{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\n\nimport algebra.group_power.basic\nimport logic.function.iterate\nimport group_theory.perm.basic\n\n/-!\n# Iterates of monoid and ring homomorphisms\n\nIterate of a monoid/ring homomorphism is a monoid/ring homomorphism but it has a wrong type, so Lean\ncan't apply lemmas like `monoid_hom.map_one` to `f^[n] 1`. Though it is possible to define\na monoid structure on the endomorphisms, quite often we do not want to convert from\n`M \u2192* M` to (not yet defined) `monoid.End M` and from `f^[n]` to `f^n` just to apply a simple lemma.\n\nSo, we restate standard `*_hom.map_*` lemmas under names `*_hom.iterate_map_*`.\n\nWe also prove formulas for iterates of add/mul left/right.\n\n## Tags\n\nhomomorphism, iterate\n-/\n\nopen function\n\nvariables {M : Type*} {N : Type*} {G : Type*} {H : Type*}\n\n/-- An auxiliary lemma that can be used to prove `\u21d1(f ^ n) = (\u21d1f^[n])`. -/\nlemma hom_coe_pow {F : Type*} [monoid F] (c : F \u2192 M \u2192 M) (h1 : c 1 = id)\n  (hmul : \u2200 f g, c (f * g) = c f \u2218 c g) (f : F) : \u2200 n, c (f ^ n) = (c f^[n])\n| 0 := by { rw [pow_zero, h1], refl }\n| (n + 1) := by rw [pow_succ, iterate_succ', hmul, hom_coe_pow]\n\nnamespace monoid_hom\n\nsection\n\nvariables [mul_one_class M] [mul_one_class N]\n\n@[simp, to_additive]\ntheorem iterate_map_one (f : M \u2192* M) (n : \u2115) : f^[n] 1 = 1 :=\niterate_fixed f.map_one n\n\n@[simp, to_additive]\ntheorem iterate_map_mul (f : M \u2192* M) (n : \u2115) (x y) :\n  f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nsemiconj\u2082.iterate f.map_mul n x y\n\nend\n\nvariables [monoid M] [monoid N] [group G] [group H]\n\n@[simp, to_additive]\ntheorem iterate_map_inv (f : G \u2192* G) (n : \u2115) (x) :\n  f^[n] (x\u207b\u00b9) = (f^[n] x)\u207b\u00b9 :=\ncommute.iterate_left f.map_inv n x\n\ntheorem iterate_map_pow (f : M \u2192* M) (a) (n m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_pow x m) n a\n\ntheorem iterate_map_zpow (f : G \u2192* G) (a) (n : \u2115) (m : \u2124) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_zpow x m) n a\n\nlemma coe_pow {M} [comm_monoid M] (f : monoid.End M) (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) _ _\n\nend monoid_hom\n\nnamespace add_monoid_hom\n\nvariables [add_monoid M] [add_monoid N] [add_group G] [add_group H]\n\n@[simp]\ntheorem iterate_map_sub (f : G \u2192+ G) (n : \u2115) (x y) :\n  f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=\nsemiconj\u2082.iterate f.map_sub n x y\n\ntheorem iterate_map_smul (f : M \u2192+ M) (n m : \u2115) (x : M) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_pow x n m\n\ntheorem iterate_map_zsmul (f : G \u2192+ G) (n : \u2115) (m : \u2124) (x : G) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_zpow x n m\n\nend add_monoid_hom\n\nnamespace ring_hom\n\nsection semiring\n\nvariables {R : Type*} [semiring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\nlemma coe_pow (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) f n\n\ntheorem iterate_map_one : f^[n] 1 = 1 := f.to_monoid_hom.iterate_map_one n\n\ntheorem iterate_map_zero : f^[n] 0 = 0 := f.to_add_monoid_hom.iterate_map_zero n\n\ntheorem iterate_map_add : f^[n] (x + y) = (f^[n] x) + (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_add n x y\n\ntheorem iterate_map_mul : f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nf.to_monoid_hom.iterate_map_mul n x y\n\ntheorem iterate_map_pow (a) (n m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\nf.to_monoid_hom.iterate_map_pow a n m\n\ntheorem iterate_map_smul (n m : \u2115) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_smul n m x\n\nend semiring\n\nvariables {R : Type*} [ring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\ntheorem iterate_map_sub : f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_sub n x y\n\ntheorem iterate_map_neg : f^[n] (-x) = -(f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_neg n x\n\ntheorem iterate_map_zsmul (n : \u2115) (m : \u2124) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_zsmul n m x\n\nend ring_hom\n\nlemma equiv.perm.coe_pow {\u03b1 : Type*} (f : equiv.perm \u03b1) (n : \u2115) : \u21d1(f ^ n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb _ _, rfl) _ _\n\n--what should be the namespace for this section?\nsection monoid\n\nvariables [monoid G] (a : G) (n : \u2115)\n\n@[simp, to_additive] lemma mul_left_iterate : ((*) a)^[n] = (*) (a^n) :=\nnat.rec_on n (funext $ \u03bb x, by simp) $ \u03bb n ihn,\nfunext $ \u03bb x, by simp [iterate_succ, ihn, pow_succ', mul_assoc]\n\n@[simp, to_additive] lemma mul_right_iterate : (* a)^[n] = (* a ^ n) :=\nbegin\n  induction n with d hd,\n  { simpa },\n  { simp [\u2190 pow_succ, hd] }\nend\n\n@[to_additive]\nlemma mul_right_iterate_apply_one : (* a)^[n] 1 = a ^ n :=\nby simp [mul_right_iterate]\n\nend monoid\n\nsection semigroup\n\nvariables [semigroup G] {a b c : G}\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_left (h : semiconj_by a b c) :\n  function.semiconj ((*)a) ((*)b) ((*)c) :=\n\u03bb j, by rw [\u2190 mul_assoc, h.eq, mul_assoc]\n\n@[to_additive]\nlemma commute.function_commute_mul_left (h : commute a b) :\n  function.commute ((*)a) ((*)b) :=\nsemiconj_by.function_semiconj_mul_left h\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_right_swap (h : semiconj_by a b c) :\n  function.semiconj (*a) (*c) (*b) :=\n\u03bb j, by simp_rw [mul_assoc, \u2190 h.eq]\n\n@[to_additive]\nlemma commute.function_commute_mul_right (h : commute a b) :\n  function.commute (*a) (*b) :=\nsemiconj_by.function_semiconj_mul_right_swap h\n\nend semigroup\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/iterate_hom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7499632491958378}}
{"text": "/-\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Peter Jipsen\nNames based on http://math.chapman.edu/~jipsen/structures/doku.php\n-/\n\nimport init.logic .identities\nuniverses u\n\nclass Mag {\u03b1:Type u}(o:\u03b1\u2192\u03b1 \u2192 \u03b1)                         --Magmas (=Binars)\n\nclass Sgrp{\u03b1:Type u}(o:\u03b1\u2192\u03b1 \u2192 \u03b1) :=                      --Semigroups\n(asso: associative o)\n\nlemma asso_sgrp {\u03b1 : Type}{o:\u03b1\u2192\u03b1 \u2192 \u03b1}{e:\u03b1} [Sgrp o]:  --sgrps are associative\n    \u2200a b c:\u03b1, o(o a b)c = o a(o b c) := Sgrp.asso o\n\nclass CSgrp{\u03b1:Type u}(o:\u03b1\u2192\u03b1 \u2192 \u03b1) extends Sgrp o :=      --Commutative semigroups\n(comm: commutative o)\n\nclass Band {\u03b1:Type u}(m:\u03b1\u2192\u03b1 \u2192 \u03b1) extends Sgrp m :=      --Bands\n(idem: idempotent m)\n\nclass Slat {\u03b1:Type u}(m:\u03b1\u2192\u03b1 \u2192 \u03b1) extends Band m :=      --Semiattices\n(comm: commutative m)\n-- use coersion to tell Lean that every Slat is an idempotent CSgrp\n\nclass Lat {\u03b1:Type u}(j:\u03b1\u2192\u03b1 \u2192 \u03b1)(m:\u03b1\u2192\u03b1 \u2192 \u03b1) :=           --Lattices\n(asso_j: associative j)(asso_m: associative m)\n(comm_j: commutative j)(comm_m: commutative m)\n(abs_jm: absorption j m)(abs_mj: absorption m j)\n\nclass Mon {\u03b1:Type u}(o:\u03b1\u2192\u03b1 \u2192 \u03b1)(e:\u03b1) extends Sgrp o :=  --Monoids\n(id_l: identity_l o e)\n(id_r: identity_r o e)\n\nlemma asso {\u03b1 : Type}{o:\u03b1\u2192\u03b1 \u2192 \u03b1}{e:\u03b1} [Mon o e]:  -- monoids are associative\n    \u2200a b c:\u03b1, o(o a b)c = o a(o b c) := Sgrp.asso o\n\nclass CMon {\u03b1:Type u}(o:\u03b1\u2192\u03b1 \u2192 \u03b1)(e:\u03b1) extends Mon o e :=--Commutative monoids\n(comm: commutative o)\n\n--class MValg {\u03b1:Type u}(o:\u03b1\u2192\u03b1 \u2192 \u03b1)(i:\u03b1 \u2192 \u03b1)(e:\u03b1) extends Sgrp o := --MV-algebras\n\n\nclass Grp {\u03b1:Type u}(o:\u03b1\u2192\u03b1 \u2192 \u03b1)(i:\u03b1 \u2192 \u03b1)(e:\u03b1) extends Sgrp o := --Groups\n(id_l : identity_l o e)\n(inv_l: inverse_r o i e)\n\n\n-- Some small models\n\ninductive M\u2082: Type | e:M\u2082 | a:M\u2082\nexport M\u2082 (e a)\nnamespace M\u2082            -- 2-elt idempotent monoid\n  def cdot:  M\u2082\u2192M\u2082 \u2192 M\u2082 | e x := x  | x e := x | a a := a\n\n  lemma cdot_id: identity_r cdot e := assume x, by cases x; refl\n  lemma id_cdot: identity_l cdot e := assume x, by cases x; refl\n  lemma cdot_asso: associative cdot := \n    assume x y z, by cases x; cases y; cases z; refl\n  lemma cdot_idem: idempotent cdot := assume x, by cases x; refl\n\n  instance: Sgrp cdot := \u27e8cdot_asso\u27e9\n  instance: Band cdot := \u27e8cdot_idem\u27e9   -- removed 1st component \u27e8cdot_asso\u27e9, \n  instance: Mon cdot e := \u27e8id_cdot, cdot_id\u27e9  -- removed 1st component \u27e8cdot_asso\u27e9, \nend M\u2082\n\n\ninductive Z\u2082: Type | e:Z\u2082 | a:Z\u2082\nexport Z\u2082 (e a)\nnamespace Z\u2082            -- 2-elt group\n  def add:  Z\u2082\u2192Z\u2082 \u2192 Z\u2082 | e x := x  | x e := x | a a := e\n\n  lemma add_zero: right_identity add e := assume x, by cases x; refl\n  lemma zero_add: left_identity add e := assume x, by cases x; refl\n  lemma add_assoc: associative add := \n  assume x y z, by cases x; cases y; cases z; refl\n\n  instance: Sgrp add := \u27e8add_assoc\u27e9\n  instance: Mon add e := \u27e8zero_add, add_zero\u27e9   -- removed 1st component \u27e8add_asso\u27e9, \nend Z\u2082", "meta": {"author": "jipsen", "repo": "lean-prover-universal-algebra", "sha": "5decd84053f30f175ebb86c39df4fd6b6d72400e", "save_path": "github-repos/lean/jipsen-lean-prover-universal-algebra", "path": "github-repos/lean/jipsen-lean-prover-universal-algebra/lean-prover-universal-algebra-5decd84053f30f175ebb86c39df4fd6b6d72400e/classes/ua_classes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7499632438411459}}
{"text": "import tactic\n\ninductive mynat\n| Z : mynat\n| S : mynat \u2192 mynat\n\nnamespace mynat\n\nexample : mynat := Z\n\n#check Z\n#check S(Z)\n#check S(S(S(S(S(S(S(S(Z))))))))\n\n-- clearly just numbers (count the S's)\n\nend mynat\n\n-- more powerful system of numbers!\n\ninductive supernat\n| Z : supernat\n| S : supernat \u2192 supernat\n| T : supernat \u2192 supernat\n\nnamespace supernat\n\n#check S(Z)\n#check T(Z)\n\n#check S(T(T(S(T(S(S(T(T(Z)))))))))\n\n-- clearly some rich binary tree\n\nend supernat\n\n/-\n\nHow can we understand things like STSSTSTSTSTSSZ ?\n\nFirst thing we notice: they all end in Z\n\nSo really a term of this type is just more like STSSSTSTSTSSTS\n\n-- a string of S's and T's\n\nImagine S=0 and T=1\n\n-- it's a string of zeros and 1s!\n\n-- So it's a binary number!\n\n-- is supernat = nat?\n\nBinary numbers 1001 and 00000001001 are the same\n\nBut TSST \u2260 SSSSSSSTSST\n\n0\n1\n10\n11\n100\n101\n110\n111\n1000\n...\n\nOther than 0, they do all start with 1. Maybe that was Z?\n\nHow about Z=initial 1, and then read it backwards\n\ngeneral number is\n\nZSSTST (backwards)\n\nand this should become\n100101 = 37\n\nso supernat is just binary\n\n-/\n\ninductive binary_nat\n| one : binary_nat\n| bit0 : binary_nat \u2192 binary_nat -- \"add a 0 on the end\" -- i.e. double\n| bit1 : binary_nat \u2192 binary_nat -- double and add 1\n\nnotation `\u2119` := binary_nat -- \\bbP\n\nnamespace binary_nat\n\ndef thirtyseven : binary_nat := bit1 (bit0 (bit1 (bit0 (bit0 one))))\n\n-- notice that these nats start at 1 -- can't make 0\n-- so they're the \"British Natural Numbers\" :-)\n-- now need to make an API for binary nats\n-- let's play the British Natural Number Game!\n\n-- succ was important!\n\ninstance : has_one binary_nat := \u27e8binary_nat.one\u27e9\n\ndef succ : binary_nat \u2192 binary_nat\n| 1 := bit0 1\n| (bit0 t) := bit1 t\n| (bit1 t) := bit0 (succ t)\n\n@[simp] lemma one_def : one = 1 := rfl\n\n@[simp] lemma succ_one : succ 1 = bit0 1 := rfl\n@[simp] lemma succ_bit0 (t : \u2119) : succ (bit0 t) = bit1 t := rfl\n@[simp] lemma succ_bit1 (t : \u2119) : succ (bit1 t) = bit0 (succ t) := rfl\n\n-- now let's define addition of binary nats! This is literally column addition\n\ndef add : \u2119 \u2192 \u2119 \u2192 \u2119\n|       a        1  := succ a\n|       1        b  := succ b\n| (bit0 a) (bit0 b) := bit0 (add a b)\n| (bit0 a) (bit1 b) := bit1 (add a b)\n| (bit1 a) (bit0 b) := bit1 (add a b)\n| (bit1 a) (bit1 b) := bit0 (succ (add a b))\n\ninstance : has_add \u2119 := \u27e8add\u27e9\n\n@[simp] lemma bit0_add_bit0 (a b : \u2119) : (bit0 a) + (bit0 b) = bit0 (a + b) := rfl\n@[simp] lemma bit0_add_bit1 (a b : \u2119) : (bit0 a) + (bit1 b) = bit1 (a + b) := rfl\n@[simp] lemma bit1_add_bit0 (a b : \u2119) : (bit1 a) + (bit0 b) = bit1 (a + b) := rfl\n@[simp] lemma bit1_add_bit1 (a b : \u2119) : (bit1 a) + (bit1 b) = bit0 (succ(a + b)) := rfl\n\n-- inspired by NNG, let's prove succ_eq_add_one\n\n@[simp] lemma add_one_eq_succ (a : \u2119) : a + 1 = succ a :=\nbegin\n  cases a; refl\nend\n\n\n@[simp] lemma one_add_eq_succ (b : \u2119) : 1 + b = succ b :=\nbegin\n  cases b,\n  { refl },\n  { refl },\n  { refl }\nend\n\n-- next on the agenda in NNG is add_assoc\n-- but this will involve 27 cases :-) \n-- and some induction as well!\n-- a + b in NNG depends on whether b = 0 or succ(c) so two cases\n\nlemma add_assoc_one_one (a : \u2119) : (a + 1) + 1 = a + (1 + 1) :=\nbegin\n  induction a with b hb b hb; simp; try {refl},\nend.\n\n@[simp] lemma add_two (a : \u2119) : a + bit0 1 = succ (succ a) :=\nbegin\n  show a + (1 + 1) = succ (succ a),\n  rw \u2190add_assoc_one_one,\n  simp\nend.\n\n\n-- -- this is just add_succ\n-- lemma add_assoc_one (a b : \u2119) : (a + b) + 1 = a + (b + 1) :=\n-- begin\n--   induction b; cases a; simp; try {refl},\n--   sorry, sorry\n-- end.\n\n@[simp] lemma add_succ (a b : \u2119) : a + succ b = succ (a + b) :=\nbegin\n  induction b with d hd d hd generalizing a,\n  { simp },\n  { induction a with c hc c hc; simp},\n  { induction a with c hc c hc; try {simp}; simp [hd c]}\n\nend.\n\n\n-- don't really want to do associativity -- straightforward but long\n\n-- here's another idea though -- binary nats are just positive natural numbers\n-- and we've already proved that addition is associative on natural numbers\n-- in NNG (and it was easy!)\n-- So why not deduce associativity of binary + from associativity of +\n\ndef of_nat'' : \u03a0 (n : \u2115), (n \u2260 0) \u2192 \u2119\n| 0 h := begin exfalso, apply h, refl, end\n| 1 h := binary_nat.one\n| (n+2) h := succ (of_nat'' (n+1) (nat.succ_ne_zero n))\n\ndef of_nat' (a : {x : \u2115 // x \u2260 0}) : \u2119 := of_nat'' a.1 a.2\n\ndef of_nat : \u2115 \u2192 \u2119\n| 0 := thirtyseven\n| 1 := 1\n| (n + 2) := succ (of_nat (n + 1))\n\ntheorem of_nat_succ (a : \u2115) (ha : a \u2260 0) : of_nat (a + 1) = succ (of_nat a) :=\nbegin\n  cases a, cases ha rfl,\n  cases a,\n  { refl},\n  clear ha,\n  refl,\nend\n\n@[simp] lemma of_nat_one : of_nat 1 = 1 := rfl\n@[simp] lemma of_nat_succ_succ (a : \u2115) : of_nat (a + 2) = succ (of_nat (a + 1)) := rfl\n\n-- Theorem: column addition gives the right answer! i.e. we are formally\n-- verifying the column addition algorithm\ntheorem of_nat_add (a b : \u2115) (ha : a \u2260 0) (hb : b \u2260 0) : of_nat (a + b) = of_nat a + of_nat b :=\nbegin\n  cases a, cases ha rfl, cases b, cases hb rfl,\n  clear ha hb,\n  induction b with d hd generalizing a,\n  { simp }, -- simp works\n  change of_nat ((a+1)+(d+2)) = of_nat (a+1) + of_nat (d+2), \n  rw of_nat_succ_succ,\n  rw add_succ,\n  rw \u2190hd a,\n  rw (show nat.succ a + nat.succ d = (a+d+1)+1, by omega),\n  rw \u2190of_nat_succ_succ,\n  apply congr_arg,\n  omega,\nend.\n\n\nend binary_nat\n\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/src/binarynats.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.749925429552154}}
{"text": "/- A FAMILY OF TYPES (\"INDUCTIVE FAMILY\")\n\nefine a family of types, *tuple n*, indexed\nby natural numbers. For any (n : nat), tuple n \nis the type of tuples (of natural numbers) of \nlength n. \n-/\n\n\n-- nat \u2a2f nat\n\n--  \u2115 \u2115 \u2115 \n-- (1,2,3)\n\n--  \u2115 \u2a2f (\u2115\u00d7\u2115) \n-- (1,(2,3))\n\n-- (1, (2, (3, (4, 5))))\n\n/-\nBuild a function that takes a natural number, n,\nand returns a TYPE: the type of tuples of length\nn.\n\n#check tuple\n\nnat \u2192 (nat \u2a2f (nat \u2a2f nat))\n\ntuple : \u03a0 (n : \u2115), _\n-/\n\n/-\nReminder: prod is a type builder. Given\ntypes, \u03b1 and \u03b2, prod \u03b1 \u03b2 (or \u03b1 \u00d7 \u03b2) is the\nthe *type* of ordered \u03b1-\u03b2 pairs. We can\nthen use prod.mk to create values of such\na type. \n\nThe following function recursively applies\n\u00d7 to nat, enabling us to build product types\nwith any number of components, not just two\n(where, here, for simplicity, we support\nonly products of the nat type). The base\ncase for the recursion when n=0 is the unit\ntype. \n-/\n\n-- for each (n : nat), a type, (tuple n)\ndef tuple : nat \u2192 Type\n| 0 := unit\n| (n' + 1) := nat \u00d7 (tuple n')\n\n/-\n0   tuple 0 = unit\n1   tuple 1 = nat \u2a2f unit\n2   tuple 2 = nat \u2a2f (nat \u2a2f unit)\n3   tuple 3 = nat \u2a2f (nat \u2a2f (nat \u2a2f unit))\n4   tuple 4 = nat \u2a2f (tuple 3)\n...\nn   tuple (n' + 1) = nat \u2a2f (tuple n')\n-/\n\n#check tuple  -- \u2115 \u2192 Type (*important*)\n\n#check nat\n#check (prod nat nat)\n\n/-\nFor values of n from 0 to 3, we get the \nfollowing types by applying tuple to n.\n\n0: unit\n1: nat \u2a2f unit\n2: nat \u00d7 (nat \u00d7 unit)\n3: nat \u00d7 (nat \u00d7 (nat \u00d7 unit)) \n\nValues of these types include:\n\n0 : (unit.star)\n1: (1, unit.star)\n2: (1, 2, unit.star)\n3: (1, 2, 4, unit.star)\n-/\n\ndef t0 : tuple 0 := unit.star\ndef t1' : tuple 1 := prod.mk 1 unit.star\ndef t1 : tuple 1 := (1, unit.star)  -- notation\ndef t2 : tuple 2 := (1, 2, unit.star)\ndef t3 : tuple 3 := (1, (2, (4, (unit.star))))\n\n--  (1, 2, unit.star)\n--  (1, (2, (unit.star)))\n-- prod.mk 1 (prod.mk 2 unit.star)\n\n\n/-\nThe length is typechecked! The error\nmessages are cryptic, but, hey.\n-/\n\ndef t3' : tuple 3 := (1, 2, 3, 4, unit.star) -- no\ndef t3'' : tuple 3 := (1, 2, 4, unit.star) -- no\n\n/-\nWe could define a nicer concrete syntax that \nwould let us avoid having to write the star\nat the end, but we'll skip that here to stay\nfocused on the essentials. \n-/\n\n/-\nNote that tuple is a *type builder*. It\ntakes a natural number, n, and returns a \n*type*: in particular, one that depends \non n. Tuple is defined by recursion on n.\nIt iteratively computes the product type\nof nat and smaller product of nats until\nn=0, at which point it returns the product\nof all that with the unit type (base case).\n-/\n\n/-\nMore generally, given (\u03b1 : Type) and \n(\u03b2 : \u03b1 \u2192 Type), we can view \u03b2 as defining\na *family of types over \u03b1*, with a different\ntype, (\u03b2 a), for such each value, (a : \u03b1). \n\nIn our example above, \u03b1 = nat and \u03b2 = tuple.\nTuple defines an inductive family of types\n\"indexed by the natural numbers.\" To each\nnatural number, n, tuple thus associates \na corresponding type, tuple n,that depends\non n.\n-/\n\ndef n0 : tuple 0 := ()\n#reduce n0\n\ndef nil := tuple 0\n\ndef cons : \u03a0 {n : \u2115}, nat \u2192 tuple n \u2192 tuple (n + 1) \n| n a t := prod.mk a t\n\n-- {2} 7 (1, 2, star) -> (7, (1, 2, star))\n-- #reduce cons 7 ((1, (2, unit.star)) : tuple 2)\n\ndef head : \u03a0 {n : nat}, tuple  n \u2192 option nat\n| 0 _ := none\n| (n' + 1) (prod.mk h t) := some h\n\ndef tail {\u03b1 : Type} : \u03a0 (n : nat), tuple n \u2192 option (tuple (n-1))\n| 0 _ := none\n| (n' + 1) (prod.mk h t) := some t\n\ndef append :\n  \u03a0 {n m : \u2115}, (tuple n) \u2192 tuple m \u2192 tuple (m + n)\n| 0 m tn tm := tm\n| (n' + 1) m (prod.mk h tn') tm := prod.mk h (append tn' tm) -- infers n' m\n\ndef t6 := append t3 t3\n#reduce t6\n\n-- Type check catches bounds errors\ndef foo (t : tuple 3) : nat := 0\n#check foo t2   -- No: type of t2 is tuple 2, not tuple 3\n\n/-\nDEPENDENT FUNCTION TYPES\n-/\n\n/-\nThe importance of Pi types, \u03a0 x : \u03b1, \u03b2 x, is that they generalize \nthe notion of a function type, \u03b1 \u2192 \u03b2, by allowing the type, \u03b2, to \ndepend on  (a : \u03b1). Here's a function that takes a value, n, of\ntype nat, and that returns a value of type *(tuple n)*. Clearly\nthe type of the return value depends on the value of the argument,\nn. It should now also be clear why \u03a0 binds a name to an argument:\nso that the value can be used in defining the rest of the *type*\nof a function.\n-/\ndef zerotuple : \u03a0 (n : nat), tuple n\n| 0 := ()\n| (n' + 1) := (0, zerotuple n')\n\n\n-- \u03a0 (n : nat), tuple n\n\n#reduce zerotuple 4\n#check zerotuple 4\n\ndef nToNtuple (n : nat) : tuple n := zerotuple n\n#check nToNtuple\n\ndef z0 := nToNtuple 0\ndef z1 := nToNtuple 1\ndef z2 := nToNtuple 2\ndef z3 := nToNtuple 3\ndef z4 := nToNtuple 4\n\n#check z0\n#check z1\n#check z2\n#check z3\n#check z4\n\n#reduce z0\n#reduce z1\n#reduce z2\n#reduce z3\n#reduce z4\n\n-- General notation for dependently typed functions\n-- \u03a0 (a : A), B a \n-- \u03a0 (n : \u2115), tuple n\n\n-- \u03a0 (a : A), B   -- special case where B doesn't depend on a \n-- A \u2192 B \n\n\n-- Ours is a dependently typed function\n#check nToNtuple\n\n\n/-\nSIGMA (DEPENDENT PRODUCT) TYPES\n-/\n\n#print sigma\n\n/-\nstructure sigma : \u03a0 {\u03b1 : Type u}, (\u03b1 \u2192 Type v) \u2192 Type (max u v)\nfields:\nsigma.fst : \u03a0 {\u03b1 : Type u} {\u03b2 : \u03b1 \u2192 Type v}, sigma \u03b2 \u2192 \u03b1\nsigma.snd : \u03a0 {\u03b1 : Type u} {\u03b2 : \u03b1 \u2192 Type v} (c : sigma \u03b2), \u03b2 c.fstLean\n-/\n\n#check \u03a3 (n : nat), tuple n   -- dependent pair type, \u27e8 n, tuple n \u27e9 \n\ndef s3 : \u03a3 (n : nat), tuple n := sigma.mk 3 (1,2,3,unit.star) \ndef s5 : \u03a3 (n : nat), tuple n := \u27e8  5, (nToNtuple 5) \u27e9 \ndef sx : \u03a3 (n : nat), tuple n := \u27e8 5, (nToNtuple 4) \u27e9 -- Cannot form, snd has wrong type\n\n#print sigma \n\n#reduce sigma.fst s3\n#reduce sigma.snd s3\n#reduce s3.fst\n#reduce s3.snd\n#reduce s3.1\n#reduce s3.2\n\n-- Identical types, varying in notation\n#check \u03a3 (n : nat), tuple n \n#check @sigma nat tuple\n\n#check sigma.mk 3 (nToNtuple 3)\n#check sigma.mk 4 (nToNtuple 4)\n#reduce sigma.mk 3 (nToNtuple 3)\n#reduce sigma.mk 4 (nToNtuple 4)\n\n\n\ndef nToSigma (n : nat) : sigma tuple := \n\u27e8 n, nToNtuple n\u27e9 \n\ndef nToSigma' (n : nat): \u03a3 (n : nat), tuple n :=\n\u27e8 n, nToNtuple n\u27e9 \n\n\n#reduce nToSigma 5\n\n\n/-\nvariable \u03b1 : Type\nvariable \u03b2 : \u03b1 \u2192 Type\nvariable a : \u03b1\nvariable b : \u03b2 a\n\n#check sigma.mk a b      -- \u03a3 (a : \u03b1), \u03b2 a\n#check (sigma.mk a b).1  -- \u03b1\n#check (sigma.mk a b).2  -- \u03b2 (sigma.fst (sigma.mk a b))\n\n#reduce  (sigma.mk a b).1  -- a\n#reduce  (sigma.mk a b).2  -- b-/\n\ndef evenNum : {n : nat // n%2 = 0} := \u27e8 2, rfl \u27e9 \n\n#reduce evenNum\n\ndef oops : {n : nat // n%2 = 0} := \u27e8 3, rfl \u27e9 \n\ndef evenId : {n : nat // n%2 = 0} \u2192 nat \n\n| \u27e8 val, proof_about_val \u27e9 := val\n\n#eval evenId \u27e8 0, rfl \u27e9 \n#eval evenId \u27e8 1, rfl \u27e9 \n#eval evenId \u27e8 2, rfl \u27e9 \n#eval evenId \u27e8 3, rfl \u27e9 \n#eval evenId \u27e8 4, rfl \u27e9 \n#eval evenId \u27e8 5, rfl \u27e9 \n\n#print subtype", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/inClassNotes/dependentTypes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7499254275587208}}
{"text": "variables (real : Type) [ordered_ring real]\nvariables (log exp : real \u2192 real)\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\ncalc\n    log (x * y) = log (exp (log x) * exp (log y)) : by rw [exp_log_eq hx, exp_log_eq hy]\n            ... = log (exp (log x + log y))       : by rw exp_add\n            ... = log x + log y                   : by rw log_exp_eq\n\n", "meta": {"author": "hyponymous", "repo": "theorem-proving-in-lean-solutions", "sha": "a95320ae81c90c1b15da04574602cd378794400d", "save_path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions", "path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions/theorem-proving-in-lean-solutions-a95320ae81c90c1b15da04574602cd378794400d/4.6.6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7499131063743476}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones\n--    1. Importar la teor\u00eda de ret\u00edculos.\n--    2. Declarar \u03b1 como un tipo sobre ret\u00edculos\n--    3. Declarar x e y como variabkes sobre \u03b1\n-- ----------------------------------------------------------------------\n\nimport order.lattice               -- 1\nvariables {\u03b1 : Type*} [lattice \u03b1]  -- 2\nvariables x y : \u03b1                  -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    x \u2293 (x \u2294 y) = x\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2293 (x \u2294 y) = x :=\nbegin\n  have h1 : x \u2293 (x \u2294 y) \u2264 x, finish,\n  have h2 : x \u2264 x \u2293 (x \u2294 y), finish,\n  show x \u2293 (x \u2294 y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2293 (x \u2294 y) = x :=\nbegin\n  have h1 : x \u2293 (x \u2294 y) \u2264 x := inf_le_left,\n  have h2 : x \u2264 x \u2293 (x \u2294 y),\n  { have h2a : x \u2264 x := rfl.ge,\n    have h2b : x \u2264 x \u2294 y := le_sup_left,\n    show x \u2264 x \u2293 (x \u2294 y),\n      by exact le_inf h2a h2b, },\n  show x \u2293 (x \u2294 y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2293 (x \u2294 y) = x :=\nbegin\n  apply le_antisymm,\n  { apply inf_le_left },\n  { apply le_inf,\n    { apply le_refl },\n    { apply le_sup_left }},\nend\n\n-- Su desarrollo es\n--\n-- \u22a2 x \u2293 (x \u2294 y) = x\n--    apply le_antisymm,\n-- | \u22a2 x \u2293 (x \u2294 y) \u2264 x\n-- | |   { apply inf_le_left },\n-- | \u22a2 x \u2264 x \u2293 (x \u2294 y)\n-- |   { apply le_inf,\n-- | | \u22a2 x \u2264 x\n-- | |     { apply le_refl },\n-- | | \u22a2 x \u2264 x \u2294 y\n-- | |     { apply le_sup_left }},\n-- no goals\n\n-- 4\u00aa demostraci\u00f3n\nexample : x \u2293 (x \u2294 y) = x :=\n-- by library_search\ninf_sup_self\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2293 (x \u2294 y) = x :=\n-- by hint\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que\n--    x \u2294 (x \u2293 y) = x\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\nbegin\n  have h1 : x \u2294 (x \u2293 y) \u2264 x, finish,\n  have h2 : x \u2264 x \u2294 (x \u2293 y), finish,\n  show x \u2294 (x \u2293 y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\nbegin\n  have h1 : x \u2294 (x \u2293 y) \u2264 x,\n  { have h1a : x \u2264 x := le_rfl,\n    have h1b : x \u2293 y \u2264 x := inf_le_left,\n    show x \u2294 (x \u2293 y) \u2264 x,\n      by exact sup_le h1a h1b,\n  },\n  have h2 : x \u2264 x \u2294 (x \u2293 y) := le_sup_left,\n  show x \u2294 (x \u2293 y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\nbegin\n  apply le_antisymm,\n  { apply sup_le,\n    { apply le_refl },\n    { apply inf_le_left }},\n  { apply le_sup_left },\nend\n\n-- Su desarrollo es\n--\n-- \u22a2 x \u2294 x \u2293 y = x\n--    apply le_antisymm,\n-- | \u22a2 x \u2294 x \u2293 y \u2264 x\n-- |    { apply sup_le,\n-- | | \u22a2 x \u2264 x\n-- | |      { apply le_refl },\n-- | | \u22a2 x \u2293 y \u2264 x\n-- | |      { apply inf_le_left }},\n-- | \u22a2 x \u2264 x \u2294 x \u2293 y\n-- | |    { apply le_sup_left },\n-- no goals\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\n-- by library_search\nsup_inf_self\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\n-- by hint\nby simp\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Basicos/Leyes_de_absorcion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7498999486411978}}
{"text": "import data.real.basic\n\nopen function\n\ndefinition pals {X Y Z : Type} (f : X \u2192 Y) (g : X \u2192 Z) := \u2203 h : Y \u2192 Z, bijective h \u2227 g = h \u2218 f\n\nlemma Q5 (X Y Z: Type) (f : X \u2192 Y) (g : X \u2192 Z) (hf : surjective f) (hg : surjective g) : pals f g \u2194 \u2200 a b : X, (f a = f b) \u2194 (g a = g b) :=\nbegin\n  split,\n  { -- if pals then equiv relns equal\n    rintro \u27e8h, hb, hghf\u27e9,\n      rw funext_iff at hghf,\n    intros a b,\n    split,\n    { -- f(a)=f(b) implies g(a)=g(b)\n      intro hfab,\n      rw hghf,\n      rw hghf,\n      show h (f a) = h (f b),\n      rw hfab,\n    },\n    intro hgab,\n    cases hb with hi hs,\n    apply hi,\n    rw hghf at hgab,    \n    rw hghf at hgab,    \n    exact hgab,\n  },\n  { intro hequiv,\n    unfold pals,\n    let hf' := hf,\n    choose temp htemp using hf', -- a temporary function Y \u2192 X sending y to some random x with f(x)=y\n    use g \u2218 temp,\n    split,\n    { split,\n      { intros y\u2081 y\u2082 h12,\n        change g (temp y\u2081) = g (temp y\u2082) at h12,\n        rw \u2190hequiv at h12,\n        rw htemp at h12,\n        rw htemp at h12,\n        assumption,\n      },\n      intro z,\n      cases hg z with x hx,\n      use f x,\n      show g(temp(f(x))) = _,\n      rw \u2190hx,\n      rw \u2190hequiv,\n      rw htemp,\n    },\n    ext,\n    show _ = g(temp(f(x))),\n    rw \u2190hequiv,\n    rw htemp,\n  }\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2019/solutions/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7498999484217583}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Alexander Bentkamp\n-/\nimport linear_algebra.linear_independent\nimport linear_algebra.projection\nimport linear_algebra.linear_pmap\nimport data.fintype.card\n\n/-!\n\n# Bases\n\nThis file defines bases in a module or vector space.\n\nIt is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.\n\n## Main definitions\n\nAll definitions are given for families of vectors, i.e. `v : \u03b9 \u2192 M` where `M` is the module or\nvector space and `\u03b9 : Type*` is an arbitrary indexing type.\n\n* `is_basis R v` states that the vector family `v` is a basis, i.e. it is linearly independent and\n  spans the entire space.\n\n* `is_basis.repr hv x` is the basis version of `linear_independent.repr hv x`. It returns the\n  linear combination representing `x : M` on a basis `v` of `M` (using classical choice).\n  The argument `hv` must be a proof that `is_basis R v`. `is_basis.repr hv` is given as a linear\n  map as well.\n\n* `is_basis.constr hv f` constructs a linear map `M\u2081 \u2192\u2097[R] M\u2082` given the values `f : \u03b9 \u2192 M\u2082` at the\n  basis `v : \u03b9 \u2192 M\u2081`, given `hv : is_basis R v`.\n\n## Main statements\n\n* `is_basis.ext` states that two linear maps are equal if they coincide on a basis.\n\n* `exists_is_basis` states that every vector space has a basis.\n\n## Implementation notes\n\nWe use families instead of sets because it allows us to say that two identical vectors are linearly\ndependent. For bases, this is useful as well because we can easily derive ordered bases by using an\nordered index type `\u03b9`.\n\n## Tags\n\nbasis, bases\n\n-/\n\nnoncomputable theory\n\nuniverse u\n\nopen function set submodule\nopen_locale classical big_operators\n\nvariables {\u03b9 : Type*} {\u03b9' : Type*} {R : Type*} {K : Type*}\nvariables {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}\n\nsection module\n\nopen linear_map\n\nvariables {v : \u03b9 \u2192 M}\nvariables [ring R] [add_comm_group M] [add_comm_group M'] [add_comm_group M'']\nvariables [module R M] [module R M'] [module R M'']\nvariables {a b : R} {x y : M}\n\nvariables (R) (v)\n/-- A family of vectors is a basis if it is linearly independent and all vectors are in the span. -/\ndef is_basis := linear_independent R v \u2227 span R (range v) = \u22a4\nvariables {R} {v}\n\nsection is_basis\nvariables {s t : set M} (hv : is_basis R v)\n\nlemma is_basis.mem_span (hv : is_basis R v) : \u2200 x, x \u2208 span R (range v) := eq_top_iff'.1 hv.2\n\nlemma is_basis.comp (hv : is_basis R v) (f : \u03b9' \u2192 \u03b9) (hf : bijective f) :\n  is_basis R (v \u2218 f) :=\nbegin\n  split,\n  { apply hv.1.comp f hf.1 },\n  { rw[set.range_comp, range_iff_surjective.2 hf.2, image_univ, hv.2] }\nend\n\nlemma is_basis.injective [nontrivial R] (hv : is_basis R v) : injective v :=\n  \u03bb x y h, linear_independent.injective hv.1 h\n\nlemma is_basis.range (hv : is_basis R v) : is_basis R (\u03bb x, x : range v \u2192 M) :=\n\u27e8hv.1.to_subtype_range,\n  by { convert hv.2, ext i, exact \u27e8\u03bb \u27e8p, hp\u27e9, hp \u25b8 p.2, \u03bb hi, \u27e8\u27e8i, hi\u27e9, rfl\u27e9\u27e9 }\u27e9\n\n/-- Given a basis, any vector can be written as a linear combination of the basis vectors. They are\ngiven by this linear map. This is one direction of `module_equiv_finsupp`. -/\ndef is_basis.repr : M \u2192\u2097 (\u03b9 \u2192\u2080 R) :=\n(hv.1.repr).comp (linear_map.id.cod_restrict _ hv.mem_span)\n\nlemma is_basis.total_repr (x) : finsupp.total \u03b9 M R v (hv.repr x) = x :=\nhv.1.total_repr \u27e8x, _\u27e9\n\nlemma is_basis.total_comp_repr : (finsupp.total \u03b9 M R v).comp hv.repr = linear_map.id :=\nlinear_map.ext hv.total_repr\n\nlemma is_basis.ext {f g : M \u2192\u2097[R] M'} (hv : is_basis R v) (h : \u2200i, f (v i) = g (v i)) : f = g :=\nlinear_map.ext_on_range hv.2 h\n\nlemma is_basis.repr_ker : hv.repr.ker = \u22a5 :=\nlinear_map.ker_eq_bot.2 $ left_inverse.injective hv.total_repr\n\nlemma is_basis.repr_range : hv.repr.range = finsupp.supported R R univ :=\nby rw [is_basis.repr, linear_map.range_eq_map, submodule.map_comp,\n  linear_map.map_cod_restrict, submodule.map_id, comap_top, map_top, hv.1.repr_range,\n  finsupp.supported_univ]\n\nlemma is_basis.repr_total (x : \u03b9 \u2192\u2080 R) (hx : x \u2208 finsupp.supported R R (univ : set \u03b9)) :\n  hv.repr (finsupp.total \u03b9 M R v x) = x :=\nbegin\n  rw [\u2190 hv.repr_range, linear_map.mem_range] at hx,\n  cases hx with w hw,\n  rw [\u2190 hw, hv.total_repr],\nend\n\nlemma is_basis.repr_eq_single {i} : hv.repr (v i) = finsupp.single i 1 :=\nby apply hv.1.repr_eq_single; simp\n\n@[simp]\nlemma is_basis.repr_self_apply (i j : \u03b9) [decidable (i = j)] :\n  hv.repr (v i) j = if i = j then 1 else 0 :=\nby rw [hv.repr_eq_single, finsupp.single_apply]\n\nlemma is_basis.repr_eq_iff {f : M \u2192\u2097[R] (\u03b9 \u2192\u2080 R)} :\n  hv.repr = f \u2194 \u2200 i, f (v i) = finsupp.single i 1 :=\nbegin\n  split,\n  { rintros rfl i,\n    exact hv.repr_eq_single },\n  intro h,\n  refine hv.ext (\u03bb _, _),\n  rw [h, hv.repr_eq_single]\nend\n\nlemma is_basis.repr_apply_eq {f : M \u2192 \u03b9 \u2192 R}\n  (hadd : \u2200 x y, f (x + y) = f x + f y) (hsmul : \u2200 (c : R) (x : M), f (c \u2022 x) = c \u2022 f x)\n  (f_eq : \u2200 i, f (v i) = finsupp.single i 1) (x : M) (i : \u03b9) :\n  hv.repr x i = f x i :=\nbegin\n  let f_i : M \u2192\u2097[R] R :=\n  { to_fun := \u03bb x, f x i,\n    map_add' := \u03bb _ _, by rw [hadd, pi.add_apply],\n    map_smul' := \u03bb _ _, by rw [hsmul, pi.smul_apply] },\n  show (finsupp.lapply i).comp hv.repr x = f_i x,\n  congr' 1,\n  refine hv.ext (\u03bb j, _),\n  show hv.repr (v j) i = f (v j) i,\n  rw [hv.repr_eq_single, f_eq]\nend\n\nlemma is_basis.range_repr_self (i : \u03b9) :\n  hv.range.repr (v i) = finsupp.single \u27e8v i, mem_range_self i\u27e9 1 :=\nhv.1.to_subtype_range.repr_eq_single _ _ rfl\n\n@[simp] lemma is_basis.range_repr (i : \u03b9) :\n  hv.range.repr x \u27e8v i, mem_range_self i\u27e9 = hv.repr x i :=\nbegin\n  by_cases H : (0 : R) = 1,\n  { exact eq_of_zero_eq_one H _ _ },\n  refine (hv.repr_apply_eq _ _ _ x i).symm,\n  { intros x y,\n    ext j,\n    rw [linear_map.map_add, finsupp.add_apply],\n    refl },\n  { intros c x,\n    ext j,\n    rw [linear_map.map_smul, finsupp.smul_apply],\n    refl },\n  { intro i,\n    ext j,\n    haveI : nontrivial R := \u27e8\u27e80, 1, H\u27e9\u27e9,\n    simp [hv.range_repr_self, finsupp.single_apply, hv.injective.eq_iff] }\nend\n\n/-- Construct a linear map given the value at the basis. -/\ndef is_basis.constr (f : \u03b9 \u2192 M') : M \u2192\u2097[R] M' :=\n(finsupp.total M' M' R id).comp $ (finsupp.lmap_domain R R f).comp hv.repr\n\ntheorem is_basis.constr_apply (f : \u03b9 \u2192 M') (x : M) :\n  (hv.constr f : M \u2192 M') x = (hv.repr x).sum (\u03bbb a, a \u2022 f b) :=\nby dsimp [is_basis.constr] ;\n   rw [finsupp.total_apply, finsupp.sum_map_domain_index]; simp [add_smul]\n\n@[simp] lemma constr_basis {f : \u03b9 \u2192 M'} {i : \u03b9} (hv : is_basis R v) :\n  (hv.constr f : M \u2192 M') (v i) = f i :=\nby simp [is_basis.constr_apply, hv.repr_eq_single, finsupp.sum_single_index]\n\nlemma constr_eq {g : \u03b9 \u2192 M'} {f : M \u2192\u2097[R] M'} (hv : is_basis R v)\n  (h : \u2200i, g i = f (v i)) : hv.constr g = f :=\nhv.ext $ \u03bb i, (constr_basis hv).trans (h i)\n\nlemma constr_self (f : M \u2192\u2097[R] M') : hv.constr (\u03bb i, f (v i)) = f :=\nconstr_eq hv $ \u03bb x, rfl\n\nlemma constr_zero (hv : is_basis R v) : hv.constr (\u03bbi, (0 : M')) = 0 :=\nconstr_eq hv $ \u03bb x, rfl\n\nlemma constr_add {g f : \u03b9 \u2192 M'} (hv : is_basis R v) :\n  hv.constr (\u03bbi, f i + g i) = hv.constr f + hv.constr g :=\nconstr_eq hv $ \u03bb b, by simp\n\nlemma constr_neg {f : \u03b9 \u2192 M'} (hv : is_basis R v) : hv.constr (\u03bbi, - f i) = - hv.constr f :=\nconstr_eq hv $ \u03bb b, by simp\n\nlemma constr_sub {g f : \u03b9 \u2192 M'} (hs : is_basis R v) :\n  hv.constr (\u03bbi, f i - g i) = hs.constr f - hs.constr g :=\nby simp [sub_eq_add_neg, constr_add, constr_neg]\n\n-- this only works on functions if `R` is a commutative ring\nlemma constr_smul {\u03b9 R M} [comm_ring R] [add_comm_group M] [module R M]\n  {v : \u03b9 \u2192 R} {f : \u03b9 \u2192 M} {a : R} (hv : is_basis R v) :\n  hv.constr (\u03bbb, a \u2022 f b) = a \u2022 hv.constr f :=\nconstr_eq hv $ by simp [constr_basis hv] {contextual := tt}\n\nlemma constr_range [nonempty \u03b9] (hv : is_basis R v) {f : \u03b9  \u2192 M'} :\n  (hv.constr f).range = span R (range f) :=\nby rw [is_basis.constr, linear_map.range_comp, linear_map.range_comp, is_basis.repr_range,\n    finsupp.lmap_domain_supported, \u2190set.image_univ, \u2190finsupp.span_eq_map_total, image_id]\n\n/-- Canonical equivalence between a module and the linear combinations of basis vectors. -/\ndef module_equiv_finsupp (hv : is_basis R v) : M \u2243\u2097[R] \u03b9 \u2192\u2080 R :=\n(hv.1.total_equiv.trans (linear_equiv.of_top _ hv.2)).symm\n\n@[simp] theorem module_equiv_finsupp_apply_basis (hv : is_basis R v) (i : \u03b9) :\n  module_equiv_finsupp hv (v i) = finsupp.single i 1 :=\n(linear_equiv.symm_apply_eq _).2 $ by simp [linear_independent.total_equiv]\n\n/-- Isomorphism between the two modules, given two modules `M` and `M'` with respective bases\n`v` and `v'` and a bijection between the indexing sets of the two bases. -/\ndef linear_equiv_of_is_basis {v : \u03b9 \u2192 M} {v' : \u03b9' \u2192 M'} (hv : is_basis R v) (hv' : is_basis R v')\n  (e : \u03b9 \u2243 \u03b9') : M \u2243\u2097[R] M' :=\n{ inv_fun := hv'.constr (v \u2218 e.symm),\n  left_inv := have (hv'.constr (v \u2218 e.symm)).comp (hv.constr (v' \u2218 e)) = linear_map.id,\n      from hv.ext $ by simp,\n    \u03bb x, congr_arg (\u03bb h : M \u2192\u2097[R] M, h x) this,\n  right_inv := have (hv.constr (v' \u2218 e)).comp (hv'.constr (v \u2218 e.symm)) = linear_map.id,\n      from hv'.ext $ by simp,\n    \u03bb y, congr_arg (\u03bb h : M' \u2192\u2097[R] M', h y) this,\n  ..hv.constr (v' \u2218 e) }\n\n/-- Isomorphism between the two modules, given two modules `M` and `M'` with respective bases\n`v` and `v'` and a bijection between the two bases. -/\ndef linear_equiv_of_is_basis' {v : \u03b9 \u2192 M} {v' : \u03b9' \u2192 M'} (f : M \u2192 M') (g : M' \u2192 M)\n  (hv : is_basis R v) (hv' : is_basis R v')\n  (hf : \u2200i, f (v i) \u2208 range v') (hg : \u2200i, g (v' i) \u2208 range v)\n  (hgf : \u2200i, g (f (v i)) = v i) (hfg : \u2200i, f (g (v' i)) = v' i) :\n  M \u2243\u2097 M' :=\n{ inv_fun := hv'.constr (g \u2218 v'),\n  left_inv :=\n    have (hv'.constr (g \u2218 v')).comp (hv.constr (f \u2218 v)) = linear_map.id,\n    from hv.ext $ \u03bb i, exists.elim (hf i)\n      (\u03bb i' hi', by simp [constr_basis, hi'.symm]; rw [hi', hgf]),\n    \u03bb x, congr_arg (\u03bb h:M \u2192\u2097[R] M, h x) this,\n  right_inv :=\n    have (hv.constr (f \u2218 v)).comp (hv'.constr (g \u2218 v')) = linear_map.id,\n    from hv'.ext $ \u03bb i', exists.elim (hg i')\n      (\u03bb i hi, by simp [constr_basis, hi.symm]; rw [hi, hfg]),\n    \u03bb y, congr_arg (\u03bb h:M' \u2192\u2097[R] M', h y) this,\n  ..hv.constr (f \u2218 v) }\n\n@[simp] lemma linear_equiv_of_is_basis_comp {\u03b9'' : Type*} {v : \u03b9 \u2192 M} {v' : \u03b9' \u2192 M'}\n  {v'' : \u03b9'' \u2192 M''} (hv : is_basis R v) (hv' : is_basis R v') (hv'' : is_basis R v'')\n  (e : \u03b9 \u2243 \u03b9') (f : \u03b9' \u2243 \u03b9'' ) :\n  (linear_equiv_of_is_basis hv hv' e).trans (linear_equiv_of_is_basis hv' hv'' f) =\n  linear_equiv_of_is_basis hv hv'' (e.trans f) :=\nbegin\n  apply linear_equiv.to_linear_map_injective,\n  apply hv.ext,\n  intros i,\n  simp [linear_equiv_of_is_basis]\nend\n\n@[simp] lemma linear_equiv_of_is_basis_refl :\n  linear_equiv_of_is_basis hv hv (equiv.refl \u03b9) = linear_equiv.refl R M :=\nbegin\n  apply linear_equiv.to_linear_map_injective,\n  apply hv.ext,\n  intros i,\n  simp [linear_equiv_of_is_basis]\nend\n\nlemma linear_equiv_of_is_basis_trans_symm (e : \u03b9 \u2243 \u03b9') {v' : \u03b9' \u2192 M'} (hv' : is_basis R v') :\n  (linear_equiv_of_is_basis hv hv' e).trans (linear_equiv_of_is_basis hv' hv e.symm) =\n  linear_equiv.refl R M :=\nby simp\n\nlemma linear_equiv_of_is_basis_symm_trans (e : \u03b9 \u2243 \u03b9') {v' : \u03b9' \u2192 M'} (hv' : is_basis R v') :\n  (linear_equiv_of_is_basis hv' hv e.symm).trans (linear_equiv_of_is_basis hv hv' e) =\n  linear_equiv.refl R M' :=\nby simp\n\nlemma is_basis_inl_union_inr {v : \u03b9 \u2192 M} {v' : \u03b9' \u2192 M'}\n  (hv : is_basis R v) (hv' : is_basis R v') :\n  is_basis R (sum.elim (inl R M M' \u2218 v) (inr R M M' \u2218 v')) :=\nbegin\n  split,\n  apply linear_independent_inl_union_inr' hv.1 hv'.1,\n  rw [sum.elim_range, span_union,\n      set.range_comp, span_image (inl R M M'), hv.2,  map_top,\n      set.range_comp, span_image (inr R M M'), hv'.2, map_top],\n  exact linear_map.sup_range_inl_inr\nend\n\n@[simp] lemma is_basis.repr_eq_zero {x : M} :\n  hv.repr x = 0 \u2194 x = 0 :=\n\u27e8\u03bb h, (hv.total_repr x).symm.trans (h.symm \u25b8 (finsupp.total _ _ _ _).map_zero),\n \u03bb h, h.symm \u25b8 hv.repr.map_zero\u27e9\n\nlemma is_basis.ext_elem {x y : M}\n  (h : \u2200 i, hv.repr x i = hv.repr y i) : x = y :=\nby { rw [\u2190 hv.total_repr x, \u2190 hv.total_repr y], congr' 1, ext i, exact h i }\n\nsection\n\ninclude hv\n\n-- Can't be an instance because the basis can't be inferred.\nlemma is_basis.no_zero_smul_divisors [no_zero_divisors R] :\n  no_zero_smul_divisors R M :=\n\u27e8\u03bb c x hcx, or_iff_not_imp_right.mpr (\u03bb hx, begin\n  rw [\u2190 hv.total_repr x, \u2190 linear_map.map_smul] at hcx,\n  have := linear_independent_iff.mp hv.1 (c \u2022 hv.repr x) hcx,\n  rw smul_eq_zero at this,\n  exact this.resolve_right (\u03bb hr, hx (hv.repr_eq_zero.mp hr))\nend)\u27e9\n\nlemma is_basis.smul_eq_zero [no_zero_divisors R] {c : R} {x : M} :\n  c \u2022 x = 0 \u2194 c = 0 \u2228 x = 0 :=\n@smul_eq_zero _ _ _ _ _ hv.no_zero_smul_divisors _ _\n\nend\n\nend is_basis\n\nlemma is_basis_singleton_iff\n  {R : Type*} [ring R] [nontrivial R] [module R M] [no_zero_smul_divisors R M]\n  (\u03b9 : Type*) [unique \u03b9] (x : M) :\n  is_basis R (\u03bb (_ : \u03b9), x) \u2194 x \u2260 0 \u2227 \u2200 y : M, \u2203 r : R, r \u2022 x = y :=\nbegin\n  fsplit,\n  rintro \u27e8li, sp\u27e9,\n  fsplit,\n  apply linear_independent.ne_zero (default \u03b9) li,\n  simpa [span_singleton_eq_top_iff] using sp,\n  rintro \u27e8nz, w\u27e9,\n  fsplit,\n  simpa [linear_independent_unique_iff] using nz,\n  simpa [span_singleton_eq_top_iff] using w,\nend\n\nlemma is_basis_singleton_one (R : Type*) [unique \u03b9] [ring R] :\n  is_basis R (\u03bb (_ : \u03b9), (1 : R)) :=\nbegin\n  split,\n  { refine linear_independent_iff.2 (\u03bb l hl, _),\n    rw [finsupp.total_unique, smul_eq_mul, mul_one] at hl,\n    exact finsupp.unique_ext hl },\n  { refine top_unique (\u03bb _ _, _),\n    simp only [mem_span_singleton, range_const, mul_one, exists_eq, smul_eq_mul] }\nend\n\nprotected lemma linear_equiv.is_basis (hs : is_basis R v)\n  (f : M \u2243\u2097[R] M') : is_basis R (f \u2218 v) :=\nbegin\n  split,\n  { simpa only using hs.1.map' (f : M \u2192\u2097[R] M') f.ker },\n  { rw [set.range_comp, \u2190 linear_equiv.coe_coe, span_image, hs.2, map_top, f.range] }\nend\n\nlemma is_basis_span (hs : linear_independent R v) :\n  @is_basis \u03b9 R (span R (range v)) (\u03bb i : \u03b9, \u27e8v i, subset_span (mem_range_self _)\u27e9) _ _ _ :=\nbegin\nsplit,\n{ apply linear_independent_span hs },\n{ rw eq_top_iff',\n  intro x,\n  have h\u2081 : subtype.val '' set.range (\u03bb i, subtype.mk (v i) _) = range v,\n    by rw \u2190set.range_comp,\n  have h\u2082 : map (submodule.subtype _) (span R (set.range (\u03bb i, subtype.mk (v i) _)))\n              = span R (range v),\n    by rw [\u2190span_image, submodule.subtype_eq_val, h\u2081],\n  have h\u2083 : (x : M) \u2208 map (submodule.subtype _) (span R (set.range (\u03bb i, subtype.mk (v i) _))),\n    by rw h\u2082; apply subtype.mem x,\n  rcases mem_map.1 h\u2083 with \u27e8y, hy\u2081, hy\u2082\u27e9,\n  have h_x_eq_y : x = y,\n    by rw [subtype.ext_iff, \u2190 hy\u2082]; simp,\n  rw h_x_eq_y,\n  exact hy\u2081 }\nend\n\nvariables (M)\n\nlemma is_basis_empty [subsingleton M] (h_empty : \u00ac nonempty \u03b9) : is_basis R (\u03bb x : \u03b9, (0 : M)) :=\n\u27e8 linear_independent_empty_type h_empty, subsingleton.elim _ _ \u27e9\n\nvariables {M}\n\nopen fintype\nvariables [fintype \u03b9] (h : is_basis R v)\n\n/-- A module over `R` with a finite basis is linearly equivalent to functions from its basis to `R`.\n-/\ndef is_basis.equiv_fun : M \u2243\u2097[R] (\u03b9 \u2192 R) :=\nlinear_equiv.trans (module_equiv_finsupp h)\n  { to_fun := coe_fn,\n    map_add' := finsupp.coe_add,\n    map_smul' := finsupp.coe_smul,\n    ..finsupp.equiv_fun_on_fintype }\n\n/-- A module over a finite ring that admits a finite basis is finite. -/\ndef module.fintype_of_fintype [fintype R] : fintype M :=\nfintype.of_equiv _ h.equiv_fun.to_equiv.symm\n\ntheorem module.card_fintype [fintype R] [fintype M] :\n  card M = (card R) ^ (card \u03b9) :=\ncalc card M = card (\u03b9 \u2192 R)    : card_congr h.equiv_fun.to_equiv\n        ... = card R ^ card \u03b9 : card_fun\n\n/-- Given a basis `v` indexed by `\u03b9`, the canonical linear equivalence between `\u03b9 \u2192 R` and `M` maps\na function `x : \u03b9 \u2192 R` to the linear combination `\u2211_i x i \u2022 v i`. -/\n@[simp] lemma is_basis.equiv_fun_symm_apply (x : \u03b9 \u2192 R) :\n  h.equiv_fun.symm x = \u2211 i, x i \u2022 v i :=\nbegin\n  change finsupp.sum\n      ((finsupp.equiv_fun_on_fintype.symm : (\u03b9 \u2192 R) \u2243 (\u03b9 \u2192\u2080 R)) x) (\u03bb (i : \u03b9) (a : R), a \u2022 v i)\n    = \u2211 i, x i \u2022 v i,\n  dsimp [finsupp.equiv_fun_on_fintype, finsupp.sum],\n  rw finset.sum_filter,\n  refine finset.sum_congr rfl (\u03bbi hi, _),\n  by_cases H : x i = 0; simp [H]\nend\n\nlemma is_basis.equiv_fun_apply (u : M) : h.equiv_fun u = h.repr u := rfl\n\nlemma is_basis.equiv_fun_total (u : M) : \u2211 i, h.equiv_fun u i \u2022 v i = u:=\nbegin\n  conv_rhs { rw \u2190 h.total_repr u },\n  simp [finsupp.total_apply, finsupp.sum_fintype, h.equiv_fun_apply]\nend\n\n@[simp]\nlemma is_basis.equiv_fun_self (i j : \u03b9) : h.equiv_fun (v i) j = if i = j then 1 else 0 :=\nby { rw [h.equiv_fun_apply, h.repr_self_apply] }\n\n@[simp] theorem is_basis.constr_apply_fintype (f : \u03b9 \u2192 M') (x : M) :\n  (h.constr f : M \u2192 M') x = \u2211 i, (h.equiv_fun x i) \u2022 f i :=\nby simp [h.constr_apply, h.equiv_fun_apply, finsupp.sum_fintype]\n\nend module\n\nsection vector_space\n\nvariables [field K] [add_comm_group V] [add_comm_group V'] [module K V] [module K V']\nvariables {v : \u03b9 \u2192 V} {s t : set V} {x y z : V}\n\ninclude K\n\nopen submodule\n\nlemma exists_subset_is_basis (hs : linear_independent K (\u03bb x, x : s \u2192 V)) :\n  \u2203b, s \u2286 b \u2227 is_basis K (coe : b \u2192 V) :=\nlet \u27e8b, hb\u2080, hx, hb\u2082, hb\u2083\u27e9 := exists_linear_independent hs (@subset_univ _ _) in\n\u27e8 b, hx,\n  @linear_independent.restrict_of_comp_subtype _ _ _ id _ _ _ _ hb\u2083,\n  by simp; exact eq_top_iff.2 hb\u2082\u27e9\n\nlemma exists_sum_is_basis (hs : linear_independent K v) :\n  \u2203 (\u03b9' : Type u) (v' : \u03b9' \u2192 V), is_basis K (sum.elim v v') :=\nbegin\n  -- This is a hack: we jump through hoops to reuse `exists_subset_is_basis`.\n  let s := set.range v,\n  let e : \u03b9 \u2243 s := equiv.of_injective v hs.injective,\n  have : (\u03bb x, x : s \u2192 V) = v \u2218 e.symm := by { ext, dsimp, rw [equiv.apply_of_injective_symm v] },\n  have : linear_independent K (\u03bb x, x : s \u2192 V),\n  { rw this,\n    exact linear_independent.comp hs _ (e.symm.injective), },\n  obtain \u27e8b, ss, is\u27e9 := exists_subset_is_basis this,\n  let e' : \u03b9 \u2295 (b \\ s : set V) \u2243 b :=\n  calc \u03b9 \u2295 (b \\ s : set V) \u2243 s \u2295 (b \\ s : set V) : equiv.sum_congr e (equiv.refl _)\n                       ... \u2243 b                   : equiv.set.sum_diff_subset ss,\n  refine \u27e8(b \\ s : set V), \u03bb x, x.1, _\u27e9,\n  convert is_basis.comp is e' _,\n  { funext x,\n    cases x; simp; refl, },\n  { exact e'.bijective, },\nend\n\nvariables (K V)\nlemma exists_is_basis : \u2203b : set V, is_basis K (\u03bb i, i : b \u2192 V) :=\nlet \u27e8b, _, hb\u27e9 := exists_subset_is_basis (linear_independent_empty K V : _) in \u27e8b, hb\u27e9\nvariables {K V}\n\nlemma linear_map.exists_left_inverse_of_injective (f : V \u2192\u2097[K] V')\n  (hf_inj : f.ker = \u22a5) : \u2203g:V' \u2192\u2097 V, g.comp f = linear_map.id :=\nbegin\n  rcases exists_is_basis K V with \u27e8B, hB\u27e9,\n  have hB\u2080 : _ := hB.1.to_subtype_range,\n  have : linear_independent K (\u03bb x, x : f '' B \u2192 V'),\n  { have h\u2081 := hB\u2080.image_subtype\n      (show disjoint (span K (range (\u03bb i : B, i.val))) (linear_map.ker f), by simp [hf_inj]),\n    rwa subtype.range_coe at h\u2081 },\n  rcases exists_subset_is_basis this with \u27e8C, BC, hC\u27e9,\n  haveI : inhabited V := \u27e80\u27e9,\n  use hC.constr (C.restrict (inv_fun f)),\n  refine hB.ext (\u03bb b, _),\n  rw image_subset_iff at BC,\n  have : f b = (\u27e8f b, BC b.2\u27e9 : C) := rfl,\n  dsimp,\n  rw [this, constr_basis hC],\n  exact left_inverse_inv_fun (linear_map.ker_eq_bot.1 hf_inj) _\nend\n\nlemma submodule.exists_is_compl (p : submodule K V) : \u2203 q : submodule K V, is_compl p q :=\nlet \u27e8f, hf\u27e9 := p.subtype.exists_left_inverse_of_injective p.ker_subtype in\n\u27e8f.ker, linear_map.is_compl_of_proj $ linear_map.ext_iff.1 hf\u27e9\n\ninstance module.submodule.is_complemented : is_complemented (submodule K V) :=\n\u27e8submodule.exists_is_compl\u27e9\n\nlemma linear_map.exists_right_inverse_of_surjective (f : V \u2192\u2097[K] V')\n  (hf_surj : f.range = \u22a4) : \u2203g:V' \u2192\u2097 V, f.comp g = linear_map.id :=\nbegin\n  rcases exists_is_basis K V' with \u27e8C, hC\u27e9,\n  haveI : inhabited V := \u27e80\u27e9,\n  use hC.constr (C.restrict (inv_fun f)),\n  refine hC.ext (\u03bb c, _),\n  simp [constr_basis hC, right_inverse_inv_fun (linear_map.range_eq_top.1 hf_surj) c]\nend\n\n/-- Any linear map `f : p \u2192\u2097[K] V'` defined on a subspace `p` can be extended to the whole\nspace. -/\nlemma linear_map.exists_extend {p : submodule K V} (f : p \u2192\u2097[K] V') :\n  \u2203 g : V \u2192\u2097[K] V', g.comp p.subtype = f :=\nlet \u27e8g, hg\u27e9 := p.subtype.exists_left_inverse_of_injective p.ker_subtype in\n\u27e8f.comp g, by rw [linear_map.comp_assoc, hg, f.comp_id]\u27e9\n\nopen submodule linear_map\n\n/-- If `p < \u22a4` is a subspace of a vector space `V`, then there exists a nonzero linear map\n`f : V \u2192\u2097[K] K` such that `p \u2264 ker f`. -/\nlemma submodule.exists_le_ker_of_lt_top (p : submodule K V) (hp : p < \u22a4) :\n  \u2203 f \u2260 (0 : V \u2192\u2097[K] K), p \u2264 ker f :=\nbegin\n  rcases set_like.exists_of_lt hp with \u27e8v, -, hpv\u27e9, clear hp,\n  rcases (linear_pmap.sup_span_singleton \u27e8p, 0\u27e9 v (1 : K) hpv).to_fun.exists_extend with \u27e8f, hf\u27e9,\n  refine \u27e8f, _, _\u27e9,\n  { rintro rfl, rw [linear_map.zero_comp] at hf,\n    have := linear_pmap.sup_span_singleton_apply_mk \u27e8p, 0\u27e9 v (1 : K) hpv 0 p.zero_mem 1,\n    simpa using (linear_map.congr_fun hf _).trans this },\n  { refine \u03bb x hx, mem_ker.2 _,\n    have := linear_pmap.sup_span_singleton_apply_mk \u27e8p, 0\u27e9 v (1 : K) hpv x hx 0,\n    simpa using (linear_map.congr_fun hf _).trans this }\nend\n\ntheorem quotient_prod_linear_equiv (p : submodule K V) :\n  nonempty ((p.quotient \u00d7 p) \u2243\u2097[K] V) :=\nlet \u27e8q, hq\u27e9 := p.exists_is_compl in nonempty.intro $\n((quotient_equiv_of_is_compl p q hq).prod (linear_equiv.refl _ _)).trans\n  (prod_equiv_of_is_compl q p hq.symm)\n\nopen fintype\nvariables (K) (V)\n\ntheorem vector_space.card_fintype [fintype K] [fintype V] :\n  \u2203 n : \u2115, card V = (card K) ^ n :=\nexists.elim (exists_is_basis K V) $ \u03bb b hb, \u27e8card b, module.card_fintype hb\u27e9\n\nend vector_space\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/linear_algebra/basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7498793684575179}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport topology.continuous_function.compact -- funciones continuas, conjuntos compactos\n\n/-!\n\n# Ejercicio\nEn este fichero el objetivo es demostrar que si `f : X \u2192 Y`\nes una funci\u00f3n continua y `S : set X` es un conjunto compacto,\nentonces su imagen `f '' S : set Y` tambi\u00e9n es compacta. \n\nUn lema \u00fatil para esta demostraci\u00f3n es\n\n* `continuous.is_open_preimage` : la preimagen de un abierto bajo\nuna funci\u00f3n continua es un abierto.\n-/\n\n-- Fijamos espacios topol\u00f3gicos X e Y \nvariables (X Y : Type) [topological_space X] [topological_space Y]\n\n-- S es un subconjunto de X\nvariable (S : set X)\n\n-- `f : X \u2192 Y` es una funci\u00f3n\nvariables (f : X \u2192 Y) \n\n-- Si f es continua y S es compacto,  la imagen f(S) tambi\u00e9n es un conjunto compacto.\nexample (hf : continuous f) (hS : is_compact S) : is_compact (f '' S) :=\nbegin\n  rw is_compact_iff_finite_subcover at hS \u22a2,\n  sorry\nend\n\n\n\n\n", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_5/compacto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069105, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.7498793651155738}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.fintype.sort\n! leanprover-community/mathlib commit 509de852e1de55e1efa8eacfa11df0823f26f226\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Sort\nimport Mathlib.Data.Fintype.Basic\n\n/-!\n# Sorting a finite type\n\nThis file provides two equivalences for linearly ordered fintypes:\n* `monoEquivOfFin`: Order isomorphism between `\u03b1` and `Fin (card \u03b1)`.\n* `finSumEquivOfFinset`: Equivalence between `\u03b1` and `Fin m \u2295 Fin n` where `m` and `n` are\n  respectively the cardinalities of some `Finset \u03b1` and its complement.\n-/\n\n\nopen Finset\n\n/-- Given a linearly ordered fintype `\u03b1` of cardinal `k`, the order isomorphism\n`monoEquivOfFin \u03b1 h` is the increasing bijection between `Fin k` and `\u03b1`. Here, `h` is a proof\nthat the cardinality of `\u03b1` is `k`. We use this instead of an isomorphism `Fin (card \u03b1) \u2243o \u03b1` to\navoid casting issues in further uses of this function. -/\ndef monoEquivOfFin (\u03b1 : Type _) [Fintype \u03b1] [LinearOrder \u03b1] {k : \u2115} (h : Fintype.card \u03b1 = k) :\n    Fin k \u2243o \u03b1 :=\n  (univ.orderIsoOfFin h).trans <| (OrderIso.setCongr _ _ coe_univ).trans OrderIso.Set.univ\n#align mono_equiv_of_fin monoEquivOfFin\n\nvariable {\u03b1 : Type _} [DecidableEq \u03b1] [Fintype \u03b1] [LinearOrder \u03b1] {m n : \u2115} {s : Finset \u03b1}\n\n/-- If `\u03b1` is a linearly ordered fintype, `s : Finset \u03b1` has cardinality `m` and its complement has\ncardinality `n`, then `Fin m \u2295 Fin n \u2243 \u03b1`. The equivalence sends elements of Fin m` to\nelements of `s` and elements of `Fin n` to elements of `s\u1d9c` while preserving order on each\n\"half\" of `Fin m \u2295 Fin n` (using `Set.orderIsoOfFin`). -/\ndef finSumEquivOfFinset (hm : s.card = m) (hn : s\u1d9c.card = n) : Sum (Fin m) (Fin n) \u2243 \u03b1 :=\n  calc\n    Sum (Fin m) (Fin n) \u2243 Sum (s : Set \u03b1) (s\u1d9c : Set \u03b1) :=\n      Equiv.sumCongr (s.orderIsoOfFin hm).toEquiv <|\n        (s\u1d9c.orderIsoOfFin hn).toEquiv.trans <| Equiv.Set.ofEq s.coe_compl\n    _ \u2243 \u03b1 := Equiv.Set.sumCompl _\n\n#align fin_sum_equiv_of_finset finSumEquivOfFinset\n\n@[simp]\ntheorem finSumEquivOfFinset_inl (hm : s.card = m) (hn : s\u1d9c.card = n) (i : Fin m) :\n    finSumEquivOfFinset hm hn (Sum.inl i) = s.orderEmbOfFin hm i :=\n  rfl\n#align fin_sum_equiv_of_finset_inl finSumEquivOfFinset_inl\n\n@[simp]\ntheorem finSumEquivOfFinset_inr (hm : s.card = m) (hn : s\u1d9c.card = n) (i : Fin n) :\n    finSumEquivOfFinset hm hn (Sum.inr i) = s\u1d9c.orderEmbOfFin hn i :=\n  rfl\n#align fin_sum_equiv_of_finset_inr finSumEquivOfFinset_inr\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Fintype/Sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7498793616575995}}
{"text": "import data.set.finite\n-- Church numerals\n\n-- Another way of doing nat.\n\n-- The church nat, ch\u2115 (happy to change the name) is a pi type\n-- and not a structure. So proofs are not done by induction!\n--import data.equiv \n\ndef ch\u2115 := \u03a0 X : Type, (X \u2192 X) \u2192 X \u2192 X \nnamespace chnat\n\nopen nat \n-- map from normal nats\ndef of_nat : \u2115 \u2192 ch\u2115 \n| 0 := \u03bb X f x, x\n| (succ n) := \u03bb X f x, f (of_nat n X f x)\n-- can I close nat now?\n\n-- examples of chnats\ndef c0 := of_nat 0\ndef c1 := of_nat 1\ndef c2 := of_nat 2\ndef c3 := of_nat 3\n\n-- now we have some constants.\n\n-- what is zero?\nexample (X f x) : c0 X f x = x := rfl\n-- what is one?\nexample (X f x) : c1 X f x = f x := rfl\n-- what is two?\nexample (X f x) : c2 X f x = f (f x) := rfl\n-- what is three?\nexample (X f x) : c3 X f x = f (f (f x)) := rfl\n-- and so on\n\n-- we can go back from ch\u2115 to \u2115\ndefinition to_nat : ch\u2115 \u2192 \u2115 := \u03bb m, m \u2115 nat.succ 0 -- there is a beauty here\n-- it is almost as if the structure \u2115 were built to be fed into ch\u2115 \n-- Why does this happen? KB doesn't understand\n\n-- that definition needs to be moved if we can't prove functoriality wrt succ\n\nexample : to_nat c3 = 3 := rfl \n\n-- exercise: define succ\ndef succ :ch\u2115 \u2192 ch\u2115 := \u03bb n X f x, f (n X f x) -- KB can do this one\n-- no notation\n\n--unit tests -- KB can pass these\nexample : succ c0 = c1 := rfl\nexample : succ c2 = c3 := rfl\n\nexample (n : \u2115) : of_nat (nat.succ n) = succ (of_nat n) := rfl\n\n--KB can't do this one. Is it unprovable? If so, move definition of to_nat much further down.\nexample (m : ch\u2115) : to_nat (succ m) = nat.succ (to_nat m) := rfl\n--Kenny can do this one, lol.\n\n-- exercise : define add\ndef add : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 := \u03bb m n X f x, n X f (m X f x) -- KB can do this\ninstance : has_add ch\u2115 := \u27e8add\u27e9 -- now we have + notation\n\nexample : c2 + c1 = c3 := rfl\n-- KB didn't do this one yet but feels it should be true.\ntheorem of_nat.add (m n : \u2115) : of_nat (m + n) = of_nat m + of_nat n :=\nbegin\n  induction n with n ih,\n  { refl },\n  { simp [of_nat, ih], simp [(+), add] }\nend\n\n-- exercise : define mul\ndef mul : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 := \u03bb m n X f, n X (m X f) -- KB can do this\ninstance : has_mul ch\u2115 := \u27e8mul\u27e9 -- incantation to give us *\n\n-- KB can do this one\nexample : c1 + c2 + c3 = c2 * c3 := rfl\n-- KB didn't try this one\ntheorem of_nat.mul (m n : \u2115) : of_nat (m * n) = of_nat m * of_nat n :=\nbegin\n  induction n with n ih,\n  { refl },\n  { rw nat.mul_comm at ih,\n    rw [nat.mul_succ, nat.mul_comm, of_nat.add, of_nat, ih],\n    dsimp [(*), mul, (+), add],\n    refl }\nend\n\n-- exercise : define pow\ndef pow : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 := \u03bb m n X, n (X \u2192 X) (m X) -- KB can do this one\n-- instance : has_pow ch\u2115 := \u27e8pow\u27e9 -- doesn't seem to work\n\n-- KB can do this\nexample : pow c2 c3 + c1 = pow c3 c2 := rfl\n-- KB didn't try this\nexample (m n : \u2115) : of_nat (nat.pow m n) = pow (of_nat m) (of_nat n) :=\nbegin\n  induction n with n ih,\n  { refl },\n  { unfold nat.pow,\n    unfold of_nat,\n    rw [of_nat.mul, ih],\n    unfold pow,\n    dsimp [(*), mul],\n    refl }\nend\n\n-- exercise : define Ackermann\ndef ack : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 :=\n\u03bb m n X, m ((((X \u2192 X) \u2192 (X \u2192 X)) \u2192 (X \u2192 X) \u2192 (X \u2192 X)) \u2192 ((X \u2192 X) \u2192 X \u2192 X))\n  (\u03bb m_ih n f, n\n    (\u03bb n_ih x, m_ih sorry f x) -- n_ih represents f\n-- composed with itself Ack(m,n) times, but I need\n-- to convert it to a church numeral in \"sorry\".\n    (\u03bb x, m_ih id f x))\n  (\u03bb n f, n\n    (\u03bb n_ih x, f (n_ih x))\n    (\u03bb x, f x))\n  (n (X \u2192 X)) -- KB didn't try this one\n-- Is it possible?\n-- Kenny : I don't think it is possible, since you need to\n-- recursively build a Type 1 function, whereas ch\u2115 only\n-- permits recursion on Type 0 stuff.\n\n-- if it's possible, prove it agrees with usual ackermnann\n-- example : ack m n = ack (of_nat m) (of_nat n) := sorry\n\n-- question : Is this provable? KB couldn't do this one\ntheorem add_comm (m n : ch\u2115) : m + n = n + m := sorry \n\n-- KB thinks this might be ch\u2115's free theorem\n-- KB can't prove it\ntheorem free_chnat : \u2200 (A B : Type), \u2200 f : A \u2192 B, \n\u2200 r : ch\u2115, \u2200 a : A, r (A \u2192 B) (\u03bb g,f) f a  = r (A \u2192 B) (\u03bb g,g) f a \n := sorry\n\nstructure equiv' (\u03b1 : Sort*) (\u03b2 : Sort*) :=\n(to_fun    : \u03b1 \u2192 \u03b2)\n(inv_fun   : \u03b2 \u2192 \u03b1)\n(left_inv  : \u2200 (x : \u03b1), inv_fun (to_fun x) = x)\n(right_inv : \u2200 (y : \u03b2), to_fun (inv_fun y) = y)\n\n-- is \u2115 equiv to ch\u2115 ?\n\ntheorem ij : \u2200 n : \u2115, to_nat (of_nat n) = n := begin\nintro n,\ninduction n with d Hd,refl,\nunfold of_nat,\nunfold to_nat,\nunfold to_nat at Hd,\nrw Hd,\nend\n\n-- KB can't do this one\ntheorem ji : \u2200 c : ch\u2115, of_nat (to_nat c) = c := sorry\n-- Can someone write down an uncomputable counterexample?\n\n-- so KB can't do this either\ndefinition \u2115_is_ch\u2115 : equiv' \u2115 ch\u2115 := sorry \n\n-- idle question\ntheorem is_it_true (X : Type) (f : X \u2192 X) (x : X) : f x = x := sorry\n\n-- bad church numeral\nlocal attribute [instance] classical.prop_decidable\nnoncomputable definition satan (X : Type) (f : X \u2192 X) (x : X) := dite (X = \u2115) (\u03bb H,begin show X,rw H,rw H at x,exact x end) (\u03bb _,f x)\n#check (satan : ch\u2115) -- 1 everywhere apart from nat, where it's zero\n\nlemma bool_not_nat : bool \u2260 \u2115 := \u03bb h,\nby haveI : fintype \u2115 := eq.rec_on h (by apply_instance);\nexact set.not_injective_nat_fintype @nat.succ_inj\n\ntheorem satan_is_bad : of_nat (to_nat satan) = satan \u2192 false :=\nbegin\nintro H,\nhave H2 : (of_nat (to_nat satan)) bool bnot tt = satan bool bnot tt := by rw H,\nunfold to_nat at H2,\nunfold satan at H2,\nsimp at H2,\nchange tt = _ at H2,\nsuffices : \u00ac (bool = \u2115),\nsimp [this] at H2,assumption,\nexact bool_not_nat,\nend \n\n\nend chnat\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/canonical_isomorphism/kenny_church+proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7497224744031027}}
{"text": "@[elab_as_eliminator]\nlemma nat_ind\n  {P : \u2115 \u2192 Prop}\n  (zero : P 0)\n  (successor : \u2200 n, P n \u2192 P (n + 1)) (n : \u2115)\n  : P n :=\nnat.rec zero successor n\n\nexample\n  {P : \u2115 \u2192 Prop}\n  (z : P 0)\n  (s : \u2200 n, P n \u2192 P (n + 1)) (n : \u2115)\n  : P n :=\nbegin\n  with_cases { apply nat_ind },\n  case zero { exact z},\n  case successor : m ih { exact s m ih }\nend\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Principio_de_induccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7497224602225955}}
{"text": "theorem le_succ (a b : mynat) : a \u2264 b \u2192 a \u2264 (succ b) :=\nbegin\nintro h,\ncases h with c hc,\nuse c + 1,\nrw add_one_eq_succ,\nrw add_succ,\nrw hc,\nrefl,\nend", "meta": {"author": "nicholaspun", "repo": "natural-number-game-solutions", "sha": "1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0", "save_path": "github-repos/lean/nicholaspun-natural-number-game-solutions", "path": "github-repos/lean/nicholaspun-natural-number-game-solutions/natural-number-game-solutions-1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0/8-inequality-world/l3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7497071607586601}}
{"text": "import tactic\n\n/-- The equivalence relation on \u2115\u00b2 such that equivalence classes are \u2124 -/\ndef nat2.R (a b : \u2115 \u00d7 \u2115) : Prop :=\na.1 + b.2 = b.1 + a.2\n-- here a and b are pairs, so a = (a.1, a.2) etc.\n\n-- introduce \u2248 (type with `\\~~`) notation for this relation\ninstance : has_equiv (\u2115 \u00d7 \u2115) := \u27e8nat2.R\u27e9\n\n-- let's prove some lemmas about this binary relation\nnamespace nat2.R\n\n-- The following lemma is true by definition, but it's useful to\n-- have it around so you can rewrite with it\nlemma equiv_def {i j k l : \u2115} : (i, j) \u2248 (k, l) \u2194 i + l = k + j :=\nbegin\n  refl\nend\n\n-- try rewriting `equiv_def`\nlemma practice : (3, 5) \u2248 (4, 6) :=\nbegin\n  sorry\nend\n\n-- Now let's prove that this binary relation is an equivalence relation\nlemma reflexive : \u2200 x : \u2115 \u00d7 \u2115, x \u2248 x :=\nbegin\n  -- let x be (i,j)\n  rintro \u27e8i, j\u27e9,\n  sorry\nend\n\nlemma symmetric : \u2200 x y : \u2115 \u00d7 \u2115, (x \u2248 y) \u2192 (y \u2248 x) :=\nbegin\n  -- here are a couple of tricks\n  rintro \u27e8i, j\u27e9 \u27e8k, l\u27e9 h,\n  -- type `\u22a2` with `\\|-` \n  rw equiv_def at h \u22a2,\n  sorry\nend\n\n-- sub-boss\n\nlemma transitive : \u2200 x y z : \u2115 \u00d7 \u2115, (x \u2248 y) \u2192 (y \u2248 z) \u2192 (x \u2248 z) :=\nbegin\n  -- this is a little trickier\n  -- recall `add_left_inj a` says `b + a = c + a \u2194 b = c`\n  -- and you might want to consider rewriting it in the \u2190 direction\n  sorry\nend\n\n-- This line tells Lean that the binary relation is an equivalence\n-- relation and hence we can take the \"quotient\", i.e. the\n-- type of equivalence classes\ninstance setoid : setoid (\u2115 \u00d7 \u2115) :=\n{ r := nat2.R,\n  iseqv := \u27e8reflexive, symmetric, transitive\u27e9 }\n\n-- end of lemmas about the binary relation\nend nat2.R\n\n-- ...but we're still going to be using them\nopen nat2.R\n\n/-- The integers are the equivalence classes of the equivalence relation\n we just defined on \u2115\u00b2  -/\ndef myint := quotient nat2.R.setoid\n\n-- let's make some definitions, and prove some theorems, about integers\nnamespace myint \n\n-- The first goal is to get a good interface for addition.\n-- To do this we need to define a+b, and -a, and 0. Let's do\n-- them in reverse order.\n\n/-! ## zero -/\n\n-- Notation: \u27e6(a,b)\u27e7 \u2208 \u2124 is the equivalence class of (a,b) \u2208 \u2115\u00b2\n\n/-- 0 is the equivalence class of (0,0) -/\ndef zero := \u27e6(0,0)\u27e7\n\n-- Notation 0 for zero\ninstance : has_zero myint := \u27e8myint.zero\u27e9\n\n-- true by definition\nlemma zero_def : (0 : myint) = \u27e6(0, 0)\u27e7 :=\nbegin\n  sorry\nend\n\n/-! ## negation (additive inverse) -/\n\n-- First we define an \"auxiliary\" map from \u2115\u00b2 to \u2124 \n-- sending (a,b) to the equivalence class of (b,a).\n\ndef neg_aux (x : \u2115 \u00d7 \u2115) : myint := \u27e6(x.2, x.1)\u27e7\n\n-- true by definition\nlemma neg_aux_def (i j : \u2115) : neg_aux (i, j) = \u27e6(j, i)\u27e7 :=\nbegin\n  sorry\nend\n\n/-! ### Well-definedness of negation\n\nOK now here's the concrete problem. We would like to define\na negation map `\u2124 \u2192 \u2124` sending `z` to `-z`. We want to do this in\nthe following way: Say `z \u2208 \u2124`. Choose `a=(i,j) \u2208 \u2115\u00b2` representing `z`\n(i.e. such that `cl(i,j) = \u27e6(i,j)\u27e7 = z`)\nNow apply `neg_aux` to `a`, and define `-z` to be the result.\n\nThe problem with this is that what if `b` is a different\nelement of the equivalence class? Then we also want `-z` to be `neg_aux b`.\n\nIndeed, in Lean this construction is called `quotient.lift`, and\nif you uncomment the below code\n-/\n\n--def neg : myint \u2192 myint :=\n--quotient.lift neg_aux _\n\n/-\nyou'll see an error, and if you put your cursor on the error you'll\nsee that Lean wants a proof that if two elements `a` and `b` are in the\nsame equivalence class, then `neg_aux a = neg_aux b`. So let's prove this now.\n\nYou'll need to know `quotient.sound : a \u2248 b \u2192 \u27e6a\u27e7 = \u27e6b\u27e7`\n-/\n\n\n-- negation on the integers, defined via neg_aux, is well-defined.\nlemma neg_aux_lemma : \u2200 x y : \u2115 \u00d7 \u2115, x \u2248 y \u2192 neg_aux x = neg_aux y :=\nbegin\n  rintro \u27e8i,j\u27e9 \u27e8k,l\u27e9 h,\n  rw [neg_aux_def, neg_aux_def],\n  -- \u22a2 \u27e6(j, i)\u27e7 = \u27e6(l, k)\u27e7\n  -- next step: if \u27e6a\u27e7=\u27e6b\u27e7 then a \u2248 b\n  apply quotient.sound,\n  -- \u22a2 (j, i) \u2248 (l, k)\n  -- take it from here.\n  sorry\nend\n\n-- Note that we use `neg_aux_lemma` in the definition below\n-- to justify well-definedness of `neg`\n\n/-- Negation on on the integers. The function sending `z` to `-z`. -/\ndef neg : myint \u2192 myint :=\nquotient.lift neg_aux neg_aux_lemma\n\n-- notation for negation\ninstance : has_neg myint := \u27e8neg\u27e9\n\n-- We can now write `-z` if `z : myint`\n\n-- this is true by definition\nlemma neg_def (i j : \u2115) : (-\u27e6(i, j)\u27e7 : myint) = \u27e6(j, i)\u27e7 :=\nbegin\n  sorry\nend\n\n/-!  ## addition\n\nOur final construction: we want to define addition on `myint`. \nHere we have the same problem. Say z\u2081 and z\u2082 are integers.\nChoose elements a\u2081=(i,j) and a\u2082=(k,l) in \u2115\u00b2. We want to define\nz\u2081 + z\u2082 to be \u27e6(i+k,j+l)\u27e7, the equivalence class of a\u2081 + a\u2082.\nWe will need to check this is well-defined.\n\n-/\n\n/-- An auxiliary function taking two elements of \u2115\u00b2 and returning\nthe equivalence class of their sum. -/\ndef add_aux (x y : \u2115 \u00d7 \u2115) : myint := \u27e6(x.1 + y.1, x.2 + y.2)\u27e7\n\n-- true by definition\nlemma add_aux_def (i j k l : \u2115) : add_aux (i, j) (k, l) = \u27e6(i + k, j + l)\u27e7 :=\nbegin\n  sorry\nend\n\n/-\n\nWe want the definition of addition to look like the below.\nUncomment it to see the problem. \n\n-/\n\n--def add : myint \u2192 myint \u2192 myint :=\n--quotient.lift\u2082 add_aux _\n\n/-\nWe had better check that choosing different elements in the same\nequivalence class gives the same definition.\n\n-/\n\nlemma add_aux_lemma : \u2200 x\u2081 x\u2082 y\u2081 y\u2082 : \u2115 \u00d7 \u2115,\n(x\u2081 \u2248 y\u2081) \u2192 (x\u2082 \u2248 y\u2082) \u2192 add_aux x\u2081 x\u2082 = add_aux y\u2081 y\u2082 :=\nbegin\n  sorry\nend\n\n-- Now this is checked, we can define addition: it's well-defined.\n\n/-- Addition on the integers -/\ndef add : myint \u2192 myint \u2192 myint :=\nquotient.lift\u2082 add_aux add_aux_lemma\n\n-- notation for addition\ninstance : has_add myint := \u27e8add\u27e9\n\n-- true by definition\nlemma add_def (i j k l : \u2115) :\n  (\u27e6(i, j)\u27e7 + \u27e6(k, l)\u27e7 : myint) = \u27e6(i + k, j + l)\u27e7 :=\nbegin\n  sorry\nend\n\n/-\nThe four fundamental facts about addition on the integers are:\n1) associativity\n2) commutativity\n3) zero is an additive identity\n4) negation is an additive inverse.\n\nLet's prove these now.\n\n-/\n\nlemma zero_add (x : myint) : 0 + x = x :=\nbegin\n  -- need to get from \u2124 back to \u2115\u00b2\n  apply quotient.induction_on x,\n  sorry,\nend\n\nlemma add_zero (x : myint) : x + 0 = x :=\nbegin\n  sorry\nend\n\nlemma add_left_neg (x : myint) : -x + x = 0 :=\nbegin\n  sorry\nend\n\n-- here we need to change both x and y into elements of \u2115\u00b2\nlemma add_comm (x y : myint) : x + y = y + x :=\nbegin\n  apply quotient.induction_on\u2082 x y,\n  sorry\nend\n\nlemma add_assoc (x y z : myint) : (x + y) + z = x + (y + z) :=\nbegin\n  sorry,\nend\n\n-- The lemmas above are the axioms for a commutative group.\n\n-- Hence we just proved that the integers are a\n-- commutative group under addition!\n\ninstance : add_comm_group myint :=\n{ add := (+),\n  add_assoc := add_assoc,\n  zero := 0,\n  zero_add := zero_add,\n  add_zero := add_zero,\n  neg := has_neg.neg,\n  add_left_neg := add_left_neg,\n  add_comm := add_comm }\n\n-- woohoo!\n\n/-! ## multiplication\n\nWhat's left to define is 1 and multiplication (note that we don't need multiplicative\ninverses -- if a is a non-zero integer then a\u207b\u00b9 is typially not an integer)\n\n-/\n\ndef mul_aux (x y : \u2115 \u00d7 \u2115) : myint := \u27e6(sorry, sorry)\u27e7\n\n-- true by definition\nlemma mul_aux_def (i j k l : \u2115) : mul_aux (i, j) (k, l) = sorry :=\nbegin\n  sorry\nend\n\n-- Boss level. \n-- Dr. Lawn: \"We leave the similar verification for multiplication as an exercise.\"\n\n-- This is what we need to check for multiplication to \"descend\" (or \"lift\" as Lean\n-- calls it) to a well-defined function on the quotient. \nlemma mul_aux_lemma : \u2200 x\u2081 x\u2082 y\u2081 y\u2082 : \u2115 \u00d7 \u2115,\n(x\u2081 \u2248 y\u2081) \u2192 (x\u2082 \u2248 y\u2082) \u2192 mul_aux x\u2081 x\u2082 = mul_aux y\u2081 y\u2082 :=\nbegin\n  sorry\nend\n\n-- It's much easier from here on\n\n-- definition of multiplication\ndef mul : myint \u2192 myint \u2192 myint :=\nquotient.lift\u2082 mul_aux mul_aux_lemma\n\ninstance : has_mul myint := \u27e8mul\u27e9 \n\n-- true by definition\nlemma mul_def (i j k l : \u2115) : (\u27e6(i, j)\u27e7 * \u27e6(k, l)\u27e7 : myint) = \u27e6(sorry, sorry)\u27e7 :=\nbegin\n  sorry\nend\n\nlemma mul_assoc (x y z : myint) : (x * y) * z = x * (y * z) :=\nbegin\n  sorry\nend\n\ndef one : myint := \u27e6(sorry, sorry)\u27e7\n\ninstance : has_one myint := \u27e8myint.one\u27e9\n\n-- true by definition\nlemma one_def : (1 : myint) = sorry :=\nbegin\n  sorry\nend\n\nlemma one_mul (x : myint) : 1 * x = x :=\nbegin\n  sorry\nend\n\nlemma mul_one (x : myint) : x * 1 = x :=\nbegin\n  sorry\nend\n\nlemma mul_comm (x y : myint) : x * y = y * x :=\nbegin\n  sorry\nend\n\nlemma mul_add (x y z : myint) : x * (y + z) = x * y + x * z :=\nbegin\n  sorry\nend\n\nlemma add_mul (x y z : myint) : (x + y) * z = x * z + y * z :=\nbegin\n  sorry\nend\n\n-- The integers are a commutative ring\n-- (that is, they satisfy the axioms we just proved)\ninstance : comm_ring myint :=\n{ mul := (*),\n  mul_assoc := mul_assoc,\n  one := 1,\n  one_mul := one_mul,\n  mul_one := mul_one,\n  left_distrib := mul_add,\n  right_distrib := add_mul,\n  mul_comm := mul_comm,\n  ..myint.add_comm_group }\n\nend myint\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/integers/int_def.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7496759113318602}}
{"text": "import set_theory.cardinal\nimport data.finset.basic\nimport data.stream.basic\nimport tactic\n\nopen_locale classical\nnoncomputable theory\n\n-- Definition 1: Prof V X represents the set of (V, X)-profiles\ndef Prof : Type \u2192 Type \u2192 Type := \u03bb (V X : Type), V \u2192 X \u2192 X \u2192 Prop\n\n-- Definition 2: Given a profile P and x, y \u2208 X(P)\n-- we say that x is majority preferred to y in P if\n-- more voters rank x above y than rank y above x.\ndef majority_preferred {V X : Type} : Prof V X \u2192 X \u2192 X \u2192 Prop := \u03bb P x y,\ncardinal.mk {v : V // P v x y} > cardinal.mk {v : V // P v y x}\n\n-- Definition 3: Given a profile P and x\u2081, x\u2082 \u2208 X(P), \n-- the margin of x\u2081 over x\u2082 in P, denoted Margin\u209a(x\u2081, x\u2082), is \n-- |{i \u2208 V (P) | x\u2081P\u1d62x\u2082}| \u2212 |{i \u2208 V (P) | x\u2082P\u1d62x\u2081}|.\ndef margin {V X : Type} [fintype V] : Prof V X \u2192 X \u2192 X \u2192 \u2124 := \n    \u03bb P x\u2081 x\u2082, \u2191(finset.univ.filter (\u03bb v, P v x\u2081 x\u2082)).card \n    - \u2191(finset.univ.filter (\u03bb v, P v x\u2082 x\u2081)).card\n\n-- The property of skew-symmetry takes in a function \n-- and outputs the proposition stating that the \n-- skew-symmetry equation holds for all pairs:\ndef skew_symmetric {X : Type} : (X \u2192 X \u2192 \u2124) \u2192 Prop := \n    \u03bb M, \u2200 x y, M x y = - M y x.\n\n-- Proof that Margin\u209a is skew-symmetric for any Prof P.\nlemma margin_skew_symmetric {V X : Type} (P : Prof V X) [fintype V] : skew_symmetric (margin P) :=\nbegin\n    unfold margin,\n    obviously,\nend\n\n-- Definition 4: Given a profile P and x \u2208 X(P), we say that x is \n-- a Condorcet winner in P if for all y \u2208 X(P) with y \u2260 x, \n-- x is majority preferred to y in P.\ndef condorcet_winner {V X : Type} (P : Prof V X) (x : X) : Prop := \n    \u2200 y \u2260 x, majority_preferred P x y\n\n-- We say that x is a majority winner in P if the number of voters \n-- who rank x (and only x) in first place is greater than the number \n-- of voters who do not rank x in first place.\ndef majority_winner {V X : Type} (P : Prof V X) (x : X) : Prop := \n    cardinal.mk {v : V // \u2200 y \u2260 x, P v x y} > cardinal.mk {v : V // \u2203 y \u2260 x, P v y x}\n\n-- Proof that a majority winner is a Condorcet winner.\nlemma condorcet_of_majority_winner {V X : Type} (P : Prof V X) [fintype V] (x : X) : majority_winner P x \u2192 condorcet_winner P x :=\nbegin\n    intros majority z z_ne_x, \n    have imp1 : \u2200 v, (\u2200 y \u2260 x, P v x y) \u2192 P v x z := by finish,\n    refine lt_of_lt_of_le _ (cardinal.mk_subtype_mono imp1), \n    have imp2 : \u2200 v, P v z x \u2192 (\u2203 y \u2260 x, P v y x) := by finish,\n    apply lt_of_le_of_lt (cardinal.mk_subtype_mono imp2),\n    exact majority,\nend\n\n-- Definition 5: Let SCC be a function that assigns \n-- to each pair (V, X) the set of all (V, X)-SCCs.\ndef SCC := \u03bb (V X : Type), Prof V X \u2192 set X\n\ndef universal_domain_SCC {V X : Type} (F : SCC V X) : Prop := \n    \u2200 P : Prof V X, F P \u2260 \u2205\n\n-- Example 1: Given a (V, X)-profile P, if there is a Condorcet winner, \n-- then output the set of all Condorcet winners (which will be a singleton),\n-- and otherwise output all candidates in X.\ndef condorcet_SCC {V X : Type} : SCC V X := \u03bb P,\n    {x : X | condorcet_winner P x \u2228 (\u00ac\u2203 y, condorcet_winner P y)}\n\n-- Definition 6: A variable-election social choice correspondence (VSCC) \n-- is a function F that assigns to each pair (V, X) a (V,X)-SCC. \ndef VSCC : Type 1 := \u03a0 (V X : Type), SCC V X.\n\ndef finite_universal_domain_VSCC (F : VSCC) : Prop :=\n    \u2200 V X [inhabited V] [inhabited X] [fintype V] [fintype X], universal_domain_SCC (F V X)\n\n-- Example 2\ndef condorcet_VSCC : VSCC := \u03bb V X, condorcet_SCC\n\n-- A collective choice rule for (V, X), or (V, X)-CCR, is \n-- a function f : Prof(V, X) \u2192 B(X). Let CCR be a function \n-- that assigns to each pair (V, X) of the set of all (V,X)-CCRs.\ndef CCR := \u03bb (V X : Type), Prof V X \u2192 X \u2192 X \u2192 Prop\n\n-- cycle takes in a binary relation R and a list c of\n-- elements of X and  outputs the proposition stating that \n-- (i) there is a proof e that c is not the empty list, and \n-- (ii) c is a cycle in R.\ndef cycle {X: Type} := \u03bb (R : X \u2192 X \u2192 Prop) (c : list X),\n    \u2203 (e : c \u2260 list.nil), list.chain R (c.last e) c\n\n-- Example 3: A candidate x defeats a candidate y in P \n-- just in case the margin of x over y is (i) positive and \n-- (ii) greater than the weakest margin in each majority cycle containing x and y. \ndef split_cycle_CCR {V X : Type} : CCR V X :=\n    \u03bb (P : Prof V X) (x y : X), \u2200 [f: fintype V],\n    0 < @margin V X f P x y \u2227\n    \u00ac (\u2203 (c : list X), x \u2208 c \u2227 y \u2208 c \u2227\n    cycle (\u03bb a b, @margin V X f P x y \u2264 @margin V X f P a b) c)\n\n-- Definition 8: A variable-election collective choice rule (VCCR) \n-- is a function that assigns to each pair (V, X) a (V, X)-CCR.\ndef VCCR := \u03a0 (V X : Type), CCR V X\n\n-- Example 4\ndef split_cycle_VCCR : VCCR := \u03bb V X, split_cycle_CCR\n\n-- Definition 9: Given an asymmetric VCCR F, we define the induced VSCC F* \n-- such that for any V, X, and (V, X)-profile P, we have\n-- F*(V,X)(P) = {x \u2208 X(P) | \u2200y \u2208 X(P), (y, x) \u2209 F(V, X)(P)}.\ndef max_el_VSCC : VCCR \u2192 VSCC := \u03bb f V X P, {x | \u2200 y : X, \u00ac f V X P y x}\n\n-- Example 5: The Split Cycle voting method is \n-- the induced VSCC from the Split Cycle VCCR\ndef split_cycle : VSCC := max_el_VSCC split_cycle_VCCR\n\ndef acyclic {X : Type} : (X \u2192 X \u2192 Prop) \u2192 Prop := \n    \u03bb Q, \u2200 (c : list X), \u00ac cycle Q c\n\n-- Any acyclic VCCR induces a VSCC satisfying (finite) universal domain\n-- the proof for the following theorem can be found in src/main.lean\ntheorem max_el_VSCC_universal_domain (F : VCCR)\n(a : \u2200 V X [inhabited V] [inhabited X] [fintype V] [fintype X] (P : Prof V X), acyclic (F V X P)) :\nfinite_universal_domain_VSCC (max_el_VSCC F) := sorry\n\n-- Converts a walk to a path \nnoncomputable def to_path {X : Type} : list X \u2192 list X\n| [] := []\n| (u :: p) := let p' := to_path p in\n    if u \u2208 p' then (p'.drop (p'.index_of u)) else (u :: p')\n\n-- Given a particular candidate c, we say that a nonempty set D of candidates \n-- (not containing c) is a set of clones of c if D \u222a {c} is a set of clones. \ndef clones {V X : Type} (P : Prof V X) (c : X) (D : set {x : X // x \u2260 c}) : \n    Prop := D.nonempty \u2227 (\u2200 (c' \u2208 D) (x : {x : X // x \u2260 c}) (i : V), \n    x \u2208 D \u2192 ((P i c x \u2194 P i c' x) \u2227 (P i x c \u2194 P i x c')))\n\n-- minus_candidate takes in a Prof P for V and X, as well as \n-- a candidate b from X, and outputs the Prof for V and {x : X // x \u0338= b} \n-- that agrees with P on how every voter ranks the candidates other than b.\ndef minus_candidate {V X : Type} (P : Prof V X) (b : X) : \n    Prof V {x : X // x \u2260 b} := \u03bb v x y, P v x y\n\n--  removing a clone from a profile should not change which non-clones win\ndef non_clone_choice_ind_clones {V X : Type} (P : Prof V X) (c : X) (D : set {x : X // x \u2260 c}) \n    : VSCC \u2192 Prop :=  \u03bb F, clones P c D \u2192 (\u2200 a : {x : X // x \u2260 c}, \n    a \u2209 D \u2192 (a.val \u2208 (F V X P) \u2194 a \u2208 (F V {x : X // x \u2260 c} (minus_candidate P c))))\n\n-- we can state that Split Cycle satisfies part (i) of independence of clones as follows:\n-- the proof for the following theorem can be found in src/clones.lean\ntheorem non_clone_choice_ind_clones_split_cycle {V X : Type} [fintype V] \n    (P : Prof V X) (c : X) (D : set {x : X // x \u2260 c}) : non_clone_choice_ind_clones P c D split_cycle := sorry", "meta": {"author": "chasenorman", "repo": "Formalized-Voting", "sha": "de04e630b83525b042db166670ba97f9952b5691", "save_path": "github-repos/lean/chasenorman-Formalized-Voting", "path": "github-repos/lean/chasenorman-Formalized-Voting/Formalized-Voting-de04e630b83525b042db166670ba97f9952b5691/src/lori2021/lori.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7496759105289078}}
{"text": "import lecture1\n\nopen_locale filter topological_space big_operators\nopen filter\n\nopen_locale classical\nnoncomputable theory\n\nlemma tendsto_of_le_of_le {x y z : \u2115 \u2192 \u211d} {t : \u211d} (hx : tendsto x at_top (\ud835\udcdd t)) \n  (hz : tendsto z at_top (\ud835\udcdd t)) (hxy : \u2200 n, x n \u2264 y n) (hyz : \u2200 n, y n \u2264 z n) : \n  tendsto y at_top (\ud835\udcdd t) :=\nbegin\n  rw tendsto_seq_iff at *,\n  intros \u03b5 h\u03b5,\n  cases hx (\u03b5/2) (half_pos h\u03b5) with N\u2081 hN\u2081,\n  cases hz (\u03b5/2) (half_pos h\u03b5) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  specialize hxy n,\n  specialize hyz n,\n  specialize hN\u2081 n (le_of_max_le_left hn),\n  specialize hN\u2082 n (le_of_max_le_right hn),\n  rw abs_sub_lt_iff at *,\n  cases hN\u2081 with hN\u2081 hN\u2081',\n  cases hN\u2082 with hN\u2082 hN\u2082',\n  split;\n  linarith,\nend\n\n/-\nTheorem 1.3 (Bolzano-Weierstrass)\n\nTo prove this, we are going to use the proof given in lecture, that is, the one by halving the\ninterval every time, and showing that we have an infinite number of elements no matter how small\nthe interval becomes.\n-/\nnamespace bolzano_weierstrass\n\n/-\nFirst, we define the inductive step. That is, given an interval [a, b], this returns either \n  [a, (a+b)/2] or [(a+b)/2, b], depending on whether there is an infinite number of x\u2099 in the first\n  interval.\n-/\ndef step (x : \u2115 \u2192 \u211d) (a b : \u211d) : \u211d \u00d7 \u211d :=\nif set.infinite {n | x n \u2208 set.Icc a ((a+b)/2)} then\n  (a, (a + b)/2)\nelse\n  ((a + b)/2, b)\n\n/-\nFirst, we show that the result of `step` still forms a well defined interval.\n-/\nlemma step_valid (x : \u2115 \u2192 \u211d) {a b : \u211d} (h : a \u2264 b) :\n  let p := step x a b in\n  p.1 \u2264 p.2 :=\nbegin\n  dsimp [step],\n  split_ifs with hp hp; linarith\nend\n\n/-\nThen, we show that the resulting interval still contains an infinite number of x\u2099s. To show this,\nnote that it is not possible for both intervals to be finite, as their union is the original \ninterval, and if they are both finite then so is their union. Contradiction.\n-/\nlemma step_valid'_aux {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b) \n  (hx : set.infinite {n | x n \u2208 set.Icc a b}) :\n  set.infinite {n | x n \u2208 set.Icc a ((a+b)/2)} \u2228 set.infinite {n | x n \u2208 set.Icc ((a+b)/2) b} :=\nbegin\n  by_contra h,\n  push_neg at h,\n  rw [set.infinite, set.infinite, not_not, not_not] at h,\n  apply hx,\n  have : {n | x n \u2208 set.Icc a b} = {n | x n \u2208 set.Icc a ((a+b)/2)} \u222a {n | x n \u2208 set.Icc ((a+b)/2) b},\n  { ext k,\n    simp only [set.mem_union_eq, set.mem_set_of_eq, set.mem_Icc],\n    split,\n    { rintro \u27e8h1, h2\u27e9,\n      by_cases h' : x k \u2264 (a + b)/ 2,\n      { left, split; linarith },\n      { right, split; linarith } },\n    { rintro (\u27e8h1,h2\u27e9|\u27e8h1, h2\u27e9);\n      split;\n      linarith } },\n  rw this,\n  refine set.finite.union h.1 h.2,\nend\n\nlemma step_valid' {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b) \n  (hx : set.infinite {n | x n \u2208 set.Icc a b}) :\n  let p := step x a b in\n  set.infinite {n | x n \u2208 set.Icc p.1 p.2} :=\nbegin\n  dsimp [step],\n  split_ifs with hp hp,\n  { exact hp },\n  { exact or.resolve_left (step_valid'_aux h hx) hp }\nend\n\n/-\nNext, we show that the new interval is contained within the previous interval\n-/\nlemma step_valid'' (x : \u2115 \u2192 \u211d) {a b : \u211d} (h : a \u2264 b) :\n  let p := step x a b in\n  a \u2264 p.1 :=\nbegin\n  dsimp [step],\n  split_ifs with hp hp,\n  { refl },\n  { linarith }\nend\n\nlemma step_valid''' (x : \u2115 \u2192 \u211d) {a b : \u211d} (h : a \u2264 b) :\n  let p := step x a b in\n  p.2 \u2264 b :=\nbegin\n  dsimp [step],\n  split_ifs with hp hp,\n  { linarith },\n  { refl },\nend\n\n/-\nFinally, we show that the size of the new interval is half the size of the original interval.\n-/\nlemma step_valid'''' (x : \u2115 \u2192 \u211d) {a b : \u211d} :\n  let p := step x a b in\n  p.2 - p.1 = 1/2 * (b - a) :=\nbegin\n  dsimp [step],\n  split_ifs with hp hp;\n  { linarith },\nend\n\n/-\nThen, we define the sequence of intervals. [a, b], [a\u2081, b\u2081], ...\n-/\nnoncomputable def step_n (x : \u2115 \u2192 \u211d) (a b : \u211d) : \u2115 \u2192 \u211d \u00d7 \u211d\n| 0 := (a, b)\n| (n + 1) := let p := step_n n in step x p.1 p.2\n\n/-\nWe can show that the nth term of this is still a well defined sequence, by induction and the fact\nthat we have already proven this for `step`.\n-/\nlemma step_n_valid (x : \u2115 \u2192 \u211d) {a b : \u211d} (h : a \u2264 b) (n : \u2115) :\n  (step_n x a b n).1 \u2264 (step_n x a b n).2 :=\nbegin\n  induction n with k ih,\n  { exact h },\n  { dsimp [step_n],\n    apply step_valid,\n    exact ih }\nend\n\n/-\nWe then define two sequences a\u2099 and b\u2099, which are the lower and upper bounds of those intervals\nrespectively.\n-/\ndef seq_a (x : \u2115 \u2192 \u211d) (a b : \u211d) (n : \u2115) : \u211d := (step_n x a b n).1\ndef seq_b (x : \u2115 \u2192 \u211d) (a b : \u211d) (n : \u2115) : \u211d := (step_n x a b n).2\n\n/-\nWe note that a\u2099 is increasing, that is, a\u2080 \u2264 a\u2081 \u2264 a\u2082 \u2264 ...\n-/\nlemma seq_a_increasing (x : \u2115 \u2192 \u211d) (a b : \u211d) (ha : a \u2264 b) : monotone (seq_a x a b) :=\nbegin\n  apply monotone_of_monotone_nat,\n  intro n,\n  dsimp [seq_a, step_n],\n  apply step_valid'',\n  apply step_n_valid,\n  exact ha,\nend\n\n/-\nAs a corollary, this means that the a\u2099 are bounded below by a\u2080 = a\n-/\nlemma a_le_seq_a (x : \u2115 \u2192 \u211d) (a b : \u211d) (ha : a \u2264 b) (n : \u2115) : a \u2264 seq_a x a b n :=\nbegin\n  exact @seq_a_increasing x a b ha 0 n (nat.zero_le _),\nend\n\n/-\nWe also note that b\u2099 is decreasing, that is b\u2080 \u2265 b\u2081 \u2265 ...\n-/\nlemma seq_b_decreasing (x : \u2115 \u2192 \u211d) (a b : \u211d) (ha : a \u2264 b) : \n  \u2200 n m, n \u2264 m \u2192 seq_b x a b m \u2264 seq_b x a b n :=\nbegin\n  intros n m h,\n  induction h with k ih\u2081 ih\u2082,\n  { refl },\n  { dsimp [seq_b, step_n],\n    apply le_trans _ ih\u2082,\n    apply step_valid''',\n    apply step_n_valid,\n    exact ha }\nend\n\n/-\nAnd it follows that b\u2099 are bounded above by b\u2080 = b\n-/\nlemma seq_b_le_b (x : \u2115 \u2192 \u211d) (a b : \u211d) (ha : a \u2264 b) (n : \u2115) : seq_b x a b n \u2264 b :=\nbegin\n  exact seq_b_decreasing x a b ha 0 n (nat.zero_le _),\nend\n\n/-\nAn alternative statement for `step_n_valid` is that `a\u2099 \u2264 b\u2099` for all `n`.\n-/\nlemma seq_a_le_seq_b (x : \u2115 \u2192 \u211d) (a b : \u211d) (ha : a \u2264 b) (n : \u2115) : seq_a x a b n \u2264 seq_b x a b n :=\nstep_n_valid x ha n\n\n/-\nThen, a\u2099 is an increasing sequence, bounded above by `b`, so it must converge.\n-/\nlemma is_convergent_seq_a (x : \u2115 \u2192 \u211d) (a b : \u211d) (ha : a \u2264 b) : is_convergent (seq_a x a b) :=\nbegin\n  apply is_convergent_of_increasing_of_bdd_above b,\n  { intro n,\n    apply seq_a_increasing,\n    exact ha,\n    exact nat.le_succ _ },\n  { intro n,\n    apply le_trans (seq_a_le_seq_b x a b ha n),\n    apply seq_b_le_b,\n    exact ha }\nend\n\n/-\nSimilarly, b\u2099 is a decreasing sequence that is bounded below, and it must converge as well.\n-/\nlemma is_convergent_seq_b (x : \u2115 \u2192 \u211d) (a b : \u211d) (ha : a \u2264 b) : is_convergent (seq_b x a b) :=\nbegin\n  apply is_convergent_of_decreasing_of_bdd_below a,\n  { intro n,\n    apply seq_b_decreasing,\n    exact ha,\n    exact nat.le_succ _ },\n  { intro n,\n    apply le_trans _ (seq_a_le_seq_b _ _ _ _ _),\n    apply a_le_seq_a,\n    exact ha,\n    exact ha }\nend\n\n/-\nAn alternative statement of the halving of the sizes of the inverals is that \n  b\u2099\u208a\u2081 - a\u2099\u208a\u2081 = 1/2 (b\u2099 - a\u2099) \n-/\nlemma seq_b_succ_sub_seq_a_succ {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b) (n : \u2115) :\n  seq_b x a b n.succ - seq_a x a b n.succ = 1/2 * (seq_b x a b n - seq_a x a b n) :=\nbegin\n  dsimp [seq_a, seq_b, step_n],\n  apply step_valid'''',\nend\n\n/-\nThen we get that a\u2099 and b\u2099 must tend to the same limit. To see this, suppose if a\u2099 \u2192 s and b\u2099 \u2192 t,\nthen b\u2099 - a\u2099 \u2192 s - t. As a result, b\u2099\u208a\u2081 - a\u2099\u208a\u2081 \u2192 1/2 (s - t) from the above. However, b\u2099\u208a\u2081 - a\u2099\u208a\u2081\nis also a subsequence of b\u2099 - a\u2099, so it must tend to the same limit. Thus, 1/2 (s - t) = (s - t),\nand s = t.\n-/\nlemma seq_a_seq_b_limit_same {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b) (s t : \u211d)\n  (hs : tendsto (seq_a x a b) at_top (\ud835\udcdd s))\n  (ht : tendsto (seq_b x a b) at_top (\ud835\udcdd t)) : s = t :=\nbegin\n  have h1 := filter.tendsto.sub ht hs,\n  have h2 := @tendsto_subseq _ _ nat.succ (\u03bb n, nat.lt_succ_self _) h1,\n  have h3 : (\u03bb n, seq_b x a b n - seq_a x a b n) \u2218 nat.succ = (\u03bb n, 1/2 *(seq_b x a b n - seq_a x a b n)),\n  { ext n,\n    dsimp,\n    rwa seq_b_succ_sub_seq_a_succ },\n  rw h3 at h2,\n  have h4 := tendsto.const_mul (1/2 : \u211d) h1,\n  have h5 := tendsto_at_top_nhds_unique h2 h4,\n  linarith,\nend\n\n/-\nWe can then prove that there are infinitely many `n` such that x\u2099 \u2208 [a\u1d62, b\u1d62] for all i.\n-/\nlemma step_n_valid' {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b) (hx : set.infinite {i | x i \u2208 set.Icc a b}) \n  (n : \u2115) : set.infinite {i | x i \u2208 set.Icc (seq_a x a b n) (seq_b x a b n)} :=\nbegin\n  induction n with k ih,\n  { exact hx },\n  { dsimp [seq_a, seq_b, step_n] at *,\n    apply step_valid',\n    { apply step_n_valid,\n      apply h },\n    { exact ih } }\nend\n\n/-\nFrom this, the set of such `n` mustn't be bounded above. So no matter gow large `k` is, there is\nalways an `n > k` such that x\u2099 \u2208 [a\u1d62, b\u1d62]\n-/\nlemma exists_ge_mem_Icc {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b) \n  (hx : set.infinite {i | x i \u2208 set.Icc a b}) (k m : \u2115) : \n  \u2203 n > k, x n \u2208 set.Icc (seq_a x a b m) (seq_b x a b m) :=\nbegin\n  have h1 := step_n_valid' h hx m,\n  dsimp at h1,\n  by_contra h,\n  push_neg at h,\n  have h2 : {i | x i \u2208 set.Icc (seq_a x a b m) (seq_b x a b m)} \u2286 (finset.range (k+1) : set \u2115),\n  { intros n hn,\n    rw [finset.mem_coe, finset.mem_range],\n    by_contra h',\n    have h'' : k < n,\n    { linarith },\n    specialize h n h'',\n    apply h,\n    exact hn },\n  apply h1,\n  exact set.finite.subset (finset.finite_to_set _) h2,\nend\n\n/-\nWe define `n\u1d62` such that `n\u1d62\u208a\u2081 > n\u1d62` and that `x_n\u1d62 \u2208 [a\u1d62, b\u1d62]` for all `i`. We have shown that such\nn\u1d62 always exists so this is well defined.\n-/\nnoncomputable def n {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b) \n  (hx : set.infinite {i | x i \u2208 set.Icc a b}) : \u2115 \u2192 \u2115\n| 0 := nat.find $ exists_ge_mem_Icc h hx 0 0\n| (k + 1) := let p := n k in nat.find $ exists_ge_mem_Icc h hx p (k+1)\n\n/-\nFinally, we show that `n` satisfies the properties outlined above.\n-/\nlemma n_spec {x : \u2115 \u2192 \u211d} {a b : \u211d} (h : a \u2264 b)\n  (hx : set.infinite {i | x i \u2208 set.Icc a b}) (k : \u2115) :\n  x (n h hx k) \u2208 set.Icc (seq_a x a b k) (seq_b x a b k) :=\nbegin\n  cases k,\n  { cases nat.find_spec (exists_ge_mem_Icc h hx 0 0) with h1 h2,\n    exact h2 },\n  { let p := n h hx k,\n    cases nat.find_spec (exists_ge_mem_Icc h hx p (k+1)) with h1 h2,\n    dsimp [seq_a, seq_b, step_n, n] at *, -- ok, this `dsimp` is necessary?\n    exact h2 }\nend\n\nend bolzano_weierstrass\n\n/-\nNow that we have this, Bolzano-Weierstrass is fairly straightforward. As each of the \n`x_n\u1d62 \u2208 [a\u1d62, b\u1d62]`, a\u1d62 \u2264 x_n\u1d62 \u2264 b\u1d62, and that we've shown that a\u1d62 and b\u1d62 converge to the same limit,\nso x_n\u1d62 must converge to the same limit as well.\n-/\ntheorem bolzano_weierstrass {x : \u2115 \u2192 \u211d} (K : \u211d) (hx : \u2200 i, |x i| \u2264 K) :\n  \u2203 (n : \u2115 \u2192 \u2115), (\u2200 i, n i < n (i + 1)) \u2227 is_convergent (x \u2218 n) :=\nbegin\n  set a := -K with ha,\n  set b := K with ha,\n  have hKnonneg : 0 \u2264 K,\n  { linarith [abs_nonneg (x 0), hx 0] },\n  have hab : a \u2264 b := by linarith,\n  have hx' : set.infinite {i | x i \u2208 set.Icc a b},\n  { convert set.infinite_univ,\n    { ext n,\n      rw [iff_true, set.mem_Icc],\n      specialize hx n,\n      rw abs_le at hx,\n      split; linarith },\n    { exact nat.infinite } },\n  use bolzano_weierstrass.n hab hx',\n  split,\n  { intro i,\n    unfold bolzano_weierstrass.n,\n    let p := bolzano_weierstrass.n hab hx' i,\n    dsimp only,\n    cases nat.find_spec (bolzano_weierstrass.exists_ge_mem_Icc hab hx' p (i+1)) with h1 h2,\n    exact h1 },\n  { cases bolzano_weierstrass.is_convergent_seq_a x a b hab with t ht,\n    cases bolzano_weierstrass.is_convergent_seq_b x a b hab with r hr,\n    have := bolzano_weierstrass.seq_a_seq_b_limit_same hab t r ht hr,\n    rw this at *,\n    use r,\n    apply tendsto_of_le_of_le ht hr,\n    { intro n,\n      exact (bolzano_weierstrass.n_spec hab hx' n).1 },\n    { intro n,\n      exact (bolzano_weierstrass.n_spec hab hx' n).2 } }\nend .\n\n/-\nDefinition of a Cauchy Sequence\n-/\nlemma cauchy_seq_iff (x : \u2115 \u2192 \u211d) :\n  cauchy_seq x \u2194 \u2200 \u03b5 > 0, \u2203 N, \u2200 n m, N \u2264 n \u2192 N \u2264 m \u2192 |x n - x m| < \u03b5 :=\nmetric.cauchy_seq_iff\n\n/-\nLemma 1.4\n\nEvery convergent sequence is Cauchy\n-/\nlemma cauchy_seq_of_is_convergent {x : \u2115 \u2192 \u211d} (hx : is_convergent x) : cauchy_seq x :=\nbegin\n  rw cauchy_seq_iff,\n  intros \u03b5 h\u03b5,\n  cases hx with a ha,\n  rw tendsto_seq_iff at ha,\n  cases ha (\u03b5/2) (half_pos h\u03b5) with N hN,\n  use N,\n  intros n m hn hm,\n  have h1 := hN n hn,\n  have h2 := hN m hm,\n  calc |x n - x m| = |(x n - a) + (a - x m)| : by ring\n               ... \u2264 |x n - a| + |a - x m| : abs_add _ _\n               ... = |x n - a| + |x m - a| : by rw abs_sub a\n               ... < \u03b5 : by linarith\nend\n\n/-\nTheorem 1.5\n\nEvery Cauchy sequence is convergent\n-/\n\n/-\nFirst, we shall show that every Cauchy sequence is bounded.\n-/\nlemma bdd_of_is_cauchy {x : \u2115 \u2192 \u211d} (hx : cauchy_seq x) : \u2203 k, \u2200 n, |x n| \u2264 k :=\nbegin\n  rw cauchy_seq_iff at hx,\n  cases hx 1 zero_lt_one with N\u2081 hN\u2081,\n  have h\u2081 : \u2200 m \u2265 N\u2081, |x m| < |x N\u2081| + 1,\n  { intros m hm,\n    specialize hN\u2081 m N\u2081 hm (le_refl _),\n    calc |x m| \u2264 |x m - x N\u2081| + |x N\u2081| : _\n           ... < |x N\u2081| + 1 : _,\n    { convert abs_add _ _, ring },\n    { linarith } },\n  set S := (finset.range (N\u2081 + 1)).image (abs \u2218 x) with hSdef,\n  have hS : S.nonempty,\n  { refine finset.nonempty.image _ (abs \u2218 x),\n    use 0,\n    simp only [nat.succ_pos', finset.mem_range] },\n  set k := max (|x N\u2081| + 1) (S.max' hS) with hk,\n  use k,\n  intro n,\n    cases lt_or_le n N\u2081,\n    { have : |x n| \u2264 S.max' hS,\n      { apply finset.le_max',\n        rw [hSdef, finset.mem_image],\n        use n,\n        split,\n        { rw [finset.mem_range], linarith },\n        { refl } },\n      refine le_trans this (le_max_right (|x N\u2081| + 1) (finset.max' S hS)) },\n    { have : |x n| \u2264 |x N\u2081| + 1,\n      { apply le_of_lt,\n        apply h\u2081,\n        exact h },\n      refine le_trans this (le_max_left (|x N\u2081| + 1) (finset.max' S hS)) }\nend .\n\ntheorem is_convergent_of_is_cauchy {x : \u2115 \u2192 \u211d} (hx : cauchy_seq x) : is_convergent x :=\nbegin\n  cases bdd_of_is_cauchy hx with k hk,\n  rcases bolzano_weierstrass k hk with \u27e8n, h\u2081, \u27e8a, h\u2082\u27e9\u27e9,\n  use a,\n  rw tendsto_seq_iff at \u22a2 h\u2082,\n  intros \u03b5 h\u03b5,\n  rw cauchy_seq_iff at hx,\n  cases hx (\u03b5/2) (half_pos h\u03b5) with N\u2081 hN\u2081,\n  cases h\u2082 (\u03b5/2) (half_pos h\u03b5) with j\u2080 hj\u2080,\n  use max N\u2081 j\u2080,\n  intros j hj,\n  calc |x j - a| \u2264 |x j - x (n j)| + |x (n j) - a| : _\n             ... < \u03b5 : _,\n  { convert abs_add _ _,\n    ring },\n  { have hnj : j \u2264 n j,\n    { apply le_of_nat_strict_mono h\u2081 },\n    specialize hN\u2081 j (n j) (le_of_max_le_left hj) (le_trans (le_of_max_le_left hj) hnj),\n    specialize hj\u2080 j (le_of_max_le_right hj),\n    simp only [function.comp_app] at hj\u2080,\n    linarith }\nend .\n\n/-\nSeries\n\nWe say the sum is convergent if it the partial sums converge.\n-/\ndef sum_convergent (x : \u2115 \u2192 \u211d) := is_convergent (\u03bb N, \u2211 i in finset.range N, x i)\n\n/-\nLemma 1.6 (i)\n   \u221e        \u221e                                 \u221e\nIf \u2211 a\u2099 and \u2211 b\u2099 both converges, then so does \u2211 (\u03b1a\u2099 + \u03b2b\u2099).\n   n=1       n=1                                n=1\n-/\nlemma sum_convergent_add {a b : \u2115 \u2192 \u211d} (ha : sum_convergent a) (hb : sum_convergent b) (\u03b1 \u03b2 : \u211d):\n  sum_convergent (\u03bb n, \u03b1 * a n + \u03b2 * b n) :=\nbegin\n  cases ha with x hx,\n  cases hb with y hy,\n  use \u03b1 * x + \u03b2 * y,\n  simp_rw [finset.sum_add_distrib, \u2190finset.mul_sum],\n  apply tendsto.add,\n  { apply tendsto.const_mul,\n    exact hx },\n  { apply tendsto.const_mul,\n    exact hy },\nend\n\n/-\nLemma 1.6 (ii)\n                                                   \u221e                             \u221e\nIf there exists N such that \u2200 n \u2265 N, a\u2099 = b\u2099, then \u2211 a\u2099 converges if and only if \u2211 b\u2099 converges.\n                                                   n=1                            n=1\n\nThe argument here is clearly symmetric, so we shall prove the implication first, and the iff\nfollows.\n-/\nlemma foo {a b : \u2115 \u2192 \u211d} (h : \u2203 N, \u2200 n \u2265 N, a n = b n)  (ha : sum_convergent a) : sum_convergent b :=\nbegin\n  cases h with N hN,\n  cases ha with x hx,\n  use x - (\u2211 i in finset.range N, a i) + (\u2211 i in finset.range N, b i),\n  -- have : (\u03bb n, \u2211 i in finset.range n, b i) = \n  -- \u03bb n, (\u2211 i in finset.range n, a i) - (\u2211 i in finset.range N, a i) + (\u2211 i in finset.range N, b i),\n  -- { ext n,\n  --   simp only, },\n  -- rw this,\n  sorry,\nend\n", "meta": {"author": "shingtaklam1324", "repo": "analysis-i", "sha": "928dd413014ca6668560c504592e0a15a83ea63a", "save_path": "github-repos/lean/shingtaklam1324-analysis-i", "path": "github-repos/lean/shingtaklam1324-analysis-i/analysis-i-928dd413014ca6668560c504592e0a15a83ea63a/src/lecture2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7496368062753288}}
{"text": "-- 7. Inductive Types\n  /- Every inductive type comes with introduction rules, which show how to \n     construct an element of the type, and elimination rules, which show how \n     to \u201cuse\u201d an element of the type in another construction. We have already \n     seen the introduction rules for an inductive type: \n     they are just the constructors that are specified in the definition of the type. \n     The elimination rules provide for a principle of recursion on the type, which \n     includes, as a special case, a principle of induction as well. -/\n\n#print \"===========================================\"\n#print \"Section 7.1. Enumerated Types\"\n#print \" \"\n-- https://leanprover.github.io/theorem_proving_in_lean/inductive_types.html#enumerated-types\n\nnamespace Sec_7_1\n  -- The simplest kind of inductive type is a type with a finite, enumerated list of elements.\n  inductive weekday : Type\n  | Sunday : weekday\n  | Monday : weekday\n  | Tuesday : weekday\n  | Wednesday : weekday\n  | Thursday : weekday\n  | Friday : weekday\n  | Saturday : weekday\n\n  #check weekday.Monday\n  open weekday\n  #check Monday\n\n  -- Sunday, Monday, ..., Saturday are distinct elements of weekday, with no special properties.\n\n  /- The elimination principle `weekday.rec` is defined with `weekday` and its constructors. \n     `weekday.rec` is aka a recursor; it is what makes the type \"inductive\" and allows us \n     to define a function on weekday by assigning values corresponding to each constructor. \n     Intuition: an inductive type is exhaustively generated by its constructors, and has no \n     elements beyond those they construct. -/\n\n  /- We will use a slight variant of `weekday.rec`, called `weekday.rec_on`, also generated \n     automatically and taking its arguments in a more convenient order.  -/\n\n  -- Let's import `nat` and use `weekday.rec_on` to define a fn from weekday to natural numbers:\n\n  def number_of_day (d : weekday) : \u2115 := weekday.rec_on d 1 2 3 4 5 6 7\n\n  #reduce number_of_day weekday.Sunday  -- result: 1\n  #reduce number_of_day Sunday          -- (`weekday` is already opened, so this works too)\n  #reduce number_of_day Thursday        -- result: 5\n\n  /- The first (explicit) argument to `rec_on` is the element `d` being \"analyzed.\" \n     The next seven arguments are the values corresponding to the seven constructors. \n     Note that `number_of_day weekday.Sunday` evaluates to 1: the computation rule for\n     `rec_on` sees that `Sunday` is a constructor, and returns the appropriate argument. -/\n\n  /- A more restricted variant of `rec_on` is `cases_on`. For enumerated types, `rec_on` \n     and `cases_on` are the same, but `cases_on` emphasizes that the definition is by cases. -/\n\n  def number_of_day' (d : weekday) : \u2115 := weekday.cases_on d 1 2 3 4 5 6 7\n\n  /- It is useful to group related definitions and theorems in a single namespace. \n     We can put `number_of_day` in the `weekday` namespace and then use the shorter name \n     when we open the namespace. -/\n\n  /- The names rec_on and cases_on are generated automatically, but they are protected to \n     avoid name clashes, so they're not provided by default when the namespace is opened. \n     However, you can explicitly declare aliases for them using `renaming`. -/\n\n  namespace weekday\n    @[reducible]\n    private def cases_on := @weekday.cases_on\n\n    def number_of_day (d : weekday) : nat :=\n      cases_on d 1 2 3 4 5 6 7\n  end weekday\n\n  -- We can define functions from weekday to weekday:\n  namespace weekday\n    def next (d : weekday) : weekday :=\n      weekday.cases_on d Monday Tuesday Wednesday Thursday Friday Saturday Sunday\n\n    def previous (d : weekday) : weekday :=\n      weekday.cases_on d Saturday Sunday Monday Tuesday Wednesday Thursday Friday \n\n    #reduce next (next Tuesday)\n    #reduce next (previous Tuesday)\n\n    example (d : weekday) : next (previous d) = d := \n    weekday.cases_on d \n      (show next (previous Sunday) = Sunday, from rfl)\n      (show next (previous Monday) = Monday, from rfl) -- etc...\n      -- ...but the show is just for clarity; we can just use `rfl` by itself\n      -- as we do for the remaining cases\n      rfl rfl rfl rfl rfl\n\n    -- with tactics, we can be even more concise\n    example (d : weekday) : next (previous d) = d := \n      by apply weekday.cases_on d; refl\n  end weekday\n\n  -- Some fundamental data types in the Lean library are instances of enumerated types.\n  namespace hide\n\n    -- use `hide` so they don't conflict with the stdlib.\n\n    inductive empty : Type  -- an inductive data type with no constructors\n\n    inductive unit : Type | star : unit\n\n    inductive bool : Type\n    | ff : bool\n    | tt : bool\n\n    \n    /- As an exercise, think about the introduction and elimination rules for these types,\n       and define boolean operations `band`, `bor`, `bnot` on the boolean, and verifying \n       common identities; e.g., define `band` using a case split: -/\n\n    def band (b1 b2 : bool) : bool := bool.cases_on b1 bool.ff b2\n    def bor (b1 b2 : bool) : bool := bool.cases_on b1 b2 bool.tt \n    def bnot (b : bool) : bool := bool.cases_on b bool.tt bool.ff \n\n\n    #reduce band bool.tt bool.tt   -- returns bool.tt\n    #reduce band bool.ff bool.tt   -- returns bool.ff\n    #reduce bor bool.tt bool.ff    -- returns bool.tt\n    #reduce bor bool.ff bool.ff    -- returns bool.ff\n    #reduce bnot bool.ff           -- returns bool.tt\n    #reduce bnot bool.tt           -- returns bool.ff\n\n-- Similarly, most identities can be proved by introducing suitable case splits, and then using rfl.\n\n  end hide\n\nend Sec_7_1\n\n\n#print \"===========================================\"\n#print \"Section 7.2. Constructors with Arguments\"\n#print \" \"\n-- https://leanprover.github.io/theorem_proving_in_lean/inductive_types.html#constructors-with-arguments\n\nnamespace Sec_7_2\n  /- Enumerated types are a special case of inductive types, in which constructors take \n     no arguments. In general, a \"construction\" can depend on data, which is then represented \n     in the constructed argument. Consider the definitions of the product and sum types:-/\n\n  universes u v\n\n  namespace hide\n    inductive prod (\u03b1 : Type u) (\u03b2 : Type v) | mk : \u03b1 \u2192 \u03b2 \u2192 prod\n    inductive sum (\u03b1 : Type u) (\u03b2 : Type v) | inl {} : \u03b1 \u2192 sum | inr {} : \u03b2 \u2192 sum\n  end hide\n  \n  /- To define a function on prod \u03b1 \u03b2, we assume input of the form prod.mk a b, and specify\n     the output in terms of a and b. For example, here is the definition of the two projections \n     for prod.  -/\n\n  -- Remember the std lib uses \u03b1 \u00d7 \u03b2 to denote prod \u03b1 \u03b2 and uses (a, b) for prod.mk a b.\n  def fst {\u03b1 : Type u} {\u03b2 : Type v} (p : \u03b1 \u00d7 \u03b2) : \u03b1 := prod.rec_on p (\u03bb a b, a)\n  def snd {\u03b1 : Type u} {\u03b2 : Type v} (p : \u03b1 \u00d7 \u03b2) : \u03b2 := prod.rec_on p (\u03bb a b, b)\n\n  /- `fst` takes pair `p`, applies recursor `prod.rec_on p (\u03bb a b, a)`---which interprets \n     `p` as pair `prod.mk a b`---then uses the 2nd arg to determine what to do with a and b. -/\n\n  -- another example\n  def prod_example (p : bool \u00d7 \u2115) : \u2115 := prod.rec_on p (\u03bb b n, cond b (2 * n) (2 * n + 1))\n\n  #reduce prod_example (tt, 3)  -- returns 6\n  #reduce prod_example (ff, 3)  -- returns 7\n\n  -- `cond` is a boolean conditional: `cond b t1 t2` returns `t1` if `b` is true, and `t2` \n  -- otherwise. (It has the same effect as `bool.rec_on b t2 t1`.)\n\n  /- `sum` has two constructors, `inl` and `inr` and each takes one explicit argument. \n     To define a function on `sum \u03b1 \u03b2`, we must handle 2 cases: if the input is of the form\n     `inl a` (resp., `inr b`) then we must specify an output value in terms of a (resp `b`). -/\n\n  def sum_example (s : \u2115 \u2295 \u2115) : \u2115 := sum.cases_on s (\u03bb n, 2*n) (\u03bb n, 2*n + 1)\n\n  #reduce sum_example (sum.inl 3) -- returns 6\n  #reduce sum_example (sum.inr 3) -- returns 7\n\n  -- Lean's inductive def syntax allows named args for constructors before the colon:\n\n  namespace hide\u2082\n    inductive prod (\u03b1 : Type) (\u03b2 : Type) | mk (fst : \u03b1) (snd : \u03b2) : prod\n    inductive sum (\u03b1 : Type) (\u03b2 : Type) | inl {} (a : \u03b1) : sum | inr {} (b : \u03b2) : sum\n    /- These result in essentially the same types as the ones above. In `sum`, `{}` refers to \n       the parameters, `\u03b1` and `\u03b2`; braces specify which args are meant to be left implicit. -/\n  end hide\u2082\n\n  /- A type, like `prod`, that has only one constructor is purely conjunctive: \n     the constructor simply packs the list of arguments into a single piece of data, \n     essentially a tuple where the type of subsequent arguments can depend on the type \n     of the initial argument. We can think of such a type as a \"record\" or a \"structure.\"  -/\n\n  /- In Lean, the keyword `structure` can be used to define such an inductive type as well \n     as its projections, at the same time. -/\n\n  namespace hide\u2083\n    structure prod (\u03b1 \u03b2 : Type) := mk :: (fst : \u03b1) (snd : \u03b2)\n    /- This simultaneously introduces the inductive type, `prod`, its constructor, `mk`, the\n       usual eliminators (`rec` and `rec_on`), as well as the projections, `fst` and `snd`. -/\n  end hide\u2083\n\n    /- If you don't name the constructor, Lean uses `mk` as a default. For example, the \n       following defines a record to store a color as a triple of RGB values: -/\n\n  structure color := (red : \u2115) (green : \u2115) (blue : \u2115)\n  def yellow := color.mk 255 255 0\n  #reduce color.red yellow     -- result: 255  (`color.red` is projection onto first component)\n  #reduce color.green yellow   -- result: 255\n  #reduce color.blue yellow    -- result: 0\n\n  -- `structure` is especially useful for defining algebraic structures!!!!!!\n  -- Lean provides substantial infrastructure to support working with them. \n\n  -- Here's the definition of a semigroup:\n\n  structure Semigroup := (carrier : Type u) \n    (mul : carrier \u2192 carrier \u2192 carrier)\n    (mul_assoc : \u2200 a b c, mul (mul a b) c = mul a (mul b c))\n\n  -- ==> More examples in CHAPTER 9!!!!!!! <==\n\n  -- Recall, sigma types are also known as the \"dependent product\" type:\n\n  namespace hide\u2084\n    inductive sigma {\u03b1 : Type u} (\u03b2 : \u03b1 \u2192 Type v) | dpair : \u03a0 a : \u03b1, \u03b2 a \u2192 sigma\n\n    -- Two more inductive types in the library are `option` and `inhabited`.\n    inductive option (\u03b1 : Type u) \n    | none {} : option \n    | some    : \u03b1 \u2192 option\n\n    inductive inhabited (\u03b1 : Type u)\n    | mk : \u03b1 \u2192 inhabited\n  end hide\u2084\n\n  -- `option` type enables us to define partial functions\n\n  /- In the semantics of dependent type theory, there is no built-in notion of a partial \n     function. Every element of a function type `\u03b1 \u2192 \u03b2` or a Pi type `\u03a0 x : \u03b1, \u03b2` is assumed \n     total. The `option` type enables us to represent partial functions. An element of \n     `option \u03b2` is either `none` or of the form `some b`, for some value `b : \u03b2`. Thus,\n     `\u03b1 \u2192 option \u03b2` is the type of partial functions from `\u03b1` to `\u03b2`; if `a : \u03b1`, then \n     `f a` either returns `none`, indicating the `f` is \"undefined\" at `a`, or `some b`. -/\n\n  /- An element of `inhabited \u03b1` is simply a witness to existence of an element of `\u03b1`. \n     `inhabited` is actually an example of a **type class** in Lean: Lean can be told that\n     suitable base types are inhabited, and can automatically infer that other constructed \n     types are inhabited on that basis. -/\n\n  /- As exercises, develop a notion of composition for partial functions from `\u03b1` to `\u03b2` and \n     `\u03b2` to `\u03b3`, and show that it behaves as expected. -/\n\n  /- Also, show that `bool` and `nat` are inhabited, that the product of two inhabited types\n     is inhabited, and that the type of functions to an inhabited type is inhabited. -/\n  \nend Sec_7_2\n\n\n#print \"===========================================\"\n#print \"Section 7.3. Inductively Defined Propositions\"\n#print \" \"\n-- https://leanprover.github.io/theorem_proving_in_lean/inductive_types.html#inductively-defined-propositions\n\n/- Inductively defined types can live in any type universe, including the bottom-most one, \n   `Prop`. In fact, this is exactly how the logical connectives are defined. -/\n\nnamespace Sec_7_3\n  namespace hide\u2085\n    inductive false : Prop\n    inductive true : Prop | intro : true\n    inductive and (a b : Prop) : Prop | intro : a \u2192 b \u2192 and\n    inductive or (a b : Prop) : Prop \n    | intro_left : a \u2192 or \n    | intro_right : b \u2192 or\n\n    -- Alternatively, we could give names to the inhabitants:\n    inductive and_alt (P Q : Prop) : Prop | intro (a : P) (b : Q) : and_alt\n    inductive or_alt (P Q : Prop) : Prop\n    | intro_left (a : P) : or_alt\n    | intro_right (b : Q) : or_alt\n  end hide\u2085\n\n  -- Think about how these give rise to the intro and elim rules we've already seen.\n\n  -- There are rules that govern what the eliminator of an inductive type can eliminate to;\n  -- that is, what kinds of types can be the target of a recursor.\n\n  /- Roughly speaking, what characterizes inductive types in Prop is that one can only \n     eliminate to other types in Prop. This agrees with the fact that if `p : Prop`, then\n     an element `hp : p` carries no info. (There is one exception discussed below.) -/\n\n  -- Even the existential quantifier is inductively defined:\n\n  namespace hide\u2086\n    universe u\n\n    inductive Exists {\u03b1 : Type u} (p : \u03b1 \u2192 Prop) : Prop\n    | intro : \u2200(a : \u03b1), p a \u2192 Exists\n\n    inductive Exists_alt {\u03b1 : Type u} (p : \u03b1 \u2192 Prop) : Prop\n    | intro (w : \u2200(a : \u03b1), p a) : Exists_alt\n  \n    def exists.intro := @Exists.intro\n  end hide\u2086\n\n  -- The notation `\u2203 x : \u03b1, p` is syntactic sugar for `Exists (\u03bb x : \u03b1, p)`.\n\n  /- The defs of `false`, `true`, `and`, and `or` are analogous to the defs of \n     `empty`, `unit`, `prod`, and `sum`. The difference is the former yield\n     elements of `Prop`, and the latter yield elements of `Type u` for some `u`. -/\n\n  -- Similarly, `\u2203 x : \u03b1, p` is a `Prop`-valued variant of `\u03a3 x : \u03b1, p`.\n\n  /- Another inductive type, denoted `{x : \u03b1 | p}`, is sort of a hybrid between \n     `\u2203 x : \u03b1, P` and `\u03a3 x : \u03b1, P`. It is the `subtype` type. -/\n\n  namespace hide\u2087\n    universe u\n    inductive subtype {\u03b1 : Type u} (p : \u03b1 \u2192 Prop)\n    | mk : \u03a0(x : \u03b1), p x \u2192 subtype\n\n    inductive subtype_alt {\u03b1 : Type u} (p : \u03b1 \u2192 Prop)\n    | mk (w : \u03a0(x : \u03b1), p x) : subtype_alt\n  end hide\u2087\n\n -- This next example is unclear to me.\n namespace confusing_example\n   universe u\n   variables {\u03b1 : Type u} (p : \u03b1 \u2192 Prop)\n   --  ==========> UNRESOLVED QUESTIONS:     <==========\n   #check subtype p        -- why is the result `subtype p : Type u` ??\n   #check {x : \u03b1 // p x }  -- why is the result `{x // p x } : Type u` ??\n end confusing_example\n -- The notation `{x : \u03b1 // p x}` is syntactic sugar for subtype `(\u03bb x : \u03b1, p x)`. \n\n\nend Sec_7_3\n\n#print \"===========================================\"\n#print \"Section 7.4. Defining the Natural Numbers\"\n#print \" \"\n-- https://leanprover.github.io/theorem_proving_in_lean/inductive_types.html#defining-the-natural-numbers\n\nnamespace Sec_7_4\n  /- The inductively defined types we have seen so far are \"flat\": constructors wrap data and\n     insert it into a type, and the corresponding recursor unpacks the data and acts on it. \n     Things get more interesting when constructors act on elements of the type being defined. -/\n\n  -- A canonical example:\n  namespace hide_7_4_1\n    inductive nat : Type \n    | zero : nat \n    | succ : nat \u2192 nat\n\n  /- The recursor for `nat` defines a dependent function `f` from `nat` to any domain, \n     that is, `nat.rec` defines an element `f` of `\u03a0 n : nat, C n` for any `C : nat \u2192 Type`. \n     It has to handle two cases: the case where the input is zero, and the case where the \n     input is of the form succ n for some n : nat. \n     First case: we specify a target value of appropriate type. \n     Second case: the recursor assumes f(n) has been computed and the recursor uses the \n     next input arg to specify a value for f (succ n) in terms of n and f n. -/\n \n    #check @nat.rec_on  -- returns: \u03a0 {C : nat \u2192 Sort u_1} (n : nat), -- arg 1: major premise\n                      --           C nat.zero \u2192                     -- arg 2: minor premise 1\n                      -- (\u03a0 (a : nat), C a \u2192 C (nat.succ a))        -- arg 3: specifies how to \n                      --                                                       construct f(n+1) \n                      --                                                       given n and f(n)\n                      -- \u2192 C n                                      -- output type\n\n    namespace nat\n      def add (m n : nat) : nat := nat.rec_on n m (\u03bb n add_m_n, succ add_m_n)\n      #reduce add (succ zero) (succ (succ zero)) -- result: succ (succ (succ zero))\n\n      -- Can we recurse on m instead of n?  Yes, of course.\n      def add' (m n : nat) : nat := nat.rec_on m n (\u03bb m add_m_n, succ add_m_n)\n      #reduce add' (succ zero) (succ (succ zero)) -- same result as above\n\n      /- Let's go back to the first definition of `add` and dissect it. \n         + First, `nat.rec_on n` says \"recurse on n\".  \n         + The next symbol is `m` which indicates what to answer in the base case n=zero.  \n         + The next group of symbols is `(\u03bb n add_m_n, succ add_m_n)` which gives the answer\n           in the inductive case. The first argument to the \u03bb abstraction is `n`, which means \n           assume we know the value, `add_m_n`, that should be returned on input `m n`.\n           Finally, use this to say what to do when the input is `m (succ n)`; namely,  \n           return `succ add_m_n`. That's all there is to it! -/\n\n      instance : has_zero nat := has_zero.mk zero\n      instance : has_add nat := has_add.mk add\n\n      theorem add_zero (m : nat) : m + 0 = m := rfl\n      theorem add_succ (m n : nat) : m + succ n = succ (m + n) := rfl\n    end nat\n\n  end   hide_7_4_1\n\n    /- Proving `0 + m = m`, however, requires induction. The induction principle is just a \n       special case of the recursion principle when the codomain `C n` is an element of `Prop`. \n       It represents the familiar pattern of proof by induction: to prove `\u2200 n, C n`, first\n       prove `C 0`, and then, for arbitrary `n`, assume `ih : C n` and prove `C (succ n)`. -/\n  namespace hide_7_4_2\n  open nat\n\n  theorem zero_add (n : \u2115) : 0 + n = n := nat.rec_on n\n    (show 0 + 0 = 0, from rfl)\n    (assume n, \n      assume ih : 0 + n = n,\n      show 0 + succ n = succ n, from \n        calc\n          0 + succ n = succ (0 + n) : rfl\n            ... = succ n : by rw ih)\n\n\n  /- N.B. when `nat.rec_on` is used in a proof, it's the induction principle in disguise. \n     The `rewrite` and `simp` tactics tend to be effective in proofs like these. -/\n  theorem zero_add' (n : \u2115) : 0 + n = n := nat.rec_on n \n  rfl (\u03bb n ih, by simp only [add_succ, ih])\n\n  theorem zero_add'' (n : \u2115) : 0 + n = n := nat.rec_on n \n  rfl (\u03bb n ih, by simp only [add_succ, ih])\n  /- N.B. leaving off the `only` modifier would be misleading because `zero_add` is declared \n     in the standard library. Using `only` guarantees `simp` uses only the identities listed.-/\n\n  /- Associativity of addition: \u2200 m n k, m + n + k = m + (n + k). \n     The hardest part is figuring out which variable to do the induction on. \n     Since addition is defined by recursion on the second argument, k is a good guess. -/\n  theorem add_assoc (m n k : \u2115) : m + n + k = m + (n + k) := nat.rec_on k\n  (show m + n + 0 = m + (n + 0), from rfl)\n  (assume k,\n    assume ih : m + n + k = m + (n + k), \n    show (m + n) + succ k = m + (n + succ k), from\n      calc\n        (m + n) + succ k = succ ((m + n) + k) : rfl\n                     ... = succ (m + (n + k)) : by rw ih\n                     ... = m + succ (n + k) : rfl\n                     ... = m + (n + succ k) : rfl)\n\n  -- once again, there is a one-line proof\n  theorem add_assoc' (m n k : \u2115) : m + n + k = m + (n + k) := nat.rec_on k\n  rfl (\u03bb k ih, by simp only [add_succ, ih])\n\n\n  theorem succ_add (m n : \u2115) : succ m + n = succ (m + n) := \n    nat.rec_on n\n    (show succ m + 0 = succ (m + 0), from rfl)\n     (assume n,\n       assume ih : succ m + n = succ (m + n),\n       show succ m + succ n = succ (m + succ n), from\n         calc \n           succ m + succ n = succ (succ m + n) : rfl\n                       ... = succ (succ (m + n)) : by rw ih\n                       ... = succ (m + succ n) : rfl)\n\n  -- Commutativity of addition:\n  theorem add_comm (m n : \u2115) : m + n = n + m := nat.rec_on n\n   (show m + 0 = 0 + m, by rw [nat.zero_add, nat.add_zero])\n   (assume n,\n     assume ih : m + n = n + m,\n     show m + succ n = succ n + m, from\n       calc \n         m + succ n = succ (m + n) : rfl\n                ... = succ (n + m) : by rw ih\n                ... = succ n + m : by simp only [succ_add])\n\n  -- Here are the shorter versions of the last two theorems:\n  theorem succ_add' (m n : \u2115) : succ m + n = succ (m + n) := \n  nat.rec_on n rfl (\u03bb n ih, by simp only [succ_add, ih])\n\n  theorem add_comm' (m n : \u2115) : m + n = n + m := nat.rec_on n \n    (by simp only [zero_add, add_zero])\n    (\u03bb n ih, by simp only [add_succ, ih, succ_add])\n\n  end hide_7_4_2\n\nend Sec_7_4\n\n\n#print \"===========================================\"\n#print \"Section 7.5. Other Recursive Data Types\"\n#print \" \"\n-- https://leanprover.github.io/theorem_proving_in_lean/inductive_types.html#other-recursive-data-types\n\n-- Here are some more examples of inductively defined types.\nnamespace Sec_7_5\n  -- For any type, \u03b1, the type list \u03b1 of lists of elements of \u03b1 is defined in the library.\n  universe u\n  inductive my_list (\u03b1 : Type u)\n  | nil {} : my_list\n  | cons : \u03b1 \u2192 my_list \u2192 my_list\n\n  namespace my_list\n  \n  variable {\u03b1 : Type}\n  \n  notation h :: t := cons h t\n\n  def append (s t : my_list \u03b1) : my_list \u03b1 := \n  my_list.rec t (\u03bb (x: \u03b1) (l: my_list \u03b1) (u: my_list \u03b1), x :: u) s\n  /- Dissection of append: \n     The first arg to `list.rec` is `t`, meaning return `t` when `s` is `null`.\n     The second arg is `(\u03bb x l u, x :: u) s`.  I *think* this means the following:\n     assuming `u` is the result of `append l t`, then `append (x :: l) t` results\n     in `x :: u`.  \n\n     ==========> UNRESOLVED QUESTION:  What about `s` ....?   <==========\n  -/\n\n  /- To give some support for the claim that the foregoing interpretation is (roughtly) \n     correct, let's make the types explicit and verify that the definition still type-checks: -/\n  def append' (s t : my_list \u03b1) : my_list \u03b1 := \n  my_list.rec (t: my_list \u03b1) (\u03bb (x : \u03b1) (l : my_list \u03b1) (u: my_list \u03b1), x :: u) (s : my_list \u03b1)\n\n  #check nil                       -- nil : list ?M_1\n  #check (nil : my_list \u2115)           -- nil : list \u2115\n  #check cons 0 nil                -- 0 :: nil : list \u2115\n  #check cons \"a\" nil              -- 0 :: nil : list string\n  #check cons \"a\" (cons \"b\" nil)   -- a :: b :: nil : list string\n\n  notation s ++ t := append s t\n\n  theorem nil_append (t : my_list \u03b1) : nil ++ t = t := rfl\n\n  theorem cons_append (x : \u03b1) (s t : my_list \u03b1) : (x :: s) ++ t = x :: (s ++ t) := rfl\n\n  \n  -- Lean allows us to define iterative notation for lists:\n\n  notation `{` l:(foldr `,` (h t, cons h t) nil) `}` := l\n\n  section\n    open nat\n    #check {1,2,3,4,5}               -- Lean assumes this is a list of nats\n    #check ({1,2,3,4,5} : my_list int)  -- Forces Lean to take this as a list of ints.\n  end \n\n  -- As an exercise, prove the following:\n  theorem append_nil (t : my_list \u03b1) : t ++ nil = t := my_list.rec_on t \n    (show (append nil nil) = nil, from rfl)\n    (assume (x : \u03b1), assume (t : my_list \u03b1),\n     assume ih : (append t nil) = t,\n     show append (x :: t) nil = (x :: t), from\n       calc\n         append (x :: t) nil = x :: append t nil  : cons_append x t nil\n                         ... = x :: t             : by rw ih)\n\n  -- As an exercise, prove the following:\n  theorem append_nil' (t : my_list \u03b1) : t ++ nil = t := my_list.rec_on t \n    rfl  -- (base)\n    (\u03bb (x : \u03b1) (t : my_list \u03b1) (ih : (append t nil) = t), by simp [cons_append, ih]) -- (induct)\n\n  --theorem append_assoc (r s t : my_list \u03b1) : r ++ s ++ t = r ++ (s ++ t) := sorry\n\n  -- binary trees\n  inductive binary_tree\n  | leaf : binary_tree\n  | node : binary_tree \u2192 binary_tree \u2192 binary_tree\n\n  -- countably branching trees\n  inductive cbtree\n  | leaf : cbtree\n  | sup : (\u2115 \u2192 cbtree) \u2192 cbtree\n\n  namespace cbtree\n  \n  def succ (t : cbtree) : cbtree := sup (\u03bb n, t)  -- Note: (\u03bb n, t) is a thunk; i.e., a way to\n                                                  -- view t as a function of type \u2115 \u2192 cbtree.\n\n  /- Note the similarity to nat's successor.  The third cbtree after t would be \n     `sup (\u03bb n, sup (\u03bb n, sup (\u03bb n, t))` -/\n\n  def omega : cbtree := sup (\u03bb n, nat.rec_on n leaf (\u03bb n t, succ t))\n  end cbtree\n  end my_list\n           \nend Sec_7_5\n\n\n#print \"===========================================\"\n#print \"Section 7.6. Tactics for Inductive Types\"\n#print \" \" \n-- https://leanprover.github.io/theorem_proving_in_lean/inductive_types.html#tactics-for-inductive-types\n\nnamespace Sec_7_6\n  /- There are a number of tactics designed to work with inductive types effectively. \n     The `cases` tactic works on elements of an inductively defined type by decomposing \n     the element into the ways it could be constructed. -/\n\n  namespace example\u2081\n  variable p : \u2115 \u2192 Prop\n  open nat\n  example (hz : p 0) (hs : \u2200 n, p (succ n)) : \u2200 n, p n :=\n  begin\n    intro n,\n    cases n,\n      exact hz,\n      apply hs\n  end\n  \n  /- `cases` lets you choose names for arguments to the constructors using `with`. \n     For example, we can choose the name `m` for the argument to `succ`, so the second \n     case refers to `succ m`. More importantly, `cases` detects items in the local context \n     that depend on the target variable. It reverts these elements, does the split, and \n     reintroduces them. In the example below, notice that `h : n \u2260 0` becomes `h : 0 \u2260 0` \n     in the first branch, and `h : succ m \u2260 0` in the second.-/\n\n  example (n : \u2115) (h : n \u2260 0) : succ (pred n) = n :=\n  begin\n    cases n with m,  -- name cases using variable m\n      -- goal: h : 0 \u2260 0 \u22a2 succ (pred 0) = 0\n      { apply (absurd rfl h) },\n      -- goal: h : succ m \u2260 0 \u22a2 succ (pred (succ m)) = succ m\n      reflexivity\n  end\n\n  -- `cases` can be also be used to produce data and define functions.\n  def f (n : \u2115) : \u2115 := \n  begin cases n, exact 3, exact 7 end\n\n  example : f 0 = 3 := rfl\n  example : f 5 = 7 := rfl\n  example : f 1000 = 7 := rfl\n  -- in fact, we can prove that f n is constantly 7, except when n = 0.\n  example  (n : \u2115) (h : n \u2260 0) : (f n) = 7 := begin\n    cases n,\n    { apply (absurd rfl h) },  -- goal: 0 \u2260 0 \u22a2 f 0 = 7\n    reflexivity                -- goal: (succ a \u2260 0) \u22a2 f (succ a) = 7\n  end\n  end example\u2081\n  -- Let's define a function that takes an single argument of type `tuple`.\n\n  -- First define the type `tuple`.\n\n\n  namespace functionals\n  universe u\n  open list\n\n  -- Recall, we define a type that satisfies a predicate like this:\n\n  def tuple (\u03b1 : Type u) (n : \u2115) := subtype (\u03bb (l : list \u03b1), (list.length l = n)) \n    -- { l : list \u03b1 // list.length l = n }  -- (this didn't work for me) \n\n  variables {\u03b1 : Type u} {n : \u2115}\n\n  def f {n : \u2115} (t : tuple \u03b1 n) : \u2115 := begin cases n, exact 3, exact 7 end\n\n  def my_tuple : tuple \u2115 3 := \u27e8[0, 1, 2], rfl\u27e9\n\n  example : f my_tuple = 7 := rfl\n\n  -- As above, we prove that f t is constantly 7, except when t.length=0.\n  example  (n : \u2115) (t : tuple \u03b1 n) (h : n \u2260 0) : f t = 7 := \n  begin\n    cases n,\n    apply (absurd rfl h),  -- goal: 0 \u2260 0 \u22a2 f 0 = 7\n    reflexivity            -- goal: (a : \u2115) (succ a \u2260 0) (t : tuple \u03b1 (succ a)) \u22a2 f t = 7\n  end\n\n  end functionals\n\n  namespace induction_tactic\n\n  /- Just as `cases` is used to carry out proof by cases, the `induction` tactic is used \n     for proofs by induction. In contrast to `cases`, the argument to `induction` can only \n     come from the local context. -/\n\n  open nat\n  theorem zero_add (n : \u2115) : 0 + n = n :=\n  begin\n    induction n with n ih,\n      refl,\n      rw [add_succ, ih]\n  end\n\n  \n  -- The `case` tactic identifies each case with named arguments, making the proof clearer:\n  theorem zero_add' (n : \u2115) : 0 + n = n :=\n  begin\n    induction n,\n    case zero { refl },\n    case succ n ih { rw [add_succ, ih] }\n  end\n\n  theorem succ_add' (m n : \u2115) : (succ m) + n = succ (m + n) :=\n  begin\n    induction n,\n    case zero { refl },\n    case succ n ih { rw [add_succ, ih] }\n  end\n\n  theorem add_comm' (m n : \u2115) : m + n = n + m :=\n  begin\n    induction n,\n    case zero { rw zero_add, refl },\n    case succ n ih { rw [add_succ, ih, succ_add] }\n  end\n\n  -- Here are terse versions of the last three proofs.\n  theorem zero_add'' (n : \u2115) : 0 + n = n := by induction n; simp only [*, add_zero, add_succ]\n\n  theorem succ_add'' (m n : \u2115) : (succ m) + n = succ (m+n) := \n  by induction n; simp only [*, add_zero, add_succ]\n\n  theorem add_comm'' (m n : \u2115) : m + n = n + m :=\n  by induction n; simp only [*, zero_add, add_zero, add_succ, succ_add]\n\n  theorem add_assoc'' (m n k : \u2115) : m + n + k = m + (n + k) :=\n  by induction k; simp only [*, add_zero, add_succ]\n\n  end induction_tactic\n\n  namespace injection_tactic\n  /-We close this section with one last tactic that is designed to facilitate working with \n    inductive types, namely, the injection tactic. By design, the elements of an inductive \n    type are freely generated, which is to say, the constructors are injective and have \n    disjoint ranges. The injection tactic is designed to make use of this fact:  -/\n  end injection_tactic\n\nend Sec_7_6\n\n\n#print \"===========================================\"\n#print \"Section 7.7. Inductive Families\"\n#print \" \"\n\nnamespace Sec_7_7\n\nend Sec_7_7\n\n\n#print \"===========================================\"\n#print \"Section 7.8. Axiomatic Details\"\n#print \" \"\n\nnamespace Sec_7_8\n\nend Sec_7_8\n\n\n#print \"===========================================\"\n#print \"Section 7.9. Mutual and Nested Inductive Types\"\n#print \" \"\n\nnamespace Sec_7_9\n\nend Sec_7_9\n\n\n#print \"===========================================\"\n#print \"Section 7.10. Exercises\"\n#print \" \"\n\nnamespace Sec_7_10\n\nend Sec_7_10\n\n\n", "meta": {"author": "williamdemeo", "repo": "LEAN_wjd", "sha": "13826c75c06ef435166a26a72e76fe984c15bad7", "save_path": "github-repos/lean/williamdemeo-LEAN_wjd", "path": "github-repos/lean/williamdemeo-LEAN_wjd/LEAN_wjd-13826c75c06ef435166a26a72e76fe984c15bad7/theorem_proving/07-inductive_types.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.749543308631591}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Julian Kuelshammer\n-/\nimport algebra.hom.iterate\nimport data.nat.modeq\nimport data.set.pointwise\nimport dynamics.periodic_pts\nimport group_theory.quotient_group\n\n/-!\n# Order of an element\n\nThis file defines the order of an element of a finite group. For a finite group `G` the order of\n`x \u2208 G` is the minimal `n \u2265 1` such that `x ^ n = 1`.\n\n## Main definitions\n\n* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite\n  order.\n* `is_of_fin_add_order` is the additive analogue of `is_of_fin_order`.\n* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`\n  if `x` has infinite order.\n* `add_order_of` is the additive analogue of `order_of`.\n\n## Tags\norder of an element\n-/\n\nopen function nat\nopen_locale pointwise\n\nuniverses u v\n\nvariables {G : Type u} {A : Type v}\nvariables {x y : G} {a b : A} {n m : \u2115}\n\nsection monoid_add_monoid\n\nvariables [monoid G] [add_monoid A]\n\nsection is_of_fin_order\n\n@[to_additive]\nlemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 \u2194 x ^ n = 1 :=\nby rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]\n\n/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite\norder, i.e. there exists `n \u2265 1` such that `n \u2022 a = 0`.-/\ndef is_of_fin_add_order (a : A) : Prop :=\n(0 : A) \u2208 periodic_pts ((+) a)\n\n/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there\nexists `n \u2265 1` such that `x ^ n = 1`.-/\n@[to_additive is_of_fin_add_order]\ndef is_of_fin_order (x : G) : Prop :=\n(1 : G) \u2208 periodic_pts ((*) x)\n\nlemma is_of_fin_add_order_of_mul_iff :\n  is_of_fin_add_order (additive.of_mul x) \u2194 is_of_fin_order x := iff.rfl\n\nlemma is_of_fin_order_of_add_iff :\n  is_of_fin_order (multiplicative.of_add a) \u2194 is_of_fin_add_order a := iff.rfl\n\n@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]\nlemma is_of_fin_order_iff_pow_eq_one (x : G) :\n  is_of_fin_order x \u2194 \u2203 n, 0 < n \u2227 x ^ n = 1 :=\nby { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }\n\n/-- Elements of finite order are of finite order in subgroups.-/\n@[to_additive is_of_fin_add_order_iff_coe]\nlemma is_of_fin_order_iff_coe {G : Type u} [group G] (H : subgroup G) (x : H) :\n  is_of_fin_order x \u2194 is_of_fin_order (x : G) :=\nby { rw [is_of_fin_order_iff_pow_eq_one, is_of_fin_order_iff_pow_eq_one], norm_cast }\n\n/-- Elements of finite order are of finite order in quotient groups.-/\n@[to_additive is_of_fin_add_order_iff_quotient]\nlemma is_of_fin_order.quotient {G : Type u} [group G] (N : subgroup G) [N.normal] (x : G) :\n  is_of_fin_order x \u2192 is_of_fin_order (x : G \u29f8 N) := begin\n  rw [is_of_fin_order_iff_pow_eq_one, is_of_fin_order_iff_pow_eq_one],\n  rintros \u27e8n, \u27e8npos, hn\u27e9\u27e9,\n  exact \u27e8n, \u27e8npos, (quotient_group.con N).eq.mpr $ hn \u25b8 (quotient_group.con N).eq.mp rfl\u27e9\u27e9,\nend\n\n/-- 1 is of finite order in any group. -/\n@[to_additive \"0 is of finite order in any additive group.\"]\nlemma is_of_fin_order_one : is_of_fin_order (1 : G) :=\n(is_of_fin_order_iff_pow_eq_one 1).mpr \u27e81, _root_.one_pos, one_pow 1\u27e9\n\nend is_of_fin_order\n\n/-- `order_of x` is the order of the element `x`, i.e. the `n \u2265 1`, s.t. `x ^ n = 1` if it exists.\nOtherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/\n@[to_additive add_order_of\n\"`add_order_of a` is the order of the element `a`, i.e. the `n \u2265 1`, s.t. `n \u2022 a = 0` if it\nexists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention.\"]\nnoncomputable def order_of (x : G) : \u2115 :=\nminimal_period ((*) x) 1\n\n@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :\n  add_order_of (additive.of_mul x) = order_of x := rfl\n\n@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :\n  order_of (multiplicative.of_add a) = add_order_of a := rfl\n\n@[to_additive add_order_of_pos']\nlemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=\nminimal_period_pos_of_mem_periodic_pts h\n\n@[to_additive add_order_of_nsmul_eq_zero]\nlemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=\nbegin\n  convert is_periodic_pt_minimal_period ((*) x) _,\n  rw [order_of, mul_left_iterate, mul_one],\nend\n\n@[to_additive add_order_of_eq_zero]\nlemma order_of_eq_zero (h : \u00ac is_of_fin_order x) : order_of x = 0 :=\nby rwa [order_of, minimal_period, dif_neg]\n\n@[to_additive add_order_of_eq_zero_iff] lemma order_of_eq_zero_iff :\n  order_of x = 0 \u2194 \u00ac is_of_fin_order x :=\n\u27e8\u03bb h H, (order_of_pos' H).ne' h, order_of_eq_zero\u27e9\n\n@[to_additive add_order_of_eq_zero_iff'] lemma order_of_eq_zero_iff' :\n  order_of x = 0 \u2194 \u2200 n : \u2115, 0 < n \u2192 x ^ n \u2260 1 :=\nby simp_rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one, not_exists, not_and]\n\n/-- A group element has finite order iff its order is positive. -/\n@[to_additive add_order_of_pos_iff\n  \"A group element has finite additive order iff its order is positive.\"]\nlemma order_of_pos_iff : 0 < order_of x \u2194 is_of_fin_order x :=\nby rwa [iff_not_comm.mp order_of_eq_zero_iff, pos_iff_ne_zero]\n\n@[to_additive nsmul_ne_zero_of_lt_add_order_of']\nlemma pow_ne_one_of_lt_order_of' (n0 : n \u2260 0) (h : n < order_of x) : x ^ n \u2260 1 :=\n\u03bb j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h\n  ((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)\n\n@[to_additive add_order_of_le_of_nsmul_eq_zero]\nlemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x \u2264 n :=\nis_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)\n\n@[simp, to_additive] lemma order_of_one : order_of (1 : G) = 1 :=\nby rw [order_of, one_mul_eq_id, minimal_period_id]\n\n@[simp, to_additive add_monoid.order_of_eq_one_iff] lemma order_of_eq_one_iff :\n  order_of x = 1 \u2194 x = 1 :=\nby rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]\n\n@[to_additive nsmul_eq_mod_add_order_of]\nlemma pow_eq_mod_order_of {n : \u2115} : x ^ n = x ^ (n % order_of x) :=\ncalc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]\n       ... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]\n\n@[to_additive add_order_of_dvd_of_nsmul_eq_zero]\nlemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x \u2223 n :=\nis_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)\n\n@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]\nlemma order_of_dvd_iff_pow_eq_one {n : \u2115} : order_of x \u2223 n \u2194 x ^ n = 1 :=\n\u27e8\u03bb h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one\u27e9\n\n@[to_additive add_order_of_map_dvd]\nlemma order_of_map_dvd {H : Type*} [monoid H] (\u03c8 : G \u2192* H) (x : G) :\n  order_of (\u03c8 x) \u2223 order_of x :=\nby { apply order_of_dvd_of_pow_eq_one, rw [\u2190map_pow, pow_order_of_eq_one], apply map_one }\n\n@[to_additive]\nlemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :\n  \u2203 m : \u2115, (x ^ n) ^ m = x :=\nbegin\n  by_cases h0 : order_of x = 0,\n  { rw [h0, coprime_zero_right] at h,\n    exact \u27e81, by rw [h, pow_one, pow_one]\u27e9 },\n  by_cases h1 : order_of x = 1,\n  { exact \u27e80, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]\u27e9 },\n  obtain \u27e8m, hm\u27e9 :=\n    exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr \u27e8h0, h1\u27e9),\n  exact \u27e8m, by rw [\u2190pow_mul, pow_eq_mod_order_of, hm, pow_one]\u27e9,\nend\n\n/--\nIf `x^n = 1`, but `x^(n/p) \u2260 1` for all prime factors `p` of `r`,\nthen `x` has order `n` in `G`.\n-/\n@[to_additive add_order_of_eq_of_nsmul_and_div_prime_nsmul]\ntheorem order_of_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x^n = 1)\n  (hd : \u2200 p : \u2115, p.prime \u2192 p \u2223 n \u2192 x^(n/p) \u2260 1) :\n  order_of x = n :=\nbegin\n  -- Let `a` be `n/(order_of x)`, and show `a = 1`\n  cases exists_eq_mul_right_of_dvd (order_of_dvd_of_pow_eq_one hx) with a ha,\n  suffices : a = 1, by simp [this, ha],\n  -- Assume `a` is not one...\n  by_contra,\n  have a_min_fac_dvd_p_sub_one : a.min_fac \u2223 n,\n  { obtain \u27e8b, hb\u27e9 : \u2203 (b : \u2115), a = b * a.min_fac := exists_eq_mul_left_of_dvd a.min_fac_dvd,\n    rw [hb, \u2190mul_assoc] at ha,\n    exact dvd.intro_left (order_of x * b) ha.symm, },\n  -- Use the minimum prime factor of `a` as `p`.\n  refine hd a.min_fac (nat.min_fac_prime h) a_min_fac_dvd_p_sub_one _,\n  rw [\u2190order_of_dvd_iff_pow_eq_one, nat.dvd_div_iff (a_min_fac_dvd_p_sub_one),\n      ha, mul_comm, nat.mul_dvd_mul_iff_left (order_of_pos' _)],\n  { exact nat.min_fac_dvd a, },\n  { rw is_of_fin_order_iff_pow_eq_one,\n    exact Exists.intro n (id \u27e8hn, hx\u27e9) },\nend\n\n@[to_additive add_order_of_eq_add_order_of_iff]\nlemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :\n  order_of x = order_of y \u2194 \u2200 n : \u2115, x ^ n = 1 \u2194 y ^ n = 1 :=\nby simp_rw [\u2190 is_periodic_pt_mul_iff_pow_eq_one, \u2190 minimal_period_eq_minimal_period_iff, order_of]\n\n@[to_additive add_order_of_injective]\nlemma order_of_injective {H : Type*} [monoid H] (f : G \u2192* H)\n  (hf : function.injective f) (x : G) : order_of (f x) = order_of x :=\nby simp_rw [order_of_eq_order_of_iff, \u2190f.map_pow, \u2190f.map_one, hf.eq_iff, iff_self, forall_const]\n\n@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}\n  (y : H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive]\nlemma order_of_units {y : G\u02e3} : order_of (y : G) = order_of y :=\norder_of_injective (units.coe_hom G) units.ext y\n\nvariables (x)\n\n@[to_additive add_order_of_nsmul']\nlemma order_of_pow' (h : n \u2260 0) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd h,\n  simp only [order_of, mul_left_iterate],\nend\n\nvariables (a) (n)\n\n@[to_additive add_order_of_nsmul'']\nlemma order_of_pow'' (h : is_of_fin_order x) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd' h,\n  simp only [order_of, mul_left_iterate],\nend\n\n@[to_additive]\nlemma commute.order_of_mul_dvd_lcm {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 nat.lcm (order_of x) (order_of y) :=\nbegin\n  convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,\n  rw [order_of, comp_mul_left],\nend\n\n@[to_additive add_order_of_add_dvd_mul_add_order_of]\nlemma commute.order_of_mul_dvd_mul_order_of {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 (order_of x) * (order_of y) :=\ndvd_trans h.order_of_mul_dvd_lcm (lcm_dvd_mul _ _)\n\n@[to_additive add_order_of_add_eq_mul_add_order_of_of_coprime]\nlemma commute.order_of_mul_eq_mul_order_of_of_coprime {x y : G} (h : commute x y)\n  (hco : nat.coprime (order_of x) (order_of y)) :\n  order_of (x * y) = (order_of x) * (order_of y) :=\nbegin\n  convert h.function_commute_mul_left.minimal_period_of_comp_eq_mul_of_coprime hco,\n  simp only [order_of, comp_mul_left],\nend\n\n/-- Commuting elements of finite order are closed under multiplication. -/\n@[to_additive \"Commuting elements of finite additive order are closed under addition.\"]\nlemma commute.is_of_fin_order_mul\n  {x} (h : commute x y) (hx : is_of_fin_order x) (hy : is_of_fin_order y) :\n  is_of_fin_order (x * y) :=\norder_of_pos_iff.mp $\n  pos_of_dvd_of_pos h.order_of_mul_dvd_mul_order_of $ mul_pos (order_of_pos' hx) (order_of_pos' hy)\n\nsection p_prime\n\nvariables {a x n} {p : \u2115} [hp : fact p.prime]\ninclude hp\n\n@[to_additive add_order_of_eq_prime]\nlemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x \u2260 1) : order_of x = p :=\nminimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)\n  (by rwa [is_fixed_pt, mul_one])\n\n@[to_additive add_order_of_eq_prime_pow]\nlemma order_of_eq_prime_pow (hnot : \u00ac x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :\n  order_of x = p ^ (n + 1) :=\nbegin\n  apply minimal_period_eq_prime_pow;\n  rwa is_periodic_pt_mul_iff_pow_eq_one,\nend\n\nomit hp\n-- An example on how to determine the order of an element of a finite group.\nexample : order_of (-1 : \u2124\u02e3) = 2 :=\norder_of_eq_prime (int.units_sq _) dec_trivial\n\nend p_prime\n\nend monoid_add_monoid\n\nsection cancel_monoid\nvariables [left_cancel_monoid G] (x y)\n\n@[to_additive]\nlemma pow_injective_aux (h : n \u2264 m)\n  (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\nby_contradiction $ assume ne : n \u2260 m,\n  have h\u2081 : m - n > 0, from nat.pos_of_ne_zero (by simp [tsub_eq_iff_eq_add_of_le h, ne.symm]),\n  have h\u2082 : m = n + (m - n) := (add_tsub_cancel_of_le h).symm,\n  have h\u2083 : x ^ (m - n) = 1,\n    by { rw [h\u2082, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (x ^ n) },\n  have le : order_of x \u2264 m - n, from order_of_le_of_pow_eq_one h\u2081 h\u2083,\n  have lt : m - n < order_of x,\n    from (tsub_lt_iff_left h).mpr $ nat.lt_add_left _ _ _ hm,\n  lt_irrefl _ (le.trans_lt lt)\n\n@[to_additive nsmul_injective_of_lt_add_order_of]\nlemma pow_injective_of_lt_order_of\n  (hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\n(le_total n m).elim\n  (assume h, pow_injective_aux x h hm eq)\n  (assume h, (pow_injective_aux x h hn eq.symm).symm)\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of']\nlemma mem_powers_iff_mem_range_order_of' [decidable_eq G] (hx : 0 < order_of x) :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' hx (\u03bb i, pow_eq_mod_order_of.symm)\n\nlemma pow_eq_one_iff_modeq : x ^ n = 1 \u2194 n \u2261 0 [MOD (order_of x)] :=\nby rw [modeq_zero_iff_dvd, order_of_dvd_iff_pow_eq_one]\n\nlemma pow_eq_pow_iff_modeq : x ^ n = x ^ m \u2194 n \u2261 m [MOD (order_of x)] :=\nbegin\n  wlog hmn : m \u2264 n,\n  obtain \u27e8k, rfl\u27e9 := nat.exists_eq_add_of_le hmn,\n  rw [\u2190 mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modeq],\n  exact \u27e8\u03bb h, nat.modeq.add_left _ h, \u03bb h, nat.modeq.add_left_cancel' _ h\u27e9,\nend\n\nend cancel_monoid\n\nsection group\nvariables [group G] [add_group A] {x a} {i : \u2124}\n\n/-- Inverses of elements of finite order have finite order. -/\n@[to_additive \"Inverses of elements of finite additive order have finite additive order.\"]\nlemma is_of_fin_order.inv {x : G} (hx : is_of_fin_order x) : is_of_fin_order x\u207b\u00b9 :=\n(is_of_fin_order_iff_pow_eq_one _).mpr $ begin\n  rcases (is_of_fin_order_iff_pow_eq_one x).mp hx with \u27e8n, npos, hn\u27e9,\n  refine \u27e8n, npos, by simp_rw [inv_pow, hn, one_inv]\u27e9,\nend\n\n/-- Inverses of elements of finite order have finite order. -/\n@[simp, to_additive \"Inverses of elements of finite additive order have finite additive order.\"]\nlemma is_of_fin_order_inv_iff {x : G} : is_of_fin_order x\u207b\u00b9 \u2194 is_of_fin_order x :=\n\u27e8\u03bb h, inv_inv x \u25b8 h.inv, is_of_fin_order.inv\u27e9\n\n@[to_additive add_order_of_dvd_iff_zsmul_eq_zero]\nlemma order_of_dvd_iff_zpow_eq_one : (order_of x : \u2124) \u2223 i \u2194 x ^ i = 1 :=\nbegin\n  rcases int.eq_coe_or_neg i with \u27e8i, rfl|rfl\u27e9,\n  { rw [int.coe_nat_dvd, order_of_dvd_iff_pow_eq_one, zpow_coe_nat] },\n  { rw [dvd_neg, int.coe_nat_dvd, zpow_neg, inv_eq_one, zpow_coe_nat,\n      order_of_dvd_iff_pow_eq_one] }\nend\n\n@[simp, to_additive]\nlemma order_of_inv (x : G) : order_of x\u207b\u00b9 = order_of x :=\nby simp [order_of_eq_order_of_iff]\n\n@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}\n  (y: H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive zsmul_eq_mod_add_order_of]\nlemma zpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=\ncalc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :\n    by rw [int.mod_add_div]\n       ... = x ^ (i % order_of x) :\n    by simp [zpow_add, zpow_mul, pow_order_of_eq_one]\n    set_option pp.all true\n\n@[to_additive nsmul_inj_iff_of_add_order_of_eq_zero]\nlemma pow_inj_iff_of_order_of_eq_zero (h : order_of x = 0) {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n = m :=\nbegin\n  rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one] at h,\n  push_neg at h,\n  induction n with n IH generalizing m,\n  { cases m,\n    { simp },\n    { simpa [eq_comm] using h m.succ m.zero_lt_succ } },\n  { cases m,\n    { simpa using h n.succ n.zero_lt_succ },\n    { simp [pow_succ, IH] } }\nend\n\n@[to_additive]\nlemma pow_inj_mod {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n % order_of x = m % order_of x :=\nbegin\n  cases (order_of x).zero_le.eq_or_lt with hx hx,\n  { simp [pow_inj_iff_of_order_of_eq_zero, hx.symm] },\n  rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ m],\n  exact \u27e8pow_injective_of_lt_order_of _ (nat.mod_lt _ hx) (nat.mod_lt _ hx), \u03bb h, congr_arg _ h\u27e9\nend\n\nend group\n\nsection comm_monoid\n\nvariables [comm_monoid G]\n\n/-- Elements of finite order are closed under multiplication. -/\n@[to_additive \"Elements of finite additive order are closed under addition.\"]\nlemma is_of_fin_order.mul (hx : is_of_fin_order x) (hy : is_of_fin_order y) :\n  is_of_fin_order (x * y) :=\n(commute.all x y).is_of_fin_order_mul hx hy\n\nend comm_monoid\n\nsection fintype\nvariables [fintype G] [fintype A]\n\nsection finite_monoid\nvariables [monoid G] [add_monoid A]\nopen_locale big_operators\n\n@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]\nlemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :\n  \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n  = (finset.univ.filter (\u03bb x : G, x ^ n = 1)).card :=\ncalc \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n    = _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm\n... = _ : congr_arg finset.card (finset.ext (begin\n  assume x,\n  suffices : order_of x \u2264 n \u2227 order_of x \u2223 n \u2194 x ^ n = 1,\n  { simpa [nat.lt_succ_iff], },\n  exact \u27e8\u03bb h, let \u27e8m, hm\u27e9 := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],\n    \u03bb h, \u27e8order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h\u27e9\u27e9\nend))\n\nend finite_monoid\n\nsection finite_cancel_monoid\n-- TODO: Of course everything also works for right_cancel_monoids.\nvariables [left_cancel_monoid G] [add_left_cancel_monoid A]\n\n-- TODO: Use this to show that a finite left cancellative monoid is a group.\n@[to_additive]\nlemma exists_pow_eq_one (x : G) : is_of_fin_order x :=\nbegin\n  refine (is_of_fin_order_iff_pow_eq_one _).mpr _,\n  obtain \u27e8i, j, a_eq, ne\u27e9 : \u2203(i j : \u2115), x ^ i = x ^ j \u2227 i \u2260 j :=\n    by simpa only [not_forall, exists_prop, injective]\n      using (not_injective_infinite_fintype (\u03bbi:\u2115, x^i)),\n  wlog h'' : j \u2264 i,\n  refine \u27e8i - j, tsub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _\u27e9,\n  rw [mul_one, \u2190 pow_add, \u2190 a_eq, add_tsub_cancel_of_le h''],\nend\n\n@[to_additive add_order_of_le_card_univ]\nlemma order_of_le_card_univ : order_of x \u2264 fintype.card G :=\nfinset.le_card_of_inj_on_range ((^) x)\n  (assume n _, finset.mem_univ _)\n  (assume i hi j hj, pow_injective_of_lt_order_of x hi hj)\n\n/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative monoid.-/\n@[to_additive add_order_of_pos\n\"This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative additive monoid.\"]\nlemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)\n\nopen nat\n\n/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is\nautomatic in the case of a finite cancellative monoid.-/\n@[to_additive add_order_of_nsmul\n\"This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less\nwhich is automatic in the case of a finite cancellative additive monoid.\"]\nlemma order_of_pow (x : G) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of]\nlemma mem_powers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)\n  (assume i, pow_eq_mod_order_of.symm)\n\n@[to_additive decidable_multiples]\nnoncomputable instance decidable_powers [decidable_eq G] :\n  decidable_pred (\u2208 submonoid.powers x) :=\nbegin\n  assume y,\n  apply decidable_of_iff'\n    (y \u2208 (finset.range (order_of x)).image ((^) x)),\n  exact mem_powers_iff_mem_range_order_of\nend\n\n/--The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`.\"-/\n@[to_additive fin_equiv_multiples \"The equivalence between `fin (add_order_of a)` and\n`add_submonoid.multiples a`, sending `i` to `i \u2022 a`.\"]\nnoncomputable def fin_equiv_powers (x : G) :\n  fin (order_of x) \u2243 (submonoid.powers x : set G) :=\nequiv.of_bijective (\u03bb n, \u27e8x ^ \u2191n, \u27e8n, rfl\u27e9\u27e9) \u27e8\u03bb \u27e8i, hi\u27e9 \u27e8j, hj\u27e9 ij,\n  subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),\n  \u03bb \u27e8_, i, rfl\u27e9, \u27e8\u27e8i % order_of x, mod_lt i (order_of_pos x)\u27e9, subtype.eq pow_eq_mod_order_of.symm\u27e9\u27e9\n\n@[simp, to_additive fin_equiv_multiples_apply]\nlemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :\n  fin_equiv_powers x n = \u27e8x ^ \u2191n, n, rfl\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_multiples_symm_apply]\nlemma fin_equiv_powers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2115), x ^ m = x ^ n} :\n  ((fin_equiv_powers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,\n  pow_eq_mod_order_of, fin.coe_mk]\n\n/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive multiples_equiv_multiples\n\"The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def powers_equiv_powers (h : order_of x = order_of y) :\n  (submonoid.powers x : set G) \u2243 (submonoid.powers y : set G) :=\n(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))\n\n@[simp, to_additive multiples_equiv_multiples_apply]\nlemma powers_equiv_powers_apply (h : order_of x = order_of y)\n  (n : \u2115) : powers_equiv_powers h \u27e8x ^ n, n, rfl\u27e9 = \u27e8y ^ n, n, rfl\u27e9 :=\nbegin\n  rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_powers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_powers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_of_eq_card_multiples]\nlemma order_eq_card_powers [decidable_eq G] :\n  order_of x = fintype.card (submonoid.powers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_powers x\u27e9)\n\nend finite_cancel_monoid\n\nsection finite_group\nvariables [group G] [add_group A]\n\n@[to_additive]\nlemma exists_zpow_eq_one (x : G) : \u2203 (i : \u2124) (H : i \u2260 0), x ^ (i : \u2124) = 1 :=\nbegin\n  rcases exists_pow_eq_one x with \u27e8w, hw1, hw2\u27e9,\n  refine \u27e8w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _\u27e9,\n  rw zpow_coe_nat,\n  exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,\nend\n\nopen subgroup\n\n@[to_additive mem_multiples_iff_mem_zmultiples]\nlemma mem_powers_iff_mem_zpowers : y \u2208 submonoid.powers x \u2194 y \u2208 zpowers x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, \u27e8n, by simp * at *\u27e9,\n\u03bb \u27e8i, hi\u27e9, \u27e8(i % order_of x).nat_abs,\n  by rwa [\u2190 zpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _\n    (int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),\n    \u2190 zpow_eq_mod_order_of]\u27e9\u27e9\n\n@[to_additive multiples_eq_zmultiples]\nlemma powers_eq_zpowers (x : G) : (submonoid.powers x : set G) = zpowers x :=\nset.ext $ \u03bb x, mem_powers_iff_mem_zpowers\n\n@[to_additive mem_zmultiples_iff_mem_range_add_order_of]\nlemma mem_zpowers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 subgroup.zpowers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nby rw [\u2190 mem_powers_iff_mem_zpowers, mem_powers_iff_mem_range_order_of]\n\n@[to_additive decidable_zmultiples]\nnoncomputable instance decidable_zpowers [decidable_eq G] :\n  decidable_pred (\u2208 subgroup.zpowers x) :=\nbegin\n  simp_rw \u2190set_like.mem_coe,\n  rw \u2190 powers_eq_zpowers,\n  exact decidable_powers,\nend\n\n/-- The equivalence between `fin (order_of x)` and `subgroup.zpowers x`, sending `i` to `x ^ i`. -/\n@[to_additive fin_equiv_zmultiples\n\"The equivalence between `fin (add_order_of a)` and `subgroup.zmultiples a`, sending `i`\nto `i \u2022 a`.\"]\nnoncomputable def fin_equiv_zpowers (x : G) :\n  fin (order_of x) \u2243 (subgroup.zpowers x : set G) :=\n(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_zpowers x))\n\n@[simp, to_additive fin_equiv_zmultiples_apply]\nlemma fin_equiv_zpowers_apply {n : fin (order_of x)} :\n  fin_equiv_zpowers x n = \u27e8x ^ (n : \u2115), n, zpow_coe_nat x n\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_zmultiples_symm_apply]\nlemma fin_equiv_zpowers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2124), x ^ m = x ^ n} :\n  ((fin_equiv_zpowers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby { rw [fin_equiv_zpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],\n  exact fin_equiv_powers_symm_apply x n }\n\n/-- The equivalence between `subgroup.zpowers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive zmultiples_equiv_zmultiples\n\"The equivalence between `subgroup.zmultiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def zpowers_equiv_zpowers (h : order_of x = order_of y) :\n  (subgroup.zpowers x : set G) \u2243 (subgroup.zpowers y : set G) :=\n(fin_equiv_zpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_zpowers y))\n\n@[simp, to_additive zmultiples_equiv_zmultiples_apply]\nlemma zpowers_equiv_zpowers_apply (h : order_of x = order_of y)\n  (n : \u2115) : zpowers_equiv_zpowers h \u27e8x ^ n, n, zpow_coe_nat x n\u27e9 = \u27e8y ^ n, n, zpow_coe_nat y n\u27e9 :=\nbegin\n  rw [zpowers_equiv_zpowers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_zpowers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_zpowers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_eq_card_zmultiples]\nlemma order_eq_card_zpowers [decidable_eq G] :\n  order_of x = fintype.card (subgroup.zpowers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_zpowers x\u27e9)\n\nopen quotient_group\n\n/- TODO: use cardinal theory, introduce `card : set G \u2192 \u2115`, or setup decidability for cosets -/\n@[to_additive add_order_of_dvd_card_univ]\nlemma order_of_dvd_card_univ : order_of x \u2223 fintype.card G :=\nbegin\n  classical,\n  have ft_prod : fintype ((G \u29f8 zpowers x) \u00d7 zpowers x),\n    from fintype.of_equiv G group_equiv_quotient_times_subgroup,\n  have ft_s : fintype (zpowers x),\n    from @fintype.prod_right _ _ _ ft_prod _,\n  have ft_cosets : fintype (G \u29f8 zpowers x),\n    from @fintype.prod_left _ _ _ ft_prod \u27e8\u27e81, (zpowers x).one_mem\u27e9\u27e9,\n  have eq\u2081 : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,\n    from calc fintype.card G = @fintype.card _ ft_prod :\n        @fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup\n      ... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :\n        congr_arg (@fintype.card _) $ subsingleton.elim _ _\n      ... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :\n        @fintype.card_prod _ _ ft_cosets ft_s,\n  have eq\u2082 : order_of x = @fintype.card _ ft_s,\n    from calc order_of x = _ : order_eq_card_zpowers\n      ... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,\n  exact dvd.intro (@fintype.card (G \u29f8 subgroup.zpowers x) ft_cosets)\n          (by rw [eq\u2081, eq\u2082, mul_comm])\nend\n\n@[simp, to_additive card_nsmul_eq_zero] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=\nlet \u27e8m, hm\u27e9 := @order_of_dvd_card_univ _ x _ _ in\nby simp [hm, pow_mul, pow_order_of_eq_one]\n\n@[to_additive] lemma pow_eq_mod_card (n : \u2115) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [pow_eq_mod_order_of, \u2190nat.mod_mod_of_dvd n order_of_dvd_card_univ,\n  \u2190 pow_eq_mod_order_of]\n\n@[to_additive] lemma zpow_eq_mod_card (n : \u2124) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [zpow_eq_mod_order_of, \u2190 int.mod_mod_of_dvd n (int.coe_nat_dvd.2 order_of_dvd_card_univ),\n  \u2190 zpow_eq_mod_order_of]\n\n/-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/\n@[to_additive \"If `gcd(|G|,n)=1` then the smul by `n` is a bijection\", simps]\n  def pow_coprime (h : nat.coprime (fintype.card G) n) : G \u2243 G :=\n{ to_fun := \u03bb g, g ^ n,\n  inv_fun := \u03bb g, g ^ (nat.gcd_b (fintype.card G) n),\n  left_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul, zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key },\n  right_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul', zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key } }\n\n@[simp, to_additive] lemma pow_coprime_one (h : nat.coprime (fintype.card G) n) :\n  pow_coprime h 1 = 1 := one_pow n\n\n@[simp, to_additive] lemma pow_coprime_inv (h : nat.coprime (fintype.card G) n) {g : G} :\n  pow_coprime h g\u207b\u00b9 = (pow_coprime h g)\u207b\u00b9 := inv_pow g n\n\n@[to_additive add_inf_eq_bot_of_coprime]\nlemma inf_eq_bot_of_coprime {G : Type*} [group G] {H K : subgroup G} [fintype H] [fintype K]\n  (h : nat.coprime (fintype.card H) (fintype.card K)) : H \u2293 K = \u22a5 :=\nbegin\n  refine (H \u2293 K).eq_bot_iff_forall.mpr (\u03bb x hx, _),\n  rw [\u2190order_of_eq_one_iff, \u2190nat.dvd_one, \u2190h.gcd_eq_one, nat.dvd_gcd_iff],\n  exact \u27e8(congr_arg (\u2223 fintype.card H) (order_of_subgroup \u27e8x, hx.1\u27e9)).mpr order_of_dvd_card_univ,\n    (congr_arg (\u2223 fintype.card K) (order_of_subgroup \u27e8x, hx.2\u27e9)).mpr order_of_dvd_card_univ\u27e9,\nend\n\nvariable (a)\n\n/-- TODO: Generalise to `submonoid.powers`.-/\n@[to_additive image_range_add_order_of]\nlemma image_range_order_of [decidable_eq G] :\n  finset.image (\u03bb i, x ^ i) (finset.range (order_of x)) = (zpowers x : set G).to_finset :=\nby { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_zpowers_iff_mem_range_order_of] }\n\n/-- TODO: Generalise to `finite_cancel_monoid`. -/\n@[to_additive gcd_nsmul_card_eq_zero_iff]\nlemma pow_gcd_card_eq_one_iff : x ^ n = 1 \u2194 x ^ (gcd n (fintype.card G)) = 1 :=\n\u27e8\u03bb h, pow_gcd_eq_one _ h $ pow_card_eq_one,\n  \u03bb h, let \u27e8m, hm\u27e9 := gcd_dvd_left n (fintype.card G) in\n    by rw [hm, pow_mul, h, one_pow]\u27e9\n\nend finite_group\n\nend fintype\n\nsection pow_is_subgroup\n\n/-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/\n@[to_additive \"A nonempty idempotent subset of a finite cancellative add monoid is a submonoid\"]\ndef submonoid_of_idempotent {M : Type*} [left_cancel_monoid M] [fintype M] (S : set M)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : submonoid M :=\nhave pow_mem : \u2200 a : M, a \u2208 S \u2192 \u2200 n : \u2115, a ^ (n + 1) \u2208 S :=\n\u03bb a ha, nat.rec (by rwa [zero_add, pow_one])\n  (\u03bb n ih, (congr_arg2 (\u2208) (pow_succ a (n + 1)).symm hS2).mp (set.mul_mem_mul ha ih)),\n{ carrier := S,\n  one_mem' := by\n  { obtain \u27e8a, ha\u27e9 := hS1,\n    rw [\u2190pow_order_of_eq_one a, \u2190 tsub_add_cancel_of_le (succ_le_of_lt (order_of_pos a))],\n    exact pow_mem a ha (order_of a - 1) },\n  mul_mem' := \u03bb a b ha hb, (congr_arg2 (\u2208) rfl hS2).mp (set.mul_mem_mul ha hb) }\n\n/-- A nonempty idempotent subset of a finite group is a subgroup -/\n@[to_additive \"A nonempty idempotent subset of a finite add group is a subgroup\"]\ndef subgroup_of_idempotent {G : Type*} [group G] [fintype G] (S : set G)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : subgroup G :=\n{ carrier := S,\n  inv_mem' := \u03bb a ha, by\n  { rw [\u2190one_mul a\u207b\u00b9, \u2190pow_one a, \u2190pow_order_of_eq_one a, \u2190pow_sub a (order_of_pos a)],\n    exact (submonoid_of_idempotent S hS1 hS2).pow_mem ha (order_of a - 1) },\n  .. submonoid_of_idempotent S hS1 hS2 }\n\n/-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/\n@[to_additive smul_card_add_subgroup \"If `S` is a nonempty subset of a finite add group `G`,\n  then `|G| \u2022 S` is a subgroup\", simps]\ndef pow_card_subgroup {G : Type*} [group G] [fintype G] (S : set G) (hS : S.nonempty) :\n  subgroup G :=\nhave one_mem : (1 : G) \u2208 (S ^ fintype.card G) := by\n{ obtain \u27e8a, ha\u27e9 := hS,\n  rw \u2190 pow_card_eq_one,\n  exact set.pow_mem_pow ha (fintype.card G) },\nsubgroup_of_idempotent (S ^ (fintype.card G)) \u27e81, one_mem\u27e9 begin\n  classical,\n  refine (set.eq_of_subset_of_card_le\n    (\u03bb b hb, (congr_arg (\u2208 _) (one_mul b)).mp (set.mul_mem_mul one_mem hb)) (ge_of_eq _)).symm,\n  change _ = fintype.card (_ * _ : set G),\n  rw [\u2190pow_add, group.card_pow_eq_card_pow_card_univ S (fintype.card G) le_rfl,\n      group.card_pow_eq_card_pow_card_univ S (fintype.card G + fintype.card G) le_add_self],\nend\n\nend pow_is_subgroup\n\nsection linear_ordered_ring\n\nvariable [linear_ordered_ring G]\n\nlemma order_of_abs_ne_one (h : |x| \u2260 1) : order_of x = 0 :=\nbegin\n  rw order_of_eq_zero_iff',\n  intros n hn hx,\n  replace hx : |x| ^ n = 1 := by simpa only [abs_one, abs_pow] using congr_arg abs hx,\n  cases h.lt_or_lt with h h,\n  { exact ((pow_lt_one (abs_nonneg x) h hn.ne').ne hx).elim },\n  { exact ((one_lt_pow h hn.ne').ne' hx).elim }\nend\n\nlemma linear_ordered_ring.order_of_le_two : order_of x \u2264 2 :=\nbegin\n  cases ne_or_eq (|x|) 1 with h h,\n  { simp [order_of_abs_ne_one h] },\n  rcases eq_or_eq_neg_of_abs_eq h with rfl | rfl,\n  { simp },\n  apply order_of_le_of_pow_eq_one; norm_num\nend\n\nend linear_ordered_ring\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/group_theory/order_of_element.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7495433036302576}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Sets in Lean, example sheet 2 : the empty set and the \"universal set\".\n\nWe know what the empty subset of `X` is, and the Lean notation for\nit is `\u2205`, or, if you want to say which type we're the empty subset\nof, it's `\u2205 : set X`. \n\nAt the other extreme, the subset of `X` containing all the terms of type `X`\nis...well...mathematicians would just call it `X`, but `X` is a type, and\nso if we want a set it's called `set.univ : set X`, or just `univ : set X` if\nwe have opened the `set` namespace. Let's do that now.\n\n-/\n\nopen set\n\n/-\n\n## Important\n\n`x \u2208 \u2205` is *by definition* equal to `false` and `x \u2208 univ` is *by definition*\nequal to `true`. You can use the `change` tactic to make these changes\nif you like. But you don't have to.\n\n## Tactics you will need\n\nYou've seen them already. `trivial` proves `\u22a2 true` and `exfalso`\nchanges `\u22a2 P` to `\u22a2 false`.\n\n-/\n\n\n-- set up variables\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D E : set X) -- A,B,C,D,E are subsets of `X`\n  (x y z : X) -- x,y,z are elements of `X` or, more precisely, terms of type `X`\n\n/-\n\nIf `x : X` then `x \u2208 \u2205` is *by definition* `false`, and `x \u2208 univ` is\n*by definition* `true`. So you can use the `change` tactic to change\nbetween these things, for example if your goal is\n\n```\n\u22a2 x \u2208 univ\n```\n\nthen `change true` will change the goal to\n\n```\n\u22a2 true\n```\n\nand you can now prove this goal with `trivial`. However you can prove\nit with `trivial` even without `change`ing it.\n\n-/\n\nopen set\n\nexample : x \u2208 (univ : set X) := \nbegin\n  sorry\nend\n\nexample : x \u2208 (\u2205 : set X) \u2192 false :=\nbegin\n  sorry\nend\n\nexample : \u2200 x : X, x \u2208 A \u2192 x \u2208 (univ : set X) :=\nbegin\n  sorry\nend\n\nexample : \u2200 x : X, x \u2208 (\u2205 : set X) \u2192 x \u2208 A :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2022/sets/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7495432948608686}}
{"text": "universe u\nvariables (\u03b1 \u03b2 \u03b3 : Type u)\n\n-- Exercise 1\n--\n-- Define the function do_twice, as described in Section 2.4.\ndef do_twice : (\u03b1 \u2192 \u03b1) \u2192 \u03b1 \u2192 \u03b1 :=\n  \u03bb f : (\u03b1 \u2192 \u03b1), \u03bb x : \u03b1, f (f x)\n\n-- Exericse 2\n--\n-- Define the functions curry and uncurry, as described in Section 2.4.\ndef curry (f : \u03b1 \u00d7 \u03b2 \u2192 \u03b3) : \u03b1 \u2192 \u03b2 \u2192 \u03b3 :=\n  \u03bb a : \u03b1, \u03bb b : \u03b2, f (a, b)\n\ndef uncurry (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) : \u03b1 \u00d7 \u03b2 \u2192 \u03b3 :=\n  \u03bb p : \u03b1 \u00d7 \u03b2, f p.fst p.snd\n\n-- Exercise 3\n--\n-- Above, we used the example vec \u03b1 n for vectors of elements of type \u03b1 of\n-- length n. Declare a constant vec_add that could represent a function that\n-- adds two vectors of natural numbers of the same length, and a constant\n-- vec_reverse that can represent a function that reverses its argument. Use\n-- implicit arguments for parameters that can be inferred. Declare some\n-- variables and check some expressions involving the constants that you have\n-- declared.\nconstant vec : Type u \u2192 \u2115 \u2192 Type u\n\nconstant vec_add : \u03a0 {\u03b1 : Type u}, \u03a0 {m n : \u2115}, vec \u03b1 m \u2192 vec \u03b1 n \u2192 vec \u03b1 (m + n)\n\nconstant vec_reverse : \u03a0 {\u03b1 : Type u}, \u03a0 {n : \u2115}, vec \u03b1 n \u2192 vec \u03b1 n\n\nconstant vec1 : vec \u2115 4\nconstant vec2 : vec \u2115 3\n\nsection\n  variables (vec1 : vec \u2115 4) (vec2 : vec \u2115 5)\n\n  #check vec_add vec1 vec2\n  #check vec_add vec2 vec1\n\n  #check vec_reverse vec1\n  #check vec_reverse vec2\nend\n\n-- Exericse 4\n--\n-- Similarly, declare a constant matrix so that matrix \u03b1 m n could represent the\n-- type of m by n matrices. Declare some constants to represent functions on\n-- this type, such as matrix addition and multiplication, and (using vec)\n-- multiplication of a matrix by a vector. Once again, declare some variables\n-- and check some expressions involving the constants that you have declared.\nconstant matrix : Type u \u2192 \u2115 \u2192 \u2115 \u2192 Type u\n\nconstant matrix_add : \u03a0 {\u03b1 : Type u}, \u03a0 {m n : \u2115}, matrix \u03b1 m n \u2192 matrix \u03b1 m n \u2192 matrix \u03b1 m n\n\nconstant matrix_mul : \u03a0 {\u03b1 : Type u}, \u03a0 {l m n : \u2115}, matrix \u03b1 l m \u2192 matrix \u03b1 m n \u2192 matrix \u03b1 l m\n\nsection\n  variables\n    (matrix1 : matrix \u2115 2 2)\n    (matrix2 : matrix \u2115 3 2)\n\n  #check matrix_add matrix1 matrix1\n\n  -- Expect this to fail:\n  -- #check matrix_add matrix1 matrix2\n\n  #check matrix_mul matrix2 matrix1\n\n  -- Expect this to fail:\n  -- #check matrix_mul matrix1 matrix2\nend\n", "meta": {"author": "crockeo", "repo": "math-exercises", "sha": "cf9150ef9e025f1b7929ba070a783e7a71f24f31", "save_path": "github-repos/lean/crockeo-math-exercises", "path": "github-repos/lean/crockeo-math-exercises/math-exercises-cf9150ef9e025f1b7929ba070a783e7a71f24f31/tpil/chapter2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7494725233497709}}
{"text": "-- Regla del conjunto vac\u00edo\n-- ========================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    \u2205 \u2286 A\n-- ----------------------------------------------------\n\nimport data.set\n\nvariable  U : Type\nvariables A : set U\nvariable  x : U\n\nopen set\n\n-- #reduce (\u2205 : set U)\n-- #reduce x \u2208 (\u2205 : set U) \n\n-- 1\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\nbegin\n  intros x h,\n  simp at h,\n  exfalso,\n  exact h,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\nbegin\n  intros x h,\n  exfalso,\n  exact h,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\nassume x,\nassume h : x \u2208 (\u2205 : set U),\nshow x \u2208 A, from false.elim h\n\n-- 4\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\n\u03bb x, \u03bb h, false.elim h\n\n-- 5\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\n\u03bb _, false.elim \n\n-- 6\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\n-- by library_search\nempty_subset A\n\n-- 7\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\nassume x,\nassume h : x \u2208 (\u2205 : set U),\nshow x \u2208 A, from absurd h (not_mem_empty x)\n\n-- 8\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\n\u03bb x h, absurd h (not_mem_empty x)\n\n-- 9\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\n-- by hint\nby tauto\n\n-- 10\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\nby finish\n\n-- 11\u00aa demostraci\u00f3n\nexample : \u2205 \u2286 A :=\nby simp \n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Minimimalidad_del_vacio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7494725149160042}}
{"text": "/-\nCopyright (c) 2019 Yury Kudriashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudriashov\n-/\nimport algebra.big_operators.order\nimport analysis.convex.hull\nimport linear_algebra.affine_space.basis\n\n/-!\n# Convex combinations\n\nThis file defines convex combinations of points in a vector space.\n\n## Main declarations\n\n* `finset.center_mass`: Center of mass of a finite family of points.\n\n## Implementation notes\n\nWe divide by the sum of the weights in the definition of `finset.center_mass` because of the way\nmathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few\nlemmas unconditional on the sum of the weights being `1`.\n-/\n\nopen set\nopen_locale big_operators classical pointwise\n\nuniverses u u'\nvariables {R E F \u03b9 \u03b9' : Type*} [linear_ordered_field R] [add_comm_group E] [add_comm_group F]\n  [module R E] [module R F] {s : set E}\n\n/-- Center of mass of a finite collection of points with prescribed weights.\nNote that we require neither `0 \u2264 w i` nor `\u2211 w = 1`. -/\ndef finset.center_mass (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E) : E :=\n(\u2211 i in t, w i)\u207b\u00b9 \u2022 (\u2211 i in t, w i \u2022 z i)\n\nvariables (i j : \u03b9) (c : R) (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n\nopen finset\n\nlemma finset.center_mass_empty : (\u2205 : finset \u03b9).center_mass w z = 0 :=\nby simp only [center_mass, sum_empty, smul_zero]\n\nlemma finset.center_mass_pair (hne : i \u2260 j) :\n  ({i, j} : finset \u03b9).center_mass w z = (w i / (w i + w j)) \u2022 z i + (w j / (w i + w j)) \u2022 z j :=\nby simp only [center_mass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul]\n\nvariable {w}\n\nlemma finset.center_mass_insert (ha : i \u2209 t) (hw : \u2211 j in t, w j \u2260 0) :\n  (insert i t).center_mass w z = (w i / (w i + \u2211 j in t, w j)) \u2022 z i +\n    ((\u2211 j in t, w j) / (w i + \u2211 j in t, w j)) \u2022 t.center_mass w z :=\nbegin\n  simp only [center_mass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, \u2190 div_eq_inv_mul],\n  congr' 2,\n  rw [div_mul_eq_mul_div, mul_inv_cancel hw, one_div]\nend\n\nlemma finset.center_mass_singleton (hw : w i \u2260 0) : ({i} : finset \u03b9).center_mass w z = z i :=\nby rw [center_mass, sum_singleton, sum_singleton, \u2190 mul_smul, inv_mul_cancel hw, one_smul]\n\nlemma finset.center_mass_eq_of_sum_1 (hw : \u2211 i in t, w i = 1) :\n  t.center_mass w z = \u2211 i in t, w i \u2022 z i :=\nby simp only [finset.center_mass, hw, inv_one, one_smul]\n\nlemma finset.center_mass_smul : t.center_mass w (\u03bb i, c \u2022 z i) = c \u2022 t.center_mass w z :=\nby simp only [finset.center_mass, finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc]\n\n/-- A convex combination of two centers of mass is a center of mass as well. This version\ndeals with two different index types. -/\nlemma finset.center_mass_segment'\n  (s : finset \u03b9) (t : finset \u03b9') (ws : \u03b9 \u2192 R) (zs : \u03b9 \u2192 E) (wt : \u03b9' \u2192 R) (zt : \u03b9' \u2192 E)\n  (hws : \u2211 i in s, ws i = 1) (hwt : \u2211 i in t, wt i = 1) (a b : R) (hab : a + b = 1) :\n  a \u2022 s.center_mass ws zs + b \u2022 t.center_mass wt zt =\n    (s.map function.embedding.inl \u222a t.map function.embedding.inr).center_mass\n      (sum.elim (\u03bb i, a * ws i) (\u03bb j, b * wt j))\n      (sum.elim zs zt) :=\nbegin\n  rw [s.center_mass_eq_of_sum_1 _ hws, t.center_mass_eq_of_sum_1 _ hwt,\n    smul_sum, smul_sum, \u2190 finset.sum_sum_elim, finset.center_mass_eq_of_sum_1],\n  { congr' with \u27e8\u27e9; simp only [sum.elim_inl, sum.elim_inr, mul_smul] },\n  { rw [sum_sum_elim, \u2190 mul_sum, \u2190 mul_sum, hws, hwt, mul_one, mul_one, hab] }\nend\n\n/-- A convex combination of two centers of mass is a center of mass as well. This version\nworks if two centers of mass share the set of original points. -/\nlemma finset.center_mass_segment\n  (s : finset \u03b9) (w\u2081 w\u2082 : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n  (hw\u2081 : \u2211 i in s, w\u2081 i = 1) (hw\u2082 : \u2211 i in s, w\u2082 i = 1) (a b : R) (hab : a + b = 1) :\n  a \u2022 s.center_mass w\u2081 z + b \u2022 s.center_mass w\u2082 z =\n    s.center_mass (\u03bb i, a * w\u2081 i + b * w\u2082 i) z :=\nhave hw : \u2211 i in s, (a * w\u2081 i + b * w\u2082 i) = 1,\n  by simp only [mul_sum.symm, sum_add_distrib, mul_one, *],\nby simp only [finset.center_mass_eq_of_sum_1, smul_sum, sum_add_distrib, add_smul, mul_smul, *]\n\nlemma finset.center_mass_ite_eq (hi : i \u2208 t) :\n  t.center_mass (\u03bb j, if (i = j) then (1 : R) else 0) z = z i :=\nbegin\n  rw [finset.center_mass_eq_of_sum_1],\n  transitivity \u2211 j in t, if (i = j) then z i else 0,\n  { congr' with i, split_ifs, exacts [h \u25b8 one_smul _ _, zero_smul _ _] },\n  { rw [sum_ite_eq, if_pos hi] },\n  { rw [sum_ite_eq, if_pos hi] }\nend\n\nvariables {t w}\n\nlemma finset.center_mass_subset {t' : finset \u03b9} (ht : t \u2286 t')\n  (h : \u2200 i \u2208 t', i \u2209 t \u2192 w i = 0) :\n  t.center_mass w z = t'.center_mass w z :=\nbegin\n  rw [center_mass, sum_subset ht h, smul_sum, center_mass, smul_sum],\n  apply sum_subset ht,\n  assume i hit' hit,\n  rw [h i hit' hit, zero_smul, smul_zero]\nend\n\nlemma finset.center_mass_filter_ne_zero :\n  (t.filter (\u03bb i, w i \u2260 0)).center_mass w z = t.center_mass w z :=\nfinset.center_mass_subset z (filter_subset _ _) $ \u03bb i hit hit',\n  by simpa only [hit, mem_filter, true_and, ne.def, not_not] using hit'\n\nvariable {z}\n\n/-- The center of mass of a finite subset of a convex set belongs to the set\nprovided that all weights are non-negative, and the total weight is positive. -/\nlemma convex.center_mass_mem (hs : convex R s) :\n  (\u2200 i \u2208 t, 0 \u2264 w i) \u2192 (0 < \u2211 i in t, w i) \u2192 (\u2200 i \u2208 t, z i \u2208 s) \u2192 t.center_mass w z \u2208 s :=\nbegin\n  induction t using finset.induction with i t hi ht, { simp [lt_irrefl] },\n  intros h\u2080 hpos hmem,\n  have zi : z i \u2208 s, from hmem _ (mem_insert_self _ _),\n  have hs\u2080 : \u2200 j \u2208 t, 0 \u2264 w j, from \u03bb j hj, h\u2080 j $ mem_insert_of_mem hj,\n  rw [sum_insert hi] at hpos,\n  by_cases hsum_t : \u2211 j in t, w j = 0,\n  { have ws : \u2200 j \u2208 t, w j = 0, from (sum_eq_zero_iff_of_nonneg hs\u2080).1 hsum_t,\n    have wz : \u2211 j in t, w j \u2022 z j = 0, from sum_eq_zero (\u03bb i hi, by simp [ws i hi]),\n    simp only [center_mass, sum_insert hi, wz, hsum_t, add_zero],\n    simp only [hsum_t, add_zero] at hpos,\n    rw [\u2190 mul_smul, inv_mul_cancel (ne_of_gt hpos), one_smul],\n    exact zi },\n  { rw [finset.center_mass_insert _ _ _ hi hsum_t],\n    refine convex_iff_div.1 hs zi (ht hs\u2080 _ _) _ (sum_nonneg hs\u2080) hpos,\n    { exact lt_of_le_of_ne (sum_nonneg hs\u2080) (ne.symm hsum_t) },\n    { intros j hj, exact hmem j (mem_insert_of_mem hj) },\n    { exact h\u2080 _ (mem_insert_self _ _) } }\nend\n\nlemma convex.sum_mem (hs : convex R s) (h\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (h\u2081 : \u2211 i in t, w i = 1)\n  (hz : \u2200 i \u2208 t, z i \u2208 s) :\n  \u2211 i in t, w i \u2022 z i \u2208 s :=\nby simpa only [h\u2081, center_mass, inv_one, one_smul] using\n  hs.center_mass_mem h\u2080 (h\u2081.symm \u25b8 zero_lt_one) hz\n\nlemma convex_iff_sum_mem :\n  convex R s \u2194\n    (\u2200 (t : finset E) (w : E \u2192 R),\n      (\u2200 i \u2208 t, 0 \u2264 w i) \u2192 \u2211 i in t, w i = 1 \u2192 (\u2200 x \u2208 t, x \u2208 s) \u2192 \u2211 x in t, w x \u2022 x \u2208 s ) :=\nbegin\n  refine \u27e8\u03bb hs t w hw\u2080 hw\u2081 hts, hs.sum_mem hw\u2080 hw\u2081 hts, _\u27e9,\n  intros h x y hx hy a b ha hb hab,\n  by_cases h_cases: x = y,\n  { rw [h_cases, \u2190add_smul, hab, one_smul], exact hy },\n  { convert h {x, y} (\u03bb z, if z = y then b else a) _ _ _,\n    { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl] },\n    { simp_intros i hi,\n      cases hi; subst i; simp [ha, hb, if_neg h_cases] },\n    { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl, hab] },\n    { simp_intros i hi,\n      cases hi; subst i; simp [hx, hy, if_neg h_cases] } }\nend\n\nlemma finset.center_mass_mem_convex_hull (t : finset \u03b9) {w : \u03b9 \u2192 R} (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (hws : 0 < \u2211 i in t, w i) {z : \u03b9 \u2192 E} (hz : \u2200 i \u2208 t, z i \u2208 s) :\n  t.center_mass w z \u2208 convex_hull R s :=\n(convex_convex_hull R s).center_mass_mem hw\u2080 hws (\u03bb i hi, subset_convex_hull R s $ hz i hi)\n\n/-- A refinement of `finset.center_mass_mem_convex_hull` when the indexed family is a `finset` of\nthe space. -/\nlemma finset.center_mass_id_mem_convex_hull (t : finset E) {w : E \u2192 R} (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (hws : 0 < \u2211 i in t, w i) :\n  t.center_mass w id \u2208 convex_hull R (t : set E) :=\nt.center_mass_mem_convex_hull hw\u2080 hws (\u03bb i, mem_coe.2)\n\nlemma affine_combination_eq_center_mass {\u03b9 : Type*} {t : finset \u03b9} {p : \u03b9 \u2192 E} {w : \u03b9 \u2192 R}\n  (hw\u2082 : \u2211 i in t, w i = 1) :\n  affine_combination t p w = center_mass t w p :=\nbegin\n  rw [affine_combination_eq_weighted_vsub_of_point_vadd_of_sum_eq_one _ w _ hw\u2082 (0 : E),\n    finset.weighted_vsub_of_point_apply, vadd_eq_add, add_zero, t.center_mass_eq_of_sum_1 _ hw\u2082],\n  simp_rw [vsub_eq_sub, sub_zero],\nend\n\nlemma affine_combination_mem_convex_hull\n  {s : finset \u03b9} {v : \u03b9 \u2192 E} {w : \u03b9 \u2192 R} (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : s.sum w = 1) :\n  s.affine_combination v w \u2208 convex_hull R (range v) :=\nbegin\n  rw affine_combination_eq_center_mass hw\u2081,\n  apply s.center_mass_mem_convex_hull hw\u2080,\n  { simp [hw\u2081], },\n  { simp, },\nend\n\n/-- The centroid can be regarded as a center of mass. -/\n@[simp] lemma finset.centroid_eq_center_mass (s : finset \u03b9) (hs : s.nonempty) (p : \u03b9 \u2192 E) :\n  s.centroid R p = s.center_mass (s.centroid_weights R) p :=\naffine_combination_eq_center_mass (s.sum_centroid_weights_eq_one_of_nonempty R hs)\n\nlemma finset.centroid_mem_convex_hull (s : finset E) (hs : s.nonempty) :\n  s.centroid R id \u2208 convex_hull R (s : set E) :=\nbegin\n  rw s.centroid_eq_center_mass hs,\n  apply s.center_mass_id_mem_convex_hull,\n  { simp only [inv_nonneg, implies_true_iff, nat.cast_nonneg, finset.centroid_weights_apply], },\n  { have hs_card : (s.card : R) \u2260 0, { simp [finset.nonempty_iff_ne_empty.mp hs] },\n    simp only [hs_card, finset.sum_const, nsmul_eq_mul, mul_inv_cancel, ne.def, not_false_iff,\n      finset.centroid_weights_apply, zero_lt_one] }\nend\n\nlemma convex_hull_range_eq_exists_affine_combination (v : \u03b9 \u2192 E) :\n  convex_hull R (range v) = { x | \u2203 (s : finset \u03b9) (w : \u03b9 \u2192 R)\n    (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : s.sum w = 1), s.affine_combination v w = x } :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    obtain \u27e8i, hi\u27e9 := set.mem_range.mp hx,\n    refine \u27e8{i}, function.const \u03b9 (1 : R), by simp, by simp, by simp [hi]\u27e9, },\n  { rw convex,\n    rintros x y \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9 \u27e8s', w', hw\u2080', hw\u2081', rfl\u27e9 a b ha hb hab,\n    let W : \u03b9 \u2192 R := \u03bb i, (if i \u2208 s then a * w i else 0) + (if i \u2208 s' then b * w' i else 0),\n    have hW\u2081 : (s \u222a s').sum W = 1,\n    { rw [sum_add_distrib, \u2190 sum_subset (subset_union_left s s'),\n        \u2190 sum_subset (subset_union_right s s'), sum_ite_of_true _ _ (\u03bb i hi, hi),\n        sum_ite_of_true _ _ (\u03bb i hi, hi), \u2190 mul_sum, \u2190 mul_sum, hw\u2081, hw\u2081', \u2190 add_mul, hab, mul_one];\n      intros i hi hi';\n      simp [hi'], },\n    refine \u27e8s \u222a s', W, _, hW\u2081, _\u27e9,\n    { rintros i -,\n      by_cases hi : i \u2208 s;\n      by_cases hi' : i \u2208 s';\n      simp [hi, hi', add_nonneg, mul_nonneg ha (hw\u2080 i _), mul_nonneg hb (hw\u2080' i _)], },\n    { simp_rw [affine_combination_eq_linear_combination (s \u222a s') v _ hW\u2081,\n        affine_combination_eq_linear_combination s v w hw\u2081,\n        affine_combination_eq_linear_combination s' v w' hw\u2081', add_smul, sum_add_distrib],\n      rw [\u2190 sum_subset (subset_union_left s s'), \u2190 sum_subset (subset_union_right s s')],\n      { simp only [ite_smul, sum_ite_of_true _ _ (\u03bb i hi, hi), mul_smul, \u2190 smul_sum], },\n      { intros i hi hi', simp [hi'], },\n      { intros i hi hi', simp [hi'], }, }, },\n  { rintros x \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9,\n    exact affine_combination_mem_convex_hull hw\u2080 hw\u2081, },\nend\n\n/-- Convex hull of `s` is equal to the set of all centers of masses of `finset`s `t`, `z '' t \u2286 s`.\nThis version allows finsets in any type in any universe. -/\nlemma convex_hull_eq (s : set E) :\n  convex_hull R s = {x : E | \u2203 (\u03b9 : Type u') (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n    (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (hw\u2081 : \u2211 i in t, w i = 1) (hz : \u2200 i \u2208 t, z i \u2208 s),\n    t.center_mass w z = x} :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    use [punit, {punit.star}, \u03bb _, 1, \u03bb _, x, \u03bb _ _, zero_le_one,\n      finset.sum_singleton, \u03bb _ _, hx],\n    simp only [finset.center_mass, finset.sum_singleton, inv_one, one_smul] },\n  { rintros x y \u27e8\u03b9, sx, wx, zx, hwx\u2080, hwx\u2081, hzx, rfl\u27e9 \u27e8\u03b9', sy, wy, zy, hwy\u2080, hwy\u2081, hzy, rfl\u27e9\n      a b ha hb hab,\n    rw [finset.center_mass_segment' _ _ _ _ _ _ hwx\u2081 hwy\u2081 _ _ hab],\n    refine \u27e8_, _, _, _, _, _, _, rfl\u27e9,\n    { rintros i hi,\n      rw [finset.mem_union, finset.mem_map, finset.mem_map] at hi,\n      rcases hi with \u27e8j, hj, rfl\u27e9|\u27e8j, hj, rfl\u27e9;\n        simp only [sum.elim_inl, sum.elim_inr];\n        apply_rules [mul_nonneg, hwx\u2080, hwy\u2080] },\n    { simp [finset.sum_sum_elim, finset.mul_sum.symm, *] },\n    { intros i hi,\n      rw [finset.mem_union, finset.mem_map, finset.mem_map] at hi,\n      rcases hi with \u27e8j, hj, rfl\u27e9|\u27e8j, hj, rfl\u27e9; apply_rules [hzx, hzy] } },\n  { rintros _ \u27e8\u03b9, t, w, z, hw\u2080, hw\u2081, hz, rfl\u27e9,\n    exact t.center_mass_mem_convex_hull hw\u2080 (hw\u2081.symm \u25b8 zero_lt_one) hz }\nend\n\nlemma finset.convex_hull_eq (s : finset E) :\n  convex_hull R \u2191s = {x : E | \u2203 (w : E \u2192 R) (hw\u2080 : \u2200 y \u2208 s, 0 \u2264 w y) (hw\u2081 : \u2211 y in s, w y = 1),\n    s.center_mass w id = x} :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    rw [finset.mem_coe] at hx,\n    refine \u27e8_, _, _, finset.center_mass_ite_eq _ _ _ hx\u27e9,\n    { intros, split_ifs, exacts [zero_le_one, le_refl 0] },\n    { rw [finset.sum_ite_eq, if_pos hx] } },\n  { rintros x y \u27e8wx, hwx\u2080, hwx\u2081, rfl\u27e9 \u27e8wy, hwy\u2080, hwy\u2081, rfl\u27e9\n      a b ha hb hab,\n    rw [finset.center_mass_segment _ _ _ _ hwx\u2081 hwy\u2081 _ _ hab],\n    refine \u27e8_, _, _, rfl\u27e9,\n    { rintros i hi,\n      apply_rules [add_nonneg, mul_nonneg, hwx\u2080, hwy\u2080], },\n    { simp only [finset.sum_add_distrib, finset.mul_sum.symm, mul_one, *] } },\n  { rintros _ \u27e8w, hw\u2080, hw\u2081, rfl\u27e9,\n    exact s.center_mass_mem_convex_hull (\u03bb x hx, hw\u2080 _ hx)\n      (hw\u2081.symm \u25b8 zero_lt_one) (\u03bb x hx, hx) }\nend\n\nlemma set.finite.convex_hull_eq {s : set E} (hs : s.finite) :\n  convex_hull R s = {x : E | \u2203 (w : E \u2192 R) (hw\u2080 : \u2200 y \u2208 s, 0 \u2264 w y)\n    (hw\u2081 : \u2211 y in hs.to_finset, w y = 1), hs.to_finset.center_mass w id = x} :=\nby simpa only [set.finite.coe_to_finset, set.finite.mem_to_finset, exists_prop]\n  using hs.to_finset.convex_hull_eq\n\n/-- A weak version of Carath\u00e9odory's theorem. -/\nlemma convex_hull_eq_union_convex_hull_finite_subsets (s : set E) :\n  convex_hull R s = \u22c3 (t : finset E) (w : \u2191t \u2286 s), convex_hull R \u2191t :=\nbegin\n  refine subset.antisymm _ _,\n  { rw convex_hull_eq,\n    rintros x \u27e8\u03b9, t, w, z, hw\u2080, hw\u2081, hz, rfl\u27e9,\n    simp only [mem_Union],\n    refine \u27e8t.image z, _, _\u27e9,\n    { rw [coe_image, set.image_subset_iff],\n      exact hz },\n    { apply t.center_mass_mem_convex_hull hw\u2080,\n      { simp only [hw\u2081, zero_lt_one] },\n      { exact \u03bb i hi, finset.mem_coe.2 (finset.mem_image_of_mem _ hi) } } },\n  { exact Union_subset (\u03bb i, Union_subset convex_hull_mono), },\nend\n\nlemma mk_mem_convex_hull_prod {t : set F} {x : E} {y : F} (hx : x \u2208 convex_hull R s)\n  (hy : y \u2208 convex_hull R t) :\n  (x, y) \u2208 convex_hull R (s \u00d7\u02e2 t) :=\nbegin\n  rw convex_hull_eq at \u22a2 hx hy,\n  obtain \u27e8\u03b9, a, w, S, hw, hw', hS, hSp\u27e9 := hx,\n  obtain \u27e8\u03ba, b, v, T, hv, hv', hT, hTp\u27e9 := hy,\n  have h_sum : \u2211 (i : \u03b9 \u00d7 \u03ba) in a.product b, w i.fst * v i.snd = 1,\n  { rw [finset.sum_product, \u2190 hw'],\n    congr,\n    ext i,\n    have : \u2211 (y : \u03ba) in b, w i * v y = \u2211 (y : \u03ba) in b, v y * w i,\n    { congr, ext, simp [mul_comm] },\n    rw [this, \u2190 finset.sum_mul, hv'],\n    simp },\n  refine \u27e8\u03b9 \u00d7 \u03ba, a.product b, \u03bb p, (w p.1) * (v p.2), \u03bb p, (S p.1, T p.2),\n    \u03bb p hp, _, h_sum, \u03bb p hp, _, _\u27e9,\n  { rw mem_product at hp,\n    exact mul_nonneg (hw p.1 hp.1) (hv p.2 hp.2) },\n  { rw mem_product at hp,\n    exact \u27e8hS p.1 hp.1, hT p.2 hp.2\u27e9 },\n  ext,\n  { rw [\u2190hSp, finset.center_mass_eq_of_sum_1 _ _ hw', finset.center_mass_eq_of_sum_1 _ _ h_sum],\n    simp_rw [prod.fst_sum, prod.smul_mk],\n    rw finset.sum_product,\n    congr,\n    ext i,\n    have : \u2211 (j : \u03ba) in b, (w i * v j) \u2022 S i = \u2211 (j : \u03ba) in b, v j \u2022 w i \u2022 S i,\n    { congr, ext, rw [mul_smul, smul_comm] },\n    rw [this, \u2190finset.sum_smul, hv', one_smul] },\n  { rw [\u2190hTp, finset.center_mass_eq_of_sum_1 _ _ hv', finset.center_mass_eq_of_sum_1 _ _ h_sum],\n    simp_rw [prod.snd_sum, prod.smul_mk],\n    rw [finset.sum_product, finset.sum_comm],\n    congr,\n    ext j,\n    simp_rw mul_smul,\n    rw [\u2190finset.sum_smul, hw', one_smul] }\nend\n\n@[simp] lemma convex_hull_prod (s : set E) (t : set F) :\n  convex_hull R (s \u00d7\u02e2 t) = convex_hull R s \u00d7\u02e2 convex_hull R t :=\nsubset.antisymm (convex_hull_min (prod_mono (subset_convex_hull _ _) $ subset_convex_hull _ _) $\n  (convex_convex_hull _ _).prod $ convex_convex_hull _ _) $\n    prod_subset_iff.2 $ \u03bb x hx y, mk_mem_convex_hull_prod hx\n\nlemma convex_hull_add (s t : set E) : convex_hull R (s + t) = convex_hull R s + convex_hull R t :=\nby simp_rw [\u2190image2_add, \u2190image_prod, is_linear_map.is_linear_map_add.convex_hull_image,\n  convex_hull_prod]\n\nlemma convex_hull_sub (s t : set E) : convex_hull R (s - t) = convex_hull R s - convex_hull R t :=\nby simp_rw [sub_eq_add_neg, convex_hull_add, convex_hull_neg]\n\n/-! ### `std_simplex` -/\n\nvariables (\u03b9) [fintype \u03b9] {f : \u03b9 \u2192 R}\n\n/-- `std_simplex \ud835\udd5c \u03b9` is the convex hull of the canonical basis in `\u03b9 \u2192 \ud835\udd5c`. -/\nlemma convex_hull_basis_eq_std_simplex :\n  convex_hull R (range $ \u03bb(i j:\u03b9), if i = j then (1:R) else 0) = std_simplex R \u03b9 :=\nbegin\n  refine subset.antisymm (convex_hull_min _ (convex_std_simplex R \u03b9)) _,\n  { rintros _ \u27e8i, rfl\u27e9,\n    exact ite_eq_mem_std_simplex R i },\n  { rintros w \u27e8hw\u2080, hw\u2081\u27e9,\n    rw [pi_eq_sum_univ w, \u2190 finset.univ.center_mass_eq_of_sum_1 _ hw\u2081],\n    exact finset.univ.center_mass_mem_convex_hull (\u03bb i hi, hw\u2080 i)\n      (hw\u2081.symm \u25b8 zero_lt_one) (\u03bb i hi, mem_range_self i) }\nend\n\nvariable {\u03b9}\n\n/-- The convex hull of a finite set is the image of the standard simplex in `s \u2192 \u211d`\nunder the linear map sending each function `w` to `\u2211 x in s, w x \u2022 x`.\n\nSince we have no sums over finite sets, we use sum over `@finset.univ _ hs.fintype`.\nThe map is defined in terms of operations on `(s \u2192 \u211d) \u2192\u2097[\u211d] \u211d` so that later we will not need\nto prove that this map is linear. -/\nlemma set.finite.convex_hull_eq_image {s : set E} (hs : s.finite) :\n  convex_hull R s = by haveI := hs.fintype; exact\n    (\u21d1(\u2211 x : s, (@linear_map.proj R s _ (\u03bb i, R) _ _ x).smul_right x.1)) '' (std_simplex R s) :=\nbegin\n  rw [\u2190 convex_hull_basis_eq_std_simplex, \u2190 linear_map.convex_hull_image, \u2190 set.range_comp, (\u2218)],\n  apply congr_arg,\n  convert subtype.range_coe.symm,\n  ext x,\n  simp [linear_map.sum_apply, ite_smul, finset.filter_eq]\nend\n\n/-- All values of a function `f \u2208 std_simplex \ud835\udd5c \u03b9` belong to `[0, 1]`. -/\nlemma mem_Icc_of_mem_std_simplex (hf : f \u2208 std_simplex R \u03b9) (x) :\n  f x \u2208 Icc (0 : R) 1 :=\n\u27e8hf.1 x, hf.2 \u25b8 finset.single_le_sum (\u03bb y hy, hf.1 y) (finset.mem_univ x)\u27e9\n\n/-- The convex hull of an affine basis is the intersection of the half-spaces defined by the\ncorresponding barycentric coordinates. -/\nlemma convex_hull_affine_basis_eq_nonneg_barycentric {\u03b9 : Type*} (b : affine_basis \u03b9 R E) :\n  convex_hull R (range b.points) = { x | \u2200 i, 0 \u2264 b.coord i x } :=\nbegin\n  rw convex_hull_range_eq_exists_affine_combination,\n  ext x,\n  split,\n  { rintros \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9 i,\n    by_cases hi : i \u2208 s,\n    { rw b.coord_apply_combination_of_mem hi hw\u2081,\n      exact hw\u2080 i hi, },\n    { rw b.coord_apply_combination_of_not_mem hi hw\u2081, }, },\n  { intros hx,\n    have hx' : x \u2208 affine_span R (range b.points),\n    { rw b.tot, exact affine_subspace.mem_top R E x, },\n    obtain \u27e8s, w, hw\u2081, rfl\u27e9 := (mem_affine_span_iff_eq_affine_combination R E).mp hx',\n    refine \u27e8s, w, _, hw\u2081, rfl\u27e9,\n    intros i hi,\n    specialize hx i,\n    rw b.coord_apply_combination_of_mem hi hw\u2081 at hx,\n    exact hx, },\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/convex/combination.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7494725127508136}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport algebra.smul_with_zero\nimport algebra.regular.basic\n\n/-!\n# Action of regular elements on a module\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe introduce `M`-regular elements, in the context of an `R`-module `M`.  The corresponding\npredicate is called `is_smul_regular`.\n\nThere are very limited typeclass assumptions on `R` and `M`, but the \"mathematical\" case of interest\nis a commutative ring `R` acting an a module `M`. Since the properties are \"multiplicative\", there\nis no actual requirement of having an addition, but there is a zero in both `R` and `M`.\nSmultiplications involving `0` are, of course, all trivial.\n\nThe defining property is that an element `a \u2208 R` is `M`-regular if the smultiplication map\n`M \u2192 M`, defined by `m \u21a6 a \u2022 m`, is injective.\n\nThis property is the direct generalization to modules of the property `is_left_regular` defined in\n`algebra/regular`.  Lemma `is_smul_regular.is_left_regular_iff` shows that indeed the two notions\ncoincide.\n-/\n\nvariables {R S : Type*} (M : Type*) {a b : R} {s : S}\n\n/-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an\ninjective map `M \u2192 M`. -/\ndef is_smul_regular [has_smul R M] (c : R) := function.injective ((\u2022) c : M \u2192 M)\n\nlemma is_left_regular.is_smul_regular [has_mul R] {c : R} (h : is_left_regular c) :\n  is_smul_regular R c := h\n\n/-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/\nlemma is_left_regular_iff [has_mul R] {a : R} :\n  is_left_regular a \u2194 is_smul_regular R a := iff.rfl\n\nlemma is_right_regular.is_smul_regular [has_mul R] {c : R} (h : is_right_regular c) :\n  is_smul_regular R (mul_opposite.op c) := h\n\n/-- Right-regular multiplication on `R` is equivalent to `R\u1d50\u1d52\u1d56`-regularity of `R` itself. -/\nlemma is_right_regular_iff [has_mul R] {a : R} :\n  is_right_regular a \u2194 is_smul_regular R (mul_opposite.op a) := iff.rfl\n\nnamespace is_smul_regular\n\nvariables {M}\n\nsection has_smul\n\nvariables [has_smul R M] [has_smul R S] [has_smul S M] [is_scalar_tower R S M]\n\n/-- The product of `M`-regular elements is `M`-regular. -/\nlemma smul (ra : is_smul_regular M a) (rs : is_smul_regular M s) :\n  is_smul_regular M (a \u2022 s) :=\n\u03bb a b ab, rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _))))\n\n/-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular\nelement, then `b` is `M`-regular. -/\nlemma of_smul (a : R) (ab : is_smul_regular M (a \u2022 s)) :\n  is_smul_regular M s :=\n@function.injective.of_comp _ _ _ (\u03bb m : M, a \u2022 m) _ (\u03bb c d cd, ab\n  (by rwa [smul_assoc, smul_assoc]))\n\n/-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element\nis `M`-regular. -/\n@[simp] lemma smul_iff (b : S) (ha : is_smul_regular M a) :\n  is_smul_regular M (a \u2022 b) \u2194 is_smul_regular M b :=\n\u27e8of_smul _, ha.smul\u27e9\n\nlemma is_left_regular [has_mul R] {a : R} (h : is_smul_regular R a) :\n  is_left_regular a := h\n\nlemma is_right_regular [has_mul R] {a : R} (h : is_smul_regular R (mul_opposite.op a)) :\n  is_right_regular a := h\n\nlemma mul [has_mul R] [is_scalar_tower R R M]\n  (ra : is_smul_regular M a) (rb : is_smul_regular M b) : is_smul_regular M (a * b) :=\nra.smul rb\n\nlemma of_mul [has_mul R] [is_scalar_tower R R M] (ab : is_smul_regular M (a * b)) :\n  is_smul_regular M b :=\nby { rw \u2190 smul_eq_mul at ab, exact ab.of_smul _ }\n\n@[simp] lemma mul_iff_right [has_mul R] [is_scalar_tower R R M] (ha : is_smul_regular M a) :\n  is_smul_regular M (a * b) \u2194 is_smul_regular M b :=\n\u27e8of_mul, ha.mul\u27e9\n\n/-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a`\nare `M`-regular. -/\nlemma mul_and_mul_iff [has_mul R] [is_scalar_tower R R M] :\n  is_smul_regular M (a * b) \u2227 is_smul_regular M (b * a) \u2194\n  is_smul_regular M a \u2227 is_smul_regular M b :=\nbegin\n  refine \u27e8_, _\u27e9,\n  { rintros \u27e8ab, ba\u27e9,\n    refine \u27e8ba.of_mul, ab.of_mul\u27e9 },\n  { rintros \u27e8ha, hb\u27e9,\n    exact \u27e8ha.mul hb, hb.mul ha\u27e9 }\nend\n\nend has_smul\n\nsection monoid\n\nvariables [monoid R] [mul_action R M]\n\nvariable (M)\n\n/-- One is `M`-regular always. -/\n@[simp] lemma one : is_smul_regular M (1 : R) :=\n\u03bb a b ab, by rwa [one_smul, one_smul] at ab\n\nvariable {M}\n\n/-- An element of `R` admitting a left inverse is `M`-regular. -/\nlemma of_mul_eq_one (h : a * b = 1) : is_smul_regular M b :=\nof_mul (by { rw h, exact one M })\n\n/-- Any power of an `M`-regular element is `M`-regular. -/\nlemma pow (n : \u2115) (ra : is_smul_regular M a) : is_smul_regular M (a ^ n) :=\nbegin\n  induction n with n hn,\n  { simp only [one, pow_zero] },\n  { rw pow_succ, exact (ra.smul_iff (a ^ n)).mpr hn }\nend\n\n/-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/\nlemma pow_iff {n : \u2115} (n0 : 0 < n) :\n  is_smul_regular M (a ^ n) \u2194 is_smul_regular M a :=\nbegin\n  refine \u27e8_, pow n\u27e9,\n  rw [\u2190 nat.succ_pred_eq_of_pos n0, pow_succ', \u2190 smul_eq_mul],\n  exact of_smul _,\nend\n\nend monoid\n\nsection monoid_smul\n\nvariables [monoid S] [has_smul R M] [has_smul R S] [mul_action S M] [is_scalar_tower R S M]\n\n/-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/\nlemma of_smul_eq_one (h : a \u2022 s = 1) : is_smul_regular M s :=\nof_smul a (by { rw h, exact one M })\n\nend monoid_smul\n\nsection monoid_with_zero\n\nvariables [monoid_with_zero R] [monoid_with_zero S] [has_zero M]\n          [mul_action_with_zero R M] [mul_action_with_zero R S] [mul_action_with_zero S M]\n          [is_scalar_tower R S M]\n\n/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\nprotected lemma subsingleton (h : is_smul_regular M (0 : R)) : subsingleton M :=\n\u27e8\u03bb a b, h (by repeat { rw mul_action_with_zero.zero_smul })\u27e9\n\n/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\nlemma zero_iff_subsingleton : is_smul_regular M (0 : R) \u2194 subsingleton M :=\n\u27e8\u03bb h, h.subsingleton, \u03bb H a b h, @subsingleton.elim _ H a b\u27e9\n\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\nlemma not_zero_iff : \u00ac is_smul_regular M (0 : R) \u2194 nontrivial M :=\nbegin\n  rw [nontrivial_iff, not_iff_comm, zero_iff_subsingleton, subsingleton_iff],\n  push_neg,\n  exact iff.rfl\nend\n\n/-- The element `0` is `M`-regular when `M` is trivial. -/\nlemma zero [sM : subsingleton M] : is_smul_regular M (0 : R) :=\nzero_iff_subsingleton.mpr sM\n\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\n\n\nend monoid_with_zero\n\nsection comm_semigroup\n\nvariables [comm_semigroup R] [has_smul R M] [is_scalar_tower R R M]\n\n/-- A product is `M`-regular if and only if the factors are. -/\nlemma mul_iff : is_smul_regular M (a * b) \u2194\n  is_smul_regular M a \u2227 is_smul_regular M b :=\nbegin\n  rw \u2190 mul_and_mul_iff,\n  exact \u27e8\u03bb ab, \u27e8ab, by rwa mul_comm\u27e9, \u03bb rab, rab.1\u27e9\nend\n\nend comm_semigroup\n\nend is_smul_regular\n\nsection group\n\nvariables {G : Type*} [group G]\n\n/-- An element of a group acting on a Type is regular. This relies on the availability\nof the inverse given by groups, since there is no `left_cancel_smul` typeclass. -/\nlemma is_smul_regular_of_group [mul_action G R] (g : G) : is_smul_regular R g :=\nbegin\n  intros x y h,\n  convert congr_arg ((\u2022) g\u207b\u00b9) h using 1;\n  simp [\u2190smul_assoc]\nend\n\nend group\n\nsection units\n\nvariables [monoid R] [mul_action R M]\n\n/-- Any element in `R\u02e3` is `M`-regular. -/\nlemma units.is_smul_regular (a : R\u02e3) : is_smul_regular M (a : R) :=\nis_smul_regular.of_mul_eq_one a.inv_val\n\n/-- A unit is `M`-regular. -/\nlemma is_unit.is_smul_regular (ua : is_unit a) : is_smul_regular M a :=\nbegin\n  rcases ua with \u27e8a, rfl\u27e9,\n  exact a.is_smul_regular M\nend\n\nend units\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/regular/smul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7494725075648323}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport ring_theory.polynomial.bernstein\nimport topology.continuous_function.compact\nimport topology.continuous_function.polynomial\nimport topology.unit_interval\nimport algebra.floor\nimport analysis.specific_limits\n\n/-!\n# Bernstein approximations and Weierstrass' theorem\n\nWe prove that the Bernstein approximations\n```\n\u2211 k : fin (n+1), f (k/n : \u211d) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], \u211d)` converge uniformly to `f` as `n` tends to infinity.\n\nOur proof follows [Richard Beals' *Analysis, an introduction*][beals-analysis], \u00a77D.\nThe original proof, due to [Bernstein](bernstein1912) in 1912, is probabilistic,\nand relies on Bernoulli's theorem,\nwhich gives bounds for how quickly the observed frequencies in a\nBernoulli trial approach the underlying probability.\n\nThe proof here does not directly rely on Bernoulli's theorem,\nbut can also be given a probabilistic account.\n* Consider a weighted coin which with probability `x` produces heads,\n  and with probability `1-x` produces tails.\n* The value of `bernstein n k x` is the probability that\n  such a coin gives exactly `k` heads in a sequence of `n` tosses.\n* If such an appearance of `k` heads results in a payoff of `f(k / n)`,\n  the `n`-th Bernstein approximation for `f` evaluated at `x` is the expected payoff.\n* The main estimate in the proof bounds the probability that\n  the observed frequency of heads differs from `x` by more than some `\u03b4`,\n  obtaining a bound of `(4 * n * \u03b4^2)\u207b\u00b9`, irrespective of `x`.\n* This ensures that for `n` large, the Bernstein approximation is (uniformly) close to the\n  payoff function `f`.\n\n(You don't need to think in these terms to follow the proof below: it's a giant `calc` block!)\n\nThis result proves Weierstrass' theorem that polynomials are dense in `C([0,1], \u211d)`,\nalthough we defer an abstract statement of this until later.\n-/\n\nnoncomputable theory\n\nopen_locale classical\nopen_locale big_operators\nopen_locale bounded_continuous_function\nopen_locale unit_interval\n\n/--\nThe Bernstein polynomials, as continuous functions on `[0,1]`.\n-/\ndef bernstein (n \u03bd : \u2115) : C(I, \u211d) :=\n(bernstein_polynomial \u211d n \u03bd).to_continuous_map_on I\n\n@[simp] lemma bernstein_apply (n \u03bd : \u2115) (x : I) :\n  bernstein n \u03bd x = n.choose \u03bd * x^\u03bd * (1-x)^(n-\u03bd) :=\nbegin\n  dsimp [bernstein, polynomial.to_continuous_map_on, polynomial.to_continuous_map,\n    bernstein_polynomial],\n  simp,\nend\n\nlemma bernstein_nonneg {n \u03bd : \u2115} {x : I} :\n  0 \u2264 bernstein n \u03bd x :=\nbegin\n  simp only [bernstein_apply],\n  exact mul_nonneg\n    (mul_nonneg (nat.cast_nonneg _) (pow_nonneg (by unit_interval) _))\n    (pow_nonneg (by unit_interval) _),\nend\n\n/-!\nWe now give a slight reformulation of `bernstein_polynomial.variance`.\n-/\n\nnamespace bernstein\n\n/--\nSend `k : fin (n+1)` to the equally spaced points `k/n` in the unit interval.\n-/\ndef z {n : \u2115} (k : fin (n+1)) : I :=\n\u27e8(k : \u211d) / n,\n  begin\n    cases n,\n    { norm_num },\n    { have h\u2081 : 0 < (n.succ : \u211d) := by exact_mod_cast (nat.succ_pos _),\n      have h\u2082 : \u2191k \u2264 n.succ := by exact_mod_cast (fin.le_last k),\n      rw [set.mem_Icc, le_div_iff h\u2081, div_le_iff h\u2081],\n      norm_cast,\n      simp [h\u2082], },\n  end\u27e9\n\nlocal postfix `/\u2099`:90 := z\n\nlemma probability (n : \u2115) (x : I) :\n  \u2211 k : fin (n+1), bernstein n k x = 1 :=\nbegin\n  have := bernstein_polynomial.sum \u211d n,\n  apply_fun (\u03bb p, polynomial.aeval (x : \u211d) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range] at this,\n  exact this,\nend\n\nlemma variance {n : \u2115} (h : 0 < (n : \u211d)) (x : I) :\n  \u2211 k : fin (n+1), (x - k/\u2099 : \u211d)^2 * bernstein n k x = x * (1-x) / n :=\nbegin\n  have h' : (n : \u211d) \u2260 0 := ne_of_gt h,\n  apply_fun (\u03bb x : \u211d, x * n) using group_with_zero.mul_right_injective h',\n  apply_fun (\u03bb x : \u211d, x * n) using group_with_zero.mul_right_injective h',\n  dsimp,\n  conv_lhs { simp only [finset.sum_mul, z], },\n  conv_rhs { rw div_mul_cancel _ h', },\n  have := bernstein_polynomial.variance \u211d n,\n  apply_fun (\u03bb p, polynomial.aeval (x : \u211d) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range, \u2190polynomial.nat_cast_mul] at this,\n  convert this using 1,\n  { congr' 1, funext k,\n    rw [mul_comm _ (n : \u211d), mul_comm _ (n : \u211d), \u2190mul_assoc, \u2190mul_assoc],\n    congr' 1,\n    field_simp [h],\n    ring, },\n  { ring, },\nend\n\nend bernstein\n\nopen bernstein\n\nlocal postfix `/\u2099`:2000 := z\nlocal notation `|`x`|` := abs x\n\n/--\nThe `n`-th approximation of a continuous function on `[0,1]` by Bernstein polynomials,\ngiven by `\u2211 k, f (k/n) * bernstein n k x`.\n-/\ndef bernstein_approximation (n : \u2115) (f : C(I, \u211d)) : C(I, \u211d) :=\n\u2211 k : fin (n+1), f k/\u2099 \u2022 bernstein n k\n\n/-!\nWe now set up some of the basic machinery of the proof that the Bernstein approximations\nconverge uniformly.\n\nA key player is the set `S f \u03b5 h n x`,\nfor some function `f : C(I, \u211d)`, `h : 0 < \u03b5`, `n : \u2115` and `x : I`.\n\nThis is the set of points `k` in `fin (n+1)` such that\n`k/n` is within `\u03b4` of `x`, where `\u03b4` is the modulus of uniform continuity for `f`,\nchosen so `|f x - f y| < \u03b5/2` when `|x - y| < \u03b4`.\n\nWe show that if `k \u2209 S`, then `1 \u2264 \u03b4^-2 * (x - k/n)^2`.\n-/\n\nnamespace bernstein_approximation\n\n@[simp] lemma apply (n : \u2115) (f : C(I, \u211d)) (x : I) :\n  bernstein_approximation n f x = \u2211 k : fin (n+1), f k/\u2099 * bernstein n k x :=\nby simp [bernstein_approximation]\n\n/--\nThe modulus of (uniform) continuity for `f`, chosen so `|f x - f y| < \u03b5/2` when `|x - y| < \u03b4`.\n-/\ndef \u03b4 (f : C(I, \u211d)) (\u03b5 : \u211d) (h : 0 < \u03b5) : \u211d := f.modulus (\u03b5/2) (half_pos h)\n\n/--\nThe set of points `k` so `k/n` is within `\u03b4` of `x`.\n-/\ndef S (f : C(I, \u211d)) (\u03b5 : \u211d) (h : 0 < \u03b5) (n : \u2115) (x : I) : finset (fin (n+1)) :=\n{ k : fin (n+1) | dist k/\u2099 x < \u03b4 f \u03b5 h }.to_finset\n\n/--\nIf `k \u2208 S`, then `f(k/n)` is close to `f x`.\n-/\nlemma lt_of_mem_S\n  {f : C(I, \u211d)} {\u03b5 : \u211d} {h : 0 < \u03b5} {n : \u2115} {x : I} {k : fin (n+1)} (m : k \u2208 S f \u03b5 h n x) :\n  |f k/\u2099 - f x| < \u03b5/2 :=\nbegin\n  apply f.dist_lt_of_dist_lt_modulus (\u03b5/2) (half_pos h),\n  simpa [S] using m,\nend\n\n/--\nIf `k \u2209 S`, then as `\u03b4 \u2264 |x - k/n|`, we have the inequality `1 \u2264 \u03b4^-2 * (x - k/n)^2`.\nThis particular formulation will be helpful later.\n-/\nlemma le_of_mem_S_compl\n  {f : C(I, \u211d)} {\u03b5 : \u211d} {h : 0 < \u03b5} {n : \u2115} {x : I} {k : fin (n+1)} (m : k \u2208 (S f \u03b5 h n x)\u1d9c) :\n  (1 : \u211d) \u2264 (\u03b4 f \u03b5 h)^(-2 : \u2124) * (x - k/\u2099) ^ 2 :=\nbegin\n  simp only [finset.mem_compl, not_lt, set.mem_to_finset, set.mem_set_of_eq, S] at m,\n  field_simp,\n  erw [le_div_iff (pow_pos f.modulus_pos 2), one_mul],\n  apply sq_le_sq,\n  rw abs_eq_self.mpr (le_of_lt f.modulus_pos),\n  rw [dist_comm] at m,\n  exact m,\nend\n\nend bernstein_approximation\n\nopen bernstein_approximation\nopen bounded_continuous_function\nopen filter\n\nopen_locale topological_space\n\n/--\nThe Bernstein approximations\n```\n\u2211 k : fin (n+1), f (k/n : \u211d) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], \u211d)` converge uniformly to `f` as `n` tends to infinity.\n\nThis is the proof given in [Richard Beals' *Analysis, an introduction*][beals-analysis], \u00a77D,\nand reproduced on wikipedia.\n-/\ntheorem bernstein_approximation_uniform (f : C(I, \u211d)) :\n  tendsto (\u03bb n : \u2115, bernstein_approximation n f) at_top (\ud835\udcdd f) :=\nbegin\n  simp only [metric.nhds_basis_ball.tendsto_right_iff, metric.mem_ball, dist_eq_norm],\n  intros \u03b5 h,\n  let \u03b4 := \u03b4 f \u03b5 h,\n  have nhds_zero := tendsto_const_div_at_top_nhds_0_nat (2 * \u2225f\u2225 * \u03b4 ^ (-2 : \u2124)),\n  filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_at_top 0],\n  intros n nh npos',\n  have npos : 0 < (n:\u211d) := by exact_mod_cast npos',\n  -- Two easy inequalities we'll need later:\n  have w\u2081 : 0 \u2264 2 * \u2225f\u2225 := mul_nonneg (by norm_num) (norm_nonneg f),\n  have w\u2082 : 0 \u2264 2 * \u2225f\u2225 * \u03b4^(-2 : \u2124) := mul_nonneg w\u2081 pow_minus_two_nonneg,\n  -- As `[0,1]` is compact, it suffices to check the inequality pointwise.\n  rw (continuous_map.norm_lt_iff _ h),\n  intro x,\n  -- The idea is to split up the sum over `k` into two sets,\n  -- `S`, where `x - k/n < \u03b4`, and its complement.\n  let S := S f \u03b5 h n x,\n  calc\n    |(bernstein_approximation n f - f) x|\n        = |bernstein_approximation n f x - f x|\n                              : rfl\n    ... = |bernstein_approximation n f x - f x * 1|\n                              : by rw mul_one\n    ... = |bernstein_approximation n f x - f x * (\u2211 k : fin (n+1), bernstein n k x)|\n                              : by rw bernstein.probability\n    ... = |\u2211 k : fin (n+1), (f k/\u2099 - f x) * bernstein n k x|\n                              : by simp [bernstein_approximation, finset.mul_sum, sub_mul]\n    ... \u2264 \u2211 k : fin (n+1), |(f k/\u2099 - f x) * bernstein n k x|\n                              : finset.abs_sum_le_sum_abs _ _\n    ... = \u2211 k : fin (n+1), |f k/\u2099 - f x| * bernstein n k x\n                              : by simp_rw [abs_mul, abs_eq_self.mpr bernstein_nonneg]\n    ... = \u2211 k in S, |f k/\u2099 - f x| * bernstein n k x +\n          \u2211 k in S\u1d9c, |f k/\u2099 - f x| * bernstein n k x\n                              : (S.sum_add_sum_compl _).symm\n    -- We'll now deal with the terms in `S` and the terms in `S\u1d9c` in separate calc blocks.\n    ... < \u03b5/2 + \u03b5/2 : add_lt_add_of_le_of_lt _ _\n    ... = \u03b5 : add_halves \u03b5,\n    { -- We now work on the terms in `S`: uniform continuity and `bernstein.probability`\n      -- quickly give us a bound.\n      calc \u2211 k in S, |f k/\u2099 - f x| * bernstein n k x\n          \u2264 \u2211 k in S, \u03b5/2 * bernstein n k x\n                                :  finset.sum_le_sum\n                                    (\u03bb k m, (mul_le_mul_of_nonneg_right (le_of_lt (lt_of_mem_S m))\n                                      bernstein_nonneg))\n      ... = \u03b5/2 * \u2211 k in S, bernstein n k x\n                                : by rw finset.mul_sum\n      -- In this step we increase the sum over `S` back to a sum over all of `fin (n+1)`,\n      -- so that we can use `bernstein.probability`.\n      ... \u2264 \u03b5/2 * \u2211 k : fin (n+1), bernstein n k x\n                                : mul_le_mul_of_nonneg_left\n                                    (finset.sum_le_univ_sum_of_nonneg (\u03bb k, bernstein_nonneg))\n                                    (le_of_lt (half_pos h))\n      ... = \u03b5/2 : by rw [bernstein.probability, mul_one] },\n      { -- We now turn to working on `S\u1d9c`: we control the difference term just using `\u2225f\u2225`,\n        -- and then insert a `\u03b4^(-2) * (x - k/n)^2` factor\n        -- (which is at least one because we are not in `S`).\n        calc \u2211 k in S\u1d9c, |f k/\u2099 - f x| * bernstein n k x\n            \u2264 \u2211 k in S\u1d9c, (2 * \u2225f\u2225) * bernstein n k x\n                                  : finset.sum_le_sum\n                                      (\u03bb k m, mul_le_mul_of_nonneg_right (f.dist_le_two_norm _ _)\n                                        bernstein_nonneg)\n        ... = (2 * \u2225f\u2225) * \u2211 k in S\u1d9c, bernstein n k x\n                                  : by rw finset.mul_sum\n        ... \u2264 (2 * \u2225f\u2225) * \u2211 k in S\u1d9c, \u03b4^(-2 : \u2124) * (x - k/\u2099)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_sum (\u03bb k m, begin\n                                        conv_lhs { rw \u2190one_mul (bernstein _ _ _), },\n                                        exact mul_le_mul_of_nonneg_right\n                                          (le_of_mem_S_compl m) bernstein_nonneg,\n                                      end)) w\u2081\n        -- Again enlarging the sum from `S\u1d9c` to all of `fin (n+1)`\n        ... \u2264 (2 * \u2225f\u2225) * \u2211 k : fin (n+1), \u03b4^(-2 : \u2124) * (x - k/\u2099)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_univ_sum_of_nonneg\n                                        (\u03bb k, mul_nonneg\n                                          (mul_nonneg pow_minus_two_nonneg (sq_nonneg _))\n                                          bernstein_nonneg)) w\u2081\n        ... = (2 * \u2225f\u2225) * \u03b4^(-2 : \u2124) * \u2211 k : fin (n+1), (x - k/\u2099)^2 * bernstein n k x\n                                  : by conv_rhs {\n                                      rw [mul_assoc, finset.mul_sum], simp only [\u2190mul_assoc], }\n        -- `bernstein.variance` and `x \u2208 [0,1]` gives the uniform bound\n        ... = (2 * \u2225f\u2225) * \u03b4^(-2 : \u2124) * x * (1-x) / n\n                                  : by { rw variance npos, ring, }\n        ... \u2264 (2 * \u2225f\u2225) * \u03b4^(-2 : \u2124) / n\n                                  : (div_le_div_right npos).mpr\n                                    begin\n                                      apply mul_nonneg_le_one_le w\u2082,\n                                      apply mul_nonneg_le_one_le w\u2082 (le_refl _),\n                                      all_goals { unit_interval, },\n                                    end\n        ... < \u03b5/2 : nh, }\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/special_functions/bernstein.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004187, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7494725047157446}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\n\nimport topology.algebra.nonarchimedean.bases\nimport topology.algebra.uniform_filter_basis\nimport ring_theory.valuation.basic\n\n/-!\n# The topology on a valued ring\n\nIn this file, we define the non archimedean topology induced by a valuation on a ring.\nThe main definition is a `valued` type class which equips a ring with a valuation taking\nvalues in a group with zero. Other instances are then deduced from this.\n-/\n\nopen_locale classical topological_space uniformity\nopen set valuation\nnoncomputable theory\n\nuniverses v u\n\nvariables {R : Type u} [ring R] {\u0393\u2080 : Type v} [linear_ordered_comm_group_with_zero \u0393\u2080]\n\nnamespace valuation\n\nvariables (v : valuation R \u0393\u2080)\n\n/-- The basis of open subgroups for the topology on a ring determined by a valuation. -/\nlemma subgroups_basis :\n  ring_subgroups_basis (\u03bb \u03b3 : \u0393\u2080\u02e3, (v.lt_add_subgroup \u03b3 : add_subgroup R)) :=\n{ inter := begin\n    rintros \u03b3\u2080 \u03b3\u2081,\n    use min \u03b3\u2080 \u03b3\u2081,\n    simp [valuation.lt_add_subgroup] ; tauto\n  end,\n  mul := begin\n    rintros \u03b3,\n    cases exists_square_le \u03b3 with \u03b3\u2080 h,\n    use \u03b3\u2080,\n    rintro - \u27e8r, s, r_in, s_in, rfl\u27e9,\n    calc (v (r*s) : \u0393\u2080) = v r * v s : valuation.map_mul _ _ _\n             ... < \u03b3\u2080*\u03b3\u2080 : mul_lt_mul\u2080 r_in s_in\n             ... \u2264 \u03b3 : by exact_mod_cast h\n  end,\n  left_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use (1 : \u0393\u2080\u02e3),\n      rintros y (y_in : (v y : \u0393\u2080) < 1),\n      change v (x * y) < _,\n      rw [valuation.map_mul, Hx, zero_mul],\n      exact units.zero_lt \u03b3 },\n    { simp only [image_subset_iff, set_of_subset_set_of, preimage_set_of_eq, valuation.map_mul],\n      use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change (v (x * y) : \u0393\u2080) < \u03b3,\n      rw [valuation.map_mul, Hx, mul_comm],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end,\n  right_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use 1,\n      rintros y (y_in : (v y : \u0393\u2080) < 1),\n      change v (y * x) < _,\n      rw [valuation.map_mul, Hx, mul_zero],\n      exact units.zero_lt \u03b3 },\n    { use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change (v (y * x) : \u0393\u2080) < \u03b3,\n      rw [valuation.map_mul, Hx],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end }\n\nend valuation\n\n/-- A valued ring is a ring that comes equipped with a distinguished valuation. The class `valued`\nis designed for the situation that there is a canonical valuation on the ring.\n\nTODO: show that there always exists an equivalent valuation taking values in a type belonging to\nthe same universe as the ring.\n\nSee Note [forgetful inheritance] for why we extend `uniform_space`, `uniform_add_group`. -/\nclass valued (R : Type u) [ring R] (\u0393\u2080 : out_param (Type v))\n  [linear_ordered_comm_group_with_zero \u0393\u2080] extends uniform_space R, uniform_add_group R :=\n(v : valuation R \u0393\u2080)\n(is_topological_valuation : \u2200 s, s \u2208 \ud835\udcdd (0 : R) \u2194 \u2203 (\u03b3 : \u0393\u2080\u02e3), { x : R | v x < \u03b3 } \u2286 s)\n\n/-- The `dangerous_instance` linter does not check whether the metavariables only occur in\narguments marked with `out_param`, so in this instance it gives a false positive. -/\nattribute [nolint dangerous_instance] valued.to_uniform_space\n\nnamespace valued\n\n/-- Alternative `valued` constructor for use when there is no preferred `uniform_space`\nstructure. -/\ndef mk' (v : valuation R \u0393\u2080) : valued R \u0393\u2080 :=\n{ v := v,\n  to_uniform_space := @topological_add_group.to_uniform_space R _ v.subgroups_basis.topology _,\n  to_uniform_add_group := @topological_add_group_is_uniform _ _ v.subgroups_basis.topology _,\n  is_topological_valuation :=\n  begin\n    letI := @topological_add_group.to_uniform_space R _ v.subgroups_basis.topology _,\n    intros s,\n    rw filter.has_basis_iff.mp v.subgroups_basis.has_basis_nhds_zero s,\n    exact exists_congr (\u03bb \u03b3, by simpa),\n  end }\n\nvariables (R \u0393\u2080) [_i : valued R \u0393\u2080]\ninclude _i\n\nlemma has_basis_nhds_zero :\n  (\ud835\udcdd (0 : R)).has_basis (\u03bb _, true) (\u03bb (\u03b3 : \u0393\u2080\u02e3), { x | v x < (\u03b3 : \u0393\u2080) }) :=\nby simp [filter.has_basis_iff, is_topological_valuation]\n\nlemma has_basis_uniformity :\n  (\ud835\udce4 R).has_basis (\u03bb _, true) (\u03bb (\u03b3 : \u0393\u2080\u02e3), { p : R \u00d7 R | v (p.2 - p.1) < (\u03b3 : \u0393\u2080) }) :=\nbegin\n  rw uniformity_eq_comap_nhds_zero,\n  exact (has_basis_nhds_zero R \u0393\u2080).comap _,\nend\n\nlemma to_uniform_space_eq :\n  to_uniform_space = @topological_add_group.to_uniform_space R _ v.subgroups_basis.topology _ :=\nuniform_space_eq\n  ((has_basis_uniformity R \u0393\u2080).eq_of_same_basis $ v.subgroups_basis.has_basis_nhds_zero.comap _)\n\nvariables {R \u0393\u2080}\n\nlemma mem_nhds {s : set R} {x : R} :\n  (s \u2208 \ud835\udcdd x) \u2194 \u2203 (\u03b3 : \u0393\u2080\u02e3), {y | (v (y - x) : \u0393\u2080) < \u03b3 } \u2286 s :=\nby simp only [\u2190 nhds_translation_add_neg x, \u2190 sub_eq_add_neg, preimage_set_of_eq, exists_true_left,\n  ((has_basis_nhds_zero R \u0393\u2080).comap (\u03bb y, y - x)).mem_iff]\n\nlemma mem_nhds_zero {s : set R} :\n  (s \u2208 \ud835\udcdd (0 : R)) \u2194 \u2203 \u03b3 : \u0393\u2080\u02e3, {x | v x < (\u03b3 : \u0393\u2080) } \u2286 s :=\nby simp only [mem_nhds, sub_zero]\n\nlemma loc_const {x : R} (h : (v x : \u0393\u2080) \u2260 0) : {y : R | v y = v x} \u2208 \ud835\udcdd x :=\nbegin\n  rw mem_nhds,\n  rcases units.exists_iff_ne_zero.mpr h with \u27e8\u03b3, hx\u27e9,\n  use \u03b3,\n  rw hx,\n  intros y y_in,\n  exact valuation.map_eq_of_sub_lt _ y_in\nend\n\n@[priority 100]\ninstance : topological_ring R :=\n(to_uniform_space_eq R \u0393\u2080).symm \u25b8 v.subgroups_basis.to_ring_filter_basis.is_topological_ring\n\nlemma cauchy_iff {F : filter R} :\n  cauchy F \u2194 F.ne_bot \u2227 \u2200 \u03b3 : \u0393\u2080\u02e3, \u2203 M \u2208 F, \u2200 x y \u2208 M, (v (y - x) : \u0393\u2080) < \u03b3 :=\nbegin\n  rw [to_uniform_space_eq, add_group_filter_basis.cauchy_iff],\n  apply and_congr iff.rfl,\n  simp_rw valued.v.subgroups_basis.mem_add_group_filter_basis_iff,\n  split,\n  { intros h \u03b3,\n    exact h _ (valued.v.subgroups_basis.mem_add_group_filter_basis _) },\n  { rintros h - \u27e8\u03b3, rfl\u27e9,\n    exact h \u03b3 }\nend\n\nend valued\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/topology/algebra/valuation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7494001274107308}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport ring_theory.principal_ideal_domain -- theory of PIDs\nimport data.polynomial.field_division -- polynomial rings over a field are PIDs\n/-\n\n# Principal Ideal Domains\n\nFirst let's showcase what mathlib has.\n\nLet `R` be a commutative ring.\n-/\n\nvariables (R : Type) [comm_ring R]\n\n-- We say `R` is a *principal ideal ring* if all ideals are principal.\n-- We say `R` is a *domain* if it's an integral domain. \n-- We say `R` is a *principal ideal domain* if it's both.\n\n-- So here's how to say \"Assume `R` is a PID\":\n\nvariables [is_principal_ideal_ring R] [is_domain R]\n\n-- Note that both of these are typeclasses, so various things should\n-- be automatic.\n\nexample : \u2200 a b : R, a * b = 0 \u2192 a = 0 \u2228 b = 0 :=\nbegin\n  intros a b,\n  apply eq_zero_or_eq_zero_of_mul_eq_zero, -- typeclass inference \n  -- magically extracts the assumption from `is_domain`\nend\n\nexample : (0 : R) \u2260 1 :=\nbegin\n  -- this is another consequence of being an integral domain\n  apply zero_ne_one,\nend\n\nexample (I : ideal R) : I.is_principal :=\nbegin\n  -- typeclass inference system finds `is_principal_ideal_ring` and\n  -- uses it automatically\n  exact is_principal_ideal_ring.principal I,\nend\n\nexample (I : ideal R) : \u2203 j, I = ideal.span {j} :=\nbegin\n  -- to make a term of type `is_principal I` you need to give one proof,\n  -- but we still need to do `cases` or equivalent (I used `obtain` below)\n  -- to get this proof out.\n  obtain \u27e8h\u27e9 := is_principal_ideal_ring.principal I,\n  exact h,\nend\n\n-- Typeclass inference knows a bunch of theorems about PIDs and which things are PIDs.\n-- Examples:\n\n-- integers are a PID\nexample : is_principal_ideal_ring \u2124 := begin\n  exact euclidean_domain.to_principal_ideal_domain\nend\n\n-- just check the domain bit:\nexample : is_domain \u2124 := begin\n  apply_instance\nend\n\n-- a field is a PID\nexample (k : Type) [field k] : is_principal_ideal_ring k :=\nbegin\n  apply_instance\nend\n\nexample (k : Type) [field k] : is_domain k :=\nbegin\n  apply_instance\nend\n\nopen_locale polynomial -- to get `k[X]` notation instead of `polynomial k`\n\n-- polys over a field are a PID\nexample (k : Type) [field k] : is_principal_ideal_ring k[X] :=\nbegin\n  apply_instance\nend\n\nexample (k : Type) [field k] : is_domain k[X] :=\nbegin\n  apply_instance\nend\n\n-- if all ideals of a ring are principal then the ring is a principal ideal ring\nexample (A : Type) [comm_ring A] (h : \u2200 I : ideal A, I.is_principal) : is_principal_ideal_ring A :=\n{ principal := h }\n\n-- see if you can prove that the ideal generated by 4 and 6 in any commutative ring is principal.\nexample (A : Type) [comm_ring A] : (ideal.span ({4, 6} : set A)).is_principal :=\nbegin\n  sorry,\nend\n\n-- product of two PIDs isn't a PID, but only becuase it's not a domain\nexample (A B : Type) [comm_ring A] [comm_ring B]\n  [is_principal_ideal_ring A] [is_principal_ideal_ring B] :\n  is_principal_ideal_ring (A \u00d7 B) :=\n{ principal := begin\n    sorry,\n  end }\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section14UFDs_and_PIDs_etc/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7493718780297658}}
{"text": "import incidence_world.level01 --hide\nopen IncidencePlane --hide\n\n/- Axiom :\nline_contains_two_points (\u2113 : Line \u03a9) : \u2203 P Q : \u03a9, P \u2260 Q \u2227 \u2113 = line_through P Q\n-/\n\n/-\n# Incidence World\n\n## Level 2: proving useful lemmas (I).\n\nIf you look at the list of your theorem statements, you will note that the lemma of the previous level has been added. Despite not\nbeing useful now, it will come handy for next levels. Analogously, the lemma of this level will be added to the list of theorem \nstatements, so that the computer can remember it in case you need to use it again.\n\nTo solve this level, another theorem statement has been added to the list as well. It is called `line_contains_two_points` and makes\nreference to the second axiom of incidence. You will need to use it now. Here you have some hints that may help you to prove the lemma. \n\n1) Add the hypothesis `A2 : \u2203 (P Q : \u03a9), P \u2260 Q \u2227 \u2113 = line_through P Q` by using the `have` tactic.\n\n2) Prove the hypothesis A2 by using the `line_contains_two_points` theorem statement (remember to type the line that you are using).+\n\n3) Work on the hypothesis A2 with the `cases` tactic.\n\n4) You may want to finish the proof with the `line_through_left` or the `line_through_right` theorem statement.\n\nIn case you get stuck, click right below for a hint.\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nYou will have to use the `cases` tactic three times. Go back to the tutorial world if you don't remember how to use it. Then, \"use\" one of the points\nthat you generated and \"rewrite\" the line \u2113 by using one of the hypotheses that you have in the local context. Still bewildered? Click on \"View source\" \n(located on the top right corner of the game screen) to see the solution. \n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables  {P Q: \u03a9} {r : Line \u03a9}  -- hide\n\n/- Lemma :\nGiven a line, there exists one point in that line.\n-/\nlemma exists_point_on_line (\u2113 : Line \u03a9): \u2203 A : \u03a9, A \u2208 \u2113 :=\nbegin\n\thave A2 : \u2203 (P Q : \u03a9), P \u2260 Q \u2227 \u2113 = line_through P Q,\n  {\n    exact line_contains_two_points \u2113,\n  },\n  cases A2 with A hA,\n  cases hA with B hB,\n  cases hB with HAB hl,\n  use A,\n  rw hl,\n  exact line_through_left A B,\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/incidence_world/level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363299661721, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7493718689358645}}
{"text": "import data.real.basic\n\n/-In this Lean tutorial, we aim to get to grips with using convergent\nsequences in Lean. We start by defining convergence in a similar manner to\nthe analysis 1 course.-/\n\ndef converges_to (s : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (s n - a) < \u03b5\n\n/-We will firstly look at the tactics which we will use in this section\nto help us close our proofs and provide some examples.-/\n\n/-We have already seen the rw, nth_rewrite and exact tactics being used, so we \nnow move onto using intros, specialize, apply, use and cases-/\n\n/-The intro tactic can be used when, for propositions A and B, our goal is of the\nform \n\u22a2 A \u2192 B \nor\n\u22a2\u2200( a : A ),B.\nThis allows us to introduce the left hand side of the goal as a hypothesis for us\nto use. For example, if you were to write \nintro h, \nfor both the previous examples, the goal states would change to\n\nh:A\n\u22a2B\n\nSome further examples of intro and shown below-/\n\nexample (A: Prop) : A \u2192 A:=\nbegin\nintro h, --We introduce our hypothesis h: A\nexact h, --Our goal is exactly the same as our hypothesis h\nend\n\nvariables {a b c : \u211d}\n\n#check (mul_pos : 0 < a \u2192 0 < b \u2192 0 < a * b)\n\nexample ( x : \u211d) (h\u2081: 0 < x) : \u2200 ( a : \u211d), 0 < a \u2192  0 < a*x:=\nbegin\nintros a apos, --We introduce the hypotheses a : \u211d and apos: 0 < a\nexact mul_pos apos h\u2081, --We use the theorem that multiplying two non-negative reals together gives a non-negative real \nend\n\n/-The use tactic can be deployed whenever our goal is of the form \n\u22a2 \u2203 (N : \u2115), statement\nThen by writing \nuse x, \nwhere x is a previous hypothesis, such as x : \u211d, meaning x is a real number, then our goal would progress to \n\u22a2 statement\nwhere the statement now depends on x. An example is given below-/\n\n#check (zero_lt_one : (0 : \u211d) < (1 : \u211d) )\n\nexample: \u2203 (x : \u211d), x < 1:=\nbegin\nuse 0,\nexact zero_lt_one,\nend\n\n/-The specialize tactic can be used whenever we have a hypothesis of the form \nhypothesis: \u2200 ( a : A), statement \nand another hypothesis say \nh : A. \nThen by writing \nspecialize @hypothesis h,\nour hypothesis will become \nhypothesis: statement depending on h\n\nFurthermore if our we have the following hypotheses \nh\u2081 : A \u2192 B\nh\u2082 : A\nthen we could write \nspecialize @h\u2081 h\u2082 \nin order to simplify h\u2081 to \nh\u2081: B \nAn example of using specialize is shown below with the question being from mathematics in Lean-/\n\nvariables {\u03b1 : Type*} (P : \u03b1 \u2192 Prop)\n\nexample (h : \u2200 x, \u00ac P x) : \u00ac \u2203 x, P x :=\nbegin\n  intros h\u2081, --This changes our goal to false h\u2081 : \u2203 (x : \u03b1), P x\n  cases h\u2081 with x hx, --We unfold our hypothesis h\u2081 giving us x:\u03b1 and hx : P x\n  specialize @h x, --We act at h: \u2200 (x : \u03b1), \u00acP x giving h: \u00acP x\n  specialize @h hx, --We know P x so acting on h: \u00acP x leaves us with h: false\n  exact h,--Our goal is exactly the same as the hypothesis h\nend\n\n/-The apply tactic for cases similar to the following\nh : A \u2192 B\n\u22a2 B\nwhere by writing \napply h,\nour goal will turn to \n\u22a2 A\nFurthermore, you can use apply when you have a theorem of the form A\u2192B\nA few examples of using apply can be found below-/\n\nexample (h\u2081 : a < b) (h\u2082: b < c): a < c :=\nbegin\napply lt_trans h\u2081 h\u2082, --We use transitivity with our two hypotheses to show a < c\nend\n\nexample (A B C : Prop) (h\u2081: A \u2192 B) (h\u2082: B \u2192 C) (h\u2083:A): C :=\nbegin\napply h\u2082, --This turns our goal from \u22a2C to \u22a2B\napply h\u2081, --This changes the goal from \u22a2B to \u22a2A\nexact h\u2083, --Our goal is the same as our hypothesis h\u2083\nend\n\n/-We lastly look at the cases tactic which can be used to unfold hypotheses of the form \nhypothesis: A \u2194 B\nin addition to \nhypothesis: \u2203(a:A), statement\nBy writing \ncases hypothesis with h\u2081 h\u2082\nWe would introduce the new hypotheses\nh\u2081 : A\nh\u2082 : B \nand \nh\u2081 : A\nh\u2082 : statement involving h\u2081\nrespectively\nAn example of using cases can be found above in the specialize section.-/\n\n/-Now we've outlined our the tactics we will use, lets outline some proofs involving convergence-/\n\n--Lets firstly look at a proof that if a function s converges absolutely to zero, then s converges to zero\n\nvariables {s t : \u2115 \u2192 \u211d} \n\n#check (sub_zero : \u2200 a : \u211d , a - 0 = a)\n#check (lt_of_abs_lt : | a |< b \u2192  a < b)\n\n\ntheorem converges_to_ze\n  (cs : converges_to (abs s) 0): converges_to (\u03bb n, s n ) (0) :=\nbegin\nintros \u03b5 \u03b5pos, --Introduce the hypotheses \u03b5:\u211d and \u03b5pos:\u03b5>0 \ndsimp,--This removes the \u03bb in our goal and makes it easier to read\ncases cs \u03b5 \u03b5pos with h\u2081 h\u2082, /-We unravel our hypothesis cs: converges_to |s| 0\nusing the fact \u03b5: \u211d and \u03b5pos: \u03b5 > 0 giving our two new hypotheses h\u2081 and h\u2082-/\nuse h\u2081, --We progress our goal by using the natural number h\u2081\nintros n h\u2083,--We progress our goal by introducing n: \u2115 and h\u2083: n \u2265 h\u2081\nspecialize @h\u2082 n h\u2083,--We simplify h\u2082 using n : \u2115 and h\u2083: n \u2265 h\u2081 leaving us with h\u2082: ||s| n - 0| < \u03b5\nrw sub_zero, --We use the theorem that a - 0 = a to simplify our goal to \u22a2 |s n| < \u03b5\nrw sub_zero at h\u2082,--We use the same theorem to simplify h\u2082 to ||s| n| < \u03b5\napply lt_of_abs_lt h\u2082,--We solve our goal by using the fact |a| < b \u2192 a < b on h\u2082 giving the goal \u22a2 |s n| < \u03b5\nend\n\n\n--Now we move onto a proof that convergent sequences are eventually bounded\n\n#check (le_abs_self : \u2200 (a :\u211d) , a \u2264 |a|)\n#check (sub_lt_iff_lt_add' : a - b < c \u2194 a < b + c)\n#check (lt_of_le_of_lt : a \u2264 b \u2192 b < c \u2192 a < c)\n\ntheorem exists_le_of_converges_to (cs : converges_to s a) :\n  \u2203 N b, \u2200 n, N \u2264 n \u2192 s n < b :=\nbegin\ncases cs 1 zero_lt_one with N h, /-Since s is convergent we let \u03b5=1 and introduce N : \u2115 and\nh: \u2200 (n : \u2115), n \u2265 N \u2192 |s n - a| < 1 -/ \nuse [N , a + 1], /-We will use n such that N \u2264 n and prove all terms beyond this\nare bounded by a+1 -/\nintros n h\u2081, -- Introduce n : \u2115 and h\u2081: N \u2264 n\nspecialize @h n h\u2081, --We use n and h\u2081 to transform h from \u2200 (n : \u2115), n \u2265 N \u2192 |s n - a| < 1 to |s n - a| < 1\nhave h\u2082: s n - a \u2264 abs(s n - a),-- We prove an auxiliary statement \napply le_abs_self, --This statement follows from the definition of the absolute value \nsuffices h\u2083: s n - a < 1, --We we show the goal \u22a2 s n - a < 1 instead\nexact sub_lt_iff_lt_add'.mp h\u2083, --(s n) - a < 1 implies (s n) < a + 1\napply lt_of_le_of_lt h\u2082 h, --We close our goal using transitivity with |s n - a| < 1 and s n - a \u2264 |s n - a|\nend\n\n\n--Now lets tackle the proof of the squeezing theorem with the following new theorems.\n\n#check (le_abs_self : \u2200 (a :\u211d) , a \u2264 |a|)\n#check (lt_trans : a < b \u2192 b < c \u2192 a < c)\n#check (lt_of_lt_of_le : a < b \u2192 b \u2264 c \u2192 a < c )\n\ntheorem squeeze (cs :converges_to s 0) \n(h\u2081: \u2200 (e:\u2115), (abs t e) < s e ): converges_to (\u03bb n, t n) (0):=\nbegin\nintros \u03b5 \u03b5pos, --Introduce the hypotheses \u03b5:\u211d and \u03b5pos:\u03b5>0 \ndsimp,-- This removes the \u03bb in our goal and makes it easier to read\ncases cs \u03b5 \u03b5pos with h\u2082 h\u2083, /-We unravel our hypothesis cs: converges_to |s| 0\nusing the fact \u03b5: \u211d and \u03b5pos: \u03b5 > 0 giving our two new hypotheses h\u2081 and h\u2082-/\nuse h\u2082, --We progress our goal by using the natural number h\u2082\nintros n h\u2084, --We progress our goal by introducing n: \u2115 and h\u2084: n \u2265 h\u2081\nspecialize @h\u2083 n h\u2084, --We simplify h\u2083 using n : \u2115 and h\u2084: n \u2265 h\u2081 leaving us with h\u2083: |s n - 0| < \u03b5\nrw sub_zero,-- We remove the zero in our goal since t n - 0 = t n\nrw sub_zero at h\u2083,--We remove the zero at h\u2083 leaving s n\nspecialize @h\u2081 n, --We simplify h\u2081 from \u2200 (e : \u2115), |t| e < s e to |t| n < s n\nhave h\u2085: s n \u2264  |s n|, --We use have in order to prove an auxiliary result, which will be helpful in our proof\nexact le_abs_self (s n),--We prove s n \u2264 |s n| using le_abs_self\napply lt_trans (lt_of_lt_of_le h\u2081 h\u2085) h\u2083, /-We close our goal using transitivity \nwith |t| n < s n, s n \u2264 |s n| and |s n| < \u03b5.-/\nend\n\n/-We now move on to proving that the sum of two convergent sequences is also convergent,\nbut we firstly mention the use of linarith and congr.\nLinarith can be used when we have a goal that can be closed just using linear arithmetic and\nLean will figure out what theorems to use to close the goal.\nCongr can be used to get rid of something that affects both sides of an equation allowing\nus to show that each side of an equality takes the same values. In the following proof\nit's used to get rid of the absolute sign when we prove an auxiliary hypothesis.-/\n\n#check (le_of_max_le_left : max a b \u2264 c \u2192 a \u2264 c )\n#check (le_of_max_le_right : max a b \u2264 c \u2192 b \u2264 c )\n#check (abs_add : \u2200 (a b : \u211d), |a+b| \u2264 |a| + |b| )\n#check (lt_of_le_of_lt : a \u2264 b \u2192 b < c \u2192 a < c )\n\n\ntheorem converges_to_add\n  (cs : converges_to s a) (ct : converges_to t b):\nconverges_to (\u03bb n, s n + t n) (a + b) :=\nbegin\nintros \u03b5 \u03b5pos, --Introduce \u03b5: \u211d and \u03b5pos: \u03b5 > 0\ndsimp, --dsimp gets rid of the \u03bb in our goal and makes it easier to read\nhave \u03b52pos : 0 < \u03b5 / 2, --Let's prove an additional statement that 0 < \u03b5/2\nlinarith , --Linarith uses linear arithmetic to show 0<\u03b5/2\ncases cs (\u03b5 / 2) \u03b52pos with Ns hs, --Convergence of s implies Ns: \u2115 and hs: \u2200 (n : \u2115), n \u2265 Ns \u2192 abs (s n - a) < \u03b5 / 2\ncases ct (\u03b5 / 2) \u03b52pos with Nt ht, --Convergence of t implies Nt: \u2115 and ht: \u2200 (n : \u2115), n \u2265 Nt \u2192 abs (t n - b) < \u03b5 / 2\nuse max Ns Nt, -- We will show \u22a2 \u2200 (n : \u2115), n \u2265 max Ns Nt \u2192 abs (s n + t n - (a + b)) < \u03b5\nintros c cN, -- Introduce c: \u2115 and cN: c \u2265 max Ns Nt\nspecialize @hs c,--hs becomes hs: c \u2265 Ns \u2192 abs (s c - a) < \u03b5 / 2\nspecialize @ht c,--ht becomes ht: c \u2265 Nt \u2192 abs (t c - b) < \u03b5 / 2\nspecialize @hs (le_of_max_le_left cN),-- hs becomes hs: abs (s c - a) < \u03b5 / 2\nspecialize @ht (le_of_max_le_right cN), --ht becomes ht: abs (t c - b) < \u03b5 / 2\nhave h\u2083: abs (s c + t c - (a + b)) = abs ((s c - a) + (t c - b)),\ncongr,-- We will show \u22a2 s c + t c - (a + b) = s c - a + (t c - b)\nlinarith, --The above can be solved with linear arithmetic\nrw h\u2083, --Change the goal to \u22a2 abs (s c - a + (t c - b)) < \u03b5\nhave h\u2085: abs (s c - a) + abs (t c - b) < \u03b5,\nlinarith, --\u03b5/2 + \u03b5 /2 = \u03b5\nhave h\u2086: abs((s c - a) + ( t c - b)) \u2264  abs (s c - a) + abs ( t c -b),\napply abs_add (s c - a) (t c - b), --We use the triangle inequality to prove h\u2086\napply lt_of_le_of_lt h\u2086 h\u2085, -- We complete our goal using transitivity\nend\n\n\n\n\n\n\n\n/-Mathematics in Lean by Jeremy Avigad has been used heavily in this tutorial with\nthe definition of convergence and first few lines of the proof showing the sum\nof convergent sequences is also convergent as well as a few of the examples for \nthe tactics.-/", "meta": {"author": "HarryPacitti", "repo": "LeanAnalysisTutorial1", "sha": "a1d39999c13f33aecd808d72961c94edc10c54a8", "save_path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1", "path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1/LeanAnalysisTutorial1-a1d39999c13f33aecd808d72961c94edc10c54a8/Examples/Analysisexample2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7492886225645539}}
{"text": "import .love01_definitions_and_statements_demo\n\n\n/-! # LoVe Demo 2: Backward Proofs\n\nA __tactic__ operates on a proof goal and either proves it or creates new\nsubgoals. Tactics are a __backward__ proof mechanism: They start from the goal\nand work towards the available hypotheses and lemmas. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace backward_proofs\n\n\n/-! ## Tactic Mode\n\nSyntax of tactical proofs:\n\n    begin\n      _tactic\u2081_,\n      \u2026,\n      _tacticN_\n    end -/\n\nlemma fst_of_two_props :\n  \u2200a b : Prop, a \u2192 b \u2192 a :=\nbegin\n  intros a b,\n  intros ha hb,\n  apply ha\nend\n\n\n/-! ## Basic Tactics\n\n`intro`(`s`) moves `\u2200`-quantified variables, or the assumptions of\nimplications `\u2192`, from the goal's conclusion (after `\u22a2`) into the goal's\nhypotheses (before `\u22a2`).\n\n`apply` matches the goal's conclusion with the conclusion of the specified lemma\nand adds the lemma's hypotheses as new goals. \n\nFood for thought: how do these compare to the typing derivation rules for \nlambda and application expressions?\n\n-/\n\nlemma fst_of_two_props\u2082 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nbegin\n  apply ha\nend\n\n/-! Terminal tactic syntax:\n\n    by _tactic_\n\nabbreviates\n\n    begin\n      _tactic_\n    end -/\n\nlemma fst_of_two_props\u2083 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nby apply ha\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  apply hbc,\n  apply hab,\n  apply ha\nend\n\n/-! `exact` matches the goal's conclusion with the specified lemma, closing the\ngoal. We can often use `apply` in such situations, but `exact` communicates our\nintentions better. -/\n\nlemma fst_of_two_props\u2084 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nby exact ha\n\n/-! `assumption` finds a hypothesis from the local context that matches the\ngoal's conclusion and applies it to prove the goal. -/\n\nlemma fst_of_two_props\u2085 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nby assumption\n\n/-! ## Reasoning about Logical Connectives and Quantifiers\n\nIntroduction rules: \n\nThe relevant symbol appears in the *conclusion* of the statement.\n(On the right side of the ->)\n\nWe apply these rules when the symbol appears in our *goal*.\n-/\n\n#check true.intro\n#check not.intro\n#check and.intro\n#check or.intro_left\n#check or.intro_right\n#check iff.intro\n#check exists.intro\n\n/-! Elimination rules: \n\nThe relevant symbol appears in a *hypothesis* of the statement.\n(On the left side of the ->)\n\nWe apply these rules when the symbol appears in our *context*.\n-/\n\n#check false.elim\n#check and.elim_left\n#check and.elim_right\n#check or.elim\n#check iff.elim_left\n#check iff.elim_right\n#check exists.elim\n\n/-! Definition of `\u00ac` and related lemmas: -/\n\n#print not\n#check not_def\n#check classical.em\n#check classical.by_contradiction\n\nlemma and_swap (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intro hab,\n  apply and.intro,\n  apply and.elim_right,\n  exact hab,\n  apply and.elim_left,\n  exact hab\nend\n\n/-! The `{ \u2026 }` combinator focuses on the first subgoal. The tactic inside must\nfully prove it. -/\n\nlemma and_swap\u2082 :\n  \u2200a b : Prop, a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intros a b hab,\n  apply and.intro,\n  { exact and.elim_right hab },\n  { exact and.elim_left hab }\nend\n\n/-! Notice above how we pass the hypothesis `hab` directly to the lemmas\n`and.elim_right` and `and.elim_left`, instead of waiting for the lemmas's\nassumptions to appear as new subgoals. This is a small forward step in an\notherwise backward proof. -/\n\nlemma or_swap (a b : Prop) :\n  a \u2228 b \u2192 b \u2228 a :=\nbegin\n  intros hab,\n  apply or.elim hab,\n  { intro ha,\n    exact or.intro_right _ ha },\n  { intro hb,\n    exact or.intro_left _ hb }\nend\n\nlemma modus_ponens (a b : Prop) :\n  (a \u2192 b) \u2192 a \u2192 b :=\nbegin\n  intros hab ha,\n  apply hab,\n  exact ha\nend\n\nlemma not_not_intro (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nbegin\n  intro ha,\n  apply not.intro,\n  intro hna,\n  apply hna,\n  exact ha\nend\n\nlemma not_not_intro\u2082 (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nbegin\n  intros ha hna,\n  apply hna,\n  exact ha\nend\n\n\ndef double (n : \u2115) : \u2115 :=\nn + n\n\nlemma nat_exists_double_iden :\n  \u2203n : \u2115, double n = n :=\nbegin\n  apply exists.intro 0,\n  refl\nend\n\n\n/-! ## Reasoning about Equality\n\n*Syntactic* equality:\n  x = x\n  [2, 1, 3] = [2, 1, 3]\n  \n*Definitional* equality (*intensional*, *up to computation*):\n  2 + 2 = 4\n  quicksort [2, 1, 3] = mergesort [2, 1, 3]\n  all of the `by refl` examples below\n\n*Propositional* equality (*provable*):\n  x + y = y + x\n  quicksort = mergesort\n -/\n\n\n\n/-! `refl` proves `l = r`, where the two sides are equal up to\ncomputation. Computation means unfolding of definitions, \u03b2-reduction\n(application of \u03bb to an argument), `let`, and more. -/\n\nlemma \u03b1_example {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) :\n  (\u03bbx, f x) = (\u03bby, f y) :=\nbegin\n  refl\nend\n\nlemma \u03b1_example\u2082 {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) :\n  (\u03bbx, f x) = (\u03bby, f y) :=\nby refl\n\nlemma \u03b2_example {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :\n  (\u03bbx, f x) a = f a :=\nby refl\n\nlemma \u03b4_example :\n  double 5 = 5 + 5 :=\nby refl\n\nlemma \u03b6_example :\n  (let n : \u2115 := 2 in n + n) = 2 + 2 :=\nby refl\n\nlemma \u03b7_example {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) :\n  (\u03bbx, f x) = f :=\nby refl\n\ninductive my_prod (\u03b1 \u03b2 : Type) : Type\n| mk : \u03b1 \u2192 \u03b2 \u2192 my_prod\n\ndef my_prod.first {\u03b1 \u03b2 : Type} : my_prod \u03b1 \u03b2 \u2192 \u03b1\n| (my_prod.mk a b) := a\n\nlemma \u03b9_example {\u03b1 \u03b2 : Type} (a : \u03b1) (b : \u03b2) :\n  my_prod.first (my_prod.mk a b) = a :=\nby refl\n\n/-!\n\nWhich ones of these are *reduction rules*?\n\n-/\n\n\n#check eq.refl\n#check eq.symm\n#check eq.trans\n#check eq.subst\n\n/-! The above rules can be used directly: -/\n\nlemma cong_fst_arg {\u03b1 : Type} (a a' b : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') :\n  f a b = f a' b :=\nbegin\n  apply eq.subst ha,\n  apply eq.refl\nend\n\nlemma cong_two_args {\u03b1 : Type} (a a' b b' : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  f a b = f a' b' :=\nbegin\n  apply eq.subst ha,\n  apply eq.subst hb,\n  apply eq.refl\nend\n\n/-! `rw` applies a single equation as a left-to-right rewrite rule, once. To\napply an equation right-to-left, prefix its name with `\u2190`. -/\n\nlemma cong_two_args\u2082 {\u03b1 : Type} (a a' b b' : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  f a b = f a' b' :=\nbegin\n  rw ha,\n  rw hb\nend\n\n#check add_comm\n#check add_assoc\n\nlemma nat_comm_example (a b c : \u2115) : \n  a + b + c = c + b + a :=\nbegin \n  rw add_comm,\n  rw add_comm a,\n  rw add_assoc\nend\n\nlemma nat_comm_example\u2082 (a b c : \u2115) : \n  a + b + c = c + b + a :=\nbegin \n  rw [add_comm, add_comm a, add_assoc]\nend\n\nlemma double_example (n : \u2115) :\n  double n = n + n + 0 :=\nbegin \n  rw double,\n  refl\nend\n\nlemma a_proof_of_negation\u2083 (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nbegin\n  rw not_def,\n  rw not_def,\n  intro ha,\n  intro hna,\n  apply hna,\n  exact ha\nend\n\n/-! `simp` applies a standard set of rewrite rules (the __simp set__)\nexhaustively. The set can be extended using the `@[simp]` attribute. Lemmas can\nbe temporarily added to the simp set with the syntax\n`simp [_lemma\u2081_, \u2026, _lemmaN_]`. -/\n\nlemma cong_two_args_etc {\u03b1 : Type} (a a' b b' : \u03b1)\n    (g : \u03b1 \u2192 \u03b1 \u2192 \u2115 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  g a b (1 + 1) = g a' b' 2 :=\nby simp [ha, hb]\n\n\n/-! `cc` applies __congruence closure__ to derive new equalities. -/\n\nlemma cong_two_args\u2083 {\u03b1 : Type} (a a' b b' : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  f a b = f a' b' :=\nby cc\n\n/-! `cc` can also reason up to associativity and commutativity of `+`, `*`,\nand other binary operators. -/\n\nlemma cong_assoc_comm (a a' b c : \u211d) (f : \u211d \u2192 \u211d)\n    (ha : a = a') :\n  f (a + b + c) = f (c + b + a') :=\nby cc\n\n\n/-! ## Proofs by Mathematical Induction\n\n`induction'` performs induction on the specified variable. It gives rise to one\nsubgoal per constructor. -/\n\nlemma add_zero (n : \u2115) :\n  add 0 n = n :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, ih] }\nend\n\n/-! We use `induction'`, a variant of Lean's built-in `induction` tactic. The\ntwo tactics are similar, but `induction'` is more user-friendly. -/\n\nlemma add_succ (i j : \u2115) :\n  add (nat.succ i) j = nat.succ (add i j) :=\nbegin\n  induction' j,\n  { refl },\n  { simp [add, ih] }\nend\n\nlemma add_comm (i j : \u2115) :\n  add i j = add j i :=\nbegin\n  induction' j,\n  { simp [add, add_zero] },\n  { simp [add, add_succ, ih] }\nend\n\nlemma add_assoc (i j k : \u2115) :\n  add (add i j) k = add i (add j k) :=\nbegin\n  induction' k,\n  { refl },\n  { simp [add, ih] }\nend\n\n/-! `cc` is extensible. We can register `add` as a commutative and associative\noperator using the type class instance mechanism (explained in lecture 4). This\nis useful for the `cc` invocation below. -/\n\n@[instance] def add.is_commutative : is_commutative \u2115 add :=\n{ comm := add_comm }\n\n@[instance] def add.is_associative : is_associative \u2115 add :=\n{ assoc := add_assoc }\n\nlemma mul_add (i j k : \u2115) :\n  mul i (add j k) = add (mul i j) (mul i k) :=\nbegin\n  induction' k,\n  { refl },\n  { simp [add, mul, ih],\n    cc }\nend\n\n\n/-! ## Cleanup Tactics\n\n`rename` changes the name of a variable or hypothesis.\n\n`clear` removes unused variables or hypotheses. -/\n\nlemma cleanup_example (a b c : Prop) (ha : a) (hb : b)\n    (hab : a \u2192 b) (hbc : b \u2192 c) :\n  c :=\nbegin\n  clear ha hab a,\n  apply hbc,\n  clear hbc c,\n  rename hb h,\n  exact h\nend\n\nend backward_proofs\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/lectures/love02_backward_proofs_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7492886181449303}}
{"text": "/- LoVe Homework 2: Tactical Proofs -/\n\nimport .love02_tactical_proofs_exercise\n\nnamespace LoVe\n\n\n/- Question 1: Connectives and Quantifiers -/\n\n/- 1.1. Complete the following proofs using basic tactics. -/\n\nlemma B (a b c : Prop) :\n  (a \u2192 b) \u2192 (c \u2192 a) \u2192 c \u2192 b :=\nsorry\n\nlemma S (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 (a \u2192 b) \u2192 a \u2192 c :=\nsorry\n\nlemma more_nonsense (a b c d : Prop) :\n  ((a \u2192 b) \u2192 c \u2192 d) \u2192 c \u2192 b \u2192 d :=\nsorry\n\nlemma even_more_nonsense (a b c : Prop) :\n  (a \u2192 b) \u2192 (a \u2192 c) \u2192 a \u2192 b \u2192 c :=\nsorry\n\n/- 1.2. Prove the following lemma. -/\n\nlemma weak_peirce (a b : Prop) :\n  ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\n\n/- Question 2 (**optional**): Logical Connectives -/\n\n/- 2.1 (**optional**). Prove the following property about double negation.\n\nHint: You will need to apply the elimination rule for `false` at a key point in\nthe proof. -/\n\nlemma herman (p : Prop) : \u00ac\u00ac (\u00ac\u00ac p \u2192 p) :=\nsorry\n\n/- 2.2 (**optional**). Prove the missing link in our chain of classical axiom\nimplications.\n\nHint: You will need to apply the double negation hypothesis for `p \u2228 \u00ac p`. You\nwill also need the left and right introduction rules for `or` at some point. -/\n\n#check excluded_middle\n#check peirce\n#check double_negation\n\nlemma em_of_dn : double_negation \u2192 excluded_middle :=\nsorry\n\n/- 2.3 (**optional**). We have proved three of the six possible implications\nbetween `excluded_middle`, `peirce`, and `double_negation`. State and prove the\nthree missing implications, exploiting the three theorems we already have. -/\n\n#check peirce_of_em\n#check dn_of_peirce\n#check em_of_dn\n\n-- enter your solution here\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love02_tactical_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.7492886157770399}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot, Casper Putz, Anne Baanen\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.finite_dimensional\n! leanprover-community/mathlib commit 1cfdf5f34e1044ecb65d10be753008baaf118edf\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Matrix.Basic\nimport Mathbin.LinearAlgebra.FiniteDimensional\n\n/-!\n# The finite-dimensional space of matrices\n\nThis file shows that `m` by `n` matrices form a finite-dimensional space,\nand proves the `finrank` of that space is equal to `card m * card n`.\n\n## Main definitions\n\n * `matrix.finite_dimensional`: matrices form a finite dimensional vector space over a field `K`\n * `matrix.finrank_matrix`: the `finrank` of `matrix m n R` is `card m * card n`\n\n## Tags\n\nmatrix, finite dimensional, findim, finrank\n\n-/\n\n\nuniverse u v\n\nnamespace Matrix\n\nsection FiniteDimensional\n\nvariable {m n : Type _} {R : Type v} [Field R]\n\ninstance [Finite m] [Finite n] : FiniteDimensional R (Matrix m n R) :=\n  LinearEquiv.finiteDimensional (LinearEquiv.curry R m n)\n\n/-- The dimension of the space of finite dimensional matrices\nis the product of the number of rows and columns.\n-/\n@[simp]\ntheorem finrank_matrix [Fintype m] [Fintype n] :\n    FiniteDimensional.finrank R (Matrix m n R) = Fintype.card m * Fintype.card n := by\n  rw [@LinearEquiv.finrank_eq R (Matrix m n R) _ _ _ _ _ _ (LinearEquiv.curry R m n).symm,\n    FiniteDimensional.finrank_fintype_fun_eq_card, Fintype.card_prod]\n#align matrix.finrank_matrix Matrix.finrank_matrix\n\nend FiniteDimensional\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/FiniteDimensional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7492886126729108}}
{"text": "import data.real.basic\nimport algebra.pi_instances\nimport tuto_lib\n\nnotation `|`x`|` := abs x\n\n/-\nIn this file we manipulate the elementary definition of limits of\nsequences of real numbers. \nmathlib has a much more general definition of limits, but here\nwe want to practice using the logical operators and relations\ncovered in the previous files.\n\nA sequence u is a function from \u2115 to \u211d, hence Lean says\nu : \u2115 \u2192 \u211d\nThe definition we'll be using is:\n\n-- Definition of \u00ab u tends to l \u00bb\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\nNote the use of `\u2200 \u03b5 > 0, ...` which is an abbreviation of\n`\u2200 \u03b5, \u03b5 > 0 \u2192 ... `\n\nIn particular, a statement like `h : \u2200 \u03b5 > 0, ...`\ncan be specialized to a given \u03b5\u2080 by\n  `specialize h \u03b5\u2080 h\u03b5\u2080`\nwhere h\u03b5\u2080 is a proof of \u03b5\u2080 > 0.\n\nAlso recall that, wherever Lean expects some proof term, we can\nstart a tactic mode proof using the keyword `by` (followed by curly braces\nif you need more than one tactic invocation).\nFor instance, if the local context contains:\n\n\u03b4 : \u211d\n\u03b4_pos : \u03b4 > 0\nh : \u2200 \u03b5 > 0, ...\n\nthen we can specialize h to the real number \u03b4/2 using:\n  `specialize h (\u03b4/2) (by linarith)`\nwhere `by linarith` will provide the proof of `\u03b4/2 > 0` expected by Lean.\n\nWe'll take this opportunity to use two new tactics:\n\n`norm_num` will perform numerical normalization on the goal and `norm_num at h` \nwill do the same in assumption `h`. This will get rid of trivial calculations on numbers,\nlike replacing |l - l| by zero in the next exercise.\n\n`congr'` will try to prove equalities between applications of functions by recursively \nproving the arguments are the same. \nFor instance, if the goal is `f x + g y = f z + g t` then congr will replace it by\ntwo goals: `x = z` and `y = t`.\nYou can limit the recursion depth by specifying a natural number after `congr'`. \nFor instance, in the above example, `congr' 1` will give new goals\n`f x = f z` and `g y = g t`, which only inspect arguments of the addition and not deeper.\n-/\n\nvariables (u v w : \u2115 \u2192 \u211d) (l l' l\u2081 l\u2082 : \u211d)\n\n-- If u is constant with value l then u tends to l\n-- 0033\nexample : (\u2200 n, u n = l) \u2192 seq_limit u l :=\nbegin\n  intros h x hx,\n  use 0,\n  intros n hn,\n  rw h,\n  norm_num,\n  exact le_of_lt hx\nend\n\n/- When dealing with absolute values, we'll use lemmas:\n\nabs_le (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nabs_add (x y : \u211d) : |x + y| \u2264 |x| + |y|\n\nabs_sub (x y : \u211d) : |x - y| = |y - x|\n\nYou should probably write them down on a sheet of paper that you keep at \nhand since they are used in many exercises.\n-/\n\n-- Assume l > 0. Then u tends to l implies u n \u2265 l/2 for large enough n\n-- 0034\nexample (hl : l > 0) : seq_limit u l \u2192 \u2203 N, \u2200 n \u2265 N, u n \u2265 l/2 :=\nbegin\n  intro h,\n  cases h (l/2) (by linarith) with x hx,\n  use x,\n  intros y hy,\n  specialize hx y hy,\n  rw abs_le at hx,\n  linarith\nend\n\n/- \nWhen dealing with max, you can use\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\nYou should probably add them to the sheet of paper where you wrote \nthe `abs` lemmas since they are used in many exercises.\n\nLet's see an example.\n-/\n\nexample (hu : seq_limit u l\u2081) (hv : seq_limit v l\u2082) :\n  seq_limit (u + v) (l\u2081 + l\u2082) :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with n\u2081 hn\u2081,\n  cases hv (\u03b5/2) (by linarith) with n\u2082 hn\u2082,\n  use max n\u2081 n\u2082,\n  intros n hn,\n  cases ge_max_iff.mp hn with hn\u2081' hn\u2082',\n  have : |u n - l\u2081| \u2264 \u03b5/2, from hn\u2081 n hn\u2081',\n  have : |v n - l\u2082| \u2264 \u03b5/2, from hn\u2082 n hn\u2082',\n  calc\n  |(u + v) n - (l\u2081 + l\u2082)| = |u n + v n - (l\u2081 + l\u2082)|   : rfl\n  ...                     = |(u n - l\u2081) + (v n - l\u2082)| : by congr' 1; ring\n  ...                     \u2264 |u n - l\u2081| + |v n - l\u2082|   : by apply abs_add\n  ...                     \u2264 \u03b5                         : by linarith\nend\n\n-- If u tends to l and v tends l' then u+v tends to l+l'\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\n  seq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  cases ge_max_iff.mp hn with hn\u2081 hn\u2082,\n  have fact\u2081 : |u n - l| \u2264 \u03b5/2,\n    from hN\u2081 n (by linarith),  -- note the use of `from`.\n                               -- This is an alias for `exact`, \n                               -- but reads nicer in this context \n  have fact\u2082 : |v n - l'| \u2264 \u03b5/2,\n    from hN\u2082 n (by linarith), \n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith,\nend\n\n/-\nIn the above proof, we used `have` to prepare facts for `linarith` consumption in the last line.\nSince we have direct proof terms for them, we can feed them directly to `linarith` as in the next proof\nof the same statement.\nAnother variation we introduce is rewriting using `ge_max_iff` and letting `linarith` handle the\nconjunction, instead of creating two new assumptions.\n-/\n\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\n  seq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  rw ge_max_iff at hn,\n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1 ; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith [hN\u2081 n (by linarith), hN\u2082 n (by linarith)],\nend\n\n/- Let's do something similar: the squeezing theorem. -/\n-- 0035\nexample (hu : seq_limit u l) (hw : seq_limit w l)\n  (h\u2081 : \u2200 n, u n \u2264 v n)\n  (h\u2082 : \u2200 n, v n \u2264 w n) : seq_limit v l :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu \u03b5 (by linarith) with n\u2081 hn\u2081,\n  cases hw \u03b5 (by linarith) with n\u2082 hn\u2082,\n  use max n\u2081 n\u2082,\n  intros k hk,\n  rw ge_max_iff at hk,\n  specialize hn\u2081 k hk.1,\n  specialize hn\u2082 k hk.2,\n  specialize h\u2081 k,\n  specialize h\u2082 k,\n  rw abs_le at *,\n  split,\n  show -\u03b5 \u2264 v k - l, by calc\n  -\u03b5  \u2264 u k - l : by linarith\n  ... \u2264 v k - l : by linarith,\n  show v k - l \u2264 \u03b5, by calc\n  v k - l \u2264 w k - l : by linarith\n  ...     \u2264 \u03b5       : by linarith,\nend\n\n/- What about < \u03b5? -/\n-- 0036\nexample (u l) : seq_limit u l \u2194\n \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5 :=\nbegin\n  split,\n  { intros h \u03b5 \u03b5_pos,\n    cases h (\u03b5/2) (by linarith) with n hn,\n    use n,\n    intros m hm,\n    specialize hn m hm,\n    linarith },\n  { intros h \u03b5 \u03b5_pos,\n    cases h \u03b5 \u03b5_pos with n hn,\n    use n,\n    intros m hm,\n    specialize hn m hm,\n    linarith }\nend\n\n/- In the next exercise, we'll use\n\neq_of_abs_sub_le_all (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y\n-/\n\n-- A sequence admits at most one limit\n-- 0037\nexample : seq_limit u l \u2192 seq_limit u l' \u2192 l = l' :=\nbegin\n  intros h h',\n  apply eq_of_abs_sub_le_all,\n  intros \u03b5 \u03b5_pos,\n  cases h (\u03b5/2) (by linarith) with n h,\n  cases h' (\u03b5/2) (by linarith) with n' h',\n  specialize h (max n n') (le_max_left _ _),\n  specialize h' (max n n') (le_max_right _ _),\n  rw abs_le at *,\n  split; linarith\nend\n\n/-\nLet's now practice deciphering definitions before proving.\n-/\n\ndef non_decreasing (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\ndef is_seq_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n-- 0038\nexample (M : \u211d) (h : is_seq_sup M u) (h' : non_decreasing u) :\n  seq_limit u M :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases h with hM hu,\n  cases hu \u03b5 \u03b5_pos with N hN,\n  use N,\n  intros n hn,\n  apply abs_le_of_le_of_neg_le,\n  { apply sub_le_of_sub_le,  \n    rw sub_le_iff_le_add,\n    specialize hM n,\n    linarith },\n  { specialize h' N n hn,\n    linarith }\nend\n\n", "meta": {"author": "pedrominicz", "repo": "learn", "sha": "b79b802a9846c86c21d4b6f3e17af36e7382f0ef", "save_path": "github-repos/lean/pedrominicz-learn", "path": "github-repos/lean/pedrominicz-learn/learn-b79b802a9846c86c21d4b6f3e17af36e7382f0ef/src/tutorials/05_sequence_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7492599559889599}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport algebra.geom_sum\nimport algebra.group.unique_prods\nimport algebra.monoid_algebra.basic\nimport data.finsupp.lex\nimport data.zmod.basic\n\n/-!\n# Examples of zero-divisors in `add_monoid_algebra`s\n\nThis file contains an easy source of zero-divisors in an `add_monoid_algebra`.\nIf `k` is a field and `G` is an additive group containing a non-zero torsion element, then\n`add_monoid_algebra k G` contains non-zero zero-divisors: this is lemma `zero_divisors_of_torsion`.\n\nThere is also a version for periodic elements of an additive monoid: `zero_divisors_of_periodic`.\n\nThe converse of this statement is\n[Kaplansky's zero divisor conjecture](https://en.wikipedia.org/wiki/Kaplansky%27s_conjectures).\n\nThe formalized example generalizes in trivial ways the assumptions: the field `k` can be any\nnontrivial ring `R` and the additive group `G` with a torsion element can be any additive monoid\n`A` with a non-zero periodic element.\n\nBesides this example, we also address a comment in `data.finsupp.lex` to the effect that the proof\nthat addition is monotone on `\u03b1 \u2192\u2080 N` uses that it is *strictly* monotone on `N`.\n\nThe specific statement is about `finsupp.lex.covariant_class_le_left` and its analogue\n`finsupp.lex.covariant_class_le_right`.  We do not need two separate counterexamples, since the\noperation is commutative.\n\nThe example is very simple.  Let `F = {0, 1}` with order determined by `0 < 1` and absorbing\naddition (which is the same as `max` in this case).  We denote a function `f : F \u2192 F` (which is\nautomatically finitely supported!) by `[f 0, f 1]`, listing its values.  Recall that the order on\nfinitely supported function is lexicographic, matching the list notation.  The inequality\n`[0, 1] \u2264 [1, 0]` holds.  However, adding `[1, 0]` to both sides yields the *reversed* inequality\n`[1, 1] > [1, 0]`.\n-/\nopen finsupp add_monoid_algebra\n\n/--  This is a simple example showing that if `R` is a non-trivial ring and `A` is an additive\nmonoid with an element `a` satisfying `n \u2022 a = a` and `(n - 1) \u2022 a \u2260 a`, for some `2 \u2264 n`,\nthen `add_monoid_algebra R A` contains non-zero zero-divisors.  The elements are easy to write down:\n`[a]` and `[a] ^ (n - 1) - 1` are non-zero elements of `add_monoid_algebra R A` whose product\nis zero.\n\nObserve that such an element `a` *cannot* be invertible.  In particular, this lemma never applies\nif `A` is a group. -/\nlemma zero_divisors_of_periodic {R A} [nontrivial R] [ring R] [add_monoid A] {n : \u2115} (a : A)\n  (n2 : 2 \u2264 n) (na : n \u2022 a = a) (na1 : (n - 1) \u2022 a \u2260 0) :\n  \u2203 f g : add_monoid_algebra R A, f \u2260 0 \u2227 g \u2260 0 \u2227 f * g = 0 :=\nbegin\n  refine \u27e8single a 1, single ((n - 1) \u2022 a) 1 - single 0 1, by simp, _, _\u27e9,\n  { exact sub_ne_zero.mpr (by simpa [single_eq_single_iff]) },\n  { rw [mul_sub, add_monoid_algebra.single_mul_single, add_monoid_algebra.single_mul_single,\n      sub_eq_zero, add_zero, \u2190 succ_nsmul, nat.sub_add_cancel (one_le_two.trans n2), na] },\nend\n\nlemma single_zero_one {R A} [semiring R] [has_zero A] :\n  single (0 : A) (1 : R) = (1 : add_monoid_algebra R A) := rfl\n\n/--  This is a simple example showing that if `R` is a non-trivial ring and `A` is an additive\nmonoid with a non-zero element `a` of finite order `oa`, then `add_monoid_algebra R A` contains\nnon-zero zero-divisors.  The elements are easy to write down:\n`\u2211 i in finset.range oa, [a] ^ i` and `[a] - 1` are non-zero elements of `add_monoid_algebra R A`\nwhose product is zero.\n\nIn particular, this applies whenever the additive monoid `A` is an additive group with a non-zero\ntorsion element. -/\nlemma zero_divisors_of_torsion {R A} [nontrivial R] [ring R] [add_monoid A] (a : A)\n  (o2 : 2 \u2264 add_order_of a) :\n  \u2203 f g : add_monoid_algebra R A, f \u2260 0 \u2227 g \u2260 0 \u2227 f * g = 0 :=\nbegin\n  refine \u27e8(finset.range (add_order_of a)).sum (\u03bb (i : \u2115), (single a 1) ^ i),\n    single a 1 - single 0 1, _, _, _\u27e9,\n  { apply_fun (\u03bb x : add_monoid_algebra R A, x 0),\n    refine ne_of_eq_of_ne (_ : (_ : R) = 1) one_ne_zero,\n    simp_rw finset.sum_apply',\n    refine (finset.sum_eq_single 0 _ _).trans _,\n    { intros b hb b0,\n      rw [single_pow, one_pow, single_eq_of_ne],\n      exact nsmul_ne_zero_of_lt_add_order_of' b0 (finset.mem_range.mp hb) },\n    { simp only [(zero_lt_two.trans_le o2).ne', finset.mem_range, not_lt, le_zero_iff,\n        false_implies_iff] },\n    { rw [single_pow, one_pow, zero_smul, single_eq_same] } },\n  { apply_fun (\u03bb x : add_monoid_algebra R A, x 0),\n    refine sub_ne_zero.mpr (ne_of_eq_of_ne (_ : (_ : R) = 0) _),\n    { have a0 : a \u2260 0 := ne_of_eq_of_ne (one_nsmul a).symm\n        (nsmul_ne_zero_of_lt_add_order_of' one_ne_zero (nat.succ_le_iff.mp o2)),\n      simp only [a0, single_eq_of_ne, ne.def, not_false_iff] },\n    { simpa only [single_eq_same] using zero_ne_one, } },\n  { convert commute.geom_sum\u2082_mul _ (add_order_of a),\n    { ext, rw [single_zero_one, one_pow, mul_one] },\n    { rw [single_pow, one_pow, add_order_of_nsmul_eq_zero, single_zero_one, one_pow, sub_self] },\n    { simp only [single_zero_one, commute.one_right] } },\nend\n\nexample {R} [ring R] [nontrivial R] (n : \u2115) (n0 : 2 \u2264 n) :\n  \u2203 f g : add_monoid_algebra R (zmod n), f \u2260 0 \u2227 g \u2260 0 \u2227 f * g = 0 :=\nzero_divisors_of_torsion (1 : zmod n) (n0.trans_eq (zmod.add_order_of_one _).symm)\n\n/--  `F` is the type with two elements `zero` and `one`.  We define the \"obvious\" linear order and\nabsorbing addition on it to generate our counterexample. -/\n@[derive [decidable_eq, inhabited]] inductive F | zero | one\n\n/--  The same as `list.get_rest`, except that we take the \"rest\" from the first match, rather than\nfrom the beginning, returning `[]` if there is no match.  For instance,\n```lean\n#eval [1,2].drop_until [3,1,2,4,1,2]  -- [4, 1, 2]\n```\n-/\ndef list.drop_until {\u03b1} [decidable_eq \u03b1] : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| l [] := []\n| l (a::as) := ((a::as).get_rest l).get_or_else (l.drop_until as)\n\n/-- `guard_decl_in_file na loc` makes sure that the declaration with name `na` is in the file with\nrelative path `\"src/\" ++ \"/\".intercalate loc ++ \".lean\"`.\n```lean\n#eval guard_decl_in_file `nat.nontrivial [\"data\", \"nat\", \"basic\"]  -- does nothing\n\n#eval guard_decl_in_file `nat.nontrivial [\"not\", \"in\", \"here\"]\n-- fails giving the location 'data/nat/basic.lean'\n```\n\nThis test makes sure that the comment referring to this example is in the file claimed in the\ndoc-module to this counterexample. -/\nmeta def guard_decl_in_file (na : name) (loc : list string) : tactic unit :=\ndo env \u2190 tactic.get_env,\n  some fil \u2190 pure $ env.decl_olean na | fail!\"the instance `{na}` is not imported!\",\n  let path : string := \u27e8list.drop_until \"/src/\".to_list fil.to_list\u27e9,\n  let locdot : string := \".\".intercalate loc,\n  guard (fil.ends_with (\"src/\" ++ \"/\".intercalate loc ++ \".lean\")) <|>\n    fail!(\"instance `{na}` is no longer in `{locdot}`.\\n\\n\" ++\n      \"Please, update the doc-module and this check with the correct location:\\n\\n'{path}'\\n\")\n\n#eval guard_decl_in_file `finsupp.lex.covariant_class_le_left [\"data\", \"finsupp\", \"lex\"]\n#eval guard_decl_in_file `finsupp.lex.covariant_class_le_right [\"data\", \"finsupp\", \"lex\"]\n\nnamespace F\n\ninstance : has_zero F := \u27e8F.zero\u27e9\n\n/--  `1` is not really needed, but it is nice to use the notation. -/\ninstance : has_one F := \u27e8F.one\u27e9\n\n/--  A tactic to prove trivial goals by enumeration. -/\nmeta def boom : tactic unit :=\n`[ repeat { rintro \u27e8\u27e9 }; dec_trivial ]\n\n/--  `val` maps `0 1 : F` to their counterparts in `\u2115`.\nWe use it to lift the linear order on `\u2115`. -/\ndef val : F \u2192 \u2115\n| 0 := 0\n| 1 := 1\n\ninstance : linear_order F := linear_order.lift' val (by boom)\n\n@[simp] lemma z01  : (0 : F) < 1 := by boom\n\n/--  `F` would be a `comm_semiring`, using `min` as multiplication.  Again, we do not need this. -/\ninstance : add_comm_monoid F :=\n{ add       := max,\n  add_assoc := by boom,\n  zero      := 0,\n  zero_add  := by boom,\n  add_zero  := by boom,\n  add_comm  := by boom }\n\n/--  The `covariant_class`es asserting monotonicity of addition hold for `F`. -/\ninstance covariant_class_add_le : covariant_class F F (+) (\u2264) := \u27e8by boom\u27e9\nexample : covariant_class F F (function.swap (+)) (\u2264) := by apply_instance\n\n/--  The following examples show that `F` has all the typeclasses used by\n`finsupp.lex.covariant_class_le_left`... -/\nexample : linear_order F := by apply_instance\nexample : add_monoid F   := by apply_instance\n\n/-- ... except for the strict monotonicity of addition, the crux of the matter. -/\nexample : \u00ac covariant_class F F (+) (<) := \u03bb h, lt_irrefl 1 $ (h.elim : covariant F F (+) (<)) 1 z01\n\n/--  A few `simp`-lemmas to take care of trivialities in the proof of the example below. -/\n@[simp] lemma f1   : \u2200 (a : F), 1 + a = 1 := by boom\n@[simp] lemma f011 : of_lex (single (0 : F) (1 : F)) 1 = 0 := single_apply_eq_zero.mpr (\u03bb h, h)\n@[simp] lemma f010 : of_lex (single (0 : F) (1 : F)) 0 = 1 := single_eq_same\n@[simp] lemma f111 : of_lex (single (1 : F) (1 : F)) 1 = 1 := single_eq_same\n@[simp] lemma f110 : of_lex (single (1 : F) (1 : F)) 0 = 0 := single_apply_eq_zero.mpr (\u03bb h, h.symm)\n\n/--  Here we see that (not-necessarily strict) monotonicity of addition on `lex (F \u2192\u2080 F)` is not\na consequence of monotonicity of addition on `F`.  Strict monotonicity of addition on `F` is\nenough and is the content of `finsupp.lex.covariant_class_le_left`. -/\nexample : \u00ac covariant_class (lex (F \u2192\u2080 F)) (lex (F \u2192\u2080 F)) (+) (\u2264) :=\nbegin\n  rintro \u27e8h\u27e9,\n  refine not_lt.mpr (h (single (0 : F) (1 : F)) (_ : single 1 1 \u2264 single 0 1)) \u27e81, _\u27e9,\n  { exact or.inr \u27e80, by simp [(by boom : \u2200 j : F, j < 0 \u2194 false)]\u27e9 },\n  { simp only [(by boom : \u2200 j : F, j < 1 \u2194 j = 0), of_lex_add, coe_add, pi.to_lex_apply,\n      pi.add_apply, forall_eq, f010, f1, eq_self_iff_true, f011, f111, zero_add, and_self] },\nend\n\nexample {\u03b1} [ring \u03b1] [nontrivial \u03b1] :\n  \u2203 f g : add_monoid_algebra \u03b1 F, f \u2260 0 \u2227 g \u2260 0 \u2227 f * g = 0 :=\nzero_divisors_of_periodic (1 : F) le_rfl (by simp [two_smul]) (z01.ne')\n\nexample {\u03b1} [has_zero \u03b1] : 2 \u2022 (single 0 1 : \u03b1 \u2192\u2080 F) = single 0 1 \u2227 (single 0 1 : \u03b1 \u2192\u2080 F) \u2260 0 :=\n\u27e8smul_single _ _ _, by simpa only [ne.def, single_eq_zero] using z01.ne\u27e9\n\nend F\n\n/-- A Type that does not have `unique_prods`. -/\nexample : \u00ac unique_prods \u2115 :=\nbegin\n  rintros \u27e8h\u27e9,\n  refine not_not.mpr (h (finset.singleton_nonempty 0) (finset.insert_nonempty 0 {1})) _,\n  suffices : (\u2203 (x : \u2115), (x = 0 \u2228 x = 1) \u2227 \u00acx = 0) \u2227 \u2203 (x : \u2115), (x = 0 \u2228 x = 1) \u2227 \u00acx = 1,\n  { simpa [unique_mul] },\n  exact \u27e8\u27e81, by simp\u27e9, \u27e80, by simp\u27e9\u27e9,\nend\n\n/-- Some Types that do not have `unique_sums`. -/\nexample (n : \u2115) (n2 : 2 \u2264 n): \u00ac unique_sums (zmod n) :=\nbegin\n  haveI : fintype (zmod n) := @zmod.fintype n \u27e8(zero_lt_two.trans_le n2).ne'\u27e9,\n  haveI : nontrivial (zmod n) := char_p.nontrivial_of_char_ne_one (one_lt_two.trans_le n2).ne',\n  rintros \u27e8h\u27e9,\n  refine not_not.mpr (h finset.univ_nonempty finset.univ_nonempty) _,\n  suffices : \u2200 (x y : zmod n), \u2203 (x' y' : zmod n), x' + y' = x + y \u2227 (x' = x \u2192 \u00acy' = y),\n  { simpa [unique_add] },\n  exact \u03bb x y, \u27e8x - 1, y + 1, sub_add_add_cancel _ _ _, by simp\u27e9,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/counterexamples/zero_divisors_in_add_monoid_algebras.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7492599548139098}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\n\nimport data.W.basic\n\n/-!\n# W types\n\nThe file `data/W.lean` shows that if `\u03b1` is an an encodable fintype and for every `a : \u03b1`,\n`\u03b2 a` is encodable, then `W \u03b2` is encodable.\n\nAs an example of how this can be used, we show that the type of propositional formulas with\nvariables labeled from an encodable type is encodable.\n\nThe strategy is to define a type of labels corresponding to the constructors.\nFrom the definition (using `sum`, `unit`, and an encodable type), Lean can infer\nthat it is encodable. We then define a map from propositional formulas to the\ncorresponding `Wfin` type, and show that map has a left inverse.\n\nWe mark the auxiliary constructions `private`, since their only purpose is to\nshow encodability.\n-/\n\n/-- Propositional formulas with labels from `\u03b1`. -/\ninductive prop_form (\u03b1 : Type*)\n| var : \u03b1 \u2192 prop_form\n| not : prop_form \u2192 prop_form\n| and : prop_form \u2192 prop_form \u2192 prop_form\n| or  : prop_form \u2192 prop_form \u2192 prop_form\n\n/-!\nThe next three functions make it easier to construct functions from a small\n`fin`.\n-/\n\nsection\nvariable {\u03b1 : Type*}\n\n/-- the trivial function out of `fin 0`. -/\ndef mk_fn0 : fin 0 \u2192 \u03b1\n| \u27e8_, h\u27e9 := absurd h dec_trivial\n\n/-- defines a function out of `fin 1` -/\ndef mk_fn1 (t : \u03b1) : fin 1 \u2192 \u03b1\n| \u27e80, _\u27e9   := t\n| \u27e8n+1, h\u27e9 := absurd h dec_trivial\n\n/-- defines a function out of `fin 2` -/\ndef mk_fn2 (s t : \u03b1) : fin 2 \u2192 \u03b1\n| \u27e80, _\u27e9   := s\n| \u27e81, _\u27e9   := t\n| \u27e8n+2, h\u27e9 := absurd h dec_trivial\n\nattribute [simp] mk_fn0 mk_fn1 mk_fn2\nend\n\nnamespace prop_form\n\nprivate def constructors (\u03b1 : Type*) := \u03b1 \u2295 unit \u2295 unit \u2295 unit\n\nlocal notation `cvar ` a := sum.inl a\nlocal notation `cnot`   := sum.inr (sum.inl unit.star)\nlocal notation `cand`   := sum.inr (sum.inr (sum.inr unit.star))\nlocal notation `cor`    := sum.inr (sum.inr (sum.inl unit.star))\n\n@[simp]\nprivate def arity (\u03b1 : Type*) : constructors \u03b1 \u2192 nat\n| (cvar a) := 0\n| cnot     := 1\n| cand     := 2\n| cor      := 2\n\nvariable {\u03b1 : Type*}\n\nprivate def f : prop_form \u03b1 \u2192 W_type (\u03bb i, fin (arity \u03b1 i))\n| (var a)   := \u27e8cvar a, mk_fn0\u27e9\n| (not p)   := \u27e8cnot, mk_fn1 (f p)\u27e9\n| (and p q) := \u27e8cand, mk_fn2 (f p) (f q)\u27e9\n| (or  p q) := \u27e8cor, mk_fn2 (f p) (f q)\u27e9\n\nprivate def finv : W_type (\u03bb i, fin (arity \u03b1 i)) \u2192 prop_form \u03b1\n| \u27e8cvar a, fn\u27e9 := var a\n| \u27e8cnot, fn\u27e9   := not (finv (fn \u27e80, dec_trivial\u27e9))\n| \u27e8cand, fn\u27e9   := and (finv (fn \u27e80, dec_trivial\u27e9)) (finv (fn \u27e81, dec_trivial\u27e9))\n| \u27e8cor, fn\u27e9    := or  (finv (fn \u27e80, dec_trivial\u27e9)) (finv (fn \u27e81, dec_trivial\u27e9))\n\ninstance [encodable \u03b1] : encodable (prop_form \u03b1) :=\nbegin\n  haveI : encodable (constructors \u03b1),\n  { unfold constructors, apply_instance },\n  exact encodable.of_left_inverse f finv\n    (by { intro p, induction p; simp [f, finv, *] })\nend\n\nend prop_form\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/examples/prop_encodable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7492599481536574}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Jason Kexing Ying, Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport measure_theory.integral.bochner\n--import probability.martingale.basic -- note to self: surely too much\n\n/-\n\n# Measures\n\nRecall that Lean calls a space equipped with\na sigma algebra a \"measurable_space\". We will go with this language\nand call sets in the sigma algebra \"measurable sets\".\n\nGiven a measurable space, a *measure* on the measurable space is a function from\nthe measurable sets to `[0,\u221e]` which is countably additive (i.e.,\nthe measure of a countable disjoint union of measurable sets is the sum of the measures).\nThis is not the *definition* of a measure in Lean, but it is mathematically equivalent to the\ndefinition. \n\nFor what it's worth, the actual definition of a measure in Lean is this: an `outer_measure`\non a type `\u03b1` is this:\n\n```\nstructure outer_measure (\u03b1 : Type*) :=\n(measure_of : set \u03b1 \u2192 \u211d\u22650\u221e)\n(empty : measure_of \u2205 = 0)\n(mono : \u2200{s\u2081 s\u2082}, s\u2081 \u2286 s\u2082 \u2192 measure_of s\u2081 \u2264 measure_of s\u2082)\n(Union_nat : \u2200(s:\u2115 \u2192 set \u03b1), measure_of (\u22c3i, s i) \u2264 \u2211'i, measure_of (s i))\n```\n\nSo it attaches an element of `[0,\u221e]` to *every* subset of \u03b1, satisfying some natural axioms;\nnote in particular it is countably *sub*additive, meaning that the measure of a countable\nunion of open sets, even if they're pairwise disjoint, is only assumed to be at most the sum of the measures.\n\nAnd if `\u03b1` has a measurable space structure then a measure on `\u03b1` is an outer measure satisfying\nsome axioms, which boil down to \"the restriction of the outer measure is a measure on the measurable\nsets, and the extension of this measure to an outer measure agrees with the outer measure we started with\".\nThe advantage of doing it this way is that given a measure, we can evaluate it on *any* subset\n(getting the outer measure of the subset) rather than having to supply a proof that the subset\nis measurable. This coincides with Lean's \"make functions total\" philosophy (the same reason that 1/0=0).\n\n-/\n\nopen filter\nopen_locale nnreal ennreal measure_theory big_operators topological_space\n-- note to self: removed `probability_theory`\n\nnamespace measure_theory\n\n-- Let \u03a9 be a set equipped with a sigma algebra.\nvariables {\u03a9 : Type} [measurable_space \u03a9]\n\n-- Now let's add a measure `\u03bc` on `\u03a9`\nvariables {\u03bc : measure \u03a9}\n\n/-\nTry proving the following:\n-/\n\nexample (S T : set \u03a9) (hS : \u03bc S \u2260 \u221e) (hT : measurable_set T) : \n  \u03bc (S \u222a T) = \u03bc S + \u03bc T - \u03bc (S \u2229 T) :=\nbegin\n  rw \u2190 measure_union_add_inter S hT,\n  rw ennreal.add_sub_cancel_right,\n  apply ne_top_of_le_ne_top hS,\n  apply outer_measure.mono,\n  exact set.inter_subset_left S T,\nend\n\n/-\n*Remark*: while proving the above, you might have noticed I've added the \ncondition `hS` (think about what is a + \u221e - \u221e). In particular, subtraction in \nextended non-negative reals (`\u211d\u22650\u221e`) might not be what you expect, \ne.g. 1 - 2 = 0 in `\u211d\u22650\u221e`. For this reason, the above lemma is better phrased as \n`\u03bc (S \u222a T) + \u03bc (S \u2229 T) = \u03bc S + \u03bc T` for which we can omit the condition `hS`.\n-/\n\n/-! \n## Measurable functions\n\nSo far we've worked in the space `\u03a9` though with all mathematical objects, we \nwant to map between them. In measure theory, the correct notion of maps is \nmeasurable functions. If you have seen continuity in topology, they are quite \nsimilar, namely, a function `f` between two measurable spaces is said to be \nmeasurable if the preimages of all measurable sets along `f` is measurable. \n-/\n\n\n\n/-\nIf you go to the definition of measurable you will find what you expect. \nHowever, of course, measure theory in Lean is a bit more complicated. As we \nshall see, in contrast to maths, there are 3 additional notions of measurability \nin mathlib. These are: \n- `ae_measurable`\n- `strongly_measurable`\n- `ae_strongly_measurable`\nThe reasons for their existence is technical but TLDR: `ae_foo f` is the predicate \nthat `f` is almost everywhere equal to some function satisfying `foo` (see the \na.e. filter section) while `strongly_measurable f` is saying `f` is the limit \nof a sequence of simple functions.\n\nAlongside `measurable`, we also see them quite often in the mathlib, although \nall you have to know is in most cases (range is metrizable and second-countable), \n`measurable` and `strongly_measurable` are equivalent.\n-/\n\nexample : measurable (id : \u03a9 \u2192 \u03a9) :=\nbegin\n  intros U hU,\n  exact hU,\nend\n\n\n\nexample {X Y Z : Type} [measurable_space X] [measurable_space Y] [measurable_space Z]\n  (f : X \u2192 Y) (g : Y \u2192 Z) (hg : measurable g) (hf : measurable f) :\n  measurable (g \u2218 f) :=\nbegin\n  intros U hU,\n  replace hg := hg hU,\n  exact hf hg,\nend\n\n\n\n/-!\n## Integration\n\nOne of the primary motivations of measure theory is to introduce a more \nsatisfactory theory of integration. If you recall the definition of the \nDarboux-Riemann integral, we cannot integrate the indicator function of \n`\u211a \u2229 [0, 1]` despite, intuitively, the set of rationals in the unit interval \nis much \"smaller\" (rationals is countable while the irrationals are not. \nIn contrast, measure theory allows us to construct the Lebesgue integral \nwhich can deal with integrals such as this one. \n\nLean uses a even more general notion of integration known as Bochner integration \nwhich allows us to integrate Banach-space valued functions. Its construction \nis similar to the Lebesgue integral. \n\nRead page 5-6 of https://arxiv.org/pdf/2102.07636.pdf\nif you want to know the details.\n-/\n\n-- Suppose now `X` is another measurable space\nvariables {X : Type} [measurable_space X] \n\n-- and suppose it's also a Banach space (i.e. a vector space and a complete metric space)\nvariables [normed_add_comm_group X] [normed_space \u211d X] [complete_space X]\n\n-- If `f : \u03a9 \u2192 X` is a function, then the integral of `f` is written as \n-- `\u222b x, f x \u2202\u03bc`. If you want to integrate over the set `s : set \u03a9` then write \n-- `\u222b x in s, f x \u2202\u03bc`.\n\n-- Try looking in mathlib\nexample {f g : \u03a9 \u2192 X} (hf : integrable f \u03bc) (hg : integrable g \u03bc) : \n  \u222b x, f x + g x \u2202\u03bc = \u222b x, f x \u2202\u03bc + \u222b x, g x \u2202\u03bc :=\nbegin\n  apply integral_add hf hg,\nend\n\nexample (a : X) (s : set \u03a9) : \u222b x in s, a \u2202\u03bc = (\u03bc s).to_real \u2022 a :=\nbegin\n  rw integral_const,\n  congr' 2,\n  rw measure.restrict_apply,\n  { simp },\n  { simp },\nend\n\n-- Harder\nexample {f : \u03a9 \u2192 \u211d} (hf : measurable f) (hint : integrable f \u03bc)\n  (h\u03bc : 0 < \u03bc {\u03c9 | 0 < f \u03c9}) : \n  (0 : \u211d) < \u222b \u03c9 in {\u03c9 | 0 < f \u03c9}, f \u03c9 \u2202\u03bc :=\nbegin\n  sorry\nend\n\n/-\n*Remark* It's a common myth that Lebesgue integration is strictly better than \nthe Darboux-Riemann integral. This is true for integration on bounded intervals \nthough it is not true when considering improper integrals. A common example \nfor this is, while `\u222b x in [0, \u221e), sin x / x dx` is Darboux-Riemann integrable \n(in fact it equals `\u03c0 / 2`) it is not Lebesgue integrable as \n`\u222b x in [0, \u221e), |sin x / x| dx = \u221e`.\n-/\n\n/-! \n## ae filter\n\nNow we have come to a very important section of working with measure theory \nin Lean.\n\nIn measure theory we have a notion known as almost everywhere (a.e.). In \nprobability this is known as almost surely however we will stick with \nalmost everywhere in this project. Namely, a predicate `P` on `\u03a9` is said to \nbe true almost everywhere if the set for which `P` holds is co-null, i.e. \n`\u03bc {\u03c9 : \u03a9 | P \u03c9}\u1d9c = 0`. \n\nAs examples, we say:\n- given functions `f, g`, `f` equals `g` a.e. if `\u03bc {\u03c9 : \u03a9 | f \u03c9 \u2260 g \u03c9} = 0`;\n- `f` is less equal to `g` a.e. if `\u03bc {\u03c9 : \u03a9 | \u00ac f \u03c9 \u2264 g \u03c9} = 0` etc.\n\nOften, showing that a property holds a.e. is the best we can do in \nmeasure/probability theory. \n\nIn Lean, the notion of a.e. is handled by the `measure.ae` filter.\nLet's construct that filter ourselves.\n-/\n\nexample (X : Type) [measurable_space X] (\u03bc : measure X) : filter X :=\n{ sets := {U | \u03bc U\u1d9c = 0},\n  univ_sets := begin\n    simp only [set.mem_set_of_eq, set.compl_univ, measure_empty],\n  end,\n  sets_of_superset := begin\n    rintro S T (hS : \u03bc S\u1d9c = 0) hST,\n    change \u03bc T\u1d9c = 0,\n    apply measure_mono_null _ hS,\n    exact set.compl_subset_compl.mpr hST,\n  end,\n  inter_sets := begin\n    intros S T hS hT,\n    rw set.mem_set_of at hS hT \u22a2,\n    rw set.compl_inter,\n    rw \u2190 le_zero_iff,\n    apply le_trans (measure_union_le _ _),\n    rw [hS, hT],\n    norm_num,\n  end }\n\n\n-- say `f` and `g` are measurable functions `\u03a9 \u2192 X`\nvariables (f g : \u03a9 \u2192 X)\n-- The following is a proposition that `f` and `g` are almost everywhere equal\n-- it's **not** a proof that `f` and `g` are a.e. equal but simply a statement\nexample : Prop := \u2200\u1d50 \u03c9 \u2202\u03bc, f \u03c9 = g \u03c9\n\n-- Here's another example on how to state `f` is almost everywhere less equal \n-- than `g`\n-- To be able to formulate this we need a notion of inequality on `X` so we \n-- will add the `has_le` instance on `X`, i.e. equip `X` with a inequality \nexample [has_le X] : Prop := \u2200\u1d50 \u03c9 \u2202\u03bc, f \u03c9 \u2264 g \u03c9\n\n-- Since the above two cases come up quite often, there are special notations \n-- for them. See if you can guess what they mean\nexample : Prop := f =\u1d50[\u03bc] g \nexample [has_le X] : Prop := f \u2264\u1d50[\u03bc] g\n\n-- In general, if `P : \u03a9 \u2192 Prop` is a predicate on `\u03a9`, we write `\u2200\u1d50 \u03c9 \u2202\u03bc, P \u03c9` \n-- for the statement that `P` holds a.e.\nexample (P : \u03a9 \u2192 Prop) : Prop := \u2200\u1d50 \u03c9 \u2202\u03bc, P \u03c9\n\n-- Sanity check: the above notation actually means what we think\nexample (P : \u03a9 \u2192 Prop) : (\u2200\u1d50 \u03c9 \u2202\u03bc, P \u03c9) \u2194 \u03bc {\u03c9 | P \u03c9}\u1d9c = 0 := \nbegin\n  refl,\nend\n\n-- Heres a more convoluted example. See if you can figure what it means\nexample (f : \u2115 \u2192 \u03a9 \u2192 \u211d) (s : set \u03a9) := \n  \u2200\u1d50 \u03c9 \u2202\u03bc.restrict s, \u2203 l : \u211d, tendsto (\u03bb n, f n \u03c9) at_top (\ud835\udcdd l)\n\n-- Now to do some exercises: you will need to dig into the source code to see \n-- what the definitions are and search for helpful lemmas\n-- *Hint*: try out the `measurability` tactic. It should be able to solve simple \n-- goals of the form `measurable_set s` and `measurable f`\nexample (s : set \u03a9) (f g : \u03a9 \u2192 \u211d)\n  (hf : measurable f) (hg : measurable g) (hfg : \u2200 \u03c9 \u2208 s, f \u03c9 = g \u03c9) : \n  f =\u1d50[\u03bc.restrict s] g :=\nbegin\n  unfold eventually_eq filter.eventually,\n  rw mem_ae_iff,\n  rw measure.restrict_apply,\n  { convert measure_empty,\n    rw set.eq_empty_iff_forall_not_mem,\n    rintro x \u27e8hx1, hx2\u27e9,\n    apply hx1,\n    apply hfg _ hx2, },\n  { measurability, },\nend\n\nexample (f g h : \u03a9 \u2192 \u211d) (h\u2081 : f \u2264\u1d50[\u03bc] g) (h\u2082 : f \u2264\u1d50[\u03bc] h) : \n  2 * f \u2264\u1d50[\u03bc] g + h :=\nbegin\n  convert eventually_le.add_le_add h\u2081 h\u2082,\n  rw two_mul,\nend\n\nexample (f g : \u03a9 \u2192 \u211d) (h : f =\u1d50[\u03bc] g) (hg : \u2200\u1d50 \u03c9 \u2202\u03bc, 2 * g \u03c9 + 1 \u2264 0) :\n  \u2200\u1d50 \u03c9 \u2202\u03bc, f \u03c9 \u2264 -1/2 :=\nbegin\n  filter_upwards [h, hg],\n  rintro a ha hg,\n  rw ha,\n  linarith,\nend\n\nexample (f g : \u2115 \u2192 \u03a9 \u2192 \u211d) (a b : \u211d) \n  (hf : \u2200\u1d50 \u03c9 \u2202\u03bc, tendsto (\u03bb n, f n \u03c9) at_top (\ud835\udcdd a))\n  (hg : \u2200\u1d50 \u03c9 \u2202\u03bc, tendsto (\u03bb n, g n \u03c9) at_top (\ud835\udcdd b)) :\n  \u2200\u1d50 \u03c9 \u2202\u03bc, tendsto (\u03bb n, f n \u03c9 + g n \u03c9) at_top (\ud835\udcdd (a + b)) :=\nbegin\n  filter_upwards [hf, hg],\n  intros \u03c9 h1 h2,\n  convert tendsto.comp tendsto_add _, swap, exact (\u03bb n, (f n \u03c9, g n \u03c9)), refl,\n  { apply_instance, },\n  rw nhds_prod_eq,\n  rw tendsto_prod_iff',\n  exact \u27e8h1, h2\u27e9, \nend\n\n/- \nI hope that you found the above examples slightly annoying, especially the \nthird example: why can't we just `rw h`?! Of course, while we often do do so on \npaper, rigourously, such a rewrite require some logic. Luckily, what we normally \ndo on paper is most often ok and we would like to do so in Lean as well. While \nwe can't directly rewrite almost everywhere equalities, we have the next best \nthing: the `filter_upwards` tactic. See the tactic documentation here: \nhttps://leanprover-community.github.io/mathlib_docs/tactics.html#filter_upwards\n\nThe `filter_upwards` tactic is much more powerful than simply rewritting a.e. \nequalities and is helpful in many situtations, e.g. the above second, third \nand fourth examples are all easily solvable with this tactic. Let us see how \nit works in action.\n-/\n\n-- Hover over each line and see how the goal changes\nexample (f\u2081 f\u2082 g\u2081 g\u2082 : \u03a9 \u2192 \u211d) (h\u2081 : f\u2081 \u2264\u1d50[\u03bc] g\u2081) (h\u2082 : f\u2082 \u2264\u1d50[\u03bc] g\u2082) : \n  f\u2081 + f\u2082 \u2264\u1d50[\u03bc] g\u2081 + g\u2082 :=\nbegin\n  filter_upwards [h\u2081, h\u2082],\n  intros \u03c9 h\u03c9\u2081 h\u03c9\u2082,\n  exact add_le_add h\u03c9\u2081 h\u03c9\u2082,\nend\n\n-- Heres an even shorter proof using additional parameters of `filter_upwards`\nexample (f\u2081 f\u2082 g\u2081 g\u2082 : \u03a9 \u2192 \u211d) (h\u2081 : f\u2081 \u2264\u1d50[\u03bc] g\u2081) (h\u2082 : f\u2082 \u2264\u1d50[\u03bc] g\u2082) : \n  f\u2081 + f\u2082 \u2264\u1d50[\u03bc] g\u2081 + g\u2082 :=\nbegin\n  filter_upwards[h\u2081, h\u2082] with \u03c9 h\u03c9\u2081 h\u03c9\u2082 using add_le_add h\u03c9\u2081 h\u03c9\u2082,\nend\n\n/-\nIntuitively, what `filter_upwards` is doing is simply exploiting the fact that \nthe intersection of two full measure sets (i.e. complements are null) is also \na set of full measure. Thus, it suffices to work in their intersection instead. \n\nNow, try the above examples again using the `filter_upwards` tactic.\n-/\n\nend measure_theory", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section12measure_theory/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541602070126, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7492347531827708}}
{"text": "-- Prove \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq\nexample (p q : Prop) : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n\u27e8\u03bb h, \u27e8\u03bb hp, h (or.inl hp), \u03bb hq, h (or.inr hq)\u27e9, \n\u03bb hn h, or.elim h hn.1 hn.2\u27e9\n\n-- Page 83\n-- Prove (A \u2227 B) \u2192 (B \u2227 A)\nexample (A B : Prop) : (A \u2227 B) \u2192 (B \u2227 A) :=\n\u03bb \u27e8A, B\u27e9, \u27e8B, A\u27e9 \n\n\nexample (A B : Prop) : (A \u2227 B) \u2192 (B \u2227 A) :=\n\u03bb p : A \u2227 B, \u27e8and.right p, and.left p\u27e9\n\nexample (A B : Prop) : (A \u2227 B) \u2192 (B \u2227 A) :=\n\u03bb p, and.intro (and.right p) (and.left p)\n\n-- Prove (((A \u2228 B) \u2192 C) \u2227 A) \u2192 C\nexample (A B C : Prop) : (((A \u2228 B) \u2192 C) \u2227 A) \u2192 C :=\n\u03bb qr, (and.left qr) (or.inl (and.right qr))\n\n-- Prove (((A \u2228 B) \u2192 C) \u2227 A) \u2192 C, second example, closer to Thompson book\nexample (A B C : Prop) : (((A \u2228 B) \u2192 C) \u2227 A) \u2192 C :=\n\u03bb \u27e8q, r\u27e9, q (or.inl r)\n\n\n-- Page 90\n-- 4.1. Show that conjunction is associative by deriving a proof of the formula\n-- (A \u2227 B) \u2227 C \u2192 A \u2227 (B \u2227 C)\nexample (A B C : Prop) : (A \u2227 B) \u2227 C \u2192 A \u2227 (B \u2227 C) :=\n\u03bb p, \u27e8and.left (and.left p), \u27e8and.right (and.left p), and.right p\u27e9\u27e9\n\nexample (A B C : Prop) : (A \u2227 B) \u2227 C \u2192 A \u2227 (B \u2227 C) :=\n\u03bb p, \u27e8and.left (and.left p), and.right (and.left p), and.right p\u27e9\n\nexample (A B C : Prop) : (A \u2227 B) \u2227 C \u2192 A \u2227 (B \u2227 C) :=\n\u03bb p, and.intro (and.left (and.left p)) (and.intro (and.right (and.left p)) (and.right p))\n\n-- 4.2. A) Show that the formula (\u00acA \u2228 B) \u2192 (A \u2192 B) is valid by exhibiting a proof object for it.\nexample (A B : Prop) : (\u00acA \u2228 B) \u2192 (A \u2192 B) :=\n\u03bb p, or.elim p\n(\u03bb na, \u03bb a, absurd a na)\n(\u03bb b, \u03bb a, b)\n\nexample (A B : Prop) : (\u00acA \u2228 B) \u2192 (A \u2192 B) :=\nassume hnab : \u00acA \u2228 B,\nor.elim hnab\n(assume hna : \u00acA,\nassume ha : A,\nshow B, from absurd ha hna)\n(assume hb : B,\nassume ha : A,\nshow B, from hb)\n\nexample (A B : Prop) : (\u00acA \u2228 B) \u2192 (A \u2192 B) :=\nassume hnab : \u00acA \u2228 B,\nor.elim hnab\n(assume hna : \u00acA,\nassume ha : A,\nshow B, from false.elim (hna ha))\n(assume hb : B,\nassume ha : A,\nshow B, from hb)\n\n\n-- 4.2 B) Do you expect the converse, (A \u2192 B) \u2192 (\u00acA \u2228 B), to be provable?\n\n\n-- 4.3. A) Show that from the assumption x : (A \u2228 \u00acA) that you can derive a\n-- proof object for the formula (\u00ac\u00acA \u2192 A). \nexample (A : Prop) : (A \u2228 \u00acA) \u2192 (\u00ac\u00acA \u2192 A) :=\n\u03bb hana, or.elim hana\n(\u03bb ha, \u03bb hna, ha)\n(\u03bb hna, \u03bb hnna, absurd hna hnna)\n\nexample (A : Prop) : (A \u2228 \u00acA) \u2192 (\u00ac\u00acA \u2192 A) :=\nassume hana : (A \u2228 \u00acA),\nor.elim hana\n(assume ha : A,\nassume hna : \u00ac\u00acA, show A, from ha)\n(assume hna : \u00acA,\nassume hnna : \u00ac\u00acA, show A, from false.elim (hnna hna))\n\n-- 4.3 B) Show that you can find a proof\n-- object for the converse, (A \u2192 \u00ac\u00acA) without this assumption.\nexample (A : Prop): (A \u2192 \u00ac\u00acA) :=\nassume ha : A,\nassume hna : \u00acA, show false, from hna ha\n\nexample (A : Prop): (A \u2192 \u00ac\u00acA) :=\nassume ha : A,\nassume hna : \u00acA, absurd ha hna\n\n-- 4.4. Show that from the assumptions x : ((A \u2227 B) \u2192 C) and y : A you\n-- can derive a proof of B \u2192 C.\nexample (A B C : Prop) : ((A \u2227 B) \u2192 C) \u2227 A \u2192 (B \u2192 C) :=\n\u03bb x, \u03bb y, x.left (and.intro x.right y)\n\nexample (A B C : Prop) : ((A \u2227 B) \u2192 C) \u2227 A \u2192 (B \u2192 C) :=\nassume habc,\nassume hb, show  C, from habc.left (and.intro habc.right hb)\n\n-- 4.5. Given a function of type A \u2192 (B \u2192 C) how would you define a\n-- function of type (A \u2227 B) \u2192 C from it? How would you do the reverse?\n-- A)\nexample (A B C : Prop) : (A \u2192 (B \u2192 C)) \u2192 ((A \u2227 B) \u2192 C) :=\nassume habc,\nassume hab, show C, from  (habc (and.left hab)) (and.right hab)\n\nexample (A B C : Prop) : (A \u2192 (B \u2192 C)) \u2192 ((A \u2227 B) \u2192 C) :=\n\u03bb abc, \u03bb ab, show C, from (abc ab.left) ab.right\n\n-- B) How would you do the reverse?\nexample (A B C : Prop) : ((A \u2227 B) \u2192 C) \u2192 (A \u2192 (B \u2192 C)) :=\nassume habc,\nassume ha,\nassume hb, show C, from habc (and.intro ha hb)\n\nexample (A B C : Prop) : ((A \u2227 B) \u2192 C) \u2192 (A \u2192 (B \u2192 C)) :=\n\u03bb habc, \u03bb ha, \u03bb hb, habc (and.intro ha hb)\n\n-- 4.6. Show that from objects x : A and y : (B \u2228 C) you can derive an object\n-- of type (A \u2227 B) \u2228 (A \u2227 C).\nexample (A B C : Prop) : (A \u2227 (B \u2228 C)) \u2192 ((A \u2227 B) \u2228 (A \u2227 C)) :=\nassume habc,\nshow (A \u2227 B) \u2228 (A \u2227 C), from\n(or.elim (and.right habc)\n(assume hb, or.inl (and.intro (and.left habc) hb))\n(assume hc, or.inr (and.intro (and.left habc) hc)))\n\nexample (A B C : Prop) : (A \u2227 (B \u2228 C)) \u2192 ((A \u2227 B) \u2228 (A \u2227 C)) :=\n\u03bb habc,\n(or.elim (and.right habc)\n  (\u03bb  hb, or.inl (and.intro (and.left habc) hb))\n  (\u03bb  hc, or.inr (and.intro (and.left habc) hc)))\n\n-- 4.7. Show how to define a function of type\n-- (A \u2227 B) \u2192 (C \u2227 D)\n-- from functions f : A \u2192 C and g : B \u2192 D.\nexample (A B C D : Prop): (A \u2227 B) \u2192 (C \u2227 D) :=\n\u03bb x: (A \u2227 B), and.intro (sorry) (sorry)\n\nexample (A B C D : Prop): (A \u2227 B) \u2192 (A \u2192 C) \u2192 (B \u2192 D) \u2192 (C \u2227 D) :=\n\u03bb x: (A \u2227 B), \u03bb f : (A \u2192 C), \u03bb g: (B \u2192 D), and.intro (f x.left)(g x.right)\n\n-- 4.8. Show that the following formulas are valid, by giving a proof object\n-- for each of them.\n-- A) A \u2192 \u00ac\u00acA\nexample (A : Prop): A \u2192 \u00ac\u00acA :=\nassume ha,\nshow \u00ac\u00acA, from (assume hna, show false, from false.elim (hna ha))\n\nexample (A : Prop): A \u2192 \u00ac\u00acA :=\n\u03bb ha, \u03bb hna, false.elim (hna ha)\n\n-- B) (B \u2228 C) \u2192 \u00ac(\u00acB \u2227 \u00acC)\nexample (B C : Prop): (B \u2228 C) \u2192 \u00ac(\u00acB \u2227 \u00acC) :=\nassume hbc : B \u2228 C,\nassume hnbnc : \u00acB \u2227 \u00acC,\nor.elim hbc\n(assume hb : B, show false, from false.elim ((and.left hnbnc) hb))\n(assume hc : C, show false, from false.elim ((and.right hnbnc) hc))\n\nexample (B C : Prop): (B \u2228 C) \u2192 \u00ac(\u00acB \u2227 \u00acC) :=\n\u03bb hbc : B \u2228 C,\n\u03bb hnbnc : \u00acB \u2227 \u00acC,\nor.elim hbc\n(\u03bb hb : B, false.elim ((and.left hnbnc) hb))\n(\u03bb hc : C, false.elim ((and.right hnbnc) hc))\n\n-- C) (A \u2192 B) \u2192 ((A \u2192 C) \u2192 (A \u2192 (B \u2227 C)))\nexample (A B C : Prop): (A \u2192 B) \u2192 ((A \u2192 C) \u2192 (A \u2192 (B \u2227 C))) :=\nassume hab : A \u2192 B,\nassume hac : A \u2192 C,\nassume ha : A, show B \u2227 C, from and.intro (hab ha) (hac ha)\n\nexample (A B C : Prop): (A \u2192 B) \u2192 ((A \u2192 C) \u2192 (A \u2192 (B \u2227 C))) :=\n\u03bb hab : A \u2192 B,\n\u03bb hac : A \u2192 C,\n\u03bb ha : A, and.intro (hab ha) (hac ha)\n\n-- 4.9. Show that the following formulas are equivalent\n-- (A \u2227 B) \u2192 C    A \u2192 (B \u2192 C)\nexample (A B C : Prop): (A \u2227 B) \u2192 C \u2194 A \u2192 (B \u2192 C) :=\niff.intro\n(assume habc, show A \u2192 B \u2192 C, from\n  assume ha,\n  assume hb,\nshow C, from habc (and.intro ha hb))\n(assume habc, show A \u2227 B \u2192 C, from\n  assume hab,\n  have ha : A, from and.left hab,\n  have hb : B, from and.right hab,\n  show C, from (habc ha) hb)\n\nexample (A B C : Prop): (A \u2227 B) \u2192 C \u2194 A \u2192 (B \u2192 C) :=\n\u27e8 \u03bb habc, \u03bb ha, \u03bb hb, habc (and.intro ha hb)\n  ,\n  \u03bb habc, \u03bb hab, habc (and.left hab) (and.right hab)\n\u27e9\n\n-- 4.10. Show that the de Morgan formula\n-- (\u00acA \u2228 \u00acB) \u2192 \u00ac(A \u2227 B)\n-- is valid by giving an object of type\n-- ((A \u2192 C) \u2228 (B \u2192 C)) \u2192 ((A \u2227 B) \u2192 C)\nexample (A B C : Prop): ((A \u2192 C) \u2228 (B \u2192 C)) \u2192 ((A \u2227 B) \u2192 C) :=\nassume hacbc, show (A \u2227 B) \u2192 C, from\n  assume hab, show C, from\n  or.elim hacbc\n  (assume hac, show C, from hac (and.left hab))\n  (assume hbc, show C, from hbc (and.right hab))\n\nexample (A B C : Prop): ((A \u2192 C) \u2228 (B \u2192 C)) \u2192 ((A \u2227 B) \u2192 C) :=\n\u03bb hacbc, \u03bb hab, or.elim hacbc\n  (\u03bb hac, hac (and.left hab))\n  (\u03bb hbc, hbc (and.right hab))\n\n\n-- 4.12. Give a derivation of a proof object of the formula\n-- (\u2203x : X).\u00acP \u2192 \u00ac(\u2200x : X).P\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample (h : \u2203 x, \u00acp x) : \u00ac\u2200 x, p x :=\n  (assume h1 : \u2200 x, p x,\n    have h2 : \u2200 x, \u00ac p x, from\n      assume x,\n      assume h3 : p x,\n      have h4 : \u2203 x, p x, from  \u27e8x, h3\u27e9,\n      show false, from h1 h4,\n    show false, from h h2)\n\nexample (h : \u2203 x, \u00acp x) : \u00ac\u2200 x, p x :=\n  (assume h1 : \u2200 x, p x,\n      assume y : \u03b1,\n      have  h2 : p y, from  h1 y,\n      show false, from sorry)\n\nexample (h : \u2203 x, \u00acp x) : \u00acp \u03b1 :=\n      assume y : \u03b1,\n      show false, from (sorry)\n", "meta": {"author": "JoseBalado", "repo": "lean-notes", "sha": "0b579f83988cc844ac1ff0592d885061959a852e", "save_path": "github-repos/lean/JoseBalado-lean-notes", "path": "github-repos/lean/JoseBalado-lean-notes/lean-notes-0b579f83988cc844ac1ff0592d885061959a852e/Type_Theory_and_Functional_Programming.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7491932517398964}}
{"text": "import .lovelib\n\n\n/- # LoVe Demo 4: Functional Programming\n\nWe take a closer look at the basics of typed functional programming: inductive\ntypes, proofs by induction, recursive functions, pattern matching, structures\n(records), and type classes. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Inductive Types\n\nRecall the definition of type `nat` (= `\u2115`): -/\n\n#print nat\n\n/- Mottos:\n\n* **No junk**: The type contains no values beyond those expressible using the\n  constructors.\n\n* **No confusion**: Values built in a different ways are different.\n\nFor `nat` (= `\u2115`):\n\n* \"No junk\" means that there are no special values, say, `\u20131` or `\u03b5`, that\n  cannot be expressed using a finite combination of `zero` and `succ`.\n\n* \"No confusion\" is what ensures that `zero` \u2260 `succ x`.\n\nIn addition, inductive types are always finite. `succ (succ (succ \u2026))` is not a\nvalue.\n\n\n## Structural Induction\n\n__Structural induction__ is a generalization of mathematical induction to\ninductive types. To prove a property `P[n]` for all natural numbers `n`, it\nsuffices to prove the base case\n\n    `P[0]`\n\nand the induction step\n\n    `\u2200k, P[k] \u2192 P[k + 1]`\n\nFor lists, the base case is\n\n    `P[[]]`\n\nand the induction step is\n\n    `\u2200y ys, P[ys] \u2192 P[y :: ys]`\n\nIn general, there is one subgoal per constructor, and induction hypotheses are\navailable for all constructor arguments of the type we are doing the induction\non. -/\n\nlemma nat.succ_neq_self (n : \u2115) :\n  nat.succ n \u2260 n :=\nbegin\n  induction' n,\n  { simp },\n  { simp [ih] }\nend\n\n/- The `case` tactic can be used to supply custom names, and potentially\nreorder the cases. -/\n\nlemma nat.succ_neq_self\u2082 (n : \u2115) :\n  nat.succ n \u2260 n :=\nbegin\n  induction' n,\n  case succ : m IH {\n    simp [IH] },\n  case zero {\n    simp }\nend\n\n\n/- ## Structural Recursion\n\n__Structural recursion__ is a form of recursion that allows us to peel off\none or more constructors from the value on which we recurse. Such functions are\nguaranteed to call themselves only finitely many times before the recursion\nstops. This is a prerequisite for establishing that the function terminates. -/\n\ndef fact : \u2115 \u2192 \u2115\n| 0       := 1\n| (n + 1) := (n + 1) * fact n\n\ndef fact\u2082 : \u2115 \u2192 \u2115\n| 0       := 1\n| 1       := 1\n| (n + 1) := (n + 1) * fact\u2082 n\n\n/- For structurally recursive functions, Lean can automatically prove\ntermination. For more general recursive schemes, the termination check may fail.\nSometimes it does so for a good reason, as in the following example: -/\n\n-- fails\ndef illegal : \u2115 \u2192 \u2115\n| n := illegal n + 1\n\nconstant immoral : \u2115 \u2192 \u2115\n\naxiom immoral_eq (n : \u2115) :\n  immoral n = immoral n + 1\n\nlemma proof_of_false :\n  false :=\nhave immoral 0 = immoral 0 + 1 :=\n  immoral_eq 0,\nhave immoral 0 - immoral 0 = immoral 0 + 1 - immoral 0 :=\n  by cc,\nhave 0 = 1 :=\n  by simp [*] at *,\nshow false, from\n  by cc\n\n\n/- ## Pattern Matching Expressions\n\n    `match` _term\u2081_, \u2026, _termM_ `with`\n    | _pattern\u2081\u2081_, \u2026, _pattern\u2081M_ := _result\u2081_\n        \u22ee\n    | _patternN\u2081_, \u2026, _patternNM_ := _resultN_\n    `end`\n\n`match` allows nonrecursive pattern matching within terms.\n\nIn contrast to pattern matching after `lemma` or `def`, the patterns are\nseparated by commas, so parentheses are optional. -/\n\ndef bcount {\u03b1 : Type} (p : \u03b1 \u2192 bool) : list \u03b1 \u2192 \u2115\n| []        := 0\n| (x :: xs) :=\n  match p x with\n  | tt := bcount xs + 1\n  | ff := bcount xs\n  end\n\ndef min (a b : \u2115) : \u2115 :=\nif a \u2264 b then a else b\n\n\n/- ## Structures\n\nLean provides a convenient syntax for defining records, or structures. These are\nessentially nonrecursive, single-constructor inductive types. -/\n\nstructure rgb :=\n(red green blue : \u2115)\n\n#check rgb.mk\n#check rgb.red\n#check rgb.green\n#check rgb.blue\n\nnamespace rgb_as_inductive\n\ninductive rgb : Type\n| mk : \u2115 \u2192 \u2115 \u2192 \u2115 \u2192 rgb\n\ndef rgb.red : rgb \u2192 \u2115\n| (rgb.mk r _ _) := r\n\ndef rgb.green : rgb \u2192 \u2115\n| (rgb.mk _ g _) := g\n\ndef rgb.blue : rgb \u2192 \u2115\n| (rgb.mk _ _ b) := b\n\nend rgb_as_inductive\n\nstructure rgba extends rgb :=\n(alpha : \u2115)\n\n#print rgba\n\ndef pure_red : rgb :=\n{ red   := 0xff,\n  green := 0x00,\n  blue  := 0x00 }\n\ndef semitransparent_red : rgba :=\n{ alpha := 0x7f,\n  ..pure_red }\n\n#print pure_red\n#print semitransparent_red\n\ndef shuffle (c : rgb) : rgb :=\n{ red   := rgb.green c,\n  green := rgb.blue c,\n  blue  := rgb.red c }\n\n/- `cases'` performs a case distinction on the specified term. This gives rise\nto as many subgoals as there are constructors in the definition of the term's\ntype. The tactic behaves the same as `induction'` except that it does not\nproduce induction hypotheses. -/\n\nlemma shuffle_shuffle_shuffle (c : rgb) :\n  shuffle (shuffle (shuffle c)) = c :=\nbegin\n  cases' c,\n  refl\nend\n\nlemma shuffle_shuffle_shuffle\u2082 (c : rgb) :\n  shuffle (shuffle (shuffle c)) = c :=\nmatch c with\n| rgb.mk r g b := eq.refl _\nend\n\n\n/- ## Type Classes\n\nA __type class__ is a structure type combining abstract constants and their\nproperties. A type can be declared an instance of a type class by providing\nconcrete definitions for the constants and proving that the properties hold.\nBased on the type, Lean retrieves the relevant instance. -/\n\n#print inhabited\n\n@[instance] def nat.inhabited : inhabited \u2115 :=\n{ default := 0 }\n\n@[instance] def list.inhabited {\u03b1 : Type} :\n  inhabited (list \u03b1) :=\n{ default := [] }\n\n#eval inhabited.default \u2115          -- result: 0\n#eval inhabited.default (list \u2124)   -- result: []\n\ndef head {\u03b1 : Type} [inhabited \u03b1] : list \u03b1 \u2192 \u03b1\n| []       := inhabited.default \u03b1\n| (x :: _) := x\n\nlemma head_head {\u03b1 : Type} [inhabited \u03b1] (xs : list \u03b1) :\n  head [head xs] = head xs :=\nbegin\n  cases' xs,\n  { refl },\n  { refl }\nend\n\n#eval head ([] : list \u2115)   -- result: 0\n\n#check list.head\n\n@[instance] def fun.inhabited {\u03b1 \u03b2 : Type} [inhabited \u03b2] :\n  inhabited (\u03b1 \u2192 \u03b2) :=\n{ default := \u03bba : \u03b1, inhabited.default \u03b2 }\n\ninductive empty : Type\n\n@[instance] def fun_empty.inhabited {\u03b2 : Type} :\n  inhabited (empty \u2192 \u03b2) :=\n{ default := \u03bba : empty, match a with end }\n\n@[instance] def prod.inhabited {\u03b1 \u03b2 : Type}\n    [inhabited \u03b1] [inhabited \u03b2] :\n  inhabited (\u03b1 \u00d7 \u03b2) :=\n{ default := (inhabited.default \u03b1, inhabited.default \u03b2) }\n\n/- Here are other type classes without properties: -/\n\n#check has_zero\n#check has_neg\n#check has_add\n#check has_one\n#check has_inv\n#check has_mul\n\n#check (1 : \u2115)\n#check (1 : \u2124)\n#check (1 : \u211d)\n\n/- We encountered these type classes in lecture 2: -/\n\n#print is_commutative\n#print is_associative\n\n\n/- ## Lists\n\n`list` is an inductive polymorphic type constructed from `nil` and `cons`: -/\n\n#print list\n\n/- `cases'` can also be used on a hypothesis of the form `l = r`. It matches `r`\nagainst `l` and replaces all occurrences of the variables occurring in `r` with\nthe corresponding terms in `l` everywhere in the goal. -/\n\nlemma injection_example {\u03b1 : Type} (x y : \u03b1) (xs ys : list \u03b1)\n    (h : list.cons x xs = list.cons y ys) :\n  x = y \u2227 xs = ys :=\nbegin\n  cases' h,\n  cc\nend\n\n/- If `r` fails to match `l`, no subgoals emerge; the proof is complete. -/\n\nlemma distinctness_example {\u03b1 : Type} (y : \u03b1) (ys : list \u03b1)\n    (h : [] = y :: ys) :\n  false :=\nby cases' h\n\ndef map {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) : list \u03b1 \u2192 list \u03b2\n| []        := []\n| (x :: xs) := f x :: map xs\n\ndef map\u2082 {\u03b1 \u03b2 : Type} : (\u03b1 \u2192 \u03b2) \u2192 list \u03b1 \u2192 list \u03b2\n| _ []        := []\n| f (x :: xs) := f x :: map\u2082 f xs\n\n#check list.map\n\nlemma map_ident {\u03b1 : Type} (xs : list \u03b1) :\n  map (\u03bbx, x) xs = xs :=\nbegin\n  induction' xs,\n  case nil {\n    refl },\n  case cons : y ys {\n    simp [map, ih] }\nend\n\nlemma map_comp {\u03b1 \u03b2 \u03b3 : Type} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3)\n    (xs : list \u03b1) :\n  map g (map f xs) = map (\u03bbx, g (f x)) xs :=\nbegin\n  induction' xs,\n  case nil {\n    refl },\n  case cons : y ys {\n    simp [map, ih] }\nend\n\nlemma map_append {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) (xs ys : list \u03b1) :\n  map f (xs ++ ys) = map f xs ++ map f ys :=\nbegin\n  induction' xs,\n  case nil {\n    refl },\n  case cons : y ys {\n    simp [map, ih] }\nend\n\ndef tail {\u03b1 : Type} : list \u03b1 \u2192 list \u03b1\n| []        := []\n| (_ :: xs) := xs\n\n#check list.tail\n\ndef head_opt {\u03b1 : Type} : list \u03b1 \u2192 option \u03b1\n| []       := option.none\n| (x :: _) := option.some x\n\ndef head_le {\u03b1 : Type} : \u2200xs : list \u03b1, xs \u2260 [] \u2192 \u03b1\n| []       hxs := by cc\n| (x :: _) _   := x\n\n#eval head_opt [3, 1, 4]\n#eval head_le [3, 1, 4] (by simp)\n-- fails\n#eval head_le ([] : list \u2115) sorry\n\ndef zip {\u03b1 \u03b2 : Type} : list \u03b1 \u2192 list \u03b2 \u2192 list (\u03b1 \u00d7 \u03b2)\n| (x :: xs) (y :: ys) := (x, y) :: zip xs ys\n| []        _         := []\n| (_ :: _)  []        := []\n\n#check list.zip\n\ndef length {\u03b1 : Type} : list \u03b1 \u2192 \u2115\n| []        := 0\n| (x :: xs) := length xs + 1\n\n#check list.length\n\n/- `cases'` can also be used to perform a case distinction on a proposition, in\nconjunction with `classical.em`. Two cases emerge: one in which the proposition\nis true and one in which it is false. -/\n\n#check classical.em\n\nlemma min_add_add (l m n : \u2115) :\n  min (m + l) (n + l) = min m n + l :=\nbegin\n  cases' classical.em (m \u2264 n),\n  case inl {\n    simp [min, h] },\n  case inr {\n    simp [min, h] }\nend\n\nlemma min_add_add\u2082 (l m n : \u2115) :\n  min (m + l) (n + l) = min m n + l :=\nmatch classical.em (m \u2264 n) with\n| or.inl h := by simp [min, h]\n| or.inr h := by simp [min, h]\nend\n\nlemma min_add_add\u2083 (l m n : \u2115) :\n  min (m + l) (n + l) = min m n + l :=\nif h : m \u2264 n then\n  by simp [min, h]\nelse\n  by simp [min, h]\n\nlemma length_zip {\u03b1 \u03b2 : Type} (xs : list \u03b1) (ys : list \u03b2) :\n  length (zip xs ys) = min (length xs) (length ys) :=\nbegin\n  induction' xs,\n  case nil {\n    refl },\n  case cons : x xs' {\n    cases' ys,\n    case nil {\n      refl },\n    case cons : y ys' {\n      simp [zip, length, ih ys', min_add_add] } }\nend\n\nlemma map_zip {\u03b1 \u03b1' \u03b2 \u03b2' : Type} (f : \u03b1 \u2192 \u03b1') (g : \u03b2 \u2192 \u03b2') :\n  \u2200xs ys,\n    map (\u03bbab : \u03b1 \u00d7 \u03b2, (f (prod.fst ab), g (prod.snd ab)))\n      (zip xs ys) =\n    zip (map f xs) (map g ys)\n| (x :: xs) (y :: ys) := by simp [zip, map, map_zip xs ys]\n| []        _         := by refl\n| (_ :: _)  []        := by refl\n\n\n/- ## Binary Trees\n\nInductive types with constructors taking several recursive arguments define\ntree-like objects. __Binary trees__ have nodes with at most two children. -/\n\ninductive btree (\u03b1 : Type) : Type\n| empty {} : btree\n| node     : \u03b1 \u2192 btree \u2192 btree \u2192 btree\n\n/- The type `aexp` of arithmetic expressions was also an example of a tree data\nstructure.\n\nThe nodes of a tree, whether inner nodes or leaf nodes, often carry labels or\nother annotations.\n\nInductive trees contain no infinite branches, not even cycles. This is less\nexpressive than pointer- or reference-based data structures (in imperative\nlanguages) but easier to reason about.\n\nRecursive definitions (and proofs by induction) work roughly as for lists, but\nwe may need to recurse (or invoke the induction hypothesis) on several child\nnodes. -/\n\ndef mirror {\u03b1 : Type} : btree \u03b1 \u2192 btree \u03b1\n| btree.empty        := btree.empty\n| (btree.node a l r) := btree.node a (mirror r) (mirror l)\n\nlemma mirror_mirror {\u03b1 : Type} (t : btree \u03b1) :\n  mirror (mirror t) = t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    simp [mirror, ih_l, ih_r] }\nend\n\nlemma mirror_mirror\u2082 {\u03b1 : Type} :\n  \u2200t : btree \u03b1, mirror (mirror t) = t\n| btree.empty        := by refl\n| (btree.node a l r) :=\n  calc  mirror (mirror (btree.node a l r))\n      = mirror (btree.node a (mirror r) (mirror l)) :\n    by refl\n  ... = btree.node a (mirror (mirror l)) (mirror (mirror r)) :\n    by refl\n  ... = btree.node a l (mirror (mirror r)) :\n    by rw mirror_mirror\u2082 l\n  ... = btree.node a l r :\n    by rw mirror_mirror\u2082 r\n\nlemma mirror_eq_empty_iff {\u03b1 : Type} :\n  \u2200t : btree \u03b1, mirror t = btree.empty \u2194 t = btree.empty\n| btree.empty        := by refl\n| (btree.node _ _ _) := by simp [mirror]\n\n\n/- ## Dependent Inductive Types (**optional**) -/\n\n#check vector\n\ninductive vec (\u03b1 : Type) : \u2115 \u2192 Type\n| nil {}                           : vec 0\n| cons (a : \u03b1) {n : \u2115} (v : vec n) : vec (n + 1)\n\n#check vec.nil\n#check vec.cons\n\ndef list_of_vec {\u03b1 : Type} : \u2200{n : \u2115}, vec \u03b1 n \u2192 list \u03b1\n| _ vec.nil        := []\n| _ (vec.cons a v) := a :: list_of_vec v\n\ndef vec_of_list {\u03b1 : Type} :\n  \u2200xs : list \u03b1, vec \u03b1 (list.length xs)\n| []        := vec.nil\n| (x :: xs) := vec.cons x (vec_of_list xs)\n\nlemma length_list_of_vec {\u03b1 : Type} :\n  \u2200{n : \u2115} (v : vec \u03b1 n), list.length (list_of_vec v) = n\n| _ vec.nil        := by refl\n| _ (vec.cons a v) :=\n  by simp [list_of_vec, length_list_of_vec v]\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love04_functional_programming_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7491932415780066}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.free_module.finite.basic\nimport linear_algebra.matrix.charpoly.coeff\n\n/-!\n\n# Characteristic polynomial\n\nWe define the characteristic polynomial of `f : M \u2192\u2097[R] M`, where `M` is a finite and\nfree `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f`\nin any basis is in `linear_algebra/charpoly/to_matrix`.\n\n## Main definition\n\n* `linear_map.charpoly f` : the characteristic polynomial of `f : M \u2192\u2097[R] M`.\n\n-/\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} [comm_ring R] [nontrivial R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M] (f : M \u2192\u2097[R] M)\n\nopen_locale classical matrix\n\nnoncomputable theory\n\nopen module.free polynomial matrix\n\nnamespace linear_map\n\nsection basic\n\n/-- The characteristic polynomial of `f : M \u2192\u2097[R] M`. -/\ndef charpoly : polynomial R :=\n(to_matrix (choose_basis R M) (choose_basis R M) f).charpoly\n\n\n\nend basic\n\nsection coeff\n\nlemma charpoly_monic : f.charpoly.monic := charpoly_monic _\n\nend coeff\n\nsection cayley_hamilton\n\n/-- The Cayley-Hamilton Theorem, that the characteristic polynomial of a linear map, applied to\nthe linear map itself, is zero. -/\nlemma aeval_self_charpoly : aeval f f.charpoly = 0 :=\nbegin\n  apply (linear_equiv.map_eq_zero_iff (alg_equiv_matrix _).to_linear_equiv).1,\n  rw [alg_equiv.to_linear_equiv_apply, \u2190 alg_equiv.coe_alg_hom,\n    \u2190 polynomial.aeval_alg_hom_apply _ _ _, charpoly_def],\n  exact aeval_self_charpoly _,\nend\n\nlemma is_integral : is_integral R f := \u27e8f.charpoly, \u27e8charpoly_monic f, aeval_self_charpoly f\u27e9\u27e9\n\nlemma minpoly_dvd_charpoly {K : Type u} {M : Type v} [field K] [add_comm_group M] [module K M]\n  [finite_dimensional K M] (f : M \u2192\u2097[K] M) : minpoly K f \u2223 f.charpoly :=\nminpoly.dvd _ _ (aeval_self_charpoly f)\n\nvariable {f}\n\nlemma minpoly_coeff_zero_of_injective (hf : function.injective f) : (minpoly R f).coeff 0 \u2260 0 :=\nbegin\n  intro h,\n  obtain \u27e8P, hP\u27e9 := X_dvd_iff.2 h,\n  have hdegP : P.degree < (minpoly R f).degree,\n  { rw [hP, mul_comm],\n    refine degree_lt_degree_mul_X (\u03bb h, _),\n    rw [h, mul_zero] at hP,\n    exact minpoly.ne_zero (is_integral f) hP },\n  have hPmonic : P.monic,\n  { suffices : (minpoly R f).monic,\n    { rwa [monic.def, hP, mul_comm, leading_coeff_mul_X, \u2190 monic.def] at this },\n    exact minpoly.monic (is_integral f) },\n  have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _,\n  simp only [hP, mul_eq_comp, ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp, alg_hom.map_mul,\n    zero_apply] at hzero,\n  exact not_le.2 hdegP (minpoly.min _ _ hPmonic (ext hzero)),\nend\n\nend cayley_hamilton\n\nend linear_map\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7491620594806765}}
{"text": "import Mathlib.Algebra.GeomSum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.LibrarySearch\nimport Mathlib.Data.Real.Basic\n\n/-!\n# IMO 2013 Q5\n\nLet \u211a>\u2080 be the set of positive rational numbers. Let f: \u211a>\u2080 \u2192 \u211d be a function satisfying\nthe conditions\n\n  (1) f(x) * f(y) \u2265 f(x * y)\n  (2) f(x + y)    \u2265 f(x) + f(y)\n\nfor all x,y \u2208 \u211a>\u2080. Given that f(a) = a for some rational a > 1, prove that f(x) = x for\nall x \u2208 \u211a>\u2080.\n\n# Solution\n\nWe provide a direct translation of the solution found in\nhttps://www.imo-official.org/problems/IMO2013SL.pdf\n-/\n\nopen BigOperators\n\nlemma le_of_all_pow_lt_succ {x y : \u211d} (hx : 1 < x) (hy : 1 < y)\n    (h : \u2200 n : \u2115, 0 < n \u2192 x^n - 1 < y^n) :\n    x \u2264 y := by\n  by_contra hxy\n  push_neg at hxy\n  have hxmy : 0 < x - y := sub_pos.mpr hxy\n  have hn : \u2200 n : \u2115, 0 < n \u2192 (x - y) * (n : \u211d) \u2264 x^n - y^n := by\n    intros n _\n    have hterm : \u2200 i : \u2115, i \u2208 Finset.range n \u2192 1 \u2264 x^i * y^(n - 1 - i) := by\n      intros i _\n      have hx' : 1 \u2264 x ^ i := one_le_pow_of_one_le hx.le i\n      have hy' : 1 \u2264 y ^ (n - 1 - i) := one_le_pow_of_one_le hy.le (n - 1 - i)\n      calc 1 \u2264 x^i             := hx'\n           _ = x^i * 1         := (mul_one _).symm\n           _ \u2264 x^i * y^(n-1-i) := mul_le_mul_of_nonneg_left hy' (zero_le_one.trans hx')\n    calc (x - y) * (n : \u211d)\n        = (n : \u211d) * (x - y) := mul_comm _ _\n      _ = (\u2211 _i in Finset.range n, (1 : \u211d)) * (x - y) :=\n                                 by simp only [mul_one, Finset.sum_const, nsmul_eq_mul,\n                                    Finset.card_range]\n      _ \u2264 (\u2211 i in Finset.range n, x ^ i * y ^ (n - 1 - i)) * (x-y) :=\n                                  (mul_le_mul_right hxmy).mpr (Finset.sum_le_sum hterm)\n      _ = x^n - y^n         := geom_sum\u2082_mul x y n\n\n  -- Choose n larger than 1 / (x - y).\n  obtain \u27e8N, hN\u27e9 := exists_nat_gt (1 / (x - y))\n  have hNp : 0 < N := by exact_mod_cast (one_div_pos.mpr hxmy).trans hN\n  have := calc 1 = (x - y) * (1 / (x - y)) := by field_simp [ne_of_gt hxmy]\n               _ < (x - y) * N             := (mul_lt_mul_left hxmy).mpr hN\n               _ \u2264 x^N - y^N               := hn N hNp\n  linarith [h N hNp]\n\n/--\n Like le_of_all_pow_lt_succ, but with a weaker assumption for y.\n-/\nlemma le_of_all_pow_lt_succ' {x y : \u211d} (hx : 1 < x) (hy : 0 < y)\n    (h : \u2200 n : \u2115, 0 < n \u2192 x^n - 1 < y^n) :\n    x \u2264 y := by\n  refine le_of_all_pow_lt_succ hx ?_ h\n  by_contra hy''\n  push_neg at hy'' -- hy'' : y \u2264 1.\n\n  -- Then there exists y' such that 0 < y \u2264 1 < y' < x.\n  let y' := (x + 1) / 2\n  have h_y'_lt_x : y' < x := by\n    have hh : (x + 1) < (x * 2) := by linarith\n    calc y' < (x * 2) / 2 := div_lt_div_of_lt two_pos hh\n         _ = x            := by field_simp\n\n  have h1_lt_y' : 1 < y' := by\n    have hh' : 1 * 2 < (x + 1) := by linarith\n    calc (1:\u211d) = 1 * 2 / 2 := by field_simp\n             _ < y'        := div_lt_div_of_lt two_pos hh'\n\n  have h_y_lt_y' : y < y' := hy''.trans_lt h1_lt_y'\n  have hh : \u2200 n, 0 < n \u2192 x^n - 1 < y'^n := by\n    intros n hn\n    calc x^n - 1 < y^n  := h n hn\n         _  \u2264 y'^n := pow_le_pow_of_le_left hy.le h_y_lt_y'.le n\n\n  exact h_y'_lt_x.not_le (le_of_all_pow_lt_succ hx h1_lt_y' hh)\n\nlemma f_pos_of_pos {f : \u211a \u2192 \u211d} {q : \u211a} (hq : 0 < q)\n    (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n    (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n    0 < f q := by\n  have hfqn := calc f q.num = f (q * q.den) := by rw [\u2190Rat.mul_den_eq_num]\n                    _ \u2264 f q * f q.den := H1 q q.den hq (Nat.cast_pos.mpr q.pos)\n\n  -- Now we just need to show that `f q.num` and `f q.denom` are positive.\n  -- Then nlinarith will be able to close the goal.\n  have num_pos : 0 < q.num := Rat.num_pos_iff_pos.mpr hq\n  have hqna : (q.num.natAbs : \u2124) = q.num := Int.natAbs_of_nonneg num_pos.le\n\n  have hqfn' := calc (q.num : \u211d)\n         = ((q.num.natAbs : \u2124) : \u211d) := congr_arg Int.cast (Eq.symm hqna)\n       _ \u2264 f q.num.natAbs           := H4 q.num.natAbs\n                                            (Int.natAbs_pos.mpr (ne_of_gt num_pos))\n       _ = f q.num                   := by rw [Nat.cast_natAbs, abs_of_nonneg num_pos.le]\n\n  have f_num_pos := calc (0 : \u211d) < q.num := Int.cast_pos.mpr num_pos\n                         _ \u2264 f q.num     := hqfn'\n\n  have f_den_pos := calc (0 : \u211d) < q.den := Nat.cast_pos.mpr q.pos\n                         _ \u2264 f q.den     := H4 q.den q.pos\n\n  nlinarith\n\nlemma fx_gt_xm1 {f : \u211a \u2192 \u211d} {x : \u211a} (hx : 1 \u2264 x)\n    (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n    (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n    (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n    (x - 1 : \u211d) < f x := by\n  have hx0 :=\n    calc (x - 1 : \u211d)\n          < \u230ax\u230b\u208a   := by exact_mod_cast Nat.sub_one_lt_floor x\n        _ \u2264 f \u230ax\u230b\u208a := H4 _ (Nat.floor_pos.2 hx)\n\n  obtain h_eq | h_lt := (Nat.floor_le $ zero_le_one.trans hx).eq_or_lt\n  \u00b7 rwa [h_eq] at hx0\n  calc (x - 1 : \u211d) < f \u230ax\u230b\u208a := hx0\n    _ < f (x - \u230ax\u230b\u208a) + f \u230ax\u230b\u208a := lt_add_of_pos_left _ (f_pos_of_pos (sub_pos.mpr h_lt) H1 H4)\n    _ \u2264 f (x - \u230ax\u230b\u208a + \u230ax\u230b\u208a)   := H2 _ _ (sub_pos.mpr h_lt) (Nat.cast_pos.2 (Nat.floor_pos.2 hx))\n    _ = f x                   := by rw [sub_add_cancel]\n\n\nlemma pow_f_le_f_pow {f : \u211a \u2192 \u211d} {n : \u2115} (hn : 0 < n) {x : \u211a} (hx : 1 < x)\n    (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n    (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n    f (x^n) \u2264 (f x)^n := by\n  induction n with\n  | zero => exfalso; exact Nat.lt_asymm hn hn\n  | succ pn hpn =>\n    cases pn with\n    | zero => simp [show Nat.succ 0 = 1 by rfl, pow_one]\n    | succ pn =>\n      have hpn' := hpn pn.succ_pos\n      rw [pow_succ' x (pn + 1), pow_succ' (f x) (pn + 1)]\n      have hxp : 0 < x := zero_lt_one.trans hx\n      calc f ((x ^ (pn+1)) * x)\n          \u2264 f (x ^ (pn+1)) * f x := H1 (x ^ (pn+1)) x (pow_pos hxp (pn+1)) hxp\n        _ \u2264 (f x) ^ (pn+1) * f x := (mul_le_mul_right (f_pos_of_pos hxp H1 H4)).mpr hpn'\n\nlemma fixed_point_of_pos_nat_pow {f : \u211a \u2192 \u211d} {n : \u2115} (hn : 0 < n)\n    (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n    (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n)\n    (H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x)\n    {a : \u211a} (ha1 : 1 < a) (hae : f a = a) :\n    f (a^n) = a^n := by\n  have hh0 : (a : \u211d) ^ n \u2264 f (a ^ n) := by\n    exact_mod_cast H5 (a ^ n) (one_lt_pow ha1 hn.ne')\n\n  have hh1 := calc f (a^n) \u2264 (f a)^n := pow_f_le_f_pow hn ha1 H1 H4\n                   _ = (a : \u211d)^n     := by rw [\u2190hae]\n  exact_mod_cast hh1.antisymm hh0\n\nlemma fixed_point_of_gt_1 {f : \u211a \u2192 \u211d} {x : \u211a} (hx : 1 < x)\n    (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n    (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n    (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n)\n    (H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x)\n    {a : \u211a} (ha1 : 1 < a) (hae : f a = a) :\n    f x = x := by\n  -- Choose n such that 1 + x < a^n.\n  obtain \u27e8N, hN\u27e9 := pow_unbounded_of_one_lt (1 + x) ha1\n  have h_big_enough : (1:\u211a) < a^N - x := lt_sub_iff_add_lt.mpr hN\n  have h1 := calc (x : \u211d) + ((a^N - x) : \u211a)\n                \u2264 f x + ((a^N - x) : \u211a) := add_le_add_right (H5 x hx) _\n              _ \u2264 f x + f (a^N - x)     := add_le_add_left (H5 _ h_big_enough) _\n  have hxp : 0 < x := zero_lt_one.trans hx\n  have hNp : 0 < N := by\n    by_contra H; push_neg at H; rw [le_zero_iff.mp H] at hN; linarith\n\n  have h2 := calc f x + f (a^N - x)\n                \u2264 f (x + (a^N - x)) := H2 x (a^N - x) hxp (zero_lt_one.trans h_big_enough)\n              _ = f (a^N)           := by ring_nf\n              _ = (a^N : \u211d)         := fixed_point_of_pos_nat_pow hNp H1 H4 H5 ha1 hae\n              _ = (x:\u211d) + ((a^N:\u211d) - (x:\u211d))     := by ring\n\n  have heq := h1.antisymm (by exact_mod_cast h2)\n  linarith [H5 x hx, H5 _ h_big_enough]\n\ntheorem imo2013_q5\n    (f : \u211a \u2192 \u211d)\n    (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n    (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n    (H_fixed_point : \u2203 a, 1 < a \u2227 f a = a) :\n    \u2200 x, 0 < x \u2192 f x = x := by\n  obtain \u27e8a, ha1, hae\u27e9 := H_fixed_point\n  have H3 : \u2200 x : \u211a, 0 < x \u2192 \u2200 n : \u2115, 0 < n \u2192 \u2191n * f x \u2264 f (n * x) := by\n    intros x hx n hn\n    cases n with\n    | zero => exfalso; exact Nat.lt_asymm hn hn\n    | succ n =>\n      induction n with\n      | zero => simp [one_mul, Nat.cast_one]\n      | succ pn hpn =>\n        calc  \u2191(pn + 2) * f x\n            = (\u2191pn + 1 + 1) * f x            := by norm_cast\n          _ = (\u2191pn + 1) * f x + f x          := by ring\n          _ \u2264 f ((\u2191pn.succ) * x) + f x       := by exact_mod_cast add_le_add_right\n                                                    (hpn pn.succ_pos) (f x)\n          _ \u2264 f ((\u2191pn + 1) * x + x)          := by exact_mod_cast H2 _ _\n                                                    (mul_pos pn.cast_add_one_pos hx) hx\n          _ = f ((\u2191pn + 1 + 1) * x)          := by ring_nf\n          _ = f (\u2191(pn + 2) * x)              := by norm_cast\n\n  have H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n := by\n    intros n hn\n    have hf1 : 1 \u2264 f 1 := by\n      have a_pos : (0 : \u211d) < a := Rat.cast_pos.mpr (zero_lt_one.trans ha1)\n      suffices \u2191a * 1 \u2264 \u2191a * f 1 by exact (mul_le_mul_left a_pos).mp this\n      calc (a:\u211d) * 1 = \u2191a := mul_one _\n           _ = f a        := hae.symm\n           _ = f (a * 1)  := by rw[mul_one]\n           _ \u2264 f a * f 1  := (H1 a 1) (zero_lt_one.trans ha1) zero_lt_one\n           _ = \u2191a * f 1   := by rw[hae]\n\n    calc (n : \u211d) = (n : \u211d) * 1 := (mul_one _).symm\n         _ \u2264 (n : \u211d) * f 1     := (mul_le_mul_left (Nat.cast_pos.mpr hn)).mpr hf1\n         _ \u2264 f (n * 1)         := H3 1 zero_lt_one n hn\n         _ = f n               := by rw [mul_one]\n\n  have H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x := by\n    intros x hx\n    have hxnm1 : \u2200 n : \u2115, 0 < n \u2192 (x : \u211d)^n - 1 < (f x)^n := by\n      intros n hn\n      calc (x : \u211d)^n - 1 < f (x^n) := by exact_mod_cast fx_gt_xm1 (one_le_pow_of_one_le hx.le n)\n                                           H1 H2 H4\n                       _ \u2264 (f x)^n := pow_f_le_f_pow hn hx H1 H4\n    have hx' : 1 < (x : \u211d) := by exact_mod_cast hx\n    have hxp : 0 < x := zero_lt_one.trans hx\n    exact le_of_all_pow_lt_succ' hx' (f_pos_of_pos hxp H1 H4) hxnm1\n\n  have h_f_commutes_with_pos_nat_mul : \u2200 n : \u2115, 0 < n \u2192 \u2200 x : \u211a, 0 < x \u2192 f (n * x) = n * f x := by\n    intros n hn x hx\n    have h2 : f (n * x) \u2264 n * f x := by\n      cases n with\n      | zero => exfalso; exact Nat.lt_asymm hn hn\n      | succ n => cases n with\n        | zero => simp [one_mul, Nat.cast_one]\n        | succ n =>\n          have hfneq : f (n.succ.succ) = n.succ.succ := by\n            have := fixed_point_of_gt_1\n                  (Nat.one_lt_cast.mpr (Nat.succ_lt_succ n.succ_pos)) H1 H2 H4 H5 ha1 hae\n            rwa [Rat.cast_coe_nat n.succ.succ] at this\n          rw [\u2190hfneq]\n          exact H1 (n.succ.succ : \u211a) x (Nat.cast_pos.mpr hn) hx\n    exact h2.antisymm (H3 x hx n hn)\n\n  -- For the final calculation, we expand x as (2*x.num) / (2*x.denom), because\n  -- we need the top of the fraction to be strictly greater than 1 in order\n  -- to apply fixed_point_of_gt_1.\n  intros x hx\n  let x2denom := 2 * x.den\n  let x2num := 2 * x.num\n\n  have hx2pos : 0 < 2 * x.den := by linarith[x.pos]\n  have hxcnez   : (x.den : \u211a) \u2260 (0 : \u211a) := ne_of_gt (Nat.cast_pos.mpr x.pos)\n  have hx2cnezr : (x2denom : \u211d) \u2260 (0 : \u211d) := Nat.cast_ne_zero.mpr (ne_of_gt hx2pos)\n\n  have hrat_expand2 := calc x = x.num / x.den := by exact_mod_cast Rat.num_den.symm\n                            _ = x2num / x2denom := by { field_simp; ring}\n\n  have h_denom_times_fx :=\n    calc (x2denom : \u211d) * f x = f (x2denom * x) := (h_f_commutes_with_pos_nat_mul\n                                                   x2denom hx2pos x hx).symm\n         _ = f (x2denom * (x2num / x2denom))   := by rw[hrat_expand2]\n         _ = f x2num                           := by congr; field_simp; ring\n\n  have h_fx2num_fixed : f x2num = x2num := by\n    have hx2num_gt_one : (1 : \u211a) < (2 * x.num : \u2124) := by\n      norm_cast; linarith [Rat.num_pos_iff_pos.mpr hx]\n    have hh := fixed_point_of_gt_1 hx2num_gt_one H1 H2 H4 H5 ha1 hae\n    rwa [Rat.cast_coe_int x2num] at hh\n\n  calc f x = f x * 1                               := (mul_one (f x)).symm\n       _ = f x * (x2denom / x2denom)               := by rw [\u2190div_self hx2cnezr]\n       _ = (f x * x2denom) / x2denom               := mul_div_assoc' (f x) _ _\n       _ = (x2denom * f x) / x2denom               := by rw[mul_comm]\n       _ = f x2num / x2denom                       := by rw[h_denom_times_fx]\n       _ = x2num / x2denom                         := by rw[h_fx2num_fixed]\n       _ = ((x2num:\u211a):\u211d) / ((x2denom:\u211a):\u211d)         := rfl\n       _ = (((x2num : \u211a) / (x2denom : \u211a) : \u211a) : \u211d) := by norm_cast\n       _ = x                                       := by rw[\u2190hrat_expand2]\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean4", "sha": "dcf38981b8b9ff59a62f1e19a4f135fcdb4c9a63", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean4", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean4/math-puzzles-in-lean4-dcf38981b8b9ff59a62f1e19a4f135fcdb4c9a63/MathPuzzles/Imo2013Q5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7491620555069325}}
{"text": "/-\nCopyright (c) 2018 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes,\n  Johannes H\u00f6lzl, Yury Kudryashov\n-/\n\nimport algebra.group_power.basic\n\n/-!\n# Instances on spaces of monoid and group morphisms\n\nWe endow the space of monoid morphisms `M \u2192* N` with a `comm_monoid` structure when the target is\ncommutative, through pointwise multiplication, and with a `comm_group` structure when the target\nis a commutative group. We also prove the same instances for additive situations.\n\nSince these structures permit morphisms of morphisms, we also provide some composition-like\noperations.\n\nFinally, we provide the `ring` structure on `add_monoid.End`.\n-/\n\nuniverses uM uN uP uQ\nvariables {M : Type uM} {N : Type uN} {P : Type uP} {Q : Type uQ}\n\n/-- `(M \u2192* N)` is a `comm_monoid` if `N` is commutative. -/\n@[to_additive \"`(M \u2192+ N)` is an `add_comm_monoid` if `N` is commutative.\"]\ninstance [mul_one_class M] [comm_monoid N] : comm_monoid (M \u2192* N) :=\n{ mul := (*),\n  mul_assoc := by intros; ext; apply mul_assoc,\n  one := 1,\n  one_mul := by intros; ext; apply one_mul,\n  mul_one := by intros; ext; apply mul_one,\n  mul_comm := by intros; ext; apply mul_comm,\n  npow := \u03bb n f,\n  { to_fun := \u03bb x, (f x) ^ n,\n    map_one' := by simp,\n    map_mul' := \u03bb x y, by simp [mul_pow] },\n  npow_zero' := \u03bb f, by { ext x, simp },\n  npow_succ' := \u03bb n f, by { ext x, simp [pow_succ] } }\n\n/-- If `G` is a commutative group, then `M \u2192* G` is a commutative group too. -/\n@[to_additive \"If `G` is an additive commutative group, then `M \u2192+ G` is an additive commutative\ngroup too.\"]\ninstance {M G} [mul_one_class M] [comm_group G] : comm_group (M \u2192* G) :=\n{ inv := has_inv.inv,\n  div := has_div.div,\n  div_eq_mul_inv := by { intros, ext, apply div_eq_mul_inv },\n  mul_left_inv := by intros; ext; apply mul_left_inv,\n  zpow := \u03bb n f, { to_fun := \u03bb x, (f x) ^ n,\n    map_one' := by simp,\n    map_mul' := \u03bb x y, by simp [mul_zpow] },\n  zpow_zero' := \u03bb f, by { ext x, simp },\n  zpow_succ' := \u03bb n f, by { ext x, simp [zpow_of_nat, pow_succ] },\n  zpow_neg'  := \u03bb n f, by { ext x, simp },\n  ..monoid_hom.comm_monoid }\n\ninstance [add_comm_monoid M] : semiring (add_monoid.End M) :=\n{ zero_mul := \u03bb x, add_monoid_hom.ext $ \u03bb i, rfl,\n  mul_zero := \u03bb x, add_monoid_hom.ext $ \u03bb i, add_monoid_hom.map_zero _,\n  left_distrib := \u03bb x y z, add_monoid_hom.ext $ \u03bb i, add_monoid_hom.map_add _ _ _,\n  right_distrib := \u03bb x y z, add_monoid_hom.ext $ \u03bb i, rfl,\n  .. add_monoid.End.monoid M,\n  .. add_monoid_hom.add_comm_monoid }\n\ninstance [add_comm_group M] : ring (add_monoid.End M) :=\n{ .. add_monoid.End.semiring,\n  .. add_monoid_hom.add_comm_group }\n\n/-!\n### Morphisms of morphisms\n\nThe structures above permit morphisms that themselves produce morphisms, provided the codomain\nis commutative.\n-/\n\nnamespace monoid_hom\n\n@[to_additive]\nlemma ext_iff\u2082 {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P}\n  {f g : M \u2192* N \u2192* P} :\n  f = g \u2194 (\u2200 x y, f x y = g x y) :=\nmonoid_hom.ext_iff.trans $ forall_congr $ \u03bb _, monoid_hom.ext_iff\n\n/-- `flip` arguments of `f : M \u2192* N \u2192* P` -/\n@[to_additive \"`flip` arguments of `f : M \u2192+ N \u2192+ P`\"]\ndef flip {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P} (f : M \u2192* N \u2192* P) :\n  N \u2192* M \u2192* P :=\n{ to_fun := \u03bb y, \u27e8\u03bb x, f x y, by rw [f.map_one, one_apply], \u03bb x\u2081 x\u2082, by rw [f.map_mul, mul_apply]\u27e9,\n  map_one' := ext $ \u03bb x, (f x).map_one,\n  map_mul' := \u03bb y\u2081 y\u2082, ext $ \u03bb x, (f x).map_mul y\u2081 y\u2082 }\n\n@[simp, to_additive] lemma flip_apply\n  {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P}\n  (f : M \u2192* N \u2192* P) (x : M) (y : N) :\n  f.flip y x = f x y :=\nrfl\n\n@[to_additive]\nlemma map_one\u2082 {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P}\n  (f : M \u2192* N \u2192* P) (n : N) : f 1 n = 1 :=\n(flip f n).map_one\n\n@[to_additive]\nlemma map_mul\u2082 {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P}\n  (f : M \u2192* N \u2192* P) (m\u2081 m\u2082 : M) (n : N) : f (m\u2081 * m\u2082) n = f m\u2081 n * f m\u2082 n :=\n(flip f n).map_mul _ _\n\n@[to_additive]\nlemma map_inv\u2082 {mM : group M} {mN : mul_one_class N} {mP : comm_group P}\n  (f : M \u2192* N \u2192* P) (m : M) (n : N) : f m\u207b\u00b9 n = (f m n)\u207b\u00b9 :=\n(flip f n).map_inv _\n\n@[to_additive]\nlemma map_div\u2082 {mM : group M} {mN : mul_one_class N} {mP : comm_group P}\n  (f : M \u2192* N \u2192* P) (m\u2081 m\u2082 : M) (n : N) : f (m\u2081 / m\u2082) n = f m\u2081 n / f m\u2082 n :=\n(flip f n).map_div _ _\n\n/-- Evaluation of a `monoid_hom` at a point as a monoid homomorphism. See also `monoid_hom.apply`\nfor the evaluation of any function at a point. -/\n@[to_additive \"Evaluation of an `add_monoid_hom` at a point as an additive monoid homomorphism.\nSee also `add_monoid_hom.apply` for the evaluation of any function at a point.\", simps]\ndef eval [mul_one_class M] [comm_monoid N] : M \u2192* (M \u2192* N) \u2192* N := (monoid_hom.id (M \u2192* N)).flip\n\n/-- The expression `\u03bb g m, g (f m)` as a `monoid_hom`.\nEquivalently, `(\u03bb g, monoid_hom.comp g f)` as a `monoid_hom`. -/\n@[to_additive \"The expression `\u03bb g m, g (f m)` as a `add_monoid_hom`.\nEquivalently, `(\u03bb g, monoid_hom.comp g f)` as a `add_monoid_hom`.\n\nThis also exists in a `linear_map` version, `linear_map.lcomp`.\", simps]\ndef comp_hom' [mul_one_class M] [mul_one_class N] [comm_monoid P] (f : M \u2192* N) :\n  (N \u2192* P) \u2192* M \u2192* P :=\nflip $ eval.comp f\n\n/-- Composition of monoid morphisms (`monoid_hom.comp`) as a monoid morphism.\n\nNote that unlike `monoid_hom.comp_hom'` this requires commutativity of `N`. -/\n@[to_additive \"Composition of additive monoid morphisms (`add_monoid_hom.comp`) as an additive\nmonoid morphism.\n\nNote that unlike `add_monoid_hom.comp_hom'` this requires commutativity of `N`.\n\nThis also exists in a `linear_map` version, `linear_map.llcomp`.\", simps]\ndef comp_hom [mul_one_class M] [comm_monoid N] [comm_monoid P] :\n  (N \u2192* P) \u2192* (M \u2192* N) \u2192* (M \u2192* P) :=\n{ to_fun := \u03bb g, { to_fun := g.comp, map_one' := comp_one g, map_mul' := comp_mul g },\n  map_one' := by { ext1 f, exact one_comp f },\n  map_mul' := \u03bb g\u2081 g\u2082, by { ext1 f, exact mul_comp g\u2081 g\u2082 f } }\n\n/-- Flipping arguments of monoid morphisms (`monoid_hom.flip`) as a monoid morphism. -/\n@[to_additive \"Flipping arguments of additive monoid morphisms (`add_monoid_hom.flip`)\nas an additive monoid morphism.\", simps]\ndef flip_hom {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P}\n  : (M \u2192* N \u2192* P) \u2192* (N \u2192* M \u2192* P) :=\n{ to_fun := monoid_hom.flip, map_one' := rfl, map_mul' := \u03bb f g, rfl }\n\n/-- The expression `\u03bb m q, f m (g q)` as a `monoid_hom`.\n\nNote that the expression `\u03bb q n, f (g q) n` is simply `monoid_hom.comp`. -/\n@[to_additive \"The expression `\u03bb m q, f m (g q)` as an `add_monoid_hom`.\n\nNote that the expression `\u03bb q n, f (g q) n` is simply `add_monoid_hom.comp`.\n\nThis also exists as a `linear_map` version, `linear_map.compl\u2082`\"]\ndef compl\u2082 [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q]\n  (f : M \u2192* N \u2192* P) (g : Q \u2192* N) : M \u2192* Q \u2192* P :=\n(comp_hom' g).comp f\n\n@[simp, to_additive]\nlemma compl\u2082_apply [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q]\n  (f : M \u2192* N \u2192* P) (g : Q \u2192* N) (m : M) (q : Q) :\n  (compl\u2082 f g) m q = f m (g q) := rfl\n\n/-- The expression `\u03bb m n, g (f m n)` as a `monoid_hom`. -/\n@[to_additive \"The expression `\u03bb m n, g (f m n)` as an `add_monoid_hom`.\n\nThis also exists as a linear_map version, `linear_map.compr\u2082`\"]\ndef compr\u2082 [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q]\n  (f : M \u2192* N \u2192* P) (g : P \u2192* Q) : M \u2192* N \u2192* Q :=\n(comp_hom g).comp f\n\n@[simp, to_additive]\nlemma compr\u2082_apply [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q]\n  (f : M \u2192* N \u2192* P) (g : P \u2192* Q) (m : M) (n : N) :\n  (compr\u2082 f g) m n = g (f m n) := rfl\n\nend monoid_hom\n\n/-!\n### Miscellaneous definitions\n\nDue to the fact this file imports `algebra.group_power.basic`, it is not possible to import it in\nsome of the lower-level files like `algebra.ring.basic`. The following lemmas should be rehomed\nif the import structure permits them to be.\n-/\n\nsection semiring\n\nvariables {R S : Type*} [semiring R] [semiring S]\n\n/-- Multiplication of an element of a (semi)ring is an `add_monoid_hom` in both arguments.\n\nThis is a more-strongly bundled version of `add_monoid_hom.mul_left` and `add_monoid_hom.mul_right`.\n\nA stronger version of this exists for algebras as `algebra.lmul`.\n-/\ndef add_monoid_hom.mul : R \u2192+ R \u2192+ R :=\n{ to_fun := add_monoid_hom.mul_left,\n  map_zero' := add_monoid_hom.ext $ zero_mul,\n  map_add' := \u03bb a b, add_monoid_hom.ext $ add_mul a b }\n\nlemma add_monoid_hom.mul_apply (x y : R) : add_monoid_hom.mul x y = x * y := rfl\n\n@[simp]\nlemma add_monoid_hom.coe_mul :\n  \u21d1(add_monoid_hom.mul : R \u2192+ R \u2192+ R) = add_monoid_hom.mul_left := rfl\n\n@[simp]\nlemma add_monoid_hom.coe_flip_mul :\n  \u21d1(add_monoid_hom.mul : R \u2192+ R \u2192+ R).flip = add_monoid_hom.mul_right := rfl\n\n/-- An `add_monoid_hom` preserves multiplication if pre- and post- composition with\n`add_monoid_hom.mul` are equivalent. By converting the statement into an equality of\n`add_monoid_hom`s, this lemma allows various specialized `ext` lemmas about `\u2192+` to then be applied.\n-/\nlemma add_monoid_hom.map_mul_iff (f : R \u2192+ S) :\n  (\u2200 x y, f (x * y) = f x * f y) \u2194\n    (add_monoid_hom.mul : R \u2192+ R \u2192+ R).compr\u2082 f = (add_monoid_hom.mul.comp f).compl\u2082 f :=\niff.symm add_monoid_hom.ext_iff\u2082\n\nend semiring\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/group/hom_instances.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7491620515369901}}
{"text": "/-\nCopyright (c) 2021 Lu-Ming Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Lu-Ming Zhang\n-/\nimport linear_algebra.matrix.symmetric\n\n/-!\n# Circulant matrices\n\nThis file contains the definition and basic results about circulant matrices.\nGiven a vector `v : n \u2192 \u03b1` indexed by a type that is endowed with subtraction,\n`matrix.circulant v` is the matrix whose `(i, j)`th entry is `v (i - j)`.\n\n## Main results\n\n- `matrix.circulant`: the circulant matrix generated by a given vector `v : n \u2192 \u03b1`.\n- `matrix.circulant_mul`: the product of two circulant matrices `circulant v` and `circulant w` is\n                          the circulant matrix generated by `mul_vec (circulant v) w`.\n- `matrix.circulant_mul_comm`: multiplication of circulant matrices commutes when the elements do.\n\n## Implementation notes\n\n`matrix.fin.foo` is the `fin n` version of `matrix.foo`.\nNamely, the index type of the circulant matrices in discussion is `fin n`.\n\n## Tags\n\ncirculant, matrix\n-/\n\nvariables {\u03b1 \u03b2 m n R : Type*}\n\nnamespace matrix\n\nopen function\nopen_locale matrix big_operators\n\n/-- Given the condition `[has_sub n]` and a vector `v : n \u2192 \u03b1`,\n    we define `circulant v` to be the circulant matrix generated by `v` of type `matrix n n \u03b1`.\n    The `(i,j)`th entry is defined to be `v (i - j)`. -/\ndef circulant [has_sub n] (v : n \u2192 \u03b1) : matrix n n \u03b1 :=\nof $ \u03bb i j, v (i - j)\n\n-- TODO: set as an equation lemma for `circulant`, see mathlib4#3024\n@[simp]\nlemma circulant_apply [has_sub n] (v : n \u2192 \u03b1) (i j) : circulant v i j = v (i - j) := rfl\n\nlemma circulant_col_zero_eq [add_group n] (v : n \u2192 \u03b1) (i : n) : circulant v i 0 = v i :=\ncongr_arg v (sub_zero _)\n\nlemma circulant_injective [add_group n] : injective (circulant : (n \u2192 \u03b1) \u2192 matrix n n \u03b1) :=\nbegin\n  intros v w h,\n  ext k,\n  rw [\u2190 circulant_col_zero_eq v, \u2190 circulant_col_zero_eq w, h]\nend\n\nlemma fin.circulant_injective : \u2200 n, injective (\u03bb v : fin n \u2192 \u03b1, circulant v)\n| 0     := dec_trivial\n| (n+1) := circulant_injective\n\n@[simp] lemma circulant_inj [add_group n] {v w : n \u2192 \u03b1} :\n  circulant v = circulant w \u2194 v = w :=\ncirculant_injective.eq_iff\n\n@[simp] lemma fin.circulant_inj {n} {v w : fin n \u2192 \u03b1} :\n  circulant v = circulant w \u2194 v = w :=\n(fin.circulant_injective n).eq_iff\n\nlemma transpose_circulant [add_group n] (v : n \u2192 \u03b1) :\n  (circulant v)\u1d40 = circulant (\u03bb i, v (-i)) :=\nby ext; simp\n\nlemma conj_transpose_circulant [has_star \u03b1] [add_group n] (v : n \u2192 \u03b1) :\n  (circulant v)\u1d34 = circulant (star (\u03bb i, v (-i))) :=\nby ext; simp\n\nlemma fin.transpose_circulant : \u2200 {n} (v : fin n \u2192 \u03b1), (circulant v)\u1d40 =  circulant (\u03bb i, v (-i))\n| 0     := dec_trivial\n| (n+1) := transpose_circulant\n\nlemma fin.conj_transpose_circulant [has_star \u03b1] :\n  \u2200 {n} (v : fin n \u2192 \u03b1), (circulant v)\u1d34 = circulant (star (\u03bb i, v (-i)))\n| 0     := dec_trivial\n| (n+1) := conj_transpose_circulant\n\nlemma map_circulant [has_sub n] (v : n \u2192 \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  (circulant v).map f = circulant (\u03bb i, f (v i)) :=\next $ \u03bb _ _, rfl\n\nlemma circulant_neg [has_neg \u03b1] [has_sub n] (v : n \u2192 \u03b1) :\n  circulant (- v) = - circulant v :=\next $ \u03bb _ _, rfl\n\n@[simp] lemma circulant_zero (\u03b1 n) [has_zero \u03b1] [has_sub n] :\n  circulant 0 = (0 : matrix n n \u03b1) :=\next $ \u03bb _ _, rfl\n\nlemma circulant_add [has_add \u03b1] [has_sub n] (v w : n \u2192 \u03b1) :\n  circulant (v + w) = circulant v + circulant w :=\next $ \u03bb _ _, rfl\n\nlemma circulant_sub [has_sub \u03b1] [has_sub n] (v w : n \u2192 \u03b1) :\n  circulant (v - w) = circulant v - circulant w :=\next $ \u03bb _ _, rfl\n\n/-- The product of two circulant matrices `circulant v` and `circulant w` is\n    the circulant matrix generated by `mul_vec (circulant v) w`. -/\nlemma circulant_mul [semiring \u03b1] [fintype n] [add_group n] (v w : n \u2192 \u03b1) :\n  circulant v \u2b1d circulant w = circulant (mul_vec (circulant v) w) :=\nbegin\n  ext i j,\n  simp only [mul_apply, mul_vec, circulant_apply, dot_product],\n  refine fintype.sum_equiv (equiv.sub_right j) _ _ _,\n  intro x,\n  simp only [equiv.sub_right_apply, sub_sub_sub_cancel_right],\nend\n\nlemma fin.circulant_mul [semiring \u03b1] :\n  \u2200 {n} (v w : fin n \u2192 \u03b1), circulant v \u2b1d circulant w = circulant (mul_vec (circulant v) w)\n| 0     := dec_trivial\n| (n+1) := circulant_mul\n\n/-- Multiplication of circulant matrices commutes when the elements do. -/\nlemma circulant_mul_comm\n  [comm_semigroup \u03b1] [add_comm_monoid \u03b1] [fintype n] [add_comm_group n] (v w : n \u2192 \u03b1) :\n  circulant v \u2b1d circulant w = circulant w \u2b1d circulant v :=\nbegin\n  ext i j,\n  simp only [mul_apply, circulant_apply, mul_comm],\n  refine fintype.sum_equiv ((equiv.sub_left i).trans (equiv.add_right j)) _ _ _,\n  intro x,\n  congr' 2,\n  { simp },\n  { simp only [equiv.coe_add_right, function.comp_app,\n               equiv.coe_trans, equiv.sub_left_apply],\n    abel }\nend\n\nlemma fin.circulant_mul_comm [comm_semigroup \u03b1] [add_comm_monoid \u03b1] :\n  \u2200 {n} (v w : fin n \u2192 \u03b1), circulant v \u2b1d circulant w = circulant w \u2b1d circulant v\n| 0     := dec_trivial\n| (n+1) := circulant_mul_comm\n\n/-- `k \u2022 circulant v` is another circulant matrix `circulant (k \u2022 v)`. -/\nlemma circulant_smul [has_sub n] [has_smul R \u03b1] (k : R) (v : n \u2192 \u03b1) :\n  circulant (k \u2022 v) = k \u2022 circulant v :=\nby ext; simp\n\n@[simp] lemma circulant_single_one\n  (\u03b1 n) [has_zero \u03b1] [has_one \u03b1] [decidable_eq n] [add_group n] :\n  circulant (pi.single 0 1 : n \u2192 \u03b1) = (1 : matrix n n \u03b1) :=\nby { ext i j, simp [one_apply, pi.single_apply, sub_eq_zero] }\n\n@[simp] lemma circulant_single\n  (n) [semiring \u03b1] [decidable_eq n] [add_group n] [fintype n] (a : \u03b1) :\n  circulant (pi.single 0 a : n \u2192 \u03b1) = scalar n a :=\nbegin\n  ext i j,\n  simp [pi.single_apply, one_apply, sub_eq_zero],\nend\n\n/-- Note we use `\u2191i = 0` instead of `i = 0` as `fin 0` has no `0`.\nThis means that we cannot state this with `pi.single` as we did with `matrix.circulant_single`. -/\nlemma fin.circulant_ite (\u03b1) [has_zero \u03b1] [has_one \u03b1] :\n  \u2200 n, circulant (\u03bb i, ite (\u2191i = 0) 1 0 : fin n \u2192 \u03b1) = 1\n| 0     := dec_trivial\n| (n+1) :=\nbegin\n  rw [\u2190circulant_single_one],\n  congr' with j,\n  simp only [pi.single_apply, fin.ext_iff],\n  congr\nend\n\n/-- A circulant of `v` is symmetric iff `v` equals its reverse. -/\nlemma circulant_is_symm_iff [add_group n] {v : n \u2192 \u03b1} :\n  (circulant v).is_symm \u2194 \u2200 i, v (- i) = v i :=\nby rw [is_symm, transpose_circulant, circulant_inj, funext_iff]\n\nlemma fin.circulant_is_symm_iff :\n  \u2200 {n} {v : fin n \u2192 \u03b1}, (circulant v).is_symm \u2194 \u2200 i, v (- i) = v i\n| 0     := \u03bb v, by simp [is_symm.ext_iff, is_empty.forall_iff]\n| (n+1) := \u03bb v, circulant_is_symm_iff\n\n/-- If `circulant v` is symmetric, `\u2200 i j : I, v (- i) = v i`. -/\nlemma circulant_is_symm_apply [add_group n] {v : n \u2192 \u03b1} (h : (circulant v).is_symm) (i : n) :\n  v (-i) = v i :=\ncirculant_is_symm_iff.1 h i\n\nlemma fin.circulant_is_symm_apply {n} {v : fin n \u2192 \u03b1} (h : (circulant v).is_symm) (i : fin n) :\n  v (-i) = v i :=\nfin.circulant_is_symm_iff.1 h i\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/circulant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.749162047572751}}
{"text": "/-\nCopyright (c) 2019 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.stream.basic\nimport Mathlib.tactic.default\nimport Mathlib.data.nat.gcd\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# The Fibonacci Sequence\n\n## Summary\n\nDefinition of the Fibonacci sequence `F\u2080 = 0, F\u2081 = 1, F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081`.\n\n## Main Definitions\n\n- `fib` returns the stream of Fibonacci numbers.\n\n## Main Statements\n\n- `fib_succ_succ` : shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.`.\n- `fib_gcd`       : `fib n` is a strong divisibility sequence.\n\n## Implementation Notes\n\nFor efficiency purposes, the sequence is defined using `stream.iterate`.\n\n## Tags\n\nfib, fibonacci\n-/\n\nnamespace nat\n\n\n/-- Auxiliary function used in the definition of `fib_aux_stream`. -/\n/-- Auxiliary stream creating Fibonacci pairs `\u27e8F\u2099, F\u2099\u208a\u2081\u27e9`. -/\n/--\nImplementation of the fibonacci sequence satisfying\n`fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`.\n\n*Note:* We use a stream iterator for better performance when compared to the naive recursive\nimplementation.\n-/\ndef fib (n : \u2115) : \u2115 := prod.fst (fib_aux_stream n)\n\n@[simp] theorem fib_zero : fib 0 = 0 := rfl\n\n@[simp] theorem fib_one : fib 1 = 1 := rfl\n\n@[simp] theorem fib_two : fib (bit0 1) = 1 := rfl\n\n/-- Shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.` -/\ntheorem fib_succ_succ {n : \u2115} : fib (n + bit0 1) = fib n + fib (n + 1) := sorry\n\ntheorem fib_pos {n : \u2115} (n_pos : 0 < n) : 0 < fib n := sorry\n\ntheorem fib_le_fib_succ {n : \u2115} : fib n \u2264 fib (n + 1) := sorry\n\ntheorem fib_mono : monotone fib := monotone_of_monotone_nat fun (_x : \u2115) => fib_le_fib_succ\n\ntheorem le_fib_self {n : \u2115} (five_le_n : bit1 (bit0 1) \u2264 n) : n \u2264 fib n := sorry\n\n/-- Subsequent Fibonacci numbers are coprime,\n  see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/\ntheorem fib_coprime_fib_succ (n : \u2115) : coprime (fib n) (fib (n + 1)) := sorry\n\n/-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/\ntheorem fib_add (m : \u2115) (n : \u2115) : fib m * fib n + fib (m + 1) * fib (n + 1) = fib (m + n + 1) :=\n  sorry\n\ntheorem gcd_fib_add_self (m : \u2115) (n : \u2115) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) := sorry\n\ntheorem gcd_fib_add_mul_self (m : \u2115) (n : \u2115) (k : \u2115) :\n    gcd (fib m) (fib (n + k * m)) = gcd (fib m) (fib n) :=\n  sorry\n\n/-- `fib n` is a strong divisibility sequence,\n  see https://proofwiki.org/wiki/GCD_of_Fibonacci_Numbers -/\ntheorem fib_gcd (m : \u2115) (n : \u2115) : fib (gcd m n) = gcd (fib m) (fib n) := sorry\n\ntheorem fib_dvd (m : \u2115) (n : \u2115) (h : m \u2223 n) : fib m \u2223 fib n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (fib m \u2223 fib n)) (propext gcd_eq_left_iff_dvd)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (fib m) (fib n) = fib m)) (Eq.symm (fib_gcd m n))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (fib (gcd m n) = fib m)) (iff.mp gcd_eq_left_iff_dvd h)))\n        (Eq.refl (fib m))))\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/nat/fib_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7491620455877798}}
{"text": "import data.real.basic\nimport data.set.basic\n\nopen finset\n\n-- We think of social states as type `\u03c3` and inidividuals as type `\u03b9`\nvariables {\u03c3 \u03b9 : Type*}\n\n/-! \n## Notes\n\n* \"All individuals rank\" refers to the rankings of each and every individual. \n* \"Society ranks\" refers to output of a social welfare function \n  (e.g. the final result of an election process).\n* <Andrew: Can you please write something describing what a social welfare function is? Thanks!>\n\n## Important Definitions\n-/\n\n/-- A social welfare function satisfies the Weak Pareto criterion if, for any two social states \n  `x` and `y`, every individual ranking `y` higher than `x` implies that society ranks `y` higher \n  than `x`. -/\ndef weak_pareto (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 \u03c3 \u2192 \u211d) (X : finset \u03c3) : Prop := \n\u2200 (x y \u2208 X) (P : \u03b9 \u2192 \u03c3 \u2192 \u211d), (\u2200 i, P i x < P i y) \u2192 (f P) x < (f P) y\n\n/-- Suppose that for any two social states `x` and `y`, every individual's ranking of `x` and `y`\n  remains unchanged between two rankings `P\u2081` and `P\u2082`. We say that a social welfare function is \n  *independent of irrelevant alternatives* if society's ranking of `x` and `y` also remains \n  unchanged between `P\u2081` and `P\u2082`. -/\ndef ind_of_irr_alts (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 \u03c3 \u2192 \u211d) (X : finset \u03c3) : Prop := \n\u2200 (x y \u2208 X) (P\u2081 P\u2082 : \u03b9 \u2192 \u03c3 \u2192 \u211d), \n  (\u2200 i, P\u2081 i x < P\u2081 i y \u2194 P\u2082 i x < P\u2082 i y) \u2192 (f P\u2081 x < f P\u2081 y \u2194 f P\u2082 x < f P\u2082 y)\n\n/-- An individual is a *dictator* with respect to a given social welfare function if their \n  ranking determines society's ranking of any two social states. -/\ndef is_dictator (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 \u03c3 \u2192 \u211d) (X : finset \u03c3) (i : \u03b9) : Prop :=\n\u2200 (x y \u2208 X) (P : \u03b9 \u2192 \u03c3 \u2192 \u211d), P i x < P i y \u2192 f P x < f P y\n\n/-- A social welfare function is called a *dictatorship* if there exists a dictator with respect to\n that function. -/\ndef is_dictatorship (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 \u03c3 \u2192 \u211d) (X : finset \u03c3) : Prop :=\n\u2203 i, is_dictator f X i\n\n/-- An individual is a dictator over all social states in a given set *except* `b` \n  if they are a dictator over every pair of distinct alternatives not equal to `b`.  -/\ndef is_dictator_except (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 (\u03c3 \u2192 \u211d)) (X : finset \u03c3) (i : \u03b9) (b : \u03c3) : Prop := \n\u2200 a c \u2208 X, a \u2260 b \u2192 c \u2260 b \u2192 \u2200 P : \u03b9 \u2192 \u03c3 \u2192 \u211d, P i a < P i c \u2192 f P a < f P c\n\n/-- A social welfare function is called a dictatorship over all social states in a given set \n  *except* `b` if there exists a dictator over every pair of distinct alternatives not equal \n  to `b`.  -/\ndef is_dictatorship_except (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 (\u03c3 \u2192 \u211d)) (X : finset \u03c3) (b : \u03c3) : Prop := \n\u2203 i, is_dictator_except f X i b\n\n/-- A social state `b` is *strictly worst* of a finite set of social states `X` with respect to \n  a ranking `p` if `b` is ranked strictly lower than every other `a \u2208 X`. -/\ndef is_strictly_worst (b : \u03c3) (p : \u03c3 \u2192 \u211d) (X : finset \u03c3) : Prop :=\n\u2200 a \u2208 X, a \u2260 b \u2192 p b < p a\n\n/-- A social state `b` is *strictly best* of a finite set of social states `X` with respect to\n  a ranking `p` if `b` is ranked strictly higher than every other `a \u2208 X`. -/\ndef is_strictly_best (b : \u03c3) (p : \u03c3 \u2192 \u211d) (X : finset \u03c3) : Prop := \n\u2200 a \u2208 X, a \u2260 b \u2192 p a < p b\n\n/-- A social state `b` is *extremal* with respect to a finite set of social states `X` \n  and a ranking `p` if `b` is either bottom or top of `X`. -/\ndef is_extremal (b : \u03c3) (p : \u03c3 \u2192 \u211d) (X : finset \u03c3) : Prop := \nis_strictly_worst b p X \u2228 is_strictly_best b p X\n\n/-- Social sates `s\u2081`, `s\u2082`, `s\u2083`, and `s\u2084` have the *same order* with respect to two rankings \n  `p\u2081` and `p\u2082` if `s\u2081` and `s\u2082` have the same ranking in `p\u2081` as `s\u2083` and `s\u2084` have in `p\u2082`. -/\ndef same_order (p\u2081 p\u2082 : \u03c3 \u2192 \u211d) (s\u2081 s\u2082 s\u2083 s\u2084 : \u03c3) : Prop :=\n(p\u2081 s\u2081 < p\u2081 s\u2082 \u2194 p\u2082 s\u2083 < p\u2082 s\u2084) \u2227 (p\u2081 s\u2082 < p\u2081 s\u2081 \u2194 p\u2082 s\u2084 < p\u2082 s\u2083)\n\n/-- An individual `i` is *pivotal* with respect to a social welfare function and a social state `b`\n  if there exist rankings `P` and `P'` such that: \n  (1) all individuals except for `i` rank all social states in the same order in both rankings\n  (2) all individuals place `b` in an extremal position in both rankings\n  (3) `i` ranks `b` bottom of their rankings in `P`, but top of their rankings in `P'`\n  (4) society ranks `b` bottom of its rankings in `P`, but top of its rankings in `P'` -/\ndef is_pivotal (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 (\u03c3 \u2192 \u211d)) (X : finset \u03c3) (i : \u03b9) (b : \u03c3) : Prop := \n\u2203 (P P' : \u03b9 \u2192 \u03c3 \u2192 \u211d),\n  (\u2200 j : \u03b9, j \u2260 i \u2192 \u2200 x y \u2208 X, same_order (P j) (P' j) x y x y) \u2227 \n    (\u2200 j : \u03b9, is_extremal b (P j) X) \u2227 (\u2200 j : \u03b9, is_extremal b (P' j) X) \u2227\n      (is_strictly_worst b (P i) X) \u2227 (is_strictly_best b (P' i) X) \u2227 \n        (is_strictly_worst b (f P) X) \u2227 (is_strictly_best b (f P') X)\n\n/-- A social welfare function has a *pivot* with respect to a social state `b` if there exists an\n  individual who is pivotal with respect to that function and `b`. -/\ndef has_pivot (f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 (\u03c3 \u2192 \u211d)) (X : finset \u03c3) (b : \u03c3) : Prop := \n\u2203 i, is_pivotal f X i b\n\nopen function\n\n/-- Given an arbitary ranking `p`, social state `b`, and finite set of social states `X`,\n  `maketop b p X` updates `p` so that `b` is now ranked at the top of `X`. -/\nnoncomputable def maketop [decidable_eq \u03c3] \n  (p : \u03c3 \u2192 \u211d) (b : \u03c3) (X : finset \u03c3) (hX : X.nonempty) : \u03c3 \u2192 \u211d :=\nupdate p b $ ((X.image p).max' (hX.image p)) + 1\n\n/-- Given an arbitary ranking `p`, social state `b`, and finite set of social states `X`,\n  `makebot b p X` updates `p` so that `b` is now ranked at the bottom of `X`. -/\nnoncomputable def makebot [decidable_eq \u03c3]\n  (p : \u03c3 \u2192 \u211d) (b : \u03c3) (X : finset \u03c3) (hX : X.nonempty) : \u03c3 \u2192 \u211d :=\nupdate p b $ ((X.image p).min' (hX.image p)) - 1\n\n/-- Given an arbitary ranking `p` and social states `a`, `b`, and `c`, \n  `makebetween p a b c` updates `p` so that `b` is now ranked between `a` and `c`. -/\nnoncomputable def makebetween [decidable_eq \u03c3] \n  (p : \u03c3 \u2192 \u211d) (a b c : \u03c3) : \u03c3 \u2192 \u211d :=\nupdate p b $ (p a + p c) / 2\n\n\n-- ## Preliminary Lemmas\n\nvariables {a b c d : \u03c3} {p : \u03c3 \u2192 \u211d} {P : \u03b9 \u2192 \u03c3 \u2192 \u211d} {f : (\u03b9 \u2192 \u03c3 \u2192 \u211d) \u2192 \u03c3 \u2192 \u211d} {X : finset \u03c3}\n\nlemma exists_second_distinct_mem (hX : 2 \u2264 X.card) (a_in : a \u2208 X) :\n  \u2203 b \u2208 X, b \u2260 a :=\nbegin\n  classical,\n  have hpos : 0 < (X.erase a).card,\n  { rw card_erase_of_mem a_in,\n    exact zero_lt_one.trans_le (nat.pred_le_pred hX) },\n  cases card_pos.mp hpos with b hb,\n  cases mem_erase.mp hb with hne H,\n  exact \u27e8b, H, hne\u27e9,\nend\n\nlemma exists_third_distinct_mem (hX : 2 < X.card) (a_in : a \u2208 X) (b_in : b \u2208 X) (h : a \u2260 b) : \n  \u2203 c \u2208 X, c \u2260 a \u2227 c \u2260 b :=\nbegin\n  classical,\n  have hpos : 0 < ((X.erase b).erase a).card,\n  { simpa only [card_erase_of_mem, mem_erase_of_ne_of_mem h a_in, b_in]\n      using nat.pred_le_pred (nat.pred_le_pred hX) }, \n  cases card_pos.mp hpos with c hc,\n  simp_rw mem_erase at hc,\n  exact \u27e8c, hc.2.2, hc.1, hc.2.1\u27e9,\nend\n\nlemma is_strictly_best.not_strictly_worst (htop : is_strictly_best b p X) (h : \u2203 a \u2208 X, a \u2260 b) : \u00acis_strictly_worst b p X :=\nbegin\n  simp only [is_strictly_worst, not_forall, not_lt, exists_prop],\n  rcases h with \u27e8a, a_in, hab\u27e9,\n  exact \u27e8a, a_in, hab, (htop a a_in hab).le\u27e9,\nend\n\nlemma is_strictly_best.not_strictly_worst' (htop : is_strictly_best b p X) (hX : 2 \u2264 X.card) (hb : b \u2208 X) : \u00acis_strictly_worst b p X :=\nhtop.not_strictly_worst $ exists_second_distinct_mem hX hb\n\nlemma is_strictly_worst.not_strictly_best (hbot : is_strictly_worst b p X) (h : \u2203 a \u2208 X, a \u2260 b) : \u00acis_strictly_best b p X :=\nbegin\n  simp only [is_strictly_best, not_forall, not_lt, exists_prop],\n  rcases h with \u27e8a, a_in, hab\u27e9,\n  exact \u27e8a, a_in, hab, (hbot a a_in hab).le\u27e9,\nend\n\nlemma is_strictly_worst.not_strictly_best' (hbot : is_strictly_worst b p X) (hX : 2 \u2264 X.card) (hb : b \u2208 X) : \u00acis_strictly_best b p X :=\nhbot.not_strictly_best $ exists_second_distinct_mem hX hb\n\nlemma is_extremal.is_strictly_best (hextr : is_extremal b p X) (not_strictly_worst : \u00acis_strictly_worst b p X) :\n  is_strictly_best b p X := \nhextr.resolve_left not_strictly_worst \n\nlemma is_extremal.is_strictly_worst (hextr : is_extremal b p X) (not_strictly_best : \u00acis_strictly_best b p X) :\n  is_strictly_worst b p X := \nhextr.resolve_right not_strictly_best \n\nlemma is_strictly_worst.is_extremal (hbot : is_strictly_worst b p X) : is_extremal b p X := \nor.inl hbot\n\nlemma is_strictly_best.is_extremal (hbot : is_strictly_best b p X) : is_extremal b p X := \nor.inr hbot\n\n/-- If every individual ranks a social state `b` at the top of its rankings, then society must also\n  rank `b` at the top of its rankings. -/\ntheorem is_strictly_best_of_forall_is_strictly_best (b_in : b \u2208 X) (hwp : weak_pareto f X)\n  (htop : \u2200 i, is_strictly_best b (P i) X) :\n  is_strictly_best b (f P) X :=\n\u03bb a a_in hab, hwp a b a_in b_in P $ \u03bb i, htop i a a_in hab\n\n/-- If every individual ranks a social state `b` at the bottom of its rankings, then society must \n  also rank `b` at the bottom of its rankings. -/\ntheorem is_strictly_worst_of_forall_is_strictly_worst (b_in : b \u2208 X) (hwp : weak_pareto f X) \n  (hbot : \u2200 i, is_strictly_worst b (P i) X) :\n  is_strictly_worst b (f P) X :=\n\u03bb a a_in hab, hwp b a b_in a_in P $ \u03bb i, hbot i a a_in hab\n\nlemma exists_of_not_extremal (hX : 3 \u2264 X.card) (hb : b \u2208 X) (h : \u00ac is_extremal b (f P) X):\n  \u2203 a c \u2208 X, a \u2260 b \u2227 c \u2260 b \u2227 a \u2260 c \u2227 f P b \u2264 f P a \u2227 f P c \u2264 f P b := \nbegin\n  unfold is_extremal is_strictly_worst is_strictly_best at h, push_neg at h,\n  obtain \u27e8\u27e8c, hc, hcb, hPc\u27e9, \u27e8a, ha, hab, hPa\u27e9\u27e9 := h,\n  obtain hac | rfl := ne_or_eq a c, { exact \u27e8a, c, ha, hc, hab, hcb, hac, hPa, hPc\u27e9 },\n  obtain \u27e8d, hd, hda, hdb\u27e9 := exists_third_distinct_mem hX ha hb hab,\n  cases lt_or_le (f P b) (f P d),\n  { exact \u27e8d, a, hd, hc, hdb, hcb, hda, h.le, hPc\u27e9 },\n  { exact \u27e8a, d, ha, hd, hab, hdb, hda.symm, hPa, h\u27e9 },\nend\n\nlemma nonempty_of_mem {s : finset \u03c3} {a : \u03c3} (ha : a \u2208 s) : s.nonempty := \nnonempty_of_ne_empty $ ne_empty_of_mem ha\n\nsection make\n\nvariable [decidable_eq \u03c3]\n\nlemma maketop_noteq (p) (hab : a \u2260 b) (hX : X.nonempty) :\n  maketop p b X hX a = p a := \nupdate_noteq hab _ p\n\nlemma makebot_noteq (p) (hab : a \u2260 b) (hX : X.nonempty) :\n  makebot p b X hX a = p a := \nupdate_noteq hab _ p\n\nlemma makebetween_noteq (p) (hdb : d \u2260 b) :\n  makebetween p a b c d = p d :=\nupdate_noteq hdb ((p a + p c) / 2) p\n\nlemma makebetween_eq (a b c : \u03c3) (p) :\n  makebetween p a b c b = (p a + p c) / 2 :=\nupdate_same _ _ _\n\nlemma maketop_lt_maketop (p) (hab : a \u2260 b) (ha : a \u2208 X) : \n  maketop p b X (nonempty_of_mem ha) a < maketop p b X (nonempty_of_mem ha) b :=\nby simpa [maketop, hab] using \n  ((X.image p).le_max' _ (mem_image_of_mem p ha)).trans_lt (lt_add_one _)\n\nlemma makebot_lt_makebot (p) (hcb : c \u2260 b) (hc : c \u2208 X) : \n  makebot p b X (nonempty_of_mem hc) b < makebot p b X (nonempty_of_mem hc) c :=\nby simpa [makebot, hcb] using sub_lt_iff_lt_add'.mpr\n  (((X.image p).min'_le (p c) (mem_image_of_mem p hc)).trans_lt (lt_one_add _))\n\nlemma makebetween_lt_makebetween_top (hcb : c \u2260 b) (hp : p a < p c) : \n  makebetween p a b c b < makebetween p a b c c :=\nbegin\n  simp only [makebetween, update_same, update_noteq hcb],\n  linarith,\nend\n\nlemma makebetween_lt_makebetween_bot (hab : a \u2260 b) (hp : p a < p c) : \n  makebetween p a b c a < makebetween p a b c b :=\nbegin\n  simp only [makebetween, update_same, update_noteq hab],\n  linarith,\nend\n\nlemma top_of_maketop (b p) (hX : X.nonempty) :\n  is_strictly_best b (maketop p b X hX) X := \n\u03bb a ha hab, maketop_lt_maketop p hab ha\n\nend make\n\n-- ## The Proof\n\n/-- Let `f` be a SWF satisfying WP and IoIA, `P` be a preference ordering, `X` be a finite set\n  containing at least 3 social states, and `b` be one of those social states.\n  If every individial ranks `b` extremally, then society also ranks `b` extremally w.r.t. `f`. -/\nlemma first_step (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X)\n  (hX : 3 \u2264 X.card) (hb : b \u2208 X) (hextr : \u2200 i, is_extremal b (P i) X) :\n  is_extremal b (f P) X := \nbegin\n  classical,\n  by_contra hnot,\n  obtain \u27e8a, c, ha, hc, hab, hcb, hac, hPa, hPc\u27e9 := exists_of_not_extremal hX hb hnot,\n  refine ((not_lt.mp ((not_congr (hind b c hb hc P _ (\u03bb i, \u27e8\u03bb hP, _, \u03bb hP', _\u27e9))).mp\n    hPc.not_lt)).trans (not_lt.mp ((not_congr (hind a b ha hb P _ (\u03bb i, \u27e8\u03bb hP, _, \u03bb hP', _\u27e9))).mp\n      hPa.not_lt))).not_lt (hwp a c ha hc _ (\u03bb i, _)),\n  { exact \u03bb j, if is_strictly_best b (P j) X then makebetween (P j) a c b else update (P j) c (P j a + 1) },\n  { have h : \u00ac is_strictly_best b (P i) X := \u03bb h, asymm hP (h c hc hcb),\n    convert lt_add_of_lt_of_pos ((hextr i).is_strictly_worst h a ha hab) _; simp [h, hcb.symm] },\n  { by_contra hP,\n    have h : is_strictly_best b (P i) X := (hextr i).is_strictly_best (\u03bb h, hP (h c hc hcb)),\n    simp only at hP', simp only [if_pos h, makebetween_noteq _ hcb.symm, makebetween_eq] at hP',\n    linarith [h a ha hab] },\n  { by_cases h : is_strictly_best b (P i) X; simpa [h, makebetween_noteq, hac, hcb.symm] },\n  { by_contra hP,\n    have h : \u00ac is_strictly_best b (P i) X := \u03bb h, hP (h a ha hab),\n    simp only at hP', simp [if_neg h, hac, hcb.symm] at hP',\n    exact hP hP' },\n  { by_cases h : is_strictly_best b (P i) X,\n    { simp [if_pos h, makebetween_lt_makebetween_bot hac (h a ha hab)] },\n    { simp [if_neg h, hac] } },\nend  \n\n/-- An auxiliary lemma for the second step, in which we perform induction on the finite set\n  `D' := {i \u2208 univ | is_strictly_worst b (P i) X}`. Its statement is formulated so strangely (involving `D'` \n  and `P`) to allow for this induction. \n  Essentially, what we are doing here is showing that, for a social welfare function `f` under the\n  appropriate conditions, we can always a construct circumstances so that `f` has a pivot with\n  respect to a given social state. -/\nlemma second_step_aux [fintype \u03b9]\n  (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X)\n  (hX : 2 < X.card) (b_in : b \u2208 X) {D' : finset \u03b9} :\n  \u2200 {P : \u03b9 \u2192 \u03c3 \u2192 \u211d}, D' = {i \u2208 univ | is_strictly_worst b (P i) X} \u2192 \n    (\u2200 i, is_extremal b (P i) X) \u2192 is_strictly_worst b (f P) X \u2192 has_pivot f X b := \nbegin\n  classical,\n  refine finset.induction_on D'\n    (\u03bb P h hextr hbot, absurd (is_strictly_best_of_forall_is_strictly_best b_in hwp (\u03bb j, (hextr j).is_strictly_best _))\n                              (hbot.not_strictly_best (exists_second_distinct_mem hX.le b_in))) \n    (\u03bb i D hi IH P h_insert hextr hbot, _),\n  { simpa using eq_empty_iff_forall_not_mem.mp h.symm j },\n  { have hX' := nonempty_of_mem b_in,\n    have hextr' : \u2200 j, is_extremal b (ite (j = i) (maketop (P j) b X hX') (P j)) X,\n    { intro j,\n      by_cases hji : j = i,\n      { refine or.inr (\u03bb a a_in hab, _),\n        simp only [if_pos hji, maketop_lt_maketop _ hab a_in] },\n      { simp only [if_neg hji, hextr j] } },\n    by_cases hP' : is_strictly_best b (f (\u03bb j, ite (j = i) (maketop (P j) b X hX') (P j))) X,\n    { refine \u27e8i, P, _, \u03bb j hj x y _ _, _, hextr, hextr', _, _, hbot, hP'\u27e9,\n      { simp [same_order, if_neg hj] },\n      { have : i \u2208 {j \u2208 univ | is_strictly_worst b (P j) X}, { rw \u2190 h_insert, exact mem_insert_self i D },\n        simpa },\n      { simp [top_of_maketop, hX'] } },\n    { refine IH _ hextr' ((first_step hwp hind hX b_in hextr').is_strictly_worst hP'),\n      ext j,\n      simp only [true_and, sep_def, mem_filter, mem_univ],\n      split; intro hj,\n      { suffices : j \u2208 insert i D,\n        { have hji : j \u2260 i, { rintro rfl, exact hi hj },\n          rw h_insert at this,\n          simpa [hji] },\n        exact mem_insert_of_mem hj },\n      { have hji : j \u2260 i,\n        { rintro rfl,\n          obtain \u27e8a, a_in, hab\u27e9 := exists_second_distinct_mem hX.le b_in,\n          apply asymm (top_of_maketop b (P j) hX' a a_in hab),\n          simpa using hj a a_in hab },\n        rw [\u2190 erase_insert hi, h_insert],\n        simpa [hji] using hj } } }, \nend \n\n/-- Let `f` be a SWF satisfying WP and IoIA, and `X` be a finite set containing at least 3 social states.\n  Then `f` has a pivot w.r.t. every social state in `X`. -/\nlemma second_step [fintype \u03b9]\n  (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X)\n  (hX : 3 \u2264 X.card) (b) (b_in : b \u2208 X) :\n  has_pivot f X b := \nbegin\n  classical,\n  have hbot : is_strictly_worst b (\u03bb x, ite (x = b) 0 1) X := \u03bb _ _ h, by simp [h],\n  exact second_step_aux hwp hind hX b_in rfl (\u03bb i, hbot.is_extremal) \n    (is_strictly_worst_of_forall_is_strictly_worst b_in hwp (\u03bb i, hbot)),\nend\n\n/-- Let `f` be a SWF satisfying IoIA, `X` be a finite set of social states, and `b` be one of those \n  social states.\n  If an individual `i` is pivotal w.r.t. `f` and `b`, then `i` is a dictator over all social states\n  in `X` except `b`. -/\nlemma third_step (hind : ind_of_irr_alts f X) \n  (hb : b \u2208 X) {i : \u03b9} (hpiv : is_pivotal f X i b) :\n  is_dictator_except f X i b :=\nbegin\n  intros a c ha hc hab hcb Q hyp,\n  obtain \u27e8P, P', hpiv\u27e9 := hpiv,\n  have hX := nonempty_of_mem hb,\n  classical,\n  let Q' := \u03bb j, \n    if j = i \n      then makebetween (Q j) a b c\n    else \n      if is_strictly_worst b (P j) X \n        then makebot (Q j) b X hX\n      else maketop (Q j) b X hX,\n  refine (hind a c ha hc Q Q' (\u03bb j, _)).mpr\n    (((hind a b ha hb P' Q' (\u03bb j, _)).mp (hpiv.2.2.2.2.2.2 a ha hab)).trans\n      ((hind b c hb hc P Q' (\u03bb j, _)).mp (hpiv.2.2.2.2.2.1 c hc hcb))),\n  { suffices : \u2200 d \u2260 b, Q j d = Q' j d, { rw [this, this]; assumption },\n    intros d hdb,\n    by_cases hj : j = i; simp only [Q', if_pos, hj, dite_eq_ite], \n    { exact (makebetween_noteq (Q i) hdb).symm },\n    { by_cases hbot : is_strictly_worst b (P j) X; simp only [if_neg hj],\n      { rw [\u2190 makebot_noteq (Q j) hdb hX, if_pos hbot] },\n      { rw [\u2190 maketop_noteq (Q j) hdb hX, if_neg hbot] } } },\n  { refine \u27e8\u03bb hP', _, \u03bb hQ', _\u27e9; by_cases hj : j = i,\n    { simpa [Q', if_pos, hj] using makebetween_lt_makebetween_bot hab hyp },\n    { have hbot : \u00ac is_strictly_worst b (P j) X := \u03bb h, asymm ((hpiv.1 j hj a b ha hb).1.2 hP') (h a ha hab),\n      simpa [Q', if_neg, hj, hbot] using maketop_lt_maketop (Q j) hab ha },\n    { convert hpiv.2.2.2.2.1 a ha hab },\n    { refine (hpiv.1 j hj a b ha hb).1.1 ((hpiv.2.1 j).is_strictly_best \n        (\u03bb hbot, asymm (makebot_lt_makebot (Q j) hab ha) _) a ha hab), \n      convert hQ'; simp [Q', if_neg hj, if_pos hbot] } },\n  { refine \u27e8\u03bb hP, _, \u03bb hQ', _\u27e9; by_cases hj : j = i,\n    { simpa [Q', if_pos, hj] using makebetween_lt_makebetween_top hcb hyp },\n    { have hbot : is_strictly_worst b (P j) X,\n      { unfold is_strictly_worst,\n        by_contra hbot, push_neg at hbot,\n        obtain \u27e8d, hd, hdb, h\u27e9 := hbot,\n        cases hpiv.2.1 j with hbot htop,\n        { exact (hbot d hd hdb).not_le h },\n        { exact (irrefl _) ((htop c hc hcb).trans hP) } },\n      simpa [Q', if_neg hj, if_pos hbot] using makebot_lt_makebot (Q j) hcb hc },\n    { convert hpiv.2.2.2.1 c hc hcb },\n    { by_contra hP,\n      have hbot : \u00ac is_strictly_worst b (P j) X := \u03bb h, hP (h c hc hcb),\n      apply asymm (maketop_lt_maketop (Q j) hcb hc),\n      convert hQ'; simp [Q', if_neg, hbot, hj] } },\nend\n\n/-- Let `f` be a SWF satisfying IoIA, and `X` be a finite set containing at least 3 social states. \n  If `f` has a pivot for every social state in `X`, then `f` is a dictatorship. -/\nlemma fourth_step (hind : ind_of_irr_alts f X)\n  (hX : 3 \u2264 X.card) (hpiv : \u2200 b \u2208 X, has_pivot f X b) : \n  is_dictatorship f X := \nbegin\n  obtain \u27e8b, hb\u27e9 := (card_pos.1 (zero_lt_two.trans hX)).bex,\n  obtain \u27e8i, ipiv\u27e9 := hpiv b hb,\n  have h : \u2200 a \u2208 X, a \u2260 b \u2192 \u2200 P\u1d62 : \u03b9 \u2192 \u03c3 \u2192 \u211d, \n          (P\u1d62 i a < P\u1d62 i b \u2192 f P\u1d62 a < f P\u1d62 b) \u2227 (P\u1d62 i b < P\u1d62 i a \u2192 f P\u1d62 b < f P\u1d62 a), -- we should have a better way of stating this that doesn't require the and (i.e. stated WLOG)\n  { intros a ha hab P\u1d62,\n    obtain \u27e8c, hc, hca, hcb\u27e9 := exists_third_distinct_mem hX ha hb hab,\n    obtain \u27e8hac, hbc\u27e9 := \u27e8hca.symm, hcb.symm\u27e9,\n    obtain \u27e8j, jpiv\u27e9 := hpiv c hc,\n    obtain hdict := third_step hind hc jpiv,\n    obtain rfl : j = i,\n    { by_contra hji,\n      obtain \u27e8R, R', hso, hextr, -, -, -, hbot, htop\u27e9 := ipiv,\n      refine asymm (htop a ha hab) (hdict b a hb ha hbc hac R' ((hso j hji a b ha hb).2.1 _)),\n      by_contra hnot,\n      have h := (hextr j).resolve_left,\n      simp only [is_strictly_best, is_strictly_worst, and_imp, exists_imp_distrib, not_forall] at h,\n      exact asymm (hbot a ha hab) (hdict a b ha hb hac hbc R (h a ha hab hnot a ha hab)) },\n    split; apply hdict; assumption },\n  refine \u27e8i, \u03bb x y hx hy P\u1d62 hP\u1d62, _\u27e9,\n  rcases eq_or_ne b x with rfl | hbx; rcases eq_or_ne b y with rfl | hby,\n  { exact ((irrefl _) hP\u1d62).rec _ },\n  { exact (h y hy hby.symm P\u1d62).2 hP\u1d62 },\n  { exact (h x hx hbx.symm P\u1d62).1 hP\u1d62 },\n  { exact third_step hind hb ipiv x y hx hy hbx.symm hby.symm P\u1d62 hP\u1d62 },\nend\n\n/-- Arrow's Impossibility Theorem: Any social welfare function involving at least three social\n  states that satisfies WP and IoIA is necessarily a dictatorship. -/\ntheorem arrow [fintype \u03b9]\n  (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X) (hX : 3 \u2264 X.card) :\n  is_dictatorship f X := \nfourth_step hind hX $ second_step hwp hind hX\n", "meta": {"author": "asouther4", "repo": "lean-social-choice", "sha": "9906ade382ace77af4fef1edb70364b84f7afd9c", "save_path": "github-repos/lean/asouther4-lean-social-choice", "path": "github-repos/lean/asouther4-lean-social-choice/lean-social-choice-9906ade382ace77af4fef1edb70364b84f7afd9c/src/deprecated/arrows_cardinal_prefs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7491208737250701}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones\n-- 1. Importar la librer\u00eda tactic\n-- 2. Abrir el espacio de nombres set\n-- 3. Declarar u y v como variables de universos.\n-- 4. Declarar \u03b1 como una variable de tipos en u.\n-- 5. Declarar I como una variable de tipos en v.\n-- 6. Declarar A y B como variables sobre funciones de I en \u03b1.\n-- 7. Declarar s como variable sobre conjuntos de elementos de \u03b1. \n-- 8. Usar la l\u00f3gica cl\u00e1sica.\n-- ----------------------------------------------------------------------\n\nimport tactic                 -- 1\nopen set                      -- 2\nuniverses u v                 -- 3\nvariable (\u03b1 : Type u)         -- 4\nvariable (I : Type v)         -- 5\nvariables (A B : I \u2192 set \u03b1)   -- 6\nvariable  s : set \u03b1           -- 7\nopen_locale classical         -- 8\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s)\n-- ----------------------------------------------------------------------\n\nexample : s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s) :=\nbegin\n  ext x,\n  simp only [mem_union, mem_Inter],\n  split,\n  { rintros (xs | xI),\n    { intro i, \n      right, \n      exact xs },\n    { intro i, \n      left, \n      exact xI i }},\n  { intro h,\n    by_cases xs : x \u2208 s,\n    { left, \n      exact xs },\n    { right,\n      intro i,\n      cases h i,\n      { assumption },\n      { contradiction }}},\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u,\nI : Type v,\nA : I \u2192 set \u03b1,\ns : set \u03b1\n\u22a2 (s \u222a \u22c2 (i : I), A i) = \u22c2 (i : I), A i \u222a s\n  >> ext x,\nx : \u03b1\n\u22a2 (x \u2208 s \u222a \u22c2 (i : I), A i) \u2194 x \u2208 \u22c2 (i : I), A i \u222a s\n  >> simp only [mem_union, mem_Inter],\n\u22a2 (x \u2208 s \u2228 \u2200 (i : I), x \u2208 A i) \u2194 \u2200 (i : I), x \u2208 A i \u2228 x \u2208 s\n  >> split,\n| \u22a2 (x \u2208 s \u2228 \u2200 (i : I), x \u2208 A i) \u2192 \u2200 (i : I), x \u2208 A i \u2228 x \u2208 s\n|   >> { rintros (xs | xI),\n| | xs : x \u2208 s\n| | \u22a2 \u2200 (i : I), x \u2208 A i \u2228 x \u2208 s\n| |   >>   { intro i,\n| | i : I\n| | \u22a2 x \u2208 A i \u2228 x \u2208 s \n| |   >>     right, \n| | \u22a2 x \u2208 s\n| |   >>     exact xs },\n| \u22a2 \u2200 (i : I), x \u2208 A i \u2228 x \u2208 s\n|   >>   { intro i, \n| i : I\n| \u22a2 x \u2208 A i \u2228 x \u2208 s\n|   >>     left, \n| \u22a2 x \u2208 A i\n|   >>     exact xI i }},\n\u22a2 (\u2200 (i : I), x \u2208 A i \u2228 x \u2208 s) \u2192 (x \u2208 s \u2228 \u2200 (i : I), x \u2208 A i)\n  >> { intro h,\nh : \u2200 (i : I), x \u2208 A i \u2228 x \u2208 s\n\u22a2 x \u2208 s \u2228 \u2200 (i : I), x \u2208 A i\n  >>   by_cases xs : x \u2208 s,\n| xs : x \u2208 s\n| \u22a2 x \u2208 s \u2228 \u2200 (i : I), x \u2208 A i\n|   >>   { left, \n| \u22a2 x \u2208 s\n|   >>     exact xs },\nxs : x \u2209 s\n\u22a2 x \u2208 s \u2228 \u2200 (i : I), x \u2208 A i\n  >>   { right,\n\u22a2 \u2200 (i : I), x \u2208 A i\n  >>     intro i,\ni : I\n\u22a2 x \u2208 A i\n  >>     cases h i,\n| h_1 : x \u2208 A i\n| \u22a2 x \u2208 A i\n|   >>     { assumption },\n\u22a2 x \u2208 A i\n  >>     { contradiction }}},\nno goals\n-/\n\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Ejercicios_de_uniones_e_intersecciones_generales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7491208597666406}}
{"text": "import game.sets.sets_level02 -- hide\n\nnamespace xena -- hide\n\nopen_locale classical -- hide\n\nvariable X : Type -- hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 3 : intersection (\u2229)\n-/\n\n\n/- \nNow prove that for any two sets $A$ and $B$, $A \u2229 B \u2286 A$.\n   \nYou will need to rewrite the following term:\n\n```\nmem_inter_iff : x \u2208 A \u2229 B \u2194 x \u2208 A \u2227 x \u2208 B \n```\n-/\n\n/- Axiom : mem_inter_iff :\nx \u2208 A \u2229 B \u2194 x \u2208 A \u2227 x \u2208 B\n-/\n\n/- Hint : Stuck?\nYou need to start the same way as in the previous levels.\nTry and get yourself into a situation where you have a\n*hypothesis* `hAB : x \u2208 A \u2229 B` and then use `rw mem_inter_iff at hAB`. \n-/\n\n/- Hint: A note on `x \u2208 A \u2227 x \u2208 B \u2192 x \u2208 A`\nBy convention, \u2227 binds more tightly than \u2192\n(i.e. `x \u2208 A \u2227 x \u2208 B \u2192 x \u2208 A` means `(x \u2208 A \u2227 x \u2208 B) \u2192 x \u2208 A`)\n-/\n\n/- Hint : Reminder about `cases` \nThe `cases h with hP hQ` tactic turns `h : P \u2227 Q` into `hP : P` and `hQ : Q`\n-/\n\n/- Hint : The `tauto!` tactic\nThe `tauto!` tactic solves goals in propositional logic (i.e. problems where\nthe relevant hypotheses and goal just involve `\u2227`, `\u2228`, `\u00ac` and `\u2192` and\npropositions -- for example it could easily solve this goal:\n\n```\nh : P \u2227 Q\n\u22a2 P\n```\n-/\n\n/- Lemma\nIf $A$ and $B$ are sets of any type $X$, then\n$$ A \\cap B \\subseteq A.$$\n-/\ntheorem intersection_subset (A B : set X) : A \u2229 B \u2286 A  :=\nbegin\n  rw subset_iff,\n  intros x hx,\n  rw mem_inter_iff at hx,\n  tauto!, -- or cases, assumption\n\n\n  \nend\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sets/sets_level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7491172985091922}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n\n! This file was ported from Lean 3 source module number_theory.padics.padic_val\n! leanprover-community/mathlib commit 60fa54e778c9e85d930efae172435f42fb0d71f7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.NumberTheory.Divisors\nimport Mathlib.RingTheory.Int.Basic\n\n/-!\n# p-adic Valuation\n\nThis file defines the `p`-adic valuation on `\u2115`, `\u2124`, and `\u211a`.\n\nThe `p`-adic valuation on `\u211a` is the difference of the multiplicities of `p` in the numerator and\ndenominator of `q`. This function obeys the standard properties of a valuation, with the appropriate\nassumptions on `p`. The `p`-adic valuations on `\u2115` and `\u2124` agree with that on `\u211a`.\n\nThe valuation induces a norm on `\u211a`. This norm is defined in padicNorm.lean.\n\n## Notations\n\nThis file uses the local notation `/.` for `Rat.mk`.\n\n## Implementation notes\n\nMuch, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically\nby taking `[Fact p.Prime]` as a type class argument.\n\n## References\n\n* [F. Q. Gouv\u00eaa, *p-adic numbers*][gouvea1997]\n* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]\n* <https://en.wikipedia.org/wiki/P-adic_number>\n\n## Tags\n\np-adic, p adic, padic, norm, valuation\n-/\n\n\nuniverse u\n\nopen Nat\n\nopen Rat\n\nopen multiplicity\n\n/-- For `p \u2260 1`, the `p`-adic valuation of a natural `n \u2260 0` is the largest natural number `k` such\nthat `p^k` divides `z`. If `n = 0` or `p = 1`, then `padicValNat p q` defaults to `0`. -/\ndef padicValNat (p : \u2115) (n : \u2115) : \u2115 :=\n  if h : p \u2260 1 \u2227 0 < n then (multiplicity p n).get (multiplicity.finite_nat_iff.2 h) else 0\n#align padic_val_nat padicValNat\n\nnamespace padicValNat\n\nopen multiplicity\n\nvariable {p : \u2115}\n\n/-- `padicValNat p 0` is `0` for any `p`. -/\n@[simp]\nprotected \n\n/-- `padicValNat p 1` is `0` for any `p`. -/\n@[simp]\nprotected theorem one : padicValNat p 1 = 0 := by\n  unfold padicValNat\n  split_ifs\n  \u00b7 simp\n  \u00b7 rfl\n#align padic_val_nat.one padicValNat.one\n\n/-- If `p \u2260 0` and `p \u2260 1`, then `padicValNat p p` is `1`. -/\n@[simp]\ntheorem self (hp : 1 < p) : padicValNat p p = 1 := by\n  have neq_one : \u00acp = 1 \u2194 True := iff_of_true hp.ne' trivial\n  have eq_zero_false : p = 0 \u2194 False := iff_false_intro (zero_lt_one.trans hp).ne'\n  simp [padicValNat, neq_one, eq_zero_false]\n#align padic_val_nat.self padicValNat.self\n\n@[simp]\ntheorem eq_zero_iff {n : \u2115} : padicValNat p n = 0 \u2194 p = 1 \u2228 n = 0 \u2228 \u00acp \u2223 n := by\n  simp only [padicValNat, dite_eq_right_iff, PartENat.get_eq_iff_eq_coe, Nat.cast_zero,\n    multiplicity_eq_zero, and_imp, pos_iff_ne_zero, Ne.def, \u2190 or_iff_not_imp_left]\n#align padic_val_nat.eq_zero_iff padicValNat.eq_zero_iff\n\ntheorem eq_zero_of_not_dvd {n : \u2115} (h : \u00acp \u2223 n) : padicValNat p n = 0 :=\n  eq_zero_iff.2 <| Or.inr <| Or.inr h\n#align padic_val_nat.eq_zero_of_not_dvd padicValNat.eq_zero_of_not_dvd\n\nend padicValNat\n\n/-- For `p \u2260 1`, the `p`-adic valuation of an integer `z \u2260 0` is the largest natural number `k` such\nthat `p^k` divides `z`. If `x = 0` or `p = 1`, then `padicValInt p q` defaults to `0`. -/\ndef padicValInt (p : \u2115) (z : \u2124) : \u2115 :=\n  padicValNat p z.natAbs\n#align padic_val_int padicValInt\n\nnamespace padicValInt\n\nopen multiplicity\n\nvariable {p : \u2115}\n\ntheorem of_ne_one_ne_zero {z : \u2124} (hp : p \u2260 1) (hz : z \u2260 0) :\n    padicValInt p z =\n      (multiplicity (p : \u2124) z).get\n        (by\n          apply multiplicity.finite_int_iff.2\n          simp [hp, hz]) := by\n  rw [padicValInt, padicValNat, dif_pos (And.intro hp (Int.natAbs_pos.mpr hz))]\n  simp only [multiplicity.Int.natAbs p z]\n#align padic_val_int.of_ne_one_ne_zero padicValInt.of_ne_one_ne_zero\n\n/-- `padicValInt p 0` is `0` for any `p`. -/\n@[simp]\nprotected theorem zero : padicValInt p 0 = 0 := by simp [padicValInt]\n#align padic_val_int.zero padicValInt.zero\n\n/-- `padicValInt p 1` is `0` for any `p`. -/\n@[simp]\nprotected theorem one : padicValInt p 1 = 0 := by simp [padicValInt]\n#align padic_val_int.one padicValInt.one\n\n/-- The `p`-adic value of a natural is its `p`-adic value as an integer. -/\n@[simp]\ntheorem of_nat {n : \u2115} : padicValInt p n = padicValNat p n := by simp [padicValInt]\n#align padic_val_int.of_nat padicValInt.of_nat\n\n/-- If `p \u2260 0` and `p \u2260 1`, then `padicValInt p p` is `1`. -/\ntheorem self (hp : 1 < p) : padicValInt p p = 1 := by simp [padicValNat.self hp]\n#align padic_val_int.self padicValInt.self\n\ntheorem eq_zero_of_not_dvd {z : \u2124} (h : \u00ac(p : \u2124) \u2223 z) : padicValInt p z = 0 := by\n  rw [padicValInt, padicValNat]\n  split_ifs <;> simp [multiplicity.Int.natAbs, multiplicity_eq_zero.2 h]\n#align padic_val_int.eq_zero_of_not_dvd padicValInt.eq_zero_of_not_dvd\n\nend padicValInt\n\n/-- `padicValRat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the\nvaluation of `q.den`. If `q = 0` or `p = 1`, then `padicValRat p q` defaults to `0`. -/\ndef padicValRat (p : \u2115) (q : \u211a) : \u2124 :=\n  padicValInt p q.num - padicValNat p q.den\n#align padic_val_rat padicValRat\n\nnamespace padicValRat\n\nopen multiplicity\n\nvariable {p : \u2115}\n\n/-- `padicValRat p q` is symmetric in `q`. -/\n@[simp]\nprotected theorem neg (q : \u211a) : padicValRat p (-q) = padicValRat p q := by\n  simp [padicValRat, padicValInt]\n#align padic_val_rat.neg padicValRat.neg\n\n/-- `padicValRat p 0` is `0` for any `p`. -/\n@[simp]\nprotected theorem zero : padicValRat p 0 = 0 := by simp [padicValRat]\n#align padic_val_rat.zero padicValRat.zero\n\n/-- `padicValRat p 1` is `0` for any `p`. -/\n@[simp]\nprotected theorem one : padicValRat p 1 = 0 := by simp [padicValRat]\n#align padic_val_rat.one padicValRat.one\n\n/-- The `p`-adic value of an integer `z \u2260 0` is its `p`-adic_value as a rational. -/\n@[simp]\ntheorem of_int {z : \u2124} : padicValRat p z = padicValInt p z := by simp [padicValRat]\n#align padic_val_rat.of_int padicValRat.of_int\n\n/-- The `p`-adic value of an integer `z \u2260 0` is the multiplicity of `p` in `z`. -/\ntheorem of_int_multiplicity {z : \u2124} (hp : p \u2260 1) (hz : z \u2260 0) :\n    padicValRat p (z : \u211a) = (multiplicity (p : \u2124) z).get (finite_int_iff.2 \u27e8hp, hz\u27e9) := by\n  rw [of_int, padicValInt.of_ne_one_ne_zero hp hz]\n#align padic_val_rat.of_int_multiplicity padicValRat.of_int_multiplicity\n\ntheorem multiplicity_sub_multiplicity {q : \u211a} (hp : p \u2260 1) (hq : q \u2260 0) :\n    padicValRat p q =\n      (multiplicity (p : \u2124) q.num).get (finite_int_iff.2 \u27e8hp, Rat.num_ne_zero_of_ne_zero hq\u27e9) -\n        (multiplicity p q.den).get\n          (by\n            rw [\u2190 finite_iff_dom, finite_nat_iff]\n            exact \u27e8hp, q.pos\u27e9) := by\n  rw [padicValRat, padicValInt.of_ne_one_ne_zero hp, padicValNat, dif_pos]\n  \u00b7 exact \u27e8hp, q.pos\u27e9\n  \u00b7 exact Rat.num_ne_zero_of_ne_zero hq\n#align padic_val_rat.multiplicity_sub_multiplicity padicValRat.multiplicity_sub_multiplicity\n\n/-- The `p`-adic value of an integer `z \u2260 0` is its `p`-adic value as a rational. -/\n@[simp]\ntheorem of_nat {n : \u2115} : padicValRat p n = padicValNat p n := by simp [padicValRat]\n#align padic_val_rat.of_nat padicValRat.of_nat\n\n/-- If `p \u2260 0` and `p \u2260 1`, then `padicValRat p p` is `1`. -/\ntheorem self (hp : 1 < p) : padicValRat p p = 1 := by simp [hp]\n#align padic_val_rat.self padicValRat.self\n\nend padicValRat\n\nsection padicValNat\n\nvariable {p : \u2115}\n\ntheorem zero_le_padicValRat_of_nat (n : \u2115) : 0 \u2264 padicValRat p n := by simp\n#align zero_le_padic_val_rat_of_nat zero_le_padicValRat_of_nat\n\n/-- `padicValRat` coincides with `padicValNat`. -/\n@[norm_cast]\ntheorem padicValRat_of_nat (n : \u2115) : \u2191(padicValNat p n) = padicValRat p n := by simp\n#align padic_val_rat_of_nat padicValRat_of_nat\n\n/-- A simplification of `padicValNat` when one input is prime, by analogy with\n`padicValRat_def`. -/\ntheorem padicValNat_def [hp : Fact p.Prime] {n : \u2115} (hn : 0 < n) :\n    padicValNat p n = (multiplicity p n).get (multiplicity.finite_nat_iff.2 \u27e8hp.out.ne_one, hn\u27e9) :=\n  dif_pos \u27e8hp.out.ne_one, hn\u27e9\n#align padic_val_nat_def padicValNat_def\n\ntheorem padicValNat_def' {n : \u2115} (hp : p \u2260 1) (hn : 0 < n) :\n    \u2191(padicValNat p n) = multiplicity p n := by simp [padicValNat, hp, hn]\n#align padic_val_nat_def' padicValNat_def'\n\n@[simp]\ntheorem padicValNat_self [Fact p.Prime] : padicValNat p p = 1 := by\n  rw [padicValNat_def (@Fact.out p.Prime).pos]\n  simp\n#align padic_val_nat_self padicValNat_self\n\ntheorem one_le_padicValNat_of_dvd {n : \u2115} [hp : Fact p.Prime] (hn : 0 < n) (div : p \u2223 n) :\n    1 \u2264 padicValNat p n := by\n  rwa [\u2190 PartENat.coe_le_coe, padicValNat_def' hp.out.ne_one hn, \u2190 pow_dvd_iff_le_multiplicity,\n    pow_one]\n#align one_le_padic_val_nat_of_dvd one_le_padicValNat_of_dvd\n\ntheorem dvd_iff_padicValNat_ne_zero {p n : \u2115} [Fact p.Prime] (hn0 : n \u2260 0) :\n    p \u2223 n \u2194 padicValNat p n \u2260 0 :=\n  \u27e8fun h => one_le_iff_ne_zero.mp (one_le_padicValNat_of_dvd hn0.bot_lt h), fun h =>\n    Classical.not_not.1 (mt padicValNat.eq_zero_of_not_dvd h)\u27e9\n#align dvd_iff_padic_val_nat_ne_zero dvd_iff_padicValNat_ne_zero\n\nend padicValNat\n\nnamespace padicValRat\n\nopen multiplicity\n\nvariable {p : \u2115} [hp : Fact p.Prime]\n\n/-- The multiplicity of `p : \u2115` in `a : \u2124` is finite exactly when `a \u2260 0`. -/\ntheorem finite_int_prime_iff {a : \u2124} : Finite (p : \u2124) a \u2194 a \u2260 0 := by\n  simp [finite_int_iff, hp.1.ne_one]\n#align padic_val_rat.finite_int_prime_iff padicValRat.finite_int_prime_iff\n\n/-- A rewrite lemma for `padicValRat p q` when `q` is expressed in terms of `Rat.mk`. -/\nprotected theorem defn (p : \u2115) [hp : Fact p.Prime] {q : \u211a} {n d : \u2124} (hqz : q \u2260 0)\n    (qdf : q = n /. d) :\n    padicValRat p q =\n      (multiplicity (p : \u2124) n).get\n          (finite_int_iff.2 \u27e8hp.1.ne_one, fun hn => by simp_all\u27e9) -\n        (multiplicity (p : \u2124) d).get\n          (finite_int_iff.2 \u27e8hp.1.ne_one, fun hd => by simp_all\u27e9) := by\n  have hd : d \u2260 0 := Rat.mk_denom_ne_zero_of_ne_zero hqz qdf\n  let \u27e8c, hc1, hc2\u27e9 := Rat.num_den_mk hd qdf\n  rw [padicValRat.multiplicity_sub_multiplicity hp.1.ne_one hqz]\n  simp only [Nat.isUnit_iff, hc1, hc2]\n  rw [multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1),\n    multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1)]\n  rw [Nat.cast_add, Nat.cast_add]\n  simp_rw [Int.coe_nat_multiplicity p q.den]\n  ring\n  -- Porting note: was\n  -- simp only [hc1, hc2, multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1),\n  --   hp.1.ne_one, hqz, pos_iff_ne_zero, Int.coe_nat_multiplicity p q.den\n#align padic_val_rat.defn padicValRat.defn\n\n/-- A rewrite lemma for `padicValRat p (q * r)` with conditions `q \u2260 0`, `r \u2260 0`. -/\nprotected theorem mul {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n    padicValRat p (q * r) = padicValRat p q + padicValRat p r := by\n  have : q * r = q.num * r.num /. (q.den * r.den) := by rw_mod_cast [Rat.mul_num_den]\n  have hq' : q.num /. q.den \u2260 0 := by rwa [Rat.num_den]\n  have hr' : r.num /. r.den \u2260 0 := by rwa [Rat.num_den]\n  have hp' : Prime (p : \u2124) := Nat.prime_iff_prime_int.1 hp.1\n  rw [padicValRat.defn p (mul_ne_zero hq hr) this]\n  conv_rhs =>\n    rw [\u2190 @Rat.num_den q, padicValRat.defn p hq', \u2190 @Rat.num_den r, padicValRat.defn p hr']\n  rw [multiplicity.mul' hp', multiplicity.mul' hp', Nat.cast_add, Nat.cast_add]\n  ring\n  -- Porting note: was\n  -- simp [add_comm, add_left_comm, sub_eq_add_neg]\n#align padic_val_rat.mul padicValRat.mul\n\n/-- A rewrite lemma for `padicValRat p (q^k)` with condition `q \u2260 0`. -/\nprotected theorem pow {q : \u211a} (hq : q \u2260 0) {k : \u2115} : padicValRat p (q ^ k) = k * padicValRat p q :=\n  by induction k <;>\n    simp [*, padicValRat.mul hq (pow_ne_zero _ hq), _root_.pow_succ, add_mul, add_comm]\n#align padic_val_rat.pow padicValRat.pow\n\n/-- A rewrite lemma for `padicValRat p (q\u207b\u00b9)` with condition `q \u2260 0`. -/\nprotected theorem inv (q : \u211a) : padicValRat p q\u207b\u00b9 = -padicValRat p q := by\n  by_cases hq : q = 0\n  \u00b7 simp [hq]\n  \u00b7 rw [eq_neg_iff_add_eq_zero, \u2190 padicValRat.mul (inv_ne_zero hq) hq, inv_mul_cancel hq,\n      padicValRat.one]\n#align padic_val_rat.inv padicValRat.inv\n\n/-- A rewrite lemma for `padicValRat p (q / r)` with conditions `q \u2260 0`, `r \u2260 0`. -/\nprotected theorem div {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n    padicValRat p (q / r) = padicValRat p q - padicValRat p r := by\n  rw [div_eq_mul_inv, padicValRat.mul hq (inv_ne_zero hr), padicValRat.inv r, sub_eq_add_neg]\n#align padic_val_rat.div padicValRat.div\n\n/-- A condition for `padicValRat p (n\u2081 / d\u2081) \u2264 padicValRat p (n\u2082 / d\u2082)`, in terms of\ndivisibility by `p^n`. -/\ntheorem padicValRat_le_padicValRat_iff {n\u2081 n\u2082 d\u2081 d\u2082 : \u2124} (hn\u2081 : n\u2081 \u2260 0) (hn\u2082 : n\u2082 \u2260 0)\n    (hd\u2081 : d\u2081 \u2260 0) (hd\u2082 : d\u2082 \u2260 0) :\n    padicValRat p (n\u2081 /. d\u2081) \u2264 padicValRat p (n\u2082 /. d\u2082) \u2194\n      \u2200 n : \u2115, (p : \u2124) ^ n \u2223 n\u2081 * d\u2082 \u2192 (p : \u2124) ^ n \u2223 n\u2082 * d\u2081 := by\n  have hf1 : Finite (p : \u2124) (n\u2081 * d\u2082) := finite_int_prime_iff.2 (mul_ne_zero hn\u2081 hd\u2082)\n  have hf2 : Finite (p : \u2124) (n\u2082 * d\u2081) := finite_int_prime_iff.2 (mul_ne_zero hn\u2082 hd\u2081)\n  conv =>\n    lhs\n    rw [padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn\u2081 hd\u2081) rfl,\n      padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn\u2082 hd\u2082) rfl, sub_le_iff_le_add', \u2190\n      add_sub_assoc, _root_.le_sub_iff_add_le]\n    norm_cast\n    rw [\u2190 multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1) hf1, add_comm, \u2190\n      multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1) hf2, PartENat.get_le_get,\n      multiplicity_le_multiplicity_iff]\n#align padic_val_rat.padic_val_rat_le_padic_val_rat_iff padicValRat.padicValRat_le_padicValRat_iff\n\n/-- Sufficient conditions to show that the `p`-adic valuation of `q` is less than or equal to the\n`p`-adic valuation of `q + r`. -/\ntheorem le_padicValRat_add_of_le {q r : \u211a} (hqr : q + r \u2260 0)\n    (h : padicValRat p q \u2264 padicValRat p r) : padicValRat p q \u2264 padicValRat p (q + r) :=\n  if hq : q = 0 then by simpa [hq] using h\n  else\n    if hr : r = 0 then by simp [hr]\n    else by\n      have hqn : q.num \u2260 0 := Rat.num_ne_zero_of_ne_zero hq\n      have hqd : (q.den : \u2124) \u2260 0 := by exact_mod_cast Rat.den_nz _\n      have hrn : r.num \u2260 0 := Rat.num_ne_zero_of_ne_zero hr\n      have hrd : (r.den : \u2124) \u2260 0 := by exact_mod_cast Rat.den_nz _\n      have hqreq : q + r = (q.num * r.den + q.den * r.num) /. (q.den * r.den) := Rat.add_num_den _ _\n      have hqrd : q.num * r.den + q.den * r.num \u2260 0 := Rat.mk_num_ne_zero_of_ne_zero hqr hqreq\n      conv_lhs => rw [\u2190 @Rat.num_den q]\n      rw [hqreq, padicValRat_le_padicValRat_iff hqn hqrd hqd (mul_ne_zero hqd hrd), \u2190\n        multiplicity_le_multiplicity_iff, mul_left_comm,\n        multiplicity.mul (Nat.prime_iff_prime_int.1 hp.1), add_mul]\n      rw [\u2190 @Rat.num_den q, \u2190 @Rat.num_den r, padicValRat_le_padicValRat_iff hqn hrn hqd hrd, \u2190\n        multiplicity_le_multiplicity_iff] at h\n      calc\n        _ \u2264\n            min (multiplicity (\u2191p) (q.num * r.den * q.den))\n              (multiplicity (\u2191p) (\u2191q.den * r.num * \u2191q.den)) :=\n          le_min\n            (by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (Nat.prime_iff_prime_int.1 hp.1), add_comm])\n            (by\n              rw [mul_assoc,\n                  @multiplicity.mul _ _ _ _ (q.den : \u2124) (_ * _)\n                    (Nat.prime_iff_prime_int.1 hp.1)]\n              exact add_le_add_left h _)\n        _ \u2264 _ := min_le_multiplicity_add\n#align padic_val_rat.le_padic_val_rat_add_of_le padicValRat.le_padicValRat_add_of_le\n\n/-- The minimum of the valuations of `q` and `r` is at most the valuation of `q + r`. -/\ntheorem min_le_padicValRat_add {q r : \u211a} (hqr : q + r \u2260 0) :\n    min (padicValRat p q) (padicValRat p r) \u2264 padicValRat p (q + r) :=\n  (le_total (padicValRat p q) (padicValRat p r)).elim\n  (fun h => by rw [min_eq_left h]; exact le_padicValRat_add_of_le hqr h)\n  (fun h => by rw [min_eq_right h, add_comm]; exact le_padicValRat_add_of_le (by rwa [add_comm]) h)\n#align padic_val_rat.min_le_padic_val_rat_add padicValRat.min_le_padicValRat_add\n\nopen BigOperators\n\n/-- A finite sum of rationals with positive `p`-adic valuation has positive `p`-adic valuation\n(if the sum is non-zero). -/\ntheorem sum_pos_of_pos {n : \u2115} {F : \u2115 \u2192 \u211a} (hF : \u2200 i, i < n \u2192 0 < padicValRat p (F i))\n    (hn0 : (\u2211 i in Finset.range n, F i) \u2260 0) : 0 < padicValRat p (\u2211 i in Finset.range n, F i) := by\n  induction' n with d hd\n  \u00b7 exact False.elim (hn0 rfl)\n  \u00b7 rw [Finset.sum_range_succ] at hn0\u22a2\n    by_cases h : (\u2211 x : \u2115 in Finset.range d, F x) = 0\n    \u00b7 rw [h, zero_add]\n      exact hF d (lt_add_one _)\n    \u00b7 refine' lt_of_lt_of_le _ (min_le_padicValRat_add hn0)\n      \u00b7 refine' lt_min (hd (fun i hi => _) h) (hF d (lt_add_one _))\n        exact hF _ (lt_trans hi (lt_add_one _))\n#align padic_val_rat.sum_pos_of_pos padicValRat.sum_pos_of_pos\n\nend padicValRat\n\nnamespace padicValNat\n\nvariable {p a b : \u2115} [hp : Fact p.Prime]\n\n/-- A rewrite lemma for `padicValNat p (a * b)` with conditions `a \u2260 0`, `b \u2260 0`. -/\nprotected theorem mul : a \u2260 0 \u2192 b \u2260 0 \u2192 padicValNat p (a * b) = padicValNat p a + padicValNat p b :=\n  by exact_mod_cast @padicValRat.mul p _ a b\n#align padic_val_nat.mul padicValNat.mul\n\nprotected theorem div_of_dvd (h : b \u2223 a) :\n    padicValNat p (a / b) = padicValNat p a - padicValNat p b := by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  \u00b7 simp\n  obtain \u27e8k, rfl\u27e9 := h\n  obtain \u27e8hb, hk\u27e9 := mul_ne_zero_iff.mp ha\n  rw [mul_comm, k.mul_div_cancel hb.bot_lt, padicValNat.mul hk hb, Nat.add_sub_cancel]\n#align padic_val_nat.div_of_dvd padicValNat.div_of_dvd\n\n/-- Dividing out by a prime factor reduces the `padicValNat` by `1`. -/\nprotected theorem div (dvd : p \u2223 b) : padicValNat p (b / p) = padicValNat p b - 1 := by\n  rw [padicValNat.div_of_dvd dvd, padicValNat_self]\n#align padic_val_nat.div padicValNat.div\n\n/-- A version of `padicValRat.pow` for `padicValNat`. -/\nprotected theorem pow (n : \u2115) (ha : a \u2260 0) : padicValNat p (a ^ n) = n * padicValNat p a := by\n  simpa only [\u2190 @Nat.cast_inj \u2124, push_cast] using padicValRat.pow (Nat.cast_ne_zero.mpr ha)\n#align padic_val_nat.pow padicValNat.pow\n\n@[simp]\nprotected theorem prime_pow (n : \u2115) : padicValNat p (p ^ n) = n := by\n  rw [padicValNat.pow _ (@Fact.out p.Prime).ne_zero, padicValNat_self, mul_one]\n#align padic_val_nat.prime_pow padicValNat.prime_pow\n\nprotected theorem div_pow (dvd : p ^ a \u2223 b) : padicValNat p (b / p ^ a) = padicValNat p b - a := by\n  rw [padicValNat.div_of_dvd dvd, padicValNat.prime_pow]\n#align padic_val_nat.div_pow padicValNat.div_pow\n\nprotected theorem div' {m : \u2115} (cpm : coprime p m) {b : \u2115} (dvd : m \u2223 b) :\n    padicValNat p (b / m) = padicValNat p b := by\n  rw [padicValNat.div_of_dvd dvd, eq_zero_of_not_dvd (hp.out.coprime_iff_not_dvd.mp cpm),\n    Nat.sub_zero]\n#align padic_val_nat.div' padicValNat.div'\n\nend padicValNat\n\nsection padicValNat\n\nvariable {p : \u2115}\n\ntheorem dvd_of_one_le_padicValNat {n : \u2115} (hp : 1 \u2264 padicValNat p n) : p \u2223 n := by\n  by_contra h\n  rw [padicValNat.eq_zero_of_not_dvd h] at hp\n  exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp)\n#align dvd_of_one_le_padic_val_nat dvd_of_one_le_padicValNat\n\ntheorem pow_padicValNat_dvd {n : \u2115} : p ^ padicValNat p n \u2223 n := by\n  rcases n.eq_zero_or_pos with (rfl | hn); \u00b7 simp\n  rcases eq_or_ne p 1 with (rfl | hp); \u00b7 simp\n  rw [multiplicity.pow_dvd_iff_le_multiplicity, padicValNat_def'] <;> assumption\n#align pow_padic_val_nat_dvd pow_padicValNat_dvd\n\ntheorem padicValNat_dvd_iff_le [hp : Fact p.Prime] {a n : \u2115} (ha : a \u2260 0) :\n    p ^ n \u2223 a \u2194 n \u2264 padicValNat p a := by\n  rw [pow_dvd_iff_le_multiplicity, \u2190 padicValNat_def' hp.out.ne_one ha.bot_lt, PartENat.coe_le_coe]\n#align padic_val_nat_dvd_iff_le padicValNat_dvd_iff_le\n\ntheorem padicValNat_dvd_iff (n : \u2115) [hp : Fact p.Prime] (a : \u2115) :\n    p ^ n \u2223 a \u2194 a = 0 \u2228 n \u2264 padicValNat p a := by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  \u00b7 exact iff_of_true (dvd_zero _) (Or.inl rfl)\n  \u00b7 rw [padicValNat_dvd_iff_le ha, or_iff_right ha]\n#align padic_val_nat_dvd_iff padicValNat_dvd_iff\n\ntheorem pow_succ_padicValNat_not_dvd {n : \u2115} [hp : Fact p.Prime] (hn : n \u2260 0) :\n    \u00acp ^ (padicValNat p n + 1) \u2223 n := by\n  rw [padicValNat_dvd_iff_le hn, not_le]\n  exact Nat.lt_succ_self _\n#align pow_succ_padic_val_nat_not_dvd pow_succ_padicValNat_not_dvd\n\ntheorem padicValNat_primes {q : \u2115} [hp : Fact p.Prime] [hq : Fact q.Prime] (neq : p \u2260 q) :\n    padicValNat p q = 0 :=\n  @padicValNat.eq_zero_of_not_dvd p q <|\n    (not_congr (Iff.symm (prime_dvd_prime_iff_eq hp.1 hq.1))).mp neq\n#align padic_val_nat_primes padicValNat_primes\n\nopen BigOperators\n\ntheorem range_pow_padicValNat_subset_divisors {n : \u2115} (hn : n \u2260 0) :\n    (Finset.range (padicValNat p n + 1)).image (p ^ \u00b7) \u2286 n.divisors := by\n  intro t ht\n  simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht\n  obtain \u27e8k, hk, rfl\u27e9 := ht\n  rw [Nat.mem_divisors]\n  exact \u27e8(pow_dvd_pow p <| by linarith).trans pow_padicValNat_dvd, hn\u27e9\n#align range_pow_padic_val_nat_subset_divisors range_pow_padicValNat_subset_divisors\n\ntheorem range_pow_padicValNat_subset_divisors' {n : \u2115} [hp : Fact p.Prime] :\n    ((Finset.range (padicValNat p n)).image fun t => p ^ (t + 1)) \u2286 n.divisors.erase 1 := by\n  rcases eq_or_ne n 0 with (rfl | hn)\n  \u00b7 simp\n  intro t ht\n  simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht\n  obtain \u27e8k, hk, rfl\u27e9 := ht\n  rw [Finset.mem_erase, Nat.mem_divisors]\n  refine' \u27e8_, (pow_dvd_pow p <| succ_le_iff.2 hk).trans pow_padicValNat_dvd, hn\u27e9\n  exact (Nat.one_lt_pow _ _ k.succ_pos hp.out.one_lt).ne'\n#align range_pow_padic_val_nat_subset_divisors' range_pow_padicValNat_subset_divisors'\n\nend padicValNat\n\nsection padicValInt\n\nvariable {p : \u2115} [hp : Fact p.Prime]\n\ntheorem padicValInt_dvd_iff (n : \u2115) (a : \u2124) : (p : \u2124) ^ n \u2223 a \u2194 a = 0 \u2228 n \u2264 padicValInt p a := by\n  rw [padicValInt, \u2190 Int.natAbs_eq_zero, \u2190 padicValNat_dvd_iff, \u2190 Int.coe_nat_dvd_left,\n    Int.coe_nat_pow]\n#align padic_val_int_dvd_iff padicValInt_dvd_iff\n\ntheorem padicValInt_dvd (a : \u2124) : (p : \u2124) ^ padicValInt p a \u2223 a := by\n  rw [padicValInt_dvd_iff]\n  exact Or.inr le_rfl\n#align padic_val_int_dvd padicValInt_dvd\n\ntheorem padicValInt_self : padicValInt p p = 1 :=\n  padicValInt.self hp.out.one_lt\n#align padic_val_int_self padicValInt_self\n\ntheorem padicValInt.mul {a b : \u2124} (ha : a \u2260 0) (hb : b \u2260 0) :\n    padicValInt p (a * b) = padicValInt p a + padicValInt p b := by\n  simp_rw [padicValInt]\n  rw [Int.natAbs_mul, padicValNat.mul] <;> rwa [Int.natAbs_ne_zero]\n#align padic_val_int.mul padicValInt.mul\n\ntheorem padicValInt_mul_eq_succ (a : \u2124) (ha : a \u2260 0) :\n    padicValInt p (a * p) = padicValInt p a + 1 := by\n  rw [padicValInt.mul ha (Int.coe_nat_ne_zero.mpr hp.out.ne_zero)]\n  simp only [eq_self_iff_true, padicValInt.of_nat, padicValNat_self]\n#align padic_val_int_mul_eq_succ padicValInt_mul_eq_succ\n\nend padicValInt\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/NumberTheory/Padics/PadicVal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7489974600586838}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module ring_theory.mv_polynomial.basic\n! leanprover-community/mathlib commit 019ead10c09bb91f49b1b7005d442960b1e0485f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.CharP.Basic\nimport Mathbin.Data.Polynomial.AlgebraMap\nimport Mathbin.Data.MvPolynomial.Variables\nimport Mathbin.LinearAlgebra.FinsuppVectorSpace\n\n/-!\n# Multivariate polynomials over commutative rings\n\nThis file contains basic facts about multivariate polynomials over commutative rings, for example\nthat the monomials form a basis.\n\n## Main definitions\n\n* `restrict_total_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` of total degree at most `m`.\n* `restrict_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` such that the degree in each individual variable is at most `m`.\n\n## Main statements\n\n* The multivariate polynomial ring over a commutative ring of positive characteristic has positive\n  characteristic.\n* `basis_monomials`: shows that the monomials form a basis of the vector space of multivariate\n  polynomials.\n\n## TODO\n\nGeneralise to noncommutative (semi)rings\n-/\n\n\nnoncomputable section\n\nopen Classical\n\nopen Set LinearMap Submodule\n\nopen BigOperators Polynomial\n\nuniverse u v\n\nvariable (\u03c3 : Type u) (R : Type v) [CommRing R] (p m : \u2115)\n\nnamespace MvPolynomial\n\nsection CharP\n\ninstance [CharP R p] : CharP (MvPolynomial \u03c3 R) p\n    where cast_eq_zero_iff n := by rw [\u2190 C_eq_coe_nat, \u2190 C_0, C_inj, CharP.cast_eq_zero_iff R p]\n\nend CharP\n\nsection Homomorphism\n\ntheorem mapRange_eq_map {R S : Type _} [CommRing R] [CommRing S] (p : MvPolynomial \u03c3 R)\n    (f : R \u2192+* S) : Finsupp.mapRange f f.map_zero p = map f p :=\n  by\n  -- `finsupp.map_range_finset_sum` expects `f : R \u2192+ S`\n  change Finsupp.mapRange (f : R \u2192+ S) (f : R \u2192+ S).map_zero p = map f p\n  rw [p.as_sum, Finsupp.mapRange_finset_sum, (map f).map_sum]\n  refine' Finset.sum_congr rfl fun n _ => _\n  rw [map_monomial, \u2190 single_eq_monomial, Finsupp.mapRange_single, single_eq_monomial,\n    f.coe_add_monoid_hom]\n#align mv_polynomial.map_range_eq_map MvPolynomial.mapRange_eq_map\n\nend Homomorphism\n\nsection Degree\n\n/-- The submodule of polynomials of total degree less than or equal to `m`.-/\ndef restrictTotalDegree : Submodule R (MvPolynomial \u03c3 R) :=\n  Finsupp.supported _ _ { n | (n.Sum fun n e => e) \u2264 m }\n#align mv_polynomial.restrict_total_degree MvPolynomial.restrictTotalDegree\n\n/-- The submodule of polynomials such that the degree with respect to each individual variable is\nless than or equal to `m`.-/\ndef restrictDegree (m : \u2115) : Submodule R (MvPolynomial \u03c3 R) :=\n  Finsupp.supported _ _ { n | \u2200 i, n i \u2264 m }\n#align mv_polynomial.restrict_degree MvPolynomial.restrictDegree\n\nvariable {R}\n\ntheorem mem_restrictTotalDegree (p : MvPolynomial \u03c3 R) :\n    p \u2208 restrictTotalDegree \u03c3 R m \u2194 p.totalDegree \u2264 m :=\n  by\n  rw [total_degree, Finset.sup_le_iff]\n  rfl\n#align mv_polynomial.mem_restrict_total_degree MvPolynomial.mem_restrictTotalDegree\n\ntheorem mem_restrictDegree (p : MvPolynomial \u03c3 R) (n : \u2115) :\n    p \u2208 restrictDegree \u03c3 R n \u2194 \u2200 s \u2208 p.support, \u2200 i, (s : \u03c3 \u2192\u2080 \u2115) i \u2264 n :=\n  by\n  rw [restrict_degree, Finsupp.mem_supported]\n  rfl\n#align mv_polynomial.mem_restrict_degree MvPolynomial.mem_restrictDegree\n\ntheorem mem_restrictDegree_iff_sup (p : MvPolynomial \u03c3 R) (n : \u2115) :\n    p \u2208 restrictDegree \u03c3 R n \u2194 \u2200 i, p.degrees.count i \u2264 n :=\n  by\n  simp only [mem_restrict_degree, degrees, Multiset.count_finset_sup, Finsupp.count_toMultiset,\n    Finset.sup_le_iff]\n  exact \u27e8fun h n s hs => h s hs n, fun h s hs n => h n s hs\u27e9\n#align mv_polynomial.mem_restrict_degree_iff_sup MvPolynomial.mem_restrictDegree_iff_sup\n\nvariable (\u03c3 R)\n\n/-- The monomials form a basis on `mv_polynomial \u03c3 R`. -/\ndef basisMonomials : Basis (\u03c3 \u2192\u2080 \u2115) R (MvPolynomial \u03c3 R) :=\n  Finsupp.basisSingleOne\n#align mv_polynomial.basis_monomials MvPolynomial.basisMonomials\n\n@[simp]\ntheorem coe_basisMonomials :\n    (basisMonomials \u03c3 R : (\u03c3 \u2192\u2080 \u2115) \u2192 MvPolynomial \u03c3 R) = fun s => monomial s 1 :=\n  rfl\n#align mv_polynomial.coe_basis_monomials MvPolynomial.coe_basisMonomials\n\ntheorem linearIndependent_x : LinearIndependent R (X : \u03c3 \u2192 MvPolynomial \u03c3 R) :=\n  (basisMonomials \u03c3 R).LinearIndependent.comp (fun s : \u03c3 => Finsupp.single s 1)\n    (Finsupp.single_left_injective one_ne_zero)\n#align mv_polynomial.linear_independent_X MvPolynomial.linearIndependent_x\n\nend Degree\n\nend MvPolynomial\n\n-- this is here to avoid import cycle issues\nnamespace Polynomial\n\n/-- The monomials form a basis on `R[X]`. -/\nnoncomputable def basisMonomials : Basis \u2115 R R[X] :=\n  Basis.ofRepr (toFinsuppIsoAlg R).toLinearEquiv\n#align polynomial.basis_monomials Polynomial.basisMonomials\n\n@[simp]\ntheorem coe_basisMonomials : (basisMonomials R : \u2115 \u2192 R[X]) = fun s => monomial s 1 :=\n  funext fun n => ofFinsupp_single _ _\n#align polynomial.coe_basis_monomials Polynomial.coe_basisMonomials\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RingTheory/MvPolynomial/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7489974532854997}}
{"text": "-- represent propositions as (are) types\n-- proofs are values of these types\n-- thus proof checking turns into type checking\n\n-- Computational domain\n#check nat\n#check 1\n\n#check string\n#check \"hello\"\n\n#check bool\n#check tt\n\n-- \"computational\" types of type, Type (aka Sort 1)\n\n-- Logical domain\n#check true \n#print true\n\ndef a_proof_of_nat : \u2115 := 8\ntheorem a_proof_of_true : true := true.intro\n-- theorem means a major proof, lemma means minor proof\n-- conjecture is a proposition that is not yet a proof\n\n#check false\n\n#check (eq 1) 1   -- eq predicate applied to 1 and 2\n#check (eq 1)\n#check 1 = 1    -- infix notation for eq\n-- proposition\n\n#print eq\n\nlemma pf_one_eq_one : 1 = 1 := eq.refl 1\nlemma pf_one_eq_two : 1 = 2 := (eq.refl 2)\n-- reflexive property of equality is why 3 = 3\n\n#check eq.refl 3\n-- value of 3 = 3\n#check 1 = 1\n\n-- values -> types -> types to which those belong\n\n#check 3 \u2208 { n : \u2115 | n % 2 = 1}\n-- proposition that is provable\n\n#check \u2203 (a b c : \u2115), a^2 + b^2 = c^2\n\n-- propositions formalized as logical types: of type, Prop (Sort 0)\n\n\n-- Values of computational types\n#check 1\n#check \"hello\"\n#check tt\n-- values of computational types are just ordinary data\n\n-- Values of logical types (aka propositions) \n#check (eq.refl 1)\n-- values of logical types are accepted as proofs\n\n\n-- eq defined as polymorphic *logical* type\n-- takes two values, v1 and v2, of any type, \u03b1 \n-- yields a proposition, eq v1 v2, of type Prop\n-- this type has just on constructor, called refl\n-- takes argument, a : \u03b1, returns a value of type a=a\n-- this value is accepted as a *proof* \n#print eq\n\n\n-- exercises involving proofs of equality\ndef pf1 : 1 = 1 := eq.refl 1\ndef pf2 : \"hello\" = \"hello\" := eq.refl \"hello\"\n\n#reduce 2 = nat.pred 3\n\nlemma pf3 : 2 = nat.pred 3 := eq.refl (nat.pred 3) \n-- vocabulary: minor result\n\ntheorem pf4 : tt = tt := eq.refl tt -- vocabulary: major result\ntheorem pf5 : 1 = 0 := _                -- StUCk!!!\n\ndef sq (n : \u2115) : \u2115 := n^2\n#reduce (sq 3 = 9)\n\nlemma pf6 : sq 3 = 9 := eq.refl 9           -- equality of reduced values\nlemma pf7 : sq 5 = 25 := eq.refl 25\n\n-- proof without having to worry about naming, example\nexample : sq 3 = 9 := eq.refl _\nexample : \u2115 := 8\n\n-- A logical type that has no values is false.\n-- That's why the proposition, \"false\", in Lean is false.\n-- a type with no constructors/values is said to be uninhabited\n#print false\ntheorem pf8 : false := _\n\n\n-- The proposition, \"true\", has one constant constructor/value/proof\n#print true\ntheorem pf9 : true := true.intro\n\n/-\nWhat we've seen so far is that some propositions are\nformalized as inductive types, the values of which, as\nbuilt using available constructors, are taken to be proofs.\nIndeed you can represent a wide variety of propositions\nand proofs this way.\n-/\n\ninductive MaryIsASoftwareEngineer : Prop\n| knowsFormalMethods\n| crackProgrammer\n\nopen MaryIsASoftwareEngineer\n\ndef me1 : MaryIsASoftwareEngineer := knowsFormalMethods\ntheorem me2 : MaryIsASoftwareEngineer := crackProgrammer\n\n/-\nLean implements a logic in which all proofs of a given\nproposition are considered to be not only equally good\nbut actually equal. This treatment of logical values is\nfundamentally different from that of computational data\nvalues, where values built by different constructors are\n*never* equal. The principle that Lean implements here \nis called the principle of \"proof irrelevance.\" To show\nthat a proposition is true, you just have to exhibit *any*\nproof/value of the given proposition/type. \n-/\n\nlemma m1 : me1 = me2 := eq.refl me1\n\ntheorem bad_news : 0 = 1 := _\n\n\n/-\nNot every logical proposition or predicate is implemented\nas an inductive type. In particular, proofs of \u2200, \u2192, and \u00ac\npropositions are not elementary data values functions. \n-/\n\n-- more to come\n", "meta": {"author": "jngo13", "repo": "Discrete-Mathematics", "sha": "bf674a866e61f60e6e6d128df85fa73819091787", "save_path": "github-repos/lean/jngo13-Discrete-Mathematics", "path": "github-repos/lean/jngo13-Discrete-Mathematics/Discrete-Mathematics-bf674a866e61f60e6e6d128df85fa73819091787/exam_2/predicate_logic/propositions_as_types.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7489974503319475}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport data.polynomial.ring_division\nimport algebra.big_operators.nat_antidiagonal\n\n/-!\n# \"Mirror\" of a univariate polynomial\n\nIn this file we define `polynomial.mirror`, a variant of `polynomial.reverse`. The difference \nbetween `reverse` and `mirror` is that `reverse` will decrease the degree if the polynomial is \ndivisible by `X`. We also define `polynomial.norm2`, which is the sum of the squares of the \ncoefficients of a polynomial. It is also a coefficient of `p * p.mirror`.\n\n## Main definitions\n\n- `polynomial.mirror`\n- `polynomial.norm2`\n\n## Main results\n\n- `polynomial.mirror_mul_of_domain`: `mirror` preserves multiplication.\n- `polynomial.irreducible_of_mirror`: an irreducibility criterion involving `mirror`\n- `polynomial.norm2_eq_mul_reverse_coeff`: `norm2` is a coefficient of `p * p.mirror`\n\n-/\n\nnamespace polynomial\n\nvariables {R : Type*} [semiring R] (p : polynomial R)\n\nsection mirror\n\n/-- mirror of a polynomial: reverses the coefficients while preserving `polynomial.nat_degree` -/\nnoncomputable def mirror := p.reverse * X ^ p.nat_trailing_degree\n\nlemma mirror_zero : (0 : polynomial R).mirror = 0 := rfl\n\nlemma mirror_monomial (n : \u2115) (a : R) : (monomial n a).mirror = (monomial n a) :=\nbegin\n  by_cases ha : a = 0,\n  { rw [ha, monomial_zero_right, mirror_zero] },\n  { rw [mirror, reverse, nat_degree_monomial n a ha, nat_trailing_degree_monomial ha,\n        \u2190C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, rev_at_le (le_refl n),\n        nat.sub_self, pow_zero, mul_one] },\nend\n\nlemma mirror_C (a : R) : (C a).mirror = C a :=\nmirror_monomial 0 a\n\nlemma mirror_X : X.mirror = (X : polynomial R) :=\nmirror_monomial 1 (1 : R)\n\nlemma mirror_nat_degree : p.mirror.nat_degree = p.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, mirror_zero] },\n  by_cases hR : nontrivial R,\n  { haveI := hR,\n    rw [mirror, nat_degree_mul', reverse_nat_degree, nat_degree_X_pow,\n        nat.sub_add_cancel p.nat_trailing_degree_le_nat_degree],\n    rwa [leading_coeff_X_pow, mul_one, reverse_leading_coeff, ne, trailing_coeff_eq_zero] },\n  { haveI := not_nontrivial_iff_subsingleton.mp hR,\n    exact congr_arg nat_degree (subsingleton.elim p.mirror p) },\nend\n\nlemma mirror_nat_trailing_degree : p.mirror.nat_trailing_degree = p.nat_trailing_degree :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, mirror_zero] },\n  { rw [mirror, nat_trailing_degree_mul_X_pow ((mt reverse_eq_zero.mp) hp),\n        reverse_nat_trailing_degree, zero_add] },\nend\n\nlemma coeff_mirror (n : \u2115) :\n  p.mirror.coeff n = p.coeff (rev_at (p.nat_degree + p.nat_trailing_degree) n) :=\nbegin\n  by_cases h2 : p.nat_degree < n,\n  { rw [coeff_eq_zero_of_nat_degree_lt (by rwa mirror_nat_degree)],\n    by_cases h1 : n \u2264 p.nat_degree + p.nat_trailing_degree,\n    { rw [rev_at_le h1, coeff_eq_zero_of_lt_nat_trailing_degree],\n      exact (nat.sub_lt_left_iff_lt_add h1).mpr (nat.add_lt_add_right h2 _) },\n    { rw [\u2190rev_at_fun_eq, rev_at_fun, if_neg h1, coeff_eq_zero_of_nat_degree_lt h2] } },\n  rw not_lt at h2,\n  rw [rev_at_le (h2.trans (nat.le_add_right _ _))],\n  by_cases h3 : p.nat_trailing_degree \u2264 n,\n  { rw [\u2190nat.sub_add_eq_add_sub h2, \u2190nat.sub_sub_assoc h2 h3, mirror, coeff_mul_X_pow',\n        if_pos h3, coeff_reverse, rev_at_le ((nat.sub_le_self _ _).trans h2)] },\n  rw not_le at h3,\n  rw coeff_eq_zero_of_nat_degree_lt (nat.lt_sub_right_iff_add_lt.mpr (nat.add_lt_add_left h3 _)),\n  exact coeff_eq_zero_of_lt_nat_trailing_degree (by rwa mirror_nat_trailing_degree),\nend\n\n--TODO: Extract `finset.sum_range_rev_at` lemma.\n\n\nlemma mirror_mirror : p.mirror.mirror = p :=\npolynomial.ext (\u03bb n, by rw [coeff_mirror, coeff_mirror,\n  mirror_nat_degree, mirror_nat_trailing_degree, rev_at_invol])\n\nlemma mirror_eq_zero : p.mirror = 0 \u2194 p = 0 :=\n\u27e8\u03bb h, by rw [\u2190p.mirror_mirror, h, mirror_zero], \u03bb h, by rw [h, mirror_zero]\u27e9\n\nlemma mirror_trailing_coeff : p.mirror.trailing_coeff = p.leading_coeff :=\nby rw [leading_coeff, trailing_coeff, mirror_nat_trailing_degree, coeff_mirror,\n  rev_at_le (nat.le_add_left _ _), nat.add_sub_cancel]\n\nlemma mirror_leading_coeff : p.mirror.leading_coeff = p.trailing_coeff :=\nby rw [\u2190p.mirror_mirror, mirror_trailing_coeff, p.mirror_mirror]\n\nlemma mirror_mul_of_domain {R : Type*} [integral_domain R] (p q : polynomial R) :\n  (p * q).mirror = p.mirror * q.mirror :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, zero_mul, mirror_zero, zero_mul] },\n  by_cases hq : q = 0,\n  { rw [hq, mul_zero, mirror_zero, mul_zero] },\n  rw [mirror, mirror, mirror, reverse_mul_of_domain, nat_trailing_degree_mul hp hq, pow_add],\n  ring,\nend\n\nlemma mirror_smul {R : Type*} [integral_domain R] (p : polynomial R) (a : R) :\n  (a \u2022 p).mirror = a \u2022 p.mirror :=\nby rw [\u2190C_mul', \u2190C_mul', mirror_mul_of_domain, mirror_C]\n\nlemma mirror_neg {R : Type*} [ring R] (p : polynomial R) : (-p).mirror = -(p.mirror) :=\nby rw [mirror, mirror, reverse_neg, nat_trailing_degree_neg, neg_mul_eq_neg_mul]\n\nlemma irreducible_of_mirror {R : Type*} [integral_domain R] {f : polynomial R}\n  (h1 : \u00ac is_unit f)\n  (h2 : \u2200 k, f * f.mirror = k * k.mirror \u2192 k = f \u2228 k = -f \u2228 k = f.mirror \u2228 k = -f.mirror)\n  (h3 : \u2200 g, g \u2223 f \u2192 g \u2223 f.mirror \u2192 is_unit g) : irreducible f :=\nbegin\n  split,\n  { exact h1 },\n  { intros g h fgh,\n    let k := g * h.mirror,\n    have key : f * f.mirror = k * k.mirror,\n    { rw [fgh, mirror_mul_of_domain, mirror_mul_of_domain, mirror_mirror,\n          mul_assoc, mul_comm h, mul_comm g.mirror, mul_assoc, \u2190mul_assoc] },\n    have g_dvd_f : g \u2223 f,\n    { rw fgh,\n      exact dvd_mul_right g h },\n    have h_dvd_f : h \u2223 f,\n    { rw fgh,\n      exact dvd_mul_left h g },\n    have g_dvd_k : g \u2223 k,\n    { exact dvd_mul_right g h.mirror },\n    have h_dvd_k_rev : h \u2223 k.mirror,\n    { rw [mirror_mul_of_domain, mirror_mirror],\n      exact dvd_mul_left h g.mirror },\n    have hk := h2 k key,\n    rcases hk with hk | hk | hk | hk,\n    { exact or.inr (h3 h h_dvd_f (by rwa \u2190 hk)) },\n    { exact or.inr (h3 h h_dvd_f (by rwa [eq_neg_iff_eq_neg.mp hk, mirror_neg, dvd_neg])) },\n    { exact or.inl (h3 g g_dvd_f (by rwa \u2190 hk)) },\n    { exact or.inl (h3 g g_dvd_f (by rwa [eq_neg_iff_eq_neg.mp hk, dvd_neg])) } },\nend\n\nend mirror\n\nend polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/polynomial/mirror.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7489915579234377}}
{"text": "import tactic\nimport group.definitions\n\n/-\nclass group (G : Type) extends has_group_notation G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\n-- IMPORTANT; KB has some much slicker proofs of these in \n-- the Wednesday solutions to his LFTCM talk. Feel\n-- free to steal\n-/\n\n-- This entire project takes place in the mygroup namespace\nnamespace mygroup\n\n/- Our first task is to prove `mul_one` and `mul_right_inv`.\n   We prove some other things along the way too -- we make \n   what a computer scientist would call \"an interface for\n   the group class\".\n\n  Examples of what we prove:\n\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n\n-/\nnamespace group\n\nvariables {G : Type} [group G]  \n\n-- We prove left_mul_cancel for group using `calc`.\n\nlemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c := \n calc b = 1 * b         : by rw one_mul\n    ... = (a\u207b\u00b9 * a) * b : by rw mul_left_inv\n    ... = a\u207b\u00b9 * (a * b) : by rw mul_assoc\n    ... = a\u207b\u00b9 * (a * c) : by rw Habac\n    ... = (a\u207b\u00b9 * a) * c : by rw mul_assoc\n    ... = 1 * c         : by rw mul_left_inv\n    ... = c             : by rw one_mul\n\n-- We can do all this one go:\n\nlemma mul_left_cancel' (a b c : G) (Habac : a * b = a * c) : b = c := \nbegin \n  rw [\u2190one_mul b, \u2190mul_left_inv a, mul_assoc, Habac,\n      \u2190mul_assoc, mul_left_inv, one_mul],\nend\n\n-- Because the above proof just uses one tactic, we could use `by`\n-- instead of `begin ... end`:\n\nlemma mul_left_cancel'' (a b c : G) (Habac : a * b = a * c) : b = c := \nby rw [\u2190one_mul b, \u2190mul_left_inv a, mul_assoc, Habac,\n  \u2190mul_assoc, mul_left_inv, one_mul]\n\n-- The below is also a useful intermediate lemma\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rw \u2190mul_assoc,\n  rw mul_left_inv,\n  rwa one_mul, -- rewrite then assumption\nend\n\n-- could prove it in `calc` mode:\n\nlemma mul_eq_of_eq_inv_mul' {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  exact calc\n  a\u207b\u00b9 * (a * x) = a\u207b\u00b9 * a * x : by rw mul_assoc\n  ...           = 1 * x       : by rw mul_left_inv\n  ...           = x           : by rw one_mul\n  ...           = a\u207b\u00b9 * y     : by rw h  \nend\n\nattribute [simp] one_mul mul_left_inv\n\n-- Alternatively, get the simplifier to do some of the work for us\nlemma mul_eq_of_eq_inv_mul'' {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y :=\n\u03bb h, mul_left_cancel a\u207b\u00b9 _ _ $ by rw \u2190mul_assoc; simp [h]\n\n-- We can now prove `mul_one`:\n\n-- nice short proof\ntheorem mul_one (a : G) : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_left_inv,\n  -- note no refl\nend\n\n-- calc example (longer than previous one)\ntheorem mul_one' : \u2200 (a : G), a * 1 = a :=\nbegin\n  intro a, -- goal is a * 1 = a\n  apply mul_left_cancel a\u207b\u00b9, -- goal now a\u207b\u00b9 * (a * 1) = a\u207b\u00b9 * a\n  exact calc a\u207b\u00b9 * (a * 1) = (a\u207b\u00b9 * a) * 1 : by rw mul_assoc\n          ...               = 1 * 1         : by rw mul_left_inv\n          ...               = 1             : by rw one_mul\n          ...               = a\u207b\u00b9 * a       : by rw mul_left_inv\nend\n\n-- term mode proof\ntheorem mul_one'' (a : G) : a * 1 = a :=\nmul_eq_of_eq_inv_mul $ by simp\n\n-- it's also a good simp lemma\nattribute [simp] mul_one\n\n-- mul_left_inv is an axiom: here's mul_right_inv. \n\ntheorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\n-- another good simp lemma\nattribute [simp] mul_right_inv\n\n-- We already proved `mul_eq_of_eq_inv_mul` but there are several other\n-- similar-looking, but slightly different, versions of this. Here\n-- is one.\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nbegin\n  rw \u2190h,\n  rw mul_assoc,\n  rw mul_right_inv,\n  rw mul_one\nend\n\n-- one-liner proof\nlemma eq_mul_inv_of_mul_eq' {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nby rw [\u2190h, mul_assoc, mul_right_inv, mul_one]\n\n-- proof using automation\nlemma eq_mul_inv_of_mul_eq'' {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nby simp [h.symm, mul_assoc]\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b\u207b\u00b9 * c :=\nbegin\n  rw [\u2190h, \u2190mul_assoc, mul_left_inv b, one_mul]\nend\n\n-- Another useful lemma for the interface:\nlemma mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1 :=\nbegin\n  split,\n  { intro h,\n    replace h := eq_mul_inv_of_mul_eq h,\n    rw mul_right_inv at h,\n    assumption\n  },\n  { intro h,\n    rw h,\n    rw one_mul\n  }\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a \u2194 b = 1 :=\nbegin\n  split,\n    intro h,\n    from calc b = a\u207b\u00b9 * a : by apply eq_inv_mul_of_mul_eq h\n           ...  = 1 : by rw mul_left_inv,\n    intro h,\n    rw [h, mul_one]\nend\n\n-- Another useful lemma for the interface.\n-- Note use of the powerful `convert` tactic.\n-- `eq_mul_inv_of_mul_eq h` says ` a = 1 * b\u207b\u00b9` which is\n-- equal to our goal; convert creates the goals necessary\n-- to prove this\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9 :=\nbegin\n  convert eq_mul_inv_of_mul_eq h,\n  rw one_mul, -- `simp` would also work\nend\n\n-- Another useful lemma for the interface\nlemma inv_inv (a : G) : a \u207b\u00b9 \u207b\u00b9 = a :=\nbegin\n  symmetry,\n  apply eq_inv_of_mul_eq_one,\n  simp,\nend\n\n-- Another useful lemma for the interface\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b :=\nbegin\n  -- we can change hypotheses with the `replace` tactic.\n  -- h implies a = 1 * b\u207b\u00b9\n  replace h := eq_mul_inv_of_mul_eq h,\n  -- and so a = b\u207b\u00b9\n  rw one_mul at h,\n  -- By substituting in, we have to prove (b\u207b\u00b9)\u207b\u00b9 = b\n  rw h,\n  -- and we just did this, it's `inv_inv`\n  rw inv_inv,\nend\n\nlemma unique_id {e : G} (h : \u2200 x : G, e * x = x) : e = 1 :=\ncalc e = e * 1 : by rw mul_one\n  ...  = 1 : by rw h 1\n\n-- Maybe add unique_id but with x * e = x\n\nlemma unique_inv {a b : G} (h : a * b = 1) : b = a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel a,\n  rw [h, mul_right_inv]\nend\n\nlemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y := \ncalc x = x * 1 : by rw mul_one\n  ...  = x * (a * a\u207b\u00b9) : by rw mul_right_inv\n  ...  = x * a * a\u207b\u00b9 : by rw mul_assoc\n  ...  = y * a * a\u207b\u00b9 : by rw Habac\n  ...  = y * (a * a\u207b\u00b9) : by rw mul_assoc\n  ...  = y * 1 : by rw mul_right_inv\n  ...  = y : by rw mul_one\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y \u2194 x = y :=\nbegin\n  split,\n    from mul_left_cancel a x y,\n    intro hxy,\n    rwa hxy\nend\n\nlemma mul_right_cancel_iff (a x y : G) : x * a = y * a \u2194 x = y :=\nbegin\n  split,\n    from mul_right_cancel a x y,\n    intro hxy,\n    rwa hxy\nend\n\n@[simp] lemma inv_mul_cancel_left (a b : G) : a\u207b\u00b9 * (a * b) = b :=\nbegin\n  rw \u2190mul_assoc, simp\nend\n\n@[simp] lemma mul_inv_cancel_left (a b : G) : a * (a\u207b\u00b9 * b) = b :=\nbegin\n  rw \u2190mul_assoc,\n  simp\nend\n\nlemma inv_mul (a b : G) : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel (a * b),\n  rw mul_right_inv, simp [mul_assoc]\nend\n\nlemma one_inv : (1 : G)\u207b\u00b9 = 1 :=\nby conv_rhs { rw [\u2190(mul_left_inv (1 : G)), mul_one] }\n\nattribute [simp] mul_left_cancel_iff mul_right_cancel_iff inv_mul inv_inv \n  one_inv\n\n\n@[simp] theorem inv_inj_iff {a b : G}: a\u207b\u00b9 = b\u207b\u00b9 \u2194 a = b :=\nbegin\n  split,\n  {  intro h,\n    rw \u2190 inv_inv a,\n    rw h,\n    rw inv_inv b},\n  { rintro rfl,\n    refl}  \nend   \n\ntheorem inv_eq {a b : G}: a\u207b\u00b9 = b \u2194 b\u207b\u00b9 = a :=\nbegin\n  split;\n  {rintro rfl,\n   rw inv_inv}\nend  \n\n-- **TODO** is this a good simp lemma? I don't think RHS is\n-- strictly simpler than LHS.\n@[simp] theorem mul_comm {G : Type} [comm_group G] (g h : G) : \n  g * h = h * g := comm_group.mul_comm g h\n\n-- **TODO** open an issue about abel only working with `*`. We\n-- have `group` working but not `comm_group`. It\n-- would be an interesting exercise to get `abel` working.\nend group\n\nend mygroup\n\n\n-- We define an instance giving a Lean group from our home-grown group.\n-- Actually, ignore this bit. We get funny name clashes because of it :-(\n\n-- open mygroup.group\n\n-- actually I'm not sure it's a good idea\n-- instance mygroup.to_group (G : Type) [mygroup.group G] : group G :=\n-- { mul := (*),\n--   mul_assoc := mul_assoc,\n--   one := 1,\n--   one_mul := one_mul,\n--   mul_one := mul_one,\n--   inv := inv,\n--   mul_left_inv := mul_left_inv }\n\n-- to make `group` work, need the simp set for our group.\n-- long exercise. Is it interesting for the reader?\n-- reference for answer : see my Wednesday talk about algebra hierarchy\n-- at LFTCM. Then you can make your own `group` tactic.\n-- **TODO** make ", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/junk/group/theorems.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.748991554180473}}
{"text": "/-\nHere is the practice exam. It provides you\nwith a set of problems illustrative of the\nmaterial to be tested. This is a homework\nassignment due this coming Thursday. We will\nreview the questions in class.\n\nCopy this file your \"work\" directory. Work\non it there. Upload to Collab when done.\n\nNote: An incorrect answer above or below\na correct answer can cause Lean to be unable\nto process the correct answer. If you are not\nable to complete a problem successfully please\ncomment out your incomplete answer so that we\ncan see your work but so that your incomplete\nwork does not cause problems for surrounding\nproblems and answers.\n-/\n\n/-\nPART I: Functions. Functions are an essential\nelement of the language of predicate logic. In\nthis section, you show that you understand how\nto define, use, and reason about functions in\nLean.\n-/\n\n/- 1.\nStudy each of the following definitions,\nthen answer the associated question about\nthe types involved in these definitions.\n-/\n\n-- Consider this function\ndef f (n : \u2115) (s : string) := s\n\n/-\na. What is it's return type? Answer:\nstring\n-/\n\n/-\nb. What is the type of (f 5)? Answer:\nstring \u2192 string\n-/\n\n/-\nc. What is the value of (f 0 \"yay\")\nstring\n-/\n\n/-\nd. What is the type of this function?\n\u2115 \u2192 string \u2192 string\n-/\n\n\n/- 2.\nDefine three functions called square,\nsquare', and square'', each of type\n\u2115 \u2192 \u2115. Each function must return the\nsquare of the value to which it is\napplied. Write the first function in\n\"C\" style, the second using a tactic\nscript, and the third using a lambda\nabstraction. Declare all argument and\nreturn types explicitly. Answer below.\n-/\ndef square (n: \u2115 ) : \u2115 := n^2\n\ndef square' (n: \u2115 ) : \u2115 :=\nbegin\n    exact n^2\nend\n\ndef square'':=\n    \u03bb n: \u2115, \n        n^2 \n\n\n\n/- 3.\nConstruct three proofs to test your\nfunction definitions. The first must\nuse \"lemma\" to define a proof, called\nsquare_3_9, of the proposition that\n(square 3) equals 9. The second must\nuse \"theorem\" to define a proof, called\nsquare'_4_16, of the proposition that\nsquare' applied to 4 reduces to 16. The\nthird must prove that square'' 5 is\nequal to 25. This third proof must not\nuse the equals sign, =, but must use\n\"eq\" instead to state the proposition\nto be proved. Hint on #3, sometimes\nyou need to use parentheses to express\nhow you want terms to be grouped. Answer\nbelow.\n-/\nlemma square_3_9 : square 3 = 9 := rfl\n\ntheorem square'_4_16 : square 4 = 16 := rfl\n\nexample : eq (square'' 5 ) 25 := rfl\n\n\n\n\n\n\n\n/- 4.\nDefine a function called last_first.\nIt must take two string values, called\n\"first\" and \"last\" (without quotes),\nand return a string consisting of \"last\"\nfollowed by a comma and a space followed\nby \"first\".\n\nFor example (last_first \"Orson\" \"Welles\")\nmust return the string, \"Welles, Orson\".\nWrite a test case for your function to\nprove that (last_first \"Orson\" \"Welles\")\nis \"Welles, Orson\". Use \"example\", to\ncheck the proof. Hint: The ++ operator\nimplements the string append function.\nAnswer below.\n-/\ndef last_first (first last: string) : string := last ++ \", \" ++ first\n\nexample : eq (last_first \"Orson\" \"Welles\") \"Welles, Orson\" := rfl\n\n\n\n\n\n/- 5.\n\nComplete the following definition of a\nfunction, called apply3. It takes, as an\nargument, a function, you might call it f,\nof type \u2115 \u2192 \u2115. It must return a function,\nalso of type \u2115 to \u2115, that, when applied\nto a value, n, returns the result of\napplying the given function, f, to the\ngiven value, n, three times. The function\nreturned must compute f(f(f(n))) when it\nis applied to an argument, n.\n-/\n\ndef apply3 : (\u2115 \u2192 \u2115 ) \u2192 (\u2115\u2192 \u2115 ):=\n    \u03bb f : \u2115 \u2192 \u2115, \n        \u03bb n : \u2115, f(f(f(n)))\n\n\n/- 6.\n\nThe Lean libraries define a function,\nstring.length, that takes a string and\nreturns its length as a natural number.\nDefine a function, len2, that takes two\nstrings and returns the sum of their\nlengths. You may use the ++ operator\nbut not the + operator in your answer.\nFollow your function definition with a\ntest case in the form of a proof using\n\"example\" showing that len2 applied to\n\"Orson\" and \"Welles\" is 11. Remember:\nyou might need parenthesis in some\ncases to group terms correctly into\nlarger terms.\n-/\ndef len2 (first last: string) : \u2115 := \n    (first++last).length\nexample : eq(len2 \"Orson\" \"Welles\") 11 := rfl\n\n\n/- 7.\nUse \"example\" to prove that there is a\nfunction of the following type:\n\nuu\nexample : \n((\u2115 \u2192 \u2115) \u2192 (\u2115 \u2192 \u2115)) \u2192\n    ((\u2115 \u2192 \u2115) \u2192 \u2115) \u2192\n        ((\u2115 \u2192 \u2115) \u2192 \u2115)\n:= \u03bb f g, g\n\n\n\n/-\nPART II: Functions, revisited. In\nmathematics,  functions play a central\nrole. A function, f, in the mathematical\nsense is a triple, f = { D, P, C }, where\nD, a set, is the domain of definition of\nf, C is the co-domain of f, and P is a\nset of ordered pairs, each with a first\nelement from D and a second element from\nC,. In addition, P has one additional\nessential  property, the subject of one\nof the following questions.\n-/\n\n/- 8.\n\nWhat one additional property is essential to\nthe definition of what it means for a triple,\n{ D, P, C } to be a function?\n\nName the property. Answer: single-valued\n\nNow explain precisely what it means:  \"That there\nare no two pairs, (x, y) and (x', y') such that...\"\n\nFill in the blank, and use a logical \u2227 in answering.\nYou might also want to use = or \u2260.\n\nAnswer: x= x' ^ y = y'\n-/\n\n/- 9.\n\nGive names to the following concepts:\n\nThe set of all values appearing as the first\nelement of any pair in P.\n\nAnswer: domain\n\nThe set of all values appearing as the second\nelement of any pair in P.\n\nAnswer: range\n\nThe property that the set of all values\nappearing as the first element of P is the\nsame as the entire set, D.\n\nAnswer: total\n\nThe property that the set of all \nvalues appearing as the second element of \nP is the same as the entire set, C. \n\nAnswer: surjective\n\nThe property of being one-to-one and onto.\n\nAnswer: bijective \n\n-/\n\n/- 10.\n\nWhat does it mean for a function, f, to be\ninjective? Give you answer by completing the\nfollowing sentences with logical expressions.\n\n\"A function, f, is said to be injective if\nit has no two pairs, (x, y) and (x', y'),\nsuch that ...\"\n\nAnswer:\n\nIn other words, \"If (x, y) and (x', y') are\nrelated by f and x \u2260 x' then ...\"\n\nAnswer:\n-/\n\n\n/- 11.\n\nSuppose that S and T are types and that f\nis defined to be a function, *in Lean*, of\ntype S \u2192 T. Which of the following properties,\nif any, does f necessarily have?\n\n- injective\n- surjective\n- bijective\n- one-to-many\n- one-to-one\n- onto\n- single-valued\n- partial\n- total\n\nAnswer:\n\n-/\n\n/-\nPART III: Logic and Proof.\n-/\n\n/- 12a.\n\nUse axiom and/or axioms in Lean to express,\nin formal logic, the following assumptions:\n\n- T is a type\n- t1 and t2 are values of type T\n- t1 = t2\n\nAnswer immediately after this comment block.\nIf you need to introduce a name, use eqt1t2.\n-/\n-/\naxiom T: Type\naxioms t1 t2 : T\naxiom eqt1t2: t1 = t2\n\n\n\n/- 12b.\n\nUse axiom or axioms to represent the\nadditional assumptions that\n\n- P is a predicate expressing a property of objects of type T\n- t1 has property P\n\nIf you need to use a name, use Pt1\n-/\naxiom P : T \u2192 Prop\naxiom Pt1 : P t1\n\n\n/- 12 c.\n\nNow use \"example\" to assert, and then\nprove, that t2 also has property P.\n-/\nexample : P t2 := eq.subst eqt1t2 Pt1\n\n\n/- 13 a.\nDefine eq_1_0 to be the proposition, 1 = 0.\n-/\ndef eq_1_0 := 1 = 0\n\n\n\n/- 13 b.\nDefine pf_eq_0_0 to be a proof of the\nproposition that 0 = 0. Use the lemma\nkeyword.\n-/\nlemma pf_eq_0_0 :  0 = 0 := rfl\n\n\n/- 13 c.\nWrite a function, w, that takes three\nvalues, a, b, and c of type \u2115, and that\nalso takes proofs, cb : c = b, and\nba : b = a, and that returns a proof\nthat a = c.\n-/\ndef w (a b c : \u2115 ) (cb : c = b) (ba : b = a) : a = c :=\n    eq.trans (eq.symm ba) (eq.symm cb)\n#check w\n\n\n/- 13d.\n\nWhat is the type of this function?\n\nAnswer: \u2200 (a b c : \u2115), c = b \u2192 b = a \u2192 a = c\n\nWhat is the form of this proposition?\n\nAnswer: universal generalization\n\nWhat's the form the proposition after the\ncomma?\n\nAnswer: Implication\n\nWhat is the premise of the proposition after\nthe comma?\n\nAnswer:\n\n-/\n\n/- 14.\nComplete the following proofs. Give each one\nin the form indicated by a comment preceding\nthe statement of the conjecture to be proved.\nWhen using tactic scripts, remember to write\nbegin/end pairs right away, so Lean knowns\nyou want to use a tactic script.\n-/\n\n-- lambda expression\nexample : \u2200 (s : string), s = s :=\n    \u03bb s, eq.refl s\n\n\n-- lambda expresion\nexample : \u2200 (n : \u2115), \u2200 (m : \u2115), true :=\n    \u03bb n m, true.intro\n\n\n-- tactic script\nexample : \u2200 (T : Type), \u2200 (t : T), eq t t :=\nbegin\n    assume T,\n    assume t,\n    exact eq.refl t\nend\n\n\n-- tactic script\nexample :\n    \u2200 (T : Type),\n    \u2200 (P : T \u2192 Prop),\n    \u2200 t1 t2 : T,\n    \u2200 Pt1 : P t1,\n    \u2200 t2t1 : t2 = t1,\n    P t2 :=\n_\n\n/-\nThe following problems involve implications.\nFor example, false \u2192 P in an implication. To\nprove an implication, just show that there is\n(give) a function of the specified type.\n-/\n\n-- lambda expression\nexample : \u2200 (P : Prop), false \u2192 P :=\n_\n\n\n-- tactic script\nexample : \u2200 (P : Prop), false \u2192 P :=\n_\n\n\n-- lambda expression\nexample : \u2200 (P Q : Prop), P \u2227 Q \u2192 Q \u2227 P :=\n_\n\n-- tactic script\nexample : \u2200 (P Q : Prop), P \u2227 Q \u2192 Q \u2227 P :=\n_\n\n\n\n-- tactic script\nexample :\n    \u2200 T : Type,\n    \u2200 (t1 t2 t3 : T),\n    t1 = t2 \u2227 t2 = t3 \u2192 t1 = t3 :=\n_\n\n\n/- 15.\n\nUse Lean to model a world in which there\nare Dogs, all Dogs are friendly, and Fido\nis a Dog, with a proof that in this world,\nFido must be friendly, too.\n-/\n", "meta": {"author": "justinqcai", "repo": "CS2102", "sha": "d309f0db3f1df52eb77206ee1e8665a3b49d7a0c", "save_path": "github-repos/lean/justinqcai-CS2102", "path": "github-repos/lean/justinqcai-CS2102/CS2102-d309f0db3f1df52eb77206ee1e8665a3b49d7a0c/hw5-exam1-practice copy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759583, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7489915529664427}}
{"text": "-- Math 52: Quiz 5\n-- Open this file in a folder that contains 'utils'.\n\nimport utils\nopen classical\n\ndefinition divides (a b : \u2124) : Prop := \u2203 (k : \u2124), b = a * k\nlocal infix \u2223 := divides\n\naxiom not_3_divides : \u2200 (m : \u2124), \u00ac (3 \u2223 m) \u2194 3 \u2223 m - 1 \u2228 3 \u2223 m + 1\n\nlemma not_3_divides_of_3_divides_minus_1 : \n\u2200 (m : \u2124), 3 \u2223 m - 1 \u2192 \u00ac (3 \u2223 m) :=\nbegin\nintros m H,\nrw not_3_divides,\nleft,\nassumption, \nend\n\nlemma not_3_divides_of_3_divides_plus_1 : \n\u2200 (m : \u2124), 3 \u2223 m + 1 \u2192 \u00ac (3 \u2223 m) :=\nbegin\nintros m H,\nrw not_3_divides,\nright,\nassumption, \nend\n\ntheorem main : \u2200 (n : \u2124), 3 \u2223 n * n - 1 \u2192 \u00ac (3 \u2223 n) :=\nbegin\nsorry\nend\n", "meta": {"author": "UVM-M52", "repo": "quiz-5-danisly", "sha": "d81d48aea4a81a9695f00a937d00833795f5b8dd", "save_path": "github-repos/lean/UVM-M52-quiz-5-danisly", "path": "github-repos/lean/UVM-M52-quiz-5-danisly/quiz-5-danisly-d81d48aea4a81a9695f00a937d00833795f5b8dd/src/quiz05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7489334290007996}}
{"text": "import algebra.big_operators data.set.finite\n\ndef matrix (\u03b1 : Type*) (m n : \u2115) := fin m \u2192 fin n \u2192 \u03b1\n\nnamespace matrix\nvariables {\u03b1 : Type*} [ring \u03b1]\nvariables {l m n o : \u2115}\n\ninstance : has_zero (matrix \u03b1 m n) :=\n\u27e8\u03bb _ _, 0\u27e9\n\ninstance : has_neg (matrix \u03b1 m n) :=\n\u27e8\u03bb M x y, - M x y\u27e9\n\ninstance : has_add (matrix \u03b1 m n) :=\n\u27e8\u03bb M N x y, M x y + N x y\u27e9\n\n@[simp] theorem add_val {M N : matrix \u03b1 m n} {x : fin m} {y : fin n} : (M + N) x y = M x y + N x y :=\nrfl\n\ntheorem add_assoc (L : matrix \u03b1 m n) (M : matrix \u03b1 m n) (N : matrix \u03b1 m n) :\n  L + (M + N) = (L + M) + N :=\nfunext $ \u03bb x, funext $ \u03bb y, by simp\n\ndef mul (M : matrix \u03b1 l m) (N : matrix \u03b1 m n) : matrix \u03b1 l n :=\n\u03bb x z, finset.univ.sum (\u03bb y, M x y * N y z)\n\n@[simp] theorem mul_val {M : matrix \u03b1 l m} {N : matrix \u03b1 m n} {x : fin l} {z : fin n} :\n  (M.mul N) x z = finset.univ.sum (\u03bb y, M x y * N y z) :=\nrfl\n\ntheorem mul_assoc (L : matrix \u03b1 l m) (M : matrix \u03b1 m n) (N : matrix \u03b1 n o) :\n  L.mul (M.mul N) = (L.mul M).mul N :=\nfunext $ \u03bb x, funext $ \u03bb z,\n  calc finset.univ.sum (\u03bb (y\u2081 : fin m), L x y\u2081 * finset.univ.sum (\u03bb (y\u2082 : fin n), M y\u2081 y\u2082 * N y\u2082 z))\n    = finset.univ.sum (\u03bb (y\u2081 : fin m), finset.univ.sum (\u03bb (y\u2082 : fin n), L x y\u2081 * M y\u2081 y\u2082 * N y\u2082 z)) :\n      by congr; funext; rw finset.mul_sum; congr; funext; rw mul_assoc\n    ... = finset.univ.sum (\u03bb (y\u2082 : fin n), finset.univ.sum (\u03bb (y\u2081 : fin m), L x y\u2081 * M y\u2081 y\u2082 * N y\u2082 z)) :\n      by rw finset.sum_comm\n    ... = finset.univ.sum (\u03bb (y\u2082 : fin n), finset.univ.sum (\u03bb (y\u2081 : fin m), L x y\u2081 * M y\u2081 y\u2082) * N y\u2082 z) :\n      by congr; funext; rw \u2190finset.sum_mul\n\nend matrix\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/xenalib/Sean_Leather_matrix_ring_cleanup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415278, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7489244629457374}}
{"text": "/-\nCopyright (c) 2020 The Xena project. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard.\nThanks: Imperial College London, leanprover-community\n-/\n\n-- We will assume that the real numbers are a field.\nimport data.real.basic\n\n/-!\n# The complex numbers\n\nWe define the complex numbers, and prove that they are a ring.\n\nWe also \"extract some basic API\" (e.g. we prove that\ntwo complex numbers are equal iff they have the same\nreal and imaginary parts)\n\nThis file has no `sorry`s in. All of the other levels:\n\n`I.lean`\n`conj.lean`\n`norm_sq.lean`\n`of_real.lean`\n`field.lean`\n`alg_closed.lean`\n\nhave sorrys, indicating puzzles to be solved.\n\n# Main Definitions\n\n`zero` : the complex number 0\n`one` : the complex number 1\n`add` -- addition of two complex numbers\n`neg` -- negation of a complex number\n`mul` -- multiplication of two complex numbers\n\n# Main Theorem\n\n`comm_ring` : The complex numbers are a commutative ring.\n\n-/\n\n/-- A complex number is defined to be a structure consisting of two real numbers,\n    the real part and the imaginary part of the complex number   . -/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\n-- Let's use the usual notation for the complex numbers\nnotation `\u2102` := complex\n\n-- You make the complex number with real part 3 and imaginary part 4 like this:\nexample : \u2102 :=\n{ re := 3,\n  im := 4 }\n\n-- Or like this:\nexample : \u2102 := complex.mk 3 4\n\n-- or like this:\nexample : \u2102 := \u27e83, 4\u27e9\n\n-- They all give the same complex number.\n\nexample : complex.mk 3 4 = \u27e83, 4\u27e9 := begin refl end  -- \"true by definition\"\n\n-- All of our definitions, like `zero` and `one`, will all\n-- live in the `complex` namespace.\n\nnamespace complex\n\n-- If you have a complex number, then you can get its real and \n-- imaginary parts with the `re` and `im` functions.\n\nexample : \u211d := re(mk 3 4) -- this term is (3 : \u211d)\n\nexample : re(mk 3 4) = 3 := begin refl end\n\n-- Computer scientists prefer the style `z.re` to `re(z)` for some reason. \n\nexample : (mk 3 4).re = 3 := begin refl end\n\nexample (z : \u2102) : re(z) = z.re := begin refl end\n\n-- Before we start making the basic \n-- We now prove the basic theorems and make the basic definitions for\n-- complex numbers. For example, we will define addition and multiplication on\n-- the complex numbers, and prove that it is a commutative ring.\n-- TODO fix\n\n/-! # Defining the ring structure on \u2102 -/\n\n-- Our main goal is to prove that the complexes are a ring. Let's\n-- define the structure first; the zero, one, addition and multiplication\n-- on the complexes. \n\n/-! ## zero (0) -/\n\n/-- The complex number with real part 0 and imaginary part 0 -/\ndef zero : \u2102 := \u27e80, 0\u27e9\n\n-- Now we set up notation so that `0 : \u2102` will mean `zero`. \n\n/-- notation `0` for `zero` -/\ninstance : has_zero \u2102 := \u27e8zero\u27e9\n\n-- Let's prove the two basic properties, both of which are true by definition,\n-- and then tag them with the appropriate attributes.\n@[simp] lemma zero_re : re(0 : \u2102) = 0 := begin refl end\n@[simp] lemma zero_im : im(0 : \u2102) = 0 := begin refl end\n\n/-! ## one (1) -/\n\n-- Now let's do the same thing for 1.\n\n/-- The complex number with real part 1 and imaginary part 0 -/\ndef one : \u2102 := \u27e81, 0\u27e9\n\n/-- Notation `1` for `one` -/\ninstance : has_one \u2102 := \u27e8one\u27e9 \n\n-- name the basic properties and tag them with `simp`\n@[simp] lemma one_re : re(1 : \u2102) = 1 := begin refl end\n@[simp] lemma one_im : im(1 : \u2102) = 0 := begin refl end\n\n/-! ## add (+) -/\n\n-- Now let's define addition\n\n/-- addition `z+w` of complex numbers -/\ndef add (z w : \u2102) : \u2102 := \u27e8z.re + w.re, z.im + w.im\u27e9\n\n/-- Notation `+` for addition -/\ninstance : has_add \u2102 := \u27e8add\u27e9\n\n-- basic properties\n@[simp] lemma add_re (z w : \u2102) : re(z + w) = re(z) + re(w) := begin refl end\n@[simp] lemma add_im (z w : \u2102) : im(z + w) = im(z) + im(w) := begin refl end\n\n/-! ## neg (-) -/\n\n-- negation\n\n/-- The negation `-z` of a complex number `z` -/\ndef neg (z : \u2102) : \u2102 := \u27e8-re(z), -im(z)\u27e9\n\n/-- Notation `-` for negation -/\ninstance : has_neg \u2102 := \u27e8neg\u27e9\n\n-- how neg interacts with re and im\n@[simp] lemma neg_re (z : \u2102) : re(-z) = -re(z) := begin refl end\n@[simp] lemma neg_im (z : \u2102) : im(-z) = -im(z) := begin refl end\n\n/-! ## mul (*) -/\n\n-- multiplication\n\n/-- Multiplication `z*w` of two complex numbers -/\ndef mul (z w : \u2102) : \u2102 := \u27e8re(z) * re(w) - im(z) * im(w), re(z) * im(w) + im(z) * re(w)\u27e9\n\n/-- Notation `*` for multiplication -/\ninstance : has_mul \u2102 := \u27e8mul\u27e9\n\n-- how `mul` reacts with `re` and `im`\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := begin refl end\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := begin refl end\n\n/-! ## Example of what `simp` can now do -/\n\nexample (a b c : \u2102) : re(a*(b+c)) = re(a) * (re(b) + re(c)) - im(a) * (im(b) + im(c)) :=\nbegin\n  simp,\nend\n\n\n/-! # `ext` : A mathematical triviality -/\n\n/- \nTwo complex numbers with the same and imaginary parts are equal.\nThis is an \"extensionality lemma\", i.e. a lemma of the form \"if two things\nare made from the same pieces, they are equal\".\nThis is not hard to prove, but we want to give the result a name\nso we can tag it with the `ext` attribute, meaning that the\n`ext` tactic will know it. To add to the confusion, let's call the theorem `ext` :-)\n-/\n\n/-- If two complex numbers z and w have equal real and imaginary parts, they are equal -/\n@[ext] theorem ext {z w : \u2102} (hre : re(z) = re(w)) (him : im(z) = im(w)) : z = w :=\nbegin\n  cases z with zr zi,\n  cases w with ww wi,\n  simp at *,\n  /- goal now a logic puzzle\n  \n  hre : zr = ww,\n  him : zi = wi\n  \u22a2 zr = ww \u2227 zi = wi\n  \n  -/\n  cc,\nend\n\n/-! # Theorem:  The complex numbers are a commutative ring -/\n\n-- Proof: we've defined all the structure, and every axiom can be checked by reducing it\n-- to checking real and imaginary parts with `ext`, expanding everything out with `simp`\n-- and then using the fact that the real numbers are a commutative ring.\ninstance : comm_ring \u2102 :=\nbegin\n  -- first the data\n  refine_struct {\n      zero := (0 : \u2102), add := (+), neg := has_neg.neg, one := 1, mul := (*),\n  ..},\n  -- now the axioms\n  -- of which there seem to be 11\n  -- introduce the variables\n  all_goals {intros},\n  -- we now have to prove an equality between two complex numbers.\n  -- It suffices to check on real and imaginary parts\n  all_goals {ext},\n  -- the simplifier can simplify stuff like re(a+0)\n  all_goals {simp},\n  -- all the goals now are identities between *real* numbers,\n  -- and the reals are already known to be a ring\n  all_goals {ring},\nend\n\n\n-- That is the end of the proof that the complexes form a ring. We built\n-- a basic API which was honed towards the general idea that to prove\n-- certain statements about the complex numbers, for example distributivity,\n-- we could just check on real and imaginary parts. We trained the\n-- simplifier to expand out things like re(z*w) in terms\n-- of re(z), im(z), re(w), im(w).\n\n/-!\n\n# Optional section for mathematicians : more basic infrastructure, and term mode\n\n-/\n\n/-! \n## `ext` revisited\n\nRecall extensionality:\n\n`theorem ext {z w : \u2102} (hre : re(z) = re(w)) (him : im(z) = im(w)) : z = w := ...`\n\nHere is another tactic mode proof of extensionality. Note that we have moved\nthe hypotheses to the other side of the colon; this does not\nchange the theorem. This proof shows the power\nof the `rintros` tactic.\n-/\n\ntheorem ext' : \u2200 z w : \u2102, z.re = w.re \u2192 z.im = w.im \u2192 z = w :=\nbegin\n  rintros \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 \u27e8rfl\u27e9 \u27e8rfl\u27e9,\n  refl,\nend\n\n\n/-\nExplanation: `rintros` does `cases` as many times as you like using this cool `\u27e8 \u27e9` syntax\nfor the case splits. Note that if you say that a proof of `a = b` is `rfl` then\nLean will define a to be b, or b to be a, and not even introduce new notation for it.\n-/\n\n-- Here is the same proof in term mode.\n\ntheorem ext'' : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\n/-!\n## `eta`\n-/\n\n/-\nWe prove the mathematically obvious statement that the\ncomplex number whose real part is re(z) and whose imaginary\npart is im(z) is of course equal to z.\n-/\n\n/-- \u27e8z.re, z.im\u27e9 is equal to z -/\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z :=\nbegin\n  intro z,\n  cases z with x y, \n  /-\n    goal now looks complicated, and contains terms which look\n    like {re := a, im := b}.re which obviously simplify to a.\n    The `dsimp` tactic will do some tidying up for us, although\n    it is not logically necessary. `dsimp` does definitional simplification.\n  -/\n  dsimp,\n  -- Now we see the goal can be solved by reflexivity\n  refl,\nend\n\n/-\nThe proof was \"unfold everything, and it's true by definition\".\nThis proof does not teach a mathematician anything, so we may as well write\nit in term mode. Many tactics have term mode equivalent.\nThe equation compiler does the `intro` and `cases` steps,\nand `dsimp` was unnecessary -- the two sides of the equation \nwere definitionally equal.\n-/\n\ntheorem eta' : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8x, y\u27e9 := rfl\n\n/-!\n## ext_iff\n-/\n\n/-\nNote that `ext` is an implication -- if re(z)=re(w) and im(z)=im(w) then z=w.\nThe below variant `ext_iff` is the two-way implication: two complex\nnumbers are equal if and only if they have the same real and imaginary part.\nLet's first see a tactic mode proof. See how the `ext` tactic is used?\nAfter it is applied, we have two goals, both of which are hypotheses.\nThe semicolon means \"apply the next tactic to all the goals produced by this one\"\n-/\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\nbegin\n  split,\n  { intro H,\n    simp [H]},\n  {\n    rintro \u27e8hre, him\u27e9,\n    ext; assumption,\n  }\nend\n\n-- Again this is easy to write in term mode, and no mathematician\n-- wants to read the proof anyway.\n\ntheorem ext_iff' {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\nend complex\n\n/-!\n\n# some last comments on the `simp` tactic\n\nSome equalities, even if obvious, had to be given names, because we want `simp`\nto be able to use them. In short, the `simp` tactic tries to solve\ngoals of the form A = B, when `refl` doesn't work (i.e. the goals are\nnot definitionally equal) but when any mathematician would be able\nto simplify A and B via \"obvious\" steps such as `0 + x = x` or\n`\u27e8z.re, z.im\u27e9 = z`. These things are sometimes not true by definition,\nbut they should be tagged as being well-known ways to simplify an equality.\nWhen building our API for the complex numbers, if we prove a theorem of the\nform `A = B` where `B` is a bit simpler than `A`, we should probably\ntag it with the `@[simp]` attribute, so `simp` can use it.\n\nNote: `simp` does *not* prove \"all simple things\". It proves *equalities*.\nIt proves `A = B` when, and only when, it can do it by applying \nits \"simplification rules\", where a simplification rule is simply a proof\nof a theorem of the form `A = B` and `B` is simpler than `A`.  \n-/\n", "meta": {"author": "ImperialCollegeLondon", "repo": "complex-number-game", "sha": "49d6ca66ded53a56dcd8a3f6dc87dbd755fcd0ac", "save_path": "github-repos/lean/ImperialCollegeLondon-complex-number-game", "path": "github-repos/lean/ImperialCollegeLondon-complex-number-game/complex-number-game-49d6ca66ded53a56dcd8a3f6dc87dbd755fcd0ac/kb_solutions/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7488840336810785}}
{"text": "/- Tactic : rw / rwa\n\n## Summary\n\nIf `h` is a proof of `X = Y`, then `rw h,` will change\nall `X`s in the goal to `Y`s. \n\n**Variants:** `rw \u2190 h` changes\n`Y` to `X` and\n`rw h at h2` changes `X` to `Y` in hypothesis `h2` instead\nof the goal.\n\n**Variant (rw and assumption):** If instead you use `rwa h` or `rwa \u2190 h`, Lean does performs\nthe `rw` and then looks whether\nthe goal is exactly one of your assumptions, in which case it closes it.\n\n## Details\n\nThe `rw` tactic is a way to do \"substituting in\". There\nare two distinct situations where use this tactics.\n\n1) If `h : A = B` is a hypothesis (i.e., a proof of `A = B`)\nin your local context (the box in the top right)\nand if your goal contains one or more `A`s, then `rw h`\nwill change them all to `B`'s. \n\n2) The `rw` tactic will also work with proofs of theorems\nwhich are equalities (look for them in the drop down\nmenu on the left, within Theorem Statements).\n\n**Important note:** if `h` is not a proof of the form `A = B`\nor `A \u2194 B` (for example if `h` is a function, an implication,\nor perhaps even a proposition itself rather than its proof),\nthen `rw` is not the tactic you want to use. For example,\n`rw (P = Q)` is never correct: `P = Q` is the true-false\nstatement itself, not the proof.\nIf `h : P = Q` is its proof, then `rw h` will work.\n\n**Pro tip 1:** If `h : A = B` and you want to change\n`B`s to `A`s instead, try `rw \u2190h` (get the arrow with `\\l`,\nnote that this is a small letter L, not a number 1).\n\n### Example:\nIf it looks like this in the top right hand box:\n```\nA B C : set X\nh : A = B \u222a C\n\u22a2 A \u222a B = B \u222a C\n```\n\nthen\n\n`rw h,`\n\nwill change the goal into `\u22a2 B \u222a C \u222a B = B \u222a C`.\n\n### Example: \nYou can use `rw` to change a hypothesis as well. \nFor example, if your local context looks like this:\n```\nA B C D : set X\nh1 : A = B \u2229 C\nh2 : B \u222a A = D\n\u22a2 D = B\n```\nthen `rw h1 at h2` will turn `h2` into `h2 : B \u222a B \u2229 C = D` (remember operator precedence).\n\n-/\n\n\n/-\nThe next tactic we will learn is *rw* (from rewrite). It rewrites equalities. That is,\nif we have a proof `h : A = B` and we want to prove `\u22a2 A \u2229 C = B \u2229 C`, then after `rw h` the goal\nwill become `\u22a2 A \u2229 C = A \u2229 C`, which seems reasonable.\n\nAfter many tactics (and `rw` is one of them) Lean tries to apply `refl`. This is why\nin the following proof you may get away with only one tactic application.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nDelete `sorry` and type `rw h,` (don't forget the comma!). Lean tries `refl` afterwards,\nso you will see that this suffices.\n-/\n\nvariables {X : Type} -- hide\n\n/- Lemma : no-side-bar\nIf A, B and C are sets and A = B, then A \u222a C = B \u222a C.\n-/\nlemma union_eq (A B C: set X) (h : A = B) : A \u222a C = B \u222a C :=\nbegin\n  rw h,\n  \nend\n", "meta": {"author": "mmasdeu", "repo": "topologygame", "sha": "0a1b868031919a5555e7b99efca66ece2f546ec7", "save_path": "github-repos/lean/mmasdeu-topologygame", "path": "github-repos/lean/mmasdeu-topologygame/topologygame-0a1b868031919a5555e7b99efca66ece2f546ec7/src/set_theory_world/level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.8918110454379297, "lm_q1q2_score": 0.7488840240226255}}
{"text": "import MyNat.Power\nnamespace MyNat\nopen MyNat\n\n/-!\n## Level 1: `zero_pow_zero`\n\nGiven the lemma `pow_zero` which says `m ^ 0 = 1`\nyou can now prove zero to the power of zero is also one.\n\n## Lemma\n`0 ^ 0 = 1`.\n-/\nlemma zero_pow_zero : (0 : MyNat) ^ (0 : MyNat) = 1 := by\n  rw [pow_zero]\n\n/-!\nThat was easy!  Next up [Level 2](./Level2.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/PowerWorld/Level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9504109770159683, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7488584503729849}}
{"text": "variables (real : Type) [ordered_ring real]\nvariables (log exp : real \u2192 real)\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\ncalc log (x * y)\n    = log (exp (log x) * exp (log y)) : by rw [exp_log_eq hx, exp_log_eq hy]\n... = log (exp (log x + log y))       : by rw exp_add\n... = log x + log y                   : by rw log_exp_eq\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/chap4_exercise6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176863577751, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7488322894738636}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport algebra.smul_with_zero\nimport algebra.regular\n/-!\n# Action of regular elements on a module\n\nWe introduce `M`-regular elements, in the context of an `R`-module `M`.  The corresponding\npredicate is called `is_smul_regular`.\n\nThere are very limited typeclass assumptions on `R` and `M`, but the \"mathematical\" case of interest\nis a commutative ring `R` acting an a module `M`. Since the properties are \"multiplicative\", there\nis no actual requirement of having an addition, but there is a zero in both `R` and `M`.\nSmultiplications involving `0` are, of course, all trivial.\n\nThe defining property is that an element `a \u2208 R` is `M`-regular if the smultiplication map\n`M \u2192 M`, defined by `m \u21a6 a \u2022 m`, is injective.\n\nThis property is the direct generalization to modules of the property `is_left_regular` defined in\n`algebra/regular`.  Lemma `is_smul_regular.is_left_regular_iff` shows that indeed the two notions\ncoincide.\n-/\n\nvariables {R S : Type*} (M : Type*) {a b : R} {s : S}\n\n/-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an\ninjective map `M \u2192 M`. -/\ndef is_smul_regular [has_scalar R M] (c : R) := function.injective ((\u2022) c : M \u2192 M)\n\nnamespace is_smul_regular\n\nvariables {M}\n\nsection has_scalar\n\nvariables [has_scalar R M] [has_scalar R S] [has_scalar S M] [is_scalar_tower R S M]\n\n/-- The product of `M`-regular elements is `M`-regular. -/\nlemma smul (ra : is_smul_regular M a) (rs : is_smul_regular M s) :\n  is_smul_regular M (a \u2022 s) :=\n\u03bb a b ab, rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _))))\n\n/-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular\nelement, then `b` is `M`-regular. -/\nlemma of_smul (a : R) (ab : is_smul_regular M (a \u2022 s)) :\n  is_smul_regular M s :=\n@function.injective.of_comp _ _ _ (\u03bb m : M, a \u2022 m) _ (\u03bb c d cd, ab\n  (by rwa [smul_assoc, smul_assoc]))\n\n/-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element\nis `M`-regular. -/\n@[simp] lemma smul_iff (b : S) (ha : is_smul_regular M a) :\n  is_smul_regular M (a \u2022 b) \u2194 is_smul_regular M b :=\n\u27e8of_smul _, ha.smul\u27e9\n\nend has_scalar\n\nsection monoid\n\nvariables [monoid R] [mul_action R M]\n\n/-- Left-regularity in a `monoid R` is equivalent to `M`-regularity, when the\n`R`-module `M` is `R`. -/\nlemma is_left_regular_iff (a : R) : is_left_regular a \u2194 is_smul_regular R a :=\niff.rfl\n\nvariable (M)\n\n/-- One is `M`-regular always. -/\n@[simp] lemma one : is_smul_regular M (1 : R) :=\n\u03bb a b ab, by rwa [one_smul, one_smul] at ab\n\nvariable {M}\n\nlemma mul (ra : is_smul_regular M a) (rb : is_smul_regular M b) :\n  is_smul_regular M (a * b) :=\nra.smul rb\n\nlemma of_mul (ab : is_smul_regular M (a * b)) :\n  is_smul_regular M b :=\nby { rw \u2190 smul_eq_mul at ab, exact ab.of_smul _ }\n\n@[simp] lemma mul_iff_right  (ha : is_smul_regular M a) :\n  is_smul_regular M (a * b) \u2194 is_smul_regular M b :=\n\u27e8of_mul, ha.mul\u27e9\n\n/-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a`\nare `M`-regular. -/\nlemma mul_and_mul_iff : is_smul_regular M (a * b) \u2227 is_smul_regular M (b * a) \u2194\n  is_smul_regular M a \u2227 is_smul_regular M b :=\nbegin\n  refine \u27e8_, _\u27e9,\n  { rintros \u27e8ab, ba\u27e9,\n    refine \u27e8ba.of_mul, ab.of_mul\u27e9 },\n  { rintros \u27e8ha, hb\u27e9,\n    exact \u27e8ha.mul hb, hb.mul ha\u27e9 }\nend\n\n/-- Any power of an `M`-regular element is `M`-regular. -/\nlemma pow (n : \u2115) (ra : is_smul_regular M a) : is_smul_regular M (a ^ n) :=\nbegin\n  induction n with n hn,\n  { simp only [one, pow_zero] },\n  { rw pow_succ, exact (ra.smul_iff (a ^ n)).mpr hn }\nend\n\n/-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/\nlemma pow_iff {n : \u2115} (n0 : 0 < n) :\n  is_smul_regular M (a ^ n) \u2194 is_smul_regular M a :=\nbegin\n  refine \u27e8_, pow n\u27e9,\n  rw [\u2190 nat.succ_pred_eq_of_pos n0, pow_succ', \u2190 smul_eq_mul],\n  exact of_smul _,\nend\n\nend monoid\n\nsection monoid_with_zero\n\nvariables [monoid_with_zero R] [monoid_with_zero S] [has_zero M] [mul_action_with_zero R M]\n  [mul_action_with_zero R S] [mul_action_with_zero S M] [is_scalar_tower R S M]\n\n/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\nprotected lemma subsingleton (h : is_smul_regular M (0 : R)) : subsingleton M :=\n\u27e8\u03bb a b, h (by repeat { rw mul_action_with_zero.zero_smul })\u27e9\n\n/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\nlemma zero_iff_subsingleton : is_smul_regular M (0 : R) \u2194 subsingleton M :=\n\u27e8\u03bb h, h.subsingleton, \u03bb H a b h, @subsingleton.elim _ H a b\u27e9\n\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\nlemma not_zero_iff : \u00ac is_smul_regular M (0 : R) \u2194 nontrivial M :=\nbegin\n  rw [nontrivial_iff, not_iff_comm, zero_iff_subsingleton, subsingleton_iff],\n  push_neg,\n  exact iff.rfl\nend\n\n/-- The element `0` is `M`-regular when `M` is trivial. -/\nlemma zero [sM : subsingleton M] : is_smul_regular M (0 : R) :=\nzero_iff_subsingleton.mpr sM\n\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\nlemma not_zero [nM : nontrivial M] : \u00ac is_smul_regular M (0 : R) :=\nnot_zero_iff.mpr nM\n\n/-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/\nlemma of_smul_eq_one (h : a \u2022 s = 1) : is_smul_regular M s :=\nof_smul a (by { rw h, exact one M })\n\n/-- An element of `R` admitting a left inverse is `M`-regular. -/\nlemma of_mul_eq_one (h : a * b = 1) : is_smul_regular M b :=\nof_mul (by { rw h, exact one M })\n\nend monoid_with_zero\n\nsection comm_monoid\n\nvariables [comm_monoid R] [mul_action R M]\n\n/-- A product is `M`-regular if and only if the factors are. -/\nlemma mul_iff : is_smul_regular M (a * b) \u2194\n  is_smul_regular M a \u2227 is_smul_regular M b :=\nbegin\n  rw \u2190 mul_and_mul_iff,\n  exact \u27e8\u03bb ab, \u27e8ab, by rwa mul_comm\u27e9, \u03bb rab, rab.1\u27e9\nend\n\nend comm_monoid\n\nend is_smul_regular\n\nvariables [monoid_with_zero R] [has_zero M] [mul_action_with_zero R M]\n\n/-- Any element in `units R` is `M`-regular. -/\nlemma units.is_smul_regular (a : units R) : is_smul_regular M (a : R)\n:=\nis_smul_regular.of_mul_eq_one a.inv_val\n\n/-- A unit is `M`-regular. -/\nlemma is_unit.is_smul_regular (ua : is_unit a) : is_smul_regular M a :=\nbegin\n  rcases ua with \u27e8a, rfl\u27e9,\n  exact a.is_smul_regular M\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/smul_regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7488032779766378}}
{"text": "import ..prooflab\nimport lectures.lec0_intro\n\n/-! # Homework 0 \nHomework must be done individually.\nReplace the placeholders `sorry` with your proofs only using tactics `refl`, `exact` and `rw`. \n-/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace PROOFS \n\n\n\n/-! ## Question 1  -/\n\nexample (x y : \u2115) : \n  y + 0 = y :=\nbegin\n  refl, \nend\n\n\n\n\n/-! ## Question 2 -/\n\nexample (m n : \u2115) (h\u2081 : n = 4) (h\u2082: m^2 = n) : \n  n = m^2 := \nbegin\n rw h\u2082,\nend\n\n\n\n\n/-! ## Question 3 -/\n\nexample (x y : \u2115) (h\u2081 : y = x) (h\u2082 : y - 1 = 0) : \n 5^(y - 1) = (2 + 3)^(x - 1) :=\nbegin\n  rw h\u2081, \nend\n\n\n\n\n/-! ## Question 4 -/\n\nexample (x y : \u2115) (h\u2081 : y = x) (h\u2082 : x - 1 = 0) : \n 5^(y - 1) = 5^0 :=\nbegin\n  rw h\u2081, -- this changes `y` to `x` in the left hand side of the goal. Therefore, our new goal is 5^(x-1) = 5 ^ 0 \n  rw h\u2082, -- this turns `x-1` into `0` by virtue of `h\u2082`\nend\n\n\n\n\n/-! ## Question 5 -/\n\nexample (a b c x y z : \u2115) (h\u2081 : 26 = x^2 + y^2 + z^2) \n(h\u2082 : x^2 = 2 * a) (h\u2083 : y^2 = b) (h\u2084 : z^2 = 2) : \n2 * a + b + 2 - z = 26 - z := \nbegin\n rw \u2190 h\u2082, \n rw \u2190 h\u2083, \n rw h\u2081, \n rw h\u2084, \nend \n\n\n\n\nend PROOFS", "meta": {"author": "sinhp", "repo": "ProofLab", "sha": "f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2", "save_path": "github-repos/lean/sinhp-ProofLab", "path": "github-repos/lean/sinhp-ProofLab/ProofLab-f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2/src/homework/hw0.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7487870958213648}}
{"text": "import algebra.ring\nimport data.real.basic\nimport tactic\n\nsection \nvariables (R : Type*) [ring R]\n\n#check (add_assoc : \u2200 a b c : R, a + b + c = a + (b + c))\n#check (add_comm : \u2200 a b : R, a + b = b + a)\n#check (zero_add : \u2200 a : R, 0 + a = a)\n#check (add_left_neg : \u2200 a : R, -a + a = 0)\n#check (mul_assoc : \u2200 a b c : R, a * b * c = a * (b * c))\n#check (mul_one : \u2200 a : R, a * 1 = a)\n#check (one_mul : \u2200 a : R, 1 * a = a)\n#check (mul_add : \u2200 a b c : R, a * (b + c) = a * b + a * c)\n#check (add_mul : \u2200 a b c : R, (a + b) * c = a * c + b * c)\nend\n\nsection\nvariables (R : Type*) [comm_ring R]\nvariables a b c d : R\n\nexample : (c * b) * a = b * (a * c) :=\nby ring\n\nexample : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nby ring\n\nexample : (a + b) * (a - b) = a^2 - b^2 :=\nby ring\n\nexample (hyp : c = d * a + b) (hyp' : b = a * d) :\n  c = 2 * a * d :=\nbegin\n  rw [hyp, hyp'],\n  ring\nend\nend\n\nnamespace my_ring\nvariables {R : Type*} [ring R]\n\ntheorem add_zero (a : R) : a + 0 = a :=\nby rw [add_comm, zero_add]\n\ntheorem add_right_neg (a : R) : a + -a = 0 :=\nby rw [add_comm, add_left_neg]\n\n#check @my_ring.add_zero\n#check @add_zero\n\nend my_ring\n\nnamespace my_ring\nvariables {R : Type*} [ring R]\n\ntheorem neg_add_cancel_left {a b : R} : -a + (a + b) = b :=\n  by rw [\u2190add_assoc, add_left_neg, zero_add]\n\ntheorem add_neg_cancel_right {a b : R} : (a + b) + -b = a :=\n  by rw [add_assoc, add_right_neg, add_zero]\n\ntheorem add_left_cancel {a b c : R} (h : a + b = a + c) : b = c :=\nbegin\n  have : -a + (a + b) = -a +(a + c) := by rw [h],\n  rw [neg_add_cancel_left, neg_add_cancel_left] at this,\n  exact this,\nend\n\ntheorem add_right_cancel {a b c : R} (h : a + b = c + b) : a = c :=\nbegin\n  have : b + a = b + c := by rw [add_comm a b, add_comm c b, h] at h; exact h, \n  exact add_left_cancel this\nend\n\ntheorem mul_zero (a : R) : a * 0 = 0 :=\nbegin\n  have h : a * 0 + a * 0 = a * 0 + 0,\n  { rw [\u2190mul_add, add_zero, add_zero] },\n  rw add_left_cancel h\nend\n\ntheorem zero_mul (a : R) : 0 * a = 0 :=\nbegin\n  have : 0 * a + 0 * a = 0 * a + 0,\n  { rw [\u2190add_mul, add_zero, add_zero]},\n  exact add_left_cancel this,\nend\n\ntheorem neg_eq_of_add_eq_zero {a b : R} (h : a + b = 0) : -a = b :=\nbegin\n  have : -a + (a + b) = -a + 0 := by rw[h],\n  have : b = -a := by rw [neg_add_cancel_left, add_zero] at this; exact this,\n  by rw this,\nend\n\ntheorem eq_neg_of_add_eq_zero {a b : R} (h : a + b = 0) : a = -b :=\nbegin\n  have : (a + b) + -b = 0 + -b := by rw [h],\n  rw [add_neg_cancel_right, zero_add] at this, \n  exact this,\nend\n\ntheorem neg_zero : (-0 : R) = 0 :=\nbegin\n  apply neg_eq_of_add_eq_zero,\n  rw add_zero\nend\n\ntheorem neg_neg (a : R) : -(-a) = a :=\nbegin  \n  have : -(-a) + -a = 0 := by rw add_left_neg,\n  have : (-(-a) + -a) + a = 0 + a := by rw [this],\n  have : -(-a) + (-a + a) = a := by rw [zero_add, add_assoc] at this; exact this,\n  rw [add_left_neg, add_zero] at this,\n  exact this\nend\n\nend my_ring\n\n\n\n\nnamespace my_ring\n\nvariables {R : Type*} [ring R]\n\ntheorem self_sub (a : R) : a - a = 0 :=\nbegin\n  calc \n    a - a\n        = (0 + a) - a : \n          by rw [zero_add]\n    ... = 0 : \n          by rw [sub_eq_add_neg, add_neg_cancel_right]\nend\n\nlemma one_add_one_eq_two : 1 + 1 = (2 : R) :=\nby refl\n\ntheorem two_mul (a : R) : 2 * a = a + a :=\nbegin \n  calc \n    2 * a \n        = (1 + 1) * a : by rw [one_add_one_eq_two]\n    ... = a + a : by rw [add_mul, one_mul]\nend\n\nend my_ring\n\n\nsection\nvariables (A : Type*) [add_group A]\n\n#check (add_assoc : \u2200 a b c : A, a + b + c = a + (b + c))\n#check (zero_add : \u2200 a : A, 0 + a = a)\n#check (add_left_neg : \u2200 a : A, -a + a = 0)\nend\n\nsection\nvariables {G : Type*} [group G]\n\n#check (mul_assoc : \u2200 a b c : G, a * b * c = a * (b * c))\n#check (one_mul : \u2200 a : G, 1 * a = a)\n#check (mul_left_inv : \u2200 a : G, a\u207b\u00b9 * a = 1)\n\nnamespace my_group\n\nlemma mul_left_cancel {a b c : G} : a * b = a * c \u2192 b = c := \nbegin\n  intros h,\n  have h : a\u207b\u00b9 * (a * b) = a\u207b\u00b9 * (a * c) := by rw [h],\n  have h : (a\u207b\u00b9 * a) * b = (a\u207b\u00b9 * a) * c := \n    by rw [h, \u2190mul_assoc, \u2190mul_assoc] at h; exact h,\n  have : 1 * b = 1 * c := \n    by rw [h, mul_left_inv] at h; exact h,\n  rw [one_mul, one_mul] at this,\n  exact this,\nend\n\n\n\ntheorem mul_right_inv {a : G} : a * a\u207b\u00b9 = 1 :=\nbegin\n  have : (a * a\u207b\u00b9)\u207b\u00b9 * ((a * a\u207b\u00b9) * (a * a\u207b\u00b9)) = 1 := \n    by rw [mul_assoc, \u2190mul_assoc a\u207b\u00b9 a, mul_left_inv, one_mul, mul_left_inv],\n  rw [\u2190this, \u2190mul_assoc, mul_left_inv, one_mul],\nend\n\ntheorem mul_one {a : G} : a * 1 = a :=\nbegin\n  calc \n    a * 1\n        = a * (a\u207b\u00b9 * a) : by rw [mul_left_inv]\n    ... = (a * a\u207b\u00b9) * a : by rw [mul_assoc]\n    ... = a : by rw [mul_right_inv, one_mul]\nend\n\nlemma mul_right_cancel {a b c : G} : a * c = b * c \u2192 a = b := \nbegin\n  intros h,\n  have : (a * c) * c\u207b\u00b9 = (b * c) * c\u207b\u00b9 := by rw [h],\n  have : a * (c * c\u207b\u00b9) = b * (c * c\u207b\u00b9) :=\n    by rw [mul_assoc, mul_assoc] at this; exact this,\n  have : a * 1 = b * 1 :=\n    by rw [mul_right_inv] at this; exact this,\n  rw [mul_one, mul_one] at this; exact this,\nend\n\n\ntheorem mul_inv_rev (a b : G) : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin \n  have : b\u207b\u00b9 * a\u207b\u00b9 = (a * b)\u207b\u00b9,\n    calc \n      b\u207b\u00b9 * a\u207b\u00b9 \n          = (a * b)\u207b\u00b9 * (a * b) * (b\u207b\u00b9 * a\u207b\u00b9) : \n            by rw [\u2190one_mul (b\u207b\u00b9 * a\u207b\u00b9), \u2190mul_left_inv (a * b), mul_left_inv, one_mul, one_mul]\n      ... = (a * b)\u207b\u00b9 * (a * (b * (b\u207b\u00b9 * a\u207b\u00b9))) : \n        by rw [mul_assoc, mul_assoc]\n      ... = (a * b)\u207b\u00b9 * a * (b * b\u207b\u00b9) * a\u207b\u00b9 : \n        by simp only [mul_assoc]\n      ... = (a * b)\u207b\u00b9 * (a * a \u207b\u00b9) :\n        by simp only [mul_right_inv, mul_one, mul_assoc]\n      ... = (a * b)\u207b\u00b9 :\n        by simp only [mul_right_inv, mul_one],\n  rw [this],\nend\n\n\nend my_group\nend\n\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/02_Basics/02_Proving_Identities_in_Algebraic_Structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.748775621858869}}
{"text": "/-\n -----------------------------------------------------------\n  Negligible functions. \n\n  TO-DO connect with security parameter, (or not, as in Nowak),\n  and refactor proofs/improve variable naming\n -----------------------------------------------------------\n-/\n\nimport analysis.special_functions.exp_log\nimport analysis.special_functions.pow\nimport data.nat.basic\nimport data.real.basic\n\n/- \n  A function f : \u2124\u22651 \u2192 \u211d is called negligible if \n  for all c \u2208 \u211d>0 there exists n\u2080 \u2208 \u2124\u22651 such that \n  n\u2080 \u2264 n \u2192  |f(n)| < 1/n^c\n-/\ndef negligible (f : \u2115 \u2192 \u211d) := \n  \u2200 c > 0, \u2203 n\u2080, \u2200 n, \n  n\u2080 \u2264 n \u2192 abs (f n) <  1 / (n : \u211d)^c\n\ndef negligible' (f : \u2115 \u2192 \u211d) :=\n  \u2200 (c : \u211d), \u2203 (n\u2080 : \u2115), \u2200 (n : \u2115),\n  0 < c \u2192 n\u2080 \u2264 n \u2192 abs (f n) < 1 / n^c\n\nlemma negl_equiv (f : \u2115 \u2192 \u211d) : negligible f \u2194 negligible' f := \nbegin\n  split,\n  {-- Forward direction\n    intros h c,\n    have arch := exists_nat_gt c,\n    cases arch with k hk,\n    let k\u2080 := max k 1,\n    have k_leq_k\u2080 : k \u2264 k\u2080 := le_max_left k 1,\n    have kr_leq_k\u2080r : (k:\u211d) \u2264 k\u2080 := nat.cast_le.mpr k_leq_k\u2080,\n    have k\u2080_pos : 0 < k\u2080 := by {apply le_max_right k 1},\n    have a := h k\u2080 k\u2080_pos,\n    cases a with n' hn\u2080,\n    let n\u2080 := max n' 1,\n    have n\u2080_pos : 0 < n\u2080 := by apply le_max_right n' 1,\n    have n'_leq_n\u2080 : n' \u2264 n\u2080 := le_max_left n' 1,\n    use n\u2080,\n    intros n c_pos hn,\n    have hnnn : n' \u2264 n := by linarith,\n    \n    have b : (n : \u211d)^c \u2264 (n : \u211d)^(k\u2080 : \u211d) := \n    begin\n      apply real.rpow_le_rpow_of_exponent_le,\n      norm_cast,\n      linarith,\n      linarith,\n    end,\n    have daf : (n : \u211d)^(k\u2080 : \u211d) = (n : \u211d)^k\u2080 := (n : \u211d).rpow_nat_cast k\u2080,\n    rw daf at b,\n    have d : 1 / (n : \u211d)^k\u2080 \u2264 1 / n^c := \n    begin\n      apply one_div_le_one_div_of_le,\n      { -- Proving 0 < (n:\u211d) ^ c\n        apply real.rpow_pos_of_pos,\n        norm_cast,\n        linarith,\n      },\n      {exact b},\n    end,\n    have goal :  abs (f n) < 1 / n^c := \n    calc\n      abs(f n) < 1 / (n : \u211d)^k\u2080 : hn\u2080 n hnnn\n           ... \u2264 1 / n^c : d,\n    exact goal,\n  },\n\n  {-- Reverse direction \n    intros h c hc,\n    cases h c with n\u2080 hn\u2080,\n    use n\u2080,\n    intros n hn,\n    have goal := hn\u2080 n (nat.cast_pos.mpr hc) hn,\n    rw (n : \u211d).rpow_nat_cast c at goal,\n    exact goal,\n  },\nend\n\nlemma zero_negl : negligible (\u03bbn, 0) := \nbegin\n  intros c hc,\n  use 1,\n  intros n hn,\n  norm_num,\n  apply one_div_pos.mpr,\n  apply pow_pos, \n  have h : 0 < n := by linarith,\n  exact nat.cast_pos.mpr h,\nend\n\nlemma negl_add_negl_negl {f g : \u2115 \u2192 \u211d} : negligible f \u2192 negligible g \u2192 negligible (f + g) := \nbegin\n  intros hf hg,\n  intros c hc,\n  have hc1 : (c+1) > 0 := nat.lt.step hc,\n  have hf2 := hf (c+1) hc1,\n  have hg2 := hg (c+1) hc1,\n  cases hf2 with nf hnf,\n  cases hg2 with ng hng,\n  let n\u2080 := max (max nf ng) 2,\n  use n\u2080,\n  intros n hn,\n  let nr := (n:\u211d),\n  have n_eq_nr : (n:\u211d) = nr := by refl,\n\n  have tn : max nf ng \u2264 n\u2080 := le_max_left (max nf ng) 2,\n  have t2n\u2080 : 2 \u2264 n\u2080 := le_max_right (max nf ng) 2,\n  have t2n : 2 \u2264 n := by linarith,\n  have t2nr : 2 \u2264 nr := \n  begin\n    have j := nat.cast_le.mpr t2n,\n    rw n_eq_nr at j,\n    norm_num at j,\n    exact j,\n    exact real.nontrivial,\n  end,\n  have tnr_pos : 0 < nr := by linarith,\n\n  have t2na : (1 / nr) * (1/nr^c) \u2264 (1 / (2 : \u211d)) * (1 / nr^c) := \n  begin\n    have ht2 : 0 < (1 / nr^c) := by {apply one_div_pos.mpr, exact pow_pos tnr_pos c},\n    apply (mul_le_mul_right ht2).mpr,\n    apply one_div_le_one_div_of_le,\n    exact zero_lt_two,\n    exact t2nr,\n  end,\n\n  have tnr2 : 1 / nr^(c + 1) \u2264 (1 / (2 : \u211d)) * (1 / nr^c) := \n  calc\n    1 / nr ^ (c + 1) = (1 / nr)^(c + 1) : by rw one_div_pow\n                 ... = (1 / nr) * (1 / nr)^c  : pow_succ (1 / nr) c\n                 ... = (1 / nr) * (1 / nr^c) : by rw one_div_pow\n                 ... \u2264 (1 / (2 : \u211d)) * (1 / nr^c) : t2na,\n  \n  have tnf : nf \u2264 n :=\n  calc \n    nf  \u2264 n\u2080 : le_of_max_le_left tn\n    ... \u2264 n : hn,\n  have tfn := hnf n tnf,\n  have tf : abs (f n) < (1 / (2 : \u211d)) * (1 / nr^c) := by linarith,\n\n  have tng : ng \u2264 n :=\n  calc ng  \u2264 n\u2080 : le_of_max_le_right tn\n       ... \u2264 n : hn,\n  have tgn := hng n tng,\n  have tg : abs (g n) < (1/(2:\u211d)) * (1/nr^c) := by linarith,\n\n  have goal : abs ((f + g) n) < 1 / nr ^ c := \n  calc\n    abs ((f + g) n) = abs (f n + g n) : by rw pi.add_apply f g n\n                ... \u2264 abs (f n) + abs (g n) : abs_add (f n) (g n)\n                ... < (1/(2:\u211d)) * (1/nr^c) + abs (g n): by linarith\n                ... < (1/(2:\u211d)) * (1/nr^c) + (1/(2:\u211d)) * (1/nr^c) : by linarith\n                ... = 1/nr^c : by ring_nf,\n  exact goal,\nend\n\nlemma bounded_negl_negl {f g : \u2115 \u2192 \u211d} (hg : negligible g): \n(\u2200 n, abs (f n) \u2264 abs (g n)) \u2192 negligible f := \nbegin\n  intro h,\n  intros c hc,\n  have hh := hg c hc,\n  cases hh with n\u2080 hn\u2080, \n  use n\u2080,\n  intros n hn,\n  have goal : abs (f n) < 1 / (n : \u211d) ^ c := \n  calc \n    abs (f n) \u2264 abs (g n) : h n\n          ... < 1 / (n : \u211d)^c: hn\u2080 n hn,\n  exact goal,\nend\n\nlemma nat_mul_negl_negl {f : \u2115 \u2192 \u211d} (m : \u2115): \nnegligible f \u2192 negligible (\u03bbn, m * (f n)) := \nbegin\n  intros hf,\n  induction m with k hk,\n  { -- Base case\n    norm_num,\n    exact zero_negl,\n  },\n  { -- Inductive step\n    norm_num,\n    have d : (\u03bbn, ((k : \u211d) + 1) * (f n)) = (\u03bbn, (k : \u211d) * (f n)) + (\u03bbn, f n) := \n      by repeat {ring_nf},\n    rw d, \n    apply negl_add_negl_negl,\n    exact hk,\n    exact hf,\n  },\nend\n\nlemma const_mul_negl_negl {f : \u2115 \u2192 \u211d} (m : \u211d) : \nnegligible f \u2192 negligible (\u03bbn, m * (f n)) := \nbegin\n  intro hf,\n  -- Use Archimedian property to get arch : \u2115 with abs m < arch\n  have arch := exists_nat_gt (abs m),\n  cases arch with k hk,\n  apply bounded_negl_negl,\n\n  { -- Demonstrate a negligible function kf  \n    have kf_negl := nat_mul_negl_negl k hf,\n    exact kf_negl,\n  },\n\n  { -- Show kf bounds mf from above\n    intro n,\n    have h : abs m \u2264 abs (k : \u211d) := \n    calc \n      abs m \u2264 (k : \u211d) : le_of_lt hk\n        ... = abs (k : \u211d) : (nat.abs_cast k).symm,\n\n    have goal : abs (m * f n) \u2264 abs ((k : \u211d) * f n) := \n    calc \n      abs (m * f n) = abs m * abs (f n) : by rw abs_mul\n                ... \u2264 abs (k : \u211d) * abs (f n) : mul_mono_nonneg (abs_nonneg (f n)) h\n                ... = abs ((k : \u211d) * f n) : by rw <- abs_mul,\n      \n    exact goal,\n  },  \nend\n\ntheorem neg_exp_negl : negligible ((\u03bbn, (1 : \u211d) / 2^n) : \u2115 \u2192 \u211d) := by sorry\n\n-- Need to prove lim n^c/2^n = 0 by induction on c using L'Hopital's rule to apply inductive \n-- hypothesis\n/-\nbegin\n  let m := 2,\n  have hm : 0 < 2 := zero_lt_two,\n  have c2_negl := c2_mul_neg_exp_is_negl 2 hm,\n  have r : (\u03bb (n : \u2115), 16 * (1 / (2 ^ n * 16)): \u2115 \u2192 \u211d) = ((\u03bbn, (1:\u211d)/2^n): \u2115 \u2192 \u211d) := \n  begin\n    funext,\n    have h : (1:\u211d) / 2^n / 16 = (1:\u211d) / (2^n * 16) := div_div_eq_div_mul 1 (2^n) 16,\n    rw <- h,\n    ring_nf,  \n  end,\n  \n  have goal := const_mul_negl_is_negl 16 c2_negl,\n  norm_num at goal,\n  rw <-r,\n  exact goal,\nend -/\n", "meta": {"author": "JoeyLupo", "repo": "cryptolib", "sha": "70cb8e5d9dfeb77acc5c0697ad696cae31500c95", "save_path": "github-repos/lean/JoeyLupo-cryptolib", "path": "github-repos/lean/JoeyLupo-cryptolib/cryptolib-70cb8e5d9dfeb77acc5c0697ad696cae31500c95/src/negligible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7487749264192679}}
{"text": "import Mathlib.Data.Real.Basic\n\n/- \nLean is a programming language which can be used to prove maths theorems.\n\nHere we will prove a theorem from 1st year analysis: \n\n  If `x\u2099 \u2192 s` and `y\u2099 \u2192 t` then `x\u2099 + y\u2099 \u2192 s + t`  \n\n(Don't worry if the code below doesn't mean anything to you, this example is\nsimply intended to show you what Lean can do.)\n\n-/\n\ndef limit (x : \u2115 \u2192 \u211d) (l : \u211d) : Prop := \n\u2200 \u03b5 > 0, \u2203 K, \u2200 n, n \u2265 K \u2192 |x n - l| < \u03b5 \n\n\ntheorem sum_limits (x y : \u2115 \u2192 \u211d) (s t : \u211d) (hx : limit x s) (hy : limit y t) :\n  limit (\u03bb n => x n + y n) (s + t) :=\nby\n  intros \u03b5 h\u03b5                    -- Given \u03b5 \u2208 \u211d satisyfing \u03b5 > 0\n  dsimp                           -- simplify for the reader\n  specialize hx (\u03b5/2)            -- use the hypothesis x\u2099 \u2192 s with \u03b5/2\n  specialize hy (\u03b5/2)            -- use the hypothesis y\u2099 \u2192 t with \u03b5/2 \n  have : (\u03b5/2) > 0 := half_pos h\u03b5 -- need to check that \u03b5/2 > 0 \n  cases' hx this with A hA         -- obtain A \u2208 \u2115 using \u03b5/2 > 0 and x\u2099 \u2192 s\n  cases' hy this with B hB         -- obtain B \u2208 \u2115 using \u03b5/2 > 0 and y\u2099 \u2192 t\n  clear hx h\u03b5 hy this             -- clear statements we no longer need\n  use max A B                     -- use the max(A,B) as our \"K\"\n  intros n hn                     -- given n \u2208 \u2115 with n \u2265 max(A,B) need to prove..\n  -- we can prove intermediate results and use them later\n  have AleM : A \u2264 max A B := le_max_left A B -- A \u2264 max(A,B)\n  -- We now have `A \u2264 max(A,B)`and `max(A,B) \u2264 n` so Lean can deduce `A \u2264 n`\n  have Alen : A \u2264 n := AleM.trans hn\n  specialize hA n Alen \n  specialize hB n (le_trans (le_max_right A B) hn) \n  -- Need to rearrange terms -- use the `ring` tactic \n  have rearrange: x n + y n  - (s + t) = x n - s + (y n - t) := add_sub_add_comm _ _ _ _\n  rw [rearrange]  -- rewrite this rearranged expression in the goal\n  -- Now apply triangle-inequality\n  have tri: |x n  - s + (y n - t)| \u2264 |x n - s| + |y n - t| := abs_add _ _\n  apply lt_of_le_of_lt tri \n  rw [\u2190 add_halves \u03b5]\n  apply add_lt_add hA hB\n\n#print sum_limits\n", "meta": {"author": "jt496", "repo": "Lean4_Test", "sha": "ec62c927827ab38b6aedadb59783a6d5066f3eb0", "save_path": "github-repos/lean/jt496-Lean4_Test", "path": "github-repos/lean/jt496-Lean4_Test/Lean4_Test-ec62c927827ab38b6aedadb59783a6d5066f3eb0/src/1_types_and_functions/examples_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342037088041, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7487217021754944}}
{"text": "-- let X, Y, Z be sets.\nvariables {X Y Z : Type} \n\n-- a function f : X \u2192 Y is *injective* if f(a) = f(b) \u2192 a = b for all a,b in X.\ndef injective (f : X \u2192 Y)  : Prop :=\n\u2200 a b : X, f(a) = f(b) \u2192 a = b\n\n-- challenge: the composite of two injective functions is injective\ntheorem challenge1\n  (f : X \u2192 Y) (hf : injective f)\n  (g : Y \u2192 Z) (hg : injective g) :\ninjective (g \u2218 f) :=\nbegin\n  sorry\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Maths_Challenges/src/challenges/challenge1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9566342024724487, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7487216915086606}}
{"text": "/-\nCopyright (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n-/\nprelude\nimport init.logic init.classical init.meta.name init.algebra.classes\n/- Make sure instances defined in this file have lower priority than the ones\n   defined for concrete structures -/\nset_option default_priority 100\n\nset_option old_structure_cmd true\n\nuniverse u\nvariables {\u03b1 : Type u}\n\nset_option auto_param.check_exists false\n\nsection preorder\n\n/-!\n### Definition of `preorder` and lemmas about types with a `preorder`\n-/\n\n/-- A preorder is a reflexive, transitive relation `\u2264` with `a < b` defined in the obvious way. -/\nclass preorder (\u03b1 : Type u) extends has_le \u03b1, has_lt \u03b1 :=\n(le_refl : \u2200 a : \u03b1, a \u2264 a)\n(le_trans : \u2200 a b c : \u03b1, a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c)\n(lt := \u03bb a b, a \u2264 b \u2227 \u00ac b \u2264 a)\n(lt_iff_le_not_le : \u2200 a b : \u03b1, a < b \u2194 (a \u2264 b \u2227 \u00ac b \u2264 a) . order_laws_tac)\n\nvariables [preorder \u03b1]\n\n/-- The relation `\u2264` on a preorder is reflexive. -/\n@[refl] lemma le_refl : \u2200 a : \u03b1, a \u2264 a :=\npreorder.le_refl\n\n/-- The relation `\u2264` on a preorder is transitive. -/\n@[trans] lemma le_trans : \u2200 {a b c : \u03b1}, a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c :=\npreorder.le_trans\n\nlemma lt_iff_le_not_le : \u2200 {a b : \u03b1}, a < b \u2194 (a \u2264 b \u2227 \u00ac b \u2264 a) :=\npreorder.lt_iff_le_not_le\n\nlemma lt_of_le_not_le : \u2200 {a b : \u03b1}, a \u2264 b \u2192 \u00ac b \u2264 a \u2192 a < b\n| a b hab hba := lt_iff_le_not_le.mpr \u27e8hab, hba\u27e9\n\nlemma le_not_le_of_lt : \u2200 {a b : \u03b1}, a < b \u2192 a \u2264 b \u2227 \u00ac b \u2264 a\n| a b hab := lt_iff_le_not_le.mp hab\n\nlemma le_of_eq {a b : \u03b1} : a = b \u2192 a \u2264 b :=\n\u03bb h, h \u25b8 le_refl a\n\n@[trans] lemma ge_trans : \u2200 {a b c : \u03b1}, a \u2265 b \u2192 b \u2265 c \u2192 a \u2265 c :=\n\u03bb a b c h\u2081 h\u2082, le_trans h\u2082 h\u2081\n\nlemma lt_irrefl : \u2200 a : \u03b1, \u00ac a < a\n| a haa := match le_not_le_of_lt haa with\n  | \u27e8h1, h2\u27e9 := false.rec _ (h2 h1)\n  end\n\nlemma gt_irrefl : \u2200 a : \u03b1, \u00ac a > a :=\nlt_irrefl\n\n@[trans] lemma lt_trans : \u2200 {a b c : \u03b1}, a < b \u2192 b < c \u2192 a < c\n| a b c hab hbc :=\n  match le_not_le_of_lt hab, le_not_le_of_lt hbc with\n  | \u27e8hab, hba\u27e9, \u27e8hbc, hcb\u27e9 := lt_of_le_not_le (le_trans hab hbc) (\u03bb hca, hcb (le_trans hca hab))\n  end\n\n@[trans] lemma gt_trans : \u2200 {a b c : \u03b1}, a > b \u2192 b > c \u2192 a > c :=\n\u03bb a b c h\u2081 h\u2082, lt_trans h\u2082 h\u2081\n\nlemma ne_of_lt {a b : \u03b1} (h : a < b) : a \u2260 b :=\n\u03bb he, absurd h (he \u25b8 lt_irrefl a)\n\nlemma ne_of_gt {a b : \u03b1} (h : b < a) : a \u2260 b :=\n\u03bb he, absurd h (he \u25b8 lt_irrefl a)\n\nlemma lt_asymm {a b : \u03b1} (h : a < b) : \u00ac b < a :=\n\u03bb h1 : b < a, lt_irrefl a (lt_trans h h1)\n\nlemma le_of_lt : \u2200 {a b : \u03b1}, a < b \u2192 a \u2264 b\n| a b hab := (le_not_le_of_lt hab).left\n\n@[trans] lemma lt_of_lt_of_le : \u2200 {a b c : \u03b1}, a < b \u2192 b \u2264 c \u2192 a < c\n| a b c hab hbc :=\n  let \u27e8hab, hba\u27e9 := le_not_le_of_lt hab in\n  lt_of_le_not_le (le_trans hab hbc) $ \u03bb hca, hba (le_trans hbc hca)\n\n@[trans] lemma lt_of_le_of_lt : \u2200 {a b c : \u03b1}, a \u2264 b \u2192 b < c \u2192 a < c\n| a b c hab hbc :=\n  let \u27e8hbc, hcb\u27e9 := le_not_le_of_lt hbc in\n  lt_of_le_not_le (le_trans hab hbc) $ \u03bb hca, hcb (le_trans hca hab)\n\n@[trans] lemma gt_of_gt_of_ge {a b c : \u03b1} (h\u2081 : a > b) (h\u2082 : b \u2265 c) : a > c :=\nlt_of_le_of_lt h\u2082 h\u2081\n\n@[trans] lemma gt_of_ge_of_gt {a b c : \u03b1} (h\u2081 : a \u2265 b) (h\u2082 : b > c) : a > c :=\nlt_of_lt_of_le h\u2082 h\u2081\n\nlemma not_le_of_gt {a b : \u03b1} (h : a > b) : \u00ac a \u2264 b :=\n(le_not_le_of_lt h).right\n\nlemma not_lt_of_ge {a b : \u03b1} (h : a \u2265 b) : \u00ac a < b :=\n\u03bb hab, not_le_of_gt hab h\n\nlemma le_of_lt_or_eq : \u2200 {a b : \u03b1}, (a < b \u2228 a = b) \u2192 a \u2264 b\n| a b (or.inl hab) := le_of_lt hab\n| a b (or.inr hab) := hab \u25b8 le_refl _\n\nlemma le_of_eq_or_lt {a b : \u03b1} (h : a = b \u2228 a < b) : a \u2264 b :=\nor.elim h le_of_eq le_of_lt\n\ninstance decidable_lt_of_decidable_le [decidable_rel ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)] :\n  decidable_rel ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop)\n| a b :=\n  if hab : a \u2264 b then\n    if hba : b \u2264 a then\n      is_false $ \u03bb hab', not_le_of_gt hab' hba\n    else\n      is_true $ lt_of_le_not_le hab hba\n  else\n    is_false $ \u03bb hab', hab (le_of_lt hab')\n\nend preorder\n\nsection partial_order\n\n/-!\n### Definition of `partial_order` and lemmas about types with a partial order\n-/\n\n/-- A partial order is a reflexive, transitive, antisymmetric relation `\u2264`. -/\nclass partial_order (\u03b1 : Type u) extends preorder \u03b1 :=\n(le_antisymm : \u2200 a b : \u03b1, a \u2264 b \u2192 b \u2264 a \u2192 a = b)\n\nvariables [partial_order \u03b1]\n\nlemma le_antisymm : \u2200 {a b : \u03b1}, a \u2264 b \u2192 b \u2264 a \u2192 a = b :=\npartial_order.le_antisymm\n\nlemma le_antisymm_iff {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 b \u2264 a :=\n\u27e8\u03bbe, \u27e8le_of_eq e, le_of_eq e.symm\u27e9, \u03bb\u27e8h1, h2\u27e9, le_antisymm h1 h2\u27e9\n\nlemma lt_of_le_of_ne {a b : \u03b1} : a \u2264 b \u2192 a \u2260 b \u2192 a < b :=\n\u03bb h\u2081 h\u2082, lt_of_le_not_le h\u2081 $ mt (le_antisymm h\u2081) h\u2082\n\ninstance decidable_eq_of_decidable_le [decidable_rel ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)] :\n  decidable_eq \u03b1\n| a b :=\n  if hab : a \u2264 b then\n    if hba : b \u2264 a then\n      is_true (le_antisymm hab hba)\n    else\n      is_false (\u03bb heq, hba (heq \u25b8 le_refl _))\n  else\n    is_false (\u03bb heq, hab (heq \u25b8 le_refl _))\n\nnamespace decidable\n\nvariables [@decidable_rel \u03b1 (\u2264)]\n\nlemma lt_or_eq_of_le {a b : \u03b1} (hab : a \u2264 b) : a < b \u2228 a = b :=\nif hba : b \u2264 a then or.inr (le_antisymm hab hba)\nelse or.inl (lt_of_le_not_le hab hba)\n\nlemma eq_or_lt_of_le {a b : \u03b1} (hab : a \u2264 b) : a = b \u2228 a < b :=\n(lt_or_eq_of_le hab).swap\n\nlemma le_iff_lt_or_eq {a b : \u03b1} : a \u2264 b \u2194 a < b \u2228 a = b :=\n\u27e8lt_or_eq_of_le, le_of_lt_or_eq\u27e9\n\nend decidable\n\nlocal attribute [instance] classical.prop_decidable\n\nlemma lt_or_eq_of_le {a b : \u03b1} : a \u2264 b \u2192 a < b \u2228 a = b := decidable.lt_or_eq_of_le\n\nlemma le_iff_lt_or_eq {a b : \u03b1} : a \u2264 b \u2194 a < b \u2228 a = b := decidable.le_iff_lt_or_eq\n\nend partial_order\n\nsection linear_order\n\n/-!\n### Definition of `linear_order` and lemmas about types with a linear order\n-/\n\n/-- Default definition of `max`. -/\ndef max_default {\u03b1 : Type u} [has_le \u03b1] [decidable_rel ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)] (a b : \u03b1) :=\nif b \u2264 a then a else b\n\n/-- Default definition of `min`. -/\ndef min_default {\u03b1 : Type u} [has_le \u03b1] [decidable_rel ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)] (a b : \u03b1) :=\nif a \u2264 b then a else b\n\n/-- A linear order is reflexive, transitive, antisymmetric and total relation `\u2264`.\nWe assume that every linear ordered type has decidable `(\u2264)`, `(<)`, and `(=)`. -/\nclass linear_order (\u03b1 : Type u) extends partial_order \u03b1 :=\n(le_total : \u2200 a b : \u03b1, a \u2264 b \u2228 b \u2264 a)\n(decidable_le : decidable_rel (\u2264))\n(decidable_eq : decidable_eq \u03b1 := @decidable_eq_of_decidable_le _ _ decidable_le)\n(decidable_lt : decidable_rel ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n    @decidable_lt_of_decidable_le _ _ decidable_le)\n(max : \u03b1 \u2192 \u03b1 \u2192 \u03b1 := @max_default \u03b1 _ _)\n(max_def : max = @max_default \u03b1 _ decidable_le . tactic.interactive.reflexivity)\n(min : \u03b1 \u2192 \u03b1 \u2192 \u03b1 := @min_default \u03b1 _ _)\n(min_def : min = @min_default \u03b1 _ decidable_le . tactic.interactive.reflexivity)\n\nvariables [linear_order \u03b1]\n\nlocal attribute [instance] linear_order.decidable_le\n\nlemma le_total : \u2200 a b : \u03b1, a \u2264 b \u2228 b \u2264 a :=\nlinear_order.le_total\n\nlemma le_of_not_ge {a b : \u03b1} : \u00ac a \u2265 b \u2192 a \u2264 b :=\nor.resolve_left (le_total b a)\n\nlemma le_of_not_le {a b : \u03b1} : \u00ac a \u2264 b \u2192 b \u2264 a :=\nor.resolve_left (le_total a b)\n\nlemma not_lt_of_gt {a b : \u03b1} (h : a > b) : \u00ac a < b :=\nlt_asymm h\n\nlemma lt_trichotomy (a b : \u03b1) : a < b \u2228 a = b \u2228 b < a :=\nor.elim (le_total a b)\n  (\u03bb h : a \u2264 b, or.elim (decidable.lt_or_eq_of_le h)\n    (\u03bb h : a < b, or.inl h)\n    (\u03bb h : a = b, or.inr (or.inl h)))\n  (\u03bb h : b \u2264 a, or.elim (decidable.lt_or_eq_of_le h)\n    (\u03bb h : b < a, or.inr (or.inr h))\n    (\u03bb h : b = a, or.inr (or.inl h.symm)))\n\nlemma le_of_not_lt {a b : \u03b1} (h : \u00ac b < a) : a \u2264 b :=\nmatch lt_trichotomy a b with\n| or.inl hlt          := le_of_lt hlt\n| or.inr (or.inl heq) := heq \u25b8 le_refl a\n| or.inr (or.inr hgt) := absurd hgt h\nend\n\nlemma le_of_not_gt {a b : \u03b1} : \u00ac a > b \u2192 a \u2264 b := le_of_not_lt\n\nlemma lt_of_not_ge {a b : \u03b1} (h : \u00ac a \u2265 b) : a < b :=\nlt_of_le_not_le ((le_total _ _).resolve_right h) h\n\nlemma lt_or_le (a b : \u03b1) : a < b \u2228 b \u2264 a :=\nif hba : b \u2264 a then or.inr hba else or.inl $ lt_of_not_ge hba\n\nlemma le_or_lt (a b : \u03b1) : a \u2264 b \u2228 b < a :=\n(lt_or_le b a).swap\n\nlemma lt_or_ge : \u2200 (a b : \u03b1), a < b \u2228 a \u2265 b := lt_or_le\nlemma le_or_gt : \u2200 (a b : \u03b1), a \u2264 b \u2228 a > b := le_or_lt\n\nlemma lt_or_gt_of_ne {a b : \u03b1} (h : a \u2260 b) : a < b \u2228 a > b :=\nmatch lt_trichotomy a b with\n| or.inl hlt          := or.inl hlt\n| or.inr (or.inl heq) := absurd heq h\n| or.inr (or.inr hgt) := or.inr hgt\nend\n\nlemma ne_iff_lt_or_gt {a b : \u03b1} : a \u2260 b \u2194 a < b \u2228 a > b :=\n\u27e8lt_or_gt_of_ne, \u03bbo, or.elim o ne_of_lt ne_of_gt\u27e9\n\nlemma lt_iff_not_ge (x y : \u03b1) : x < y \u2194 \u00ac x \u2265 y :=\n\u27e8not_le_of_gt, lt_of_not_ge\u27e9\n\n@[simp] lemma not_lt {a b : \u03b1} : \u00ac a < b \u2194 b \u2264 a := \u27e8le_of_not_gt, not_lt_of_ge\u27e9\n\n@[simp] lemma not_le {a b : \u03b1} : \u00ac a \u2264 b \u2194 b < a := (lt_iff_not_ge _ _).symm\n\ninstance (a b : \u03b1) : decidable (a < b) :=\nlinear_order.decidable_lt a b\n\ninstance (a b : \u03b1) : decidable (a \u2264 b) :=\nlinear_order.decidable_le a b\n\ninstance (a b : \u03b1) : decidable (a = b) :=\nlinear_order.decidable_eq a b\n\nlemma eq_or_lt_of_not_lt {a b : \u03b1} (h : \u00ac a < b) : a = b \u2228 b < a :=\nif h\u2081 : a = b then or.inl h\u2081\nelse or.inr (lt_of_not_ge (\u03bb hge, h (lt_of_le_of_ne hge h\u2081)))\n\ninstance : is_total_preorder \u03b1 (\u2264) :=\n{trans := @le_trans _ _, total := le_total}\n\n/- TODO(Leo): decide whether we should keep this instance or not -/\ninstance is_strict_weak_order_of_linear_order : is_strict_weak_order \u03b1 (<) :=\nis_strict_weak_order_of_is_total_preorder lt_iff_not_ge\n\n/- TODO(Leo): decide whether we should keep this instance or not -/\ninstance is_strict_total_order_of_linear_order : is_strict_total_order \u03b1 (<) :=\n{ trichotomous := lt_trichotomy }\n\n/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order. -/\ndef lt_by_cases (x y : \u03b1) {P : Sort*}\n  (h\u2081 : x < y \u2192 P) (h\u2082 : x = y \u2192 P) (h\u2083 : y < x \u2192 P) : P :=\nif h : x < y then h\u2081 h else\nif h' : y < x then h\u2083 h' else\nh\u2082 (le_antisymm (le_of_not_gt h') (le_of_not_gt h))\n\nlemma le_imp_le_of_lt_imp_lt {\u03b2} [preorder \u03b1] [linear_order \u03b2]\n  {a b : \u03b1} {c d : \u03b2} (H : d < c \u2192 b < a) (h : a \u2264 b) : c \u2264 d :=\nle_of_not_lt $ \u03bb h', not_le_of_gt (H h') h\n\nend linear_order\n", "meta": {"author": "subfish-zhou", "repo": "N2Lean", "sha": "8e858cc5b01f1ad921094dc355db3cb9473a42fd", "save_path": "github-repos/lean/subfish-zhou-N2Lean", "path": "github-repos/lean/subfish-zhou-N2Lean/N2Lean-8e858cc5b01f1ad921094dc355db3cb9473a42fd/library/init/algebra/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8807970889295664, "lm_q1q2_score": 0.7486521304984751}}
{"text": "/-\n| All possible ways to choose @k@ elements from a list, /with repetitions/. \n\\\"Symmetric power\\\" for lists. See also \"Math.Combinat.Compositions\".\nFrom Math.Combinat.Sets\n\n>>> combine 3 ['a','b','c']\n[\"aaa\",\"aab\",\"aac\",\"abb\",\"abc\",\"acc\",\"bbb\",\"bbc\",\"bcc\",\"ccc\"]\n\n>>> combine 4 ['a', 'b']\n[\"aaaa\",\"aaab\",\"aabb\",\"abbb\",\"bbbb\"]\n\ncombine :: Int -> [a] -> [[a]]\ncombine 0 _  = [[]]\ncombine k [] = []\ncombine k xxs@(x:xs) = map (x:) (combine (k-1) xxs) ++ combine k xs\n\n| All possible ways to choose @k@ elements from a list, without\nrepetitions. \\\"Antisymmetric power\\\" for lists. Synonym for 'kSublists'.\n*Perms> choose 2 [1,2,3,4]\n[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]\n\nchoose :: Int -> [a] -> [[a]]\nchoose 0 _  = [[]]\nchoose k [] = []\nchoose k (x:xs) = map (x:) (choose (k-1) xs) ++ choose k xs\n-/\n\nopen list\n\n#check @map -- (\u03b1 \u2192 \u03b2) \u2192 list \u03b1 \u2192 list \u03b2\n\nconstant  \u03b1 : Type\nconstant combine : \u2115 \u2192 list \u03b1 \u2192 list (list \u03b1)\nconstant choose  : \u2115 \u2192 list \u03b1 \u2192 list (list \u03b1)\n\n-- noncomputable instance : has_add \u03b1 := \u27e8list.append\u27e9\n\naxiom combine.zero (xs : list \u03b1) : combine 0 xs = [[]]\naxiom combine.empty (k : \u2115) : combine k [] = []\naxiom combine.step (k : \u2115) (x : \u03b1) (xs : list \u03b1) :\n  combine (k+1) (x::xs) = map (cons x) (combine k (x::xs)) ++ combine (k+1) xs\n\nexample : (\u03bb (x : \u2115), x + 1) 5 = 6 := rfl\nexample : (\u03bb (xs : list \u2115), 100 :: xs) [] = [100] := rfl\n\nattribute [simp] combine.zero combine.empty\n\nnamespace helper\nvariable x : \u03b1\n#reduce map (\u03bb (ys : list \u03b1), x :: ys) [nil] ++ nil -- [[x]]\nend helper\n\nexample : combine 0 [] = [[]] := combine.zero nil\nexample (x : \u03b1) : combine 1 [x] = [[x]] := by {\n  rw [ combine.step, combine.zero, combine.empty ],\n  refl,\n}\n\nset_option trace.simplify.rewrite true\n\nnamespace vars\nvariables (x y z : \u03b1) (xs ys zs : list \u03b1)\n\n-- combine (k+1) (x:xs) = map (x:) (combine k (x:xs)) ++ combine (k+1) xs\n-- combine 1 [x] = map (x:) (combine 0 [x]) ++ combine 1 [] = map (x:) [[]] ++ [] = [[x]]\nexample : combine 1 [x]       = [[x]]           := by simp [combine.step]\nexample : combine 1 [x, y]    = [[x], [y]]      := by simp [combine.step]\nexample : combine 1 [x, y, z] = [[x], [y], [z]] := by simp [combine.step]\nexample : combine 1 [x, y, z] = [[x], [y], [z]] := by iterate 3 { rw combine.step, simp }\n\nexample : combine 2 [x, y] = [[x, x], [x, y], [y, y]]                     := by simp [combine.step]\nexample : combine 2 [x, y, z] = [[x,x],[x,y],[x,z],[y,y],[y,z],[z,z]]     := by simp [combine.step]\nexample : combine 3 [x, y] = [[x, x, x], [x, x, y], [x, y, y], [y, y, y]] := by simp [combine.step]\nend vars\n-- [combine, choose] :: Int -> [a] -> [[a]]\n-- [combine, choose] 0 _  = [[]]\n-- [combine, choose] k [] = []\n\n-- combine (k+1) (x:xs) = map (x:) (combine k (x:xs)) ++ combine (k+1) xs\n-- choose  (k+1) (x:xs) = map (x:) (choose  k    xs ) ++ choose  (k+1) xs\n\n-- axiom combine.step (k : \u2115) (x : \u03b1) (xs : list \u03b1) :\n--   combine (k+1) (x::xs) = map (\u03bb ys, x::ys) (combine k (x::xs)) ++ combine (k+1) xs\n\n-- this two axioms may have contradiction ???\n-- axiom choose.zero (xs : list \u03b1) : choose 0 xs = [[]]\n-- axiom choose.empty (k : \u2115) : choose k [] = [] \n\naxiom choose.zero (xs : list \u03b1) : choose 0 xs = [[]]\naxiom choose.empty (k : \u2115) : k \u2265 1 \u2192 choose k [] = []\naxiom choose.step (k : \u2115) (x : \u03b1) (xs : list \u03b1) :\n  choose (k+1) (x::xs) = map (cons x) (choose k xs) ++ choose (k+1) xs\n\nattribute [simp] choose.zero choose.empty\n\nexample : choose 0 [] = [[]] := choose.zero nil\nlemma one_nil   : choose 1 [] = [] := by rw [choose.empty]; repeat { apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step }\nlemma two_nil   : choose 2 [] = [] := by rw [choose.empty]; repeat { apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step }\nlemma three_nil : choose 3 [] = [] := by rw [choose.empty]; repeat { apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step }\n\nexample (x : \u03b1) : choose 0 [x] = [[]] := choose.zero [x]\nexample (x : \u03b1) : choose 1 [x] = [[x]] := by {\n  rw [ choose.step, choose.zero, choose.empty ],\n  refl,\n  exact nat.le_refl 1, -- <=> @nat.less_than_or_equal.refl 1\n}\nexample (x : \u03b1) : choose 2 [x] = [] := by {\n  simp [choose.step],\n  iterate 2 { rw choose.empty },\n  simp,\n  iterate 3 { apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step },\n}\n\n#check nat.less_than_or_equal.step\n\nnamespace vars2\nvariables (x y z w : \u03b1) (xs ys zs ws : list \u03b1)\n-- choose (k+1) (x:xs) = map (x:) (choose k xs) ++ choose (k+1) xs\n-- choose 1 [x] = map (x:) (choose 0 []) ++ choose 1 [] = map (x:) [] ++ [] = []\n\n-- choose k (x:xs) = map (x:) (choose (k-1) xs) ++ choose k xs\n-- choose 1 [x] = map (x:) (choose 0 []) ++ choose 1 [] = \nexample : choose 1 [x] = [[x]] := by {\n  simp [choose.step]; rw [choose.empty],\n  apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step,\n}\n\nexample : choose 1 [x]       = [[x]]           := by simp [choose.step, one_nil]\nexample : choose 1 [x, y]    = [[x], [y]]      := by simp [choose.step, one_nil]\nexample : choose 1 [x, y, z] = [[x], [y], [z]] := by simp [choose.step, one_nil]\n-- example : choose 1 [x, y, z] = [[x], [y]] := by iterate 3 { rw choose.step, simp }\n\n-- induction forcing method:\n-- 1. find symmetries, rules, shortest rules (requires minimum meta-rules that can generate rules), optimal path (list) of rules, \"optimal path (method)\" of calculating optimal paths(lists)...\n-- 2. create set of hypothesis\n-- 3. prove it or find a structure that simplifies task of proof in more general cases\n\n-- group of steps for forcing cool_lemma1\nexample : choose 0 [] = [[]] := by simp [choose.step]\nexample : choose 1 [x] = [[x]] := by simp [choose.step, one_nil]\nexample : choose 2 [x, y] = [[x, y]] := by simp [choose.step, one_nil, two_nil]\nexample : choose 3 [x, y, z] = [[x, y, z]] := by simp [choose.step, one_nil, two_nil, three_nil]\nlemma cool_lemma1 (n : \u2115): choose n xs = [xs] := sorry\n\nexample : choose 3 [x, y] = [] := by {\n  repeat {\n    simp [choose.step, one_nil],\n    rw [choose.empty]; repeat { apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step },\n  },\n}\n\nexample : choose 2 [x, y, z, w] = [[x,y],[x,z],[x,w],[y,z],[y,w],[z,w]] := by {\n  repeat {\n    simp [choose.step, one_nil],\n    rw [choose.empty]; repeat { apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step },\n  },\n}\n\nexample : choose 3 [x, y, z, w] = [[x,y,z],[x,y,w],[x,z,w],[y,z,w]] := by {\n  repeat {\n    simp [choose.step, one_nil],\n    rw [choose.empty]; repeat { apply nat.less_than_or_equal.refl <|> apply nat.less_than_or_equal.step },\n  },\n}\n\nend vars2", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/functional_equations/combine.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7486521245372384}}
{"text": "/-\nCopyright (c) 2020 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\nimport tactic\n\n/-!\n# Logic\n\nA Lean companion to the \"Logic\" part of the intro module.\n\nWe develop the basic theory of the five symbols\n\u2192, \u00ac, \u2227, \u2194, \u2228\n\n(in that order)\n\n# Background\n\nIt is hard to ask you difficult questions\nabout the basic theory of these logical operators,\nbecause every question can be proved by \"check all the cases\".\n\nHowever, there is this cool theorem, that says that if\na theorem in the basic theory of logical propositions can be proved\nby \"check all the cases\", then it can be proved in the Lean theorem\nprover using only the eight constructive tactics `intro`, `apply`,\n`assumption`, `exfalso`, `split`, `cases`, `have`, `left` and `right`,\nas well as one extra rule called the Law of the Excluded Middle,\nwhich in Lean is the tactic `by_cases`. Note that the tactic `finish`\nis a general \"check all the cases\" tactic, and it uses `by_cases`.\n\n## Reference\n\n* The first half of section 1 of the M40001/40009 course notes.\n\n-/\n\nnamespace xena\n\nvariables (P Q R : Prop)\n\n/- \n\n### implies\n\nSome basic practice of `intro`, `apply` and `exact`\n-/\n\n/-- Every proposition implies itself. -/\ndef id : P \u2192 P :=\nbegin\n  -- assume P is true. Call this hypotbesis hP.\n  intro hP,\n  -- then we know that P is true by hypothesis hP.\n  exact hP,\nend\n\n-- implication isn't associative!\n-- Try it when P, Q, R are all false.\nexample : (false \u2192 (false \u2192 false)) \u2194 true := by simp\nexample : ((false \u2192 false) \u2192 false) \u2194 false := by simp\n\n-- in Lean, `P \u2192 Q \u2192 R` is _defined_ to be `P \u2192 (Q \u2192 R)`\n-- Here's a proof of what I just said.\nexample : (P \u2192 Q \u2192 R) \u2194 (P \u2192 (Q \u2192 R)) :=\nbegin\n  -- \u22a2 P \u2192 Q \u2192 R \u2194 P \u2192 Q \u2192 R\n  refl\nend\n\nexample : P \u2192 Q \u2192 P :=\nbegin\n  -- remember that by definition the goal is P \u2192 (Q \u2192 P),\n  -- so it's P implies something, so let's assume \n  -- that P is true and call this hypothesis hP.\n  intro hP,\n  -- Now we have to prove that Q implies P, so let's\n  -- assume that Q is true, and let's call this hypothesis hQ\n  intro hQ,\n  -- We now have to prove that P is true.\n  -- But this is exactly our hypothesis hP.\n  exact hP,\nend\n\n/-- If we know `P`, and we also know `P \u2192 Q`, we can deduce `Q`. -/\nlemma modus_ponens : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  -- remember this means \"P implies that ((P implies Q) implies Q)\"\n  -- so let's assume P is true\n  intro hP,\n  -- and let's assume hypothesis hPQ, that P implies Q\n  intro hPQ,\n  -- now `hPQ` says `P \u2192 Q` and we're trying to prove `Q`!\n  -- So by applying the hypothesis `hPQ`, we can reduce\n  -- this puzzle to proving `P`.\n  apply hPQ,\n  -- Now we have to prove `P`. But this is just an assumption\n  exact hP, -- or `assumption`\nend\n\nlemma trans : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  intros hPQ hQR hP,\n  apply hQR,\n  apply hPQ,\n  exact hP\nend\n\n-- This one is a \"relative modus ponens\" -- in the\n-- presence of P, if Q -> R and Q then R.\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  -- Let `hPQR` be the hypothesis that `P \u2192 Q \u2192 R`. \n  intro hPQR,\n  -- We now need to prove that `(P \u2192 Q)` implies something.\n  -- So let `hPQ` be hypothesis that `P \u2192 Q`\n  intro hPQ,\n  -- We now need to prove that `P` implies something, so \n  -- let `hP` be the hypothesis that `P` is true.\n  intro hP,\n  -- We now have to prove `R`.\n  -- We know the hypothesis `hPQR : P \u2192 (Q \u2192 R)`.\n  apply hPQR,\n    -- we now have two goals, so I indent for a second\n    -- The first goal is just to prove P, and this is an assumption\n    exact hP,\n  -- The number of goals is just one again.\n  -- the remaining goal is to prove `Q`. \n  -- But recall that `hPQ` is the hypothesis that `P` implies `Q`\n  -- so by applying it,\n  apply hPQ,\n  -- we change our goal to proving `P`. And this is a hypothesis\n  exact hP,\nend\n\n/-\n\n### not\n\n`not P`, with notation `\u00ac P`, is defined to mean `P \u2192 false` in Lean,\ni.e., the proposition that P implies false. You can easily check with\na truth table that P \u2192 false and \u00ac P are equivalent, but we need to \nremember the fact that in Lean \u00ac P was *defined* to mean `P \u2192 false`\nand not any other way\n\nWe develop a basic interface.\n-/\n\ntheorem not_not_intro : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  -- we have to prove that P implies (not (not P)),\n  -- so let's assume P is true, and let's call this assumption hP\n  intro hP,\n  -- now we have to prove `not (not P)`, a.k.a. `\u00ac (\u00ac P)`, and\n  -- by definition this means we have to prove `(\u00ac P) \u2192 false`\n  -- So let's let hnP be the hypothesis that `\u00ac P` is true.\n  intro hnP,\n  -- and now we have to prove `false`!\n  -- Sometimes this can be difficult, but it's OK if you have\n  -- *contradictory hypotheses*, because with contradictory\n  -- assumptions you can prove false conclusions, and once you've\n  -- proved one false thing you've proved all false things because\n  -- you've made mathematics collapse.\n\n  -- How are we going to use hypothesis `hnP : \u00ac P`? \n\n  -- Well, what does it _mean_? It means `P \u2192 false`,\n  -- and our _goal_ is false, so why don't we apply \n  -- hypothesis hnP, which will reduce our problem\n  -- to proving `P`.\n\n  apply hnP,\n\n  -- now our goal is `P`, and this is an assumption!\n  exact hP\nend\n\ntheorem not_not_intro'' : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  apply modus_ponens,\nend\n\n-- lambda calculus proof\ntheorem not_not_intro' : P \u2192 \u00ac (\u00ac P) :=\n\u03bb hP hnP, hnP hP\n\ntheorem contra : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  intro hPQ,\n  intro hnQ,\n  intro hP, -- we take the assumptions in a some order\n  apply hnQ,\n  apply hPQ,\n  exact hP, -- and then we put them back in a different order\nend\n\n/-!\n\n### and\n\nThe hypothesis `hPaQ : P \u2227 Q` in Lean, is equivalent to\nhypotheses `hP : P` and `hQ : Q`. \n\nIf you have `hPaQ` as a hypothesis, and you want to get to\n`hP` and `hQ`, you can use the `cases` tactic.\n\nIf you have `\u22a2 P \u2227 Q` as a goal, and want to turn the goal\ninto two goals `\u22a2 P` and `\u22a2 Q`, then use the `split` tactic.\n\nNote that after `split` it's good etiquette to use braces\ne.g.\n\nexample (hP : P) (hQ : Q) : P \u2227 Q :=\nbegin\n  split,\n  { exact hP },\n  { exact hQ }\nend\n\nbut for this sort of stuff I think principled indentation\nis OK\n\n```\nexample (hP : P) (hQ : Q) : P \u2227 Q :=\nbegin\n  split,\n    exact hP,\n  exact hQ\nend\n```\n\n-/\n\ntheorem and.elim_left : P \u2227 Q \u2192 P :=\nbegin\n  intro hPaQ,\n  cases hPaQ with hP hQ,\n  exact hP,\nend\n\ntheorem and.elim_right : P \u2227 Q \u2192 Q := \u03bb hPaQ, hPaQ.2\n\ntheorem and.intro : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  intro hP,\n  intro hQ,\n  split; assumption\nend\n\n-- the \"eliminator for and\" -- if you know `P \u2227 Q` you\n-- can deduce that something implies something else\n-- with no ands\ntheorem and.elim : P \u2227 Q \u2192 (P \u2192 Q \u2192 R) \u2192 R :=\nbegin\n  intro hPaQ,\n  cases hPaQ with hP hQ,\n  intro hPQR,\n  apply hPQR; assumption\nend\n\ntheorem and.rec : (P \u2192 Q \u2192 R) \u2192 P \u2227 Q \u2192 R :=\nbegin\n  intro hPQR,\n  rintro \u27e8hP, hQ\u27e9,\n  apply hPQR; assumption\nend\n\n-- joke proof\ntheorem and.elim' : P \u2227 Q \u2192 (P \u2192 Q \u2192 R) \u2192 R :=\nbegin\n  intro hPaQ,\n  intro hPQR,\n  apply and.rec, -- anarchy\n    exact hPQR,\n  exact hPaQ,\nend\n\n\ntheorem and.symm : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  -- goal is `\u22a2 P \u2227 Q \u2192 Q \u2227 P`\n    intro h, -- `h : P \u2227 Q`\n    cases h with hP hQ, -- `hP : P` and `hQ : Q` \n    split, -- two goals now, `\u22a2 Q` and `\u22a2 P`\n    { exact hQ },\n    { exact hP }, \nend\n\n-- term mode proof\ntheorem and.symm' : P \u2227 Q \u2192 Q \u2227 P :=\n\u03bb \u27e8P, Q\u27e9, \u27e8Q, P\u27e9\n\ntheorem and.trans : (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n  rintro \u27e8hP, hQ\u27e9,\n  rintro \u27e8hQ2, hR\u27e9,\n  split; assumption\nend\n\n/-\nExtra credit\n\nRecall that the convention for the implies sign \u2192\nis that it is _right associative_, by which\nI mean that `P \u2192 Q \u2192 R` means `P \u2192 (Q \u2192 R)` by definition.\nThis does actually simplify! If `P` implies `Q \u2192 R`\nthen this means that `P` and `Q` together, imply `R`,\nso `P \u2192 Q \u2192 R` is logically equivalent to `(P \u2227 Q) \u2192 R`.\n\nWe proved that `P \u2192 Q \u2192 R` implied `(P \u2227 Q) \u2192 R`; this was `and.rec`.\nLet's go the other way.\n-/\n\nexample : ((P \u2227 Q) \u2192 R) \u2192 (P \u2192 Q \u2192 R) :=\nbegin\n  intro hPaQR,\n  intro hP, \n  intro hQ,\n  apply hPaQR,\n  split; assumption\nend\n\n\n/-!\n\n### iff\n\nThe basic theory of `iff`.\n\nIn Lean, `P \u2194 Q` is *defined to mean* `(P \u2192 Q) \u2227 (Q \u2192 P)`.\n\nIt is _not_ defined by a truth table.\n\nThis changes the way we think about things.\n-/\n\n/-- `P \u2194 P` is true for all propositions `P`. -/\ndef iff.refl : P \u2194 P :=\nbegin\n  -- By Lean's definition I need to prove (P \u2192 P) \u2227 (P \u2192 P)\n  split,\n  { -- need to prove P \u2192 P\n    apply id },\n  { -- need to prove P \u2192 P\n    apply id }\nend\n\n-- If you get stuck, there is always the \"truth table\" tactic `tauto!`\ndef iff.refl' : P \u2194 P :=\nbegin\n  tauto!, -- the \"truth table\" tactic.\nend\n\n-- refl tactic also works\ndef iff.refl'' : P \u2194 P :=\nbegin\n  refl\nend\n\n\ndef iff.symm : (P \u2194 Q) \u2192 (Q \u2194 P) :=\nbegin\n  -- assume P \u2194 Q is true. Call this hypothesis hPiQ.\n  intro hPiQ,\n  -- by definition, hPiQ means that P \u2192 Q is true and Q \u2192 P is true.\n  -- Let's call these assumptions hPQ and hQP.\n  cases hPiQ with hPQ hQP,\n  --  We want to prove Q \u2194 P\n  -- but by definition this just means (Q \u2192 P) \u2227 (P \u2192 Q)\n  -- We split this goal, and then both goals are assumptions\n  -- (one is hPQ, one is hQP)\n  split; assumption,\nend\n\ndef iff.symm' : (P \u2194 Q) \u2192 (Q \u2194 P) :=\nbegin\n  intro h,\n  -- introduction of the rewrite tactic\n  rw h,\n  -- refl automatically applied\nend\n\n-- Instead of begin/end blocks, which many mathematicians prefer,\n-- one can write proofs in the lambda calculus, with some\n-- computer scientists like better\n\ndef iff.symm'' : (P \u2194 Q) \u2192 (Q \u2194 P) :=\n\u03bb \u27e8hPQ, hQP\u27e9, \u27e8hQP, hPQ\u27e9\n\n-- That's a full proof.\n\ndef iff.comm : (P \u2194 Q) \u2194 (Q \u2194 P) :=\nbegin\n  split;\n  apply iff.symm,\nend\n\n-- without rw or cc this is ugly\ndef iff.trans :  (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  rintro \u27e8hPQ, hQP\u27e9,\n  rintro \u27e8hQR, hRQ\u27e9,\n  split, -- split; cc finishes it\n    intro hP,\n    apply hQR,\n    apply hPQ,\n    exact hP,\n  intro hR,\n  apply hQP,\n  apply hRQ,\n  exact hR,\nend\n\ndef iff.trans' :  (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intro hPiQ,\n  intro hQiR,\n  rw hPiQ,\n  assumption\nend\n\ndef iff.boss : \u00ac (P \u2194 \u00ac P) :=\nbegin\n  rintro \u27e8h1, h2\u27e9,\n  have hnp : \u00ac P,\n    intro hP,\n    apply h1; assumption,\n  apply hnp,\n  apply h2,\n  exact hnp,\n\n\nend\n\n-- Now we have iff we can go back to and.\n\n/-! ### \u2194 and \u2227 -/\n\ntheorem and_comm : P \u2227 Q \u2194 Q \u2227 P :=\nbegin\n  split,\n    apply and.symm,\n  apply and.symm\nend\n\ntheorem and_comm' : P \u2227 Q \u2194 Q \u2227 P :=\n\u27e8and.symm _ _, and.symm _ _\u27e9\n\n-- \u2227 is \"right associative\" in Lean, which means\n-- that `P \u2227 Q \u2227 R` is _defined to mean_ `P \u2227 (Q \u2227 R)`.\n-- Associativity can hence be written like this:\ntheorem and_assoc : ((P \u2227 Q) \u2227 R) \u2194 (P \u2227 Q \u2227 R) :=\nbegin\n  split,\n  { rintros \u27e8\u27e8hP, hQ\u27e9, hR\u27e9,\n    exact \u27e8hP, hQ, hR\u27e9 },\n  { rintros \u27e8hP, hQ, hR\u27e9,\n    exact \u27e8\u27e8hP, hQ\u27e9, hR\u27e9 },  \nend\n\n\n\n/-!\n\n## Or\n\n`P \u2228 Q` is true when at least one of `P` and `Q` are true.\nHere is how to work with `\u2228` in Lean.\n\nIf you have a hypothesis `hPoQ : P \u2228 Q` then you \ncan break into the two cases `hP : P` and `hQ : Q` using\n`cases hPoQ with hP hQ`\n\nIf you have a _goal_ of the form `\u22a2 P \u2228 Q` then you\nneed to decide whether you're going to prove `P` or `Q`.\nIf you want to prove `P` then use the `left` tactic,\nand if you want to prove `Q` then use the `right` tactic.\n\n-/\n\n-- recall that P, Q, R are Propositions. We'll need S for this one.\nvariable (S : Prop)\n\n-- use the `left` tactic to reduce from `\u22a2 P \u2228 Q` to `\u22a2 P`\ntheorem or.intro_left : P \u2192 P \u2228 Q :=\nbegin\n  intro hP,\n  -- \u22a2 P \u2228 Q\n  left,\n  -- \u22a2 P\n  exact hP\nend\n\n-- use the `right` tactic to reduce from `\u22a2 P \u2228 Q`\ntheorem or.intro_right : Q \u2192 P \u2228 Q :=\nbegin\n  sorry,\nend\n\ntheorem or.elim : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  intro h,\n  intros hpq hqr,\n  cases h,\n  sorry, sorry\nend\n\n\ntheorem or.symm : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  intro hPoQ,\n  cases hPoQ with hP hQ,\n    right, \n    assumption,\n  left,\n  assumption\nend\n\ntheorem or.comm : P \u2228 Q \u2194 Q \u2228 P :=\nbegin\n  split,\n    apply or.symm,\n  apply or.symm\nend\n\n-- good luck!\n\ntheorem or.assoc : (P \u2228 Q) \u2228 R \u2194 P \u2228 Q \u2228 R :=\nbegin\n  split,\n    rintro (\u27e8hP | hQ\u27e9 | hR),\n    { left, assumption},\n    { right, left, assumption},\n    { right, right, assumption},\n    -- don't get lost. Hover over `rintro` to see the docs.\n  rintro (hP | hQ | hR),\n    { left, left, assumption},\n    { left, right, assumption},\n    { right, assumption},  \nend\n\ntheorem or.cases_on : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  rintro (hP | hQ),\n  cc,cc,\nend\n\n\n\ntheorem or.imp : (P \u2192 R) \u2192 (Q \u2192 S) \u2192 P \u2228 Q \u2192 R \u2228 S :=\nbegin\n  rintros hPR hQS (hP | hQ),\n    left, cc,\n  right, cc\nend\n\ntheorem or.imp_left : (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R :=\nbegin\n  rintros hPQ (hP | hR),\n    left, cc,\n    right, assumption\nend\n\ntheorem or.imp_right : (P \u2192 Q) \u2192 R \u2228 P \u2192 R \u2228 Q :=\nbegin\n  rintros hPQ (hP | hR),\n    left, cc,\n    right, cc,\nend\n\ntheorem or.left_comm : P \u2228 Q \u2228 R \u2194 Q \u2228 P \u2228 R :=\nbegin\n  rw or.comm,\n  rw or.assoc,\n  rw or.comm R,\n  -- (refl)\nend\n\ntheorem or.rec : (P \u2192 R) \u2192 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R :=\nbegin\n  rintros _ _ (_ | _);\n  cc\nend\n\ntheorem or.resolve_left : P \u2228 Q \u2192 \u00acP \u2192 Q :=\nbegin\n  rintros (hP | hQ) hnP,\n    contradiction,\n  assumption\nend\n\ntheorem or_congr : (P \u2194 R) \u2192 (Q \u2194 S) \u2192 (P \u2228 Q \u2194 R \u2228 S) :=\nbegin\n  rintros hPR hQS,\n  rw hPR,\n  rw hQS,\nend\n\ntheorem or_false : P \u2228 false \u2194 P :=\nbegin\n  simp,\nend\n\n\n/-!\n\n# Classical logic\n\n-/\n\n-- useful lemma about false\ntheorem false.elim' : false \u2192 P :=\nbegin\n  -- Let's assume that a false proposition is true. Let's\n  -- call this assumption h.\n  intro h,\n  -- We now have to prove P. \n  -- The `exfalso` tactic changes any goal to `false`.\n  exfalso,\n  -- Now our goal is an assumption! It's exactly `h`.\n  exact h,\nend\n\n-- This one cannot be proved using the tactics we know\n-- which are constructive. This one needs the assumption\n-- that every LEM blah \ntheorem double_negation_elimination : \u00ac (\u00ac P) \u2192 P :=\nbegin\n  -- `tauto!` works\n  classical,\n  by_cases hP : P,\n    intro h37,\n    assumption,\n  intro hnnP,\n  exfalso,\n  apply hnnP,\n  exact hP,\nend\n\n\nend xena\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/logic/solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7486521148847349}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou, Yury Kudryashov\n-/\nimport analysis.normed.group.basic\nimport algebra.indicator_function\n\n/-!\n# Indicator function and norm\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains a few simple lemmas about `set.indicator` and `norm`.\n\n## Tags\nindicator, norm\n-/\n\nvariables {\u03b1 E : Type*} [seminormed_add_comm_group E] {s t : set \u03b1} (f : \u03b1 \u2192 E) (a : \u03b1)\n\nopen set\n\nlemma norm_indicator_eq_indicator_norm :\n  \u2016indicator s f a\u2016 = indicator s (\u03bba, \u2016f a\u2016) a :=\nflip congr_fun a (indicator_comp_of_zero norm_zero).symm\n\nlemma nnnorm_indicator_eq_indicator_nnnorm :\n  \u2016indicator s f a\u2016\u208a = indicator s (\u03bba, \u2016f a\u2016\u208a) a :=\nflip congr_fun a (indicator_comp_of_zero nnnorm_zero).symm\n\nlemma norm_indicator_le_of_subset (h : s \u2286 t) (f : \u03b1 \u2192 E) (a : \u03b1) :\n  \u2016indicator s f a\u2016 \u2264 \u2016indicator t f a\u2016 :=\nbegin\n  simp only [norm_indicator_eq_indicator_norm],\n  exact indicator_le_indicator_of_subset \u2039_\u203a (\u03bb _, norm_nonneg _) _\nend\n\nlemma indicator_norm_le_norm_self : indicator s (\u03bba, \u2016f a\u2016) a \u2264 \u2016f a\u2016 :=\nindicator_le_self' (\u03bb _ _, norm_nonneg _) a\n\nlemma norm_indicator_le_norm_self : \u2016indicator s f a\u2016 \u2264 \u2016f a\u2016 :=\nby { rw norm_indicator_eq_indicator_norm, apply indicator_norm_le_norm_self }\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/indicator_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7485913856471327}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Importar la librer\u00eda de t\u00e1cticas.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n-- Nota. La m\u00f3nada opcional est\u00e1 definida por\n--    inductive option (\u03b1 : Type u)\n--    | none         : option\n--    | some (x : \u03b1) : option\n\n-- Nota. Para cada tipo `X` la funci\u00f3n `some : X \u2192 option X` es\n-- inyectiva.\n--    some_injective (\u03b1 : Type*) : function.injective (@some \u03b1)\n-- que es un corolario de\n--    some_inj {a b : \u03b1} : some a = some b \u2194 a = b\n\n-- Nota. Los elementos opcionales son distintos de none:\n--    some_ne_none (x : \u03b1) : some x \u2260 none\n\n-- Nota: Para definir una funci\u00f3n `option X \u2192 Y` hay que definir un\n-- elemento de `Y` para cada `some x` con `x : X` y tambi\u00e9n un elemento\n-- de `Y`para `none` goes. Se puede definir con el recursor de `option`,\n-- llamado `option.rec`,\n--    \u03a0 {\u03b1 : Type u} {C : option \u03b1 \u2192 Sort l},\n--      C none \u2192 (\u03a0 (val : \u03b1), C (some val)) \u2192 \u03a0 (n : option \u03b1), C n\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar X e Y como variables sobre tipos.\n-- ---------------------------------------------------------------------\n\nvariables {X Y : Type}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la funci\u00f3n\n--    g : Y \u2192 (X \u2192 Y) \u2192 (option X \u2192 Y)\n-- tal que (g y f) es la funci\u00f3n que asigna\n-- + y a none y\n-- + (f x) a (some x).\n-- ---------------------------------------------------------------------\n\ndef g : Y \u2192 (X \u2192 Y) \u2192 option X \u2192 Y :=\n\u03bb y f, \u03bb t, option.rec y f t\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar\n-- + f como una variable para funciones de X en Y.\n-- + x como una variable sobre X.\n-- + y como una variable sobre Y.\n-- ---------------------------------------------------------------------\n\nvariable (f : X \u2192 Y)\nvariable (x : X)\nvariable (y : Y)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (g y f) none\n-- ---------------------------------------------------------------------\n\nexample :\n  (g y f) none = y :=\nbegin\n  refl\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (g y f) (some x) = f x\n-- ---------------------------------------------------------------------\n\nexample :\n  (g y f) (some x) = f x :=\nbegin\n  refl\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir\n--    option_func : (X \u2192 Y) \u2192 (option X \u2192 option Y) :=\n-- tal que (option_func f) es el functor correspondiente a f.\n-- ---------------------------------------------------------------------\n\ndef option_func : (X \u2192 Y) \u2192 (option X \u2192 option Y) :=\n\u03bb f, \u03bb t, option.rec none (some \u2218 f) t\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que que option_func verifica el axioma de los\n-- functores para la identidad.\n-- ---------------------------------------------------------------------\n\nlemma option_id\n  (ox : option X)\n  : option_func id ox = ox :=\nbegin\n  cases ox with x,\n  { refl },\n  { refl }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar Z como una variable de tipos.\n-- ---------------------------------------------------------------------\n\nvariable (Z : Type)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que que option_func verifica el axioma de los\n-- functores para la composici\u00f3n\n-- ---------------------------------------------------------------------\n\nlemma option_comp\n  (f : X \u2192 Y)\n  (g : Y \u2192 Z)\n  (ox : option X) :\n  option_func (g \u2218 f) ox = (option_func g) (option_func f ox) :=\nbegin\n  cases ox with x,\n  { refl },\n  { refl },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la funci\u00f3n\n--    eta : X \u2192 option X\n-- como la funci\u00f3n some.\n-- ---------------------------------------------------------------------\n\ndef eta : X \u2192 option X :=\nsome\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la funci\u00f3n eta es una transformaci\u00f3n\n-- natural.\n-- ---------------------------------------------------------------------\n\nlemma eta_nat\n  (f : X \u2192 Y)\n  (x : X)\n  : option_func f (eta x) = eta (f x) :=\nbegin\n  refl,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la funci\u00f3n\n--    mu : option (option X) \u2192 option X\n-- que transforma `none` en `none` y `some ox` en `ox`.\n-- ---------------------------------------------------------------------\n\ndef mu : option (option X) \u2192 option X :=\n\u03bb t, option.rec none id t\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la funci\u00f3n mu es una transformaci\u00f3n\n-- natural.\n-- ---------------------------------------------------------------------\n\nlemma mu_nat (\n  f : X \u2192 Y)\n  (oox : option (option X))\n  : option_func f (mu oox) = mu (option_func (option_func f) oox) :=\nbegin\n  cases oox,\n  { refl },\n  { refl }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    mu ((option_func mu) ooox) = mu (mu ooox)\n-- ---------------------------------------------------------------------\n\nlemma coherence1\n  (ooox : option (option (option X)))\n  : mu ((option_func mu) ooox) = mu (mu ooox) :=\nbegin\n  cases ooox,\n  { refl },\n  { refl },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    mu (eta ox) = ox\n-- ---------------------------------------------------------------------\n\nlemma coherence2a\n  (ox : option X)\n  : mu (eta ox) = ox :=\nbegin\n  refl\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    mu (option_func eta ox) = ox\n-- ---------------------------------------------------------------------\n\nlemma coherence2b\n  (ox : option X)\n  : mu (option_func eta ox) = ox :=\nbegin\n  cases ox,\n  { refl },\n  { refl },\nend\n", "meta": {"author": "jaalonso", "repo": "Formalizacion_de_las_matematicas_en_Lean", "sha": "52bf9748d17a22d819cac19502fca9bc7340f7ae", "save_path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean/Formalizacion_de_las_matematicas_en_Lean-52bf9748d17a22d819cac19502fca9bc7340f7ae/src/4_Topologia/Monada_opcional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7485274798995437}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n-- 1. Importar la librer\u00eda de t\u00e1cticas.\n-- 2. Declarar \u03b1 como una variables sobre pre\u00f3rdenes.\n-- 3. Declarar a, b y c como variables sobre elementos de \u03b1.\n-- ----------------------------------------------------------------------\n\nimport tactic                       -- 1\nvariables {\u03b1 : Type*} [preorder \u03b1]  -- 2\nvariables a b c : \u03b1                 -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1. Demostrar que que la relaci\u00f3n menor es irreflexiva.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u00ac a < a :=\nbegin\n  rw lt_iff_le_not_le,\n  rintros \u27e8h1, h2\u27e9,\n  apply h2 h1,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\n_inst_1 : preorder \u03b1,\na : \u03b1\n\u22a2 \u00aca < a\n  >> rw lt_iff_le_not_le,\n\u22a2 \u00ac(a \u2264 a \u2227 \u00aca \u2264 a)\n  >> rintros \u27e8h1, h2\u27e9,\nh1 : a \u2264 a,\nh2 : \u00aca \u2264 a\n\u22a2 false\n  >> apply h2 h1,\nno goals\n-/\n\n-- Comentarios:\n-- + La t\u00e1ctica (rintros \u27e8h1, h2\u27e9), si el objetivo es de la forma \u00ac(P \u2227 Q),\n--   a\u00f1ade  las hip\u00f3tesis (h1 : P) y (h2 : Q) y cambia el objetivo a false.\n-- + Se ha usado el lema\n--      lt_iff_le_not_le : a < b \u2194 a \u2264 b \u2227 \u00acb \u2264 a\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u00ac a < a :=\nirrefl a\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que que la relaci\u00f3n menor es transitiva.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a < b \u2192 b < c \u2192 a < c :=\nbegin\n  simp only [lt_iff_le_not_le],\n  rintros \u27e8h1, h2\u27e9 \u27e8h3, h4\u27e9,\n  split,\n    apply le_trans h1 h3,\n  contrapose ! h4,\n  apply le_trans h4 h1,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\n_inst_1 : preorder \u03b1,\na b c : \u03b1\n\u22a2 a < b \u2192 b < c \u2192 a < c\n  >> simp only [lt_iff_le_not_le],\n\u22a2 a \u2264 b \u2227 \u00acb \u2264 a \u2192 b \u2264 c \u2227 \u00acc \u2264 b \u2192 a \u2264 c \u2227 \u00acc \u2264 a\n  >> rintros \u27e8h1, h2\u27e9 \u27e8h3, h4\u27e9,\nh1 : a \u2264 b,\nh2 : \u00acb \u2264 a,\nh3 : b \u2264 c,\nh4 : \u00acc \u2264 b\n\u22a2 a \u2264 c \u2227 \u00acc \u2264 a\n  >> split,\n| \u22a2 a \u2264 c\n  >>   apply le_trans h1 h3,\n\u22a2 \u00acc \u2264 a\n  >> contrapose ! h4,\nh4 : c \u2264 a\n\u22a2 c \u2264 b\n  >> apply le_trans h4 h1,\nno goals\n-/\n\n-- Comentario: Se ha aplicado los lemas\n-- + lt_iff_le_not_le : a < b \u2194 a \u2264 b \u2227 \u00acb \u2264 a\n-- + le_trans : a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a < b \u2192 b < c \u2192 a < c :=\nlt_trans\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Irreflexiva_y_transitiva_de_menor_en_preordenes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8688267864276108, "lm_q1q2_score": 0.7485274646182069}}
{"text": "import tactic\n\n-- example (n : nat) : n < n + 1 :=\n-- begin\n--   suggest,\n--   sorry\n-- end\n\nexample (n : nat) : n < n + 1 :=\nby exact lt_add_one n\n\n-- Al colocar el cursor sobre suggest muestra las siguientes sugerencias\n--    Try this: exact lt_add_one n\n--    Try this: exact nat.lt.base n\n--    Try this: exact nat.lt_succ_self n\n--    Try this: refine not_le.mp _\n--    Try this: refine gt_iff_lt.mp _\n--    Try this: refine nat.lt.step _\n--    Try this: refine set.mem_Ioi.mp _\n--    Try this: refine set.mem_Iio.mp _\n--    Try this: refine lt_of_not_ge _\n--    Try this: refine bit1_lt_bit1.mp _\n--    Try this: refine bit0_lt_bit0.mp _\n--    Try this: refine lt_of_not_ge' _\n--    Try this: refine (lt_iff_not_ge n (n + 1)).mpr _\n--    Try this: refine list.mem_range.mp _\n--    Try this: refine int.coe_nat_lt.mp _\n--    Try this: refine lt_iff_not_ge'.mpr _\n--    Try this: refine n.lt_add_left 1 n _\n--    Try this: refine nat.lt_succ_iff.mpr _\n--    Try this: refine enat.coe_lt_coe.mp _\n--    Try this: refine nat.succ_le_iff.mp _\n--    Try this: refine lt_iff_le_not_le.mpr _\n--    Try this: refine set.nonempty_Ico.mp _\n--    Try this: refine set.nonempty_Ioc.mp _\n--    Try this: refine set.left_mem_Ico.mp _\n--    Try this: refine lt_iff_le_and_ne.mpr _\n--    Try this: refine finset.mem_range.mp _\n--    Try this: refine n.lt_add_right n 1 _\n--    Try this: refine (n.psub_eq_none (n + 1)).mp _\n--    Try this: refine (nat.fact_lt _).mp _\n--    Try this: refine lt_of_le_of_ne _ _\n--    Try this: refine lt_of_le_not_le _ _\n--    Try this: refine buffer.lt_aux_1 _\n--    Try this: refine lt_of_le_of_ne' _ _\n--    Try this: refine gt.trans _ _\n--    Try this: refine lt.trans _ _\n--    Try this: refine lt_trans _ _\n--    Try this: refine gt_trans _ _\n--    Try this: refine nat.lt_trans _ _\n--    Try this: refine (lt_is_glb_iff _).mpr _\n--    Try this: refine (is_glb_lt_iff _).mpr _\n--    Try this: refine (is_lub_lt_iff _).mpr _\n--    Try this: refine (lt_is_lub_iff _).mpr _\n--    Try this: refine (pnat.mk_lt_mk n (n + 1) _ _).mp _\n--    Try this: refine gt_of_ge_of_gt _ _\n--    Try this: refine gt_of_gt_of_ge _ _\n--    Try this: refine lt_of_lt_of_le _ _\n--    Try this: refine lt_of_le_of_lt _ _\n--    Try this: refine (mul_lt_mul_left _).mp _\n--    Try this: refine forall_lt_iff_le.mpr _ _\n--    Try this: refine (mul_lt_mul_right _).mp _\n\n-- Referencia:\n-- Ver https://bit.ly/2Vkvrsu\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/La_tactica_suggest.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.748527459091005}}
{"text": "\nimport data.set\nopen set\n\n-- 1. Replace \"sorry\" in these examples.\nsection\n  variable {U : Type}\n  variables A B C : set U\n\n  example : \u2200 x, x \u2208 A \u2229 C \u2192 x \u2208 A \u222a B :=\n  assume x,\n  assume h: x \u2208 A \u2229 C,\n  show x \u2208 A \u222a B, from or.inl h.left  \n\n  example : \u2200 x, x \u2208 -(A \u222a B) \u2192 x \u2208 -A :=\n  assume x, \n  assume : x \u2208 -(A \u222a B),\n  have \u00ac x \u2208 (A \u222a B), from this,\n  assume : x \u2208 A, \n  show false, from \u2039\u00ac x \u2208 (A \u222a B)\u203a (or.inl this)\nend\n\n-- 2. Replace \"sorry\" in the last example.\nsection\n  variable {U : Type}\n\n  /- defining \"disjoint\" -/\n  def disj (A B : set U) : Prop := \u2200 \u2983x\u2984, x \u2208 A \u2192 x \u2208 B \u2192 false\n\n  example (A B : set U) (h : \u2200 x, \u00ac (x \u2208 A \u2227 x \u2208 B)) : disj A B :=\n  assume x,\n  assume h1 : x \u2208 A,\n  assume h2 : x \u2208 B,\n  have h3 : x \u2208 A \u2227 x \u2208 B, from and.intro h1 h2,\n  show false, from h x h3\n\n  -- notice that we do not have to mention x when applying\n  --   h : disj A B\n  example (A B : set U) (h1 : disj A B) (x : U) (h2 : x \u2208 A) (h3 : x \u2208 B) : false :=\n  h1 h2 h3\n\n  -- the same is true of \u2286\n  example (A B : set U) (x : U) (h : A \u2286 B) (h1 : x \u2208 A) : x \u2208 B :=\n  h h1\n\n  example (A B C D : set U) (h1 : disj A B) (h2 : C \u2286 A) (h3 : D \u2286 B) : disj C D :=\n    assume x,   \n    assume g1: x \u2208 C,\n    assume g2: x \u2208 D,\n    have g3: x \u2208 A, from h2 g1,\n    have g4: x \u2208 B, from h3 g2, \n    show false, from h1 g3 g4\nend\n\n-- 3. Prove the following facts about indexed unions and\n-- intersections, using the theorems Inter.intro, Inter.elim,\n-- Union.intro, and Union.elim listed above.\nsection\n  variables {I U : Type}\n  variables (A : I \u2192 set U) (B : I \u2192 set U) (C : set U)\n\n  def Union (A : I \u2192 set U) : set U := { x | \u2203 i : I, x \u2208 A i }\n  def Inter (A : I \u2192 set U) : set U := { x | \u2200 i : I, x \u2208 A i }\n\n    notation `\u22c3` binders `, ` r:(scoped f, Union f) := r\n    notation `\u22c2` binders `, ` r:(scoped f, Inter f) := r\n\n    theorem Inter.intro {x : U} (h : \u2200 i, x \u2208 A i) : x \u2208 \u22c2 i, A i :=\n        by simp; assumption\n\n    \n    theorem Inter.elim {x : U} (h : x \u2208 \u22c2 i, A i) (i : I) : x \u2208 A i :=\n        by simp at h; apply h\n\n    theorem Union.intro {x : U} (i : I) (h : x \u2208 A i) :\n    x \u2208 \u22c3 i, A i :=\n        by {simp, existsi i, exact h}\n\n    theorem Union.elim {b : Prop} {x : U}\n    (h\u2081 : x \u2208 \u22c3 i, A i) (h\u2082 : \u2200 (i : I), x \u2208 A i \u2192 b) : b :=\n        by {simp at h\u2081, cases h\u2081 with i h, exact h\u2082 i h}\n\n  example : (\u22c2 i, A i) \u2229 (\u22c2 i, B i) \u2286 (\u22c2 i, A i \u2229 B i) :=\n  assume x,\n        assume h: x \u2208 (\u22c2 i, A i) \u2229 (\u22c2 i, B i), \n        show x \u2208 (\u22c2 i, A i \u2229 B i), from \n            Inter.intro \n            (assume i: I,\n            have h1: x \u2208 A i, from Inter.elim h.left i,\n            have h2: x \u2208 B i, from Inter.elim h.right i,\n            show x \u2208 A i \u2229 B i, from and.intro h1 h2)\n\n  example : C \u2229 (\u22c3i, A i) \u2286 \u22c3i, C \u2229 A i :=\n  assume x : U,\n        assume h : x \u2208 C \u2229 (\u22c3i, A i),\n        show x \u2208 \u22c3 i, C \u2229 A i, from\n            Union.elim h.right \n            (assume i : I,\n            assume h1: x \u2208 A i,\n            show  x \u2208 \u22c3 i, C \u2229 A i, from \n                Union.intro i (and.intro h.left h1))\nend\n\n-- 4. Prove the following fact about power sets. You can use the\n-- theorems subset.trans and subset.refl\nsection\n  variable  {U : Type}\n  variables A B C : set U\n\n    @[refl] theorem subset.refl (a : set U) : a \u2286 a := assume x, id \n\n    @[trans] theorem subset.trans {a b c : set U} (ab : a \u2286 b) (bc : b \u2286 c) : a \u2286 c :=\n        assume x h, bc (ab h)\n  -- For this exercise these two facts are useful\n  example (h1 : A \u2286 B) (h2 : B \u2286 C) : A \u2286 C :=\n  subset.trans h1 h2\n\n  example : A \u2286 A :=\n  subset.refl A\n\n  example (h : A \u2286 B) : powerset A \u2286 powerset B :=\n   assume X : set U,\n        assume h1 : X \u2208 powerset A,\n        show X \u2208 powerset B, from subset.trans h1 h\n\n  example (h : powerset A \u2286 powerset B) : A \u2286 B :=\n  assume x: U,\n        assume h1 : x \u2208 A,\n        have h2: {y|x = y} \u2208 powerset A, from \n            assume z,\n            assume : z \u2208 {y| x = y},\n            have x = z, from this,\n            show z \u2208 A, from eq.subst this h1, \n        have h3: {y| x = y} \u2208 powerset B, from h h2, \n        have h4: x \u2208 {y| x = y}, from eq.refl x, \n        show x \u2208 B, from h3 h4\nend\n\n-- 5. Replace the sorry commands in the following proofs to show that\n-- we can create a partial order R'\u200b out of a strict partial order R.\nsection\n  parameters {A : Type} {R : A \u2192 A \u2192 Prop}\n  parameter (irreflR : irreflexive R)\n  parameter (transR : transitive R)\n\n  local infix < := R\n  variables a b c : A\n\n  def R' (a b : A) : Prop := R a b \u2228 a = b\n  local infix \u2264 := R'\n\n  theorem reflR' (a : A) : a \u2264 a :=\n  begin\n        have h1: a = a, from eq.refl a,\n        apply or.inr h1\n    end\n\n  theorem transR' {a b c : A} (h1 : a \u2264 b) (h2 : b \u2264 c): a \u2264 c :=\n    or.elim h1\n        (assume h3: a < b, or.elim h2 \n                (assume h4: b < c, or.inl (transR h3 h4))\n                (assume h4: b = c, eq.subst h4 h1))\n        (assume h3: a = b, eq.subst (eq.symm h3) h2) \n\n  theorem antisymmR' {a b : A} (h1 : a \u2264 b) (h2 : b \u2264 a) : a = b :=\n  or.elim h1 \n        (assume h: a < b, or.elim h2\n            (assume h3: b < a, false.elim ((irreflR b) (transR h3 h))) \n            (assume h3: b = a, eq.symm h3))\n        (assume h: a = b, h)\nend\n\n-- 6\nsection\n  parameters {A : Type} {R : A \u2192 A \u2192 Prop}\n  parameter (reflR : reflexive R)\n  parameter (transR : transitive R)\n\n  def S (a b : A) : Prop := R a b \u2227 R b a\n\n  example : transitive S :=\n  assume x y z,\n        assume h1 h2,\n        and.intro (transR h1.left h2.left) (transR h2.right h1.right)\nend\n\n-- 7. Only one of the following two theorems is provable. Figure out\n-- which one is true, and replace the sorry command with a complete\n-- proof.\nsection\n  parameters {A : Type} {a b c : A} {R : A \u2192 A \u2192 Prop}\n  parameter (Rab : R a b)\n  parameter (Rbc : R b c)\n  parameter (nRac : \u00ac R a c)\n\n\n  theorem R_is_not_strict_partial_order : \u00ac(irreflexive R \u2227 transitive R) :=\n  assume h: irreflexive R \u2227 transitive R, \n  show false, from nRac (h.right Rab Rbc)\nend\n\n-- 8\nsection\n  open nat\n\n  example : 1 \u2264 4 :=\n  have h1: 1 <  1 + 1, from lt_succ_self 1, \nhave h2: (1 + 1) < (1 + 1) + 1, from lt_succ_self (1 + 1),\nhave h3: (1 + 1 + 1) < (1 + 1 + 1) + 1, from lt_succ_self (1 + 1 + 1),\nhave h4: 4 = 1 + 1 + 1 + 1, by simp,\nhave h5: 1 \u2264 (1 + 1 + 1) + 1, from le_of_lt (lt_trans h1 (lt_trans h2 h3)),\neq.subst h4 h5 \nend", "meta": {"author": "Eemkayy", "repo": "discrete205", "sha": "73cd7e1973b054612363ca6cd149b183ad58a9fb", "save_path": "github-repos/lean/Eemkayy-discrete205", "path": "github-repos/lean/Eemkayy-discrete205/discrete205-73cd7e1973b054612363ca6cd149b183ad58a9fb/HW3/hw3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.748527451856817}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\n\nimport data.W.basic\n\n/-!\n# W types\n\nThe file `data/W.lean` shows that if `\u03b1` is an an encodable fintype and for every `a : \u03b1`,\n`\u03b2 a` is encodable, then `W \u03b2` is encodable.\n\nAs an example of how this can be used, we show that the type of propositional formulas with\nvariables labeled from an encodable type is encodable.\n\nThe strategy is to define a type of labels corresponding to the constructors.\nFrom the definition (using `sum`, `unit`, and an encodable type), Lean can infer\nthat it is encodable. We then define a map from propositional formulas to the\ncorresponding `Wfin` type, and show that map has a left inverse.\n\nWe mark the auxiliary constructions `private`, since their only purpose is to\nshow encodability.\n-/\n\n/-- Propositional formulas with labels from `\u03b1`. -/\ninductive prop_form (\u03b1 : Type*)\n| var : \u03b1 \u2192 prop_form\n| not : prop_form \u2192 prop_form\n| and : prop_form \u2192 prop_form \u2192 prop_form\n| or  : prop_form \u2192 prop_form \u2192 prop_form\n\n/-!\nThe next three functions make it easier to construct functions from a small\n`fin`.\n-/\n\nsection\nvariable {\u03b1 : Type*}\n\n/-- the trivial function out of `fin 0`. -/\ndef mk_fn0 : fin 0 \u2192 \u03b1\n| \u27e8_, h\u27e9 := absurd h dec_trivial\n\n/-- defines a function out of `fin 1` -/\ndef mk_fn1 (t : \u03b1) : fin 1 \u2192 \u03b1\n| \u27e80, _\u27e9   := t\n| \u27e8n+1, h\u27e9 := absurd h dec_trivial\n\n/-- defines a function out of `fin 2` -/\ndef mk_fn2 (s t : \u03b1) : fin 2 \u2192 \u03b1\n| \u27e80, _\u27e9   := s\n| \u27e81, _\u27e9   := t\n| \u27e8n+2, h\u27e9 := absurd h dec_trivial\n\nattribute [simp] mk_fn0 mk_fn1 mk_fn2\nend\n\nnamespace prop_form\n\nprivate def constructors (\u03b1 : Type*) := \u03b1 \u2295 unit \u2295 unit \u2295 unit\n\nlocal notation `cvar` a := sum.inl a\nlocal notation `cnot`   := sum.inr (sum.inl unit.star)\nlocal notation `cand`   := sum.inr (sum.inr (sum.inr unit.star))\nlocal notation `cor`    := sum.inr (sum.inr (sum.inl unit.star))\n\n@[simp]\nprivate def arity (\u03b1 : Type*) : constructors \u03b1 \u2192 nat\n| (cvar a) := 0\n| cnot     := 1\n| cand     := 2\n| cor      := 2\n\nvariable {\u03b1 : Type*}\n\nprivate def f : prop_form \u03b1 \u2192 W_type (\u03bb i, fin (arity \u03b1 i))\n| (var a)   := \u27e8cvar a, mk_fn0\u27e9\n| (not p)   := \u27e8cnot, mk_fn1 (f p)\u27e9\n| (and p q) := \u27e8cand, mk_fn2 (f p) (f q)\u27e9\n| (or  p q) := \u27e8cor, mk_fn2 (f p) (f q)\u27e9\n\nprivate def finv : W_type (\u03bb i, fin (arity \u03b1 i)) \u2192 prop_form \u03b1\n| \u27e8cvar a, fn\u27e9 := var a\n| \u27e8cnot, fn\u27e9   := not (finv (fn \u27e80, dec_trivial\u27e9))\n| \u27e8cand, fn\u27e9   := and (finv (fn \u27e80, dec_trivial\u27e9)) (finv (fn \u27e81, dec_trivial\u27e9))\n| \u27e8cor, fn\u27e9    := or  (finv (fn \u27e80, dec_trivial\u27e9)) (finv (fn \u27e81, dec_trivial\u27e9))\n\ninstance [encodable \u03b1] : encodable (prop_form \u03b1) :=\nbegin\n  haveI : encodable (constructors \u03b1),\n  { unfold constructors, apply_instance },\n  exact encodable.of_left_inverse f finv\n    (by { intro p, induction p; simp [f, finv, *] })\nend\n\nend prop_form\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/archive/examples/prop_encodable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7484690818796715}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\n\nimport topology.algebra.nonarchimedean.bases\nimport topology.algebra.uniform_filter_basis\nimport ring_theory.valuation.basic\n\n/-!\n# The topology on a valued ring\n\nIn this file, we define the non archimedean topology induced by a valuation on a ring.\nThe main definition is a `valued` type class which equips a ring with a valuation taking\nvalues in a group with zero. Other instances are then deduced from this.\n-/\n\nopen_locale classical topology uniformity\nopen set valuation\nnoncomputable theory\n\nuniverses v u\n\nvariables {R : Type u} [ring R] {\u0393\u2080 : Type v} [linear_ordered_comm_group_with_zero \u0393\u2080]\n\nnamespace valuation\n\nvariables (v : valuation R \u0393\u2080)\n\n/-- The basis of open subgroups for the topology on a ring determined by a valuation. -/\nlemma subgroups_basis :\n  ring_subgroups_basis (\u03bb \u03b3 : \u0393\u2080\u02e3, (v.lt_add_subgroup \u03b3 : add_subgroup R)) :=\n{ inter := begin\n    rintros \u03b3\u2080 \u03b3\u2081,\n    use min \u03b3\u2080 \u03b3\u2081,\n    simp [valuation.lt_add_subgroup] ; tauto\n  end,\n  mul := begin\n    rintros \u03b3,\n    cases exists_square_le \u03b3 with \u03b3\u2080 h,\n    use \u03b3\u2080,\n    rintro - \u27e8r, s, r_in, s_in, rfl\u27e9,\n    calc (v (r*s) : \u0393\u2080) = v r * v s : valuation.map_mul _ _ _\n             ... < \u03b3\u2080*\u03b3\u2080 : mul_lt_mul\u2080 r_in s_in\n             ... \u2264 \u03b3 : by exact_mod_cast h\n  end,\n  left_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use (1 : \u0393\u2080\u02e3),\n      rintros y (y_in : (v y : \u0393\u2080) < 1),\n      change v (x * y) < _,\n      rw [valuation.map_mul, Hx, zero_mul],\n      exact units.zero_lt \u03b3 },\n    { simp only [image_subset_iff, set_of_subset_set_of, preimage_set_of_eq, valuation.map_mul],\n      use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change (v (x * y) : \u0393\u2080) < \u03b3,\n      rw [valuation.map_mul, Hx, mul_comm],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end,\n  right_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use 1,\n      rintros y (y_in : (v y : \u0393\u2080) < 1),\n      change v (y * x) < _,\n      rw [valuation.map_mul, Hx, mul_zero],\n      exact units.zero_lt \u03b3 },\n    { use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change (v (y * x) : \u0393\u2080) < \u03b3,\n      rw [valuation.map_mul, Hx],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end }\n\nend valuation\n\n/-- A valued ring is a ring that comes equipped with a distinguished valuation. The class `valued`\nis designed for the situation that there is a canonical valuation on the ring.\n\nTODO: show that there always exists an equivalent valuation taking values in a type belonging to\nthe same universe as the ring.\n\nSee Note [forgetful inheritance] for why we extend `uniform_space`, `uniform_add_group`. -/\nclass valued (R : Type u) [ring R] (\u0393\u2080 : out_param (Type v))\n  [linear_ordered_comm_group_with_zero \u0393\u2080] extends uniform_space R, uniform_add_group R :=\n(v : valuation R \u0393\u2080)\n(is_topological_valuation : \u2200 s, s \u2208 \ud835\udcdd (0 : R) \u2194 \u2203 (\u03b3 : \u0393\u2080\u02e3), { x : R | v x < \u03b3 } \u2286 s)\n\n/-- The `dangerous_instance` linter does not check whether the metavariables only occur in\narguments marked with `out_param`, so in this instance it gives a false positive. -/\nattribute [nolint dangerous_instance] valued.to_uniform_space\n\nnamespace valued\n\n/-- Alternative `valued` constructor for use when there is no preferred `uniform_space`\nstructure. -/\ndef mk' (v : valuation R \u0393\u2080) : valued R \u0393\u2080 :=\n{ v := v,\n  to_uniform_space := @topological_add_group.to_uniform_space R _ v.subgroups_basis.topology _,\n  to_uniform_add_group := @topological_add_comm_group_is_uniform _ _ v.subgroups_basis.topology _,\n  is_topological_valuation :=\n  begin\n    letI := @topological_add_group.to_uniform_space R _ v.subgroups_basis.topology _,\n    intros s,\n    rw filter.has_basis_iff.mp v.subgroups_basis.has_basis_nhds_zero s,\n    exact exists_congr (\u03bb \u03b3, by simpa),\n  end }\n\nvariables (R \u0393\u2080) [_i : valued R \u0393\u2080]\ninclude _i\n\nlemma has_basis_nhds_zero :\n  (\ud835\udcdd (0 : R)).has_basis (\u03bb _, true) (\u03bb (\u03b3 : \u0393\u2080\u02e3), { x | v x < (\u03b3 : \u0393\u2080) }) :=\nby simp [filter.has_basis_iff, is_topological_valuation]\n\nlemma has_basis_uniformity :\n  (\ud835\udce4 R).has_basis (\u03bb _, true) (\u03bb (\u03b3 : \u0393\u2080\u02e3), { p : R \u00d7 R | v (p.2 - p.1) < (\u03b3 : \u0393\u2080) }) :=\nbegin\n  rw uniformity_eq_comap_nhds_zero,\n  exact (has_basis_nhds_zero R \u0393\u2080).comap _,\nend\n\nlemma to_uniform_space_eq :\n  to_uniform_space = @topological_add_group.to_uniform_space R _ v.subgroups_basis.topology _ :=\nuniform_space_eq\n  ((has_basis_uniformity R \u0393\u2080).eq_of_same_basis $ v.subgroups_basis.has_basis_nhds_zero.comap _)\n\nvariables {R \u0393\u2080}\n\nlemma mem_nhds {s : set R} {x : R} :\n  (s \u2208 \ud835\udcdd x) \u2194 \u2203 (\u03b3 : \u0393\u2080\u02e3), {y | (v (y - x) : \u0393\u2080) < \u03b3 } \u2286 s :=\nby simp only [\u2190 nhds_translation_add_neg x, \u2190 sub_eq_add_neg, preimage_set_of_eq, exists_true_left,\n  ((has_basis_nhds_zero R \u0393\u2080).comap (\u03bb y, y - x)).mem_iff]\n\nlemma mem_nhds_zero {s : set R} :\n  (s \u2208 \ud835\udcdd (0 : R)) \u2194 \u2203 \u03b3 : \u0393\u2080\u02e3, {x | v x < (\u03b3 : \u0393\u2080) } \u2286 s :=\nby simp only [mem_nhds, sub_zero]\n\nlemma loc_const {x : R} (h : (v x : \u0393\u2080) \u2260 0) : {y : R | v y = v x} \u2208 \ud835\udcdd x :=\nbegin\n  rw mem_nhds,\n  rcases units.exists_iff_ne_zero.mpr h with \u27e8\u03b3, hx\u27e9,\n  use \u03b3,\n  rw hx,\n  intros y y_in,\n  exact valuation.map_eq_of_sub_lt _ y_in\nend\n\n@[priority 100]\ninstance : topological_ring R :=\n(to_uniform_space_eq R \u0393\u2080).symm \u25b8 v.subgroups_basis.to_ring_filter_basis.is_topological_ring\n\nlemma cauchy_iff {F : filter R} :\n  cauchy F \u2194 F.ne_bot \u2227 \u2200 \u03b3 : \u0393\u2080\u02e3, \u2203 M \u2208 F, \u2200 x y \u2208 M, (v (y - x) : \u0393\u2080) < \u03b3 :=\nbegin\n  rw [to_uniform_space_eq, add_group_filter_basis.cauchy_iff],\n  apply and_congr iff.rfl,\n  simp_rw valued.v.subgroups_basis.mem_add_group_filter_basis_iff,\n  split,\n  { intros h \u03b3,\n    exact h _ (valued.v.subgroups_basis.mem_add_group_filter_basis _) },\n  { rintros h - \u27e8\u03b3, rfl\u27e9,\n    exact h \u03b3 }\nend\n\nend valued\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/valuation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7484690755588119}}
{"text": "/-\nCopyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mathieu Guay-Paquet\n-/\nimport order.ideal\n\n/-!\n# Order filters\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections\nrequire more structure, such as a bottom element, a top element, or\na join-semilattice structure.\n\n- `order.pfilter P`: The type of nonempty, downward directed, upward closed\n               subsets of `P`. This is dual to `order.ideal`, so it\n               simply wraps `order.ideal P\u1d52\u1d48`.\n- `order.is_pfilter P`: a predicate for when a `set P` is a filter.\n\n\nNote the relation between `order/filter` and `order/pfilter`: for any\ntype `\u03b1`, `filter \u03b1` represents the same mathematical object as\n`pfilter (set \u03b1)`.\n\n## References\n\n- <https://en.wikipedia.org/wiki/Filter_(mathematics)>\n\n## Tags\n\npfilter, filter, ideal, dual\n\n-/\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- A filter on a preorder `P` is a subset of `P` that is\n  - nonempty\n  - downward directed\n  - upward closed. -/\nstructure pfilter (P) [preorder P] :=\n(dual : ideal P\u1d52\u1d48)\n\n/-- A predicate for when a subset of `P` is a filter. -/\ndef is_pfilter [preorder P] (F : set P) : Prop :=\n@is_ideal P\u1d52\u1d48 _ F\n\nlemma is_pfilter.of_def [preorder P] {F : set P} (nonempty : F.nonempty)\n  (directed : directed_on (\u2265) F) (mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F) : is_pfilter F :=\n\u27e8\u03bb _ _ _ _, mem_of_le \u2039_\u203a \u2039_\u203a,  nonempty, directed\u27e9\n\n/-- Create an element of type `order.pfilter` from a set satisfying the predicate\n`order.is_pfilter`. -/\ndef is_pfilter.to_pfilter [preorder P] {F : set P} (h : is_pfilter F) : pfilter P :=\n\u27e8h.to_ideal\u27e9\n\nnamespace pfilter\n\nsection preorder\nvariables [preorder P] {x y : P} (F s t : pfilter P)\n\ninstance [inhabited P] : inhabited (pfilter P) := \u27e8\u27e8default\u27e9\u27e9\n\n/-- A filter on `P` is a subset of `P`. -/\ninstance : has_coe (pfilter P) (set P) := \u27e8\u03bb F, F.dual.carrier\u27e9\n\n/-- For the notation `x \u2208 F`. -/\ninstance : has_mem P (pfilter P) := \u27e8\u03bb x F, x \u2208 (F : set P)\u27e9\n\n@[simp] lemma mem_coe : x \u2208 (F : set P) \u2194 x \u2208 F := iff_of_eq rfl\n\nlemma is_pfilter : is_pfilter (F : set P) :=\nF.dual.is_ideal\n\nlemma nonempty : (F : set P).nonempty := F.dual.nonempty\n\nlemma directed : directed_on (\u2265) (F : set P) := F.dual.directed\n\nlemma mem_of_le {F : pfilter P} : x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F := \u03bb h, F.dual.lower h\n\n/-- Two filters are equal when their underlying sets are equal. -/\n@[ext] lemma ext (h : (s : set P) = t) : s = t :=\nby { cases s, cases t, exact congr_arg _ (ideal.ext h) }\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (pfilter P) := partial_order.lift coe ext\n\n@[trans] lemma mem_of_mem_of_le {F G : pfilter P} : x \u2208 F \u2192 F \u2264 G \u2192 x \u2208 G :=\nideal.mem_of_mem_of_le\n\n/-- The smallest filter containing a given element. -/\ndef principal (p : P) : pfilter P := \u27e8ideal.principal p\u27e9\n\n@[simp] lemma mem_def (x : P) (I : ideal P\u1d52\u1d48) :\n  x \u2208 (\u27e8I\u27e9 : pfilter P) \u2194 order_dual.to_dual x \u2208 I :=\niff.rfl\n\n@[simp] lemma principal_le_iff {F : pfilter P} : principal x \u2264 F \u2194 x \u2208 F :=\nideal.principal_le_iff\n\n@[simp] lemma mem_principal : x \u2208 principal y \u2194 y \u2264 x :=\nideal.mem_principal -- defeq abuse\n\nlemma antitone_principal : antitone (principal : P \u2192 pfilter P) := by delta antitone; simp\n\nlemma principal_le_principal_iff {p q : P} : principal q \u2264 principal p \u2194 p \u2264 q :=\nby simp\n\nend preorder\n\nsection order_top\nvariables [preorder P] [order_top P] {F : pfilter P}\n\n/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/\n@[simp] lemma top_mem : \u22a4 \u2208 F := ideal.bot_mem _\n\n/-- There is a bottom filter when `P` has a top element. -/\ninstance : order_bot (pfilter P) :=\n{ bot := \u27e8\u22a5\u27e9,\n  bot_le := \u03bb F, (bot_le : \u22a5 \u2264 F.dual) }\n\nend order_top\n\n/-- There is a top filter when `P` has a bottom element. -/\ninstance {P} [preorder P] [order_bot P] : order_top (pfilter P) :=\n{ top := \u27e8\u22a4\u27e9,\n  le_top := \u03bb F, (le_top : F.dual \u2264 \u22a4) }\n\nsection semilattice_inf\nvariables [semilattice_inf P] {x y : P} {F : pfilter P}\n\n/-- A specific witness of `pfilter.directed` when `P` has meets. -/\nlemma inf_mem (hx : x \u2208 F) (hy : y \u2208 F) : x \u2293 y \u2208 F := ideal.sup_mem hx hy\n\n@[simp] lemma inf_mem_iff : x \u2293 y \u2208 F \u2194 x \u2208 F \u2227 y \u2208 F :=\nideal.sup_mem_iff\n\nend semilattice_inf\n\nsection complete_semilattice_Inf\n\nvariables [complete_semilattice_Inf P] {F : pfilter P}\n\nlemma Inf_gc : galois_connection (\u03bb x, order_dual.to_dual (principal x))\n  (\u03bb F, Inf (order_dual.of_dual F : pfilter P)) :=\n\u03bb x F, by { simp, refl }\n\n/-- If a poset `P` admits arbitrary `Inf`s, then `principal` and `Inf` form a Galois coinsertion. -/\ndef Inf_gi : galois_coinsertion (\u03bb x, order_dual.to_dual (principal x))\n  (\u03bb F, Inf (order_dual.of_dual F : pfilter P)) :=\n{ choice := \u03bb F _, Inf (id F : pfilter P),\n  gc := Inf_gc,\n  u_l_le := \u03bb s, Inf_le $ mem_principal.2 $ le_refl s,\n  choice_eq := \u03bb _ _, rfl }\n\nend complete_semilattice_Inf\n\nend pfilter\n\nend order\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/order/pfilter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7484690733400179}}
{"text": "/-\nRequire Import List.\n\nFixpoint prefix_sum sum l :=\n  match l with\n  | nil => sum :: nil\n  | head :: tail => sum :: prefix_sum (sum + head) tail\n  end.\n\nFixpoint plus_list l1 l2 :=\n  match (l1, l2) with\n  | (nil, _) => nil\n  | (_, nil) => nil\n  | (h1 :: t1, h2 :: t2) => (h1 + h2) :: plus_list t1 t2\n  end.\n\nDefinition task :=\n  forall l1 l2,\n    prefix_sum 0 (plus_list l1 l2) =\n    plus_list (prefix_sum 0 l1) (prefix_sum 0 l2).\n-/\n\ndef prefix_sum : nat \u2192 list nat \u2192 list nat\n| sum list.nil := sum :: list.nil\n| sum (head :: tail) := sum :: prefix_sum (sum + head) tail\n\ndef plus_list : list nat \u2192 list nat \u2192 list nat\n| list.nil _ := list.nil\n| _ list.nil := list.nil\n| (h1 :: t1) (h2 :: t2) := (h1 + h2) :: plus_list t1 t2\n\nlemma nil_plus_list : \u2200 l : list nat, plus_list list.nil l = list.nil :=\nby intro l; induction l; simp [plus_list]\n\nlemma plus_list_comm : \u2200 l1 l2 :list nat, plus_list l1 l2 = plus_list l2 l1 :=\nbegin\n    intro l1, induction l1,\n        intro l2, induction l2; simp [plus_list],\n    intro l2, induction l2,\n        simp [plus_list],\n    simp [plus_list, l1_ih],\nend\n\nlemma plus_list_nil (l : list nat) : plus_list l list.nil = list.nil :=\nby simp [plus_list_comm l, nil_plus_list]\n\nlemma plus_list_prefix_sum : \u2200 h1 h2 : nat, \u2200 l1 l2 :list nat, plus_list (prefix_sum h1 l1) (prefix_sum h2 l2)\n    = prefix_sum (h1 + h2) (plus_list l1 l2) :=\nbegin\n    intros,\n    revert l2 h1 h2,\n    induction l1,\n        simp [prefix_sum, nil_plus_list],\n        intro l2, induction l2,\n            simp [prefix_sum],\n            simp [plus_list],\n            intros, trivial,\n        simp [prefix_sum],\n        simp [plus_list],\n        simp [nil_plus_list],\n        intros, trivial,\n    intro l2, induction l2,\n        simp [prefix_sum, nil_plus_list, plus_list_nil],\n        simp [plus_list, plus_list_nil],\n        intros, trivial,\n    intros,\n    simp [prefix_sum],\n    simp [plus_list, prefix_sum],\n    simp [l1_ih],\nend\n\nexample : \u2200 l1 l2 : list nat, prefix_sum 0 (plus_list l1 l2) = plus_list (prefix_sum 0 l1) (prefix_sum 0 l2) :=\nbegin\n    simp [plus_list_prefix_sum],\n    intros, trivial,\nend\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/topprover/10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7484690721277916}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n\n! This file was ported from Lean 3 source module field_theory.finiteness\n! leanprover-community/mathlib commit 6eeb941cf39066417a09b1bbc6e74761cadfcb1a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.RingTheory.Finiteness\nimport Mathbin.LinearAlgebra.Dimension\n\n/-!\n# A module over a division ring is noetherian if and only if it is finite.\n\n-/\n\n\nuniverse u v\n\nopen Classical Cardinal\n\nopen Cardinal Submodule Module Function\n\nnamespace IsNoetherian\n\nvariable {K : Type u} {V : Type v} [DivisionRing K] [AddCommGroup V] [Module K V]\n\n/-- A module over a division ring is noetherian if and only if\nits dimension (as a cardinal) is strictly less than the first infinite cardinal `\u2135\u2080`.\n-/\ntheorem iff_dim_lt_aleph0 : IsNoetherian K V \u2194 Module.rank K V < \u2135\u2080 :=\n  by\n  let b := Basis.ofVectorSpace K V\n  rw [\u2190 b.mk_eq_dim'', lt_aleph_0_iff_set_finite]\n  constructor\n  \u00b7 intro\n    exact finite_of_linearIndependent (Basis.ofVectorSpaceIndex.linearIndependent K V)\n  \u00b7 intro hbfinite\n    refine'\n      @isNoetherian_of_linearEquiv K (\u22a4 : Submodule K V) V _ _ _ _ _ (LinearEquiv.ofTop _ rfl)\n        (id _)\n    refine' isNoetherian_of_fg_of_noetherian _ \u27e8Set.Finite.toFinset hbfinite, _\u27e9\n    rw [Set.Finite.coe_toFinset, \u2190 b.span_eq, Basis.coe_ofVectorSpace, Subtype.range_coe]\n#align is_noetherian.iff_dim_lt_aleph_0 IsNoetherian.iff_dim_lt_aleph0\n\nvariable (K V)\n\n/-- The dimension of a noetherian module over a division ring, as a cardinal,\nis strictly less than the first infinite cardinal `\u2135\u2080`. -/\ntheorem dim_lt_aleph0 : \u2200 [IsNoetherian K V], Module.rank K V < \u2135\u2080 :=\n  IsNoetherian.iff_dim_lt_aleph0.1\n#align is_noetherian.dim_lt_aleph_0 IsNoetherian.dim_lt_aleph0\n\nvariable {K V}\n\n/-- In a noetherian module over a division ring, all bases are indexed by a finite type. -/\nnoncomputable def fintypeBasisIndex {\u03b9 : Type _} [IsNoetherian K V] (b : Basis \u03b9 K V) : Fintype \u03b9 :=\n  b.fintypeIndexOfDimLtAleph0 (dim_lt_aleph0 K V)\n#align is_noetherian.fintype_basis_index IsNoetherian.fintypeBasisIndex\n\n/-- In a noetherian module over a division ring,\n`basis.of_vector_space` is indexed by a finite type. -/\nnoncomputable instance [IsNoetherian K V] : Fintype (Basis.ofVectorSpaceIndex K V) :=\n  fintypeBasisIndex (Basis.ofVectorSpace K V)\n\n/-- In a noetherian module over a division ring,\nif a basis is indexed by a set, that set is finite. -/\ntheorem finite_basis_index {\u03b9 : Type _} {s : Set \u03b9} [IsNoetherian K V] (b : Basis s K V) :\n    s.Finite :=\n  b.finite_index_of_dim_lt_aleph0 (dim_lt_aleph0 K V)\n#align is_noetherian.finite_basis_index IsNoetherian.finite_basis_index\n\nvariable (K V)\n\n/-- In a noetherian module over a division ring,\nthere exists a finite basis. This is the indexing `finset`. -/\nnoncomputable def finsetBasisIndex [IsNoetherian K V] : Finset V :=\n  (finite_basis_index (Basis.ofVectorSpace K V)).toFinset\n#align is_noetherian.finset_basis_index IsNoetherian.finsetBasisIndex\n\n@[simp]\ntheorem coe_finsetBasisIndex [IsNoetherian K V] :\n    (\u2191(finsetBasisIndex K V) : Set V) = Basis.ofVectorSpaceIndex K V :=\n  Set.Finite.coe_toFinset _\n#align is_noetherian.coe_finset_basis_index IsNoetherian.coe_finsetBasisIndex\n\n@[simp]\ntheorem coeSort_finsetBasisIndex [IsNoetherian K V] :\n    (finsetBasisIndex K V : Type _) = Basis.ofVectorSpaceIndex K V :=\n  Set.Finite.coeSort_toFinset _\n#align is_noetherian.coe_sort_finset_basis_index IsNoetherian.coeSort_finsetBasisIndex\n\n/-- In a noetherian module over a division ring, there exists a finite basis.\nThis is indexed by the `finset` `finite_dimensional.finset_basis_index`.\nThis is in contrast to the result `finite_basis_index (basis.of_vector_space K V)`,\nwhich provides a set and a `set.finite`.\n-/\nnoncomputable def finsetBasis [IsNoetherian K V] : Basis (finsetBasisIndex K V) K V :=\n  (Basis.ofVectorSpace K V).reindex (by simp)\n#align is_noetherian.finset_basis IsNoetherian.finsetBasis\n\n@[simp]\ntheorem range_finsetBasis [IsNoetherian K V] :\n    Set.range (finsetBasis K V) = Basis.ofVectorSpaceIndex K V := by\n  rw [finset_basis, Basis.range_reindex, Basis.range_ofVectorSpace]\n#align is_noetherian.range_finset_basis IsNoetherian.range_finsetBasis\n\nvariable {K V}\n\n/-- A module over a division ring is noetherian if and only if it is finitely generated. -/\ntheorem iff_fg : IsNoetherian K V \u2194 Module.Finite K V :=\n  by\n  constructor\n  \u00b7 intro h\n    exact\n      \u27e8\u27e8finset_basis_index K V, by\n          convert(finset_basis K V).span_eq\n          simp\u27e9\u27e9\n  \u00b7 rintro \u27e8s, hs\u27e9\n    rw [IsNoetherian.iff_dim_lt_aleph0, \u2190 dim_top, \u2190 hs]\n    exact lt_of_le_of_lt (dim_span_le _) s.finite_to_set.lt_aleph_0\n#align is_noetherian.iff_fg IsNoetherian.iff_fg\n\nend IsNoetherian\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/FieldTheory/Finiteness.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7484690689024295}}
{"text": "import tactic\n\n/-!\n# Groups\nDefinition and basic properties of a group.\n-/\n\n-- Technical note: We work in a namespace `xena` because Lean already has groups.\nnamespace xena\n-- Now our definition of a group will really be called `xena.group`. \n\n/-\n## Definition of a group\nThe `group` class will extend `has_mul`, `has_one` and `has_inv`. \n`has_mul G` means that `G` has a multiplication `* : G \u2192 G \u2192 G`\n`has_one G` means that `G` has a `1 : G`\n`has_inv G` means that `G` has an `\u207b\u00b9 : G \u2192 G`\nAll of `*`, `1` and `\u207b\u00b9` are notation for functions -- no axioms yet.\nA `group` has all of this notation, and the group axioms too. \nLet's now define the group class.\n-/\n\n/-- A `group` structure on a type `G` is multiplication, identity and inverse,\nplus the usual axioms -/\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\n/-\nFormally, a term of type `group G` is now the following data:\na multiplication, 1, and inverse function,\nand proofs that the group axioms are satisfied.\nThe way to say \"let G be a group\" is now `(G : Type) [group G]`\nThe square bracket notation is the notation used for classes.\nFormally, it means \"put a term of type `group G` into the type class\ninference system\". In practice this just means \"you can use group\nnotation and axioms in proofs, and Lean will figure out why they're true\"\nWe have been extremely mean with our axioms. Some authors also add\nthe axioms `mul_one : \u2200 (a : G), a * 1 = a`\nand `mul_right_inv : \u2200 (a : G), a * a\u207b\u00b9 = 1`.\nBut these follow from the three axioms we used. Our first job is\nto prove them. As you might imagine, mathematically this is pretty\nmuch the trickiest part, because we have to be careful not to\naccidentally assume these axioms when we're proving them.\nHere are the four lemmas we will prove next.\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n-/\n\n-- We're proving things about groups so let's work in the `group` namespace\n-- (really this is `xena.group`)\n\nnamespace group\n\n-- let `G` be a group.\nvariables {G : Type} [group G]\n\n/-\nWe start by proving `mul_left_cancel : \u2200 a b c, a * b = a * c \u2192 b = c`.\nWe assume `Habac : a * b = a * c` and deduce `b = c`. I've written\ndown the maths proof. Your job is to supply the rewrites that are\nnecessary to justify each step. Each rewrite is either one of\nthe axioms of a group, or an assumption. A reminder of the axioms:\n`mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c)`\n`one_mul : \u2200 (a : G), 1 * a = a`\n`mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1`\nThis proof could be done using rewrites, but I will take this opportunity\nto introduce the `calc` tactic.\n-/\nlemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c := \nbegin\n calc b = 1 * b         : by rw one_mul\n    ... = (a\u207b\u00b9 * a) * b : by sorry -- replace `sorry` with `rw X` as appropriate\n    ... = a\u207b\u00b9 * (a * b) : by sorry\n    ... = a\u207b\u00b9 * (a * c) : by sorry\n    ... = (a\u207b\u00b9 * a) * c : by sorry\n    ... = 1 * c         : by sorry\n    ... = c             : by sorry\nend\n\n/-\nNext we prove that if `x = a\u207b\u00b9 * y` then `a * x = y`. Remember we are still\nmissing `mul_one` and `mul_right_inv`. A proof that avoids them is\nthe following: we want `a * x = y`. Now `apply`ing the previous lemma, it\nsuffices to prove that `a\u207b\u00b9 * (a * x) = a\u207b\u00b9 * y.`\nNow use associativity and left cancellation on on the left, to reduce\nto `h`. \nNote that `mul_left_cancel` is a function, and its first input is \ncalled `a`, but you had better give it `a\u207b\u00b9` instead.  \n-/\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9, \n  sorry\nend\n\n-- It's a bore to keep introducing variable names.\n\n-- Let `a,b,c,x,y` be elements of `G`.\nvariables (a b c x y : G)\n\n/-\nWe can use `mul_eq_of_eq_inv_mul` to prove the two \"missing\" axioms `mul_one`\nand `mul_right_inv`, and then our lives will be much easier. Try `apply`ing it\nin the theorems below.\n-/\n\n@[simp] theorem mul_one : a * 1 = a :=\nbegin\n  sorry\nend\n\n@[simp] theorem mul_right_inv : a * a\u207b\u00b9 = 1 :=\nbegin\n  sorry\nend\n\n-- Now let's talk about what that `@[simp]` means.\n\n/-\n## Lean's simplifier\nA human sees `a * a\u207b\u00b9` in group theory, and instantly replaces it with `1`.\nWe are going to train a simple AI called `simp` to do the same thing.\nLean's simplifier `simp` is a \"term rewriting system\". This means\nthat if you teach it a bunch of theorems of the form `A = B` or\n`P \u2194 Q` (by tagging them with the `@[simp]` attribute) and then give\nit a complicated goal, like\n`example : (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1`\nthen it will try to use the `rw` tactic as much as it can, using the lemmas\nit has been taught, in an attempt to simplify the goal. If it manages\nto solve it completely, then great! If it does not, but you feel like\nit should have done, you might want to tag more lemmas with `@[simp]`.\n`simp` should only be used to completely close goals. We are now\ngoing to train the simplifier to solve the example above (indeed, we are\ngoing to train it to reduce an arbitrary element of a free group into\na unique normal form, so it will solve any equalities which are true\nfor all groups, like the example above).\n## Important note\nLean's simplifier does a series of rewrites, each one replacing something\nwith something else. But the simplifier will always rewrite from left to right!\nIf you tell it that `A = B` is a `simp` lemma then it will replace `A`s with\n`B`s, but it will never replace `B`s with `A`s. If you tag a proof\nof `A = B` with `@[simp]` and you also tag a proof of `B = A` with\n`@[simp]`, then the simplifier will get stuck in an infinite loop when\nit runs into an `A`! Equality should not be thought of as symmetric here.\nBecause the simplifier works from left to right, an important\nrule of thumb is that if `A = B` is a `simp` lemma, then `B` should\nprobably be simpler than `A`! In particular, equality should not be\nthought of as symmetric here. It is not a coincidence that in\nthe theorems below\n`@[simp] theorem mul_one (a : G) : a * 1 = a`\n`@[simp] theorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\nthe right hand side is simpler than the left hand side. It would be a\n> disaster to tag `a = a * 1` with the `@[simp]` tag -- can you see why?\nLet's train Lean's simplifier! Let's teach it the axioms of a `group` next.\nWe have already done the axioms, so we have to retrospectively tag\nthem with the `@[simp]` attribute.\n-/\n\nattribute [simp] one_mul mul_left_inv mul_assoc\n\n/-\nNow let's teach the simplifier the following five lemmas:\n`inv_mul_cancel_left : a\u207b\u00b9 * (a * b) = b`\n`mul_inv_cancel_left : a * (a\u207b\u00b9 * b) = b`\n`inv_mul : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9`\n`one_inv : (1 : G)\u207b\u00b9 = 1`\n`inv_inv : (a\u207b\u00b9)\u207b\u00b9 = a`\nNote that in each case, the right hand side is simpler\nthan the left hand side.\nTry using the simplifier in your proofs! I will do the\nfirst one for you.\n-/\n\n@[simp] lemma inv_mul_cancel_left : a\u207b\u00b9 * (a * b) = b :=\nbegin\n  rw \u2190 mul_assoc, -- the simplifier wouldn't do it that way\n                  -- so we have to do it manually\n  simp, -- simplifier takes it from here, \n        -- rewriting a\u207b\u00b9 * a to 1 and then 1 * b to b\nend\n\n@[simp] lemma mul_inv_cancel_left : a * (a\u207b\u00b9 * b) = b :=\nbegin\n  sorry\nend\n\n@[simp] lemma inv_mul : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  sorry\nend\n\n@[simp] lemma one_inv : (1 : G)\u207b\u00b9 = 1 :=\nbegin\n  sorry\nend\n\n@[simp] lemma inv_inv : a \u207b\u00b9 \u207b\u00b9 = a :=\nbegin\n  sorry\nend\n\n/-\nThe reason I choose these five lemmas in particular, is that\nterm rewriting systems are very well understood by computer\nscientists, and in particular there is something called the\nKnuth-Bendix algorithm, which, given as input the three axioms\nfor a group which we used, produces a \"confluent and noetherian\nterm rewrite system\" that transforms every term into a unique\nnormal form. The system it produces is precisely the `simp`\nlemmas which we haven proven above! See\nhttps://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group\nfor more information. I won't talk any more about the Knuth-Bendix\nalgorithm because it's really computer science, and I don't really\nunderstand it, but apparently if you apply it to polynomial rings\nthen you get Buchberger's algorithm for computing Gr\u00f6bner bases.\n-/\n\n-- Now let's try our example...\nexample : (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1 := by simp -- short for begin simp end\n\n-- The simplifier solves it!\n\n-- try your own identities. `simp` will solve them all!\n\n/-\nThis is everything I wanted to show you about groups and the simplifier today.\nYou can now either go on to subgroups in Part B, or practice your group\ntheory skills by proving the lemmas below.\n-/\n\n/-\nWe already proved `mul_eq_of_eq_inv_mul` but there are several other\nsimilar-looking, but slightly different, versions of this. Here\nis one.\n-/\n\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nbegin\n  sorry\nend\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b\u207b\u00b9 * c :=\nbegin\n  sorry\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1 :=\nbegin\n  sorry\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a \u2194 b = 1 :=\nbegin\n  sorry\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9 :=\nbegin\n  sorry\nend\n\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b :=\nbegin\n  sorry,\nend\n\nlemma unique_left_id {e : G} (h : \u2200 x : G, e * x = x) : e = 1 :=\nbegin\n  sorry\nend\n\nlemma unique_right_inv {a b : G} (h : a * b = 1) : b = a\u207b\u00b9 :=\nbegin\n  sorry\nend\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y \u2194 x = y :=\nbegin\n  split,\n  { apply mul_left_cancel },\n  { intro hxy,\n    rwa hxy }\nend\n\n-- You don't even need to go into tactic mode (begin/end) to use `calc`:\nlemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y := \ncalc x = x * 1 : by rw mul_one\n  -- missing arguments here\n  ... = y : by sorry\n\n-- `\u2194` lemmas are good simp lemmas too.\n@[simp] theorem inv_inj_iff {a b : G}: a\u207b\u00b9 = b\u207b\u00b9 \u2194 a = b :=\nbegin\n  sorry\nend   \n\ntheorem inv_eq {a b : G}: a\u207b\u00b9 = b \u2194 b\u207b\u00b9 = a :=\nbegin\n  sorry\nend  \n\nend group\n\nend xena", "meta": {"author": "jamesa9283", "repo": "LiaLeanTutor", "sha": "c7ac1400f26eb2992f5f1ee0aaafb54b74665072", "save_path": "github-repos/lean/jamesa9283-LiaLeanTutor", "path": "github-repos/lean/jamesa9283-LiaLeanTutor/LiaLeanTutor-c7ac1400f26eb2992f5f1ee0aaafb54b74665072/src/wk1/Exercises/groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7484209069271781}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world2.level3 -- hide\nnamespace mynat -- hide\n\n/- \n# Addition World\n\n## Level 4: `add_comm` (boss level)\n\n[boss battle music]\n\nLook in Theorem statements -> Addition world to see the proofs you have.\nThese should be enough.\n-/\n\n/- Lemma\nOn the set of natural numbers, addition is commutative.\nIn other words, for all natural numbers $a$ and $b$, we have\n$$ a + b = b + a. $$\n-/\nlemma add_comm (a b : mynat) : a + b = b + a :=\nbegin [nat_num_game]\n  induction b with d hd,\n  { rw zero_add,\n    rw add_zero,\n    refl\n  },\n  { rw add_succ,\n    rw hd,\n    rw succ_add,\n    refl\n  }\nend\n\n/-\n\nIf you got this far -- nice! You're nearly ready to make a choice:\nMultiplication World or Function World. But there are just a couple\nmore useful lemmas in Addition World which you should prove first.\nPress on to level 5.\n\n-/\nend mynat -- hide \n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world2/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966702001757, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7483133580020315}}
{"text": "/-\nIf P and Q are of type Prop, we think\nof P \u2192 Q as a proposition in the form\nof an implication. \n\nMoreover, as we've seen, the way that \nwe give a proof of P \u2192 Q in the logic\nof Lean is to produce a function that,\nif given a proof of P returns a proof \nof Q.\n\nOn the other hand, nothing in Lean will \nprevent our using types such as nat and\nbool as P and Q. In this case we'd say\nthat P \u2192 Q, or nat \u2192 bool, is a type: a\ntype of functions from P \u2192 Q, e.g., from\nnat to bool.\n\nEXERCISE: Give two or three examples\nof interesting functions from nat to\nbool. A program that takes any natural\nnumber as an argument and always returns\na Boolean value as a result is a value\n(a \"function\", or it would be better to\nsay, a lambda expression) of this type, \n\u2115 \u2192 bool. \n-/\n\ndef zero_nat (n : \u2115) : \u2115 := 0 -- explicit return type\n#check zero_nat\n#check zero_nat 5\n#reduce zero_nat 5\n\ndef zero_nat': \u2115 \u2192 \u2115 := \u03bb n : nat, (0 : nat)\ndef zero_nat'': \u2115 \u2192 \u2115 := \u03bb n, 0\ndef zero_nat''' := \u03bb n : nat, 0\n\n/- \nEXERCISE: define a function, one_nat that takes any natural \nnumber as an argument and always returns the natural number \n1. Write it in traditional function definition notation and\nusing lambda expressions and type inference. \n-/\n\ndef one_nat' : \u2115 \u2192 \u2115 := \u03bb n : nat, 1\n\ndef identity_nat (n : \u2115) : nat := n --explicit return type\n#check identity_nat\n#check identity_nat 5\n#reduce identity_nat 5\n\n/- \nEXERCISE: define the same function, call it identity_nat'\nand write it using a lambda expression.  \n-/\n\ndef double (n : \u2115) := 2 * n -- return type inferred\n#check double\n#check double 3\n#reduce double 3\n\ndef double' : \u2115 \u2192  \u2115 := \u03bb n , 2 * n\n\n/-\nEXERCISE: Write it using a lambda expression.\n-/\n\ndef square (n: \u2115) := n * n -- return type inferred\n#check square\n#check square 3\n#reduce square 3\n\ndef square' : \u2124 \u2192 \u2124 := \u03bb n, n * n\n\n#reduce square' (-3)\n-- #reduce square (-3) -- Nope\n\n/-\nEXERCISE: Write it using a lambda expression.\n-/\ndef isPositive (n: nat) : bool := n > 0\n\n--    if n > 0 then tt else ff\n\n#check isPositive\n#check isPositive 0\n#check isPositive 1\n#check isPositive 2\n#reduce isPositive 0\n#reduce isPositive 1\n#reduce isPositive 2\n\n/-\nEXERCISE: Write it using a lambda expression.\n-/\n\n/-\nHere's a function that returns boolean true\n(tt) if a given natural number n is greater\nthan or equal to zero and less than 2^32. It\nis given using lambda notation. Write it with\na prime on its name using ordinary function\ndefinition notation (as the functions above\nare written). \n-/\n\ndef uint32: \u2115 \u2192 bool := \n    \u03bb n, \n        if n >= 0 \u2227 n < 2^32 then tt else ff\n\n#check uint32\n\n/-\nAn equivalent function definition with\na type declaration using arrow notation, \nand an explicit lambda expression as a \nvalue.\n-/\ndef positive' : nat \u2192 bool :=\n    \u03bb n : nat, \n        (if n > 0 then tt else ff : bool)\n\n#check positive'\n#check \u03bb n : nat, (if n > 0 then tt else ff : bool)\n#check \u03bb n, (if n > 0 then tt else ff)\n#check \u03bb n, n > 0\n\n\n/-\nRead the first line as saying positive'\nis a proof of (a value of type) nat \u2192 bool.\nThere are many values of this type: they\nare all the functions taking nat arguments\nand returning bool results. The specific\nvalue that we use here to \"prove the type\"\nis the function that returns true if the\nargument is strictly greater than zero,\notherwise is returns false.\n\nRead the lambda expression as follows:\nA function that takes an argument, n, of\ntype nat, and that returns the result of\nevaluating the expression, involving n,\nafter the comma: here, true if n > 0,\nand false otherwise.\n\nHere's an equivalent expression using \ntype inference to skip declaring the\ntype of n.\n-/\n\ndef positive'' : nat \u2192 bool :=\n    \u03bb n, if n > 0 then tt else ff \n\n/-\nHere we use type inference to skip\ndeclaring the function type, while\nstill using a lambda expression for\nthe program.\n-/\n\ndef positive''' := \n    \u03bb n, if n > 0 then tt else ff \n\n#check positive'''\n#reduce positive''' 3\n#reduce positive''' 0\n\ntheorem pos_is_pos : isPositive = positive''' := rfl\n\ndef my_pow (x: nat) (y: nat) := x^y\n\n#eval my_pow 2 16\n\n/-\nEXERCISE: Give two or three examples\nof interesting functions from nat to\nnat. A program that takes any natural\nnumber as an argument and always returns\na natural as a result is a value\n(a \"function\", or it would be better to\nsay, a lambda expression) of this type, \n\u2115 \u2192 \u2115\n-/\n\n\n/-\nWe can also pass functions as arguments\nto other functions!\n-/\n\ndef compose (f: \u2115 \u2192 \u2115) (g: \u2115 \u2192 \u2115) (x: \u2115) : \u2115 :=\n  f (g x)\n\n#check compose\n#check compose square double\n#reduce compose double double 3\n#reduce compose square double 3\n#reduce square (double 3)\n\ndef do_twice (f : \u2115 \u2192 \u2115) (x: \u2115) : \u2115 := f (f x)\n#check do_twice\n#reduce do_twice square 3\n\n/-\nLet's write this as a lambda expression and \nsee what we get.\n-/\n\ndef do_twice' : (\u2115 \u2192 \u2115) \u2192 \u2115 \u2192 \u2115 := \n    \u03bb (f: \u2115 \u2192 \u2115) (x: \u2115), f (f x)\n\n/-\nAnd that's a shorthand for this!\n-/\n\ndef do_twice'' : (\u2115 \u2192 \u2115) \u2192 \u2115 \u2192 \u2115 := \n    \u03bb (f : \u2115 \u2192 \u2115),\n        \u03bb (x : \u2115), \n            f (f x)\n\ndef foo := (do_twice'' double)\n#check foo\n#eval foo 5\n\ndef sub_do_twice (f: \u2115 \u2192 \u2115) := \u03bb (x : \u2115), f (f x)\n\n#check sub_do_twice\n\ndef call_sub_do_twice := sub_do_twice (\u03bb (x: \u2115), x + 1)\n#check call_sub_do_twice\n#reduce call_sub_do_twice 2\n\n\ntheorem dt_eq_dt : do_twice = do_twice'' := rfl\n\n/-\nInception! Here we define a function that takes\nas an argument a function that takes as an argument\na function (and a natural number)\n-/\n\ndef do_twice''' (f: (\u2115 \u2192 \u2115) \u2192 \u2115 \u2192 \u2115) (x: (\u2115 \u2192 \u2115)) : (\u2115 \u2192 \u2115) := f (f x)\n\n#check do_twice'''\n#check do_twice''' do_twice\n#reduce do_twice'''\n\n/-\nUse #eval instead of #reduce because #reduce will\nhave recursion problems unless we increase our\nstack space.\n-/\n\n#eval (do_twice''' do_twice) square 2\n#eval 2^16\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm", "sha": "bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c", "save_path": "github-repos/lean/kevinsullivan-cs-dm", "path": "github-repos/lean/kevinsullivan-cs-dm/cs-dm-bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c/05_Functions/functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7482717523972352}}
{"text": "/-\nIn Lean and related proof assistants, such\nas Coq, you can obtain proofs not only by\napplying inference rules, such as eq.refl,\ndirectly, but also by using programs, called\ntactics, that automate some of the details\nof finding and applying inference rules or\nsequences of such rules.\n\nAs an example, we look at the \"rfl\" tactic,\nwhich slightly simplifies the application of\nthe eq.refl inference rule. Let's first look\nat a few uses of rfl.\n-/\n\ntheorem t1 : 2 = 1 + 1 := rfl\ntheorem t2 : tt = tt := rfl\n\n/-\nThe rfl tactics appear to be producing\nproofs of the given propositions, and that\nis indeed the case. If we #check t1 we'll\nsee that this is so. t1 is a proof of 0=0\nand in fact is exactly eq.refl 0.\n-/\n\n#check t1\n#reduce t1\n\n/-\nWhat rfl is doing is grabbing the left side\nof an equality proposition, such as 2 or tt\nin the examples here, and returning eq.refl\napplied to that value.\n-/\n\n/-\nEXERCISE: Use rfl to produce a proof, h, of\nthe proposition, \"Hello\" = \"He\" ++ \"llo\".\n\nEXERCISE: Use rfl to prove p: 3*3+4*4=5*5.\n-/\n\n/- * A brief aside about terminology *-/\n\n/-\nNote: The word \"theorem\" in mathematics is generally\nused to mean an \"important\" proposition that has been\nproved. The word lemma is used to mean a less \nimportant proposition that has been proved, often as\npart of a larger proof of a more important theorem.\nMathematicians also use the word corollary to refer\nto a proposition the proof of which follows from the\nproof of a more important theorem. You can read all\nabout the various words used to refer to things that\nhave been proved, or that are intended to be proved,\nhere: https://academia.stackexchange.com/questions/113819/is-it-acceptable-for-a-referee-to-suggest-changing-theorem-into-proposition.\nFor our purposes, we'll typically just use theorem.\n-/\n\n/-\nAs you have now seen, Lean's notion of equality\ndoes not mean exact equality of expressions. It\nmeans instead the equality the values to which \nthey \"reduce\" when you \"evaluate\" them. We can \nprove 2 = 1 + 1 using rfl (or eq.refl of course) \nbecause the \"literal expression\", 2, reduces to \nthe value 2; the function application expression, \n1 + 1 (wherein the plus function is applied to \nthe two arguments, 1 and 1) also reduces to 2;\nthose two values are the same; and so eq.refl 2\ngenerates a proof that type-checks. \n-/\n\n/- \nEXERCISE: Prove as a theorem, tthof (a silly and \nuninformative name to be sure), that 2 + 3 = 1 + 4.\n\nEXERCISE: Prove as a theorem, hpleqhl, that \"Hello \" \n++ \"Lean! is equal to \"Hello Lean!\" (these values \nare of type string in Lean and the ++ operator here \nrefers to the string concatenation function in Lean.)\n-/\n\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm", "sha": "bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c", "save_path": "github-repos/lean/kevinsullivan-cs-dm", "path": "github-repos/lean/kevinsullivan-cs-dm/cs-dm-bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c/01_Equality/05_automation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8723473713594992, "lm_q1q2_score": 0.748271751624136}}
{"text": "-- Church numerals\n\n-- Another way of doing nat.\n\n-- The church nat, ch\u2115 (happy to change the name) is a pi type\n-- and not a structure. So proofs are not done by induction!\n--import data.equiv \n--open or\n\ndef ch\u2115 := \u03a0 X : Type, (X \u2192 X) \u2192 X \u2192 X\n\ndef ch\u2115free := {m : \u03a0 X : Type, (X \u2192 X) \u2192 X \u2192 X // \u2200 (X Y : Type) (a : X \u2192 Y) (f : X \u2192 X) (x : X),\n  m (X \u2192 Y) (\u03bb g, g \u2218 f) a x = a (m X f x)}\n\nnamespace chnat\n\n-- forgetful functor\ndefinition of_chnatfree : ch\u2115free \u2192 ch\u2115 := \u03bb m, m.val \n\n-- we can go back from ch\u2115 to \u2115\ndefinition to_nat : ch\u2115 \u2192 \u2115 := \u03bb m, m \u2115 nat.succ 0 -- there is a beauty here\n-- it is almost as if the structure \u2115 were built to be fed into ch\u2115 \n-- ch\u2115 is the church encoding of \u2115.\n\n--open nat \n-- map from normal nats\nopen nat\ndef of_nat : \u2115 \u2192 ch\u2115 \n| (zero) := \u03bb X f x, x\n| (succ n) := \u03bb X f x, f (of_nat n X f x) --this works\n\ntheorem nat_of_chnat_of_nat (n : \u2115) : to_nat (of_nat n) = n := begin\n  induction n with d Hd,\n  -- n = 0 case\n  { refl },\n  -- n = d + 1\n  unfold of_nat,\n  intros,unfold to_nat,\n  unfold to_nat at Hd,\n  rw Hd,\nend \n\ndefinition of_nat' : \u2115 \u2192 ch\u2115 \n| 0 := \u03bb X f x, x\n| (n + 1) := \u03bb X f x, of_nat' n X f (f x) --a bit different\n\n-- Might need to write a different destructor for \u2115? True for n implies true for 1 + n?\n\n-- broken and I don't kow why\n\n/-\ntheorem of_nat'_is_of_nat (n : \u2115) : of_nat n = of_nat' n := \nbegin\ninduction n with d Hd,\n{ refl},\nunfold of_nat,\nunfold of_nat',\nfunext,\nrw Hd,\nconv {\n  to_rhs,\n  rw \u2190Hd,\n},\n--clear Hd,\ncases d with e,\n{ refl},\nunfold of_nat at *,\nunfold of_nat' at *,\nexact Hd, -- error is here\nend\n-/\n\n\nvariable (n : \u2115)\n#reduce (n + 1)\n\nlemma of_nat_functorial (n : \u2115) (X Y : Type) (a : X \u2192 Y) (f : X \u2192 X) (x : X) : \na (of_nat n X f x) = of_nat n (X \u2192 Y) (\u03bb g x', g (f x')) a x :=\nbegin\ninduction n with d Hd,refl,\nunfold of_nat, -- I have the wrong constructor.\nend \n\n\n\n#check of_nat_functorial\n\ntheorem of_nat_is_chnatfree (n : \u2115) : \n\u2200 (X Y : Type) (a : X \u2192 Y) (f : X \u2192 X) (x : X),\n  (of_nat n) (X \u2192 Y) (\u03bb g, g \u2218 f) a x = a ((of_nat n) X f x) := begin\n  induction n with d Hd,\n    -- base case\n    intros,refl,\n\n  -- inductive step\n  intros,unfold of_nat,\n  -- v1\n  have H1 := Hd X Y (a \u2218 f) f x,\n  -- goal : f (of_nat d X f x) = of_nat d X f (f x)\n  have H2 := Hd X Y a f (f x),\n\nadmit,\nend \n\n\n--| 0 := \u27e8\u03bb X f x, x,by intros;refl\u27e9\n--| (succ n) := \u27e8\u03bb X f x, \n--  f ((of_nat n).val X f x),\n--    by {intros,have H := (of_nat n).property X Y a h x,simp * at *, rw \u2190H,sorry}\u27e9\n--  (of_nat n).val X f $ f x,\n--    by {intros, have H := (of_nat n).property X Y a f (f x),rw \u2190H,\n--    show (of_nat n).val (X \u2192 Y) (\u03bb (g : X \u2192 Y), g \u2218 f) (a \u2218 f) x =\n--    (of_nat n).val (X \u2192 Y) (\u03bb (g : X \u2192 Y), g \u2218 f) a (f x),\n--    exact _}\u27e9\n-- can I close nat now?\n\n-- examples of chnats\ndef c0 := of_nat 0\ndef c1 := of_nat 1\ndef c2 := of_nat 2\ndef c3 := of_nat 3\n\n-- now we have some constants.\n\n-- what is zero?\nexample (X f x) : c0 X f x = x := rfl\n-- what is one?\nexample (X f x) : c1 X f x = f x := rfl\n-- what is two?\nexample (X f x) : c2 X f x = f (f x) := rfl\n-- what is three?\nexample (X f x) : c3 X f x = f (f (f x)) := rfl\n-- and so on\n\n\n\n-- that definition needs to be moved if we can't prove functoriality wrt succ\n\nexample : to_nat c3 = 3 := rfl \n\n-- exercise: define succ\ndef succ :ch\u2115 \u2192 ch\u2115 := sorry -- KB can do this one\n-- no notation\n\n--unit tests -- KB can pass these\nexample : succ c0 = c1 := sorry\nexample : succ c2 = c3 := sorry\n\nexample (n : \u2115) : of_nat (nat.succ n) = succ (of_nat n) := sorry\n\n--KB can't do this one. Is it unprovable? If so, move definition of to_nat much further down.\nexample (m : ch\u2115) : to_nat (succ m) = nat.succ (to_nat m) := sorry\n\n-- exercise : define add\ndef add : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 := sorry -- KB can do this\ninstance : has_add ch\u2115 := \u27e8add\u27e9 -- now we have + notation\n\nexample : c2 + c1 = c3 := sorry \n-- KB didn't do this one yet but feels it should be true.\nexample (m n : \u2115) : of_nat (m + n) = of_nat m + of_nat n := sorry \n\n-- exercise : define mul\ndef mul : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 := sorry -- KB can do this\ninstance : has_mul ch\u2115 := \u27e8mul\u27e9 -- incantation to give us *\n\n-- KB can do this one\nexample : c1 + c2 + c3 = c2 * c3 := sorry\n-- KB didn't try this one\nexample (m n : \u2115) : of_nat (m * n) = of_nat m * of_nat n := sorry \n\n-- exercise : define pow\ndef pow : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 := sorry -- KB can do this one\n-- instance : has_pow ch\u2115 := \u27e8pow\u27e9 -- doesn't seem to work\n\n-- KB can do this\nexample : pow c2 c3 + c1 = pow c3 c2 := sorry \n-- KB didn't try this\nexample (m n : \u2115) : nat.pow m n = pow (of_nat m) (of_nat n) := sorry \n\n-- exercise : define Ackermann\ndef ack : ch\u2115 \u2192 ch\u2115 \u2192 ch\u2115 := sorry -- KB didn't try this one\n-- Is it possible?\n\n-- if it's possible, prove it agrees with usual ackermnann\n-- example : ack m n = ack (of_nat m) (of_nat n) := sorry\n\n-- question : Is this provable? KB couldn't do this one\ntheorem add_comm (m n : ch\u2115) : m + n = n + m := sorry \n\n-- KB thinks this might be ch\u2115's free theorem\n-- KB can't prove it\ntheorem free_chnat : \u2200 (A B : Type), \u2200 f : A \u2192 B, \n\u2200 r : ch\u2115, \u2200 a : A, r (A \u2192 B) (\u03bb g,f) f a  = r (A \u2192 B) (\u03bb g,g) f a \n := sorry\n\nstructure equiv' (\u03b1 : Sort*) (\u03b2 : Sort*) :=\n(to_fun    : \u03b1 \u2192 \u03b2)\n(inv_fun   : \u03b2 \u2192 \u03b1)\n(left_inv  : \u2200 (x : \u03b1), inv_fun (to_fun x) = x)\n(right_inv : \u2200 (y : \u03b2), to_fun (inv_fun y) = y)\n\n-- is \u2115 equiv to ch\u2115 ?\n\ntheorem ij : \u2200 n : \u2115, to_nat (of_nat n) = n := begin\nintro n,\ninduction n with d Hd,refl,\nunfold of_nat,\nunfold to_nat,\nunfold to_nat at Hd,\nrw Hd,\nend\n\n-- KB can't do this one\ntheorem ji : \u2200 c : ch\u2115, of_nat (to_nat c) = c := sorry\n-- Can someone write down an uncomputable counterexample?\n\n-- so KB can't do this either\ndefinition \u2115_is_ch\u2115 : equiv' \u2115 ch\u2115 := sorry \n\n-- idle question\ntheorem is_it_true (X : Type) (f : X \u2192 X) (x : X) : f x = x := sorry\n\nend chnat\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/canonical_isomorphism/church_blog_questions_with_free_theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7482703903350678}}
{"text": "/- Even more induction! -/\n\nvariable (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n-- The reflexive transitive closure of `r` as an inductive predicate\ninductive RTC : \u03b1 \u2192 \u03b1 \u2192 Prop where\n  -- Notice how declaring `r` as a `variable` instead of as a parameter instead of declaring it\n  -- directly as a parameter of `RTC` means we don't have to write `RTC r a a` inside the\n  -- declaration of `RTC`. This also works with recursive `def`s!\n  | refl : RTC a a\n  | trans : r a b \u2192 RTC b c \u2192 RTC a c\n\n-- We have arbitrarily chosen a \"left-biased\" definition of `RTC.trans`, but can easily show the\n-- mirror version by induction on the predicate\ntheorem RTC.trans' : RTC r a b \u2192 r b c \u2192 RTC r a c := by\n  intros hab hbc\n  induction hab with\n  | refl => _\n  -- `a/b/c` in the constructor `RTC.trans` are marked as *implicit* because we didn't specify them\n  -- explicitly.\n  -- Just like in other contexts, we can use `@` to specify/match implicit parameters in `induction`.\n  | @trans a a' b haa' ha'b ih => \n\nopen Nat\n\n-- By the way, we can leave out `:= fun p1 ... => match p1, ... with` at `def`\ndef double : Nat \u2192 Nat\n  | zero   => 0\n  | succ n => succ (succ (double n))\n\ntheorem double.inj : double n = double m \u2192 n = m := by\n  intro h\n  -- Try to finish this proof. You might find that the inductive case is impossible to solve!\n  -- Do you see a different approach? If not, read on!\n  induction n with\n\n-- The issue with the above approach is that our inductive hypothesis is not sufficiently general!\n-- When we begin induction, we have already fixed (introduced) a particular `m`, but for the inductive\n-- step we need the inductive hypothesis for a *different* m.\n-- We could avoid this by carefully introducing `m` (and `h`, which depends on it) only after `induction`:\n-- ```\n-- theorem double.inj : \u2200 m, double n = double m \u2192 n = m := by\n--   induction n with\n--   | zero => intro m h; ...\n--   ...\n-- ```\n-- `induction` even allows us to apply a tactic before *each* case:\n-- ```\n-- theorem double.inj : \u2200 m, double n = double m \u2192 n = m := by\n--   induction n with\n--       intro m h\n--   | zero => ...\n--   ...\n-- ```\n-- However, it turns out that we do not have to change the theorem statement at all: if we simply say\n-- ```\n-- induction n generalizing m with\n-- ```\n-- then `induction` will automatically `revert` (yes, that's also a tactic) and re`intro`duce the variable(s)\n-- before/after induction for us! So add `generalizing m` above, see how the inductive hypothesis is\n-- affected, and then go finish that proof!\n\n\n/- Partial & dependent maps -/\n\n-- *Partial maps* are a useful data type for the semantics project and many other topics.\n-- They map *some* keys of one type to values of another type.\nabbrev Map (\u03b1 \u03b2 : Type) := \u03b1 \u2192 Option \u03b2\n-- We express partiality via the `Option` type, which either holds `some b` for `b : \u03b2`, or `none`.\n-- Ctrl+click it for the whole definition.\n\nnamespace Map\n\ndef empty : Map \u03b1 \u03b2 := fun k => none\n\n-- If we wanted a partial map for programming, we might choose a more efficient implementation such\n-- as a search tree or a hash map. If, on the other hand, we are only interested in using it in a\n-- formalization, a simple function like above is usually the simpler solution. For example, a\n-- simple typing context `\u0393` can be formalized as a partial map from variable names to their types.\n\n-- The function-based definition makes defining operations such as a map update quite easy:\n\n/-- Set the entry `k` of the map `m` to the value `v`. All other entries are unchanged. -/\ndef update [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) (k : \u03b1) (v : Option \u03b2) : Map \u03b1 \u03b2 := _\n\n-- A `scoped` notation is activated only when opening/inside the current namespace\nscoped notation:max m \"[\" k \" \u21a6 \" v \"]\" => update m k v\n\ntheorem apply_update [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) : m[k \u21a6 v] k = v := by\n\n-- hint: use function extensionality (`apply funext`)\ntheorem update_self [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) : m[k \u21a6 m k] = m := by\n\nend Map\n\n-- One interesting generalization of partial maps we can express in Lean are *dependent maps* where\n-- the *type* of the value may depend on the key:\nabbrev DepMap (\u03b1 : Type) (\u03b2 : \u03b1 \u2192 Type) := (k : \u03b1) \u2192 Option (\u03b2 k)\n\nnamespace DepMap\n\ndef empty : DepMap \u03b1 \u03b2 := fun k => none\n\n-- If we try to define `update` as above, it turns out that we run into a type error!\n-- You may want to use the \"dependent if\" `if h : p then t else e` that makes a *proof* of\n-- the condition `p` available in each branch: `h : p` in the `then` branch and `h : \u00acp` in the\n-- `else` branch. You should then be able to use rewriting (e.g. `\u25b8`) to fix the type error.\ndef update [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) (k : \u03b1) (v : Option (\u03b2 k)) : DepMap \u03b1 \u03b2 := _\n\nlocal notation:max m \"[\" k \" \u21a6 \" v \"]\" => update m k v\n\n-- This one should be as before...\ntheorem apply_update [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) : m[k \u21a6 v] k = v := by\n\n-- ...but this one is where the fun starts: try replicating the corresponding `Map` proof...\ntheorem update_self [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) : m[k \u21a6 m k] = m := by\n-- and you should end up with an unsolved goal containing a subterm of the shape `(_ : a = b) \u25b8 c`. This\n-- is the rewrite from `update`; the proof is elided as `_` by default because, as we said in week 1, Lean\n-- considers all proofs of a proposition as equal, so we really don't care what proof is displayed there.\n-- So how do we get rid of the `\u25b8`? We know it is something like a match  on `Eq.refl`; more formally,\n-- both `\u25b8` and such a match compile down to an application of `Eq`'s *recursor* (week 3).\n-- We know matches/recursors reduce (\"go away\") when applied to a matching constructor application,\n-- i.e. for `\u25b8` we have `(rfl \u25b8 c) \u2261 c`.\n-- So why didn't `simp` reduce away `(_ : a = b) \u25b8` if it works for `rfl` and all proofs are the same?\n-- Well, all proofs of a *single* proposition are the same, but `rfl` is not a proof of `a = b` unless\n-- `a` and `b` are in fact the same term! Thus the general way to get rid of `(_ : a = b) \u25b8` is to\n-- first rewrite the goal with a proof of the very equality `a = b`. After that, `simp`, or definitional\n-- equality in general, will get rid of the `\u25b8`.\n-- Now, for technical reasons we should use `rw` instead of `simp` itself to do this rewrite. The short\n-- answer as to why that is is that `simp` tries to be *too clever* in this case: it will rewrite `a = b`\n-- on both sides of the `\u25b8` individually, which usually makes it more flexible (week 4, slide pages 17 & 20),\n-- but in this case unfortunately leads to a type-incorrect proof. The \"naive\" strategy of `rw`, which will\n-- simply replace all `a` with `b` everywhere simultaneously by applying the `Eq` recursor once at the root,\n-- turns out to be the better approach in this case.\n-- Phew, that was a lot of typing (in the theoretic sense and on my keyboard). If you can't get the proof to\n-- work, don't worry about it, we will not bother you with this kind of \"esoteric\" proof again. If, on the\n-- other hand, you are interested in this kind of strong dependent typing, we may have an interesting variant\n-- of the semantics project to offer you next week!\n\nend DepMap\n\nopen List Nat\n\n/- Insertion Sort -/\n\n-- We want to implement insertion sort in Lean and show that the resulting `List` is indeed sorted.\n-- To that end, we first assume that the type `\u03b1` is of the type class `LE`, meaning that we can use\n-- the symbol `\u2264` (\\le) as notation.\n-- We also assume (notice that cool dot notation) that this relation is decidable:\nvariable [LE \u03b1] [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n\n-- First, we want to define a predicate that holds if a list is sorted.\n-- The predicate should have three constructors:\n-- The empty list `[]` and the single element list `[a]` are sorted,\n-- and we can add `a` to the front of a sorted list `b :: l`, if `a \u2264 b`.s\ninductive Sorted : List \u03b1 \u2192 Prop where \n\n-- The main ingredient to insertion sort is a function `insertInOrder` which inserts\n-- a given element `a` before the first entry `x` of a list for which `a \u2264 x` holds.\n-- Define that function by recursion on the list. Remember that `\u2264` is decidable.\ndef insertInOrder (a : \u03b1) (xs : List \u03b1) : List \u03b1 := _\n\n-- Now, see whether the function actually does what it should do.\n#eval insertInOrder 4 [1, 3, 4, 6, 7]\n#eval insertInOrder 4 [1, 2, 3]\n\n-- Defining `insertionSort` itself is now an easy recursion.\ndef insertionSort (xs : List \u03b1) : List \u03b1 := _\n\n-- Let's test the sorting algorithm next.\n#eval insertionSort [6, 2, 4, 4, 1, 3, 64]\n#eval insertionSort [1, 2, 3]\n#eval insertionSort (repeat (fun xs => xs.length :: xs) 500 [])\n\n-- Now we want to move on to actually verify that the algorithm does what it claims to do!\n-- To prove this, we don't need the relation to be transitive, but we need to assume the following property:\nvariable (antisymm : \u2200 {x y : \u03b1}, \u00ac x \u2264 y \u2192 (y \u2264 x))\n\n-- Okay, now prove the statement itself!\n-- Hints:\n--   * You might at one point have the choice to either apply induction on a list or on a witness of `Sorted`.\n--     Choose wisely.\n--   * Remember the tactic `byCases` from the fifth exercise!\n\ntheorem sorted_insertionSort (as : List \u03b1) : Sorted (insertionSort as) := _\n\n-- Here's a \"soft\" question: Have we now fully verified that `insertionSort` is a sorting algorithm?\n-- What other property would be an obvious one to verify?\n\n", "meta": {"author": "IPDSnelting", "repo": "tba-2021", "sha": "b6390e55b768423d3266969e81d19290129c5914", "save_path": "github-repos/lean/IPDSnelting-tba-2021", "path": "github-repos/lean/IPDSnelting-tba-2021/tba-2021-b6390e55b768423d3266969e81d19290129c5914/TBA/Exercises/Exercise6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7482703867864794}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.factors\n! leanprover-community/mathlib commit 008205aa645b3f194c1da47025c5f110c8406eab\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Prime\nimport Mathlib.Data.List.Prime\nimport Mathlib.Data.List.Sort\nimport Mathlib.Tactic.NthRewrite\n\n/-!\n# Prime numbers\n\nThis file deals with the factors of natural numbers.\n\n## Important declarations\n\n- `Nat.factors n`: the prime factorization of `n`\n- `Nat.factors_unique`: uniqueness of the prime factorisation\n\n-/\n\nset_option autoImplicit false\n\nopen Bool Subtype\n\nopen Nat\n\nnamespace Nat\n\nattribute [instance 0] instBEqNat\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 List \u2115\n  | 0 => []\n  | 1 => []\n  | k + 2 =>\n    let m := minFac (k + 2)\n    have : (k + 2) / m < (k + 2) := factors_lemma\n    m :: factors ((k + 2) / m)\n#align nat.factors Nat.factors\n\n@[simp]\ntheorem factors_zero : factors 0 = [] := by rw [factors]\n#align nat.factors_zero Nat.factors_zero\n\n@[simp]\ntheorem factors_one : factors 1 = [] := by rw [factors]\n#align nat.factors_one Nat.factors_one\n\ntheorem prime_of_mem_factors {n : \u2115} : \u2200 {p : \u2115}, (h : p \u2208 factors n) \u2192 Prime p := by\n  match n with\n  | 0 => simp\n  | 1 => simp\n  | k + 2 =>\n      intro p h\n      let m := minFac (k + 2)\n      have : (k + 2) / m < (k + 2) := factors_lemma\n      have h\u2081 : p = m \u2228 p \u2208 factors ((k + 2) / m) :=\n        List.mem_cons.1 (by rwa [factors] at h)\n      exact Or.casesOn h\u2081 (fun h\u2082 => h\u2082.symm \u25b8 minFac_prime (by simp)) prime_of_mem_factors\n#align nat.prime_of_mem_factors Nat.prime_of_mem_factors\n\ntheorem pos_of_mem_factors {n p : \u2115} (h : p \u2208 factors n) : 0 < p :=\n  Prime.pos (prime_of_mem_factors h)\n#align nat.pos_of_mem_factors Nat.pos_of_mem_factors\n\ntheorem prod_factors : \u2200 {n}, n \u2260 0 \u2192 List.prod (factors n) = n\n  | 0 => by simp\n  | 1 => by simp\n  | k + 2 => fun _ =>\n    let m := minFac (k + 2)\n    have : (k + 2) / m < (k + 2) := factors_lemma\n    show (factors (k + 2)).prod = (k + 2) by\n      have h\u2081 : (k + 2) / m \u2260 0 := fun h => by\n        have : (k + 2) = 0 * m := (Nat.div_eq_iff_eq_mul_left (minFac_pos _) (minFac_dvd _)).1 h\n        rw [zero_mul] at this; exact (show k + 2 \u2260 0 by simp) this\n      rw [factors, List.prod_cons, prod_factors h\u2081, Nat.mul_div_cancel' (minFac_dvd _)]\n#align nat.prod_factors Nat.prod_factors\n\ntheorem factors_prime {p : \u2115} (hp : Nat.Prime p) : p.factors = [p] := by\n  have : p = p - 2 + 2 := (tsub_eq_iff_eq_add_of_le hp.two_le).mp rfl\n  rw [this, Nat.factors]\n  simp only [Eq.symm this]\n  have : Nat.minFac p = p := (Nat.prime_def_minFac.mp hp).2\n  simp only [this, Nat.factors, Nat.div_self (Nat.Prime.pos hp)]\n#align nat.factors_prime Nat.factors_prime\n\ntheorem factors_chain {n : \u2115} :\n    \u2200 {a}, (\u2200 p, Prime p \u2192 p \u2223 n \u2192 a \u2264 p) \u2192 List.Chain (\u00b7 \u2264 \u00b7) a (factors n) := by\n  match n with\n  | 0 => simp\n  | 1 => simp\n  | k + 2 =>\n      intro a h\n      let m := minFac (k + 2)\n      have : (k + 2) / m < (k + 2) := factors_lemma\n      rw [factors]\n      refine' List.Chain.cons ((le_minFac.2 h).resolve_left (by simp)) (factors_chain _)\n      exact fun p pp d => minFac_le_of_dvd pp.two_le (d.trans <| div_dvd_of_dvd <| minFac_dvd _)\n#align nat.factors_chain Nat.factors_chain\n\ntheorem factors_chain_2 (n) : List.Chain (\u00b7 \u2264 \u00b7) 2 (factors n) :=\n  factors_chain fun _ pp _ => pp.two_le\n#align nat.factors_chain_2 Nat.factors_chain_2\n\n\n\ntheorem factors_sorted (n : \u2115) : List.Sorted (\u00b7 \u2264 \u00b7) (factors n) :=\n  List.chain'_iff_pairwise.1 (factors_chain' _)\n#align nat.factors_sorted Nat.factors_sorted\n\n/-- `factors` can be constructed inductively by extracting `minFac`, for sufficiently large `n`. -/\ntheorem factors_add_two (n : \u2115) :\n    factors (n + 2) = minFac (n + 2) :: factors ((n + 2) / minFac (n + 2)) := by rw [factors]\n#align nat.factors_add_two Nat.factors_add_two\n\n@[simp]\ntheorem factors_eq_nil (n : \u2115) : n.factors = [] \u2194 n = 0 \u2228 n = 1 := by\n  constructor <;> intro h\n  \u00b7 rcases n with (_ | _ | n)\n    \u00b7 exact Or.inl rfl\n    \u00b7 exact Or.inr rfl\n    \u00b7 rw [factors] at h\n      injection h\n  \u00b7 rcases h with (rfl | rfl)\n    \u00b7 exact factors_zero\n    \u00b7 exact factors_one\n#align nat.factors_eq_nil Nat.factors_eq_nil\n\ntheorem eq_of_perm_factors {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) (h : a.factors ~ b.factors) :\n    a = b := by simpa [prod_factors ha, prod_factors hb] using List.Perm.prod_eq h\n#align nat.eq_of_perm_factors Nat.eq_of_perm_factors\n\nsection\n\nopen List\n\ntheorem mem_factors_iff_dvd {n p : \u2115} (hn : n \u2260 0) (hp : Prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n  \u27e8fun h => prod_factors hn \u25b8 List.dvd_prod h, fun h =>\n    mem_list_primes_of_dvd_prod (prime_iff.mp hp) (fun _ h => prime_iff.mp (prime_of_mem_factors h))\n      ((prod_factors hn).symm \u25b8 h)\u27e9\n#align nat.mem_factors_iff_dvd Nat.mem_factors_iff_dvd\n\ntheorem dvd_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2223 n := by\n  rcases n.eq_zero_or_pos with (rfl | hn)\n  \u00b7 exact dvd_zero p\n  \u00b7 rwa [\u2190 mem_factors_iff_dvd hn.ne' (prime_of_mem_factors h)]\n#align nat.dvd_of_mem_factors Nat.dvd_of_mem_factors\n\ntheorem mem_factors {n p} (hn : n \u2260 0) : p \u2208 factors n \u2194 Prime p \u2227 p \u2223 n :=\n  \u27e8fun h => \u27e8prime_of_mem_factors h, dvd_of_mem_factors h\u27e9, fun \u27e8hprime, hdvd\u27e9 =>\n    (mem_factors_iff_dvd hn hprime).mpr hdvd\u27e9\n#align nat.mem_factors Nat.mem_factors\n\ntheorem le_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2264 n := by\n  rcases n.eq_zero_or_pos with (rfl | hn)\n  \u00b7 rw [factors_zero] at h\n    cases h\n  \u00b7 exact le_of_dvd hn (dvd_of_mem_factors h)\n#align nat.le_of_mem_factors Nat.le_of_mem_factors\n\n/-- **Fundamental theorem of arithmetic**-/\ntheorem factors_unique {n : \u2115} {l : List \u2115} (h\u2081 : prod l = n) (h\u2082 : \u2200 p \u2208 l, Prime p) :\n    l ~ factors n := by\n  refine' perm_of_prod_eq_prod _ _ _\n  \u00b7 rw [h\u2081]\n    refine' (prod_factors _).symm\n    rintro rfl\n    rw [prod_eq_zero_iff] at h\u2081\n    exact Prime.ne_zero (h\u2082 0 h\u2081) rfl\n  \u00b7 simp_rw [\u2190 prime_iff]\n    exact h\u2082\n  \u00b7 simp_rw [\u2190 prime_iff]\n    exact fun p => prime_of_mem_factors\n#align nat.factors_unique Nat.factors_unique\n\ntheorem Prime.factors_pow {p : \u2115} (hp : p.Prime) (n : \u2115) :\n    (p ^ n).factors = List.replicate n p := by\n  symm\n  rw [\u2190 List.replicate_perm]\n  apply Nat.factors_unique (List.prod_replicate n p)\n  intro q hq\n  rwa [eq_of_mem_replicate hq]\n#align nat.prime.factors_pow Nat.Prime.factors_pow\n\ntheorem eq_prime_pow_of_unique_prime_dvd {n p : \u2115} (hpos : n \u2260 0)\n    (h : \u2200 {d}, Nat.Prime d \u2192 d \u2223 n \u2192 d = p) : n = p ^ n.factors.length := by\n  set k := n.factors.length\n  rw [\u2190 prod_factors hpos, \u2190 prod_replicate k p,\n    eq_replicate_of_mem fun d hd => h (prime_of_mem_factors hd) (dvd_of_mem_factors hd)]\n#align nat.eq_prime_pow_of_unique_prime_dvd Nat.eq_prime_pow_of_unique_prime_dvd\n\n/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\ntheorem perm_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n    (a * b).factors ~ a.factors ++ b.factors := by\n  refine' (factors_unique _ _).symm\n  \u00b7 rw [List.prod_append, prod_factors ha, prod_factors hb]\n  \u00b7 intro p hp\n    rw [List.mem_append] at hp\n    cases' hp with hp' hp' <;> exact prime_of_mem_factors hp'\n\n#align nat.perm_factors_mul Nat.perm_factors_mul\n\n/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\ntheorem perm_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) :\n    (a * b).factors ~ a.factors ++ b.factors := by\n  rcases a.eq_zero_or_pos with (rfl | ha)\n  \u00b7 simp [(coprime_zero_left _).mp hab]\n  rcases b.eq_zero_or_pos with (rfl | hb)\n  \u00b7 simp [(coprime_zero_right _).mp hab]\n  exact perm_factors_mul ha.ne' hb.ne'\n#align nat.perm_factors_mul_of_coprime Nat.perm_factors_mul_of_coprime\n\ntheorem factors_sublist_right {n k : \u2115} (h : k \u2260 0) : n.factors <+ (n * k).factors := by\n  cases' n with hn\n  \u00b7 simp [zero_mul]\n  apply sublist_of_subperm_of_sorted _ (factors_sorted _) (factors_sorted _)\n  simp [(perm_factors_mul (Nat.succ_ne_zero _) h).subperm_left]\n  exact (sublist_append_left _ _).subperm\n#align nat.factors_sublist_right Nat.factors_sublist_right\n\ntheorem factors_sublist_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors <+ k.factors := by\n  obtain \u27e8a, rfl\u27e9 := h\n  exact factors_sublist_right (right_ne_zero_of_mul h')\n#align nat.factors_sublist_of_dvd Nat.factors_sublist_of_dvd\n\ntheorem factors_subset_right {n k : \u2115} (h : k \u2260 0) : n.factors \u2286 (n * k).factors :=\n  (factors_sublist_right h).subset\n#align nat.factors_subset_right Nat.factors_subset_right\n\ntheorem factors_subset_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors \u2286 k.factors :=\n  (factors_sublist_of_dvd h h').subset\n#align nat.factors_subset_of_dvd Nat.factors_subset_of_dvd\n\ntheorem dvd_of_factors_subperm {a b : \u2115} (ha : a \u2260 0) (h : a.factors <+~ b.factors) : a \u2223 b := by\n  rcases b.eq_zero_or_pos with (rfl | hb)\n  \u00b7 exact dvd_zero _\n  rcases a with (_ | _ | a)\n  \u00b7 exact (ha rfl).elim\n  \u00b7 exact one_dvd _\n  --Porting note: previous proof\n  --use (b.factors.diff a.succ.succ.factors).prod\n  use (@List.diff _ instBEq b.factors a.succ.succ.factors).prod\n  nth_rw 1 [\u2190 Nat.prod_factors ha]\n  rw [\u2190 List.prod_append,\n    List.Perm.prod_eq <| List.subperm_append_diff_self_of_count_le <| List.subperm_ext_iff.mp h,\n    Nat.prod_factors hb.ne']\n#align nat.dvd_of_factors_subperm Nat.dvd_of_factors_subperm\n\nend\n\ntheorem mem_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) {p : \u2115} :\n    p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u2228 p \u2208 b.factors := by\n  rw [mem_factors (mul_ne_zero ha hb), mem_factors ha, mem_factors hb, \u2190 and_or_left]\n  simpa only [and_congr_right_iff] using Prime.dvd_mul\n#align nat.mem_factors_mul Nat.mem_factors_mul\n\n/-- The sets of factors of coprime `a` and `b` are disjoint -/\ntheorem coprime_factors_disjoint {a b : \u2115} (hab : a.coprime b) :\n    List.Disjoint a.factors b.factors := by\n  intro q hqa hqb\n  apply not_prime_one\n  rw [\u2190 eq_one_of_dvd_coprimes hab (dvd_of_mem_factors hqa) (dvd_of_mem_factors hqb)]\n  exact prime_of_mem_factors hqa\n#align nat.coprime_factors_disjoint Nat.coprime_factors_disjoint\n\ntheorem mem_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) (p : \u2115) :\n    p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u222a b.factors := by\n  rcases a.eq_zero_or_pos with (rfl | ha)\n  \u00b7 simp [(coprime_zero_left _).mp hab]\n  rcases b.eq_zero_or_pos with (rfl | hb)\n  \u00b7 simp [(coprime_zero_right _).mp hab]\n  rw [mem_factors_mul ha.ne' hb.ne', List.mem_union]\n#align nat.mem_factors_mul_of_coprime Nat.mem_factors_mul_of_coprime\n\nopen List\n\n/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/\ntheorem mem_factors_mul_left {p a b : \u2115} (hpa : p \u2208 a.factors) (hb : b \u2260 0) : p \u2208 (a * b).factors :=\n  by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  \u00b7 simp at hpa\n  apply (mem_factors_mul ha hb).2 (Or.inl hpa)\n#align nat.mem_factors_mul_left Nat.mem_factors_mul_left\n\n/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/\ntheorem mem_factors_mul_right {p a b : \u2115} (hpb : p \u2208 b.factors) (ha : a \u2260 0) :\n    p \u2208 (a * b).factors := by\n  rw [mul_comm]\n  exact mem_factors_mul_left hpb ha\n#align nat.mem_factors_mul_right Nat.mem_factors_mul_right\n\ntheorem eq_two_pow_or_exists_odd_prime_and_dvd (n : \u2115) :\n    (\u2203 k : \u2115, n = 2 ^ k) \u2228 \u2203 p, Nat.Prime p \u2227 p \u2223 n \u2227 Odd p :=\n  (eq_or_ne n 0).elim (fun hn => Or.inr \u27e83, prime_three, hn.symm \u25b8 dvd_zero 3, \u27e81, rfl\u27e9\u27e9) fun hn =>\n    or_iff_not_imp_right.mpr fun H =>\n      \u27e8n.factors.length,\n        eq_prime_pow_of_unique_prime_dvd hn fun {_} hprime hdvd =>\n          hprime.eq_two_or_odd'.resolve_right fun hodd => H \u27e8_, hprime, hdvd, hodd\u27e9\u27e9\n#align nat.eq_two_pow_or_exists_odd_prime_and_dvd Nat.eq_two_pow_or_exists_odd_prime_and_dvd\n\nend Nat\n\n-- Porting note: `assert_not_exists` is not implemented yet.\n--assert_not_exists Multiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Factors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.748253806324083}}
{"text": "-- Potencias_de_potencias_en_monoides.lean\n-- Potencias de potencias en monoides\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 9 de julio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En los [monoides](https://en.wikipedia.org/wiki/Monoid) se define la\n-- potencia con exponentes naturales. En Lean la potencia x^n se\n-- se caracteriza por los siguientes lemas:\n--    pow_zero : x^0 = 1\n--    pow_succ' : x^(succ n) = x * x^n\n--\n-- Demostrar que si M, a \u2208 M y m, n \u2208 \u2115, entonces\n--    a^(m * n) = (a^m)^n\n--\n-- Indicaci\u00f3n: Se puede usar el lema\n--    pow_add : a^(m + n) = a^m * a^n\n-- ---------------------------------------------------------------------\n\nimport algebra.group_power.basic\nopen monoid nat\n\nvariables {M : Type} [monoid M]\nvariable  a : M\nvariables (m n : \u2115)\n\n-- Para que no use la notaci\u00f3n con puntos\nset_option pp.structure_projections false\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a^(m * n) = (a^m)^n :=\nbegin\n  induction n with n HI,\n  { calc a^(m * 0)\n         = a^0             : congr_arg ((^) a) (nat.mul_zero m)\n     ... = 1               : pow_zero a\n     ... = (a^m)^0         : (pow_zero (a^m)).symm },\n  { calc a^(m * succ n)\n         = a^(m * n + m)   : congr_arg ((^) a) (nat.mul_succ m n)\n     ... = a^(m * n) * a^m : pow_add a (m * n) m\n     ... = (a^m)^n * a^m   : congr_arg (* a^m) HI\n     ... = (a^m)^(succ n)  : (pow_succ' (a^m) n).symm },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a^(m * n) = (a^m)^n :=\nbegin\n  induction n with n HI,\n  { calc a^(m * 0)\n         = a^0             : by simp only [nat.mul_zero]\n     ... = 1               : by simp only [pow_zero]\n     ... = (a^m)^0         : by simp only [pow_zero] },\n  { calc a^(m * succ n)\n         = a^(m * n + m)   : by simp only [nat.mul_succ]\n     ... = a^(m * n) * a^m : by simp only [pow_add]\n     ... = (a^m)^n * a^m   : by simp only [HI]\n     ... = (a^m)^succ n    : by simp only [pow_succ'] },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a^(m * n) = (a^m)^n :=\nbegin\n  induction n with n HI,\n  { calc a^(m * 0)\n         = a^0             : by simp [nat.mul_zero]\n     ... = 1               : by simp\n     ... = (a^m)^0         : by simp },\n  { calc a^(m * succ n)\n         = a^(m * n + m)   : by simp [nat.mul_succ]\n     ... = a^(m * n) * a^m : by simp [pow_add]\n     ... = (a^m)^n * a^m   : by simp [HI]\n     ... = (a^m)^succ n    : by simp [pow_succ'] },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a^(m * n) = (a^m)^n :=\nbegin\n  induction n with n HI,\n  { by simp [nat.mul_zero] },\n  { by simp [nat.mul_succ,\n             pow_add,\n             HI,\n             pow_succ'] },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a^(m * n) = (a^m)^n :=\nbegin\n  induction n with n HI,\n  { rw nat.mul_zero,\n    rw pow_zero,\n    rw pow_zero, },\n  { rw nat.mul_succ,\n    rw pow_add,\n    rw HI,\n    rw pow_succ', }\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a^(m * n) = (a^m)^n :=\nbegin\n  induction n with n HI,\n  { rw [nat.mul_zero, pow_zero, pow_zero] },\n  { rw [nat.mul_succ, pow_add, HI, pow_succ'] }\nend\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a^(m * n) = (a^m)^n :=\npow_mul a m n\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Potencias_de_potencias_en_monoides.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7482537967028624}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser, Jireh Loreaux\n\n! This file was ported from Lean 3 source module group_theory.subsemigroup.center\n! leanprover-community/mathlib commit a437a2499163d85d670479f69f625f461cc5fef9\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Ring.Defs\nimport Mathlib.GroupTheory.Subsemigroup.Operations\n\n/-!\n# Centers of magmas and semigroups\n\n## Main definitions\n\n* `Set.center`: the center of a magma\n* `Subsemigroup.center`: the center of a semigroup\n* `Set.addCenter`: the center of an additive magma\n* `AddSubsemigroup.center`: the center of an additive semigroup\n\nWe provide `Submonoid.center`, `AddSubmonoid.center`, `Subgroup.center`, `AddSubgroup.center`,\n`Subsemiring.center`, and `Subring.center` in other files.\n-/\n\n\nvariable {M : Type _}\n\nnamespace Set\n\nvariable (M)\n\n/-- The center of a magma. -/\n@[to_additive addCenter \" The center of an additive magma. \"]\ndef center [Mul M] : Set M :=\n  { z | \u2200 m, m * z = z * m }\n#align set.center Set.center\n#align set.add_center Set.addCenter\n\n-- porting note: The `to_additive` version used to be `mem_addCenter` without the iff\n@[to_additive mem_addCenter_iff]\ntheorem mem_center_iff [Mul M] {z : M} : z \u2208 center M \u2194 \u2200 g, g * z = z * g :=\n  Iff.rfl\n#align set.mem_center_iff Set.mem_center_iff\n#align set.mem_add_center Set.mem_addCenter_iff\n\ninstance decidableMemCenter [Mul M] [\u2200 a : M, Decidable <| \u2200 b : M, b * a = a * b] :\n    DecidablePred (\u00b7 \u2208 center M) := fun _ => decidable_of_iff' _ (mem_center_iff M)\n#align set.decidable_mem_center Set.decidableMemCenter\n\n@[to_additive (attr := simp) zero_mem_addCenter]\ntheorem one_mem_center [MulOneClass M] : (1 : M) \u2208 Set.center M := by simp [mem_center_iff]\n#align set.one_mem_center Set.one_mem_center\n#align set.zero_mem_add_center Set.zero_mem_addCenter\n\n@[simp]\ntheorem zero_mem_center [MulZeroClass M] : (0 : M) \u2208 Set.center M := by simp [mem_center_iff]\n#align set.zero_mem_center Set.zero_mem_center\n\nvariable {M}\n\n@[to_additive (attr := simp) add_mem_addCenter]\ntheorem mul_mem_center [Semigroup M] {a b : M} (ha : a \u2208 Set.center M) (hb : b \u2208 Set.center M) :\n    a * b \u2208 Set.center M := fun g => by rw [mul_assoc, \u2190 hb g, \u2190 mul_assoc, ha g, mul_assoc]\n#align set.mul_mem_center Set.mul_mem_center\n#align set.add_mem_add_center Set.add_mem_addCenter\n\n@[to_additive (attr := simp) neg_mem_addCenter]\ntheorem inv_mem_center [Group M] {a : M} (ha : a \u2208 Set.center M) :\n    a\u207b\u00b9 \u2208 Set.center M := fun g => by\n  rw [\u2190 inv_inj, mul_inv_rev, inv_inv, \u2190 ha, mul_inv_rev, inv_inv]\n#align set.inv_mem_center Set.inv_mem_center\n#align set.neg_mem_add_center Set.neg_mem_addCenter\n\n@[simp]\ntheorem add_mem_center [Distrib M] {a b : M} (ha : a \u2208 Set.center M) (hb : b \u2208 Set.center M) :\n    a + b \u2208 Set.center M := fun c => by rw [add_mul, mul_add, ha c, hb c]\n#align set.add_mem_center Set.add_mem_center\n\n@[simp]\ntheorem neg_mem_center [Ring M] {a : M} (ha : a \u2208 Set.center M) : -a \u2208 Set.center M := fun c => by\n  rw [\u2190 neg_mul_comm, ha (-c), neg_mul_comm]\n#align set.neg_mem_center Set.neg_mem_center\n\n@[to_additive subset_addCenter_add_units]\ntheorem subset_center_units [Monoid M] : ((\u2191) : M\u02e3 \u2192 M) \u207b\u00b9' center M \u2286 Set.center M\u02e3 :=\n  fun _ ha _ => Units.ext <| ha _\n#align set.subset_center_units Set.subset_center_units\n#align set.subset_add_center_add_units Set.subset_addCenter_add_units\n\ntheorem center_units_subset [GroupWithZero M] : Set.center M\u02e3 \u2286 ((\u2191) : M\u02e3 \u2192 M) \u207b\u00b9' center M :=\n  fun a ha b => by\n  obtain rfl | hb := eq_or_ne b 0\n  \u00b7 rw [zero_mul, mul_zero]\n  \u00b7 exact Units.ext_iff.mp (ha (Units.mk0 _ hb))\n#align set.center_units_subset Set.center_units_subset\n\n/-- In a group with zero, the center of the units is the preimage of the center. -/\ntheorem center_units_eq [GroupWithZero M] : Set.center M\u02e3 = ((\u2191) : M\u02e3 \u2192 M) \u207b\u00b9' center M :=\n  Subset.antisymm center_units_subset subset_center_units\n#align set.center_units_eq Set.center_units_eq\n\n@[simp]\ntheorem inv_mem_center\u2080 [GroupWithZero M] {a : M} (ha : a \u2208 Set.center M) : a\u207b\u00b9 \u2208 Set.center M := by\n  obtain rfl | ha0 := eq_or_ne a 0\n  \u00b7 rw [inv_zero]\n    exact zero_mem_center M\n  rcases IsUnit.mk0 _ ha0 with \u27e8a, rfl\u27e9\n  rw [\u2190 Units.val_inv_eq_inv_val]\n  exact center_units_subset (inv_mem_center (subset_center_units ha))\n#align set.inv_mem_center\u2080 Set.inv_mem_center\u2080\n\n@[to_additive (attr := simp) sub_mem_addCenter]\ntheorem div_mem_center [Group M] {a b : M} (ha : a \u2208 Set.center M) (hb : b \u2208 Set.center M) :\n    a / b \u2208 Set.center M := by\n  rw [div_eq_mul_inv]\n  exact mul_mem_center ha (inv_mem_center hb)\n#align set.div_mem_center Set.div_mem_center\n#align set.sub_mem_add_center Set.sub_mem_addCenter\n\n@[simp]\ntheorem div_mem_center\u2080 [GroupWithZero M] {a b : M} (ha : a \u2208 Set.center M)\n    (hb : b \u2208 Set.center M) : a / b \u2208 Set.center M := by\n  rw [div_eq_mul_inv]\n  exact mul_mem_center ha (inv_mem_center\u2080 hb)\n#align set.div_mem_center\u2080 Set.div_mem_center\u2080\n\nvariable (M)\n\n@[to_additive (attr := simp) addCenter_eq_univ]\ntheorem center_eq_univ [CommSemigroup M] : center M = Set.univ :=\n  (Subset.antisymm (subset_univ _)) fun x _ y => mul_comm y x\n#align set.center_eq_univ Set.center_eq_univ\n#align set.add_center_eq_univ Set.addCenter_eq_univ\n\nend Set\n\nnamespace Subsemigroup\n\nsection\n\nvariable (M) [Semigroup M]\n\n/-- The center of a semigroup `M` is the set of elements that commute with everything in `M` -/\n@[to_additive\n      \"The center of a semigroup `M` is the set of elements that commute with everything in `M`\"]\ndef center : Subsemigroup M where\n  carrier := Set.center M\n  mul_mem':= Set.mul_mem_center\n#align subsemigroup.center Subsemigroup.center\n#align add_subsemigroup.center AddSubsemigroup.center\n\n-- porting note: `coe_center` is now redundant\n#noalign subsemigroup.coe_center\n#noalign add_subsemigroup.coe_center\n\nvariable {M}\n\n@[to_additive]\ntheorem mem_center_iff {z : M} : z \u2208 center M \u2194 \u2200 g, g * z = z * g :=\n  Iff.rfl\n#align subsemigroup.mem_center_iff Subsemigroup.mem_center_iff\n#align add_subsemigroup.mem_center_iff AddSubsemigroup.mem_center_iff\n\n@[to_additive]\ninstance decidableMemCenter (a) [Decidable <| \u2200 b : M, b * a = a * b] : Decidable (a \u2208 center M) :=\n  decidable_of_iff' _ mem_center_iff\n#align subsemigroup.decidable_mem_center Subsemigroup.decidableMemCenter\n#align add_subsemigroup.decidable_mem_center AddSubsemigroup.decidableMemCenter\n\n/-- The center of a semigroup is commutative. -/\n@[to_additive \"The center of an additive semigroup is commutative.\"]\ninstance : CommSemigroup (center M) :=\n  { MulMemClass.toSemigroup (center M) with mul_comm := fun _ b => Subtype.ext <| b.2 _ }\n\nend\n\nsection\n\nvariable (M) [CommSemigroup M]\n\n@[to_additive (attr := simp)]\ntheorem center_eq_top : center M = \u22a4 :=\n  SetLike.coe_injective (Set.center_eq_univ M)\n#align subsemigroup.center_eq_top Subsemigroup.center_eq_top\n#align add_subsemigroup.center_eq_top AddSubsemigroup.center_eq_top\n\nend\n\nend Subsemigroup\n\n-- Guard against import creep\n-- Porting note: Not implemented yet\n-- assert_not_exists finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/Subsemigroup/Center.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.8418256452674009, "lm_q1q2_score": 0.7481799547404671}}
{"text": "import tactic\n\n/-\n\n# Prove that there exists infinitely many positive integers n such that\n# 4n\u00b2 + 1 is divisible both by 5 and 13.\n\nThis is the third question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\nmaths proof: if n=1 then 4n^2+1 is divisible by 5\nso if n=1 mod 5 then 4n^2+1 will be divisible by 5\n\nin fact if n=4 then 4n^2+1 is divisible by both 5 and 13\nso if n=4+65*t then this will work\n-/\n\nlemma divides_of_cong_four (t : \u2115) : 5 \u2223 4 * (65 * t + 4)^2 + 1 \u2227\n13 \u2223 4 * (65 * t + 4)^2 + 1 :=\nbegin\n  split,\n  { use 3380*t^2 + 416*t + 13,\n    ring },\n  { use 1300*t^2 + 160*t + 5,\n    ring }\nend\n\n\nlemma arb_large_soln : \u2200 N : \u2115, \u2203 n > N, 5 \u2223 4*n^2+1 \u2227 13 \u2223 4*n^2+1 :=\nbegin\n  intro N,\n  -- need to find t such that 65t+4>N\n  use 65 * N + 4,\n  split,\n  { linarith },\n  { apply divides_of_cong_four }  \nend\n\nlemma infinite_iff_arb_large (S : set \u2115) : S.infinite \u2194 \u2200 N, \u2203 n > N, n \u2208 S :=\nbegin\n  split,\n  { intro h,\n    have h2 := set.infinite.exists_nat_lt h,\n    intro n,\n    rcases h2 n with \u27e8m, hm, h3\u27e9,\n    use m,\n    exact \u27e8h3, hm\u27e9,\n  },\n  { contrapose!,\n    intro h,\n    rw set.not_infinite at h,\n    let S2 : finset \u2115 := set.finite.to_finset h,\n    have h2 : \u2203 B, \u2200n \u2208 S2, n \u2264 B,\n    { use finset.sup S2 id,\n      intros,\n      apply finset.le_sup H },\n    cases h2 with N hN,\n    use N,\n    have h3 : \u2200n : \u2115, n \u2208 S \u2194 n \u2208 S2,\n      intro n,\n      exact (set.finite.mem_to_finset h).symm,\n    intros n hn h4,\n    rw h3 at h4,\n    specialize hN n h4,\n    linarith,\n  }\nend\n\nexample : {n : \u2115 | 5 \u2223 4*n^2+1 \u2227 13 \u2223 4*n^2+1}.infinite :=\nbegin\n  rw infinite_iff_arb_large,\n  exact arb_large_soln,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section08numbertheory/examples/example03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7481799356142153}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function world.\n\n## Level 8: `(P \u2192 Q) \u2192 ((Q \u2192 empty) \u2192 (P \u2192 empty))`\n\nLevel 8 is the same as level 7, except we have replaced the\nset  `F` with the empty set `\u2205`. The same proof will work (after all, our\nprevious proof worked for all sets, and the empty set is a set).\nBut note that if you start with `intro f; intro h; intro p,`\n(which can incidentally be shortened to `intros f h p`,\nsee [intros tactic](../Tactics/intros.lean.md)),\nthen the local context looks like this:\n\n```\nP Q : Type,\nf : P \u2192 Q,\nh : Q \u2192 empty,\np : P\n\u22a2 empty\n```\n\nand your job is to construct an element of the empty set!\nThis on the face of it seems hard, but what is going on is that\nour hypotheses (we have an element of  `P `, and functions  `P \u2192 Q`\nand  `Q \u2192 \u2205`) are themselves contradictory, so\nI guess we are doing some kind of proof by contradiction at this point? However,\nif your next line is `apply h` then all of a sudden the goal\nseems like it might be possible again. If this is confusing, note\nthat the proof of the previous world worked for all sets  `F `, so in particular\nit worked for the empty set, you just probably weren't really thinking about\nthis case explicitly beforehand. [Technical note to constructivists: I know\nthat we are not doing a proof by contradiction. But how else do you explain\nto a classical mathematician that their goal is to prove something false\nand this is OK because their hypotheses don't add up?]\n\n## Definition\n\nWhatever the sets  `P ` and  `Q ` are, we\nmake an element of \\\\(\\operatorname{Hom}(\\operatorname{Hom}(P,Q),\n\\operatorname{Hom}(\\operatorname{Hom}(Q,\\emptyset),\\operatorname{Hom}(P,\\emptyset)))\\\\).\n-/\nexample (P Q : Type) : (P \u2192 Q) \u2192 ((Q \u2192 empty) \u2192 (P \u2192 empty)) := by\n  intros f h p\n  apply h\n  apply f\n  exact p\n\n/-!\n\nNext up [Level 9](./Level9.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/FunctionWorld/Level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7481262822740308}}
{"text": "import formula\n\n/- The soundness and completeness theorems are always proven with respect to a \nsemantics. In this file we define the usual truth-value based reasoning \nsystem, where formulas are evaluated to the truth value they denote. The \nevaluation is based on what truth values are assigned to the variables, so a\nsemantic model of propositional logic in this system is a truth assignment \nfunction to the propositional variables. We also define some related notions \nsuch as satisfiability.\n-/\n\nvariable {vars : Type}\n\n/-- Evaluates formulas to truth values given a propositional variable \n    truth assignment `v`. -/\ndef eval (v : vars \u2192 bool) : Form vars \u2192 bool\n| \u22a5       := ff\n| \u2983x\u2984     := v x\n| (~ P)   := not (eval P)\n| (P \u22c0 Q) := and (eval P) (eval Q)\n| (P \u22c1 Q) := or (eval P) (eval Q)\n\nnotation `\u27e6` P `\u27e7_` v := eval v P\nnotation v ` \u22a8 ` A := \u27e6A\u27e7_v\nnotation v ` \u22a8 ` \u0393 := \u2200 \u03b3, \u03b3 \u2208 \u0393 \u2192 \u27e6\u03b3\u27e7_v\n\ntheorem no_bot (v : vars \u2192 bool) : \u00ac (\u21a5(v \u22a8 \u22a5)) :=\nby simp [eval]\n\n/-- A set of formulas \u0393 semantically entail another formula A iff \nall the models of \u0393 are models of A. -/\ndef entail (\u0393 : set (Form vars)) (A : Form vars) : Prop :=\n\u2200 (v : vars \u2192 bool), (v \u22a8 \u0393) \u2192 (v \u22a8 A)\n\nnotation \u0393 ` \u22a8 ` A := entail \u0393 A\nnotation \u0393 ` \u22ad ` A := \u00ac entail \u0393 A\n\n/-- A set of formulas are satisfiable iff it has a model. -/\ndef satisfiable (\u0393 : set (Form vars)) : Prop :=\n\u2203 (v : vars \u2192 bool), v \u22a8 \u0393\n\n/-- A set of formulas are satisfiable iff it has no model. -/\ndef unsatisfiable (\u0393 : set (Form vars)) : Prop :=\n\u00ac satisfiable \u0393\n\nvariable {\u0393 : set (Form vars)}\n\ntheorem satisfiable_iff : satisfiable \u0393 \u2194 (\u0393 \u22ad \u22a5) :=\nby simp [satisfiable, entail, eval]\n\ntheorem unsatisfiable_iff : unsatisfiable \u0393 \u2194 (\u0393 \u22a8 \u22a5) :=\nby simp [unsatisfiable, satisfiable_iff]\n\n#lint", "meta": {"author": "alyata", "repo": "formalising-math-1", "sha": "f77f9d7101d1c63af2051868a5d81976d9a50fdc", "save_path": "github-repos/lean/alyata-formalising-math-1", "path": "github-repos/lean/alyata-formalising-math-1/formalising-math-1-f77f9d7101d1c63af2051868a5d81976d9a50fdc/src/semantics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7481156540881737}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.set_theory.pgame\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Basic definitions about who has a winning stratergy\n\nWe define `G.first_loses`, `G.first_wins`, `G.left_wins` and `G.right_wins` for a pgame `G`, which\nmeans the second, first, left and right players have a winning strategy respectively.\nThese are defined by inequalities which can be unfolded with `pgame.lt_def` and `pgame.le_def`.\n-/\n\nnamespace pgame\n\n\n/-- The player who goes first loses -/\ndef first_loses (G : pgame) :=\n  G \u2264 0 \u2227 0 \u2264 G\n\n/-- The player who goes first wins -/\ndef first_wins (G : pgame) :=\n  0 < G \u2227 G < 0\n\n/-- The left player can always win -/\ndef left_wins (G : pgame) :=\n  0 < G \u2227 0 \u2264 G\n\n/-- The right player can always win -/\ndef right_wins (G : pgame) :=\n  G \u2264 0 \u2227 G < 0\n\ntheorem zero_first_loses : first_loses 0 :=\n  { left := le_refl 0, right := le_refl 0 }\n\ntheorem one_left_wins : left_wins 1 := sorry\n\ntheorem star_first_wins : first_wins star :=\n  { left := zero_lt_star, right := star_lt_zero }\n\ntheorem omega_left_wins : left_wins omega := sorry\n\ntheorem winner_cases (G : pgame) : left_wins G \u2228 right_wins G \u2228 first_loses G \u2228 first_wins G := sorry\n\ntheorem first_loses_is_zero {G : pgame} : first_loses G \u2194 equiv G 0 :=\n  iff.refl (first_loses G)\n\ntheorem first_loses_of_equiv {G : pgame} {H : pgame} (h : equiv G H) : first_loses G \u2192 first_loses H :=\n  fun (hGp : first_loses G) =>\n    { left := le_of_equiv_of_le (and.symm h) (and.left hGp), right := le_of_le_of_equiv (and.right hGp) h }\n\ntheorem first_wins_of_equiv {G : pgame} {H : pgame} (h : equiv G H) : first_wins G \u2192 first_wins H :=\n  fun (hGn : first_wins G) =>\n    { left := lt_of_lt_of_equiv (and.left hGn) h, right := lt_of_equiv_of_lt (and.symm h) (and.right hGn) }\n\ntheorem left_wins_of_equiv {G : pgame} {H : pgame} (h : equiv G H) : left_wins G \u2192 left_wins H :=\n  fun (hGl : left_wins G) => { left := lt_of_lt_of_equiv (and.left hGl) h, right := le_of_le_of_equiv (and.right hGl) h }\n\ntheorem right_wins_of_equiv {G : pgame} {H : pgame} (h : equiv G H) : right_wins G \u2192 right_wins H :=\n  fun (hGr : right_wins G) =>\n    { left := le_of_equiv_of_le (and.symm h) (and.left hGr), right := lt_of_equiv_of_lt (and.symm h) (and.right hGr) }\n\ntheorem first_loses_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) : first_loses G \u2194 first_loses H :=\n  { mp := first_loses_of_equiv h, mpr := first_loses_of_equiv (and.symm h) }\n\ntheorem first_wins_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) : first_wins G \u2194 first_wins H :=\n  { mp := first_wins_of_equiv h, mpr := first_wins_of_equiv (and.symm h) }\n\ntheorem left_wins_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) : left_wins G \u2194 left_wins H :=\n  { mp := left_wins_of_equiv h, mpr := left_wins_of_equiv (and.symm h) }\n\ntheorem right_wins_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) : right_wins G \u2194 right_wins H :=\n  { mp := right_wins_of_equiv h, mpr := right_wins_of_equiv (and.symm h) }\n\ntheorem not_first_wins_of_first_loses {G : pgame} : first_loses G \u2192 \u00acfirst_wins G := sorry\n\ntheorem not_first_loses_of_first_wins {G : pgame} : first_wins G \u2192 \u00acfirst_loses G :=\n  iff.mp imp_not_comm not_first_wins_of_first_loses\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/set_theory/game/winner.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7481156461329019}}
{"text": "\nvariables p q : Prop\n\n\n-- Equivilant\nexample (h : p \u2227 q) : q \u2227 p := \nhave hp : p, from and.left h,\nhave hq : q, from and.right h,\nshow q \u2227 p, from \u27e8hq, hp\u27e9\n\nexample (h : p \u2227 q) : q \u2227 p := \nhave hp : p, from and.left h,\nsuffices hq: q, from and.intro hq hp,\nshow q, from and.right h\n-- ", "meta": {"author": "robkorn", "repo": "theorem-proving-in-lean-exercises", "sha": "9c51da587105ee047a9db55d52709d881a39be7a", "save_path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises", "path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises/theorem-proving-in-lean-exercises-9c51da587105ee047a9db55d52709d881a39be7a/Chapter3/3-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7481037703196348}}
{"text": "import game.sup_inf.supSumSets\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 6\n\nThis level, very similar to the previous, showcases the infimum.\n-/\n\ndef sum_of_sets (A : set \u211d) (B : set \u211d) := { x : \u211d | \u2203 y \u2208 A, \u2203 z \u2208 B, x = y + z}\n\n\n/- Lemma\nIf $A$ and $B$ are sets of reals, then\n$$ \\textrm{inf} (A + B) = \\textrm{inf} (A) + \\textrm{inf}(B)$$\n-/\nlemma inf_sum_of_sets (A : set \u211d) (B : set \u211d) (h1A : A.nonempty) (h1B : B.nonempty) \n  (h2A : bdd_below A) (h2B : bdd_below B) (a : \u211d) (b : \u211d) : \n  (is_glb A a) \u2227 (is_glb B b) \u2192 is_glb (sum_of_sets A B) (a + b) :=\nbegin\n  intro h,\n  cases h with hA hB,\n  split,\n  -- prove that (a+b) is a lower bound\n  intros x h0,\n  cases h0 with y h1,\n  cases h1 with yA h2,\n  cases h2 with z h3,\n  cases h3 with zB hx,\n  --have H11A := hA.right, have H11B := hB.right,\n  have H12A := hA.left, have H12B := hB.left,\n  have H13A := H12A yA, have H13B := H12B zB,\n  linarith,\n  -- now prove (a+b) is the greatest lower bound\n  intros L hL,  -- L is another lower bound of (A+B)\n  have H1 : \u2200 x \u2208 A, (L - x) \u2208 lower_bounds B,\n  { \n    intros x hx y hy, \n    suffices : L \u2264 x + y, by linarith,\n    exact hL \u27e8x, hx, y, hy, rfl\u27e9,\n  },\n  have H2 : L - b \u2208 lower_bounds A,\n  { \n    intros x hx, \n    suffices : L - x \u2264 b, by linarith,\n    exact hB.2 (H1 x hx),\n  },\n  linarith [hA.2 H2], done\nend\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sup_inf/infSumSets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7481003312705681}}
{"text": "/-\nCopyright (c) 2019 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou, S\u00e9bastien Gou\u00ebzel, Fr\u00e9d\u00e9ric Dupuis, Heather Macbeth\n-/\n\nimport linear_algebra.bilinear_form\nimport linear_algebra.sesquilinear_form\nimport topology.metric_space.pi_Lp\nimport data.complex.is_R_or_C\nimport analysis.special_functions.sqrt\n\n/-!\n# Inner Product Space\n\nThis file defines inner product spaces and proves its basic properties.\n\nAn inner product space is a vector space endowed with an inner product. It generalizes the notion of\ndot product in `\u211d^n` and provides the means of defining the length of a vector and the angle between\ntwo vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero.\nWe define both the real and complex cases at the same time using the `is_R_or_C` typeclass.\n\n## Main results\n\n- We define the class `inner_product_space \ud835\udd5c E` extending `normed_space \ud835\udd5c E` with a number of basic\n  properties, most notably the Cauchy-Schwarz inequality. Here `\ud835\udd5c` is understood to be either `\u211d`\n  or `\u2102`, through the `is_R_or_C` typeclass.\n- We show that if `f i` is an inner product space for each `i`, then so is `\u03a0 i, f i`\n- We define `euclidean_space \ud835\udd5c n` to be `n \u2192 \ud835\udd5c` for any `fintype n`, and show that\n  this an inner product space.\n- Existence of orthogonal projection onto nonempty complete subspace:\n  Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.\n  Then there exists a unique `v` in `K` that minimizes the distance `\u2225u - v\u2225` to `u`.\n  The point `v` is usually called the orthogonal projection of `u` onto `K`.\n- We define `orthonormal`, a predicate on a function `v : \u03b9 \u2192 E`.  We prove the existence of a\n  maximal orthonormal set, `exists_maximal_orthonormal`, and also prove that a maximal orthonormal\n  set is a basis (`maximal_orthonormal_iff_is_basis_of_finite_dimensional`), if `E` is finite-\n  dimensional, or in general (`maximal_orthonormal_iff_dense_span`) a set whose span is dense\n  (i.e., a Hilbert basis, although we do not make that definition).\n\n## Notation\n\nWe globally denote the real and complex inner products by `\u27ea\u00b7, \u00b7\u27eb_\u211d` and `\u27ea\u00b7, \u00b7\u27eb_\u2102` respectively.\nWe also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,\nwhich respectively introduce the plain notation `\u27ea\u00b7, \u00b7\u27eb` for the the real and complex inner product.\n\nThe orthogonal complement of a submodule `K` is denoted by `K\u15ee`.\n\n## Implementation notes\n\nWe choose the convention that inner products are conjugate linear in the first argument and linear\nin the second.\n\n## TODO\n\n- Fix the section on the existence of minimizers and orthogonal projections to make sure that it\n  also applies in the complex case.\n\n## Tags\n\ninner product space, norm\n\n## References\n*  [Cl\u00e9ment & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]\n*  [Cl\u00e9ment & Martin, *A Coq formal proof of the Lax\u2013Milgram theorem*]\n\nThe Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>\n-/\n\nnoncomputable theory\n\nopen is_R_or_C real filter\nopen_locale big_operators classical topological_space\n\nvariables {\ud835\udd5c E F : Type*} [is_R_or_C \ud835\udd5c]\n\n/-- Syntactic typeclass for types endowed with an inner product -/\nclass has_inner (\ud835\udd5c E : Type*) := (inner : E \u2192 E \u2192 \ud835\udd5c)\n\nexport has_inner (inner)\n\nnotation `\u27ea`x`, `y`\u27eb_\u211d` := @inner \u211d _ _ x y\nnotation `\u27ea`x`, `y`\u27eb_\u2102` := @inner \u2102 _ _ x y\n\nsection notations\n\nlocalized \"notation `\u27ea`x`, `y`\u27eb` := @inner \u211d _ _ x y\" in real_inner_product_space\nlocalized \"notation `\u27ea`x`, `y`\u27eb` := @inner \u2102 _ _ x y\" in complex_inner_product_space\n\nend notations\n\n/--\nAn inner product space is a vector space with an additional operation called inner product.\nThe norm could be derived from the inner product, instead we require the existence of a norm and\nthe fact that `\u2225x\u2225^2 = re \u27eax, x\u27eb` to be able to put instances on `\ud835\udd42` or product\nspaces.\n\nTo construct a norm from an inner product, see `inner_product_space.of_core`.\n-/\nclass inner_product_space (\ud835\udd5c : Type*) (E : Type*) [is_R_or_C \ud835\udd5c]\n  extends normed_group E, normed_space \ud835\udd5c E, has_inner \ud835\udd5c E :=\n(norm_sq_eq_inner : \u2200 (x : E), \u2225x\u2225^2 = re (inner x x))\n(conj_sym  : \u2200 x y, conj (inner y x) = inner x y)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\nattribute [nolint dangerous_instance] inner_product_space.to_normed_group\n-- note [is_R_or_C instance]\n\n/-!\n### Constructing a normed space structure from an inner product\n\nIn the definition of an inner product space, we require the existence of a norm, which is equal\n(but maybe not defeq) to the square root of the scalar product. This makes it possible to put\nan inner product space structure on spaces with a preexisting norm (for instance `\u211d`), with good\nproperties. However, sometimes, one would like to define the norm starting only from a well-behaved\nscalar product. This is what we implement in this paragraph, starting from a structure\n`inner_product_space.core` stating that we have a nice scalar product.\n\nOur goal here is not to develop a whole theory with all the supporting API, as this will be done\nbelow for `inner_product_space`. Instead, we implement the bare minimum to go as directly as\npossible to the construction of the norm and the proof of the triangular inequality.\n\nWarning: Do not use this `core` structure if the space you are interested in already has a norm\ninstance defined on it, otherwise this will create a second non-defeq norm instance!\n-/\n\n/-- A structure requiring that a scalar product is positive definite and symmetric, from which one\ncan construct an `inner_product_space` instance in `inner_product_space.of_core`. -/\n@[nolint has_inhabited_instance]\nstructure inner_product_space.core\n  (\ud835\udd5c : Type*) (F : Type*)\n  [is_R_or_C \ud835\udd5c] [add_comm_group F] [module \ud835\udd5c F] :=\n(inner     : F \u2192 F \u2192 \ud835\udd5c)\n(conj_sym  : \u2200 x y, conj (inner y x) = inner x y)\n(nonneg_re : \u2200 x, 0 \u2264 re (inner x x))\n(definite  : \u2200 x, inner x x = 0 \u2192 x = 0)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\n/- We set `inner_product_space.core` to be a class as we will use it as such in the construction\nof the normed space structure that it produces. However, all the instances we will use will be\nlocal to this proof. -/\nattribute [class] inner_product_space.core\n\nnamespace inner_product_space.of_core\n\nvariables [add_comm_group F] [module \ud835\udd5c F] [c : inner_product_space.core \ud835\udd5c F]\ninclude c\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c F _ x y\nlocal notation `norm_sqK` := @is_R_or_C.norm_sq \ud835\udd5c _\nlocal notation `reK` := @is_R_or_C.re \ud835\udd5c _\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal notation `ext_iff` := @is_R_or_C.ext_iff \ud835\udd5c _\nlocal postfix `\u2020`:90 := @is_R_or_C.conj \ud835\udd5c _\n\n/-- Inner product defined by the `inner_product_space.core` structure. -/\ndef to_has_inner : has_inner \ud835\udd5c F := { inner := c.inner }\nlocal attribute [instance] to_has_inner\n\n/-- The norm squared function for `inner_product_space.core` structure. -/\ndef norm_sq (x : F) := reK \u27eax, x\u27eb\n\nlocal notation `norm_sqF` := @norm_sq \ud835\udd5c F _ _ _ _\n\nlemma inner_conj_sym (x y : F) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := c.conj_sym x y\n\nlemma inner_self_nonneg {x : F} : 0 \u2264 re \u27eax, x\u27eb := c.nonneg_re _\n\nlemma inner_self_nonneg_im {x : F} : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp [inner_conj_sym]\n\nlemma inner_self_im_zero {x : F} : im \u27eax, x\u27eb = 0 :=\ninner_self_nonneg_im\n\nlemma inner_add_left {x y z : F} : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\nc.add_left _ _ _\n\nlemma inner_add_right {x y z : F} : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby rw [\u2190inner_conj_sym, inner_add_left, ring_hom.map_add]; simp only [inner_conj_sym]\n\nlemma inner_norm_sq_eq_inner_self (x : F) : (norm_sqF x : \ud835\udd5c) = \u27eax, x\u27eb :=\nbegin\n  rw ext_iff,\n  exact \u27e8by simp only [of_real_re]; refl, by simp only [inner_self_nonneg_im, of_real_im]\u27e9\nend\n\nlemma inner_re_symm {x y : F} : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : F} : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : F} {r : \ud835\udd5c} : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\nc.smul_left _ _ _\n\nlemma inner_smul_right {x y : F} {r : \ud835\udd5c} : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_smul_left]; simp only [conj_conj, inner_conj_sym, ring_hom.map_mul]\n\nlemma inner_zero_left {x : F} : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190zero_smul \ud835\udd5c (0 : F), inner_smul_left]; simp only [zero_mul, ring_hom.map_zero]\n\nlemma inner_zero_right {x : F} : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_sym, inner_zero_left]; simp only [ring_hom.map_zero]\n\nlemma inner_self_eq_zero {x : F} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\niff.intro (c.definite _) (by { rintro rfl, exact inner_zero_left })\n\nlemma inner_self_re_to_K {x : F} : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby norm_num [ext_iff, inner_self_nonneg_im]\n\nlemma inner_abs_conj_sym {x y : F} : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\n  by rw [\u2190inner_conj_sym, abs_conj]\n\nlemma inner_neg_left {x y : F} : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\nlemma inner_neg_right {x y : F} : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_sym]\n\nlemma inner_sub_left {x y z : F} : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left, inner_neg_left] }\n\nlemma inner_sub_right {x y z : F} : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right, inner_neg_right] }\n\nlemma inner_mul_conj_re_abs {x y : F} : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw[\u2190inner_conj_sym, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `inner (x + y) (x + y)` -/\nlemma inner_add_add_self {x y : F} : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/- Expand `inner (x - y) (x - y)` -/\nlemma inner_sub_sub_self {x y : F} : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/--\nCauchy\u2013Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia.\nWe need this for the `core` structure to prove the triangle inequality below when\nshowing the core is a normed group.\n-/\nlemma inner_mul_inner_self_le (x y : F) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { change y \u2260 0 at hy,\n    have hy' : \u27eay, y\u27eb \u2260 0 := \u03bb h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := by simp only [inner_self_re_to_K],\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw ext_iff,\n      exact \u27e8by simp [H],by simp [inner_self_nonneg_im]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by field_simp [-mul_re, inner_conj_sym, hT, conj_div, h\u2081, h\u2083]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw [div_mul_eq_mul_div_comm, \u2190mul_div_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Norm constructed from a `inner_product_space.core` structure, defined to be the square root\nof the scalar product. -/\ndef to_has_norm : has_norm F :=\n{ norm := \u03bb x, sqrt (re \u27eax, x\u27eb) }\n\nlocal attribute [instance] to_has_norm\n\nlemma norm_eq_sqrt_inner (x : F) : \u2225x\u2225 = sqrt (re \u27eax, x\u27eb) := rfl\n\nlemma inner_self_eq_norm_sq (x : F) : re \u27eax, x\u27eb = \u2225x\u2225 * \u2225x\u2225 :=\nby rw[norm_eq_sqrt_inner, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma sqrt_norm_sq_eq_norm {x : F} : sqrt (norm_sqF x) = \u2225x\u2225 := rfl\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : F) : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _))\nbegin\n  have H : \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225) = re \u27eay, y\u27eb * re \u27eax, x\u27eb,\n  { simp only [inner_self_eq_norm_sq], ring, },\n  rw H,\n  conv\n  begin\n    to_lhs, congr, rw[inner_abs_conj_sym],\n  end,\n  exact inner_mul_inner_self_le y x,\nend\n\n/-- Normed group structure constructed from an `inner_product_space.core` structure -/\ndef to_normed_group : normed_group F :=\nnormed_group.of_core F\n{ norm_eq_zero_iff := assume x,\n  begin\n    split,\n    { intro H,\n      change sqrt (re \u27eax, x\u27eb) = 0 at H,\n      rw [sqrt_eq_zero inner_self_nonneg] at H,\n      apply (inner_self_eq_zero : \u27eax, x\u27eb = 0 \u2194 x = 0).mp,\n      rw ext_iff,\n      exact \u27e8by simp [H], by simp [inner_self_im_zero]\u27e9 },\n    { rintro rfl,\n      change sqrt (re \u27ea0, 0\u27eb) = 0,\n      simp only [sqrt_zero, inner_zero_right, add_monoid_hom.map_zero] }\n  end,\n  triangle := assume x y,\n  begin\n    have h\u2081 : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := abs_inner_le_norm _ _,\n    have h\u2082 : re \u27eax, y\u27eb \u2264 abs \u27eax, y\u27eb := re_le_abs _,\n    have h\u2083 : re \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := by linarith,\n    have h\u2084 : re \u27eay, x\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := by rwa [\u2190inner_conj_sym, conj_re],\n    have : \u2225x + y\u2225 * \u2225x + y\u2225 \u2264 (\u2225x\u2225 + \u2225y\u2225) * (\u2225x\u2225 + \u2225y\u2225),\n    { simp [\u2190inner_self_eq_norm_sq, inner_add_add_self, add_mul, mul_add, mul_comm],\n      linarith },\n    exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this\n  end,\n  norm_neg := \u03bb x, by simp only [norm, inner_neg_left, neg_neg, inner_neg_right] }\n\nlocal attribute [instance] to_normed_group\n\n/-- Normed space structure constructed from a `inner_product_space.core` structure -/\ndef to_normed_space : normed_space \ud835\udd5c F :=\n{ norm_smul_le := assume r x,\n  begin\n    rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, \u2190mul_assoc],\n    rw [conj_mul_eq_norm_sq_left, of_real_mul_re, sqrt_mul, \u2190inner_norm_sq_eq_inner_self,\n        of_real_re],\n    { simp [sqrt_norm_sq_eq_norm, is_R_or_C.sqrt_norm_sq_eq_norm] },\n    { exact norm_sq_nonneg r }\n  end }\n\nend inner_product_space.of_core\n\n/-- Given a `inner_product_space.core` structure on a space, one can use it to turn\nthe space into an inner product space, constructing the norm out of the inner product -/\ndef inner_product_space.of_core [add_comm_group F] [module \ud835\udd5c F]\n  (c : inner_product_space.core \ud835\udd5c F) : inner_product_space \ud835\udd5c F :=\nbegin\n  letI : normed_group F := @inner_product_space.of_core.to_normed_group \ud835\udd5c F _ _ _ c,\n  letI : normed_space \ud835\udd5c F := @inner_product_space.of_core.to_normed_space \ud835\udd5c F _ _ _ c,\n  exact { norm_sq_eq_inner := \u03bb x,\n    begin\n      have h\u2081 : \u2225x\u2225^2 = (sqrt (re (c.inner x x))) ^ 2 := rfl,\n      have h\u2082 : 0 \u2264 re (c.inner x x) := inner_product_space.of_core.inner_self_nonneg,\n      simp [h\u2081, sq_sqrt, h\u2082],\n    end,\n    ..c }\nend\n\n/-! ### Properties of inner product spaces -/\n\nvariables [inner_product_space \ud835\udd5c E] [inner_product_space \u211d F]\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\nlocal notation `IK` := @is_R_or_C.I \ud835\udd5c _\nlocal notation `absR` := _root_.abs\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal postfix `\u2020`:90 := @is_R_or_C.conj \ud835\udd5c _\nlocal postfix `\u22c6`:90 := complex.conj\n\nexport inner_product_space (norm_sq_eq_inner)\n\nsection basic_properties\n\n@[simp] lemma inner_conj_sym (x y : E) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := inner_product_space.conj_sym _ _\nlemma real_inner_comm (x y : F) : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := inner_conj_sym x y\n\nlemma inner_eq_zero_sym {x y : E} : \u27eax, y\u27eb = 0 \u2194 \u27eay, x\u27eb = 0 :=\n\u27e8\u03bb h, by simp [\u2190inner_conj_sym, h], \u03bb h, by simp [\u2190inner_conj_sym, h]\u27e9\n\n@[simp] lemma inner_self_nonneg_im {x : E} : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp\n\nlemma inner_self_im_zero {x : E} : im \u27eax, x\u27eb = 0 := inner_self_nonneg_im\n\nlemma inner_add_left {x y z : E} : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\ninner_product_space.add_left _ _ _\n\nlemma inner_add_right {x y z : E} : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby { rw [\u2190inner_conj_sym, inner_add_left, ring_hom.map_add], simp only [inner_conj_sym] }\n\nlemma inner_re_symm {x y : E} : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : E} : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : E} {r : \ud835\udd5c} : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\ninner_product_space.smul_left _ _ _\nlemma real_inner_smul_left {x y : F} {r : \u211d} : \u27ear \u2022 x, y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d := inner_smul_left\n\nlemma inner_smul_real_left {x y : E} {r : \u211d} : \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_left, conj_of_real, algebra.smul_def], refl }\n\nlemma inner_smul_right {x y : E} {r : \ud835\udd5c} : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_smul_left, ring_hom.map_mul, conj_conj, inner_conj_sym]\nlemma real_inner_smul_right {x y : F} {r : \u211d} : \u27eax, r \u2022 y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d := inner_smul_right\n\nlemma inner_smul_real_right {x y : E} {r : \u211d} : \u27eax, (r : \ud835\udd5c) \u2022 y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_right, algebra.smul_def], refl }\n\n/-- The inner product as a sesquilinear form. -/\n@[simps]\ndef sesq_form_of_inner : sesq_form \ud835\udd5c E (conj_to_ring_equiv \ud835\udd5c) :=\n{ sesq := \u03bb x y, \u27eay, x\u27eb,    -- Note that sesquilinear forms are linear in the first argument\n  sesq_add_left := \u03bb x y z, inner_add_right,\n  sesq_add_right := \u03bb x y z, inner_add_left,\n  sesq_smul_left := \u03bb r x y, inner_smul_right,\n  sesq_smul_right := \u03bb r x y, inner_smul_left }\n\n/-- The real inner product as a bilinear form. -/\n@[simps]\ndef bilin_form_of_real_inner : bilin_form \u211d F :=\n{ bilin := inner,\n  bilin_add_left := \u03bb x y z, inner_add_left,\n  bilin_smul_left := \u03bb a x y, inner_smul_left,\n  bilin_add_right := \u03bb x y z, inner_add_right,\n  bilin_smul_right := \u03bb a x y, inner_smul_right }\n\n/-- An inner product with a sum on the left. -/\nlemma sum_inner {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27ea\u2211 i in s, f i, x\u27eb = \u2211 i in s, \u27eaf i, x\u27eb :=\nsesq_form.sum_right (sesq_form_of_inner) _ _ _\n\n/-- An inner product with a sum on the right. -/\nlemma inner_sum {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27eax, \u2211 i in s, f i\u27eb = \u2211 i in s, \u27eax, f i\u27eb :=\nsesq_form.sum_left (sesq_form_of_inner) _ _ _\n\n/-- An inner product with a sum on the left, `finsupp` version. -/\nlemma finsupp.sum_inner {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eal.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i), x\u27eb\n  = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), (is_R_or_C.conj a) \u2022 \u27eav i, x\u27eb) :=\nby { convert sum_inner l.support (\u03bb a, l a \u2022 v a) x, simp [inner_smul_left, finsupp.sum] }\n\n/-- An inner product with a sum on the right, `finsupp` version. -/\nlemma finsupp.inner_sum {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eax, l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i)\u27eb = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 \u27eax, v i\u27eb) :=\nby { convert inner_sum l.support (\u03bb a, l a \u2022 v a) x, simp [inner_smul_right, finsupp.sum] }\n\n@[simp] lemma inner_zero_left {x : E} : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190 zero_smul \ud835\udd5c (0:E), inner_smul_left, ring_hom.map_zero, zero_mul]\n\nlemma inner_re_zero_left {x : E} : re \u27ea0, x\u27eb = 0 :=\nby simp only [inner_zero_left, add_monoid_hom.map_zero]\n\n@[simp] lemma inner_zero_right {x : E} : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_sym, inner_zero_left, ring_hom.map_zero]\n\nlemma inner_re_zero_right {x : E} : re \u27eax, 0\u27eb = 0 :=\nby simp only [inner_zero_right, add_monoid_hom.map_zero]\n\nlemma inner_self_nonneg {x : E} : 0 \u2264 re \u27eax, x\u27eb :=\nby rw [\u2190norm_sq_eq_inner]; exact pow_nonneg (norm_nonneg x) 2\nlemma real_inner_self_nonneg {x : F} : 0 \u2264 \u27eax, x\u27eb_\u211d := @inner_self_nonneg \u211d F _ _ x\n\n@[simp] lemma inner_self_eq_zero {x : E} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    have h\u2081 : re \u27eax, x\u27eb = 0 := by rw is_R_or_C.ext_iff at h; simp [h.1],\n    rw [\u2190norm_sq_eq_inner x] at h\u2081,\n    rw [\u2190norm_eq_zero],\n    exact pow_eq_zero h\u2081 },\n  { rintro rfl,\n    exact inner_zero_left }\nend\n\n@[simp] lemma inner_self_nonpos {x : E} : re \u27eax, x\u27eb \u2264 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    rw \u2190inner_self_eq_zero,\n    have H\u2081 : re \u27eax, x\u27eb \u2265 0, exact inner_self_nonneg,\n    have H\u2082 : re \u27eax, x\u27eb = 0, exact le_antisymm h H\u2081,\n    rw is_R_or_C.ext_iff,\n    exact \u27e8by simp [H\u2082], by simp [inner_self_nonneg_im]\u27e9 },\n  { rintro rfl,\n    simp only [inner_zero_left, add_monoid_hom.map_zero] }\nend\n\nlemma real_inner_self_nonpos {x : F} : \u27eax, x\u27eb_\u211d \u2264 0 \u2194 x = 0 :=\nby { have h := @inner_self_nonpos \u211d F _ _ x, simpa using h }\n\n@[simp] lemma inner_self_re_to_K {x : E} : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby rw is_R_or_C.ext_iff; exact \u27e8by simp, by simp [inner_self_nonneg_im]\u27e9\n\nlemma inner_self_eq_norm_sq_to_K (x : E) : \u27eax, x\u27eb = (\u2225x\u2225 ^ 2 : \ud835\udd5c) :=\nbegin\n  suffices : (is_R_or_C.re \u27eax, x\u27eb : \ud835\udd5c) = \u2225x\u2225 ^ 2,\n  { simpa [inner_self_re_to_K] using this },\n  exact_mod_cast (norm_sq_eq_inner x).symm\nend\n\nlemma inner_self_re_abs {x : E} : re \u27eax, x\u27eb = abs \u27eax, x\u27eb :=\nbegin\n  conv_rhs { rw [\u2190inner_self_re_to_K] },\n  symmetry,\n  exact is_R_or_C.abs_of_nonneg inner_self_nonneg,\nend\n\nlemma inner_self_abs_to_K {x : E} : (absK \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby { rw[\u2190inner_self_re_abs], exact inner_self_re_to_K }\n\nlemma real_inner_self_abs {x : F} : absR \u27eax, x\u27eb_\u211d = \u27eax, x\u27eb_\u211d :=\nby { have h := @inner_self_abs_to_K \u211d F _ _ x, simpa using h }\n\nlemma inner_abs_conj_sym {x y : E} : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, abs_conj]\n\n@[simp] lemma inner_neg_left {x y : E} : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\n@[simp] lemma inner_neg_right {x y : E} : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_sym]\n\nlemma inner_neg_neg {x y : E} : \u27ea-x, -y\u27eb = \u27eax, y\u27eb := by simp\n\n@[simp] lemma inner_self_conj {x : E} : \u27eax, x\u27eb\u2020 = \u27eax, x\u27eb :=\nby rw [is_R_or_C.ext_iff]; exact \u27e8by rw [conj_re], by rw [conj_im, inner_self_im_zero, neg_zero]\u27e9\n\nlemma inner_sub_left {x y z : E} : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left] }\n\nlemma inner_sub_right {x y z : E} : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right] }\n\nlemma inner_mul_conj_re_abs {x y : E} : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw[\u2190inner_conj_sym, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `\u27eax + y, x + y\u27eb` -/\nlemma inner_add_add_self {x y : E} : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/-- Expand `\u27eax + y, x + y\u27eb_\u211d` -/\nlemma real_inner_add_add_self {x y : F} : \u27eax + y, x + y\u27eb_\u211d = \u27eax, x\u27eb_\u211d + 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  simp [inner_add_add_self, this],\n  ring,\nend\n\n/- Expand `\u27eax - y, x - y\u27eb` -/\nlemma inner_sub_sub_self {x y : E} : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/-- Expand `\u27eax - y, x - y\u27eb_\u211d` -/\nlemma real_inner_sub_sub_self {x y : F} : \u27eax - y, x - y\u27eb_\u211d = \u27eax, x\u27eb_\u211d - 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  simp [inner_sub_sub_self, this],\n  ring,\nend\n\n/-- Parallelogram law -/\nlemma parallelogram_law {x y : E} :\n  \u27eax + y, x + y\u27eb + \u27eax - y, x - y\u27eb = 2 * (\u27eax, x\u27eb + \u27eay, y\u27eb) :=\nby simp [inner_add_add_self, inner_sub_sub_self, two_mul, sub_eq_add_neg, add_comm, add_left_comm]\n\n/-- Cauchy\u2013Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia. -/\nlemma inner_mul_inner_self_le (x y : E) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { change y \u2260 0 at hy,\n    have hy' : \u27eay, y\u27eb \u2260 0 := \u03bb h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := by simp,\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw is_R_or_C.ext_iff,\n      exact \u27e8by simp [H],by simp [inner_self_nonneg_im]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by field_simp [-mul_re, hT, conj_div, h\u2081, h\u2083, inner_conj_sym]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw [div_mul_eq_mul_div_comm, \u2190mul_div_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Cauchy\u2013Schwarz inequality for real inner products. -/\nlemma real_inner_mul_inner_self_le (x y : F) : \u27eax, y\u27eb_\u211d * \u27eax, y\u27eb_\u211d \u2264 \u27eax, x\u27eb_\u211d * \u27eay, y\u27eb_\u211d :=\nbegin\n  have h\u2081 : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  have h\u2082 := @inner_mul_inner_self_le \u211d F _ _ x y,\n  dsimp at h\u2082,\n  have h\u2083 := abs_mul_abs_self \u27eax, y\u27eb_\u211d,\n  rw [h\u2081] at h\u2082,\n  simpa [h\u2083] using h\u2082,\nend\n\n/-- A family of vectors is linearly independent if they are nonzero\nand orthogonal. -/\nlemma linear_independent_of_ne_zero_of_inner_eq_zero {\u03b9 : Type*} {v : \u03b9 \u2192 E}\n  (hz : \u2200 i, v i \u2260 0) (ho : \u2200 i j, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0) : linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff',\n  intros s g hg i hi,\n  have h' : g i * inner (v i) (v i) = inner (v i) (\u2211 j in s, g j \u2022 v j),\n  { rw inner_sum,\n    symmetry,\n    convert finset.sum_eq_single i _ _,\n    { rw inner_smul_right },\n    { intros j hj hji,\n      rw [inner_smul_right, ho i j hji.symm, mul_zero] },\n    { exact \u03bb h, false.elim (h hi) } },\n  simpa [hg, hz] using h'\nend\n\nend basic_properties\n\nsection orthonormal_sets\nvariables {\u03b9 : Type*} (\ud835\udd5c)\n\ninclude \ud835\udd5c\n\n/-- An orthonormal set of vectors in an `inner_product_space` -/\ndef orthonormal (v : \u03b9 \u2192 E) : Prop :=\n(\u2200 i, \u2225v i\u2225 = 1) \u2227 (\u2200 {i j}, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0)\n\nomit \ud835\udd5c\n\nvariables {\ud835\udd5c}\n\n/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal.  (Inner\nproduct equals Kronecker delta.) -/\nlemma orthonormal_iff_ite {v : \u03b9 \u2192 E} :\n  orthonormal \ud835\udd5c v \u2194 \u2200 i j, \u27eav i, v j\u27eb = if i = j then (1:\ud835\udd5c) else (0:\ud835\udd5c) :=\nbegin\n  split,\n  { intros hv i j,\n    split_ifs,\n    { simp [h, inner_self_eq_norm_sq_to_K, hv.1] },\n    { exact hv.2 h } },\n  { intros h,\n    split,\n    { intros i,\n      have h' : \u2225v i\u2225 ^ 2 = 1 ^ 2 := by simp [norm_sq_eq_inner, h i i],\n      have h\u2081 : 0 \u2264 \u2225v i\u2225 := norm_nonneg _,\n      have h\u2082 : (0:\u211d) \u2264 1 := by norm_num,\n      rwa eq_of_sq_eq_sq h\u2081 h\u2082 at h' },\n    { intros i j hij,\n      simpa [hij] using h i j } }\nend\n\n/-- `if ... then ... else` characterization of a set of vectors being orthonormal.  (Inner product\nequals Kronecker delta.) -/\ntheorem orthonormal_subtype_iff_ite {s : set E} :\n  orthonormal \ud835\udd5c (coe : s \u2192 E) \u2194\n  (\u2200 v \u2208 s, \u2200 w \u2208 s, \u27eav, w\u27eb = if v = w then 1 else 0) :=\nbegin\n  rw orthonormal_iff_ite,\n  split,\n  { intros h v hv w hw,\n    convert h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9 using 1,\n    simp },\n  { rintros h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9,\n    convert h v hv w hw using 1,\n    simp }\nend\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = l i :=\nby simp [finsupp.total_apply, finsupp.inner_sum, orthonormal_iff_ite.mp hv]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, \u2211 i : \u03b9, (l i) \u2022 (v i)\u27eb = l i :=\nby simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = conj (l i) :=\nby rw [\u2190 inner_conj_sym, hv.inner_right_finsupp]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27ea\u2211 i : \u03b9, (l i) \u2022 (v i), v i\u27eb = conj (l i) :=\nby simp [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv]\n\n/-- An orthonormal set is linearly independent. -/\nlemma orthonormal.linear_independent {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff,\n  intros l hl,\n  ext i,\n  have key : \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = \u27eav i, 0\u27eb := by rw hl,\n  simpa [hv.inner_right_finsupp] using key\nend\n\n/-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an\northonormal family. -/\nlemma orthonormal.comp\n  {\u03b9' : Type*} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : \u03b9' \u2192 \u03b9) (hf : function.injective f) :\n  orthonormal \ud835\udd5c (v \u2218 f) :=\nbegin\n  rw orthonormal_iff_ite at \u22a2 hv,\n  intros i j,\n  convert hv (f i) (f j) using 1,\n  simp [hf.eq_iff]\nend\n\n/-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the\nset. -/\nlemma orthonormal.inner_finsupp_eq_zero\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) {s : set \u03b9} {i : \u03b9} (hi : i \u2209 s) {l : \u03b9 \u2192\u2080 \ud835\udd5c}\n  (hl : l \u2208 finsupp.supported \ud835\udd5c \ud835\udd5c s) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = 0 :=\nbegin\n  rw finsupp.mem_supported' at hl,\n  simp [hv.inner_left_finsupp, hl i hi],\nend\n\n/- The material that follows, culminating in the existence of a maximal orthonormal subset, is\nadapted from the corresponding development of the theory of linearly independents sets.  See\n`exists_linear_independent` in particular. -/\n\nvariables (\ud835\udd5c E)\nlemma orthonormal_empty : orthonormal \ud835\udd5c (\u03bb x, x : (\u2205 : set E) \u2192 E) :=\nby simp [orthonormal_subtype_iff_ite]\nvariables {\ud835\udd5c E}\n\nlemma orthonormal_Union_of_directed\n  {\u03b7 : Type*} {s : \u03b7 \u2192 set E} (hs : directed (\u2286) s) (h : \u2200 i, orthonormal \ud835\udd5c (\u03bb x, x : s i \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3 i, s i) \u2192 E) :=\nbegin\n  rw orthonormal_subtype_iff_ite,\n  rintros x \u27e8_, \u27e8i, rfl\u27e9, hxi\u27e9 y \u27e8_, \u27e8j, rfl\u27e9, hyj\u27e9,\n  obtain \u27e8k, hik, hjk\u27e9 := hs i j,\n  have h_orth : orthonormal \ud835\udd5c (\u03bb x, x : (s k) \u2192 E) := h k,\n  rw orthonormal_subtype_iff_ite at h_orth,\n  exact h_orth x (hik hxi) y (hjk hyj)\nend\n\nlemma orthonormal_sUnion_of_directed\n  {s : set (set E)} (hs : directed_on (\u2286) s)\n  (h : \u2200 a \u2208 s, orthonormal \ud835\udd5c (\u03bb x, x : (a : set E) \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3\u2080 s) \u2192 E) :=\nby rw set.sUnion_eq_Union; exact orthonormal_Union_of_directed hs.directed_coe (by simpa using h)\n\n/-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set\ncontaining it. -/\nlemma exists_maximal_orthonormal {s : set E} (hs : orthonormal \ud835\udd5c (coe : s \u2192 E)) :\n  \u2203 w \u2287 s, orthonormal \ud835\udd5c (coe : w \u2192 E) \u2227 \u2200 u \u2287 w, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2192 u = w :=\nbegin\n  rcases zorn.zorn_subset_nonempty {b | orthonormal \ud835\udd5c (coe : b \u2192 E)} _ _ hs  with \u27e8b, bi, sb, h\u27e9,\n  { refine \u27e8b, sb, bi, _\u27e9,\n    exact \u03bb u hus hu, h u hu hus },\n  { refine \u03bb c hc cc c0, \u27e8\u22c3\u2080 c, _, _\u27e9,\n    { exact orthonormal_sUnion_of_directed cc.directed_on (\u03bb x xc, hc xc) },\n    { exact \u03bb _, set.subset_sUnion_of_mem } }\nend\n\nlemma orthonormal.ne_zero {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (i : \u03b9) : v i \u2260 0 :=\nbegin\n  have : \u2225v i\u2225 \u2260 0,\n  { rw hv.1 i,\n    norm_num },\n  simpa using this\nend\n\nopen finite_dimensional\n\nlemma is_basis_of_orthonormal_of_card_eq_finrank [fintype \u03b9] [nonempty \u03b9] {v : \u03b9 \u2192 E}\n  (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finrank \ud835\udd5c E) :\n  is_basis \ud835\udd5c v :=\nis_basis_of_linear_independent_of_card_eq_finrank hv.linear_independent card_eq\n\nend orthonormal_sets\n\nsection norm\n\nlemma norm_eq_sqrt_inner (x : E) : \u2225x\u2225 = sqrt (re \u27eax, x\u27eb) :=\nbegin\n  have h\u2081 : \u2225x\u2225^2 = re \u27eax, x\u27eb := norm_sq_eq_inner x,\n  have h\u2082 := congr_arg sqrt h\u2081,\n  simpa using h\u2082,\nend\n\nlemma norm_eq_sqrt_real_inner (x : F) : \u2225x\u2225 = sqrt \u27eax, x\u27eb_\u211d :=\nby { have h := @norm_eq_sqrt_inner \u211d F _ _ x, simpa using h }\n\nlemma inner_self_eq_norm_sq (x : E) : re \u27eax, x\u27eb = \u2225x\u2225 * \u2225x\u2225 :=\nby rw[norm_eq_sqrt_inner, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma real_inner_self_eq_norm_sq (x : F) : \u27eax, x\u27eb_\u211d = \u2225x\u2225 * \u2225x\u2225 :=\nby { have h := @inner_self_eq_norm_sq \u211d F _ _ x, simpa using h }\n\n\n/-- Expand the square -/\nlemma norm_add_sq {x y : E} : \u2225x + y\u2225^2 = \u2225x\u2225^2 + 2 * (re \u27eax, y\u27eb) + \u2225y\u2225^2 :=\nbegin\n  repeat {rw [sq, \u2190inner_self_eq_norm_sq]},\n  rw[inner_add_add_self, two_mul],\n  simp only [add_assoc, add_left_inj, add_right_inj, add_monoid_hom.map_add],\n  rw [\u2190inner_conj_sym, conj_re],\nend\n\nalias norm_add_sq \u2190 norm_add_pow_two\n\n/-- Expand the square -/\nlemma norm_add_sq_real {x y : F} : \u2225x + y\u2225^2 = \u2225x\u2225^2 + 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225^2 :=\nby { have h := @norm_add_sq \u211d F _ _, simpa using h }\n\nalias norm_add_sq_real \u2190 norm_add_pow_two_real\n\n/-- Expand the square -/\nlemma norm_add_mul_self {x y : E} : \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + 2 * (re \u27eax, y\u27eb) + \u2225y\u2225 * \u2225y\u2225 :=\nby { repeat {rw [\u2190 sq]}, exact norm_add_sq }\n\n/-- Expand the square -/\nlemma norm_add_mul_self_real {x y : F} : \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225 * \u2225y\u2225 :=\nby { have h := @norm_add_mul_self \u211d F _ _, simpa using h }\n\n/-- Expand the square -/\nlemma norm_sub_sq {x y : E} : \u2225x - y\u2225^2 = \u2225x\u2225^2 - 2 * (re \u27eax, y\u27eb) + \u2225y\u2225^2 :=\nbegin\n  repeat {rw [sq, \u2190inner_self_eq_norm_sq]},\n  rw[inner_sub_sub_self],\n  calc\n    re (\u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb)\n        = re \u27eax, x\u27eb - re \u27eax, y\u27eb - re \u27eay, x\u27eb + re \u27eay, y\u27eb  : by simp\n    ... = -re \u27eay, x\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb  : by ring\n    ... = -re (\u27eax, y\u27eb\u2020) - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw[inner_conj_sym]\n    ... = -re \u27eax, y\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw[conj_re]\n    ... = re \u27eax, x\u27eb - 2*re \u27eax, y\u27eb + re \u27eay, y\u27eb : by ring\nend\n\nalias norm_sub_sq \u2190 norm_sub_pow_two\n\n/-- Expand the square -/\nlemma norm_sub_sq_real {x y : F} : \u2225x - y\u2225^2 = \u2225x\u2225^2 - 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225^2 :=\nnorm_sub_sq\n\nalias norm_sub_sq_real \u2190 norm_sub_pow_two_real\n\n/-- Expand the square -/\nlemma norm_sub_mul_self {x y : E} : \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 - 2 * re \u27eax, y\u27eb + \u2225y\u2225 * \u2225y\u2225 :=\nby { repeat {rw [\u2190 sq]}, exact norm_sub_sq }\n\n/-- Expand the square -/\nlemma norm_sub_mul_self_real {x y : F} : \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 - 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225 * \u2225y\u2225 :=\nby { have h := @norm_sub_mul_self \u211d F _ _, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : E) : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _))\nbegin\n  have : \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225) = (re \u27eax, x\u27eb) * (re \u27eay, y\u27eb),\n    simp only [inner_self_eq_norm_sq], ring,\n  rw this,\n  conv_lhs { congr, skip, rw [inner_abs_conj_sym] },\n  exact inner_mul_inner_self_le _ _\nend\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_real_inner_le_norm (x y : F) : absR \u27eax, y\u27eb_\u211d \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nby { have h := @abs_inner_le_norm \u211d F _ _ x y, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma real_inner_le_norm (x y : F) : \u27eax, y\u27eb_\u211d \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nle_trans (le_abs_self _) (abs_real_inner_le_norm _ _)\n\ninclude \ud835\udd5c\nlemma parallelogram_law_with_norm {x y : E} :\n  \u2225x + y\u2225 * \u2225x + y\u2225 + \u2225x - y\u2225 * \u2225x - y\u2225 = 2 * (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225) :=\nbegin\n  simp only [\u2190 inner_self_eq_norm_sq],\n  rw[\u2190 re.map_add, parallelogram_law, two_mul, two_mul],\n  simp only [re.map_add],\nend\nomit \ud835\udd5c\n\nlemma parallelogram_law_with_norm_real {x y : F} :\n  \u2225x + y\u2225 * \u2225x + y\u2225 + \u2225x - y\u2225 * \u2225x - y\u2225 = 2 * (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225) :=\nby { have h := @parallelogram_law_with_norm \u211d F _ _ x y, simpa using h }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x\u2225 * \u2225x\u2225 - \u2225y\u2225 * \u2225y\u2225) / 2 :=\nby { rw norm_add_mul_self, ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 2 :=\nby { rw [norm_sub_mul_self], ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 4 :=\nby { rw [norm_add_mul_self, norm_sub_mul_self], ring }\n\n/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/\nlemma im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four (x y : E) :\n  im \u27eax, y\u27eb = (\u2225x - IK \u2022 y\u2225 * \u2225x - IK \u2022 y\u2225 - \u2225x + IK \u2022 y\u2225 * \u2225x + IK \u2022 y\u2225) / 4 :=\nby { simp only [norm_add_mul_self, norm_sub_mul_self, inner_smul_right, I_mul_re], ring }\n\n/-- Polarization identity: The inner product, in terms of the norm. -/\nlemma inner_eq_sum_norm_sq_div_four (x y : E) :\n  \u27eax, y\u27eb = (\u2225x + y\u2225 ^ 2 - \u2225x - y\u2225 ^ 2 + (\u2225x - IK \u2022 y\u2225 ^ 2 - \u2225x + IK \u2022 y\u2225 ^ 2) * IK) / 4 :=\nbegin\n  rw [\u2190 re_add_im \u27eax, y\u27eb, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,\n    im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four],\n  push_cast,\n  simp only [sq, \u2190 mul_div_right_comm, \u2190 add_div]\nend\n\nsection\n\nvariables {E' : Type*} [inner_product_space \ud835\udd5c E']\n\n/-- A linear isometry preserves the inner product. -/\n@[simp] lemma linear_isometry.inner_map_map (f : E \u2192\u2097\u1d62[\ud835\udd5c] E') (x y : E) : \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nby simp [inner_eq_sum_norm_sq_div_four, \u2190 f.norm_map]\n\n/-- A linear isometric equivalence preserves the inner product. -/\n@[simp] lemma linear_isometry_equiv.inner_map_map (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') (x y : E) :\n  \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nf.to_linear_isometry.inner_map_map x y\n\n/-- A linear map that preserves the inner product is a linear isometry. -/\ndef linear_map.isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) : E \u2192\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, \u03bb x, by simp only [norm_eq_sqrt_inner, h]\u27e9\n\n@[simp] lemma linear_map.coe_isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_map.isometry_of_inner_to_linear_map (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_map = f := rfl\n\n/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/\ndef linear_equiv.isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, ((f : E \u2192\u2097[\ud835\udd5c] E').isometry_of_inner h).norm_map\u27e9\n\n@[simp] lemma linear_equiv.coe_isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_equiv.isometry_of_inner_to_linear_equiv (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_equiv = f := rfl\n\nend\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x\u2225 * \u2225x\u2225 - \u2225y\u2225 * \u2225y\u2225) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y\n\n/-- Pythagorean theorem, if-and-only-if vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [norm_add_mul_self, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : \u27eax, y\u27eb = 0) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\nbegin\n  rw [norm_add_mul_self, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  apply or.inr,\n  simp only [h, zero_re'],\nend\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\n(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector\ninner product form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [norm_sub_mul_self, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero,\n      mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, subtracting vectors, vector inner product\nform. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\n(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- The sum and difference of two vectors are orthogonal if and only\nif they have the same norm. -/\nlemma real_inner_add_sub_eq_zero_iff (x y : F) : \u27eax + y, x - y\u27eb_\u211d = 0 \u2194 \u2225x\u2225 = \u2225y\u2225 :=\nbegin\n  conv_rhs { rw \u2190mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _) },\n  simp only [\u2190inner_self_eq_norm_sq, inner_add_left, inner_sub_right,\n            real_inner_comm y x, sub_eq_zero, re_to_real],\n  split,\n  { intro h,\n    rw [add_comm] at h,\n    linarith },\n  { intro h,\n    linarith }\nend\n\n/-- The real inner product of two vectors, divided by the product of their\nnorms, has absolute value at most 1. -/\nlemma abs_real_inner_div_norm_mul_norm_le_one (x y : F) : absR (\u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225)) \u2264 1 :=\nbegin\n  rw _root_.abs_div,\n  by_cases h : 0 = absR (\u2225x\u2225 * \u2225y\u2225),\n  { rw [\u2190h, div_zero],\n    norm_num },\n  { change 0 \u2260 absR (\u2225x\u2225 * \u2225y\u2225) at h,\n    rw div_le_iff' (lt_of_le_of_ne (ge_iff_le.mp (_root_.abs_nonneg (\u2225x\u2225 * \u2225y\u2225))) h),\n    convert abs_real_inner_le_norm x y using 1,\n    rw [_root_.abs_mul, _root_.abs_of_nonneg (norm_nonneg x), _root_.abs_of_nonneg (norm_nonneg y),\n        mul_one] }\nend\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_left (x : F) (r : \u211d) : \u27ear \u2022 x, x\u27eb_\u211d = r * (\u2225x\u2225 * \u2225x\u2225) :=\nby rw [real_inner_smul_left, \u2190real_inner_self_eq_norm_sq]\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_right (x : F) (r : \u211d) : \u27eax, r \u2022 x\u27eb_\u211d = r * (\u2225x\u2225 * \u2225x\u2225) :=\nby rw [inner_smul_right, \u2190real_inner_self_eq_norm_sq]\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : E} {r : \ud835\udd5c} (hx : x \u2260 0) (hr : r \u2260 0) : abs \u27eax, r \u2022 x\u27eb / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  have hx' : \u2225x\u2225 \u2260 0 := by simp [norm_eq_zero, hx],\n  have hr' : abs r \u2260 0 := by simp [is_R_or_C.abs_eq_zero, hr],\n  rw [inner_smul_right, is_R_or_C.abs_mul, \u2190inner_self_re_abs, inner_self_eq_norm_sq,\n      norm_smul],\n  rw [is_R_or_C.norm_eq_abs, \u2190mul_assoc, \u2190div_div_eq_div_mul, mul_div_cancel _ hx',\n     \u2190div_div_eq_div_mul, mul_comm, mul_div_cancel _ hr', div_self hx'],\nend\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r \u2260 0) : absR \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  rw \u2190 abs_to_real,\n  exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr\nend\n\n/-- The inner product of a nonzero vector with a positive multiple of\nitself, divided by the product of their norms, has value 1. -/\nlemma real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : 0 < r) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2225x\u2225, mul_comm _ (absR r),\n      mul_assoc, _root_.abs_of_nonneg (le_of_lt hr), div_self],\n  exact mul_ne_zero (ne_of_gt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of a nonzero vector with a negative multiple of\nitself, divided by the product of their norms, has value -1. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r < 0) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = -1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2225x\u2225, mul_comm _ (absR r),\n      mul_assoc, abs_of_neg hr, \u2190neg_mul_eq_neg_mul, div_neg_eq_neg_div, div_self],\n  exact mul_ne_zero (ne_of_lt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_iff (x y : E) :\n  abs (\u27eax, y\u27eb / (\u2225x\u2225 * \u2225y\u2225)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have hx0 : x \u2260 0,\n    { intro hx0,\n      rw [hx0, inner_zero_left, zero_div] at h,\n      norm_num at h, },\n    refine and.intro hx0 _,\n    set r := \u27eax, y\u27eb / (\u2225x\u2225 * \u2225x\u2225) with hr,\n    use r,\n    set t := y - r \u2022 x with ht,\n    have ht0 : \u27eax, t\u27eb = 0,\n    { rw [ht, inner_sub_right, inner_smul_right, hr],\n      norm_cast,\n      rw [\u2190inner_self_eq_norm_sq, inner_self_re_to_K,\n          div_mul_cancel _ (\u03bb h, hx0 (inner_self_eq_zero.1 h)), sub_self] },\n    replace h : \u2225r \u2022 x\u2225 / \u2225t + r \u2022 x\u2225 = 1,\n    { rw [\u2190sub_add_cancel y (r \u2022 x), \u2190ht, inner_add_right, ht0, zero_add, inner_smul_right,\n        is_R_or_C.abs_div, is_R_or_C.abs_mul, \u2190inner_self_re_abs,\n        inner_self_eq_norm_sq] at h,\n      norm_cast at h,\n      rwa [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm, \u2190mul_assoc, mul_comm,\n        mul_div_mul_left _ _ (\u03bb h, hx0 (norm_eq_zero.1 h)), \u2190is_R_or_C.norm_eq_abs,\n        \u2190norm_smul] at h },\n    have hr0 : r \u2260 0,\n    { intro hr0,\n      rw [hr0, zero_smul, norm_zero, zero_div] at h,\n      norm_num at h },\n    refine and.intro hr0 _,\n    have h2 : \u2225r \u2022 x\u2225 ^ 2 = \u2225t + r \u2022 x\u2225 ^ 2,\n    { rw [eq_of_div_eq_one h] },\n    replace h2 : \u27ear \u2022 x, r \u2022 x\u27eb = \u27eat, t\u27eb + \u27eat, r \u2022 x\u27eb + \u27ear \u2022 x, t\u27eb + \u27ear \u2022 x, r \u2022 x\u27eb,\n    { rw [sq, sq, \u2190inner_self_eq_norm_sq, \u2190inner_self_eq_norm_sq ] at h2,\n      have h2' := congr_arg (\u03bb z : \u211d, (z : \ud835\udd5c)) h2,\n      simp_rw [inner_self_re_to_K, inner_add_add_self] at h2',\n      exact h2' },\n    conv at h2 in \u27ear \u2022 x, t\u27eb { rw [inner_smul_left, ht0, mul_zero] },\n    symmetry' at h2,\n    have h\u2081 : \u27eat, r \u2022 x\u27eb = 0 := by { rw [inner_smul_right, \u2190inner_conj_sym, ht0], simp },\n    rw [add_zero, h\u2081, add_left_eq_self, add_zero, inner_self_eq_zero] at h2,\n    rw h2 at ht,\n    exact eq_of_sub_eq_zero ht.symm },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw [hy, is_R_or_C.abs_div],\n    norm_cast,\n    rw [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm],\n    exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  absR (\u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  have := @abs_inner_div_norm_mul_norm_eq_one_iff \u211d F _ _ x y,\n  simpa [coe_real_eq_id] using this,\nend\n\n/--\nIf the inner product of two vectors is equal to the product of their norms, then the two vectors\nare multiples of each other. One form of the equality case for Cauchy-Schwarz.\nCompare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma abs_inner_eq_norm_iff (x y : E) (hx0 : x \u2260 0) (hy0 : y \u2260 0):\n  abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225 \u2194 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x :=\nbegin\n  have hx0' : \u2225x\u2225 \u2260 0 := by simp [norm_eq_zero, hx0],\n  have hy0' : \u2225y\u2225 \u2260 0 := by simp [norm_eq_zero, hy0],\n  have hxy0 : \u2225x\u2225 * \u2225y\u2225 \u2260 0 := by simp [hx0', hy0'],\n  have h\u2081 : abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225 \u2194 abs (\u27eax, y\u27eb / (\u2225x\u2225 * \u2225y\u2225)) = 1,\n  { refine \u27e8_ ,_\u27e9,\n    { intro h,\n      norm_cast,\n      rw [is_R_or_C.abs_div, h, abs_of_real, _root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm],\n      exact div_self hxy0 },\n    { intro h,\n      norm_cast at h,\n      rwa [is_R_or_C.abs_div, abs_of_real, _root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm,\n          div_eq_one_iff_eq hxy0] at h } },\n  rw [h\u2081, abs_inner_div_norm_mul_norm_eq_one_iff x y],\n  have : x \u2260 0 := \u03bb h, (hx0' $ norm_eq_zero.mpr h),\n  simp [this]\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value 1 if and only if they are nonzero and one is\na positive multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), 0 < r \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrneg,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrneg) hr) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value -1 if and only if they are nonzero and one is\na negative multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225) = -1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r < 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrpos,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrpos) hr.symm) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx hr }\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma inner_eq_norm_mul_iff {x y : E} :\n  \u27eax, y\u27eb = (\u2225x\u2225 : \ud835\udd5c) * \u2225y\u2225 \u2194 (\u2225y\u2225 : \ud835\udd5c) \u2022 x = (\u2225x\u2225 : \ud835\udd5c) \u2022 y :=\nbegin\n  by_cases h : (x = 0 \u2228 y = 0), -- WLOG `x` and `y` are nonzero\n  { cases h; simp [h] },\n  calc \u27eax, y\u27eb = (\u2225x\u2225 : \ud835\udd5c) * \u2225y\u2225 \u2194 \u2225x\u2225 * \u2225y\u2225 = re \u27eax, y\u27eb :\n  begin\n    norm_cast,\n    split,\n    { intros h',\n      simp [h'] },\n    { have cauchy_schwarz := abs_inner_le_norm x y,\n      intros h',\n      rw h' at \u22a2 cauchy_schwarz,\n      rwa re_eq_self_of_le }\n  end\n  ... \u2194 2 * \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225 - re \u27eax, y\u27eb) = 0 :\n    by simp [h, show (2:\u211d) \u2260 0, by norm_num, sub_eq_zero]\n  ... \u2194 \u2225(\u2225y\u2225:\ud835\udd5c) \u2022 x - (\u2225x\u2225:\ud835\udd5c) \u2022 y\u2225 * \u2225(\u2225y\u2225:\ud835\udd5c) \u2022 x - (\u2225x\u2225:\ud835\udd5c) \u2022 y\u2225 = 0 :\n  begin\n    simp only [norm_sub_mul_self, inner_smul_left, inner_smul_right, norm_smul, conj_of_real,\n      is_R_or_C.norm_eq_abs, abs_of_real, of_real_im, of_real_re, mul_re, abs_norm_eq_norm],\n    refine eq.congr _ rfl,\n    ring\n  end\n  ... \u2194 (\u2225y\u2225 : \ud835\udd5c) \u2022 x = (\u2225x\u2225 : \ud835\udd5c) \u2022 y : by simp [norm_sub_eq_zero_iff]\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma inner_eq_norm_mul_iff_real {x y : F} : \u27eax, y\u27eb_\u211d = \u2225x\u2225 * \u2225y\u2225 \u2194 \u2225y\u2225 \u2022 x = \u2225x\u2225 \u2022 y :=\ninner_eq_norm_mul_iff\n\n/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of\nthe equality case for Cauchy-Schwarz. -/\nlemma inner_eq_norm_mul_iff_of_norm_one {x y : E} (hx : \u2225x\u2225 = 1) (hy : \u2225y\u2225 = 1) :\n  \u27eax, y\u27eb = 1 \u2194 x = y :=\nby { convert inner_eq_norm_mul_iff using 2; simp [hx, hy] }\n\nlemma inner_lt_norm_mul_iff_real {x y : F} :\n  \u27eax, y\u27eb_\u211d < \u2225x\u2225 * \u2225y\u2225 \u2194 \u2225y\u2225 \u2022 x \u2260 \u2225x\u2225 \u2022 y :=\ncalc \u27eax, y\u27eb_\u211d < \u2225x\u2225 * \u2225y\u2225\n    \u2194 \u27eax, y\u27eb_\u211d \u2260 \u2225x\u2225 * \u2225y\u2225 : \u27e8ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)\u27e9\n... \u2194 \u2225y\u2225 \u2022 x \u2260 \u2225x\u2225 \u2022 y : not_congr inner_eq_norm_mul_iff_real\n\n/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are\ndistinct. One form of the equality case for Cauchy-Schwarz. -/\nlemma inner_lt_one_iff_real_of_norm_one {x y : F} (hx : \u2225x\u2225 = 1) (hy : \u2225y\u2225 = 1) :\n  \u27eax, y\u27eb_\u211d < 1 \u2194 x \u2260 y :=\nby { convert inner_lt_norm_mul_iff_real; simp [hx, hy] }\n\n/-- The inner product of two weighted sums, where the weights in each\nsum add to 0, in terms of the norms of pairwise differences. -/\nlemma inner_sum_smul_sum_smul_of_sum_eq_zero {\u03b9\u2081 : Type*} {s\u2081 : finset \u03b9\u2081} {w\u2081 : \u03b9\u2081 \u2192 \u211d}\n    (v\u2081 : \u03b9\u2081 \u2192 F) (h\u2081 : \u2211 i in s\u2081, w\u2081 i = 0) {\u03b9\u2082 : Type*} {s\u2082 : finset \u03b9\u2082} {w\u2082 : \u03b9\u2082 \u2192 \u211d}\n    (v\u2082 : \u03b9\u2082 \u2192 F) (h\u2082 : \u2211 i in s\u2082, w\u2082 i = 0) :\n  \u27ea(\u2211 i\u2081 in s\u2081, w\u2081 i\u2081 \u2022 v\u2081 i\u2081), (\u2211 i\u2082 in s\u2082, w\u2082 i\u2082 \u2022 v\u2082 i\u2082)\u27eb_\u211d =\n    (-\u2211 i\u2081 in s\u2081, \u2211 i\u2082 in s\u2082, w\u2081 i\u2081 * w\u2082 i\u2082 * (\u2225v\u2081 i\u2081 - v\u2082 i\u2082\u2225 * \u2225v\u2081 i\u2081 - v\u2082 i\u2082\u2225)) / 2 :=\nby simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,\n            real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two,\n            \u2190div_sub_div_same, \u2190div_add_div_same, mul_sub_left_distrib, left_distrib,\n            finset.sum_sub_distrib, finset.sum_add_distrib, \u2190finset.mul_sum, \u2190finset.sum_mul,\n            h\u2081, h\u2082, zero_mul, mul_zero, finset.sum_const_zero, zero_add, zero_sub, finset.mul_sum,\n            neg_div, finset.sum_div, mul_div_assoc, mul_assoc]\n\n/-- The inner product with a fixed left element, as a continuous linear map.  This can be upgraded\nto a continuous map which is jointly conjugate-linear in the left argument and linear in the right\nargument, once (TODO) conjugate-linear maps have been defined. -/\ndef inner_right (v : E) : E \u2192L[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk_continuous\n  { to_fun := \u03bb w, \u27eav, w\u27eb,\n    map_add' := \u03bb x y, inner_add_right,\n    map_smul' := \u03bb c x, inner_smul_right }\n  \u2225v\u2225\n  (by simpa [is_R_or_C.norm_eq_abs] using abs_inner_le_norm v)\n\n@[simp] lemma inner_right_coe (v : E) : (inner_right v : E \u2192 \ud835\udd5c) = \u03bb w, \u27eav, w\u27eb := rfl\n\n@[simp] lemma inner_right_apply (v w : E) : inner_right v w = \u27eav, w\u27eb := rfl\n\nend norm\n\n/-! ### Inner product space structure on product spaces -/\n\n/-\n If `\u03b9` is a finite type and each space `f i`, `i : \u03b9`, is an inner product space,\nthen `\u03a0 i, f i` is an inner product space as well. Since `\u03a0 i, f i` is endowed with the sup norm,\nwe use instead `pi_Lp 2 one_le_two f` for the product space, which is endowed with the `L^2` norm.\n-/\ninstance pi_Lp.inner_product_space {\u03b9 : Type*} [fintype \u03b9] (f : \u03b9 \u2192 Type*)\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] : inner_product_space \ud835\udd5c (pi_Lp 2 one_le_two f) :=\n{ inner := \u03bb x y, \u2211 i, inner (x i) (y i),\n  norm_sq_eq_inner :=\n  begin\n    intro x,\n    have h\u2081 : \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u2115) = \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d),\n    { apply finset.sum_congr rfl,\n      intros j hj,\n      simp [\u2190rpow_nat_cast] },\n    have h\u2082 : 0 \u2264 \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d),\n    { rw [\u2190h\u2081],\n      exact finset.sum_nonneg (\u03bb j (hj : j \u2208 finset.univ), pow_nonneg (norm_nonneg (x j)) 2) },\n    simp [norm, add_monoid_hom.map_sum, \u2190norm_sq_eq_inner],\n    rw [\u2190rpow_nat_cast ((\u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d)) ^ (2 : \u211d)\u207b\u00b9) 2],\n    rw [\u2190rpow_mul h\u2082],\n    norm_num [h\u2081],\n  end,\n  conj_sym :=\n  begin\n    intros x y,\n    unfold inner,\n    rw [\u2190finset.sum_hom finset.univ conj],\n    apply finset.sum_congr rfl,\n    rintros z -,\n    apply inner_conj_sym,\n    apply_instance\n  end,\n  add_left := \u03bb x y z,\n    show \u2211 i, inner (x i + y i) (z i) = \u2211 i, inner (x i) (z i) + \u2211 i, inner (y i) (z i),\n    by simp only [inner_add_left, finset.sum_add_distrib],\n  smul_left := \u03bb x y r,\n    show \u2211 (i : \u03b9), inner (r \u2022 x i) (y i) = (conj r) * \u2211 i, inner (x i) (y i),\n    by simp only [finset.mul_sum, inner_smul_left]\n}\n\n@[simp] lemma pi_Lp.inner_apply {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 Type*}\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] (x y : pi_Lp 2 one_le_two f) :\n  \u27eax, y\u27eb = \u2211 i, \u27eax i, y i\u27eb :=\nrfl\n\nlemma pi_Lp.norm_eq_of_L2 {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 Type*}\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] (x : pi_Lp 2 one_le_two f) :\n  \u2225x\u2225 = sqrt (\u2211 (i : \u03b9), \u2225x i\u2225 ^ 2) :=\nby { rw [pi_Lp.norm_eq_of_nat 2]; simp [sqrt_eq_rpow] }\n\n/-- A field `\ud835\udd5c` satisfying `is_R_or_C` is itself a `\ud835\udd5c`-inner product space. -/\ninstance is_R_or_C.inner_product_space : inner_product_space \ud835\udd5c \ud835\udd5c :=\n{ inner := (\u03bb x y, (conj x) * y),\n  norm_sq_eq_inner := \u03bb x,\n    by { unfold inner, rw [mul_comm, mul_conj, of_real_re, norm_sq_eq_def'] },\n  conj_sym := \u03bb x y, by simp [mul_comm],\n  add_left := \u03bb x y z, by simp [inner, add_mul],\n  smul_left := \u03bb x y z, by simp [inner, mul_assoc] }\n\n@[simp] lemma is_R_or_C.inner_apply (x y : \ud835\udd5c) : \u27eax, y\u27eb = (conj x) * y := rfl\n\n/-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional\nspace use `euclidean_space \ud835\udd5c (fin n)`. -/\n@[reducible, nolint unused_arguments]\ndef euclidean_space (\ud835\udd5c : Type*) [is_R_or_C \ud835\udd5c]\n  (n : Type*) [fintype n] : Type* := pi_Lp 2 one_le_two (\u03bb (i : n), \ud835\udd5c)\n\nlemma euclidean_space.norm_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x : euclidean_space \ud835\udd5c n) : \u2225x\u2225 = real.sqrt (\u2211 (i : n), \u2225x i\u2225 ^ 2) :=\npi_Lp.norm_eq_of_L2 x\n\n/-! ### Inner product space structure on subspaces -/\n\n/-- Induced inner product on a submodule. -/\ninstance submodule.inner_product_space (W : submodule \ud835\udd5c E) : inner_product_space \ud835\udd5c W :=\n{ inner             := \u03bb x y, \u27ea(x:E), (y:E)\u27eb,\n  conj_sym          := \u03bb _ _, inner_conj_sym _ _ ,\n  norm_sq_eq_inner  := \u03bb _, norm_sq_eq_inner _,\n  add_left          := \u03bb _ _ _ , inner_add_left,\n  smul_left         := \u03bb _ _ _, inner_smul_left,\n  ..submodule.normed_space W }\n\n/-- The inner product on submodules is the same as on the ambient space. -/\n@[simp] lemma submodule.coe_inner (W : submodule \ud835\udd5c E) (x y : W) : \u27eax, y\u27eb = \u27ea(x:E), \u2191y\u27eb := rfl\n\nsection is_R_or_C_to_real\n\nvariables {G : Type*}\n\nvariables (\ud835\udd5c E)\ninclude \ud835\udd5c\n\n/-- A general inner product implies a real inner product. This is not registered as an instance\nsince it creates problems with the case `\ud835\udd5c = \u211d`. -/\ndef has_inner.is_R_or_C_to_real : has_inner \u211d E :=\n{ inner := \u03bb x y, re \u27eax, y\u27eb }\n\n/-- A general inner product space structure implies a real inner product structure. This is not\nregistered as an instance since it creates problems with the case `\ud835\udd5c = \u211d`, but in can be used in a\nproof to obtain a real inner product space structure from a given `\ud835\udd5c`-inner product space\nstructure. -/\ndef inner_product_space.is_R_or_C_to_real : inner_product_space \u211d E :=\n{ norm_sq_eq_inner := norm_sq_eq_inner,\n  conj_sym := \u03bb x y, inner_re_symm,\n  add_left := \u03bb x y z, by {\n    change re \u27eax + y, z\u27eb = re \u27eax, z\u27eb + re \u27eay, z\u27eb,\n    simp [inner_add_left] },\n  smul_left := \u03bb x y r, by {\n    change re \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r * re \u27eax, y\u27eb,\n    simp [inner_smul_left] },\n  ..has_inner.is_R_or_C_to_real \ud835\udd5c E,\n  ..normed_space.restrict_scalars \u211d \ud835\udd5c E }\n\nvariable {E}\n\nlemma real_inner_eq_re_inner (x y : E) :\n  @has_inner.inner \u211d E (has_inner.is_R_or_C_to_real \ud835\udd5c E) x y = re \u27eax, y\u27eb := rfl\n\nomit \ud835\udd5c\n\n/-- A complex inner product implies a real inner product -/\ninstance inner_product_space.complex_to_real [inner_product_space \u2102 G] : inner_product_space \u211d G :=\ninner_product_space.is_R_or_C_to_real \u2102 G\n\nend is_R_or_C_to_real\n\nsection deriv\n\n/-!\n### Derivative of the inner product\n\nIn this section we prove that the inner product and square of the norm in an inner space are\ninfinitely `\u211d`-smooth. In order to state these results, we need a `normed_space \u211d E`\ninstance. Though we can deduce this structure from `inner_product_space \ud835\udd5c E`, this instance may be\nnot definitionally equal to some other \u201cnatural\u201d instance. So, we assume `[normed_space \u211d E]` and\n`[is_scalar_tower \u211d \ud835\udd5c E]`. In both interesting cases `\ud835\udd5c = \u211d` and `\ud835\udd5c = \u2102` we have these instances.\n\n-/\n\nvariables [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E]\n\nlemma is_bounded_bilinear_map_inner : is_bounded_bilinear_map \u211d (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\n{ add_left := \u03bb _ _ _, inner_add_left,\n  smul_left := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r x, algebra_map_eq_of_real, inner_smul_real_left],\n  add_right := \u03bb _ _ _, inner_add_right,\n  smul_right := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r y, algebra_map_eq_of_real, inner_smul_real_right],\n  bound := \u27e81, zero_lt_one, \u03bb x y,\n    by { rw [one_mul, is_R_or_C.norm_eq_abs], exact abs_inner_le_norm x y, }\u27e9 }\n\n/-- Derivative of the inner product. -/\ndef fderiv_inner_clm (p : E \u00d7 E) : E \u00d7 E \u2192L[\u211d] \ud835\udd5c := is_bounded_bilinear_map_inner.deriv p\n\n@[simp] lemma fderiv_inner_clm_apply (p x : E \u00d7 E) :\n  fderiv_inner_clm  p x = \u27eap.1, x.2\u27eb + \u27eax.1, p.2\u27eb := rfl\n\nlemma times_cont_diff_inner {n} : times_cont_diff \u211d n (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\nis_bounded_bilinear_map_inner.times_cont_diff\n\nlemma times_cont_diff_at_inner {p : E \u00d7 E} {n} :\n  times_cont_diff_at \u211d n (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) p :=\ntimes_cont_diff_inner.times_cont_diff_at\n\nlemma differentiable_inner : differentiable \u211d (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\nis_bounded_bilinear_map_inner.differentiable_at\n\nvariables {G : Type*} [normed_group G] [normed_space \u211d G]\n  {f g : G \u2192 E} {f' g' : G \u2192L[\u211d] E} {s : set G} {x : G} {n : with_top \u2115}\n\ninclude \ud835\udd5c\n\nlemma times_cont_diff_within_at.inner (hf : times_cont_diff_within_at \u211d n f s x)\n  (hg : times_cont_diff_within_at \u211d n g s x) :\n  times_cont_diff_within_at \u211d n (\u03bb x, \u27eaf x, g x\u27eb) s x :=\ntimes_cont_diff_at_inner.comp_times_cont_diff_within_at x (hf.prod hg)\n\nlemma times_cont_diff_at.inner (hf : times_cont_diff_at \u211d n f x)\n  (hg : times_cont_diff_at \u211d n g x) :\n  times_cont_diff_at \u211d n (\u03bb x, \u27eaf x, g x\u27eb) x :=\nhf.inner hg\n\nlemma times_cont_diff_on.inner (hf : times_cont_diff_on \u211d n f s) (hg : times_cont_diff_on \u211d n g s) :\n  times_cont_diff_on \u211d n (\u03bb x, \u27eaf x, g x\u27eb) s :=\n\u03bb x hx, (hf x hx).inner (hg x hx)\n\nlemma times_cont_diff.inner (hf : times_cont_diff \u211d n f) (hg : times_cont_diff \u211d n g) :\n  times_cont_diff \u211d n (\u03bb x, \u27eaf x, g x\u27eb) :=\ntimes_cont_diff_inner.comp (hf.prod hg)\n\nlemma has_fderiv_within_at.inner (hf : has_fderiv_within_at f f' s x)\n  (hg : has_fderiv_within_at g g' s x) :\n  has_fderiv_within_at (\u03bb t, \u27eaf t, g t\u27eb) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') s x :=\n(is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp_has_fderiv_within_at x (hf.prod hg)\n\nlemma has_fderiv_at.inner (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :\n  has_fderiv_at (\u03bb t, \u27eaf t, g t\u27eb) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') x :=\n(is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp x (hf.prod hg)\n\nlemma has_deriv_within_at.inner {f g : \u211d \u2192 E} {f' g' : E} {s : set \u211d} {x : \u211d}\n  (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :\n  has_deriv_within_at (\u03bb t, \u27eaf t, g t\u27eb) (\u27eaf x, g'\u27eb + \u27eaf', g x\u27eb) s x :=\nby simpa using (hf.has_fderiv_within_at.inner hg.has_fderiv_within_at).has_deriv_within_at\n\nlemma has_deriv_at.inner {f g : \u211d \u2192 E} {f' g' : E} {x : \u211d} :\n  has_deriv_at f f' x \u2192  has_deriv_at g g' x \u2192\n  has_deriv_at (\u03bb t, \u27eaf t, g t\u27eb) (\u27eaf x, g'\u27eb + \u27eaf', g x\u27eb) x :=\nby simpa only [\u2190 has_deriv_within_at_univ] using has_deriv_within_at.inner\n\nlemma differentiable_within_at.inner (hf : differentiable_within_at \u211d f s x)\n  (hg : differentiable_within_at \u211d g s x) :\n  differentiable_within_at \u211d (\u03bb x, \u27eaf x, g x\u27eb) s x :=\n((differentiable_inner _).has_fderiv_at.comp_has_fderiv_within_at x\n  (hf.prod hg).has_fderiv_within_at).differentiable_within_at\n\nlemma differentiable_at.inner (hf : differentiable_at \u211d f x) (hg : differentiable_at \u211d g x) :\n  differentiable_at \u211d (\u03bb x, \u27eaf x, g x\u27eb) x :=\n(differentiable_inner _).comp x (hf.prod hg)\n\nlemma differentiable_on.inner (hf : differentiable_on \u211d f s) (hg : differentiable_on \u211d g s) :\n  differentiable_on \u211d (\u03bb x, \u27eaf x, g x\u27eb) s :=\n\u03bb x hx, (hf x hx).inner (hg x hx)\n\nlemma differentiable.inner (hf : differentiable \u211d f) (hg : differentiable \u211d g) :\n  differentiable \u211d (\u03bb x, \u27eaf x, g x\u27eb) :=\n\u03bb x, (hf x).inner (hg x)\n\nlemma fderiv_inner_apply (hf : differentiable_at \u211d f x) (hg : differentiable_at \u211d g x) (y : G) :\n  fderiv \u211d (\u03bb t, \u27eaf t, g t\u27eb) x y = \u27eaf x, fderiv \u211d g x y\u27eb + \u27eafderiv \u211d f x y, g x\u27eb :=\nby { rw [(hf.has_fderiv_at.inner hg.has_fderiv_at).fderiv], refl }\n\nlemma deriv_inner_apply {f g : \u211d \u2192 E} {x : \u211d} (hf : differentiable_at \u211d f x)\n  (hg : differentiable_at \u211d g x) :\n  deriv (\u03bb t, \u27eaf t, g t\u27eb) x = \u27eaf x, deriv g x\u27eb + \u27eaderiv f x, g x\u27eb :=\n(hf.has_deriv_at.inner hg.has_deriv_at).deriv\n\nlemma times_cont_diff_norm_sq : times_cont_diff \u211d n (\u03bb x : E, \u2225x\u2225 ^ 2) :=\nbegin\n  simp only [sq, \u2190 inner_self_eq_norm_sq],\n  exact (re_clm : \ud835\udd5c \u2192L[\u211d] \u211d).times_cont_diff.comp (times_cont_diff_id.inner times_cont_diff_id)\nend\n\nlemma times_cont_diff.norm_sq (hf : times_cont_diff \u211d n f) :\n  times_cont_diff \u211d n (\u03bb x, \u2225f x\u2225 ^ 2) :=\ntimes_cont_diff_norm_sq.comp hf\n\nlemma times_cont_diff_within_at.norm_sq (hf : times_cont_diff_within_at \u211d n f s x) :\n  times_cont_diff_within_at \u211d n (\u03bb y, \u2225f y\u2225 ^ 2) s x :=\ntimes_cont_diff_norm_sq.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\nlemma times_cont_diff_at.norm_sq (hf : times_cont_diff_at \u211d n f x) :\n  times_cont_diff_at \u211d n (\u03bb y, \u2225f y\u2225 ^ 2) x :=\nhf.norm_sq\n\nlemma times_cont_diff_at_norm {x : E} (hx : x \u2260 0) : times_cont_diff_at \u211d n norm x :=\nhave \u2225id x\u2225 ^ 2 \u2260 0, from pow_ne_zero _ (norm_pos_iff.2 hx).ne',\nby simpa only [id, sqrt_sq, norm_nonneg] using times_cont_diff_at_id.norm_sq.sqrt this\n\nlemma times_cont_diff_at.norm (hf : times_cont_diff_at \u211d n f x) (h0 : f x \u2260 0) :\n  times_cont_diff_at \u211d n (\u03bb y, \u2225f y\u2225) x :=\n(times_cont_diff_at_norm h0).comp x hf\n\nlemma times_cont_diff_at.dist (hf : times_cont_diff_at \u211d n f x) (hg : times_cont_diff_at \u211d n g x)\n  (hne : f x \u2260 g x) :\n  times_cont_diff_at \u211d n (\u03bb y, dist (f y) (g y)) x :=\nby { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) }\n\nlemma times_cont_diff_within_at.norm (hf : times_cont_diff_within_at \u211d n f s x) (h0 : f x \u2260 0) :\n  times_cont_diff_within_at \u211d n (\u03bb y, \u2225f y\u2225) s x :=\n(times_cont_diff_at_norm h0).comp_times_cont_diff_within_at x hf\n\nlemma times_cont_diff_within_at.dist (hf : times_cont_diff_within_at \u211d n f s x)\n  (hg : times_cont_diff_within_at \u211d n g s x) (hne : f x \u2260 g x) :\n  times_cont_diff_within_at \u211d n (\u03bb y, dist (f y) (g y)) s x :=\nby { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) }\n\nlemma times_cont_diff_on.norm_sq (hf : times_cont_diff_on \u211d n f s) :\n  times_cont_diff_on \u211d n (\u03bb y, \u2225f y\u2225 ^ 2) s :=\n(\u03bb x hx, (hf x hx).norm_sq)\n\nlemma times_cont_diff_on.norm (hf : times_cont_diff_on \u211d n f s) (h0 : \u2200 x \u2208 s, f x \u2260 0) :\n  times_cont_diff_on \u211d n (\u03bb y, \u2225f y\u2225) s :=\n\u03bb x hx, (hf x hx).norm (h0 x hx)\n\nlemma times_cont_diff_on.dist (hf : times_cont_diff_on \u211d n f s)\n  (hg : times_cont_diff_on \u211d n g s) (hne : \u2200 x \u2208 s, f x \u2260 g x) :\n  times_cont_diff_on \u211d n (\u03bb y, dist (f y) (g y)) s :=\n\u03bb x hx, (hf x hx).dist (hg x hx) (hne x hx)\n\nlemma times_cont_diff.norm (hf : times_cont_diff \u211d n f) (h0 : \u2200 x, f x \u2260 0) :\n  times_cont_diff \u211d n (\u03bb y, \u2225f y\u2225) :=\ntimes_cont_diff_iff_times_cont_diff_at.2 $ \u03bb x, hf.times_cont_diff_at.norm (h0 x)\n\nlemma times_cont_diff.dist (hf : times_cont_diff \u211d n f) (hg : times_cont_diff \u211d n g)\n  (hne : \u2200 x, f x \u2260 g x) :\n  times_cont_diff \u211d n (\u03bb y, dist (f y) (g y)) :=\ntimes_cont_diff_iff_times_cont_diff_at.2 $\n  \u03bb x, hf.times_cont_diff_at.dist hg.times_cont_diff_at (hne x)\n\nlemma differentiable_at.norm_sq (hf : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bb y, \u2225f y\u2225 ^ 2) x :=\n(times_cont_diff_at_id.norm_sq.differentiable_at le_rfl).comp x hf\n\nlemma differentiable_at.norm (hf : differentiable_at \u211d f x) (h0 : f x \u2260 0) :\n  differentiable_at \u211d (\u03bb y, \u2225f y\u2225) x :=\n((times_cont_diff_at_norm h0).differentiable_at le_rfl).comp x hf\n\nlemma differentiable_at.dist (hf : differentiable_at \u211d f x) (hg : differentiable_at \u211d g x)\n  (hne : f x \u2260 g x) :\n  differentiable_at \u211d (\u03bb y, dist (f y) (g y)) x :=\nby { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) }\n\nlemma differentiable.norm_sq (hf : differentiable \u211d f) : differentiable \u211d (\u03bb y, \u2225f y\u2225 ^ 2) :=\n\u03bb x, (hf x).norm_sq\n\nlemma differentiable.norm (hf : differentiable \u211d f) (h0 : \u2200 x, f x \u2260 0) :\n  differentiable \u211d (\u03bb y, \u2225f y\u2225) :=\n\u03bb x, (hf x).norm (h0 x)\n\nlemma differentiable.dist (hf : differentiable \u211d f) (hg : differentiable \u211d g)\n  (hne : \u2200 x, f x \u2260 g x) :\n  differentiable \u211d (\u03bb y, dist (f y) (g y)) :=\n\u03bb x, (hf x).dist (hg x) (hne x)\n\nlemma differentiable_within_at.norm_sq (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb y, \u2225f y\u2225 ^ 2) s x :=\n(times_cont_diff_at_id.norm_sq.differentiable_at le_rfl).comp_differentiable_within_at x hf\n\nlemma differentiable_within_at.norm (hf : differentiable_within_at \u211d f s x) (h0 : f x \u2260 0) :\n  differentiable_within_at \u211d (\u03bb y, \u2225f y\u2225) s x :=\n((times_cont_diff_at_id.norm h0).differentiable_at le_rfl).comp_differentiable_within_at x hf\n\nlemma differentiable_within_at.dist (hf : differentiable_within_at \u211d f s x)\n  (hg : differentiable_within_at \u211d g s x) (hne : f x \u2260 g x) :\n  differentiable_within_at \u211d (\u03bb y, dist (f y) (g y)) s x :=\nby { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) }\n\nlemma differentiable_on.norm_sq (hf : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bb y, \u2225f y\u2225 ^ 2) s :=\n\u03bb x hx, (hf x hx).norm_sq\n\nlemma differentiable_on.norm (hf : differentiable_on \u211d f s) (h0 : \u2200 x \u2208 s, f x \u2260 0) :\n  differentiable_on \u211d (\u03bb y, \u2225f y\u2225) s :=\n\u03bb x hx, (hf x hx).norm (h0 x hx)\n\nlemma differentiable_on.dist (hf : differentiable_on \u211d f s) (hg : differentiable_on \u211d g s)\n  (hne : \u2200 x \u2208 s, f x \u2260 g x) :\n  differentiable_on \u211d (\u03bb y, dist (f y) (g y)) s :=\n\u03bb x hx, (hf x hx).dist (hg x hx) (hne x hx)\n\nend deriv\n\nsection continuous\n\n/-!\n### Continuity and measurability of the inner product\n\nSince the inner product is `\u211d`-smooth, it is continuous. We do not need a `[normed_space \u211d E]`\nstructure to *state* this fact and its corollaries, so we introduce them in the proof instead.\n-/\n\nlemma continuous_inner : continuous (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\nbegin\n  letI : inner_product_space \u211d E := inner_product_space.is_R_or_C_to_real \ud835\udd5c E,\n  letI : is_scalar_tower \u211d \ud835\udd5c E := restrict_scalars.is_scalar_tower _ _ _,\n  exact differentiable_inner.continuous\nend\n\nvariables {\u03b1 : Type*}\n\nlemma filter.tendsto.inner {f g : \u03b1 \u2192 E} {l : filter \u03b1} {x y : E} (hf : tendsto f l (\ud835\udcdd x))\n  (hg : tendsto g l (\ud835\udcdd y)) :\n  tendsto (\u03bb t, \u27eaf t, g t\u27eb) l (\ud835\udcdd \u27eax, y\u27eb) :=\n(continuous_inner.tendsto _).comp (hf.prod_mk_nhds hg)\n\nlemma measurable.inner [measurable_space \u03b1] [measurable_space E] [opens_measurable_space E]\n  [topological_space.second_countable_topology E] [measurable_space \ud835\udd5c] [borel_space \ud835\udd5c]\n  {f g : \u03b1 \u2192 E} (hf : measurable f) (hg : measurable g) :\n  measurable (\u03bb t, \u27eaf t, g t\u27eb) :=\ncontinuous.measurable2 continuous_inner hf hg\n\nlemma ae_measurable.inner [measurable_space \u03b1] [measurable_space E] [opens_measurable_space E]\n  [topological_space.second_countable_topology E] [measurable_space \ud835\udd5c] [borel_space \ud835\udd5c]\n  {\u03bc : measure_theory.measure \u03b1} {f g : \u03b1 \u2192 E} (hf : ae_measurable f \u03bc) (hg : ae_measurable g \u03bc) :\n  ae_measurable (\u03bb x, \u27eaf x, g x\u27eb) \u03bc :=\nbegin\n  refine \u27e8\u03bb x, \u27eahf.mk f x, hg.mk g x\u27eb, hf.measurable_mk.inner hg.measurable_mk, _\u27e9,\n  refine hf.ae_eq_mk.mp (hg.ae_eq_mk.mono (\u03bb x hxg hxf, _)),\n  dsimp only,\n  congr,\n  { exact hxf, },\n  { exact hxg, },\nend\n\nvariables [topological_space \u03b1] {f g : \u03b1 \u2192 E} {x : \u03b1} {s : set \u03b1}\n\ninclude \ud835\udd5c\n\nlemma continuous_within_at.inner (hf : continuous_within_at f s x)\n  (hg : continuous_within_at g s x) :\n  continuous_within_at (\u03bb t, \u27eaf t, g t\u27eb) s x :=\nhf.inner hg\n\nlemma continuous_at.inner (hf : continuous_at f x) (hg : continuous_at g x) :\n  continuous_at (\u03bb t, \u27eaf t, g t\u27eb) x :=\nhf.inner hg\n\nlemma continuous_on.inner (hf : continuous_on f s) (hg : continuous_on g s) :\n  continuous_on (\u03bb t, \u27eaf t, g t\u27eb) s :=\n\u03bb x hx, (hf x hx).inner (hg x hx)\n\nlemma continuous.inner (hf : continuous f) (hg : continuous g) : continuous (\u03bb t, \u27eaf t, g t\u27eb) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, hf.continuous_at.inner hg.continuous_at\n\nend continuous\n\nsection pi_Lp\nlocal attribute [reducible] pi_Lp\nvariables {\u03b9 : Type*} [fintype \u03b9]\n\ninstance : finite_dimensional \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\ninstance : inner_product_space \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\n\n@[simp] lemma finrank_euclidean_space :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) = fintype.card \u03b9 := by simp\n\nlemma finrank_euclidean_space_fin {n : \u2115} :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c (fin n)) = n := by simp\n\n/-- An orthonormal basis on a fintype `\u03b9` for an inner product space induces an isometry with\n`euclidean_space \ud835\udd5c \u03b9`. -/\ndef is_basis.isometry_euclidean_of_orthonormal\n  {v : \u03b9 \u2192 E} (h : is_basis \ud835\udd5c v) (hv : orthonormal \ud835\udd5c v) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c \u03b9) :=\nh.equiv_fun.isometry_of_inner\nbegin\n  intros x y,\n  let p : euclidean_space \ud835\udd5c \u03b9 := h.equiv_fun x,\n  let q : euclidean_space \ud835\udd5c \u03b9 := h.equiv_fun y,\n  have key : \u27eap, q\u27eb = \u27ea\u2211 i, p i \u2022 v i, \u2211 i, q i \u2022 v i\u27eb,\n  { simp [sum_inner, inner_smul_left, hv.inner_right_fintype] },\n  convert key,\n  { rw [\u2190 h.equiv_fun.symm_apply_apply x, h.equiv_fun_symm_apply] },\n  { rw [\u2190 h.equiv_fun.symm_apply_apply y, h.equiv_fun_symm_apply] }\nend\n\n/-- `\u2102` is isometric to \u211d\u00b2 with the Euclidean inner product. -/\ndef complex.isometry_euclidean : \u2102 \u2243\u2097\u1d62[\u211d] (euclidean_space \u211d (fin 2)) :=\ncomplex.is_basis_one_I.isometry_euclidean_of_orthonormal\nbegin\n  rw orthonormal_iff_ite,\n  intros i, fin_cases i;\n  intros j; fin_cases j;\n  simp [real_inner_eq_re_inner]\nend\n\n@[simp] lemma complex.isometry_euclidean_symm_apply (x : euclidean_space \u211d (fin 2)) :\n  complex.isometry_euclidean.symm x = (x 0) + (x 1) * I :=\nbegin\n  convert complex.is_basis_one_I.equiv_fun_symm_apply x,\n  { simpa },\n  { simp },\nend\n\nlemma complex.isometry_euclidean_proj_eq_self (z : \u2102) :\n  \u2191(complex.isometry_euclidean z 0) + \u2191(complex.isometry_euclidean z 1) * (I : \u2102) = z :=\nby rw [\u2190 complex.isometry_euclidean_symm_apply (complex.isometry_euclidean z),\n  complex.isometry_euclidean.symm_apply_apply z]\n\n@[simp] lemma complex.isometry_euclidean_apply_zero (z : \u2102) :\n  complex.isometry_euclidean z 0 = z.re :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\n@[simp] lemma complex.isometry_euclidean_apply_one (z : \u2102) :\n  complex.isometry_euclidean z 1 = z.im :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\nend pi_Lp\n\n\n/-! ### Orthogonal projection in inner product spaces -/\n\nsection orthogonal\n\nopen filter\n\n/--\nExistence of minimizers\nLet `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.\nThen there exists a (unique) `v` in `K` that minimizes the distance `\u2225u - v\u2225` to `u`.\n -/\n-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`\n-- It should be broken in a sequence of more manageable pieces,\n-- perhaps with individual statements for the three steps below.\ntheorem exists_norm_eq_infi_of_complete_convex {K : set F} (ne : K.nonempty) (h\u2081 : is_complete K)\n  (h\u2082 : convex K) : \u2200 u : F, \u2203 v \u2208 K, \u2225u - v\u2225 = \u2a05 w : K, \u2225u - w\u2225 := assume u,\nbegin\n  let \u03b4 := \u2a05 w : K, \u2225u - w\u2225,\n  letI : nonempty K := ne.to_subtype,\n  have zero_le_\u03b4 : 0 \u2264 \u03b4 := le_cinfi (\u03bb _, norm_nonneg _),\n  have \u03b4_le : \u2200 w : K, \u03b4 \u2264 \u2225u - w\u2225,\n    from cinfi_le \u27e80, set.forall_range_iff.2 $ \u03bb _, norm_nonneg _\u27e9,\n  have \u03b4_le' : \u2200 w \u2208 K, \u03b4 \u2264 \u2225u - w\u2225 := assume w hw, \u03b4_le \u27e8w, hw\u27e9,\n  -- Step 1: since `\u03b4` is the infimum, can find a sequence `w : \u2115 \u2192 K` in `K`\n  -- such that `\u2225u - w n\u2225 < \u03b4 + 1 / (n + 1)` (which implies `\u2225u - w n\u2225 --> \u03b4`);\n  -- maybe this should be a separate lemma\n  have exists_seq : \u2203 w : \u2115 \u2192 K, \u2200 n, \u2225u - w n\u2225 < \u03b4 + 1 / (n + 1),\n  { have h\u03b4 : \u2200n:\u2115, \u03b4 < \u03b4 + 1 / (n + 1), from\n      \u03bb n, lt_add_of_le_of_pos (le_refl _) nat.one_div_pos_of_nat,\n    have h := \u03bb n, exists_lt_of_cinfi_lt (h\u03b4 n),\n    let w : \u2115 \u2192 K := \u03bb n, classical.some (h n),\n    exact \u27e8w, \u03bb n, classical.some_spec (h n)\u27e9 },\n  rcases exists_seq with \u27e8w, hw\u27e9,\n  have norm_tendsto : tendsto (\u03bb n, \u2225u - w n\u2225) at_top (nhds \u03b4),\n  { have h : tendsto (\u03bb n:\u2115, \u03b4) at_top (nhds \u03b4) := tendsto_const_nhds,\n    have h' : tendsto (\u03bb n:\u2115, \u03b4 + 1 / (n + 1)) at_top (nhds \u03b4),\n    { convert h.add tendsto_one_div_add_at_top_nhds_0_nat, simp only [add_zero] },\n    exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h'\n      (\u03bb x, \u03b4_le _) (\u03bb x, le_of_lt (hw _)) },\n  -- Step 2: Prove that the sequence `w : \u2115 \u2192 K` is a Cauchy sequence\n  have seq_is_cauchy : cauchy_seq (\u03bb n, ((w n):F)),\n  { rw cauchy_seq_iff_le_tendsto_0, -- splits into three goals\n    let b := \u03bb n:\u2115, (8 * \u03b4 * (1/(n+1)) + 4 * (1/(n+1)) * (1/(n+1))),\n    use (\u03bbn, sqrt (b n)),\n    split,\n    -- first goal :  `\u2200 (n : \u2115), 0 \u2264 sqrt (b n)`\n    assume n, exact sqrt_nonneg _,\n    split,\n    -- second goal : `\u2200 (n m N : \u2115), N \u2264 n \u2192 N \u2264 m \u2192 dist \u2191(w n) \u2191(w m) \u2264 sqrt (b N)`\n    assume p q N hp hq,\n    let wp := ((w p):F), let wq := ((w q):F),\n    let a := u - wq, let b := u - wp,\n    let half := 1 / (2:\u211d), let div := 1 / ((N:\u211d) + 1),\n    have : 4 * \u2225u - half \u2022 (wq + wp)\u2225 * \u2225u - half \u2022 (wq + wp)\u2225 + \u2225wp - wq\u2225 * \u2225wp - wq\u2225 =\n      2 * (\u2225a\u2225 * \u2225a\u2225 + \u2225b\u2225 * \u2225b\u2225) :=\n    calc\n      4 * \u2225u - half\u2022(wq + wp)\u2225 * \u2225u - half\u2022(wq + wp)\u2225 + \u2225wp - wq\u2225 * \u2225wp - wq\u2225\n          = (2*\u2225u - half\u2022(wq + wp)\u2225) * (2 * \u2225u - half\u2022(wq + wp)\u2225) + \u2225wp-wq\u2225*\u2225wp-wq\u2225 : by ring\n      ... = (absR ((2:\u211d)) * \u2225u - half\u2022(wq + wp)\u2225) * (absR ((2:\u211d)) * \u2225u - half\u2022(wq+wp)\u2225) +\n            \u2225wp-wq\u2225*\u2225wp-wq\u2225 :\n      by { rw _root_.abs_of_nonneg, exact zero_le_two }\n      ... = \u2225(2:\u211d) \u2022 (u - half \u2022 (wq + wp))\u2225 * \u2225(2:\u211d) \u2022 (u - half \u2022 (wq + wp))\u2225 +\n            \u2225wp-wq\u2225 * \u2225wp-wq\u2225 :\n      by simp [norm_smul]\n      ... = \u2225a + b\u2225 * \u2225a + b\u2225 + \u2225a - b\u2225 * \u2225a - b\u2225 :\n      begin\n        rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : \u211d) \u2260 0),\n            \u2190 one_add_one_eq_two, add_smul],\n        simp only [one_smul],\n        have eq\u2081 : wp - wq = a - b, from (sub_sub_sub_cancel_left _ _ _).symm,\n        have eq\u2082 : u + u - (wq + wp) = a + b, show u + u - (wq + wp) = (u - wq) + (u - wp), abel,\n        rw [eq\u2081, eq\u2082],\n      end\n      ... = 2 * (\u2225a\u2225 * \u2225a\u2225 + \u2225b\u2225 * \u2225b\u2225) : parallelogram_law_with_norm,\n    have eq : \u03b4 \u2264 \u2225u - half \u2022 (wq + wp)\u2225,\n    { rw smul_add,\n      apply \u03b4_le', apply h\u2082,\n        repeat {exact subtype.mem _},\n        repeat {exact le_of_lt one_half_pos},\n        exact add_halves 1 },\n    have eq\u2081 : 4 * \u03b4 * \u03b4 \u2264 4 * \u2225u - half \u2022 (wq + wp)\u2225 * \u2225u - half \u2022 (wq + wp)\u2225,\n    {  mono, mono, norm_num, apply mul_nonneg, norm_num, exact norm_nonneg _ },\n    have eq\u2082 : \u2225a\u2225 * \u2225a\u2225 \u2264 (\u03b4 + div) * (\u03b4 + div) :=\n      mul_self_le_mul_self (norm_nonneg _)\n        (le_trans (le_of_lt $ hw q) (add_le_add_left (nat.one_div_le_one_div hq) _)),\n    have eq\u2082' : \u2225b\u2225 * \u2225b\u2225 \u2264 (\u03b4 + div) * (\u03b4 + div) :=\n      mul_self_le_mul_self (norm_nonneg _)\n        (le_trans (le_of_lt $ hw p) (add_le_add_left (nat.one_div_le_one_div hp) _)),\n    rw dist_eq_norm,\n    apply nonneg_le_nonneg_of_sq_le_sq, { exact sqrt_nonneg _ },\n    rw mul_self_sqrt,\n    exact calc\n      \u2225wp - wq\u2225 * \u2225wp - wq\u2225 = 2 * (\u2225a\u2225*\u2225a\u2225 + \u2225b\u2225*\u2225b\u2225) -\n        4 * \u2225u - half \u2022 (wq+wp)\u2225 * \u2225u - half \u2022 (wq+wp)\u2225 : by { rw \u2190 this, simp }\n      ... \u2264 2 * (\u2225a\u2225 * \u2225a\u2225 + \u2225b\u2225 * \u2225b\u2225) - 4 * \u03b4 * \u03b4 : sub_le_sub_left eq\u2081 _\n      ... \u2264 2 * ((\u03b4 + div) * (\u03b4 + div) + (\u03b4 + div) * (\u03b4 + div)) - 4 * \u03b4 * \u03b4 :\n        sub_le_sub_right (mul_le_mul_of_nonneg_left (add_le_add eq\u2082 eq\u2082') (by norm_num)) _\n      ... = 8 * \u03b4 * div + 4 * div * div : by ring,\n    exact add_nonneg\n      (mul_nonneg (mul_nonneg (by norm_num) zero_le_\u03b4) (le_of_lt nat.one_div_pos_of_nat))\n      (mul_nonneg (mul_nonneg (by norm_num) nat.one_div_pos_of_nat.le) nat.one_div_pos_of_nat.le),\n    -- third goal : `tendsto (\u03bb (n : \u2115), sqrt (b n)) at_top (\ud835\udcdd 0)`\n    apply tendsto.comp,\n    { convert continuous_sqrt.continuous_at, exact sqrt_zero.symm },\n    have eq\u2081 : tendsto (\u03bb (n : \u2115), 8 * \u03b4 * (1 / (n + 1))) at_top (nhds (0:\u211d)),\n    { convert (@tendsto_const_nhds _ _ _ (8 * \u03b4) _).mul tendsto_one_div_add_at_top_nhds_0_nat,\n      simp only [mul_zero] },\n    have : tendsto (\u03bb (n : \u2115), (4:\u211d) * (1 / (n + 1))) at_top (nhds (0:\u211d)),\n    { convert (@tendsto_const_nhds _ _ _ (4:\u211d) _).mul tendsto_one_div_add_at_top_nhds_0_nat,\n      simp only [mul_zero] },\n    have eq\u2082 : tendsto (\u03bb (n : \u2115), (4:\u211d) * (1 / (n + 1)) * (1 / (n + 1))) at_top (nhds (0:\u211d)),\n    { convert this.mul tendsto_one_div_add_at_top_nhds_0_nat,\n      simp only [mul_zero] },\n    convert eq\u2081.add eq\u2082, simp only [add_zero] },\n  -- Step 3: By completeness of `K`, let `w : \u2115 \u2192 K` converge to some `v : K`.\n  -- Prove that it satisfies all requirements.\n  rcases cauchy_seq_tendsto_of_is_complete h\u2081 (\u03bb n, _) seq_is_cauchy with \u27e8v, hv, w_tendsto\u27e9,\n  use v, use hv,\n  have h_cont : continuous (\u03bb v, \u2225u - v\u2225) :=\n    continuous.comp continuous_norm (continuous.sub continuous_const continuous_id),\n  have : tendsto (\u03bb n, \u2225u - w n\u2225) at_top (nhds \u2225u - v\u2225),\n    convert (tendsto.comp h_cont.continuous_at w_tendsto),\n  exact tendsto_nhds_unique this norm_tendsto,\n  exact subtype.mem _\nend\n\n/-- Characterization of minimizers for the projection on a convex set in a real inner product\nspace. -/\ntheorem norm_eq_infi_iff_real_inner_le_zero {K : set F} (h : convex K) {u : F} {v : F}\n  (hv : v \u2208 K) : \u2225u - v\u2225 = (\u2a05 w : K, \u2225u - w\u2225) \u2194 \u2200 w \u2208 K, \u27eau - v, w - v\u27eb_\u211d \u2264 0 :=\niff.intro\nbegin\n  assume eq w hw,\n  let \u03b4 := \u2a05 w : K, \u2225u - w\u2225, let p := \u27eau - v, w - v\u27eb_\u211d, let q := \u2225w - v\u2225^2,\n  letI : nonempty K := \u27e8\u27e8v, hv\u27e9\u27e9,\n  have zero_le_\u03b4 : 0 \u2264 \u03b4,\n    apply le_cinfi, intro, exact norm_nonneg _,\n  have \u03b4_le : \u2200 w : K, \u03b4 \u2264 \u2225u - w\u2225,\n    assume w, apply cinfi_le, use (0:\u211d), rintros _ \u27e8_, rfl\u27e9, exact norm_nonneg _,\n  have \u03b4_le' : \u2200 w \u2208 K, \u03b4 \u2264 \u2225u - w\u2225 := assume w hw, \u03b4_le \u27e8w, hw\u27e9,\n  have : \u2200\u03b8:\u211d, 0 < \u03b8 \u2192 \u03b8 \u2264 1 \u2192 2 * p \u2264 \u03b8 * q,\n    assume \u03b8 h\u03b8\u2081 h\u03b8\u2082,\n    have : \u2225u - v\u2225^2 \u2264 \u2225u - v\u2225^2 - 2 * \u03b8 * \u27eau - v, w - v\u27eb_\u211d + \u03b8*\u03b8*\u2225w - v\u2225^2 :=\n    calc\n      \u2225u - v\u2225^2 \u2264 \u2225u - (\u03b8\u2022w + (1-\u03b8)\u2022v)\u2225^2 :\n      begin\n        simp only [sq], apply mul_self_le_mul_self (norm_nonneg _),\n        rw [eq], apply \u03b4_le',\n        apply h hw hv,\n        exacts [le_of_lt h\u03b8\u2081, sub_nonneg.2 h\u03b8\u2082, add_sub_cancel'_right _ _],\n      end\n      ... = \u2225(u - v) - \u03b8 \u2022 (w - v)\u2225^2 :\n      begin\n        have : u - (\u03b8\u2022w + (1-\u03b8)\u2022v) = (u - v) - \u03b8 \u2022 (w - v),\n        { rw [smul_sub, sub_smul, one_smul],\n          simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] },\n        rw this\n      end\n      ... = \u2225u - v\u2225^2 - 2 * \u03b8 * inner (u - v) (w - v) + \u03b8*\u03b8*\u2225w - v\u2225^2 :\n      begin\n        rw [norm_sub_sq, inner_smul_right, norm_smul],\n        simp only [sq],\n        show \u2225u-v\u2225*\u2225u-v\u2225-2*(\u03b8*inner(u-v)(w-v))+absR (\u03b8)*\u2225w-v\u2225*(absR (\u03b8)*\u2225w-v\u2225)=\n                \u2225u-v\u2225*\u2225u-v\u2225-2*\u03b8*inner(u-v)(w-v)+\u03b8*\u03b8*(\u2225w-v\u2225*\u2225w-v\u2225),\n        rw abs_of_pos h\u03b8\u2081, ring\n      end,\n    have eq\u2081 : \u2225u-v\u2225^2-2*\u03b8*inner(u-v)(w-v)+\u03b8*\u03b8*\u2225w-v\u2225^2=\u2225u-v\u2225^2+(\u03b8*\u03b8*\u2225w-v\u2225^2-2*\u03b8*inner(u-v)(w-v)),\n      by abel,\n    rw [eq\u2081, le_add_iff_nonneg_right] at this,\n    have eq\u2082 : \u03b8*\u03b8*\u2225w-v\u2225^2-2*\u03b8*inner(u-v)(w-v)=\u03b8*(\u03b8*\u2225w-v\u2225^2-2*inner(u-v)(w-v)), ring,\n    rw eq\u2082 at this,\n    have := le_of_sub_nonneg (nonneg_of_mul_nonneg_left this h\u03b8\u2081),\n    exact this,\n  by_cases hq : q = 0,\n  { rw hq at this,\n    have : p \u2264 0,\n      have := this (1:\u211d) (by norm_num) (by norm_num),\n      linarith,\n    exact this },\n  { have q_pos : 0 < q,\n      apply lt_of_le_of_ne, exact sq_nonneg _, intro h, exact hq h.symm,\n    by_contradiction hp, rw not_le at hp,\n    let \u03b8 := min (1:\u211d) (p / q),\n    have eq\u2081 : \u03b8*q \u2264 p := calc\n      \u03b8*q \u2264 (p/q) * q : mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _)\n      ... = p : div_mul_cancel _ hq,\n    have : 2 * p \u2264 p := calc\n      2 * p \u2264 \u03b8*q : by { refine this \u03b8 (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num) }\n      ... \u2264 p : eq\u2081,\n    linarith }\nend\nbegin\n  assume h,\n  letI : nonempty K := \u27e8\u27e8v, hv\u27e9\u27e9,\n  apply le_antisymm,\n  { apply le_cinfi, assume w,\n    apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _),\n    have := h w w.2,\n    exact calc\n      \u2225u - v\u2225 * \u2225u - v\u2225 \u2264 \u2225u - v\u2225 * \u2225u - v\u2225 - 2 * inner (u - v) ((w:F) - v) : by linarith\n      ... \u2264 \u2225u - v\u2225^2 - 2 * inner (u - v) ((w:F) - v) + \u2225(w:F) - v\u2225^2 :\n        by { rw sq, refine le_add_of_nonneg_right _, exact sq_nonneg _ }\n      ... = \u2225(u - v) - (w - v)\u2225^2 : norm_sub_sq.symm\n      ... = \u2225u - w\u2225 * \u2225u - w\u2225 :\n        by { have : (u - v) - (w - v) = u - w, abel, rw [this, sq] } },\n  { show (\u2a05 (w : K), \u2225u - w\u2225) \u2264 (\u03bbw:K, \u2225u - w\u2225) \u27e8v, hv\u27e9,\n      apply cinfi_le, use 0, rintros y \u27e8z, rfl\u27e9, exact norm_nonneg _ }\nend\n\nvariables (K : submodule \ud835\udd5c E)\n\n/--\nExistence of projections on complete subspaces.\nLet `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.\nThen there exists a (unique) `v` in `K` that minimizes the distance `\u2225u - v\u2225` to `u`.\nThis point `v` is usually called the orthogonal projection of `u` onto `K`.\n-/\ntheorem exists_norm_eq_infi_of_complete_subspace\n  (h : is_complete (\u2191K : set E)) : \u2200 u : E, \u2203 v \u2208 K, \u2225u - v\u2225 = \u2a05 w : (K : set E), \u2225u - w\u2225 :=\nbegin\n  letI : inner_product_space \u211d E := inner_product_space.is_R_or_C_to_real \ud835\udd5c E,\n  letI : module \u211d E := restrict_scalars.module \u211d \ud835\udd5c E,\n  letI : is_scalar_tower \u211d \ud835\udd5c E := restrict_scalars.is_scalar_tower _ _ _,\n  let K' : submodule \u211d E := submodule.restrict_scalars \u211d K,\n  exact exists_norm_eq_infi_of_complete_convex \u27e80, K'.zero_mem\u27e9 h K'.convex\nend\n\n/--\nCharacterization of minimizers in the projection on a subspace, in the real case.\nLet `u` be a point in a real inner product space, and let `K` be a nonempty subspace.\nThen point `v` minimizes the distance `\u2225u - v\u2225` over points in `K` if and only if\nfor all `w \u2208 K`, `\u27eau - v, w\u27eb = 0` (i.e., `u - v` is orthogonal to the subspace `K`).\nThis is superceded by `norm_eq_infi_iff_inner_eq_zero` that gives the same conclusion over\nany `is_R_or_C` field.\n-/\ntheorem norm_eq_infi_iff_real_inner_eq_zero (K : submodule \u211d F) {u : F} {v : F}\n  (hv : v \u2208 K) : \u2225u - v\u2225 = (\u2a05 w : (\u2191K : set F), \u2225u - w\u2225) \u2194 \u2200 w \u2208 K, \u27eau - v, w\u27eb_\u211d = 0 :=\niff.intro\nbegin\n  assume h,\n  have h : \u2200 w \u2208 K, \u27eau - v, w - v\u27eb_\u211d \u2264 0,\n  { rwa [norm_eq_infi_iff_real_inner_le_zero] at h, exacts [K.convex, hv] },\n  assume w hw,\n  have le : \u27eau - v, w\u27eb_\u211d \u2264 0,\n    let w' := w + v,\n    have : w' \u2208 K := submodule.add_mem _ hw hv,\n    have h\u2081 := h w' this,\n    have h\u2082 : w' - v = w, simp only [add_neg_cancel_right, sub_eq_add_neg],\n    rw h\u2082 at h\u2081, exact h\u2081,\n  have ge : \u27eau - v, w\u27eb_\u211d \u2265 0,\n    let w'' := -w + v,\n    have : w'' \u2208 K := submodule.add_mem _ (submodule.neg_mem _ hw) hv,\n    have h\u2081 := h w'' this,\n    have h\u2082 : w'' - v = -w, simp only [neg_inj, add_neg_cancel_right, sub_eq_add_neg],\n    rw [h\u2082, inner_neg_right] at h\u2081,\n    linarith,\n    exact le_antisymm le ge\nend\nbegin\n  assume h,\n  have : \u2200 w \u2208 K, \u27eau - v, w - v\u27eb_\u211d \u2264 0,\n    assume w hw,\n    let w' := w - v,\n    have : w' \u2208 K := submodule.sub_mem _ hw hv,\n    have h\u2081 := h w' this,\n    exact le_of_eq h\u2081,\n  rwa norm_eq_infi_iff_real_inner_le_zero,\n  exacts [submodule.convex _, hv]\nend\n\n/--\nCharacterization of minimizers in the projection on a subspace.\nLet `u` be a point in an inner product space, and let `K` be a nonempty subspace.\nThen point `v` minimizes the distance `\u2225u - v\u2225` over points in `K` if and only if\nfor all `w \u2208 K`, `\u27eau - v, w\u27eb = 0` (i.e., `u - v` is orthogonal to the subspace `K`)\n-/\ntheorem norm_eq_infi_iff_inner_eq_zero {u : E} {v : E}\n  (hv : v \u2208 K) : \u2225u - v\u2225 = (\u2a05 w : (\u2191K : set E), \u2225u - w\u2225) \u2194 \u2200 w \u2208 K, \u27eau - v, w\u27eb = 0 :=\nbegin\n  letI : inner_product_space \u211d E := inner_product_space.is_R_or_C_to_real \ud835\udd5c E,\n  letI : module \u211d E := restrict_scalars.module \u211d \ud835\udd5c E,\n  letI : is_scalar_tower \u211d \ud835\udd5c E := restrict_scalars.is_scalar_tower _ _ _,\n  let K' : submodule \u211d E := K.restrict_scalars \u211d,\n  split,\n  { assume H,\n    have A : \u2200 w \u2208 K, re \u27eau - v, w\u27eb = 0 := (norm_eq_infi_iff_real_inner_eq_zero K' hv).1 H,\n    assume w hw,\n    apply ext,\n    { simp [A w hw] },\n    { symmetry, calc\n      im (0 : \ud835\udd5c) = 0 : im.map_zero\n      ... = re \u27eau - v, (-I) \u2022 w\u27eb : (A _ (K.smul_mem (-I) hw)).symm\n      ... = re ((-I) * \u27eau - v, w\u27eb) : by rw inner_smul_right\n      ... = im \u27eau - v, w\u27eb : by simp } },\n  { assume H,\n    have : \u2200 w \u2208 K', \u27eau - v, w\u27eb_\u211d = 0,\n    { assume w hw,\n      rw [real_inner_eq_re_inner, H w hw],\n      exact zero_re' },\n    exact (norm_eq_infi_iff_real_inner_eq_zero K' hv).2 this }\nend\n\nsection orthogonal_projection\nvariables [complete_space K]\n\n/-- The orthogonal projection onto a complete subspace, as an\nunbundled function.  This definition is only intended for use in\nsetting up the bundled version `orthogonal_projection` and should not\nbe used once that is defined. -/\ndef orthogonal_projection_fn (v : E) :=\n(exists_norm_eq_infi_of_complete_subspace K (complete_space_coe_iff_is_complete.mp \u2039_\u203a) v).some\n\nvariables {K}\n\n/-- The unbundled orthogonal projection is in the given subspace.\nThis lemma is only intended for use in setting up the bundled version\nand should not be used once that is defined. -/\nlemma orthogonal_projection_fn_mem (v : E) : orthogonal_projection_fn K v \u2208 K :=\n(exists_norm_eq_infi_of_complete_subspace K\n  (complete_space_coe_iff_is_complete.mp \u2039_\u203a) v).some_spec.some\n\n/-- The characterization of the unbundled orthogonal projection.  This\nlemma is only intended for use in setting up the bundled version\nand should not be used once that is defined. -/\nlemma orthogonal_projection_fn_inner_eq_zero (v : E) :\n  \u2200 w \u2208 K, \u27eav - orthogonal_projection_fn K v, w\u27eb = 0 :=\nbegin\n  rw \u2190norm_eq_infi_iff_inner_eq_zero K (orthogonal_projection_fn_mem v),\n  exact (exists_norm_eq_infi_of_complete_subspace K\n    (complete_space_coe_iff_is_complete.mp \u2039_\u203a) v).some_spec.some_spec\nend\n\n/-- The unbundled orthogonal projection is the unique point in `K`\nwith the orthogonality property.  This lemma is only intended for use\nin setting up the bundled version and should not be used once that is\ndefined. -/\nlemma eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero\n  {u v : E} (hvm : v \u2208 K) (hvo : \u2200 w \u2208 K, \u27eau - v, w\u27eb = 0) :\n  orthogonal_projection_fn K u = v :=\nbegin\n  rw [\u2190sub_eq_zero, \u2190inner_self_eq_zero],\n  have hvs : orthogonal_projection_fn K u - v \u2208 K :=\n    submodule.sub_mem K (orthogonal_projection_fn_mem u) hvm,\n  have huo : \u27eau - orthogonal_projection_fn K u, orthogonal_projection_fn K u - v\u27eb = 0 :=\n    orthogonal_projection_fn_inner_eq_zero u _ hvs,\n  have huv : \u27eau - v, orthogonal_projection_fn K u - v\u27eb = 0 := hvo _ hvs,\n  have houv : \u27ea(u - v) - (u - orthogonal_projection_fn K u), orthogonal_projection_fn K u - v\u27eb = 0,\n  { rw [inner_sub_left, huo, huv, sub_zero] },\n  rwa sub_sub_sub_cancel_left at houv\nend\n\nvariables (K)\n\nlemma orthogonal_projection_fn_norm_sq (v : E) :\n  \u2225v\u2225 * \u2225v\u2225 = \u2225v - (orthogonal_projection_fn K v)\u2225 * \u2225v - (orthogonal_projection_fn K v)\u2225\n            + \u2225orthogonal_projection_fn K v\u2225 * \u2225orthogonal_projection_fn K v\u2225 :=\nbegin\n  set p := orthogonal_projection_fn K v,\n  have h' : \u27eav - p, p\u27eb = 0,\n  { exact orthogonal_projection_fn_inner_eq_zero _ _ (orthogonal_projection_fn_mem v) },\n  convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2;\n  simp,\nend\n\n/-- The orthogonal projection onto a complete subspace. -/\ndef orthogonal_projection : E \u2192L[\ud835\udd5c] K :=\nlinear_map.mk_continuous\n  { to_fun := \u03bb v, \u27e8orthogonal_projection_fn K v, orthogonal_projection_fn_mem v\u27e9,\n    map_add' := \u03bb x y, begin\n      have hm : orthogonal_projection_fn K x + orthogonal_projection_fn K y \u2208 K :=\n        submodule.add_mem K (orthogonal_projection_fn_mem x) (orthogonal_projection_fn_mem y),\n      have ho :\n        \u2200 w \u2208 K, \u27eax + y - (orthogonal_projection_fn K x + orthogonal_projection_fn K y), w\u27eb = 0,\n      { intros w hw,\n        rw [add_sub_comm, inner_add_left, orthogonal_projection_fn_inner_eq_zero _ w hw,\n            orthogonal_projection_fn_inner_eq_zero _ w hw, add_zero] },\n      ext,\n      simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho]\n    end,\n    map_smul' := \u03bb c x, begin\n      have hm : c \u2022 orthogonal_projection_fn K x \u2208 K :=\n        submodule.smul_mem K _ (orthogonal_projection_fn_mem x),\n      have ho : \u2200 w \u2208 K, \u27eac \u2022 x - c \u2022 orthogonal_projection_fn K x, w\u27eb = 0,\n      { intros w hw,\n        rw [\u2190smul_sub, inner_smul_left, orthogonal_projection_fn_inner_eq_zero _ w hw, mul_zero] },\n      ext,\n      simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho]\n    end }\n  1\n  (\u03bb x, begin\n    simp only [one_mul, linear_map.coe_mk],\n    refine le_of_pow_le_pow 2 (norm_nonneg _) (by norm_num) _,\n    change \u2225orthogonal_projection_fn K x\u2225 ^ 2 \u2264 \u2225x\u2225 ^ 2,\n    nlinarith [orthogonal_projection_fn_norm_sq K x]\n  end)\n\nvariables {K}\n\n@[simp]\nlemma orthogonal_projection_fn_eq (v : E) :\n  orthogonal_projection_fn K v = (orthogonal_projection K v : E) :=\nrfl\n\n/-- The characterization of the orthogonal projection.  -/\n@[simp]\nlemma orthogonal_projection_inner_eq_zero (v : E) :\n  \u2200 w \u2208 K, \u27eav - orthogonal_projection K v, w\u27eb = 0 :=\northogonal_projection_fn_inner_eq_zero v\n\n/-- The orthogonal projection is the unique point in `K` with the\northogonality property. -/\nlemma eq_orthogonal_projection_of_mem_of_inner_eq_zero\n  {u v : E} (hvm : v \u2208 K) (hvo : \u2200 w \u2208 K, \u27eau - v, w\u27eb = 0) :\n  (orthogonal_projection K u : E) = v :=\neq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hvm hvo\n\n/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/\nlemma eq_orthogonal_projection_of_eq_submodule\n  {K' : submodule \ud835\udd5c E} [complete_space K'] (h : K = K') (u : E) :\n  (orthogonal_projection K u : E) = (orthogonal_projection K' u : E) :=\nbegin\n  change orthogonal_projection_fn K u = orthogonal_projection_fn K' u,\n  congr,\n  exact h\nend\n\n/-- The orthogonal projection sends elements of `K` to themselves. -/\n@[simp] lemma orthogonal_projection_mem_subspace_eq_self (v : K) : orthogonal_projection K v = v :=\nby { ext, apply eq_orthogonal_projection_of_mem_of_inner_eq_zero; simp }\n\nlocal attribute [instance] finite_dimensional_bot\n\n/-- The orthogonal projection onto the trivial submodule is the zero map. -/\n@[simp] lemma orthogonal_projection_bot : orthogonal_projection (\u22a5 : submodule \ud835\udd5c E) = 0 :=\nbegin\n  ext u,\n  apply eq_orthogonal_projection_of_mem_of_inner_eq_zero,\n  { simp },\n  { intros w hw,\n    simp [(submodule.mem_bot \ud835\udd5c).mp hw] }\nend\n\nvariables (K)\n\n/-- The orthogonal projection has norm `\u2264 1`. -/\nlemma orthogonal_projection_norm_le : \u2225orthogonal_projection K\u2225 \u2264 1 :=\nlinear_map.mk_continuous_norm_le _ (by norm_num) _\n\nvariables (\ud835\udd5c)\n\nlemma smul_orthogonal_projection_singleton {v : E} (w : E) :\n  (\u2225v\u2225 ^ 2 : \ud835\udd5c) \u2022 (orthogonal_projection (\ud835\udd5c \u2219 v) w : E) = \u27eav, w\u27eb \u2022 v :=\nbegin\n  suffices : \u2191(orthogonal_projection (\ud835\udd5c \u2219 v) ((\u2225v\u2225 ^ 2 : \ud835\udd5c) \u2022 w)) = \u27eav, w\u27eb \u2022 v,\n  { simpa using this },\n  apply eq_orthogonal_projection_of_mem_of_inner_eq_zero,\n  { rw submodule.mem_span_singleton,\n    use \u27eav, w\u27eb },\n  { intros x hx,\n    obtain \u27e8c, rfl\u27e9 := submodule.mem_span_singleton.mp hx,\n    have hv : \u2191\u2225v\u2225 ^ 2 = \u27eav, v\u27eb := by { norm_cast, simp [norm_sq_eq_inner] },\n    simp [inner_sub_left, inner_smul_left, inner_smul_right, is_R_or_C.conj_div, mul_comm, hv,\n      inner_product_space.conj_sym, hv] }\nend\n\n/-- Formula for orthogonal projection onto a single vector. -/\nlemma orthogonal_projection_singleton {v : E} (w : E) :\n  (orthogonal_projection (\ud835\udd5c \u2219 v) w : E) = (\u27eav, w\u27eb / \u2225v\u2225 ^ 2) \u2022 v :=\nbegin\n  by_cases hv : v = 0,\n  { rw [hv, eq_orthogonal_projection_of_eq_submodule submodule.span_zero_singleton],\n    { simp },\n    { apply_instance } },\n  have hv' : \u2225v\u2225 \u2260 0 := ne_of_gt (norm_pos_iff.mpr hv),\n  have key : ((\u2225v\u2225 ^ 2 : \ud835\udd5c)\u207b\u00b9 * \u2225v\u2225 ^ 2) \u2022 \u2191(orthogonal_projection (\ud835\udd5c \u2219 v) w)\n              = ((\u2225v\u2225 ^ 2 : \ud835\udd5c)\u207b\u00b9 * \u27eav, w\u27eb) \u2022 v,\n  { simp [mul_smul, smul_orthogonal_projection_singleton \ud835\udd5c w] },\n  convert key;\n  field_simp [hv']\nend\n\n/-- Formula for orthogonal projection onto a single unit vector. -/\nlemma orthogonal_projection_unit_singleton {v : E} (hv : \u2225v\u2225 = 1) (w : E) :\n  (orthogonal_projection (\ud835\udd5c \u2219 v) w : E) = \u27eav, w\u27eb \u2022 v :=\nby { rw \u2190 smul_orthogonal_projection_singleton \ud835\udd5c w, simp [hv] }\n\nend orthogonal_projection\n\n/-- The subspace of vectors orthogonal to a given subspace. -/\ndef submodule.orthogonal : submodule \ud835\udd5c E :=\n{ carrier := {v | \u2200 u \u2208 K, \u27eau, v\u27eb = 0},\n  zero_mem' := \u03bb _ _, inner_zero_right,\n  add_mem' := \u03bb x y hx hy u hu, by rw [inner_add_right, hx u hu, hy u hu, add_zero],\n  smul_mem' := \u03bb c x hx u hu, by rw [inner_smul_right, hx u hu, mul_zero] }\n\nnotation K`\u15ee`:1200 := submodule.orthogonal K\n\n/-- When a vector is in `K\u15ee`. -/\nlemma submodule.mem_orthogonal (v : E) : v \u2208 K\u15ee \u2194 \u2200 u \u2208 K, \u27eau, v\u27eb = 0 := iff.rfl\n\n/-- When a vector is in `K\u15ee`, with the inner product the\nother way round. -/\nlemma submodule.mem_orthogonal' (v : E) : v \u2208 K\u15ee \u2194 \u2200 u \u2208 K, \u27eav, u\u27eb = 0 :=\nby simp_rw [submodule.mem_orthogonal, inner_eq_zero_sym]\n\nvariables {K}\n\n/-- A vector in `K` is orthogonal to one in `K\u15ee`. -/\nlemma submodule.inner_right_of_mem_orthogonal {u v : E} (hu : u \u2208 K) (hv : v \u2208 K\u15ee) : \u27eau, v\u27eb = 0 :=\n(K.mem_orthogonal v).1 hv u hu\n\n/-- A vector in `K\u15ee` is orthogonal to one in `K`. -/\nlemma submodule.inner_left_of_mem_orthogonal {u v : E} (hu : u \u2208 K) (hv : v \u2208 K\u15ee) : \u27eav, u\u27eb = 0 :=\nby rw [inner_eq_zero_sym]; exact submodule.inner_right_of_mem_orthogonal hu hv\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\nlemma inner_right_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v \u2208 (\ud835\udd5c \u2219 u)\u15ee) : \u27eau, v\u27eb = 0 :=\nsubmodule.inner_right_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\nlemma inner_left_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v \u2208 (\ud835\udd5c \u2219 u)\u15ee) : \u27eav, u\u27eb = 0 :=\nsubmodule.inner_left_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\nvariables (K)\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\nlemma submodule.inf_orthogonal_eq_bot : K \u2293 K\u15ee = \u22a5 :=\nbegin\n  rw submodule.eq_bot_iff,\n  intros x,\n  rw submodule.mem_inf,\n  exact \u03bb \u27e8hx, ho\u27e9, inner_self_eq_zero.1 (ho x hx)\nend\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\nlemma submodule.orthogonal_disjoint : disjoint K K\u15ee :=\nby simp [disjoint_iff, K.inf_orthogonal_eq_bot]\n\n/-- `K\u15ee` can be characterized as the intersection of the kernels of the operations of\ninner product with each of the elements of `K`. -/\nlemma orthogonal_eq_inter : K\u15ee = \u2a05 v : K, (inner_right (v:E)).ker :=\nbegin\n  apply le_antisymm,\n  { rw le_infi_iff,\n    rintros \u27e8v, hv\u27e9 w hw,\n    simpa using hw _ hv },\n  { intros v hv w hw,\n    simp only [submodule.mem_infi] at hv,\n    exact hv \u27e8w, hw\u27e9 }\nend\n\n/-- The orthogonal complement of any submodule `K` is closed. -/\nlemma submodule.is_closed_orthogonal : is_closed (K\u15ee : set E) :=\nbegin\n  rw orthogonal_eq_inter K,\n  convert is_closed_Inter (\u03bb v : K, (inner_right (v:E)).is_closed_ker),\n  simp\nend\n\n/-- In a complete space, the orthogonal complement of any submodule `K` is complete. -/\ninstance [complete_space E] : complete_space K\u15ee := K.is_closed_orthogonal.complete_space_coe\n\nvariables (\ud835\udd5c E)\n\n/-- `submodule.orthogonal` gives a `galois_connection` between\n`submodule \ud835\udd5c E` and its `order_dual`. -/\nlemma submodule.orthogonal_gc :\n  @galois_connection (submodule \ud835\udd5c E) (order_dual $ submodule \ud835\udd5c E) _ _\n    submodule.orthogonal submodule.orthogonal :=\n\u03bb K\u2081 K\u2082, \u27e8\u03bb h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu),\n          \u03bb h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu)\u27e9\n\nvariables {\ud835\udd5c E}\n\n/-- `submodule.orthogonal` reverses the `\u2264` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_le {K\u2081 K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) : K\u2082\u15ee \u2264 K\u2081\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).monotone_l h\n\n/-- `submodule.orthogonal.orthogonal` preserves the `\u2264` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_orthogonal_monotone {K\u2081 K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) :\n  K\u2081\u15ee\u15ee \u2264 K\u2082\u15ee\u15ee :=\nsubmodule.orthogonal_le (submodule.orthogonal_le h)\n\n/-- `K` is contained in `K\u15ee\u15ee`. -/\nlemma submodule.le_orthogonal_orthogonal : K \u2264 K\u15ee\u15ee := (submodule.orthogonal_gc \ud835\udd5c E).le_u_l _\n\n/-- The inf of two orthogonal subspaces equals the subspace orthogonal\nto the sup. -/\nlemma submodule.inf_orthogonal (K\u2081 K\u2082 : submodule \ud835\udd5c E) : K\u2081\u15ee \u2293 K\u2082\u15ee = (K\u2081 \u2294 K\u2082)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_sup.symm\n\n/-- The inf of an indexed family of orthogonal subspaces equals the\nsubspace orthogonal to the sup. -/\nlemma submodule.infi_orthogonal {\u03b9 : Type*} (K : \u03b9 \u2192 submodule \ud835\udd5c E) : (\u2a05 i, (K i)\u15ee) = (supr K)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_supr.symm\n\n/-- The inf of a set of orthogonal subspaces equals the subspace orthogonal to the sup. -/\nlemma submodule.Inf_orthogonal (s : set $ submodule \ud835\udd5c E) : (\u2a05 K \u2208 s, K\u15ee) = (Sup s)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_Sup.symm\n\n/-- If `K\u2081` is complete and contained in `K\u2082`, `K\u2081` and `K\u2081\u15ee \u2293 K\u2082` span `K\u2082`. -/\nlemma submodule.sup_orthogonal_inf_of_is_complete {K\u2081 K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082)\n  (hc : is_complete (K\u2081 : set E)) : K\u2081 \u2294 (K\u2081\u15ee \u2293 K\u2082) = K\u2082 :=\nbegin\n  ext x,\n  rw submodule.mem_sup,\n  rcases exists_norm_eq_infi_of_complete_subspace K\u2081 hc x with \u27e8v, hv, hvm\u27e9,\n  rw norm_eq_infi_iff_inner_eq_zero K\u2081 hv at hvm,\n  split,\n  { rintro \u27e8y, hy, z, hz, rfl\u27e9,\n    exact K\u2082.add_mem (h hy) hz.2 },\n  { exact \u03bb hx, \u27e8v, hv, x - v, \u27e8(K\u2081.mem_orthogonal' _).2 hvm, K\u2082.sub_mem hx (h hv)\u27e9,\n                 add_sub_cancel'_right _ _\u27e9 }\nend\n\nvariables {K}\n\n/-- If `K` is complete, `K` and `K\u15ee` span the whole space. -/\nlemma submodule.sup_orthogonal_of_is_complete (h : is_complete (K : set E)) : K \u2294 K\u15ee = \u22a4 :=\nbegin\n  convert submodule.sup_orthogonal_inf_of_is_complete (le_top : K \u2264 \u22a4) h,\n  simp\nend\n\n/-- If `K` is complete, `K` and `K\u15ee` span the whole space. Version using `complete_space`. -/\nlemma submodule.sup_orthogonal_of_complete_space [complete_space K] : K \u2294 K\u15ee = \u22a4 :=\nsubmodule.sup_orthogonal_of_is_complete (complete_space_coe_iff_is_complete.mp \u2039_\u203a)\n\nvariables (K)\n\n/-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `K\u15ee`. -/\nlemma submodule.exists_sum_mem_mem_orthogonal [complete_space K] (v : E) :\n  \u2203 (y \u2208 K) (z \u2208 K\u15ee), v = y + z :=\nbegin\n  have h_mem : v \u2208 K \u2294 K\u15ee := by simp [submodule.sup_orthogonal_of_complete_space],\n  obtain \u27e8y, hy, z, hz, hyz\u27e9 := submodule.mem_sup.mp h_mem,\n  exact \u27e8y, hy, z, hz, hyz.symm\u27e9\nend\n\n/-- If `K` is complete, then the orthogonal complement of its orthogonal complement is itself. -/\n@[simp] lemma submodule.orthogonal_orthogonal [complete_space K] : K\u15ee\u15ee = K :=\nbegin\n  ext v,\n  split,\n  { obtain \u27e8y, hy, z, hz, rfl\u27e9 := K.exists_sum_mem_mem_orthogonal v,\n    intros hv,\n    have hz' : z = 0,\n    { have hyz : \u27eaz, y\u27eb = 0 := by simp [hz y hy, inner_eq_zero_sym],\n      simpa [inner_add_right, hyz] using hv z hz },\n    simp [hy, hz'] },\n  { intros hv w hw,\n    rw inner_eq_zero_sym,\n    exact hw v hv }\nend\n\nlemma submodule.orthogonal_orthogonal_eq_closure [complete_space E] :\n  K\u15ee\u15ee = K.topological_closure :=\nbegin\n  refine le_antisymm _ _,\n  { convert submodule.orthogonal_orthogonal_monotone K.submodule_topological_closure,\n    haveI : complete_space K.topological_closure :=\n      K.is_closed_topological_closure.complete_space_coe,\n    rw K.topological_closure.orthogonal_orthogonal },\n  { exact K.topological_closure_minimal K.le_orthogonal_orthogonal K\u15ee.is_closed_orthogonal }\nend\n\nvariables {K}\n\n/-- If `K` is complete, `K` and `K\u15ee` are complements of each other. -/\nlemma submodule.is_compl_orthogonal_of_is_complete (h : is_complete (K : set E)) : is_compl K K\u15ee :=\n\u27e8K.orthogonal_disjoint, le_of_eq (submodule.sup_orthogonal_of_is_complete h).symm\u27e9\n\n@[simp] lemma submodule.top_orthogonal_eq_bot : (\u22a4 : submodule \ud835\udd5c E)\u15ee = \u22a5 :=\nbegin\n  ext,\n  rw [submodule.mem_bot, submodule.mem_orthogonal],\n  exact \u27e8\u03bb h, inner_self_eq_zero.mp (h x submodule.mem_top), by { rintro rfl, simp }\u27e9\nend\n\n@[simp] lemma submodule.bot_orthogonal_eq_top : (\u22a5 : submodule \ud835\udd5c E)\u15ee = \u22a4 :=\nbegin\n  rw [\u2190 submodule.top_orthogonal_eq_bot, eq_top_iff],\n  exact submodule.le_orthogonal_orthogonal \u22a4\nend\n\n@[simp] lemma submodule.orthogonal_eq_bot_iff (hK : is_complete (K : set E)) :\n  K\u15ee = \u22a5 \u2194 K = \u22a4 :=\nbegin\n  refine \u27e8_, by { rintro rfl, exact submodule.top_orthogonal_eq_bot }\u27e9,\n  intro h,\n  have : K \u2294 K\u15ee = \u22a4 := submodule.sup_orthogonal_of_is_complete hK,\n  rwa [h, sup_comm, bot_sup_eq] at this,\nend\n\n@[simp] lemma submodule.orthogonal_eq_top_iff : K\u15ee = \u22a4 \u2194 K = \u22a5 :=\nbegin\n  refine \u27e8_, by { rintro rfl, exact submodule.bot_orthogonal_eq_top }\u27e9,\n  intro h,\n  have : K \u2293 K\u15ee = \u22a5 := K.orthogonal_disjoint.eq_bot,\n  rwa [h, inf_comm, top_inf_eq] at this\nend\n\n/-- A point in `K` with the orthogonality property (here characterized in terms of `K\u15ee`) must be the\northogonal projection. -/\nlemma eq_orthogonal_projection_of_mem_orthogonal\n  [complete_space K] {u v : E} (hv : v \u2208 K) (hvo : u - v \u2208 K\u15ee) :\n  (orthogonal_projection K u : E) = v :=\neq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hv (\u03bb w, inner_eq_zero_sym.mp \u2218 (hvo w))\n\n/-- A point in `K` with the orthogonality property (here characterized in terms of `K\u15ee`) must be the\northogonal projection. -/\nlemma eq_orthogonal_projection_of_mem_orthogonal'\n  [complete_space K] {u v z : E} (hv : v \u2208 K) (hz : z \u2208 K\u15ee) (hu : u = v + z) :\n  (orthogonal_projection K u : E) = v :=\neq_orthogonal_projection_of_mem_orthogonal hv (by simpa [hu])\n\n/-- The orthogonal projection onto `K` of an element of `K\u15ee` is zero. -/\nlemma orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero\n  [complete_space K] {v : E} (hv : v \u2208 K\u15ee) :\n  orthogonal_projection K v = 0 :=\nby { ext, convert eq_orthogonal_projection_of_mem_orthogonal _ _; simp [hv] }\n\n/-- The orthogonal projection onto `K\u15ee` of an element of `K` is zero. -/\nlemma orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero\n  [complete_space E] {v : E} (hv : v \u2208 K) :\n  orthogonal_projection K\u15ee v = 0 :=\northogonal_projection_mem_subspace_orthogonal_complement_eq_zero (K.le_orthogonal_orthogonal hv)\n\n/-- The orthogonal projection onto `(\ud835\udd5c \u2219 v)\u15ee` of `v` is zero. -/\nlemma orthogonal_projection_orthogonal_complement_singleton_eq_zero [complete_space E] (v : E) :\n  orthogonal_projection (\ud835\udd5c \u2219 v)\u15ee v = 0 :=\northogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero\n  (submodule.mem_span_singleton_self v)\n\nvariables (K)\n\n/-- In a complete space `E`, a vector splits as the sum of its orthogonal projections onto a\ncomplete submodule `K` and onto the orthogonal complement of `K`.-/\nlemma eq_sum_orthogonal_projection_self_orthogonal_complement\n  [complete_space E] [complete_space K] (w : E) :\n  w = (orthogonal_projection K w : E) + (orthogonal_projection K\u15ee w : E) :=\nbegin\n  obtain \u27e8y, hy, z, hz, hwyz\u27e9 := K.exists_sum_mem_mem_orthogonal w,\n  convert hwyz,\n  { exact eq_orthogonal_projection_of_mem_orthogonal' hy hz hwyz },\n  { rw add_comm at hwyz,\n    refine eq_orthogonal_projection_of_mem_orthogonal' hz _ hwyz,\n    simp [hy] }\nend\n\n/-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal\ncomplement sum to the identity. -/\nlemma id_eq_sum_orthogonal_projection_self_orthogonal_complement\n  [complete_space E] [complete_space K] :\n  continuous_linear_map.id \ud835\udd5c E\n  = K.subtypeL.comp (orthogonal_projection K)\n  + K\u15ee.subtypeL.comp (orthogonal_projection K\u15ee) :=\nby { ext w, exact eq_sum_orthogonal_projection_self_orthogonal_complement K w }\n\nopen finite_dimensional\n\n/-- Given a finite-dimensional subspace `K\u2082`, and a subspace `K\u2081`\ncontainined in it, the dimensions of `K\u2081` and the intersection of its\northogonal subspace with `K\u2082` add to that of `K\u2082`. -/\nlemma submodule.finrank_add_inf_finrank_orthogonal {K\u2081 K\u2082 : submodule \ud835\udd5c E}\n  [finite_dimensional \ud835\udd5c K\u2082] (h : K\u2081 \u2264 K\u2082) :\n  finrank \ud835\udd5c K\u2081 + finrank \ud835\udd5c (K\u2081\u15ee \u2293 K\u2082 : submodule \ud835\udd5c E) = finrank \ud835\udd5c K\u2082 :=\nbegin\n  haveI := submodule.finite_dimensional_of_le h,\n  have hd := submodule.dim_sup_add_dim_inf_eq K\u2081 (K\u2081\u15ee \u2293 K\u2082),\n  rw [\u2190inf_assoc, (submodule.orthogonal_disjoint K\u2081).eq_bot, bot_inf_eq, finrank_bot,\n      submodule.sup_orthogonal_inf_of_is_complete h\n        (submodule.complete_of_finite_dimensional _)] at hd,\n  rw add_zero at hd,\n  exact hd.symm\nend\n\n/-- Given a finite-dimensional subspace `K\u2082`, and a subspace `K\u2081`\ncontainined in it, the dimensions of `K\u2081` and the intersection of its\northogonal subspace with `K\u2082` add to that of `K\u2082`. -/\nlemma submodule.finrank_add_inf_finrank_orthogonal' {K\u2081 K\u2082 : submodule \ud835\udd5c E}\n  [finite_dimensional \ud835\udd5c K\u2082] (h : K\u2081 \u2264 K\u2082) {n : \u2115} (h_dim : finrank \ud835\udd5c K\u2081 + n = finrank \ud835\udd5c K\u2082) :\n  finrank \ud835\udd5c (K\u2081\u15ee \u2293 K\u2082 : submodule \ud835\udd5c E) = n :=\nby { rw \u2190 add_right_inj (finrank \ud835\udd5c K\u2081),\n     simp [submodule.finrank_add_inf_finrank_orthogonal h, h_dim] }\n\n/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `K\u15ee` add to\nthat of `E`. -/\nlemma submodule.finrank_add_finrank_orthogonal [finite_dimensional \ud835\udd5c E] {K : submodule \ud835\udd5c E} :\n  finrank \ud835\udd5c K + finrank \ud835\udd5c K\u15ee = finrank \ud835\udd5c E :=\nbegin\n  convert submodule.finrank_add_inf_finrank_orthogonal (le_top : K \u2264 \u22a4) using 1,\n  { rw inf_top_eq },\n  { simp }\nend\n\n/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `K\u15ee` add to\nthat of `E`. -/\nlemma submodule.finrank_add_finrank_orthogonal' [finite_dimensional \ud835\udd5c E] {K : submodule \ud835\udd5c E} {n : \u2115}\n  (h_dim : finrank \ud835\udd5c K + n = finrank \ud835\udd5c E) :\n  finrank \ud835\udd5c K\u15ee = n :=\nby { rw \u2190 add_right_inj (finrank \ud835\udd5c K), simp [submodule.finrank_add_finrank_orthogonal, h_dim] }\n\nlocal attribute [instance] finite_dimensional_of_finrank_eq_succ\n\n/-- In a finite-dimensional inner product space, the dimension of the orthogonal complement of the\nspan of a nonzero vector is one less than the dimension of the space. -/\nlemma finrank_orthogonal_span_singleton {n : \u2115} [_i : fact (finrank \ud835\udd5c E = n + 1)]\n  {v : E} (hv : v \u2260 0) :\n  finrank \ud835\udd5c (\ud835\udd5c \u2219 v)\u15ee = n :=\nsubmodule.finrank_add_finrank_orthogonal' $ by simp [finrank_span_singleton hv, _i.elim, add_comm]\n\nend orthogonal\n\nsection orthonormal_basis\n\n/-! ### Existence of Hilbert basis, orthonormal basis, etc. -/\n\nvariables {\ud835\udd5c E} {v : set E}\n\nopen finite_dimensional submodule set\n\n/-- An orthonormal set in an `inner_product_space` is maximal, if and only if the orthogonal\ncomplement of its span is empty. -/\nlemma maximal_orthonormal_iff_orthogonal_complement_eq_bot (hv : orthonormal \ud835\udd5c (coe : v \u2192 E)) :\n  (\u2200 u \u2287 v, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2192 u = v) \u2194 (span \ud835\udd5c v)\u15ee = \u22a5 :=\nbegin\n  rw submodule.eq_bot_iff,\n  split,\n  { contrapose!,\n    -- ** direction 1: nonempty orthogonal complement implies nonmaximal\n    rintros \u27e8x, hx', hx\u27e9,\n    -- take a nonzero vector and normalize it\n    let e := (\u2225x\u2225\u207b\u00b9 : \ud835\udd5c) \u2022 x,\n    have he : \u2225e\u2225 = 1 := by simp [e, norm_smul_inv_norm hx],\n    have he' : e \u2208 (span \ud835\udd5c v)\u15ee := smul_mem' _ _ hx',\n    have he'' : e \u2209 v,\n    { intros hev,\n      have : e = 0,\n      { have : e \u2208 (span \ud835\udd5c v) \u2293 (span \ud835\udd5c v)\u15ee := \u27e8subset_span hev, he'\u27e9,\n        simpa [(span \ud835\udd5c v).inf_orthogonal_eq_bot] using this },\n      have : e \u2260 0 := hv.ne_zero \u27e8e, hev\u27e9,\n      contradiction },\n    -- put this together with `v` to provide a candidate orthonormal basis for the whole space\n    refine \u27e8v.insert e, v.subset_insert e, \u27e8_, _\u27e9, (v.ne_insert_of_not_mem he'').symm\u27e9,\n    { -- show that the elements of `v.insert e` have unit length\n      rintros \u27e8a, ha'\u27e9,\n      cases eq_or_mem_of_mem_insert ha' with ha ha,\n      { simp [ha, he] },\n      { exact hv.1 \u27e8a, ha\u27e9 } },\n    { -- show that the elements of `v.insert e` are orthogonal\n      have h_end : \u2200 a \u2208 v, \u27eaa, e\u27eb = 0,\n      { intros a ha,\n        exact he' a (submodule.subset_span ha) },\n      rintros \u27e8a, ha'\u27e9,\n      cases eq_or_mem_of_mem_insert ha' with ha ha,\n      { rintros \u27e8b, hb'\u27e9 hab',\n        have hb : b \u2208 v,\n        { refine mem_of_mem_insert_of_ne hb' _,\n          intros hbe',\n          apply hab',\n          simp [ha, hbe'] },\n        rw inner_eq_zero_sym,\n        simpa [ha] using h_end b hb },\n      rintros \u27e8b, hb'\u27e9 hab',\n      cases eq_or_mem_of_mem_insert hb' with hb hb,\n      { simpa [hb] using h_end a ha },\n      have : (\u27e8a, ha\u27e9 : v) \u2260 \u27e8b, hb\u27e9,\n      { intros hab'',\n        apply hab',\n        simpa using hab'' },\n      exact hv.2 this } },\n    { -- ** direction 2: empty orthogonal complement implies maximal\n      simp only [subset.antisymm_iff],\n      rintros h u (huv : v \u2286 u) hu,\n      refine \u27e8_, huv\u27e9,\n      intros x hxu,\n      refine ((mt (h x)) (hu.ne_zero \u27e8x, hxu\u27e9)).imp_symm _,\n      intros hxv y hy,\n      have hxv' : (\u27e8x, hxu\u27e9 : u) \u2209 (coe \u207b\u00b9' v : set u) := by simp [huv, hxv],\n      obtain \u27e8l, hl, rfl\u27e9 :\n        \u2203 l \u2208 finsupp.supported \ud835\udd5c \ud835\udd5c (coe \u207b\u00b9' v : set u), (finsupp.total \u21a5u E \ud835\udd5c coe) l = y,\n      { rw \u2190 finsupp.mem_span_iff_total,\n        simp [huv, inter_eq_self_of_subset_left, hy] },\n      exact hu.inner_finsupp_eq_zero hxv' hl }\nend\n\n/-- An orthonormal set in an `inner_product_space` is maximal, if and only if the closure of its\nspan is the whole space. -/\nlemma maximal_orthonormal_iff_dense_span [complete_space E] (hv : orthonormal \ud835\udd5c (coe : v \u2192 E)) :\n  (\u2200 u \u2287 v, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2192 u = v) \u2194 (span \ud835\udd5c v).topological_closure = \u22a4 :=\nby rw [maximal_orthonormal_iff_orthogonal_complement_eq_bot hv, \u2190 submodule.orthogonal_eq_top_iff,\n  (span \ud835\udd5c v).orthogonal_orthogonal_eq_closure]\n\n/-- Any orthonormal subset can be extended to an orthonormal set whose span is dense. -/\nlemma exists_subset_is_orthonormal_dense_span\n  [complete_space E] (hv : orthonormal \ud835\udd5c (coe : v \u2192 E)) :\n  \u2203 u \u2287 v, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2227 (span \ud835\udd5c u).topological_closure = \u22a4 :=\nbegin\n  obtain \u27e8u, hus, hu, hu_max\u27e9 := exists_maximal_orthonormal hv,\n  rw maximal_orthonormal_iff_dense_span hu at hu_max,\n  exact \u27e8u, hus, hu, hu_max\u27e9\nend\n\nvariables (\ud835\udd5c E)\n/-- An inner product space admits an orthonormal set whose span is dense. -/\nlemma exists_is_orthonormal_dense_span [complete_space E] :\n  \u2203 u : set E, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2227 (span \ud835\udd5c u).topological_closure = \u22a4 :=\nlet \u27e8u, hus, hu, hu_max\u27e9 := exists_subset_is_orthonormal_dense_span (orthonormal_empty \ud835\udd5c E) in\n\u27e8u, hu, hu_max\u27e9\nvariables {\ud835\udd5c E}\n\n/-- An orthonormal set in a finite-dimensional `inner_product_space` is maximal, if and only if it\nis a basis. -/\nlemma maximal_orthonormal_iff_is_basis_of_finite_dimensional\n  [finite_dimensional \ud835\udd5c E] (hv : orthonormal \ud835\udd5c (coe : v \u2192 E)) :\n  (\u2200 u \u2287 v, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2192 u = v) \u2194 is_basis \ud835\udd5c (coe : v \u2192 E) :=\nbegin\n  rw maximal_orthonormal_iff_orthogonal_complement_eq_bot hv,\n  have hv_compl : is_complete (span \ud835\udd5c v : set E) := (span \ud835\udd5c v).complete_of_finite_dimensional,\n  rw submodule.orthogonal_eq_bot_iff hv_compl,\n  have hv_coe : range (coe : v \u2192 E) = v := by simp,\n  split,\n  { refine \u03bb h, \u27e8hv.linear_independent, _\u27e9,\n    convert h },\n  { intros h,\n    convert \u2190 h.2 }\nend\n\n/-- In a finite-dimensional `inner_product_space`, any orthonormal subset can be extended to an\northonormal basis. -/\nlemma exists_subset_is_orthonormal_basis\n  [finite_dimensional \ud835\udd5c E] (hv : orthonormal \ud835\udd5c (coe : v \u2192 E)) :\n  \u2203 u \u2287 v, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2227 is_basis \ud835\udd5c (coe : u \u2192 E) :=\nbegin\n  obtain \u27e8u, hus, hu, hu_max\u27e9 := exists_maximal_orthonormal hv,\n  rw maximal_orthonormal_iff_is_basis_of_finite_dimensional hu at hu_max,\n  exact \u27e8u, hus, hu, hu_max\u27e9\nend\n\nvariables (\ud835\udd5c E)\n/-- A finite-dimensional `inner_product_space` has an orthonormal basis. -/\nlemma exists_is_orthonormal_basis [finite_dimensional \ud835\udd5c E] :\n  \u2203 u : set E, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2227 is_basis \ud835\udd5c (coe : u \u2192 E) :=\nlet \u27e8u, hus, hu, hu_max\u27e9 := exists_subset_is_orthonormal_basis (orthonormal_empty \ud835\udd5c E) in\n\u27e8u, hu, hu_max\u27e9\nvariables {\ud835\udd5c E}\n\n/-- Given a natural number `n` equal to the `finrank` of a finite-dimensional inner product space,\nthere exists an orthonormal basis for the space indexed by `fin n`. -/\nlemma exists_is_orthonormal_basis' [finite_dimensional \ud835\udd5c E] {n : \u2115} (hn : finrank \ud835\udd5c E = n) :\n  \u2203 v : fin n \u2192 E, orthonormal \ud835\udd5c v \u2227 is_basis \ud835\udd5c v :=\nbegin\n  obtain \u27e8u, hu, hu_basis\u27e9 := exists_is_orthonormal_basis \ud835\udd5c E,\n  obtain \u27e8g, hg\u27e9 := finite_dimensional.equiv_fin_of_dim_eq hn hu_basis,\n  exact \u27e8coe \u2218 g, hu.comp _ g.injective, hg\u27e9\nend\n\n/-- Given a natural number `n` equal to the `finrank` of a finite-dimensional inner product space,\nthere exists an isometry from the space to `euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.of_inner_product_space\n  [finite_dimensional \ud835\udd5c E] {n : \u2115} (hn : finrank \ud835\udd5c E = n) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\nlet hv := classical.some_spec (exists_is_orthonormal_basis' hn) in\nhv.2.isometry_euclidean_of_orthonormal hv.1\n\nlocal attribute [instance] finite_dimensional_of_finrank_eq_succ\n\n/-- Given a natural number `n` one less than the `finrank` of a finite-dimensional inner product\nspace, there exists an isometry from the orthogonal complement of a nonzero singleton to\n`euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.from_orthogonal_span_singleton\n  (n : \u2115) [fact (finrank \ud835\udd5c E = n + 1)] {v : E} (hv : v \u2260 0) :\n  (\ud835\udd5c \u2219 v)\u15ee \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\nlinear_isometry_equiv.of_inner_product_space (finrank_orthogonal_span_singleton hv)\n\nend orthonormal_basis\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/normed_space/inner_product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7480692585532904}}
{"text": "import analysis.special_functions.exp\nimport data.real.basic\nimport tactic\n\nopen real\n\nvariables a b : \u211d\n\n#check pow_two_nonneg\n#check pow_two_nonneg b\n#check @exp_le_exp \n#check exp_le_exp.mpr\n\n-- BEGIN\nexample (a : \u211d) : 0 \u2264 a^2 :=\nbegin\n  exact pow_two_nonneg a,\nend\n\nexample (a b : \u211d) (h : a \u2264 b) : exp a \u2264 exp b :=\nbegin\n  rw exp_le_exp,\n  exact h,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.2_exact/ex1_exact_le_exp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107843878721, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7480692515541139}}
{"text": "theorem ex1 (n m : Nat) : 0 + (n, m).1 = n := by\n  simp only\n  rw [Nat.zero_add]\n\ntheorem ex2 (n m : Nat) : 0 + (n, m).1 = n := by\n  simp\n\ntheorem ex3 (n m : Nat) : 0 + (n, m).1 + 0 = n := by\n  simp only [Nat.add_zero]\n  rw [Nat.zero_add]\n\ntheorem ex4 (n m : Nat) : 0 + (n, m).1 + 0 = n := by\n  simp\n\ntheorem ex5 (m n : Nat) : m + n = n + m := by\n  induction n with\n  | zero      => rw [Nat.zero_add, Nat.add_zero]\n  | succ n ih => simp only [Nat.add_succ, Nat.succ_add, ih]\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/simpOnly.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7480443857613365}}
{"text": "-- Diversion from LTL_Diff. What if we prove that the standard smooth maximum\n-- actually approximates the maximum.\n\n-- Second attempt using fin n \u2192 \u211d.\n\nimport data.real.basic\nimport data.complex.exponential\nimport analysis.complex.basic\nimport analysis.special_functions.pow\nimport analysis.special_functions.exp_log\nimport analysis.calculus.times_cont_diff\nimport algebra.big_operators\n\nnoncomputable theory\n\nopen real classical topological_space\nopen_locale big_operators\n\n-- Definition of soft_max.\nsection soft_max \n\nvariables (n : \u2115)\n\ndef soft_max.num (\u03b1 : \u211d) : (fin (n + 1) \u2192 \u211d) \u2192 \u211d := \n\u03bb v, \u2211 i, (v i) * exp (\u03b1 * (v i))\n\n@[simp] lemma soft_max.num_zero (\u03b1 : \u211d) : soft_max.num 0 \u03b1 = \u03bb v, (v 0) * exp (\u03b1 * (v 0)) := \nbegin\n  ext v, \n  unfold soft_max.num, -- How do I get rid of this ?\n  rw [fin.sum_univ_succ, fin.sum_univ_zero, add_zero],\nend\n\nlemma soft_max.num_succ_aux (\u03b1 : \u211d) (v : fin (n + 1).succ \u2192 \u211d) : \nsoft_max.num n.succ \u03b1 v = (soft_max.num n \u03b1 (\u03bb i, v i)) + (v (n + 1)) * exp (\u03b1 * (v (n + 1))) :=\nbegin\n  unfold soft_max.num,\n  rw fin.sum_univ_cast_succ,\n  congr,\n  { simp, },\n  { rw \u2190fin.coe_nat_eq_last; refl, },\n  { rw \u2190fin.coe_nat_eq_last; refl, }\nend\n\n@[simp] lemma soft_max.num_succ (\u03b1 : \u211d) : \nsoft_max.num n.succ \u03b1 = \u03bb (v : fin (n + 1).succ \u2192 \u211d), \n  (soft_max.num n \u03b1 (\u03bb i, v i)) + (v (n + 1)) * exp (\u03b1 * (v (n + 1))) :=\nby ext v; exact soft_max.num_succ_aux n \u03b1 v\n\ndef soft_max.den (\u03b1 : \u211d) : (fin (n + 1) \u2192 \u211d) \u2192 \u211d := \n\u03bb v, \u2211 i, exp (\u03b1 * (v i))\n\n@[simp] lemma soft_max.den_zero (\u03b1 : \u211d) : soft_max.den 0 \u03b1 = \u03bb v, exp (\u03b1 * (v 0)) := \nbegin\n  ext v, \n  unfold soft_max.den, -- How do I get rid of this ?\n  rw [fin.sum_univ_succ, fin.sum_univ_zero, add_zero],\nend\n\ndef soft_max (\u03b1 : \u211d) : (fin (n + 1) \u2192 \u211d) \u2192 \u211d := \n\u03bb v, (soft_max.num n \u03b1 v) / (soft_max.den n \u03b1 v)\n\nnamespace soft_max\n\n-- Lemma 1.a: soft_max.num is continuous everywhere.\nlemma num.continuity_at : \u2200 \u03b1 v, continuous_at (soft_max.num n \u03b1) v := \nbegin\n  intros \u03b1 v,\n  induction n with m hm,\n  { rw soft_max.num_zero,\n    apply continuous_at.mul,\n    { apply continuous_iff_continuous_at.1,\n      apply continuous_apply, },\n    { have hexp : (\u03bb (x : fin 1 \u2192 \u211d), exp (\u03b1 * x 0)) = (\u03bb (x : fin 1 \u2192 \u211d), (exp (x 0)) ^ \u03b1),\n        ext x,\n        rw [mul_comm \u03b1 (x 0), exp_mul],\n      rw hexp,\n      apply continuous_iff_continuous_at.1,\n      apply continuous_rpow,\n      { intros v',\n        left,\n        exact exp_ne_zero (v' 0), },\n      { show continuous (exp \u2218 (\u03bb (a : fin 1 \u2192 \u211d), a 0)),\n        refine continuous.comp continuous_exp _,\n        apply continuous_apply, },\n      { apply continuous_const, }, }, },\n  { rw soft_max.num_succ m,\n    apply continuous_at.add,\n    { show continuous_at ((num m \u03b1) \u2218 (\u03bb (x : fin (m.succ + 1) \u2192 \u211d), (\u03bb (i : fin (m + 1)), x \u2191i))) v,\n      apply continuous_at.comp,\n      { apply hm, },\n      { -- Some rearranging.\n        suffices hsuff : continuous_at (\u03bb (x : fin (m.succ + 1) \u2192 \u211d) (i : fin m.succ), x (fin.cast_succ i)) v,\n        { suffices hsuff2 : \n            (\u03bb (x : fin (m.succ + 1) \u2192 \u211d) (i : fin m.succ), x (fin.cast_succ i)) =\n            (\u03bb (x : fin (m.succ + 1) \u2192 \u211d) (i : fin (m + 1)), x \u2191i),\n            { rw \u2190hsuff2,\n              exact hsuff, }, \n          ext x i,\n          simp, },\n        -- Continue.\n        show continuous_at (flip ((\u03bb (i : fin (m.succ + 1)) (x : fin (m.succ + 1) \u2192 \u211d), x i) \u2218 fin.cast_succ)) v,\n        -- Continuous flip lemma? To mathlib?\n        sorry,\n        } }, \n    { -- This we have already proved, so factor that out and re-use.\n      sorry,}, },\nend\n\n-- Lemma 1.b: soft_max.den is continuous everywhere.\nlemma den.continuity_at : \u2200 \u03b1 v, continuous_at (soft_max.den n \u03b1) v := sorry\n\n-- Lemma 1.b: soft_max.den is non-zero.\nlemma den.nonzero : \u2200 \u03b1 v, soft_max.den n \u03b1 v \u2260 0 := sorry\n\n-- Lemma 1: soft_max is continuous.\nlemma continuity : \u2200 \u03b1, continuous (soft_max n \u03b1) :=\nbegin\n  intro \u03b1,\n  rw continuous_iff_continuous_at,\n  intro v,\n  apply continuous_at.div,\n  { exact num.continuity_at n \u03b1 v, },\n  { exact den.continuity_at n \u03b1 v, },\n  { exact den.nonzero n \u03b1 v, },\nend\n\n-- Lemma 2: soft_max is smooth.\nlemma smoothness : \u2200 \u03b1, times_cont_diff \u211d \u22a4 (soft_max n \u03b1) :=\nbegin\n    intro \u03b1,\n    rw times_cont_diff_top,\n    intro m,\n    induction m,\n    { erw times_cont_diff_zero,\n      exact continuity n \u03b1, },\n    { sorry }\nend\n\nend soft_max\n\nend soft_max", "meta": {"author": "ramonfmir", "repo": "lean-experiments", "sha": "041c8727bb540fb8d1519c1ad84924d473885c27", "save_path": "github-repos/lean/ramonfmir-lean-experiments", "path": "github-repos/lean/ramonfmir-lean-experiments/lean-experiments-041c8727bb540fb8d1519c1ad84924d473885c27/src/mlv/differentiable_ltl/soft_max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.747999667150411}}
{"text": "import data.real.basic\n\nvariables (f g : \u211d \u2192 \u211d)\n\n#check mul_le_mul_of_nonneg_left\n\n-- BEGIN\nexample {c : \u211d} (mf : monotone f) (nnc : 0 \u2264 c) :\n  monotone (\u03bb x, c * f x) :=\nbegin\n  intros a b aleb,\n  dsimp,\n  have : f a \u2264 f b,\n    from mf aleb,\n  exact mul_le_mul_of_nonneg_left this nnc,\nend\n\nexample (mf : monotone f) (mg : monotone g) :\n  monotone (\u03bb x, f x + g x) :=\nbegin\n  intros a b aleb,\n  apply add_le_add,\n  apply mf aleb,\n  apply mg aleb,\nend\n\nexample (mf : monotone f) (mg : monotone g) :\n  monotone (\u03bb x, f (g x)) :=\nbegin \n  intros a b aleb,\n  dsimp,\n  apply mf,\n  apply mg,\n  apply aleb,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/2_intro(s)/ex9_intro_vari_h_monof_operation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7479560132356023}}
{"text": "import data.nat.basic\nimport tactic.ring\nimport tactic\nnoncomputable theory\nopen_locale classical\nopen nat\n\n-- \"a mod b = c\"\ndef mod (a b c : \u2115) := c < b \u2227 \u2203 (d : \u2115), d * b + c = a\n\n/- \n  Main theorem of this file. Used in the prime number file in order to check for primes faster\n-/\ntheorem mod_neq_0_not_div (a b : \u2115) : (\u2203 (c : \u2115), c \u2260 0 \u2227 mod a b c) \u2192 \u00ac b \u2223 a :=\nbegin\n  intros h div,\n  cases h with c hc,\n  have hl := hc.left,\n  cases hc.right.right with d hd,\n  have hf := hc.right.left,\n  cases div with e he,\n  rw he at hd,\n  have hg : c = b * (e - d), {\n    calc c = b * e - d * b      : (norm_num.sub_nat_pos (b * e) (d * b) c hd).symm\n      ...  = b * e - b * d      : by ring_nf\n      ...  = b * (e - d)        : (nat.mul_sub_left_distrib b e d).symm, \n  },\n  have hee : (e-d) = 0 \u2228 (e-d) \u2265 1, {exact (e - d).eq_zero_or_pos,},\n  cases hee with zero one,\n  rw [zero,mul_zero] at hg,\n  exact hl hg,\n  have hee : c \u2265 b, {\n    calc c = b * (e - d) : hg\n      ...  \u2265 b * 1       : mul_le_mul_left' one b\n      ...  = b           : by rw mul_one,\n  },\n  linarith,\nend ", "meta": {"author": "encryptedsalad", "repo": "fermat_theorem", "sha": "99943f8bc2e90ef013cbd1ef55fb79c2abc90dff", "save_path": "github-repos/lean/encryptedsalad-fermat_theorem", "path": "github-repos/lean/encryptedsalad-fermat_theorem/fermat_theorem-99943f8bc2e90ef013cbd1ef55fb79c2abc90dff/src/modular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7479560077620181}}
{"text": "import GMLInit.Data.Nat.Basic\n\nnamespace Nat\nvariable {\u03b1} (f : \u03b1 \u2192 \u03b1)\n\n/-- `iter (f : \u03b1 \u2192 \u03b1) (n : Nat)` calculates the `n`th iterate of the function `f` -/\n@[specialize, inline] def iter : (n : Nat) \u2192 \u03b1 \u2192 \u03b1\n| 0, r => r\n| n+1, r => iter n (f r)\n\ntheorem iter_zero (a : \u03b1) : iter f 0 a = a := rfl\n\ntheorem iter_one (a : \u03b1) : iter f 1 a = f a := rfl\n\ntheorem iter_succ (n : Nat) (a : \u03b1) : iter f (n + 1) a = iter f n (f a) := rfl\n\ntheorem iter_add (m n : Nat) (a : \u03b1) : iter f (m + n) a = iter f m (iter f n a) := by\n  induction n generalizing a with\n  | zero => rfl\n  | succ n ih =>\n    calc\n    _ = iter f (m + n + 1) a := rfl\n    _ = iter f (m + n) (f a) := by rw [iter_succ]\n    _ = iter f m (iter f n (f a)) := by rw [ih]\n    _ = iter f m (iter f (n + 1) a) := by rw [iter_succ]\n\ntheorem iter_mul (m n : Nat) (a : \u03b1) : iter f (m * n) a = iter (iter f m) n a := by\n  induction n generalizing a with\n  | zero => rfl\n  | succ n ih =>\n    calc\n    _ = iter f (m * n + m) a := rfl\n    _ = iter f (m * n) (iter f m a) := by rw [iter_add]\n    _ = iter (iter f m) n (iter f m a) := by rw [ih]\n    _ = iter (iter f m) (n + 1) a := by rw [iter_succ]\n\ntheorem iter_zero_eq_id : iter f 0 = id := rfl\n\ntheorem iter_one_eq_self : iter f 1 = f := rfl\n\ntheorem iter_succ_eq_iter_comp_self (n : Nat) : iter f (n + 1) = iter f n \u2218 f := rfl\n\ntheorem iter_add_eq_iter_comp_iter (m n : Nat) : iter f (m + n) = iter f m \u2218 iter f n := funext (iter_add f m n)\n\ntheorem iter_mul_eq_iter_iter (m n : Nat) : iter f (m * n) = iter (iter f m) n := funext (iter_mul f m n)\n\nend Nat\n", "meta": {"author": "fgdorais", "repo": "GMLInit", "sha": "a295111627ac907ebc6a86f906dd9b4d69b338d8", "save_path": "github-repos/lean/fgdorais-GMLInit", "path": "github-repos/lean/fgdorais-GMLInit/GMLInit-a295111627ac907ebc6a86f906dd9b4d69b338d8/GMLInit/Data/Nat/Iter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7478852746049955}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Functions in Lean, example sheet 1 : injectivity and surjectivity\n\nIn this sheet we'll learn how to manipulate the concepts of \ninjectivity and surjectivity in Lean.\n\nThe notation for functions is the usual one in matheamtics:\nif `X` and `Y` are types, then `f : X \u2192 Y` denotes a function\nfrom `X` to `Y`. In fact what is going on here is that `X \u2192 Y`\ndenotes the type of all functions from `X` to `Y`, and `f : X \u2192 Y`\nmeans that `f` is a term of type `X \u2192 Y`, i.e., a function\nfrom `X` to `Y`.\n\nOne thing worth mentioning is that the simplest kind of function\nevaluation, where you have `x : X` and `f : X \u2192 Y`, doesn't need\nbrackets: you can just write `f x` instead of `f(x)`. You only\nneed it when evaluating a function at a more complex object;\nfor example if we also had `g : Y \u2192 Z` then we can't write\n`g f x` for `g(f(x))`, we have to write `g(f x)` otherwise\n`g` would eat `f` and get confused. Without brackets,\na function just eats the next term greedily.\n\n## Tactics\n\n### More on `rcases` and `rintro` -- the `rfl` hack.\n\nYou don't need to know the below trick but it can make your\nproofs shorter.\n\nThere is a clever hack in Lean which sometimes enables you to\ndo `cases` and `rw` all in one go. It works like this. Say\nyour tactic state is\n\n```\nh1 : \u2203 a, b = f a\nh2 : g b = d\n\u22a2 b = c\n```\n\nIf you do `cases h1 with a ha` or `rcases h1 with \u27e8a, ha\u27e9` (the same thing)\nthen you'll end up with\n```\na : X\nha : b = f a\nh2 : g b = d\n\u22a2 b = c\n```\n\nNow `ha`, our new hypothesis, is a \"formula for b\" and probably what you're\ngoing to want to do next is \"substitute in for b\", i.e. `rw ha,`\nor maybe even `rw ha at h2 \u22a2,`or `rw ha at *` to replace `b` by `f a`\neverywhere. Then there are no `b`s left other than in `ha` itself and\n`ha` is now basically redundant.\n\nInstead of the rewrites, you can use the `subst` tactic to do them for you;\n`subst ha,` will remove `b` completely, replacing it with `f a` everywhere\nand will then delete `ha` for you.\n\nBut even better, there is an approach where `ha` is never even created.\nThe tactic `rcases h1 with \u27e8a, rfl\u27e9`, means \"let `b` be `f a` by definition\",\ni.e. \"replace all `b`s with `f a` and delete `b`\". It is a bit of a hack\n(because it means you can't have a variable called `rfl`) but it's very\nconvenient for making proofs shorter.\n\n### More on `rw` -- syntactic equality.\n\nThe definition of `function.comp`, known to mathematicians via its `\u2218`\nnotation, is that `(f \u2218 g) x = f (g x)` by definition. So if your\ngoal mentions `(f \u2218 g) x` and you want it to mention `f (g x)` instead,\nyou can either use the `change` tactic, or you can define `comp_eval`\nas I do below, and then `rw comp_eval f g x,`. Or you can just do nothing,\nconfident in the fact that because `(f \u2218 g) x` and `f (g x)` are equal\nby definition, we don't have to worry. \n\nExcept here's a case where you have to do something. Say your\ntactic state looks like this:\n\n```\nh : g x = 37\n\u22a2 (f \u2218 g) x = b\n```\n\nThen, because `(f \u2218 g) x` and `f (g x)` are equal *by definition*,\n`rw h,` should work and change the goal to `f 37 = b`, right? Wrong :-(\nThe `rw` tactic works up to *syntactic equality*. Syntactic equality\nis the strongest version of equality -- two terms are syntactically equal\nif they are literally the same string of characters. In particular,\n`(f \u2218 g) x` and `f (g x)` are definitionally equal, but not syntactically\nequal, so `rw h,` will fail.\n\nThis is why we define `comp_eval` below. It is a proof of `(f \u2218 g) x = f (g x)`.\nThe proof is `refl`, because `refl` works up to definitional equality.\nBut because we have given the proof a name, you can `rw comp_eval,`\nto change `(f \u2218 g) x` to `f (g x)`. This means that with the tactic\nstate above, you can make progress with `rw [comp_eval, h],`.\n\n-/\n\nopen function\n\n -- Our functions will go between these sets, or Types as Lean calls them\nvariables (X Y Z : Type)\n\n-- Let's prove some theorems, each of which are true by definition.\n\ntheorem injective_def (f : X \u2192 Y) : \n  injective f \u2194 \u2200 (a b : X), f a = f b \u2192 a = b :=\nbegin\n  refl -- this proof works, because `injective f` \n       -- means \u2200 a b, f a = f b \u2192 a = b *by definition*\n       -- so the proof is \"it's reflexivity of `\u2194`\"\nend\n\n-- similarly this is the *definition* of `surjective f`\ntheorem surjective_def (f : X \u2192 Y) : \n  surjective f \u2194 \u2200 y : Y, \u2203 x : X, f x = y :=\nbegin\n  refl\nend\n\n-- similarly the *definition* of `id x` is `x`\ntheorem id_eval (x : X) :\n  id x = x :=\nbegin\n  refl\nend\n\n-- the *definition* of (g \u2218 f) (x) is g(f(x)).\ntheorem comp_eval (f : X \u2192 Y) (g : Y \u2192 Z) (x : X) :\n  (g \u2218 f) x = g (f x) :=\nbegin\n  refl\nend\n\n-- Why did we just prove all those theorems with a proof\n-- saying \"it's true by definition\"? Because now, if we want,\n-- we can `rw` the theorems to replace things by their definitions.\n\nexample : injective (id : X \u2192 X) :=\nbegin\n  -- you can start with `rw injective_def` if you like\n  -- but because `injective_def` is true by definition\n  -- you can delete it later :-)\n  sorry\nend\n\nexample : surjective (id : X \u2192 X) :=\nbegin\n  sorry\nend\n\nexample (f : X \u2192 Y) (g : Y \u2192 Z) (hf : injective f) (hg : injective g) :\n  injective (g \u2218 f) :=\nbegin\n  sorry\nend\n\nexample (f : X \u2192 Y) (g : Y \u2192 Z) (hf : surjective f) (hg : surjective g) :\n  surjective (g \u2218 f) :=\nbegin\n  sorry\nend\n\n-- This is a question on the IUM function problem sheet\nexample (f : X \u2192 Y) (g : Y \u2192 Z) : \n  injective (g \u2218 f) \u2192 injective f :=\nbegin\n  sorry\nend\n\n-- This is another one\nexample (f : X \u2192 Y) (g : Y \u2192 Z) : \n  surjective (g \u2218 f) \u2192 surjective g :=\nbegin\n  sorry\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2021/functions/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.9046505434556232, "lm_q1q2_score": 0.747885269924836}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Kenny Lau\n-/\n\nimport algebra.geom_sum\nimport ring_theory.ideal.quotient\n\n/-!\n# Basic results in number theory\n\nThis file should contain basic results in number theory. So far, it only contains the essential\nlemma in the construction of the ring of Witt vectors.\n\n## Main statement\n\n`dvd_sub_pow_of_dvd_sub` proves that for elements `a` and `b` in a commutative ring `R` and for\nall natural numbers `p` and `k` if `p` divides `a-b` in `R`, then `p ^ (k + 1)` divides\n`a ^ (p ^ k) - b ^ (p ^ k)`.\n-/\n\nsection\n\nopen ideal ideal.quotient\n\nlemma dvd_sub_pow_of_dvd_sub {R : Type*} [comm_ring R] {p : \u2115}\n  {a b : R} (h : (p : R) \u2223 a - b) (k : \u2115) :\n  (p^(k+1) : R) \u2223 a^(p^k) - b^(p^k) :=\nbegin\n  induction k with k ih,\n  { rwa [pow_one, pow_zero, pow_one, pow_one] },\n  rw [pow_succ' p k, pow_mul, pow_mul, \u2190 geom_sum\u2082_mul, pow_succ],\n  refine mul_dvd_mul _ ih,\n  let I : ideal R := span {p},\n  let f : R \u2192+* R \u29f8 I := mk I,\n  have hp : (p : R \u29f8 I) = 0,\n  { rw [\u2190 f.map_nat_cast, eq_zero_iff_mem, mem_span_singleton] },\n  rw [\u2190 mem_span_singleton, \u2190 ideal.quotient.eq] at h,\n  rw [\u2190 mem_span_singleton, \u2190 eq_zero_iff_mem, ring_hom.map_geom_sum\u2082,\n      ring_hom.map_pow, ring_hom.map_pow, h, geom_sum\u2082_self, hp, zero_mul],\nend\n\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.826711787666479, "lm_q1q2_score": 0.7478852653371284}}
{"text": "import tactic\n\n-- BEGIN\nvariables {\u03b1 : Type*} [partial_order \u03b1]\nvariables a b : \u03b1\n\nexample : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\nbegin\n  rw lt_iff_le_not_le,\n  split,\n    intro hl,\n    split,\n    cases hl with hl1 hl2,\n    exact hl1,\n    contrapose! hl,\n    intro h',\n    rw hl,\n\n    intro hr,\n    cases hr with hr1 hr2,\n    split, \n    exact hr1,\n    contrapose! hr2,\n    exact le_antisymm hr1 hr2,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/5_split/5.3_iff & conjunc/ex2_split_altb.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091156, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7478496805943387}}
{"text": "/-\nCOMP2009 Tutorial 2\n-/\n\nvariables P Q R : Prop\n\n/-\nWhat is a logic?\nA particular system or codification of the principles of proof and inference.\n* Propositional logic - a formal system where formulae are built by joining\n  propositions using logical connectives.\n* Classical logic - logic based on truth value (uses truth tables).\n* Intuitionistic logic - logic based on evidence. \n* Predicate logic - extends propositional logic and will be covered next week. \n\nClassical Logic = Intuitionistic Logic + Excluded Middle (em P : P \u2228 \u00ac P)\n\nIt turns out that excluded middle is equivalent to another law, double\nnegation elimination/reductio ad absurdum (raa P : \u00ac \u00ac P \u2192 P).\n\nThe basic tactics seen so far in Lean have all been intuitionistic. In order\nto prove classical logic formulae, we have to tell Lean we want to work in\nclassical logic and access EM by doing the following.\n-/\n\nopen classical\n\n-- This makes the following available.\n\n-- #check (em P)\n\n--------------------------------------------------------------------------------\n-- PART I : EM & RAA\n\n-- Proof that EM (P \u2228 \u00ac P) implies RAA (\u00ac \u00ac P \u2192 P)\n\ntheorem raa : \u00ac \u00ac P \u2192 P := \nbegin\n    assume nnp,\n    /-\n        nnp : \u00ac \u00ac P\n        \u22a2 P\n    -/\n    cases (em P) with p np,\n    /-\n        (Case 1)\n        nnp : \u00ac \u00ac P\n        p : P\n        \u22a2 P\n\n        (Case 2)\n        nnp : \u00ac \u00ac P\n        p : \u00ac P\n        \u22a2 P\n    -/\n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    have f : false,\n    /-\n        (Case 2.1)\n        nnp : \u00ac \u00ac P\n        p : \u00ac P\n        \u22a2 false\n\n        (Case 2.2)\n        nnp : \u00ac \u00ac P\n        p : \u00ac P\n        f : false\n        \u22a2 P\n    -/\n    apply nnp,\n    /-\n        (Case 2.1)\n        nnp : \u00ac \u00ac P\n        p : \u00ac P\n        \u22a2 \u00ac P\n\n        (Case 2.2)\n        nnp : \u00ac \u00ac P\n        p : \u00ac P\n        f : false\n        \u22a2 P\n    -/\n    exact np,\n    /-\n        Gets rid of Case 2.1\n    -/\n    cases f,\n    /-\n        No goals (Gets rid of Case 2.2)\n    -/\nend\n\n-- #check raa\n\n-- Proof that RAA (\u00ac \u00ac P \u2192 P) implies EM (P \u2228 \u00ac P) \n-- (requires an auxiliary proof)\n\ntheorem nn_em : \u00ac \u00ac (P \u2228 \u00ac P) :=\nbegin   \n    assume npnp,\n    /-\n        npnp : \u00ac (P \u2228 \u00ac P)\n        \u22a2 false\n    -/   \n    apply npnp,\n    /-\n        npnp : \u00ac (P \u2228 \u00ac P)\n        \u22a2 P \u2228 \u00ac P\n    -/\n    right,\n    /-\n        npnp : \u00ac (P \u2228 \u00ac P)\n        \u22a2 \u00ac P\n    -/\n    assume p,\n    /-\n        npnp : \u00ac (P \u2228 \u00ac P)\n        p : P\n        \u22a2 false\n    -/\n    apply npnp,\n    /-\n        npnp : \u00ac (P \u2228 \u00ac P)\n        p : P\n        \u22a2 P \u2228 \u00ac P\n    -/\n    left,\n    /-\n        npnp : \u00ac (P \u2228 \u00ac P)\n        p : P\n        \u22a2 P \n    -/\n    exact p,\n    /-\n        No goals\n    -/\nend  \n\ntheorem my_em : P \u2228 \u00ac P :=\nbegin\n  apply raa (P \u2228 \u00ac P),\n  apply nn_em,\nend \n\n-- Any classical logic formula can be proved by assuming either one\n-- of EM or RAA.\n\n------------------------------------------------------------------------------\n-- PART II: Examples\n\n/-\n3 possible cases: \n* A) provable intuitionistically\n* B) provable classically\n* C) not provable \n-/     \n\n-- A) Intuitionistic\ntheorem example_1 : ((P \u2228 Q) \u2227 \u00ac P) \u2192 Q :=\nbegin\n    assume hyp,\n    /-\n        hyp : P \u2228 Q \u2227 \u00ac P\n        \u22a2 Q\n    -/\n    cases hyp with pq np,\n    /-\n        pq : P \u2228 Q \n        np : \u00ac P\n        \u22a2 Q\n    -/\n    cases pq with p q,\n    /-\n        (Case P)\n        p : P \n        np : \u00ac P\n        \u22a2 Q\n\n       (Case Q)\n        q : Q \n        np : \u00ac P\n        \u22a2 Q \n    -/\n    have f : false,\n    /-\n        (Case P.1)\n        p : P \n        np : \u00ac P\n        \u22a2 false\n\n        (Case P.2)\n        p : P \n        np : \u00ac P\n        f : false\n        \u22a2 Q\n\n       (Case Q)\n        q : Q \n        np : \u00ac P\n        \u22a2 Q \n    -/\n    apply np,\n    /-\n        (Case P.1)\n        p : P \n        np : \u00ac P\n        \u22a2 P\n\n        (Case P.2)\n        p : P \n        np : \u00ac P\n        f : false\n        \u22a2 Q\n\n       (Case Q)\n        q : Q \n        np : \u00ac P\n        \u22a2 Q \n    -/\n    exact p,\n    /-\n        Gets rid of Case P.1\n    -/ \n    cases f,\n    /-\n        Gets rid of Case P.2\n    -/\n    exact q,\n    /-\n        No goals (Gets is of Case Q)\n    -/\nend  \n-- B) Classical\ntheorem example_2_em : (\u00ac P \u2192 Q) \u2192 (\u00ac Q \u2192 P) :=\n-- contrapositive: (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P)\nbegin\n    assume np2q,\n    assume nq,\n    /-\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        \u22a2 P\n    -/\n    cases (em P) with p np,\n    /-\n        (Case p)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        p : P\n        \u22a2 P\n\n        (Case np)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        np : \u00ac P\n        \u22a2 P\n    -/\n    exact p,\n    /-\n        Gets rid of Case p\n    -/\n    have f : false,\n    /-\n        (Case np, f.1)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        np : \u00ac P\n        \u22a2 false\n\n        (Case np, f.2)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        np : \u00ac P\n        f : false\n        \u22a2 P\n    -/\n    apply nq,\n    /-\n        (Case np, f.1)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        np : \u00ac P\n        \u22a2 Q\n\n        (Case np, f.2)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        np : \u00ac P\n        f : false\n        \u22a2 P\n    -/\n    apply np2q,\n    /-\n        (Case np, f.1)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        np : \u00ac P\n        \u22a2 \u00ac P\n\n        (Case np, f.2)\n        np2q : \u00ac P \u2192 Q\n        nq : \u00ac Q\n        np : \u00ac P\n        f : false\n        \u22a2 P\n    -/\n    exact np,\n    /-\n        Gets rid of Case np\n    -/\n    cases f,\n    /-\n        No goals (Gets rid of Case np, f.2)\n    -/\nend \n\ntheorem example_2_raa : (\u00ac P \u2192 Q) \u2192 (\u00ac Q \u2192 P) :=\nbegin\n    assume np2q,\n    assume nq,\n    /-\n        np2q : \u00ac P \u2192 Q  \n        nq : \u00ac Q\n        \u22a2 P\n    -/\n    apply raa,\n    /-\n        np2q : \u00ac P \u2192 Q  \n        nq : \u00ac Q\n        \u22a2 \u00ac\u00ac P\n    -/\n    assume np,\n    /-\n        np2q : \u00ac P \u2192 Q  \n        nq : \u00ac Q\n        np : \u00ac P \n        \u22a2 false\n    -/\n    apply nq,\n    /-\n        np2q : \u00ac P \u2192 Q  \n        nq : \u00ac Q\n        np : \u00ac P \n        \u22a2 Q\n    -/\n    apply np2q,\n    /-\n        np2q : \u00ac P \u2192 Q  \n        nq : \u00ac Q\n        np : \u00ac P \n        \u22a2 \u00ac P\n    -/\n    exact np,\n    /-\n        No goals\n    -/\nend\n\n/-\nP | \u00ac P | P \u2228 \u00ac P | \u00ac (P \u2228 \u00ac P)\nT |  F  |   T     |    F\nF |  T  |   T     |    F\n-/\n\n-- C) Not provable\ntheorem example_3 : \u00ac (P \u2228 \u00ac P) :=\nbegin\n  sorry,\nend\n\n-- B) Classical\ntheorem example_4_em : (\u00ac P \u2192 P) \u2192 P :=\nbegin\n    assume np2p,\n    /-\n        np2p : \u00ac P \u2192 P\n        \u22a2 P\n    -/\n    cases (em P) with p np,\n    /-\n        (Case p)\n        np2p : \u00ac P \u2192 P\n        p : P\n        \u22a2 P\n\n        (Case np)\n        np2p : \u00ac P \u2192 P\n        np : \u00acP\n        \u22a2 P\n    -/\n    exact p,\n    /-\n        Gets rid of Case p\n    -/\n    apply np2p,\n    /-\n        (Case np)\n        np2p : \u00ac P \u2192 P\n        np : \u00acP\n        \u22a2 \u00acP\n    -/\n    exact np,\n    /-\n        No goals (Gets rid of Case np)\n    -/\nend  \n\ntheorem example_4_raa : (\u00ac P \u2192 P) \u2192 P :=\nbegin\n    assume np2p,\n    /-\n        np2p : \u00ac P \u2192 P\n        \u22a2 P\n    -/\n    apply raa,\n    /-\n        np2p : \u00ac P \u2192 P\n        \u22a2 \u00ac\u00ac P\n    -/\n    assume np,\n    /-\n        np2p : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 false\n    -/\n    apply np,\n    /-\n        np2p : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 P \n    -/\n    apply np2p,\n    /-\n        np2p : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 \u00ac P \n    -/\n    exact np,\n    /-\n        No goals\n    -/\nend\n\n/-\nTips:\n* using truth tables tells us whether something is provable or not, but does \n  not tell us whether it is provable intuitionistically or classically \n* when trying to prove something intuitionistically, think of witnesses/evidence\n  e.g. \u00ac (P \u2227 Q) \u2192 (\u00ac P \u2228 \u00ac Q) vs (\u00ac P \u2228 \u00ac Q) \u2192 \u00ac (P \u2227 Q)\n  have f : P \u2227 Q \u2192 false\n  want either g : P \u2192 false or h : Q \u2192 false\n  not provable intuitionistically\n  --\n  have either f : P \u2192 false or g : Q \u2192 false\n  want h : P \u2227 Q \u2192 false\n  provable intuitionistically\n-/\n", "meta": {"author": "BraxWong", "repo": "lean_Rev", "sha": "c626bda0d38477f95ba4edaf20b9eaa034375c48", "save_path": "github-repos/lean/BraxWong-lean_Rev", "path": "github-repos/lean/BraxWong-lean_Rev/lean_Rev-c626bda0d38477f95ba4edaf20b9eaa034375c48/tutorial2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7478463498456703}}
{"text": "/-\nCopyright (c) 2020 Gihan Marasingha. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gihan Marasingha\n-/\nimport tactic.linarith\n\n/-!\n# An MIU Decision Procedure in Lean\n\nThe [MIU formal system](https://en.wikipedia.org/wiki/MU_puzzle) was introduced by Douglas\nHofstadter in the first chapter of his 1979 book,\n[G\u00f6del, Escher, Bach](https://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bach).\nThe system is defined by four rules of inference, one axiom, and an alphabet of three symbols:\n`M`, `I`, and `U`.\n\nHofstadter's central question is: can the string `\"MU\"` be derived?\n\nIt transpires that there is a simple decision procedure for this system. A string is derivable if\nand only if it starts with `M`, contains no other `M`s, and the number of `I`s in the string is\ncongruent to 1 or 2 modulo 3.\n\nThe principal aim of this project is to give a Lean proof that the derivability of a string is a\ndecidable predicate.\n\n## The MIU System\n\nIn Hofstadter's description, an _atom_ is any one of `M`, `I` or `U`. A _string_ is a finite\nsequence of zero or more symbols. To simplify notation, we write a sequence `[I,U,U,M]`,\nfor example, as `IUUM`.\n\nThe four rules of inference are:\n\n1. xI \u2192 xIU,\n2. Mx \u2192 Mxx,\n3. xIIIy \u2192 xUy,\n4. xUUy \u2192 xy,\n\nwhere the notation \u03b1 \u2192 \u03b2 is to be interpreted as 'if \u03b1 is derivable, then \u03b2 is derivable'.\n\nAdditionally, he has an axiom:\n\n* `MI` is derivable.\n\nIn Lean, it is natural to treat the rules of inference and the axiom on an equal footing via an\ninductive data type `derivable` designed so that `derviable x` represents the notion that the string\n`x` can be derived from the axiom by the rules of inference. The axiom is represented as a\nnonrecursive constructor for `derivable`. This mirrors the translation of Peano's axiom '0 is a\nnatural number' into the nonrecursive constructor `zero` of the inductive type `nat`.\n\n## References\n\n* [Jeremy Avigad, Leonardo de Moura and Soonho Kong, _Theorem Proving in Lean_][avigad_moura_kong-2017]\n* [Douglas R Hofstadter, _G\u00f6del, Escher, Bach_][Hofstadter-1979]\n\n## Tags\n\nmiu, derivable strings\n\n-/\n\nnamespace miu\n\n/-!\n### Declarations and instance derivations for `miu_atom` and `miustr`\n-/\n\n/--\nThe atoms of MIU can be represented as an enumerated type in Lean.\n-/\n@[derive decidable_eq]\ninductive miu_atom : Type\n| M : miu_atom\n| I : miu_atom\n| U : miu_atom\n\n/-!\nThe annotation `@[derive decidable_eq]` above assigns the attribute `derive` to `miu_atom`, through\nwhich Lean automatically derives that `miu_atom` is an instance of `decidable_eq`. The use of\n`derive` is crucial in this project and will lead to the automatic derivation of decidability.\n-/\n\nopen miu_atom\n\n/--\nWe show that the type `miu_atom` is inhabited, giving `M` (for no particular reason) as the default\nelement.\n-/\ninstance miu_atom_inhabited : inhabited miu_atom :=\ninhabited.mk M\n\n/--\n`miu_atom.repr` is the 'natural' function from `miu_atom` to `string`.\n-/\ndef miu_atom.repr : miu_atom \u2192 string\n| M := \"M\"\n| I := \"I\"\n| U := \"U\"\n\n/--\nUsing `miu_atom.repr`, we prove that ``miu_atom` is an instance of `has_repr`.\n-/\ninstance : has_repr miu_atom :=\n\u27e8\u03bb u, u.repr\u27e9\n\n/--\nFor simplicity, an `miustr` is just a list of elements of type `miu_atom`.\n-/\n@[derive [has_append, has_mem miu_atom]]\ndef miustr := list miu_atom\n\n/--\nFor display purposes, an `miustr` can be represented as a `string`.\n-/\ndef miustr.mrepr : miustr \u2192 string\n| [] := \"\"\n| (c::cs) := c.repr ++ (miustr.mrepr cs)\n\ninstance miurepr : has_repr miustr :=\n\u27e8\u03bb u, u.mrepr\u27e9\n\n/--\nIn the other direction, we set up a coercion from `string` to `miustr`.\n-/\ndef lchar_to_miustr : (list char) \u2192 miustr\n| [] := []\n| (c::cs) :=\n  let ms := lchar_to_miustr cs in\n  match c with\n  | 'M' := M::ms\n  | 'I' := I::ms\n  | 'U' := U::ms\n  |  _  := []\n  end\n\ninstance string_coe_miustr : has_coe string miustr :=\n\u27e8\u03bb st, lchar_to_miustr st.data \u27e9\n\n/-!\n### Derivability\n-/\n\n/--\nThe inductive type `derivable` has five constructors. The nonrecursive constructor `mk` corresponds\nto Hofstadter's axiom that `\"MI\"` is derivable. Each of the constructors `r1`, `r2`, `r3`, `r4`\ncorresponds to the one of Hofstadter's rules of inference.\n-/\ninductive derivable : miustr \u2192 Prop\n| mk : derivable \"MI\"\n| r1 {x} : derivable (x ++ [I]) \u2192 derivable (x ++ [I, U])\n| r2 {x} : derivable (M :: x) \u2192 derivable (M :: x ++ x)\n| r3 {x y} : derivable (x ++ [I, I, I] ++ y) \u2192 derivable (x ++ U :: y)\n| r4 {x y} : derivable (x ++ [U, U] ++ y) \u2192 derivable (x ++ y)\n\n/-!\n### Rule usage examples\n-/\n\nexample (h : derivable \"UMI\") : derivable \"UMIU\" :=\nbegin\n  change (\"UMIU\" : miustr) with [U,M] ++ [I,U],\n  exact derivable.r1 h, -- Rule 1\nend\n\nexample (h : derivable \"MIIU\") : derivable \"MIIUIIU\" :=\nbegin\n  change (\"MIIUIIU\" : miustr) with M :: [I,I,U] ++ [I,I,U],\n  exact derivable.r2 h, -- Rule 2\nend\n\nexample (h : derivable \"UIUMIIIMMM\") : derivable \"UIUMUMMM\" :=\nbegin\n  change (\"UIUMUMMM\" : miustr) with [U,I,U,M] ++ U :: [M,M,M],\n  exact derivable.r3 h, -- Rule 3\nend\n\nexample (h : derivable \"MIMIMUUIIM\") : derivable \"MIMIMIIM\" :=\nbegin\n  change (\"MIMIMIIM\" : miustr) with [M,I,M,I,M] ++ [I,I,M],\n  exact derivable.r4 h, -- Rule 4\nend\n\n/-!\n### Derivability examples\n-/\n\nprivate lemma MIU_der : derivable \"MIU\":=\nbegin\n  change (\"MIU\" :miustr) with [M] ++ [I,U],\n  apply derivable.r1, -- reduce to deriving \"MI\",\n  constructor, -- which is the base of the inductive construction.\nend\n\nexample : derivable \"MIUIU\" :=\nbegin\n  change (\"MIUIU\" : miustr) with M :: [I,U] ++ [I,U],\n  exact derivable.r2 MIU_der, -- `\"MIUIU\"` can be derived as `\"MIU\"` can.\nend\n\nexample : derivable \"MUI\" :=\nbegin\n  have h\u2082 : derivable \"MII\",\n  { change (\"MII\" : miustr) with M :: [I] ++ [I],\n    exact derivable.r2 derivable.mk, },\n  have h\u2083 : derivable \"MIIII\",\n  { change (\"MIIII\" : miustr) with M :: [I,I] ++ [I,I],\n    exact derivable.r2 h\u2082, },\n  change (\"MUI\" : miustr) with [M] ++ U :: [I],\n  exact derivable.r3 h\u2083, -- We prove our main goal using rule 3\nend\n\nend miu\n", "meta": {"author": "gihanmarasingha", "repo": "miu_language", "sha": "ffc2a1d4b33e76098578f3617b9b0a699dbcc885", "save_path": "github-repos/lean/gihanmarasingha-miu_language", "path": "github-repos/lean/gihanmarasingha-miu_language/miu_language-ffc2a1d4b33e76098578f3617b9b0a699dbcc885/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7478463489965844}}
{"text": "import .Funcion_inversa\n\nuniverses u v                          \nvariables {\u03b1 : Type u} [inhabited \u03b1]   \nvariables {\u03b2 : Type v}                 \nvariable  f : \u03b1 \u2192 \u03b2\nvariable  g : \u03b2 \u2192 \u03b1\nvariable  x : \u03b1\n\nopen set function\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que g es la inversa por la izquierda de f syss\n--    \u2200 x, g (f x) = x\n-- ----------------------------------------------------------------------\n\nexample : left_inverse g f \u2194 \u2200 x, g (f x) = x :=\nby rw left_inverse\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que las siguientes condiciones son equivalentes:\n-- 1. f es inyectiva\n-- 2. left_inverse (inverse f) f\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : injective f \u2194 left_inverse (inverse f) f  :=\nbegin\n  split,\n  { intros h y,\n    apply h,\n    apply inverse_spec,\n    use y },\n  { intros h x1 x2 e,\n    rw \u2190h x1, \n    rw \u2190h x2, \n    rw e },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u,\n_inst_1 : inhabited \u03b1,\n\u03b2 : Type v,\nf : \u03b1 \u2192 \u03b2\n\u22a2 injective f \u2194 left_inverse (inverse f) f\n  >> split,\n| \u22a2 injective f \u2192 left_inverse (inverse f) f\n|   >> { intros h y,\n| h : injective f,\n| y : \u03b1\n| \u22a2 inverse f (f y) = y\n|   >>   apply h,\n| \u22a2 f (inverse f (f y)) = f y\n|   >>   apply inverse_spec,\n| \u22a2 \u2203 (x : \u03b1), f x = f y\n|   >>   use y },\n\u22a2 left_inverse (inverse f) f \u2192 injective f\n  >> { intros h x1 x2 e,\nh : left_inverse (inverse f) f,\nx1 x2 : \u03b1,\ne : f x1 = f x2\n\u22a2 x1 = x2\n  >>   rw \u2190h x1,\n\u22a2 inverse f (f x1) = x2 \n  >>   rw \u2190h x2, \n\u22a2 inverse f (f x1) = inverse f (f x2)\n  >>   rw e },\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : injective f \u2194 left_inverse (inverse f) f  :=\n\u27e8\u03bb h y, h (inverse_spec _ \u27e8y, rfl\u27e9), \n \u03bb h x1 x2 e, by rw [\u2190h x1, \u2190h x2, e]\u27e9\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Caracterizacion_de_las_funciones_inyectivas_mediante_la_inversa_por_la_izquierda.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7478463463934913}}
{"text": "/-\nCopyright (c) 2022 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module data.set.pointwise.list_of_fn\n! leanprover-community/mathlib commit f694c7dead66f5d4c80f446c796a5aad14707f0e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Pointwise.Basic\nimport Mathlib.Data.List.OfFn\n\n/-!\n# Pointwise operations with lists of sets\n\nThis file proves some lemmas about pointwise algebraic operations with lists of sets.\n-/\n\nnamespace Set\n\nvariable {F \u03b1 \u03b2 \u03b3 : Type _}\n\nvariable [Monoid \u03b1] {s t : Set \u03b1} {a : \u03b1} {m n : \u2115}\n\nopen Pointwise\n\n@[to_additive]\ntheorem mem_prod_list_ofFn {a : \u03b1} {s : Fin n \u2192 Set \u03b1} :\n    a \u2208 (List.ofFn s).prod \u2194 \u2203 f : \u2200 i : Fin n, s i, (List.ofFn fun i \u21a6 (f i : \u03b1)).prod = a :=\n  by\n  induction' n with n ih generalizing a\n  \u00b7 simp_rw [List.ofFn_zero, List.prod_nil, Fin.exists_fin_zero_pi, eq_comm, Set.mem_one]\n  \u00b7\n    simp_rw [List.ofFn_succ, List.prod_cons, Fin.exists_fin_succ_pi, Fin.cons_zero, Fin.cons_succ,\n      mem_mul, @ih, exists_and_left, exists_exists_eq_and, SetCoe.exists, Subtype.coe_mk,\n      exists_prop]\n#align set.mem_prod_list_of_fn Set.mem_prod_list_ofFn\n#align set.mem_sum_list_of_fn Set.mem_sum_list_ofFn\n\n@[to_additive]\ntheorem mem_list_prod {l : List (Set \u03b1)} {a : \u03b1} :\n    a \u2208 l.prod \u2194\n      \u2203 l' : List (\u03a3s : Set \u03b1, \u21a5s),\n        List.prod (l'.map fun x \u21a6 (Sigma.snd x : \u03b1)) = a \u2227 l'.map Sigma.fst = l :=\n  by\n  induction' l using List.ofFnRec with n f\n  simp only [mem_prod_list_ofFn, List.exists_iff_exists_tuple, List.map_ofFn, Function.comp,\n    List.ofFn_inj', Sigma.mk.inj_iff, and_left_comm, exists_and_left, exists_eq_left, heq_eq_eq]\n  constructor\n  \u00b7 rintro \u27e8fi, rfl\u27e9\n    exact \u27e8fun i \u21a6 \u27e8_, fi i\u27e9, rfl, rfl\u27e9\n  \u00b7 rintro \u27e8fi, rfl, rfl\u27e9\n    exact \u27e8fun i \u21a6 _, rfl\u27e9\n#align set.mem_list_prod Set.mem_list_prod\n#align set.mem_list_sum Set.mem_list_sum\n\n@[to_additive]\ntheorem mem_pow {a : \u03b1} {n : \u2115} :\n    a \u2208 s ^ n \u2194 \u2203 f : Fin n \u2192 s, (List.ofFn fun i \u21a6 (f i : \u03b1)).prod = a := by\n  rw [\u2190 mem_prod_list_ofFn, List.ofFn_const, List.prod_replicate]\n#align set.mem_pow Set.mem_pow\n#align set.mem_nsmul Set.mem_nsmul\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Pointwise/ListOfFn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7478463455257934}}
{"text": "import data.real.basic\n--- sub_nonneg {x y : \u211d} : 0 \u2264 y - x \u2194 x \u2264 y\n\nexample {a b c : \u211d} (hab : a \u2264 b) : c + a \u2264 c + b :=\nbegin\n  rw \u2190 sub_nonneg,\n  have key : (c + b) - (c + a) = b - a, by {ring},\n  rw key,\n  rw sub_nonneg,\n  exact hab,\nend\n \nexample {a b c : \u211d} (hab : a \u2264 b) : c + a \u2264 c + b := \nbegin \n  apply add_le_add_left hab,\nend\n\nexample {a b : \u211d} (ha : 0 \u2264 a) : b \u2264 a + b :=\nbegin\n  calc\n    b   = 0 + b : by {ring}\n    ... \u2264 a + b : by {exact add_le_add_right ha b},\nend\n\nexample {a b : \u211d} (hb: 0 \u2264 b) : a \u2264 a + b :=\nbegin\n  calc\n    a   = a + 0 : by {ring}\n    ... \u2264 a + b : by {exact add_le_add_left hb a},\nend\n\n\n-- le_add_of_nonneg_left  {a b : \u211d} (ha : 0 \u2264 a) : b \u2264 a + b\n-- le_add_of_nonneg_right {a b : \u211d} (hb : 0 \u2264 b) : a \u2264 a + b\nexample {a b : \u211d} (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a + b :=\nbegin\n  calc  \n    0   \u2264 a     : ha\n    ... \u2264 a + b : le_add_of_nonneg_right hb,\nend\n\nexample {a b c d : \u211d} (hab : a \u2264 b) (hcd : c \u2264 d) : a + c \u2264 b + d :=\nbegin\n  calc\n    a + c \u2264 b + c : by {exact add_le_add_right hab c}\n    ...   \u2264 b + d : by {exact add_le_add_left hcd b},\nend\n\nexample {a b c : \u211d} (hc : 0 \u2264 c) (hab : a \u2264 b) : a*c \u2264 b*c :=\nbegin\n  rw \u2190 sub_nonneg,\n  have key : b * c - a * c = (b - a) * c := by ring,\n  rw key,\n  apply mul_nonneg, -- {x y : \u211d} (hx : 0 \u2264 x) (hy : 0 \u2264 y) : 0 \u2264 x*y\n  {\n    rw sub_nonneg,\n    exact hab,\n  },\n  {\n    exact hc\n  }\nend\n\nexample {a b c : \u211d} (hc : 0 \u2264 c) (hab : a \u2264 b) : a*c \u2264 b*c :=\nbegin\n  have hab' : 0 \u2264 b - a, {rwa \u2190 sub_nonneg at hab}, -- `rw \u2190 sub_nonneg at hab; exact hab`\n  have h\u2081 : 0 \u2264 (b-a)*c, {exact mul_nonneg hab' hc},\n  have h\u2082 : (b-a)*c = b*c - a*c, by ring,\n  have h\u2083 : 0 \u2264 b*c - a*c, by rwa h\u2082 at h\u2081,\n  rwa sub_nonneg at h\u2083,\nend\n\nexample {a b c : \u211d} (hc : 0 \u2264 c) (hab : a \u2264 b) : a*c \u2264 b*c :=\nbegin\n  rw \u2190 sub_nonneg,\n  calc\n    0   \u2264 (b-a)*c   : mul_nonneg (by rwa sub_nonneg) hc\n    ... = b*c - a*c : by ring,\nend\n\nexample {a b c : \u211d} (hc : c \u2264 0) (hab : a \u2264 b) : b*c \u2264 a*c :=\nbegin\n  rw \u2190 sub_nonpos at hab,\n  rw \u2190 sub_nonneg,\n  have key : a * c - b * c = (a - b) * c := by ring,\n  rw key,\n  exact (mul_nonneg_of_nonpos_of_nonpos hab hc), \nend\n\n-- le_add_of_nonneg_left (a b : \u211d) : 0 \u2264 a \u2192 b \u2264 a + b\nexample {a b : \u211d} : 0 \u2264 a \u2192 b \u2264 a + b := le_add_of_nonneg_left\n\nexample {a b : \u211d} : 0 \u2264 b \u2192 a \u2264 a + b := \nbegin\n  intros h,\n  calc\n    a   = a + 0 : by {ring}\n    ... \u2264 a + b : by {exact add_le_add_left h a},\nend\n\nexample {a b : \u211d} : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b :=\nbegin\n  intros h,\n  cases h with ha hb,\n  exact add_nonneg ha hb,\nend\n\nexample {a b : \u211d} : 0 \u2264 a \u2192 0 \u2264 b \u2192 (0 \u2264 a + b) := add_nonneg\n\nexample {a b : \u211d} (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\nbegin\n  intros ha hb,\n  apply H,\n  split,\n  exact ha,\n  exact hb,\nend\n\nexample (P Q R : Prop) : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  intro h,\n  cases h with hp hq,\n  split,\n  exact hq,\n  exact hp,\nend\n\nexample {a b : \u211d} (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\nbegin\n  intros ha hb,\n  exact H \u27e8 ha, hb \u27e9,\nend\n\nexample (P Q R : Prop): P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  rintros \u27e8h\u2081, h\u2082\u27e9,\n  exact \u27e8h\u2082, h\u2081\u27e9,\nend\n\nexample {P Q R : Prop} : (P \u2227 Q \u2192 R) \u2194 (P \u2192 Q \u2192 R) :=\nbegin\n  split,\n  intros h,\n  intros hp hq,\n  apply h,\n  split,\n  exact hp,\n  exact hq,\n\n  intros h,\n  intros hpq,\n  cases hpq with hp hq,\n  apply h,\n  exact hp,\n  exact hq,\nend\n\n\nexample (a b : \u211d) (hb : 0 \u2264 b) : a \u2264 a + b :=\nbegin\n  linarith,\nend", "meta": {"author": "SnO2WMaN", "repo": "lean3-tutorial", "sha": "6d276aab5b386329f6d79a94ee09315389fb51fa", "save_path": "github-repos/lean/SnO2WMaN-lean3-tutorial", "path": "github-repos/lean/SnO2WMaN-lean3-tutorial/lean3-tutorial-6d276aab5b386329f6d79a94ee09315389fb51fa/src/02_iff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985636, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.7478456740380158}}
{"text": "import algebra.group.basic\nimport data.bracket\n\n/- # The simplifier\nUp till now we have been using `rewrite` to manually instruct Lean which steps to take one at a time.\nThis is a very useful tool, but after a while you will notice that there are some rewrites that\nwill always make things easier when substituted.\nFor example we almost always want to use the fact that multiplying by 1 or adding 0 doesn't\nchange things.\n-/\n\n/- Tactic : simp\n\n## Summary\n\nThe `simp` tactic is a high-level tactic which tries\nto prove equalities using facts in its database.\n\n## Details\n\nThe `simp` tactic does basic automation.\nFor example, some proofs involve a tedious number of rewrites of `add_assoc` and `add_comm`, \nthe same is true of `mul_assoc` and `mul_comm` in the case of multiplication. \nWe can use `simp` to do this automatically. \nTo tell `simp` to use some lemma `h` when simplifying, write `simp[h]`. More generally, \nfor `simp` to include additional lemmas `h1`, `h2`, ..., `hn` when simplifying, write \n`simp[h1, h2, ..., hn]`. \n\n### Example:\nIf our goal is this:\n```\n\u22a2 a + b + c + d + e = a + (b + (c + d) + e)\n```\n\nwe can solve this with `simp` using `simp[add_assoc]`. \n\n### Example:\nIf our goal is this:\n```\n\u22a2 a * b * c = c * b * a\n```\n-/\n/-\n\n\n# Commutator identities\n\nIn these exercises we will write the proofs of the identities in\n<https://en.wikipedia.org/wiki/Commutator#Identities_(group_theory)>\nin Lean.\n\nFirst we will set up the basic definitions, in World 1, we didn't make any new mathematical\ndefinitions, we just made use of the natural numbers, propositions, and some lemmas Lean\nalready knew about.\n\n-/\nnotation `[`x`, `y`]` := has_bracket.bracket x y -- hide\ndefinition commutator {G : Type*} [group G] (x y : G) : G := x\u207b\u00b9 * y\u207b\u00b9 * x * y\ninstance group.has_bracket {G : Type*} [group G] : has_bracket G G := \u27e8commutator\u27e9 -- hide\ndefinition conjugate {G : Type*} [group G] (x y : G) : G := y\u207b\u00b9 * x * y\ninstance group.has_pow {G : Type*} [group G] : has_pow G G := \u27e8conjugate\u27e9 -- hide\n/- Axiom : The definition of commutator\ncommutator_def : [x, y] = x\u207b\u00b9 * y\u207b\u00b9 * x * y\n-/\nlemma commutator_def {G : Type*} [group G] {x y : G} : [x, y] = x\u207b\u00b9 * y\u207b\u00b9 * x * y := rfl\n/- Axiom : The definition of conjugate\nconjugate_def : y^x = x\u207b\u00b9 * y * x := rfl\n-/\nlemma conjugate_def {G : Type*} [group G] {x y : G} : y^x = x\u207b\u00b9 * y * x := rfl\n\n/- Axiom : cancelling inverses on the right\ninv_mul_cancel_right : \u2200 {G : Type} [_inst_1 : group G] (a b : G), a * b\u207b\u00b9 * b = a\n-/\n\n/- Axiom : cancelling an element with its own inverse\ninv_mul_self : \u2200 {G : Type} [_inst_1 : group G] (a : G), a\u207b\u00b9 * a = 1\n-/\n\n/-\nRemember to check out the panel on the left for some useful lemmas\n-/\n\n/- Lemma :\n-/\n@[simp]\nlemma commutator_self {G : Type} [group G] {x : G} : [x, x] = 1 :=\nbegin\n  rw commutator_def,\n  rw inv_mul_cancel_right,\n  rw inv_mul_self,\n\n\n\n\nend\n", "meta": {"author": "alexjbest", "repo": "CAP-game", "sha": "d823def7325d7142d61e766b2e027f936685a8ff", "save_path": "github-repos/lean/alexjbest-CAP-game", "path": "github-repos/lean/alexjbest-CAP-game/CAP-game-d823def7325d7142d61e766b2e027f936685a8ff/src/simplifier/level_commutator_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.8539127510928477, "lm_q1q2_score": 0.7478456683358178}}
{"text": "/-\nCopyright (c) 2021 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta, Alena Gusakov, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module combinatorics.set_family.shadow\n! leanprover-community/mathlib commit f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Slice\nimport Mathlib.Logic.Function.Iterate\n\n/-!\n# Shadows\n\nThis file defines shadows of a set family. The shadow of a set family is the set family of sets we\nget by removing any element from any set of the original family. If one pictures `finset \u03b1` as a big\nhypercube (each dimension being membership of a given element), then taking the shadow corresponds\nto projecting each finset down once in all available directions.\n\n## Main definitions\n\n* `Finset.shadow`: The shadow of a set family. Everything we can get by removing a new element from\n  some set.\n* `Finset.up_shadow`: The upper shadow of a set family. Everything we can get by adding an element\n  to some set.\n\n## Notation\n\nWe define notation in locale `FinsetFamily`:\n* `\u2202 \ud835\udc9c`: Shadow of `\ud835\udc9c`.\n* `\u2202\u207a \ud835\udc9c`: Upper shadow of `\ud835\udc9c`.\n\nWe also maintain the convention that `a, b : \u03b1` are elements of the ground type, `s, t : finset \u03b1`\nare finsets, and `\ud835\udc9c, \u212c : finset (finset \u03b1)` are finset families.\n\n## References\n\n* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf\n* http://discretemath.imp.fu-berlin.de/DMII-2015-16/kruskal.pdf\n\n## Tags\n\nshadow, set family\n-/\n\n\nopen Finset Nat\n\nvariable {\u03b1 : Type _}\n\nnamespace Finset\n\nsection Shadow\n\nvariable [DecidableEq \u03b1] {\ud835\udc9c : Finset (Finset \u03b1)} {s t : Finset \u03b1} {a : \u03b1} {k r : \u2115}\n\n/-- The shadow of a set family `\ud835\udc9c` is all sets we can get by removing one element from any set in\n`\ud835\udc9c`, and the (`k` times) iterated shadow (`shadow^[k]`) is all sets we can get by removing `k`\nelements from any set in `\ud835\udc9c`. -/\ndef shadow (\ud835\udc9c : Finset (Finset \u03b1)) : Finset (Finset \u03b1) :=\n  \ud835\udc9c.sup fun s => s.image (erase s)\n#align finset.shadow Finset.shadow\n\n-- mathport name: finset.shadow\n-- Porting note: added `inherit_doc` to calm linter\n@[inherit_doc] scoped[FinsetFamily] notation:90 \"\u2202 \" => Finset.shadow\n-- Porting note: had to open FinsetFamily\nopen FinsetFamily\n\n/-- The shadow of the empty set is empty. -/\n@[simp]\ntheorem shadow_empty : (\u2202 ) (\u2205 : Finset (Finset \u03b1)) = \u2205 :=\n  rfl\n#align finset.shadow_empty Finset.shadow_empty\n\n@[simp]\ntheorem shadow_singleton_empty : (\u2202 ) ({\u2205} : Finset (Finset \u03b1)) = \u2205 :=\n  rfl\n#align finset.shadow_singleton_empty Finset.shadow_singleton_empty\n\n--TODO: Prove `\u2202 {{a}} = {\u2205}` quickly using `covers` and `grade_order`\n/-- The shadow is monotone. -/\n@[mono]\ntheorem shadow_monotone : Monotone (shadow : Finset (Finset \u03b1) \u2192 Finset (Finset \u03b1)) := fun _ _ =>\n  sup_mono\n#align finset.shadow_monotone Finset.shadow_monotone\n\n/-- `s` is in the shadow of `\ud835\udc9c` iff there is an `t \u2208 \ud835\udc9c` from which we can remove one element to\nget `s`. -/\ntheorem mem_shadow_iff : s \u2208 (\u2202 ) \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, \u2203 a \u2208 t, erase t a = s := by\n  simp only [shadow, mem_sup, mem_image]\n#align finset.mem_shadow_iff Finset.mem_shadow_iff\n\ntheorem erase_mem_shadow (hs : s \u2208 \ud835\udc9c) (ha : a \u2208 s) : erase s a \u2208 (\u2202 ) \ud835\udc9c :=\n  mem_shadow_iff.2 \u27e8s, hs, a, ha, rfl\u27e9\n#align finset.erase_mem_shadow Finset.erase_mem_shadow\n\n/-- `t` is in the shadow of `\ud835\udc9c` iff we can add an element to it so that the resulting finset is in\n`\ud835\udc9c`. -/\ntheorem mem_shadow_iff_insert_mem : s \u2208 (\u2202 ) \ud835\udc9c \u2194 \u2203 (a : _)(_ : a \u2209 s), insert a s \u2208 \ud835\udc9c := by\n  refine' mem_shadow_iff.trans \u27e8_, _\u27e9\n  \u00b7 rintro \u27e8s, hs, a, ha, rfl\u27e9\n    refine' \u27e8a, not_mem_erase a s, _\u27e9\n    rwa [insert_erase ha]\n  \u00b7 rintro \u27e8a, ha, hs\u27e9\n    exact \u27e8insert a s, hs, a, mem_insert_self _ _, erase_insert ha\u27e9\n#align finset.mem_shadow_iff_insert_mem Finset.mem_shadow_iff_insert_mem\n\n/-- The shadow of a family of `r`-sets is a family of `r - 1`-sets. -/\nprotected theorem Set.Sized.shadow (h\ud835\udc9c : (\ud835\udc9c : Set (Finset \u03b1)).Sized r) :\n    ((\u2202 ) \ud835\udc9c : Set (Finset \u03b1)).Sized (r - 1) := by\n  intro A h\n  obtain \u27e8A, hA, i, hi, rfl\u27e9 := mem_shadow_iff.1 h\n  rw [card_erase_of_mem hi, h\ud835\udc9c hA]\n#align finset.set.sized.shadow Finset.Set.Sized.shadow\n\ntheorem sized_shadow_iff (h : \u2205 \u2209 \ud835\udc9c) :\n    ((\u2202 ) \ud835\udc9c : Set (Finset \u03b1)).Sized r \u2194 (\ud835\udc9c : Set (Finset \u03b1)).Sized (r + 1) := by\n  refine' \u27e8fun h\ud835\udc9c s hs => _, Set.Sized.shadow\u27e9\n  obtain \u27e8a, ha\u27e9 := nonempty_iff_ne_empty.2 (ne_of_mem_of_not_mem hs h)\n  rw [\u2190 h\ud835\udc9c (erase_mem_shadow hs ha), card_erase_add_one ha]\n#align finset.sized_shadow_iff Finset.sized_shadow_iff\n\n/-- `s \u2208 \u2202 \ud835\udc9c` iff `s` is exactly one element less than something from `\ud835\udc9c` -/\ntheorem mem_shadow_iff_exists_mem_card_add_one :\n    s \u2208 (\u2202 ) \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, s \u2286 t \u2227 t.card = s.card + 1 := by\n  refine' mem_shadow_iff_insert_mem.trans \u27e8_, _\u27e9\n  \u00b7 rintro \u27e8a, ha, hs\u27e9\n    exact \u27e8insert a s, hs, subset_insert _ _, card_insert_of_not_mem ha\u27e9\n  \u00b7 rintro \u27e8t, ht, hst, h\u27e9\n    obtain \u27e8a, ha\u27e9 : \u2203 a, t \\ s = {a} :=\n      card_eq_one.1 (by rw [card_sdiff hst, h, add_tsub_cancel_left])\n    exact\n      \u27e8a, fun hat => not_mem_sdiff_of_mem_right hat ((ha.ge : _ \u2286 _) <| mem_singleton_self a), by\n        rwa [insert_eq a s, \u2190 ha, sdiff_union_of_subset hst]\u27e9\n#align finset.mem_shadow_iff_exists_mem_card_add_one Finset.mem_shadow_iff_exists_mem_card_add_one\n\n/-- Being in the shadow of `\ud835\udc9c` means we have a superset in `\ud835\udc9c`. -/\ntheorem exists_subset_of_mem_shadow (hs : s \u2208 (\u2202 ) \ud835\udc9c) : \u2203 t \u2208 \ud835\udc9c, s \u2286 t :=\n  let \u27e8t, ht, hst\u27e9 := mem_shadow_iff_exists_mem_card_add_one.1 hs\n  \u27e8t, ht, hst.1\u27e9\n#align finset.exists_subset_of_mem_shadow Finset.exists_subset_of_mem_shadow\n\n/-- `t \u2208 \u2202^k \ud835\udc9c` iff `t` is exactly `k` elements less than something in `\ud835\udc9c`. -/\ntheorem mem_shadow_iff_exists_mem_card_add :\n    s \u2208 (\u2202 ^[k]) \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, s \u2286 t \u2227 t.card = s.card + k := by\n  induction' k with k ih generalizing \ud835\udc9c s\n  \u00b7 refine' \u27e8fun hs => \u27e8s, hs, Subset.refl _, rfl\u27e9, _\u27e9\n    rintro \u27e8t, ht, hst, hcard\u27e9\n    rwa [eq_of_subset_of_card_le hst hcard.le]\n  simp only [exists_prop, Function.comp_apply, Function.iterate_succ]\n  refine' ih.trans _\n  clear ih\n  constructor\n  \u00b7 rintro \u27e8t, ht, hst, hcardst\u27e9\n    obtain \u27e8u, hu, htu, hcardtu\u27e9 := mem_shadow_iff_exists_mem_card_add_one.1 ht\n    refine' \u27e8u, hu, hst.trans htu, _\u27e9\n    rw [hcardtu, hcardst]\n    rfl\n  \u00b7 rintro \u27e8t, ht, hst, hcard\u27e9\n    obtain \u27e8u, hsu, hut, hu\u27e9 :=\n      Finset.exists_intermediate_set k\n        (by\n          rw [add_comm, hcard]\n          exact le_succ _)\n        hst\n    rw [add_comm] at hu\n    refine' \u27e8u, mem_shadow_iff_exists_mem_card_add_one.2 \u27e8t, ht, hut, _\u27e9, hsu, hu\u27e9\n    rw [hcard, hu]\n    rfl\n#align finset.mem_shadow_iff_exists_mem_card_add Finset.mem_shadow_iff_exists_mem_card_add\n\nend Shadow\n\nopen FinsetFamily\n\nsection UpShadow\n\nvariable [DecidableEq \u03b1] [Fintype \u03b1] {\ud835\udc9c : Finset (Finset \u03b1)} {s t : Finset \u03b1} {a : \u03b1} {k r : \u2115}\n\n/-- The upper shadow of a set family `\ud835\udc9c` is all sets we can get by adding one element to any set in\n`\ud835\udc9c`, and the (`k` times) iterated upper shadow (`up_shadow^[k]`) is all sets we can get by adding\n`k` elements from any set in `\ud835\udc9c`. -/\ndef upShadow (\ud835\udc9c : Finset (Finset \u03b1)) : Finset (Finset \u03b1) :=\n  \ud835\udc9c.sup fun s => s\u1d9c.image fun a => insert a s\n#align finset.up_shadow Finset.upShadow\n\n-- mathport name: finset.up_shadow\n-- Porting note: added `inheric_doc` to calm linter\n@[inherit_doc] scoped[FinsetFamily] notation:90 \"\u2202\u207a \" => Finset.upShadow\n\n/-- The upper shadow of the empty set is empty. -/\n@[simp]\ntheorem upShadow_empty : (\u2202\u207a ) (\u2205 : Finset (Finset \u03b1)) = \u2205 :=\n  rfl\n#align finset.up_shadow_empty Finset.upShadow_empty\n\n/-- The upper shadow is monotone. -/\n@[mono]\ntheorem upShadow_monotone : Monotone (upShadow : Finset (Finset \u03b1) \u2192 Finset (Finset \u03b1)) :=\n  fun _ _ => sup_mono\n#align finset.up_shadow_monotone Finset.upShadow_monotone\n\n/-- `s` is in the upper shadow of `\ud835\udc9c` iff there is an `t \u2208 \ud835\udc9c` from which we can remove one element\nto get `s`. -/\ntheorem mem_upShadow_iff : s \u2208 (\u2202\u207a ) \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, \u2203 (a : _)(_ : a \u2209 t), insert a t = s := by\n  simp_rw [upShadow, mem_sup, mem_image, exists_prop, mem_compl]\n#align finset.mem_up_shadow_iff Finset.mem_upShadow_iff\n\ntheorem insert_mem_upShadow (hs : s \u2208 \ud835\udc9c) (ha : a \u2209 s) : insert a s \u2208 (\u2202\u207a ) \ud835\udc9c :=\n  mem_upShadow_iff.2 \u27e8s, hs, a, ha, rfl\u27e9\n#align finset.insert_mem_up_shadow Finset.insert_mem_upShadow\n\n/-- The upper shadow of a family of `r`-sets is a family of `r + 1`-sets. -/\nprotected theorem Set.Sized.upShadow (h\ud835\udc9c : (\ud835\udc9c : Set (Finset \u03b1)).Sized r) :\n    ((\u2202\u207a ) \ud835\udc9c : Set (Finset \u03b1)).Sized (r + 1) := by\n  intro A h\n  obtain \u27e8A, hA, i, hi, rfl\u27e9 := mem_upShadow_iff.1 h\n  rw [card_insert_of_not_mem hi, h\ud835\udc9c hA]\n#align finset.set.sized.up_shadow Finset.Set.Sized.upShadow\n\n/-- `t` is in the upper shadow of `\ud835\udc9c` iff we can remove an element from it so that the resulting\nfinset is in `\ud835\udc9c`. -/\ntheorem mem_upShadow_iff_erase_mem : s \u2208 (\u2202\u207a ) \ud835\udc9c \u2194 \u2203 a \u2208 s, s.erase a \u2208 \ud835\udc9c := by\n  refine' mem_upShadow_iff.trans \u27e8_, _\u27e9\n  \u00b7 rintro \u27e8s, hs, a, ha, rfl\u27e9\n    refine' \u27e8a, mem_insert_self a s, _\u27e9\n    rwa [erase_insert ha]\n  \u00b7 rintro \u27e8a, ha, hs\u27e9\n    exact \u27e8s.erase a, hs, a, not_mem_erase _ _, insert_erase ha\u27e9\n#align finset.mem_up_shadow_iff_erase_mem Finset.mem_upShadow_iff_erase_mem\n\n/-- `s \u2208 \u2202\u207a \ud835\udc9c` iff `s` is exactly one element less than something from `\ud835\udc9c`. -/\ntheorem mem_upShadow_iff_exists_mem_card_add_one :\n    s \u2208 (\u2202\u207a ) \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, t \u2286 s \u2227 t.card + 1 = s.card := by\n  refine' mem_upShadow_iff_erase_mem.trans \u27e8_, _\u27e9\n  \u00b7 rintro \u27e8a, ha, hs\u27e9\n    exact \u27e8s.erase a, hs, erase_subset _ _, card_erase_add_one ha\u27e9\n  \u00b7 rintro \u27e8t, ht, hts, h\u27e9\n    obtain \u27e8a, ha\u27e9 : \u2203 a, s \\ t = {a} :=\n      card_eq_one.1 (by rw [card_sdiff hts, \u2190 h, add_tsub_cancel_left])\n    refine' \u27e8a, sdiff_subset _ _ ((ha.ge : _ \u2286 _) <| mem_singleton_self a), _\u27e9\n    rwa [\u2190 sdiff_singleton_eq_erase, \u2190 ha, sdiff_sdiff_eq_self hts]\n#align finset.mem_up_shadow_iff_exists_mem_card_add_one Finset.mem_upShadow_iff_exists_mem_card_add_one\n\n/-- Being in the upper shadow of `\ud835\udc9c` means we have a superset in `\ud835\udc9c`. -/\ntheorem exists_subset_of_mem_upShadow (hs : s \u2208 (\u2202\u207a ) \ud835\udc9c) : \u2203 t \u2208 \ud835\udc9c, t \u2286 s :=\n  let \u27e8t, ht, hts, _\u27e9 := mem_upShadow_iff_exists_mem_card_add_one.1 hs\n  \u27e8t, ht, hts\u27e9\n#align finset.exists_subset_of_mem_up_shadow Finset.exists_subset_of_mem_upShadow\n\n/-- `t \u2208 \u2202^k \ud835\udc9c` iff `t` is exactly `k` elements more than something in `\ud835\udc9c`. -/\ntheorem mem_upShadow_iff_exists_mem_card_add :\n    s \u2208 (\u2202\u207a ^[k]) \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, t \u2286 s \u2227 t.card + k = s.card := by\n  induction' k with k ih generalizing \ud835\udc9c s\n  \u00b7 refine' \u27e8fun hs => \u27e8s, hs, Subset.refl _, rfl\u27e9, _\u27e9\n    rintro \u27e8t, ht, hst, hcard\u27e9\n    rwa [\u2190 eq_of_subset_of_card_le hst hcard.ge]\n  simp only [exists_prop, Function.comp_apply, Function.iterate_succ]\n  refine' ih.trans _\n  clear ih\n  constructor\n  \u00b7 rintro \u27e8t, ht, hts, hcardst\u27e9\n    obtain \u27e8u, hu, hut, hcardtu\u27e9 := mem_upShadow_iff_exists_mem_card_add_one.1 ht\n    refine' \u27e8u, hu, hut.trans hts, _\u27e9\n    rw [\u2190 hcardst, \u2190 hcardtu, add_right_comm]\n    rfl\n  \u00b7 rintro \u27e8t, ht, hts, hcard\u27e9\n    obtain \u27e8u, htu, hus, hu\u27e9 :=\n      Finset.exists_intermediate_set 1\n        (by\n          rw [add_comm, \u2190 hcard]\n          exact add_le_add_left (succ_le_of_lt (zero_lt_succ _)) _)\n        hts\n    rw [add_comm] at hu\n    refine' \u27e8u, mem_upShadow_iff_exists_mem_card_add_one.2 \u27e8t, ht, htu, hu.symm\u27e9, hus, _\u27e9\n    rw [hu, \u2190 hcard, add_right_comm]\n    rfl\n#align finset.mem_up_shadow_iff_exists_mem_card_add Finset.mem_upShadow_iff_exists_mem_card_add\n\n@[simp]\ntheorem shadow_image_compl : ((\u2202 ) \ud835\udc9c).image compl = (\u2202\u207a ) (\ud835\udc9c.image compl) := by\n  ext s\n  simp only [mem_image, exists_prop, mem_shadow_iff, mem_upShadow_iff]\n  constructor\n  \u00b7 rintro \u27e8_, \u27e8s, hs, a, ha, rfl\u27e9, rfl\u27e9\n    exact \u27e8s\u1d9c, \u27e8s, hs, rfl\u27e9, a, not_mem_compl.2 ha, compl_erase.symm\u27e9\n  \u00b7 rintro \u27e8_, \u27e8s, hs, rfl\u27e9, a, ha, rfl\u27e9\n    exact \u27e8s.erase a, \u27e8s, hs, a, not_mem_compl.1 ha, rfl\u27e9, compl_erase\u27e9\n#align finset.shadow_image_compl Finset.shadow_image_compl\n\n@[simp]\ntheorem upShadow_image_compl : ((\u2202\u207a ) \ud835\udc9c).image compl = (\u2202 ) (\ud835\udc9c.image compl) := by\n  ext s\n  simp only [mem_image, exists_prop, mem_shadow_iff, mem_upShadow_iff]\n  constructor\n  \u00b7 rintro \u27e8_, \u27e8s, hs, a, ha, rfl\u27e9, rfl\u27e9\n    exact \u27e8s\u1d9c, \u27e8s, hs, rfl\u27e9, a, mem_compl.2 ha, compl_insert.symm\u27e9\n  \u00b7 rintro \u27e8_, \u27e8s, hs, rfl\u27e9, a, ha, rfl\u27e9\n    exact \u27e8insert a s, \u27e8s, hs, a, mem_compl.1 ha, rfl\u27e9, compl_insert\u27e9\n#align finset.up_shadow_image_compl Finset.upShadow_image_compl\n\nend UpShadow\n\nend Finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/SetFamily/Shadow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7478149208004228}}
{"text": "/-\nCopyright (c) 2021 Gabriel Moise. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gabriel Moise, Ya\u00ebl Dillies, Kyle Miller\n-/\nimport combinatorics.simple_graph.basic\nimport data.matrix.basic\n\n/-!\n# Incidence matrix of a simple graph\n\nThis file defines the unoriented incidence matrix of a simple graph.\n\n## Main definitions\n\n* `simple_graph.inc_matrix`: `G.inc_matrix R` is the incidence matrix of `G` over the ring `R`.\n\n## Main results\n\n* `simple_graph.inc_matrix_mul_transpose_diag`: The diagonal entries of the product of\n  `G.inc_matrix R` and its transpose are the degrees of the vertices.\n* `simple_graph.inc_matrix_mul_transpose`: Gives a complete description of the product of\n  `G.inc_matrix R` and its transpose; the diagonal is the degrees of each vertex, and the\n  off-diagonals are 1 or 0 depending on whether or not the vertices are adjacent.\n* `simple_graph.inc_matrix_transpose_mul_diag`: The diagonal entries of the product of the\n  transpose of `G.inc_matrix R` and `G.inc_matrix R` are `2` or `0` depending on whether or\n  not the unordered pair is an edge of `G`.\n\n## Implementation notes\n\nThe usual definition of an incidence matrix has one row per vertex and one column per edge.\nHowever, this definition has columns indexed by all of `sym2 \u03b1`, where `\u03b1` is the vertex type.\nThis appears not to change the theory, and for simple graphs it has the nice effect that every\nincidence matrix for each `simple_graph \u03b1` has the same type.\n\n## TODO\n\n* Define the oriented incidence matrices for oriented graphs.\n* Define the graph Laplacian of a simple graph using the oriented incidence matrix from an\n  arbitrary orientation of a simple graph.\n-/\n\nopen finset matrix simple_graph sym2\nopen_locale big_operators matrix\n\nnamespace simple_graph\nvariables (R : Type*) {\u03b1 : Type*} (G : simple_graph \u03b1)\n\n/-- `G.inc_matrix R` is the `\u03b1 \u00d7 sym2 \u03b1` matrix whose `(a, e)`-entry is `1` if `e` is incident to\n`a` and `0` otherwise. -/\nnoncomputable def inc_matrix [has_zero R] [has_one R] : matrix \u03b1 (sym2 \u03b1) R :=\n\u03bb a, (G.incidence_set a).indicator 1\n\nvariables {R}\n\nlemma inc_matrix_apply [has_zero R] [has_one R] {a : \u03b1} {e : sym2 \u03b1} :\n  G.inc_matrix R a e = (G.incidence_set a).indicator 1 e := rfl\n\n/-- Entries of the incidence matrix can be computed given additional decidable instances. -/\nlemma inc_matrix_apply' [has_zero R] [has_one R] [decidable_eq \u03b1] [decidable_rel G.adj]\n  {a : \u03b1} {e : sym2 \u03b1} :\n  G.inc_matrix R a e = if e \u2208 G.incidence_set a then 1 else 0 :=\nby convert rfl\n\nsection mul_zero_one_class\nvariables [mul_zero_one_class R] {a b : \u03b1} {e : sym2 \u03b1}\n\nlemma inc_matrix_apply_mul_inc_matrix_apply :\n  G.inc_matrix R a e * G.inc_matrix R b e = (G.incidence_set a \u2229 G.incidence_set b).indicator 1 e :=\nbegin\n  classical,\n  simp only [inc_matrix, set.indicator_apply, \u2190ite_and_mul_zero,\n    pi.one_apply, mul_one, set.mem_inter_iff],\nend\n\nlemma inc_matrix_apply_mul_inc_matrix_apply_of_not_adj (hab : a \u2260 b) (h : \u00ac G.adj a b) :\n  G.inc_matrix R a e * G.inc_matrix R b e = 0 :=\nbegin\n  rw [inc_matrix_apply_mul_inc_matrix_apply, set.indicator_of_not_mem],\n  rw [G.incidence_set_inter_incidence_set_of_not_adj h hab],\n  exact set.not_mem_empty e,\nend\n\nlemma inc_matrix_of_not_mem_incidence_set (h : e \u2209 G.incidence_set a) :\n  G.inc_matrix R a e = 0 :=\nby rw [inc_matrix_apply, set.indicator_of_not_mem h]\n\nlemma inc_matrix_of_mem_incidence_set (h : e \u2208 G.incidence_set a) : G.inc_matrix R a e = 1 :=\nby rw [inc_matrix_apply, set.indicator_of_mem h, pi.one_apply]\n\nvariables [nontrivial R]\n\nlemma inc_matrix_apply_eq_zero_iff : G.inc_matrix R a e = 0 \u2194 e \u2209 G.incidence_set a :=\nbegin\n  simp only [inc_matrix_apply, set.indicator_apply_eq_zero, pi.one_apply, one_ne_zero],\n  exact iff.rfl,\nend\n\nlemma inc_matrix_apply_eq_one_iff : G.inc_matrix R a e = 1 \u2194 e \u2208 G.incidence_set a :=\nby { convert one_ne_zero.ite_eq_left_iff, apply_instance }\n\nend mul_zero_one_class\n\nsection non_assoc_semiring\nvariables [fintype \u03b1] [non_assoc_semiring R] {a b : \u03b1} {e : sym2 \u03b1}\n\nlemma sum_inc_matrix_apply [decidable_eq \u03b1] [decidable_rel G.adj] :\n  \u2211 e, G.inc_matrix R a e = G.degree a :=\nby simp [inc_matrix_apply', sum_boole, set.filter_mem_univ_eq_to_finset]\n\nlemma inc_matrix_mul_transpose_diag [decidable_eq \u03b1] [decidable_rel G.adj] :\n  (G.inc_matrix R \u2b1d (G.inc_matrix R)\u1d40) a a = G.degree a :=\nbegin\n  rw \u2190sum_inc_matrix_apply,\n  simp [matrix.mul_apply, inc_matrix_apply', \u2190ite_and_mul_zero],\nend\n\nlemma sum_inc_matrix_apply_of_mem_edge_set : e \u2208 G.edge_set \u2192 \u2211 a, G.inc_matrix R a e = 2 :=\nbegin\n  classical,\n  refine e.ind _,\n  intros a b h,\n  rw mem_edge_set at h,\n  rw [\u2190nat.cast_two, \u2190card_doubleton h.ne],\n  simp only [inc_matrix_apply', sum_boole, mk_mem_incidence_set_iff, h, true_and],\n  congr' 2,\n  ext e,\n  simp only [mem_filter, mem_univ, true_and, mem_insert, mem_singleton],\nend\n\nlemma sum_inc_matrix_apply_of_not_mem_edge_set (h : e \u2209 G.edge_set) : \u2211 a, G.inc_matrix R a e = 0 :=\nsum_eq_zero $ \u03bb a _, G.inc_matrix_of_not_mem_incidence_set $ \u03bb he, h he.1\n\nlemma inc_matrix_transpose_mul_diag [decidable_rel G.adj] :\n  ((G.inc_matrix R)\u1d40 \u2b1d G.inc_matrix R) e e = if e \u2208 G.edge_set then 2 else 0 :=\nbegin\n  classical,\n  simp only [matrix.mul_apply, inc_matrix_apply', transpose_apply, \u2190ite_and_mul_zero,\n    one_mul, sum_boole, and_self],\n  split_ifs with h,\n  { revert h,\n    refine e.ind _,\n    intros v w h,\n    rw [\u2190nat.cast_two, \u2190card_doubleton (G.ne_of_adj h)],\n    simp [mk_mem_incidence_set_iff, G.mem_edge_set.mp h],\n    congr' 2,\n    ext u,\n    simp, },\n  { revert h,\n    refine e.ind _,\n    intros v w h,\n    simp [mk_mem_incidence_set_iff, G.mem_edge_set.not.mp h], },\nend\n\nend non_assoc_semiring\n\nsection semiring\nvariables [fintype (sym2 \u03b1)] [semiring R] {a b : \u03b1} {e : sym2 \u03b1}\n\nlemma inc_matrix_mul_transpose_apply_of_adj (h : G.adj a b) :\n  (G.inc_matrix R \u2b1d (G.inc_matrix R)\u1d40) a b = (1 : R) :=\nbegin\n  classical,\n  simp_rw [matrix.mul_apply, matrix.transpose_apply, inc_matrix_apply_mul_inc_matrix_apply,\n    set.indicator_apply, pi.one_apply, sum_boole],\n  convert nat.cast_one,\n  convert card_singleton \u27e6(a, b)\u27e7,\n  rw [\u2190coe_eq_singleton, coe_filter_univ],\n  exact G.incidence_set_inter_incidence_set_of_adj h,\nend\n\nlemma inc_matrix_mul_transpose [fintype \u03b1] [decidable_eq \u03b1] [decidable_rel G.adj] :\n  G.inc_matrix R \u2b1d (G.inc_matrix R)\u1d40 = \u03bb a b,\n    if a = b then G.degree a else if G.adj a b then 1 else 0 :=\nbegin\n  ext a b,\n  split_ifs with h h',\n  { subst b,\n    convert G.inc_matrix_mul_transpose_diag },\n  { exact G.inc_matrix_mul_transpose_apply_of_adj h' },\n  { simp only [matrix.mul_apply, matrix.transpose_apply,\n    G.inc_matrix_apply_mul_inc_matrix_apply_of_not_adj h h', sum_const_zero] }\nend\n\nend semiring\nend simple_graph\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/simple_graph/inc_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7478149191732556}}
{"text": "import MyNat.Definition\nimport MyNat.Addition -- add_zero\nimport AdvancedAdditionWorld.Level1 -- succ_inj\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Advanced Addition World\n\n## Level 5: `add_right_cancel`\n\nThe theorem `add_right_cancel` is the theorem that you can cancel on the right\nwhen you're doing addition -- if `a + t = b + t` then `a = b`. After `intro h`\nI'd recommend induction on `t`. Don't forget that `rw [add_zero] at h` can be used\nto do rewriting of hypotheses rather than the goal.\n\n## Theorem\nOn the set of natural numbers, addition has the right cancellation property.\nIn other words, if there are natural numbers `a, b` and `c` such that\n` a + t = b + t ` then we have `a = b`.\n-/\ntheorem add_right_cancel (a t b : MyNat) : a + t = b + t \u2192 a = b := by\n  intro h\n  induction t with\n  | zero =>\n    rw [zero_is_0] at h\n    rw [add_zero] at h\n    rw [add_zero] at h\n    exact h\n  | succ d ih =>\n    apply ih\n    rw [add_succ] at h\n    rw [add_succ] at h\n    exact succ_inj h\n\n/-!\nNext up [Level 6](./Level6.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedAdditionWorld/Level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7476924509362892}}
{"text": "-- some definitions before Q3a\n\ntheorem three_not_zero : (3:\u2115) \u2260 0 := by norm_num\ntheorem two_not_zero : (2:\u2115) \u2260 0 := by norm_num\n\ntheorem pow_pos_of_pos (x : fake_reals) (n : \u2115) : (0 < x) \u2192 (0 < n) \u2192 0 < x^n :=\nbegin\nintros Hx_pos Hn_pos,\ncases n with m,\n  revert Hn_pos,norm_num,\nclear Hn_pos,\ninduction m with p Hp,\n  simp [Hx_pos,monoid.pow],\nexact A4 Hx_pos Hp,\nend\n\ntheorem pow_lt_of_lt (x y : fake_reals) (n : \u2115) : (0 < x) \u2192 (x < y) \u2192 (0 < n) \u2192 x ^ n < y^n :=\nbegin\nintros Hx_pos Hx_lt_y Hn_pos,\ncases n with m,\n  exfalso, revert Hn_pos,norm_num,\ninduction m with p Hp,\n  simp [Hx_lt_y,monoid.pow],\nhave H : x^ nat.succ p < y^nat.succ p := Hp (nat.zero_lt_succ p),\nclear Hp Hn_pos,\nchange x ^ nat.succ (nat.succ p) with x * (x^nat.succ p),\nchange y ^ nat.succ (nat.succ p) with y * (y^nat.succ p),\n\nhave H1: x * (x ^ nat.succ p) < y * (x ^ nat.succ p) := calc\nx * (x ^ nat.succ p) = (x ^ nat.succ p) * x : by rw [mul_comm]\n... < (x ^ nat.succ p) * y : mul_pos_lt_of_lt Hx_lt_y (pow_pos_of_pos x (nat.succ p) Hx_pos (nat.zero_lt_succ p))\n... = y * (x ^ nat.succ p) : by rw [mul_comm],\n\nhave H2 : y * (x ^ nat.succ p) < y * (y ^ nat.succ p) := mul_pos_lt_of_lt H (A2 Hx_pos Hx_lt_y),\n\nexact A2 H1 H2\nend\n\ndef n:\u2115 := 1000000000000\n\ndef t3_stuff := A6 3000000000000 (by norm_num) \u21913 (n_pos 3 (three_not_zero))\ndef t2_stuff := A6 2000000000000 (by norm_num) \u21912 (n_pos 2 (two_not_zero))\nnoncomputable def t2 := classical.some t2_stuff\nnoncomputable def t3 := classical.some t3_stuff\ndef t2_facts := classical.some_spec t2_stuff\ndef t3_facts := classical.some_spec t3_stuff\n\n\ntheorem Q3a : t3 > t2 := sorry\n\n-- I've done the next two parts with integers, on the basis that\n-- inequality on the reals extends inequality on the integers.\n\n-- ambiguous overload for power ^ symbol :-(\n-- Could mean nat.pow or pow_nat.\n\n-- Here's something that's in core lean for nat.pow\n-- and we need for pow_nat.\n\ntheorem pow_lt_pow_of_lt {x i j : \u2115} : x > 1 \u2192 i < j \u2192 x^i < x^j :=\nbegin\nrw [\u2190nat.pow_eq_pow,\u2190nat.pow_eq_pow],\nintro H,\nexact nat.pow_lt_pow_of_lt_right H,\nend\n\ntheorem Q3b : 10000^100 < 100^10000 := sorry\n\ntheorem Q3ci : (2^11)^2 = 2^22 := sorry\n\ntheorem Q3cii : (2^(2^21))^2 = 2^(2^22) := sorry\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1F/problem_bank/0303/Q0303.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7476845888461757}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport set_theory.cardinal.basic\n\n/-!\n# Denumerability of \u211a\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves that \u211a is infinite, denumerable, and deduces that it has cardinality `omega`.\n-/\n\nnamespace rat\nopen denumerable\n\ninstance : infinite \u211a :=\ninfinite.of_injective (coe : \u2115 \u2192 \u211a) nat.cast_injective\n\nprivate def denumerable_aux : \u211a \u2243 { x : \u2124 \u00d7 \u2115 // 0 < x.2 \u2227 x.1.nat_abs.coprime x.2 } :=\n{ to_fun := \u03bb x, \u27e8\u27e8x.1, x.2\u27e9, x.3, x.4\u27e9,\n  inv_fun := \u03bb x, \u27e8x.1.1, x.1.2, x.2.1, x.2.2\u27e9,\n  left_inv := \u03bb \u27e8_, _, _, _\u27e9, rfl,\n  right_inv := \u03bb \u27e8\u27e8_, _\u27e9, _, _\u27e9, rfl }\n\n/-- **Denumerability of the Rational Numbers** -/\ninstance : denumerable \u211a :=\nbegin\n  let T := { x : \u2124 \u00d7 \u2115 // 0 < x.2 \u2227 x.1.nat_abs.coprime x.2 },\n  letI : infinite T := infinite.of_injective _ denumerable_aux.injective,\n  letI : encodable T := subtype.encodable,\n  letI : denumerable T := of_encodable_of_infinite T,\n  exact denumerable.of_equiv T denumerable_aux\nend\n\nend rat\n\nopen_locale cardinal\n\nlemma cardinal.mk_rat : #\u211a = \u2135\u2080 := by simp\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/rat/denumerable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7476370540551063}}
{"text": "/-\nCopyright (c) 2022 Matthias Uschold. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Matthias Uschold.\n-/\nimport topology.continuous_function.bounded\n\n\n/-!\n# Some Lemma on boundedness\n\nIn this file, we prove that two notions of boundedness of functions (to \u211d)\nare equivalent.\n\n## Tags\n\nboundedness, bounded function\n\n\n-/\n\nlemma function_bounded_classical\n  {X: Type*}\n  {f: X \u2192 \u211d}\n  : (\u2203 (C:\u211d), \u2200 (x y: X), dist (f x) (f y) \u2264 C )  -- The Lean definition \n  \u2194 (\u2203 (C:\u211d), \u2200 (x:X), abs (f x) \u2264 C )           --classical \n:= begin \n  split,\n  {\n    assume hC,\n    by_cases (is_empty X),\n    {  \n      use 0,\n      assume x,\n      exfalso,\n      exact is_empty_iff.mp h x,\n    },\n    --choose an element\n    let x0 : X := classical.choice (not_is_empty_iff.mp h),\n    rcases hC with \u27e8C, hC\u27e9,\n    use C + |f x0|,\n    assume x :X,\n    calc |f x| = |(f x - f x0) + f x0|\n                  : by simp \n           ... \u2264  |f x - f x0| + |f x0|\n                  : abs_add (f x - f x0) (f x0)\n           ... = dist (f x) (f x0) + |f x0|\n                  : by congr'; exact real.dist_eq (f x) (f x0)\n           ... \u2264 C + |f x0|\n                  : by linarith only [hC x x0],\n  },\n  {\n    assume h,\n    rcases h with \u27e8C, hC\u27e9,\n    use 2*C,\n    assume x y :X,\n    calc  dist (f x) (f y)\n         = |f x - f y|\n          : by exact real.dist_eq _ _ \n    ... \u2264 |f x| + |f y| \n          : abs_sub (f x) (f y)\n    ... \u2264 C + C \n          : by linarith only [hC x, hC y]\n    ... = 2 * C \n          : by ring,\n  }\nend \n\nlemma function_bounded_classical'\n  {X: Type*} \n  [topological_space X]\n  (f: bounded_continuous_function X \u211d)\n  : \u2203 (C:\u211d), \u2200 (x:X), abs (f x) \u2264 C\n:= function_bounded_classical.mp f.bounded   ", "meta": {"author": "matthias567", "repo": "lean-amenable-release", "sha": "32ea6fdbada245e334d6c20288691b454e3922a9", "save_path": "github-repos/lean/matthias567-lean-amenable-release", "path": "github-repos/lean/matthias567-lean-amenable-release/lean-amenable-release-32ea6fdbada245e334d6c20288691b454e3922a9/src/aux_lemmas_bounded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7476370483379026}}
{"text": "import game.sup_inf.rat_complete\n\nnamespace xena --hide \n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 14\n-/\n\n\n/- \nThe Least Upper Bound property implies\nGreatest Lower bound Property\n-/\n\n-- begin hide\n--NOTE: We have a form of the completeness axiom at Sup/Inf World\n--level 13.\n--Here I'll assume LUB property as an axiom, and prove it implies \n--GLB property. But perhaps `axiom` should be avoided. -- GT\n-- end hide\n\ndef is_bdd_above (S : set \u211d) := \u2203 x : \u211d, is_upper_bound S x    \n\ndef is_lower_bound (S : set \u211d) (x : \u211d) := \u2200 s \u2208 S, x \u2264 s\ndef is_bdd_below (S : set \u211d) := \u2203 x : \u211d, is_lower_bound S x\ndef is_glb (S : set \u211d) (x : \u211d) := is_lower_bound S x \u2227 \n\u2200 y : \u211d, is_lower_bound S y \u2192 y \u2264 x\ndef has_glb (S : set \u211d) := \u2203 x : \u211d, is_glb S x\n\n/-\nCompleteness Axiom\n-/\n\naxiom lub_property_reals (S : set \u211d) : \n(S.nonempty \u2227 is_bdd_above S) \u2192 (has_lub S)\n\n/- Lemma\nLUB property implies GLB property\n-/\n\ntheorem glb_property_reals (S: set \u211d) : \n(S.nonempty \u2227 is_bdd_below S) \u2192 has_glb S :=\n\nbegin\nintro hyp,\n\n--define set L of lower bounds of S\nlet L := { x : \u211d | is_lower_bound S x},  \n\n--anything in S is an upper bound of L\nhave fact1: \u2200 x \u2208 S, is_upper_bound L x,\nintros x hypx b hypb,\nexact hypb x hypx,            -- `suggest` provided this line\n\n--hyp.left is the claim that S is nonempty. use this to show\n--that L is bounded above\ncases hyp.left with y hypy, \nhave fact2: is_bdd_above L, use y, exact fact1 y hypy,\n\n-- can now show that L has supremum `a`. Note direct use of hyp.right\n-- (S is bounded below) as proof that L is nonempty\nhave fact3:= lub_property_reals L (and.intro hyp.right fact2),\ncases fact3 with a hypa,\n\n-- we now show that a is the infimum of S\n\nuse a,\nsplit,\n    -- first prove that a is a lower bound for S,\n    {\n    assume z hypz,\n    -- given z \u2208 S, we prove by contradiction that a \u2264 z,\n    by_contradiction claim,\n    push_neg at claim,\n    unfold is_lub at hypa,\n    -- hypa.right says that for any upper bound y of L, a \u2264 y\n    let for_contra := hypa.right z (fact1 z hypz), \n    -- linarith solves our goal - claim and for_contra are contradictory.\n    linarith,\n    },\n\n    -- now prove that for any lower bound x of S, x \u2264 a \n    {\n    intros x hypx,\n    have fact: x \u2208 L, exact hypx,\n    -- hypa.left says that a is an upper bound of L\n    exact hypa.left x hypx,\n    }\n\nend\n\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sup_inf/GLBprop_if_LUBprop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7476370461525657}}
{"text": "import algebra.group.basic\nimport tactic\nimport group_theory.subgroup.basic\nimport data.set_like.basic\nimport chapter2.set_theory_cosets\n\nvariables {A:Type} [semigroup A]\n--if I try to use these proofs on something that is not a semigroup, what would happen? \nlemma lcoset_lcoset (S: set A) (a b : A) : lcoset (A) (b) (lcoset (A) (a) (S)) = lcoset (A) (b*a) (S) := \nbegin\nunfold lcoset,\next x,\nsimp,\nsplit,\n{intro hx, cases hx with s hs_1, cases hs_1 with hs_1 hs_2,\nuse s, split, exact hs_1, rw mul_assoc, exact hs_2,},\n{intro hx, cases hx with s hs_1, cases hs_1 with hs_1 hs_2,\nuse s, split, exact hs_1, rw mul_assoc at hs_2, exact hs_2,},\nend\n\nlemma rcoset_rcoset (S: set A) (a b : A) : rcoset (A) (rcoset (A) (S) (a)) (b) = rcoset (A) (S) (a*b) := \nbegin\nunfold rcoset,\next x,\nsimp,\nsplit,\n{intro hx, cases hx with s hs_1, cases hs_1 with hs_1 hs_2,\nuse s, split, exact hs_1, rw mul_assoc at hs_2, exact hs_2,},\n{intro hx, cases hx with s hs_1, cases hs_1 with hs_1 hs_2,\nuse s, split, exact hs_1, rw mul_assoc, exact hs_2,},\nend\n\n--#print rcoset_rcoset here is my answer to the above question! It knows variable A better be an instance of a semigroup \n\nlemma lcoset_rcoset (S:set A) (a b : A) : rcoset (A) (lcoset (A) (a) (S)) (b) = lcoset (A) (a) (rcoset (A) (S) (b)) :=\nbegin\nunfold lcoset, \nunfold rcoset, \next x, simp, \nsplit, \n{intro hx, cases hx with s hs_1, cases hs_1 with hs_1 hs_2,\nuse s, split, exact hs_1, rw mul_assoc at hs_2, exact hs_2,}, \n{intro hx, cases hx with s hs_1, cases hs_1 with hs_1 hs_2, \nuse s, split, exact hs_1, rw mul_assoc, exact hs_2,},\nend", "meta": {"author": "jam-1057", "repo": "dummit_and_foote_lean", "sha": "1d910d38cad9f2cbb3160d3947d116e93f2a1f14", "save_path": "github-repos/lean/jam-1057-dummit_and_foote_lean", "path": "github-repos/lean/jam-1057-dummit_and_foote_lean/dummit_and_foote_lean-1d910d38cad9f2cbb3160d3947d116e93f2a1f14/src/chapter2/set_theory_cosets_continued_w_semigroups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7476370458729632}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.polynomial.hasse_deriv\n\n/-!\n# Taylor expansions of polynomials\n\n## Main declarations\n\n* `polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`\n* `polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is\n  `(polynomial.hasse_deriv k f).eval r`\n* `polynomial.eq_zero_of_hasse_deriv_eq_zero`:\n  the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero\n\n-/\n\nnoncomputable theory\n\nnamespace polynomial\n\nvariables {R : Type*} [semiring R] (r : R) (f : polynomial R)\n\n/-- The Taylor expansion of a polynomial `f` at `r`. -/\ndef taylor (r : R) : polynomial R \u2192\u2097[R] polynomial R :=\n{ to_fun := \u03bb f, f.comp (X + C r),\n  map_add' := \u03bb f g, add_comp,\n  map_smul' := \u03bb c f, by simp only [smul_eq_C_mul, C_mul_comp, ring_hom.id_apply] }\n\nlemma taylor_apply : taylor r f = f.comp (X + C r) := rfl\n\n@[simp] lemma taylor_X : taylor r X = X + C r :=\nby simp only [taylor_apply, X_comp]\n\n@[simp] lemma taylor_C (x : R) : taylor r (C x) = C x :=\nby simp only [taylor_apply, C_comp]\n\n@[simp] lemma taylor_zero' : taylor (0 : R) = linear_map.id :=\nbegin\n  ext,\n  simp only [taylor_apply, add_zero, comp_X, _root_.map_zero, linear_map.id_comp, function.comp_app,\n             linear_map.coe_comp]\nend\n\nlemma taylor_zero (f : polynomial R) : taylor 0 f = f :=\nby rw [taylor_zero', linear_map.id_apply]\n\n@[simp] lemma taylor_one : taylor r (1 : polynomial R) = C 1 :=\nby rw [\u2190 C_1, taylor_C]\n\n@[simp] lemma taylor_monomial (i : \u2115) (k : R) : taylor r (monomial i k) = C k * (X + C r) ^ i :=\nby simp [taylor_apply]\n\n/-- The `k`th coefficient of `polynomial.taylor r f` is `(polynomial.hasse_deriv k f).eval r`. -/\nlemma taylor_coeff (n : \u2115) : (taylor r f).coeff n = (hasse_deriv n f).eval r :=\nshow (lcoeff R n).comp (taylor r) f = (leval r).comp (hasse_deriv n) f,\nbegin\n  congr' 1, clear f, ext i,\n  simp only [leval_apply, mul_one, one_mul, eval_monomial, linear_map.comp_apply, coeff_C_mul,\n    hasse_deriv_monomial, taylor_apply, monomial_comp, C_1,\n    (commute_X (C r)).add_pow i, linear_map.map_sum],\n  simp only [lcoeff_apply, \u2190 C_eq_nat_cast, mul_assoc, \u2190 C_pow, \u2190 C_mul, coeff_mul_C,\n    (nat.cast_commute _ _).eq, coeff_X_pow, boole_mul, finset.sum_ite_eq, finset.mem_range],\n  split_ifs with h, { refl },\n  push_neg at h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero],\nend\n\n@[simp] lemma taylor_coeff_zero : (taylor r f).coeff 0 = f.eval r :=\nby rw [taylor_coeff, hasse_deriv_zero, linear_map.id_apply]\n\n@[simp] lemma taylor_coeff_one : (taylor r f).coeff 1 = f.derivative.eval r :=\nby rw [taylor_coeff, hasse_deriv_one]\n\n@[simp] lemma nat_degree_taylor (p : polynomial R) (r : R) :\n  nat_degree (taylor r p) = nat_degree p :=\nbegin\n  refine map_nat_degree_eq_nat_degree _ _,\n  nontriviality R,\n  intros n c c0,\n  simp [taylor_monomial, nat_degree_C_mul_eq_of_mul_ne_zero, nat_degree_pow_X_add_C, c0]\nend\n\n@[simp] lemma taylor_mul {R} [comm_semiring R] (r : R) (p q : polynomial R) :\n  taylor r (p * q) = taylor r p * taylor r q :=\nby simp only [taylor_apply, mul_comp]\n\nlemma taylor_taylor {R} [comm_semiring R] (f : polynomial R) (r s : R) :\n  taylor r (taylor s f) = taylor (r + s) f :=\nby simp only [taylor_apply, comp_assoc, map_add, add_comp, X_comp, C_comp, C_add, add_assoc]\n\nlemma taylor_eval {R} [comm_semiring R] (r : R) (f : polynomial R) (s : R) :\n  (taylor r f).eval s = f.eval (s + r) :=\nby simp only [taylor_apply, eval_comp, eval_C, eval_X, eval_add]\n\nlemma taylor_eval_sub {R} [comm_ring R] (r : R) (f : polynomial R) (s : R) :\n  (taylor r f).eval (s - r) = f.eval s :=\nby rw [taylor_eval, sub_add_cancel]\n\nlemma taylor_injective {R} [comm_ring R] (r : R) : function.injective (taylor r) :=\nbegin\n  intros f g h,\n  apply_fun taylor (-r) at h,\n  simpa only [taylor_apply, comp_assoc, add_comp, X_comp, C_comp, C_neg,\n    neg_add_cancel_right, comp_X] using h,\nend\n\n\n\n/-- Taylor's formula. -/\nlemma sum_taylor_eq {R} [comm_ring R] (f : polynomial R) (r : R) :\n  (taylor r f).sum (\u03bb i a, C a * (X - C r) ^ i) = f :=\nby rw [\u2190comp_eq_sum_left, sub_eq_add_neg, \u2190C_neg, \u2190taylor_apply, taylor_taylor, neg_add_self,\n       taylor_zero]\n\nend polynomial\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/polynomial/taylor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7476103108889395}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport linear_algebra.finite_dimensional -- finite-dimensional vector spaces\n\n/-!\n\n# Finite-dimensional vector spaces\n\nHere's how you say \"let `k` be a field and let `V` be a finite-dimensional `k`-vector space\"\n\n-/\n\n-- let k be a field and let V be a k-vector space\nvariables (k : Type) [field k] (V : Type) [add_comm_group V] [module k V] [finite_dimensional k V]\n\n/-\n\nThere are two concepts of \"dimension\" in Lean. There's a general `module.rank k V`, which\nreturns a `cardinal` (so in particular the answer could be one of many kinds of infinity)\nand, in the finite-dimensional case, there is `finite_dimensional.finrank k V`, which returns\na natural number. Note that, as is idiomatic in Lean, the latter function will accept\nan infinite-dimensional space as input (garbage in) and will return 0 for the answer\n(garbage out). All our spaces will be finite-dimensional, so we can use\n`finite_dimensional.finrank`. Note that if we `open finite_dimensional` then we can\njust call it `finrank`. \n\n# An example sheet question\n\nA 2019 University of Edinburgh example sheet question: prove that if `V` is a 9-dimensional\nvector space and `A, B` are two subspaces of dimension 5, then `A \u2229 B` cannot be \nthe zero vector space. See below the question for the API you'll need.\n\n-/\n\nopen finite_dimensional\n\nexample (A B : subspace k V) (hV : finrank k V = 9) (hA : finrank k A = 5) (hB : finrank k B = 5) :\n  A \u2293 B \u2260 \u22a5 :=\nbegin\n  sorry,\nend\n\n/-\n\nHere's some API which you will need for this question. Note that if `A : subspace k V` then\n`A` is a term, not a type, and in particular it's not a vector space (it's a vector subspace).\nHowever `\u21a5A`, a \"coercion to type\", is a type, and hence has a dimension. \n\n## Some API for finite-dimensional vector spaces\n\nThis should be all you need.\n\n`submodule.dim_sup_add_dim_inf_eq A B : finrank k \u21a5(A \u2294 B) + finrank k \u21a5(A \u2293 B) = finrank k \u21a5A + finrank k \u21a5B`\n`submodule.finrank_le A : finrank k \u21a5A \u2264 finrank k V`\n`finrank_bot k V : finrank K \u21a5\u22a5 = 0`\n\n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section11vector_spaces/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7475818631155573}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module algebra.hom.embedding\n! leanprover-community/mathlib commit 70d50ecfd4900dd6d328da39ab7ebd516abe4025\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Defs\nimport Mathlib.Logic.Embedding.Basic\n\n/-!\n# The embedding of a cancellative semigroup into itself by multiplication by a fixed element.\n-/\n\n\nvariable {R : Type _}\n\nsection LeftOrRightCancelSemigroup\n\n/-- The embedding of a left cancellative semigroup into itself\nby left multiplication by a fixed element.\n -/\n@[to_additive (attr := simps)\n      \"The embedding of a left cancellative additive semigroup into itself\n         by left translation by a fixed element.\" ]\ndef mulLeftEmbedding {G : Type _} [LeftCancelSemigroup G] (g : G) : G \u21aa G where\n  toFun h := g * h\n  inj' := mul_right_injective g\n#align mul_left_embedding mulLeftEmbedding\n#align add_left_embedding addLeftEmbedding\n#align add_left_embedding_apply addLeftEmbedding_apply\n#align mul_left_embedding_apply mulLeftEmbedding_apply\n\n/-- The embedding of a right cancellative semigroup into itself\nby right multiplication by a fixed element.\n -/\n@[to_additive (attr := simps)\n      \"The embedding of a right cancellative additive semigroup into itself\n         by right translation by a fixed element.\"]\ndef mulRightEmbedding {G : Type _} [RightCancelSemigroup G] (g : G) : G \u21aa G where\n  toFun h := h * g\n  inj' := mul_left_injective g\n#align mul_right_embedding mulRightEmbedding\n#align add_right_embedding addRightEmbedding\n#align mul_right_embedding_apply mulRightEmbedding_apply\n#align add_right_embedding_apply addRightEmbedding_apply\n\n@[to_additive]\ntheorem mul_left_embedding_eq_mul_right_embedding {G : Type _} [CancelCommMonoid G] (g : G) :\n    mulLeftEmbedding g = mulRightEmbedding g := by\n  ext\n  exact mul_comm _ _\n#align mul_left_embedding_eq_mul_right_embedding mul_left_embedding_eq_mul_right_embedding\n#align add_left_embedding_eq_add_right_embedding add_left_embedding_eq_add_right_embedding\n\nend LeftOrRightCancelSemigroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Hom/Embedding.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894548800271, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7475818605587079}}
{"text": "import .love05_inductive_predicates_demo\nimport .love13_rational_and_real_numbers_demo\n\n\n/- # LoVe Exercise 13: Rational and Real Numbers -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1: Rationals\n\n1.1. Prove the following lemma.\n\nHint: The lemma `fraction.mk.inj_eq` might be useful. -/\n\n#check fraction.mk.inj_eq\n\nlemma fraction.ext (a b : fraction) (hnum : fraction.num a = fraction.num b)\n    (hdenom : fraction.denom a = fraction.denom b) :\n  a = b :=\nsorry\n\n/- 1.2. Extending the `fraction.has_mul` instance from the lecture, declare\n`fraction` as an instance of `semigroup`.\n\nHint: Use the lemma `fraction.ext` above, and possibly `fraction.mul_num`, and\n`fraction.mul_denom`. -/\n\n#check fraction.ext\n#check fraction.mul_num\n#check fraction.mul_denom\n\n@[instance] def fraction.semigroup : semigroup fraction :=\n{ mul_assoc :=\n    sorry,\n  ..fraction.has_mul }\n\n/- 1.3. Extending the `rat.has_mul` instance from the lecture, declare `rat` as\nan instance of `semigroup`. -/\n\n@[instance] def rat.semigroup : semigroup rat :=\n{ mul_assoc :=\n    sorry,\n  ..rat.has_mul }\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love13_rational_and_real_numbers_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7475688099751551}}
{"text": "import tactic\n\n-- injective and surjective functions are already in Lean.\n-- They are called `function.injective` and `function.surjective`.\n-- It gets a bit boring typing `function.` a lot so we start\n-- by opening the `function` namespace\n\nopen function\n\n-- We now move into the `xena` namespace\n\nnamespace xena\n\n-- let X, Y, Z be \"types\", i.e. sets, and let `f : X \u2192 Y` and `g : Y \u2192 Z`\n-- be functions\n\nvariables {X Y Z : Type} {f : X \u2192 Y} {g : Y \u2192 Z}\n\n-- let a,b,x be elements of X, let y be an element of Y and let z be an\n-- element of Z\n\nvariables (a b x : X) (y : Y) (z : Z)\n\n/-!\n# Injective functions\n-/\n\n-- let's start by checking the definition of injective is\n-- what we think it is.\n\nlemma injective_def : injective f \u2194 \u2200 a b : X, f a = f b \u2192 a = b :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- You can now `rw injective_def` to change `injective f` into its definition.\n\n-- The identity function id : X \u2192 X is defined by id(x) = x. Let's check this\n\nlemma id_def : id x = x :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- you can now `rw id_def` to change `id x` into `x`\n\n/-- The identity function is injective -/\nlemma injective_id : injective (id : X \u2192 X) :=\nbegin\n  intros a b h,\n  exact h,\nend\n\n-- function composition g \u2218 f is satisfies (g \u2218 f) (x) = g(f(x)). This\n-- is true by definition. Let's check this\n\nlemma comp_def : (g \u2218 f) x = g (f x) :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-- Composite of two injective functions is injective -/\nlemma injective_comp (hf : injective f) (hg : injective g) : injective (g \u2218 f) :=\nbegin\n  -- you could start with `rw injective_def at *` if you like.\n  -- In some sense it doesn't do anything, but it might make you happier.\n  intros a b h,\n  apply hf, \n  apply hg,\n  exact h,\nend\n\n/-!\n\n### Surjective functions\n\n-/\n\n-- Let's start by checking the definition of surjectivity is what we think it is\n\nlemma surjective_def : surjective f \u2194 \u2200 y : Y, \u2203 x : X, f x = y :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-- The identity function is surjective -/\nlemma surjective_id : surjective (id : X \u2192 X) :=\nbegin\n  -- you can start with `rw surjective_def` if you like.\n  intro b,\n  use b,\n  refl,\nend\n\n-- If you started with `rw surjective_def` -- try deleting it.\n-- Probably your proof still works! This is because\n-- `surjective_def` is true *by definition*. The proof is `refl`.\n\n-- For this next one, the `have` tactic is helpful.\n\n/-- Composite of two surjective functions is surjective -/\nlemma surjective_comp (hf : surjective f) (hg : surjective g) : surjective (g \u2218 f) :=\nbegin\n  intro c,\n  obtain \u27e8b,h\u27e9 := hg c,\n  obtain \u27e8a,h'\u27e9 := hf b,\n  use a, \n  dsimp,\n  rwa [h'],\nend\n\n/-!\n\n### Bijective functions\n\nIn Lean a function is defined to be bijective if it is injective and surjective.\nLet's check this.\n\n-/\n\nlemma bijective_def : bijective f \u2194 injective f \u2227 surjective f :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- You can now use the lemmas you've proved already to make these\n-- proofs very short.\n\n/-- The identity function is bijective. -/\nlemma bijective_id : bijective (id : X \u2192 X) :=\nbegin\n  exact \u27e8injective_id, surjective_id\u27e9,\nend\n\n/-- A composite of bijective functions is bijective. -/\nlemma bijective_comp (hf : bijective f) (hg : bijective g) : bijective (g \u2218 f) :=\nbegin\n  refine \u27e8injective_comp _ _, surjective_comp _ _\u27e9,\n  exact hf.left,\n  exact hg.left,\n  exact hf.right,\n  exact hg.right,\nend\n\nend xena\n", "meta": {"author": "UofSC-Spring-2023-Math-768-001", "repo": "formalising-mathematics", "sha": "5743b4e2904830d2d0febacf3b82d4b5b288717e", "save_path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalising-mathematics", "path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalising-mathematics/formalising-mathematics-5743b4e2904830d2d0febacf3b82d4b5b288717e/src/week_1/Part_C_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7475688033783833}}
{"text": "import Sets.Basic\n\nopen Set\n\nvariable (\u03b1 \u03b2 : Type)\nvariable (X Y Z : Set \u03b1)\nvariable (W : Set \u03b2) \n\n\ntheorem problem1 : \u2205 \u2208 \ud835\udcab  X := sorry \n\ntheorem problem2 (U : \u03b2 \u2192 Set \u03b1) : \u2200 b, U b \u2286 BigUnion U := sorry \n\ntheorem problem3 (h : X \u2286 Y) : (X \u00d7\u02e2 W) \u2286 (Y \u00d7\u02e2 W) := sorry\n\ntheorem problem4 (h : Y \u2229 Z = \u2205) : Y\u1d9c \u222a Z\u1d9c = Univ := sorry \n\ntheorem problem5 : (X \\ Y) \u222a (Y \\ X) = (X \u222a Y) \\ (X \u2229 Y) := sorry \n", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "homework9", "sha": "c26e748a8f91c4f459d6f568a6819b53cd6088a1", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework9", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework9/homework9-c26e748a8f91c4f459d6f568a6819b53cd6088a1/Hw9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9615338123908151, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7474001088071129}}
{"text": "import MyNat.Definition\nimport MyNat.Addition -- add_zero\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport InequalityWorld.Level15 -- lt_aux\u2081\nimport InequalityWorld.Level16 -- lt_aux\u2082\nimport AdvancedAdditionWorld.Level13 -- ne_succ_self\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 17: definition of `<`\n\nOK so we are going to *define* `a < b` by `a \u2264 b \u2227 \u00ac (b \u2264 a)`,\nand given `lt_aux_one a b` and `lt_aux_two a b` it should now just\nbe a few lines to prove `a < b \u2194 succ a \u2264 b`.\n\n## Lemma : lt_iff_succ_le\nFor all naturals `a` and `b`, `a<b \u2194 succ a \u2264 b.`\n-/\nlemma lt_iff_succ_le (a b : MyNat) : a < b \u2194 succ a \u2264 b := by\n  constructor\n  exact lt_aux\u2081 a b\n  exact lt_aux\u2082 a b\n\n/-!\nSadly that is the end of all our nicely documented levels in this tutorial!\n\nInterested in playing levels involving other kinds of mathematics?\nLook <a href=\"https://github.com/ImperialCollegeLondon/natural_number_game/blob/master/WHATS_NEXT.md\"\n  target=\"blank\">here</a> for more ideas about what to do next.\n\nInterested in learning more? Join us on the\n<a href=\"https://leanprover.zulipchat.com/\" target=\"blank\">Zulip Lean chat</a>\nand ask questions in the `#new members` stream. Real names preferred. Be nice.\n-/\n\n/-!\nIf you want to see a whole bunch of great examples see [Level 18](./Level18.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level17.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7473905863751198}}
{"text": "import data.nat\nopen nat\n\ntheorem mul_mod_eq_mod_mul_mod (m n k : nat) : (m * n) mod k = ((m mod k) * n) mod k :=\nby_cases_zero_pos k\n  (by rewrite [*mod_zero])\n  (take k, assume H : k > 0,\n    (calc\n      (m * n) mod k = (((m div k) * k + m mod k) * n) mod k : eq_div_mul_add_mod\n            ... = ((m mod k) * n) mod k                     :\n                    by rewrite [mul.right_distrib, mul.right_comm, add.comm, add_mul_mod_self H]))\n\ntheorem eq_zero_or_eq_one_of_lt_two : \u2200 {n : nat}, n < 2 \u2192 n = 0 \u2228 n = 1 := dec_trivial\n\ndefinition even (n : nat) : Prop := n mod 2 = 0\n\ndefinition odd (n : nat) : Prop := n mod 2 = 1\n\ntheorem even_or_odd (n : nat) : even n \u2228 odd n := eq_zero_or_eq_one_of_lt_two (mod_lt dec_trivial)\n\ntheorem even_of_exists_eq_two_mul {n : nat} (H : \u2203 m, n = 2 * m) : even n :=\nobtain m (H1 : n = 2 * m), from H,\ncalc\n  n mod 2 = 2*m mod 2 : H1\n      ... = 0         : mul_mod_right\n\ntheorem exists_eq_two_mul_of_even {n : nat} (H : even n) : \u2203 m, n = 2 * m :=\nexists.intro (n div 2)\n  (calc\n    n     = (n div 2) * 2 + n mod 2 : eq_div_mul_add_mod\n      ... = 2*(n div 2)             : by rewrite [\u2191even at H, H, add_zero, mul.comm])\n\ntheorem even_of_even_square {n : nat} (H : even (n * n)) : even n :=\nor.elim (even_or_odd n) (assume H, H)\n  (assume H1 : n mod 2 = 1,\n    have H2 : 0 = 1, from calc\n      0     = n * n mod 2           : H\n        ... = ((n mod 2) * n) mod 2 : mul_mod_eq_mod_mul_mod\n        ... = 1                     : by rewrite [H1, one_mul, H1],\n    absurd H2 dec_trivial)\n\ntheorem sqrt2_irrational (m : nat) : \u2200 n : nat, n * n = 2 * m * m \u2192 m = 0 :=\nnat.strong_induction_on m\n  (take m,\n    by_cases_zero_pos m (\u03bb IH n H, rfl)\n      (take m,\n        assume (mpos : m > 0),\n        assume IH : \u2200 {m'}, m' < m \u2192 (\u2200 {n}, n * n = 2 * m' * m' \u2192 m' = 0),\n        take n,\n        assume H : n * n = 2 * m * m,\n        have H1 : even (n * n),\n          from even_of_exists_eq_two_mul (exists.intro _ (eq.subst !mul.assoc H)),\n        have H2 : even n, from even_of_even_square H1,\n        obtain k (H3 : n = 2 * k), from exists_eq_two_mul_of_even H2,\n        have H4 : 2 * (m * m) = 2 * (2 * k * k),\n          by rewrite [-mul.assoc, -H, H3, *mul.assoc, mul.left_comm k],\n        assert H5 : m * m = 2 * k * k, from !eq_of_mul_eq_mul_left dec_trivial H4,\n        have H6 : k < m, from\n          lt_of_not_le\n            (assume H' : k \u2265 m,\n              have H1' : k > 0, from lt_of_lt_of_le mpos H',\n              have H2' : k * k \u2265 m * m, from mul_le_mul H' H',\n              assert H3' : 2 * (k * k) > 1 * (m * m),\n                from mul_lt_mul_of_lt_of_le (mul_pos H1' H1') dec_trivial H2',\n              have H4' : 2 * k * k > 2 * k * k,\n                by revert H3'; rewrite [H5, one_mul, mul.assoc]; intros; assumption,\n              absurd H4' !lt.irrefl),\n        assert H7 : k = 0, from IH H6 H5,\n        have H8 : m * m = 0, by rewrite [H5, H7, mul_zero],\n        show m = 0, from iff.mp !or_self (eq_zero_or_eq_zero_of_mul_eq_zero H8)))", "meta": {"author": "KoenKahlman", "repo": "transfer", "sha": "b7de7b23ed00764dd02b5c6fd715a70c6e0b8374", "save_path": "github-repos/lean/KoenKahlman-transfer", "path": "github-repos/lean/KoenKahlman-transfer/transfer-b7de7b23ed00764dd02b5c6fd715a70c6e0b8374/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.7473905782421872}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n-/\nimport algebra.abs\nimport algebra.order.group.order_iso\nimport order.min_max\n\n/-!\n# Absolute values in ordered groups.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {\u03b1 : Type*}\nopen function\n\nsection covariant_add_le\n\nsection has_neg\n\n/-- `abs a` is the absolute value of `a`. -/\n@[to_additive \"`abs a` is the absolute value of `a`\",\n  priority 100] -- see Note [lower instance priority]\ninstance has_inv.to_has_abs [has_inv \u03b1] [has_sup \u03b1] : has_abs \u03b1 := \u27e8\u03bb a, a \u2294 a\u207b\u00b9\u27e9\n\n@[to_additive] lemma abs_eq_sup_inv [has_inv \u03b1] [has_sup \u03b1] (a : \u03b1) : |a| = a \u2294 a\u207b\u00b9 := rfl\n\nvariables [has_neg \u03b1] [linear_order \u03b1] {a b: \u03b1}\n\nlemma abs_eq_max_neg : abs a = max a (-a) :=\nrfl\n\nlemma abs_choice (x : \u03b1) : |x| = x \u2228 |x| = -x := max_choice _ _\n\nlemma abs_le' : |a| \u2264 b \u2194 a \u2264 b \u2227 -a \u2264 b := max_le_iff\n\nlemma le_abs : a \u2264 |b| \u2194 a \u2264 b \u2228 a \u2264 -b := le_max_iff\n\nlemma le_abs_self (a : \u03b1) : a \u2264 |a| := le_max_left _ _\n\nlemma neg_le_abs_self (a : \u03b1) : -a \u2264 |a| := le_max_right _ _\n\nlemma lt_abs : a < |b| \u2194 a < b \u2228 a < -b := lt_max_iff\n\ntheorem abs_le_abs (h\u2080 : a \u2264 b) (h\u2081 : -a \u2264 b) : |a| \u2264 |b| :=\n(abs_le'.2 \u27e8h\u2080, h\u2081\u27e9).trans (le_abs_self b)\n\nlemma abs_by_cases (P : \u03b1 \u2192 Prop) {a : \u03b1} (h1 : P a) (h2 : P (-a)) : P (|a|) :=\nsup_ind _ _ h1 h2\n\nend has_neg\n\nsection add_group\nvariables [add_group \u03b1] [linear_order \u03b1]\n\n@[simp] lemma abs_neg (a : \u03b1) : | -a| = |a| :=\nbegin\n  rw [abs_eq_max_neg, max_comm, neg_neg, abs_eq_max_neg]\nend\n\nlemma eq_or_eq_neg_of_abs_eq {a b : \u03b1} (h : |a| = b) : a = b \u2228 a = -b :=\nby simpa only [\u2190 h, eq_comm, neg_eq_iff_eq_neg] using abs_choice a\n\nlemma abs_eq_abs {a b : \u03b1} : |a| = |b| \u2194 a = b \u2228 a = -b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { obtain rfl | rfl := eq_or_eq_neg_of_abs_eq h;\n    simpa only [neg_eq_iff_eq_neg, neg_inj, or.comm] using abs_choice b },\n  { cases h; simp only [h, abs_neg] },\nend\n\nlemma abs_sub_comm (a b : \u03b1) : |a - b| = |b - a| :=\ncalc  |a - b| = | - (b - a)| : congr_arg _ (neg_sub b a).symm\n          ... = |b - a|      : abs_neg (b - a)\n\nvariables [covariant_class \u03b1 \u03b1 (+) (\u2264)] {a b c : \u03b1}\n\nlemma abs_of_nonneg (h : 0 \u2264 a) : |a| = a :=\nmax_eq_left $ (neg_nonpos.2 h).trans h\n\nlemma abs_of_pos (h : 0 < a) : |a| = a :=\nabs_of_nonneg h.le\n\nlemma abs_of_nonpos (h : a \u2264 0) : |a| = -a :=\nmax_eq_right $ h.trans (neg_nonneg.2 h)\n\nlemma abs_of_neg (h : a < 0) : |a| = -a :=\nabs_of_nonpos h.le\n\nlemma abs_le_abs_of_nonneg (ha : 0 \u2264 a) (hab : a \u2264 b) : |a| \u2264 |b| :=\nby rwa [abs_of_nonneg ha, abs_of_nonneg (ha.trans hab)]\n\n@[simp] lemma abs_zero : |0| = (0:\u03b1) :=\nabs_of_nonneg le_rfl\n\n@[simp] lemma abs_pos : 0 < |a| \u2194 a \u2260 0 :=\nbegin\n  rcases lt_trichotomy a 0 with (ha|rfl|ha),\n  { simp [abs_of_neg ha, neg_pos, ha.ne, ha] },\n  { simp },\n  { simp [abs_of_pos ha, ha, ha.ne.symm] }\nend\n\nlemma abs_pos_of_pos (h : 0 < a) : 0 < |a| := abs_pos.2 h.ne.symm\n\nlemma abs_pos_of_neg (h : a < 0) : 0 < |a| := abs_pos.2 h.ne\n\nlemma neg_abs_le_self (a : \u03b1) : -|a| \u2264 a :=\nbegin\n  cases le_total 0 a with h h,\n  { calc -|a| = - a   : congr_arg (has_neg.neg) (abs_of_nonneg h)\n            ... \u2264 0     : neg_nonpos.mpr h\n            ... \u2264 a     : h },\n  { calc -|a| = - - a : congr_arg (has_neg.neg) (abs_of_nonpos h)\n            ... \u2264 a     : (neg_neg a).le }\nend\n\nlemma add_abs_nonneg (a : \u03b1) : 0 \u2264 a + |a| :=\nbegin\n  rw \u2190add_right_neg a,\n  apply add_le_add_left,\n  exact (neg_le_abs_self a),\nend\n\nlemma neg_abs_le_neg (a : \u03b1) : -|a| \u2264 -a :=\nby simpa using neg_abs_le_self (-a)\n\n@[simp] lemma abs_nonneg (a : \u03b1) : 0 \u2264 |a| :=\n(le_total 0 a).elim (\u03bb h, h.trans (le_abs_self a)) (\u03bb h, (neg_nonneg.2 h).trans $ neg_le_abs_self a)\n\n@[simp] lemma abs_abs (a : \u03b1) : | |a| | = |a| :=\nabs_of_nonneg $ abs_nonneg a\n\n@[simp] lemma abs_eq_zero : |a| = 0 \u2194 a = 0 :=\ndecidable.not_iff_not.1 $ ne_comm.trans $ (abs_nonneg a).lt_iff_ne.symm.trans abs_pos\n\n@[simp] lemma abs_nonpos_iff {a : \u03b1} : |a| \u2264 0 \u2194 a = 0 :=\n(abs_nonneg a).le_iff_eq.trans abs_eq_zero\n\nvariable [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n\nlemma abs_le_abs_of_nonpos (ha : a \u2264 0) (hab : b \u2264 a) : |a| \u2264 |b| :=\nby { rw [abs_of_nonpos ha, abs_of_nonpos (hab.trans ha)], exact neg_le_neg_iff.mpr hab }\n\nlemma abs_lt : |a| < b \u2194 - b < a \u2227 a < b :=\nmax_lt_iff.trans $ and.comm.trans $ by rw [neg_lt]\n\nlemma neg_lt_of_abs_lt (h : |a| < b) : -b < a := (abs_lt.mp h).1\n\nlemma lt_of_abs_lt (h : |a| < b) : a < b := (abs_lt.mp h).2\n\nlemma max_sub_min_eq_abs' (a b : \u03b1) : max a b - min a b = |a - b| :=\nbegin\n  cases le_total a b with ab ba,\n  { rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub], rwa sub_nonpos },\n  { rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg], rwa sub_nonneg }\nend\n\nlemma max_sub_min_eq_abs (a b : \u03b1) : max a b - min a b = |b - a| :=\nby { rw abs_sub_comm, exact max_sub_min_eq_abs' _ _ }\n\nend add_group\n\nend covariant_add_le\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1] {a b c d : \u03b1}\n\nlemma abs_le : |a| \u2264 b \u2194 - b \u2264 a \u2227 a \u2264 b := by rw [abs_le', and.comm, neg_le]\n\nlemma le_abs' : a \u2264 |b| \u2194 b \u2264 -a \u2228 a \u2264 b := by rw [le_abs, or.comm, le_neg]\n\nlemma neg_le_of_abs_le (h : |a| \u2264 b) : -b \u2264 a := (abs_le.mp h).1\n\nlemma le_of_abs_le (h : |a| \u2264 b) : a \u2264 b := (abs_le.mp h).2\n\n@[to_additive] lemma apply_abs_le_mul_of_one_le' {\u03b2 : Type*} [mul_one_class \u03b2] [preorder \u03b2]\n  [covariant_class \u03b2 \u03b2 (*) (\u2264)] [covariant_class \u03b2 \u03b2 (swap (*)) (\u2264)] {f : \u03b1 \u2192 \u03b2} {a : \u03b1}\n  (h\u2081 : 1 \u2264 f a) (h\u2082 : 1 \u2264 f (-a)) :\n  f (|a|) \u2264 f a * f (-a) :=\n(le_total a 0).by_cases (\u03bb ha, (abs_of_nonpos ha).symm \u25b8 le_mul_of_one_le_left' h\u2081)\n  (\u03bb ha, (abs_of_nonneg ha).symm \u25b8 le_mul_of_one_le_right' h\u2082)\n\n@[to_additive] lemma apply_abs_le_mul_of_one_le {\u03b2 : Type*} [mul_one_class \u03b2] [preorder \u03b2]\n  [covariant_class \u03b2 \u03b2 (*) (\u2264)] [covariant_class \u03b2 \u03b2 (swap (*)) (\u2264)] {f : \u03b1 \u2192 \u03b2}\n  (h : \u2200 x, 1 \u2264 f x) (a : \u03b1) :\n  f (|a|) \u2264 f a * f (-a) :=\napply_abs_le_mul_of_one_le' (h _) (h _)\n\n/--\nThe **triangle inequality** in `linear_ordered_add_comm_group`s.\n-/\nlemma abs_add (a b : \u03b1) : |a + b| \u2264 |a| + |b| :=\nabs_le.2 \u27e8(neg_add (|a|) (|b|)).symm \u25b8\n  add_le_add (neg_le.2 $ neg_le_abs_self _) (neg_le.2 $ neg_le_abs_self _),\n  add_le_add (le_abs_self _) (le_abs_self _)\u27e9\n\nlemma abs_add' (a b : \u03b1) : |a| \u2264 |b| + |b + a| :=\nby simpa using abs_add (-b) (b + a)\n\ntheorem abs_sub (a b : \u03b1) :\n  |a - b| \u2264 |a| + |b| :=\nby { rw [sub_eq_add_neg, \u2190abs_neg b], exact abs_add a _ }\n\nlemma abs_sub_le_iff : |a - b| \u2264 c \u2194 a - b \u2264 c \u2227 b - a \u2264 c :=\nby rw [abs_le, neg_le_sub_iff_le_add, sub_le_iff_le_add', and_comm, sub_le_iff_le_add']\n\nlemma abs_sub_lt_iff : |a - b| < c \u2194 a - b < c \u2227 b - a < c :=\nby rw [abs_lt, neg_lt_sub_iff_lt_add', sub_lt_iff_lt_add', and_comm, sub_lt_iff_lt_add']\n\nlemma sub_le_of_abs_sub_le_left (h : |a - b| \u2264 c) : b - c \u2264 a :=\nsub_le_comm.1 $ (abs_sub_le_iff.1 h).2\n\nlemma sub_le_of_abs_sub_le_right (h : |a - b| \u2264 c) : a - c \u2264 b :=\nsub_le_of_abs_sub_le_left (abs_sub_comm a b \u25b8 h)\n\nlemma sub_lt_of_abs_sub_lt_left (h : |a - b| < c) : b - c < a :=\nsub_lt_comm.1 $ (abs_sub_lt_iff.1 h).2\n\nlemma sub_lt_of_abs_sub_lt_right (h : |a - b| < c) : a - c < b :=\nsub_lt_of_abs_sub_lt_left (abs_sub_comm a b \u25b8 h)\n\nlemma abs_sub_abs_le_abs_sub (a b : \u03b1) : |a| - |b| \u2264 |a - b| :=\nsub_le_iff_le_add.2 $\ncalc |a| = |a - b + b|     : by rw [sub_add_cancel]\n       ... \u2264 |a - b| + |b| : abs_add _ _\n\nlemma abs_abs_sub_abs_le_abs_sub (a b : \u03b1) : | |a| - |b| | \u2264 |a - b| :=\nabs_sub_le_iff.2 \u27e8abs_sub_abs_le_abs_sub _ _, by rw abs_sub_comm; apply abs_sub_abs_le_abs_sub\u27e9\n\nlemma abs_eq (hb : 0 \u2264 b) : |a| = b \u2194 a = b \u2228 a = -b :=\nbegin\n  refine \u27e8eq_or_eq_neg_of_abs_eq, _\u27e9,\n  rintro (rfl|rfl); simp only [abs_neg, abs_of_nonneg hb]\nend\n\nlemma abs_le_max_abs_abs (hab : a \u2264 b) (hbc : b \u2264 c) : |b| \u2264 max (|a|) (|c|) :=\nabs_le'.2\n  \u27e8by simp [hbc.trans (le_abs_self c)],\n   by simp [(neg_le_neg_iff.mpr hab).trans (neg_le_abs_self a)]\u27e9\n\nlemma min_abs_abs_le_abs_max : min (|a|) (|b|) \u2264 |max a b| :=\n(le_total a b).elim\n  (\u03bb h, (min_le_right _ _).trans_eq $ congr_arg _ (max_eq_right h).symm)\n  (\u03bb h, (min_le_left _ _).trans_eq $ congr_arg _ (max_eq_left h).symm)\n\nlemma min_abs_abs_le_abs_min : min (|a|) (|b|) \u2264 |min a b| :=\n(le_total a b).elim\n  (\u03bb h, (min_le_left _ _).trans_eq $ congr_arg _ (min_eq_left h).symm)\n  (\u03bb h, (min_le_right _ _).trans_eq $ congr_arg _ (min_eq_right h).symm)\n\nlemma abs_max_le_max_abs_abs : |max a b| \u2264 max (|a|) (|b|) :=\n(le_total a b).elim\n  (\u03bb h, (congr_arg _ $ max_eq_right h).trans_le $ le_max_right _ _)\n  (\u03bb h, (congr_arg _ $ max_eq_left h).trans_le $ le_max_left _ _)\n\nlemma abs_min_le_max_abs_abs : |min a b| \u2264 max (|a|) (|b|) :=\n(le_total a b).elim\n  (\u03bb h, (congr_arg _ $ min_eq_left h).trans_le $ le_max_left _ _)\n  (\u03bb h, (congr_arg _ $ min_eq_right h).trans_le $ le_max_right _ _)\n\nlemma eq_of_abs_sub_eq_zero {a b : \u03b1} (h : |a - b| = 0) : a = b :=\nsub_eq_zero.1 $ abs_eq_zero.1 h\n\nlemma abs_sub_le (a b c : \u03b1) : |a - c| \u2264 |a - b| + |b - c| :=\ncalc\n    |a - c| = |a - b + (b - c)|     : by rw [sub_add_sub_cancel]\n            ... \u2264 |a - b| + |b - c| : abs_add _ _\n\nlemma abs_add_three (a b c : \u03b1) : |a + b + c| \u2264 |a| + |b| + |c| :=\n(abs_add _ _).trans (add_le_add_right (abs_add _ _) _)\n\nlemma dist_bdd_within_interval {a b lb ub : \u03b1} (hal : lb \u2264 a) (hau : a \u2264 ub)\n      (hbl : lb \u2264 b) (hbu : b \u2264 ub) : |a - b| \u2264 ub - lb :=\nabs_sub_le_iff.2 \u27e8sub_le_sub hau hbl, sub_le_sub hbu hal\u27e9\n\nlemma eq_of_abs_sub_nonpos (h : |a - b| \u2264 0) : a = b :=\neq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b)))\n\nend linear_ordered_add_comm_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/group/abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7473800608759242}}
{"text": "/-\nCopyright (c) 2021 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n\n! This file was ported from Lean 3 source module analysis.normed_space.spectrum\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Algebra.Spectrum\nimport Mathbin.Analysis.SpecialFunctions.Pow\nimport Mathbin.Analysis.Complex.Liouville\nimport Mathbin.Analysis.Complex.Polynomial\nimport Mathbin.Analysis.Analytic.RadiusLiminf\nimport Mathbin.Topology.Algebra.Module.CharacterSpace\nimport Mathbin.Analysis.NormedSpace.Exponential\n\n/-!\n# The spectrum of elements in a complete normed algebra\n\nThis file contains the basic theory for the resolvent and spectrum of a Banach algebra.\n\n## Main definitions\n\n* `spectral_radius : \u211d\u22650\u221e`: supremum of `\u2016k\u2016\u208a` for all `k \u2208 spectrum \ud835\udd5c a`\n* `normed_ring.alg_equiv_complex_of_complete`: **Gelfand-Mazur theorem** For a complex\n  Banach division algebra, the natural `algebra_map \u2102 A` is an algebra isomorphism whose inverse\n  is given by selecting the (unique) element of `spectrum \u2102 a`\n\n## Main statements\n\n* `spectrum.is_open_resolvent_set`: the resolvent set is open.\n* `spectrum.is_closed`: the spectrum is closed.\n* `spectrum.subset_closed_ball_norm`: the spectrum is a subset of closed disk of radius\n  equal to the norm.\n* `spectrum.is_compact`: the spectrum is compact.\n* `spectrum.spectral_radius_le_nnnorm`: the spectral radius is bounded above by the norm.\n* `spectrum.has_deriv_at_resolvent`: the resolvent function is differentiable on the resolvent set.\n* `spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius`: Gelfand's formula for the\n  spectral radius in Banach algebras over `\u2102`.\n* `spectrum.nonempty`: the spectrum of any element in a complex Banach algebra is nonempty.\n\n\n## TODO\n\n* compute all derivatives of `resolvent a`.\n\n-/\n\n\nopen ENNReal NNReal\n\n/-- The *spectral radius* is the supremum of the `nnnorm` (`\u2016\u2b1d\u2016\u208a`) of elements in the spectrum,\n    coerced into an element of `\u211d\u22650\u221e`. Note that it is possible for `spectrum \ud835\udd5c a = \u2205`. In this\n    case, `spectral_radius a = 0`.  It is also possible that `spectrum \ud835\udd5c a` be unbounded (though\n    not for Banach algebras, see `spectrum.is_bounded`, below).  In this case,\n    `spectral_radius a = \u221e`. -/\nnoncomputable def spectralRadius (\ud835\udd5c : Type _) {A : Type _} [NormedField \ud835\udd5c] [Ring A] [Algebra \ud835\udd5c A]\n    (a : A) : \u211d\u22650\u221e :=\n  \u2a06 k \u2208 spectrum \ud835\udd5c a, \u2016k\u2016\u208a\n#align spectral_radius spectralRadius\n\nvariable {\ud835\udd5c : Type _} {A : Type _}\n\nnamespace spectrum\n\nsection SpectrumCompact\n\nopen Filter\n\nvariable [NormedField \ud835\udd5c] [NormedRing A] [NormedAlgebra \ud835\udd5c A]\n\n-- mathport name: expr\u03c3\nlocal notation \"\u03c3\" => spectrum \ud835\udd5c\n\n-- mathport name: expr\u03c1\nlocal notation \"\u03c1\" => resolventSet \ud835\udd5c\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap \ud835\udd5c A\n\n@[simp]\ntheorem SpectralRadius.of_subsingleton [Subsingleton A] (a : A) : spectralRadius \ud835\udd5c a = 0 := by\n  simp [spectralRadius]\n#align spectrum.spectral_radius.of_subsingleton spectrum.SpectralRadius.of_subsingleton\n\n@[simp]\ntheorem spectralRadius_zero : spectralRadius \ud835\udd5c (0 : A) = 0 :=\n  by\n  nontriviality A\n  simp [spectralRadius]\n#align spectrum.spectral_radius_zero spectrum.spectralRadius_zero\n\ntheorem mem_resolventSet_of_spectralRadius_lt {a : A} {k : \ud835\udd5c} (h : spectralRadius \ud835\udd5c a < \u2016k\u2016\u208a) :\n    k \u2208 \u03c1 a :=\n  Classical.not_not.mp fun hn => h.not_le <| le_sup\u1d62\u2082 k hn\n#align spectrum.mem_resolvent_set_of_spectral_radius_lt spectrum.mem_resolventSet_of_spectralRadius_lt\n\nvariable [CompleteSpace A]\n\ntheorem isOpen_resolventSet (a : A) : IsOpen (\u03c1 a) :=\n  Units.isOpen.Preimage ((continuous_algebraMap \ud835\udd5c A).sub continuous_const)\n#align spectrum.is_open_resolvent_set spectrum.isOpen_resolventSet\n\nprotected theorem isClosed (a : A) : IsClosed (\u03c3 a) :=\n  (isOpen_resolventSet a).isClosed_compl\n#align spectrum.is_closed spectrum.isClosed\n\ntheorem mem_resolventSet_of_norm_lt_mul {a : A} {k : \ud835\udd5c} (h : \u2016a\u2016 * \u2016(1 : A)\u2016 < \u2016k\u2016) : k \u2208 \u03c1 a :=\n  by\n  rw [resolventSet, Set.mem_setOf_eq, Algebra.algebraMap_eq_smul_one]\n  nontriviality A\n  have hk : k \u2260 0 :=\n    ne_zero_of_norm_ne_zero ((mul_nonneg (norm_nonneg _) (norm_nonneg _)).trans_lt h).ne'\n  let ku := Units.map \u2191\u2090.toMonoidHom (Units.mk0 k hk)\n  rw [\u2190 inv_inv \u2016(1 : A)\u2016,\n    mul_inv_lt_iff (inv_pos.2 <| norm_pos_iff.2 (one_ne_zero : (1 : A) \u2260 0))] at h\n  have hku : \u2016-a\u2016 < \u2016(\u2191ku\u207b\u00b9 : A)\u2016\u207b\u00b9 := by simpa [ku, norm_algebraMap] using h\n  simpa [ku, sub_eq_add_neg, Algebra.algebraMap_eq_smul_one] using (ku.add (-a) hku).IsUnit\n#align spectrum.mem_resolvent_set_of_norm_lt_mul spectrum.mem_resolventSet_of_norm_lt_mul\n\ntheorem mem_resolventSet_of_norm_lt [NormOneClass A] {a : A} {k : \ud835\udd5c} (h : \u2016a\u2016 < \u2016k\u2016) : k \u2208 \u03c1 a :=\n  mem_resolventSet_of_norm_lt_mul (by rwa [norm_one, mul_one])\n#align spectrum.mem_resolvent_set_of_norm_lt spectrum.mem_resolventSet_of_norm_lt\n\ntheorem norm_le_norm_mul_of_mem {a : A} {k : \ud835\udd5c} (hk : k \u2208 \u03c3 a) : \u2016k\u2016 \u2264 \u2016a\u2016 * \u2016(1 : A)\u2016 :=\n  le_of_not_lt <| mt mem_resolventSet_of_norm_lt_mul hk\n#align spectrum.norm_le_norm_mul_of_mem spectrum.norm_le_norm_mul_of_mem\n\ntheorem norm_le_norm_of_mem [NormOneClass A] {a : A} {k : \ud835\udd5c} (hk : k \u2208 \u03c3 a) : \u2016k\u2016 \u2264 \u2016a\u2016 :=\n  le_of_not_lt <| mt mem_resolventSet_of_norm_lt hk\n#align spectrum.norm_le_norm_of_mem spectrum.norm_le_norm_of_mem\n\ntheorem subset_closedBall_norm_mul (a : A) : \u03c3 a \u2286 Metric.closedBall (0 : \ud835\udd5c) (\u2016a\u2016 * \u2016(1 : A)\u2016) :=\n  fun k hk => by simp [norm_le_norm_mul_of_mem hk]\n#align spectrum.subset_closed_ball_norm_mul spectrum.subset_closedBall_norm_mul\n\ntheorem subset_closedBall_norm [NormOneClass A] (a : A) : \u03c3 a \u2286 Metric.closedBall (0 : \ud835\udd5c) \u2016a\u2016 :=\n  fun k hk => by simp [norm_le_norm_of_mem hk]\n#align spectrum.subset_closed_ball_norm spectrum.subset_closedBall_norm\n\ntheorem is_bounded (a : A) : Metric.Bounded (\u03c3 a) :=\n  (Metric.bounded_iff_subset_ball 0).mpr \u27e8\u2016a\u2016 * \u2016(1 : A)\u2016, subset_closedBall_norm_mul a\u27e9\n#align spectrum.is_bounded spectrum.is_bounded\n\nprotected theorem isCompact [ProperSpace \ud835\udd5c] (a : A) : IsCompact (\u03c3 a) :=\n  Metric.isCompact_of_isClosed_bounded (spectrum.isClosed a) (is_bounded a)\n#align spectrum.is_compact spectrum.isCompact\n\ntheorem spectralRadius_le_nnnorm [NormOneClass A] (a : A) : spectralRadius \ud835\udd5c a \u2264 \u2016a\u2016\u208a :=\n  by\n  refine' sup\u1d62\u2082_le fun k hk => _\n  exact_mod_cast norm_le_norm_of_mem hk\n#align spectrum.spectral_radius_le_nnnorm spectrum.spectralRadius_le_nnnorm\n\ntheorem exists_nnnorm_eq_spectralRadius_of_nonempty [ProperSpace \ud835\udd5c] {a : A} (ha : (\u03c3 a).Nonempty) :\n    \u2203 k \u2208 \u03c3 a, (\u2016k\u2016\u208a : \u211d\u22650\u221e) = spectralRadius \ud835\udd5c a :=\n  by\n  obtain \u27e8k, hk, h\u27e9 := (spectrum.isCompact a).exists_forall_ge ha continuous_nnnorm.continuous_on\n  exact \u27e8k, hk, le_antisymm (le_sup\u1d62\u2082 k hk) (sup\u1d62\u2082_le <| by exact_mod_cast h)\u27e9\n#align spectrum.exists_nnnorm_eq_spectral_radius_of_nonempty spectrum.exists_nnnorm_eq_spectralRadius_of_nonempty\n\ntheorem spectralRadius_lt_of_forall_lt_of_nonempty [ProperSpace \ud835\udd5c] {a : A} (ha : (\u03c3 a).Nonempty)\n    {r : \u211d\u22650} (hr : \u2200 k \u2208 \u03c3 a, \u2016k\u2016\u208a < r) : spectralRadius \ud835\udd5c a < r :=\n  sup\u209b_image.symm.trans_lt <|\n    ((spectrum.isCompact a).sup\u209b_lt_iff_of_continuous ha\n          (ENNReal.continuous_coe.comp continuous_nnnorm).ContinuousOn (r : \u211d\u22650\u221e)).mpr\n      (by exact_mod_cast hr)\n#align spectrum.spectral_radius_lt_of_forall_lt_of_nonempty spectrum.spectralRadius_lt_of_forall_lt_of_nonempty\n\nopen ENNReal Polynomial\n\nvariable (\ud835\udd5c)\n\ntheorem spectralRadius_le_pow_nnnorm_pow_one_div (a : A) (n : \u2115) :\n    spectralRadius \ud835\udd5c a \u2264 \u2016a ^ (n + 1)\u2016\u208a ^ (1 / (n + 1) : \u211d) * \u2016(1 : A)\u2016\u208a ^ (1 / (n + 1) : \u211d) :=\n  by\n  refine' sup\u1d62\u2082_le fun k hk => _\n  -- apply easy direction of the spectral mapping theorem for polynomials\n  have pow_mem : k ^ (n + 1) \u2208 \u03c3 (a ^ (n + 1)) := by\n    simpa only [one_mul, Algebra.algebraMap_eq_smul_one, one_smul, aeval_monomial, one_mul,\n      eval_monomial] using subset_polynomial_aeval a (monomial (n + 1) (1 : \ud835\udd5c)) \u27e8k, hk, rfl\u27e9\n  -- power of the norm is bounded by norm of the power\n  have nnnorm_pow_le : (\u2191(\u2016k\u2016\u208a ^ (n + 1)) : \u211d\u22650\u221e) \u2264 \u2016a ^ (n + 1)\u2016\u208a * \u2016(1 : A)\u2016\u208a := by\n    simpa only [Real.toNNReal_mul (norm_nonneg _), norm_toNNReal, nnnorm_pow k (n + 1),\n      ENNReal.coe_mul] using coe_mono (Real.toNNReal_mono (norm_le_norm_mul_of_mem pow_mem))\n  -- take (n + 1)\u1d57\u02b0 roots and clean up the left-hand side\n  have hn : 0 < ((n + 1 : \u2115) : \u211d) := by exact_mod_cast Nat.succ_pos'\n  convert monotone_rpow_of_nonneg (one_div_pos.mpr hn).le nnnorm_pow_le\n  erw [coe_pow, \u2190 rpow_nat_cast, \u2190 rpow_mul, mul_one_div_cancel hn.ne', rpow_one]\n  rw [Nat.cast_succ, ENNReal.coe_mul_rpow]\n#align spectrum.spectral_radius_le_pow_nnnorm_pow_one_div spectrum.spectralRadius_le_pow_nnnorm_pow_one_div\n\ntheorem spectralRadius_le_liminf_pow_nnnorm_pow_one_div (a : A) :\n    spectralRadius \ud835\udd5c a \u2264 atTop.liminf fun n : \u2115 => (\u2016a ^ n\u2016\u208a : \u211d\u22650\u221e) ^ (1 / n : \u211d) :=\n  by\n  refine' ENNReal.le_of_forall_lt_one_mul_le fun \u03b5 h\u03b5 => _\n  by_cases \u03b5 = 0\n  \u00b7 simp only [h, MulZeroClass.zero_mul, zero_le']\n  have h\u03b5' : \u03b5\u207b\u00b9 \u2260 \u221e := fun h' =>\n    h (by simpa only [inv_inv, inv_top] using congr_arg (fun x : \u211d\u22650\u221e => x\u207b\u00b9) h')\n  simp only [ENNReal.mul_le_iff_le_inv h (h\u03b5.trans_le le_top).Ne, mul_comm \u03b5\u207b\u00b9,\n    liminf_eq_supr_infi_of_nat', ENNReal.sup\u1d62_mul, ENNReal.inf\u1d62_mul h\u03b5']\n  rw [\u2190 ENNReal.inv_lt_inv, inv_one] at h\u03b5\n  obtain \u27e8N, hN\u27e9 :=\n    eventually_at_top.mp\n      (ENNReal.eventually_pow_one_div_le (ENNReal.coe_ne_top : \u2191\u2016(1 : A)\u2016\u208a \u2260 \u221e) h\u03b5)\n  refine' le_trans _ (le_sup\u1d62 _ (N + 1))\n  refine' le_inf\u1d62 fun n => _\n  simp only [\u2190 add_assoc]\n  refine' (spectral_radius_le_pow_nnnorm_pow_one_div \ud835\udd5c a (n + N)).trans _\n  norm_cast\n  exact mul_le_mul_left' (hN (n + N + 1) (by linarith)) _\n#align spectrum.spectral_radius_le_liminf_pow_nnnorm_pow_one_div spectrum.spectralRadius_le_liminf_pow_nnnorm_pow_one_div\n\nend SpectrumCompact\n\nsection resolvent\n\nopen Filter Asymptotics\n\nvariable [NontriviallyNormedField \ud835\udd5c] [NormedRing A] [NormedAlgebra \ud835\udd5c A] [CompleteSpace A]\n\n-- mathport name: expr\u03c1\nlocal notation \"\u03c1\" => resolventSet \ud835\udd5c\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap \ud835\udd5c A\n\ntheorem hasDerivAt_resolvent {a : A} {k : \ud835\udd5c} (hk : k \u2208 \u03c1 a) :\n    HasDerivAt (resolvent a) (-resolvent a k ^ 2) k :=\n  by\n  have H\u2081 : HasFderivAt Ring.inverse _ (\u2191\u2090 k - a) := hasFderivAt_ring_inverse hk.unit\n  have H\u2082 : HasDerivAt (fun k => \u2191\u2090 k - a) 1 k := by\n    simpa using (Algebra.linearMap \ud835\udd5c A).HasDerivAt.sub_const a\n  simpa [resolvent, sq, hk.unit_spec, \u2190 Ring.inverse_unit hk.unit] using H\u2081.comp_has_deriv_at k H\u2082\n#align spectrum.has_deriv_at_resolvent spectrum.hasDerivAt_resolvent\n\n/- TODO: Once there is sufficient API for bornology, we should get a nice filter / asymptotics\nversion of this, for example: `tendsto (resolvent a) (cobounded \ud835\udd5c) (\ud835\udcdd 0)` or more specifically\n`(resolvent a) =O[cobounded \ud835\udd5c] (\u03bb z, z\u207b\u00b9)`. -/\ntheorem norm_resolvent_le_forall (a : A) :\n    \u2200 \u03b5 > 0, \u2203 R > 0, \u2200 z : \ud835\udd5c, R \u2264 \u2016z\u2016 \u2192 \u2016resolvent a z\u2016 \u2264 \u03b5 :=\n  by\n  obtain \u27e8c, c_pos, hc\u27e9 := (@NormedRing.inverse_one_sub_norm A _ _).exists_pos\n  rw [is_O_with_iff, eventually_iff, Metric.mem_nhds_iff] at hc\n  rcases hc with \u27e8\u03b4, \u03b4_pos, h\u03b4\u27e9\n  simp only [CstarRing.norm_one, mul_one] at h\u03b4\n  intro \u03b5 h\u03b5\n  have ha\u2081 : 0 < \u2016a\u2016 + 1 := lt_of_le_of_lt (norm_nonneg a) (lt_add_one _)\n  have min_pos : 0 < min (\u03b4 * (\u2016a\u2016 + 1)\u207b\u00b9) (\u03b5 * c\u207b\u00b9) :=\n    lt_min (mul_pos \u03b4_pos (inv_pos.mpr ha\u2081)) (mul_pos h\u03b5 (inv_pos.mpr c_pos))\n  refine' \u27e8(min (\u03b4 * (\u2016a\u2016 + 1)\u207b\u00b9) (\u03b5 * c\u207b\u00b9))\u207b\u00b9, inv_pos.mpr min_pos, fun z hz => _\u27e9\n  have hnz : z \u2260 0 := norm_pos_iff.mp (lt_of_lt_of_le (inv_pos.mpr min_pos) hz)\n  replace hz := inv_le_of_inv_le min_pos hz\n  rcases(\u27e8Units.mk0 z hnz, Units.val_mk0 hnz\u27e9 : IsUnit z) with \u27e8z, rfl\u27e9\n  have lt_\u03b4 : \u2016z\u207b\u00b9 \u2022 a\u2016 < \u03b4 :=\n    by\n    rw [Units.smul_def, norm_smul, Units.val_inv_eq_inv_val, norm_inv]\n    calc\n      \u2016(z : \ud835\udd5c)\u2016\u207b\u00b9 * \u2016a\u2016 \u2264 \u03b4 * (\u2016a\u2016 + 1)\u207b\u00b9 * \u2016a\u2016 :=\n        mul_le_mul_of_nonneg_right (hz.trans (min_le_left _ _)) (norm_nonneg _)\n      _ < \u03b4 :=\n        by\n        conv =>\n          rw [mul_assoc]\n          rhs\n          rw [(mul_one \u03b4).symm]\n        exact\n          mul_lt_mul_of_pos_left\n            ((inv_mul_lt_iff ha\u2081).mpr ((mul_one (\u2016a\u2016 + 1)).symm \u25b8 lt_add_one _)) \u03b4_pos\n      \n  rw [\u2190 inv_smul_smul z (resolvent a (z : \ud835\udd5c)), units_smul_resolvent_self, resolvent,\n    Algebra.algebraMap_eq_smul_one, one_smul, Units.smul_def, norm_smul, Units.val_inv_eq_inv_val,\n    norm_inv]\n  calc\n    _ \u2264 \u03b5 * c\u207b\u00b9 * c :=\n      mul_le_mul (hz.trans (min_le_right _ _)) (h\u03b4 (mem_ball_zero_iff.mpr lt_\u03b4)) (norm_nonneg _)\n        (mul_pos h\u03b5 (inv_pos.mpr c_pos)).le\n    _ = _ := inv_mul_cancel_right\u2080 c_pos.ne.symm \u03b5\n    \n#align spectrum.norm_resolvent_le_forall spectrum.norm_resolvent_le_forall\n\nend resolvent\n\nsection OneSubSmul\n\nopen ContinuousMultilinearMap ENNReal FormalMultilinearSeries\n\nopen NNReal ENNReal\n\nvariable [NontriviallyNormedField \ud835\udd5c] [NormedRing A] [NormedAlgebra \ud835\udd5c A]\n\nvariable (\ud835\udd5c)\n\n/-- In a Banach algebra `A` over a nontrivially normed field `\ud835\udd5c`, for any `a : A` the\npower series with coefficients `a ^ n` represents the function `(1 - z \u2022 a)\u207b\u00b9` in a disk of\nradius `\u2016a\u2016\u208a\u207b\u00b9`. -/\ntheorem hasFpowerSeriesOnBallInverseOneSubSmul [CompleteSpace A] (a : A) :\n    HasFpowerSeriesOnBall (fun z : \ud835\udd5c => Ring.inverse (1 - z \u2022 a))\n      (fun n => ContinuousMultilinearMap.mkPiField \ud835\udd5c (Fin n) (a ^ n)) 0 \u2016a\u2016\u208a\u207b\u00b9 :=\n  { r_le :=\n      by\n      refine'\n        le_of_forall_nnreal_lt fun r hr => le_radius_of_bound_nnreal _ (max 1 \u2016(1 : A)\u2016\u208a) fun n => _\n      rw [\u2190 norm_toNNReal, norm_mk_pi_field, norm_toNNReal]\n      cases n\n      \u00b7 simp only [le_refl, mul_one, or_true_iff, le_max_iff, pow_zero]\n      \u00b7 refine'\n          le_trans (le_trans (mul_le_mul_right' (nnnorm_pow_le' a n.succ_pos) (r ^ n.succ)) _)\n            (le_max_left _ _)\n        \u00b7 by_cases \u2016a\u2016\u208a = 0\n          \u00b7 simp only [h, MulZeroClass.zero_mul, zero_le', pow_succ]\n          \u00b7 rw [\u2190 coe_inv h, coe_lt_coe, NNReal.lt_inv_iff_mul_lt h] at hr\n            simpa only [\u2190 mul_pow, mul_comm] using pow_le_one' hr.le n.succ\n    r_pos := ENNReal.inv_pos.mpr coe_ne_top\n    HasSum := fun y hy =>\n      by\n      have norm_lt : \u2016y \u2022 a\u2016 < 1 := by\n        by_cases h : \u2016a\u2016\u208a = 0\n        \u00b7 simp only [nnnorm_eq_zero.mp h, norm_zero, zero_lt_one, smul_zero]\n        \u00b7 have nnnorm_lt : \u2016y\u2016\u208a < \u2016a\u2016\u208a\u207b\u00b9 := by\n            simpa only [\u2190 coe_inv h, mem_ball_zero_iff, Metric.emetric_ball_nnreal] using hy\n          rwa [\u2190 coe_nnnorm, \u2190 Real.lt_toNNReal_iff_coe_lt, Real.toNNReal_one, nnnorm_smul, \u2190\n            NNReal.lt_inv_iff_mul_lt h]\n      simpa [\u2190 smul_pow, (NormedRing.summable_geometric_of_norm_lt_1 _ norm_lt).hasSum_iff] using\n        (NormedRing.inverse_oneSub _ norm_lt).symm }\n#align spectrum.has_fpower_series_on_ball_inverse_one_sub_smul spectrum.hasFpowerSeriesOnBallInverseOneSubSmul\n\nvariable {\ud835\udd5c}\n\ntheorem isUnit_one_sub_smul_of_lt_inv_radius {a : A} {z : \ud835\udd5c} (h : \u2191\u2016z\u2016\u208a < (spectralRadius \ud835\udd5c a)\u207b\u00b9) :\n    IsUnit (1 - z \u2022 a) := by\n  by_cases hz : z = 0\n  \u00b7 simp only [hz, isUnit_one, sub_zero, zero_smul]\n  \u00b7 let u := Units.mk0 z hz\n    suffices hu : IsUnit (u\u207b\u00b9 \u2022 1 - a)\n    \u00b7 rwa [IsUnit.smul_sub_iff_sub_inv_smul, inv_inv u] at hu\n    \u00b7 rw [Units.smul_def, \u2190 Algebra.algebraMap_eq_smul_one, \u2190 mem_resolvent_set_iff]\n      refine' mem_resolvent_set_of_spectral_radius_lt _\n      rwa [Units.val_inv_eq_inv_val, nnnorm_inv,\n        coe_inv (nnnorm_ne_zero_iff.mpr (Units.val_mk0 hz \u25b8 hz : (u : \ud835\udd5c) \u2260 0)), lt_inv_iff_lt_inv]\n#align spectrum.is_unit_one_sub_smul_of_lt_inv_radius spectrum.isUnit_one_sub_smul_of_lt_inv_radius\n\n/-- In a Banach algebra `A` over `\ud835\udd5c`, for `a : A` the function `\u03bb z, (1 - z \u2022 a)\u207b\u00b9` is\ndifferentiable on any closed ball centered at zero of radius `r < (spectral_radius \ud835\udd5c a)\u207b\u00b9`. -/\ntheorem differentiableOn_inverse_one_sub_smul [CompleteSpace A] {a : A} {r : \u211d\u22650}\n    (hr : (r : \u211d\u22650\u221e) < (spectralRadius \ud835\udd5c a)\u207b\u00b9) :\n    DifferentiableOn \ud835\udd5c (fun z : \ud835\udd5c => Ring.inverse (1 - z \u2022 a)) (Metric.closedBall 0 r) :=\n  by\n  intro z z_mem\n  apply DifferentiableAt.differentiableWithinAt\n  have hu : IsUnit (1 - z \u2022 a) :=\n    by\n    refine' is_unit_one_sub_smul_of_lt_inv_radius (lt_of_le_of_lt (coe_mono _) hr)\n    simpa only [norm_toNNReal, Real.toNNReal_coe] using\n      Real.toNNReal_mono (mem_closed_ball_zero_iff.mp z_mem)\n  have H\u2081 : Differentiable \ud835\udd5c fun w : \ud835\udd5c => 1 - w \u2022 a := (differentiable_id.smul_const a).const_sub 1\n  exact DifferentiableAt.comp z (differentiableAt_inverse hu.unit) H\u2081.differentiable_at\n#align spectrum.differentiable_on_inverse_one_sub_smul spectrum.differentiableOn_inverse_one_sub_smul\n\nend OneSubSmul\n\nsection GelfandFormula\n\nopen Filter ENNReal ContinuousMultilinearMap\n\nopen Topology\n\nvariable [NormedRing A] [NormedAlgebra \u2102 A] [CompleteSpace A]\n\n/-- The `limsup` relationship for the spectral radius used to prove `spectrum.gelfand_formula`. -/\ntheorem limsup_pow_nnnorm_pow_one_div_le_spectralRadius (a : A) :\n    limsup (fun n : \u2115 => \u2191\u2016a ^ n\u2016\u208a ^ (1 / n : \u211d)) atTop \u2264 spectralRadius \u2102 a :=\n  by\n  refine' ennreal.inv_le_inv.mp (le_of_forall_pos_nnreal_lt fun r r_pos r_lt => _)\n  simp_rw [inv_limsup, \u2190 one_div]\n  let p : FormalMultilinearSeries \u2102 \u2102 A := fun n =>\n    ContinuousMultilinearMap.mkPiField \u2102 (Fin n) (a ^ n)\n  suffices h : (r : \u211d\u22650\u221e) \u2264 p.radius\n  \u00b7 convert h\n    simp only [p.radius_eq_liminf, \u2190 norm_toNNReal, norm_mk_pi_field]\n    congr\n    ext n\n    rw [norm_toNNReal, ENNReal.coe_rpow_def \u2016a ^ n\u2016\u208a (1 / n : \u211d), if_neg]\n    exact fun ha => by linarith [ha.2, (one_div_nonneg.mpr n.cast_nonneg : 0 \u2264 (1 / n : \u211d))]\n  \u00b7 have H\u2081 := (differentiable_on_inverse_one_sub_smul r_lt).HasFpowerSeriesOnBall r_pos\n    exact ((has_fpower_series_on_ball_inverse_one_sub_smul \u2102 a).exchangeRadius H\u2081).r_le\n#align spectrum.limsup_pow_nnnorm_pow_one_div_le_spectral_radius spectrum.limsup_pow_nnnorm_pow_one_div_le_spectralRadius\n\n/-- **Gelfand's formula**: Given an element `a : A` of a complex Banach algebra, the\n`spectral_radius` of `a` is the limit of the sequence `\u2016a ^ n\u2016\u208a ^ (1 / n)` -/\ntheorem pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius (a : A) :\n    Tendsto (fun n : \u2115 => (\u2016a ^ n\u2016\u208a ^ (1 / n : \u211d) : \u211d\u22650\u221e)) atTop (\ud835\udcdd (spectralRadius \u2102 a)) :=\n  tendsto_of_le_liminf_of_limsup_le (spectralRadius_le_liminf_pow_nnnorm_pow_one_div \u2102 a)\n    (limsup_pow_nnnorm_pow_one_div_le_spectralRadius a)\n#align spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius\n\n/- This is the same as `pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius` but for `norm`\ninstead of `nnnorm`. -/\n/-- **Gelfand's formula**: Given an element `a : A` of a complex Banach algebra, the\n`spectral_radius` of `a` is the limit of the sequence `\u2016a ^ n\u2016\u208a ^ (1 / n)` -/\ntheorem pow_norm_pow_one_div_tendsto_nhds_spectralRadius (a : A) :\n    Tendsto (fun n : \u2115 => ENNReal.ofReal (\u2016a ^ n\u2016 ^ (1 / n : \u211d))) atTop (\ud835\udcdd (spectralRadius \u2102 a)) :=\n  by\n  convert pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius a\n  ext1\n  rw [\u2190 of_real_rpow_of_nonneg (norm_nonneg _) _, \u2190 coe_nnnorm, coe_nnreal_eq]\n  exact one_div_nonneg.mpr (by exact_mod_cast zero_le _)\n#align spectrum.pow_norm_pow_one_div_tendsto_nhds_spectral_radius spectrum.pow_norm_pow_one_div_tendsto_nhds_spectralRadius\n\nend GelfandFormula\n\nsection NonemptySpectrum\n\nvariable [NormedRing A] [NormedAlgebra \u2102 A] [CompleteSpace A] [Nontrivial A] (a : A)\n\n/-- In a (nontrivial) complex Banach algebra, every element has nonempty spectrum. -/\nprotected theorem nonempty : (spectrum \u2102 a).Nonempty :=\n  by\n  /- Suppose `\u03c3 a = \u2205`, then resolvent set is `\u2102`, any `(z \u2022 1 - a)` is a unit, and `resolvent`\n    is differentiable on `\u2102`. -/\n  rw [Set.nonempty_iff_ne_empty]\n  by_contra h\n  have H\u2080 : resolventSet \u2102 a = Set.univ := by rwa [spectrum, Set.compl_empty_iff] at h\n  have H\u2081 : Differentiable \u2102 fun z : \u2102 => resolvent a z := fun z =>\n    (has_deriv_at_resolvent (H\u2080.symm \u25b8 Set.mem_univ z : z \u2208 resolventSet \u2102 a)).DifferentiableAt\n  /- The norm of the resolvent is small for all sufficently large `z`, and by compactness and\n    continuity it is bounded on the complement of a large ball, thus uniformly bounded on `\u2102`.\n    By Liouville's theorem `\u03bb z, resolvent a z` is constant -/\n  have H\u2082 := norm_resolvent_le_forall a\n  have H\u2083 : \u2200 z : \u2102, resolvent a z = resolvent a (0 : \u2102) :=\n    by\n    refine' fun z => H\u2081.apply_eq_apply_of_bounded (bounded_iff_forall_norm_le.mpr _) z 0\n    rcases H\u2082 1 zero_lt_one with \u27e8R, R_pos, hR\u27e9\n    rcases(ProperSpace.isCompact_closedBall (0 : \u2102) R).exists_bound_of_continuousOn\n        H\u2081.continuous.continuous_on with\n      \u27e8C, hC\u27e9\n    use max C 1\n    rintro _ \u27e8w, rfl\u27e9\n    refine' Or.elim (em (\u2016w\u2016 \u2264 R)) (fun hw => _) fun hw => _\n    \u00b7 exact (hC w (mem_closed_ball_zero_iff.mpr hw)).trans (le_max_left _ _)\n    \u00b7 exact (hR w (not_le.mp hw).le).trans (le_max_right _ _)\n  -- `resolvent a 0 = 0`, which is a contradition because it isn't a unit.\n  have H\u2085 : resolvent a (0 : \u2102) = 0 :=\n    by\n    refine' norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add fun \u03b5 h\u03b5 => _) (norm_nonneg _))\n    rcases H\u2082 \u03b5 h\u03b5 with \u27e8R, R_pos, hR\u27e9\n    simpa only [H\u2083 R] using\n      (zero_add \u03b5).symm.subst (hR R (by exact_mod_cast (Real.norm_of_nonneg R_pos.lt.le).symm.le))\n  -- `not_is_unit_zero` is where we need `nontrivial A`, it is unavoidable.\n  exact\n    not_isUnit_zero\n      (H\u2085.subst (is_unit_resolvent.mp (mem_resolvent_set_iff.mp (H\u2080.symm \u25b8 Set.mem_univ 0))))\n#align spectrum.nonempty spectrum.nonempty\n\n/-- In a complex Banach algebra, the spectral radius is always attained by some element of the\nspectrum. -/\ntheorem exists_nnnorm_eq_spectralRadius : \u2203 z \u2208 spectrum \u2102 a, (\u2016z\u2016\u208a : \u211d\u22650\u221e) = spectralRadius \u2102 a :=\n  exists_nnnorm_eq_spectralRadius_of_nonempty (spectrum.nonempty a)\n#align spectrum.exists_nnnorm_eq_spectral_radius spectrum.exists_nnnorm_eq_spectralRadius\n\n/-- In a complex Banach algebra, if every element of the spectrum has norm strictly less than\n`r : \u211d\u22650`, then the spectral radius is also strictly less than `r`. -/\ntheorem spectralRadius_lt_of_forall_lt {r : \u211d\u22650} (hr : \u2200 z \u2208 spectrum \u2102 a, \u2016z\u2016\u208a < r) :\n    spectralRadius \u2102 a < r :=\n  spectralRadius_lt_of_forall_lt_of_nonempty (spectrum.nonempty a) hr\n#align spectrum.spectral_radius_lt_of_forall_lt spectrum.spectralRadius_lt_of_forall_lt\n\nopen Polynomial\n\nopen Polynomial\n\n/-- The **spectral mapping theorem** for polynomials in a Banach algebra over `\u2102`. -/\ntheorem map_polynomial_aeval (p : \u2102[X]) :\n    spectrum \u2102 (aeval a p) = (fun k => eval k p) '' spectrum \u2102 a :=\n  map_polynomial_aeval_of_nonempty a p (spectrum.nonempty a)\n#align spectrum.map_polynomial_aeval spectrum.map_polynomial_aeval\n\n/-- A specialization of the spectral mapping theorem for polynomials in a Banach algebra over `\u2102`\nto monic monomials. -/\nprotected theorem map_pow (n : \u2115) : spectrum \u2102 (a ^ n) = (fun x => x ^ n) '' spectrum \u2102 a := by\n  simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval a (X ^ n)\n#align spectrum.map_pow spectrum.map_pow\n\nend NonemptySpectrum\n\nsection GelfandMazurIsomorphism\n\nvariable [NormedRing A] [NormedAlgebra \u2102 A] (hA : \u2200 {a : A}, IsUnit a \u2194 a \u2260 0)\n\ninclude hA\n\n-- mathport name: expr\u03c3\nlocal notation \"\u03c3\" => spectrum \u2102\n\ntheorem algebraMap_eq_of_mem {a : A} {z : \u2102} (h : z \u2208 \u03c3 a) : algebraMap \u2102 A z = a := by\n  rwa [mem_iff, hA, Classical.not_not, sub_eq_zero] at h\n#align spectrum.algebra_map_eq_of_mem spectrum.algebraMap_eq_of_mem\n\n/-- **Gelfand-Mazur theorem**: For a complex Banach division algebra, the natural `algebra_map \u2102 A`\nis an algebra isomorphism whose inverse is given by selecting the (unique) element of\n`spectrum \u2102 a`. In addition, `algebra_map_isometry` guarantees this map is an isometry.\n\nNote: because `normed_division_ring` requires the field `norm_mul' : \u2200 a b, \u2016a * b\u2016 = \u2016a\u2016 * \u2016b\u2016`, we\ndon't use this type class and instead opt for a `normed_ring` in which the nonzero elements are\nprecisely the units. This allows for the application of this isomorphism in broader contexts, e.g.,\nto the quotient of a complex Banach algebra by a maximal ideal. In the case when `A` is actually a\n`normed_division_ring`, one may fill in the argument `hA` with the lemma `is_unit_iff_ne_zero`. -/\n@[simps]\nnoncomputable def NormedRing.algEquivComplexOfComplete [CompleteSpace A] : \u2102 \u2243\u2090[\u2102] A :=\n  let nt : Nontrivial A := \u27e8\u27e81, 0, hA.mp \u27e8\u27e81, 1, mul_one _, mul_one _\u27e9, rfl\u27e9\u27e9\u27e9\n  { Algebra.ofId \u2102 A with\n    toFun := algebraMap \u2102 A\n    invFun := fun a => (@spectrum.nonempty _ _ _ _ nt a).some\n    left_inv := fun z => by\n      simpa only [@scalar_eq _ _ _ _ _ nt _] using\n        (@spectrum.nonempty _ _ _ _ nt <| algebraMap \u2102 A z).some_mem\n    right_inv := fun a => algebraMap_eq_of_mem (@hA) (@spectrum.nonempty _ _ _ _ nt a).some_mem }\n#align normed_ring.alg_equiv_complex_of_complete NormedRing.algEquivComplexOfComplete\n\nend GelfandMazurIsomorphism\n\nsection ExpMapping\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap \ud835\udd5c A\n\n/-- For `\ud835\udd5c = \u211d` or `\ud835\udd5c = \u2102`, `exp \ud835\udd5c` maps the spectrum of `a` into the spectrum of `exp \ud835\udd5c a`. -/\ntheorem exp_mem_exp [IsROrC \ud835\udd5c] [NormedRing A] [NormedAlgebra \ud835\udd5c A] [CompleteSpace A] (a : A) {z : \ud835\udd5c}\n    (hz : z \u2208 spectrum \ud835\udd5c a) : exp \ud835\udd5c z \u2208 spectrum \ud835\udd5c (exp \ud835\udd5c a) :=\n  by\n  have hexpmul : exp \ud835\udd5c a = exp \ud835\udd5c (a - \u2191\u2090 z) * \u2191\u2090 (exp \ud835\udd5c z) := by\n    rw [algebraMap_exp_comm z, \u2190 exp_add_of_commute (Algebra.commutes z (a - \u2191\u2090 z)).symm,\n      sub_add_cancel]\n  let b := \u2211' n : \u2115, ((n + 1).factorial\u207b\u00b9 : \ud835\udd5c) \u2022 (a - \u2191\u2090 z) ^ n\n  have hb : Summable fun n : \u2115 => ((n + 1).factorial\u207b\u00b9 : \ud835\udd5c) \u2022 (a - \u2191\u2090 z) ^ n :=\n    by\n    refine' summable_of_norm_bounded_eventually _ (Real.summable_pow_div_factorial \u2016a - \u2191\u2090 z\u2016) _\n    filter_upwards [Filter.eventually_cofinite_ne 0]with n hn\n    rw [norm_smul, mul_comm, norm_inv, IsROrC.norm_eq_abs, IsROrC.abs_cast_nat, \u2190 div_eq_mul_inv]\n    exact\n      div_le_div (pow_nonneg (norm_nonneg _) n) (norm_pow_le' (a - \u2191\u2090 z) (zero_lt_iff.mpr hn))\n        (by exact_mod_cast Nat.factorial_pos n)\n        (by exact_mod_cast Nat.factorial_le (lt_add_one n).le)\n  have h\u2080 : (\u2211' n : \u2115, ((n + 1).factorial\u207b\u00b9 : \ud835\udd5c) \u2022 (a - \u2191\u2090 z) ^ (n + 1)) = (a - \u2191\u2090 z) * b := by\n    simpa only [mul_smul_comm, pow_succ] using hb.tsum_mul_left (a - \u2191\u2090 z)\n  have h\u2081 : (\u2211' n : \u2115, ((n + 1).factorial\u207b\u00b9 : \ud835\udd5c) \u2022 (a - \u2191\u2090 z) ^ (n + 1)) = b * (a - \u2191\u2090 z) := by\n    simpa only [pow_succ', Algebra.smul_mul_assoc] using hb.tsum_mul_right (a - \u2191\u2090 z)\n  have h\u2083 : exp \ud835\udd5c (a - \u2191\u2090 z) = 1 + (a - \u2191\u2090 z) * b :=\n    by\n    rw [exp_eq_tsum]\n    convert tsum_eq_zero_add (exp_series_summable' (a - \u2191\u2090 z))\n    simp only [Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, one_smul]\n    exact h\u2080.symm\n  rw [spectrum.mem_iff, IsUnit.sub_iff, \u2190 one_mul (\u2191\u2090 (exp \ud835\udd5c z)), hexpmul, \u2190 _root_.sub_mul,\n    Commute.isUnit_mul_iff (Algebra.commutes (exp \ud835\udd5c z) (exp \ud835\udd5c (a - \u2191\u2090 z) - 1)).symm,\n    sub_eq_iff_eq_add'.mpr h\u2083, Commute.isUnit_mul_iff (h\u2080 \u25b8 h\u2081 : (a - \u2191\u2090 z) * b = b * (a - \u2191\u2090 z))]\n  exact not_and_of_not_left _ (not_and_of_not_left _ ((not_iff_not.mpr IsUnit.sub_iff).mp hz))\n#align spectrum.exp_mem_exp spectrum.exp_mem_exp\n\nend ExpMapping\n\nend spectrum\n\nnamespace AlgHom\n\nsection NormedField\n\nvariable {F : Type _} [NormedField \ud835\udd5c] [NormedRing A] [NormedAlgebra \ud835\udd5c A] [CompleteSpace A]\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap \ud835\udd5c A\n\n/-- An algebra homomorphism into the base field, as a continuous linear map (since it is\nautomatically bounded). See note [lower instance priority] -/\ninstance (priority := 100) [AlgHomClass F \ud835\udd5c A \ud835\udd5c] : ContinuousLinearMapClass F \ud835\udd5c A \ud835\udd5c :=\n  { AlgHomClass.linearMapClass with\n    map_continuous := fun \u03c6 =>\n      AddMonoidHomClass.continuous_of_bound \u03c6 \u2016(1 : A)\u2016 fun a =>\n        mul_comm \u2016a\u2016 \u2016(1 : A)\u2016 \u25b8 spectrum.norm_le_norm_mul_of_mem (apply_mem_spectrum \u03c6 _) }\n\n/-- An algebra homomorphism into the base field, as a continuous linear map (since it is\nautomatically bounded). -/\ndef toContinuousLinearMap (\u03c6 : A \u2192\u2090[\ud835\udd5c] \ud835\udd5c) : A \u2192L[\ud835\udd5c] \ud835\udd5c :=\n  { \u03c6.toLinearMap with cont := map_continuous \u03c6 }\n#align alg_hom.to_continuous_linear_map AlgHom.toContinuousLinearMap\n\n@[simp]\ntheorem coe_toContinuousLinearMap (\u03c6 : A \u2192\u2090[\ud835\udd5c] \ud835\udd5c) : \u21d1\u03c6.toContinuousLinearMap = \u03c6 :=\n  rfl\n#align alg_hom.coe_to_continuous_linear_map AlgHom.coe_toContinuousLinearMap\n\ntheorem norm_apply_le_self_mul_norm_one [AlgHomClass F \ud835\udd5c A \ud835\udd5c] (f : F) (a : A) :\n    \u2016f a\u2016 \u2264 \u2016a\u2016 * \u2016(1 : A)\u2016 :=\n  spectrum.norm_le_norm_mul_of_mem (apply_mem_spectrum f _)\n#align alg_hom.norm_apply_le_self_mul_norm_one AlgHom.norm_apply_le_self_mul_norm_one\n\ntheorem norm_apply_le_self [NormOneClass A] [AlgHomClass F \ud835\udd5c A \ud835\udd5c] (f : F) (a : A) : \u2016f a\u2016 \u2264 \u2016a\u2016 :=\n  spectrum.norm_le_norm_of_mem (apply_mem_spectrum f _)\n#align alg_hom.norm_apply_le_self AlgHom.norm_apply_le_self\n\nend NormedField\n\nsection NontriviallyNormedField\n\nvariable [NontriviallyNormedField \ud835\udd5c] [NormedRing A] [NormedAlgebra \ud835\udd5c A] [CompleteSpace A]\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap \ud835\udd5c A\n\n@[simp]\ntheorem toContinuousLinearMap_norm [NormOneClass A] (\u03c6 : A \u2192\u2090[\ud835\udd5c] \ud835\udd5c) :\n    \u2016\u03c6.toContinuousLinearMap\u2016 = 1 :=\n  ContinuousLinearMap.op_norm_eq_of_bounds zero_le_one\n    (fun a => (one_mul \u2016a\u2016).symm \u25b8 spectrum.norm_le_norm_of_mem (apply_mem_spectrum \u03c6 _))\n    fun _ _ h => by simpa only [coe_to_continuous_linear_map, map_one, norm_one, mul_one] using h 1\n#align alg_hom.to_continuous_linear_map_norm AlgHom.toContinuousLinearMap_norm\n\nend NontriviallyNormedField\n\nend AlgHom\n\nnamespace WeakDual\n\nnamespace CharacterSpace\n\nvariable [NontriviallyNormedField \ud835\udd5c] [NormedRing A] [CompleteSpace A]\n\nvariable [NormedAlgebra \ud835\udd5c A]\n\n/-- The equivalence between characters and algebra homomorphisms into the base field. -/\ndef equivAlgHom : characterSpace \ud835\udd5c A \u2243 (A \u2192\u2090[\ud835\udd5c] \ud835\udd5c)\n    where\n  toFun := toAlgHom\n  invFun f :=\n    { val := f.toContinuousLinearMap\n      property := by\n        rw [eq_set_map_one_map_mul]\n        exact \u27e8map_one f, map_mul f\u27e9 }\n  left_inv f := Subtype.ext <| ContinuousLinearMap.ext fun x => rfl\n  right_inv f := AlgHom.ext fun x => rfl\n#align weak_dual.character_space.equiv_alg_hom WeakDual.characterSpace.equivAlgHom\n\n@[simp]\ntheorem equivAlgHom_coe (f : characterSpace \ud835\udd5c A) : \u21d1(equivAlgHom f) = f :=\n  rfl\n#align weak_dual.character_space.equiv_alg_hom_coe WeakDual.characterSpace.equivAlgHom_coe\n\n@[simp]\ntheorem equivAlgHom_symm_coe (f : A \u2192\u2090[\ud835\udd5c] \ud835\udd5c) : \u21d1(equivAlgHom.symm f) = f :=\n  rfl\n#align weak_dual.character_space.equiv_alg_hom_symm_coe WeakDual.characterSpace.equivAlgHom_symm_coe\n\nend CharacterSpace\n\nend WeakDual\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/NormedSpace/Spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181876, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7473800599463024}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Ejercutar las siguientes acciones\n-- 1. Importar la librer\u00eda data.set.basic data.nat.parity\n-- 2. Abrir los espacios de nombres set y nat.\n-- ----------------------------------------------------------------------\n\nimport data.set.basic data.nat.parity\n\nopen set nat\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el conjunto de los n\u00fameros pares. \n-- ----------------------------------------------------------------------\n\ndef evens : set \u2115 := {n | even n}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el conjunto de los n\u00fameros impares. \n-- ----------------------------------------------------------------------\n\ndef odds :  set \u2115 := {n | \u00ac even n}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar la uni\u00f3n de los pares e impares es el universal.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : evens \u222a odds = univ :=\nbegin\n  rw [evens, odds],\n  ext n,\n  simp,\n  apply classical.em,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u22a2 evens \u222a odds = univ\n  >> rw [evens, odds],\n\u22a2 {n : \u2115 | n.even} \u222a {n : \u2115 | \u00acn.even} = univ\n  >> ext n,\nn : \u2115\n\u22a2 n \u2208 {n : \u2115 | n.even} \u222a {n : \u2115 | \u00acn.even} \u2194 n \u2208 univ\n  >> simp,\n\u22a2 n.even \u2228 \u00acn.even\n  >> apply classical.em,\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : evens \u222a odds = univ :=\nbegin\n  ext n,\n  simp,\n  apply classical.em,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u22a2 evens \u222a odds = univ\n  >> ext n,\nn : \u2115\n\u22a2 n \u2208 evens \u222a odds \u2194 n \u2208 univ\n  >> simp,\n\u22a2 n \u2208 evens \u2228 n \u2208 odds\n  >> apply classical.em,\nno goals\n-/\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Union_de_pares_e_impares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7473800513744628}}
{"text": "import data.nat.prime \n\nnamespace nat\n\nclass Prime :=\n(p : \u2115) (pp : nat.prime p)\n\n-- unit test\n\ndefinition two' : Prime := \u27e82,prime_two\u27e9\n\ninstance Prime_is_nat : has_coe Prime \u2115 := \u27e8\u03bb P, P.p\u27e9\n\n-- unit test\n\nexample : (two' : \u2115) = 2 := rfl\n\nend nat \n\nclass is_prime (p : \u2115) : Prop := \n(Hp : nat.prime p)\n\n\n", "meta": {"author": "mr-infty", "repo": "perfectoid-spaces", "sha": "1a49b3897ec3c7b871d8c970926c00f727a4e2a6", "save_path": "github-repos/lean/mr-infty-perfectoid-spaces", "path": "github-repos/lean/mr-infty-perfectoid-spaces/perfectoid-spaces-1a49b3897ec3c7b871d8c970926c00f727a4e2a6/src/for_mathlib/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7473197021876993}}
{"text": "--proving random stuff about fibonacci numbers\n--hopefully show F_n | F_m if n | m\nimport tactic\n\n--useful for working with Sigma notation\nopen_locale big_operators\nopen finset\n\ndef F : \u2115 \u2192 \u2124\n| 0 := 0\n| 1 := 1\n| (n + 2) := F n + F (n + 1)\n\nlemma fib_nonneg' (n : \u2115) : \u2200 m \u2264 n, F m \u2265 0 :=\nbegin\n  cases n,\n  { intros,\n    cases H,\n    exact le_refl _,\n  },\n  induction n with n hn,\n  { intros,\n    cases H with H1 H2,\n    { exact int.one_nonneg},\n    { change m \u2264 0 at H2,\n      rw nat.le_zero_iff at H2,\n      rw H2,\n      exact le_refl _,},\n  },\n  { intros,\n    cases H with H1 H2,\n    { change F n + F (n + 1) \u2265 0,\n      apply add_nonneg,\n      { apply hn,\n        exact nat.le_succ n,\n      },\n      { apply hn,\n        exact le_refl _,\n      }\n    },\n    { exact hn m H2,}\n  },\nend\nlemma fib_nonneg (n : \u2115) : F n \u2265 0 := fib_nonneg' n n (le_refl n)\nlemma fib_add_two (n : \u2115) : F (n + 2) = F n + F (n + 1) := rfl\n@[simp] lemma fib_zero : F 0 = 0 := rfl\n@[simp] lemma fib_one : F 1 = 1 := rfl\n@[simp] lemma fib_two : F 2 = 1 := rfl\n\nexample (n : \u2115) : \u2211 i in range n, F i = F (n + 1) - 1 :=\nbegin\n  induction n with n hn,\n  { simp [F],},\n  { rw sum_range_succ,\n    rw hn,\n    rw fib_add_two,\n    ring,\n  }\nend\n\nexample (n : \u2115) : \u2211 i in range (n + 1), (F i)^2 = F (n) * F (n+1) :=\nbegin\n  induction n with n ih,\n  { refl,},\n  { rw sum_range_succ,\n    rw ih,\n    rw fib_add_two,\n    ring,\n  }\nend\n\nlemma fibonacci_hell' (m n : \u2115) : \u2200 k : \u2115, k \u2264 n \u2192 F (m + k + 1) = \n  F (m + 1) * F (k + 1) + F m * F k :=\nbegin\n  cases n,\n  {simp,},\n  induction n with n ih,\n  { rintro \u27e8k, rfl\u27e9,\n    simp,\n    intro h,\n    cases h with h h,\n    rw fib_add_two,\n    simp,\n    rw add_comm,\n    cases h,\n  },\n  { intros k hk,\n    cases hk with hk hk,\n    { rw nat.add_succ m,\n      rw fib_add_two,\n      nth_rewrite 0 nat.add_succ,\n      rw ih n (nat.le_succ n),\n      rw ih (n.succ) (le_refl n.succ),\n      rw fib_add_two n.succ,\n      rw fib_add_two,\n      ring,\n    },\n    { exact ih k hk},\n  }\nend\n\nlemma fibonacci_hell (m n : \u2115) : F (m + n + 1) = \n  F (m + 1) * F (n + 1) + F m * F n := fibonacci_hell' m n n (le_refl n)\n\nlemma fib_dvd_fib (m n : \u2115) : n \u2223 m \u2192 F n \u2223 F m :=\nbegin\n  rintro \u27e8k, rfl\u27e9,\n  cases n,\n  { simp},\n  induction k with k ih,\n  { simp,},\n  { have H : n.succ * k.succ = n.succ + n.succ*k := by {zify, ring},\n    rw H,\n    have H2 := fibonacci_hell n.succ (n.succ*k - 1),\n    cases k,\n    { simp,},\n    have H3 : n.succ * k.succ - 1 + 1 = n.succ * k.succ,\n      { apply nat.succ_pred_eq_of_pos,\n        apply mul_pos;\n        apply nat.succ_pos,\n      },\n    rw add_assoc at H2,\n    rw H3 at H2,\n    rw H2,\n    apply dvd_add,\n    { exact dvd_mul_of_dvd_right ih (F (nat.succ n + 1)),},\n    { apply dvd_mul_right,},\n  }\nend", "meta": {"author": "raymondpg", "repo": "XLL", "sha": "f97237922687d0edfa3fdab4c9cb831b39284e49", "save_path": "github-repos/lean/raymondpg-XLL", "path": "github-repos/lean/raymondpg-XLL/XLL-f97237922687d0edfa3fdab4c9cb831b39284e49/src/Leo/Fibonacci.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090322, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7473196869622443}}
{"text": "import tactic.norm_num\nimport tactic.linarith\nimport tactic.ring\nimport data.nat.basic\nimport data.real.basic\nimport data.set.basic\nimport data.set.lattice\nimport data.complex.basic\nimport data.complex.exponential\nimport data.polynomial\n--import analysis.polynomial\n--import analysis.exponential\nimport data.nat.choose\n\nuniverse u\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n--QUESTION 1\n\nsection question_1\n\nopen nat\n\n----part a\n\n------i\n\ntheorem count (n : \u2115) (hn : n \u2265 1) : finset.sum (finset.range (nat.succ n)) (\u03bb m, choose n m) = 2 ^ n := ---ans\n    begin\n        have H := (add_pow (1 : \u2115) 1 n).symm,\n        simpa [nat.one_pow, one_mul, one_add_one_eq_two, \n            (finset.sum_nat_cast _ _).symm, nat.cast_id] using H,\n    end\n\n------ii\ntheorem countdown (n : \u2115) (hn : n \u2265 1) : finset.sum (finset.range (nat.succ n)) (\u03bb m, (-1 : \u2124) ^ m * choose n m) = 0 := ---ans\n    begin\n        have H := (add_pow (-1 : \u2124) 1 n).symm,\n        have H2 := @_root_.zero_pow \u2124 _ _ hn,\n        simpa [nat.one_pow, one_mul, one_add_one_eq_two, nat.zero_pow hn,\n            (finset.sum_nat_cast _ _).symm, nat.cast_id, H2] using H,\n    end\n\n----part b\n------i\nopen real\n#exit\nnoncomputable def chebyshev : \u2115 \u2192 polynomial \u211d\n| 0 := polynomial.C 1\n| 1 := polynomial.X\n| (n + 2) := 2 * polynomial.X * chebyshev (n + 1) - chebyshev n\n\ndef chebyshev' : \u2115 \u2192 polynomial \u2124\n| 0 := polynomial.C 1\n| 1 := polynomial.X\n| (n + 2) := 2 * polynomial.X * chebyshev' (n + 1) - chebyshev' n\n\nlemma polycos (n : \u2115) (hn : n \u2265 1) : \u2200 \u03b8 : \u211d, cos (n * \u03b8) = polynomial.eval (cos \u03b8) (chebyshev n) :=\n    begin\n        intro \u03b8,\n        apply nat.strong_induction_on n,\n        intros k ih, \n        have ih1 : cos (\u2191(k - 1) * \u03b8) = polynomial.eval (cos \u03b8) (chebyshev (k - 1)),\n            by_cases h : k = 0,\n              simp [h, chebyshev],\n          --by_cases h : k \u2260 0,\n              exact ih (k - 1) (nat.sub_lt (nat.pos_of_ne_zero h) (by norm_num : 0 < 1)),\n        have ih2 : cos (\u2191(k - 2) * \u03b8) = polynomial.eval (cos \u03b8) (chebyshev (k - 2)),\n            by_cases h : k = 0,\n              simp [h, chebyshev],\n            --by_cases h : k \u2260 0,\n              exact ih (k - 2) (nat.sub_lt (nat.pos_of_ne_zero h) (by norm_num : 0 < 2)),\n        by_cases h1 : k = 0, simp [h1, chebyshev],\n        by_cases h2 : k = 1, simp [h2, chebyshev],\n        have hk : k = (k - 2) + 2, rw nat.sub_add_cancel, swap,\n        rw [hk, chebyshev, \u2190hk, nat.succ_eq_add_one, (_ : k - 2 + 1 = k - 1), two_mul,\n            polynomial.eval_sub, polynomial.eval_mul, polynomial.eval_add,\n            polynomial.eval_X, \u2190two_mul, \u2190ih1, \u2190ih2], \n        rw [\u2190complex.of_real_inj, complex.of_real_sub, complex.of_real_mul, complex.of_real_mul,\n            complex.of_real_cos, complex.of_real_cos, complex.of_real_cos, complex.of_real_cos,\n            complex.cos, complex.cos, complex.cos, complex.cos],\n        simp,\n        rw [mul_div_cancel', \u2190mul_div_assoc, \u2190neg_div, \u2190add_div, add_mul, mul_add, mul_add,\n            \u2190complex.exp_add, \u2190complex.exp_add, \u2190complex.exp_add, \u2190complex.exp_add,\n            mul_assoc, mul_assoc, mul_assoc],\n        rw [\u2190one_mul (\u2191\u03b8 * complex.I)] {occs := occurrences.pos [5, 7]},\n        rw [\u2190add_mul, \u2190sub_eq_add_neg, \u2190sub_mul, \u2190neg_one_mul (\u2191\u03b8 * complex.I),\n            \u2190add_mul, \u2190sub_eq_add_neg, \u2190sub_mul, @nat.cast_sub _ _ _ 1 k, add_sub, nat.cast_one, \n            add_sub_cancel', \u2190sub_add, sub_add_eq_add_sub, one_add_one_eq_two, add_sub, \n            \u2190sub_add_eq_add_sub, \u2190neg_add', one_add_one_eq_two, \u2190sub_add, sub_add_eq_add_sub, \n            neg_add_self, zero_sub, nat.cast_sub, neg_mul_eq_neg_mul, neg_mul_eq_neg_mul, \n            neg_sub, nat.cast_two, neg_add, sub_eq_neg_add, \u2190add_assoc, \u2190neg_add, \n            \u2190sub_eq_neg_add, add_sub_add_right_eq_sub, \u2190add_assoc, sub_add_cancel],\n        all_goals { \n            try {\n            have H : k \u2265 2,\n                apply le_of_not_gt, intro,\n                have h12 : k = 0 \u2228 k = 1,\n                    clear ih ih1 ih2 h1 h2, try { clear hk },\n                    revert k a, exact dec_trivial,\n                apply or.elim h12 (\u03bb h12, h1 h12) (\u03bb h12, h2 h12) }, \n                try { exact H }, try { exact le_trans (by norm_num : 1 \u2264 2) H } },\n        apply two_ne_zero',\n        apply @eq_of_add_eq_add_right _ _ _ 1 _,\n        rw [add_assoc, one_add_one_eq_two, nat.sub_add_cancel H, \n            nat.sub_add_cancel (le_trans (by norm_num : 1 \u2264 2) H)]\n    end\n\ntheorem exist_polycos (n : \u2115) (hn : n \u2265 1) : \u2203 Pn : polynomial \u211d, \u2200 \u03b8 : \u211d, cos (n * \u03b8) = polynomial.eval (cos \u03b8) Pn := ---ans\n    Exists.intro (chebyshev n) (polycos n hn)\n\n------ii\n\nopen polynomial\n\nexample : chebyshev' 4 = 8 * X ^ 4 - 8 * X ^ 2 + 1 :=\nbegin\n  unfold chebyshev',\n  ring\nend\n\n------iii\n\nlemma useful (k : \u2115) : polynomial.degree (chebyshev' k) = k :=\nbegin\n    apply nat.strong_induction_on k,\n    intros n ih,\n    have ih1 : polynomial.degree (chebyshev' (n - 1)) = \u2191(n - 1),\n        by_cases h : n = 0,\n            simp [h, chebyshev'], refl,\n            exact ih _ (nat.sub_lt (nat.pos_of_ne_zero h) (zero_lt_one)),\n    have ih2 : polynomial.degree (chebyshev' (n - 2)) = \u2191(n - 2),\n        by_cases h : n \u2264 1,\n            apply or.elim ((dec_trivial : \u2200 j : \u2115, j \u2264 1 \u2192 j = 0 \u2228 j = 1) n h),\n                intro h0, simp [h0, chebyshev'], refl,\n                intro h1, simp [h1, chebyshev'], refl,\n            apply ih _, apply nat.sub_lt (lt_of_not_ge (\u03bb w, h (le_trans w zero_le_one))), norm_num,\n    by_cases h : n \u2265 2,\n        have H : n - 2 + 2 = n := nat.sub_add_cancel h,\n        have H' : nat.succ (n - 2) = n - 1,\n            have W : n \u2265 2,\n                apply le_of_not_gt, intro,\n                have h12 : n = 0 \u2228 n = 1,\n                    clear ih ih1 ih2 H h,\n                    revert n a, exact dec_trivial,\n                apply or.elim h12,\n                    intro h1, rw h1 at h, revert h, norm_num,\n                    intro h2, rw h2 at h, revert h, norm_num,\n        apply @eq_of_add_eq_add_right _ _ _ 1 _,\n        show n - 2 + 1 + 1 = n - 1 + 1,\n        rw [add_assoc, one_add_one_eq_two, nat.sub_add_cancel W, \n            nat.sub_add_cancel (le_of_lt h)],\n        rw [\u2190H, chebyshev', H, sub_eq_neg_add, polynomial.degree_add_eq_of_degree_lt,\n            polynomial.degree_mul_eq, polynomial.degree_mul_eq, polynomial.degree_X, H', ih1],\n        show (polynomial.degree (polynomial.C 2) + 1 + \u2191(n - 1) = \u2191n),\n        rw [polynomial.degree_C, zero_add, \u2190with_bot.coe_one, \u2190with_bot.coe_add,\n            add_comm, nat.sub_add_cancel (le_of_lt h)],\n        exact two_ne_zero',\n        rw [polynomial.degree_neg, polynomial.degree_mul_eq, polynomial.degree_mul_eq, ih2, H', ih1],\n        show (\u2191(n - 2) < polynomial.degree (polynomial.C 2) + polynomial.degree polynomial.X + \u2191(n - 1)),\n        rw [polynomial.degree_C, polynomial.degree_X, zero_add, \u2190with_bot.coe_one, \u2190with_bot.coe_add,\n            add_comm, nat.sub_add_cancel (le_of_lt h), with_bot.coe_lt_coe],\n        apply nat.sub_lt (lt_trans zero_lt_one h), norm_num,\n        exact two_ne_zero',\n        apply or.elim ((dec_trivial : \u2200 j : \u2115, j \u2264 1 \u2192 j = 0 \u2228 j = 1) n (le_of_not_gt h)),\n            intro h0, simp [h0, chebyshev'], refl,\n            intro h1, simp [h1, chebyshev']\nend\n\nlemma useful' (k : \u2115) : polynomial.degree (chebyshev' (k - 2)) < 1 + polynomial.degree (chebyshev' (k - 1)) :=\nbegin\n    rw [useful, useful, \u2190with_bot.coe_one, \u2190with_bot.coe_add, with_bot.coe_lt_coe, add_comm],\n    by_cases h : k \u2264 1,\n        apply or.elim ((dec_trivial : \u2200 (j : \u2115), j \u2264 1 \u2192 j = 0 \u2228 j = 1) k h),\n            intro h0, simp [h0], exact zero_lt_one,\n            intro h1, simp [h1], exact zero_lt_one,\n    rw [nat.sub_add_cancel (le_of_not_le h)],\n    apply nat.sub_lt (lt_of_lt_of_le zero_lt_one (le_of_not_le h)), norm_num\nend\n\ntheorem not_useful (n : \u2115) : polynomial.leading_coeff (chebyshev' n) = 2 ^ (n - 1) := ---ans\nbegin\n    apply nat.strong_induction_on n, intros k hk,\n    have h1 : polynomial.leading_coeff (chebyshev' (k - 1)) = 2 ^ (k - 1 - 1),\n        by_cases h : k = 0,\n          simp [h, chebyshev'],\n          exact hk (k - 1) (nat.pred_lt h : k - 1 < k),\n    have h2 : polynomial.leading_coeff (chebyshev' (k - 2)) = 2 ^ (k - 2 - 1),\n        by_cases h : k \u2264 1,\n            apply or.elim ((dec_trivial : \u2200 j : \u2115, j \u2264 1 \u2192 j = 0 \u2228 j = 1) k h),\n                intro h0, simp [h0, chebyshev'], \n                intro h1, simp [h1, chebyshev'],\n            exact hk (k - 2) (nat.sub_lt (lt_of_not_ge (\u03bb w, h (le_trans w zero_le_one))) (by norm_num)),\n    by_cases h : k \u2265 2,\n        have H : k - 2 + 2 = k := nat.sub_add_cancel h,\n        rw [\u2190H, chebyshev', H, (_ : nat.succ (k - 2) = k - 1), sub_eq_add_neg, add_comm, \n            polynomial.leading_coeff_add_of_degree_lt, polynomial.leading_coeff_mul,\n            polynomial.leading_coeff_mul, \u2190one_add_one_eq_two, \n            polynomial.leading_coeff_add_of_degree_eq rfl, \u2190polynomial.C_1,\n            polynomial.leading_coeff_C, polynomial.leading_coeff_X, h1, \n            one_add_one_eq_two, mul_one, \u2190pow_succ, nat.sub_add_cancel],\n    change 1 \u2264 k - 1,\n    rwa [nat.le_sub_left_iff_add_le (le_of_lt h), one_add_one_eq_two],\n    rw [\u2190polynomial.C_1, polynomial.leading_coeff_C, one_add_one_eq_two], exact two_ne_zero',\n    rw [polynomial.degree_neg, polynomial.degree_mul_eq, polynomial.degree_mul_eq,\n        ((one_add_one_eq_two).symm : ((2 : polynomial \u2124) = 1 + 1)), \u2190polynomial.C_1, \u2190polynomial.C_add, \n        one_add_one_eq_two, polynomial.degree_C, zero_add, polynomial.degree_X],\n    exact useful' k,\n    exact two_ne_zero',\n    rw [nat.succ_eq_add_one, eq_comm, \u2190nat.sub_eq_iff_eq_add, nat.sub_sub, one_add_one_eq_two],\n    rwa [nat.le_sub_left_iff_add_le (le_of_lt h), one_add_one_eq_two],\n    rw not_lt at h, \n    have h' : k = 0 \u2228 k = 1, clear hk h1 h2, revert k h, exact dec_trivial,\n    cases h',\n        all_goals { simp [h', chebyshev'] }\nend\n\n------iv\n\ntheorem cheby1 (n : \u2115) (hn : n \u2265 1) : polynomial.eval 1 (chebyshev n) = 1 := ---ans\nbegin\n    have h := (polycos n hn 0).symm,\n    rwa [mul_zero, cos_zero] at h,\nend\n\n--QUESTION 2\n----part a\n------i\ndef ub (S : set \u211d) (x : \u211d) := \u2200 s \u2208 S, s \u2264 x ---ans\n\n------ii\ndef iba (S : set \u211d) := \u2203 x, ub S x ---ans\n\n------iii\ndef lub (S : set \u211d) (x : \u211d) := ub S x \u2227 \u2200 y : \u211d, (ub S y \u2192 x \u2264 y) ---ans\n\n----part b\ntheorem lub_duh (S : set \u211d) : (\u2203 x, lub S x) \u2192 S \u2260 \u2205 \u2227 iba S := ---ans\n    begin\n        intro Hexlub, cases Hexlub with x Hlub,\n        split,\n            intro Hemp, rw set.empty_def at Hemp, \n            cases Hlub with Hub Hl,\n            have Hallub : \u2200 y : \u211d, ub S y, \n                unfold ub, rw Hemp, change (\u2200 (y s : \u211d), false \u2192 s \u2264 y), \n                intros y s Hf, exfalso, exact Hf,\n            have Hneginf : \u2200 y : \u211d, x \u2264 y,\n                intro y, apply Hl, apply Hallub,\n            have Hcontr := Hneginf (x - 1),\n            revert Hcontr, norm_num,\n      --split,\n            existsi x, exact Hlub.left,\n    end\n\n----part c\n------i\ndef S1 := {x : \u211d | x < 59}\n\nlemma between_bounds (x y : \u211d) (H : x < y) : x < (x + y) / 2 \u2227 (x + y) / 2 < y := \n\u27e8by linarith, by linarith\u27e9\n\ntheorem S1_lub : \u2203 x, lub S1 x := ---ans\n    begin\n        existsi (59 : \u211d),\n        split,\n            intro, change (s < 59 \u2192 s \u2264 59), exact le_of_lt,\n      --split,\n            intro y, change ((\u2200 (s : \u211d), s < 59 \u2192 s \u2264 y) \u2192 59 \u2264 y), intro Hbub,\n            apply le_of_not_gt, intro Hbadub,\n            have Houtofbounds := between_bounds y 59 Hbadub,\n            apply not_le_of_gt Houtofbounds.1 (Hbub ((y + 59) / 2) Houtofbounds.2),\n    end\n\n------ii\n\n/------------------SORRY--------------------/\n\n----part d\n------i\ntheorem ublub_the_first (S : set \u211d) (b : \u211d) (hub : ub S b) (hin : b \u2208 S) : lub S b := ---ans\n    begin\n        split,\n            exact hub,\n      --split,\n            intros y huby,\n            exact huby b hin,\n    end\n\n------ii\ntheorem adlub_the_second (S T : set \u211d) (b c : \u211d) (hlubb : lub S b) (hlubc : lub T c) ---ans\n: lub ({x : \u211d | \u2203 s t : \u211d, s \u2208 S \u2227 t \u2208 T \u2227 x = s + t}) (b + c) :=\n    begin\n        split,\n            unfold ub, simp, intros x s hss t htt hxst, rw hxst,\n            apply add_le_add (hlubb.1 s hss) (hlubc.1 t htt),\n      --split,\n            unfold ub, simp, intros x Hx,\n            apply le_of_not_gt, intro Hcontr,\n            let \u03b5 := b + c - x, \n            have Hcontr' : \u03b5 > 0 := (by linarith : b + c - x > 0),\n            have rwx : x = (b - \u03b5 / 2) + (c - \u03b5 / 2) \n            := (by linarith : x = (b - (b + c - x) / 2) + (c - (b + c - x) / 2)),\n            have hnbub : \u2203 s' \u2208 S, b - \u03b5 / 2 < s',\n                by_contradiction,\n                have a' : (\u00ac\u2203 (s' : \u211d), s' \u2208 S \u2227 b - \u03b5 / 2 < s'), \n                    intro b, apply a, cases b with \u03c3 H\u03c3, existsi \u03c3, existsi H\u03c3.1, exact H\u03c3.2,\n                have a'' : \u2200 (x : \u211d), x \u2208 S \u2192 \u00ac(b - \u03b5 / 2 < x),\n                    intros x Hx Hb, rw not_exists at a', apply a' x, exact \u27e8Hx, Hb\u27e9,\n                simp only [not_lt] at a'', rw \u2190ub at a'',\n                have a''' := hlubb.2 _ a'',\n                linarith,\n            have hnbuc : \u2203 t' \u2208 T, c - \u03b5 / 2 < t',\n                by_contradiction,\n                have a' : (\u00ac\u2203 (t' : \u211d), t' \u2208 T \u2227 c - \u03b5 / 2 < t'), \n                    intro b, apply a, cases b with \u03c3 H\u03c3, existsi \u03c3, existsi H\u03c3.1, exact H\u03c3.2,\n                have a'' : \u2200 (x : \u211d), x \u2208 T \u2192 \u00ac(c - \u03b5 / 2 < x),\n                    intros x Hx Hc, rw not_exists at a', apply a' x, exact \u27e8Hx, Hc\u27e9,\n                simp only [not_lt] at a'', rw \u2190ub at a'',\n                have a''' := hlubc.2 _ a'',\n                linarith,\n            cases hnbub with s' hnbub', cases hnbub' with Hs' hnbub'',\n            cases hnbuc with t' hnbuc', cases hnbuc' with Ht' hnbuc'',\n            have Hx' := Hx (s' + t') s' Hs' t' Ht' rfl,\n            have Haha : x < x \n            := lt_of_lt_of_le (by { rw rwx, apply add_lt_add hnbub'' hnbuc'' } : x < s' + t') Hx',\n            linarith,            \n    end\n\n--QUESTION 3\nvariable {S : Type u}\n\n----part a\n------i\nvariable (binary_relation : S \u2192 S \u2192 Prop) ---ans\nlocal infix ` ~ `:1000 := binary_relation\n\n------ii\ndef reflexivity := \u2200 x, x ~ x\ndef symmetry := \u2200 (x y), x ~ y \u2192 y ~ x\ndef transitivity := \u2200 (x y z), x ~ y \u2192 y ~ z \u2192 x ~ z\ndef is_equivalence := reflexivity binary_relation \u2227 symmetry binary_relation \u2227 transitivity binary_relation ---ans\n\n------iii\nvariable {binary_relation}\ndef cl (h : is_equivalence binary_relation) (a : S) : set S := { x | x ~ a } ---ans\n\n----part b\ntheorem classes_injective2 (h : is_equivalence binary_relation) (a b : S) : (cl h a = cl h b) \u2228 (cl h a \u2229 cl h b) = \u2205 := ---ans\n    begin\n        /-duplicate h so we can continue using it as a parameter to cl, then unpack hDupe-/\n        have hDupe : is_equivalence binary_relation := h,\n        cases hDupe with hR hST, cases hST with hS hT,\n        rw reflexivity at hR, rw symmetry at hS, rw transitivity at hT,\n        /-if one of them is true (if they exclude) we don't need to bother-/\n        cases classical.em (cl h a \u2229 cl h b = \u2205) with excl intsct,\n        --case excl\n            right, exact excl,\n        --case intsct\n            left,\n            /-prove that if something isn't empty it must have stuff in it-/\n            rw set.eq_empty_iff_forall_not_mem at intsct,\n            rw not_forall_not at intsct,\n            /-clean stuff up-/\n            cases intsct with x intsctX, cases intsctX with intsctXa intsctXb,\n            rw cl at intsctXa, rw cl at intsctXb,\n            change binary_relation x a at intsctXa, change binary_relation x b at intsctXb,\n            rename intsctXa Hrxa, rename intsctXb Hrxb,\n            rw cl, rw cl,\n            /-now do the actual math-/\n            have Hrax : binary_relation a x, apply hS x a, exact Hrxa,\n            have Hrab : binary_relation a b, apply hT a x b, exact Hrax, exact Hrxb,\n            have Hrba : binary_relation b a, apply hS a b, exact Hrab,\n            /-definition of set equivalence-/\n            apply set.eq_of_subset_of_subset,\n            --split 1\n                /-clean things up again-/\n                intro y, intro Hrya, change binary_relation y a at Hrya, change binary_relation y b,\n                /-do math again-/\n                apply hT y a b, exact Hrya, exact Hrab,\n            --split 2\n                /-clean things up again-/\n                intro y, intro Hryb, change binary_relation y b at Hryb, change binary_relation y a,\n                /-do math again-/\n                have Hrby : binary_relation b y, apply hS y b, exact Hryb,\n                apply hT y b a, exact Hryb, exact Hrba,\n    end\n\n----part c\n\ninductive double_cosets : \u2124 \u2192 \u2124 \u2192 Prop\n    | cond1 : \u2200 x, double_cosets x (x + 3)\n    | cond2 : \u2200 x, double_cosets x (x - 5)\n    | condT : \u2200 x y z, double_cosets x y \u2192 double_cosets y z \u2192 double_cosets x z\nlocal infix ` \u22c6 `:1001 := double_cosets\n\ntheorem double_cosets_reflexive : reflexivity double_cosets := ---ans\n    begin\n        rw reflexivity, intro x,\n        /-get some trivial things out of the way-/\n        have H0 : x - 5 - 5 - 5 + 3 + 3 + 3 + 3 + 3 = x, norm_num,\n        /-start moving-/\n        have Hx5x : x \u22c6 (x - 5), exact double_cosets.cond2 x,\n        have H5x10x : (x - 5) \u22c6 (x - 5 - 5), exact double_cosets.cond2 (x - 5),\n        have H10x15x : (x - 5 - 5) \u22c6 (x - 5 - 5 - 5), exact double_cosets.cond2 (x - 5 - 5),\n        /-transitivity is hopper fare-/\n        have Hx10x : x \u22c6 (x - 5 - 5), apply double_cosets.condT x (x - 5) (x - 5 - 5), exact Hx5x, exact H5x10x,\n        have Hx15x : x \u22c6 (x - 5 - 5 - 5), apply double_cosets.condT x (x - 5 - 5) (x - 5 - 5 - 5), exact Hx10x, exact H10x15x,\n        /-now come back-/\n        have H15x12x : (x - 5 - 5 - 5) \u22c6 (x - 5 - 5 - 5 + 3), exact double_cosets.cond1 (x - 5 - 5 - 5),\n        have H12x9x : (x - 5 - 5 - 5 + 3) \u22c6 (x - 5 - 5 - 5 + 3 + 3), exact double_cosets.cond1 (x - 5 - 5 - 5 + 3),\n        have H9x6x : (x - 5 - 5 - 5 + 3 + 3) \u22c6 (x - 5 - 5 - 5 + 3 + 3 + 3), exact double_cosets.cond1 (x - 5 - 5 - 5 + 3 + 3),\n        have H6x3x : (x - 5 - 5 - 5 + 3 + 3 + 3) \u22c6 (x - 5 - 5 - 5 + 3 + 3 + 3 + 3), exact double_cosets.cond1 (x - 5 - 5 - 5 + 3 + 3 + 3),\n        have H3xx : (x - 5 - 5 - 5 + 3 + 3 + 3 + 3) \u22c6 (x - 5 - 5 - 5 + 3 + 3 + 3 + 3 + 3), exact double_cosets.cond1 (x - 5 - 5 - 5 + 3 + 3 + 3 + 3),\n        /-are we still within 1 hour?-/\n        have H15x9x : (x - 5 - 5 - 5) \u22c6 (x - 5 - 5 - 5 + 3 + 3), apply double_cosets.condT (x - 5 - 5 - 5) (x - 5 - 5 - 5 + 3) (x - 5 - 5 - 5 + 3 + 3), exact H15x12x, exact H12x9x,\n        have H15x6x : (x - 5 - 5 - 5) \u22c6 (x - 5 - 5 - 5 + 3 + 3 + 3), apply double_cosets.condT (x - 5 - 5 - 5) (x - 5 - 5 - 5 + 3 + 3) (x - 5 - 5 - 5 + 3 + 3 + 3), exact H15x9x, exact H9x6x,\n        have H15x3x : (x - 5 - 5 - 5) \u22c6 (x - 5 - 5 - 5 + 3 + 3 + 3 + 3), apply double_cosets.condT (x - 5 - 5 - 5) (x - 5 - 5 - 5 + 3 + 3 + 3) (x - 5 - 5 - 5 + 3 + 3 + 3 + 3), exact H15x6x, exact H6x3x,\n        have H15xx : (x - 5 - 5 - 5) \u22c6 (x - 5 - 5 - 5 + 3 + 3 + 3 + 3 + 3), apply double_cosets.condT (x - 5 - 5 - 5) (x - 5 - 5 - 5 + 3 + 3 + 3 + 3) (x - 5 - 5 - 5 + 3 + 3 + 3 + 3 + 3), exact H15x3x, exact H3xx,\n        have Hxx : x \u22c6 (x - 5 - 5 - 5 + 3 + 3 + 3 + 3 + 3), apply double_cosets.condT x (x - 5 - 5 - 5) (x - 5 - 5 - 5 + 3 + 3 + 3 + 3 + 3), exact Hx15x, exact H15xx,\n        /-show that we're back-/\n        rw H0 at Hxx, exact Hxx,\n    end\n\n----part d\n\ndef S' : Type := fin 2\n\ninductive self : fin 2 \u2192 fin 2 \u2192 Prop\n    | condR : \u2200 x, self x x\nlocal infix ` \u22c6 `:1 := self\n\ntheorem self_transitive : transitivity self := ---ans\n    begin\n        rw transitivity,\n        intros x y z,\n        --rw S' at z y x,\n        have Hxyyzzx : x = y \u2228 y = z \u2228 z = x,\n            cases classical.em (x = y \u2228 y = z \u2228 z = x) with corr contr,\n            --case corr\n                exact corr,\n            --case contr\n                exfalso,\n                have contr_rw : \u00ac (x = y) \u2227 \u00ac (y = z) \u2227 \u00ac (z = x),\n                    rw \u2190not_or_distrib, rw \u2190not_or_distrib, exact contr,\n                cases contr_rw with contr_xy contr_yzzx, cases contr_yzzx with contr_yz contr_zx,\n                have H01 : \u2200 s : fin 2, s = 0 \u2228 s = 1, exact dec_trivial,\n                have x01 : x = 0 \u2228 x = 1, exact H01 x,\n                have y01 : y = 0 \u2228 y = 1, exact H01 y,\n                have z01 : z = 0 \u2228 z = 1, exact H01 z,\n                cases x01, cases y01, cases z01,\n                    rw \u2190y01 at x01, apply contr_xy, exact x01,\n                    rw \u2190y01 at x01, apply contr_xy, exact x01,\n                  cases z01,\n                    rw \u2190x01 at z01, apply contr_zx, exact z01,\n                    rw \u2190z01 at y01, apply contr_yz, exact y01,\n                  cases y01, cases z01,\n                    rw \u2190z01 at y01, apply contr_yz, exact y01,\n                    rw \u2190x01 at z01, apply contr_zx, exact z01,\n                  cases z01,\n                    rw \u2190y01 at x01, apply contr_xy, exact x01,\n                    rw \u2190y01 at x01, apply contr_xy, exact x01,\n        cases Hxyyzzx with Hxy Hyzzx,\n        --case Hxy\n            rw Hxy,\n            intro Hyy, intro Hyz, exact Hyz,\n          cases Hyzzx with Hyz Hxy,\n        --case Hyz\n            rw Hyz,\n            intro Hxz, intro Hzz, exact Hxz,\n        --case Hxy\n            rw Hxy,\n            intro Hxy, intro Hyx, exact self.condR x,\n    end\n\n--QUESTION 4\nvariable {X : Type u}\nvariable {Y : Type u}\nvariable {f : X \u2192 Y}\n\n----part a\n------i\ndef injectivity (g : X \u2192 Y) := \u2200 x1 x2 : X, g x1 = g x2 \u2192 x1 = x2 ---ans\n\n------ii\ndef surjectivity (g : X \u2192 Y) := \u2200 y : Y, \u2203 x : X, g x = y ---ans\n\n------iii\ndef bijectivity (g : X \u2192 Y) := injectivity g \u2227 surjectivity g ---ans\n\n----part b\n------i\ndef f1 : \u2115 \u2192 \u2115\n    | n := n + 2\ntheorem injection : \u2203 f : \u2115 \u2192 \u2115, injectivity f \u2227 \u00ac surjectivity f := ---ans\n    begin\n        have injectionf1 : injectivity f1 \u2227 \u00ac surjectivity f1,\n            split,\n            --split 1\n                rw injectivity,\n                change \u2200 (x1 x2 : \u2115), x1 + 2 = x2 + 2 \u2192 x1 = x2,\n                intros x1 x2, intro Hinjsame,\n                calc x1 = x1 + 2 - 2 : by rw nat.add_sub_cancel\n                    ... = x2 + 2 - 2 : by rw Hinjsame\n                    ... = x2 : by rw nat.add_sub_cancel,\n            --split 2\n                rw surjectivity, intro Hsurj,\n                change \u2200 (y : \u2115), \u2203 (x : \u2115), x + 2 = y at Hsurj,\n                have Hsurj1 := Hsurj 1,\n                cases Hsurj1 with x Hx10',\n                have Hx10 : x + 1 = 0 :=\n                    calc x + 1 = x + (2 - 1) : by norm_num\n                           ... = (x + 2) - 1 : begin rw \u2190nat.add_sub_assoc, norm_num end\n                           ... = 1 - 1 : by rw Hx10'\n                           ... = 0 : by rw nat.sub_self,\n                have Hnx10 : x + 1 \u2260 0, exact nat.add_one_ne_zero x,\n                apply Hnx10, exact Hx10,\n        fapply exists.intro, exact f1, exact injectionf1,\n    end\n\n------ii\ndef f2 : \u2115 \u2192 \u2115\n    | n := n / 2\n\ntheorem surjection : \u2203 f : \u2115 \u2192 \u2115, surjectivity f \u2227 \u00ac injectivity f := ---ans\n    begin\n        have surjectionf2 : surjectivity f2 \u2227 \u00ac injectivity f2,\n            split,\n            --split 1\n                rw surjectivity,\n                change \u2200 (y : \u2115), \u2203 (x : \u2115), x / 2 = y,\n                intro y,\n                fapply exists.intro, exact 2 * y,\n                    calc 2 * y / 2 = (2 * y + 0) / 2 : by rw nat.add_zero\n                               ... = (0 + 2 * y) / 2 : by rw nat.add_comm\n                               ... = 0 / 2 + y : begin rw nat.add_mul_div_left 0 y, norm_num, end\n                               ... = 0 + y : by norm_num\n                               ... = y + 0 : by rw nat.add_comm\n                               ... = y : by rw nat.add_zero,\n            --split 2\n                rw injectivity, intro Hinj,\n                change \u2200 (x1 x2 : \u2115), x1 / 2 = x2 / 2 \u2192 x1 = x2 at Hinj,\n                have Hinjsame23 := Hinj 2 3,\n                have Hn23 : 2 = 3 \u2192 false, norm_num,\n                apply Hn23, apply Hinjsame23, norm_num,\n        fapply exists.intro, exact f2, exact surjectionf2,\n    end\n\n------iii\ntheorem bijections_are_injections : (\u2203 f : \u2115 \u2192 \u2115, bijectivity f \u2227 \u00ac injectivity f) \u2192 false := ---ans\n    begin\n        intro Hf,\n        cases Hf with f Hff,\n        rw bijectivity at Hff,\n        cases Hff with Hffis Hfffi, cases Hffis with Hffi Hffs,\n        apply Hfffi, exact Hffi,\n    end\n\n------iv\ndef setN : set \u2115 := set.univ\ndef powN := set.powerset setN\n\ntheorem cantor : \u00ac (\u2203 F : \u2115 \u2192 set \u2115, bijectivity F) := ---ans\n    begin\n        intro HE_cantor,\n        cases HE_cantor with F HE_cantor_F,\n        let Snm : set \u2115 := {n : \u2115 | \u00ac (n \u2208 F n)},\n        rw bijectivity at HE_cantor_F, cases HE_cantor_F with HE_can_F HE_tor_F, rw surjectivity at HE_tor_F, rw injectivity at HE_can_F,\n        have HE_tor_F_S := HE_tor_F Snm,\n        cases HE_tor_F_S with x Hx_tor_F_S,\n        cases classical.em (x \u2208 Snm) with HxS HxnS,\n        --case HxS\n            have HnxS := HxS,\n            change \u00ac (x \u2208 F x) at HnxS,\n            rw Hx_tor_F_S at HnxS,\n            apply HnxS, exact HxS,\n        --case HxnS\n            have HyxS := HxnS,\n            change \u00ac \u00ac (x \u2208 F x) at HyxS,\n            rw Hx_tor_F_S at HyxS,\n            apply HyxS, exact HxnS,\n    end\n\n----part c\ndef G (f : X \u2192 Y) : set (X \u00d7 Y) := { g | g.2 = f (g.1) }\ndef p1 (g : G f) : X := g.1.1\n\ndef injectivity' {X' Y' : Type u} (g : X' \u2192 Y') := \u2200 x1 x2 : X', g x1 = g x2 \u2192 x1 = x2\ndef surjectivity' {X' Y' : Type u} (g : X' \u2192 Y') := \u2200 y : Y', \u2203 x : X', g x = y\ndef bijectivity' {X' Y' : Type u} (g : X' \u2192 Y') := injectivity' g \u2227 surjectivity' g\n\ntheorem bij_p1 : @bijectivity' (\u21a5(G f)) X (p1) := ---ans\n    begin\n        split,\n            intros x1 x2 Hpx, rw [p1, p1] at Hpx,\n            cases x1, cases x2, cases x1_val, cases x2_val,\n            change x1_val_snd = f(x1_val_fst) at x1_property,\n            change x2_val_snd = f(x2_val_fst) at x2_property,\n            simp, simp at Hpx,\n            have Hpfx : x1_val_snd = x2_val_snd, rw [x1_property, x2_property, Hpx],\n            split, rw Hpx, rw Hpfx,\n      --split,\n            intro x,\n            let xy : (\u21a5(G f)) := \u27e8\u27e8x,f x\u27e9, rfl\u27e9,\n            existsi xy, refl,\n    end\n\n----part d\ndef p2 (g : G f) : Y := g.1.2\n\ntheorem bij_p2_f : @bijectivity' (\u21a5(G f)) Y (p2) \u2192 bijectivity' f := ---ans\n    begin\n        intro Hp,\n        cases Hp with Hpi Hps, rw injectivity' at Hpi, rw surjectivity' at Hps,\n        split,\n            intros a b Hfx,\n            let afa : (\u21a5(G f)) := \u27e8\u27e8a,f a\u27e9, rfl\u27e9,\n            let bfb : (\u21a5(G f)) := \u27e8\u27e8b,f b\u27e9, rfl\u27e9,\n            have Hpab : p2 afa = p2 bfb, rw [p2, p2], simp, exact Hfx,\n            have Hpiab := Hpi afa bfb Hpab, simp at Hpiab, cases Hpiab with Hab Hfab, \n            exact Hab,\n      --split,\n            intro y,\n            have Hpsy := Hps y, cases Hpsy with xy Hpxy, \n            rw p2 at Hpxy, cases xy, cases xy_val, change xy_val_snd = y at Hpxy,\n            change xy_val_snd = f xy_val_fst at xy_property,\n            existsi xy_val_fst, rw [\u2190xy_property, Hpxy],\n    end\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1F-exam-may-2018", "sha": "8b5eca2037d4a14d6cfac3da1858b6c4119216d3", "save_path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018", "path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018/M1F-exam-may-2018-8b5eca2037d4a14d6cfac3da1858b6c4119216d3/exam18.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8031737869342624, "lm_q1q2_score": 0.7473196775518532}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot, Casper Putz, Anne Baanen\n-/\nimport data.matrix.basic\nimport linear_algebra.finite_dimensional\n\n/-!\n# The finite-dimensional space of matrices\n\nThis file shows that `m` by `n` matrices form a finite-dimensional space,\nand proves the `finrank` of that space is equal to `card m * card n`.\n\n## Main definitions\n\n * `matrix.finite_dimensional`: matrices form a finite dimensional vector space over a field `K`\n * `matrix.finrank_matrix`: the `finrank` of `matrix m n R` is `card m * card n`\n\n## Tags\n\nmatrix, finite dimensional, findim, finrank\n\n-/\n\nuniverses u v\n\nnamespace matrix\n\nsection finite_dimensional\n\nvariables {m n : Type*} [fintype m] [fintype n]\nvariables {R : Type v} [field R]\n\ninstance : finite_dimensional R (matrix m n R) :=\nlinear_equiv.finite_dimensional (linear_equiv.curry R m n)\n\n/--\nThe dimension of the space of finite dimensional matrices\nis the product of the number of rows and columns.\n-/\n@[simp] lemma finrank_matrix :\n  finite_dimensional.finrank R (matrix m n R) = fintype.card m * fintype.card n :=\nby rw [@linear_equiv.finrank_eq R (matrix m n R) _ _ _ _ _ _ (linear_equiv.curry R m n).symm,\n       finite_dimensional.finrank_fintype_fun_eq_card, fintype.card_prod]\n\nend finite_dimensional\n\nend matrix\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/matrix/finite_dimensional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7472984867584553}}
{"text": "import tactic -- hide\nopen function nat -- hide\n\n/-\n## The `intro` tactic\n\nMany statements in mathematics start with the phrase: \"for all $x$ such that...\". The way to proceed is usually\nto suppose that we are given an $x$ with the given condition, and then prove something about it.\n\nThe tactic `intro` allows for this. It takes a parameter, which will be the name given to the variable.\n\nIt also works in statements of the form `P \u2192 Q` (we can think of it as equivalent to \"To each proof of $P$ we produce a proof of $Q$\").\n\nIn the following lemma, we will need to apply the `intro` tactic twice to get to business.\n\n**Pro tip:** the `revert` tactic does exactly the opposite.\n\n**Pro tip bis:** `intros h1 h2 h3,` is the same as `intro h1, intro h2, intro h3,`.\n-/\n/- Symbol:\n\u2200 : \\forall\n\u2192 : \\imp\n-/\n/- Lemma : no-side-bar\nFor all $a$, if $a = 3$ then $a + 1 = 4$.\n-/\nlemma l4 : \u2200 (a : \u2115),  a = 3 \u2192 a + 1 = 4 :=\nbegin\n  intro a,\n  intro h,\n  rw h,\n\n\n  \nend", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/tutorial_world/04_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7472984811659781}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Eric Wieser\n-/\n\nimport algebra.char_p.basic\nimport ring_theory.ideal.quotient\n\n/-!\n# Characteristic of quotients rings\n-/\n\nuniverses u v\n\nnamespace char_p\n\ntheorem quotient (R : Type u) [comm_ring R] (p : \u2115) [hp1 : fact p.prime] (hp2 : \u2191p \u2208 nonunits R) :\n  char_p (R \u29f8 (ideal.span {p} : ideal R)) p :=\nhave hp0 : (p : R \u29f8 (ideal.span {p} : ideal R)) = 0,\n  from map_nat_cast (ideal.quotient.mk (ideal.span {p} : ideal R)) p \u25b8\n    ideal.quotient.eq_zero_iff_mem.2 (ideal.subset_span $ set.mem_singleton _),\nring_char.of_eq $ or.resolve_left ((nat.dvd_prime hp1.1).1 $ ring_char.dvd hp0) $ \u03bb h1,\nhp2 $ is_unit_iff_dvd_one.2 $ ideal.mem_span_singleton.1 $ ideal.quotient.eq_zero_iff_mem.1 $\n@@subsingleton.elim (@@char_p.subsingleton _ $ ring_char.of_eq h1) _ _\n\n/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient\ninherits the characteristic of the underlying ring. -/\nlemma quotient' {R : Type*} [comm_ring R] (p : \u2115) [char_p R p] (I : ideal R)\n  (h : \u2200 x : \u2115, (x : R) \u2208 I \u2192 (x : R) = 0) :\n  char_p (R \u29f8 I) p :=\n\u27e8\u03bb x, begin\n  rw [\u2190cast_eq_zero_iff R p x, \u2190map_nat_cast (ideal.quotient.mk I)],\n  refine quotient.eq'.trans (_ : \u2191x - 0 \u2208 I \u2194 _),\n  rw sub_zero,\n  exact \u27e8h x, \u03bb h', h'.symm \u25b8 I.zero_mem\u27e9,\nend\u27e9\n\nend char_p\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/char_p/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7472984796520172}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sean m y n n\u00fameros naturales. Demostrar que si\n--    m \u2223 n \u2227 m \u2260 n\n-- entonces\n--    m \u2223 n \u2227 \u00ac n \u2223 m\n-- ----------------------------------------------------------------------\n\nimport data.nat.gcd\n\nopen nat\n\nvariables {m n : \u2115} \n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h : m \u2223 n \u2227 m \u2260 n) \n  : m \u2223 n \u2227 \u00ac n \u2223 m :=\nbegin\n  cases h with h\u2080 h\u2081,\n  split,\n    exact h\u2080,\n  contrapose! h\u2081,\n  apply dvd_antisymm h\u2080 h\u2081,\nend\n\n-- Prueba\n-- ======\n\n/-\nm n : \u2115,\nh : m \u2223 n \u2227 m \u2260 n\n\u22a2 m \u2223 n \u2227 \u00acn \u2223 m\n  >> cases h with h\u2080 h\u2081,\nh\u2080 : m \u2223 n,\nh\u2081 : m \u2260 n\n\u22a2 m \u2223 n \u2227 \u00acn \u2223 m\n  >> split,\n| \u22a2 m \u2223 n\n|   >>   exact h\u2080,\n\u22a2 \u00acn \u2223 m\n  >> contrapose! h\u2081,\nh\u2081 : n \u2223 m\n\u22a2 m = n\n  >> apply dvd_antisymm h\u2080 h\u2081,\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h : m \u2223 n \u2227 m \u2260 n) \n  : m \u2223 n \u2227 \u00ac n \u2223 m :=\nbegin\n  rcases h with \u27e8h\u2080, h\u2081\u27e9,\n  split,\n    exact h\u2080,\n  contrapose! h\u2081,\n  apply dvd_antisymm h\u2080 h\u2081,\nend\n\n-- Prueba\n-- ======\n\n/-\nm n : \u2115,\nh : m \u2223 n \u2227 m \u2260 n\n\u22a2 m \u2223 n \u2227 \u00acn \u2223 m\n  >> rcases h with \u27e8h\u2080, h\u2081\u27e9,\nh\u2080 : m \u2223 n,\nh\u2081 : m \u2260 n\n\u22a2 m \u2223 n \u2227 \u00acn \u2223 m\n  >> split,\n| \u22a2 m \u2223 n\n|   >>   exact h\u2080,\n\u22a2 \u00acn \u2223 m\n  >> contrapose! h\u2081,\nh\u2081 : n \u2223 m\n\u22a2 m = n\n  >> apply dvd_antisymm h\u2080 h\u2081,\nno goals\n-/\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Uso_de_conjuncion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7472494256622316}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro\n-/\nimport algebra.associated\nimport linear_algebra.basic\nimport order.zorn\nimport order.atoms\nimport order.compactly_generated\nimport tactic.abel\nimport data.nat.choose.sum\nimport linear_algebra.finsupp\n/-!\n\n# Ideals over a ring\n\nThis file defines `ideal R`, the type of (left) ideals over a ring `R`.\nNote that over commutative rings, left ideals and two-sided ideals are equivalent.\n\n## Implementation notes\n\n`ideal R` is implemented using `submodule R R`, where `\u2022` is interpreted as `*`.\n\n## TODO\n\nSupport right ideals, and two-sided ideals over non-commutative rings.\n-/\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\nopen set function\n\nopen_locale classical big_operators pointwise\n\n/-- A (left) ideal in a semiring `R` is an additive submonoid `s` such that\n`a * b \u2208 s` whenever `b \u2208 s`. If `R` is a ring, then `s` is an additive subgroup.  -/\n@[reducible] def ideal (R : Type u) [semiring R] := submodule R R\n\nsection semiring\n\nnamespace ideal\nvariables [semiring \u03b1] (I : ideal \u03b1) {a b : \u03b1}\n\nprotected lemma zero_mem : (0 : \u03b1) \u2208 I := I.zero_mem\n\nprotected lemma add_mem : a \u2208 I \u2192 b \u2208 I \u2192 a + b \u2208 I := I.add_mem\n\nvariables (a)\nlemma mul_mem_left : b \u2208 I \u2192 a * b \u2208 I := I.smul_mem a\nvariables {a}\n\n@[ext] lemma ext {I J : ideal \u03b1} (h : \u2200 x, x \u2208 I \u2194 x \u2208 J) : I = J :=\nsubmodule.ext h\n\nlemma sum_mem (I : ideal \u03b1) {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 \u03b1} :\n  (\u2200c\u2208t, f c \u2208 I) \u2192 (\u2211 i in t, f i) \u2208 I := submodule.sum_mem I\n\ntheorem eq_top_of_unit_mem\n  (x y : \u03b1) (hx : x \u2208 I) (h : y * x = 1) : I = \u22a4 :=\neq_top_iff.2 $ \u03bb z _, calc\n    z = z * (y * x) : by simp [h]\n  ... = (z * y) * x : eq.symm $ mul_assoc z y x\n  ... \u2208 I : I.mul_mem_left _ hx\n\ntheorem eq_top_of_is_unit_mem {x} (hx : x \u2208 I) (h : is_unit x) : I = \u22a4 :=\nlet \u27e8y, hy\u27e9 := h.exists_left_inv in eq_top_of_unit_mem I x y hx hy\n\ntheorem eq_top_iff_one : I = \u22a4 \u2194 (1:\u03b1) \u2208 I :=\n\u27e8by rintro rfl; trivial,\n \u03bb h, eq_top_of_unit_mem _ _ 1 h (by simp)\u27e9\n\ntheorem ne_top_iff_one : I \u2260 \u22a4 \u2194 (1:\u03b1) \u2209 I :=\nnot_congr I.eq_top_iff_one\n\n@[simp]\ntheorem unit_mul_mem_iff_mem {x y : \u03b1} (hy : is_unit y) : y * x \u2208 I \u2194 x \u2208 I :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, I.mul_mem_left y h\u27e9,\n  obtain \u27e8y', hy'\u27e9 := hy.exists_left_inv,\n  have := I.mul_mem_left y' h,\n  rwa [\u2190 mul_assoc, hy', one_mul] at this,\nend\n\n/-- The ideal generated by a subset of a ring -/\ndef span (s : set \u03b1) : ideal \u03b1 := submodule.span \u03b1 s\n\n@[simp] lemma submodule_span_eq {s : set \u03b1} :\n  submodule.span \u03b1 s = ideal.span s :=\nrfl\n\n@[simp] lemma span_empty : span (\u2205 : set \u03b1) = \u22a5 := submodule.span_empty\n\n@[simp] lemma span_univ : span (set.univ : set \u03b1) = \u22a4 := submodule.span_univ\n\nlemma span_union (s t : set \u03b1) : span (s \u222a t) = span s \u2294 span t :=\nsubmodule.span_union _ _\n\nlemma span_Union {\u03b9} (s : \u03b9 \u2192 set \u03b1) : span (\u22c3 i, s i) = \u2a06 i, span (s i) :=\nsubmodule.span_Union _\n\nlemma mem_span {s : set \u03b1} (x) : x \u2208 span s \u2194 \u2200 p : ideal \u03b1, s \u2286 p \u2192 x \u2208 p :=\nmem_Inter\u2082\n\nlemma subset_span {s : set \u03b1} : s \u2286 span s := submodule.subset_span\n\nlemma span_le {s : set \u03b1} {I} : span s \u2264 I \u2194 s \u2286 I := submodule.span_le\n\nlemma span_mono {s t : set \u03b1} : s \u2286 t \u2192 span s \u2264 span t := submodule.span_mono\n\n@[simp] lemma span_eq : span (I : set \u03b1) = I := submodule.span_eq _\n\n@[simp] lemma span_singleton_one : span ({1} : set \u03b1) = \u22a4 :=\n(eq_top_iff_one _).2 $ subset_span $ mem_singleton _\n\nlemma mem_span_insert {s : set \u03b1} {x y} :\n  x \u2208 span (insert y s) \u2194 \u2203 a (z \u2208 span s), x = a * y + z := submodule.mem_span_insert\n\nlemma mem_span_singleton' {x y : \u03b1} :\n  x \u2208 span ({y} : set \u03b1) \u2194 \u2203 a, a * y = x := submodule.mem_span_singleton\n\nlemma span_insert (x) (s : set \u03b1) : span (insert x s) = span ({x} : set \u03b1) \u2294 span s :=\nsubmodule.span_insert x s\n\nlemma span_eq_bot {s : set \u03b1} : span s = \u22a5 \u2194 \u2200 x \u2208 s, (x:\u03b1) = 0 := submodule.span_eq_bot\n\n@[simp] lemma span_singleton_eq_bot {x} : span ({x} : set \u03b1) = \u22a5 \u2194 x = 0 :=\nsubmodule.span_singleton_eq_bot\n\n@[simp] lemma span_zero : span (0 : set \u03b1) = \u22a5 := by rw [\u2190set.singleton_zero, span_singleton_eq_bot]\n\n@[simp] lemma span_one : span (1 : set \u03b1) = \u22a4 := by rw [\u2190set.singleton_one, span_singleton_one]\n\nlemma span_eq_top_iff_finite (s : set \u03b1) :\n  span s = \u22a4 \u2194 \u2203 s' : finset \u03b1, \u2191s' \u2286 s \u2227 span (s' : set \u03b1) = \u22a4 :=\nbegin\n  simp_rw eq_top_iff_one,\n  exact \u27e8submodule.mem_span_finite_of_mem_span, \u03bb \u27e8s', h\u2081, h\u2082\u27e9, span_mono h\u2081 h\u2082\u27e9\nend\n\n/--\nThe ideal generated by an arbitrary binary relation.\n-/\ndef of_rel (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : ideal \u03b1 :=\nsubmodule.span \u03b1 { x | \u2203 (a b) (h : r a b), x + b = a }\n\n/-- An ideal `P` of a ring `R` is prime if `P \u2260 R` and `xy \u2208 P \u2192 x \u2208 P \u2228 y \u2208 P` -/\nclass is_prime (I : ideal \u03b1) : Prop :=\n(ne_top' : I \u2260 \u22a4)\n(mem_or_mem' : \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I)\n\ntheorem is_prime_iff {I : ideal \u03b1} :\n  is_prime I \u2194 I \u2260 \u22a4 \u2227 \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I :=\n\u27e8\u03bb h, \u27e8h.1, h.2\u27e9, \u03bb h, \u27e8h.1, h.2\u27e9\u27e9\n\ntheorem is_prime.ne_top {I : ideal \u03b1} (hI : I.is_prime) : I \u2260 \u22a4 := hI.1\n\ntheorem is_prime.mem_or_mem {I : ideal \u03b1} (hI : I.is_prime) :\n  \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I := hI.2\n\ntheorem is_prime.mem_or_mem_of_mul_eq_zero {I : ideal \u03b1} (hI : I.is_prime)\n  {x y : \u03b1} (h : x * y = 0) : x \u2208 I \u2228 y \u2208 I :=\nhI.mem_or_mem (h.symm \u25b8 I.zero_mem)\n\ntheorem is_prime.mem_of_pow_mem {I : ideal \u03b1} (hI : I.is_prime)\n  {r : \u03b1} (n : \u2115) (H : r^n \u2208 I) : r \u2208 I :=\nbegin\n  induction n with n ih,\n  { rw pow_zero at H, exact (mt (eq_top_iff_one _).2 hI.1).elim H },\n  { rw pow_succ at H, exact or.cases_on (hI.mem_or_mem H) id ih }\nend\n\nlemma not_is_prime_iff {I : ideal \u03b1} : \u00ac I.is_prime \u2194 I = \u22a4 \u2228 \u2203 (x \u2209 I) (y \u2209 I), x * y \u2208 I :=\nbegin\n  simp_rw [ideal.is_prime_iff, not_and_distrib, ne.def, not_not, not_forall, not_or_distrib],\n  exact or_congr iff.rfl\n    \u27e8\u03bb \u27e8x, y, hxy, hx, hy\u27e9, \u27e8x, hx, y, hy, hxy\u27e9, \u03bb \u27e8x, hx, y, hy, hxy\u27e9, \u27e8x, y, hxy, hx, hy\u27e9\u27e9\nend\n\ntheorem zero_ne_one_of_proper {I : ideal \u03b1} (h : I \u2260 \u22a4) : (0:\u03b1) \u2260 1 :=\n\u03bb hz, I.ne_top_iff_one.1 h $ hz \u25b8 I.zero_mem\n\nlemma bot_prime {R : Type*} [ring R] [is_domain R] : (\u22a5 : ideal R).is_prime :=\n\u27e8\u03bb h, one_ne_zero (by rwa [ideal.eq_top_iff_one, submodule.mem_bot] at h),\n \u03bb x y h, mul_eq_zero.mp (by simpa only [submodule.mem_bot] using h)\u27e9\n\n/-- An ideal is maximal if it is maximal in the collection of proper ideals. -/\nclass is_maximal (I : ideal \u03b1) : Prop := (out : is_coatom I)\n\ntheorem is_maximal_def {I : ideal \u03b1} : I.is_maximal \u2194 is_coatom I := \u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\ntheorem is_maximal.ne_top {I : ideal \u03b1} (h : I.is_maximal) : I \u2260 \u22a4 := (is_maximal_def.1 h).1\n\ntheorem is_maximal_iff {I : ideal \u03b1} : I.is_maximal \u2194\n  (1:\u03b1) \u2209 I \u2227 \u2200 (J : ideal \u03b1) x, I \u2264 J \u2192 x \u2209 I \u2192 x \u2208 J \u2192 (1:\u03b1) \u2208 J :=\nis_maximal_def.trans $ and_congr I.ne_top_iff_one $ forall_congr $ \u03bb J,\nby rw [lt_iff_le_not_le]; exact\n \u27e8\u03bb H x h hx\u2081 hx\u2082, J.eq_top_iff_one.1 $\n    H \u27e8h, not_subset.2 \u27e8_, hx\u2082, hx\u2081\u27e9\u27e9,\n  \u03bb H \u27e8h\u2081, h\u2082\u27e9, let \u27e8x, xJ, xI\u27e9 := not_subset.1 h\u2082 in\n   J.eq_top_iff_one.2 $ H x h\u2081 xI xJ\u27e9\n\ntheorem is_maximal.eq_of_le {I J : ideal \u03b1}\n  (hI : I.is_maximal) (hJ : J \u2260 \u22a4) (IJ : I \u2264 J) : I = J :=\neq_iff_le_not_lt.2 \u27e8IJ, \u03bb h, hJ (hI.1.2 _ h)\u27e9\n\ninstance : is_coatomic (ideal \u03b1) :=\nbegin\n  apply complete_lattice.coatomic_of_top_compact,\n  rw \u2190span_singleton_one,\n  exact submodule.singleton_span_is_compact_element 1,\nend\n\n/-- **Krull's theorem**: if `I` is an ideal that is not the whole ring, then it is included in some\n    maximal ideal. -/\ntheorem exists_le_maximal (I : ideal \u03b1) (hI : I \u2260 \u22a4) :\n  \u2203 M : ideal \u03b1, M.is_maximal \u2227 I \u2264 M :=\nlet \u27e8m, hm\u27e9 := (eq_top_or_exists_le_coatom I).resolve_left hI in \u27e8m, \u27e8\u27e8hm.1\u27e9, hm.2\u27e9\u27e9\n\nvariables (\u03b1)\n\n/-- Krull's theorem: a nontrivial ring has a maximal ideal. -/\ntheorem exists_maximal [nontrivial \u03b1] : \u2203 M : ideal \u03b1, M.is_maximal :=\nlet \u27e8I, \u27e8hI, _\u27e9\u27e9 := exists_le_maximal (\u22a5 : ideal \u03b1) bot_ne_top in \u27e8I, hI\u27e9\n\nvariables {\u03b1}\n\ninstance [nontrivial \u03b1] : nontrivial (ideal \u03b1) :=\nbegin\n  rcases @exists_maximal \u03b1 _ _ with \u27e8M, hM, _\u27e9,\n  exact nontrivial_of_ne M \u22a4 hM\nend\n\n/-- If P is not properly contained in any maximal ideal then it is not properly contained\n  in any proper ideal -/\nlemma maximal_of_no_maximal {R : Type u} [semiring R] {P : ideal R}\n(hmax : \u2200 m : ideal R, P < m \u2192 \u00acis_maximal m) (J : ideal R) (hPJ : P < J) : J = \u22a4 :=\nbegin\n  by_contradiction hnonmax,\n  rcases exists_le_maximal J hnonmax with \u27e8M, hM1, hM2\u27e9,\n  exact hmax M (lt_of_lt_of_le hPJ hM2) hM1,\nend\n\ntheorem mem_span_pair {x y z : \u03b1} :\n  z \u2208 span ({x, y} : set \u03b1) \u2194 \u2203 a b, a * x + b * y = z :=\nby simp [mem_span_insert, mem_span_singleton', @eq_comm _ _ z]\n\ntheorem is_maximal.exists_inv {I : ideal \u03b1}\n  (hI : I.is_maximal) {x} (hx : x \u2209 I) : \u2203 y, \u2203 i \u2208 I, y * x + i = 1 :=\nbegin\n  cases is_maximal_iff.1 hI with H\u2081 H\u2082,\n  rcases mem_span_insert.1 (H\u2082 (span (insert x I)) x\n    (set.subset.trans (subset_insert _ _) subset_span)\n    hx (subset_span (mem_insert _ _))) with \u27e8y, z, hz, hy\u27e9,\n  refine \u27e8y, z, _, hy.symm\u27e9,\n  rwa \u2190 span_eq I,\nend\n\nsection lattice\nvariables {R : Type u} [semiring R]\n\nlemma mem_sup_left {S T : ideal R} : \u2200 {x : R}, x \u2208 S \u2192 x \u2208 S \u2294 T :=\nshow S \u2264 S \u2294 T, from le_sup_left\n\nlemma mem_sup_right {S T : ideal R} : \u2200 {x : R}, x \u2208 T \u2192 x \u2208 S \u2294 T :=\nshow T \u2264 S \u2294 T, from le_sup_right\n\n\n\nlemma mem_Sup_of_mem {S : set (ideal R)} {s : ideal R}\n  (hs : s \u2208 S) : \u2200 {x : R}, x \u2208 s \u2192 x \u2208 Sup S :=\nshow s \u2264 Sup S, from le_Sup hs\n\ntheorem mem_Inf {s : set (ideal R)} {x : R} :\n  x \u2208 Inf s \u2194 \u2200 \u2983I\u2984, I \u2208 s \u2192 x \u2208 I :=\n\u27e8\u03bb hx I his, hx I \u27e8I, infi_pos his\u27e9, \u03bb H I \u27e8J, hij\u27e9, hij \u25b8 \u03bb S \u27e8hj, hS\u27e9, hS \u25b8 H hj\u27e9\n\n@[simp] lemma mem_inf {I J : ideal R} {x : R} : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J := iff.rfl\n\n@[simp] lemma mem_infi {\u03b9 : Sort*} {I : \u03b9 \u2192 ideal R} {x : R} : x \u2208 infi I \u2194 \u2200 i, x \u2208 I i :=\nsubmodule.mem_infi _\n\n@[simp] lemma mem_bot {x : R} : x \u2208 (\u22a5 : ideal R) \u2194 x = 0 :=\nsubmodule.mem_bot _\n\nend lattice\n\nsection pi\nvariables (\u03b9 : Type v)\n\n/-- `I^n` as an ideal of `R^n`. -/\ndef pi : ideal (\u03b9 \u2192 \u03b1) :=\n{ carrier := { x | \u2200 i, x i \u2208 I },\n  zero_mem' := \u03bb i, I.zero_mem,\n  add_mem' := \u03bb a b ha hb i, I.add_mem (ha i) (hb i),\n  smul_mem' := \u03bb a b hb i, I.mul_mem_left (a i) (hb i) }\n\nlemma mem_pi (x : \u03b9 \u2192 \u03b1) : x \u2208 I.pi \u03b9 \u2194 \u2200 i, x i \u2208 I := iff.rfl\n\nend pi\n\nend ideal\n\nend semiring\n\nsection comm_semiring\n\nvariables {a b : \u03b1}\n\n-- A separate namespace definition is needed because the variables were historically in a different\n-- order.\nnamespace ideal\nvariables [comm_semiring \u03b1] (I : ideal \u03b1)\n\n@[simp]\ntheorem mul_unit_mem_iff_mem {x y : \u03b1} (hy : is_unit y) : x * y \u2208 I \u2194 x \u2208 I :=\nmul_comm y x \u25b8 unit_mul_mem_iff_mem I hy\n\nlemma mem_span_singleton {x y : \u03b1} :\n  x \u2208 span ({y} : set \u03b1) \u2194 y \u2223 x :=\nmem_span_singleton'.trans $ exists_congr $ \u03bb _, by rw [eq_comm, mul_comm]\n\nlemma span_singleton_le_span_singleton {x y : \u03b1} :\n  span ({x} : set \u03b1) \u2264 span ({y} : set \u03b1) \u2194 y \u2223 x :=\nspan_le.trans $ singleton_subset_iff.trans mem_span_singleton\n\nlemma span_singleton_eq_span_singleton {\u03b1 : Type u} [comm_ring \u03b1] [is_domain \u03b1] {x y : \u03b1} :\n  span ({x} : set \u03b1) = span ({y} : set \u03b1) \u2194 associated x y :=\nbegin\n  rw [\u2190dvd_dvd_iff_associated, le_antisymm_iff, and_comm],\n  apply and_congr;\n  rw span_singleton_le_span_singleton,\nend\n\nlemma span_singleton_mul_right_unit {a : \u03b1} (h2 : is_unit a) (x : \u03b1) :\n  span ({x * a} : set \u03b1) = span {x} :=\nbegin\n  apply le_antisymm,\n  { rw span_singleton_le_span_singleton, use a},\n  { rw span_singleton_le_span_singleton, rw is_unit.mul_right_dvd h2}\nend\n\nlemma span_singleton_mul_left_unit {a : \u03b1} (h2 : is_unit a) (x : \u03b1) :\n  span ({a * x} : set \u03b1) = span {x} := by rw [mul_comm, span_singleton_mul_right_unit h2]\n\nlemma span_singleton_eq_top {x} : span ({x} : set \u03b1) = \u22a4 \u2194 is_unit x :=\nby rw [is_unit_iff_dvd_one, \u2190 span_singleton_le_span_singleton, span_singleton_one,\n  eq_top_iff]\n\ntheorem span_singleton_prime {p : \u03b1} (hp : p \u2260 0) :\n  is_prime (span ({p} : set \u03b1)) \u2194 prime p :=\nby simp [is_prime_iff, prime, span_singleton_eq_top, hp, mem_span_singleton]\n\ntheorem is_maximal.is_prime {I : ideal \u03b1} (H : I.is_maximal) : I.is_prime :=\n\u27e8H.1.1, \u03bb x y hxy, or_iff_not_imp_left.2 $ \u03bb hx, begin\n  let J : ideal \u03b1 := submodule.span \u03b1 (insert x \u2191I),\n  have IJ : I \u2264 J  := (set.subset.trans (subset_insert _ _) subset_span),\n  have xJ : x \u2208 J := ideal.subset_span (set.mem_insert x I),\n  cases is_maximal_iff.1 H with _ oJ,\n  specialize oJ J x IJ hx xJ,\n  rcases submodule.mem_span_insert.mp oJ with \u27e8a, b, h, oe\u27e9,\n  obtain (F : y * 1 = y * (a \u2022 x + b)) := congr_arg (\u03bb g : \u03b1, y * g) oe,\n  rw [\u2190 mul_one y, F, mul_add, mul_comm, smul_eq_mul, mul_assoc],\n  refine submodule.add_mem I (I.mul_mem_left a hxy) (submodule.smul_mem I y _),\n  rwa submodule.span_eq at h,\nend\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_maximal.is_prime' (I : ideal \u03b1) : \u2200 [H : I.is_maximal], I.is_prime :=\nis_maximal.is_prime\n\nlemma span_singleton_lt_span_singleton [comm_ring \u03b2] [is_domain \u03b2] {x y : \u03b2} :\n  span ({x} : set \u03b2) < span ({y} : set \u03b2) \u2194 dvd_not_unit y x :=\nby rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton,\n  dvd_and_not_dvd_iff]\n\nlemma factors_decreasing [comm_ring \u03b2] [is_domain \u03b2]\n  (b\u2081 b\u2082 : \u03b2) (h\u2081 : b\u2081 \u2260 0) (h\u2082 : \u00ac is_unit b\u2082) :\n  span ({b\u2081 * b\u2082} : set \u03b2) < span {b\u2081} :=\nlt_of_le_not_le (ideal.span_le.2 $ singleton_subset_iff.2 $\n  ideal.mem_span_singleton.2 \u27e8b\u2082, rfl\u27e9) $ \u03bb h,\nh\u2082 $ is_unit_of_dvd_one _ $ (mul_dvd_mul_iff_left h\u2081).1 $\nby rwa [mul_one, \u2190 ideal.span_singleton_le_span_singleton]\n\nvariables (b)\nlemma mul_mem_right (h : a \u2208 I) : a * b \u2208 I := mul_comm b a \u25b8 I.mul_mem_left b h\nvariables {b}\n\nlemma pow_mem_of_mem (ha : a \u2208 I) (n : \u2115) (hn : 0 < n) : a ^ n \u2208 I :=\nnat.cases_on n (not.elim dec_trivial) (\u03bb m hm, (pow_succ a m).symm \u25b8 I.mul_mem_right (a^m) ha) hn\n\ntheorem is_prime.mul_mem_iff_mem_or_mem {I : ideal \u03b1} (hI : I.is_prime) :\n  \u2200 {x y : \u03b1}, x * y \u2208 I \u2194 x \u2208 I \u2228 y \u2208 I :=\n\u03bb x y, \u27e8hI.mem_or_mem, by { rintro (h | h), exacts [I.mul_mem_right y h, I.mul_mem_left x h] }\u27e9\n\ntheorem is_prime.pow_mem_iff_mem {I : ideal \u03b1} (hI : I.is_prime)\n  {r : \u03b1} (n : \u2115) (hn : 0 < n) : r ^ n \u2208 I \u2194 r \u2208 I :=\n\u27e8hI.mem_of_pow_mem n, (\u03bb hr, I.pow_mem_of_mem hr n hn)\u27e9\n\ntheorem pow_multiset_sum_mem_span_pow (s : multiset \u03b1) (n : \u2115) :\n  s.sum ^ (s.card * n + 1) \u2208 span ((s.map (\u03bb x, x ^ (n + 1))).to_finset : set \u03b1) :=\nbegin\n  induction s using multiset.induction_on with a s hs,\n  { simp },\n  simp only [finset.coe_insert, multiset.map_cons, multiset.to_finset_cons, multiset.sum_cons,\n    multiset.card_cons, add_pow],\n  refine submodule.sum_mem _ _,\n  intros c hc,\n  rw mem_span_insert,\n  by_cases h : n+1 \u2264 c,\n  { refine \u27e8a ^ (c - (n + 1)) * s.sum ^ ((s.card + 1) * n + 1 - c) *\n      (((s.card + 1) * n + 1).choose c), 0, submodule.zero_mem _, _\u27e9,\n    rw mul_comm _ (a ^ (n + 1)),\n    simp_rw \u2190 mul_assoc,\n    rw [\u2190 pow_add, add_zero, add_tsub_cancel_of_le h], },\n  { use 0,\n    simp_rw [zero_mul, zero_add],\n    refine \u27e8_,_,rfl\u27e9,\n    replace h : c \u2264 n := nat.lt_succ_iff.mp (not_le.mp h),\n    have : (s.card + 1) * n + 1 - c = s.card * n + 1 + (n - c),\n    { rw [add_mul, one_mul, add_assoc, add_comm n 1, \u2190 add_assoc, add_tsub_assoc_of_le h] },\n    rw [this, pow_add],\n    simp_rw [mul_assoc, mul_comm (s.sum ^ (s.card * n + 1)), \u2190 mul_assoc],\n    exact mul_mem_left _ _ hs }\nend\n\ntheorem sum_pow_mem_span_pow {\u03b9} (s : finset \u03b9) (f : \u03b9 \u2192 \u03b1) (n : \u2115) :\n  (\u2211 i in s, f i) ^ (s.card * n + 1) \u2208 span ((\u03bb i, f i ^ (n + 1)) '' s) :=\nbegin\n  convert pow_multiset_sum_mem_span_pow (s.1.map f) n,\n  { rw multiset.card_map, refl },\n  rw [multiset.map_map, multiset.to_finset_map, finset.val_to_finset, finset.coe_image]\nend\n\ntheorem span_pow_eq_top (s : set \u03b1)\n  (hs : span s = \u22a4) (n : \u2115) : span ((\u03bb x, x ^ n) '' s) = \u22a4 :=\nbegin\n  rw eq_top_iff_one,\n  cases n,\n  { obtain rfl | \u27e8x, hx\u27e9 := eq_empty_or_nonempty s,\n    { rw [set.image_empty, hs],\n      trivial },\n    { exact subset_span \u27e8_, hx, pow_zero _\u27e9 } },\n  rw [eq_top_iff_one, span, finsupp.mem_span_iff_total] at hs,\n  rcases hs with \u27e8f, hf\u27e9,\n  change f.support.sum (\u03bb a, f a * a) = 1 at hf,\n  have := sum_pow_mem_span_pow f.support (\u03bb a, f a * a) n,\n  rw [hf, one_pow] at this,\n  refine (span_le).mpr _ this,\n  rintros _ hx,\n  simp_rw [finset.mem_coe, set.mem_image] at hx,\n  rcases hx with \u27e8x, hx, rfl\u27e9,\n  have : span ({x ^ (n + 1)} : set \u03b1) \u2264 span ((\u03bb (x : \u03b1), x ^ (n + 1)) '' s),\n  { rw [span_le, set.singleton_subset_iff],\n    exact subset_span \u27e8x, x.prop, rfl\u27e9 },\n  refine this _,\n  rw [mul_pow, mem_span_singleton],\n  exact \u27e8f x ^ (n + 1), mul_comm _ _\u27e9\nend\n\nend ideal\n\nend comm_semiring\n\nsection ring\n\nnamespace ideal\n\nvariables [ring \u03b1] (I : ideal \u03b1) {a b : \u03b1}\n\nprotected lemma neg_mem_iff : -a \u2208 I \u2194 a \u2208 I := neg_mem_iff\nprotected lemma add_mem_iff_left : b \u2208 I \u2192 (a + b \u2208 I \u2194 a \u2208 I) := I.add_mem_iff_left\nprotected lemma add_mem_iff_right : a \u2208 I \u2192 (a + b \u2208 I \u2194 b \u2208 I) := I.add_mem_iff_right\nprotected lemma sub_mem : a \u2208 I \u2192 b \u2208 I \u2192 a - b \u2208 I := sub_mem\n\nlemma mem_span_insert' {s : set \u03b1} {x y} :\n  x \u2208 span (insert y s) \u2194 \u2203a, x + a * y \u2208 span s := submodule.mem_span_insert'\n\nend ideal\n\nend ring\n\nsection division_ring\nvariables {K : Type u} [division_ring K] (I : ideal K)\n\nnamespace ideal\n\n/-- All ideals in a division ring are trivial. -/\nlemma eq_bot_or_top : I = \u22a5 \u2228 I = \u22a4 :=\nbegin\n  rw or_iff_not_imp_right,\n  change _ \u2260 _ \u2192 _,\n  rw ideal.ne_top_iff_one,\n  intro h1,\n  rw eq_bot_iff,\n  intros r hr,\n  by_cases H : r = 0, {simpa},\n  simpa [H, h1] using I.mul_mem_left r\u207b\u00b9 hr,\nend\n\nlemma eq_bot_of_prime [h : I.is_prime] : I = \u22a5 :=\nor_iff_not_imp_right.mp I.eq_bot_or_top h.1\n\nlemma bot_is_maximal : is_maximal (\u22a5 : ideal K) :=\n\u27e8\u27e8\u03bb h, absurd ((eq_top_iff_one (\u22a4 : ideal K)).mp rfl) (by rw \u2190 h; simp),\n\u03bb I hI, or_iff_not_imp_left.mp (eq_bot_or_top I) (ne_of_gt hI)\u27e9\u27e9\n\nend ideal\n\nend division_ring\n\nsection comm_ring\n\nnamespace ideal\n\ntheorem mul_sub_mul_mem {R : Type*} [comm_ring R] (I : ideal R) {a b c d : R}\n  (h1 : a - b \u2208 I) (h2 : c - d \u2208 I) : a * c - b * d \u2208 I :=\nbegin\n  rw (show a * c - b * d = (a - b) * c + b * (c - d), by {rw [sub_mul, mul_sub], abel}),\n  exact I.add_mem (I.mul_mem_right _ h1) (I.mul_mem_left _ h2),\nend\n\nend ideal\n\nend comm_ring\n\nnamespace ring\n\nvariables {R : Type*} [comm_ring R]\n\nlemma not_is_field_of_subsingleton {R : Type*} [ring R] [subsingleton R] : \u00ac is_field R :=\n\u03bb \u27e8\u27e8x, y, hxy\u27e9, _, _\u27e9, hxy (subsingleton.elim x y)\n\nlemma exists_not_is_unit_of_not_is_field [nontrivial R] (hf : \u00ac is_field R) :\n  \u2203 x \u2260 (0 : R), \u00ac is_unit x :=\nbegin\n  have : \u00ac _ := \u03bb h, hf \u27e8exists_pair_ne R, mul_comm, h\u27e9,\n  simp_rw is_unit_iff_exists_inv,\n  push_neg at \u22a2 this,\n  obtain \u27e8x, hx, not_unit\u27e9 := this,\n  exact \u27e8x, hx, not_unit\u27e9\nend\n\nlemma not_is_field_iff_exists_ideal_bot_lt_and_lt_top [nontrivial R] :\n  \u00ac is_field R \u2194 \u2203 I : ideal R, \u22a5 < I \u2227 I < \u22a4 :=\nbegin\n  split,\n  { intro h,\n    obtain \u27e8x, nz, nu\u27e9 := exists_not_is_unit_of_not_is_field h,\n    use ideal.span {x},\n    rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top],\n    exact \u27e8mt ideal.span_singleton_eq_bot.mp nz, mt ideal.span_singleton_eq_top.mp nu\u27e9 },\n  { rintros \u27e8I, bot_lt, lt_top\u27e9 hf,\n    obtain \u27e8x, mem, ne_zero\u27e9 := set_like.exists_of_lt bot_lt,\n    rw submodule.mem_bot at ne_zero,\n    obtain \u27e8y, hy\u27e9 := hf.mul_inv_cancel ne_zero,\n    rw [lt_top_iff_ne_top, ne.def, ideal.eq_top_iff_one, \u2190 hy] at lt_top,\n    exact lt_top (I.mul_mem_right _ mem), }\nend\n\nlemma not_is_field_iff_exists_prime [nontrivial R] :\n  \u00ac is_field R \u2194 \u2203 p : ideal R, p \u2260 \u22a5 \u2227 p.is_prime :=\nnot_is_field_iff_exists_ideal_bot_lt_and_lt_top.trans\n  \u27e8\u03bb \u27e8I, bot_lt, lt_top\u27e9, let \u27e8p, hp, le_p\u27e9 := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top) in\n    \u27e8p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.is_prime\u27e9,\n   \u03bb \u27e8p, ne_bot, prime\u27e9, \u27e8p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr prime.1\u27e9\u27e9\n\n/-- When a ring is not a field, the maximal ideals are nontrivial. -/\nlemma ne_bot_of_is_maximal_of_not_is_field [nontrivial R] {M : ideal R} (max : M.is_maximal)\n  (not_field : \u00ac is_field R) : M \u2260 \u22a5 :=\nbegin\n  rintros h,\n  rw h at max,\n  rcases max with \u27e8\u27e8h1, h2\u27e9\u27e9,\n  obtain \u27e8I, hIbot, hItop\u27e9 := not_is_field_iff_exists_ideal_bot_lt_and_lt_top.mp not_field,\n  exact ne_of_lt hItop (h2 I hIbot),\nend\n\nend ring\n\nnamespace ideal\n\n/-- Maximal ideals in a non-field are nontrivial. -/\nvariables {R : Type u} [comm_ring R] [nontrivial R]\nlemma bot_lt_of_maximal (M : ideal R) [hm : M.is_maximal] (non_field : \u00ac is_field R) : \u22a5 < M :=\nbegin\n  rcases (ring.not_is_field_iff_exists_ideal_bot_lt_and_lt_top.1 non_field)\n    with \u27e8I, Ibot, Itop\u27e9,\n  split, { simp },\n  intro mle,\n  apply @irrefl _ (<) _ (\u22a4 : ideal R),\n  have : M = \u22a5 := eq_bot_iff.mpr mle,\n  rw this at *,\n  rwa hm.1.2 I Ibot at Itop,\nend\n\nend ideal\n\nvariables {a b : \u03b1}\n\n/-- The set of non-invertible elements of a monoid. -/\ndef nonunits (\u03b1 : Type u) [monoid \u03b1] : set \u03b1 := { a | \u00acis_unit a }\n\n@[simp] theorem mem_nonunits_iff [monoid \u03b1] : a \u2208 nonunits \u03b1 \u2194 \u00ac is_unit a := iff.rfl\n\ntheorem mul_mem_nonunits_right [comm_monoid \u03b1] :\n  b \u2208 nonunits \u03b1 \u2192 a * b \u2208 nonunits \u03b1 :=\nmt is_unit_of_mul_is_unit_right\n\ntheorem mul_mem_nonunits_left [comm_monoid \u03b1] :\n  a \u2208 nonunits \u03b1 \u2192 a * b \u2208 nonunits \u03b1 :=\nmt is_unit_of_mul_is_unit_left\n\ntheorem zero_mem_nonunits [semiring \u03b1] : 0 \u2208 nonunits \u03b1 \u2194 (0:\u03b1) \u2260 1 :=\nnot_congr is_unit_zero_iff\n\n@[simp] theorem one_not_mem_nonunits [monoid \u03b1] : (1:\u03b1) \u2209 nonunits \u03b1 :=\nnot_not_intro is_unit_one\n\ntheorem coe_subset_nonunits [semiring \u03b1] {I : ideal \u03b1} (h : I \u2260 \u22a4) :\n  (I : set \u03b1) \u2286 nonunits \u03b1 :=\n\u03bb x hx hu, h $ I.eq_top_of_is_unit_mem hx hu\n\nlemma exists_max_ideal_of_mem_nonunits [comm_semiring \u03b1] (h : a \u2208 nonunits \u03b1) :\n  \u2203 I : ideal \u03b1, I.is_maximal \u2227 a \u2208 I :=\nbegin\n  have : ideal.span ({a} : set \u03b1) \u2260 \u22a4,\n  { intro H, rw ideal.span_singleton_eq_top at H, contradiction },\n  rcases ideal.exists_le_maximal _ this with \u27e8I, Imax, H\u27e9,\n  use [I, Imax], apply H, apply ideal.subset_span, exact set.mem_singleton a\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/ring_theory/ideal/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7472494192586654}}
{"text": "import init.data.set\nimport set_theory.cardinal.basic\nimport helper\n\nopen set\n\n-- proof: https://en.wikipedia.org/wiki/Cantor%27s_theorem#Proof\n\ntheorem cantor_surjective {\u03b1 : Type} (f : \u03b1 \u2192 set \u03b1) : \n  \u00acfunction.surjective f :=\nbegin \n  set B := {x : \u03b1 | x \u2209 f x},\n  by_contradiction,\n  have : \u2203 (\u03be : \u03b1), f \u03be = B,\n  { exact h B, },\n  { rcases this with \u27e8\u03be, fx\u27e9,\n    have : \u03be \u2208 B \u2194 \u03be \u2209 f(\u03be),\n    { exact mem_set_of, },\n    { rw fx at this,\n      exact p_equiv_np_implies_false _ this, }}\nend\n\ntheorem cantor_surjective' {\u03b1 : Type} (f : \u03b1 \u2192 set \u03b1) : \n  \u00acfunction.surjective f :=\nbegin \n  set B := {x : \u03b1 | x \u2209 f x},\n  by_contradiction,\n  obtain \u27e8\u03be, fx\u27e9 : \u2203 \u03be, f \u03be = B := h B,\n  have : \u03be \u2208 B \u2194 \u03be \u2209 f(\u03be),\n  { exact mem_set_of, },\n  { rw fx at this,\n    exact p_equiv_np_implies_false _ this, }\nend", "meta": {"author": "crabbo-rave", "repo": "cantor", "sha": "2e690e45029d2d096ced1253897c200020eb5216", "save_path": "github-repos/lean/crabbo-rave-cantor", "path": "github-repos/lean/crabbo-rave-cantor/cantor-2e690e45029d2d096ced1253897c200020eb5216/src/cantor_surjective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7471982141391037}}
{"text": "import linear_algebra.vandermonde\nimport linear_algebra.matrix.nondegenerate\nimport to_mathlib.polynomial.degree_lt_le\n\nnamespace matrix\nopen_locale big_operators matrix\nopen finset\nlemma det_vandermonde_ne_zero_of_injective {R : Type*} [comm_ring R] \n[is_domain R] {n : \u2115} (\u03b1 : fin n \u21aa R) : (vandermonde \u03b1).det \u2260 0 :=\nbegin\n  simp_rw [det_vandermonde, prod_ne_zero_iff, mem_filter, \n  mem_univ, forall_true_left, true_and, sub_ne_zero, ne.def, \n  embedding_like.apply_eq_iff_eq],\n  rintro _ _ _ rfl, apply lt_irrefl _ (by assumption)\nend\n\ntheorem vandermonde_invertibility' {R : Type*} [comm_ring R]\n[is_domain R] {n : \u2115} (\u03b1 : fin n \u21aa R) {f : fin n \u2192 R}\n(h\u2082 : \u2200 j, \u2211 i : fin n, (\u03b1 j ^ (i : \u2115)) * f i = 0) : f = 0\n:= by {apply eq_zero_of_mul_vec_eq_zero (det_vandermonde_ne_zero_of_injective \u03b1), ext, apply h\u2082}\n\ntheorem vandermonde_invertibility {R : Type*} [comm_ring R]\n[is_domain R] {n : \u2115}\n{\u03b1 : fin n \u21aa R} {f : fin n \u2192 R}\n(h\u2082 : \u2200 j, \u2211 i, f i * (\u03b1 j ^ (i : \u2115))  = 0) : f = 0\n:= by {apply vandermonde_invertibility' \u03b1, simp_rw mul_comm, exact h\u2082}\n\ntheorem vandermonde_invertibility_transposed {R : Type*} [comm_ring R] \n[is_domain R] {n : \u2115}\n{\u03b1 : fin n \u21aa R} {f : fin n \u2192 R}\n(h\u2082 : \u2200 i : fin n, \u2211 j : fin n, f j * (\u03b1 j ^ (i : \u2115)) = 0) : f = 0\n:= by {apply eq_zero_of_vec_mul_eq_zero \n(det_vandermonde_ne_zero_of_injective \u03b1), ext, apply h\u2082}\n\nend matrix\n\nnamespace polynomial\nopen_locale polynomial big_operators\n\nopen linear_equiv matrix polynomial\n\ntheorem vandermonde_invertibility {R : Type*} [comm_ring R] [is_domain R] {n : \u2115}\n(\u03b1 : fin n \u21aa R) (p : degree_lt R n) (h\u2081 : \u2200 j, (p : R[X]).is_root (\u03b1 j)) : p = 0 :=\nbegin\n  simp_rw degree_lt.to_tuple_root at h\u2081,\n  exact (degree_lt.to_tuple_eq_zero_iff p).mp (vandermonde_invertibility h\u2081)\nend\n\ntheorem vandermonde_invertibility_tranposed {R : Type*} [comm_ring R] [is_domain R]\n{n : \u2115} (\u03b1 : fin n \u21aa R) (p : degree_lt R n)\n(h\u2081 : \u2200 i : fin n, \u2211 j : fin n, (p : R[X]).coeff j * (\u03b1 j ^ (i : \u2115)) = 0) : p = 0 :=\n(degree_lt.to_tuple_eq_zero_iff p).mp (vandermonde_invertibility_transposed h\u2081)\n\ntheorem vandermonde_agreement {R : Type*} [comm_ring R] [is_domain R] {n : \u2115}\n(\u03b1 : fin n \u21aa R) {p q : R[X]} (h\u2080 : (p - q) \u2208 degree_lt R n)\n(h\u2082 : \u2200 j, p.eval (\u03b1 j) = q.eval (\u03b1 j)) : p = q :=\nbegin\n  rw \u2190 sub_eq_zero, have vi := vandermonde_invertibility \u03b1 \u27e8p - q, h\u2080\u27e9,\n  simp only [submodule.coe_mk, is_root.def, eval_sub, submodule.mk_eq_zero] at vi,\n  exact vi (\u03bb _, sub_eq_zero.mpr (h\u2082 _)),\nend\n\nend polynomial", "meta": {"author": "linesthatinterlace", "repo": "goppadecoding", "sha": "294f31a0dd56ad9497f3a9585190cdd54f064d7f", "save_path": "github-repos/lean/linesthatinterlace-goppadecoding", "path": "github-repos/lean/linesthatinterlace-goppadecoding/goppadecoding-294f31a0dd56ad9497f3a9585190cdd54f064d7f/src/to_mathlib/polynomial/vandermonde.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7471137148369381}}
{"text": "/-\nCopyright (c) 2020 Gihan Marasingha. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gihan Marasingha\n-/\nimport tactic.linarith\n\n/-!\n# An MIU Decision Procedure in Lean\n\nThe [MIU formal system](https://en.wikipedia.org/wiki/MU_puzzle) was introduced by Douglas\nHofstadter in the first chapter of his 1979 book,\n[G\u00f6del, Escher, Bach](https://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bach).\nThe system is defined by four rules of inference, one axiom, and an alphabet of three symbols:\n`M`, `I`, and `U`.\n\nHofstadter's central question is: can the string `\"MU\"` be derived?\n\nIt transpires that there is a simple decision procedure for this system. A string is derivable if\nand only if it starts with `M`, contains no other `M`s, and the number of `I`s in the string is\ncongruent to 1 or 2 modulo 3.\n\nThe principal aim of this project is to give a Lean proof that the derivability of a string is a\ndecidable predicate.\n\n## The MIU System\n\nIn Hofstadter's description, an _atom_ is any one of `M`, `I` or `U`. A _string_ is a finite\nsequence of zero or more symbols. To simplify notation, we write a sequence `[I,U,U,M]`,\nfor example, as `IUUM`.\n\nThe four rules of inference are:\n\n1. xI \u2192 xIU,\n2. Mx \u2192 Mxx,\n3. xIIIy \u2192 xUy,\n4. xUUy \u2192 xy,\n\nwhere the notation \u03b1 \u2192 \u03b2 is to be interpreted as 'if \u03b1 is derivable, then \u03b2 is derivable'.\n\nAdditionally, he has an axiom:\n\n* `MI` is derivable.\n\nIn Lean, it is natural to treat the rules of inference and the axiom on an equal footing via an\ninductive data type `derivable` designed so that `derivable x` represents the notion that the string\n`x` can be derived from the axiom by the rules of inference. The axiom is represented as a\nnonrecursive constructor for `derivable`. This mirrors the translation of Peano's axiom '0 is a\nnatural number' into the nonrecursive constructor `zero` of the inductive type `nat`.\n\n## References\n\n* [Jeremy Avigad, Leonardo de Moura and Soonho Kong, _Theorem Proving in Lean_]\n  [avigad_moura_kong-2017]\n* [Douglas R Hofstadter, _G\u00f6del, Escher, Bach_][Hofstadter-1979]\n\n## Tags\n\nmiu, derivable strings\n\n-/\n\nnamespace miu\n\n/-!\n### Declarations and instance derivations for `miu_atom` and `miustr`\n-/\n\n/--\nThe atoms of MIU can be represented as an enumerated type in Lean.\n-/\n@[derive decidable_eq]\ninductive miu_atom : Type\n| M : miu_atom\n| I : miu_atom\n| U : miu_atom\n\n/-!\nThe annotation `@[derive decidable_eq]` above assigns the attribute `derive` to `miu_atom`, through\nwhich Lean automatically derives that `miu_atom` is an instance of `decidable_eq`. The use of\n`derive` is crucial in this project and will lead to the automatic derivation of decidability.\n-/\n\nopen miu_atom\n\n/--\nWe show that the type `miu_atom` is inhabited, giving `M` (for no particular reason) as the default\nelement.\n-/\ninstance miu_atom_inhabited : inhabited miu_atom :=\ninhabited.mk M\n\n/--\n`miu_atom.repr` is the 'natural' function from `miu_atom` to `string`.\n-/\ndef miu_atom.repr : miu_atom \u2192 string\n| M := \"M\"\n| I := \"I\"\n| U := \"U\"\n\n/--\nUsing `miu_atom.repr`, we prove that ``miu_atom` is an instance of `has_repr`.\n-/\ninstance : has_repr miu_atom :=\n\u27e8\u03bb u, u.repr\u27e9\n\n/--\nFor simplicity, an `miustr` is just a list of elements of type `miu_atom`.\n-/\n@[derive [has_append, has_mem miu_atom]]\ndef miustr := list miu_atom\n\n/--\nFor display purposes, an `miustr` can be represented as a `string`.\n-/\ndef miustr.mrepr : miustr \u2192 string\n| [] := \"\"\n| (c::cs) := c.repr ++ (miustr.mrepr cs)\n\ninstance miurepr : has_repr miustr :=\n\u27e8\u03bb u, u.mrepr\u27e9\n\n/--\nIn the other direction, we set up a coercion from `string` to `miustr`.\n-/\ndef lchar_to_miustr : (list char) \u2192 miustr\n| [] := []\n| (c::cs) :=\n  let ms := lchar_to_miustr cs in\n  match c with\n  | 'M' := M::ms\n  | 'I' := I::ms\n  | 'U' := U::ms\n  |  _  := []\n  end\n\ninstance string_coe_miustr : has_coe string miustr :=\n\u27e8\u03bb st, lchar_to_miustr st.data \u27e9\n\n/-!\n### Derivability\n-/\n\n/--\nThe inductive type `derivable` has five constructors. The nonrecursive constructor `mk` corresponds\nto Hofstadter's axiom that `\"MI\"` is derivable. Each of the constructors `r1`, `r2`, `r3`, `r4`\ncorresponds to the one of Hofstadter's rules of inference.\n-/\ninductive derivable : miustr \u2192 Prop\n| mk : derivable \"MI\"\n| r1 {x} : derivable (x ++ [I]) \u2192 derivable (x ++ [I, U])\n| r2 {x} : derivable (M :: x) \u2192 derivable (M :: x ++ x)\n| r3 {x y} : derivable (x ++ [I, I, I] ++ y) \u2192 derivable (x ++ U :: y)\n| r4 {x y} : derivable (x ++ [U, U] ++ y) \u2192 derivable (x ++ y)\n\n/-!\n### Rule usage examples\n-/\n\nexample (h : derivable \"UMI\") : derivable \"UMIU\" :=\nbegin\n  change (\"UMIU\" : miustr) with [U,M] ++ [I,U],\n  exact derivable.r1 h, -- Rule 1\nend\n\nexample (h : derivable \"MIIU\") : derivable \"MIIUIIU\" :=\nbegin\n  change (\"MIIUIIU\" : miustr) with M :: [I,I,U] ++ [I,I,U],\n  exact derivable.r2 h, -- Rule 2\nend\n\nexample (h : derivable \"UIUMIIIMMM\") : derivable \"UIUMUMMM\" :=\nbegin\n  change (\"UIUMUMMM\" : miustr) with [U,I,U,M] ++ U :: [M,M,M],\n  exact derivable.r3 h, -- Rule 3\nend\n\nexample (h : derivable \"MIMIMUUIIM\") : derivable \"MIMIMIIM\" :=\nbegin\n  change (\"MIMIMIIM\" : miustr) with [M,I,M,I,M] ++ [I,I,M],\n  exact derivable.r4 h, -- Rule 4\nend\n\n/-!\n### Derivability examples\n-/\n\nprivate lemma MIU_der : derivable \"MIU\":=\nbegin\n  change (\"MIU\" :miustr) with [M] ++ [I,U],\n  apply derivable.r1, -- reduce to deriving \"MI\",\n  constructor, -- which is the base of the inductive construction.\nend\n\nexample : derivable \"MIUIU\" :=\nbegin\n  change (\"MIUIU\" : miustr) with M :: [I,U] ++ [I,U],\n  exact derivable.r2 MIU_der, -- `\"MIUIU\"` can be derived as `\"MIU\"` can.\nend\n\nexample : derivable \"MUI\" :=\nbegin\n  have h\u2082 : derivable \"MII\",\n  { change (\"MII\" : miustr) with M :: [I] ++ [I],\n    exact derivable.r2 derivable.mk, },\n  have h\u2083 : derivable \"MIIII\",\n  { change (\"MIIII\" : miustr) with M :: [I,I] ++ [I,I],\n    exact derivable.r2 h\u2082, },\n  change (\"MUI\" : miustr) with [M] ++ U :: [I],\n  exact derivable.r3 h\u2083, -- We prove our main goal using rule 3\nend\n\nend miu\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/miu_language/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.8652240964782012, "lm_q1q2_score": 0.7470272165224259}}
{"text": "import data.real.basic\n\nexample (a b c : \u211d) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\nexample (a b c : \u211d) : a * (b * c) = b * (a * c) :=\nbegin\n  rw \u2190 mul_assoc a b c,\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\nexample {a b c : \u211d} : a * (b * c) = b * (a * c) := by ring\n\nexample {a b c d : \u211d} (h\u2081 : c = d*a + b) (h\u2082 : b = a*d) : c = 2*a*d :=\nbegin\n  rw h\u2082 at h\u2081,\n  rw mul_comm d a at h\u2081,\n  rw \u2190 two_mul (a * d) at h\u2081,\n  rw \u2190 mul_assoc 2 a d at h\u2081,\n  exact h\u2081,\nend\n\nexample {a b c d : \u211d} (h\u2081 : c = d*a + b) (h\u2082 : b = a*d) : c = 2*a*d :=\nbegin\n  rw [h\u2082, mul_comm d a, \u2190 two_mul, \u2190 mul_assoc] at h\u2081,\n  exact h\u2081,\nend\n\nexample {a b c d : \u211d} (h\u2081 : c = d*a + b) (h\u2082 : b = a*d) : c = 2*a*d :=\nbegin\n  calc \n    c   = d*a + b   : by {rw h\u2081}\n    ... = d*a + a*d : by {rw h\u2082}\n    ... = a*d + a*d : by {rw mul_comm d a}\n    ... = 2*(a*d)   : by {rw two_mul}\n    ... = 2*a*d     : by {rw mul_assoc},\nend\n\nexample {a b c d : \u211d} (h\u2081 : c = d*a + b) (h\u2082 : b = a*d) : c = 2*a*d :=\nbegin\n  calc \n    c   = d*a + b   : by {rw h\u2081}\n    ... = d*a + a*d : by {rw h\u2082}\n    ... = 2*a*d     : by {ring},\nend\n\nexample {a b c d : \u211d} (h\u2081 : c = b*a - d) (h\u2082 : d = a*b) : c = 0 :=\nbegin\n  rw [h\u2082, mul_comm b a, sub_self] at h\u2081,\n  exact h\u2081,\nend\n\nexample {a b c d : \u211d} (h\u2081 : c = b*a - d) (h\u2082 : d = a*b) : c = 0 :=\nbegin\n  calc\n    c   = b*a - d   : by {rw h\u2081}\n    ... = b*a - a*b : by {rw h\u2082}\n    ... = b*a - b*a : by {rw mul_comm}\n    ... = 0         : by {rw sub_self},\nend\n\nexample {a b : \u211d} : (a + b) + a = 2*a + b := by ring\n\n-- \u7701\u7565\uff0e\nexample (a b : \u211d) : (a + b)*(a - b) = a^2 - b^2 := by ring\n\n", "meta": {"author": "SnO2WMaN", "repo": "lean3-tutorial", "sha": "6d276aab5b386329f6d79a94ee09315389fb51fa", "save_path": "github-repos/lean/SnO2WMaN-lean3-tutorial", "path": "github-repos/lean/SnO2WMaN-lean3-tutorial/lean3-tutorial-6d276aab5b386329f6d79a94ee09315389fb51fa/src/01_eqality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.7470272105621513}}
{"text": "/-\nCopyright (c) 2015 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Robert Y. Lewis\n-/\nimport data.nat.basic\nimport tactic.monotonicity.basic\nimport group_theory.group_action.defs\n\n/-!\n# Power operations on monoids and groups\n\nThe power operation on monoids and groups.\nWe separate this from group, because it depends on `\u2115`,\nwhich in turn depends on other parts of algebra.\n\nThis module contains lemmas about `a ^ n` and `n \u2022 a`, where `n : \u2115` or `n : \u2124`.\nFurther lemmas can be found in `algebra.group_power.lemmas`.\n\n## Notation\n\n- `a ^ n` is used as notation for `has_pow.pow a n`; in this file `n : \u2115` or `n : \u2124`.\n- `n \u2022 a` is used as notation for `has_scalar.smul n a`; in this file `n : \u2115` or `n : \u2124`.\n\n## Implementation details\n\nWe adopt the convention that `0^0 = 1`.\n-/\n\nuniverses u v w x y z u\u2081 u\u2082\n\nvariables {M : Type u} {N : Type v} {G : Type w} {H : Type x} {A : Type y} {B : Type z}\n  {R : Type u\u2081} {S : Type u\u2082}\n\n/-!\n### Commutativity\n\nFirst we prove some facts about `semiconj_by` and `commute`. They do not require any theory about\n`pow` and/or `nsmul` and will be useful later in this file.\n-/\n\nsection monoid\nvariables [monoid M] [monoid N] [add_monoid A] [add_monoid B]\n\n@[simp, to_additive one_nsmul]\ntheorem pow_one (a : M) : a^1 = a :=\nby rw [pow_succ, pow_zero, mul_one]\n\n/-- Note that most of the lemmas about powers of two refer to it as `sq`. -/\n@[to_additive two_nsmul]\ntheorem pow_two (a : M) : a^2 = a * a :=\nby rw [pow_succ, pow_one]\n\nalias pow_two \u2190 sq\n\n@[to_additive nsmul_add_comm']\ntheorem pow_mul_comm' (a : M) (n : \u2115) : a^n * a = a * a^n := commute.pow_self a n\n\n@[to_additive add_nsmul]\ntheorem pow_add (a : M) (m n : \u2115) : a^(m + n) = a^m * a^n :=\nby induction n with n ih; [rw [nat.add_zero, pow_zero, mul_one],\n  rw [pow_succ', \u2190 mul_assoc, \u2190 ih, \u2190 pow_succ', nat.add_assoc]]\n\n@[simp] lemma pow_ite (P : Prop) [decidable P] (a : M) (b c : \u2115) :\n  a ^ (if P then b else c) = if P then a ^ b else a ^ c :=\nby split_ifs; refl\n\n@[simp] lemma ite_pow (P : Prop) [decidable P] (a b : M) (c : \u2115) :\n  (if P then a else b) ^ c = if P then a ^ c else b ^ c :=\nby split_ifs; refl\n\n@[simp] lemma pow_boole (P : Prop) [decidable P] (a : M) :\n  a ^ (if P then 1 else 0) = if P then a else 1 :=\nby simp\n\n-- the attributes are intentionally out of order. `smul_zero` proves `nsmul_zero`.\n@[to_additive nsmul_zero, simp] theorem one_pow (n : \u2115) : (1 : M)^n = 1 :=\nby induction n with n ih; [exact pow_zero _, rw [pow_succ, ih, one_mul]]\n\n@[to_additive mul_nsmul']\ntheorem pow_mul (a : M) (m n : \u2115) : a^(m * n) = (a^m)^n :=\nbegin\n  induction n with n ih,\n  { rw [nat.mul_zero, pow_zero, pow_zero] },\n  { rw [nat.mul_succ, pow_add, pow_succ', ih] }\nend\n\n@[to_additive nsmul_left_comm]\nlemma pow_right_comm (a : M) (m n : \u2115) : (a^m)^n = (a^n)^m :=\nby rw [\u2190pow_mul, nat.mul_comm, pow_mul]\n\n@[to_additive mul_nsmul]\ntheorem pow_mul' (a : M) (m n : \u2115) : a^(m * n) = (a^n)^m :=\nby rw [nat.mul_comm, pow_mul]\n\n@[to_additive nsmul_add_sub_nsmul]\ntheorem pow_mul_pow_sub (a : M) {m n : \u2115} (h : m \u2264 n) : a ^ m * a ^ (n - m) = a ^ n :=\nby rw [\u2190pow_add, nat.add_comm, tsub_add_cancel_of_le h]\n\n@[to_additive sub_nsmul_nsmul_add]\ntheorem pow_sub_mul_pow (a : M) {m n : \u2115} (h : m \u2264 n) : a ^ (n - m) * a ^ m = a ^ n :=\nby rw [\u2190pow_add, tsub_add_cancel_of_le h]\n\n@[to_additive bit0_nsmul]\ntheorem pow_bit0 (a : M) (n : \u2115) : a ^ bit0 n = a^n * a^n := pow_add _ _ _\n\n@[to_additive bit1_nsmul]\ntheorem pow_bit1 (a : M) (n : \u2115) : a ^ bit1 n = a^n * a^n * a :=\nby rw [bit1, pow_succ', pow_bit0]\n\n@[to_additive nsmul_add_comm]\ntheorem pow_mul_comm (a : M) (m n : \u2115) : a^m * a^n = a^n * a^m :=\ncommute.pow_pow_self a m n\n\n@[to_additive]\nlemma commute.mul_pow {a b : M} (h : commute a b) (n : \u2115) : (a * b) ^ n = a ^ n * b ^ n :=\nnat.rec_on n (by simp only [pow_zero, one_mul]) $ \u03bb n ihn,\nby simp only [pow_succ, ihn, \u2190 mul_assoc, (h.pow_left n).right_comm]\n\ntheorem neg_pow [ring R] (a : R) (n : \u2115) : (- a) ^ n = (-1) ^ n * a ^ n :=\n(neg_one_mul a) \u25b8 (commute.neg_one_left a).mul_pow n\n\n@[to_additive bit0_nsmul']\ntheorem pow_bit0' (a : M) (n : \u2115) : a ^ bit0 n = (a * a) ^ n :=\nby rw [pow_bit0, (commute.refl a).mul_pow]\n\n@[to_additive bit1_nsmul']\ntheorem pow_bit1' (a : M) (n : \u2115) : a ^ bit1 n = (a * a) ^ n * a :=\nby rw [bit1, pow_succ', pow_bit0']\n\n@[simp] theorem neg_pow_bit0 [ring R] (a : R) (n : \u2115) : (- a) ^ (bit0 n) = a ^ (bit0 n) :=\nby rw [pow_bit0', neg_mul_neg, pow_bit0']\n\n@[simp] theorem neg_pow_bit1 [ring R] (a : R) (n : \u2115) : (- a) ^ (bit1 n) = - a ^ (bit1 n) :=\nby simp only [bit1, pow_succ, neg_pow_bit0, neg_mul_eq_neg_mul]\n\nend monoid\n\n/-!\n### Commutative (additive) monoid\n-/\n\nsection comm_monoid\nvariables [comm_monoid M] [add_comm_monoid A]\n\n@[to_additive nsmul_add]\ntheorem mul_pow (a b : M) (n : \u2115) : (a * b)^n = a^n * b^n :=\n(commute.all a b).mul_pow n\n\n\n/-- The `n`th power map on a commutative monoid for a natural `n`, considered as a morphism of\nmonoids. -/\n@[to_additive nsmul_add_monoid_hom \"Multiplication by a natural `n` on a commutative additive\nmonoid, considered as a morphism of additive monoids.\", simps]\ndef pow_monoid_hom (n : \u2115) : M \u2192* M :=\n{ to_fun := (^ n),\n  map_one' := one_pow _,\n  map_mul' := \u03bb a b, mul_pow a b n }\n\n-- the below line causes the linter to complain :-/\n-- attribute [simps] pow_monoid_hom nsmul_add_monoid_hom\n\nlemma dvd_pow {x y : M} (hxy : x \u2223 y) :\n  \u2200 {n : \u2115} (hn : n \u2260 0), x \u2223 y^n\n| 0       hn := (hn rfl).elim\n| (n + 1) hn := by { rw pow_succ, exact hxy.mul_right _ }\n\nalias dvd_pow \u2190 has_dvd.dvd.pow\n\nlemma dvd_pow_self (a : M) {n : \u2115} (hn : n \u2260 0) : a \u2223 a^n :=\ndvd_rfl.pow hn\n\nend comm_monoid\n\nsection div_inv_monoid\nvariable [div_inv_monoid G]\n\nopen int\n\n@[simp, to_additive one_zsmul]\ntheorem zpow_one (a : G) : a ^ (1:\u2124) = a :=\nby { convert pow_one a using 1, exact zpow_coe_nat a 1 }\n\ntheorem zpow_two (a : G) : a ^ (2 : \u2124) = a * a :=\nby { convert pow_two a using 1, exact zpow_coe_nat a 2 }\n\nend div_inv_monoid\n\nsection group\nvariables [group G] [group H] [add_group A] [add_group B]\n\nopen int\n\nsection nat\n\n@[simp, to_additive neg_nsmul] theorem inv_pow (a : G) (n : \u2115) : (a\u207b\u00b9)^n = (a^n)\u207b\u00b9 :=\nbegin\n  induction n with n ih,\n  { rw [pow_zero, pow_zero, one_inv] },\n  { rw [pow_succ', pow_succ, ih, mul_inv_rev] }\nend\n\n@[to_additive nsmul_sub] -- rename to sub_nsmul?\ntheorem pow_sub (a : G) {m n : \u2115} (h : n \u2264 m) : a^(m - n) = a^m * (a^n)\u207b\u00b9 :=\nhave h1 : m - n + n = m, from tsub_add_cancel_of_le h,\nhave h2 : a^(m - n) * a^n = a^m, by rw [\u2190pow_add, h1],\neq_mul_inv_of_mul_eq h2\n\n@[to_additive nsmul_neg_comm]\ntheorem pow_inv_comm (a : G) (m n : \u2115) : (a\u207b\u00b9)^m * a^n = a^n * (a\u207b\u00b9)^m :=\n(commute.refl a).inv_left.pow_pow m n\n\n@[to_additive sub_nsmul_neg]\ntheorem inv_pow_sub (a : G) {m n : \u2115} (h : n \u2264 m) : a\u207b\u00b9^(m - n) = (a^m)\u207b\u00b9 * a^n :=\nby rw [pow_sub a\u207b\u00b9 h, inv_pow, inv_pow, inv_inv]\n\nend nat\n\n@[simp, to_additive zsmul_zero]\ntheorem one_zpow : \u2200 (n : \u2124), (1 : G) ^ n = 1\n| (n : \u2115) := by rw [zpow_coe_nat, one_pow]\n| -[1+ n] := by rw [zpow_neg_succ_of_nat, one_pow, one_inv]\n\n@[simp, to_additive neg_zsmul]\ntheorem zpow_neg (a : G) : \u2200 (n : \u2124), a ^ -n = (a ^ n)\u207b\u00b9\n| (n+1:\u2115) := div_inv_monoid.zpow_neg' _ _\n| 0       := by { change a ^ (0 : \u2124) = (a ^ (0 : \u2124))\u207b\u00b9, simp }\n| -[1+ n] := by { rw [zpow_neg_succ_of_nat, inv_inv, \u2190 zpow_coe_nat], refl }\n\n@[to_additive neg_one_zsmul_add] lemma mul_zpow_neg_one (a b : G) :\n  (a*b)^(-(1:\u2124)) = b^(-(1:\u2124))*a^(-(1:\u2124)) :=\nby simp only [mul_inv_rev, zpow_one, zpow_neg]\n\n@[to_additive neg_one_zsmul]\ntheorem zpow_neg_one (x : G) : x ^ (-1:\u2124) = x\u207b\u00b9 :=\nby { rw [\u2190 congr_arg has_inv.inv (pow_one x), zpow_neg, \u2190 zpow_coe_nat], refl }\n\n@[to_additive zsmul_neg]\ntheorem inv_zpow (a : G) : \u2200n:\u2124, a\u207b\u00b9 ^ n = (a ^ n)\u207b\u00b9\n| (n : \u2115) := by rw [zpow_coe_nat, zpow_coe_nat, inv_pow]\n| -[1+ n] := by rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, inv_pow]\n\n@[to_additive add_commute.zsmul_add]\ntheorem commute.mul_zpow {a b : G} (h : commute a b) : \u2200 n : \u2124, (a * b) ^ n = a ^ n * b ^ n\n| (n : \u2115) := by simp [zpow_coe_nat, h.mul_pow n]\n| -[1+n]  := by simp [h.mul_pow, (h.pow_pow n.succ n.succ).inv_inv.symm.eq]\n\nend group\n\nsection comm_group\nvariables [comm_group G] [add_comm_group A]\n\n@[to_additive zsmul_add]\ntheorem mul_zpow (a b : G) (n : \u2124) : (a * b)^n = a^n * b^n := (commute.all a b).mul_zpow n\n\n@[to_additive zsmul_sub]\ntheorem div_zpow (a b : G) (n : \u2124) : (a / b) ^ n = a ^ n / b ^ n :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, mul_zpow, inv_zpow]\n\n/-- The `n`th power map (`n` an integer) on a commutative group, considered as a group\nhomomorphism. -/\n@[to_additive \"Multiplication by an integer `n` on a commutative additive group, considered as an\nadditive group homomorphism.\", simps]\ndef zpow_group_hom (n : \u2124) : G \u2192* G :=\n{ to_fun := (^ n),\n  map_one' := one_zpow n,\n  map_mul' := \u03bb a b, mul_zpow a b n }\n\nend comm_group\n\nlemma zero_pow [monoid_with_zero R] : \u2200 {n : \u2115}, 0 < n \u2192 (0 : R) ^ n = 0\n| (n+1) _ := by rw [pow_succ, zero_mul]\n\nlemma zero_pow_eq [monoid_with_zero R] (n : \u2115) : (0 : R)^n = if n = 0 then 1 else 0 :=\nbegin\n  split_ifs with h,\n  { rw [h, pow_zero], },\n  { rw [zero_pow (nat.pos_of_ne_zero h)] },\nend\n\nlemma pow_eq_zero_of_le [monoid_with_zero M] {x : M} {n m : \u2115}\n  (hn : n \u2264 m) (hx : x^n = 0) : x^m = 0 :=\nby rw [\u2190 tsub_add_cancel_of_le hn, pow_add, hx, mul_zero]\n\nnamespace ring_hom\n\nvariables [semiring R] [semiring S]\n\n@[simp] lemma map_pow (f : R \u2192+* S) (a) :\n  \u2200 n : \u2115, f (a ^ n) = (f a) ^ n :=\nf.to_monoid_hom.map_pow a\n\nend ring_hom\n\nsection\nvariables (R)\n\ntheorem neg_one_pow_eq_or [ring R] : \u2200 n : \u2115, (-1 : R)^n = 1 \u2228 (-1 : R)^n = -1\n| 0     := or.inl (pow_zero _)\n| (n+1) := (neg_one_pow_eq_or n).swap.imp\n  (\u03bb h, by rw [pow_succ, h, neg_one_mul, neg_neg])\n  (\u03bb h, by rw [pow_succ, h, mul_one])\n\nend\n\n@[simp]\nlemma neg_one_pow_mul_eq_zero_iff [ring R] {n : \u2115} {r : R} : (-1)^n * r = 0 \u2194 r = 0 :=\nby rcases neg_one_pow_eq_or R n; simp [h]\n\n@[simp]\nlemma mul_neg_one_pow_eq_zero_iff [ring R] {n : \u2115} {r : R} : r * (-1)^n = 0 \u2194 r = 0 :=\nby rcases neg_one_pow_eq_or R n; simp [h]\n\nlemma pow_dvd_pow [monoid R] (a : R) {m n : \u2115} (h : m \u2264 n) :\n  a ^ m \u2223 a ^ n := \u27e8a ^ (n - m), by rw [\u2190 pow_add, nat.add_comm, tsub_add_cancel_of_le h]\u27e9\n\ntheorem pow_dvd_pow_of_dvd [comm_monoid R] {a b : R} (h : a \u2223 b) : \u2200 n : \u2115, a ^ n \u2223 b ^ n\n| 0     := by rw [pow_zero, pow_zero]\n| (n+1) := by { rw [pow_succ, pow_succ], exact mul_dvd_mul h (pow_dvd_pow_of_dvd n) }\n\nlemma sq_sub_sq {R : Type*} [comm_ring R] (a b : R) :\n  a ^ 2 - b ^ 2 = (a + b) * (a - b) :=\nby rw [sq, sq, mul_self_sub_mul_self]\n\nalias sq_sub_sq \u2190 pow_two_sub_pow_two\n\nlemma eq_or_eq_neg_of_sq_eq_sq [comm_ring R] [is_domain R] (a b : R) (h : a ^ 2 = b ^ 2) :\n  a = b \u2228 a = -b :=\nby rwa [\u2190 add_eq_zero_iff_eq_neg, \u2190 sub_eq_zero, or_comm, \u2190 mul_eq_zero,\n        \u2190 sq_sub_sq a b, sub_eq_zero]\n\ntheorem pow_eq_zero [monoid_with_zero R] [no_zero_divisors R] {x : R} {n : \u2115} (H : x^n = 0) :\n  x = 0 :=\nbegin\n  induction n with n ih,\n  { rw pow_zero at H,\n    rw [\u2190 mul_one x, H, mul_zero] },\n  { rw pow_succ at H,\n    exact or.cases_on (mul_eq_zero.1 H) id ih }\nend\n\n@[simp] lemma pow_eq_zero_iff [monoid_with_zero R] [no_zero_divisors R]\n  {a : R} {n : \u2115} (hn : 0 < n) :\n  a ^ n = 0 \u2194 a = 0 :=\nbegin\n  refine \u27e8pow_eq_zero, _\u27e9,\n  rintros rfl,\n  exact zero_pow hn,\nend\n\nlemma pow_ne_zero_iff [monoid_with_zero R] [no_zero_divisors R] {a : R} {n : \u2115} (hn : 0 < n) :\n  a ^ n \u2260 0 \u2194 a \u2260 0 :=\nby rwa [not_iff_not, pow_eq_zero_iff]\n\n@[field_simps] theorem pow_ne_zero [monoid_with_zero R] [no_zero_divisors R]\n  {a : R} (n : \u2115) (h : a \u2260 0) : a ^ n \u2260 0 :=\nmt pow_eq_zero h\n\nsection semiring\n\nvariables [semiring R]\n\nlemma min_pow_dvd_add {n m : \u2115} {a b c : R} (ha : c ^ n \u2223 a) (hb : c ^ m \u2223 b) :\n  c ^ (min n m) \u2223 a + b :=\nbegin\n  replace ha := (pow_dvd_pow c (min_le_left n m)).trans ha,\n  replace hb := (pow_dvd_pow c (min_le_right n m)).trans hb,\n  exact dvd_add ha hb\nend\n\nend semiring\n\nsection comm_semiring\n\nvariables [comm_semiring R]\n\nlemma add_sq (a b : R) : (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2 :=\nby simp only [sq, add_mul_self_eq]\n\nalias add_sq \u2190 add_pow_two\n\nend comm_semiring\n\n@[simp] lemma neg_sq {\u03b1} [ring \u03b1] (z : \u03b1) : (-z)^2 = z^2 :=\nby simp [sq]\n\nalias neg_sq \u2190 neg_pow_two\n\nlemma sub_sq {R} [comm_ring R] (a b : R) : (a - b) ^ 2 = a ^ 2 - 2 * a * b + b ^ 2 :=\nby rw [sub_eq_add_neg, add_sq, neg_sq, mul_neg_eq_neg_mul_symm, \u2190 sub_eq_add_neg]\n\nalias sub_sq \u2190 sub_pow_two\n\nlemma of_add_nsmul [add_monoid A] (x : A) (n : \u2115) :\n  multiplicative.of_add (n \u2022 x) = (multiplicative.of_add x)^n := rfl\n\nlemma of_add_zsmul [add_group A] (x : A) (n : \u2124) :\n  multiplicative.of_add (n \u2022 x) = (multiplicative.of_add x)^n := rfl\n\nlemma of_mul_pow {A : Type*} [monoid A] (x : A) (n : \u2115) :\n  additive.of_mul (x ^ n) = n \u2022 (additive.of_mul x) := rfl\n\nlemma of_mul_zpow [group G] (x : G) (n : \u2124) : additive.of_mul (x ^ n) = n \u2022 additive.of_mul x :=\nrfl\n\n@[simp] lemma semiconj_by.zpow_right [group G] {a x y : G} (h : semiconj_by a x y) :\n  \u2200 m : \u2124, semiconj_by a (x^m) (y^m)\n| (n : \u2115) := by simp [zpow_coe_nat, h.pow_right n]\n| -[1+n] := by simp [(h.pow_right n.succ).inv_right]\n\nnamespace commute\n\nvariables [group G] {a b : G}\n\n@[simp] lemma zpow_right (h : commute a b) (m : \u2124) : commute a (b^m) :=\nh.zpow_right m\n\n@[simp] lemma zpow_left (h : commute a b) (m : \u2124) : commute (a^m) b :=\n(h.symm.zpow_right m).symm\n\nlemma zpow_zpow (h : commute a b) (m n : \u2124) : commute (a^m) (b^n) := (h.zpow_left m).zpow_right n\n\nvariables (a) (m n : \u2124)\n\n@[simp] theorem self_zpow : commute a (a ^ n) := (commute.refl a).zpow_right n\n@[simp] theorem zpow_self : commute (a ^ n) a := (commute.refl a).zpow_left n\n@[simp] theorem zpow_zpow_self : commute (a ^ m) (a ^ n) := (commute.refl a).zpow_zpow m n\n\nend commute\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/group_power/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7469987369874171}}
{"text": "import group_theory.quotient_group\nimport group_theory.subgroup.basic\n\nvariables {G : Type*} [group G]\n\ndef subgroup_generated_by (S : set G) : subgroup G := \n\u2a05 (H : subgroup G) (hH : S \u2286 H), H\n\ninclude G\ndef foo : \u2115 \u2192 \u2115 := \u03bb a, a\n\nnamespace subgroup_gen\n\ninductive carrier (S : set G) : set G \n| of (s : G) (hs : s \u2208 S) : carrier s\n| one : carrier 1\n| mul {x y : G} : carrier x \u2192 carrier y \u2192 carrier (x * y)\n| inv {x : G} : carrier x \u2192 carrier x\u207b\u00b9\n\nend subgroup_gen\n\nopen subgroup_gen\n\ndef subgroup_gen (S : set G) : subgroup G := \n{ carrier := carrier S,\n  mul_mem' := \u03bb a b ha hb, carrier.mul ha hb,\n  one_mem' := carrier.one,\n  inv_mem' := \u03bb x hx, carrier.inv hx }\n\nexample (S : set G) : subgroup_generated_by S = subgroup_gen S :=\nbegin\n  apply le_antisymm,\n  { intros x hx, unfold subgroup_generated_by at hx,\n    simp_rw subgroup.mem_infi at hx,\n    apply hx,\n    intros s hs,\n    apply carrier.of,\n    exact hs },\n  { intros x hx, unfold subgroup_generated_by, \n    simp_rw subgroup.mem_infi, \n    intros H hH,\n    induction hx,\n    case carrier.of : s hs { apply hH, exact hs },\n    case carrier.one { exact H.one_mem },\n    case carrier.mul : a b h1 h2 hh1 hh2 { apply H.mul_mem, exact hh1, exact hh2 },\n    case carrier.inv : a _ ha { apply H.inv_mem, exact ha } }\nend\n\n/-!\nQUOTIENTS\n-/\n\nvariable (R : G \u2192 G \u2192 Prop)\n\n/-!\n\nI want to construct the smallest relation `S : G \u2192 G \u2192 Prop` \nwhich satisfies the following properties:\n1. It should be implied by `R`, meaning if `R a b` then `S a b` should also hold true.\n2. `S` is an equivalence relation.\n3. `G/S` is a group where the product has the form `[a] * [b] = [a * b]` and inversion\n  has the form `[a]\u207b\u00b9 = [a\u207b\u00b9]`.\n-/\n\ninductive congr_rel (R : G \u2192 G \u2192 Prop) : G \u2192 G \u2192 Prop\n| of (x y : G) (h : R x y) : congr_rel x y\n| refl (x : G) : congr_rel x x\n| symm (x y : G) : congr_rel x y \u2192 congr_rel y x\n| trans (x y z : G) : congr_rel x y \u2192 congr_rel y z \u2192 congr_rel x z\n| inv (x y : G) : congr_rel x y \u2192 congr_rel x\u207b\u00b9 y\u207b\u00b9 \n| mul (x x' y y' : G) : congr_rel x x' \u2192 congr_rel y y' \u2192 congr_rel (x * y) (x' * y')\n\ndef congr_setoid (R : G \u2192 G \u2192 Prop) : setoid G := \n{ r := congr_rel R,\n  iseqv := begin\n    refine \u27e8_,_,_\u27e9,\n    { apply congr_rel.refl, },\n    { apply congr_rel.symm },\n    { apply congr_rel.trans },\n  end }\n\ndef quotient_group (R : G \u2192 G \u2192 Prop) := quotient (congr_setoid R)\n\ninstance : group (quotient_group R) :=\n{ mul := \u03bb a b, quotient.lift_on\u2082' a b (\u03bb x y, quotient.mk' $ x * y) begin\n    intros a\u2081 a\u2082 b\u2081 b\u2082 h1 h2,\n    dsimp,\n    apply quotient.sound',\n    apply congr_rel.mul,\n    exact h1,\n    exact h2,\n  end,\n  mul_assoc := begin\n    rintros \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n    apply quotient.sound',\n    rw mul_assoc,\n    apply setoid.refl',\n  end,\n  one := quotient.mk' 1,\n  one_mul := begin\n    rintros \u27e8a\u27e9,\n    apply quotient.sound',\n    rw one_mul,\n    apply setoid.refl',\n  end,\n  mul_one := begin\n    rintros \u27e8a\u27e9,\n    apply quotient.sound',\n    rw mul_one,\n    apply setoid.refl',\n  end,\n  inv := \u03bb x, quotient.lift_on' x (\u03bb g, quotient.mk' g\u207b\u00b9) begin\n    intros a b h,\n    dsimp,\n    apply quotient.sound',\n    apply congr_rel.inv,\n    exact h,\n  end,\n  mul_left_inv := begin\n    rintros \u27e8a\u27e9,\n    apply quotient.sound',\n    rw mul_left_inv,\n    apply setoid.refl',\n  end }\n\ndef \u03c0 : G \u2192* quotient_group R := \n{ to_fun := quotient.mk',\n  map_one' := rfl,\n  map_mul' := \u03bb a b, rfl }\n\ndef desc_to_quotient\n  {H : Type*} [group H] \n  (f : G \u2192* H)\n  (hf : \u2200 a b : G, R a b \u2192 f a = f b) :\n  quotient_group R \u2192* H :=\n{ to_fun := \u03bb x, quotient.lift_on' x f begin\n    intros a b h,\n    induction h,\n    case congr_rel.of : a b h { apply hf, assumption },\n    case congr_rel.refl { refl },\n    case congr_rel.symm { symmetry, assumption },\n    case congr_rel.trans { cc },\n    case congr_rel.inv : a b h hh { simp_rw [f.map_inv, hh], },\n    case congr_rel.mul : a a' b b' h hh h1 h2 { simp_rw [f.map_mul, h1, h2] }\n  end,\n  map_one' := f.map_one,\n  map_mul' := begin\n    rintros \u27e8a\u27e9 \u27e8b\u27e9,\n    apply f.map_mul,\n  end }\n\ntheorem universal_property_of_the_quotient_by_a_relation \n  {H : Type*} [group H] \n  (f : G \u2192* H)\n  (hf : \u2200 a b : G, R a b \u2192 f a = f b) :\n  ((desc_to_quotient R f hf).comp (\u03c0 R) = f) \u2227\n  (\u2200 (g : quotient_group R \u2192* H) (hg : g.comp (\u03c0 R) = f), g = desc_to_quotient R f hf) := \nbegin\n  split,\n  { ext, refl, },\n  { intros g hg,\n    ext \u27e8t\u27e9,\n    apply_fun (\u03bb e, e t) at hg,\n    exact hg }\nend", "meta": {"author": "adamtopaz", "repo": "Math328-lean-stuff", "sha": "f96b6bc90c92be65ca51a0cd832ef9f9d56483ed", "save_path": "github-repos/lean/adamtopaz-Math328-lean-stuff", "path": "github-repos/lean/adamtopaz-Math328-lean-stuff/Math328-lean-stuff-f96b6bc90c92be65ca51a0cd832ef9f9d56483ed/src/2022_11_01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7469986170063474}}
{"text": "import fibonacci_world.divides_mul -- hide\n/-\n## Divisibility of a sum\n\nIn the quest for proving an interesting result about Fibonacci numbers\nit will be useful to have the following lemma, that allows to deduce\nthe divibility of a sum from the divisibility of the summands.\n-/\n\n/- Lemma :\nIf $k$ divides $n$ and $m$, then $k$ divides $m + n$.\n-/\nlemma divides_add {k n m : \u2115} (hn : k \u2223 n) (hm : k \u2223 m) : k \u2223 m + n :=\nbegin\n  cases hn with n1 hn1,\n  cases hm with m1 hm1,\n  use n1 + m1,\n  rw hn1,\n  rw hm1,\n  ring,\n\n\n\n  \nend\n\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/fibonacci_world/divides.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7469986086662328}}
{"text": "import .love01_definitions_and_statements_demo\n\n\n/-! # LoVe Demo 3: Forward Proofs\n\nWhen developing a proof, often it makes sense to work __forward__: to start with\nwhat we already know and proceed step by step towards our goal. Structured\nproofs are a style that supports this reasoning. -/\n\n\nset_option pp.beta true\n\nnamespace LoVe\n\n\n/-! ## Structured Constructs\n\nStructured proofs are syntactic sugar sprinkled on top of Lean's\n__proof terms__.\n\nThe simplest kind of structured proof is the name of a lemma, possibly with\narguments. -/\n\nlemma add_comm_zero_left (n : \u2115) :\n  0 + n = n + 0 :=\nbegin\n  apply add_comm 0 n\nend \n\nlemma add_comm_zero_left\u2082 (n : \u2115) :\n  0 + n = n + 0 :=\nby exact add_comm 0 n\n\n/-! `fix` and `assume` move `\u2200`-quantified variables and assumptions from the\ngoal into the local context. They can be seen as structured versions of the\n`intros` tactic.\n\n`show` repeats the goal to prove. It is useful as documentation or to rephrase\nthe goal (up to computation). -/\n\nlemma fst_of_two_props :\n  \u2200a b : Prop, a \u2192 b \u2192 a :=\nfix a b : Prop,\nassume ha : a,\nassume hb : b,\nshow a, from\n  ha\n\nlemma fst_of_two_props\u2082 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nshow a, from\n  begin\n    exact ha\n  end\n\nlemma fst_of_two_props\u2083 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nha\n\n/-! `have` proves an intermediate lemma, which can refer to the local\ncontext. -/\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nhave hb : b :=\n  hab ha,\nhave hc : c :=\n  hbc hb,\nshow c, from\n  hc\n\nlemma prop_comp\u2082 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nshow c, from\n  hbc (hab ha)\n\n\n/-! ## Forward Reasoning about Connectives and Quantifiers -/\n\nlemma and_swap (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nassume hab : a \u2227 b,\nhave ha : a :=\n  and.elim_left hab,\nhave hb : b :=\n  and.elim_right hab,\nshow b \u2227 a, from\n  and.intro hb ha\n\nlemma or_swap (a b : Prop) :\n  a \u2228 b \u2192 b \u2228 a :=\nassume hab : a \u2228 b,\nshow b \u2228 a, from\n  or.elim hab\n    (assume ha : a,\n     show b \u2228 a, from\n       or.intro_right b ha)\n    (assume hb : b,\n     show b \u2228 a, from\n       or.intro_left a hb)\n\ndef double (n : \u2115) : \u2115 :=\nn + n\n\nlemma nat_exists_double_iden :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0\n  (show double 0 = 0, from\n     by refl)\n\nlemma nat_exists_double_iden\u2082 :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0 (by refl)\n\nlemma modus_ponens (a b : Prop) :\n  (a \u2192 b) \u2192 a \u2192 b :=\n\u03bb hab : a \u2192 b,\n\u03bb ha : a,\nshow b, from\n  hab ha\n\nlemma not_not_intro (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\n\u03bb ha : a,\n\u03bb hna : \u00ac a,\nshow false, from\n  begin\n    apply hna ha,\n  end\n\nlemma forall.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2200x, x = t \u2192 p x) \u2194 p t :=\niff.intro\n  (assume hall : \u2200x, x = t \u2192 p x,\n   show p t, from\n     begin\n       apply hall t,\n       refl\n     end)\n  (assume hp : p t,\n   fix x,\n   assume heq : x = t,\n   show p x, from\n     begin\n       rewrite heq,\n       exact hp\n     end)\n\nlemma beast_666 (beast : \u2115) :\n  (\u2200n, n = 666 \u2192 beast \u2265 n) \u2194 beast \u2265 666 :=\nforall.one_point _ _\n\n#print beast_666\n\nlemma exists.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2203x : \u03b1, x = t \u2227 p x) \u2194 p t :=\niff.intro\n  (assume hex : \u2203x, x = t \u2227 p x,\n   show p t, from\n     exists.elim hex\n       (fix x,\n        assume hand : x = t \u2227 p x,\n        show p t, from\n          by cc))\n  (assume hp : p t,\n   show \u2203x : \u03b1, x = t \u2227 p x, from\n     exists.intro t\n       (show t = t \u2227 p t, from\n          by cc))\n\n\n/-! ## Calculational Proofs\n\nIn informal mathematics, we often use transitive chains of equalities,\ninequalities, or equivalences (e.g., `a \u2265 b \u2265 c`). In Lean, such calculational\nproofs are supported by `calc`.\n\nSyntax:\n\n    calc      _term\u2080_\n        _op\u2081_ _term\u2081_ :\n      _proof\u2081_\n    ... _op\u2082_ _term\u2082_ :\n      _proof\u2082_\n     \u22ee\n    ... _opN_ _termN_ :\n      _proofN_ -/\n\nlemma two_mul_example (m n : \u2115) :\n  2 * m + n = m + n + m :=\ncalc  2 * m + n\n    = (m + m) + n :\n  by rewrite two_mul\n... = m + n + m :\n  by cc\n\n/-! `calc` saves some repetition, some `have` labels, and some transitive\nreasoning: -/\n\nlemma two_mul_example\u2082 (m n : \u2115) :\n  2 * m + n = m + n + m :=\nhave h\u2081 : 2 * m + n = (m + m) + n :=\n  by rewrite two_mul,\nhave h\u2082 : (m + m) + n = m + n + m :=\n  by cc,\nshow _, from\n  eq.trans h\u2081 h\u2082\n\n\n/-! ## Forward Tactics\n\nThe `have` and `let` structured proof commands are also available as a tactic.\nEven in tactic mode, it can be useful to state intermediate results and\ndefinitions in a forward fashion.\n\nObserve that the syntax for the tactic `let` is slightly different than for the\nstructured proof command `let`, with `,` instead of `in`. -/\n\nlemma prop_comp\u2083 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  have hb : b :=\n    hab ha,\n  let c' := c,\n  have hc : c' :=\n    hbc hb,\n  exact hc\nend\n\n\n/-! ## Dependent Types\n\nDependent types are the defining feature of the dependent type theory family of\nlogics.\n\nConsider a function `pick` that take a number `n : \u2115` and that returns a number\nbetween 0 and `n`. Conceptually, `pick` has a dependent type, namely\n\n    `(n : \u2115) \u2192 {i : \u2115 // i \u2264 n}`\n\nWe can think of this type as a `\u2115`-indexed family, where each member's type may\ndepend on the index:\n\n    `pick n : {i : \u2115 // n \u2264 x}`\n\nBut a type may also depend on another type, e.g., `list` (or `\u03bb\u03b1, list \u03b1`) and\n`\u03bb\u03b1, \u03b1 \u2192 \u03b1`.\n\nA term may depend on a type, e.g., `\u03bb\u03b1, \u03bbx : \u03b1, x` (a polymorphic identity\nfunction).\n\nOf course, a term may also depend on a term.\n\nUnless otherwise specified, a __dependent type__ means a type depending on a\nterm. This is what we mean when we say that simple type theory does not support\ndependent types.\n\nIn summary, there are four cases for `\u03bbx, t` in the calculus of inductive\nconstructions (cf. Barendregt's \u03bb-cube):\n\nBody (`t`) |              | Argument (`x`) | Description\n---------- | ------------ | -------------- | ------------------------------\nA term     | depending on | a term         | Simply typed \u03bb-expression\nA type     | depending on | a term         | Dependent type (stricto senso)\nA term     | depending on | a type         | Polymorphic term\nA type     | depending on | a type         | Type constructor\n\nRevised typing rules:\n\n    C \u22a2 t : (x : \u03c3) \u2192 \u03c4[x]    C \u22a2 u : \u03c3\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    C \u22a2 t u : \u03c4[u]\n\n    C, x : \u03c3 \u22a2 t : \u03c4[x]\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    C \u22a2 (\u03bbx : \u03c3, t) : (x : \u03c3) \u2192 \u03c4[x]\n\nThese two rules degenerate to `App` and `Lam` if `x` does not occur in `\u03c4[x]`\n\nExample of `App'`:\n\n    \u22a2 pick : (x : \u2115) \u2192 {y : \u2115 // y \u2264 x}    \u22a2 5 : \u2115\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    \u22a2 pick 5 : {y : \u2115 // y \u2264 5}\n\nExample of `Lam'`:\n\n    \u03b1 : Type, x : \u03b1 \u22a2 x : \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam or Lam'\n    \u03b1 : Type \u22a2 (\u03bbx : \u03b1, x) : \u03b1 \u2192 \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    \u22a2 (\u03bb\u03b1 : Type, \u03bbx : \u03b1, x) : (\u03b1 : Type) \u2192 \u03b1 \u2192 \u03b1\n\nRegrettably, the intuitive syntax `(x : \u03c3) \u2192 \u03c4` is not available in Lean.\nInstead, we must write `\u2200x : \u03c3, \u03c4` to specify a dependent type.\n\nAliases:\n\n    `\u03c3 \u2192 \u03c4` := `\u2200_ : \u03c3, \u03c4`\n    `\u03a0`     := `\u2200`\n\n\n## The Curry\u2013Howard Correspondence\n\n`\u2192` is used both as the implication symbol and as the type constructor of\nfunctions. Similarly, `\u2200` is used both as a quantifier and in dependent types.\n\nThe two pairs of concepts not only look the same, they are the same, by the PAT\nprinciple:\n\n* PAT = propositions as types;\n* PAT = proofs as terms.\n\nThis is also called the Curry\u2013Howard(\u2013De Bruijn) correspondence.\n\nTypes:\n\n* `\u03c3 \u2192 \u03c4` is the type of total functions from `\u03c3` to `\u03c4`;\n* `\u2200x : \u03c3, \u03c4[x]` is the dependent function type from `x : \u03c3` to `\u03c4[x]`.\n\nPropositions:\n\n* `P \u2192 Q` can be read as \"`P` implies `Q`\", or as the type of functions mapping\n  proofs of `P` to proofs of `Q`.\n* `\u2200x : \u03c3, Q[x]` can be read as \"for all `x`, `Q[x]`\", or as the type of\n  functions mapping values `x` of type `\u03c3` to proofs of `Q[x]`.\n\nTerms:\n\n* A constant is a term.\n* A variable is a term.\n* `t u` is the application of function `t` to value `u`.\n* `\u03bbx, t[x]` is a function mapping `x` to `t[x]`.\n\nProofs:\n\n* A lemma or hypothesis name is a proof.\n* `H t`, which instantiates the leading parameter or quantifier of proof `H`'\n  statement with term `t`, is a proof.\n* `H G`, which discharges the leading assumption of `H`'s statement with\n  proof `G`, is a proof.\n* `\u03bbh : P, H[h]` is a proof of `P \u2192 Q`, assuming `H[h]` is a proof of `Q`\n  for `h : P`.\n* `\u03bbx : \u03c3, H[x]` is a proof of `\u2200x : \u03c3, Q[x]`, assuming `H[x]` is a proof of\n  `Q[x]` for `x : \u03c3`. -/\n\nlemma and_swap\u2083 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\n\u03bb hab : a \u2227 b, and.intro (and.elim_right hab) (and.elim_left hab)\n\nlemma and_swap\u2084 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intro hab,\n  apply and.intro,\n  apply and.elim_right,\n  exact hab,\n  apply and.elim_left,\n  exact hab\nend\n\n#check \u03bb (Q R S : Type*) (v : R \u2192 S) (u : Q \u2192 R) (x : Q),\n        v (u x)\n/-! Tactical proofs are reduced to proof terms. -/\n\n#print and_swap\u2083\n#print and_swap\u2084\n\n\n/-! ## Induction by Pattern Matching\n\nBy the Curry\u2013Howard correspondence, a proof by induction is the same as a\nrecursively specified proof term. Thus, as alternative to the `induction`\ntactic, induction can also be done by pattern matching:\n\n * the induction hypothesis is then available under the name of the lemma we are\n   proving;\n\n * well-foundedness of the argument is often proved automatically. -/\n\n#check reverse\n\nlemma reverse_append {\u03b1 : Type} :\n  \u2200xs ys : list \u03b1, reverse (xs ++ ys) = reverse ys ++ reverse xs\n| []        ys := by simp [reverse]\n| (x :: xs) ys := by simp [reverse, reverse_append xs]\n\nlemma reverse_append\u2082 {\u03b1 : Type} (xs ys : list \u03b1) :\n  reverse (xs ++ ys) = reverse ys ++ reverse xs :=\nbegin\n  induction xs,\n  {\n    simp [reverse],\n  },\n  {\n    simp [reverse, xs_ih],\n  }\nend\n\nlemma reverse_reverse {\u03b1 : Type} :\n  \u2200xs : list \u03b1, reverse (reverse xs) = xs\n| []        := by refl\n| (x :: xs) :=\n  by simp [reverse, reverse_append, reverse_reverse xs]\n\nend LoVe\n", "meta": {"author": "yizhou7", "repo": "learning-lean", "sha": "91fb366c624df6e56e19555b2e482ce767cd8224", "save_path": "github-repos/lean/yizhou7-learning-lean", "path": "github-repos/lean/yizhou7-learning-lean/learning-lean-91fb366c624df6e56e19555b2e482ce767cd8224/my_project/src/love03_forward_proofs_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7469844450151236}}
{"text": "-- 4.1. The Universal Quantifier\n-- Prove (\u2200 x : \u03b1, p x \u2227 q x) \u2192 \u2200 y : \u03b1, p y\nnamespace one\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) -- This defines \u03b1 and 'p' and 'q' for the whole file\n\nexample : (\u2200 x : \u03b1, p x \u2227 q x) \u2192 \u2200 y : \u03b1, p y  :=\nassume h : \u2200 x : \u03b1, p x \u2227 q x,\nassume y : \u03b1,\nshow p y, from (h y).left\n\nexample : (\u2200 x : \u03b1, p x \u2227 q x) \u2192 \u2200 y : \u03b1, p y  :=\nassume h : \u2200 x : \u03b1, p x \u2227 q x,\nassume y : \u03b1,\nshow p y, from and.left (h y)\n\n-- My example, using variable x in both the hypothesis and in the conclusion,\n-- plus explicity set the quantifier in the 'show' section.\nexample : (\u2200 x : \u03b1, p x \u2227 q x) \u2192 \u2200 y : \u03b1, p y  :=\nassume h : \u2200 x : \u03b1, p x \u2227 q x,\nshow \u2200 y, p y, from\n  (assume y: \u03b1, show p y, from (h y).left)\n\n\n-- Remember that expressions which differ up to renaming of bound variables are considered to\n-- be equivalent. So, for example, we could have used the same variable, x, in both the hypothesis\n-- and conclusion, and instantiated it by a different variable, z, in the proof:\nexample : (\u2200 x : \u03b1, p x \u2227 q x) \u2192 \u2200 x : \u03b1, p x  :=\nassume h : \u2200 x : \u03b1, p x \u2227 q x,\nassume z : \u03b1,\nshow p z, from and.left (h z)\nend one\n\n-- Express the fact that a relation, r, is transitive:\nnamespace two\nvariable (\u03b1 : Type)\nvariables (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\nvariable  trans_r : \u2200 x y z, r x y \u2192 r y z \u2192 r x z\n\nvariables a b c : \u03b1\nvariables (hab : r a b) (hbc : r b c)\n\n#check trans_r    -- \u2200 (x y z : \u03b1), r x y \u2192 r y z \u2192 r x z\n#check trans_r a b c\n#check trans_r a b c hab\n#check trans_r a b c hab hbc\nend two\n\nnamespace three\nuniverse u\nvariables (\u03b1 : Type u) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\nvariable  trans_r : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z\n\nvariables (a b c : \u03b1)\nvariables (hab : r a b) (hbc : r b c)\n\n#check trans_r\n#check trans_r hab\n#check trans_r hab hbc\nend three\n\nnamespace four\nvariables (\u03b1 : Type) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\nvariable refl_r : \u2200 x, r x x\nvariable symm_r : \u2200 {x y}, r x y \u2192 r y x\nvariable trans_r : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z\n\nexample (a b c d : \u03b1) (hab : r a b) (hcb : r c b) (hcd : r c d) :\n  r a d :=\ntrans_r (trans_r hab (symm_r hcb)) hcd\nend four\n\n\n-- 4.2. Equality\nnamespace equality_1\nuniverse u\nvariables (\u03b1 : Type u) (a b c d : \u03b1)\nvariables (hab : a = b) (hcb : c = b) (hcd : c = d)\n\nexample : a = d :=\neq.trans (eq.trans hab (eq.symm hcb)) hcd\n\n-- We can also use the projection notation:\nexample : a = d := (hab.trans hcb.symm).trans hcd\n\nend equality_1\n\nnamespace equality_2\nuniverse u\nvariables (\u03b1 \u03b2 : Type u)\n\nexample (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (\u03bb x, f x) a = f a := eq.refl _\nexample (a : \u03b1) (b : \u03b1) : (a, b).1 = a := eq.refl _\nexample : 2 + 3 = 5 := eq.refl _\n\n-- This feature of the framework is so important that the library defines a notation rfl\nexample (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (\u03bb x, f x) a = f a := rfl\nexample (a : \u03b1) (b : \u03b1) : (a, b).1 = a := rfl\nexample : 2 + 3 = 5 := rfl\n\nend equality_2\n\nnamespace equality_3\n-- Equality is much more than an equivalence relation, however. It has the important property that\n-- every assertion respects the equivalence, in the sense that we can substitute equal expressions\n-- without changing the truth value. That is, given h1 : a = b and h2 : p a, we can construct\n-- a proof for p b using substitution: eq.subst h1 h2.\nuniverse u\n\nexample (\u03b1 : Type u) (a b : \u03b1) (p : \u03b1 \u2192 Prop)\n  (h1 : a = b) (h2 : p a) : p b :=\neq.subst h1 h2\n\nexample (\u03b1 : Type u) (a b : \u03b1) (p : \u03b1 \u2192 Prop)\n  (h1 : a = b) (h2 : p a) : p b :=\nh1 \u25b8 h2\n\nend equality_3\n\nnamespace equality_4\nvariable \u03b1 : Type\nvariables a b : \u03b1\nvariables f g : \u03b1 \u2192 \u2115\nvariable h\u2081 : a = b\nvariable h\u2082 : f = g\n\nexample : f a = f b := congr_arg f h\u2081\nexample : f a = g a := congr_fun h\u2082 a\nexample : f a = g b := congr h\u2082 h\u2081\nend equality_4\n\n-- 4.4. The Existential Quantifier\nexample : \u2203 x : \u2115, x > 0 :=\nhave h : 1 > 0, from nat.zero_lt_succ 0,\nexists.intro 1 h\n\nexample : \u2203 x : \u2115, x > 0 :=\nhave h : 4 > 0, from nat.zero_lt_succ 3,\nexists.intro 4 h\n\nexample (x : \u2115) (h : x > 0) : \u2203 y, y < x :=\nexists.intro 0 h\n\nexample (x y z : \u2115) (hxy : x < y) (hyz : y < z) :\n  \u2203 w, x < w \u2227 w < z :=\nexists.intro y (and.intro hxy hyz)\n\n#check @exists.intro\n\n-- We can use the anonymous constructor notation \u27e8t, h\u27e9 for exists.intro t h, when the\n-- type is clear from the context.\nexample : \u2203 x : \u2115, x > 0 :=\n\u27e81, nat.zero_lt_succ 0\u27e9\n\nexample (x : \u2115) (h : x > 0) : \u2203 y, y < x :=\n\u27e80, h\u27e9\n\nexample (x y z : \u2115) (hxy : x < y) (hyz : y < z) :\n  \u2203 w, x < w \u2227 w < z :=\n\u27e8y, hxy, hyz\u27e9\n\n\n-- Note that exists.intro has implicit arguments: Lean has to infer the predicate p : \u03b1 \u2192 Prop\n-- in the conclusion \u2203 x, p x.\n-- For example, if we have have hg : g 0 0 = 0 and write exists.intro 0 hg, there are many\n-- possible values for the predicate p, corresponding to the theorems\n-- \u2203 x, g x x = x, \u2203 x, g x x = 0, \u2203 x, g x 0 = x, etc.\n-- Lean uses the context to infer which one is appropriate.\nvariable g : \u2115 \u2192 \u2115 \u2192 \u2115\nvariable hg : g 0 0 = 0\n\ntheorem gex1 : \u2203 x, g x x = x := \u27e80, hg\u27e9\ntheorem gex2 : \u2203 x, g x 0 = x := \u27e80, hg\u27e9\ntheorem gex3 : \u2203 x, g 0 0 = x := \u27e80, hg\u27e9\ntheorem gex4 : \u2203 x, g x x = 0 := \u27e80, hg\u27e9\n\ntheorem gex5 : \u2203 x, g 0 x = x := \u27e80, hg\u27e9\ntheorem gex6 : \u2203 x, g x 0 = 0 := \u27e80, hg\u27e9\ntheorem gex7 : \u2203 x, g 0 x = 0 := \u27e80, hg\u27e9\n\nset_option pp.implicit true  -- display implicit arguments\n#print gex1\n#print gex2\n#print gex3\n#print gex4\n\n\n-- The existential elimination rule, exists.elim, performs the opposite operation.\n-- It allows us to prove a proposition q from \u2203 x : \u03b1, p x, by showing that q follows from p w for an arbitrary value w.\n-- Roughly speaking, since we know there is an x satisfying p x, we can give it a name, say, w.\n-- If q does not mention w, then showing that q follows from p w is tantamount to showing the q follows from the existence of any such x. Here is an example: \nnamespace five\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nexists.elim h\n  (assume w,\n    assume hw : p w \u2227 q w,\n    show \u2203 x, q x \u2227 p x, from \u27e8w, \u27e8hw.right, hw.left\u27e9\u27e9)\nend five\n\n-- Lean provides a more convenient way to eliminate from an existential quantifier with the match statement:\nnamespace six\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nmatch h with \u27e8w, hw\u27e9 :=\n  \u27e8w, hw.right, hw.left\u27e9\nend\n\n-- We can annotate the types used in the match for greater clarity:\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nmatch h with \u27e8(w : \u03b1), (hw : p w \u2227 q w)\u27e9 :=\n  \u27e8w, hw.right, hw.left\u27e9\nend\n\n-- We can even use the match statement to decompose the conjunction at the same time:\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nmatch h with \u27e8w, hpw, hqw\u27e9 :=\n  \u27e8w, hqw, hpw\u27e9\nend\n\n-- Lean also provides a pattern-matching let expression:\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nlet \u27e8w, hpw, hqw\u27e9 := h in \u27e8w, hqw, hpw\u27e9\n\n-- This is essentially just alternative notation for the match construct above. Lean will even allow\n-- us to use an implicit match in the assume statement:\nexample : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, q x \u2227 p x :=\nassume \u27e8w, hpw, hqw\u27e9, \u27e8w, hqw, hpw\u27e9\n\nend six\n\n-- Prove \u00ac \u2200 x, \u00ac p x \u2192 \u2203 x, p x\nnamespace ApEp\nvariables (\u03b1 : Type) (p : \u03b1 \u2192 Prop)\n\nexample (h : \u00ac \u2200 x, \u00ac p x) : \u2203 x, p x :=\nclassical.by_contradiction\n  (assume h1 : \u00ac \u2203 x, p x,\n    have h2 : \u2200 x, \u00ac p x, from\n      assume x,\n      assume h3 : p x,\n      have h4 : \u2203 x, p x, from  \u27e8x, h3\u27e9,\n      show false, from h1 h4,\n    show false, from h h2)\n\n-- Same example using Exists.intro\nexample (h : \u00ac \u2200 x, \u00ac p x) : \u2203 x, p x :=\nclassical.by_contradiction\n  (assume h1 : \u00ac \u2203 x, p x,\n    have h2 : \u2200 x, \u00ac p x, from\n      assume x,\n      assume h3 : p x,\n      have h4 : \u2203 x, p x, from exists.intro x h3,\n      show false, from h1 h4,\n    show false, from h h2)\nend ApEp\n\n-- Existential quantifier. Exercises:\nnamespace exercises\nopen classical\n\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable a : \u03b1\nvariable r : Prop\n\n\nexample : (\u2203 x : \u03b1, r) \u2192 r :=\nassume h : (\u2203 x : \u03b1, r),\nexists.elim h\n(assume (a : \u03b1) (hr : r), show r, from hr)\n\n\nexample : r \u2192 (\u2203 x : \u03b1, r) :=\nassume h : r,\nexists.intro a h\n\n\nexample : (\u2203 x, p x) \u2227 r \u2194 (\u2203 x, p x \u2227 r) :=\niff.intro\n(\n assume h : ((\u2203 x, p x) \u2227 r), show (\u2203 x, p x \u2227 r), from\n exists.elim (and.left h)\n  (assume a (hr : p a), show (\u2203 x, p x \u2227 r),\n  from exists.intro a (and.intro hr (and.right h)))\n)\n(\n assume h : (\u2203 x, p x \u2227 r), show (\u2203 x, p x) \u2227 r, from\n and.intro\n (exists.elim h (assume a (hr : p a \u2227 r), show (\u2203 x, p x), from exists.intro a hr.left))\n (exists.elim h (assume a (hr : p a \u2227 r), show r, from and.right hr))\n)\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\niff.intro\n(assume h : (\u2203 x, p x \u2228 q x), show (\u2203 x, p x) \u2228 (\u2203 x, q x), from\n  exists.elim h (assume a (hr : p a \u2228 q a), show (\u2203 x, p x) \u2228 (\u2203 x, q x),\n  from or.elim hr\n    (assume hpa : p a, show (\u2203 x, p x) \u2228 (\u2203 x, q x), from or.inl (exists.intro a hpa))\n    (assume hpq : q a, show (\u2203 x, p x) \u2228 (\u2203 x, q x), from or.inr (exists.intro a hpq)))\n)\n(assume h : (\u2203 x, p x) \u2228 (\u2203 x, q x), show (\u2203 x, p x \u2228 q x), from\n  or.elim h\n  (assume hpq : (\u2203 x, p x), show (\u2203 x, p x \u2228 q x), from\n    exists.elim hpq\n      (assume a (hpa : p a), show (\u2203 x, p x \u2228 q x), from exists.intro a (or.inl hpa))\n  )\n  (assume hpq : (\u2203 x, q x), show (\u2203 x, p x \u2228 q x), from\n    exists.elim hpq\n      (assume a (hpa : q a), show (\u2203 x, p x \u2228 q x), from exists.intro a (or.inr hpa))\n  )\n)\n\nend exercises\n\n\n-- 4.5. More on the Proof Language\nvariable f : \u2115 \u2192 \u2115\nvariable h : \u2200 x : \u2115, f x \u2264 f (x + 1)\n\nexample : f 0 \u2265 f 1 \u2192 f 0 = f 1 :=\nassume : f 0 \u2265 f 1,\nshow f 0 = f 1, from le_antisymm (h 0) this\n\n\n-- 4.6. Exercises\n-- Prove these equivalences:\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2192 (\u2200 x, p x) \u2227 (\u2200 x, q x)  :=\nassume h : (\u2200 x, p x \u2227 q x),\nshow (\u2200 x, p x) \u2227 (\u2200 x, q x), from\nand.intro\n  (assume x : \u03b1, show p x, from (h x).left)\n  (assume x : \u03b1, show q x, from (h x).right)\n\n\nexample :  (\u2200 x, p x) \u2227 (\u2200 x, q x) \u2192 (\u2200 x, p x \u2227 q x) :=\nassume h : (\u2200 x, p x) \u2227 (\u2200 x, q x),\nassume x : \u03b1,\nshow p x \u2227 q x, from\nand.intro (h.left x) (h.right x)\n\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\niff.intro\n(assume h : (\u2200 x, p x \u2227 q x),\n  show (\u2200 x, p x) \u2227 (\u2200 x, q x), from\n    and.intro\n    (assume x : \u03b1, show p x, from (h x).left)\n    (assume x : \u03b1, show q x, from (h x).right))\n(assume h : (\u2200 x, p x) \u2227 (\u2200 x, q x),\n  show (\u2200 x, p x \u2227 q x), from\n  (assume x : \u03b1,\n   show p x \u2227 q x, from and.intro (h.left x) (h.right x)))\n\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\nassume h : (\u2200 x, p x \u2192 q x),\nassume i : (\u2200 x, p x),\nshow (\u2200 x, q x), from\n(assume x : \u03b1, show q x, from (h x)(i x))\n\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\nassume h : (\u2200 x, p x \u2192 q x),\nassume i : (\u2200 x, p x),\nshow (\u2200 x, q x), from\n(assume a : \u03b1, show q a, from (h a)(i a))\n\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\nassume h : (\u2200 x, p x) \u2228 (\u2200 x, q x),\nshow \u2200 x, p x \u2228 q x, from\nassume a : \u03b1, show p a \u2228 q a, from\nor.elim h\n(assume h1 : (\u2200 x, p x), show p a \u2228 q a, from or.inl (h1 a))\n(assume h2 : (\u2200 x, q x), show p a \u2228 q a, from or.inr (h2 a))\n", "meta": {"author": "JoseBalado", "repo": "lean-notes", "sha": "0b579f83988cc844ac1ff0592d885061959a852e", "save_path": "github-repos/lean/JoseBalado-lean-notes", "path": "github-repos/lean/JoseBalado-lean-notes/lean-notes-0b579f83988cc844ac1ff0592d885061959a852e/theorem_proving_in_lean/4.Quantifiers_and_Equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7469844360126396}}
{"text": "import tactic \nopen classical\n\nsection\n\nparameters {A : Type} {R : A \u2192 A \u2192 Prop}\n\n/- Defininig Complete Relations -/\ndef complete (R : A \u2192 A \u2192 Prop) : Prop :=\n\u2200 x y, R x y \u2228 R y x\n\n/- Defininig Incomplete Relations -/\ndef incomplete (R : A \u2192 A \u2192 Prop) : Prop :=\n\u2203 x y, \u00ac (R x y \u2228 R y x)\n\n/- Defininig S the Strict Preference Relation-/\ndef S (a b : A) : Prop := R a b \u2227 \u00ac R b a\n\n/- Defininig the Indifference Relation-/\ndef I (a b : A) : Prop := R a b \u2227 R b a\n\n\n/-Prop 1.9 https://assets.press.princeton.edu/chapters/s9890.pdf-/\n\n/- 1.9 a -/ \ntheorem propa (compR : complete R) (x : A)(y : A): S x y \u2194 \u00ac R y x :=\nbegin\nsplit, \n{intro Sxy, cases Sxy, assumption,},\n{intro nRyx, rw [S], have RxyOrRyx : R x y \u2228 R y x, from compR x y, tauto,}\n\nend\n\n\n/- 1.9 b -/\ntheorem propb (compR : complete R) (trnsR : transitive R)(x : A)(y : A): S x y \u2192 \u00ac S y x :=\nbegin\nintros Sxy nSyx, rw [S] at *, tauto,\nend\n\n/- 1.9 d -/\ntheorem propd (compR : complete R) (trnsR : transitive R)(x : A): I x x :=\nbegin\nhave Rxx : R x x \u2228 R x x, from compR x x, rw [I], tauto,\nend\n\n/- 1.9 e -/\ntheorem prope (compR : complete R) (trnsR : transitive R)(x : A)(y : A): I x y \u2192 I y x :=\nbegin\nintro Ixy, cases Ixy, rw [I], tauto,\nend\n\n/- 1.9 f -/\ntheorem propf (compR : complete R) (trnsR : transitive R)(x : A)(y : A)(z : A): \n(I x y \u2227 I y z) \u2192 I x z :=\nbegin\nintro IxyandIyz, cases IxyandIyz, rename [IxyandIyz_left Ixy, IxyandIyz_right Iyz], cases Ixy, cases Iyz, rw [I], tauto,\nend\n\n/- 1.9 g -/\ntheorem propg (compR : complete R) (trnsR : transitive R)(x : A)(y : A)(z : A): (S x y \u2227 R y z) \u2192 S x z :=\nbegin\nintro SxyandRyz, cases SxyandRyz, rename [SxyandRyz_left Sxy, SxyandRyz_right Ryz], cases Sxy, rw [S], split,\n{rename [Sxy_left Rxy, Sxy_right nRyx], exact trnsR Rxy Ryz,},\n{rename[Sxy_left Rxy, Sxy_right nRyx], by_contra Rzx, have Ryx : R y x, from trnsR Ryz Rzx, tauto,}\nend\n\n\n/- 1.9 h -/\ntheorem proph (compR : complete R) (trnsR : transitive R)(x : A)(y : A)(z : A): (S x y \u2227 S y z) \u2192 S x z :=\nbegin\nintro SxyandSyx, cases SxyandSyx, rename[SxyandSyx_left Sxy, SxyandSyx_right Syz], rw [S] at Syz, cases Syz, \nrename[Syz_left Ryz, Syz_right nRzy], exact propg compR trnsR x y z (and.intro Sxy Ryz), \nend\n\n/- 1.9 c -/\ntheorem propc (compR : complete R) (trnsR : transitive R)(x : A)(y : A)(z : A): S x y \u2192 (S z y \u2228 S x z) :=\nbegin\nintro Sxy, have h1 : R y z \u2228 R z y, from compR y z, have h2 : R x z \u2228 R z x, from compR x z, cases Sxy, cases h1, cases h2,\n{rename [Sxy_left Rxy, Sxy_right nRyx, h1 Ryz, h2 Rxz],\nhave Sxy : S x y, from and.intro Rxy nRyx,\nhave Sxz : S x z, from propg compR trnsR x y z (and.intro Sxy Ryz),\napply or.inr,\nassumption,\n},\n{rename [Sxy_left Rxy, Sxy_right nRyx, h1 Ryz, h2 Rzx],\nhave Sxy : S x y, from and.intro Rxy nRyx,\nhave Sxz : S x z, from propg compR trnsR x y z (and.intro Sxy Ryz),\napply or.inr,\nassumption,\n},\n{\ncases h2,\n{rename [Sxy_left Rxy, Sxy_right nRyx, h1 Rzy, h2 Rxz],\nhave Sxy : S x y, from and.intro Rxy nRyx,\nby_contra' h,\ncases h,\nrename [h_left nSzy, h_right nSxz],\nrw S at nSzy,\npush_neg at nSzy,\nrename nSzy h,\nhave Ryz : R y z, from h Rzy,\nhave Sxz : S x z, from propg compR trnsR x y z (and.intro Sxy Ryz),\ntrivial,\n},\n{rename [Sxy_left Rxy, Sxy_right nRyx, h1 Rzy, h2 Rzx],\nhave Sxy : S x y, from and.intro Rxy nRyx,\nby_contra' h,\ncases h,\nrename [h_left nSzy, h_right nSxz],\nrw S at nSzy,\npush_neg at nSzy,\nrename nSzy h,\nhave Ryz : R y z, from h Rzy,\nhave Sxz : S x z, from propg compR trnsR x y z (and.intro Sxy Ryz),\ntrivial,\n},\n}\n\nend\n\n\nend\n", "meta": {"author": "gregleo-econ", "repo": "formal-microeconoimcs", "sha": "9a1ec0934c806ccf279f1febcbb2f45c9d5f65b6", "save_path": "github-repos/lean/gregleo-econ-formal-microeconoimcs", "path": "github-repos/lean/gregleo-econ-formal-microeconoimcs/formal-microeconoimcs-9a1ec0934c806ccf279f1febcbb2f45c9d5f65b6/src/Kreps_Prop_1_9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7469541226378699}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Kenny Lau\n-/\n\nimport algebra.geom_sum\nimport ring_theory.ideal.quotient\n\n/-!\n# Basic results in number theory\n\nThis file should contain basic results in number theory. So far, it only contains the essential\nlemma in the construction of the ring of Witt vectors.\n\n## Main statement\n\n`dvd_sub_pow_of_dvd_sub` proves that for elements `a` and `b` in a commutative ring `R` and for\nall natural numbers `p` and `k` if `p` divides `a-b` in `R`, then `p ^ (k + 1)` divides\n`a ^ (p ^ k) - b ^ (p ^ k)`.\n-/\n\nsection\n\nopen ideal ideal.quotient\n\nlemma dvd_sub_pow_of_dvd_sub {R : Type*} [comm_ring R] {p : \u2115}\n  {a b : R} (h : (p : R) \u2223 a - b) (k : \u2115) :\n  (p^(k+1) : R) \u2223 a^(p^k) - b^(p^k) :=\nbegin\n  induction k with k ih,\n  { rwa [pow_one, pow_zero, pow_one, pow_one] },\n  rw [pow_succ' p k, pow_mul, pow_mul, \u2190 geom_sum\u2082_mul, pow_succ],\n  refine mul_dvd_mul _ ih,\n  let I : ideal R := span {p},\n  let f : R \u2192+* R \u29f8 I := mk I,\n  have hp : (p : R \u29f8 I) = 0,\n  { rw [\u2190 map_nat_cast f, eq_zero_iff_mem, mem_span_singleton] },\n  rw [\u2190 mem_span_singleton, \u2190 ideal.quotient.eq] at h,\n  rw [\u2190 mem_span_singleton, \u2190 eq_zero_iff_mem, ring_hom.map_geom_sum\u2082,\n      ring_hom.map_pow, ring_hom.map_pow, h, geom_sum\u2082_self, hp, zero_mul],\nend\n\nend\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/number_theory/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7469541128687517}}
{"text": "variable n : \u2115\n\nlemma zero_add1 : 0 + n = n :=\nbegin\n    induction n with d hd,\n    rw add_zero,\n\n    rw nat.add_succ,\n    rw hd,\nend", "meta": {"author": "Samyak-Surti", "repo": "LeanCode", "sha": "944eac3e5f43e2614ed246083b97fbdf24181d83", "save_path": "github-repos/lean/Samyak-Surti-LeanCode", "path": "github-repos/lean/Samyak-Surti-LeanCode/LeanCode-944eac3e5f43e2614ed246083b97fbdf24181d83/nat_num_game/src/Addition_World/add_wrld1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9643214491222695, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7469473765018969}}
{"text": "import measure_theory.lebesgue_measure\nimport measure_theory.measurable_space\n\nopen measure_theory\n\n-- https://en.wikipedia.org/wiki/Probability_space\n\nclass probability_space (\u03b1 : Type*) extends measure_space \u03b1 :=\n(is_probability_measure:  probability_measure volume)\n\n-- https://en.wikipedia.org/wiki/Random_variable#Definition\n\ndef random_variable (\u03b1 \u03b2: Type*) (PS: probability_space \u03b1) (MS: measurable_space \u03b2):=\n  @measurable \u03b1 \u03b2 PS.to_measure_space.to_measurable_space MS\n\n--https://en.wikipedia.org/wiki/Stochastic_process#Stochastic_process\n\ndef stochastic_process (\u03b1 \u03b2 T: Type*) (PS: probability_space \u03b1) (MS: measurable_space \u03b2) (X: T \u2192 \u03b1 \u2192 \u03b2) (t: T) := \n  random_variable \u03b1 \u03b2 PS MS (X t)\n\n-- https://en.wikipedia.org/wiki/Stochastic_process#Index_set\n\ndef index_set (\u03b1 \u03b2 T: Type*) (X: T \u2192 \u03b1 \u2192 \u03b2) := T\n\n-- https://en.wikipedia.org/wiki/Stochastic_process#State_space\n\ndef state_space (\u03b1 \u03b2 T: Type*) (X: T \u2192 \u03b1 \u2192 \u03b2) := \u03b2\n\n-- https://en.wikipedia.org/wiki/Stochastic_process#Sample_function\n\ndef sample_function (\u03b1 \u03b2 T: Type*) (X: T \u2192 \u03b1 \u2192 \u03b2) := \u03bb (\u03c9: \u03b1), \u03bb (t: T), X t \u03c9 \n\n-- https://en.wikipedia.org/wiki/Stochastic_process#Law\ndef law (\u03b1 \u03b2 T: Type*) \n        (PS: probability_space \u03b1) \n        (MS: measurable_space \u03b2) \n        (X: T \u2192 \u03b1 \u2192 \u03b2) \n        (t: T) \n        (SP: stochastic_process \u03b1 \u03b2 T PS MS X t)\n        (HM: has_mem \u03b2 \u03b2)\n        (Y: set \u03b2):=\n  PS.volume.to_outer_measure.measure_of {\u03c9 : \u03b1 | \u2203 y:\u03b2, X t \u03c9 \u2208 y}\n\n-- Steinhaus space\n\nnoncomputable instance {\u03b1} {p : \u03b1 \u2192 Prop} [m : measure_space \u03b1] : measure_space (subtype p) :=\n{ volume := measure.comap (coe : _ \u2192 \u03b1) volume }\n\ntheorem subtype.volume_apply {\u03b1} {p : \u03b1 \u2192 Prop} [measure_space \u03b1]\n  (hp : is_measurable {x | p x}) {s : set (subtype p)} (hs : is_measurable s) :\n  volume s = volume ((coe : _ \u2192 \u03b1) '' s) :=\nmeasure.comap_apply _ subtype.coe_injective (\u03bb _, is_measurable.subtype_image hp) _ hs\n\ninstance steinhaus_measure : probability_measure (volume : measure (set.Icc (0 : \u211d) 1)) :=\n{ measure_univ := begin\n    refine (subtype.volume_apply is_measurable_Icc is_measurable.univ).trans _,\n    suffices : volume (set.Icc (0 : \u211d) 1) = 1, {simpa},\n    rw [real.volume_Icc], simp\n  end \n}\n\nnoncomputable instance steinhaus_space : probability_space (set.Icc (0 : \u211d) 1) := \n{ is_probability_measure := steinhaus_measure }", "meta": {"author": "catskillsresearch", "repo": "grundbegriffe", "sha": "e8aa4fe66308d9e6e85d5bdedd9d981af99f17f7", "save_path": "github-repos/lean/catskillsresearch-grundbegriffe", "path": "github-repos/lean/catskillsresearch-grundbegriffe/grundbegriffe-e8aa4fe66308d9e6e85d5bdedd9d981af99f17f7/src/stochastic_process.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7469401396219519}}
{"text": "/-\nThe cases tactic applies the elimination\nrules to a term, appropriate to it's type.\n\nFor example, if h is a proof of P \u2227 Q, the\ncases tactic will \"eliminate\" h to a proof\nof p and proof of q; and that will be the\nonly case. Why? Because there's only one\nway that the proof, h, could have been \nconstructed, namely by the application of\nand.intro to two arguments, a proof of P\nand a proof of Q. \n-/\n\nvariables P Q R : Prop\n\n/-\nYou *could* apply the elimination rules\n\"manually.\"\n-/\nexample : P \u2227 Q \u2192 P :=\nbegin\nassume h,\nlet p : P := and.elim_left h,\nexact p,\nend\n\n/-\nOr you could just use the cases tactic\n-/\nexample : P \u2227 Q \u2192 P :=\nbegin\nassume h,\ncases h,\nexact h_left,\nend\n\n/-\nIf you don't specify names for the \nresults of the elimination, Lean will\nmake up names for you. It's better to\nprovide more meaningful names. It can\nmake a big difference in being able \nto think about what you've got. \n-/\nexample : P \u2227 Q \u2192 P :=\nbegin\nassume h,\ncases h with p q, -- *with p q*\nexact p,\nend\n\n/-\nNow suppose you've got a proof of a type\nfor which there are two introduction rules.\nThere are now *two ways* that an assumed\nproof could have been constructed. What you\ngenerally want to know is that no matter\nhow the proof was constructive, the goal\nremains true. To prove that, you need to\nconsider each *case*. \n\nConsider a proof of P \u2228 Q. There are two\nintroduction rules: or.intro_left Q p and\nor.intro_right P q. Note that if Lean is\nable to infer the P and Q arguments, you\ncan use the simpler or.inl p and or.inr q\nconstructors. \n-/\n\nexample : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\nassume h,\ncases h with p q,\n/-\nWhat remain are two subgoals, one\nfor each case. If the proof, h, of \nP \u2228 Q was constructed using or.inl,\nthen you need to show that given P,\nR follows (basically P \u2192 R); and if\nP \u2228 Q was proven using or.inr q, you\nneed to complete the proof of Q \u2192 R.\n(Given the assumed proof of Q, show\nthat R is true by provind a proof of\nit.)\n-/\nend\n\n/-\nIf we want to reason \"classically\"\nrather than constructively, then we\ncan use the classical.em rule to\nconvert and proposition, P, into a\nproof of P \u2228 \u00acP, *on which we can\nthen do case analysis*.\n-/\n\n#check @classical.em P\n\nexample : \u00ac\u00acP \u2192 P :=\nbegin\nassume nnp,\ncases (classical.em P) with p np, -- here!\n-- make sure you can finish this proof!\nexact p,\ncontradiction,\nend\n\n/-\nHow is a proof of P \u2194 Q constructed? It's by\napplying iff.intro to a proof of P \u2192 Q and to\na proof of Q \u2192 P. That's the only way to do\nit. When we apply case analysis to a proof of\nP \u2194 Q we should thus expect one case, where\niff.intro was applied to two assumed argments\nof the right types. That's just what we get.\n-/\n\nexample : (P \u2194 Q) \u2192 (Q \u2192 P) :=\nbegin\nassume h,\ncases h with pq qp,\nassumption, -- uses proof in context\nend\n\n\n/-\nAs an aside, we can even do case analysis\non data values. The bool type, for example,\nhas two values.\n-/\n\ndef my_not : bool \u2192 bool :=\nbegin\nassume b,\ncases b,\nexact tt, -- in case b = tt, return ff\nexact ff, -- in case b = ff, return tt\nend\n\n#eval (my_not tt)\n#eval (my_not ff)\n\n-- Whoa: we defined a function by cases! \n\n/-\nFinally, case analysis works only on data\nvalues, including proof values. It can't\nbe applied to functions. In the following\nexample, we assume we have a function that\ntakes a nat and returns a nat, along with\na nat. We'll first show how you can \"prove\nthis type\" by giving a particular function\nvalue of this type; then we'll get to the\nmain point, which is to show that you will\nget an error if you try to do case analysis\non the function argument. \n-/\n\ndef app_func : (\u2115 \u2192 \u2115) \u2192 \u2115 \u2192 \u2115 :=\nbegin\nassume f n,\nexact (f n),\nend\n\n#eval\n\n/-\nWhat you have just proved is that if\nf takes and returns a nat, and n is\na nat, then f applied to n is a nat.\nWhat happens if we try \"cases f\"? It's\na no-go.\n-/\n\n\nexample : (\u2115 \u2192 \u2115) \u2192 \u2115 \u2192 \u2115 :=\nbegin\nassume f n,\ncases f,\n/-\nError: \"cases tactic failed, it is not \napplicable to the given hypothesis.\" You\ncan't do case analysis on a function, or\non a proof of an implication or universal\ngeneralization, because these things are\nbasically functions.\n-/\n\nexample : (P \u2192 Q) \u2192 P \u2192 Q :=\nbegin\nassume i p,\nexact (i p),\nend\n\nexample : (P \u2192 Q) \u2192 P \u2192 Q :=\nbegin\nassume i p,\ncases i,      -- Nope\nend\n\n/-\nSimilarly you can't do case analysis\non a data *type* (such as bool) or on\na proposition (a logical *type*). These\nthings aren't data values, so \"cases\"\ndoes not work. Independent of Lean, \nyou can't do \"case analysis\" on things\nof these kind in predicate logic.  \n-/\n", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/99_Lean_Prover/03_Proof_Tactics/03_elim_via_cases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.746898896887628}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Ines Wright\n-/\n\nimport group_theory.general_commutator\nimport group_theory.quotient_group\n\n/-!\n\n# Nilpotent groups\n\nAn API for nilpotent groups, that is, groups for which the upper central series\nreaches `\u22a4`.\n\n## Main definitions\n\nRecall that if `H K : subgroup G` then `\u2045H, K\u2046 : subgroup G` is the subgroup of `G` generated\nby the commutators `hkh\u207b\u00b9k\u207b\u00b9`. Recall also Lean's conventions that `\u22a4` denotes the\nsubgroup `G` of `G`, and `\u22a5` denotes the trivial subgroup `{1}`.\n\n* `upper_central_series G : \u2115 \u2192 subgroup G` : the upper central series of a group `G`.\n     This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = \u22a5` and\n     `H (n + 1) / H n` is the centre of `G / H n`.\n* `lower_central_series G : \u2115 \u2192 subgroup G` : the lower central series of a group `G`.\n     This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = \u22a4` and\n     `H (n + 1) = \u2045H n, G\u2046`.\n* `is_nilpotent` : A group G is nilpotent if its upper central series reaches `\u22a4`, or\n    equivalently if its lower central series reaches `\u22a5`.\n* `nilpotency_class` : the length of the upper central series of a nilpotent group.\n* `is_ascending_central_series (H : \u2115 \u2192 subgroup G) : Prop` and\n* `is_descending_central_series (H : \u2115 \u2192 subgroup G) : Prop` : Note that in the literature\n    a \"central series\" for a group is usually defined to be a *finite* sequence of normal subgroups\n    `H 0`, `H 1`, ..., starting at `\u22a4`, finishing at `\u22a5`, and with each `H n / H (n + 1)`\n    central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates\n    on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central\n    series* if it starts at `G` and `\u2045H n, \u22a4\u2046 \u2286 H (n + 1)` for all `n`. Note that this series\n    may not terminate at `\u22a5`, and the `H i` need not be normal. Similarly a sequence is an\n    *ascending central series* if `H 0 = \u22a5` and `\u2045H (n + 1), \u22a4\u2046 \u2286 H n` for all `n`, again with no\n    requirement that the series reaches `\u22a4` or that the `H i` are normal.\n\n## Main theorems\n\n`G` is *defined* to be nilpotent if the upper central series reaches `\u22a4`.\n* `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central\n    series reaches `\u22a4`.\n* `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central\n    series reaches `\u22a5`.\n* `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `\u22a5`.\n\n## Warning\n\nA \"central series\" is usually defined to be a finite sequence of normal subgroups going\nfrom `\u22a5` to `\u22a4` with the property that each subquotient is contained within the centre of\nthe associated quotient of `G`. This means that if `G` is not nilpotent, then\nnone of what we have called `upper_central_series G`, `lower_central_series G` or\nthe sequences satisfying `is_ascending_central_series` or `is_descending_central_series`\nare actually central series. Note that the fact that the upper and lower central series\nare not central series if `G` is not nilpotent is a standard abuse of notation.\n\n-/\n\nopen subgroup\n\nvariables {G : Type*} [group G] (H : subgroup G) [normal H]\n\n/-- If `H` is a normal subgroup of `G`, then the set `{x : G | \u2200 y : G, x*y*x\u207b\u00b9*y\u207b\u00b9 \u2208 H}`\nis a subgroup of `G` (because it is the preimage in `G` of the centre of the\nquotient group `G/H`.)\n-/\ndef upper_central_series_step : subgroup G :=\n{ carrier := {x : G | \u2200 y : G, x * y * x\u207b\u00b9 * y\u207b\u00b9 \u2208 H},\n  one_mem' := \u03bb y, by simp [subgroup.one_mem],\n  mul_mem' := \u03bb a b ha hb y, begin\n    convert subgroup.mul_mem _ (ha (b * y * b\u207b\u00b9)) (hb y) using 1,\n    group,\n  end,\n  inv_mem' := \u03bb x hx y, begin\n    specialize hx y\u207b\u00b9,\n    rw [mul_assoc, inv_inv] at \u22a2 hx,\n    exact subgroup.normal.mem_comm infer_instance hx,\n  end }\n\nlemma mem_upper_central_series_step (x : G) :\n  x \u2208 upper_central_series_step H \u2194 \u2200 y, x * y * x\u207b\u00b9 * y\u207b\u00b9 \u2208 H := iff.rfl\n\nopen quotient_group\n\n/-- The proof that `upper_central_series_step H` is the preimage of the centre of `G/H` under\nthe canonical surjection. -/\nlemma upper_central_series_step_eq_comap_center :\n  upper_central_series_step H = subgroup.comap (mk' H) (center (G \u29f8 H)) :=\nbegin\n  ext,\n  rw [mem_comap, mem_center_iff, forall_coe],\n  apply forall_congr,\n  intro y,\n  change x * y * x\u207b\u00b9 * y\u207b\u00b9 \u2208 H \u2194 ((y * x : G) : G \u29f8 H) = (x * y : G),\n  rw [eq_comm, eq_iff_div_mem, div_eq_mul_inv],\n  congr' 2,\n  group,\nend\n\ninstance : normal (upper_central_series_step H) :=\nbegin\n  rw upper_central_series_step_eq_comap_center,\n  apply_instance,\nend\n\nvariable (G)\n\n/-- An auxiliary type-theoretic definition defining both the upper central series of\na group, and a proof that it is normal, all in one go. -/\ndef upper_central_series_aux : \u2115 \u2192 \u03a3' (H : subgroup G), normal H\n| 0 := \u27e8\u22a5, infer_instance\u27e9\n| (n + 1) := let un := upper_central_series_aux n, un_normal := un.2 in\n   by exactI \u27e8upper_central_series_step un.1, infer_instance\u27e9\n\n/-- `upper_central_series G n` is the `n`th term in the upper central series of `G`. -/\ndef upper_central_series (n : \u2115) : subgroup G := (upper_central_series_aux G n).1\n\ninstance (n : \u2115) : normal (upper_central_series G n) := (upper_central_series_aux G n).2\n\n@[simp] lemma upper_central_series_zero : upper_central_series G 0 = \u22a5 := rfl\n\n/-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such\nthat `\u2045x,G\u2046 \u2286 H n`-/\nlemma mem_upper_central_series_succ_iff (n : \u2115) (x : G) :\n  x \u2208 upper_central_series G (n + 1) \u2194\n  \u2200 y : G, x * y * x\u207b\u00b9 * y\u207b\u00b9 \u2208 upper_central_series G n := iff.rfl\n\n-- is_nilpotent is already defined in the root namespace (for elements of rings).\n/-- A group `G` is nilpotent if its upper central series is eventually `G`. -/\nclass group.is_nilpotent (G : Type*) [group G] : Prop :=\n(nilpotent [] : \u2203 n : \u2115, upper_central_series G n = \u22a4)\n\nopen group\n\nsection classical\n\nopen_locale classical\n\n/-- The nilpotency class of a nilpotent group is the small natural `n` such that\nthe `n`'th term of the upper central series is `G`. -/\nnoncomputable def group.nilpotency_class (G : Type*) [group G] [is_nilpotent G] : \u2115 :=\nnat.find (is_nilpotent.nilpotent G)\n\nend classical\n\nvariable {G}\n\n/-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and\n  `\u2045H (n + 1), G\u2046 \u2286 H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/\ndef is_ascending_central_series (H : \u2115 \u2192 subgroup G) : Prop :=\n  H 0 = \u22a5 \u2227 \u2200 (x : G) (n : \u2115), x \u2208 H (n + 1) \u2192 \u2200 g, x * g * x\u207b\u00b9 * g\u207b\u00b9 \u2208 H n\n\n/-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and\n  `\u2045H n, G\u2046 \u2286 H (n + 1)` for all `n`. Note that we do not requre that `H n = {1}` for some `n`. -/\ndef is_descending_central_series (H : \u2115 \u2192 subgroup G) := H 0 = \u22a4 \u2227\n  \u2200 (x : G) (n : \u2115), x \u2208 H n \u2192 \u2200 g, x * g * x\u207b\u00b9 * g\u207b\u00b9 \u2208 H (n + 1)\n\n/-- Any ascending central series for a group is bounded above by the upper central series. -/\nlemma ascending_central_series_le_upper (H : \u2115 \u2192 subgroup G) (hH : is_ascending_central_series H) :\n  \u2200 n : \u2115, H n \u2264 upper_central_series G n\n| 0 := hH.1.symm \u25b8 le_refl \u22a5\n| (n + 1) := begin\n  specialize ascending_central_series_le_upper n,\n  intros x hx,\n  have := hH.2 x n hx,\n  rw mem_upper_central_series_succ_iff,\n  intro y,\n  apply ascending_central_series_le_upper,\n  apply this,\nend\n\nvariable (G)\n\n/-- The upper central series of a group is an ascending central series. -/\nlemma upper_central_series_is_ascending_central_series :\n  is_ascending_central_series (upper_central_series G) :=\n\u27e8rfl, \u03bb x n h, h\u27e9\n\nlemma upper_central_series_mono : monotone (upper_central_series G) :=\nbegin\n  refine monotone_nat_of_le_succ _,\n  intros n x hx y,\n  rw [mul_assoc, mul_assoc, \u2190 mul_assoc y x\u207b\u00b9 y\u207b\u00b9],\n  exact mul_mem (upper_central_series G n) hx\n    (normal.conj_mem (upper_central_series.subgroup.normal G n) x\u207b\u00b9 (inv_mem _ hx) y),\nend\n\n/-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in\n  finitely many steps. -/\ntheorem nilpotent_iff_finite_ascending_central_series :\n  is_nilpotent G \u2194 \u2203 H : \u2115 \u2192 subgroup G, is_ascending_central_series H \u2227 \u2203 n : \u2115, H n = \u22a4 :=\nbegin\n  split,\n  { intro h,\n    use upper_central_series G,\n    refine \u27e8upper_central_series_is_ascending_central_series G, h.1\u27e9 },\n  { rintro \u27e8H, hH, n, hn\u27e9,\n    use n,\n    have := ascending_central_series_le_upper H hH n,\n    rw hn at this,\n    exact eq_top_iff.mpr this }\nend\n\n/-- A group `G` is nilpotent iff there exists a descending central series which reaches the\n  trivial group in a finite time. -/\ntheorem nilpotent_iff_finite_descending_central_series :\n  is_nilpotent G \u2194 \u2203 H : \u2115 \u2192 subgroup G, is_descending_central_series H \u2227 \u2203 n : \u2115, H n = \u22a5 :=\nbegin\n  rw nilpotent_iff_finite_ascending_central_series,\n  split,\n  { rintro \u27e8H, \u27e8h0, hH\u27e9, n, hn\u27e9,\n    use (\u03bb m, H (n - m)),\n    split,\n    { refine \u27e8hn, \u03bb x m hx g, _\u27e9,\n      dsimp at hx,\n      by_cases hm : n \u2264 m,\n      { have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm,\n        rw [hnm, h0, subgroup.mem_bot] at hx,\n        subst hx,\n        convert subgroup.one_mem _,\n        group },\n      { push_neg at hm,\n        apply hH,\n        convert hx,\n        rw nat.sub_succ,\n        exact nat.succ_pred_eq_of_pos (tsub_pos_of_lt hm) } },\n    { use n,\n      rwa tsub_self } },\n  { rintro \u27e8H, \u27e8h0, hH\u27e9, n, hn\u27e9,\n    use (\u03bb m, H (n - m)),\n    split,\n    { refine \u27e8hn, \u03bb x m hx g, _\u27e9,\n      dsimp only at hx,\n      by_cases hm : n \u2264 m,\n      { have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm,\n        dsimp only,\n        rw [hnm, h0],\n        exact mem_top _ },\n      { push_neg at hm,\n        dsimp only,\n        convert hH x _ hx g,\n        rw nat.sub_succ,\n        exact (nat.succ_pred_eq_of_pos (tsub_pos_of_lt hm)).symm } },\n    { use n,\n      rwa tsub_self } },\nend\n\n/-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined\n  by `H 0` is all of `G` and for `n\u22651`, `H (n + 1) = \u2045H n, G\u2046` -/\ndef lower_central_series (G : Type*) [group G] : \u2115 \u2192 subgroup G\n| 0 := \u22a4\n| (n+1) := \u2045lower_central_series n, \u22a4\u2046\n\nvariable {G}\n\n@[simp] lemma lower_central_series_zero : lower_central_series G 0 = \u22a4 := rfl\n\nlemma mem_lower_central_series_succ_iff (n : \u2115) (q : G) :\n  q \u2208 lower_central_series G (n + 1) \u2194\n  q \u2208 closure {x | \u2203 (p \u2208 lower_central_series G n) (q \u2208 (\u22a4 : subgroup G)), p * q * p\u207b\u00b9 * q\u207b\u00b9 = x}\n:= iff.rfl\n\nlemma lower_central_series_succ (n : \u2115) :\n  lower_central_series G (n + 1) =\n  closure {x | \u2203 (p \u2208 lower_central_series G n) (q \u2208 (\u22a4 : subgroup G)), p * q * p\u207b\u00b9 * q\u207b\u00b9 = x} :=\nrfl\n\ninstance (n : \u2115) : normal (lower_central_series G n) :=\nbegin\n  induction n with d hd,\n  { exact (\u22a4 : subgroup G).normal_of_characteristic },\n  { exactI general_commutator_normal (lower_central_series G d) \u22a4 },\nend\n\nlemma lower_central_series_antitone :\n  antitone (lower_central_series G) :=\nbegin\n  refine antitone_nat_of_succ_le (\u03bb n x hx, _),\n  simp only [mem_lower_central_series_succ_iff, exists_prop, mem_top, exists_true_left, true_and]\n    at hx,\n  refine closure_induction hx _ (subgroup.one_mem _) (@subgroup.mul_mem _ _ _)\n    (@subgroup.inv_mem _ _ _),\n  rintros y \u27e8z, hz, a, ha\u27e9,\n  rw [\u2190 ha, mul_assoc, mul_assoc, \u2190 mul_assoc a z\u207b\u00b9 a\u207b\u00b9],\n  exact mul_mem (lower_central_series G n) hz\n    (normal.conj_mem (lower_central_series.subgroup.normal n) z\u207b\u00b9 (inv_mem _ hz) a),\nend\n\n/-- The lower central series of a group is a descending central series. -/\ntheorem lower_central_series_is_descending_central_series :\n  is_descending_central_series (lower_central_series G) :=\nbegin\n  split, refl,\n  intros x n hxn g,\n  exact general_commutator_containment _ _ hxn (subgroup.mem_top g),\nend\n\n/-- Any descending central series for a group is bounded below by the lower central series. -/\nlemma descending_central_series_ge_lower (H : \u2115 \u2192 subgroup G)\n  (hH : is_descending_central_series H) : \u2200 n : \u2115, lower_central_series G n \u2264 H n\n| 0 := hH.1.symm \u25b8 le_refl \u22a4\n| (n + 1) := begin\n  specialize descending_central_series_ge_lower n,\n  apply (general_commutator_le _ _ _).2,\n  intros x hx q _,\n  exact hH.2 x n (descending_central_series_ge_lower hx) q,\nend\n\n/-- A group is nilpotent if and only if its lower central series eventually reaches\n  the trivial subgroup. -/\ntheorem nilpotent_iff_lower_central_series : is_nilpotent G \u2194 \u2203 n, lower_central_series G n = \u22a5 :=\nbegin\n  rw nilpotent_iff_finite_descending_central_series,\n  split,\n  { rintro \u27e8H, \u27e8h0, hs\u27e9, n, hn\u27e9,\n    use n,\n    have := descending_central_series_ge_lower H \u27e8h0, hs\u27e9 n,\n    rw hn at this,\n    exact eq_bot_iff.mpr this },\n  { intro h,\n    use [lower_central_series G, lower_central_series_is_descending_central_series, h] },\nend\n\nlemma lower_central_series_map_subtype_le (H : subgroup G) (n : \u2115) :\n  (lower_central_series H n).map H.subtype \u2264 lower_central_series G n :=\nbegin\n  induction n with d hd,\n  { simp },\n  { rw [lower_central_series_succ, lower_central_series_succ, monoid_hom.map_closure],\n    apply subgroup.closure_mono,\n    rintros x1 \u27e8x2, \u27e8x3, hx3, x4, hx4, rfl\u27e9, rfl\u27e9,\n    exact \u27e8x3, (hd (mem_map.mpr \u27e8x3, hx3, rfl\u27e9)), x4, by simp\u27e9 }\nend\n\ninstance subgroup.is_nilpotent (H : subgroup G) [hG : is_nilpotent G] :\n  is_nilpotent H :=\nbegin\n  rw nilpotent_iff_lower_central_series at *,\n  rcases hG with \u27e8n, hG\u27e9,\n  use n,\n  have := lower_central_series_map_subtype_le H n,\n  simp only [hG, set_like.le_def, mem_map, forall_apply_eq_imp_iff\u2082, exists_imp_distrib] at this,\n  exact eq_bot_iff.mpr (\u03bb x hx, subtype.ext (this x hx)),\nend\n\n@[priority 100]\ninstance is_nilpotent_of_subsingleton [subsingleton G] : is_nilpotent G :=\nnilpotent_iff_lower_central_series.2 \u27e80, subsingleton.elim \u22a4 \u22a5\u27e9\n\nlemma upper_central_series.map {H : Type*} [group H] {f : G \u2192* H} (h : function.surjective f)\n  (n : \u2115) : subgroup.map f (upper_central_series G n) \u2264 upper_central_series H n :=\nbegin\n  induction n with d hd,\n  { simp },\n  { rintros _ \u27e8x, hx : x \u2208 upper_central_series G d.succ, rfl\u27e9 y',\n    rcases (h y') with \u27e8y, rfl\u27e9,\n    simpa using hd (mem_map_of_mem f (hx y)) }\nend\n\nlemma lower_central_series.map {H : Type*} [group H] (f : G \u2192* H) (n : \u2115) :\n  subgroup.map f (lower_central_series G n) \u2264 lower_central_series H n :=\nbegin\n  induction n with d hd,\n  { simp [nat.nat_zero_eq_zero] },\n  { rintros a \u27e8x, hx : x \u2208 lower_central_series G d.succ, rfl\u27e9,\n    refine closure_induction hx _ (by simp [f.map_one, subgroup.one_mem _])\n      (\u03bb y z hy hz, by simp [monoid_hom.map_mul, subgroup.mul_mem _ hy hz])\n      (\u03bb y hy, by simp [f.map_inv, subgroup.inv_mem _ hy]),\n    rintros a \u27e8y, hy, z, \u27e8-, rfl\u27e9\u27e9,\n    apply mem_closure.mpr,\n    exact \u03bb K hK, hK \u27e8f y, hd (mem_map_of_mem f hy), by simp\u27e9 }\nend\n\nlemma lower_central_series_succ_eq_bot {n : \u2115} (h : lower_central_series G n \u2264 center G) :\n  lower_central_series G (n + 1) = \u22a5 :=\nbegin\n  rw [lower_central_series_succ, closure_eq_bot_iff, set.subset_singleton_iff],\n  rintro x \u27e8y, hy1, z, \u27e8\u27e9, rfl\u27e9,\n  symmetry,\n  rw [eq_mul_inv_iff_mul_eq, eq_mul_inv_iff_mul_eq, one_mul],\n  exact mem_center_iff.mp (h hy1) z,\nend\n\nlemma is_nilpotent_of_ker_le_center {H : Type*} [group H] {f : G \u2192* H}\n  (hf1 : f.ker \u2264 center G) (hH : is_nilpotent H) : is_nilpotent G :=\nbegin\n  rw nilpotent_iff_lower_central_series at *,\n  rcases hH with \u27e8n, hn\u27e9,\n  refine \u27e8n + 1, lower_central_series_succ_eq_bot\n    (le_trans ((map_eq_bot_iff _).mp _) hf1)\u27e9,\n  exact eq_bot_iff.mpr (hn \u25b8 (lower_central_series.map f n)),\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/group_theory/nilpotent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797081106935, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7468875315281042}}
{"text": "import ..lovelib\n\n\n/-! # LoVe Exercise 3: Forward Proofs -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Connectives and Quantifiers\n\n1.1. Supply structured proofs of the following lemmas. -/\n\nlemma I (a : Prop) :\n  a \u2192 a :=\nsorry\n\nlemma K (a b : Prop) :\n  a \u2192 b \u2192 b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 b \u2192 a \u2192 c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a \u2192 a \u2192 a :=\nsorry\n\n/-! Please give a different answer than for `proj_1st`. -/\n\nlemma proj_2nd (a : Prop) :\n  a \u2192 a \u2192 a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 a \u2192 (a \u2192 c) \u2192 b \u2192 c :=\nsorry\n\n/-! 1.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a \u2192 b) \u2192 \u00ac b \u2192 \u00ac a :=\nsorry\n\n/-! 1.3. Supply a structured proof of the distributivity of `\u2200` over `\u2227`. -/\n\nlemma forall_and {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2200x, p x \u2227 q x) \u2194 (\u2200x, p x) \u2227 (\u2200x, q x) :=\nsorry\n\n/-! 1.4 (**optional**). Reuse, if possible, the lemma `forall_and` from question\n1.3 to prove the following instance of the lemma. -/\n\nlemma forall_and_inst {\u03b1 : Type} (r s : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2200x, r x x \u2227 s x x) \u2194 (\u2200x, r x x) \u2227 (\u2200x, s x x) :=\nsorry\n\n/-! 1.5. Supply a structured proof of the following property, which can be used\nto pull a `\u2200`-quantifier past an `\u2203`-quantifier. -/\n\nlemma forall_exists_of_exists_forall {\u03b1 : Type} (p : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2203x, \u2200y, p x y) \u2192 (\u2200y, \u2203x, p x y) :=\nsorry\n\n\n/-! ## Question 2: Chain of Equalities\n\n2.1. Write the following proof using `calc`.\n\n      (a + b) * (a + b)\n    = a * (a + b) + b * (a + b)\n    = a * a + a * b + b * a + b * b\n    = a * a + a * b + a * b + b * b\n    = a * a + 2 * a * b + b * b\n\nHint: You might need the tactics `simp` and `cc` and the lemmas `mul_add`,\n`add_mul`, and `two_mul`. -/\n\nlemma binomial_square (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/-! 2.2 (**optional**). Prove the same argument again, this time as a structured\nproof, with `have` steps corresponding to the `calc` equations. Try to reuse as\nmuch of the above proof idea as possible, proceeding mechanically. -/\n\nlemma binomial_square\u2082 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/-! 2.3. Prove the same lemma again, this time using tactics. -/\n\nlemma binomial_square\u2083 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nbegin\n  sorry\nend\n\n\n/-! ## Question 3 (**optional**): One-Point Rules\n\n3.1 (**optional**). Prove that the following wrong formulation of the one-point\nrule for `\u2200` is inconsistent, using a structured proof. -/\n\naxiom forall.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2200x : \u03b1, x = t \u2227 p x) \u2194 p t\n\nlemma proof_of_false :\n  false :=\nsorry\n\n/-! 3.2 (**optional**). Prove that the following wrong formulation of the\none-point rule for `\u2203` is inconsistent, using a tactical or structured proof. -/\n\naxiom exists.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2203x : \u03b1, x = t \u2192 p x) \u2194 p t\n\nlemma proof_of_false\u2082 :\n  false :=\nsorry\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/exercises/love03_forward_proofs_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642945, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7468715941635277}}
{"text": "import topology.algebra.infinite_sum\nimport data.real.basic\nimport data.real.nnreal\nimport algebra.geom_sum\n\nopen_locale big_operators\nopen_locale classical\nopen finset\n\nnotation `|`x`|` := abs x\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\ndef non_decreasing (u : \u2115 \u2192 \u211d) := \n\u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\ndef is_seq_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n/- The following is a lemma proven from exercises -/\n\nlemma bounded_above_and_increasing_func_converges_to_sup \n(M : \u211d) (u : \u2115 \u2192 \u211d) (h : is_seq_sup M u) (h' : non_decreasing u) :\nseq_limit u M :=\nbegin\n  -- get rid off most of the \u2200, \u2203 statements\n  intros \u03b5 \u03b5_pos,\n  cases h with ha hb,\n  cases hb \u03b5 \u03b5_pos with n\u2080 un\u2080,\n  use n\u2080,\n  intros n,\n  specialize h' n\u2080 n,\n  intros h'l,\n  -- gather hypothesis to prove the desired result\n  have inter\u2081 : u n\u2080 \u2264 u n,\n  {\n    apply h',\n    exact h'l,\n  },\n  have inter\u2082 : u n \u2265 M - \u03b5, { linarith, },\n  have inter\u2083 : M + \u03b5 \u2265 u n,\n  {\n    specialize ha n,\n    linarith,\n  },\n  have inter\u2082' : M - u n \u2264 \u03b5, { linarith, },\n  have inter\u2083' : u n - M \u2264 \u03b5, { linarith, },\n  rw abs_le,\n  split,\n  repeat { linarith, },\nend\n\nlemma bounded_above_and_increasing_func_converges\n(u : \u2115 \u2192 \u211d) (bounded_above : \u2203 x : \u211d, \u2200 n : \u2115, u n \u2264 x) (increasing : non_decreasing u) :\n\u2203 l : \u211d, seq_limit u l :=\nbegin\n  have non_empty : (\u2203 (x : \u211d), x \u2208 set.range u),\n  {\n    use u 1,\n    use 1,\n  },\n  -- prove that \u2203 supremum\n  have inter : (\u2203 (x : \u211d), \u2200 (y : \u211d), x \u2264 y \u2194 \u2200 (z : \u211d), z \u2208 set.range u \u2192 z \u2264 y),\n  {\n    refine real.exists_sup (set.range u) non_empty _,\n    cases bounded_above with x hx,\n    use x,\n    intros y hy, \n    cases hy with n hn,\n    specialize hx n,\n    linarith,\n  },\n  -- in inter, x is sup, y is upper bounds, z is (u n)\n  cases inter with M hM,\n  cases bounded_above with x hx,\n  -- simplify the expression\n  /- Note: inter' should not prematurely specify y,\n   - e.g. have inter' : M \u2264 x \u2194 \u2200 (n : \u2115), u n \u2264 x,\n   - otherwise cannot be used as the Prop to be contraposed\n   -/\n  have inter' : \u2200 y : \u211d, M \u2264 y \u2194 \u2200 n : \u2115, u n \u2264 y, \n  {\n    intros y,\n    rw hM,\n    exact set.forall_range_iff,\n  },\n  -- necessary lemma to be proved so as to prove the current lemma\n  have is_sup : \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5,\n  {\n    contrapose! inter',\n    rcases inter' with \u27e8\u03b5, \u03b5_pos, h\u03b5\u27e9,\n    use (M - \u03b5 / 2),\n    rw not_iff,\n    rw not_le,\n    split,\n    {\n      intros h1 n,\n      specialize h\u03b5 n,\n      linarith,\n    },\n    {\n      intro h,\n      linarith,\n    },\n  },\n  -- use everything proved previously to prove the proposition!\n  use M,\n  refine bounded_above_and_increasing_func_converges_to_sup M u _ increasing,\n  split,\n  {\n    specialize inter' M,\n    apply inter'.1,\n    linarith,\n  },\n  {\n    exact is_sup,\n  },\nend\n\n-- The following two lemmas thanks to Jason KY\n\ndef partial_sum_to (a : \u2115 \u2192 \u211d) (n : \u2115) := finset.sum (finset.range n) a\nnotation `\u2211` a := partial_sum_to a\n\nlemma sum_diff {a : \u2115 \u2192 \u211d} {n m : \u2115} (h\u2081 : n < m) :\n(\u2211 a) m - (\u2211 a) n = finset.sum (finset.Ico n m) a :=\nbegin\n  unfold partial_sum_to, \n  induction m with k hk,\n  {\n    exfalso, \n    from nat.not_succ_le_zero n h\u2081,\n  },\n  {\n    rw [finset.sum_range_succ, finset.sum_Ico_succ_top],\n    swap, \n    from nat.lt_succ_iff.mp h\u2081,\n    simp,\n    cases nat.lt_succ_iff_lt_or_eq.mp h\u2081,\n    {\n      specialize hk h,\n      linarith,\n    },\n    -- the line below somehow doesn't work for proving the first case\n    -- {rw [\u2190sub_eq_add_neg, hk h]},\n    {\n      rw h, \n      simp,\n    },\n  }\nend\n\nlemma sum_pos {a : \u2115 \u2192 \u211d} {n m : \u2115} (h\u2081 : \u2200 k : \u2115, 0 \u2264 a k) :\n0 \u2264 finset.sum (finset.Ico n m) a :=\nbegin\n  induction m with k hk,\n  {\n    rw finset.Ico.eq_empty_iff.mpr (zero_le n), \n    simp,\n  },\n  {\n    cases le_or_lt n k,\n    {\n      rw finset.sum_Ico_succ_top h,\n      from add_nonneg hk (h\u2081 k),\n    },\n    {\n      rw finset.Ico.eq_empty_iff.mpr (nat.succ_le_iff.mpr h),\n      simp,\n    },\n  },\nend\n\n/- The question to be proven in this project:\n - Suppose a\u2099 \u2265 0 \u2200 n and converges to a \u2208 [0,1). Prove \u2211_{n=1}^\u221e a\u2099^n converges.\n - you can jump to where \"MARK !!!\" is to see the core of the proof\n -/\nlemma series_of_root_numbers_converges \n(a : \u2115 \u2192 \u211d) (l : \u211d) (h_seq : seq_limit a l) (hu : \u2200 n : \u2115, a n \u2265 0) (hl : l \u2208 set.Ico (0 : \u211d) 1):\n\u2203 x : \u211d, seq_limit (\u03bb N : \u2115 , (\u2211 (\u03bb n : \u2115, a n ^ n)) N) x :=\nbegin\n  have hann : \u2200 n : \u2115, a n ^ n \u2265 0,\n  {\n    intros n,\n    specialize hu n,\n    exact pow_nonneg hu n,\n  },\n  apply bounded_above_and_increasing_func_converges,\n  {\n    -- prove that the series is bounded above\n    unfold seq_limit at h_seq,\n    have l_nonneg: l \u2265 0, { exact hl.left, },\n    have l_lt_1: l < 1, { exact hl.right, },\n    specialize h_seq ((1 - l) / 2) (by linarith),\n    cases h_seq with N hN,\n    let A : \u211d := (1 + l) / 2,\n    have A_pos : A > 0,\n    {\n      have inter : (1 + l) / 2 > 0, { linarith, },\n      exact inter,\n    },\n    -- Below is the upper bound of the series\n    use (((\u2211 (\u03bb n : \u2115, a n ^ n)) N) + A ^ N / (1 - A)),\n    intro n,\n    let hN' := hN n,\n    have hAN_pos : A ^ N > 0, { exact pow_pos A_pos N, },\n    have hAn_pos : A ^ n > 0, { exact pow_pos A_pos n, },\n    by_cases n \u2264 N,\n    {\n      -- trivial but unfortunately long proof...\n      have hAN : A ^ N / (1 - A) > 0,\n      {\n        have temp : 1 - A > 0,\n        {\n          have inter : (1 - (1 + l) / 2 > 0), { linarith, },\n          exact inter,\n        },\n        exact div_pos hAN_pos temp,\n      },\n      by_cases h' : n = N,\n      {\n        rw h',\n        linarith,\n      },\n      {\n        refine sub_nonneg.mp _,\n        have temp_add_sub_comm: \u2200 x y z : \u211d, x + y - z = x - z + y,\n        {\n          intros x y z,\n          ring,\n        },\n        rw temp_add_sub_comm,\n        have hnN : n < N, \n        { exact lt_of_le_of_ne h h', },\n        rw sum_diff hnN,\n        have nonneg_sum_diff : 0 \u2264 finset.sum (finset.Ico n N) (\u03bb n : \u2115, a n ^ n),\n        { exact sum_pos hann, },\n        linarith,\n      },\n    },\n    {\n      push_neg at h,\n      have h' : N \u2264 n, { linarith, },\n      have A_le_1: A < 1,\n      {\n        have inter : (1 + l) / 2 < 1, { linarith, },\n        exact inter,\n      },\n      specialize hN' h',\n      -- The following c\u1d62's are for deducing each line in the calc block later\n      have c\u2081 : (\u2211\u03bb (n : \u2115), a n ^ n) n - (\u2211\u03bb (n : \u2115), a n ^ n) N \n        = finset.sum (finset.Ico N n) (\u03bb (n : \u2115), a n ^ n),\n      { exact sum_diff h, },\n      have c\u2082 : finset.sum (finset.Ico N n) (\u03bb (n : \u2115), a n ^ n) \n        \u2264 finset.sum (finset.Ico N n) (\u03bb (n : \u2115), A ^ n),\n      {\n        have temp : \u2200 x \u2208 Ico N n, a x ^ x \u2264 A ^ x,\n        {\n          intros n' hn'Nn,\n          have haA : a n' \u2264 (1 + l) / 2,\n          {\n            specialize hN n' _,\n            {\n              rw abs_le at hN,\n              cases hN,\n              linarith,\n            },\n            {\n              rwa Ico.mem at hn'Nn,\n              linarith,\n            },\n          },\n          exact pow_le_pow_of_le_left (hu n') haA n',\n        },\n        exact sum_le_sum temp,\n      },\n      have c\u2083 : finset.sum (finset.Ico N n) (\u03bb (n : \u2115), A ^ n) \n        = (A ^ n - A ^ N) / (A - 1),\n      {\n        by exact geom_sum_Ico (by linarith) h',\n      },\n      have c\u2084 : (A ^ n - A ^ N) / (A - 1) = (A ^ N - A ^ n) / (1 - A),\n      {\n        have inter\u2081 : A - 1 \u2260 0, { linarith, },\n        have inter\u2082 : 1 - A \u2260 0, { linarith, },\n        rw div_eq_div_iff inter\u2081 inter\u2082,\n        linarith,\n      },\n      have c\u2085 : (A ^ N - A ^ n) / (1 - A) \u2264 A ^ N / (1 - A),\n      {\n        apply div_le_div,\n        repeat { linarith, },\n      },\n      -- MARK !!!\n      -- The following calc block is the holy grail of the proof!\n      calc (\u2211\u03bb (n : \u2115), a n ^ n) n \n      = (\u2211\u03bb (n : \u2115), a n ^ n) N + finset.sum (finset.Ico N n) (\u03bb (n : \u2115), a n ^ n) : by linarith\n      ... \u2264 (\u2211\u03bb (n : \u2115), a n ^ n) N + finset.sum (finset.Ico N n) (\u03bb (n : \u2115), A ^ n) : by linarith\n      ... = (\u2211\u03bb (n : \u2115), a n ^ n) N + (A ^ n - A ^ N) / (A - 1) : by linarith\n      ... = (\u2211\u03bb (n : \u2115), a n ^ n) N + (A ^ N - A ^ n) / (1 - A) : by linarith\n      ... \u2264 (\u2211\u03bb (n : \u2115), a n ^ n) N + A ^ N / (1 - A) : by linarith,\n    },\n  },\n  {\n    -- prove that the series is monotonically increasing\n    unfold non_decreasing,\n    intros n m hnm,\n    rw le_iff_lt_or_eq at hnm,\n    cases hnm with hl he,\n    {\n      refine sub_nonneg.mp _,\n      rw sum_diff hl,\n      exact sum_pos hann,\n    },\n    {\n      rw le_iff_lt_or_eq,\n      right,\n      rwa he,\n    },\n  },\nend\n\n/- potentially more general version:\nlemma series_of_root_numbers_converges \n(a : \u2115 \u2192 \u211d) (l : \u211d) (h_seq : seq_limit a l) (hu : \u2200 n : \u2115, a n \u2265 0) \n(l_pos : l \u2265 0) (l_lt_one: l < 1) :\n\u2203 x : \u211d, has_sum (\u03bb n, (a n) ^ n) x :=\nbegin\n  sorry\nend\n -/", "meta": {"author": "qsmy41", "repo": "ICL-UROP---LeanProver", "sha": "20aa66d479c5edd0706819d641d2f642432e6adb", "save_path": "github-repos/lean/qsmy41-ICL-UROP---LeanProver", "path": "github-repos/lean/qsmy41-ICL-UROP---LeanProver/ICL-UROP---LeanProver-20aa66d479c5edd0706819d641d2f642432e6adb/src/UROP.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7468715821007629}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n\nDefinitions and properties of gcd, lcm, and coprime.\n-/\nimport .div data.nat.gcd\nopen eq.ops\n\nnamespace int\n\n/- gcd -/\n\ndefinition gcd (a b : \u2124) : \u2124 := of_nat (nat.gcd (nat_abs a) (nat_abs b))\n\ntheorem gcd_nonneg (a b : \u2124) : gcd a b \u2265 0 :=\nof_nat_nonneg (nat.gcd (nat_abs a) (nat_abs b))\n\ntheorem gcd.comm (a b : \u2124) : gcd a b = gcd b a :=\nby rewrite [\u2191gcd, nat.gcd.comm]\n\ntheorem gcd_zero_right (a : \u2124) : gcd a 0 = abs a :=\nby rewrite [\u2191gcd, nat_abs_zero, nat.gcd_zero_right, of_nat_nat_abs]\n\ntheorem gcd_zero_left (a : \u2124) : gcd 0 a = abs a :=\nby rewrite [gcd.comm, gcd_zero_right]\n\ntheorem gcd_one_right (a : \u2124) : gcd a 1 = 1 :=\nby rewrite [\u2191gcd, nat_abs_one, nat.gcd_one_right]\n\ntheorem gcd_one_left (a : \u2124) : gcd 1 a = 1 :=\nby rewrite [gcd.comm, gcd_one_right]\n\ntheorem gcd_abs_left (a b : \u2124) : gcd (abs a) b = gcd a b :=\nby rewrite [\u2191gcd, *nat_abs_abs]\n\ntheorem gcd_abs_right (a b : \u2124) : gcd (abs a) b = gcd a b :=\nby rewrite [\u2191gcd, *nat_abs_abs]\n\ntheorem gcd_abs_abs (a b : \u2124) : gcd (abs a) (abs b) = gcd a b :=\nby rewrite [\u2191gcd, *nat_abs_abs]\n\nsection\nopen nat\ntheorem gcd_of_ne_zero (a : \u2124) {b : \u2124} (H : b \u2260 0) : gcd a b = gcd b (abs a % abs b) :=\nhave nat_abs b \u2260 0,  from assume H', H (eq_zero_of_nat_abs_eq_zero H'),\nhave nat_abs b > 0,  from pos_of_ne_zero this,\nhave nat.gcd (nat_abs a) (nat_abs b) = (nat.gcd (nat_abs b) (nat_abs a % nat_abs b)),\n  from @nat.gcd_of_pos (nat_abs a) (nat_abs b) this,\ncalc\n gcd a b = nat.gcd (nat_abs b) (nat_abs a % nat_abs b) : by rewrite [\u2191gcd, this]\n     ... = gcd (abs b) (abs a % abs b)                 : by rewrite [\u2191gcd, -*of_nat_nat_abs, of_nat_mod]\n     ... = gcd b (abs a % abs b)                       : by rewrite [\u2191gcd, *nat_abs_abs]\nend\n\ntheorem gcd_of_pos (a : \u2124) {b : \u2124} (H : b > 0) : gcd a b = gcd b (abs a % b) :=\nby rewrite [!gcd_of_ne_zero (ne_of_gt H), abs_of_pos H]\n\ntheorem gcd_of_nonneg_of_pos {a b : \u2124} (H1 : a \u2265 0) (H2 : b > 0) : gcd a b = gcd b (a % b) :=\nby rewrite [!gcd_of_pos H2, abs_of_nonneg H1]\n\ntheorem gcd_self (a : \u2124) : gcd a a = abs a :=\nby rewrite [\u2191gcd, nat.gcd_self, of_nat_nat_abs]\n\ntheorem gcd_dvd_left (a b : \u2124) : gcd a b \u2223 a :=\nhave gcd a b \u2223 abs a,\n  by rewrite [\u2191gcd, -of_nat_nat_abs, of_nat_dvd_of_nat_iff]; apply nat.gcd_dvd_left,\niff.mp !dvd_abs_iff this\n\ntheorem gcd_dvd_right (a b : \u2124) : gcd a b \u2223 b :=\nby rewrite gcd.comm; apply gcd_dvd_left\n\ntheorem dvd_gcd {a b c : \u2124} : a \u2223 b \u2192 a \u2223 c \u2192 a \u2223 gcd b c :=\nbegin\n  rewrite [\u2191gcd, -*(abs_dvd_iff a), -(dvd_abs_iff _ b), -(dvd_abs_iff _ c), -*of_nat_nat_abs],\n  rewrite [*of_nat_dvd_of_nat_iff] ,\n  apply nat.dvd_gcd\nend\n\ntheorem gcd.assoc (a b c : \u2124) : gcd (gcd a b) c = gcd a (gcd b c) :=\ndvd.antisymm !gcd_nonneg !gcd_nonneg\n  (dvd_gcd\n    (dvd.trans !gcd_dvd_left !gcd_dvd_left)\n    (dvd_gcd (dvd.trans !gcd_dvd_left !gcd_dvd_right) !gcd_dvd_right))\n  (dvd_gcd\n    (dvd_gcd !gcd_dvd_left (dvd.trans !gcd_dvd_right !gcd_dvd_left))\n    (dvd.trans !gcd_dvd_right !gcd_dvd_right))\n\ntheorem gcd_mul_left (a b c : \u2124) : gcd (a * b) (a * c) = abs a * gcd b c :=\nby rewrite [\u2191gcd, *nat_abs_mul, nat.gcd_mul_left, of_nat_mul, of_nat_nat_abs]\n\ntheorem gcd_mul_right (a b c : \u2124) : gcd (a * b) (c * b) = gcd a c * abs b :=\nby rewrite [mul.comm a, mul.comm c, mul.comm (gcd a c), gcd_mul_left]\n\ntheorem gcd_pos_of_ne_zero_left {a : \u2124} (b : \u2124) (H : a \u2260 0) : gcd a b > 0 :=\nhave gcd a b \u2260 0, from\n  suppose gcd a b = 0,\n  have 0 \u2223 a,    from this \u25b8 gcd_dvd_left a b,\n  show false,    from H (eq_zero_of_zero_dvd this),\nlt_of_le_of_ne (gcd_nonneg a b) (ne.symm this)\n\ntheorem gcd_pos_of_ne_zero_right (a : \u2124) {b : \u2124} (H : b \u2260 0) : gcd a b > 0 :=\nby rewrite gcd.comm; apply !gcd_pos_of_ne_zero_left H\n\ntheorem eq_zero_of_gcd_eq_zero_left {a b : \u2124} (H : gcd a b = 0) : a = 0 :=\ndecidable.by_contradiction\n  (suppose a \u2260 0,\n    have gcd a b > 0, from !gcd_pos_of_ne_zero_left this,\n    ne_of_lt this H\u207b\u00b9)\n\ntheorem eq_zero_of_gcd_eq_zero_right {a b : \u2124} (H : gcd a b = 0) : b = 0 :=\nby rewrite gcd.comm at H; apply !eq_zero_of_gcd_eq_zero_left H\n\ntheorem gcd_div {a b c : \u2124} (H1 : c \u2223 a) (H2 : c \u2223 b) :\n  gcd (a / c) (b / c) = gcd a b / (abs c) :=\ndecidable.by_cases\n  (suppose c = 0,\n    calc\n      gcd (a / c) (b / c) = gcd 0 0               : by subst c; rewrite *int.div_zero\n                          ... = 0                 : gcd_zero_left\n                          ... = gcd a b / 0       : int.div_zero\n                          ... = gcd a b / (abs c) : by subst c)\n  (suppose c \u2260 0,\n    have abs c \u2260 0, from assume H', this (eq_zero_of_abs_eq_zero H'),\n    eq.symm (int.div_eq_of_eq_mul_left this\n      (eq.symm (calc\n        gcd (a / c) (b / c) * abs c = gcd (a / c * c) (b / c * c) : gcd_mul_right\n                               ... = gcd a (b / c * c)            : int.div_mul_cancel H1\n                               ... = gcd a b                      : int.div_mul_cancel H2))))\n\ntheorem gcd_dvd_gcd_mul_left (a b c : \u2124) : gcd a b \u2223 gcd (c * a) b :=\ndvd_gcd (dvd.trans !gcd_dvd_left !dvd_mul_left) !gcd_dvd_right\n\ntheorem gcd_dvd_gcd_mul_right (a b c : \u2124) : gcd a b \u2223 gcd (a * c) b :=\n!mul.comm \u25b8 !gcd_dvd_gcd_mul_left\n\ntheorem div_gcd_eq_div_gcd_of_nonneg {a\u2081 b\u2081 a\u2082 b\u2082 : \u2124} (H : a\u2081 * b\u2082 = a\u2082 * b\u2081)\n    (H1 : b\u2081 \u2260 0) (H2 : b\u2082 \u2260 0) (H3 : a\u2081 \u2265 0) (H4 : a\u2082 \u2265 0) :\n  a\u2081 / (gcd a\u2081 b\u2081) = a\u2082 / (gcd a\u2082 b\u2082) :=\nbegin\n  apply div_eq_div_of_dvd_of_dvd,\n  repeat (apply gcd_dvd_left),\n  intro H', apply H1, apply eq_zero_of_gcd_eq_zero_right H',\n  intro H', apply H2, apply eq_zero_of_gcd_eq_zero_right H',\n  rewrite [-abs_of_nonneg H3 at {1}, -abs_of_nonneg H4 at {2}],\n  rewrite [-gcd_mul_left, -gcd_mul_right, H, mul.comm b\u2081]\nend\n\ntheorem div_gcd_eq_div_gcd {a\u2081 b\u2081 a\u2082 b\u2082 : \u2124} (H : a\u2081 * b\u2082 = a\u2082 * b\u2081) (H1 : b\u2081 > 0) (H2 : b\u2082 > 0) :\n  a\u2081 / (gcd a\u2081 b\u2081) = a\u2082 / (gcd a\u2082 b\u2082) :=\nor.elim (le_or_gt 0 a\u2081)\n  (assume H3 : a\u2081 \u2265 0,\n    have H4 : a\u2082 * b\u2081 \u2265 0, by rewrite -H; apply mul_nonneg H3 (le_of_lt H2),\n    have H5 : a\u2082 \u2265 0, from nonneg_of_mul_nonneg_right H4 H1,\n    div_gcd_eq_div_gcd_of_nonneg H (ne_of_gt H1) (ne_of_gt H2) H3 H5)\n  (assume H3 : a\u2081 < 0,\n    have H4 : a\u2082 * b\u2081 < 0, by rewrite -H; apply mul_neg_of_neg_of_pos H3 H2,\n    have H5 : a\u2082 < 0, from neg_of_mul_neg_right H4 (le_of_lt H1),\n    have H6 : abs a\u2081 / (gcd (abs a\u2081) (abs b\u2081)) = abs a\u2082 / (gcd (abs a\u2082) (abs b\u2082)),\n      begin\n        apply div_gcd_eq_div_gcd_of_nonneg,\n        rewrite [abs_of_pos H1, abs_of_pos H2, abs_of_neg H3, abs_of_neg H5],\n        rewrite [-*neg_mul_eq_neg_mul, H],\n        apply ne_of_gt (abs_pos_of_pos H1),\n        apply ne_of_gt (abs_pos_of_pos H2),\n        repeat (apply abs_nonneg)\n      end,\n    have H7 : -a\u2081 / (gcd a\u2081 b\u2081) = -a\u2082 / (gcd a\u2082 b\u2082),\n      begin\n        rewrite [-abs_of_neg H3, -abs_of_neg H5, -gcd_abs_abs a\u2081],\n        rewrite [-gcd_abs_abs a\u2082 b\u2082],\n        exact H6\n      end,\n    calc\n      a\u2081 / (gcd a\u2081 b\u2081) = -(-a\u2081 / (gcd a\u2081 b\u2081))   :\n                             by rewrite [neg_div_of_dvd !gcd_dvd_left, neg_neg]\n                     ... = -(-a\u2082 / (gcd a\u2082 b\u2082)) : H7\n                     ... = a\u2082 / (gcd a\u2082 b\u2082)     :\n                             by rewrite [neg_div_of_dvd !gcd_dvd_left, neg_neg])\n\n/- lcm -/\n\ndefinition lcm (a b : \u2124) : \u2124 := of_nat (nat.lcm (nat_abs a) (nat_abs b))\n\ntheorem lcm_nonneg (a b : \u2124) : lcm a b \u2265 0 :=\nof_nat_nonneg (nat.lcm (nat_abs a) (nat_abs b))\n\ntheorem lcm.comm (a b : \u2124) : lcm a b = lcm b a :=\nby rewrite [\u2191lcm, nat.lcm.comm]\n\ntheorem lcm_zero_left (a : \u2124) : lcm 0 a = 0 :=\nby rewrite [\u2191lcm, nat_abs_zero, nat.lcm_zero_left]\n\ntheorem lcm_zero_right (a : \u2124) : lcm a 0 = 0 :=\n!lcm.comm \u25b8 !lcm_zero_left\n\ntheorem lcm_one_left (a : \u2124) : lcm 1 a = abs a :=\nby rewrite [\u2191lcm, nat_abs_one, nat.lcm_one_left, of_nat_nat_abs]\n\ntheorem lcm_one_right (a : \u2124) : lcm a 1 = abs a :=\n!lcm.comm \u25b8 !lcm_one_left\n\ntheorem lcm_abs_left (a b : \u2124) : lcm (abs a) b = lcm a b :=\nby rewrite [\u2191lcm, *nat_abs_abs]\n\ntheorem lcm_abs_right (a b : \u2124) : lcm (abs a) b = lcm a b :=\nby rewrite [\u2191lcm, *nat_abs_abs]\n\ntheorem lcm_abs_abs (a b : \u2124) : lcm (abs a) (abs b) = lcm a b :=\nby rewrite [\u2191lcm, *nat_abs_abs]\n\ntheorem lcm_self (a : \u2124) : lcm a a = abs a :=\nby rewrite [\u2191lcm, nat.lcm_self, of_nat_nat_abs]\n\ntheorem dvd_lcm_left (a b : \u2124) : a \u2223 lcm a b :=\nby rewrite [\u2191lcm, -abs_dvd_iff, -of_nat_nat_abs, of_nat_dvd_of_nat_iff]; apply nat.dvd_lcm_left\n\ntheorem dvd_lcm_right (a b : \u2124) : b \u2223 lcm a b :=\n!lcm.comm \u25b8 !dvd_lcm_left\n\ntheorem gcd_mul_lcm (a b : \u2124) : gcd a b * lcm a b = abs (a * b) :=\nbegin\n  rewrite [\u2191gcd, \u2191lcm, -of_nat_nat_abs, -of_nat_mul, of_nat_eq_of_nat_iff, nat_abs_mul],\n  apply nat.gcd_mul_lcm\nend\n\ntheorem lcm_dvd {a b c : \u2124} : a \u2223 c \u2192 b \u2223 c \u2192 lcm a b \u2223 c :=\nbegin\n  rewrite [\u2191lcm, -(abs_dvd_iff a), -(abs_dvd_iff b), -*(dvd_abs_iff _ c), -*of_nat_nat_abs],\n  rewrite [*of_nat_dvd_of_nat_iff] ,\n  apply nat.lcm_dvd\nend\n\ntheorem lcm_assoc (a b c : \u2124) : lcm (lcm a b) c = lcm a (lcm b c) :=\ndvd.antisymm !lcm_nonneg !lcm_nonneg\n  (lcm_dvd\n    (lcm_dvd !dvd_lcm_left (dvd.trans !dvd_lcm_left !dvd_lcm_right))\n    (dvd.trans !dvd_lcm_right !dvd_lcm_right))\n  (lcm_dvd\n    (dvd.trans !dvd_lcm_left !dvd_lcm_left)\n    (lcm_dvd (dvd.trans !dvd_lcm_right !dvd_lcm_left) !dvd_lcm_right))\n\n/- coprime -/\n\nabbreviation coprime (a b : \u2124) : Prop := gcd a b = 1\n\ntheorem coprime_swap {a b : \u2124} (H : coprime b a) : coprime a b :=\n!gcd.comm \u25b8 H\n\ntheorem dvd_of_coprime_of_dvd_mul_right {a b c : \u2124} (H1 : coprime c b) (H2 : c \u2223 a * b) : c \u2223 a :=\nhave H3 : gcd (a * c) (a * b) = abs a, from\n  calc\n    gcd (a * c) (a * b) = abs a * gcd c b : gcd_mul_left\n                    ... = abs a * 1       : H1\n                    ... = abs a           : mul_one,\nhave H4 : (c \u2223 gcd (a * c) (a * b)), from dvd_gcd !dvd_mul_left H2,\nby rewrite [-dvd_abs_iff, -H3]; apply H4\n\ntheorem dvd_of_coprime_of_dvd_mul_left {a b c : \u2124} (H1 : coprime c a) (H2 : c \u2223 a * b) : c \u2223 b :=\ndvd_of_coprime_of_dvd_mul_right H1 (!mul.comm \u25b8 H2)\n\ntheorem gcd_mul_left_cancel_of_coprime {c : \u2124} (a : \u2124) {b : \u2124} (H : coprime c b) :\n   gcd (c * a) b = gcd a b :=\nbegin\n  revert H, unfold [coprime, gcd],\n  rewrite [-of_nat_one],\n  rewrite [+of_nat_eq_of_nat_iff, nat_abs_mul],\n  apply nat.gcd_mul_left_cancel_of_coprime,\nend\n\ntheorem gcd_mul_right_cancel_of_coprime (a : \u2124) {c b : \u2124} (H : coprime c b) :\n   gcd (a * c) b = gcd a b :=\n!mul.comm \u25b8 !gcd_mul_left_cancel_of_coprime H\n\ntheorem gcd_mul_left_cancel_of_coprime_right {c a : \u2124} (b : \u2124) (H : coprime c a) :\n   gcd a (c * b) = gcd a b :=\n!gcd.comm \u25b8 !gcd.comm \u25b8 !gcd_mul_left_cancel_of_coprime H\n\ntheorem gcd_mul_right_cancel_of_coprime_right {c a : \u2124} (b : \u2124) (H : coprime c a) :\n   gcd a (b * c) = gcd a b :=\n!gcd.comm \u25b8 !gcd.comm \u25b8 !gcd_mul_right_cancel_of_coprime H\n\ntheorem coprime_div_gcd_div_gcd {a b : \u2124} (H : gcd a b \u2260 0) :\n  coprime (a / gcd a b) (b / gcd a b) :=\ncalc\n  gcd (a / gcd a b) (b / gcd a b)\n         = gcd a b / abs (gcd a b) : gcd_div !gcd_dvd_left !gcd_dvd_right\n     ... = 1                       : by rewrite [abs_of_nonneg !gcd_nonneg, int.div_self H]\n\ntheorem not_coprime_of_dvd_of_dvd {m n d : \u2124} (dgt1 : d > 1) (Hm : d \u2223 m) (Hn : d \u2223 n) :\n  \u00ac coprime m n :=\nassume co : coprime m n,\nhave d \u2223 gcd m n, from dvd_gcd Hm Hn,\nhave d \u2223 1, by rewrite [\u2191coprime at co, co at this]; apply this,\nhave d \u2264 1, from le_of_dvd dec_trivial this,\nshow false, from not_lt_of_ge `d \u2264 1` `d > 1`\n\ntheorem exists_coprime {a b : \u2124} (H : gcd a b \u2260 0) :\n  exists a' b', coprime a' b' \u2227 a = a' * gcd a b \u2227 b = b' * gcd a b :=\nhave H1 : a = (a / gcd a b) * gcd a b, from (int.div_mul_cancel !gcd_dvd_left)\u207b\u00b9,\nhave H2 : b = (b / gcd a b) * gcd a b, from (int.div_mul_cancel !gcd_dvd_right)\u207b\u00b9,\nexists.intro _ (exists.intro _ (and.intro (coprime_div_gcd_div_gcd H) (and.intro H1 H2)))\n\ntheorem coprime_mul {a b c : \u2124} (H1 : coprime a c) (H2 : coprime b c) : coprime (a * b) c :=\ncalc\n  gcd (a * b) c = gcd b c : !gcd_mul_left_cancel_of_coprime H1\n            ... = 1       : H2\n\ntheorem coprime_mul_right {c a b : \u2124} (H1 : coprime c a) (H2 : coprime c b) : coprime c (a * b) :=\ncoprime_swap (coprime_mul (coprime_swap H1) (coprime_swap H2))\n\ntheorem coprime_of_coprime_mul_left {c a b : \u2124} (H : coprime (c * a) b) : coprime a b :=\nhave H1 : (gcd a b \u2223 gcd (c * a) b), from !gcd_dvd_gcd_mul_left,\neq_one_of_dvd_one !gcd_nonneg (H \u25b8 H1)\n\ntheorem coprime_of_coprime_mul_right {c a b : \u2124} (H : coprime (a * c) b) : coprime a b :=\ncoprime_of_coprime_mul_left (!mul.comm \u25b8 H)\n\ntheorem coprime_of_coprime_mul_left_right {c a b : \u2124} (H : coprime a (c * b)) : coprime a b :=\ncoprime_swap (coprime_of_coprime_mul_left (coprime_swap H))\n\ntheorem coprime_of_coprime_mul_right_right {c a b : \u2124} (H : coprime a (b * c)) : coprime a b :=\ncoprime_of_coprime_mul_left_right (!mul.comm \u25b8 H)\n\ntheorem exists_eq_prod_and_dvd_and_dvd {a b c : \u2124} (H : c \u2223 a * b) :\n  \u2203 a' b', c = a' * b' \u2227 a' \u2223 a \u2227 b' \u2223 b :=\ndecidable.by_cases\n (suppose gcd c a = 0,\n    have c = 0, from eq_zero_of_gcd_eq_zero_left `gcd c a = 0`,\n    have a = 0, from eq_zero_of_gcd_eq_zero_right `gcd c a = 0`,\n    have c = 0 * b, from `c = 0` \u2b1d !zero_mul\u207b\u00b9,\n    have 0 \u2223 a, from `a = 0`\u207b\u00b9 \u25b8 !dvd.refl,\n    have b \u2223 b, from !dvd.refl,\n    exists.intro _ (exists.intro _ (and.intro `c = 0 * b` (and.intro `0 \u2223 a` `b \u2223 b`))))\n  (suppose gcd c a \u2260 0,\n    have gcd c a \u2223 c, from !gcd_dvd_left,\n    have H3 : c / gcd c a \u2223 (a * b) / gcd c a, from div_dvd_div this H,\n    have H4 : (a * b) / gcd c a = (a / gcd c a) * b, from\n      calc\n        a * b / gcd c a = b * a / gcd c a     : mul.comm\n                      ... = b * (a / gcd c a) : !int.mul_div_assoc !gcd_dvd_right\n                      ... = a / gcd c a * b   : mul.comm,\n    have H5 : c / gcd c a \u2223 (a / gcd c a) * b, from H4 \u25b8 H3,\n    have H6 : coprime (c / gcd c a) (a / gcd c a), from coprime_div_gcd_div_gcd `gcd c a \u2260 0`,\n    have H7 : c / gcd c a \u2223 b, from dvd_of_coprime_of_dvd_mul_left H6 H5,\n    have H8 : c = gcd c a * (c / gcd c a), from (int.mul_div_cancel' `gcd c a \u2223 c`)\u207b\u00b9,\n    exists.intro _ (exists.intro _ (and.intro H8 (and.intro !gcd_dvd_right H7))))\n\nend int\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/int/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.746871573558723}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport algebra.algebra.basic\n\n/-!\n# Multiplication and division of submodules of an algebra.\n\nAn interface for multiplication and division of sub-R-modules of an R-algebra A is developed.\n\n## Main definitions\n\nLet `R` be a commutative ring (or semiring) and aet `A` be an `R`-algebra.\n\n* `1 : submodule R A`       : the R-submodule R of the R-algebra A\n* `has_mul (submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be\n                              the smallest submodule containing all the products `m * n`.\n* `has_div (submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such\n                              that `a \u2022 J \u2286 I`\n\nIt is proved that `submodule R A` is a semiring, and also an algebra over `set A`.\n\n## Tags\n\nmultiplication of submodules, division of subodules, submodule semiring\n-/\n\nuniverses u v\n\nopen algebra set\n\nnamespace submodule\n\nvariables {R : Type u} [comm_semiring R]\n\nsection ring\n\nvariables {A : Type v} [semiring A] [algebra R A]\nvariables (S T : set A) {M N P Q : submodule R A} {m n : A}\n\n/-- `1 : submodule R A` is the submodule R of A. -/\ninstance : has_one (submodule R A) :=\n\u27e8submodule.map (of_id R A).to_linear_map (\u22a4 : submodule R R)\u27e9\n\ntheorem one_eq_map_top :\n  (1 : submodule R A) = submodule.map (of_id R A).to_linear_map (\u22a4 : submodule R R) := rfl\n\ntheorem one_eq_span : (1 : submodule R A) = R \u2219 1 :=\nbegin\n  apply submodule.ext,\n  intro a,\n  erw [mem_map, mem_span_singleton],\n  apply exists_congr,\n  intro r,\n  simpa [smul_def],\nend\n\ntheorem one_le : (1 : submodule R A) \u2264 P \u2194 (1 : A) \u2208 P :=\nby simpa only [one_eq_span, span_le, set.singleton_subset_iff]\n\n/-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the\nsmallest R-submodule of `A` containing the elements `m * n` for `m \u2208 M` and `n \u2208 N`. -/\ninstance : has_mul (submodule R A) :=\n\u27e8\u03bb M N, \u2a06 s : M, N.map $ algebra.lmul R A s.1\u27e9\n\ntheorem mul_mem_mul (hm : m \u2208 M) (hn : n \u2208 N) : m * n \u2208 M * N :=\n(le_supr _ \u27e8m, hm\u27e9 : _ \u2264 M * N) \u27e8n, hn, rfl\u27e9\n\ntheorem mul_le : M * N \u2264 P \u2194 \u2200 (m \u2208 M) (n \u2208 N), m * n \u2208 P :=\n\u27e8\u03bb H m hm n hn, H $ mul_mem_mul hm hn,\n\u03bb H, supr_le $ \u03bb \u27e8m, hm\u27e9, map_le_iff_le_comap.2 $ \u03bb n hn, H m hm n hn\u27e9\n\n@[elab_as_eliminator] protected theorem mul_induction_on\n  {C : A \u2192 Prop} {r : A} (hr : r \u2208 M * N)\n  (hm : \u2200 (m \u2208 M) (n \u2208 N), C (m * n))\n  (h0 : C 0) (ha : \u2200 x y, C x \u2192 C y \u2192 C (x + y))\n  (hs : \u2200 (r : R) x, C x \u2192 C (r \u2022 x)) : C r :=\n(@mul_le _ _ _ _ _ _ _ \u27e8C, h0, ha, hs\u27e9).2 hm hr\n\nvariables R\ntheorem span_mul_span : span R S * span R T = span R (S * T) :=\nbegin\n  apply le_antisymm,\n  { rw mul_le, intros a ha b hb,\n    apply span_induction ha,\n    work_on_goal 0 { intros, apply span_induction hb,\n      work_on_goal 0 { intros, exact subset_span \u27e8_, _, \u2039_\u203a, \u2039_\u203a, rfl\u27e9 } },\n    all_goals { intros, simp only [mul_zero, zero_mul, zero_mem,\n        left_distrib, right_distrib, mul_smul_comm, smul_mul_assoc],\n      try {apply add_mem _ _ _}, try {apply smul_mem _ _ _} }, assumption' },\n  { rw span_le, rintros _ \u27e8a, b, ha, hb, rfl\u27e9,\n    exact mul_mem_mul (subset_span ha) (subset_span hb) }\nend\nvariables {R}\n\nvariables (M N P Q)\nprotected theorem mul_assoc : (M * N) * P = M * (N * P) :=\nle_antisymm (mul_le.2 $ \u03bb mn hmn p hp,\n  suffices M * N \u2264 (M * (N * P)).comap (algebra.lmul_right R p), from this hmn,\n  mul_le.2 $ \u03bb m hm n hn, show m * n * p \u2208 M * (N * P), from\n  (mul_assoc m n p).symm \u25b8 mul_mem_mul hm (mul_mem_mul hn hp))\n(mul_le.2 $ \u03bb m hm np hnp,\n  suffices N * P \u2264 (M * N * P).comap (algebra.lmul_left R m), from this hnp,\n  mul_le.2 $ \u03bb n hn p hp, show m * (n * p) \u2208 M * N * P, from\n  mul_assoc m n p \u25b8 mul_mem_mul (mul_mem_mul hm hn) hp)\n\n@[simp] theorem mul_bot : M * \u22a5 = \u22a5 :=\neq_bot_iff.2 $ mul_le.2 $ \u03bb m hm n hn, by rw [submodule.mem_bot] at hn \u22a2; rw [hn, mul_zero]\n\n@[simp] theorem bot_mul : \u22a5 * M = \u22a5 :=\neq_bot_iff.2 $ mul_le.2 $ \u03bb m hm n hn, by rw [submodule.mem_bot] at hm \u22a2; rw [hm, zero_mul]\n\n@[simp] protected theorem one_mul : (1 : submodule R A) * M = M :=\nby { conv_lhs { rw [one_eq_span, \u2190 span_eq M] }, erw [span_mul_span, one_mul, span_eq] }\n\n@[simp] protected theorem mul_one : M * 1 = M :=\nby { conv_lhs { rw [one_eq_span, \u2190 span_eq M] }, erw [span_mul_span, mul_one, span_eq] }\n\nvariables {M N P Q}\n\n@[mono] theorem mul_le_mul (hmp : M \u2264 P) (hnq : N \u2264 Q) : M * N \u2264 P * Q :=\nmul_le.2 $ \u03bb m hm n hn, mul_mem_mul (hmp hm) (hnq hn)\n\ntheorem mul_le_mul_left (h : M \u2264 N) : M * P \u2264 N * P :=\nmul_le_mul h (le_refl P)\n\ntheorem mul_le_mul_right (h : N \u2264 P) : M * N \u2264 M * P :=\nmul_le_mul (le_refl M) h\n\nvariables (M N P)\n\n\ntheorem sup_mul : (M \u2294 N) * P = M * P \u2294 N * P :=\nle_antisymm (mul_le.2 $ \u03bb mn hmn p hp, let \u27e8m, hm, n, hn, hmn\u27e9 := mem_sup.1 hmn in\n  mem_sup.2 \u27e8_, mul_mem_mul hm hp, _, mul_mem_mul hn hp, hmn \u25b8 (add_mul m n p).symm\u27e9)\n(sup_le (mul_le_mul_left le_sup_left) (mul_le_mul_left le_sup_right))\n\nlemma mul_subset_mul : (\u2191M : set A) * (\u2191N : set A) \u2286 (\u2191(M * N) : set A) :=\nby { rintros _ \u27e8i, j, hi, hj, rfl\u27e9, exact mul_mem_mul hi hj }\n\nlemma map_mul {A'} [semiring A'] [algebra R A'] (f : A \u2192\u2090[R] A') :\n  map f.to_linear_map (M * N) = map f.to_linear_map M * map f.to_linear_map N :=\ncalc map f.to_linear_map (M * N)\n    = \u2a06 (i : M), (N.map (lmul R A i)).map f.to_linear_map : map_supr _ _\n... = map f.to_linear_map M * map f.to_linear_map N  :\n  begin\n    apply congr_arg Sup,\n    ext S,\n    split; rintros \u27e8y, hy\u27e9,\n    { use [f y, mem_map.mpr \u27e8y.1, y.2, rfl\u27e9],\n      refine trans _ hy,\n      ext,\n      simp },\n    { obtain \u27e8y', hy', fy_eq\u27e9 := mem_map.mp y.2,\n      use [y', hy'],\n      refine trans _ hy,\n      rw f.to_linear_map_apply at fy_eq,\n      ext,\n      simp [fy_eq] }\nend\n\nsection decidable_eq\n\nopen_locale classical\n\nlemma mem_span_mul_finite_of_mem_span_mul {S : set A} {S' : set A} {x : A}\n  (hx : x \u2208 span R (S * S')) :\n  \u2203 (T T' : finset A), \u2191T \u2286 S \u2227 \u2191T' \u2286 S' \u2227 x \u2208 span R (T * T' : set A) :=\nbegin\n  obtain \u27e8U, h, hU\u27e9 := mem_span_finite_of_mem_span hx,\n  obtain \u27e8T, T', hS, hS', h\u27e9 := finset.subset_mul h,\n  use [T, T', hS, hS'],\n  have h' : (U : set A) \u2286 T * T', { assumption_mod_cast, },\n  have h'' := span_mono h' hU,\n  assumption,\nend\n\nend decidable_eq\n\nlemma mem_span_mul_finite_of_mem_mul {P Q : submodule R A} {x : A} (hx : x \u2208 P * Q) :\n  \u2203 (T T' : finset A), (T : set A) \u2286 P \u2227 (T' : set A) \u2286 Q \u2227 x \u2208 span R (T * T' : set A) :=\nsubmodule.mem_span_mul_finite_of_mem_span_mul\n  (by rwa [\u2190 submodule.span_eq P, \u2190 submodule.span_eq Q, submodule.span_mul_span] at hx)\n\nvariables {M N P}\n\n/-- Sub-R-modules of an R-algebra form a semiring. -/\ninstance : semiring (submodule R A) :=\n{ one_mul       := submodule.one_mul,\n  mul_one       := submodule.mul_one,\n  mul_assoc     := submodule.mul_assoc,\n  zero_mul      := bot_mul,\n  mul_zero      := mul_bot,\n  left_distrib  := mul_sup,\n  right_distrib := sup_mul,\n  ..submodule.add_comm_monoid_submodule,\n  ..submodule.has_one,\n  ..submodule.has_mul }\n\nvariables (M)\n\nlemma pow_subset_pow {n : \u2115} : (\u2191M : set A)^n \u2286 \u2191(M^n : submodule R A) :=\nbegin\n  induction n with n ih,\n  { erw [pow_zero, pow_zero, set.singleton_subset_iff],\n    rw [set_like.mem_coe, \u2190 one_le],\n    exact le_refl _ },\n  { rw [pow_succ, pow_succ],\n    refine set.subset.trans (set.mul_subset_mul (subset.refl _) ih) _,\n    apply mul_subset_mul }\nend\n\n/-- `span` is a semiring homomorphism (recall multiplication is pointwise multiplication of subsets\non either side). -/\ndef span.ring_hom : set_semiring A \u2192+* submodule R A :=\n{ to_fun := submodule.span R,\n  map_zero' := span_empty,\n  map_one' := le_antisymm (span_le.2 $ singleton_subset_iff.2 \u27e81, \u27e8\u27e9, (algebra_map R A).map_one\u27e9)\n    (map_le_iff_le_comap.2 $ \u03bb r _, mem_span_singleton.2 \u27e8r, (algebra_map_eq_smul_one r).symm\u27e9),\n  map_add' := span_union,\n  map_mul' := \u03bb s t, by erw [span_mul_span, \u2190 image_mul_prod] }\n\nend ring\n\nsection comm_ring\n\nvariables {A : Type v} [comm_semiring A] [algebra R A]\nvariables {M N : submodule R A} {m n : A}\n\ntheorem mul_mem_mul_rev (hm : m \u2208 M) (hn : n \u2208 N) : n * m \u2208 M * N :=\nmul_comm m n \u25b8 mul_mem_mul hm hn\n\nvariables (M N)\nprotected theorem mul_comm : M * N = N * M :=\nle_antisymm (mul_le.2 $ \u03bb r hrm s hsn, mul_mem_mul_rev hsn hrm)\n(mul_le.2 $ \u03bb r hrn s hsm, mul_mem_mul_rev hsm hrn)\n\n/-- Sub-R-modules of an R-algebra A form a semiring. -/\ninstance : comm_semiring (submodule R A) :=\n{ mul_comm := submodule.mul_comm,\n  .. submodule.semiring }\n\nvariables (R A)\n\n/-- R-submodules of the R-algebra A are a module over `set A`. -/\ninstance module_set : module (set_semiring A) (submodule R A) :=\n{ smul := \u03bb s P, span R s * P,\n  smul_add := \u03bb _ _ _, mul_add _ _ _,\n  add_smul := \u03bb s t P, show span R (s \u2294 t) * P = _, by { erw [span_union, right_distrib] },\n  mul_smul := \u03bb s t P, show _ = _ * (_ * _),\n    by { rw [\u2190 mul_assoc, span_mul_span, \u2190 image_mul_prod] },\n  one_smul := \u03bb P, show span R {(1 : A)} * P = _,\n    by { conv_lhs {erw \u2190 span_eq P}, erw [span_mul_span, one_mul, span_eq] },\n  zero_smul := \u03bb P, show span R \u2205 * P = \u22a5, by erw [span_empty, bot_mul],\n  smul_zero := \u03bb _, mul_bot _ }\n\n\nvariables {R A}\n\nlemma smul_def {s : set_semiring A} {P : submodule R A} : s \u2022 P = span R s * P := rfl\n\nlemma smul_le_smul {s t : set_semiring A} {M N : submodule R A} (h\u2081 : s.down \u2264 t.down)\n  (h\u2082 : M \u2264 N) : s \u2022 M \u2264 t \u2022 N :=\nmul_le_mul (span_mono h\u2081) h\u2082\n\nlemma smul_singleton (a : A) (M : submodule R A) :\n  ({a} : set A).up \u2022 M = M.map (lmul_left _ a) :=\nbegin\n  conv_lhs {rw \u2190 span_eq M},\n  change span _ _ * span _ _ = _,\n  rw [span_mul_span],\n  apply le_antisymm,\n  { rw span_le,\n    rintros _ \u27e8b, m, hb, hm, rfl\u27e9,\n    rw [set_like.mem_coe, mem_map, set.mem_singleton_iff.mp hb],\n    exact \u27e8m, hm, rfl\u27e9 },\n  { rintros _ \u27e8m, hm, rfl\u27e9, exact subset_span \u27e8a, m, set.mem_singleton a, hm, rfl\u27e9 }\nend\n\nsection quotient\n\n/-- The elements of `I / J` are the `x` such that `x \u2022 J \u2286 I`.\n\nIn fact, we define `x \u2208 I / J` to be `\u2200 y \u2208 J, x * y \u2208 I` (see `mem_div_iff_forall_mul_mem`),\nwhich is equivalent to `x \u2022 J \u2286 I` (see `mem_div_iff_smul_subset`), but nicer to use in proofs.\n\nThis is the general form of the ideal quotient, traditionally written $I : J$.\n-/\ninstance : has_div (submodule R A) :=\n\u27e8 \u03bb I J, {\n  carrier   := { x | \u2200 y \u2208 J, x * y \u2208 I },\n  zero_mem' := \u03bb y hy, by { rw zero_mul, apply submodule.zero_mem },\n  add_mem'  := \u03bb a b ha hb y hy, by { rw add_mul, exact submodule.add_mem _ (ha _ hy) (hb _ hy) },\n  smul_mem' := \u03bb r x hx y hy, by { rw algebra.smul_mul_assoc,\n    exact submodule.smul_mem _ _ (hx _ hy) } } \u27e9\n\nlemma mem_div_iff_forall_mul_mem {x : A} {I J : submodule R A} :\n  x \u2208 I / J \u2194 \u2200 y \u2208 J, x * y \u2208 I :=\niff.refl _\n\nlemma mem_div_iff_smul_subset {x : A} {I J : submodule R A} : x \u2208 I / J \u2194 x \u2022 (J : set A) \u2286 I :=\n\u27e8 \u03bb h y \u27e8y', hy', xy'_eq_y\u27e9, by { rw \u2190 xy'_eq_y, apply h, assumption },\n  \u03bb h y hy, h (set.smul_mem_smul_set hy) \u27e9\n\nlemma le_div_iff {I J K : submodule R A} : I \u2264 J / K \u2194 \u2200 (x \u2208 I) (z \u2208 K), x * z \u2208 J := iff.refl _\n\nlemma le_div_iff_mul_le {I J K : submodule R A} : I \u2264 J / K \u2194 I * K \u2264 J :=\nby rw [le_div_iff, mul_le]\n\n@[simp] lemma one_le_one_div {I : submodule R A} :\n  1 \u2264 1 / I \u2194 I \u2264 1 :=\nbegin\n  split, all_goals {intro hI},\n  {rwa [le_div_iff_mul_le, one_mul] at hI},\n  {rwa [le_div_iff_mul_le, one_mul]},\nend\n\nlemma le_self_mul_one_div {I : submodule R A} (hI : I \u2264 1) :\n  I \u2264 I * (1 / I) :=\nbegin\n  rw [\u2190 mul_one I] {occs := occurrences.pos [1]},\n  apply mul_le_mul_right (one_le_one_div.mpr hI),\nend\n\nlemma mul_one_div_le_one {I : submodule R A} : I * (1 / I) \u2264 1 :=\nbegin\n  rw submodule.mul_le,\n  intros m hm n hn,\n  rw [submodule.mem_div_iff_forall_mul_mem] at hn,\n  rw mul_comm,\n  exact hn m hm,\nend\n\n@[simp] lemma map_div {B : Type*} [comm_ring B] [algebra R B]\n  (I J : submodule R A) (h : A \u2243\u2090[R] B) :\n  (I / J).map h.to_linear_map = I.map h.to_linear_map / J.map h.to_linear_map :=\nbegin\n  ext x,\n  simp only [mem_map, mem_div_iff_forall_mul_mem],\n  split,\n  { rintro \u27e8x, hx, rfl\u27e9 _ \u27e8y, hy, rfl\u27e9,\n    exact \u27e8x * y, hx _ hy, h.map_mul x y\u27e9 },\n  { rintro hx,\n    refine \u27e8h.symm x, \u03bb z hz, _, h.apply_symm_apply x\u27e9,\n    obtain \u27e8xz, xz_mem, hxz\u27e9 := hx (h z) \u27e8z, hz, rfl\u27e9,\n    convert xz_mem,\n    apply h.injective,\n    erw [h.map_mul, h.apply_symm_apply, hxz] }\nend\n\nend quotient\n\nend comm_ring\n\nend submodule\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/algebra/operations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.746868320688593}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura\n\nMatrices\n-/\nimport algebra.ring data.fin data.fintype\nopen fin nat\n\ndefinition matrix [reducible] (A : Type) (m n : nat) := fin m \u2192 fin n \u2192 A\n\nnamespace matrix\nvariables {A B C : Type} {m n p : nat}\n\ndefinition val [reducible] (M : matrix A m n) (i : fin m) (j : fin n) : A :=\nM i j\n\nnamespace ops\nnotation M `[` i `, ` j `]` := val M i j\nend ops\n\nopen ops\n\nprotected lemma ext {M N : matrix A m n} (h : \u2200 i j, M[i,j] = N[i, j]) : M = N :=\nfunext (\u03bb i, funext (\u03bb j, h i j))\n\nprotected lemma has_decidable_eq [h : decidable_eq A] (m n : nat) : decidable_eq (matrix A m n) :=\n_\n\ndefinition to_matrix (f : fin m \u2192 fin n \u2192 A) : matrix A m n :=\nf\n\ndefinition map (f : A \u2192 B) (M : matrix A m n) : matrix B m n :=\n\u03bb i j, f (M[i,j])\n\ndefinition map\u2082 (f : A \u2192 B \u2192 C) (M : matrix A m n) (N : matrix B m n) : matrix C m n :=\n\u03bb i j, f (M[i, j]) (N[i,j])\n\ndefinition transpose (M : matrix A m n) : matrix A n m :=\n\u03bb i j, M[j, i]\n\ndefinition symmetric (M : matrix A n n) :=\ntranspose M = M\n\nsection\nvariable [r : comm_ring A]\ninclude r\n\ndefinition identity (n : nat) : matrix A n n :=\n\u03bb i j, if i = j then 1 else 0\n\ndefinition I {n : nat} : matrix A n n :=\nidentity n\n\nprotected definition zero (m n : nat) : matrix A m n :=\n\u03bb i j, 0\n\nprotected definition add (M : matrix A m n) (N : matrix A m n) : matrix A m n :=\n\u03bb i j, M[i, j] + N[i, j]\n\nprotected definition sub (M : matrix A m n) (N : matrix A m n) : matrix A m n :=\n\u03bb i j, M[i, j] - N[i, j]\n\nprotected definition mul (M : matrix A m n) (N : matrix A n p) : matrix A m p :=\n\u03bb i j, fin.foldl has_add.add 0 (\u03bb k : fin n, M[i,k] * N[k,j])\n\ndefinition smul (a : A) (M : matrix A m n) : matrix A m n :=\n\u03bb i j, a * M[i, j]\n\ndefinition matrix_has_zero [instance] (m n : nat) : has_zero (matrix A m n) :=\nhas_zero.mk (matrix.zero m n)\n\ndefinition matrix_has_one [instance] (n : nat) : has_one (matrix A n n) :=\nhas_one.mk (identity n)\n\ndefinition matrix_has_add [instance] (m n : nat) : has_add (matrix A m n) :=\nhas_add.mk matrix.add\n\ndefinition matrix_has_mul [instance] (n : nat) : has_mul (matrix A n n) :=\nhas_mul.mk matrix.mul\n\ninfix ` \u00d7 ` := mul\ninfix `\u2b1d`    := smul\n\nprotected lemma add_zero (M : matrix A m n) : M + 0 = M :=\nmatrix.ext (\u03bb i j, !add_zero)\n\nprotected lemma zero_add (M : matrix A m n) : 0 + M = M :=\nmatrix.ext (\u03bb i j, !zero_add)\n\nprotected lemma add.comm (M : matrix A m n) (N : matrix A m n) : M + N = N + M :=\nmatrix.ext (\u03bb i j, !add.comm)\n\nprotected lemma add.assoc (M : matrix A m n) (N : matrix A m n) (P : matrix A m n) : (M + N) + P = M + (N + P) :=\nmatrix.ext (\u03bb i j, !add.assoc)\n\ndefinition is_diagonal (M : matrix A n n) :=\n\u2200 i j, i = j \u2228 M[i, j] = 0\n\ndefinition is_zero (M : matrix A m n) :=\n\u2200 i j, M[i, j] = 0\n\ndefinition is_upper_triangular (M : matrix A n n) :=\n\u2200 i j : fin n, i > j \u2192 M[i, j] = 0\n\ndefinition is_lower_triangular (M : matrix A n n) :=\n\u2200 i j : fin n, i < j \u2192 M[i, j] = 0\n\ndefinition inverse (M : matrix A n n) (N : matrix A n n) :=\nM * N = I \u2227 N * M = I\n\ndefinition invertible (M : matrix A n n) :=\n\u2203 N, inverse M N\n\nend\nend matrix\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.7468683202342783}}
{"text": "/-\n\nIn this file we will address how to deal with some examples from logic, namely and and or.\n\n-/\n\n/- Ignore this for now. But all imports are on the top of the file. -/\n-- import tactic.suggest\n/- Uncomment after reading the last note. -/\n\n\n\n/- Prove that p \u2227 q \u2192 p. It should be pretty straight-forward -/\n\ntheorem p_and_q_implies_p (p q:Prop):  \n    p \u2227 q \u2192 p :=\nbegin\n    intro proof_of_p_and_q,\n    exact proof_of_p_and_q.left, -- how did we know about this?\nend\n\n/-\n\nIf you delete \"left\" and ask for the autocomplete (cmd+space), you will not find left.\nSo how did we know that it was the solution?\n\nIf you cmd+click on the \u2227 symbol, you go to its definition and you can discover that it is\na structure (similar to a struct in C or records in Haskell). You can see that it is made of\ntwo fields: left and right. In this case, we use the one that is most useful for our proof.\n\n-/\n\n/- Prove that p \u2192 p \u2228 q -/\n\ntheorem p_implies_p_or_q (p q:Prop) : \n    p \u2192 p \u2228 q := \nbegin\n    intro proof_of_p,\n    left,\n    exact proof_of_p,\nend\n\n/-\nWhile there are other options, here we use the left (as opposed to the right) tactic.\nThese two tactics can be used to focus on the right or left side or an \u2228-goal. We only\nneed to prove one of the sides.\n-/\n\n\ntheorem q_implies_p_or_q_or_r (p q r :Prop) : \n    q \u2192 (p \u2228 q) \u2228 r := \nbegin\n    sorry, -- it is another exercice.\nend\n\n\ntheorem p_implies_p_or_not_p (p:Prop) : p \u2192 p \u2228 (\u00ac p) :=\nbegin\n    sorry, -- it is yet another exercice.\nend\n\n/-\n    For this last theorem, the structure will be very similar to p_implies_p_or_q. In\n    fact, too similar! Instead of copying the proof, you should use the existing theorems\n    and lemmas. Tip: despite not being in the shown context, every theorem and lemma can be\n    used in the context of proofs.\n\n-/\n\n\n\n/- This next example is interesting, because we cannot go left or right. We have\nto go both ways.\n\nThat can be done using induction on the structure of or. If calling it an induction bothers\nyou, you can replace \"induction\" with \"cases\", which works in the same way.\n\n -/\n\nexample (n:\u2115) : n = 3 \u2228 n = 4 \u2192 n = 4 \u2228 n = 3 :=\nbegin\n    intros or_3_4,\n    induction or_3_4,\n    {\n        right,\n        exact or_3_4,\n    },\n    {\n        left,\n        exact or_3_4,\n    }\nend\n\n\n/-\n\nMy main complaints writing proofs was that I had to dive into the source code of\nlean standard library looking for lemmas that would solve my problem, without knowing its name.\n\nThis example should be trivial to solve, if we have a theorem that shows that \u2228 is commutative.\n\nLet's use the \"library_search\" tactic, imported from \"tactic.suggest\" on the top of this file,\nwhich you need to uncomment. Notice that it solves the goal, but has a blue wavy underline under \nit. Library_search is useful when writing proofs, but does not serve as a proof that others can \nread. Visual Studio Code shows a shortcut on the right to replace library_search with the found\nlemma. The code shown below is the found tactic. Feel free to replace it and try library_search.\n\n\nNote: library_search does not come with the lean standard library, and does not work on the webbrowser.\nThis tactic comes with the mathlib library, which you can install following the instructions on the Readme.\n\n-/\n\nexample (n:\u2115) : n = 3 \u2228 n = 4 \u2192 n = 4 \u2228 n = 3 :=\nbegin\n    exact or.swap,\nend", "meta": {"author": "alcides", "repo": "lean3_tutorial", "sha": "7a871e00c4fd5cb000929a59e1bd804a626ef277", "save_path": "github-repos/lean/alcides-lean3_tutorial", "path": "github-repos/lean/alcides-lean3_tutorial/lean3_tutorial-7a871e00c4fd5cb000929a59e1bd804a626ef277/src/04_fol.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7468683183793134}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport number_theory.zsqrtd.basic\nimport data.complex.basic\nimport ring_theory.principal_ideal_domain\nimport number_theory.legendre_symbol.quadratic_reciprocity\n/-!\n# Gaussian integers\n\nThe Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both\nintegers.\n\n## Main definitions\n\nThe Euclidean domain structure on `\u2124[i]` is defined in this file.\n\nThe homomorphism `to_complex` into the complex numbers is also defined in this file.\n\n## Main statements\n\n`prime_iff_mod_four_eq_three_of_nat_prime`\nA prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4`\n\n## Notations\n\nThis file uses the local notation `\u2124[i]` for `gaussian_int`\n\n## Implementation notes\n\nGaussian integers are implemented using the more general definition `zsqrtd`, the type of integers\nadjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties\nand definitions about `zsqrtd` can easily be used.\n-/\n\nopen zsqrtd complex\n\n/-- The Gaussian integers, defined as `\u2124\u221a(-1)`. -/\n@[reducible] def gaussian_int : Type := zsqrtd (-1)\n\nlocal notation `\u2124[i]` := gaussian_int\n\nnamespace gaussian_int\n\ninstance : has_repr \u2124[i] := \u27e8\u03bb x, \"\u27e8\" ++ repr x.re ++ \", \" ++ repr x.im ++ \"\u27e9\"\u27e9\n\ninstance : comm_ring \u2124[i] := zsqrtd.comm_ring\n\nsection\nlocal attribute [-instance] complex.field -- Avoid making things noncomputable unnecessarily.\n\n/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/\ndef to_complex : \u2124[i] \u2192+* \u2102 :=\nzsqrtd.lift \u27e8I, by simp\u27e9\nend\n\ninstance : has_coe (\u2124[i]) \u2102 := \u27e8to_complex\u27e9\n\nlemma to_complex_def (x : \u2124[i]) : (x : \u2102) = x.re + x.im * I := rfl\n\nlemma to_complex_def' (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102) = x + y * I := by simp [to_complex_def]\n\nlemma to_complex_def\u2082 (x : \u2124[i]) : (x : \u2102) = \u27e8x.re, x.im\u27e9 :=\nby apply complex.ext; simp [to_complex_def]\n\n@[simp] lemma to_real_re (x : \u2124[i]) : ((x.re : \u2124) : \u211d) = (x : \u2102).re := by simp [to_complex_def]\n@[simp] lemma to_real_im (x : \u2124[i]) : ((x.im : \u2124) : \u211d) = (x : \u2102).im := by simp [to_complex_def]\n@[simp] lemma to_complex_re (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).re = x := by simp [to_complex_def]\n@[simp] lemma to_complex_im (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).im = y := by simp [to_complex_def]\n@[simp] lemma to_complex_add (x y : \u2124[i]) : ((x + y : \u2124[i]) : \u2102) = x + y := to_complex.map_add _ _\n@[simp] lemma to_complex_mul (x y : \u2124[i]) : ((x * y : \u2124[i]) : \u2102) = x * y := to_complex.map_mul _ _\n@[simp] lemma to_complex_one : ((1 : \u2124[i]) : \u2102) = 1 := to_complex.map_one\n@[simp] lemma to_complex_zero : ((0 : \u2124[i]) : \u2102) = 0 := to_complex.map_zero\n@[simp] lemma to_complex_neg (x : \u2124[i]) : ((-x : \u2124[i]) : \u2102) = -x := to_complex.map_neg _\n@[simp] lemma to_complex_sub (x y : \u2124[i]) : ((x - y : \u2124[i]) : \u2102) = x - y := to_complex.map_sub _ _\n\n@[simp] lemma to_complex_inj {x y : \u2124[i]} : (x : \u2102) = y \u2194 x = y :=\nby cases x; cases y; simp [to_complex_def\u2082]\n\n@[simp] lemma to_complex_eq_zero {x : \u2124[i]} : (x : \u2102) = 0 \u2194 x = 0 :=\nby rw [\u2190 to_complex_zero, to_complex_inj]\n\n@[simp] lemma nat_cast_real_norm (x : \u2124[i]) : (x.norm : \u211d) = (x : \u2102).norm_sq :=\nby rw [norm, norm_sq]; simp\n\n@[simp] lemma nat_cast_complex_norm (x : \u2124[i]) : (x.norm : \u2102) = (x : \u2102).norm_sq :=\nby cases x; rw [norm, norm_sq]; simp\n\nlemma norm_nonneg (x : \u2124[i]) : 0 \u2264 norm x := norm_nonneg (by norm_num) _\n\n@[simp] lemma norm_eq_zero {x : \u2124[i]} : norm x = 0 \u2194 x = 0 :=\nby rw [\u2190 @int.cast_inj \u211d _ _ _]; simp\n\nlemma norm_pos {x : \u2124[i]} : 0 < norm x \u2194 x \u2260 0 :=\nby rw [lt_iff_le_and_ne, ne.def, eq_comm, norm_eq_zero]; simp [norm_nonneg]\n\nlemma coe_nat_abs_norm (x : \u2124[i]) : (x.norm.nat_abs : \u2124) = x.norm :=\nint.nat_abs_of_nonneg (norm_nonneg _)\n\n@[simp] lemma nat_cast_nat_abs_norm {\u03b1 : Type*} [ring \u03b1]\n  (x : \u2124[i]) : (x.norm.nat_abs : \u03b1) = x.norm :=\nby rw [\u2190 int.cast_coe_nat, coe_nat_abs_norm]\n\nlemma nat_abs_norm_eq (x : \u2124[i]) : x.norm.nat_abs =\n  x.re.nat_abs * x.re.nat_abs + x.im.nat_abs * x.im.nat_abs :=\nint.coe_nat_inj $ begin simp, simp [norm] end\n\ninstance : has_div \u2124[i] :=\n\u27e8\u03bb x y, let n := (rat.of_int (norm y))\u207b\u00b9, c := y.conj in\n  \u27e8round (rat.of_int (x * c).re * n : \u211a), round (rat.of_int (x * c).im * n : \u211a)\u27e9\u27e9\n\nlemma div_def (x y : \u2124[i]) : x / y = \u27e8round ((x * conj y).re / norm y : \u211a),\n  round ((x * conj y).im / norm y : \u211a)\u27e9 :=\nshow zsqrtd.mk _ _ = _, by simp [rat.of_int_eq_mk, rat.mk_eq_div, div_eq_mul_inv]\n\nlemma to_complex_div_re (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).re = round ((x / y : \u2102).re) :=\nby rw [div_def, \u2190 @rat.round_cast \u211d _ _];\n  simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlemma to_complex_div_im (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).im = round ((x / y : \u2102).im) :=\nby rw [div_def, \u2190 @rat.round_cast \u211d _ _, \u2190 @rat.round_cast \u211d _ _];\n  simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlemma norm_sq_le_norm_sq_of_re_le_of_im_le {x y : \u2102} (hre : |x.re| \u2264 |y.re|)\n  (him : |x.im| \u2264 |y.im|) : x.norm_sq \u2264 y.norm_sq :=\nby rw [norm_sq_apply, norm_sq_apply, \u2190 _root_.abs_mul_self, _root_.abs_mul,\n  \u2190 _root_.abs_mul_self y.re, _root_.abs_mul y.re,\n  \u2190 _root_.abs_mul_self x.im, _root_.abs_mul x.im,\n  \u2190 _root_.abs_mul_self y.im, _root_.abs_mul y.im]; exact\n(add_le_add (mul_self_le_mul_self (abs_nonneg _) hre)\n  (mul_self_le_mul_self (abs_nonneg _) him))\n\nlemma norm_sq_div_sub_div_lt_one (x y : \u2124[i]) :\n  ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq < 1 :=\ncalc ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq =\n    ((x / y : \u2102).re - ((x / y : \u2124[i]) : \u2102).re +\n    ((x / y : \u2102).im - ((x / y : \u2124[i]) : \u2102).im) * I : \u2102).norm_sq :\n      congr_arg _ $ by apply complex.ext; simp\n  ... \u2264 (1 / 2 + 1 / 2 * I).norm_sq :\n  have |(2\u207b\u00b9 : \u211d)| = 2\u207b\u00b9, from _root_.abs_of_nonneg (by norm_num),\n  norm_sq_le_norm_sq_of_re_le_of_im_le\n    (by rw [to_complex_div_re]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).re)\n    (by rw [to_complex_div_im]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).im)\n  ... < 1 : by simp [norm_sq]; norm_num\n\ninstance : has_mod \u2124[i] := \u27e8\u03bb x y, x - y * (x / y)\u27e9\n\nlemma mod_def (x y : \u2124[i]) : x % y = x - y * (x / y) := rfl\n\nlemma norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) : (x % y).norm < y.norm :=\nhave (y : \u2102) \u2260 0, by rwa [ne.def, \u2190 to_complex_zero, to_complex_inj],\n(@int.cast_lt \u211d _ _ _ _).1 $\n  calc \u2191(norm (x % y)) = (x - y * (x / y : \u2124[i]) : \u2102).norm_sq : by simp [mod_def]\n  ... = (y : \u2102).norm_sq * (((x / y) - (x / y : \u2124[i])) : \u2102).norm_sq :\n    by rw [\u2190 norm_sq_mul, mul_sub, mul_div_cancel' _ this]\n  ... < (y : \u2102).norm_sq * 1 : mul_lt_mul_of_pos_left (norm_sq_div_sub_div_lt_one _ _)\n    (norm_sq_pos.2 this)\n  ... = norm y : by simp\n\nlemma nat_abs_norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (x % y).norm.nat_abs < y.norm.nat_abs :=\nint.coe_nat_lt.1 (by simp [-int.coe_nat_lt, norm_mod_lt x hy])\n\nlemma norm_le_norm_mul_left (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (norm x).nat_abs \u2264 (norm (x * y)).nat_abs :=\nby rw [norm_mul, int.nat_abs_mul];\n  exact le_mul_of_one_le_right (nat.zero_le _)\n    (int.coe_nat_le.1 (by rw [coe_nat_abs_norm]; exact int.add_one_le_of_lt (norm_pos.2 hy)))\n\ninstance : nontrivial \u2124[i] :=\n\u27e8\u27e80, 1, dec_trivial\u27e9\u27e9\n\ninstance : euclidean_domain \u2124[i] :=\n{ quotient := (/),\n  remainder := (%),\n  quotient_zero := by { simp [div_def], refl },\n  quotient_mul_add_remainder_eq := \u03bb _ _, by simp [mod_def],\n  r := _,\n  r_well_founded := measure_wf (int.nat_abs \u2218 norm),\n  remainder_lt := nat_abs_norm_mod_lt,\n  mul_left_not_lt := \u03bb a b hb0, not_lt_of_ge $ norm_le_norm_mul_left a hb0,\n  .. gaussian_int.comm_ring,\n  .. gaussian_int.nontrivial }\n\nopen principal_ideal_ring\n\nlemma mod_four_eq_three_of_nat_prime_of_prime (p : \u2115) [hp : fact p.prime] (hpi : prime (p : \u2124[i])) :\n  p % 4 = 3 :=\nhp.1.eq_two_or_odd.elim\n  (\u03bb hp2, absurd hpi (mt irreducible_iff_prime.2 $\n    \u03bb \u27e8hu, h\u27e9, begin\n      have := h \u27e81, 1\u27e9 \u27e81, -1\u27e9 (hp2.symm \u25b8 rfl),\n      rw [\u2190 norm_eq_one_iff, \u2190 norm_eq_one_iff] at this,\n      exact absurd this dec_trivial\n    end))\n  (\u03bb hp1, by_contradiction $ \u03bb hp3 : p % 4 \u2260 3,\n    have hp41 : p % 4 = 1,\n      begin\n        rw [\u2190 nat.mod_mul_left_mod p 2 2, show 2 * 2 = 4, from rfl] at hp1,\n        have := nat.mod_lt p (show 0 < 4, from dec_trivial),\n        revert this hp3 hp1,\n        generalize : p % 4 = m, dec_trivial!,\n      end,\n    let \u27e8k, hk\u27e9 := (zmod.exists_sq_eq_neg_one_iff p).2 $\n      by rw hp41; exact dec_trivial in\n    begin\n      obtain \u27e8k, k_lt_p, rfl\u27e9 : \u2203 (k' : \u2115) (h : k' < p), (k' : zmod p) = k,\n      { refine \u27e8k.val, k.val_lt, zmod.nat_cast_zmod_val k\u27e9 },\n      have hpk : p \u2223 k ^ 2 + 1,\n        by { rw [pow_two, \u2190 char_p.cast_eq_zero_iff (zmod p) p, nat.cast_add, nat.cast_mul,\n                 nat.cast_one, \u2190 hk, add_left_neg], },\n      have hkmul : (k ^ 2 + 1 : \u2124[i]) = \u27e8k, 1\u27e9 * \u27e8k, -1\u27e9 :=\n        by simp [sq, zsqrtd.ext],\n      have hpne1 : p \u2260 1 := ne_of_gt hp.1.one_lt,\n      have hkltp : 1 + k * k < p * p,\n        from calc 1 + k * k \u2264 k + k * k :\n          add_le_add_right (nat.pos_of_ne_zero\n            (\u03bb hk0, by clear_aux_decl; simp [*, pow_succ'] at *)) _\n        ... = k * (k + 1) : by simp [add_comm, mul_add]\n        ... < p * p : mul_lt_mul k_lt_p k_lt_p (nat.succ_pos _) (nat.zero_le _),\n      have hpk\u2081 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, -1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (norm \u27e8k, -1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (-1 : \u2124) \u2260 0, from dec_trivial) $\n              by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpk\u2082 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, 1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (norm \u27e8k, 1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (1 : \u2124) \u2260 0, from dec_trivial) $\n                by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2\n        (by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n        exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1),\n      obtain \u27e8y, hy\u27e9 := hpk,\n      have := hpi.2.2 \u27e8k, 1\u27e9 \u27e8k, -1\u27e9 \u27e8y, by rw [\u2190 hkmul, \u2190 nat.cast_mul p, \u2190 hy]; simp\u27e9,\n      clear_aux_decl, tauto\n    end)\n\nlemma sq_add_sq_of_nat_prime_of_not_irreducible (p : \u2115) [hp : fact p.prime]\n  (hpi : \u00acirreducible (p : \u2124[i])) : \u2203 a b, a^2 + b^2 = p :=\nhave hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2 $\n  by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n    exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1,\nhave hab : \u2203 a b, (p : \u2124[i]) = a * b \u2227 \u00ac is_unit a \u2227 \u00ac is_unit b,\n  by simpa [irreducible_iff, hpu, not_forall, not_or_distrib] using hpi,\nlet \u27e8a, b, hpab, hau, hbu\u27e9 := hab in\nhave hnap : (norm a).nat_abs = p, from ((hp.1.mul_eq_prime_sq_iff\n    (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 $\n  by rw [\u2190 int.coe_nat_inj', int.coe_nat_pow, sq,\n    \u2190 @norm_nat_cast (-1), hpab];\n    simp).1,\n\u27e8a.re.nat_abs, a.im.nat_abs, by simpa [nat_abs_norm_eq, sq] using hnap\u27e9\n\nlemma prime_of_nat_prime_of_mod_four_eq_three (p : \u2115) [hp : fact p.prime] (hp3 : p % 4 = 3) :\n  prime (p : \u2124[i]) :=\nirreducible_iff_prime.1 $ classical.by_contradiction $ \u03bb hpi,\n  let \u27e8a, b, hab\u27e9 := sq_add_sq_of_nat_prime_of_not_irreducible p hpi in\nhave \u2200 a b : zmod 4, a^2 + b^2 \u2260 p, by erw [\u2190 zmod.nat_cast_mod p 4, hp3]; exact dec_trivial,\nthis a b (hab \u25b8 by simp)\n\n/-- A prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4` -/\nlemma prime_iff_mod_four_eq_three_of_nat_prime (p : \u2115) [hp : fact p.prime] :\n  prime (p : \u2124[i]) \u2194 p % 4 = 3 :=\n\u27e8mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p\u27e9\n\nend gaussian_int\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/number_theory/zsqrtd/gaussian_int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7468683169786635}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport ring_theory.polynomial.bernstein\nimport topology.continuous_function.polynomial\n\n/-!\n# Bernstein approximations and Weierstrass' theorem\n\nWe prove that the Bernstein approximations\n```\n\u2211 k : fin (n+1), f (k/n : \u211d) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], \u211d)` converge uniformly to `f` as `n` tends to infinity.\n\nOur proof follows [Richard Beals' *Analysis, an introduction*][beals-analysis], \u00a77D.\nThe original proof, due to [Bernstein](bernstein1912) in 1912, is probabilistic,\nand relies on Bernoulli's theorem,\nwhich gives bounds for how quickly the observed frequencies in a\nBernoulli trial approach the underlying probability.\n\nThe proof here does not directly rely on Bernoulli's theorem,\nbut can also be given a probabilistic account.\n* Consider a weighted coin which with probability `x` produces heads,\n  and with probability `1-x` produces tails.\n* The value of `bernstein n k x` is the probability that\n  such a coin gives exactly `k` heads in a sequence of `n` tosses.\n* If such an appearance of `k` heads results in a payoff of `f(k / n)`,\n  the `n`-th Bernstein approximation for `f` evaluated at `x` is the expected payoff.\n* The main estimate in the proof bounds the probability that\n  the observed frequency of heads differs from `x` by more than some `\u03b4`,\n  obtaining a bound of `(4 * n * \u03b4^2)\u207b\u00b9`, irrespective of `x`.\n* This ensures that for `n` large, the Bernstein approximation is (uniformly) close to the\n  payoff function `f`.\n\n(You don't need to think in these terms to follow the proof below: it's a giant `calc` block!)\n\nThis result proves Weierstrass' theorem that polynomials are dense in `C([0,1], \u211d)`,\nalthough we defer an abstract statement of this until later.\n-/\n\nnoncomputable theory\n\nopen_locale classical\nopen_locale big_operators\nopen_locale bounded_continuous_function\nopen_locale unit_interval\n\n/--\nThe Bernstein polynomials, as continuous functions on `[0,1]`.\n-/\ndef bernstein (n \u03bd : \u2115) : C(I, \u211d) :=\n(bernstein_polynomial \u211d n \u03bd).to_continuous_map_on I\n\n@[simp] lemma bernstein_apply (n \u03bd : \u2115) (x : I) :\n  bernstein n \u03bd x = n.choose \u03bd * x^\u03bd * (1-x)^(n-\u03bd) :=\nbegin\n  dsimp [bernstein, polynomial.to_continuous_map_on, polynomial.to_continuous_map,\n    bernstein_polynomial],\n  simp,\nend\n\nlemma bernstein_nonneg {n \u03bd : \u2115} {x : I} :\n  0 \u2264 bernstein n \u03bd x :=\nbegin\n  simp only [bernstein_apply],\n  exact mul_nonneg\n    (mul_nonneg (nat.cast_nonneg _) (pow_nonneg (by unit_interval) _))\n    (pow_nonneg (by unit_interval) _),\nend\n\n/-!\nWe now give a slight reformulation of `bernstein_polynomial.variance`.\n-/\n\nnamespace bernstein\n\n/--\nSend `k : fin (n+1)` to the equally spaced points `k/n` in the unit interval.\n-/\ndef z {n : \u2115} (k : fin (n+1)) : I :=\n\u27e8(k : \u211d) / n,\n  begin\n    cases n,\n    { norm_num },\n    { have h\u2081 : 0 < (n.succ : \u211d) := by exact_mod_cast (nat.succ_pos _),\n      have h\u2082 : \u2191k \u2264 n.succ := by exact_mod_cast (fin.le_last k),\n      rw [set.mem_Icc, le_div_iff h\u2081, div_le_iff h\u2081],\n      norm_cast,\n      simp [h\u2082], },\n  end\u27e9\n\nlocal postfix `/\u2099`:90 := z\n\nlemma probability (n : \u2115) (x : I) :\n  \u2211 k : fin (n+1), bernstein n k x = 1 :=\nbegin\n  have := bernstein_polynomial.sum \u211d n,\n  apply_fun (\u03bb p, polynomial.aeval (x : \u211d) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range] at this,\n  exact this,\nend\n\nlemma variance {n : \u2115} (h : 0 < (n : \u211d)) (x : I) :\n  \u2211 k : fin (n+1), (x - k/\u2099 : \u211d)^2 * bernstein n k x = x * (1-x) / n :=\nbegin\n  have h' : (n : \u211d) \u2260 0 := ne_of_gt h,\n  apply_fun (\u03bb x : \u211d, x * n) using group_with_zero.mul_right_injective h',\n  apply_fun (\u03bb x : \u211d, x * n) using group_with_zero.mul_right_injective h',\n  dsimp,\n  conv_lhs { simp only [finset.sum_mul, z], },\n  conv_rhs { rw div_mul_cancel _ h', },\n  have := bernstein_polynomial.variance \u211d n,\n  apply_fun (\u03bb p, polynomial.aeval (x : \u211d) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range, \u2190polynomial.nat_cast_mul] at this,\n  convert this using 1,\n  { congr' 1, funext k,\n    rw [mul_comm _ (n : \u211d), mul_comm _ (n : \u211d), \u2190mul_assoc, \u2190mul_assoc],\n    congr' 1,\n    field_simp [h],\n    ring, },\n  { ring, },\nend\n\nend bernstein\n\nopen bernstein\n\nlocal postfix `/\u2099`:2000 := z\n\n/--\nThe `n`-th approximation of a continuous function on `[0,1]` by Bernstein polynomials,\ngiven by `\u2211 k, f (k/n) * bernstein n k x`.\n-/\ndef bernstein_approximation (n : \u2115) (f : C(I, \u211d)) : C(I, \u211d) :=\n\u2211 k : fin (n+1), f k/\u2099 \u2022 bernstein n k\n\n/-!\nWe now set up some of the basic machinery of the proof that the Bernstein approximations\nconverge uniformly.\n\nA key player is the set `S f \u03b5 h n x`,\nfor some function `f : C(I, \u211d)`, `h : 0 < \u03b5`, `n : \u2115` and `x : I`.\n\nThis is the set of points `k` in `fin (n+1)` such that\n`k/n` is within `\u03b4` of `x`, where `\u03b4` is the modulus of uniform continuity for `f`,\nchosen so `|f x - f y| < \u03b5/2` when `|x - y| < \u03b4`.\n\nWe show that if `k \u2209 S`, then `1 \u2264 \u03b4^-2 * (x - k/n)^2`.\n-/\n\nnamespace bernstein_approximation\n\n@[simp] lemma apply (n : \u2115) (f : C(I, \u211d)) (x : I) :\n  bernstein_approximation n f x = \u2211 k : fin (n+1), f k/\u2099 * bernstein n k x :=\nby simp [bernstein_approximation]\n\n/--\nThe modulus of (uniform) continuity for `f`, chosen so `|f x - f y| < \u03b5/2` when `|x - y| < \u03b4`.\n-/\ndef \u03b4 (f : C(I, \u211d)) (\u03b5 : \u211d) (h : 0 < \u03b5) : \u211d := f.modulus (\u03b5/2) (half_pos h)\n\n/--\nThe set of points `k` so `k/n` is within `\u03b4` of `x`.\n-/\ndef S (f : C(I, \u211d)) (\u03b5 : \u211d) (h : 0 < \u03b5) (n : \u2115) (x : I) : finset (fin (n+1)) :=\n{ k : fin (n+1) | dist k/\u2099 x < \u03b4 f \u03b5 h }.to_finset\n\n/--\nIf `k \u2208 S`, then `f(k/n)` is close to `f x`.\n-/\nlemma lt_of_mem_S\n  {f : C(I, \u211d)} {\u03b5 : \u211d} {h : 0 < \u03b5} {n : \u2115} {x : I} {k : fin (n+1)} (m : k \u2208 S f \u03b5 h n x) :\n  |f k/\u2099 - f x| < \u03b5/2 :=\nbegin\n  apply f.dist_lt_of_dist_lt_modulus (\u03b5/2) (half_pos h),\n  simpa [S] using m,\nend\n\n/--\nIf `k \u2209 S`, then as `\u03b4 \u2264 |x - k/n|`, we have the inequality `1 \u2264 \u03b4^-2 * (x - k/n)^2`.\nThis particular formulation will be helpful later.\n-/\nlemma le_of_mem_S_compl\n  {f : C(I, \u211d)} {\u03b5 : \u211d} {h : 0 < \u03b5} {n : \u2115} {x : I} {k : fin (n+1)} (m : k \u2208 (S f \u03b5 h n x)\u1d9c) :\n  (1 : \u211d) \u2264 (\u03b4 f \u03b5 h)^(-2 : \u2124) * (x - k/\u2099) ^ 2 :=\nbegin\n  simp only [finset.mem_compl, not_lt, set.mem_to_finset, set.mem_set_of_eq, S] at m,\n  field_simp,\n  erw [le_div_iff (pow_pos f.modulus_pos 2), one_mul],\n  apply sq_le_sq,\n  rw abs_eq_self.mpr (le_of_lt f.modulus_pos),\n  rw [dist_comm] at m,\n  exact m,\nend\n\nend bernstein_approximation\n\nopen bernstein_approximation\nopen bounded_continuous_function\nopen filter\n\nopen_locale topological_space\n\n/--\nThe Bernstein approximations\n```\n\u2211 k : fin (n+1), f (k/n : \u211d) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], \u211d)` converge uniformly to `f` as `n` tends to infinity.\n\nThis is the proof given in [Richard Beals' *Analysis, an introduction*][beals-analysis], \u00a77D,\nand reproduced on wikipedia.\n-/\ntheorem bernstein_approximation_uniform (f : C(I, \u211d)) :\n  tendsto (\u03bb n : \u2115, bernstein_approximation n f) at_top (\ud835\udcdd f) :=\nbegin\n  simp only [metric.nhds_basis_ball.tendsto_right_iff, metric.mem_ball, dist_eq_norm],\n  intros \u03b5 h,\n  let \u03b4 := \u03b4 f \u03b5 h,\n  have nhds_zero := tendsto_const_div_at_top_nhds_0_nat (2 * \u2225f\u2225 * \u03b4 ^ (-2 : \u2124)),\n  filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_at_top 0],\n  intros n nh npos',\n  have npos : 0 < (n:\u211d) := by exact_mod_cast npos',\n  -- Two easy inequalities we'll need later:\n  have w\u2081 : 0 \u2264 2 * \u2225f\u2225 := mul_nonneg (by norm_num) (norm_nonneg f),\n  have w\u2082 : 0 \u2264 2 * \u2225f\u2225 * \u03b4^(-2 : \u2124) := mul_nonneg w\u2081 pow_minus_two_nonneg,\n  -- As `[0,1]` is compact, it suffices to check the inequality pointwise.\n  rw (continuous_map.norm_lt_iff _ h),\n  intro x,\n  -- The idea is to split up the sum over `k` into two sets,\n  -- `S`, where `x - k/n < \u03b4`, and its complement.\n  let S := S f \u03b5 h n x,\n  calc\n    |(bernstein_approximation n f - f) x|\n        = |bernstein_approximation n f x - f x|\n                              : rfl\n    ... = |bernstein_approximation n f x - f x * 1|\n                              : by rw mul_one\n    ... = |bernstein_approximation n f x - f x * (\u2211 k : fin (n+1), bernstein n k x)|\n                              : by rw bernstein.probability\n    ... = |\u2211 k : fin (n+1), (f k/\u2099 - f x) * bernstein n k x|\n                              : by simp [bernstein_approximation, finset.mul_sum, sub_mul]\n    ... \u2264 \u2211 k : fin (n+1), |(f k/\u2099 - f x) * bernstein n k x|\n                              : finset.abs_sum_le_sum_abs _ _\n    ... = \u2211 k : fin (n+1), |f k/\u2099 - f x| * bernstein n k x\n                              : by simp_rw [abs_mul, abs_eq_self.mpr bernstein_nonneg]\n    ... = \u2211 k in S, |f k/\u2099 - f x| * bernstein n k x +\n          \u2211 k in S\u1d9c, |f k/\u2099 - f x| * bernstein n k x\n                              : (S.sum_add_sum_compl _).symm\n    -- We'll now deal with the terms in `S` and the terms in `S\u1d9c` in separate calc blocks.\n    ... < \u03b5/2 + \u03b5/2 : add_lt_add_of_le_of_lt _ _\n    ... = \u03b5 : add_halves \u03b5,\n    { -- We now work on the terms in `S`: uniform continuity and `bernstein.probability`\n      -- quickly give us a bound.\n      calc \u2211 k in S, |f k/\u2099 - f x| * bernstein n k x\n          \u2264 \u2211 k in S, \u03b5/2 * bernstein n k x\n                                :  finset.sum_le_sum\n                                    (\u03bb k m, (mul_le_mul_of_nonneg_right (le_of_lt (lt_of_mem_S m))\n                                      bernstein_nonneg))\n      ... = \u03b5/2 * \u2211 k in S, bernstein n k x\n                                : by rw finset.mul_sum\n      -- In this step we increase the sum over `S` back to a sum over all of `fin (n+1)`,\n      -- so that we can use `bernstein.probability`.\n      ... \u2264 \u03b5/2 * \u2211 k : fin (n+1), bernstein n k x\n                                : mul_le_mul_of_nonneg_left\n                                    (finset.sum_le_univ_sum_of_nonneg (\u03bb k, bernstein_nonneg))\n                                    (le_of_lt (half_pos h))\n      ... = \u03b5/2 : by rw [bernstein.probability, mul_one] },\n      { -- We now turn to working on `S\u1d9c`: we control the difference term just using `\u2225f\u2225`,\n        -- and then insert a `\u03b4^(-2) * (x - k/n)^2` factor\n        -- (which is at least one because we are not in `S`).\n        calc \u2211 k in S\u1d9c, |f k/\u2099 - f x| * bernstein n k x\n            \u2264 \u2211 k in S\u1d9c, (2 * \u2225f\u2225) * bernstein n k x\n                                  : finset.sum_le_sum\n                                      (\u03bb k m, mul_le_mul_of_nonneg_right (f.dist_le_two_norm _ _)\n                                        bernstein_nonneg)\n        ... = (2 * \u2225f\u2225) * \u2211 k in S\u1d9c, bernstein n k x\n                                  : by rw finset.mul_sum\n        ... \u2264 (2 * \u2225f\u2225) * \u2211 k in S\u1d9c, \u03b4^(-2 : \u2124) * (x - k/\u2099)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_sum (\u03bb k m, begin\n                                        conv_lhs { rw \u2190one_mul (bernstein _ _ _), },\n                                        exact mul_le_mul_of_nonneg_right\n                                          (le_of_mem_S_compl m) bernstein_nonneg,\n                                      end)) w\u2081\n        -- Again enlarging the sum from `S\u1d9c` to all of `fin (n+1)`\n        ... \u2264 (2 * \u2225f\u2225) * \u2211 k : fin (n+1), \u03b4^(-2 : \u2124) * (x - k/\u2099)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_univ_sum_of_nonneg\n                                        (\u03bb k, mul_nonneg\n                                          (mul_nonneg pow_minus_two_nonneg (sq_nonneg _))\n                                          bernstein_nonneg)) w\u2081\n        ... = (2 * \u2225f\u2225) * \u03b4^(-2 : \u2124) * \u2211 k : fin (n+1), (x - k/\u2099)^2 * bernstein n k x\n                                  : by conv_rhs\n                                    { rw [mul_assoc, finset.mul_sum], simp only [\u2190mul_assoc], }\n        -- `bernstein.variance` and `x \u2208 [0,1]` gives the uniform bound\n        ... = (2 * \u2225f\u2225) * \u03b4^(-2 : \u2124) * x * (1-x) / n\n                                  : by { rw variance npos, ring, }\n        ... \u2264 (2 * \u2225f\u2225) * \u03b4^(-2 : \u2124) / n\n                                  : (div_le_div_right npos).mpr\n                                    begin\n                                      apply mul_nonneg_le_one_le w\u2082,\n                                      apply mul_nonneg_le_one_le w\u2082 (le_refl _),\n                                      all_goals { unit_interval, },\n                                    end\n        ... < \u03b5/2 : nh, }\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/special_functions/bernstein.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7468683123223984}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n\n! This file was ported from Lean 3 source module set_theory.game.ordinal\n! leanprover-community/mathlib commit b90e72c7eebbe8de7c8293a80208ea2ba135c834\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.SetTheory.Game.Basic\nimport Mathbin.SetTheory.Ordinal.NaturalOps\n\n/-!\n# Ordinals as games\n\nWe define the canonical map `ordinal \u2192 pgame`, where every ordinal is mapped to the game whose left\nset consists of all previous ordinals.\n\nThe map to surreals is defined in `ordinal.to_surreal`.\n\n# Main declarations\n\n- `ordinal.to_pgame`: The canonical map between ordinals and pre-games.\n- `ordinal.to_pgame_embedding`: The order embedding version of the previous map.\n-/\n\n\nuniverse u\n\nopen Pgame\n\nopen NaturalOps Pgame\n\nnamespace Ordinal\n\n/-- Converts an ordinal into the corresponding pre-game. -/\nnoncomputable def toPgame : Ordinal.{u} \u2192 Pgame.{u}\n  | o =>\n    \u27e8o.out.\u03b1, PEmpty, fun x =>\n      let hwf := Ordinal.typein_lt_self x\n      (typein (\u00b7 < \u00b7) x).toPgame,\n      PEmpty.elim\u27e9\n#align ordinal.to_pgame Ordinal.toPgame\n\ntheorem toPgame_def (o : Ordinal) :\n    o.toPgame = \u27e8o.out.\u03b1, PEmpty, fun x => (typein (\u00b7 < \u00b7) x).toPgame, PEmpty.elim\u27e9 := by\n  rw [to_pgame]\n#align ordinal.to_pgame_def Ordinal.toPgame_def\n\n@[simp]\ntheorem toPgame_leftMoves (o : Ordinal) : o.toPgame.LeftMoves = o.out.\u03b1 := by\n  rw [to_pgame, left_moves]\n#align ordinal.to_pgame_left_moves Ordinal.toPgame_leftMoves\n\n@[simp]\ntheorem toPgame_rightMoves (o : Ordinal) : o.toPgame.RightMoves = PEmpty := by\n  rw [to_pgame, right_moves]\n#align ordinal.to_pgame_right_moves Ordinal.toPgame_rightMoves\n\ninstance isEmpty_zero_toPgame_leftMoves : IsEmpty (toPgame 0).LeftMoves :=\n  by\n  rw [to_pgame_left_moves]\n  infer_instance\n#align ordinal.is_empty_zero_to_pgame_left_moves Ordinal.isEmpty_zero_toPgame_leftMoves\n\ninstance isEmpty_toPgame_rightMoves (o : Ordinal) : IsEmpty o.toPgame.RightMoves :=\n  by\n  rw [to_pgame_right_moves]\n  infer_instance\n#align ordinal.is_empty_to_pgame_right_moves Ordinal.isEmpty_toPgame_rightMoves\n\n/-- Converts an ordinal less than `o` into a move for the `pgame` corresponding to `o`, and vice\nversa. -/\nnoncomputable def toLeftMovesToPgame {o : Ordinal} : Set.Iio o \u2243 o.toPgame.LeftMoves :=\n  (enumIsoOut o).toEquiv.trans (Equiv.cast (toPgame_leftMoves o).symm)\n#align ordinal.to_left_moves_to_pgame Ordinal.toLeftMovesToPgame\n\n@[simp]\ntheorem toLeftMovesToPgame_symm_lt {o : Ordinal} (i : o.toPgame.LeftMoves) :\n    \u2191(toLeftMovesToPgame.symm i) < o :=\n  (toLeftMovesToPgame.symm i).Prop\n#align ordinal.to_left_moves_to_pgame_symm_lt Ordinal.toLeftMovesToPgame_symm_lt\n\ntheorem toPgame_moveLeft_hEq {o : Ordinal} :\n    HEq o.toPgame.moveLeft fun x : o.out.\u03b1 => (typein (\u00b7 < \u00b7) x).toPgame :=\n  by\n  rw [to_pgame]\n  rfl\n#align ordinal.to_pgame_move_left_heq Ordinal.toPgame_moveLeft_hEq\n\n@[simp]\ntheorem toPgame_move_left' {o : Ordinal} (i) :\n    o.toPgame.moveLeft i = (toLeftMovesToPgame.symm i).val.toPgame :=\n  (congr_heq toPgame_moveLeft_hEq.symm (cast_hEq _ i)).symm\n#align ordinal.to_pgame_move_left' Ordinal.toPgame_move_left'\n\ntheorem toPgame_moveLeft {o : Ordinal} (i) :\n    o.toPgame.moveLeft (toLeftMovesToPgame i) = i.val.toPgame := by simp\n#align ordinal.to_pgame_move_left Ordinal.toPgame_moveLeft\n\n/-- `0.to_pgame` has the same moves as `0`. -/\nnoncomputable def zeroToPgameRelabelling : toPgame 0 \u2261r 0 :=\n  Relabelling.isEmpty _\n#align ordinal.zero_to_pgame_relabelling Ordinal.zeroToPgameRelabelling\n\nnoncomputable instance uniqueOneToPgameLeftMoves : Unique (toPgame 1).LeftMoves :=\n  (Equiv.cast <| toPgame_leftMoves 1).unique\n#align ordinal.unique_one_to_pgame_left_moves Ordinal.uniqueOneToPgameLeftMoves\n\n@[simp]\ntheorem one_toPgame_leftMoves_default_eq :\n    (default : (toPgame 1).LeftMoves) = @toLeftMovesToPgame 1 \u27e80, zero_lt_one\u27e9 :=\n  rfl\n#align ordinal.one_to_pgame_left_moves_default_eq Ordinal.one_toPgame_leftMoves_default_eq\n\n@[simp]\ntheorem to_leftMoves_one_toPgame_symm (i) : (@toLeftMovesToPgame 1).symm i = \u27e80, zero_lt_one\u27e9 := by\n  simp\n#align ordinal.to_left_moves_one_to_pgame_symm Ordinal.to_leftMoves_one_toPgame_symm\n\ntheorem one_toPgame_moveLeft (x) : (toPgame 1).moveLeft x = toPgame 0 := by simp\n#align ordinal.one_to_pgame_move_left Ordinal.one_toPgame_moveLeft\n\n/-- `1.to_pgame` has the same moves as `1`. -/\nnoncomputable def oneToPgameRelabelling : toPgame 1 \u2261r 1 :=\n  \u27e8Equiv.equivOfUnique _ _, Equiv.equivOfIsEmpty _ _, fun i => by\n    simpa using zero_to_pgame_relabelling, isEmptyElim\u27e9\n#align ordinal.one_to_pgame_relabelling Ordinal.oneToPgameRelabelling\n\ntheorem toPgame_lf {a b : Ordinal} (h : a < b) : a.toPgame \u29cf b.toPgame :=\n  by\n  convert move_left_lf (to_left_moves_to_pgame \u27e8a, h\u27e9)\n  rw [to_pgame_move_left]\n#align ordinal.to_pgame_lf Ordinal.toPgame_lf\n\ntheorem toPgame_le {a b : Ordinal} (h : a \u2264 b) : a.toPgame \u2264 b.toPgame :=\n  by\n  refine' le_iff_forall_lf.2 \u27e8fun i => _, isEmptyElim\u27e9\n  rw [to_pgame_move_left']\n  exact to_pgame_lf ((to_left_moves_to_pgame_symm_lt i).trans_le h)\n#align ordinal.to_pgame_le Ordinal.toPgame_le\n\ntheorem toPgame_lt {a b : Ordinal} (h : a < b) : a.toPgame < b.toPgame :=\n  \u27e8toPgame_le h.le, toPgame_lf h\u27e9\n#align ordinal.to_pgame_lt Ordinal.toPgame_lt\n\ntheorem toPgame_nonneg (a : Ordinal) : 0 \u2264 a.toPgame :=\n  zeroToPgameRelabelling.ge.trans <| toPgame_le <| Ordinal.zero_le a\n#align ordinal.to_pgame_nonneg Ordinal.toPgame_nonneg\n\n@[simp]\ntheorem toPgame_lf_iff {a b : Ordinal} : a.toPgame \u29cf b.toPgame \u2194 a < b :=\n  \u27e8by\n    contrapose\n    rw [not_lt, not_lf]\n    exact to_pgame_le, toPgame_lf\u27e9\n#align ordinal.to_pgame_lf_iff Ordinal.toPgame_lf_iff\n\n@[simp]\ntheorem toPgame_le_iff {a b : Ordinal} : a.toPgame \u2264 b.toPgame \u2194 a \u2264 b :=\n  \u27e8by\n    contrapose\n    rw [not_le, Pgame.not_le]\n    exact to_pgame_lf, toPgame_le\u27e9\n#align ordinal.to_pgame_le_iff Ordinal.toPgame_le_iff\n\n@[simp]\ntheorem toPgame_lt_iff {a b : Ordinal} : a.toPgame < b.toPgame \u2194 a < b :=\n  \u27e8by\n    contrapose\n    rw [not_lt]\n    exact fun h => not_lt_of_le (to_pgame_le h), toPgame_lt\u27e9\n#align ordinal.to_pgame_lt_iff Ordinal.toPgame_lt_iff\n\n@[simp]\ntheorem toPgame_equiv_iff {a b : Ordinal} : (a.toPgame \u2248 b.toPgame) \u2194 a = b := by\n  rw [Pgame.Equiv, le_antisymm_iff, to_pgame_le_iff, to_pgame_le_iff]\n#align ordinal.to_pgame_equiv_iff Ordinal.toPgame_equiv_iff\n\ntheorem toPgame_injective : Function.Injective Ordinal.toPgame := fun a b h =>\n  toPgame_equiv_iff.1 <| equiv_of_eq h\n#align ordinal.to_pgame_injective Ordinal.toPgame_injective\n\n@[simp]\ntheorem toPgame_eq_iff {a b : Ordinal} : a.toPgame = b.toPgame \u2194 a = b :=\n  toPgame_injective.eq_iff\n#align ordinal.to_pgame_eq_iff Ordinal.toPgame_eq_iff\n\n/-- The order embedding version of `to_pgame`. -/\n@[simps]\nnoncomputable def toPgameEmbedding : Ordinal.{u} \u21aao Pgame.{u}\n    where\n  toFun := Ordinal.toPgame\n  inj' := toPgame_injective\n  map_rel_iff' := @toPgame_le_iff\n#align ordinal.to_pgame_embedding Ordinal.toPgameEmbedding\n\n/-- The sum of ordinals as games corresponds to natural addition of ordinals. -/\ntheorem toPgame_add : \u2200 a b : Ordinal.{u}, a.toPgame + b.toPgame \u2248 (a \u266f b).toPgame\n  | a, b =>\n    by\n    refine' \u27e8le_of_forall_lf (fun i => _) isEmptyElim, le_of_forall_lf (fun i => _) isEmptyElim\u27e9\n    \u00b7 apply left_moves_add_cases i <;> intro i <;> let wf := to_left_moves_to_pgame_symm_lt i <;>\n            try rw [add_move_left_inl] <;> try rw [add_move_left_inr] <;>\n        rw [to_pgame_move_left', lf_congr_left (to_pgame_add _ _), to_pgame_lf_iff]\n      \u00b7 exact nadd_lt_nadd_right wf _\n      \u00b7 exact nadd_lt_nadd_left wf _\n    \u00b7 rw [to_pgame_move_left']\n      rcases lt_nadd_iff.1 (to_left_moves_to_pgame_symm_lt i) with (\u27e8c, hc, hc'\u27e9 | \u27e8c, hc, hc'\u27e9) <;>\n          rw [\u2190 to_pgame_le_iff, \u2190 le_congr_right (to_pgame_add _ _)] at hc' <;>\n        apply lf_of_le_of_lf hc'\n      \u00b7 apply add_lf_add_right\n        rwa [to_pgame_lf_iff]\n      \u00b7 apply add_lf_add_left\n        rwa [to_pgame_lf_iff]decreasing_by solve_by_elim [PSigma.Lex.left, PSigma.Lex.right]\n#align ordinal.to_pgame_add Ordinal.toPgame_add\n\n@[simp]\ntheorem toPgame_add_mk' (a b : Ordinal) : \u27e6a.toPgame\u27e7 + \u27e6b.toPgame\u27e7 = \u27e6(a \u266f b).toPgame\u27e7 :=\n  Quot.sound (toPgame_add a b)\n#align ordinal.to_pgame_add_mk Ordinal.toPgame_add_mk'\n\nend Ordinal\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/SetTheory/Game/Ordinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7468683119057898}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot\n-/\n\nimport tactic.apply_fun\nimport topology.uniform_space.basic\nimport topology.separation\n\n/-!\n# Hausdorff properties of uniform spaces. Separation quotient.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file studies uniform spaces whose underlying topological spaces are separated\n(also known as Hausdorff or T\u2082).\nThis turns out to be equivalent to asking that the intersection of all entourages\nis the diagonal only. This condition actually implies the stronger separation property\nthat the space is T\u2083, hence those conditions are equivalent for topologies coming from\na uniform structure.\n\nMore generally, the intersection `\ud835\udce2 X` of all entourages of `X`, which has type `set (X \u00d7 X)` is an\nequivalence relation on `X`. Points which are equivalent under the relation are basically\nundistinguishable from the point of view of the uniform structure. For instance any uniformly\ncontinuous function will send equivalent points to the same value.\n\nThe quotient `separation_quotient X` of `X` by `\ud835\udce2 X` has a natural uniform structure which is\nseparated, and satisfies a universal property: every uniformly continuous function\nfrom `X` to a separated uniform space uniquely factors through `separation_quotient X`.\nAs usual, this allows to turn `separation_quotient` into a functor (but we don't use the\ncategory theory library in this file).\n\nThese notions admit relative versions, one can ask that `s : set X` is separated, this\nis equivalent to asking that the uniform structure induced on `s` is separated.\n\n## Main definitions\n\n* `separation_relation X : set (X \u00d7 X)`: the separation relation\n* `separated_space X`: a predicate class asserting that `X` is separated\n* `separation_quotient X`: the maximal separated quotient of `X`.\n* `separation_quotient.lift f`: factors a map `f : X \u2192 Y` through the separation quotient of `X`.\n* `separation_quotient.map f`: turns a map `f : X \u2192 Y` into a map between the separation quotients\n  of `X` and `Y`.\n\n## Main results\n\n* `separated_iff_t2`: the equivalence between being separated and being Hausdorff for uniform\n  spaces.\n* `separation_quotient.uniform_continuous_lift`: factoring a uniformly continuous map through the\n  separation quotient gives a uniformly continuous map.\n* `separation_quotient.uniform_continuous_map`: maps induced between separation quotients are\n  uniformly continuous.\n\n##\u00a0Notations\n\nLocalized in `uniformity`, we have the notation `\ud835\udce2 X` for the separation relation\non a uniform space `X`,\n\n## Implementation notes\n\nThe separation setoid `separation_setoid` is not declared as a global instance.\nIt is made a local instance while building the theory of `separation_quotient`.\nThe factored map `separation_quotient.lift f` is defined without imposing any condition on\n`f`, but returns junk if `f` is not uniformly continuous (constant junk hence it is always\nuniformly continuous).\n\n-/\n\nopen filter topological_space set classical function uniform_space\nopen_locale classical topology uniformity filter\nnoncomputable theory\nset_option eqn_compiler.zeta true\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\nvariables [uniform_space \u03b1] [uniform_space \u03b2] [uniform_space \u03b3]\n\n\n/-!\n### Separated uniform spaces\n-/\n\n@[priority 100]\ninstance uniform_space.to_regular_space : regular_space \u03b1 :=\nregular_space.of_basis\n  (\u03bb a, by { rw [nhds_eq_comap_uniformity], exact uniformity_has_basis_closed.comap _ })\n  (\u03bb a V hV, hV.2.preimage $ continuous_const.prod_mk continuous_id)\n\n/-- The separation relation is the intersection of all entourages.\n  Two points which are related by the separation relation are \"indistinguishable\"\n  according to the uniform structure. -/\nprotected def separation_rel (\u03b1 : Type u) [u : uniform_space \u03b1] :=\n\u22c2\u2080 (\ud835\udce4 \u03b1).sets\n\nlocalized \"notation (name := separation_rel) `\ud835\udce2` := separation_rel\" in uniformity\n\nlemma separated_equiv : equivalence (\u03bbx y, (x, y) \u2208 \ud835\udce2 \u03b1) :=\n\u27e8assume x, assume s, refl_mem_uniformity,\n  assume x y, assume h (s : set (\u03b1\u00d7\u03b1)) hs,\n    have preimage prod.swap s \u2208 \ud835\udce4 \u03b1,\n      from symm_le_uniformity hs,\n    h _ this,\n  assume x y z (hxy : (x, y) \u2208 \ud835\udce2 \u03b1) (hyz : (y, z) \u2208 \ud835\udce2 \u03b1)\n      s (hs : s \u2208 \ud835\udce4 \u03b1),\n    let \u27e8t, ht, (h_ts : comp_rel t t \u2286 s)\u27e9 := comp_mem_uniformity_sets hs in\n    h_ts $ show (x, z) \u2208 comp_rel t t,\n      from \u27e8y, hxy t ht, hyz t ht\u27e9\u27e9\n\nlemma filter.has_basis.mem_separation_rel {\u03b9 : Sort*} {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 set (\u03b1 \u00d7 \u03b1)}\n  (h : (\ud835\udce4 \u03b1).has_basis p s) {a : \u03b1 \u00d7 \u03b1} :\n  a \u2208 \ud835\udce2 \u03b1 \u2194 \u2200 i, p i \u2192 a \u2208 s i :=\nh.forall_mem_mem\n\ntheorem separation_rel_iff_specializes {a b : \u03b1} : (a, b) \u2208 \ud835\udce2 \u03b1 \u2194 a \u2933 b :=\nby simp only [(\ud835\udce4 \u03b1).basis_sets.mem_separation_rel, id, mem_set_of_eq,\n  (nhds_basis_uniformity (\ud835\udce4 \u03b1).basis_sets).specializes_iff]\n\ntheorem separation_rel_iff_inseparable {a b : \u03b1} : (a, b) \u2208 \ud835\udce2 \u03b1 \u2194 inseparable a b :=\n  separation_rel_iff_specializes.trans specializes_iff_inseparable\n\n/-- A uniform space is separated if its separation relation is trivial (each point\nis related only to itself). -/\nclass separated_space (\u03b1 : Type u) [uniform_space \u03b1] : Prop := (out : \ud835\udce2 \u03b1 = id_rel)\n\ntheorem separated_space_iff {\u03b1 : Type u} [uniform_space \u03b1] :\n  separated_space \u03b1 \u2194 \ud835\udce2 \u03b1 = id_rel :=\n\u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\ntheorem separated_def {\u03b1 : Type u} [uniform_space \u03b1] :\n  separated_space \u03b1 \u2194 \u2200 x y, (\u2200 r \u2208 \ud835\udce4 \u03b1, (x, y) \u2208 r) \u2192 x = y :=\nby simp [separated_space_iff, id_rel_subset.2 separated_equiv.1, subset.antisymm_iff];\n   simp [subset_def, separation_rel]\n\ntheorem separated_def' {\u03b1 : Type u} [uniform_space \u03b1] :\n  separated_space \u03b1 \u2194 \u2200 x y, x \u2260 y \u2192 \u2203 r \u2208 \ud835\udce4 \u03b1, (x, y) \u2209 r :=\nseparated_def.trans $ forall\u2082_congr $ \u03bb x y, by rw \u2190 not_imp_not; simp [not_forall]\n\nlemma eq_of_uniformity {\u03b1 : Type*} [uniform_space \u03b1] [separated_space \u03b1] {x y : \u03b1}\n  (h : \u2200 {V}, V \u2208 \ud835\udce4 \u03b1 \u2192 (x, y) \u2208 V) : x = y :=\nseparated_def.mp \u2039separated_space \u03b1\u203a x y (\u03bb _, h)\n\nlemma eq_of_uniformity_basis {\u03b1 : Type*} [uniform_space \u03b1] [separated_space \u03b1] {\u03b9 : Type*}\n  {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 set (\u03b1 \u00d7 \u03b1)} (hs : (\ud835\udce4 \u03b1).has_basis p s) {x y : \u03b1}\n  (h : \u2200 {i}, p i \u2192 (x, y) \u2208 s i) : x = y :=\neq_of_uniformity (\u03bb V V_in, let \u27e8i, hi, H\u27e9 := hs.mem_iff.mp V_in in H (h hi))\n\nlemma eq_of_forall_symmetric {\u03b1 : Type*} [uniform_space \u03b1] [separated_space \u03b1] {x y : \u03b1}\n  (h : \u2200 {V}, V \u2208 \ud835\udce4 \u03b1 \u2192 symmetric_rel V \u2192 (x, y) \u2208 V) : x = y :=\neq_of_uniformity_basis has_basis_symmetric (by simpa [and_imp] using \u03bb _, h)\n\nlemma eq_of_cluster_pt_uniformity [separated_space \u03b1] {x y : \u03b1} (h : cluster_pt (x, y) (\ud835\udce4 \u03b1)) :\n  x = y :=\neq_of_uniformity_basis uniformity_has_basis_closed $ \u03bb V \u27e8hV, hVc\u27e9,\n  is_closed_iff_cluster_pt.1 hVc _ $ h.mono $ le_principal_iff.2 hV\n\nlemma id_rel_sub_separation_relation (\u03b1 : Type*) [uniform_space \u03b1] : id_rel \u2286 \ud835\udce2 \u03b1 :=\nbegin\n  unfold separation_rel,\n  rw id_rel_subset,\n  intros x,\n  suffices : \u2200 t \u2208 \ud835\udce4 \u03b1, (x, x) \u2208 t, by simpa only [refl_mem_uniformity],\n  exact \u03bb t, refl_mem_uniformity,\nend\n\nlemma separation_rel_comap  {f : \u03b1 \u2192 \u03b2}\n  (h : \u2039uniform_space \u03b1\u203a = uniform_space.comap f \u2039uniform_space \u03b2\u203a) :\n  \ud835\udce2 \u03b1 = (prod.map f f) \u207b\u00b9' \ud835\udce2 \u03b2 :=\nbegin\n  unfreezingI { subst h },\n  dsimp [separation_rel],\n  simp_rw [uniformity_comap, (filter.comap_has_basis (prod.map f f) (\ud835\udce4 \u03b2)).sInter_sets,\n      \u2190 preimage_Inter, sInter_eq_bInter],\n  refl,\nend\n\nprotected lemma filter.has_basis.separation_rel {\u03b9 : Sort*} {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 set (\u03b1 \u00d7 \u03b1)}\n  (h : has_basis (\ud835\udce4 \u03b1) p s) :\n  \ud835\udce2 \u03b1 = \u22c2 i (hi : p i), s i :=\nby { unfold separation_rel, rw h.sInter_sets }\n\nlemma separation_rel_eq_inter_closure : \ud835\udce2 \u03b1 = \u22c2\u2080 (closure '' (\ud835\udce4 \u03b1).sets) :=\nby simp [uniformity_has_basis_closure.separation_rel]\n\nlemma is_closed_separation_rel : is_closed (\ud835\udce2 \u03b1) :=\nbegin\n  rw separation_rel_eq_inter_closure,\n  apply is_closed_sInter,\n  rintros _ \u27e8t, t_in, rfl\u27e9,\n  exact is_closed_closure,\nend\n\nlemma separated_iff_t2 : separated_space \u03b1 \u2194 t2_space \u03b1 :=\nbegin\n  classical,\n  split ; introI h,\n  { rw [t2_iff_is_closed_diagonal, \u2190 show \ud835\udce2 \u03b1 = diagonal \u03b1, from h.1],\n    exact is_closed_separation_rel },\n  { rw separated_def',\n    intros x y hxy,\n    rcases t2_separation hxy with \u27e8u, v, uo, vo, hx, hy, h\u27e9,\n    rcases is_open_iff_ball_subset.1 uo x hx with \u27e8r, hrU, hr\u27e9,\n    exact \u27e8r, hrU, \u03bb H, h.le_bot \u27e8hr H, hy\u27e9\u27e9 }\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance separated_t3 [separated_space \u03b1] : t3_space \u03b1 :=\nby { haveI := separated_iff_t2.mp \u2039_\u203a, exact \u27e8\u27e9 }\n\ninstance subtype.separated_space [separated_space \u03b1] (s : set \u03b1) : separated_space s :=\nseparated_iff_t2.mpr subtype.t2_space\n\nlemma is_closed_of_spaced_out [separated_space \u03b1] {V\u2080 : set (\u03b1 \u00d7 \u03b1)} (V\u2080_in : V\u2080 \u2208 \ud835\udce4 \u03b1)\n  {s : set \u03b1} (hs : s.pairwise (\u03bb x y, (x, y) \u2209 V\u2080)) : is_closed s :=\nbegin\n  rcases comp_symm_mem_uniformity_sets V\u2080_in with \u27e8V\u2081, V\u2081_in, V\u2081_symm, h_comp\u27e9,\n  apply is_closed_of_closure_subset,\n  intros x hx,\n  rw mem_closure_iff_ball at hx,\n  rcases hx V\u2081_in with \u27e8y, hy, hy'\u27e9,\n  suffices : x = y, by rwa this,\n  apply eq_of_forall_symmetric,\n  intros V V_in V_symm,\n  rcases hx (inter_mem V\u2081_in V_in) with \u27e8z, hz, hz'\u27e9,\n  obtain rfl : z = y,\n  { by_contra hzy,\n    exact hs hz' hy' hzy (h_comp $ mem_comp_of_mem_ball V\u2081_symm (ball_inter_left x _ _ hz) hy) },\n  exact ball_inter_right x _ _ hz\nend\n\nlemma is_closed_range_of_spaced_out {\u03b9} [separated_space \u03b1] {V\u2080 : set (\u03b1 \u00d7 \u03b1)} (V\u2080_in : V\u2080 \u2208 \ud835\udce4 \u03b1)\n  {f : \u03b9 \u2192 \u03b1} (hf : pairwise (\u03bb x y, (f x, f y) \u2209 V\u2080)) : is_closed (range f) :=\nis_closed_of_spaced_out V\u2080_in $\n  by { rintro _ \u27e8x, rfl\u27e9 _ \u27e8y, rfl\u27e9 h, exact hf (ne_of_apply_ne f h) }\n\n\n/-!\n### Separation quotient\n-/\nnamespace uniform_space\n\n/-- The separation relation of a uniform space seen as a setoid. -/\ndef separation_setoid (\u03b1 : Type u) [uniform_space \u03b1] : setoid \u03b1 :=\n\u27e8\u03bbx y, (x, y) \u2208 \ud835\udce2 \u03b1, separated_equiv\u27e9\n\nlocal attribute [instance] separation_setoid\n\ninstance separation_setoid.uniform_space {\u03b1 : Type u} [u : uniform_space \u03b1] :\n  uniform_space (quotient (separation_setoid \u03b1)) :=\n{ to_topological_space := u.to_topological_space.coinduced (\u03bbx, \u27e6x\u27e7),\n  uniformity := map (\u03bbp:(\u03b1\u00d7\u03b1), (\u27e6p.1\u27e7, \u27e6p.2\u27e7)) u.uniformity,\n  refl := le_trans (by simp [quotient.exists_rep]) (filter.map_mono refl_le_uniformity),\n  symm := tendsto_map' $\n    by simp [prod.swap, (\u2218)]; exact tendsto_map.comp tendsto_swap_uniformity,\n  comp := calc (map (\u03bb (p : \u03b1 \u00d7 \u03b1), (\u27e6p.fst\u27e7, \u27e6p.snd\u27e7)) u.uniformity).lift' (\u03bbs, comp_rel s s) =\n          u.uniformity.lift' ((\u03bbs, comp_rel s s) \u2218 image (\u03bb (p : \u03b1 \u00d7 \u03b1), (\u27e6p.fst\u27e7, \u27e6p.snd\u27e7))) :\n      map_lift'_eq2 $ monotone_id.comp_rel monotone_id\n    ... \u2264 u.uniformity.lift' (image (\u03bb (p : \u03b1 \u00d7 \u03b1), (\u27e6p.fst\u27e7, \u27e6p.snd\u27e7)) \u2218\n            (\u03bbs:set (\u03b1\u00d7\u03b1), comp_rel s (comp_rel s s))) :\n      lift'_mono' $ assume s hs \u27e8a, b\u27e9 \u27e8c, \u27e8\u27e8a\u2081, a\u2082\u27e9, ha, a_eq\u27e9, \u27e8\u27e8b\u2081, b\u2082\u27e9, hb, b_eq\u27e9\u27e9,\n      begin\n        simp at a_eq,\n        simp at b_eq,\n        have h : \u27e6a\u2082\u27e7 = \u27e6b\u2081\u27e7, { rw [a_eq.right, b_eq.left] },\n        have h : (a\u2082, b\u2081) \u2208 \ud835\udce2 \u03b1 := quotient.exact h,\n        simp [function.comp, set.image, comp_rel, and.comm, and.left_comm, and.assoc],\n        exact \u27e8a\u2081, a_eq.left, b\u2082, b_eq.right, a\u2082, ha, b\u2081, h s hs, hb\u27e9\n      end\n    ... = map (\u03bbp:(\u03b1\u00d7\u03b1), (\u27e6p.1\u27e7, \u27e6p.2\u27e7))\n            (u.uniformity.lift' (\u03bbs:set (\u03b1\u00d7\u03b1), comp_rel s (comp_rel s s))) :\n      by rw [map_lift'_eq];\n        exact monotone_id.comp_rel (monotone_id.comp_rel monotone_id)\n    ... \u2264 map (\u03bbp:(\u03b1\u00d7\u03b1), (\u27e6p.1\u27e7, \u27e6p.2\u27e7)) u.uniformity :\n      map_mono comp_le_uniformity3,\n  is_open_uniformity := assume s,\n    have \u2200a, \u27e6a\u27e7 \u2208 s \u2192\n        ({p:\u03b1\u00d7\u03b1 | p.1 = a \u2192 \u27e6p.2\u27e7 \u2208 s} \u2208 \ud835\udce4 \u03b1 \u2194\n          {p:\u03b1\u00d7\u03b1 | p.1 \u2248 a \u2192 \u27e6p.2\u27e7 \u2208 s} \u2208 \ud835\udce4 \u03b1),\n      from assume a ha,\n      \u27e8assume h,\n        let \u27e8t, ht, hts\u27e9 := comp_mem_uniformity_sets h in\n        have hts : \u2200{a\u2081 a\u2082}, (a, a\u2081) \u2208 t \u2192 (a\u2081, a\u2082) \u2208 t \u2192 \u27e6a\u2082\u27e7 \u2208 s,\n          from assume a\u2081 a\u2082 ha\u2081 ha\u2082, @hts (a, a\u2082) \u27e8a\u2081, ha\u2081, ha\u2082\u27e9 rfl,\n        have ht' : \u2200{a\u2081 a\u2082}, a\u2081 \u2248 a\u2082 \u2192 (a\u2081, a\u2082) \u2208 t,\n          from assume a\u2081 a\u2082 h, sInter_subset_of_mem ht h,\n        u.uniformity.sets_of_superset ht $ assume \u27e8a\u2081, a\u2082\u27e9 h\u2081 h\u2082, hts (ht' $ setoid.symm h\u2082) h\u2081,\n        assume h, u.uniformity.sets_of_superset h $ by simp {contextual := tt}\u27e9,\n    begin\n      simp only [is_open_coinduced, is_open_uniformity, uniformity, forall_quotient_iff,\n        mem_preimage, mem_map, preimage_set_of_eq, quotient.eq],\n      exact \u27e8\u03bbh a ha, (this a ha).mp $ h a ha, \u03bbh a ha, (this a ha).mpr $ h a ha\u27e9\n    end }\n\nlemma uniformity_quotient :\n  \ud835\udce4 (quotient (separation_setoid \u03b1)) = (\ud835\udce4 \u03b1).map (\u03bbp:(\u03b1\u00d7\u03b1), (\u27e6p.1\u27e7, \u27e6p.2\u27e7)) :=\nrfl\n\nlemma uniform_continuous_quotient_mk :\n  uniform_continuous (quotient.mk : \u03b1 \u2192 quotient (separation_setoid \u03b1)) :=\nle_rfl\n\nlemma uniform_continuous_quotient {f : quotient (separation_setoid \u03b1) \u2192 \u03b2}\n  (hf : uniform_continuous (\u03bbx, f \u27e6x\u27e7)) : uniform_continuous f :=\nhf\n\nlemma uniform_continuous_quotient_lift\n  {f : \u03b1 \u2192 \u03b2} {h : \u2200a b, (a, b) \u2208 \ud835\udce2 \u03b1 \u2192 f a = f b}\n  (hf : uniform_continuous f) : uniform_continuous (\u03bba, quotient.lift f h a) :=\nuniform_continuous_quotient hf\n\nlemma uniform_continuous_quotient_lift\u2082\n  {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {h : \u2200a c b d, (a, b) \u2208 \ud835\udce2 \u03b1 \u2192 (c, d) \u2208 \ud835\udce2 \u03b2 \u2192 f a c = f b d}\n  (hf : uniform_continuous (\u03bbp:\u03b1\u00d7\u03b2, f p.1 p.2)) :\n  uniform_continuous (\u03bbp:_\u00d7_, quotient.lift\u2082 f h p.1 p.2) :=\nbegin\n  rw [uniform_continuous, uniformity_prod_eq_prod, uniformity_quotient, uniformity_quotient,\n    filter.prod_map_map_eq, filter.tendsto_map'_iff, filter.tendsto_map'_iff],\n  rwa [uniform_continuous, uniformity_prod_eq_prod, filter.tendsto_map'_iff] at hf\nend\n\nlemma comap_quotient_le_uniformity :\n  (\ud835\udce4 $ quotient $ separation_setoid \u03b1).comap (\u03bb (p : \u03b1 \u00d7 \u03b1), (\u27e6p.fst\u27e7, \u27e6p.snd\u27e7)) \u2264 (\ud835\udce4 \u03b1) :=\nassume t' ht',\nlet \u27e8t, ht, tt_t'\u27e9 := comp_mem_uniformity_sets ht' in\nlet \u27e8s, hs, ss_t\u27e9 := comp_mem_uniformity_sets ht in\n\u27e8(\u03bbp:\u03b1\u00d7\u03b1, (\u27e6p.1\u27e7, \u27e6p.2\u27e7)) '' s,\n  (\ud835\udce4 \u03b1).sets_of_superset hs $ assume x hx, \u27e8x, hx, rfl\u27e9,\n  assume \u27e8a\u2081, a\u2082\u27e9 \u27e8\u27e8b\u2081, b\u2082\u27e9, hb, ab_eq\u27e9,\n  have \u27e6b\u2081\u27e7 = \u27e6a\u2081\u27e7 \u2227 \u27e6b\u2082\u27e7 = \u27e6a\u2082\u27e7, from prod.mk.inj ab_eq,\n  have b\u2081 \u2248 a\u2081 \u2227 b\u2082 \u2248 a\u2082, from and.imp quotient.exact quotient.exact this,\n  have ab\u2081 : (a\u2081, b\u2081) \u2208 t, from (setoid.symm this.left) t ht,\n  have ba\u2082 : (b\u2082, a\u2082) \u2208 s, from this.right s hs,\n  tt_t' \u27e8b\u2081, show ((a\u2081, a\u2082).1, b\u2081) \u2208 t, from ab\u2081,\n    ss_t \u27e8b\u2082, show ((b\u2081, a\u2082).1, b\u2082) \u2208 s, from hb, ba\u2082\u27e9\u27e9\u27e9\n\nlemma comap_quotient_eq_uniformity :\n  (\ud835\udce4 $ quotient $ separation_setoid \u03b1).comap (\u03bb (p : \u03b1 \u00d7 \u03b1), (\u27e6p.fst\u27e7, \u27e6p.snd\u27e7)) = \ud835\udce4 \u03b1 :=\nle_antisymm comap_quotient_le_uniformity le_comap_map\n\n\ninstance separated_separation : separated_space (quotient (separation_setoid \u03b1)) :=\n\u27e8set.ext $ assume \u27e8a, b\u27e9, quotient.induction_on\u2082 a b $ assume a b,\n  \u27e8assume h,\n    have a \u2248 b, from assume s hs,\n      have s \u2208 (\ud835\udce4 $ quotient $ separation_setoid \u03b1).comap (\u03bbp:(\u03b1\u00d7\u03b1), (\u27e6p.1\u27e7, \u27e6p.2\u27e7)),\n        from comap_quotient_le_uniformity hs,\n      let \u27e8t, ht, hts\u27e9 := this in\n      hts begin dsimp [preimage], exact h t ht end,\n    show \u27e6a\u27e7 = \u27e6b\u27e7, from quotient.sound this,\n\n  assume heq : \u27e6a\u27e7 = \u27e6b\u27e7, assume h hs,\n  heq \u25b8 refl_mem_uniformity hs\u27e9\u27e9\n\nlemma separated_of_uniform_continuous {f : \u03b1 \u2192 \u03b2} {x y : \u03b1}\n  (H : uniform_continuous f) (h : x \u2248 y) : f x \u2248 f y :=\nassume _ h', h _ (H h')\n\nlemma eq_of_separated_of_uniform_continuous [separated_space \u03b2] {f : \u03b1 \u2192 \u03b2} {x y : \u03b1}\n  (H : uniform_continuous f) (h : x \u2248 y) : f x = f y :=\nseparated_def.1 (by apply_instance) _ _ $ separated_of_uniform_continuous H h\n\n/-- The maximal separated quotient of a uniform space `\u03b1`. -/\ndef separation_quotient (\u03b1 : Type*) [uniform_space \u03b1] := quotient (separation_setoid \u03b1)\n\nnamespace separation_quotient\ninstance : uniform_space (separation_quotient \u03b1) := separation_setoid.uniform_space\ninstance : separated_space (separation_quotient \u03b1) := uniform_space.separated_separation\ninstance [inhabited \u03b1] : inhabited (separation_quotient \u03b1) :=\nquotient.inhabited (separation_setoid \u03b1)\n\nlemma mk_eq_mk {x y : \u03b1} : (\u27e6x\u27e7 : separation_quotient \u03b1) = \u27e6y\u27e7 \u2194 inseparable x y :=\nquotient.eq'.trans separation_rel_iff_inseparable\n\n/-- Factoring functions to a separated space through the separation quotient. -/\ndef lift [separated_space \u03b2] (f : \u03b1 \u2192 \u03b2) : (separation_quotient \u03b1 \u2192 \u03b2) :=\nif h : uniform_continuous f then\n  quotient.lift f (\u03bb x y, eq_of_separated_of_uniform_continuous h)\nelse\n  \u03bb x, f (nonempty.some \u27e8x.out\u27e9)\n\nlemma lift_mk [separated_space \u03b2] {f : \u03b1 \u2192 \u03b2} (h : uniform_continuous f) (a : \u03b1) :\n  lift f \u27e6a\u27e7 = f a :=\nby rw [lift, dif_pos h]; refl\n\nlemma uniform_continuous_lift [separated_space \u03b2] (f : \u03b1 \u2192 \u03b2) : uniform_continuous (lift f) :=\nbegin\n  by_cases hf : uniform_continuous f,\n  { rw [lift, dif_pos hf], exact uniform_continuous_quotient_lift hf },\n  { rw [lift, dif_neg hf], exact uniform_continuous_of_const (assume a b, rfl) }\nend\n\n/-- The separation quotient functor acting on functions. -/\ndef map (f : \u03b1 \u2192 \u03b2) : separation_quotient \u03b1 \u2192 separation_quotient \u03b2 :=\nlift (quotient.mk \u2218 f)\n\nlemma map_mk {f : \u03b1 \u2192 \u03b2} (h : uniform_continuous f) (a : \u03b1) : map f \u27e6a\u27e7 = \u27e6f a\u27e7 :=\nby rw [map, lift_mk (uniform_continuous_quotient_mk.comp h)]\n\nlemma uniform_continuous_map (f : \u03b1 \u2192 \u03b2) : uniform_continuous (map f) :=\nuniform_continuous_lift (quotient.mk \u2218 f)\n\nlemma map_unique {f : \u03b1 \u2192 \u03b2} (hf : uniform_continuous f)\n  {g : separation_quotient \u03b1 \u2192 separation_quotient \u03b2}\n  (comm : quotient.mk \u2218 f = g \u2218 quotient.mk) : map f = g :=\nby ext \u27e8a\u27e9;\ncalc map f \u27e6a\u27e7 = \u27e6f a\u27e7 : map_mk hf a\n  ... = g \u27e6a\u27e7 : congr_fun comm a\n\nlemma map_id : map (@id \u03b1) = id :=\nmap_unique uniform_continuous_id rfl\n\nlemma map_comp {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (hf : uniform_continuous f) (hg : uniform_continuous g) :\n  map g \u2218 map f = map (g \u2218 f) :=\n(map_unique (hg.comp hf) $ by simp only [(\u2218), map_mk, hf, hg]).symm\n\nend separation_quotient\n\nlemma separation_prod {a\u2081 a\u2082 : \u03b1} {b\u2081 b\u2082 : \u03b2} : (a\u2081, b\u2081) \u2248 (a\u2082, b\u2082) \u2194 a\u2081 \u2248 a\u2082 \u2227 b\u2081 \u2248 b\u2082 :=\nbegin\n  split,\n  { assume h,\n    exact \u27e8separated_of_uniform_continuous uniform_continuous_fst h,\n           separated_of_uniform_continuous uniform_continuous_snd h\u27e9 },\n  { rintros \u27e8eqv_\u03b1, eqv_\u03b2\u27e9 r r_in,\n    rw uniformity_prod at r_in,\n    rcases r_in with \u27e8t_\u03b1, \u27e8r_\u03b1, r_\u03b1_in, h_\u03b1\u27e9, t_\u03b2, \u27e8r_\u03b2, r_\u03b2_in, h_\u03b2\u27e9, rfl\u27e9,\n    let p_\u03b1 := \u03bb(p : (\u03b1 \u00d7 \u03b2) \u00d7 (\u03b1 \u00d7 \u03b2)), (p.1.1, p.2.1),\n    let p_\u03b2 := \u03bb(p : (\u03b1 \u00d7 \u03b2) \u00d7 (\u03b1 \u00d7 \u03b2)), (p.1.2, p.2.2),\n    have key_\u03b1 : p_\u03b1 ((a\u2081, b\u2081), (a\u2082, b\u2082)) \u2208 r_\u03b1, { simp [p_\u03b1, eqv_\u03b1 r_\u03b1 r_\u03b1_in] },\n    have key_\u03b2 : p_\u03b2 ((a\u2081, b\u2081), (a\u2082, b\u2082)) \u2208 r_\u03b2, { simp [p_\u03b2, eqv_\u03b2 r_\u03b2 r_\u03b2_in] },\n    exact \u27e8h_\u03b1 key_\u03b1, h_\u03b2 key_\u03b2\u27e9 },\nend\n\ninstance separated.prod [separated_space \u03b1] [separated_space \u03b2] : separated_space (\u03b1 \u00d7 \u03b2) :=\nseparated_def.2 $ assume x y H, prod.ext\n  (eq_of_separated_of_uniform_continuous uniform_continuous_fst H)\n  (eq_of_separated_of_uniform_continuous uniform_continuous_snd H)\n\nend uniform_space\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/uniform_space/separation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7468683105051398}}
{"text": "/-\nCopyright (c) 2022 Ivan Sadofschi Costa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ivan Sadofschi Costa\n\n! This file was ported from Lean 3 source module topology.continuous_function.t0_sierpinski\n! leanprover-community/mathlib commit dc6c365e751e34d100e80fe6e314c3c3e0fd2988\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.Order\nimport Mathlib.Topology.Sets.Opens\nimport Mathlib.Topology.ContinuousFunction.Basic\n\n/-!\n# Any T0 space embeds in a product of copies of the Sierpinski space.\n\nWe consider `Prop` with the Sierpinski topology. If `X` is a topological space, there is a\ncontinuous map `productOfMemOpens` from `X` to `Opens X \u2192 Prop` which is the product of the maps\n`X \u2192 Prop` given by `x \u21a6 x \u2208 u`.\n\nThe map `productOfMemOpens` is always inducing. Whenever `X` is T0, `productOfMemOpens` is\nalso injective and therefore an embedding.\n-/\n\n\nnoncomputable section\n\nnamespace TopologicalSpace\n\ntheorem eq_induced_by_maps_to_sierpinski (X : Type _) [t : TopologicalSpace X] :\n    t = \u2a05 u : Opens X, sierpinskiSpace.induced (\u00b7 \u2208 u) := by\n  apply le_antisymm\n  \u00b7 rw [le_inf\u1d62_iff]\n    exact fun u => Continuous.le_induced (isOpen_iff_continuous_mem.mp u.2)\n  \u00b7 intro u h\n    rw [\u2190 generateFrom_union\u1d62_isOpen]\n    apply isOpen_generateFrom_of_mem\n    simp only [Set.mem_union\u1d62, Set.mem_setOf_eq, isOpen_induced_iff]\n    exact \u27e8\u27e8u, h\u27e9, {True}, isOpen_singleton_true, by simp [Set.preimage]\u27e9\n#align topological_space.eq_induced_by_maps_to_sierpinski TopologicalSpace.eq_induced_by_maps_to_sierpinski\n\nvariable (X : Type _) [TopologicalSpace X]\n\n/-- The continuous map from `X` to the product of copies of the Sierpinski space, (one copy for each\nopen subset `u` of `X`). The `u` coordinate of `productOfMemOpens x` is given by `x \u2208 u`.\n-/\ndef productOfMemOpens : C(X, Opens X \u2192 Prop) where\n  toFun x u := x \u2208 u\n  continuous_toFun := continuous_pi_iff.2 fun u => continuous_Prop.2 u.isOpen\n#align topological_space.product_of_mem_opens TopologicalSpace.productOfMemOpens\n\ntheorem productOfMemOpens_inducing : Inducing (productOfMemOpens X) := by\n  convert inducing_inf\u1d62_to_pi fun (u : Opens X) (x : X) => x \u2208 u\n  apply eq_induced_by_maps_to_sierpinski\n#align topological_space.product_of_mem_opens_inducing TopologicalSpace.productOfMemOpens_inducing\n\ntheorem productOfMemOpens_injective [T0Space X] : Function.Injective (productOfMemOpens X) := by\n  intro x1 x2 h\n  apply Inseparable.eq\n  rw [\u2190 Inducing.inseparable_iff (productOfMemOpens_inducing X), h]\n#align topological_space.product_of_mem_opens_injective TopologicalSpace.productOfMemOpens_injective\n\ntheorem productOfMemOpens_embedding [T0Space X] : Embedding (productOfMemOpens X) :=\n  Embedding.mk (productOfMemOpens_inducing X) (productOfMemOpens_injective X)\n#align topological_space.product_of_mem_opens_embedding TopologicalSpace.productOfMemOpens_embedding\n\nend TopologicalSpace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/ContinuousFunction/T0Sierpinski.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7468683095965101}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis file formalises part of the paper \"Iterated chromatic \nlocalization\" by Nicola Bellumat and Neil Strickland.  We have \nformalised all of the combinatorial content (including the \nresults in the combinatorial homotopy theory of finite \nposets).  We have not formalised any of the theory of derivators.\n-/\n\nimport data.list.basic\nimport data.fin\nimport data.fintype\nimport order.bounded_lattice\nimport algebra.big_operators\nimport fin_extra basic upper\nimport tactic.squeeze\n\n#print notation\nopen poset\n\nnamespace itloc\n\nlemma two_pos' : 2 > 0 := dec_trivial\n\n/-- `\ud835\udd40 n` is the set {0,1,...,n-1} -/\nvariable (n : \u2115)\n\ndef \ud835\udd40 := fin n\n\nnamespace \ud835\udd40 \n\n/-- The type `\ud835\udd40 n` is finite, with decidable equality, and there\n  is an obvious way of printing a string representation of any\n  element.  The lines below use the `apply_instance` tactic to\n  deal with these things. \n-/\ninstance : fintype (\ud835\udd40 n)      := by { dsimp [\ud835\udd40], apply_instance }\ninstance : decidable_eq (\ud835\udd40 n) := by { dsimp [\ud835\udd40], apply_instance }\ninstance : has_repr (\ud835\udd40 n)     := by { dsimp [\ud835\udd40], apply_instance }\n\ninstance : decidable_linear_order (\ud835\udd40 n) := \n  (@fin.decidable_linear_order n).\n\nend \ud835\udd40 \n\n/--\n `\u2119 n` is the poset of subsets of `\ud835\udd40 n`, ordered by inclusion\n\n LaTeX: defn-P\n-/\n\ndef \u2119 := finset (\ud835\udd40 n)\n\nnamespace \u2119 \n\n/-- The type `\u2119 n` is finite, with decidable equality, and \n  an obvious string representation.  Additionally, there \n  is a membership relation between `\ud835\udd40 n` and `\u2119 n`, for which\n  we have a `has_mem` instance.\n-/\n\ninstance : fintype (\u2119 n)       := by { dsimp [\u2119] , apply_instance }\ninstance : decidable_eq (\u2119 n)  := by { dsimp [\u2119] , apply_instance }\ninstance : has_mem (\ud835\udd40 n) (\u2119 n) := by { dsimp [\ud835\udd40,\u2119], apply_instance }\ninstance : has_repr (\u2119 n)      := by { dsimp [\u2119] , apply_instance }\n\n/-- The `apply_instance` tactic also knows enough to give\n  `\u2119 n` a structure as a distributive lattice.  However, \n  the library does not contain any general rule showing that\n  `\u2119 n` has a top and bottom element, so we prove that \n  explicitly.\n-/\n\ninstance dl : lattice.distrib_lattice (\u2119 n) := \nby { dsimp [\u2119], apply_instance }\n\ninstance : lattice.bounded_distrib_lattice (\u2119 n) := {\n  bot := finset.empty,\n  top := finset.univ,\n  le_top := \u03bb (A : finset (\ud835\udd40 n)),\n   begin change A \u2286 finset.univ,intros i _,exact finset.mem_univ i end,\n  bot_le := \u03bb (A : finset (\ud835\udd40 n)),\n   begin change finset.empty \u2286 A,intros i h,\n    exact (finset.not_mem_empty i h).elim end,\n  .. (\u2119.dl n)\n}\n\n/-- From the lattice structure we can obtain a partial order.\n  It is not normally necessary to mention that fact explicitly,\n  but we do so here to avoid some subtle technical issues later.\n-/\n\ninstance po : partial_order (\u2119 n) := by apply_instance\n\n/-- The only element of `\u2119 0` is the empty set. -/\nlemma mem_zero (A : \u2119 0) : A = \u22a5 := \nby {ext a, exact fin.elim0 a}\n\n/-- The order relation on `\u2119 n` is decidable -/\ninstance decidable_le : decidable_rel (\u03bb (A B : \u2119 n), A \u2264 B) := \n \u03bb (A B : finset (\ud835\udd40 n)), by { change decidable (A \u2286 B), apply_instance, }\n\nvariable {n} \n\n/-- The bottom element is the empty set, so nothing is a member. -/\nlemma not_mem_bot (i : \ud835\udd40 n) : \u00ac (i \u2208 (\u22a5 : \u2119 n)) := finset.not_mem_empty i\n\n/-- The top element is the full set `\u2119 n`, so everything is a member. -/\nlemma mem_top     (i : \ud835\udd40 n) :   (i \u2208 (\u22a4 : \u2119 n)) := finset.mem_univ i\n\n/-- The membership rule for a union (= sup in the lattice) -/\nlemma mem_sup {A B : \u2119 n} {i : \ud835\udd40 n} : \n i \u2208 A \u2294 B \u2194 (i \u2208 A) \u2228 (i \u2208 B) := finset.mem_union\n\n/-- The membership rule for an intersection (= inf in the lattice) -/\nlemma mem_inf {A B : \u2119 n} {i : \ud835\udd40 n} : \n i \u2208 A \u2293 B \u2194 (i \u2208 A) \u2227 (i \u2208 B) := finset.mem_inter\n\n/-- `A.filter_lt i` is Lean notation for `{a \u2208 A : a < i}` -/\ndef filter_lt (i : \u2115) (A : \u2119 n) := A.filter (\u03bb a, a.val < i)\n\n/-- `A.filter_ge i` is Lean notation for `{a \u2208 A : a \u2265 i}` -/\ndef filter_ge (i : \u2115) (A : \u2119 n) := A.filter (\u03bb a, a.val \u2265 i)\n\n/-- Membership rule for these sets. -/\nlemma mem_filter_lt {i : \u2115} {A : \u2119 n} {a : \ud835\udd40 n} : \n a \u2208 (A.filter_lt i) \u2194 a \u2208 A \u2227 a.val < i := finset.mem_filter \n\nlemma mem_filter_ge {i : \u2115} {A : \u2119 n} {a : \ud835\udd40 n} : \n a \u2208 (A.filter_ge i) \u2194 a \u2208 A \u2227 a.val \u2265 i := finset.mem_filter \n\nlemma filter_lt_is_le (i : \u2115) (A : \u2119 n) : \n  A.filter_lt i \u2264 A := \u03bb a ha, (mem_filter_lt.mp ha).left\n\nlemma filter_ge_is_le (i : \u2115) (A : \u2119 n) : \n  A.filter_ge i \u2264 A := \u03bb a ha, (mem_filter_ge.mp ha).left\n\nlemma filter_sup {i j : \u2115} (h : i \u2265 j) (A : \u2119 n) : \n  A.filter_lt i \u2294 A.filter_ge j = A := \nbegin\n  ext a,\n  rw [mem_sup, mem_filter_lt, mem_filter_ge, \u2190 and_or_distrib_left],\n  have : a.val < i \u2228 a.val \u2265 j := \n  begin\n    rcases lt_or_ge a.val i with h_lt | h_ge,\n    exact or.inl h_lt, exact or.inr (le_trans h h_ge) \n  end,\n  rw [eq_true_intro this, and_true],\nend\n\nlemma filter_lt_zero (A : \u2119 n) : A.filter_lt 0 = \u22a5 := \n by { ext a,\n      rw[\u2119.mem_filter_lt],\n      have : \u00ac (a \u2208 \u22a5) := finset.not_mem_empty a,\n      simp only [nat.not_lt_zero,this,iff_self,and_false]}\n\nlemma filter_ge_zero (A : \u2119 n) : A.filter_ge 0 = A := \n by { ext a,\n      rw[\u2119.mem_filter_ge],\n      have : a.val \u2265 0 := nat.zero_le a.val,\n      simp only [this,iff_self,and_true]}\n\nlemma filter_lt_last {i : \u2115} (hi : i \u2265 n) (A : \u2119 n) : \n A.filter_lt i = A := \nbegin\n  ext a,\n  rw[\u2119.mem_filter_lt],\n  simp only [lt_of_lt_of_le a.is_lt hi, iff_self, and_true]\nend\n\nlemma filter_ge_last {i : \u2115} (hi : i \u2265 n) (A : \u2119 n) : \n A.filter_ge i = \u22a5 := \nbegin\n  ext a,\n  rw[\u2119.mem_filter_ge],\n  have h\u2080 : \u00ac (a \u2208 \u22a5) := finset.not_mem_empty a,\n  have h\u2081 : \u00ac (a.val \u2265 i) := \n    not_le_of_gt (lt_of_lt_of_le a.is_lt hi),\n  simp only [h\u2080, h\u2081, iff_self, and_false]\nend\n\n/-\n For subsets `A,B \u2286 \ud835\udd40 n`, the notation `A \u221f B` means that every \n element of `A` is less than or equal to every element of `B` \n\n LaTeX: defn-P\n-/\n\ndef angle : (\u2119 n) \u2192 (\u2119 n) \u2192 Prop := \n \u03bb A B, \u2200 {{i j : \ud835\udd40 n}}, i \u2208 A \u2192 j \u2208 B \u2192 i \u2264 j\n\nreserve infix ` \u221f `:50\nnotation A \u221f B := angle A B\n\n/-- The angle relation is decidable -/\ninstance : \u2200 (A B : \u2119 n), decidable (angle A B) := \nby { dsimp [angle], apply_instance }\n\nlemma bot_angle (B : \u2119 n) : \u22a5 \u221f B := \n\u03bb i j i_in_A j_in_B, (finset.not_mem_empty i i_in_A).elim\n\nlemma angle_bot (A : \u2119 n) : A \u221f \u22a5 := \n\u03bb i j i_in_A j_in_B, (finset.not_mem_empty j j_in_B).elim\n\nlemma sup_angle (A B C : \u2119 n) : A \u2294 B \u221f C \u2194 (A \u221f C) \u2227 (B \u221f C) := \nbegin\n  split,\n  { rintro hAB, split,\n    exact \u03bb i k i_in_A k_in_C,\n          hAB (finset.subset_union_left A B i_in_A) k_in_C,\n    exact \u03bb j k j_in_B k_in_C,\n          hAB (finset.subset_union_right A B j_in_B) k_in_C },\n  { rintro \u27e8hA,hB\u27e9 i k i_in_AB k_in_C,\n    rcases finset.mem_union.mp i_in_AB with i_in_A | i_in_B,\n    exact hA i_in_A k_in_C,\n    exact hB i_in_B k_in_C }\nend\n\nlemma angle_sup (A B C : \u2119 n) : A \u221f B \u2294 C \u2194 (A \u221f B) \u2227 (A \u221f C) := \nbegin\n  split,\n  { rintro hBC, split,\n    exact \u03bb i j i_in_A j_in_B,\n          hBC i_in_A (finset.subset_union_left  B C j_in_B),\n    exact \u03bb i k i_in_A k_in_C,\n          hBC i_in_A (finset.subset_union_right B C k_in_C) },\n  { rintro \u27e8hB,hC\u27e9 i j i_in_A j_in_BC,\n    rcases finset.mem_union.mp j_in_BC with j_in_B | j_in_C,\n    exact hB i_in_A j_in_B,\n    exact hC i_in_A j_in_C }\nend\n\nlemma filter_angle {i j : \u2115} (h : i \u2264 j + 1) (A : \u2119 n) : \n  (A.filter_lt i) \u221f (A.filter_ge j) := \nbegin\n  intros a b ha hb,\n  replace ha : a.val + 1 \u2264 i := (mem_filter_lt.mp ha).right,\n  replace hb := nat.succ_le_succ (mem_filter_ge.mp hb).right, \n  exact nat.le_of_succ_le_succ (le_trans (le_trans ha h) hb)\nend\n\nlemma angle_mono {A\u2080 A\u2081 B\u2080 B\u2081 : \u2119 n} \n  (hA : A\u2080 \u2264 A\u2081) (hB : B\u2080 \u2264 B\u2081) (h : A\u2081 \u221f B\u2081) : A\u2080 \u221f B\u2080 := \n\u03bb x y hx hy, h (hA hx) (hB hy)\n\nlemma split_angle {A B : \u2119 n} (k : \ud835\udd40 n) \n (hA : \u2200 i, i \u2208 A \u2192 i \u2264 k) (hB : \u2200 j, j \u2208 B \u2192 k \u2264 j) : A \u221f B := \n  \u03bb i j i_in_A j_in_B, le_trans (hA i i_in_A) (hB j j_in_B)\n\nlemma angle_iff {A B : \u2119 n} : \n A \u221f B \u2194 n = 0 \u2228 \n          \u2203 (k : \ud835\udd40 n), (\u2200 {i}, (i \u2208 A) \u2192 i \u2264 k) \u2227 (\u2200 {i}, i \u2208 B \u2192 k \u2264 i) := \nbegin\n cases n with n,\n { rw[A.mem_zero, B.mem_zero], simp [bot_angle] },\n split,\n { intro h_angle, right,\n   let z : \ud835\udd40 n.succ := \u27e80,nat.zero_lt_succ n\u27e9,\n   let A0 : finset (\ud835\udd40 n.succ) := insert z A,\n   rcases fin.finset_largest_element A0 \n    (finset.ne_empty_of_mem (finset.mem_insert_self z A))\n      with \u27e8k, k_in_A0, k_largest\u27e9,\n   use k,\n   split,\n   { intros a a_in_A, \n     exact k_largest a (finset.mem_insert_of_mem a_in_A) },\n   { intros b b_in_B,\n     rcases (finset.mem_insert.mp k_in_A0) with k_eq_z | k_in_A,\n     { rw [k_eq_z], exact nat.zero_le b.val },\n     { exact h_angle k_in_A b_in_B } } },\n { rintro (\u27e8\u27e8\u27e9\u27e9 | \u27e8k,hA,hB\u27e9) a b a_in_A b_in_B,\n   exact le_trans (hA a_in_A) (hB b_in_B) }\nend\n\nlemma not_angle_iff {A B : \u2119 n} : \n \u00ac (A \u221f B) \u2194 (\u2203 (a \u2208 A) (b \u2208 B), a > b) := \nbegin\n  dsimp[angle],\n  rw [not_forall],\n  apply exists_congr, intro a,\n  rw [not_forall],\n  split; intro h,\n  { rcases h with \u27e8b,hb\u27e9,\n    rw[not_imp, not_imp, \u2190 lt_iff_not_ge] at hb,\n    exact \u27e8hb.1,b,hb.2.1,hb.2.2\u27e9 },\n  { rcases h with \u27e8ha,b,hb,h_lt\u27e9,\n    change b < a at h_lt,\n    use b,\n    simp [ha, hb, h_lt] }\nend\n\nlemma angle_iff' {A B : \u2119 n} : \n A \u221f B \u2194 (A = \u22a5 \u2227 B = \u22a5) \u2228 \n          \u2203 (k : \ud835\udd40 n), (\u2200 i, (i \u2208 A) \u2192 i \u2264 k) \u2227 (\u2200 i, i \u2208 B \u2192 k \u2264 i) := \nbegin\n split,\n {intro h,\n  by_cases hA : A = \u22a5,\n  {by_cases hB : B = \u22a5,\n   {left, exact \u27e8hA,hB\u27e9},\n   {rcases (fin.finset_least_element B hB) with \u27e8k,\u27e8k_in_B,k_least\u27e9\u27e9,\n    right,use k,split,\n    {intros i i_in_A,exact h i_in_A k_in_B,},\n    {exact k_least,}\n   },\n  },{\n   rcases (fin.finset_largest_element A hA) with \u27e8k,\u27e8k_in_A,k_largest\u27e9\u27e9,\n   right,use k,split,\n   {exact k_largest},\n   {intros j j_in_B,exact h k_in_A j_in_B,}\n  }\n },\n {rintro (\u27e8A_empty,B_empty\u27e9 | \u27e8k,\u27e8hA,hB\u27e9\u27e9),\n  {rw[A_empty],exact bot_angle B},\n  {exact split_angle k hA hB,}\n }\nend\n\nend \u2119 \n\n/-\n We define `\ud835\udd42 n` to be the poset of upwards-closed subsets of \n `\u2119 n`, ordered by reverse inclusion.  \n\n LaTeX: defn-Q\n-/\n\nvariable (n)\ndef \ud835\udd42 := poset.upper (\u2119 n)\n\nnamespace \ud835\udd42 \n\ninstance : lattice.bounded_distrib_lattice (\ud835\udd42 n) := \n@upper.bdl (\u2119 n) _ _ _ _\n\ninstance : partial_order (\ud835\udd42 n) := by apply_instance \n\ninstance : fintype  (\ud835\udd42 n) := upper.fintype (\u2119 n)\ninstance : has_repr (\ud835\udd42 n) := upper.has_repr (\u2119 n)\n\ninstance \u2119_mem_\ud835\udd42 : has_mem (\u2119 n) (\ud835\udd42 n) := \nby { unfold \ud835\udd42, apply_instance }\n\ninstance decidable_mem (A : \u2119 n) (U : \ud835\udd42 n) : decidable (A \u2208 U) := \nby { change decidable (A \u2208 U.val), apply_instance }\n\nvariable {n}\n\n/-- LaTeX: defn-Q -/\ndef u : poset.hom (\u2119 n) (\ud835\udd42 n) := upper.u\n\nlemma mem_u {T : \u2119 n} {A : \u2119 n} : A \u2208 @u n T \u2194 T \u2264 A := \nbegin\n  change A \u2208 finset.filter _ _ \u2194 T \u2264 A,\n  simp [finset.mem_filter, finset.mem_univ]\nend\n\n/-- LaTeX: defn-Q -/\ndef v (T : \u2119 n) : (\ud835\udd42 n) := \n\u27e8 finset.univ.filter (\u03bb A, \u2203 i, i \u2208 A \u2227 i \u2208 T), \n  begin \n    rintro A B A_le_B h,\n    rw [finset.mem_filter] at *,\n    rcases h with \u27e8A_in_univ,i,i_in_A,i_in_T\u27e9,\n    exact \u27e8finset.mem_univ B,\u27e8i,\u27e8A_le_B i_in_A,i_in_T\u27e9\u27e9\u27e9\n  end \u27e9 \n\nlemma mem_v {T : \u2119 n} {A : \u2119 n} : A \u2208 v T \u2194 \u2203 i, i \u2208 A \u2227 i \u2208 T := \nbegin\n  change (A \u2208 finset.filter _ _) \u2194 _,\n  rw [finset.mem_filter],\n  simp [finset.mem_univ A]\nend\n\nlemma v_mono {T\u2080 T\u2081 : \u2119 n} (h : T\u2080 \u2264 T\u2081) : v T\u2080 \u2265 v T\u2081 := \nbegin\n  intros A h\u2080,\n  rcases finset.mem_filter.mp h\u2080 with \u27e8A_in_univ,\u27e8i,i_in_A,i_in_T\u2080\u27e9\u27e9,\n  exact finset.mem_filter.mpr \u27e8A_in_univ,\u27e8i,i_in_A,h i_in_T\u2080\u27e9\u27e9\nend\n\n/-\n We make `\ud835\udd42 n` into a monoid as follows: `U * V` is the set of all\n sets of the form `A \u222a B`, where `A \u2208 U` and `B \u2208 V` and `A \u221f B`.\n The monoid structure is compatible with the partial order, and this\n allows us to regard `\ud835\udd42 n` as a monoidal category (in which all\n hom sets have size at most one).  \n\n LaTeX: lem-mu\n-/\n\ndef mul0 (U V : finset (\u2119 n)) : finset (\u2119 n) := \n U.bind (\u03bb A, (V.filter (\u03bb B,A \u221f B)).image (\u03bb B, A \u2294 B))\n\nlemma mem_mul0 (U V : finset (\u2119 n)) (C : \u2119 n) : \n (C \u2208 (mul0 U V)) \u2194 \u2203 A B, A \u2208 U \u2227 B \u2208 V \u2227 (A \u221f B) \u2227 (A \u2294 B = C) := \nbegin\n split,\n {intro hC,\n  rcases finset.mem_bind.mp hC with \u27e8A,\u27e8A_in_U,C_in_image\u27e9\u27e9,\n  rcases finset.mem_image.mp C_in_image with \u27e8B,\u27e8B_in_filter,e\u27e9\u27e9,\n  rcases finset.mem_filter.mp B_in_filter with \u27e8B_in_V,A_angle_B\u27e9,\n  use A, use B,\n  exact \u27e8A_in_U,B_in_V,A_angle_B,e\u27e9,\n },{\n  rintro \u27e8A,B,A_in_U,B_in_V,A_angle_B,e\u27e9,\n  apply finset.mem_bind.mpr,use A,use A_in_U,\n  apply finset.mem_image.mpr,use B,\n  have B_in_filter : B \u2208 V.val.filter _ := \n   finset.mem_filter.mpr \u27e8B_in_V,A_angle_B\u27e9,\n  use B_in_filter,\n  exact e,\n }\nend\n\nlemma bot_mul0 (V : finset (\u2119 n)) (hV : is_upper V) : mul0 finset.univ V = V := \nbegin \n ext C,\n rw[mem_mul0 finset.univ V C],\n split,\n {rintro \u27e8A,B,hA,hB,hAB,hC\u27e9,\n  have B_le_C : B \u2264 C := hC \u25b8 (@lattice.le_sup_right _ _ A B),\n  exact hV B C B_le_C hB,\n },{\n  intro C_in_V,\n  have A_in_U : (\u22a5 : \u2119 n) \u2208 finset.univ := @finset.mem_univ (\u2119 n) _ \u22a5,\n  use \u22a5,use C,\n  exact \u27e8A_in_U,C_in_V,C.bot_angle,lattice.bot_sup_eq\u27e9, \n }\nend\n\nlemma mul0_bot (U : finset (\u2119 n)) (hU : is_upper U) : mul0 U finset.univ = U := \nbegin\n ext C,\n rw[mem_mul0 U finset.univ C],\n split,\n {rintro \u27e8A,B,hA,hB,hAB,hC\u27e9,\n  have A_le_C : A \u2264 C := hC \u25b8 (@lattice.le_sup_left _ _ A B),\n  exact hU A C A_le_C hA,\n },{\n  intro C_in_U,\n  have B_in_V : (\u22a5 : \u2119 n) \u2208 (\u22a5 : \ud835\udd42 n) := @finset.mem_univ (\u2119 n) _ \u22a5,\n  use C,use \u22a5,\n  exact \u27e8C_in_U,B_in_V,C.angle_bot,lattice.sup_bot_eq\u27e9, \n } \nend\n\nlemma is_upper_mul0 (U V : finset (\u2119 n)) \n (hU : is_upper U) (hV : is_upper V) : is_upper (mul0 U V) := \nbegin\n intros C C' C_le_C' C_in_mul,\n rcases (mem_mul0 U V C).mp C_in_mul with \u27e8A,B,A_in_U,B_in_V,A_angle_B,e\u27e9,\n apply (mem_mul0 U V C').mpr,\n rcases (\u2119.angle_iff.mp A_angle_B) with \u27e8\u27e8\u27e9\u27e9 | \u27e8k,\u27e8hA,hB\u27e9\u27e9,\n { rw[C.mem_zero] at *, rw[C'.mem_zero] at *,\n   use A, use B,\n   exact \u27e8A_in_U, B_in_V, A_angle_B, e\u27e9 },\n { let A' := C'.filter (\u03bb i, i \u2264 k),\n   let B' := C'.filter (\u03bb j, k \u2264 j),\n   have A'_angle_B' : A' \u221f B' := \u03bb i j i_in_A' j_in_B', \n    le_trans (finset.mem_filter.mp i_in_A').right (finset.mem_filter.mp j_in_B').right,\n   have A_le_C : A \u2264 C := e \u25b8 (@lattice.le_sup_left _ _ A B),\n   have B_le_C : B \u2264 C := e \u25b8 (@lattice.le_sup_right _ _ A B),\n   have A_le_A' : A \u2264 A' := \u03bb i i_in_A, \n    finset.mem_filter.mpr \u27e8(le_trans A_le_C C_le_C') i_in_A,hA i_in_A\u27e9,\n   have B_le_B' : B \u2264 B' := \u03bb j j_in_B, \n    finset.mem_filter.mpr \u27e8(le_trans B_le_C C_le_C') j_in_B,hB j_in_B\u27e9,\n   have A'_in_U : A' \u2208 U.val := hU A A' A_le_A' A_in_U,\n   have B'_in_V : B' \u2208 V.val := hV B B' B_le_B' B_in_V,\n   have eC' : C' = A' \u2294 B' := \n   begin\n    ext i,split,\n    { intro i_in_C',\n      by_cases h : i \u2264 k,\n      { exact finset.mem_union_left  B' (finset.mem_filter.mpr \u27e8i_in_C',h\u27e9)},\n      { replace h := le_of_lt (lt_of_not_ge h),\n        exact finset.mem_union_right A' (finset.mem_filter.mpr \u27e8i_in_C',h\u27e9) } },\n    { intro i_in_union,\n      rcases finset.mem_union.mp i_in_union with i_in_A' | i_in_B',\n      { exact (finset.mem_filter.mp i_in_A').left },\n      { exact (finset.mem_filter.mp i_in_B').left } }\n  end,\n  use A', use B',\n  exact \u27e8A'_in_U,B'_in_V,A'_angle_B',eC'.symm\u27e9,\n }\nend\n\nvariable (n) \n\ninstance : monoid (\ud835\udd42 n) := {\n  one := \u22a5, \n  mul := \u03bb U V, \u27e8mul0 U.val V.val,is_upper_mul0 U.val V.val U.property V.property\u27e9,\n  one_mul := \u03bb V, subtype.eq (bot_mul0 V.val V.property),\n  mul_one := \u03bb U, subtype.eq (mul0_bot U.val U.property),\n  mul_assoc := \u03bb \u27e8U,hU\u27e9 \u27e8V,hV\u27e9 \u27e8W,hW\u27e9, \n  begin -- Proof of associativity\n   apply subtype.eq,\n   change mul0 (mul0 U V) W = mul0 U (mul0 V W),\n   ext E,split,\n   {intro h,\n    rcases (mem_mul0 _ W E).mp h with \u27e8AB,C,\u27e8hAB,hC,AB_angle_C,e_AB_C\u27e9\u27e9,\n    rcases (mem_mul0 U V AB).mp hAB with \u27e8A,B,hA,hB,A_angle_B,e_A_B\u27e9,\n    have A_le_AB : A \u2264 AB := e_A_B \u25b8 (finset.subset_union_left  A B),\n    have B_le_AB : B \u2264 AB := e_A_B \u25b8 (finset.subset_union_right A B),\n    have A_angle_C : A \u221f C := \u03bb i k i_in_A k_in_C, \n     AB_angle_C (A_le_AB i_in_A) k_in_C,\n    have B_angle_C : B \u221f C := \u03bb j k j_in_B k_in_C, \n     AB_angle_C (B_le_AB j_in_B) k_in_C,\n    let BC := B \u2294 C,\n    have A_angle_BC : A \u221f BC := begin\n     rintros i j i_in_A j_in_BC,\n     rcases (finset.mem_union.mp j_in_BC) with j_in_B | j_in_C,\n     {exact A_angle_B i_in_A j_in_B,},\n     {exact A_angle_C i_in_A j_in_C,}\n    end,\n    have hBC : BC \u2208 mul0 V W := begin \n     apply (mem_mul0 V W BC).mpr,use B, use C,\n     exact \u27e8hB,hC,B_angle_C,rfl\u27e9\n    end,\n    have e_A_BC := calc\n     A \u2294 BC = A \u2294 (B \u2294 C) : rfl\n     ... = (A \u2294 B) \u2294 C : by rw[lattice.sup_assoc]\n     ... = E : by rw[e_A_B,e_AB_C],\n    apply (mem_mul0 U (mul0 V W) E).mpr,\n    use A,use BC,\n    exact \u27e8hA,hBC,A_angle_BC,e_A_BC\u27e9,\n   },\n   {intro h,\n    rcases (mem_mul0 U _ E).mp h with \u27e8A,BC,\u27e8hA,hBC,A_angle_BC,e_A_BC\u27e9\u27e9,\n    rcases (mem_mul0 V W BC).mp hBC with \u27e8B,C,hB,hC,B_angle_C,e_B_C\u27e9,\n    have B_le_BC : B \u2264 BC := e_B_C \u25b8 (finset.subset_union_left  B C),\n    have C_le_BC : C \u2264 BC := e_B_C \u25b8 (finset.subset_union_right B C),\n    have A_angle_B : A \u221f B := \u03bb i j i_in_A j_in_B, \n     A_angle_BC i_in_A (B_le_BC j_in_B),\n    have A_angle_C : A \u221f C := \u03bb i k i_in_A k_in_C, \n     A_angle_BC i_in_A (C_le_BC k_in_C),\n    let AB := A \u2294 B,\n    have AB_angle_C : AB \u221f C := begin\n     rintros i k i_in_AB k_in_C,\n     rcases (finset.mem_union.mp i_in_AB) with i_in_A | i_in_B,\n     {exact A_angle_C i_in_A k_in_C,},\n     {exact B_angle_C i_in_B k_in_C,}\n    end,\n    have hAB : AB \u2208 mul0 U V := begin \n     apply (mem_mul0 U V AB).mpr,use A, use B,\n     exact \u27e8hA,hB,A_angle_B,rfl\u27e9\n    end,\n    have e_AB_C := calc\n     AB \u2294 C = (A \u2294 B) \u2294 C : rfl\n     ... = A \u2294 (B \u2294 C) : by rw[\u2190 lattice.sup_assoc]\n     ... = E : by rw[e_B_C,e_A_BC],\n    apply (mem_mul0 (mul0 U V) W E).mpr,\n    use AB,use C,\n    exact \u27e8hAB,hC,AB_angle_C,e_AB_C\u27e9,\n   }\n  end\n}\n\nvariable {n} \n\n/-- Membership rule for `U * V` -/\nlemma mem_mul (U V : \ud835\udd42 n) (C : \u2119 n) : C \u2208 U * V \u2194  \n  \u2203 A B, A \u2208 U \u2227 B \u2208 V \u2227 (A \u221f B) \u2227 (A \u2294 B = C) := mem_mul0 U.val V.val C \n\n/-- Multiplication is monotone in both variables. -/\nlemma mul_le_mul (U\u2080 V\u2080 U\u2081 V\u2081 : \ud835\udd42 n) (hU : U\u2080 \u2264 U\u2081 ) (hV : V\u2080 \u2264 V\u2081) : \n U\u2080 * V\u2080 \u2264 U\u2081 * V\u2081 := \nbegin\n change (mul0 U\u2081.val V\u2081.val) \u2286 (mul0 U\u2080.val V\u2080.val),\n intros C C_in_W\u2081,\n rcases (mem_mul0 _ _ C).mp C_in_W\u2081 with \u27e8A,B,hA,hB,A_angle_B,e_A_B\u27e9,\n exact (mem_mul0 U\u2080.val V\u2080.val C).mpr \u27e8A,B,hU hA,hV hB,A_angle_B,e_A_B\u27e9, \nend\n\n/-- Multiplication distributes over union (on both sides).\n  Recall that we order \ud835\udd42 n by reverse inclusion, so the union\n  is the lattice inf operation, and is written as U \u2293 V.\n\n  LaTeX: lem-mu\n-/\n\nlemma mul_inf (U V W : \ud835\udd42 n) : U * (V \u2293 W) = (U * V) \u2293 (U * W) := \nbegin\n  ext C,\n  rw [upper.mem_inf, mem_mul U (V \u2293 W)],\n  split, \n  { rintro \u27e8A,B,hAU,hBVW,h_angle,h_ABC\u27e9, \n    rw [upper.mem_inf] at hBVW,\n    rcases hBVW with hBV | hBW,\n    { left , exact (mem_mul U V C).mpr \u27e8A,B,hAU,hBV,h_angle,h_ABC\u27e9 },\n    { right, exact (mem_mul U W C).mpr \u27e8A,B,hAU,hBW,h_angle,h_ABC\u27e9 } },\n  { rintro (hCUV | hCUW),\n    { rcases (mem_mul U V C).mp hCUV with \u27e8A,B,hAU,hBV,h_angle,h_ABC\u27e9,\n      have hBVW : B \u2208 V \u2293 W := (upper.mem_inf B).mpr (or.inl hBV),\n      exact \u27e8A,B,hAU,hBVW,h_angle,h_ABC\u27e9 },\n    { rcases (mem_mul U W C).mp hCUW with \u27e8A,B,hAU,hBW,h_angle,h_ABC\u27e9,\n      have hBVW : B \u2208 V \u2293 W := (upper.mem_inf B).mpr (or.inr hBW),\n      exact \u27e8A,B,hAU,hBVW,h_angle,h_ABC\u27e9 } }\nend\n\nlemma inf_mul (U V W : \ud835\udd42 n) : (U \u2293 V) * W = (U * W) \u2293 (V * W) := \nbegin\n  ext C,\n  rw [upper.mem_inf, mem_mul (U \u2293 V) W],\n  split, \n  { rintro \u27e8A,B,hAUV,hBW,h_angle,h_ABC\u27e9, \n    rw [upper.mem_inf] at hAUV,\n    rcases hAUV with hAU | hAV,\n    { left , exact (mem_mul U W C).mpr \u27e8A,B,hAU,hBW,h_angle,h_ABC\u27e9 },\n    { right, exact (mem_mul V W C).mpr \u27e8A,B,hAV,hBW,h_angle,h_ABC\u27e9 } },\n  { rintro (hCUW | hCVW),\n    { rcases (mem_mul U W C).mp hCUW with \u27e8A,B,hAU,hBW,h_angle,h_ABC\u27e9,\n      have hAUV : A \u2208 U \u2293 V := (upper.mem_inf A).mpr (or.inl hAU),\n      exact \u27e8A,B,hAUV,hBW,h_angle,h_ABC\u27e9 },\n    { rcases (mem_mul V W C).mp hCVW with \u27e8A,B,hAV,hBW,h_angle,h_ABC\u27e9,\n      have hAUV : A \u2208 U \u2293 V := (upper.mem_inf A).mpr (or.inr hAV),\n      exact \u27e8A,B,hAUV,hBW,h_angle,h_ABC\u27e9 } }\nend\n\n/-- LaTeX: rem-kp -/\n\ndef \u03ba (U : \ud835\udd42 n) : \u2119 n := \n  finset.univ.filter (\u03bb i, finset.singleton i \u2208 U)\n\nlemma \u03ba_mul (U V : \ud835\udd42 n) : \u03ba (U * V) = (\u03ba U) \u2293 (\u03ba V) := \nbegin\n  ext i,\n  let ii := finset.singleton i,\n  have ii_angle : ii \u221f ii := \u03bb j k hj hk, \n    by { rw[finset.mem_singleton.mp hj, finset.mem_singleton.mp hk] },\n  have ii_union : ii \u222a ii = ii := lattice.sup_idem,\n  have : ii \u2208 U * V \u2194 ii \u2208 U \u2227 ii \u2208 V := \n  begin\n    rw[\ud835\udd42.mem_mul],\n    split,\n    { rintro \u27e8A,B,A_in_U,B_in_V,h_angle,h_union\u27e9,\n      have hA : A \u2264 ii := by { rw[\u2190 h_union], exact lattice.le_sup_left },\n      have hB : B \u2264 ii := by { rw[\u2190 h_union], exact lattice.le_sup_right },\n      have hU : ii \u2208 U := U.property A ii hA A_in_U,\n      have hV : ii \u2208 V := V.property B ii hB B_in_V,\n      exact \u27e8hU,hV\u27e9 },\n    { rintro \u27e8hU,hV\u27e9, \n      use ii, use ii,\n      exact \u27e8hU,hV,ii_angle,ii_union\u27e9 }\n  end,\n  rw [\u2119.mem_inf],\n  repeat {rw [\u03ba, finset.mem_filter]},\n  simp [this]\nend\n\n/-- LaTeX: defn-thread -/\ndef threads : list (\u2119 n) \u2192 finset (list (\ud835\udd40 n)) \n| list.nil := finset.singleton list.nil\n| (list.cons A AA) := \n    A.bind (\u03bb a, ((threads AA).filter (\u03bb B, \u2200 b \u2208 B, a \u2264 b)).image (list.cons a))\n\ndef thread_sets (AA : list (\u2119 n)) : \ud835\udd42 n := \n\u27e8 finset.univ.filter (\u03bb T, \u2203 u \u2208 threads AA, (\u2200 a \u2208 u, a \u2208 T)),\n  begin\n    intros T\u2080 T\u2081 h_le h_mem,\n    rcases finset.mem_filter.mp h_mem with \u27e8_,\u27e8u,h_thread,u_in_T\u2080\u27e9\u27e9,\n    apply finset.mem_filter.mpr,\n    exact \u27e8finset.mem_univ T\u2081,u, h_thread,\u03bb a ha, h_le (u_in_T\u2080 a ha)\u27e9\n  end \u27e9 \n\nlemma mem_thread_sets {AA : list (\u2119 n)} {T : \u2119 n} : \n  T \u2208 thread_sets AA \u2194 \u2203 u \u2208 threads AA, (\u2200 a \u2208 u, a \u2208 T) := \nbegin\n  change T \u2208 (finset.univ.filter _) \u2194 _,\n  rw [finset.mem_filter],\n  simp [finset.mem_univ T]\nend\n\n/-- LaTeX: prop-thread -/\nlemma v_mul (AA : list (\u2119 n)) : (AA.map v).prod = thread_sets AA := \nbegin\n  induction AA with A AA ih,\n  { change \u22a5 = _,\n    ext A,\n    have : A \u2208 (\u22a5 : \ud835\udd42 n) := upper.mem_bot A, simp[this],\n    apply finset.mem_filter.mpr \u27e8finset.mem_univ A,_\u27e9,\n    use list.nil,\n    use finset.mem_singleton_self list.nil,\n    intros a a_in_nil,\n    exact false.elim (list.not_mem_nil a a_in_nil) },\n  { rw [list.map_cons, list.prod_cons],\n    ext T,\n    rw [ih, \ud835\udd42.mem_mul (v A) _],\n    split; intro h,\n    { rcases h with \u27e8R,S,hR,hS,h_angle,h_union\u27e9, \n      rcases mem_thread_sets.mp hS with \u27e8u,u_in_threads,u_in_S\u27e9,\n      rcases mem_v.mp hR with \u27e8i,i_in_R,i_in_A\u27e9,\n      apply (@mem_thread_sets n (A :: AA) T).mpr,\n      use (i :: u),\n      have : (list.cons i u) \u2208 threads (A :: AA) := \n      begin\n        rw [threads, finset.mem_bind],\n        use i, use i_in_A,\n        rw [finset.mem_image],\n        use u,\n        have : u \u2208 finset.filter (\u03bb (v : list (\ud835\udd40 n)), \u2200 (b : \ud835\udd40 n), b \u2208 v \u2192 i \u2264 b) (threads AA) := \n        begin\n          rw [finset.mem_filter],\n          split, {exact u_in_threads},\n          intros a a_in_u,\n          exact h_angle i_in_R (u_in_S a a_in_u),\n        end,\n        use this,\n      end,\n      use this,\n      rintro a (a_eq_i | a_in_u); rw [\u2190 h_union],\n      { rw[a_eq_i],\n        exact finset.mem_union_left S i_in_R },\n      { exact finset.mem_union_right R (u_in_S a a_in_u), } },\n    {\n      rcases (@mem_thread_sets n (A :: AA) T).mp h with \u27e8w,w_in_threads,w_in_T\u27e9,\n      rw [threads, finset.mem_bind] at w_in_threads,\n      rcases w_in_threads with \u27e8a,a_in_A,w_in_image\u27e9,\n      rcases finset.mem_image.mp w_in_image with \u27e8u,\u27e8u_in_filter,au_eq_w\u27e9\u27e9,\n      rcases finset.mem_filter.mp u_in_filter with \u27e8u_in_threads, u_ge_a\u27e9,\n      use T.filter_lt a.val.succ,\n      use T.filter_ge a.val,\n      have a_in_w : a \u2208 w := \n        by { rw[\u2190 au_eq_w], exact list.mem_cons_self a u },\n      have a_in_T : a \u2208 T := w_in_T a a_in_w,\n      have u_in_T1 : \u2200 (i : \ud835\udd40 n) (i_in_u : i \u2208 u), i \u2208 (T.filter_ge a.val) := \u03bb i i_in_u,\n      begin\n        apply \u2119.mem_filter_ge.mpr,\n        have : i \u2208 (list.cons a u) := list.mem_cons_of_mem a i_in_u,\n        rw [au_eq_w] at this,\n        exact \u27e8w_in_T i this, u_ge_a i i_in_u\u27e9,\n      end,\n      split,\n      { exact mem_v.mpr \u27e8a,\u27e8\u2119.mem_filter_lt.mpr \u27e8a_in_T,a.val.lt_succ_self\u27e9,a_in_A\u27e9\u27e9 },\n      split, \n      { rw [mem_thread_sets],\n        use u, use u_in_threads, exact u_in_T1 },\n      split, \n      { exact \u2119.filter_angle (le_refl _) T },\n      { exact \u2119.filter_sup (le_of_lt a.val.lt_succ_self) T } } }\nend\n\nend \ud835\udd42 \n\ndef is_universal {\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1] (l : list \u03b1) := \n  l.nodup \u2227 l.to_finset = finset.univ\n\ninstance {\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1] (l : list \u03b1) : \n  decidable (is_universal l) := \nby { dsimp[is_universal], apply_instance }\n\n/- LaTeX: eg-fracture-obj -/\nnamespace example_two\n\ndef i\u2080 : \ud835\udd40 2 := \u27e80,dec_trivial\u27e9 \ndef i\u2081 : \ud835\udd40 2 := \u27e81,dec_trivial\u27e9 \n\nlemma \ud835\udd40_univ : is_universal [i\u2080, i\u2081] := dec_trivial\n\ndef p   : \u2119 2 := \u22a5 \ndef p\u2080  : \u2119 2 := [i\u2080].to_finset \ndef p\u2081  : \u2119 2 := [i\u2081].to_finset \ndef p\u2080\u2081 : \u2119 2 := \u22a4 \n\nlemma \u2119_univ : is_universal [p, p\u2080, p\u2081, p\u2080\u2081] := dec_trivial\n\ndef u := @\ud835\udd42.u 2\n\ndef L : list (\ud835\udd42 2) := [u p, u p\u2080, u p\u2081, u p\u2080\u2081, u p\u2080 \u2293 u p\u2081, \u22a4]\n\n#eval (L.nodup : bool)\n#eval (is_universal L : bool)\n\nlemma \ud835\udd42_univ : is_universal L := dec_trivial\n\nend example_two \n\n/- LaTeX: eg-fracture-obj -/\nnamespace example_three\n\ndef i\u2080 : \ud835\udd40 3 := \u27e80,dec_trivial\u27e9 \ndef i\u2081 : \ud835\udd40 3 := \u27e81,dec_trivial\u27e9 \ndef i\u2082 : \ud835\udd40 3 := \u27e82,dec_trivial\u27e9 \n\nlemma \ud835\udd40_univ : is_universal [i\u2080, i\u2081, i\u2082] := dec_trivial\n\ndef p    : \u2119 3 := \u22a5 \ndef p\u2080   : \u2119 3 := [i\u2080].to_finset \ndef p\u2081   : \u2119 3 := [i\u2081].to_finset \ndef p\u2082   : \u2119 3 := [i\u2082].to_finset \ndef p\u2080\u2081  : \u2119 3 := [i\u2080,i\u2081].to_finset\ndef p\u2080\u2082  : \u2119 3 := [i\u2080,i\u2082].to_finset\ndef p\u2081\u2082  : \u2119 3 := [i\u2081,i\u2082].to_finset\ndef p\u2080\u2081\u2082 : \u2119 3 := \u22a4 \n\nlemma \u2119_univ :\n is_universal [p, p\u2080, p\u2081, p\u2082, p\u2080\u2081, p\u2080\u2082, p\u2081\u2082, p\u2080\u2081\u2082] := dec_trivial\n\ndef u := @\ud835\udd42.u 3\ndef v := @\ud835\udd42.v 3\n\ndef u\u2080 : \ud835\udd42 3 := u p\u2080 \ndef u\u2081 : \ud835\udd42 3 := u p\u2081 \ndef u\u2082 : \ud835\udd42 3 := u p\u2082 \n\ndef u\u2080\u2081 : \ud835\udd42 3 := u p\u2080\u2081  \ndef u\u2080\u2082 : \ud835\udd42 3 := u p\u2080\u2082 \ndef u\u2081\u2082 : \ud835\udd42 3 := u p\u2081\u2082 \n\ndef u\u2080\u2081\u2082 : \ud835\udd42 3 := u p\u2080\u2081\u2082 \n\ndef v\u2080\u2081 : \ud835\udd42 3 := u p\u2080 \u2293 u p\u2081 \ndef v\u2080\u2082 : \ud835\udd42 3 := u p\u2080 \u2293 u p\u2082 \ndef v\u2081\u2082 : \ud835\udd42 3 := u p\u2081 \u2293 u p\u2082 \n\ndef x\u2080 : \ud835\udd42 3 := u p\u2080 \u2293 u p\u2081\u2082 \ndef x\u2081 : \ud835\udd42 3 := u p\u2081 \u2293 u p\u2080\u2082 \ndef x\u2082 : \ud835\udd42 3 := u p\u2082 \u2293 u p\u2080\u2081 \n\ndef w\u2080 : \ud835\udd42 3 := u\u2080\u2081 \u2293 u\u2080\u2082 \ndef w\u2081 : \ud835\udd42 3 := u\u2080\u2081 \u2293 u\u2081\u2082 \ndef w\u2082 : \ud835\udd42 3 := u\u2080\u2082 \u2293 u\u2081\u2082 \n\ndef y := u\u2080\u2081 \u2293 u\u2080\u2082 \u2293 u\u2081\u2082 \n\ndef L : list (\ud835\udd42 3) := [\n \u22a5, v p\u2080\u2081\u2082, v\u2080\u2081, v\u2080\u2082, v\u2081\u2082, x\u2080, x\u2081, x\u2082, \n u\u2080, u\u2081, u\u2082, w\u2080, w\u2081, w\u2082, u\u2080\u2081, u\u2080\u2082, u\u2081\u2082, \n u\u2080\u2081\u2082, y, \u22a4 ]\n\n#eval (L.nodup : bool)\n#eval (is_universal L : bool)\n\n-- lemma \ud835\udd42_univ : is_universal L := dec_trivial\n\nlemma eqs : \n x\u2080 = v\u2080\u2081 * v\u2080\u2082 \u2227 x\u2081 = v\u2080\u2081 * v\u2081\u2082 \u2227 x\u2082 = v\u2080\u2082 * v\u2081\u2082 \u2227 \n w\u2080 = u\u2080  * v\u2081\u2082 \u2227 w\u2082 = v\u2080\u2081 * u\u2082  \u2227 y = v\u2080\u2081 * v\u2080\u2082 * v\u2081\u2082 := \nbegin \n  repeat { split }; \n  ext A; revert A; exact dec_trivial,\nend\n\nend example_three \n\nvariable (n)\n\n/-- LaTeX : defn-doubly-localising-alt -/\ndef \ud835\udd44 := { AB : (\u2119 n) \u00d7 (\u2119 n) // AB.1 \u221f AB.2 }\n\nnamespace \ud835\udd44 \n\ninstance : partial_order (\ud835\udd44 n) := {\n le := \u03bb \u27e8\u27e8A,B\u27e9,hAB\u27e9 \u27e8\u27e8C,D\u27e9,hCD\u27e9, (A \u2264 C) \u2227 (B \u2264 D),\n le_refl := \u03bb \u27e8\u27e8A,B\u27e9,hAB\u27e9, by { split; apply @le_refl (\u2119 n) _, },\n le_antisymm := \u03bb \u27e8\u27e8A,B\u27e9,hAB\u27e9 \u27e8\u27e8C,D\u27e9,hCD\u27e9 \u27e8hAC,hBD\u27e9 \u27e8hCA,hDB\u27e9, \n  begin congr,exact le_antisymm hAC hCA,exact le_antisymm hBD hDB end,\n le_trans :=\n  \u03bb \u27e8\u27e8A,B\u27e9,hAB\u27e9 \u27e8\u27e8C,D\u27e9,hCD\u27e9 \u27e8\u27e8E,F\u27e9,hEF\u27e9 \u27e8hAC,hBD\u27e9 \u27e8hCE,hDF\u27e9,\n   \u27e8le_trans hAC hCE,le_trans hBD hDF\u27e9, \n}\n\ninstance : lattice.has_bot (\ud835\udd44 n) := \u27e8\u27e8\u27e8\u22a5,\u22a5\u27e9,\u2119.bot_angle \u22a5\u27e9\u27e9\n\n/-- The only element of `\ud835\udd44 0` is `\u22a5`. -/\nlemma mem_zero (AB : \ud835\udd44 0) : AB = \u22a5 := \nbegin\n  apply subtype.eq, \n  apply prod.ext, \n  { rw [\u2119.mem_zero AB.val.1], refl },\n  { rw [\u2119.mem_zero AB.val.2], refl }\nend\n\ninstance : fintype (\ud835\udd44 n) := by { unfold \ud835\udd44, apply_instance }\n\ninstance : decidable_rel (\u03bb (AB CD : \ud835\udd44 n), AB \u2264 CD) := \n \u03bb \u27e8\u27e8A,B\u27e9,hAB\u27e9 \u27e8\u27e8C,D\u27e9,hCD\u27e9, \n  by { change decidable ((A \u2264 C) \u2227 (B \u2264 D)), apply_instance, }\n\nend \ud835\udd44 \n\nvariable {n} \n\n/-- LaTeX : defn-doubly-localising-alt -/\ndef \u03c3 : poset.hom (\ud835\udd44 n) (\u2119 n) := \n \u27e8\u03bb \u27e8\u27e8A,B\u27e9,hAB\u27e9, A \u2294 B,\n  \u03bb \u27e8\u27e8A,B\u27e9,hAB\u27e9 \u27e8\u27e8C,D\u27e9,hCD\u27e9 \u27e8hAC,hBD\u27e9, lattice.sup_le_sup hAC hBD\u27e9 \n\ndef \u03b6 : poset.hom (\u2119 n) (\ud835\udd44 n) := \n \u27e8\u03bb B, \u27e8\u27e8\u22a5,B\u27e9,B.bot_angle\u27e9, \u03bb B D hBD, \u27e8le_refl \u22a5,hBD\u27e9\u27e9\n\ndef \u03be : poset.hom (\u2119 n) (\ud835\udd44 n) := \n \u27e8\u03bb A, \u27e8\u27e8A,\u22a5\u27e9,A.angle_bot\u27e9, \u03bb A C hAC, \u27e8hAC,le_refl \u22a5\u27e9\u27e9 \n\nlemma half_step (i : \u2115) : \n  (i / 2) \u2264 ((i + 1) / 2) \u2227 \n  ((i + 1) / 2) \u2264 (i / 2) + 1 := \nbegin\n  split,\n  exact nat.div_le_div_right (le_of_lt i.lt_succ_self),\n  exact calc \n    (i + 1) / 2 \u2264 (i + 2) / 2 : \n          nat.div_le_div_right (le_of_lt i.succ.lt_succ_self)\n    ... = (i / 2) + 1 : nat.add_div_right i two_pos'\nend\n\nlemma half_misc (i : \u2115) :\n  ((2 * i) / 2) = i \u2227 \n  ((2 * i + 1) / 2) = i \u2227 \n  ((2 * i + 2) / 2) = i + 1 \u2227 \n  ((2 * i + 3) / 2) = i + 1 :=\nbegin\n  have h\u2081 : 1 / 2 = 0 := rfl,\n  have h\u2082 : 2 / 2 = 1 := rfl,\n  have h\u2083 : 3 / 2 = 1 := rfl,\n  rw [mul_comm, \n      add_comm _ 1, add_comm _ 2, add_comm _ 3,\n      nat.mul_div_cancel i two_pos',\n      nat.add_mul_div_right 1 i two_pos', \n      nat.add_mul_div_right 2 i two_pos', \n      nat.add_mul_div_right 3 i two_pos', \n      h\u2081, h\u2082, h\u2083, zero_add, add_comm 1],\n  repeat {split}; refl\nend\n\n/-- LaTeX: defn-al-bt -/\ndef \u03b1 (i : \u2115) : hom (\ud835\udd44 n) (\ud835\udd44 n) := \n\u27e8\u03bb ABh,\n \u27e8\u27e8ABh.val.1.filter_lt ((i + 1)/2),\n  ABh.val.1.filter_ge (i / 2) \u2294 ABh.val.2\u27e9,\n  begin -- Proof that we have an element of \ud835\udd44 n\n    rcases ABh with \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n    let u := (i + 1) / 2,\n    let v := i / 2,\n    rcases half_step i with \u27e8hvu,huv\u27e9,\n    change (A.filter_lt u) \u221f ((A.filter_ge v) \u2294 B),\n    rw[\u2119.angle_sup],\n    split,\n    { exact \u2119.filter_angle huv A },\n    { exact \u2119.angle_mono (A.filter_lt_is_le u) (le_refl _) h_angle } \n  end\u27e9,\n begin -- Proof of monotonicity\n   rintro \u27e8\u27e8A\u2080,B\u2080\u27e9,h_angle\u2080\u27e9 \u27e8\u27e8A\u2081,B\u2081\u27e9,h_angle\u2081\u27e9 \u27e8hA,hB\u27e9,\n   let u := (i + 1) / 2,\n   let v := i / 2,\n   change \n    (A\u2080.filter_lt u \u2264 A\u2081.filter_lt u) \u2227 \n    (A\u2080.filter_ge v \u2294 B\u2080) \u2264 (A\u2081.filter_ge v \u2294 B\u2081),\n   split; intros x hx,\n   { rw[\u2119.mem_filter_lt] at hx \u22a2, exact \u27e8hA hx.1,hx.2\u27e9 },\n   { rw [\u2119.mem_sup, \u2119.mem_filter_ge] at hx \u22a2, \n     rcases hx with hxA | hxB,\n     { exact or.inl \u27e8hA hxA.1,hxA.2\u27e9 },\n     { exact or.inr (hB hxB) } }\n end\u27e9 \n\ndef \u03b2 (i : \u2115) : hom (\ud835\udd44 n) (\ud835\udd44 n) := \n\u27e8\u03bb ABh,\n \u27e8\u27e8ABh.val.1 \u2294 ABh.val.2.filter_lt ((i + 1)/2),\n  ABh.val.2.filter_ge (i / 2)\u27e9,\n  begin -- Proof that we have an element of \ud835\udd44 n\n    rcases ABh with \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n    let u := (i + 1) / 2,\n    let v := i / 2,\n    rcases half_step i with \u27e8hvu,huv\u27e9,\n    change (A \u2294 B.filter_lt u) \u221f (B.filter_ge v),\n    rw[\u2119.sup_angle],\n    split,\n    { exact \u2119.angle_mono (le_refl A) (B.filter_ge_is_le v) h_angle },\n    { exact \u2119.filter_angle huv B }\n  end\u27e9,\n begin -- Proof of monotonicity\n   rintro \u27e8\u27e8A\u2080,B\u2080\u27e9,h_angle\u2080\u27e9 \u27e8\u27e8A\u2081,B\u2081\u27e9,h_angle\u2081\u27e9 \u27e8hA,hB\u27e9,\n   let u := (i + 1) / 2,\n   let v := i / 2,\n   change \n    (A\u2080 \u2294 B\u2080.filter_lt u \u2264 A\u2081 \u2294 B\u2081.filter_lt u) \u2227 \n    (B\u2080.filter_ge v) \u2264 (B\u2081.filter_ge v),\n   split; intros x hx,\n   { rw [\u2119.mem_sup, \u2119.mem_filter_lt] at hx \u22a2, \n     rcases hx with hxA | hxB,\n     { exact or.inl (hA hxA) },\n     { exact or.inr \u27e8hB hxB.1,hxB.2\u27e9 } },\n   { rw[\u2119.mem_filter_ge] at hx \u22a2, exact \u27e8hB hx.1,hx.2\u27e9 }\n end\u27e9 \n\n/-- The relation `\u03c3 \u03b1\u1d62 = \u03c3` -/\nlemma \u03c3\u03b1 (i : \u2115) : poset.comp (@\u03c3 n) (@\u03b1 n i) = @\u03c3 n :=\nbegin\n apply poset.hom_ext, \n rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9, \n let u := (i + 1) / 2,\n let v := i / 2,\n rcases half_step i with \u27e8hvu,huv\u27e9,\n rw[poset.comp],\n change (A.filter_lt u) \u2294 ((A.filter_ge v) \u2294 B) = A \u2294 B,\n rw [\u2190 lattice.sup_assoc, \u2119.filter_sup hvu A]\nend\n\n/-- The relation `\u03c3 \u03b2\u1d62 = \u03c3` -/\nlemma \u03c3\u03b2 (i : \u2115) : poset.comp (@\u03c3 n) (@\u03b2 n i) = @\u03c3 n :=\nbegin\n apply poset.hom_ext, \n rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9, \n let u := (i + 1) / 2,\n let v := i / 2,\n rcases half_step i with \u27e8hvu,huv\u27e9,\n rw[poset.comp],\n change (A \u2294 B.filter_lt u) \u2294 (B.filter_ge v) = A \u2294 B,\n rw [lattice.sup_assoc, \u2119.filter_sup hvu B]\nend\n\n/-- The relation `\u03b1\u2080 \u27e8A,B\u27e9 = \u27e8\u22a5, A\u2294 B\u27e9` -/\nlemma \u03b1_zero : (@\u03b1 n 0) = poset.comp (@\u03b6 n) (@\u03c3 n) := \nbegin\n  apply poset.hom_ext, \n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9, \n  rw[poset.comp],\n  apply subtype.eq,\n  change prod.mk (A.filter_lt 0) ((A.filter_ge 0) \u2294 B) = \n         prod.mk \u22a5 (A \u2294 B),\n  rw[\u2119.filter_lt_zero, \u2119.filter_ge_zero]\nend\n\n/-- The relation `\u03b1\u1d62 = 1` for `i \u2265 2n` -/\nlemma \u03b1_last {i : \u2115} (hi : i \u2265 2 * n) :\n  (@\u03b1 n i) = poset.id _ := \nbegin\n  apply poset.hom_ext, \n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9, \n  rw[poset.id],\n  apply subtype.eq,\n  let u := (i + 1) / 2,\n  let v := i / 2,\n  have hv : v \u2265 n := calc \n    n = (2 * n) / 2 : by rw [mul_comm, nat.mul_div_cancel n two_pos']\n    ... \u2264 v : nat.div_le_div_right hi,\n  have hu : u \u2265 n :=\n   le_trans hv (nat.div_le_div_right (le_of_lt i.lt_succ_self)),\n  change prod.mk (A.filter_lt u) ((A.filter_ge v) \u2294 B) = \n         prod.mk A B,\n  rw [\u2119.filter_lt_last hu, \u2119.filter_ge_last hv],\n  congr,\n  exact @lattice.bot_sup_eq _ _ B,\nend\n\n/-- The relation `\u03b2\u2080 = 1` -/\nlemma \u03b2_zero : (@\u03b2 n 0) = poset.id _ := \nbegin\n  apply poset.hom_ext, \n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9, \n  rw[poset.id],\n  apply subtype.eq,\n  change prod.mk (A \u2294 B.filter_lt 0) (B.filter_ge 0) = \n         prod.mk A B,\n  rw[\u2119.filter_lt_zero, \u2119.filter_ge_zero],\n  congr,\n  exact @lattice.sup_bot_eq _ _ A,\nend\n\n/-- The relation `\u03b2\u1d62 \u27e8A,B\u27e9 = \u27e8A\u2294 B, \u22a5\u27e9` for `i \u2265 2n` -/\nlemma \u03b2_last {i : \u2115} (hi : i \u2265 2 * n) :\n  (@\u03b2 n i) = poset.comp (@\u03be n) (@\u03c3 n)  := \nbegin\n  apply poset.hom_ext, \n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9, \n  rw [poset.comp],\n  apply subtype.eq,\n  let u := (i + 1) / 2,\n  let v := i / 2,\n  have hv : v \u2265 n := calc \n    n = (2 * n) / 2 : by rw [mul_comm, nat.mul_div_cancel n two_pos']\n    ... \u2264 v : nat.div_le_div_right hi,\n  have hu : u \u2265 n :=\n   le_trans hv (nat.div_le_div_right (le_of_lt i.lt_succ_self)),\n  change prod.mk (A \u2294 B.filter_lt u) (B.filter_ge v) = \n         prod.mk (A \u2294 B) \u22a5,\n  rw [\u2119.filter_lt_last hu, \u2119.filter_ge_last hv]\nend\n\n/-- The inequality `\u03b1\u2082\u1d62 \u2264 \u03b1\u2082\u1d62\u208a\u2081` -/\nlemma \u03b1_even_step (i : \u2115) : (@\u03b1 n (2 * i)) \u2264 (@\u03b1 n (2 * i + 1)) := \nbegin\n  rcases half_misc i with \u27e8h\u2080,h\u2081,h\u2082,h\u2083\u27e9,\n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n  change\n   ((A.filter_lt ((2*i+1)/2) \u2264 (A.filter_lt ((2*i+2)/2))) \u2227 \n    (A.filter_ge ((2*i)/2) \u2294 B  \u2264 (A.filter_ge ((2*i+1)/2)) \u2294 B)),\n  rw [h\u2080, h\u2081, h\u2082],\n  split,\n  { intros x hx, \n    rw[\u2119.mem_filter_lt] at hx \u22a2, \n    exact \u27e8hx.1, lt_trans hx.2 i.lt_succ_self\u27e9 },\n  { exact le_refl _ }\nend\n\n/-- The inequality `\u03b1\u2082\u1d62\u208a\u2082 \u2264 \u03b1\u2082\u1d62\u208a\u2081` -/\nlemma \u03b1_odd_step (i : \u2115) : (@\u03b1 n (2 * i + 2)) \u2264 (@\u03b1 n (2 * i + 1)) := \nbegin\n  rcases half_misc i with \u27e8h\u2080,h\u2081,h\u2082,h\u2083\u27e9,\n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n  change\n   ((A.filter_lt ((2*i+3)/2) \u2264 (A.filter_lt ((2*i+2)/2))) \u2227 \n    (A.filter_ge ((2*i+2)/2) \u2294 B  \u2264 (A.filter_ge ((2*i+1)/2)) \u2294 B)),\n  rw [h\u2081, h\u2082, h\u2083],\n  split,\n  { exact le_refl _ },\n  { apply lattice.sup_le_sup _ (le_refl _),\n    intros x hx,\n    rw[\u2119.mem_filter_ge] at hx \u22a2, \n    exact \u27e8hx.1,le_trans (le_of_lt i.lt_succ_self) hx.2\u27e9 }\nend\n\n/-- The inequality `\u03b2\u2082\u1d62 \u2264 \u03b2\u2082\u1d62\u208a\u2081` -/\nlemma \u03b2_even_step (i : \u2115) : (@\u03b2 n (2 * i)) \u2264 (@\u03b2 n (2 * i + 1)) := \nbegin\n  rcases half_misc i with \u27e8h\u2080,h\u2081,h\u2082,h\u2083\u27e9,\n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n  change\n   ((A \u2294 B.filter_lt ((2*i+1)/2) \u2264 (A \u2294 B.filter_lt ((2*i+2)/2))) \u2227 \n    (B.filter_ge ((2*i)/2)  \u2264 (B.filter_ge ((2*i+1)/2)))),\n  rw [h\u2080, h\u2081, h\u2082],\n  split,\n  { apply lattice.sup_le_sup (le_refl _) _,\n    intros x hx, \n    rw[\u2119.mem_filter_lt] at hx \u22a2, \n    exact \u27e8hx.1, lt_trans hx.2 i.lt_succ_self\u27e9 },\n  { exact le_refl _ }\nend\n\n/-- The inequality `\u03b2\u2082\u1d62\u208a\u2081 \u2264 \u03b2\u2082\u1d62\u208a\u2081` -/\nlemma \u03b2_odd_step (i : \u2115) : (@\u03b2 n (2 * i + 2)) \u2264 (@\u03b2 n (2 * i + 1)) := \nbegin\n  rcases half_misc i with \u27e8h\u2080,h\u2081,h\u2082,h\u2083\u27e9,\n  rintro \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n  change\n   ((A \u2294 B.filter_lt ((2*i+3)/2) \u2264 (A \u2294 B.filter_lt ((2*i+2)/2))) \u2227 \n    (B.filter_ge ((2*i+2)/2)  \u2264 (B.filter_ge ((2*i+1)/2)))),\n  rw [h\u2081, h\u2082, h\u2083],\n  split,\n  { exact le_refl _ },\n  { intros x hx, \n    rw[\u2119.mem_filter_ge] at hx \u22a2, \n    exact \u27e8hx.1, le_trans (le_of_lt i.lt_succ_self) hx.2\u27e9 }\nend\n\n/-- All `\u03b1\u1d62` are in the identity component.  -/\nlemma \u03b1_component : \u2200 i, poset.component (@\u03b1 n i) = poset.id\u2095 _ := \nbegin\n  let c := \u03bb i, poset.component (@\u03b1 n i),\n  change \u2200 i, c i = poset.id\u2095 _,\n  have h_all : \u2200 i, c i = c 0 := \n    poset.zigzag \u03b1 \u03b1_even_step \u03b1_odd_step,\n  have : c (2 * n) = poset.id\u2095 _ := \n    congr_arg component (\u03b1_last (le_refl _)),\n  intro i,\n  exact ((h_all i).trans (h_all (2 * n)).symm).trans this \nend\n\n/-- All `\u03b2\u1d62` are in the identity component.  -/\nlemma \u03b2_component : \u2200 i, poset.component (@\u03b2 n i) = poset.id\u2095 _ := \nbegin\n  let c := \u03bb i, poset.component (@\u03b2 n i),\n  change \u2200 i, c i = poset.id\u2095 _,\n  have h_all : \u2200 i, c i = c 0 := \n    poset.zigzag \u03b2 \u03b2_even_step \u03b2_odd_step,\n  intro i,\n  have : c 0 = poset.id\u2095 _ := congr_arg component \u03b2_zero,\n  rw [\u2190 this],\n  exact h_all i\nend\n\n/-- `\u03b6\u03c3 = 1` up to strong homotopy  -/\nlemma \u03b6\u03c3_component : poset.component (poset.comp (@\u03b6 n) (@\u03c3 n)) = poset.id\u2095 _ := \n  (congr_arg poset.component (@\u03b1_zero n)).symm.trans (@\u03b1_component n 0)\n\n/-- `\ud835\udd43 n` is the poset of upper sets in `\ud835\udd44 n`.  This is \n  not mentioned explicitly in the LaTeX document, but is\n  there in the background.\n-/\ndef \ud835\udd43 (n : \u2115) := poset.upper (\ud835\udd44 n)\n\nnamespace \ud835\udd43 \n\ninstance : _root_.lattice.bounded_distrib_lattice (\ud835\udd43 n) := \n  @upper.bdl (\ud835\udd44 n) _ _ _ _\n\ninstance : partial_order (\ud835\udd44 n) := by apply_instance \n\ninstance \ud835\udd44_mem_\ud835\udd43 : has_mem (\ud835\udd44 n) (\ud835\udd43 n) := \n by { unfold \ud835\udd43, apply_instance }\n\nend \ud835\udd43 \n\n/-- LaTeX : defn-ostar -/\ndef omul0 (U V : finset (\u2119 n)) : finset (\ud835\udd44 n) := \n (U.bind (\u03bb A, V.image (\u03bb B, prod.mk A B))).subtype (\u03bb AB, AB.1 \u221f AB.2)\n\nlemma mem_omul0 (U V : finset (\u2119 n)) (AB : \ud835\udd44 n) : \n AB \u2208 omul0 U V \u2194 AB.val.1 \u2208 U \u2227 AB.val.2 \u2208 V := \nbegin\n rw[omul0,finset.mem_subtype],\n split,\n {intro h0,\n  rcases (finset.mem_bind.mp h0) with \u27e8A,\u27e8hAU,h1\u27e9\u27e9,\n  rcases (finset.mem_image.mp h1) with \u27e8B,\u27e8hBV,h2\u27e9\u27e9,\n  rw[\u2190 h2],\n  exact \u27e8hAU,hBV\u27e9,\n },\n {rcases AB with \u27e8\u27e8A,B\u27e9,hAB\u27e9,\n  rintros \u27e8hAU,hBV\u27e9,\n  apply finset.mem_bind.mpr,use A,use hAU,\n  apply finset.mem_image.mpr,use B,use hBV,\n }\nend\n\nlemma is_upper_omul0 {U V : finset (\u2119 n)}\n (hU : is_upper U) (hV : is_upper V) : is_upper (omul0 U V) := \nbegin\n rintros \u27e8\u27e8A\u2080,B\u2080\u27e9,hAB\u2080\u27e9 \u27e8\u27e8A\u2081,B\u2081\u27e9,hAB\u2081\u27e9 \u27e8h_le_A,h_le_B\u27e9 AB\u2080_in_omul,\n rcases (mem_omul0 U V _).mp AB\u2080_in_omul with \u27e8A\u2080_in_U,B\u2080_in_V\u27e9,\n apply (mem_omul0 U V _).mpr,\n simp only [],\n exact \u27e8hU A\u2080 A\u2081 h_le_A A\u2080_in_U,hV B\u2080 B\u2081 h_le_B B\u2080_in_V\u27e9,\nend\n\ndef omul : (\ud835\udd42 n) \u2192 (\ud835\udd42 n) \u2192 (\ud835\udd43 n) := \n \u03bb U V, \u27e8omul0 U.val V.val, is_upper_omul0 U.property V.property\u27e9 \n\nlemma mem_omul (U V : (\ud835\udd42 n)) (AB : \ud835\udd44 n) : \n AB \u2208 omul U V \u2194 AB.val.1 \u2208 U \u2227 AB.val.2 \u2208 V := \nmem_omul0 U.val V.val AB  \n\nlemma omul_mono\u2082 : \n \u2200 {U\u2080 U\u2081 V\u2080 V\u2081 : \ud835\udd42 n} (hU : U\u2080 \u2264 U\u2081) (hV : V\u2080 \u2264 V\u2081), \n  omul U\u2080 V\u2080 \u2264 omul U\u2081 V\u2081\n| \u27e8U\u2080,hU\u2080\u27e9 \u27e8U\u2081,hU\u2081\u27e9 \u27e8V\u2080,hV\u2080\u27e9 \u27e8V\u2081,hV\u2081\u27e9 hU hV \u27e8A,B\u27e9 h := \nbegin\n rcases (mem_omul0 U\u2081 V\u2081 \u27e8A,B\u27e9).mp h with \u27e8hAU,hBV\u27e9,\n apply (mem_omul0 U\u2080 V\u2080 \u27e8A,B\u27e9).mpr,\n exact \u27e8hU hAU,hV hBV\u27e9,\nend\n\ndef \u03c30 (W : \ud835\udd43 n) : \ud835\udd42 n := \n \u27e8W.val.image (@\u03c3 n),\n  begin\n   intros C C' h_le C_in_sg_W,\n   rcases finset.mem_image.mp C_in_sg_W with \u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h_mem,h_eq\u27e9,\n   let AB : \ud835\udd44 n := \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n   rcases \u2119.angle_iff.mp h_angle with \u27e8\u27e8\u27e8\u27e9\u27e9 | h\u27e9,\n   { rw[C.mem_zero] at *, rw[C'.mem_zero], exact C_in_sg_W },\n   { rcases h with \u27e8k,hA,hB\u27e9,\n     change (A \u222a B : finset _) = C at h_eq,\n     rw [\u2190 h_eq] at h_le,\n     let A' := C'.filter_lt k.val.succ,\n     let B' := C'.filter_ge k.val,\n     have h_angle' : A' \u221f B' := \u2119.filter_angle k.val.lt_succ_self C',\n     let AB' : \ud835\udd44 n := \u27e8\u27e8A',B'\u27e9,h_angle'\u27e9,\n     have h_le' : AB \u2264 AB' := \n     begin\n      split,\n      { intros a a_in_A, \n        exact finset.mem_filter.mpr\n          \u27e8h_le (finset.mem_union_left B a_in_A),\n           lt_of_le_of_lt (hA a_in_A) k.val.lt_succ_self\u27e9 },\n      { intros b b_in_B, \n        exact finset.mem_filter.mpr\n          \u27e8h_le (finset.mem_union_right A b_in_B),hB b_in_B\u27e9 }\n     end,\n     have h_mem' : AB' \u2208 W.val := W.property AB AB' h_le' h_mem,\n     have h_eq' :  (@\u03c3 n) AB' = C' := \n     begin \n       change A' \u222a B' = C',\n       ext c,\n       rw [finset.mem_union, \u2119.mem_filter_lt, \u2119.mem_filter_ge,\n           \u2190 and_or_distrib_left, nat.lt_succ_iff],\n       simp [le_total]\n     end,\n     exact finset.mem_image.mpr \u27e8AB',h_mem',h_eq'\u27e9\n   }\n  end\u27e9\n\ndef \u03c3' : poset.hom (\ud835\udd43 n) (\ud835\udd42 n) := \u27e8@\u03c30 n,\nbegin\n  rintro W\u2080 W\u2081 h_le C C_in_sg_W,\n  rcases finset.mem_image.mp C_in_sg_W with \u27e8AB,h_mem,h_eq\u27e9,\n  exact finset.mem_image.mpr \u27e8AB,h_le h_mem,h_eq\u27e9\nend\u27e9 \n\nlemma mem_\u03c3' (W : \ud835\udd43 n) (C : \u2119 n) : \n  C \u2208 @\u03c3' n W \u2194 \u2203 AB, AB \u2208 W \u2227 @\u03c3 n AB = C := \nbegin\n  change (C \u2208 W.val.image (@\u03c3 n) \u2194 _),\n  rw[finset.mem_image],\n  apply exists_congr,\n  intro AB, simp, refl,\nend\n\nlemma factor_\u03c3 (U V : \ud835\udd42 n) : U * V = @\u03c3' n (omul U V) := \nbegin\n  ext C,\n  rw [\ud835\udd42.mem_mul U V C, mem_\u03c3' (omul U V)],\n  split; intro h,\n  { rcases h with \u27e8A,B,A_in_U,B_in_V,h_angle,h_eq\u27e9, \n    use \u27e8\u27e8A,B\u27e9,h_angle\u27e9,\n    exact \u27e8(mem_omul U V \u27e8\u27e8A,B\u27e9,h_angle\u27e9).mpr \u27e8A_in_U,B_in_V\u27e9,h_eq\u27e9 },\n  { rcases h with \u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h_mem,h_eq\u27e9, \n    use A, use B,\n    replace h_mem := (mem_omul U V \u27e8\u27e8A,B\u27e9,h_angle\u27e9).mp h_mem,\n    change A \u2208 U \u2227 B \u2208 V at h_mem,\n    exact \u27e8h_mem.left,h_mem.right,h_angle,h_eq\u27e9 }\nend\n\n/-- LaTeX: lem-mu-u -/\nlemma mul_u (A B : \u2119 n) : (@\ud835\udd42.u n A) * (@\ud835\udd42.u n B) =\n  ite (A \u221f B) (@\ud835\udd42.u n (A \u2294 B)) \u22a4 := \nbegin\n  ext C, \n  rw [\ud835\udd42.mem_mul (@\ud835\udd42.u n A) (@\ud835\udd42.u n B) C],  \n  split; intro h,\n  { rcases h with \u27e8A',B',hA,hB,h_angle,h_union\u27e9, \n    rw [\ud835\udd42.mem_u] at hA hB,\n    have : A \u221f B := \u03bb a b ha hb, h_angle (hA ha) (hB hb),\n    rw [if_pos this, @\ud835\udd42.mem_u n (A \u2294 B) C, \u2190 h_union],\n    exact lattice.sup_le_sup hA hB },\n  { by_cases h_angle : A \u221f B, \n    { rw [if_pos h_angle, @\ud835\udd42.mem_u n] at h, \n      rcases (\u2119.angle_iff.mp h_angle) with \u27e8\u27e8\u27e9\u27e9 | \u27e8k,\u27e8hA,hB\u27e9\u27e9,\n      { use \u22a5, use \u22a5, \n        rw[\u2119.mem_zero A, \u2119.mem_zero B, \u2119.mem_zero C, \ud835\udd42.mem_u],\n        simp only [\u2119.bot_angle, le_refl, lattice.sup_bot_eq, true_and] },\n      { use C.filter_lt k.val.succ, \n        use C.filter_ge k.val,\n        rw [\ud835\udd42.mem_u, \ud835\udd42.mem_u],\n        have hA' : A \u2264 C.filter_lt k.val.succ := \u03bb a ha, \n         \u2119.mem_filter_lt.mpr\n           \u27e8h (finset.mem_union_left B ha),nat.lt_succ_iff.mpr (hA ha)\u27e9,\n        have hB' : B \u2264 C.filter_ge k.val := \u03bb b hb, \n         \u2119.mem_filter_ge.mpr\n           \u27e8h (finset.mem_union_right A hb),hB hb\u27e9,\n        exact \u27e8hA', hB', \n               \u2119.filter_angle k.val.lt_succ_self C,\n               \u2119.filter_sup (le_of_lt k.val.lt_succ_self) C\u27e9 } },\n    { rw [if_neg h_angle] at h,\n      exact (upper.not_mem_top C h).elim } }\nend\n\n/-- `\u03c3_slice U V` is the map from `U # V` to `U * V` whose\n  (co)finality is proved in prop-sg-final and prop-sg-cofinal.\n-/\ndef \u03c3_slice (U V : \ud835\udd42 n) : hom (omul U V).els (U * V).els := \n\u27e8 \u03bb ABh, \u27e8@\u03c3 n ABh.val, \n begin \n  rw [factor_\u03c3 U V],\n  exact finset.mem_image_of_mem _ ABh.property, \n end \u27e9,\n \u03bb ABh\u2080 ABh\u2081 h, \u03c3.property h \u27e9 \n\nnamespace \u03c3_slice\n\nvariables (U V : \ud835\udd42 n) (C : (U * V).els)\n\n/-- This is the map sending `A` to `C_{\u2264 max A}`, which is \n  used (but not named) in prop-sg-cofinal. -/\ndef \u03b7 : hom (\u2119 n) (\u2119 n) := \n\u27e8 \u03bb A, C.val.filter (\u03bb c, \u2203 a, a \u2208 A \u2227 c \u2264 a),\n  \u03bb A\u2080 A\u2081 h c hc, \n  begin \n    rw [finset.mem_filter] at *,\n    rcases hc with \u27e8hcC,\u27e8a,\u27e8haA,hca\u27e9\u27e9\u27e9,\n    exact \u27e8hcC,\u27e8a,\u27e8h haA,hca\u27e9\u27e9\u27e9\n  end\u27e9 \n\n/-- This is the map sending `A` to `C_{\u2265 min A}`, which is \n  used (but not named) in prop-sg-cofinal. -/\ndef \u03b8 : hom (\u2119 n) (\u2119 n) := \n\u27e8 \u03bb B, C.val.filter (\u03bb c, \u2203 b, b \u2208 B \u2227 b \u2264 c),\n  \u03bb B\u2080 B\u2081 h c hc, \n  begin \n    rw [finset.mem_filter] at *,\n    rcases hc with \u27e8hcC,\u27e8b,\u27e8hbB,hbc\u27e9\u27e9\u27e9,\n    exact \u27e8hcC,\u27e8b,\u27e8h hbB,hbc\u27e9\u27e9\u27e9\n  end\u27e9 \n\nlemma \u03b7_angle_\u03b8 (A B : \u2119 n) : A \u221f B \u2192 (\u03b7 U V C A) \u221f (\u03b8 U V C B) := \n\u03bb h_angle x y hx hy, \nbegin \n  rcases (finset.mem_filter.mp hx).right with \u27e8a,\u27e8haA,hxa\u27e9\u27e9,\n  rcases (finset.mem_filter.mp hy).right with \u27e8b,\u27e8hbB,hby\u27e9\u27e9,\n  exact le_trans (le_trans hxa (h_angle haA hbB)) hby,\nend\n\ndef \u03c6\u2080 : hom (\ud835\udd44 n) (\ud835\udd44 n) := \n\u27e8\u03bb AB, \u27e8\u27e8\u03b7 U V C AB.val.1,\u03b8 U V C AB.val.2\u27e9, \n        \u03b7_angle_\u03b8 U V C AB.val.1 AB.val.2 AB.property\u27e9,\n \u03bb \u27e8\u27e8A\u2080,B\u2080\u27e9,h_angle\u2080\u27e9 \u27e8\u27e8A\u2081,B\u2081\u27e9,h_angle\u2081\u27e9 h,\n begin \n   change A\u2080 \u2264 A\u2081 \u2227 B\u2080 \u2264 B\u2081 at h,\n   change ((\u03b7 U V C A\u2080) \u2264 (\u03b7 U V C A\u2081)) \u2227 \n          ((\u03b8 U V C B\u2080) \u2264 (\u03b8 U V C B\u2081)),\n   exact \u27e8(\u03b7 U V C).property h.left,(\u03b8 U V C).property h.right\u27e9\n end\u27e9\n\n/-- This is the main map used in prop-sg-cofinal -/\ndef \u03c6 : hom (comma (\u03c3_slice U V) C) (comma (\u03c3_slice U V) C) := \n\u27e8 \u03bb X, \n  \u27e8\u27e8\u03c6\u2080 U V C X.val.val,\n    begin \n      rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h_omul\u27e9,hABC\u27e9,\n      rcases (mem_omul U V _).mp h_omul with \u27e8hAU,hBV\u27e9,\n      have hABC' : A \u2294 B \u2264 C.val := hABC,\n      rcases lattice.sup_le_iff.mp hABC' with \u27e8hAC,hBC\u27e9, \n      apply (mem_omul U V _).mpr,\n      let A\u2081 := \u03b7 U V C A,\n      let B\u2081 := \u03b8 U V C B,\n      change A\u2081 \u2208 U \u2227 B\u2081 \u2208 V,\n      split,\n      { have : A \u2264 A\u2081 := \u03bb a ha, \n          finset.mem_filter.mpr \u27e8hAC ha,\u27e8a,\u27e8ha,le_refl a\u27e9\u27e9\u27e9,\n          exact U.property A A\u2081 this hAU },\n      { have : B \u2264 B\u2081 := \u03bb b hb, \n          finset.mem_filter.mpr \u27e8hBC hb,\u27e8b,\u27e8hb,le_refl b\u27e9\u27e9\u27e9,\n          exact V.property B B\u2081 this hBV }\n    end\u27e9, \n    begin \n      rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h_omul\u27e9,hABC\u27e9,\n      change (\u03b7 U V C A) \u2294 (\u03b8 U V C B) \u2264 C.val,\n      intros x hx,\n      rcases finset.mem_union.mp hx with hx' | hx';\n      exact (finset.mem_filter.mp hx').left,\n    end\u27e9, \n  begin\n    rintro \u27e8\u27e8AB\u2080,h_omul\u2080\u27e9,hABC\u2080\u27e9 \u27e8\u27e8AB\u2081,h_omul\u2081\u27e9,hABC\u2081\u27e9 h,\n    exact (\u03c6\u2080 U V C).property (h : AB\u2080 \u2264 AB\u2081),\n  end\u27e9 \n\nlemma id_le_\u03c6 : (id (comma (\u03c3_slice U V) C)) \u2264 (\u03c6 U V C) := \nbegin\n  intro X,\n  rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h_omul\u27e9,hABC\u27e9,\n  change A \u221f B at h_angle,\n  rcases (mem_omul U V _).mp h_omul with \u27e8hAU,hBV\u27e9,\n  change A \u2208 U at hAU, change B \u2208 V at hBV, \n  change A \u2294 B \u2264 C.val at hABC,\n  rcases lattice.sup_le_iff.mp hABC with \u27e8hAC,hBC\u27e9,\n  change (A \u2264 \u03b7 U V C A) \u2227 (B \u2264 \u03b8 U V C B),\n  split, \n  { intros a ha, \n    exact finset.mem_filter.mpr \u27e8hAC ha, \u27e8a,\u27e8ha,le_refl a\u27e9\u27e9\u27e9, },\n  { intros b hb, \n    exact finset.mem_filter.mpr \u27e8hBC hb, \u27e8b,\u27e8hb,le_refl b\u27e9\u27e9\u27e9, },\nend\n\n/-- The proof of prop-sg-cofinal uses a pair of natural \n  numbers `i` and `j` with certain properties.  The definition\n  below encapsulates these properties.\n-/\ndef ij_spec (i j : \u2115) := \n    i \u2264 n \u2227 j \u2264 n \u2227 \n    C.val.filter_lt i \u2208 U \u2227 \n    C.val.filter_ge j \u2208 V \u2227 \n    (\u2200 k, k \u2264 n \u2192 C.val.filter_lt k \u2208 U \u2192 i \u2264 k) \u2227 \n    (\u2200 k, k \u2264 n \u2192 C.val.filter_ge k \u2208 V \u2192 k \u2264 j) \u2227 \n    i \u2264 j + 1\n\n/-- We now prove that a pair of numbers with the required\n  properties exists.  Note that this is formulated as a \n  bare existence statement, from which we cannot extract a \n  witness.  A constructive version would be possible but \n  would require a little reorganisation.  \n-/\n\nlemma ij_exists  :\n \u2203 i j : \u2115, ij_spec U V C i j := \nbegin \n  rcases C with \u27e8C,hC\u27e9,\n  rcases (\ud835\udd42.mem_mul U V C).mp hC with \u27e8A\u2080,B\u2080,hA\u2080,hB\u2080,h_angle\u2080,h_eq\u2080\u27e9,\n  have hAC\u2080 : A\u2080 \u2264 C := by { rw[\u2190 h_eq\u2080], exact lattice.le_sup_left },\n  have hBC\u2080 : B\u2080 \u2264 C := by { rw[\u2190 h_eq\u2080], exact lattice.le_sup_right },\n  let i_prop : fin n.succ \u2192 Prop := \u03bb i, C.filter_lt i.val \u2208 U,\n  let j_prop : fin n.succ \u2192 Prop := \u03bb j, C.filter_ge j \u2208 V,\n  let k_zero : fin n.succ := \u27e80, n.zero_lt_succ\u27e9,\n  let k_last : fin n.succ := \u27e8n, n.lt_succ_self\u27e9,\n  have i_prop_last : i_prop k_last := \n  begin\n    have : A\u2080 \u2264 C.filter_lt n := \n      \u03bb a ha, \u2119.mem_filter_lt.mpr \u27e8hAC\u2080 ha, a.is_lt\u27e9,\n    exact U.property A\u2080 _ this hA\u2080,\n  end,\n  have j_prop_zero : j_prop k_zero := \n  begin\n    have : B\u2080 \u2264 C.filter_ge 0 := \n      \u03bb b hb, \u2119.mem_filter_ge.mpr \u27e8hBC\u2080 hb, nat.zero_le _\u27e9,\n    exact V.property B\u2080 _ this hB\u2080,\n  end,\n  have i_prop_last' : k_last \u2208 finset.univ.filter i_prop := \n      finset.mem_filter.mpr \u27e8finset.mem_univ k_last, i_prop_last\u27e9,\n  have j_prop_zero' : k_zero \u2208 finset.univ.filter j_prop := \n      finset.mem_filter.mpr \u27e8finset.mem_univ k_zero, j_prop_zero\u27e9,\n  rcases fin.finset_least_element\n    (finset.univ.filter i_prop) (finset.ne_empty_of_mem i_prop_last') \n      with \u27e8i,\u27e8i_prop_i',i_least'\u27e9\u27e9,\n  rcases fin.finset_largest_element\n    (finset.univ.filter j_prop) (finset.ne_empty_of_mem j_prop_zero')\n        with \u27e8j,\u27e8j_prop_j',j_largest'\u27e9\u27e9,\n  let i_prop_i := (finset.mem_filter.mp i_prop_i').right,\n  let j_prop_j := (finset.mem_filter.mp j_prop_j').right,\n  have i_least : \u2200 (k : fin n.succ) (hk : i_prop k), i \u2264 k := \n    \u03bb k hk, i_least' k (finset.mem_filter.mpr \u27e8finset.mem_univ _,hk\u27e9),\n  have j_largest : \u2200 (k : fin n.succ) (hk : j_prop k), k \u2264 j := \n    \u03bb k hk, j_largest' k (finset.mem_filter.mpr \u27e8finset.mem_univ _,hk\u27e9),\n  use i.val, use j.val,\n  split, exact nat.le_of_lt_succ i.is_lt,\n  split, exact nat.le_of_lt_succ j.is_lt,\n  split, exact i_prop_i,\n  split, exact j_prop_j,\n  split, \n  { intros k hkn hk,\n    exact i_least \u27e8k, nat.lt_succ_of_le hkn\u27e9 hk },\n  split, \n  { intros k hkn hk,\n    exact j_largest \u27e8k, nat.lt_succ_of_le hkn\u27e9 hk },\n  rcases \u2119.angle_iff.mp h_angle\u2080 with \u27e8\u27e8\u27e9\u27e9 | \u27e8k,hkA\u2080,hkB\u2080\u27e9,\n  { apply le_add_left, exact le_of_lt i.is_lt },\n  { let k\u2080 : fin n.succ := \u27e8k.val, lt_trans k.is_lt n.lt_succ_self\u27e9,\n    let k\u2081 : fin n.succ := \u27e8k.val.succ, nat.succ_lt_succ k.is_lt\u27e9,\n    have i_prop_k : i_prop k\u2081 :=  \n    begin\n      have : A\u2080 \u2264 C.filter_lt k\u2081 := \n      \u03bb i hi, \u2119.mem_filter_lt.mpr\n        \u27e8by { rw[\u2190 h_eq\u2080], exact finset.mem_union_left B\u2080 hi}, \n         nat.lt_succ_of_le (hkA\u2080 hi) \u27e9,\n      exact U.property A\u2080 (C.filter_lt k\u2081) this hA\u2080,\n    end,\n    have j_prop_k : j_prop k\u2080 := \n    begin\n      have : B\u2080 \u2264 C.filter_ge k\u2080 := \n      \u03bb i hi, \u2119.mem_filter_ge.mpr\n        \u27e8by { rw[\u2190 h_eq\u2080], exact finset.mem_union_right A\u2080 hi}, \n         hkB\u2080 hi \u27e9,\n      exact V.property B\u2080 (C.filter_ge k.val) this hB\u2080,\n    end,\n    have hik : i.val \u2264 k.val + 1 := i_least k\u2081 i_prop_k,\n    have hkj : k.val \u2264 j.val := j_largest k\u2080 j_prop_k,\n    exact le_trans hik (nat.succ_le_succ hkj) },\nend\n\nsection with_ij\n/-- In this section, we assume that we are given `i` and `j`,\n  together with a proof of the required properties.  \n  Only in the final part of the proof do we invoke `ij_exists`.\n-/\n\nvariables (i j : \u2115) (h : ij_spec U V C i j) \ninclude i j h\n\n/-- This is the basepoint to which we will contract the comma poset. -/\ndef base : comma (\u03c3_slice U V) C := \nbegin\n  rcases h with \u27e8hi_is_le,hj_is_le,hiU,hjV,hi,hj,hij\u27e9,\n  let A\u2081 := C.val.filter_lt i,\n  let B\u2081 := C.val.filter_ge j,\n  have hA\u2081 : A\u2081 \u2208 U := hiU,\n  have hB\u2081 : B\u2081 \u2208 V := hjV,\n  have h_angle\u2081 : A\u2081 \u221f B\u2081 := \u03bb a b ha hb, \n    nat.le_of_lt_succ $\n    calc \n      a.val < i : (finset.mem_filter.mp ha).right\n      ... \u2264 j + 1 : hij \n      ... \u2264 b.val + 1 : nat.succ_le_succ (finset.mem_filter.mp hb).right,\n  let AB\u2081 : \ud835\udd44 n := \u27e8\u27e8A\u2081,B\u2081\u27e9,h_angle\u2081\u27e9,\n  let AB\u2082 : (omul U V).els := \u27e8AB\u2081,(mem_omul U V AB\u2081).mpr \u27e8hA\u2081,hB\u2081\u27e9\u27e9,\n  have hABC : \u03c3_slice U V AB\u2082 \u2264 C := \n  begin\n    let hAC : A\u2081 \u2264 C.val := \u2119.filter_lt_is_le i C.val,\n    let hBC : B\u2081 \u2264 C.val := \u2119.filter_ge_is_le j C.val,\n    exact lattice.sup_le hAC hBC,\n  end,\n  exact \u27e8AB\u2082, hABC\u27e9\nend\n\n/-- The values of the map `\u03c6` lie above the basepoint. -/\nlemma base_le_\u03c6 (X : (comma (\u03c3_slice U V) C)) : \n    base U V C i j h \u2264 (\u03c6 U V C).val X := \nbegin\n  rcases h with \u27e8hi_is_le,hj_is_le,hiU,hjV,hi,hj,hij\u27e9,\n  rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h_omul\u27e9,hABC\u27e9,\n  change A \u221f B at h_angle,\n  rcases (mem_omul U V _).mp h_omul with \u27e8hAU,hBV\u27e9,\n  change A \u2208 U at hAU, change B \u2208 V at hBV, \n  change A \u2294 B \u2264 C.val at hABC,\n  rcases lattice.sup_le_iff.mp hABC with \u27e8hAC,hBC\u27e9,\n  have hi' : ((C.val.filter_lt i) \u2264 \u03b7 U V C A) := \n  begin \n    intros c hc, \n    rw [\u2119.mem_filter_lt] at hc,\n    apply finset.mem_filter.mpr,\n    split, {exact hc.left},\n    by_contradiction h,\n    rw [not_exists] at h,\n    have : A \u2264 C.val.filter_lt c.val := \u03bb a ha,\n    begin \n      rw [\u2119.mem_filter_lt],\n      exact \u27e8hAC ha, lt_of_not_ge (\u03bb h\u2080, h a \u27e8ha,h\u2080\u27e9)\u27e9,\n    end, \n    have : C.val.filter_lt c.val \u2208 U :=\n      U.property A (C.val.filter_lt c.val) this hAU,\n    have : i \u2264 c.val := hi c.val (le_of_lt c.is_lt) this,\n    exact not_lt_of_ge this hc.right,\n  end,\n  have hj' : ((C.val.filter_ge j) \u2264 \u03b8 U V C B) := \n  begin \n    intros c hc, \n    rw [\u2119.mem_filter_ge] at hc,\n    apply finset.mem_filter.mpr,\n    split, {exact hc.left},\n    by_contradiction h,\n    rw [not_exists] at h,\n    have : B \u2264 C.val.filter_ge c.val.succ := \u03bb b hb,\n    begin \n      rw [\u2119.mem_filter_ge],\n      exact \u27e8hBC hb, le_of_not_gt (\u03bb h\u2080, h b \u27e8hb, nat.le_of_lt_succ h\u2080\u27e9)\u27e9,\n    end, \n    have : C.val.filter_ge c.val.succ \u2208 V :=\n      V.property B (C.val.filter_ge c.val.succ) this hBV,\n    have : c.val < j := hj c.val.succ c.is_lt this,\n    exact not_le_of_gt this hc.right,\n  end,\n  exact \u27e8hi',hj'\u27e9\nend\n\nend with_ij\n\n/-- LaTeX: prop-sg-cofinal -/\ntheorem cofinal : cofinal\u2095 (\u03c3_slice U V) := \nbegin\n  intro C,\n  rcases ij_exists U V C with \u27e8i,j,hij\u27e9,\n  let M := (comma (\u03c3_slice U V) C),\n  change nonempty (equiv\u2095 M unit),\n  let m : M := base U V C i j hij,\n  let f : hom M unit := const M unit.star,\n  let g : hom unit M := const unit m,\n  have hfg : comp f g = id unit := \n    by { ext p, rcases p, refl },\n  have gf_le_\u03c6 : comp g f \u2264 \u03c6 U V C := \n    \u03bb X, base_le_\u03c6 U V C i j hij X,\n  have hgf : comp\u2095 (component g) (component f) = id\u2095 M := \n    (\u03c0\u2080.sound gf_le_\u03c6).trans (\u03c0\u2080.sound (id_le_\u03c6 U V C)).symm,\n  let e : equiv\u2095 M unit := \n    { to_fun    := component f,\n      inv_fun   := component g, \n      left_inv  := hgf, \n      right_inv := congr_arg component hfg },\n  exact \u27e8e\u27e9\nend\n\n\n/-- The proof of prop-sg-final uses a number `k` with \n  certain properties.  We handle this in the same way as \n  the pair `\u27e8i,j\u27e9` in the previous proof.\n-/\ndef k_spec (k : \u2115) : Prop :=\n k \u2264 n \u2227 C.val.filter_lt k.succ \u2208 U \u2227 C.val.filter_ge k \u2208 V\n\nlemma k_exists : \u2203 (k : \u2115), k_spec U V C k := \nbegin\n  rcases C with \u27e8C,hC\u27e9,\n  rcases (\ud835\udd42.mem_mul U V C).mp hC with \u27e8A,B,hAU,hBV,h_angle,hABC\u27e9,\n  rcases \u2119.angle_iff.mp h_angle with \u27e8\u27e8\u27e9\u27e9 | \u27e8k,hkA,hkB\u27e9,\n  { use 0, \n    dsimp [k_spec],\n    rw [\u2119.mem_zero A] at hAU, \n    rw [\u2119.mem_zero B] at hBV, \n    rw [\u2119.mem_zero (C.filter_lt 1), \u2119.mem_zero (C.filter_ge 0)],\n    exact \u27e8le_refl 0, hAU, hBV\u27e9 },\n  { use k.val, \n    dsimp [k_spec],\n    split, { exact le_of_lt k.is_lt },\n    have hAC : A \u2264 C := by { rw[\u2190 hABC], exact lattice.le_sup_left  },\n    have hBC : B \u2264 C := by { rw[\u2190 hABC], exact lattice.le_sup_right },\n    let A' := C.filter_lt k.val.succ,\n    let B' := C.filter_ge k.val,\n    have hABC' : A' \u2294 B' = C :=\n      \u2119.filter_sup (le_of_lt k.val.lt_succ_self) C,\n    have h_angle' : A' \u221f B' := \u2119.filter_angle (le_refl _) C,\n    have hAA' : A \u2264 A' := \n     \u03bb a ha, \u2119.mem_filter_lt.mpr \u27e8hAC ha,nat.lt_succ_iff.mpr (hkA ha)\u27e9, \n    have hBB' : B \u2264 B' := \u03bb b hb, \u2119.mem_filter_ge.mpr \u27e8hBC hb,hkB hb\u27e9,\n    have hAU' : A' \u2208 U := U.property A A' hAA' hAU, \n    have hBV' : B' \u2208 V := V.property B B' hBB' hBV, \n    exact \u27e8hAU',hBV'\u27e9 }\nend\n\nsection with_k \n\nvariables (k : \u2115) (hk : k_spec U V C k)\ninclude k hk\n\n\n/-- The restrictions of `\u03b1\u1d62` and `\u03b2\u1d62` to the comma poset are \n  denoted by `\u03b1'` and `\u03b2'`.\n-/\ndef \u03b1' (i : \u2115) (hi : i > 2 * k) : \n  hom (cocomma (\u03c3_slice U V) C) (cocomma (\u03c3_slice U V) C) := \nlet u := (i + 1)/2 in let v := i / 2 in\n\u27e8 \u03bb x, \u27e8\u27e8(\u03b1 i).val x.val.val, \n  begin\n   have hu : u > k := \n   begin\n     have : 2 * k + 2 \u2264 i + 1 := nat.succ_le_succ hi,\n     have : (2 * k + 2) / 2 \u2264 u := nat.div_le_div_right this,\n     exact calc\n       k + 1 = ((k + 1) * 2) / 2 : \n         (nat.mul_div_cancel (k + 1) two_pos').symm\n       ... = (2 * k + 2) / 2 : by { rw [add_mul, one_mul, mul_comm] }\n       ... \u2264 u : this,\n   end,\n   rcases half_step i with \u27e8hvu,huv\u27e9,\n   rcases x with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h\u2080\u27e9,h\u2081\u27e9,\n   rcases (mem_omul U V _).mp h\u2080 with \u27e8hAU,hBV\u27e9,\n   rcases hk with \u27e8hkn,hkU,hkV\u27e9,\n   change A \u221f B at h_angle, \n   change A \u2208 U at hAU, change B \u2208 V at hBV,\n   change C.val \u2264 A \u2294 B at h\u2081, \n   apply (mem_omul U V _).mpr,\n   change A.filter_lt u \u2208 U \u2227 (A.filter_ge v \u2294 B) \u2208 V,\n   split,\n   { by_cases h : \u2203 (a : \ud835\udd40 n), a \u2208 A \u2227 a.val \u2265 u,\n     { rcases h with \u27e8a,ha\u27e9,\n       have : C.val.filter_lt k.succ \u2264 A.filter_lt u := \u03bb c hc,\n       begin\n         rcases \u2119.mem_filter_lt.mp hc with \u27e8hcC,hck\u27e9, \n         replace hck := nat.lt_succ_iff.mp hck,\n         have hcu : c.val < u := lt_of_le_of_lt hck hu,\n         rcases finset.mem_union.mp (h\u2081 hcC) with hcA | hcB,\n         { rw [\u2119.mem_filter_lt], exact \u27e8hcA,hcu\u27e9 },\n         { exfalso, \n           have hca : c.val < a.val := lt_of_lt_of_le hcu ha.right,\n           exact not_le_of_gt hca (h_angle ha.left hcB) }\n       end,\n       exact U.property (C.val.filter_lt k.succ) (A.filter_lt u) this hkU },\n     { have : A.filter_lt u = A := \n       begin\n         rw [not_exists] at h,\n         ext a,\n         rw [\u2119.mem_filter_lt],\n         split,\n         { exact \u03bb h, h.left },\n         { exact \u03bb ha, \u27e8ha, lt_of_not_ge (\u03bb h\u2080, h a \u27e8ha,h\u2080\u27e9)\u27e9 }\n       end,\n       rw [this], \n       exact hAU } },\n     { exact V.property B (A.filter_ge v \u2294 B) lattice.le_sup_right hBV } \n  end\u27e9, \n  begin \n    rcases half_step i with \u27e8hvu,huv\u27e9,\n    rcases x with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h\u2080\u27e9,h\u2081\u27e9,\n    change C.val \u2264 ((A.filter_lt u) \u2294 (A.filter_ge v \u2294 B)),\n    rw [\u2190 lattice.sup_assoc, \u2119.filter_sup hvu A],\n    exact h\u2081, \n  end\u27e9,\n begin \n   rintro \u27e8\u27e8X\u2080,_\u27e9,_\u27e9 \u27e8\u27e8X\u2081,_\u27e9,_\u27e9 h,\n   exact (\u03b1 i).property h\n end\u27e9 \n\ndef \u03b2' (i : \u2115) (hi : i \u2264 2 * k + 1) : \n  hom (cocomma (\u03c3_slice U V) C) (cocomma (\u03c3_slice U V) C) := \nlet u := (i + 1)/2 in let v := i / 2 in\n\u27e8 \u03bb x, \u27e8\u27e8(\u03b2 i).val x.val.val, \n  begin\n   have hv : i/2 \u2264 k := calc\n     i / 2 \u2264 (2 * k + 1) / 2 : nat.div_le_div_right hi\n     ... = k : (half_misc k).2.1,\n   rcases half_step i with \u27e8hvu,huv\u27e9,\n   rcases x with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h\u2080\u27e9,h\u2081\u27e9,\n   rcases (mem_omul U V _).mp h\u2080 with \u27e8hAU,hBV\u27e9,\n   rcases hk with \u27e8hkn,hkU,hkV\u27e9,\n   change A \u221f B at h_angle, \n   change A \u2208 U at hAU, change B \u2208 V at hBV,\n   change C.val \u2264 A \u2294 B at h\u2081, \n   apply (mem_omul U V _).mpr,\n   change A \u2294 B.filter_lt u \u2208 U \u2227 B.filter_ge v \u2208 V,\n   split,\n   { exact U.property A (A \u2294 B.filter_lt u) lattice.le_sup_left hAU }, \n   { by_cases h : \u2203 (b : \ud835\udd40 n), b \u2208 B \u2227 b.val < v,\n     { rcases h with \u27e8b,hb\u27e9,\n       have : C.val.filter_ge k \u2264 B.filter_ge v := \u03bb c hc,\n       begin\n         rcases \u2119.mem_filter_ge.mp hc with \u27e8hcC,hck\u27e9, \n         have hcu : c.val \u2265 v := le_trans hv hck,\n         rcases finset.mem_union.mp (h\u2081 hcC) with hcA | hcB,\n         { exfalso, \n           have hbc : b.val < c.val := lt_of_lt_of_le hb.right hcu,\n           exact not_le_of_gt hbc (h_angle hcA hb.left) },\n         { rw [\u2119.mem_filter_ge], exact \u27e8hcB,hcu\u27e9 }\n       end,\n       exact V.property (C.val.filter_ge k) (B.filter_ge v) this hkV },\n     { have : B.filter_ge v = B := \n       begin\n         rw [not_exists] at h,\n         ext a,\n         rw [\u2119.mem_filter_ge],\n         split,\n         { exact \u03bb h, h.left },\n         { exact \u03bb ha, \u27e8ha, le_of_not_gt (\u03bb h\u2080, h a \u27e8ha,h\u2080\u27e9)\u27e9 }\n       end,\n       rw [this], \n       exact hBV } },\n  end\u27e9, \n  begin \n    rcases half_step i with \u27e8hvu,huv\u27e9,\n    rcases x with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h_angle\u27e9,h\u2080\u27e9,h\u2081\u27e9,\n    change C.val \u2264 A \u2294 (B.filter_lt u) \u2294 (B.filter_ge v),\n    rw [lattice.sup_assoc, \u2119.filter_sup hvu B],\n    exact h\u2081, \n  end\u27e9,\n begin \n   rintro \u27e8\u27e8X\u2080,_\u27e9,_\u27e9 \u27e8\u27e8X\u2081,_\u27e9,_\u27e9 h,\n   exact (\u03b2 i).property h\n end\u27e9 \n\nlemma \u03b1'_last : \n  \u03b1' U V C k hk (2 * n + 1) \n   (lt_of_le_of_lt (nat.mul_le_mul_left 2 hk.1) (2 * n).lt_succ_self)\n     = poset.id _ :=\nbegin\n  ext X,\n  rcases X with \u27e8\u27e8Y,_\u27e9,_\u27e9,\n  apply subtype.eq,\n  apply subtype.eq,\n  change (\u03b1 (2 * n + 1)).val Y = Y,\n  rw [\u03b1_last (le_of_lt (2 * n).lt_succ_self)],\n  refl,\nend\n\nlemma \u03b2'_zero  : \n  \u03b2' U V C k hk 0 (nat.zero_le _) = poset.id _ := \nbegin\n  ext X,\n  rcases X with \u27e8\u27e8Y,_\u27e9,_\u27e9,\n  apply subtype.eq,\n  apply subtype.eq,\n  change (\u03b2 0).val Y = Y,\n  rw [\u03b2_zero],\n  refl,\nend\n\n/-- All the maps `\u03b1'` lie in the identity component. -/\nlemma \u03b1'_component : \n  \u2200 (i : \u2115) (hi : i > 2 * k), \n   component (\u03b1' U V C k hk i hi) = poset.id\u2095 _ := \nbegin\n  let c := \u03bb (i : \u2115) (hi : i > 2 * k), component (\u03b1' U V C k hk i hi),\n  change \u2200 (i : \u2115) (hi : i > 2 * k), c i hi = poset.id\u2095 _,\n  let u := \u03bb (i : \u2115), \u2200 (hi : i > 2 * k), \n                         c i hi = c (2 * k + 1) (2 * k).lt_succ_self,\n  have u_zero : u 0 := \u03bb hi, (nat.not_lt_zero _ hi).elim,\n  have u_even : \u2200 i, u (2 * i) \u2192 u (2 * i + 1) := \n  begin\n    intros i hu hm,\n    let hi : k \u2264 i :=\n      (mul_le_mul_left two_pos').mp (nat.le_of_succ_le_succ hm),\n    by_cases h : k = i,\n    { cases h, refl },\n    replace hi := lt_of_le_of_ne hi h, \n    have hm' : 2 * i > 2 * k := \n      (mul_lt_mul_left two_pos').mpr hi,\n    rw [\u2190 hu hm'], symmetry,\n    apply \u03c0\u2080.sound,\n    rintro \u27e8\u27e8X,_\u27e9,_\u27e9,\n    exact \u03b1_even_step i X  \n  end,\n  have u_odd : \u2200 i, u (2 * i + 1) \u2192 u (2 * i + 2) := \n  begin\n    intros i hu hm,\n    let hi := @nat.div_le_div_right _ _ (nat.le_of_succ_le_succ hm) 2,\n    rw [(half_misc k).1, (half_misc i).2.1] at hi,\n    have hm' : 2 * i + 1 > 2 * k := \n      lt_of_le_of_lt ((mul_le_mul_left two_pos').mpr hi) (2 * i).lt_succ_self,\n    rw [\u2190 hu hm'],\n    apply \u03c0\u2080.sound,\n    rintro \u27e8\u27e8X,_\u27e9,_\u27e9,\n    exact \u03b1_odd_step i X  \n  end,\n  have u_all := parity_induction u u_zero u_even u_odd,\n  have h : (2 * n + 1) > 2 * k := \n   lt_of_le_of_lt ((mul_le_mul_left two_pos').mpr hk.1) (2 * n).lt_succ_self, \n  have : c (2 * n + 1) h = poset.id\u2095 _ := \n    congr_arg component (\u03b1'_last U V C k hk),\n  intros i hi,\n  rw [\u2190 this, u_all i hi, u_all (2 * n + 1) h]\nend\n\n/-- All the maps `\u03b2'` lie in the identity component. -/\nlemma \u03b2'_component : \n  \u2200 (i : \u2115) (hi : i \u2264 2 * k + 1), \n   component (\u03b2' U V C k hk i hi) = poset.id\u2095 _ := \nbegin\n  let c := \u03bb (i : \u2115) (hi : i \u2264 2 * k + 1), component (\u03b2' U V C k hk i hi),\n  let u := \u03bb (i : \u2115), \u2200 (hi : i \u2264 2 * k + 1), c i hi = id\u2095 _,\n  change \u2200 (i : \u2115), u i,\n  have u_zero : u 0 := \u03bb _, congr_arg component (\u03b2'_zero U V C k hk),\n  have u_even : \u2200 i, u (2 * i) \u2192 u (2 * i + 1) := \n  begin\n    intros i hu hm,\n    have hm' := le_trans (le_of_lt (2 * i).lt_succ_self) hm,\n    rw [\u2190 hu hm'], symmetry,\n    apply \u03c0\u2080.sound,\n    rintro \u27e8\u27e8X,_\u27e9,_\u27e9,\n    exact \u03b2_even_step i X\n  end,\n  have u_odd : \u2200 i, u (2 * i + 1) \u2192 u (2 * i + 2) := \n  begin\n    intros i hu hm,\n    have hm' := le_trans (le_of_lt (2 * i + 1).lt_succ_self) hm,\n    rw [\u2190 hu hm'],\n    apply \u03c0\u2080.sound,\n    rintro \u27e8\u27e8X,_\u27e9,_\u27e9,\n    exact \u03b2_odd_step i X\n  end,\n  exact parity_induction u u_zero u_even u_odd\nend\n\ndef \u03b1_middle := \u03b1' U V C k hk (2 * k + 1) (2 * k).lt_succ_self\ndef \u03b2_middle := \u03b2' U V C k hk (2 * k + 1) (le_refl _)\n\ndef \u03b1_middle' : (\u2119 n) \u00d7 (\u2119 n) \u2192 (\u2119 n) \u00d7 (\u2119 n) := \n\u03bb AB, \u27e8AB.1.filter_lt k.succ,AB.1.filter_ge k \u2294 AB.2\u27e9 \n\ndef \u03b2_middle' : (\u2119 n) \u00d7 (\u2119 n) \u2192 (\u2119 n) \u00d7 (\u2119 n) := \n\u03bb AB, \u27e8AB.1 \u2294 AB.2.filter_lt k.succ,AB.2.filter_ge k\u27e9 \n\nlemma \u03b1_middle_val (X : cocomma (\u03c3_slice U V) C) : \n ((\u03b1_middle U V C k hk).val X).val.val.val = \n   \u03b1_middle' U V C k hk X.val.val.val := \nbegin\n  rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,_\u27e9,_\u27e9,_\u27e9, \n  change (prod.mk _ _) = (prod.mk _ _),\n  rcases half_misc k with \u27e8h\u2080,h\u2081,h\u2082,h\u2083\u27e9,\n  rw [h\u2081, h\u2082]\nend\n\nlemma \u03b2_middle_val (X : cocomma (\u03c3_slice U V) C) : \n ((\u03b2_middle U V C k hk).val X).val.val.val = \n   \u03b2_middle' U V C k hk X.val.val.val := \nbegin\n  rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,_\u27e9,_\u27e9,_\u27e9, \n  change (prod.mk _ _) = (prod.mk _ _),\n  rcases half_misc k with \u27e8h\u2080,h\u2081,h\u2082,h\u2083\u27e9,\n  rw [h\u2081, h\u2082]\nend\n\ndef \u03b1\u03b2_middle := \n comp (\u03b1_middle U V C k hk) (\u03b2_middle U V C k hk)\n\ndef \u03b1\u03b2_middle' : (\u2119 n) \u00d7 (\u2119 n) \u2192 (\u2119 n) \u00d7 (\u2119 n) := \n\u03bb AB, \u27e8(AB.1 \u2294 AB.2).filter_lt k.succ,\n       (AB.1 \u2294 AB.2).filter_ge k\u27e9 \n\nlemma \u03b1\u03b2_middle_val (X : cocomma (\u03c3_slice U V) C) : \n ((\u03b1\u03b2_middle U V C k hk).val X).val.val.val = \n   \u03b1\u03b2_middle' U V C k hk X.val.val.val := \nbegin\n  dsimp [\u03b1\u03b2_middle, comp],\n  rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,_\u27e9,_\u27e9,_\u27e9, \n  rw [\u03b1_middle_val, \u03b2_middle_val, \u03b1_middle', \u03b2_middle'],\n  change (prod.mk _ _) = (prod.mk _ _),\n  apply prod.ext ; simp only [],\n  { ext x, \n    simp [\u2119.mem_filter_lt, \u2119.mem_filter_ge, \u2119.mem_sup],\n    tauto },\n  { ext x, \n    simp [\u2119.mem_filter_lt, \u2119.mem_filter_ge, \u2119.mem_sup],\n    tauto },\nend\n\n/-- This defines the basepoint to which we will contract -/\ndef cobase : cocomma (\u03c3_slice U V) C := \n\u27e8\u27e8\u27e8\u27e8C.val.filter_lt k.succ,C.val.filter_ge k\u27e9,\n  \u2119.filter_angle (le_refl k.succ) C.val\u27e9,\n  (mem_omul U V _).mpr hk.2\u27e9,\n  begin\n    change _ \u2264 _ \u2294 _,\n    rw [\u2119.filter_sup (le_of_lt k.lt_succ_self) C.val], \n    exact le_refl C.val\n  end\u27e9\n\nlemma cocomma_order (X Y : cocomma (\u03c3_slice U V) C) : \n  X \u2264 Y \u2194 X.val.val.val \u2264 Y.val.val.val :=\nbegin\n  rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,u\u2080\u27e9,u\u2081\u27e9,u\u2082\u27e9,\n  rcases Y with \u27e8\u27e8\u27e8\u27e8C,D\u27e9,v\u2080\u27e9,v\u2081\u27e9,v\u2082\u27e9,\n  let X\u2080 : (\u2119 n) \u00d7 (\u2119 n) := \u27e8A,B\u27e9,\n  let Y\u2080 : (\u2119 n) \u00d7 (\u2119 n) := \u27e8C,D\u27e9,\n  change (X\u2080 \u2264 Y\u2080) \u2194 (A \u2264 C \u2227 B \u2264 D),\n  dsimp [X\u2080, Y\u2080], refl\nend\n\nlemma \u03b1\u03b2_middle_ge (X : cocomma (\u03c3_slice U V) C) : \n  (cobase U V C k hk) \u2264 ((\u03b1\u03b2_middle U V C k hk).val X) := \nbegin \n  let h := cocomma_order U V C k hk,\n  let hh := h (cobase U V C k hk) ((\u03b1\u03b2_middle U V C k hk).val X),\n  rw [hh, \u03b1\u03b2_middle_val, \u03b1\u03b2_middle', cobase],\n  rcases X with \u27e8\u27e8\u27e8\u27e8A,B\u27e9,h\u2080\u27e9,h\u2081\u27e9,h\u2082\u27e9,\n  let D := A \u2294 B,\n  change C.val \u2264 D at h\u2082, \n  change (C.val.filter_lt k.succ) \u2264 (D.filter_lt k.succ) \u2227 \n         (C.val.filter_ge k) \u2264 (D.filter_ge k),\n  split; intros x hx,\n  { rw[\u2119.mem_filter_lt] at hx \u22a2, exact \u27e8h\u2082 hx.1, hx.2\u27e9 }, \n  { rw[\u2119.mem_filter_ge] at hx \u22a2, exact \u27e8h\u2082 hx.1, hx.2\u27e9 } \nend\n\nend with_k\n\ntheorem final : final\u2095 (\u03c3_slice U V) := \nbegin\n  intro C,\n  let M := (cocomma (\u03c3_slice U V) C),\n  change nonempty (equiv\u2095 M unit),\n  let f : hom M unit := const M unit.star,\n  rcases k_exists U V C with \u27e8k, hk\u27e9,\n  let m := cobase U V C k hk,\n  let g : hom unit M := const unit m,\n  have hfg : comp f g = id unit := \n  by { ext t, rcases t, refl },\n  have hgf : component (comp g f) = id\u2095 _ := \n  begin \n   let gf\u2080 : hom M M := comp g f,\n   let gf\u2081 : hom M M := \u03b1\u03b2_middle U V C k hk,\n   let gf\u2082 : hom M M := poset.id _,\n   have : gf\u2080 \u2264 gf\u2081 := \u03bb X, \u03b1\u03b2_middle_ge U V C k hk X,\n   rw [\u03c0\u2080.sound this],\n   let u := component (\u03b1_middle U V C k hk),\n   let v := component (\u03b2_middle U V C k hk),\n   have huv : component gf\u2081 = comp\u2095 u v := rfl,\n   have : u = id\u2095 _ := \u03b1'_component U V C k hk (2 * k + 1) _,\n   rw [this] at huv,\n   have : v = id\u2095 _ := \u03b2'_component U V C k hk (2 * k + 1) _,\n   rw [this, comp_id\u2095] at huv,\n   exact huv,\n  end,\n  let e : equiv\u2095 M unit := \n  { to_fun := component f, inv_fun := component g,\n    left_inv := hgf, right_inv := congr_arg component hfg },\n  exact \u27e8e\u27e9 \nend\n\nend \u03c3_slice\n\nend itloc\n\n", "meta": {"author": "NeilStrickland", "repo": "itloc", "sha": "5b13b5b418766d10926b983eb3dd2ac42abf63d8", "save_path": "github-repos/lean/NeilStrickland-itloc", "path": "github-repos/lean/NeilStrickland-itloc/itloc-5b13b5b418766d10926b983eb3dd2ac42abf63d8/src/itloc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7468683095588045}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport order.monotone.odd\nimport analysis.special_functions.exp_deriv\nimport analysis.special_functions.trigonometric.basic\nimport data.set.intervals.monotone\n\n/-!\n# Differentiability of trigonometric functions\n\n## Main statements\n\nThe differentiability of the usual trigonometric functions is proved, and their derivatives are\ncomputed.\n\n## Tags\n\nsin, cos, tan, angle\n-/\n\nnoncomputable theory\nopen_locale classical topology filter\nopen set filter\n\nnamespace complex\n\n/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/\nlemma has_strict_deriv_at_sin (x : \u2102) : has_strict_deriv_at sin (cos x) x :=\nbegin\n  simp only [cos, div_eq_mul_inv],\n  convert ((((has_strict_deriv_at_id x).neg.mul_const I).cexp.sub\n    ((has_strict_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:\u2102)\u207b\u00b9,\n  simp only [function.comp, id],\n  rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,\n      I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]\nend\n\n/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/\nlemma has_deriv_at_sin (x : \u2102) : has_deriv_at sin (cos x) x :=\n(has_strict_deriv_at_sin x).has_deriv_at\n\nlemma cont_diff_sin {n} : cont_diff \u2102 n sin :=\n(((cont_diff_neg.mul cont_diff_const).cexp.sub\n  (cont_diff_id.mul cont_diff_const).cexp).mul cont_diff_const).div_const _\n\nlemma differentiable_sin : differentiable \u2102 sin :=\n\u03bbx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin {x : \u2102} : differentiable_at \u2102 sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ \u03bb x, (has_deriv_at_sin x).deriv\n\n/-- The complex cosine function is everywhere strictly differentiable, with the derivative\n`-sin x`. -/\nlemma has_strict_deriv_at_cos (x : \u2102) : has_strict_deriv_at cos (-sin x) x :=\nbegin\n  simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],\n  convert (((has_strict_deriv_at_id x).mul_const I).cexp.add\n    ((has_strict_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:\u2102)\u207b\u00b9,\n  simp only [function.comp, id],\n  ring\nend\n\n/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/\nlemma has_deriv_at_cos (x : \u2102) : has_deriv_at cos (-sin x) x :=\n(has_strict_deriv_at_cos x).has_deriv_at\n\nlemma cont_diff_cos {n} : cont_diff \u2102 n cos :=\n((cont_diff_id.mul cont_diff_const).cexp.add\n  (cont_diff_neg.mul cont_diff_const).cexp).div_const _\n\nlemma differentiable_cos : differentiable \u2102 cos :=\n\u03bbx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos {x : \u2102} : differentiable_at \u2102 cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos {x : \u2102} : deriv cos x = -sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (\u03bb x, -sin x) :=\nfunext $ \u03bb x, deriv_cos\n\n/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative\n`cosh x`. -/\nlemma has_strict_deriv_at_sinh (x : \u2102) : has_strict_deriv_at sinh (cosh x) x :=\nbegin\n  simp only [cosh, div_eq_mul_inv],\n  convert ((has_strict_deriv_at_exp x).sub (has_strict_deriv_at_id x).neg.cexp).mul_const (2:\u2102)\u207b\u00b9,\n  rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]\nend\n\n/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative\n`cosh x`. -/\nlemma has_deriv_at_sinh (x : \u2102) : has_deriv_at sinh (cosh x) x :=\n(has_strict_deriv_at_sinh x).has_deriv_at\n\nlemma cont_diff_sinh {n} : cont_diff \u2102 n sinh :=\n(cont_diff_exp.sub cont_diff_neg.cexp).div_const _\n\nlemma differentiable_sinh : differentiable \u2102 sinh :=\n\u03bbx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh {x : \u2102} : differentiable_at \u2102 sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ \u03bb x, (has_deriv_at_sinh x).deriv\n\n/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the\nderivative `sinh x`. -/\nlemma has_strict_deriv_at_cosh (x : \u2102) : has_strict_deriv_at cosh (sinh x) x :=\nbegin\n  simp only [sinh, div_eq_mul_inv],\n  convert ((has_strict_deriv_at_exp x).add (has_strict_deriv_at_id x).neg.cexp).mul_const (2:\u2102)\u207b\u00b9,\n  rw [id, mul_neg_one, sub_eq_add_neg]\nend\n\n/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative\n`sinh x`. -/\nlemma has_deriv_at_cosh (x : \u2102) : has_deriv_at cosh (sinh x) x :=\n(has_strict_deriv_at_cosh x).has_deriv_at\n\nlemma cont_diff_cosh {n} : cont_diff \u2102 n cosh :=\n(cont_diff_exp.add cont_diff_neg.cexp).div_const _\n\nlemma differentiable_cosh : differentiable \u2102 cosh :=\n\u03bbx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh {x : \u2102} : differentiable_at \u2102 cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ \u03bb x, (has_deriv_at_cosh x).deriv\n\nend complex\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, complex.cos (f x)` etc., `f : \u2102 \u2192 \u2102` -/\n\nvariables {f : \u2102 \u2192 \u2102} {f' x : \u2102} {s : set \u2102}\n\n/-! #### `complex.cos` -/\n\nlemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') x :=\n(complex.has_strict_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') x :=\n(complex.has_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=\n(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_ccos (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.ccos.deriv_within hxs\n\n@[simp] lemma deriv_ccos (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=\nhc.has_deriv_at.ccos.deriv\n\n/-! #### `complex.sin` -/\n\nlemma has_strict_deriv_at.csin (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') x :=\n(complex.has_strict_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_at.csin (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') x :=\n(complex.has_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') s x :=\n(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_csin (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.csin.deriv_within hxs\n\n@[simp] lemma deriv_csin (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=\nhc.has_deriv_at.csin.deriv\n\n/-! #### `complex.cosh` -/\n\nlemma has_strict_deriv_at.ccosh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=\n(complex.has_strict_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=\n(complex.has_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_ccosh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.ccosh.deriv_within hxs\n\n@[simp] lemma deriv_ccosh (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=\nhc.has_deriv_at.ccosh.deriv\n\n/-! #### `complex.sinh` -/\n\nlemma has_strict_deriv_at.csinh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=\n(complex.has_strict_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=\n(complex.has_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_csinh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.csinh.deriv_within hxs\n\n@[simp] lemma deriv_csinh (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=\nhc.has_deriv_at.csinh.deriv\n\nend\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, complex.cos (f x)` etc., `f : E \u2192 \u2102` -/\n\nvariables {E : Type*} [normed_add_comm_group E] [normed_space \u2102 E] {f : E \u2192 \u2102} {f' : E \u2192L[\u2102] \u2102}\n  {x : E} {s : set E}\n\n/-! #### `complex.cos` -/\n\nlemma has_strict_fderiv_at.ccos (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') x :=\n(complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') s x :=\n(complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.ccos (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.cos (f x)) s x :=\nhf.has_fderiv_within_at.ccos.differentiable_within_at\n\n@[simp] lemma differentiable_at.ccos (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.cos (f x)) x :=\nhc.has_fderiv_at.ccos.differentiable_at\n\nlemma differentiable_on.ccos (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.cos (f x)) s :=\n\u03bbx h, (hc x h).ccos\n\n@[simp] lemma differentiable.ccos (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.cos (f x)) :=\n\u03bbx, (hc x).ccos\n\nlemma fderiv_within_ccos (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.cos (f x)) s x = - complex.sin (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.ccos.fderiv_within hxs\n\n@[simp] lemma fderiv_ccos (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.cos (f x)) x = - complex.sin (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.ccos.fderiv\n\nlemma cont_diff.ccos {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.cos (f x)) :=\ncomplex.cont_diff_cos.comp h\n\nlemma cont_diff_at.ccos {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.cos (f x)) x :=\ncomplex.cont_diff_cos.cont_diff_at.comp x hf\n\nlemma cont_diff_on.ccos {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.cos (f x)) s :=\ncomplex.cont_diff_cos.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.ccos {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.cos (f x)) s x :=\ncomplex.cont_diff_cos.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `complex.sin` -/\n\nlemma has_strict_fderiv_at.csin (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') x :=\n(complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') s x :=\n(complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.csin (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.sin (f x)) s x :=\nhf.has_fderiv_within_at.csin.differentiable_within_at\n\n@[simp] lemma differentiable_at.csin (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.sin (f x)) x :=\nhc.has_fderiv_at.csin.differentiable_at\n\nlemma differentiable_on.csin (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.sin (f x)) s :=\n\u03bbx h, (hc x h).csin\n\n@[simp] lemma differentiable.csin (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.sin (f x)) :=\n\u03bbx, (hc x).csin\n\nlemma fderiv_within_csin (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.sin (f x)) s x = complex.cos (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.csin.fderiv_within hxs\n\n@[simp] lemma fderiv_csin (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.sin (f x)) x = complex.cos (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.csin.fderiv\n\nlemma cont_diff.csin {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.sin (f x)) :=\ncomplex.cont_diff_sin.comp h\n\nlemma cont_diff_at.csin {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.sin (f x)) x :=\ncomplex.cont_diff_sin.cont_diff_at.comp x hf\n\nlemma cont_diff_on.csin {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.sin (f x)) s :=\ncomplex.cont_diff_sin.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.csin {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.sin (f x)) s x :=\ncomplex.cont_diff_sin.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `complex.cosh` -/\n\nlemma has_strict_fderiv_at.ccosh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') s x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.ccosh (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.cosh (f x)) s x :=\nhf.has_fderiv_within_at.ccosh.differentiable_within_at\n\n@[simp] lemma differentiable_at.ccosh (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.cosh (f x)) x :=\nhc.has_fderiv_at.ccosh.differentiable_at\n\nlemma differentiable_on.ccosh (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.cosh (f x)) s :=\n\u03bbx h, (hc x h).ccosh\n\n@[simp] lemma differentiable.ccosh (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.cosh (f x)) :=\n\u03bbx, (hc x).ccosh\n\nlemma fderiv_within_ccosh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.cosh (f x)) s x = complex.sinh (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.ccosh.fderiv_within hxs\n\n@[simp] lemma fderiv_ccosh (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.cosh (f x)) x = complex.sinh (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.ccosh.fderiv\n\nlemma cont_diff.ccosh {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.cosh (f x)) :=\ncomplex.cont_diff_cosh.comp h\n\nlemma cont_diff_at.ccosh {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.cosh (f x)) x :=\ncomplex.cont_diff_cosh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.ccosh {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.cosh (f x)) s :=\ncomplex.cont_diff_cosh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.ccosh {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.cosh (f x)) s x :=\ncomplex.cont_diff_cosh.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `complex.sinh` -/\n\nlemma has_strict_fderiv_at.csinh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') s x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.csinh (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.sinh (f x)) s x :=\nhf.has_fderiv_within_at.csinh.differentiable_within_at\n\n@[simp] lemma differentiable_at.csinh (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.sinh (f x)) x :=\nhc.has_fderiv_at.csinh.differentiable_at\n\nlemma differentiable_on.csinh (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.sinh (f x)) s :=\n\u03bbx h, (hc x h).csinh\n\n@[simp] lemma differentiable.csinh (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.sinh (f x)) :=\n\u03bbx, (hc x).csinh\n\nlemma fderiv_within_csinh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.sinh (f x)) s x = complex.cosh (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.csinh.fderiv_within hxs\n\n@[simp] lemma fderiv_csinh (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.sinh (f x)) x = complex.cosh (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.csinh.fderiv\n\nlemma cont_diff.csinh {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.sinh (f x)) :=\ncomplex.cont_diff_sinh.comp h\n\nlemma cont_diff_at.csinh {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.sinh (f x)) x :=\ncomplex.cont_diff_sinh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.csinh {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.sinh (f x)) s :=\ncomplex.cont_diff_sinh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.csinh {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.sinh (f x)) s x :=\ncomplex.cont_diff_sinh.cont_diff_at.comp_cont_diff_within_at x hf\n\nend\n\nnamespace real\n\nvariables {x y z : \u211d}\n\nlemma has_strict_deriv_at_sin (x : \u211d) : has_strict_deriv_at sin (cos x) x :=\n(complex.has_strict_deriv_at_sin x).real_of_complex\n\nlemma has_deriv_at_sin (x : \u211d) : has_deriv_at sin (cos x) x :=\n(has_strict_deriv_at_sin x).has_deriv_at\n\nlemma cont_diff_sin {n} : cont_diff \u211d n sin :=\ncomplex.cont_diff_sin.real_of_complex\n\nlemma differentiable_sin : differentiable \u211d sin :=\n\u03bbx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin : differentiable_at \u211d sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ \u03bb x, (has_deriv_at_sin x).deriv\n\nlemma has_strict_deriv_at_cos (x : \u211d) : has_strict_deriv_at cos (-sin x) x :=\n(complex.has_strict_deriv_at_cos x).real_of_complex\n\nlemma has_deriv_at_cos (x : \u211d) : has_deriv_at cos (-sin x) x :=\n(complex.has_deriv_at_cos x).real_of_complex\n\nlemma cont_diff_cos {n} : cont_diff \u211d n cos :=\ncomplex.cont_diff_cos.real_of_complex\n\nlemma differentiable_cos : differentiable \u211d cos :=\n\u03bbx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos : differentiable_at \u211d cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos : deriv cos x = - sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (\u03bb x, - sin x) :=\nfunext $ \u03bb _, deriv_cos\n\nlemma has_strict_deriv_at_sinh (x : \u211d) : has_strict_deriv_at sinh (cosh x) x :=\n(complex.has_strict_deriv_at_sinh x).real_of_complex\n\nlemma has_deriv_at_sinh (x : \u211d) : has_deriv_at sinh (cosh x) x :=\n(complex.has_deriv_at_sinh x).real_of_complex\n\nlemma cont_diff_sinh {n} : cont_diff \u211d n sinh :=\ncomplex.cont_diff_sinh.real_of_complex\n\nlemma differentiable_sinh : differentiable \u211d sinh :=\n\u03bbx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh : differentiable_at \u211d sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ \u03bb x, (has_deriv_at_sinh x).deriv\n\nlemma has_strict_deriv_at_cosh (x : \u211d) : has_strict_deriv_at cosh (sinh x) x :=\n(complex.has_strict_deriv_at_cosh x).real_of_complex\n\nlemma has_deriv_at_cosh (x : \u211d) : has_deriv_at cosh (sinh x) x :=\n(complex.has_deriv_at_cosh x).real_of_complex\n\nlemma cont_diff_cosh {n} : cont_diff \u211d n cosh :=\ncomplex.cont_diff_cosh.real_of_complex\n\nlemma differentiable_cosh : differentiable \u211d cosh :=\n\u03bbx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh : differentiable_at \u211d cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ \u03bb x, (has_deriv_at_cosh x).deriv\n\n/-- `sinh` is strictly monotone. -/\nlemma sinh_strict_mono : strict_mono sinh :=\nstrict_mono_of_deriv_pos $ by { rw real.deriv_sinh, exact cosh_pos }\n\n/-- `sinh` is injective, `\u2200 a b, sinh a = sinh b \u2192 a = b`. -/\nlemma sinh_injective : function.injective sinh := sinh_strict_mono.injective\n\n@[simp] lemma sinh_inj : sinh x = sinh y \u2194 x = y := sinh_injective.eq_iff\n@[simp] lemma sinh_le_sinh : sinh x \u2264 sinh y \u2194 x \u2264 y := sinh_strict_mono.le_iff_le\n@[simp] lemma sinh_lt_sinh : sinh x < sinh y \u2194 x < y := sinh_strict_mono.lt_iff_lt\n\n@[simp] lemma sinh_pos_iff : 0 < sinh x \u2194 0 < x :=\nby simpa only [sinh_zero] using @sinh_lt_sinh 0 x\n\n@[simp] lemma sinh_nonpos_iff : sinh x \u2264 0 \u2194 x \u2264 0 :=\nby simpa only [sinh_zero] using @sinh_le_sinh x 0\n\n@[simp] lemma sinh_neg_iff : sinh x < 0 \u2194 x < 0 :=\nby simpa only [sinh_zero] using @sinh_lt_sinh x 0\n\n@[simp] lemma sinh_nonneg_iff : 0 \u2264 sinh x \u2194 0 \u2264 x :=\nby simpa only [sinh_zero] using @sinh_le_sinh 0 x\n\nlemma abs_sinh (x : \u211d) : |sinh x| = sinh (|x|) :=\nby cases le_total x 0; simp [abs_of_nonneg, abs_of_nonpos, *]\n\nlemma cosh_strict_mono_on : strict_mono_on cosh (Ici 0) :=\n(convex_Ici _).strict_mono_on_of_deriv_pos continuous_cosh.continuous_on $ \u03bb x hx,\n  by { rw [interior_Ici, mem_Ioi] at hx, rwa [deriv_cosh, sinh_pos_iff] }\n\n@[simp] lemma cosh_le_cosh : cosh x \u2264 cosh y \u2194 |x| \u2264 |y| :=\ncosh_abs x \u25b8 cosh_abs y \u25b8 cosh_strict_mono_on.le_iff_le (_root_.abs_nonneg x) (_root_.abs_nonneg y)\n\n@[simp] lemma cosh_lt_cosh : cosh x < cosh y \u2194 |x| < |y| :=\nlt_iff_lt_of_le_iff_le cosh_le_cosh\n\n@[simp] lemma one_le_cosh (x : \u211d) : 1 \u2264 cosh x :=\ncosh_zero \u25b8 cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg])\n\n@[simp] lemma one_lt_cosh : 1 < cosh x \u2194 x \u2260 0 :=\ncosh_zero \u25b8 cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos])\n\nlemma sinh_sub_id_strict_mono : strict_mono (\u03bb x, sinh x - x) :=\nbegin\n  refine strict_mono_of_odd_strict_mono_on_nonneg (\u03bb x, by simp) _,\n  refine (convex_Ici _).strict_mono_on_of_deriv_pos _ (\u03bb x hx, _),\n  { exact (continuous_sinh.sub continuous_id).continuous_on },\n  { rw [interior_Ici, mem_Ioi] at hx,\n    rw [deriv_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh],\n    exacts [hx.ne', differentiable_at_sinh, differentiable_at_id] }\nend\n\n@[simp] lemma self_le_sinh_iff : x \u2264 sinh x \u2194 0 \u2264 x :=\ncalc x \u2264 sinh x \u2194 sinh 0 - 0 \u2264 sinh x - x : by simp\n... \u2194 0 \u2264 x : sinh_sub_id_strict_mono.le_iff_le\n\n@[simp] lemma sinh_le_self_iff : sinh x \u2264 x \u2194 x \u2264 0 :=\ncalc sinh x \u2264 x \u2194 sinh x - x \u2264 sinh 0 - 0 : by simp\n... \u2194 x \u2264 0 : sinh_sub_id_strict_mono.le_iff_le\n\n@[simp] lemma self_lt_sinh_iff : x < sinh x \u2194 0 < x :=\nlt_iff_lt_of_le_iff_le sinh_le_self_iff\n\n@[simp] lemma sinh_lt_self_iff : sinh x < x \u2194 x < 0 :=\nlt_iff_lt_of_le_iff_le self_le_sinh_iff\n\nend real\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, real.cos (f x)` etc., `f : \u211d \u2192 \u211d` -/\n\nvariables {f : \u211d \u2192 \u211d} {f' x : \u211d} {s : set \u211d}\n\n/-! #### `real.cos` -/\n\nlemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') x :=\n(real.has_strict_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_at.cos (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') x :=\n(real.has_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') s x :=\n(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_cos (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.cos.deriv_within hxs\n\n@[simp] lemma deriv_cos (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=\nhc.has_deriv_at.cos.deriv\n\n/-! #### `real.sin` -/\n\nlemma has_strict_deriv_at.sin (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') x :=\n(real.has_strict_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_at.sin (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') x :=\n(real.has_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') s x :=\n(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_sin (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.sin.deriv_within hxs\n\n@[simp] lemma deriv_sin (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=\nhc.has_deriv_at.sin.deriv\n\n/-! #### `real.cosh` -/\n\nlemma has_strict_deriv_at.cosh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') x :=\n(real.has_strict_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') x :=\n(real.has_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') s x :=\n(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_cosh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.cosh.deriv_within hxs\n\n@[simp] lemma deriv_cosh (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=\nhc.has_deriv_at.cosh.deriv\n\n/-! #### `real.sinh` -/\n\nlemma has_strict_deriv_at.sinh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') x :=\n(real.has_strict_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') x :=\n(real.has_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') s x :=\n(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_sinh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.sinh.deriv_within hxs\n\n@[simp] lemma deriv_sinh (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=\nhc.has_deriv_at.sinh.deriv\n\nend\n\nsection\n\n/-! ### Simp lemmas for derivatives of `\u03bb x, real.cos (f x)` etc., `f : E \u2192 \u211d` -/\n\nvariables {E : Type*} [normed_add_comm_group E] [normed_space \u211d E] {f : E \u2192 \u211d} {f' : E \u2192L[\u211d] \u211d}\n  {x : E} {s : set E}\n\n/-! #### `real.cos` -/\n\nlemma has_strict_fderiv_at.cos (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') x :=\n(real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') s x :=\n(real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.cos (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.cos (f x)) s x :=\nhf.has_fderiv_within_at.cos.differentiable_within_at\n\n@[simp] lemma differentiable_at.cos (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.cos (f x)) x :=\nhc.has_fderiv_at.cos.differentiable_at\n\nlemma differentiable_on.cos (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.cos (f x)) s :=\n\u03bbx h, (hc x h).cos\n\n@[simp] lemma differentiable.cos (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.cos (f x)) :=\n\u03bbx, (hc x).cos\n\nlemma fderiv_within_cos (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.cos (f x)) s x = - real.sin (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.cos.fderiv_within hxs\n\n@[simp] lemma fderiv_cos (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.cos (f x)) x = - real.sin (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.cos.fderiv\n\nlemma cont_diff.cos {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.cos (f x)) :=\nreal.cont_diff_cos.comp h\n\nlemma cont_diff_at.cos {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.cos (f x)) x :=\nreal.cont_diff_cos.cont_diff_at.comp x hf\n\nlemma cont_diff_on.cos {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.cos (f x)) s :=\nreal.cont_diff_cos.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.cos {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.cos (f x)) s x :=\nreal.cont_diff_cos.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `real.sin` -/\n\nlemma has_strict_fderiv_at.sin (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') x :=\n(real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') s x :=\n(real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.sin (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.sin (f x)) s x :=\nhf.has_fderiv_within_at.sin.differentiable_within_at\n\n@[simp] lemma differentiable_at.sin (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.sin (f x)) x :=\nhc.has_fderiv_at.sin.differentiable_at\n\nlemma differentiable_on.sin (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.sin (f x)) s :=\n\u03bbx h, (hc x h).sin\n\n@[simp] lemma differentiable.sin (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.sin (f x)) :=\n\u03bbx, (hc x).sin\n\nlemma fderiv_within_sin (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.sin (f x)) s x = real.cos (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.sin.fderiv_within hxs\n\n@[simp] lemma fderiv_sin (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.sin (f x)) x = real.cos (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.sin.fderiv\n\nlemma cont_diff.sin {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.sin (f x)) :=\nreal.cont_diff_sin.comp h\n\nlemma cont_diff_at.sin {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.sin (f x)) x :=\nreal.cont_diff_sin.cont_diff_at.comp x hf\n\nlemma cont_diff_on.sin {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.sin (f x)) s :=\nreal.cont_diff_sin.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.sin {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.sin (f x)) s x :=\nreal.cont_diff_sin.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `real.cosh` -/\n\nlemma has_strict_fderiv_at.cosh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') x :=\n(real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') s x :=\n(real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.cosh (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.cosh (f x)) s x :=\nhf.has_fderiv_within_at.cosh.differentiable_within_at\n\n@[simp] lemma differentiable_at.cosh (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.cosh (f x)) x :=\nhc.has_fderiv_at.cosh.differentiable_at\n\nlemma differentiable_on.cosh (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.cosh (f x)) s :=\n\u03bbx h, (hc x h).cosh\n\n@[simp] lemma differentiable.cosh (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.cosh (f x)) :=\n\u03bbx, (hc x).cosh\n\nlemma fderiv_within_cosh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.cosh (f x)) s x = real.sinh (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.cosh.fderiv_within hxs\n\n@[simp] lemma fderiv_cosh (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.cosh (f x)) x = real.sinh (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.cosh.fderiv\n\nlemma cont_diff.cosh {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.cosh (f x)) :=\nreal.cont_diff_cosh.comp h\n\nlemma cont_diff_at.cosh {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.cosh (f x)) x :=\nreal.cont_diff_cosh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.cosh {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.cosh (f x)) s :=\nreal.cont_diff_cosh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.cosh {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.cosh (f x)) s x :=\nreal.cont_diff_cosh.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `real.sinh` -/\n\nlemma has_strict_fderiv_at.sinh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') x :=\n(real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') s x :=\n(real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.sinh (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.sinh (f x)) s x :=\nhf.has_fderiv_within_at.sinh.differentiable_within_at\n\n@[simp] lemma differentiable_at.sinh (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.sinh (f x)) x :=\nhc.has_fderiv_at.sinh.differentiable_at\n\nlemma differentiable_on.sinh (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.sinh (f x)) s :=\n\u03bbx h, (hc x h).sinh\n\n@[simp] lemma differentiable.sinh (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.sinh (f x)) :=\n\u03bbx, (hc x).sinh\n\nlemma fderiv_within_sinh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.sinh (f x)) s x = real.cosh (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.sinh.fderiv_within hxs\n\n@[simp] lemma fderiv_sinh (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.sinh (f x)) x = real.cosh (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.sinh.fderiv\n\nlemma cont_diff.sinh {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.sinh (f x)) :=\nreal.cont_diff_sinh.comp h\n\nlemma cont_diff_at.sinh {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.sinh (f x)) x :=\nreal.cont_diff_sinh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.sinh {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.sinh (f x)) s :=\nreal.cont_diff_sinh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.sinh {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.sinh (f x)) s x :=\nreal.cont_diff_sinh.cont_diff_at.comp_cont_diff_within_at x hf\n\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/trigonometric/deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7468683063408955}}
{"text": "import ..lectures.love01_definitions_and_statements_demo\n\n\n/-! # LoVe Exercise 1: Definitions and Statements\n\nReplace the placeholders (e.g., `:= sorry`) with your solutions. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Truncated Subtraction\n\n1.1. Define the function `sub` that implements truncated subtraction on natural\nnumbers by recursion. \"Truncated\" means that results that mathematically would\nbe negative are represented by 0. For example:\n\n    `sub 7 2 = 5`\n    `sub 2 7 = 0` -/\n\ndef sub : \u2115 \u2192 \u2115 \u2192 \u2115\n| m            0            := m\n| 0            _            := 0\n| (nat.succ m) (nat.succ n) := sub m n\n\n/-! 1.2. Check that your function works as expected. -/\n\n#eval sub 0 0   -- expected: 0\n#eval sub 0 1   -- expected: 0\n#eval sub 0 7   -- expected: 0\n#eval sub 1 0   -- expected: 1\n#eval sub 1 1   -- expected: 0\n#eval sub 3 0   -- expected: 3\n#eval sub 2 7   -- expected: 0\n#eval sub 3 1   -- expected: 2\n#eval sub 3 3   -- expected: 0\n#eval sub 3 7   -- expected: 0\n#eval sub 7 2   -- expected: 5\n\n\n/-! ## Question 2: Arithmetic Expressions\n\nConsider the type `aexp` from the lecture and the function `eval` that\ncomputes the value of an expression. You will find the definitions in the file\n`love01_definitions_and_statements_demo.lean`. One way to find them quickly is\nto\n\n1. hold the Control (on Linux and Windows) or Command (on macOS) key pressed;\n2. move the cursor to the identifier `aexp` or `eval`;\n3. click the identifier. -/\n\n#check aexp\n#check eval\n\n/-! 2.1. Test that `eval` behaves as expected. Make sure to exercise each\nconstructor at least once. You can use the following environment in your tests.\nWhat happens if you divide by zero?\n\nMake sure to use `#eval`. For technical reasons, `#reduce` does not work well\nhere. Note that `#eval` (Lean's evaluation command) and `eval` (our evaluation\nfunction on `aexp`) are unrelated. -/\n\ndef some_env : string \u2192 \u2124\n| \"x\" := 3\n| \"y\" := 17\n| _   := 201\n\n#eval eval some_env (aexp.var \"x\")   -- expected: 3\n#eval eval some_env (aexp.num 12)                              -- expected: 12\n#eval eval some_env (aexp.add (aexp.var \"x\") (aexp.var \"y\"))   -- expected: 20\n#eval eval some_env (aexp.sub (aexp.num 5) (aexp.var \"y\"))     -- expected: -12\n#eval eval some_env (aexp.mul (aexp.num 11) (aexp.var \"z\"))    -- expected: 2211\n#eval eval some_env (aexp.div (aexp.num 2) (aexp.num 0))       -- expected: 0\n\n/-! 2.2. The following function simplifies arithmetic expressions involving\naddition. It simplifies `0 + e` and `e + 0` to `e`. Complete the definition so\nthat it also simplifies expressions involving the other three binary\noperators. -/\n\ndef simplify : aexp \u2192 aexp\n| (aexp.add (aexp.num 0) e\u2082) := simplify e\u2082\n| (aexp.add e\u2081 (aexp.num 0)) := simplify e\u2081\n| (aexp.sub e\u2081 (aexp.num 0)) := simplify e\u2081\n| (aexp.mul (aexp.num 0) e\u2082) := aexp.num 0\n| (aexp.mul e\u2081 (aexp.num 0)) := aexp.num 0\n| (aexp.mul (aexp.num 1) e\u2082) := simplify e\u2082\n| (aexp.mul e\u2081 (aexp.num 1)) := simplify e\u2081\n| (aexp.div (aexp.num 0) e\u2082) := aexp.num 0\n| (aexp.div e\u2081 (aexp.num 0)) := aexp.num 0\n| (aexp.div e\u2081 (aexp.num 1)) := simplify e\u2081\n-- catch-all cases below\n| (aexp.num i)               := aexp.num i\n| (aexp.var x)               := aexp.var x\n| (aexp.add e\u2081 e\u2082)           := aexp.add (simplify e\u2081) (simplify e\u2082)\n| (aexp.sub e\u2081 e\u2082)           := aexp.sub (simplify e\u2081) (simplify e\u2082)\n| (aexp.mul e\u2081 e\u2082)           := aexp.mul (simplify e\u2081) (simplify e\u2082)\n| (aexp.div e\u2081 e\u2082)           := aexp.div (simplify e\u2081) (simplify e\u2082)\n\n/-! 2.3. Is the `simplify` function correct? In fact, what would it mean for it\nto be correct or not? Intuitively, for `simplify` to be correct, it must\nreturn an arithmetic expression that yields the same numeric value when\nevaluated as the original expression.\n\nGiven an environment `env` and an expression `e`, state (without proving it)\nthe property that the value of `e` after simplification is the same as the\nvalue of `e` before. -/\n\nlemma simplify_correct (env : string \u2192 \u2124) (e : aexp) :\n  eval env (simplify e) = eval env e :=\nsorry\n\n\n/-! ## Question 3: \u03bb-Terms\n\n3.1. Complete the following definitions, by replacing the `sorry` markers by\nterms of the expected type.\n\nHint: A procedure for doing so systematically is described in Section 1.1.4 of\nthe Hitchhiker's Guide. As explained there, you can use `_` as a placeholder\nwhile constructing a term. By hovering over `_`, you will see the current\nlogical context. -/\n\ndef I : \u03b1 \u2192 \u03b1 :=\n\u03bba, a\n\ndef K : \u03b1 \u2192 \u03b2 \u2192 \u03b1 :=\n\u03bba b, a\n\ndef C : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 \u03b2 \u2192 \u03b1 \u2192 \u03b3 :=\n\u03bbg b a, g a b\n\ndef proj_1st : \u03b1 \u2192 \u03b1 \u2192 \u03b1 :=\n\u03bbx y, x\n\n/-! Please give a different answer than for `proj_1st`. -/\n\ndef proj_2nd : \u03b1 \u2192 \u03b1 \u2192 \u03b1 :=\n\u03bbx y, y\n\ndef some_nonsense : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 \u03b1 \u2192 (\u03b1 \u2192 \u03b3) \u2192 \u03b2 \u2192 \u03b3 :=\n\u03bbg a f b, g a b\n\n/-! 3.2. Show the typing derivation for your definition of `C` above, on paper\nor using ASCII or Unicode art. You might find the characters `\u2013` (to draw\nhorizontal bars) and `\u22a2` useful. -/\n\n/-! Let `D` := `g : \u03b1 \u2192 \u03b2 \u2192 \u03b3, b : \u03b2, a : \u03b1`. We have\n\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Var    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Var\n    D \u22a2 g : \u03b1 \u2192 \u03b2 \u2192 \u03b3         D \u22a2 a : \u03b1\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 App    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Var\n    D \u22a2 g a : \u03b2 \u2192 \u03b3                             D \u22a2 b : \u03b2\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 App\n    D \u22a2 g a b : \u03b3\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Lam\n    g : \u03b1 \u2192 \u03b2 \u2192 \u03b3, b : \u03b2 \u22a2 (\u03bba : \u03b1, g a b) : \u03b1 \u2192 \u03b3\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Lam\n    g : \u03b1 \u2192 \u03b2 \u2192 \u03b3 \u22a2 (\u03bb(b : \u03b2) (a : \u03b1), g a b) : \u03b2 \u2192 \u03b1 \u2192 \u03b3\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Lam\n    \u22a2 (\u03bb(g : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (b : \u03b2) (a : \u03b1), g a b) : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 \u03b2 \u2192 \u03b1 \u2192 \u03b3 -/\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/exercises/love01_definitions_and_statements_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8152324826183821, "lm_q1q2_score": 0.7468423202386744}}
{"text": "import game.order.level06\nimport data.real.irrational\n\nopen real\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 7\n\nProve by example that there exist pairs of real numbers\n$a$ and $b$ such that $a \\in \\mathbb{R} \\setminus \\mathbb{Q}$, \n$b \\in \\mathbb{R} \\setminus \\mathbb{Q}$,\nbut their sum $a + b$ is a rational number, $(a+b) \\in \\mathbb{Q}$.\nYou may use this result in the Lean mathlib library:\n\n`irrational_sqrt_two : irrational (sqrt 2)`\n\n-/\n\n/- Axiom : irrational_sqrt_two : irrational (sqrt 2)\n-/\n\n\n/- Lemma\nNot true that for any $a$, $b$, irrational numbers, the sum is \nalso an irrational number.\n-/\ntheorem not_sum_irrational : \n    \u00ac ( \u2200 (a b : \u211d), irrational a \u2192  irrational b \u2192 irrational (a+b) ) :=\nbegin\n  intro H,\n  have H2 := H (sqrt 2) (-sqrt 2),\n  have H3 := H2 irrational_sqrt_two (irrational_neg_iff.2 irrational_sqrt_two),\n  apply H3,\n  existsi (0 : \u211a),\n  simp, done\nend\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.7468315190667697}}
{"text": "import Mynat.MulAdv\n\nnamespace mynat\n\ndef myle (a b : mynat) :=  \u2203 (c : mynat), b = a + c\ninstance : LE mynat where\n  le := myle\ntheorem le_iff_exists_add (a b : mynat) : a \u2264 b \u2194 \u2203 (c : mynat), b = a + c := Iff.rfl\n\ntheorem one_add_le_self (x : mynat) : x \u2264 1 + x := by\n  rw [le_iff_exists_add]\n  exists 1\n  rw [add_comm]\n\ntheorem le_refl (x : mynat) : x \u2264 x :=\n  Exists.intro 0 rfl\n\n-- attribute [rfl] mynat.le_refl\n-- Why doesn't it work?\n\ntheorem le_succ (a b : mynat) : a \u2264 b \u2192 a \u2264 (succ b) := by\n  intro h\n  cases h with\n  | intro c hc =>\n    exists succ c\n    rw [add_succ]\n    rw [hc]\n\ntheorem zero_le (a : mynat) : 0 \u2264 a := by\n  rw [le_iff_exists_add]\n  exists a\n  rw [zero_add]\n\ntheorem le_trans (a b c : mynat) (hab : a \u2264 b) (hbc : b \u2264 c) : a \u2264 c := by\n  rw [le_iff_exists_add] at hab hbc\n  cases hab with\n  | intro d hd =>\n    cases hbc with\n    | intro e he =>\n      rw [hd] at he\n      exists d + e\n      rw [\u2190 add_assoc]\n      exact he\n\ntheorem le_antisymm (a b : mynat) (hab : a \u2264 b) (hba : b \u2264 a) : a = b := by\n  cases hab with\n  | intro c hc =>\n    cases hba with\n    | intro d hd =>\n      rw [hc] at hd\n      conv at hd =>\n        lhs\n        rw [\u2190 add_zero a]\n      rw [add_assoc] at hd\n      have halc := (add_left_cancel a 0 (c+d)) hd\n      have halcsym := Eq.symm halc\n      have hcez := add_right_eq_zero halcsym\n      rw [hcez] at hc\n      rw [add_zero] at hc\n      exact Eq.symm hc\n\ntheorem le_zero (a : mynat) (h : a \u2264 0) : a = 0 := by\n  have hh := zero_le a\n  exact le_antisymm a 0 h hh\n\ntheorem succ_le_succ (a b : mynat) (h : a \u2264 b) : succ a \u2264 succ b := by\n  cases h with\n  | intro c hc =>\n    exists c\n    rw [hc]\n    rw [succ_add]\n\ntheorem le_total (a b : mynat) : a \u2264 b \u2228 b \u2264 a := by\n  cases b\n  case zero =>\n    apply Or.intro_right\n    exact zero_le a\n  case succ b' =>\n    have hind := le_total a b'\n    cases hind\n    case inl h =>\n      apply Or.intro_left\n      cases h with\n      | intro c hc =>\n        exists succ c\n        rw [add_succ]\n        rw [hc]\n    case inr h =>\n      cases h with\n      | intro c hc =>\n        cases c\n        case zero =>\n          rw [mynat_zero_eq_zero] at hc\n          apply Or.intro_left\n          exists 1\n          rw [hc]\n          rw [add_assoc]\n          rw [zero_add]\n          exact succ_eq_add_one b'\n        case succ c' =>\n          apply Or.intro_right\n          exists c'\n          rw [hc]\n          rw [succ_add]\n          rw [add_succ]\n\ntheorem le_succ_self (a : mynat) : a \u2264 succ a := by\n  exists 1\n\ntheorem add_le_add_right {a b : mynat} : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) := by\n  intro h\n  cases h with\n  | intro c hc =>\n    intro t\n    exists c\n    rw [hc]\n    rw [add_assoc]\n    rw [add_assoc]\n    rw [add_comm c t]\n\ntheorem le_of_succ_le_succ (a b : mynat) : succ a \u2264 succ b \u2192 a \u2264 b := by\n  intro h\n  cases h with\n  | intro c hc =>\n    exists c\n    rw [succ_eq_add_one] at hc\n    rw [succ_eq_add_one] at hc\n    rw [add_comm b 1] at hc\n    rw [add_comm a 1] at hc\n    rw [add_assoc] at hc\n    exact add_left_cancel 1 b (a + c) hc\n\ntheorem not_succ_le_self (a : mynat) : \u00ac (succ a \u2264 a) := by\n  intro h\n  cases h with\n  | intro c hc =>\n    rw [succ_eq_add_one] at hc\n    conv at hc =>\n      lhs\n      rw [\u2190 add_zero a]\n    rw [add_assoc] at hc\n    have hd := add_left_cancel a 0 (1 + c) hc\n    rw [add_comm] at hd\n    rw [\u2190 succ_eq_add_one] at hd\n    have hnd := zero_ne_succ c\n    exact hnd hd\n\ntheorem add_le_add_left {a b : mynat} (h : a \u2264 b) (t : mynat) :\n  t + a \u2264 t + b := by\n  cases h with\n  | intro c hc =>\n    exists c\n    rw [hc]\n    rw [\u2190 add_assoc]\n\ntheorem lt_aux_one (a b : mynat) : a \u2264 b \u2227 \u00ac (b \u2264 a) \u2192 succ a \u2264 b := by\n  intro h\n  have h1 := h.left\n  have h2 := h.right\n  cases h1 with\n  | intro c hc =>\n    cases c\n    case zero =>\n      rw [mynat_zero_eq_zero] at hc\n      -- by contradiction\n      rw [add_zero] at hc\n      rw [hc] at h2\n      apply False.elim\n      exact h2 (le_refl a)\n    case succ c' =>\n      exists c'\n      rw [succ_add]\n      rw [add_succ] at hc\n      exact hc\n\ntheorem lt_aux_two (a b : mynat) : succ a \u2264 b \u2192 a \u2264 b \u2227 \u00ac (b \u2264 a) := by\n  intro h\n  cases h with\n  | intro c hc =>\n    apply And.intro\n    case intro.left =>\n      exists succ c\n      rw [add_succ]\n      rw [succ_add] at hc\n      exact hc\n    case intro.right =>\n      intro hh\n      rw [hc] at hh\n      rw [succ_add] at hh\n      rw [\u2190 add_succ] at hh\n      cases hh with\n      | intro d hd =>\n        conv at hd =>\n          lhs\n          rw [\u2190 add_zero a]\n        rw [add_assoc] at hd\n        have hfalse := add_left_cancel a 0 (succ c + d) hd\n        have hsz := add_right_eq_zero (Eq.symm hfalse)\n        exact zero_ne_succ c (Eq.symm hsz)\n\ndef mylt (a b : mynat) := a \u2264 b \u2227 \u00ac (b \u2264 a)\n-- incantation so that we can use `<` notation: \ninstance : LT mynat := \u27e8mylt\u27e9\ntheorem lt_def (a b : mynat) : a < b \u2194 a \u2264 b \u2227 \u00ac (b \u2264 a) := Iff.rfl\n\ntheorem lt_iff_succ_le (a b : mynat) : a < b \u2194 succ a \u2264 b := by\n  rw [lt_def]\n  apply Iff.intro\n  . apply lt_aux_one\n  . apply lt_aux_two\n\nend mynat", "meta": {"author": "plumsirawit", "repo": "mynat", "sha": "0a6529078322c76f7460ef6dafba8367608a5163", "save_path": "github-repos/lean/plumsirawit-mynat", "path": "github-repos/lean/plumsirawit-mynat/mynat-0a6529078322c76f7460ef6dafba8367608a5163/Mynat/Ineq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7467705767602848}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.real.basic\nimport data.real.sqrt\n\nopen real\n\n/-!\n# IMO 2008 Q4\nFind all functions `f : (0,\u221e) \u2192 (0,\u221e)` (so, `f` is a function from the positive real\nnumbers to the positive real numbers) such that\n      ```\n      (f(w)^2 + f(x)^2)/(f(y^2) + f(z^2)) = (w^2 + x^2)/(y^2 + z^2)\n      ```\nfor all positive real numbers `w`, `x`, `y`, `z`, satisfying `wx = yz`.\n\n# Solution\nThe desired theorem is that either `f = \u03bb x, x` or `f = \u03bb x, 1/x`\n-/\n\ntheorem imo2008_q4\n  (f : \u211d \u2192 \u211d)\n  (H\u2081 : \u2200 x > 0, f(x) > 0) :\n  (\u2200 w x y z : \u211d, 0 < w \u2192 0 < x \u2192 0 < y \u2192 0 < z \u2192 w*x = y*z \u2192\n    (f(w)^2 + f(x)^2)/(f(y^2) + f(z^2)) = (w^2 + x^2)/(y^2 + z^2)) \u2194\n  ((\u2200 x > 0, f(x) = x) \u2228 (\u2200 x > 0, f(x) = 1/x)) :=\nbegin\n  split, swap,\n  -- proof that f(x) = x and f(x) = 1/x satisfy the condition\n  { rintros (h | h),\n    { intros w x y z hw hx hy hz hprod,\n      rw [(h w hw), (h x hx), (h (y^2) (pow_pos hy 2)), (h (z^2) (pow_pos hz 2))] },\n    { intros w x y z hw hx hy hz hprod,\n      rw [(h w hw), (h x hx), (h (y^2) (pow_pos hy 2)), (h (z^2) (pow_pos hz 2))],\n      have hy2z2 : y^2 + z^2 \u2260 0 := ne_of_gt (add_pos (pow_pos hy 2) (pow_pos hz 2)),\n      have hz2y2 : z^2 + y^2 \u2260 0 := ne_of_gt (add_pos (pow_pos hz 2) (pow_pos hy 2)),\n      have hp2 : w^2 * x^2 = y^2 * z^2, { rw [(mul_pow w x 2).symm, (mul_pow y z 2).symm, hprod] },\n      field_simp [(ne_of_gt hw), (ne_of_gt hx), (ne_of_gt hy), (ne_of_gt hz), hy2z2, hz2y2, hp2],\n      ring } },\n\n  -- proof that the only solutions are f(x) = x or f(x) = 1/x\n  intro H\u2082,\n  have h\u2080 : f(1) \u2260 0, { specialize H\u2081 1 zero_lt_one, exact ne_of_gt H\u2081 },\n\n  have h\u2081 : f(1) = 1,\n  { specialize H\u2082 1 1 1 1 zero_lt_one zero_lt_one zero_lt_one zero_lt_one rfl,\n    norm_num at H\u2082,\n    rw [(two_mul (f(1)^2)).symm, (two_mul (f 1)).symm] at H\u2082,\n    rw mul_div_mul_left (f(1)^2) (f 1) two_ne_zero at H\u2082,\n    rwa \u2190 (div_eq_iff h\u2080).mpr (pow_two (f 1)) },\n\n  have h\u2082 : \u2200 x > 0, (f x - x) * (f x - 1/x) = 0,\n  { intros x hx,\n    have h1xss : 1 * x = (sqrt x) * (sqrt x), { rw [one_mul, mul_self_sqrt (le_of_lt hx)] },\n    specialize H\u2082 1 x (sqrt x) (sqrt x) zero_lt_one hx (sqrt_pos.mpr hx) (sqrt_pos.mpr hx) h1xss,\n    rw [h\u2081, (one_pow 2), (sqr_sqrt (le_of_lt hx)), (two_mul (f x)).symm, (two_mul x).symm] at H\u2082,\n    have hx_ne_0 : x \u2260 0 := ne_of_gt hx,\n    have hfx_ne_0 : (f x) \u2260 0, { specialize H\u2081 x hx, exact ne_of_gt H\u2081 },\n    field_simp at H\u2082,\n\n    have h1 : (2 * x) * ((f x - x) * (f x - 1/x)) = 0,\n    { calc  (2*x) * ((f x - x) * (f x - 1/x))\n          = 2 * (f x - x) * (x * f x - x * 1/x)   : by ring\n      ... = 2 * (f x - x) * (x * f x - 1)         : by rw (mul_div_cancel_left 1 hx_ne_0)\n      ... = ((1+f(x)^2)*(2*x) - (1+x^2)*(2*f(x))) : by ring\n      ... = 0                                     : sub_eq_zero.mpr H\u2082 },\n\n    have h2x_ne_0 : 2*x \u2260 0 := mul_ne_zero two_ne_zero hx_ne_0,\n\n    calc  ((f x - x) * (f x - 1/x))\n        = (2*x) * ((f x - x) * (f x - 1/x)) / (2*x) : (mul_div_cancel_left _ h2x_ne_0).symm\n    ... = 0                                         : by { rw h1, exact zero_div (2*x) } },\n\n  have h\u2083 : \u2200 x > 0, f(x) = x \u2228 f(x) = 1/x,\n  { rintros x hx,\n    obtain h := zero_eq_mul.mp (h\u2082 x hx).symm,\n    cases h with hp hq,\n    left, linarith [hp],\n    right, linarith [hq] },\n\n  by_contradiction,\n  obtain \u27e8hp\u2081, hq\u2081\u27e9 := not_or_distrib.mp h,\n\n  obtain \u27e8a, hq\u2082\u27e9 := not_forall.mp hq\u2081,\n  obtain \u27e8ha, hq\u2083\u27e9 := not_imp.mp hq\u2082,\n  obtain hq\u2084 := or.resolve_right (h\u2083 a ha) hq\u2083,\n  -- f(a) \u2260 1/a, f(a) = a\n\n  obtain \u27e8b, hp\u2082\u27e9 := not_forall.mp hp\u2081,\n  obtain \u27e8hb, hp\u2083\u27e9 := not_imp.mp hp\u2082,\n  obtain hp\u2084 := or.resolve_left (h\u2083 b hb) hp\u2083,\n  -- f(b) \u2260 b, f(b) = 1/b\n\n  have hab : a*b > 0 := mul_pos ha hb,\n  have habss : a*b = sqrt(a*b) * sqrt(a*b) := (mul_self_sqrt (le_of_lt hab)).symm,\n\n  specialize H\u2082 a b (sqrt (a*b)) (sqrt (a*b)) ha hb (sqrt_pos.mpr hab) (sqrt_pos.mpr hab) habss,\n  rw [(sqr_sqrt (le_of_lt hab)), (two_mul (f (a*b))).symm, (two_mul (a*b)).symm] at H\u2082,\n  rw [hp\u2084, hq\u2084] at H\u2082,\n\n  have h2ab_ne_0 : 2*(a*b) \u2260 0 := mul_ne_zero two_ne_zero (ne_of_gt hab),\n\n  specialize h\u2083 (a*b) hab,\n  cases h\u2083 with hab\u2081 hab\u2082,\n\n  -- f(ab) = ab \u2192 b^4 = 1 \u2192 b = 1 \u2192 f(b) = b \u2192 false\n  { rw hab\u2081 at H\u2082, field_simp at H\u2082,\n    obtain hb\u2081 := or.resolve_right H\u2082 h2ab_ne_0,\n    field_simp [ne_of_gt hb] at hb\u2081,\n    rw (show b^2 * b^2 = (b^2)^2, by ring) at hb\u2081,\n    have hb\u2082 : sqrt 1 = b^2 := (sqrt_eq_iff_sqr_eq zero_le_one (pow_two_nonneg _)).mpr hb\u2081.symm,\n    rw sqrt_one at hb\u2082,\n    have hb\u2083 : sqrt 1 = b := (sqrt_eq_iff_sqr_eq zero_le_one (le_of_lt hb)).mpr hb\u2082.symm,\n    rw sqrt_one at hb\u2083,\n    rw \u2190 hb\u2083 at hp\u2083, exact hp\u2083 h\u2081 },\n\n  -- f(ab) = 1/ab \u2192 a^4 = 1 \u2192 a = 1 \u2192 f(a) = 1/a \u2192 false\n  { have hb_ne_0 : b \u2260 0 := ne_of_gt hb,\n    rw hab\u2082 at H\u2082, field_simp at H\u2082,\n    rw \u2190 sub_eq_zero at H\u2082,\n    rw (show (a^2*b^2+1)*(a*b)*(2*(a*b)) - (a^2+b^2)*(b^2*2) = 2*(b^4)*(a^4-1), by ring) at H\u2082,\n    have h2b4_ne_0 : 2*(b^4) \u2260 0 := mul_ne_zero two_ne_zero (pow_ne_zero 4 hb_ne_0),\n    obtain ha\u2081 := or.resolve_left (zero_eq_mul.mp H\u2082.symm) h2b4_ne_0,\n    rw (show a^4-1 = (a^2+1)*(a^2-1), by ring) at ha\u2081,\n    have h2a1_ne_0 : a^2+1 \u2260 0 := ne_of_gt (add_pos (pow_pos ha 2) zero_lt_one),\n    obtain ha\u2082 := or.resolve_left (zero_eq_mul.mp ha\u2081.symm) h2a1_ne_0,\n    rw (show a^2-1 = (a+1)*(a-1), by ring) at ha\u2082,\n    have ha1_ne_0 : a + 1 \u2260 0 := ne_of_gt (add_pos ha zero_lt_one),\n    obtain ha\u2083 := or.resolve_left (zero_eq_mul.mp ha\u2082.symm) ha1_ne_0,\n    rw sub_eq_zero at ha\u2083,\n    rw ha\u2083 at hq\u2083, norm_num at hq\u2083 },\nend\n", "meta": {"author": "manuelcandales", "repo": "imo-lean", "sha": "fa54938100fc84c98fe04e1d19e20a424dd006e7", "save_path": "github-repos/lean/manuelcandales-imo-lean", "path": "github-repos/lean/manuelcandales-imo-lean/imo-lean-fa54938100fc84c98fe04e1d19e20a424dd006e7/src/imo2008_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7467705557442713}}
{"text": "import linear_algebra.basic     \nimport data.fintype.basic\nimport algebra.big_operators\nimport data.finset algebra.big_operators\nimport data.set.function\nimport data.equiv.basic\nopen finset \nopen equiv function fintype finset\nuniverses u v w\nnamespace technical \nnotation `\u03a3` := finset.sum finset.univ \nvariables {\u03b1 : Type u} {\u03b2 : Type v}\nlemma finset.prod_univ_perm [fintype \u03b1] [comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} (\u03c3 : perm \u03b1) :\n  (univ : finset \u03b1).prod f = univ.prod (\u03bb z, f (\u03c3 z)) :=\neq.symm $ prod_bij (\u03bb z _, \u03c3 z) (\u03bb _ _, mem_univ _) (\u03bb _ _, rfl)\n  (\u03bb _ _ _ _ H, \u03c3.injective H) (\u03bb b _, \u27e8\u03c3\u207b\u00b9 b, mem_univ _, by simp\u27e9)\nend technical\n\ndef Sum {R : Type u}[add_comm_monoid R]{X : Type v}[fintype X](g : X \u2192 R) : R  := finset.sum (finset.univ) g \n\n\n\nlemma Sum_permutation  {R :Type u}[add_comm_monoid R]{X : Type v}[fintype X](g : X \u2192 R)(\u03c3 : equiv.perm X )\n: finset.sum (finset.univ) g =   finset.sum (finset.univ) (\u03bb z, g (\u03c3 z))  :=   @technical.finset.prod_univ_perm _ (multiplicative R) _ _ g \u03c3\n\nlemma Sum_add {R : Type} [ring R]{X : Type}[fintype X] (g : X \u2192 R)(h : X \u2192 R)  :  \u03a3  (h+g) = \u03a3  h + \u03a3  g  := begin\n    exact multiset.sum_map_add,  --- \nend\n#check multiset.sum_map_sum_map\n\nlemma Sum.left_mul {R : Type} [ring  R]{X : Type}[fintype X] (g : X \u2192 R)  (r : R):  \u03a3 (r \u2022  g) = r \u2022 \u03a3 g  := begin\n    exact multiset.sum_map_mul_left,\nend\n\n\nlemma Sum.left_right {R : Type} [add_comm_monoid R]{X : Type}[fintype X] (g : X \u2192 R)(r : R) :  \u03a3  (r \u2022   g ) =  (\u03a3  g)   := begin\n    rw mul_comm, exact Sum.left_mul g r,\nend\nlemma Sum.morp {R : Type} [add_comm_monoid R] (R' : Type) [add_comm_monoid R']\n{X : Type}[fintype X] (g : X \u2192 R) (\u03c6 : R \u2192+ R') : \u03c6 ( \u03a3   g ) =  \u03a3 (\u03bb t, \u03c6  ( g t) )    := begin\n    exact add_monoid_hom.map_sum \u03c6 g univ,\nend\n\ndef Sum' (R : Type)[hyp1 : comm_ring R](X :Type)[hyp2 : fintype X] : (X \u2192 R) \u2192\u2097[R] R := { to_fun := \u03bb g, \u03a3 g,\n  add := begin intros, rw Sum_add,end,\n  smul := begin intros, rw Sum.left_mul, exact rfl, end }\n", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep1/sommation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7467639703412279}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\n! This file was ported from Lean 3 source module data.int.order.units\n! leanprover-community/mathlib commit d012cd09a9b256d870751284dd6a29882b0be105\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Int.Order.Basic\nimport Mathlib.Data.Int.Units\nimport Mathlib.Algebra.GroupPower.Order\n\n/-!\n# Lemmas about units in `\u2124`, which interact with the order structure.\n-/\n\n\nnamespace Int\n\n\n\ntheorem isUnit_sq {a : \u2124} (ha : IsUnit a) : a ^ 2 = 1 := by rw [sq, isUnit_mul_self ha]\n#align int.is_unit_sq Int.isUnit_sq\n\n@[simp]\ntheorem units_sq (u : \u2124\u02e3) : u ^ 2 = 1 := by\n  rw [Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one, isUnit_sq u.isUnit]\n#align int.units_sq Int.units_sq\n\nalias units_sq \u2190 units_pow_two\n#align int.units_pow_two Int.units_pow_two\n\n@[simp]\ntheorem units_mul_self (u : \u2124\u02e3) : u * u = 1 := by rw [\u2190 sq, units_sq]\n#align int.units_mul_self Int.units_mul_self\n\n@[simp]\ntheorem units_inv_eq_self (u : \u2124\u02e3) : u\u207b\u00b9 = u := by rw [inv_eq_iff_mul_eq_one, units_mul_self]\n#align int.units_inv_eq_self Int.units_inv_eq_self\n\n-- `units.coe_mul` is a \"wrong turn\" for the simplifier, this undoes it and simplifies further\n@[simp]\ntheorem units_coe_mul_self (u : \u2124\u02e3) : (u * u : \u2124) = 1 := by\n  rw [\u2190 Units.val_mul, units_mul_self, Units.val_one]\n#align int.units_coe_mul_self Int.units_coe_mul_self\n\n@[simp]\ntheorem neg_one_pow_ne_zero {n : \u2115} : (-1 : \u2124) ^ n \u2260 0 :=\n  pow_ne_zero _ (abs_pos.mp (by simp))\n#align int.neg_one_pow_ne_zero Int.neg_one_pow_ne_zero\n\ntheorem sq_eq_one_of_sq_lt_four {x : \u2124} (h1 : x ^ 2 < 4) (h2 : x \u2260 0) : x ^ 2 = 1 :=\n  sq_eq_one_iff.mpr\n    ((abs_eq (zero_le_one' \u2124)).mp\n      (le_antisymm (lt_add_one_iff.mp (abs_lt_of_sq_lt_sq h1 zero_le_two))\n        (sub_one_lt_iff.mp (abs_pos.mpr h2))))\n#align int.sq_eq_one_of_sq_lt_four Int.sq_eq_one_of_sq_lt_four\n\ntheorem sq_eq_one_of_sq_le_three {x : \u2124} (h1 : x ^ 2 \u2264 3) (h2 : x \u2260 0) : x ^ 2 = 1 :=\n  sq_eq_one_of_sq_lt_four (lt_of_le_of_lt h1 (lt_add_one (3 : \u2124))) h2\n#align int.sq_eq_one_of_sq_le_three Int.sq_eq_one_of_sq_le_three\n\ntheorem units_pow_eq_pow_mod_two (u : \u2124\u02e3) (n : \u2115) : u ^ n = u ^ (n % 2) := by\n  conv =>\n      lhs\n      rw [\u2190 Nat.mod_add_div n 2];\n      rw [pow_add, pow_mul, units_sq, one_pow, mul_one]\n#align int.units_pow_eq_pow_mod_two Int.units_pow_eq_pow_mod_two\n\nend Int\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/Order/Units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7467639675172331}}
{"text": "import MyNat.Definition\nimport MyNat.Addition\nimport AdvancedAdditionWorld.Level1 -- succ_inj\nimport AdvancedAdditionWorld.Level10 -- zero_ne_succ\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Advanced Addition World\n\n## Level 13: `ne_succ_self`\n\nThe last level in Advanced Addition World is the statement\nthat `n \u2260 succ n`.\n\n## Lemma\nFor any natural number `n`, we have ` n \u2260 succ n`.\n-/\nlemma ne_succ_self (n : MyNat) : n \u2260 succ n := by\n  induction n with\n  | zero =>\n    apply zero_ne_succ\n  | succ n ih =>\n    intro hs\n    apply ih\n    apply succ_inj\n    assumption\n\n/-!\nWell that's a wrap on Advanced Addition World !\n\nYou can now move on to Advanced Multiplication World\n(after first doing [Multiplication World](../MultiplicationWorld.lean.md), if you didn't do it already).\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedAdditionWorld/Level13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9572778036723354, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7466698904352663}}
{"text": "import data.fintype.basic\nimport data.set.function\nimport .sum_tools\nimport data.equiv.basic\nimport linear_algebra.bilinear_form\nuniverse variables u v w \nopen finset\nopen_locale big_operators\n/--\n#   Je n'aime pas du tout l'utilisation du produit scalaire car je prefere avoir une notion sp\u00e9cifique \n-/\nvariables {G :Type u} {R : Type v} [group G] [comm_ring R][fintype G]\n/-!\n    We define a `scalar_product` on function `G \u2192 R`\n-/\ndef bilinear   (\u03c6 \u03c8 : G \u2192 R  ) :=  \u2211 t, (\u03c6 t) *  (\u03c8 t\u207b\u00b9)    \n\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\nvariables (\u03c6 \u03c8 :  G \u2192 R  )\nnotation ` \u2045  ` \u03c6 ` | ` \u03c8 ` \u2046 ` := bilinear \u03c6 \u03c8 \n/--\n     `\u300a \u03c6 + \u03b3 | \u03c8 \u300b = \u300a \u03c6 | \u03c8 \u300b + \u300a \u03b3  | \u03c8 \u300b`\n-/\n@[simp]theorem add_first  (\u03c6 \u03b3 \u03c8  : G \u2192 R  ) : \u2045 \u03c6 + \u03b3 | \u03c8 \u2046  = \u2045  \u03c6 | \u03c8 \u2046  + \u2045  \u03b3  | \u03c8 \u2046  := \nbegin \n      unfold bilinear, erw \u2190 multiset.sum_map_add,  --- ?\n      congr,funext, erw \u2190 right_distrib _ _ (\u03c8 t\u207b\u00b9),\n      exact rfl,\nend\n/--\n     `\u300a r \u2022 \u03c6  | \u03c8 \u300b = r \u2022 \u300a \u03c6 | \u03c8 \u300b`  \n-/\n@[simp]theorem smul_first  (r : R) (\u03c6 \u03c8   : G \u2192 R  ) : \u2045  r \u2022 \u03c6  | \u03c8 \u2046  = r \u2022 \u2045 \u03c6 | \u03c8 \u2046  := begin \n      unfold bilinear,\n     erw  finset.smul_sum,congr,funext, erw mul_assoc, exact rfl,\nend\n/--\n     `\u2045  \u03c8  |  \u03c6 \u2046  =  \u2045 \u03c6 | \u03c8 \u2046`  \n-/\n@[simp]theorem symm_bilinear (\u03c6 \u03c8   : G \u2192 R  ) : \u2045  \u03c8  |  \u03c6 \u2046  =  \u2045 \u03c6 | \u03c8 \u2046 := \nbegin\n    unfold bilinear,\n    rw sum_univ_perm _ (inv_equiv), congr,\n    funext, unfold inv_equiv, dsimp, rw inv_inv,rw mul_comm,\nend \n/--\n    `\u2045 \u03c6  | \u03c8 + \u03b3\u2046  = \u2045  \u03c6 | \u03c8 \u2046  + \u2045  \u03c6   | \u03b3  \u2046`\n-/\n@[simp]theorem add_snd  (\u03c6 \u03c8 \u03b3  : G \u2192 R  ) : \u2045 \u03c6  | \u03c8 + \u03b3\u2046  = \u2045  \u03c6 | \u03c8 \u2046  + \u2045  \u03c6   | \u03b3  \u2046  :=begin \n    rw symm_bilinear, rw add_first, simp,\nend\n/--\n    `\u2045   \u03c6  | r \u2022 \u03c8 \u2046  = r \u2022 \u2045 \u03c6 | \u03c8 \u2046\n-/\n@[simp]theorem smul_snd  (r : R) (\u03c6 \u03c8   : G \u2192 R  ) : \u2045   \u03c6  | r \u2022 \u03c8 \u2046  = r \u2022 \u2045 \u03c6 | \u03c8 \u2046 := begin \n    rw symm_bilinear, rw smul_first, rw symm_bilinear,\nend\n\n\ndef scalar_product (G : Type u)[group G] [fintype G] (R : Type v) [group G] [comm_ring R] : bilin_form  R (G \u2192 R) := { \n  bilin             := @bilinear G R _ _ _,\n  bilin_add_left    := @add_first G R _ _ _,\n  bilin_smul_left   := @smul_first G R _ _ _,\n  bilin_add_right   := @add_snd G R _ _ _,\n  bilin_smul_right  := @smul_snd G R _ _ _\n}  \n/--\n    `scalar_product G f1 f2 =   \u2211 t, (f1 t) *  (f2 t\u207b\u00b9) `\n-/\nlemma scalar_product_ext (G : Type u)[group G] [fintype G] {R : Type v} [group G] [comm_ring R] (f1 f2 : G \u2192 R ) : \n    scalar_product G R f1 f2 =   \u2211 t, (f1 t) *  (f2 t\u207b\u00b9) := rfl \nopen bilin_form\n/--\n    `scalar_product G f1 f2 = \u2045   f1  | f2 \u2046`\n-/\nlemma scalar_product_ext' (G : Type u)[group G] [fintype G] (f1 f2 : G \u2192 R ) : scalar_product G R f1 f2 = \n       \u2045   f1  | f2 \u2046 := rfl \nopen bilin_form\nlemma bilin_sum (X Y : Type w )[fintype X][fintype Y][decidable_eq X][decidable_eq Y] \n (\u03c6_l : X \u2192 (G \u2192 R ))\n (\u03c6_r : Y \u2192 (G \u2192 R )) : \n scalar_product G R (\u2211 x, \u03c6_l x ) (\u2211 y, \u03c6_r y) = \u2211 x, (\u2211 y, scalar_product G R (\u03c6_l x) (\u03c6_r y)) := \n begin \n  rw map_sum_left,\n  congr,\n  funext,\n  rw map_sum_right,\nend \nlemma bilin_symm (G : Type u)[group G] [fintype G] (f1 f2 : G \u2192 R ) : scalar_product G R f1 f2 = scalar_product G R f2 f1 :=\nbegin \n    rw scalar_product_ext', erw  symm_bilinear,  exact rfl,\nend", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep_2/Tools/bilinear_over_comm_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7466078977888018}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Sets in Lean, example sheet 2 : the empty set and the \"universal set\".\n\nWe know what the empty subset of `X` is, and the Lean notation for\nit is `\u2205`, or, if you want to say which type we're the empty subset\nof, it's `\u2205 : set X`. \n\nAt the other extreme, the subset of `X` containing all the terms of type `X`\nis...well...mathematicians would just call it `X`, but `X` is a type, and\nso if we want a set it's called `set.univ : set X`, or just `univ : set X` if\nwe have opened the `set` namespace. Let's do that now.\n\n-/\n\nopen set\n\n/-\n\n## Important\n\n`x \u2208 \u2205` is *by definition* equal to `false` and `x \u2208 univ` is *by definition*\nequal to `true`. You can use the `change` tactic to make these changes\nif you like. But you don't have to.\n\n## Tactics you will need\n\nYou've seen them already. `trivial` proves `\u22a2 true` and `exfalso`\nchanges `\u22a2 P` to `\u22a2 false`.\n\n-/\n\n\n-- set up variables\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D E : set X) -- A,B,C,D,E are subsets of `X`\n  (x y z : X) -- x,y,z are elements of `X` or, more precisely, terms of type `X`\n\n/-\n\nIf `x : X` then `x \u2208 \u2205` is *by definition* `false`, and `x \u2208 univ` is\n*by definition* `true`. So you can use the `change` tactic to change\nbetween these things, for example if your goal is\n\n```\n\u22a2 x \u2208 univ\n```\n\nthen `change true` will change the goal to\n\n```\n\u22a2 true\n```\n\nand you can now prove this goal with `trivial`. However you can prove\nit with `trivial` even without `change`ing it.\n\n-/\n\nopen set\n\nexample : x \u2208 (univ : set X) := \nbegin\n  sorry\nend\n\nexample : x \u2208 (\u2205 : set X) \u2192 false :=\nbegin\n  sorry\nend\n\nexample : \u2200 x : X, x \u2208 A \u2192 x \u2208 (univ : set X) :=\nbegin\n  sorry\nend\n\nexample : \u2200 x : X, x \u2208 (\u2205 : set X) \u2192 x \u2208 A :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2021/sets/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7465994979648535}}
{"text": "import data.fintype.basic order.filter.at_top_bot\n\nlemma subseq_ex_frequent_val_of_finite_range\n{\u03b2 : Type} [fintype \u03b2]\n(s : \u2115 \u2192 \u03b2) :\n\u2203 (b : \u03b2), \u2200 n : \u2115, \u2203 m : \u2115, m \u2265 n \u2227 s m = b :=\nbegin\n  by_contra,\n  push_neg at h,\n  choose ns hns using h,\n  let n := finset.univ.sup ns,\n  have : n \u2265 ns (s n) := finset.le_sup (finset.mem_univ (s n)),\n  replace := hns (s n) n this,\n  exact this rfl,\nend\n\nlemma ex_const_subseq_of_finite_range\n{\u03b2: Type} [fintype \u03b2]\n(s : \u2115 \u2192 \u03b2) :\n\u2203 (b : \u03b2) (\u03c6 : \u2115 \u2192 \u2115),\nstrict_mono \u03c6 \u2227\n\u2200 n : \u2115, s (\u03c6 n) = b :=\nbegin\n  rcases subseq_ex_frequent_val_of_finite_range s\n    with \u27e8b, hb\u27e9,\n  refine \u27e8b, _\u27e9,\n  convert filter.extraction_of_frequently_at_top' _,\n  rotate,\n  {exact \u03bb n, s n = b},\n  rotate,\n  {refl},\n  intro n,\n  rcases hb n.succ with \u27e8m, hge, heq\u27e9,\n  exact \u27e8m, (nat.lt_of_succ_le hge), heq\u27e9,\nend\n\nlemma ex_const_mem_subseq_of_setvalued_seq\n{\u03b2 : Type} [fintype \u03b2]\n{s : \u2115 \u2192 finset \u03b2}\n(hs : \u2200 n : \u2115, (s n).nonempty) :\n\u2203 (b : \u03b2) (\u03c6 : \u2115 \u2192 \u2115),\nstrict_mono \u03c6 \u2227\n\u2200 n : \u2115, b \u2208 s (\u03c6 n) :=\nbegin\n  choose s' hs' using hs,\n  rcases ex_const_subseq_of_finite_range s'\n    with \u27e8b, \u03c6, hmon, heq\u27e9,\n  refine \u27e8b, \u03c6, hmon, _\u27e9,\n  intro n,\n  rw [\u2190heq n],\n  exact hs' (\u03c6 n),\nend\n\n-- perhaps compare subseq_forall_of_frequently\nlemma subseq_forall_of_frequently'\n{\u03b1 : Type}\n{s : \u2115 \u2192 \u03b1}\n(p : \u03b1 \u2192 Prop)\n(h : \u2203\u1da0 n in filter.at_top, p (s n)) :\n\u2203 \u03c6 : \u2115 \u2192 \u2115,\nstrict_mono \u03c6 \u2227\n\u2200 n : \u2115, p ((s \u2218 \u03c6) n) :=\nbegin\n  have : \u2200 n : \u2115, \u2203 m : \u2115, m \u2265 n \u2227 p (s m),\n  {\n    intro n,\n    rw [filter.frequently_at_top] at h,\n    obtain \u27e8m, h\u2081, h\u2082\u27e9 := h n,\n    refine \u27e8m, h\u2081, h\u2082\u27e9,\n  },\n  choose \u03c6\u2081 h\u2081 using this,\n  obtain \u27e8\u03c6\u2082, h\u2082\u2081, h\u2082\u2082\u27e9 := filter.strict_mono_subseq_of_id_le (\u03bb n, (h\u2081 n).1),\n  refine \u27e8\u03c6\u2081 \u2218 \u03c6\u2082, h\u2082\u2082, _\u27e9,\n  intro n,\n  simp only [function.comp_app],\n  exact (h\u2081 (\u03c6\u2082 n)).2,\nend\n\n/- lemma frequently_subseq\n{\u03b1 : Type}\n{s : \u2115 \u2192 \u03b1}\n(p : \u03b1 \u2192 Prop)\n(h : \u2200\u1da0 n in filter.at_top, p (s n)) : -/\n", "meta": {"author": "datokrat", "repo": "triangle-bodies", "sha": "532a2820a0cb3686afddb60051340acf2f03db9e", "save_path": "github-repos/lean/datokrat-triangle-bodies", "path": "github-repos/lean/datokrat-triangle-bodies/triangle-bodies-532a2820a0cb3686afddb60051340acf2f03db9e/src/sequence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874624, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7464840937810066}}
{"text": "-- we want to use tactics\nimport tactic\n-- we want to use the real numbers\nimport data.real.basic\n\n/-\n\n# Limits of sequences in Lean\n\nWe give the standard `\u03b5`, `N` definition of the limit of a sequence\nand prove some theorems about them. The boss level: limit of\nproducts is product of limits.\n\n## Lean level\n\nYou need to know the natural number game tactics and a few more too.\nCheck out the `HINTS.md` file for more information about tactics which\nare useful for this sheet. I would say this sheet was of easy\nmathematical difficulty and medium lean difficulty.\n\n-/\n\n/-\n\n## lambda (\u03bb) notation for functions\n\nHere's how we define the functions from the naturals to the naturals\nsending n to n^2 + 3:\n\n-/\n\ndef f : \u2115 \u2192 \u211d := \u03bb n, n^2+3\n\n/-\n\nMathematicians might write `n \u21a6 n^2+3` for this functions; indeed `\u03bb` is\njust prefix notation for the infix notation `\u21a6` (i.e. you write it at the\nfront, not in the middle).\n\nThe reason we need to know about function notation for this sheet\nis that a sequence `x\u2080, x\u2081, x\u2082, \u2026` of reals on this sheet will\nbe encoded as a function `f : \u2115 \u2192 \u211d` sending `0` to `x\u2080`, `1` to `x\u2081`\nand so on.\n \n## Limit of a sequence.\n\nHere's the definition of the limit of a sequence in Lean.\nIn VS Code, if you ever hover any `tendsto` *other* than the one actually\nbeing defined, you can see the\ndefinition and the docstring (just above it) formatted nicely.\n-/\n\n/-- If `a(n)` is a sequence of reals and `t` is a real, `tendsto a t`\nis the assertion that the limit of `a(n)` as `n \u2192 \u221e` is `t`. -/\ndef tendsto (a : \u2115 \u2192 \u211d) (t : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 B : \u2115, \u2200 n, B \u2264 n \u2192 |a n - t| < \u03b5\n\n-- the basic API for `tendsto`\n\n/-- If your goal is `tendsto a t` and you want to replace it with\n`\u2200 \u03b5 > 0, \u2203 B, \u2026` then you can do this with `rw tendsto_def`. -/\ntheorem tendsto_def {a : \u2115 \u2192 \u211d} {t : \u211d} :\n  tendsto a t \u2194 \u2200 \u03b5, 0 < \u03b5 \u2192 \u2203 B : \u2115, \u2200 n, B \u2264 n \u2192 |a n - t| < \u03b5 :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-\n\n## The questions\n\nHere are some basic results about limits of sequences.\nSee if you can fill in the `sorry`s with Lean proofs.\nThe HINTS.md file in this directory contains some mathematical\nsketch proofs and some hints about which tactics might be helpful\nin this situation.\n\n-/\n\n/-- The limit of the constant sequence with value 37 is 37. -/\ntheorem tendsto_thirtyseven (c : \u211d) : tendsto (\u03bb n, 37) 37 :=\nbegin\n  -- start with `rw tendsto_def` so you can see what's going on.\n  -- That's the point of `tendsto_def`. \n  sorry,\nend\n\n/-- The limit of the constant sequence with value `c` is `c`. -/\ntheorem tendsto_const (c : \u211d) : tendsto (\u03bb n, c) c :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` then `a(n) + c` tends to `t + c` -/\ntheorem tendsto_add_const {a : \u2115 \u2192 \u211d} {t : \u211d} (c : \u211d)\n  (h : tendsto a t) :\n  tendsto (\u03bb n, a n + c) (t + c) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` then `-a(n)` tends to `-t`.  -/\ntheorem tendsto_neg {a : \u2115 \u2192 \u211d} {t : \u211d} (ha : tendsto a t) :\n  tendsto (\u03bb n, - a n) (-t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `b(n)` tends to `u` then `a(n) + b(n)`\ntends to `t + u`. -/\ntheorem tendsto_add {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (\u03bb n, a n + b n) (t + u) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to t and `b(n)` tends to `u` then `a(n) - b(n)`\ntends to `t - u`. -/\ntheorem tendsto_sub {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (\u03bb n, a n - b n) (t - u) :=\nbegin\n  sorry\nend\n\n/-- If `a(n)` tends to `t` then `37 * a(n)` tends to `37 * t`-/\ntheorem tendsto_thirtyseven_mul (a : \u2115 \u2192 \u211d) (t : \u211d) (h : tendsto a t) :\n  tendsto (\u03bb n, 37 * a n) (37 * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a positive constant then\n`c * a(n)` tends to `c * t`. -/\ntheorem tendsto_pos_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (h : tendsto a t)\n  {c : \u211d} (hc : 0 < c) : tendsto (\u03bb n, c * a n) (c * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a negative constant then\n`c * a(n)` tends to `c * t`. -/\ntheorem tendsto_neg_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (h : tendsto a t)\n  {c : \u211d} (hc : c < 0) : tendsto (\u03bb n, c * a n) (c * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a constant then `c * a(n)` tends\nto `c * t`. -/\ntheorem tendsto_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (c : \u211d) (h : tendsto a t) :\n  tendsto (\u03bb n, c * a n) (c * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a constant then `a(n) * c` tends\nto `t * c`. -/\ntheorem tendsto_mul_const {a : \u2115 \u2192 \u211d} {t : \u211d} (c : \u211d) (h : tendsto a t) :\n  tendsto (\u03bb n, a n * c) (t * c) :=\nbegin\n  sorry\nend\n\n/-- If `a(n)-b(n)` tends to `t` and `b(n)` tends to `u` then\n`a(n)` tends to `t + u`. -/\ntheorem tendsto_of_tendsto_sub {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (h1 : tendsto (\u03bb n, a n - b n) t) (h2 : tendsto b u) :\n  tendsto a (t+u) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` then `a(n)-t` tends to `0`. -/\ntheorem tendsto_sub_lim {a : \u2115 \u2192 \u211d} {t : \u211d}\n  (h : tendsto a t) : tendsto (\u03bb n, a n - t) 0 :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` and `b(n)` both tend to zero, then their product tends\nto zero. -/\ntheorem tendsto_zero_mul_tendsto_zero\n  {a b : \u2115 \u2192 \u211d} (ha : tendsto a 0) (hb : tendsto b 0) :\n  tendsto (\u03bb n, a n * b n) 0 :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `b(n)` tends to `u` then\n`a(n)*b(n)` tends to `t*u`. -/\ntheorem tendsto_mul (a b : \u2115 \u2192 \u211d) (t u : \u211d) (ha : tendsto a t)\n  (hb : tendsto b u) : tendsto (\u03bb n, a n * b n) (t * u) :=\nbegin\n  sorry,\nend\n\n-- something we never used!\n/-- A sequence has at most one limit. -/\ntheorem tendsto_unique (a : \u2115 \u2192 \u211d) (s t : \u211d)\n  (hs : tendsto a s) (ht : tendsto a t) : s = t :=\nbegin\n  sorry\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "lean-maths-examples", "sha": "fc5521567da32bca2a568a0811488f793d3ddd75", "save_path": "github-repos/lean/ImperialCollegeLondon-lean-maths-examples", "path": "github-repos/lean/ImperialCollegeLondon-lean-maths-examples/lean-maths-examples-fc5521567da32bca2a568a0811488f793d3ddd75/src/limits-of-sequences/questions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7464840896653012}}
{"text": "\n-- various flavours of induction \n\nimport  .num_lemmas \n----------------------------------------------------------------\nopen_locale classical \nnoncomputable theory \n\nuniverse u \n\nopen set \n\nvariables {\u03b1 : Type*} \n\nsection numbers \n\nvariables (P : \u2124 \u2192 Prop)\n\n/-- Strong induction (with base case 0) for the nonnegative integers -/\nlemma nonneg_int_strong_induction : \n  P 0 \u2192 (\u2200 n, 0 < n \u2192 (\u2200 m, 0 \u2264 m \u2192 m < n \u2192 P m) \u2192 P n) \u2192 (\u2200 n\u2080, 0 \u2264 n\u2080 \u2192 P n\u2080) := \nbegin\n  intros h0 IH n\u2080 hn\u2080, \n  set Q : \u2115 \u2192 Prop := \u03bb s, (\u2200 t, t \u2264 s \u2192 P t) with hQ,\n  suffices : Q (n\u2080.to_nat), \n\n  have h' := this n\u2080.to_nat (le_of_eq _), \n  rw (int.to_nat_of_nonneg hn\u2080) at h', from h', refl,\n\n  apply nat.case_strong_induction_on _, \n  refine \u03bb t ht, _, \n  rw nat.eq_zero_of_le_zero ht, norm_cast, from h0, \n\n  intros n hn t ht, \n  cases (nat.eq_zero_or_pos t), \n  rw h, norm_cast, from h0, \n\n  apply IH t _, \n  intros m h0m hmt, \n  have := hn (m.to_nat) _ (m.to_nat) (le_refl _), \n  rw (int.to_nat_of_nonneg h0m) at this, from this,\n\n  rw int.to_nat_le, \n  rw [\u2190int.coe_nat_le_coe_nat_iff, \u2190int.coe_nat_add_one_out] at ht, linarith, \n\n  exact int.coe_nat_pos.mpr h, \nend\n\n/-- Induction on nonnegative integers with base case 0, and inductive step n-1 \u2192 n -/\nlemma nonneg_int_induction_minus : \n  P 0 \u2192 (\u2200 n, 0 < n \u2192 P (n-1) \u2192 P n) \u2192 (\u2200 n\u2080, 0 \u2264 n\u2080 \u2192 P n\u2080) := \nbegin\n  intros h0 IH, \n  apply nonneg_int_strong_induction _ h0, \n  from \u03bb n hn0 IHs, IH n hn0 (IHs _ (int.le_sub_one_of_lt hn0) (sub_one_lt _)),  \nend\n\n/-- Induction on nonnegative integers with base case 0, and inductive step n \u2192 n+1 -/\nlemma nonneg_int_induction : \n  P 0 \u2192 (\u2200 n, 0 \u2264 n \u2192 P n \u2192 P (n+1)) \u2192 (\u2200 n\u2080, 0 \u2264 n\u2080 \u2192 P n\u2080) := \nbegin\n  refine \u03bb h IHplus, (nonneg_int_induction_minus P h (\u03bb n hn, _)), \n  have := \u03bb hminus, IHplus (n-1) (int.le_sub_one_of_lt hn) hminus,  \n  norm_num at this, assumption, \nend\n\nlemma nat_induction_zero_one (P : \u2115 \u2192 Prop) (n\u2080 : \u2115) : \n  P 0 \u2192 P 1 \u2192 (\u2200 n, 2 \u2264 n \u2192 P (n-1) \u2192 P n) \u2192 P n\u2080 :=\nbegin\n  intros h0 h1 hind, \n  induction n\u2080 with m,\n  from h0, \n  cases nat.eq_zero_or_pos m, \n  rw h, from h1, \n  have : 2 \u2264 m.succ := by {rw nat.succ_eq_add_one, linarith},\n  from hind _ this n\u2080_ih, \nend\n\n/-- Proves that P holds for all elements of a type \u03b1 by \n    strong induction on the value of a nonnegative parameter f on \u03b1 -/\n\nlemma nonneg_int_strong_induction_param (P : \u03b1 \u2192 Prop) (f : \u03b1 \u2192 \u2124)\n(f_nonneg : \u2200 a : \u03b1, 0 \u2264 f a) :\n  (\u2200 a, f a = 0 \u2192 P a) \u2192 (\u2200 a : \u03b1, 0 < f a \u2192 (\u2200 a', f a' < f a \u2192 P a') \u2192 P a) \u2192 (\u2200 a, P a) :=\nbegin\n  let Q : \u2124 \u2192 Prop := \u03bb s, \u2200 a, f a = s \u2192 P a,\n  intros h h', \n  suffices : \u2200 n\u2080, 0 \u2264 n\u2080 \u2192 Q n\u2080, \n    from \u03bb a, this (f a) (f_nonneg _) _ rfl, \n  apply nonneg_int_strong_induction Q h,\n  intros n hn hnI a ha,\n  refine h' _ (by {rw ha, from hn}) (\u03bb a' ha', _), \n  from hnI (f a') (f_nonneg a') (by {rw \u2190ha ,from ha'}) _ rfl,  \nend\n\nlemma min_counterexample_nonneg_int_param (P : \u03b1 \u2192 Prop) (f : \u03b1 \u2192 \u2124) (f_nonneg : \u2200 a : \u03b1, 0 \u2264 f a) :\n  \u00ac (\u2200 a, P a) \u2192 \u2203 x, (\u00ac P x \u2227 \u2200 x', f x' < f x \u2192 P x') :=\nbegin\n  contrapose!, \n  refine \u03bb h, nonneg_int_strong_induction_param P f f_nonneg \n    (\u03bb a ha, by_contra (\u03bb hn, _)) \n    (\u03bb a ha h', by_contra (\u03bb hn, (let \u27e8a',h\u2081,h\u2082\u27e9 := h _ hn in h\u2082 (h' _ h\u2081)))),\n  obtain \u27e8a', h', -\u27e9 :=  h _ hn,\n  have := f_nonneg a', \n    -- linarith should work here before the rw but for some reason it doesn't. Look into this.\n  rw ha at h',\n  linarith,   \nend\n\n\n\n\nend numbers \n\n ", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_aux/prelim/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8289388083214155, "lm_q1q2_score": 0.7464840811237756}}
{"text": "import NBG.SetTheory.Relation.Reflexive\n\n\ndef isSymmetric (R : Class) [Relation R] : Prop := (R \uff1d RelInv R)\nclass Symmetric (R : Class) extends Relation R where\n  isSymmetric : isSymmetric R\n\ndef isTransitiveRelation (R : Class) [Relation R] : Prop :=\n  \u2200x y z: Class, \u2200_: Set x, \u2200_: Set y, \u2200_: Set z,\n    (\uff1cx, y\uff1e \u2208 R \u2227 \uff1cy, z\uff1e \u2208 R) \u2192 \uff1cx, z\uff1e \u2208 R\nclass TransitiveRelation (R : Class) extends Relation R where\n  isTransitiveRelation : isTransitiveRelation R\n\ndef isEquivalence (R : Class) [Relation R] : Prop :=\n  isSymmetric R \u2227 isTransitiveRelation R\nclass EqivalenceRelation (R : Class) extends Symmetric R, TransitiveRelation R\n\ntheorem IdentityFunctionIsEquivalenceRelation:\n  @isEquivalence IdClass \u27e8IdClassIsRelation\u27e9 := sorry\n\ntheorem EquivalenceRelationImpDomEqRng (R : Class) [EqivalenceRelation R]:\n  Dom R \uff1d Rng R := sorry\n\ntheorem EquivalenceRelationIsReflexive (R : Class) [EqivalenceRelation R]:\n  isReflexive R := sorry\n\n-- Equivalence Class\n\n", "meta": {"author": "furea2", "repo": "NBG", "sha": "51b45e0b08c1d0090430b0d898de4fc1b7bc09d7", "save_path": "github-repos/lean/furea2-NBG", "path": "github-repos/lean/furea2-NBG/NBG-51b45e0b08c1d0090430b0d898de4fc1b7bc09d7/NBG/SetTheory/Relation/Equivalence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7464259621477773}}
{"text": "import ..lovelib\n\n\n/-! # LoVe Exercise 3: Forward Proofs -/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Connectives and Quantifiers\n\n1.1. Supply structured proofs of the following lemmas. -/\n\nlemma I (a : Prop) :\n  a \u2192 a :=\nsorry\n\nlemma K (a b : Prop) :\n  a \u2192 b \u2192 b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 b \u2192 a \u2192 c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a \u2192 a \u2192 a :=\nsorry\n\n/-! Please give a different answer than for `proj_1st`. -/\n\nlemma proj_2nd (a : Prop) :\n  a \u2192 a \u2192 a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 a \u2192 (a \u2192 c) \u2192 b \u2192 c :=\nsorry\n\n/-! 1.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a \u2192 b) \u2192 \u00ac b \u2192 \u00ac a :=\nsorry\n\n/-! 1.3. Supply a structured proof of the distributivity of `\u2200` over `\u2227`. -/\n\nlemma forall_and {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2200x, p x \u2227 q x) \u2194 (\u2200x, p x) \u2227 (\u2200x, q x) :=\nsorry\n\n/-! 1.4 (**optional**). Reuse, if possible, the lemma `forall_and` from question\n1.3 to prove the following instance of the lemma. -/\n\nlemma forall_and_inst {\u03b1 : Type} (r s : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2200x, r x x \u2227 s x x) \u2194 (\u2200x, r x x) \u2227 (\u2200x, s x x) :=\nsorry\n\n/-! 1.5. Supply a structured proof of the following property, which can be used\npull a `\u2200`-quantifier past an `\u2203`-quantifier. -/\n\nlemma forall_exists_of_exists_forall {\u03b1 : Type} (p : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2203x, \u2200y, p x y) \u2192 (\u2200y, \u2203x, p x y) :=\nsorry\n\n\n/-! ## Question 2: Chain of Equalities\n\n2.1. Write the following proof using `calc`.\n\n      (a + b) * (a + b)\n    = a * (a + b) + b * (a + b)\n    = a * a + a * b + b * a + b * b\n    = a * a + a * b + a * b + b * b\n    = a * a + 2 * a * b + b * b\n\nHint: You might need the tactics `simp` and `cc` and the lemmas `mul_add`,\n`add_mul`, and `two_mul`. -/\n\nlemma binomial_square (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/-! 2.2 (**optional**). Prove the same argument again, this time as a structured\nproof, with `have` steps corresponding to the `calc` equations. Try to reuse as\nmuch of the above proof idea as possible, proceeding mechanically. -/\n\nlemma binomial_square\u2082 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/-! 2.3. Prove the same lemma again, this time using tactics. -/\n\nlemma binomial_square\u2083 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nbegin\n  sorry\nend\n\n\n/-! ## Question 3 (**optional**): One-Point Rules\n\n3.1 (**optional**). Prove that the following wrong formulation of the one-point\nrule for `\u2200` is inconsistent, using a structured proof. -/\n\naxiom forall.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2200x : \u03b1, x = t \u2227 p x) \u2194 p t\n\nlemma proof_of_false :\n  false :=\nsorry\n\n/-! 3.2 (**optional**). Prove that the following wrong formulation of the\none-point rule for `\u2203` is inconsistent, using a tactical or structured proof. -/\n\naxiom exists.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2203x : \u03b1, x = t \u2192 p x) \u2194 p t\n\nlemma proof_of_false\u2082 :\n  false :=\nsorry\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/exercises/love03_forward_proofs_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7463209649892693}}
{"text": "import data.real.basic\nimport data.nat.prime\n\nexample {x y : \u211d} (h\u2080 : x \u2264 y) (h\u2081 : \u00ac y \u2264 x) : x \u2264 y \u2227 x \u2260 y :=\nbegin\n  split,\n  { assumption},\n  intro h,\n  apply h\u2081,\n  rw h,\nend\n\nexample {x y : \u211d} (h\u2080 : x \u2264 y) (h\u2081 : \u00ac y \u2264 x) : x \u2264 y \u2227 x \u2260 y :=\nbegin\n  have h : x \u2260 y,\n  { contrapose! h\u2081,\n    rw h\u2081 },\n  exact \u27e8h\u2080, h\u27e9\nend\n\nexample {x y : \u211d} (h : x \u2264 y \u2227 x \u2260 y) : \u00ac y \u2264 x :=\nbegin\n  cases h with h1 h2,\n  contrapose! h2,\n  from le_antisymm h1 h2,\nend\n\nexample {m n : \u2115} (h : m \u2223 n \u2227 m \u2260 n) :\n  m \u2223 n \u2227 \u00ac n \u2223 m :=\nbegin \n  cases h with h1 h2,\n  split,\n  { exact h1,},\n  { contrapose! h2,\n    exact nat.dvd_antisymm h1 h2},\nend\n\nexample (x y : \u211d) : (\u2203 z : \u211d, x < z \u2227 z < y) \u2192 x < y :=\nbegin\n  rintros \u27e8z, xltz, zlty\u27e9,\n  from lt_trans xltz zlty,\nend\n\nexample {x y : \u211d} (h : x \u2264 y) : \u00ac y \u2264 x \u2194 x \u2260 y :=\nbegin \n  split,\n    contrapose!,\n    intro h',\n    from le_of_eq h'.symm,\n\n    contrapose!,\n    from le_antisymm h,\nend\n\nexample {x y : \u211d} : x \u2264 y \u2227 \u00ac y \u2264 x \u2194 x \u2264 y \u2227 x \u2260 y :=\nbegin\n  split,\n  { rintros \u27e8h1, h2\u27e9,\n    split,\n    { from h1,},\n    { contrapose! h2,\n      from le_of_eq h2.symm,},\n  },\n  { rintros \u27e8h1, h2\u27e9,\n    split,\n    { from h1,},\n    { contrapose! h2,\n      from le_antisymm h1 h2,},\n  },\nend\n\ntheorem aux {x y : \u211d} (h : x^2 + y^2 = 0) : x = 0 :=\nbegin\n  have h' : x^2 = 0,\n  { apply le_antisymm,\n    { apply le_of_not_gt,\n      intro hn,\n      have : x^2 + y^2 > y^2 := by linarith,\n      have : 0 > y^2 := by linarith,\n      have : 0 \u2264 y^2 := by apply pow_two_nonneg,\n      linarith,},\n    { apply pow_two_nonneg,}\n  },\n  exact pow_eq_zero h'\nend\n\nexample (x y : \u211d) : x^2 + y^2 = 0 \u2194 x = 0 \u2227 y = 0 :=\nbegin \n  split,\n  { intro h,\n    split,\n    from aux h,\n    rw add_comm at h,\n    from aux h,\n  },\n  { rintro \u27e8h1, h2\u27e9,\n    rw [h1, h2],\n    norm_num,\n  },\nend\n\nexample (x y : \u211d) : abs (x + 3) < 5 \u2192 -8 < x \u2227 x < 2 :=\nbegin\n  rw abs_lt,\n  intro h,\n  split; linarith,\nend\n\ntheorem not_monotone_iff {f : \u211d \u2192 \u211d}:\n  \u00ac monotone f \u2194 \u2203 x y, x \u2264 y \u2227 f x > f y :=\nby { rw monotone, push_neg }\n\nexample : \u00ac monotone (\u03bb x : \u211d, -x) :=\nbegin \n  rw not_monotone_iff,\n  use [1, 2],\n  norm_num,\nend\n\n\nsection\nvariables {\u03b1 : Type*} [partial_order \u03b1]\nvariables a b : \u03b1\n\nexample : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\nbegin\n  rw lt_iff_le_not_le,\n  split,\n  { rintro \u27e8h1 , h2\u27e9,\n    split,\n    from h1,\n    intro h,\n    apply h2,\n    from le_of_eq h.symm,\n  },\n  { rintro \u27e8h1, h2\u27e9,\n    split,\n    from h1,\n    contrapose! h2,\n    from le_antisymm h1 h2,\n  },\nend\n\nend\n\n\nsection\nvariables {\u03b1 : Type*} [preorder \u03b1]\nvariables a b c : \u03b1\n\nexample : \u00ac a < a :=\nbegin\n  rw lt_iff_le_not_le,\n  rintro \u27e8h, hn\u27e9,\n  from hn h,\nend\n\nexample : a < b \u2192 b < c \u2192 a < c :=\nbegin\n  simp only [lt_iff_le_not_le], -- \u22a2 \u22a2 a \u2264 b \u2227 \u00acb \u2264 a \u2192 b \u2264 c \u2227 \u00acc \u2264 b \u2192 a \u2264 c \u2227 \u00acc \u2264 a\n  rintros \u27e8aleb, nblea\u27e9 \u27e8blec, ncleb\u27e9,\n  split,\n  from le_trans aleb blec,\n  contrapose! ncleb,\n  from le_trans ncleb aleb,\nend\n\nend", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/03_Logic/04_Conjuction_Bi-implication.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.746320951527666}}
{"text": "/-\nCopyright (c) 2022 Cuma K\u00f6kmen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Cuma K\u00f6kmen, Yury Kudryashov\n-/\nimport measure_theory.integral.circle_integral\n\n/-!\n# Integral over a torus in `\u2102\u207f`\n\nIn this file we define the integral of a function `f : \u2102\u207f \u2192 E` over a torus\n`{z : \u2102\u207f | \u2200 i, z i \u2208 metric.sphere (c i) (R i)}`. In order to do this, we define\n`torus_map (c : \u2102\u207f) (R \u03b8 : \u211d\u207f)` to be the point in `\u2102\u207f` given by $z_k=c_k+R_ke^{\u03b8_ki}$,\nwhere $i$ is the imaginary unit, then define `torus_integral f c R` as the integral over\nthe cube $[0, (\u03bb _, 2\u03c0)] = \\{\u03b8\\|\u2200 k, 0 \u2264 \u03b8_k \u2264 2\u03c0\\}$ of the Jacobian of the\n`torus_map` multiplied by `f (torus_map c R \u03b8)`.\n\nWe also define a predicate saying that `f \u2218 torus_map c R` is integrable on the cube\n`[0, (\u03bb _, 2\\pi)]`.\n\n## Main definitions\n\n* `torus_map c R`: the generalized multidimensional exponential map from `\u211d\u207f` to `\u2102\u207f` that sends\n  $\u03b8=(\u03b8_0,\u2026,\u03b8_{n-1})$ to $z=(z_0,\u2026,z_{n-1})$, where $z_k= c_k + R_ke^{\u03b8_k i}$;\n\n* `torus_integrable f c R`: a function `f : \u2102\u207f \u2192 E` is integrable over the generalized torus\n  with center `c : \u2102\u207f` and radius `R : \u211d\u207f` if `f \u2218 torus_map c R` is integrable on the\n  closed cube `Icc (0 : \u211d\u207f) (\u03bb _, 2 * \u03c0)`;\n\n* `torus_integral f c R`: the integral of a function `f : \u2102\u207f \u2192 E` over a torus with\n  center `c \u2208 \u2102\u207f` and radius `R \u2208 \u211d\u207f` defined as\n  $\\iiint_{[0, 2 * \u03c0]} (\u220f_{k = 1}^{n} i R_k e^{\u03b8_k * i}) \u2022 f (c + Re^{\u03b8_k i})\\,d\u03b8_0\u2026d\u03b8_{k-1}$.\n\n## Main statements\n\n* `torus_integral_dim0`, `torus_integral_dim1`, `torus_integral_succ`: formulas for `torus_integral`\n  in cases of dimension `0`, `1`, and `n + 1`.\n\n## Notations\n\n- `\u211d\u2070`, `\u211d\u00b9`, `\u211d\u207f`, `\u211d\u207f\u207a\u00b9`: local notation for `fin 0 \u2192 \u211d`, `fin 1 \u2192 \u211d`, `fin n \u2192 \u211d`, and\n  `fin (n + 1) \u2192 \u211d`, respectively;\n- `\u2102\u2070`, `\u2102\u00b9`, `\u2102\u207f`, `\u2102\u207f\u207a\u00b9`: local notation for `fin 0 \u2192 \u2102`, `fin 1 \u2192 \u2102`, `fin n \u2192 \u2102`, and\n  `fin (n + 1) \u2192 \u2102`, respectively;\n- `\u222f z in T(c, R), f z`: notation for `torus_integral f c R`;\n- `\u222e z in C(c, R), f z`: notation for `circle_integral f c R`, defined elsewhere;\n- `\u220f k, f k`: notation for `finset.prod`, defined elsewhere;\n- `\u03c0`: notation for `real.pi`, defined elsewhere.\n\n## Tags\n\nintegral, torus\n-/\n\nvariable {n : \u2115}\nvariables {E : Type*} [normed_add_comm_group E]\n\nnoncomputable theory\n\nopen complex set measure_theory function filter topological_space\nopen_locale real big_operators\n\nlocal notation `\u211d\u2070` := fin 0 \u2192 \u211d\nlocal notation `\u2102\u2070` := fin 0 \u2192 \u2102\nlocal notation `\u211d\u00b9` := fin 1 \u2192 \u211d\nlocal notation `\u2102\u00b9` := fin 1 \u2192 \u2102\nlocal notation `\u211d\u207f` := fin n \u2192 \u211d\nlocal notation `\u2102\u207f` := fin n \u2192 \u2102\nlocal notation `\u211d\u207f\u207a\u00b9` := fin (n + 1) \u2192 \u211d\nlocal notation `\u2102\u207f\u207a\u00b9` := fin (n + 1) \u2192 \u2102\n\n/-!\n### `torus_map`, a generalization of a torus\n-/\n\n/-- The n dimensional exponential map $\u03b8_i \u21a6 c + R e^{\u03b8_i*I}, \u03b8 \u2208 \u211d\u207f$ representing\na torus in `\u2102\u207f` with center `c \u2208 \u2102\u207f` and generalized radius `R \u2208 \u211d\u207f`, so we can adjust\nit to every n axis. -/\ndef torus_map (c : \u2102\u207f) (R : \u211d\u207f) : \u211d\u207f \u2192 \u2102\u207f :=\n\u03bb \u03b8 i, c i + R i * exp(\u03b8 i * I)\n\nlemma torus_map_sub_center (c : \u2102\u207f) (R : \u211d\u207f) (\u03b8 : \u211d\u207f) :\n  torus_map c R \u03b8 - c = torus_map 0 R \u03b8 :=\nby { ext1 i, simp [torus_map] }\n\nlemma torus_map_eq_center_iff {c : \u2102\u207f} {R : \u211d\u207f} {\u03b8 : \u211d\u207f} :\n  torus_map c R \u03b8 = c \u2194 R = 0 :=\nby simp [funext_iff, torus_map, exp_ne_zero]\n\n@[simp] lemma torus_map_zero_radius (c : \u2102\u207f) : torus_map c 0 = const \u211d\u207f c :=\nby { ext1, rw torus_map_eq_center_iff.2 rfl }\n\n/-!\n### Integrability of a function on a generalized torus\n-/\n\n/-- A function `f : \u2102\u207f \u2192 E` is integrable on the generalized torus if the function\n`f \u2218 torus_map c R \u03b8` is integrable on `Icc (0 : \u211d\u207f) (\u03bb _, 2 * \u03c0)`-/\ndef torus_integrable (f : \u2102\u207f \u2192 E) (c : \u2102\u207f) (R : \u211d\u207f) : Prop :=\n  integrable_on (\u03bb (\u03b8 : \u211d\u207f), f (torus_map c R \u03b8)) (Icc (0 : \u211d\u207f) (\u03bb _, 2 * \u03c0)) volume\n\nnamespace torus_integrable\n\nvariables {f g : \u2102\u207f \u2192 E} {c : \u2102\u207f} {R : \u211d\u207f}\n\n/-- Constant functions are torus integrable -/\nlemma torus_integrable_const (a : E) (c : \u2102\u207f) (R : \u211d\u207f) :\n  torus_integrable (\u03bb _, a) c R :=\nby simp [torus_integrable, measure_Icc_lt_top]\n\n/-- If `f` is torus integrable then `-f` is torus integrable. -/\nprotected lemma neg (hf : torus_integrable f c R) : torus_integrable (-f) c R := hf.neg\n\n/-- If `f` and `g` are two torus integrable functions, then so is `f + g`. -/\nprotected lemma add (hf : torus_integrable f c R) (hg : torus_integrable g c R) :\n  torus_integrable (f + g) c R :=\nhf.add hg\n\n/-- If `f` and `g` are two torus integrable functions, then so is `f - g`. -/\nprotected lemma sub (hf : torus_integrable f c R) (hg : torus_integrable g c R) :\n  torus_integrable (f - g) c R :=\nhf.sub hg\n\nlemma torus_integrable_zero_radius {f : \u2102\u207f \u2192 E} {c : \u2102\u207f} :\n  torus_integrable f c 0 :=\nbegin\n  rw [torus_integrable, torus_map_zero_radius],\n  apply torus_integrable_const (f c) c 0,\nend\n\n/--The function given in the definition of `torus_integral` is integrable. -/\nlemma function_integrable [normed_space \u2102 E] (hf : torus_integrable f c R) :\n  integrable_on (\u03bb (\u03b8 : \u211d\u207f), (\u220f i, R i * exp(\u03b8 i * I) * I : \u2102) \u2022 f (torus_map c R \u03b8))\n                (Icc (0 : \u211d\u207f) (\u03bb _, 2 * \u03c0)) volume :=\nbegin\n  refine (hf.norm.const_mul (\u220f i, |R i|)).mono' _ _,\n  { refine (continuous.ae_strongly_measurable _).smul hf.1,\n    exact continuous_finset_prod finset.univ (\u03bb i hi, (continuous_const.mul\n      (((continuous_of_real.comp (continuous_apply i)).mul continuous_const).cexp)).mul\n      continuous_const) },\n  simp [norm_smul, map_prod],\nend\n\nend torus_integrable\n\nvariables [normed_space \u2102 E] [complete_space E] {f g : \u2102\u207f \u2192 E} {c : \u2102\u207f} {R : \u211d\u207f}\n\n/--The definition of the integral over a generalized torus with center `c \u2208 \u2102\u207f` and radius `R \u2208 \u211d\u207f`\nas the `\u2022`-product of the derivative of `torus_map` and `f (torus_map c R \u03b8)`-/\ndef torus_integral (f : \u2102\u207f \u2192 E) (c : \u2102\u207f) (R : \u211d\u207f) :=\n\u222b (\u03b8 : \u211d\u207f) in Icc (0 : \u211d\u207f) (\u03bb _, 2 * \u03c0), (\u220f i, R i * exp(\u03b8 i * I) * I : \u2102) \u2022 f (torus_map c R \u03b8)\n\nnotation `\u222f` binders ` in ` `T(` c `, ` R `)` `, ` r:(scoped:60 f, torus_integral f c R) := r\n\nlemma torus_integral_radius_zero (hn : n \u2260 0) (f : \u2102\u207f \u2192 E) (c : \u2102\u207f): \u222f x in T(c, 0), f x = 0 :=\nby simp only [torus_integral, pi.zero_apply, of_real_zero, mul_zero, zero_mul, fin.prod_const,\n  zero_pow' n hn, zero_smul, integral_zero]\n\nlemma torus_integral_neg (f : \u2102\u207f \u2192 E) (c : \u2102\u207f) (R : \u211d\u207f) :\n  \u222f x in T(c, R), -f x = -\u222f x in T(c, R), f x :=\nby simp [torus_integral, integral_neg]\n\nlemma torus_integral_add (hf : torus_integrable f c R) (hg : torus_integrable g c R) :\n  \u222f x in T(c, R), f x + g x = (\u222f x in T(c, R), f x) + \u222f x in T(c, R), g x :=\nby simpa only [torus_integral, smul_add, pi.add_apply]\n  using integral_add hf.function_integrable hg.function_integrable\n\nlemma torus_integral_sub (hf : torus_integrable f c R) (hg : torus_integrable g c R) :\n  \u222f x in T(c, R), f x - g x = (\u222f x in T(c, R), f x) - \u222f x in T(c, R), g x :=\nby simpa only [sub_eq_add_neg, \u2190 torus_integral_neg] using torus_integral_add hf hg.neg\n\nlemma torus_integral_smul {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] [normed_space \ud835\udd5c E] [smul_comm_class \ud835\udd5c \u2102 E]\n  (a : \ud835\udd5c) (f : \u2102\u207f \u2192 E) (c : \u2102\u207f) (R : \u211d\u207f) :\n  \u222f x in T(c, R), a \u2022 f x = a \u2022 \u222f x in T(c, R), f x :=\nby simp only [torus_integral, integral_smul, \u2190 smul_comm a]\n\nlemma torus_integral_const_mul (a : \u2102) (f : \u2102\u207f \u2192 \u2102) (c : \u2102\u207f) (R : \u211d\u207f) :\n  \u222f x in T(c, R), a * f x = a * \u222f x in T(c, R), f x :=\ntorus_integral_smul a f c R\n\n/--If for all `\u03b8 : \u211d\u207f`, `\u2016f (torus_map c R \u03b8)\u2016` is less than or equal to a constant `C : \u211d`, then\n`\u2016\u222f x in T(c, R), f x\u2016` is less than or equal to `(2 * \u03c0)^n * (\u220f i, |R i|) * C`-/\nlemma norm_torus_integral_le_of_norm_le_const {C : \u211d} (hf : \u2200 \u03b8, \u2016f (torus_map c R \u03b8)\u2016 \u2264 C) :\n  \u2016\u222f x in T(c, R), f x\u2016 \u2264 (2 * \u03c0)^(n: \u2115) * (\u220f i, |R i|) * C :=\ncalc \u2016\u222f x in T(c, R), f x\u2016 \u2264 (\u220f i, |R i|) * C * (volume (Icc (0 : \u211d\u207f) (\u03bb _, 2 * \u03c0))).to_real :\n  norm_set_integral_le_of_norm_le_const' measure_Icc_lt_top measurable_set_Icc $ \u03bb \u03b8 h\u03b8,\n    ( calc \u2016(\u220f i : fin n, R i * exp (\u03b8 i * I) * I : \u2102) \u2022 f (torus_map c R \u03b8)\u2016\n          = (\u220f i : fin n, |R i|) * \u2016f (torus_map c R \u03b8)\u2016 : by simp [norm_smul]\n      ... \u2264 (\u220f i : fin n, |R i|) * C :\n        mul_le_mul_of_nonneg_left (hf _) (finset.prod_nonneg $ \u03bb _ _, abs_nonneg _) )\n... = (2 * \u03c0)^(n: \u2115) * (\u220f i, |R i|) * C :\n  by simp only [pi.zero_def, real.volume_Icc_pi_to_real (\u03bb _, real.two_pi_pos.le), sub_zero,\n      fin.prod_const, mul_assoc, mul_comm ((2 * \u03c0) ^ (n : \u2115))]\n\n@[simp] lemma torus_integral_dim0 (f : \u2102\u2070 \u2192 E) (c : \u2102\u2070) (R : \u211d\u2070) : \u222f x in T(c, R), f x = f c :=\nby simp only [torus_integral, fin.prod_univ_zero, one_smul,\n  subsingleton.elim (\u03bb i : fin 0, 2 * \u03c0) 0, Icc_self, measure.restrict_singleton, volume_pi,\n  integral_smul_measure, integral_dirac, measure.pi_of_empty _ 0,\n  measure.dirac_apply_of_mem (mem_singleton _), subsingleton.elim (torus_map c R 0) c]\n\n/-- In dimension one, `torus_integral` is the same as `circle_integral`\n(up to the natural equivalence between `\u2102` and `fin 1 \u2192 \u2102`). -/\nlemma torus_integral_dim1 (f : \u2102\u00b9 \u2192 E) (c : \u2102\u00b9) (R : \u211d\u00b9) :\n  \u222f x in T(c, R), f x = \u222e z in C(c 0, R 0), f (\u03bb _, z) :=\nbegin\n  have : (\u03bb (x : \u211d) (b : fin 1), x) \u207b\u00b9' Icc 0 (\u03bb _, 2 * \u03c0) = Icc 0 (2 * \u03c0),\n    from (order_iso.fun_unique (fin 1) \u211d).symm.preimage_Icc _ _,\n  simp only [torus_integral, circle_integral, interval_integral.integral_of_le real.two_pi_pos.le,\n    measure.restrict_congr_set Ioc_ae_eq_Icc, deriv_circle_map, fin.prod_univ_one,\n    \u2190 ((volume_preserving_fun_unique (fin 1) \u211d).symm _).set_integral_preimage_emb\n      (measurable_equiv.measurable_embedding _), this, measurable_equiv.fun_unique_symm_apply],\n  simp only [torus_map, circle_map, zero_add],\n  rcongr\nend\n\n/-- Recurrent formula for `torus_integral`, see also `torus_integral_succ`. -/\nlemma torus_integral_succ_above {f : \u2102\u207f\u207a\u00b9 \u2192 E} {c : \u2102\u207f\u207a\u00b9} {R : \u211d\u207f\u207a\u00b9} (hf : torus_integrable f c R)\n  (i : fin (n + 1)) :\n  \u222f x in T(c, R), f x =\n    \u222e x in C(c i, R i), \u222f y in T(c \u2218 i.succ_above, R \u2218 i.succ_above), f (i.insert_nth x y) :=\nbegin\n  set e : \u211d \u00d7 \u211d\u207f \u2243\u1d50 \u211d\u207f\u207a\u00b9 := (measurable_equiv.pi_fin_succ_above_equiv (\u03bb _, \u211d) i).symm,\n  have hem : measure_preserving e,\n    from (volume_preserving_pi_fin_succ_above_equiv (\u03bb j : fin (n + 1), \u211d) i).symm _,\n  have he\u03c0 : e \u207b\u00b9' (Icc 0 (\u03bb _, 2 * \u03c0)) = Icc 0 (2 * \u03c0) \u00d7\u02e2 Icc (0 : \u211d\u207f) (\u03bb _, 2 * \u03c0),\n    from ((order_iso.pi_fin_succ_above_iso (\u03bb _, \u211d) i).symm.preimage_Icc _ _).trans\n      (Icc_prod_eq _ _),\n  rw [torus_integral, \u2190 hem.map_eq, set_integral_map_equiv, he\u03c0, measure.volume_eq_prod,\n    set_integral_prod, circle_integral_def_Icc],\n  { refine set_integral_congr measurable_set_Icc (\u03bb \u03b8 h\u03b8, _),\n    simp only [torus_integral, \u2190 integral_smul, deriv_circle_map, i.prod_univ_succ_above _,\n      smul_smul, torus_map, circle_map_zero],\n    refine set_integral_congr measurable_set_Icc (\u03bb \u0398 h\u0398, _),\n    simp only [measurable_equiv.pi_fin_succ_above_equiv_symm_apply, i.insert_nth_apply_same,\n      i.insert_nth_apply_succ_above, (\u2218)],\n    congr' 2,\n    simp only [funext_iff, i.forall_iff_succ_above, circle_map, fin.insert_nth_apply_same,\n      eq_self_iff_true, fin.insert_nth_apply_succ_above, implies_true_iff, and_self] },\n  { have := hf.function_integrable,\n    rwa [\u2190 hem.integrable_on_comp_preimage e.measurable_embedding, he\u03c0] at this }\nend\n\n/-- Recurrent formula for `torus_integral`, see also `torus_integral_succ_above`. -/\nlemma torus_integral_succ {f : \u2102\u207f\u207a\u00b9 \u2192 E} {c : \u2102\u207f\u207a\u00b9} {R : \u211d\u207f\u207a\u00b9} (hf : torus_integrable f c R) :\n  \u222f x in T(c, R), f x =\n    \u222e x in C(c 0, R 0), \u222f y in T(c \u2218 fin.succ, R \u2218 fin.succ), f (fin.cons x y) :=\nby simpa using torus_integral_succ_above hf 0\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/integral/torus_integral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.746320939848388}}
{"text": "variables (\u03b1 : Type*) (p q : \u03b1 \u2192 Prop)\n\ntheorem thml : (\u2200 x, p x \u2227 q x) \u2192 (\u2200 x, p x) :=\nassume h, \nassume y,\nshow p y, from and.elim_left(h y)\n\ntheorem thmr : (\u2200 x, p x \u2227 q x) \u2192  (\u2200 x, q x) :=\nassume h, \nassume y,\nshow q y, from and.elim_right(h y)\n\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\niff.intro \n  (assume h : (\u2200 x, p x \u2227 q x),\n  and.intro (assume t : \u03b1, and.left (h t)) (assume t : \u03b1, and.right (h t)))\n  (assume h, assume t, and.intro ((and.left h) t) ((and.right h) t))\n  \n  \nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := \nassume h : (\u2200 x, p x \u2192 q x),\nassume g : (\u2200 x, p x),\nassume y : \u03b1,\n(h y) (g y) \n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := \nassume h,\nor.elim h \n  (assume g, assume t, or.inl (g t)) (assume g, assume t, or.inr (g t))", "meta": {"author": "faustoUrtiz", "repo": "learning-leanprover", "sha": "3acddd0ffb952ce32b0135b8f49de5e930c9820a", "save_path": "github-repos/lean/faustoUrtiz-learning-leanprover", "path": "github-repos/lean/faustoUrtiz-learning-leanprover/learning-leanprover-3acddd0ffb952ce32b0135b8f49de5e930c9820a/quatifiers-equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7462806182995467}}
{"text": "import order.boolean_algebra\n\nopen lattice\n\n/-\nEXERCISE:\n\nIn mathematics, a Boolean ring R is a ring for which x\u00b2 = x for all x in R.\n\nDefine a class of boolean rings. It should extend the typeclass of rings.\n\n-/\n\nclass boolean_ring (\u03b1 : Type*) := sorry\n\nopen boolean_ring\n\n\nuniverse u\n\nvariables {\u03b1 : Type u} [boolean_ring \u03b1]\n\n\n/-\nSince the join operation \u2228 in a Boolean algebra is often written additively, it makes sense in this context to denote ring addition by \u2295, a symbol that is often used to denote exclusive or.\n\nGiven a Boolean ring R, for x and y in R we can define\n\n    x \u2227 y = xy,\n\n    x \u2228 y = x \u2295 y \u2295 xy,\n\n    \u00acx = 1 \u2295 x.\n\nThese operations then satisfy all of the axioms for meets, joins, and complements in a Boolean algebra. Thus every Boolean ring becomes a Boolean algebra.\n-/\nlocal notation x ` \u2295 ` y := (x : \u03b1) + (y : \u03b1)\n\n/- Every Boolean ring R satisfies x \u2295 x = 0 for all x in R, because we know\n\n    x \u2295 x = (x \u2295 x)\u00b2 = x\u00b2 \u2295 x\u00b2 \u2295 x\u00b2 \u2295 x\u00b2 = x \u2295 x \u2295 x \u2295 x\n\nand since (R,\u2295) is an abelian group, we can subtract x \u2295 x from both sides of this equation, which gives x \u2295 x = 0. A similar proof shows that every Boolean ring is commutative:\n\n    x \u2295 y = (x \u2295 y)\u00b2 = x\u00b2 \u2295 xy \u2295 yx \u2295 y\u00b2 = x \u2295 xy \u2295 yx \u2295 y\n\n and this yields xy \u2295 yx = 0, which means xy = yx (using the first property above). -/\n\n/- EXERCISE: Prove a lemma which says that \u2200 x : \u03b1, x \u2295 x = 0 and a lemma that multiplication commutes.-/\n\n\n/- EXERCISE: Given the boolean_ring instance on \u03b1, construct the boolean_algebra instance on \u03b1. -/\n\n/- the inf operation should be x * y, the sup operation should be x \u2295 y \u2295 x * y, and the complement operation should be 1 \u2295 x. -/\n\ninstance boolean_algebra_of_boolean_ring {\u03b1 : Type*} [boolean_ring \u03b1] : boolean_algebra \u03b1 :=\n{!_!} -- use the hole command for creating a structure stub\n", "meta": {"author": "jesse-michael-han", "repo": "hanoi-lean-2019", "sha": "a5a9f368e394d563bfcc13e3773863924505b1ce", "save_path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019", "path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019/hanoi-lean-2019-a5a9f368e394d563bfcc13e3773863924505b1ce/src/floris/exercises-day-two-boolean-ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7462806035466311}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport ring_theory.principal_ideal_domain -- theory of PIDs\n\n/-\n\n# Principal Ideal Domains\n\nFirst let's showcase what mathlib has.\n\nLet `R` be a commutative ring.\n-/\n\nvariables (R : Type) [comm_ring R]\n\n-- We say `R` is a *principal ideal ring* if all ideals are principal.\n-- We say `R` is a *domain* if it's an integral domain. \n-- We say `R` is a *principal ideal domain* if it's both.\n-- So here's how to say \"Assume `R` is a PID\":\n\nvariables [is_principal_ideal_ring R] [is_domain R]\n\n-- Note that both of these are typeclasses, so various things should\n-- be automatic.\n\nexample : \u2200 a b : R, a * b = 0 \u2192 a = 0 \u2228 b = 0 :=\nbegin\n  intros a b,\n  apply eq_zero_or_eq_zero_of_mul_eq_zero, -- typeclass inference \n  -- magically extracts the assumption from `is_domain`\nend\n\nexample : (0 : R) \u2260 1 :=\nbegin\n  -- this is another consequence of being an integral domain\n  apply zero_ne_one,\nend\n\nexample (I : ideal R) : I.is_principal :=\nbegin\n  -- typeclass inference system finds `is_principal_ideal_ring` and\n  -- uses it automatically\n  exact is_principal_ideal_ring.principal I,\nend\n\nexample (I : ideal R) : \u2203 j, I = ideal.span {j} :=\nbegin\n  -- to make a term of type `is_principal I` you need to give one proof,\n  -- but we still need to do `cases` or equivalent (I used `obtain` below)\n  -- to get this proof out.\n  obtain \u27e8h\u27e9 := is_principal_ideal_ring.principal I,\n  exact h,\nend\n\n-- product of two PIDs isn't a PID, but only becuase it's not a domain\nexample (A B : Type) [comm_ring A] [comm_ring B]\n  [is_principal_ideal_ring A] [is_principal_ideal_ring B] : \n  is_principal_ideal_ring (A \u00d7 B) :=\n{ principal := begin\n    intro I,\n    obtain \u27e8a, (hA : _ = ideal.span _)\u27e9 := is_principal_ideal_ring.principal (I.map (ring_hom.fst A B)),\n    obtain \u27e8b, (hB : _ = ideal.span _)\u27e9 := is_principal_ideal_ring.principal (I.map (ring_hom.snd A B)),\n    use (a,b),\n    ext,\n    simp only [ideal.submodule_span_eq],\n    rw ideal.mem_span_singleton,\n    split,\n    { intro h,\n      have h1 : ring_hom.fst A B x \u2208 I.map (ring_hom.fst A B),\n      { apply ideal.mem_map_of_mem _ h, },\n      rw [hA, ideal.mem_span_singleton] at h1,\n      rcases h1 with \u27e8r, hr\u27e9,\n      have h2 : ring_hom.snd A B x \u2208 I.map (ring_hom.snd A B),\n      { apply ideal.mem_map_of_mem _ h, },\n      rw [hB, ideal.mem_span_singleton] at h2,\n      rcases h2 with \u27e8s, hs\u27e9,\n      use (r,s),\n      change x = (a*r,b*s),\n      rw [\u2190 hr, \u2190 hs],\n      simp only [ring_hom.coe_fst, ring_hom.coe_snd, prod.mk.eta],  \n    },\n    { rintro \u27e8\u27e8r, s\u27e9, rfl\u27e9,\n      have ha : a \u2208 I.map (ring_hom.fst A B),\n      { rw [hA, ideal.mem_span_singleton], },\n      have hb : b \u2208 I.map (ring_hom.snd A B),\n      { rw [hB, ideal.mem_span_singleton], },\n      rw ideal.mem_map_iff_of_surjective at ha hb,\n      { rcases ha with \u27e8\u27e8a, b'\u27e9, haI, rfl\u27e9,\n        rcases hb with \u27e8\u27e8a', b\u27e9, hbI, rfl\u27e9,\n        suffices : (a,b) \u2208 I,\n        { exact ideal.mul_mem_right _ _ this, },\n        convert I.add_mem (I.mul_mem_left (1,0) haI)\n          (I.mul_mem_left (0,1) hbI);\n        simp, },\n      { intro a, use (a,0), refl, },\n      { intro b, use (0,b), refl, },\n    }\n  end }", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section14UFDs_and_PIDs_etc/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7462806003690645}}
{"text": "import algebra.comm_rings.instances.basic\nimport misc.rationals.pos_nat\n\nnamespace rational\n\ndef same_ratio : \u2124 \u00d7 \u2115\u207a \u2192 \u2124 \u00d7 \u2115\u207a \u2192 Prop \n| (z\u2081,n\u2081) (z\u2082,n\u2082) := z\u2081 * n\u2082 = z\u2082 * n\u2081 \n\ntheorem same_ratio_refl : \u2200 p : \u2124 \u00d7 \u2115\u207a, same_ratio p p :=\nbegin\n  intro p,\n  cases p with z n,\n  simp[same_ratio],\nend\n\ntheorem same_ratio_symm : \u2200 p\u2081 p\u2082 : \u2124 \u00d7 \u2115\u207a, same_ratio p\u2081 p\u2082 \u2192 same_ratio p\u2082 p\u2081 :=\nbegin\n  intros p\u2081 p\u2082,\n  cases p\u2081 with z\u2081 n\u2081,\n  cases p\u2082 with z\u2082 n\u2082,\n  simp[same_ratio],\n  apply symm,\nend\n\ntheorem same_ratio_trans : \u2200 p\u2081 p\u2082 p\u2083 : \u2124 \u00d7 \u2115\u207a, same_ratio p\u2081 p\u2082 \u2192 same_ratio p\u2082 p\u2083\n  \u2192 same_ratio p\u2081 p\u2083 :=\nbegin\n  intros p\u2081 p\u2082 p\u2083,\n  cases p\u2081 with z\u2081 n\u2081,\n  cases p\u2082 with z\u2082 n\u2082,\n  cases p\u2083 with z\u2083 n\u2083,\n  simp[same_ratio],\n  intros h\u2081 h\u2082,\n  apply pos_nat_mul_right_cancel n\u2082,\n  rw [int.mul_assoc,int.mul_comm \u2191n\u2083,\u2190 int.mul_assoc,h\u2081],\n  rw [int.mul_assoc,int.mul_comm \u2191n\u2081,\u2190 int.mul_assoc,h\u2082],\n  rw [int.mul_assoc,int.mul_assoc,int.mul_comm \u2191n\u2082],\nend\n\ninstance rational_setoid : setoid (\u2124 \u00d7 \u2115\u207a) \n  := \u27e8same_ratio,same_ratio_refl,same_ratio_symm,same_ratio_trans\u27e9\n\n@[simp]\ntheorem same_ratio_equiv : \u2200 (z\u2081 z\u2082 : \u2124) (n\u2081 n\u2082 : \u2115\u207a), (z\u2081,n\u2081) \u2248 (z\u2082,n\u2082) \u2194 z\u2081 * n\u2082 = z\u2082 * n\u2081\n  := \u03bb _ _ _ _, by refl\n\ndef rational : Type := quotient rational.rational_setoid\n\nnotation `\u211a` := rational\n\ninstance rational_zero : has_zero \u211a := \u27e8\u27e6(0,1)\u27e7\u27e9 \ninstance rational_one : has_one \u211a := \u27e8\u27e6(1,1)\u27e7\u27e9\n\ntheorem rational_zero_concrete_char : (0 : \u211a) = \u27e6(0,1)\u27e7 := rfl\ntheorem rational_one_concrete_char : (1 : \u211a) = \u27e6(1,1)\u27e7 := rfl\n\ndef pre_add_rationals : \u2124 \u00d7 \u2115\u207a \u2192 \u2124 \u00d7 \u2115\u207a \u2192 \u211a \n| (z\u2081,n\u2081) (z\u2082,n\u2082) := \u27e6(z\u2081*n\u2082 + z\u2082*n\u2081, n\u2081 * n\u2082)\u27e7\n\ndef add_rationals : \u211a \u2192 \u211a \u2192 \u211a :=\nbegin\n  apply quotient.lift\u2082 pre_add_rationals,\n  intros ap\u2081 ap\u2082 bp\u2081 bp\u2082 r\u2081 r\u2082,\n  cases ap\u2081 with az\u2081 an\u2081,\n  cases ap\u2082 with az\u2082 an\u2082,\n  cases bp\u2081 with bz\u2081 bn\u2081,\n  cases bp\u2082 with bz\u2082 bn\u2082,\n  simp[pre_add_rationals],\n  apply quotient.sound,\n  have hrw\u2081 : az\u2081 * bn\u2081 = bz\u2081 * an\u2081,\n    exact r\u2081,\n  have hrw\u2082 : az\u2082 * bn\u2082 = bz\u2082 * an\u2082,\n    exact r\u2082,\n  have hrw\u2083 : (az\u2081 * \u2191an\u2082 + az\u2082 * \u2191an\u2081) * \u2191(bn\u2081 * bn\u2082) \n      = (bz\u2081 * \u2191bn\u2082 + bz\u2082 * \u2191bn\u2081) * \u2191(an\u2081 * an\u2082),\n    simp[coe_prevs_mul, int.distrib_right],\n    have sub\u2081 : az\u2081 * \u2191an\u2082 * (\u2191bn\u2081 * \u2191bn\u2082) = bz\u2081 * \u2191bn\u2082 * (\u2191an\u2081 * \u2191an\u2082),\n      rw [comm_ring.mul_assoc\u2084, int.mul_comm \u2191an\u2082,\u2190comm_ring.mul_assoc\u2084,hrw\u2081,comm_ring.mul_assoc\u2084],\n      rw [int.mul_assoc,int.mul_comm (\u2191an\u2081 * \u2191an\u2082)],\n      simp [int.mul_assoc],\n    have sub\u2082 : az\u2082 * \u2191an\u2081 * (\u2191bn\u2081 * \u2191bn\u2082) = bz\u2082 * \u2191bn\u2081 * (\u2191an\u2081 * \u2191an\u2082),\n      rw [int.mul_comm \u2191bn\u2081,comm_ring.mul_assoc\u2084,int.mul_comm \u2191an\u2081,\u2190comm_ring.mul_assoc\u2084,hrw\u2082],\n      rw [comm_ring.mul_assoc\u2084,int.mul_comm \u2191an\u2081,int.mul_assoc,int.mul_comm (\u2191an\u2082 * \u2191an\u2081)],\n      simp [int.mul_assoc],\n    rw [sub\u2081, sub\u2082],\n  exact hrw\u2083,\nend\n\ninstance rational_has_add : has_add \u211a := \u27e8add_rationals\u27e9 \n\ntheorem rational_add_concrete_char : \u2200 (z\u2081 z\u2082 : \u2124) (n\u2081 n\u2082 : \u2115\u207a), (\u27e6(z\u2081,n\u2081)\u27e7 + \u27e6(z\u2082,n\u2082)\u27e7 : \u211a) =\n  \u27e6(z\u2081 * n\u2082 + z\u2082 * n\u2081, n\u2081 * n\u2082)\u27e7 := \u03bb _ _ _ _, rfl\n\ndef pre_mul_rationals : \u2124 \u00d7 \u2115\u207a \u2192 \u2124 \u00d7 \u2115\u207a \u2192 \u211a \n| (z\u2081,n\u2081) (z\u2082,n\u2082) := \u27e6(z\u2081 * z\u2082, n\u2081 * n\u2082)\u27e7\n\ndef mul_rationals : \u211a \u2192 \u211a \u2192 \u211a :=\nbegin\n  apply quotient.lift\u2082 pre_mul_rationals,\n  intros ap\u2081 ap\u2082 bp\u2081 bp\u2082 r\u2081 r\u2082,\n  cases ap\u2081 with az\u2081 an\u2081,\n  cases ap\u2082 with az\u2082 an\u2082,\n  cases bp\u2081 with bz\u2081 bn\u2081,\n  cases bp\u2082 with bz\u2082 bn\u2082,\n  simp[pre_mul_rationals],\n  apply quotient.sound,\n  have hrw\u2081 : az\u2081 * bn\u2081 = bz\u2081 * an\u2081,\n    exact r\u2081,\n  have hrw\u2082 : az\u2082 * bn\u2082 = bz\u2082 * an\u2082,\n    exact r\u2082,\n  have hrw\u2083 : (az\u2081 * az\u2082) * \u2191(bn\u2081 * bn\u2082) = (bz\u2081 * bz\u2082) * \u2191(an\u2081 * an\u2082),\n    simp[coe_prevs_mul],\n    rw [comm_ring.mul_assoc\u2084,int.mul_comm az\u2082,\u2190 comm_ring.mul_assoc\u2084],\n    rw [hrw\u2081,hrw\u2082],\n    rw [comm_ring.mul_assoc\u2084, int.mul_comm \u2191an\u2081,\u2190 comm_ring.mul_assoc\u2084],\n  exact hrw\u2083,\nend\n\ninstance rational_has_mul : has_mul \u211a := \u27e8mul_rationals\u27e9 \n\ntheorem rational_mul_concrete_char : \u2200 (z\u2081 z\u2082 : \u2124) (n\u2081 n\u2082 : \u2115\u207a), (\u27e6(z\u2081,n\u2081)\u27e7 * \u27e6(z\u2082,n\u2082)\u27e7 : \u211a) =\n  \u27e6(z\u2081 * z\u2082, n\u2081 * n\u2082)\u27e7 := \u03bb _ _ _ _, rfl\n\ndef pre_rational_minus : \u2124 \u00d7 \u2115\u207a \u2192 \u211a \n| (z,n) := \u27e6(-z,n)\u27e7\n\ndef rational_minus : \u211a \u2192 \u211a :=\nbegin\n  apply quotient.lift pre_rational_minus,\n  intros p\u2081 p\u2082 r,\n  cases p\u2081 with z\u2081 n\u2081,\n  cases p\u2082 with z\u2082 n\u2082,\n  have hrw\u2081 : z\u2081 * n\u2082 = z\u2082 * n\u2081,\n    exact r,\n  apply quotient.sound,\n  have hrw\u2083 : (-z\u2081) * n\u2082 = (-z\u2082) * n\u2081,\n    simp[\u2190 comm_ring.minus_mul,hrw\u2081],\n  exact hrw\u2083,\nend\n\ninstance rational_has_neg : has_neg \u211a := \u27e8rational_minus\u27e9\n\ntheorem rational_minus_concrete_char : \u2200 (z : \u2124) (n : \u2115\u207a), (-\u27e6(z,n)\u27e7 : \u211a) = \u27e6(-z,n)\u27e7 \n  := \u03bb _ _,rfl\n\ninstance rational_has_sub : has_sub \u211a := \u27e8\u03bb x y, x + -y\u27e9  \n\n@[simp]\ntheorem break_down_sub : \u2200 x y : \u211a, x - y = x + -y := \u03bb _ _, rfl\n\nend rational", "meta": {"author": "CameronTorrance", "repo": "Schemes", "sha": "f407ce80b8407101231170680b03b55984c42496", "save_path": "github-repos/lean/CameronTorrance-Schemes", "path": "github-repos/lean/CameronTorrance-Schemes/Schemes-f407ce80b8407101231170680b03b55984c42496/src/misc/rationals/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7462601051762704}}
{"text": "namespace Naturals\n\ninductive Nat where\n  | zero : Nat\n  | succ : Nat \u2192 Nat\n\nopen Nat\n\ndef convert : _root_.Nat \u2192 Nat\n  | _root_.Nat.zero    =>  zero\n  | _root_.Nat.succ n  =>  succ (convert n)\n\ninstance (n : _root_.Nat) : OfNat Nat n where\n  ofNat := convert n\n\ndef add : Nat \u2192 Nat \u2192 Nat\n  | m , zero   => m\n  | m , succ n => succ (add m n)\n\n-- from lean4/src/Init/Prelude.lean\n-- class Add (\u03b1 : Type) where\n--   add : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n-- class Mul (\u03b1 : Type) where\n--   mul : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n\n-- from lean4/src/Init/Notation.lean (simplified)\n-- infixl:65 \" + \"   => Add.add\n-- infixl:70 \" * \"   => Mul.mul\n\ninstance : Add Nat where\n  add := add\n\nexample : 3 + 2 = (5 : Nat) :=\n  calc\n    3 + 2\n      =  succ (3 + 1)         := rfl\n    _ =  succ (succ (3 + 0))  := rfl\n    _ =  succ (succ 3)        := rfl\n    _ =  (5 : Nat)            := rfl\n\n-- a shorter proof\nexample : 3 + 2 = 5 := rfl\n\ndef mul : Nat \u2192 Nat \u2192 Nat\n  | _ , zero   => zero\n  | m , succ n => (mul m n) + m\n\ninstance : Mul Nat where\n  mul := mul\n\nexample : 3 * 2 = (6 : Nat) :=\n  calc\n    3 * 2\n      =  (3 * 1 + 3 : Nat)     := rfl\n    _ =  (3 * 0 + 3 + 3 : Nat) := rfl\n    _ =  (0 + 3 + 3 : Nat)     := rfl\n    _ =  (6 : Nat)             := rfl\n\ndef monus : Nat \u2192 Nat \u2192 Nat\n  | m      , zero    =>  m\n  | zero   , succ _  =>  zero\n  | succ m , succ n  =>  monus m n\n\ninstance : Sub Nat where\n  sub := monus\n\nexample : 3 - 2 = (1 : Nat) :=\n  calc\n    3 - 2\n      =  (2 - 1 : Nat)  := rfl\n    _ =  (1 - 0 : Nat)  := rfl\n    _ =  (1 : Nat)      := rfl\n\nexample : 2 - 3 = (0 : Nat) :=\n  calc\n    2 - 3\n      =  (1 - 2 : Nat)  := rfl\n    _ =  (0 - 1 : Nat)  := rfl\n    _ =  (0 : Nat)      := rfl\n\ndef monus1 : Nat \u2192 Nat\n| zero => zero\n| succ n => n\n\ntheorem invert (m n : Nat) : succ m = succ n \u2192 m = n\n  := by\n    intro succ_m_eq_succ_n\n    calc\n      m = monus1 (succ m)  := by rfl\n      _ = monus1 (succ n)  := by rw [succ_m_eq_succ_n]\n      _ = n                := by rfl\n\ndef is_zero : Nat \u2192 Prop\n| zero => True\n| succ _ => False\n\ntheorem invert' (m n : Nat) (h : succ m = succ n) : m = n\n  := by injection h with h' ; exact h'\n\ntheorem succ_neq_zero (n : Nat) (h : succ n = zero) : False\n  := by injection h\n\ntheorem succ_neq_zero' (n : Nat) (h : succ n = zero) : False\n  := by contradiction\n\n\n\n\n\n\n\n\n", "meta": {"author": "plfa", "repo": "plfl", "sha": "b334801bbbfe3b894d139a64ce634417c9501ffb", "save_path": "github-repos/lean/plfa-plfl", "path": "github-repos/lean/plfa-plfl/plfl-b334801bbbfe3b894d139a64ce634417c9501ffb/src/Naturals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7462600926583451}}
{"text": "import data.real.basic\n\n-- BEGIN\ntheorem not_monotone_iff {f : \u211d \u2192 \u211d}:\n  \u00ac monotone f \u2194 \u2203 x y, x \u2264 y \u2227 f x > f y :=\nby { rw monotone, push_neg }\n\nexample : \u00ac monotone (\u03bb x : \u211d, -x) :=\nbegin\n  rw monotone, \n  push_neg,\n  use -2,\n  use -1,\n  norm_num,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/1_rw/ex20_rw_def_not_monof.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.746260091019319}}
{"text": "/-\nCopyright (c) 2018 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison, Bhavik Mehta\n\n! This file was ported from Lean 3 source module category_theory.functor.const\n! leanprover-community/mathlib commit dc6c365e751e34d100e80fe6e314c3c3e0fd2988\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.Opposites\n\n/-!\n# The constant functor\n\n`const J : C \u2964 (J \u2964 C)` is the functor that sends an object `X : C` to the functor `J \u2964 C` sending\nevery object in `J` to `X`, and every morphism to `\ud835\udfd9 X`.\n\nWhen `J` is nonempty, `const` is faithful.\n\nWe have `(const J).obj X \u22d9 F \u2245 (const J).obj (F.obj X)` for any `F : C \u2964 D`.\n-/\n\n\n-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation\nuniverse v\u2081 v\u2082 v\u2083 u\u2081 u\u2082 u\u2083\n\nopen CategoryTheory\n\nnamespace CategoryTheory.Functor\n\nvariable (J : Type u\u2081) [Category.{v\u2081} J]\n\nvariable {C : Type u\u2082} [Category.{v\u2082} C]\n\n/-- The functor sending `X : C` to the constant functor `J \u2964 C` sending everything to `X`.\n-/\n@[simps]\ndef const : C \u2964 J \u2964 C\n    where\n  obj X :=\n    { obj := fun _ => X\n      map := fun _ => \ud835\udfd9 X }\n  map f := { app := fun _ => f }\n#align category_theory.functor.const CategoryTheory.Functor.const\n\nnamespace const\n\nopen Opposite\n\nvariable {J}\n\n/-- The contant functor `J\u1d52\u1d56 \u2964 C\u1d52\u1d56` sending everything to `op X`\nis (naturally isomorphic to) the opposite of the constant functor `J \u2964 C` sending everything to `X`.\n-/\n@[simps]\ndef opObjOp (X : C) : (const J\u1d52\u1d56).obj (op X) \u2245 ((const J).obj X).op\n    where\n  hom := { app := fun j => \ud835\udfd9 _ }\n  inv := { app := fun j => \ud835\udfd9 _ }\n#align category_theory.functor.const.op_obj_op CategoryTheory.Functor.const.opObjOp\n\n/-- The contant functor `J\u1d52\u1d56 \u2964 C` sending everything to `unop X`\nis (naturally isomorphic to) the opposite of\nthe constant functor `J \u2964 C\u1d52\u1d56` sending everything to `X`.\n-/\ndef opObjUnop (X : C\u1d52\u1d56) : (const J\u1d52\u1d56).obj (unop X) \u2245 ((const J).obj X).leftOp\n    where\n  hom := { app := fun j => \ud835\udfd9 _ }\n  inv := { app := fun j => \ud835\udfd9 _ }\n#align category_theory.functor.const.op_obj_unop CategoryTheory.Functor.const.opObjUnop\n\n-- Lean needs some help with universes here.\n@[simp]\ntheorem opObjUnop_hom_app (X : C\u1d52\u1d56) (j : J\u1d52\u1d56) : (opObjUnop.{v\u2081, v\u2082} X).hom.app j = \ud835\udfd9 _ :=\n  rfl\n#align category_theory.functor.const.op_obj_unop_hom_app CategoryTheory.Functor.const.opObjUnop_hom_app\n\n@[simp]\ntheorem opObjUnop_inv_app (X : C\u1d52\u1d56) (j : J\u1d52\u1d56) : (opObjUnop.{v\u2081, v\u2082} X).inv.app j = \ud835\udfd9 _ :=\n  rfl\n#align category_theory.functor.const.op_obj_unop_inv_app CategoryTheory.Functor.const.opObjUnop_inv_app\n\n@[simp]\ntheorem unop_functor_op_obj_map (X : C\u1d52\u1d56) {j\u2081 j\u2082 : J} (f : j\u2081 \u27f6 j\u2082) :\n    (unop ((Functor.op (const J)).obj X)).map f = \ud835\udfd9 (unop X) :=\n  rfl\n#align category_theory.functor.const.unop_functor_op_obj_map CategoryTheory.Functor.const.unop_functor_op_obj_map\n\nend const\n\nsection\n\nvariable {D : Type u\u2083} [Category.{v\u2083} D]\n\n/-- These are actually equal, of course, but not definitionally equal\n  (the equality requires F.map (\ud835\udfd9 _) = \ud835\udfd9 _). A natural isomorphism is\n  more convenient than an equality between functors (compare id_to_iso). -/\n@[simps]\ndef constComp (X : C) (F : C \u2964 D) : (const J).obj X \u22d9 F \u2245 (const J).obj (F.obj X)\n    where\n  hom := { app := fun _ => \ud835\udfd9 _ }\n  inv := { app := fun _ => \ud835\udfd9 _ }\n#align category_theory.functor.const_comp CategoryTheory.Functor.constComp\n\n/-- If `J` is nonempty, then the constant functor over `J` is faithful. -/\ninstance [Nonempty J] : Faithful (const J : C \u2964 J \u2964 C)\n    where map_injective e := NatTrans.congr_app e (Classical.arbitrary J)\n\nend\n\nend CategoryTheory.Functor\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Functor/Const.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7461291765238143}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Yury Kudryashov\n-/\nimport order.filter.pi\nimport topology.bases\nimport data.finset.order\nimport data.set.accumulate\nimport tactic.tfae\nimport topology.bornology.basic\n\n/-!\n# Properties of subsets of topological spaces\n\nIn this file we define various properties of subsets of a topological space, and some classes on\ntopological spaces.\n\n## Main definitions\n\nWe define the following properties for sets in a topological space:\n\n* `is_compact`: each open cover has a finite subcover. This is defined in mathlib using filters.\n  The main property of a compact set is `is_compact.elim_finite_subcover`.\n* `is_clopen`: a set that is both open and closed.\n* `is_irreducible`: a nonempty set that has contains no non-trivial pair of disjoint opens.\n  See also the section below in the module doc.\n\nFor each of these definitions (except for `is_clopen`), we also have a class stating that the whole\nspace satisfies that property:\n`compact_space`, `irreducible_space`\n\nFurthermore, we have three more classes:\n* `locally_compact_space`: for every point `x`, every open neighborhood of `x` contains a compact\n  neighborhood of `x`. The definition is formulated in terms of the neighborhood filter.\n* `sigma_compact_space`: a space that is the union of a countably many compact subspaces;\n* `noncompact_space`: a space that is not a compact space.\n\n## On the definition of irreducible and connected sets/spaces\n\nIn informal mathematics, irreducible spaces are assumed to be nonempty.\nWe formalise the predicate without that assumption as `is_preirreducible`.\nIn other words, the only difference is whether the empty space counts as irreducible.\nThere are good reasons to consider the empty space to be \u201ctoo simple to be simple\u201d\nSee also https://ncatlab.org/nlab/show/too+simple+to+be+simple,\nand in particular\nhttps://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.\n-/\n\nopen set filter classical topological_space\nopen_locale classical topological_space filter\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v}  {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*}\nvariables [topological_space \u03b1] [topological_space \u03b2] {s t : set \u03b1}\n\n/- compact sets -/\nsection compact\n\n/-- A set `s` is compact if for every nontrivial filter `f` that contains `s`,\n    there exists `a \u2208 s` such that every set of `f` meets every neighborhood of `a`. -/\ndef is_compact (s : set \u03b1) := \u2200 \u2983f\u2984 [ne_bot f], f \u2264 \ud835\udcdf s \u2192 \u2203 a \u2208 s, cluster_pt a f\n\n/-- The complement to a compact set belongs to a filter `f` if it belongs to each filter\n`\ud835\udcdd a \u2293 f`, `a \u2208 s`. -/\nlemma is_compact.compl_mem_sets (hs : is_compact s) {f : filter \u03b1} (hf : \u2200 a \u2208 s, s\u1d9c \u2208 \ud835\udcdd a \u2293 f) :\n  s\u1d9c \u2208 f :=\nbegin\n  contrapose! hf,\n  simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc, \u2190 exists_prop] at hf \u22a2,\n  exact @hs _ hf inf_le_right\nend\n\n/-- The complement to a compact set belongs to a filter `f` if each `a \u2208 s` has a neighborhood `t`\nwithin `s` such that `t\u1d9c` belongs to `f`. -/\nlemma is_compact.compl_mem_sets_of_nhds_within (hs : is_compact s) {f : filter \u03b1}\n  (hf : \u2200 a \u2208 s, \u2203 t \u2208 \ud835\udcdd[s] a, t\u1d9c \u2208 f) :\n  s\u1d9c \u2208 f :=\nbegin\n  refine hs.compl_mem_sets (\u03bb a ha, _),\n  rcases hf a ha with \u27e8t, ht, hst\u27e9,\n  replace ht := mem_inf_principal.1 ht,\n  apply mem_inf_of_inter ht hst,\n  rintros x \u27e8h\u2081, h\u2082\u27e9 hs,\n  exact h\u2082 (h\u2081 hs)\nend\n\n/-- If `p : set \u03b1 \u2192 Prop` is stable under restriction and union, and each point `x`\n  of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/\n@[elab_as_eliminator]\nlemma is_compact.induction_on {s : set \u03b1} (hs : is_compact s) {p : set \u03b1 \u2192 Prop} (he : p \u2205)\n  (hmono : \u2200 \u2983s t\u2984, s \u2286 t \u2192 p t \u2192 p s) (hunion : \u2200 \u2983s t\u2984, p s \u2192 p t \u2192 p (s \u222a t))\n  (hnhds : \u2200 x \u2208 s, \u2203 t \u2208 \ud835\udcdd[s] x, p t) :\n  p s :=\nlet f : filter \u03b1 :=\n  { sets := {t | p t\u1d9c},\n    univ_sets := by simpa,\n    sets_of_superset := \u03bb t\u2081 t\u2082 ht\u2081 ht, hmono (compl_subset_compl.2 ht) ht\u2081,\n    inter_sets := \u03bb t\u2081 t\u2082 ht\u2081 ht\u2082, by simp [compl_inter, hunion ht\u2081 ht\u2082] } in\nhave s\u1d9c \u2208 f, from hs.compl_mem_sets_of_nhds_within (by simpa using hnhds),\nby simpa\n\n/-- The intersection of a compact set and a closed set is a compact set. -/\nlemma is_compact.inter_right (hs : is_compact s) (ht : is_closed t) :\n  is_compact (s \u2229 t) :=\nbegin\n  introsI f hnf hstf,\n  obtain \u27e8a, hsa, ha\u27e9 : \u2203 a \u2208 s, cluster_pt a f :=\n    hs (le_trans hstf (le_principal_iff.2 (inter_subset_left _ _))),\n  have : a \u2208 t :=\n    (ht.mem_of_nhds_within_ne_bot $ ha.mono $\n      le_trans hstf (le_principal_iff.2 (inter_subset_right _ _))),\n  exact \u27e8a, \u27e8hsa, this\u27e9, ha\u27e9\nend\n\n/-- The intersection of a closed set and a compact set is a compact set. -/\nlemma is_compact.inter_left (ht : is_compact t) (hs : is_closed s) : is_compact (s \u2229 t) :=\ninter_comm t s \u25b8 ht.inter_right hs\n\n/-- The set difference of a compact set and an open set is a compact set. -/\nlemma is_compact.diff (hs : is_compact s) (ht : is_open t) : is_compact (s \\ t) :=\nhs.inter_right (is_closed_compl_iff.mpr ht)\n\n/-- A closed subset of a compact set is a compact set. -/\nlemma compact_of_is_closed_subset (hs : is_compact s) (ht : is_closed t) (h : t \u2286 s) :\n  is_compact t :=\ninter_eq_self_of_subset_right h \u25b8 hs.inter_right ht\n\nlemma is_compact.image_of_continuous_on {f : \u03b1 \u2192 \u03b2} (hs : is_compact s) (hf : continuous_on f s) :\n  is_compact (f '' s) :=\nbegin\n  intros l lne ls,\n  have : ne_bot (l.comap f \u2293 \ud835\udcdf s) :=\n    comap_inf_principal_ne_bot_of_image_mem lne (le_principal_iff.1 ls),\n  obtain \u27e8a, has, ha\u27e9 : \u2203 a \u2208 s, cluster_pt a (l.comap f \u2293 \ud835\udcdf s) := @@hs this inf_le_right,\n  use [f a, mem_image_of_mem f has],\n  have : tendsto f (\ud835\udcdd a \u2293 (comap f l \u2293 \ud835\udcdf s)) (\ud835\udcdd (f a) \u2293 l),\n  { convert (hf a has).inf (@tendsto_comap _ _ f l) using 1,\n    rw nhds_within,\n    ac_refl },\n  exact @@tendsto.ne_bot _ this ha,\nend\n\nlemma is_compact.image {f : \u03b1 \u2192 \u03b2} (hs : is_compact s) (hf : continuous f) :\n  is_compact (f '' s) :=\nhs.image_of_continuous_on hf.continuous_on\n\nlemma is_compact.adherence_nhdset {f : filter \u03b1}\n  (hs : is_compact s) (hf\u2082 : f \u2264 \ud835\udcdf s) (ht\u2081 : is_open t) (ht\u2082 : \u2200 a \u2208 s, cluster_pt a f \u2192 a \u2208 t) :\n  t \u2208 f :=\nclassical.by_cases mem_of_eq_bot $\n  assume : f \u2293 \ud835\udcdf t\u1d9c \u2260 \u22a5,\n  let \u27e8a, ha, (hfa : cluster_pt a $ f \u2293 \ud835\udcdf t\u1d9c)\u27e9 := @@hs \u27e8this\u27e9 $ inf_le_of_left_le hf\u2082 in\n  have a \u2208 t,\n    from ht\u2082 a ha (hfa.of_inf_left),\n  have t\u1d9c \u2229 t \u2208 \ud835\udcdd[t\u1d9c] a,\n    from inter_mem_nhds_within _ (is_open.mem_nhds ht\u2081 this),\n  have A : \ud835\udcdd[t\u1d9c] a = \u22a5,\n    from empty_mem_iff_bot.1 $ compl_inter_self t \u25b8 this,\n  have \ud835\udcdd[t\u1d9c] a \u2260 \u22a5,\n    from hfa.of_inf_right.ne,\n  absurd A this\n\nlemma is_compact_iff_ultrafilter_le_nhds :\n  is_compact s \u2194 (\u2200 f : ultrafilter \u03b1, \u2191f \u2264 \ud835\udcdf s \u2192 \u2203 a \u2208 s, \u2191f \u2264 \ud835\udcdd a) :=\nbegin\n  refine (forall_ne_bot_le_iff _).trans _,\n  { rintro f g hle \u27e8a, has, haf\u27e9,\n    exact \u27e8a, has, haf.mono hle\u27e9 },\n  { simp only [ultrafilter.cluster_pt_iff] }\nend\n\nalias is_compact_iff_ultrafilter_le_nhds \u2194 is_compact.ultrafilter_le_nhds _\n\n/-- For every open directed cover of a compact set, there exists a single element of the\ncover which itself includes the set. -/\nlemma is_compact.elim_directed_cover {\u03b9 : Type v} [h\u03b9 : nonempty \u03b9] (hs : is_compact s)\n  (U : \u03b9 \u2192 set \u03b1) (hUo : \u2200 i, is_open (U i)) (hsU : s \u2286 \u22c3 i, U i) (hdU : directed (\u2286) U) :\n  \u2203 i, s \u2286 U i :=\nh\u03b9.elim $ \u03bb i\u2080, is_compact.induction_on hs \u27e8i\u2080, empty_subset _\u27e9\n  (\u03bb s\u2081 s\u2082 hs \u27e8i, hi\u27e9, \u27e8i, subset.trans hs hi\u27e9)\n  (\u03bb s\u2081 s\u2082 \u27e8i, hi\u27e9 \u27e8j, hj\u27e9, let \u27e8k, hki, hkj\u27e9 := hdU i j in\n    \u27e8k, union_subset (subset.trans hi hki) (subset.trans hj hkj)\u27e9)\n  (\u03bb x hx, let \u27e8i, hi\u27e9 := mem_Union.1 (hsU hx) in\n    \u27e8U i, mem_nhds_within_of_mem_nhds (is_open.mem_nhds (hUo i) hi), i, subset.refl _\u27e9)\n\n/-- For every open cover of a compact set, there exists a finite subcover. -/\nlemma is_compact.elim_finite_subcover {\u03b9 : Type v} (hs : is_compact s)\n  (U : \u03b9 \u2192 set \u03b1) (hUo : \u2200 i, is_open (U i)) (hsU : s \u2286 \u22c3 i, U i) :\n  \u2203 t : finset \u03b9, s \u2286 \u22c3 i \u2208 t, U i :=\nhs.elim_directed_cover _ (\u03bb t, is_open_bUnion $ \u03bb i _, hUo i) (Union_eq_Union_finset U \u25b8 hsU)\n  (directed_of_sup $ \u03bb t\u2081 t\u2082 h, bUnion_subset_bUnion_left h)\n\nlemma is_compact.elim_nhds_subcover' (hs : is_compact s) (U : \u03a0 x \u2208 s, set \u03b1)\n  (hU : \u2200 x \u2208 s, U x \u2039x \u2208 s\u203a \u2208 \ud835\udcdd x) :\n  \u2203 t : finset s, s \u2286 \u22c3 x \u2208 t, U (x : s) x.2 :=\n(hs.elim_finite_subcover (\u03bb x : s, interior (U x x.2)) (\u03bb x, is_open_interior)\n  (\u03bb x hx, mem_Union.2 \u27e8\u27e8x, hx\u27e9, mem_interior_iff_mem_nhds.2 $ hU _ _\u27e9)).imp $ \u03bb t ht,\nsubset.trans ht $ Union\u2082_mono $ \u03bb _ _, interior_subset\n\nlemma is_compact.elim_nhds_subcover (hs : is_compact s) (U : \u03b1 \u2192 set \u03b1) (hU : \u2200 x \u2208 s, U x \u2208 \ud835\udcdd x) :\n  \u2203 t : finset \u03b1, (\u2200 x \u2208 t, x \u2208 s) \u2227 s \u2286 \u22c3 x \u2208 t, U x :=\nlet \u27e8t, ht\u27e9 := hs.elim_nhds_subcover' (\u03bb x _, U x) hU\nin \u27e8t.image coe, \u03bb x hx, let \u27e8y, hyt, hyx\u27e9 := finset.mem_image.1 hx in hyx \u25b8 y.2,\n  by rwa finset.set_bUnion_finset_image\u27e9\n\n/-- For every family of closed sets whose intersection avoids a compact set,\nthere exists a finite subfamily whose intersection avoids this compact set. -/\nlemma is_compact.elim_finite_subfamily_closed {s : set \u03b1} {\u03b9 : Type v} (hs : is_compact s)\n  (Z : \u03b9 \u2192 set \u03b1) (hZc : \u2200 i, is_closed (Z i)) (hsZ : s \u2229 (\u22c2 i, Z i) = \u2205) :\n  \u2203 t : finset \u03b9, s \u2229 (\u22c2 i \u2208 t, Z i) = \u2205 :=\nlet \u27e8t, ht\u27e9 := hs.elim_finite_subcover (\u03bb i, (Z i)\u1d9c) (\u03bb i, (hZc i).is_open_compl)\n  (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,\n    exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using hsZ)\n    in\n\u27e8t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,\n    exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using ht\u27e9\n\n/-- If `s` is a compact set in a topological space `\u03b1` and `f : \u03b9 \u2192 set \u03b1` is a locally finite\nfamily of sets, then `f i \u2229 s` is nonempty only for a finitely many `i`. -/\nlemma locally_finite.finite_nonempty_inter_compact {\u03b9 : Type*} {f : \u03b9 \u2192 set \u03b1}\n  (hf : locally_finite f) {s : set \u03b1} (hs : is_compact s) :\n  finite {i | (f i \u2229 s).nonempty} :=\nbegin\n  choose U hxU hUf using hf,\n  rcases hs.elim_nhds_subcover U (\u03bb x _, hxU x) with \u27e8t, -, hsU\u27e9,\n  refine (t.finite_to_set.bUnion (\u03bb x _, hUf x)).subset _,\n  rintro i \u27e8x, hx\u27e9,\n  rcases mem_Union\u2082.1 (hsU hx.2) with \u27e8c, hct, hcx\u27e9,\n  exact mem_bUnion hct \u27e8x, hx.1, hcx\u27e9\nend\n\n/-- To show that a compact set intersects the intersection of a family of closed sets,\n  it is sufficient to show that it intersects every finite subfamily. -/\nlemma is_compact.inter_Inter_nonempty {s : set \u03b1} {\u03b9 : Type v} (hs : is_compact s)\n  (Z : \u03b9 \u2192 set \u03b1) (hZc : \u2200 i, is_closed (Z i)) (hsZ : \u2200 t : finset \u03b9, (s \u2229 \u22c2 i \u2208 t, Z i).nonempty) :\n  (s \u2229 \u22c2 i, Z i).nonempty :=\nbegin\n  simp only [\u2190 ne_empty_iff_nonempty] at hsZ \u22a2,\n  apply mt (hs.elim_finite_subfamily_closed Z hZc), push_neg, exact hsZ\nend\n\n/-- Cantor's intersection theorem:\nthe intersection of a directed family of nonempty compact closed sets is nonempty. -/\nlemma is_compact.nonempty_Inter_of_directed_nonempty_compact_closed\n  {\u03b9 : Type v} [h\u03b9 : nonempty \u03b9] (Z : \u03b9 \u2192 set \u03b1) (hZd : directed (\u2287) Z)\n  (hZn : \u2200 i, (Z i).nonempty) (hZc : \u2200 i, is_compact (Z i)) (hZcl : \u2200 i, is_closed (Z i)) :\n  (\u22c2 i, Z i).nonempty :=\nbegin\n  apply h\u03b9.elim,\n  intro i\u2080,\n  let Z' := \u03bb i, Z i \u2229 Z i\u2080,\n  suffices : (\u22c2 i, Z' i).nonempty,\n  { exact this.mono (Inter_mono $ \u03bb i, inter_subset_left (Z i) (Z i\u2080)) },\n  rw \u2190 ne_empty_iff_nonempty,\n  intro H,\n  obtain \u27e8t, ht\u27e9 : \u2203 (t : finset \u03b9), ((Z i\u2080) \u2229 \u22c2 (i \u2208 t), Z' i) = \u2205,\n    from (hZc i\u2080).elim_finite_subfamily_closed Z'\n      (assume i, is_closed.inter (hZcl i) (hZcl i\u2080)) (by rw [H, inter_empty]),\n  obtain \u27e8i\u2081, hi\u2081\u27e9 : \u2203 i\u2081 : \u03b9, Z i\u2081 \u2286 Z i\u2080 \u2227 \u2200 i \u2208 t, Z i\u2081 \u2286 Z' i,\n  { rcases directed.finset_le hZd t with \u27e8i, hi\u27e9,\n    rcases hZd i i\u2080 with \u27e8i\u2081, hi\u2081, hi\u2081\u2080\u27e9,\n    use [i\u2081, hi\u2081\u2080],\n    intros j hj,\n    exact subset_inter (subset.trans hi\u2081 (hi j hj)) hi\u2081\u2080 },\n  suffices : ((Z i\u2080) \u2229 \u22c2 (i \u2208 t), Z' i).nonempty,\n  { rw \u2190 ne_empty_iff_nonempty at this, contradiction },\n  exact (hZn i\u2081).mono (subset_inter hi\u2081.left $ subset_Inter\u2082 hi\u2081.right),\nend\n\n/-- Cantor's intersection theorem for sequences indexed by `\u2115`:\nthe intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/\nlemma is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed\n  (Z : \u2115 \u2192 set \u03b1) (hZd : \u2200 i, Z (i+1) \u2286 Z i)\n  (hZn : \u2200 i, (Z i).nonempty) (hZ0 : is_compact (Z 0)) (hZcl : \u2200 i, is_closed (Z i)) :\n  (\u22c2 i, Z i).nonempty :=\nhave Zmono : antitone Z := antitone_nat_of_succ_le hZd,\nhave hZd : directed (\u2287) Z, from directed_of_sup Zmono,\nhave \u2200 i, Z i \u2286 Z 0, from assume i, Zmono $ zero_le i,\nhave hZc : \u2200 i, is_compact (Z i), from assume i, compact_of_is_closed_subset hZ0 (hZcl i) (this i),\nis_compact.nonempty_Inter_of_directed_nonempty_compact_closed Z hZd hZn hZc hZcl\n\n/-- For every open cover of a compact set, there exists a finite subcover. -/\nlemma is_compact.elim_finite_subcover_image {b : set \u03b9} {c : \u03b9 \u2192 set \u03b1}\n  (hs : is_compact s) (hc\u2081 : \u2200 i \u2208 b, is_open (c i)) (hc\u2082 : s \u2286 \u22c3 i \u2208 b, c i) :\n  \u2203 b' \u2286 b, finite b' \u2227 s \u2286 \u22c3 i \u2208 b', c i :=\nbegin\n  rcases hs.elim_finite_subcover (\u03bb i, c i : b \u2192 set \u03b1) _ _ with \u27e8d, hd\u27e9;\n    [skip, simpa using hc\u2081, simpa using hc\u2082],\n  refine \u27e8\u2191(d.image coe), _, finset.finite_to_set _, _\u27e9,\n  { simp },\n  { rwa [finset.coe_image, bUnion_image] }\nend\n\n/-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`,\nthere exists a finite subfamily whose intersection avoids `s`. -/\ntheorem is_compact_of_finite_subfamily_closed\n  (h : \u03a0 {\u03b9 : Type u} (Z : \u03b9 \u2192 (set \u03b1)), (\u2200 i, is_closed (Z i)) \u2192\n    s \u2229 (\u22c2 i, Z i) = \u2205 \u2192 (\u2203 (t : finset \u03b9), s \u2229 (\u22c2 i \u2208 t, Z i) = \u2205)) :\n  is_compact s :=\nassume f hfn hfs, classical.by_contradiction $ assume : \u00ac (\u2203 x \u2208 s, cluster_pt x f),\n  have hf : \u2200 x \u2208 s, \ud835\udcdd x \u2293 f = \u22a5,\n    by simpa only [cluster_pt, not_exists, not_not, ne_bot_iff],\n  have \u00ac \u2203 x \u2208 s, \u2200 t \u2208 f.sets, x \u2208 closure t,\n    from assume \u27e8x, hxs, hx\u27e9,\n    have \u2205 \u2208 \ud835\udcdd x \u2293 f, by rw [empty_mem_iff_bot, hf x hxs],\n    let \u27e8t\u2081, ht\u2081, t\u2082, ht\u2082, ht\u27e9 := by rw [mem_inf_iff] at this; exact this in\n    have \u2205 \u2208 \ud835\udcdd[t\u2082] x,\n      by { rw [ht, inter_comm], exact inter_mem_nhds_within _ ht\u2081 },\n    have \ud835\udcdd[t\u2082] x = \u22a5,\n      by rwa [empty_mem_iff_bot] at this,\n    by simp only [closure_eq_cluster_pts] at hx; exact (hx t\u2082 ht\u2082).ne this,\n  let \u27e8t, ht\u27e9 := h (\u03bb i : f.sets, closure i.1) (\u03bb i, is_closed_closure)\n    (by simpa [eq_empty_iff_forall_not_mem, not_exists]) in\n  have (\u22c2 i \u2208 t, subtype.val i) \u2208 f,\n    from t.Inter_mem_sets.2 $ assume i hi, i.2,\n  have s \u2229 (\u22c2 i \u2208 t, subtype.val i) \u2208 f,\n    from inter_mem (le_principal_iff.1 hfs) this,\n  have \u2205 \u2208 f,\n    from mem_of_superset this $ assume x \u27e8hxs, hx\u27e9,\n    let \u27e8i, hit, hxi\u27e9 := (show \u2203 i \u2208 t, x \u2209 closure (subtype.val i),\n      by { rw [eq_empty_iff_forall_not_mem] at ht, simpa [hxs, not_forall] using ht x }) in\n    have x \u2208 closure i.val, from subset_closure (by { rw mem_Inter\u2082 at hx, exact hx i hit }),\n    show false, from hxi this,\n  hfn.ne $ by rwa [empty_mem_iff_bot] at this\n\n/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/\nlemma is_compact_of_finite_subcover\n  (h : \u03a0 {\u03b9 : Type u} (U : \u03b9 \u2192 (set \u03b1)), (\u2200 i, is_open (U i)) \u2192\n    s \u2286 (\u22c3 i, U i) \u2192 (\u2203 (t : finset \u03b9), s \u2286 (\u22c3 i \u2208 t, U i))) :\n  is_compact s :=\nis_compact_of_finite_subfamily_closed $\n  assume \u03b9 Z hZc hsZ,\n  let \u27e8t, ht\u27e9 := h (\u03bb i, (Z i)\u1d9c) (assume i, is_open_compl_iff.mpr $ hZc i)\n    (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,\n      exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using hsZ)\n      in\n  \u27e8t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,\n      exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using ht\u27e9\n\n/-- A set `s` is compact if and only if\nfor every open cover of `s`, there exists a finite subcover. -/\nlemma is_compact_iff_finite_subcover :\n  is_compact s \u2194 (\u03a0 {\u03b9 : Type u} (U : \u03b9 \u2192 (set \u03b1)), (\u2200 i, is_open (U i)) \u2192\n    s \u2286 (\u22c3 i, U i) \u2192 (\u2203 (t : finset \u03b9), s \u2286 (\u22c3 i \u2208 t, U i))) :=\n\u27e8assume hs \u03b9, hs.elim_finite_subcover, is_compact_of_finite_subcover\u27e9\n\n/-- A set `s` is compact if and only if\nfor every family of closed sets whose intersection avoids `s`,\nthere exists a finite subfamily whose intersection avoids `s`. -/\ntheorem is_compact_iff_finite_subfamily_closed :\n  is_compact s \u2194 (\u03a0 {\u03b9 : Type u} (Z : \u03b9 \u2192 (set \u03b1)), (\u2200 i, is_closed (Z i)) \u2192\n    s \u2229 (\u22c2 i, Z i) = \u2205 \u2192 (\u2203 (t : finset \u03b9), s \u2229 (\u22c2 i \u2208 t, Z i) = \u2205)) :=\n\u27e8assume hs \u03b9, hs.elim_finite_subfamily_closed, is_compact_of_finite_subfamily_closed\u27e9\n\n/--\nTo show that `\u2200 y \u2208 K, P x y` holds for `x` close enough to `x\u2080` when `K` is compact,\nit is sufficient to show that for all `y\u2080 \u2208 K` there `P x y` holds for `(x, y)` close enough\nto `(x\u2080, y\u2080)`.\n-/\nlemma is_compact.eventually_forall_of_forall_eventually {x\u2080 : \u03b1} {K : set \u03b2} (hK : is_compact K)\n  {P : \u03b1 \u2192 \u03b2 \u2192 Prop} (hP : \u2200 y \u2208 K, \u2200\u1da0 (z : \u03b1 \u00d7 \u03b2) in \ud835\udcdd (x\u2080, y), P z.1 z.2):\n  \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200 y \u2208 K, P x y :=\nbegin\n  refine hK.induction_on _ _ _ _,\n  { exact eventually_of_forall (\u03bb x y, false.elim) },\n  { intros s t hst ht, refine ht.mono (\u03bb x h y hys, h y $ hst hys) },\n  { intros s t hs ht, filter_upwards [hs, ht], rintro x h1 h2 y (hys|hyt),\n    exacts [h1 y hys, h2 y hyt] },\n  { intros y hyK,\n    specialize hP y hyK,\n    rw [nhds_prod_eq, eventually_prod_iff] at hP,\n    rcases hP with \u27e8p, hp, q, hq, hpq\u27e9,\n    exact \u27e8{y | q y}, mem_nhds_within_of_mem_nhds hq, eventually_of_mem hp @hpq\u27e9 }\nend\n\n@[simp]\nlemma is_compact_empty : is_compact (\u2205 : set \u03b1) :=\nassume f hnf hsf, not.elim hnf.ne $\nempty_mem_iff_bot.1 $ le_principal_iff.1 hsf\n\n@[simp]\nlemma is_compact_singleton {a : \u03b1} : is_compact ({a} : set \u03b1) :=\n\u03bb f hf hfa, \u27e8a, rfl, cluster_pt.of_le_nhds'\n  (hfa.trans $ by simpa only [principal_singleton] using pure_le_nhds a) hf\u27e9\n\nlemma set.subsingleton.is_compact {s : set \u03b1} (hs : s.subsingleton) : is_compact s :=\nsubsingleton.induction_on hs is_compact_empty $ \u03bb x, is_compact_singleton\n\nlemma set.finite.compact_bUnion {s : set \u03b9} {f : \u03b9 \u2192 set \u03b1} (hs : finite s)\n  (hf : \u2200 i \u2208 s, is_compact (f i)) :\n  is_compact (\u22c3 i \u2208 s, f i) :=\nis_compact_of_finite_subcover $ assume \u03b9 U hUo hsU,\n  have \u2200 i : subtype s, \u2203 t : finset \u03b9, f i \u2286 (\u22c3 j \u2208 t, U j), from\n    assume \u27e8i, hi\u27e9, (hf i hi).elim_finite_subcover _ hUo\n      (calc f i \u2286 \u22c3 i \u2208 s, f i : subset_bUnion_of_mem hi\n            ... \u2286 \u22c3 j, U j     : hsU),\n  let \u27e8finite_subcovers, h\u27e9 := axiom_of_choice this in\n  by haveI : fintype (subtype s) := hs.fintype; exact\n  let t := finset.bUnion finset.univ finite_subcovers in\n  have (\u22c3 i \u2208 s, f i) \u2286 (\u22c3 i \u2208 t, U i), from Union\u2082_subset $\n    assume i hi, calc\n    f i \u2286 (\u22c3 j \u2208 finite_subcovers \u27e8i, hi\u27e9, U j) : (h \u27e8i, hi\u27e9)\n    ... \u2286 (\u22c3 j \u2208 t, U j) : bUnion_subset_bUnion_left $\n      assume j hj, finset.mem_bUnion.mpr \u27e8_, finset.mem_univ _, hj\u27e9,\n  \u27e8t, this\u27e9\n\nlemma finset.compact_bUnion (s : finset \u03b9) {f : \u03b9 \u2192 set \u03b1} (hf : \u2200 i \u2208 s, is_compact (f i)) :\n  is_compact (\u22c3 i \u2208 s, f i) :=\ns.finite_to_set.compact_bUnion hf\n\nlemma compact_accumulate {K : \u2115 \u2192 set \u03b1} (hK : \u2200 n, is_compact (K n)) (n : \u2115) :\n  is_compact (accumulate K n) :=\n(finite_le_nat n).compact_bUnion $ \u03bb k _, hK k\n\nlemma compact_Union {f : \u03b9 \u2192 set \u03b1} [fintype \u03b9]\n  (h : \u2200 i, is_compact (f i)) : is_compact (\u22c3 i, f i) :=\nby rw \u2190 bUnion_univ; exact finite_univ.compact_bUnion (\u03bb i _, h i)\n\nlemma set.finite.is_compact (hs : finite s) : is_compact s :=\nbUnion_of_singleton s \u25b8 hs.compact_bUnion (\u03bb _ _, is_compact_singleton)\n\nlemma is_compact.finite_of_discrete [discrete_topology \u03b1] {s : set \u03b1} (hs : is_compact s) :\n  s.finite :=\nbegin\n  have : \u2200 x : \u03b1, ({x} : set \u03b1) \u2208 \ud835\udcdd x, by simp [nhds_discrete],\n  rcases hs.elim_nhds_subcover (\u03bb x, {x}) (\u03bb x hx, this x) with \u27e8t, hts, hst\u27e9,\n  simp only [\u2190 t.set_bUnion_coe, bUnion_of_singleton] at hst,\n  exact t.finite_to_set.subset hst\nend\n\nlemma is_compact_iff_finite [discrete_topology \u03b1] {s : set \u03b1} : is_compact s \u2194 s.finite :=\n\u27e8\u03bb h, h.finite_of_discrete, \u03bb h, h.is_compact\u27e9\n\nlemma is_compact.union (hs : is_compact s) (ht : is_compact t) : is_compact (s \u222a t) :=\nby rw union_eq_Union; exact compact_Union (\u03bb b, by cases b; assumption)\n\nlemma is_compact.insert (hs : is_compact s) (a) : is_compact (insert a s) :=\nis_compact_singleton.union hs\n\n/-- If `V : \u03b9 \u2192 set \u03b1` is a decreasing family of closed compact sets then any neighborhood of\n`\u22c2 i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `\u03b1` is\nnot assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/\nlemma exists_subset_nhd_of_compact' {\u03b9 : Type*} [nonempty \u03b9] {V : \u03b9 \u2192 set \u03b1} (hV : directed (\u2287) V)\n  (hV_cpct : \u2200 i, is_compact (V i)) (hV_closed : \u2200 i, is_closed (V i))\n  {U : set \u03b1} (hU : \u2200 x \u2208 \u22c2 i, V i, U \u2208 \ud835\udcdd x) : \u2203 i, V i \u2286 U :=\nbegin\n  obtain \u27e8W, hsubW, W_op, hWU\u27e9 := exists_open_set_nhds hU,\n  suffices : \u2203 i, V i \u2286 W,\n  { rcases this with \u27e8i, hi\u27e9,\n    refine \u27e8i, set.subset.trans hi hWU\u27e9 },\n  by_contra' H,\n  replace H : \u2200 i, (V i \u2229 W\u1d9c).nonempty := \u03bb i, set.inter_compl_nonempty_iff.mpr (H i),\n  have : (\u22c2 i, V i \u2229 W\u1d9c).nonempty,\n  { refine is_compact.nonempty_Inter_of_directed_nonempty_compact_closed _ (\u03bb i j, _) H\n      (\u03bb i, (hV_cpct i).inter_right W_op.is_closed_compl)\n      (\u03bb i, (hV_closed i).inter W_op.is_closed_compl),\n    rcases hV i j with \u27e8k, hki, hkj\u27e9,\n    refine \u27e8k, \u27e8\u03bb x, _, \u03bb x, _\u27e9\u27e9 ; simp only [and_imp, mem_inter_eq, mem_compl_eq] ; tauto },\n  have : \u00ac (\u22c2 (i : \u03b9), V i) \u2286 W, by simpa [\u2190 Inter_inter, inter_compl_nonempty_iff],\n  contradiction\nend\n\nnamespace filter\n\n/-- `filter.cocompact` is the filter generated by complements to compact sets. -/\ndef cocompact (\u03b1 : Type*) [topological_space \u03b1] : filter \u03b1 :=\n\u2a05 (s : set \u03b1) (hs : is_compact s), \ud835\udcdf (s\u1d9c)\n\nlemma has_basis_cocompact : (cocompact \u03b1).has_basis is_compact compl :=\nhas_basis_binfi_principal'\n  (\u03bb s hs t ht, \u27e8s \u222a t, hs.union ht, compl_subset_compl.2 (subset_union_left s t),\n    compl_subset_compl.2 (subset_union_right s t)\u27e9)\n  \u27e8\u2205, is_compact_empty\u27e9\n\nlemma mem_cocompact : s \u2208 cocompact \u03b1 \u2194 \u2203 t, is_compact t \u2227 t\u1d9c \u2286 s :=\nhas_basis_cocompact.mem_iff.trans $ exists_congr $ \u03bb t, exists_prop\n\nlemma mem_cocompact' : s \u2208 cocompact \u03b1 \u2194 \u2203 t, is_compact t \u2227 s\u1d9c \u2286 t :=\nmem_cocompact.trans $ exists_congr $ \u03bb t, and_congr_right $ \u03bb ht, compl_subset_comm\n\nlemma _root_.is_compact.compl_mem_cocompact (hs : is_compact s) : s\u1d9c \u2208 filter.cocompact \u03b1 :=\nhas_basis_cocompact.mem_of_mem hs\n\nlemma cocompact_le_cofinite : cocompact \u03b1 \u2264 cofinite :=\n\u03bb s hs, compl_compl s \u25b8 hs.is_compact.compl_mem_cocompact\n\nlemma cocompact_eq_cofinite (\u03b1 : Type*) [topological_space \u03b1] [discrete_topology \u03b1] :\n  cocompact \u03b1 = cofinite :=\nhas_basis_cocompact.eq_of_same_basis $\n  by { convert has_basis_cofinite, ext s, exact is_compact_iff_finite }\n\n@[simp] lemma _root_.nat.cocompact_eq : cocompact \u2115 = at_top :=\n(cocompact_eq_cofinite \u2115).trans nat.cofinite_eq_at_top\n\nlemma tendsto.is_compact_insert_range_of_cocompact {f : \u03b1 \u2192 \u03b2} {b}\n  (hf : tendsto f (cocompact \u03b1) (\ud835\udcdd b)) (hfc : continuous f) :\n  is_compact (insert b (range f)) :=\nbegin\n  introsI l hne hle,\n  by_cases hb : cluster_pt b l, { exact \u27e8b, or.inl rfl, hb\u27e9 },\n  simp only [cluster_pt_iff, not_forall, \u2190 not_disjoint_iff_nonempty_inter, not_not] at hb,\n  rcases hb with \u27e8s, hsb, t, htl, hd\u27e9,\n  rcases mem_cocompact.1 (hf hsb) with \u27e8K, hKc, hKs\u27e9,\n  have : f '' K \u2208 l,\n  { filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf,\n    rcases hyf with (rfl|\u27e8x, rfl\u27e9),\n    exacts [(hd \u27e8mem_of_mem_nhds hsb, hyt\u27e9).elim,\n      mem_image_of_mem _ (not_not.1 $ \u03bb hxK, hd \u27e8hKs hxK, hyt\u27e9)] },\n  rcases hKc.image hfc (le_principal_iff.2 this) with \u27e8y, hy, hyl\u27e9,\n  exact \u27e8y, or.inr $ image_subset_range _ _ hy, hyl\u27e9\nend\n\nlemma tendsto.is_compact_insert_range_of_cofinite {f : \u03b9 \u2192 \u03b1} {a}\n  (hf : tendsto f cofinite (\ud835\udcdd a)) :\n  is_compact (insert a (range f)) :=\nbegin\n  letI : topological_space \u03b9 := \u22a5, haveI : discrete_topology \u03b9 := \u27e8rfl\u27e9,\n  rw \u2190 cocompact_eq_cofinite at hf,\n  exact hf.is_compact_insert_range_of_cocompact continuous_of_discrete_topology\nend\n\nlemma tendsto.is_compact_insert_range {f : \u2115 \u2192 \u03b1} {a} (hf : tendsto f at_top (\ud835\udcdd a)) :\n  is_compact (insert a (range f)) :=\nfilter.tendsto.is_compact_insert_range_of_cofinite $ nat.cofinite_eq_at_top.symm \u25b8 hf\n\n/-- `filter.coclosed_compact` is the filter generated by complements to closed compact sets.\nIn a Hausdorff space, this is the same as `filter.cocompact`. -/\ndef coclosed_compact (\u03b1 : Type*) [topological_space \u03b1] : filter \u03b1 :=\n\u2a05 (s : set \u03b1) (h\u2081 : is_closed s) (h\u2082 : is_compact s), \ud835\udcdf (s\u1d9c)\n\nlemma has_basis_coclosed_compact :\n  (filter.coclosed_compact \u03b1).has_basis (\u03bb s, is_closed s \u2227 is_compact s) compl :=\nbegin\n  simp only [filter.coclosed_compact, infi_and'],\n  refine has_basis_binfi_principal' _ \u27e8\u2205, is_closed_empty, is_compact_empty\u27e9,\n  rintro s \u27e8hs\u2081, hs\u2082\u27e9 t \u27e8ht\u2081, ht\u2082\u27e9,\n  exact \u27e8s \u222a t, \u27e8\u27e8hs\u2081.union ht\u2081, hs\u2082.union ht\u2082\u27e9, compl_subset_compl.2 (subset_union_left _ _),\n    compl_subset_compl.2 (subset_union_right _ _)\u27e9\u27e9\nend\n\nlemma mem_coclosed_compact : s \u2208 coclosed_compact \u03b1 \u2194 \u2203 t, is_closed t \u2227 is_compact t \u2227 t\u1d9c \u2286 s :=\nby simp [has_basis_coclosed_compact.mem_iff, and_assoc]\n\nlemma mem_coclosed_compact' : s \u2208 coclosed_compact \u03b1 \u2194 \u2203 t, is_closed t \u2227 is_compact t \u2227 s\u1d9c \u2286 t :=\nby simp only [mem_coclosed_compact, compl_subset_comm]\n\nlemma cocompact_le_coclosed_compact : cocompact \u03b1 \u2264 coclosed_compact \u03b1 :=\ninfi_mono $ \u03bb s, le_infi $ \u03bb _, le_rfl\n\nlemma _root_.is_compact.compl_mem_coclosed_compact_of_is_closed (hs : is_compact s)\n  (hs' : is_closed s) :\n  s\u1d9c \u2208 filter.coclosed_compact \u03b1 :=\nhas_basis_coclosed_compact.mem_of_mem \u27e8hs', hs\u27e9\n\nend filter\n\nnamespace bornology\n\nvariable (\u03b1)\n\n/-- Sets that are contained in a compact set form a bornology. Its `cobounded` filter is\n`filter.cocompact`. See also `bornology.relatively_compact` the bornology of sets with compact\nclosure. -/\ndef in_compact : bornology \u03b1 :=\n{ cobounded := filter.cocompact \u03b1,\n  le_cofinite := filter.cocompact_le_cofinite }\n\nvariable {\u03b1}\n\nlemma in_compact.is_bounded_iff : @is_bounded _ (in_compact \u03b1) s \u2194 \u2203 t, is_compact t \u2227 s \u2286 t :=\nbegin\n  change s\u1d9c \u2208 filter.cocompact \u03b1 \u2194 _,\n  rw filter.mem_cocompact,\n  simp\nend\n\nend bornology\n\nsection tube_lemma\n\n/-- `nhds_contain_boxes s t` means that any open neighborhood of `s \u00d7 t` in `\u03b1 \u00d7 \u03b2` includes\na product of an open neighborhood of `s` by an open neighborhood of `t`. -/\ndef nhds_contain_boxes (s : set \u03b1) (t : set \u03b2) : Prop :=\n\u2200 (n : set (\u03b1 \u00d7 \u03b2)) (hn : is_open n) (hp : s \u00d7\u02e2 t \u2286 n),\n\u2203 (u : set \u03b1) (v : set \u03b2), is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 u \u00d7\u02e2 v \u2286 n\n\nlemma nhds_contain_boxes.symm {s : set \u03b1} {t : set \u03b2} :\n  nhds_contain_boxes s t \u2192 nhds_contain_boxes t s :=\nassume H n hn hp,\n  let \u27e8u, v, uo, vo, su, tv, p\u27e9 :=\n    H (prod.swap \u207b\u00b9' n)\n      (hn.preimage continuous_swap)\n      (by rwa [\u2190image_subset_iff, image_swap_prod]) in\n  \u27e8v, u, vo, uo, tv, su,\n    by rwa [\u2190image_subset_iff, image_swap_prod] at p\u27e9\n\nlemma nhds_contain_boxes.comm {s : set \u03b1} {t : set \u03b2} :\n  nhds_contain_boxes s t \u2194 nhds_contain_boxes t s :=\niff.intro nhds_contain_boxes.symm nhds_contain_boxes.symm\n\nlemma nhds_contain_boxes_of_singleton {x : \u03b1} {y : \u03b2} :\n  nhds_contain_boxes ({x} : set \u03b1) ({y} : set \u03b2) :=\nassume n hn hp,\n  let \u27e8u, v, uo, vo, xu, yv, hp'\u27e9 :=\n    is_open_prod_iff.mp hn x y (hp $ by simp) in\n  \u27e8u, v, uo, vo, by simpa, by simpa, hp'\u27e9\n\nlemma nhds_contain_boxes_of_compact {s : set \u03b1} (hs : is_compact s) (t : set \u03b2)\n  (H : \u2200 x \u2208 s, nhds_contain_boxes ({x} : set \u03b1) t) : nhds_contain_boxes s t :=\nassume n hn hp,\nhave \u2200 x : s, \u2203 uv : set \u03b1 \u00d7 set \u03b2,\n     is_open uv.1 \u2227 is_open uv.2 \u2227 {\u2191x} \u2286 uv.1 \u2227 t \u2286 uv.2 \u2227 uv.1 \u00d7\u02e2 uv.2 \u2286 n,\n  from assume \u27e8x, hx\u27e9,\n    have ({x} : set \u03b1) \u00d7\u02e2 t \u2286 n, from\n      subset.trans (prod_mono (by simpa) subset.rfl) hp,\n    let \u27e8ux,vx,H1\u27e9 := H x hx n hn this in \u27e8\u27e8ux,vx\u27e9,H1\u27e9,\nlet \u27e8uvs, h\u27e9 := classical.axiom_of_choice this in\nhave us_cover : s \u2286 \u22c3 i, (uvs i).1, from\n  assume x hx, subset_Union _ \u27e8x,hx\u27e9 (by simpa using (h \u27e8x,hx\u27e9).2.2.1),\nlet \u27e8s0, s0_cover\u27e9 :=\n  hs.elim_finite_subcover _ (\u03bbi, (h i).1) us_cover in\nlet u := \u22c3(i \u2208 s0), (uvs i).1 in\nlet v := \u22c2(i \u2208 s0), (uvs i).2 in\nhave is_open u, from is_open_bUnion (\u03bbi _, (h i).1),\nhave is_open v, from is_open_bInter s0.finite_to_set (\u03bbi _, (h i).2.1),\nhave t \u2286 v, from subset_Inter\u2082 (\u03bbi _, (h i).2.2.2.1),\nhave u \u00d7\u02e2 v \u2286 n, from assume \u27e8x',y'\u27e9 \u27e8hx',hy'\u27e9,\n  have \u2203 i \u2208 s0, x' \u2208 (uvs i).1, by simpa using hx',\n  let \u27e8i,is0,hi\u27e9 := this in\n  (h i).2.2.2.2 \u27e8hi, (bInter_subset_of_mem is0 : v \u2286 (uvs i).2) hy'\u27e9,\n\u27e8u, v, \u2039is_open u\u203a, \u2039is_open v\u203a, s0_cover, \u2039t \u2286 v\u203a, \u2039u \u00d7\u02e2 v \u2286 n\u203a\u27e9\n\n/-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s \u00d7 t`, then there exist\nopen neighborhoods `u \u2287 s` and `v \u2287 t` such that `u \u00d7 v \u2286 n`. -/\nlemma generalized_tube_lemma {s : set \u03b1} (hs : is_compact s) {t : set \u03b2} (ht : is_compact t)\n  {n : set (\u03b1 \u00d7 \u03b2)} (hn : is_open n) (hp : s \u00d7\u02e2 t \u2286 n) :\n  \u2203 (u : set \u03b1) (v : set \u03b2), is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 u \u00d7\u02e2 v \u2286 n :=\nhave _, from\n  nhds_contain_boxes_of_compact hs t $ assume x _, nhds_contain_boxes.symm $\n    nhds_contain_boxes_of_compact ht {x} $ assume y _, nhds_contain_boxes_of_singleton,\nthis n hn hp\n\nend tube_lemma\n\n/-- Type class for compact spaces. Separation is sometimes included in the definition, especially\nin the French literature, but we do not include it here. -/\nclass compact_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(compact_univ : is_compact (univ : set \u03b1))\n\n@[priority 10] -- see Note [lower instance priority]\ninstance subsingleton.compact_space [subsingleton \u03b1] : compact_space \u03b1 :=\n\u27e8subsingleton_univ.is_compact\u27e9\n\nlemma is_compact_univ_iff : is_compact (univ : set \u03b1) \u2194 compact_space \u03b1 := \u27e8\u03bb h, \u27e8h\u27e9, \u03bb h, h.1\u27e9\n\nlemma compact_univ [h : compact_space \u03b1] : is_compact (univ : set \u03b1) := h.compact_univ\n\nlemma cluster_point_of_compact [compact_space \u03b1] (f : filter \u03b1) [ne_bot f] :\n  \u2203 x, cluster_pt x f :=\nby simpa using compact_univ (show f \u2264 \ud835\udcdf univ, by simp)\n\nlemma compact_space.elim_nhds_subcover [compact_space \u03b1]\n  (U : \u03b1 \u2192 set \u03b1) (hU : \u2200 x, U x \u2208 \ud835\udcdd x) :\n  \u2203 t : finset \u03b1, (\u22c3 x \u2208 t, U x) = \u22a4 :=\nbegin\n  obtain \u27e8t, -, s\u27e9 := is_compact.elim_nhds_subcover compact_univ U (\u03bb x m, hU x),\n  exact \u27e8t, by { rw eq_top_iff, exact s }\u27e9,\nend\n\ntheorem compact_space_of_finite_subfamily_closed\n  (h : \u03a0 {\u03b9 : Type u} (Z : \u03b9 \u2192 (set \u03b1)), (\u2200 i, is_closed (Z i)) \u2192\n    (\u22c2 i, Z i) = \u2205 \u2192 \u2203 (t : finset \u03b9), (\u22c2 i \u2208 t, Z i) = \u2205) :\n  compact_space \u03b1 :=\n{ compact_univ :=\n  begin\n    apply is_compact_of_finite_subfamily_closed,\n    intros \u03b9 Z, specialize h Z,\n    simpa using h\n  end }\n\nlemma is_closed.is_compact [compact_space \u03b1] {s : set \u03b1} (h : is_closed s) :\n  is_compact s :=\ncompact_of_is_closed_subset compact_univ h (subset_univ _)\n\n/-- `\u03b1` is a noncompact topological space if it not a compact space. -/\nclass noncompact_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(noncompact_univ [] : \u00acis_compact (univ : set \u03b1))\n\nexport noncompact_space (noncompact_univ)\n\nlemma is_compact.ne_univ [noncompact_space \u03b1] {s : set \u03b1} (hs : is_compact s) : s \u2260 univ :=\n\u03bb h, noncompact_univ \u03b1 (h \u25b8 hs)\n\ninstance [noncompact_space \u03b1] : ne_bot (filter.cocompact \u03b1) :=\nbegin\n  refine filter.has_basis_cocompact.ne_bot_iff.2 (\u03bb s hs, _),\n  contrapose hs, rw [not_nonempty_iff_eq_empty, compl_empty_iff] at hs,\n  rw hs, exact noncompact_univ \u03b1\nend\n\n@[simp]\nlemma filter.cocompact_eq_bot [compact_space \u03b1] : filter.cocompact \u03b1 = \u22a5 :=\nfilter.has_basis_cocompact.eq_bot_iff.mpr \u27e8set.univ, compact_univ, set.compl_univ\u27e9\n\ninstance [noncompact_space \u03b1] : ne_bot (filter.coclosed_compact \u03b1) :=\nne_bot_of_le filter.cocompact_le_coclosed_compact\n\nlemma noncompact_space_of_ne_bot (h : ne_bot (filter.cocompact \u03b1)) : noncompact_space \u03b1 :=\n\u27e8\u03bb h', (filter.nonempty_of_mem h'.compl_mem_cocompact).ne_empty compl_univ\u27e9\n\nlemma filter.cocompact_ne_bot_iff : ne_bot (filter.cocompact \u03b1) \u2194 noncompact_space \u03b1 :=\n\u27e8noncompact_space_of_ne_bot, @filter.cocompact.filter.ne_bot _ _\u27e9\n\nlemma not_compact_space_iff : \u00accompact_space \u03b1 \u2194 noncompact_space \u03b1 :=\n\u27e8\u03bb h\u2081, \u27e8\u03bb h\u2082, h\u2081 \u27e8h\u2082\u27e9\u27e9, \u03bb \u27e8h\u2081\u27e9 \u27e8h\u2082\u27e9, h\u2081 h\u2082\u27e9\n\ninstance : noncompact_space \u2124 :=\nnoncompact_space_of_ne_bot $ by simp only [filter.cocompact_eq_cofinite, filter.cofinite_ne_bot]\n\n/-- A compact discrete space is finite. -/\nnoncomputable\ndef fintype_of_compact_of_discrete [compact_space \u03b1] [discrete_topology \u03b1] :\n  fintype \u03b1 :=\nfintype_of_univ_finite $ compact_univ.finite_of_discrete\n\nlemma finite_cover_nhds_interior [compact_space \u03b1] {U : \u03b1 \u2192 set \u03b1} (hU : \u2200 x, U x \u2208 \ud835\udcdd x) :\n  \u2203 t : finset \u03b1, (\u22c3 x \u2208 t, interior (U x)) = univ :=\nlet \u27e8t, ht\u27e9 := compact_univ.elim_finite_subcover (\u03bb x, interior (U x)) (\u03bb x, is_open_interior)\n  (\u03bb x _, mem_Union.2 \u27e8x, mem_interior_iff_mem_nhds.2 (hU x)\u27e9)\nin \u27e8t, univ_subset_iff.1 ht\u27e9\n\nlemma finite_cover_nhds [compact_space \u03b1] {U : \u03b1 \u2192 set \u03b1} (hU : \u2200 x, U x \u2208 \ud835\udcdd x) :\n  \u2203 t : finset \u03b1, (\u22c3 x \u2208 t, U x) = univ :=\nlet \u27e8t, ht\u27e9 := finite_cover_nhds_interior hU in \u27e8t, univ_subset_iff.1 $ ht.symm.subset.trans $\n  Union\u2082_mono $ \u03bb x hx, interior_subset\u27e9\n\n/-- If `\u03b1` is a compact space, then a locally finite family of sets of `\u03b1` can have only finitely\nmany nonempty elements. -/\nlemma locally_finite.finite_nonempty_of_compact {\u03b9 : Type*} [compact_space \u03b1] {f : \u03b9 \u2192 set \u03b1}\n  (hf : locally_finite f) :\n  finite {i | (f i).nonempty} :=\nby simpa only [inter_univ]  using hf.finite_nonempty_inter_compact compact_univ\n\n/-- If `\u03b1` is a compact space, then a locally finite family of nonempty sets of `\u03b1` can have only\nfinitely many elements, `set.finite` version. -/\nlemma locally_finite.finite_of_compact {\u03b9 : Type*} [compact_space \u03b1] {f : \u03b9 \u2192 set \u03b1}\n  (hf : locally_finite f) (hne : \u2200 i, (f i).nonempty) :\n  finite (univ : set \u03b9) :=\nby simpa only [hne] using hf.finite_nonempty_of_compact\n\n/-- If `\u03b1` is a compact space, then a locally finite family of nonempty sets of `\u03b1` can have only\nfinitely many elements, `fintype` version. -/\nnoncomputable def locally_finite.fintype_of_compact {\u03b9 : Type*} [compact_space \u03b1] {f : \u03b9 \u2192 set \u03b1}\n  (hf : locally_finite f) (hne : \u2200 i, (f i).nonempty) :\n  fintype \u03b9 :=\nfintype_of_univ_finite (hf.finite_of_compact hne)\n\n/-- The comap of the cocompact filter on `\u03b2` by a continuous function `f : \u03b1 \u2192 \u03b2` is less than or\nequal to the cocompact filter on `\u03b1`.\nThis is a reformulation of the fact that images of compact sets are compact. -/\nlemma filter.comap_cocompact {f : \u03b1 \u2192 \u03b2} (hf : continuous f) :\n  (filter.cocompact \u03b2).comap f \u2264 filter.cocompact \u03b1 :=\nbegin\n  rw (filter.has_basis_cocompact.comap f).le_basis_iff filter.has_basis_cocompact,\n  intros t ht,\n  refine \u27e8f '' t, ht.image hf, _\u27e9,\n  simpa using t.subset_preimage_image f\nend\n\nlemma is_compact_range [compact_space \u03b1] {f : \u03b1 \u2192 \u03b2} (hf : continuous f) :\n  is_compact (range f) :=\nby rw \u2190 image_univ; exact compact_univ.image hf\n\n/-- If X is is_compact then pr\u2082 : X \u00d7 Y \u2192 Y is a closed map -/\ntheorem is_closed_proj_of_is_compact\n  {X : Type*} [topological_space X] [compact_space X]\n  {Y : Type*} [topological_space Y]  :\n  is_closed_map (prod.snd : X \u00d7 Y \u2192 Y) :=\nbegin\n  set \u03c0X := (prod.fst : X \u00d7 Y \u2192 X),\n  set \u03c0Y := (prod.snd : X \u00d7 Y \u2192 Y),\n  assume C (hC : is_closed C),\n  rw is_closed_iff_cluster_pt at hC \u22a2,\n  assume y (y_closure : cluster_pt y $ \ud835\udcdf (\u03c0Y '' C)),\n  have : ne_bot (map \u03c0X (comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C)),\n  { suffices : ne_bot (map \u03c0Y (comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C)),\n      by simpa only [map_ne_bot_iff],\n    convert y_closure,\n    calc map \u03c0Y (comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C) =\n       \ud835\udcdd y \u2293 map \u03c0Y (\ud835\udcdf C) : filter.push_pull' _ _ _\n      ... = \ud835\udcdd y \u2293 \ud835\udcdf (\u03c0Y '' C) : by rw map_principal },\n  resetI,\n  obtain \u27e8x, hx\u27e9 : \u2203 x, cluster_pt x (map \u03c0X (comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C)),\n    from cluster_point_of_compact _,\n  refine \u27e8\u27e8x, y\u27e9, _, by simp [\u03c0Y]\u27e9,\n  apply hC,\n  rw [cluster_pt, \u2190 filter.map_ne_bot_iff \u03c0X],\n  convert hx,\n  calc map \u03c0X (\ud835\udcdd (x, y) \u2293 \ud835\udcdf C)\n      = map \u03c0X (comap \u03c0X (\ud835\udcdd x) \u2293 comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C) : by rw [nhds_prod_eq, filter.prod]\n  ... = map \u03c0X (comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C \u2293 comap \u03c0X (\ud835\udcdd x)) : by ac_refl\n  ... = map \u03c0X (comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C) \u2293 \ud835\udcdd x            : by rw filter.push_pull\n  ... = \ud835\udcdd x \u2293 map \u03c0X (comap \u03c0Y (\ud835\udcdd y) \u2293 \ud835\udcdf C)            : by rw inf_comm\nend\n\nlemma exists_subset_nhd_of_compact_space [compact_space \u03b1] {\u03b9 : Type*} [nonempty \u03b9]\n  {V : \u03b9 \u2192 set \u03b1} (hV : directed (\u2287) V) (hV_closed : \u2200 i, is_closed (V i))\n  {U : set \u03b1} (hU : \u2200 x \u2208 \u22c2 i, V i, U \u2208 \ud835\udcdd x) : \u2203 i, V i \u2286 U :=\nexists_subset_nhd_of_compact' hV (\u03bb i, (hV_closed i).is_compact) hV_closed hU\n\n/-- If `f : \u03b1 \u2192 \u03b2` is an `inducing` map, then the image `f '' s` of a set `s` is compact if and only\nif the set `s` is closed. -/\nlemma inducing.is_compact_iff {f : \u03b1 \u2192 \u03b2} (hf : inducing f) {s : set \u03b1} :\n  is_compact (f '' s) \u2194 is_compact s :=\nbegin\n  refine \u27e8_, \u03bb hs, hs.image hf.continuous\u27e9,\n  introsI hs F F_ne_bot F_le,\n  obtain \u27e8_, \u27e8x, x_in : x \u2208 s, rfl\u27e9, hx : cluster_pt (f x) (map f F)\u27e9 :=\n    hs (calc map f F \u2264 map f (\ud835\udcdf s) : map_mono F_le\n                ... = \ud835\udcdf (f '' s) : map_principal),\n  use [x, x_in],\n  suffices : (map f (\ud835\udcdd x \u2293 F)).ne_bot, by simpa [filter.map_ne_bot_iff],\n  rwa calc map f (\ud835\udcdd x \u2293 F) = map f ((comap f $ \ud835\udcdd $ f x) \u2293 F) : by rw hf.nhds_eq_comap\n                        ... = \ud835\udcdd (f x) \u2293 map f F : filter.push_pull' _ _ _\nend\n\n/-- If `f : \u03b1 \u2192 \u03b2` is an `embedding` (or more generally, an `inducing` map, see\n`inducing.is_compact_iff`), then the image `f '' s` of a set `s` is compact if and only if the set\n`s` is closed. -/\nlemma embedding.is_compact_iff_is_compact_image {f : \u03b1 \u2192 \u03b2} (hf : embedding f) :\n  is_compact s \u2194 is_compact (f '' s) :=\nhf.to_inducing.is_compact_iff.symm\n\n/-- The preimage of a compact set under a closed embedding is a compact set. -/\nlemma closed_embedding.is_compact_preimage {f : \u03b1 \u2192 \u03b2} (hf : closed_embedding f) {K : set \u03b2}\n  (hK : is_compact K) : is_compact (f \u207b\u00b9' K) :=\nbegin\n  replace hK := hK.inter_right hf.closed_range,\n  rwa [\u2190 hf.to_inducing.is_compact_iff, image_preimage_eq_inter_range]\nend\n\n/-- A closed embedding is proper, ie, inverse images of compact sets are contained in compacts.\nMoreover, the preimage of a compact set is compact, see `closed_embedding.is_compact_preimage`. -/\nlemma closed_embedding.tendsto_cocompact\n  {f : \u03b1 \u2192 \u03b2} (hf : closed_embedding f) : tendsto f (filter.cocompact \u03b1) (filter.cocompact \u03b2) :=\nfilter.has_basis_cocompact.tendsto_right_iff.mpr $ \u03bb K hK,\n  (hf.is_compact_preimage hK).compl_mem_cocompact\n\nlemma compact_iff_compact_in_subtype {p : \u03b1 \u2192 Prop} {s : set {a // p a}} :\n  is_compact s \u2194 is_compact ((coe : _ \u2192 \u03b1) '' s) :=\nembedding_subtype_coe.is_compact_iff_is_compact_image\n\nlemma is_compact_iff_is_compact_univ {s : set \u03b1} : is_compact s \u2194 is_compact (univ : set s) :=\nby rw [compact_iff_compact_in_subtype, image_univ, subtype.range_coe]; refl\n\nlemma is_compact_iff_compact_space {s : set \u03b1} : is_compact s \u2194 compact_space s :=\nis_compact_iff_is_compact_univ.trans \u27e8\u03bb h, \u27e8h\u27e9, @compact_space.compact_univ _ _\u27e9\n\nprotected lemma closed_embedding.noncompact_space [noncompact_space \u03b1] {f : \u03b1 \u2192 \u03b2}\n  (hf : closed_embedding f) : noncompact_space \u03b2 :=\nnoncompact_space_of_ne_bot hf.tendsto_cocompact.ne_bot\n\nprotected lemma closed_embedding.compact_space [h : compact_space \u03b2] {f : \u03b1 \u2192 \u03b2}\n  (hf : closed_embedding f) : compact_space \u03b1 :=\nby { unfreezingI { contrapose! h, rw not_compact_space_iff at h \u22a2 }, exact hf.noncompact_space }\n\nlemma is_compact.prod {s : set \u03b1} {t : set \u03b2} (hs : is_compact s) (ht : is_compact t) :\n  is_compact (s \u00d7\u02e2 t) :=\nbegin\n  rw is_compact_iff_ultrafilter_le_nhds at hs ht \u22a2,\n  intros f hfs,\n  rw le_principal_iff at hfs,\n  obtain \u27e8a : \u03b1, sa : a \u2208 s, ha : map prod.fst \u2191f \u2264 \ud835\udcdd a\u27e9 :=\n    hs (f.map prod.fst) (le_principal_iff.2 $ mem_map.2 $ mem_of_superset hfs (\u03bb x, and.left)),\n  obtain \u27e8b : \u03b2, tb : b \u2208 t, hb : map prod.snd \u2191f \u2264 \ud835\udcdd b\u27e9 :=\n    ht (f.map prod.snd) (le_principal_iff.2 $ mem_map.2 $\n      mem_of_superset hfs (\u03bb x, and.right)),\n  rw map_le_iff_le_comap at ha hb,\n  refine \u27e8\u27e8a, b\u27e9, \u27e8sa, tb\u27e9, _\u27e9,\n  rw nhds_prod_eq, exact le_inf ha hb\nend\n\n/-- Finite topological spaces are compact. -/\n@[priority 100] instance fintype.compact_space [fintype \u03b1] : compact_space \u03b1 :=\n{ compact_univ := finite_univ.is_compact }\n\n/-- The product of two compact spaces is compact. -/\ninstance [compact_space \u03b1] [compact_space \u03b2] : compact_space (\u03b1 \u00d7 \u03b2) :=\n\u27e8by { rw \u2190 univ_prod_univ, exact compact_univ.prod compact_univ }\u27e9\n\n/-- The disjoint union of two compact spaces is compact. -/\ninstance [compact_space \u03b1] [compact_space \u03b2] : compact_space (\u03b1 \u2295 \u03b2) :=\n\u27e8begin\n  rw \u2190 range_inl_union_range_inr,\n  exact (is_compact_range continuous_inl).union (is_compact_range continuous_inr)\nend\u27e9\n\ninstance [fintype \u03b9] [\u03a0 i, topological_space (\u03c0 i)] [\u2200 i, compact_space (\u03c0 i)] :\n  compact_space (\u03a3 i, \u03c0 i) :=\nbegin\n  refine \u27e8_\u27e9,\n  rw sigma.univ,\n  exact compact_Union (\u03bb i, is_compact_range continuous_sigma_mk),\nend\n\n/-- The coproduct of the cocompact filters on two topological spaces is the cocompact filter on\ntheir product. -/\nlemma filter.coprod_cocompact :\n  (filter.cocompact \u03b1).coprod (filter.cocompact \u03b2) = filter.cocompact (\u03b1 \u00d7 \u03b2) :=\nbegin\n  ext S,\n  simp only [mem_coprod_iff, exists_prop, mem_comap, filter.mem_cocompact],\n  split,\n  { rintro \u27e8\u27e8A, \u27e8t, ht, hAt\u27e9, hAS\u27e9, B, \u27e8t', ht', hBt'\u27e9, hBS\u27e9,\n    refine \u27e8t \u00d7\u02e2 t', ht.prod ht', _\u27e9,\n    refine subset.trans _ (union_subset hAS hBS),\n    rw compl_subset_comm at \u22a2 hAt hBt',\n    refine subset.trans _ (set.prod_mono hAt hBt'),\n    intros x,\n    simp only [compl_union, mem_inter_eq, mem_prod, mem_preimage, mem_compl_eq],\n    tauto },\n  { rintros \u27e8t, ht, htS\u27e9,\n    refine \u27e8\u27e8(prod.fst '' t)\u1d9c, _, _\u27e9, \u27e8(prod.snd '' t)\u1d9c, _, _\u27e9\u27e9,\n    { exact \u27e8prod.fst '' t, ht.image continuous_fst, subset.rfl\u27e9 },\n    { rw preimage_compl,\n      rw compl_subset_comm at \u22a2 htS,\n      exact subset.trans htS (subset_preimage_image prod.fst _) },\n    { exact \u27e8prod.snd '' t, ht.image continuous_snd, subset.rfl\u27e9 },\n    { rw preimage_compl,\n      rw compl_subset_comm at \u22a2 htS,\n      exact subset.trans htS (subset_preimage_image prod.snd _) } }\nend\n\nlemma prod.noncompact_space_iff :\n  noncompact_space (\u03b1 \u00d7 \u03b2) \u2194 noncompact_space \u03b1 \u2227 nonempty \u03b2 \u2228 nonempty \u03b1 \u2227 noncompact_space \u03b2 :=\nby simp [\u2190 filter.cocompact_ne_bot_iff, \u2190 filter.coprod_cocompact, filter.coprod_ne_bot_iff]\n\n@[priority 100] -- See Note [lower instance priority]\ninstance prod.noncompact_space_left [noncompact_space \u03b1] [nonempty \u03b2] : noncompact_space (\u03b1 \u00d7 \u03b2) :=\nprod.noncompact_space_iff.2 (or.inl \u27e8\u2039_\u203a, \u2039_\u203a\u27e9)\n\n@[priority 100] -- See Note [lower instance priority]\ninstance prod.noncompact_space_right [nonempty \u03b1] [noncompact_space \u03b2] : noncompact_space (\u03b1 \u00d7 \u03b2) :=\nprod.noncompact_space_iff.2 (or.inr \u27e8\u2039_\u203a, \u2039_\u203a\u27e9)\n\nsection tychonoff\nvariables [\u03a0 i, topological_space (\u03c0 i)]\n\n/-- **Tychonoff's theorem** -/\nlemma is_compact_pi_infinite {s : \u03a0 i, set (\u03c0 i)} :\n  (\u2200 i, is_compact (s i)) \u2192 is_compact {x : \u03a0 i, \u03c0 i | \u2200 i, x i \u2208 s i} :=\nbegin\n  simp only [is_compact_iff_ultrafilter_le_nhds, nhds_pi, filter.pi, exists_prop, mem_set_of_eq,\n    le_infi_iff, le_principal_iff],\n  intros h f hfs,\n  have : \u2200 i:\u03b9, \u2203 a, a \u2208 s i \u2227 tendsto (\u03bbx:\u03a0i:\u03b9, \u03c0 i, x i) f (\ud835\udcdd a),\n  { refine \u03bb i, h i (f.map _) (mem_map.2 _),\n    exact mem_of_superset hfs (\u03bb x hx, hx i) },\n  choose a ha,\n  exact \u27e8a, assume i, (ha i).left, assume i, (ha i).right.le_comap\u27e9\nend\n\n/-- A version of Tychonoff's theorem that uses `set.pi`. -/\nlemma is_compact_univ_pi {s : \u03a0 i, set (\u03c0 i)} (h : \u2200 i, is_compact (s i)) :\n  is_compact (pi univ s) :=\nby { convert is_compact_pi_infinite h, simp only [\u2190 mem_univ_pi, set_of_mem_eq] }\n\ninstance pi.compact_space [\u2200 i, compact_space (\u03c0 i)] : compact_space (\u03a0i, \u03c0 i) :=\n\u27e8by { rw [\u2190 pi_univ univ], exact is_compact_univ_pi (\u03bb i, compact_univ) }\u27e9\n\n/-- Product of compact sets is compact -/\nlemma filter.Coprod_cocompact {\u03b4 : Type*} {\u03ba : \u03b4 \u2192 Type*} [\u03a0 d, topological_space (\u03ba d)] :\n  filter.Coprod (\u03bb d, filter.cocompact (\u03ba d)) = filter.cocompact (\u03a0 d, \u03ba d) :=\nbegin\n  ext S, rcases compl_surjective S with \u27e8S, rfl\u27e9,\n  simp_rw [compl_mem_Coprod_iff, filter.mem_cocompact, compl_subset_compl],\n  split,\n  { rintro \u27e8t, H, hSt\u27e9, choose K hKc htK using H,\n    exact \u27e8set.pi univ K, is_compact_univ_pi hKc, hSt.trans $ pi_mono $ \u03bb i _, htK i\u27e9 },\n  { rintro \u27e8K, hKc, hSK\u27e9,\n    exact \u27e8\u03bb i, function.eval i '' K, \u03bb i, \u27e8_, hKc.image (continuous_apply i), subset.rfl\u27e9,\n      hSK.trans $ subset_pi_eval_image _ _\u27e9 }\nend\n\nend tychonoff\n\ninstance quot.compact_space {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [compact_space \u03b1] :\n  compact_space (quot r) :=\n\u27e8by { rw \u2190 range_quot_mk, exact is_compact_range continuous_quot_mk }\u27e9\n\ninstance quotient.compact_space {s : setoid \u03b1} [compact_space \u03b1] :\n  compact_space (quotient s) :=\nquot.compact_space\n\n/-- There are various definitions of \"locally compact space\" in the literature, which agree for\nHausdorff spaces but not in general. This one is the precise condition on X needed for the\nevaluation `map C(X, Y) \u00d7 X \u2192 Y` to be continuous for all `Y` when `C(X, Y)` is given the\ncompact-open topology. -/\nclass locally_compact_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(local_compact_nhds : \u2200 (x : \u03b1) (n \u2208 \ud835\udcdd x), \u2203 s \u2208 \ud835\udcdd x, s \u2286 n \u2227 is_compact s)\n\nlemma compact_basis_nhds [locally_compact_space \u03b1] (x : \u03b1) :\n  (\ud835\udcdd x).has_basis (\u03bb s, s \u2208 \ud835\udcdd x \u2227 is_compact s) (\u03bb s, s) :=\nhas_basis_self.2 $ by simpa only [and_comm] using locally_compact_space.local_compact_nhds x\n\nlemma local_compact_nhds [locally_compact_space \u03b1] {x : \u03b1} {n : set \u03b1} (h : n \u2208 \ud835\udcdd x) :\n  \u2203 s \u2208 \ud835\udcdd x, s \u2286 n \u2227 is_compact s :=\nlocally_compact_space.local_compact_nhds _ _ h\n\nlemma locally_compact_space_of_has_basis {\u03b9 : \u03b1 \u2192 Type*} {p : \u03a0 x, \u03b9 x \u2192 Prop}\n  {s : \u03a0 x, \u03b9 x \u2192 set \u03b1} (h : \u2200 x, (\ud835\udcdd x).has_basis (p x) (s x))\n  (hc : \u2200 x i, p x i \u2192 is_compact (s x i)) :\n  locally_compact_space \u03b1 :=\n\u27e8\u03bb x t ht, let \u27e8i, hp, ht\u27e9 := (h x).mem_iff.1 ht in \u27e8s x i, (h x).mem_of_mem hp, ht, hc x i hp\u27e9\u27e9\n\ninstance locally_compact_space.prod (\u03b1 : Type*) (\u03b2 : Type*) [topological_space \u03b1]\n  [topological_space \u03b2] [locally_compact_space \u03b1] [locally_compact_space \u03b2] :\n  locally_compact_space (\u03b1 \u00d7 \u03b2) :=\nhave _ := \u03bb x : \u03b1 \u00d7 \u03b2, (compact_basis_nhds x.1).prod_nhds' (compact_basis_nhds x.2),\nlocally_compact_space_of_has_basis this $ \u03bb x s \u27e8\u27e8_, h\u2081\u27e9, _, h\u2082\u27e9, h\u2081.prod h\u2082\n\n/-- A reformulation of the definition of locally compact space: In a locally compact space,\n  every open set containing `x` has a compact subset containing `x` in its interior. -/\nlemma exists_compact_subset [locally_compact_space \u03b1] {x : \u03b1} {U : set \u03b1}\n  (hU : is_open U) (hx : x \u2208 U) : \u2203 (K : set \u03b1), is_compact K \u2227 x \u2208 interior K \u2227 K \u2286 U :=\nbegin\n  rcases locally_compact_space.local_compact_nhds x U (hU.mem_nhds hx) with \u27e8K, h1K, h2K, h3K\u27e9,\n  exact \u27e8K, h3K, mem_interior_iff_mem_nhds.2 h1K, h2K\u27e9,\nend\n\n/-- In a locally compact space every point has a compact neighborhood. -/\nlemma exists_compact_mem_nhds [locally_compact_space \u03b1] (x : \u03b1) :\n  \u2203 K, is_compact K \u2227 K \u2208 \ud835\udcdd x :=\nlet \u27e8K, hKc, hx, H\u27e9 := exists_compact_subset is_open_univ (mem_univ x)\nin \u27e8K, hKc, mem_interior_iff_mem_nhds.1 hx\u27e9\n\n/-- In a locally compact space, every compact set is contained in the interior of a compact set. -/\nlemma exists_compact_superset [locally_compact_space \u03b1] {K : set \u03b1} (hK : is_compact K) :\n  \u2203 K', is_compact K' \u2227 K \u2286 interior K' :=\nbegin\n  choose U hUc hxU using \u03bb x : K, exists_compact_mem_nhds (x : \u03b1),\n  have : K \u2286 \u22c3 x, interior (U x),\n    from \u03bb x hx, mem_Union.2 \u27e8\u27e8x, hx\u27e9, mem_interior_iff_mem_nhds.2 (hxU _)\u27e9,\n  rcases hK.elim_finite_subcover _ _ this with \u27e8t, ht\u27e9,\n  { refine \u27e8_, t.compact_bUnion (\u03bb x _, hUc x), \u03bb x hx, _\u27e9,\n    rcases mem_Union\u2082.1 (ht hx) with \u27e8y, hyt, hy\u27e9,\n    exact interior_mono (subset_bUnion_of_mem hyt) hy },\n  { exact \u03bb _, is_open_interior }\nend\n\nprotected lemma closed_embedding.locally_compact_space [locally_compact_space \u03b2] {f : \u03b1 \u2192 \u03b2}\n  (hf : closed_embedding f) : locally_compact_space \u03b1 :=\nbegin\n  have : \u2200 x : \u03b1, (\ud835\udcdd x).has_basis (\u03bb s, s \u2208 \ud835\udcdd (f x) \u2227 is_compact s) (\u03bb s, f \u207b\u00b9' s),\n  { intro x,\n    rw hf.to_embedding.to_inducing.nhds_eq_comap,\n    exact (compact_basis_nhds _).comap _ },\n  exact locally_compact_space_of_has_basis this (\u03bb x s hs, hf.is_compact_preimage hs.2)\nend\n\nprotected lemma is_closed.locally_compact_space [locally_compact_space \u03b1] {s : set \u03b1}\n  (hs : is_closed s) : locally_compact_space s :=\n(closed_embedding_subtype_coe hs).locally_compact_space\n\nprotected lemma open_embedding.locally_compact_space [locally_compact_space \u03b2] {f : \u03b1 \u2192 \u03b2}\n  (hf : open_embedding f) : locally_compact_space \u03b1 :=\nbegin\n  have : \u2200 x : \u03b1, (\ud835\udcdd x).has_basis (\u03bb s, (s \u2208 \ud835\udcdd (f x) \u2227 is_compact s) \u2227 s \u2286 range f) (\u03bb s, f \u207b\u00b9' s),\n  { intro x,\n    rw hf.to_embedding.to_inducing.nhds_eq_comap,\n    exact ((compact_basis_nhds _).restrict_subset $\n      hf.open_range.mem_nhds $ mem_range_self _).comap _ },\n  refine locally_compact_space_of_has_basis this (\u03bb x s hs, _),\n  rw [\u2190 hf.to_inducing.is_compact_iff, image_preimage_eq_of_subset hs.2],\n  exact hs.1.2\nend\n\nprotected lemma is_open.locally_compact_space [locally_compact_space \u03b1] {s : set \u03b1}\n  (hs : is_open s) : locally_compact_space s :=\nhs.open_embedding_subtype_coe.locally_compact_space\n\nlemma ultrafilter.le_nhds_Lim [compact_space \u03b1] (F : ultrafilter \u03b1) :\n  \u2191F \u2264 \ud835\udcdd (@Lim _ _ (F : filter \u03b1).nonempty_of_ne_bot F) :=\nbegin\n  rcases compact_univ.ultrafilter_le_nhds F (by simp) with \u27e8x, -, h\u27e9,\n  exact le_nhds_Lim \u27e8x,h\u27e9,\nend\n\ntheorem is_closed.exists_minimal_nonempty_closed_subset [compact_space \u03b1]\n  {S : set \u03b1} (hS : is_closed S) (hne : S.nonempty) :\n  \u2203 (V : set \u03b1),\n    V \u2286 S \u2227 V.nonempty \u2227 is_closed V \u2227\n      (\u2200 (V' : set \u03b1), V' \u2286 V \u2192 V'.nonempty \u2192 is_closed V' \u2192 V' = V) :=\nbegin\n  let opens := {U : set \u03b1 | S\u1d9c \u2286 U \u2227 is_open U \u2227 U\u1d9c.nonempty},\n  obtain \u27e8U, \u27e8Uc, Uo, Ucne\u27e9, h\u27e9 := zorn_subset opens (\u03bb c hc hz, begin\n    by_cases hcne : c.nonempty,\n    { obtain \u27e8U\u2080, hU\u2080\u27e9 := hcne,\n      haveI : nonempty {U // U \u2208 c} := \u27e8\u27e8U\u2080, hU\u2080\u27e9\u27e9,\n      obtain \u27e8U\u2080compl, U\u2080opn, U\u2080ne\u27e9 := hc hU\u2080,\n      use \u22c3\u2080 c,\n      refine \u27e8\u27e8_, _, _\u27e9, \u03bb U hU a ha, \u27e8U, hU, ha\u27e9\u27e9,\n      { exact \u03bb a ha, \u27e8U\u2080, hU\u2080, U\u2080compl ha\u27e9 },\n      { exact is_open_sUnion (\u03bb _ h, (hc h).2.1) },\n      { convert_to (\u22c2(U : {U // U \u2208 c}), U.1\u1d9c).nonempty,\n        { ext,\n          simp only [not_exists, exists_prop, not_and, set.mem_Inter, subtype.forall,\n            set.mem_set_of_eq, set.mem_compl_eq, subtype.val_eq_coe],\n          refl, },\n        apply is_compact.nonempty_Inter_of_directed_nonempty_compact_closed,\n        { rintros \u27e8U, hU\u27e9 \u27e8U', hU'\u27e9,\n          obtain \u27e8V, hVc, hVU, hVU'\u27e9 := hz.directed_on U hU U' hU',\n          exact \u27e8\u27e8V, hVc\u27e9, set.compl_subset_compl.mpr hVU, set.compl_subset_compl.mpr hVU'\u27e9, },\n        { exact \u03bb U, (hc U.2).2.2, },\n        { exact \u03bb U, (is_closed_compl_iff.mpr (hc U.2).2.1).is_compact, },\n        { exact \u03bb U, (is_closed_compl_iff.mpr (hc U.2).2.1), } } },\n    { use S\u1d9c,\n      refine \u27e8\u27e8set.subset.refl _, is_open_compl_iff.mpr hS, _\u27e9, \u03bb U Uc, (hcne \u27e8U, Uc\u27e9).elim\u27e9,\n      rw compl_compl,\n      exact hne, }\n  end),\n  refine \u27e8U\u1d9c, set.compl_subset_comm.mp Uc, Ucne, is_closed_compl_iff.mpr Uo, _\u27e9,\n  intros V' V'sub V'ne V'cls,\n  have : V'\u1d9c = U,\n  { refine h V'\u1d9c \u27e8_, is_open_compl_iff.mpr V'cls, _\u27e9 (set.subset_compl_comm.mp V'sub),\n    exact set.subset.trans Uc (set.subset_compl_comm.mp V'sub),\n    simp only [compl_compl, V'ne], },\n  rw [\u2190this, compl_compl],\nend\n\n/-- A \u03c3-compact space is a space that is the union of a countable collection of compact subspaces.\n  Note that a locally compact separable T\u2082 space need not be \u03c3-compact.\n  The sequence can be extracted using `topological_space.compact_covering`. -/\nclass sigma_compact_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(exists_compact_covering : \u2203 K : \u2115 \u2192 set \u03b1, (\u2200 n, is_compact (K n)) \u2227 (\u22c3 n, K n) = univ)\n\n@[priority 200] -- see Note [lower instance priority]\ninstance compact_space.sigma_compact [compact_space \u03b1] : sigma_compact_space \u03b1 :=\n\u27e8\u27e8\u03bb _, univ, \u03bb _, compact_univ, Union_const _\u27e9\u27e9\n\nlemma sigma_compact_space.of_countable (S : set (set \u03b1)) (Hc : countable S)\n  (Hcomp : \u2200 s \u2208 S, is_compact s) (HU : \u22c3\u2080 S = univ) : sigma_compact_space \u03b1 :=\n\u27e8(exists_seq_cover_iff_countable \u27e8_, is_compact_empty\u27e9).2 \u27e8S, Hc, Hcomp, HU\u27e9\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance sigma_compact_space_of_locally_compact_second_countable [locally_compact_space \u03b1]\n  [second_countable_topology \u03b1] : sigma_compact_space \u03b1 :=\nbegin\n  choose K hKc hxK using \u03bb x : \u03b1, exists_compact_mem_nhds x,\n  rcases countable_cover_nhds hxK with \u27e8s, hsc, hsU\u27e9,\n  refine sigma_compact_space.of_countable _ (hsc.image K) (ball_image_iff.2 $ \u03bb x _, hKc x) _,\n  rwa sUnion_image\nend\n\nvariables (\u03b1) [sigma_compact_space \u03b1]\nopen sigma_compact_space\n\n/-- A choice of compact covering for a `\u03c3`-compact space, chosen to be monotone. -/\ndef compact_covering : \u2115 \u2192 set \u03b1 :=\naccumulate exists_compact_covering.some\n\nlemma is_compact_compact_covering (n : \u2115) : is_compact (compact_covering \u03b1 n) :=\ncompact_accumulate (classical.some_spec sigma_compact_space.exists_compact_covering).1 n\n\nlemma Union_compact_covering : (\u22c3 n, compact_covering \u03b1 n) = univ :=\nbegin\n  rw [compact_covering, Union_accumulate],\n  exact (classical.some_spec sigma_compact_space.exists_compact_covering).2\nend\n\n@[mono] lemma compact_covering_subset \u2983m n : \u2115\u2984 (h : m \u2264 n) :\n  compact_covering \u03b1 m \u2286 compact_covering \u03b1 n :=\nmonotone_accumulate h\n\nvariable {\u03b1}\n\nlemma exists_mem_compact_covering (x : \u03b1) : \u2203 n, x \u2208 compact_covering \u03b1 n :=\nUnion_eq_univ_iff.mp (Union_compact_covering \u03b1) x\n\n/-- If `\u03b1` is a `\u03c3`-compact space, then a locally finite family of nonempty sets of `\u03b1` can have\nonly countably many elements, `set.countable` version. -/\nprotected lemma locally_finite.countable_univ {\u03b9 : Type*} {f : \u03b9 \u2192 set \u03b1} (hf : locally_finite f)\n  (hne : \u2200 i, (f i).nonempty) :\n  countable (univ : set \u03b9) :=\nbegin\n  have := \u03bb n, hf.finite_nonempty_inter_compact (is_compact_compact_covering \u03b1 n),\n  refine (countable_Union (\u03bb n, (this n).countable)).mono (\u03bb i hi, _),\n  rcases hne i with \u27e8x, hx\u27e9,\n  rcases Union_eq_univ_iff.1 (Union_compact_covering \u03b1) x with \u27e8n, hn\u27e9,\n  exact mem_Union.2 \u27e8n, x, hx, hn\u27e9\nend\n\n/-- If `f : \u03b9 \u2192 set \u03b1` is a locally finite covering of a \u03c3-compact topological space by nonempty\nsets, then the index type `\u03b9` is encodable. -/\nprotected noncomputable def locally_finite.encodable {\u03b9 : Type*} {f : \u03b9 \u2192 set \u03b1}\n  (hf : locally_finite f) (hne : \u2200 i, (f i).nonempty) : encodable \u03b9 :=\n@encodable.of_equiv _ _ (hf.countable_univ hne).to_encodable (equiv.set.univ _).symm\n\n/-- In a topological space with sigma compact topology, if `f` is a function that sends each point\n`x` of a closed set `s` to a neighborhood of `x` within `s`, then for some countable set `t \u2286 s`,\nthe neighborhoods `f x`, `x \u2208 t`, cover the whole set `s`. -/\nlemma countable_cover_nhds_within_of_sigma_compact {f : \u03b1 \u2192 set \u03b1} {s : set \u03b1} (hs : is_closed s)\n  (hf : \u2200 x \u2208 s, f x \u2208 \ud835\udcdd[s] x) : \u2203 t \u2286 s, countable t \u2227 s \u2286 \u22c3 x \u2208 t, f x :=\nbegin\n  simp only [nhds_within, mem_inf_principal] at hf,\n  choose t ht hsub using \u03bb n, ((is_compact_compact_covering \u03b1 n).inter_right hs).elim_nhds_subcover\n    _ (\u03bb x hx, hf x hx.right),\n  refine \u27e8\u22c3 n, (t n : set \u03b1), Union_subset $ \u03bb n x hx, (ht n x hx).2,\n    countable_Union $ \u03bb n, (t n).countable_to_set, \u03bb x hx, mem_Union\u2082.2 _\u27e9,\n  rcases exists_mem_compact_covering x with \u27e8n, hn\u27e9,\n  rcases mem_Union\u2082.1 (hsub n \u27e8hn, hx\u27e9) with \u27e8y, hyt : y \u2208 t n, hyf : x \u2208 s \u2192 x \u2208 f y\u27e9,\n  exact \u27e8y, mem_Union.2 \u27e8n, hyt\u27e9, hyf hx\u27e9\nend\n\n/-- In a topological space with sigma compact topology, if `f` is a function that sends each\npoint `x` to a neighborhood of `x`, then for some countable set `s`, the neighborhoods `f x`,\n`x \u2208 s`, cover the whole space. -/\nlemma countable_cover_nhds_of_sigma_compact {f : \u03b1 \u2192 set \u03b1}\n  (hf : \u2200 x, f x \u2208 \ud835\udcdd x) : \u2203 s : set \u03b1, countable s \u2227 (\u22c3 x \u2208 s, f x) = univ :=\nbegin\n  simp only [\u2190 nhds_within_univ] at hf,\n  rcases countable_cover_nhds_within_of_sigma_compact is_closed_univ (\u03bb x _, hf x)\n    with \u27e8s, -, hsc, hsU\u27e9,\n  exact \u27e8s, hsc, univ_subset_iff.1 hsU\u27e9\nend\n\nend compact\n\n/-- An [exhaustion by compact sets](https://en.wikipedia.org/wiki/Exhaustion_by_compact_sets) of a\ntopological space is a sequence of compact sets `K n` such that `K n \u2286 interior (K (n + 1))` and\n`(\u22c3 n, K n) = univ`.\n\nIf `X` is a locally compact sigma compact space, then `compact_exhaustion.choice X` provides\na choice of an exhaustion by compact sets. This choice is also available as\n`(default : compact_exhaustion X)`. -/\nstructure compact_exhaustion (X : Type*) [topological_space X] :=\n(to_fun : \u2115 \u2192 set X)\n(is_compact' : \u2200 n, is_compact (to_fun n))\n(subset_interior_succ' : \u2200 n, to_fun n \u2286 interior (to_fun (n + 1)))\n(Union_eq' : (\u22c3 n, to_fun n) = univ)\n\nnamespace compact_exhaustion\n\ninstance : has_coe_to_fun (compact_exhaustion \u03b1) (\u03bb _, \u2115 \u2192 set \u03b1) := \u27e8to_fun\u27e9\n\nvariables {\u03b1} (K : compact_exhaustion \u03b1)\n\nprotected lemma is_compact (n : \u2115) : is_compact (K n) := K.is_compact' n\n\nlemma subset_interior_succ (n : \u2115) : K n \u2286 interior (K (n + 1)) :=\nK.subset_interior_succ' n\n\nlemma subset_succ (n : \u2115) : K n \u2286 K (n + 1) :=\nsubset.trans (K.subset_interior_succ n) interior_subset\n\n@[mono] protected lemma subset \u2983m n : \u2115\u2984 (h : m \u2264 n) : K m \u2286 K n :=\nshow K m \u2264 K n, from monotone_nat_of_le_succ K.subset_succ h\n\nlemma subset_interior \u2983m n : \u2115\u2984 (h : m < n) : K m \u2286 interior (K n) :=\nsubset.trans (K.subset_interior_succ m) $ interior_mono $ K.subset h\n\nlemma Union_eq : (\u22c3 n, K n) = univ := K.Union_eq'\n\nlemma exists_mem (x : \u03b1) : \u2203 n, x \u2208 K n := Union_eq_univ_iff.1 K.Union_eq x\n\n/-- The minimal `n` such that `x \u2208 K n`. -/\nprotected noncomputable def find (x : \u03b1) : \u2115 := nat.find (K.exists_mem x)\n\nlemma mem_find (x : \u03b1) : x \u2208 K (K.find x) := nat.find_spec (K.exists_mem x)\n\nlemma mem_iff_find_le {x : \u03b1} {n : \u2115} : x \u2208 K n \u2194 K.find x \u2264 n :=\n\u27e8\u03bb h, nat.find_min' (K.exists_mem x) h, \u03bb h, K.subset h $ K.mem_find x\u27e9\n\n/-- Prepend the empty set to a compact exhaustion `K n`. -/\ndef shiftr : compact_exhaustion \u03b1 :=\n{ to_fun := \u03bb n, nat.cases_on n \u2205 K,\n  is_compact' := \u03bb n, nat.cases_on n is_compact_empty K.is_compact,\n  subset_interior_succ' := \u03bb n, nat.cases_on n (empty_subset _) K.subset_interior_succ,\n  Union_eq' := Union_eq_univ_iff.2 $ \u03bb x, \u27e8K.find x + 1, K.mem_find x\u27e9 }\n\n@[simp] lemma find_shiftr (x : \u03b1) : K.shiftr.find x = K.find x + 1 :=\nnat.find_comp_succ _ _ (not_mem_empty _)\n\nlemma mem_diff_shiftr_find (x : \u03b1) : x \u2208 K.shiftr (K.find x + 1) \\ K.shiftr (K.find x) :=\n\u27e8K.mem_find _, mt K.shiftr.mem_iff_find_le.1 $\n  by simp only [find_shiftr, not_le, nat.lt_succ_self]\u27e9\n\n/-- A choice of an\n[exhaustion by compact sets](https://en.wikipedia.org/wiki/Exhaustion_by_compact_sets)\nof a locally compact sigma compact space. -/\nnoncomputable def choice (X : Type*) [topological_space X] [locally_compact_space X]\n  [sigma_compact_space X] : compact_exhaustion X :=\nbegin\n  apply classical.choice,\n  let K : \u2115 \u2192 {s : set X // is_compact s} :=\n    \u03bb n, nat.rec_on n \u27e8\u2205, is_compact_empty\u27e9\n      (\u03bb n s, \u27e8(exists_compact_superset s.2).some \u222a compact_covering X n,\n        (exists_compact_superset s.2).some_spec.1.union (is_compact_compact_covering _ _)\u27e9),\n  refine \u27e8\u27e8\u03bb n, K n, \u03bb n, (K n).2, \u03bb n, _, _\u27e9\u27e9,\n  { exact subset.trans (exists_compact_superset (K n).2).some_spec.2\n      (interior_mono $ subset_union_left _ _) },\n  { refine univ_subset_iff.1 (Union_compact_covering X \u25b8 _),\n    exact Union_mono' (\u03bb n, \u27e8n + 1, subset_union_right _ _\u27e9) }\nend\n\nnoncomputable instance [locally_compact_space \u03b1] [sigma_compact_space \u03b1] :\n  inhabited (compact_exhaustion \u03b1) :=\n\u27e8compact_exhaustion.choice \u03b1\u27e9\n\nend compact_exhaustion\n\nsection clopen\n\n/-- A set is clopen if it is both open and closed. -/\ndef is_clopen (s : set \u03b1) : Prop :=\nis_open s \u2227 is_closed s\n\nprotected lemma is_clopen.is_open (hs : is_clopen s) : is_open s := hs.1\nprotected lemma is_clopen.is_closed (hs : is_clopen s) : is_closed s := hs.2\n\nlemma is_clopen_iff_frontier_eq_empty {s : set \u03b1} : is_clopen s \u2194 frontier s = \u2205 :=\nbegin\n  rw [is_clopen, \u2190 closure_eq_iff_is_closed, \u2190 interior_eq_iff_open, frontier, diff_eq_empty],\n  refine \u27e8\u03bb h, (h.2.trans h.1.symm).subset, \u03bb h, _\u27e9,\n  exact \u27e8interior_subset.antisymm (subset_closure.trans h),\n    (h.trans interior_subset).antisymm subset_closure\u27e9\nend\n\nalias is_clopen_iff_frontier_eq_empty \u2194 is_clopen.frontier_eq _\n\ntheorem is_clopen.union {s t : set \u03b1} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s \u222a t) :=\n\u27e8hs.1.union ht.1, hs.2.union ht.2\u27e9\n\ntheorem is_clopen.inter {s t : set \u03b1} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s \u2229 t) :=\n\u27e8hs.1.inter ht.1, hs.2.inter ht.2\u27e9\n\n@[simp] theorem is_clopen_empty : is_clopen (\u2205 : set \u03b1) :=\n\u27e8is_open_empty, is_closed_empty\u27e9\n\n@[simp] theorem is_clopen_univ : is_clopen (univ : set \u03b1) :=\n\u27e8is_open_univ, is_closed_univ\u27e9\n\ntheorem is_clopen.compl {s : set \u03b1} (hs : is_clopen s) : is_clopen s\u1d9c :=\n\u27e8hs.2.is_open_compl, hs.1.is_closed_compl\u27e9\n\n@[simp] theorem is_clopen_compl_iff {s : set \u03b1} : is_clopen s\u1d9c \u2194 is_clopen s :=\n\u27e8\u03bb h, compl_compl s \u25b8 is_clopen.compl h, is_clopen.compl\u27e9\n\ntheorem is_clopen.diff {s t : set \u03b1} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s \\ t) :=\nhs.inter ht.compl\n\nlemma is_clopen_Union {\u03b2 : Type*} [fintype \u03b2] {s : \u03b2 \u2192 set \u03b1}\n  (h : \u2200 i, is_clopen (s i)) : is_clopen (\u22c3 i, s i) :=\n\u27e8is_open_Union (forall_and_distrib.1 h).1, is_closed_Union (forall_and_distrib.1 h).2\u27e9\n\nlemma is_clopen_bUnion {\u03b2 : Type*} {s : finset \u03b2} {f : \u03b2 \u2192 set \u03b1} (h : \u2200 i \u2208 s, is_clopen $ f i) :\n  is_clopen (\u22c3 i \u2208 s, f i) :=\nbegin\n  refine \u27e8is_open_bUnion (\u03bb i hi, (h i hi).1), _\u27e9,\n  show is_closed (\u22c3 (i : \u03b2) (H : i \u2208 (s : set \u03b2)), f i),\n  rw bUnion_eq_Union,\n  exact is_closed_Union (\u03bb \u27e8i, hi\u27e9,(h i hi).2)\nend\n\nlemma is_clopen_Inter {\u03b2 : Type*} [fintype \u03b2] {s : \u03b2 \u2192 set \u03b1}\n  (h : \u2200 i, is_clopen (s i)) : is_clopen (\u22c2 i, s i) :=\n\u27e8(is_open_Inter (forall_and_distrib.1 h).1), (is_closed_Inter (forall_and_distrib.1 h).2)\u27e9\n\nlemma is_clopen_bInter {\u03b2 : Type*} {s : finset \u03b2} {f : \u03b2 \u2192 set \u03b1} (h : \u2200 i \u2208 s, is_clopen (f i)) :\n  is_clopen (\u22c2 i \u2208 s, f i) :=\n\u27e8 is_open_bInter \u27e8finset_coe.fintype s\u27e9 (\u03bb i hi, (h i hi).1),\n  by {show is_closed (\u22c2 (i : \u03b2) (H : i \u2208 (\u2191s : set \u03b2)), f i), rw bInter_eq_Inter,\n    apply is_closed_Inter, rintro \u27e8i, hi\u27e9, exact (h i hi).2}\u27e9\n\nlemma continuous_on.preimage_clopen_of_clopen\n  {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {t : set \u03b2} (hf : continuous_on f s) (hs : is_clopen s)\n  (ht : is_clopen t) : is_clopen (s \u2229 f\u207b\u00b9' t) :=\n\u27e8continuous_on.preimage_open_of_open hf hs.1 ht.1,\n  continuous_on.preimage_closed_of_closed hf hs.2 ht.2\u27e9\n\n/-- The intersection of a disjoint covering by two open sets of a clopen set will be clopen. -/\ntheorem is_clopen_inter_of_disjoint_cover_clopen {Z a b : set \u03b1} (h : is_clopen Z)\n  (cover : Z \u2286 a \u222a b) (ha : is_open a) (hb : is_open b) (hab : a \u2229 b = \u2205) : is_clopen (Z \u2229 a) :=\nbegin\n  refine \u27e8is_open.inter h.1 ha, _\u27e9,\n  have : is_closed (Z \u2229 b\u1d9c) := is_closed.inter h.2 (is_closed_compl_iff.2 hb),\n  convert this using 1,\n  apply subset.antisymm,\n  { exact inter_subset_inter_right Z (subset_compl_iff_disjoint.2 hab) },\n  { rintros x \u27e8hx\u2081, hx\u2082\u27e9,\n    exact \u27e8hx\u2081, by simpa [not_mem_of_mem_compl hx\u2082] using cover hx\u2081\u27e9 }\nend\n\n@[simp] lemma is_clopen_discrete [discrete_topology \u03b1] (x : set \u03b1) : is_clopen x :=\n\u27e8is_open_discrete _, is_closed_discrete _\u27e9\n\nlemma clopen_range_sigma_mk {\u03b9 : Type*} {\u03c3 : \u03b9 \u2192 Type*} [\u03a0 i, topological_space (\u03c3 i)] {i : \u03b9} :\n  is_clopen (set.range (@sigma.mk \u03b9 \u03c3 i)) :=\n\u27e8open_embedding_sigma_mk.open_range, closed_embedding_sigma_mk.closed_range\u27e9\n\nprotected lemma quotient_map.is_clopen_preimage {f : \u03b1 \u2192 \u03b2}\n  (hf : quotient_map f) {s : set \u03b2} : is_clopen (f \u207b\u00b9' s) \u2194 is_clopen s :=\nand_congr hf.is_open_preimage hf.is_closed_preimage\n\nend clopen\n\nsection preirreducible\n\n/-- A preirreducible set `s` is one where there is no non-trivial pair of disjoint opens on `s`. -/\ndef is_preirreducible (s : set \u03b1) : Prop :=\n\u2200 (u v : set \u03b1), is_open u \u2192 is_open v \u2192\n  (s \u2229 u).nonempty \u2192 (s \u2229 v).nonempty \u2192 (s \u2229 (u \u2229 v)).nonempty\n\n/-- An irreducible set `s` is one that is nonempty and\nwhere there is no non-trivial pair of disjoint opens on `s`. -/\ndef is_irreducible (s : set \u03b1) : Prop :=\ns.nonempty \u2227 is_preirreducible s\n\nlemma is_irreducible.nonempty {s : set \u03b1} (h : is_irreducible s) :\n  s.nonempty := h.1\n\nlemma is_irreducible.is_preirreducible {s : set \u03b1} (h : is_irreducible s) :\n  is_preirreducible s := h.2\n\ntheorem is_preirreducible_empty : is_preirreducible (\u2205 : set \u03b1) :=\n\u03bb _ _ _ _ _ \u27e8x, h1, h2\u27e9, h1.elim\n\nlemma set.subsingleton.is_preirreducible {s : set \u03b1} (hs : s.subsingleton) :\n  is_preirreducible s :=\n\u03bb u v hu hv \u27e8x, hxs, hxu\u27e9 \u27e8y, hys, hyv\u27e9, \u27e8y, hys, hs hxs hys \u25b8 hxu, hyv\u27e9\n\ntheorem is_irreducible_singleton {x} : is_irreducible ({x} : set \u03b1) :=\n\u27e8singleton_nonempty x, subsingleton_singleton.is_preirreducible\u27e9\n\ntheorem is_preirreducible.closure {s : set \u03b1} (H : is_preirreducible s) :\n  is_preirreducible (closure s) :=\n\u03bb u v hu hv \u27e8y, hycs, hyu\u27e9 \u27e8z, hzcs, hzv\u27e9,\nlet \u27e8p, hpu, hps\u27e9 := mem_closure_iff.1 hycs u hu hyu in\nlet \u27e8q, hqv, hqs\u27e9 := mem_closure_iff.1 hzcs v hv hzv in\nlet \u27e8r, hrs, hruv\u27e9 := H u v hu hv \u27e8p, hps, hpu\u27e9 \u27e8q, hqs, hqv\u27e9 in\n\u27e8r, subset_closure hrs, hruv\u27e9\n\nlemma is_irreducible.closure {s : set \u03b1} (h : is_irreducible s) :\n  is_irreducible (closure s) :=\n\u27e8h.nonempty.closure, h.is_preirreducible.closure\u27e9\n\ntheorem exists_preirreducible (s : set \u03b1) (H : is_preirreducible s) :\n  \u2203 t : set \u03b1, is_preirreducible t \u2227 s \u2286 t \u2227 \u2200 u, is_preirreducible u \u2192 t \u2286 u \u2192 u = t :=\nlet \u27e8m, hm, hsm, hmm\u27e9 := zorn_subset_nonempty {t : set \u03b1 | is_preirreducible t}\n  (\u03bb c hc hcc hcn, let \u27e8t, htc\u27e9 := hcn in\n    \u27e8\u22c3\u2080 c, \u03bb u v hu hv \u27e8y, hy, hyu\u27e9 \u27e8z, hz, hzv\u27e9,\n      let \u27e8p, hpc, hyp\u27e9 := mem_sUnion.1 hy,\n          \u27e8q, hqc, hzq\u27e9 := mem_sUnion.1 hz in\n      or.cases_on (hcc.total hpc hqc)\n        (assume hpq : p \u2286 q, let \u27e8x, hxp, hxuv\u27e9 := hc hqc u v hu hv\n            \u27e8y, hpq hyp, hyu\u27e9 \u27e8z, hzq, hzv\u27e9 in\n          \u27e8x, mem_sUnion_of_mem hxp hqc, hxuv\u27e9)\n        (assume hqp : q \u2286 p, let \u27e8x, hxp, hxuv\u27e9 := hc hpc u v hu hv\n            \u27e8y, hyp, hyu\u27e9 \u27e8z, hqp hzq, hzv\u27e9 in\n          \u27e8x, mem_sUnion_of_mem hxp hpc, hxuv\u27e9),\n    \u03bb x hxc, subset_sUnion_of_mem hxc\u27e9) s H in\n\u27e8m, hm, hsm, \u03bb u hu hmu, hmm _ hu hmu\u27e9\n\n/-- A maximal irreducible set that contains a given point. -/\ndef irreducible_component (x : \u03b1) : set \u03b1 :=\nclassical.some (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)\n\nlemma irreducible_component_property (x : \u03b1) :\n  is_preirreducible (irreducible_component x) \u2227 {x} \u2286 (irreducible_component x) \u2227\n  \u2200 u, is_preirreducible u \u2192 (irreducible_component x) \u2286 u \u2192 u = (irreducible_component x) :=\nclassical.some_spec (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)\n\ntheorem mem_irreducible_component {x : \u03b1} : x \u2208 irreducible_component x :=\nsingleton_subset_iff.1 (irreducible_component_property x).2.1\n\ntheorem is_irreducible_irreducible_component {x : \u03b1} : is_irreducible (irreducible_component x) :=\n\u27e8\u27e8x, mem_irreducible_component\u27e9, (irreducible_component_property x).1\u27e9\n\ntheorem eq_irreducible_component {x : \u03b1} :\n  \u2200 {s : set \u03b1}, is_preirreducible s \u2192 irreducible_component x \u2286 s \u2192 s = irreducible_component x :=\n(irreducible_component_property x).2.2\n\ntheorem is_closed_irreducible_component {x : \u03b1} :\n  is_closed (irreducible_component x) :=\nclosure_eq_iff_is_closed.1 $ eq_irreducible_component\n  is_irreducible_irreducible_component.is_preirreducible.closure\n  subset_closure\n\n/-- A preirreducible space is one where there is no non-trivial pair of disjoint opens. -/\nclass preirreducible_space (\u03b1 : Type u) [topological_space \u03b1] : Prop :=\n(is_preirreducible_univ [] : is_preirreducible (univ : set \u03b1))\n\n/-- An irreducible space is one that is nonempty\nand where there is no non-trivial pair of disjoint opens. -/\nclass irreducible_space (\u03b1 : Type u) [topological_space \u03b1] extends preirreducible_space \u03b1 : Prop :=\n(to_nonempty [] : nonempty \u03b1)\n\n-- see Note [lower instance priority]\nattribute [instance, priority 50] irreducible_space.to_nonempty\n\nlemma irreducible_space.is_irreducible_univ (\u03b1 : Type u) [topological_space \u03b1]\n  [irreducible_space \u03b1] : is_irreducible (\u22a4 : set \u03b1) :=\n\u27e8by simp, preirreducible_space.is_preirreducible_univ \u03b1\u27e9\n\nlemma irreducible_space_def (\u03b1 : Type u) [topological_space \u03b1] :\n  irreducible_space \u03b1 \u2194 is_irreducible (\u22a4 : set \u03b1) :=\n\u27e8@@irreducible_space.is_irreducible_univ \u03b1 _,\n  \u03bb h, by { haveI : preirreducible_space \u03b1 := \u27e8h.2\u27e9, exact \u27e8\u27e8h.1.some\u27e9\u27e9 }\u27e9\n\ntheorem nonempty_preirreducible_inter [preirreducible_space \u03b1] {s t : set \u03b1} :\n  is_open s \u2192 is_open t \u2192 s.nonempty \u2192 t.nonempty \u2192 (s \u2229 t).nonempty :=\nby simpa only [univ_inter, univ_subset_iff] using\n  @preirreducible_space.is_preirreducible_univ \u03b1 _ _ s t\n\ntheorem is_preirreducible.image {s : set \u03b1} (H : is_preirreducible s)\n  (f : \u03b1 \u2192 \u03b2) (hf : continuous_on f s) : is_preirreducible (f '' s) :=\nbegin\n  rintros u v hu hv \u27e8_, \u27e8\u27e8x, hx, rfl\u27e9, hxu\u27e9\u27e9 \u27e8_, \u27e8\u27e8y, hy, rfl\u27e9, hyv\u27e9\u27e9,\n  rw \u2190 mem_preimage at hxu hyv,\n  rcases continuous_on_iff'.1 hf u hu with \u27e8u', hu', u'_eq\u27e9,\n  rcases continuous_on_iff'.1 hf v hv with \u27e8v', hv', v'_eq\u27e9,\n  have := H u' v' hu' hv',\n  rw [inter_comm s u', \u2190 u'_eq] at this,\n  rw [inter_comm s v', \u2190 v'_eq] at this,\n  rcases this \u27e8x, hxu, hx\u27e9 \u27e8y, hyv, hy\u27e9 with \u27e8z, hzs, hzu', hzv'\u27e9,\n  refine \u27e8f z, mem_image_of_mem f hzs, _, _\u27e9,\n  all_goals\n  { rw \u2190 mem_preimage,\n    apply mem_of_mem_inter_left,\n    show z \u2208 _ \u2229 s,\n    simp [*] }\nend\n\ntheorem is_irreducible.image {s : set \u03b1} (H : is_irreducible s)\n  (f : \u03b1 \u2192 \u03b2) (hf : continuous_on f s) : is_irreducible (f '' s) :=\n\u27e8nonempty_image_iff.mpr H.nonempty, H.is_preirreducible.image f hf\u27e9\n\nlemma subtype.preirreducible_space {s : set \u03b1} (h : is_preirreducible s) :\n  preirreducible_space s :=\n{ is_preirreducible_univ :=\n  begin\n    intros u v hu hv hsu hsv,\n    rw is_open_induced_iff at hu hv,\n    rcases hu with \u27e8u, hu, rfl\u27e9,\n    rcases hv with \u27e8v, hv, rfl\u27e9,\n    rcases hsu with \u27e8\u27e8x, hxs\u27e9, hxs', hxu\u27e9,\n    rcases hsv with \u27e8\u27e8y, hys\u27e9, hys', hyv\u27e9,\n    rcases h u v hu hv \u27e8x, hxs, hxu\u27e9 \u27e8y, hys, hyv\u27e9 with \u27e8z, hzs, \u27e8hzu, hzv\u27e9\u27e9,\n    exact \u27e8\u27e8z, hzs\u27e9, \u27e8set.mem_univ _, \u27e8hzu, hzv\u27e9\u27e9\u27e9\n  end }\n\nlemma subtype.irreducible_space {s : set \u03b1} (h : is_irreducible s) :\n  irreducible_space s :=\n{ is_preirreducible_univ :=\n  (subtype.preirreducible_space h.is_preirreducible).is_preirreducible_univ,\n  to_nonempty := h.nonempty.to_subtype }\n\n/-- A set `s` is irreducible if and only if\nfor every finite collection of open sets all of whose members intersect `s`,\n`s` also intersects the intersection of the entire collection\n(i.e., there is an element of `s` contained in every member of the collection). -/\nlemma is_irreducible_iff_sInter {s : set \u03b1} :\n  is_irreducible s \u2194\n  \u2200 (U : finset (set \u03b1)) (hU : \u2200 u \u2208 U, is_open u) (H : \u2200 u \u2208 U, (s \u2229 u).nonempty),\n  (s \u2229 \u22c2\u2080 \u2191U).nonempty :=\nbegin\n  split; intro h,\n  { intro U, apply finset.induction_on U,\n    { intros, simpa using h.nonempty },\n    { intros u U hu IH hU H,\n      rw [finset.coe_insert, sInter_insert],\n      apply h.2,\n      { solve_by_elim [finset.mem_insert_self] },\n      { apply is_open_sInter (finset.finite_to_set U),\n        intros, solve_by_elim [finset.mem_insert_of_mem] },\n      { solve_by_elim [finset.mem_insert_self] },\n      { apply IH,\n        all_goals { intros, solve_by_elim [finset.mem_insert_of_mem] } } } },\n  { split,\n    { simpa using h \u2205 _ _; intro u; simp },\n    intros u v hu hv hu' hv',\n    simpa using h {u,v} _ _,\n    all_goals\n    { intro t,\n      rw [finset.mem_insert, finset.mem_singleton],\n      rintro (rfl|rfl); assumption } }\nend\n\n/-- A set is preirreducible if and only if\nfor every cover by two closed sets, it is contained in one of the two covering sets. -/\nlemma is_preirreducible_iff_closed_union_closed {s : set \u03b1} :\n  is_preirreducible s \u2194\n  \u2200 (z\u2081 z\u2082 : set \u03b1), is_closed z\u2081 \u2192 is_closed z\u2082 \u2192 s \u2286 z\u2081 \u222a z\u2082 \u2192 s \u2286 z\u2081 \u2228 s \u2286 z\u2082 :=\nbegin\n  split,\n  all_goals\n  { intros h t\u2081 t\u2082 ht\u2081 ht\u2082,\n    specialize h t\u2081\u1d9c t\u2082\u1d9c,\n    simp only [is_open_compl_iff, is_closed_compl_iff] at h,\n    specialize h ht\u2081 ht\u2082 },\n  { contrapose!, simp only [not_subset],\n    rintro \u27e8\u27e8x, hx, hx'\u27e9, \u27e8y, hy, hy'\u27e9\u27e9,\n    rcases h \u27e8x, hx, hx'\u27e9 \u27e8y, hy, hy'\u27e9 with \u27e8z, hz, hz'\u27e9,\n    rw \u2190 compl_union at hz',\n    exact \u27e8z, hz, hz'\u27e9 },\n  { rintro \u27e8x, hx, hx'\u27e9 \u27e8y, hy, hy'\u27e9,\n    rw \u2190 compl_inter at h,\n    delta set.nonempty,\n    rw imp_iff_not_or at h,\n    contrapose! h,\n    split,\n    { intros z hz hz', exact h z \u27e8hz, hz'\u27e9 },\n    { split; intro H; refine H _ \u2039_\u203a; assumption } }\nend\n\n/-- A set is irreducible if and only if\nfor every cover by a finite collection of closed sets,\nit is contained in one of the members of the collection. -/\nlemma is_irreducible_iff_sUnion_closed {s : set \u03b1} :\n  is_irreducible s \u2194\n  \u2200 (Z : finset (set \u03b1)) (hZ : \u2200 z \u2208 Z, is_closed z) (H : s \u2286 \u22c3\u2080 \u2191Z),\n  \u2203 z \u2208 Z, s \u2286 z :=\nbegin\n  rw [is_irreducible, is_preirreducible_iff_closed_union_closed],\n  split; intro h,\n  { intro Z, apply finset.induction_on Z,\n    { intros, rw [finset.coe_empty, sUnion_empty] at H,\n      rcases h.1 with \u27e8x, hx\u27e9,\n      exfalso, tauto },\n    { intros z Z hz IH hZ H,\n      cases h.2 z (\u22c3\u2080 \u2191Z) _ _ _\n        with h' h',\n      { exact \u27e8z, finset.mem_insert_self _ _, h'\u27e9 },\n      { rcases IH _ h' with \u27e8z', hz', hsz'\u27e9,\n        { exact \u27e8z', finset.mem_insert_of_mem hz', hsz'\u27e9 },\n        { intros, solve_by_elim [finset.mem_insert_of_mem] } },\n      { solve_by_elim [finset.mem_insert_self] },\n      { rw sUnion_eq_bUnion,\n        apply is_closed_bUnion (finset.finite_to_set Z),\n        { intros, solve_by_elim [finset.mem_insert_of_mem] } },\n      { simpa using H } } },\n  { split,\n    { by_contradiction hs,\n      simpa using h \u2205 _ _,\n      { intro z, simp },\n      { simpa [set.nonempty] using hs } },\n    intros z\u2081 z\u2082 hz\u2081 hz\u2082 H,\n    have := h {z\u2081, z\u2082} _ _,\n    simp only [exists_prop, finset.mem_insert, finset.mem_singleton] at this,\n    { rcases this with \u27e8z, rfl|rfl, hz\u27e9; tauto },\n    { intro t,\n      rw [finset.mem_insert, finset.mem_singleton],\n      rintro (rfl|rfl); assumption },\n    { simpa using H } }\nend\n\n/-- A nonemtpy open subset of a preirreducible subspace is dense in the subspace. -/\nlemma subset_closure_inter_of_is_preirreducible_of_is_open {S U : set \u03b1}\n  (hS : is_preirreducible S) (hU : is_open U) (h : (S \u2229 U).nonempty) : S \u2286 closure (S \u2229 U) :=\nbegin\n  by_contra h',\n  obtain \u27e8x, h\u2081, h\u2082, h\u2083\u27e9 := hS _ (closure (S \u2229 U))\u1d9c hU (is_open_compl_iff.mpr is_closed_closure) h\n    (set.inter_compl_nonempty_iff.mpr h'),\n  exact h\u2083 (subset_closure \u27e8h\u2081, h\u2082\u27e9)\nend\n\n/-- If `\u2205 \u2260 U \u2286 S \u2286 Z` such that `U` is open and `Z` is preirreducible, then `S` is irreducible. -/\nlemma is_preirreducible.subset_irreducible {S U Z : set \u03b1}\n  (hZ : is_preirreducible Z) (hU : U.nonempty) (hU' : is_open U)\n  (h\u2081 : U \u2286 S) (h\u2082 : S \u2286 Z) : is_irreducible S :=\nbegin\n  classical,\n  obtain \u27e8z, hz\u27e9 := hU,\n  replace hZ : is_irreducible Z := \u27e8\u27e8z, h\u2082 (h\u2081 hz)\u27e9, hZ\u27e9,\n  refine \u27e8\u27e8z, h\u2081 hz\u27e9, _\u27e9,\n  rintros u v hu hv \u27e8x, hx, hx'\u27e9 \u27e8y, hy, hy'\u27e9,\n  obtain \u27e8a, -, ha'\u27e9 := is_irreducible_iff_sInter.mp hZ {U, u, v} (by tidy) _,\n  replace ha' : a \u2208 U \u2227 a \u2208 u \u2227 a \u2208 v := by simpa using ha',\n  exact \u27e8a, h\u2081 ha'.1, ha'.2\u27e9,\n  { intros U H,\n    simp only [finset.mem_insert, finset.mem_singleton] at H,\n    rcases H with (rfl|rfl|rfl),\n    exacts [\u27e8z, h\u2082 (h\u2081 hz), hz\u27e9, \u27e8x, h\u2082 hx, hx'\u27e9, \u27e8y, h\u2082 hy, hy'\u27e9] }\nend\n\nlemma is_preirreducible.open_subset {Z U : set \u03b1} (hZ : is_preirreducible Z)\n  (hU : is_open U) (hU' : U \u2286 Z) :\n  is_preirreducible U :=\nU.eq_empty_or_nonempty.elim (\u03bb h, h.symm \u25b8 is_preirreducible_empty)\n  (\u03bb h, (hZ.subset_irreducible h hU (\u03bb _, id) hU').2)\n\nlemma is_preirreducible.interior {Z : set \u03b1} (hZ : is_preirreducible Z) :\n  is_preirreducible (interior Z) :=\nhZ.open_subset is_open_interior interior_subset\n\nlemma is_preirreducible.preimage {Z : set \u03b1} (hZ : is_preirreducible Z)\n  {f : \u03b2 \u2192 \u03b1} (hf : open_embedding f) :\n  is_preirreducible (f \u207b\u00b9' Z) :=\nbegin\n  rintros U V hU hV \u27e8x, hx, hx'\u27e9 \u27e8y, hy, hy'\u27e9,\n  obtain \u27e8_, h\u2081, \u27e8z, h\u2082, rfl\u27e9, \u27e8z', h\u2083, h\u2084\u27e9\u27e9 := hZ _ _ (hf.is_open_map _ hU) (hf.is_open_map _ hV)\n    \u27e8f x, hx, set.mem_image_of_mem f hx'\u27e9 \u27e8f y, hy, set.mem_image_of_mem f hy'\u27e9,\n  cases hf.inj h\u2084,\n  exact \u27e8z, h\u2081, h\u2082, h\u2083\u27e9\nend\n\nend preirreducible\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/topology/subset_properties.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.746113199650313}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland, Yury Kudryashov\n-/\nimport algebra.group.semiconj\n\n/-!\n# Commuting pairs of elements in monoids\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define the predicate `commute a b := a * b = b * a` and provide some operations on terms `(h :\ncommute a b)`. E.g., if `a`, `b`, and c are elements of a semiring, and that `hb : commute a b` and\n`hc : commute a c`.  Then `hb.pow_left 5` proves `commute (a ^ 5) b` and `(hb.pow_right 2).add_right\n(hb.mul_right hc)` proves `commute a (b ^ 2 + b * c)`.\n\nLean does not immediately recognise these terms as equations, so for rewriting we need syntax like\n`rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`.\n\nThis file defines only a few operations (`mul_left`, `inv_right`, etc).  Other operations\n(`pow_right`, field inverse etc) are in the files that define corresponding notions.\n\n## Implementation details\n\nMost of the proofs come from the properties of `semiconj_by`.\n-/\n\nvariables {G : Type*}\n\n/-- Two elements commute if `a * b = b * a`. -/\n@[to_additive add_commute \"Two elements additively commute if `a + b = b + a`\"]\ndef commute {S : Type*} [has_mul S] (a b : S) : Prop := semiconj_by a b b\n\nnamespace commute\n\nsection has_mul\n\nvariables {S : Type*} [has_mul S]\n\n/-- Equality behind `commute a b`; useful for rewriting. -/\n@[to_additive \"Equality behind `add_commute a b`; useful for rewriting.\"]\nprotected lemma eq {a b : S} (h : commute a b) : a * b = b * a := h\n\n/-- Any element commutes with itself. -/\n@[refl, simp, to_additive \"Any element commutes with itself.\"]\nprotected lemma refl (a : S) : commute a a := eq.refl (a * a)\n\n/-- If `a` commutes with `b`, then `b` commutes with `a`. -/\n@[symm, to_additive \"If `a` commutes with `b`, then `b` commutes with `a`.\"]\nprotected lemma symm {a b : S} (h : commute a b) : commute b a := eq.symm h\n\n@[to_additive] protected theorem semiconj_by {a b : S} (h : commute a b) : semiconj_by a b b := h\n\n@[to_additive]\nprotected theorem symm_iff {a b : S} : commute a b \u2194 commute b a :=\n\u27e8commute.symm, commute.symm\u27e9\n\n@[to_additive] instance : is_refl S commute := \u27e8commute.refl\u27e9\n\n-- This instance is useful for `finset.noncomm_prod`\n@[to_additive] instance on_is_refl {f : G \u2192 S} : is_refl G (\u03bb a b, commute (f a) (f b)) :=\n\u27e8\u03bb _, commute.refl _\u27e9\n\nend has_mul\n\nsection semigroup\n\nvariables {S : Type*} [semigroup S] {a b c : S}\n\n/-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/\n@[simp, to_additive \"If `a` commutes with both `b` and `c`, then it commutes with their sum.\"]\nlemma mul_right (hab : commute a b) (hac : commute a c) : commute a (b * c) := hab.mul_right hac\n\n/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/\n@[simp, to_additive \"If both `a` and `b` commute with `c`, then their product commutes with `c`.\"]\nlemma mul_left (hac : commute a c) (hbc : commute b c) : commute (a * b) c := hac.mul_left hbc\n\n@[to_additive] protected lemma right_comm (h : commute b c) (a : S) :\n  a * b * c = a * c * b :=\nby simp only [mul_assoc, h.eq]\n\n@[to_additive] protected lemma left_comm (h : commute a b) (c) :\n  a * (b * c) = b * (a * c) :=\nby simp only [\u2190 mul_assoc, h.eq]\n\n@[to_additive] protected lemma mul_mul_mul_comm (hbc : commute b c) (a d : S) :\n  (a * b) * (c * d) = (a * c) * (b * d) :=\nby simp only [hbc.left_comm, mul_assoc]\n\nend semigroup\n\n@[to_additive]\nprotected \n\nsection mul_one_class\n\nvariables {M : Type*} [mul_one_class M]\n\n@[simp, to_additive] theorem one_right (a : M) : commute a 1 := semiconj_by.one_right a\n@[simp, to_additive] theorem one_left (a : M) : commute 1 a := semiconj_by.one_left a\n\nend mul_one_class\n\nsection monoid\n\nvariables {M : Type*} [monoid M] {a b : M} {u u\u2081 u\u2082 : M\u02e3}\n\n@[simp, to_additive]\ntheorem pow_right (h : commute a b) (n : \u2115) : commute a (b ^ n) := h.pow_right n\n@[simp, to_additive]\ntheorem pow_left (h : commute a b) (n : \u2115) : commute (a ^ n) b := (h.symm.pow_right n).symm\n@[simp, to_additive]\ntheorem pow_pow (h : commute a b) (m n : \u2115) : commute (a ^ m) (b ^ n) :=\n(h.pow_left m).pow_right n\n\n@[simp, to_additive]\ntheorem self_pow (a : M) (n : \u2115) : commute a (a ^ n) := (commute.refl a).pow_right n\n@[simp, to_additive]\ntheorem pow_self (a : M) (n : \u2115) : commute (a ^ n) a := (commute.refl a).pow_left n\n@[simp, to_additive]\ntheorem pow_pow_self (a : M) (m n : \u2115) : commute (a ^ m) (a ^ n) :=\n(commute.refl a).pow_pow m n\n\n@[to_additive succ_nsmul'] theorem _root_.pow_succ' (a : M) (n : \u2115) : a ^ (n + 1) = a ^ n * a :=\n(pow_succ a n).trans (self_pow _ _)\n\n@[to_additive] theorem units_inv_right : commute a u \u2192 commute a \u2191u\u207b\u00b9 :=\nsemiconj_by.units_inv_right\n\n@[simp, to_additive] theorem units_inv_right_iff :\n  commute a \u2191u\u207b\u00b9 \u2194 commute a u :=\nsemiconj_by.units_inv_right_iff\n\n@[to_additive] theorem units_inv_left : commute \u2191u a \u2192 commute \u2191u\u207b\u00b9 a :=\nsemiconj_by.units_inv_symm_left\n\n@[simp, to_additive]\ntheorem units_inv_left_iff: commute \u2191u\u207b\u00b9 a \u2194 commute \u2191u a :=\nsemiconj_by.units_inv_symm_left_iff\n\n@[to_additive]\ntheorem units_coe : commute u\u2081 u\u2082 \u2192 commute (u\u2081 : M) u\u2082 := semiconj_by.units_coe\n@[to_additive]\ntheorem units_of_coe : commute (u\u2081 : M) u\u2082 \u2192 commute u\u2081 u\u2082 := semiconj_by.units_of_coe\n@[simp, to_additive]\ntheorem units_coe_iff : commute (u\u2081 : M) u\u2082 \u2194 commute u\u2081 u\u2082 := semiconj_by.units_coe_iff\n\n/-- If the product of two commuting elements is a unit, then the left multiplier is a unit. -/\n@[to_additive \"If the sum of two commuting elements is an additive unit, then the left summand is an\nadditive unit.\"]\ndef _root_.units.left_of_mul (u : M\u02e3) (a b : M) (hu : a * b = u) (hc : commute a b) : M\u02e3 :=\n{ val := a,\n  inv := b * \u2191u\u207b\u00b9,\n  val_inv := by rw [\u2190 mul_assoc, hu, u.mul_inv],\n  inv_val := have commute a u, from hu \u25b8 (commute.refl _).mul_right hc,\n    by rw [\u2190 this.units_inv_right.right_comm, \u2190 hc.eq, hu, u.mul_inv] }\n\n/-- If the product of two commuting elements is a unit, then the right multiplier is a unit. -/\n@[to_additive \"If the sum of two commuting elements is an additive unit, then the right summand is\nan additive unit.\"]\ndef _root_.units.right_of_mul (u : M\u02e3) (a b : M) (hu : a * b = u) (hc : commute a b) : M\u02e3 :=\nu.left_of_mul b a (hc.eq \u25b8 hu) hc.symm\n\n@[to_additive] lemma is_unit_mul_iff (h : commute a b) :\n  is_unit (a * b) \u2194 is_unit a \u2227 is_unit b :=\n\u27e8\u03bb \u27e8u, hu\u27e9, \u27e8(u.left_of_mul a b hu.symm h).is_unit, (u.right_of_mul a b hu.symm h).is_unit\u27e9,\n  \u03bb H, H.1.mul H.2\u27e9\n\n@[simp, to_additive] lemma _root_.is_unit_mul_self_iff :\n  is_unit (a * a) \u2194 is_unit a :=\n(commute.refl a).is_unit_mul_iff.trans (and_self _)\n\nend monoid\n\nsection division_monoid\nvariables [division_monoid G] {a b c d : G}\n\n@[to_additive] protected lemma inv_inv : commute a b \u2192 commute a\u207b\u00b9 b\u207b\u00b9 := semiconj_by.inv_inv_symm\n@[simp, to_additive]\nlemma inv_inv_iff : commute a\u207b\u00b9 b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_inv_symm_iff\n\n@[to_additive] protected lemma mul_inv (hab : commute a b) : (a * b)\u207b\u00b9 = a\u207b\u00b9 * b\u207b\u00b9 :=\nby rw [hab.eq, mul_inv_rev]\n\n@[to_additive] protected lemma inv (hab : commute a b) : (a * b)\u207b\u00b9 = a\u207b\u00b9 * b\u207b\u00b9 :=\nby rw [hab.eq, mul_inv_rev]\n\n@[to_additive] protected lemma div_mul_div_comm (hbd : commute b d) (hbc : commute b\u207b\u00b9 c) :\n  a / b * (c / d) = a * c / (b * d) :=\nby simp_rw [div_eq_mul_inv, mul_inv_rev, hbd.inv_inv.symm.eq, hbc.mul_mul_mul_comm]\n\n@[to_additive] protected lemma mul_div_mul_comm (hcd : commute c d) (hbc : commute b c\u207b\u00b9) :\n  a * b / (c * d) = a / c * (b / d) :=\n(hcd.div_mul_div_comm hbc.symm).symm\n\n@[to_additive] protected lemma div_div_div_comm (hbc : commute b c) (hbd : commute b\u207b\u00b9 d)\n  (hcd : commute c\u207b\u00b9 d) : a / b / (c / d) = a / c / (b / d) :=\nby simp_rw [div_eq_mul_inv, mul_inv_rev, inv_inv, hbd.symm.eq, hcd.symm.eq,\n  hbc.inv_inv.mul_mul_mul_comm]\n\nend division_monoid\n\nsection group\n\nvariables [group G] {a b : G}\n\n@[to_additive]\ntheorem inv_right : commute a b \u2192 commute a b\u207b\u00b9 := semiconj_by.inv_right\n@[simp, to_additive]\ntheorem inv_right_iff : commute a b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_right_iff\n\n@[to_additive] theorem inv_left :  commute a b \u2192 commute a\u207b\u00b9 b := semiconj_by.inv_symm_left\n@[simp, to_additive]\ntheorem inv_left_iff : commute a\u207b\u00b9 b \u2194 commute a b := semiconj_by.inv_symm_left_iff\n\n@[to_additive]\nprotected theorem inv_mul_cancel (h : commute a b) : a\u207b\u00b9 * b * a = b :=\nby rw [h.inv_left.eq, inv_mul_cancel_right]\n\n@[to_additive]\ntheorem inv_mul_cancel_assoc (h : commute a b) : a\u207b\u00b9 * (b * a) = b :=\nby rw [\u2190 mul_assoc, h.inv_mul_cancel]\n\n@[to_additive]\nprotected theorem mul_inv_cancel (h : commute a b) : a * b * a\u207b\u00b9 = b :=\nby rw [h.eq, mul_inv_cancel_right]\n\n@[to_additive]\ntheorem mul_inv_cancel_assoc (h : commute a b) : a * (b * a\u207b\u00b9) = b :=\nby rw [\u2190 mul_assoc, h.mul_inv_cancel]\n\nend group\n\nend commute\n\nsection comm_group\n\nvariables [comm_group G] (a b : G)\n\n@[simp, to_additive] lemma mul_inv_cancel_comm : a * b * a\u207b\u00b9 = b :=\n(commute.all a b).mul_inv_cancel\n\n@[simp, to_additive] lemma mul_inv_cancel_comm_assoc : a * (b * a\u207b\u00b9) = b :=\n(commute.all a b).mul_inv_cancel_assoc\n\n@[simp, to_additive] lemma inv_mul_cancel_comm : a\u207b\u00b9 * b * a = b :=\n(commute.all a b).inv_mul_cancel\n\n@[simp, to_additive] lemma inv_mul_cancel_comm_assoc : a\u207b\u00b9 * (b * a) = b :=\n(commute.all a b).inv_mul_cancel_assoc\n\nend comm_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/group/commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952838963489, "lm_q2_score": 0.8311430520409024, "lm_q1q2_score": 0.7461131980603358}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport linear_algebra.affine_space.affine_equiv\n\n/-!\n# Affine spaces\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines affine subspaces (over modules) and the affine span of a set of points.\n\n## Main definitions\n\n* `affine_subspace k P` is the type of affine subspaces.  Unlike\n  affine spaces, affine subspaces are allowed to be empty, and lemmas\n  that do not apply to empty affine subspaces have `nonempty`\n  hypotheses.  There is a `complete_lattice` structure on affine\n  subspaces.\n* `affine_subspace.direction` gives the `submodule` spanned by the\n  pairwise differences of points in an `affine_subspace`.  There are\n  various lemmas relating to the set of vectors in the `direction`,\n  and relating the lattice structure on affine subspaces to that on\n  their directions.\n* `affine_subspace.parallel`, notation `\u2225`, gives the property of two affine subspaces being\n  parallel (one being a translate of the other).\n* `affine_span` gives the affine subspace spanned by a set of points,\n  with `vector_span` giving its direction.  `affine_span` is defined\n  in terms of `span_points`, which gives an explicit description of\n  the points contained in the affine span; `span_points` itself should\n  generally only be used when that description is required, with\n  `affine_span` being the main definition for other purposes.  Two\n  other descriptions of the affine span are proved equivalent: it is\n  the `Inf` of affine subspaces containing the points, and (if\n  `[nontrivial k]`) it contains exactly those points that are affine\n  combinations of points in the given set.\n\n## Implementation notes\n\n`out_param` is used in the definiton of `add_torsor V P` to make `V` an implicit argument (deduced\nfrom `P`) in most cases; `include V` is needed in many cases for `V`, and type classes using it, to\nbe added as implicit arguments to individual lemmas.  As for modules, `k` is an explicit argument\nrather than implied by `P` or `V`.\n\nThis file only provides purely algebraic definitions and results.\nThose depending on analysis or topology are defined elsewhere; see\n`analysis.normed_space.add_torsor` and `topology.algebra.affine`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Affine_space\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n-/\n\nnoncomputable theory\nopen_locale big_operators affine\n\nopen set\n\nsection\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\nvariables [affine_space V P]\ninclude V\n\n/-- The submodule spanning the differences of a (possibly empty) set\nof points. -/\ndef vector_span (s : set P) : submodule k V := submodule.span k (s -\u1d65 s)\n\n/-- The definition of `vector_span`, for rewriting. -/\nlemma vector_span_def (s : set P) : vector_span k s = submodule.span k (s -\u1d65 s) :=\nrfl\n\n/-- `vector_span` is monotone. -/\nlemma vector_span_mono {s\u2081 s\u2082 : set P} (h : s\u2081 \u2286 s\u2082) : vector_span k s\u2081 \u2264 vector_span k s\u2082 :=\nsubmodule.span_mono (vsub_self_mono h)\n\nvariables (P)\n\n/-- The `vector_span` of the empty set is `\u22a5`. -/\n@[simp] lemma vector_span_empty : vector_span k (\u2205 : set P) = (\u22a5 : submodule k V) :=\nby rw [vector_span_def, vsub_empty, submodule.span_empty]\n\nvariables {P}\n\n/-- The `vector_span` of a single point is `\u22a5`. -/\n@[simp] lemma vector_span_singleton (p : P) : vector_span k ({p} : set P) = \u22a5 :=\nby simp [vector_span_def]\n\n/-- The `s -\u1d65 s` lies within the `vector_span k s`. -/\nlemma vsub_set_subset_vector_span (s : set P) : s -\u1d65 s \u2286 \u2191(vector_span k s) :=\nsubmodule.subset_span\n\n/-- Each pairwise difference is in the `vector_span`. -/\nlemma vsub_mem_vector_span {s : set P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n  p1 -\u1d65 p2 \u2208 vector_span k s :=\nvsub_set_subset_vector_span k s (vsub_mem_vsub hp1 hp2)\n\n/-- The points in the affine span of a (possibly empty) set of\npoints. Use `affine_span` instead to get an `affine_subspace k P`. -/\ndef span_points (s : set P) : set P :=\n{p | \u2203 p1 \u2208 s, \u2203 v \u2208 (vector_span k s), p = v +\u1d65 p1}\n\n/-- A point in a set is in its affine span. -/\nlemma mem_span_points (p : P) (s : set P) : p \u2208 s \u2192 p \u2208 span_points k s\n| hp := \u27e8p, hp, 0, submodule.zero_mem _, (zero_vadd V p).symm\u27e9\n\n/-- A set is contained in its `span_points`. -/\nlemma subset_span_points (s : set P) : s \u2286 span_points k s :=\n\u03bb p, mem_span_points k p s\n\n/-- The `span_points` of a set is nonempty if and only if that set\nis. -/\n@[simp] lemma span_points_nonempty (s : set P) :\n  (span_points k s).nonempty \u2194 s.nonempty :=\nbegin\n  split,\n  { contrapose,\n    rw [set.not_nonempty_iff_eq_empty, set.not_nonempty_iff_eq_empty],\n    intro h,\n    simp [h, span_points] },\n  { exact \u03bb h, h.mono (subset_span_points _ _) }\nend\n\n/-- Adding a point in the affine span and a vector in the spanning\nsubmodule produces a point in the affine span. -/\nlemma vadd_mem_span_points_of_mem_span_points_of_mem_vector_span {s : set P} {p : P} {v : V}\n    (hp : p \u2208 span_points k s) (hv : v \u2208 vector_span k s) : v +\u1d65 p \u2208 span_points k s :=\nbegin\n  rcases hp with \u27e8p2, \u27e8hp2, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9,\n  rw [hv2p, vadd_vadd],\n  use [p2, hp2, v + v2, (vector_span k s).add_mem hv hv2, rfl]\nend\n\n/-- Subtracting two points in the affine span produces a vector in the\nspanning submodule. -/\nlemma vsub_mem_vector_span_of_mem_span_points_of_mem_span_points {s : set P} {p1 p2 : P}\n    (hp1 : p1 \u2208 span_points k s) (hp2 : p2 \u2208 span_points k s) :\n  p1 -\u1d65 p2 \u2208 vector_span k s :=\nbegin\n  rcases hp1 with \u27e8p1a, \u27e8hp1a, \u27e8v1, \u27e8hv1, hv1p\u27e9\u27e9\u27e9\u27e9,\n  rcases hp2 with \u27e8p2a, \u27e8hp2a, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9,\n  rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +\u1d65 p1a), vadd_vsub_assoc, add_comm, add_sub_assoc],\n  have hv1v2 : v1 - v2 \u2208 vector_span k s,\n  { rw sub_eq_add_neg,\n    apply (vector_span k s).add_mem hv1,\n    rw \u2190neg_one_smul k v2,\n    exact (vector_span k s).smul_mem (-1 : k) hv2 },\n  refine (vector_span k s).add_mem _ hv1v2,\n  exact vsub_mem_vector_span k hp1a hp2a\nend\n\nend\n\n/-- An `affine_subspace k P` is a subset of an `affine_space V P`\nthat, if not empty, has an affine space structure induced by a\ncorresponding subspace of the `module k V`. -/\nstructure affine_subspace (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V]\n    [module k V] [affine_space V P] :=\n(carrier : set P)\n(smul_vsub_vadd_mem : \u2200 (c : k) {p1 p2 p3 : P}, p1 \u2208 carrier \u2192 p2 \u2208 carrier \u2192 p3 \u2208 carrier \u2192\n  c \u2022 (p1 -\u1d65 p2 : V) +\u1d65 p3 \u2208 carrier)\n\nnamespace submodule\n\nvariables {k V : Type*} [ring k] [add_comm_group V] [module k V]\n\n/-- Reinterpret `p : submodule k V` as an `affine_subspace k V`. -/\ndef to_affine_subspace (p : submodule k V) : affine_subspace k V :=\n{ carrier := p,\n  smul_vsub_vadd_mem := \u03bb c p\u2081 p\u2082 p\u2083 h\u2081 h\u2082 h\u2083, p.add_mem (p.smul_mem _ (p.sub_mem h\u2081 h\u2082)) h\u2083 }\n\nend submodule\n\nnamespace affine_subspace\n\nvariables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\ninstance : set_like (affine_subspace k P) P :=\n{ coe := carrier,\n  coe_injective' := \u03bb p q _, by cases p; cases q; congr' }\n\n/-- A point is in an affine subspace coerced to a set if and only if\nit is in that affine subspace. -/\n@[simp] lemma mem_coe (p : P) (s : affine_subspace k P) :\n  p \u2208 (s : set P) \u2194 p \u2208 s :=\niff.rfl\n\nvariables {k P}\n\n/-- The direction of an affine subspace is the submodule spanned by\nthe pairwise differences of points.  (Except in the case of an empty\naffine subspace, where the direction is the zero submodule, every\nvector in the direction is the difference of two points in the affine\nsubspace.) -/\ndef direction (s : affine_subspace k P) : submodule k V := vector_span k (s : set P)\n\n/-- The direction equals the `vector_span`. -/\nlemma direction_eq_vector_span (s : affine_subspace k P) :\n  s.direction = vector_span k (s : set P) :=\nrfl\n\n/-- Alternative definition of the direction when the affine subspace\nis nonempty.  This is defined so that the order on submodules (as used\nin the definition of `submodule.span`) can be used in the proof of\n`coe_direction_eq_vsub_set`, and is not intended to be used beyond\nthat proof. -/\ndef direction_of_nonempty {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  submodule k V :=\n{ carrier := (s : set P) -\u1d65 s,\n  zero_mem' := begin\n    cases h with p hp,\n    exact (vsub_self p) \u25b8 vsub_mem_vsub hp hp\n  end,\n  add_mem' := begin\n    intros a b ha hb,\n    rcases ha with \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    rcases hb with \u27e8p3, p4, hp3, hp4, rfl\u27e9,\n    rw [\u2190vadd_vsub_assoc],\n    refine vsub_mem_vsub _ hp4,\n    convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3,\n    rw one_smul\n  end,\n  smul_mem' := begin\n    intros c v hv,\n    rcases hv with \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    rw [\u2190vadd_vsub (c \u2022 (p1 -\u1d65 p2)) p2],\n    refine vsub_mem_vsub _ hp2,\n    exact s.smul_vsub_vadd_mem c hp1 hp2 hp2\n  end }\n\n/-- `direction_of_nonempty` gives the same submodule as\n`direction`. -/\nlemma direction_of_nonempty_eq_direction {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  direction_of_nonempty h = s.direction :=\nle_antisymm (vsub_set_subset_vector_span k s) (submodule.span_le.2 set.subset.rfl)\n\n/-- The set of vectors in the direction of a nonempty affine subspace\nis given by `vsub_set`. -/\nlemma coe_direction_eq_vsub_set {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  (s.direction : set V) = (s : set P) -\u1d65 s :=\ndirection_of_nonempty_eq_direction h \u25b8 rfl\n\n/-- A vector is in the direction of a nonempty affine subspace if and\nonly if it is the subtraction of two vectors in the subspace. -/\nlemma mem_direction_iff_eq_vsub {s : affine_subspace k P} (h : (s : set P).nonempty) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p1 \u2208 s, \u2203 p2 \u2208 s, v = p1 -\u1d65 p2 :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set h],\n  exact \u27e8\u03bb \u27e8p1, p2, hp1, hp2, hv\u27e9, \u27e8p1, hp1, p2, hp2, hv.symm\u27e9,\n         \u03bb \u27e8p1, hp1, p2, hp2, hv\u27e9, \u27e8p1, p2, hp1, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Adding a vector in the direction to a point in the subspace\nproduces a point in the subspace. -/\nlemma vadd_mem_of_mem_direction {s : affine_subspace k P} {v : V} (hv : v \u2208 s.direction) {p : P}\n    (hp : p \u2208 s) : v +\u1d65 p \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub \u27e8p, hp\u27e9 at hv,\n  rcases hv with \u27e8p1, hp1, p2, hp2, hv\u27e9,\n  rw hv,\n  convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp,\n  rw one_smul\nend\n\n/-- Subtracting two points in the subspace produces a vector in the\ndirection. -/\nlemma vsub_mem_direction {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n  (p1 -\u1d65 p2) \u2208 s.direction :=\nvsub_mem_vector_span k hp1 hp2\n\n/-- Adding a vector to a point in a subspace produces a point in the\nsubspace if and only if the vector is in the direction. -/\nlemma vadd_mem_iff_mem_direction {s : affine_subspace k P} (v : V) {p : P} (hp : p \u2208 s) :\n  v +\u1d65 p \u2208 s \u2194 v \u2208 s.direction :=\n\u27e8\u03bb h, by simpa using vsub_mem_direction h hp, \u03bb h, vadd_mem_of_mem_direction h hp\u27e9\n\n/-- Adding a vector in the direction to a point produces a point in the subspace if and only if\nthe original point is in the subspace. -/\nlemma vadd_mem_iff_mem_of_mem_direction {s : affine_subspace k P} {v : V} (hv : v \u2208 s.direction)\n  {p : P} : v +\u1d65 p \u2208 s \u2194 p \u2208 s :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, vadd_mem_of_mem_direction hv h\u27e9,\n  convert vadd_mem_of_mem_direction (submodule.neg_mem _ hv) h,\n  simp\nend\n\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nright. -/\nlemma coe_direction_eq_vsub_set_right {s : affine_subspace k P} {p : P} (hp : p \u2208 s) :\n  (s.direction : set V) = (-\u1d65 p) '' s :=\nbegin\n  rw coe_direction_eq_vsub_set \u27e8p, hp\u27e9,\n  refine le_antisymm _ _,\n  { rintros v \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    exact \u27e8p1 -\u1d65 p2 +\u1d65 p,\n           vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp,\n           (vadd_vsub _ _)\u27e9 },\n  { rintros v \u27e8p2, hp2, rfl\u27e9,\n    exact \u27e8p2, p, hp2, hp, rfl\u27e9 }\nend\n\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nleft. -/\nlemma coe_direction_eq_vsub_set_left {s : affine_subspace k P} {p : P} (hp : p \u2208 s) :\n  (s.direction : set V) = (-\u1d65) p '' s :=\nbegin\n  ext v,\n  rw [set_like.mem_coe, \u2190submodule.neg_mem_iff, \u2190set_like.mem_coe,\n      coe_direction_eq_vsub_set_right hp, set.mem_image_iff_bex, set.mem_image_iff_bex],\n  conv_lhs { congr, funext, rw [\u2190neg_vsub_eq_vsub_rev, neg_inj] }\nend\n\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the right. -/\nlemma mem_direction_iff_eq_vsub_right {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p2 -\u1d65 p :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set_right hp],\n  exact \u27e8\u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9, \u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the left. -/\nlemma mem_direction_iff_eq_vsub_left {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p -\u1d65 p2 :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set_left hp],\n  exact \u27e8\u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9, \u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the right is in the direction if and only if the other point\nis in the subspace. -/\nlemma vsub_right_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n  p2 -\u1d65 p \u2208 s.direction \u2194 p2 \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub_right hp,\n  simp\nend\n\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the left is in the direction if and only if the other point\nis in the subspace. -/\nlemma vsub_left_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n  p -\u1d65 p2 \u2208 s.direction \u2194 p2 \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub_left hp,\n  simp\nend\n\n/-- Two affine subspaces are equal if they have the same points. -/\nlemma coe_injective : function.injective (coe : affine_subspace k P \u2192 set P) :=\nset_like.coe_injective\n\n@[ext] theorem ext {p q : affine_subspace k P} (h : \u2200 x, x \u2208 p \u2194 x \u2208 q) : p = q :=\nset_like.ext h\n\n@[simp] lemma ext_iff (s\u2081 s\u2082 : affine_subspace k P) :\n  (s\u2081 : set P) = s\u2082 \u2194 s\u2081 = s\u2082 :=\nset_like.ext'_iff.symm\n\n/-- Two affine subspaces with the same direction and nonempty\nintersection are equal. -/\nlemma ext_of_direction_eq {s1 s2 : affine_subspace k P} (hd : s1.direction = s2.direction)\n    (hn : ((s1 : set P) \u2229 s2).nonempty) : s1 = s2 :=\nbegin\n  ext p,\n  have hq1 := set.mem_of_mem_inter_left hn.some_mem,\n  have hq2 := set.mem_of_mem_inter_right hn.some_mem,\n  split,\n  { intro hp,\n    rw \u2190vsub_vadd p hn.some,\n    refine vadd_mem_of_mem_direction _ hq2,\n    rw \u2190hd,\n    exact vsub_mem_direction hp hq1 },\n  { intro hp,\n    rw \u2190vsub_vadd p hn.some,\n    refine vadd_mem_of_mem_direction _ hq1,\n    rw hd,\n    exact vsub_mem_direction hp hq2 }\nend\n\n/-- This is not an instance because it loops with `add_torsor.nonempty`. -/\n@[reducible] -- See note [reducible non instances]\ndef to_add_torsor (s : affine_subspace k P) [nonempty s] : add_torsor s.direction s :=\n{ vadd := \u03bb a b, \u27e8(a:V) +\u1d65 (b:P), vadd_mem_of_mem_direction a.2 b.2\u27e9,\n  zero_vadd := by simp,\n  add_vadd := \u03bb a b c, by { ext, apply add_vadd },\n  vsub := \u03bb a b, \u27e8(a:P) -\u1d65 (b:P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2 \u27e9,\n  nonempty := by apply_instance,\n  vsub_vadd' := \u03bb a b, by { ext, apply add_torsor.vsub_vadd' },\n  vadd_vsub' := \u03bb a b, by { ext, apply add_torsor.vadd_vsub' } }\n\nlocal attribute [instance] to_add_torsor\n\n@[simp, norm_cast] lemma coe_vsub (s : affine_subspace k P) [nonempty s] (a b : s) :\n  \u2191(a -\u1d65 b) = (a:P) -\u1d65 (b:P) :=\nrfl\n\n@[simp, norm_cast] lemma coe_vadd (s : affine_subspace k P) [nonempty s] (a : s.direction) (b : s) :\n  \u2191(a +\u1d65 b) = (a:V) +\u1d65 (b:P) :=\nrfl\n\n/-- Embedding of an affine subspace to the ambient space, as an affine map. -/\nprotected def subtype (s : affine_subspace k P) [nonempty s] : s \u2192\u1d43[k] P :=\n{ to_fun := coe,\n  linear := s.direction.subtype,\n  map_vadd' := \u03bb p v, rfl }\n\n@[simp] lemma subtype_linear (s : affine_subspace k P) [nonempty s] :\n  s.subtype.linear = s.direction.subtype :=\nrfl\n\nlemma subtype_apply (s : affine_subspace k P) [nonempty s] (p : s) : s.subtype p = p :=\nrfl\n\n@[simp] lemma coe_subtype (s : affine_subspace k P) [nonempty s] : (s.subtype : s \u2192 P) = coe :=\nrfl\n\nlemma injective_subtype (s : affine_subspace k P) [nonempty s] : function.injective s.subtype :=\nsubtype.coe_injective\n\n/-- Two affine subspaces with nonempty intersection are equal if and\nonly if their directions are equal. -/\nlemma eq_iff_direction_eq_of_mem {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h\u2081 : p \u2208 s\u2081)\n  (h\u2082 : p \u2208 s\u2082) : s\u2081 = s\u2082 \u2194 s\u2081.direction = s\u2082.direction :=\n\u27e8\u03bb h, h \u25b8 rfl, \u03bb h, ext_of_direction_eq h \u27e8p, h\u2081, h\u2082\u27e9\u27e9\n\n/-- Construct an affine subspace from a point and a direction. -/\ndef mk' (p : P) (direction : submodule k V) : affine_subspace k P :=\n{ carrier := {q | \u2203 v \u2208 direction, q = v +\u1d65 p},\n  smul_vsub_vadd_mem := \u03bb c p1 p2 p3 hp1 hp2 hp3, begin\n    rcases hp1 with \u27e8v1, hv1, hp1\u27e9,\n    rcases hp2 with \u27e8v2, hv2, hp2\u27e9,\n    rcases hp3 with \u27e8v3, hv3, hp3\u27e9,\n    use [c \u2022 (v1 - v2) + v3,\n         direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3],\n    simp [hp1, hp2, hp3, vadd_vadd]\n  end }\n\n/-- An affine subspace constructed from a point and a direction contains\nthat point. -/\nlemma self_mem_mk' (p : P) (direction : submodule k V) :\n  p \u2208 mk' p direction :=\n\u27e80, \u27e8direction.zero_mem, (zero_vadd _ _).symm\u27e9\u27e9\n\n/-- An affine subspace constructed from a point and a direction contains\nthe result of adding a vector in that direction to that point. -/\nlemma vadd_mem_mk' {v : V} (p : P) {direction : submodule k V} (hv : v \u2208 direction) :\n  v +\u1d65 p \u2208 mk' p direction :=\n\u27e8v, hv, rfl\u27e9\n\n/-- An affine subspace constructed from a point and a direction is\nnonempty. -/\nlemma mk'_nonempty (p : P) (direction : submodule k V) : (mk' p direction : set P).nonempty :=\n\u27e8p, self_mem_mk' p direction\u27e9\n\n/-- The direction of an affine subspace constructed from a point and a\ndirection. -/\n@[simp] lemma direction_mk' (p : P) (direction : submodule k V) :\n  (mk' p direction).direction = direction :=\nbegin\n  ext v,\n  rw mem_direction_iff_eq_vsub (mk'_nonempty _ _),\n  split,\n  { rintros \u27e8p1, \u27e8v1, hv1, hp1\u27e9, p2, \u27e8v2, hv2, hp2\u27e9, hv\u27e9,\n    rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right],\n    exact direction.sub_mem  hv1 hv2 },\n  { exact \u03bb hv, \u27e8v +\u1d65 p, vadd_mem_mk' _ hv, p,\n                 self_mem_mk' _ _, (vadd_vsub _ _).symm\u27e9 }\nend\n\n/-- A point lies in an affine subspace constructed from another point and a direction if and only\nif their difference is in that direction. -/\nlemma mem_mk'_iff_vsub_mem {p\u2081 p\u2082 : P} {direction : submodule k V} :\n  p\u2082 \u2208 mk' p\u2081 direction \u2194 p\u2082 -\u1d65 p\u2081 \u2208 direction :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rw \u2190direction_mk' p\u2081 direction,\n    exact vsub_mem_direction h (self_mem_mk' _ _) },\n  { rw \u2190 vsub_vadd p\u2082 p\u2081,\n    exact vadd_mem_mk' p\u2081 h }\nend\n\n/-- Constructing an affine subspace from a point in a subspace and\nthat subspace's direction yields the original subspace. -/\n@[simp] lemma mk'_eq {s : affine_subspace k P} {p : P} (hp : p \u2208 s) : mk' p s.direction = s :=\next_of_direction_eq (direction_mk' p s.direction)\n                    \u27e8p, set.mem_inter (self_mem_mk' _ _) hp\u27e9\n\n/-- If an affine subspace contains a set of points, it contains the\n`span_points` of that set. -/\nlemma span_points_subset_coe_of_subset_coe {s : set P} {s1 : affine_subspace k P} (h : s \u2286 s1) :\n  span_points k s \u2286 s1 :=\nbegin\n  rintros p \u27e8p1, hp1, v, hv, hp\u27e9,\n  rw hp,\n  have hp1s1 : p1 \u2208 (s1 : set P) := set.mem_of_mem_of_subset hp1 h,\n  refine vadd_mem_of_mem_direction _ hp1s1,\n  have hs : vector_span k s \u2264 s1.direction := vector_span_mono k h,\n  rw set_like.le_def at hs,\n  rw \u2190set_like.mem_coe,\n  exact set.mem_of_mem_of_subset hv hs\nend\n\nend affine_subspace\n\nlemma affine_map.line_map_mem\n  {k V P : Type*} [ring k] [add_comm_group V] [module k V] [add_torsor V P]\n  {Q : affine_subspace k P} {p\u2080 p\u2081 : P} (c : k) (h\u2080 : p\u2080 \u2208 Q) (h\u2081 : p\u2081 \u2208 Q) :\n  affine_map.line_map p\u2080 p\u2081 c \u2208 Q :=\nbegin\n  rw affine_map.line_map_apply,\n  exact Q.smul_vsub_vadd_mem c h\u2081 h\u2080 h\u2080,\nend\n\nsection affine_span\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\n/-- The affine span of a set of points is the smallest affine subspace\ncontaining those points. (Actually defined here in terms of spans in\nmodules.) -/\ndef affine_span (s : set P) : affine_subspace k P :=\n{ carrier := span_points k s,\n  smul_vsub_vadd_mem := \u03bb c p1 p2 p3 hp1 hp2 hp3,\n    vadd_mem_span_points_of_mem_span_points_of_mem_vector_span k hp3\n      ((vector_span k s).smul_mem c\n        (vsub_mem_vector_span_of_mem_span_points_of_mem_span_points k hp1 hp2)) }\n\n/-- The affine span, converted to a set, is `span_points`. -/\n@[simp] lemma coe_affine_span (s : set P) :\n  (affine_span k s : set P) = span_points k s :=\nrfl\n\n/-- A set is contained in its affine span. -/\nlemma subset_affine_span (s : set P) : s \u2286 affine_span k s :=\nsubset_span_points k s\n\n/-- The direction of the affine span is the `vector_span`. -/\nlemma direction_affine_span (s : set P) : (affine_span k s).direction = vector_span k s :=\nbegin\n  apply le_antisymm,\n  { refine submodule.span_le.2 _,\n    rintros v \u27e8p1, p3, \u27e8p2, hp2, v1, hv1, hp1\u27e9, \u27e8p4, hp4, v2, hv2, hp3\u27e9, rfl\u27e9,\n    rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, set_like.mem_coe],\n    exact (vector_span k s).sub_mem ((vector_span k s).add_mem hv1\n      (vsub_mem_vector_span k hp2 hp4)) hv2 },\n  { exact vector_span_mono k (subset_span_points k s) }\nend\n\n/-- A point in a set is in its affine span. -/\nlemma mem_affine_span {p : P} {s : set P} (hp : p \u2208 s) : p \u2208 affine_span k s :=\nmem_span_points k p s hp\n\nend affine_span\n\nnamespace affine_subspace\n\nvariables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [S : affine_space V P]\ninclude S\n\ninstance : complete_lattice (affine_subspace k P) :=\n{ sup := \u03bb s1 s2, affine_span k (s1 \u222a s2),\n  le_sup_left := \u03bb s1 s2, set.subset.trans (set.subset_union_left s1 s2)\n                                           (subset_span_points k _),\n  le_sup_right :=  \u03bb s1 s2, set.subset.trans (set.subset_union_right s1 s2)\n                                             (subset_span_points k _),\n  sup_le := \u03bb s1 s2 s3 hs1 hs2, span_points_subset_coe_of_subset_coe (set.union_subset hs1 hs2),\n  inf := \u03bb s1 s2, mk (s1 \u2229 s2)\n                     (\u03bb c p1 p2 p3 hp1 hp2 hp3,\n                       \u27e8s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1,\n                       s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2\u27e9),\n  inf_le_left := \u03bb _ _, set.inter_subset_left _ _,\n  inf_le_right := \u03bb _ _, set.inter_subset_right _ _,\n  le_inf := \u03bb _ _ _, set.subset_inter,\n  top := { carrier := set.univ,\n    smul_vsub_vadd_mem := \u03bb _ _ _ _ _ _ _, set.mem_univ _ },\n  le_top := \u03bb _ _ _, set.mem_univ _,\n  bot := { carrier := \u2205,\n    smul_vsub_vadd_mem := \u03bb _ _ _ _, false.elim },\n  bot_le := \u03bb _ _, false.elim,\n  Sup := \u03bb s, affine_span k (\u22c3 s' \u2208 s, (s' : set P)),\n  Inf := \u03bb s, mk (\u22c2 s' \u2208 s, (s' : set P))\n                 (\u03bb c p1 p2 p3 hp1 hp2 hp3, set.mem_Inter\u2082.2 $ \u03bb s2 hs2, begin\n                   rw set.mem_Inter\u2082 at *,\n                   exact s2.smul_vsub_vadd_mem c (hp1 s2 hs2) (hp2 s2 hs2) (hp3 s2 hs2)\n                 end),\n  le_Sup := \u03bb _ _ h, set.subset.trans (set.subset_bUnion_of_mem h) (subset_span_points k _),\n  Sup_le := \u03bb _ _ h, span_points_subset_coe_of_subset_coe (set.Union\u2082_subset h),\n  Inf_le := \u03bb _ _, set.bInter_subset_of_mem,\n  le_Inf := \u03bb _ _, set.subset_Inter\u2082,\n  .. partial_order.lift (coe : affine_subspace k P \u2192 set P) coe_injective }\n\ninstance : inhabited (affine_subspace k P) := \u27e8\u22a4\u27e9\n\n/-- The `\u2264` order on subspaces is the same as that on the corresponding\nsets. -/\nlemma le_def (s1 s2 : affine_subspace k P) : s1 \u2264 s2 \u2194 (s1 : set P) \u2286 s2 :=\niff.rfl\n\n/-- One subspace is less than or equal to another if and only if all\nits points are in the second subspace. -/\nlemma le_def' (s1 s2 : affine_subspace k P) : s1 \u2264 s2 \u2194 \u2200 p \u2208 s1, p \u2208 s2 :=\niff.rfl\n\n/-- The `<` order on subspaces is the same as that on the corresponding\nsets. -/\nlemma lt_def (s1 s2 : affine_subspace k P) : s1 < s2 \u2194 (s1 : set P) \u2282 s2 :=\niff.rfl\n\n/-- One subspace is not less than or equal to another if and only if\nit has a point not in the second subspace. -/\nlemma not_le_iff_exists (s1 s2 : affine_subspace k P) : \u00ac s1 \u2264 s2 \u2194 \u2203 p \u2208 s1, p \u2209 s2 :=\nset.not_subset\n\n/-- If a subspace is less than another, there is a point only in the\nsecond. -/\nlemma exists_of_lt {s1 s2 : affine_subspace k P} (h : s1 < s2) : \u2203 p \u2208 s2, p \u2209 s1 :=\nset.exists_of_ssubset h\n\n/-- A subspace is less than another if and only if it is less than or\nequal to the second subspace and there is a point only in the\nsecond. -/\nlemma lt_iff_le_and_exists (s1 s2 : affine_subspace k P) : s1 < s2 \u2194 s1 \u2264 s2 \u2227 \u2203 p \u2208 s2, p \u2209 s1 :=\nby rw [lt_iff_le_not_le, not_le_iff_exists]\n\n/-- If an affine subspace is nonempty and contained in another with\nthe same direction, they are equal. -/\nlemma eq_of_direction_eq_of_nonempty_of_le {s\u2081 s\u2082 : affine_subspace k P}\n  (hd : s\u2081.direction = s\u2082.direction) (hn : (s\u2081 : set P).nonempty) (hle : s\u2081 \u2264 s\u2082) :\n  s\u2081 = s\u2082 :=\nlet \u27e8p, hp\u27e9 := hn in ext_of_direction_eq hd \u27e8p, hp, hle hp\u27e9\n\nvariables (k V)\n\n/-- The affine span is the `Inf` of subspaces containing the given\npoints. -/\nlemma affine_span_eq_Inf (s : set P) : affine_span k s = Inf {s' | s \u2286 s'} :=\nle_antisymm (span_points_subset_coe_of_subset_coe $ set.subset_Inter\u2082 $ \u03bb _, id)\n            (Inf_le (subset_span_points k _))\n\nvariables (P)\n\n/-- The Galois insertion formed by `affine_span` and coercion back to\na set. -/\nprotected def gi : galois_insertion (affine_span k) (coe : affine_subspace k P \u2192 set P) :=\n{ choice := \u03bb s _, affine_span k s,\n  gc := \u03bb s1 s2, \u27e8\u03bb h, set.subset.trans (subset_span_points k s1) h,\n                       span_points_subset_coe_of_subset_coe\u27e9,\n  le_l_u := \u03bb _, subset_span_points k _,\n  choice_eq := \u03bb _ _, rfl }\n\n/-- The span of the empty set is `\u22a5`. -/\n@[simp] lemma span_empty : affine_span k (\u2205 : set P) = \u22a5 :=\n(affine_subspace.gi k V P).gc.l_bot\n\n/-- The span of `univ` is `\u22a4`. -/\n@[simp] lemma span_univ : affine_span k (set.univ : set P) = \u22a4 :=\neq_top_iff.2 $ subset_span_points k _\n\nvariables {k V P}\n\nlemma _root_.affine_span_le {s : set P} {Q : affine_subspace k P} :\n  affine_span k s \u2264 Q \u2194 s \u2286 (Q : set P) :=\n(affine_subspace.gi k V P).gc _ _\n\nvariables (k V) {P} {p\u2081 p\u2082 : P}\n\n/-- The affine span of a single point, coerced to a set, contains just\nthat point. -/\n@[simp] lemma coe_affine_span_singleton (p : P) : (affine_span k ({p} : set P) : set P) = {p} :=\nbegin\n  ext x,\n  rw [mem_coe, \u2190vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_singleton p)) _,\n      direction_affine_span],\n  simp\nend\n\n/-- A point is in the affine span of a single point if and only if\nthey are equal. -/\n@[simp] lemma mem_affine_span_singleton : p\u2081 \u2208 affine_span k ({p\u2082} : set P) \u2194 p\u2081 = p\u2082 :=\nby simp [\u2190mem_coe]\n\n@[simp] lemma preimage_coe_affine_span_singleton (x : P) :\n  (coe : affine_span k ({x} : set P) \u2192 P) \u207b\u00b9' {x} = univ :=\neq_univ_of_forall $ \u03bb y, (affine_subspace.mem_affine_span_singleton _ _).1 y.2\n\n/-- The span of a union of sets is the sup of their spans. -/\nlemma span_union (s t : set P) : affine_span k (s \u222a t) = affine_span k s \u2294 affine_span k t :=\n(affine_subspace.gi k V P).gc.l_sup\n\n/-- The span of a union of an indexed family of sets is the sup of\ntheir spans. -/\nlemma span_Union {\u03b9 : Type*} (s : \u03b9 \u2192 set P) :\n  affine_span k (\u22c3 i, s i) = \u2a06 i, affine_span k (s i) :=\n(affine_subspace.gi k V P).gc.l_supr\n\nvariables (P)\n\n/-- `\u22a4`, coerced to a set, is the whole set of points. -/\n@[simp] lemma top_coe : ((\u22a4 : affine_subspace k P) : set P) = set.univ :=\nrfl\n\nvariables {P}\n\n/-- All points are in `\u22a4`. -/\nlemma mem_top (p : P) : p \u2208 (\u22a4 : affine_subspace k P) :=\nset.mem_univ p\n\nvariables (P)\n\n/-- The direction of `\u22a4` is the whole module as a submodule. -/\n@[simp] lemma direction_top : (\u22a4 : affine_subspace k P).direction = \u22a4 :=\nbegin\n  cases S.nonempty with p,\n  ext v,\n  refine \u27e8imp_intro submodule.mem_top, \u03bb hv, _\u27e9,\n  have hpv : (v +\u1d65 p -\u1d65 p : V) \u2208 (\u22a4 : affine_subspace k P).direction :=\n    vsub_mem_direction (mem_top k V _) (mem_top k V _),\n  rwa vadd_vsub at hpv\nend\n\n/-- `\u22a5`, coerced to a set, is the empty set. -/\n@[simp] lemma bot_coe : ((\u22a5 : affine_subspace k P) : set P) = \u2205 :=\nrfl\n\nlemma bot_ne_top : (\u22a5 : affine_subspace k P) \u2260 \u22a4 :=\nbegin\n  intros contra,\n  rw [\u2190 ext_iff, bot_coe, top_coe] at contra,\n  exact set.empty_ne_univ contra,\nend\n\ninstance : nontrivial (affine_subspace k P) := \u27e8\u27e8\u22a5, \u22a4, bot_ne_top k V P\u27e9\u27e9\n\nlemma nonempty_of_affine_span_eq_top {s : set P} (h : affine_span k s = \u22a4) : s.nonempty :=\nbegin\n  rw set.nonempty_iff_ne_empty,\n  rintros rfl,\n  rw affine_subspace.span_empty at h,\n  exact bot_ne_top k V P h,\nend\n\n/-- If the affine span of a set is `\u22a4`, then the vector span of the same set is the `\u22a4`. -/\nlemma vector_span_eq_top_of_affine_span_eq_top {s : set P} (h : affine_span k s = \u22a4) :\n  vector_span k s = \u22a4 :=\nby rw [\u2190 direction_affine_span, h, direction_top]\n\n/-- For a nonempty set, the affine span is `\u22a4` iff its vector span is `\u22a4`. -/\nlemma affine_span_eq_top_iff_vector_span_eq_top_of_nonempty {s : set P} (hs : s.nonempty) :\n  affine_span k s = \u22a4 \u2194 vector_span k s = \u22a4 :=\nbegin\n  refine \u27e8vector_span_eq_top_of_affine_span_eq_top k V P, _\u27e9,\n  intros h,\n  suffices : nonempty (affine_span k s),\n  { obtain \u27e8p, hp : p \u2208 affine_span k s\u27e9 := this,\n    rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affine_span, h, direction_top] },\n  obtain \u27e8x, hx\u27e9 := hs,\n  exact \u27e8\u27e8x, mem_affine_span k hx\u27e9\u27e9,\nend\n\n/-- For a non-trivial space, the affine span of a set is `\u22a4` iff its vector span is `\u22a4`. -/\nlemma affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial {s : set P} [nontrivial P] :\n  affine_span k s = \u22a4 \u2194 vector_span k s = \u22a4 :=\nbegin\n  cases s.eq_empty_or_nonempty with hs hs,\n  { simp [hs, subsingleton_iff_bot_eq_top, add_torsor.subsingleton_iff V P, not_subsingleton], },\n  { rw affine_span_eq_top_iff_vector_span_eq_top_of_nonempty k V P hs, },\nend\n\nlemma card_pos_of_affine_span_eq_top {\u03b9 : Type*} [fintype \u03b9] {p : \u03b9 \u2192 P}\n  (h : affine_span k (range p) = \u22a4) :\n  0 < fintype.card \u03b9 :=\nbegin\n  obtain \u27e8-, \u27e8i, -\u27e9\u27e9 := nonempty_of_affine_span_eq_top k V P h,\n  exact fintype.card_pos_iff.mpr \u27e8i\u27e9,\nend\n\nvariables {P}\n\n/-- No points are in `\u22a5`. -/\nlemma not_mem_bot (p : P) : p \u2209 (\u22a5 : affine_subspace k P) :=\nset.not_mem_empty p\n\nvariables (P)\n\n/-- The direction of `\u22a5` is the submodule `\u22a5`. -/\n@[simp] lemma direction_bot : (\u22a5 : affine_subspace k P).direction = \u22a5 :=\nby rw [direction_eq_vector_span, bot_coe, vector_span_def, vsub_empty, submodule.span_empty]\n\nvariables {k V P}\n\n@[simp] lemma coe_eq_bot_iff (Q : affine_subspace k P) : (Q : set P) = \u2205 \u2194 Q = \u22a5 :=\ncoe_injective.eq_iff' (bot_coe _ _ _)\n\n@[simp] lemma coe_eq_univ_iff (Q : affine_subspace k P) : (Q : set P) = univ \u2194 Q = \u22a4 :=\ncoe_injective.eq_iff' (top_coe _ _ _)\n\nlemma nonempty_iff_ne_bot (Q : affine_subspace k P) : (Q : set P).nonempty \u2194 Q \u2260 \u22a5 :=\nby { rw nonempty_iff_ne_empty, exact not_congr Q.coe_eq_bot_iff }\n\nlemma eq_bot_or_nonempty (Q : affine_subspace k P) : Q = \u22a5 \u2228 (Q : set P).nonempty :=\nby { rw nonempty_iff_ne_bot, apply eq_or_ne }\n\nlemma subsingleton_of_subsingleton_span_eq_top {s : set P} (h\u2081 : s.subsingleton)\n  (h\u2082 : affine_span k s = \u22a4) : subsingleton P :=\nbegin\n  obtain \u27e8p, hp\u27e9 := affine_subspace.nonempty_of_affine_span_eq_top k V P h\u2082,\n  have : s = {p}, { exact subset.antisymm (\u03bb q hq, h\u2081 hq hp) (by simp [hp]), },\n  rw [this, \u2190 affine_subspace.ext_iff, affine_subspace.coe_affine_span_singleton,\n    affine_subspace.top_coe, eq_comm, \u2190 subsingleton_iff_singleton (mem_univ _)] at h\u2082,\n  exact subsingleton_of_univ_subsingleton h\u2082,\nend\n\nlemma eq_univ_of_subsingleton_span_eq_top {s : set P} (h\u2081 : s.subsingleton)\n  (h\u2082 : affine_span k s = \u22a4) : s = (univ : set P) :=\nbegin\n  obtain \u27e8p, hp\u27e9 := affine_subspace.nonempty_of_affine_span_eq_top k V P h\u2082,\n  have : s = {p}, { exact subset.antisymm (\u03bb q hq, h\u2081 hq hp) (by simp [hp]), },\n  rw [this, eq_comm, \u2190 subsingleton_iff_singleton (mem_univ p), subsingleton_univ_iff],\n  exact subsingleton_of_subsingleton_span_eq_top h\u2081 h\u2082,\nend\n\n/-- A nonempty affine subspace is `\u22a4` if and only if its direction is\n`\u22a4`. -/\n@[simp] lemma direction_eq_top_iff_of_nonempty {s : affine_subspace k P}\n  (h : (s : set P).nonempty) : s.direction = \u22a4 \u2194 s = \u22a4 :=\nbegin\n  split,\n  { intro hd,\n    rw \u2190direction_top k V P at hd,\n    refine ext_of_direction_eq hd _,\n    simp [h] },\n  { rintro rfl,\n    simp }\nend\n\n/-- The inf of two affine subspaces, coerced to a set, is the\nintersection of the two sets of points. -/\n@[simp] lemma inf_coe (s1 s2 : affine_subspace k P) : ((s1 \u2293 s2) : set P) = s1 \u2229 s2 :=\nrfl\n\n/-- A point is in the inf of two affine subspaces if and only if it is\nin both of them. -/\nlemma mem_inf_iff (p : P) (s1 s2 : affine_subspace k P) : p \u2208 s1 \u2293 s2 \u2194 p \u2208 s1 \u2227 p \u2208 s2 :=\niff.rfl\n\n/-- The direction of the inf of two affine subspaces is less than or\nequal to the inf of their directions. -/\nlemma direction_inf (s1 s2 : affine_subspace k P) :\n  (s1 \u2293 s2).direction \u2264 s1.direction \u2293 s2.direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact le_inf\n    (Inf_le_Inf (\u03bb p hp, trans (vsub_self_mono (inter_subset_left _ _)) hp))\n    (Inf_le_Inf (\u03bb p hp, trans (vsub_self_mono (inter_subset_right _ _)) hp))\nend\n\n/-- If two affine subspaces have a point in common, the direction of\ntheir inf equals the inf of their directions. -/\nlemma direction_inf_of_mem {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h\u2081 : p \u2208 s\u2081) (h\u2082 : p \u2208 s\u2082) :\n  (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\nbegin\n  ext v,\n  rw [submodule.mem_inf, \u2190vadd_mem_iff_mem_direction v h\u2081, \u2190vadd_mem_iff_mem_direction v h\u2082,\n      \u2190vadd_mem_iff_mem_direction v ((mem_inf_iff p s\u2081 s\u2082).2 \u27e8h\u2081, h\u2082\u27e9), mem_inf_iff]\nend\n\n/-- If two affine subspaces have a point in their inf, the direction\nof their inf equals the inf of their directions. -/\nlemma direction_inf_of_mem_inf {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h : p \u2208 s\u2081 \u2293 s\u2082) :\n  (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\ndirection_inf_of_mem ((mem_inf_iff p s\u2081 s\u2082).1 h).1 ((mem_inf_iff p s\u2081 s\u2082).1 h).2\n\n/-- If one affine subspace is less than or equal to another, the same\napplies to their directions. -/\nlemma direction_le {s1 s2 : affine_subspace k P} (h : s1 \u2264 s2) : s1.direction \u2264 s2.direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact vector_span_mono k h\nend\n\n/-- If one nonempty affine subspace is less than another, the same\napplies to their directions -/\nlemma direction_lt_of_nonempty {s1 s2 : affine_subspace k P} (h : s1 < s2)\n    (hn : (s1 : set P).nonempty) : s1.direction < s2.direction :=\nbegin\n  cases hn with p hp,\n  rw lt_iff_le_and_exists at h,\n  rcases h with \u27e8hle, p2, hp2, hp2s1\u27e9,\n  rw set_like.lt_iff_le_and_exists,\n  use [direction_le hle, p2 -\u1d65 p, vsub_mem_direction hp2 (hle hp)],\n  intro hm,\n  rw vsub_right_mem_direction_iff_mem hp p2 at hm,\n  exact hp2s1 hm\nend\n\n/-- The sup of the directions of two affine subspaces is less than or\nequal to the direction of their sup. -/\nlemma sup_direction_le (s1 s2 : affine_subspace k P) :\n  s1.direction \u2294 s2.direction \u2264 (s1 \u2294 s2).direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact sup_le\n    (Inf_le_Inf (\u03bb p hp, set.subset.trans (vsub_self_mono (le_sup_left : s1 \u2264 s1 \u2294 s2)) hp))\n    (Inf_le_Inf (\u03bb p hp, set.subset.trans (vsub_self_mono (le_sup_right : s2 \u2264 s1 \u2294 s2)) hp))\nend\n\n/-- The sup of the directions of two nonempty affine subspaces with\nempty intersection is less than the direction of their sup. -/\nlemma sup_direction_lt_of_nonempty_of_inter_empty {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty) (he : (s1 \u2229 s2 : set P) = \u2205) :\n  s1.direction \u2294 s2.direction < (s1 \u2294 s2).direction :=\nbegin\n  cases h1 with p1 hp1,\n  cases h2 with p2 hp2,\n  rw set_like.lt_iff_le_and_exists,\n  use [sup_direction_le s1 s2, p2 -\u1d65 p1,\n       vsub_mem_direction ((le_sup_right : s2 \u2264 s1 \u2294 s2) hp2) ((le_sup_left : s1 \u2264 s1 \u2294 s2) hp1)],\n  intro h,\n  rw submodule.mem_sup at h,\n  rcases h with \u27e8v1, hv1, v2, hv2, hv1v2\u27e9,\n  rw [\u2190sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc,\n      \u2190vadd_vsub_assoc, \u2190neg_neg v2, add_comm, \u2190sub_eq_add_neg, \u2190vsub_vadd_eq_vsub_sub,\n      vsub_eq_zero_iff_eq] at hv1v2,\n  refine set.nonempty.ne_empty _ he,\n  use [v1 +\u1d65 p1, vadd_mem_of_mem_direction hv1 hp1],\n  rw hv1v2,\n  exact vadd_mem_of_mem_direction (submodule.neg_mem _ hv2) hp2\nend\n\n/-- If the directions of two nonempty affine subspaces span the whole\nmodule, they have nonempty intersection. -/\nlemma inter_nonempty_of_nonempty_of_sup_direction_eq_top {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)\n    (hd : s1.direction \u2294 s2.direction = \u22a4) : ((s1 : set P) \u2229 s2).nonempty :=\nbegin\n  by_contradiction h,\n  rw set.not_nonempty_iff_eq_empty at h,\n  have hlt := sup_direction_lt_of_nonempty_of_inter_empty h1 h2 h,\n  rw hd at hlt,\n  exact not_top_lt hlt\nend\n\n/-- If the directions of two nonempty affine subspaces are complements\nof each other, they intersect in exactly one point. -/\nlemma inter_eq_singleton_of_nonempty_of_is_compl {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)\n    (hd : is_compl s1.direction s2.direction) : \u2203 p, (s1 : set P) \u2229 s2 = {p} :=\nbegin\n  cases inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top with p hp,\n  use p,\n  ext q,\n  rw set.mem_singleton_iff,\n  split,\n  { rintros \u27e8hq1, hq2\u27e9,\n    have hqp : q -\u1d65 p \u2208 s1.direction \u2293 s2.direction :=\n      \u27e8vsub_mem_direction hq1 hp.1, vsub_mem_direction hq2 hp.2\u27e9,\n    rwa [hd.inf_eq_bot, submodule.mem_bot, vsub_eq_zero_iff_eq] at hqp },\n  { exact \u03bb h, h.symm \u25b8 hp }\nend\n\n/-- Coercing a subspace to a set then taking the affine span produces\nthe original subspace. -/\n@[simp] lemma affine_span_coe (s : affine_subspace k P) : affine_span k (s : set P) = s :=\nbegin\n  refine le_antisymm _ (subset_span_points _ _),\n  rintros p \u27e8p1, hp1, v, hv, rfl\u27e9,\n  exact vadd_mem_of_mem_direction hv hp1\nend\n\nend affine_subspace\n\nsection affine_space'\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\nvariables {\u03b9 : Type*}\ninclude V\n\nopen affine_subspace set\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left. -/\nlemma vector_span_eq_span_vsub_set_left {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65) p '' s) :=\nbegin\n  rw vector_span_def,\n  refine le_antisymm _ (submodule.span_mono _),\n  { rw submodule.span_le,\n    rintros v \u27e8p1, p2, hp1, hp2, hv\u27e9,\n    rw \u2190vsub_sub_vsub_cancel_left p1 p2 p at hv,\n    rw [\u2190hv, set_like.mem_coe, submodule.mem_span],\n    exact \u03bb m hm, submodule.sub_mem _ (hm \u27e8p2, hp2, rfl\u27e9) (hm \u27e8p1, hp1, rfl\u27e9) },\n  { rintros v \u27e8p2, hp2, hv\u27e9,\n    exact \u27e8p, p2, hp, hp2, hv\u27e9 }\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right. -/\nlemma vector_span_eq_span_vsub_set_right {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65 p) '' s) :=\nbegin\n  rw vector_span_def,\n  refine le_antisymm _ (submodule.span_mono _),\n  { rw submodule.span_le,\n    rintros v \u27e8p1, p2, hp1, hp2, hv\u27e9,\n    rw \u2190vsub_sub_vsub_cancel_right p1 p2 p at hv,\n    rw [\u2190hv, set_like.mem_coe, submodule.mem_span],\n    exact \u03bb m hm, submodule.sub_mem _ (hm \u27e8p1, hp1, rfl\u27e9) (hm \u27e8p2, hp2, rfl\u27e9) },\n  { rintros v \u27e8p2, hp2, hv\u27e9,\n    exact \u27e8p2, p, hp2, hp, hv\u27e9 }\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_set_left_ne {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65) p '' (s \\ {p})) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_left k hp, \u2190set.insert_eq_of_mem hp,\n                 \u2190set.insert_diff_singleton, set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_set_right_ne {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65 p) '' (s \\ {p})) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_right k hp, \u2190set.insert_eq_of_mem hp,\n                 \u2190set.insert_diff_singleton, set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_finset_right_ne [decidable_eq P] [decidable_eq V] {s : finset P}\n  {p : P} (hp : p \u2208 s) :\n  vector_span k (s : set P) = submodule.span k ((s.erase p).image (-\u1d65 p)) :=\nby simp [vector_span_eq_span_vsub_set_right_ne _ (finset.mem_coe.mpr hp)]\n\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the left, excluding the\nsubtraction of that point from itself. -/\nlemma vector_span_image_eq_span_vsub_set_left_ne (p : \u03b9 \u2192 P) {s : set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  vector_span k (p '' s) = submodule.span k ((-\u1d65) (p i) '' (p '' (s \\ {i}))) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_left k (set.mem_image_of_mem p hi),\n                 \u2190set.insert_eq_of_mem hi, \u2190set.insert_diff_singleton, set.image_insert_eq,\n                 set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the right, excluding the\nsubtraction of that point from itself. -/\nlemma vector_span_image_eq_span_vsub_set_right_ne (p : \u03b9 \u2192 P) {s : set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  vector_span k (p '' s) = submodule.span k ((-\u1d65 (p i)) '' (p '' (s \\ {i}))) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_right k (set.mem_image_of_mem p hi),\n                 \u2190set.insert_eq_of_mem hi, \u2190set.insert_diff_singleton, set.image_insert_eq,\n                 set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left. -/\nlemma vector_span_range_eq_span_range_vsub_left (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : \u03b9), p i0 -\u1d65 p i)) :=\nby rw [vector_span_eq_span_vsub_set_left k (set.mem_range_self i0), \u2190set.range_comp]\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right. -/\nlemma vector_span_range_eq_span_range_vsub_right (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : \u03b9), p i -\u1d65 p i0)) :=\nby rw [vector_span_eq_span_vsub_set_right k (set.mem_range_self i0), \u2190set.range_comp]\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left, excluding the subtraction\nof that point from itself. -/\nlemma vector_span_range_eq_span_range_vsub_left_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : {x // x \u2260 i\u2080}), p i\u2080 -\u1d65 p i)) :=\nbegin\n  rw [\u2190set.image_univ, vector_span_image_eq_span_vsub_set_left_ne k _ (set.mem_univ i\u2080)],\n  congr' with v,\n  simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,\n             subtype.coe_mk],\n  split,\n  { rintros \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9,\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9 },\n  { exact \u03bb \u27e8i\u2081, hi\u2081, hv\u27e9, \u27e8p i\u2081, \u27e8i\u2081, \u27e8set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9 }\nend\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right, excluding the subtraction\nof that point from itself. -/\nlemma vector_span_range_eq_span_range_vsub_right_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : {x // x \u2260 i\u2080}), p i -\u1d65 p i\u2080)) :=\nbegin\n  rw [\u2190set.image_univ, vector_span_image_eq_span_vsub_set_right_ne k _ (set.mem_univ i\u2080)],\n  congr' with v,\n  simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,\n             subtype.coe_mk],\n  split,\n  { rintros \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9,\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9 },\n  { exact \u03bb \u27e8i\u2081, hi\u2081, hv\u27e9, \u27e8p i\u2081, \u27e8i\u2081, \u27e8set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9 }\nend\n\nsection\nvariables {s : set P}\n\n/-- The affine span of a set is nonempty if and only if that set is. -/\nlemma affine_span_nonempty : (affine_span k s : set P).nonempty \u2194 s.nonempty :=\nspan_points_nonempty k s\n\nalias affine_span_nonempty \u2194 _ _root_.set.nonempty.affine_span\n\n/-- The affine span of a nonempty set is nonempty. -/\ninstance [nonempty s] : nonempty (affine_span k s) :=\n((nonempty_coe_sort.1 \u2039_\u203a).affine_span _).to_subtype\n\n/-- The affine span of a set is `\u22a5` if and only if that set is empty. -/\n@[simp] lemma affine_span_eq_bot : affine_span k s = \u22a5 \u2194 s = \u2205 :=\nby rw [\u2190not_iff_not, \u2190ne.def, \u2190ne.def, \u2190nonempty_iff_ne_bot, affine_span_nonempty,\n       nonempty_iff_ne_empty]\n\n@[simp] lemma bot_lt_affine_span : \u22a5 < affine_span k s \u2194 s.nonempty :=\nby { rw [bot_lt_iff_ne_bot, nonempty_iff_ne_empty], exact (affine_span_eq_bot _).not }\n\nend\n\nvariables {k}\n\n/--\nAn induction principle for span membership. If `p` holds for all elements of `s` and is\npreserved under certain affine combinations, then `p` holds for all elements of the span of `s`.\n-/\nlemma affine_span_induction {x : P} {s : set P} {p : P \u2192 Prop} (h : x \u2208 affine_span k s)\n  (Hs : \u2200 x : P, x \u2208 s \u2192 p x)\n  (Hc : \u2200 (c : k) (u v w : P), p u \u2192 p v \u2192 p w \u2192 p (c \u2022 (u -\u1d65 v) +\u1d65 w)) : p x :=\n(@affine_span_le _ _ _ _ _ _ _ _ \u27e8p, Hc\u27e9).mpr Hs h\n\n/-- A dependent version of `affine_span_induction`. -/\nlemma affine_span_induction' {s : set P} {p : \u03a0 x, x \u2208 affine_span k s \u2192 Prop}\n  (Hs : \u2200 y (hys : y \u2208 s), p y (subset_affine_span k _ hys))\n  (Hc : \u2200 (c : k) u hu v hv w hw, p u hu \u2192 p v hv \u2192 p w hw \u2192\n    p (c \u2022 (u -\u1d65 v) +\u1d65 w) (affine_subspace.smul_vsub_vadd_mem _ _ hu hv hw))\n  {x : P} (h : x \u2208 affine_span k s) : p x h :=\nbegin\n  refine exists.elim _ (\u03bb (hx : x \u2208 affine_span k s) (hc : p x hx), hc),\n  refine @affine_span_induction k V P _ _ _ _ _ _ _ h _ _,\n  { exact (\u03bb y hy, \u27e8subset_affine_span _ _ hy, Hs y hy\u27e9) },\n  { exact (\u03bb c u v w hu hv hw, exists.elim hu $ \u03bb hu' hu, exists.elim hv $ \u03bb hv' hv,\n      exists.elim hw $ \u03bb hw' hw,\n        \u27e8affine_subspace.smul_vsub_vadd_mem _ _ hu' hv' hw', Hc _ _ _ _ _ _ _ hu hv hw\u27e9) },\nend\n\nsection with_local_instance\n\nlocal attribute [instance] affine_subspace.to_add_torsor\n\n/-- A set, considered as a subset of its spanned affine subspace, spans the whole subspace. -/\n@[simp] lemma affine_span_coe_preimage_eq_top (A : set P) [nonempty A] :\n  affine_span k ((coe : affine_span k A \u2192 P) \u207b\u00b9' A) = \u22a4 :=\nbegin\n  rw [eq_top_iff],\n  rintro \u27e8x, hx\u27e9 -,\n  refine affine_span_induction' (\u03bb y hy, _) (\u03bb c u hu v hv w hw, _) hx,\n  { exact subset_affine_span _ _ hy },\n  { exact affine_subspace.smul_vsub_vadd_mem _ _ },\nend\n\nend with_local_instance\n\n/-- Suppose a set of vectors spans `V`.  Then a point `p`, together\nwith those vectors added to `p`, spans `P`. -/\nlemma affine_span_singleton_union_vadd_eq_top_of_span_eq_top {s : set V} (p : P)\n    (h : submodule.span k (set.range (coe : s \u2192 V)) = \u22a4) :\n  affine_span k ({p} \u222a (\u03bb v, v +\u1d65 p) '' s) = \u22a4 :=\nbegin\n  convert ext_of_direction_eq _\n    \u27e8p,\n     mem_affine_span k (set.mem_union_left _ (set.mem_singleton _)),\n     mem_top k V p\u27e9,\n  rw [direction_affine_span, direction_top,\n      vector_span_eq_span_vsub_set_right k\n        ((set.mem_union_left _ (set.mem_singleton _)) : p \u2208 _), eq_top_iff, \u2190h],\n  apply submodule.span_mono,\n  rintros v \u27e8v', rfl\u27e9,\n  use (v' : V) +\u1d65 p,\n  simp\nend\n\nvariables (k)\n\n/-- The `vector_span` of two points is the span of their difference. -/\nlemma vector_span_pair (p\u2081 p\u2082 : P) : vector_span k ({p\u2081, p\u2082} : set P) = k \u2219 (p\u2081 -\u1d65 p\u2082) :=\nby rw [vector_span_eq_span_vsub_set_left k (mem_insert p\u2081 _), image_pair, vsub_self,\n       submodule.span_insert_zero]\n\n/-- The `vector_span` of two points is the span of their difference (reversed). -/\nlemma vector_span_pair_rev (p\u2081 p\u2082 : P) : vector_span k ({p\u2081, p\u2082} : set P) = k \u2219 (p\u2082 -\u1d65 p\u2081) :=\nby rw [pair_comm, vector_span_pair]\n\n/-- The difference between two points lies in their `vector_span`. -/\nlemma vsub_mem_vector_span_pair (p\u2081 p\u2082 : P) : p\u2081 -\u1d65 p\u2082 \u2208 vector_span k ({p\u2081, p\u2082} : set P) :=\nvsub_mem_vector_span _ (set.mem_insert _ _) (set.mem_insert_of_mem _ (set.mem_singleton _))\n\n/-- The difference between two points (reversed) lies in their `vector_span`. -/\nlemma vsub_rev_mem_vector_span_pair (p\u2081 p\u2082 : P) : p\u2082 -\u1d65 p\u2081 \u2208 vector_span k ({p\u2081, p\u2082} : set P) :=\nvsub_mem_vector_span _ (set.mem_insert_of_mem _ (set.mem_singleton _)) (set.mem_insert _ _)\n\nvariables {k}\n\n/-- A multiple of the difference between two points lies in their `vector_span`. -/\nlemma smul_vsub_mem_vector_span_pair (r : k) (p\u2081 p\u2082 : P) :\n  r \u2022 (p\u2081 -\u1d65 p\u2082) \u2208 vector_span k ({p\u2081, p\u2082} : set P) :=\nsubmodule.smul_mem _ _ (vsub_mem_vector_span_pair k p\u2081 p\u2082)\n\n/-- A multiple of the difference between two points (reversed) lies in their `vector_span`. -/\nlemma smul_vsub_rev_mem_vector_span_pair (r : k) (p\u2081 p\u2082 : P) :\n  r \u2022 (p\u2082 -\u1d65 p\u2081) \u2208 vector_span k ({p\u2081, p\u2082} : set P) :=\nsubmodule.smul_mem _ _ (vsub_rev_mem_vector_span_pair k p\u2081 p\u2082)\n\n/-- A vector lies in the `vector_span` of two points if and only if it is a multiple of their\ndifference. -/\nlemma mem_vector_span_pair {p\u2081 p\u2082 : P} {v : V} :\n  v \u2208 vector_span k ({p\u2081, p\u2082} : set P) \u2194 \u2203 r : k, r \u2022 (p\u2081 -\u1d65 p\u2082) = v :=\nby rw [vector_span_pair, submodule.mem_span_singleton]\n\n/-- A vector lies in the `vector_span` of two points if and only if it is a multiple of their\ndifference (reversed). -/\nlemma mem_vector_span_pair_rev {p\u2081 p\u2082 : P} {v : V} :\n  v \u2208 vector_span k ({p\u2081, p\u2082} : set P) \u2194 \u2203 r : k, r \u2022 (p\u2082 -\u1d65 p\u2081) = v :=\nby rw [vector_span_pair_rev, submodule.mem_span_singleton]\n\nvariables (k)\n\nnotation `line[` k `, ` p\u2081 `, ` p\u2082 `]` :=\naffine_span k (insert p\u2081 (@singleton _ _ set.has_singleton p\u2082))\n\n/-- The first of two points lies in their affine span. -/\nlemma left_mem_affine_span_pair (p\u2081 p\u2082 : P) : p\u2081 \u2208 line[k, p\u2081, p\u2082] :=\nmem_affine_span _ (set.mem_insert _ _)\n\n/-- The second of two points lies in their affine span. -/\nlemma right_mem_affine_span_pair (p\u2081 p\u2082 : P) : p\u2082 \u2208 line[k, p\u2081, p\u2082] :=\nmem_affine_span _ (set.mem_insert_of_mem _ (set.mem_singleton _))\n\nvariables {k}\n\n/-- A combination of two points expressed with `line_map` lies in their affine span. -/\nlemma affine_map.line_map_mem_affine_span_pair (r : k) (p\u2081 p\u2082 : P) :\n  affine_map.line_map p\u2081 p\u2082 r \u2208 line[k, p\u2081, p\u2082] :=\naffine_map.line_map_mem _ (left_mem_affine_span_pair _ _ _) (right_mem_affine_span_pair _ _ _)\n\n/-- A combination of two points expressed with `line_map` (with the two points reversed) lies in\ntheir affine span. -/\nlemma affine_map.line_map_rev_mem_affine_span_pair (r : k) (p\u2081 p\u2082 : P) :\n  affine_map.line_map p\u2082 p\u2081 r \u2208 line[k, p\u2081, p\u2082] :=\naffine_map.line_map_mem _ (right_mem_affine_span_pair _ _ _) (left_mem_affine_span_pair _ _ _)\n\n/-- A multiple of the difference of two points added to the first point lies in their affine\nspan. -/\nlemma smul_vsub_vadd_mem_affine_span_pair (r : k) (p\u2081 p\u2082 : P) :\n  r \u2022 (p\u2082 -\u1d65 p\u2081) +\u1d65 p\u2081 \u2208 line[k, p\u2081, p\u2082] :=\naffine_map.line_map_mem_affine_span_pair _ _ _\n\n/-- A multiple of the difference of two points added to the second point lies in their affine\nspan. -/\nlemma smul_vsub_rev_vadd_mem_affine_span_pair (r : k) (p\u2081 p\u2082 : P) :\n  r \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2082 \u2208 line[k, p\u2081, p\u2082] :=\naffine_map.line_map_rev_mem_affine_span_pair _ _ _\n\n/-- A vector added to the first point lies in the affine span of two points if and only if it is\na multiple of their difference. -/\nlemma vadd_left_mem_affine_span_pair {p\u2081 p\u2082 : P} {v : V} :\n  v +\u1d65 p\u2081 \u2208 line[k, p\u2081, p\u2082] \u2194 \u2203 r : k, r \u2022 (p\u2082 -\u1d65 p\u2081) = v :=\nby rw [vadd_mem_iff_mem_direction _ (left_mem_affine_span_pair _ _ _), direction_affine_span,\n       mem_vector_span_pair_rev]\n\n/-- A vector added to the second point lies in the affine span of two points if and only if it is\na multiple of their difference. -/\nlemma vadd_right_mem_affine_span_pair {p\u2081 p\u2082 : P} {v : V} :\n  v +\u1d65 p\u2082 \u2208 line[k, p\u2081, p\u2082] \u2194 \u2203 r : k, r \u2022 (p\u2081 -\u1d65 p\u2082) = v :=\nby rw [vadd_mem_iff_mem_direction _ (right_mem_affine_span_pair _ _ _), direction_affine_span,\n       mem_vector_span_pair]\n\n/-- The span of two points that lie in an affine subspace is contained in that subspace. -/\nlemma affine_span_pair_le_of_mem_of_mem {p\u2081 p\u2082 : P} {s : affine_subspace k P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) : line[k, p\u2081, p\u2082] \u2264 s :=\nbegin\n  rw [affine_span_le, set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8hp\u2081, hp\u2082\u27e9\nend\n\n/-- One line is contained in another differing in the first point if the first point of the first\nline is contained in the second line. -/\nlemma affine_span_pair_le_of_left_mem {p\u2081 p\u2082 p\u2083 : P} (h : p\u2081 \u2208 line[k, p\u2082, p\u2083]) :\n  line[k, p\u2081, p\u2083] \u2264 line[k, p\u2082, p\u2083] :=\naffine_span_pair_le_of_mem_of_mem h (right_mem_affine_span_pair _ _ _)\n\n/-- One line is contained in another differing in the second point if the second point of the\nfirst line is contained in the second line. -/\nlemma affine_span_pair_le_of_right_mem {p\u2081 p\u2082 p\u2083 : P} (h : p\u2081 \u2208 line[k, p\u2082, p\u2083]) :\n  line[k, p\u2082, p\u2081] \u2264 line[k, p\u2082, p\u2083] :=\naffine_span_pair_le_of_mem_of_mem (left_mem_affine_span_pair _ _ _) h\n\nvariables (k)\n\n/-- `affine_span` is monotone. -/\n@[mono]\nlemma affine_span_mono {s\u2081 s\u2082 : set P} (h : s\u2081 \u2286 s\u2082) : affine_span k s\u2081 \u2264 affine_span k s\u2082 :=\nspan_points_subset_coe_of_subset_coe (set.subset.trans h (subset_affine_span k _))\n\n/-- Taking the affine span of a set, adding a point and taking the\nspan again produces the same results as adding the point to the set\nand taking the span. -/\nlemma affine_span_insert_affine_span (p : P) (ps : set P) :\n  affine_span k (insert p (affine_span k ps : set P)) = affine_span k (insert p ps) :=\nby rw [set.insert_eq, set.insert_eq, span_union, span_union, affine_span_coe]\n\n/-- If a point is in the affine span of a set, adding it to that set\ndoes not change the affine span. -/\nlemma affine_span_insert_eq_affine_span {p : P} {ps : set P} (h : p \u2208 affine_span k ps) :\n  affine_span k (insert p ps) = affine_span k ps :=\nbegin\n  rw \u2190mem_coe at h,\n  rw [\u2190affine_span_insert_affine_span, set.insert_eq_of_mem h, affine_span_coe]\nend\n\nvariables {k}\n\n/-- If a point is in the affine span of a set, adding it to that set\ndoes not change the vector span. -/\nlemma vector_span_insert_eq_vector_span {p : P} {ps : set P} (h : p \u2208 affine_span k ps) :\n  vector_span k (insert p ps) = vector_span k ps :=\nby simp_rw [\u2190direction_affine_span, affine_span_insert_eq_affine_span _ h]\n\nend affine_space'\n\nnamespace affine_subspace\n\nvariables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\n/-- The direction of the sup of two nonempty affine subspaces is the\nsup of the two directions and of any one difference between points in\nthe two subspaces. -/\nlemma direction_sup {s1 s2 : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s1) (hp2 : p2 \u2208 s2) :\n  (s1 \u2294 s2).direction = s1.direction \u2294 s2.direction \u2294 k \u2219 (p2 -\u1d65 p1) :=\nbegin\n  refine le_antisymm _ _,\n  { change (affine_span k ((s1 : set P) \u222a s2)).direction \u2264 _,\n    rw \u2190mem_coe at hp1,\n    rw [direction_affine_span, vector_span_eq_span_vsub_set_right k (set.mem_union_left _ hp1),\n        submodule.span_le],\n    rintros v \u27e8p3, hp3, rfl\u27e9,\n    cases hp3,\n    { rw [sup_assoc, sup_comm, set_like.mem_coe, submodule.mem_sup],\n      use [0, submodule.zero_mem _, p3 -\u1d65 p1, vsub_mem_direction hp3 hp1],\n      rw zero_add },\n    { rw [sup_assoc, set_like.mem_coe, submodule.mem_sup],\n      use [0, submodule.zero_mem _, p3 -\u1d65 p1],\n      rw [and_comm, zero_add],\n      use rfl,\n      rw [\u2190vsub_add_vsub_cancel p3 p2 p1, submodule.mem_sup],\n      use [p3 -\u1d65 p2, vsub_mem_direction hp3 hp2, p2 -\u1d65 p1,\n           submodule.mem_span_singleton_self _] } },\n  { refine sup_le (sup_direction_le _ _) _,\n    rw [direction_eq_vector_span, vector_span_def],\n    exact Inf_le_Inf (\u03bb p hp, set.subset.trans\n      (set.singleton_subset_iff.2\n        (vsub_mem_vsub (mem_span_points k p2 _ (set.mem_union_right _ hp2))\n                       (mem_span_points k p1 _ (set.mem_union_left _ hp1))))\n      hp) }\nend\n\n/-- The direction of the span of the result of adding a point to a\nnonempty affine subspace is the sup of the direction of that subspace\nand of any one difference between that point and a point in the\nsubspace. -/\nlemma direction_affine_span_insert {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) :\n  (affine_span k (insert p2 (s : set P))).direction = submodule.span k {p2 -\u1d65 p1} \u2294 s.direction :=\nbegin\n  rw [sup_comm, \u2190set.union_singleton, \u2190coe_affine_span_singleton k V p2],\n  change (s \u2294 affine_span k {p2}).direction = _,\n  rw [direction_sup hp1 (mem_affine_span k (set.mem_singleton _)), direction_affine_span],\n  simp\nend\n\n/-- Given a point `p1` in an affine subspace `s`, and a point `p2`, a\npoint `p` is in the span of `s` with `p2` added if and only if it is a\nmultiple of `p2 -\u1d65 p1` added to a point in `s`. -/\nlemma mem_affine_span_insert_iff {s : affine_subspace k P} {p1 : P} (hp1 : p1 \u2208 s) (p2 p : P) :\n  p \u2208 affine_span k (insert p2 (s : set P)) \u2194\n    \u2203 (r : k) (p0 : P) (hp0 : p0 \u2208 s), p = r \u2022 (p2 -\u1d65 p1 : V) +\u1d65 p0 :=\nbegin\n  rw \u2190mem_coe at hp1,\n  rw [\u2190vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_insert_of_mem _ hp1)),\n      direction_affine_span_insert hp1, submodule.mem_sup],\n  split,\n  { rintros \u27e8v1, hv1, v2, hv2, hp\u27e9,\n    rw submodule.mem_span_singleton at hv1,\n    rcases hv1 with \u27e8r, rfl\u27e9,\n    use [r, v2 +\u1d65 p1, vadd_mem_of_mem_direction hv2 hp1],\n    symmetry' at hp,\n    rw [\u2190sub_eq_zero, \u2190vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hp,\n    rw [hp, vadd_vadd] },\n  { rintros \u27e8r, p3, hp3, rfl\u27e9,\n    use [r \u2022 (p2 -\u1d65 p1), submodule.mem_span_singleton.2 \u27e8r, rfl\u27e9, p3 -\u1d65 p1,\n         vsub_mem_direction hp3 hp1],\n    rw [vadd_vsub_assoc, add_comm] }\nend\n\nend affine_subspace\n\nsection map_comap\n\nvariables {k V\u2081 P\u2081 V\u2082 P\u2082 V\u2083 P\u2083 : Type*} [ring k]\nvariables [add_comm_group V\u2081] [module k V\u2081] [add_torsor V\u2081 P\u2081]\nvariables [add_comm_group V\u2082] [module k V\u2082] [add_torsor V\u2082 P\u2082]\nvariables [add_comm_group V\u2083] [module k V\u2083] [add_torsor V\u2083 P\u2083]\ninclude V\u2081 V\u2082\n\nsection\n\nvariables (f : P\u2081 \u2192\u1d43[k] P\u2082)\n\n@[simp] lemma affine_map.vector_span_image_eq_submodule_map {s : set P\u2081} :\n  submodule.map f.linear (vector_span k s) = vector_span k (f '' s) :=\nby simp [f.image_vsub_image, vector_span_def]\n\nnamespace affine_subspace\n\n/-- The image of an affine subspace under an affine map as an affine subspace. -/\ndef map (s : affine_subspace k P\u2081) : affine_subspace k P\u2082 :=\n{ carrier := f '' s,\n  smul_vsub_vadd_mem :=\n    begin\n      rintros t - - - \u27e8p\u2081, h\u2081, rfl\u27e9 \u27e8p\u2082, h\u2082, rfl\u27e9 \u27e8p\u2083, h\u2083, rfl\u27e9,\n      use t \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2083,\n      suffices : t \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2083 \u2208 s, { simp [this], },\n      exact s.smul_vsub_vadd_mem t h\u2081 h\u2082 h\u2083,\n    end }\n\n@[simp] lemma coe_map (s : affine_subspace k P\u2081) : (s.map f : set P\u2082) = f '' s := rfl\n\n@[simp] lemma mem_map {f : P\u2081 \u2192\u1d43[k] P\u2082} {x : P\u2082} {s : affine_subspace k P\u2081} :\n  x \u2208 s.map f \u2194 \u2203 y \u2208 s, f y = x := mem_image_iff_bex\n\nlemma mem_map_of_mem {x : P\u2081} {s : affine_subspace k P\u2081} (h : x \u2208 s) : f x \u2208 s.map f :=\nset.mem_image_of_mem _ h\n\nlemma mem_map_iff_mem_of_injective {f : P\u2081 \u2192\u1d43[k] P\u2082} {x : P\u2081} {s : affine_subspace k P\u2081}\n  (hf : function.injective f) : f x \u2208 s.map f \u2194 x \u2208 s :=\nhf.mem_set_image\n\n@[simp] lemma map_bot : (\u22a5 : affine_subspace k P\u2081).map f = \u22a5 :=\ncoe_injective $ image_empty f\n\n@[simp] lemma map_eq_bot_iff {s : affine_subspace k P\u2081} : s.map f = \u22a5 \u2194 s = \u22a5 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rwa [\u2190coe_eq_bot_iff, coe_map, image_eq_empty, coe_eq_bot_iff] at h },\n  { rw [h, map_bot] }\nend\n\nomit V\u2082\n\n@[simp] lemma map_id (s : affine_subspace k P\u2081) : s.map (affine_map.id k P\u2081) = s :=\ncoe_injective $ image_id _\n\ninclude V\u2082 V\u2083\n\nlemma map_map (s : affine_subspace k P\u2081) (f : P\u2081 \u2192\u1d43[k] P\u2082) (g : P\u2082 \u2192\u1d43[k] P\u2083) :\n  (s.map f).map g = s.map (g.comp f) :=\ncoe_injective $ image_image _ _ _\n\nomit V\u2083\n\n@[simp] lemma map_direction (s : affine_subspace k P\u2081) :\n  (s.map f).direction = s.direction.map f.linear :=\nby simp [direction_eq_vector_span]\n\nlemma map_span (s : set P\u2081) :\n  (affine_span k s).map f = affine_span k (f '' s) :=\nbegin\n  rcases s.eq_empty_or_nonempty with rfl | \u27e8p, hp\u27e9, { simp, },\n  apply ext_of_direction_eq,\n  { simp [direction_affine_span], },\n  { exact \u27e8f p, mem_image_of_mem f (subset_affine_span k _ hp),\n                subset_affine_span k _ (mem_image_of_mem f hp)\u27e9, },\nend\n\nend affine_subspace\n\nnamespace affine_map\n\n@[simp] lemma map_top_of_surjective (hf : function.surjective f) : affine_subspace.map f \u22a4 = \u22a4 :=\nbegin\n  rw \u2190 affine_subspace.ext_iff,\n  exact image_univ_of_surjective hf,\nend\n\nlemma span_eq_top_of_surjective {s : set P\u2081}\n  (hf : function.surjective f) (h : affine_span k s = \u22a4) :\n  affine_span k (f '' s) = \u22a4 :=\nby rw [\u2190 affine_subspace.map_span, h, map_top_of_surjective f hf]\n\nend affine_map\n\nnamespace affine_equiv\n\nlemma span_eq_top_iff {s : set P\u2081} (e : P\u2081 \u2243\u1d43[k] P\u2082) :\n  affine_span k s = \u22a4 \u2194 affine_span k (e '' s) = \u22a4 :=\nbegin\n  refine \u27e8(e : P\u2081 \u2192\u1d43[k] P\u2082).span_eq_top_of_surjective e.surjective, _\u27e9,\n  intros h,\n  have : s = e.symm '' (e '' s), { simp [\u2190 image_comp], },\n  rw this,\n  exact (e.symm : P\u2082 \u2192\u1d43[k] P\u2081).span_eq_top_of_surjective e.symm.surjective h,\nend\n\nend affine_equiv\n\nend\n\nnamespace affine_subspace\n\n/-- The preimage of an affine subspace under an affine map as an affine subspace. -/\ndef comap (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : affine_subspace k P\u2082) : affine_subspace k P\u2081 :=\n{ carrier := f \u207b\u00b9' s,\n  smul_vsub_vadd_mem := \u03bb t p\u2081 p\u2082 p\u2083 (hp\u2081 : f p\u2081 \u2208 s) (hp\u2082 : f p\u2082 \u2208 s) (hp\u2083 : f p\u2083 \u2208 s),\n    show f _ \u2208 s, begin\n      rw [affine_map.map_vadd, linear_map.map_smul, affine_map.linear_map_vsub],\n      apply s.smul_vsub_vadd_mem _ hp\u2081 hp\u2082 hp\u2083,\n    end }\n\n@[simp] lemma coe_comap (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : affine_subspace k P\u2082) :\n  (s.comap f : set P\u2081) = f \u207b\u00b9' \u2191s := rfl\n\n@[simp] lemma mem_comap {f : P\u2081 \u2192\u1d43[k] P\u2082} {x : P\u2081} {s : affine_subspace k P\u2082} :\n  x \u2208 s.comap f \u2194 f x \u2208 s := iff.rfl\n\nlemma comap_mono {f : P\u2081 \u2192\u1d43[k] P\u2082} {s t : affine_subspace k P\u2082} : s \u2264 t \u2192 s.comap f \u2264 t.comap f :=\npreimage_mono\n\n@[simp] lemma comap_top {f : P\u2081 \u2192\u1d43[k] P\u2082} : (\u22a4 : affine_subspace k P\u2082).comap f = \u22a4 :=\nby { rw \u2190 ext_iff, exact preimage_univ, }\n\nomit V\u2082\n\n@[simp] lemma comap_id (s : affine_subspace k P\u2081) : s.comap (affine_map.id k P\u2081) = s :=\ncoe_injective rfl\n\ninclude V\u2082 V\u2083\n\nlemma comap_comap (s : affine_subspace k P\u2083) (f : P\u2081 \u2192\u1d43[k] P\u2082) (g : P\u2082 \u2192\u1d43[k] P\u2083) :\n  (s.comap g).comap f = s.comap (g.comp f) :=\ncoe_injective rfl\n\nomit V\u2083\n\n-- lemmas about map and comap derived from the galois connection\n\nlemma map_le_iff_le_comap {f : P\u2081 \u2192\u1d43[k] P\u2082} {s : affine_subspace k P\u2081} {t : affine_subspace k P\u2082} :\n  s.map f \u2264 t \u2194 s \u2264 t.comap f :=\nimage_subset_iff\n\nlemma gc_map_comap (f : P\u2081 \u2192\u1d43[k] P\u2082) : galois_connection (map f) (comap f) :=\n\u03bb _ _, map_le_iff_le_comap\n\nlemma map_comap_le (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : affine_subspace k P\u2082) : (s.comap f).map f \u2264 s :=\n(gc_map_comap f).l_u_le _\n\nlemma le_comap_map (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : affine_subspace k P\u2081) : s \u2264 (s.map f).comap f :=\n(gc_map_comap f).le_u_l _\n\nlemma map_sup (s t : affine_subspace k P\u2081) (f : P\u2081 \u2192\u1d43[k] P\u2082) : (s \u2294 t).map f = s.map f \u2294 t.map f :=\n(gc_map_comap f).l_sup\n\nlemma map_supr {\u03b9 : Sort*} (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : \u03b9 \u2192 affine_subspace k P\u2081) :\n  (supr s).map f = \u2a06 i, (s i).map f :=\n(gc_map_comap f).l_supr\n\nlemma comap_inf (s t : affine_subspace k P\u2082) (f : P\u2081 \u2192\u1d43[k] P\u2082) :\n  (s \u2293 t).comap f = s.comap f \u2293 t.comap f :=\n(gc_map_comap f).u_inf\n\nlemma comap_supr {\u03b9 : Sort*} (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : \u03b9 \u2192 affine_subspace k P\u2082) :\n  (infi s).comap f = \u2a05 i, (s i).comap f :=\n(gc_map_comap f).u_infi\n\n@[simp] lemma comap_symm (e : P\u2081 \u2243\u1d43[k] P\u2082) (s : affine_subspace k P\u2081) :\n  s.comap (e.symm : P\u2082 \u2192\u1d43[k] P\u2081) = s.map e :=\ncoe_injective $ e.preimage_symm _\n\n@[simp] lemma map_symm (e : P\u2081 \u2243\u1d43[k] P\u2082) (s : affine_subspace k P\u2082) :\n  s.map (e.symm : P\u2082 \u2192\u1d43[k] P\u2081) = s.comap e :=\ncoe_injective $ e.image_symm _\n\nlemma comap_span (f : P\u2081 \u2243\u1d43[k] P\u2082) (s : set P\u2082) :\n  (affine_span k s).comap (f : P\u2081 \u2192\u1d43[k] P\u2082) = affine_span k (f \u207b\u00b9' s) :=\nby rw [\u2190map_symm, map_span, affine_equiv.coe_coe, f.image_symm]\n\nend affine_subspace\n\nend map_comap\n\nnamespace affine_subspace\n\nopen affine_equiv\n\nvariables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\nvariables [affine_space V P]\ninclude V\n\n/-- Two affine subspaces are parallel if one is related to the other by adding the same vector\nto all points. -/\ndef parallel (s\u2081 s\u2082 : affine_subspace k P) : Prop :=\n\u2203 v : V, s\u2082 = s\u2081.map (const_vadd k P v)\n\nlocalized \"infix (name := affine_subspace.parallel) ` \u2225 `:50 := affine_subspace.parallel\" in affine\n\n@[symm] lemma parallel.symm {s\u2081 s\u2082 : affine_subspace k P} (h : s\u2081 \u2225 s\u2082) : s\u2082 \u2225 s\u2081 :=\nbegin\n  rcases h with \u27e8v, rfl\u27e9,\n  refine \u27e8-v, _\u27e9,\n  rw [map_map, \u2190coe_trans_to_affine_map, \u2190const_vadd_add, neg_add_self, const_vadd_zero,\n      coe_refl_to_affine_map, map_id]\nend\n\nlemma parallel_comm {s\u2081 s\u2082 : affine_subspace k P} : s\u2081 \u2225 s\u2082 \u2194 s\u2082 \u2225 s\u2081 :=\n\u27e8parallel.symm, parallel.symm\u27e9\n\n@[refl] lemma parallel.refl (s : affine_subspace k P) : s \u2225 s :=\n\u27e80, by simp\u27e9\n\n@[trans] lemma parallel.trans {s\u2081 s\u2082 s\u2083 : affine_subspace k P} (h\u2081\u2082 : s\u2081 \u2225 s\u2082) (h\u2082\u2083 : s\u2082 \u2225 s\u2083) :\n  s\u2081 \u2225 s\u2083 :=\nbegin\n  rcases h\u2081\u2082 with \u27e8v\u2081\u2082, rfl\u27e9,\n  rcases h\u2082\u2083 with \u27e8v\u2082\u2083, rfl\u27e9,\n  refine \u27e8v\u2082\u2083 + v\u2081\u2082, _\u27e9,\n  rw [map_map, \u2190coe_trans_to_affine_map, \u2190const_vadd_add]\nend\n\nlemma parallel.direction_eq {s\u2081 s\u2082 : affine_subspace k P} (h : s\u2081 \u2225 s\u2082) :\n  s\u2081.direction = s\u2082.direction :=\nbegin\n  rcases h with \u27e8v, rfl\u27e9,\n  simp\nend\n\n@[simp] lemma parallel_bot_iff_eq_bot {s : affine_subspace k P} :\n  s \u2225 \u22a5 \u2194 s = \u22a5 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, h \u25b8 parallel.refl _\u27e9,\n  rcases h with \u27e8v, h\u27e9,\n  rwa [eq_comm, map_eq_bot_iff] at h\nend\n\n@[simp] lemma bot_parallel_iff_eq_bot {s : affine_subspace k P} :\n  \u22a5 \u2225 s \u2194 s = \u22a5 :=\nby rw [parallel_comm, parallel_bot_iff_eq_bot]\n\nlemma parallel_iff_direction_eq_and_eq_bot_iff_eq_bot {s\u2081 s\u2082 : affine_subspace k P} :\n  s\u2081 \u2225 s\u2082 \u2194 s\u2081.direction = s\u2082.direction \u2227 (s\u2081 = \u22a5 \u2194 s\u2082 = \u22a5) :=\nbegin\n  refine \u27e8\u03bb h, \u27e8h.direction_eq, _, _\u27e9, \u03bb h, _\u27e9,\n  { rintro rfl, exact bot_parallel_iff_eq_bot.1 h },\n  { rintro rfl, exact parallel_bot_iff_eq_bot.1 h },\n  { rcases h with \u27e8hd, hb\u27e9,\n    by_cases hs\u2081 : s\u2081 = \u22a5,\n    { rw [hs\u2081, bot_parallel_iff_eq_bot],\n      exact hb.1 hs\u2081 },\n    { have hs\u2082 : s\u2082 \u2260 \u22a5 := hb.not.1 hs\u2081,\n      rcases (nonempty_iff_ne_bot s\u2081).2 hs\u2081 with \u27e8p\u2081, hp\u2081\u27e9,\n      rcases (nonempty_iff_ne_bot s\u2082).2 hs\u2082 with \u27e8p\u2082, hp\u2082\u27e9,\n      refine \u27e8p\u2082 -\u1d65 p\u2081, (eq_iff_direction_eq_of_mem hp\u2082 _).2 _\u27e9,\n      { rw mem_map,\n        refine \u27e8p\u2081, hp\u2081, _\u27e9,\n        simp },\n      { simpa using hd.symm } } }\nend\n\nlemma parallel.vector_span_eq {s\u2081 s\u2082 : set P} (h : affine_span k s\u2081 \u2225 affine_span k s\u2082) :\n  vector_span k s\u2081 = vector_span k s\u2082 :=\nbegin\n  simp_rw \u2190direction_affine_span,\n  exact h.direction_eq\nend\n\nlemma affine_span_parallel_iff_vector_span_eq_and_eq_empty_iff_eq_empty {s\u2081 s\u2082 : set P} :\n  affine_span k s\u2081 \u2225 affine_span k s\u2082 \u2194 vector_span k s\u2081 = vector_span k s\u2082 \u2227 (s\u2081 = \u2205 \u2194 s\u2082 = \u2205) :=\nbegin\n  simp_rw [\u2190direction_affine_span, \u2190affine_span_eq_bot k],\n  exact parallel_iff_direction_eq_and_eq_bot_iff_eq_bot\nend\n\nlemma affine_span_pair_parallel_iff_vector_span_eq {p\u2081 p\u2082 p\u2083 p\u2084 : P} :\n  line[k, p\u2081, p\u2082] \u2225 line[k, p\u2083, p\u2084] \u2194\n    vector_span k ({p\u2081, p\u2082} : set P) = vector_span k ({p\u2083, p\u2084} : set P) :=\nby simp [affine_span_parallel_iff_vector_span_eq_and_eq_empty_iff_eq_empty,\n         \u2190not_nonempty_iff_eq_empty]\n\nend affine_subspace\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/affine_space/affine_subspace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8438951084436076, "lm_q1q2_score": 0.7460364332721564}}
{"text": "-- Imagen_de_la_union_general.lean\n-- Imagen de la uni\u00f3n general\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 23 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ----------------------------------------------------------------------\n-- Demostrar que\n--    f '' (\u22c3 i, A i) = \u22c3 i, f '' A i\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {I : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables A : \u2115 \u2192 set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y,\n  split,\n  { intro hy,\n    rw mem_image at hy,\n    cases hy with x hx,\n    cases hx with xUA fxy,\n    rw mem_Union at xUA,\n    cases xUA with i xAi,\n    rw mem_Union,\n    use i,\n    rw \u2190 fxy,\n    apply mem_image_of_mem,\n    exact xAi, },\n  { intro hy,\n    rw mem_Union at hy,\n    cases hy with i yAi,\n    cases yAi with x hx,\n    cases hx with xAi fxy,\n    rw \u2190 fxy,\n    apply mem_image_of_mem,\n    rw mem_Union,\n    use i,\n    exact xAi, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y,\n  simp,\n  split,\n  { rintros \u27e8x, \u27e8i, xAi\u27e9, fxy\u27e9,\n    use [i, x, xAi, fxy] },\n  { rintros \u27e8i, x, xAi, fxy\u27e9,\n    exact \u27e8x, \u27e8i, xAi\u27e9, fxy\u27e9 },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nby tidy\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nimage_Union\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Imagen_de_la_union_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8438951025545427, "lm_q1q2_score": 0.7460364229095393}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n-/\nimport Mathlib.Data.Nat.Basic\nimport Mathlib.Init.Dvd\n\n/-!\n# Definitions and properties of `gcd`, `lcm`, and `coprime`\n\n-/\n\nnamespace Nat\n\n--- TODO all of these dvd preliminaries belong elsewhere.\n\nprotected theorem dvd_mul_left (a b : \u2115) : a \u2223 b * a := Exists.intro b (Nat.mul_comm b a)\nprotected theorem dvd_refl (a : \u2115) : a \u2223 a := Exists.intro 1 (by simp)\nprotected theorem dvd_zero (a : \u2115) : a \u2223 0 := Exists.intro 0 (by simp)\n\nprotected theorem mul_dvd_mul : \u2200 {a b c d : \u2115}, a \u2223 b \u2192 c \u2223 d \u2192 a * c \u2223 b * d\n| a, b, c, d, \u27e8e, he\u27e9, \u27e8f, hf\u27e9 => \u27e8e * f, by rw [he, hf,\n                                                 Nat.mul_assoc a _,\n                                                 \u2190Nat.mul_assoc e _,\n                                                 Nat.mul_comm e c,\n                                                 Nat.mul_assoc a c _,\n                                                 Nat.mul_assoc c e _,]\u27e9\n\nprotected theorem mul_dvd_mul_left (a : \u2115) {b c : \u2115} (h : b \u2223 c) : a * b \u2223 a * c :=\nNat.mul_dvd_mul (Nat.dvd_refl a) h\n\nprotected theorem mul_dvd_mul_right {a b : \u2115} (h: a \u2223 b) (c : \u2115) : a * c \u2223 b * c :=\nNat.mul_dvd_mul h (Nat.dvd_refl c)\n\n----\n-- Here's where we get into the main gcd results\n\ntheorem gcd_rec (m n : \u2115) : gcd m n = gcd (n % m) m :=\n  match m with\n  | 0 => by have := (mod_zero n).symm\n            rwa [gcd_zero_right]\n  | pm + 1 => by simp [gcd_succ]\n\ntheorem gcd.induction\n  {P : \u2115 \u2192 \u2115 \u2192 Prop}\n  (m n : \u2115)\n  (H0 : \u2200n, P 0 n)\n  (H1 : \u2200 m n, 0 < m \u2192 P (n % m) m \u2192 P m n) :\n  P m n :=\n  @WellFounded.induction _ _ lt_wfRel.wf (\u03bb m => \u2200 n, P m n) m\n    (\u03bb k IH =>\n      match k with\n      | 0 => H0\n      | pk+1 => \u03bb n => H1 _ _ (succ_pos _) (IH _ (mod_lt _ (succ_pos _)) _) )\n    n\n\ndef lcm (m n : \u2115) : \u2115 := m * n / gcd m n\n\n@[reducible] def coprime (m n : \u2115) : Prop := gcd m n = 1\n\n---\n\ntheorem gcd_dvd (m n : \u2115) : (gcd m n \u2223 m) \u2227 (gcd m n \u2223 n) := by\n  induction m, n using gcd.induction with\n  | H0 n => exact And.intro (Exists.intro 0 (by simp))\n                            (Exists.intro 1 (by simp))\n  | H1 m n mpos IH =>\n    let \u27e8IH\u2081, IH\u2082\u27e9 := IH\n    exact And.intro (by rwa [gcd_rec])\n                    (by rw [\u2190gcd_rec] at IH\u2081\n                        rw [\u2190gcd_rec] at IH\u2082\n                        exact (dvd_mod_iff IH\u2082).1 IH\u2081)\n\ntheorem gcd_dvd_left (m n : \u2115) : gcd m n \u2223 m := (gcd_dvd m n).left\n\ntheorem gcd_dvd_right (m n : \u2115) : gcd m n \u2223 n := (gcd_dvd m n).right\n\ntheorem gcd_le_left {m} (n) (h : 0 < m) : gcd m n \u2264 m := le_of_dvd h $ gcd_dvd_left m n\n\ntheorem gcd_le_right {m} (n) (h : 0 < n) : gcd m n \u2264 n := le_of_dvd h $ gcd_dvd_right m n\n\ntheorem dvd_gcd {m n k : \u2115} : k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 gcd m n := by\n  induction m, n using gcd.induction with\n  | H0 n => intros _ kn\n            rw [gcd_zero_left]\n            exact kn\n  | H1 m n mpos IH => intros H1 H2\n                      rw [gcd_rec]\n                      exact IH ((dvd_mod_iff H1).mpr H2) H1\n\ntheorem dvd_gcd_iff {m n k : \u2115} : k \u2223 gcd m n \u2194 k \u2223 m \u2227 k \u2223 n :=\nIff.intro (\u03bb h => And.intro (Nat.dvd_trans h (gcd_dvd m n).left) (Nat.dvd_trans h (gcd_dvd m n).right))\n          (\u03bb h => dvd_gcd h.left h.right)\n\ntheorem gcd_comm (m n : \u2115) : gcd m n = gcd n m :=\n  dvd_antisymm\n    (dvd_gcd (gcd_dvd_right m n) (gcd_dvd_left m n))\n    (dvd_gcd (gcd_dvd_right n m) (gcd_dvd_left n m))\n\ntheorem gcd_eq_left_iff_dvd {m n :\u2115} : m \u2223 n \u2194 gcd m n = m :=\nIff.intro\n  (\u03bb h => by rw [gcd_rec, mod_eq_zero_of_dvd h, gcd_zero_left])\n  (\u03bb h => h \u25b8 gcd_dvd_right m n)\n\ntheorem gcd_eq_right_iff_dvd {m n : \u2115} : m \u2223 n \u2194 gcd n m = m :=\nby rw [gcd_comm]\n   apply gcd_eq_left_iff_dvd\n\ntheorem gcd_assoc (m n k : \u2115) : gcd (gcd m n) k = gcd m (gcd n k) :=\ndvd_antisymm\n  (dvd_gcd\n    (Nat.dvd_trans (gcd_dvd_left (gcd m n) k) (gcd_dvd_left m n))\n    (dvd_gcd (Nat.dvd_trans (gcd_dvd_left (gcd m n) k) (gcd_dvd_right m n))\n      (gcd_dvd_right (gcd m n) k)))\n  (dvd_gcd\n    (dvd_gcd (gcd_dvd_left m (gcd n k)) (Nat.dvd_trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_left n k)))\n    (Nat.dvd_trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_right n k)))\n\n@[simp] theorem gcd_one_right (n : \u2115) : gcd n 1 = 1 :=\nEq.trans (gcd_comm n 1) $ gcd_one_left n\n\ntheorem gcd_mul_left (m n k : \u2115) : gcd (m * n) (m * k) = m * gcd n k := by\n  induction n, k using gcd.induction with\n  | H0 k => simp\n  | H1 n k npos IH => rwa [\u2190mul_mod_mul_left, \u2190gcd_rec, \u2190gcd_rec] at IH\n\ntheorem gcd_mul_right (m n k : \u2115) : gcd (m * n) (k * n) = gcd m k * n :=\nby rw [Nat.mul_comm m n, Nat.mul_comm k n, Nat.mul_comm (gcd m k) n, gcd_mul_left]\n\ntheorem gcd_pos_of_pos_left {m : \u2115} (n : \u2115) (mpos : 0 < m) : 0 < gcd m n :=\npos_of_dvd_of_pos (gcd_dvd_left m n) mpos\n\ntheorem gcd_pos_of_pos_right (m : \u2115) {n : \u2115} (npos : 0 < n) : 0 < gcd m n :=\npos_of_dvd_of_pos (gcd_dvd_right m n) npos\n\ntheorem eq_zero_of_gcd_eq_zero_left {m n : \u2115} (H : gcd m n = 0) : m = 0 :=\nmatch eq_zero_or_pos m with\n| Or.inl H0 => H0\n| Or.inr H1 => absurd (Eq.symm H) (ne_of_lt (gcd_pos_of_pos_left _ H1))\n\ntheorem eq_zero_of_gcd_eq_zero_right {m n : \u2115} (H : gcd m n = 0) : n = 0 :=\nby rw [gcd_comm] at H\n   exact eq_zero_of_gcd_eq_zero_left H\n\ntheorem gcd_div {m n k : \u2115} (H1 : k \u2223 m) (H2 : k \u2223 n) :\n  gcd (m / k) (n / k) = gcd m n / k :=\nmatch eq_zero_or_pos k with\n| Or.inl H0 => by rw [H0, Nat.div_zero, Nat.div_zero, Nat.div_zero, gcd_zero_right]\n| Or.inr H3 =>\n  Nat.eq_of_mul_eq_mul_right H3 $ by rw [Nat.div_mul_cancel (dvd_gcd H1 H2), \u2190gcd_mul_right,\n                                         Nat.div_mul_cancel H1, Nat.div_mul_cancel H2]\n\ntheorem gcd_dvd_gcd_of_dvd_left {m k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd m n \u2223 gcd k n :=\ndvd_gcd (Nat.dvd_trans (gcd_dvd_left m n) H) (gcd_dvd_right m n)\n\ntheorem gcd_dvd_gcd_of_dvd_right {m k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd n m \u2223 gcd n k :=\ndvd_gcd (gcd_dvd_left n m) (Nat.dvd_trans (gcd_dvd_right n m) H)\n\ntheorem gcd_dvd_gcd_mul_left (m n k : \u2115) : gcd m n \u2223 gcd (k * m) n :=\ngcd_dvd_gcd_of_dvd_left _ (Nat.dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (m n k : \u2115) : gcd m n \u2223 gcd (m * k) n :=\ngcd_dvd_gcd_of_dvd_left _ (Nat.dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (m n k : \u2115) : gcd m n \u2223 gcd m (k * n) :=\ngcd_dvd_gcd_of_dvd_right _ (Nat.dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (m n k : \u2115) : gcd m n \u2223 gcd m (n * k) :=\ngcd_dvd_gcd_of_dvd_right _ (Nat.dvd_mul_right _ _)\n\ntheorem gcd_eq_left {m n : \u2115} (H : m \u2223 n) : gcd m n = m :=\ndvd_antisymm (gcd_dvd_left _ _) (dvd_gcd (Nat.dvd_refl _) H)\n\ntheorem gcd_eq_right {m n : \u2115} (H : n \u2223 m) : gcd m n = n :=\nby rw [gcd_comm, gcd_eq_left H]\n\n@[simp] lemma gcd_mul_left_left (m n : \u2115) : gcd (m * n) n = n :=\ndvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (Nat.dvd_mul_left _ _) (Nat.dvd_refl _))\n\n@[simp] lemma gcd_mul_left_right (m n : \u2115) : gcd n (m * n) = n :=\nby rw [gcd_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_left (m n : \u2115) : gcd (n * m) n = n :=\nby rw [Nat.mul_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_right (m n : \u2115) : gcd n (n * m) = n :=\nby rw [gcd_comm, gcd_mul_right_left]\n\n@[simp] lemma gcd_gcd_self_right_left (m n : \u2115) : gcd m (gcd m n) = gcd m n :=\ndvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (gcd_dvd_left _ _) (Nat.dvd_refl _))\n\n@[simp] lemma gcd_gcd_self_right_right (m n : \u2115) : gcd m (gcd n m) = gcd n m :=\nby rw [gcd_comm n m, gcd_gcd_self_right_left]\n\n@[simp] lemma gcd_gcd_self_left_right (m n : \u2115) : gcd (gcd n m) m = gcd n m :=\nby rw [gcd_comm, gcd_gcd_self_right_right]\n\n@[simp] lemma gcd_gcd_self_left_left (m n : \u2115) : gcd (gcd m n) m = gcd m n :=\nby rw [gcd_comm m n, gcd_gcd_self_left_right]\n\nlemma gcd_add_mul_self (m n k : \u2115) : gcd m (n + k * m) = gcd m n :=\nby simp [gcd_rec m (n + k * m), gcd_rec m n]\n\ntheorem gcd_eq_zero_iff {i j : \u2115} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 :=\nIff.intro\n  (\u03bb h => \u27e8eq_zero_of_gcd_eq_zero_left h, eq_zero_of_gcd_eq_zero_right h\u27e9)\n  (\u03bb h => by rw [h.1, h.2]\n             exact Nat.gcd_zero_right _)\n\n/-! ### `lcm` -/\n\ntheorem lcm_comm (m n : \u2115) : lcm m n = lcm n m :=\nby have h1 : lcm m n = m * n / gcd m n := rfl\n   have h2 : lcm n m = n * m / gcd n m := rfl\n   rw [h1, h2, Nat.mul_comm n m, gcd_comm n m]\n\n@[simp]\ntheorem lcm_zero_left (m : \u2115) : lcm 0 m = 0 :=\nby have h : lcm 0 m = 0 * m / gcd 0 m := rfl\n   simp [h]\n\n@[simp]\ntheorem lcm_zero_right (m : \u2115) : lcm m 0 = 0 := lcm_comm 0 m \u25b8 lcm_zero_left m\n\n@[simp]\ntheorem lcm_one_left (m : \u2115) : lcm 1 m = m :=\nby have h : lcm 1 m = 1 * m / gcd 1 m := rfl\n   simp [h]\n\n@[simp]\ntheorem lcm_one_right (m : \u2115) : lcm m 1 = m := lcm_comm 1 m \u25b8 lcm_one_left m\n\n@[simp]\ntheorem lcm_self (m : \u2115) : lcm m m = m :=\nmatch eq_zero_or_pos m with\n| Or.inl h => by rw [h, lcm_zero_left]\n| Or.inr h => by have h1 : lcm m m = m * m / gcd m m := rfl\n                 simp [h1, Nat.mul_div_cancel _ h]\n\ntheorem dvd_lcm_left (m n : \u2115) : m \u2223 lcm m n :=\nExists.intro (n / gcd m n)\n             (by rw [\u2190 Nat.mul_div_assoc m (Nat.gcd_dvd_right m n)]\n                 rfl)\n\ntheorem dvd_lcm_right (m n : \u2115) : n \u2223 lcm m n :=\nlcm_comm n m \u25b8 dvd_lcm_left n m\n\ntheorem gcd_mul_lcm (m n : \u2115) : gcd m n * lcm m n = m * n :=\nby have h1 : lcm m n = m * n / gcd m n := rfl\n   rw [h1]\n   rw [Nat.mul_div_cancel' (Nat.dvd_trans (gcd_dvd_left m n) (Nat.dvd_mul_right m n))]\n\ntheorem lcm_dvd {m n k : \u2115} (H1 : m \u2223 k) (H2 : n \u2223 k) : lcm m n \u2223 k :=\nmatch eq_zero_or_pos k with\n| Or.inl h => by rw [h]\n                 exact Nat.dvd_zero _\n| Or.inr kpos => Nat.dvd_of_mul_dvd_mul_left (gcd_pos_of_pos_left n (pos_of_dvd_of_pos H1 kpos)) $\n                   by rw [gcd_mul_lcm, \u2190gcd_mul_right, Nat.mul_comm n k];\n                      exact dvd_gcd (Nat.mul_dvd_mul_left _ H2) (Nat.mul_dvd_mul_right H1 _)\n\ntheorem lcm_assoc (m n k : \u2115) : lcm (lcm m n) k = lcm m (lcm n k) :=\ndvd_antisymm\n  (lcm_dvd\n    (lcm_dvd (dvd_lcm_left m (lcm n k)) (Nat.dvd_trans (dvd_lcm_left n k) (dvd_lcm_right m (lcm n k))))\n    (Nat.dvd_trans (dvd_lcm_right n k) (dvd_lcm_right m (lcm n k))))\n  (lcm_dvd\n    (Nat.dvd_trans (dvd_lcm_left m n) (dvd_lcm_left (lcm m n) k))\n    (lcm_dvd (Nat.dvd_trans (dvd_lcm_right m n) (dvd_lcm_left (lcm m n) k))\n      (dvd_lcm_right (lcm m n) k)))\n\ntheorem lcm_ne_zero {m n : \u2115} (hm : m \u2260 0) (hn : n \u2260 0) : lcm m n \u2260 0 :=\nby intro h\n   have h1 := gcd_mul_lcm m n\n   rw [h, Nat.mul_zero] at h1\n   match eq_zero_of_mul_eq_zero h1.symm with\n   | Or.inl hm1 => exact hm hm1\n   | Or.inr hn1 => exact hn hn1\n\n/-!\n### `coprime`\n\nSee also `nat.coprime_of_dvd` and `nat.coprime_of_dvd'` to prove `nat.coprime m n`.\n-/\n\ninstance (m n : \u2115) : Decidable (coprime m n) :=\n  if h: gcd m n = 1 then isTrue h else isFalse h\n\ntheorem coprime_iff_gcd_eq_one {m n : \u2115} : coprime m n \u2194 gcd m n = 1 := Iff.rfl\n\ntheorem coprime.gcd_eq_one {m n : \u2115} : coprime m n \u2192 gcd m n = 1 := id\n\ntheorem coprime.symm {m n : \u2115} : coprime n m \u2192 coprime m n := (gcd_comm m n).trans\n\ntheorem coprime_comm {m n : \u2115} : coprime n m \u2194 coprime m n := \u27e8coprime.symm, coprime.symm\u27e9\n\ntheorem coprime.dvd_of_dvd_mul_right {m n k : \u2115} (H1 : coprime k n) (H2 : k \u2223 m * n) : k \u2223 m :=\nlet t := dvd_gcd (Nat.dvd_mul_left k m) H2\nby rwa [gcd_mul_left, H1.gcd_eq_one, Nat.mul_one] at t\n\ntheorem coprime.dvd_of_dvd_mul_left {m n k : \u2115} (H1 : coprime k m) (H2 : k \u2223 m * n) : k \u2223 n :=\nby rw [Nat.mul_comm] at H2\n   exact H1.dvd_of_dvd_mul_right H2\n\ntheorem coprime.gcd_mul_left_cancel {k : \u2115} (m : \u2115) {n : \u2115} (H : coprime k n) :\n   gcd (k * m) n = gcd m n :=\nlet H1 : coprime (gcd (k * m) n) k :=\n   by have h1 : coprime (gcd (k * m) n) k = (gcd (gcd (k * m) n) k = 1) := rfl\n      rw [h1, Nat.gcd_assoc, H.symm.gcd_eq_one, gcd_one_right]\ndvd_antisymm\n  (dvd_gcd (H1.dvd_of_dvd_mul_left (gcd_dvd_left _ _)) (gcd_dvd_right _ _))\n  (gcd_dvd_gcd_mul_left _ _ _)\n\ntheorem coprime.gcd_mul_right_cancel (m : \u2115) {k n : \u2115} (H : coprime k n) :\n   gcd (m * k) n = gcd m n :=\nby rw [Nat.mul_comm m k, H.gcd_mul_left_cancel m]\n\ntheorem coprime.gcd_mul_left_cancel_right {k m : \u2115} (n : \u2115) (H : coprime k m) :\n   gcd m (k * n) = gcd m n :=\nby rw [gcd_comm m n, gcd_comm m (k * n), H.gcd_mul_left_cancel n]\n\ntheorem coprime.gcd_mul_right_cancel_right {k m : \u2115} (n : \u2115) (H : coprime k m) :\n   gcd m (n * k) = gcd m n :=\nby rw [Nat.mul_comm n k, H.gcd_mul_left_cancel_right n]\n\ntheorem coprime_div_gcd_div_gcd {m n : \u2115} (H : 0 < gcd m n) :\n  coprime (m / gcd m n) (n / gcd m n) :=\nby rw [coprime_iff_gcd_eq_one, gcd_div (gcd_dvd_left m n) (gcd_dvd_right m n), Nat.div_self H]\n\ntheorem not_coprime_of_dvd_of_dvd {m n d : \u2115} (dgt1 : 1 < d) (Hm : d \u2223 m) (Hn : d \u2223 n) :\n  \u00ac coprime m n :=\n\u03bb co => by have hd : \u00ac d \u2264 1 := Nat.not_le_of_gt dgt1\n           have := (Nat.le_of_dvd Nat.zero_lt_one $ by rw [\u2190co.gcd_eq_one]; exact dvd_gcd Hm Hn)\n           exact hd this\n\ntheorem exists_coprime {m n : \u2115} (H : 0 < gcd m n) :\n  \u2203 m' n', coprime m' n' \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n\u27e8_, _, coprime_div_gcd_div_gcd H,\n  (Nat.div_mul_cancel (gcd_dvd_left m n)).symm,\n  (Nat.div_mul_cancel (gcd_dvd_right m n)).symm\u27e9\n\ntheorem exists_coprime' {m n : \u2115} (H : 0 < gcd m n) :\n  \u2203 g m' n', 0 < g \u2227 coprime m' n' \u2227 m = m' * g \u2227 n = n' * g :=\n  let \u27e8m', n', h\u27e9 := exists_coprime H\n  \u27e8_, m', n', H, h\u27e9\n\ntheorem coprime.mul {m n k : \u2115} (H1 : coprime m k) (H2 : coprime n k) : coprime (m * n) k :=\n(H1.gcd_mul_left_cancel n).trans H2\n\ntheorem coprime.mul_right {k m n : \u2115} (H1 : coprime k m) (H2 : coprime k n) : coprime k (m * n) :=\n(H1.symm.mul H2.symm).symm\n\ntheorem coprime.coprime_dvd_left {m k n : \u2115} (H1 : m \u2223 k) (H2 : coprime k n) : coprime m n :=\nby apply eq_one_of_dvd_one\n   have h1 : coprime k n = (gcd k n = 1) := rfl\n   rw [h1] at H2\n   have := @Nat.gcd_dvd_gcd_of_dvd_left m k n H1\n   rwa [\u2190H2]\n\ntheorem coprime.coprime_dvd_right {m k n : \u2115} (H1 : n \u2223 m) (H2 : coprime k m) : coprime k n :=\n(H2.symm.coprime_dvd_left H1).symm\n\ntheorem coprime.coprime_mul_left {k m n : \u2115} (H : coprime (k * m) n) : coprime m n :=\nH.coprime_dvd_left (Nat.dvd_mul_left _ _)\n\ntheorem coprime.coprime_mul_right {k m n : \u2115} (H : coprime (m * k) n) : coprime m n :=\nH.coprime_dvd_left (Nat.dvd_mul_right _ _)\n\ntheorem coprime.coprime_mul_left_right {k m n : \u2115} (H : coprime m (k * n)) : coprime m n :=\nH.coprime_dvd_right (Nat.dvd_mul_left _ _)\n\ntheorem coprime.coprime_mul_right_right {k m n : \u2115} (H : coprime m (n * k)) : coprime m n :=\nH.coprime_dvd_right (Nat.dvd_mul_right _ _)\n\ntheorem coprime.coprime_div_left {m n a : \u2115} (cmn : coprime m n) (dvd : a \u2223 m) :\n  coprime (m / a) n :=\nmatch eq_zero_or_pos a with\n| Or.inl h0 => by rw [h0] at dvd\n                  rw [Nat.eq_zero_of_zero_dvd dvd]\n                  rw [Nat.eq_zero_of_zero_dvd dvd] at cmn\n                  simp\n                  assumption\n| Or.inr hpos =>\n   match dvd with\n   | \u27e8k, hk\u27e9 => by rw [hk, Nat.mul_div_cancel_left _ hpos]\n                   rw [hk] at cmn\n                   exact coprime.coprime_mul_left cmn\n\ntheorem coprime.coprime_div_right {m n a : \u2115} (cmn : coprime m n) (dvd : a \u2223 n) :\n  coprime m (n / a) :=\n(coprime.coprime_div_left cmn.symm dvd).symm\n\nlemma coprime_mul_iff_left {k m n : \u2115} : coprime (m * n) k \u2194 coprime m k \u2227 coprime n k :=\n\u27e8\u03bb h => \u27e8coprime.coprime_mul_right h, coprime.coprime_mul_left h\u27e9,\n  \u03bb \u27e8h, _\u27e9 => by rwa [coprime_iff_gcd_eq_one, coprime.gcd_mul_left_cancel n h]\u27e9\n\nlemma coprime_mul_iff_right {k m n : \u2115} : coprime k (m * n) \u2194 coprime k m \u2227 coprime k n :=\nby rw [@coprime_comm (m*n) k, @coprime_comm m k, @coprime_comm n k, coprime_mul_iff_left]\n\nlemma coprime.gcd_left (k : \u2115) {m n : \u2115} (hmn : coprime m n) : coprime (gcd k m) n :=\nhmn.coprime_dvd_left $ gcd_dvd_right k m\n\nlemma coprime.gcd_right (k : \u2115) {m n : \u2115} (hmn : coprime m n) : coprime m (gcd k n) :=\nhmn.coprime_dvd_right $ gcd_dvd_right k n\n\nlemma coprime.gcd_both (k l : \u2115) {m n : \u2115} (hmn : coprime m n) : coprime (gcd k m) (gcd l n) :=\n(hmn.gcd_left k).gcd_right l\n\nlemma coprime.mul_dvd_of_dvd_of_dvd {a n m : \u2115} (hmn : coprime m n)\n  (hm : m \u2223 a) (hn : n \u2223 a) : m * n \u2223 a :=\n  let \u27e8k, hk\u27e9 := hm\n  hk.symm \u25b8 Nat.mul_dvd_mul_left _ (hmn.symm.dvd_of_dvd_mul_left (hk \u25b8 hn))\n\ntheorem coprime_one_left : \u2200 n, coprime 1 n := gcd_one_left\n\ntheorem coprime_one_right : \u2200 n, coprime n 1 := gcd_one_right\n\ntheorem coprime.pow_left {m k : \u2115} (n : \u2115) (H1 : coprime m k) : coprime (m ^ n) k :=\nby induction n with\n   | zero => exact coprime_one_left _\n   | succ n ih => have hm := H1.mul ih\n                  have : m ^ succ n = m * m ^ n := by rw [Nat.pow_succ, Nat.mul_comm]\n                  rwa [this]\n\ntheorem coprime.pow_right {m k : \u2115} (n : \u2115) (H1 : coprime k m) : coprime k (m ^ n) :=\n(H1.symm.pow_left n).symm\n\ntheorem coprime.pow {k l : \u2115} (m n : \u2115) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) :=\n(H1.pow_left _).pow_right _\n\ntheorem coprime.eq_one_of_dvd {k m : \u2115} (H : coprime k m) (d : k \u2223 m) : k = 1 :=\nby rw [\u2190 H.gcd_eq_one, gcd_eq_left d]\n\n@[simp] theorem coprime_zero_left (n : \u2115) : coprime 0 n \u2194 n = 1 :=\nby simp [coprime]\n\n@[simp] theorem coprime_zero_right (n : \u2115) : coprime n 0 \u2194 n = 1 :=\nby simp [coprime]\n\n@[simp] theorem coprime_one_left_iff (n : \u2115) : coprime 1 n \u2194 true :=\nby simp [coprime]\n\n@[simp] theorem coprime_one_right_iff (n : \u2115) : coprime n 1 \u2194 true :=\nby simp [coprime]\n\n@[simp] theorem coprime_self (n : \u2115) : coprime n n \u2194 n = 1 :=\nby simp [coprime]\n\n/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. -/\ndef prod_dvd_and_dvd_of_dvd_prod {m n k : \u2115} (H : k \u2223 m * n) :\n  { d : {m' // m' \u2223 m} \u00d7 {n' // n' \u2223 n} // k = d.1.val * d.2.val } :=\nby cases h0 : gcd k m with\n   | zero => have : k = 0 := eq_zero_of_gcd_eq_zero_left h0\n             subst this\n             have : m = 0 := eq_zero_of_gcd_eq_zero_right h0\n             subst this\n             exact \u27e8\u27e8\u27e80, Nat.dvd_refl 0\u27e9, \u27e8n, Nat.dvd_refl n\u27e9\u27e9, (Nat.zero_mul n).symm\u27e9\n   | succ p => have hpos : 0 < gcd k m := h0.symm \u25b8 Nat.zero_lt_succ _;\n               clear h0\n               have hd : gcd k m * (k / gcd k m) = k := (Nat.mul_div_cancel' (gcd_dvd_left k m))\n               have hn : (k / gcd k m) \u2223 n := by apply Nat.dvd_of_mul_dvd_mul_left hpos\n                                                 rw [hd, \u2190 gcd_mul_right]\n                                                 exact Nat.dvd_gcd (Nat.dvd_mul_right _ _) H\n               exact \u27e8\u27e8\u27e8gcd k m,  gcd_dvd_right k m\u27e9, \u27e8k / gcd k m, hn\u27e9\u27e9, hd.symm\u27e9\n\ntheorem gcd_mul_dvd_mul_gcd (k m n : \u2115) : gcd k (m * n) \u2223 gcd k m * gcd k n :=\nmatch (prod_dvd_and_dvd_of_dvd_prod $ gcd_dvd_right k (m * n)) with\n| \u27e8\u27e8\u27e8m', hm'\u27e9, \u27e8n', hn'\u27e9\u27e9, h\u27e9 =>\n  by have h' : gcd k (m * n) = m' * n' := h\n     rw [h']\n     have hm'n' : m' * n' \u2223 k := h \u25b8 gcd_dvd_left _ _\n     exact Nat.mul_dvd_mul\n       (by have hm'k : m' \u2223 k := Nat.dvd_trans (Nat.dvd_mul_right m' n') hm'n'\n           exact dvd_gcd hm'k hm')\n       (by have hn'k : n' \u2223 k := Nat.dvd_trans (Nat.dvd_mul_left n' m') hm'n'\n           exact dvd_gcd hn'k hn')\n\ntheorem coprime.gcd_mul (k : \u2115) {m n : \u2115} (h : coprime m n) : gcd k (m * n) = gcd k m * gcd k n :=\ndvd_antisymm\n  (gcd_mul_dvd_mul_gcd k m n)\n  ((h.gcd_both k k).mul_dvd_of_dvd_of_dvd\n    (gcd_dvd_gcd_mul_right_right _ _ _)\n    (gcd_dvd_gcd_mul_left_right _ _ _))\n\n-- TODO: pow_dvd_pow_iff\n\nlemma gcd_mul_gcd_of_coprime_of_mul_eq_mul {a b c d : \u2115} (cop : c.coprime d) (h : a * b = c * d) :\n  a.gcd c * b.gcd c = c :=\ndvd_antisymm\n  (by apply Nat.coprime.dvd_of_dvd_mul_right (Nat.coprime.mul (cop.gcd_left _) (cop.gcd_left _))\n      rw [\u2190 h]\n      apply Nat.mul_dvd_mul (gcd_dvd _ _).1 (gcd_dvd _ _).1)\n  (by rw [gcd_comm a _, gcd_comm b _]\n      have h1 : c \u2223 gcd c (a * b) :=\n        by rw [h, gcd_mul_right_right d c]\n           exact Nat.dvd_refl _\n      have h2 : gcd c (a * b) \u2223 gcd c a * gcd c b :=\n        by apply gcd_mul_dvd_mul_gcd\n      exact Nat.dvd_trans h1 h2)\n", "meta": {"author": "JOSHCLUNE", "repo": "Keller_reduction", "sha": "dc392b3da352fc1ffcfbecb1d4717d05f5faed4a", "save_path": "github-repos/lean/JOSHCLUNE-Keller_reduction", "path": "github-repos/lean/JOSHCLUNE-Keller_reduction/Keller_reduction-dc392b3da352fc1ffcfbecb1d4717d05f5faed4a/Lean4_Clique/Mathlib/Mathlib/Data/Nat/Gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7460364117537954}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura\n-/\nprelude\nimport init.data.nat init.data.fin.basic\n\nnamespace fin\nopen nat\nvariable {n : nat}\n\nprotected def succ : fin n \u2192 fin (succ n)\n| \u27e8a, h\u27e9 := \u27e8nat.succ a, succ_lt_succ h\u27e9\n\ndef of_nat {n : nat} (a : nat) : fin (succ n) :=\n\u27e8a % succ n, nat.mod_lt _ (nat.zero_lt_succ _)\u27e9\n\nprivate lemma mlt {n b : nat} : \u2200 {a}, n > a \u2192 b % n < n\n| 0     h := nat.mod_lt _ h\n| (a+1) h :=\n  have n > 0, from lt_trans (nat.zero_lt_succ _) h,\n  nat.mod_lt _ this\n\nprotected def add : fin n \u2192 fin n \u2192 fin n\n| \u27e8a, h\u27e9 \u27e8b, _\u27e9 := \u27e8(a + b) % n, mlt h\u27e9\n\nprotected def mul : fin n \u2192 fin n \u2192 fin n\n| \u27e8a, h\u27e9 \u27e8b, _\u27e9 := \u27e8(a * b) % n, mlt h\u27e9\n\nprivate lemma sublt {a b n : nat} (h : a < n) : a - b < n :=\nlt_of_le_of_lt (nat.sub_le a b) h\n\nprotected def sub : fin n \u2192 fin n \u2192 fin n\n| \u27e8a, h\u27e9 \u27e8b, _\u27e9 := \u27e8(a + (n - b)) % n, mlt h\u27e9\n\nprivate lemma modlt {a b n : nat} (h\u2081 : a < n) (h\u2082 : b < n) : a % b < n :=\nbegin\n  cases b with b,\n  {simp [mod_zero], assumption},\n  {have h : a % (succ b) < succ b,\n   apply nat.mod_lt _ (nat.zero_lt_succ _),\n   exact lt_trans h h\u2082}\nend\n\nprotected def mod : fin n \u2192 fin n \u2192 fin n\n| \u27e8a, h\u2081\u27e9 \u27e8b, h\u2082\u27e9 := \u27e8a % b, modlt h\u2081 h\u2082\u27e9\n\nprivate lemma divlt {a b n : nat} (h : a < n) : a / b < n :=\nlt_of_le_of_lt (nat.div_le_self a b) h\n\nprotected def div : fin n \u2192 fin n \u2192 fin n\n| \u27e8a, h\u27e9 \u27e8b, _\u27e9 := \u27e8a / b, divlt h\u27e9\n\ninstance : has_zero (fin (succ n)) := \u27e8\u27e80, succ_pos n\u27e9\u27e9\ninstance : has_one (fin (succ n))  := \u27e8of_nat 1\u27e9\ninstance : has_add (fin n)         := \u27e8fin.add\u27e9\ninstance : has_sub (fin n)         := \u27e8fin.sub\u27e9\ninstance : has_mul (fin n)         := \u27e8fin.mul\u27e9\ninstance : has_mod (fin n)         := \u27e8fin.mod\u27e9\ninstance : has_div (fin n)         := \u27e8fin.div\u27e9\n\nlemma of_nat_zero : @of_nat n 0 = 0 := rfl\n\nlemma add_def (a b : fin n) : (a + b).val = (a.val + b.val) % n :=\nshow (fin.add a b).val = (a.val + b.val) % n, from\nby cases a; cases b; simp [fin.add]\n\nlemma mul_def (a b : fin n) : (a * b).val = (a.val * b.val) % n :=\nshow (fin.mul a b).val = (a.val * b.val) % n, from\nby cases a; cases b; simp [fin.mul]\n\nlemma sub_def (a b : fin n) : (a - b).val = (a.val + (n - b.val)) % n :=\nby cases a; cases b; refl\n\nlemma mod_def (a b : fin n) : (a % b).val = a.val % b.val :=\nshow (fin.mod a b).val = a.val % b.val, from\nby cases a; cases b; simp [fin.mod]\n\nlemma div_def (a b : fin n) : (a / b).val = a.val / b.val :=\nshow (fin.div a b).val = a.val / b.val, from\nby cases a; cases b; simp [fin.div]\n\nlemma lt_def (a b : fin n) : (a < b) = (a.val < b.val) :=\nshow (fin.lt a b) = (a.val < b.val), from\nby cases a; cases b; simp [fin.lt]\n\nlemma le_def (a b : fin n) : (a \u2264 b) = (a.val \u2264 b.val) :=\nshow (fin.le a b) = (a.val \u2264 b.val), from\nby cases a; cases b; simp [fin.le]\n\nlemma val_zero : (0 : fin (succ n)).val = 0 := rfl\n\ndef pred {n : nat} : \u2200 i : fin (succ n), i \u2260 0 \u2192 fin n\n| \u27e8a, h\u2081\u27e9 h\u2082 := \u27e8a.pred,\n  begin\n    have this : a \u2260 0,\n    { have aux\u2081 := vne_of_ne h\u2082,\n      dsimp at aux\u2081, rw val_zero at aux\u2081, exact aux\u2081 },\n    exact nat.pred_lt_pred this h\u2081\n  end\u27e9\n\nend fin\n", "meta": {"author": "subfish-zhou", "repo": "N2Lean", "sha": "8e858cc5b01f1ad921094dc355db3cb9473a42fd", "save_path": "github-repos/lean/subfish-zhou-N2Lean", "path": "github-repos/lean/subfish-zhou-N2Lean/N2Lean-8e858cc5b01f1ad921094dc355db3cb9473a42fd/library/init/data/fin/ops.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7460266965590708}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport algebra.quaternion\nimport analysis.inner_product_space.basic\n\n/-!\n# Quaternions as a normed algebra\n\nIn this file we define the following structures on the space `\u210d := \u210d[\u211d]` of quaternions:\n\n* inner product space;\n* normed ring;\n* normed space over `\u211d`.\n\n## Notation\n\nThe following notation is available with `open_locale quaternion`:\n\n* `\u210d` : quaternions\n\n## Tags\n\nquaternion, normed ring, normed space, normed algebra\n-/\n\nlocalized \"notation `\u210d` := quaternion \u211d\" in quaternion\nopen_locale real_inner_product_space\n\nnoncomputable theory\n\nnamespace quaternion\n\ninstance : has_inner \u211d \u210d := \u27e8\u03bb a b, (a * b.conj).re\u27e9\n\nlemma inner_self (a : \u210d) : \u27eaa, a\u27eb = norm_sq a := rfl\n\nlemma inner_def (a b : \u210d) : \u27eaa, b\u27eb = (a * b.conj).re := rfl\n\ninstance : inner_product_space \u211d \u210d :=\ninner_product_space.of_core\n{ inner := has_inner.inner,\n  conj_sym := \u03bb x y, by simp [inner_def, mul_comm],\n  nonneg_re := \u03bb x, norm_sq_nonneg,\n  definite := \u03bb x, norm_sq_eq_zero.1,\n  add_left := \u03bb x y z, by simp only [inner_def, add_mul, add_re],\n  smul_left := \u03bb x y r, by simp [inner_def] }\n\nlemma norm_sq_eq_norm_sq (a : \u210d) : norm_sq a = \u2225a\u2225 * \u2225a\u2225 :=\nby rw [\u2190 inner_self, real_inner_self_eq_norm_mul_norm]\n\ninstance : norm_one_class \u210d :=\n\u27e8by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_one, real.sqrt_one]\u27e9\n\n@[simp, norm_cast] lemma norm_coe (a : \u211d) : \u2225(a : \u210d)\u2225 = \u2225a\u2225 :=\nby rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_coe, real.sqrt_sq_eq_abs, real.norm_eq_abs]\n\n@[simp, norm_cast] lemma nnnorm_coe (a : \u211d) : \u2225(a : \u210d)\u2225\u208a = \u2225a\u2225\u208a :=\nsubtype.ext $ norm_coe a\n\nnoncomputable instance : normed_division_ring \u210d :=\n{ dist_eq := \u03bb _ _, rfl,\n  norm_mul' := \u03bb a b, by { simp only [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_mul],\n                           exact real.sqrt_mul norm_sq_nonneg _ } }\n\nnoncomputable instance : normed_algebra \u211d \u210d :=\n{ norm_smul_le := \u03bb a x, (norm_smul a x).le,\n  to_algebra := quaternion.algebra }\n\ninstance : has_coe \u2102 \u210d := \u27e8\u03bb z, \u27e8z.re, z.im, 0, 0\u27e9\u27e9\n\n@[simp, norm_cast] \n\n@[simp, norm_cast] lemma coe_complex_add (z w : \u2102) : \u2191(z + w) = (z + w : \u210d) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_mul (z w : \u2102) : \u2191(z * w) = (z * w : \u210d) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_zero : ((0 : \u2102) : \u210d) = 0 := rfl\n@[simp, norm_cast] lemma coe_complex_one : ((1 : \u2102) : \u210d) = 1 := rfl\n@[simp, norm_cast] lemma coe_real_complex_mul (r : \u211d) (z : \u2102) : (r \u2022 z : \u210d) = \u2191r * \u2191z :=\nby ext; simp\n@[simp, norm_cast] lemma coe_complex_coe (r : \u211d) : ((r : \u2102) : \u210d) = r := rfl\n\n/-- Coercion `\u2102 \u2192\u2090[\u211d] \u210d` as an algebra homomorphism. -/\ndef of_complex : \u2102 \u2192\u2090[\u211d] \u210d :=\n{ to_fun := coe,\n  map_one' := rfl,\n  map_zero' := rfl,\n  map_add' := coe_complex_add,\n  map_mul' := coe_complex_mul,\n  commutes' := \u03bb x, rfl }\n\n@[simp] lemma coe_of_complex : \u21d1of_complex = coe := rfl\n\nend quaternion\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/quaternion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7460266925564637}}
{"text": "import tactic\nimport data.real.sqrt\nimport data.polynomial\n\n/- had help from people on leanprover zulip. thank you! (gareth ma and kevin buzzard) -/\n\n/- fibonacci sequence definition -/\n/- here, we want N -> Z instead of N -> N because of potential issues that may come up when we try to go for (-1)^n. just makes my life easier ngl... -/\ndef fib : \u2115 -> \u2124\n| 0 := 0\n| 1 := 1\n| (x+2) := fib (x) + fib (x+1)\n\n/- end of preamble thing, now we try to prove F_n * F_{n+2} - F_{n+1}^2 = (-1)^n -/\n\nlemma fib_rule (n : \u2115) : fib(n + 2) = fib(n) + fib(n + 1) := rfl\nlemma fib_rule' (n : \u2115) (hn : n > 0) : fib(n + 1) = fib(n) + fib(n - 1) :=\nbegin\n  cases hn,\n  { simp [fib], },\n  { simp [fib], rw add_comm, }\nend\nlemma negative_fib_rule (n : \u2115) : fib(n + 2) - fib(n + 1) = fib (n) :=\nbegin\n  rw [fib_rule],\n  ring,\nend\n\ntheorem strong_induction {P : \u2115 \u2192 Prop} {H : \u2200 n : \u2115, (\u2200 m : \u2115, m < n \u2192 P m) \u2192 P n} (n : \u2115) : P n :=\nbegin\n  have H1 : \u2200 k \u2264 n, P k, {\n    induction n,\n    {\n      intros k hk,\n      apply H,\n      intros m hm,\n      cases hk, cases hm,\n    },\n    {\n      intros k hk,\n      apply H,\n      intros m hm,\n      apply n_ih,\n      apply nat.le_of_lt_succ,\n      apply lt_of_lt_of_le,\n      exact hm,\n      exact hk,\n    },\n  },\n  apply H1,\n  linarith,\nend\n\n-- Fibonacci Addition Law : F_(m+n) = F_(n+1) F_m + F_n F_(m-1)\ntheorem fib_add (m n : \u2115) (hm : m > 0) : fib(m + n) = fib(n + 1) * fib(m) + fib(n) * fib(m - 1) :=\nbegin\n  apply strong_induction n,\n  intros k h,\n  cases k,\n  { simp [fib], },\n  { cases k,\n    { simp [fib, fib_rule' m hm], },\n    { simp only [nat.succ_eq_add_one, add_assoc],\n      norm_num,\n      rw [\u2190add_assoc, fib, nat.succ_eq_add_one, add_assoc m k 1],\n      rw [h k _, h (k + 1) _],\n      rw [fib_rule (k + 1), fib_rule k],\n      ring,\n      exact nat.lt_succ_self _,\n      exact lt_trans (nat.lt_succ_self _) (nat.lt_succ_self _),\n    },\n  },\nend\n\n-- Fibonacci Divisibility : F_m | F_n if m | n.\ntheorem fib_divide (m n : \u2115) (hm : m > 0) (hyp_div : m \u2223 n) : fib(m) \u2223 fib(n) :=\nbegin\n  rcases hyp_div with \u27e8k, rfl\u27e9,\n  induction k,\n  { simp only [fib, mul_zero, dvd_zero], },\n  { rw [nat.succ_eq_add_one, mul_add, add_comm, mul_one, fib_add m (m * k_n) hm],\n    simp only [dvd_add, dvd_mul_left, dvd_mul_of_dvd_left k_ih], },\nend\n\n-- F_n * F_(n+2) - F_(n+1)^2 = (-1)^n\ntheorem fib_close_square (n : \u2115) : fib(n) * fib(n + 2) - fib(n + 1)^2 = (-1)^(n+1) :=\nbegin\n  induction n,\n  {\n    rw [zero_add, zero_add],\n    simp [fib],\n  },\n\n  have H1 : fib n_n.succ * fib n_n.succ + fib n_n.succ * fib (n_n.succ + 1) - fib (n_n.succ + 1) ^ 2 = fib n_n.succ * fib n_n.succ - fib (n_n.succ + 1) * (fib (n_n.succ + 1) - fib n_n.succ),\n    { ring },\n\n  have H2 : fib n_n.succ * fib n_n.succ - fib (n_n.succ + 1) * (fib (n_n.succ + 1) - fib n_n.succ) = fib n_n.succ * fib n_n.succ - fib (n_n.succ + 1) * fib (n_n.succ - 1),\n    { rw negative_fib_rule, ring },\n\n  have H3 : fib (n_n + 1) ^ 2 - fib n_n * fib (n_n + 2) = (-1) * (fib n_n * fib (n_n + 2) - fib (n_n + 1) ^ 2),\n    { linarith, },\n\n  have H4 : (-1 : \u2124) ^ (n_n + 2) = (-1 : \u2124) * (-1) ^ (n_n + 1),\n    { conv begin to_rhs, congr, rw \u2190pow_one (-1 : \u2124), skip end, rw \u2190pow_add, conv begin to_rhs, congr, skip, rw nat.add_left_comm end, },\n\n  {\n    rw [fib_rule, mul_add],\n    rw [H1, H2],\n    ring_nf,\n    rw [\u2190nat.add_one],\n    simp,\n    rw [add_assoc],\n    simp,\n    -- conv begin to_lhs, congr, skip, congr, skip, congr, congr, skip, change 2, end,\n    rw [H3, H4],\n    linarith,\n  },\nend\n\nsection binet\nopen polynomial\n-- todo: prove binet\nnoncomputable def \u03c6 := (1 + real.sqrt(5)) / 2\nnoncomputable def \u03c4 := (1 - real.sqrt(5)) / 2\n-- noncomputable def f : polynomial \u211d := X^2 - X - 1\n\n#check is_root\n\n--lemma binet_lemma_\u03c4 : (f.is_root \u03c4) :=\n\nlemma original_binet_lemma (x : \u211d) (hx : x^2 = x + 1) (n : \u2115) (hn : n > 0) : x^n = x*(fib n) + fib (n-1) :=\nbegin\n  cases n,\n  { exfalso, linarith, },\n  { induction n with n,\n    { simp [fib], },\n    {\n      have H1 : x * \u2191(fib (n + 1)) + \u2191(fib n.succ) = (x + 1) * fib(n+1),\n      { linarith, },\n\n      rw [fib_rule],\n      simp,\n      rw [mul_add, add_assoc, H1, \u2190hx],\n      by_cases x = 0,\n      { exfalso, rw h at hx, linarith, },\n      {\n        rw [nat.succ_eq_add_one, pow_add, pow_one, mul_comm],\n        rw [pow_two, mul_assoc, \u2190mul_add],\n        rw [mul_right_inj' h, add_comm, \u2190nat.succ_eq_add_one],\n        apply n_ih,\n        exact nat.succ_pos n,\n      },\n    },\n  },\nend\n\ntheorem attempt_binet_formula (n : \u2115) : (fib(n) : \u211d) = (1 / real.sqrt(5)) * (((1 + real.sqrt(5)) / 2)^n - ((1 - real.sqrt(5)) / 2)^n) :=\nbegin\n  set \u03c6 := (1 + real.sqrt(5)) / 2, \n  set \u03c4 := (1 - real.sqrt(5)) / 2,\n\n  rw [binet_lemma, binet_lemma],\n  simp[\u03c6, \u03c4],\n  field_simp,\n  norm_num,\n  rw [mul_comm],\n\n  have H1 : (2 * ((1 + real.sqrt 5) * \u2191(fib n)) - 2 * ((1 - real.sqrt 5) * \u2191(fib n))) = fib n * (real.sqrt 5 * 4),\n  {\n    sorry,\n  },\n\n  rw [H1, \u2190div_div_eq_mul_div],\n  simp,\n\n\n  { sorry },\n  { simp[\u03c4], field_simp, ring, rw sub_mul, norm_num, rw [mul_assoc, \u2190pow_two, @real.sq_sqrt 5 (by norm_num)], linarith, },\n  { sorry },\n  { simp[\u03c6], field_simp, norm_num, rw [\u2190pow_two], },\n  \n\n  \n  sorry,\nend\n\n-- binet formula, but kevin buzzard stepped in lmao:\n-- this is just for reference purposes so ig i can learn\nlemma binet_lemma {R : Type*} [comm_ring R] (x : R) (hx : x*x = x + 1) (m : \u2115) :\n  x^(m+1) = x * (fib (m+1)) + fib m :=\nbegin\n  induction m with d hd,\n  { simp [fib], },\n  { rw [pow_succ, hd],\n    simp [fib, nat.succ_eq_add_one, mul_add, \u2190 mul_assoc, hx],\n    ring, }\nend\n\ntheorem binet_formula (n : \u2115) : \n  (fib n : \u211d) = (1 / real.sqrt 5) * (((1 + real.sqrt 5) / 2) ^ n - ((1 - real.sqrt 5) / 2) ^ n) :=\nbegin\n  have sqrt5_not_zero : real.sqrt 5 \u2260 0 := by norm_num,\n  induction n with d hd,\n  { simp [fib], },\n  { rw [nat.succ_eq_add_one, binet_lemma, binet_lemma],\n    { field_simp, norm_num, ring, },\n    { field_simp [mul_sub, sub_mul], norm_num, ring, },\n    { field_simp [mul_add, add_mul], norm_num, ring, },\n  },\nend\n\nend binet\n--useful tactics: norm_num, norm_cast, ring\n\n#check real.sqrt(5)", "meta": {"author": "Vilin97", "repo": "LLL", "sha": "ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9", "save_path": "github-repos/lean/Vilin97-LLL", "path": "github-repos/lean/Vilin97-LLL/LLL-ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9/lawrence/fib stuff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013355, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7459845298325221}}
{"text": "import data.int.basic\n\nnamespace Zmodn\n\n-- variable {n : \u2115}\n\n/- a mod n: a + k*n  -/\nstructure Zmodn : Type :=\n(Z : \u2124)\n(k : \u2124)\n\ndef zero : Zmodn := \u27e80, 0\u27e9\ndef one  : Zmodn := \u27e81, 0\u27e9\n\n/- a + k\u2081*n + b + k\u2082*n = (a + b) + (k\u2081 + k\u2082)*n -/\ndef add (a b : Zmodn) : Zmodn :=\n{\n  Z := a.Z + b.Z,\n  k := a.k + b.k,\n}\nnotation a ` +\u2098 ` b := add a b\n\n/- (a + k\u2081*n) * (b + k\u2082*n) = a*b + (a*k\u2082 + b*k\u2081 + k\u2081*k\u2082*n)*n -/\ndef mul (a b : Zmodn) : Zmodn :=\n{\n  Z := a.Z * b.Z,\n  k := a.Z * b.k + b.Z * a.k + a.k * b.k * 5,\n}\nnotation a ` *\u2098 ` b := mul a b\n\ndef equals (a b : Zmodn) :=\na.Z = b.Z\nnotation a ` =\u2098 ` b := equals a b\n\nlemma reflexive_equals :\n\u2200 a, a =\u2098 a :=\nby {intro, simp [equals]}\n\nlemma symmetric_equals :\n\u2200 a b, (a =\u2098 b) \u2192 (b =\u2098 a) :=\nby {intros a b h, rw equals at *, rw h.symm}\n\nlemma transitive_equals :\n\u2200 a b c, (a =\u2098 b) \u2192 (b =\u2098 c) \u2192 (a =\u2098 c) :=\nby {intros a b c h1 h2, simp [equals, eq.trans h1 h2]}\n\nlemma add_zero :\n\u2200 a, a +\u2098 zero =\u2098 a :=\nby simp [add, zero, equals, int.add_zero]\n\nlemma mul_one :\n\u2200 a, a *\u2098 one =\u2098 a :=\nby simp [mul, one, equals, int.mul_one]\n\nlemma add_comm :\n\u2200 (a b : Zmodn),\n(a +\u2098 b) =\u2098 (b +\u2098 a) :=\nby {intros, simp [add, equals, int.add_comm]}\n\nlemma mul_comm :\n\u2200 (a b : Zmodn),\n(a *\u2098 b) =\u2098 (b *\u2098 a) :=\nby {intros, simp [mul, equals, int.mul_comm]}\n\nlemma add_assoc :\n\u2200 (a b c : Zmodn),\n((a +\u2098 b) +\u2098 c) =\u2098 (a +\u2098 (b +\u2098 c)) :=\nby {intros, simp [add, equals, int.add_assoc]}\n\nlemma mul_assoc :\n\u2200 (a b c : Zmodn),\n((a *\u2098 b) *\u2098 c) =\u2098 (a *\u2098 (b *\u2098 c)) :=\nby {intros, simp [mul, equals, int.mul_assoc]}\n\nlemma distrib :\n\u2200 (a b c : Zmodn),\n(a *\u2098 (b +\u2098 c)) =\u2098 ((a *\u2098 b) +\u2098 (a *\u2098 c)) :=\nby {intros, simp [add, mul, equals, int.distrib_left]}\n\nlemma add_inv :\n\u2200 a, \u2203 b,\na +\u2098 b =\u2098 zero :=\nby {intro, use \u27e8-a.Z, a.k\u27e9, simp [add, zero, equals]}\n\nend Zmodn", "meta": {"author": "BassemSafieldeen", "repo": "Field_Zmodn_of_prime_n", "sha": "51bacb074c70dc4dafec50d3d2220913a18ee8a2", "save_path": "github-repos/lean/BassemSafieldeen-Field_Zmodn_of_prime_n", "path": "github-repos/lean/BassemSafieldeen-Field_Zmodn_of_prime_n/Field_Zmodn_of_prime_n-51bacb074c70dc4dafec50d3d2220913a18ee8a2/src/Zmodn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7459845179088002}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard\n-/\n\nimport algebra.module.basic\nimport linear_algebra.finsupp\nimport linear_algebra.basis\n\n/-!\n\n# Projective modules\n\nThis file contains a definition of a projective module, the proof that\nour definition is equivalent to a lifting property, and the\nproof that all free modules are projective.\n\n## Main definitions\n\nLet `R` be a ring (or a semiring) and let `M` be an `R`-module.\n\n* `is_projective R M` : the proposition saying that `M` is a projective `R`-module.\n\n## Main theorems\n\n* `is_projective.lifting_property` : a map from a projective module can be lifted along\n  a surjection.\n\n* `is_projective.of_lifting_property` : If for all R-module surjections `A \u2192\u2097 B`, all\n  maps `M \u2192\u2097 B` lift to `M \u2192\u2097 A`, then `M` is projective.\n\n* `is_projective.of_free` : Free modules are projective\n\n## Implementation notes\n\nThe actual definition of projective we use is that the natural R-module map\nfrom the free R-module on the type M down to M splits. This is more convenient\nthan certain other definitions which involve quantifying over universes,\nand also universe-polymorphic (the ring and module can be in different universes).\n\nEverything works for semirings and modules except that apparently\nwe don't have free modules over semirings, so here we stick to rings.\n\n## References\n\nhttps://en.wikipedia.org/wiki/Projective_module\n\n## TODO\n\n- Direct sum of two projective modules is projective.\n- Arbitrary sum of projective modules is projective.\n- Any module admits a surjection from a projective module.\n\nAll of these should be relatively straightforward.\n\n## Tags\n\nprojective module\n\n-/\n\nuniverses u v\n\n/- The actual implementation we choose: `P` is projective if the natural surjection\n   from the free `R`-module on `P` to `P` splits. -/\n/-- An R-module is projective if it is a direct summand of a free module, or equivalently\n  if maps from the module lift along surjections. There are several other equivalent\n  definitions. -/\ndef is_projective\n  (R : Type u) [semiring R] (P : Type v) [add_comm_monoid P] [module R P] : Prop :=\n\u2203 s : P \u2192\u2097[R] (P \u2192\u2080 R), function.left_inverse (finsupp.total P P R id) s\n\nnamespace is_projective\n\nsection semiring\n\nvariables {R : Type u} [semiring R] {P : Type v} [add_comm_monoid P] [module R P]\n  {M : Type*} [add_comm_group M] [module R M] {N : Type*} [add_comm_group N] [module R N]\n\n/-- A projective R-module has the property that maps from it lift along surjections. -/\ntheorem lifting_property (h : is_projective R P) (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N)\n  (hf : function.surjective f) : \u2203 (h : P \u2192\u2097[R] M), f.comp h = g :=\nbegin\n  /-\n  Here's the first step of the proof.\n  Recall that `X \u2192\u2080 R` is Lean's way of talking about the free `R`-module\n  on a type `X`. The universal property `finsupp.total` says that to a map\n  `X \u2192 N` from a type to an `R`-module, we get an associated R-module map\n  `(X \u2192\u2080 R) \u2192\u2097 N`. Apply this to a (noncomputable) map `P \u2192 M` coming from the map\n  `P \u2192\u2097 N` and a random splitting of the surjection `M \u2192\u2097 N`, and we get\n  a map `\u03c6 : (P \u2192\u2080 R) \u2192\u2097 M`.\n  -/\n  let \u03c6 : (P \u2192\u2080 R) \u2192\u2097[R] M := finsupp.total _ _ _ (\u03bb p, function.surj_inv hf (g p)),\n  -- By projectivity we have a map `P \u2192\u2097 (P \u2192\u2080 R)`;\n  cases h with s hs,\n  -- Compose to get `P \u2192\u2097 M`. This works.\n  use \u03c6.comp s,\n  ext p,\n  conv_rhs {rw \u2190 hs p},\n  simp [\u03c6, finsupp.total_apply, function.surj_inv_eq hf],\nend\n\n/-- A module which satisfies the universal property is projective. Note that the universe variables\nin `huniv` are somewhat restricted. -/\ntheorem of_lifting_property {R : Type u} [semiring R]\n  {P : Type v} [add_comm_monoid P] [module R P]\n  -- If for all surjections of `R`-modules `M \u2192\u2097 N`, all maps `P \u2192\u2097 N` lift to `P \u2192\u2097 M`,\n  (huniv : \u2200 {M : Type (max v u)} {N : Type v} [add_comm_monoid M] [add_comm_monoid N],\n    by exactI\n    \u2200 [module R M] [module R N],\n    by exactI\n    \u2200 (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N),\n  function.surjective f \u2192 \u2203 (h : P \u2192\u2097[R] M), f.comp h = g) :\n  -- then `P` is projective.\n  is_projective R P :=\nbegin\n  -- let `s` be the universal map `(P \u2192\u2080 R) \u2192\u2097 P` coming from the identity map `P \u2192\u2097 P`.\n  obtain \u27e8s, hs\u27e9 : \u2203 (s : P \u2192\u2097[R] P \u2192\u2080 R),\n    (finsupp.total P P R id).comp s = linear_map.id :=\n    huniv (finsupp.total P P R (id : P \u2192 P)) (linear_map.id : P \u2192\u2097[R] P) _,\n  -- This `s` works.\n  { use s,\n    rwa linear_map.ext_iff at hs },\n  { intro p,\n    use finsupp.single p 1,\n    simp },\nend\n\nend semiring\n\nsection ring\n\nvariables {R : Type u} [ring R] {P : Type v} [add_comm_group P] [module R P]\n\n/-- Free modules are projective. -/\ntheorem of_free {\u03b9 : Type*} {b : \u03b9 \u2192 P} (hb : is_basis R b) : is_projective R P :=\nbegin\n  -- need P \u2192\u2097 (P \u2192\u2080 R) for definition of projective.\n  -- get it from `\u03b9 \u2192 (P \u2192\u2080 R)` coming from `b`.\n  use hb.constr (\u03bb i, finsupp.single (b i) 1),\n  intro m,\n  simp only [hb.constr_apply, mul_one, id.def, finsupp.smul_single', finsupp.total_single,\n    linear_map.map_finsupp_sum],\n  exact hb.total_repr m,\nend\n\nend ring\n\nend is_projective\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/module/projective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7459845078506802}}
{"text": "import tactic\n\n-- References: Schmidt, G. (2010) Relational Mathematics. Cambridge: Cambridge University Press (Encyclopedia of Mathematics and its Applications). doi: 10.1017/CBO9780511778810.\n\nnamespace myrelation\nvariables {\u03b1 \u03b2 \u03b3 A: Type*}\n\ndef union (r : \u03b1 \u2192 \u03b2 \u2192 Prop) (s : \u03b1 \u2192 \u03b2 \u2192 Prop) (a : \u03b1) (b : \u03b2) : Prop := r a b \u2228 s a b\ndef intersect (r : \u03b1 \u2192 \u03b2 \u2192 Prop) (s : \u03b1 \u2192 \u03b2 \u2192 Prop) (a : \u03b1) (b : \u03b2) : Prop := r a b \u2227 s a b\n\ndef reflexive (R : A \u2192 A \u2192 Prop) : Prop := \u2200 x, R x x\ndef irreflexive (R : A \u2192 A \u2192 Prop) : Prop := \u2200 x, \u00ac R x x\ndef symmetric (R : A \u2192 A \u2192 Prop) : Prop := \u2200 x y, R x y \u2192 R y x\ndef asymmetric (R : A \u2192 A \u2192 Prop) : Prop := \u2200 (a b : A), R a b \u2192 \u00ac(R b a)\ndef transitive (R : A \u2192 A \u2192 Prop) : Prop := \u2200 x y z, R x y \u2192 R y z \u2192 R x z\ndef anti_symmetric (R : A \u2192 A \u2192 Prop) : Prop := \u2200 x y, R x y \u2192 R y x \u2192 x = y\n\ndef preorder (R : A \u2192 A \u2192 Prop) : Prop := reflexive R \u2227 transitive R\ndef total (R : A \u2192 A \u2192 Prop) : Prop := \u2200 x y, R x y \u2228 R y x\ndef partial_order (R : A \u2192 A \u2192 Prop) : Prop := preorder R \u2227 anti_symmetric R\ndef total_order (R : A \u2192 A \u2192 Prop) : Prop := partial_order R \u2227 total R\ndef strict_order (R : A \u2192 A \u2192 Prop) : Prop := transitive R \u2227 asymmetric R\n\n-- 2021 IUM Final Q1c\n    -- R, S two binary relations on set {A : Type}. \n    -- Define relations `def T (a b : A) : Prop := R a b \u2227 S a b`, \n    -- `def U (a b : A) : Prop := R a b \u2228 S a b`\n    -- (i)    If R, S equivalence relations, then T is equivalence relation\n    -- (ii)   If R, S equivalence relations, then U may not be an equivalence relation.\n    -- (iii)  If R, S antisymmetric, then T is also antisymmetric.\n    -- (iv)   If R, S antisymmetric, then U may not be antisymmetric.\n\n-- Extension\n-- (1) Reflexivity: preserved under \u222a and \u2229. (shown in (i)(ii))\nexample (R S : A \u2192 A \u2192 Prop) (reflR : reflexive R) (reflS : reflexive S) : reflexive (intersect R S) :=\nbegin\n  intro x,\n  split,\n  apply reflR x,\n  apply reflS x,\nend\n\nexample (R S : A \u2192 A \u2192 Prop) (reflR : reflexive R) (reflS : reflexive S) : reflexive (union R S) :=\nbegin\n  intro x,\n  left,\n  apply reflR x,\nend\n\n-- (2) Symmetry: preserved under \u222a and \u2229. (shown in (i)(ii))\nexample (R S : A \u2192 A \u2192 Prop) (symmR : symmetric R) (symmS : symmetric S) : symmetric (intersect R S) :=\nbegin\n  intros x y h,\n  cases h with hRxy hSxy,\n  split,\n  apply symmR x y hRxy,\n  apply symmS x y hSxy,\nend\n\nexample (R S : A \u2192 A \u2192 Prop) (symmR : symmetric R) (symmS : symmetric S) : symmetric (union R S) :=\nbegin\n  intros x y h,\n  cases h with hRxy hSxy,\n  left, apply symmR x y hRxy,\n  right, apply symmS x y hSxy,\nend\n\n-- (3) Transitivity: preserved only under \u2229, but not \u222a (shown in (i)(ii))\nexample (R S : A \u2192 A \u2192 Prop) (transR : transitive R) (transS : transitive S) : transitive (intersect R S) :=\nbegin\n  intros x y z h1 h2,\n  cases h1 with hRxy hSxy,\n  cases h2 with hRyz hSyz,\n  split,\n  { apply transR x y z hRxy hRyz},\n  { apply transS x y z hSxy hSyz},\nend\n\n-- Counterexample for `\u222a`: Idea (For a,b,c, we construct R and S that\n                     -- R(a,b), S(b,c) true, R(b,c), S(a,b) false, R(a,c), S(a,c) false)\n                     -- In fact, such R and S exist\n                     -- Let X = {a,b,c}\n                     -- R(a,a), R(b,b), R(c,c), R(a,b), R(b,a) true, else false\n                     -- S(a,a), S(b,b), S(c,c), S(b,c), S(b,c) true, else false\n\nnamespace transitivity\n\ninductive X : Type\n| a : X\n| b : X\n| c : X\n\nnamespace X\n\n-- Define binary relation R such that \n-- R(a,a), R(b,b), R(c,c), R(a,b), R(b,a) true, else false\ndef R : X \u2192 X \u2192 Prop\n| a a := true\n| b b := true\n| c c := true\n| a b := true\n| b a := true\n| b c := false\n| c b := false\n| a c := false\n| c a := false\n\n-- Define binary relation S such that \n-- S(a,a), S(b,b), S(c,c), S(b,c), S(b,c) true, else false\ndef S : X \u2192 X \u2192 Prop\n| a a := true\n| b b := true\n| c c := true\n| a b := false\n| b a := false\n| b c := true\n| c b := true\n| a c := false\n| c a := false\n\ndef U (x y : X) : Prop := R x y \u2228 S x y\n\n-- R is transitive\nlemma R_trans : transitive R :=\nbegin\n  rintros x y z,\n    rcases x,\n      -- x = a\n      rcases y,\n        -- y = a\n          rcases z, -- 3 cases\n            repeat {intros h1 h2, triv}, -- solves first two T \u2192 T cases\n            intros h1 h2, exact h2, -- solve last case\n        -- y = b\n          rcases z, -- 3 cases\n            repeat {intros h1 h2, triv}, -- solves first two T \u2192 T cases\n            intros h1 h2, exact h2, -- solve last case\n        -- y = c\n          rcases z, -- 3 cases\n            repeat {intros h1 h2, triv}, -- solves first two T \u2192 T cases\n            intros h1 h2, exact h1, -- solve last case\n      \n      -- x = b\n      rcases y,  \n        -- y = a\n          rcases z,\n            repeat {intros h1 h2, triv},\n            intros h1 h2, exact h2,\n        -- y = b\n          rcases z,\n            repeat {intros h1 h2, triv},\n            intros h1 h2, exact h2,\n        -- y = c\n          rcases z,\n            repeat {intros h1 h2, triv},\n            intros h1 h2, exact h1,\n      -- x = c\n      rcases y,\n        -- y = a\n          rcases z, \n            intros h1 h2, exact h1,\n            intros h1 h2, by_contra h3, exact h1,\n            intros h1 h2, triv,\n        -- y = b\n          rcases z,\n            intros h1 h2, by_contra h3, exact h1, \n            intros h1 h2, exact h1,\n            intros h1 h2, triv,\n        -- y = c\n          rcases z,\n            repeat {intros h1 h2, exact h2},\nend\n\n-- S is transitive\nlemma S_trans : transitive S :=\nbegin\n  rintros x y z,\n    rcases x,\n      -- x = a\n      rcases y,\n        -- y = a\n          rcases z, -- 3 cases\n            intros h1 h2, triv,\n            repeat {intros h1 h2, exact h2},\n        -- y = b\n          rcases z, -- 3 cases\n            intros h1 h2, triv,\n            repeat {intros h1 h2, exact h1},\n        -- y = c\n          rcases z, -- 3 cases\n            intros h1 h2, triv, -- solves first two T \u2192 T cases\n            repeat {intros h1 h2, exact h1}, -- solve last case\n      \n      -- x = b\n      rcases y,  \n        -- y = a\n          rcases z,\n            intros h1 h2, exact h1,\n            repeat {intros h1 h2, triv},\n        -- y = b\n          rcases z,\n            repeat {intros h1 h2, triv},\n            intros h1 h2, exact h2,\n        -- y = c\n          rcases z,\n            repeat {intros h1 h2, triv},\n            intros h1 h2, by_contra h3, exact h2,\n      -- x = c\n      rcases y,\n        -- y = a\n          rcases z, \n            intros h1 h2, exact h1,\n            intros h1 h2, by_contra h3, exact h1,\n            intros h1 h2, triv,\n        -- y = b\n          rcases z,\n            intros h1 h2, by_contra h3, exact h2, \n            intros h1 h2, exact h1,\n            intros h1 h2, triv,\n        -- y = c\n          rcases z,\n            repeat {intros h1 h2, exact h2},\nend\n\n-- U is not transitive\nexample : \u00ac(\u2200 A : Type, \u2200 (R: A \u2192 A \u2192 Prop) (S: A \u2192 A \u2192 Prop), (transitive R \u2192 transitive S) \u2192 transitive U) := \nbegin\n  intro h, -- change to `hypothesis \u2192 false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { intro transR,\n    exact S_trans}, -- Prove S is equivalence relation\n  { -- rw transitive at h,\n    have h1 : U a b, -- show hypothesis that U a b is true\n      {left, triv},\n    have h2 : U b c, -- show hypothesis that U b c is true\n      {right, triv},\n    specialize h a b c h1 h2, -- focus on the specific case with h1, h2\n    rcases h, repeat {exact h}, -- since U a c = R a c \u2228 S a c, use the fact that R a c and S a c are false\n  },\nend\n\nend X\nend transitivity\n-- The above is also a counter-example to the following question in 2021 IUM Q1c:\n-- (ii) If R, S equivalence relations, then U may not be an equivalence relation.\n\n-- (4) Anti-symmetry: preserved only under \u2229, but not \u222a (shown in (iii)(iv))\n\nexample (R S : A \u2192 A \u2192 Prop) (antisymmR : anti_symmetric R) (antisymmS : anti_symmetric S) : anti_symmetric (intersect R S) :=\n  begin\n    intros a b hab hba,\n    cases hab with hRab hSab,\n    cases hba with hRba hSba,\n    apply antisymmR a b hRab hRba,\n  end\n\n-- Counterexample for `\u222a`: Let X = {a,b}\n                        -- R(a,b) true, else false\n                        -- S(b,a) true, else false\n                        -- Then U(a,b) and U(b,a) are true, but a \u2260 b\n\nnamespace antisymmetry\n\ninductive X : Type\n| a : X\n| b : X\n\nnamespace X\n\n-- Define binary relation R such that \n-- R(a,b) true, else false\ndef R : X \u2192 X \u2192 Prop\n| a a := false\n| a b := true\n| b a := false\n| b b := false\n\n-- Define binary relation R such that \n-- S(b,a) true, else false\ndef S : X \u2192 X \u2192 Prop\n| a a := false\n| a b := false\n| b a := true\n| b b := false\n\n\ndef U (x y : X) : Prop := R x y \u2228 S x y\n\n-- R is antisymmetric\nlemma Q_iv_R_antisymm : anti_symmetric R :=\nbegin\n  intros x y hXY hYX,\n  rcases x,\n    -- x = a\n    rcases y,\n      refl, -- the case y = a\n      exfalso, exact hYX, -- the case y = b\n    -- x = b\n    rcases y,\n      exfalso, exact hXY, -- the case y = a\n      refl, -- the case y = b\nend\n\n-- S is antisymmetric\nlemma Q_iv_S_antisymm : anti_symmetric S :=\nbegin\n  intros x y hXY hYX,\n  rcases x,\n    -- x = a\n    rcases y,\n      refl, -- the case y = a\n      exfalso, exact hXY, -- the case y = b\n    -- x = b\n    rcases y,\n      exfalso, exact hYX, -- the case y = a\n      refl, -- the case y = b\nend\n\n-- U is NOT antisymmetric\nexample : \u00ac(\u2200 A : Type, \u2200 (R: A \u2192 A \u2192 Prop) (S: A \u2192 A \u2192 Prop), (anti_symmetric R \u2192 anti_symmetric S) \u2192 anti_symmetric U) := \nbegin\n  intro h, -- change to `hypothesis \u2192 false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { intro antisymmR,\n    exact Q_iv_S_antisymm}, -- Prove S is antisymmetric\n  { rw anti_symmetric at h,\n    have h1 : U a b, -- show hypothesis that U a b is true\n      {left, triv},\n    have h2 : U b a, -- show hypothesis that U b a is true\n      {right, triv},\n    specialize h a b h1 h2, -- focus on the specific case with h1, h2\n    rcases h, -- check that `h` is false\n  },\nend\n\nend X\nend antisymmetry\n\n-- (5) Asymmetry: preserved only under \u2229, but not \u222a.\nexample (R S : A \u2192 A \u2192 Prop) (asymmR : asymmetric R) (asymmS : asymmetric S) : asymmetric (intersect R S) :=\nbegin\n  intros x y h1 h2,\n  cases h1 with hRxy hSxy,\n  cases h2 with hRyx hSyx,\n  apply asymmR x y hRxy hRyx,\nend\n\nnamespace asymmetry\n\ninductive X : Type\n| a : X\n| b : X\n\nnamespace X\n\n-- Define binary relation R such that \n-- R(a,b) true, else false\ndef R : X \u2192 X \u2192 Prop\n| a a := false\n| a b := true\n| b a := false\n| b b := false\n\n-- Define binary relation R such that \n-- S(b,a) true, else false\ndef S : X \u2192 X \u2192 Prop\n| a a := false\n| a b := false\n| b a := true\n| b b := false\n\n\ndef U (x y : X) : Prop := R x y \u2228 S x y\n\n-- R is asymmetric\nlemma R_asymm : asymmetric R :=\nbegin\n  intros x y hxy hyx,\n  rcases x,\n    -- x = a\n    rcases y,\n      exact hxy, -- the case y = a; follows that `R a a` is false\n      exact hyx, -- the case y = b; follows that `R b a` is false\n\n    -- x = b\n    rcases y,\n      exact hxy, -- the case y = a; follows that `R b a` is false\n      exact hxy, -- the case y = b; follows that `R b b` is false\nend\n\n-- S is asymmetric\nlemma S_asymm : asymmetric S :=\nbegin\n  intros x y hxy hyx,\n  rcases x,\n    -- x = a\n    rcases y,\n      exact hxy, -- the case y = a; follows that `R a a` is false\n      exact hxy, -- the case y = b; follows that `R b a` is false\n\n    -- x = b\n    rcases y,\n      exact hyx, -- the case y = a; follows that `R b a` is false\n      exact hxy, -- the case y = b; follows that `R b b` is false\nend\n\n-- U is NOT asymmetric\nexample : \u00ac(\u2200 A : Type, \u2200 (R: A \u2192 A \u2192 Prop) (S: A \u2192 A \u2192 Prop), (asymmetric R \u2192 asymmetric S) \u2192 asymmetric U) := \nbegin\n  intro h, -- change to `hypothesis \u2192 false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { intro asymmR,\n    exact S_asymm}, -- Prove S is antisymmetric\n  { rw asymmetric at h,\n    have h1 : U a b, -- show hypothesis that U a b is true\n      {left, triv},\n    have h2 : U b a, -- show hypothesis that U b a is true\n      {right, triv},\n    specialize h a b h1 h2, -- focus on the specific case with h1, h2\n    rcases h, -- check that `h` is false\n  },\nend\n\nend X\nend asymmetry\n\n-- (6) Irreflexivity: preserved under \u222a and \u2229.\nexample (R S : A \u2192 A \u2192 Prop) (irrflR : irreflexive R) (irrflS : irreflexive S) : irreflexive (intersect R S) :=\nbegin\n  intros x h,\n  cases h with hR hS,\n  apply irrflS x hS,\nend\n\nexample (R S : A \u2192 A \u2192 Prop) (irrflR : irreflexive R) (irrflS : irreflexive S) : irreflexive  (union R S) :=\nbegin\n  intros x h,\n  cases h with hR hS,\n  apply irrflR x hR,\n  apply irrflS x hS,\nend\n\n-- (7) Totality: preserved only under \u222a, but not \u2229.\n\nexample (R S : A \u2192 A \u2192 Prop) (totalR : total R) (totalS : total S) : total (union R S) :=\nbegin\n  intros x y,\n  specialize totalR x y,\n  specialize totalS x y,\n  cases totalR with hRxy hRyx,\n  { cases totalS with hSxy hSyx,\n    left, left, exact hRxy,\n    right, right, exact hSyx},\n  { cases totalS with hSxy hSyx,\n    right, left, exact hRyx,\n    right, right, exact hSyx},\nend\n\nnamespace totality\n\ninductive X : Type\n| a : X\n| b : X\n\nnamespace X\n\n-- Define binary relation R such that \n-- R(a,b) true, else false\ndef R : X \u2192 X \u2192 Prop\n| a a := true\n| a b := true\n| b a := false\n| b b := true\n\n-- Define binary relation R such that \n-- S(b,a) true, else false\ndef S : X \u2192 X \u2192 Prop\n| a a := true\n| a b := false\n| b a := true\n| b b := true\n\ndef T (x y : X) : Prop := R x y \u2227 S x y\n\n-- R is total\nlemma R_total : total R :=\nbegin\n  intros x y,\n  rcases x,\n    -- x = a\n    rcases y,\n      left, triv, -- the case y = a; follows that `R a a` is true\n      left, triv, -- the case y = b; follows that `R a b` is true\n\n    -- x = b\n    rcases y,\n      right, triv, -- the case y = a; follows that `R a b` is true\n      right, triv, -- the case y = b; follows that `R b b` is true\nend\n\n-- S is total\nlemma S_total : total S :=\nbegin\n  intros x y,\n  rcases x,\n    -- x = a\n    rcases y,\n      left, triv, -- the case y = a; follows that `R a a` is true\n      right, triv, -- the case y = b; follows that `R b a` is true\n\n    -- x = b\n    rcases y,\n      left, triv, -- the case y = a; follows that `R b a` is true\n      right, triv, -- the case y = b; follows that `R b b` is true\nend\n\n-- T is NOT asymmetric\nexample : \u00ac(\u2200 A : Type, \u2200 (R: A \u2192 A \u2192 Prop) (S: A \u2192 A \u2192 Prop), (total R \u2192 total S) \u2192 total T) := \nbegin\n  intro h, -- change to `hypothesis \u2192 false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { intro totalR,\n    exact S_total}, -- Prove S is antisymmetric\n  { rw total at h,\n    have h1 : \u00ac(T a b), -- show hypothesis that T a b is false\n      {intro hTab, cases hTab with hRab hSab, apply hSab},\n    have h2 : \u00ac(T b a), -- show hypothesis that T b a is false\n      {intro hTba, cases hTba with hRba hSba, apply hRba},\n    specialize h a b, -- focus on the specific case with x = a, y = b\n    rcases h, -- check that `h` is false\n    {apply h1, exact h},\n    {apply h2, exact h},\n  },\nend\n\nend X\nend totality\n\nend myrelation\n", "meta": {"author": "josephho1013", "repo": "Xena-Summer-Project-2022", "sha": "9899ff2fd303f8eda14412f8be546e236a7a47dc", "save_path": "github-repos/lean/josephho1013-Xena-Summer-Project-2022", "path": "github-repos/lean/josephho1013-Xena-Summer-Project-2022/Xena-Summer-Project-2022-9899ff2fd303f8eda14412f8be546e236a7a47dc/Relations_in_lean_(2_1_exercises_predicates).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552536, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7458776970311226}}
{"text": "import category_theory.category.default\n\nuniverses v u  -- The order in this declaration matters: v often needs to be explicitly specified while u often can be omitted\n\nnamespace category_theory\n\nvariables (C : Type u) [category.{v} C]\n\n/-\n# Category world\n\n## Level 7: Monomorphisms & epimorphisms\n\nA monomorphism `f : Y \u27f6 Z` is a morphism such that, for all pairs `g h : X \u27f6 Y`, if `h \u226b f = g \u226b f`, \nthen ` h = g`.\n\nSimilarly, an epimorphism `f : X \u27f6 Y` is a morphism such that, for all pairs `g h : Y \u27f6 Z`, if `f \u226b h = f \u226b g`, then ` h = g`.\n\nCategory theorists commonly refer to monomorphisms and epimorphisms as `mono` and `epi` respectively, and this is the case in Lean as well. \n\nSo this gives us axioms\n-/\n\n/- Axiom:\n    mono f, g h : Y \u27f6 Z, f \u226b g = f \u226b h \u2192 g = h-/ --figure out how to phrase these axioms jeez\n\n/-We will now prove that, if `f` is mono, then f \u226b g = f \u226b h \u2194 g = h so we can use `rw`.-/\n\n/- Lemma\nIf $$f : X \u27f6 Y$$ and $$g : X \u27f6 Y$$ are morphisms such that $$f = g$$, then $$f \u226b h = g \u226b h$$.\n-/\nlemma cancel_mono' (X Y Z : C) (f : X \u27f6 Y) [mono f] {g h : Z \u27f6 X} : (g \u226b f = h \u226b f) \u2194 g = h :=\nbegin\n    split,\n    \n    intro hyp,\n    apply mono.right_cancellation g h hyp,\n\n    intro hyp,\n    rw hyp,\nend\n\nend category_theory", "meta": {"author": "agusakov", "repo": "category-theory-game", "sha": "652dd7e90ae706643b2a597e2c938403653e167d", "save_path": "github-repos/lean/agusakov-category-theory-game", "path": "github-repos/lean/agusakov-category-theory-game/category-theory-game-652dd7e90ae706643b2a597e2c938403653e167d/src/game/world3/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7458776931871429}}
{"text": "import tactic -- hide\nimport data.real.basic -- hide\n\n/-\n## The `have` tactic\n\nIt is common in proofs to introduce auxiliary results, or claims, that help towards the goal. *Lean*\nallows for this kind of structure, by allowing you to insert new hypotheses (as long as you prove them,\nof course). This is done with the `have` tactic. The syntax is `have h : P,` where `h` is the name\nyou want to give to the new hypothesis (check that it doesn't exist already or you will run intro problems)\nand `P` is a predicate like `x + 3 = 5`. You will get two goals, the first one will be to prove `P`,\nand the second one will be the original goal. In the second one, you will have `h` available.\n\nThe next lemma cannot be proven by `ring` directly, since it involves an arbitrary exponent. There\nare tactics that work with these kind of equations, but we will do something easier. If we can prove\nfirst that $x+y=y+x$, then replacing that equality on the left-hand side will immediately finish the\ngoal. So start with `have h : x + y = y + x,` and work from there.\n-/\n/- Symbol:\n\u211d : \\R\n-/\n/- Lemma : no-side-bar\nFor all $n$, we have $(x+y)^n=(y+x)^n$.\n-/\nlemma h0 (x y : \u211d) (n : \u2115) : (x + y)^n = (y + x)^n :=\nbegin\n  have h : x + y = y + x,\n  {\n    ring,\n  },\n  rw h,\n\n\n\n\nend\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/tactics_world/04_have.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391621868805, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7458776837884297}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam\n-/\n\nimport data.mv_polynomial.variables\nimport algebra.module.basic\nimport tactic.ring\n\n/-!\n# Partial derivatives of polynomials\n\nThis file defines the notion of the formal *partial derivative* of a polynomial,\nthe derivative with respect to a single variable.\nThis derivative is not connected to the notion of derivative from analysis.\nIt is based purely on the polynomial exponents and coefficients.\n\n## Main declarations\n\n* `mv_polynomial.pderiv i p` : the partial derivative of `p` with respect to `i`.\n\n## Notation\n\nAs in other polynomial files, we typically use the notation:\n\n+ `\u03c3 : Type*` (indexing the variables)\n\n+ `R : Type*` `[comm_ring R]` (the coefficients)\n\n+ `s : \u03c3 \u2192\u2080 \u2115`, a function from `\u03c3` to `\u2115` which is zero away from a finite set.\nThis will give rise to a monomial in `mv_polynomial \u03c3 R` which mathematicians might call `X^s`\n\n+ `a : R`\n\n+ `i : \u03c3`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians\n\n+ `p : mv_polynomial \u03c3 R`\n\n-/\n\nnoncomputable theory\n\nopen_locale classical big_operators\n\nopen set function finsupp add_monoid_algebra\nopen_locale big_operators\n\nuniverses u\nvariables {R : Type u}\n\nnamespace mv_polynomial\nvariables {\u03c3 : Type*} {a a' a\u2081 a\u2082 : R} {s : \u03c3 \u2192\u2080 \u2115}\n\nsection pderiv\n\nvariables {R} [comm_semiring R]\n\n/-- `pderiv i p` is the partial derivative of `p` with respect to `i` -/\ndef pderiv (i : \u03c3) : mv_polynomial \u03c3 R \u2192\u2097[R] mv_polynomial \u03c3 R :=\n{ to_fun := \u03bb p, p.sum (\u03bb A B, monomial (A - single i 1) (B * (A i))),\n  map_smul' := begin\n    intros c x,\n    rw [sum_smul_index', smul_sum],\n    { dsimp, simp_rw [\u2190 (monomial _).map_smul, smul_eq_mul, mul_assoc] },\n    { intros s,\n      simp only [monomial_zero, zero_mul] }\n  end,\n  map_add' := \u03bb f g, sum_add_index (by simp only [monomial_zero, forall_const, zero_mul])\n    (by simp only [add_mul, forall_const, eq_self_iff_true, (monomial _).map_add]), }\n\n@[simp]\nlemma pderiv_monomial {i : \u03c3} :\n  pderiv i (monomial s a) = monomial (s - single i 1) (a * (s i)) :=\nby simp only [pderiv, monomial_zero, sum_monomial_eq, zero_mul, linear_map.coe_mk]\n\n\n@[simp]\nlemma pderiv_C {i : \u03c3} : pderiv i (C a) = 0 :=\nsuffices pderiv i (monomial 0 a) = 0, by simpa,\nby simp only [monomial_zero, pderiv_monomial, nat.cast_zero, mul_zero, zero_apply]\n\n@[simp]\nlemma pderiv_one {i : \u03c3} : pderiv i (1 : mv_polynomial \u03c3 R) = 0 := pderiv_C\n\nlemma pderiv_eq_zero_of_not_mem_vars {i : \u03c3} {f : mv_polynomial \u03c3 R} (h : i \u2209 f.vars) :\n  pderiv i f = 0 :=\nbegin\n  change (pderiv i) f = 0,\n  rw [f.as_sum, linear_map.map_sum],\n  apply finset.sum_eq_zero,\n  intros x H,\n  simp [mem_support_not_mem_vars_zero H h],\nend\n\nlemma pderiv_X [decidable_eq \u03c3] {i j : \u03c3} :\n  pderiv i (X j : mv_polynomial \u03c3 R) = if i = j then 1 else 0 :=\nbegin\n  refine pderiv_monomial.trans _,\n  rcases eq_or_ne i j with (rfl|hne),\n  { simp },\n  { simp [hne, hne.symm] }\nend\n\n@[simp] lemma pderiv_X_self {i : \u03c3} : pderiv i (X i : mv_polynomial \u03c3 R) = 1 :=\nby simp [pderiv_X]\n\nlemma pderiv_monomial_single {i : \u03c3} {n : \u2115} :\n  pderiv i (monomial (single i n) a) = monomial (single i (n-1)) (a * n) :=\nby simp\n\nprivate lemma monomial_sub_single_one_add {i : \u03c3} {s' : \u03c3 \u2192\u2080 \u2115} :\n  monomial (s - single i 1 + s') (a * (s i) * a') =\n    monomial (s + s' - single i 1) (a * (s i) * a') :=\nby by_cases h : s i = 0; simp [h, sub_single_one_add]\n\nprivate lemma monomial_add_sub_single_one {i : \u03c3} {s' : \u03c3 \u2192\u2080 \u2115} :\n  monomial (s + (s' - single i 1)) (a * (a' * (s' i))) =\n    monomial (s + s' - single i 1) (a * (a' * (s' i))) :=\nby by_cases h : s' i = 0; simp [h, add_sub_single_one]\n\nlemma pderiv_monomial_mul {i : \u03c3} {s' : \u03c3 \u2192\u2080 \u2115} :\n  pderiv i (monomial s a * monomial s' a') =\n    pderiv i (monomial s a) * monomial s' a' + monomial s a * pderiv i (monomial s' a') :=\nbegin\n  simp only [monomial_sub_single_one_add, monomial_add_sub_single_one, pderiv_monomial,\n    pi.add_apply, monomial_mul, nat.cast_add, coe_add],\n  rw [mul_add, (monomial _).map_add, \u2190 mul_assoc, mul_right_comm a _ a']\nend\n\n@[simp]\nlemma pderiv_mul {i : \u03c3} {f g : mv_polynomial \u03c3 R} :\n  pderiv i (f * g) = pderiv i f * g + f * pderiv i g :=\nbegin\n  apply induction_on' f,\n  { apply induction_on' g,\n    { intros u r u' r', exact pderiv_monomial_mul },\n    { intros p q hp hq u r,\n      rw [mul_add, linear_map.map_add, hp, hq, mul_add, linear_map.map_add],\n      ring } },\n  { intros p q hp hq,\n    simp [add_mul, hp, hq],\n    ring, }\nend\n\n@[simp]\nlemma pderiv_C_mul {f : mv_polynomial \u03c3 R} {i : \u03c3} :\n  pderiv i (C a * f) = C a * pderiv i f :=\nby convert linear_map.map_smul (pderiv i) a f; rw C_mul'\n\n@[simp]\nlemma pderiv_pow {i : \u03c3} {f : mv_polynomial \u03c3 R} {n : \u2115} :\n  pderiv i (f^n) = n * pderiv i f * f^(n-1) :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp only [nat.succ_sub_succ_eq_sub, nat.cast_succ, tsub_zero, mv_polynomial.pderiv_mul,\n      pow_succ, ih],\n    cases n,\n    { simp, },\n    { simp only [nat.succ_eq_add_one, nat.add_succ_sub_one, add_zero, nat.cast_add, nat.cast_one,\n        pow_succ],\n      ring, }, },\nend\n\n@[simp]\nlemma pderiv_nat_cast {i : \u03c3} {n : \u2115} : pderiv i (n : mv_polynomial \u03c3 R) = 0 :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih], },\nend\n\nend pderiv\n\nend mv_polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/mv_polynomial/pderiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7458776825210122}}
{"text": "import betweenness_world.level04 --hide\nopen IncidencePlane --hide\n\n/- Axiom :\nbetween_symmetric {A B C : \u03a9} : (A * B * C) \u2194 (C * B * A)\n-/\n\n/-\n# Betweenness World\n\n## Level 5: the definition of segment.\n\nWe've already seen how to define some primitive notions from a given set of axioms, such as **point**, **line**, **incidence** or **betweenness**. In\nmathematics, we can also define new concepts by combining those that we've learned so far. In this way, the notion of **segment** joins the party.\n\n**Definition:** a point C is in the segment A\u00b7B if and only if A * C * B or C = A or C = B.\n\nIn Lean, a segment is represented as A\u00b7B. When we refer to the point A, it is represented as (A\u00b7B).A. When we refer to the point B, it is represented \nas (A\u00b7B).B. With that being said, you can try to solve this level by your own. You may want to use the first axiom of order once (`different_of_between`).\n\nIn case you get stuck, click right below for a hint.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nWhenever you see the hypothesis `hx: B \u2208 A\u2b1dA`, the `cases` tactic will make progress. Whenever you see the goal `\u22a2 A \u2208 A\u2b1dA`, the `left` and `right` tactics\nwill make progress. Still bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B C P Q R : \u03a9} --hide\nvariables {\u2113 r s t : Line \u03a9} --hide\n\n/- Lemma :\nThe only point on the segment A\u2b1dA is A itself.\n-/\nlemma one_point_segment (A B : \u03a9) : B \u2208 A\u2b1dA \u2194 B = A :=\nbegin\n  split,\n  {\n    intro hx,\n    cases hx,\n    {\n      exact hx,\n    },\n    {\n      cases hx,\n      {\n        exact hx,\n      },\n      {\n        exfalso,\n        apply (different_of_between hx).2.1,\n        refl,\n      }\n    }\n  },\n  {\n    intro h,\n    rw h,\n    left,\n    refl,\n  },\n\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/betweenness_world/level05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7458776808102585}}
{"text": "/-\n  Same as covering but the Ui's are elements of the basis and such that Ui \u2229 Uj\n  (not necessarily in the basis) is covered by Uijk's all in the basis.\n-/\n\nimport topology.basic\nimport to_mathlib.opens\nimport sheaves.covering.covering\n\nuniverses u v\n\nopen topological_space lattice\n\nsection covering_on_basis\n\nparameters {\u03b1 : Type u} [topological_space \u03b1]\nparameters {B : set (opens \u03b1)} [HB : opens.is_basis B]\n\n-- Open cover for basis.\n\nstructure covering_basis (U : opens \u03b1) extends covering U :=\n{Iij       : \u03b3 \u2192 \u03b3 \u2192 Type v }\n(Uijks     : \u03a0 (i j), Iij i j \u2192 opens \u03b1)\n(BUis      : \u2200 i, Uis i \u2208 B)\n(BUijks    : \u2200 i j k, Uijks i j k \u2208 B)\n(Hintercov : \u2200 i j, \u22c3 (Uijks i j) = Uis i \u2229 Uis j)\n\n-- If \u22c3 Uijk = Ui \u2229 Uj then for all k, Uijk \u2286 Ui \u2229 Uj.\n\nlemma subset_covering_basis {U : opens \u03b1} {OC : covering_basis U}\n: \u2200 i j k, OC.Uijks i j k \u2286 OC.Uis i \u2229 OC.Uis j := \n\u03bb i j k x, (OC.Hintercov i j) \u25b8 opens_supr_mem (OC.Uijks i j) k x\n\n-- If \u22c3 Uijk = Ui \u2229 Uj then for all k, Uijk \u2286 Ui.\n\nlemma subset_covering_basis_inter_left {U : opens \u03b1} {OC : covering_basis U}\n: \u2200 i j k, OC.Uijks i j k \u2286 OC.Uis i :=\n\u03bb i j k, set.subset.trans (subset_covering_basis i j k) (set.inter_subset_left _ _) \n\n-- If \u22c3 Uijk = Ui \u2229 Uj then for all k, Uijk \u2286 Uj.\n\nlemma subset_covering_basis_inter_right {U : opens \u03b1} {OC : covering_basis U}\n: \u2200 i j k, OC.Uijks i j k \u2286 OC.Uis j :=\n\u03bb i j k, set.subset.trans (subset_covering_basis i j k) (set.inter_subset_right _ _) \n\nend covering_on_basis\n", "meta": {"author": "ramonfmir", "repo": "lean-scheme", "sha": "6d3ec18fecfd174b79d0ce5c85a783f326dd50f6", "save_path": "github-repos/lean/ramonfmir-lean-scheme", "path": "github-repos/lean/ramonfmir-lean-scheme/lean-scheme-6d3ec18fecfd174b79d0ce5c85a783f326dd50f6/src/sheaves/covering/covering_on_basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.8080672043084051, "lm_q1q2_score": 0.745877675255525}}
{"text": "\n-- let's define the real numbers to be a number system which satisfies\n-- the basic properties of the real numbers which we will need.\n\nnoncomputable theory \nconstant real : Type\n@[instance] constant real_field : linear_ordered_field real\n\n-- This piece of magic means that \"real\" now behaves a lot like\n-- the real numbers. In particular we now have a bunch\n-- of theorems:\n\nexample : \u2200 x y : real, x * y = y * x := mul_comm\n\nvariable x : real\nvariable n : nat\n\n-- We do _not_ have powers though. So we need to make them.\n\nopen nat \n\ndefinition natural_power : real \u2192 nat \u2192 real\n| x 0 := 1\n| x (succ n) := (natural_power x n) * x\n\ntheorem T1 : \u2200 x:real, \u2200 m n:nat, natural_power x (m+n) = natural_power x m *natural_power x n :=\n    begin\n        assume x m n,\n        induction n with n H,\n        unfold natural_power,\n        rw [add_zero, mul_one],\n        unfold natural_power,\n        rw [H, mul_assoc],\n    end\n\ntheorem T2 : \u2200 x: real, \u2200 m n : nat, natural_power (natural_power x m) n = natural_power x (m*n) :=\n    begin\n        assume x m n,\n        induction n with n H,\n        unfold natural_power,\n        rw [mul_zero, eq_comm],\n        unfold natural_power,\n        rw [succ_eq_add_one,mul_add,mul_one,add_one],\n        unfold natural_power,\n        rw [T1,H]\n    end\n\ntheorem T3 : \u2200 x y: real, \u2200 n : nat, natural_power x n * natural_power y n = natural_power (x*y) n :=\n    begin\n        assume x y n,\n        induction n with n H,\n        unfold natural_power,\n        exact mul_one 1,\n        rw[succ_eq_add_one],\n        rw[T1],\n        unfold natural_power,\n        rw[one_mul],\n        cc,\n    end\n\n\nconstant nth_root (x : real) (n : nat) : (x>0) \u2192 (n>0) \u2192 real\n\naxiom is_nth_root (x : real) (n : nat) (Hx : x>0) (Hn : n>0) : natural_power (nth_root x n Hx Hn) n = x \n\ndefinition rational_power_v0 (x : real) (n : nat) (d : nat) (Hx : x > 0) (Hd : d > 0) : real :=\nnatural_power (nth_root x d Hx Hd) n \n\n\ntheorem T4 (x:real) (n:\u2115) (Hx:x\u22650): 0 \u2264 natural_power x n:=\n    begin\n        induction n with n H,\n        unfold natural_power,\n        exact zero_le_one,\n        unfold natural_power,\n        exact calc 0 = 0*x:by rw[zero_mul]\n            ... \u2264 natural_power x n * x:mul_le_mul_of_nonneg_right H Hx,\n    end\n\n\ntheorem T5 (x y:real) (n:\u2115) (Hx:x\u22650) (Hy:y\u22650) (Hn:n\u22651): natural_power x n = natural_power y n \u2192 x = y :=\n    begin\n        have H1:  \u2200 (s t:real), \u2200 (Hs : s \u2265 0), \u2200 (Ht : t \u2265 0) , s < t \u2192 natural_power s n < natural_power t n,\n            assume s t Hs Ht Hslt,\n            cases n with k,\n            exfalso,\n            have Htemp : 0 < 0,\n            exact calc 0 < 1 : zero_lt_one\n                ... \u2264 0 : Hn,\n            have Htemp2 : \u00ac (0=0),\n            exact ne_of_lt Htemp,\n            apply Htemp2,\n            trivial,\n            clear Hn,\n\n            induction k with k Hk,\n                unfold natural_power,\n                rwa[one_mul,one_mul],\n                unfold natural_power,\n                exact calc natural_power s k * s * s = natural_power s (succ k) * s:rfl\n                    ... \u2264 natural_power s (succ k) * t:mul_le_mul_of_nonneg_left (le_of_lt Hslt) (T4 s (succ k) Hs) --  (sorry)\n                    ... < natural_power t (succ k) * t: mul_lt_mul_of_pos_right Hk (calc 0\u2264s : Hs ... <t : Hslt)\n                    ... = natural_power t k * t * t : rfl,\n\n        intro Hnp,\n        cases  lt_or_ge x y with H2 H3,\n        exfalso,\n        exact ne_of_lt (H1 x y Hx Hy H2) Hnp, \n\n        cases lt_or_eq_of_le H3 with H4 H5,\n        tactic.swap,\n        exact eq.symm H5,\n        exfalso,\n        exact ne_of_lt (H1 y x Hy Hx H4) (eq.symm Hnp),\n    end\n\naxiom positive_nth_root (x:real) (n:\u2115) (Hx:x>0) (Hn:n>0):0<nth_root x n Hx Hn\n\ntheorem T6 (x:real) (m n k l:\u2115) (Hx:x>0) (Hm:m\u22650) (Hn:n>0) (Hk:k\u22650) (Hl:l>0) (Hmnkl:m*l=k*n): rational_power_v0 x m n Hx Hn=rational_power_v0 x k l Hx Hl:=\nbegin\n    have H2:natural_power (rational_power_v0 x m n Hx Hn) (n*l)=natural_power (rational_power_v0 x k l Hx Hl) (n*l):=\n        begin\n            have H2_1:natural_power (rational_power_v0 x k l Hx Hl) (n*l) = natural_power (rational_power_v0 x k l Hx Hl) (l*n):=\n                begin rw[mul_comm] end,\n            rw[H2_1], clear H2_1,\n            rw[\u2190T2,\u2190T2],\n            unfold rational_power_v0,\n            rw[T2 (nth_root x l Hx Hl), mul_comm,\u2190T2, is_nth_root],\n            rw[T2 (nth_root x n Hx Hn), mul_comm,\u2190T2, is_nth_root],\n            rw[T2,T2,Hmnkl]\n        end,\n    have Hxmn:rational_power_v0 x m n Hx Hn\u22650:=\n        begin\n            unfold rational_power_v0,\n            have Hxmn_1:0\u2264nth_root x n Hx Hn:= le_of_lt (positive_nth_root x n Hx Hn),\n            exact T4 (nth_root x n Hx Hn) m Hxmn_1,\n        end,\n    have Hxkl:rational_power_v0 x k l Hx Hl\u22650:=\n        begin\n            unfold rational_power_v0,\n            have Hxkl_1:0\u2264nth_root x l Hx Hl:= le_of_lt (positive_nth_root x l Hx Hl),\n            exact T4 (nth_root x l Hx Hl) k Hxkl_1,\n        end,\n    have Hnl:n*l\u22651:=\n        begin\n            have Hnl_1:0<n*l:=mul_pos Hn Hl,\n            have Hnl_2:1<1+(n*l):=add_lt_add_left Hnl_1 1,\n            have Hnl_3:1<succ(n*l):=\n                begin\n                    rw[succ_eq_add_one,add_comm],\n                    exact Hnl_2,\n                end,\n            have Hnl_4:1\u2264(n*l):=le_of_lt_succ Hnl_3,\n            exact(Hnl_4),\n        end,\n\n    exact T5 (rational_power_v0 x m n Hx Hn) (rational_power_v0 x k l Hx Hl) (n*l) Hxmn Hxkl Hnl H2,\n\nend\n\ntheorem T7 (x:real) (m n k l:\u2115) (Hx:x>0) (Hm:m\u22650) (Hn:n>0) (Hk:k\u22650) (Hl:l>0) (Hmnkl:m*l=k*n): T6 x m n k l Hx Hm Hn Hk Hl Hmnkl = T6 x m n k l Hx Hm Hn Hk Hl Hmnkl :=\nbegin\nunfold T6,\nend", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/rationalpowers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966641739774, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7458530413941776}}
{"text": "import data.nat.basic\nimport tactic.library_search\n\n-- Turn off trace messages so they don't pollute the test build:\nset_option trace.silence_library_search true\n-- For debugging purposes, we can display the list of lemmas:\n-- set_option trace.library_search true\n\n-- Check that `library_search` fails if there are no goals.\nexample : true :=\nbegin\n  trivial,\n  success_if_fail { library_search },\nend\n\nexample (a b : \u2115) : a + b = b + a :=\nby library_search -- says: `exact add_comm a b`\n\nexample {a b : \u2115} : a \u2264 a + b :=\nby library_search -- says: `exact le_add_right a b`\n\nexample (n m k : \u2115) : n * (m - k) = n * m - n * k :=\nby library_search -- says: `exact nat.mul_sub_left_distrib n m k`\n\nexample {n m : \u2115} (h : m < n) : m \u2264 n - 1 :=\nby library_search -- says: `exact nat.le_pred_of_lt h`\n\nexample {\u03b1 : Type} (x y : \u03b1) : x = y \u2194 y = x :=\nby library_search -- says: `exact eq_comm`\n\nexample (a b : \u2115) (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=\nby library_search -- says: `exact add_pos ha hb`\n\nexample (a b : \u2115) : 0 < a \u2192 0 < b \u2192 0 < a + b :=\nby library_search -- says: `exact add_pos`\n\nexample (a b : \u2115) (h : a \u2223 b) (w : b > 0) : a \u2264 b :=\nby library_search -- says: `exact nat.le_of_dvd w h`\n\n\n-- We even find `iff` results:\n\nexample {b : \u2115} (w : b > 0) : b \u2265 1 :=\nby library_search -- says: `exact nat.succ_le_iff.mpr w`\n\nexample : \u2200 P : Prop, \u00ac(P \u2194 \u00acP) :=\nby library_search -- says: `\u03bb (a : Prop), (iff_not_self a).mp`\n\nexample {a b c : \u2115} (h\u2081 : a \u2223 c) (h\u2082 : a \u2223 b + c) : a \u2223 b :=\nby library_search -- says `exact (nat.dvd_add_left h\u2081).mp h\u2082`\n\nexample {a b c : \u2115} (h\u2081 : a \u2223 b) (h\u2082 : a \u2223 b + c) : a \u2223 c :=\nby library_search -- says `exact (nat.dvd_add_left h\u2081).mp h\u2082`\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/test/library_search/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7458499313446098}}
{"text": "import tutorial_world.level06_intro --hide\nopen IncidencePlane --hide\n\n/- Tactic : split\n\n## Summary:\n\nIf the goal is `P \u2227 Q` or `P \u2194 Q` then `split` will break it into two goals.\n\n## Details\n\nIf `P Q : Prop` and the goal is `\u22a2 P \u2227 Q`, then `split` will change it into\ntwo goals, namely `\u22a2 P` and `\u22a2 Q`. \n\nIf `P Q : Prop` and the goal is `\u22a2 P \u2194 Q`, then `split` will change it into\ntwo goals, namely `\u22a2 P \u2192 Q` and `\u22a2 Q \u2192 P`.  \n\n## Example:\n\nIf your local context (the top right window) looks like this\n```\nX : Type\nA B : set X\nx : X\n\u22a2 x \u2208 A \u2194 x \u2208 B\n```\n\nthen after\n\n`split,`\n\nit will look like this:\n\n```\n2 goals\nX : Type\nA B : set X\nx : X\n\u22a2 x \u2208 A \u2192 x \u2208 B\n\n\nX : Type\nA B : set X\nx : X\n\u22a2 x \u2208 B \u2192 x \u2208 A\n```\n-/\n\n/-\n# Tutorial World\n\n## Level 7: the `split` tactic.\n\nIn this level we will learn the `split` tactic. It breaks a goal of the type `P \u2227 Q` into two goals (proving `P`, and then proving `Q`),\nand also breaks goals of the form `P \u2194 Q` into proving each of the implications separately. That is to say, it asks us to prove `P \u2192 Q` first, and \nthen `Q \u2192 P`. In mathematics and logic, the **\u2227** symbol is read as **and**. For example, `IT RAINS \u2227 I AM IN THE STREET \u2192 I OPEN THE UMBRELLA`. \nAnalogously, the **`\u2194`** symbol refers to a **double implication**, or an **if and only if** statement. In written mathematics, you could also\nfind the **`\u2194`** symbol written as **iff**. \n\nBecause you are supposed to be making process, try to solve this level by your own. You can solve it in three lines of code. \nAfter deleting `sorry` and typing `split,`, you will see that this level is remarkably similar to Level 5. Feel free to go back to it! \n[**Remember:** Whenever there are two goals to solve in Lean, you will always have to solve the above goal first, and then the one below.]\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nDelete `sorry` and type `split,` (don't forget the comma!). Directly after, go to the \"Theorem statements\" box (located on the \ntop left of the game screen) and try to find a lemma which could be suitable to solve this level. Still bewildered? Click on \"View source\"\n(located on the top right corner of the game screen) to see the solution. \n\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\n\n\n/- Lemma : no-side-bar\nIf two lines contain two distinct points, then they are the same line.\n-/\nlemma line_through_contains_points (P Q : \u03a9) : P \u2208 (line_through P Q) \u2227 Q \u2208 (line_through P Q)\n:=\nbegin\n  split,\n  exact line_through_left P Q,\n  exact line_through_right P Q,\nend\n\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/tutorial_world/level07_split.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7458499269372446}}
{"text": "/-\nCopyright (c) 2022 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n\n! This file was ported from Lean 3 source module algebra.group.commutator\n! leanprover-community/mathlib commit c4658a649d216f57e99621708b09dcb3dcccbd23\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Defs\nimport Mathlib.Data.Bracket\n\n/-!\n# The bracket on a group given by commutator.\n-/\n\n/-- The commutator of two elements `g\u2081` and `g\u2082`. -/\ninstance commutatorElement {G : Type _} [Group G] : Bracket G G :=\n  \u27e8fun g\u2081 g\u2082 \u21a6 g\u2081 * g\u2082 * g\u2081\u207b\u00b9 * g\u2082\u207b\u00b9\u27e9\n#align commutator_element commutatorElement\n\ntheorem commutatorElement_def {G : Type _} [Group G] (g\u2081 g\u2082 : G) :\n  \u2045g\u2081, g\u2082\u2046 = g\u2081 * g\u2082 * g\u2081\u207b\u00b9 * g\u2082\u207b\u00b9 :=\n  rfl\n#align commutator_element_def commutatorElement_def\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Group/Commutator.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181417, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.745849922192882}}
{"text": "import tactic.basic data.num.lemmas data.list.basic \n\nnamespace ring_tac\nopen tactic\n\n-- We start by modelling polynomials as lists of integers. Note that znum\n-- is basically the same as int, but optimised for computations.\n\n-- The list [a0,a1,...,an] represents a0 + a1*x + a2*x^2 + ... +an*x^n\n\ndef poly := list znum\n\n-- We now make basic definitions and prove basic lemmas about addition of polynomials,\n-- multiplication of a polynomial by a scalar, and multiplication of polynomials.\n\ndef poly.add : poly \u2192 poly \u2192 poly\n| [] g := g\n| f [] := f\n| (a :: f') (b :: g') := (a + b) :: poly.add f' g'\n\n@[simp] lemma poly.zero_add (p : poly) : poly.add [] p = p := by induction p;refl\n\ndef poly.smul : znum \u2192 poly \u2192 poly\n| _ [] := []\n| z (a :: f') := (z * a) :: poly.smul z f'\n\ndef poly.mul : poly \u2192 poly \u2192 poly\n| [] _ := []\n| (a :: f') g := poly.add (poly.smul a g) (0 :: (poly.mul f' g))\n\ndef poly.const : znum \u2192 poly := \u03bb z, [z]\n\ndef poly.X : poly := [0,1]\n\n-- One problem with our implementation is that the lists [1,2,3] and [1,2,3,0] are different\n-- list, but represent the same polynomial. So we define an \"is_equal\" predicate.\n\ndef poly.is_eq_aux : list znum -> list znum -> bool\n| [] [] := tt \n| [] (h\u2082 :: t\u2082) := if (h\u2082 = 0) then poly.is_eq_aux [] t\u2082 else ff \n| (h\u2081 :: t\u2081) [] := if (h\u2081 = 0) then poly.is_eq_aux t\u2081 [] else ff\n| (h\u2081 :: t\u2081) (h\u2082 :: t\u2082) := if (h\u2081 = h\u2082) then poly.is_eq_aux t\u2081 t\u2082 else ff\n\ndef poly.is_eq : poly \u2192 poly \u2192 bool := poly.is_eq_aux \n\n-- evaluation of a polynomial at some element of a commutative ring.\ndef poly.eval {\u03b1} [comm_ring \u03b1] (X : \u03b1) : poly \u2192 \u03b1\n| [] := 0\n| (n::l) := n + X * poly.eval l\n\n-- Lemmas saying that evaluation plays well with addition, multiplication, polynomial equality etc\n\n@[simp] lemma poly.eval_zero {\u03b1} [comm_ring \u03b1] (X : \u03b1) : poly.eval X [] = 0 := rfl\n\n@[simp] theorem poly.eval_add {\u03b1} [comm_ring \u03b1] (X : \u03b1) : \u2200 p\u2081 p\u2082 : poly,\n  (p\u2081.add p\u2082).eval X = p\u2081.eval X + p\u2082.eval X :=\nbegin\n  intro p\u2081,\n  induction p\u2081 with h\u2081 t\u2081 H,\n    -- base case\n    intros,simp [poly.eval],\n  -- inductive step\n  intro p\u2082,\n  cases p\u2082 with h\u2082 t\u2082,\n    simp [poly.add],\n  unfold poly.eval poly.add,\n  rw (H t\u2082),\n  simp [mul_add]\nend\n\n@[simp] lemma poly.eval_mul_zero {\u03b1} [comm_ring \u03b1] (f : poly) (X : \u03b1) :\n  poly.eval X (poly.mul f []) = 0 :=\nbegin\n  induction f with h t H,\n    refl,\n  unfold poly.mul poly.smul poly.add poly.mul poly.eval,\n  rw H,simp\nend\n\n@[simp] lemma poly.eval_smul {\u03b1} [comm_ring \u03b1] (X : \u03b1) (z : znum) (f : poly) :\n  poly.eval X (poly.smul z f) = z * poly.eval X f :=\nbegin\n  induction f with h t H, simp [poly.smul,poly.eval,mul_zero],\n  unfold poly.smul poly.eval,\n  rw H,\n  simp [mul_add,znum.cast_mul,mul_assoc,mul_comm]\nend\n\n@[simp] theorem poly.eval_mul {\u03b1} [comm_ring \u03b1] (X : \u03b1) : \u2200 p\u2081 p\u2082 : poly,\n  (p\u2081.mul p\u2082).eval X = p\u2081.eval X * p\u2082.eval X :=\nbegin\n  intro p\u2081,induction p\u2081 with h\u2081 t\u2081 H,\n    simp [poly.mul],\n  intro p\u2082,\n  unfold poly.mul,\n  rw poly.eval_add,\n  unfold poly.eval,\n  rw [H p\u2082,znum.cast_zero,zero_add,add_mul,poly.eval_smul,mul_assoc]\nend\n\n@[simp] theorem poly.eval_const {\u03b1} [comm_ring \u03b1] (X : \u03b1) : \u2200 n : znum,\n  (poly.const n).eval X = n :=\nbegin\n  intro n,\n  unfold poly.const poly.eval,simp\nend\n\n@[simp] theorem poly.eval_X {\u03b1} [comm_ring \u03b1] (X : \u03b1) : poly.X.eval X = X :=\nbegin\n  unfold poly.X poly.eval,simp\nend\n\n-- Different list representing the same polynomials evaluate to the same thing\ntheorem poly.eval_is_eq {\u03b1} [comm_ring \u03b1] (X : \u03b1) {p\u2081 p\u2082 : poly} : \n  poly.is_eq p\u2081 p\u2082 \u2192 p\u2081.eval X = p\u2082.eval X := \nbegin\n  revert p\u2082,\n  induction p\u2081 with h\u2081 t\u2081 H\u2081,\n  { intros p\u2082 H,\n    induction p\u2082 with h\u2081 t\u2081 H\u2082,refl,\n    unfold poly.eval,\n    unfold poly.is_eq poly.is_eq_aux at H,\n    split_ifs at H,swap,cases H,\n    rw [h,\u2190H\u2082 H],\n    simp,\n  },\n  { intros p\u2082 H,\n    induction p\u2082 with h\u2082 t\u2082 H\u2082,\n    { unfold poly.eval,\n      unfold poly.is_eq poly.is_eq_aux at H,\n      split_ifs at H,swap,cases H,\n      rw [h,H\u2081 H],\n      simp\n    },\n    { unfold poly.eval,\n      unfold poly.is_eq poly.is_eq_aux at H,\n      split_ifs at H,swap,cases H,\n      unfold poly.is_eq at H\u2082,\n      rw [h,H\u2081 H]\n    }\n  } \n    \nend \n\n-- That's the end of the poly interface. We now prepare for the reflection.\n\n-- First an abstract version of polynomials (where equality is harder to test, and we won't\n-- need to test it). We'll construct a term of this type from (x+1)*(x+1)*(x+1)\n\n-- fancy attribute because we will be using reflection in meta-land\n@[derive has_reflect]\ninductive ring_expr : Type\n| add : ring_expr \u2192 ring_expr \u2192 ring_expr\n| mul : ring_expr \u2192 ring_expr \u2192 ring_expr\n| const : znum \u2192 ring_expr\n| X : ring_expr\n\n-- turning the abstract poly into a concrete list of coefficients.\ndef to_poly : ring_expr \u2192 poly\n| (ring_expr.add e\u2081 e\u2082) := (to_poly e\u2081).add (to_poly e\u2082)\n| (ring_expr.mul e\u2081 e\u2082) := (to_poly e\u2081).mul (to_poly e\u2082)\n| (ring_expr.const z) := poly.const z\n| ring_expr.X := poly.X\n\n-- evaluating the abstract poly\ndef ring_expr.eval {\u03b1} [comm_ring \u03b1] (X : \u03b1) : ring_expr \u2192 \u03b1\n| (ring_expr.add e\u2081 e\u2082) := e\u2081.eval + e\u2082.eval\n| (ring_expr.mul e\u2081 e\u2082) := e\u2081.eval * e\u2082.eval\n| (ring_expr.const z) := z\n| ring_expr.X := X\n\n-- evaluating the abstract and the concrete polynomial gives the same answer\ntheorem to_poly_eval {\u03b1} [comm_ring \u03b1] (X : \u03b1) (e) : (to_poly e).eval X = e.eval X :=\nby induction e; simp [to_poly, ring_expr.eval, *]\n\n-- The big theorem! If the concrete polys are equal then the abstract ones evaluate\n-- to the same value. \ntheorem main_thm {\u03b1} [comm_ring \u03b1] (X : \u03b1) (e\u2081 e\u2082) {x\u2081 x\u2082}\n  (H : poly.is_eq (to_poly e\u2081) (to_poly e\u2082)) (R1 : e\u2081.eval X = x\u2081) (R2 : e\u2082.eval X = x\u2082) : x\u2081 = x\u2082 :=\nby rw [\u2190 R1, \u2190 R2, \u2190 to_poly_eval,poly.eval_is_eq X H, to_poly_eval]\n\n\n-- Now a \"reflection\" of this abstract type which the VM can play with.\nmeta def reflect_expr (X : expr) : expr \u2192 option ring_expr\n| `(%%e\u2081 + %%e\u2082) := do\n  p\u2081 \u2190 reflect_expr e\u2081,\n  p\u2082 \u2190 reflect_expr e\u2082,\n  return (ring_expr.add p\u2081 p\u2082)\n| `(%%e\u2081 * %%e\u2082) := do\n  p\u2081 \u2190 reflect_expr e\u2081,\n  p\u2082 \u2190 reflect_expr e\u2082,\n  return (ring_expr.mul p\u2081 p\u2082)\n| e := if e = X then return ring_expr.X else\n  do n \u2190 expr.to_int e,\n     return (ring_expr.const (znum.of_int' n))\n\n-- Now here's the tactic! It takes as input the unknown but concrete variable x\n-- and an expression f(x)=g(x),\n-- creates abstract polys f(X) and g(X), proves they're equal using rfl,\n-- and then applies the main theorem to deduce f(x)=g(x).\n\nmeta def ring_tac (X : pexpr) : tactic unit := do\n  X \u2190 to_expr X,\n  `(%%x\u2081 = %%x\u2082) \u2190 target,\n  r\u2081 \u2190 reflect_expr X x\u2081,\n  r\u2082 \u2190 reflect_expr X x\u2082,\n  let e\u2081 : expr := reflect r\u2081,\n  let e\u2082 : expr := reflect r\u2082,\n  `[refine main_thm %%X %%e\u2081 %%e\u2082 rfl _ _],\n  all_goals `[simp only [ring_expr.eval,\n    znum.cast_pos, znum.cast_neg, znum.cast_zero',\n    pos_num.cast_bit0, pos_num.cast_bit1,\n    pos_num.cast_one']]\n\nexample (x : \u2124) : (x + 1) * (x + 1) = x*x+2*x+1 := by do ring_tac ```(x)\n\nexample (x : \u2124) : (x + 1) * (x + 1) * (x + 1) = x*x*x+3*x*x+3*x+1 := by do ring_tac ```(x) \n\nexample (x : \u2124) : (x + 1) + ((-1)*x + 1) = 2 := by do ring_tac ```(x) \n\nend ring_tac\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/blog/baby_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7458499187965065}}
{"text": "/-\nCopyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mathieu Guay-Paquet\n\n! This file was ported from Lean 3 source module order.pfilter\n! leanprover-community/mathlib commit 740acc0e6f9adf4423f92a485d0456fc271482da\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Ideal\n\n/-!\n# Order filters\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections\nrequire more structure, such as a bottom element, a top element, or\na join-semilattice structure.\n\n- `Order.PFilter P`: The type of nonempty, downward directed, upward closed\n               subsets of `P`. This is dual to `Order.Ideal`, so it\n               simply wraps `Order.Ideal P\u1d52\u1d48`.\n- `Order.IsPFilter P`: a predicate for when a `Set P` is a filter.\n\n\nNote the relation between `Order/Filter` and `Order/PFilter`: for any\ntype `\u03b1`, `Filter \u03b1` represents the same mathematical object as\n`PFilter (Set \u03b1)`.\n\n## References\n\n- <https://en.wikipedia.org/wiki/Filter_(mathematics)>\n\n## Tags\n\npfilter, filter, ideal, dual\n\n-/\n\nopen OrderDual\n\nnamespace Order\n\nvariable {P : Type _}\n\n/-- A filter on a preorder `P` is a subset of `P` that is\n  - nonempty\n  - downward directed\n  - upward closed. -/\nstructure PFilter (P) [Preorder P] where\n  dual : Ideal P\u1d52\u1d48\n#align order.pfilter Order.PFilter\n\n/-- A predicate for when a subset of `P` is a filter. -/\ndef IsPFilter [Preorder P] (F : Set P) : Prop :=\n  IsIdeal (OrderDual.ofDual \u207b\u00b9' F)\n#align order.is_pfilter Order.IsPFilter\n\ntheorem IsPFilter.of_def [Preorder P] {F : Set P} (nonempty : F.Nonempty)\n    (directed : DirectedOn (\u00b7 \u2265 \u00b7) F) (mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F) :\n    IsPFilter F :=\n  \u27e8fun _ _ _ _ => mem_of_le \u2039_\u203a \u2039_\u203a, nonempty, directed\u27e9\n#align order.is_pfilter.of_def Order.IsPFilter.of_def\n\n/-- Create an element of type `Order.PFilter` from a set satisfying the predicate\n`Order.IsPFilter`. -/\ndef IsPFilter.toPFilter [Preorder P] {F : Set P} (h : IsPFilter F) : PFilter P :=\n  \u27e8h.toIdeal\u27e9\n#align order.is_pfilter.to_pfilter Order.IsPFilter.toPFilter\n\nnamespace PFilter\n\nsection Preorder\n\nvariable [Preorder P] {x y : P} (F s t : PFilter P)\n\ninstance [Inhabited P] : Inhabited (PFilter P) := \u27e8\u27e8default\u27e9\u27e9\n\n/-- A filter on `P` is a subset of `P`. -/\ninstance : SetLike (PFilter P) P where\n  coe F := toDual \u207b\u00b9' F.dual.carrier\n  coe_injective' := fun \u27e8_\u27e9 \u27e8_\u27e9 h => congr_arg mk <| Ideal.ext h\n\n#align order.pfilter.mem_coe SetLike.mem_coe\u2093\n\ntheorem isPFilter : IsPFilter (F : Set P) := F.dual.isIdeal\n#align order.pfilter.is_pfilter Order.PFilter.isPFilter\n\nprotected theorem nonempty : (F : Set P).Nonempty := F.dual.nonempty\n#align order.pfilter.nonempty Order.PFilter.nonempty\n\ntheorem directed : DirectedOn (\u00b7 \u2265 \u00b7) (F : Set P) := F.dual.directed\n#align order.pfilter.directed Order.PFilter.directed\n\ntheorem mem_of_le {F : PFilter P} : x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F := fun h => F.dual.lower h\n#align order.pfilter.mem_of_le Order.PFilter.mem_of_le\n\n/-- Two filters are equal when their underlying sets are equal. -/\n@[ext]\ntheorem ext (h : (s : Set P) = t) : s = t := SetLike.ext' h\n#align order.pfilter.ext Order.PFilter.ext\n\n@[trans]\ntheorem mem_of_mem_of_le {F G : PFilter P} (hx : x \u2208 F) (hle : F \u2264 G) : x \u2208 G :=\n  hle hx\n#align order.pfilter.mem_of_mem_of_le Order.PFilter.mem_of_mem_of_le\n\n/-- The smallest filter containing a given element. -/\ndef principal (p : P) : PFilter P :=\n  \u27e8Ideal.principal (toDual p)\u27e9\n#align order.pfilter.principal Order.PFilter.principal\n\n@[simp]\ntheorem mem_mk (x : P) (I : Ideal P\u1d52\u1d48) : x \u2208 (\u27e8I\u27e9 : PFilter P) \u2194 toDual x \u2208 I :=\n  Iff.rfl\n#align order.pfilter.mem_def Order.PFilter.mem_mk\n\n@[simp]\ntheorem principal_le_iff {F : PFilter P} : principal x \u2264 F \u2194 x \u2208 F :=\n  Ideal.principal_le_iff (x := toDual x)\n#align order.pfilter.principal_le_iff Order.PFilter.principal_le_iff\n\n@[simp] theorem mem_principal : x \u2208 principal y \u2194 y \u2264 x := Iff.rfl\n#align order.pfilter.mem_principal Order.PFilter.mem_principal\n\ntheorem principal_le_principal_iff {p q : P} : principal q \u2264 principal p \u2194 p \u2264 q := by simp\n#align order.pfilter.principal_le_principal_iff Order.PFilter.principal_le_principal_iff\n\n-- defeq abuse\ntheorem antitone_principal : Antitone (principal : P \u2192 PFilter P) := fun _ _ =>\n  principal_le_principal_iff.2\n#align order.pfilter.antitone_principal Order.PFilter.antitone_principal\n\nend Preorder\n\nsection OrderTop\n\nvariable [Preorder P] [OrderTop P] {F : PFilter P}\n\n/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/\n@[simp] theorem top_mem : \u22a4 \u2208 F := Ideal.bot_mem _\n#align order.pfilter.top_mem Order.PFilter.top_mem\n\n/-- There is a bottom filter when `P` has a top element. -/\ninstance : OrderBot (PFilter P) where\n  bot := \u27e8\u22a5\u27e9\n  bot_le F := (bot_le : \u22a5 \u2264 F.dual)\n\nend OrderTop\n\n/-- There is a top filter when `P` has a bottom element. -/\ninstance {P} [Preorder P] [OrderBot P] : OrderTop (PFilter P) where\n  top := \u27e8\u22a4\u27e9\n  le_top F := (le_top : F.dual \u2264 \u22a4)\n\nsection SemilatticeInf\n\nvariable [SemilatticeInf P] {x y : P} {F : PFilter P}\n\n/-- A specific witness of `pfilter.directed` when `P` has meets. -/\ntheorem inf_mem (hx : x \u2208 F) (hy : y \u2208 F) : x \u2293 y \u2208 F :=\n  Ideal.sup_mem hx hy\n#align order.pfilter.inf_mem Order.PFilter.inf_mem\n\n@[simp]\ntheorem inf_mem_iff : x \u2293 y \u2208 F \u2194 x \u2208 F \u2227 y \u2208 F :=\n  Ideal.sup_mem_iff\n#align order.pfilter.inf_mem_iff Order.PFilter.inf_mem_iff\n\nend SemilatticeInf\n\nsection CompleteSemilatticeInf\n\nvariable [CompleteSemilatticeInf P] {F : PFilter P}\n\ntheorem inf\u209b_gc :\n    GaloisConnection (fun x => toDual (principal x)) fun F => inf\u209b (ofDual F : PFilter P) :=\n  fun x F => by\n  simp\n  rfl\n#align order.pfilter.Inf_gc Order.PFilter.inf\u209b_gc\n\n/-- If a poset `P` admits arbitrary `Inf`s, then `principal` and `Inf` form a Galois coinsertion. -/\ndef infGi :\n    GaloisCoinsertion (fun x => toDual (principal x)) fun F => inf\u209b (ofDual F : PFilter P) :=\n  inf\u209b_gc.toGaloisCoinsertion fun _ => inf\u209b_le <| mem_principal.2 le_rfl\n#align order.pfilter.Inf_gi Order.PFilter.infGi\n\nend CompleteSemilatticeInf\n\nend PFilter\n\nend Order\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/PFilter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7458499165085746}}
{"text": "import algebra.ring\n\nnamespace my_ring\n\nvariables {R : Type*} [ring R]\n\n#check add_zero\n#check mul_add\n#check add_left_cancel\n\n-- BEGIN\n\ntheorem mul_zero (a : R) : a * 0 = 0 :=\nbegin\n  have h : a * 0 + a * 0 = a * 0 + 0,\n    { rw [\u2190mul_add, add_zero, add_zero] },\n  rw add_left_cancel h,\nend\n-- END\n\n#check mul_zero\n\nend my_ring", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/1_rw/ex11_rw_mul_zero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7458145907967125}}
{"text": "import game.world3.level5 -- hide\nimport mynat.mul -- hide\nnamespace mynat -- hide\n\n/-\n# Multiplication World\n\n## Level 6: `succ_mul`\n\nWe now begin our journey to `mul_comm`, the proof that `a * b = b * a`. \nWe'll get there in level 8. Until we're there, it is frustrating\nbut true that we cannot assume commutativity. We have `mul_succ`\nbut we're going to need `succ_mul` (guess what it says -- maybe you\nare getting the hang of Lean's naming conventions). \n\nRemember also that we have tools like\n\n* `add_right_comm a b c : a + b + c = a + c + b` \n\nThese things are the tools we need to slowly build up the results\nwhich we will need to do mathematics \"normally\". \nWe also now have access to Lean's `simp` tactic,\nwhich will solve any goal which just needs a bunch\nof rewrites of `add_assoc` and `add_comm`. Use if\nyou're getting lazy!\n-/\n\n/- Lemma\nFor all natural numbers $a$ and $b$, we have\n$$ \\operatorname{succ}(a) \\times b = ab + b. $$\n-/\nlemma succ_mul (a b : mynat) : succ a * b = a * b + b :=\nbegin [nat_num_game]\n  induction b with d hd,\n  {\n    rw mul_zero,\n    rw mul_zero,\n    rw add_zero,\n    refl,\n  },\n  {\n    rw mul_succ,\n    rw mul_succ,\n    rw hd,\n    rw add_succ,\n    rw add_succ,\n    rw add_right_comm,\n    refl,\n  }\nend\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world3/level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693688269985, "lm_q2_score": 0.7853085884247212, "lm_q1q2_score": 0.7457835115037261}}
{"text": "-- \u2200x A(x) -> (\u2200x B(x) -> \u2200y(A(y) \u2227 B(y)))\n\nvariable U: Type\nvariables A B: U -> Prop \n\nexample : (\u2200 x, A x) -> (\u2200 x, B x) -> (\u2200 x, A x \u2227 B x) :=\nassume hA:  \u2200 x, A x,\nassume hB:  \u2200 x, B x,\nassume y,\nhave pAy: A y, from hA y,\nhave pBy: B y, from hB y,\nshow A y \u2227 B y, from and.intro pAy pBy ", "meta": {"author": "osoulim", "repo": "LEAN", "sha": "5e0dc240e86e392fdab4b2ffdcc3174c0cce7b66", "save_path": "github-repos/lean/osoulim-LEAN", "path": "github-repos/lean/osoulim-LEAN/LEAN-5e0dc240e86e392fdab4b2ffdcc3174c0cce7b66/W3-proof.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693617046215, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.745783503524588}}
{"text": "theorem inv_inv\n  {G: Type}\n  (inv: G \u2192 G)\n  (mul: G \u2192 G \u2192 G)\n  (one: G)\n  (assocMul: forall (a b c: G), mul a (mul b c) = (mul (mul a b) c))\n  (invLeft: forall (a: G), mul (inv a) a = one)\n  (mulOne: forall (a: G), mul a one = a)\n  (oneMul: forall (a: G), mul one a = a)\n  (invRight: forall (a: G), mul a (inv a) = one)\n  (x: G)\n  : (inv (inv x) = x) := by\n  simp [assocMul, invLeft, mulOne, oneMul, invRight]\n\ntheorem inv_mul_cancel_left\n  {G: Type}\n  (inv: G \u2192 G)\n  (mul: G \u2192 G \u2192 G)\n  (one: G)\n  (assocMul: forall (a b c: G), mul a (mul b c) = (mul (mul a b) c))\n  (invLeft: forall (a: G), mul (inv a) a = one)\n  (mulOne: forall (a: G), mul a one = a)\n  (oneMul: forall (a: G), mul one a = a)\n  (invRight: forall (a: G), mul a (inv a) = one)\n  (x y : G)\n  : (mul (inv x) (mul x y)) = y := by\n  simp [assocMul, invLeft, mulOne, oneMul, invRight]\n\n\ntheorem mul_inv_cancel_left\n  {G: Type}\n  (inv: G \u2192 G)\n  (mul: G \u2192 G \u2192 G)\n  (one: G)\n  (assocMul: forall (a b c: G), mul a (mul b c) = (mul (mul a b) c))\n  (invLeft: forall (a: G), mul (inv a) a = one)\n  (mulOne: forall (a: G), mul a one = a)\n  (oneMul: forall (a: G), mul one a = a)\n  (invRight: forall (a: G), mul a (inv a) = one)\n  (x y : G)\n  : (mul x (mul (inv x) y)) = y := by\n  simp [assocMul, invLeft, mulOne, oneMul, invRight]\n\n\ntheorem inv_mul\n  {G: Type}\n  (inv: G \u2192 G)\n  (mul: G \u2192 G \u2192 G)\n  (one: G)\n  (assocMul: forall (a b c: G), mul a (mul b c) = (mul (mul a b) c))\n  (invLeft: forall (a: G), mul (inv a) a = one)\n  (mulOne: forall (a: G), mul a one = a)\n  (oneMul: forall (a: G), mul one a = a)\n  (invRight: forall (a: G), mul a (inv a) = one)\n  (x y : G)\n  : (inv (mul x y)) = (mul (inv y) (inv x)) := by\n  simp [assocMul, invLeft, mulOne, oneMul, invRight]\n\ntheorem one_inv\n  {G: Type}\n  (inv: G \u2192 G)\n  (mul: G \u2192 G \u2192 G)\n  (one: G)\n  (assocMul: forall (a b c: G), mul a (mul b c) = (mul (mul a b) c))\n  (invLeft: forall (a: G), mul (inv a) a = one)\n  (mulOne: forall (a: G), mul a one = a)\n  (oneMul: forall (a: G), mul one a = a)\n  (invRight: forall (a: G), mul a (inv a) = one)\n  (x y : G)\n  : (inv one) = one := by\n  simp [assocMul, invLeft, mulOne, oneMul, invRight]\n", "meta": {"author": "opencompl", "repo": "egg-tactic-code", "sha": "4c37f57478f88d5e11120051012e3d97264c338c", "save_path": "github-repos/lean/opencompl-egg-tactic-code", "path": "github-repos/lean/opencompl-egg-tactic-code/egg-tactic-code-4c37f57478f88d5e11120051012e3d97264c338c/Evaluation/GroupsKnuthBendixSimp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7457448624243727}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon, Ya\u00ebl Dillies\n-/\nimport data.nat.pow\nimport tactic.by_contra\n\n/-!\n# Natural number logarithms\n\nThis file defines two `\u2115`-valued analogs of the logarithm of `n` with base `b`:\n* `log b n`: Lower logarithm, or floor **log**. Greatest `k` such that `b^k \u2264 n`.\n* `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n \u2264 b^k`.\n\nThese are interesting because, for `1 < b`, `nat.log b` and `nat.clog b` are respectively right and\nleft adjoints of `nat.pow b`. See `pow_le_iff_le_log` and `le_pow_iff_clog_le`.\n-/\n\nnamespace nat\n\n/-! ### Floor logarithm -/\n\n/-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : \u2115`\nsuch that `b^k \u2264 n`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot] def log (b : \u2115) : \u2115 \u2192 \u2115\n| n :=\n  if h : b \u2264 n \u2227 1 < b then\n    have n / b < n,\n      from div_lt_self ((zero_lt_one.trans h.2).trans_le h.1) h.2,\n    log (n / b) + 1\n  else 0\n\nprivate lemma log_eq_zero_aux {b n : \u2115} (hnb : n < b \u2228 b \u2264 1) : log b n = 0 :=\nbegin\n  rw [or_iff_not_and_not, not_lt, not_le] at hnb,\n  rw [log, \u2190ite_not, if_pos hnb]\nend\n\nlemma log_of_lt {b n : \u2115} (hb : n < b) : log b n = 0 :=\nlog_eq_zero_aux (or.inl hb)\n\nlemma log_of_left_le_one {b : \u2115} (hb : b \u2264 1) (n) : log b n = 0 :=\nlog_eq_zero_aux (or.inr hb)\n\nlemma log_of_one_lt_of_le {b n : \u2115} (h : 1 < b) (hn : b \u2264 n) : log b n = log b (n / b) + 1 :=\nby { rw log, exact if_pos \u27e8hn, h\u27e9 }\n\nlemma log_eq_zero_iff {b n : \u2115} : log b n = 0 \u2194 n < b \u2228 b \u2264 1 :=\n\u27e8\u03bb h_log, begin\n  by_contra' h,\n  have := log_of_one_lt_of_le h.2 h.1,\n  rw h_log at this,\n  exact succ_ne_zero _ this.symm\nend, log_eq_zero_aux\u27e9\n\nlemma log_eq_one_iff {b n : \u2115} : log b n = 1 \u2194 n < b * b \u2227 1 < b \u2227 b \u2264 n :=\n-- This is best possible: if b = 2, n = 5, then 1 < b and b \u2264 n but n > b * b.\nbegin\n  refine \u27e8\u03bb h_log, _, _\u27e9,\n  { have bound : 1 < b \u2227 b \u2264 n,\n    { contrapose h_log,\n      rw [not_and_distrib, not_lt, not_le, or_comm, \u2190log_eq_zero_iff] at h_log,\n      rw h_log,\n      exact nat.zero_ne_one, },\n    cases bound with one_lt_b b_le_n,\n    refine \u27e8_, one_lt_b, b_le_n\u27e9,\n    rw [log_of_one_lt_of_le one_lt_b b_le_n, succ_inj',\n        log_eq_zero_iff, nat.div_lt_iff_lt_mul (lt_trans zero_lt_one one_lt_b)] at h_log,\n    exact h_log.resolve_right (\u03bb b_small, lt_irrefl _ (lt_of_lt_of_le one_lt_b b_small)), },\n  { rintros \u27e8h, one_lt_b, b_le_n\u27e9,\n    rw [log_of_one_lt_of_le one_lt_b b_le_n, succ_inj',\n        log_eq_zero_iff, nat.div_lt_iff_lt_mul (lt_trans zero_lt_one one_lt_b)],\n    exact or.inl h, },\nend\n\n@[simp] lemma log_zero_left : \u2200 n, log 0 n = 0 :=\nlog_of_left_le_one zero_le_one\n\n@[simp] lemma log_zero_right (b : \u2115) : log b 0 = 0 :=\nby { rw log, cases b; refl }\n\n@[simp] lemma log_one_left : \u2200 n, log 1 n = 0 :=\nlog_of_left_le_one le_rfl\n\n@[simp] lemma log_one_right (b : \u2115) : log b 1 = 0 :=\nif h : b \u2264 1 then\n  log_of_left_le_one h 1\nelse\n  log_of_lt (not_le.mp h)\n\n/-- `pow b` and `log b` (almost) form a Galois connection. -/\nlemma pow_le_iff_le_log {b : \u2115} (hb : 1 < b) {x y : \u2115} (hy : 0 < y) : b ^ x \u2264 y \u2194 x \u2264 log b y :=\nbegin\n  induction y using nat.strong_induction_on with y ih generalizing x,\n  cases x,\n  { exact iff_of_true hy (zero_le _) },\n  rw log, split_ifs,\n  { have b_pos : 0 < b := zero_le_one.trans_lt hb,\n    rw [succ_eq_add_one, add_le_add_iff_right, \u2190ih (y / b) (div_lt_self hy hb)\n      (nat.div_pos h.1 b_pos), le_div_iff_mul_le b_pos, pow_succ'] },\n  { refine iff_of_false (\u03bb hby, h \u27e8le_trans _ hby, hb\u27e9) (not_succ_le_zero _),\n    convert pow_mono hb.le (zero_lt_succ x),\n    exact (pow_one b).symm }\nend\n\nlemma lt_pow_iff_log_lt {b : \u2115} (hb : 1 < b) {x y : \u2115} (hy : 0 < y) : y < b ^ x \u2194 log b y < x :=\nlt_iff_lt_of_le_iff_le (pow_le_iff_le_log hb hy)\n\nlemma log_pow {b : \u2115} (hb : 1 < b) (x : \u2115) : log b (b ^ x) = x :=\neq_of_forall_le_iff $ \u03bb z,\nby { rw \u2190pow_le_iff_le_log hb (pow_pos (zero_lt_one.trans hb) _),\n    exact (pow_right_strict_mono hb).le_iff_le }\n\nlemma log_pos {b n : \u2115} (hb : 1 < b) (hn : b \u2264 n) : 0 < log b n :=\nby { rwa [\u2190succ_le_iff, \u2190pow_le_iff_le_log hb (hb.le.trans hn), pow_one] }\n\nlemma log_mul_base (b n : \u2115) (hb : 1 < b) (hn : 0 < n) : log b (n * b) = log b n + 1 :=\neq_of_forall_le_iff $ \u03bb z,\nbegin\n  cases z,\n  { simp },\n  have : 0 < b := zero_lt_one.trans hb,\n  rw [\u2190pow_le_iff_le_log hb, pow_succ', (strict_mono_mul_right_of_pos this).le_iff_le,\n      pow_le_iff_le_log hb hn, nat.succ_le_succ_iff],\n  simp [hn, this]\nend\n\nlemma lt_pow_succ_log_self {b : \u2115} (hb : 1 < b) (x : \u2115) :\n  x < b ^ (log b x).succ :=\nbegin\n  cases x.eq_zero_or_pos with hx hx,\n  { simp only [hx, log_zero_right, pow_one],\n    exact pos_of_gt hb },\n  rw [\u2190not_le, pow_le_iff_le_log hb hx, not_le],\n  exact lt_succ_self _,\nend\n\nlemma pow_log_le_self {b : \u2115} (hb : 1 < b) {x : \u2115} (hx : 0 < x) : b ^ log b x \u2264 x :=\n(pow_le_iff_le_log hb hx).2 le_rfl\n\n@[mono] lemma log_mono_right {b n m : \u2115} (h : n \u2264 m) : log b n \u2264 log b m :=\nbegin\n  cases le_or_lt b 1 with hb hb,\n  { rw log_of_left_le_one hb, exact zero_le _ },\n  { cases nat.eq_zero_or_pos n with hn hn,\n    { rw [hn, log_zero_right], exact zero_le _ },\n    { rw \u2190pow_le_iff_le_log hb (hn.trans_le h),\n      exact (pow_log_le_self hb hn).trans h } }\nend\n\n@[mono] lemma log_anti_left {b c n : \u2115} (hc : 1 < c) (hb : c \u2264 b) : log b n \u2264 log c n :=\nbegin\n  cases n, { rw [log_zero_right, log_zero_right] },\n  rw \u2190pow_le_iff_le_log hc (zero_lt_succ n),\n  calc c ^ log b n.succ \u2264 b ^ log b n.succ : pow_le_pow_of_le_left\n                                              (zero_lt_one.trans hc).le hb _\n                    ... \u2264 n.succ           : pow_log_le_self (hc.trans_le hb)\n                                              (zero_lt_succ n)\nend\n\nlemma log_monotone {b : \u2115} : monotone (log b) :=\n\u03bb x y, log_mono_right\n\nlemma log_antitone_left {n : \u2115} : antitone_on (\u03bb b, log b n) (set.Ioi 1) :=\n\u03bb _ hc _ _ hb, log_anti_left (set.mem_Iio.1 hc) hb\n\n@[simp] lemma log_div_mul_self (b n : \u2115) : log b (n / b * b) = log b n :=\neq_of_forall_le_iff (\u03bb z, \u27e8\u03bb h, h.trans (log_monotone (div_mul_le_self _ _)), \u03bb h, begin\n  rcases b with _|_|b,\n  { rwa log_zero_left at * },\n  { rwa log_one_left at * },\n  rcases n.zero_le.eq_or_lt with rfl|hn,\n  { rwa [nat.zero_div, zero_mul] },\n  cases le_or_lt b.succ.succ n with hb hb,\n  { cases z,\n    { apply zero_le },\n    rw [\u2190pow_le_iff_le_log, pow_succ'] at h \u22a2,\n    { rwa [(strict_mono_mul_right_of_pos nat.succ_pos').le_iff_le,\n            nat.le_div_iff_mul_le nat.succ_pos'] },\n    all_goals { simp [hn, nat.div_pos hb nat.succ_pos'] } },\n  { simpa [div_eq_of_lt, hb, log_of_lt] using h }\nend\u27e9)\n\n@[simp] lemma log_div_base (b n : \u2115) : log b (n / b) = log b n - 1 :=\nbegin\n  cases lt_or_le n b with h h,\n  { rw [div_eq_of_lt h, log_of_lt h, log_zero_right] },\n  rcases n.zero_le.eq_or_lt with rfl|hn,\n  { rw [nat.zero_div, log_zero_right] },\n  rcases b with _|_|b,\n  { rw [log_zero_left, log_zero_left] },\n  { rw [log_one_left, log_one_left] },\n  rw [\u2190succ_inj', \u2190succ_inj'],\n  simp_rw succ_eq_add_one,\n  rw [nat.sub_add_cancel, \u2190log_mul_base];\n  { simp [succ_le_iff, log_pos, h, nat.div_pos] },\nend\n\nprivate lemma add_pred_div_lt {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) : (n + b - 1) / b < n :=\nbegin\n  rw [div_lt_iff_lt_mul (zero_lt_one.trans hb), \u2190succ_le_iff, \u2190pred_eq_sub_one,\n    succ_pred_eq_of_pos (add_pos (zero_lt_one.trans hn) (zero_lt_one.trans hb))],\n  exact add_le_mul hn hb,\nend\n\n/-! ### Ceil logarithm -/\n\n/-- `clog b n`, is the upper logarithm of natural number `n` in base `b`. It returns the smallest\n`k : \u2115` such that `n \u2264 b^k`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot] def clog (b : \u2115) : \u2115 \u2192 \u2115\n| n :=\n  if h : 1 < b \u2227 1 < n then\n    have (n + b - 1)/b < n := add_pred_div_lt h.1 h.2,\n    clog ((n + b - 1)/b) + 1\n  else 0\n\nlemma clog_of_left_le_one {b : \u2115} (hb : b \u2264 1) (n : \u2115) : clog b n = 0 :=\nby rw [clog, if_neg (\u03bb h : 1 < b \u2227 1 < n, h.1.not_le hb)]\n\nlemma clog_of_right_le_one {n : \u2115} (hn : n \u2264 1) (b : \u2115) : clog b n = 0 :=\nby rw [clog, if_neg (\u03bb h : 1 < b \u2227 1 < n, h.2.not_le hn)]\n\n@[simp] lemma clog_zero_left (n : \u2115) : clog 0 n = 0 :=\nclog_of_left_le_one zero_le_one _\n\n@[simp] lemma clog_zero_right (b : \u2115) : clog b 0 = 0 :=\nclog_of_right_le_one zero_le_one _\n\n@[simp] lemma clog_one_left (n : \u2115) : clog 1 n = 0 :=\nclog_of_left_le_one le_rfl _\n\n@[simp] lemma clog_one_right (b : \u2115) : clog b 1 = 0 :=\nclog_of_right_le_one le_rfl _\n\nlemma clog_of_two_le {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) :\n  clog b n = clog b ((n + b - 1)/b) + 1 :=\nby rw [clog, if_pos (\u27e8hb, hn\u27e9 : 1 < b \u2227 1 < n)]\n\nlemma clog_pos {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) : 0 < clog b n :=\nby { rw clog_of_two_le hb hn, exact zero_lt_succ _ }\n\nlemma clog_eq_one {b n : \u2115} (hn : 2 \u2264 n) (h : n \u2264 b) : clog b n = 1 :=\nbegin\n  rw [clog_of_two_le (hn.trans h) hn, clog_of_right_le_one],\n  have n_pos : 0 < n := zero_lt_two.trans_le hn,\n  rw [\u2190lt_succ_iff, nat.div_lt_iff_lt_mul (n_pos.trans_le h), \u2190succ_le_iff,\n    \u2190pred_eq_sub_one, succ_pred_eq_of_pos (add_pos n_pos (n_pos.trans_le h)), succ_mul, one_mul],\n  exact add_le_add_right h _,\nend\n\n/--`clog b` and `pow b` form a Galois connection. -/\nlemma le_pow_iff_clog_le {b : \u2115} (hb : 1 < b) {x y : \u2115} : x \u2264 b ^ y \u2194 clog b x \u2264 y :=\nbegin\n  induction x using nat.strong_induction_on with x ih generalizing y,\n  cases y,\n  { rw [pow_zero],\n    refine \u27e8\u03bb h, (clog_of_right_le_one h b).le, _\u27e9,\n    simp_rw \u2190not_lt,\n    contrapose!,\n    exact clog_pos hb },\n  have b_pos : 0 < b := zero_lt_two.trans_le hb,\n  rw clog, split_ifs,\n  { rw [succ_eq_add_one, add_le_add_iff_right, \u2190ih ((x + b - 1)/b) (add_pred_div_lt hb h.2),\n      nat.div_le_iff_le_mul_add_pred b_pos,\n      \u2190 pow_succ, add_tsub_assoc_of_le (nat.succ_le_of_lt b_pos), add_le_add_iff_right] },\n  { exact iff_of_true ((not_lt.1 (not_and.1 h hb)).trans $ succ_le_of_lt $ pow_pos b_pos _)\n    (zero_le _) }\nend\n\nlemma pow_lt_iff_lt_clog {b : \u2115} (hb : 1 < b) {x y : \u2115} : b ^ y < x \u2194 y < clog b x :=\nlt_iff_lt_of_le_iff_le (le_pow_iff_clog_le hb)\n\nlemma clog_pow (b x : \u2115) (hb : 1 < b) : clog b (b ^ x) = x :=\neq_of_forall_ge_iff $ \u03bb z,\nby { rw \u2190le_pow_iff_clog_le hb, exact (pow_right_strict_mono hb).le_iff_le }\n\nlemma pow_pred_clog_lt_self {b : \u2115} (hb : 1 < b) {x : \u2115} (hx : 1 < x) :\n  b ^ (clog b x).pred < x :=\nbegin\n  rw [\u2190not_le, le_pow_iff_clog_le hb, not_le],\n  exact pred_lt (clog_pos hb hx).ne',\nend\n\nlemma le_pow_clog {b : \u2115} (hb : 1 < b) (x : \u2115) : x \u2264 b ^ clog b x :=\n(le_pow_iff_clog_le hb).2 le_rfl\n\n@[mono] lemma clog_mono_right (b : \u2115) {n m : \u2115} (h : n \u2264 m) : clog b n \u2264 clog b m :=\nbegin\n  cases le_or_lt b 1 with hb hb,\n  { rw clog_of_left_le_one hb, exact zero_le _ },\n  { rw \u2190le_pow_iff_clog_le hb,\n    exact h.trans (le_pow_clog hb _) }\nend\n\n@[mono] lemma clog_anti_left {b c n : \u2115} (hc : 1 < c) (hb : c \u2264 b) : clog b n \u2264 clog c n :=\nbegin\n  rw \u2190 le_pow_iff_clog_le (lt_of_lt_of_le hc hb),\n  calc\n    n \u2264 c ^ clog c n : le_pow_clog hc _\n  ... \u2264 b ^ clog c n : pow_le_pow_of_le_left (zero_lt_one.trans hc).le hb _\nend\n\nlemma clog_monotone (b : \u2115) : monotone (clog b) :=\n\u03bb x y, clog_mono_right _\n\nlemma clog_antitone_left {n : \u2115} : antitone_on (\u03bb b : \u2115, clog b n) (set.Ioi 1) :=\n\u03bb _ hc _ _ hb, clog_anti_left (set.mem_Iio.1 hc) hb\n\nlemma log_le_clog (b n : \u2115) : log b n \u2264 clog b n :=\nbegin\n  obtain hb | hb := le_or_lt b 1,\n  { rw log_of_left_le_one hb,\n    exact zero_le _},\n  cases n,\n  { rw log_zero_right,\n    exact zero_le _},\n  exact (pow_right_strict_mono hb).le_iff_le.1 ((pow_log_le_self hb $ succ_pos _).trans $\n    le_pow_clog hb _),\nend\n\nend nat\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/nat/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7457282242577814}}
{"text": "/-\n  Standard opens form basis.\n\n  https://stacks.math.columbia.edu/tag/04PM\n-/\n\nimport topology.basic\nimport to_mathlib.opens\nimport spectrum_of_a_ring.zariski_topology\nimport spectrum_of_a_ring.properties\n\nuniverse u \n\nopen topological_space\n\nlocal attribute [instance] classical.prop_decidable\n\nsection standard_basis\n\nparameters (R : Type u) [comm_ring R]\n\n@[reducible] def D_fs := {U : opens (Spec R) | \u2203 f : R, U = Spec.DO R (f)}\n\nlemma D_fs.mem : \u2200 f, Spec.DO R f \u2208 D_fs := \u03bb f, \u27e8f, rfl\u27e9\n\nlemma D_fs_basis : opens.is_basis D_fs := \nbegin\n  refine topological_space.is_topological_basis_of_open_of_nhds _ _,\n  { intros U HU,\n    rcases HU with \u27e8OU, HOU, HOUval\u27e9,\n    rw \u2190HOUval,\n    exact OU.2, },\n  { intros x U HxU OU,\n    cases OU with E HVE,\n    have HDE : U = -Spec.V E := by simp [HVE],\n    have HDE' := HDE,\n    rw set.ext_iff at HDE,\n    replace HDE := HDE x,\n    rw iff_true_left HxU at HDE,\n    simp [Spec.V, has_subset.subset, set.subset] at HDE,\n    rw not_forall at HDE,\n    cases HDE with f Hf,\n    rw not_imp at Hf,\n    cases Hf with HfE Hfx,\n    use Spec.D' f,\n    have HDfDfs : Spec.D' f \u2208 subtype.val '' D_fs,\n      simp,\n      use [D_fs_open R f, f],\n      dsimp [Spec.DO],\n      refl,\n    use HDfDfs,\n    split,\n    { exact Hfx, },\n    { intros y Hy,\n      rw HDE',\n      intro HyE,\n      simp [Spec.D'] at Hy,\n      apply Hy,\n      exact HyE HfE, } }\nend\n\nlemma Spec.V'.empty : Spec.V'((1 : R)) = \u2205 :=\nbegin\n  simp [Spec.V'],\n  apply set.ext,\n  rintros \u27e8I, PI\u27e9,\n  split,\n  { intros HI,\n    exfalso,\n    replace HI : (1 : R) \u2208 I := HI,\n    apply PI.1,\n    rw ideal.eq_top_iff_one,\n    exact HI, },\n  { intros HI,\n    cases HI, }\nend\n\nlemma D_fs_standard_basis : \nopens.univ \u2208 D_fs \u2227 \u2200 {U V}, U \u2208 D_fs \u2192 V \u2208 D_fs \u2192 U \u2229 V \u2208 D_fs :=\nbegin\n  split,\n  { use 1,\n    apply subtype.eq,\n    simp [Spec.DO, Spec.D'],\n    rw Spec.V'.empty,\n    rw set.compl_empty,\n    refl, },\n  { intros U V HU HV,\n    cases HU with fU HU,\n    cases HV with fV HV,\n    use [fU * fV],\n    apply subtype.eq,\n    rw [HU, HV],\n    simp [Spec.DO],\n    exact (Spec.D'.product_eq_inter _ _).symm, }\nend\n\nend standard_basis\n", "meta": {"author": "ramonfmir", "repo": "lean-scheme", "sha": "6d3ec18fecfd174b79d0ce5c85a783f326dd50f6", "save_path": "github-repos/lean/ramonfmir-lean-scheme", "path": "github-repos/lean/ramonfmir-lean-scheme/lean-scheme-6d3ec18fecfd174b79d0ce5c85a783f326dd50f6/src/spectrum_of_a_ring/standard_basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7457282151389333}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\n\nimport data.polynomial.basic\nimport data.finset.nat_antidiagonal\nimport data.nat.choose.sum\n\n/-!\n# Theory of univariate polynomials\n\nThe theorems include formulas for computing coefficients, such as\n`coeff_add`, `coeff_sum`, `coeff_mul`\n\n-/\n\nnoncomputable theory\n\nopen finsupp finset add_monoid_algebra\nopen_locale big_operators\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b : R} {n m : \u2115}\n\nvariables [semiring R] {p q r : polynomial R}\n\nsection coeff\n\nlemma coeff_one (n : \u2115) : coeff (1 : polynomial R) n = if 0 = n then 1 else 0 :=\ncoeff_monomial\n\n@[simp]\nlemma coeff_add (p q : polynomial R) (n : \u2115) : coeff (p + q) n = coeff p n + coeff q n :=\nby { rcases p, rcases q, simp [coeff, add_to_finsupp] }\n\n@[simp] lemma coeff_smul [monoid S] [distrib_mul_action S R] (r : S) (p : polynomial R) (n : \u2115) :\n  coeff (r \u2022 p) n = r \u2022 coeff p n :=\nby { rcases p, simp [coeff, smul_to_finsupp] }\n\nlemma support_smul [monoid S] [distrib_mul_action S R] (r : S) (p : polynomial R) :\n  support (r \u2022 p) \u2286 support p :=\nbegin\n  assume i hi,\n  simp [mem_support_iff] at hi \u22a2,\n  contrapose! hi,\n  simp [hi]\nend\n\n/-- `polynomial.sum` as a linear map. -/\n@[simps] def lsum {R A M : Type*} [semiring R] [semiring A] [add_comm_monoid M]\n  [module R A] [module R M] (f : \u2115 \u2192 A \u2192\u2097[R] M) :\n  polynomial A \u2192\u2097[R] M :=\n{ to_fun := \u03bb p, p.sum (\u03bb n r, f n r),\n  map_add' := \u03bb p q, sum_add_index p q _ (\u03bb n, (f n).map_zero) (\u03bb n _ _, (f n).map_add _ _),\n  map_smul' := \u03bb c p,\n  begin\n    rw [sum_eq_of_subset _ (\u03bb n r, f n r) (\u03bb n, (f n).map_zero) _ (support_smul c p)],\n    simp only [sum_def, finset.smul_sum, coeff_smul, linear_map.map_smul, ring_hom.id_apply]\n  end }\n\nvariable (R)\n/-- The nth coefficient, as a linear map. -/\ndef lcoeff (n : \u2115) : polynomial R \u2192\u2097[R] R :=\n{ to_fun := \u03bb p, coeff p n,\n  map_add' := \u03bb p q, coeff_add p q n,\n  map_smul' := \u03bb r p, coeff_smul r p n }\n\nvariable {R}\n\n@[simp] lemma lcoeff_apply (n : \u2115) (f : polynomial R) : lcoeff R n f = coeff f n := rfl\n\n@[simp] lemma finset_sum_coeff {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 polynomial R) (n : \u2115) :\n  coeff (\u2211 b in s, f b) n = \u2211 b in s, coeff (f b) n :=\n(lcoeff R n).map_sum\n\nlemma coeff_sum [semiring S] (n : \u2115) (f : \u2115 \u2192 R \u2192 polynomial S) :\n  coeff (p.sum f) n = p.sum (\u03bb a b, coeff (f a b) n) :=\nby { rcases p, simp [polynomial.sum, support, coeff] }\n\n/-- Decomposes the coefficient of the product `p * q` as a sum\nover `nat.antidiagonal`. A version which sums over `range (n + 1)` can be obtained\nby using `finset.nat.sum_antidiagonal_eq_sum_range_succ`. -/\nlemma coeff_mul (p q : polynomial R) (n : \u2115) :\n  coeff (p * q) n = \u2211 x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 :=\nbegin\n  rcases p, rcases q,\n  simp only [coeff, mul_to_finsupp],\n  exact add_monoid_algebra.mul_apply_antidiagonal p q n _ (\u03bb x, nat.mem_antidiagonal)\nend\n\n@[simp] lemma mul_coeff_zero (p q : polynomial R) : coeff (p * q) 0 = coeff p 0 * coeff q 0 :=\nby simp [coeff_mul]\n\nlemma coeff_mul_X_zero (p : polynomial R) : coeff (p * X) 0 = 0 :=\nby simp\n\nlemma coeff_X_mul_zero (p : polynomial R) : coeff (X * p) 0 = 0 :=\nby simp\n\nlemma coeff_C_mul_X (x : R) (k n : \u2115) :\n  coeff (C x * X^k : polynomial R) n = if n = k then x else 0 :=\nby { rw [\u2190 monomial_eq_C_mul_X, coeff_monomial], congr' 1, simp [eq_comm] }\n\n@[simp] lemma coeff_C_mul (p : polynomial R) : coeff (C a * p) n = a * coeff p n :=\nby { rcases p, simp only [C, monomial, monomial_fun, mul_to_finsupp, ring_hom.coe_mk,\n  coeff, add_monoid_algebra.single_zero_mul_apply p a n] }\n\nlemma C_mul' (a : R) (f : polynomial R) : C a * f = a \u2022 f :=\nby { ext, rw [coeff_C_mul, coeff_smul, smul_eq_mul] }\n\n@[simp] lemma coeff_mul_C (p : polynomial R) (n : \u2115) (a : R) :\n  coeff (p * C a) n = coeff p n * a :=\nby { rcases p, simp only [C, monomial, monomial_fun, mul_to_finsupp, ring_hom.coe_mk,\n  coeff, add_monoid_algebra.mul_single_zero_apply p a n] }\n\nlemma coeff_X_pow (k n : \u2115) :\n  coeff (X^k : polynomial R) n = if n = k then 1 else 0 :=\nby simp only [one_mul, ring_hom.map_one, \u2190 coeff_C_mul_X]\n\n@[simp]\nlemma coeff_X_pow_self (n : \u2115) :\n  coeff (X^n : polynomial R) n = 1 :=\nby simp [coeff_X_pow]\n\ntheorem coeff_mul_X_pow (p : polynomial R) (n d : \u2115) :\n  coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=\nbegin\n  rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one],\n  { rintros \u27e8i,j\u27e9 h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,\n    rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },\n  { exact \u03bb h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }\nend\n\nlemma coeff_mul_X_pow' (p : polynomial R) (n d : \u2115) :\n  (p * X ^ n).coeff d = ite (n \u2264 d) (p.coeff (d - n)) 0 :=\nbegin\n  split_ifs,\n  { rw [\u2190 tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] },\n  { refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (\u03bb x hx, _)),\n    rw [coeff_X_pow, if_neg, mul_zero],\n    exact ne_of_lt (lt_of_le_of_lt (nat.le_of_add_le_right\n      (le_of_eq (finset.nat.mem_antidiagonal.mp hx))) (not_le.mp h)) },\nend\n\n@[simp] theorem coeff_mul_X (p : polynomial R) (n : \u2115) :\n  coeff (p * X) (n + 1) = coeff p n :=\nby simpa only [pow_one] using coeff_mul_X_pow p 1 n\n\ntheorem mul_X_pow_eq_zero {p : polynomial R} {n : \u2115}\n  (H : p * X ^ n = 0) : p = 0 :=\next $ \u03bb k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n)\n\nlemma C_mul_X_pow_eq_monomial (c : R) (n : \u2115) : C c * X^n = monomial n c :=\nby { ext1, rw [monomial_eq_smul_X, coeff_smul, coeff_C_mul, smul_eq_mul] }\n\nlemma support_mul_X_pow (c : R) (n : \u2115) (H : c \u2260 0) : (C c * X^n).support = singleton n :=\nby rw [C_mul_X_pow_eq_monomial, support_monomial n c H]\n\nlemma support_C_mul_X_pow' {c : R} {n : \u2115} : (C c * X^n).support \u2286 singleton n :=\nby { rw [C_mul_X_pow_eq_monomial], exact support_monomial' n c }\n\nlemma coeff_X_add_one_pow (R : Type*) [semiring R] (n k : \u2115) :\n  ((X + 1) ^ n).coeff k = (n.choose k : R) :=\nbegin\n  rw [(commute_X (1 : polynomial R)).add_pow, \u2190 lcoeff_apply, linear_map.map_sum],\n  simp only [one_pow, mul_one, lcoeff_apply, \u2190 C_eq_nat_cast, coeff_mul_C, nat.cast_id],\n  rw [finset.sum_eq_single k, coeff_X_pow_self, one_mul],\n  { intros _ _,\n    simp only [coeff_X_pow, boole_mul, ite_eq_right_iff, ne.def] {contextual := tt},\n    rintro h rfl, contradiction },\n  { simp only [coeff_X_pow_self, one_mul, not_lt, finset.mem_range],\n    intro h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero], }\nend\n\nlemma coeff_one_add_X_pow (R : Type*) [semiring R] (n k : \u2115) :\n  ((1 + X) ^ n).coeff k = (n.choose k : R) :=\nby rw [add_comm _ X, coeff_X_add_one_pow]\n\nlemma C_dvd_iff_dvd_coeff (r : R) (\u03c6 : polynomial R) :\n  C r \u2223 \u03c6 \u2194 \u2200 i, r \u2223 \u03c6.coeff i :=\nbegin\n  split,\n  { rintros \u27e8\u03c6, rfl\u27e9 c, rw coeff_C_mul, apply dvd_mul_right },\n  { intro h,\n    choose c hc using h,\n    classical,\n    let c' : \u2115 \u2192 R := \u03bb i, if i \u2208 \u03c6.support then c i else 0,\n    let \u03c8 : polynomial R := \u2211 i in \u03c6.support, monomial i (c' i),\n    use \u03c8,\n    ext i,\n    simp only [\u03c8, c', coeff_C_mul, mem_support_iff, coeff_monomial,\n               finset_sum_coeff, finset.sum_ite_eq'],\n    split_ifs with hi hi,\n    { rw hc },\n    { rw [not_not] at hi, rwa mul_zero } },\nend\n\nlemma coeff_bit0_mul (P Q : polynomial R) (n : \u2115) :\n  coeff (bit0 P * Q) n = 2 * coeff (P * Q) n :=\nby simp [bit0, add_mul]\n\n\n\nlemma smul_eq_C_mul (a : R) : a \u2022 p = C a * p := by simp [ext_iff]\n\nlemma update_eq_add_sub_coeff {R : Type*} [ring R] (p : polynomial R) (n : \u2115) (a : R) :\n  p.update n a = p + (polynomial.C (a - p.coeff n) * polynomial.X ^ n) :=\nbegin\n  ext,\n  rw [coeff_update_apply, coeff_add, coeff_C_mul_X],\n  split_ifs with h;\n  simp [h]\nend\n\nend coeff\n\nsection cast\n\n@[simp] lemma nat_cast_coeff_zero {n : \u2115} {R : Type*} [semiring R] :\n  (n : polynomial R).coeff 0 = n :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih], },\nend\n\n@[simp, norm_cast] theorem nat_cast_inj\n  {m n : \u2115} {R : Type*} [semiring R] [char_zero R] : (\u2191m : polynomial R) = \u2191n \u2194 m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (\u03bb p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\n@[simp] lemma int_cast_coeff_zero {i : \u2124} {R : Type*} [ring R] :\n  (i : polynomial R).coeff 0 = i :=\nby cases i; simp\n\n@[simp, norm_cast] theorem int_cast_inj\n  {m n : \u2124} {R : Type*} [ring R] [char_zero R] : (\u2191m : polynomial R) = \u2191n \u2194 m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (\u03bb p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\nend cast\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/coeff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7457282134313689}}
{"text": "import Mathlib\n\n/-!\n# Monads and randomness\nWe will first recall the `Option` monad and its properties.\n\n* If `\u03b1` is a type `Option \u03b1` is a type.\n* Given `a: \u03b1` we get a term of type `Option \u03b1` by writing `some a`.\n-/\n\nexample : Option \u2115 := pure 42 -- `pure` is terminology from any Monad.\n\n/-!\n* Given `a: Option \u03b1` and `f : \u03b1 \u2192 \u03b2` we get a term of type `Option \u03b2` by writing `a.map f`.\n* Given `a: Option \u03b1` and `f: \u03b1 \u2192 Option \u03b2` we get a term of type `Option \u03b2` by writing `a.bind f`.\n\nFor both these it is more pleasant to use the `do` notation.\n\nEquivalent to the second is that there is a function `Option Option \u03b1 \u2192 Option \u03b1` called `join`.\n-/\n\n#check Option.join\n\n#check Task.spawn \n\n/-!\n## IO Monad\n\nRoughly wraps with the state of the *real world*.\n\nFor example, a random number is wrapped in this.\n-/\n\n#check IO.rand -- IO.rand (lo hi : \u2115) : IO \u2115\n\n/-!\n**Question::** Why not just `\u2115`?\n\n* Otherwise we will violate the principle that the value of a function is determined by its arguments.\n\nWe still do want a natural number. To get this we can `run` the `IO` computation.\n-/\n\n/-- A random natural number -/\ndef rnd (lo hi : \u2115) : \u2115 := \n  ((IO.rand lo hi).run' \n      (() : IO.RealWorld)).get!\n\n/-!\nThis does not lead to a contradiction, though in a way that may be somewhat surprising.\n-/\n\n/-- A random number between 0 and 100-/\ndef a : \u2115 := rnd 0 100\n/-- A random number between 0 and 100-/\ndef b : \u2115 := rnd 0 100\n\n/-!\nWe can run these (every run gives a different result).\n```lean\n#eval a -- 23\n#eval b -- 96\n```\n\nInterestingly, we can also run the pair of them and get a result on the diagonal.\n```lean\n#eval (a, b) -- (87, 87)\n```\n-/\n\n#eval a -- 23\n#eval b -- 96\n\n#eval (a, b) -- (87, 87)\n\n/-- A random pair -/\ndef rndPair (lo hi : \u2115) : IO <| \u2115 \u00d7 \u2115 := do\n  let a \u2190 IO.rand lo hi\n  let b \u2190 IO.rand lo hi\n  pure (a, b)\n\n#eval rndPair 0 100 -- (47, 30)\n/-!\n```lean\n#eval a -- 23\n#eval b -- 96\n\n#eval (a, b) -- (87, 87)\n```\n-/\n\n\n#check IO.RealWorld\n\n#check Unit\n\nexample : a = b := by rfl\n\n-- #reduce a -- times out\n\n-- example : a = 23 := by rfl -- fails\n\n#check Option.orElse\n\n#eval (some 3).orElse \n          (fun _ \u21a6 some 4) -- some 3\n\n#eval (none).orElse \n          (fun _ \u21a6 some 4) -- some 4", "meta": {"author": "siddhartha-gadgil", "repo": "proofs-and-programs-2023", "sha": "9d95a5396c018b9a26ed0d27c52cd446794cd1aa", "save_path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023", "path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023/proofs-and-programs-2023-9d95a5396c018b9a26ed0d27c52cd446794cd1aa/PnP2023/Lec_03_01/RandomIO.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7457282115301292}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.polynomial.algebra_map\nimport data.polynomial.hasse_deriv\nimport data.polynomial.degree.lemmas\n\n/-!\n# Taylor expansions of polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main declarations\n\n* `polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`\n* `polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is\n  `(polynomial.hasse_deriv k f).eval r`\n* `polynomial.eq_zero_of_hasse_deriv_eq_zero`:\n  the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero\n\n-/\n\nnoncomputable theory\n\nnamespace polynomial\nopen_locale polynomial\n\nvariables {R : Type*} [semiring R] (r : R) (f : R[X])\n\n/-- The Taylor expansion of a polynomial `f` at `r`. -/\ndef taylor (r : R) : R[X] \u2192\u2097[R] R[X] :=\n{ to_fun := \u03bb f, f.comp (X + C r),\n  map_add' := \u03bb f g, add_comp,\n  map_smul' := \u03bb c f, by simp only [smul_eq_C_mul, C_mul_comp, ring_hom.id_apply] }\n\nlemma taylor_apply : taylor r f = f.comp (X + C r) := rfl\n\n@[simp] lemma taylor_X : taylor r X = X + C r :=\nby simp only [taylor_apply, X_comp]\n\n@[simp] lemma taylor_C (x : R) : taylor r (C x) = C x :=\nby simp only [taylor_apply, C_comp]\n\n@[simp] lemma taylor_zero' : taylor (0 : R) = linear_map.id :=\nbegin\n  ext,\n  simp only [taylor_apply, add_zero, comp_X, _root_.map_zero, linear_map.id_comp, function.comp_app,\n             linear_map.coe_comp]\nend\n\nlemma taylor_zero (f : R[X]) : taylor 0 f = f :=\nby rw [taylor_zero', linear_map.id_apply]\n\n@[simp] lemma taylor_one : taylor r (1 : R[X]) = C 1 :=\nby rw [\u2190 C_1, taylor_C]\n\n@[simp] lemma taylor_monomial (i : \u2115) (k : R) : taylor r (monomial i k) = C k * (X + C r) ^ i :=\nby simp [taylor_apply]\n\n/-- The `k`th coefficient of `polynomial.taylor r f` is `(polynomial.hasse_deriv k f).eval r`. -/\nlemma taylor_coeff (n : \u2115) : (taylor r f).coeff n = (hasse_deriv n f).eval r :=\nshow (lcoeff R n).comp (taylor r) f = (leval r).comp (hasse_deriv n) f,\nbegin\n  congr' 1, clear f, ext i,\n  simp only [leval_apply, mul_one, one_mul, eval_monomial, linear_map.comp_apply, coeff_C_mul,\n    hasse_deriv_monomial, taylor_apply, monomial_comp, C_1,\n    (commute_X (C r)).add_pow i, linear_map.map_sum],\n  simp only [lcoeff_apply, \u2190 C_eq_nat_cast, mul_assoc, \u2190 C_pow, \u2190 C_mul, coeff_mul_C,\n    (nat.cast_commute _ _).eq, coeff_X_pow, boole_mul, finset.sum_ite_eq, finset.mem_range],\n  split_ifs with h, { refl },\n  push_neg at h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero],\nend\n\n@[simp] lemma taylor_coeff_zero : (taylor r f).coeff 0 = f.eval r :=\nby rw [taylor_coeff, hasse_deriv_zero, linear_map.id_apply]\n\n@[simp] lemma taylor_coeff_one : (taylor r f).coeff 1 = f.derivative.eval r :=\nby rw [taylor_coeff, hasse_deriv_one]\n\n@[simp] lemma nat_degree_taylor (p : R[X]) (r : R) :\n  nat_degree (taylor r p) = nat_degree p :=\nbegin\n  refine map_nat_degree_eq_nat_degree _ _,\n  nontriviality R,\n  intros n c c0,\n  simp [taylor_monomial, nat_degree_C_mul_eq_of_mul_ne_zero, nat_degree_pow_X_add_C, c0]\nend\n\n@[simp] lemma taylor_mul {R} [comm_semiring R] (r : R) (p q : R[X]) :\n  taylor r (p * q) = taylor r p * taylor r q :=\nby simp only [taylor_apply, mul_comp]\n\n/-- `polynomial.taylor` as a `alg_hom` for commutative semirings -/\n@[simps apply] def taylor_alg_hom {R} [comm_semiring R] (r : R) : R[X] \u2192\u2090[R] R[X] :=\nalg_hom.of_linear_map (taylor r) (taylor_one r) (taylor_mul r)\n\nlemma taylor_taylor {R} [comm_semiring R] (f : R[X]) (r s : R) :\n  taylor r (taylor s f) = taylor (r + s) f :=\nby simp only [taylor_apply, comp_assoc, map_add, add_comp, X_comp, C_comp, C_add, add_assoc]\n\nlemma taylor_eval {R} [comm_semiring R] (r : R) (f : R[X]) (s : R) :\n  (taylor r f).eval s = f.eval (s + r) :=\nby simp only [taylor_apply, eval_comp, eval_C, eval_X, eval_add]\n\nlemma taylor_eval_sub {R} [comm_ring R] (r : R) (f : R[X]) (s : R) :\n  (taylor r f).eval (s - r) = f.eval s :=\nby rw [taylor_eval, sub_add_cancel]\n\nlemma taylor_injective {R} [comm_ring R] (r : R) : function.injective (taylor r) :=\nbegin\n  intros f g h,\n  apply_fun taylor (-r) at h,\n  simpa only [taylor_apply, comp_assoc, add_comp, X_comp, C_comp, C_neg,\n    neg_add_cancel_right, comp_X] using h,\nend\n\n\n\n/-- Taylor's formula. -/\nlemma sum_taylor_eq {R} [comm_ring R] (f : R[X]) (r : R) :\n  (taylor r f).sum (\u03bb i a, C a * (X - C r) ^ i) = f :=\nby rw [\u2190comp_eq_sum_left, sub_eq_add_neg, \u2190C_neg, \u2190taylor_apply, taylor_taylor, neg_add_self,\n       taylor_zero]\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/taylor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7457282115301292}}
{"text": "/-\nCopyright (c) 2019 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou, S\u00e9bastien Gou\u00ebzel, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport algebra.direct_sum.module\nimport analysis.complex.basic\nimport analysis.convex.uniform\nimport analysis.normed_space.completion\nimport analysis.normed_space.bounded_linear_maps\nimport linear_algebra.bilinear_form\n\n/-!\n# Inner product space\n\nThis file defines inner product spaces and proves the basic properties.  We do not formally\ndefine Hilbert spaces, but they can be obtained using the set of assumptions\n`[normed_add_comm_group E] [inner_product_space \ud835\udd5c E] [complete_space E]`.\n\nAn inner product space is a vector space endowed with an inner product. It generalizes the notion of\ndot product in `\u211d^n` and provides the means of defining the length of a vector and the angle between\ntwo vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero.\nWe define both the real and complex cases at the same time using the `is_R_or_C` typeclass.\n\nThis file proves general results on inner product spaces. For the specific construction of an inner\nproduct structure on `n \u2192 \ud835\udd5c` for `\ud835\udd5c = \u211d` or `\u2102`, see `euclidean_space` in\n`analysis.inner_product_space.pi_L2`.\n\n## Main results\n\n- We define the class `inner_product_space \ud835\udd5c E` extending `normed_space \ud835\udd5c E` with a number of basic\n  properties, most notably the Cauchy-Schwarz inequality. Here `\ud835\udd5c` is understood to be either `\u211d`\n  or `\u2102`, through the `is_R_or_C` typeclass.\n- We show that the inner product is continuous, `continuous_inner`, and bundle it as the\n  the continuous sesquilinear map `innerSL` (see also `inner\u209b\u2097` for the non-continuous version).\n- We define `orthonormal`, a predicate on a function `v : \u03b9 \u2192 E`, and prove the existence of a\n  maximal orthonormal set, `exists_maximal_orthonormal`.  Bessel's inequality,\n  `orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`,\n  the sum of the norm-squares of the inner products `\u27eav i, x\u27eb` is no more than the norm-square of\n  `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file\n  `analysis.inner_product_space.projection`.\n\n## Notation\n\nWe globally denote the real and complex inner products by `\u27ea\u00b7, \u00b7\u27eb_\u211d` and `\u27ea\u00b7, \u00b7\u27eb_\u2102` respectively.\nWe also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,\nwhich respectively introduce the plain notation `\u27ea\u00b7, \u00b7\u27eb` for the real and complex inner product.\n\n## Implementation notes\n\nWe choose the convention that inner products are conjugate linear in the first argument and linear\nin the second.\n\n## Tags\n\ninner product space, Hilbert space, norm\n\n## References\n*  [Cl\u00e9ment & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]\n*  [Cl\u00e9ment & Martin, *A Coq formal proof of the Lax\u2013Milgram theorem*]\n\nThe Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>\n-/\n\nnoncomputable theory\n\nopen is_R_or_C real filter\nopen_locale big_operators topology complex_conjugate\n\nvariables {\ud835\udd5c E F : Type*} [is_R_or_C \ud835\udd5c]\n\n/-- Syntactic typeclass for types endowed with an inner product -/\nclass has_inner (\ud835\udd5c E : Type*) := (inner : E \u2192 E \u2192 \ud835\udd5c)\n\nexport has_inner (inner)\n\nnotation `\u27ea`x`, `y`\u27eb_\u211d` := @inner \u211d _ _ x y\nnotation `\u27ea`x`, `y`\u27eb_\u2102` := @inner \u2102 _ _ x y\n\nsection notations\n\nlocalized \"notation (name := inner.real)\n  `\u27ea`x`, `y`\u27eb` := @inner \u211d _ _ x y\" in real_inner_product_space\nlocalized \"notation (name := inner.complex)\n  `\u27ea`x`, `y`\u27eb` := @inner \u2102 _ _ x y\" in complex_inner_product_space\n\nend notations\n\n/--\nAn inner product space is a vector space with an additional operation called inner product.\nThe norm could be derived from the inner product, instead we require the existence of a norm and\nthe fact that `\u2016x\u2016^2 = re \u27eax, x\u27eb` to be able to put instances on `\ud835\udd42` or product\nspaces.\n\nTo construct a norm from an inner product, see `inner_product_space.of_core`.\n-/\nclass inner_product_space (\ud835\udd5c : Type*) (E : Type*) [is_R_or_C \ud835\udd5c] [normed_add_comm_group E]\n  extends normed_space \ud835\udd5c E, has_inner \ud835\udd5c E :=\n(norm_sq_eq_inner : \u2200 (x : E), \u2016x\u2016^2 = re (inner x x))\n(conj_symm : \u2200 x y, conj (inner y x) = inner x y)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\n/-!\n### Constructing a normed space structure from an inner product\n\nIn the definition of an inner product space, we require the existence of a norm, which is equal\n(but maybe not defeq) to the square root of the scalar product. This makes it possible to put\nan inner product space structure on spaces with a preexisting norm (for instance `\u211d`), with good\nproperties. However, sometimes, one would like to define the norm starting only from a well-behaved\nscalar product. This is what we implement in this paragraph, starting from a structure\n`inner_product_space.core` stating that we have a nice scalar product.\n\nOur goal here is not to develop a whole theory with all the supporting API, as this will be done\nbelow for `inner_product_space`. Instead, we implement the bare minimum to go as directly as\npossible to the construction of the norm and the proof of the triangular inequality.\n\nWarning: Do not use this `core` structure if the space you are interested in already has a norm\ninstance defined on it, otherwise this will create a second non-defeq norm instance!\n-/\n\n/-- A structure requiring that a scalar product is positive definite and symmetric, from which one\ncan construct an `inner_product_space` instance in `inner_product_space.of_core`. -/\n@[nolint has_nonempty_instance]\nstructure inner_product_space.core\n  (\ud835\udd5c : Type*) (F : Type*)\n  [is_R_or_C \ud835\udd5c] [add_comm_group F] [module \ud835\udd5c F] :=\n(inner     : F \u2192 F \u2192 \ud835\udd5c)\n(conj_symm : \u2200 x y, conj (inner y x) = inner x y)\n(nonneg_re : \u2200 x, 0 \u2264 re (inner x x))\n(definite  : \u2200 x, inner x x = 0 \u2192 x = 0)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\n/- We set `inner_product_space.core` to be a class as we will use it as such in the construction\nof the normed space structure that it produces. However, all the instances we will use will be\nlocal to this proof. -/\nattribute [class] inner_product_space.core\n\nnamespace inner_product_space.of_core\n\nvariables [add_comm_group F] [module \ud835\udd5c F] [c : inner_product_space.core \ud835\udd5c F]\ninclude c\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c F _ x y\nlocal notation `norm_sqK` := @is_R_or_C.norm_sq \ud835\udd5c _\nlocal notation `reK` := @is_R_or_C.re \ud835\udd5c _\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal notation `ext_iff` := @is_R_or_C.ext_iff \ud835\udd5c _\nlocal postfix `\u2020`:90 := star_ring_end _\n\n/-- Inner product defined by the `inner_product_space.core` structure. -/\ndef to_has_inner : has_inner \ud835\udd5c F := { inner := c.inner }\nlocal attribute [instance] to_has_inner\n\n/-- The norm squared function for `inner_product_space.core` structure. -/\ndef norm_sq (x : F) := reK \u27eax, x\u27eb\n\nlocal notation `norm_sqF` := @norm_sq \ud835\udd5c F _ _ _ _\n\nlemma inner_conj_symm (x y : F) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := c.conj_symm x y\n\nlemma inner_self_nonneg {x : F} : 0 \u2264 re \u27eax, x\u27eb := c.nonneg_re _\n\nlemma inner_self_nonneg_im (x : F) : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp [inner_conj_symm]\n\nlemma inner_self_im_zero (x : F) : im \u27eax, x\u27eb = 0 :=\ninner_self_nonneg_im _\n\nlemma inner_add_left (x y z : F) : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\nc.add_left _ _ _\n\nlemma inner_add_right (x y z : F) : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby rw [\u2190inner_conj_symm, inner_add_left, ring_hom.map_add]; simp only [inner_conj_symm]\n\nlemma inner_norm_sq_eq_inner_self (x : F) : (norm_sqF x : \ud835\udd5c) = \u27eax, x\u27eb :=\nbegin\n  rw ext_iff,\n  exact \u27e8by simp only [of_real_re]; refl, by simp only [inner_self_nonneg_im, of_real_im]\u27e9\nend\n\nlemma inner_re_symm (x y : F) : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_symm, conj_re]\n\nlemma inner_im_symm (x y : F) : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_symm, conj_im]\n\nlemma inner_smul_left (x y : F) {r : \ud835\udd5c} : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\nc.smul_left _ _ _\n\nlemma inner_smul_right (x y : F) {r : \ud835\udd5c} : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_symm, inner_smul_left]; simp only [conj_conj, inner_conj_symm, ring_hom.map_mul]\n\nlemma inner_zero_left (x : F) : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190zero_smul \ud835\udd5c (0 : F), inner_smul_left]; simp only [zero_mul, ring_hom.map_zero]\n\nlemma inner_zero_right (x : F) : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_symm, inner_zero_left]; simp only [ring_hom.map_zero]\n\nlemma inner_self_eq_zero {x : F} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\niff.intro (c.definite _) (by { rintro rfl, exact inner_zero_left _ })\n\nlemma inner_self_ne_zero {x : F} : \u27eax, x\u27eb \u2260 0 \u2194 x \u2260 0 :=\ninner_self_eq_zero.not\n\nlemma inner_self_re_to_K (x : F) : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby norm_num [ext_iff, inner_self_nonneg_im]\n\nlemma inner_abs_conj_symm (x y : F) : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_symm, abs_conj]\n\nlemma inner_neg_left (x y : F) : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\nlemma inner_neg_right (x y : F) : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_symm, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_symm]\n\nlemma inner_sub_left (x y z : F) : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left, inner_neg_left] }\n\nlemma inner_sub_right (x y z : F) : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right, inner_neg_right] }\n\nlemma inner_mul_conj_re_abs (x y : F) : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw [\u2190inner_conj_symm, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `inner (x + y) (x + y)` -/\nlemma inner_add_add_self (x y : F) : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/- Expand `inner (x - y) (x - y)` -/\nlemma inner_sub_sub_self (x y : F) : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/--\n**Cauchy\u2013Schwarz inequality**. This proof follows \"Proof 2\" on Wikipedia.\nWe need this for the `core` structure to prove the triangle inequality below when\nshowing the core is a normed group.\n-/\nlemma inner_mul_inner_self_le (x y : F) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { change y \u2260 0 at hy,\n    have hy' : \u27eay, y\u27eb \u2260 0 := inner_self_ne_zero.mpr hy,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm _ _,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm _ _,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := by simp only [inner_self_re_to_K],\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw ext_iff,\n      exact \u27e8by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082,\n                      neg_mul, add_monoid_hom.map_add, mul_re,\n                      conj_im, add_monoid_hom.map_sub, mul_neg, conj_re, neg_neg]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by field_simp [-mul_re, inner_conj_symm, hT, map_div\u2080, h\u2081, h\u2083]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw \u2190mul_div_right_comm\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Norm constructed from a `inner_product_space.core` structure, defined to be the square root\nof the scalar product. -/\ndef to_has_norm : has_norm F :=\n{ norm := \u03bb x, sqrt (re \u27eax, x\u27eb) }\n\nlocal attribute [instance] to_has_norm\n\nlemma norm_eq_sqrt_inner (x : F) : \u2016x\u2016 = sqrt (re \u27eax, x\u27eb) := rfl\n\nlemma inner_self_eq_norm_mul_norm (x : F) : re \u27eax, x\u27eb = \u2016x\u2016 * \u2016x\u2016 :=\nby rw [norm_eq_sqrt_inner, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma sqrt_norm_sq_eq_norm (x : F) : sqrt (norm_sqF x) = \u2016x\u2016 := rfl\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : F) : abs \u27eax, y\u27eb \u2264 \u2016x\u2016 * \u2016y\u2016 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _))\nbegin\n  have H : \u2016x\u2016 * \u2016y\u2016 * (\u2016x\u2016 * \u2016y\u2016) = re \u27eay, y\u27eb * re \u27eax, x\u27eb,\n  { simp only [inner_self_eq_norm_mul_norm], ring, },\n  rw H,\n  conv\n  begin\n    to_lhs, congr, rw [inner_abs_conj_symm],\n  end,\n  exact inner_mul_inner_self_le y x,\nend\n\n/-- Normed group structure constructed from an `inner_product_space.core` structure -/\ndef to_normed_add_comm_group : normed_add_comm_group F :=\nadd_group_norm.to_normed_add_comm_group\n{ to_fun := \u03bb x, sqrt (re \u27eax, x\u27eb),\n  map_zero' := by simp only [sqrt_zero, inner_zero_right, map_zero],\n  neg' := \u03bb x, by simp only [inner_neg_left, neg_neg, inner_neg_right],\n  add_le' := \u03bb x y, begin\n    have h\u2081 : abs \u27eax, y\u27eb \u2264 \u2016x\u2016 * \u2016y\u2016 := abs_inner_le_norm _ _,\n    have h\u2082 : re \u27eax, y\u27eb \u2264 abs \u27eax, y\u27eb := re_le_abs _,\n    have h\u2083 : re \u27eax, y\u27eb \u2264 \u2016x\u2016 * \u2016y\u2016 := by linarith,\n    have h\u2084 : re \u27eay, x\u27eb \u2264 \u2016x\u2016 * \u2016y\u2016 := by rwa [\u2190inner_conj_symm, conj_re],\n    have : \u2016x + y\u2016 * \u2016x + y\u2016 \u2264 (\u2016x\u2016 + \u2016y\u2016) * (\u2016x\u2016 + \u2016y\u2016),\n    { simp only [\u2190inner_self_eq_norm_mul_norm, inner_add_add_self, mul_add, mul_comm, map_add],\n      linarith },\n    exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this,\n  end,\n  eq_zero_of_map_eq_zero' := \u03bb x hx, (inner_self_eq_zero : \u27eax, x\u27eb = 0 \u2194 x = 0).1 $ begin\n    change sqrt (re \u27eax, x\u27eb) = 0 at hx,\n    rw [sqrt_eq_zero inner_self_nonneg] at hx,\n    exact ext (by simp [hx]) (by simp [inner_self_im_zero]),\n  end }\n\nlocal attribute [instance] to_normed_add_comm_group\n\n/-- Normed space structure constructed from a `inner_product_space.core` structure -/\ndef to_normed_space : normed_space \ud835\udd5c F :=\n{ norm_smul_le := assume r x,\n  begin\n    rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, \u2190mul_assoc],\n    rw [conj_mul_eq_norm_sq_left, of_real_mul_re, sqrt_mul, \u2190inner_norm_sq_eq_inner_self,\n        of_real_re],\n    { simp [sqrt_norm_sq_eq_norm, is_R_or_C.sqrt_norm_sq_eq_norm] },\n    { exact norm_sq_nonneg r }\n  end }\n\nend inner_product_space.of_core\n\nsection\nlocal attribute [instance] inner_product_space.of_core.to_normed_add_comm_group\n\n/-- Given a `inner_product_space.core` structure on a space, one can use it to turn\nthe space into an inner product space. The `normed_add_comm_group` structure is expected\nto already be defined with `inner_product_space.of_core.to_normed_add_comm_group`. -/\ndef inner_product_space.of_core [add_comm_group F] [module \ud835\udd5c F]\n  (c : inner_product_space.core \ud835\udd5c F) : inner_product_space \ud835\udd5c F :=\nbegin\n  letI : normed_space \ud835\udd5c F := @inner_product_space.of_core.to_normed_space \ud835\udd5c F _ _ _ c,\n  exact { norm_sq_eq_inner := \u03bb x,\n    begin\n      have h\u2081 : \u2016x\u2016^2 = (sqrt (re (c.inner x x))) ^ 2 := rfl,\n      have h\u2082 : 0 \u2264 re (c.inner x x) := inner_product_space.of_core.inner_self_nonneg,\n      simp [h\u2081, sq_sqrt, h\u2082],\n    end,\n    ..c }\nend\n\nend\n\n/-! ### Properties of inner product spaces -/\n\nvariables [normed_add_comm_group E] [inner_product_space \ud835\udd5c E]\nvariables [normed_add_comm_group F] [inner_product_space \u211d F]\nvariables [dec_E : decidable_eq E]\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\nlocal notation `IK` := @is_R_or_C.I \ud835\udd5c _\nlocal notation `absR` := has_abs.abs\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal postfix `\u2020`:90 := star_ring_end _\n\nexport inner_product_space (norm_sq_eq_inner)\n\nsection basic_properties\n\n@[simp] lemma inner_conj_symm (x y : E) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := inner_product_space.conj_symm _ _\nlemma real_inner_comm (x y : F) : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := @inner_conj_symm \u211d _ _ _ _ x y\n\nlemma inner_eq_zero_symm {x y : E} : \u27eax, y\u27eb = 0 \u2194 \u27eay, x\u27eb = 0 :=\n\u27e8\u03bb h, by simp [\u2190inner_conj_symm, h], \u03bb h, by simp [\u2190inner_conj_symm, h]\u27e9\n\n@[simp] lemma inner_self_nonneg_im (x : E) : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp\n\nlemma inner_self_im_zero (x : E) : im \u27eax, x\u27eb = 0 := inner_self_nonneg_im _\n\nlemma inner_add_left (x y z : E) : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\ninner_product_space.add_left _ _ _\n\nlemma inner_add_right (x y z : E) : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby { rw [\u2190inner_conj_symm, inner_add_left, ring_hom.map_add], simp only [inner_conj_symm] }\n\nlemma inner_re_symm (x y : E) : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_symm, conj_re]\n\nlemma inner_im_symm (x y : E) : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_symm, conj_im]\n\nlemma inner_smul_left (x y : E) (r : \ud835\udd5c) : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\ninner_product_space.smul_left _ _ _\nlemma real_inner_smul_left (x y : F) (r : \u211d) : \u27ear \u2022 x, y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d := inner_smul_left _ _ _\n\nlemma inner_smul_real_left (x y : E) (r : \u211d) : \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_left, conj_of_real, algebra.smul_def], refl }\n\nlemma inner_smul_right (x y : E) (r : \ud835\udd5c) : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_symm, inner_smul_left, ring_hom.map_mul, conj_conj, inner_conj_symm]\nlemma real_inner_smul_right (x y : F) (r : \u211d) : \u27eax, r \u2022 y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d :=\ninner_smul_right _ _ _\n\nlemma inner_smul_real_right (x y : E) (r : \u211d) : \u27eax, (r : \ud835\udd5c) \u2022 y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_right, algebra.smul_def], refl }\n\n/-- The inner product as a sesquilinear form.\n\nNote that in the case `\ud835\udd5c = \u211d` this is a bilinear form. -/\n@[simps]\ndef sesq_form_of_inner : E \u2192\u2097[\ud835\udd5c] E \u2192\u2097\u22c6[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk\u2082'\u209b\u2097 (ring_hom.id \ud835\udd5c) (star_ring_end _)\n  (\u03bb x y, \u27eay, x\u27eb)\n  (\u03bb x y z, inner_add_right _ _ _)\n  (\u03bb r x y, inner_smul_right _ _ _)\n  (\u03bb x y z, inner_add_left _ _ _)\n  (\u03bb r x y, inner_smul_left _ _ _)\n\n/-- The real inner product as a bilinear form. -/\n@[simps]\ndef bilin_form_of_real_inner : bilin_form \u211d F :=\n{ bilin := inner,\n  bilin_add_left := inner_add_left,\n  bilin_smul_left := \u03bb a x y, inner_smul_left _ _ _,\n  bilin_add_right := inner_add_right,\n  bilin_smul_right := \u03bb a x y, inner_smul_right _ _ _ }\n\n/-- An inner product with a sum on the left. -/\nlemma sum_inner {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27ea\u2211 i in s, f i, x\u27eb = \u2211 i in s, \u27eaf i, x\u27eb := (sesq_form_of_inner x).map_sum\n\n/-- An inner product with a sum on the right. -/\nlemma inner_sum {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27eax, \u2211 i in s, f i\u27eb = \u2211 i in s, \u27eax, f i\u27eb := (linear_map.flip sesq_form_of_inner x).map_sum\n\n/-- An inner product with a sum on the left, `finsupp` version. -/\nlemma finsupp.sum_inner {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eal.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i), x\u27eb\n  = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), (conj a) \u2022 \u27eav i, x\u27eb) :=\nby { convert sum_inner l.support (\u03bb a, l a \u2022 v a) x,\n     simp only [inner_smul_left, finsupp.sum, smul_eq_mul] }\n\n/-- An inner product with a sum on the right, `finsupp` version. -/\nlemma finsupp.inner_sum {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eax, l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i)\u27eb = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 \u27eax, v i\u27eb) :=\nby { convert inner_sum l.support (\u03bb a, l a \u2022 v a) x,\n     simp only [inner_smul_right, finsupp.sum, smul_eq_mul] }\n\nlemma dfinsupp.sum_inner {\u03b9 : Type*} [dec : decidable_eq \u03b9] {\u03b1 : \u03b9 \u2192 Type*}\n  [\u03a0 i, add_zero_class (\u03b1 i)] [\u03a0 i (x : \u03b1 i), decidable (x \u2260 0)]\n  (f : \u03a0 i, \u03b1 i \u2192 E) (l : \u03a0\u2080 i, \u03b1 i) (x : E) :\n  \u27eal.sum f, x\u27eb = l.sum (\u03bb i a, \u27eaf i a, x\u27eb) :=\nby simp only [dfinsupp.sum, sum_inner, smul_eq_mul] {contextual := tt}\n\nlemma dfinsupp.inner_sum {\u03b9 : Type*} [dec : decidable_eq \u03b9] {\u03b1 : \u03b9 \u2192 Type*}\n  [\u03a0 i, add_zero_class (\u03b1 i)] [\u03a0 i (x : \u03b1 i), decidable (x \u2260 0)]\n  (f : \u03a0 i, \u03b1 i \u2192 E) (l : \u03a0\u2080 i, \u03b1 i) (x : E) :\n  \u27eax, l.sum f\u27eb = l.sum (\u03bb i a, \u27eax, f i a\u27eb) :=\nby simp only [dfinsupp.sum, inner_sum, smul_eq_mul] {contextual := tt}\n\n@[simp] lemma inner_zero_left (x : E) : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190 zero_smul \ud835\udd5c (0:E), inner_smul_left, ring_hom.map_zero, zero_mul]\n\nlemma inner_re_zero_left (x : E) : re \u27ea0, x\u27eb = 0 :=\nby simp only [inner_zero_left, add_monoid_hom.map_zero]\n\n@[simp] lemma inner_zero_right (x : E) : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_symm, inner_zero_left, ring_hom.map_zero]\n\nlemma inner_re_zero_right (x : E) : re \u27eax, 0\u27eb = 0 :=\nby simp only [inner_zero_right, add_monoid_hom.map_zero]\n\nlemma inner_self_nonneg {x : E} : 0 \u2264 re \u27eax, x\u27eb :=\nby rw [\u2190norm_sq_eq_inner]; exact pow_nonneg (norm_nonneg x) 2\nlemma real_inner_self_nonneg {x : F} : 0 \u2264 \u27eax, x\u27eb_\u211d := @inner_self_nonneg \u211d F _ _ _ x\n\n@[simp] lemma inner_self_eq_zero {x : E} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    have h\u2081 : re \u27eax, x\u27eb = 0 :=\n    by rw is_R_or_C.ext_iff at h; simp only [h.1, zero_re'],\n    rw [\u2190norm_sq_eq_inner x] at h\u2081,\n    rw [\u2190norm_eq_zero],\n    exact pow_eq_zero h\u2081 },\n  { rintro rfl,\n    exact inner_zero_left _ }\nend\n\nlemma inner_self_ne_zero {x : E} : \u27eax, x\u27eb \u2260 0 \u2194 x \u2260 0 :=\ninner_self_eq_zero.not\n\n@[simp] lemma inner_self_nonpos {x : E} : re \u27eax, x\u27eb \u2264 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    rw \u2190@inner_self_eq_zero \ud835\udd5c,\n    have H\u2081 : re \u27eax, x\u27eb \u2265 0, exact inner_self_nonneg,\n    have H\u2082 : re \u27eax, x\u27eb = 0, exact le_antisymm h H\u2081,\n    rw is_R_or_C.ext_iff,\n    exact \u27e8by simp [H\u2082], by simp [inner_self_nonneg_im]\u27e9 },\n  { rintro rfl,\n    simp only [inner_zero_left, add_monoid_hom.map_zero] }\nend\n\nlemma real_inner_self_nonpos {x : F} : \u27eax, x\u27eb_\u211d \u2264 0 \u2194 x = 0 :=\nby { have h := @inner_self_nonpos \u211d F _ _ _ x, simpa using h }\n\n@[simp] lemma inner_self_re_to_K (x : E) : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nis_R_or_C.ext_iff.2 \u27e8by simp only [of_real_re], by simp only [inner_self_nonneg_im, of_real_im]\u27e9\n\nlemma inner_self_eq_norm_sq_to_K (x : E) : \u27eax, x\u27eb = (\u2016x\u2016 ^ 2 : \ud835\udd5c) :=\nbegin\n  suffices : (is_R_or_C.re \u27eax, x\u27eb : \ud835\udd5c) = \u2016x\u2016 ^ 2,\n  { simpa only [inner_self_re_to_K] using this },\n  exact_mod_cast (norm_sq_eq_inner x).symm\nend\n\nlemma inner_self_re_abs (x : E) : re \u27eax, x\u27eb = abs \u27eax, x\u27eb :=\nbegin\n  conv_rhs { rw [\u2190inner_self_re_to_K] },\n  symmetry,\n  exact is_R_or_C.abs_of_nonneg inner_self_nonneg,\nend\n\nlemma inner_self_abs_to_K (x : E) : (absK \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby { rw [\u2190inner_self_re_abs], exact inner_self_re_to_K _ }\n\nlemma real_inner_self_abs (x : F) : absR \u27eax, x\u27eb_\u211d = \u27eax, x\u27eb_\u211d :=\nby { have h := @inner_self_abs_to_K \u211d F _ _ _ x, simpa using h }\n\nlemma inner_abs_conj_symm (x y : E) : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_symm, abs_conj]\n\n@[simp] lemma inner_neg_left (x y : E) : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\n@[simp] lemma inner_neg_right (x y : E) : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_symm, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_symm]\n\nlemma inner_neg_neg (x y : E) : \u27ea-x, -y\u27eb = \u27eax, y\u27eb := by simp\n\n@[simp] lemma inner_self_conj (x : E) : \u27eax, x\u27eb\u2020 = \u27eax, x\u27eb :=\nby rw [is_R_or_C.ext_iff]; exact \u27e8by rw [conj_re], by rw [conj_im, inner_self_im_zero, neg_zero]\u27e9\n\nlemma inner_sub_left (x y z : E) : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left] }\n\nlemma inner_sub_right (x y z : E) : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right] }\n\nlemma inner_mul_conj_re_abs (x y : E) : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw [\u2190inner_conj_symm, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `\u27eax + y, x + y\u27eb` -/\nlemma inner_add_add_self (x y : E) : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/-- Expand `\u27eax + y, x + y\u27eb_\u211d` -/\nlemma real_inner_add_add_self (x y : F) : \u27eax + y, x + y\u27eb_\u211d = \u27eax, x\u27eb_\u211d + 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_symm]; refl,\n  simp only [inner_add_add_self, this, add_left_inj],\n  ring,\nend\n\n/- Expand `\u27eax - y, x - y\u27eb` -/\nlemma inner_sub_sub_self (x y : E) : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/-- Expand `\u27eax - y, x - y\u27eb_\u211d` -/\nlemma real_inner_sub_sub_self (x y : F) : \u27eax - y, x - y\u27eb_\u211d = \u27eax, x\u27eb_\u211d - 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_symm]; refl,\n  simp only [inner_sub_sub_self, this, add_left_inj],\n  ring,\nend\n\nvariable (\ud835\udd5c)\ninclude \ud835\udd5c\n\nlemma ext_inner_left {x y : E} (h : \u2200 v, \u27eav, x\u27eb = \u27eav, y\u27eb) : x = y :=\nby rw [\u2190sub_eq_zero, \u2190@inner_self_eq_zero \ud835\udd5c, inner_sub_right, sub_eq_zero, h (x - y)]\n\nlemma ext_inner_right {x y : E} (h : \u2200 v, \u27eax, v\u27eb = \u27eay, v\u27eb) : x = y :=\nby rw [\u2190sub_eq_zero, \u2190@inner_self_eq_zero \ud835\udd5c, inner_sub_left, sub_eq_zero, h (x - y)]\n\nomit \ud835\udd5c\nvariable {\ud835\udd5c}\n\n/-- Parallelogram law -/\nlemma parallelogram_law {x y : E} :\n  \u27eax + y, x + y\u27eb + \u27eax - y, x - y\u27eb = 2 * (\u27eax, x\u27eb + \u27eay, y\u27eb) :=\nby simp [inner_add_add_self, inner_sub_sub_self, two_mul, sub_eq_add_neg, add_comm, add_left_comm]\n\n/-- Cauchy\u2013Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia. -/\nlemma inner_mul_inner_self_le (x y : E) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { have hy' : \u27eay, y\u27eb \u2260 0 := inner_self_eq_zero.not.2 hy,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm _ _,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm _ _,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := (inner_self_re_to_K _).symm,\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw is_R_or_C.ext_iff,\n      exact \u27e8by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082,\n                      neg_mul, add_monoid_hom.map_add, conj_im,\n                      add_monoid_hom.map_sub, mul_neg, conj_re, neg_neg, mul_re]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by simp only [map_div\u2080, h\u2083, inner_conj_symm, sub_add_cancel]\n                    with field_simps {discharger := tactic.field_simp.ne_zero}\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw \u2190mul_div_right_comm\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Cauchy\u2013Schwarz inequality for real inner products. -/\nlemma real_inner_mul_inner_self_le (x y : F) : \u27eax, y\u27eb_\u211d * \u27eax, y\u27eb_\u211d \u2264 \u27eax, x\u27eb_\u211d * \u27eay, y\u27eb_\u211d :=\nbegin\n  have h\u2081 : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_symm]; refl,\n  have h\u2082 := @inner_mul_inner_self_le \u211d F _ _ _ x y,\n  dsimp at h\u2082,\n  have h\u2083 := abs_mul_abs_self \u27eax, y\u27eb_\u211d,\n  rw [h\u2081] at h\u2082,\n  simpa [h\u2083] using h\u2082,\nend\n\n/-- A family of vectors is linearly independent if they are nonzero\nand orthogonal. -/\nlemma linear_independent_of_ne_zero_of_inner_eq_zero {\u03b9 : Type*} {v : \u03b9 \u2192 E}\n  (hz : \u2200 i, v i \u2260 0) (ho : \u2200 i j, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0) : linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff',\n  intros s g hg i hi,\n  have h' : g i * inner (v i) (v i) = inner (v i) (\u2211 j in s, g j \u2022 v j),\n  { rw inner_sum,\n    symmetry,\n    convert finset.sum_eq_single i _ _,\n    { rw inner_smul_right },\n    { intros j hj hji,\n      rw [inner_smul_right, ho i j hji.symm, mul_zero] },\n    { exact \u03bb h, false.elim (h hi) } },\n  simpa [hg, hz] using h'\nend\n\nend basic_properties\n\nsection orthonormal_sets\nvariables {\u03b9 : Type*} [dec_\u03b9 : decidable_eq \u03b9] (\ud835\udd5c)\n\ninclude \ud835\udd5c\n\n/-- An orthonormal set of vectors in an `inner_product_space` -/\ndef orthonormal (v : \u03b9 \u2192 E) : Prop :=\n(\u2200 i, \u2016v i\u2016 = 1) \u2227 (\u2200 {i j}, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0)\n\nomit \ud835\udd5c\n\nvariables {\ud835\udd5c}\n\ninclude dec_\u03b9\n/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal.  (Inner\nproduct equals Kronecker delta.) -/\nlemma orthonormal_iff_ite {v : \u03b9 \u2192 E} :\n  orthonormal \ud835\udd5c v \u2194 \u2200 i j, \u27eav i, v j\u27eb = if i = j then (1:\ud835\udd5c) else (0:\ud835\udd5c) :=\nbegin\n  split,\n  { intros hv i j,\n    split_ifs,\n    { simp [h, inner_self_eq_norm_sq_to_K, hv.1] },\n    { exact hv.2 h } },\n  { intros h,\n    split,\n    { intros i,\n      have h' : \u2016v i\u2016 ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_inner \ud835\udd5c, h i i],\n      have h\u2081 : 0 \u2264 \u2016v i\u2016 := norm_nonneg _,\n      have h\u2082 : (0:\u211d) \u2264 1 := zero_le_one,\n      rwa sq_eq_sq h\u2081 h\u2082 at h' },\n    { intros i j hij,\n      simpa [hij] using h i j } }\nend\nomit dec_\u03b9\n\ninclude dec_E\n/-- `if ... then ... else` characterization of a set of vectors being orthonormal.  (Inner product\nequals Kronecker delta.) -/\ntheorem orthonormal_subtype_iff_ite {s : set E} :\n  orthonormal \ud835\udd5c (coe : s \u2192 E) \u2194\n  (\u2200 v \u2208 s, \u2200 w \u2208 s, \u27eav, w\u27eb = if v = w then 1 else 0) :=\nbegin\n  rw orthonormal_iff_ite,\n  split,\n  { intros h v hv w hw,\n    convert h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9 using 1,\n    simp },\n  { rintros h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9,\n    convert h v hv w hw using 1,\n    simp }\nend\nomit dec_E\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = l i :=\nby classical; simp [finsupp.total_apply, finsupp.inner_sum, orthonormal_iff_ite.mp hv]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_sum\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) {s : finset \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  \u27eav i, \u2211 i in s, (l i) \u2022 (v i)\u27eb = l i :=\nby classical; simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, \u2211 i : \u03b9, (l i) \u2022 (v i)\u27eb = l i :=\nhv.inner_right_sum l (finset.mem_univ _)\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = conj (l i) :=\nby rw [\u2190 inner_conj_symm, hv.inner_right_finsupp]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_sum\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) {s : finset \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  \u27ea\u2211 i in s, (l i) \u2022 (v i), v i\u27eb = conj (l i) :=\nby classical; simp only\n[sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi, mul_boole, finset.sum_ite_eq', if_true]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27ea\u2211 i : \u03b9, (l i) \u2022 (v i), v i\u27eb = conj (l i) :=\nhv.inner_left_sum l (finset.mem_univ _)\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum over the first `finsupp`. -/\nlemma orthonormal.inner_finsupp_eq_sum_left\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l\u2081 l\u2082 : \u03b9 \u2192\u2080 \ud835\udd5c) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l\u2081, finsupp.total \u03b9 E \ud835\udd5c v l\u2082\u27eb = l\u2081.sum (\u03bb i y, conj y * l\u2082 i) :=\nby simp only [l\u2081.total_apply _, finsupp.sum_inner, hv.inner_right_finsupp, smul_eq_mul]\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum over the second `finsupp`. -/\nlemma orthonormal.inner_finsupp_eq_sum_right\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l\u2081 l\u2082 : \u03b9 \u2192\u2080 \ud835\udd5c) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l\u2081, finsupp.total \u03b9 E \ud835\udd5c v l\u2082\u27eb = l\u2082.sum (\u03bb i y, conj (l\u2081 i) * y) :=\nby simp only [l\u2082.total_apply _, finsupp.inner_sum, hv.inner_left_finsupp, mul_comm, smul_eq_mul]\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum. -/\nlemma orthonormal.inner_sum\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l\u2081 l\u2082 : \u03b9 \u2192 \ud835\udd5c) (s : finset \u03b9) :\n  \u27ea\u2211 i in s, l\u2081 i \u2022 v i, \u2211 i in s, l\u2082 i \u2022 v i\u27eb = \u2211 i in s, conj (l\u2081 i) * l\u2082 i :=\nbegin\n  simp_rw [sum_inner, inner_smul_left],\n  refine finset.sum_congr rfl (\u03bb i hi, _),\n  rw hv.inner_right_sum l\u2082 hi\nend\n\n/--\nThe double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the\nsum of the weights.\n-/\nlemma orthonormal.inner_left_right_finset {s : finset \u03b9}  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v)\n  {a : \u03b9 \u2192 \u03b9 \u2192 \ud835\udd5c} : \u2211 i in s, \u2211 j in s, (a i j) \u2022 \u27eav j, v i\u27eb = \u2211 k in s, a k k :=\nby classical; simp [orthonormal_iff_ite.mp hv, finset.sum_ite_of_true]\n\n/-- An orthonormal set is linearly independent. -/\nlemma orthonormal.linear_independent {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff,\n  intros l hl,\n  ext i,\n  have key : \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = \u27eav i, 0\u27eb := by rw hl,\n  simpa only [hv.inner_right_finsupp, inner_zero_right] using key\nend\n\n/-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an\northonormal family. -/\nlemma orthonormal.comp\n  {\u03b9' : Type*} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : \u03b9' \u2192 \u03b9) (hf : function.injective f) :\n  orthonormal \ud835\udd5c (v \u2218 f) :=\nbegin\n  classical,\n  rw orthonormal_iff_ite at \u22a2 hv,\n  intros i j,\n  convert hv (f i) (f j) using 1,\n  simp [hf.eq_iff]\nend\n\n/-- An injective family `v : \u03b9 \u2192 E` is orthonormal if and only if `coe : (range v) \u2192 E` is\northonormal. -/\nlemma orthonormal_subtype_range {v : \u03b9 \u2192 E} (hv : function.injective v) :\n  orthonormal \ud835\udd5c (coe : set.range v \u2192 E) \u2194 orthonormal \ud835\udd5c v :=\nbegin\n  let f : \u03b9 \u2243 set.range v := equiv.of_injective v hv,\n  refine \u27e8\u03bb h, h.comp f f.injective, \u03bb h, _\u27e9,\n  rw \u2190 equiv.self_comp_of_injective_symm hv,\n  exact h.comp f.symm f.symm.injective,\nend\n\n/-- If `v : \u03b9 \u2192 E` is an orthonormal family, then `coe : (range v) \u2192 E` is an orthonormal\nfamily. -/\nlemma orthonormal.to_subtype_range {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  orthonormal \ud835\udd5c (coe : set.range v \u2192 E) :=\n(orthonormal_subtype_range hv.linear_independent.injective).2 hv\n\n/-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the\nset. -/\nlemma orthonormal.inner_finsupp_eq_zero\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) {s : set \u03b9} {i : \u03b9} (hi : i \u2209 s) {l : \u03b9 \u2192\u2080 \ud835\udd5c}\n  (hl : l \u2208 finsupp.supported \ud835\udd5c \ud835\udd5c s) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = 0 :=\nbegin\n  rw finsupp.mem_supported' at hl,\n  simp only [hv.inner_left_finsupp, hl i hi, map_zero],\nend\n\n/-- Given an orthonormal family, a second family of vectors is orthonormal if every vector equals\nthe corresponding vector in the original family or its negation. -/\nlemma orthonormal.orthonormal_of_forall_eq_or_eq_neg {v w : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v)\n  (hw : \u2200 i, w i = v i \u2228 w i = -(v i)) : orthonormal \ud835\udd5c w :=\nbegin\n  classical,\n  rw orthonormal_iff_ite at *,\n  intros i j,\n  cases hw i with hi hi; cases hw j with hj hj; split_ifs with h;\n  simpa only [hi, hj, h, inner_neg_right, inner_neg_left,\n              neg_neg, eq_self_iff_true, neg_eq_zero] using hv i j\nend\n\n/- The material that follows, culminating in the existence of a maximal orthonormal subset, is\nadapted from the corresponding development of the theory of linearly independents sets.  See\n`exists_linear_independent` in particular. -/\n\nvariables (\ud835\udd5c E)\nlemma orthonormal_empty : orthonormal \ud835\udd5c (\u03bb x, x : (\u2205 : set E) \u2192 E) :=\nby classical; simp [orthonormal_subtype_iff_ite]\nvariables {\ud835\udd5c E}\n\nlemma orthonormal_Union_of_directed\n  {\u03b7 : Type*} {s : \u03b7 \u2192 set E} (hs : directed (\u2286) s) (h : \u2200 i, orthonormal \ud835\udd5c (\u03bb x, x : s i \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3 i, s i) \u2192 E) :=\nbegin\n  classical,\n  rw orthonormal_subtype_iff_ite,\n  rintros x \u27e8_, \u27e8i, rfl\u27e9, hxi\u27e9 y \u27e8_, \u27e8j, rfl\u27e9, hyj\u27e9,\n  obtain \u27e8k, hik, hjk\u27e9 := hs i j,\n  have h_orth : orthonormal \ud835\udd5c (\u03bb x, x : (s k) \u2192 E) := h k,\n  rw orthonormal_subtype_iff_ite at h_orth,\n  exact h_orth x (hik hxi) y (hjk hyj)\nend\n\nlemma orthonormal_sUnion_of_directed\n  {s : set (set E)} (hs : directed_on (\u2286) s)\n  (h : \u2200 a \u2208 s, orthonormal \ud835\udd5c (\u03bb x, x : (a : set E) \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3\u2080 s) \u2192 E) :=\nby rw set.sUnion_eq_Union; exact orthonormal_Union_of_directed hs.directed_coe (by simpa using h)\n\n/-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set\ncontaining it. -/\nlemma exists_maximal_orthonormal {s : set E} (hs : orthonormal \ud835\udd5c (coe : s \u2192 E)) :\n  \u2203 w \u2287 s, orthonormal \ud835\udd5c (coe : w \u2192 E) \u2227 \u2200 u \u2287 w, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2192 u = w :=\nbegin\n  obtain \u27e8b, bi, sb, h\u27e9 := zorn_subset_nonempty {b | orthonormal \ud835\udd5c (coe : b \u2192 E)} _ _ hs,\n  { refine \u27e8b, sb, bi, _\u27e9,\n    exact \u03bb u hus hu, h u hu hus },\n  { refine \u03bb c hc cc c0, \u27e8\u22c3\u2080 c, _, _\u27e9,\n    { exact orthonormal_sUnion_of_directed cc.directed_on (\u03bb x xc, hc xc) },\n    { exact \u03bb _, set.subset_sUnion_of_mem } }\nend\n\nlemma orthonormal.ne_zero {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (i : \u03b9) : v i \u2260 0 :=\nbegin\n  have : \u2016v i\u2016 \u2260 0,\n  { rw hv.1 i,\n    norm_num },\n  simpa using this\nend\n\nopen finite_dimensional\n\n/-- A family of orthonormal vectors with the correct cardinality forms a basis. -/\ndef basis_of_orthonormal_of_card_eq_finrank [fintype \u03b9] [nonempty \u03b9] {v : \u03b9 \u2192 E}\n  (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finrank \ud835\udd5c E) :\n  basis \u03b9 \ud835\udd5c E :=\nbasis_of_linear_independent_of_card_eq_finrank hv.linear_independent card_eq\n\n@[simp] lemma coe_basis_of_orthonormal_of_card_eq_finrank [fintype \u03b9] [nonempty \u03b9] {v : \u03b9 \u2192 E}\n  (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finrank \ud835\udd5c E) :\n  (basis_of_orthonormal_of_card_eq_finrank hv card_eq : \u03b9 \u2192 E) = v :=\ncoe_basis_of_linear_independent_of_card_eq_finrank _ _\n\nend orthonormal_sets\n\nsection norm\n\nlemma norm_eq_sqrt_inner (x : E) : \u2016x\u2016 = sqrt (re \u27eax, x\u27eb) :=\ncalc \u2016x\u2016 = sqrt (\u2016x\u2016 ^ 2) : (sqrt_sq (norm_nonneg _)).symm\n... = sqrt (re \u27eax, x\u27eb) : congr_arg _ (norm_sq_eq_inner _)\n\nlemma norm_eq_sqrt_real_inner (x : F) : \u2016x\u2016 = sqrt \u27eax, x\u27eb_\u211d :=\nby { have h := @norm_eq_sqrt_inner \u211d F _ _ _ x, simpa using h }\n\nlemma inner_self_eq_norm_mul_norm (x : E) : re \u27eax, x\u27eb = \u2016x\u2016 * \u2016x\u2016 :=\nby rw [@norm_eq_sqrt_inner \ud835\udd5c, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma inner_self_eq_norm_sq (x : E) : re \u27eax, x\u27eb = \u2016x\u2016^2 :=\nby rw [pow_two, inner_self_eq_norm_mul_norm]\n\nlemma real_inner_self_eq_norm_mul_norm (x : F) : \u27eax, x\u27eb_\u211d = \u2016x\u2016 * \u2016x\u2016 :=\nby { have h := @inner_self_eq_norm_mul_norm \u211d F _ _ _ x, simpa using h }\n\nlemma real_inner_self_eq_norm_sq (x : F) : \u27eax, x\u27eb_\u211d = \u2016x\u2016^2 :=\nby rw [pow_two, real_inner_self_eq_norm_mul_norm]\n\nvariables (\ud835\udd5c)\n/-- Expand the square -/\nlemma norm_add_sq (x y : E) : \u2016x + y\u2016^2 = \u2016x\u2016^2 + 2 * (re \u27eax, y\u27eb) + \u2016y\u2016^2 :=\nbegin\n  repeat {rw [sq, \u2190@inner_self_eq_norm_mul_norm \ud835\udd5c]},\n  rw [inner_add_add_self, two_mul],\n  simp only [add_assoc, add_left_inj, add_right_inj, add_monoid_hom.map_add],\n  rw [\u2190inner_conj_symm, conj_re],\nend\n\nalias norm_add_sq \u2190 norm_add_pow_two\n\n/-- Expand the square -/\nlemma norm_add_sq_real (x y : F) : \u2016x + y\u2016^2 = \u2016x\u2016^2 + 2 * \u27eax, y\u27eb_\u211d + \u2016y\u2016^2 :=\nby { have h := @norm_add_sq \u211d _ _ _ _ x y, simpa using h }\n\nalias norm_add_sq_real \u2190 norm_add_pow_two_real\n\n/-- Expand the square -/\nlemma norm_add_mul_self (x y : E) : \u2016x + y\u2016 * \u2016x + y\u2016 = \u2016x\u2016 * \u2016x\u2016 + 2 * (re \u27eax, y\u27eb) + \u2016y\u2016 * \u2016y\u2016 :=\nby { repeat {rw [\u2190 sq]}, exact norm_add_sq _ _ }\n\n/-- Expand the square -/\nlemma norm_add_mul_self_real (x y : F) : \u2016x + y\u2016 * \u2016x + y\u2016 = \u2016x\u2016 * \u2016x\u2016 + 2 * \u27eax, y\u27eb_\u211d + \u2016y\u2016 * \u2016y\u2016 :=\nby { have h := @norm_add_mul_self \u211d _ _ _ _ x y, simpa using h }\n\n/-- Expand the square -/\nlemma norm_sub_sq (x y : E) : \u2016x - y\u2016^2 = \u2016x\u2016^2 - 2 * (re \u27eax, y\u27eb) + \u2016y\u2016^2 :=\nbegin\n  repeat {rw [sq, \u2190@inner_self_eq_norm_mul_norm \ud835\udd5c]},\n  rw [inner_sub_sub_self],\n  calc\n    re (\u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb)\n        = re \u27eax, x\u27eb - re \u27eax, y\u27eb - re \u27eay, x\u27eb + re \u27eay, y\u27eb  : by simp only [map_add, map_sub]\n    ... = -re \u27eay, x\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb  : by ring\n    ... = -re (\u27eax, y\u27eb\u2020) - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw [inner_conj_symm]\n    ... = -re \u27eax, y\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw [conj_re]\n    ... = re \u27eax, x\u27eb - 2*re \u27eax, y\u27eb + re \u27eay, y\u27eb : by ring\nend\n\nalias norm_sub_sq \u2190 norm_sub_pow_two\n\n/-- Expand the square -/\nlemma norm_sub_sq_real (x y : F) : \u2016x - y\u2016^2 = \u2016x\u2016^2 - 2 * \u27eax, y\u27eb_\u211d + \u2016y\u2016^2 :=\n@norm_sub_sq \u211d _ _ _ _ _ _\n\nalias norm_sub_sq_real \u2190 norm_sub_pow_two_real\n\n/-- Expand the square -/\nlemma norm_sub_mul_self (x y : E) : \u2016x - y\u2016 * \u2016x - y\u2016 = \u2016x\u2016 * \u2016x\u2016 - 2 * re \u27eax, y\u27eb + \u2016y\u2016 * \u2016y\u2016 :=\nby { repeat {rw [\u2190 sq]}, exact norm_sub_sq _ _ }\n\n/-- Expand the square -/\nlemma norm_sub_mul_self_real (x y : F) : \u2016x - y\u2016 * \u2016x - y\u2016 = \u2016x\u2016 * \u2016x\u2016 - 2 * \u27eax, y\u27eb_\u211d + \u2016y\u2016 * \u2016y\u2016 :=\nby { have h := @norm_sub_mul_self \u211d _ _ _ _ x y, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : E) : abs \u27eax, y\u27eb \u2264 \u2016x\u2016 * \u2016y\u2016 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _))\nbegin\n  have : \u2016x\u2016 * \u2016y\u2016 * (\u2016x\u2016 * \u2016y\u2016) = (re \u27eax, x\u27eb) * (re \u27eay, y\u27eb),\n    simp only [inner_self_eq_norm_mul_norm], ring,\n  rw this,\n  conv_lhs { congr, skip, rw [inner_abs_conj_symm] },\n  exact inner_mul_inner_self_le _ _\nend\n\nlemma norm_inner_le_norm (x y : E) : \u2016\u27eax, y\u27eb\u2016 \u2264 \u2016x\u2016 * \u2016y\u2016 :=\n(is_R_or_C.norm_eq_abs _).le.trans (abs_inner_le_norm x y)\n\nlemma nnnorm_inner_le_nnnorm (x y : E) : \u2016\u27eax, y\u27eb\u2016\u208a \u2264 \u2016x\u2016\u208a * \u2016y\u2016\u208a :=\nnorm_inner_le_norm x y\n\nlemma re_inner_le_norm (x y : E) : re \u27eax, y\u27eb \u2264 \u2016x\u2016 * \u2016y\u2016 :=\nle_trans (re_le_abs (inner x y)) (abs_inner_le_norm x y)\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_real_inner_le_norm (x y : F) : absR \u27eax, y\u27eb_\u211d \u2264 \u2016x\u2016 * \u2016y\u2016 :=\nby { have h := @abs_inner_le_norm \u211d F _ _ _ x y, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma real_inner_le_norm (x y : F) : \u27eax, y\u27eb_\u211d \u2264 \u2016x\u2016 * \u2016y\u2016 :=\nle_trans (le_abs_self _) (abs_real_inner_le_norm _ _)\n\ninclude \ud835\udd5c\nvariables (\ud835\udd5c)\nlemma parallelogram_law_with_norm (x y : E) :\n  \u2016x + y\u2016 * \u2016x + y\u2016 + \u2016x - y\u2016 * \u2016x - y\u2016 = 2 * (\u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016) :=\nbegin\n  simp only [\u2190 @inner_self_eq_norm_mul_norm \ud835\udd5c],\n  rw [\u2190 re.map_add, parallelogram_law, two_mul, two_mul],\n  simp only [re.map_add],\nend\n\nlemma parallelogram_law_with_nnnorm (x y : E) :\n  \u2016x + y\u2016\u208a * \u2016x + y\u2016\u208a + \u2016x - y\u2016\u208a * \u2016x - y\u2016\u208a = 2 * (\u2016x\u2016\u208a * \u2016x\u2016\u208a + \u2016y\u2016\u208a * \u2016y\u2016\u208a) :=\nsubtype.ext $ parallelogram_law_with_norm \ud835\udd5c x y\nvariables {\ud835\udd5c}\nomit \ud835\udd5c\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2016x + y\u2016 * \u2016x + y\u2016 - \u2016x\u2016 * \u2016x\u2016 - \u2016y\u2016 * \u2016y\u2016) / 2 :=\nby { rw @norm_add_mul_self \ud835\udd5c, ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 - \u2016x - y\u2016 * \u2016x - y\u2016) / 2 :=\nby { rw [@norm_sub_mul_self \ud835\udd5c], ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :\n  re \u27eax, y\u27eb = (\u2016x + y\u2016 * \u2016x + y\u2016 - \u2016x - y\u2016 * \u2016x - y\u2016) / 4 :=\nby { rw [@norm_add_mul_self \ud835\udd5c, @norm_sub_mul_self \ud835\udd5c], ring }\n\n/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/\nlemma im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four (x y : E) :\n  im \u27eax, y\u27eb = (\u2016x - IK \u2022 y\u2016 * \u2016x - IK \u2022 y\u2016 - \u2016x + IK \u2022 y\u2016 * \u2016x + IK \u2022 y\u2016) / 4 :=\nby { simp only [@norm_add_mul_self \ud835\udd5c, @norm_sub_mul_self \ud835\udd5c, inner_smul_right, I_mul_re], ring }\n\n/-- Polarization identity: The inner product, in terms of the norm. -/\nlemma inner_eq_sum_norm_sq_div_four (x y : E) :\n  \u27eax, y\u27eb = (\u2016x + y\u2016 ^ 2 - \u2016x - y\u2016 ^ 2 + (\u2016x - IK \u2022 y\u2016 ^ 2 - \u2016x + IK \u2022 y\u2016 ^ 2) * IK) / 4 :=\nbegin\n  rw [\u2190 re_add_im \u27eax, y\u27eb, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,\n    im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four],\n  push_cast,\n  simp only [sq, \u2190 mul_div_right_comm, \u2190 add_div]\nend\n\n/-- Formula for the distance between the images of two nonzero points under an inversion with center\nzero. See also `euclidean_geometry.dist_inversion_inversion` for inversions around a general\npoint. -/\nlemma dist_div_norm_sq_smul {x y : F} (hx : x \u2260 0) (hy : y \u2260 0) (R : \u211d) :\n  dist ((R / \u2016x\u2016) ^ 2 \u2022 x) ((R / \u2016y\u2016) ^ 2 \u2022 y) = (R ^ 2 / (\u2016x\u2016 * \u2016y\u2016)) * dist x y :=\nhave hx' : \u2016x\u2016 \u2260 0, from norm_ne_zero_iff.2 hx,\nhave hy' : \u2016y\u2016 \u2260 0, from norm_ne_zero_iff.2 hy,\ncalc dist ((R / \u2016x\u2016) ^ 2 \u2022 x) ((R / \u2016y\u2016) ^ 2 \u2022 y)\n    = sqrt (\u2016(R / \u2016x\u2016) ^ 2 \u2022 x - (R / \u2016y\u2016) ^ 2 \u2022 y\u2016^2) :\n  by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)]\n... = sqrt ((R ^ 2 / (\u2016x\u2016 * \u2016y\u2016)) ^ 2 * \u2016x - y\u2016 ^ 2) :\n  congr_arg sqrt $ by { field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left,\n    inner_smul_right, real.norm_of_nonneg (mul_self_nonneg _)], ring }\n... = (R ^ 2 / (\u2016x\u2016 * \u2016y\u2016)) * dist x y :\n  by rw [sqrt_mul (sq_nonneg _), sqrt_sq (norm_nonneg _),\n    sqrt_sq (div_nonneg (sq_nonneg _) (mul_nonneg (norm_nonneg _) (norm_nonneg _))), dist_eq_norm]\n\n@[priority 100] -- See note [lower instance priority]\ninstance inner_product_space.to_uniform_convex_space : uniform_convex_space F :=\n\u27e8\u03bb \u03b5 h\u03b5, begin\n  refine \u27e82 - sqrt (4 - \u03b5^2), sub_pos_of_lt $ (sqrt_lt' zero_lt_two).2 _, \u03bb x hx y hy hxy, _\u27e9,\n  { norm_num,\n    exact pow_pos h\u03b5 _ },\n  rw sub_sub_cancel,\n  refine le_sqrt_of_sq_le _,\n  rw [sq, eq_sub_iff_add_eq.2 (parallelogram_law_with_norm \u211d x y), \u2190sq (\u2016x - y\u2016), hx, hy],\n  norm_num,\n  exact pow_le_pow_of_le_left h\u03b5.le hxy _,\nend\u27e9\n\nsection complex\n\nvariables {V : Type*} [normed_add_comm_group V] [inner_product_space \u2102 V]\n\n/--\nA complex polarization identity, with a linear map\n-/\nlemma inner_map_polarization (T : V \u2192\u2097[\u2102] V) (x y : V):\n  \u27ea T y, x \u27eb_\u2102 = (\u27eaT (x + y) , x + y\u27eb_\u2102 - \u27eaT (x - y) , x - y\u27eb_\u2102 +\n    complex.I * \u27eaT (x + complex.I \u2022 y) , x + complex.I \u2022 y\u27eb_\u2102 -\n    complex.I * \u27eaT (x - complex.I \u2022 y), x - complex.I \u2022 y \u27eb_\u2102) / 4 :=\nbegin\n  simp only [map_add, map_sub, inner_add_left, inner_add_right, linear_map.map_smul,\n             inner_smul_left, inner_smul_right, complex.conj_I, \u2190pow_two, complex.I_sq,\n             inner_sub_left, inner_sub_right, mul_add, \u2190mul_assoc, mul_neg, neg_neg,\n             sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub],\n  ring,\nend\n\nlemma inner_map_polarization' (T : V \u2192\u2097[\u2102] V) (x y : V):\n  \u27ea T x, y \u27eb_\u2102 = (\u27eaT (x + y) , x + y\u27eb_\u2102 - \u27eaT (x - y) , x - y\u27eb_\u2102 -\n    complex.I * \u27eaT (x + complex.I \u2022 y) , x + complex.I \u2022 y\u27eb_\u2102 +\n    complex.I * \u27eaT (x - complex.I \u2022 y), x - complex.I \u2022 y \u27eb_\u2102) / 4 :=\nbegin\n  simp only [map_add, map_sub, inner_add_left, inner_add_right, linear_map.map_smul,\n             inner_smul_left, inner_smul_right, complex.conj_I, \u2190pow_two, complex.I_sq,\n             inner_sub_left, inner_sub_right, mul_add, \u2190mul_assoc, mul_neg, neg_neg,\n             sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub],\n  ring,\nend\n\n/--\nA linear map `T` is zero, if and only if the identity `\u27eaT x, x\u27eb_\u2102 = 0` holds for all `x`.\n-/\nlemma inner_map_self_eq_zero (T : V \u2192\u2097[\u2102] V) :\n  (\u2200 (x : V), \u27eaT x, x\u27eb_\u2102 = 0) \u2194 T = 0 :=\nbegin\n  split,\n  { intro hT,\n    ext x,\n    simp only [linear_map.zero_apply, \u2190 @inner_self_eq_zero \u2102, inner_map_polarization, hT],\n    norm_num },\n  { rintro rfl x,\n    simp only [linear_map.zero_apply, inner_zero_left] }\nend\n\n/--\nTwo linear maps `S` and `T` are equal, if and only if the identity `\u27eaS x, x\u27eb_\u2102 = \u27eaT x, x\u27eb_\u2102` holds\nfor all `x`.\n-/\nlemma ext_inner_map (S T : V \u2192\u2097[\u2102] V) :\n  (\u2200 (x : V), \u27eaS x, x\u27eb_\u2102 = \u27eaT x, x\u27eb_\u2102) \u2194 S = T :=\nbegin\n  rw [\u2190sub_eq_zero, \u2190inner_map_self_eq_zero],\n  refine forall_congr (\u03bb x, _),\n  rw [linear_map.sub_apply, inner_sub_left, sub_eq_zero],\nend\n\nend complex\n\nsection\n\nvariables {\u03b9 : Type*} {\u03b9' : Type*} {\u03b9'' : Type*}\nvariables {E' : Type*} [normed_add_comm_group E'] [inner_product_space \ud835\udd5c E']\nvariables {E'' : Type*} [normed_add_comm_group E''] [inner_product_space \ud835\udd5c E'']\n\n/-- A linear isometry preserves the inner product. -/\n@[simp] lemma linear_isometry.inner_map_map (f : E \u2192\u2097\u1d62[\ud835\udd5c] E') (x y : E) : \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nby simp [inner_eq_sum_norm_sq_div_four, \u2190 f.norm_map]\n\n/-- A linear isometric equivalence preserves the inner product. -/\n@[simp] lemma linear_isometry_equiv.inner_map_map (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') (x y : E) :\n  \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nf.to_linear_isometry.inner_map_map x y\n\n/-- A linear map that preserves the inner product is a linear isometry. -/\ndef linear_map.isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) : E \u2192\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, \u03bb x, by simp only [@norm_eq_sqrt_inner \ud835\udd5c, h]\u27e9\n\n@[simp] lemma linear_map.coe_isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_map.isometry_of_inner_to_linear_map (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_map = f := rfl\n\n/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/\ndef linear_equiv.isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, ((f : E \u2192\u2097[\ud835\udd5c] E').isometry_of_inner h).norm_map\u27e9\n\n@[simp] lemma linear_equiv.coe_isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_equiv.isometry_of_inner_to_linear_equiv (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_equiv = f := rfl\n\n/-- A linear isometry preserves the property of being orthonormal. -/\nlemma linear_isometry.orthonormal_comp_iff {v : \u03b9 \u2192 E} (f : E \u2192\u2097\u1d62[\ud835\udd5c] E') :\n  orthonormal \ud835\udd5c (f \u2218 v) \u2194 orthonormal \ud835\udd5c v :=\nbegin\n  classical,\n  simp_rw [orthonormal_iff_ite, linear_isometry.inner_map_map]\nend\n\n/-- A linear isometry preserves the property of being orthonormal. -/\nlemma orthonormal.comp_linear_isometry {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : E \u2192\u2097\u1d62[\ud835\udd5c] E') :\n  orthonormal \ud835\udd5c (f \u2218 v) :=\nby rwa f.orthonormal_comp_iff\n\n/-- A linear isometric equivalence preserves the property of being orthonormal. -/\nlemma orthonormal.comp_linear_isometry_equiv {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') :\n  orthonormal \ud835\udd5c (f \u2218 v) :=\nhv.comp_linear_isometry f.to_linear_isometry\n\n/-- A linear isometric equivalence, applied with `basis.map`, preserves the property of being\northonormal. -/\nlemma orthonormal.map_linear_isometry_equiv {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') : orthonormal \ud835\udd5c (v.map f.to_linear_equiv) :=\nhv.comp_linear_isometry_equiv f\n\n/-- A linear map that sends an orthonormal basis to orthonormal vectors is a linear isometry. -/\ndef linear_map.isometry_of_orthonormal (f : E \u2192\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  (hf : orthonormal \ud835\udd5c (f \u2218 v)) : E \u2192\u2097\u1d62[\ud835\udd5c] E' :=\nf.isometry_of_inner $ \u03bb x y, by rw [\u2190v.total_repr x, \u2190v.total_repr y, finsupp.apply_total,\n                                    finsupp.apply_total, hv.inner_finsupp_eq_sum_left,\n                                    hf.inner_finsupp_eq_sum_left]\n\n@[simp] lemma linear_map.coe_isometry_of_orthonormal (f : E \u2192\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E}\n  (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  \u21d1(f.isometry_of_orthonormal hv hf) = f :=\nrfl\n\n@[simp] lemma linear_map.isometry_of_orthonormal_to_linear_map (f : E \u2192\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E}\n  (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  (f.isometry_of_orthonormal hv hf).to_linear_map = f :=\nrfl\n\n/-- A linear equivalence that sends an orthonormal basis to orthonormal vectors is a linear\nisometric equivalence. -/\ndef linear_equiv.isometry_of_orthonormal (f : E \u2243\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  (hf : orthonormal \ud835\udd5c (f \u2218 v)) : E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\nf.isometry_of_inner $ \u03bb x y, begin\n  rw \u2190linear_equiv.coe_coe at hf,\n  rw [\u2190v.total_repr x, \u2190v.total_repr y, \u2190linear_equiv.coe_coe, finsupp.apply_total,\n      finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left]\nend\n\n@[simp] lemma linear_equiv.coe_isometry_of_orthonormal (f : E \u2243\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E}\n  (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  \u21d1(f.isometry_of_orthonormal hv hf) = f :=\nrfl\n\n@[simp] lemma linear_equiv.isometry_of_orthonormal_to_linear_equiv (f : E \u2243\u2097[\ud835\udd5c] E')\n  {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  (f.isometry_of_orthonormal hv hf).to_linear_equiv = f :=\nrfl\n\n/-- A linear isometric equivalence that sends an orthonormal basis to a given orthonormal basis. -/\ndef orthonormal.equiv {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') : E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\n(v.equiv v' e).isometry_of_orthonormal hv begin\n  have h : (v.equiv v' e) \u2218 v = v' \u2218 e,\n  { ext i,\n    simp },\n  rw h,\n  exact hv'.comp _ e.injective\nend\n\n@[simp] lemma orthonormal.equiv_to_linear_equiv {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  {v' : basis \u03b9' \ud835\udd5c E'} (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') :\n  (hv.equiv hv' e).to_linear_equiv = v.equiv v' e :=\nrfl\n\n@[simp] lemma orthonormal.equiv_apply {\u03b9' : Type*} {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  {v' : basis \u03b9' \ud835\udd5c E'} (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') (i : \u03b9) :\n  hv.equiv hv' e (v i) = v' (e i) :=\nbasis.equiv_apply _ _ _ _\n\n@[simp] lemma orthonormal.equiv_refl {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) :\n  hv.equiv hv (equiv.refl \u03b9) = linear_isometry_equiv.refl \ud835\udd5c E :=\nv.ext_linear_isometry_equiv $ \u03bb i,\n  by simp only [orthonormal.equiv_apply, equiv.coe_refl, id.def, linear_isometry_equiv.coe_refl]\n\n@[simp] lemma orthonormal.equiv_symm {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') : (hv.equiv hv' e).symm = hv'.equiv hv e.symm :=\nv'.ext_linear_isometry_equiv $ \u03bb i, (hv.equiv hv' e).injective $\n  by simp only [linear_isometry_equiv.apply_symm_apply, orthonormal.equiv_apply, e.apply_symm_apply]\n\n@[simp] lemma orthonormal.equiv_trans {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') {v'' : basis \u03b9'' \ud835\udd5c E''} (hv'' : orthonormal \ud835\udd5c v'')\n  (e' : \u03b9' \u2243 \u03b9'') : (hv.equiv hv' e).trans (hv'.equiv hv'' e') = hv.equiv hv'' (e.trans e') :=\nv.ext_linear_isometry_equiv $ \u03bb i,\n  by simp only [linear_isometry_equiv.trans_apply, orthonormal.equiv_apply, e.coe_trans]\n\nlemma orthonormal.map_equiv {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') :\n  v.map ((hv.equiv hv' e).to_linear_equiv) = v'.reindex e.symm :=\nv.map_equiv _ _\n\nend\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2016x + y\u2016 * \u2016x + y\u2016 - \u2016x\u2016 * \u2016x\u2016 - \u2016y\u2016 * \u2016y\u2016) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 - \u2016x - y\u2016 * \u2016x - y\u2016) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y\n\n/-- Pythagorean theorem, if-and-only-if vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2016x + y\u2016 * \u2016x + y\u2016 = \u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [@norm_add_mul_self \u211d, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/\nlemma norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} :\n  \u2016x + y\u2016 = sqrt (\u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016) \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nby rw [\u2190norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm,\n  sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)]\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : \u27eax, y\u27eb = 0) :\n  \u2016x + y\u2016 * \u2016x + y\u2016 = \u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 :=\nbegin\n  rw [@norm_add_mul_self \ud835\udd5c, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  apply or.inr,\n  simp only [h, zero_re'],\nend\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2016x + y\u2016 * \u2016x + y\u2016 = \u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 :=\n(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector\ninner product form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2016x - y\u2016 * \u2016x - y\u2016 = \u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [@norm_sub_mul_self \u211d, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero,\n      mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square\nroots. -/\nlemma norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} :\n  \u2016x - y\u2016 = sqrt (\u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016) \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nby rw [\u2190norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm,\n  sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)]\n\n/-- Pythagorean theorem, subtracting vectors, vector inner product\nform. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2016x - y\u2016 * \u2016x - y\u2016 = \u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 :=\n(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- The sum and difference of two vectors are orthogonal if and only\nif they have the same norm. -/\nlemma real_inner_add_sub_eq_zero_iff (x y : F) : \u27eax + y, x - y\u27eb_\u211d = 0 \u2194 \u2016x\u2016 = \u2016y\u2016 :=\nbegin\n  conv_rhs { rw \u2190mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _) },\n  simp only [\u2190@inner_self_eq_norm_mul_norm \u211d, inner_add_left, inner_sub_right,\n            real_inner_comm y x, sub_eq_zero, re_to_real],\n  split,\n  { intro h,\n    rw [add_comm] at h,\n    linarith },\n  { intro h,\n    linarith }\nend\n\n/-- Given two orthogonal vectors, their sum and difference have equal norms. -/\nlemma norm_sub_eq_norm_add {v w : E} (h : \u27eav, w\u27eb = 0) : \u2016w - v\u2016 = \u2016w + v\u2016 :=\nbegin\n  rw \u2190mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _),\n  simp only [h, \u2190@inner_self_eq_norm_mul_norm \ud835\udd5c, sub_neg_eq_add, sub_zero, map_sub, zero_re',\n    zero_sub,\n    add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm, zero_add]\nend\n\n/-- The real inner product of two vectors, divided by the product of their\nnorms, has absolute value at most 1. -/\nlemma abs_real_inner_div_norm_mul_norm_le_one (x y : F) : absR (\u27eax, y\u27eb_\u211d / (\u2016x\u2016 * \u2016y\u2016)) \u2264 1 :=\nbegin\n  rw _root_.abs_div,\n  by_cases h : 0 = absR (\u2016x\u2016 * \u2016y\u2016),\n  { rw [\u2190h, div_zero],\n    norm_num },\n  { change 0 \u2260 absR (\u2016x\u2016 * \u2016y\u2016) at h,\n    rw div_le_iff' (lt_of_le_of_ne (ge_iff_le.mp (_root_.abs_nonneg (\u2016x\u2016 * \u2016y\u2016))) h),\n    convert abs_real_inner_le_norm x y using 1,\n    rw [_root_.abs_mul, _root_.abs_of_nonneg (norm_nonneg x), _root_.abs_of_nonneg (norm_nonneg y),\n        mul_one] }\nend\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_left (x : F) (r : \u211d) : \u27ear \u2022 x, x\u27eb_\u211d = r * (\u2016x\u2016 * \u2016x\u2016) :=\nby rw [real_inner_smul_left, \u2190real_inner_self_eq_norm_mul_norm]\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_right (x : F) (r : \u211d) : \u27eax, r \u2022 x\u27eb_\u211d = r * (\u2016x\u2016 * \u2016x\u2016) :=\nby rw [inner_smul_right, \u2190real_inner_self_eq_norm_mul_norm]\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : E} {r : \ud835\udd5c} (hx : x \u2260 0) (hr : r \u2260 0) : abs \u27eax, r \u2022 x\u27eb / (\u2016x\u2016 * \u2016r \u2022 x\u2016) = 1 :=\nbegin\n  have hx' : \u2016x\u2016 \u2260 0 := by simp [norm_eq_zero, hx],\n  have hr' : abs r \u2260 0 := by simp [is_R_or_C.abs_eq_zero, hr],\n  rw [inner_smul_right, is_R_or_C.abs_mul, \u2190inner_self_re_abs, inner_self_eq_norm_mul_norm,\n      norm_smul],\n  rw [is_R_or_C.norm_eq_abs, \u2190mul_assoc, \u2190div_div, mul_div_cancel _ hx',\n     \u2190div_div, mul_comm, mul_div_cancel _ hr', div_self hx'],\nend\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r \u2260 0) : absR \u27eax, r \u2022 x\u27eb_\u211d / (\u2016x\u2016 * \u2016r \u2022 x\u2016) = 1 :=\nbegin\n  rw \u2190 abs_to_real,\n  exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr\nend\n\n/-- The inner product of a nonzero vector with a positive multiple of\nitself, divided by the product of their norms, has value 1. -/\nlemma real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : 0 < r) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2016x\u2016 * \u2016r \u2022 x\u2016) = 1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2016x\u2016, mul_comm _ (absR r),\n      mul_assoc, _root_.abs_of_nonneg (le_of_lt hr), div_self],\n  exact mul_ne_zero (ne_of_gt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of a nonzero vector with a negative multiple of\nitself, divided by the product of their norms, has value -1. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r < 0) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2016x\u2016 * \u2016r \u2022 x\u2016) = -1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2016x\u2016, mul_comm _ (absR r),\n      mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self],\n  exact mul_ne_zero (ne_of_lt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_iff (x y : E) :\n  abs (\u27eax, y\u27eb / (\u2016x\u2016 * \u2016y\u2016)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have hx0 : x \u2260 0,\n    { intro hx0,\n      rw [hx0, inner_zero_left, zero_div] at h,\n      norm_num at h, },\n    refine and.intro hx0 _,\n    set r := \u27eax, y\u27eb / (\u2016x\u2016 * \u2016x\u2016) with hr,\n    use r,\n    set t := y - r \u2022 x with ht,\n    have ht0 : \u27eax, t\u27eb = 0,\n    { rw [ht, inner_sub_right, inner_smul_right, hr],\n      norm_cast,\n      rw [\u2190@inner_self_eq_norm_mul_norm \ud835\udd5c, inner_self_re_to_K,\n          div_mul_cancel _ (\u03bb h, hx0 ((@inner_self_eq_zero \ud835\udd5c _ _ _ _ _).1 h)), sub_self] },\n    replace h : \u2016r \u2022 x\u2016 / \u2016t + r \u2022 x\u2016 = 1,\n    { rw [\u2190sub_add_cancel y (r \u2022 x), \u2190ht, inner_add_right, ht0, zero_add, inner_smul_right,\n        is_R_or_C.abs_div, is_R_or_C.abs_mul, \u2190inner_self_re_abs,\n        inner_self_eq_norm_mul_norm] at h,\n      norm_cast at h,\n      rwa [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm, \u2190mul_assoc, mul_comm,\n        mul_div_mul_left _ _ (\u03bb h, hx0 (norm_eq_zero.1 h)), \u2190is_R_or_C.norm_eq_abs,\n        \u2190norm_smul] at h },\n    have hr0 : r \u2260 0,\n    { intro hr0,\n      rw [hr0, zero_smul, norm_zero, zero_div] at h,\n      norm_num at h },\n    refine and.intro hr0 _,\n    have h2 : \u2016r \u2022 x\u2016 ^ 2 = \u2016t + r \u2022 x\u2016 ^ 2,\n    { rw [eq_of_div_eq_one h] },\n    replace h2 : \u27ear \u2022 x, r \u2022 x\u27eb = \u27eat, t\u27eb + \u27eat, r \u2022 x\u27eb + \u27ear \u2022 x, t\u27eb + \u27ear \u2022 x, r \u2022 x\u27eb,\n    { rw [sq, sq, \u2190@inner_self_eq_norm_mul_norm \ud835\udd5c, \u2190@inner_self_eq_norm_mul_norm \ud835\udd5c] at h2,\n      have h2' := congr_arg (\u03bb z : \u211d, (z : \ud835\udd5c)) h2,\n      simp_rw [inner_self_re_to_K, inner_add_add_self] at h2',\n      exact h2' },\n    conv at h2 in \u27ear \u2022 x, t\u27eb { rw [inner_smul_left, ht0, mul_zero] },\n    symmetry' at h2,\n    have h\u2081 : \u27eat, r \u2022 x\u27eb = 0 := by { rw [inner_smul_right, \u2190inner_conj_symm, ht0], simp },\n    rw [add_zero, h\u2081, add_left_eq_self, add_zero, inner_self_eq_zero] at h2,\n    rw h2 at ht,\n    exact eq_of_sub_eq_zero ht.symm },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw [hy, is_R_or_C.abs_div],\n    norm_cast,\n    rw [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm],\n    exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  absR (\u27eax, y\u27eb_\u211d / (\u2016x\u2016 * \u2016y\u2016)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  have := @abs_inner_div_norm_mul_norm_eq_one_iff \u211d F _ _ _ x y,\n  simpa [coe_real_eq_id] using this,\nend\n\n/--\nIf the inner product of two vectors is equal to the product of their norms, then the two vectors\nare multiples of each other. One form of the equality case for Cauchy-Schwarz.\nCompare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `\u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016`. -/\nlemma abs_inner_eq_norm_iff (x y : E) (hx0 : x \u2260 0) (hy0 : y \u2260 0):\n  abs \u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016 \u2194 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x :=\nbegin\n  have hxy0 : \u2016x\u2016 * \u2016y\u2016 \u2260 0 := mul_ne_zero (norm_eq_zero.not.2 hx0) (norm_eq_zero.not.2 hy0),\n  have h\u2081 : abs \u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016 \u2194 abs (\u27eax, y\u27eb / (\u2016x\u2016 * \u2016y\u2016)) = 1,\n  { rw [\u2190algebra_map.coe_mul, is_R_or_C.abs_div, is_R_or_C.abs_of_nonneg, div_eq_one_iff_eq hxy0],\n    positivity },\n  rw [h\u2081, abs_inner_div_norm_mul_norm_eq_one_iff x y],\n  exact and_iff_right hx0,\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value 1 if and only if they are nonzero and one is\na positive multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2016x\u2016 * \u2016y\u2016) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), 0 < r \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrneg,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrneg) hr) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value -1 if and only if they are nonzero and one is\na negative multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2016x\u2016 * \u2016y\u2016) = -1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r < 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrpos,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrpos) hr.symm) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx hr }\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016`. -/\nlemma inner_eq_norm_mul_iff {x y : E} :\n  \u27eax, y\u27eb = (\u2016x\u2016 : \ud835\udd5c) * \u2016y\u2016 \u2194 (\u2016y\u2016 : \ud835\udd5c) \u2022 x = (\u2016x\u2016 : \ud835\udd5c) \u2022 y :=\nbegin\n  by_cases h : (x = 0 \u2228 y = 0), -- WLOG `x` and `y` are nonzero\n  { cases h; simp [h] },\n  calc \u27eax, y\u27eb = (\u2016x\u2016 : \ud835\udd5c) * \u2016y\u2016 \u2194 \u2016x\u2016 * \u2016y\u2016 = re \u27eax, y\u27eb :\n  begin\n    norm_cast,\n    split,\n    { intros h',\n      simp [h'] },\n    { have cauchy_schwarz := abs_inner_le_norm x y,\n      intros h',\n      rw h' at \u22a2 cauchy_schwarz,\n      rwa re_eq_self_of_le }\n  end\n  ... \u2194 2 * \u2016x\u2016 * \u2016y\u2016 * (\u2016x\u2016 * \u2016y\u2016 - re \u27eax, y\u27eb) = 0 :\n    by simp [h, show (2:\u211d) \u2260 0, by norm_num, sub_eq_zero]\n  ... \u2194 \u2016(\u2016y\u2016:\ud835\udd5c) \u2022 x - (\u2016x\u2016:\ud835\udd5c) \u2022 y\u2016 * \u2016(\u2016y\u2016:\ud835\udd5c) \u2022 x - (\u2016x\u2016:\ud835\udd5c) \u2022 y\u2016 = 0 :\n  begin\n    simp only [@norm_sub_mul_self \ud835\udd5c, inner_smul_left, inner_smul_right, norm_smul, conj_of_real,\n      is_R_or_C.norm_eq_abs, abs_of_real, of_real_im, of_real_re, mul_re, abs_norm_eq_norm],\n    refine eq.congr _ rfl,\n    ring\n  end\n  ... \u2194 (\u2016y\u2016 : \ud835\udd5c) \u2022 x = (\u2016x\u2016 : \ud835\udd5c) \u2022 y : by simp [norm_sub_eq_zero_iff]\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016`. -/\nlemma inner_eq_norm_mul_iff_real {x y : F} : \u27eax, y\u27eb_\u211d = \u2016x\u2016 * \u2016y\u2016 \u2194 \u2016y\u2016 \u2022 x = \u2016x\u2016 \u2022 y :=\ninner_eq_norm_mul_iff\n\n/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of\nthe equality case for Cauchy-Schwarz. -/\nlemma inner_eq_norm_mul_iff_of_norm_one {x y : E} (hx : \u2016x\u2016 = 1) (hy : \u2016y\u2016 = 1) :\n  \u27eax, y\u27eb = 1 \u2194 x = y :=\nby { convert inner_eq_norm_mul_iff using 2; simp [hx, hy] }\n\nlemma inner_lt_norm_mul_iff_real {x y : F} :\n  \u27eax, y\u27eb_\u211d < \u2016x\u2016 * \u2016y\u2016 \u2194 \u2016y\u2016 \u2022 x \u2260 \u2016x\u2016 \u2022 y :=\ncalc \u27eax, y\u27eb_\u211d < \u2016x\u2016 * \u2016y\u2016\n    \u2194 \u27eax, y\u27eb_\u211d \u2260 \u2016x\u2016 * \u2016y\u2016 : \u27e8ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)\u27e9\n... \u2194 \u2016y\u2016 \u2022 x \u2260 \u2016x\u2016 \u2022 y : not_congr inner_eq_norm_mul_iff_real\n\n/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are\ndistinct. One form of the equality case for Cauchy-Schwarz. -/\nlemma inner_lt_one_iff_real_of_norm_one {x y : F} (hx : \u2016x\u2016 = 1) (hy : \u2016y\u2016 = 1) :\n  \u27eax, y\u27eb_\u211d < 1 \u2194 x \u2260 y :=\nby { convert inner_lt_norm_mul_iff_real; simp [hx, hy] }\n\n/-- The inner product of two weighted sums, where the weights in each\nsum add to 0, in terms of the norms of pairwise differences. -/\nlemma inner_sum_smul_sum_smul_of_sum_eq_zero {\u03b9\u2081 : Type*} {s\u2081 : finset \u03b9\u2081} {w\u2081 : \u03b9\u2081 \u2192 \u211d}\n    (v\u2081 : \u03b9\u2081 \u2192 F) (h\u2081 : \u2211 i in s\u2081, w\u2081 i = 0) {\u03b9\u2082 : Type*} {s\u2082 : finset \u03b9\u2082} {w\u2082 : \u03b9\u2082 \u2192 \u211d}\n    (v\u2082 : \u03b9\u2082 \u2192 F) (h\u2082 : \u2211 i in s\u2082, w\u2082 i = 0) :\n  \u27ea(\u2211 i\u2081 in s\u2081, w\u2081 i\u2081 \u2022 v\u2081 i\u2081), (\u2211 i\u2082 in s\u2082, w\u2082 i\u2082 \u2022 v\u2082 i\u2082)\u27eb_\u211d =\n    (-\u2211 i\u2081 in s\u2081, \u2211 i\u2082 in s\u2082, w\u2081 i\u2081 * w\u2082 i\u2082 * (\u2016v\u2081 i\u2081 - v\u2082 i\u2082\u2016 * \u2016v\u2081 i\u2081 - v\u2082 i\u2082\u2016)) / 2 :=\nby simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,\n            real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two,\n            \u2190div_sub_div_same, \u2190div_add_div_same, mul_sub_left_distrib, left_distrib,\n            finset.sum_sub_distrib, finset.sum_add_distrib, \u2190finset.mul_sum, \u2190finset.sum_mul,\n            h\u2081, h\u2082, zero_mul, mul_zero, finset.sum_const_zero, zero_add, zero_sub, finset.mul_sum,\n            neg_div, finset.sum_div, mul_div_assoc, mul_assoc]\n\nvariables (\ud835\udd5c)\n\n/-- The inner product as a sesquilinear map. -/\ndef inner\u209b\u2097 : E \u2192\u2097\u22c6[\ud835\udd5c] E \u2192\u2097[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk\u2082'\u209b\u2097 _ _ (\u03bb v w, \u27eav, w\u27eb) inner_add_left (\u03bb _ _ _, inner_smul_left _ _ _)\n  inner_add_right (\u03bb _ _ _, inner_smul_right _ _ _)\n\n@[simp] lemma inner\u209b\u2097_apply_coe (v : E) : \u21d1(inner\u209b\u2097 \ud835\udd5c v) = \u03bb w, \u27eav, w\u27eb := rfl\n\n@[simp] lemma inner\u209b\u2097_apply (v w : E) : inner\u209b\u2097 \ud835\udd5c v w = \u27eav, w\u27eb := rfl\n\n/-- The inner product as a continuous sesquilinear map. Note that `to_dual_map` (resp. `to_dual`)\nin `inner_product_space.dual` is a version of this given as a linear isometry (resp. linear\nisometric equivalence). -/\ndef innerSL : E \u2192L\u22c6[\ud835\udd5c] E \u2192L[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk_continuous\u2082 (inner\u209b\u2097 \ud835\udd5c) 1\n(\u03bb x y, by simp only [norm_inner_le_norm, one_mul, inner\u209b\u2097_apply])\n\n@[simp] lemma innerSL_apply_coe (v : E) : \u21d1(innerSL \ud835\udd5c v) = \u03bb w, \u27eav, w\u27eb := rfl\n\n@[simp] lemma innerSL_apply (v w : E) : innerSL \ud835\udd5c v w = \u27eav, w\u27eb := rfl\n\n/-- `innerSL` is an isometry. Note that the associated `linear_isometry` is defined in\n`inner_product_space.dual` as `to_dual_map`.  -/\n@[simp] lemma innerSL_apply_norm (x : E) : \u2016innerSL \ud835\udd5c x\u2016 = \u2016x\u2016 :=\nbegin\n  refine le_antisymm ((innerSL \ud835\udd5c x).op_norm_le_bound (norm_nonneg _)\n    (\u03bb y, norm_inner_le_norm _ _)) _,\n  cases eq_or_lt_of_le (norm_nonneg x) with h h,\n  { have : x = 0 := norm_eq_zero.mp (eq.symm h),\n    simp [this] },\n  { refine (mul_le_mul_right h).mp _,\n    calc \u2016x\u2016 * \u2016x\u2016 = \u2016x\u2016 ^ 2 : by ring\n    ... = re \u27eax, x\u27eb : norm_sq_eq_inner _\n    ... \u2264 abs \u27eax, x\u27eb : re_le_abs _\n    ... = \u2016\u27eax, x\u27eb\u2016 : by rw [\u2190is_R_or_C.norm_eq_abs]\n    ... \u2264 \u2016innerSL \ud835\udd5c x\u2016 * \u2016x\u2016 : (innerSL \ud835\udd5c x).le_op_norm _ }\nend\n\n/-- The inner product as a continuous sesquilinear map, with the two arguments flipped. -/\ndef innerSL_flip : E \u2192L[\ud835\udd5c] E \u2192L\u22c6[\ud835\udd5c] \ud835\udd5c :=\n@continuous_linear_map.flip\u2097\u1d62' \ud835\udd5c \ud835\udd5c \ud835\udd5c E E \ud835\udd5c _ _ _ _ _ _ _ _ _ (ring_hom.id \ud835\udd5c) (star_ring_end \ud835\udd5c) _ _\n  (innerSL \ud835\udd5c)\n\n@[simp] lemma innerSL_flip_apply (x y : E) : innerSL_flip \ud835\udd5c x y = \u27eay, x\u27eb := rfl\n\nvariables {\ud835\udd5c}\n\nnamespace continuous_linear_map\n\nvariables  {E' : Type*} [normed_add_comm_group E'] [inner_product_space \ud835\udd5c E']\n\n/-- Given `f : E \u2192L[\ud835\udd5c] E'`, construct the continuous sesquilinear form `\u03bb x y, \u27eax, A y\u27eb`, given\nas a continuous linear map. -/\ndef to_sesq_form : (E \u2192L[\ud835\udd5c] E') \u2192L[\ud835\udd5c] E' \u2192L\u22c6[\ud835\udd5c] E \u2192L[\ud835\udd5c] \ud835\udd5c :=\n\u2191((continuous_linear_map.flip\u2097\u1d62' E E' \ud835\udd5c\n  (star_ring_end \ud835\udd5c) (ring_hom.id \ud835\udd5c)).to_continuous_linear_equiv) \u2218L\n(continuous_linear_map.compSL E E' (E' \u2192L\u22c6[\ud835\udd5c] \ud835\udd5c) (ring_hom.id \ud835\udd5c) (ring_hom.id \ud835\udd5c) (innerSL_flip \ud835\udd5c))\n\n@[simp] lemma to_sesq_form_apply_coe (f : E \u2192L[\ud835\udd5c] E') (x : E') :\n  to_sesq_form f x = (innerSL \ud835\udd5c x).comp f := rfl\n\nlemma to_sesq_form_apply_norm_le {f : E \u2192L[\ud835\udd5c] E'} {v : E'} : \u2016to_sesq_form f v\u2016 \u2264 \u2016f\u2016 * \u2016v\u2016 :=\nbegin\n  refine op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _,\n  intro x,\n  have h\u2081 : \u2016f x\u2016 \u2264 \u2016f\u2016 * \u2016x\u2016 := le_op_norm _ _,\n  have h\u2082 := @norm_inner_le_norm \ud835\udd5c E' _ _ _ v (f x),\n  calc \u2016\u27eav, f x\u27eb\u2016 \u2264 \u2016v\u2016 * \u2016f x\u2016       :  h\u2082\n              ... \u2264 \u2016v\u2016 * (\u2016f\u2016 * \u2016x\u2016)  : mul_le_mul_of_nonneg_left h\u2081 (norm_nonneg v)\n              ... = \u2016f\u2016 * \u2016v\u2016 * \u2016x\u2016    : by ring,\nend\n\nend continuous_linear_map\n\n/-- When an inner product space `E` over `\ud835\udd5c` is considered as a real normed space, its inner\nproduct satisfies `is_bounded_bilinear_map`.\n\nIn order to state these results, we need a `normed_space \u211d E` instance. We will later establish\nsuch an instance by restriction-of-scalars, `inner_product_space.is_R_or_C_to_real \ud835\udd5c E`, but this\ninstance may be not definitionally equal to some other \u201cnatural\u201d instance. So, we assume\n`[normed_space \u211d E]`.\n-/\nlemma is_bounded_bilinear_map_inner [normed_space \u211d E] :\n  is_bounded_bilinear_map \u211d (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\n{ add_left := inner_add_left,\n  smul_left := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r x, algebra_map_eq_of_real, inner_smul_real_left],\n  add_right := inner_add_right,\n  smul_right := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r y, algebra_map_eq_of_real, inner_smul_real_right],\n  bound := \u27e81, zero_lt_one, \u03bb x y,\n    by { rw [one_mul], exact norm_inner_le_norm x y, }\u27e9 }\n\nend norm\n\nsection bessels_inequality\n\nvariables {\u03b9: Type*} (x : E) {v : \u03b9 \u2192 E}\n\n/-- Bessel's inequality for finite sums. -/\nlemma orthonormal.sum_inner_products_le {s : finset \u03b9} (hv : orthonormal \ud835\udd5c v) :\n  \u2211 i in s, \u2016\u27eav i, x\u27eb\u2016 ^ 2 \u2264 \u2016x\u2016 ^ 2 :=\nbegin\n  have h\u2082 : \u2211 i in s, \u2211 j in s, \u27eav i, x\u27eb * \u27eax, v j\u27eb * \u27eav j, v i\u27eb\n    = (\u2211 k in s, (\u27eav k, x\u27eb * \u27eax, v k\u27eb) : \ud835\udd5c),\n  { exact hv.inner_left_right_finset },\n  have h\u2083 : \u2200 z : \ud835\udd5c, re (z * conj (z)) = \u2016z\u2016 ^ 2,\n  { intro z,\n    simp only [mul_conj, norm_sq_eq_def'],\n    norm_cast, },\n  suffices hbf: \u2016x -  \u2211 i in s, \u27eav i, x\u27eb \u2022 (v i)\u2016 ^ 2 = \u2016x\u2016 ^ 2 - \u2211 i in s, \u2016\u27eav i, x\u27eb\u2016 ^ 2,\n  { rw [\u2190sub_nonneg, \u2190hbf],\n    simp only [norm_nonneg, pow_nonneg], },\n  rw [@norm_sub_sq \ud835\udd5c, sub_add],\n  simp only [@inner_product_space.norm_sq_eq_inner \ud835\udd5c, inner_sum],\n  simp only [sum_inner, two_mul, inner_smul_right, inner_conj_symm, \u2190mul_assoc, h\u2082, \u2190h\u2083,\n  inner_conj_symm, add_monoid_hom.map_sum, finset.mul_sum, \u2190finset.sum_sub_distrib, inner_smul_left,\n  add_sub_cancel'],\nend\n\n/-- Bessel's inequality. -/\nlemma orthonormal.tsum_inner_products_le (hv : orthonormal \ud835\udd5c v) :\n  \u2211' i, \u2016\u27eav i, x\u27eb\u2016 ^ 2 \u2264 \u2016x\u2016 ^ 2 :=\nbegin\n  refine tsum_le_of_sum_le' _ (\u03bb s, hv.sum_inner_products_le x),\n  simp only [norm_nonneg, pow_nonneg]\nend\n\n/-- The sum defined in Bessel's inequality is summable. -/\nlemma orthonormal.inner_products_summable (hv : orthonormal \ud835\udd5c v) : summable (\u03bb i, \u2016\u27eav i, x\u27eb\u2016 ^ 2) :=\nbegin\n  use \u2a06 s : finset \u03b9, \u2211 i in s, \u2016\u27eav i, x\u27eb\u2016 ^ 2,\n  apply has_sum_of_is_lub_of_nonneg,\n  { intro b,\n    simp only [norm_nonneg, pow_nonneg], },\n  { refine is_lub_csupr _,\n    use \u2016x\u2016 ^ 2,\n    rintro y \u27e8s, rfl\u27e9,\n    exact hv.sum_inner_products_le x }\nend\n\nend bessels_inequality\n\n/-- A field `\ud835\udd5c` satisfying `is_R_or_C` is itself a `\ud835\udd5c`-inner product space. -/\ninstance is_R_or_C.inner_product_space : inner_product_space \ud835\udd5c \ud835\udd5c :=\n{ inner := \u03bb x y, conj x * y,\n  norm_sq_eq_inner := \u03bb x,\n    by { unfold inner, rw [mul_comm, mul_conj, of_real_re, norm_sq_eq_def'] },\n  conj_symm := \u03bb x y, by simp only [mul_comm, map_mul, star_ring_end_self_apply],\n  add_left := \u03bb x y z, by simp only [add_mul, map_add],\n  smul_left := \u03bb x y z, by simp only [mul_assoc, smul_eq_mul, map_mul] }\n\n@[simp] lemma is_R_or_C.inner_apply (x y : \ud835\udd5c) : \u27eax, y\u27eb = (conj x) * y := rfl\n\n/-! ### Inner product space structure on subspaces -/\n\n/-- Induced inner product on a submodule. -/\ninstance submodule.inner_product_space (W : submodule \ud835\udd5c E) : inner_product_space \ud835\udd5c W :=\n{ inner             := \u03bb x y, \u27ea(x:E), (y:E)\u27eb,\n  conj_symm         := \u03bb _ _, inner_conj_symm _ _,\n  norm_sq_eq_inner  := \u03bb x, norm_sq_eq_inner (x : E),\n  add_left          := \u03bb _ _ _, inner_add_left _ _ _,\n  smul_left         := \u03bb _ _ _, inner_smul_left _ _ _,\n  ..submodule.normed_space W }\n\n/-- The inner product on submodules is the same as on the ambient space. -/\n@[simp] lemma submodule.coe_inner (W : submodule \ud835\udd5c E) (x y : W) : \u27eax, y\u27eb = \u27ea(x:E), \u2191y\u27eb := rfl\n\nlemma orthonormal.cod_restrict {\u03b9 : Type*} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v)\n  (s : submodule \ud835\udd5c E) (hvs : \u2200 i, v i \u2208 s) :\n  @orthonormal \ud835\udd5c s _ _ _ \u03b9 (set.cod_restrict v s hvs) :=\ns.subtype\u2097\u1d62.orthonormal_comp_iff.mp hv\n\nlemma orthonormal_span {\u03b9 : Type*} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  @orthonormal \ud835\udd5c (submodule.span \ud835\udd5c (set.range v)) _ _ _ \u03b9\n    (\u03bb i : \u03b9, \u27e8v i, submodule.subset_span (set.mem_range_self i)\u27e9) :=\nhv.cod_restrict (submodule.span \ud835\udd5c (set.range v))\n  (\u03bb i, submodule.subset_span (set.mem_range_self i))\n\n/-! ### Families of mutually-orthogonal subspaces of an inner product space -/\n\nsection orthogonal_family\nvariables {\u03b9 : Type*} [dec_\u03b9 : decidable_eq \u03b9] (\ud835\udd5c)\nopen_locale direct_sum\n\n/-- An indexed family of mutually-orthogonal subspaces of an inner product space `E`.\n\nThe simple way to express this concept would be as a condition on `V : \u03b9 \u2192 submodule \ud835\udd5c E`.  We\nWe instead implement it as a condition on a family of inner product spaces each equipped with an\nisometric embedding into `E`, thus making it a property of morphisms rather than subobjects.\n\nThis definition is less lightweight, but allows for better definitional properties when the inner\nproduct space structure on each of the submodules is important -- for example, when considering\ntheir Hilbert sum (`pi_lp V 2`).  For example, given an orthonormal set of vectors `v : \u03b9 \u2192 E`,\nwe have an associated orthogonal family of one-dimensional subspaces of `E`, which it is convenient\nto be able to discuss using `\u03b9 \u2192 \ud835\udd5c` rather than `\u03a0 i : \u03b9, span \ud835\udd5c (v i)`. -/\ndef orthogonal_family (G : \u03b9 \u2192 Type*)\n  [\u03a0 i, normed_add_comm_group (G i)] [\u03a0 i, inner_product_space \ud835\udd5c (G i)] (V : \u03a0 i, G i \u2192\u2097\u1d62[\ud835\udd5c] E) :\n  Prop :=\n\u2200 \u2983i j\u2984, i \u2260 j \u2192 \u2200 v : G i, \u2200 w : G j, \u27eaV i v, V j w\u27eb = 0\n\nvariables {\ud835\udd5c} {G : \u03b9 \u2192 Type*}\n  [\u03a0 i, normed_add_comm_group (G i)] [\u03a0 i, inner_product_space \ud835\udd5c (G i)] {V : \u03a0 i, G i \u2192\u2097\u1d62[\ud835\udd5c] E}\n  (hV : orthogonal_family \ud835\udd5c G V) [dec_V : \u03a0 i (x : G i), decidable (x \u2260 0)]\n\nlemma orthonormal.orthogonal_family {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  orthogonal_family \ud835\udd5c (\u03bb i : \u03b9, \ud835\udd5c)\n    (\u03bb i, linear_isometry.to_span_singleton \ud835\udd5c E (hv.1 i)) :=\n\u03bb i j hij a b, by simp [inner_smul_left, inner_smul_right, hv.2 hij]\n\ninclude hV dec_\u03b9\nlemma orthogonal_family.eq_ite {i j : \u03b9} (v : G i) (w : G j) :\n  \u27eaV i v, V j w\u27eb = ite (i = j) \u27eaV i v, V j w\u27eb 0 :=\nbegin\n  split_ifs,\n  { refl },\n  { exact hV h v w }\nend\n\ninclude dec_V\nlemma orthogonal_family.inner_right_dfinsupp (l : \u2a01 i, G i) (i : \u03b9) (v : G i) :\n  \u27eaV i v, l.sum (\u03bb j, V j)\u27eb = \u27eav, l i\u27eb :=\ncalc \u27eaV i v, l.sum (\u03bb j, V j)\u27eb\n    = l.sum (\u03bb j, \u03bb w, \u27eaV i v, V j w\u27eb) : dfinsupp.inner_sum (\u03bb j, V j) l (V i v)\n... = l.sum (\u03bb j, \u03bb w, ite (i=j) \u27eaV i v, V j w\u27eb 0) :\n  congr_arg l.sum $ funext $ \u03bb j, funext $ hV.eq_ite v\n... = \u27eav, l i\u27eb :\nbegin\n  simp only [dfinsupp.sum, submodule.coe_inner, finset.sum_ite_eq, ite_eq_left_iff,\n    dfinsupp.mem_support_to_fun],\n  split_ifs with h h,\n  { simp only [linear_isometry.inner_map_map] },\n  { simp only [of_not_not h, inner_zero_right] },\nend\nomit dec_\u03b9 dec_V\n\nlemma orthogonal_family.inner_right_fintype [fintype \u03b9] (l : \u03a0 i, G i) (i : \u03b9) (v : G i) :\n  \u27eaV i v, \u2211 j : \u03b9, V j (l j)\u27eb = \u27eav, l i\u27eb :=\nby classical;\ncalc \u27eaV i v, \u2211 j : \u03b9, V j (l j)\u27eb\n    = \u2211 j : \u03b9, \u27eaV i v, V j (l j)\u27eb: by rw inner_sum\n... = \u2211 j, ite (i = j) \u27eaV i v, V j (l j)\u27eb 0 :\n  congr_arg (finset.sum finset.univ) $ funext $ \u03bb j, (hV.eq_ite v (l j))\n... = \u27eav, l i\u27eb : by simp only [finset.sum_ite_eq, finset.mem_univ, (V i).inner_map_map, if_true]\n\nlemma orthogonal_family.inner_sum (l\u2081 l\u2082 : \u03a0 i, G i) (s : finset \u03b9) :\n  \u27ea\u2211 i in s, V i (l\u2081 i), \u2211 j in s, V j (l\u2082 j)\u27eb = \u2211 i in s, \u27eal\u2081 i, l\u2082 i\u27eb :=\nby classical;\ncalc \u27ea\u2211 i in s, V i (l\u2081 i), \u2211 j in s, V j (l\u2082 j)\u27eb\n    = \u2211 j in s, \u2211 i in s, \u27eaV i (l\u2081 i), V j (l\u2082 j)\u27eb : by simp only [sum_inner, inner_sum]\n... = \u2211 j in s, \u2211 i in s, ite (i = j) \u27eaV i (l\u2081 i), V j (l\u2082 j)\u27eb 0 :\nbegin\n  congr' with i,\n  congr' with j,\n  apply hV.eq_ite,\nend\n... = \u2211 i in s, \u27eal\u2081 i, l\u2082 i\u27eb : by simp only [finset.sum_ite_of_true,\n  finset.sum_ite_eq', linear_isometry.inner_map_map, imp_self, implies_true_iff]\n\nlemma orthogonal_family.norm_sum (l : \u03a0 i, G i) (s : finset \u03b9) :\n  \u2016\u2211 i in s, V i (l i)\u2016 ^ 2 = \u2211 i in s, \u2016l i\u2016 ^ 2 :=\nbegin\n  have : (\u2016\u2211 i in s, V i (l i)\u2016 ^ 2 : \ud835\udd5c) = \u2211 i in s, \u2016l i\u2016 ^ 2,\n  { simp only [\u2190 inner_self_eq_norm_sq_to_K, hV.inner_sum] },\n  exact_mod_cast this,\nend\n\n/-- The composition of an orthogonal family of subspaces with an injective function is also an\northogonal family. -/\nlemma orthogonal_family.comp {\u03b3 : Type*} {f : \u03b3 \u2192 \u03b9} (hf : function.injective f) :\n  orthogonal_family \ud835\udd5c (\u03bb g, G (f g)) (\u03bb g, V (f g)) :=\n\u03bb i j hij v w, hV (hf.ne hij) v w\n\nlemma orthogonal_family.orthonormal_sigma_orthonormal {\u03b1 : \u03b9 \u2192 Type*} {v_family : \u03a0 i, (\u03b1 i) \u2192 G i}\n  (hv_family : \u2200 i, orthonormal \ud835\udd5c (v_family i)) :\n  orthonormal \ud835\udd5c (\u03bb a : \u03a3 i, \u03b1 i, V a.1 (v_family a.1 a.2)) :=\nbegin\n  split,\n  { rintros \u27e8i, v\u27e9,\n    simpa only [linear_isometry.norm_map] using (hv_family i).left v },\n  rintros \u27e8i, v\u27e9 \u27e8j, w\u27e9 hvw,\n  by_cases hij : i = j,\n  { subst hij,\n    have : v \u2260 w := \u03bb h, by { subst h, exact hvw rfl },\n    simpa only [linear_isometry.inner_map_map] using (hv_family i).2 this },\n  { exact hV hij (v_family i v) (v_family j w) }\nend\n\ninclude dec_\u03b9\nlemma orthogonal_family.norm_sq_diff_sum (f : \u03a0 i, G i) (s\u2081 s\u2082 : finset \u03b9) :\n  \u2016\u2211 i in s\u2081, V i (f i) - \u2211 i in s\u2082, V i (f i)\u2016 ^ 2\n  = \u2211 i in s\u2081 \\ s\u2082, \u2016f i\u2016 ^ 2 + \u2211 i in s\u2082 \\ s\u2081, \u2016f i\u2016 ^ 2 :=\nbegin\n  rw [\u2190 finset.sum_sdiff_sub_sum_sdiff, sub_eq_add_neg, \u2190 finset.sum_neg_distrib],\n  let F : \u03a0 i, G i := \u03bb i, if i \u2208 s\u2081 then f i else - (f i),\n  have hF\u2081 : \u2200 i \u2208 s\u2081 \\ s\u2082, F i = f i := \u03bb i hi, if_pos (finset.sdiff_subset _ _ hi),\n  have hF\u2082 : \u2200 i \u2208 s\u2082 \\ s\u2081, F i = - f i := \u03bb i hi, if_neg (finset.mem_sdiff.mp hi).2,\n  have hF : \u2200 i, \u2016F i\u2016 = \u2016f i\u2016,\n  { intros i,\n    dsimp only [F],\n    split_ifs;\n    simp only [eq_self_iff_true, norm_neg], },\n  have : \u2016\u2211 i in s\u2081 \\ s\u2082, V i (F i) + \u2211 i in s\u2082 \\ s\u2081, V i (F i)\u2016 ^ 2 =\n    \u2211 i in s\u2081 \\ s\u2082, \u2016F i\u2016 ^ 2 + \u2211 i in s\u2082 \\ s\u2081, \u2016F i\u2016 ^ 2,\n  { have hs : disjoint (s\u2081 \\ s\u2082) (s\u2082 \\ s\u2081) := disjoint_sdiff_sdiff,\n    simpa only [finset.sum_union hs] using hV.norm_sum F (s\u2081 \\ s\u2082 \u222a s\u2082 \\ s\u2081) },\n  convert this using 4,\n  { refine finset.sum_congr rfl (\u03bb i hi, _),\n    simp only [hF\u2081 i hi] },\n  { refine finset.sum_congr rfl (\u03bb i hi, _),\n    simp only [hF\u2082 i hi, linear_isometry.map_neg] },\n  { simp only [hF] },\n  { simp only [hF] },\nend\n\nomit dec_\u03b9\n\n/-- A family `f` of mutually-orthogonal elements of `E` is summable, if and only if\n`(\u03bb i, \u2016f i\u2016 ^ 2)` is summable. -/\nlemma orthogonal_family.summable_iff_norm_sq_summable [complete_space E] (f : \u03a0 i, G i) :\n  summable (\u03bb i, V i (f i)) \u2194 summable (\u03bb i, \u2016f i\u2016 ^ 2) :=\nbegin\n  classical,\n  simp only [summable_iff_cauchy_seq_finset, normed_add_comm_group.cauchy_seq_iff,\n    real.norm_eq_abs],\n  split,\n  { intros hf \u03b5 h\u03b5,\n    obtain \u27e8a, H\u27e9 := hf _ (sqrt_pos.mpr h\u03b5),\n    use a,\n    intros s\u2081 hs\u2081 s\u2082 hs\u2082,\n    rw \u2190 finset.sum_sdiff_sub_sum_sdiff,\n    refine (_root_.abs_sub _ _).trans_lt _,\n    have : \u2200 i, 0 \u2264 \u2016f i\u2016 ^ 2 := \u03bb i : \u03b9, sq_nonneg _,\n    simp only [finset.abs_sum_of_nonneg' this],\n    have : \u2211 i in s\u2081 \\ s\u2082, \u2016f i\u2016 ^ 2 + \u2211 i in s\u2082 \\ s\u2081, \u2016f i\u2016 ^ 2 < (sqrt \u03b5) ^ 2,\n    { rw [\u2190 hV.norm_sq_diff_sum, sq_lt_sq,\n        _root_.abs_of_nonneg (sqrt_nonneg _), _root_.abs_of_nonneg (norm_nonneg _)],\n      exact H s\u2081 hs\u2081 s\u2082 hs\u2082 },\n    have h\u03b7 := sq_sqrt (le_of_lt h\u03b5),\n    linarith },\n  { intros hf \u03b5 h\u03b5,\n    have h\u03b5' : 0 < \u03b5 ^ 2 / 2 := half_pos (sq_pos_of_pos h\u03b5),\n    obtain \u27e8a, H\u27e9 := hf _ h\u03b5',\n    use a,\n    intros s\u2081 hs\u2081 s\u2082 hs\u2082,\n    refine (abs_lt_of_sq_lt_sq' _ (le_of_lt h\u03b5)).2,\n    have has : a \u2264 s\u2081 \u2293 s\u2082 := le_inf hs\u2081 hs\u2082,\n    rw hV.norm_sq_diff_sum,\n    have Hs\u2081 : \u2211 (x : \u03b9) in s\u2081 \\ s\u2082, \u2016f x\u2016 ^ 2 < \u03b5 ^ 2 / 2,\n    { convert H _ hs\u2081 _ has,\n      have : s\u2081 \u2293 s\u2082 \u2286 s\u2081 := finset.inter_subset_left _ _,\n      rw [\u2190 finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],\n      { simp },\n      { exact \u03bb i, sq_nonneg _ } },\n    have Hs\u2082 : \u2211 (x : \u03b9) in s\u2082 \\ s\u2081, \u2016f x\u2016 ^ 2 < \u03b5 ^ 2 /2,\n    { convert H _ hs\u2082 _ has,\n      have : s\u2081 \u2293 s\u2082 \u2286 s\u2082 := finset.inter_subset_right _ _,\n      rw [\u2190 finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],\n      { simp },\n      { exact \u03bb i, sq_nonneg _ } },\n    linarith },\nend\n\nomit hV\n\n/-- An orthogonal family forms an independent family of subspaces; that is, any collection of\nelements each from a different subspace in the family is linearly independent. In particular, the\npairwise intersections of elements of the family are 0. -/\nlemma orthogonal_family.independent {V : \u03b9 \u2192 submodule \ud835\udd5c E}\n  (hV : orthogonal_family \ud835\udd5c (\u03bb i, V i) (\u03bb i, (V i).subtype\u2097\u1d62)) :\n  complete_lattice.independent V :=\nbegin\n  classical,\n  apply complete_lattice.independent_of_dfinsupp_lsum_injective,\n  rw [\u2190 @linear_map.ker_eq_bot _ _ _ _ _ _ (direct_sum.add_comm_group (\u03bb i, V i)),\n    submodule.eq_bot_iff],\n  intros v hv,\n  rw linear_map.mem_ker at hv,\n  ext i,\n  suffices : \u27ea(v i : E), v i\u27eb = 0,\n  { simpa only [inner_self_eq_zero] using this },\n  calc \u27ea(v i : E), v i\u27eb = \u27ea(v i : E), dfinsupp.lsum \u2115 (\u03bb i, (V i).subtype) v\u27eb :\n    by simpa only [dfinsupp.sum_add_hom_apply, dfinsupp.lsum_apply_apply]\n      using (hV.inner_right_dfinsupp v i (v i)).symm\n  ... = 0 : by simp only [hv, inner_zero_right],\nend\n\ninclude dec_\u03b9\nlemma direct_sum.is_internal.collected_basis_orthonormal {V : \u03b9 \u2192 submodule \ud835\udd5c E}\n  (hV : orthogonal_family \ud835\udd5c (\u03bb i, V i) (\u03bb i, (V i).subtype\u2097\u1d62))\n  (hV_sum : direct_sum.is_internal (\u03bb i, V i))\n  {\u03b1 : \u03b9 \u2192 Type*}\n  {v_family : \u03a0 i, basis (\u03b1 i) \ud835\udd5c (V i)} (hv_family : \u2200 i, orthonormal \ud835\udd5c (v_family i)) :\n  orthonormal \ud835\udd5c (hV_sum.collected_basis v_family) :=\nby simpa only [hV_sum.collected_basis_coe] using hV.orthonormal_sigma_orthonormal hv_family\n\nend orthogonal_family\n\nsection is_R_or_C_to_real\n\nvariables {G : Type*}\n\nvariables (\ud835\udd5c E)\ninclude \ud835\udd5c\n\n/-- A general inner product implies a real inner product. This is not registered as an instance\nsince it creates problems with the case `\ud835\udd5c = \u211d`. -/\ndef has_inner.is_R_or_C_to_real : has_inner \u211d E :=\n{ inner := \u03bb x y, re \u27eax, y\u27eb }\n\n/-- A general inner product space structure implies a real inner product structure. This is not\nregistered as an instance since it creates problems with the case `\ud835\udd5c = \u211d`, but in can be used in a\nproof to obtain a real inner product space structure from a given `\ud835\udd5c`-inner product space\nstructure. -/\ndef inner_product_space.is_R_or_C_to_real : inner_product_space \u211d E :=\n{ norm_sq_eq_inner := norm_sq_eq_inner,\n  conj_symm := \u03bb x y, inner_re_symm _ _,\n  add_left := \u03bb x y z, by\n  { change re \u27eax + y, z\u27eb = re \u27eax, z\u27eb + re \u27eay, z\u27eb,\n    simp only [inner_add_left, map_add] },\n  smul_left := \u03bb x y r, by\n  { change re \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r * re \u27eax, y\u27eb,\n    simp only [inner_smul_left, conj_of_real, of_real_mul_re] },\n  ..has_inner.is_R_or_C_to_real \ud835\udd5c E,\n  ..normed_space.restrict_scalars \u211d \ud835\udd5c E }\n\nvariable {E}\n\nlemma real_inner_eq_re_inner (x y : E) :\n  @has_inner.inner \u211d E (has_inner.is_R_or_C_to_real \ud835\udd5c E) x y = re \u27eax, y\u27eb := rfl\n\nlemma real_inner_I_smul_self (x : E) :\n  @has_inner.inner \u211d E (has_inner.is_R_or_C_to_real \ud835\udd5c E) x ((I : \ud835\udd5c) \u2022 x) = 0 :=\nby simp [real_inner_eq_re_inner, inner_smul_right]\n\nomit \ud835\udd5c\n\n/-- A complex inner product implies a real inner product -/\ninstance inner_product_space.complex_to_real\n  [normed_add_comm_group G] [inner_product_space \u2102 G] : inner_product_space \u211d G :=\ninner_product_space.is_R_or_C_to_real \u2102 G\n\n@[simp] protected lemma complex.inner (w z : \u2102) : \u27eaw, z\u27eb_\u211d = (conj w * z).re := rfl\n\n/-- The inner product on an inner product space of dimension 2 can be evaluated in terms\nof a complex-number representation of the space. -/\nlemma inner_map_complex [normed_add_comm_group G] [inner_product_space \u211d G]\n  (f : G \u2243\u2097\u1d62[\u211d] \u2102) (x y : G) :\n  \u27eax, y\u27eb_\u211d = (conj (f x) * f y).re :=\nby rw [\u2190 complex.inner, f.inner_map_map]\n\nend is_R_or_C_to_real\n\nsection continuous\n\n/-!\n### Continuity of the inner product\n-/\n\nlemma continuous_inner : continuous (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\nbegin\n  letI : inner_product_space \u211d E := inner_product_space.is_R_or_C_to_real \ud835\udd5c E,\n  exact is_bounded_bilinear_map_inner.continuous\nend\n\nvariables {\u03b1 : Type*}\n\nlemma filter.tendsto.inner {f g : \u03b1 \u2192 E} {l : filter \u03b1} {x y : E} (hf : tendsto f l (\ud835\udcdd x))\n  (hg : tendsto g l (\ud835\udcdd y)) :\n  tendsto (\u03bb t, \u27eaf t, g t\u27eb) l (\ud835\udcdd \u27eax, y\u27eb) :=\n(continuous_inner.tendsto _).comp (hf.prod_mk_nhds hg)\n\nvariables [topological_space \u03b1] {f g : \u03b1 \u2192 E} {x : \u03b1} {s : set \u03b1}\n\ninclude \ud835\udd5c\n\nlemma continuous_within_at.inner (hf : continuous_within_at f s x)\n  (hg : continuous_within_at g s x) :\n  continuous_within_at (\u03bb t, \u27eaf t, g t\u27eb) s x :=\nhf.inner hg\n\nlemma continuous_at.inner (hf : continuous_at f x) (hg : continuous_at g x) :\n  continuous_at (\u03bb t, \u27eaf t, g t\u27eb) x :=\nhf.inner hg\n\nlemma continuous_on.inner (hf : continuous_on f s) (hg : continuous_on g s) :\n  continuous_on (\u03bb t, \u27eaf t, g t\u27eb) s :=\n\u03bb x hx, (hf x hx).inner (hg x hx)\n\n@[continuity]\nlemma continuous.inner (hf : continuous f) (hg : continuous g) : continuous (\u03bb t, \u27eaf t, g t\u27eb) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, hf.continuous_at.inner hg.continuous_at\n\nend continuous\n\nsection re_apply_inner_self\n\n/-- Extract a real bilinear form from an operator `T`, by taking the pairing `\u03bb x, re \u27eaT x, x\u27eb`. -/\ndef continuous_linear_map.re_apply_inner_self (T : E \u2192L[\ud835\udd5c] E) (x : E) : \u211d := re \u27eaT x, x\u27eb\n\nlemma continuous_linear_map.re_apply_inner_self_apply (T : E \u2192L[\ud835\udd5c] E) (x : E) :\n  T.re_apply_inner_self x = re \u27eaT x, x\u27eb :=\nrfl\n\nlemma continuous_linear_map.re_apply_inner_self_continuous (T : E \u2192L[\ud835\udd5c] E) :\n  continuous T.re_apply_inner_self :=\nre_clm.continuous.comp $ T.continuous.inner continuous_id\n\nlemma continuous_linear_map.re_apply_inner_self_smul (T : E \u2192L[\ud835\udd5c] E) (x : E) {c : \ud835\udd5c} :\n  T.re_apply_inner_self (c \u2022 x) = \u2016c\u2016 ^ 2 * T.re_apply_inner_self x :=\nby simp only [continuous_linear_map.map_smul, continuous_linear_map.re_apply_inner_self_apply,\n  inner_smul_left, inner_smul_right, \u2190 mul_assoc, mul_conj, norm_sq_eq_def', \u2190 smul_re,\n  algebra.smul_def (\u2016c\u2016 ^ 2) \u27eaT x, x\u27eb, algebra_map_eq_of_real]\n\nend re_apply_inner_self\n\nnamespace uniform_space.completion\n\nopen uniform_space function\n\ninstance {\ud835\udd5c' E' : Type*} [topological_space \ud835\udd5c'] [uniform_space E'] [has_inner \ud835\udd5c' E'] :\n  has_inner \ud835\udd5c' (completion E') :=\n{ inner := curry $ (dense_inducing_coe.prod dense_inducing_coe).extend (uncurry inner) }\n\n@[simp] lemma inner_coe (a b : E) :\n  inner (a : completion E) (b : completion E) = (inner a b : \ud835\udd5c) :=\n(dense_inducing_coe.prod dense_inducing_coe).extend_eq\n  (continuous_inner : continuous (uncurry inner : E \u00d7 E \u2192 \ud835\udd5c)) (a, b)\n\nprotected lemma continuous_inner :\n  continuous (uncurry inner : completion E \u00d7 completion E \u2192 \ud835\udd5c) :=\nbegin\n  let inner' : E \u2192+ E \u2192+ \ud835\udd5c :=\n  { to_fun := \u03bb x, (inner\u209b\u2097 \ud835\udd5c x).to_add_monoid_hom,\n    map_zero' := by ext x; exact inner_zero_left _,\n    map_add' := \u03bb x y, by ext z; exact inner_add_left _ _ _ },\n  have : continuous (\u03bb p : E \u00d7 E, inner' p.1 p.2) := continuous_inner,\n  rw [completion.has_inner, uncurry_curry _],\n  change continuous (((dense_inducing_to_compl E).prod (dense_inducing_to_compl E)).extend\n    (\u03bb p : E \u00d7 E, inner' p.1 p.2)),\n  exact (dense_inducing_to_compl E).extend_Z_bilin (dense_inducing_to_compl E) this,\nend\n\nprotected lemma continuous.inner {\u03b1 : Type*} [topological_space \u03b1]\n  {f g : \u03b1 \u2192 completion E} (hf : continuous f) (hg : continuous g) :\n  continuous (\u03bb x : \u03b1, inner (f x) (g x) : \u03b1 \u2192 \ud835\udd5c) :=\nuniform_space.completion.continuous_inner.comp (hf.prod_mk hg : _)\n\ninstance : inner_product_space \ud835\udd5c (completion E) :=\n{ norm_sq_eq_inner := \u03bb x, completion.induction_on x\n    (is_closed_eq\n      (continuous_norm.pow 2)\n      (continuous_re.comp (continuous.inner continuous_id' continuous_id')))\n    (\u03bb a, by simp only [norm_coe, inner_coe, inner_self_eq_norm_sq]),\n  conj_symm := \u03bb x y, completion.induction_on\u2082 x y\n    (is_closed_eq\n      (continuous_conj.comp (continuous.inner continuous_snd continuous_fst))\n      (continuous.inner continuous_fst continuous_snd))\n    (\u03bb a b, by simp only [inner_coe, inner_conj_symm]),\n  add_left := \u03bb x y z, completion.induction_on\u2083 x y z\n    (is_closed_eq\n      (continuous.inner (continuous_fst.add (continuous_fst.comp continuous_snd))\n        (continuous_snd.comp continuous_snd))\n      ((continuous.inner continuous_fst (continuous_snd.comp continuous_snd)).add\n        (continuous.inner (continuous_fst.comp continuous_snd)\n          (continuous_snd.comp continuous_snd))))\n    (\u03bb a b c, by simp only [\u2190 coe_add, inner_coe, inner_add_left]),\n  smul_left := \u03bb x y c, completion.induction_on\u2082 x y\n    (is_closed_eq\n      (continuous.inner (continuous_fst.const_smul c) continuous_snd)\n      ((continuous_mul_left _).comp (continuous.inner continuous_fst continuous_snd)))\n    (\u03bb a b, by simp only [\u2190 coe_smul c a, inner_coe, inner_smul_left]) }\n\nend uniform_space.completion\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/inner_product_space/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.745673607392343}}
{"text": "/-\nPractice with predicate logic in Lean \n-/\n\nvariable {\u03b1 : Type} (P Q : \u03b1 \u2192 Prop) \n\ntheorem prob01 (a\u2080 : \u03b1) (h : \u2200 a, P a) : \u2203 a, P a := sorry \n\ntheorem prob02 (h : \u2203 a, P a \u2227 \u00ac Q a) (h : \u2200 a, P a \u2192 Q a) : False := sorry \n\ntheorem prob03 (a a' : \u03b1) (h : a = a') (h' : P a) : P a' := sorry \n\n", "meta": {"author": "UofSC-Spring-2023-SCHC-411-H01", "repo": "quiz03", "sha": "f159c7f72a8f89547a472a422484ee824c31b7f5", "save_path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-quiz03", "path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-quiz03/quiz03-f159c7f72a8f89547a472a422484ee824c31b7f5/Quiz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9626731083722525, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.745670589118176}}
{"text": "import .topologia\nimport .metrics\nimport data.set.finite\nimport data.real.basic -- for metrics\n\nopen set\nopen topological_space\n\nnoncomputable theory\n\n/- Now it is quite easy to give a topology on the product of a pair of\n   topological spaces. -/\ninstance prod.topological_space (X Y : Type) [topological_space X]\n  [topological_space Y] : topological_space (X \u00d7 Y) :=\ntopological_space.generate_from {U | \u2203 (Ux : set X) (Uy : set Y)\n  (hx : is_open Ux) (hy : is_open Uy), U = set.prod Ux Uy}\n\nlemma is_open_prod (X Y : Type) [topological_space X] [topological_space Y]\n {U : set X} {V : set Y} (hU : is_open U) (hV : is_open V) : is_open (U.prod V) :=\nbegin\n  fconstructor,\n  simp,\n  exact \u27e8U, hU, \u27e8V, \u27e8hV,rfl\u27e9\u27e9\u27e9,\nend\n\nlemma is_open_prod_iff {X Y : Type} [topological_space X] [topological_space Y]\n  {s : set (X \u00d7 Y)} :\n  is_open s \u2194 (\u2200 (ab : X \u00d7 Y), ab \u2208 s \u2192 \u2203u v, is_open u \u2227 is_open v \u2227\n  ab.1 \u2208 u \u2227 ab.2 \u2208 v \u2227 set.prod u v \u2286 s) := \n  begin\n    split,\n    {\n      intros h_s ab h_ab,\n      induction h_s with w hw \u212c hh h\u2081 h\u2082 h\u2083 h\u2084 h\u2085 h\u2086 h\u2087,\n      {\n        let h := (univ: set X).prod (univ: set Y),\n        exact \u27e8univ, univ, univ_mem, univ_mem, trivial, trivial, h.subset_univ\u27e9,\n      },\n      {\n        rcases hw with \u27e8w_x, \u27e8w_y, \u27e8h_x, \u27e8h_y, hh\u27e9\u27e9\u27e9\u27e9,\n        use w_x, \n        use w_y,\n        repeat {split},\n        all_goals {try {finish} },\n      },\n      {\n        rcases h_ab with \u27e8U, hU_1, hU_2\u27e9,\n        let h1 := h\u2081 U hU_1 hU_2,\n        norm_num at h1,\n        obtain \u27e8u, h_u\u27e9 := h1,\n        cases h_u with is_open_u h_uv,\n        obtain \u27e8v, h_v\u27e9 := h_uv,\n        use u, use v,\n        repeat {split},\n        all_goals {try {tauto}},\n        intros a ha,\n        use U,\n        tauto,\n      },\n      {\n        cases h_ab,\n        have h1 : \u2203 (u : set X) (v : set Y), is_open u \u2227 is_open v \u2227 ab.1 \u2208 u \u2227 ab.2 \u2208 v \u2227 u.prod v \u2286 h\u2082,\n        {\n          apply h\u2086,\n          tauto,\n        },\n        have h2 : \u2203 (u : set X) (v : set Y), is_open u \u2227 is_open v \u2227 ab.1 \u2208 u \u2227 ab.2 \u2208 v \u2227 u.prod v \u2286 h\u2083,\n        {\n          apply h\u2087,\n          tauto,\n        },\n        rcases h1 with \u27e8x1, y1, is_open_x1, is_open_y1, a_in_x1, b_in_y1, prod_in_h2\u27e9,\n        rcases h2 with \u27e8x2, y2, is_open_x2, is_open_y2, a_in_x2, b_in_y2, prod_in_h3\u27e9,\n        use x1 \u2229 x2,\n        use y1 \u2229 y2,\n        repeat {split},\n        all_goals {\n          try {apply topological_space.inter},\n          try {tauto},\n          try {assumption},\n        },\n        intros xy h_xy,\n        have h1: (x1 \u2229 x2).prod (y1 \u2229 y2) \u2286 x1.prod y1,\n          by simp [\u2190prod_inter_prod],\n        have h2: (x1 \u2229 x2).prod (y1 \u2229 y2) \u2286 x2.prod y2,\n          by simp [\u2190prod_inter_prod],\n        split;\n        tauto,\n      }\n    },\n    {\n      intro h,\n     let Opens : set (set (X \u00d7 Y)):=\n       { uv | \u2203 (u: set X) (v : set Y), uv = (set.prod u v) \u2227 is_open u \u2227 is_open v \u2227 (set.prod u v) \u2286 s},\n     have h_s : s = \u22c3\u2080 Opens,\n     begin\n       ext1,\n       split,\n       {\n         cases x with x y,\n         intro h_xy,\n         norm_num,\n         have hh := h (x, y) h_xy,\n         obtain \u27e8u, v, is_open_u, is_open_v, x_in_u, y_in_v, uv_in_s\u27e9 := hh,\n         use set.prod u v,\n         use u,\n         use v,\n         tauto,\n         finish,\n    },\n       {\n         intro h_Opens,\n         obtain \u27e8U, \u27e8x, y, U_eq_xy, is_open_x, is_open_y, xy_subset_s\u27e9, x_in_U\u27e9 := h_Opens,\n         apply xy_subset_s,\n         finish,\n       }\n     end,\n     rw h_s,\n     apply topological_space.union,\n     intros B hB,\n     simp at *,\n     obtain \u27e8x, y, B_is_xy, is_open_x, is_open_y, h_xy\u27e9 := hB,\n     fconstructor,\n     norm_num,\n     use x,\n     split,\n     exact is_open_x,\n     use y,\n     split; assumption,\n    },\n  end\n\nnamespace metric_space\nopen metric_space_basic\n\nlemma is_open_prod_balls {X Y : Type} (r : \u211d) [metric_space X] [metric_space Y]\n  (xy : X \u00d7 Y) : is_open {zt : X \u00d7 Y | dist xy.1 zt.1 < r \u2227\n  dist xy.2 zt.2 < r} :=\nbegin\n  change is_open ({x : X | dist xy.1 x < r}.prod \n  {y : Y | dist xy.2 y < r}),\n  apply is_open_prod;\n  apply open_of_ball,\nend\n\n/- Now lets define the product of two metric spaces properly -/\ninstance {X Y : Type} [metric_space X] [metric_space Y] : metric_space (X \u00d7 Y) :=\n{ compatible :=\n  begin\n    intro U,\n    split,\n    {\n      intros hU xy hxy,\n      have H := is_open_prod_iff.1 hU xy hxy,\n      obtain \u27e8u, v, \u27e8hu, hv, hxyu, hxyv, huvU\u27e9\u27e9 := H,\n      have hu' : \u2203 ru, (0 < ru) \u2227 (ball xy.fst ru \u2286 u)\n        := (compatible u).mp hu xy.fst hxyu,\n      have hv' : \u2203 rv, (0 < rv) \u2227 ball xy.snd rv \u2286 v \n        := (compatible v).mp hv xy.snd hxyv,\n      obtain \u27e8ru, \u27e8hru, hu'\u27e9\u27e9 := hu',\n      obtain \u27e8rv, \u27e8hrv, hv'\u27e9\u27e9 := hv',\n      use min ru rv,\n      split,\n      { exact lt_min hru hrv },\n      have hu'': ball xy.fst (min ru rv) \u2286 u\n        := subset.trans (ball_subset_ball (min_le_left ru rv)) hu',\n      have hv'': ball xy.snd (min ru rv) \u2286 v\n        := subset.trans (ball_subset_ball (min_le_right ru rv)) hv',\n      apply subset.trans _ huvU,\n      have H' : {zt : X \u00d7 Y | dist xy zt < min ru rv} =\n        {z : X | dist xy.fst z < min ru rv}.prod {t : Y | dist xy.snd t < min ru rv},\n      {\n        unfold dist,\n        ext,\n        simp,\n        tauto,\n      },\n      rw H',\n      rw prod_subset_prod_iff, left,\n      split; assumption,\n    },\n    {\n      intros h,\n      rw is_open_prod_iff,\n      intros ab hab,\n      specialize h ab hab,\n      obtain \u27e8r, hr, hrU\u27e9 := h,\n      use (ball ab.fst r),\n      use (ball ab.snd r),\n      repeat {split},\n      { exact open_of_ball },\n      { exact open_of_ball },\n      { exact mem_center_ball_iff.mpr hr },\n      { exact mem_center_ball_iff.mpr hr },\n      simp [hrU],\n    }\n  end,\n  ..prod.topological_space X Y,\n  ..prod.metric_space_basic X Y\n}\n\nend metric_space", "meta": {"author": "mmasdeu", "repo": "barcelonaleanseminar", "sha": "140478080f6680ea5e3ce61e6523272e7e12219f", "save_path": "github-repos/lean/mmasdeu-barcelonaleanseminar", "path": "github-repos/lean/mmasdeu-barcelonaleanseminar/barcelonaleanseminar-140478080f6680ea5e3ce61e6523272e7e12219f/src/productes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7456500706091808}}
{"text": "import tutorial_world.level12_cases3_exists --hide\nopen IncidencePlane --hide\nopen set --hide\n\n/- Tactic : left and right\n## Summary\n`left` and `right` work on the goal, and they change\n`\u22a2 P \u2228 Q` to `\u22a2 P` and `\u22a2 Q` respectively.\n## Details\nThe tactics `left` and `right` work on a goal which is a type with\ntwo constructors, the classic example being `P \u2228 Q`. \nTo prove `P \u2228 Q` it suffices to either prove `P` or prove `Q`,\nand once you know which one you are going for you can change\nthe goal with `left` or `right` to the appropriate choice.\n-/\n\n/- Tactic : unfold\n## Summary\n`unfold` works both on the goal and the hypotheses. It transforms some\nmathematical expressions into others which are simpler to read. \n## Example\nIf we find the expression `\u22a2 collinear {A, B, C}`, then typing `unfold collinear`\nwill change the goal into `\u22a2 \u2203 (\u2113 : Line \u03a9), \u2200 {P : \u03a9}, P \u2208 {A, B, C} \u2192 P \u2208 \u2113`, which makes \nit easier to understand what `tactic` we should apply to solve the goal.\n-/\n\n/-\n# Tutorial World\n\n## Level 13: the `unfold`, and the `left` and `right` tactics.\n\nUntil now, we have seen how to \nprove a goal of the form `P \u2227 Q` with the `split` tactic. In this level, you will learn how to prove a goal of the\nform `P \u2228 Q`, which means that either `P` holds or `Q` holds. In this case, you will have to decide whether you can\nprove `P` or `Q`. The `left` and `right` tactics will allow you to change the goal to `\u22a2 P` or `\u22a2 Q`, respectively.\n\n[**Tip:** Before typing any line, try to think which is the shortest path to finish the proof, either P or Q.] To\ntake the best decision, read the lemma and do a drawing of the situation. Once you're done, come back here. In this \ncase, it seems clear that proving `\u22a2 A = C` is not possible, since we don't have any hypotheses we can use to make progress.\nIn case you are not sure about that, try to prove `\u22a2 A = C` by typing `left,` and you will see that is not possible to move on from there.\nBecause of this reason, changing the goal into `\u22a2 collinear {A, B, C}` by typing `right,` will be the right path to complete this level. \n[**Remember:** In geometry, collinearity is the property of a set of points lying on the same line. In Lean, the elements of a set are\nwritten between curly brackets, separated by commas {A, B, C}.]\n\nNow, you may be wondering how we could step through `\u22a2 collinear {A, B, C}` if there isn't any `tactic` that works with this form \nof goal. To your surprise, there exists a tactic called `unfold` whose purpose is transforming some mathematical expressions into\nothers which are simpler to read. Type `unfold collinear,` to see how the goal changes into `\u22a2 \u2203 (\u2113 : Line \u03a9), \u2200 {P : \u03a9}, P \u2208 {A, B, C} \u2192 P \u2208 \u2113`.\nThis last goal is read as **there exists a line \u2113 in the plane \u03a9 \"for all\" (\u2200) points P in the plane \u03a9, such that P being an element of the set of points\nA, B and C implies that P is an element of the line \u2113.**\n\nI'm sure that you know now what tactic makes progress with this type of goal. To give you a hint, we need to consider a specific line \u2113 in the plane \u03a9.\nCan you see that the hypothesis `h` assumes that the point C is an element of the `line_through A B`? Then, because the goal says that the point P is an\nelement of the set of points A, B and C, there is no other way than changing the line \u2113 into the `line_through A B`. Once you've done that, use the `intros`\ntactic to add two new hypotheses to the local context until you see the goal `\u22a2 P \u2208 line_through A B`. From there, use the `cases` tactic to make the point P\nequal to the points A, B and C, in each of the cases. Try to finish the proof by your own. In case you get stuck, I recommend you to take a look at the previous levels. \n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nAfter typing `unfold collinear,`, you should have noticed that the `use` tactic had to be employed with `line_through A B`. Then, \nyou made progress by typing `intros P hP,`. Now, use `cases hP` and make an effort to prove the goals that you are left with. The\n`exact` and `rewrite` tactics may help you. Bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution. \n-/\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] -- hide\n\n/- Lemma : no-side-bar\nGiven three distinct points A, B and C, if C lies in the line through A and B, either A = C or A, B and C are collinear points. \n-/\nlemma left_right_example (A B C : \u03a9) (h : C \u2208 line_through A B) :\nA = C \u2228 collinear ({A, B, C} : set \u03a9) :=\nbegin\n  right,\n  unfold collinear,\n  use line_through A B,\n  intros P hP,\n  cases hP,\n  {\n    rw hP,\n    exact line_through_left A B,\n  },\n  cases hP,\n  {\n    rw hP,\n    exact line_through_right A B,\n  },\n  {\n    cases hP,\n    exact h,\n  },\n\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/tutorial_world/level13_leftright.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7456500687572417}}
{"text": "import tactic \nimport order.zorn\n\nvariable {\u03b1 : Type*}\n\nlemma max_of_fin_chain [partial_order \u03b1]\n: \u2200{c : set \u03b1}, c.finite \u2192 is_chain (\u2264) c \u2192 c.nonempty \u2192 \u2203m \u2208 c, \u2200{b}, b \u2208 c \u2192 b \u2264 m :=\nbegin \n\tintros c c_fin c_chain c_nonempty,\n\trcases finset.exists_maximal (set.finite.to_finset c_fin) \n\t((set.finite.nonempty_to_finset c_fin).mpr c_nonempty) with \u27e8m, hmc, hm\u27e9,\n\thave hmc' :=(set.finite.mem_to_finset c_fin).mp hmc,\n\tuse [m, hmc'],\n\tintros b hbc,\n\tspecialize hm b ((set.finite.mem_to_finset c_fin).mpr hbc),\n\tunfold is_chain set.pairwise at c_chain,\n\tspecialize c_chain hbc hmc',\n\tby_cases hbm : b = m,\n\t{exact (eq.symm hbm).ge},\n\t{\n\t\tcases c_chain hbm, exact h, exfalso,\n\t\texact hm ((ne.symm hbm).lt_of_le h),\n\t}\nend\n\ndef finite_character (F : set (set \u03b1)) : Prop :=\n\u2200 X, X \u2208 F \u2194 (\u2200 {Y : set \u03b1}, Y \u2286 X \u2192 Y.finite \u2192 Y \u2208 F)\n\nvariable {F : set (set \u03b1)}\n\nlemma mem_empty_of_fin_character : \nF.nonempty \u2192 finite_character F \u2192 \u2205 \u2208 F :=\nbegin\n\tintros F_nonempty F_fin_char,\n\tcases F_nonempty with X hX,\n\texact (F_fin_char X).mp hX (set.empty_subset X) set.finite_empty,\nend\n\nlemma exists_maximal_of_finite_character {X} (hX : X \u2208 F) :\n finite_character F \u2192 \u2203M \u2208 F, X \u2286 M \u2227 \u2200{Y}, Y \u2208 F \u2192 M \u2286 Y \u2192 Y = M :=\nbegin \n\tintro F_fin_char,\n\tapply zorn_subset_nonempty, swap, exact hX,\n\n\tintros c c_ss c_chain c_nonempty,\n\tuse c.sUnion,\n\n\tsplit, swap, {exact \u03bbs hs, set.subset_sUnion_of_mem hs},\n\tby_contra hUcF,\n\trw F_fin_char c.sUnion at hUcF, push_neg at hUcF,\n\trcases hUcF with \u27e8Y, Y_ss, Y_fin, hYF\u27e9,\n\tsuffices : \u2203b \u2208 c, b \u2209 F,\t{rcases this with \u27e8b, hb1, hb2\u27e9, exact hb2 (c_ss hb1)},\n\thave : \u2200y \u2208 Y, \u2203Z \u2208 c, y \u2208 Z,\n\t{\n\t\tintros y hy,\n\t\trcases Y_ss hy with \u27e8Z, hZc, hyZ\u27e9,\n\t\texact \u27e8Z, hZc, hyZ\u27e9,\n\t},\n\tchoose f hfc hf using this,\n\thave sub_chain_fin := set.finite.dependent_image Y_fin f,\n\tset sub_chain := {y : set \u03b1 | \u2203 (x : \u03b1) (hx : x \u2208 Y), y = f x hx}\n\twith sub_chain_def,\n\thave sub_chain_ss : sub_chain \u2286 c,\n\t{\n\t\tintros Z hZ,\n\t\trw sub_chain_def at hZ,\n\t\tsimp at hZ,\n\t\trcases hZ with \u27e8y, hyY, hyf\u27e9,\n\t\trw hyf,\n\t\texact hfc y hyY,\n\t},\n\thave Y_nonempty : Y.nonempty,\n\t{\n\t\trw\u2190 set.ne_empty_iff_nonempty,\n\t\tintro contra,\n\t\trw contra at hYF,\n\t\texact hYF (mem_empty_of_fin_character \u27e8X, hX\u27e9 F_fin_char),\n\t},\n\thave sub_chain_nonempty : sub_chain.nonempty,\n\t{\n\t\tcases Y_nonempty with y hy,\n\t\thave : f y hy \u2208 sub_chain, {rw sub_chain_def, simp,exact \u27e8y, hy, rfl\u27e9},\n\t\texact set.nonempty_of_mem this,\n\t},\n\trcases max_of_fin_chain sub_chain_fin (is_chain.mono sub_chain_ss c_chain)\n\tsub_chain_nonempty with \u27e8m, hmsub, hm\u27e9,\n\tuse [m, sub_chain_ss hmsub],\n\tsuffices : Y \u2286 m, {rw F_fin_char, push_neg, exact \u27e8Y, this, Y_fin, hYF\u27e9},\n\tsuffices : \u2200y \u2208 Y, \u2203Z \u2208 sub_chain, y \u2208 Z,\n\t{\n\t\tintros y hy,\n\t\trcases this y hy with \u27e8Z, Z_sub, hyZ\u27e9,\n\t\texact @hm Z Z_sub y hyZ,\n\t},\n\n\tintros y hy,\n\tuse [f y hy, y, hy, rfl, hf y hy],\nend", "meta": {"author": "duduFreire", "repo": "formal_logic", "sha": "d7977f4bc03267b56c2a694595c4654eaef84f42", "save_path": "github-repos/lean/duduFreire-formal_logic", "path": "github-repos/lean/duduFreire-formal_logic/formal_logic-d7977f4bc03267b56c2a694595c4654eaef84f42/src/tukey.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.745650065539424}}
{"text": "/-\nCopyright (c) 2022 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\nimport combinatorics.simple_graph.trails\nimport tactic.derive_fintype\n\n/-!\n# The K\u00f6nigsberg bridges problem\n\nWe show that a graph that represents the islands and mainlands of K\u00f6nigsberg and seven bridges\nbetween them has no Eulerian trail.\n-/\n\nnamespace konigsberg\n\n/-- The vertices for the K\u00f6nigsberg graph; four vertices for the bodies of land and seven\nvertices for the bridges. -/\n@[derive [decidable_eq, fintype], nolint has_inhabited_instance]\ninductive verts : Type\n| V1 | V2 | V3 | V4 -- The islands and mainlands\n| B1 | B2 | B3 | B4 | B5 | B6 | B7 -- The bridges\n\nopen verts\n\n/-- Each of the connections between the islands/mainlands and the bridges.\nThese are ordered pairs, but the data becomes symmetric in `konigsberg.adj`. -/\ndef edges : list (verts \u00d7 verts) :=\n[ (V1, B1), (V1, B2), (V1, B3), (V1, B4), (V1, B5),\n  (B1, V2), (B2, V2), (B3, V4), (B4, V3), (B5, V3),\n  (V2, B6), (B6, V4),\n  (V3, B7), (B7, V4) ]\n\n/-- The adjacency relation for the K\u00f6nigsberg graph. -/\ndef adj (v w : verts) : bool := ((v, w) \u2208 edges) || ((w, v) \u2208 edges)\n\n/-- The K\u00f6nigsberg graph structure. While the K\u00f6nigsberg bridge problem\nis usually described using a multigraph, the we use a \"mediant\" construction\nto transform it into a simple graph -- every edge in the multigraph is subdivided\ninto a path of two edges. This construction preserves whether a graph is Eulerian.\n\n(TODO: once mathlib has multigraphs, either prove the mediant construction preserves the\nEulerian property or switch this file to use multigraphs. -/\n@[simps]\ndef graph : simple_graph verts :=\n{ adj := \u03bb v w, adj v w,\n  symm := begin\n    dsimp [symmetric, adj],\n    dec_trivial,\n  end,\n  loopless := begin\n    dsimp [irreflexive, adj],\n    dec_trivial\n  end }\n\ninstance : decidable_rel graph.adj := \u03bb a b, decidable_of_bool (adj a b) iff.rfl\n\n/-- To speed up the proof, this is a cache of all the degrees of each vertex,\nproved in `konigsberg.degree_eq_degree`. -/\n@[simp]\ndef degree : verts \u2192 \u2115\n| V1 := 5 | V2 := 3 | V3 := 3 | V4 := 3\n| B1 := 2 | B2 := 2 | B3 := 2 | B4 := 2 | B5 := 2 | B6 := 2 | B7 := 2\n\n@[simp] lemma degree_eq_degree (v : verts) : graph.degree v = degree v := by cases v; refl\n\n/-- The K\u00f6nigsberg graph is not Eulerian. -/\ntheorem not_is_eulerian {u v : verts} (p : graph.walk u v) (h : p.is_eulerian) : false :=\nbegin\n  have : {v | odd (graph.degree v)} = {verts.V1, verts.V2, verts.V3, verts.V4},\n  { ext w,\n    simp only [degree_eq_degree, nat.odd_iff_not_even, set.mem_set_of_eq, set.mem_insert_iff,\n      set.mem_singleton_iff],\n    cases w; simp, },\n  have h := h.card_odd_degree,\n  simp_rw [this] at h,\n  norm_num at h,\nend\n\nend konigsberg\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/100-theorems-list/54_konigsberg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7456453527842477}}
{"text": "section\n\nvariables A B C D : Prop\n\nexample : A \u2227 (A \u2192 B) \u2192 B :=\nassume h : A \u2227 (A \u2192 B),\nhave g : A, from and.left h,\nhave i : A \u2192 B, from and.right h,\nshow B, from i g\n\ntheorem nny (ha : A) : \u00ac (\u00ac A) :=\nassume hna : \u00ac A,\nshow false, from hna ha\n\n#check nny\n\ntheorem notAnotB (h : \u00ac A \u2228 \u00ac B) : \u00ac (A \u2227 B) :=\nor.elim h\n  (assume hna : \u00ac A,\n    assume hn : A \u2227 B,\n    show false, from hna (and.left hn))\n  (assume hnb : \u00ac B,\n    assume hn : A \u2227 B,\n    show false, from hnb (and.right hn))\n\n#check notAnotB\n\n  \nexample : A \u2192 \u00ac (\u00ac A \u2227 B) :=\nassume ha : A,\nassume hnab : \u00ac A \u2227 B,\nshow false, from and.left hnab ha\n\nexample : \u00ac (A \u2227 B) \u2192 (A \u2192 \u00ac B) :=\nassume hnanb : \u00ac (A \u2227 B),\nassume ha : A,\nassume hb : B,\nshow false, from hnanb (and.intro ha hb)\n\n\nexample (h1 : A \u2228 B) (h2 : A \u2192 C) (h3 : B \u2192 D) : C \u2228 D :=\nor.elim h1\n  (assume h1a : A,\n    show C \u2228 D, from or.inl (h2 h1a))\n  (assume h1b : B,\n    show C \u2228 D, from or.inr (h3 h1b))\n\n\n\nexample (h : \u00ac A \u2227 \u00ac B) : \u00ac (A \u2228 B) :=\nassume g : A \u2228 B,\nor.elim g \n  (assume ga : A,\n    show false, from (and.left h) ga)\n  (assume gb : B,\n    show false, from (and.right h) gb)\n\n\nexample : \u00ac (A \u2227 \u00ac A) :=\nassume h : A \u2227 \u00ac A,\nshow false, from and.right h (and.left h)\n\n\nlemma AimpNotA (h : A \u2192 \u00ac A) : \u00ac A :=\nassume g : A,\nshow false, from (h g) g\n\n#check AimpNotA\n\n\n\nexample : \u00ac (A \u2194 \u00ac A) :=\nassume hiff : A \u2194 \u00ac A,\nhave hl : A \u2192 \u00ac A, from iff.elim_left hiff,\nhave hr : \u00ac A \u2192 A, from iff.elim_right hiff,\nhave hna : \u00ac A, from \n  assume h : A, \n  show false, from (hl h) h,\nhave ha : A, from hr hna,\nshow false, from hna ha\n\n\n\nend\n", "meta": {"author": "faustoUrtiz", "repo": "learning-leanprover", "sha": "3acddd0ffb952ce32b0135b8f49de5e930c9820a", "save_path": "github-repos/lean/faustoUrtiz-learning-leanprover", "path": "github-repos/lean/faustoUrtiz-learning-leanprover/learning-leanprover-3acddd0ffb952ce32b0135b8f49de5e930c9820a/propositional-exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384595, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7456284729176439}}
{"text": "import tactic\nimport data.nat.parity\n\ndef soucet_do_n : \u2115 \u2192 \u2115\n| 0       := 0\n| (n + 1) := (n + 1) + (soucet_do_n n)\n\ndef soucet_do_n' : \u2115 \u2192 \u2115 :=\n\u03bb n, n * (n + 1) / 2\n\ntheorem soucty_odpovidaji : soucet_do_n = soucet_do_n' :=\nbegin\n  ext1,\n  induction x with n ih,\n  {\n    refl,\n  },\n  unfold soucet_do_n,\n  rw ih,\n  unfold soucet_do_n',\n  convert_to n + 1 + n * (n + 1) / 2 = (n + 1) * (n + 2) / 2,\n\n  have pul_a_pul : \u2200 x y : \u2115, even x \u2192 even y \u2192 x / 2 + y / 2 = (x + y) / 2,\n  {\n    intros x y hx hy,\n    cases hx with x' hx',\n    cases hy with y' hy',\n    rw hx',\n    rw hy',\n    ring_nf,\n    convert_to x' + y' = (2 * x' + 2 * y') / 2,\n    {\n      apply congr_arg2;\n      norm_num,\n    },\n    rw \u2190 mul_add,\n    norm_num,\n  },\n  calc n + 1 + n * (n + 1) / 2 \n      = (n + 1) * 2 / 2 + n * (n + 1) / 2 : by norm_num\n  ... = ((n + 1) * 2 + n * (n + 1)) / 2   : pul_a_pul _ _ \u27e8n + 1, mul_two _\u27e9 (nat.even_mul_succ_self n)\n  ... = ((2 + n) * (n + 1)) / 2           : by ring_nf\n  ... = (n + 1) * (n + 2) / 2             : by ring_nf,\nend\n", "meta": {"author": "madvorak", "repo": "mam-lean", "sha": "8268f3f822fd7da3395d6fccc153e038d5cd6e31", "save_path": "github-repos/lean/madvorak-mam-lean", "path": "github-repos/lean/madvorak-mam-lean/mam-lean-8268f3f822fd7da3395d6fccc153e038d5cd6e31/src/dil_3_casopis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7456284480345914}}
{"text": "/-\nCopyright (c) 2020 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa, Jujian Zhang\n\n! This file was ported from Lean 3 source module number_theory.liouville.liouville_constant\n! leanprover-community/mathlib commit 98cbfb459a053c5ca44aec69f0a5a932b84c0d67\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.NumberTheory.Liouville.Basic\n\n/-!\n\n# Liouville constants\n\nThis file contains a construction of a family of Liouville numbers, indexed by a natural number $m$.\nThe most important property is that they are examples of transcendental real numbers.\nThis fact is recorded in `liouville.is_transcendental`.\n\nMore precisely, for a real number $m$, Liouville's constant is\n$$\n\\sum_{i=0}^\\infty\\frac{1}{m^{i!}}.\n$$\nThe series converges only for $1 < m$.  However, there is no restriction on $m$, since,\nif the series does not converge, then the sum of the series is defined to be zero.\n\nWe prove that, for $m \\in \\mathbb{N}$ satisfying $2 \\le m$, Liouville's constant associated to $m$\nis a transcendental number.  Classically, the Liouville number for $m = 2$ is the one called\n``Liouville's constant''.\n\n## Implementation notes\n\nThe indexing $m$ is eventually a natural number satisfying $2 \u2264 m$.  However, we prove the first few\nlemmas for $m \\in \\mathbb{R}$.\n-/\n\n\nnoncomputable section\n\nopen Nat BigOperators\n\nopen Real Finset\n\nnamespace Liouville\n\n/-- For a real number `m`, Liouville's constant is\n$$\n\\sum_{i=0}^\\infty\\frac{1}{m^{i!}}.\n$$\nThe series converges only for `1 < m`.  However, there is no restriction on `m`, since,\nif the series does not converge, then the sum of the series is defined to be zero.\n-/\ndef liouvilleNumber (m : \u211d) : \u211d :=\n  \u2211' i : \u2115, 1 / m ^ i !\n#align liouville.liouville_number Liouville.liouvilleNumber\n\n/-- `liouville_number_initial_terms` is the sum of the first `k + 1` terms of Liouville's constant,\ni.e.\n$$\n\\sum_{i=0}^k\\frac{1}{m^{i!}}.\n$$\n-/\ndef liouvilleNumberInitialTerms (m : \u211d) (k : \u2115) : \u211d :=\n  \u2211 i in range (k + 1), 1 / m ^ i !\n#align liouville.liouville_number_initial_terms Liouville.liouvilleNumberInitialTerms\n\n/-- `liouville_number_tail` is the sum of the series of the terms in `liouville_number m`\nstarting from `k+1`, i.e\n$$\n\\sum_{i=k+1}^\\infty\\frac{1}{m^{i!}}.\n$$\n-/\ndef liouvilleNumberTail (m : \u211d) (k : \u2115) : \u211d :=\n  \u2211' i, 1 / m ^ (i + (k + 1))!\n#align liouville.liouville_number_tail Liouville.liouvilleNumberTail\n\ntheorem liouvilleNumberTail_pos {m : \u211d} (hm : 1 < m) (k : \u2115) : 0 < liouvilleNumberTail m k :=\n  calc\n    -- replace `0` with the constantly zero series `\u2211 i : \u2115, 0`\n        (0 : \u211d) =\n        \u2211' i : \u2115, 0 :=\n      tsum_zero.symm\n    _ <\n        liouvilleNumberTail m\n          k :=-- to show that a series with non-negative terms has strictly positive sum it suffices\n          -- to prove that\n          -- 1. the terms of the zero series are indeed non-negative\n          -- 2. the terms of our series are non-negative\n          -- 3. one term of our series is strictly positive -- they all are, we use the first term\n          tsum_lt_tsum_of_nonneg\n          (fun _ => rfl.le) (fun i => one_div_nonneg.mpr (pow_nonneg (zero_le_one.trans hm.le) _))\n          (one_div_pos.mpr\n            (pow_pos (zero_lt_one.trans hm)\n              (0 +\n                  (k +\n                    1))!)) <|-- 4. our series converges -- it does since it is the tail of a converging series, though\n          -- this is not the argument here.\n          summable_one_div_pow_of_le\n          hm fun i => trans le_self_add (Nat.self_le_factorial _)\n    \n#align liouville.liouville_number_tail_pos Liouville.liouvilleNumberTail_pos\n\n/-- Split the sum definining a Liouville number into the first `k` term and the rest. -/\ntheorem liouvilleNumber_eq_initial_terms_add_tail {m : \u211d} (hm : 1 < m) (k : \u2115) :\n    liouvilleNumber m = liouvilleNumberInitialTerms m k + liouvilleNumberTail m k :=\n  (sum_add_tsum_nat_add _ (summable_one_div_pow_of_le hm fun i => i.self_le_factorial)).symm\n#align liouville.liouville_number_eq_initial_terms_add_tail Liouville.liouvilleNumber_eq_initial_terms_add_tail\n\n/-! We now prove two useful inequalities, before collecting everything together. -/\n\n\n/-- Partial inequality, works with `m \u2208 \u211d` satisfying `1 < m`. -/\ntheorem tsum_one_div_pow_factorial_lt (n : \u2115) {m : \u211d} (m1 : 1 < m) :\n    (\u2211' i : \u2115, 1 / m ^ (i + (n + 1))!) < (1 - 1 / m)\u207b\u00b9 * (1 / m ^ (n + 1)!) :=\n  have\n    m0 :-- two useful inequalities\n      0 <\n      m :=\n    zero_lt_one.trans m1\n  have mi : |1 / m| < 1 :=\n    (le_of_eq (abs_of_pos (one_div_pos.mpr m0))).trans_lt ((div_lt_one m0).mpr m1)\n  calc\n    (\u2211' i, 1 / m ^ (i + (n + 1))!) <\n        \u2211' i,\n          1 /\n            m ^\n              (i + (n + 1)!) :=-- to show the strict inequality between these series, we prove that:\n        tsum_lt_tsum_of_nonneg\n        (-- 1. the first series has non-negative terms\n        fun b => one_div_nonneg.mpr (pow_nonneg m0.le _))\n        (-- 2. the second series dominates the first\n        fun b =>\n          one_div_pow_le_one_div_pow_of_le m1.le (b.add_factorial_succ_le_factorial_add_succ n))\n        (-- 3. the term with index `i = 2` of the first series is strictly smaller than\n          -- the corresponding term of the second series\n          one_div_pow_strictAnti\n          m1 (n.add_factorial_succ_lt_factorial_add_succ rfl.le))\n        (-- 4. the second series is summable, since its terms grow quickly\n          summable_one_div_pow_of_le\n          m1 fun j => Nat.le.intro rfl)\n    _ = \u2211' i, (1 / m) ^ i * (1 / m ^ (n + 1)!) :=-- split the sum in the exponent and massage\n    by\n      congr\n      ext i\n      rw [pow_add, \u2190 div_div, div_eq_mul_one_div, one_div_pow]\n    -- factor the constant `(1 / m ^ (n + 1)!)` out of the series\n        _ =\n        (\u2211' i, (1 / m) ^ i) * (1 / m ^ (n + 1)!) :=\n      tsum_mul_right\n    _ = (1 - 1 / m)\u207b\u00b9 * (1 / m ^ (n + 1)!) :=-- the series if the geometric series\n          mul_eq_mul_right_iff.mpr\n        (Or.inl (tsum_geometric_of_abs_lt_1 mi))\n    \n#align liouville.tsum_one_div_pow_factorial_lt Liouville.tsum_one_div_pow_factorial_lt\n\ntheorem aux_calc (n : \u2115) {m : \u211d} (hm : 2 \u2264 m) :\n    (1 - 1 / m)\u207b\u00b9 * (1 / m ^ (n + 1)!) \u2264 1 / (m ^ n !) ^ n :=\n  calc\n    (1 - 1 / m)\u207b\u00b9 * (1 / m ^ (n + 1)!) \u2264\n        2 * (1 / m ^ (n + 1)!) :=-- the second factors coincide (and are non-negative),\n        -- the first factors, satisfy the inequality `sub_one_div_inv_le_two`\n        mul_le_mul_of_nonneg_right\n        (sub_one_div_inv_le_two hm) (by positivity)\n    _ = 2 / m ^ (n + 1)! := (mul_one_div 2 _)\n    _ = 2 / m ^ (n ! * (n + 1)) := (congr_arg ((\u00b7 / \u00b7) 2) (congr_arg (pow m) (mul_comm _ _)))\n    _ \u2264 1 / m ^ (n ! * n) :=\n      by\n      -- [ NB: in this block, I do not follow the brace convention for subgoals -- I wait until\n      --   I solve all extraneous goals at once with `exact pow_pos (zero_lt_two.trans_le hm) _`. ]\n      -- Clear denominators and massage*\n      apply (div_le_div_iff _ _).mpr\n      conv_rhs => rw [one_mul, mul_add, pow_add, mul_one, pow_mul, mul_comm, \u2190 pow_mul]\n      -- the second factors coincide, so we prove the inequality of the first factors*\n      refine' (mul_le_mul_right _).mpr _\n      -- solve all the inequalities `0 < m ^ ??`\n      any_goals exact pow_pos (zero_lt_two.trans_le hm) _\n      -- `2 \u2264 m ^ n!` is a consequence of monotonicity of exponentiation at `2 \u2264 m`.\n      exact trans (trans hm (pow_one _).symm.le) (pow_mono (one_le_two.trans hm) n.factorial_pos)\n    _ = 1 / (m ^ n !) ^ n := congr_arg ((\u00b7 / \u00b7) 1) (pow_mul m n ! n)\n    \n#align liouville.aux_calc Liouville.aux_calc\n\n/-!  Starting from here, we specialize to the case in which `m` is a natural number. -/\n\n\n/-- The sum of the `k` initial terms of the Liouville number to base `m` is a ratio of natural\nnumbers where the denominator is `m ^ k!`. -/\ntheorem liouville_number_rat_initial_terms {m : \u2115} (hm : 0 < m) (k : \u2115) :\n    \u2203 p : \u2115, liouvilleNumberInitialTerms m k = p / m ^ k ! :=\n  by\n  induction' k with k h\n  \u00b7 exact \u27e81, by rw [liouville_number_initial_terms, range_one, sum_singleton, Nat.cast_one]\u27e9\n  \u00b7 rcases h with \u27e8p_k, h_k\u27e9\n    use p_k * m ^ ((k + 1)! - k !) + 1\n    unfold liouville_number_initial_terms at h_k\u22a2\n    rw [sum_range_succ, h_k, div_add_div, div_eq_div_iff, add_mul]\n    \u00b7 norm_cast\n      rw [add_mul, one_mul, Nat.factorial_succ,\n        show k.succ * k ! - k ! = (k.succ - 1) * k ! by rw [tsub_mul, one_mul], Nat.succ_sub_one,\n        add_mul, one_mul, pow_add]\n      simp [mul_assoc]\n    refine' mul_ne_zero_iff.mpr \u27e8_, _\u27e9\n    all_goals exact pow_ne_zero _ (nat.cast_ne_zero.mpr hm.ne.symm)\n#align liouville.liouville_number_rat_initial_terms Liouville.liouville_number_rat_initial_terms\n\ntheorem is_liouville {m : \u2115} (hm : 2 \u2264 m) : Liouville (liouvilleNumber m) :=\n  by\n  -- two useful inequalities\n  have mZ1 : 1 < (m : \u2124) := by\n    norm_cast\n    exact one_lt_two.trans_le hm\n  have m1 : 1 < (m : \u211d) := by\n    norm_cast\n    exact one_lt_two.trans_le hm\n  intro n\n  -- the first `n` terms sum to `p / m ^ k!`\n  rcases liouville_number_rat_initial_terms (zero_lt_two.trans_le hm) n with \u27e8p, hp\u27e9\n  refine' \u27e8p, m ^ n !, one_lt_pow mZ1 n.factorial_ne_zero, _\u27e9\n  push_cast\n  -- separate out the sum of the first `n` terms and the rest\n  rw [liouville_number_eq_initial_terms_add_tail m1 n, \u2190 hp, add_sub_cancel',\n    abs_of_nonneg (liouville_number_tail_pos m1 _).le]\n  exact\n    \u27e8((lt_add_iff_pos_right _).mpr (liouville_number_tail_pos m1 n)).Ne.symm,\n      (tsum_one_div_pow_factorial_lt n m1).trans_le\n        (aux_calc _ (nat.cast_two.symm.le.trans (nat.cast_le.mpr hm)))\u27e9\n#align liouville.is_liouville Liouville.is_liouville\n\n/- Placing this lemma outside of the `open/closed liouville`-namespace would allow to remove\n`_root_.`, at the cost of some other small weirdness. -/\ntheorem is_transcendental {m : \u2115} (hm : 2 \u2264 m) : Transcendental \u2124 (liouvilleNumber m) :=\n  transcendental (is_liouville hm)\n#align liouville.is_transcendental Liouville.is_transcendental\n\nend Liouville\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/Liouville/LiouvilleConstant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7455472904305972}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.polynomial.algebra_map\nimport data.polynomial.hasse_deriv\n\n/-!\n# Taylor expansions of polynomials\n\n## Main declarations\n\n* `polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`\n* `polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is\n  `(polynomial.hasse_deriv k f).eval r`\n* `polynomial.eq_zero_of_hasse_deriv_eq_zero`:\n  the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero\n\n-/\n\nnoncomputable theory\n\nnamespace polynomial\nopen_locale polynomial\n\nvariables {R : Type*} [semiring R] (r : R) (f : R[X])\n\n/-- The Taylor expansion of a polynomial `f` at `r`. -/\ndef taylor (r : R) : R[X] \u2192\u2097[R] R[X] :=\n{ to_fun := \u03bb f, f.comp (X + C r),\n  map_add' := \u03bb f g, add_comp,\n  map_smul' := \u03bb c f, by simp only [smul_eq_C_mul, C_mul_comp, ring_hom.id_apply] }\n\nlemma taylor_apply : taylor r f = f.comp (X + C r) := rfl\n\n@[simp] lemma taylor_X : taylor r X = X + C r :=\nby simp only [taylor_apply, X_comp]\n\n@[simp] lemma taylor_C (x : R) : taylor r (C x) = C x :=\nby simp only [taylor_apply, C_comp]\n\n@[simp] lemma taylor_zero' : taylor (0 : R) = linear_map.id :=\nbegin\n  ext,\n  simp only [taylor_apply, add_zero, comp_X, _root_.map_zero, linear_map.id_comp, function.comp_app,\n             linear_map.coe_comp]\nend\n\nlemma taylor_zero (f : R[X]) : taylor 0 f = f :=\nby rw [taylor_zero', linear_map.id_apply]\n\n@[simp] lemma taylor_one : taylor r (1 : R[X]) = C 1 :=\nby rw [\u2190 C_1, taylor_C]\n\n@[simp] lemma taylor_monomial (i : \u2115) (k : R) : taylor r (monomial i k) = C k * (X + C r) ^ i :=\nby simp [taylor_apply]\n\n/-- The `k`th coefficient of `polynomial.taylor r f` is `(polynomial.hasse_deriv k f).eval r`. -/\nlemma taylor_coeff (n : \u2115) : (taylor r f).coeff n = (hasse_deriv n f).eval r :=\nshow (lcoeff R n).comp (taylor r) f = (leval r).comp (hasse_deriv n) f,\nbegin\n  congr' 1, clear f, ext i,\n  simp only [leval_apply, mul_one, one_mul, eval_monomial, linear_map.comp_apply, coeff_C_mul,\n    hasse_deriv_monomial, taylor_apply, monomial_comp, C_1,\n    (commute_X (C r)).add_pow i, linear_map.map_sum],\n  simp only [lcoeff_apply, \u2190 C_eq_nat_cast, mul_assoc, \u2190 C_pow, \u2190 C_mul, coeff_mul_C,\n    (nat.cast_commute _ _).eq, coeff_X_pow, boole_mul, finset.sum_ite_eq, finset.mem_range],\n  split_ifs with h, { refl },\n  push_neg at h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero],\nend\n\n@[simp] lemma taylor_coeff_zero : (taylor r f).coeff 0 = f.eval r :=\nby rw [taylor_coeff, hasse_deriv_zero, linear_map.id_apply]\n\n@[simp] lemma taylor_coeff_one : (taylor r f).coeff 1 = f.derivative.eval r :=\nby rw [taylor_coeff, hasse_deriv_one]\n\n@[simp] lemma nat_degree_taylor (p : R[X]) (r : R) :\n  nat_degree (taylor r p) = nat_degree p :=\nbegin\n  refine map_nat_degree_eq_nat_degree _ _,\n  nontriviality R,\n  intros n c c0,\n  simp [taylor_monomial, nat_degree_C_mul_eq_of_mul_ne_zero, nat_degree_pow_X_add_C, c0]\nend\n\n@[simp] lemma taylor_mul {R} [comm_semiring R] (r : R) (p q : R[X]) :\n  taylor r (p * q) = taylor r p * taylor r q :=\nby simp only [taylor_apply, mul_comp]\n\n/-- `polynomial.taylor` as a `alg_hom` for commutative semirings -/\n@[simps apply] def taylor_alg_hom {R} [comm_semiring R] (r : R) : R[X] \u2192\u2090[R] R[X] :=\nalg_hom.of_linear_map (taylor r) (taylor_one r) (taylor_mul r)\n\nlemma taylor_taylor {R} [comm_semiring R] (f : R[X]) (r s : R) :\n  taylor r (taylor s f) = taylor (r + s) f :=\nby simp only [taylor_apply, comp_assoc, map_add, add_comp, X_comp, C_comp, C_add, add_assoc]\n\nlemma taylor_eval {R} [comm_semiring R] (r : R) (f : R[X]) (s : R) :\n  (taylor r f).eval s = f.eval (s + r) :=\nby simp only [taylor_apply, eval_comp, eval_C, eval_X, eval_add]\n\nlemma taylor_eval_sub {R} [comm_ring R] (r : R) (f : R[X]) (s : R) :\n  (taylor r f).eval (s - r) = f.eval s :=\nby rw [taylor_eval, sub_add_cancel]\n\nlemma taylor_injective {R} [comm_ring R] (r : R) : function.injective (taylor r) :=\nbegin\n  intros f g h,\n  apply_fun taylor (-r) at h,\n  simpa only [taylor_apply, comp_assoc, add_comp, X_comp, C_comp, C_neg,\n    neg_add_cancel_right, comp_X] using h,\nend\n\n\n\n/-- Taylor's formula. -/\nlemma sum_taylor_eq {R} [comm_ring R] (f : R[X]) (r : R) :\n  (taylor r f).sum (\u03bb i a, C a * (X - C r) ^ i) = f :=\nby rw [\u2190comp_eq_sum_left, sub_eq_add_neg, \u2190C_neg, \u2190taylor_apply, taylor_taylor, neg_add_self,\n       taylor_zero]\n\nend polynomial\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/polynomial/taylor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7455472877000326}}
{"text": "import data.int.basic tactic.pure_maths -- hide\n\n/-\n# Propositional logic\n## Level 1: And elimination\n\nLet $p$ and $q$ be propositions (mathematical statements). The formal statement $p \\land q$\n(read '$p$ conjunction $q$')\ncorresponds to the informal statement '$p$ and $q$'.\n\nSuppose you are given a hypothesis `h : p \u2227 q`. Then\n\n1. [left and elimination] `h.left` is a proof of `p` and\n2. [right and elimination] `h.right` is a proof of `q`.\n\nHere, `h.left` is an abbreviation for `and.elim_left h`. Likewise for `h.right`.\n\n**Theorem**: Let $x$ be an integer. Supose $h : (x > 0) \\land (x ^ 2 = 16)$. Then $x ^ 2 = 16$.\n\n**Proof**: The result follows from right and elimination on $h$. \u220e\n\nThe Lean proof is below.\n\n**Notation**: the symbol `\u2227` in Lean is typed `\\and`.\n-/\n\n\n/- Axiom : and.elim_left (h : p \u2227 q) :\np\n-/\n\n/- Axiom : and.elim_right (h : p \u2227 q) :\nq\n-/\n\n\n\nexample (x : \u2124) (h : (x > 0) \u2227 (x * x = 16)) : x * x = 16 :=\nbegin\n  from h.right,\nend\n\n/-\nAlternatively, the `cases` tactic will decompose the `\u2227` into both the left and right sides.\nBelow `cases h with h\u2081 h\u2082` decomposes `h` into `h\u2081 : x > 0` and `h\u2082 : x * x = 16`.\n-/\n\nexample (x : \u2124) (h : (x > 0) \u2227 (x * x = 16)) : x * x = 16  :=\nbegin\n  cases h with h\u2081 h\u2082,  \n  show x * x = 16, from h\u2082,\nend\n\n\n\n/-\nFrequently, we consider the conjunction of several statements. \nWe can, for instance, derive $q$ given the assumption $p \\land (q \\land r).\n-/\n\nexample (p q r : Prop) (h : p \u2227 (q \u2227 r)) : q :=\nbegin\n  have h\u2082 : q \u2227 r, from h.right,\n  show q, from h\u2082.left,\nend\n\n\n/- Tactic : cases\n`cases` is a general-purpose elimination tactic. It it used to 'decompose' a hypothesis into\nits constituent parts.\n\n### Examples\n\n* Given `h : \u2203 (x : \u2124), x + 5 = y`, typing `cases h with m h\u2082` replaces `h` with `m : \u2124` and\n`h\u2082 : m + 5 = y`.\n\n* Given `h : p \u2227 q`, typing `cases h with hp hq` replaces `h` with `hp : p` and `hq : q`.\n\n* Given `h : p \u2228 q`, typing `cases h with hp hq` replaces the current goal with two goals\n(1) in which `h` is replaced with `hp : p` and (2) in which `h` is replaced with `hq : q`.\n\n* Given `x : \u2115`, typing `cases x with k` replaces the goal with two new goals: (1) a goal in which\nevery occurence of `x` is replaced with `0` and (2) a goal with a new variable `k : \u2115` and in \nwhich every occurrence of `x` is replaced with `succ k`.\n\n* Given `h : \u2203 (x : X), P(x)`, typing `cases h with y h\u2082` introduces a new variable `y : X`\nand replaces `h` with `h\u2082 : P(y)`.\n-/\n\n\nnamespace exlean -- hide\n\n/-\n## Tasks\n\n1. Replace `sorry` below with a Lean proof using `have` together with left and right and elimination.\nAdapt the proof of the example above.\n2. Write another Lean proof using `cases`.\n3. On a piece of paper, state and give a handwritten proof of this result.\n-/\n\n/- Theorem : no-side-bar\nLet $p$, $q$, and $r$ be propositions. Assuming $h : (r \\land (p \\land q)) \\land r$,\nwe have $q$.\n-/\ntheorem decomposing_and (p q r : Prop) (h : (r \u2227 (p \u2227 q)) \u2227 r) :\nq :=\nbegin\n  have h\u2082 : r \u2227 (p \u2227 q), from h.left,\n  have h\u2083 : p \u2227 q, from h\u2082.right,\n  show q, from h\u2083.right,\n\n\n\n\n\nend\n\nend exlean -- hide", "meta": {"author": "gihanmarasingha", "repo": "lean-game-template", "sha": "75bb3c4cd17afb31062d74eb9b2ab9b232e49719", "save_path": "github-repos/lean/gihanmarasingha-lean-game-template", "path": "github-repos/lean/gihanmarasingha-lean-game-template/lean-game-template-75bb3c4cd17afb31062d74eb9b2ab9b232e49719/src/propositional_logic/and_elimination.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7454881164151969}}
{"text": "-- Pruebas de la distributiva del producto sobre sumas\n-- ===================================================\n\nimport data.nat.basic\nopen nat\nopen list\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  (x : \u03b1)\nvariables (xs : list \u03b1)\nvariable  (n : \u2115)\nvariable  (ns : list \u2115)\n\n-- ----------------------------------------------------\n-- Nota. Se usar\u00e1 la funci\u00f3n aplica y sus propiedades\n-- estudiadas anteriormente.\n-- ----------------------------------------------------\n\ndef aplica : (\u03b1 \u2192 \u03b2) \u2192 list \u03b1 \u2192 list \u03b2\n| f []        := []\n| f (x :: xs) := (f x) :: aplica f xs\n\n@[simp]\nlemma aplica_nil\n  (f : \u03b1 \u2192 \u03b2)\n  : aplica f [] = [] :=\nrfl\n\n@[simp]\nlemma aplica_cons\n  (f : \u03b1 \u2192 \u03b2)\n  : aplica f (x :: xs) = (f x) :: aplica f xs :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la funci\u00f3n\n--    suma : list \u2115 \u2192 \u2115\n-- tal que (suma xs) es la suma de los elementos de\n-- xs. Por ejemplo,\n--    suma [3,2,5] = 10\n-- ----------------------------------------------------\n\ndef suma : list \u2115 \u2192 \u2115\n| []        := 0\n| (n :: ns) := n + suma ns\n\n-- #eval suma [3,2,5]\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar los siguientes lemas\n-- + suma_nil :\n--      suma ([] : list \u2115) = 0 :=\n-- + suma_cons :\n--      suma (n :: ns) = n + suma ns :=\n-- ----------------------------------------------------\n\n@[simp]\nlemma suma_nil :\n  suma ([] : list \u2115) = 0 :=\nrfl\n\n@[simp]\nlemma suma_cons :\n  suma (n :: ns) = n + suma ns :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 3. (p. 45) Demostrar que\n--    suma (aplica (\u03bb x, 2*x) ns) = 2 * (suma ns)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  suma (aplica (\u03bb x, 2*x) ns) = 2 * (suma ns) :=\nbegin\n  induction ns with m ms HI,\n  { rw aplica_nil,\n    rw suma_nil,\n    rw nat.mul_zero, },\n  { rw aplica_cons,\n    rw suma_cons,\n    rw HI,\n    rw suma_cons,\n    rw mul_add, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  suma (aplica (\u03bb x, 2*x) ns) = 2 * (suma ns) :=\nbegin\n  induction ns with m ms HI,\n  { calc suma (aplica (\u03bb (x : \u2115), 2 * x) [])\n         = suma []                                : by rw aplica_nil\n     ... = 0                                      : by rw suma_nil\n     ... = 2 * 0                                  : by rw nat.mul_zero\n     ... = 2 * suma []                            : by rw suma_nil, },\n  { calc suma (aplica (\u03bb x, 2 * x) (m :: ms))\n         = suma (2 * m :: aplica (\u03bb x, 2 * x) ms) : by rw aplica_cons\n     ... = 2 * m + suma (aplica (\u03bb x, 2 * x) ms)  : by rw suma_cons\n     ... = 2 * m + 2 * suma ms                    : by rw HI\n     ... = 2 * (m + suma ms)                      : by rw mul_add\n     ... = 2 * suma (m :: ms)                     : by rw suma_cons, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  suma (aplica (\u03bb x, 2*x) ns) = 2 * (suma ns) :=\nbegin\n  induction ns with m ms HI,\n  { simp, },\n  { simp [HI, mul_add], },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  suma (aplica (\u03bb x, 2*x) ns) = 2 * (suma ns) :=\nby induction ns ; simp [*, mul_add]\n\n-- 5\u00aa demostraci\u00f3n\nlemma suma_aplica :\n  \u2200 ns, suma (aplica (\u03bb x, 2*x) ns) = 2 * (suma ns)\n| []        := by simp\n| (m :: ms) := by simp [suma_aplica ms, mul_add]\n\n-- Comentarios sobre las funciones sum y map:\n-- + Son equivalentes a las funciones suma y aplica.\n-- + Para usarla hay que importar la librer\u00eda\n--   data.list.basic y abrir el espacio de nombre\n--   list escribiendo al principio del fichero\n--      import data.list.basic\n--      open list\n-- + Se puede evaluar. Por ejemplo,\n--      #eval sum [3,2,5]\n--      #eval map (\u03bbx, 2*x) [3,2,5]\n--      #eval map ((*) 2) [3,2,5]\n--      #eval map ((+) 2) [3,2,5]\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/7_Programas/Pruebas_de_la_distributiva_de_producto_sobre_sumas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.7454881123876522}}
{"text": "import analysis.topology.continuity\nimport analysis.topology.topological_space\nimport analysis.topology.infinite_sum\nimport analysis.topology.topological_structures\nimport analysis.topology.uniform_space\n\nimport data.equiv.basic\n\nlocal attribute [instance] classical.prop_decidable\n\nuniverses u v w\n\nopen set filter lattice classical\n\ndefinition is_open_sets {\u03b1 : Type u} (is_open : set \u03b1 \u2192 Prop) :=\n  is_open univ \u2227 (\u2200s t, is_open s \u2192 is_open t \u2192 is_open (s \u2229 t)) \u2227 (\u2200s, (\u2200t\u2208s, is_open t) \u2192 is_open (\u22c3\u2080 s))\n\ndefinition is_to_top {\u03b1 : Type u} (is_open : set \u03b1 \u2192 Prop) (H : is_open_sets (is_open)) : topological_space \u03b1 :=\n{ is_open := is_open,\n  is_open_univ := H.left,\n  is_open_inter := H.right.left,\n  is_open_sUnion := H.right.right\n}\n\ndefinition top_to_is {\u03b1 : Type u} (T : topological_space \u03b1) : is_open_sets (T.is_open) :=\n\u27e8T.is_open_univ,T.is_open_inter,T.is_open_sUnion\u27e9\n\n--Definition 9.9\ndefinition topology_dense {\u03b1 : Type u} [topological_space \u03b1] (s : set \u03b1) : Prop := closure s = univ\n\n--Proposition 9.11\ntheorem continuous_iff_image_closure_subset_closure_image {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [topological_space \u03b2] (f : \u03b1 \u2192 \u03b2) :\ncontinuous f \u2194 \u2200 s, f '' closure s \u2286 closure (f '' s) := \nbegin\n  split,\n    intros Hf s,\n    exact image_closure_subset_closure_image Hf,\n  intros Hf,\n  rw continuous_iff_is_closed,\n  intros b Hb,\n  let f_inv_b := f \u207b\u00b9' (b),\n  let f_f_inv_b := f '' f_inv_b,\n  have H1 : f '' (closure f_inv_b) \u2286 closure (f '' f_inv_b), by exact Hf f_inv_b,\n  have H2 : closure (f '' f_inv_b) \u2286 closure b, by exact closure_mono (set.image_preimage_subset f b),\n  have H3 : closure b = b, by exact closure_eq_of_is_closed Hb,\n  rw H3 at H2,\n  have H4 : f '' (closure f_inv_b) \u2286 b := set.subset.trans H1 H2,\n  have H5 : f \u207b\u00b9' (f '' closure f_inv_b) \u2286 f \u207b\u00b9' b := set.preimage_mono H4,\n  have H6 : closure f_inv_b \u2286 f_inv_b := set.subset.trans (set.subset_preimage_image f (closure f_inv_b)) H5,\n  exact closure_eq_iff_is_closed.1 (set.eq_of_subset_of_subset H6 subset_closure),\nend\n\n--Prooposition 9.13\nlemma closure_sInter' {\u03b1 : Type u} [topological_space \u03b1] {I : set (set \u03b1)} : \nclosure (sInter I) \u2286 (\u22c2 (i \u2208 I), closure i) := \nbegin\n  have H1 : \u22c2\u2080 I \u2286 \u22c2 (i \u2208 I), closure i,\n    apply subset_bInter,\n    intros x Hx,\n    exact subset.trans (sInter_subset_of_mem Hx) subset_closure,\n  have H2 : is_closed (\u22c2 (i : set \u03b1) (H : i \u2208 I), closure i),\n    have H6 : (\u22c2 (i : set \u03b1) (H : i \u2208 I), closure i) = \u22c2 (i : I), closure i,\n      apply set.ext,\n      intro x, simp,\n      split, intro Hx,\n      intros i Hi,\n      exact Hx i Hi,\n      intro Hx,\n      intros x_1 Hx_1,\n      exact Hx x_1 Hx_1,\n\n\n  have H7 : is_closed (\u22c2 (i : I), closure \u2191i) := @is_closed_Inter \u03b1 _ _ _ (\u03bb (i : I), @is_closed_closure _ _ \u2191i),\n  rw \u2190H6 at H7,\n  assumption,\n    have H3 : closure \u22c2\u2080 I \u2286 closure \u22c2 (i \u2208 I), closure i := closure_mono H1,\n\n    have H4 : @closure \u03b1 _ (\u22c2 (i \u2208 I), closure i) = \u22c2 (i \u2208 I), closure i,\n      apply closure_eq_of_is_closed,\n      exact H2,\n    rw H4 at H3,\n    exact H3,  \nend\n\n#print Inter\n\n\n--Corollary 9.21\nlemma frontier_eq_frontier_compl {\u03b1 : Type u} [topological_space \u03b1] {s : set \u03b1} : frontier s = frontier (-s) :=\nbegin\nrw frontier_eq_closure_inter_closure, rw frontier_eq_closure_inter_closure, \nfinish,\nend\n--What should I have done instead of finish??\n\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/Topology/Material/Sutherland_Chapter_9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133489844307, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7454508752733338}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-\n\n# More on functions\n\nAnother question on the Imperial introduction to proof problem sheet on functions\nis \"If `f : X \u2192 Y` and `g : Y \u2192 Z` and `g \u2218 f` is injective, is it true that `g` is injective?\"\nThis is not true. A counterexample could be made by letting `X` and `Z` have one element, \nand letting `Y` have two elements; `f` and `g` are then not hard to write down. Let's\nsee how to do this in Lean by making inductive types `X`, `Y` and `Z` and functions\n`f` and `g` which give an explicit counterexample.\n\n-/\n\n-- Let X be {a}\ninductive X : Type\n| a : X\n\n-- in fact the term of type X is called `X.a`.\n\n-- Let Y be {b,c}\ninductive Y : Type\n| b : Y\n| c : Y\n\ninductive Z : Type\n| d : Z\n\n-- Define f by f(X.a)=Y.b\ndef f : X \u2192 Y\n| X.a := Y.b\n\n-- define g by g(Y.b)=g(Y.c)=Z.d\ndef g : Y \u2192 Z\n| Y.b := Z.d\n| Y.c := Z.d\n\n-- examples of how these things work\nexample (z : Z) : z = Z.d :=\nbegin\n  cases z,\n  refl,\nend\n\nexample : Y.b \u2260 Y.c :=\nbegin\n  intro h, -- x \u2260 y is definitionally equal to (x = y) \u2192 false\n  cases h, -- no cases when they're equal!\nend\n\n\nopen function\n\nlemma gf_injective : injective (g \u2218 f) :=\nbegin\n  sorry,\nend\n\n-- This is a question on the IUM (Imperial introduction to proof course) function problem sheet\nexample : \u00ac (\u2200 X Y Z : Type, \u2200 (f : X \u2192 Y) (g : Y \u2192 Z), injective (g \u2218 f) \u2192 injective g) :=\nbegin\n  sorry,\nend\n\n-- This is another one\nexample : \u00ac (\u2200 X Y Z : Type, \u2200 (f : X \u2192 Y) (g : Y \u2192 Z), surjective (g \u2218 f) \u2192 surjective f) :=\nbegin\n  sorry,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section04functions/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.7454450858301271}}
{"text": "/-\nCopyright (c) 2020 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n-/\nimport analysis.normed_space.finite_dimension\nimport field_theory.tower\nimport data.is_R_or_C.basic\n\n/-! # Further lemmas about `is_R_or_C` -/\n\nvariables {K E : Type*} [is_R_or_C K]\n\nnamespace polynomial\n\nopen_locale polynomial\n\nlemma of_real_eval (p : \u211d[X]) (x : \u211d) : (p.eval x : K) = aeval \u2191x p :=\n(@aeval_algebra_map_apply_eq_algebra_map_eval \u211d K _ _ _ x p).symm\n\nend polynomial\n\nnamespace finite_dimensional\n\nopen_locale classical\nopen is_R_or_C\n\n/-- This instance generates a type-class problem with a metavariable `?m` that should satisfy\n`is_R_or_C ?m`. Since this can only be satisfied by `\u211d` or `\u2102`, this does not cause problems. -/\nlibrary_note \"is_R_or_C instance\"\n\n/-- An `is_R_or_C` field is finite-dimensional over `\u211d`, since it is spanned by `{1, I}`. -/\n@[nolint dangerous_instance] instance is_R_or_C_to_real : finite_dimensional \u211d K :=\n\u27e8\u27e8{1, I},\n  begin\n    rw eq_top_iff,\n    intros a _,\n    rw [finset.coe_insert, finset.coe_singleton, submodule.mem_span_insert],\n    refine \u27e8re a, (im a) \u2022 I, _, _\u27e9,\n    { rw submodule.mem_span_singleton,\n      use im a },\n    simp [re_add_im a, algebra.smul_def, algebra_map_eq_of_real]\n  end\u27e9\u27e9\n\nvariables (K E) [normed_add_comm_group E] [normed_space K E]\n\n/-- A finite dimensional vector space over an `is_R_or_C` is a proper metric space.\n\nThis is not an instance because it would cause a search for `finite_dimensional ?x E` before\n`is_R_or_C ?x`. -/\nlemma proper_is_R_or_C [finite_dimensional K E] : proper_space E :=\nbegin\n  letI : normed_space \u211d E := restrict_scalars.normed_space \u211d K E,\n  letI : finite_dimensional \u211d E := finite_dimensional.trans \u211d K E,\n  apply_instance\nend\n\nvariable {E}\n\ninstance is_R_or_C.proper_space_submodule (S : submodule K E) [finite_dimensional K \u21a5S] :\n  proper_space S :=\nproper_is_R_or_C K S\n\nend finite_dimensional\n\nnamespace is_R_or_C\n\n@[simp, is_R_or_C_simps] lemma re_clm_norm : \u2016(re_clm : K \u2192L[\u211d] \u211d)\u2016 = 1 :=\nbegin\n  apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _),\n  convert continuous_linear_map.ratio_le_op_norm _ (1 : K),\n  { simp },\n  { apply_instance }\nend\n\n@[simp, is_R_or_C_simps] lemma conj_cle_norm : \u2016(@conj_cle K _ : K \u2192L[\u211d] K)\u2016 = 1 :=\n(@conj_lie K _).to_linear_isometry.norm_to_continuous_linear_map\n\n@[simp, is_R_or_C_simps] lemma of_real_clm_norm : \u2016(of_real_clm : \u211d \u2192L[\u211d] K)\u2016 = 1 :=\nlinear_isometry.norm_to_continuous_linear_map of_real_li\n\nend is_R_or_C\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/is_R_or_C/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.7454450645858886}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, R\u00e9my Degenne\n-/\nimport order.min_max\nimport data.set.prod\n\n/-!\n# Intervals\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn any preorder `\u03b1`, we define intervals (which on each side can be either infinite, open, or\nclosed) using the following naming conventions:\n- `i`: infinite\n- `o`: open\n- `c`: closed\n\nEach interval has the name `I` + letter for left side + letter for right side. For instance,\n`Ioc a b` denotes the inverval `(a, b]`.\n\nThis file contains these definitions, and basic facts on inclusion, intersection, difference of\nintervals (where the precise statements may depend on the properties of the order, in particular\nfor some statements it should be `linear_order` or `densely_ordered`).\n\nTODO: This is just the beginning; a lot of rules are missing\n-/\n\nopen function order_dual (to_dual of_dual)\n\nvariables {\u03b1 \u03b2 : Type*}\n\nnamespace set\nsection preorder\nvariables [preorder \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c x : \u03b1}\n\n/-- Left-open right-open interval -/\ndef Ioo (a b : \u03b1) := {x | a < x \u2227 x < b}\n\n/-- Left-closed right-open interval -/\ndef Ico (a b : \u03b1) := {x | a \u2264 x \u2227 x < b}\n\n/-- Left-infinite right-open interval -/\ndef Iio (a : \u03b1) := {x | x < a}\n\n/-- Left-closed right-closed interval -/\ndef Icc (a b : \u03b1) := {x | a \u2264 x \u2227 x \u2264 b}\n\n/-- Left-infinite right-closed interval -/\ndef Iic (b : \u03b1) := {x | x \u2264 b}\n\n/-- Left-open right-closed interval -/\ndef Ioc (a b : \u03b1) := {x | a < x \u2227 x \u2264 b}\n\n/-- Left-closed right-infinite interval -/\ndef Ici (a : \u03b1) := {x | a \u2264 x}\n\n/-- Left-open right-infinite interval -/\ndef Ioi (a : \u03b1) := {x | a < x}\n\nlemma Ioo_def (a b : \u03b1) : {x | a < x \u2227 x < b} = Ioo a b := rfl\n\nlemma Ico_def (a b : \u03b1) : {x | a \u2264 x \u2227 x < b} = Ico a b := rfl\n\nlemma Iio_def (a : \u03b1) : {x | x < a} = Iio a := rfl\n\nlemma Icc_def (a b : \u03b1) : {x | a \u2264 x \u2227 x \u2264 b} = Icc a b := rfl\n\nlemma Iic_def (b : \u03b1) : {x | x \u2264 b} = Iic b := rfl\n\nlemma Ioc_def (a b : \u03b1) : {x | a < x \u2227 x \u2264 b} = Ioc a b := rfl\n\nlemma Ici_def (a : \u03b1) : {x | a \u2264 x} = Ici a := rfl\n\nlemma Ioi_def (a : \u03b1) : {x | a < x} = Ioi a := rfl\n\n@[simp] lemma mem_Ioo : x \u2208 Ioo a b \u2194 a < x \u2227 x < b := iff.rfl\n@[simp] lemma mem_Ico : x \u2208 Ico a b \u2194 a \u2264 x \u2227 x < b := iff.rfl\n@[simp] lemma mem_Iio : x \u2208 Iio b \u2194 x < b := iff.rfl\n@[simp] lemma mem_Icc : x \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b := iff.rfl\n@[simp] lemma mem_Iic : x \u2208 Iic b \u2194 x \u2264 b := iff.rfl\n@[simp] lemma mem_Ioc : x \u2208 Ioc a b \u2194 a < x \u2227 x \u2264 b := iff.rfl\n@[simp] lemma mem_Ici : x \u2208 Ici a \u2194 a \u2264 x := iff.rfl\n@[simp] lemma mem_Ioi : x \u2208 Ioi a \u2194 a < x := iff.rfl\n\ninstance decidable_mem_Ioo [decidable (a < x \u2227 x < b)] : decidable (x \u2208 Ioo a b) := by assumption\ninstance decidable_mem_Ico [decidable (a \u2264 x \u2227 x < b)] : decidable (x \u2208 Ico a b) := by assumption\ninstance decidable_mem_Iio [decidable (x < b)] : decidable (x \u2208 Iio b) := by assumption\ninstance decidable_mem_Icc [decidable (a \u2264 x \u2227 x \u2264 b)] : decidable (x \u2208 Icc a b) := by assumption\ninstance decidable_mem_Iic [decidable (x \u2264 b)] : decidable (x \u2208 Iic b) := by assumption\ninstance decidable_mem_Ioc [decidable (a < x \u2227 x \u2264 b)] : decidable (x \u2208 Ioc a b) := by assumption\ninstance decidable_mem_Ici [decidable (a \u2264 x)] : decidable (x \u2208 Ici a) := by assumption\ninstance decidable_mem_Ioi [decidable (a < x)] : decidable (x \u2208 Ioi a) := by assumption\n\n@[simp] lemma left_mem_Ioo : a \u2208 Ioo a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma left_mem_Ico : a \u2208 Ico a b \u2194 a < b := by simp [le_refl]\n@[simp] lemma left_mem_Icc : a \u2208 Icc a b \u2194 a \u2264 b := by simp [le_refl]\n@[simp] lemma left_mem_Ioc : a \u2208 Ioc a b \u2194 false := by simp [lt_irrefl]\nlemma left_mem_Ici : a \u2208 Ici a := by simp\n@[simp] lemma right_mem_Ioo : b \u2208 Ioo a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma right_mem_Ico : b \u2208 Ico a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma right_mem_Icc : b \u2208 Icc a b \u2194 a \u2264 b := by simp [le_refl]\n@[simp] lemma right_mem_Ioc : b \u2208 Ioc a b \u2194 a < b := by simp [le_refl]\nlemma right_mem_Iic : a \u2208 Iic a := by simp\n\n@[simp] lemma dual_Ici : Ici (to_dual a) = of_dual \u207b\u00b9' Iic a := rfl\n@[simp] lemma dual_Iic : Iic (to_dual a) = of_dual \u207b\u00b9' Ici a := rfl\n@[simp] lemma dual_Ioi : Ioi (to_dual a) = of_dual \u207b\u00b9' Iio a := rfl\n@[simp] lemma dual_Iio : Iio (to_dual a) = of_dual \u207b\u00b9' Ioi a := rfl\n@[simp] lemma dual_Icc : Icc (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Icc b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ioc : Ioc (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ico b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ico : Ico (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ioc b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ioo : Ioo (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ioo b a :=\nset.ext $ \u03bb x, and_comm _ _\n\n@[simp] lemma nonempty_Icc : (Icc a b).nonempty \u2194 a \u2264 b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans hx.2, \u03bb h, \u27e8a, left_mem_Icc.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ico : (Ico a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans_lt hx.2, \u03bb h, \u27e8a, left_mem_Ico.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ioc : (Ioc a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans_le hx.2, \u03bb h, \u27e8b, right_mem_Ioc.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ici : (Ici a).nonempty := \u27e8a, left_mem_Ici\u27e9\n\n@[simp] lemma nonempty_Iic : (Iic a).nonempty := \u27e8a, right_mem_Iic\u27e9\n\n@[simp] lemma nonempty_Ioo [densely_ordered \u03b1] : (Ioo a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, ha, hb\u27e9, ha.trans hb, exists_between\u27e9\n\n@[simp] lemma nonempty_Ioi [no_max_order \u03b1] : (Ioi a).nonempty := exists_gt a\n@[simp] lemma nonempty_Iio [no_min_order \u03b1] : (Iio a).nonempty := exists_lt a\n\nlemma nonempty_Icc_subtype (h : a \u2264 b) : nonempty (Icc a b) :=\nnonempty.to_subtype (nonempty_Icc.mpr h)\n\nlemma nonempty_Ico_subtype (h : a < b) : nonempty (Ico a b) :=\nnonempty.to_subtype (nonempty_Ico.mpr h)\n\nlemma nonempty_Ioc_subtype (h : a < b) : nonempty (Ioc a b) :=\nnonempty.to_subtype (nonempty_Ioc.mpr h)\n\n/-- An interval `Ici a` is nonempty. -/\ninstance nonempty_Ici_subtype : nonempty (Ici a) :=\nnonempty.to_subtype nonempty_Ici\n\n/-- An interval `Iic a` is nonempty. -/\ninstance nonempty_Iic_subtype : nonempty (Iic a) :=\nnonempty.to_subtype nonempty_Iic\n\nlemma nonempty_Ioo_subtype [densely_ordered \u03b1] (h : a < b) : nonempty (Ioo a b) :=\nnonempty.to_subtype (nonempty_Ioo.mpr h)\n\n/-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/\ninstance nonempty_Ioi_subtype [no_max_order \u03b1] : nonempty (Ioi a) :=\nnonempty.to_subtype nonempty_Ioi\n\n/-- In an order without minimal elements, the intervals `Iio` are nonempty. -/\ninstance nonempty_Iio_subtype [no_min_order \u03b1] : nonempty (Iio a) :=\nnonempty.to_subtype nonempty_Iio\n\ninstance [no_min_order \u03b1] : no_min_order (Iio a) :=\n\u27e8\u03bb a, let \u27e8b, hb\u27e9 := exists_lt (a : \u03b1) in \u27e8\u27e8b, lt_trans hb a.2\u27e9, hb\u27e9\u27e9\n\ninstance [no_min_order \u03b1] : no_min_order (Iic a) :=\n\u27e8\u03bb a, let \u27e8b, hb\u27e9 := exists_lt (a : \u03b1) in \u27e8\u27e8b, hb.le.trans a.2\u27e9, hb\u27e9\u27e9\n\ninstance [no_max_order \u03b1] : no_max_order (Ioi a) :=\norder_dual.no_max_order (Iio (to_dual a))\n\ninstance [no_max_order \u03b1] : no_max_order (Ici a) :=\norder_dual.no_max_order (Iic (to_dual a))\n\n@[simp] lemma Icc_eq_empty (h : \u00aca \u2264 b) : Icc a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans hb)\n\n@[simp] lemma Ico_eq_empty (h : \u00aca < b) : Ico a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans_lt hb)\n\n@[simp] lemma Ioc_eq_empty (h : \u00aca < b) : Ioc a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans_le hb)\n\n@[simp] lemma Ioo_eq_empty (h : \u00aca < b) : Ioo a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9,  h (ha.trans hb)\n\n@[simp] lemma Icc_eq_empty_of_lt (h : b < a) : Icc a b = \u2205 :=\nIcc_eq_empty h.not_le\n\n@[simp] lemma Ico_eq_empty_of_le (h : b \u2264 a) : Ico a b = \u2205 :=\nIco_eq_empty h.not_lt\n\n@[simp] lemma Ioc_eq_empty_of_le (h : b \u2264 a) : Ioc a b = \u2205 :=\nIoc_eq_empty h.not_lt\n\n@[simp] lemma Ioo_eq_empty_of_le (h : b \u2264 a) : Ioo a b = \u2205 :=\nIoo_eq_empty h.not_lt\n\n@[simp] lemma Ico_self (a : \u03b1) : Ico a a = \u2205 := Ico_eq_empty $ lt_irrefl _\n@[simp] lemma Ioc_self (a : \u03b1) : Ioc a a = \u2205 := Ioc_eq_empty $ lt_irrefl _\n@[simp] lemma Ioo_self (a : \u03b1) : Ioo a a = \u2205 := Ioo_eq_empty $ lt_irrefl _\n\nlemma Ici_subset_Ici : Ici a \u2286 Ici b \u2194 b \u2264 a :=\n\u27e8\u03bb h, h $ left_mem_Ici, \u03bb h x hx, h.trans hx\u27e9\n\nlemma Iic_subset_Iic : Iic a \u2286 Iic b \u2194 a \u2264 b := @Ici_subset_Ici \u03b1\u1d52\u1d48 _ _ _\n\nlemma Ici_subset_Ioi : Ici a \u2286 Ioi b \u2194 b < a :=\n\u27e8\u03bb h, h left_mem_Ici, \u03bb h x hx, h.trans_le hx\u27e9\n\nlemma Iic_subset_Iio : Iic a \u2286 Iio b \u2194 a < b :=\n\u27e8\u03bb h, h right_mem_Iic, \u03bb h x hx, lt_of_le_of_lt hx h\u27e9\n\nlemma Ioo_subset_Ioo (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ioo a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans_lt hx\u2081, hx\u2082.trans_le h\u2082\u27e9\n\nlemma Ioo_subset_Ioo_left (h : a\u2081 \u2264 a\u2082) : Ioo a\u2082 b \u2286 Ioo a\u2081 b :=\nIoo_subset_Ioo h le_rfl\n\nlemma Ioo_subset_Ioo_right (h : b\u2081 \u2264 b\u2082) : Ioo a b\u2081 \u2286 Ioo a b\u2082 :=\nIoo_subset_Ioo le_rfl h\n\nlemma Ico_subset_Ico (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ico a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans hx\u2081, hx\u2082.trans_le h\u2082\u27e9\n\nlemma Ico_subset_Ico_left (h : a\u2081 \u2264 a\u2082) : Ico a\u2082 b \u2286 Ico a\u2081 b :=\nIco_subset_Ico h le_rfl\n\nlemma Ico_subset_Ico_right (h : b\u2081 \u2264 b\u2082) : Ico a b\u2081 \u2286 Ico a b\u2082 :=\nIco_subset_Ico le_rfl h\n\nlemma Icc_subset_Icc (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Icc a\u2081 b\u2081 \u2286 Icc a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans hx\u2081, le_trans hx\u2082 h\u2082\u27e9\n\nlemma Icc_subset_Icc_left (h : a\u2081 \u2264 a\u2082) : Icc a\u2082 b \u2286 Icc a\u2081 b :=\nIcc_subset_Icc h le_rfl\n\nlemma Icc_subset_Icc_right (h : b\u2081 \u2264 b\u2082) : Icc a b\u2081 \u2286 Icc a b\u2082 :=\nIcc_subset_Icc le_rfl h\n\nlemma Icc_subset_Ioo (ha : a\u2082 < a\u2081) (hb : b\u2081 < b\u2082) :\n  Icc a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 :=\n\u03bb x hx, \u27e8ha.trans_le hx.1, hx.2.trans_lt hb\u27e9\n\nlemma Icc_subset_Ici_self : Icc a b \u2286 Ici a := \u03bb x, and.left\n\nlemma Icc_subset_Iic_self : Icc a b \u2286 Iic b := \u03bb x, and.right\n\nlemma Ioc_subset_Iic_self : Ioc a b \u2286 Iic b := \u03bb x, and.right\n\nlemma Ioc_subset_Ioc (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ioc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans_lt hx\u2081, hx\u2082.trans h\u2082\u27e9\n\nlemma Ioc_subset_Ioc_left (h : a\u2081 \u2264 a\u2082) : Ioc a\u2082 b \u2286 Ioc a\u2081 b :=\nIoc_subset_Ioc h le_rfl\n\nlemma Ioc_subset_Ioc_right (h : b\u2081 \u2264 b\u2082) : Ioc a b\u2081 \u2286 Ioc a b\u2082 :=\nIoc_subset_Ioc le_rfl h\n\nlemma Ico_subset_Ioo_left (h\u2081 : a\u2081 < a\u2082) : Ico a\u2082 b \u2286 Ioo a\u2081 b :=\n\u03bb x, and.imp_left h\u2081.trans_le\n\nlemma Ioc_subset_Ioo_right (h : b\u2081 < b\u2082) : Ioc a b\u2081 \u2286 Ioo a b\u2082 :=\n\u03bb x, and.imp_right $ \u03bb h', h'.trans_lt h\n\nlemma Icc_subset_Ico_right (h\u2081 : b\u2081 < b\u2082) : Icc a b\u2081 \u2286 Ico a b\u2082 :=\n\u03bb x, and.imp_right $ \u03bb h\u2082, h\u2082.trans_lt h\u2081\n\nlemma Ioo_subset_Ico_self : Ioo a b \u2286 Ico a b := \u03bb x, and.imp_left le_of_lt\n\nlemma Ioo_subset_Ioc_self : Ioo a b \u2286 Ioc a b := \u03bb x, and.imp_right le_of_lt\n\nlemma Ico_subset_Icc_self : Ico a b \u2286 Icc a b := \u03bb x, and.imp_right le_of_lt\n\nlemma Ioc_subset_Icc_self : Ioc a b \u2286 Icc a b := \u03bb x, and.imp_left le_of_lt\n\nlemma Ioo_subset_Icc_self : Ioo a b \u2286 Icc a b :=\nsubset.trans Ioo_subset_Ico_self Ico_subset_Icc_self\n\nlemma Ico_subset_Iio_self : Ico a b \u2286 Iio b := \u03bb x, and.right\n\nlemma Ioo_subset_Iio_self : Ioo a b \u2286 Iio b := \u03bb x, and.right\n\nlemma Ioc_subset_Ioi_self : Ioc a b \u2286 Ioi a := \u03bb x, and.left\n\nlemma Ioo_subset_Ioi_self : Ioo a b \u2286 Ioi a := \u03bb x, and.left\n\nlemma Ioi_subset_Ici_self : Ioi a \u2286 Ici a := \u03bb x hx, le_of_lt hx\n\nlemma Iio_subset_Iic_self : Iio a \u2286 Iic a := \u03bb x hx, le_of_lt hx\n\nlemma Ico_subset_Ici_self : Ico a b \u2286 Ici a := \u03bb x, and.left\n\nlemma Ioi_ssubset_Ici_self  : Ioi a \u2282 Ici a := \u27e8Ioi_subset_Ici_self, \u03bb h, lt_irrefl a (h le_rfl)\u27e9\n\nlemma Iio_ssubset_Iic_self : Iio a \u2282 Iic a := @Ioi_ssubset_Ici_self \u03b1\u1d52\u1d48 _ _\n\nlemma Icc_subset_Icc_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Icc a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans hx, hx'.trans h'\u27e9\u27e9\n\nlemma Icc_subset_Ioo_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 \u2194 a\u2082 < a\u2081 \u2227 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans_le hx, hx'.trans_lt h'\u27e9\u27e9\n\nlemma Icc_subset_Ico_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans hx, hx'.trans_lt h'\u27e9\u27e9\n\nlemma Icc_subset_Ioc_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 \u2194 a\u2082 < a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans_le hx, hx'.trans h'\u27e9\u27e9\n\nlemma Icc_subset_Iio_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Iio b\u2082 \u2194 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, h \u27e8h\u2081, le_rfl\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, hx'.trans_lt h\u27e9\n\nlemma Icc_subset_Ioi_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioi a\u2082 \u2194 a\u2082 < a\u2081 :=\n\u27e8\u03bb h, h \u27e8le_rfl, h\u2081\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, h.trans_le hx\u27e9\n\nlemma Icc_subset_Iic_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Iic b\u2082 \u2194 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, h \u27e8h\u2081, le_rfl\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, hx'.trans h\u27e9\n\nlemma Icc_subset_Ici_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ici a\u2082 \u2194 a\u2082 \u2264 a\u2081 :=\n\u27e8\u03bb h, h \u27e8le_rfl, h\u2081\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, h.trans hx\u27e9\n\nlemma Icc_ssubset_Icc_left (hI : a\u2082 \u2264 b\u2082) (ha : a\u2082 < a\u2081) (hb : b\u2081 \u2264 b\u2082) :\n  Icc a\u2081 b\u2081 \u2282 Icc a\u2082 b\u2082 :=\n(ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr\n  \u27e8a\u2082, left_mem_Icc.mpr hI, not_and.mpr (\u03bb f g, lt_irrefl a\u2082 (ha.trans_le f))\u27e9\n\nlemma Icc_ssubset_Icc_right (hI : a\u2082 \u2264 b\u2082) (ha : a\u2082 \u2264 a\u2081) (hb : b\u2081 < b\u2082) :\n  Icc a\u2081 b\u2081 \u2282 Icc a\u2082 b\u2082 :=\n(ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr\n  \u27e8b\u2082, right_mem_Icc.mpr hI, (\u03bb f, lt_irrefl b\u2081 (hb.trans_le f.2))\u27e9\n\n/-- If `a \u2264 b`, then `(b, +\u221e) \u2286 (a, +\u221e)`. In preorders, this is just an implication. If you need\nthe equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/\nlemma Ioi_subset_Ioi (h : a \u2264 b) : Ioi b \u2286 Ioi a :=\n\u03bb x hx, h.trans_lt hx\n\n/-- If `a \u2264 b`, then `(b, +\u221e) \u2286 [a, +\u221e)`. In preorders, this is just an implication. If you need\nthe equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/\nlemma Ioi_subset_Ici (h : a \u2264 b) : Ioi b \u2286 Ici a :=\nsubset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self\n\n/-- If `a \u2264 b`, then `(-\u221e, a) \u2286 (-\u221e, b)`. In preorders, this is just an implication. If you need\nthe equivalence in linear orders, use `Iio_subset_Iio_iff`. -/\nlemma Iio_subset_Iio (h : a \u2264 b) : Iio a \u2286 Iio b :=\n\u03bb x hx, lt_of_lt_of_le hx h\n\n/-- If `a \u2264 b`, then `(-\u221e, a) \u2286 (-\u221e, b]`. In preorders, this is just an implication. If you need\nthe equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/\nlemma Iio_subset_Iic (h : a \u2264 b) : Iio a \u2286 Iic b :=\nsubset.trans (Iio_subset_Iio h) Iio_subset_Iic_self\n\nlemma Ici_inter_Iic : Ici a \u2229 Iic b = Icc a b := rfl\nlemma Ici_inter_Iio : Ici a \u2229 Iio b = Ico a b := rfl\nlemma Ioi_inter_Iic : Ioi a \u2229 Iic b = Ioc a b := rfl\nlemma Ioi_inter_Iio : Ioi a \u2229 Iio b = Ioo a b := rfl\nlemma Iic_inter_Ici : Iic a \u2229 Ici b = Icc b a := inter_comm _ _\nlemma Iio_inter_Ici : Iio a \u2229 Ici b = Ico b a := inter_comm _ _\nlemma Iic_inter_Ioi : Iic a \u2229 Ioi b = Ioc b a := inter_comm _ _\nlemma Iio_inter_Ioi : Iio a \u2229 Ioi b = Ioo b a := inter_comm _ _\n\nlemma mem_Icc_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Icc a b := Ioo_subset_Icc_self h\nlemma mem_Ico_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Ico a b := Ioo_subset_Ico_self h\nlemma mem_Ioc_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Ioc a b := Ioo_subset_Ioc_self h\nlemma mem_Icc_of_Ico (h : x \u2208 Ico a b) : x \u2208 Icc a b := Ico_subset_Icc_self h\nlemma mem_Icc_of_Ioc (h : x \u2208 Ioc a b) : x \u2208 Icc a b := Ioc_subset_Icc_self h\nlemma mem_Ici_of_Ioi (h : x \u2208 Ioi a) : x \u2208 Ici a := Ioi_subset_Ici_self h\nlemma mem_Iic_of_Iio (h : x \u2208 Iio a) : x \u2208 Iic a := Iio_subset_Iic_self h\n\nlemma Icc_eq_empty_iff : Icc a b = \u2205 \u2194 \u00aca \u2264 b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc]\n\nlemma Ico_eq_empty_iff : Ico a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico]\n\nlemma Ioc_eq_empty_iff : Ioc a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc]\n\nlemma Ioo_eq_empty_iff [densely_ordered \u03b1] : Ioo a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo]\n\nlemma _root_.is_top.Iic_eq (h : is_top a) : Iic a = univ := eq_univ_of_forall h\nlemma _root_.is_bot.Ici_eq (h : is_bot a) : Ici a = univ := eq_univ_of_forall h\nlemma _root_.is_max.Ioi_eq (h : is_max a) : Ioi a = \u2205 := eq_empty_of_subset_empty $ \u03bb b, h.not_lt\nlemma _root_.is_min.Iio_eq (h : is_min a) : Iio a = \u2205 := eq_empty_of_subset_empty $ \u03bb b, h.not_lt\n\nlemma Iic_inter_Ioc_of_le (h : a \u2264 c) : Iic a \u2229 Ioc b c = Ioc b a :=\next $ \u03bb x, \u27e8\u03bb H, \u27e8H.2.1, H.1\u27e9, \u03bb H, \u27e8H.2, H.1, H.2.trans h\u27e9\u27e9\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] {a b c : \u03b1}\n\n@[simp] lemma Icc_self (a : \u03b1) : Icc a a = {a} :=\nset.ext $ by simp [Icc, le_antisymm_iff, and_comm]\n\n@[simp] lemma Icc_eq_singleton_iff : Icc a b = {c} \u2194 a = c \u2227 b = c :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { have hab : a \u2264 b := nonempty_Icc.1 (h.symm.subst $ singleton_nonempty c),\n    exact \u27e8eq_of_mem_singleton $ h.subst $ left_mem_Icc.2 hab,\n      eq_of_mem_singleton $ h.subst $ right_mem_Icc.2 hab\u27e9 },\n  { rintro \u27e8rfl, rfl\u27e9,\n    exact Icc_self _ }\nend\n\n@[simp] lemma Icc_diff_left : Icc a b \\ {a} = Ioc a b :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, eq_comm, and.right_comm]\n\n@[simp] lemma Icc_diff_right : Icc a b \\ {b} = Ico a b :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, and_assoc]\n\n@[simp] lemma Ico_diff_left : Ico a b \\ {a} = Ioo a b :=\next $ \u03bb x, by simp [and.right_comm, \u2190 lt_iff_le_and_ne, eq_comm]\n\n@[simp] lemma Ioc_diff_right : Ioc a b \\ {b} = Ioo a b :=\next $ \u03bb x, by simp [and_assoc, \u2190 lt_iff_le_and_ne]\n\n@[simp] lemma Icc_diff_both : Icc a b \\ {a, b} = Ioo a b :=\nby rw [insert_eq, \u2190 diff_diff, Icc_diff_left, Ioc_diff_right]\n\n@[simp] lemma Ici_diff_left : Ici a \\ {a} = Ioi a :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, eq_comm]\n\n@[simp] lemma Iic_diff_right : Iic a \\ {a} = Iio a :=\next $ \u03bb x, by simp [lt_iff_le_and_ne]\n\n@[simp] lemma Ico_diff_Ioo_same (h : a < b) : Ico a b \\ Ioo a b = {a} :=\nby rw [\u2190 Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 $ left_mem_Ico.2 h)]\n\n@[simp] lemma Ioc_diff_Ioo_same (h : a < b) : Ioc a b \\ Ioo a b = {b} :=\nby rw [\u2190 Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 $ right_mem_Ioc.2 h)]\n\n@[simp] lemma Icc_diff_Ico_same (h : a \u2264 b) : Icc a b \\ Ico a b = {b} :=\nby rw [\u2190 Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 $ right_mem_Icc.2 h)]\n\n@[simp] lemma Icc_diff_Ioc_same (h : a \u2264 b) : Icc a b \\ Ioc a b = {a} :=\nby rw [\u2190 Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 $ left_mem_Icc.2 h)]\n\n@[simp] lemma Icc_diff_Ioo_same (h : a \u2264 b) : Icc a b \\ Ioo a b = {a, b} :=\nby { rw [\u2190 Icc_diff_both, diff_diff_cancel_left], simp [insert_subset, h] }\n\n@[simp] lemma Ici_diff_Ioi_same : Ici a \\ Ioi a = {a} :=\nby rw [\u2190 Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)]\n\n@[simp] lemma Iic_diff_Iio_same : Iic a \\ Iio a = {a} :=\nby rw [\u2190 Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)]\n\n@[simp] lemma Ioi_union_left : Ioi a \u222a {a} = Ici a := ext $ \u03bb x, by simp [eq_comm, le_iff_eq_or_lt]\n\n@[simp] lemma Iio_union_right : Iio a \u222a {a} = Iic a := ext $ \u03bb x, le_iff_lt_or_eq.symm\n\nlemma Ioo_union_left (hab : a < b) : Ioo a b \u222a {a} = Ico a b :=\nby rw [\u2190 Ico_diff_left, diff_union_self,\n  union_eq_self_of_subset_right (singleton_subset_iff.2 $ left_mem_Ico.2 hab)]\n\nlemma Ioo_union_right (hab : a < b) : Ioo a b \u222a {b} = Ioc a b :=\nby simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual\n\nlemma Ioc_union_left (hab : a \u2264 b) : Ioc a b \u222a {a} = Icc a b :=\nby rw [\u2190 Icc_diff_left, diff_union_self,\n  union_eq_self_of_subset_right (singleton_subset_iff.2 $ left_mem_Icc.2 hab)]\n\nlemma Ico_union_right (hab : a \u2264 b) : Ico a b \u222a {b} = Icc a b :=\nby simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual\n\n@[simp] lemma Ico_insert_right (h : a \u2264 b) : insert b (Ico a b) = Icc a b :=\nby rw [insert_eq, union_comm, Ico_union_right h]\n\n@[simp] lemma Ioc_insert_left (h : a \u2264 b) : insert a (Ioc a b) = Icc a b :=\nby rw [insert_eq, union_comm, Ioc_union_left h]\n\n@[simp] lemma Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b :=\nby rw [insert_eq, union_comm, Ioo_union_left h]\n\n@[simp] lemma Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b :=\nby rw [insert_eq, union_comm, Ioo_union_right h]\n\n@[simp] lemma Iio_insert : insert a (Iio a) = Iic a := ext $ \u03bb _, le_iff_eq_or_lt.symm\n\n@[simp] lemma Ioi_insert : insert a (Ioi a) = Ici a :=\next $ \u03bb _, (or_congr_left' eq_comm).trans le_iff_eq_or_lt.symm\n\nlemma mem_Ici_Ioi_of_subset_of_subset {s : set \u03b1} (ho : Ioi a \u2286 s) (hc : s \u2286 Ici a) :\n  s \u2208 ({Ici a, Ioi a} : set (set \u03b1)) :=\nclassical.by_cases\n  (\u03bb h : a \u2208 s, or.inl $ subset.antisymm hc $ by rw [\u2190 Ioi_union_left, union_subset_iff]; simp *)\n  (\u03bb h, or.inr $ subset.antisymm (\u03bb x hx, lt_of_le_of_ne (hc hx) (\u03bb heq, h $ heq.symm \u25b8 hx)) ho)\n\nlemma mem_Iic_Iio_of_subset_of_subset {s : set \u03b1} (ho : Iio a \u2286 s) (hc : s \u2286 Iic a) :\n  s \u2208 ({Iic a, Iio a} : set (set \u03b1)) :=\n@mem_Ici_Ioi_of_subset_of_subset \u03b1\u1d52\u1d48 _ a s ho hc\n\nlemma mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : set \u03b1} (ho : Ioo a b \u2286 s) (hc : s \u2286 Icc a b) :\n  s \u2208 ({Icc a b, Ico a b, Ioc a b, Ioo a b} : set (set \u03b1)) :=\nbegin\n  classical,\n  by_cases ha : a \u2208 s; by_cases hb : b \u2208 s,\n  { refine or.inl (subset.antisymm hc _),\n    rwa [\u2190 Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha,\n      \u2190 Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho },\n  { refine (or.inr $ or.inl $ subset.antisymm _ _),\n    { rw [\u2190 Icc_diff_right],\n      exact subset_diff_singleton hc hb },\n    { rwa [\u2190 Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho } },\n  { refine (or.inr $ or.inr $ or.inl $ subset.antisymm _ _),\n    { rw [\u2190 Icc_diff_left],\n      exact subset_diff_singleton hc ha },\n    { rwa [\u2190 Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho } },\n  { refine (or.inr $ or.inr $ or.inr $ subset.antisymm _ ho),\n    rw [\u2190 Ico_diff_left, \u2190 Icc_diff_right],\n    apply_rules [subset_diff_singleton] }\nend\n\nlemma eq_left_or_mem_Ioo_of_mem_Ico {x : \u03b1} (hmem : x \u2208 Ico a b) :\n  x = a \u2228 x \u2208 Ioo a b :=\nhmem.1.eq_or_gt.imp_right $ \u03bb h, \u27e8h, hmem.2\u27e9\n\nlemma eq_right_or_mem_Ioo_of_mem_Ioc {x : \u03b1} (hmem : x \u2208 Ioc a b) :\n  x = b \u2228 x \u2208 Ioo a b :=\nhmem.2.eq_or_lt.imp_right $ and.intro hmem.1\n\nlemma eq_endpoints_or_mem_Ioo_of_mem_Icc {x : \u03b1} (hmem : x \u2208 Icc a b) :\n  x = a \u2228 x = b \u2228 x \u2208 Ioo a b :=\nhmem.1.eq_or_gt.imp_right $ \u03bb h, eq_right_or_mem_Ioo_of_mem_Ioc \u27e8h, hmem.2\u27e9\n\nlemma _root_.is_max.Ici_eq (h : is_max a) : Ici a = {a} :=\neq_singleton_iff_unique_mem.2 \u27e8left_mem_Ici, \u03bb b, h.eq_of_ge\u27e9\n\nlemma _root_.is_min.Iic_eq (h : is_min a) : Iic a = {a} := h.to_dual.Ici_eq\n\nlemma Ici_injective : injective (Ici : \u03b1 \u2192 set \u03b1) := \u03bb a b, eq_of_forall_ge_iff \u2218 set.ext_iff.1\nlemma Iic_injective : injective (Iic : \u03b1 \u2192 set \u03b1) := \u03bb a b, eq_of_forall_le_iff \u2218 set.ext_iff.1\n\nlemma Ici_inj : Ici a = Ici b \u2194 a = b := Ici_injective.eq_iff\nlemma Iic_inj : Iic a = Iic b \u2194 a = b := Iic_injective.eq_iff\n\nend partial_order\n\nsection order_top\n\n@[simp] lemma Ici_top [partial_order \u03b1] [order_top \u03b1] : Ici (\u22a4 : \u03b1) = {\u22a4} := is_max_top.Ici_eq\n\nvariables [preorder \u03b1] [order_top \u03b1] {a : \u03b1}\n\n@[simp] lemma Ioi_top : Ioi (\u22a4 : \u03b1) = \u2205 := is_max_top.Ioi_eq\n@[simp] lemma Iic_top : Iic (\u22a4 : \u03b1) = univ := is_top_top.Iic_eq\n@[simp] lemma Icc_top : Icc a \u22a4 = Ici a := by simp [\u2190 Ici_inter_Iic]\n@[simp] lemma Ioc_top : Ioc a \u22a4 = Ioi a := by simp [\u2190 Ioi_inter_Iic]\n\nend order_top\n\nsection order_bot\n\n@[simp] lemma Iic_bot [partial_order \u03b1] [order_bot \u03b1] : Iic (\u22a5 : \u03b1) = {\u22a5} :=\nis_min_bot.Iic_eq\n\nvariables [preorder \u03b1] [order_bot \u03b1] {a : \u03b1}\n\n@[simp] lemma Iio_bot : Iio (\u22a5 : \u03b1) = \u2205 := is_min_bot.Iio_eq\n@[simp] lemma Ici_bot : Ici (\u22a5 : \u03b1) = univ := is_bot_bot.Ici_eq\n@[simp] lemma Icc_bot : Icc \u22a5 a = Iic a := by simp [\u2190 Ici_inter_Iic]\n@[simp] lemma Ico_bot : Ico \u22a5 a = Iio a := by simp [\u2190 Ici_inter_Iio]\n\nend order_bot\n\nlemma Icc_bot_top [partial_order \u03b1] [bounded_order \u03b1] : Icc (\u22a5 : \u03b1) \u22a4 = univ := by simp\n\nsection linear_order\nvariables [linear_order \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c d : \u03b1}\n\nlemma not_mem_Ici : c \u2209 Ici a \u2194 c < a := not_le\n\nlemma not_mem_Iic : c \u2209 Iic b \u2194 b < c := not_le\n\nlemma not_mem_Icc_of_lt (ha : c < a) : c \u2209 Icc a b :=\nnot_mem_subset Icc_subset_Ici_self $ not_mem_Ici.mpr ha\n\nlemma not_mem_Icc_of_gt (hb : b < c) : c \u2209 Icc a b :=\nnot_mem_subset Icc_subset_Iic_self $ not_mem_Iic.mpr hb\n\nlemma not_mem_Ico_of_lt (ha : c < a) : c \u2209 Ico a b :=\nnot_mem_subset Ico_subset_Ici_self $ not_mem_Ici.mpr ha\n\nlemma not_mem_Ioc_of_gt (hb : b < c) : c \u2209 Ioc a b :=\nnot_mem_subset Ioc_subset_Iic_self $ not_mem_Iic.mpr hb\n\nlemma not_mem_Ioi : c \u2209 Ioi a \u2194 c \u2264 a := not_lt\n\nlemma not_mem_Iio : c \u2209 Iio b \u2194 b \u2264 c := not_lt\n\n@[simp] lemma not_mem_Ioi_self : a \u2209 Ioi a := lt_irrefl _\n\n@[simp] lemma not_mem_Iio_self : b \u2209 Iio b := lt_irrefl _\n\nlemma not_mem_Ioc_of_le (ha : c \u2264 a) : c \u2209 Ioc a b :=\nnot_mem_subset Ioc_subset_Ioi_self $ not_mem_Ioi.mpr ha\n\nlemma not_mem_Ico_of_ge (hb : b \u2264 c) : c \u2209 Ico a b :=\nnot_mem_subset Ico_subset_Iio_self $ not_mem_Iio.mpr hb\n\nlemma not_mem_Ioo_of_le (ha : c \u2264 a) : c \u2209 Ioo a b :=\nnot_mem_subset Ioo_subset_Ioi_self $ not_mem_Ioi.mpr ha\n\nlemma not_mem_Ioo_of_ge (hb : b \u2264 c) : c \u2209 Ioo a b :=\nnot_mem_subset Ioo_subset_Iio_self $ not_mem_Iio.mpr hb\n\n@[simp] lemma compl_Iic : (Iic a)\u1d9c = Ioi a := ext $ \u03bb _, not_le\n@[simp] lemma compl_Ici : (Ici a)\u1d9c = Iio a := ext $ \u03bb _, not_le\n@[simp] lemma compl_Iio : (Iio a)\u1d9c = Ici a := ext $ \u03bb _, not_lt\n@[simp] lemma compl_Ioi : (Ioi a)\u1d9c = Iic a := ext $ \u03bb _, not_lt\n\n@[simp] lemma Ici_diff_Ici : Ici a \\ Ici b = Ico a b :=\nby rw [diff_eq, compl_Ici, Ici_inter_Iio]\n\n@[simp] lemma Ici_diff_Ioi : Ici a \\ Ioi b = Icc a b :=\nby rw [diff_eq, compl_Ioi, Ici_inter_Iic]\n\n@[simp] lemma Ioi_diff_Ioi : Ioi a \\ Ioi b = Ioc a b :=\nby rw [diff_eq, compl_Ioi, Ioi_inter_Iic]\n\n@[simp] lemma Ioi_diff_Ici : Ioi a \\ Ici b = Ioo a b :=\nby rw [diff_eq, compl_Ici, Ioi_inter_Iio]\n\n@[simp] lemma Iic_diff_Iic : Iic b \\ Iic a = Ioc a b :=\nby rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic]\n\n@[simp] lemma Iio_diff_Iic : Iio b \\ Iic a = Ioo a b :=\nby rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio]\n\n@[simp] lemma Iic_diff_Iio : Iic b \\ Iio a = Icc a b :=\nby rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic]\n\n@[simp] lemma Iio_diff_Iio : Iio b \\ Iio a = Ico a b :=\nby rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio]\n\nlemma Ioi_injective : injective (Ioi : \u03b1 \u2192 set \u03b1) := \u03bb a b, eq_of_forall_gt_iff \u2218 set.ext_iff.1\nlemma Iio_injective : injective (Iio : \u03b1 \u2192 set \u03b1) := \u03bb a b, eq_of_forall_lt_iff \u2218 set.ext_iff.1\n\nlemma Ioi_inj : Ioi a = Ioi b \u2194 a = b := Ioi_injective.eq_iff\nlemma Iio_inj : Iio a = Iio b \u2194 a = b := Iio_injective.eq_iff\n\nlemma Ico_subset_Ico_iff (h\u2081 : a\u2081 < b\u2081) :\n  Ico a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, have a\u2082 \u2264 a\u2081 \u2227 a\u2081 < b\u2082 := h \u27e8le_rfl, h\u2081\u27e9,\n  \u27e8this.1, le_of_not_lt $ \u03bb h', lt_irrefl b\u2082 (h \u27e8this.2.le, h'\u27e9).2\u27e9,\n \u03bb \u27e8h\u2081, h\u2082\u27e9, Ico_subset_Ico h\u2081 h\u2082\u27e9\n\nlemma Ioc_subset_Ioc_iff (h\u2081 : a\u2081 < b\u2081) :\n  Ioc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 \u2194 b\u2081 \u2264 b\u2082 \u2227 a\u2082 \u2264 a\u2081 :=\nby { convert @Ico_subset_Ico_iff \u03b1\u1d52\u1d48 _ b\u2081 b\u2082 a\u2081 a\u2082 h\u2081; exact (@dual_Ico \u03b1 _ _ _).symm }\n\nlemma Ioo_subset_Ioo_iff [densely_ordered \u03b1] (h\u2081 : a\u2081 < b\u2081) :\n  Ioo a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, begin\n  rcases exists_between h\u2081 with \u27e8x, xa, xb\u27e9,\n  split; refine le_of_not_lt (\u03bb h', _),\n  { have ab := (h \u27e8xa, xb\u27e9).1.trans xb,\n    exact lt_irrefl _ (h \u27e8h', ab\u27e9).1 },\n  { have ab := xa.trans (h \u27e8xa, xb\u27e9).2,\n    exact lt_irrefl _ (h \u27e8ab, h'\u27e9).2 }\nend, \u03bb \u27e8h\u2081, h\u2082\u27e9, Ioo_subset_Ioo h\u2081 h\u2082\u27e9\n\nlemma Ico_eq_Ico_iff (h : a\u2081 < b\u2081 \u2228 a\u2082 < b\u2082) : Ico a\u2081 b\u2081 = Ico a\u2082 b\u2082 \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082 :=\n\u27e8\u03bb e, begin\n  simp [subset.antisymm_iff] at e, simp [le_antisymm_iff],\n  cases h; simp [Ico_subset_Ico_iff h] at e;\n    [ rcases e with \u27e8\u27e8h\u2081, h\u2082\u27e9, e'\u27e9, rcases e with \u27e8e', \u27e8h\u2081, h\u2082\u27e9\u27e9 ];\n    have := (Ico_subset_Ico_iff $ h\u2081.trans_lt $ h.trans_le h\u2082).1 e';\n    tauto\nend, \u03bb \u27e8h\u2081, h\u2082\u27e9, by rw [h\u2081, h\u2082]\u27e9\n\nopen_locale classical\n\n@[simp] lemma Ioi_subset_Ioi_iff : Ioi b \u2286 Ioi a \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Ioi_subset_Ioi h\u27e9,\n  by_contradiction ba,\n  exact lt_irrefl _ (h (not_le.mp ba))\nend\n\n@[simp] lemma Ioi_subset_Ici_iff [densely_ordered \u03b1] : Ioi b \u2286 Ici a \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Ioi_subset_Ici h\u27e9,\n  by_contradiction ba,\n  obtain \u27e8c, bc, ca\u27e9 : \u2203c, b < c \u2227 c < a := exists_between (not_le.mp ba),\n  exact lt_irrefl _ (ca.trans_le (h bc))\nend\n\n@[simp] lemma Iio_subset_Iio_iff : Iio a \u2286 Iio b \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Iio_subset_Iio h\u27e9,\n  by_contradiction ab,\n  exact lt_irrefl _ (h (not_le.mp ab))\nend\n\n@[simp] lemma Iio_subset_Iic_iff [densely_ordered \u03b1] : Iio a \u2286 Iic b \u2194 a \u2264 b :=\nby rw [\u2190diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt]\n\n/-! ### Unions of adjacent intervals -/\n\n/-! #### Two infinite intervals -/\n\nlemma Iic_union_Ioi_of_le (h : a \u2264 b) : Iic b \u222a Ioi a = univ :=\neq_univ_of_forall $ \u03bb x, (h.lt_or_le x).symm\n\nlemma Iio_union_Ici_of_le (h : a \u2264 b) : Iio b \u222a Ici a = univ :=\neq_univ_of_forall $ \u03bb x, (h.le_or_lt x).symm\n\nlemma Iic_union_Ici_of_le (h : a \u2264 b) : Iic b \u222a Ici a = univ :=\neq_univ_of_forall $ \u03bb x, (h.le_or_le x).symm\n\nlemma Iio_union_Ioi_of_lt (h : a < b) : Iio b \u222a Ioi a = univ :=\neq_univ_of_forall $ \u03bb x, (h.lt_or_lt x).symm\n\n@[simp] lemma Iic_union_Ici : Iic a \u222a Ici a = univ := Iic_union_Ici_of_le le_rfl\n@[simp] lemma Iio_union_Ici : Iio a \u222a Ici a = univ := Iio_union_Ici_of_le le_rfl\n@[simp] lemma Iic_union_Ioi : Iic a \u222a Ioi a = univ := Iic_union_Ioi_of_le le_rfl\n@[simp] lemma Iio_union_Ioi : Iio a \u222a Ioi a = {a}\u1d9c := ext $ \u03bb x, lt_or_lt_iff_ne\n\n/-! #### A finite and an infinite interval -/\n\nlemma Ioo_union_Ioi' (h\u2081 : c < b) :\n  Ioo a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioo, mem_Ioi, min_lt_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x < b := (le_of_not_gt hc).trans_lt h\u2081,\n    tauto },\nend\n\nlemma Ioo_union_Ioi (h : c < max a b) :\n  Ioo a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ioo_union_Ioi' h },\n  { rw min_comm,\n    simp [*, min_eq_left_of_lt] },\nend\n\nlemma Ioi_subset_Ioo_union_Ici : Ioi a \u2286 Ioo a b \u222a Ici b :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b \u222a Ici b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_le) Ioi_subset_Ioo_union_Ici\n\nlemma Ici_subset_Ico_union_Ici : Ici a \u2286 Ico a b \u222a Ici b :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ico_union_Ici_eq_Ici (h : a \u2264 b) : Ico a b \u222a Ici b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans) Ici_subset_Ico_union_Ici\n\nlemma Ico_union_Ici' (h\u2081 : c \u2264 b) :\n  Ico a b \u222a Ici c = Ici (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ico, mem_Ici, min_le_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\nend\n\nlemma Ico_union_Ici  (h : c \u2264 max a b) :\n  Ico a b \u222a Ici c = Ici (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ico_union_Ici' h },\n  { simp [*] },\nend\n\nlemma Ioi_subset_Ioc_union_Ioi : Ioi a \u2286 Ioc a b \u222a Ioi b :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ioc_union_Ioi_eq_Ioi (h : a \u2264 b) : Ioc a b \u222a Ioi b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_lt) Ioi_subset_Ioc_union_Ioi\n\nlemma Ioc_union_Ioi' (h\u2081 : c \u2264 b) :\n  Ioc a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioc, mem_Ioi, min_lt_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081,\n    tauto },\nend\n\nlemma Ioc_union_Ioi (h : c \u2264 max a b) :\n  Ioc a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ioc_union_Ioi' h },\n  { simp [*] },\nend\n\nlemma Ici_subset_Icc_union_Ioi : Ici a \u2286 Icc a b \u222a Ioi b :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Icc_union_Ioi_eq_Ici (h : a \u2264 b) : Icc a b \u222a Ioi b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left $ \u03bb hx', h.trans $ le_of_lt hx') Ici_subset_Icc_union_Ioi\n\nlemma Ioi_subset_Ioc_union_Ici : Ioi a \u2286 Ioc a b \u222a Ici b :=\nsubset.trans Ioi_subset_Ioo_union_Ici (union_subset_union_left _ Ioo_subset_Ioc_self)\n\n@[simp] lemma Ioc_union_Ici_eq_Ioi (h : a < b) : Ioc a b \u222a Ici b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_le) Ioi_subset_Ioc_union_Ici\n\nlemma Ici_subset_Icc_union_Ici : Ici a \u2286 Icc a b \u222a Ici b :=\nsubset.trans Ici_subset_Ico_union_Ici (union_subset_union_left _ Ico_subset_Icc_self)\n\n@[simp] lemma Icc_union_Ici_eq_Ici (h : a \u2264 b) : Icc a b \u222a Ici b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans) Ici_subset_Icc_union_Ici\n\nlemma Icc_union_Ici' (h\u2081 : c \u2264 b) :\n  Icc a b \u222a Ici c = Ici (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Icc, mem_Ici, min_le_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\nend\n\nlemma Icc_union_Ici (h : c \u2264 max a b) :\n  Icc a b \u222a Ici c = Ici (min a c) :=\nbegin\n  cases le_or_lt a b with hab hab; simp [hab] at h,\n  { exact Icc_union_Ici' h },\n  { cases h,\n    { simp [*] },\n    { have hca : c \u2264 a := h.trans hab.le,\n      simp [*] } },\nend\n\n/-! #### An infinite and a finite interval -/\n\nlemma Iic_subset_Iio_union_Icc : Iic b \u2286 Iio a \u222a Icc a b :=\n\u03bb x hx, (lt_or_le x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iio_union_Icc_eq_Iic (h : a \u2264 b) : Iio a \u222a Icc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx, (le_of_lt hx).trans h) and.right)\n  Iic_subset_Iio_union_Icc\n\nlemma Iio_subset_Iio_union_Ico : Iio b \u2286 Iio a \u222a Ico a b :=\n\u03bb x hx, (lt_or_le x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iio_union_Ico_eq_Iio (h : a \u2264 b) : Iio a \u222a Ico a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_lt_of_le hx' h) and.right) Iio_subset_Iio_union_Ico\n\nlemma Iio_union_Ico' (h\u2081 : c \u2264 b) :\n  Iio b \u222a Ico c d = Iio (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iio, mem_Ico, lt_max_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\nend\n\nlemma Iio_union_Ico (h : min c d \u2264 b) :\n  Iio b \u222a Ico c d = Iio (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iio_union_Ico' h },\n  { simp [*] },\nend\n\nlemma Iic_subset_Iic_union_Ioc : Iic b \u2286 Iic a \u222a Ioc a b :=\n\u03bb x hx, (le_or_lt x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iic_union_Ioc_eq_Iic (h : a \u2264 b) : Iic a \u222a Ioc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', le_trans hx' h) and.right) Iic_subset_Iic_union_Ioc\n\nlemma Iic_union_Ioc' (h\u2081 : c < b) :\n  Iic b \u222a Ioc c d = Iic (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iic, mem_Ioc, le_max_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081.le,\n    tauto },\nend\n\nlemma Iic_union_Ioc (h : min c d < b) :\n  Iic b \u222a Ioc c d = Iic (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iic_union_Ioc' h },\n  { rw max_comm,\n    simp [*, max_eq_right_of_lt h] },\nend\n\nlemma Iio_subset_Iic_union_Ioo : Iio b \u2286 Iic a \u222a Ioo a b :=\n\u03bb x hx, (le_or_lt x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iic_union_Ioo_eq_Iio (h : a < b) : Iic a \u222a Ioo a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_le_of_lt hx' h) and.right) Iio_subset_Iic_union_Ioo\n\nlemma Iio_union_Ioo' (h\u2081 : c < b) :\n  Iio b \u222a Ioo c d = Iio (max b d) :=\nbegin\n  ext x,\n  cases lt_or_le x b with hba hba,\n  { simp [hba, h\u2081] },\n  { simp only [mem_Iio, mem_union, mem_Ioo, lt_max_iff],\n    refine or_congr iff.rfl \u27e8and.right, _\u27e9,\n    exact \u03bb h\u2082, \u27e8h\u2081.trans_le hba, h\u2082\u27e9 },\nend\n\nlemma Iio_union_Ioo (h : min c d < b) :\n  Iio b \u222a Ioo c d = Iio (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iio_union_Ioo' h },\n  { rw max_comm,\n    simp [*, max_eq_right_of_lt h] },\nend\n\nlemma Iic_subset_Iic_union_Icc : Iic b \u2286 Iic a \u222a Icc a b :=\nsubset.trans Iic_subset_Iic_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)\n\n@[simp] lemma Iic_union_Icc_eq_Iic (h : a \u2264 b) : Iic a \u222a Icc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', le_trans hx' h) and.right) Iic_subset_Iic_union_Icc\n\nlemma Iic_union_Icc' (h\u2081 : c \u2264 b) :\n  Iic b \u222a Icc c d = Iic (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iic, mem_Icc, le_max_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\nend\n\nlemma Iic_union_Icc (h : min c d \u2264 b) :\n  Iic b \u222a Icc c d = Iic (max b d) :=\nbegin\n  cases le_or_lt c d with hcd hcd; simp [hcd] at h,\n  { exact Iic_union_Icc' h },\n  { cases h,\n    { have hdb : d \u2264 b := hcd.le.trans h,\n      simp [*] },\n    { simp [*] } },\nend\n\nlemma Iio_subset_Iic_union_Ico : Iio b \u2286 Iic a \u222a Ico a b :=\nsubset.trans Iio_subset_Iic_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Iic_union_Ico_eq_Iio (h : a < b) : Iic a \u222a Ico a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_le_of_lt hx' h) and.right) Iio_subset_Iic_union_Ico\n\n/-! #### Two finite intervals, `I?o` and `Ic?` -/\n\nlemma Ioo_subset_Ioo_union_Ico : Ioo a c \u2286 Ioo a b \u222a Ico b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioo_union_Ico_eq_Ioo (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioo a b \u222a Ico b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_le h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioo_subset_Ioo_union_Ico\n\nlemma Ico_subset_Ico_union_Ico : Ico a c \u2286 Ico a b \u222a Ico b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ico_union_Ico_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ico a b \u222a Ico b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_le h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Ico_subset_Ico_union_Ico\n\nlemma Ico_union_Ico' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Ico a b \u222a Ico c d = Ico (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ico, min_le_iff, lt_max_iff],\n  by_cases hc : c \u2264 x; by_cases hd : x < d,\n  { tauto },\n  { have hax : a \u2264 x := h\u2082.trans (le_of_not_gt hd),\n    tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\n  { tauto },\nend\n\nlemma Ico_union_Ico (h\u2081 : min a b \u2264 max c d) (h\u2082 : min c d \u2264 max a b) :\n  Ico a b \u222a Ico c d = Ico (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd; simp [hab, hcd] at h\u2081 h\u2082,\n  { exact Ico_union_Ico' h\u2082 h\u2081 },\n  all_goals { simp [*] },\nend\n\nlemma Icc_subset_Ico_union_Icc : Icc a c \u2286 Ico a b \u222a Icc b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ico_union_Icc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ico a b \u222a Icc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.le.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Icc_subset_Ico_union_Icc\n\nlemma Ioc_subset_Ioo_union_Icc : Ioc a c \u2286 Ioo a b \u222a Icc b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioo_union_Icc_eq_Ioc (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioo a b \u222a Icc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.le.trans h\u2082\u27e9)\n    (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioc_subset_Ioo_union_Icc\n\n/-! #### Two finite intervals, `I?c` and `Io?` -/\n\nlemma Ioo_subset_Ioc_union_Ioo : Ioo a c \u2286 Ioc a b \u222a Ioo b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioc_union_Ioo_eq_Ioo (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Ioc a b \u222a Ioo b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_lt hx.1, hx.2\u27e9))\n  Ioo_subset_Ioc_union_Ioo\n\nlemma Ico_subset_Icc_union_Ioo : Ico a c \u2286 Icc a b \u222a Ioo b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Icc_union_Ioo_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Icc a b \u222a Ioo b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9)\n    (\u03bb hx, \u27e8h\u2081.trans hx.1.le, hx.2\u27e9))\n  Ico_subset_Icc_union_Ioo\n\nlemma Icc_subset_Icc_union_Ioc : Icc a c \u2286 Icc a b \u222a Ioc b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Icc_union_Ioc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Icc a b \u222a Ioc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1.le, hx.2\u27e9))\n  Icc_subset_Icc_union_Ioc\n\nlemma Ioc_subset_Ioc_union_Ioc : Ioc a c \u2286 Ioc a b \u222a Ioc b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioc_union_Ioc_eq_Ioc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ioc a b \u222a Ioc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_lt hx.1, hx.2\u27e9))\n  Ioc_subset_Ioc_union_Ioc\n\nlemma Ioc_union_Ioc' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Ioc a b \u222a Ioc c d = Ioc (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioc, min_lt_iff, le_max_iff],\n  by_cases hc : c < x; by_cases hd : x \u2264 d,\n  { tauto },\n  { have hax : a < x := h\u2082.trans_lt (lt_of_not_ge hd),\n    tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081,\n    tauto },\n  { tauto },\nend\n\nlemma Ioc_union_Ioc (h\u2081 : min a b \u2264 max c d) (h\u2082 : min c d \u2264 max a b) :\n  Ioc a b \u222a Ioc c d = Ioc (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd; simp [hab, hcd] at h\u2081 h\u2082,\n  { exact Ioc_union_Ioc' h\u2082 h\u2081 },\n  all_goals { simp [*] },\nend\n\n/-! #### Two finite intervals with a common point -/\n\nlemma Ioo_subset_Ioc_union_Ico : Ioo a c \u2286 Ioc a b \u222a Ico b c :=\nsubset.trans Ioo_subset_Ioc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Ioc_union_Ico_eq_Ioo (h\u2081 : a < b) (h\u2082 : b < c) : Ioc a b \u222a Ico b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx', \u27e8hx'.1, hx'.2.trans_lt h\u2082\u27e9) (\u03bb hx', \u27e8h\u2081.trans_le hx'.1, hx'.2\u27e9))\n  Ioo_subset_Ioc_union_Ico\n\nlemma Ico_subset_Icc_union_Ico : Ico a c \u2286 Icc a b \u222a Ico b c :=\nsubset.trans Ico_subset_Icc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Icc_union_Ico_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Icc a b \u222a Ico b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Ico_subset_Icc_union_Ico\n\n\n\n@[simp] lemma Icc_union_Icc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Icc a b \u222a Icc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Icc_subset_Icc_union_Icc\n\nlemma Icc_union_Icc' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Icc a b \u222a Icc c d = Icc (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Icc, min_le_iff, le_max_iff],\n  by_cases hc : c \u2264 x; by_cases hd : x \u2264 d,\n  { tauto },\n  { have hax : a \u2264 x := h\u2082.trans (le_of_not_ge hd),\n    tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\n  { tauto }\nend\n\n/--\nWe cannot replace `<` by `\u2264` in the hypotheses.\nOtherwise for `b < a = d < c` the l.h.s. is `\u2205` and the r.h.s. is `{a}`.\n-/\nlemma Icc_union_Icc (h\u2081 : min a b < max c d) (h\u2082 : min c d < max a b) :\n  Icc a b \u222a Icc c d = Icc (min a c) (max b d) :=\nbegin\n  cases le_or_lt a b with hab hab; cases le_or_lt c d with hcd hcd;\n    simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, min_eq_left_of_lt,\n    min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt, hab, hcd] at h\u2081 h\u2082,\n  { exact Icc_union_Icc' h\u2082.le h\u2081.le },\n  all_goals { simp [*, min_eq_left_of_lt, max_eq_left_of_lt, min_eq_right_of_lt,\n    max_eq_right_of_lt] },\nend\n\nlemma Ioc_subset_Ioc_union_Icc : Ioc a c \u2286 Ioc a b \u222a Icc b c :=\nsubset.trans Ioc_subset_Ioc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)\n\n@[simp] lemma Ioc_union_Icc_eq_Ioc (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioc a b \u222a Icc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioc_subset_Ioc_union_Icc\n\nlemma Ioo_union_Ioo' (h\u2081 : c < b) (h\u2082 : a < d) :\n  Ioo a b \u222a Ioo c d = Ioo (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioo, min_lt_iff, lt_max_iff],\n  by_cases hc : c < x; by_cases hd : x < d,\n  { tauto },\n  { have hax : a < x := h\u2082.trans_le (le_of_not_lt hd),\n    tauto },\n  { have hxb : x < b := (le_of_not_lt hc).trans_lt h\u2081,\n    tauto },\n  { tauto }\nend\n\nlemma Ioo_union_Ioo (h\u2081 : min a b < max c d) (h\u2082 : min c d < max a b) :\n  Ioo a b \u222a Ioo c d = Ioo (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd;\n    simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, hab, hcd] at h\u2081 h\u2082,\n  { exact Ioo_union_Ioo' h\u2082 h\u2081 },\n  all_goals\n  { simp [*, min_eq_left_of_lt, min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt,\n      le_of_lt h\u2082, le_of_lt h\u2081] },\nend\n\nend linear_order\n\nsection lattice\n\nsection inf\n\nvariables [semilattice_inf \u03b1]\n\n@[simp] lemma Iic_inter_Iic {a b : \u03b1} : Iic a \u2229 Iic b = Iic (a \u2293 b) :=\nby { ext x, simp [Iic] }\n\n@[simp] lemma Ioc_inter_Iic (a b c : \u03b1) : Ioc a b \u2229 Iic c = Ioc a (b \u2293 c) :=\nby rw [\u2190 Ioi_inter_Iic, \u2190 Ioi_inter_Iic, inter_assoc, Iic_inter_Iic]\n\nend inf\n\nsection sup\n\nvariables [semilattice_sup \u03b1]\n\n@[simp] lemma Ici_inter_Ici {a b : \u03b1} : Ici a \u2229 Ici b = Ici (a \u2294 b) :=\nby { ext x, simp [Ici] }\n\n@[simp] lemma Ico_inter_Ici (a b c : \u03b1) : Ico a b \u2229 Ici c = Ico (a \u2294 c) b :=\nby rw [\u2190 Ici_inter_Iio, \u2190 Ici_inter_Iio, \u2190 Ici_inter_Ici, inter_right_comm]\n\nend sup\n\nsection both\n\nvariables [lattice \u03b1] {a b c a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1}\n\nlemma Icc_inter_Icc : Icc a\u2081 b\u2081 \u2229 Icc a\u2082 b\u2082 = Icc (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_refl\n\n@[simp] lemma Icc_inter_Icc_eq_singleton (hab : a \u2264 b) (hbc : b \u2264 c) :\n  Icc a b \u2229 Icc b c = {b} :=\nby rw [Icc_inter_Icc, sup_of_le_right hab, inf_of_le_left hbc, Icc_self]\n\nend both\nend lattice\n\nsection linear_order\nvariables [linear_order \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {a a\u2081 a\u2082 b b\u2081 b\u2082 c d : \u03b1}\n\n@[simp] lemma Ioi_inter_Ioi : Ioi a \u2229 Ioi b = Ioi (a \u2294 b) := ext $ \u03bb _, sup_lt_iff.symm\n@[simp] lemma Iio_inter_Iio : Iio a \u2229 Iio b = Iio (a \u2293 b) := ext $ \u03bb _, lt_inf_iff.symm\n\nlemma Ico_inter_Ico : Ico a\u2081 b\u2081 \u2229 Ico a\u2082 b\u2082 = Ico (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ici_inter_Iio.symm, Ici_inter_Ici.symm, Iio_inter_Iio.symm]; ac_refl\n\nlemma Ioc_inter_Ioc : Ioc a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioc (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ioi_inter_Iic.symm, Ioi_inter_Ioi.symm, Iic_inter_Iic.symm]; ac_refl\n\nlemma Ioo_inter_Ioo : Ioo a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioo (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ioi_inter_Iio.symm, Ioi_inter_Ioi.symm, Iio_inter_Iio.symm]; ac_refl\n\nlemma Ioc_inter_Ioo_of_left_lt (h : b\u2081 < b\u2082) : Ioc a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioc (max a\u2081 a\u2082) b\u2081 :=\next $ \u03bb x, by simp [and_assoc, @and.left_comm (x \u2264 _),\n  and_iff_left_iff_imp.2 (\u03bb h', lt_of_le_of_lt h' h)]\n\nlemma Ioc_inter_Ioo_of_right_le (h : b\u2082 \u2264 b\u2081) : Ioc a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioo (max a\u2081 a\u2082) b\u2082 :=\next $ \u03bb x, by simp [and_assoc, @and.left_comm (x \u2264 _),\n  and_iff_right_iff_imp.2 (\u03bb h', ((le_of_lt h').trans h))]\n\nlemma Ioo_inter_Ioc_of_left_le (h : b\u2081 \u2264 b\u2082) : Ioo a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioo (max a\u2081 a\u2082) b\u2081 :=\nby rw [inter_comm, Ioc_inter_Ioo_of_right_le h, max_comm]\n\nlemma Ioo_inter_Ioc_of_right_lt (h : b\u2082 < b\u2081) : Ioo a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioc (max a\u2081 a\u2082) b\u2082 :=\nby rw [inter_comm, Ioc_inter_Ioo_of_left_lt h, max_comm]\n\n@[simp] lemma Ico_diff_Iio : Ico a b \\ Iio c = Ico (max a c) b :=\nby rw [diff_eq, compl_Iio, Ico_inter_Ici, sup_eq_max]\n\n@[simp] lemma Ioc_diff_Ioi : Ioc a b \\ Ioi c = Ioc a (min b c) :=\next $ by simp [iff_def] {contextual:=tt}\n\n@[simp] lemma Ioc_inter_Ioi : Ioc a b \u2229 Ioi c = Ioc (a \u2294 c) b :=\nby rw [\u2190 Ioi_inter_Iic, inter_assoc, inter_comm, inter_assoc, Ioi_inter_Ioi, inter_comm,\n  Ioi_inter_Iic, sup_comm]\n\n@[simp] lemma Ico_inter_Iio : Ico a b \u2229 Iio c = Ico a (min b c) :=\next $ by simp [iff_def] {contextual:=tt}\n\n@[simp] lemma Ioc_diff_Iic : Ioc a b \\ Iic c = Ioc (max a c) b :=\nby rw [diff_eq, compl_Iic, Ioc_inter_Ioi, sup_eq_max]\n\n@[simp] lemma Ioc_union_Ioc_right : Ioc a b \u222a Ioc a c = Ioc a (max b c) :=\nby rw [Ioc_union_Ioc, min_self]; exact (min_le_left _ _).trans (le_max_left _ _)\n\n@[simp] lemma Ioc_union_Ioc_left : Ioc a c \u222a Ioc b c = Ioc (min a b) c :=\nby rw [Ioc_union_Ioc, max_self]; exact (min_le_right _ _).trans (le_max_right _ _)\n\n@[simp] lemma Ioc_union_Ioc_symm : Ioc a b \u222a Ioc b a = Ioc (min a b) (max a b) :=\nby { rw max_comm, apply Ioc_union_Ioc; rw max_comm; exact min_le_max }\n\n@[simp] lemma Ioc_union_Ioc_union_Ioc_cycle :\n  Ioc a b \u222a Ioc b c \u222a Ioc c a = Ioc (min a (min b c)) (max a (max b c)) :=\nbegin\n  rw [Ioc_union_Ioc, Ioc_union_Ioc],\n  ac_refl,\n  all_goals { solve_by_elim [min_le_of_left_le, min_le_of_right_le, le_max_of_le_left,\n    le_max_of_le_right, le_refl] { max_depth := 5 }}\nend\n\nend linear_order\n\n/-!\n### Closed intervals in `\u03b1 \u00d7 \u03b2`\n-/\n\nsection prod\n\nvariables [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma Iic_prod_Iic (a : \u03b1) (b : \u03b2) : Iic a \u00d7\u02e2 Iic b = Iic (a, b) := rfl\n\n@[simp] lemma Ici_prod_Ici (a : \u03b1) (b : \u03b2) : Ici a \u00d7\u02e2 Ici b = Ici (a, b) := rfl\n\nlemma Ici_prod_eq (a : \u03b1 \u00d7 \u03b2) : Ici a = Ici a.1 \u00d7\u02e2 Ici a.2 := rfl\n\nlemma Iic_prod_eq (a : \u03b1 \u00d7 \u03b2) : Iic a = Iic a.1 \u00d7\u02e2 Iic a.2 := rfl\n\n@[simp] lemma Icc_prod_Icc (a\u2081 a\u2082 : \u03b1) (b\u2081 b\u2082 : \u03b2) :\n  Icc a\u2081 a\u2082 \u00d7\u02e2 Icc b\u2081 b\u2082 = Icc (a\u2081, b\u2081) (a\u2082, b\u2082) :=\nby { ext \u27e8x, y\u27e9, simp [and.assoc, and_comm, and.left_comm] }\n\nlemma Icc_prod_eq (a b : \u03b1 \u00d7 \u03b2) :\n  Icc a b = Icc a.1 b.1 \u00d7\u02e2 Icc a.2 b.2 :=\nby simp\n\nend prod\n\nend set\n\n/-! ### Lemmas about intervals in dense orders -/\n\nsection dense\n\nvariables (\u03b1) [preorder \u03b1] [densely_ordered \u03b1] {x y : \u03b1}\n\ninstance : no_min_order (set.Ioo x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2081 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2081, hb\u2082.trans ha\u2082\u27e9, hb\u2082\u27e9\nend\u27e9\n\ninstance : no_min_order (set.Ioc x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2081 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2081, hb\u2082.le.trans ha\u2082\u27e9, hb\u2082\u27e9\nend\u27e9\n\ninstance : no_min_order (set.Ioi x) :=\n\u27e8\u03bb \u27e8a, ha\u27e9, begin\n  rcases exists_between ha with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2081\u27e9, hb\u2082\u27e9\nend\u27e9\n\ninstance : no_max_order (set.Ioo x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2082 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, ha\u2081.trans hb\u2081, hb\u2082\u27e9, hb\u2081\u27e9\nend\u27e9\n\ninstance : no_max_order (set.Ico x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2082 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, ha\u2081.trans hb\u2081.le, hb\u2082\u27e9, hb\u2081\u27e9\nend\u27e9\n\ninstance : no_max_order (set.Iio x) :=\n\u27e8\u03bb \u27e8a, ha\u27e9, begin\n  rcases exists_between ha with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2082\u27e9, hb\u2081\u27e9\nend\u27e9\n\nend dense\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/set/intervals/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8633916082162402, "lm_q1q2_score": 0.7454450585161059}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Michael Howes\n-/\nimport group_theory.quotient_group\nimport tactic.group\n\n/-!\n# The abelianization of a group\n\nThis file defines the commutator and the abelianization of a group. It furthermore prepares for the\nresult that the abelianization is left adjoint to the forgetful functor from abelian groups to\ngroups, which can be found in `algebra/category/Group/adjunctions`.\n\n## Main definitions\n\n* `commutator`: defines the commutator of a group `G` as a subgroup of `G`.\n* `abelianization`: defines the abelianization of a group `G` as the quotient of a group by its\n  commutator subgroup.\n-/\n\nuniverses u v\n\n-- Let G be a group.\nvariables (G : Type u) [group G]\n\n/-- The commutator subgroup of a group G is the normal subgroup\n  generated by the commutators [p,q]=`p*q*p\u207b\u00b9*q\u207b\u00b9`. -/\n@[derive subgroup.normal]\ndef commutator : subgroup G :=\nsubgroup.normal_closure {x | \u2203 p q, p * q * p\u207b\u00b9 * q\u207b\u00b9 = x}\n\n/-- The abelianization of G is the quotient of G by its commutator subgroup. -/\ndef abelianization : Type u :=\nquotient_group.quotient (commutator G)\n\nnamespace abelianization\n\nlocal attribute [instance] quotient_group.left_rel\n\ninstance : comm_group (abelianization G) :=\n{ mul_comm := \u03bb x y, quotient.induction_on\u2082' x y $ \u03bb a b,\n  begin\n    apply quotient.sound,\n    apply subgroup.subset_normal_closure,\n    use b\u207b\u00b9, use a\u207b\u00b9,\n    group,\n  end,\n.. quotient_group.quotient.group _ }\n\ninstance : inhabited (abelianization G) := \u27e81\u27e9\n\nvariable {G}\n\n/-- `of` is the canonical projection from G to its abelianization. -/\ndef of : G \u2192* abelianization G :=\n{ to_fun := quotient_group.mk,\n  map_one' := rfl,\n  map_mul' := \u03bb x y, rfl }\n\nsection lift\n-- So far we have built G\u1d43\u1d47 and proved it's an abelian group.\n-- Furthremore we defined the canonical projection `of : G \u2192 G\u1d43\u1d47`\n\n-- Let `A` be an abelian group and let `f` be a group homomorphism from `G` to `A`.\nvariables {A : Type v} [comm_group A] (f : G \u2192* A)\n\nlemma commutator_subset_ker : commutator G \u2264 f.ker :=\nbegin\n  apply subgroup.normal_closure_le_normal,\n  rintros x \u27e8p, q, rfl\u27e9,\n  simp [monoid_hom.mem_ker, mul_right_comm (f p) (f q)],\nend\n\n/-- If `f : G \u2192 A` is a group homomorphism to an abelian group, then `lift f` is the unique map from\n  the abelianization of a `G` to `A` that factors through `f`. -/\ndef lift : (G \u2192* A) \u2243 (abelianization G \u2192* A) :=\n{ to_fun := \u03bb f, quotient_group.lift _ f (\u03bb x h, f.mem_ker.2 $ commutator_subset_ker _ h),\n  inv_fun := \u03bb F, F.comp of,\n  left_inv := \u03bb f, monoid_hom.ext $ \u03bb x, rfl,\n  right_inv := \u03bb F, monoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ \u03bb z, rfl }\n\n@[simp] lemma lift.of (x : G) : lift f (of x) = f x :=\nrfl\n\ntheorem lift.unique\n  (\u03c6 : abelianization G \u2192* A)\n  -- h\u03c6 : \u03c6 agrees with f on the image of G in G\u1d43\u1d47\n  (h\u03c6 : \u2200 (x : G), \u03c6 (of x) = f x)\n  {x : abelianization G} :\n  \u03c6 x = lift f x :=\nquotient_group.induction_on x h\u03c6\n\nend lift\n\nvariables {A : Type v} [monoid A]\n\n/-- See note [partially-applied ext lemmas]. -/\n@[ext]\ntheorem hom_ext (\u03c6 \u03c8 : abelianization G \u2192* A)\n  (h : \u03c6.comp of = \u03c8.comp of) : \u03c6 = \u03c8 :=\nmonoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ monoid_hom.congr_fun h\n\nend abelianization\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/abelianization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7454235962578798}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Michael Howes\n-/\nimport group_theory.quotient_group\nimport tactic.group\n\n/-!\n# The abelianization of a group\n\nThis file defines the commutator and the abelianization of a group. It furthermore prepares for the\nresult that the abelianization is left adjoint to the forgetful functor from abelian groups to\ngroups, which can be found in `algebra/category/Group/adjunctions`.\n\n## Main definitions\n\n* `commutator`: defines the commutator of a group `G` as a subgroup of `G`.\n* `abelianization`: defines the abelianization of a group `G` as the quotient of a group by its\n  commutator subgroup.\n-/\n\nuniverses u v\n\n-- Let G be a group.\nvariables (G : Type u) [group G]\n\n/-- The commutator subgroup of a group G is the normal subgroup\n  generated by the commutators [p,q]=`p*q*p\u207b\u00b9*q\u207b\u00b9`. -/\n@[derive subgroup.normal]\ndef commutator : subgroup G :=\nsubgroup.normal_closure {x | \u2203 p q, p * q * p\u207b\u00b9 * q\u207b\u00b9 = x}\n\n/-- The abelianization of G is the quotient of G by its commutator subgroup. -/\ndef abelianization : Type u :=\nG \u29f8 (commutator G)\n\nnamespace abelianization\n\nlocal attribute [instance] quotient_group.left_rel\n\ninstance : comm_group (abelianization G) :=\n{ mul_comm := \u03bb x y, quotient.induction_on\u2082' x y $ \u03bb a b,\n  begin\n    apply quotient.sound,\n    apply subgroup.subset_normal_closure,\n    use b\u207b\u00b9, use a\u207b\u00b9,\n    group,\n  end,\n.. quotient_group.quotient.group _ }\n\ninstance : inhabited (abelianization G) := \u27e81\u27e9\n\nvariable {G}\n\n/-- `of` is the canonical projection from G to its abelianization. -/\ndef of : G \u2192* abelianization G :=\n{ to_fun := quotient_group.mk,\n  map_one' := rfl,\n  map_mul' := \u03bb x y, rfl }\n\nsection lift\n-- So far we have built G\u1d43\u1d47 and proved it's an abelian group.\n-- Furthremore we defined the canonical projection `of : G \u2192 G\u1d43\u1d47`\n\n-- Let `A` be an abelian group and let `f` be a group homomorphism from `G` to `A`.\nvariables {A : Type v} [comm_group A] (f : G \u2192* A)\n\nlemma commutator_subset_ker : commutator G \u2264 f.ker :=\nbegin\n  apply subgroup.normal_closure_le_normal,\n  rintros x \u27e8p, q, rfl\u27e9,\n  simp [monoid_hom.mem_ker, mul_right_comm (f p) (f q)],\nend\n\n/-- If `f : G \u2192 A` is a group homomorphism to an abelian group, then `lift f` is the unique map from\n  the abelianization of a `G` to `A` that factors through `f`. -/\ndef lift : (G \u2192* A) \u2243 (abelianization G \u2192* A) :=\n{ to_fun := \u03bb f, quotient_group.lift _ f (\u03bb x h, f.mem_ker.2 $ commutator_subset_ker _ h),\n  inv_fun := \u03bb F, F.comp of,\n  left_inv := \u03bb f, monoid_hom.ext $ \u03bb x, rfl,\n  right_inv := \u03bb F, monoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ \u03bb z, rfl }\n\n@[simp] lemma lift.of (x : G) : lift f (of x) = f x :=\nrfl\n\ntheorem lift.unique\n  (\u03c6 : abelianization G \u2192* A)\n  -- h\u03c6 : \u03c6 agrees with f on the image of G in G\u1d43\u1d47\n  (h\u03c6 : \u2200 (x : G), \u03c6 (of x) = f x)\n  {x : abelianization G} :\n  \u03c6 x = lift f x :=\nquotient_group.induction_on x h\u03c6\n\nend lift\n\nvariables {A : Type v} [monoid A]\n\n/-- See note [partially-applied ext lemmas]. -/\n@[ext]\ntheorem hom_ext (\u03c6 \u03c8 : abelianization G \u2192* A)\n  (h : \u03c6.comp of = \u03c8.comp of) : \u03c6 = \u03c8 :=\nmonoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ monoid_hom.congr_fun h\n\nend abelianization\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/group_theory/abelianization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656671, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7454235931409603}}
{"text": "import tactic.basic\nimport .uwyo_aux\nimport analysis.calculus.local_extr\n\nnoncomputable theory\nopen_locale classical topological_space \nopen filter \n\n-- For examples, see mathlib/src/analysis/specific_limits.lean\n-- Main business: Newton's method sequence of approximations\n-- Working first with a sequence of rationals for the approximations themselves\ndef x : \u2115 \u2192 \u211a\n| 0     := (2 : \u211a)\n| (n+1) := ( x n * x n + 2) / ( 2 * x n)\n-- Now pretend otherwise\ndef s (n : \u2115) : \u211d := real.sqrt 2 - x n\n\n\nlemma newton_seq_positive : \u2200 n : \u2115, 0 < x n :=\nbegin\n  intro n,\n  induction n with d hd,\n  { -- base case n = 0\n    have h1 : x 0 = 2, refl,\n    rw h1, linarith,\n  },\n  { -- induction step\n    have h2 : x d.succ = ( x d * x d + 2) / ( 2 * x d), refl,\n    set X := x d with hX,\n    have h3 : 0 < X * X, nlinarith,\n    have h4 : 0 < X * X + 2, linarith,\n    have h5 : 0 < 2 * X, linarith,\n    exact div_pos h4 h5, \n  }, \n  done\nend\n\nlemma newton_seq_bounded_below : \u2200 n : \u2115, 2 < (x n) * (x n) :=\nbegin\n  intro n,\n  induction n with d hd,\n  { -- base case n= 0\n    have h0 : x 0 =2 , refl,\n    rw h0, linarith,\n  },\n  { -- induction step, kind of ugly so far\n    have h1 : x d.succ = ( x d * x d + 2) / ( 2 * x d), refl,\n    rw h1,\n    have H := newton_seq_positive d,\n    set X := x d with hX,\n    have G : X \u2260 0, linarith,\n    set Y := X * X with hY,\n    have G1 : Y \u2260 0, nlinarith,\n    have g1 : (Y + 2) * (Y + 2) = Y * Y + 4 * Y + 4, ring,\n    set V := 2 * X with hV,\n    have F : V \u2260 0, linarith,\n    have E : V * V \u2260 0, nlinarith,\n    have g2 :  (Y + 2) * (Y + 2) / ( V * V) = (Y + 2) / V * ((Y + 2) / V),\n      field_simp,\n    -- this needs some polishing\n    have h21 := aux_1 X Y V G hY hV G1,\n    have h201 : (1/4) * (4 * (Y + 2) / V * ((Y + 2) / (V))) = (1/4) * (Y + 2 * 2 + (2*2/(X * X)) ),\n      rw h21,\n    have h202 : (1/4) * (4 * (Y + 2) / V * ((Y + 2) / (V))) = (Y + 2) / V * ((Y + 2) / (V)),\n      ring,\n    have h2 : (Y + 2) / V * ((Y + 2) / (V)) = (1/4) * (Y + 2 * 2 + (2*2/(X * X)) ), \n      rw h202 at h201, exact h201,\n    have h3 : \n      2 - (1/4) * ( X * X + 2 * 2 + (2*2/(X*X)) ) = (1/4) * ( - X * X + 2 * 2 - (2*2/(X*X)) ), \n      ring,\n    have h4 : (1/4) * ( - X * X + 2 * 2 - (2*2/(X*X)) ) = - (1/4) * ( 2 / X - X ) ^ 2, \n      have h41 : ( 2 / X - X ) ^ 2 = ( 2 / X - X ) * ( 2 / X - X ), ring,\n      rw h41,\n      have h42 := aux_2 X G,\n      rw h42, ring,\n    have h51 : 0 \u2264 ( 2 / X - X ) ^ 2, exact pow_two_nonneg _,\n    have h52 : 0 \u2260 ( 2 / X - X ), exact no_rat_sq_eq_two X G,  \n    have h53 : 0 \u2260 ( 2 / X - X ) ^ 2, exact ne.symm (pow_ne_zero 2 (ne.symm h52)),\n    have h54 : 0 < ( 2 / X - X ) ^ 2, exact lt_of_le_of_ne h51 h53,\n    have h6 : - (1/4) * ( 2 / X - X ) ^ 2 < 0, linarith,\n    rw h2,\n    apply sub_lt_zero.mp,\n    rw h3, rw h4, exact h6,\n  },\n  done\nend\n\nlemma newton_seq_decreasing : \u2200 n : \u2115, x (n+1) < x n :=\nbegin\n  intro n,\n  have h1 : x (n+1) = ( x n * x n + 2) / ( 2 * x n), refl,\n  have h2 : x (n+1) - x n = ( x n * x n + 2) / ( 2 * x n) - x n, rw h1,\n  have h21 := newton_seq_positive n,\n  set X := x n with hX,\n  have h3 := aux_0 X h21,\n  have h4 : 2 - X * X < 0, \n    have h41 := newton_seq_bounded_below n,\n    rw \u2190 hX at h41,\n    linarith,\n  have h5 : 0 < 2 * X, linarith,\n  have h6 := div_neg_of_neg_of_pos h4 h5,\n  rw \u2190 h3 at h6, rw \u2190 h2 at h6, linarith,\n  done\nend\n\ntheorem sqrt_sub_newton_monotone : monotone s :=\nbegin\n  apply monotone_of_monotone_nat,\n  intro n,\n  unfold s,\n  have h1 := newton_seq_decreasing n,\n  have h2 : ((x (n + 1)) : \u211d) \u2264 ((x n) : \u211d), \n    norm_cast, linarith,\n  exact (sub_le_sub_iff_left (real.sqrt 2)).mpr h2,\n  done\nend\n\ntheorem sqrt_sub_newton_below_zero : \u2200 n : \u2115, s n < (0 : \u211d) :=\nbegin\n  unfold s,\n  intro n,\n  rw sub_lt, rw sub_zero,\n  have h1 := newton_seq_bounded_below n,\n  have h2 := newton_seq_positive n,\n  set X := x n with hX,\n  have h3 : 0 \u2264 (2 : \u211d), linarith,\n  have h4 : 0 \u2264 X, linarith,\n  have h41 : 0 \u2264 ((X * X) : \u211d), nlinarith,\n  have h42 : 2 < ((X * X) : \u211d), norm_cast, exact h1,\n  have h5 := (real.sqrt_lt h3 h41).mpr h42,\n  rw \u2190 pow_two at h5,\n  rw real.sqrt_sqr at h5, exact h5,\n  norm_cast, exact h4,\nend\n\nlemma sqrt_sub_newton_range_subset : set.range s \u2286 set.Iic (0:\u211d) :=\nbegin\n  unfold set.range,\n  have h := sqrt_sub_newton_below_zero,\n  intros x hx,\n  cases hx with m hm,\n  have h1 := h m,\n  rw hm at h1,\n  rw set.mem_Iic,\n  linarith,\nend\n\ntheorem sqrt_sub_newton_bounded_above : bdd_above (set.range s) :=\nbegin\n  have h1 := sqrt_sub_newton_range_subset,\n  have h2 : \u2203 a : \u211d, (set.range s) \u2286 set.Iic a,\n    use [0, h1],\n  exact bdd_above_iff_subset_Iic.mpr h2,\nend\n\ntheorem sqrt_sub_newton_tendsto_finite_limit : \u2203 L0 : \u211d, tendsto s at_top (\ud835\udcdd L0) :=\nbegin\n  have h1 := tendsto_of_monotone sqrt_sub_newton_monotone,\n  cases h1 with hf ht,\n  have h2 := unbounded_of_tendsto_at_top hf,\n  have h3 := sqrt_sub_newton_bounded_above,\n  exfalso,  -- this sequence doesn't go to infinity; it is bounded above\n  exact h2 h3,\n  exact ht, done\nend\n\ntheorem sqrt_sub_newton_tendsto_finite_limit_v1 : \u2203 L0 : \u211d, tendsto s at_top (\ud835\udcdd L0) :=\nbegin\n  have h1 := tendsto_of_monotone sqrt_sub_newton_monotone,\n  cases h1 with hf ht,\n  have h2 := unbounded_of_tendsto_at_top hf,\n  have h3 := sqrt_sub_newton_bounded_above,\n  exfalso,  -- this sequence doesn't go to infinity; it is bounded above\n  exact h2 h3,\n  exact ht, done\nend\n\n-- This is due to Yuri Kudryashov\nexample (s : \u2115 \u2192 \u211d) (L : \u211d) (h : \u2200 n : \u2115, s n < L) : \u00ac (tendsto s at_top at_top) := \nbegin\n  intro H,\n  --have h0 := H.eventually,\n  have h1 : \u2203 n, L \u2264 s n := (H.eventually (eventually_ge_at_top L)).exists,\n  cases h1 with n hn,\n  have h2 := h n, \n  linarith, done\nend\n\n-- This is the sequence of Newton approximations, viewed as real numbers\ndef xR (n : \u2115) : \u211d := real.sqrt 2 - s n\n-- We can actually prove `xR` and `x` generate the same values\ntheorem xR_same_as_x (n : \u2115) : ((x n): \u211d) = xR n := \nbegin\n  have h1 : xR n = real.sqrt 2 - s n, refl,\n  have h2 : s n = real.sqrt 2 - x n, refl,\n  rw h2 at h1,\n  have h3 : real.sqrt 2 - (real.sqrt 2 - \u2191(x n)) = \u2191(x n),\n    linarith,\n  rw h3 at h1, \n  exact h1.symm, done\nend\n\n-- Rewrite the recursive formula as a function application\n--def f (x : \u211d) : \u211d := (1/2) * (x + 2 / x)\ndef f (x : \u211d) : \u211d := ( x * x + 2) / ( 2 * x)\n-- This is needed in the limit calculation result\nlemma rw_recursion : \u2200 n : \u2115, xR (n+1) = f (xR n) := \nbegin\n  intro n,\n  have h1 := xR_same_as_x n,\n  have h2 := xR_same_as_x (n+1),\n  rw [\u2190 h1, \u2190 h2],\n  unfold f,\n  have h3 : x (n+1) = ( x n * x n + 2) / ( 2 * x n), refl,\n  rw h3,\n  norm_cast, done\nend\n\nlemma f_contin_at_L (L : \u211d) (h : L \u2260 0) : continuous_at f L := \nbegin \n  apply continuous_at.div,\n  swap 3, { norm_num, exact h, },\n  apply continuous_at.add,\n  apply continuous_at.mul,\n  apply continuous_at_id,\n  apply continuous_at_id,\n  apply continuous_at_const,\n  apply continuous_at.mul,\n  apply continuous_at_const,\n  exact continuous_at_id, done\nend\n\n-- So now the final push\n-- The sequence `xR` has a finite limit:\ntheorem newton_tendsto_finite_limit : \u2203 L : \u211d, tendsto xR at_top (\ud835\udcdd L) :=\nbegin\n  have h1 := sqrt_sub_newton_tendsto_finite_limit,\n  cases h1 with l0 hl0,\n  use real.sqrt 2 - l0,\n  apply tendsto.sub,\n  exact tendsto_const_nhds,\n  exact hl0, done\nend\n\n-- The limit can't be zero:\ntheorem newton_tendsto_nonzero_limit (L : \u211d) : tendsto xR at_top (\ud835\udcdd L) \u2192 L \u2260 0 :=\nbegin\n  have h2 := xR_same_as_x,\n  have h0 : \u2200 n : \u2115, 0 < xR n, \n    intro n,\n    have g0 := newton_seq_positive n,\n    have h21 := h2 n,\n    rw \u2190 h21, norm_cast, exact g0,\n  have h1 := newton_seq_bounded_below,\n  have h3 : \u2200 n : \u2115, real.sqrt 2 < xR n,\n    intro n, \n    have h30 := h1 n,\n    have h31 := h2 n,\n    have h00 := h0 n,\n    have h32 : 0 \u2264 (2:\u211d), linarith,\n    have h33 : 0 \u2264 (xR n) * (xR n), nlinarith,\n    have h34 : 2 < (xR n) * (xR n), rw \u2190 h31, norm_cast, exact h30,\n    have h35 := (real.sqrt_lt h32 h33).mpr h34,\n    have h01 : 0 \u2264 xR n, linarith,\n    have h36 : real.sqrt ((xR n) * (xR n)) = xR n, exact real.sqrt_mul_self h01,\n    rw h36 at h35,\n    exact h35,\n  intros H hL,\n  have G := aux_3 xR h3,\n  rw hL at H,\n  exact G H, done\nend\n\n-- And this limit satisfies a specific equation\ntheorem newton_limit_satisfies (L : \u211d) (H : tendsto xR at_top ((\ud835\udcdd L) )) :\n  f L = L :=\nbegin\n  have h1 : tendsto (xR \u2218 nat.succ) at_top (\ud835\udcdd L) := (tendsto_add_at_top_iff_nat 1).mpr H,\n  have h2 := (tendsto_add_at_top_iff_nat 1).mpr H,\n  rw show xR \u2218 nat.succ = f \u2218 xR, from funext rw_recursion at h1,\n  have hL : L \u2260 0, exact newton_tendsto_nonzero_limit L H,\n  have hf : continuous_at f L, exact f_contin_at_L L hL,\n  exact tendsto_nhds_unique (tendsto.comp hf H) h1,\n  done\nend\n\n-- The equation for the limit `L` can be solved to get `L = real.sqrt 2`\n-- Courtesy Patrick Massot \nlemma solve_limit_eqn {L : \u211d} (h : L = (2 + L * L)/(2*L)) (hL : 0 < L) : L = real.sqrt 2 :=\nbegin\n  apply_fun (\u03bb x, 2*L*x) at h,\n  simp_rw mul_div_cancel' _ (ne_of_gt (by linarith) : 2*L \u2260 0) at h,\n  apply_fun (\u03bb x, x - L*L) at h,\n  ring at h,\n  symmetry,\n  rwa real.sqrt_eq_iff_sqr_eq; linarith,\nend\n\n--------- Scratch space below here:\n-- This slick proof due to Patrick Massot:\nlemma dan_limit {u : \u2115 \u2192 \u211d} {L : \u211d} {f : \u211d \u2192 \u211d} (hu : tendsto u at_top $ \ud835\udcdd L)\n(hf : continuous_at f L) (huf : \u2200 n, u (n+1) = f (u n)) : f L = L :=\nbegin\n  have lim : tendsto (u \u2218 nat.succ) at_top (\ud835\udcdd L) :=\n    (tendsto_add_at_top_iff_nat 1).mpr hu,\n  rw show u \u2218 nat.succ = f \u2218 u, from funext huf at lim,\n  exact tendsto_nhds_unique (tendsto.comp hf hu) lim\nend\n-- This one is due to Mario Carneiro:\nexample (s : \u2115 \u2192 \u211d) (hs : \u2200 n : \u2115, 2 < s n) : \u00ac (tendsto s at_top (\ud835\udcdd 0)) :=\nbegin\n  have : (0:\u211d) \u2209 set.Ici (2 : \u211d), { simp, norm_num },\n  rw \u2190 closure_Ioi at this,\n  exact \u03bb h, this (mem_closure_of_tendsto h (eventually_of_forall hs)),\n  done\nend\n\n", "meta": {"author": "stanescuUW", "repo": "numerical-analysis-with-Lean", "sha": "98e6974f8b68cc5232ceff40535d776a33444c73", "save_path": "github-repos/lean/stanescuUW-numerical-analysis-with-Lean", "path": "github-repos/lean/stanescuUW-numerical-analysis-with-Lean/numerical-analysis-with-Lean-98e6974f8b68cc5232ceff40535d776a33444c73/src/NewtonMethod/newtonMeth.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7453950427849221}}
{"text": "open classical\n\n\nvariables p q r s : Prop\n\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\n   iff.intro\n       (assume h: p \u2227 q, show q \u2227 p, from and.intro h.right h.left)\n       (assume h: q \u2227 p, show p \u2227 q, from and.intro h.right h.left)\n     \n\n\nlemma swap_or: p \u2228 q \u2192 q \u2228 p :=\n   assume hpq: p \u2228 q,\n   show q \u2228 p, from or.elim hpq\n       (assume hp: p, or.intro_right q hp)\n       (assume hq: q, or.intro_left p hq)\n\n\nexample : p \u2228 q \u2194 q \u2228 p :=\n  iff.intro\n      (assume h: p \u2228 q, show q \u2228 p, from swap_or p q h)\n      (assume h: q \u2228 p, show p \u2228 q, from swap_or q p h)\n\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n  iff.intro\n       (\n           assume h: (p \u2227 q) \u2227 r,\n           have hpq: (p \u2227 q), from h.left,\n           have hqr: (q \u2227 r), from and.intro hpq.right h.right,\n           and.intro hpq.left hqr\n       )\n       (\n           assume h: p \u2227 (q \u2227 r),\n           have hqr: (q \u2227 r), from h.right,\n           and.intro (and.intro h.left hqr.left) hqr.right\n       )\n\n\n\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n   have hlr: p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r), from (\n       assume h: p \u2227 (q \u2228 r),\n       or.elim\n           h.right\n           (\n               assume hq: q,\n               have hpq: p \u2227 q, from and.intro h.left hq,\n               or.intro_left (p \u2227 r) hpq\n           )\n           (\n               assume hr: r,\n               have hpr: p \u2227 r, from and.intro h.left hr,\n               or.intro_right (p \u2227 q) hpr\n           )\n   ),\n   have hrl: (p \u2227 q) \u2228 (p \u2227 r) \u2192  p \u2227 (q \u2228 r), from (\n       assume h: (p \u2227 q) \u2228 (p \u2227 r),\n       or.elim\n           h\n           (\n               assume hpq: p \u2227 q,\n               have hqr: q \u2228 r, from or.intro_left r hpq.right,\n               and.intro hpq.left hqr\n           )\n           (\n               assume hpr: p \u2227 r,\n               have hqr: q \u2228 r, from or.intro_right q hpr.right,\n               and.intro hpr.left hqr\n           )\n   ),\n   iff.intro hlr hrl\n\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n   iff.intro\n       (\n           assume h: p \u2228 (q \u2227 r),\n           or.elim\n               h\n               (\n                   assume hp:p,\n                   have hpq: p \u2228 q, from or.intro_left q hp,\n                   have hpr: p \u2228 r, from or.intro_left r hp,\n                   and.intro hpq hpr\n               )\n               (\n                   assume hqr: q \u2227 r,\n                   have hpq: p \u2228 q, from or.intro_right p hqr.left,\n                   have hpr: p \u2228 r, from or.intro_right p hqr.right,\n                   and.intro hpq hpr\n               )\n       )\n       (\n           assume h: (p \u2228 q) \u2227 (p \u2228 r),\n           have hpq: p \u2228 q, from h.left,\n           have hpr: p \u2228 r, from h.right,\n           or.elim hpq\n               (assume hp: p, or.intro_left (q \u2227 r) hp)\n               (\n                   assume hq: q,\n                   or.elim hpr\n                       (assume hp: p, or.intro_left (q \u2227 r) hp)\n                       (\n                           assume hr: r,\n                           have hqr: q \u2227 r, from and.intro hq hr,\n                           or.intro_right p hqr\n                       )\n               )\n       )\n\n\n\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n   have hlr: (p \u2192 (q \u2192 r)) \u2192  (p \u2227 q \u2192 r), from (  \n             assume h: p \u2192 q \u2192 r,\n       assume hpq: p \u2227 q,\n       (h hpq.left) hpq.right\n   ),\n   have hrl: (p \u2227 q \u2192 r) \u2192 (p \u2192 (q \u2192 r)), from (\n       assume h: (p \u2227 q \u2192 r),\n       assume hp: p,\n       assume hq: q,\n       h (and.intro hp hq)\n   ),\n   iff.intro hlr hrl\n\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\n   have hlr: ((p \u2228 q) \u2192 r) \u2192 (p \u2192 r) \u2227 (q \u2192 r), from (\n       assume h: ((p \u2228 q) \u2192 r),\n       have hpr: (p \u2192 r), from (\n           assume hp: p,\n           have hpq: p \u2228 q, from or.intro_left q hp,\n           h hpq\n       ),\n       have hqr: (q \u2192 r), from (\n           assume hq: q,\n           have hpq: p \u2228 q, from or.intro_right p hq,\n           h hpq\n       ),\n       and.intro hpr hqr\n   ),\n   have hrl: (p \u2192 r) \u2227 (q \u2192 r) \u2192 ((p \u2228 q) \u2192 r), from (\n       assume hp: (p \u2192 r) \u2227 (q \u2192 r),\n       assume hpq: p \u2228 q,\n       or.elim hpq hp.left hp.right\n   ),\n   iff.intro hlr hrl\n\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n   iff.intro\n       (\n           assume h: \u00ac (p \u2228 q),\n           have hnp: \u00ac p, from (assume hp: p, absurd (or.intro_left q hp) h),\n           have hnq: \u00ac q, from (assume hq: q, absurd (or.intro_right p hq) h),\n           and.intro hnp hnq\n       )\n       (\n           assume h: \u00ac p \u2227 \u00ac q,\n           assume hpq: p \u2228 q,\n           or.elim hpq\n               (assume hp: p, absurd hp h.left)\n               (assume hq: q, absurd hq h.right)\n       )\n\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n   assume h: \u00ac p \u2228 \u00ac q,\n   assume hpq: p \u2227 q,\n   or.elim h\n       (assume hnp: \u00ac p, absurd hpq.left hnp)\n       (assume hnq: \u00ac q, absurd hpq.right hnq)\n\n\nexample : \u00ac(p \u2227 \u00acp) := assume h: p \u2227 \u00ac p, absurd h.left h.right\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n   assume h: p \u2227 \u00ac q,\n   assume hpq: p \u2192 q,\n   absurd (hpq h.left) h.right\n\n\nexample : \u00acp \u2192 (p \u2192 q) :=\n   assume hnp: \u00ac p,\n   assume hp: p,\n   absurd hp hnp\n\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n   assume h: \u00ac p \u2228 q,\n   or.elim h\n       (assume hnp: \u00ac p, assume hp: p, absurd hp hnp)\n       (assume hq: q, assume hp: p, hq)\nexample : p \u2228 false \u2194 p := iff.intro\n   (\n       assume h: p \u2228 false,\n       or.elim h\n           (assume hp: p, hp)\n           (false.elim)\n   )\n   (assume p, or.intro_left false p)\n\n\nexample : p \u2227 false \u2194 false := iff.intro\n   (assume h: p \u2227 false, h.right)\n   (false.elim)\n\n\nexample : \u00ac(p \u2194 \u00acp) :=\n   assume h: (p \u2194 \u00ac p),\n   have hnp: \u00ac p, from (\n       assume hp: p,\n       absurd hp (h.mp hp)\n   ),\n   have hp: p, from h.mpr hnp,\n   absurd hp (h.mp hp)\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n   assume h: p \u2192 q,\n   assume hnq: \u00ac q,\n   assume hp: p,\n   absurd (h hp) hnq\n\n-- these require classical reasoning\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n    assume h : p \u2192 r \u2228 s,\n    by_cases\n        ( assume : p \u2192 r, or.intro_left (p \u2192 s) this )\n        (\n            assume : \u00ac (p \u2192 r),\n            have p \u2192 s, from (\n                assume : p,\n                show s, from by_contradiction (\n                    assume : \u00ac s,\n                    have r \u2228 s, from h \u2039p\u203a,\n                    or.elim this\n                        (\n                            assume : r,\n                            have p \u2192 r, from (assume : p, \u2039r\u203a),\n                            absurd this \u2039\u00ac (p \u2192 r)\u203a\n                        )\n                        (\n                            assume : s,\n                            absurd this \u2039\u00ac s\u203a\n                        )\n                )\n            ),\n            or.intro_right (p \u2192 r) this\n        )\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n    assume h: \u00ac (p \u2227 q),\n    by_cases\n        (\n            assume hp: p,\n            have \u00ac q, from (\n                assume hq: q,\n                absurd (and.intro hp hq) h\n            ),\n            or.intro_right (\u00ac p) this\n        )\n        (\n            assume hnp: \u00ac p,\n            or.intro_left (\u00ac q) hnp\n        )\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n    assume h : \u00ac (p \u2192 q),\n    by_cases\n        (\n            assume : p,\n            have \u00ac q, from (\n                assume : q,\n                have p \u2192 q, from (\n                    assume : p,\n                    \u2039 q \u203a\n                ),\n                absurd this h\n            ),\n            and.intro \u2039p\u203a this\n        )\n        (\n            assume : \u00ac p,\n            have p \u2192 q, from (\n                assume : p,\n                absurd this \u2039\u00ac p\u203a\n            ),\n            absurd this h\n        )\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n    assume h : p \u2192 q,\n    by_cases\n        (assume : q, or.intro_right (\u00ac p) this)\n        (\n            assume : \u00ac q,\n            have \u00ac p, from (\n                assume : p,\n                absurd (h this) \u2039\u00ac q\u203a\n            ),\n            or.intro_left q this\n        )\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n    assume h : \u00ac q \u2192 \u00ac p,\n    assume hp : p,\n    by_contradiction (\n        assume : \u00ac q,\n        absurd hp (h this)\n    )\nexample : p \u2228 \u00acp := em p\nexample : p \u2228 \u00acp :=\n    by_cases\n        (assume : p, or.intro_left (\u00ac p) this)\n        (assume : \u00ac p, or.intro_right p this)\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\n    assume h : (p \u2192 q) \u2192 p,\n    by_cases\n        (\n            assume : p \u2192 q,\n            show p, from h this\n        )\n        (\n            assume : \u00ac (p \u2192 q),\n            show p, from by_contradiction (\n                assume : \u00ac p,\n                have p \u2192 q, from (\n                    assume : p,\n                    absurd this \u2039\u00ac p\u203a\n                ),\n                absurd this \u2039\u00ac (p \u2192 q)\u203a\n            )\n        )\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/chap3_exercise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229959153748, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.745395032986287}}
{"text": "/-\nCopyright (c) 2021 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport data.mv_polynomial.cardinal\nimport data.mv_polynomial.equiv\n/-!\n# Cardinality of Polynomial Ring\n\nThe reuslt in this file is that the cardinality of `polynomial R` is at most the maximum\nof `#R` and `\u03c9`.\n-/\nuniverse u\n\nopen_locale cardinal\nopen cardinal\n\nnamespace polynomial\n\nlemma cardinal_mk_le_max {R : Type u} [comm_semiring R] : #(polynomial R) \u2264 max (#R) \u03c9 :=\ncalc #(polynomial R) = #(mv_polynomial punit.{u + 1} R) :\n  cardinal.eq.2 \u27e8(mv_polynomial.punit_alg_equiv.{u u} R).to_equiv.symm\u27e9\n... \u2264 _ : mv_polynomial.cardinal_mk_le_max\n... \u2264 _ : begin\n  have : #(punit.{u + 1}) \u2264 \u03c9, from le_of_lt (lt_omega_iff_fintype.2 \u27e8infer_instance\u27e9),\n  rw [max_assoc, max_eq_right this]\nend\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.7453950291664154}}
{"text": "import MyNat.Definition\nimport MyNat.Power\nimport MyNat.Inequality -- LE\nimport InequalityWorld.Level4 -- zero_le\nimport InequalityWorld.Level5 -- le_trans\nimport InequalityWorld.Level17 -- lt, lt_iff_succ_le\nimport MultiplicationWorld.Level4 -- mul_add\nimport MultiplicationWorld.Level8 -- mul_comm\nnamespace MyNat\nopen MyNat\n\nlemma lt_irrefl (a : MyNat) : \u00ac (a < a) := by\n  intro h\n  cases h with\n  | _ h1 h2 =>\n    apply h2\n    exact h1\n\nlemma ne_of_lt (a b : MyNat) : a < b \u2192 a \u2260 b := by\n  intro h\n  intro h1\n  cases h with\n  | _ h2 h3 =>\n    apply h3\n    rw [h1]\n\ntheorem not_lt_zero (a : MyNat) : \u00ac(a < 0) := by\n  intro h\n  cases h with\n  | _ ha hna =>\n    apply hna\n    exact zero_le a\n\ntheorem lt_of_lt_of_le (a b c : MyNat) : a < b \u2192 b \u2264 c \u2192 a < c := by\n  intro hab\n  intro hbc\n  rw [lt_iff_succ_le] at hab \u22a2\n  cases hbc with\n  | _ x hx =>\n    cases hab with\n    | _ y hy =>\n      rw [hx]\n      rw [hy]\n      use y + x\n      rw [add_assoc]\n\ntheorem lt_of_le_of_lt (a b c : MyNat) : a \u2264 b \u2192 b < c \u2192 a < c := by\n  intro hab\n  intro hbc\n  rw [lt_iff_succ_le] at hbc \u22a2\n  cases hbc with\n  | _ x hx =>\n    cases hab with\n    | _ y hy =>\n      rw [hx]\n      rw [hy]\n      use y + x\n      rw [succ_add]\n      rw [succ_add]\n      rw [add_assoc]\n\ntheorem lt_trans (a b c : MyNat) : a < b \u2192 b < c \u2192 a < c := by\n  intro hab\n  intro hbc\n  rw [lt_iff_succ_le] at hab hbc \u22a2\n  cases hbc with\n  | _ x hx =>\n    cases hab with\n    | _ y hy =>\n      rw [hx]\n      rw [hy]\n      use y + x + 1\n      repeat rw [succ_add]\n      repeat rw [succ_eq_add_one]\n      simp\n\ntheorem lt_iff_le_and_ne (a b : MyNat) : a < b \u2194 a \u2264 b \u2227 a \u2260 b := by\n  constructor\n  {\n    intro h\n    cases h with\n    | _ h1 h2 =>\n      constructor\n      assumption\n      intro h\n      apply h2\n      rw [h]\n  }\n  {\n    intro h\n    cases h with\n    | _ h1 h2 =>\n    constructor\n    exact h1\n    intro h\n    apply h2\n    exact le_antisymm _ _ h1 h\n  }\n\ntheorem lt_succ_self (n : MyNat) : n < succ n := by\n  rw [lt_iff_le_and_ne]\n  constructor\n  {\n    use 1\n  }\n  {\n    intro h\n    exact ne_succ_self n h\n  }\n\nlemma succ_le_succ_iff (m n : MyNat) : succ m \u2264 succ n \u2194 m \u2264 n := by\n  constructor\n  {\n    intro h\n    cases h with\n    | _ c hc =>\n      use c\n      apply succ_inj\n      rw [hc]\n      rw [succ_add]\n  }\n  {\n    intro h\n    cases h with\n    | _ c hc =>\n      use c\n      rw [hc]\n      rw [succ_add]\n  }\n\n\nlemma lt_succ_iff_le (m n : MyNat) : m < succ n \u2194 m \u2264 n := by\n  rw [lt_iff_succ_le]\n  exact succ_le_succ_iff m n\n\n\nlemma le_of_add_le_add_left (a b c : MyNat) : a + b \u2264 a + c \u2192 b \u2264 c := by\n  intro h\n  cases h with\n  | _ d hd =>\n    use d\n    apply add_left_cancel a\n    rw [hd]\n    rw [add_assoc]\n\nlemma lt_of_add_lt_add_left (a b c : MyNat) : a + b < a + c \u2192 b < c := by\n  repeat rw [lt_iff_succ_le]\n  intro h\n  apply le_of_add_le_add_left a\n  rw [add_succ]\n  assumption\n\nlemma add_lt_add_right (a b : MyNat) : a < b \u2192 \u2200 c : MyNat, a + c < b + c := by\n  intro h\n  intro c\n  rw [lt_iff_succ_le] at h \u22a2\n  cases h with\n  | _ d hd =>\n    use d\n    rw [hd]\n    repeat rw [succ_add]\n    rw [add_right_comm]\n\n-- BUGBUG: collectibles\n-- and now we get three achievements!\n-- instance : ordered_comm_monoid MyNat :=\n-- { add_le_add_left := \u03bb _ _, add_le_add_left,\n--   lt_of_add_lt_add_left := lt_of_add_lt_add_left,\n--   ..MyNat.add_comm_monoid, ..MyNat.partial_order}\n-- instance : canonically_ordered_monoid MyNat :=\n-- { le_iff_exists_add := le_iff_exists_add,\n--   bot := 0,\n--   bot_le := zero_le,\n--   ..MyNat.ordered_comm_monoid,\n--   }\n-- instance : ordered_cancel_comm_monoid MyNat :=\n-- { add_left_cancel := add_left_cancel,\n--   add_right_cancel := add_right_cancel,\n--   le_of_add_le_add_left := le_of_add_le_add_left,\n--   ..MyNat.ordered_comm_monoid}\n\ndef succ_lt_succ_iff (a b : MyNat) : succ a < succ b \u2194 a < b := by\n  repeat rw [lt_iff_succ_le]\n  exact succ_le_succ_iff _ _\n\n-- multiplication\n\ntheorem mul_le_mul_of_nonneg_left (a b c : MyNat) : a \u2264 b \u2192 0 \u2264 c \u2192 c * a \u2264 c * b := by\n  intro hab\n  intro h0\n  cases hab with\n  | _ d hd =>\n    rw [hd]\n    rw [mul_add]\n    use c * d\n\ntheorem mul_le_mul_of_nonneg_right (a b c : MyNat) : a \u2264 b \u2192 0 \u2264 c \u2192 a * c \u2264 b * c := by\n  intro hab\n  intro h0\n  rw [mul_comm]\n  rw [mul_comm b]\n  apply mul_le_mul_of_nonneg_left\n  assumption\n  assumption\n\ntheorem mul_lt_mul_of_pos_left (a b c : MyNat) : a < b \u2192 0 < c \u2192 c * a < c * b := by\n  intro hab\n  intro hc\n  cases c with\n  | zero =>\n    exfalso\n    exact lt_irrefl 0 hc\n  | succ d =>\n    clear hc\n    induction d with\n    | zero =>\n      rw [succ_mul, zero_is_0, zero_mul]\n      rw [zero_add, succ_mul, zero_mul, zero_add]\n      exact hab\n    | succ e he =>\n      rw [succ_mul]\n      rw [succ_mul (succ e)]\n      have h : succ e * a + a < succ e * b + a := by\n        exact add_lt_add_right _ _ he _\n      apply lt_trans _ _ _ h\n      rw [add_comm]\n      rw [add_comm _ b]\n      apply add_lt_add_right\n      assumption\n\ntheorem mul_lt_mul_of_pos_right (a b c : MyNat) : a < b \u2192 0 < c \u2192 a * c < b * c := by\n  intros ha h0\n  rw [mul_comm]\n  rw [mul_comm b]\n  apply mul_lt_mul_of_pos_left\n  assumption\n  assumption\n\n-- BUGBUG todo\n-- And now another achievement! The naturals are an ordered semiring.\n-- instance : ordered_semiring MyNat :=\n-- { mul_le_mul_of_nonneg_left := mul_le_mul_of_nonneg_left,\n--   mul_le_mul_of_nonneg_right := mul_le_mul_of_nonneg_right,\n--   mul_lt_mul_of_pos_left := mul_lt_mul_of_pos_left,\n--   mul_lt_mul_of_pos_right := mul_lt_mul_of_pos_right,\n--   ..MyNat.semiring,\n--   ..MyNat.ordered_cancel_comm_monoid\n-- }\n\n-- The Orderd semiring would give us this theorem, but we can do it manually instead.\nlemma mul_le_mul {a b c d : MyNat} (hac : a \u2264 c) (hbd : b \u2264 d) (nn_b : 0 \u2264 b) (nn_c : 0 \u2264 c) : a * b \u2264 c * d := by\n  calc\n    a * b \u2264 c * b := mul_le_mul_of_nonneg_right _ _ _ hac nn_b\n    _ \u2264 c * d := mul_le_mul_of_nonneg_left _ _ _ hbd nn_c\n\nlemma le_mul (a b c d : MyNat) : a \u2264 b \u2192 c \u2264 d \u2192 a * c \u2264 b * d := by\n  intros hab hcd\n  induction a with\n  | zero =>\n    rw [zero_is_0, zero_mul]\n    apply zero_le\n  | succ t Ht =>\n    have cz : 0 \u2264 c := by\n      apply zero_le\n    have bz : 0 \u2264 b := by\n      apply zero_le\n    apply mul_le_mul hab hcd cz bz\n\nlemma pow_le (m n a : MyNat) : m \u2264 n \u2192 m ^ a \u2264 n ^ a := by\n  intro h\n  induction a with\n  | zero =>\n    rw [zero_is_0, pow_zero, pow_zero]\n  | succ t Ht =>\n    rw [pow_succ, pow_succ]\n    apply le_mul\n    assumption\n    assumption\n\nlemma strong_induction_aux (P : MyNat \u2192 Prop)\n  (IH : \u2200 m : MyNat, (\u2200 b : MyNat, b < m \u2192 P b) \u2192 P m)\n  (n : MyNat) : \u2200 c < n, P c := by\n  induction n with\n  | zero =>\n    intro c\n    intro hc\n    exfalso\n    revert hc\n    exact not_lt_zero c\n  | succ d hd =>\n    intros e he\n    rw [lt_succ_iff_le] at he\n    apply IH\n    intros b hb\n    apply hd\n    exact lt_of_lt_of_le _ _ _ hb he\n\ntheorem strong_induction (P : MyNat \u2192 Prop)\n  (IH : \u2200 m : MyNat, (\u2200 d : MyNat, d < m \u2192 P d) \u2192 P m) :\n  \u2200 n, P n := by\n  intro n\n  apply strong_induction_aux P IH (succ n)\n  exact lt_succ_self n\n\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level18.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8596637487122112, "lm_q1q2_score": 0.7453592203998518}}
{"text": "import .love08_operational_semantics_exercise_sheet\nimport .love09_hoare_logic_demo\n\n\n/-! # LoVe Homework 9: Hoare Logic\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (6 points): Hoare Logic for Dijkstra's Guarded Command Language\n\nRecall the definition of GCL from exercise 8: -/\n\nnamespace gcl\n\n#check stmt\n#check big_step\n\n/-! The definition of Hoare triples for partial correctness is unsurprising: -/\n\ndef partial_hoare (P : state \u2192 Prop) (S : stmt state) (Q : state \u2192 Prop) :\n  Prop :=\n\u2200s t, P s \u2192 (S, s) \u27f9 t \u2192 Q t\n\nlocal notation `{* ` P : 1 ` *} ` S : 1 ` {* ` Q : 1 ` *}` :=\npartial_hoare P S Q\n\nnamespace partial_hoare\n\n/-! 1.1 (4 points). Prove the following Hoare rules: -/\n\nlemma consequence {P P' Q Q' : state \u2192 Prop} {S} (h : {* P *} S {* Q *})\n    (hp : \u2200s, P' s \u2192 P s) (hq : \u2200s, Q s \u2192 Q' s) :\n  {* P' *} S {* Q' *} :=\nsorry\n\nlemma assign_intro {P : state \u2192 Prop} {x} {a : state \u2192 \u2115}:\n  {* \u03bbs, P (s{x \u21a6 a s}) *} stmt.assign x a {* P *} :=\nsorry\n\nlemma assert_intro {P Q : state \u2192 Prop} :\n  {* \u03bbs, Q s \u2192 P s *} stmt.assert Q {* P *} :=\nsorry\n\nlemma seq_intro {P Q R S T} (hS : {* P *} S {* Q *}) (hT : {* Q *} T {* R *}) :\n  {* P *} stmt.seq S T {* R *} :=\nsorry\n\nlemma choice_intro {P Q Ss}\n    (h : \u2200i (hi : i < list.length Ss), {* P *} list.nth_le Ss i hi {* Q *}) :\n  {* P *} stmt.choice Ss {* Q *} :=\nsorry\n\n/-! 1.2 (2 points). Prove the rule for `loop`. Notice the similarity with the\nrule for `while` in the WHILE language. -/\n\nlemma loop_intro {P S} (h : {* P *} S {* P *}) :\n  {* P *} stmt.loop S {* P *} :=\nsorry\n\nend partial_hoare\n\nend gcl\n\n\n/-! ## Question 2 (3 points): Factorial\n\nThe following WHILE program is intended to compute the factorial of `n`, leaving\nthe result in `r`. -/\n\ndef FACT : stmt :=\nstmt.assign \"r\" (\u03bbs, 1) ;;\nstmt.while (\u03bbs, s \"n\" \u2260 0)\n  (stmt.assign \"r\" (\u03bbs, s \"r\" * s \"n\") ;;\n   stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n\n/-! 2.1 (1 point). Define the factorial function. -/\n\ndef fact : \u2115 \u2192 \u2115 :=\nsorry\n\n/-! 2.2 (2 points). Prove the correctness of `FACT` using `vcg`. -/\n\nlemma FACT_correct (n\u2080 : \u2115) :\n  {* \u03bbs, s \"n\" = n\u2080 *} FACT {* \u03bbs, s \"r\" = fact n\u2080 *} :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2021", "sha": "23b469c79afd482fa66da82e4726a317e3a7b5d5", "save_path": "github-repos/lean/blanchette-logical_verification_2021", "path": "github-repos/lean/blanchette-logical_verification_2021/logical_verification_2021-23b469c79afd482fa66da82e4726a317e3a7b5d5/lean/love09_hoare_logic_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7453591966073533}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport algebra.big_operators data.nat.gcd\n\nopen finset\n\nnamespace nat\n\ndef totient (n : \u2115) : \u2115 := ((range n).filter (nat.coprime n)).card\n\nlocal notation `\u03c6` := totient\n\nlemma totient_le (n : \u2115) : \u03c6 n \u2264 n :=\ncalc totient n \u2264 (range n).card : card_le_of_subset (filter_subset _)\n           ... = n              : card_range _\n\nlemma totient_pos : \u2200 {n : \u2115}, 0 < n \u2192 0 < \u03c6 n\n| 0 := dec_trivial\n| 1 := dec_trivial\n| (n+2) := \u03bb h, card_pos.2 (mt eq_empty_iff_forall_not_mem.1\n(not_forall_of_exists_not \u27e81, not_not.2 $ mem_filter.2 \u27e8mem_range.2 dec_trivial, by simp [coprime]\u27e9\u27e9))\n\n\n\nend nat", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/data/nat/totient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7453508651509982}}
{"text": "import DFA\nimport data.fintype.basic\nimport order.boolean_algebra\nimport data.quot\n\n\nuniverses u v\n\ndef is_regular {\u03b1 : Type u} [fintype \u03b1] (l : language \u03b1) : Prop := \n\u2203 (\u03c3 : Type v) [fintype \u03c3] (A : DFA \u03b1 \u03c3), A.accepts = l\n\nlemma is_regular_def {\u03b1 : Type u} [fintype \u03b1] {l : language \u03b1} : \n(is_regular.{u v}) l \u2194 (\u2203 (\u03c3 : Type v) [fintype \u03c3] (A : DFA \u03b1 \u03c3), A.accepts = l) :=\niff.refl _\n\nnamespace regular_language\n\nopen DFA\n\nsection basic\n/--\nHere we prove basic things on regular languages, such as the they form a boolean algebra\n-/\n\nvariables {\u03b1 : Type u} [fintype \u03b1]\nvariables {l l' : language \u03b1}\n\nlemma inf_regular : (is_regular.{u v} l) \u2192 (is_regular.{u v} l') \u2192 is_regular.{u v} (l \u2293 l') :=\nbegin\n  rintros \u27e8\u03c3, h\u03c3, A, hA\u27e9,\n  rintros \u27e8\u03c4, h\u03c4, B, hB\u27e9,\n  resetI,\n  refine \u27e8\u03c3 \u00d7 \u03c4, infer_instance, inter A B, _\u27e9,\n  rw [inter_accepts, hA, hB],\nend\n\nlemma compl_regular : (is_regular.{u v} l) \u2192 (is_regular.{u v} l\u1d9c) :=\nbegin\n  rintros \u27e8Q, hQ, A, hA\u27e9,\n  refine \u27e8Q, hQ, A.compl, _\u27e9,\n  rw [compl_accepts, hA]\nend\n\nlemma compl_regular_iff : (is_regular.{u v} l\u1d9c) \u2194 (is_regular.{u v} l) :=\nbegin\n  split,\n  {\n    intro h,\n    rw \u2190 compl_compl l,\n    exact compl_regular h \n  },\n  { exact compl_regular },\nend\n\nlemma sup_regular : (is_regular.{u v} l) \u2192 (is_regular.{u v} l') \u2192 is_regular.{u v} (l \u2294 l') :=\nbegin\n  intros hl hl',\n  rw [\u2190compl_compl (l \u2294 l'), compl_sup, compl_regular_iff],\n  exact inf_regular (compl_regular hl) (compl_regular hl'),\nend\n\nend basic\n\nsection relation\n/-!\n### Myhill-Nerode theorem\n\nGiven `l`, we define an equivalence relation on `list \u03b1`. \nThe main theorem is that `l` is regular iff the number of \nequivalence classes of this relation is finite.\n-/\n\n\nparameters {\u03b1 : Type u} [fintype \u03b1]\n\nsection basic\n\nparameters (l : language \u03b1)\n\n/--\nA relation on `list \u03b1`, identifying `x, y` if for all \n`z : list \u03b1`, `(x ++ z \u2208 l) \u2194 (y ++ z \u2208 l)`.\n-/\ndef rel : list \u03b1 \u2192 list \u03b1 \u2192 Prop :=\n\u03bb x y, \u2200 (z : list \u03b1), (x ++ z \u2208 l) \u2194 (y ++ z \u2208 l)\n\nparameter {l}\n\nlemma iff_mem_language_of_equiv {x y : list \u03b1} (Rxy : rel x y) : x \u2208 l \u2194 y \u2208 l :=\nbegin\n  specialize Rxy [],\n  repeat {rwa list.append_nil at Rxy},\nend \n\nparameter (l)\n\nlemma rel_refl : reflexive (rel) := \u03bb _ _, by refl\nlemma rel_symm : symmetric (rel) := \u03bb _ _ hxy z, iff.symm (hxy z)\nlemma rel_trans : transitive (rel) := \u03bb _ _ _ hxy hyz z, iff.trans (hxy z) (hyz z)\nlemma rel_equiv : equivalence (rel) := \u27e8rel_refl, rel_symm, rel_trans\u27e9\n\ninstance space.setoid : setoid (list \u03b1) := setoid.mk rel rel_equiv\n\ndefinition space := quotient space.setoid\n\nparameter {l}\n\ndefinition mk (x : list \u03b1) : space := @quotient.mk _ space.setoid x\n\n@[simp] lemma mk_def (x : list \u03b1) : mk x = @quotient.mk _ space.setoid x := rfl\n\nend basic\n\nsection finite_class_space\n/-!\n### Myhill-Nerode, first direction\n\nWe build an automaton accepting `l` whose states are `space l`.\nAs a consequence, if `space l` is finite, then `l` is regular.\n-/\n\nparameters (l : language \u03b1)\n\ndef to_DFA : DFA \u03b1 (space l) := \n{\n  step := begin\n    apply quot.lift (\u03bb (z : list \u03b1) (\u03c3 : \u03b1), (mk (z ++ [\u03c3]) : space l)),\n    intros x y r,\n    ext \u03c3,\n    simp only [regular_language.mk_def, quotient.eq],\n    intro z,\n    simp [r (\u03c3 :: z)],\n  end,\n  start := mk [],\n  accept := begin\n    apply quot.lift (\u2208 l),\n    intros x y r,\n    simp [iff_mem_language_of_equiv r],\n  end\n}\n\n@[simp] lemma to_DFA_step (w : list \u03b1) (\u03c3 : \u03b1) : to_DFA.step (mk w) \u03c3 = mk (w ++ [\u03c3]) := rfl\n@[simp] lemma to_DFA_start : to_DFA.start = mk [] := rfl\n@[simp] lemma to_DFA_accept (w : list \u03b1) : (mk w) \u2208 to_DFA.accept \u2194 w \u2208 l := by refl\n\n@[simp] lemma to_DFA_eval_from (x y : list \u03b1) : eval_from to_DFA (mk x) y = mk (x ++ y) :=\nbegin\n  induction y with \u03c3 y generalizing x,\n  { \n    simp,\n    exact rel_refl l _,\n  },\n  {\n    specialize y_ih (x ++ [\u03c3]),\n    simp at *,\n    exact y_ih,\n  }\nend\n\nlemma to_DFA_accepts : accepts to_DFA = l :=\nbegin\n  ext,\n  rw [mem_accepts, to_DFA_start, to_DFA_eval_from, list.nil_append, to_DFA_accept],\nend\n\ntheorem regular_of_fintype_language_space [fintype (space l)] : is_regular.{u u} l := \n  \u27e8space l, infer_instance, to_DFA, to_DFA_accepts\u27e9\n\nend finite_class_space\n\nsection regular\n/-!\n### Myhill-Nerode, the other direction.\n\nNow we wish to prove that if `l` is regular then `space l` is finite.\nWe prove this using the canonical functions `Q \u21a9 DFA_space \u21a0 space l`,\nthe first of which we constructed in DFA.relation.\n-/\nparameters {Q : Type u} (A : DFA \u03b1 Q)\n\nprivate def l := A.accepts\n\n@[simp] private lemma l_def : l = A.accepts := rfl\n\nlemma language_rel_of_DFA_rel (x y : list \u03b1) : A.rel x y \u2192 rel l x y :=\nbegin\n  intros r z,\n  rw rel_def at r,\n  rw [l_def, mem_accepts, mem_accepts, eval_from_of_append, eval_from_of_append,\n  \u2190 eval_def, \u2190 eval_def, r],\nend\n\ndefinition language_space_of_DFA_space : A.space \u2192 space l := \nby exact quot.map id (language_rel_of_DFA_rel _)\n\n@[simp] lemma language_space_of_DFA_space_def (w : list \u03b1) : \nlanguage_space_of_DFA_space (DFA.space.mk w) = mk w := rfl\n\nlemma language_space_of_DFA_space_surjective : function.surjective language_space_of_DFA_space :=\nbegin\n  apply quotient.ind,\n  intro w,\n  use DFA.space.mk w,\n  rw language_space_of_DFA_space_def,\n  refl\nend\n\nopen classical\nlocal attribute [instance] prop_decidable\n\nnoncomputable instance fintype_language_space_of_regular (l : language \u03b1) (r : is_regular l) : \nfintype (space l) :=\nbegin\n  choose Q fQ A hA using r,\n  rw \u2190 hA,\n  resetI,\n  haveI : fintype A.space := DFA.fintype_space_of_fintype_states _,\n  exact fintype.of_surjective _ (language_space_of_DFA_space_surjective _),\nend\n\nend regular\n\nend relation\n\nend regular_language\n\nvariable (\u03b1 : Type u)\n", "meta": {"author": "atarnoam", "repo": "lean-automata", "sha": "46c69ddaa142913b1f43ef57f700f2481cdfba76", "save_path": "github-repos/lean/atarnoam-lean-automata", "path": "github-repos/lean/atarnoam-lean-automata/lean-automata-46c69ddaa142913b1f43ef57f700f2481cdfba76/src/regular_languages.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7453165902478863}}
{"text": "variables p q r : Prop \n\nnamespace mth1001\n\nsection and_introduction\n\n/-\nIn the previous section, we saw how to eliminate `\u2227`. That is, we saw how to take a premise\ninvolving `\u2227` and derive a statement in which that occurrence of `\u2227` has been removed.\n\nIn this section, we do the opposite. We introduce `\u2227`.\n-/\n\n/-\nThe following can be read in standard maths as:\n\n  Given `hp : p` and `hq : q`, `p \u2227 q` follows by and introduction on `hp` and `hq`.\n\nor:\n\n  Given `p` and `q`, `p \u2227 q` follows by and introduction on `p` and `q`.\n-/\nexample (hp : p) (hq : q) : p \u2227 q :=\nand.intro hp hq\n\n-- Below, the symbols `\u27e8` and `\u27e9` are entered as `\\<` and `\\>`.\nexample (hp : p) (hq : q) : p \u2227 q :=\n\u27e8hp, hq\u27e9\n\n/-\nBelow, the `split` tactic decoposes the goal `p \u2227 q` into two subgoals, `p`\nand `q`. Compare this with the `cases` tactic that decomposes the premise.\n\nWe wrote write this in standard maths as:\n\n  Given `hp : p` and `hq : q`, `p \u2227 q` follows.\n  Proof: It suffices to prove both `p` and `q`.\n  `p` follows from `hp`.\n  `q` follows from `hq`.\n\nor:\n\n  Given `p` and `q`, `p \u2227 q` follows.\n  Proof: It suffices to prove both `p` and `q`.\n  `p` follows from `p`.\n  `q` follows from `q`.\n-/\nexample (hp : p) (hq : q) : p \u2227 q :=\nbegin \n  split,\n    exact hp,\n    exact hq,\nend\n\n-- It is considered good style to wrap braces around each new subgoal.\nexample (hp : p) (hq : q) : p \u2227 q :=\nbegin \n  split,\n  { exact hp, },\n  { exact hq, },\nend\n\n-- We can even combine tactic-style and term-style proofs.\nexample (hp : p) (hq : q) : p \u2227 q :=\nby exact and.intro hp hq\n\n-- Exercise 016:\n-- Use both `cases` and `split` to complete the following proof. Either write in Lean and convert\n-- into standard maths or the other way round.\n-- There isn't only one correct solution. Find as many essentially different solutions as you can.\nexample (h : p \u2227 q) : q \u2227 p :=\nbegin\n  sorry  \nend\n\n-- Exercise 017:\n-- This time, use `cases`, but complete the proof using `and.intro` or `\u27e8` and `\u27e9`\nexample (h : p \u2227 q) : q \u2227 p :=\nbegin\n  sorry  \nend\n\n-- Exercise 018:\n-- Give a one-line proof term.\nexample (h : p \u2227 q) : q \u2227 p :=\nsorry \n\n-- We'll prove one direction of associativity of `\u2227`. First using tactics. \nexample (h : p \u2227 (q \u2227 r)) : (p \u2227 q) \u2227 r := \nbegin \n  cases h with hp hqr,\n  cases hqr with hq hr,\n  split,\n  { split,\n    { exact hp, },\n    { exact hq, }},\n  { exact hr, },\nend\n\n-- Now as a purely term-style proof. Not very readable!\nexample (h : p \u2227 (q \u2227 r)) : (p \u2227 q) \u2227 r := \n\u27e8 \u27e8h.1, h.2.1 \u27e9, h.2.2 \u27e9 \n\n-- To aid readability, we can introduce statements into the context using `have`.\n-- In tactic mode, the `have` tactic must be followed by a tactic that closes the goal.\nexample (h : p \u2227 q) : q \u2227 p :=\nbegin \n  have hp : p,\n  { exact h.left, },\n  have hq : q, \n  { exact h.right, },\n  exact \u27e8hq, hp\u27e9, -- Here, `\u27e8hq, hp\u27e9` is a abbreviation of `and.intro hq hp`.\nend\n\n-- In a term-style proof, we use `have` \u2026 `from`.\nexample (h : p \u2227 q) : q \u2227 p :=\nhave hp : p, from h.left,\nhave hq : q, from h.right,\n\u27e8hq, hp\u27e9\n\n-- We can emulate the term-style `have` \u2026 `from` in tactic mode using either \nexample (h : p \u2227 q) : q \u2227 p :=\nbegin \n  have hp : p, from h.left,\n  have hq : q := h.right,\n  exact and.intro hq hp, -- I could have written `\u27e8hq, hp\u27e9` instead of `and.intro hq hp`.\nend\n\n-- Exercise 019:\n-- Fill in the `sorry`s below to give a proof of the goal introduced by the `have` tactic.\nexample (h : p \u2227 (q \u2227 r)) : (p \u2227 q) \u2227 r :=\nbegin\n  cases h with hp hqr,\n  have hpq : p \u2227 q, -- Follow `have` by a tactic that closes the goal `p \u2227 q`.\n  { split,\n    { sorry, }, \n    { sorry, }, }, \n  have hr : r, from -- `have` \u2026 `from` should be followed by a proof term for the goal `r`.\n    sorry,\n  exact \u27e8hpq, hr\u27e9,\nend\n\n-- Exercise 020:\n-- Complete the following term-style proof of the above result.\nexample (h : p \u2227 (q \u2227 r)) : (p \u2227 q) \u2227 r := \nhave hp : p, from sorry, \nhave hqr : q \u2227 r, from h.2,\nhave hpq : p \u2227 q, from sorry, \nhave hr : r, from hqr.2,\n\u27e8hpq, hr\u27e9\n\n-- To further aid readability, `show` \u2026 `from` indicates what we are proving.\nexample (h : p \u2227 (q \u2227 r)) : (p \u2227 q) \u2227 r := \nhave hp : p, from sorry, \nhave hqr : q \u2227 r, from h.2,\nhave hpq : p \u2227 q, from sorry, \nhave hr : r, from hqr.2,\nshow (p \u2227 q) \u2227 r, from \u27e8hpq, hr\u27e9\n\n\n-- Exercise 021:\n/-\nProve the other direction of associativity of `\u2227`. Choose whatever proof style you like.\nAdd `begin` and `end` if you want to use a tactic-style proof.\n-/\nexample (h : (p \u2227 q) \u2227 r) : p \u2227 (q \u2227 r) :=\nsorry \n\nend and_introduction\n\n/-\nSUMMARY\n\n* And introduction.\n* Term-style proof using `and.intro` or `\u27e8` and `\u27e9`.\n* Tactic-sytyle and introduction using `split`.\n* Proving intermediate steps with `have`.\n* Using `show` to indicate what is being proved. \n-/\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_02_and_introduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.868826771143471, "lm_q1q2_score": 0.7452518993664137}}
{"text": "import .lovelib\n\n\n/-! # LoVe Homework 8: Operational Semantics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (6 points + 1 bonus point): Semantics of the REPEAT Language\n\nWe introduce REPEAT, a programming language that resembles the WHILE language\nbut whose defining feature is a `repeat` loop.\n\nThe Lean definition of its abstract syntax tree follows: -/\n\ninductive stmt : Type\n| skip   : stmt\n| assign : string \u2192 (state \u2192 \u2115) \u2192 stmt\n| seq    : stmt \u2192 stmt \u2192 stmt\n| unless : (state \u2192 Prop) \u2192 stmt \u2192 stmt\n| repeat : \u2115 \u2192 stmt \u2192 stmt\n\ninfixr ` ;; ` : 90 := stmt.seq\n\n/-! The `skip`, `assign`, and `S ;; T` statements have the same syntax and\nsemantics as in the WHILE language.\n\nThe `unless b S` statement executes `S` unless `b` is true\u2014i.e., it executes `S`\nif `b` is false. Otherwise, `unless b S` does nothing. This construct is\ninspired by the Perl language.\n\nThe `repeat n S` statement executes `S` exactly `n` times. Thus, `repeat 5 S`\nhas the same effect as `S ;; S ;; S ;; S ;; S` (as far as the big-step semantics\nis concerned), and `repeat 0 S` has the same effect as `skip`.\n\n1.1 (1.5 points). Complete the following definition of a big-step\nsemantics: -/\n\ninductive big_step : stmt \u00d7 state \u2192 state \u2192 Prop\n| skip {s} :\n  big_step (stmt.skip, s) s\n-- enter the missing cases here\n\ninfix ` \u27f9 ` : 110 := big_step\n\n/-! 1.2 (1.5 points). Complete the following definition of a small-step\nsemantics: -/\n\ninductive small_step : stmt \u00d7 state \u2192 stmt \u00d7 state \u2192 Prop\n| assign {x a s} :\n  small_step (stmt.assign x a, s) (stmt.skip, s{x \u21a6 a s})\n-- enter the missing cases here\n\ninfixr ` \u21d2 ` := small_step\ninfixr ` \u21d2* ` : 100 := star small_step\n\n/-! 1.3 (1 point). We will now attempt to prove termination of the REPEAT\nlanguage. More precisely, we will show that there cannot be infinite chains of\nthe form\n\n    `(S\u2080, s\u2080) \u21d2 (S\u2081, s\u2081) \u21d2 (S\u2082, s\u2082) \u21d2 \u22ef`\n\nTowards this goal, you are asked to define a __measure__ function: a function\n`mess` that takes a statement `S` and that returns a natural number indicating\nhow \"big\" the statement is. The measure should be defined so that it strictly\ndecreases with each small-step transition. -/\n\ndef mess : stmt \u2192 \u2115\n| stmt.skip         := 0\n-- enter the missing cases here\n\n/-! 1.4 (1 point). Consider the following program `S\u2080`: -/\n\ndef incr (x : string) : stmt :=\nstmt.assign x (\u03bbs, s x + 1)\n\ndef S\u2080 : stmt :=\nstmt.repeat 1 (incr \"m\" ;; incr \"n\")\n\n/-! Check that `mess` strictly decreases with each step of its small-step\nevaluation, by giving `S\u2080`, `S\u2081`, `S\u2082`, \u2026, as well as the corresponding values\nof `mess` (which you can obtain using `#eval`). -/\n\n-- enter your answer here\n\n/-! 1.5 (1 point). Prove that the measure decreases with each small-step\ntransition. If necessary, revise your answer to question 1.3. -/\n\nlemma small_step_mess_decreases {Ss Tt : stmt \u00d7 state} (h : Ss \u21d2 Tt) :\n  mess (prod.fst Ss) > mess (prod.fst Tt) :=\nsorry\n\n/-! 1.6 (1 bonus point). Prove that the inverse of the `\u21d2` relation is well\nfounded. The inverse is simply `\u03bbTt Ss, Ss \u21d2 Tt`. A relation `\u227a` is well founded\nif there exist no infinite left-descending chains of the form\n\n    `\u22ef \u227a x\u2082 \u227a x\u2081 \u227a x\u2080`\n\nProof strategy: The `measure` function from `mathlib` converts a function to `\u2115`\nto a relation, using `<` to compare two numbers. Hence, start by proving that\n`measure mess`, or rather `measure (mess \u2218 prod.fst)`, is well founded. Here,\n`library_search` can help, or just search manually in `wf.lean`, close to the\ndefinition of `measure`. Then prove that `\u03bbTt Ss, Ss \u21d2 Tt` is a subrelation of\n`measure (mess \u2218 prod.fst)` (using lemma `small_step_mess_decreases` from\nquestion 1.5) and therefore (using another lemma from `wf.lean`) that it must be\nwell founded. -/\n\nlemma small_step_wf :\n  well_founded (\u03bbTt Ss, Ss \u21d2 Tt) :=\nsorry\n\n\n/-! ## Question 2 (3 points): Inversion Rules\n\n2.1 (1 point). Prove the following inversion rule for the big-step semantics\nof `unless`. -/\n\nlemma big_step_ite_iff {b S s t} :\n  (stmt.unless b S, s) \u27f9 t \u2194 (b s \u2227 s = t) \u2228 (\u00ac b s \u2227 (S, s) \u27f9 t) :=\nsorry\n\n/-! 2.2 (2 points). Prove the following inversion rule for the big-step\nsemantics of `repeat`. -/\n\nlemma big_step_repeat_iff {n S s u} :\n  (stmt.repeat n S, s) \u27f9 u \u2194\n  (n = 0 \u2227 u = s)\n  \u2228 (\u2203m t, n = m + 1 \u2227 (S, s) \u27f9 t \u2227 (stmt.repeat m S, t) \u27f9 u) :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2022", "sha": "5aee593fbef9b63d4338288b4789d85851d258aa", "save_path": "github-repos/lean/blanchette-logical_verification_2022", "path": "github-repos/lean/blanchette-logical_verification_2022/logical_verification_2022-5aee593fbef9b63d4338288b4789d85851d258aa/lean/love08_operational_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7452518974184883}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function World\n\n## Level 3: the `have` tactic.\n\nSay you have a whole bunch of sets and functions between them,\nand your goal is to build a certain element of a certain set.\nIf it helps, you can build intermediate elements of other sets\nalong the way, using the [have tactic](../Tactics/have.lean.md). `have` is the Lean analogue\nof saying \"let's define an element `q \u2208 Q` by...\" in the middle of a calculation.\nIt is often not logically necessary, but on the other hand\nit is very convenient, for example it can save on notation, or\nit can break proofs or calculations up into smaller steps.\n\nIn this level, we have an element of `P` and we want an element\nof `U`; during the proof we will make several intermediate elements\nof some of the other sets involved. The diagram of sets and\nfunctions looks like this pictorially:\n\n![diagram](../assets/function_diag.svg)\n\nand so it's clear how to make the element of `U` from the element of `P.`\nIndeed, we could solve this level in one move by typing\n\n`exact l (j (h p))`\n\nBut let us instead stroll more lazily through the level.\nWe can start by using the `have` tactic to make an element of `Q`:\n\n`have q := h p`\n\nand then we note that `j q` is an element of `T`\n\n`have t : T := j q`\n\n(notice how on this occasion we explicitly told Lean what set we thought `t` was in, with\nthat `: T` thing before the `:=`) and we could even define `u` to be `l t`:\n\n`have u : U := l t`\n\nand then finish the level with `exact u`.\n\n## Definition\nGiven an element of `P` we can define an element of `U`.\n\n-/\nexample (P Q R S T U: Type)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U := by\n  have q := h p\n  have t : T := j q\n  have u : U := l t\n  exact u\n\n/-!\nRemember you can move your cursor around with the arrow keys and explore the various tactic states\nin this proof in Visual Studio Code, and note that the tactic state at the beginning of `exact u` is\nthis mess:\n\n```\nP Q R S T U : Type,\np : P,\nh : P \u2192 Q,\ni : Q \u2192 R,\nj : Q \u2192 T,\nk : S \u2192 T,\nl : T \u2192 U,\nq : Q,\nt : T,\nu : U\n\u22a2 U\n```\n\nIt was already bad enough to start with, and we added three more\nterms to it. In level 4 we will learn about the `apply` tactic\nwhich solves the level using another technique, without leaving\nso much junk behind.\n\nNext up [Level 4](./Level4.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/FunctionWorld/Level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7451036276928034}}
{"text": "/-\nCopyright (c) 2023 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport algebra.monoid_algebra.ideal\nimport data.mv_polynomial.division\n\n/-!\n# Lemmas about ideals of `mv_polynomial`\n\nNotably this contains results about monomial ideals.\n\n## Main results\n\n* `mv_polynomial.mem_ideal_span_monomial_image`\n* `mv_polynomial.mem_ideal_span_X_image`\n-/\n\nvariables {\u03c3 R : Type*}\n\nnamespace mv_polynomial\nvariables [comm_semiring R]\n\n\n/-- `x` is in a monomial ideal generated by `s` iff every element of of its support dominates one of\nthe generators. Note that `si \u2264 xi` is analogous to saying that the monomial corresponding to `si`\ndivides the monomial corresponding to `xi`. -/\nlemma mem_ideal_span_monomial_image\n  {x : mv_polynomial \u03c3 R} {s : set (\u03c3 \u2192\u2080 \u2115)} :\n  x \u2208 ideal.span ((\u03bb s, monomial s (1 : R)) '' s) \u2194 \u2200 xi \u2208 x.support, \u2203 si \u2208 s, si \u2264 xi :=\nbegin\n  refine add_monoid_algebra.mem_ideal_span_of'_image.trans _,\n  simp_rw [le_iff_exists_add, add_comm],\n  refl,\nend\n\nlemma mem_ideal_span_monomial_image_iff_dvd {x : mv_polynomial \u03c3 R} {s : set (\u03c3 \u2192\u2080 \u2115)} :\n  x \u2208 ideal.span ((\u03bb s, monomial s (1 : R)) '' s) \u2194\n    \u2200 xi \u2208 x.support, \u2203 si \u2208 s, monomial si 1 \u2223 monomial xi (x.coeff xi) :=\nbegin\n  refine mem_ideal_span_monomial_image.trans (forall\u2082_congr $ \u03bb xi hxi, _),\n  simp_rw [monomial_dvd_monomial, one_dvd, and_true, mem_support_iff.mp hxi, false_or],\nend\n\n/-- `x` is in a monomial ideal generated by variables `X` iff every element of of its support\nhas a component in `s`. -/\nlemma mem_ideal_span_X_image {x : mv_polynomial \u03c3 R} {s : set \u03c3} :\n  x \u2208 ideal.span (mv_polynomial.X '' s : set (mv_polynomial \u03c3 R)) \u2194\n    \u2200 m \u2208 x.support, \u2203 i \u2208 s, (m : \u03c3 \u2192\u2080 \u2115) i \u2260 0 :=\nbegin\n  have := @mem_ideal_span_monomial_image \u03c3 R _ _ ((\u03bb i, finsupp.single i 1) '' s),\n  rw set.image_image at this,\n  refine this.trans _,\n  simp [nat.one_le_iff_ne_zero],\nend\n\nend mv_polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/mv_polynomial/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7451036094888848}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport data.set.lattice -- para uniones e intersecciones arbitrarias\n\n/-\n\n# Conjuntos\n\nRecordad que `set X` es el tipo de subconjuntos de `X`. Es decir, `S : set X` \nindica que `S` es un conjunto de t\u00e9rminos de `X`.\n\nEn la segunda sesi\u00f3n del curso, aprendimos a indicar pertenencia a \nun conjunto (`x \u2208 S`, donde `x : X`) y demostramos algunos lemas sobre\ninclusi\u00f3n de conjuntos (`\u2286`), uniones (`\u222a`) e intersecciones (`\u2229`).\n\n\n## Detalle de implementaci\u00f3n\n\nInternamente, `set X` est\u00e1 implementado como una funci\u00f3n de `X` a `Prop`. \nUn `S : set X` est\u00e1 representado mediante la funci\u00f3n que manda todos\nlos elementos de `S` a `true` y el resto de elementos de `X` a `false.`\nEl enunciado `a \u2208 S` est\u00e1 representado por la proposici\u00f3n `S a`.\n\nSin embargo, para trabajar con conjuntos en Lean no es necesario conocer\neste detalle de implementaci\u00f3n, sino cu\u00e1l es la API disponible (es decir,\nqu\u00e9 resultados sobre conjuntos ya est\u00e1n demostrados en mathlib).\n\n## Notaci\u00f3n\n\nDados tipos `(X Y : Type)` y una funci\u00f3n `f : X \u2192 Y`:\n\nEl conjunto vac\u00edo es `\u2205 : set X`.\n\nEl conjunto que contiene todos los elementos de `X` es `univ : set X`.\n\nEl complemento de `S : set X` es `S\u1d9c : set X`.\n\nDado `S : set X`, la imagen de `S` bajo `f` se denota como `f '' S : set Y`.\n\nDado `T : set Y`, `f \u207b\u00b9' T : set X` denota la preimagen de `T`.\n\nEl rango de `f` se puede escribir como `f '' univ` \u00f3 `range f`. \n\n-/\n\nvariables (X Y Z : Type) (f : X \u2192 Y) (g : Y \u2192 Z) (S : set X) (y : Y)\n\nopen set\n\n/-!\n\n## Imagen\n\n`y \u2208 f '' S` es definicionalmente igual a `\u2203 x : X, x \u2208 S \u2227 f x = y`,\ny el correspondiente lema de reescritura es\n`mem_image f S y : y \u2208 f '' S \u2194 \u2203 (x : X), x \u2208 S \u2227 f x = y`\n-/\n\n-- Vamos a ver c\u00f3mo simplificar el siguiente ejemplo.\nexample : id '' S = S :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    rw mem_image at hx,\n    obtain \u27e8x', h, h'\u27e9 := hx,\n    rw \u2190 h',\n    exact h, },\n  { intro hx,\n    rw mem_image,\n    use x,\n    use hx,\n    refl, },\nend\n\n-- Aunque por supuesto ya lo tenemos en mathlib:\nexample : id '' S = S :=\nbegin\n  apply image_id', -- por ejemplo, `simp` o `library_search` lo demostrar\u00edan\nend\n\n\nlemma image_comp (S : set X) : (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  sorry\nend\n\nopen function\n\n-- Recordad que pod\u00e9is usar `dsimp only` para simplificar las evaluaciones de lambdas.\nlemma image_injective : injective f \u2192 injective (\u03bb S, f '' S) :=\nbegin\n  sorry\nend\n\n/-!\n\n## Preimagen\n\nPor definici\u00f3n, tenemos `x \u2208 f \u207b\u00b9' T \u2194 f x \u2208 T`. El correspondiente lema\nde reescritura es `mem_preimage : x \u2208 f \u207b\u00b9' T \u2194 f x \u2208 T`.\n-/\n\nexample (S : set X) : S = id \u207b\u00b9' S :=\nbegin\n  sorry\nend\n\n-- Una vez terminado este ejercicio, mirad la soluci\u00f3n propuesta.\nexample (T : set Z) : (g \u2218 f) \u207b\u00b9' T = f \u207b\u00b9' (g \u207b\u00b9' T) :=\nbegin\n  refl,\nend\n\n/-- `squeeze_simp` o ` library_search` encuentran la demostraci\u00f3n de este lema \n  y los dos siguientes en la librer\u00eda, pero intentad demostrarlos a partir de\n  las definiciones. -/\nlemma preimage_injective (hf : surjective f) : injective (\u03bb T, f \u207b\u00b9' T) :=\nbegin\n  sorry\nend\n\nlemma image_surjective (hf : surjective f) : surjective (\u03bb S, f '' S) :=\nbegin\n  sorry\nend\n\nlemma preimage_surjective (hf : injective f) : surjective (\u03bb S, f \u207b\u00b9' S) :=\nbegin\n  sorry\nend\n\n/-!\n\n## Uniones arbitrarias (`Union`)\n\nDado un tipo `(\u03b9 : Type)` y una funci\u00f3n `(F : \u03b9 \u2192 set X)` , los\n`F i` para `i : \u03b9` son una familia de subconjuntos de `X`, y por\ntanto podemos tomar su uni\u00f3n.\nEn Lean, esto se representa mediante `Union F` (la U may\u00fascula es\nnecesaria para uniones arbitrarias). Tambi\u00e9n est\u00e1 disponible la\nnotaci\u00f3n `\u22c3 (i : \u03b9), F i`.\n\nPod\u00e9is utilizar el siguiente lema, que dice que `x : X` pertenece\na `Union F` si y s\u00f3lo si pertenece a uno de los conjuntos `F i`:\n`mem_Union : (x \u2208 \u22c3 (i : \u03b9), F i) \u2194 \u2203 j : \u03b9, x \u2208 F j`\n\n-/\n\nvariables (\u03b9 : Type) (F : \u03b9 \u2192 set X) (x : X)\n\nlemma image_Union (F : \u03b9 \u2192 set X) (f : X \u2192 Y) :\n  f '' (\u22c3 (i : \u03b9), F i) = \u22c3 (i : \u03b9), f '' (F i) :=\nbegin\n  sorry\nend\n\n/-!\n\n## bUnion\n\nEn ocasiones, dados `\u03b9 : Type` y `F : \u03b9 \u2192 set X`, no queremos tomar\nla uni\u00f3n sobre todos los t\u00e9rminos de `\u03b9`, sino s\u00f3lo sobre\naqu\u00e9llos que pertenezcan a un subconjunto `Z : set \u03b9`.\nPara ello podemos utilizar la notaci\u00f3n `\u22c3 (i \u2208 Z), F i`.\n\nLos lemas para este tipo de uniones tienen `bUnion` en el nombre.\nPor ejemplo:\n`mem_bUnion_iff : (x \u2208 \u22c3 (i \u2208 J), F i) \u2194 \u2203 (j \u2208 J), x \u2208 F j`\n\n-/\n\nlemma preimage_bUnion (F : \u03b9 \u2192 set Y) (Z : set \u03b9) :\n  f \u207b\u00b9' (\u22c3 (i \u2208 Z), F i) = \u22c3 (i \u2208 Z), f \u207b\u00b9' (F i) :=\nbegin\n  sorry\nend", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_5/conjuntos_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511359371249, "lm_q2_score": 0.8705972566572504, "lm_q1q2_score": 0.7451016510538524}}
{"text": "/-\nCopyright (c) 2021 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying, Eric Wieser\n\n! This file was ported from Lean 3 source module data.real.sign\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Real.Basic\n\n/-!\n# Real sign function\n\nThis file introduces and contains some results about `Real.sign` which maps negative\nreal numbers to -1, positive real numbers to 1, and 0 to 0.\n\n## Main definitions\n\n * `Real.sign r` is $\\begin{cases} -1 & \\text{if } r < 0, \\\\\n                               ~~\\, 0 & \\text{if } r = 0, \\\\\n                               ~~\\, 1 & \\text{if } r > 0. \\end{cases}$\n\n## Tags\n\nsign function\n-/\n\n\nnamespace Real\n\n/-- The sign function that maps negative real numbers to -1, positive numbers to 1, and 0\notherwise. -/\nnoncomputable def sign (r : \u211d) : \u211d :=\n  if r < 0 then -1 else if 0 < r then 1 else 0\n#align real.sign Real.sign\n\ntheorem sign_of_neg {r : \u211d} (hr : r < 0) : sign r = -1 := by rw [sign, if_pos hr]\n#align real.sign_of_neg Real.sign_of_neg\n\ntheorem sign_of_pos {r : \u211d} (hr : 0 < r) : sign r = 1 := by rw [sign, if_pos hr, if_neg hr.not_lt]\n#align real.sign_of_pos Real.sign_of_pos\n\n@[simp]\ntheorem sign_zero : sign 0 = 0 := by rw [sign, if_neg (lt_irrefl _), if_neg (lt_irrefl _)]\n#align real.sign_zero Real.sign_zero\n\n@[simp]\ntheorem sign_one : sign 1 = 1 :=\n  sign_of_pos <| by norm_num\n#align real.sign_one Real.sign_one\n\ntheorem sign_apply_eq (r : \u211d) : sign r = -1 \u2228 sign r = 0 \u2228 sign r = 1 := by\n  obtain hn | rfl | hp := lt_trichotomy r (0 : \u211d)\n  \u00b7 exact Or.inl <| sign_of_neg hn\n  \u00b7 exact Or.inr <| Or.inl <| sign_zero\n  \u00b7 exact Or.inr <| Or.inr <| sign_of_pos hp\n#align real.sign_apply_eq Real.sign_apply_eq\n\n/-- This lemma is useful for working with `\u211d\u02e3` -/\ntheorem sign_apply_eq_of_ne_zero (r : \u211d) (h : r \u2260 0) : sign r = -1 \u2228 sign r = 1 :=\n  h.lt_or_lt.imp sign_of_neg sign_of_pos\n#align real.sign_apply_eq_of_ne_zero Real.sign_apply_eq_of_ne_zero\n\n@[simp]\ntheorem sign_eq_zero_iff {r : \u211d} : sign r = 0 \u2194 r = 0 := by\n  refine' \u27e8fun h => _, fun h => h.symm \u25b8 sign_zero\u27e9\n  obtain hn | rfl | hp := lt_trichotomy r (0 : \u211d)\n  \u00b7 rw [sign_of_neg hn, neg_eq_zero] at h\n    exact (one_ne_zero h).elim\n  \u00b7 rfl\n  \u00b7 rw [sign_of_pos hp] at h\n    exact (one_ne_zero h).elim\n#align real.sign_eq_zero_iff Real.sign_eq_zero_iff\n\ntheorem sign_int_cast (z : \u2124) : sign (z : \u211d) = \u2191(Int.sign z) := by\n  obtain hn | rfl | hp := lt_trichotomy z (0 : \u2124)\n  \u00b7 rw [sign_of_neg (Int.cast_lt_zero.mpr hn), Int.sign_eq_neg_one_of_neg hn, Int.cast_neg,\n      Int.cast_one]\n  \u00b7 rw [Int.cast_zero, sign_zero, Int.sign_zero, Int.cast_zero]\n  \u00b7 rw [sign_of_pos (Int.cast_pos.mpr hp), Int.sign_eq_one_of_pos hp, Int.cast_one]\n#align real.sign_int_cast Real.sign_int_cast\n\ntheorem sign_neg {r : \u211d} : sign (-r) = -sign r := by\n  obtain hn | rfl | hp := lt_trichotomy r (0 : \u211d)\n  \u00b7 rw [sign_of_neg hn, sign_of_pos (neg_pos.mpr hn), neg_neg]\n  \u00b7 rw [sign_zero, neg_zero, sign_zero]\n  \u00b7 rw [sign_of_pos hp, sign_of_neg (neg_lt_zero.mpr hp)]\n#align real.sign_neg Real.sign_neg\n\ntheorem sign_mul_nonneg (r : \u211d) : 0 \u2264 sign r * r := by\n  obtain hn | rfl | hp := lt_trichotomy r (0 : \u211d)\n  \u00b7 rw [sign_of_neg hn]\n    exact mul_nonneg_of_nonpos_of_nonpos (by norm_num) hn.le\n  \u00b7 rw [mul_zero]\n  \u00b7 rw [sign_of_pos hp, one_mul]\n    exact hp.le\n#align real.sign_mul_nonneg Real.sign_mul_nonneg\n\ntheorem sign_mul_pos_of_ne_zero (r : \u211d) (hr : r \u2260 0) : 0 < sign r * r := by\n  refine' lt_of_le_of_ne (sign_mul_nonneg r) fun h => hr _\n  have hs0 := (zero_eq_mul.mp h).resolve_right hr\n  exact sign_eq_zero_iff.mp hs0\n#align real.sign_mul_pos_of_ne_zero Real.sign_mul_pos_of_ne_zero\n\n@[simp]\ntheorem inv_sign (r : \u211d) : (sign r)\u207b\u00b9 = sign r := by\n  obtain hn | hz | hp := sign_apply_eq r\n  \u00b7 rw [hn]\n    norm_num\n  \u00b7 rw [hz]\n    exact inv_zero\n  \u00b7 rw [hp]\n    exact inv_one\n#align real.inv_sign Real.inv_sign\n\n@[simp]\ntheorem sign_inv (r : \u211d) : sign r\u207b\u00b9 = sign r := by\n  obtain hn | rfl | hp := lt_trichotomy r (0 : \u211d)\n  \u00b7 rw [sign_of_neg hn, sign_of_neg (inv_lt_zero.mpr hn)]\n  \u00b7 rw [sign_zero, inv_zero, sign_zero]\n  \u00b7 rw [sign_of_pos hp, sign_of_pos (inv_pos.mpr hp)]\n#align real.sign_inv Real.sign_inv\n\nend Real\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Real/Sign.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7450934521501544}}
{"text": "import group.definitions -- definition of a group and a comm_group\n\n/-\nclass group (G : Type) extends has_group_notation G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\nand `comm_group G` has the extra axiom\n\n`mul_comm : \u2200 (x y : G), x * y = y * x`\n\nYou access these axioms with `group.mul_assoc`, `group.one_mul` etc.\n-/\n\n-- This entire project takes place in the mygroup namespace\nnamespace mygroup\n\n/- Our goal is to prove the following theorems (in the order\n  listed) :\n\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n`eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9`\n`mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1`\n`eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9`\n`inv_inv (a : G) : a \u207b\u00b9 \u207b\u00b9 = a`\n`inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b`\n\nand possibly more to come if we run into stuff we need.\n\nWe start with only `mul_assoc`, `one_mul` and `mul_left_inv`. \n\nmul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c)\none_mul : \u2200 (a : G), 1 * a = a\nmul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1\n\n-/\nnamespace group\n\nvariables {G : Type} [group G]  \n\nlemma mul_left_cancel (a x y : G) (Habac : a * x = a * y) : x = y := \nbegin\n  sorry\nend\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  sorry\nend\n\ntheorem mul_one (a : G) : a * 1 = a :=\nbegin\n  sorry\nend\n\ntheorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1 :=\nbegin\n  sorry\nend\n\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nbegin\n  sorry\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1 :=\nbegin\n  sorry\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9 :=\nbegin\n  sorry\nend\n\nlemma inv_inv (a : G) : a \u207b\u00b9 \u207b\u00b9 = a :=\nbegin\n  sorry\nend\n\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b :=\nbegin\n  sorry\nend\n\nend group\n\nend mygroup", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/levels/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7450934503235681}}
{"text": "/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nModule init.relation\nAuthors: Leonardo de Moura\n-/\nprelude\nimport init.logic\n\n-- TODO(Leo): remove duplication between this file and algebra/relation.lean\n-- We need some of the following definitions asap when \"initializing\" Lean.\n\nvariables {A B : Type} (R : B \u2192 B \u2192 Prop)\nlocal infix `\u227a`:50 := R\n\ndefinition reflexive := \u2200x, x \u227a x\n\ndefinition symmetric := \u2200\u2983x y\u2984, x \u227a y \u2192 y \u227a x\n\ndefinition transitive := \u2200\u2983x y z\u2984, x \u227a y \u2192 y \u227a z \u2192 x \u227a z\n\ndefinition equivalence := reflexive R \u2227 symmetric R \u2227 transitive R\n\ndefinition total := \u2200 x y, x \u227a y \u2228 y \u227a x\n\ndefinition mk_equivalence (r : reflexive R) (s : symmetric R) (t : transitive R) : equivalence R :=\nand.intro r (and.intro s t)\n\ndefinition irreflexive := \u2200x, \u00ac x \u227a x\n\ndefinition anti_symmetric := \u2200\u2983x y\u2984, x \u227a y \u2192 y \u227a x \u2192 x = y\n\ndefinition empty_relation := \u03bba\u2081 a\u2082 : A, false\n\ndefinition subrelation (Q R : B \u2192 B \u2192 Prop) := \u2200\u2983x y\u2984, Q x y \u2192 R x y\n\ndefinition inv_image (f : A \u2192 B) : A \u2192 A \u2192 Prop :=\n\u03bba\u2081 a\u2082, f a\u2081 \u227a f a\u2082\n\ntheorem inv_image.trans (f : A \u2192 B) (H : transitive R) : transitive (inv_image R f) :=\n\u03bb (a\u2081 a\u2082 a\u2083 : A) (H\u2081 : inv_image R f a\u2081 a\u2082) (H\u2082 : inv_image R f a\u2082 a\u2083), H H\u2081 H\u2082\n\ntheorem inv_image.irreflexive (f : A \u2192 B) (H : irreflexive R) : irreflexive (inv_image R f) :=\n\u03bb (a : A) (H\u2081 : inv_image R f a a), H (f a) H\u2081\n\ninductive tc {A : Type} (R : A \u2192 A \u2192 Prop) : A \u2192 A \u2192 Prop :=\n| base  : \u2200a b, R a b \u2192 tc R a b\n| trans : \u2200a b c, tc R a b \u2192 tc R b c \u2192 tc R a c\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/init/relation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7450934496485916}}
{"text": "import tactic.ring\nimport data.real.basic\nimport algebra.parity\n\nexample (x y : \u2115) : x + y = y + x := by ring\nexample (x y : \u2115) : x + y + y = 2 * y + x := by ring\nexample (x y : \u2115) : x + id y = y + id x := by ring!\nexample {\u03b1} [comm_ring \u03b1] (x y : \u03b1) : x + y + y - x = 2 * y := by ring\nexample (x y : \u211a) : x / 2 + x / 2 = x := by ring\nexample (x y : \u211a) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring\nexample (x y : \u211d) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring\nexample {\u03b1} [comm_semiring \u03b1] (x : \u03b1) : (x + 1) ^ 6 = (1 + x) ^ 6 := by try_for 15000 {ring}\nexample (n : \u2115) : (n / 2) + (n / 2) = 2 * (n / 2) := by ring\nexample {\u03b1} [field \u03b1] [char_zero \u03b1] (a : \u03b1) : a / 2 = a / 2 := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  a * (-c / b) * (-c / b) + -c + c = a * (c / b * (c / b)) := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring\nexample (x : \u211a) : x ^ (2 + 2) = x^4 := by ring_nf -- TODO: ring should work?\nexample {\u03b1} [comm_ring \u03b1] (x : \u03b1) : x ^ 2 = x * x := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  b ^ 2 - 4 * a * c = 4 * a * 0 + b * b - 4 * a * c := by ring\nexample {\u03b1} [comm_semiring \u03b1] (x y z : \u03b1) (n : \u2115) :\n  (x + y) * (z * (y * y) + (x * x ^ n + (1 + \u2191n) * x ^ n * y)) =\n    x * (x * x ^ n) + ((2 + \u2191n) * (x * x ^ n) * y + (x * z + (z * y + (1 + \u2191n) * x ^ n)) * (y * y)) := by ring\nexample {\u03b1} [comm_ring \u03b1] (a b c d e : \u03b1) :\n  (-(a * b) + c + d) * e = (c + (d + -a * b)) * e := by ring\nexample (a n s: \u2115) : a * (n - s) = (n - s) * a := by ring\n\nexample (x y z : \u211a) (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  x / (y / z) + y \u207b\u00b9 + 1 / (y * -x) = -1/ (x * y) + (x * z + 1) / y :=\nbegin\n  field_simp,\n  ring\nend\n\nexample {A : \u2124} (f : \u2124 \u2192 \u2124) : f 0 = f (A - A) := by ring_nf\nexample {A : \u2124} (f : \u2124 \u2192 \u2124) : f 0 = f (A + -A) := by ring_nf\n\nexample {a b c : \u211d} (h : 0 < a ^ 4 + b ^ 4 + c ^ 4) :\n  a ^ 4 / (a ^ 4 + b ^ 4 + c ^ 4) +\n  b ^ 4 / (b ^ 4 + c ^ 4 + a ^ 4) +\n  c ^ 4 / (c ^ 4 + a ^ 4 + b ^ 4)\n  = 1 :=\nbegin\n  ring_nf at \u22a2 h,\n  field_simp [h.ne'],\nend\n\nexample (a b c d x y : \u211a) (hx : x \u2260 0) (hy : y \u2260 0) :\n  a + b / x - c / x^2 + d / x^3 = a + x\u207b\u00b9 * (y * b / y + (d / x - c) / x) :=\nbegin\n  field_simp,\n  ring\nend\n\nexample : (876544 : \u2124) * -1 + (1000000 - 123456) = 0 := by ring\n\nexample (x y : \u211d) (hx : x \u2260 0) (hy : y \u2260 0) :\n  2 * x ^ 3 * 2 / (24 * x) = x ^ 2 / 6 :=\nbegin\n  field_simp,\n  ring\nend\n\n-- this proof style is not recommended practice\nexample (A B : \u2115) (H : B * A = 2) : A * B = 2 := by {ring_nf, exact H}\n\nexample (a : \u2124) : odd ((2 * a + 1) ^ 2) :=\nbegin\n  use 2 * a ^ 2 + 2 * a,\n  ring_nf,\nend\n\nexample {x y : \u211d}\n  (hxy : -y ^ 2 + x ^ 2 = -(5 * y) + 5 * x) :\n  x ^ 2 - y ^ 2 = 5 * x - 5 * y :=\nbegin\n  ring_nf at hxy \u22a2,\n  exact hxy\nend\n\nexample {\u03b1} [field \u03b1] {x y : \u03b1}\n  (h : 0 = (1 - x) ^ 2 * (x * (2 ^ 2 * y ^ 2 + 4 * (1 - x) ^ 2))) :\n  0 = x * ((2 ^ 2 * y ^ 2 + 4 * (1 - x) ^ 2) * (1 - x) ^ 2) :=\nby transitivity; [exact h, ring]\n\n-- `ring_nf` should descend into the subexpressions `x * -a` and `-a * x`:\nexample {a x : \u211a} : x * -a = - a * x := by ring_nf\n\nexample (f : \u2124 \u2192 \u2124) (a b : \u2124) : f (2 * a + b) + b = b + f (b + a + a) :=\nbegin\n  success_if_fail {{ ring_nf {recursive := ff} }},\n  ring_nf\nend\n\n-- instances do not have to syntactically be `monoid.has_pow`\nexample {R} [comm_semiring R] (x : \u2115 \u2192 R) : x ^ 2 = x * x := by ring\n\n-- even if there's an instance we don't recognize, we treat it as an atom\nexample {R} [field R] (x : \u2115 \u2192 R) :\n  (x ^ (2 : \u2124)) ^ 2 = (x ^ (2 : \u2124)) * (x ^ (2 : \u2124)) := by ring\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/test/ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7450934407140016}}
{"text": "theorem le_of_succ_le_succ (a b : mynat) : succ a \u2264 succ b \u2192 a \u2264 b :=\nbegin\nintro h,\ncases h with c hc,\nuse c,\nrw succ_add at hc,\nrw succ_eq_succ_iff at hc,\nexact hc,\nend\n", "meta": {"author": "chanha-park", "repo": "naturalNumberGame", "sha": "4e0d7100ce4575e1add92feefa38b1250431b879", "save_path": "github-repos/lean/chanha-park-naturalNumberGame", "path": "github-repos/lean/chanha-park-naturalNumberGame/naturalNumberGame-4e0d7100ce4575e1add92feefa38b1250431b879/Inequality/12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.7450521394515598}}
{"text": "import positive_nat.def\nimport data.nat.basic\nimport tactic.interactive\nimport tactic.rcases\nimport tactic.tidy\nimport tactic.wlog\nimport lib.tactics\n\nuniverses u v\n\nnamespace positive_nat\nnamespace natural\n\nlemma add_succ {a b : natural} : a + (b + 1) = (a + b) + 1 := rfl\n\nlemma one_add_eq_succ {a : natural} : 1 + a = a + 1 :=\nbegin\n  induction a with b ih,\n  { refl },\n  { rw add_succ, rw ih }\nend\n\nlemma mul_succ {a b : natural} : a * (b + 1) = a + a * b := rfl\n\nlemma succ_add {a b : natural} : (a + 1) + b = (a + b) + 1 :=\nbegin\n  induction b with b ih,\n  { refl },\n  { rw add_succ,\n    rw ih,\n    rw add_succ }\nend\n\nlemma add_comm {a b : natural} : a + b = b + a :=\nbegin\n  induction b with b ih,\n  { rw one_add_eq_succ },\n  { rw add_succ,\n    rw ih,\n    rw succ_add }\nend\n\ninstance add.commutative : is_commutative natural add := \u27e8@add_comm\u27e9\n\n@[simp]\nlemma one_mul {a : natural} : 1 * a = a :=\nbegin\n  induction a with b ih,\n  { refl },\n  { rw mul_succ, rw ih, exact add_comm }\nend\n\n@[simp]\nlemma mul_one {a : natural} : a * 1 = a := rfl\n\nlemma add_assoc {a b c : natural} : a + b + c = a + (b + c) :=\nbegin\n  induction c with c ih,\n  { rw add_comm,\n    rw add_succ,\n    rw add_comm },\n  { rw add_succ,\n    rw ih,\n    rw add_succ,\n    rw add_succ }\nend\n\ninstance add.associative : is_associative natural add := \u27e8@add_assoc\u27e9\n\nlemma succ_mul {a b : natural} : (a + 1) * b = b + (a * b) :=\nbegin\n  induction b with b ih,\n  { rw mul_one,\n    rw mul_one,\n    rw add_comm },\n  { rw mul_succ,\n    rw ih,\n    rw mul_succ,\n    rw \u2190add_assoc,\n    rw \u2190add_assoc,\n    rw @add_comm a,\n    rw @add_comm b,\n    rw @add_assoc 1,\n    rw @add_comm a,\n    rw \u2190@add_assoc 1\n    }\nend\n\nlemma mul_comm {a b : natural} : a * b = b * a :=\nbegin\n  induction b with b ih,\n  { rw one_mul, refl },\n  { rw mul_succ, rw ih, rw succ_mul }\nend\n\ninstance mul.commutative : is_commutative natural mul := \u27e8@mul_comm\u27e9\n\nlemma mul_add_dist {a b c: natural} : a * (b + c) = a * b + a * c :=\nbegin\n  induction c with c ih,\n  { rw mul_succ,\n    rw mul_one,\n    rw add_comm },\n  { rw add_succ,\n    rw mul_succ,\n    rw ih,\n    rw mul_succ,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw @add_comm a }\nend\n\nlemma mul_assoc {a b c : natural} : a * b * c = a * (b * c) :=\nbegin\n  induction c with c ih,\n  { rw mul_one, rw mul_one },\n  { rw mul_succ,\n    rw ih,\n    rw mul_succ,\n    rw mul_add_dist }\nend\n\ninstance mul.associative : is_associative natural mul := \u27e8@mul_assoc\u27e9\n\ndef one_ne_succ {a b : natural} : \u00ac(1 = a + b) :=\nbegin\n  apply b.cases_on,\n  { delta natural, apply type.no_confusion },\n  { intro b, rw add_succ, delta natural at *, apply type.no_confusion }\nend\n\nlemma succ_ne_one {a : natural} : \u00ac(a + 1 = 1) := ne.symm one_ne_succ\n\nlemma succ_inj {a b : natural} : a + 1 = b + 1 \u2192 a = b := begin\n  delta natural at *,\n  exact type.succ.inj\nend\n\nlemma succ_inj_eq {a b : natural} : (a + 1 = b + 1) = (a = b) :=\nbegin\n  delta natural,\n  apply type.succ.inj_eq\nend\n\nlemma add_ne_self {a b : natural} (h : a + b = a) : false :=\nbegin\n  induction a with a ih,\n  { revert h,\n    rw add_comm,\n    exact succ_ne_one },\n  { rw succ_add at h,\n    replace h := succ_inj h,\n    exact ih h }\nend\n\nlemma eq_one_of_mul_eq {a b : natural} (h : a * b = b) : a = 1 :=\nbegin\n  cases_on a,\n  { refl },\n  { rw [succ_mul] at h,\n    exfalso,\n    exact add_ne_self h }\nend\n\nlemma add_inj_left {a b c : natural} (h : a + b = a + c) : b = c :=\nbegin\n  induction a with a ih,\n  { repeat {rw one_add_eq_succ at h},\n    exact succ_inj h },\n  { repeat {rw succ_add at h},\n    exact ih (succ_inj h) }\nend\n\nlemma add_inj_right {a b c : natural} (h : a + c = b + c) : a = b := begin\n  rw @add_comm a at h,\n  rw @add_comm b at h,\n  exact add_inj_left h\nend\n\nlemma mul_inj {a b c : natural} (h : a * c = b * c) : a = b :=\nbegin\n  revert a,\n  induction b with b ih,\n  { intros a h,\n    rw one_mul at h,\n    exact eq_one_of_mul_eq h },\n  { intros a h,\n    rw succ_mul at h,\n    cases_on a,\n    { rw [one_mul] at h,\n      replace h := eq.symm h,\n      exfalso,\n      exact add_ne_self h },\n    { rw [succ_mul] at h,\n      replace h := add_inj_left h,\n      congr,\n      exact ih h } }\nend\n\nlemma lt_of_succ_lt_succ {a b : natural} (h : a + 1 < b + 1) : a < b :=\nbegin\n  cases h with c h,\n  use c,\n  rw [add_assoc, @add_comm 1, \u2190add_assoc] at h,\n  exact add_inj_right h\nend\n\ninstance decidable_lt : \u03a0 {a b : natural}, decidable (a < b)\n| 1 1 := is_false (by { rintro \u27e8\u27e9, apply add_ne_self, assumption })\n| 1 (a + 1) := is_true (by { split, rw @one_add_eq_succ a })\n| (a + 1) 1 := is_false (by { rintro \u27e8\u27e9, rw succ_add at *, apply succ_ne_one, assumption })\n| (a + 1) (b + 1) := match @decidable_lt a b with\n  | is_false h := is_false (by { intro hh, exact h (lt_of_succ_lt_succ hh) })\n  | is_true h := is_true (by { cases h with c h, use c, rw succ_add, rw h })\nend\n\nlemma add_ne_one {a b : natural} (h : a + b = 1) : false :=\nbegin\n  cases_on b,\n  { rw add_comm at h, exact add_ne_self h },\n  { rw [add_succ] at h, exact succ_ne_one h }\nend\n\n@[simp]\nlemma succ_pred_eq_self {a : natural} {h} : (pred a) + 1 = a :=\nbegin\n  cases_on a,\n  { cases h,\n    exfalso,\n    apply add_ne_self,\n    assumption },\n  { refl }\nend\n\nlemma one_lt_succ {a : natural} : 1 < a + 1 :=\nbegin\n  split,\n  rw one_add_eq_succ\nend\n\nlemma one_lt_of_succ_lt {a b : natural} (h : a + 1 < b) : 1 < b :=\nbegin\n  cases_on b,\n  { exfalso,\n    cases h with c h,\n    rw [@add_comm a, add_assoc] at h,\n    exact add_ne_self h },\n  { exact one_lt_succ }\nend\n\n@[simp]\nlemma pred_succ {a : natural} {h : 1 < a + 1} : pred (a + 1) h = a := rfl\n\nset_option trace.check true\n\nlemma eq_pred_of_succ_eq {n m : natural} (h : n + 1 = m) : n = pred m (by { use n, rwa add_comm }):=\nbegin\n  cases_on m,\n  { cases h },\n  { revert h,\n    intro h,\n    rw pred_succ,\n    exact add_inj_right h }\nend\n\nlemma lt_pred_of_succ_lt {a b : natural} (h : a + 1 < b) : a < pred b (one_lt_of_succ_lt h) :=\nbegin\n  cases h with c h,\n  use c,\n  rw [succ_add] at h,\n  apply eq_pred_of_succ_eq,\n  assumption\nend\n\nlemma lt_of_succ_lt {a b : natural} (h : a + 1 < b) : a < b :=\nbegin\n  cases h with c h,\n  use c + 1,\n  rw succ_add at h,\n  rw add_succ,\n  assumption\nend\n\nlemma sub_succ_eq_pred_sub {a b : natural} {h : b + 1 < a}: sub a (b + 1) h = sub (pred a (one_lt_of_succ_lt h)) b (lt_pred_of_succ_lt h) :=\nbegin\n  unfold sub sub.total pred\nend\n\nlemma eq_sub_of_add_eq {a b c : natural} (h : a + b = c) : a = sub c b \u27e8a, by {rw add_comm, assumption}\u27e9 :=\nbegin\n  revert c,\n  induction b with b ih,\n  { intros c h,\n    unfold sub sub.total,\n    subst c,\n    unfold pred.total },\n  { intros c h,\n    rw sub_succ_eq_pred_sub,\n    have hh := h,\n    rw add_succ at hh,\n    exact ih (eq_pred_of_succ_eq hh) }\nend\n\nlemma sub_succ.pred {a b : natural} (h : b + 1 < a) : sub a b (lt_of_succ_lt h) > 1 :=\nbegin\n  cases h with c h,\n  split, swap, exact c,\n  rw [add_assoc, add_comm] at h,\n  apply eq_sub_of_add_eq,\n  assumption\nend\n\nlemma sub_succ {a b : natural} {h : b + 1 < a} : sub a (b + 1) = pred (sub a b (lt_of_succ_lt h)) (sub_succ.pred h) :=\nbegin\n  revert a,\n  induction b with b ih,\n  { intros a h, unfold sub sub.total, refl },\n  { intros a h,\n    rw sub_succ_eq_pred_sub,\n    revert h,\n    intro h,\n    rw @ih _ (lt_pred_of_succ_lt h),\n    congr }\nend\n\n@[simp]\nlemma sub_add_eq {a b : natural} {h} : a.sub b + b = a :=\nbegin\n  induction b with b ih,\n  { cases_on a,\n    { exfalso, cases h, apply add_ne_self, assumption },\n    { unfold sub sub.total, refl } },\n  { rw add_succ,\n    rw sub_succ,\n    rw \u2190 succ_add,\n    rw succ_pred_eq_self,\n    apply ih }\nend\n\nlemma sub_lt_of_lt {a b : natural} (h : a < b) : sub b a < b :=\nbegin\n  cases h with c h,\n  split,\n  exact sub_add_eq\nend\n\nlemma one_lt_add {a b : natural} : 1 < a + b :=\nbegin\n  cases_on b; unfold has_add.add add; exact one_lt_succ\nend\n\nlemma add_eq_succ {a b : natural} : a + b = (pred (a + b) one_lt_add) + 1 :=\nbegin\n  rw succ_pred_eq_self\nend\n\nlemma not_lt_one {a : natural} (h : a < 1) : false :=\nbegin\n  cases h with c h,\n  rw add_eq_succ at h,\n  exact succ_ne_one h\nend\n\nlemma not_lt_of_eq {a : natural} : \u00ac a < a :=\nbegin\n  intro h,\n  cases h with x h,\n  apply add_ne_self h\nend\n\nlemma not_lt_and_lt_symm {a b : natural} : \u00ac (a < b \u2227 b < a) :=\nbegin\n  intro h,\n  cases h with hl hr,\n  cases hl with x hx,\n  cases hr with y hy,\n  rw [\u2190hy, add_assoc] at hx,\n  exact add_ne_self hx\nend\n\nlemma le_of_lt_succ {a b : natural} (h : a < b + 1) : a \u2264 b :=\nbegin\n  cases h with c h,\n  cases_on c,\n  { left, exact add_inj_right h },\n  { right,\n    use m,\n    rw \u2190add_assoc at h,\n    exact add_inj_right h }\nend\n\ninstance decidable_eq : decidable_eq natural\n| 1 1 := decidable.is_true rfl\n| (n + 1) (m + 1) := match decidable_eq n m with\n  | decidable.is_true h := decidable.is_true (congr_arg (\u03bb x, add x 1) h)\n  | decidable.is_false h := decidable.is_false (h \u2218 add_inj_right)\nend\n| 1 (m + 1) := decidable.is_false (succ_ne_one \u2218 eq.symm)\n| (n + 1) 1 := decidable.is_false succ_ne_one\n\n@[elab_as_eliminator]\nlemma strong_induction {p : natural \u2192 Sort u} (n : natural) (h : \u2200 n, (\u2200 m, m < n \u2192 p m) \u2192 p n) : p n :=\nbegin\n  suffices hh : \u2200 n m, m < n \u2192 p m, { apply h, apply hh },\n  intros n, induction n with n ih,\n  { intros m hh, exfalso, apply not_lt_one, exact hh },\n  { intros m hh,\n    apply or.by_cases (le_of_lt_succ hh),\n    { intros, subst m, apply h, apply ih },\n    { intros, apply ih, assumption } }\nend\n\nlemma le_self {a : natural} : a \u2264 a := or.inl rfl\n\n@[simp]\nlemma one_le {a : natural} : 1 \u2264 a :=\nbegin\n  cases_on a,\n  { left, refl },\n  { right, use m, rw add_comm }\nend\n\nlemma le_or_gt (a b : natural) : a \u2264 b \u2228 a > b :=\nif h\u2081 : b < a then or.inr h\u2081 else\nif h\u2082 : a = b then or.inl (or.inl h\u2082) else\nif h\u2083 : a < b then or.inl (or.inr h\u2083) else begin\n  exfalso,\n  induction a with a ih,\n  { cases_on b, exact h\u2082 rfl, exact h\u2083 one_lt_succ },\n  { apply ih; intro h,\n    { apply h\u2081, cases h with c h, use c + 1, rw \u2190add_assoc, congr, assumption },\n    { subst a, apply h\u2081, constructor, refl },\n    { cases h with c h, subst b, cases_on c,\n      { apply h\u2082, refl },\n      { apply h\u2083, constructor,\n        rw @add_comm m,\n        rw add_assoc } } }\nend\n\nlemma cases_le_or_gt {p : Prop} (a b : natural) (h\u2081 : a \u2264 b \u2192 p) (h\u2082 : a > b \u2192 p) : p :=\nbegin\n  have h := le_or_gt a b,\n  cases h; cc\nend\n\ninstance decidable_le {a b : natural} : decidable (a \u2264 b) :=\nif h\u2081 : a < b then decidable.is_true (or.inr h\u2081) else\nif h\u2082 : a = b then decidable.is_true (or.inl h\u2082) else\ndecidable.is_false begin\n  intro h, cases h, exact h\u2082 h, exact h\u2081 h\nend\n\nlemma succ_sub_succ {a b : natural} {h} : sub (a + 1) (b + 1) = sub a b (lt_of_succ_lt_succ h) :=\nbegin\n  unfold sub,\n  rw sub.total.equations._eqn_2,\n  rw pred.total.equations._eqn_2\nend\n\n@[simp]\nlemma add_sub_eq {a b : natural} {h} : sub (a + b) b h = a :=\nbegin\n  induction b with b ih,\n  { refl },\n  { conv in (a + (b + 1)) { rw \u2190 add_assoc },\n    rwa succ_sub_succ, exact ih }\nend\n\ninstance eq.decidable : \u03a0 {a b : natural}, decidable (a = b)\n| 1 1 := is_true rfl\n| 1 (_ + 1) := is_false (by { intro h, exact succ_ne_one (eq.symm h)})\n| (_ + 1) 1 := is_false (by { intro h, exact succ_ne_one h})\n| (a + 1) (b + 1) := match @eq.decidable a b with\n  | is_true h := by { rw \u2190 succ_inj_eq at h, exact is_true h }\n  | is_false h := by { apply is_false, intro hh, exact h (succ_inj hh) }\nend\n\nlemma lt_of_add_lt_add {a b c : natural} (h : a + b < a + c) : b < c :=\nbegin\n  induction a with a ih,\n  { repeat { rw one_add_eq_succ at h },\n    exact lt_of_succ_lt_succ h },\n  { repeat { rw succ_add at h },\n    exact ih (lt_of_succ_lt_succ h) }\nend\n\nlemma le_or_le_symm {x y : natural} : x \u2264 y \u2228 y \u2264 x :=\nbegin\n  have hh := le_or_gt x y, cases hh,\n    { left, assumption },\n    { right, exact or.inr hh }\nend\n\nlemma sub_lt_self {a b : natural} {h} : sub a b < a :=\nbegin\n  constructor,\n  exact sub_add_eq\nend\n\nlemma le_irrefl {a : natural} (h : a < a) : false :=\nbegin\n  cases h,\n  apply add_ne_self,\n  assumption\nend\n\nlemma sub_dvd_of_dvd {a b: natural} (h : b \u2223 a) {hle} : b \u2223 sub a b :=\nbegin\n  cases h with x h,\n  cases_on x,\n  { rw mul_one at h, subst a, exfalso, exact le_irrefl hle },\n  { rw mul_succ at h,\n    subst a,\n    conv in (b + _) { rw add_comm },\n    rw add_sub_eq,\n    use m }\nend\n\nlemma dvd.rfl {a : natural} : a \u2223 a :=\nbegin\n  unfold has_dvd.dvd dvd, use 1, simp\nend\n\nlemma le_of_succ_le_succ {a b :natural} (h : a + 1 \u2264 b + 1) : a \u2264 b :=\nbegin\n  cases h,\n  { left, exact add_inj_right h },\n  { right, cases h with x h, use x,\n    rw [add_assoc, @add_comm 1, \u2190 add_assoc] at h,\n    exact add_inj_right h }\nend\n\nlemma ne_succ {a : natural} : a \u2260 a + 1 :=\nbegin\n  induction a with a ih,\n  { intro h, cases h },\n  { intro h, exact ih (add_inj_right h) }\nend\n\nlemma ne_add {a b : natural} : a \u2260 a + b :=\nbegin\n  induction a with a ih,\n  { intro h, rw add_comm at h, exact one_ne_succ h },\n  { intro h, rw [add_assoc, @add_comm 1, \u2190 add_assoc] at h,\n    exact ih (add_inj_right h) }\nend\n\nlemma le_trans {a b c : natural} (h : a \u2264 b) (g : b \u2264 c): a \u2264 c :=\nbegin\n    cases h,\n    subst a, assumption,\n    cases g,\n    subst b, exact or.inr h,\n    cases h with x, cases g with y,\n    right, use x + y,\n    subst b, subst c,\n    rw \u2190 add_assoc\nend\n\nlemma le_total {a b : natural} : a \u2264 b \u2228 b \u2264 a := begin\n    induction b with b ih,\n    { right, cases_on a,\n      left, refl,\n      right, apply one_lt_succ },\n    { cases_on a,\n      { left, right,\n        apply one_lt_succ },\n      { cases ih,\n        { left, right, cases ih,\n          { rw ih, use 1 },\n          { cases ih with x h,\n            use x + 1,\n            rw \u2190 add_assoc,\n            rw h } },\n        { cases ih,\n          { left, right, rw \u2190 ih, use 1 },\n          { right, cases ih with x h,\n            cases_on x,\n            { left, exact h },\n            { right, use m_1, rw \u2190 h,\n              rw @add_comm m_1,\n              rw \u2190 add_assoc,\n              } } } } }\nend\n\nlemma le_antisymm {a b : natural} (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 a) : a = b := begin\n    cases h\u2081, assumption,\n    cases h\u2082, symmetry, assumption,\n    cases h\u2081 with x h\u2081,\n    subst b,\n    cases h\u2082 with y h,\n    exfalso,\n    rw add_assoc at h,\n    exact ne_add h.symm\nend\n\nlemma ge_of_not_lt {a b : natural} (h : \u00ac(a < b)) : a \u2265 b :=\nbegin\n  cases le_or_gt a b with h\u2082 h\u2082, cases h\u2082,\n  { left, symmetry, assumption },\n  { exfalso, exact h h\u2082 },\n  { right, assumption }\nend\n\ninstance has_well_founded : has_well_founded natural :=\nbegin\n  use (<),\n  constructor, intro x,\n  induction x using positive_nat.natural.strong_induction with x ih,\n  constructor, intros y h,\n  apply ih, assumption\nend\n\nlemma not_add_lt {a b : natural} (h : a + b < a) : false :=\nbegin\n  induction b with b ih,\n  { cases h with _ h, rw add_assoc at h, exact add_ne_self h },\n  { rw add_succ at h,\n    apply ih,\n    exact lt_of_succ_lt h }\nend\n\nlemma not_mul_lt {a b : natural} (h : a * b < a) : false :=\nbegin\n  induction b with b ih,\n  { exact not_lt_of_eq h },\n  { rw mul_succ at h,\n    exact not_add_lt h }\nend\n\ndef sub_one {a : natural} {h\u2082} : sub a 1 h\u2082 = pred a :=\nbegin\n  unfold sub sub.total,\n  cases_on a,\n  { cases h\u2082 with x h, exfalso, rw add_comm at h, exact succ_ne_one h },\n  { unfold pred }\nend\n\nlemma succ_pred {a : natural} {h} : pred a + 1 = a :=\nbegin\n  cases_on a;\n  unfold pred pred.total,\n  exfalso,\n  exact not_lt_of_eq h\nend\n\nlemma eq_succ_of_pred_eq {a b : natural} {h\u2081} (h : pred a = b) : a = b + 1 :=\nbegin\n  cases_on a,\n  { exfalso, exact not_lt_of_eq h\u2081 },\n  { congr, rw pred_succ at h, assumption }\nend\n\nlemma succ_sub {a b} (h : a > b) {h\u2081} : sub (a + 1) b h\u2081 = sub a b h + 1 :=\nbegin\n  induction b with b ih,\n  { rw sub_one, rw sub_one, simp },\n  { rw sub_succ, rw sub_succ,\n    rw succ_pred,\n    symmetry,\n    apply eq_pred_of_succ_eq,\n    symmetry,\n    have h\u2082 : a > b, { cases h with x h, use x + 1, subst a, ac_refl },\n    exact ih h\u2082 }\nend\n\nlemma sub_step {a b : natural} {_} : sub (a + b) b = a :=\nbegin\n  generalize h : a + b = x,\n  conv in (a + b) { rw h },\n  exact (eq_sub_of_add_eq h).symm\nend\n\nlemma not_le_sub {a b : natural} {h\u2081} (h : a \u2264 sub a b h\u2081) : false :=\nbegin\n  cases sub_lt_of_lt h\u2081 with x h\u2082,\n  cases h,\n  { conv at h\u2082 { to_rhs, rw h },\n    exact add_ne_self h\u2082 },\n  { cases h with y h,\n    rw [\u2190 h, add_assoc] at h\u2082,\n    exact add_ne_self h\u2082 }\nend\n\nlemma lt_of_le_lt {a b c : natural} (h\u2081 : a \u2264 b) (h\u2082 : b < c) : a < c :=\nbegin\n  cases h\u2081,\n  { subst a, assumption },\n  { cases h\u2081 with x, cases h\u2082 with y,\n    subst c, subst b,\n    use x + y,\n    ac_refl }\nend\n\nend natural\nend positive_nat\n", "meta": {"author": "AtnNn", "repo": "lean-sandbox", "sha": "8c68afbdc09213173aef1be195da7a9a86060a97", "save_path": "github-repos/lean/AtnNn-lean-sandbox", "path": "github-repos/lean/AtnNn-lean-sandbox/lean-sandbox-8c68afbdc09213173aef1be195da7a9a86060a97/src/positive_nat/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7450158296642644}}
{"text": "variables A B C D : Prop\n\n-- A \u2227 (A \u2192 B) \u2192 B\nexample : A \u2227 (A \u2192 B) \u2192 B :=\n    assume h : A \u2227 (A \u2192 B),\n    show B, from and.right h (and.left h)\n\n-- A \u2192 \u00ac (\u00ac A \u2227 B)\nexample : A \u2192 \u00ac (\u00ac A \u2227 B) :=\n    assume h1 : A,\n    assume h2 : \u00ac A \u2227 B,\n    show false, from and.left h2 h1\n\n-- \u00ac (A \u2227 B) \u2192 (A \u2192 \u00ac B)\nexample (A B : Prop): \u00ac (A \u2227 B) \u2192 (A \u2192 \u00ac B) :=\nassume h1: \u00ac (A \u2227 B),\nassume h2: A,\nassume h3: B,\nshow false, from h1 (and.intro h2 h3)\n\nexample (h1 : A \u2228 B) (h2 : A \u2192 C) (h3 : B \u2192 D) : C \u2228 D :=\nshow C \u2228 D, from or.elim h1 (assume h4 : A, show C \u2228 D , from or.inl (h2 h4)) \n                (assume h5 : B, show C \u2228 D , from or.inr (h3 h5))\n    \n-- \u00ac A \u2227 \u00ac B \u2192  \u00ac (A \u2228 B)\nexample : \u00ac A \u2227 \u00ac B \u2192  \u00ac (A \u2228 B) :=\n  assume h1 : \u00ac A \u2227 \u00ac B,\n  assume h2: A \u2228 B,\n  show false, from or.elim h2 (and.left h1) (and.right h1)\n\n-- \u00ac (A \u2194 \u00ac A)\nvariable h1 : \u00ac A\nvariable h2 : A\nexample : \u00ac (A \u2194 \u00ac A) :=\nassume h: (A \u2194 \u00ac A),\nshow false, from (iff.elim_left h h2) (iff.elim_right h h1)\n", "meta": {"author": "m-slee", "repo": "lean-logic", "sha": "9809f35bbfe96e5f70fceaa594b055bfbd9e64e3", "save_path": "github-repos/lean/m-slee-lean-logic", "path": "github-repos/lean/m-slee-lean-logic/lean-logic-9809f35bbfe96e5f70fceaa594b055bfbd9e64e3/logic_examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632275178339, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7449876284478456}}
{"text": "/-\nCopyright (c) 2020 Gihan Marasingha. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gihan Marasingha\n-/\nimport .basic\nimport data.nat.modeq\nimport tactic.ring\n\n/-!\n# Decision procedure: necessary condition\n\nWe introduce a condition `decstr` and show that if a string `en` is `derivable`, then `decstr en`\nholds.\n\nUsing this, we give a negative answer to the question: is `\"MU\"` derivable?\n\n## Tags\n\nmiu, decision procedure\n-/\n\nnamespace miu\n\nopen miu_atom nat list\n\n/-!\n### Numerical condition on the `I` count\n\nSuppose `st : miustr`. Then `count I st` is the number of `I`s in `st`. We'll show, if\n`derivable st`, then `count I st` must be 1 or 2 modulo 3. To do this, it suffices to show that if\nthe `en : miustr` is derived from `st`, then `count I en` moudulo 3 is either equal to or is twice\n`count I st`, modulo 3.\n-/\n\n/--\nGiven `st en : miustr`, the relation `count_equiv_or_equiv_two_mul_mod3 st en` holds if `st` and\n`en` either have equal `count I`, modulo 3, or `count I en` is twice `count I st`, modulo 3.\n -/\ndef count_equiv_or_equiv_two_mul_mod3 (st en : miustr) : Prop :=\nlet a := (count I st) in\nlet b := (count I en) in\nb \u2261 a [MOD 3] \u2228 b \u2261 2*a [MOD 3]\n\nexample : count_equiv_or_equiv_two_mul_mod3 \"II\" \"MIUI\" :=\nor.inl rfl\n\nexample : count_equiv_or_equiv_two_mul_mod3 \"IUIM\" \"MI\" :=\nor.inr rfl\n\n/--\nIf `a` is 1 or 2 mod 3 and if `b` is `a` or twice `a` mod 3, then `b` is 1 or 2 mod 3.\n-/\nlemma mod3_eq_1_or_mod3_eq_2 {a b : \u2115} (h1 : a % 3 = 1 \u2228 a % 3 = 2)\n  (h2 : b % 3 = a % 3 \u2228  b % 3 = (2 * a % 3)) : b % 3 = 1 \u2228 b % 3 = 2 :=\nbegin\n  cases h2,\n  { rw h2, exact h1, },\n  { cases h1,\n    { right, simpa [h2,mul_mod,h1], },\n    { left, simpa [h2,mul_mod,h1], }, },\nend\n\n/--\n`count_equiv_one_or_two_mod3_of_derivable` shows any derivable string must have a `count I` that\nis 1 or 2 modulo 3.\n-/\ntheorem count_equiv_one_or_two_mod3_of_derivable (en : miustr): derivable en \u2192\n  (count I en) % 3 = 1 \u2228 (count I en) % 3 = 2:=\nbegin\n  intro h,\n  induction h,\n  { left, apply mod_def, },\n    any_goals {apply mod3_eq_1_or_mod3_eq_2 h_ih},\n    { left, simp only [count_append], refl, },\n    { right, simp only [count, countp, count_append, if_false,two_mul], },\n    { left, simp only [count, count_append, countp, if_false, if_pos],\n      rw [add_right_comm, add_mod_right], },\n    { left, simp only [count ,countp, countp_append, if_false, add_zero], },\nend\n\n/--\nUsing the above theorem, we solve the MU puzzle, showing that `\"MU\"` is not derivable.\nOnce we have proved that `derivable` is an instance of `decidable_pred`, this will follow\nimmediately from `dec_trivial`.\n-/\ntheorem not_derivable_mu : \u00ac(derivable \"MU\") :=\nbegin\n  intro h,\n  cases (count_equiv_one_or_two_mod3_of_derivable _ h);\n    contradiction,\nend\n\n/-!\n### Condition on `M`\n\nThat solves the MU puzzle, but we'll proceed by demonstrating the other necessary condition for a\nstring to be derivable, namely that the string must start with an M and contain no M in its tail.\n-/\n\n/--\n`goodm xs` holds if `xs : miustr` begins with `M` and has no `M` in its tail.\n-/\n@[derive decidable_pred]\ndef goodm (xs : miustr) : Prop :=\nlist.head xs = M \u2227 \u00ac(M \u2208 list.tail xs)\n\n/--\nDemonstration that `\"MI\"` starts with `M` and has no `M` in its tail.\n-/\nlemma goodmi : goodm [M,I] :=\nbegin\n  split,\n  { refl },\n  { rw [tail ,mem_singleton], trivial },\nend\n\n/-!\nWe'll show, for each `i` from 1 to 4, that if `en` follows by Rule `i` from `st` and if\n`goodm st` holds, then so does `goodm en`.\n-/\n\nlemma goodm_of_rule1 (xs : miustr) (h\u2081 : derivable (xs ++ [I])) (h\u2082 : goodm (xs ++ [I]))\n  : goodm (xs ++ [I,U]) :=\nbegin\n  cases h\u2082 with mhead nmtail,\n  have : xs \u2260 nil,\n  { intro h, rw h at *, rw [nil_append, head] at mhead, contradiction, },\n  split,\n  { rwa [head_append] at *; exact this, },\n  { change [I,U] with [I] ++ [U],\n    rw [\u2190append_assoc, tail_append_singleton_of_ne_nil],\n    { simp only [mem_append, nmtail, false_or, mem_singleton, not_false_iff], },\n    { exact append_ne_nil_of_ne_nil_left _ _ this, }, },\nend\n\nlemma goodm_of_rule2 (xs : miustr) (h\u2081 : derivable (M :: xs))\n  (h\u2082 : goodm (M :: xs)) : goodm (M :: xs ++ xs) :=\nbegin\n  split,\n  { refl, },\n  { cases h\u2082 with mhead mtail,\n    contrapose! mtail,\n    rw cons_append at mtail,\n    rw tail at *,\n    exact (or_self _).mp (mem_append.mp mtail), },\nend\n\nlemma goodm_of_rule3  (as bs : miustr) (h\u2081 : derivable (as ++ [I,I,I] ++ bs))\n  (h\u2082 : goodm (as ++ [I,I,I] ++ bs)) : goodm (as ++ U :: bs) :=\nbegin\n  cases h\u2082 with mhead nmtail,\n  have k : as \u2260 nil ,\n  { intro h, rw h at mhead, rw [nil_append] at mhead, contradiction, },\n  split,\n  { revert mhead, simp only [append_assoc,head_append _ k], exact id, },\n  { contrapose! nmtail,\n    rcases (exists_cons_of_ne_nil k) with \u27e8x,xs,rfl\u27e9,\n    simp only [cons_append, tail, mem_append, mem_cons_iff, false_or, mem_nil_iff, or_false] at *,\n    exact nmtail, },\nend\n\n/-!\n The proof of the next lemma is identical, on the tactic level, to the previous proof.\n-/\n\nlemma goodm_of_rule4  (as bs : miustr) (h\u2081 : derivable (as ++ [U,U] ++ bs))\n  (h\u2082 : goodm (as ++ [U,U] ++ bs)) : goodm (as ++ bs) :=\nbegin\n  cases h\u2082 with mhead nmtail,\n  have k : as \u2260 nil ,\n  { intro h, rw h at mhead, rw [nil_append] at mhead, contradiction, },\n  split,\n  { revert mhead, simp only [append_assoc,head_append _ k], exact id, },\n  { contrapose! nmtail,\n    rcases (exists_cons_of_ne_nil k) with \u27e8x,xs,rfl\u27e9,\n    simp only [cons_append, tail, mem_append, mem_cons_iff, false_or, mem_nil_iff, or_false] at *,\n    exact nmtail, },\nend\n\n/--\nAny derivable string must begin with `M` and have no `M` in its tail.\n-/\ntheorem goodm_of_derivable (en : miustr): derivable en \u2192\n  goodm en:=\nbegin\n  intro h,\n  induction h,\n  { exact goodmi, },\n  { apply goodm_of_rule1; assumption, },\n  { apply goodm_of_rule2; assumption, },\n  { apply goodm_of_rule3; assumption, },\n  { apply goodm_of_rule4; assumption, },\nend\n\n/-!\nWe put togther our two conditions to give one necessary condition `decstr` for an `miustr` to be\nderivable.\n-/\n\n/--\n`decstr en` is the condition that `count I en` is 1 or 2 modulo 3, that `en` starts with `M`, and\nthat `en` has no `M` in its tail. We automatically derive that this is a decidable predicate.\n-/\n@[derive decidable_pred]\ndef decstr (en : miustr) :=\ngoodm en \u2227 ((count I en) % 3 = 1 \u2228 (count I en) % 3 = 2)\n\n/--\nSuppose `en : miustr`. If `en` is `derivable`, then the condition `decstr en` holds.\n-/\ntheorem decstr_of_der {en : miustr} : derivable en \u2192 decstr en :=\nbegin\n  intro h,\n  split,\n  { exact goodm_of_derivable en h, },\n  { exact count_equiv_one_or_two_mod3_of_derivable en h, },\nend\n\nend miu\n", "meta": {"author": "gihanmarasingha", "repo": "miu_language", "sha": "ffc2a1d4b33e76098578f3617b9b0a699dbcc885", "save_path": "github-repos/lean/gihanmarasingha-miu_language", "path": "github-repos/lean/gihanmarasingha-miu_language/miu_language-ffc2a1d4b33e76098578f3617b9b0a699dbcc885/src/decision_nec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7449748091439515}}
{"text": "import tutorial_world.level10_cases1_and --hide\nopen set IncidencePlane --hide\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\n\n/-\n# Tutorial World\n\n## Level 11: the `cases` tactic (II).\n\nSuppose now that your hypothesis says that `P` **or** `Q` holds. That is, you have `h : P \u2228 Q`. Then `cases h` will create\ntwo new goals; in the first place, `h : P \u2228 Q` will be replaced by `h : P`, and, in the second case, it will be replaced by `h : Q`.\n\nTo solve this level, you may need to remember how to employ the `use` tactic. As a reminder, note that if the goal is of \nthe form `\u22a2 \u2203 (R : \u03a9), R \u2208 X`, then you can type `use ?,`, where `?` is any object that satisfies the property of R, so that it\nturns the goal into `\u22a2 ? \u2208 X`. The object you are looking for is either found in \"Theorem statements\" or in the hypotheses located \nright above the goal of this level. [**Reminder:** if the goal breaks into two goals, remember that you can use curly braces to make \nthe look of the proof more visual.]\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nAfter typing `cases h,`, two goals will appear. Write curly braces to structure the proof. Then, start each goal by typing `use P` \nand `use Q`, respectively. The line that closes the goal is the same for both cases. Still bewildered? Click on \"View source\" (located on the\ntop right corner of the game screen) to see the solution.\n-/\n\n/- Lemma : no-side-bar\nIf \u2113 is any line in the plane \u03a9 and either the point P or the point Q is in \u2113, then \u2113 is not an empty line.\n-/\nlemma nonempty_example (P Q : \u03a9) (\u2113 : Line \u03a9) (h : P \u2208 \u2113 \u2228 Q \u2208 \u2113) : \u2203 R, R \u2208 \u2113 :=\nbegin\n\n  cases h,\n  {\n    use P,\n    exact h,\n  },\n  {\n    use Q,\n    exact h,\n  },\n  \nend\n\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/tutorial_world/level11_cases2_or.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7449697584984946}}
{"text": "variable (p q r : Prop)\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := \n  Iff.intro\n    (fun h : p \u2227 q => And.intro (And.right h) (And.left h))\n    (fun h : q \u2227 p => And.intro (And.right h) (And.left h))\n\nexample : p \u2228 q \u2194 q \u2228 p :=\n  have hpq : p \u2228 q \u2192 q \u2228 p := \n    (fun h : p \u2228 q =>\n      Or.elim h\n        (fun hp : p => Or.inr hp)\n        (fun hq : q => Or.inl hq))\n  have hqp : q \u2228 p \u2192 p \u2228 q :=\n    (fun h : q \u2228 p =>\n      Or.elim h\n        (fun hq : q => Or.inr hq)\n        (fun hp : p => Or.inl hp))\n  Iff.intro hpq hqp \n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n  Iff.intro \n    (fun h_lhs : (p \u2227 q) \u2227 r =>\n      And.intro (And.left (And.left h_lhs)) (And.intro (And.right (And.left h_lhs)) (And.right h_lhs)))\n    (fun h_rhs : p \u2227 (q \u2227 r) =>\n      And.intro (And.intro (And.left h_rhs) (And.left (And.right h_rhs))) (And.right (And.right h_rhs)))\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n  have h_lhs : (p \u2228 q) \u2228 r \u2192 p \u2228 (q \u2228 r) :=\n    (fun h : (p \u2228 q) \u2228 r => \n      Or.elim h \n        (fun hpq : (p \u2228 q) => \n          Or.elim hpq\n            (fun hp : p => Or.inl hp)\n            (fun hq : q => Or.inr (Or.inl hq)))\n        (fun hr : r => \n          Or.inr (Or.inr hr)))\n  have h_rhs : p \u2228 (q \u2228 r) \u2192 (p \u2228 q) \u2228 r :=\n    (fun h : p \u2228 (q \u2228 r) =>\n      Or.elim h\n        (fun hp : p =>\n          Or.inl (Or.inl hp))\n        (fun hqr : q \u2228 r =>\n          Or.elim hqr\n            (fun hq : q =>\n              Or.inl (Or.inr hq))\n            (fun hr : r =>\n              Or.inr hr)))\n  Iff.intro h_lhs h_rhs\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  have h_lhs : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\n    (fun h_pqr : p \u2227 (q \u2228 r) =>\n      have hp : p := And.left h_pqr\n      Or.elim (And.right h_pqr)\n        (fun hq : q => Or.inl (And.intro hp hq))\n        (fun hr : r => Or.inr (And.intro hp hr)))\n  have h_rhs : (p \u2227 q) \u2228 (p \u2227 r) \u2192 p \u2227 (q \u2228 r) := \n    (fun h_pq_pr : (p \u2227 q) \u2228 (p \u2227 r) =>\n      Or.elim h_pq_pr\n        (fun hpq : p \u2227 q =>\n          (And.intro (And.left hpq) (Or.inl (And.right hpq))))\n        (fun hpr : p \u2227 r =>\n          (And.intro (And.left hpr) (Or.inr (And.right hpr)))))\n  Iff.intro h_lhs h_rhs\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := \n  have h_p_qr : p \u2228 (q \u2227 r) \u2192 (p \u2228 q) \u2227 (p \u2228 r) :=\n    (fun hp_qr : p \u2228 (q \u2227 r) =>\n      Or.elim hp_qr\n        (fun hp : p => And.intro (Or.inl hp) (Or.inl hp))\n        (fun hqr : q \u2227 r => And.intro (Or.inr (And.left hqr)) (Or.inr (And.right hqr))))\n  have h_pq_pr : (p \u2228 q) \u2227 (p \u2228 r) \u2192 p \u2228 (q \u2227 r) := \n    (fun h_pq_pr : (p \u2228 q) \u2227 (p \u2228 r) => \n      Or.elim (And.left h_pq_pr)\n        (fun hp : p => Or.inl hp)\n        (fun hq : q =>\n          Or.elim (And.right h_pq_pr)\n            (fun hp : p => Or.inl hp)\n            (fun hr : r => Or.inr (And.intro hq hr))))\n  Iff.intro h_p_qr h_pq_pr\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := \n  have h_lhs : (p \u2192 (q \u2192 r)) \u2192 (p \u2227 q \u2192 r) := \n    (fun h_pqr : p \u2192 (q \u2192 r) =>\n      (fun hpq : p \u2227 q =>\n        (h_pqr (And.left hpq) (And.right hpq)))) \n  have h_rhs : (p \u2227 q \u2192 r) \u2192 (p \u2192 (q \u2192 r)) :=\n    (fun h_pqr : (p \u2227 q \u2192 r) => \n      (fun hp : p =>\n        (fun hq : q => \n          (h_pqr (And.intro hp hq))))) \n  Iff.intro h_lhs h_rhs\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := \n  have h_lhs : ((p \u2228 q) \u2192 r) \u2192 (p \u2192 r) \u2227 (q \u2192 r) :=\n    (fun h_pq_r : ((p \u2228 q) \u2192 r) =>\n      And.intro\n        (fun hp : p => \n          h_pq_r (Or.inl hp))\n        (fun hq : q =>\n          h_pq_r (Or.inr hq)))\n  have h_rhs : (p \u2192 r) \u2227 (q \u2192 r) \u2192 ((p \u2228 q) \u2192 r) :=\n    (fun h_pr_qr : (p \u2192 r) \u2227 (q \u2192 r) => \n      (fun hpq : p \u2228 q =>\n        Or.elim hpq \n          (fun hp : p => (And.left h_pr_qr) hp)\n          (fun hq : q => (And.right h_pr_qr) hq)))\n  Iff.intro h_lhs h_rhs\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := \n  have h_lhs : \u00ac(p \u2228 q) \u2192 \u00acp \u2227 \u00acq :=\n    (fun (npq : (p \u2228 q) \u2192 False) => \n      (And.intro \n        (fun (hp : p) => (npq (Or.inl hp)))\n        (fun (hq : q) => (npq (Or.inr hq)))))\n  have h_rhs : \u00acp \u2227 \u00acq \u2192 \u00ac(p \u2228 q) :=\n    (fun (hnpnq : \u00acp \u2227 \u00acq) => \n      (fun (hpq : p \u2228 q) => \n        Or.elim hpq\n          (fun (hp : p) => \n            (And.left hnpnq) hp)\n          (fun (hq : q) =>\n            (And.right hnpnq) hq)))\n  Iff.intro h_lhs h_rhs\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := \n  (fun (hnpnq : \u00acp \u2228 \u00acq) (hpq: p \u2227 q) =>\n    Or.elim hnpnq\n      (fun hnp : \u00acp => False.elim (hnp (And.left hpq)))\n      (fun hnq : \u00acq => False.elim (hnq (And.right hpq))))\n\nexample : \u00ac(p \u2227 \u00acp) :=\n  (fun hpnp : p \u2227 \u00acp =>\n    (False.elim ((And.right hpnp) (And.left hpnp))))\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := \n  (fun (hpnq : p \u2227 \u00acq) (hpq : p \u2192 q) =>\n    (False.elim ((And.right hpnq) (hpq (And.left hpnq)))))\n\nexample : \u00acp \u2192 (p \u2192 q) := \n  (fun (hnp : \u00acp) (hp : p) =>\n    False.elim (hnp hp))\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := \n  (fun h_npq : (\u00acp \u2228 q) =>\n    (fun hp : p => \n      Or.elim h_npq\n        (fun hnp : \u00acp =>\n          False.elim (hnp hp))\n        (fun hq : q => hq)))\n\nexample : p \u2228 False \u2194 p := \n  have h_lhs : p \u2228 False \u2192 p :=\n    (fun h_pf : p \u2228 False => \n      Or.elim h_pf \n        (fun hp : p => hp)\n        (fun hf : False => False.elim hf))\n  have h_rhs : p \u2192 p \u2228 False :=\n    (fun hp : p => Or.inl hp)\n  Iff.intro h_lhs h_rhs\n\nexample : p \u2227 False \u2194 False := \n  have h_lhs : p \u2227 False \u2192 False :=\n    (fun h_pf : p \u2227 False => \n      And.right h_pf)\n  have h_rhs : False \u2192 p \u2227 False :=\n    (fun h_f : False =>\n      And.intro (False.elim h_f) h_f)\n  Iff.intro h_lhs h_rhs\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := \n  (fun h_pq : p \u2192 q =>\n    (fun hnq : \u00acq =>\n      (fun hp : p =>\n        False.elim (hnq (h_pq hp)))))\n\nopen Classical\n\nvariable (p q r s : Prop)\n\ntheorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\n  Or.elim (em p)\n  (fun hp : p => hp)\n  (fun nhp : \u00acp => False.elim (h nhp))\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := sorry\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := sorry\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := sorry\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := sorry\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := sorry\nexample : p \u2228 \u00acp := sorry\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := sorry\n", "meta": {"author": "huckkim", "repo": "Leaning4U", "sha": "2c26849408fcca85c0d7354e18b876c703bc733c", "save_path": "github-repos/lean/huckkim-Leaning4U", "path": "github-repos/lean/huckkim-Leaning4U/Leaning4U-2c26849408fcca85c0d7354e18b876c703bc733c/propositional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7449697525299499}}
{"text": "open classical\n\nvariables { p q r : Prop }\n\ntheorem not_not_iff : \u00ac\u00acp \u2194 p :=\n\u27e8by_contradiction \u2218 flip absurd, not_not_intro\u27e9 \n\ntheorem imp_classical : p \u2192 q \u2194 \u00ac p \u2228 q := \n\u27e8\u03bbh, by_cases (or.inr \u2218 h) or.inl, \u03bbh h1, h.elim (absurd h1) id\u27e9\n\ntheorem not_and_iff_neg_or : \u00ac (p \u2227 q) \u2194 (\u00ac p \u2228 \u00ac q) :=\nby { split; intro h,\n    { apply @by_cases p; intro h1,\n        { apply @by_cases q; intro h2,\n            { apply false.elim, apply h,\n                split, exact h1, exact h2 },\n            { right, exact h2 } },\n        { left, exact h1 } },\n    { intro h1, cases h1 with h2 h3, cases h with h h; apply h,\n        exact h2, exact h3 } }\n\ntheorem not_or_iff_neg_and : \u00ac (p \u2228 q) \u2194 (\u00ac p \u2227 \u00ac q) :=\nby { split; intro h, \n    { split; intro h1; apply h,\n        { left, exact h1 }, { right, exact h1 } },\n    { cases h with h h1, intro h2, cases h2 with h2 h2,\n        { apply h, exact h2 }, { apply h1, exact h2 } } }", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/classical_logic/proposional_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285009303773, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7449627584253343}}
{"text": "import game.sets.sets_level10\nimport data.real.basic\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 1\n\nThis level aims to familiarize you with the use of the trichotomy property in \nLean, as it will come in handy in later levels.\nThis property is stated in Lean's mathlib is:\n\n`lt_trichotomy : \u2200 (a b : ?M_1), a < b \u2228 a = b \u2228 b < a`\n\nand you can just use it to finish the proof below.\n-/\n\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$ a < b \\lor a = b \\lor b < a$$.\n-/\ntheorem trichotomy' (a b : \u211d) : a < b \u2228 a = b \u2228 b < a :=\nbegin\n    exact lt_trichotomy a b, done\nend\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7449627479373161}}
{"text": "import game.max.level10\n\nopen_locale classical\n\nnoncomputable theory\n\nnamespace test\n\nvariables {a b c : \u211d}\n\n-- What \u211d has that a general total order hasn't got, is - .\n\nexample : -a \u2264 -b \u2194 b \u2264 a := by split; intros; linarith\n\ndef abs (x : \u211d) := max x (-x)\n\n-- useful for rewriting\nlemma abs_def (x : \u211d) : abs x = max x (-x) := rfl\n\n-- needs congr'\nlemma abs_neg (x : \u211d) : abs (-x) = abs x :=\nbegin\n  rw abs_def,\n  rw abs_def,\n  rw max_comm,\n  congr',\n  ring,\nend\n\n-- order level 3\n-- Powerful. Teaches them the colon. \ntheorem abs_le : abs a \u2264 b \u2194 -b \u2264 a \u2227 a \u2264 b :=\nbegin\n  rw abs_def,\n  rw max_le_iff,\n  split;\n  intro h;\n  cases h;\n  split;\n  linarith,\nend\n\ntheorem abs_of_nonneg (h : 0 \u2264 a) : abs a = a :=\nbegin\n  rw abs_def,\n  apply max_eq_left,\n  linarith\nend\n\ntheorem abs_of_nonpos (h : a \u2264 0) : abs a = -a :=\nbegin\n  rw abs_def,\n  apply max_eq_right,\n  linarith\nend\n\nvariables (a b) -- want them explicit in the next few\n\ntheorem abs_add : abs (a + b) \u2264 abs a + abs b :=\nbegin\n  rw abs_le,\n  cases le_total 0 a with h0a ha0,\n  { -- 0 \u2264 a\n    rw abs_of_nonneg h0a,\n    cases le_total 0 b with h0b hb0,\n    { rw abs_of_nonneg h0b,\n      split; linarith\n    },\n    { rw abs_of_nonpos hb0,\n      split; linarith\n    },\n  },\n  { -- a \u2264 0\n    rw abs_of_nonpos ha0,\n    cases le_total 0 b with h0b hb0,\n    { rw abs_of_nonneg h0b,\n      split; linarith\n    },\n    { rw abs_of_nonpos hb0,\n      split; linarith\n    },\n  },\nend\n\n-- order level 4\n-- convert makes this simple\ntheorem abs_sub_le_add_abs : abs (a - b) \u2264 abs a + abs b :=\nbegin\n  rw \u2190abs_neg b,\n  convert abs_add a (-b),\nend\n\n-- order level 5\n-- combination of ring and linarith; always try and deduce from triangle ineq\ntheorem abs_abs_sub_le_abs_sub : abs (abs a - abs b) \u2264 abs (a - b) :=\nbegin\n  rw abs_le,\n  split,\n  { have h := abs_sub_le_add_abs a (a - b),\n    ring at h,\n    linarith,\n  },\n  { have h := abs_sub_le_add_abs (a - b) (-b),\n    rw abs_neg at h,\n    ring at h,\n    linarith\n  }\nend\n\n-- order level 2\ntheorem abs_mul (a b : \u211d) : abs (a * b) = abs a * abs b :=\nbegin\n  cases le_total 0 a with h0a ha0;\n  cases le_total 0 b with h0b hb0,\n  { -- both nonnegative\n    rw abs_of_nonneg h0a,\n    rw abs_of_nonneg h0b,\n    rw abs_of_nonneg,\n    nlinarith,\n  },\n  { -- b <= 0 <= a\n    rw abs_of_nonneg h0a,\n    rw abs_of_nonpos hb0,\n    rw abs_of_nonpos,\n    { ring},\n    nlinarith,\n  },\n  { -- a \u2264 0 \u2264 b\n    rw abs_of_nonpos ha0,\n    rw abs_of_nonneg h0b,\n    rw abs_of_nonpos,\n    { ring},\n    nlinarith,\n  },\n  { -- both nonnegative\n    rw abs_of_nonpos ha0,\n    rw abs_of_nonpos hb0,\n    rw abs_of_nonneg,\n    { ring},\n    nlinarith,\n  },  \nend\n\n-- order level 6 (unfinished)\nlemma le_iff_square_le (ha : 0 \u2264 a) (hb : 0 \u2264 b): a \u2264 b \u2194 a^2 \u2264 b^2 :=\nbegin\n  rw (show a^2 \u2264 b^2 \u2194 0 \u2264 b^2 - a^2, by split; intros; linarith),\n  rw (show b^2 - a^2 = (b + a) * (b - a), by ring),\n  rw (show a \u2264 b \u2194 0 \u2264 b - a, by split; intros; linarith), -- should be a lemma\n  have hab : 0 \u2264 b + a, by linarith,\n  split,\n  { intros,\n    nlinarith},\n  { intros,\n    by_cases h : b + a = 0,\n    { linarith },\n    have ha2 : 0 < b + a,\n    { by_contradiction hab,\n      push_neg at hab,\n      apply h,\n      linarith\n    },\n    sorry\n  } \nend\n\n\nend test\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/abs/abs_API_test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7449627428398032}}
{"text": "variables P Q : Prop\n\nexample : (P \u2192 Q) \u2192 (\u00acQ \u2192 \u00acP) :=\nbegin\n    intro HPQ,\n    intro HnQ,\n    \nend", "meta": {"author": "Samyak-Surti", "repo": "LeanCode", "sha": "944eac3e5f43e2614ed246083b97fbdf24181d83", "save_path": "github-repos/lean/Samyak-Surti-LeanCode", "path": "github-repos/lean/Samyak-Surti-LeanCode/LeanCode-944eac3e5f43e2614ed246083b97fbdf24181d83/lean_test/src/test2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.7449627419860188}}
{"text": "/-\nCopyright (c) 2022 Alexander Bentkamp. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp\n-/\nimport analysis.inner_product_space.gram_schmidt_ortho\nimport linear_algebra.matrix.pos_def\n\n/-! # LDL decomposition\n\nThis file proves the LDL-decomposition of matricies: Any positive definite matrix `S` can be\ndecomposed as `S = LDL\u1d34` where `L` is a lower-triangular matrix and `D` is a diagonal matrix.\n\n## Main definitions\n\n * `LDL.lower` is the lower triangular matrix `L`.\n * `LDL.lower_inv` is the inverse of the lower triangular matrix `L`.\n * `LDL.diag` is the diagonal matrix `D`.\n\n## Main result\n\n* `ldl_decomposition` states that any positive definite matrix can be decomposed as `LDL\u1d34`.\n\n## TODO\n\n* Prove that `LDL.lower` is lower triangular from `LDL.lower_inv_triangular`.\n\n-/\n\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c]\nvariables {n : Type*} [linear_order n] [is_well_order n (<)] [locally_finite_order_bot n]\n\nlocal notation `\u27ea`x`, `y`\u27eb\u2091` := @inner \ud835\udd5c _ _ ((pi_Lp.equiv 2 _).symm x) ((pi_Lp.equiv _ _).symm y)\n\nopen matrix\nopen_locale matrix\nvariables {S : matrix n n \ud835\udd5c} [fintype n] (hS : S.pos_def)\n\n/-- The inverse of the lower triangular matrix `L` of the LDL-decomposition. It is obtained by\napplying Gram-Schmidt-Orthogonalization w.r.t. the inner product induced by `S\u1d40` on the standard\nbasis vectors `pi.basis_fun`. -/\nnoncomputable def LDL.lower_inv : matrix n n \ud835\udd5c :=\n@gram_schmidt\n  \ud835\udd5c (n \u2192 \ud835\udd5c) _\n  (_ : _)\n  (inner_product_space.of_matrix hS.transpose) n _ _ _ (pi.basis_fun \ud835\udd5c n)\n\nlemma LDL.lower_inv_eq_gram_schmidt_basis :\n  LDL.lower_inv hS = ((pi.basis_fun \ud835\udd5c n).to_matrix\n    (@gram_schmidt_basis \ud835\udd5c (n \u2192 \ud835\udd5c) _ (_ : _)\n    (inner_product_space.of_matrix hS.transpose) n _ _ _ (pi.basis_fun \ud835\udd5c n)))\u1d40 :=\nbegin\n  ext i j,\n  rw [LDL.lower_inv, basis.coe_pi_basis_fun.to_matrix_eq_transpose, coe_gram_schmidt_basis],\n  refl\nend\n\nnoncomputable instance LDL.invertible_lower_inv : invertible (LDL.lower_inv hS) :=\nbegin\n  rw [LDL.lower_inv_eq_gram_schmidt_basis],\n  haveI := basis.invertible_to_matrix (pi.basis_fun \ud835\udd5c n)\n    (@gram_schmidt_basis \ud835\udd5c (n \u2192 \ud835\udd5c) _ (_ : _) (inner_product_space.of_matrix hS.transpose)\n      n _ _ _ (pi.basis_fun \ud835\udd5c n)),\n  apply_instance\nend\n\nlemma LDL.lower_inv_orthogonal {i j : n} (h\u2080 : i \u2260 j) :\n  \u27ea(LDL.lower_inv hS i), S\u1d40.mul_vec (LDL.lower_inv hS j)\u27eb\u2091 = 0 :=\n@gram_schmidt_orthogonal \ud835\udd5c _ _ (_ : _) (inner_product_space.of_matrix hS.transpose) _ _ _ _ _ _ _ h\u2080\n\n/-- The entries of the diagonal matrix `D` of the LDL decomposition. -/\nnoncomputable def LDL.diag_entries : n \u2192 \ud835\udd5c :=\n\u03bb i, \u27eastar (LDL.lower_inv hS i), S.mul_vec (star (LDL.lower_inv hS i))\u27eb\u2091\n\n/-- The diagonal matrix `D` of the LDL decomposition. -/\nnoncomputable def LDL.diag : matrix n n \ud835\udd5c := matrix.diagonal (LDL.diag_entries hS)\n\nlemma LDL.lower_inv_triangular {i j : n} (hij : i < j) :\n  LDL.lower_inv hS i j = 0 :=\nby rw [\u2190 @gram_schmidt_triangular\n    \ud835\udd5c (n \u2192 \ud835\udd5c) _ (_ : _) (inner_product_space.of_matrix hS.transpose) n _ _ _\n    i j hij (pi.basis_fun \ud835\udd5c n), pi.basis_fun_repr, LDL.lower_inv]\n\n/-- Inverse statement of **LDL decomposition**: we can conjugate a positive definite matrix\nby some lower triangular matrix and get a diagonal matrix. -/\nlemma LDL.diag_eq_lower_inv_conj : LDL.diag hS = LDL.lower_inv hS \u2b1d S \u2b1d (LDL.lower_inv hS)\u1d34 :=\nbegin\n  ext i j,\n  by_cases hij : i = j,\n  { simpa only [hij, LDL.diag, diagonal_apply_eq, LDL.diag_entries, matrix.mul_assoc,\n      euclidean_space.inner_pi_Lp_equiv_symm, star_star] },\n  { simp only [LDL.diag, hij, diagonal_apply_ne, ne.def, not_false_iff, mul_mul_apply],\n    rw [conj_transpose, transpose_map, transpose_transpose, dot_product_mul_vec,\n      (LDL.lower_inv_orthogonal hS (\u03bb h : j = i, hij h.symm)).symm,\n      \u2190 inner_conj_symm, mul_vec_transpose, euclidean_space.inner_pi_Lp_equiv_symm,\n      \u2190 is_R_or_C.star_def, \u2190 star_dot_product_star, dot_product_comm, star_star],\n    refl }\nend\n\n/-- The lower triangular matrix `L` of the LDL decomposition. -/\nnoncomputable def LDL.lower := (LDL.lower_inv hS)\u207b\u00b9\n\n/-- **LDL decomposition**: any positive definite matrix `S` can be\ndecomposed as `S = LDL\u1d34` where `L` is a lower-triangular matrix and `D` is a diagonal matrix.  -/\ntheorem LDL.lower_conj_diag :\n  LDL.lower hS \u2b1d LDL.diag hS \u2b1d (LDL.lower hS)\u1d34 = S :=\nbegin\n  rw [LDL.lower, conj_transpose_nonsing_inv, matrix.mul_assoc,\n    matrix.inv_mul_eq_iff_eq_mul_of_invertible (LDL.lower_inv hS),\n    matrix.mul_inv_eq_iff_eq_mul_of_invertible],\n  exact LDL.diag_eq_lower_inv_conj hS,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/ldl.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.7449627377422904}}
{"text": "import tactic\n\ninductive pre_term\n| var : \u2115 \u2192 pre_term \n| app : pre_term \u2192 pre_term \u2192 pre_term\n| abs : \u2115 \u2192 pre_term \u2192 pre_term\n\ndef free_variables : pre_term \u2192 set \u2115\n| (pre_term.var n) := {n}\n|\t(pre_term.app M N) := free_variables M \u222a free_variables N\n| (pre_term.abs n M) := free_variables M \\ {n}\n\nlemma free_variables_finite : \u2200 M, (free_variables M).finite :=\n\u03bb M, pre_term.rec (\u03bb n, set.finite_singleton n)\n  (\u03bb M N ihM ihN, ihM.union ihN)\n  (\u03bb n M ihn, ihn.diff {n}) M\n\nlemma exists_new_free_var (M N : pre_term) : \u2203n, n \u2209 free_variables M \u2227 n \u2209 free_variables N :=\nbegin \n\t suffices : \u2203n, n \u2209 (free_variables M \u222a free_variables N),\n\t {\n\t\t cases this with n hn,\n\t\t use n,\n\t\t exact not_or_distrib.mp hn,\n\t },\n\n\t have : free_variables M \u222a free_variables N \u2260 set.univ,\n\t {\n\t\tintro h,\n\t \thave h_fin := (free_variables_finite M).union(free_variables_finite N),\n\t\trw h at h_fin,\n\t\texact @not_fintype \u2115 nat.infinite (set.fintype_of_finite_univ h_fin),\n\t },\n\n\tby_contra,\n\tpush_neg at h, apply this,\n\text, split, \n\t{ exact \u03bb hx, set.mem_univ x },\n\t{exact \u03bb gbg, h x},\nend\n\n\nopen classical\nlocal attribute [instance] prop_decidable\n\ndef closed : pre_term \u2192 Prop := \u03bbM, free_variables M = \u2205\n\n-- noncomputable def subst : pre_term \u2192 \u2115 \u2192 pre_term \u2192 pre_term\n-- | (pre_term.var n) x N := if x = n then N else pre_term.var n \n-- | (pre_term.app P Q) x N := pre_term.app (subst P x N) (subst Q x N)\n-- | (pre_term.abs y P) x N := if x = y then (pre_term.abs y P) else \n-- (\n-- \tif x \u2208 free_variables P \u2227 x \u2208 free_variables N then \n-- \tlet z := classical.some (exists_new_free_var P N) in let temp := (subst P y (pre_term.var z)) in\n-- \tpre_term.abs z (subst temp x N)\n-- )\n\nconstant subst : pre_term \u2192 \u2115 \u2192 pre_term \u2192 pre_term\n\ninductive \u03b1_equiv : pre_term \u2192 pre_term \u2192 Prop\n| refl (M) : \u03b1_equiv M M\n| symm (M N) : \u03b1_equiv M N \u2192 \u03b1_equiv N M \n| trans (M N O) : \u03b1_equiv M N \u2192 \u03b1_equiv N O \u2192 \u03b1_equiv M O\n| app (M M' N N') : \u03b1_equiv M M' \u2192 \u03b1_equiv N N' \u2192 \u03b1_equiv (pre_term.app M N) (pre_term.app M' N')\n| abs (P P' x) : \u03b1_equiv P P' \u2192 \u03b1_equiv (pre_term.abs x P) (pre_term.abs x P')\n| rename (P) (x y) :\n y \u2209 free_variables P \u2192 \u03b1_equiv (pre_term.abs x P) (pre_term.abs y (subst P x (pre_term.var y)))\n\ninstance lambda_term.setoid : setoid pre_term := \nsetoid.mk \u03b1_equiv \u27e8\u03b1_equiv.refl, \u03b1_equiv.symm, \u03b1_equiv.trans\u27e9\n\ndef lamba_term := quotient lambda_term.setoid \n\n", "meta": {"author": "duduFreire", "repo": "formal_logic", "sha": "d7977f4bc03267b56c2a694595c4654eaef84f42", "save_path": "github-repos/lean/duduFreire-formal_logic", "path": "github-repos/lean/duduFreire-formal_logic/formal_logic-d7977f4bc03267b56c2a694595c4654eaef84f42/src/lambda.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7449572821782994}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module algebra.regular.smul\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.SmulWithZero\nimport Mathbin.Algebra.Regular.Basic\n\n/-!\n# Action of regular elements on a module\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe introduce `M`-regular elements, in the context of an `R`-module `M`.  The corresponding\npredicate is called `is_smul_regular`.\n\nThere are very limited typeclass assumptions on `R` and `M`, but the \"mathematical\" case of interest\nis a commutative ring `R` acting an a module `M`. Since the properties are \"multiplicative\", there\nis no actual requirement of having an addition, but there is a zero in both `R` and `M`.\nSmultiplications involving `0` are, of course, all trivial.\n\nThe defining property is that an element `a \u2208 R` is `M`-regular if the smultiplication map\n`M \u2192 M`, defined by `m \u21a6 a \u2022 m`, is injective.\n\nThis property is the direct generalization to modules of the property `is_left_regular` defined in\n`algebra/regular`.  Lemma `is_smul_regular.is_left_regular_iff` shows that indeed the two notions\ncoincide.\n-/\n\n\nvariable {R S : Type _} (M : Type _) {a b : R} {s : S}\n\n#print IsSMulRegular /-\n/-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an\ninjective map `M \u2192 M`. -/\ndef IsSMulRegular [SMul R M] (c : R) :=\n  Function.Injective ((\u00b7 \u2022 \u00b7) c : M \u2192 M)\n#align is_smul_regular IsSMulRegular\n-/\n\n#print IsLeftRegular.isSMulRegular /-\ntheorem IsLeftRegular.isSMulRegular [Mul R] {c : R} (h : IsLeftRegular c) : IsSMulRegular R c :=\n  h\n#align is_left_regular.is_smul_regular IsLeftRegular.isSMulRegular\n-/\n\n#print isLeftRegular_iff /-\n/-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/\ntheorem isLeftRegular_iff [Mul R] {a : R} : IsLeftRegular a \u2194 IsSMulRegular R a :=\n  Iff.rfl\n#align is_left_regular_iff isLeftRegular_iff\n-/\n\n#print IsRightRegular.isSMulRegular /-\ntheorem IsRightRegular.isSMulRegular [Mul R] {c : R} (h : IsRightRegular c) :\n    IsSMulRegular R (MulOpposite.op c) :=\n  h\n#align is_right_regular.is_smul_regular IsRightRegular.isSMulRegular\n-/\n\n#print isRightRegular_iff /-\n/-- Right-regular multiplication on `R` is equivalent to `R\u1d50\u1d52\u1d56`-regularity of `R` itself. -/\ntheorem isRightRegular_iff [Mul R] {a : R} :\n    IsRightRegular a \u2194 IsSMulRegular R (MulOpposite.op a) :=\n  Iff.rfl\n#align is_right_regular_iff isRightRegular_iff\n-/\n\nnamespace IsSMulRegular\n\nvariable {M}\n\nsection SMul\n\nvariable [SMul R M] [SMul R S] [SMul S M] [IsScalarTower R S M]\n\n/- warning: is_smul_regular.smul -> IsSMulRegular.smul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {S : Type.{u2}} {M : Type.{u3}} {a : R} {s : S} [_inst_1 : SMul.{u1, u3} R M] [_inst_2 : SMul.{u1, u2} R S] [_inst_3 : SMul.{u2, u3} S M] [_inst_4 : IsScalarTower.{u1, u2, u3} R S M _inst_2 _inst_3 _inst_1], (IsSMulRegular.{u1, u3} R M _inst_1 a) -> (IsSMulRegular.{u2, u3} S M _inst_3 s) -> (IsSMulRegular.{u2, u3} S M _inst_3 (SMul.smul.{u1, u2} R S _inst_2 a s))\nbut is expected to have type\n  forall {R : Type.{u3}} {S : Type.{u1}} {M : Type.{u2}} {a : R} {s : S} [_inst_1 : SMul.{u3, u2} R M] [_inst_2 : SMul.{u3, u1} R S] [_inst_3 : SMul.{u1, u2} S M] [_inst_4 : IsScalarTower.{u3, u1, u2} R S M _inst_2 _inst_3 _inst_1], (IsSMulRegular.{u3, u2} R M _inst_1 a) -> (IsSMulRegular.{u1, u2} S M _inst_3 s) -> (IsSMulRegular.{u1, u2} S M _inst_3 (HSMul.hSMul.{u3, u1, u1} R S S (instHSMul.{u3, u1} R S _inst_2) a s))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.smul IsSMulRegular.smul\u2093'. -/\n/-- The product of `M`-regular elements is `M`-regular. -/\ntheorem smul (ra : IsSMulRegular M a) (rs : IsSMulRegular M s) : IsSMulRegular M (a \u2022 s) :=\n  fun a b ab => rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _))))\n#align is_smul_regular.smul IsSMulRegular.smul\n\n/- warning: is_smul_regular.of_smul -> IsSMulRegular.of_smul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {S : Type.{u2}} {M : Type.{u3}} {s : S} [_inst_1 : SMul.{u1, u3} R M] [_inst_2 : SMul.{u1, u2} R S] [_inst_3 : SMul.{u2, u3} S M] [_inst_4 : IsScalarTower.{u1, u2, u3} R S M _inst_2 _inst_3 _inst_1] (a : R), (IsSMulRegular.{u2, u3} S M _inst_3 (SMul.smul.{u1, u2} R S _inst_2 a s)) -> (IsSMulRegular.{u2, u3} S M _inst_3 s)\nbut is expected to have type\n  forall {R : Type.{u1}} {S : Type.{u3}} {M : Type.{u2}} {s : S} [_inst_1 : SMul.{u1, u2} R M] [_inst_2 : SMul.{u1, u3} R S] [_inst_3 : SMul.{u3, u2} S M] [_inst_4 : IsScalarTower.{u1, u3, u2} R S M _inst_2 _inst_3 _inst_1] (a : R), (IsSMulRegular.{u3, u2} S M _inst_3 (HSMul.hSMul.{u1, u3, u3} R S S (instHSMul.{u1, u3} R S _inst_2) a s)) -> (IsSMulRegular.{u3, u2} S M _inst_3 s)\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.of_smul IsSMulRegular.of_smul\u2093'. -/\n/-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular\nelement, then `b` is `M`-regular. -/\ntheorem of_smul (a : R) (ab : IsSMulRegular M (a \u2022 s)) : IsSMulRegular M s :=\n  @Function.Injective.of_comp _ _ _ (fun m : M => a \u2022 m) _ fun c d cd =>\n    ab (by rwa [smul_assoc, smul_assoc])\n#align is_smul_regular.of_smul IsSMulRegular.of_smul\n\n/- warning: is_smul_regular.smul_iff -> IsSMulRegular.smul_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {S : Type.{u2}} {M : Type.{u3}} {a : R} [_inst_1 : SMul.{u1, u3} R M] [_inst_2 : SMul.{u1, u2} R S] [_inst_3 : SMul.{u2, u3} S M] [_inst_4 : IsScalarTower.{u1, u2, u3} R S M _inst_2 _inst_3 _inst_1] (b : S), (IsSMulRegular.{u1, u3} R M _inst_1 a) -> (Iff (IsSMulRegular.{u2, u3} S M _inst_3 (SMul.smul.{u1, u2} R S _inst_2 a b)) (IsSMulRegular.{u2, u3} S M _inst_3 b))\nbut is expected to have type\n  forall {R : Type.{u3}} {S : Type.{u1}} {M : Type.{u2}} {a : R} [_inst_1 : SMul.{u3, u2} R M] [_inst_2 : SMul.{u3, u1} R S] [_inst_3 : SMul.{u1, u2} S M] [_inst_4 : IsScalarTower.{u3, u1, u2} R S M _inst_2 _inst_3 _inst_1] (b : S), (IsSMulRegular.{u3, u2} R M _inst_1 a) -> (Iff (IsSMulRegular.{u1, u2} S M _inst_3 (HSMul.hSMul.{u3, u1, u1} R S S (instHSMul.{u3, u1} R S _inst_2) a b)) (IsSMulRegular.{u1, u2} S M _inst_3 b))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.smul_iff IsSMulRegular.smul_iff\u2093'. -/\n/-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element\nis `M`-regular. -/\n@[simp]\ntheorem smul_iff (b : S) (ha : IsSMulRegular M a) : IsSMulRegular M (a \u2022 b) \u2194 IsSMulRegular M b :=\n  \u27e8of_smul _, ha.smul\u27e9\n#align is_smul_regular.smul_iff IsSMulRegular.smul_iff\n\n#print IsSMulRegular.isLeftRegular /-\ntheorem isLeftRegular [Mul R] {a : R} (h : IsSMulRegular R a) : IsLeftRegular a :=\n  h\n#align is_smul_regular.is_left_regular IsSMulRegular.isLeftRegular\n-/\n\n#print IsSMulRegular.isRightRegular /-\ntheorem isRightRegular [Mul R] {a : R} (h : IsSMulRegular R (MulOpposite.op a)) :\n    IsRightRegular a :=\n  h\n#align is_smul_regular.is_right_regular IsSMulRegular.isRightRegular\n-/\n\n/- warning: is_smul_regular.mul -> IsSMulRegular.mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} {b : R} [_inst_1 : SMul.{u1, u2} R M] [_inst_5 : Mul.{u1} R] [_inst_6 : IsScalarTower.{u1, u1, u2} R R M (Mul.toSMul.{u1} R _inst_5) _inst_1 _inst_1], (IsSMulRegular.{u1, u2} R M _inst_1 a) -> (IsSMulRegular.{u1, u2} R M _inst_1 b) -> (IsSMulRegular.{u1, u2} R M _inst_1 (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R _inst_5) a b))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} {b : R} [_inst_1 : SMul.{u2, u1} R M] [_inst_5 : Mul.{u2} R] [_inst_6 : IsScalarTower.{u2, u2, u1} R R M (Mul.toSMul.{u2} R _inst_5) _inst_1 _inst_1], (IsSMulRegular.{u2, u1} R M _inst_1 a) -> (IsSMulRegular.{u2, u1} R M _inst_1 b) -> (IsSMulRegular.{u2, u1} R M _inst_1 (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R _inst_5) a b))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.mul IsSMulRegular.mul\u2093'. -/\ntheorem mul [Mul R] [IsScalarTower R R M] (ra : IsSMulRegular M a) (rb : IsSMulRegular M b) :\n    IsSMulRegular M (a * b) :=\n  ra.smul rb\n#align is_smul_regular.mul IsSMulRegular.mul\n\n/- warning: is_smul_regular.of_mul -> IsSMulRegular.of_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} {b : R} [_inst_1 : SMul.{u1, u2} R M] [_inst_5 : Mul.{u1} R] [_inst_6 : IsScalarTower.{u1, u1, u2} R R M (Mul.toSMul.{u1} R _inst_5) _inst_1 _inst_1], (IsSMulRegular.{u1, u2} R M _inst_1 (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R _inst_5) a b)) -> (IsSMulRegular.{u1, u2} R M _inst_1 b)\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} {b : R} [_inst_1 : SMul.{u2, u1} R M] [_inst_5 : Mul.{u2} R] [_inst_6 : IsScalarTower.{u2, u2, u1} R R M (Mul.toSMul.{u2} R _inst_5) _inst_1 _inst_1], (IsSMulRegular.{u2, u1} R M _inst_1 (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R _inst_5) a b)) -> (IsSMulRegular.{u2, u1} R M _inst_1 b)\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.of_mul IsSMulRegular.of_mul\u2093'. -/\ntheorem of_mul [Mul R] [IsScalarTower R R M] (ab : IsSMulRegular M (a * b)) : IsSMulRegular M b :=\n  by\n  rw [\u2190 smul_eq_mul] at ab\n  exact ab.of_smul _\n#align is_smul_regular.of_mul IsSMulRegular.of_mul\n\n/- warning: is_smul_regular.mul_iff_right -> IsSMulRegular.mul_iff_right is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} {b : R} [_inst_1 : SMul.{u1, u2} R M] [_inst_5 : Mul.{u1} R] [_inst_6 : IsScalarTower.{u1, u1, u2} R R M (Mul.toSMul.{u1} R _inst_5) _inst_1 _inst_1], (IsSMulRegular.{u1, u2} R M _inst_1 a) -> (Iff (IsSMulRegular.{u1, u2} R M _inst_1 (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R _inst_5) a b)) (IsSMulRegular.{u1, u2} R M _inst_1 b))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} {b : R} [_inst_1 : SMul.{u2, u1} R M] [_inst_5 : Mul.{u2} R] [_inst_6 : IsScalarTower.{u2, u2, u1} R R M (Mul.toSMul.{u2} R _inst_5) _inst_1 _inst_1], (IsSMulRegular.{u2, u1} R M _inst_1 a) -> (Iff (IsSMulRegular.{u2, u1} R M _inst_1 (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R _inst_5) a b)) (IsSMulRegular.{u2, u1} R M _inst_1 b))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.mul_iff_right IsSMulRegular.mul_iff_right\u2093'. -/\n@[simp]\ntheorem mul_iff_right [Mul R] [IsScalarTower R R M] (ha : IsSMulRegular M a) :\n    IsSMulRegular M (a * b) \u2194 IsSMulRegular M b :=\n  \u27e8of_mul, ha.mul\u27e9\n#align is_smul_regular.mul_iff_right IsSMulRegular.mul_iff_right\n\n/- warning: is_smul_regular.mul_and_mul_iff -> IsSMulRegular.mul_and_mul_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} {b : R} [_inst_1 : SMul.{u1, u2} R M] [_inst_5 : Mul.{u1} R] [_inst_6 : IsScalarTower.{u1, u1, u2} R R M (Mul.toSMul.{u1} R _inst_5) _inst_1 _inst_1], Iff (And (IsSMulRegular.{u1, u2} R M _inst_1 (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R _inst_5) a b)) (IsSMulRegular.{u1, u2} R M _inst_1 (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R _inst_5) b a))) (And (IsSMulRegular.{u1, u2} R M _inst_1 a) (IsSMulRegular.{u1, u2} R M _inst_1 b))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} {b : R} [_inst_1 : SMul.{u2, u1} R M] [_inst_5 : Mul.{u2} R] [_inst_6 : IsScalarTower.{u2, u2, u1} R R M (Mul.toSMul.{u2} R _inst_5) _inst_1 _inst_1], Iff (And (IsSMulRegular.{u2, u1} R M _inst_1 (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R _inst_5) a b)) (IsSMulRegular.{u2, u1} R M _inst_1 (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R _inst_5) b a))) (And (IsSMulRegular.{u2, u1} R M _inst_1 a) (IsSMulRegular.{u2, u1} R M _inst_1 b))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.mul_and_mul_iff IsSMulRegular.mul_and_mul_iff\u2093'. -/\n/-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a`\nare `M`-regular. -/\ntheorem mul_and_mul_iff [Mul R] [IsScalarTower R R M] :\n    IsSMulRegular M (a * b) \u2227 IsSMulRegular M (b * a) \u2194 IsSMulRegular M a \u2227 IsSMulRegular M b :=\n  by\n  refine' \u27e8_, _\u27e9\n  \u00b7 rintro \u27e8ab, ba\u27e9\n    refine' \u27e8ba.of_mul, ab.of_mul\u27e9\n  \u00b7 rintro \u27e8ha, hb\u27e9\n    exact \u27e8ha.mul hb, hb.mul ha\u27e9\n#align is_smul_regular.mul_and_mul_iff IsSMulRegular.mul_and_mul_iff\n\nend SMul\n\nsection Monoid\n\nvariable [Monoid R] [MulAction R M]\n\nvariable (M)\n\n/- warning: is_smul_regular.one -> IsSMulRegular.one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} (M : Type.{u2}) [_inst_1 : Monoid.{u1} R] [_inst_2 : MulAction.{u1, u2} R M _inst_1], IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (MulOneClass.toHasOne.{u1} R (Monoid.toMulOneClass.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u2}} (M : Type.{u1}) [_inst_1 : Monoid.{u2} R] [_inst_2 : MulAction.{u2, u1} R M _inst_1], IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) (OfNat.ofNat.{u2} R 1 (One.toOfNat1.{u2} R (Monoid.toOne.{u2} R _inst_1)))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.one IsSMulRegular.one\u2093'. -/\n/-- One is `M`-regular always. -/\n@[simp]\ntheorem one : IsSMulRegular M (1 : R) := fun a b ab => by rwa [one_smul, one_smul] at ab\n#align is_smul_regular.one IsSMulRegular.one\n\nvariable {M}\n\n/- warning: is_smul_regular.of_mul_eq_one -> IsSMulRegular.of_mul_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} {b : R} [_inst_1 : Monoid.{u1} R] [_inst_2 : MulAction.{u1, u2} R M _inst_1], (Eq.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (MulOneClass.toHasMul.{u1} R (Monoid.toMulOneClass.{u1} R _inst_1))) a b) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (MulOneClass.toHasOne.{u1} R (Monoid.toMulOneClass.{u1} R _inst_1)))))) -> (IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) b)\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} {b : R} [_inst_1 : Monoid.{u2} R] [_inst_2 : MulAction.{u2, u1} R M _inst_1], (Eq.{succ u2} R (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (MulOneClass.toMul.{u2} R (Monoid.toMulOneClass.{u2} R _inst_1))) a b) (OfNat.ofNat.{u2} R 1 (One.toOfNat1.{u2} R (Monoid.toOne.{u2} R _inst_1)))) -> (IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) b)\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.of_mul_eq_one IsSMulRegular.of_mul_eq_one\u2093'. -/\n/-- An element of `R` admitting a left inverse is `M`-regular. -/\ntheorem of_mul_eq_one (h : a * b = 1) : IsSMulRegular M b :=\n  of_mul\n    (by\n      rw [h]\n      exact one M)\n#align is_smul_regular.of_mul_eq_one IsSMulRegular.of_mul_eq_one\n\n/- warning: is_smul_regular.pow -> IsSMulRegular.pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} [_inst_1 : Monoid.{u1} R] [_inst_2 : MulAction.{u1, u2} R M _inst_1] (n : Nat), (IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) a) -> (IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R _inst_1)) a n))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} [_inst_1 : Monoid.{u2} R] [_inst_2 : MulAction.{u2, u1} R M _inst_1] (n : Nat), (IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) a) -> (IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) (HPow.hPow.{u2, 0, u2} R Nat R (instHPow.{u2, 0} R Nat (Monoid.Pow.{u2} R _inst_1)) a n))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.pow IsSMulRegular.pow\u2093'. -/\n/-- Any power of an `M`-regular element is `M`-regular. -/\ntheorem pow (n : \u2115) (ra : IsSMulRegular M a) : IsSMulRegular M (a ^ n) :=\n  by\n  induction' n with n hn\n  \u00b7 simp only [one, pow_zero]\n  \u00b7 rw [pow_succ]\n    exact (ra.smul_iff (a ^ n)).mpr hn\n#align is_smul_regular.pow IsSMulRegular.pow\n\n/- warning: is_smul_regular.pow_iff -> IsSMulRegular.pow_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} [_inst_1 : Monoid.{u1} R] [_inst_2 : MulAction.{u1, u2} R M _inst_1] {n : Nat}, (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) -> (Iff (IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R _inst_1)) a n)) (IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) a))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} [_inst_1 : Monoid.{u2} R] [_inst_2 : MulAction.{u2, u1} R M _inst_1] {n : Nat}, (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) -> (Iff (IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) (HPow.hPow.{u2, 0, u2} R Nat R (instHPow.{u2, 0} R Nat (Monoid.Pow.{u2} R _inst_1)) a n)) (IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) a))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.pow_iff IsSMulRegular.pow_iff\u2093'. -/\n/-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/\ntheorem pow_iff {n : \u2115} (n0 : 0 < n) : IsSMulRegular M (a ^ n) \u2194 IsSMulRegular M a :=\n  by\n  refine' \u27e8_, pow n\u27e9\n  rw [\u2190 Nat.succ_pred_eq_of_pos n0, pow_succ', \u2190 smul_eq_mul]\n  exact of_smul _\n#align is_smul_regular.pow_iff IsSMulRegular.pow_iff\n\nend Monoid\n\nsection MonoidSmul\n\nvariable [Monoid S] [SMul R M] [SMul R S] [MulAction S M] [IsScalarTower R S M]\n\n/- warning: is_smul_regular.of_smul_eq_one -> IsSMulRegular.of_smul_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {S : Type.{u2}} {M : Type.{u3}} {a : R} {s : S} [_inst_1 : Monoid.{u2} S] [_inst_2 : SMul.{u1, u3} R M] [_inst_3 : SMul.{u1, u2} R S] [_inst_4 : MulAction.{u2, u3} S M _inst_1] [_inst_5 : IsScalarTower.{u1, u2, u3} R S M _inst_3 (MulAction.toHasSmul.{u2, u3} S M _inst_1 _inst_4) _inst_2], (Eq.{succ u2} S (SMul.smul.{u1, u2} R S _inst_3 a s) (OfNat.ofNat.{u2} S 1 (OfNat.mk.{u2} S 1 (One.one.{u2} S (MulOneClass.toHasOne.{u2} S (Monoid.toMulOneClass.{u2} S _inst_1)))))) -> (IsSMulRegular.{u2, u3} S M (MulAction.toHasSmul.{u2, u3} S M _inst_1 _inst_4) s)\nbut is expected to have type\n  forall {R : Type.{u2}} {S : Type.{u3}} {M : Type.{u1}} {a : R} {s : S} [_inst_1 : Monoid.{u3} S] [_inst_2 : SMul.{u2, u1} R M] [_inst_3 : SMul.{u2, u3} R S] [_inst_4 : MulAction.{u3, u1} S M _inst_1] [_inst_5 : IsScalarTower.{u2, u3, u1} R S M _inst_3 (MulAction.toSMul.{u3, u1} S M _inst_1 _inst_4) _inst_2], (Eq.{succ u3} S (HSMul.hSMul.{u2, u3, u3} R S S (instHSMul.{u2, u3} R S _inst_3) a s) (OfNat.ofNat.{u3} S 1 (One.toOfNat1.{u3} S (Monoid.toOne.{u3} S _inst_1)))) -> (IsSMulRegular.{u3, u1} S M (MulAction.toSMul.{u3, u1} S M _inst_1 _inst_4) s)\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.of_smul_eq_one IsSMulRegular.of_smul_eq_one\u2093'. -/\n/-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/\ntheorem of_smul_eq_one (h : a \u2022 s = 1) : IsSMulRegular M s :=\n  of_smul a\n    (by\n      rw [h]\n      exact one M)\n#align is_smul_regular.of_smul_eq_one IsSMulRegular.of_smul_eq_one\n\nend MonoidSmul\n\nsection MonoidWithZero\n\nvariable [MonoidWithZero R] [MonoidWithZero S] [Zero M] [MulActionWithZero R M]\n  [MulActionWithZero R S] [MulActionWithZero S M] [IsScalarTower R S M]\n\n/- warning: is_smul_regular.subsingleton -> IsSMulRegular.subsingleton is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : MonoidWithZero.{u1} R] [_inst_3 : Zero.{u2} M] [_inst_4 : MulActionWithZero.{u1, u2} R M _inst_1 _inst_3], (IsSMulRegular.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M _inst_3 (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))) _inst_3 (MulActionWithZero.toSMulWithZero.{u1, u2} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))))))) -> (Subsingleton.{succ u2} M)\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : MonoidWithZero.{u2} R] [_inst_3 : Zero.{u1} M] [_inst_4 : MulActionWithZero.{u2, u1} R M _inst_1 _inst_3], (IsSMulRegular.{u2, u1} R M (SMulZeroClass.toSMul.{u2, u1} R M _inst_3 (SMulWithZero.toSMulZeroClass.{u2, u1} R M (MonoidWithZero.toZero.{u2} R _inst_1) _inst_3 (MulActionWithZero.toSMulWithZero.{u2, u1} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (MonoidWithZero.toZero.{u2} R _inst_1)))) -> (Subsingleton.{succ u1} M)\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.subsingleton IsSMulRegular.subsingleton\u2093'. -/\n/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\nprotected theorem subsingleton (h : IsSMulRegular M (0 : R)) : Subsingleton M :=\n  \u27e8fun a b => h (by repeat' rw [MulActionWithZero.zero_smul])\u27e9\n#align is_smul_regular.subsingleton IsSMulRegular.subsingleton\n\n/- warning: is_smul_regular.zero_iff_subsingleton -> IsSMulRegular.zero_iff_subsingleton is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : MonoidWithZero.{u1} R] [_inst_3 : Zero.{u2} M] [_inst_4 : MulActionWithZero.{u1, u2} R M _inst_1 _inst_3], Iff (IsSMulRegular.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M _inst_3 (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))) _inst_3 (MulActionWithZero.toSMulWithZero.{u1, u2} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))))))) (Subsingleton.{succ u2} M)\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : MonoidWithZero.{u2} R] [_inst_3 : Zero.{u1} M] [_inst_4 : MulActionWithZero.{u2, u1} R M _inst_1 _inst_3], Iff (IsSMulRegular.{u2, u1} R M (SMulZeroClass.toSMul.{u2, u1} R M _inst_3 (SMulWithZero.toSMulZeroClass.{u2, u1} R M (MonoidWithZero.toZero.{u2} R _inst_1) _inst_3 (MulActionWithZero.toSMulWithZero.{u2, u1} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (MonoidWithZero.toZero.{u2} R _inst_1)))) (Subsingleton.{succ u1} M)\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.zero_iff_subsingleton IsSMulRegular.zero_iff_subsingleton\u2093'. -/\n/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\ntheorem zero_iff_subsingleton : IsSMulRegular M (0 : R) \u2194 Subsingleton M :=\n  \u27e8fun h => h.Subsingleton, fun H a b h => @Subsingleton.elim _ H a b\u27e9\n#align is_smul_regular.zero_iff_subsingleton IsSMulRegular.zero_iff_subsingleton\n\n/- warning: is_smul_regular.not_zero_iff -> IsSMulRegular.not_zero_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : MonoidWithZero.{u1} R] [_inst_3 : Zero.{u2} M] [_inst_4 : MulActionWithZero.{u1, u2} R M _inst_1 _inst_3], Iff (Not (IsSMulRegular.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M _inst_3 (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))) _inst_3 (MulActionWithZero.toSMulWithZero.{u1, u2} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1)))))))) (Nontrivial.{u2} M)\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : MonoidWithZero.{u2} R] [_inst_3 : Zero.{u1} M] [_inst_4 : MulActionWithZero.{u2, u1} R M _inst_1 _inst_3], Iff (Not (IsSMulRegular.{u2, u1} R M (SMulZeroClass.toSMul.{u2, u1} R M _inst_3 (SMulWithZero.toSMulZeroClass.{u2, u1} R M (MonoidWithZero.toZero.{u2} R _inst_1) _inst_3 (MulActionWithZero.toSMulWithZero.{u2, u1} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (MonoidWithZero.toZero.{u2} R _inst_1))))) (Nontrivial.{u1} M)\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.not_zero_iff IsSMulRegular.not_zero_iff\u2093'. -/\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\ntheorem not_zero_iff : \u00acIsSMulRegular M (0 : R) \u2194 Nontrivial M :=\n  by\n  rw [nontrivial_iff, not_iff_comm, zero_iff_subsingleton, subsingleton_iff]\n  push_neg\n  exact Iff.rfl\n#align is_smul_regular.not_zero_iff IsSMulRegular.not_zero_iff\n\n/- warning: is_smul_regular.zero -> IsSMulRegular.zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : MonoidWithZero.{u1} R] [_inst_3 : Zero.{u2} M] [_inst_4 : MulActionWithZero.{u1, u2} R M _inst_1 _inst_3] [sM : Subsingleton.{succ u2} M], IsSMulRegular.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M _inst_3 (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))) _inst_3 (MulActionWithZero.toSMulWithZero.{u1, u2} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))))))\nbut is expected to have type\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : MonoidWithZero.{u1} R] [_inst_3 : Zero.{u2} M] [_inst_4 : MulActionWithZero.{u1, u2} R M _inst_1 _inst_3] [sM : Subsingleton.{succ u2} M], IsSMulRegular.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M _inst_3 (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R _inst_1) _inst_3 (MulActionWithZero.toSMulWithZero.{u1, u2} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R _inst_1)))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.zero IsSMulRegular.zero\u2093'. -/\n/-- The element `0` is `M`-regular when `M` is trivial. -/\ntheorem zero [sM : Subsingleton M] : IsSMulRegular M (0 : R) :=\n  zero_iff_subsingleton.mpr sM\n#align is_smul_regular.zero IsSMulRegular.zero\n\n/- warning: is_smul_regular.not_zero -> IsSMulRegular.not_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : MonoidWithZero.{u1} R] [_inst_3 : Zero.{u2} M] [_inst_4 : MulActionWithZero.{u1, u2} R M _inst_1 _inst_3] [nM : Nontrivial.{u2} M], Not (IsSMulRegular.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M _inst_3 (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1))) _inst_3 (MulActionWithZero.toSMulWithZero.{u1, u2} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R _inst_1)))))))\nbut is expected to have type\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : MonoidWithZero.{u1} R] [_inst_3 : Zero.{u2} M] [_inst_4 : MulActionWithZero.{u1, u2} R M _inst_1 _inst_3] [nM : Nontrivial.{u2} M], Not (IsSMulRegular.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M _inst_3 (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R _inst_1) _inst_3 (MulActionWithZero.toSMulWithZero.{u1, u2} R M _inst_1 _inst_3 _inst_4))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.not_zero IsSMulRegular.not_zero\u2093'. -/\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\ntheorem not_zero [nM : Nontrivial M] : \u00acIsSMulRegular M (0 : R) :=\n  not_zero_iff.mpr nM\n#align is_smul_regular.not_zero IsSMulRegular.not_zero\n\nend MonoidWithZero\n\nsection CommSemigroup\n\nvariable [CommSemigroup R] [SMul R M] [IsScalarTower R R M]\n\n/- warning: is_smul_regular.mul_iff -> IsSMulRegular.mul_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} {a : R} {b : R} [_inst_1 : CommSemigroup.{u1} R] [_inst_2 : SMul.{u1, u2} R M] [_inst_3 : IsScalarTower.{u1, u1, u2} R R M (Mul.toSMul.{u1} R (Semigroup.toHasMul.{u1} R (CommSemigroup.toSemigroup.{u1} R _inst_1))) _inst_2 _inst_2], Iff (IsSMulRegular.{u1, u2} R M _inst_2 (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Semigroup.toHasMul.{u1} R (CommSemigroup.toSemigroup.{u1} R _inst_1))) a b)) (And (IsSMulRegular.{u1, u2} R M _inst_2 a) (IsSMulRegular.{u1, u2} R M _inst_2 b))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} {a : R} {b : R} [_inst_1 : CommSemigroup.{u2} R] [_inst_2 : SMul.{u2, u1} R M] [_inst_3 : IsScalarTower.{u2, u2, u1} R R M (Mul.toSMul.{u2} R (Semigroup.toMul.{u2} R (CommSemigroup.toSemigroup.{u2} R _inst_1))) _inst_2 _inst_2], Iff (IsSMulRegular.{u2, u1} R M _inst_2 (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (Semigroup.toMul.{u2} R (CommSemigroup.toSemigroup.{u2} R _inst_1))) a b)) (And (IsSMulRegular.{u2, u1} R M _inst_2 a) (IsSMulRegular.{u2, u1} R M _inst_2 b))\nCase conversion may be inaccurate. Consider using '#align is_smul_regular.mul_iff IsSMulRegular.mul_iff\u2093'. -/\n/-- A product is `M`-regular if and only if the factors are. -/\ntheorem mul_iff : IsSMulRegular M (a * b) \u2194 IsSMulRegular M a \u2227 IsSMulRegular M b :=\n  by\n  rw [\u2190 mul_and_mul_iff]\n  exact \u27e8fun ab => \u27e8ab, by rwa [mul_comm]\u27e9, fun rab => rab.1\u27e9\n#align is_smul_regular.mul_iff IsSMulRegular.mul_iff\n\nend CommSemigroup\n\nend IsSMulRegular\n\nsection Group\n\nvariable {G : Type _} [Group G]\n\n#print isSMulRegular_of_group /-\n/-- An element of a group acting on a Type is regular. This relies on the availability\nof the inverse given by groups, since there is no `left_cancel_smul` typeclass. -/\ntheorem isSMulRegular_of_group [MulAction G R] (g : G) : IsSMulRegular R g :=\n  by\n  intro x y h\n  convert congr_arg ((\u00b7 \u2022 \u00b7) g\u207b\u00b9) h using 1 <;> simp [\u2190 smul_assoc]\n#align is_smul_regular_of_group isSMulRegular_of_group\n-/\n\nend Group\n\nsection Units\n\nvariable [Monoid R] [MulAction R M]\n\n/- warning: units.is_smul_regular -> Units.isSMulRegular is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} (M : Type.{u2}) [_inst_1 : Monoid.{u1} R] [_inst_2 : MulAction.{u1, u2} R M _inst_1] (a : Units.{u1} R _inst_1), IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} R _inst_1) R (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} R _inst_1) R (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} R _inst_1) R (coeBase.{succ u1, succ u1} (Units.{u1} R _inst_1) R (Units.hasCoe.{u1} R _inst_1)))) a)\nbut is expected to have type\n  forall {R : Type.{u2}} (M : Type.{u1}) [_inst_1 : Monoid.{u2} R] [_inst_2 : MulAction.{u2, u1} R M _inst_1] (a : Units.{u2} R _inst_1), IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) (Units.val.{u2} R _inst_1 a)\nCase conversion may be inaccurate. Consider using '#align units.is_smul_regular Units.isSMulRegular\u2093'. -/\n/-- Any element in `R\u02e3` is `M`-regular. -/\ntheorem Units.isSMulRegular (a : R\u02e3) : IsSMulRegular M (a : R) :=\n  IsSMulRegular.of_mul_eq_one a.inv_val\n#align units.is_smul_regular Units.isSMulRegular\n\n/- warning: is_unit.is_smul_regular -> IsUnit.isSMulRegular is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} (M : Type.{u2}) {a : R} [_inst_1 : Monoid.{u1} R] [_inst_2 : MulAction.{u1, u2} R M _inst_1], (IsUnit.{u1} R _inst_1 a) -> (IsSMulRegular.{u1, u2} R M (MulAction.toHasSmul.{u1, u2} R M _inst_1 _inst_2) a)\nbut is expected to have type\n  forall {R : Type.{u2}} (M : Type.{u1}) {a : R} [_inst_1 : Monoid.{u2} R] [_inst_2 : MulAction.{u2, u1} R M _inst_1], (IsUnit.{u2} R _inst_1 a) -> (IsSMulRegular.{u2, u1} R M (MulAction.toSMul.{u2, u1} R M _inst_1 _inst_2) a)\nCase conversion may be inaccurate. Consider using '#align is_unit.is_smul_regular IsUnit.isSMulRegular\u2093'. -/\n/-- A unit is `M`-regular. -/\ntheorem IsUnit.isSMulRegular (ua : IsUnit a) : IsSMulRegular M a :=\n  by\n  rcases ua with \u27e8a, rfl\u27e9\n  exact a.is_smul_regular M\n#align is_unit.is_smul_regular IsUnit.isSMulRegular\n\nend Units\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Regular/Smul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7449572703466597}}
{"text": "/-\n  Induced map from Spec(B) to Spec(A).\n\n  https://stacks.math.columbia.edu/tag/00E2\n-/\n\nimport topology.basic\nimport ring_theory.ideal_operations\nimport spectrum_of_a_ring.zariski_topology\n\nopen lattice\n\nuniverses u v\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [comm_ring \u03b1] [comm_ring \u03b2]\nvariables (f : \u03b1 \u2192 \u03b2) [is_ring_hom f]\n\n-- Given \u03c6 : A \u2192 B, we have Spec(\u03c6) : Spec(B) \u2192 Spec(A), \ud835\udd2d\u2032\u27fc\u03c6\u207b\u00b9(\ud835\udd2d\u2032).\n\ndef Zariski.induced : Spec \u03b2 \u2192 Spec \u03b1 :=\n\u03bb \u27e8P, HP\u27e9, \u27e8ideal.comap f P, @ideal.is_prime.comap _ _ _ _ f _ P HP\u27e9\n\n-- This induced map is continuous.\n\nlemma Zariski.induced.continuous : continuous (Zariski.induced f) :=\nbegin \n  rintros U \u27e8E, HE\u27e9,\n  use [f '' E],\n  apply set.ext,\n  rintros \u27e8I, PI\u27e9,\n  split,\n  { intros HI HC,\n    suffices HfI : Zariski.induced f \u27e8I, PI\u27e9 \u2208 Spec.V E,\n      rw HE at HfI,\n      apply HfI,\n      exact HC, \n    intros x Hx,\n    simp [Zariski.induced] at *,\n    have HfE : f '' E \u2286 I := HI,\n    have Hfx : f x \u2208 f '' E := set.mem_image_of_mem f Hx,\n    exact (HfE Hfx), },\n  { rintros HI x \u27e8y, \u27e8Hy, Hfy\u27e9\u27e9,\n    suffices HfI : Zariski.induced f \u27e8I, PI\u27e9 \u2208 Spec.V E, \n      rw \u2190Hfy,\n      exact (HfI Hy),\n    intros z Hz,\n    simp [Zariski.induced] at *,\n    replace HI : _ \u2208 -U := HI,\n    rw \u2190HE at HI,\n    exact (HI Hz), }\nend \n\ntheorem Zariski.induced.preimage_D (x : \u03b1) \n: Zariski.induced f \u207b\u00b9' (Spec.D' x) = Spec.D' (f x) :=\nset.ext $ \u03bb \u27e8P, HP\u27e9, \nby simp [Spec.D', Spec.V', Zariski.induced]\n", "meta": {"author": "Or7ando", "repo": "lean", "sha": "d41169cf4e416a0d42092fb6bdc14131cee9dd15", "save_path": "github-repos/lean/Or7ando-lean", "path": "github-repos/lean/Or7ando-lean/lean-d41169cf4e416a0d42092fb6bdc14131cee9dd15/.github/workflows/project_1_a_decrire/lean-scheme-submission/src/spectrum_of_a_ring/induced_continuous_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7449130974845686}}
{"text": "-- Asociatividad_del_supremo.lean\n-- Si R es un ret\u00edculo y x, y, z \u2208 R, entonces (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z)\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 19-octubre-2022\n-- ---------------------------------------------------------------------\n\nimport order.lattice\n\nvariables {R : Type*} [lattice R]\nvariables x y z : R\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nbegin\n  have h1 : (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n    { have h1a : x \u2294 y \u2264 x \u2294 (y \u2294 z), by finish,\n      have h1b : z \u2264 x \u2294 (y \u2294 z), by finish,\n      show (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n        by exact sup_le h1a h1b, },\n  have h2 : x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n    { have h2a : x \u2264 (x \u2294 y) \u2294 z, by finish,\n      have h2b : y \u2294 z \u2264 (x \u2294 y) \u2294 z, by finish,\n      show x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n        by exact sup_le h2a h2b, },\n  show (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z),\n    by exact le_antisymm h1 h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nbegin\n  have h1 : (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n    { have h1a : x \u2294 y \u2264 x \u2294 (y \u2294 z),\n        { have h1a1 : x \u2264 x \u2294 (y \u2294 z) :=\n            le_sup_left,\n          have h1a2 : y \u2264 x \u2294 (y \u2294 z), calc\n            y \u2264 y \u2294 z         : le_sup_left\n            ... \u2264 x \u2294 (y \u2294 z) : le_sup_right,\n          show x \u2294 y \u2264 x \u2294 (y \u2294 z),\n            by exact sup_le h1a1 h1a2, },\n      have h1b : z \u2264 x \u2294 (y \u2294 z), calc\n        z   \u2264 y \u2294 z       : le_sup_right\n        ... \u2264 x \u2294 (y \u2294 z) : le_sup_right,\n      show (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n        by exact sup_le h1a h1b, },\n  have h2 : x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n    { have h2a : x \u2264 (x \u2294 y) \u2294 z, calc\n        x   \u2264 x \u2294 y       : le_sup_left\n        ... \u2264 (x \u2294 y) \u2294 z : le_sup_left,\n      have h2b : y \u2294 z \u2264 (x \u2294 y) \u2294 z,\n        { have h2b1 : y \u2264 (x \u2294 y) \u2294 z, calc\n            y   \u2264 x \u2294 y       : le_sup_right\n            ... \u2264 (x \u2294 y) \u2294 z : le_sup_left,\n          have h2b2 : z \u2264 (x \u2294 y) \u2294 z :=\n            le_sup_right,\n          show y \u2294 z \u2264 (x \u2294 y) \u2294 z,\n            by exact sup_le h2b1 h2b2, },\n      show x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n        by exact sup_le h2a h2b, },\n  show (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z),\n    by exact le_antisymm h1 h2,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nbegin\n  apply le_antisymm,\n  { apply sup_le,\n    { apply sup_le le_sup_left (le_sup_of_le_right le_sup_left)},\n    { apply le_sup_of_le_right le_sup_right}},\n  { apply sup_le,\n    { apply le_sup_of_le_left le_sup_left},\n    { apply sup_le (le_sup_of_le_left le_sup_right) le_sup_right}},\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nle_antisymm\n  (sup_le\n    (sup_le le_sup_left (le_sup_of_le_right le_sup_left))\n    (le_sup_of_le_right le_sup_right))\n  (sup_le\n    (le_sup_of_le_left le_sup_left)\n    (sup_le (le_sup_of_le_left le_sup_right) le_sup_right))\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 y \u2294 z = x \u2294 (y \u2294 z) :=\n-- by library_search\nsup_assoc\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 y \u2294 z = x \u2294 (y \u2294 z) :=\n-- by hint\nby finish\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Asociatividad_del_supremo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7449130950226506}}
{"text": "import super\nopen tactic\n\ndef prime (n : \u2115) := \u2200 d, d \u2223 n \u2192 d = 1 \u2228 d = n\n\nlemma nat_mul_cancel_one {m n : \u2115} : m \u2260 0 \u2192 m * n = m \u2192 n = 1 :=\nby cases m; super nat.zero_lt_succ nat.eq_of_mul_eq_mul_left nat.mul_one\n\nlemma not_prime_zero : \u00ac prime 0 :=\nby intro h; cases h 2 \u27e80, rfl\u27e9; cases h_1\n\n@[simp] lemma nat.dvd_refl (m : \u2115) : m \u2223 m := \u27e81, by simp [nat.mul_one]\u27e9\n@[simp] theorem nat.dvd_mul_left (a b : \u2115) : a \u2223 b * a := \u27e8b, nat.mul_comm _ _\u27e9\n\nexample {m n : \u2115} : prime (m * n) \u2192 m = 1 \u2228 n = 1 :=\nby super with prime nat.dvd_refl nat.dvd_mul_right nat.dvd_mul_left\nnat_mul_cancel_one not_prime_zero nat.mul_zero nat.zero_mul\n\nexample : nat.zero \u2260 nat.succ nat.zero := by super\nexample (x y : \u2115) : nat.succ x = nat.succ y \u2192 x = y := by super\nexample (i) (a b c : i) : [a,b,c] = [b,c,a] -> a = b \u2227 b = c := by super\n\ndefinition is_positive (n : \u2115) := n > 0\nexample (n : \u2115) : n > 0 \u2194 is_positive n := by super with is_positive\n\nexample (m n : \u2115) : 0 + m = 0 + n \u2192 m = n :=\nby super with nat.zero_add\n\nexample : \u2200x y : \u2115, x + y = y + x :=\nbegin intros, have h : nat.zero = 0 := rfl, induction x,\n      super with nat.add_zero nat.zero_add,\n      super with nat.add_succ nat.succ_add end\n\nexample (i) [inhabited i] : nonempty i := by super\nexample (i) [nonempty i] : \u00ac(inhabited i \u2192 false) := by super\n\nexample : nonempty \u2115 := by super\nexample : \u00ac(inhabited \u2115 \u2192 false) := by super\n\nexample {a b} : \u00ac(b \u2228 \u00aca) \u2228 (a \u2192 b) := by super\nexample {a} : a \u2228 \u00aca := by super\nexample {a} : (a \u2227 a) \u2228 (\u00aca \u2227 \u00aca) := by super\nexample (i) (c : i) (p : i \u2192 Prop) (f : i \u2192 i) :\n  p c \u2192 (\u2200x, p x \u2192 p (f x)) \u2192 p (f (f (f c))) := by super\n\nexample (i) (p : i \u2192 Prop) : \u2200x, p x \u2192 \u2203x, p x := by super\n\nexample (i) [nonempty i] (p : i \u2192 i \u2192 Prop) : (\u2200x y, p x y) \u2192 \u2203x, \u2200z, p x z := by super\n\nexample (i) [nonempty i] (p : i \u2192 Prop) : (\u2200x, p x) \u2192 \u00ac\u00ac\u2200x, p x := by super\n\n-- Requires non-empty domain.\nexample {i} [nonempty i] (p : i \u2192 Prop) :\n  (\u2200x y, p x \u2228 p y) \u2192 \u2203x y, p x \u2227 p y := by super\n\nexample (i) (a b : i) (p : i \u2192 Prop) (H : a = b) : p b \u2192 p a :=\nby super\n\nexample (i) (a b : i) (p : i \u2192 Prop) (H : a = b) : p a \u2192 p b :=\nby super\n\nexample (i) (a b : i) (p : i \u2192 Prop) (H : a = b) : p b = p a :=\nby super\n\nexample (i) (c : i) (p : i \u2192 Prop) (f g : i \u2192 i) :\np c \u2192 (\u2200x, p x \u2192 p (f x)) \u2192 (\u2200x, p x \u2192 f x = g x) \u2192 f (f c) = g (g c) :=\nby super\n\nexample (i) (p q : i \u2192 i \u2192 Prop) (a b c d : i) :\n  (\u2200x y z, p x y \u2227 p y z \u2192 p x z) \u2192\n  (\u2200x y z, q x y \u2227 q y z \u2192 q x z) \u2192\n  (\u2200x y, q x y \u2192 q y x) \u2192\n  (\u2200x y, p x y \u2228 q x y) \u2192\n  p a b \u2228 q c d :=\nby super\n\n-- This example from Davis-Putnam actually requires a non-empty domain\n\nexample (i) [nonempty i] (f g : i \u2192 i \u2192 Prop) :\n  \u2203x y, \u2200z, (f x y \u2192 f y z \u2227 f z z) \u2227 (f x y \u2227 g x y \u2192 g x z \u2227 g z z) :=\nby super\n\nexample (person) [nonempty person] (drinks : person \u2192 Prop) :\n  \u2203canary, drinks canary \u2192 \u2200other, drinks other := by super\n\nexample {p q : \u2115 \u2192 Prop} {r} : (\u2200x y, p x \u2227 q y \u2227 r) -> \u2200x, (p x \u2227 r \u2227 q x) := by super\n", "meta": {"author": "leanprover", "repo": "super", "sha": "47b107b4cec8f3b41d72daba9cbda2f9d54025de", "save_path": "github-repos/lean/leanprover-super", "path": "github-repos/lean/leanprover-super/super-47b107b4cec8f3b41d72daba9cbda2f9d54025de/test/super_examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7449130933070105}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.bounds\nimport Mathlib.data.set.intervals.image_preimage\nimport Mathlib.PostPort\n\nuniverses u \n\nnamespace Mathlib\n\n/-!\n# Intervals without endpoints ordering\n\nIn any decidable linear order `\u03b1`, we define the set of elements lying between two elements `a` and\n`b` as `Icc (min a b) (max a b)`.\n\n`Icc a b` requires the assumption `a \u2264 b` to be meaningful, which is sometimes inconvenient. The\ninterval as defined in this file is always the set of things lying between `a` and `b`, regardless\nof the relative order of `a` and `b`.\n\nFor real numbers, `Icc (min a b) (max a b)` is the same as `segment a b`.\n\n## Notation\n\nWe use the localized notation `[a, b]` for `interval a b`. One can open the locale `interval` to\nmake the notation available.\n\n-/\n\nnamespace set\n\n\n/-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/\ndef interval {\u03b1 : Type u} [linear_order \u03b1] (a : \u03b1) (b : \u03b1) : set \u03b1 :=\n  Icc (min a b) (max a b)\n\n@[simp] theorem interval_of_le {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) : interval a b = Icc a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (interval a b = Icc a b)) (interval.equations._eqn_1 a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (Icc (min a b) (max a b) = Icc a b)) (min_eq_left h)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (Icc a (max a b) = Icc a b)) (max_eq_right h))) (Eq.refl (Icc a b))))\n\n@[simp] theorem interval_of_ge {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : b \u2264 a) : interval a b = Icc b a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (interval a b = Icc b a)) (interval.equations._eqn_1 a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (Icc (min a b) (max a b) = Icc b a)) (min_eq_right h)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (Icc b (max a b) = Icc b a)) (max_eq_left h))) (Eq.refl (Icc b a))))\n\ntheorem interval_swap {\u03b1 : Type u} [linear_order \u03b1] (a : \u03b1) (b : \u03b1) : interval a b = interval b a := sorry\n\ntheorem interval_of_lt {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) : interval a b = Icc a b :=\n  interval_of_le (le_of_lt h)\n\ntheorem interval_of_gt {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : b < a) : interval a b = Icc b a :=\n  interval_of_ge (le_of_lt h)\n\ntheorem interval_of_not_le {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : \u00aca \u2264 b) : interval a b = Icc b a :=\n  interval_of_gt (lt_of_not_ge h)\n\ntheorem interval_of_not_ge {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : \u00acb \u2264 a) : interval a b = Icc a b :=\n  interval_of_lt (lt_of_not_ge h)\n\n@[simp] theorem interval_self {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} : interval a a = singleton a := sorry\n\n@[simp] theorem nonempty_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} : set.nonempty (interval a b) := sorry\n\n@[simp] theorem left_mem_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} : a \u2208 interval a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 interval a b)) (interval.equations._eqn_1 a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 Icc (min a b) (max a b))) (propext mem_Icc)))\n      { left := min_le_left a b, right := le_max_left a b })\n\n@[simp] theorem right_mem_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} : b \u2208 interval a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b \u2208 interval a b)) (interval_swap a b))) left_mem_interval\n\ntheorem Icc_subset_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} : Icc a b \u2286 interval a b :=\n  id\n    fun (x : \u03b1) (h : x \u2208 Icc a b) =>\n      eq.mpr (id (Eq._oldrec (Eq.refl (x \u2208 interval a b)) (interval_of_le (le_trans (and.left h) (and.right h))))) h\n\ntheorem Icc_subset_interval' {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} : Icc b a \u2286 interval a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (Icc b a \u2286 interval a b)) (interval_swap a b))) Icc_subset_interval\n\ntheorem mem_interval_of_le {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (ha : a \u2264 x) (hb : x \u2264 b) : x \u2208 interval a b :=\n  Icc_subset_interval { left := ha, right := hb }\n\ntheorem mem_interval_of_ge {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (hb : b \u2264 x) (ha : x \u2264 a) : x \u2208 interval a b :=\n  Icc_subset_interval' { left := hb, right := ha }\n\ntheorem interval_subset_interval {\u03b1 : Type u} [linear_order \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1} (h\u2081 : a\u2081 \u2208 interval a\u2082 b\u2082) (h\u2082 : b\u2081 \u2208 interval a\u2082 b\u2082) : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082 :=\n  Icc_subset_Icc (le_min (and.left h\u2081) (and.left h\u2082)) (max_le (and.right h\u2081) (and.right h\u2082))\n\ntheorem interval_subset_interval_iff_mem {\u03b1 : Type u} [linear_order \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1} : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082 \u2194 a\u2081 \u2208 interval a\u2082 b\u2082 \u2227 b\u2081 \u2208 interval a\u2082 b\u2082 :=\n  { mp := fun (h : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082) => { left := h left_mem_interval, right := h right_mem_interval },\n    mpr := fun (h : a\u2081 \u2208 interval a\u2082 b\u2082 \u2227 b\u2081 \u2208 interval a\u2082 b\u2082) => interval_subset_interval (and.left h) (and.right h) }\n\ntheorem interval_subset_interval_iff_le {\u03b1 : Type u} [linear_order \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1} : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082 \u2194 min a\u2082 b\u2082 \u2264 min a\u2081 b\u2081 \u2227 max a\u2081 b\u2081 \u2264 max a\u2082 b\u2082 := sorry\n\ntheorem interval_subset_interval_right {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (h : x \u2208 interval a b) : interval x b \u2286 interval a b :=\n  interval_subset_interval h right_mem_interval\n\ntheorem interval_subset_interval_left {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (h : x \u2208 interval a b) : interval a x \u2286 interval a b :=\n  interval_subset_interval left_mem_interval h\n\ntheorem bdd_below_bdd_above_iff_subset_interval {\u03b1 : Type u} [linear_order \u03b1] (s : set \u03b1) : bdd_below s \u2227 bdd_above s \u2194 \u2203 (a : \u03b1), \u2203 (b : \u03b1), s \u2286 interval a b := sorry\n\n@[simp] theorem preimage_const_add_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a + x) \u207b\u00b9' interval b c = interval (b - a) (c - a) := sorry\n\n@[simp] theorem preimage_add_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x + a) \u207b\u00b9' interval b c = interval (b - a) (c - a) := sorry\n\n@[simp] theorem preimage_neg_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) : -interval a b = interval (-a) (-b) := sorry\n\n@[simp] theorem preimage_sub_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x - a) \u207b\u00b9' interval b c = interval (b + a) (c + a) := sorry\n\n@[simp] theorem preimage_const_sub_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a - x) \u207b\u00b9' interval b c = interval (a - b) (a - c) := sorry\n\n@[simp] theorem image_const_add_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a + x) '' interval b c = interval (a + b) (a + c) := sorry\n\n@[simp] theorem image_add_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x + a) '' interval b c = interval (b + a) (c + a) := sorry\n\n@[simp] theorem image_const_sub_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a - x) '' interval b c = interval (a - b) (a - c) := sorry\n\n@[simp] theorem image_sub_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x - a) '' interval b c = interval (b - a) (c - a) := sorry\n\ntheorem image_neg_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) : Neg.neg '' interval a b = interval (-a) (-b) := sorry\n\n/-- If `[x, y]` is a subinterval of `[a, b]`, then the distance between `x` and `y`\nis less than or equal to that of `a` and `b` -/\ntheorem abs_sub_le_of_subinterval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} {y : \u03b1} (h : interval x y \u2286 interval a b) : abs (y - x) \u2264 abs (b - a) := sorry\n\n/-- If `x \u2208 [a, b]`, then the distance between `a` and `x` is less than or equal to\nthat of `a` and `b`  -/\ntheorem abs_sub_left_of_mem_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (h : x \u2208 interval a b) : abs (x - a) \u2264 abs (b - a) :=\n  abs_sub_le_of_subinterval (interval_subset_interval_left h)\n\n/-- If `x \u2208 [a, b]`, then the distance between `x` and `b` is less than or equal to\nthat of `a` and `b`  -/\ntheorem abs_sub_right_of_mem_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (h : x \u2208 interval a b) : abs (b - x) \u2264 abs (b - a) :=\n  abs_sub_le_of_subinterval (interval_subset_interval_right h)\n\n@[simp] theorem preimage_mul_const_interval {k : Type u} [linear_ordered_field k] {a : k} (ha : a \u2260 0) (b : k) (c : k) : (fun (x : k) => x * a) \u207b\u00b9' interval b c = interval (b / a) (c / a) := sorry\n\n@[simp] theorem preimage_const_mul_interval {k : Type u} [linear_ordered_field k] {a : k} (ha : a \u2260 0) (b : k) (c : k) : (fun (x : k) => a * x) \u207b\u00b9' interval b c = interval (b / a) (c / a) := sorry\n\n@[simp] theorem preimage_div_const_interval {k : Type u} [linear_ordered_field k] {a : k} (ha : a \u2260 0) (b : k) (c : k) : (fun (x : k) => x / a) \u207b\u00b9' interval b c = interval (b * a) (c * a) := sorry\n\n@[simp] theorem image_mul_const_interval {k : Type u} [linear_ordered_field k] (a : k) (b : k) (c : k) : (fun (x : k) => x * a) '' interval b c = interval (b * a) (c * a) := sorry\n\n@[simp] theorem image_const_mul_interval {k : Type u} [linear_ordered_field k] (a : k) (b : k) (c : k) : (fun (x : k) => a * x) '' interval b c = interval (a * b) (a * c) := sorry\n\n@[simp] theorem image_div_const_interval {k : Type u} [linear_ordered_field k] (a : k) (b : k) (c : k) : (fun (x : k) => x / a) '' interval b c = interval (b / a) (c / a) :=\n  image_mul_const_interval (a\u207b\u00b9) b c\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/set/intervals/unordered_interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7449085526971193}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport analysis.normed_space.lp_space -- theory of \u2113\u1d56 spaces\n\n/-\n\n# \u2113\u1d56 spaces\n\nThe set-up : `I` is an index type, `E` is a family of `normed_add_comm_group`s\n(so if `i : I` then `E i` is a type and if `v : E i` then `\u2016v\u2016` makes sense and\nis a real number).\n\nThen given `p : \u211d\u22650\u221e` (i.e. an element `p` of `[0,\u221e]`) there is a theory\nof \u2113\u1d56 spaces, which is the subspace of `\u220f\u1d62, E i` consisting of the\nsections `v\u1d62` such that `\u2211\u1d62 \u2016v\u1d62\u2016\u1d56 < \u221e`. For `p=\u221e` this means \"the \u2016v\u1d62\u2016 are\nbounded\".\n\n-/\n\nopen_locale ennreal -- to get notation \u211d\u22650\u221e\n\nvariables (I : Type) (E : I \u2192 Type) [\u2200 i, normed_add_comm_group (E i)] (p : \u211d\u22650\u221e)\n\n-- Here's how to say that an element of the product of the E\u1d62 is in the \u2113\u1d56 space\n\nexample (v : \u03a0 i, E i) : Prop := mem_\u2113p v p\n\n-- Technical note: 0^0=1 and x^0=0 for x>0, so \u2113\u2070 is the functions with finite support.\n\nvariable (v : \u03a0 i, E i)\n\nexample : mem_\u2113p v 0 \u2194 set.finite {i | v i \u2260 0} :=\nbegin\n  exact mem_\u2113p_zero_iff,\nend\n\nexample : mem_\u2113p v \u221e \u2194 bdd_above (set.range (\u03bb i, \u2016v i\u2016)) :=\nbegin\n  exact mem_\u2113p_infty_iff,\nend\n\n-- The function ennreal.to_real sends x<\u221e to x and \u221e to 0. \n-- So `0 < p.to_real` is a way of saying `0 < p < \u221e`. \n\nexample (hp : 0 < p.to_real) : \n  mem_\u2113p v p \u2194 summable (\u03bb i, \u2016v i\u2016 ^ p.to_real) :=\nbegin\n  exact mem_\u2113p_gen_iff hp\nend\n\n-- It's a theorem in the library that if p \u2264 q then mem_\u2113p v p \u2192 mem_\u2113p v q\n\nexample (q : \u211d\u22650\u221e) (hpq : p \u2264 q) : mem_\u2113p v p \u2192 mem_\u2113p v q := \nbegin\n  intro h,\n  exact h.of_exponent_ge hpq,\nend\n\n\n-- The space of all `v` satisfying `mem_\u2113p v p` is\n-- called lp E p\n\nexample : Type := lp E p \n\n-- It has a norm:\n\nnoncomputable example (v : lp E p) : \u211d := \u2016v\u2016  \n\n-- It's a `normed_add_comm_group` if `1 \u2264 p`\n\nnoncomputable example [fact (1 \u2264 p)] : normed_add_comm_group (lp E p) :=\nbegin\n  apply_instance, -- Typeclass inference can't see 1 \u2264 p unless we \n                  -- use the `fact` typeclass (a way of putting arbitrary facts)\n                  -- into the system\nend\n\n\n-- `real.is_conjugate_exponent p q` means that `p,q>1` are reals and `1/p+1/q=1`\n\nexample (p q : \u211d) (hp : 1 < p) (hq : 1 < q) (hpq : 1 / p + 1 / q = 1) : \n  p.is_conjugate_exponent q :=\n{ one_lt := hp,\n  inv_add_inv_conj := hpq } -- note that `hq` not needed as it follows\n\n-- We have a verison of Hoelder's inequality.\n\n#check @lp.tsum_mul_le_mul_norm\n\nexample (q : \u211d\u22650\u221e) (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p)\n  (g : lp E q) : \u2211' (i : I), \u2016f i\u2016 * \u2016g i\u2016 \u2264 \u2016f\u2016 * \u2016g\u2016 :=\nbegin\n  have := lp.tsum_mul_le_mul_norm hpq f g,\n  exact this.2,\nend\n\n-- This would be a useless theorem if `\u2211' (i : I), \u2016f i\u2016 * \u2016g i\u2016` diverged,\n-- because in Lean if a sum diverges then by definition the `\u2211'` of it is 0. \n-- So we also need this:\n\nexample (q : \u211d\u22650\u221e) (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p)\n  (g : lp E q) : summable (\u03bb i, \u2016f i\u2016 * \u2016g i\u2016) :=\nbegin\n  have := lp.tsum_mul_le_mul_norm hpq f g,\n  exact this.1,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section17curves_and_surfaces/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7448587922592869}}
{"text": "import Chap5\nnamespace HTPI\nset_option pp.funBinderTypes true\n\n/- Section 5.1 -/\n-- 1.\ntheorem func_from_graph_ltr {A B : Type} (F : Set (A \u00d7 B)) :\n    (\u2203 (f : A \u2192 B), graph f = F) \u2192 is_func_graph F := sorry\n\n-- 2.\ntheorem Exercise_5_1_13a\n    {A B C : Type} (R : Set (A \u00d7 B)) (S : Set (B \u00d7 C)) (f : A \u2192 C)\n    (h1 : \u2200 (b : B), b \u2208 Ran R \u2227 b \u2208 Dom S) (h2 : graph f = comp S R) :\n    is_func_graph S := sorry\n\n-- 3.\ntheorem Exercise_5_1_14a\n    {A B : Type} (f : A \u2192 B) (R : BinRel A) (S : BinRel B)\n    (h : \u2200 (x y : A), R x y \u2194 S (f x) (f y)) :\n    reflexive S \u2192 reflexive R := sorry\n\n-- 4.\n--You might not be able to complete this proof\ntheorem Exercise_5_1_15a\n    {A B : Type} (f : A \u2192 B) (R : BinRel A) (S : BinRel B)\n    (h : \u2200 (x y : B), S x y \u2194 \u2203 (u v : A), f u = x \u2227 f v = y \u2227 R u v) :\n    reflexive R \u2192 reflexive S := sorry\n\n-- 5.\n--You might not be able to complete this proof\ntheorem Exercise_5_1_15c\n    {A B : Type} (f : A \u2192 B) (R : BinRel A) (S : BinRel B)\n    (h : \u2200 (x y : B), S x y \u2194 \u2203 (u v : A), f u = x \u2227 f v = y \u2227 R u v) :\n    transitive R \u2192 transitive S := sorry\n\n-- 6.\ntheorem Exercise_5_1_16b\n    {A B : Type} (R : BinRel B) (S : BinRel (A \u2192 B))\n    (h : \u2200 (f g : A \u2192 B), S f g \u2194 \u2200 (x : A), R (f x) (g x)) :\n    symmetric R \u2192 symmetric S := sorry\n\n-- 7.\ntheorem Exercise_5_1_17a {A : Type} (f : A \u2192 A) (a : A)\n    (h : \u2200 (x : A), f x = a) : \u2200 (g : A \u2192 A), f \u2218 g = f := sorry\n\n-- 8.\ntheorem Exercise_5_1_17b {A : Type} (f : A \u2192 A) (a : A)\n    (h : \u2200 (g : A \u2192 A), f \u2218 g = f) :\n    \u2203 (y : A), \u2200 (x : A), f x = y := sorry\n\n/- Section 5.2 -/\n-- 1.\ntheorem Exercise_5_2_10a {A B C : Type} (f: A \u2192 B) (g : B \u2192 C) :\n    onto (g \u2218 f) \u2192 onto g := sorry\n\n-- 2.\ntheorem Exercise_5_2_10b {A B C : Type} (f: A \u2192 B) (g : B \u2192 C) :\n    one_to_one (g \u2218 f) \u2192 one_to_one f := sorry\n\n-- 3.\ntheorem Exercise_5_2_11a {A B C : Type} (f: A \u2192 B) (g : B \u2192 C) :\n    onto f \u2192 \u00ac(one_to_one g) \u2192 \u00ac(one_to_one (g \u2218 f)) := sorry\n\n-- 4.\ntheorem Exercise_5_2_11b {A B C : Type} (f: A \u2192 B) (g : B \u2192 C) :\n    \u00ac(onto f) \u2192 one_to_one g \u2192 \u00ac(onto (g \u2218 f)) := sorry\n\n-- 5.\ntheorem Exercise_5_2_12 {A B : Type} (f : A \u2192 B) (g : B \u2192 Set A)\n    (h : \u2200 (b : B), g b = { a : A | f a = b }) :\n    onto f \u2192 one_to_one g := sorry\n\n-- 6.\ntheorem Exercise_5_2_16 {A B C : Type}\n    (R : Set (A \u00d7 B)) (S : Set (B \u00d7 C)) (f : A \u2192 C) (g : B \u2192 C)\n    (h1 : graph f = comp S R) (h2 : graph g = S) (h3 : one_to_one g) :\n    is_func_graph R := sorry\n\n-- 7.\ntheorem Exercise_5_2_17a\n    {A B : Type} (f : A \u2192 B) (R : BinRel A) (S : BinRel B)\n    (h1 : \u2200 (x y : B), S x y \u2194 \u2203 (u v : A), f u = x \u2227 f v = y \u2227 R u v)\n    (h2 : onto f) : reflexive R \u2192 reflexive S := sorry\n\n-- 8.\ntheorem Exercise_5_2_17b\n    {A B : Type} (f : A \u2192 B) (R : BinRel A) (S : BinRel B)\n    (h1 : \u2200 (x y : B), S x y \u2194 \u2203 (u v : A), f u = x \u2227 f v = y \u2227 R u v)\n    (h2 : one_to_one f) : transitive R \u2192 transitive S := sorry\n\n-- 9.\ntheorem Exercise_5_2_21a {A B C : Type} (f : B \u2192 C) (g h : A \u2192 B)\n    (h1 : one_to_one f) (h2 : f \u2218 g = f \u2218 h) : g = h := sorry\n\n-- 10.\ntheorem Exercise_5_2_21b {A B C : Type} (f : B \u2192 C) (a : A)\n    (h1 : \u2200 (g h : A \u2192 B), f \u2218 g = f \u2218 h \u2192 g = h) :\n    one_to_one f := sorry\n\n/- Section 5.3 -/\n-- 1.\ntheorem Theorem_5_3_2_2_ex {A B : Type} (f : A \u2192 B) (g : B \u2192 A)\n    (h1 : graph g = inv (graph f)) : f \u2218 g = id := sorry\n\n-- 2.\ntheorem Theorem_5_3_3_2_ex {A B : Type} (f : A \u2192 B) :\n    (\u2203 (g : B \u2192 A), f \u2218 g = id) \u2192 onto f := sorry\n\n-- 3.\ntheorem Exercise_5_3_11a {A B : Type} (f : A \u2192 B) (g : B \u2192 A) :\n    one_to_one f \u2192 f \u2218 g = id \u2192 graph g = inv (graph f) := sorry\n\n-- 4.\ntheorem Exercise_5_3_11b {A B : Type} (f : A \u2192 B) (g : B \u2192 A) :\n    onto f \u2192 g \u2218 f = id \u2192 graph g = inv (graph f) := sorry\n\n-- 5.\ntheorem Exercise_5_3_14a {A B : Type} (f : A \u2192 B) (g : B \u2192 A)\n    (h : f \u2218 g = id) : \u2200 x \u2208 Ran (graph g), g (f x) = x := sorry\n\n-- 6.\ntheorem Exercise_5_3_18 {A B C : Type} (f : A \u2192 C) (g : B \u2192 C)\n    (h1 : one_to_one g) (h2 : onto g) :\n    \u2203 (h : A \u2192 B), g \u2218 h = f := sorry\n\n-- Definition for next two exercises:\ndef conj (A : Type) (f1 f2 : A \u2192 A) : Prop :=\n    \u2203 (g g' : A \u2192 A), (f1 = g' \u2218 f2 \u2218 g) \u2227 (g \u2218 g' = id) \u2227 (g' \u2218 g = id)\n\n-- 7.\ntheorem Exercise_5_3_17a {A : Type} : symmetric (conj A) := sorry\n\n-- 8.\ntheorem Exercise_5_3_17b {A : Type} (f1 f2 : A \u2192 A)\n    (h1 : conj A f1 f2) (h2 : \u2203 (a : A), f1 a = a) :\n    \u2203 (a : A), f2 a = a := sorry\n\n/- Section 5.4 -/\n-- 1.\nexample {A : Type} (F : Set (Set A)) (B : Set A) :\n    smallestElt (sub A) B F \u2192 B = \u22c2\u2080 F := sorry\n\n-- 2.\ndef complement {A : Type} (B : Set A) : Set A := { a : A | a \u2209 B }\n\ntheorem Exercise_5_4_7 {A : Type} (f g : A \u2192 A) (C : Set A)\n    (h1 : f \u2218 g = id) (h2 : closed f C) : closed g (complement C) := sorry\n\n-- 3.\ntheorem Exercise_5_4_9a {A : Type} (f : A \u2192 A) (C1 C2 : Set A)\n    (h1 : closed f C1) (h2 : closed f C2) : closed f (C1 \u222a C2) := sorry\n\n-- 4.\ntheorem Exercise_5_4_10a {A : Type} (f : A \u2192 A) (B1 B2 C1 C2 : Set A)\n    (h1 : closure f B1 C1) (h2 : closure f B2 C2) :\n    B1 \u2286 B2 \u2192 C1 \u2286 C2 := sorry\n\n-- 5.\ntheorem Exercise_5_4_10b {A : Type} (f : A \u2192 A) (B1 B2 C1 C2 : Set A)\n    (h1 : closure f B1 C1) (h2 : closure f B2 C2) :\n    closure f (B1 \u222a B2) (C1 \u222a C2) := sorry\n\n-- 6.\ntheorem Theorem_5_4_9_ex {A : Type} (f : A \u2192 A \u2192 A) (B : Set A) :\n    \u2203 (C : Set A), closure2 f B C := sorry\n\n-- 7.\ntheorem Exercise_5_4_13a {A : Type} (F : Set (A \u2192 A)) (B : Set A) :\n    \u2203 (C : Set A), closure_family F B C := sorry\n\n/- Section 5.5 -/\n\n--Warning!  Not all of these examples are correct!\nexample {A B : Type} (f : A \u2192 B) (W X : Set A) :\n    image f (W \u222a X) = image f W \u222a image f X := sorry\n\nexample {A B : Type} (f : A \u2192 B) (W X : Set A) :\n    image f (W \\ X) = image f W \\ image f X := sorry\n\nexample {A B : Type} (f : A \u2192 B) (W X : Set A) :\n    W \u2286 X \u2194 image f W \u2286 image f X := sorry\n\nexample {A B : Type} (f : A \u2192 B) (Y Z : Set B) :\n    inverse_image f  (Y \u2229 Z) =\n        inverse_image f Y \u2229 inverse_image f Z := sorry\n\nexample {A B : Type} (f : A \u2192 B) (Y Z : Set B) :\n    inverse_image f  (Y \u222a Z) =\n        inverse_image f Y \u222a inverse_image f Z := sorry\n\nexample {A B : Type} (f : A \u2192 B) (Y Z : Set B) :\n    inverse_image f  (Y \\ Z) =\n        inverse_image f Y \\ inverse_image f Z := sorry\n\nexample {A B : Type} (f : A \u2192 B) (Y Z : Set B) :\n    Y \u2286 Z \u2194 inverse_image f Y \u2286 inverse_image f Z := sorry\n\nexample {A B : Type} (f : A \u2192 B) (X : Set A) :\n    inverse_image f (image f X) = X := sorry\n\nexample {A B : Type} (f : A \u2192 B) (Y : Set B) :\n    image f (inverse_image f Y) = Y := sorry\n\nexample {A : Type} (f : A \u2192 A) (C : Set A) :\n    closed f C \u2192 image f C \u2286 C := sorry\n\nexample {A : Type} (f : A \u2192 A) (C : Set A) :\n    image f C \u2286 C \u2192 C \u2286 inverse_image f C := sorry\n\nexample {A : Type} (f : A \u2192 A) (C : Set A) :\n    C \u2286 inverse_image f C \u2192 closed f C := sorry\n\nexample {A B : Type} (f : A \u2192 B) (g : B \u2192 A) (Y : Set B)\n    (h1 : f \u2218 g = id) (h2 : g \u2218 f = id) :\n    inverse_image f Y = image g Y := sorry", "meta": {"author": "djvelleman", "repo": "HTPILeanPackage", "sha": "b4a0ab0d0d5473ef27fbbbfba3f5d3208d5377da", "save_path": "github-repos/lean/djvelleman-HTPILeanPackage", "path": "github-repos/lean/djvelleman-HTPILeanPackage/HTPILeanPackage-b4a0ab0d0d5473ef27fbbbfba3f5d3208d5377da/Chap5Ex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.8152324915965391, "lm_q1q2_score": 0.7448587886958384}}
{"text": "/-\n1. Prove these equivalences:\n-/\n\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\n    iff.intro\n    (\n        assume h : \u2200 x, p x \u2227 q x,\n        show (\u2200 x, p x) \u2227 (\u2200 x, q x), from\n            and.intro\n            (\n                show \u2200 x, p x, from\n                    assume x,\n                    (h x).left\n            )\n            (\n                show \u2200 x, q x, from\n                    assume x,\n                    (h x).right\n            )\n    )\n    (\n        assume h : (\u2200 x, p x) \u2227 (\u2200 x, q x),\n        show \u2200 x, p x \u2227 q x, from\n            assume x,\n            and.intro (h.left x) (h.right x)\n    )\n-- short version\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\n    iff.intro\n    (\u03bb h, and.intro (\u03bb x, (h x).left) (\u03bb x, (h x).right))\n    (\u03bb h, \u03bb x, and.intro (h.left x) (h.right x))\n\n\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\n    assume h : \u2200 x, p x \u2192 q x,\n    assume g : \u2200 x, p x,\n    show \u2200 x, q x, from\n        assume x,\n        show q x, from (h x) (g x)\n-- short version\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\n    \u03bb h, \u03bb g, \u03bb x, (h x) (g x)\n\n\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\n    assume h : (\u2200 x, p x) \u2228 (\u2200 x, q x),\n    show \u2200 x, p x \u2228 q x, from\n        assume x,\n        h.elim\n        (\n            assume h1 : \u2200 x, p x,\n            show p x \u2228 q x, from\n                or.inl (h1 x)\n        )\n        (\n            assume h2 : \u2200 x, q x,\n            show p x \u2228 q x, from\n                or.inr (h2 x)\n        )\n-- short version\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\n    \u03bb h, \u03bb x, h.elim (\u03bb h1, or.inl (h1 x)) (\u03bb h2, or.inr (h2 x))\n", "meta": {"author": "ishioka0222", "repo": "theorem-proving-in-lean", "sha": "78884884cbf5b94fe2afb818e948b8168a53ea3d", "save_path": "github-repos/lean/ishioka0222-theorem-proving-in-lean", "path": "github-repos/lean/ishioka0222-theorem-proving-in-lean/theorem-proving-in-lean-78884884cbf5b94fe2afb818e948b8168a53ea3d/src/ch04-ex01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7448587884267801}}
{"text": "import algebra.big_operators algebra.group_power chris_hughes_various.zmod data.fintype data.nat.gcd M3P14.order_zmodn_kmb M3P14.Arithmetic_functions.mobius\n\nopen nat \nopen fintype\n\n--TODO: Add explicit formula for \u03c4 n \n-- make the non-computable definition of mobius function work\n-- add the mobius inversion formula\n\n-- arithmetic functions and their properties\n\ndef is_mult (f : \u2115 \u2192 \u2115) (m n : \u2115) (hp: gcd m n = 1) := f (m * n) = (f m) * (f n)\ndef is_strong_mult (f : \u2115 \u2192 \u2115) (m n : \u2115) := f (m * n) = (f m) * (f n)\ndef is_add (f : \u2115 \u2192 \u2124) (m n : \u2115) (hp: gcd m n = 1) := f (m + n) = (f m) + (f n)\ndef is_strong_add (f : \u2115 \u2192 \u2124) (m n : \u2115) := f (m + n) = (f m) + (f n)\n\n-- minor arithmetic functions that nobody cares about probably\n\n--liouville function\n\ndef liouville_function (n : \u2115) : int := (-1)^(primes_div_dup n) \nlocal notation `\u03b4` := liouville_function\n-- lambda was already taken up by lambda functions\ntheorem lio_strong_mul (n m : \u2115) : \u03b4 (m * n) = (\u03b4 m) * (\u03b4 n) := sorry \n\n--number of divisors\n\ndef number_of_divisors_function (n : \u2115) := n.factors.erase_dup.length\nlocal notation `\u03c4` := number_of_divisors_function\n\ntheorem tau_is_mul (n m : \u2115) (hp: gcd n m = 1) : \u03c4 (n*m) = (\u03c4 n) * (\u03c4 m) := sorry \n\n--theorem tau_formula (n \u03b1 : \u2115) \n    -- ((range n.succ).filter (\u2223 n))\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M3P14/Arithmetic_functions/arithmetic_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.744833910157398}}
{"text": "/-\nCopyright (c) 2021 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport data.mv_polynomial.cardinal\nimport data.mv_polynomial.equiv\n/-!\n# Cardinality of Polynomial Ring\n\nThe reuslt in this file is that the cardinality of `polynomial R` is at most the maximum\nof `#R` and `\u03c9`.\n-/\nuniverse u\n\nopen_locale cardinal polynomial\nopen cardinal\n\nnamespace polynomial\n\nlemma cardinal_mk_le_max {R : Type u} [comm_semiring R] : #R[X] \u2264 max (#R) \u03c9 :=\ncalc #R[X] = #(mv_polynomial punit.{u + 1} R) :\n  cardinal.eq.2 \u27e8(mv_polynomial.punit_alg_equiv.{u u} R).to_equiv.symm\u27e9\n... \u2264 _ : mv_polynomial.cardinal_mk_le_max\n... \u2264 _ : begin\n  have : #(punit.{u + 1}) \u2264 \u03c9, from le_of_lt (lt_omega_iff_fintype.2 \u27e8infer_instance\u27e9),\n  rw [max_assoc, max_eq_right this]\nend\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/polynomial/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.7448338895603945}}
{"text": "/-\n6. Give a calculational proof of the theorem log_mul below.\n-/\n\nimport algebra.ordered_ring\n\nvariables (real : Type) [ordered_ring real]\nvariables (log exp : real \u2192 real)\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\n  calc\n    log (x * y) = log (exp (log x) * y) : by rw exp_log_eq hx\n            ... = log (exp (log x) * exp (log y)) : by rw exp_log_eq hy\n            ... = log (exp ((log x) + (log y))) : by rw exp_add\n            ... = log x + log y : by rw log_exp_eq\n", "meta": {"author": "ishioka0222", "repo": "theorem-proving-in-lean", "sha": "78884884cbf5b94fe2afb818e948b8168a53ea3d", "save_path": "github-repos/lean/ishioka0222-theorem-proving-in-lean", "path": "github-repos/lean/ishioka0222-theorem-proving-in-lean/theorem-proving-in-lean-78884884cbf5b94fe2afb818e948b8168a53ea3d/src/ch04-ex06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248123094437, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7447461623601158}}
{"text": "-- 1\nexample : 0 \u2260 1 :=\nbegin\n  -- \u00ac (0 = 1)\n  -- (0 = 1) \u2192 false\n  assume h,\n  cases h,\nend\n\n\n-- 2\nexample : 0 \u2260 0 \u2192 2 = 3 :=\nbegin\n  assume h,\n  have f : false := h (eq.refl 0),\n  exact false.elim (f),\nend\n\n-- 3\nexample : \u2200 (P : Prop), P \u2192 \u00ac\u00acP :=\nbegin\n  assume P,\n  assume (p : P),\n  -- \u00ac\u00acP\n  -- \u00acP \u2192 false\n  -- (P \u2192 false) \u2192 false\n  assume h,\n  have f := h p,\n  exact f,\nend \n\n-- We might need classical (vs constructive) reasoning \n#check classical.em\nopen classical\n#check em\n\n/-\naxiom em : \u2200 (p : Prop), p \u2228 \u00acp\n\nThis is the famous and historically controversial\n\"law\" (now axiom) of the excluded middle. It's is\na key to proving many intuitive theorems in logic\nand mathematics. But it also leads to giving up on\nhaving evidence *why* something is either true or\nnot true, in that you no longer need a proof of \neither P or of \u00acP to have a proof of P \u2228 \u00acP.\n-/\n\n-- 4\ntheorem neg_elim : \u2200 (P : Prop), \u00ac\u00acP \u2192 P :=\nbegin\n  assume P,\n  assume h,\n  have pornp := classical.em P,\n  cases pornp with p pn,\n  assumption,\n  contradiction,\nend\n#check not.intro \n-- 5\n\ntheorem demorgan_1 : \u2200 (P Q : Prop), \u00ac (P \u2227 Q) \u2194 \u00ac P \u2228 \u00ac Q :=\nbegin\n  assume P Q,\n  apply iff.intro _ _,\n  --forward\n    intro h,\n    by_cases p : P,\n    right,\n    intro q,\n    have pnq : P \u2227 Q := and.intro p q,\n    apply h pnq,\n    left,\n    exact p,\n\n  --backward\n  assume npornq,\n  by_cases p : P,\n  by_cases q : Q,\n  apply not.intro,\n  assume pnq,\n  apply or.elim npornq,\n    assume np,\n    apply np p,\n      assume nq,\n      apply nq q,\n        apply not.intro,\n        assume pnq,\n        have q1 : Q := and.elim_right pnq,\n        apply q q1,\n          apply not.intro,\n          assume pnq,\n          have p1 : P := and.elim_left pnq,\n          apply p p1,\nend\n\n-- 6\ntheorem demorgan_2 : \u2200 (P Q : Prop), \u00ac (P \u2228 Q) \u2192 \u00acP \u2227 \u00acQ :=\nbegin\n  assume P Q,\n  intro h,\n  have pornp := classical.em P,\n  have qornq := classical.em Q,\n  cases pornp with p np,\n    -- p\n    have falso := h (or.intro_left _ p),\n    exact false.elim falso,\n    -- np\n    cases qornq with q nq,\n      -- q\n      have falso := h (or.intro_right _ q),\n      exact false.elim falso,\n      -- nq\n      exact and.intro np nq,\nend\n\n\n-- 7\ntheorem disappearing_opposite : \n  \u2200 (P Q : Prop), P \u2228 \u00acP \u2227 Q \u2194 P \u2228 Q := \nbegin\n  --forward\n  assume P Q,\n  apply iff.intro _ _,\n  assume p_or_npandq, \n  apply or.elim p_or_npandq,\n  assume p,\n  apply or.intro_left,\n  exact p,\n  assume npandq,\n  have q := and.elim_right npandq,\n  apply or.intro_right,\n  exact q,\n  --backward\n  assume porq,\n  apply or.elim porq,\n  assume p,\n\n  apply or.intro_left,\n  exact p,\n  /-assume q,\n  apply or.intro_right,\n  apply and.intro,-/\n  assume q,\n  have pornp := classical.em P,\n  apply or.elim pornp,\n  assume p,\n  apply or.intro_left,\n  exact p,\n  assume np,\n  apply or.intro_right,\n  apply and.intro np q,\n  \n\nend\n\n\n-- 8\ntheorem distrib_and_or : \n  \u2200 (P Q R: Prop), (P \u2228 Q) \u2227 (P \u2228 R) \u2194\n                    P \u2228 (Q \u2227 R) :=\nbegin\n  intros P Q R,\n  apply iff.intro _ _,\n  assume h,\n  have porq := h.left,\n  have porr := h.right,\n  cases porq with p q,\n    exact or.intro_left _ p,\n      cases porr with p r,\n        exact or.intro_left _ p,\n          exact or.intro_right _ (and.intro q r),\n  \n  assume h,\n  cases h with p qnr, \n    -- p\n    exact and.intro (or.intro_left _ p) (or.intro_left _ p),\n    -- qnr\n    have r := and.elim_right qnr,\n    have q := and.elim_left qnr,\n    exact and.intro (or.intro_right _ q) (or.intro_right _ r),\nend\n\n-- remember or is right associative\n-- you need this to know what the lefts and rights are\n-- 9\ntheorem distrib_and_or_foil : \n  \u2200 (P Q R S : Prop),\n  (P \u2228 Q) \u2227 (R \u2228 S) \u2194\n  (P \u2227 R) \u2228 (P \u2227 S) \u2228 (Q \u2227 R) \u2228 (Q \u2227 S) :=\nbegin\n  intros P Q R S,\n  apply iff.intro _ _,\n    --forward\n    assume h,\n    have rors := h.right,\n    have porq := h.left,\n    cases porq with p q,\n      -- p\n      cases rors with r s,\n        -- r within p\n        have j := and.intro p r,\n        exact or.intro_left _ j,\n        -- s within p\n        have pands := and.intro p s,\n        exact or.intro_right _ (or.intro_left _ pands),\n      -- q\n      cases rors with r s,\n        -- r within q\n        have qandr := and.intro q r,\n        exact or.intro_right _ (or.intro_right _ (or.intro_left _ qandr)),\n        -- s within q\n        have qands := and.intro q s,\n        have qandr_or_qands := or.intro_right _ qands,\n        exact or.intro_right _ (or.intro_right _ qandr_or_qands),\n    --backward\n    assume h,\n    cases h with i j,\n      -- case i (P \u2227 R)\n      have p := and.elim_left i,\n      have r := and.elim_right i,\n      have porq := or.intro_left _ p,\n      have rors := or.intro_left _ r,\n      exact and.intro porq rors,\n      -- case j ( P \u2227 S \u2228 Q \u2227 R \u2228 Q \u2227 S)\n      cases j with m n,\n      -- case m (P \u2227 S)\n        have p:= and.elim_left m,\n        have s := and.elim_right m,\n        have rors := or.intro_right _ s,\n        have porq := or.intro_left _ p,\n        exact and.intro porq rors,\n      -- case n (Q \u2227 R \u2228 Q \u2227 S)\n        cases n with a b,\n        -- case a (Q \u2227 R)\n          have q := and.elim_left a,\n          have r := and.elim_right a,\n          have porq := or.intro_right _ q,\n          have rors := or.intro_left _ r,\n          exact and.intro porq rors,\n        -- case b ( Q \u2227 S)\n          have q := and.elim_left b,\n          have s := and.elim_right b,\n          have porq := or.intro_right _ q,\n          have rors := or.intro_right _ s,\n          exact and.intro porq rors,\n\nend\n\n\n/- 10\nFormally state and prove the proposition that\nnot every natural number is equal to zero.\n-/\nlemma not_all_nats_are_zero : \u2200(n : \u2115), (n=0) \u2228 (n\u22600):=\nbegin\n  assume n,\n  apply classical.em,\nend \n\n-- 11. equivalence of P\u2192Q and (\u00acP\u2228Q)\nexample : \u2200 (P Q : Prop), (P \u2192 Q) \u2194 (\u00acP \u2228 Q) :=\nbegin\n  intros P Q,\n  apply iff.intro,\n  --forward\n    assume h,\n    have pornp := classical.em P,\n    cases pornp with p np,\n    --case p\n      have q := h p,\n      exact or.intro_right _ q,\n    -- case np\n      exact or.intro_left _ np,\n  --backward\n    assume h,\n    assume p,\n    cases h with np q,\n      -- case np\n      exact false.elim(np p),\n      --case q\n      exact q,\nend\n\n-- 12\nexample : \u2200 (P Q : Prop), (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  intros P Q,\n  assume pimpq,\n  assume nq,\n  apply not.intro,\n  assume p,\n  have q := pimpq p,\n  exact (nq q),\nend\n\n-- 13\nexample : \u2200 (P Q : Prop), ( \u00acP \u2192 \u00acQ) \u2192 (Q \u2192 P) :=\nbegin\n  intros P Q,\n  assume npimpnq,\n  assume q,\n  have pornp := classical.em P,\n  cases pornp with p np,\n  -- p\n    exact p,\n  -- np\n    have nq := npimpnq np,\n    have falso := nq q,\n    exact false.elim falso,\nend\n", "meta": {"author": "jakekauff", "repo": "DiscreteMath", "sha": "1ce98ac3fdb7b7fa880e595ac29f66a5098cfdba", "save_path": "github-repos/lean/jakekauff-DiscreteMath", "path": "github-repos/lean/jakekauff-DiscreteMath/DiscreteMath-1ce98ac3fdb7b7fa880e595ac29f66a5098cfdba/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942080055513, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7447316847650659}}
{"text": "/-\nCopyright (c) 2022 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\nimport analysis.normed.ring.seminorm\nimport analysis.special_functions.pow\n\n/-!\n# Seminorm related definitions\n## Tags\nring_norm, equivalent\n-/\n\n/-- A function `f : \u03b1 \u2192 \u03b2` is nonarchimedean if it satisfies the inequality\n  `f (a + b) \u2264 max (f a) (f b)` for all `a, b \u2208 \u03b1`. -/\ndef is_nonarchimedean {\u03b1 : Type*} [has_add \u03b1] {\u03b2 : Type*} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 r s, f (r + s) \u2264 max (f r) (f s)\n\nlemma is_nonarchimedean_def {\u03b1 : Type*} [has_add \u03b1] {\u03b2 : Type*} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) :\nis_nonarchimedean f \u2194 \u2200 r s, f (r + s) \u2264 max (f r) (f s) := iff.rfl\n\n/-- A function `f : \u03b1 \u2192 \u03b2` is `multiplicative` if it satisfies the equality\n  `f (a * b) = (f a) * (f b)` for all `a, b \u2208 \u03b1`. -/\ndef mul_eq {\u03b1 : Type*} [has_mul \u03b1] {\u03b2 : Type*} [has_mul \u03b2] [has_le \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 r s, f (r * s) = (f r) * (f s)\n\nlemma mul_eq_def {\u03b1 : Type*} [has_mul \u03b1] {\u03b2 : Type*} [has_mul \u03b2] [has_le \u03b2] (f : \u03b1 \u2192 \u03b2) :\nmul_eq f \u2194 \u2200 r s, f (r * s) = (f r) * (f s) := iff.rfl\n\nnamespace mul_ring_norm\n\n/-- Two multiplicative ring norms `f, g` on `R` are equivalent if there exists a positive constant\n  `c` such that for all `x \u2208 R`, `(f x)^c = g x`.\n  This could be generalised to ring_norm, but mul_ring_norm does not extend this. -/\ndef equiv {R : Type*} [ring R] (f : mul_ring_norm R) (g : mul_ring_norm R) :=\n  \u2203 c : \u211d, 0 < c \u2227 (\u03bb x : R, (f x) ^ c) = g\n\nlemma equiv_refl {R : Type*} [ring R] (f : mul_ring_norm R) :\n  equiv f f := by refine \u27e81, by linarith, by simp only [real.rpow_one]\u27e9\n\nlemma equiv_symm {R : Type*} [ring R] (f g : mul_ring_norm R) (hfg : equiv f g) :\n  equiv g f :=\nbegin\n  rcases hfg with \u27e8c, hfg1, hfg2\u27e9,\n  refine \u27e81 / c, by simp only [hfg1, one_div, inv_pos], _\u27e9,\n  rw \u2190 hfg2,\n  ext,\n  simp only [one_div],\n  have h1 : c \u2260 0 := by linarith,\n  rw \u2190 real.rpow_mul (map_nonneg f x),\n  simp only [h1, mul_inv_cancel, ne.def, not_false_iff, real.rpow_one],\nend\n\nlemma equiv_trans {R : Type*} [ring R] (f g k : mul_ring_norm R) (hfg : equiv f g) (hgk : equiv g k) :\n  equiv f k :=\nbegin\n  rcases hfg with \u27e8c, hfg1, hfg2\u27e9,\n  rcases hgk with \u27e8d, hgk1, hgk2\u27e9,\n  refine \u27e8c * d, by simp only [hfg1, hgk1, zero_lt_mul_right], _\u27e9,\n  rw \u2190 hgk2,\n  rw \u2190 hfg2,\n  ext,\n  exact real.rpow_mul (map_nonneg f x) c d,\nend\n\nend mul_ring_norm", "meta": {"author": "mariainesdff", "repo": "ostrowski", "sha": "b29d8bd9d98923ec2fab923cb67c76a54aa70386", "save_path": "github-repos/lean/mariainesdff-ostrowski", "path": "github-repos/lean/mariainesdff-ostrowski/ostrowski-b29d8bd9d98923ec2fab923cb67c76a54aa70386/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005327, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.744731677649506}}
{"text": "-- La_composicion_por_la_izquierda_con_una_inyectiva_es_inyectiva.lean\n-- La composici\u00f3n por la izquierda con una inyectiva es una operaci\u00f3n inyectiva\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 11 de agosto de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Sean f\u2081 y f\u2082 funciones de X en Y y g una funci\u00f3n de X en Y. Demostrar\n-- que si g es inyectiva y g \u2218 f\u2081 = g \u2218 f\u2082, entonces f\u2081 = f\u2082.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\nvariables {X Y Z : Type*}\nvariables {f\u2081 f\u2082 : X \u2192 Y}\nvariable  {g : Y \u2192 Z}\n\nexample\n  (hg : function.injective g)\n  (hgf : g \u2218 f\u2081 = g \u2218 f\u2082)\n  : f\u2081 = f\u2082 :=\nbegin\n  funext,\n  apply hg,\n  calc g (f\u2081 x)\n       = (g \u2218 f\u2081) x : rfl\n   ... = (g \u2218 f\u2082) x : congr_fun hgf x\n   ... = g (f\u2082 x)   : rfl,\nend\n\nexample\n  (hg : function.injective g)\n  (hgf : g \u2218 f\u2081 = g \u2218 f\u2082)\n  : f\u2081 = f\u2082 :=\nbegin\n  funext,\n  apply hg,\n  exact congr_fun hgf x,\nend\n\nlemma function.injective.comp_left'\n  (hg : function.injective g)\n  (hgf : g \u2218 f\u2081 = g \u2218 f\u2082)\n  : f\u2081 = f\u2082 :=\nbegin\n  refine funext (\u03bb i, hg _),\n  exact congr_fun hgf i,\nend\n\nlemma function.injective.comp_left2\n  (hg : function.injective g)\n  : function.injective ((\u2218) g : (X \u2192 Y) \u2192 (X \u2192 Z)) :=\n\u03bb f\u2081 f\u2082 hgf, funext $ \u03bb i, hg (congr_fun hgf i : _)\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/La_composicion_por_la_izquierda_con_una_inyectiva_es_inyectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7446765557356629}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level4 -- add_comm\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Inequality world.\n\n## Level 1: the [`use` tactic](../Tactics/use.lean.md)\n\nThe goal below is to prove `x \u2264 1+x` for any natural number `x`.\nFirst let's turn the goal explicitly into an existence problem with\n\n`rw [le_iff_exists_add]`\n\nand now the goal has become `\u2203 c : MyNat, 1 + x = x + c`. Clearly\nthis statement is true, and the proof is that `c=1` will work (we also\nneed the fact that addition is commutative, but we proved that a long\ntime ago). How do we make progress with this goal?\n\nThe `use` tactic can be used on goals of the form `\u2203 c, ...`. The idea\nis that we choose which natural number we want to use, and then we use it.\nSo try\n\n`use 1`\n\nand now the goal becomes `\u22a2 1 + x = x + 1`. You can solve this by\n`exact add_comm 1 x`, or if you are lazy you can just use the `ring` tactic,\nwhich is a powerful AI which will solve any equality in algebra which can\nbe proved using the standard rules of addition and multiplication. Now\nlook at your proof. We're going to remove a line.\n\n## Important\n\nAn important time-saver here is to note that because `a \u2264 b` is *defined*\nas `\u2203 c : MyNat, b = a + c`, you *do not need to write* `rw [le_iff_exists_add]`.\nThe `use` tactic will work directly on a goal of the form `a \u2264 b`. Just\nuse the difference `b - a` (note that we have not defined subtraction so\nthis does not formally make sense, but you can do the calculation in your head).\nIf you have written `rw [le_iff_exists_add]` below, then just put two minus signs `--`\nbefore it and comment it out. See that the proof still compiles.\n\n## Lemma : one_add_le_self\nIf `x` is a natural number, then `x \u2264 1+x`.\n-/\nlemma one_add_le_self (x : MyNat) : x \u2264 1 + x := by\n  rw [le_iff_exists_add]\n  use 1\n  rw [add_comm]\n\n/-!\n\n\nNext up [Level 2](./Level2.lean.md)\n\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7446765487629567}}
{"text": "--------------------------------------------------------------------------------\n-- File     : PUZ131_1 : TPTP v7.3.0. Released v5.0.0.\n-- Domain   : Puzzles\n-- Problem  : Victor teaches Michael\n-- Version  : Especial.\n-- English  : Every student is enrolled in at least one course. Every professor\n--            teaches at least one course. Every course has at least one student\n--            enrolled. Every course has at least one professor teaching. The\n--            coordinator of a course teaches the course. If a student is\n--            enroled in a course then the student is taught by every professor\n--            who teaches the course. Michael is enrolled in CSC410. Victor is\n--            the coordinator of CSC410. Therefore, Michael is taught by Victor.\n\n-- Source   : [TPTP]\n--------------------------------------------------------------------------------\n\nvariable student : Type\nvariable professor : Type\nvariable course : Type\nvariable michael : student\nvariable victor : professor\nvariable csc410 : course\nvariable enrolled : student \u00d7 course \u2192 Prop\nvariable teaches : professor \u00d7 course \u2192 Prop\nvariable taughtby : student \u00d7 professor \u2192 Prop\nvariable coordinatorof : course \u2192 professor\n\n-- axioms\nvariable student_enrolled_axiom :\n  \u2200 X : student,\n  \u2203 Y : course,\n  enrolled (X, Y)\n\nvariable professor_teaches :\n  \u2200 X: professor,\n  \u2203 Y: course,\n  teaches (X, Y)\n\nvariable course_enrolled :\n  \u2200 X: course,\n  \u2203 Y: student,\n  enrolled(Y,X)\n\nvariable course_teaches :\n  \u2200 X : course,\n  \u2203 Y : professor,\n  teaches(Y,X)\n\nvariable coordinator_teaches :\n  \u2200 X : course,\n  teaches(coordinatorof(X),X)\n\nvariable student_enrolled_taught :\n  \u2200 (X: student)(Y: course),\n  (enrolled(X,Y) \u2192\n  \u2200 (Z: professor), (teaches(Z,Y) \u2192 taughtby(X,Z)))\n\nvariable michael_enrolled_csc410_axiom:\n  enrolled(michael,csc410)\n\nvariable victor_coordinator_csc410_axiom:\n  coordinatorof(csc410) = victor\n\n-- conjecture : teaching_conjecture\ninclude coordinatorof\ninclude coordinator_teaches\ninclude victor_coordinator_csc410_axiom\ninclude student_enrolled_taught\ninclude michael_enrolled_csc410_axiom\n\ntheorem teaching_conjecture : taughtby(michael,victor) :=\n  have victor_teaches_csc410 : teaches(victor, csc410) :=\n    begin\n        have coordinator_teaches_csc410 : teaches(_,csc410),\n        from coordinator_teaches csc410,\n        rw victor_coordinator_csc410_axiom at coordinator_teaches_csc410,\n        assumption\n    end,\n  begin\n    have michael_taught,\n    from student_enrolled_taught _ _ michael_enrolled_csc410_axiom,\n    exact michael_taught _ victor_teaches_csc410\n  end\n", "meta": {"author": "own-pt", "repo": "common-sense-lean", "sha": "f672210aecb4172f5bae265e43e6867397e13b1c", "save_path": "github-repos/lean/own-pt-common-sense-lean", "path": "github-repos/lean/own-pt-common-sense-lean/common-sense-lean-f672210aecb4172f5bae265e43e6867397e13b1c/tptp-lean-puzzles/resolutions-lean/PUZ131_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7446765470526345}}
{"text": "import betweenness_world.level02 --hide\nopen IncidencePlane --hide\n\n\n/-\n# Betweenness World\n\n## Level 3: proof, proof, proof!\n\nTo solve this level, the mathematical proof in paper will be given to you. Remember that you can use theorem statements from previous worlds.\n\n**Claim:** A point that lies between two different collinear points shares the same line with them.\n\n**Proof:** Let B be the point that lies between A and B, where these two are different collinear points that lie on the line `r`.\n\n**(i)** Let us assume that there exists a line \u2113 such that A \u2208 \u2113 \u2227 B \u2208 \u2113 \u2227 C \u2208 \u2113. By the first axiom of order `collinear_of_between`, since A * B * C,  \nwe prove that there exists a line \u2113 such that A \u2208 \u2113 \u2227 B \u2208 \u2113 \u2227 C \u2208 \u2113. Let this line be called `s`. Then, A \u2208 s \u2227 B \u2208 s \u2227 C \u2208 s.\n\n**(ii)** Let us assume that A \u2260 C. By contradiction, if A = C, then A * B * C would be equal to C * B * C. By the lemma `no_point_between_a_point`, this is \nnot possible, so we prove that A \u2260 C.\n\n**(iii)** Let us assume that r = s. By the lemma `equal_lines_of_contain_two_points`, since A \u2260 C, A \u2208 r, A \u2208 s, C \u2208 r and C \u2208 s, then we prove that\nr = s. Because r = s, then B \u2208 s, which we proved in **(i)**, must be equivalent to B \u2208 r. Therefore, the point B shares the same line `r` with the points\nA and C and satisfies that A * B * C.\n\nHence, we have shown that a point that lies between two different collinear points shares the same line with them.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nWhenever we have a hypothesis of the form `h : P \u2227 Q \u2227 R`, we write `h.1` to refer to `P` and we type `h.2` to refer to `Q \u2227 R`. If we want to refer to just \n`Q`, we need to write `h.2.1`. Analogously, if we want to refer to just `R`, then we type `h.2.2`. \n\nIn case you don't know how to use the lemma `no_point_between_a_point`, look how you proved it in the previous level, so that you can adapt that code\nfor this one.\n\nStill bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B C P Q R : \u03a9} --hide\nvariables {\u2113 r s t : Line \u03a9} --hide\n\n/- Lemma :\nA point that lies between two different collinear points shares the same line with them.\n-/\nlemma between_points_share_line (hAr : A \u2208 r) (hCr : C \u2208 r) : \n\t(A * B * C) \u2192 B \u2208 r :=\nbegin\n    intro H,\n\thave h : \u2203 \u2113, A \u2208 \u2113 \u2227 B \u2208 \u2113 \u2227 C \u2208 \u2113,\n    apply collinear_of_between,\n    exact H,\n    cases h with s h1,\n    have hAC : A \u2260 C,\n    {\n      intro hAC,\n      rw hAC at H,\n      have hCBC : C \u2260 B \u2227 C \u2260 C \u2227 B \u2260 C,\n      apply different_of_between,\n      exact H,\n      cases hCBC with hCB hCC,\n      cases hCC with hC hBC,\n      apply hC,\n      refl,\n    },\n    have hrs : r = s,\n    exact equal_lines_of_contain_two_points hAC hAr h1.1 hCr h1.2.2,\n    rw \u2190 hrs at h1,\n    exact h1.2.1,\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/betweenness_world/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7446755646583868}}
{"text": "/-\nCopyright (c) 2021 Gabriel Moise. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gabriel Moise, Ya\u00ebl Dillies, Kyle Miller\n-/\nimport combinatorics.simple_graph.basic\nimport data.matrix.basic\n\n/-!\n# Incidence matrix of a simple graph\n\nThis file defines the unoriented incidence matrix of a simple graph.\n\n## Main definitions\n\n* `simple_graph.inc_matrix`: `G.inc_matrix R` is the incidence matrix of `G` over the ring `R`.\n\n## Main results\n\n* `simple_graph.inc_matrix_mul_transpose_diag`: The diagonal entries of the product of\n  `G.inc_matrix R` and its transpose are the degrees of the vertices.\n* `simple_graph.inc_matrix_mul_transpose`: Gives a complete description of the product of\n  `G.inc_matrix R` and its transpose; the diagonal is the degrees of each vertex, and the\n  off-diagonals are 1 or 0 depending on whether or not the vertices are adjacent.\n* `simple_graph.inc_matrix_transpose_mul_diag`: The diagonal entries of the product of the\n  transpose of `G.inc_matrix R` and `G.inc_matrix R` are `2` or `0` depending on whether or\n  not the unordered pair is an edge of `G`.\n\n## Implementation notes\n\nThe usual definition of an incidence matrix has one row per vertex and one column per edge.\nHowever, this definition has columns indexed by all of `sym2 \u03b1`, where `\u03b1` is the vertex type.\nThis appears not to change the theory, and for simple graphs it has the nice effect that every\nincidence matrix for each `simple_graph \u03b1` has the same type.\n\n## TODO\n\n* Define the oriented incidence matrices for oriented graphs.\n* Define the graph Laplacian of a simple graph using the oriented incidence matrix from an\n  arbitrary orientation of a simple graph.\n-/\n\nnoncomputable theory\n\nopen finset matrix simple_graph sym2\nopen_locale big_operators matrix\n\nnamespace simple_graph\nvariables (R : Type*) {\u03b1 : Type*} (G : simple_graph \u03b1)\n\n/-- `G.inc_matrix R` is the `\u03b1 \u00d7 sym2 \u03b1` matrix whose `(a, e)`-entry is `1` if `e` is incident to\n`a` and `0` otherwise. -/\ndef inc_matrix [has_zero R] [has_one R] : matrix \u03b1 (sym2 \u03b1) R :=\n\u03bb a, (G.incidence_set a).indicator 1\n\nvariables {R}\n\nlemma inc_matrix_apply [has_zero R] [has_one R] {a : \u03b1} {e : sym2 \u03b1} :\n  G.inc_matrix R a e = (G.incidence_set a).indicator 1 e := rfl\n\n/-- Entries of the incidence matrix can be computed given additional decidable instances. -/\nlemma inc_matrix_apply' [has_zero R] [has_one R] [decidable_eq \u03b1] [decidable_rel G.adj]\n  {a : \u03b1} {e : sym2 \u03b1} :\n  G.inc_matrix R a e = if e \u2208 G.incidence_set a then 1 else 0 :=\nby convert rfl\n\nsection mul_zero_one_class\nvariables [mul_zero_one_class R] {a b : \u03b1} {e : sym2 \u03b1}\n\nlemma inc_matrix_apply_mul_inc_matrix_apply :\n  G.inc_matrix R a e * G.inc_matrix R b e = (G.incidence_set a \u2229 G.incidence_set b).indicator 1 e :=\nbegin\n  simp only [inc_matrix, set.indicator_apply, \u2190ite_and_mul_zero,\n    pi.one_apply, mul_one, set.mem_inter_eq],\n  congr,\nend\n\nlemma inc_matrix_apply_mul_inc_matrix_apply_of_not_adj (hab : a \u2260 b) (h : \u00ac G.adj a b) :\n  G.inc_matrix R a e * G.inc_matrix R b e = 0 :=\nbegin\n  rw [inc_matrix_apply_mul_inc_matrix_apply, set.indicator_of_not_mem],\n  rw [G.incidence_set_inter_incidence_set_of_not_adj h hab],\n  exact set.not_mem_empty e,\nend\n\nlemma inc_matrix_of_not_mem_incidence_set (h : e \u2209 G.incidence_set a) :\n  G.inc_matrix R a e = 0 :=\nby rw [inc_matrix_apply, set.indicator_of_not_mem h]\n\nlemma inc_matrix_of_mem_incidence_set (h : e \u2208 G.incidence_set a) : G.inc_matrix R a e = 1 :=\nby rw [inc_matrix_apply, set.indicator_of_mem h, pi.one_apply]\n\nvariables [nontrivial R]\n\nlemma inc_matrix_apply_eq_zero_iff : G.inc_matrix R a e = 0 \u2194 e \u2209 G.incidence_set a :=\nbegin\n  simp only [inc_matrix_apply, set.indicator_apply_eq_zero, pi.one_apply, one_ne_zero],\n  exact iff.rfl,\nend\n\nlemma inc_matrix_apply_eq_one_iff : G.inc_matrix R a e = 1 \u2194 e \u2208 G.incidence_set a :=\nby { convert one_ne_zero.ite_eq_left_iff, assumption }\n\nend mul_zero_one_class\n\nsection non_assoc_semiring\nvariables [fintype \u03b1] [non_assoc_semiring R] {a b : \u03b1} {e : sym2 \u03b1}\n\nlemma sum_inc_matrix_apply [decidable_eq \u03b1] [decidable_rel G.adj] :\n  \u2211 e, G.inc_matrix R a e = G.degree a :=\nby simp [inc_matrix_apply', sum_boole, set.filter_mem_univ_eq_to_finset]\n\nlemma inc_matrix_mul_transpose_diag [decidable_eq \u03b1] [decidable_rel G.adj] :\n  (G.inc_matrix R \u2b1d (G.inc_matrix R)\u1d40) a a = G.degree a :=\nbegin\n  rw \u2190sum_inc_matrix_apply,\n  simp [matrix.mul_apply, inc_matrix_apply', \u2190ite_and_mul_zero],\nend\n\nlemma sum_inc_matrix_apply_of_mem_edge_set : e \u2208 G.edge_set \u2192 \u2211 a, G.inc_matrix R a e = 2 :=\nbegin\n  classical,\n  refine e.ind _,\n  intros a b h,\n  rw mem_edge_set at h,\n  rw [\u2190nat.cast_two, \u2190card_doubleton h.ne],\n  simp only [inc_matrix_apply', sum_boole, mk_mem_incidence_set_iff, h, true_and],\n  congr' 2,\n  ext e,\n  simp only [mem_filter, mem_univ, true_and, mem_insert, mem_singleton],\nend\n\nlemma sum_inc_matrix_apply_of_not_mem_edge_set (h : e \u2209 G.edge_set) : \u2211 a, G.inc_matrix R a e = 0 :=\nsum_eq_zero $ \u03bb a _, G.inc_matrix_of_not_mem_incidence_set $ \u03bb he, h he.1\n\nlemma inc_matrix_transpose_mul_diag [decidable_rel G.adj] :\n  ((G.inc_matrix R)\u1d40 \u2b1d G.inc_matrix R) e e = if e \u2208 G.edge_set then 2 else 0 :=\nbegin\n  classical,\n  simp only [matrix.mul_apply, inc_matrix_apply', transpose_apply, \u2190ite_and_mul_zero,\n    one_mul, sum_boole, and_self],\n  split_ifs with h,\n  { revert h,\n    refine e.ind _,\n    intros v w h,\n    rw [\u2190nat.cast_two, \u2190card_doubleton (G.ne_of_adj h)],\n    simp [mk_mem_incidence_set_iff, G.mem_edge_set.mp h],\n    congr' 2,\n    ext u,\n    simp, },\n  { revert h,\n    refine e.ind _,\n    intros v w h,\n    simp [mk_mem_incidence_set_iff, G.mem_edge_set.not.mp h], },\nend\n\nend non_assoc_semiring\n\nsection semiring\nvariables [fintype (sym2 \u03b1)] [semiring R] {a b : \u03b1} {e : sym2 \u03b1}\n\nlemma inc_matrix_mul_transpose_apply_of_adj (h : G.adj a b) :\n  (G.inc_matrix R \u2b1d (G.inc_matrix R)\u1d40) a b = (1 : R) :=\nbegin\n  simp_rw [matrix.mul_apply, matrix.transpose_apply, inc_matrix_apply_mul_inc_matrix_apply,\n    set.indicator_apply, pi.one_apply, sum_boole],\n  convert nat.cast_one,\n  convert card_singleton \u27e6(a, b)\u27e7,\n  rw [\u2190coe_eq_singleton, coe_filter_univ],\n  exact G.incidence_set_inter_incidence_set_of_adj h,\nend\n\nlemma inc_matrix_mul_transpose [fintype \u03b1] [decidable_eq \u03b1] [decidable_rel G.adj] :\n  G.inc_matrix R \u2b1d (G.inc_matrix R)\u1d40 = \u03bb a b,\n    if a = b then G.degree a else if G.adj a b then 1 else 0 :=\nbegin\n  ext a b,\n  split_ifs with h h',\n  { subst b,\n    convert G.inc_matrix_mul_transpose_diag },\n  { exact G.inc_matrix_mul_transpose_apply_of_adj h' },\n  { simp only [matrix.mul_apply, matrix.transpose_apply,\n    G.inc_matrix_apply_mul_inc_matrix_apply_of_not_adj h h', sum_const_zero] }\nend\n\nend semiring\nend simple_graph\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/combinatorics/simple_graph/inc_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7446755642289086}}
{"text": "import game.sup_inf.supProdSets\n\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 11\n-/\n\ndef embedded_rationals : set \u211d := {x : \u211d | \u2203 y : \u211a, x = \u2191y}\n\n/- Lemma\nThe set of rational numbers does not have a supremum\n-/\nlemma not_lub_rationals : \u2200 b : \u211d, \u00ac (is_lub (embedded_rationals) b) :=\nbegin\nintros b Hlub,\nhave Hbub : b \u2208 upper_bounds embedded_rationals := Hlub.left,\nhave H : b < (b+1) := calc b = b+0 : (add_zero _).symm\n                         ... < b+1 : add_lt_add_left zero_lt_one _,\ncases (exists_rat_btwn H) with q Hq,\nhave Hqin : \u2191q \u2208 embedded_rationals := \u27e8q,rfl\u27e9,\nhave Hwrong2 := Hbub Hqin,\nexact not_lt.2 Hwrong2 (Hq.left),\nend\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sup_inf/lub_rationals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7446755607200787}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport algebra.order.field.basic\nimport algebra.order.field.canonical.defs\nimport algebra.order.field.inj_surj\nimport algebra.order.nonneg.ring\n\n/-!\n# Semifield structure on the type of nonnegative elements\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines instances and prove some properties about the nonnegative elements\n`{x : \u03b1 // 0 \u2264 x}` of an arbitrary type `\u03b1`.\n\nThis is used to derive algebraic structures on `\u211d\u22650` and `\u211a\u22650` automatically.\n\n## Main declarations\n\n* `{x : \u03b1 // 0 \u2264 x}` is a `canonically_linear_ordered_semifield` if `\u03b1` is a `linear_ordered_field`.\n-/\n\nopen set\n\nvariables {\u03b1 : Type*}\n\nnamespace nonneg\n\nsection linear_ordered_semifield\nvariables [linear_ordered_semifield \u03b1] {x y : \u03b1}\n\ninstance has_inv : has_inv {x : \u03b1 // 0 \u2264 x} := \u27e8\u03bb x, \u27e8x\u207b\u00b9, inv_nonneg.2 x.2\u27e9\u27e9\n\n@[simp, norm_cast]\nprotected lemma coe_inv (a : {x : \u03b1 // 0 \u2264 x}) : ((a\u207b\u00b9 : {x : \u03b1 // 0 \u2264 x}) : \u03b1) = a\u207b\u00b9 := rfl\n\n@[simp] \n\ninstance has_div : has_div {x : \u03b1 // 0 \u2264 x} := \u27e8\u03bb x y, \u27e8x / y, div_nonneg x.2 y.2\u27e9\u27e9\n\n@[simp, norm_cast] protected lemma coe_div (a b : {x : \u03b1 // 0 \u2264 x}) :\n  ((a / b : {x : \u03b1 // 0 \u2264 x}) : \u03b1) = a / b := rfl\n\n@[simp] lemma mk_div_mk (hx : 0 \u2264 x) (hy : 0 \u2264 y) :\n  (\u27e8x, hx\u27e9 : {x : \u03b1 // 0 \u2264 x}) / \u27e8y, hy\u27e9 = \u27e8x / y, div_nonneg hx hy\u27e9 := rfl\n\ninstance has_zpow : has_pow {x : \u03b1 // 0 \u2264 x} \u2124 := \u27e8\u03bb a n, \u27e8a ^ n, zpow_nonneg a.2 _\u27e9\u27e9\n\n@[simp, norm_cast] protected lemma coe_zpow (a : {x : \u03b1 // 0 \u2264 x}) (n : \u2124) :\n  ((a ^ n : {x : \u03b1 // 0 \u2264 x}) : \u03b1) = a ^ n := rfl\n\n@[simp] lemma mk_zpow (hx : 0 \u2264 x) (n : \u2124) :\n  (\u27e8x, hx\u27e9 : {x : \u03b1 // 0 \u2264 x}) ^ n = \u27e8x ^ n, zpow_nonneg hx n\u27e9 := rfl\n\ninstance linear_ordered_semifield : linear_ordered_semifield {x : \u03b1 // 0 \u2264 x} :=\nsubtype.coe_injective.linear_ordered_semifield _ nonneg.coe_zero nonneg.coe_one nonneg.coe_add\n    nonneg.coe_mul nonneg.coe_inv nonneg.coe_div (\u03bb _ _, rfl) nonneg.coe_pow nonneg.coe_zpow\n    nonneg.coe_nat_cast (\u03bb _ _, rfl) (\u03bb _ _, rfl)\n\nend linear_ordered_semifield\n\ninstance canonically_linear_ordered_semifield [linear_ordered_field \u03b1] :\n  canonically_linear_ordered_semifield {x : \u03b1 // 0 \u2264 x} :=\n{ ..nonneg.linear_ordered_semifield, ..nonneg.canonically_ordered_comm_semiring }\n\ninstance linear_ordered_comm_group_with_zero [linear_ordered_field \u03b1] :\n  linear_ordered_comm_group_with_zero {x : \u03b1 // 0 \u2264 x} :=\ninfer_instance\n\nend nonneg\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/nonneg/field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7446755565670315}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport data.finset.card\nimport data.multiset.nat_antidiagonal\n\n/-!\n# Antidiagonals in \u2115 \u00d7 \u2115 as finsets\n\nThis file defines the antidiagonals of \u2115 \u00d7 \u2115 as finsets: the `n`-th antidiagonal is the finset of\npairs `(i, j)` such that `i + j = n`. This is useful for polynomial multiplication and more\ngenerally for sums going from `0` to `n`.\n\n## Notes\n\nThis refines files `data.list.nat_antidiagonal` and `data.multiset.nat_antidiagonal`.\n-/\n\nnamespace finset\nnamespace nat\n\n/-- The antidiagonal of a natural number `n` is\n    the finset of pairs `(i, j)` such that `i + j = n`. -/\ndef antidiagonal (n : \u2115) : finset (\u2115 \u00d7 \u2115) :=\n\u27e8multiset.nat.antidiagonal n, multiset.nat.nodup_antidiagonal n\u27e9\n\n/-- A pair (i, j) is contained in the antidiagonal of `n` if and only if `i + j = n`. -/\n@[simp] lemma mem_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} :\n  x \u2208 antidiagonal n \u2194 x.1 + x.2 = n :=\nby rw [antidiagonal, mem_def, multiset.nat.mem_antidiagonal]\n\n/-- The cardinality of the antidiagonal of `n` is `n + 1`. -/\n@[simp] lemma card_antidiagonal (n : \u2115) : (antidiagonal n).card = n+1 :=\nby simp [antidiagonal]\n\n/-- The antidiagonal of `0` is the list `[(0, 0)]` -/\n@[simp] lemma antidiagonal_zero : antidiagonal 0 = {(0, 0)} :=\nrfl\n\nlemma antidiagonal_succ (n : \u2115) :\n  antidiagonal (n + 1) = cons (0, n + 1) ((antidiagonal n).map\n  (function.embedding.prod_map \u27e8nat.succ, nat.succ_injective\u27e9 (function.embedding.refl _)))\n  (by simp) :=\nbegin\n  apply eq_of_veq,\n  rw [cons_val, map_val],\n  { apply multiset.nat.antidiagonal_succ },\nend\n\nlemma antidiagonal_succ' (n : \u2115) :\n  antidiagonal (n + 1) = cons (n + 1, 0) ((antidiagonal n).map\n  (function.embedding.prod_map (function.embedding.refl _) \u27e8nat.succ, nat.succ_injective\u27e9))\n  (by simp) :=\nbegin\n  apply eq_of_veq,\n  rw [cons_val, map_val],\n  exact multiset.nat.antidiagonal_succ',\nend\n\nlemma antidiagonal_succ_succ' {n : \u2115} :\n  antidiagonal (n + 2) =\n    cons (0, n + 2)\n      (cons (n + 2, 0) ((antidiagonal n).map\n        (function.embedding.prod_map \u27e8nat.succ, nat.succ_injective\u27e9 \u27e8nat.succ, nat.succ_injective\u27e9))\n        $ by simp) (by simp) :=\nby { simp_rw [antidiagonal_succ (n + 1), antidiagonal_succ', finset.map_cons, map_map], refl }\n\nlemma map_swap_antidiagonal {n : \u2115} :\n  (antidiagonal n).map \u27e8prod.swap, prod.swap_right_inverse.injective\u27e9 = antidiagonal n :=\neq_of_veq $ by simp [antidiagonal, multiset.nat.map_swap_antidiagonal]\n\n/-- A point in the antidiagonal is determined by its first co-ordinate. -/\nlemma antidiagonal_congr {n : \u2115} {p q : \u2115 \u00d7 \u2115} (hp : p \u2208 antidiagonal n)\n  (hq : q \u2208 antidiagonal n) : p = q \u2194 p.fst = q.fst :=\nbegin\n  refine \u27e8congr_arg prod.fst, (\u03bb h, prod.ext h ((add_right_inj q.fst).mp _))\u27e9,\n  rw mem_antidiagonal at hp hq,\n  rw [hq, \u2190 h, hp],\nend\n\nlemma antidiagonal.fst_le {n : \u2115} {kl : \u2115 \u00d7 \u2115} (hlk : kl \u2208 antidiagonal n) :\n  kl.1 \u2264 n :=\nbegin\n  rw le_iff_exists_add,\n  use kl.2,\n  rwa [mem_antidiagonal, eq_comm] at hlk\nend\n\nlemma antidiagonal.snd_le {n : \u2115} {kl : \u2115 \u00d7 \u2115} (hlk : kl \u2208 antidiagonal n) :\n  kl.2 \u2264 n :=\nbegin\n  rw le_iff_exists_add,\n  use kl.1,\n  rwa [mem_antidiagonal, eq_comm, add_comm] at hlk\nend\n\nlemma filter_fst_eq_antidiagonal (n m : \u2115) :\n  filter (\u03bb x : \u2115 \u00d7 \u2115, x.fst = m) (antidiagonal n) = if m \u2264 n then {(m, n - m)} else \u2205 :=\nbegin\n  ext \u27e8x, y\u27e9,\n  simp only [mem_filter, nat.mem_antidiagonal],\n  split_ifs with h h,\n  { simp [and_comm, eq_tsub_iff_add_eq_of_le h, add_comm] {contextual := tt} },\n  { rw not_le at h,\n    simp only [not_mem_empty, iff_false, not_and],\n    exact \u03bb hn, ne_of_lt (lt_of_le_of_lt (le_self_add.trans hn.le) h) }\nend\n\nlemma filter_snd_eq_antidiagonal (n m : \u2115) :\n  filter (\u03bb x : \u2115 \u00d7 \u2115, x.snd = m) (antidiagonal n) = if m \u2264 n then {(n - m, m)} else \u2205 :=\nbegin\n  have : (\u03bb (x : \u2115 \u00d7 \u2115), x.snd = m) \u2218 prod.swap = (\u03bb (x : \u2115 \u00d7 \u2115), x.fst = m),\n  { ext, simp },\n  rw \u2190map_swap_antidiagonal,\n  simp [map_filter, this, filter_fst_eq_antidiagonal, apply_ite (finset.map _)]\nend\n\nsection equiv_prod\n\n/-- The disjoint union of antidiagonals `\u03a3 (n : \u2115), antidiagonal n` is equivalent to the product\n    `\u2115 \u00d7 \u2115`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/\n@[simps] def sigma_antidiagonal_equiv_prod : (\u03a3 (n : \u2115), antidiagonal n) \u2243 \u2115 \u00d7 \u2115 :=\n{ to_fun := \u03bb x, x.2,\n  inv_fun := \u03bb x, \u27e8x.1 + x.2, x, mem_antidiagonal.mpr rfl\u27e9,\n  left_inv :=\n    begin\n      rintros \u27e8n, \u27e8k, l\u27e9, h\u27e9,\n      rw mem_antidiagonal at h,\n      exact sigma.subtype_ext h rfl,\n    end,\n  right_inv := \u03bb x, rfl }\n\nend equiv_prod\n\nend nat\n\nend finset\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/finset/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055544, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7446725596620272}}
{"text": "import init.data.nat.basic\nimport init.data.int.basic\n\nsection\n-- * Quant  itfiers + Equality\n-- *  Universal\n\n\n--\n-- object of type \u03b1 \u2192 Prop. In that case, given x : \u03b1, p x denotes the assertion\n-- that p holds of x. Similarly, an object r : \u03b1 \u2192 \u03b1 \u2192 Prop denotes a binary\n-- relation on \u03b1: given x y : \u03b1, r x y denotes the assertion that x is related\n-- to y.\n\n-- The universal quantifier, \u2200 x : \u03b1, p x is supposed to denote the assertion\n-- that \u201cfor every x : \u03b1, p x\u201d holds. As with the propositional connectives, in\n-- systems of natural deduction, \u201cforall\u201d is governed by an introduction and\n-- elimination rule. Informally, the introduction rule states:\n\n-- Given a proof of p x, in a context where x : \u03b1 is arbitrary, we obtain a proof \u2200 x : \u03b1, p x.\n\n-- The elimination rule states:\n\n--   Given a proof \u2200 x : \u03b1, p x and any term t : \u03b1, we obtain a proof of p t.\n\n\nvariables (\u03b1 : Type*) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x : \u03b1, p x \u2227 q x) \u2192 \u2200 y : \u03b1, p y  :=\nassume h : \u2200 x : \u03b1, p x \u2227 q x,\nassume y : \u03b1,\nshow p y, from (h y).left\n\n-- INTRODUCTION AND ELIMINATION\n\n--The canonical way to prove \u2200 y : \u03b1, p y is to take an arbitrary y, and prove p\n-- y. This is the introduction rule. Now, given that h has type \u2200 x : \u03b1, p x \u2227 q\n-- x, the expression h y has type p y \u2227 q y. This is the elimination rule.\n\n-- TWO WAYS OF PROVING TRANSITIVITY\nvariables (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\nvariable  trans_r : \u2200 x y z, r x y \u2192 r y z \u2192 r x z\n\nvariables a b c : \u03b1\nvariables (hab : r a b) (hbc : r b c)\n\n#check trans_r    -- \u2200 (x y z : \u03b1), r x y \u2192 r y z \u2192 r x z\n#check trans_r a b c\n#check trans_r a b c hab\n#check trans_r a b c hab hbc\n\n\n-- NOTe THE IMPLICIT \u2200 {x y z} !!!!!!!\nvariable  trans_r2 : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z\nvariables (a2 b2 c2 : \u03b1)\nvariables (hab2 : r a2 b2) (hbc2 : r b2 c2)\n\n#check trans_r2\n#check trans_r2 hab2\n#check trans_r2 hab2 hbc2\n\n\nvariable refl_r : \u2200 x, r x x\nvariable symm_r : \u2200 {x y}, r x y \u2192 r y x\n\n\nexample (a b c d : \u03b1) (hab : r a b) (hcb : r c b) (hcd : r c d) :\n  r a d :=\ntrans_r2 (trans_r2 hab (symm_r hcb)) hcd\n\n-- BIG BRAIN THING THAT I DONT UNDERSTAND\n\n--  The impredicativity of Prop means that we can form propositions that\n--  quantify over \u03b1 \u2192 Prop. In particular, we can define predicates on \u03b1 by\n--  quantifying over all predicates on \u03b1, which is exactly the type of\n--  circularity that was once considered problematic.\n\n-- * Equality\n\n-- ** eq.refl _\nvariables (\u03b2 : Type*)\n\nexample (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (\u03bb x, f x) a = f a := eq.refl _\nexample (a : \u03b1) (b : \u03b1) : (a, b).1 = a := eq.refl _\nexample : 2 + 3 = 5 := eq.refl _\n\n-- **  refl\nexample (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (\u03bb x, f x) a = f a := rfl\nexample (a : \u03b1) (b : \u03b1) : (a, b).1 = a := rfl\nexample : 2 + 3 = 5 := rfl\n-- **   eq.subst h1 h2. or h1 \u25b8 h2\nexample (\u03b1 : Type*) (a b : \u03b1) (p : \u03b1 \u2192 Prop)\n  (h1 : a = b) (h2 : p a) : p b :=\neq.subst h1 h2\n\nexample (\u03b1 : Type*) (a b : \u03b1) (p : \u03b1 \u2192 Prop)\n  (h1 : a = b) (h2 : p a) : p b := h1 \u25b8 h2\n\n-- ** congr_arg, conrg_fun, congr\n\n-- Specifically, congr_arg can be used to replace the argument, congr_fun can be\n-- used to replace the term that is being applied, and congr can be used to\n-- replace both at once.\n\nvariables a3 b3 : \u03b1\nvariables f g : \u03b1 \u2192 \u2115\nvariable h\u2081 : a3 = b3\nvariable h\u2082 : f = g\n\nexample : f a3 = f b3 := congr_arg f h\u2081\nexample : f a3 = g a3 := congr_fun h\u2082 a3\nexample : f a3 = g b3 := congr h\u2082 h\u2081\n-- ** useful identities in standard library\n\n-- import data.int.basic\n-- variables a4 b4 c4 d : \u2124\n\n-- example : a4 + 0 = a4 := add_zero a4\n-- example : 0 + a4 = a4 := zero_add a4\n-- example : a4 * 1 = a4 := mul_one a4\n-- example : 1 * a4 = a4 := one_mul a4\n-- example : -a4 + a4 = 0 := neg_add_self a4\n-- example : a4 + -a4 = 0 := add_neg_self a4\n-- example : a4 - a4 = 0 := sub_self a4\n-- example : a4 + b4 = b4 + a4 := add_comm a4 b4\n-- example : a4 + b4 + c4 = a4 + (b4 + c4) := add_assoc a4 b4 c4\n-- example : a4 * b4 = b4 * a4 := mul_comm a4 b4\n-- example : a4 * b4 * c4 = a4 * (b4 * c4) := mul_assoc a4 b4 c4\n-- example : a4 * (b4 + c4) = a * b4 + a4 * c4 := mul_add a4 b4 c4\n-- example : a4 * (b4 + c4) = a4 * b4 + a4 * c4 := left_distrib a4 b4 c4\n-- example : (a4 + b4) * c4 = a4 * c4 + b4 * c4 := add_mul a4 b4 c4\n-- example : (a4 + b4) * c4 = a4 * c4 + b4 * c4 := right_distrib a4 b4 c4\n-- example : a4 * (b4 - c4) = a4 * b4 - a4 * c4 := mul_sub a4 b4 c4\n-- example : (a4 - b4) * c4 = a4 * c4 - b4 * c := sub_mul a4\n\n-- no idea why the identifiers are not found\nvariables x y z : \u2124\n\nexample (x y z : \u2115) : x * (y + z) = x * y + x * z :=  mul_add x y z\nexample (x y z : \u2115) : (x + y) * z = x * z + y * z := add_mul x y z\nexample (x y z : \u2115) : x + y + z = x + (y + z) := nat.add_assoc x y z\n\nexample (x y : \u2115) :\n  (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\nhave h1 : (x + y) * (x + y) = (x + y) * x + (x + y) * y,\n  from mul_add (x + y) x y,\nhave h2 : (x + y) * (x + y) = x * x + y * x + (x * y + y * y),\n  from (add_mul x y x) \u25b8 (add_mul x y y) \u25b8 h1,\nh2.trans (add_assoc (x * x + y * x) (x * y) (y * y)).symm\n\n\nend\n\n-- *  Calculational proofs\nsection\n\n\n\nvariables (a b c d e : \u2115)\n\nvariable h1 : a = b\nvariable h2 : b = c + 1\nvariable h3 : c = d\nvariable h4 : e = 1 + d\n\ntheorem T : a = e :=\ncalc\n  a     = b      : h1\n    ... = c + 1  : h2\n    ... = d + 1  : congr_arg _ h3\n    ... = 1 + d  : nat.add_comm d (1 : \u2115)\n    ... =  e     : eq.symm h4\n\n\n-- Beautiful equational proofs;\n\n-- it is not always clear what the names in rw h1 refer to (though, in this\n-- case, it is). For that reason, section variables and variables that only\n-- appear in a tactic command or block are not automatically added to the\n-- context. The include command takes care of that.\n\ninclude h1 h2 h3 h4\n\ntheorem T2 : a = e :=\ncalc\n  a     = b      : by rw h1\n    ... = c + 1  : by rw h2\n    ... = d + 1  : by rw h3\n    ... = 1 + d  : by rw nat.add_comm\n    ... =  e     : by rw h4\n\n-- Equivalently\n\ntheorem T3 : a = e :=\ncalc\n  a     = d + 1  : by rw [h1, h2, h3]\n    ... = 1 + d  : by rw nat.add_comm\n    ... = e      : by rw h4\n\n\n-- simp tactic The simp tactic, instead, rewrites the goal by applying the given\n-- identities repeatedly, in any order, anywhere they are applicable in a term.\n-- It also uses other rules that have been previously declared to the system,\n-- and applies commutativity wisely to avoid looping. As a result, we can also\n-- prove the theorem as follows:\n\ntheorem T4 : a = e :=\nby simp [h1, h2, h3, h4, nat.add_comm]\n\nend\n\n-- The calc command can be configured for any relation that supports some form\n-- of transitivity. It can even combine different relations.\n\nsection\n\ntheorem T5 (a b c d : \u2115)\n  (h1 : a = b) (h2 : b \u2264 c) (h3 : c + 1 < d) : a < d :=\ncalc\n  a     = b     : h1\n    ... < b + 1 : nat.lt_succ_self b\n    ... \u2264 c + 1 : nat.succ_le_succ h2\n    ... < d     : h3\n\nend\n\n-- ** Proving stuff from previous section using calculational style\n-- obviouly mul_add is not found messing up with the proof lol\n\nexample (x y : \u2115) :\n  (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\ncalc\n  (x + y) * (x + y) = (x + y) * x + (x + y) * y  : by rw mul_add\n    ... = x * x + y * x + (x + y) * y            : by rw add_mul\n    ... = x * x + y * x + (x * y + y * y)        : by rw add_mul\n    ... = x * x + y * x + x * y + y * y          : by rw \u2190add_assoc\n\n\nexample (x y : \u2115) :\n  (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\nby rw [mul_add, add_mul, add_mul, \u2190add_assoc]\n\nexample (x y : \u2115) :\n  (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\nby simp [mul_add, add_mul, add_assoc, add_left_comm]\n\n-- * Existential\n-- ** Introduction : exists intro\n\n-- The introduction rule is straightforward: to prove \u2203 x : \u03b1, p x, it suffices\n-- to provide a suitable term t and a proof of p t. here are some examples:\n\nopen nat\n\nexample : \u2203 x : \u2115, x > 0 :=\nhave h : 1 > 0, from zero_lt_succ 0,\nexists.intro 1 h\n\nexample (x : \u2115) (h : x > 0) : \u2203 y, y < x :=\nexists.intro 0 h\n\nexample (x y z : \u2115) (hxy : x < y) (hyz : y < z) :\n  \u2203 w, x < w \u2227 w < z :=\nexists.intro y (and.intro hxy hyz)\n\n\n#check @exists.intro\n\n-- *** \u27e8 \u27e9 as anonymous constructor for exists\n-- We can use the anonymous constructor notation \u27e8t, h\u27e9 for exists.intro t h,\n-- when the type is clear from the context.\n\nexample : \u2203 x : \u2115, x > 0 :=\n\u27e81, zero_lt_succ 0\u27e9\n\nexample (x : \u2115) (h : x > 0) : \u2203 y, y < x :=\n\u27e80, h\u27e9\n\nexample (x y z : \u2115) (hxy : x < y) (hyz : y < z) :\n  \u2203 w, x < w \u2227 w < z := \u27e8y, hxy, hyz\u27e9\n-- ** Elimination : exists.elim\n\n-- The existential elimination rule, exists.elim allows us to prove a\n-- proposition q from \u2203 x : \u03b1, p x, by showing that q follows from p w for an\n-- arbitrary value w. Roughly speaking, since we know there is an x satisfying p\n-- x, we can give it a name, say, w. If q does not mention w, then showing that\n-- q follows from p w is tantamount to showing the q follows from the existence\n-- of any such x.\n\n\nvariables (\u03b1 : Type*) (p q : \u03b1 \u2192 Prop)\n\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nexists.elim h\n  (assume w,\n    assume hw : p w \u2227 q w,\n    show \u2203 x, q x \u2227 p x, from \u27e8w, hw.right, hw.left\u27e9)\n\n-- \u2191\u2191\u2191 in the above example we first elim the first \u2203\n-- by naming it w, then we prove the goal of form \u2203\n-- by exists.introing it !\n-- So we actually had to assume the var in which the \u2203 works\n-- together the proposition of interest.\n-- Then we used to instantiated variables to construct\n-- the new goal, which in this examples also happens to be of\n-- the form \u2203.\n\n\n-- *** existential elimination with match\n\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nmatch h with \u27e8w, hw\u27e9 :=\n  \u27e8w, hw.right, hw.left\u27e9\nend\n\n\n-- alternatively,\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\nmatch h with \u27e8w, hpw, hqw\u27e9 :=\n  \u27e8w, hqw, hpw\u27e9\nend\n-- or even,\n\nexample : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, q x \u2227 p x :=\nassume \u27e8w, hpw, hqw\u27e9, \u27e8w, hqw, hpw\u27e9\n\n\n-- *** constructivism and or\n\n-- Just as the constructive \u201cor\u201d is stronger than the classical \u201cor,\u201d so, too,\n-- is the constructive \u201cexists\u201d stronger than the classical \u201cexists\u201d. For\n-- example, the following implication requires classical reasoning because, from\n-- a constructive standpoint, knowing that it is not the case that every x\n-- satisfies \u00ac p is not the same as having a particular x that satisfies p.\n\nopen classical\n\n-- Too tricky, gotta study this\nexample (h : \u00ac \u2200 x, \u00ac p x) : \u2203 x, p x :=\nby_contradiction\n  (assume h1 : \u00ac \u2203 x, p x,\n    have h2 : \u2200 x, \u00ac p x, from\n      assume x,\n      assume h3 : p x,\n      have h4 : \u2203 x, p x, from  \u27e8x, h3\u27e9,\n      show false, from h1 h4,\n    show false, from h h2)\n\n\nvariable r : Prop\n\nexample : (\u2203 x : \u03b1, r) \u2192 r := sorry\nexample (a : \u03b1) : r \u2192 (\u2203 x : \u03b1, r) := sorry\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := sorry\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := sorry\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := sorry\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := sorry\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) := sorry\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := sorry\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := sorry\nexample (a : \u03b1) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := sorry\nexample (a : \u03b1) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := sorry\n-- * More on the proof language\n-- ** The anonymous have + this\n\n\n-- To start with, we can use anonymous \u201chave\u201d expressions to introduce an\n-- auxiliary goal without having to label it. We can refer to the last\n-- expression introduced in this way using the keyword this:\n\n\nvariable f : \u2115 \u2192 \u2115\nvariable h : \u2200 x : \u2115, f x \u2264 f (x + 1)\n\nexample : f 0 \u2264 f 3 :=\nhave f 0 \u2264 f 1, from h 0,\nhave f 0 \u2264 f 2, from le_trans this (h 1),\nshow f 0 \u2264 f 3, from le_trans this (h 2)\n\n\n-- ** assumption tactic\n\n-- When the goal can be inferred, we can also ask Lean instead to fill in the\n-- proof by writing by assumption:This tells Lean to use the assumption tactic,\n-- which, in turn, proves the goal by finding a suitable hypothesis in the local\n-- context.\n\n\nexample : f 0 \u2264 f 3 :=\nhave f 0 \u2264 f 1, from h 0,\nhave f 0 \u2264 f 2, from le_trans (by assumption) (h 1),\nshow f 0 \u2264 f 3, from le_trans (by assumption) (h 2)\n\n\n-- We can also ask Lean to fill in the proof by writing \u2039p\u203a, where p is the proposition whose proof we want Lean to find in the context.You can type these corner quotes using \\f< and \\f>, respectively. This approach is more robust than using by assumption, because the type of the assumption that needs to be inferred is given explicitly. It also makes proofs more readable.\n\nexample : f 0 \u2265 f 1 \u2192 f 1 \u2265 f 2 \u2192 f 0 = f 2 :=\nassume : f 0 \u2265 f 1,\nassume : f 1 \u2265 f 2,\nhave f 0 \u2265 f 2, from le_trans this \u2039f 0 \u2265 f 1\u203a,\nhave f 0 \u2264 f 2, from le_trans (h 0) (h 1),\nshow f 0 = f 2, from le_antisymm this \u2039f 0 \u2265 f 2\u203a\n\nexample : f 0 \u2264 f 3 :=\nhave f 0 \u2264 f 1, from h 0,\nhave f 1 \u2264 f 2, from h 1,\nhave f 2 \u2264 f 3, from h 2,\nshow f 0 \u2264 f 3, from le_trans \u2039f 0 \u2264 f 1\u203a\n  (le_trans \u2039f 1 \u2264 f 2\u203a \u2039f 2 \u2264 f 3\u203a)\n-- ** anonynomous assume\n\n-- We can also assume a hypothesis without giving it a label:In contrast to the\n-- usage with have, an anonymous assume needs an extra colon. The reason is that\n-- Lean allows us to write assume h to introduce a hypothesis without specifying\n-- it, and without the colon it would be ambiguous as to whether the h here is\n-- meant as the label or the assumption. As with the anonymous have, when you\n-- use an anonymous assume to introduce an assumption, that assumption can also\n-- be invoked later in the proof by enclosing it in French quotes.\n\n\nexample : f 0 \u2265 f 1 \u2192 f 0 = f 1 :=\nassume : f 0 \u2265 f 1,\nshow f 0 = f 1, from le_antisymm (h 0) this\n\nexample : f 0 \u2265 f 1 \u2192 f 1 \u2265 f 2 \u2192 f 0 = f 2 :=\nassume : f 0 \u2265 f 1,\nassume : f 1 \u2265 f 2,\nhave f 0 \u2265 f 2, from le_trans \u2039f 2 \u2264 f 1\u203a \u2039f 1 \u2264 f 0\u203a,\nhave f 0 \u2264 f 2, from le_trans (h 0) (h 1),\nshow f 0 = f 2, from le_antisymm this \u2039f 0 \u2265 f 2\u203a\n", "meta": {"author": "marcelovmaciel", "repo": "learning_lean", "sha": "0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4", "save_path": "github-repos/lean/marcelovmaciel-learning_lean", "path": "github-repos/lean/marcelovmaciel-learning_lean/learning_lean-0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4/theorem_proving_with_lean/third_note.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7444785989403816}}
{"text": "\ntheorem Ex014(a b: Prop): a \u2227 b \u2194 b \u2227 a := \nshow  a \u2227 b \u2194 b \u2227 a , from iff.intro\n  (\n    assume H1:a \u2227 b,\n    have A:a,from and.elim_left H1,\n    have B:b,from and.elim_right H1,\n    show b \u2227 a, from and.intro B A\n  )\n  (\n    assume H1 : b \u2227 a,\n    have A:b,from and.elim_left H1,\n    have B:a,from and.elim_right H1,\n    show a \u2227 b, from and.intro B A\n  )\n", "meta": {"author": "SvenWille", "repo": "LeanLogicExercises", "sha": "2dbc920feadd63bbc50f87e69646c0081db26eba", "save_path": "github-repos/lean/SvenWille-LeanLogicExercises", "path": "github-repos/lean/SvenWille-LeanLogicExercises/LeanLogicExercises-2dbc920feadd63bbc50f87e69646c0081db26eba/src/propLogic/Ex014.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.744423330988245}}
{"text": "import .reals\nopen classical\n\nstructure complex :=\n(Re : real) (Im : real)\n\ndef pure_real (z : complex) := z.Im = 0\ndef pure_imaginary (z : complex) := z.Re = 0\n\nnotation `\u2102` := complex\nopen complex\n\n@[reducible] noncomputable\ndef complex.zero : complex := \u27e80,0\u27e9\n\n@[reducible] noncomputable\ndef complex.one : complex := \u27e81,0\u27e9\n\n@[reducible] noncomputable\ndef complex.add : complex \u2192 complex \u2192 complex\n| \u27e8a, b\u27e9 \u27e8c, d\u27e9 := \u27e8a + c, b + d\u27e9\n\n@[reducible] noncomputable\ndef complex.neg : complex \u2192 complex\n| \u27e8a, b\u27e9 := \u27e8-a, -b\u27e9\n\n@[reducible] noncomputable\ndef complex.mul : complex \u2192 complex \u2192 complex\n| \u27e8a, b\u27e9 \u27e8c, d\u27e9 := \u27e8a*c - b*d, a * d + b * c\u27e9\n\n@[reducible] noncomputable\ndef complex.scalar_mul (k : real) : complex \u2192 complex\n| \u27e8x, y\u27e9 := \u27e8k*x, k*y\u27e9\n\n@[reducible] noncomputable\ndef complex.conj : complex \u2192 complex\n| \u27e8x, y\u27e9 := \u27e8x, -y\u27e9\n\n@[reducible] noncomputable\ndef complex.norm_squared : complex \u2192 real\n| \u27e8x, y\u27e9 := x*x + y*y\n\nlemma complex.norm_squared_nonneg : \u2200 z : \u2102, z.norm_squared \u2265 0 \n| \u27e8x, y\u27e9 := add_nonneg (mul_self_nonneg x) (mul_self_nonneg y)\n\n@[reducible] noncomputable\ndef complex.norm (z : complex) := \u221a(complex.norm_squared z)\n\nlemma complex.norm_nonneg : \u2200 z : \u2102, z.norm \u2265 0 :=\n\u03bb z, sqrt_nonneg z.norm_squared\n\nlemma squared_norm_eq_norm_squared : \u2200 z : \u2102, z.norm * z.norm = z.norm_squared :=\n\u03bb z, sqrt_sq z.norm_squared_nonneg\n\nnoncomputable\ndef complex.inv (z : complex) : complex :=\n  complex.scalar_mul (1/(complex.norm_squared z)) (complex.conj z)\n\n@[reducible] noncomputable\ndef i : \u2102 := \u27e80, 1\u27e9\n\nnoncomputable instance : has_coe \u211d \u2102 := \u27e8\u03bb r, \u27e8r, 0\u27e9\u27e9\n\nlemma coe_pure_real : \u2200 x : \u211d, pure_real x := \u03bb x, rfl\n\nmeta def simple_complex_eq := do\n  names \u2190 tactic.intros,\n  monad.mapm' tactic.cases names,\n  `[simp [1, 0, (+), (*)]],\n  `[simp [complex.zero, complex.one, complex.add, complex.mul]]\n\nlemma complex.mul_comm : \u2200 z w, complex.mul z w = complex.mul w z :=\n  by { intros z w, cases z, cases w, simp [complex.mul], \n       constructor,\n       { rw mul_comm, apply congr_arg, rw mul_comm },\n       { rw add_comm, apply congr; rw mul_comm } }\n\nlemma norm_squared_eq_mul_conj\n  : \u2200 z, complex.mul z (complex.conj z) = \u27e8complex.norm_squared z, 0\u27e9\n  := by { intros, cases z, simp [complex.conj, complex.norm_squared, complex.mul],\n          rw [mul_comm, add_neg_self] }\n\nlemma norm_squared_eq_mul_conj'\n  : \u2200 z, complex.norm_squared z = Re (complex.mul z (complex.conj z))\n  := by intros; rw norm_squared_eq_mul_conj\n\nlemma mul_conj_is_pure_real\n  : \u2200 z, pure_real (complex.mul z (complex.conj z))\n  := by intros; rw norm_squared_eq_mul_conj; simp [pure_real]\n\nlemma scalar_mul_comm_mul\n  : \u2200 w z k, complex.scalar_mul k (complex.mul w z) = complex.mul w (complex.scalar_mul k z)\n  := by { intros, cases z, cases w, \n          simp [complex.scalar_mul, complex.mul],\n          constructor; rw left_distrib; apply congr,\n          { apply congr_arg, ac_refl },\n          { rw \u2190 neg_mul_eq_mul_neg, ac_refl },\n          { apply congr_arg, ac_refl },\n          { ac_refl } }\n\nlemma conj_of_conj : \u2200 z, complex.conj (complex.conj z) = z :=\n  by intros; cases z; simp [complex.conj]\n\nlemma norm_squared_eq_norm_squared_of_conj : \u2200 z, complex.norm_squared z = complex.norm_squared (complex.conj z) := by {\n  intros,\n  suffices : complex.mk (complex.norm_squared z) 0 = \u27e8complex.norm_squared (complex.conj z), 0\u27e9,\n  { have := congr_arg Re this,\n    simp at this, assumption },\n  rw [\u2190 norm_squared_eq_mul_conj, \u2190 norm_squared_eq_mul_conj, conj_of_conj],\n  rw complex.mul_comm }\n\nlemma norm_squared_zero_implies_zero \n  : \u2200 z, complex.norm_squared z = 0 \u2192 z = complex.zero\n  := by {\n    intros z h, \n    cases z,\n    dunfold complex.norm_squared at h,\n    suffices : z_Re*z_Re = 0 \u2227 z_Im*z_Im = 0,\n    { unfold complex.zero,\n      cases this,\n      suffices : z_Re = 0 \u2227 z_Im = 0,\n      { rw [this.left, this.right] },\n      by_contra, rw decidable.not_and_iff_or_not at a,\n      cases a;\n      apply division_ring.mul_ne_zero a a; assumption },\n    by_contradiction,\n    rw decidable.not_and_iff_or_not at a,\n    have hnonneg1 : 0 \u2264 z_Re * z_Re, { apply mul_self_nonneg },\n    have hnonneg2 : 0 \u2264 z_Im * z_Im, { apply mul_self_nonneg },\n    have : 0 < z_Re * z_Re \u2228 0 < z_Im * z_Im,\n    { cases a,\n      { apply or.inl,\n        apply lt_of_le_of_ne,\n        exact hnonneg1,\n        intro, apply a, symmetry, assumption },\n      { apply or.inr,\n        apply lt_of_le_of_ne,\n        exact hnonneg2,\n        intro, apply a, symmetry, assumption } },\n    suffices : 0 < z_Re * z_Re + z_Im * z_Im,\n    { have := or.inl this,\n      rw \u2190 ne_iff_lt_or_gt at this,\n      apply this, symmetry, assumption },\n    cases this,\n    { rw add_comm,\n      apply add_pos_of_nonneg_of_pos; assumption },\n    { apply add_pos_of_nonneg_of_pos; assumption } }\n\nlemma complex.mul_inv_cancel\n  : \u2200 z, z \u2260 complex.zero \u2192 complex.mul z (complex.inv z) = complex.one\n  := by {\n    intros z h, \n    unfold complex.inv,\n    rw \u2190 scalar_mul_comm_mul,\n    rw norm_squared_eq_mul_conj,\n    unfold complex.scalar_mul,\n    rw mul_zero,\n    have : complex.norm_squared z \u2260 0,\n    { by_contra, apply h, apply norm_squared_zero_implies_zero,\n      by_contra, exact a a_1 },\n    rw one_div_mul_cancel this }\n\nlemma complex.inv_mul_cancel\n  : \u2200 z, z \u2260 complex.zero \u2192 complex.mul (complex.inv z) z = complex.one\n  := by intros z h; rw complex.mul_comm; apply complex.mul_inv_cancel z h\n\nlemma complex.left_distrib\n: \u2200 v w z, complex.mul v (complex.add w z)\n           = complex.add (complex.mul v w) (complex.mul v z)\n  := by { intros, cases v, cases w, cases z,\n          simp [complex.mul, complex.add],\n          constructor,\n          { rw left_distrib, simp,\n            apply congr_arg, apply congr_arg,\n            rw left_distrib, rw neg_add },\n          { rw left_distrib, simp,\n            apply congr_arg, apply congr_arg,\n            rw left_distrib } }\n\nnoncomputable instance : discrete_field \u2102 :=\n  { zero := complex.zero\n  , one := complex.one\n  , add := complex.add\n  , mul := complex.mul\n  , neg := complex.neg\n  , inv := complex.inv\n  , add_zero := by simple_complex_eq\n  , zero_add := by simple_complex_eq\n  , one_mul := by simple_complex_eq\n  , mul_one := by simple_complex_eq\n  , add_assoc := by simple_complex_eq\n  , add_comm := by simple_complex_eq\n  , mul_assoc := by { simple_complex_eq, constructor,\n                      { rw left_distrib a_Re, rw right_distrib _ _ c_Re,\n                        rw right_distrib, rw left_distrib, rw neg_add, rw neg_add,\n                        repeat { rw mul_assoc },\n                        generalize h1 : -(a_Re * (b_Im * c_Im)) = x, \n                        rw (_ : a_Re * -(b_Im * c_Im) = x),\n                        generalize : -(a_Im * (b_Re * c_Im)) = y, \n                        generalize : a_Re * (b_Re * c_Re) = z,\n                        generalize h2 : -(a_Im * b_Im) * c_Re = w,\n                        rw (_ : -(a_Im * (b_Im * c_Re)) = w),\n                        ac_refl,\n                        { rw \u2190 h2,\n                          rw neg_eq_neg_one_mul,\n                          rw neg_eq_neg_one_mul (a_Im * _),\n                          ac_refl },\n                        { rw \u2190 h1,\n                          rw neg_eq_neg_one_mul,\n                          rw neg_eq_neg_one_mul (a_Re * _),\n                          ac_refl }, },\n                      { rw neg_mul_eq_mul_neg, rw neg_mul_eq_neg_mul,\n                        rw left_distrib a_Im, rw right_distrib _ _ c_Im,\n                        rw add_comm (b_Re * c_Im) (b_Im * c_Re), \n                        rw left_distrib a_Re, rw right_distrib _ _ c_Re,\n                        rw \u2190 add_assoc, rw \u2190 add_assoc,\n                        simp,\n                        apply congr, { apply congr_arg, rw mul_assoc },\n                        apply congr, { apply congr_arg, rw mul_assoc },\n                        apply congr, { apply congr_arg, rw mul_assoc },\n                        apply congr_arg, rw mul_assoc } }\n  , mul_comm := complex.mul_comm\n  , zero_ne_one := by { intro h, apply real_field.zero_ne_one, simp [0, 1], simp [0, 1] at h,\n                        rw (_ : real_field.zero = Re complex.zero),\n                        rw (_ : real_field.one = Re complex.one),\n                        rw h, refl, refl }\n  , add_left_neg := by simple_complex_eq\n  , mul_inv_cancel := complex.mul_inv_cancel\n  , inv_mul_cancel := complex.inv_mul_cancel\n  , left_distrib := complex.left_distrib\n  , right_distrib := by { intros, simp [(*)],\n                          rw complex.mul_comm _ c,\n                          rw complex.mul_comm a c,\n                          rw complex.mul_comm b c,\n                          apply complex.left_distrib }\n  , inv_zero := by { dsimp [complex.zero, complex.inv, complex.norm_squared],\n                     rw [mul_zero, add_zero, div_zero, complex.conj],\n                     dsimp [complex.scalar_mul], congr, rw mul_zero, rw zero_mul }\n  , has_decidable_eq := by {\n      intros x y, cases x, cases y,\n      rw (_ : ({complex .  Re := x_Re, Im := x_Im} = {Re := y_Re, Im := y_Im})\n            = (x_Re = y_Re \u2227 x_Im = y_Im)),\n      apply_instance, apply propext, constructor; intro h,\n      { cases h, constructor; refl },\n      { cases h, cases h_left, cases h_right, refl } } }\n\nnoncomputable\ninstance : decidable_eq \u2102 :=\n  by { intros x y, cases x, cases y,\n       rw (_ : ({complex .  Re := x_Re, Im := x_Im} = {Re := y_Re, Im := y_Im})\n             = (x_Re = y_Re \u2227 x_Im = y_Im)),\n       apply_instance, apply propext, constructor; intro h,\n       { cases h, constructor; refl },\n       { cases h, cases h_left, cases h_right, refl } }\n\nnotation `|`z`|` := complex.norm z\n\nlemma norm_zero_implies_zero  : \u2200 z, |z| = 0 \u2192 z = 0 :=\nby { intros z h, rw (_ : 0 = \u221a0) at h, apply norm_squared_zero_implies_zero,\n     apply eq_of_sqrt_eq, apply complex.norm_squared_nonneg, refl, exact h,\n     apply sqrt_unique, refl, refl, rw mul_zero }\n\nlemma norm_of_pure_real : \u2200 z, pure_real z \u2192 |z| = abs (Re z) :=\nbegin\n  intros z hz, rw abs_eq_sq_sqrt, dsimp [complex.norm],\n  rw (_ : complex.norm_squared z = z.Re * z.Re),\n  cases z, dsimp [complex.norm_squared], rw (_ : z_Im = 0),\n  rw [mul_zero, add_zero], exact hz,\nend\n\nlemma norm_of_zero : |0| = 0 :=\n  eq.symm $ sqrt_unique (complex.norm_squared_nonneg 0) (le_refl 0)\n          $ by { rw mul_zero, rw (_ : (0 : \u2102) = \u27e80, 0\u27e9), dsimp [complex.norm_squared], simp, refl }\n\nlemma norm_of_one : |1| = 1 :=\n  eq.symm $ sqrt_unique (complex.norm_squared_nonneg 1) zero_le_one\n          $ by { rw mul_one, rw (_ : (1 : \u2102) = \u27e81, 0\u27e9), dsimp [complex.norm_squared], simp, refl }\n\n@[simp]\nlemma complex.unfold_add : \u2200 a b c d,\n  complex.mk a b + complex.mk c d = complex.mk (a + c) (b + d) := by intros; refl\n@[simp]\nlemma complex.unfold_neg : \u2200 a b,\n  -complex.mk a b = complex.mk (-a) (-b) := by intros; refl\n@[simp]\nlemma complex.unfold_mul : \u2200 a b c d,\n  complex.mk a b * complex.mk c d = complex.mk (a*c - b*d) (a * d + b * c) := by intros; refl\n@[simp]\nlemma complex.unfold_inv : \u2200 a b,\n  (complex.mk a b)\u207b\u00b9 = complex.mk (a/(a*a + b*b)) (-b/(a*a + b*b)) :=\n  by { intros, generalize h : complex.mk a b = z,\n       transitivity complex.scalar_mul (1/(complex.norm_squared z)) (complex.conj z), refl, \n       subst h, dsimp [complex.norm_squared, complex.scalar_mul],\n       rw [mul_comm _ a, \u2190 div_eq_mul_one_div], rw [mul_comm _ (-b), \u2190 div_eq_mul_one_div] }\n      \n@[simp]\nlemma complex.unfold_conj : \u2200 a b,\n  complex.conj (complex.mk a b) = complex.mk a (-b) := by intros; refl\n\nlemma norm_conj : \u2200 z : \u2102, |z| = |z.conj| :=\nby intro z; dsimp [complex.norm]; rw norm_squared_eq_norm_squared_of_conj\n\nlemma norm_sub : \u2200 z w : \u2102, |z - w| = |w - z| :=\nby { intros, dsimp [complex.norm], rw (_ : complex.norm_squared (z + -w) = complex.norm_squared (w + -z)),\n     cases z, cases w, simp, dsimp [complex.norm_squared], apply congr,\n     { apply congr_arg, transitivity -(z_Re + -w_Re) * -(z_Re + -w_Re),\n       rw neg_eq_neg_one_mul (z_Re + -w_Re), rw \u2190 mul_assoc, rw mul_right_comm (-1 : \u211d),\n       rw [square_neg_one, one_mul], rw [neg_add, neg_neg, add_comm] },\n     { transitivity -(z_Im + -w_Im) * -(z_Im + -w_Im),\n       rw neg_eq_neg_one_mul (z_Im + -w_Im), rw \u2190 mul_assoc, rw mul_right_comm (-1 : \u211d),\n       rw [square_neg_one, one_mul], rw [neg_add, neg_neg, add_comm] } }\n\nlemma norm_neg : \u2200 z, |(-z)| = |z| :=\nby intro; rw [\u2190 zero_sub, norm_sub, sub_zero]\n\nlemma complex.norm_pos : \u2200 z : \u2102, z \u2260 0 \u2192 z.norm > 0 :=\nbegin\n  intros, apply lt_of_le_of_ne,\n  apply complex.norm_nonneg, apply ne.symm,\n  apply mt (norm_zero_implies_zero z), assumption\nend\n\nlemma norm_squared_of_scale : \u2200 x z, complex.norm_squared (complex.scalar_mul x z) = (x*x) * z.norm_squared :=\nby { intros, cases z, simp [complex.scalar_mul, complex.norm_squared],\n     rw left_distrib, ac_refl, }\n\nlemma Re_additive : \u2200 z w, Re (z + w) = Re z + Re w :=\nby intros; cases z; cases w; simp\n\nlemma Im_additive : \u2200 z w, Im (z + w) = Im z + Im w :=\nby intros; cases z; cases w; simp\n\nlemma mul_pure_real : \u2200 z w : \u2102, pure_real z \u2192 z * w = complex.scalar_mul z.Re w :=\nby intros; cases z; cases w; simp [pure_real] at a; rw a; simp [complex.scalar_mul]\n\nlemma scale_pure_real : \u2200 x (z : \u2102), pure_real z \u2192 pure_real (complex.scalar_mul x z)\n                      \u2227 Re (complex.scalar_mul x z) = x * Re z :=\nby intros; cases z; simp [pure_real] at a; rw a; simp [complex.scalar_mul, pure_real]\n\nlemma Re_of_scale : \u2200 x (z : \u2102), Re (complex.scalar_mul x z) = x * Re z :=\nby intros; cases z; simp\n\nlemma Im_of_scale : \u2200 x (z : \u2102), Im (complex.scalar_mul x z) = x * Im z :=\nby intros; cases z; simp\n\nlemma Re_conj : \u2200 z, Re z = Re z.conj := by intro; cases z; refl\n\nlemma Re_neg : \u2200 z, Re (-z) = -Re z :=\nby intros; cases z; simp\n\nlemma Re_sub : \u2200 z w, Re (z - w) = Re z - Re w :=\nby intros; cases z; cases w; simp\n\nlemma Im_neg : \u2200 z, Im (-z) = -Im z :=\nby intros; cases z; simp\n\nlemma conj_add : \u2200 z w, complex.conj (z + w) = complex.conj z + complex.conj w :=\nby intros; cases z; cases w; simp [complex.conj]\n\nlemma conj_mul : \u2200 z w, complex.conj (z * w) = complex.conj z * complex.conj w :=\nby intros; cases z; cases w; simp [complex.conj]\n\nlemma conj_neg : \u2200 z, complex.conj (-z) = - complex.conj z :=\nby intros; cases z; simp\n\nlemma conj_sub : \u2200 z w, complex.conj (z - w) = complex.conj z - complex.conj w :=\nby intros; cases z; cases w; simp\n\nlemma norm_mul : \u2200 z w, |z*w| = |z|*|w| :=\nbegin\n  intros, symmetry, apply sqrt_unique,\n  apply complex.norm_squared_nonneg,\n  apply mul_nonneg; apply complex.norm_nonneg, \n  rw [mul_left_comm, mul_assoc, \u2190 mul_assoc],\n  rw [squared_norm_eq_norm_squared, squared_norm_eq_norm_squared],\n  rw [norm_squared_eq_mul_conj' (z*w)],\n  transitivity ((z * w) * (complex.conj (z * w))).Re,\n  { rw [conj_mul,mul_left_comm, mul_assoc, \u2190 mul_assoc, mul_comm _ z],\n    rw norm_squared_eq_mul_conj', rw norm_squared_eq_mul_conj',\n    rw [mul_pure_real, Re_of_scale], congr,\n    apply mul_conj_is_pure_real },\n  refl\nend\n\nlemma norm_squared_eq_mul_conj''\n  : \u2200 (z : \u2102), complex.norm_squared z = (z * (complex.conj z)).Re\n  := norm_squared_eq_mul_conj'\n\nlemma norm_inv : \u2200 z, z \u2260 0 \u2192 |z\u207b\u00b9| = |z|\u207b\u00b9 :=\nbegin\n  intros, have : z.norm_squared > 0,\n  { apply lt_of_le_of_ne, apply complex.norm_squared_nonneg,\n    apply ne.symm, apply mt (norm_squared_zero_implies_zero z), assumption },\n  cases z, simp [complex.inv],\n  simp [complex.norm, complex.norm_squared],\n  rw \u2190 field.div_mul_eq_mul_div_comm,\n  rw inv_sqrt, congr, \n  rw inv_eq_one_div,\n  rw div_eq_mul_one_div,\n  rw div_eq_mul_one_div, \n  rw div_eq_mul_one_div (-z_Im),\n  rw mul_right_comm,\n  rw \u2190 mul_assoc, rw \u2190 right_distrib,\n  suffices : (z_Re * (1 / (z_Re * z_Re + z_Im * z_Im)) * z_Re + -z_Im * (1 / (z_Re * z_Re + z_Im * z_Im)) * -z_Im) = 1,\n  { rw this, rw one_mul },\n  rw mul_right_comm, rw mul_right_comm (-z_Im),\n  rw \u2190 right_distrib,\n  rw [mul_neg_eq_neg_mul_symm, neg_mul_eq_neg_mul_symm, neg_neg],\n  rw \u2190 div_eq_mul_one_div, rw div_self,\n  all_goals { dsimp [complex.norm_squared] at this, try { apply ne_of_gt }, assumption }\nend\n\nlemma norm_div : \u2200 z w, w \u2260 0 \u2192 |z/w| = |z|/|w| :=\nbegin\n  intros, rw div_eq_mul_one_div, rw norm_mul, congr,\n  rw [\u2190 norm_inv, inv_eq_one_div], assumption\nend\n\nlemma abs_Re_le_norm : \u2200 z, abs (Re z) \u2264 |z| :=\nbegin\n  intro z, rw abs_eq_sq_sqrt, dsimp [complex.norm],\n  apply sqrt_monotone, cases z, dsimp [ complex.norm_squared], \n  apply le_add_of_nonneg_right, apply mul_self_nonneg\nend\n\nlemma abs_Im_le_norm : \u2200 z, abs (Im z) \u2264 |z| :=\nbegin\n  intro z, rw abs_eq_sq_sqrt, dsimp [complex.norm],\n  apply sqrt_monotone, cases z, dsimp [complex.norm_squared], \n  apply le_add_of_nonneg_left, apply mul_self_nonneg\nend\n\nlemma complex.eq_of_really_close : \u2200 {z w : \u2102}, (\u2200 \u03b5, \u03b5 > 0 \u2192 |z - w| < \u03b5) \u2192 z = w :=\nbegin\n  intros z w h, suffices : Re z = Re w \u2227 Im z = Im w, { cases z, cases w, simp at this, rw [this.left, this.right] },\n  constructor,\n  { apply eq_of_really_close, intros \u03b5 h\u03b5, specialize h \u03b5 h\u03b5,\n    rw [sub_eq_add_neg, \u2190 Re_neg, \u2190 Re_additive, \u2190 sub_eq_add_neg],\n    apply lt_of_le_of_lt, apply abs_Re_le_norm, assumption },\n  { apply eq_of_really_close, intros \u03b5 h\u03b5, specialize h \u03b5 h\u03b5,\n    rw [sub_eq_add_neg, \u2190 Im_neg, \u2190 Im_additive, \u2190 sub_eq_add_neg],\n    apply lt_of_le_of_lt, apply abs_Im_le_norm, assumption }\nend\n\nlemma norm_squared_sum : \u2200 z w, complex.norm_squared (z + w) = complex.norm_squared z + 2*(Re (z * w.conj)) + complex.norm_squared w :=\nbegin\n  intros, rw norm_squared_eq_mul_conj'',\n  rw norm_squared_eq_mul_conj'', rw norm_squared_eq_mul_conj'',\n  rw [conj_add, left_distrib, right_distrib, right_distrib],\n  rw [add_assoc, \u2190 add_assoc (w * _)], rw \u2190 add_assoc,\n  rw [Re_additive, Re_additive], congr, rw two_mul,\n  cases z, cases w, simp, ac_refl,\nend\n\nlemma complex.triangle_inequality : \u2200 (x y : \u2102), |x + y| \u2264 |x| + |y| :=\nbegin\n  intros, apply nonneg_le_nonneg_of_squares_le,\n  apply add_nonneg; apply complex.norm_nonneg,\n  rw [squared_norm_eq_norm_squared, norm_squared_sum],\n  rw FOIL, rw [squared_norm_eq_norm_squared, squared_norm_eq_norm_squared],\n  rw add_assoc _ ( |x| * |y| ), rw mul_comm ( |y| ), rw \u2190 two_mul,\n  apply add_le_add_right, apply add_le_add_left,\n  apply mul_le_mul_of_nonneg_left _,\n  { apply le_trans, apply zero_le_one, apply le_add_of_nonneg_right zero_le_one },\n  rw [norm_conj y, \u2190 norm_mul], transitivity, apply le_abs_self,\n  apply abs_Re_le_norm\nend\n\nlemma complex.triangle_inequality' : \u2200 (x y z : \u2102), |x - y| \u2264 |x - z| + |z - y| :=\nbegin\n  intros, rw (_ : x - y = (x - z) + (z - y)),\n  apply complex.triangle_inequality,\n  rw [\u2190 add_sub_assoc, sub_add_cancel]\nend\n\nlemma complex.lt_of_lt_triangle_lt (x y z : \u2102) (\u03b5 : \u211d) :\n  |x - z| < \u03b5/2 \u2192 |y - z| < \u03b5/2 \u2192 |x - y| < \u03b5 :=\nby { intros h h', rw norm_sub at h', apply lt_of_le_of_lt (complex.triangle_inequality' x y z),\n     rw [\u2190 add_self_div_two \u03b5, \u2190 div_add_div_same], exact add_lt_add h h' }\n\nlemma complex.squared_dist (z w : \u2102)\n  : |z - w|*|z - w| = z.norm_squared - 2 * Re (z*w.conj) + w.norm_squared :=\nbegin\n  intros, rw squared_norm_eq_norm_squared,\n  rw [norm_squared_eq_mul_conj', norm_squared_eq_mul_conj'],\n  rw [two_mul], transitivity\n    (complex.mul z (complex.conj z)).Re - ((z * complex.conj w).Re + (complex.conj z * w).Re) +\n      (complex.mul w (complex.conj w)).Re,\n  { rw [sub_eq_add_neg (Re _), neg_add, \u2190 Re_neg, \u2190 Re_neg],\n    rw [\u2190 Re_additive, \u2190 Re_additive, \u2190 Re_additive],\n   apply congr, refl, \n   transitivity (z + -w) * complex.conj (z + -w),\n   { rw sub_eq_add_neg, refl },\n     transitivity z * (complex.conj z) + (-(z * complex.conj w) + -(complex.conj z * w)) + w * (complex.conj w),\n     { rw [conj_add, conj_neg, FOIL], \n       rw \u2190 add_assoc, apply congr,\n       { congr, rw neg_mul_eq_mul_neg, rw mul_comm, rw neg_mul_eq_mul_neg },\n       { apply neg_mul_neg, } },\n     refl },\n  rw [\u2190 norm_squared_eq_mul_conj', \u2190 norm_squared_eq_mul_conj'],\n  apply congr_fun, apply congr_arg, apply congr_arg, apply congr_arg,\n  rw Re_conj, rw [conj_mul, conj_of_conj]\nend\n\nlemma distrib_scalar_mul_over_add_complex : \u2200 r z w,\n  complex.scalar_mul r (z + w) = complex.scalar_mul r z + complex.scalar_mul r w :=\nby { intros, cases z, cases w, simp [complex.scalar_mul],\n     constructor; apply left_distrib, }\n\nlemma distrib_complex_over_scalar_mul_add_real : \u2200 x y z,\n  complex.scalar_mul (x + y) z = complex.scalar_mul x z + complex.scalar_mul y z :=\nby { intros, cases z, simp [complex.scalar_mul],\n     constructor; apply right_distrib }\n\nlemma scalar_mul_comm_mul'\n  : \u2200 w z k, complex.scalar_mul k (w * z) = w * (complex.scalar_mul k z)\n  := scalar_mul_comm_mul\n\nlemma norm_squared_div_self\n  : \u2200 z, complex.scalar_mul (complex.norm_squared z) (1/z) = complex.conj z :=\nbegin\n  intro z, by_cases complex.norm_squared z = 0, \n  { rw norm_squared_zero_implies_zero _ h,\n    dsimp [complex.norm_squared], rw [zero_mul, zero_add],\n    generalize : 1/complex.zero = w, cases w,\n    simp [complex.scalar_mul] },\n  cases z, simp [complex.norm_squared, complex.scalar_mul],\n  rw mul_div_cancel', rw mul_div_cancel', constructor; refl,\n  exact h, exact h\nend", "meta": {"author": "Shamrock-Frost", "repo": "FormalComplexAnalysis", "sha": "3cac79d9b603b1edf7df1bc7e948c74eb86a2cc0", "save_path": "github-repos/lean/Shamrock-Frost-FormalComplexAnalysis", "path": "github-repos/lean/Shamrock-Frost-FormalComplexAnalysis/FormalComplexAnalysis-3cac79d9b603b1edf7df1bc7e948c74eb86a2cc0/complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7444167045406913}}
{"text": "import ring_theory.polynomial.content\n\n\nnoncomputable theory\nopen_locale polynomial classical\n\nnamespace polynomial\nopen unique_factorization_monoid\n\nvariables {k: Type*} [field k]\n\nlemma degree_ne_bot {a : k[X]} (ha : a \u2260 0) : a.degree \u2260 \u22a5 :=\n  by intro h; rw degree_eq_bot at h; exact ha h\n\n/-- Prime factors of a polynomial `a` are monic factors of `a` without duplication. -/\ndef prime_factors (a: k[X]) : finset (k[X]) := \n  (normalized_factors a).to_finset\n\n/-- Radical of a polynomial `a` is a product of prime factors of `a`. -/\ndef radical (a: k[X]) : k[X] := \n  (prime_factors a).prod id\n\nlemma radical_zero : radical (0 : k[X]) = 1 :=\nby rw [radical, prime_factors, normalized_factors_zero, multiset.to_finset_zero, finset.prod_empty]\n\nlemma radical_one : radical (1 : k[X]) = 1 :=\nby rw [radical, prime_factors, normalized_factors_one, multiset.to_finset_zero, finset.prod_empty]\n\nlemma radical_associated {a b : k[X]} (h : associated a b) : radical a = radical b :=\nbegin\n  rcases iff_iff_and_or_not_and_not.mp h.eq_zero_iff with \u27e8rfl, rfl\u27e9 | \u27e8ha, hb\u27e9,\n  { refl },\n  { simp_rw [radical, prime_factors],\n    rw (associated_iff_normalized_factors_eq_normalized_factors ha hb).mp h },\nend\n\nlemma radical_is_unit {a : k[X]} (h : is_unit a) : radical a = 1 :=\n(radical_associated (associated_one_iff_is_unit.mpr h)).trans radical_one\n\nlemma radical_unit {u : k[X]\u02e3} : radical (\u2191u: k[X]) = 1 :=\nradical_is_unit u.is_unit\n\nlemma radical_unit_mul {u : k[X]\u02e3} {a : k[X]} : radical (\u2191u * a) = radical a :=\nradical_associated (associated_unit_mul_left _ _ u.is_unit)\n\n/-- coprime polynomials have disjoint prime factors (as multisets). -/\nlemma is_coprime.disjoint_normalized_factors {a b : k[X]} (hc: is_coprime a b) : \n  (normalized_factors a).disjoint (normalized_factors b):=\nbegin\n  intros x hxa hxb,\n  have x_dvd_a := dvd_of_mem_normalized_factors hxa,\n  have x_dvd_b := dvd_of_mem_normalized_factors hxb,\n  have xp := prime_of_normalized_factor x hxa,\n  exact xp.not_unit (hc.is_unit_of_dvd' x_dvd_a x_dvd_b),\nend\n\n-- coprime polynomials have disjoint prime factors (as finsets)\nlemma is_coprime.disjoint_prime_factors {a b : k[X]} (hc: is_coprime a b) : \n  disjoint (prime_factors a) (prime_factors b):=\nbegin\n  exact multiset.disjoint_to_finset.mpr hc.disjoint_normalized_factors,\nend\n\nlemma _root_.is_coprime.mul_prime_factors_disj_union {a b : k[X]}\n  (ha : a \u2260 0) (hb : b \u2260 0) (hc : is_coprime a b) : \n  prime_factors (a * b) = \n    (prime_factors a).disj_union (prime_factors b) (hc.disjoint_prime_factors) :=\nbegin\n  rw [finset.disj_union_eq_union],\n  simp_rw prime_factors, \n  rw [normalized_factors_mul ha hb, multiset.to_finset_add],\nend\n\n-- possible TODO: the proof is unnecessarily long\n@[simp]\nlemma radical_neg_one : (-1 : k[X]).radical = 1 :=\nradical_is_unit (is_unit_one.neg)\n\nlemma radical_mul {a b : k[X]} (hc: is_coprime a b) : \n  (a * b).radical = a.radical * b.radical :=\nbegin\n  by_cases ha: a = 0,\n  { subst ha, rw is_coprime_zero_left at hc,\n    simp only [zero_mul, radical_zero, one_mul, radical_is_unit hc], },\n  by_cases hb: b = 0,\n  { subst hb, rw is_coprime_zero_right at hc,\n    simp only [mul_zero, radical_zero, mul_one, radical_is_unit hc], },\n  simp_rw radical,\n  rw hc.mul_prime_factors_disj_union ha hb,\n  rw finset.prod_disj_union (hc.disjoint_prime_factors),\nend\n\nlemma radical_neg {a : k[X]} : \n  (-a).radical = a.radical :=\nneg_one_mul a \u25b8 radical_associated $ associated_unit_mul_left a (-1) is_unit_one.neg\n\nlemma prime_factors_pow (a: k[X]) {n: \u2115} (hn: 1 \u2264 n) : \n  prime_factors (a^n) = prime_factors a :=\nbegin\n  simp_rw prime_factors,\n  simp only [normalized_factors_pow],\n  rw multiset.to_finset_nsmul,\n  exact ne_of_gt hn,\nend\n\nlemma radical_pow (a: k[X]) {n: nat} (hn: 0 < n) : \n  (a^n).radical = a.radical :=\nbegin\n  simp_rw [radical, prime_factors_pow a hn],\nend\n\nlemma radical_dvd_self (a : k[X]) : a.radical \u2223 a :=\nbegin\n  by_cases ha : a = 0,\n  { rw ha,\n    apply dvd_zero },\n  { rw [radical, \u2190 finset.prod_val, \u2190 (normalized_factors_prod ha).dvd_iff_dvd_right],\n    apply multiset.prod_dvd_prod_of_le,\n    rw [prime_factors, multiset.to_finset_val],\n    apply multiset.dedup_le },\nend\n\nlemma radical_ne_zero (a: k[X]) : a.radical \u2260 0 :=\nbegin\n  rw [radical, \u2190finset.prod_val],\n  apply multiset.prod_ne_zero,\n  rw prime_factors,\n  simp only [multiset.to_finset_val, multiset.mem_dedup], \n  exact zero_not_mem_normalized_factors _,\nend \n\nlemma radical_prime {a : k[X]} (ha: prime a) : \n  a.radical = normalize a :=\nbegin\n  rw [radical, prime_factors],\n  rw normalized_factors_irreducible ha.irreducible,\n  simp only [multiset.to_finset_singleton, id.def, finset.prod_singleton],\nend\n\nlemma radical_prime_pow {a : k[X]} (ha: prime a)\n  {n : \u2115} (hn : 1 \u2264 n): (a^n).radical = normalize a :=\nbegin\n  rw (a.radical_pow hn),\n  exact (radical_prime ha),\nend\n\nlemma radical_degree_le {a: k[X]} (ha : a \u2260 0) : \n  a.radical.degree \u2264 a.degree :=\nbegin\n  exact degree_le_of_dvd (radical_dvd_self a) ha,\nend\n\nlemma radical_nat_degree_le {a : k[X]} : \n  a.radical.nat_degree \u2264 a.nat_degree :=\nbegin\n  by_cases ha : a = 0,\n  { rw [ha, radical_zero, nat_degree_one, nat_degree_zero] },\n  { exact nat_degree_le_of_dvd (radical_dvd_self a) ha },\nend\n\nend polynomial\n", "meta": {"author": "seewoo5", "repo": "lean-poly-abc", "sha": "30649e24bee0182999d494b07847e2ddf06607ef", "save_path": "github-repos/lean/seewoo5-lean-poly-abc", "path": "github-repos/lean/seewoo5-lean-poly-abc/lean-poly-abc-30649e24bee0182999d494b07847e2ddf06607ef/src/lib/radical.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7444166908569768}}
{"text": "import data.nat.basic\nimport data.nat.modeq\nimport data.nat.gcd\nimport data.zmod.basic\nimport tactic\nimport algebra.euclidean_domain\nimport data.int.basic\nimport data.equiv.ring\nnoncomputable theory\n\nopen nat nat.modeq zmod euclidean_domain \nnamespace lemmas2\n\n/- LEMMAS FOR CHINESE REMAINDER THEOREM WITH 2 CONGRUENCE RELATIONS -/\n\n/--\nTwo natural numbers are equal if and only if they are mutual divisors\n-/\nlemma eq_iff_dvd_dvd {n m : \u2115 } : n = m \u2194 m \u2223 n \u2227 n \u2223 m :=\nbegin\n    split, \n    intro H, \n    rw H, \n    split; \n    refl,\n \n    intro H,\n    rcases H with \u27e8\u27e8c, hc\u27e9, \u27e8d, hd\u27e9\u27e9, \n    rw hd,\n    rw hc at hd,\n    induction m with x hx,  \n    rw zero_mul at hc,\n    rw hc,\n    ring,\n\n    rw mul_assoc at hd,\n    have hd' : x.succ * (c * d) = x.succ,\n        linarith,\n    rw mul_right_eq_self_iff at hd',\n    have h : d = 1,\n        rw nat.mul_eq_one_iff at hd',\n        exact hd'.2,\n    rw h,\n    ring,\n    exact succ_pos',\nend\n\n/-- \nGiven coprime natural numbers M1 M2, find the inverse of M2 M1 \nassuming that both are nonzero so avoid (1,0) case which is silly. \n-/\nlemma nat_inv (M1 M2 : \u2115 ) (M1pos : 0 < M1) (M2pos : 0 < M2) (H : coprime M1 M2) :\n                         \u2203 b1 : \u2115, modeq M1 (b1 * M2) 1 := \nbegin\n    -- first cast to Z/M1 Z and get the group inverse \n    have hb1 := mul_inv_eq_gcd (M2 : zmod M1),  \n    have H' := coprime.symm H,\n    unfold coprime at *, \n    rw val_nat_cast M2 at hb1, \n\n    have H'' : (M2 % M1).gcd M1 = M2.gcd M1, \n    begin\n        have qr  := div_add_mod (M2 : \u2124) (M1 : \u2124 ),\n        have qr' : (M1 * (M2 / M1) + M2 % M1) = M2,\n            begin\n                rw [\u2190 int.coe_nat_div M2 M1,\n                    \u2190 int.coe_nat_mod M2 M1,\n                    \u2190 int.coe_nat_mul _ _ ,\n                    \u2190 int.coe_nat_add _ _ ,\n                      int.coe_nat_inj'] at qr,\n                exact qr,\n            end,\n        -- want to show  M2.gcd M1 \u2223 (M2 % M1).gcd M1,\n        have div1 : M2.gcd M1 \u2223 (M2 % M1).gcd M1, \n        begin   \n            have f1 := gcd_dvd_left M2 M1,\n            have f2 := gcd_dvd_right M2 M1,\n            have f3 : M2.gcd M1 \u2223 M1 * (M2 / M1),\n                {cases f2 with c hc,\n                use c * (M2 / M1),\n                rw \u2190 mul_assoc,\n                rw \u2190 hc,},\n            have f4 : M2.gcd M1\u2223 M1 * (M2 / M1) + M2 % M1,\n                {rw qr',\n                exact f1,},\n            rw nat.dvd_add_right f3 at f4,\n            exact dvd_gcd f4 f2,\n        end,\n        -- want to show  (M2 % M1).gcd M1 \u2223 M2.gcd M1,\n        have div2 : (M2 % M1).gcd M1 \u2223 M2.gcd M1, \n        begin\n            have f1 := gcd_dvd_right (M2 % M1) M1,\n            have f2 := gcd_dvd_left (M2 % M1) M1,\n            have f3 := dvd_mul_of_dvd_left f1 (M2 / M1),\n            have f4 : (M2 % M1).gcd M1 \u2223 M2,\n            begin    \n                have k := (nat.dvd_add_right f3).2 f2,\n                rw qr' at k,  \n                exact k, \n            end,\n            exact dvd_gcd f4 f1,         \n        end,\n        have div : M2.gcd M1 \u2223 (M2 % M1).gcd M1 \u2227 (M2 % M1).gcd M1 \u2223 M2.gcd M1, \n            exact \u27e8div1, div2\u27e9,\n        rw \u2190 eq_iff_dvd_dvd at div,\n        exact div, \n    end,\n    -- use coprimeness and equality of gcd's to get as an actual inverse\n    rw [H'',H'] at hb1,     \n    use (M2 : zmod M1)\u207b\u00b9.val,\n    --translate this to zmod M1\n    rw \u2190 nat_coe_eq_nat_coe_iff _ _ _, \n    simp at *,\n    rw mul_comm,\n\n    have fact : (((M2 : zmod M1)\u207b\u00b9.val) : zmod M1) = (M2 : zmod M1)\u207b\u00b9,\n    begin\n        rw @nat_cast_zmod_val _ _,\n        use M1pos,\n    end,\n    rw fact,\n    exact hb1, \nend\n\n/- LEMMAS FOR CHINESE REMAINDER THEOREM WITH K CONGRUENCE RELATIONS -/\n\n\nend lemmas2\n\n\n", "meta": {"author": "amichaelsen", "repo": "Lean-Chinese-Remainder-Theorem", "sha": "9efb4b97da30e5aedb6af3c95d5132ac300f2902", "save_path": "github-repos/lean/amichaelsen-Lean-Chinese-Remainder-Theorem", "path": "github-repos/lean/amichaelsen-Lean-Chinese-Remainder-Theorem/Lean-Chinese-Remainder-Theorem-9efb4b97da30e5aedb6af3c95d5132ac300f2902/src/lemmas2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7444088751492344}}
{"text": "import game.sup_inf.level03\nimport data.real.basic\n\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 4 \n-/\n\n/-\nA generalization of the result in the previous level.\n-/\n\n-- begin hide\n-- these three helper results to go in sidebar\nlemma two_real_ne_zero : (2:\u211d) \u2260 0 :=\nbegin\n    intro, linarith,\nend\n\nlemma avg_lt_max {mn mx: \u211d} (H : mn < mx) : (mn+mx) / 2 < mx :=\nbegin\n  apply (mul_lt_mul_right (show (0:\u211d)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_real_ne_zero)],\n  simp [H,mul_two],\nend\n\nlemma min_lt_avg {mn mx: \u211d} (H : mn < mx) : mn < (mn+mx) / 2 :=\nbegin\n  apply (mul_lt_mul_right (show (0:\u211d)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_real_ne_zero)],\n  simp [H,mul_two],\nend\n-- end hide\n\n/- Lemma\nA more general version of the previous level...\n-/\nlemma lub_open (y : \u211d) : is_lub {x : \u211d | x < y} y :=\nbegin\n  split,\n  intro h,\n  intro j,\n  exact le_of_lt j,\n  intro h,\n  intro j,\n  refine le_of_not_gt _,\n  intro k,\n  let c := (h+y)/2,\n  have H2 := j c,\n  have H : c \u2208 {x : \u211d  | x < y},\n  exact avg_lt_max k,\n  have G := H2 H,\n  have P : h < c := min_lt_avg k,\n  exact not_lt.2 G P,\nend\n\nend xena -- hide\n\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/sup_inf/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.7444088733407094}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.free_module.finite.basic\nimport linear_algebra.matrix.charpoly.coeff\n\n/-!\n\n# Characteristic polynomial\n\nWe define the characteristic polynomial of `f : M \u2192\u2097[R] M`, where `M` is a finite and\nfree `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f`\nin any basis is in `linear_algebra/charpoly/to_matrix`.\n\n## Main definition\n\n* `linear_map.charpoly f` : the characteristic polynomial of `f : M \u2192\u2097[R] M`.\n\n-/\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} [comm_ring R] [nontrivial R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M] (f : M \u2192\u2097[R] M)\n\nopen_locale classical matrix polynomial\n\nnoncomputable theory\n\nopen module.free polynomial matrix\n\nnamespace linear_map\n\nsection basic\n\n/-- The characteristic polynomial of `f : M \u2192\u2097[R] M`. -/\ndef charpoly : R[X] :=\n(to_matrix (choose_basis R M) (choose_basis R M) f).charpoly\n\n\n\nend basic\n\nsection coeff\n\nlemma charpoly_monic : f.charpoly.monic := charpoly_monic _\n\nend coeff\n\nsection cayley_hamilton\n\n/-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied\nto the linear map itself, is zero.\n\nSee `matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/\nlemma aeval_self_charpoly : aeval f f.charpoly = 0 :=\nbegin\n  apply (linear_equiv.map_eq_zero_iff (alg_equiv_matrix _).to_linear_equiv).1,\n  rw [alg_equiv.to_linear_equiv_apply, \u2190 alg_equiv.coe_alg_hom,\n    \u2190 polynomial.aeval_alg_hom_apply _ _ _, charpoly_def],\n  exact aeval_self_charpoly _,\nend\n\nlemma is_integral : is_integral R f := \u27e8f.charpoly, \u27e8charpoly_monic f, aeval_self_charpoly f\u27e9\u27e9\n\nlemma minpoly_dvd_charpoly {K : Type u} {M : Type v} [field K] [add_comm_group M] [module K M]\n  [finite_dimensional K M] (f : M \u2192\u2097[K] M) : minpoly K f \u2223 f.charpoly :=\nminpoly.dvd _ _ (aeval_self_charpoly f)\n\n/-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %\u2098 f.charpoly`; that is,\n`p` is equivalent to a polynomial with degree less than the dimension of the module. -/\nlemma aeval_eq_aeval_mod_charpoly (p : R[X]) : aeval f p = aeval f (p %\u2098 f.charpoly) :=\n(aeval_mod_by_monic_eq_self_of_root f.charpoly_monic f.aeval_self_charpoly).symm\n\n/-- Any endomorphism power can be computed as the sum of endomorphism powers less than the\ndimension of the module. -/\nlemma pow_eq_aeval_mod_charpoly (k : \u2115) : f^k = aeval f (X^k %\u2098 f.charpoly) :=\nby rw [\u2190aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]\n\nvariable {f}\n\nlemma minpoly_coeff_zero_of_injective (hf : function.injective f) : (minpoly R f).coeff 0 \u2260 0 :=\nbegin\n  intro h,\n  obtain \u27e8P, hP\u27e9 := X_dvd_iff.2 h,\n  have hdegP : P.degree < (minpoly R f).degree,\n  { rw [hP, mul_comm],\n    refine degree_lt_degree_mul_X (\u03bb h, _),\n    rw [h, mul_zero] at hP,\n    exact minpoly.ne_zero (is_integral f) hP },\n  have hPmonic : P.monic,\n  { suffices : (minpoly R f).monic,\n    { rwa [monic.def, hP, mul_comm, leading_coeff_mul_X, \u2190 monic.def] at this },\n    exact minpoly.monic (is_integral f) },\n  have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _,\n  simp only [hP, mul_eq_comp, ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp, alg_hom.map_mul,\n    zero_apply] at hzero,\n  exact not_le.2 hdegP (minpoly.min _ _ hPmonic (ext hzero)),\nend\n\nend cayley_hamilton\n\nend linear_map\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/linear_algebra/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7444088685026312}}
{"text": "import algebra.module\nimport analysis.inner_product_space.basic\nimport data.matrix.notation\nimport data.matrix.dmatrix\nimport linear_algebra.basic\nimport linear_algebra.bilinear_form\nimport linear_algebra.quadratic_form.basic\nimport linear_algebra.finsupp\nimport tactic\nimport linear_algebra.matrix.nonsingular_inverse\n\nnoncomputable theory\n\n/-\nAccording to Wikipedia, everyone's favourite reliable source of knowledge,\nlinear algebra studies linear equations and linear maps, representing them\nin vector spaces and through matrices.\n\nVector spaces are special cases of modules where scalars live any semiring,\nnot necessarily a field.\n-/\n\n#print module\n-- class module (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M]\n-- extends distrib_mul_action R M := ...\n\n/-\nIn other words: let `R` be a semiring and `M` have `0` and a commutative operator `+`,\nthen a module structure over `R` on `M` has a scalar multiplication `\u2022` (`has_smul.smul`),\nwhich satisfies the following identities:\n-/\n#check add_smul -- \u2200 (r s : R) (x : M), (r + s) \u2022 x = r \u2022 x + s \u2022 x\n#check smul_add -- \u2200 (r : R) (x y : M), r \u2022 (x + y) = r \u2022 x + r \u2022 y\n#check mul_smul -- \u2200 (r s : R) (x : M), (r * s) \u2022 x = r \u2022 (s \u2022 x)\n#check one_smul -- \u2200 (x : M), 1 \u2022 x = x\n#check zero_smul -- \u2200 (x : M), 0 \u2022 x = 0\n#check smul_zero -- \u2200 (r : R), r \u2022 0 = 0\n/-\nThese equations define modules (and vector spaces).\n-/\n\n/-\nThe last two identities follow automatically from the previous if `M` has a negation operator,\nturning it into an additive group, so the function `module.of_core` does the proofs for you:\n-/\n#check module.of_core\n\nsection module\n\n/-\nTypical examples of modules (and vector spaces):\n-/\n-- import algebra.pi_instances\nvariables {n : Type} [fintype n]\nexample : module \u2115 (n \u2192 \u2115) := infer_instance -- Or as mathematicians commonly know it: `\u2115^n`.\nexample : module \u2124 (n \u2192 \u2124) := infer_instance\nexample : module \u211a (n \u2192 \u211a) := infer_instance\n\n\n/- If you want a specifically `k`-dimensional module, use `fin k` as the `fintype`. -/\nexample {k : \u2115} : module \u2124 (fin k \u2192 \u2124) := infer_instance\n\nvariables {R M N : Type} [ring R] [add_comm_group M] [add_comm_group N] [module R M] [module R N]\nexample : module R R := infer_instance\nexample : module \u2124 R := infer_instance\nexample : module R (M \u00d7 N) := infer_instance\nexample : module R (M \u00d7 N) := infer_instance\n\nexample {R' : Type} [comm_ring R'] (f : R \u2192+* R') : module R R' := ring_hom.to_module f\n\n/- To explicitly construct elements of `fin k \u2192 R`, use the following notation: -/\n-- import data.matrix.notation\nexample : fin 4 \u2192 \u2124 := ![1, 2, -4, 3]\n\nend module\n\nsection linear_map\n\nvariables {R M : Type} [comm_ring R] [add_comm_group M] [module R M]\n\n/-\nMaps between modules that respect `+` and `\u2022` are called `linear_map`,\nand an `R`-linear map from `M` to `N` has notation `M \u2192\u2097[R] N`:\n-/\n#print linear_map\n\n/- They are bundled, meaning we define them by giving the map and the proofs simultaneously: -/\ndef twice : M \u2192\u2097[R] M :=\n{ to_fun := \u03bb x, (2 : R) \u2022 x,\n  map_add' := \u03bb x y, smul_add 2 x y,\n  map_smul' := \u03bb s x, smul_comm 2 s x }\n\n/- Linear maps can be applied as if they were functions: -/\n#check twice (![37, 42] : fin 2 \u2192 \u211a)\n\n/- Some basic operations on linear maps: -/\n-- import linear_algebra.basic\n#check linear_map.comp -- composition\n#check linear_map.has_zero -- 0\n#check linear_map.has_add -- (+)\n#check linear_map.has_smul -- (\u2022)\n\n/-\nA linear equivalence is an invertible linear map.\nThese are the correct notion of \"isomorphism of modules\".\n-/\n#print linear_equiv\n/- The identity function is defined twice: once as linear map and once as linear equivalence. -/\n#check linear_map.id\n#check linear_equiv.refl\n\nend linear_map\n\nsection submodule\n\nvariables {R M : Type} [comm_ring R] [add_comm_group M] [module R M]\n\n/-\nThe submodules of a module `M` are subsets of `M` (i.e. elements of `set M`)\nthat are closed under the module operations `0`, `+` and `\u2022`.\n`subspace` is defined to be a special case of `submodule`.\n-/\n#print submodule\n#print subspace\n\n/-\nNote that the `ideal`s of a ring `R` are defined to be exactly the `R`-submodules of `R`.\nThis should save us a lot of re-definition work.\n-/\n#print ideal\n\n/-\nYou can directly define a submodule by giving its carrier subset and proving that\nthe carrier is closed under each operation:\n-/\ndef zero_submodule : submodule R M :=\n{ carrier := {0},\n  zero_mem' := by simp,\n  add_mem' := by { intros x y hx hy, simp at hx hy, simp [hx, hy] },\n  smul_mem' := by { intros r x hx, simp at hx, simp [hx] } }\n\n/- There are many library functions for defining submodules: -/\nvariables (S T : submodule R M)\n#check (twice.range : submodule R M) -- the image of `twice` in `M`\n#check (twice.ker : submodule R M) -- the kernel of `twice` in `M`\n#check submodule.span \u2124 {(2 : \u2124)} -- also known as 2\u2124\n#check S.map twice -- also known as {twice x | x \u2208 S}\n#check S.comap twice -- also known as {x | twice x \u2208 S}\n\n/- For submodule inclusion, we write `\u2264`: -/\n#check S \u2264 T\n#check S < T\n/- The zero submodule is written `\u22a5` and the whole module as a submodule is written `\u22a4`: -/\nexample {x : M} : x \u2208 (\u22a5 : submodule R M) \u2194 x = 0 := submodule.mem_bot R\nexample {x : M} : x \u2208 (\u22a4 : submodule R M) := submodule.mem_top\n/- Intersection and sum of submodules are usually written with the lattice operators `\u2293` and `\u2294`: -/\n#check submodule.mem_inf -- x \u2208 S \u2293 T \u2194 x \u2208 S \u2227 x \u2208 T\n#check submodule.mem_sup -- x \u2208 S \u2294 T \u2194 \u2203 (y \u2208 S) (z \u2208 T), x = y + z\n\n/- The embedding of a submodule in the ambient space, is called `subtype`: -/\n#check submodule.subtype\n\n/- Finally, we can take the quotient modulo a submodule.\nNote the nonstandard \u29f8, typed with \\quot .\n -/\n\n#check \u2124 \u29f8 submodule.span \u2124 {(2 : \u2124)}\n\nend submodule\n\nsection forms\n\nvariables {n R : Type} [comm_ring R] [fintype n]\n\n/- In addition to linear maps, there are bilinear forms, quadratic forms and sesquilinear forms. -/\n-- import linear_algebra.bilinear_form\n-- import linear_algebra.quadratic_form\n#check bilin_form\n\n/- Defining a bilinear form works similarly to defining a linear map: -/\ndef dot_product : bilin_form R (n \u2192 R) :=\n{ bilin := \u03bb x y, matrix.dot_product x y,\n  bilin_add_left := matrix.add_dot_product,\n  bilin_smul_left := matrix.smul_dot_product,\n  bilin_add_right := matrix.dot_product_add,\n  bilin_smul_right := matrix.dot_product_smul }\n\n/- Some other constructions on forms: -/\n#check bilin_form.to_quadratic_form\n#check quadratic_form.associated\n#check quadratic_form.has_smul\n#check quadratic_form.proj\n\nend forms\n\nsection matrix\n\nvariables {m n R : Type} [fintype m] [fintype n] [comm_ring R]\n\n/-\nMatrices in mathlib are basically no more than a rectangular block of entries.\nUnder the hood, they are specified by a function taking a row and column,\nand returning the entry at that index.\nThey are useful when you want to compute an invariant such as the determinant,\nas these are typically noncomputable for linear maps.\n\nA type of matrices `matrix m n \u03b1` requires that the types `m` and `n` of the indices\nare `fintype`s, and there is no restriction on the type `\u03b1` of the entries.\n-/\n#print matrix\n\n/-\nLike vectors in `n \u2192 R`, matrices are typically indexed over `fin k`.\nTo define a matrix, you map the indexes to the entry:\n-/\ndef example_matrix : matrix (fin 2) (fin 3) \u2124 := \u03bb i j, i + j\n#eval example_matrix 1 2\n\n/- Like vectors, we can use `![...]` notation to define matrices: -/\ndef other_example_matrix : matrix (fin 3) (fin 2) \u2124 :=\n![![0, 1],\n  ![1, 2],\n  ![2, 3]]\n\n/- We have the 0 matrix and the sum of two matrices: -/\nexample (i j) : (0 : matrix m n R) i j = 0 := dmatrix.zero_apply i j\nexample (A B : matrix m n R) (i j) : (A + B) i j = A i j + B i j := dmatrix.add_apply A B i j\n\n/-\nMatrices have multiplication and transpose operators `matrix.mul` and `matrix.transpose`.\nThe following line allows `\u2b1d` and `\u1d40` to stand for these two respectively:\n-/\nopen_locale matrix\n\n#check example_matrix \u2b1d other_example_matrix\n#check example_matrix\u1d40\n\n/- On square matrices, we have a semiring structure with `(*) = (\u2b1d)` and `1` as the identity matrix. -/\n#check matrix.semiring\n\n/-\nWhen working with matrices, a \"vector\" is always of the form `n \u2192 R`\nwhere `n` is a `fintype`. The operations between matrices and vectors are defined.\n-/\n#check matrix.col -- turn a vector into a column matrix\n#check matrix.row -- turn a vector into a row matrix\n#check matrix.vec_mul_vec -- column vector times row vector\n\n/-\nYou have to explicitly specify whether vectors are multiplied on the left or on the right:\n-/\n#check example_matrix.mul_vec -- (fin 3 \u2192 \u2124) \u2192 (fin 2 \u2192 \u2124), right multiplication\n#check matrix.vec_mul _ example_matrix -- (fin 2 \u2192 \u2124) \u2192 (fin 3 \u2192 \u2124), left multiplication\n\n/- You can convert a matrix to a linear map, which acts by right multiplication of vectors. -/\nvariables {M N : Type} [add_comm_group M] [add_comm_group N] [module R M] [module R N]\n#check matrix.to_lin' -- matrix m n R \u2192 ((n \u2192 R) \u2192\u2097[R] (m \u2192 R))\n\n/-\nGoing between linear maps and matrices is an isomorphism,\nas long as you have chosen a basis for each module.\n-/\nvariables [decidable_eq m] [decidable_eq n]\nvariables (v : basis m R M) (w : basis n R N)\n#check linear_map.to_matrix v w -- (M \u2192\u2097[R] N) \u2248\u2097[R] matrix n m R\n\n/-\nInvertible (i.e. nonsingular) matrices have an inverse operation denoted by `\u207b\u00b9`.\n-/\n#check matrix.inv_def\n\nend matrix\n\nsection odds_and_ends\n\n/- Other useful parts of the library: -/\n-- import analysis.inner_product_space.basic\n#print normed_space -- module with a norm\n#print inner_product_space -- normed space with an inner product in \u211d or \u2102\n\n#print finite_dimensional.finrank -- the rank (or dimension) of a space, as a natural number (infinity -> 0)\n#print module.rank -- the rank (or dimension) of a module (or vector space), as a cardinal\n\nend odds_and_ends\n", "meta": {"author": "leanprover-community", "repo": "lftcm2020", "sha": "cc683e2b074b61909310746d6acc1fb3d42d6ee2", "save_path": "github-repos/lean/leanprover-community-lftcm2020", "path": "github-repos/lean/leanprover-community-lftcm2020/lftcm2020-cc683e2b074b61909310746d6acc1fb3d42d6ee2/src/demos/linalg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.744408868208883}}
{"text": "/-\nCopyright (c) 2021 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n-/\nimport analysis.normed_space.ordered\nimport analysis.asymptotics.asymptotics\n\n/-!\n# A collection of specific asymptotic results\n\nThis file contains specific lemmas about asymptotics which don't have their place in the general\ntheory developped in `analysis.asymptotics.asymptotics`.\n-/\n\nopen filter asymptotics\nopen_locale topological_space\n\nsection linear_ordered_field\n\nvariables {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c]\n\nlemma pow_div_pow_eventually_eq_at_top {p q : \u2115} :\n  (\u03bb x : \ud835\udd5c, x^p / x^q) =\u1da0[at_top] (\u03bb x, x^((p : \u2124) -q)) :=\nbegin\n  apply ((eventually_gt_at_top (0 : \ud835\udd5c)).mono (\u03bb x hx, _)),\n  simp [zpow_sub\u2080 hx.ne'],\nend\n\nlemma pow_div_pow_eventually_eq_at_bot {p q : \u2115} :\n  (\u03bb x : \ud835\udd5c, x^p / x^q) =\u1da0[at_bot] (\u03bb x, x^((p : \u2124) -q)) :=\nbegin\n  apply ((eventually_lt_at_bot (0 : \ud835\udd5c)).mono (\u03bb x hx, _)),\n  simp [zpow_sub\u2080 hx.ne'.symm],\nend\n\nlemma tendsto_zpow_at_top_at_top {n : \u2124}\n  (hn : 0 < n) : tendsto (\u03bb x : \ud835\udd5c, x^n) at_top at_top :=\nbegin\n  lift n to \u2115 using hn.le,\n  simp only [zpow_coe_nat],\n  exact tendsto_pow_at_top (nat.succ_le_iff.mpr $int.coe_nat_pos.mp hn)\nend\n\nlemma tendsto_pow_div_pow_at_top_at_top {p q : \u2115}\n  (hpq : q < p) : tendsto (\u03bb x : \ud835\udd5c, x^p / x^q) at_top at_top :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma tendsto_pow_div_pow_at_top_zero [topological_space \ud835\udd5c] [order_topology \ud835\udd5c] {p q : \u2115}\n  (hpq : p < q) : tendsto (\u03bb x : \ud835\udd5c, x^p / x^q) at_top (\ud835\udcdd 0) :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_zpow_at_top_zero,\n  linarith\nend\n\nend linear_ordered_field\n\nsection normed_linear_ordered_field\n\nvariables {\ud835\udd5c : Type*} [normed_linear_ordered_field \ud835\udd5c]\n\nlemma asymptotics.is_o_pow_pow_at_top_of_lt\n  [order_topology \ud835\udd5c] {p q : \u2115} (hpq : p < q) :\n  is_o (\u03bb x : \ud835\udd5c, x^p) (\u03bb x, x^q) at_top :=\nbegin\n  refine (is_o_iff_tendsto' _).mpr (tendsto_pow_div_pow_at_top_zero hpq),\n  exact (eventually_gt_at_top 0).mono (\u03bb x hx hxq, (pow_ne_zero q hx.ne' hxq).elim),\nend\n\nlemma asymptotics.is_O.trans_tendsto_norm_at_top {\u03b1 : Type*} {u v : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n  (huv : is_O u v l) (hu : tendsto (\u03bb x, \u2225u x\u2225) l at_top) : tendsto (\u03bb x, \u2225v x\u2225) l at_top :=\nbegin\n  rcases huv.exists_pos with \u27e8c, hc, hcuv\u27e9,\n  rw is_O_with at hcuv,\n  convert tendsto.at_top_div_const hc (tendsto_at_top_mono' l hcuv hu),\n  ext x,\n  rw mul_div_cancel_left _ hc.ne.symm,\nend\n\nend normed_linear_ordered_field\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/asymptotics/specific_asymptotics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7443937044278628}}
{"text": "theorem le_of_succ_le_succ (a b : mynat) : succ a \u2264 succ b \u2192 a \u2264 b :=\nbegin\nintro h,\nrepeat { rw succ_eq_add_one at h },\ncases h with c hc,\nrw add_assoc a 1 c at hc,\nrw add_comm 1 c at hc,\nrw \u2190 add_assoc a c 1 at hc,\nrw add_right_cancel_iff at hc,\nrw hc,\nuse c, \nrefl,\nend", "meta": {"author": "nicholaspun", "repo": "natural-number-game-solutions", "sha": "1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0", "save_path": "github-repos/lean/nicholaspun-natural-number-game-solutions", "path": "github-repos/lean/nicholaspun-natural-number-game-solutions/natural-number-game-solutions-1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0/8-inequality-world/l12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533163686645, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7442719079849279}}
{"text": "import init.data.set\nimport set_theory.cardinal.basic\n\nopen set\nopen_locale cardinal\n\ntheorem mk_le_of_surjective {\u03b1 \u03b2 : Type} {f : \u03b1 \u2192 \u03b2} \n  (hf : function.surjective f) :\n  #\u03b1 \u2265 #\u03b2 :=\nbegin\n  fsplit,\n  fsplit,\n  exact function.surj_inv hf,\n  exact function.injective_surj_inv hf,\nend\n\ntheorem mk_le_of_injective {\u03b1 \u03b2 : Type} {f : \u03b1 \u2192 \u03b2}\n  (hf : function.injective f) :\n  #\u03b1 \u2264 #\u03b2 := \nbegin \n  fsplit,\n  fsplit,\n  assumption,\n  assumption,\nend", "meta": {"author": "crabbo-rave", "repo": "cantor", "sha": "2e690e45029d2d096ced1253897c200020eb5216", "save_path": "github-repos/lean/crabbo-rave-cantor", "path": "github-repos/lean/crabbo-rave-cantor/cantor-2e690e45029d2d096ced1253897c200020eb5216/src/set_relations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7442718915408011}}
{"text": "import data.set\nimport logic.basic\n\nopen set\n\nnamespace mth1001\n\nsection set_difference\n\nvariable U : Type* -- We'll have sets on the type `U`.\nvariables A B C : set U\n\n-- In addition to `mem_inter_iff` and `mem_union_eq` from the previous file, we'll\n-- now use `mem_diff` for the set difference\n\nexample (x : U) : x \u2208 A \\ B \u2194 x \u2208 A \u2227 x \u2209 B := by rw mem_diff\n\n-- We need the follow two lines to admit classical reasoning.\nopen classical\nlocal attribute [instance] prop_decidable\n\n-- In addition to the rules of propositional logic given in the previous file, we use\n-- De Morgan's laws, as follows.\n\nexample (p q : Prop) : \u00ac(p \u2227 q) \u2194 \u00acp \u2228 \u00acq := by rw not_and_distrib\nexample (p q : Prop) : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := by rw not_or_distrib\n\nexample : A \\ (B \u2229 C) = (A \\ B) \u222a (A \\ C) :=\nbegin\n  ext, -- Assume `x : U`. It suffices to prove `x \u2208 A \\ (B \u2229 C) \u2194 x \u2208  (A \\ B) \u222a (A \\ C)`. \n  -- Rewrite using definitions of set difference, intersection, and union.\n  rw [mem_diff, mem_union_eq, mem_inter_iff, mem_diff, mem_diff],\n  rw not_and_distrib,        -- De Morgan's law\n  rw and_or_distrib_left,    -- Distributivity of conjunction over disjunction\nend\n\n-- Exercise 138:\n-- In addition to De Morgan's law, the propositional logic aspect of the following problem requires\n-- several applications of the laws featured in the previous file. If you get irritated, the\n-- `tauto` tactic will close many goals in propositional logic.\nexample : A \\ (B \u222a C) = (A \\ B) \u2229 (A \\ C) :=\nbegin\n  ext,\n  rw [mem_diff, mem_union_eq, mem_inter_iff, mem_diff, mem_diff],\n  rw not_or_distrib,        -- De Morgan's law\n  rw and_comm (x \u2208 A) (x \u2209 B),\n  sorry  \nend \n\n\nend set_difference\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_26_set_difference.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7442160289570456}}
{"text": "import tactic\nimport data.int.parity\nimport data.int.modeq\nimport data.nat.factorization.basic\nimport number_theory.legendre_symbol.quadratic_reciprocity\n\n\nimport Mordell.CongruencesMod4\n\nlemma int.exists_nat_of_nonneg {z : \u2124} (hz : 0 \u2264 z) : \u2203 n : \u2115, \n  (n : \u2124) = z := \nbegin\n  use z.nat_abs,\n  exact int.nat_abs_of_nonneg hz,\nend\n\nlemma do_we_have (x : \u2124) (h : x^2 - 2*x + 4 \u2261 3 [ZMOD 4]) :\n  \u2203 (p : \u2115), p.prime \u2227 (p : int) \u2223 (x^2 - 2*x + 4)  \u2227 p \u2261 3 [MOD 4] := \nbegin\n  have h1 : (x^2 - 2*x + 4) = (x-1)^2 + 3:= by ring,\n  have h2 : 0 \u2264 x^2 - 2*x + 4,\n  { nlinarith, },\n  obtain \u27e8n, hn\u27e9  := int.exists_nat_of_nonneg h2,\n  rw \u2190 hn at h,\n  have h3 : n \u2261 3 [MOD 4],\n  unfold int.modeq at h,\n  unfold nat.modeq,\n  assumption_mod_cast,\n  obtain \u27e8p, hp1, hp2, hp3\u27e9 := three_modulo_four_prime_factor n h3,\n  refine \u27e8p, hp1, _, hp3\u27e9,\n  rwa [\u2190 hn, int.coe_nat_dvd],\nend\n\nexample (x y : \u2124) : y^2 \u2260 x^3 + 7 :=\nbegin\n  intro heq,\n  have oddx: odd x,\n    { apply int.odd_iff_not_even.2, \n      intro h, \n      rw even_iff_two_dvd at h,\n      have h3: 0 < 3,\n        {\n          norm_num,\n        },\n      rw \u2190 int.pow_dvd_pow_iff h3 at h,\n      norm_num at h,\n      rw \u2190 int.modeq_zero_iff_dvd at h,\n      have h2 := int.modeq.add_right 7 h,\n      rw \u2190 heq at h2,\n      norm_num at h2,\n      have h4:= int.square_ne_three_mod_four y,\n      apply h4,\n      clear h4,\n      have h6: (4 : \u2124 ) \u2223 8:= by norm_num,\n      have h5:= int.modeq.modeq_of_dvd h6 h2,\n      unfold int.modeq at h5 \u22a2,\n      rw h5,\n      norm_num,\n  },\n  have h2 : y^2+1=(x+2)*(x^2 - 2*x + 4),\n    { rw heq,\n      ring,\n    },\n  have h6 : (x-1)^2 + 3 \u2261  3 [ZMOD 4],\n    { rcases oddx with \u27e8n,rfl\u27e9,\n       ring_nf,\n       symmetry,\n       rw int.modeq_iff_dvd,\n       unfold has_dvd.dvd,\n       use n^2,\n       ring,\n    },\n  have h7 : (x^2 - 2*x + 4) = (x-1)^2 + 3:= by ring,\n  rw \u2190 h7 at h6,\n  obtain \u27e8p, hp, hpd, h8\u27e9  := do_we_have x h6,\n  have h9 : \u2191p\u2223y^2 + 1,\n  { rw h2,\n    exact dvd_mul_of_dvd_right hpd (x + 2), },\n  haveI : fact (nat.prime p) := \u27e8hp\u27e9,\n  set yp : zmod p := y with hyp0,\n  have hyp : yp^2 = -1,\n  { rw \u2190 zmod.int_coe_zmod_eq_zero_iff_dvd at h9,\n    push_cast at h9,\n    linear_combination h9, },\n  apply zmod.mod_four_ne_three_of_sq_eq_neg_one hyp,\n  rw nat.modeq at h8, \n  norm_num at h8,\n  assumption,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "diophantine", "sha": "93a407512156a7b13355a7d2fabb806f512362f5", "save_path": "github-repos/lean/ImperialCollegeLondon-diophantine", "path": "github-repos/lean/ImperialCollegeLondon-diophantine/diophantine-93a407512156a7b13355a7d2fabb806f512362f5/src/Mordell/7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7442160289570456}}
{"text": "-- vim: ts=2 sw=0 sts=-1 et ai tw=70\n\nimport .lt\nimport ..logic\nimport ..myset.basic\n\nnamespace hidden\n\nopen mynat\n\n-- proof of the principle of strong induction\n-- conceptually quite nice: works by showing that for any N, the\n-- statement will hold for all M less than or equal to that N.\ntheorem strong_induction\n(statement: mynat \u2192 Prop)\n(base_case: statement 0)\n(inductive_step: \u2200 n: mynat,\n                  (\u2200 m: mynat, m \u2264 n \u2192 statement m)\n                    \u2192 statement (succ n)):\n\u2200 k: mynat, statement k :=\nbegin\n  intro k,\n  have h_aux: \u2200 N: mynat, (\u2200 M: mynat, M \u2264 N \u2192 statement M), {\n    intro N,\n    induction N with N_n N_ih, {\n      simp,\n      intro M,\n      assume hMl0,\n      have hM0 := le_zero hMl0,\n      rw hM0,\n      from base_case,\n    }, {\n      intro M,\n      assume hMlesN,\n      cases hMlesN with d hd,\n      cases d, {\n        simp at hd,\n        rw \u2190hd,\n        from inductive_step N_n N_ih,\n      }, {\n        have hMleN: M \u2264 N_n, {\n          existsi d,\n          simp at hd,\n          assumption,\n        },\n        from N_ih M hMleN,\n      },\n    },\n  },\n  from h_aux (succ k) k (le_to_add: k \u2264 k + 1),\nend\n\n-- very similar. Formulating it in terms of the strict ordering\n-- makes the prerequisites seem easier, but my hot take is that\n-- this one is secretly much less nice\ntheorem strict_strong_induction\n(statement: mynat \u2192 Prop)\n(inductive_step: \u2200 n: mynat,\n                  (\u2200 m: mynat, m < n \u2192 statement m)\n                    \u2192 statement n):\n\u2200 k: mynat, statement k :=\nbegin\n  apply strong_induction, {\n    apply inductive_step,\n    intro m,\n    assume hm0,\n    exfalso,\n    from lt_nzero hm0,\n  }, {\n    intro n,\n    assume h_ih,\n    apply inductive_step,\n    intro m,\n    assume hmsn,\n    apply h_ih,\n    rw le_iff_lt_succ,\n    assumption,\n  },\nend\n\n-- can this be done in an even flashier one-term sort of way?\n-- it must be possible, right\ntheorem lt_well_founded : well_founded lt :=\nbegin\n  split,\n  intro a,\n  apply strict_strong_induction,\n  intro n,\n  assume h_ih,\n  split,\n  assumption,\nend\n\ninstance: has_well_founded mynat := \u27e8lt, lt_well_founded\u27e9\n\n\n-- induction with n base cases.\n-- Note the case with n = 0 is basically a direct proof,\n-- the case with n = 1 is regular induction.\n-- This is currently a bit of a pain to actually use, particularly for\n-- proving bases cases, hence the below special case. It would be\n-- really cool to have a tactic to just split the base cases into\n-- goals ^_^\ntheorem multi_induction\n(n: mynat)\n(statement: mynat \u2192 Prop)\n-- statement is true for 0, ..., n - 1\n(base_cases: \u2200 m: mynat, m < n \u2192 statement m)\n-- given the statement for m, ..., m + n - 1, the statement holds for\n-- m + n\n(inductive_step: \u2200 m: mynat,\n  (\u2200 d: mynat, d < n \u2192 statement (m + d)) \u2192 statement (m + n)):\n\u2200 m: mynat, statement m :=\nbegin\n  -- I'm not sure if this proof is the nicest way to go\n  apply strong_induction, {\n    -- yuckily, the base case depends on if n is 0 or not\n    cases n, {\n      apply inductive_step,\n      intro d,\n      assume hd0,\n      exfalso, from lt_nzero hd0,\n    }, {\n      apply base_cases,\n      from zero_lt_succ,\n    },\n  }, {\n    intro m,\n    by_cases (n \u2264 (succ m)), {\n      cases h with d hd,\n      rw hd,\n      assume h_sih,\n      rw add_comm,\n      apply inductive_step,\n      -- at this point it just takes a bit of wrangling to show the\n      -- obvious\n      intro d',\n      assume hdn,\n      apply h_sih,\n      rw [le_iff_lt_succ, hd, add_comm],\n      from lt_add hdn,\n    }, {\n      assume _,\n      from base_cases _ h,\n    },\n  },\nend\n\n-- theorem for convenience\ntheorem duo_induction\n(statement: mynat \u2192 Prop)\n(h0: statement 0)\n(h1: statement 1)\n(inductive_step: \u2200 m: mynat,\n  statement m \u2192 statement (m + 1) \u2192 statement (m + 2)):\n\u2200 m: mynat, statement m :=\nbegin\n  apply multi_induction 2, {\n    -- grind out base cases\n    intro m,\n    cases m, {\n      assume _, assumption,\n    }, {\n      cases m, {\n        assume _, assumption,\n      }, {\n        assume hcontr,\n        exfalso, from lt_nzero (lt_cancel 2 hcontr),\n      },\n    },\n  }, {\n    intro m,\n    intro hd,\n    apply inductive_step, {\n      apply hd 0,\n      from zero_lt_succ,\n    }, {\n      apply hd 1,\n      from lt_add zero_lt_succ,\n    },\n  },\nend\n\n-- oddly specific convenient way to prove conjunctive statements\n-- about mynat\ntheorem induction_conjunction\n(p q: mynat \u2192 Prop)\n(base_case: p 0 \u2227 q 0)\n(inductive_step:\n  \u2200 n, (p n \u2192 q n \u2192 p (succ n)) \u2227\n       (p n \u2192 q n \u2192 p (succ n) \u2192 q (succ n))):\n\u2200 n, p n \u2227 q n :=\nbegin\n  intro n,\n  induction n, {\n    from base_case,\n  }, {\n    have hpsn := (inductive_step n_n).left n_ih.left n_ih.right,\n    split, {\n      from hpsn,\n    }, {\n      from (inductive_step n_n).right n_ih.left n_ih.right hpsn,\n    },\n  },\nend\n\nopen classical\nlocal attribute [instance] prop_decidable\n\n-- Should help prove Bezout\ntheorem well_ordering\n{statement : mynat \u2192 Prop} :\n(\u2203 k : mynat, statement k) \u2192\n\u2203 k : mynat, statement k \u2227\n\u2200 j : mynat, (statement j) \u2192  k \u2264 j :=\nbegin\n  assume hex,\n  by_contradiction h,\n  rw not_exists at h,\n  -- Prove by strong_induction that it's true for all\n  -- if there is no smallest for which it is false.\n  have hall : \u2200 k : mynat, \u00ac(statement k), {\n    apply strong_induction (\u03bb k, \u00acstatement k), {\n      assume hs0,\n      have h0 := h 0,\n      rw not_and at h0,\n      have hcontra := h0 hs0,\n      suffices : \u2200 (j : mynat), statement j \u2192 0 \u2264 j,\n        contradiction,\n      intro j,\n      assume _,\n      from zero_le,\n    }, {\n      assume n hn hsucc,\n      have hnall := (not_and.mp (h (succ n))) hsucc,\n      cases not_forall.mp hnall with x hnx,\n      cases not_imp.mp hnx with hx hnotsucclex,\n      have hxlen : x \u2264 n, {\n        have hxltsucc : x < succ n, from hnotsucclex,\n        rw \u2190le_iff_lt_succ at hxltsucc, assumption,\n      },\n      have hcontra := hn x hxlen,\n      contradiction,\n    },\n  },\n  cases hex with k hk,\n  have hnk := hall k,\n  contradiction,\nend\n\n-- Intuitionist given well-ordering\ntheorem infinite_descent\n(statement : mynat \u2192 Prop) :\n(\u2200 k : mynat, (statement k \u2192 \u2203 j : mynat, statement j \u2227 j < k))\n\u2192 \u2200 k : mynat, \u00ac(statement k) :=\nbegin\n  assume h k hk,\n  have hex : \u2203 k : mynat, statement k \u2227\n             \u2200 j : mynat, (statement j) \u2192  k \u2264 j, {\n    apply well_ordering,\n    existsi k,\n    assumption,\n  },\n  cases hex with i hi,\n  cases hi with hil hir,\n  have hallile := h i hil,\n  cases hallile with j hj,\n  cases hj with hjl hjr,\n  have := hir j hjl,\n  contradiction,\nend\n\ntheorem descend_to_zero (p : mynat \u2192 Prop)\n(hdec: \u2200 {k}, p (succ k) \u2192 p k)\n: \u2200 {m}, p m \u2192 p 0\n| zero := assume h, by assumption\n| (succ m) := assume h, descend_to_zero (hdec h)\n\n\n/-- Lemma to shorten things a bit -/\nprivate lemma nempty_imp_exists {\u03b1 : Type} {S : myset \u03b1}\n(h : \u00acmyset.empty S) : \u2203 x, x \u2208 S :=\nby rwa myset.exists_iff_nempty\n\n-- TODO: Is this the right place for this? Is this the right name?\n-- Could make S implicit but this makes the goal state confusing,\n-- filled with _\n-- Notice we don't need to prove that there is a unique such element,\n-- though we do later to actually make it useful\n/-- Given a non-empty set of mynats, (noncomputably) get its least element, via\nwell-ordering -/\nnoncomputable def min (S : myset mynat) (h : \u00acmyset.empty S) : mynat :=\nclassical.some (well_ordering (nempty_imp_exists h))\n\n-- some_spec is a proof that `some` satifies its definition\ntheorem min_property {S : myset mynat} (hS : \u00acmyset.empty S) :\nmin S hS \u2208 S :=\n(classical.some_spec (well_ordering (nempty_imp_exists hS))).left\n\ntheorem min_le {S : myset mynat} {m : mynat}\n(hS : \u00acmyset.empty S) (hm : m \u2208 S) : min S hS \u2264 m :=\n(classical.some_spec (well_ordering (nempty_imp_exists hS))).right m hm\n\n-- Prove that the minimum is unique\n-- I called it min_rw because it allows you to rw inside min, if the sets\n-- are equal\ntheorem min_rw {S T : myset mynat} (hS : \u00acmyset.empty S) (hT : \u00acmyset.empty T)\n(h : S = T) : min S hS = min T hT :=\nbegin\n  apply mynat.le_antisymm; apply min_le,\n    rw h,\n  tactic.swap,\n  rw \u2190h,\n  all_goals { apply min_property, },\nend\n\nend hidden\n", "meta": {"author": "Sterrs", "repo": "leaning", "sha": "3901cc953694b33adda86cb88ca30ba99594db31", "save_path": "github-repos/lean/Sterrs-leaning", "path": "github-repos/lean/Sterrs-leaning/leaning-3901cc953694b33adda86cb88ca30ba99594db31/src/principia/mynat/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.7442160244248717}}
{"text": "-- Dos_por_a_igual_a_mas_a.lean\n-- Si R es un anillo y a \u2208 R, entonces 2 * a = a + a.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 13-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si R es un anillo y a \u2208 R, entonces\n--    2 * a = a + a\n-- ----------------------------------------------------------------------\n\nimport algebra.ring\n\nvariables {R : Type*} [ring R]\nvariables a : R\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 2 * a = a + a :=\ncalc\n  2 * a = (1 + 1) * a   : congr_fun (congr_arg has_mul.mul one_add_one_eq_two.symm) a\n  ...   = 1 * a + 1 * a : add_mul 1 1 a\n  ...   = a + 1 * a     : congr_arg (\u03bb x, x + 1 * a) (one_mul a)\n  ...   = a + a         : congr_arg (\u03bb x, a + x) (one_mul a)\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 2 * a = a + a :=\ncalc\n  2 * a = (1 + 1) * a   : by rw one_add_one_eq_two\n  ...   = 1 * a + 1 * a : by rw add_mul\n  ...   = a + a         : by rw one_mul\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 2 * a = a + a :=\nby rw [one_add_one_eq_two.symm, add_mul, one_mul]\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 2 * a = a + a :=\ncalc\n  2 * a = (1 + 1)  * a  : rfl\n  ...   = 1 * a + 1 * a : by simp [add_mul]\n  ...   = a + a         : by simp\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 2 * a = a + a :=\n-- by library_search\ntwo_mul a\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Dos_por_a_igual_a_mas_a.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114835, "lm_q2_score": 0.8418256512199032, "lm_q1q2_score": 0.744206951775541}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Benjamin Davidson\n-/\nimport data.nat.parity\n\n/-!\n# Parity of integers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains theorems about the `even` and `odd` predicates on the integers.\n\n## Tags\n\neven, odd\n-/\n\nnamespace int\n\nvariables {m n : \u2124}\n\n@[simp] theorem mod_two_ne_one : \u00ac n % 2 = 1 \u2194 n % 2 = 0 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\nlocal attribute [simp] -- euclidean_domain.mod_eq_zero uses (2 \u2223 n) as normal form\ntheorem mod_two_ne_zero : \u00ac n % 2 = 0 \u2194 n % 2 = 1 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\ntheorem even_iff : even n \u2194 n % 2 = 0 :=\n\u27e8\u03bb \u27e8m, hm\u27e9, by simp [\u2190 two_mul, hm], \u03bb h, \u27e8n / 2, (mod_add_div n 2).symm.trans\n  (by simp [\u2190 two_mul, h])\u27e9\u27e9\n\ntheorem odd_iff : odd n \u2194 n % 2 = 1 :=\n\u27e8\u03bb \u27e8m, hm\u27e9, by { rw [hm, add_mod], norm_num },\n \u03bb h, \u27e8n / 2, (mod_add_div n 2).symm.trans (by { rw h, abel })\u27e9\u27e9\n\nlemma not_even_iff : \u00ac even n \u2194 n % 2 = 1 :=\nby rw [even_iff, mod_two_ne_zero]\n\nlemma not_odd_iff : \u00ac odd n \u2194 n % 2 = 0 :=\nby rw [odd_iff, mod_two_ne_one]\n\nlemma even_iff_not_odd : even n \u2194 \u00ac odd n :=\nby rw [not_odd_iff, even_iff]\n\n@[simp] lemma odd_iff_not_even : odd n \u2194 \u00ac even n :=\nby rw [not_even_iff, odd_iff]\n\nlemma is_compl_even_odd : is_compl {n : \u2124 | even n} {n | odd n} :=\nby simp [\u2190 set.compl_set_of, is_compl_compl]\n\nlemma even_or_odd (n : \u2124) : even n \u2228 odd n :=\nor.imp_right odd_iff_not_even.2 $ em $ even n\n\nlemma even_or_odd' (n : \u2124) : \u2203 k, n = 2 * k \u2228 n = 2 * k + 1 :=\nby simpa only [\u2190 two_mul, exists_or_distrib, \u2190 odd, \u2190 even] using even_or_odd n\n\nlemma even_xor_odd (n : \u2124) : xor (even n) (odd n) :=\nbegin\n  cases even_or_odd n with h,\n  { exact or.inl \u27e8h, even_iff_not_odd.mp h\u27e9 },\n  { exact or.inr \u27e8h, odd_iff_not_even.mp h\u27e9 },\nend\n\nlemma even_xor_odd' (n : \u2124) : \u2203 k, xor (n = 2 * k) (n = 2 * k + 1) :=\nbegin\n  rcases even_or_odd n with \u27e8k, rfl\u27e9 | \u27e8k, rfl\u27e9;\n  use k,\n  { simpa only [\u2190 two_mul, xor, true_and, eq_self_iff_true, not_true, or_false, and_false]\n      using (succ_ne_self (2*k)).symm },\n  { simp only [xor, add_right_eq_self, false_or, eq_self_iff_true, not_true, not_false_iff,\n               one_ne_zero, and_self] },\nend\n\n@[simp] theorem two_dvd_ne_zero : \u00ac 2 \u2223 n \u2194 n % 2 = 1 :=\neven_iff_two_dvd.symm.not.trans not_even_iff\n\ninstance : decidable_pred (even : \u2124 \u2192 Prop) := \u03bb n, decidable_of_iff _ even_iff.symm\ninstance : decidable_pred (odd : \u2124 \u2192 Prop) := \u03bb n, decidable_of_iff _ odd_iff_not_even.symm\n\n@[simp] theorem not_even_one : \u00ac even (1 : \u2124) :=\nby rw even_iff; norm_num\n\n@[parity_simps] theorem even_add : even (m + n) \u2194 (even m \u2194 even n) :=\nby cases mod_two_eq_zero_or_one m with h\u2081 h\u2081;\n   cases mod_two_eq_zero_or_one n with h\u2082 h\u2082;\n   simp [even_iff, h\u2081, h\u2082, int.add_mod];\n   norm_num\n\ntheorem even_add' : even (m + n) \u2194 (odd m \u2194 odd n) :=\nby rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n\n@[simp] theorem not_even_bit1 (n : \u2124) : \u00ac even (bit1 n) :=\nby simp [bit1] with parity_simps\n\nlemma two_not_dvd_two_mul_add_one (n : \u2124) : \u00ac(2 \u2223 2 * n + 1) :=\nby { simp [add_mod], refl }\n\n@[parity_simps] theorem even_sub : even (m - n) \u2194 (even m \u2194 even n) :=\nby simp [sub_eq_add_neg] with parity_simps\n\ntheorem even_sub' : even (m - n) \u2194 (odd m \u2194 odd n) :=\nby rw [even_sub, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n\n@[parity_simps] theorem even_add_one : even (n + 1) \u2194 \u00ac even n :=\nby simp [even_add]\n\n@[parity_simps] theorem even_mul : even (m * n) \u2194 even m \u2228 even n :=\nby cases mod_two_eq_zero_or_one m with h\u2081 h\u2081;\n   cases mod_two_eq_zero_or_one n with h\u2082 h\u2082;\n   simp [even_iff, h\u2081, h\u2082, int.mul_mod];\n   norm_num\n\ntheorem odd_mul : odd (m * n) \u2194 odd m \u2227 odd n :=\nby simp [not_or_distrib] with parity_simps\n\ntheorem odd.of_mul_left (h : odd (m * n)) : odd m :=\n(odd_mul.mp h).1\n\ntheorem odd.of_mul_right (h : odd (m * n)) : odd n :=\n(odd_mul.mp h).2\n\n@[parity_simps] theorem even_pow {n : \u2115} : even (m ^ n) \u2194 even m \u2227 n \u2260 0 :=\nby { induction n with n ih; simp [*, even_mul, pow_succ], tauto }\n\ntheorem even_pow' {n : \u2115} (h : n \u2260 0) : even (m ^ n) \u2194 even m :=\neven_pow.trans $ and_iff_left h\n\n@[parity_simps] theorem odd_add : odd (m + n) \u2194 (odd m \u2194 even n) :=\nby rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even]\n\ntheorem odd_add' : odd (m + n) \u2194 (odd n \u2194 even m) :=\nby rw [add_comm, odd_add]\n\nlemma ne_of_odd_add (h : odd (m + n)) : m \u2260 n :=\n\u03bb hnot, by simpa [hnot] with parity_simps using h\n\n@[parity_simps] theorem odd_sub : odd (m - n) \u2194 (odd m \u2194 even n) :=\nby rw [odd_iff_not_even, even_sub, not_iff, odd_iff_not_even]\n\ntheorem odd_sub' : odd (m - n) \u2194 (odd n \u2194 even m) :=\nby rw [odd_iff_not_even, even_sub, not_iff, not_iff_comm, odd_iff_not_even]\n\nlemma even_mul_succ_self (n : \u2124) : even (n * (n + 1)) :=\nbegin\n  rw even_mul,\n  convert n.even_or_odd,\n  simp with parity_simps\nend\n\n@[simp, norm_cast] theorem even_coe_nat (n : \u2115) : even (n : \u2124) \u2194 even n :=\nby rw_mod_cast [even_iff, nat.even_iff]\n\n@[simp, norm_cast] theorem odd_coe_nat (n : \u2115) : odd (n : \u2124) \u2194 odd n :=\nby rw [odd_iff_not_even, nat.odd_iff_not_even, even_coe_nat]\n\n@[simp] theorem nat_abs_even : even n.nat_abs \u2194 even n :=\nby simp [even_iff_two_dvd, dvd_nat_abs, coe_nat_dvd_left.symm]\n\n@[simp] theorem nat_abs_odd : odd n.nat_abs \u2194 odd n :=\nby rw [odd_iff_not_even, nat.odd_iff_not_even, nat_abs_even]\n\nalias nat_abs_even \u2194 _ _root_.even.nat_abs\nalias nat_abs_odd \u2194 _ _root_.odd.nat_abs\n\nattribute [protected] even.nat_abs odd.nat_abs\n\nlemma four_dvd_add_or_sub_of_odd {a b : \u2124} (ha : odd a) (hb : odd b) : 4 \u2223 a + b \u2228 4 \u2223 a - b :=\nbegin\n  obtain \u27e8m, rfl\u27e9 := ha,\n  obtain \u27e8n, rfl\u27e9 := hb,\n  obtain h|h := int.even_or_odd (m + n),\n  { right,\n    rw [int.even_add, \u2190int.even_sub] at h,\n    obtain \u27e8k, hk\u27e9 := h,\n    convert dvd_mul_right 4 k,\n    rw [eq_add_of_sub_eq hk, mul_add, add_assoc, add_sub_cancel, \u2190 two_mul, \u2190mul_assoc],\n    refl },\n  { left,\n    obtain \u27e8k, hk\u27e9 := h,\n    convert dvd_mul_right 4 (k + 1),\n    rw [eq_sub_of_add_eq hk, add_right_comm, \u2190add_sub, mul_add, mul_sub, add_assoc, add_assoc,\n      sub_add, add_assoc, \u2190sub_sub (2 * n), sub_self, zero_sub, sub_neg_eq_add, \u2190mul_assoc,\n      mul_add],\n    refl },\nend\n\nlemma two_mul_div_two_of_even : even n \u2192 2 * (n / 2) = n :=\n\u03bb h, int.mul_div_cancel' (even_iff_two_dvd.mp h)\n\nlemma div_two_mul_two_of_even : even n \u2192 n / 2 * 2 = n := --int.div_mul_cancel\n\u03bb h, int.div_mul_cancel (even_iff_two_dvd.mp h)\n\nlemma two_mul_div_two_add_one_of_odd : odd n \u2192 2 * (n / 2) + 1 = n :=\nby { rintro \u27e8c, rfl\u27e9, rw mul_comm, convert int.div_add_mod' _ _, simpa [int.add_mod] }\n\nlemma div_two_mul_two_add_one_of_odd : odd n \u2192 n / 2 * 2 + 1 = n :=\nby { rintro \u27e8c, rfl\u27e9, convert int.div_add_mod' _ _, simpa [int.add_mod] }\n\nlemma add_one_div_two_mul_two_of_odd : odd n \u2192 1 + n / 2 * 2 = n :=\nby { rintro \u27e8c, rfl\u27e9, rw add_comm, convert int.div_add_mod' _ _, simpa [int.add_mod] }\n\nlemma two_mul_div_two_of_odd (h : odd n) : 2 * (n / 2) = n - 1 :=\neq_sub_of_add_eq (two_mul_div_two_add_one_of_odd h)\n\n-- Here are examples of how `parity_simps` can be used with `int`.\n\nexample (m n : \u2124) (h : even m) : \u00ac even (n + 3) \u2194 even (m^2 + m + n) :=\nby simp [*, (dec_trivial : \u00ac 2 = 0)] with parity_simps\n\nexample : \u00ac even (25394535 : \u2124) :=\nby simp\n\nend int\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7442069421873093}}
{"text": "import tutorial_world.level18_by_contra --hide\nopen IncidencePlane --hide\n\n/- Axiom :\nexistence (\u03a9 : Type) : \u2203 P Q R : \u03a9, P \u2260 Q \u2227 P \u2260 R \u2227 Q \u2260 R \u2227 R \u2209 (line_through P Q)\n-/\n\n/-\n# Incidence World\n\n## Level 1: The axioms of incidence.\n\nJust as the roof of a building cannot stand without the bricks that are glued to the floor, \nneither can theorems stand without axioms. In mathematics, we need to set down some starting points \nto build our knowledge, and this is why axioms should join the game. What are axioms? - you will be\nwondering... Axioms are unprovable statements which are assumed to be true because of their self-evidence. \nThey are served as a premise for further reasoning and arguments, so that we can reach new conclusions from them.\n\nBy travelling back in time to 300 B.C., we meet the great mathematician Euclid, who suggested the very \nfirst postulates of geometry in his well-known book **`Elements`**. Euclidean geometry can be built up from three\nseparate sets of axioms, each of them adding new independent notions that are needed to define the plane. These sets of axioms \nwere proposed by David Hilbert (1862-1943 AD), who made remarkable improvements in the foundations of geometry.\nThese three sets are called **incidence**, **order** and **congruence** (we might also want to add the **Parallel Axiom**).\n\nWhen it comes to the first set of axioms, there are up to three axioms of incidence. These are established to define\nthe primitive notions of **point**, **line** and the relationship between these two concepts, which is called **incidence**. Notice \nthat by \"incidence\" we mean whatever idea that satifies the axioms of incidence. Then, you will be wondering... are the\nnotions of \"point\" and \"line\" referring to whatever object of reality that satisfies the axioms of incidence? Exactly!\nBefore the axioms of incidence, these notions are **undefined**!\n\nIn fact, if we want to verify the consistency and independency of these axioms from one another, we need to create something \ncalled a **model**. A model consists of assigning the concepts that are mentioned in the axioms to whatever objects of reality we would like to imagine.\nAs long as all the `axioms of incidence` are satisfied by this model, we can then assure that this set of axioms is consistent. \nLet's introduce the axioms of incidence so that we can create a model that satisfies them!\n\n**A.1)** For every point P and for every point Q not equal to P, there exists a unique line \u2113 \"passing through\" (= incident with) P and Q.\n\n**A.2)** For every line \u2113, there exist two distinct points that \"pass through\" (= are incident with) it.  \n\n**A.3)** There exist three distinct points with the property that no line \"passes through\" (= is incident with) all three of them.\n\nIt might be useful for you to do a drawing in order to understand each of the axioms more clearly, but remember that mathematics\ndoes not understand drawings but logical relationships to build new knowledge!\n\nLet's make a model! For example, say that we have three distinct needles and thread. (**Note:** we must specify how many objects of each type\nwe have in order to be as rigorous as axioms are.) Then, we can define these three distinct needles as three distinct points and thread as the line \u2113.\nNow, we have to check if this model satisfies the axioms of incidence. If you try by your own, you will realise that the three axioms are being \nsatisfied at the same time and without contradicting one another. Then, the axioms of incidence are consistent! \n\nNow, notice that **the more axioms there exist, the more difficult it is to create a model that satisfies all of them.** For this reason, \n**the objective of axiomatic geometry is establishing as less axioms as possible to create a specific model that might be beautiful or applicable to reality.**\n\n## The axioms of incidence in Lean.\n\nHow do we make the computer understand such complex statements? By using Type Theory, it is possible to define these concepts in Lean! However, \nsome of them are such difficult for a computer to comprehend that they must be divided into more than one statement. For example, the first axiom is \ndivided into four statements: \n\n* `line_through (P Q : \u03a9) : Line \u03a9 := line_through' P Q`\n\n* `line_through_left (P Q : \u03a9) : P \u2208 (line_through P Q)`\n\n* `line_through_right (P Q : \u03a9) : Q \u2208 (line_through P Q)`\n\n* `incidence {P Q : \u03a9} {\u2113 : Line \u03a9} : P \u2260 Q \u2192 P \u2208 \u2113 \u2192 Q \u2208 \u2113 \u2192 \u2113 = line_through P Q`\n\nHere it comes the second axiom of incidence in Lean: \n\n* `line_contains_two_points (\u2113 : Line \u03a9) : \u2203 P Q : \u03a9, P \u2260 Q \u2227 \u2113 = line_through P Q`\n\nAnd, to finish with, the third one appears right below: \n\n* `existence (\u03a9 : Type) : \u2203 P Q R : \u03a9, P \u2260 Q \u2227 P \u2260 R \u2227 Q \u2260 R \u2227 R \u2209 (line_through P Q)`\n\nWith that being said, let's try to solve the first level of this world together! \n\n## Let's solve this level together!\n\nNow that we have learned the basic Lean tactics, we are ready to prove our first theorem! \n\nThe goal of this world is to prove the existence of triangles, but we will start showing that there is no line \nthat covers the whole plane. That is to say, every line misses at least one point.\n\nTo solve this level, we will need to use the third axiom of incidence. For this reason, the theorem statement \ncalled `existence` has been added to the list of our theorem statements (located at the left-hand side of the game screen).\n[**Remember:** Despite being in the Incidence World, we can freely use the theorem statements from the Tutorial World.]\n\n## Step 1: Thinking of a mathematical proof!\n\nTo begin with, we are going to understand why we need to start our proof by using the third axiom of incidence. Read the lemma \nof this level and do a drawing of the situation. Can you see that there is a point which is not in the line you have drawed? Now, go above and \nread the first two axioms of incidence. Then, come back here. Have you noticed it? All the points which are considered in the first two axioms \npass through a line! Meanwhile, if we want to prove our lemma, we need to generate a point which is not in a line! Now, go above and read the \nthird axiom of incidence. Because this is the only axiom that considers a point which is not in a line, we must start by using it!\n\nOnce we've discovered how to start our proof, let's now define the objects that we are going to use! First, we need three distinct points which \nwill be called A, B and C. Then, we need a plane \u03a9 that contains all of them! Now, you may be wondering if we have to define a line as well...\nThe answer is that we will have to define more than one line in fact, but we won't do this at the beginning of the proof because it's not necessary yet. \nHowever, you might be asking... why can we not define a line that passes through two of the three points that we have defined and say that the line misses \none of the points? The answer is simple: that is not what we want. If you read the lemma again, you will see that it considers **every** possible line of the plane. \nThen, if we define a line, we are just proving one case out of all the lines that could exist in a plane!\n\nBecause of this reason, **we must divide our proof into different cases**. That is, into different possible lines. Does this mean that we have to consider as many\ncases as lines exist in a plane? Absolutely not! If that was the case, we would need infinite lifes to finish that proof! What we need to do, instead, is to\n**provide as less cases as possible to prove that the lemma is true**. Then, **how do we know the minimum number of cases that are needed to prove this lemma?** \nThe answer to this question is **by knowing the minimum number of dimensions that are needed to satisfy the lemma**. If you try to prove this lemma in non-dimensional\nor one-dimensional spaces, you will see that it is not possible. However, in two-dimensional spaces (that is, the plane) it **is** possible to prove it. And because\nthe minimum number of points to build the plane is three, then we can prove this lemma just by generating three points. \n\nNow that we have divided the proof into three cases, it's time to talk about each of them. The strategy is to define a unique line for each of the cases so that\nexactly one point misses that line. To define the lines, we will make use of the first axiom of incidence, which is the only one that makes it possible when we've\nalready generated two or more points. Because these cases don't have to follow a specific order, we will just choose an arbitrary order to step through them. In the\nfirst case, we will define a line through the points A and B so that the line misses the point C. In the second one, we will define a line through the points A and C\nso that the line misses the point B. In the third one, we will define a line through the points B and C so that the line misses the point A. \n\nTo finish with, draw the situation of these three cases separately. Then, make sure that all of them satisfy the three axioms of incidence and answer the lemma of\nthis level at the same time. Read this section as many times as necessary to understand it so that you can enjoy the following steps to the maximum!\n\n## Step 2: Writing a mathematical proof in paper!\n\nBefore typing any tactic in Lean, writing the mathematical proof in paper first is a synonym of success! In this way, you will have a clear and structured strategy to\nface the level you are trying to complete! Now, read the mathematical proof in paper for this lemma and try to grasp every bit of it!\n\n**Claim:** Every line misses at least one point.\n\n**Proof:** \n\nBy the third axiom of incidence, let A, B and C be three non-collinear points that lie on the plane \u03a9. \n\nNow, we proceed with the proof by cases.\n\n**Case 1:** By the first axiom of incidence, let \u2113 be the line that is incident with the points A and B. Because of the third axiom of incidence, the line \u2113 \nin not incident with the point C.\n\n**Case 2:** By the first axiom of incidence, let \u2113 be the line that is incident with the points A and C. Because of the third axiom of incidence, the line \u2113 \nin not incident with the point B.\n\n**Case 3:** By the first axiom of incidence, let \u2113 be the line that is incident with the points B and C. Because of the third axiom of incidence, the line \u2113 \nin not incident with the point A.\n\nHence, we have shown that every line misses at least one point.\n\n## Step 3: Writing a mathematical proof in Lean!\n\nTo begin with, we generate three non-collinear points A, B and C in the plane \u03a9 by using the following theorem statement:\n\n`existence (\u03a9 : Type) : \u2203 P Q R : \u03a9, P \u2260 Q \u2227 P \u2260 R \u2227 Q \u2260 R \u2227 R \u2209 (line_through P Q)`\n\nTo do so, delete the `sorry` and type `rcases existence \u03a9 with \u27e8A, B, C, \u27e8hAB, hAC, hBC, h\u27e9\u27e9,` where \u03a9 is the plane, A, B and C are the points that lie on \nthat plane and `hAB`, `hAC`, `hBC` and `h` are the hypotheses `A \u2260 B`, `A \u2260 C`, `B \u2260 C` and `C \u2209 (line_through A B)`, respectively.\n\nThen, we proceed with the proof by cases. First, we type `by_cases hA : A \u2208 \u2113,`. This will break the proof into two cases. On the one hand, the one where the \npoint A is in the line \u2113. On the other hand, the one where the line \u2113 misses the point A. [**Recommendation:** Write curly braces to structure the proof. See level\n9 of Tutorial World in case you don't remember how to do it.] \n\nSubsequently, and inside the first case, we type `by_cases hB : B \u2208 \u2113,`. This will break the firt case into two cases. On the one hand, the one where the \npoints A and B are in the line \u2113. In this case, you will have to call the point C by typing `use C,`, since it is the one that satisfies the goal `\u22a2 \u2203 (P : \u03a9), P \u2209 \u2113`. Right\nafter, try to use the `incidence` theorem statement to change the goal from `\u22a2 C \u2209 \u2113` into `\u22a2 C \u2209 line_through A B`. On the other hand, it appears the one\nwhere the points A and C are in the line \u2113, so that \u2113 misses the point B. Because of this reason, `use B,` will close the goal automatically.\n\nTo finish with, you can finish the proof by solving the last case, which is the one where the line \u2113 misses the point A. Try to follow the train of thought from the\nprevious cases to complete this level. In case you get stuck, click right below for a hint. \n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nWhen using the `incidence` theorem statement, you are trying to \"substitute\" the line `\u2113` for the `line_through A B`. Try to find the Lean tactic that allows us\nto make progress. Still bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution. \n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\n\n/- Lemma :\nEvery line misses at least one point.\n-/\nlemma exists_point_not_in_line (\u2113 : Line \u03a9) : \u2203 (P : \u03a9), P \u2209 \u2113 :=\nbegin\n  rcases existence \u03a9 with \u27e8A, B, C, \u27e8hAB, hAC, hBC, h\u27e9\u27e9,\n  by_cases hA : A \u2208 \u2113,\n  {\n    by_cases hB : B \u2208 \u2113,\n    {\n      use C,\n      rw incidence hAB hA hB,\n      exact h,\n    },\n    {\n      use B,\n    }\n  },\n  {\n    use A,\n  },\n  \nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/incidence_world/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7442069352894198}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module data.mv_polynomial.funext\n! leanprover-community/mathlib commit da01792ca4894d4f3a98d06b6c50455e5ed25da3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Polynomial.RingDivision\nimport Mathbin.Data.MvPolynomial.Rename\nimport Mathbin.RingTheory.Polynomial.Basic\n\n/-!\n## Function extensionality for multivariate polynomials\n\nIn this file we show that two multivariate polynomials over an infinite integral domain are equal\nif they are equal upon evaluating them on an arbitrary assignment of the variables.\n\n# Main declaration\n\n* `mv_polynomial.funext`: two polynomials `\u03c6 \u03c8 : mv_polynomial \u03c3 R`\n  over an infinite integral domain `R` are equal if `eval x \u03c6 = eval x \u03c8` for all `x : \u03c3 \u2192 R`.\n\n-/\n\n\nnamespace MvPolynomial\n\nvariable {R : Type _} [CommRing R] [IsDomain R] [Infinite R]\n\nprivate theorem funext_fin {n : \u2115} {p : MvPolynomial (Fin n) R}\n    (h : \u2200 x : Fin n \u2192 R, eval x p = 0) : p = 0 :=\n  by\n  induction' n with n ih generalizing R\n  \u00b7 let e := MvPolynomial.isEmptyRingEquiv R (Fin 0)\n    apply e.injective\n    rw [RingEquiv.map_zero]\n    convert h finZeroElim\n    suffices\n      (eval\u2082_hom (RingHom.id _) (IsEmpty.elim' Fin.isEmpty)) p =\n        (eval finZeroElim : MvPolynomial (Fin 0) R \u2192+* R) p\n      by\n      rw [\u2190 this]\n      simp only [coe_eval\u2082_hom, is_empty_ring_equiv_apply, RingEquiv.trans_apply,\n        aeval_eq_eval\u2082_hom]\n      congr\n    exact eval\u2082_hom_congr rfl (Subsingleton.elim _ _) rfl\n  \u00b7 let e := (finSuccEquiv R n).toRingEquiv\n    apply e.injective\n    simp only [RingEquiv.map_zero]\n    apply Polynomial.funext\n    intro q\n    rw [Polynomial.eval_zero]\n    apply ih\n    swap\n    \u00b7 infer_instance\n    intro x\n    dsimp [e]\n    rw [fin_succ_equiv_apply]\n    calc\n      _ = eval _ p := _\n      _ = 0 := h _\n      \n    \u00b7 intro i\n      exact Fin.cases (eval x q) x i\n    apply induction_on p\n    \u00b7 intro r\n      simp only [eval_C, Polynomial.eval_C, RingHom.coe_comp, eval\u2082_hom_C]\n    \u00b7 intros\n      simp only [*, RingHom.map_add, Polynomial.eval_add]\n    \u00b7 intro \u03c6 i h\u03c6\n      simp only [*, eval_X, Polynomial.eval_mul, RingHom.map_mul, eval\u2082_hom_X']\n      congr 1\n      by_cases hi : i = 0\n      \u00b7 subst hi\n        simp only [Polynomial.eval_X, Fin.cases_zero]\n      \u00b7 rw [\u2190 Fin.succ_pred i hi]\n        simp only [eval_X, Polynomial.eval_C, Fin.cases_succ]\n    \u00b7 infer_instance\n#align mv_polynomial.funext_fin mv_polynomial.funext_fin\n\n/-- Two multivariate polynomials over an infinite integral domain are equal\nif they are equal upon evaluating them on an arbitrary assignment of the variables. -/\ntheorem funext {\u03c3 : Type _} {p q : MvPolynomial \u03c3 R} (h : \u2200 x : \u03c3 \u2192 R, eval x p = eval x q) :\n    p = q :=\n  by\n  suffices \u2200 p, (\u2200 x : \u03c3 \u2192 R, eval x p = 0) \u2192 p = 0\n    by\n    rw [\u2190 sub_eq_zero, this (p - q)]\n    simp only [h, RingHom.map_sub, forall_const, sub_self]\n  clear h p q\n  intro p h\n  obtain \u27e8n, f, hf, p, rfl\u27e9 := exists_fin_rename p\n  suffices p = 0 by rw [this, AlgHom.map_zero]\n  apply funext_fin\n  intro x\n  classical\n    convert h (Function.extend f x 0)\n    simp only [eval, eval\u2082_hom_rename, Function.extend_comp hf]\n#align mv_polynomial.funext MvPolynomial.funext\n\ntheorem funext_iff {\u03c3 : Type _} {p q : MvPolynomial \u03c3 R} :\n    p = q \u2194 \u2200 x : \u03c3 \u2192 R, eval x p = eval x q :=\n  \u27e8by rintro rfl <;> simp only [forall_const, eq_self_iff_true], funext\u27e9\n#align mv_polynomial.funext_iff MvPolynomial.funext_iff\n\nend MvPolynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/MvPolynomial/Funext.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7441344705848172}}
{"text": "/-\nCopyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.units\n! leanprover-community/mathlib commit 2258b40dacd2942571c8ce136215350c702dc78f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Basic\nimport Mathlib.Algebra.Group.Units\n\n/-! # The units of the natural numbers as a `Monoid` and `AddMonoid` -/\n\n\nnamespace Nat\n\ntheorem units_eq_one (u : \u2115\u02e3) : u = 1 :=\n  Units.ext <| Nat.eq_one_of_dvd_one \u27e8u.inv, u.val_inv.symm\u27e9\n#align nat.units_eq_one Nat.units_eq_one\n\ntheorem addUnits_eq_zero (u : AddUnits \u2115) : u = 0 :=\n  AddUnits.ext <| (Nat.eq_zero_of_add_eq_zero u.val_neg).1\n#align nat.add_units_eq_zero Nat.addUnits_eq_zero\n\n@[simp]\nprotected theorem isUnit_iff {n : \u2115} : IsUnit n \u2194 n = 1 :=\n  Iff.intro\n    (fun \u27e8u, hu\u27e9 =>\n      match n, u, hu, Nat.units_eq_one u with\n      | _, _, rfl, rfl => rfl)\n    fun h => h.symm \u25b8 \u27e81, rfl\u27e9\n#align nat.is_unit_iff Nat.isUnit_iff\n\ninstance unique_units : Unique \u2115\u02e3 where\n  default := 1\n  uniq := Nat.units_eq_one\n#align nat.unique_units Nat.unique_units\n\ninstance unique_addUnits : Unique (AddUnits \u2115) where\n  default := 0\n  uniq := Nat.addUnits_eq_zero\n#align nat.unique_add_units Nat.unique_addUnits\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7440720370630604}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.group.to_additive\nimport Mathlib.tactic.basic\nimport Mathlib.PostPort\n\nuniverses u l \n\nnamespace Mathlib\n\n/-!\n# Typeclasses for (semi)groups and monoid\n\nIn this file we define typeclasses for algebraic structures with one binary operation.\nThe classes are named `(add_)?(comm_)?(semigroup|monoid|group)`, where `add_` means that\nthe class uses additive notation and `comm_` means that the class assumes that the binary\noperation is commutative.\n\nThe file does not contain any lemmas except for\n\n* axioms of typeclasses restated in the root namespace;\n* lemmas required for instances.\n\nFor basic lemmas about these classes see `algebra.group.basic`.\n-/\n\n/- Additive \"sister\" structures.\n   Example, add_semigroup mirrors semigroup.\n   These structures exist just to help automation.\n   In an alternative design, we could have the binary operation as an\n   extra argument for semigroup, monoid, group, etc. However, the lemmas\n   would be hard to index since they would not contain any constant.\n   For example, mul_assoc would be\n\n   lemma mul_assoc {\u03b1 : Type u} {op : \u03b1 \u2192 \u03b1 \u2192 \u03b1} [semigroup \u03b1 op] :\n                   \u2200 a b c : \u03b1, op (op a b) c = op a (op b c) :=\n    semigroup.mul_assoc\n\n   The simplifier cannot effectively use this lemma since the pattern for\n   the left-hand-side would be\n\n        ?op (?op ?a ?b) ?c\n\n   Remark: we use a tactic for transporting theorems from the multiplicative fragment\n   to the additive one.\n-/\n\n/-- `left_mul g` denotes left multiplication by `g` -/\ndef left_add {G : Type u} [Add G] : G \u2192 G \u2192 G :=\n  fun (g x : G) => g + x\n\n/-- `right_mul g` denotes right multiplication by `g` -/\ndef right_mul {G : Type u} [Mul G] : G \u2192 G \u2192 G :=\n  fun (g x : G) => x * g\n\n/-- A semigroup is a type with an associative `(*)`. -/\nclass semigroup (G : Type u) \nextends Mul G\nwhere\n  mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c)\n\n/-- An additive semigroup is a type with an associative `(+)`. -/\nclass add_semigroup (G : Type u) \nextends Add G\nwhere\n  add_assoc : \u2200 (a b c : G), a + b + c = a + (b + c)\n\ntheorem mul_assoc {G : Type u} [semigroup G] (a : G) (b : G) (c : G) : a * b * c = a * (b * c) :=\n  semigroup.mul_assoc\n\nprotected instance add_semigroup.to_is_associative {G : Type u} [add_semigroup G] : is_associative G Add.add :=\n  is_associative.mk add_assoc\n\n/-- A commutative semigroup is a type with an associative commutative `(*)`. -/\nclass comm_semigroup (G : Type u) \nextends semigroup G\nwhere\n  mul_comm : \u2200 (a b : G), a * b = b * a\n\n/-- A commutative additive semigroup is a type with an associative commutative `(+)`. -/\nclass add_comm_semigroup (G : Type u) \nextends add_semigroup G\nwhere\n  add_comm : \u2200 (a b : G), a + b = b + a\n\ntheorem mul_comm {G : Type u} [comm_semigroup G] (a : G) (b : G) : a * b = b * a :=\n  comm_semigroup.mul_comm\n\nprotected instance comm_semigroup.to_is_commutative {G : Type u} [comm_semigroup G] : is_commutative G Mul.mul :=\n  is_commutative.mk mul_comm\n\n/-- A `left_cancel_semigroup` is a semigroup such that `a * b = a * c` implies `b = c`. -/\nclass left_cancel_semigroup (G : Type u) \nextends semigroup G\nwhere\n  mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c\n\n/-- An `add_left_cancel_semigroup` is an additive semigroup such that\n`a + b = a + c` implies `b = c`. -/\nclass add_left_cancel_semigroup (G : Type u) \nextends add_semigroup G\nwhere\n  add_left_cancel : \u2200 (a b c : G), a + b = a + c \u2192 b = c\n\ntheorem mul_left_cancel {G : Type u} [left_cancel_semigroup G] {a : G} {b : G} {c : G} : a * b = a * c \u2192 b = c :=\n  left_cancel_semigroup.mul_left_cancel a b c\n\ntheorem mul_left_cancel_iff {G : Type u} [left_cancel_semigroup G] {a : G} {b : G} {c : G} : a * b = a * c \u2194 b = c :=\n  { mp := mul_left_cancel, mpr := congr_arg fun {b : G} => a * b }\n\ntheorem mul_right_injective {G : Type u} [left_cancel_semigroup G] (a : G) : function.injective (Mul.mul a) :=\n  fun (b c : G) => mul_left_cancel\n\n@[simp] theorem add_right_inj {G : Type u} [add_left_cancel_semigroup G] (a : G) {b : G} {c : G} : a + b = a + c \u2194 b = c :=\n  function.injective.eq_iff (add_right_injective a)\n\n/-- A `right_cancel_semigroup` is a semigroup such that `a * b = c * b` implies `a = c`. -/\nclass right_cancel_semigroup (G : Type u) \nextends semigroup G\nwhere\n  mul_right_cancel : \u2200 (a b c : G), a * b = c * b \u2192 a = c\n\n/-- An `add_right_cancel_semigroup` is an additive semigroup such that\n`a + b = c + b` implies `a = c`. -/\nclass add_right_cancel_semigroup (G : Type u) \nextends add_semigroup G\nwhere\n  add_right_cancel : \u2200 (a b c : G), a + b = c + b \u2192 a = c\n\ntheorem mul_right_cancel {G : Type u} [right_cancel_semigroup G] {a : G} {b : G} {c : G} : a * b = c * b \u2192 a = c :=\n  right_cancel_semigroup.mul_right_cancel a b c\n\ntheorem add_right_cancel_iff {G : Type u} [add_right_cancel_semigroup G] {a : G} {b : G} {c : G} : b + a = c + a \u2194 b = c :=\n  { mp := add_right_cancel, mpr := congr_arg fun {b : G} => b + a }\n\ntheorem add_left_injective {G : Type u} [add_right_cancel_semigroup G] (a : G) : function.injective fun (x : G) => x + a :=\n  fun (b c : G) => add_right_cancel\n\n@[simp] theorem add_left_inj {G : Type u} [add_right_cancel_semigroup G] (a : G) {b : G} {c : G} : b + a = c + a \u2194 b = c :=\n  function.injective.eq_iff (add_left_injective a)\n\n/-- A `monoid` is a `semigroup` with an element `1` such that `1 * a = a * 1 = a`. -/\nclass monoid (M : Type u) \nextends semigroup M, HasOne M\nwhere\n  one_mul : \u2200 (a : M), 1 * a = a\n  mul_one : \u2200 (a : M), a * 1 = a\n\n/-- An `add_monoid` is an `add_semigroup` with an element `0` such that `0 + a = a + 0 = a`. -/\nclass add_monoid (M : Type u) \nextends HasZero M, add_semigroup M\nwhere\n  zero_add : \u2200 (a : M), 0 + a = a\n  add_zero : \u2200 (a : M), a + 0 = a\n\n@[simp] theorem one_mul {M : Type u} [monoid M] (a : M) : 1 * a = a :=\n  monoid.one_mul\n\n@[simp] theorem add_zero {M : Type u} [add_monoid M] (a : M) : a + 0 = a :=\n  add_monoid.add_zero\n\nprotected instance monoid_to_is_left_id {M : Type u} [monoid M] : is_left_id M Mul.mul 1 :=\n  is_left_id.mk monoid.one_mul\n\nprotected instance add_monoid_to_is_right_id {M : Type u} [add_monoid M] : is_right_id M Add.add 0 :=\n  is_right_id.mk add_monoid.add_zero\n\ntheorem left_neg_eq_right_neg {M : Type u} [add_monoid M] {a : M} {b : M} {c : M} (hba : b + a = 0) (hac : a + c = 0) : b = c := sorry\n\n/-- A commutative monoid is a monoid with commutative `(*)`. -/\nclass comm_monoid (M : Type u) \nextends comm_semigroup M, monoid M\nwhere\n\n/-- An additive commutative monoid is an additive monoid with commutative `(+)`. -/\nclass add_comm_monoid (M : Type u) \nextends add_comm_semigroup M, add_monoid M\nwhere\n\n/-- An additive monoid in which addition is left-cancellative.\nMain examples are `\u2115` and groups. This is the right typeclass for many sum lemmas, as having a zero\nis useful to define the sum over the empty set, so `add_left_cancel_semigroup` is not enough. -/\n-- TODO: I found 1 (one) lemma assuming `[add_left_cancel_monoid]`.\n\nclass add_left_cancel_monoid (M : Type u) \nextends add_left_cancel_semigroup M, add_monoid M\nwhere\n\n-- Should we port more lemmas to this typeclass?\n\n/-- A monoid in which multiplication is left-cancellative. -/\nclass left_cancel_monoid (M : Type u) \nextends left_cancel_semigroup M, monoid M\nwhere\n\n/-- Commutative version of add_left_cancel_monoid. -/\nclass add_left_cancel_comm_monoid (M : Type u) \nextends add_left_cancel_monoid M, add_comm_monoid M\nwhere\n\n/-- Commutative version of left_cancel_monoid. -/\nclass left_cancel_comm_monoid (M : Type u) \nextends left_cancel_monoid M, comm_monoid M\nwhere\n\n/-- An additive monoid in which addition is right-cancellative.\nMain examples are `\u2115` and groups. This is the right typeclass for many sum lemmas, as having a zero\nis useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/\nclass add_right_cancel_monoid (M : Type u) \nextends add_monoid M, add_right_cancel_semigroup M\nwhere\n\n/-- A monoid in which multiplication is right-cancellative. -/\nclass right_cancel_monoid (M : Type u) \nextends right_cancel_semigroup M, monoid M\nwhere\n\n/-- Commutative version of add_right_cancel_monoid. -/\nclass add_right_cancel_comm_monoid (M : Type u) \nextends add_right_cancel_monoid M, add_comm_monoid M\nwhere\n\n/-- Commutative version of right_cancel_monoid. -/\nclass right_cancel_comm_monoid (M : Type u) \nextends right_cancel_monoid M, comm_monoid M\nwhere\n\n/-- An additive monoid in which addition is cancellative on both sides.\nMain examples are `\u2115` and groups. This is the right typeclass for many sum lemmas, as having a zero\nis useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/\nclass add_cancel_monoid (M : Type u) \nextends add_left_cancel_monoid M, add_right_cancel_monoid M\nwhere\n\n/-- A monoid in which multiplication is cancellative. -/\nclass cancel_monoid (M : Type u) \nextends left_cancel_monoid M, right_cancel_monoid M\nwhere\n\n/-- Commutative version of add_cancel_monoid. -/\nclass add_cancel_comm_monoid (M : Type u) \nextends add_left_cancel_comm_monoid M, add_right_cancel_comm_monoid M\nwhere\n\n/-- Commutative version of cancel_monoid. -/\nclass cancel_comm_monoid (M : Type u) \nextends right_cancel_comm_monoid M, left_cancel_comm_monoid M\nwhere\n\n/-- `try_refl_tac` solves goals of the form `\u2200 a b, f a b = g a b`,\nif they hold by definition. -/\n/-- A `div_inv_monoid` is a `monoid` with operations `/` and `\u207b\u00b9` satisfying\n`div_eq_mul_inv : \u2200 a b, a / b = a * b\u207b\u00b9`.\n\nThis is the immediate common ancestor of `group` and `group_with_zero`,\nin order to deduplicate the name `div_eq_mul_inv`.\nThe default for `div` is such that `a / b = a * b\u207b\u00b9` holds by definition.\n\nAdding `div` as a field rather than defining `a / b := a * b\u207b\u00b9` allows us to\navoid certain classes of unification failures, for example:\nLet `foo X` be a type with a `\u2200 X, has_div (foo X)` instance but no\n`\u2200 X, has_inv (foo X)`, e.g. when `foo X` is a `euclidean_domain`. Suppose we\nalso have an instance `\u2200 X [cromulent X], group_with_zero (foo X)`. Then the\n`(/)` coming from `group_with_zero_has_div` cannot be definitionally equal to\nthe `(/)` coming from `foo.has_div`.\n-/\nclass div_inv_monoid (G : Type u) \nextends Div G, monoid G, has_inv G\nwhere\n  div_eq_mul_inv : autoParam (\u2200 (a b : G), a / b = a * (b\u207b\u00b9))\n  (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring \"Mathlib.try_refl_tac\")\n    (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous \"Mathlib\") \"try_refl_tac\") [])\n\n/-- A `sub_neg_monoid` is an `add_monoid` with unary `-` and binary `-` operations\nsatisfying `sub_eq_add_neg : \u2200 a b, a - b = a + -b`.\n\nThe default for `sub` is such that `a - b = a + -b` holds by definition.\n\nAdding `sub` as a field rather than defining `a - b := a + -b` allows us to\navoid certain classes of unification failures, for example:\nLet `foo X` be a type with a `\u2200 X, has_sub (foo X)` instance but no\n`\u2200 X, has_neg (foo X)`. Suppose we also have an instance\n`\u2200 X [cromulent X], add_group (foo X)`. Then the `(-)` coming from\n`add_group.has_sub` cannot be definitionally equal to the `(-)` coming from\n`foo.has_sub`.\n-/\nclass sub_neg_monoid (G : Type u) \nextends Sub G, Neg G, add_monoid G\nwhere\n  sub_eq_add_neg : autoParam (\u2200 (a b : G), a - b = a + -b)\n  (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring \"Mathlib.try_refl_tac\")\n    (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous \"Mathlib\") \"try_refl_tac\") [])\n\ntheorem sub_eq_add_neg {G : Type u} [sub_neg_monoid G] (a : G) (b : G) : a - b = a + -b :=\n  sub_neg_monoid.sub_eq_add_neg\n\n/-- A `group` is a `monoid` with an operation `\u207b\u00b9` satisfying `a\u207b\u00b9 * a = 1`.\n\nThere is also a division operation `/` such that `a / b = a * b\u207b\u00b9`,\nwith a default so that `a / b = a * b\u207b\u00b9` holds by definition.\n-/\nclass group (G : Type u) \nextends div_inv_monoid G\nwhere\n  mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1\n\n/-- An `add_group` is an `add_monoid` with a unary `-` satisfying `-a + a = 0`.\n\nThere is also a binary operation `-` such that `a - b = a + -b`,\nwith a default so that `a - b = a + -b` holds by definition.\n-/\nclass add_group (A : Type u) \nextends sub_neg_monoid A\nwhere\n  add_left_neg : \u2200 (a : A), -a + a = 0\n\n/-- Abbreviation for `@div_inv_monoid.to_monoid _ (@group.to_div_inv_monoid _ _)`.\n\nUseful because it corresponds to the fact that `Grp` is a subcategory of `Mon`.\nNot an instance since it duplicates `@div_inv_monoid.to_monoid _ (@group.to_div_inv_monoid _ _)`.\n-/\ndef group.to_monoid (G : Type u) [group G] : monoid G :=\n  div_inv_monoid.to_monoid G\n\n@[simp] theorem mul_left_inv {G : Type u} [group G] (a : G) : a\u207b\u00b9 * a = 1 :=\n  group.mul_left_inv\n\ntheorem inv_mul_self {G : Type u} [group G] (a : G) : a\u207b\u00b9 * a = 1 :=\n  mul_left_inv a\n\n@[simp] theorem neg_add_cancel_left {G : Type u} [add_group G] (a : G) (b : G) : -a + (a + b) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-a + (a + b) = b)) (Eq.symm (add_assoc (-a) a b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a + a + b = b)) (add_left_neg a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 + b = b)) (zero_add b))) (Eq.refl b)))\n\n@[simp] theorem inv_eq_of_mul_eq_one {G : Type u} [group G] {a : G} {b : G} (h : a * b = 1) : a\u207b\u00b9 = b :=\n  left_inv_eq_right_inv (inv_mul_self a) h\n\n@[simp] theorem inv_inv {G : Type u} [group G] (a : G) : a\u207b\u00b9\u207b\u00b9 = a :=\n  inv_eq_of_mul_eq_one (mul_left_inv a)\n\n@[simp] theorem add_right_neg {G : Type u} [add_group G] (a : G) : a + -a = 0 :=\n  (fun (this : --a + -a = 0) => eq.mp (Eq._oldrec (Eq.refl ( --a + -a = 0)) (neg_neg a)) this) (add_left_neg (-a))\n\ntheorem add_neg_self {G : Type u} [add_group G] (a : G) : a + -a = 0 :=\n  add_right_neg a\n\n@[simp] theorem mul_inv_cancel_right {G : Type u} [group G] (a : G) (b : G) : a * b * (b\u207b\u00b9) = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b * (b\u207b\u00b9) = a)) (mul_assoc a b (b\u207b\u00b9))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (b * (b\u207b\u00b9)) = a)) (mul_right_inv b)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a * 1 = a)) (mul_one a))) (Eq.refl a)))\n\nprotected instance add_group.to_cancel_add_monoid {G : Type u} [add_group G] : add_cancel_monoid G :=\n  add_cancel_monoid.mk add_group.add add_group.add_assoc sorry add_group.zero add_group.zero_add add_group.add_zero sorry\n\n/-- A commutative group is a group with commutative `(*)`. -/\n/-- An additive commutative group is an additive group with commutative `(+)`. -/\nclass comm_group (G : Type u) \nextends group G, comm_monoid G\nwhere\n\nclass add_comm_group (G : Type u) \nextends add_group G, add_comm_monoid G\nwhere\n\nprotected instance comm_group.to_cancel_comm_monoid {G : Type u} [comm_group G] : cancel_comm_monoid G :=\n  cancel_comm_monoid.mk comm_group.mul comm_group.mul_assoc sorry comm_group.one comm_group.one_mul comm_group.mul_one\n    comm_group.mul_comm sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/group/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7440720184212647}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\nimport group_theory.submonoid.center\n\n/-!\n# Centralizers of magmas and monoids\n\n## Main definitions\n\n* `set.centralizer`: the center of a magma\n* `submonoid.centralizer`: the center of a monoid\n* `set.add_centralizer`: the center of an additive magma\n* `add_submonoid.centralizer`: the center of an additive monoid\n\nWe provide `subgroup.centralizer`, `add_subgroup.centralizer` in other files.\n-/\n\nvariables {M : Type*} {S T : set M}\n\nnamespace set\n\nvariables (S)\n\n/-- The centralizer of a subset of a magma. -/\n@[to_additive add_centralizer /-\" The centralizer of a subset of an additive magma. \"-/]\ndef centralizer [has_mul M] : set M := {c | \u2200 m \u2208 S, m * c = c * m}\n\nvariables {S}\n\n@[to_additive mem_add_centralizer]\nlemma mem_centralizer_iff [has_mul M] {c : M} : c \u2208 centralizer S \u2194 \u2200 m \u2208 S, m * c = c * m :=\niff.rfl\n\n@[to_additive decidable_mem_add_centralizer]\ninstance decidable_mem_centralizer [has_mul M] [decidable_eq M] [fintype M]\n  [decidable_pred (\u2208 S)] : decidable_pred (\u2208 centralizer S) :=\n\u03bb _, decidable_of_iff' _ (mem_centralizer_iff)\n\nvariables (S)\n\n@[simp, to_additive zero_mem_add_centralizer]\nlemma one_mem_centralizer [mul_one_class M] : (1 : M) \u2208 centralizer S :=\nby simp [mem_centralizer_iff]\n\n@[simp]\nlemma zero_mem_centralizer [mul_zero_class M] : (0 : M) \u2208 centralizer S :=\nby simp [mem_centralizer_iff]\n\nvariables {S} {a b : M}\n\n@[simp, to_additive add_mem_add_centralizer]\nlemma mul_mem_centralizer [semigroup M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a * b \u2208 centralizer S :=\n\u03bb g hg, by rw [mul_assoc, \u2190hb g hg, \u2190 mul_assoc, ha g hg, mul_assoc]\n\n@[simp, to_additive neg_mem_add_centralizer]\nlemma inv_mem_centralizer [group M] (ha : a \u2208 centralizer S) : a\u207b\u00b9 \u2208 centralizer S :=\n\u03bb g hg, by rw [mul_inv_eq_iff_eq_mul, mul_assoc, eq_inv_mul_iff_mul_eq, ha g hg]\n\n@[simp]\nlemma add_mem_centralizer [distrib M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a + b \u2208 centralizer S :=\n\u03bb c hc, by rw [add_mul, mul_add, ha c hc, hb c hc]\n\n@[simp]\nlemma neg_mem_centralizer [has_mul M] [has_distrib_neg M] (ha : a \u2208 centralizer S) :\n  -a \u2208 centralizer S :=\n\u03bb c hc, by rw [mul_neg, ha c hc, neg_mul]\n\n@[simp]\nlemma inv_mem_centralizer\u2080 [group_with_zero M] (ha : a \u2208 centralizer S) : a\u207b\u00b9 \u2208 centralizer S :=\n(eq_or_ne a 0).elim (\u03bb h, by { rw [h, inv_zero], exact zero_mem_centralizer S })\n  (\u03bb ha0 c hc, by rw [mul_inv_eq_iff_eq_mul\u2080 ha0, mul_assoc, eq_inv_mul_iff_mul_eq\u2080 ha0, ha c hc])\n\n@[simp, to_additive sub_mem_add_centralizer]\nlemma div_mem_centralizer [group M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a / b \u2208 centralizer S :=\nbegin\n  rw [div_eq_mul_inv],\n  exact mul_mem_centralizer ha (inv_mem_centralizer hb),\nend\n\n@[simp]\nlemma div_mem_centralizer\u2080 [group_with_zero M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a / b \u2208 centralizer S :=\nbegin\n  rw div_eq_mul_inv,\n  exact mul_mem_centralizer ha (inv_mem_centralizer\u2080 hb),\nend\n\n@[to_additive add_centralizer_subset]\nlemma centralizer_subset [has_mul M] (h : S \u2286 T) : centralizer T \u2286 centralizer S :=\n\u03bb t ht s hs, ht s (h hs)\n\nvariables (M)\n\n@[simp, to_additive add_centralizer_univ]\nlemma centralizer_univ [has_mul M] : centralizer univ = center M :=\nsubset.antisymm (\u03bb a ha b, ha b (set.mem_univ b)) (\u03bb a ha b hb, ha b)\n\nvariables {M} (S)\n\n@[simp, to_additive add_centralizer_eq_univ]\nlemma centralizer_eq_univ [comm_semigroup M] : centralizer S = univ :=\nsubset.antisymm (subset_univ _) $ \u03bb x hx y hy, mul_comm y x\n\nend set\n\nnamespace submonoid\nsection\nvariables {M} [monoid M] (S)\n\n/-- The centralizer of a subset of a monoid `M`. -/\n@[to_additive \"The centralizer of a subset of an additive monoid.\"]\ndef centralizer : submonoid M :=\n{ carrier := S.centralizer,\n  one_mem' := S.one_mem_centralizer,\n  mul_mem' := \u03bb a b, set.mul_mem_centralizer }\n\n@[simp, norm_cast, to_additive] lemma coe_centralizer : \u2191(centralizer S) = S.centralizer := rfl\n\nvariables {S}\n\n@[to_additive] lemma mem_centralizer_iff {z : M} : z \u2208 centralizer S \u2194 \u2200 g \u2208 S, g * z = z * g :=\niff.rfl\n\n@[to_additive] instance decidable_mem_centralizer [decidable_eq M] [fintype M]\n  [decidable_pred (\u2208 S)] : decidable_pred (\u2208 centralizer S) :=\n\u03bb _, decidable_of_iff' _ mem_centralizer_iff\n\n@[to_additive]\nlemma centralizer_le (h : S \u2286 T) : centralizer T \u2264 centralizer S :=\nset.centralizer_subset h\n\nvariables (M)\n\n@[simp, to_additive]\nlemma centralizer_univ : centralizer set.univ = center M :=\nset_like.ext' (set.centralizer_univ M)\n\nend\n\nend submonoid\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/group_theory/submonoid/centralizer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7440720170130325}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.ordinal.fixed_point\n\n/-!\n### Principal ordinals\n\nWe define principal or indecomposable ordinals, and we prove the standard properties about them.\n\n### Main definitions and results\n* `principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and\n  any other typically excluded edge cases for simplicity.\n* `unbounded_principal`: Principal ordinals are unbounded.\n* `principal_add_iff_zero_or_omega_opow`: The main characterization theorem for additive principal\n  ordinals.\n* `principal_mul_iff_le_two_or_omega_opow_opow`: The main characterization theorem for\n  multiplicative principal ordinals.\n\n### Todo\n* Prove that exponential principal ordinals are 0, 1, 2, \u03c9, or epsilon numbers, i.e. fixed points\n  of `\u03bb x, \u03c9 ^ x`.\n-/\n\nuniverse u\n\nnoncomputable theory\n\nopen order\n\nnamespace ordinal\nlocal infixr ^ := @pow ordinal ordinal ordinal.has_pow\n\n/-! ### Principal ordinals -/\n\n/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of\nordinals less than it is closed under that operation. In standard mathematical usage, this term is\nalmost exclusively used for additive and multiplicative principal ordinals.\n\nFor simplicity, we break usual convention and regard 0 as principal. -/\ndef principal (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : Prop :=\n\u2200 \u2983a b\u2984, a < o \u2192 b < o \u2192 op a b < o\n\ntheorem principal_iff_principal_swap {op : ordinal \u2192 ordinal \u2192 ordinal} {o : ordinal} :\n  principal op o \u2194 principal (function.swap op) o :=\nby split; exact \u03bb h a b ha hb, h hb ha\n\ntheorem principal_zero {op : ordinal \u2192 ordinal \u2192 ordinal} : principal op 0 :=\n\u03bb a _ h, (ordinal.not_lt_zero a h).elim\n\n@[simp] theorem principal_one_iff {op : ordinal \u2192 ordinal \u2192 ordinal} :\n  principal op 1 \u2194 op 0 0 = 0 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h a b ha hb, _\u27e9,\n  { rwa \u2190lt_one_iff_zero,\n    exact h zero_lt_one zero_lt_one },\n  { rwa [lt_one_iff_zero, ha, hb] at * }\nend\n\ntheorem principal.iterate_lt {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal} (hao : a < o)\n  (ho : principal op o) (n : \u2115) : (op a)^[n] a < o :=\nbegin\n  induction n with n hn,\n  { rwa function.iterate_zero },\n  { rw function.iterate_succ', exact ho hao hn }\nend\n\ntheorem op_eq_self_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal.{u}}\n  (hao : a < o) (H : is_normal (op a)) (ho : principal op o) (ho' : is_limit o) : op a o = o :=\nbegin\n  refine le_antisymm _ (H.self_le _),\n  rw [\u2190is_normal.bsup_eq.{u u} H ho', bsup_le_iff],\n  exact \u03bb b hbo, (ho hao hbo).le\nend\n\ntheorem nfp_le_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal}\n  {a o : ordinal} (hao : a < o) (ho : principal op o) : nfp (op a) a \u2264 o :=\nnfp_le $ \u03bb n, (ho.iterate_lt hao n).le\n\n/-! ### Principal ordinals are unbounded -/\n\n/-- The least strict upper bound of `op` applied to all pairs of ordinals less than `o`. This is\nessentially a two-argument version of `ordinal.blsub`. -/\ndef blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : ordinal :=\nlsub (\u03bb x : o.out.\u03b1 \u00d7 o.out.\u03b1, op (typein (<) x.1) (typein (<) x.2))\n\ntheorem lt_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) {o : ordinal} {a b : ordinal} (ha : a < o)\n  (hb : b < o) : op a b < blsub\u2082 op o :=\nbegin\n  convert lt_lsub _ (prod.mk (enum (<) a (by rwa type_lt)) (enum (<) b (by rwa type_lt))),\n  simp only [typein_enum]\nend\n\ntheorem principal_nfp_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) :\n  principal op (nfp (blsub\u2082.{u u} op) o) :=\n\u03bb a b ha hb, begin\n  rw lt_nfp at *,\n  cases ha with m hm,\n  cases hb with n hn,\n  cases le_total ((blsub\u2082.{u u} op)^[m] o) ((blsub\u2082.{u u} op)^[n] o) with h h,\n  { use n + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op (hm.trans_le h) hn },\n  { use m + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op hm (hn.trans_le h) },\nend\n\ntheorem unbounded_principal (op : ordinal \u2192 ordinal \u2192 ordinal) :\n  set.unbounded (<) {o | principal op o} :=\n\u03bb o, \u27e8_, principal_nfp_blsub\u2082 op o, (le_nfp _ o).not_lt\u27e9\n\n/-! #### Additive principal ordinals -/\n\ntheorem principal_add_one : principal (+) 1 :=\nprincipal_one_iff.2 $ zero_add 0\n\ntheorem principal_add_of_le_one {o : ordinal} (ho : o \u2264 1) : principal (+) o :=\nbegin\n  rcases le_one_iff.1 ho with rfl | rfl,\n  { exact principal_zero },\n  { exact principal_add_one }\nend\n\ntheorem principal_add_is_limit {o : ordinal} (ho\u2081 : 1 < o) (ho : principal (+) o) :\n  o.is_limit :=\nbegin\n  refine \u27e8\u03bb ho\u2080, _, \u03bb a hao, _\u27e9,\n  { rw ho\u2080 at ho\u2081,\n    exact not_lt_of_gt ordinal.zero_lt_one ho\u2081 },\n  { cases eq_or_ne a 0 with ha ha,\n    { rw [ha, succ_zero],\n      exact ho\u2081 },\n    { refine lt_of_le_of_lt _ (ho hao hao),\n      rwa [\u2190add_one_eq_succ, add_le_add_iff_left, one_le_iff_ne_zero] } }\nend\n\ntheorem principal_add_iff_add_left_eq_self {o : ordinal} :\n  principal (+) o \u2194 \u2200 a < o, a + o = o :=\nbegin\n  refine \u27e8\u03bb ho a hao, _, \u03bb h a b hao hbo, _\u27e9,\n  { cases lt_or_le 1 o with ho\u2081 ho\u2081,\n    { exact op_eq_self_of_principal hao (add_is_normal a) ho (principal_add_is_limit ho\u2081 ho) },\n    { rcases le_one_iff.1 ho\u2081 with rfl | rfl,\n      { exact (ordinal.not_lt_zero a hao).elim },\n      { rw lt_one_iff_zero at hao,\n        rw [hao, zero_add] }}},\n  { rw \u2190h a hao,\n    exact (add_is_normal a).strict_mono hbo }\nend\n\ntheorem exists_lt_add_of_not_principal_add {a} (ha : \u00ac principal (+) a) :\n  \u2203 (b c) (hb : b < a) (hc : c < a), b + c = a :=\nbegin\n  unfold principal at ha,\n  push_neg at ha,\n  rcases ha with \u27e8b, c, hb, hc, H\u27e9,\n  refine \u27e8b, _, hb, lt_of_le_of_ne (sub_le_self a b) (\u03bb hab, _),\n    ordinal.add_sub_cancel_of_le hb.le\u27e9,\n  rw [\u2190sub_le, hab] at H,\n  exact H.not_lt hc\nend\n\ntheorem principal_add_iff_add_lt_ne_self {a} :\n  principal (+) a \u2194 \u2200 \u2983b c\u2984, b < a \u2192 c < a \u2192 b + c \u2260 a :=\n\u27e8\u03bb ha b c hb hc, (ha hb hc).ne, \u03bb H, begin\n  by_contra' ha,\n  rcases exists_lt_add_of_not_principal_add ha with \u27e8b, c, hb, hc, rfl\u27e9,\n  exact (H hb hc).irrefl\nend\u27e9\n\ntheorem add_omega {a : ordinal} (h : a < omega) : a + omega = omega :=\nbegin\n  rcases lt_omega.1 h with \u27e8n, rfl\u27e9,\n  clear h, induction n with n IH,\n  { rw [nat.cast_zero, zero_add] },\n  { rwa [nat.cast_succ, add_assoc, one_add_of_omega_le (le_refl _)] }\nend\n\ntheorem principal_add_omega : principal (+) omega :=\nprincipal_add_iff_add_left_eq_self.2 (\u03bb a, add_omega)\n\ntheorem add_omega_opow {a b : ordinal} (h : a < omega ^ b) : a + omega ^ b = omega ^ b :=\nbegin\n  refine le_antisymm _ (le_add_left _ _),\n  revert h, refine limit_rec_on b (\u03bb h, _) (\u03bb b _ h, _) (\u03bb b l IH h, _),\n  { rw [opow_zero, \u2190 succ_zero, lt_succ_iff, ordinal.le_zero] at h,\n    rw [h, zero_add] },\n  { rw opow_succ at h,\n    rcases (lt_mul_of_limit omega_is_limit).1 h with \u27e8x, xo, ax\u27e9,\n    refine le_trans (add_le_add_right (le_of_lt ax) _) _,\n    rw [opow_succ, \u2190 mul_add, add_omega xo] },\n  { rcases (lt_opow_of_limit omega_ne_zero l).1 h with \u27e8x, xb, ax\u27e9,\n    exact (((add_is_normal a).trans (opow_is_normal one_lt_omega)).limit_le l).2 (\u03bb y yb,\n      (add_le_add_left (opow_le_opow_right omega_pos (le_max_right _ _)) _).trans\n      (le_trans (IH _ (max_lt xb yb) (ax.trans_le $ opow_le_opow_right omega_pos (le_max_left _ _)))\n      (opow_le_opow_right omega_pos $ le_of_lt $ max_lt xb yb))) }\nend\n\ntheorem principal_add_omega_opow (o : ordinal) : principal (+) (omega ^ o) :=\nprincipal_add_iff_add_left_eq_self.2 (\u03bb a, add_omega_opow)\n\n/-- The main characterization theorem for additive principal ordinals. -/\ntheorem principal_add_iff_zero_or_omega_opow {o : ordinal} :\n  principal (+) o \u2194 o = 0 \u2228 \u2203 a, o = omega ^ a :=\nbegin\n  rcases eq_or_ne o 0 with rfl | ho,\n  { simp only [principal_zero, or.inl] },\n  { rw [principal_add_iff_add_left_eq_self],\n    simp only [ho, false_or],\n    refine \u27e8\u03bb H, \u27e8_, ((lt_or_eq_of_le (opow_log_le_self _ (ordinal.pos_iff_ne_zero.2 ho)))\n        .resolve_left $ \u03bb h, _).symm\u27e9, \u03bb \u27e8b, e\u27e9, e.symm \u25b8 \u03bb a, add_omega_opow\u27e9,\n    have := H _ h,\n    have := lt_opow_succ_log_self one_lt_omega o,\n    rw [opow_succ, lt_mul_of_limit omega_is_limit] at this,\n    rcases this with \u27e8a, ao, h'\u27e9,\n    rcases lt_omega.1 ao with \u27e8n, rfl\u27e9, clear ao,\n    revert h', apply not_lt_of_le,\n    suffices e : omega ^ log omega o * \u2191n + o = o,\n    { simpa only [e] using le_add_right (omega ^ log omega o * \u2191n) o },\n    induction n with n IH, {simp only [nat.cast_zero, mul_zero, zero_add]},\n    simp only [nat.cast_succ, mul_add_one, add_assoc, this, IH] }\nend\n\ntheorem opow_principal_add_of_principal_add {a} (ha : principal (+) a) (b : ordinal) :\n  principal (+) (a ^ b) :=\nbegin\n  rcases principal_add_iff_zero_or_omega_opow.1 ha with rfl | \u27e8c, rfl\u27e9,\n  { rcases eq_or_ne b 0 with rfl | hb,\n    { rw opow_zero, exact principal_add_one },\n    { rwa zero_opow hb } },\n  { rw \u2190opow_mul, exact principal_add_omega_opow _ }\nend\n\ntheorem add_absorp {a b c : ordinal} (h\u2081 : a < omega ^ b) (h\u2082 : omega ^ b \u2264 c) : a + c = c :=\nby rw [\u2190 ordinal.add_sub_cancel_of_le h\u2082, \u2190 add_assoc, add_omega_opow h\u2081]\n\ntheorem mul_principal_add_is_principal_add (a : ordinal.{u}) {b : ordinal.{u}} (hb\u2081 : b \u2260 1)\n  (hb : principal (+) b) : principal (+) (a * b) :=\nbegin\n  rcases eq_zero_or_pos a with rfl | ha,\n  { rw zero_mul,\n    exact principal_zero },\n  { rcases eq_zero_or_pos b with rfl | hb\u2081',\n    { rw mul_zero,\n      exact principal_zero },\n    { rw [\u2190 succ_le_iff, succ_zero] at hb\u2081',\n      intros c d hc hd,\n      rw lt_mul_of_limit (principal_add_is_limit (lt_of_le_of_ne hb\u2081' hb\u2081.symm) hb) at *,\n      { rcases hc with \u27e8x, hx, hx'\u27e9,\n        rcases hd with \u27e8y, hy, hy'\u27e9,\n        use [x + y, hb hx hy],\n        rw mul_add,\n        exact left.add_lt_add hx' hy' },\n      assumption' } }\nend\n\n/-! #### Multiplicative principal ordinals -/\n\ntheorem principal_mul_one : principal (*) 1 :=\nby { rw principal_one_iff, exact zero_mul _ }\n\ntheorem principal_mul_two : principal (*) 2 :=\n\u03bb a b ha hb, begin\n  have h\u2082 : succ (1 : ordinal) = 2 := rfl,\n  rw [\u2190h\u2082, lt_succ_iff] at *,\n  convert mul_le_mul' ha hb,\n  exact (mul_one 1).symm\nend\n\ntheorem principal_mul_of_le_two {o : ordinal} (ho : o \u2264 2) : principal (*) o :=\nbegin\n  rcases lt_or_eq_of_le ho with ho | rfl,\n  { have h\u2082 : succ (1 : ordinal) = 2 := rfl,\n    rw [\u2190h\u2082, lt_succ_iff] at ho,\n    rcases lt_or_eq_of_le ho with ho | rfl,\n    { rw lt_one_iff_zero.1 ho,\n      exact principal_zero },\n    { exact principal_mul_one } },\n  { exact principal_mul_two }\nend\n\ntheorem principal_add_of_principal_mul {o : ordinal} (ho : principal (*) o) (ho\u2082 : o \u2260 2) :\n  principal (+) o :=\nbegin\n  cases lt_or_gt_of_ne ho\u2082 with ho\u2081 ho\u2082,\n  { change o < succ 1 at ho\u2081,\n    rw lt_succ_iff at ho\u2081,\n    exact principal_add_of_le_one ho\u2081 },\n  { refine \u03bb a b hao hbo, lt_of_le_of_lt _ (ho (max_lt hao hbo) ho\u2082),\n    rw mul_two,\n    exact add_le_add (le_max_left a b) (le_max_right a b) }\nend\n\ntheorem principal_mul_is_limit {o : ordinal.{u}} (ho\u2082 : 2 < o) (ho : principal (*) o) :\n  o.is_limit :=\nprincipal_add_is_limit\n  ((lt_succ 1).trans ho\u2082)\n  (principal_add_of_principal_mul ho (ne_of_gt ho\u2082))\n\ntheorem principal_mul_iff_mul_left_eq {o : ordinal} :\n  principal (*) o \u2194 \u2200 a, 0 < a \u2192 a < o \u2192 a * o = o :=\nbegin\n  refine \u27e8\u03bb h a ha\u2080 hao, _, \u03bb h a b hao hbo, _\u27e9,\n  { cases le_or_gt o 2 with ho ho,\n    { convert one_mul o,\n      apply le_antisymm,\n      { have : a < succ 1 := hao.trans_le ho,\n        rwa lt_succ_iff at this },\n      { rwa [\u2190succ_le_iff, succ_zero] at ha\u2080 } },\n    { exact op_eq_self_of_principal hao (mul_is_normal ha\u2080) h (principal_mul_is_limit ho h) } },\n  { rcases eq_or_ne a 0 with rfl | ha, { rwa zero_mul },\n    rw \u2190ordinal.pos_iff_ne_zero at ha,\n    rw \u2190h a ha hao,\n    exact (mul_is_normal ha).strict_mono hbo }\nend\n\ntheorem principal_mul_omega : principal (*) omega :=\n\u03bb a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by { rw [\u2190 nat_cast_mul], apply nat_lt_omega }\nend\n\ntheorem mul_omega {a : ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega :=\nprincipal_mul_iff_mul_left_eq.1 (principal_mul_omega) a a0 ha\n\ntheorem mul_lt_omega_opow {a b c : ordinal}\n  (c0 : 0 < c) (ha : a < omega ^ c) (hb : b < omega) : a * b < omega ^ c :=\nbegin\n  rcases zero_or_succ_or_limit c with rfl|\u27e8c,rfl\u27e9|l,\n  { exact (lt_irrefl _).elim c0 },\n  { rw opow_succ at ha,\n    rcases ((mul_is_normal $ opow_pos _ omega_pos).limit_lt\n      omega_is_limit).1 ha with \u27e8n, hn, an\u27e9,\n    apply (mul_le_mul_right' (le_of_lt an) _).trans_lt,\n    rw [opow_succ, mul_assoc, mul_lt_mul_iff_left (opow_pos _ omega_pos)],\n    exact principal_mul_omega hn hb },\n  { rcases ((opow_is_normal one_lt_omega).limit_lt l).1 ha with \u27e8x, hx, ax\u27e9,\n    refine (mul_le_mul' (le_of_lt ax) (le_of_lt hb)).trans_lt _,\n    rw [\u2190 opow_succ, opow_lt_opow_iff_right one_lt_omega],\n    exact l.2 _ hx }\nend\n\ntheorem mul_omega_opow_opow {a b : ordinal} (a0 : 0 < a) (h : a < omega ^ omega ^ b) :\n  a * omega ^ omega ^ b = omega ^ omega ^ b :=\nbegin\n  by_cases b0 : b = 0, {rw [b0, opow_zero, opow_one] at h \u22a2, exact mul_omega a0 h},\n  refine le_antisymm _\n    (by simpa only [one_mul] using mul_le_mul_right' (one_le_iff_pos.2 a0) (omega ^ omega ^ b)),\n  rcases (lt_opow_of_limit omega_ne_zero (opow_is_limit_left omega_is_limit b0)).1 h\n    with \u27e8x, xb, ax\u27e9,\n  apply (mul_le_mul_right' (le_of_lt ax) _).trans,\n  rw [\u2190 opow_add, add_omega_opow xb]\nend\n\ntheorem principal_mul_omega_opow_opow (o : ordinal) : principal (*) (omega ^ omega ^ o) :=\nprincipal_mul_iff_mul_left_eq.2 (\u03bb a, mul_omega_opow_opow)\n\ntheorem principal_add_of_principal_mul_opow {o b : ordinal} (hb : 1 < b)\n  (ho : principal (*) (b ^ o)) : principal (+) o :=\n\u03bb x y hx hy, begin\n  have := ho ((opow_lt_opow_iff_right hb).2 hx) ((opow_lt_opow_iff_right hb).2 hy),\n  rwa [\u2190opow_add, opow_lt_opow_iff_right hb] at this\nend\n\n/-- The main characterization theorem for multiplicative principal ordinals. -/\ntheorem principal_mul_iff_le_two_or_omega_opow_opow {o : ordinal} :\n  principal (*) o \u2194 o \u2264 2 \u2228 \u2203 a, o = omega ^ omega ^ a :=\nbegin\n  refine \u27e8\u03bb ho, _, _\u27e9,\n  { cases le_or_lt o 2 with ho\u2082 ho\u2082,\n    { exact or.inl ho\u2082 },\n    rcases principal_add_iff_zero_or_omega_opow.1 (principal_add_of_principal_mul ho ho\u2082.ne')\n      with rfl | \u27e8a, rfl\u27e9,\n    { exact (ordinal.not_lt_zero 2 ho\u2082).elim },\n    rcases principal_add_iff_zero_or_omega_opow.1\n      (principal_add_of_principal_mul_opow one_lt_omega ho) with rfl | \u27e8b, rfl\u27e9,\n    { rw opow_zero at ho\u2082,\n      exact ((lt_succ 1).not_le ho\u2082.le).elim },\n    exact or.inr \u27e8b, rfl\u27e9 },\n  { rintro (ho\u2082 | \u27e8a, rfl\u27e9),\n    { exact principal_mul_of_le_two ho\u2082 },\n    { exact principal_mul_omega_opow_opow a } }\nend\n\n\n\ntheorem mul_eq_opow_log_succ {a b : ordinal.{u}} (ha : 0 < a) (hb : principal (*) b) (hb\u2082 : 2 < b) :\n  a * b = b ^ succ (log b a) :=\nbegin\n  apply le_antisymm,\n  { have hbl := principal_mul_is_limit hb\u2082 hb,\n    rw [\u2190is_normal.bsup_eq.{u u} (mul_is_normal ha) hbl, bsup_le_iff],\n    intros c hcb,\n    have hb\u2081 : 1 < b := (lt_succ 1).trans hb\u2082,\n    have hbo\u2080 : b ^ b.log a \u2260 0 := ordinal.pos_iff_ne_zero.1 (opow_pos _ (zero_lt_one.trans hb\u2081)),\n    apply le_trans (mul_le_mul_right' (le_of_lt (lt_mul_succ_div a hbo\u2080)) c),\n    rw [mul_assoc, opow_succ],\n    refine mul_le_mul_left' (le_of_lt (hb (hbl.2 _ _) hcb)) _,\n    rw [div_lt hbo\u2080, \u2190opow_succ],\n    exact lt_opow_succ_log_self hb\u2081 _ },\n  { rw opow_succ,\n    exact mul_le_mul_right' (opow_log_le_self b ha) b }\nend\n\n/-! #### Exponential principal ordinals -/\n\ntheorem principal_opow_omega : principal (^) omega :=\n\u03bb a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by { simp_rw \u2190nat_cast_opow, apply nat_lt_omega }\nend\n\ntheorem opow_omega {a : ordinal} (a1 : 1 < a) (h : a < omega) : a ^ omega = omega :=\nle_antisymm\n  ((opow_le_of_limit (one_le_iff_ne_zero.1 $ le_of_lt a1) omega_is_limit).2\n    (\u03bb b hb, (principal_opow_omega h hb).le))\n  (right_le_opow _ a1)\n\nend ordinal\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/set_theory/ordinal/principal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7440599536778937}}
{"text": "import tactic \nimport data.real.sqrt\nimport analysis.specific_limits.basic\nimport analysis.specific_limits.normed\nimport data.complex.exponential\nimport data.real.irrational\n\nopen filter real\nopen_locale topological_space \nopen_locale big_operators \n\ntheorem liebeck_23_1_i :\n  tendsto (\u03bb n : \u2115, n / (n + 5) : \u2115 \u2192 \u211d) at_top (\ud835\udcdd 1) :=\nbegin \n  sorry \nend \n\ntheorem liebeck_23_1_ii :\n  tendsto (\u03bb n : \u2115, 1 / sqrt (n + 5)) at_top (\ud835\udcdd 0) :=\nbegin \n  sorry \nend \n\ntheorem liebeck_23_1_iii :\n  tendsto (\u03bb n : \u2115, \u2191n * sqrt n / (n + 5)) at_top at_top :=\nbegin \n  sorry\nend \n\ntheorem liebeck_23_1_iv :\n  tendsto (\u03bb n : \u2115, ((-1)^n * sin n) / sqrt n ) at_top (\ud835\udcdd 0) :=\nbegin \n  sorry \nend \n\ntheorem liebeck_23_1_v :\n  tendsto (\u03bb n : \u2115, (\u2191n^3 - 2*sqrt n + 7) / (2 - \u2191n^2 - 5*\u2191n^3)) at_top (\ud835\udcdd (-1/5)) :=\nbegin \n  sorry \nend  \n\ntheorem liebeck_23_1_vi (n : \u2115) :\n  \u00ac\u2203 l : \u211d, tendsto (\u03bb n, (1 - (-1)^n * n) / n : \u2115 \u2192 \u211d) at_top (\ud835\udcdd l) :=\nbegin \n  sorry \nend \n\ntheorem liebeck_23_1_vii :\n  tendsto (\u03bb n : \u2115, sqrt (n + 1) - sqrt n) at_top (\ud835\udcdd 0) :=\nbegin \n  sorry\nend \n\ntheorem leibeck_23_2 (X : Type*) [topological_space X] (a : \u2115 \u2192 X) (l\u2081 l\u2082 : X)\n  (h\u2081 : tendsto a at_top (\ud835\udcdd l\u2081)) (h\u2082 : tendsto a at_top (\ud835\udcdd l\u2082)) :\n  l\u2081 = l\u2082 :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_3 (S : set \u211d) (c : \u211d) (hc : is_lub S c) :\n  \u2203 (f : \u2115 \u2192 \u211d), (\u2200 n, f n \u2208 S) \u2227 tendsto f at_top (\ud835\udcdd c) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_i_a :\n  \u2203 b : \u211d, \u2200 n, abs (n^3 / (n^3 - 1) : \u211d) \u2264 b :=\nbegin \n  sorry, \nend \n\ntheorem leibeck_23_4_i_c (n : \u2115) :\n  (n : \u211d)^3 / (n^3 - 1) \u2265 (n + 1)^3 / ((n + 1)^3 - 1) :=\nbegin \n  sorry, \nend \n\ntheorem leibeck_23_4_i_d (a : \u2115 \u2192 \u211d) (h : \u2200 n : \u2115, a n = n^3 / (n^3 - 1)) :\n  \u2203 l : \u211d, tendsto a at_top (\ud835\udcdd l) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_ii_a :\n  \u2203 M : \u211d, \u2200 m : \u2115, abs (2 ^ (1 / m)) \u2264 M :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_ii_c (n : \u2115) : \n  2^(1/n) \u2265 2^(1/(n+1)) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_ii_d (a : \u2115 \u2192 \u211d) (h : \u2200 n : \u2115, a n = 2 ^ (1 / n)) :\n  \u2203 l : \u211d, tendsto a at_top (\ud835\udcdd l) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iii_a :\n  \u2203 b : \u211d, \u2200 n : \u2115, abs (1 - (-1)^n / \u2191n) \u2264 b :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iii_b (n : \u2115) :\n  \u00ac (\u2200 n : \u2115, (1 : \u211d) - (-1)^n / n \u2264 1 - (-1)^(n+1) / (n+1)) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iii_c (n : \u2115) : \n  \u00ac (\u2200 m : \u2115, (1 - (-1)^n / n.cast : \u211d) \u2265 (1 - (-1)^(n+m) / (n+m).cast : \u211d)) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iii_d (f : \u2115 \u2192 \u211d) (hf : \u2200 n : \u2115, f n = 1 - (-1)^n / n) :\n  \u2203 r : \u211d, tendsto f at_top (\ud835\udcdd r) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iv_a :\n  \u2200 m : \u2115, \u2203 N : \u2115, \u2200 n \u2265 N, abs (5*n - n^2 : \u211d) \u2265 m :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iv_b :\n  \u00ac (\u2200 n : \u2115, abs (5*n - n^2 : \u211d) \u2264 abs (5*(n+1) - (n+1)^2 : \u211d)) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iv_c :\n  \u00ac (\u2200 n : \u2115, abs (5*n - n^2 : \u211d) \u2265 abs (5*(n+1) - (n+1)^2 : \u211d)) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_4_iv_d :\n  tendsto (\u03bb n : \u2115, abs (5*n - n^2 : \u211d)) at_top at_top :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_5 (a : \u211d) (f : \u2115 \u2192 \u211d) :\n  (\u2203 N, \u2200 \u03b5 > 0, \u2200 n \u2265 N, abs (f n - a) < \u03b5) \u2194 (\u2203 N, \u2200 n \u2265 N, f n = a) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_6 (f : \u2115 \u2192 \u211d) (hf : \u2200 n, f (n + 1) \u2264 f n)\n  (hf_bdd : \u2203 a, \u2200 n, f n \u2264 a) :\n  \u2203 a, tendsto f at_top (\ud835\udcdd a) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_7_i_a (a : \u2115 \u2192 \u211d) (h1 : a 1 = 1)\n  (h2 : \u2200 n : \u2115, a (n + 1) = (a n ^ 2 + 2) / (2 * a n)) :\n  \u2203 M : \u211d, \u2200 n : \u2115, abs (a n) \u2264 M :=\nbegin \n  sorry \nend \n\ntheorem liebeck_23_7_i_b (a : \u2115 \u2192 \u211d) (h1 : a 1 = 1) (h2 : \u2200 n, a (n+1) = (a n ^ 2 + 2) / (2 * a n)) :\n  \u2200 n, n \u2265 2 \u2192 a n \u2265 a (n+1) :=\nbegin \n  sorry \nend \n\ntheorem liebeck_23_7_ii (a : \u2115 \u2192 \u211d) (h1 : a 1 = 1) (h2 : \u2200 n, a (n+1) = (a n ^ 2 + 2) / (2 * a n)) :\n  tendsto a at_top (\ud835\udcdd 2) :=\nbegin \n  sorry \nend \n\nnoncomputable def e : \u2115 \u2192 \u211d := \u03bb n, \u2211 i in finset.range(n+1), 1 / (nat.factorial i)\n\ntheorem leibeck_23_8_a (n : \u2115) :\n  \u2203 p : \u2115, e n = p / (nat.factorial n) :=\nbegin   \n  sorry \nend \n\ntheorem leibeck_23_8_b (n : \u2115) : \n  0 < exp 1 - e n \u2227 exp 1 - e n < 1 / (n * nat.factorial n) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_8_c : \n  \u2203 p : \u2115 \u2192 \u211d, \u2200 n : \u2115, 0 < exp 1 * nat.factorial n - e n \u2227 \n  exp 1 * nat.factorial n - e n < 1 / (n * nat.factorial n) :=\nbegin \n  sorry \nend \n\n-- Assume e is rational, then show n!e \u2208 \u2124 for some n.\ntheorem leibeck_23_8_d : \n  irrational (exp 1) := \nbegin \n  sorry \nend \n\nvariable a : \u2115 \u2192 \u211d \n\ntheorem leibeck_23_9_a : \n  \u00ac (\u2200 l : \u211d, tendsto a at_top (\ud835\udcdd l)) \u2194 tendsto a at_top at_top :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_9_c : \n  (\u2200 R > 0, \u2203 N : \u2115, \u2200 n \u2265 N, a n > R) \u2194 (tendsto a at_top at_top) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_9_d : \n  \u00ac (\u2200 L : \u211d, \u2200 \u03b5 : \u211d, \u2203 N : \u2115, \u2200 n \u2265 N, abs (a n - L) > \u03b5) \u2194 (tendsto a at_top at_top) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_9_e : \n  (\u2200 \u03b5 > 0, \u2203 N : \u2115, \u2200 n \u2265 N, a n > 1 / \u03b5) \u2194 (tendsto a at_top at_top) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_9_f : \n  \u00ac (\u2200 n : \u2115, a (n+1) > a n) \u2194 (tendsto a at_top at_top) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_9_g : \n  \u00ac (\u2203 N : \u2115, \u2200 R > 0, \u2200 n \u2265 N, a n > R) \u2194 (tendsto a at_top at_top) :=\nbegin \n  sorry \nend \n\ntheorem leibeck_23_10_g : \n  \u00ac (\u2200 R : \u211d, \u2203 n : \u2115, a n > R) \u2194 (tendsto a at_top at_top) :=\nbegin \n  sorry \nend \n\n", "meta": {"author": "wudcscheme", "repo": "lean-challenges", "sha": "dfaf3f6f71148b60db75479e7b09c68012f354c1", "save_path": "github-repos/lean/wudcscheme-lean-challenges", "path": "github-repos/lean/wudcscheme-lean-challenges/lean-challenges-dfaf3f6f71148b60db75479e7b09c68012f354c1/src/liebeck_a_concise_introduction_to_pure_mathematics/analysis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.743982895087995}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Sets in Lean, sheet 5 : equality of sets\n\nSets are extensional objects to mathematicians, which means that\nif two sets have the same elements, then they are equal. \n\n## Tactics \n\nTactics you will need to know for this sheet:\n\n* `ext`\n\n### The `ext` tactic\n\nIf the goal is `\u22a2 A = B` where `A` and `B` are subsets of `X`, then\nthe tactic `ext x,` will create a hypothesis `x : X` and change\nthe goal to `x \u2208 A \u2194 x \u2208 B`.\n\n-/\n\nopen set\n\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D E : set X) -- A,B,C,D,E are subsets of `X`\n  (x y z : X) -- x,y,z are elements of `X` or, more precisely, terms of type `X`\n\nexample : A \u222a A = A :=\nbegin\n  sorry\nend\n\nexample : A \u2229 A = A :=\nbegin\n  sorry\nend\n\nexample : A \u2229 \u2205 = \u2205 :=\nbegin\n  sorry\nend\n\nexample : A \u222a univ = univ :=\nbegin\n  sorry\nend\n\nexample : A \u2286 B \u2192 B \u2286 A \u2192 A = B :=\nbegin\n  sorry\nend\n\nexample : A \u2229 B = B \u2229 A :=\nbegin\n  sorry\nend\n\nexample : A \u2229 (B \u2229 C) = (A \u2229 B) \u2229 C :=\nbegin\n  sorry\nend\n\nexample : A \u222a (B \u222a C) = (A \u222a B) \u222a C :=\nbegin\n  sorry\nend\n\nexample : A \u222a (B \u2229 C) = (A \u222a B) \u2229 (A \u222a C) :=\nbegin\n  sorry,\nend\n\nexample : A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\n  sorry,\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section05sets/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037384317888, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7439828923579065}}
{"text": "import data.real.basic\n\nvariables a b c : \u211d\n\n#check add_le_add_left\n#check add_le_add_right\n#check le_antisymm\n#check le_min\n#check min_le_left\n#check min_le_right\n\n-- BEGIN\n\nlemma aux : min a b + c \u2264 min (a + c) (b + c) :=\nbegin\n  apply le_min,\n   show min a b + c \u2264 a + c,\n    have h : min a b \u2264 a,\n    apply min_le_left,\n    apply add_le_add_right h, \n   show min a b + c \u2264 b + c,   \n    have h' : min a b \u2264 b,\n    apply min_le_right, \n    apply add_le_add_right h',\nend\n\nexample : min a b + c = min (a + c) (b + c) :=\nbegin\n  apply le_antisymm,\n  exact aux a b c,\n  have ha : min (a + c) (b + c) - c <= a := by linarith [min_le_left (a + c) (b + c)],\n  have hb : min (a + c) (b + c) - c <= b := by linarith [min_le_right (a + c) (b + c)],\n  have h : min (a + c) (b + c) - c <= min a b := le_min ha hb,\n  linarith only [h],\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.1_apply/ex9_apply_min.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7439828874659044}}
{"text": "import data.nat.prime\nimport number_theory.padics.padic_norm\nimport data.pnat.factors\n\n-- ERIC'S CODE\n@[simp]\nlemma prime_multiset.coe_add (m n : prime_multiset) : \u2191(m + n) = (m + n : multiset \u2115) :=\nis_add_monoid_hom.map_add _ _ _\n\nattribute [simp] pnat.coe_nat_factor_multiset\n\nlemma factors_mul {p q : \u2115} (hp : 0 < p) (hq : 0 < q) : (p * q).factors ~ p.factors ++ q.factors :=\nbegin\n  rw \u2190multiset.coe_eq_coe,\n  have := pnat.factor_multiset_mul \u27e8p, hp\u27e9 \u27e8q, hq\u27e9,\n  rw \u2190prime_multiset.coe_nat_injective.eq_iff at this,\n  simpa using this,\nend\n\n--MY CODE\nlemma factors_prime_pow_eq_repeat_prime_pow (p y : \u2115) (hprime : p.prime) : list.repeat p y = (p ^ y).factors :=\nbegin\n  haveI : fact p.prime := \u27e8hprime\u27e9,\n  induction y,\n  { simp [pow_zero, nat.factors_one] },\n  { apply list.repeat_perm.1 (list.perm.trans _ (factors_mul (nat.prime.pos hprime) (pow_pos (nat.prime.pos hprime) y_n)).symm),\n    simp [nat.factors_prime hprime, y_ih] }\nend\n\nlemma padic_val_nat.prime_pow_eq_pow {p y : \u2115} (hp : p.prime) : y = padic_val_nat p (p ^ y) :=\nbegin\n  haveI : fact p.prime := \u27e8hp\u27e9,\n  rw [padic_val_nat_eq_factors_count p, \u2190 @factors_prime_pow_eq_repeat_prime_pow p y hp, \u2190 (list.count_repeat p y).symm],\nend\n\n", "meta": {"author": "ineswright", "repo": "Lean-Sylow", "sha": "74b99544ab1ca96dc28fbe152125f565763a893b", "save_path": "github-repos/lean/ineswright-Lean-Sylow", "path": "github-repos/lean/ineswright-Lean-Sylow/Lean-Sylow-74b99544ab1ca96dc28fbe152125f565763a893b/src/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7439828825436884}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland, Yury Kudryashov\n-/\nimport algebra.group.semiconj\n\n/-!\n# Commuting pairs of elements in monoids\n\nWe define the predicate `commute a b := a * b = b * a` and provide some operations on terms `(h :\ncommute a b)`. E.g., if `a`, `b`, and c are elements of a semiring, and that `hb : commute a b` and\n`hc : commute a c`.  Then `hb.pow_left 5` proves `commute (a ^ 5) b` and `(hb.pow_right 2).add_right\n(hb.mul_right hc)` proves `commute a (b ^ 2 + b * c)`.\n\nLean does not immediately recognise these terms as equations, so for rewriting we need syntax like\n`rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`.\n\nThis file defines only a few operations (`mul_left`, `inv_right`, etc).  Other operations\n(`pow_right`, field inverse etc) are in the files that define corresponding notions.\n\n## Implementation details\n\nMost of the proofs come from the properties of `semiconj_by`.\n-/\n\n/-- Two elements commute if `a * b = b * a`. -/\n@[to_additive add_commute \"Two elements additively commute if `a + b = b + a`\"]\ndef commute {S : Type*} [has_mul S] (a b : S) : Prop := semiconj_by a b b\n\nnamespace commute\n\nsection has_mul\n\nvariables {S : Type*} [has_mul S]\n\n/-- Equality behind `commute a b`; useful for rewriting. -/\n@[to_additive] protected theorem eq {a b : S} (h : commute a b) : a * b = b * a := h\n\n/-- Any element commutes with itself. -/\n@[refl, simp, to_additive] protected theorem refl (a : S) : commute a a := eq.refl (a * a)\n\n/-- If `a` commutes with `b`, then `b` commutes with `a`. -/\n@[symm, to_additive] protected theorem symm {a b : S} (h : commute a b) : commute b a :=\neq.symm h\n\n@[to_additive] protected theorem semiconj_by {a b : S} (h : commute a b) : semiconj_by a b b := h\n\n@[to_additive]\nprotected theorem symm_iff {a b : S} : commute a b \u2194 commute b a :=\n\u27e8commute.symm, commute.symm\u27e9\n\nend has_mul\n\nsection semigroup\n\nvariables {S : Type*} [semigroup S] {a b c : S}\n\n/-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/\n@[simp, to_additive] theorem mul_right (hab : commute a b) (hac : commute a c) :\n  commute a (b * c) :=\nhab.mul_right hac\n\n/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/\n@[simp, to_additive] theorem mul_left (hac : commute a c) (hbc : commute b c) :\n  commute (a * b) c :=\nhac.mul_left hbc\n\n@[to_additive] protected lemma right_comm (h : commute b c) (a : S) :\n  a * b * c = a * c * b :=\nby simp only [mul_assoc, h.eq]\n\n@[to_additive] protected lemma left_comm (h : commute a b) (c) :\n  a * (b * c) = b * (a * c) :=\nby simp only [\u2190 mul_assoc, h.eq]\n\nend semigroup\n\n@[to_additive]\nprotected \n\nsection mul_one_class\n\nvariables {M : Type*} [mul_one_class M]\n\n@[simp, to_additive] theorem one_right (a : M) : commute a 1 := semiconj_by.one_right a\n@[simp, to_additive] theorem one_left (a : M) : commute 1 a := semiconj_by.one_left a\n\nend mul_one_class\n\nsection monoid\n\nvariables {M : Type*} [monoid M] {a b : M} {u u\u2081 u\u2082 : units M}\n\n@[simp, to_additive]\ntheorem pow_right (h : commute a b) (n : \u2115) : commute a (b ^ n) := h.pow_right n\n@[simp, to_additive]\ntheorem pow_left (h : commute a b) (n : \u2115) : commute (a ^ n) b := (h.symm.pow_right n).symm\n@[simp, to_additive]\ntheorem pow_pow (h : commute a b) (m n : \u2115) : commute (a ^ m) (b ^ n) :=\n(h.pow_left m).pow_right n\n\n@[simp, to_additive]\ntheorem self_pow (a : M) (n : \u2115) : commute a (a ^ n) := (commute.refl a).pow_right n\n@[simp, to_additive]\ntheorem pow_self (a : M) (n : \u2115) : commute (a ^ n) a := (commute.refl a).pow_left n\n@[simp, to_additive]\ntheorem pow_pow_self (a : M) (m n : \u2115) : commute (a ^ m) (a ^ n) :=\n(commute.refl a).pow_pow m n\n\n@[to_additive succ_nsmul'] theorem _root_.pow_succ' (a : M) (n : \u2115) : a ^ (n + 1) = a ^ n * a :=\n(pow_succ a n).trans (self_pow _ _)\n\n@[to_additive] theorem units_inv_right : commute a u \u2192 commute a \u2191u\u207b\u00b9 :=\nsemiconj_by.units_inv_right\n\n@[simp, to_additive] theorem units_inv_right_iff :\n  commute a \u2191u\u207b\u00b9 \u2194 commute a u :=\nsemiconj_by.units_inv_right_iff\n\n@[to_additive] theorem units_inv_left : commute \u2191u a \u2192 commute \u2191u\u207b\u00b9 a :=\nsemiconj_by.units_inv_symm_left\n\n@[simp, to_additive]\ntheorem units_inv_left_iff: commute \u2191u\u207b\u00b9 a \u2194 commute \u2191u a :=\nsemiconj_by.units_inv_symm_left_iff\n\n@[to_additive]\ntheorem units_coe : commute u\u2081 u\u2082 \u2192 commute (u\u2081 : M) u\u2082 := semiconj_by.units_coe\n@[to_additive]\ntheorem units_of_coe : commute (u\u2081 : M) u\u2082 \u2192 commute u\u2081 u\u2082 := semiconj_by.units_of_coe\n@[simp, to_additive]\ntheorem units_coe_iff : commute (u\u2081 : M) u\u2082 \u2194 commute u\u2081 u\u2082 := semiconj_by.units_coe_iff\n\n@[to_additive] lemma is_unit_mul_iff (h : commute a b) :\n  is_unit (a * b) \u2194 is_unit a \u2227 is_unit b :=\nbegin\n  refine \u27e8_, \u03bb H, H.1.mul H.2\u27e9,\n  rintro \u27e8u, hu\u27e9,\n  have : b * \u2191u\u207b\u00b9 * a = 1,\n  { have : commute a u := hu.symm \u25b8 (commute.refl _).mul_right h,\n    rw [\u2190 this.units_inv_right.right_comm, \u2190 h.eq, \u2190 hu, u.mul_inv] },\n  split,\n  { refine \u27e8\u27e8a, b * \u2191u\u207b\u00b9, _, this\u27e9, rfl\u27e9,\n    rw [\u2190 mul_assoc, \u2190 hu, u.mul_inv] },\n  { rw mul_assoc at this,\n    refine \u27e8\u27e8b, \u2191u\u207b\u00b9 * a, this, _\u27e9, rfl\u27e9,\n    rw [mul_assoc, \u2190 hu, u.inv_mul] }\nend\n\n@[simp, to_additive] lemma _root_.is_unit_mul_self_iff :\n  is_unit (a * a) \u2194 is_unit a :=\n(commute.refl a).is_unit_mul_iff.trans (and_self _)\n\nend monoid\n\nsection group\n\nvariables {G : Type*} [group G] {a b : G}\n\n@[to_additive]\ntheorem inv_right : commute a b \u2192 commute a b\u207b\u00b9 := semiconj_by.inv_right\n@[simp, to_additive]\ntheorem inv_right_iff : commute a b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_right_iff\n\n@[to_additive] theorem inv_left :  commute a b \u2192 commute a\u207b\u00b9 b := semiconj_by.inv_symm_left\n@[simp, to_additive]\ntheorem inv_left_iff : commute a\u207b\u00b9 b \u2194 commute a b := semiconj_by.inv_symm_left_iff\n\n@[to_additive]\ntheorem inv_inv : commute a b \u2192 commute a\u207b\u00b9 b\u207b\u00b9 := semiconj_by.inv_inv_symm\n@[simp, to_additive]\ntheorem inv_inv_iff : commute a\u207b\u00b9 b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_inv_symm_iff\n\n@[to_additive]\nprotected theorem inv_mul_cancel (h : commute a b) : a\u207b\u00b9 * b * a = b :=\nby rw [h.inv_left.eq, inv_mul_cancel_right]\n\n@[to_additive]\ntheorem inv_mul_cancel_assoc (h : commute a b) : a\u207b\u00b9 * (b * a) = b :=\nby rw [\u2190 mul_assoc, h.inv_mul_cancel]\n\n@[to_additive]\nprotected theorem mul_inv_cancel (h : commute a b) : a * b * a\u207b\u00b9 = b :=\nby rw [h.eq, mul_inv_cancel_right]\n\n@[to_additive]\ntheorem mul_inv_cancel_assoc (h : commute a b) : a * (b * a\u207b\u00b9) = b :=\nby rw [\u2190 mul_assoc, h.mul_inv_cancel]\n\nend group\n\nend commute\n\nsection comm_group\n\nvariables {G : Type*} [comm_group G] (a b : G)\n\n@[simp, to_additive] lemma mul_inv_cancel_comm : a * b * a\u207b\u00b9 = b :=\n(commute.all a b).mul_inv_cancel\n\n@[simp, to_additive] lemma mul_inv_cancel_comm_assoc : a * (b * a\u207b\u00b9) = b :=\n(commute.all a b).mul_inv_cancel_assoc\n\n@[simp, to_additive] lemma inv_mul_cancel_comm : a\u207b\u00b9 * b * a = b :=\n(commute.all a b).inv_mul_cancel\n\n@[simp, to_additive] lemma inv_mul_cancel_comm_assoc : a\u207b\u00b9 * (b * a) = b :=\n(commute.all a b).inv_mul_cancel_assoc\n\nend comm_group\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/group/commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.743982880361632}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.eval\nimport algebra.iterate_hom\n\n/-!\n# The derivative map on polynomials\n\n## Main definitions\n * `polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map.\n\n-/\n\nnoncomputable theory\nlocal attribute [instance, priority 100] classical.prop_decidable\n\nopen finsupp finset\nopen_locale big_operators\n\nnamespace polynomial\nuniverses u v w y z\nvariables {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type y} {A : Type z} {a b : R} {n : \u2115}\n\nsection derivative\n\nsection semiring\nvariables [semiring R]\n\n/-- `derivative p` is the formal derivative of the polynomial `p` -/\ndef derivative : polynomial R \u2192\u2097[R] polynomial R :=\nfinsupp.total \u2115 (polynomial R) R (\u03bb n, C \u2191n * X^(n - 1))\n\nlemma derivative_apply (p : polynomial R) :\n  derivative p = p.sum (\u03bbn a, C (a * n) * X^(n - 1)) :=\nbegin\n  rw [derivative, total_apply],\n  apply congr rfl,\n  ext,\n  simp [mul_assoc, coeff_C_mul],\nend\n\nlemma coeff_derivative (p : polynomial R) (n : \u2115) :\n  coeff (derivative p) n = coeff p (n + 1) * (n + 1) :=\nbegin\n  rw [derivative_apply],\n  simp only [coeff_X_pow, coeff_sum, coeff_C_mul],\n  rw [sum_def, finset.sum_eq_single (n + 1)],\n  simp only [nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true], norm_cast,\n  swap,\n  { rw [if_pos (nat.add_sub_cancel _ _).symm, mul_one, nat.cast_add, nat.cast_one, mem_support_iff],\n    intro h, push_neg at h, simp [h], },\n  { assume b, cases b,\n    { intros, rw [nat.cast_zero, mul_zero, zero_mul], },\n    { intros _ H, rw [nat.succ_sub_one b, if_neg (mt (congr_arg nat.succ) H.symm), mul_zero] } }\nend\n\n@[simp]\nlemma derivative_zero : derivative (0 : polynomial R) = 0 :=\nderivative.map_zero\n\n@[simp]\nlemma iterate_derivative_zero {k : \u2115} : derivative^[k] (0 : polynomial R) = 0 :=\nbegin\n  induction k with k ih,\n  { simp, },\n  { simp [ih], },\nend\n\n@[simp]\nlemma derivative_monomial (a : R) (n : \u2115) : derivative (monomial n a) = monomial (n - 1) (a * n) :=\n(derivative_apply _).trans ((sum_single_index $ by simp).trans (C_mul_X_pow_eq_monomial _ _))\n\nlemma derivative_C_mul_X_pow (a : R) (n : \u2115) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) :=\nby rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial]\n\n@[simp] lemma derivative_X_pow (n : \u2115) :\n  derivative (X ^ n : polynomial R) = (n : polynomial R) * X ^ (n - 1) :=\nby convert derivative_C_mul_X_pow (1 : R) n; simp\n\n@[simp] lemma derivative_C {a : R} : derivative (C a) = 0 :=\nby simp [derivative_apply]\n\n@[simp] lemma derivative_X : derivative (X : polynomial R) = 1 :=\n(derivative_monomial _ _).trans $ by simp\n\n@[simp] lemma derivative_one : derivative (1 : polynomial R) = 0 :=\nderivative_C\n\n@[simp] lemma derivative_bit0 {a : polynomial R} : derivative (bit0 a) = bit0 (derivative a) :=\nby simp [bit0]\n\n@[simp] lemma derivative_bit1 {a : polynomial R} : derivative (bit1 a) = bit0 (derivative a) :=\nby simp [bit1]\n\n@[simp] lemma derivative_add {f g : polynomial R} :\n  derivative (f + g) = derivative f + derivative g :=\nderivative.map_add f g\n\n@[simp] lemma iterate_derivative_add {f g : polynomial R} {k : \u2115} :\n  derivative^[k] (f + g) = (derivative^[k] f) + (derivative^[k] g) :=\nderivative.to_add_monoid_hom.iterate_map_add _ _ _\n\n@[simp] lemma derivative_neg {R : Type*} [ring R] (f : polynomial R) :\n  derivative (-f) = - derivative f :=\nlinear_map.map_neg derivative f\n\n@[simp] lemma iterate_derivative_neg {R : Type*} [ring R] {f : polynomial R} {k : \u2115} :\n  derivative^[k] (-f) = - (derivative^[k] f) :=\n(@derivative R _).to_add_monoid_hom.iterate_map_neg _ _\n\n@[simp] lemma derivative_sub {R : Type*} [ring R] {f g : polynomial R} :\n  derivative (f - g) = derivative f - derivative g :=\nlinear_map.map_sub derivative f g\n\n@[simp] lemma iterate_derivative_sub {R : Type*} [ring R] {k : \u2115} {f g : polynomial R} :\n  derivative^[k] (f - g) = (derivative^[k] f) - (derivative^[k] g) :=\nbegin\n  induction k with k ih generalizing f g,\n  { simp [nat.iterate], },\n  { simp [nat.iterate, ih], }\nend\n\n@[simp] lemma derivative_sum {s : finset \u03b9} {f : \u03b9 \u2192 polynomial R} :\n  derivative (\u2211 b in s, f b) = \u2211 b in s, derivative (f b) :=\nderivative.map_sum\n\n@[simp] lemma derivative_smul (r : R) (p : polynomial R) : derivative (r \u2022 p) = r \u2022 derivative p :=\nderivative.map_smul _ _\n\n@[simp] lemma iterate_derivative_smul (r : R) (p : polynomial R) (k : \u2115) :\n  derivative^[k] (r \u2022 p) = r \u2022 (derivative^[k] p) :=\nbegin\n  induction k with k ih generalizing p,\n  { simp, },\n  { simp [ih], },\nend\n\n/-- We can't use `derivative_mul` here because\nwe want to prove this statement also for noncommutative rings.-/\n@[simp]\nlemma derivative_C_mul (a : R) (p : polynomial R) : derivative (C a * p) = C a * derivative p :=\nby convert derivative_smul a p; apply C_mul'\n\n@[simp]\nlemma iterate_derivative_C_mul (a : R) (p : polynomial R) (k : \u2115) :\n  derivative^[k] (C a * p) = C a * (derivative^[k] p) :=\nby convert iterate_derivative_smul a p k; apply C_mul'\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R]\n\nlemma derivative_eval (p : polynomial R) (x : R) :\n  p.derivative.eval x = p.sum (\u03bb n a, (a * n)*x^(n-1)) :=\nby simp only [derivative_apply, eval_sum, eval_pow, eval_C, eval_X, eval_nat_cast, eval_mul]\n\n@[simp] lemma derivative_mul {f g : polynomial R} :\n  derivative (f * g) = derivative f * g + f * derivative g :=\ncalc derivative (f * g) = f.sum (\u03bbn a, g.sum (\u03bbm b, C ((a * b) * (n + m : \u2115)) * X^((n + m) - 1))) :\n  begin\n    transitivity, exact derivative_sum,\n    transitivity, { apply finset.sum_congr rfl, assume x hx, exact derivative_sum },\n    apply finset.sum_congr rfl, assume n hn, apply finset.sum_congr rfl, assume m hm,\n    transitivity,\n    { apply congr_arg, exact single_eq_C_mul_X },\n    exact derivative_C_mul_X_pow _ _\n  end\n  ... = f.sum (\u03bbn a, g.sum (\u03bbm b,\n      (C (a * n) * X^(n - 1)) * (C b * X^m) + (C a * X^n) * (C (b * m) * X^(m - 1)))) :\n    sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm,\n      by simp only [nat.cast_add, mul_add, add_mul, C_add, C_mul];\n      cases n; simp only [nat.succ_sub_succ, pow_zero];\n      cases m; simp only [nat.cast_zero, C_0, nat.succ_sub_succ, zero_mul, mul_zero,\n        nat.sub_zero, pow_zero, pow_add, one_mul, pow_succ, mul_comm, mul_left_comm]\n  ... = derivative f * g + f * derivative g :\n    begin\n      conv { to_rhs, congr,\n        { rw [\u2190 sum_C_mul_X_eq g] },\n        { rw [\u2190 sum_C_mul_X_eq f] } },\n      simp only [finsupp.sum, sum_add_distrib, finset.mul_sum, finset.sum_mul, derivative_apply]\n    end\n\ntheorem derivative_pow_succ (p : polynomial R) (n : \u2115) :\n  (p ^ (n + 1)).derivative = (n + 1) * (p ^ n) * p.derivative :=\nnat.rec_on n (by rw [pow_one, nat.cast_zero, zero_add, one_mul, pow_zero, one_mul]) $ \u03bb n ih,\nby rw [pow_succ', derivative_mul, ih, mul_right_comm, \u2190 add_mul,\n    add_mul (n.succ : polynomial R), one_mul, pow_succ', mul_assoc, n.cast_succ]\n\ntheorem derivative_pow (p : polynomial R) (n : \u2115) :\n  (p ^ n).derivative = n * (p ^ (n - 1)) * p.derivative :=\nnat.cases_on n (by rw [pow_zero, derivative_one, nat.cast_zero, zero_mul, zero_mul]) $ \u03bb n,\nby rw [p.derivative_pow_succ n, n.succ_sub_one, n.cast_succ]\n\nlemma derivative_comp (p q : polynomial R) :\n  (p.comp q).derivative = q.derivative * p.derivative.comp q :=\nbegin\n  apply polynomial.induction_on' p,\n  { intros p\u2081 p\u2082 h\u2081 h\u2082, simp [h\u2081, h\u2082, mul_add], },\n  { intros n r,\n    simp only [derivative_pow, derivative_mul, monomial_comp, derivative_monomial, derivative_C,\n      zero_mul, C_eq_nat_cast, zero_add, ring_hom.map_mul],\n    -- is there a tactic for this? (a multiplicative `abel`):\n    rw [mul_comm (derivative q)],\n    simp only [mul_assoc], }\nend\n\n@[simp]\ntheorem derivative_map [comm_semiring S] (p : polynomial R) (f : R \u2192+* S) :\n  (p.map f).derivative = p.derivative.map f :=\npolynomial.induction_on p\n  (\u03bb r, by rw [map_C, derivative_C, derivative_C, map_zero])\n  (\u03bb p q ihp ihq, by rw [map_add, derivative_add, ihp, ihq, derivative_add, map_add])\n  (\u03bb n r ih, by rw [map_mul, map_C, map_pow, map_X,\n      derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one,\n      derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one,\n      map_mul, map_C, map_mul, map_pow, map_add, map_nat_cast, map_one, map_X])\n\n@[simp]\ntheorem iterate_derivative_map [comm_semiring S] (p : polynomial R) (f : R \u2192+* S) (k : \u2115):\n  polynomial.derivative^[k] (p.map f) = (polynomial.derivative^[k] p).map f :=\nbegin\n  induction k with k ih generalizing p,\n  { simp, },\n  { simp [ih], },\nend\n\n/-- Chain rule for formal derivative of polynomials. -/\ntheorem derivative_eval\u2082_C (p q : polynomial R) :\n  (p.eval\u2082 C q).derivative = p.derivative.eval\u2082 C q * q.derivative :=\npolynomial.induction_on p\n  (\u03bb r, by rw [eval\u2082_C, derivative_C, eval\u2082_zero, zero_mul])\n  (\u03bb p\u2081 p\u2082 ih\u2081 ih\u2082, by rw [eval\u2082_add, derivative_add, ih\u2081, ih\u2082, derivative_add, eval\u2082_add, add_mul])\n  (\u03bb n r ih, by rw [pow_succ', \u2190 mul_assoc, eval\u2082_mul, eval\u2082_X, derivative_mul, ih,\n      @derivative_mul _ _ _ X, derivative_X, mul_one, eval\u2082_add, @eval\u2082_mul _ _ _ _ X, eval\u2082_X,\n      add_mul, mul_right_comm])\n\ntheorem of_mem_support_derivative {p : polynomial R} {n : \u2115} (h : n \u2208 p.derivative.support) :\n  n + 1 \u2208 p.support :=\nfinsupp.mem_support_iff.2 $ \u03bb (h1 : p.coeff (n+1) = 0), finsupp.mem_support_iff.1 h $\nshow p.derivative.coeff n = 0, by rw [coeff_derivative, h1, zero_mul]\n\ntheorem degree_derivative_lt {p : polynomial R} (hp : p \u2260 0) : p.derivative.degree < p.degree :=\n(finset.sup_lt_iff $ bot_lt_iff_ne_bot.2 $ mt degree_eq_bot.1 hp).2 $ \u03bb n hp, lt_of_lt_of_le\n(with_bot.some_lt_some.2 n.lt_succ_self) $ finset.le_sup $ of_mem_support_derivative hp\n\ntheorem nat_degree_derivative_lt {p : polynomial R} (hp : p.derivative \u2260 0) :\n  p.derivative.nat_degree < p.nat_degree :=\nhave hp1 : p \u2260 0, from \u03bb h, hp $ by rw [h, derivative_zero],\nwith_bot.some_lt_some.1 $\nbegin\n  rw [nat_degree, option.get_or_else_of_ne_none $ mt degree_eq_bot.1 hp, nat_degree,\n    option.get_or_else_of_ne_none $ mt degree_eq_bot.1 hp1],\n  exact degree_derivative_lt hp1\nend\n\ntheorem degree_derivative_le {p : polynomial R} : p.derivative.degree \u2264 p.degree :=\nif H : p = 0 then le_of_eq $ by rw [H, derivative_zero] else le_of_lt $ degree_derivative_lt H\n\n/-- The formal derivative of polynomials, as linear homomorphism. -/\ndef derivative_lhom (R : Type*) [comm_ring R] : polynomial R \u2192\u2097[R] polynomial R :=\n{ to_fun    := derivative,\n  map_add'  := \u03bb p q, derivative_add,\n  map_smul' := \u03bb r p, derivative_smul r p }\n\n@[simp] lemma derivative_lhom_coe {R : Type*} [comm_ring R] :\n  (polynomial.derivative_lhom R : polynomial R \u2192 polynomial R) = polynomial.derivative :=\nrfl\n\n@[simp] lemma derivative_cast_nat {n : \u2115} : derivative (n : polynomial R) = 0 :=\nbegin\n  rw \u2190 C.map_nat_cast n,\n  exact derivative_C,\nend\n\n@[simp] lemma iterate_derivative_cast_nat_mul {n k : \u2115} {f : polynomial R} :\n  derivative^[k] (n * f) = n * (derivative^[k] f) :=\nbegin\n  induction k with k ih generalizing f,\n  { simp [nat.iterate], },\n  { simp [nat.iterate, ih], }\nend\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nlemma derivative_comp_one_sub_X (p : polynomial R) :\n  (p.comp (1-X)).derivative = -p.derivative.comp (1-X) :=\nby simp [derivative_comp]\n\n@[simp]\nlemma iterate_derivative_comp_one_sub_X (p : polynomial R) (k : \u2115) :\n  derivative^[k] (p.comp (1-X)) = (-1)^k * (derivative^[k] p).comp (1-X) :=\nbegin\n  induction k with k ih generalizing p,\n  { simp, },\n  { simp [ih p.derivative, iterate_derivative_neg, derivative_comp, pow_succ], },\nend\n\nend comm_ring\n\nsection domain\nvariables [integral_domain R]\n\nlemma mem_support_derivative [char_zero R] (p : polynomial R) (n : \u2115) :\n  n \u2208 (derivative p).support \u2194 n + 1 \u2208 p.support :=\nsuffices (\u00ac(coeff p (n + 1) = 0 \u2228 ((n + 1:\u2115) : R) = 0)) \u2194 coeff p (n + 1) \u2260 0,\n  by simpa only [mem_support_iff, coeff_derivative, ne.def, mul_eq_zero],\nby { rw [nat.cast_eq_zero], simp only [nat.succ_ne_zero, or_false] }\n\n@[simp] lemma degree_derivative_eq [char_zero R] (p : polynomial R) (hp : 0 < nat_degree p) :\n  degree (derivative p) = (nat_degree p - 1 : \u2115) :=\nbegin\n  have h0 : p \u2260 0,\n  { contrapose! hp,\n    simp [hp] },\n  apply le_antisymm,\n  { rw derivative_apply,\n    apply le_trans (degree_sum_le _ _) (sup_le (\u03bb n hn, _)),\n    apply le_trans (degree_C_mul_X_pow_le _ _) (with_bot.coe_le_coe.2 (nat.sub_le_sub_right _ _)),\n    apply le_nat_degree_of_mem_supp _ hn },\n  { refine le_sup _,\n    rw [mem_support_derivative, nat.sub_add_cancel, mem_support_iff],\n    { show \u00ac leading_coeff p = 0,\n      rw [leading_coeff_eq_zero],\n      assume h, rw [h, nat_degree_zero] at hp,\n      exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp), },\n    exact hp }\nend\n\ntheorem nat_degree_eq_zero_of_derivative_eq_zero\n  [char_zero R] {f : polynomial R} (h : f.derivative = 0) :\n  f.nat_degree = 0 :=\nbegin\n  by_cases hf : f = 0,\n  { exact (congr_arg polynomial.nat_degree hf).trans rfl },\n  { rw nat_degree_eq_zero_iff_degree_le_zero,\n    by_contra absurd,\n    have f_nat_degree_pos : 0 < f.nat_degree,\n    { rwa [not_le, \u2190nat_degree_pos_iff_degree_pos] at absurd },\n    let m := f.nat_degree - 1,\n    have hm : m + 1 = f.nat_degree := nat.sub_add_cancel f_nat_degree_pos,\n    have h2 := coeff_derivative f m,\n    rw polynomial.ext_iff at h,\n    rw [h m, coeff_zero, zero_eq_mul] at h2,\n    cases h2,\n    { rw [hm, \u2190leading_coeff, leading_coeff_eq_zero] at h2,\n      exact hf h2, },\n    { norm_cast at h2 } }\nend\n\nend domain\n\nend derivative\nend polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/polynomial/derivative.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.8175744850834649, "lm_q1q2_score": 0.7439167479405904}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- $\\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}$ is the arithmetic mean\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a + b + c) / 3, from\n    by {norm_num,ring},\n  -- $\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b}$ is the harmonic mean\n  have h2 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) = 3 / ((b + c) + (a + c) + (a + b)), from\n    by {norm_num,ring},\n  -- $\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b}$ is the harmonic mean\n  have h3 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) = 3 / ((b + c) + (a + c) + (a + b)), from\n    by {norm_num,ring},\n  -- $\\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}$ is the arithmetic mean\n  have h4 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a + b + c) / 3, from\n    by {norm_num,ring},\n  -- $\\frac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n  have h5 : (a + b + c) / ((b + c) + (a + c) + (a + b)) = 1 / 2, from\n    by {norm_num,ring},\n  -- $\\frac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }$\n  have h6 : 9 * (a + b + c) / ((b + c) + (a + c) + (a + b)) = 9 / 2, from\n    by {norm_num,ring},\n  -- $\\frac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3$\n  have h7 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) / 3 = 3 / ((b + c) + (a + c) + (a + b)), from\n    by {norm_num,ring},\n  -- $\\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}$\n  have h8 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) = 9 / 2, from\n    by {norm_num,ring},\n  -- $\\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b} \\ge \\dfrac 3 2$\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 3 / 2, from\n    by {rw [\u2190 h1, \u2190 h8], apply arithmetic_mean_is_never_less_than_harmonic_mean, norm_num, ring, exact hb, exact hc},\nend\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- adding a $3$\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)), from\n    by rw add_three,\n  -- as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n  have h2 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) \u2265 ((9 * (a + b + c)) / ((b + c) + (a + c) + (a + b))), from\n    by rw [div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same,div_add_div_same],\n  -- dividing by $3 \\paren {a + b + c}$\n  have h3 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from\n    by rw div_mul_div_same h1,\n  -- These are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from\n    by {rw \u2190 h1, apply arithmetic_mean_is_never_less_than_harmonic_mean, exact h3}\nend\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- $a$, $b$ and $c$ are positive real numbers\n  assume (ha : 0 < a) (hb : 0 < b) (hc : 0 < c),\n\n  -- Then:\n  -- :$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from\n  begin\n    -- $\\leadstoandfrom$\n    have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2) * (a + b + c) / ((b + c) + (a + c) + (a + b)), from\n    begin\n      -- as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n      have h1 : (a + b + c) / ((b + c) + (a + c) + (a + b)) = (1 / 2), from by {\n        have h1 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n        have h2 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n        show ((a + b + c) / ((b + c) + (a + c) + (a + b))) = (1 / 2), from by {\n          have h3 : ((a + b + c) * ((b + c) + (a + c) + (a + b))) = ((a + b + c) * (a + b + c)) + ((a + b + c) * (a + c)) + ((a + b + c) * (b + c)), from by ring,\n          have h4 : ((a + b + c) * ((b + c) + (a + c) + (a + b))) = ((a + b + c) * (a + b + c)) + ((a + b + c) * (a + c)) + ((a + b + c) * (b + c)), from by ring,\n          have h5 : ((a + b + c) * ((b + c) + (a + c) + (a + b))) = ((a + b + c) * (a + b + c)) + ((a + b + c) * (a + c)) + ((a + b + c) * (b + c)), from by ring,\n          have h6 : ((a + b + c) * ((b + c) + (a + c) + (a + b))) = ((a + b + c) * (a + b + c)) + ((a + b + c) * (a + c)) + ((a + b + c) * (b + c)), from by ring,\n          have h7 : ((a + b + c) * ((b + c) + (a + c) + (a + b))) = ((a + b + c) * (a + b + c)) + ((a + b + c) * (a + c)) + ((a + b + c) * (b + c)), from by ring,\n          have h8 : ((a + b + c) * ((b + c) + (a + c) + (a + b))) = ((a + b + c) * (a + b + c)) + ((a + b + c) * (a + c)) + ((a + b + c) * (b + c)), from by ring,\n          rw [h3,h7,h8,div_mul_cancel _ (ne.symm (ne_of_lt ha))],\n          rw [h4,h6,h8,div_mul_cancel _ (ne.symm (ne_of_lt hb))],\n          rw [h5,h6,h7,div_mul_cancel _ (ne.symm (ne_of_lt hc))],\n          ring,\n        },\n      },\n      -- $\\leadstoandfrom$\n      have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2) * (a + b + c) / ((b + c) + (a + c) + (a + b)), from by {\n        rw h1,\n        have h3 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2) * (1 / 2), from by linarith,\n        rw mul_comm (9 / 2) (1 / 2),\n        exact h3,\n      },\n      -- $\\leadstoandfrom$\n      have h3 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2) * (1 / 2), from by linarith,\n      rw mul_comm (9 / 2) (1 / 2),\n      exact h3,\n    },\n\n    -- These are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n\n    -- From Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n\n    -- Thus Nesbitt's Inequality holds.\n    have h2 : (9 / 2) * (a + b + c) / ((b + c) + (a + c) + (a + b)) \u2265 (9 / 2) * (3 / ((b + c) + (a + c) + (a + b))), from by {\n      have h3 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n      have h4 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n      have h5 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n      have h6 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n      have h7 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n      have h8 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a + b + c), from by ring,\n      have h9 : ((b + c) + (a + c) + (a + b)) * (a + b + c) = (b + c) * (a + b + c) + (a + c) * (a + b + c) + (a + b) * (a\nend --Needs more than 2000 tokens!\n\n--OUTPUT 4\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- Rearranging and adding $3$ gives:\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from by {\n    rw [add_div,add_div,add_div,add_div,add_div,add_div,add_div],\n    have h2 : a + b + c > 0, from by {rw \u2190 add_assoc, rw add_comm b c, rw add_assoc, rw add_comm a (b + c), rw add_assoc, rw add_comm c a, rw add_assoc, rw add_comm b c, rw add_assoc, rw add_comm a (b + c), rw add_assoc, rw add_comm c a, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, ring},\n    rw \u2190 div_div_eq_div_mul,\n    rw div_self h2,\n    rw mul_one,\n    rw mul_comm,\n    rw mul_one,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw add_mul,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n    rw \u2190\nend --Needs more than 2000 tokens!\n\n--OUTPUT 5\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- adding $3$ gives:\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2), from by {\n    have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + 3, from by {\n      rw \u2190 add_assoc (c / (a + b)) (b / (a + c)) (a / (b + c)),\n      rw add_comm 3 (c / (a + b)), rw \u2190 add_assoc (b / (a + c)) (a / (b + c)) 3,\n      rw \u2190 add_assoc (a / (b + c)) 3 (b / (a + c)), rw \u2190 add_assoc 3 (b / (a + c)) (a / (b + c)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h3 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + 3 = (a / (b + c)) + 3 + (b / (a + c)) + (c / (a + b)), from by {\n      rw \u2190 add_assoc (c / (a + b)) (b / (a + c)) (a / (b + c)),\n      rw add_comm 3 (c / (a + b)), rw \u2190 add_assoc (b / (a + c)) (a / (b + c)) 3,\n      rw \u2190 add_assoc (a / (b + c)) 3 (b / (a + c)), rw \u2190 add_assoc 3 (b / (a + c)) (a / (b + c)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h4 : (a / (b + c)) + 3 + (b / (a + c)) + (c / (a + b)) = 3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b)), from by {\n      rw \u2190 add_assoc 3 (c / (a + b)) ((a / (b + c)) + (b / (a + c))),\n      rw \u2190 add_assoc 3 ((a / (b + c)) + (b / (a + c))) (c / (a + b)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h5 : 3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = 3 + ((a / (b + c)) + (b / (a + c)) + (c / (a + b))), from by {\n      rw \u2190 add_assoc 3 (c / (a + b)) ((a / (b + c)) + (b / (a + c))),\n      rw \u2190 add_assoc 3 ((a / (b + c)) + (b / (a + c))) (c / (a + b)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h6 : 3 + ((a / (b + c)) + (b / (a + c)) + (c / (a + b))) = (3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b))), from by {\n      rw \u2190 add_assoc 3 (c / (a + b)) ((a / (b + c)) + (b / (a + c))),\n      rw \u2190 add_assoc 3 ((a / (b + c)) + (b / (a + c))) (c / (a + b)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h7 : 3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b))) + 0, from by {\n      rw \u2190 add_assoc (c / (a + b)) (b / (a + c)) (a / (b + c)),\n      rw add_comm 3 (c / (a + b)), rw \u2190 add_assoc (b / (a + c)) (a / (b + c)) 3,\n      rw \u2190 add_assoc (a / (b + c)) 3 (b / (a + c)), rw \u2190 add_assoc 3 (b / (a + c)) (a / (b + c)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h8 : (3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b))) + 0 = (3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b))) + 3*0, from by {\n      rw \u2190 add_assoc (c / (a + b)) (b / (a + c)) (a / (b + c)),\n      rw add_comm 3 (c / (a + b)), rw \u2190 add_assoc (b / (a + c)) (a / (b + c)) 3,\n      rw \u2190 add_assoc (a / (b + c)) 3 (b / (a + c)), rw \u2190 add_assoc 3 (b / (a + c)) (a / (b + c)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h9 : (3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b))) + 3*0 = (3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b))) + 3*1, from by {\n      rw \u2190 add_assoc (c / (a + b)) (b / (a + c)) (a / (b + c)),\n      rw add_comm 3 (c / (a + b)), rw \u2190 add_assoc (b / (a + c)) (a / (b + c)) 3,\n      rw \u2190 add_assoc (a / (b + c)) 3 (b / (a + c)), rw \u2190 add_assoc 3 (b / (a + c)) (a / (b + c)),\n      repeat {rw \u2190 add_assoc},\n    },\n    have h10 : (3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b))) + 3*1 = 3 + (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + 3, from by {\n      rw \u2190 add_assoc (c / (a + b)) (b / (a + c)) (a / (b + c)),\n      rw add_comm 3 (c / (a + b)), rw \u2190 add_assoc (b / (a + c)) (a / (b + c)) 3,\n      rw \u2190 add_assoc (a / (b + c)) 3 (b / (a + c)), rw \u2190 add_assoc 3 (b / (a + c)) (a / (b + c)),\n      repeat {rw \u2190 add_assoc},\n    },\n    show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2), from eq.trans h2 (eq.trans h3 (eq.trans h4 (eq.trans h5 (eq.trans h6 (eq.trans h7 (eq.trans h8 h9))))))\n  },\n\n  -- as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n  have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / ((b + c) + (a + c) + (a + b))), from by {\n    have h3 : (a + b + c\nend --Needs more than 2000 tokens!\n\n--OUTPUT 6\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- By adding $3$\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)),\n    from by {rw [add_halves,add_halves,add_halves, add_halves,add_halves,add_halves], ring,},\n  -- as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n  have h2 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) \u2265 (9 * (a + b + c)) / ((b + c) + (a + c) + (a + b)),\n    from by {rw add_halves, ring,},\n  -- dividing by $3 \\paren {a + b + c}$\n  have h3 : (9 * (a + b + c)) / ((b + c) + (a + c) + (a + b)) \u2265 ((1 / (b + c)) + (1 / (a + c)) + (1 / (a + b))) / 3,\n    from by {rw mul_assoc, apply div_le_div_of_le_of_pos h2, ring,},\n  -- These are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n  have h4 : ((1 / (b + c)) + (1 / (a + c)) + (1 / (a + b))) / 3 \u2265 (3 / ((b + c) + (a + c) + (a + b))),\n    from by {apply arithmetic_mean_ge_harmonic_mean,},\n  have h5 : ((3 : \u211d) / ((b + c) + (a + c) + (a + b))) \u2265 (3 / 2),\n    from by {apply div_le_div_of_le_of_pos,ring,},\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from by {\n    apply le_trans,\n    apply h1,\n    apply le_trans,\n    apply h3,\n    apply le_trans,\n    apply h4,\n    apply h5,\n  }\nend\n\n--OUTPUT 7\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- $\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from\n    by {\n      -- by adding $3$\n      have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)),\n        from by {rw [div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv], exact add_le_add (le_div_iff_mul_le'.mp hb) (le_div_iff_mul_le'.mp hc) (le_div_iff_mul_le'.mp hc) (le_div_iff_mul_le'.mp ha) (le_div_iff_mul_le'.mp ha) (le_div_iff_mul_le'.mp hb), },\n      -- as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n      have h3 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) \u2265 (3 / (2 * (b + c + a))),\n        from by {rw [div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv], rw [\u2190 mul_assoc,\u2190 mul_assoc,\u2190 mul_assoc], rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, ring, },\n      -- dividing by $3 \\paren {a + b + c}$\n      have h4 : (3 / (2 * (b + c + a))) \u2265 (3 / ((b + c) + (a + c) + (a + b))),\n        from by {rw [\u2190 div_eq_mul_inv,\u2190 div_eq_mul_inv,\u2190 div_eq_mul_inv,\u2190 div_eq_mul_inv], rw [\u2190 mul_assoc,\u2190 mul_assoc,\u2190 mul_assoc,\u2190 mul_assoc,\u2190 mul_assoc,\u2190 mul_assoc,\u2190 mul_assoc,\u2190 mul_assoc], rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, rw \u2190 add_assoc, ring, exact mul_le_mul_left ha (le_div_iff_mul_le'.mp hb) (le_div_iff_mul_le'.mp hc) (le_div_iff_mul_le'.mp ha) (le_div_iff_mul_le'.mp hb) (le_div_iff_mul_le'.mp hc), },\n      -- These are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n      -- From Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n      -- Thus Nesbitt's Inequality holds.\n      exact arithmetic_mean_never_less_harmonic_mean h2 h4,\n    },\n  -- $\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from h1,\nend\n\n--OUTPUT 8\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have habc : 0 < a + b + c, from by {apply add_pos ha, apply add_pos hb, apply add_pos hc},\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) :\n  begin\n    rw [\u2190 add_div_right ha, \u2190 add_div_right hb, \u2190 add_div_right hc],\n    ring\n  end\n  ... \u2265 (9 * (a + b + c)) / (2 * (b + c) + 2 * (a + c) + 2 * (a + b)) :\n  begin\n    apply div_le_div_of_le_of_pos (add_le_add (add_le_add (mul_le_mul_of_nonneg_left (le_of_lt habc) (le_of_lt (add_pos hb hc)))\n      (mul_le_mul_of_nonneg_left (le_of_lt habc) (le_of_lt (add_pos ha hc))))\n      (mul_le_mul_of_nonneg_left (le_of_lt habc) (le_of_lt (add_pos ha hb)))),\n    show (2 * (b + c) + 2 * (a + c) + 2 * (a + b)) > 0, from by {apply add_pos, apply add_pos, apply add_pos},\n    rw [\u2190 mul_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc],\n    rw [\u2190 mul_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc],\n    apply add_le_add (add_le_add (mul_le_mul_of_nonneg_left (le_of_lt habc) (le_of_lt (add_pos hb hc)))\n      (mul_le_mul_of_nonneg_left (le_of_lt habc) (le_of_lt (add_pos ha hc))))\n      (mul_le_mul_of_nonneg_left (le_of_lt habc) (le_of_lt (add_pos ha hb))),\n  end\n  ... \u2265 (3 * ((1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)))) / (b + c + a + c + a + b) :\n  begin\n    apply div_le_div_of_le_of_pos (add_le_add (add_le_add (mul_le_mul_of_nonneg_left (le_of_lt (add_pos hb hc)) (le_of_lt (add_pos ha hc)))\n      (mul_le_mul_of_nonneg_left (le_of_lt (add_pos ha hc)) (le_of_lt (add_pos ha hb))))\n      (mul_le_mul_of_nonneg_left (le_of_lt (add_pos ha hb)) (le_of_lt (add_pos hb hc)))),\n    show (b + c + a + c + a + b) > 0, from by {apply add_pos, apply add_pos, apply add_pos},\n    rw [\u2190 mul_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc],\n    rw [\u2190 mul_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 add_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc, \u2190 mul_assoc],\n    apply add_le_add (add_le_add (mul_le_mul_of_nonneg_left (le_of_lt (add_pos hb hc)) (le_of_lt (add_pos ha hc)))\n      (mul_le_mul_of_nonneg_left (le_of_lt (add_pos ha hc)) (le_of_lt (add_pos ha hb))))\n      (mul_le_mul_of_nonneg_left (le_of_lt (add_pos ha hb)) (le_of_lt (add_pos hb hc))),\n  end\n  ... = 3 * ((1 / (b + c)) + (1 / (a + c)) + (1 / (a + b))) : by rw [\u2190 add_div_right ha, \u2190 add_div_right hb, \u2190 add_div_right hc]\n  ... \u2265 3 * (2 / 3) : by apply arithmetic_mean_is_never_less_than_harmonic_mean\n  ... = 3 : by rw [\u2190 mul_assoc, mul_comm 3 2, \u2190 mul_assoc, mul_comm 3 2, mul_assoc],\nend\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  -- Then $A \u2286 S$ and $B \u2286 S$, by power set definition\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB},\n  -- Then $(A \u2229 B) \u2286 A$, by intersection of set is a subset\n  have h2 : (A \u2229 B) \u2286 A, from by apply set.inter_subset_left,\n  -- Then $(A \u2229 B) \u2286 S$, by subset relation is transitive \n  have h3 : (A \u2229 B) \u2286 S, from by {apply set.subset.trans h2 h1.left},\n  -- Hence $(A \u2229 B) \u2208  \ud835\udcab S$, by power set definition\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by {apply set.mem_powerset h3},\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  -- expand the power\n  calc (x + y)^2 = (x+y)*(x+y) : by rw sq\n  -- distributive property of multiplication over addition gives:\n  ... = x*(x+y) + y*(x+y) : by rw add_mul\n  -- applying the above property further gives:\n  ... = x*x + x*y + y*x + y*y : by {rw [mul_comm x (x+y),mul_comm y (x+y)], rw [add_mul,add_mul], ring}\n  -- rearranging the terms using commutativity and adding gives:\n  ... = x^2 + 2*x*y + y^2 : by {repeat {rw \u2190 sq}, rw mul_comm y x, ring}\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  -- Group has Latin Square Property\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by {\n    assume a b : G, use a\u207b\u00b9 * b, obviously, },\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by {\n    assume a b : G, use b * a\u207b\u00b9, obviously, }, \n\n  -- Setting $b = a$, this becomes:\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from \n    assume a : G, h1 a a,\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from\n    assume a : G, h2 a a,\n\n  -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from assume a :G,\n    exists_unique.unique (h3 a) (classical.some_spec (exists_unique.exists (h3 a)))\n    (mul_one a),\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from assume a : G,\n    exists_unique.unique (h4 a) (classical.some_spec (exists_unique.exists (h4 a))) (one_mul a), \n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by {\n    use (1 : G),\n    have h7 : \u2200 e : G, (\u2200 a : G, e * a = a \u2227 a * e = a) \u2192 e = 1, from by {\n      assume (e : G) (hident : \u2200 a : G, e * a = a \u2227 a * e = a),\n      have h8 : \u2200 a : G, e = classical.some (h3 a).exists, from assume (a : G),\n        exists_unique.unique (h3 a) (hident a).right\n        (classical.some_spec (exists_unique.exists (h3 a))), \n      have h9 : \u2200 a : G, e = classical.some (h4 a).exists, from assume (a : G),\n        exists_unique.unique (h4 a) (hident a).left\n        (classical.some_spec (exists_unique.exists (h4 a))),\n      show e = (1 : G), from eq.trans (h9 e) (h6 _),     \n    },\n    exact \u27e8by obviously, h7\u27e9,\n  }\nend\n\n/--`theorem`\nNesbitt's inequality\nLet $a$, $b$ and $c$ be positive real numbers.\n\nThen:\n:$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n\n`proof`\n{{begin-eqn}}\n{{eqn | l = \\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}\n      | o = \\ge\n      | r = \\dfrac 3 2\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac 9 2\n      | c = by adding $3$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3\n      | o = \\ge\n      | r = \\frac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = dividing by $3 \\paren {a + b + c}$\n}}\n{{end-eqn}}\nThese are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n\nFrom Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n\nThus Nesbitt's Inequality holds.\n{{qed}}\n\n-/\ntheorem  nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_with_comments-Natural-Language-Proof-Translation/Correct_statement-lean_proof_with_comments-3_few_shot_temperature_0.6_max_tokens_2000_n_8/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7439167377798006}}
{"text": "import data.nat.basic\nimport combinatorics.simple_graph.clique\nimport tactic.core\nimport data.finset.basic\nimport combinatorics.simple_graph.basic\nimport misc_finset\n\nopen finset nat \nnamespace simple_graph\n\n-- extremal graph theory studies finite graphs and we do a lot of counting so I naively thought I should \n-- prove some lemmas about (sub)graphs and edge_finsets..\n\n-- main new def below \"G.is_far H s\" if by deleting at most s edges from G we obtain a subgraph of H \n\nsection fedges\nvariables {t n : \u2115} \nvariables {\u03b1 : Type*} [fintype \u03b1][nonempty \u03b1][decidable_eq \u03b1]\n{G H : simple_graph \u03b1}[decidable_rel G.adj][decidable_rel H.adj]\n\n\n\n-- G is a subgraph of H iff G.edge_finset is subset of H.edge_finset\nlemma subgraph_edge_subset : G \u2264 H \u2194 G.edge_finset \u2286 H.edge_finset:=\nbegin\n  split,{ intro gh, intros e he, obtain \u27e8x,y\u27e9:=e, simp only [mem_edge_finset] at *, exact gh he},\n  { intro gh,intros x y h, have :\u27e6(x,y)\u27e7\u2208 G.edge_set:=h, rw [\u2190 mem_edge_finset] at this, \n  have:= gh this, rwa mem_edge_finset at this,},\nend\n\n-- graphs (on same vertex set) are equal iff edge_finsets are equal\nlemma eq_iff_edges_eq   : G = H \u2194 G.edge_finset = H.edge_finset:= \nbegin\n  split, {intro eq, exact subset_antisymm (subgraph_edge_subset.mp (le_of_eq eq)) (subgraph_edge_subset.mp (le_of_eq eq.symm))},\n  {intro eq, exact le_antisymm (subgraph_edge_subset.mpr (subset_of_eq eq)) (subgraph_edge_subset.mpr (subset_of_eq eq.symm))},  \nend\n\n-- if G=H (finite) graph they have the same number of edges..\nlemma eq_imp_edges_card_eq   : G=H \u2192 G.edge_finset.card = H.edge_finset.card:= \nbegin intro h,\n  rwa eq_iff_edges_eq.mp h,  \nend\n\n-- a subgraph of the same size or larger is the same graph (... everything is finite)\nlemma edge_eq_sub_imp_eq (hs: G\u2264 H) (hc: H.edge_finset.card \u2264 G.edge_finset.card): G = H\n:=eq_iff_edges_eq.mpr  (finset.eq_of_subset_of_card_le (subgraph_edge_subset.mp hs) hc)\n\n\n-- the empty graph has no edges\nlemma empty_has_no_edges :(\u22a5 : simple_graph \u03b1).edge_finset =\u2205:=\nbegin\n  ext, obtain \u27e8x,y\u27e9:=a, rw mem_edge_finset, simp only [not_mem_empty, iff_false],\n  intro h, assumption,\nend\n\n-- a graph is the empty graph iff it has no edges\nlemma empty_iff_edge_empty  : G = \u22a5  \u2194 G.edge_finset=\u2205\n:= by rwa [eq_iff_edges_eq, empty_has_no_edges]\n\n\n-- if G is not the empty graph there exist a pair of distinct adjacent vertices\nlemma edge_of_not_empty : G \u2260 \u22a5 \u2192 \u2203v:\u03b1,\u2203w:\u03b1, v\u2260 w \u2227 G.adj v w:=\nbegin\n  contrapose,intro h,push_neg at h, push_neg, ext,rw bot_adj,specialize h x x_1,\n  by_cases h':x=x_1, simp only [*, G.irrefl], have:= (h h'), tauto,\nend\n\n-- if G is 2-clique free then it is empty\nlemma two_clique_free_imp_empty  : G.clique_free 2 \u2192 G = \u22a5:=\nbegin\n  intros h ,  contrapose h, obtain \u27e8v,w,had\u27e9:=edge_of_not_empty h,\n  rw clique_free,push_neg, use {v,w}, split, {tidy}, {exact card_doubleton had.1},\nend\n\n-- meet of two graphs has edges given by intersection\nlemma meet_edges_eq {G H :simple_graph \u03b1} [decidable_rel G.adj][decidable_rel H.adj] : (G\u2293H).edge_finset =G.edge_finset \u2229 H.edge_finset:=\nbegin\n  ext,simp only [mem_edge_finset, mem_inter], induction a,{refl},{refl},\nend\n\n-- join of two graphs has edges given by union\nlemma join_edges_eq {G H :simple_graph \u03b1} [decidable_rel G.adj][decidable_rel H.adj] : (G \u2294 H).edge_finset =G.edge_finset \u222a H.edge_finset:=\nbegin\n  ext,simp only [mem_edge_finset, mem_union], induction a,{refl},{refl},\nend\n\n-- edge sets are disjoint iff meet is empty graph\nlemma disjoint_edges_iff_meet_empty {G H :simple_graph \u03b1} [decidable_rel G.adj][decidable_rel H.adj] : disjoint G.edge_finset H.edge_finset \u2194  G \u2293 H = \u22a5:= \nbegin\n  rw [empty_iff_edge_empty, meet_edges_eq], exact disjoint_iff,\nend\n\n--if G and H meet in \u22a5 then the card of their edge sets adds\nlemma card_edges_add_of_meet_empty {G H :simple_graph \u03b1} [decidable_rel G.adj][decidable_rel H.adj] : G \u2293 H = \u22a5 \u2192\n(G \u2294 H).edge_finset.card= G.edge_finset.card+ H.edge_finset.card:=\nbegin\n  rw [\u2190 disjoint_edges_iff_meet_empty, join_edges_eq], intros h, exact card_disjoint_union h,\nend\n\n-- the subgraph formed by deleting edges (from edge_finset)\n@[ext]\ndef del_fedges (G:simple_graph \u03b1) (S: finset (sym2 \u03b1))[decidable_rel G.adj]  :simple_graph \u03b1 :={\nadj:= G.adj \\ sym2.to_rel S,\nsymm := \u03bb a b, by simp [adj_comm, sym2.eq_swap] }\n\n--deleting all the edges in H from G is G\\H\nlemma del_fedges_is_sdiff  (G H:simple_graph \u03b1) (S: finset (sym2 \u03b1))[decidable_rel G.adj][decidable_rel H.adj] :\n G.del_fedges H.edge_finset =G\\H:=\nbegin\n  ext,simp only [del_fedges, sdiff_adj, set.coe_to_finset, pi.sdiff_apply, sym2.to_rel_prop, mem_edge_set],\n  refl,\nend\n\n-- now introduce a simple version of distance between graphs \n-- G.is_far s H iff there exists a finset of at most s edges such that G-S is a subgraph of H\n\ndef is_far (G H :simple_graph \u03b1) (s : \u2115) [decidable_rel G.adj][decidable_rel H.adj] \n:= \u2203S:finset (sym2 \u03b1), ((G.del_fedges S) \u2264 H) \u2227 (S.card \u2264 s)\n\n\nlemma is_far_le (G H :simple_graph \u03b1) {s t : \u2115} (h:s\u2264t) [decidable_rel G.adj][decidable_rel H.adj]: \nG.is_far H s \u2192 G.is_far H t:=\nbegin\n  intro h1, obtain \u27e8S,hS1,hS2\u27e9:=h1,exact \u27e8S,hS1,le_trans hS2 h\u27e9,\nend\n\nlemma is_far_trivial (G H :simple_graph \u03b1) (s : \u2115) [decidable_rel G.adj][decidable_rel H.adj]:\n(G.edge_finset.card \u2264 s) \u2192 G.is_far H s:=\nbegin\n  intro h,  refine \u27e8G.edge_finset,_,h\u27e9, rw del_fedges_is_sdiff, simp only [_root_.sdiff_self, bot_le],\n  exact G.edge_finset,\nend\n\n\nend fedges\n\nend simple_graph", "meta": {"author": "jt496", "repo": "extremal_graph", "sha": "1bfb63ed1f6ca633d1ee4e1846f429cfe32c6a83", "save_path": "github-repos/lean/jt496-extremal_graph", "path": "github-repos/lean/jt496-extremal_graph/extremal_graph-1bfb63ed1f6ca633d1ee4e1846f429cfe32c6a83/src/fedges.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.743916733760171}}
{"text": "/-\nCopyright (c) 2022 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Junyan Xu, Anne Baanen\n-/\nimport linear_algebra.linear_independent\nimport ring_theory.localization.fraction_ring\nimport ring_theory.localization.integer\n\n/-!\n# Modules / vector spaces over localizations / fraction fields\n\nThis file contains some results about vector spaces over the field of fractions of a ring.\n\n## Main results\n\n * `linear_independent.localization`: `b` is linear independent over a localization of `R`\n   if it is linear independent over `R` itself\n * `basis.localization`: promote an `R`-basis `b` to an `R\u209b`-basis,\n   where `R\u209b` is a localization of `R`\n * `linear_independent.iff_fraction_ring`: `b` is linear independent over `R` iff it is\n   linear independent over `Frac(R)`\n-/\n\nopen_locale big_operators\nopen_locale non_zero_divisors\n\nsection localization\n\nvariables {R : Type*} (R\u209b : Type*) [comm_ring R] [comm_ring R\u209b] [algebra R R\u209b]\nvariables (S : submonoid R) [hT : is_localization S R\u209b]\n\ninclude hT\n\nsection add_comm_monoid\nvariables {M : Type*} [add_comm_monoid M] [module R M] [module R\u209b M] [is_scalar_tower R R\u209b M]\n\nlemma linear_independent.localization {\u03b9 : Type*} {b : \u03b9 \u2192 M} (hli : linear_independent R b) :\n  linear_independent R\u209b b :=\nbegin\n  rw linear_independent_iff' at \u22a2 hli,\n  intros s g hg i hi,\n  choose a g' hg' using is_localization.exist_integer_multiples S s g,\n  letI := \u03bb i, classical.prop_decidable (i \u2208 s),\n  specialize hli s (\u03bb i, if hi : i \u2208 s then g' i hi else 0) _ i hi,\n  { rw [\u2190 @smul_zero _ M _ _ _ (a : R), \u2190 hg, finset.smul_sum],\n    refine finset.sum_congr rfl (\u03bb i hi, _),\n    dsimp only,\n    rw [dif_pos hi, \u2190 is_scalar_tower.algebra_map_smul R\u209b, hg' i hi, smul_assoc],\n    apply_instance },\n  refine ((is_localization.map_units R\u209b a).mul_right_eq_zero).mp _,\n  rw [\u2190 algebra.smul_def, \u2190 map_zero (algebra_map R R\u209b), \u2190 hli],\n  simp [hi, hg']\nend\nend add_comm_monoid\n\nsection add_comm_group\nvariables {M : Type*} [add_comm_group M] [module R M] [module R\u209b M] [is_scalar_tower R R\u209b M]\n\n/-- Promote a basis for `M` over `R` to a basis for `M` over the localization `R\u209b` -/\nnoncomputable def basis.localization {\u03b9 : Type*} (b : basis \u03b9 R M) : basis \u03b9 R\u209b M :=\nbasis.mk (b.linear_independent.localization R\u209b S) $\nby { rw [\u2190 @submodule.restrict_scalars_eq_top_iff R\u209b R, eq_top_iff, \u2190 b.span_eq],\n     apply submodule.span_le_restrict_scalars }\n\nend add_comm_group\n\nend localization\n\nsection fraction_ring\n\nvariables (R K : Type*) [comm_ring R] [field K] [algebra R K] [is_fraction_ring R K]\nvariables {V : Type*} [add_comm_group V] [module R V] [module K V] [is_scalar_tower R K V]\n\nlemma linear_independent.iff_fraction_ring {\u03b9 : Type*} {b : \u03b9 \u2192 V} :\n  linear_independent R b \u2194 linear_independent K b :=\n\u27e8linear_independent.localization K (R\u2070),\n linear_independent.restrict_scalars (smul_left_injective R one_ne_zero)\u27e9\n\nend fraction_ring\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/localization/module.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.743899251989196}}
{"text": "/-\nCopyright (c) 2022 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n-/\nimport ring_theory.simple_module\nimport topology.algebra.module.basic\n\n/-!\n# The kernel of a linear function is closed or dense\n\nIn this file we prove (`linear_map.is_closed_or_dense_ker`) that the kernel of a linear function `f\n: M \u2192\u2097[R] N` is either closed or dense in `M` provided that `N` is a simple module over `R`. This\napplies, e.g., to the case when `R = N` is a division ring.\n-/\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} {N : Type w}\n  [ring R] [topological_space R]\n  [topological_space M] [add_comm_group M] [add_comm_group N]\n  [module R M] [has_continuous_smul R M] [module R N]\n  [has_continuous_add M] [is_simple_module R N]\n\n/-- The kernel of a linear map taking values in a simple module over the base ring is closed or\ndense. Applies, e.g., to the case when `R = N` is a division ring. -/\nlemma linear_map.is_closed_or_dense_ker (l : M \u2192\u2097[R] N) :\n  is_closed (l.ker : set M) \u2228 dense (l.ker : set M) :=\nbegin\n  rcases l.surjective_or_eq_zero with (hl|rfl),\n  { exact l.ker.is_closed_or_dense_of_is_coatom (linear_map.is_coatom_ker_of_surjective hl) },\n  { rw linear_map.ker_zero,\n    left,\n    exact is_closed_univ },\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/module/simple.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7438992519307905}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport analysis.specific_limits.basic\nimport data.rat.denumerable\nimport data.set.pointwise.interval\nimport set_theory.cardinal.continuum\n\n/-!\n# The cardinality of the reals\n\nThis file shows that the real numbers have cardinality continuum, i.e. `#\u211d = \ud835\udd20`.\n\nWe show that `#\u211d \u2264 \ud835\udd20` by noting that every real number is determined by a Cauchy-sequence of the\nform `\u2115 \u2192 \u211a`, which has cardinality `\ud835\udd20`. To show that `#\u211d \u2265 \ud835\udd20` we define an injection from\n`{0, 1} ^ \u2115` to `\u211d` with `f \u21a6 \u03a3 n, f n * (1 / 3) ^ n`.\n\nWe conclude that all intervals with distinct endpoints have cardinality continuum.\n\n## Main definitions\n\n* `cardinal.cantor_function` is the function that sends `f` in `{0, 1} ^ \u2115` to `\u211d` by\n  `f \u21a6 \u03a3' n, f n * (1 / 3) ^ n`\n\n## Main statements\n\n* `cardinal.mk_real : #\u211d = \ud835\udd20`: the reals have cardinality continuum.\n* `cardinal.not_countable_real`: the universal set of real numbers is not countable.\n  We can use this same proof to show that all the other sets in this file are not countable.\n* 8 lemmas of the form `mk_Ixy_real` for `x,y \u2208 {i,o,c}` state that intervals on the reals\n  have cardinality continuum.\n\n## Notation\n\n* `\ud835\udd20` : notation for `cardinal.continuum` in locale `cardinal`, defined in `set_theory.continuum`.\n\n## Tags\ncontinuum, cardinality, reals, cardinality of the reals\n-/\n\nopen nat set\nopen_locale cardinal\nnoncomputable theory\n\nnamespace cardinal\n\nvariables {c : \u211d} {f g : \u2115 \u2192 bool} {n : \u2115}\n\n/-- The body of the sum in `cantor_function`.\n`cantor_function_aux c f n = c ^ n` if `f n = tt`;\n`cantor_function_aux c f n = 0` if `f n = ff`. -/\ndef cantor_function_aux (c : \u211d) (f : \u2115 \u2192 bool) (n : \u2115) : \u211d := cond (f n) (c ^ n) 0\n\n@[simp] lemma cantor_function_aux_tt (h : f n = tt) : cantor_function_aux c f n = c ^ n :=\nby simp [cantor_function_aux, h]\n\n@[simp] lemma cantor_function_aux_ff (h : f n = ff) : cantor_function_aux c f n = 0 :=\nby simp [cantor_function_aux, h]\n\nlemma cantor_function_aux_nonneg (h : 0 \u2264 c) : 0 \u2264 cantor_function_aux c f n :=\nby { cases h' : f n; simp [h'], apply pow_nonneg h }\n\nlemma cantor_function_aux_eq (h : f n = g n) :\n  cantor_function_aux c f n = cantor_function_aux c g n :=\nby simp [cantor_function_aux, h]\n\nlemma cantor_function_aux_zero (f : \u2115 \u2192 bool) :\n  cantor_function_aux c f 0 = cond (f 0) 1 0 :=\nby { cases h : f 0; simp [h] }\n\nlemma cantor_function_aux_succ (f : \u2115 \u2192 bool) :\n  (\u03bb n, cantor_function_aux c f (n + 1)) = \u03bb n, c * cantor_function_aux c (\u03bb n, f (n + 1)) n :=\nby { ext n, cases h : f (n + 1); simp [h, pow_succ] }\n\nlemma summable_cantor_function (f : \u2115 \u2192 bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n  summable (cantor_function_aux c f) :=\nbegin\n  apply (summable_geometric_of_lt_1 h1 h2).summable_of_eq_zero_or_self,\n  intro n, cases h : f n; simp [h]\nend\n\n/-- `cantor_function c (f : \u2115 \u2192 bool)` is `\u03a3 n, f n * c ^ n`, where `tt` is interpreted as `1` and\n`ff` is interpreted as `0`. It is implemented using `cantor_function_aux`. -/\ndef cantor_function (c : \u211d) (f : \u2115 \u2192 bool) : \u211d := \u2211' n, cantor_function_aux c f n\n\nlemma cantor_function_le (h1 : 0 \u2264 c) (h2 : c < 1) (h3 : \u2200 n, f n \u2192 g n) :\n  cantor_function c f \u2264 cantor_function c g :=\nbegin\n  apply tsum_le_tsum _ (summable_cantor_function f h1 h2) (summable_cantor_function g h1 h2),\n  intro n, cases h : f n, simp [h, cantor_function_aux_nonneg h1],\n  replace h3 : g n = tt := h3 n h, simp [h, h3]\nend\n\nlemma cantor_function_succ (f : \u2115 \u2192 bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n  cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (\u03bb n, f (n+1)) :=\nbegin\n  rw [cantor_function, tsum_eq_zero_add (summable_cantor_function f h1 h2)],\n  rw [cantor_function_aux_succ, tsum_mul_left, cantor_function_aux, pow_zero],\n  refl\nend\n\n/-- `cantor_function c` is strictly increasing with if `0 < c < 1/2`, if we endow `\u2115 \u2192 bool` with a\nlexicographic order. The lexicographic order doesn't exist for these infinitary products, so we\nexplicitly write out what it means. -/\nlemma increasing_cantor_function (h1 : 0 < c) (h2 : c < 1 / 2) {n : \u2115} {f g : \u2115 \u2192 bool}\n  (hn : \u2200(k < n), f k = g k) (fn : f n = ff) (gn : g n = tt) :\n  cantor_function c f < cantor_function c g :=\nbegin\n  have h3 : c < 1, { apply h2.trans, norm_num },\n  induction n with n ih generalizing f g,\n  { let f_max : \u2115 \u2192 bool := \u03bb n, nat.rec ff (\u03bb _ _, tt) n,\n    have hf_max : \u2200n, f n \u2192 f_max n,\n    { intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl },\n    let g_min : \u2115 \u2192 bool := \u03bb n, nat.rec tt (\u03bb _ _, ff) n,\n    have hg_min : \u2200n, g_min n \u2192 g n,\n    { intros n hn, cases n, rw [gn], apply rfl, contradiction },\n    apply (cantor_function_le (le_of_lt h1) h3 hf_max).trans_lt,\n    refine lt_of_lt_of_le _ (cantor_function_le (le_of_lt h1) h3 hg_min),\n    have : c / (1 - c) < 1,\n    { rw [div_lt_one, lt_sub_iff_add_lt],\n      { convert add_lt_add h2 h2, norm_num },\n      rwa sub_pos },\n    convert this,\n    { rw [cantor_function_succ _ (le_of_lt h1) h3, div_eq_mul_inv,\n          \u2190tsum_geometric_of_lt_1 (le_of_lt h1) h3],\n      apply zero_add },\n    { refine (tsum_eq_single 0 _).trans _,\n      { intros n hn, cases n, contradiction, refl },\n      { exact cantor_function_aux_zero _ }, } },\n  rw [cantor_function_succ f (le_of_lt h1) h3, cantor_function_succ g (le_of_lt h1) h3],\n  rw [hn 0 $ zero_lt_succ n],\n  apply add_lt_add_left, rw mul_lt_mul_left h1, exact ih (\u03bb k hk, hn _ $ nat.succ_lt_succ hk) fn gn\nend\n\n/-- `cantor_function c` is injective if `0 < c < 1/2`. -/\nlemma cantor_function_injective (h1 : 0 < c) (h2 : c < 1 / 2) :\n  function.injective (cantor_function c) :=\nbegin\n  intros f g hfg, classical, by_contra h, revert hfg,\n  have : \u2203n, f n \u2260 g n,\n  { rw [\u2190not_forall], intro h', apply h, ext, apply h' },\n  let n := nat.find this,\n  have hn : \u2200 (k : \u2115), k < n \u2192 f k = g k,\n  { intros k hk, apply of_not_not, exact nat.find_min this hk },\n  cases fn : f n,\n  { apply ne_of_lt, refine increasing_cantor_function h1 h2 hn fn _,\n    apply eq_tt_of_not_eq_ff, rw [\u2190fn], apply ne.symm, exact nat.find_spec this },\n  { apply ne_of_gt, refine increasing_cantor_function h1 h2 (\u03bb k hk, (hn k hk).symm) _ fn,\n    apply eq_ff_of_not_eq_tt, rw [\u2190fn], apply ne.symm, exact nat.find_spec this }\nend\n\n/-- The cardinality of the reals, as a type. -/\nlemma mk_real : #\u211d = \ud835\udd20 :=\nbegin\n  apply le_antisymm,\n  { rw real.equiv_Cauchy.cardinal_eq,\n    apply mk_quotient_le.trans, apply (mk_subtype_le _).trans_eq,\n    rw [\u2190 power_def, mk_nat, mk_rat, aleph_0_power_aleph_0] },\n  { convert mk_le_of_injective (cantor_function_injective _ _),\n    rw [\u2190power_def, mk_bool, mk_nat, two_power_aleph_0], exact 1 / 3, norm_num, norm_num }\nend\n\n/-- The cardinality of the reals, as a set. -/\nlemma mk_univ_real : #(set.univ : set \u211d) = \ud835\udd20 :=\nby rw [mk_univ, mk_real]\n\n/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/\nlemma not_countable_real : \u00ac (set.univ : set \u211d).countable :=\nby { rw [\u2190 le_aleph_0_iff_set_countable, not_le, mk_univ_real], apply cantor }\n\n/-- The cardinality of the interval (a, \u221e). -/\nlemma mk_Ioi_real (a : \u211d) : #(Ioi a) = \ud835\udd20 :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  rw [\u2190 not_lt], intro h,\n  refine ne_of_lt _ mk_univ_real,\n  have hu : Iio a \u222a {a} \u222a Ioi a = set.univ,\n  { convert Iic_union_Ioi, exact Iio_union_right },\n  rw \u2190 hu,\n  refine lt_of_le_of_lt (mk_union_le _ _) _,\n  refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) _,\n  have h2 : (\u03bb x, a + a - x) '' Ioi a = Iio a,\n  { convert image_const_sub_Ioi _ _, simp },\n  rw \u2190 h2,\n  refine add_lt_of_lt (cantor _).le _ h,\n  refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) _,\n  rw mk_singleton,\n  exact one_lt_aleph_0.trans (cantor _)\nend\n\n/-- The cardinality of the interval [a, \u221e). -/\nlemma mk_Ici_real (a : \u211d) : #(Ici a) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioi_real a \u25b8 mk_le_mk_of_subset Ioi_subset_Ici_self)\n\n/-- The cardinality of the interval (-\u221e, a). -/\nlemma mk_Iio_real (a : \u211d) : #(Iio a) = \ud835\udd20 :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  have h2 : (\u03bb x, a + a - x) '' Iio a = Ioi a,\n  { convert image_const_sub_Iio _ _, simp },\n  exact mk_Ioi_real a \u25b8 h2 \u25b8 mk_image_le\nend\n\n/-- The cardinality of the interval (-\u221e, a]. -/\nlemma mk_Iic_real (a : \u211d) : #(Iic a) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Iio_real a \u25b8 mk_le_mk_of_subset Iio_subset_Iic_self)\n\n/-- The cardinality of the interval (a, b). -/\nlemma mk_Ioo_real {a b : \u211d} (h : a < b) : #(Ioo a b) = \ud835\udd20 :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  have h1 : #((\u03bb x, x - a) '' Ioo a b) \u2264 #(Ioo a b) := mk_image_le,\n  refine le_trans _ h1,\n  rw [image_sub_const_Ioo, sub_self],\n  replace h := sub_pos_of_lt h,\n  have h2 : #(has_inv.inv '' Ioo 0 (b - a)) \u2264 #(Ioo 0 (b - a)) := mk_image_le,\n  refine le_trans _ h2,\n  rw [image_inv, inv_Ioo_0_left h, mk_Ioi_real]\nend\n\n/-- The cardinality of the interval [a, b). -/\n\n\n/-- The cardinality of the interval [a, b]. -/\nlemma mk_Icc_real {a b : \u211d} (h : a < b) : #(Icc a b) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Icc_self)\n\n/-- The cardinality of the interval (a, b]. -/\nlemma mk_Ioc_real {a b : \u211d} (h : a < b) : #(Ioc a b) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Ioc_self)\n\nend cardinal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/real/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7438992481130554}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 2 : `true` and `false`\n\nWe learn about the `true` and `false` propositions.\n\n## Tactics you will need\n\nTo solve the levels on this sheet you will need to know all previous\ntactics, plus the following two new ones. Check out their explanations\nin the course book. Or just try them out and hover over them to see\nif you can understand what's going on.\n\n* `triv`\n* `exfalso`\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : true :=\nbegin\n  triv,\nend\n\nexample : true :=\nbegin\n  exact true.intro,\nend\n\nexample : true \u2192 true :=\nbegin\n  intro _,\n  triv,\nend\n\nexample : false \u2192 true :=\nbegin\n  intro _,\n  triv,\nend\n\nexample : false \u2192 false :=\nbegin\n  intro f,\n  exact f,\nend\n\nexample : false \u2192 P :=\nbegin\n  intro f,\n  cases f, -- there are no cases to examine, so trivially true\nend\n\nexample : (true \u2192 false) \u2192 false :=\nbegin\n  intro hTF,\n  apply hTF,\n  triv,\nend\n\nexample : false \u2192 P :=\nbegin\n  intro h,\n  exfalso,\n  exact h,\nend\n\nexample : true \u2192 false \u2192 true \u2192 false \u2192 true \u2192 false :=\nbegin\n  intros _ hf,\n  exfalso,\n  exact hf,\nend\n\nexample : P \u2192 ((P \u2192 false) \u2192 false) :=\nbegin\n  intros hP hPF,\n  exact hPF hP,\nend\n\nexample : (P \u2192 false) \u2192 P \u2192 Q :=\nbegin\n  intros hPF hP,\n  exfalso,\n  exact hPF hP,\nend\n\nexample : (true \u2192 false) \u2192 P :=\nbegin\n  intro hTF,\n  exfalso,\n  apply hTF,\n  triv,\nend", "meta": {"author": "ineswright", "repo": "formalising-maths-2023", "sha": "d29dee07d9d55e96bcfd3d783d6f56943d61d8b6", "save_path": "github-repos/lean/ineswright-formalising-maths-2023", "path": "github-repos/lean/ineswright-formalising-maths-2023/formalising-maths-2023-d29dee07d9d55e96bcfd3d783d6f56943d61d8b6/src/section01logic/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7438992479962447}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.complex\nimport analysis.special_functions.trigonometric.deriv\n\n/-!\n# Complex trigonometric functions\n\nBasic facts and derivatives for the complex trigonometric functions.\n-/\n\nnoncomputable theory\n\nnamespace complex\n\nopen set filter\nopen_locale real\n\nlemma has_strict_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_strict_deriv_at tan (1 / (cos x)^2) x :=\nbegin\n  convert (has_strict_deriv_at_sin x).div (has_strict_deriv_at_cos x) h,\n  rw \u2190 sin_sq_add_cos_sq x,\n  ring,\nend\n\nlemma has_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_deriv_at tan (1 / (cos x)^2) x :=\n(has_strict_deriv_at_tan h).has_deriv_at\n\nopen_locale topological_space\n\nlemma tendsto_abs_tan_of_cos_eq_zero {x : \u2102} (hx : cos x = 0) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[\u2260] x) at_top :=\nbegin\n  simp only [tan_eq_sin_div_cos, \u2190 norm_eq_abs, norm_div],\n  have A : sin x \u2260 0 := \u03bb h, by simpa [*, sq] using sin_sq_add_cos_sq x,\n  have B : tendsto cos (\ud835\udcdd[\u2260] (x)) (\ud835\udcdd[\u2260] 0),\n    from hx \u25b8 (has_deriv_at_cos x).tendsto_punctured_nhds (neg_ne_zero.2 A),\n  exact continuous_sin.continuous_within_at.norm.mul_at_top (norm_pos_iff.2 A)\n    (tendsto_norm_nhds_within_zero.comp B).inv_tendsto_zero,\nend\n\nlemma tendsto_abs_tan_at_top (k : \u2124) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[\u2260] ((2 * k + 1) * \u03c0 / 2)) at_top :=\ntendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 \u27e8k, rfl\u27e9\n\n@[simp] lemma continuous_at_tan {x : \u2102} : continuous_at tan x \u2194 cos x \u2260 0 :=\nbegin\n  refine \u27e8\u03bb hc h\u2080, _, \u03bb h, (has_deriv_at_tan h).continuous_at\u27e9,\n  exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h\u2080) _\n    (hc.norm.tendsto.mono_left inf_le_left)\nend\n\n@[simp] lemma differentiable_at_tan {x : \u2102} : differentiable_at \u2102 tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at, \u03bb h, (has_deriv_at_tan h).differentiable_at\u27e9\n\n@[simp] lemma deriv_tan (x : \u2102) : deriv tan x = 1 / (cos x)^2 :=\nif h : cos x = 0 then\n  have \u00acdifferentiable_at \u2102 tan x := mt differentiable_at_tan.1 (not_not.2 h),\n  by simp [deriv_zero_of_not_differentiable_at this, h, sq]\nelse (has_deriv_at_tan h).deriv\n\n@[simp] lemma cont_diff_at_tan {x : \u2102} {n : with_top \u2115} :\n  cont_diff_at \u2102 n tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at,\n  cont_diff_sin.cont_diff_at.div cont_diff_cos.cont_diff_at\u27e9\n\nend complex\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/special_functions/trigonometric/complex_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7438992439448882}}
{"text": "-- Reglas de la intersecci\u00f3n general\n-- =================================\n\nimport data.set\nopen set\n\nsection\nvariables {I U : Type}\nvariables {A : I \u2192 set U}\nvariable  {x : U}\n\n-- Regla de introducci\u00f3n de la intersecci\u00f3n\n-- ========================================\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (h : \u2200 i, x \u2208 A i) \n  : x \u2208 \u22c2 i, A i :=\nbegin\n  simp,\n  assumption,\nend\n\n-- 2\u00aa demostraci\u00f3n\ntheorem Inter.intro  \n  (h : \u2200 i, x \u2208 A i) \n  : x \u2208 \u22c2 i, A i :=\nby simp; assumption\n\n-- Regla de eliminaci\u00f3n de la intersecci\u00f3n\n-- =======================================\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (h : x \u2208 \u22c2 i, A i) \n  (i : I) \n  : x \u2208 A i :=\nbegin\n  simp at h,\n  apply h,\nend\n\n-- 2\u00aa demostraci\u00f3n\n@[elab_simple]\ntheorem Inter.elim \n  (h : x \u2208 \u22c2 i, A i) \n  (i : I) \n  : x \u2208 A i :=\nby simp at h; apply h\n\nend\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Reglas_de_la_interseccion_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7438992437696716}}
{"text": "/-\nCopyright \u00a9 2018 Fran\u00e7ois G. Dorais. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n-/\n\nimport .basic\n\nnamespace fin\n\nlemma forall_iff_zero_and_succ {n} (p : fin (n+1) \u2192 Prop) :\np 0 \u2227 (\u2200 i, p (fin.succ i)) \u2194 (\u2200 i, p i) :=\niff.intro \n  (\u03bb \u27e8ho,hs\u27e9 i, \n  match i with\n  | \u27e80,_\u27e9 := ho\n  | \u27e8i+1,hi\u27e9 := hs \u27e8i, nat.lt_of_succ_lt_succ hi\u27e9 \n  end)\n  (\u03bb h, \u27e8h 0, \u03bb i, h (fin.succ i)\u27e9)\n\nlemma forall_iff_lift_and_last {n} (p : fin (n+1) \u2192 Prop) :\n(\u2200 i, p (fin.lift i)) \u2227 p (fin.last n) \u2194 (\u2200 i, p i) :=\niff.intro \n  (\u03bb \u27e8hl,h\u27e9 i,\n  if hi : i = fin.last n then\n  eq.substr hi h\n  else\n  have fin.lift (fin.drop i hi) = i, from lift_drop _ _,\n  eq.subst this $ hl (fin.drop i hi))\n  (\u03bb h, \u27e8\u03bb i, h (fin.lift i), h (fin.last n)\u27e9)\n\nlemma exists_iff_zero_or_succ {n} (p : fin (n+1) \u2192 Prop) :\np 0 \u2228 (\u2203 i, p (fin.succ i)) \u2194 (\u2203 i, p i) :=\niff.intro\n  (\u03bb h, or.elim h (\u03bb ho, \u27e80, ho\u27e9) (\u03bb \u27e8i,hi\u27e9, \u27e8fin.succ i, hi\u27e9))\n  (\u03bb \u27e8i,hi\u27e9, \n  match i,hi with\n  | \u27e80,_\u27e9,ho := or.inl ho\n  | \u27e8i+1,hi\u27e9,hs := or.inr (exists.intro \u27e8i, nat.lt_of_succ_lt_succ hi\u27e9 hs)\n  end)\n\nlemma exists_iff_lift_or_last {n} (p : fin (n+1) \u2192 Prop) :\n(\u2203 i, p (fin.lift i)) \u2228 p (fin.last n) \u2194 (\u2203 i, p i) :=\niff.intro\n  (\u03bb h, or.elim h (\u03bb \u27e8i,h\u27e9, \u27e8fin.lift i, h\u27e9) (\u03bb h, \u27e8fin.last n, h\u27e9))\n  (\u03bb \u27e8i,h\u27e9,\n  if hi : i = fin.last n then\n  or.inr (eq.subst hi h)\n  else\n  or.inl\n    (have p (fin.lift (fin.drop i hi)), \n    from eq.substr (lift_drop i hi) h,\n    \u27e8fin.drop i hi, this\u27e9))\n\ninstance forall_decidable :\n\u03a0 {n : \u2115} (p : fin n \u2192 Prop) [decidable_pred p], decidable (\u2200 i, p i)\n| 0 p _ := decidable.is_true (\u03bb (i : fin 0), fin.elim0 i)\n| (n+1) p dp := \n  have d0: decidable (p (fin.zero n)), from dp (fin.zero n),\n  have ds: decidable (\u2200 i, p (fin.succ i)),\n  from @forall_decidable n (\u03bb i, p (fin.succ i)) (\u03bb i, dp (fin.succ i)),\n  decidable_of_decidable_of_iff (@and.decidable _ _ d0 ds) (forall_iff_zero_and_succ p)\n\ninstance exists_decidable :\n\u03a0 {n : \u2115} (p : fin n \u2192 Prop) [decidable_pred p], decidable (\u2203 i, p i)\n| 0 p _ := decidable.is_false (\u03bb \u27e8i,_\u27e9, fin.elim0 i)\n| (n+1) p dp := \n  have d0: decidable (p (fin.zero n)), from dp (fin.zero n),\n  have ds: decidable (\u2203 i, p (fin.succ i)),\n  from @exists_decidable n (\u03bb i, p (fin.succ i)) (\u03bb i, dp (fin.succ i)),\n  decidable_of_decidable_of_iff (@or.decidable _ _ d0 ds) (exists_iff_zero_or_succ p)\n\nend fin", "meta": {"author": "fgdorais", "repo": "tup", "sha": "ac4a2f8ca2ccc8aea091498439a0a47d43ac4700", "save_path": "github-repos/lean/fgdorais-tup", "path": "github-repos/lean/fgdorais-tup/tup-ac4a2f8ca2ccc8aea091498439a0a47d43ac4700/src/fin/decidable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7438992357253634}}
{"text": "import algebra.group\nimport chris_hughes_various.zmod\nimport group_theory.order_of_element\n\nopen zmod nat\n\n-- I spell this one out so you can see how it goes.\nlemma gcd_one_of_unit {n : \u2115} [pos_nat n] (u : units (zmod n)) :\nnat.gcd (u.val.val) n = 1 :=\nbegin\n  let abar := u.val, let bbar := u.inv, --  in zmod n\n  let a := abar.val, let b := bbar.val, -- in \u2115\n  have H : (a * b) % n = 1 % n,\n    show (abar.val * bbar.val) % n = 1 % n,\n    rw \u2190mul_val,\n    rw u.val_inv,\n    refl,\n  let d := nat.gcd a n,\n  show d = 1,\n  rw \u2190nat.dvd_one,\n  rw \u2190dvd_mod_iff (gcd_dvd_right a n),\n  rw \u2190H,\n  rw dvd_mod_iff (gcd_dvd_right a n),\n  apply dvd_mul_of_dvd_left,\n  exact gcd_dvd_left a n\nend\n\n-- this one comes for free now, and it's the one we want\nlemma gcd_one_of_has_inv {n : \u2115} [pos_nat n] (a : zmod n) (Hinv : \u2203 b, a * b = 1) :\nnat.gcd (a.val) n = 1 :=\nbegin\n  cases Hinv with b Hb,\n  let u : units (zmod n) := \u27e8a,b,Hb,mul_comm a b \u25b8 Hb\u27e9,\n  exact gcd_one_of_unit u\nend \n\n-- thanks Chris :-)\n@[simp] lemma cast_val {n : \u2115} [pos_nat n] (a : zmod n) : (a.val : zmod n) = a :=\nby cases a; simp [mk_eq_cast]\n\ndef coprime_zmodn_units (n : \u2115) [pos_nat n] : \nequiv (units (zmod n)) {a : zmod n // \u2203 b, a * b = 1} :=\n{ to_fun := \u03bb u, \u27e8u.1, u.2, u.3\u27e9,\n  inv_fun := \u03bb A, \n  { val := (A.val).val, inv := ((A.val).val\u207b\u00b9),\n    val_inv := by rw [mul_inv_eq_gcd,gcd_one_of_has_inv A.val A.property];dsimp;rw zero_add,\n    inv_val := by rw [mul_comm,mul_inv_eq_gcd,gcd_one_of_has_inv A.val A.property];dsimp;rw zero_add,\n  },\n  left_inv := \u03bb u,begin apply units.ext,show (\u2191((u.val).val) : zmod n) = u.val,simp,end,\n  right_inv := \u03bb A, by simp,\n}\n\ninstance (n : nat) : pos_nat (nat.succ n) := \u27e8nat.succ_pos _\u27e9 \ninstance (n : \u2115) [pos_nat n] : fintype (units (zmod n)) := fintype.of_equiv _ (equiv.symm (coprime_zmodn_units n))\ninstance decidable_eq_units_zmod (n : \u2115) [pos_nat n] [monoid (zmod n)] : decidable_eq (units (zmod n)) :=  \u03bb x y, decidable_of_iff _ \u27e8 units.ext, \u03bb _,by simp *\u27e9\n \n#eval @order_of (units (zmod 7)) _ _ _ \u27e8(2 : zmod 7), 2\u207b\u00b9, rfl, rfl\u27e9\n#eval @order_of (units (zmod 5)) _ _ _ \u27e8(2 : zmod 5), 2\u207b\u00b9, rfl, rfl\u27e9\n#eval @order_of (units (zmod 7)) _ _ _ \u27e8(1 : zmod 7), 1\u207b\u00b9, rfl, rfl\u27e9", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M3P14/order_zmodn_kmb.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7438476046352464}}
{"text": "\n\ninductive xnat\n| zero : xnat\n| succ : xnat \u2192 xnat\nopen xnat\n#print xnat.succ.inj\n#print xnat.no_confusion\ndefinition one := succ zero\ndefinition two := succ one\ndefinition add :xnat \u2192 xnat \u2192 xnat\n| n zero := n\n| n (succ p) := succ (add n p)\nnotation a + b := add a b\ntheorem one_add_one_equals_two : one + one = two :=\n    begin\n        unfold two,\n        unfold one,\n        unfold add,\n    end\ntheorem add_zerox (n:xnat): n+zero=n:=\n    begin\n        unfold add,\n    end\ntheorem zero_addx (n:xnat):zero+n=n:=\n    begin\n        induction n with k H,\n        unfold add,\n        unfold add,\n        rw[H],\n    end\ntheorem add_assocx (a b c:xnat):(a+b)+c=a+(b+c):=\n    begin\n        induction c with k H,\n        unfold add,\n        unfold add,\n        rw[H],\n    end\ntheorem zero_add_eq_add_zerox (n:xnat) : zero+n=n+zero:=\n    begin \n        rw[zero_addx,add_zerox],\n    end\ntheorem add_one_eq_succx (n:xnat) : n + one = succ n:=\n    begin\n        unfold one add,\n    end\ntheorem one_add_eq_succx (n : xnat) : one+n=succ n:=\n    begin\n        induction n with k H,\n        unfold one add,\n        unfold one add,\n        rw[\u2190H],\n        unfold one,\n    end\ntheorem succ_addx (a b:xnat) : succ (a + b) = succ a + b:=begin\n    induction b with b hi,\n    trivial,\n    unfold add,rw hi,\nend\ntheorem add_commx (a b:xnat) : a+b = b+a:=\n    begin\n        induction b with k H,\n        rw[zero_add_eq_add_zerox],\n        unfold add,\n        rw [H,succ_addx],\n    end\ntheorem eq_iff_succ_eq_succ (a b : xnat) : succ a = succ b \u2194 a = b :=\n    begin\n        split,\n        exact succ.inj,\n        assume H : a = b,\n        rw [H],\n    end\ntheorem add_cancel_right (a b t : xnat) :  a = b \u2194 a+t = b+t :=\n    begin\n        split,\n        assume H,\n        rw[H],\n        induction t with k H,\n        rw[add_zerox,add_zerox],\n        assume H1,\n        exact H1,\n        unfold add,\n        rw[eq_iff_succ_eq_succ],\n        exact H,\n    end\ndefinition mul:xnat\u2192xnat\u2192xnat\n| n zero:=zero\n| n (succ p):= mul n p + n\nnotation a * b := mul a b\ntheorem mul_zerox (a : xnat) : a * zero = zero :=\n    begin\n        trivial,\n    end\ntheorem zero_mulx (a : xnat) : zero * a = zero :=\n    begin\n        induction a with k H,\n        unfold mul,\n        unfold mul add,\n        rw[H],\n    end\ntheorem mul_onex (a : xnat) : a * one = a :=\n    begin\n        unfold one mul,\n        rw[zero_addx],\n    end\ntheorem one_mulx (a : xnat) : one * a = a :=\n    begin\n        induction a with k H,\n        unfold mul,\n        unfold mul,\n        rw[add_one_eq_succx, H],\n    end\ntheorem right_distribx (a b c : xnat) : a * (b + c) = a* b + a * c :=\n    begin\n        induction c with k H,\n        rw[mul_zerox,add_zerox,add_zerox],\n        unfold add mul,\n        rw[H, add_assocx],\n    end\ntheorem left_distribx (a b c : xnat) : (a + b) * c = a * c + b * c :=\n    begin\n        induction c with n Hn,\n        unfold mul,\n        refl,\n        rw [\u2190add_one_eq_succx,right_distribx,Hn,right_distribx,right_distribx],\n        rw [mul_onex,mul_onex,mul_onex],\n        rw [add_assocx,\u2190add_assocx (b*n),add_commx (b*n),\u2190add_assocx,\u2190add_assocx,\u2190add_assocx],\n    end\ntheorem mul_assocx (a b c : xnat) : (a * b) * c = a * (b * c) :=\n    begin\n        induction c with k H,\n        rw[mul_zerox,mul_zerox,mul_zerox],\n        unfold mul,\n        rw[right_distribx,H]\n    end\ntheorem mul_commx (a b : xnat) : a * b = b * a :=\n    begin\n        induction b with k H,\n        rw[mul_zerox,zero_mulx],\n        unfold mul,\n        rw[H],\n        exact calc k * a + a = k * a + one * a: by rw[one_mulx]\n        ...=(k + one) * a: by rw[left_distribx]\n        ...=succ k * a: by rw[add_one_eq_succx],\n    end\ndefinition lt : xnat \u2192 xnat \u2192 Prop \n    | zero zero := false\n    | (succ m) zero := false\n    | zero (succ p) := true \n    | (succ m) (succ p) := lt m p\n\nnotation b > a := lt a b \nnotation a < b := lt a b\n\ntheorem inequality_A1 (a b t : xnat) : a < b \u2192 a + t < b + t :=\n    begin\n        induction t with n H,\n        rw[add_zerox,add_zerox],\n        assume H1,\n        exact H1,\n        unfold add lt, exact H,\n    end\ntheorem blah: \u2200a b c:xnat,a<b\u2192b<c\u2192a<c:=begin\n    assume a,\n    induction a with a1 Hia,\n        assume b c,\n        cases b with b1,\n            unfold lt,cc,\n            \n            \n            cases c with c1,\n                unfold lt,cc,\n\n                unfold lt,cc,\n        assume b c,\n        cases b with b1,\n            unfold lt,cc,\n\n            cases c with c1,\n                unfold lt,cc,\n\n                unfold lt,\n                exact Hia b1 c1,\nend\ntheorem blah1: \u2200a b c:xnat,a<b\u2192b<c\u2192a<c:=begin\n    assume a b, revert a,\n    induction b with b1 Hib,\n        assume a,\n        cases a with a1,\n            unfold lt,cc,\n\n            unfold lt,cc,\n        assume a c,\n        cases c with c1,\n            unfold lt,cc,\n\n        cases a with a1,\n            unfold lt,cc,\n\n            unfold lt,exact Hib a1 c1,\nend\ntheorem blah2: \u2200a b c:xnat,a<b\u2192b<c\u2192a<c:=begin\n    assume a b c,revert a b,\n    induction c with c1 Hic,\n        assume a b,\n        cases b with b1,\n            unfold lt,cc,\n\n            unfold lt,cc,\n        \n        assume a b,\n        cases a with a1,\n            unfold lt,cc,\n\n            cases b with b1,\n                unfold lt,trivial,\n\n                unfold lt,exact Hic a1 b1,\nend\n#check list.\n#print blah2\ntheorem subtraction :\u2200 a b:xnat,a<b\u2192\u2203c,c+a=b:=begin\n    assume a,\n    induction a with a1 Hia,\n        assume b H1,\n        existsi b, unfold add,\n        \n        assume b1,\n        cases b1 with b2,\n            unfold lt,trivial,\n\n            unfold lt,\n            assume H2,\n            apply exists.elim (Hia b2 H2),\n            assume c H3,\n            existsi c,rw \u2190H3,unfold add,\n\nend\ntheorem a_lt_a_add_succ_b (a b:xnat):a<a+succ b:=begin\n    induction a with a1 Ha,\n    rw zero_addx,unfold lt,\n    unfold add lt,rwa[\u2190add_one_eq_succx,add_assocx,one_add_eq_succx],\nend\ntheorem blah3 (x y:xnat):zero<x\u2192one<y\u2192x<x*y:=begin\n    cases x with x1,\n        unfold lt,cc,\n\n        cases y with y1,\n            unfold one lt,cc,\n\n            cases y1 with y2,\n                unfold one lt,cc,\n\n                unfold one lt mul,\n                rw[add_commx,\u2190one_add_eq_succx,add_assocx,one_add_eq_succx,one_add_eq_succx],\n                unfold lt,\n                have H1:x1 + (succ x1 * y2 + succ x1)=x1+succ (succ x1 * y2 + x1):=calc\n                    x1 + (succ x1 * y2 + succ x1) = x1 + (succ x1 * y2 + (x1+one)):begin rw \u2190add_one_eq_succx end\n                    ...=x1 + (succ x1 * y2 + x1+one):begin rw add_assocx, end\n                    ...=x1 +succ (succ x1 * y2 + x1):begin rw add_one_eq_succx, end,\n                rw H1,\n                assume H2 H3,\n                exact a_lt_a_add_succ_b x1 (succ x1 * y2 + x1),       \nend\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/addition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.743847604100997}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport tactic\nimport data.nat.parity\nimport data.real.basic\nimport data.finset.basic\nimport data.real.basic\n\n\n/-! \n# Nuevas t\u00e1cticas\n* `refine`\n* `obtain`\n* `swap`\n* `library_search`\n* `simp`\n* `group`\n-/\n\n/- ## refine \nFunciona como exact, pero permitiendo utilizar barras bajas _ en la expresi\u00f3n; cada una de ellas\nser\u00e1 reemplazada por la submeta correspondiente. \n\nPor ejemplo, dada una meta de forma `P \u2227 Q`, `refine \u27e8_, _\u27e9`, es equivalente a `split`. Pero \n`refine` es m\u00e1s flexible: si por ejemplo ya tenemos una demostraci\u00f3n `hP : P`, podemos usar\n`refine \u27e8hP, _\u27e9` y la meta pasar\u00e1 a ser `\u22a2 Q`.\n-/\n\nexample {n : \u2115} : even n \u2194 even (n^2) :=\nbegin\n  refine \u27e8\u03bb hn, even.pow_of_ne_zero hn (two_ne_zero), \u03bb hn, _\u27e9,\n  rw [pow_two, nat.even_mul, or_self] at hn,\n  exact hn,\nend\n/- ## obtain\nLa t\u00e1ctica `obtain` combina `have` y `cases`.\nLa instrucci\u00f3n `obtain \u27e8pattern\u27e9 : type := proof` es equivalente a\n```\nhave h : type,\n{ ... },\nrcases h with \u27e8patt\u27e9\n```\nEn muchos casos no es necesario incluir el tipo expl\u00edcitamente\n-/\n\nexample {n : \u2115} (hn : even n) : odd (n + 1) :=\nbegin\n  obtain \u27e8k, hk\u27e9 := hn,\n  refine \u27e8k, _\u27e9,\n  rw [hk, two_mul],\nend\n\nexample {X Y Z : Type*} {f : X \u2192 Y} {g : Y \u2192 Z} (hf : function.surjective f) \n  (hg : function.surjective g) : function.surjective (g \u2218 f) :=\nbegin\n  intros z,\n  have hgz : \u2203 (a : Y), g a = z,\n  { exact hg z},\n  cases hgz with y hy,\n  obtain \u27e8x, hx\u27e9 := hf y,\n  use x,\n  rw [function.comp_app, hx, hy],\nend\n\n/- ## swap \nLa t\u00e1ctica `swap` intercambia las dos primeras metas.\n\nTambi\u00e9n se puede utilizar como `swap n`, que convierte la en\u00e9sima meta en la primera.\n-/\n\nexample {\u03a9 : Type*} {X Y : set \u03a9} (hXY : X \u2286 Y) (hYX : Y \u2286 X) : X = Y :=\nbegin\n  ext a,\n  split,\n  swap,\n  { apply hYX },\n  { apply hXY },\nend\n\n/- ## library_search \n`library_search` intenta cerrar la meta actual aplicando un lema existente en la librer\u00eda mathlib.\nSi lo encuentra, imprime un mensaje `exact ...` con la soluci\u00f3n empleada.\n\n-/\n\n--example {n m : \u2115} : n + m = m + n := by library_search\n\n--example {n m : \u2115} (hn : even n) (hm : odd m) : odd (m + n) := by library_search\n\n/- ## simp\nMuchos lemas de mathlib que demuestran igualdades o equivalencias l\u00f3gicas est\u00e1n marcados con la \netiqueta `@[simp]`. Tambi\u00e9n podemos utilizar esta etiqueta en lemas que demostremos.\n\nLa t\u00e1ctica `simp` intenta encontrar lemas cuyo lado izquierdo aparece en la meta, y sustituirlos por\nel lado derecho (por tanto, si creamos un lema marcado `@[simp]`, el lado derecho debe ser la \nexpresi\u00f3n m\u00e1s sencilla).\n\nTambi\u00e9n podemos usar `simp [lema1, lema2, ...]` para que, adem\u00e1s de los lemas etiquetados, el \nsimplificador tambi\u00e9n intente utilizar los lemas proporcionados.\n\nPodemos utilizar `simp` en hip\u00f3tesis locales, con la sintaxis `simp at h`.\n\nNo es buena pr\u00e1ctica utilizar `simp` en el medio de una demostraci\u00f3n; es mejor sustituirlo por\nuna aplicaci\u00f3n de `simp only [...]`, como veremos abajo.\n-/\n\nexample : (0 : \u211d) + 1 = 1 + 0 := by simp\n\nopen_locale big_operators\nopen finset\n\nexample (n : \u2115) : \u2211 i in range n, (i : \u211d) = n * (n - 1) / 2 :=\nbegin\n  induction n with d hd,\n  { -- la suma sobre el conjunto vac\u00edo es 0 * (0 - 1) / 2\n    simp },\n  { -- inducci\u00f3n\n    rw [sum_range_succ, hd],\n    simp, -- reduce la meta a \u22a2 \u2191d * (\u2191d - 1) / 2 + \u2191d = (\u2191d + 1) * \u2191d / 2\n    ring, \n  }\nend\n\n/- ### simp only\nSi utilizamos `simp only [h\u2081 h\u2082 ... h\u2099]` en lugar de `simp [h\u2081 h\u2082 ... h\u2099]`, el simplificador s\u00f3lo\nutilizar\u00e1 los lemas h\u1d62, pero no los lemas marcados con `@[simp]`.\n-/\n\nexample (n : \u2115) : \u2211 i in range n, (i : \u211d) = n * (n - 1) / 2 :=\nbegin\n  induction n with d hd,\n  { -- la suma sobre el conjunto vac\u00edo es 0 * (0 - 1) / 2\n    simp only [range_zero, sum_empty, nat.cast_zero, zero_mul, zero_div], },\n  { -- inducci\u00f3n\n    rw [sum_range_succ, hd],\n    simp only [nat.cast_succ, add_tsub_cancel_right], \n    -- reduce la meta a \u22a2 \u2191d * (\u2191d - 1) / 2 + \u2191d = (\u2191d + 1) * \u2191d / 2\n    ring, \n  }\nend\n\n/- ### squeeze_simp \n`squeeze_simp` funciona como `simp`, y adem\u00e1s imprime un mensaje `simp only [...]` con la lista\nde lemas que han sido utilizados.\n-/\n\n--example : (0 : \u211d) + 1 = 1 + 0 := by squeeze_simp\n\n/- ## group\nEsta t\u00e1ctica se utiliza para simplificar expresiones en grupos multiplicativos, utilizando s\u00f3lo\nlos axiomas de grupo, sin asumir conmutatividad.\n\nNo utiliza las hip\u00f3tesis locales, por lo que es probable que haya que combinarla con otras t\u00e1cticas\ncomo rw.\n-/\n\n-- Ejemplo tomado de la documentaci\u00f3n de mathlib\nexample {G : Type} [group G] (a b c d : G) (h : c = (a*b^2)*((b*b)\u207b\u00b9*a\u207b\u00b9)*d) : a*c*d\u207b\u00b9 = a :=\nbegin\n  group at h, -- normaliza `h`, obteniendo `h : c = d`\n  rw h,       -- la meta es ahora `a*d*d\u207b\u00b9 = a`\n  group,      -- group cierra la meta\nend\n", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_3/tacticas_3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7438448632087783}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.list.big_operators.basic\nimport data.multiset.basic\n\n/-!\n# Sums and products over multisets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `multiset.prod`: `s.prod f` is the product of `f i` over all `i \u2208 s`. Not to be mistaken with\n  the cartesian product `multiset.product`.\n* `multiset.sum`: `s.sum f` is the sum of `f i` over all `i \u2208 s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`.  This split does not need to be permanent.\n-/\n\nvariables {\u03b9 \u03b1 \u03b2 \u03b3 : Type*}\n\nnamespace multiset\nsection comm_monoid\nvariables [comm_monoid \u03b1] {s t : multiset \u03b1} {a : \u03b1} {m : multiset \u03b9} {f g : \u03b9 \u2192 \u03b1}\n\n/-- Product of a multiset given a commutative monoid structure on `\u03b1`.\n  `prod {a, b, c} = a * b * c` -/\n@[to_additive \"Sum of a multiset given a commutative additive monoid structure on `\u03b1`.\n  `sum {a, b, c} = a + b + c`\"]\ndef prod : multiset \u03b1 \u2192 \u03b1 := foldr (*) (\u03bb x y z, by simp [mul_left_comm]) 1\n\n@[to_additive]\nlemma prod_eq_foldr (s : multiset \u03b1) : prod s = foldr (*) (\u03bb x y z, by simp [mul_left_comm]) 1 s :=\nrfl\n\n@[to_additive]\nlemma prod_eq_foldl (s : multiset \u03b1) : prod s = foldl (*) (\u03bb x y z, by simp [mul_right_comm]) 1 s :=\n(foldr_swap _ _ _ _).trans (by simp [mul_comm])\n\n@[simp, norm_cast, to_additive] lemma coe_prod (l : list \u03b1) : prod \u2191l = l.prod := prod_eq_foldl _\n\n@[simp, to_additive]\nlemma prod_to_list (s : multiset \u03b1) : s.to_list.prod = s.prod :=\nbegin\n  conv_rhs { rw \u2190coe_to_list s },\n  rw coe_prod,\nend\n\n@[simp, to_additive] lemma prod_zero : @prod \u03b1 _ 0 = 1 := rfl\n\n@[simp, to_additive]\nlemma prod_cons (a : \u03b1) (s) : prod (a ::\u2098 s) = a * prod s := foldr_cons _ _ _ _ _\n\n@[simp, to_additive]\nlemma prod_erase [decidable_eq \u03b1] (h : a \u2208 s) : a * (s.erase a).prod = s.prod :=\nby rw [\u2190 s.coe_to_list, coe_erase, coe_prod, coe_prod, list.prod_erase (mem_to_list.2 h)]\n\n@[simp, to_additive]\nlemma prod_map_erase [decidable_eq \u03b9] {a : \u03b9} (h : a \u2208 m) :\n  f a * ((m.erase a).map f).prod = (m.map f).prod :=\nby rw [\u2190 m.coe_to_list, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n  list.prod_map_erase f (mem_to_list.2 h)]\n\n@[simp, to_additive]\nlemma prod_singleton (a : \u03b1) : prod {a} = a :=\nby simp only [mul_one, prod_cons, \u2190cons_zero, eq_self_iff_true, prod_zero]\n\n@[to_additive]\nlemma prod_pair (a b : \u03b1) : ({a, b} : multiset \u03b1).prod = a * b :=\nby rw [insert_eq_cons, prod_cons, prod_singleton]\n\n@[simp, to_additive]\nlemma prod_add (s t : multiset \u03b1) : prod (s + t) = prod s * prod t :=\nquotient.induction_on\u2082 s t $ \u03bb l\u2081 l\u2082, by simp\n\nlemma prod_nsmul (m : multiset \u03b1) : \u2200 (n : \u2115), (n \u2022 m).prod = m.prod ^ n\n| 0       := by { rw [zero_nsmul, pow_zero], refl }\n| (n + 1) :=\n  by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul n]\n\n@[simp, to_additive] lemma prod_replicate (n : \u2115) (a : \u03b1) : (replicate n a).prod = a ^ n :=\nby simp [replicate, list.prod_replicate]\n\n@[to_additive]\nlemma prod_map_eq_pow_single [decidable_eq \u03b9] (i : \u03b9) (hf : \u2200 i' \u2260 i, i' \u2208 m \u2192 f i' = 1) :\n  (m.map f).prod = f i ^ m.count i :=\nbegin\n  induction m using quotient.induction_on with l,\n  simp [list.prod_map_eq_pow_single i f hf],\nend\n\n@[to_additive]\nlemma prod_eq_pow_single [decidable_eq \u03b1] (a : \u03b1) (h : \u2200 a' \u2260 a, a' \u2208 s \u2192 a' = 1) :\n  s.prod = a ^ (s.count a) :=\nbegin\n  induction s using quotient.induction_on with l,\n  simp [list.prod_eq_pow_single a h],\nend\n\n@[to_additive]\nlemma pow_count [decidable_eq \u03b1] (a : \u03b1) : a ^ s.count a = (s.filter (eq a)).prod :=\nby rw [filter_eq, prod_replicate]\n\n@[to_additive]\nlemma prod_hom [comm_monoid \u03b2] (s : multiset \u03b1) {F : Type*} [monoid_hom_class F \u03b1 \u03b2] (f : F) :\n  (s.map f).prod = f s.prod :=\nquotient.induction_on s $ \u03bb l, by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n\n@[to_additive]\nlemma prod_hom' [comm_monoid \u03b2] (s : multiset \u03b9) {F : Type*} [monoid_hom_class F \u03b1 \u03b2] (f : F)\n  (g : \u03b9 \u2192 \u03b1) : (s.map $ \u03bb i, f $ g i).prod = f (s.map g).prod :=\nby { convert (s.map g).prod_hom f, exact (map_map _ _ _).symm }\n\n@[to_additive]\nlemma prod_hom\u2082 [comm_monoid \u03b2] [comm_monoid \u03b3] (s : multiset \u03b9) (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3)\n  (hf : \u2200 a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f\u2081 : \u03b9 \u2192 \u03b1) (f\u2082 : \u03b9 \u2192 \u03b2) :\n  (s.map $ \u03bb i, f (f\u2081 i) (f\u2082 i)).prod = f (s.map f\u2081).prod (s.map f\u2082).prod :=\nquotient.induction_on s $ \u03bb l,\n  by simp only [l.prod_hom\u2082 f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n\n@[to_additive]\nlemma prod_hom_rel [comm_monoid \u03b2] (s : multiset \u03b9) {r : \u03b1 \u2192 \u03b2 \u2192 Prop} {f : \u03b9 \u2192 \u03b1} {g : \u03b9 \u2192 \u03b2}\n  (h\u2081 : r 1 1) (h\u2082 : \u2200 \u2983a b c\u2984, r b c \u2192 r (f a * b) (g a * c)) :\n  r (s.map f).prod (s.map g).prod :=\nquotient.induction_on s $ \u03bb l,\n  by simp only [l.prod_hom_rel h\u2081 h\u2082, quot_mk_to_coe, coe_map, coe_prod]\n\n@[to_additive]\nlemma prod_map_one : prod (m.map (\u03bb i, (1 : \u03b1))) = 1 := by rw [map_const, prod_replicate, one_pow]\n\n@[simp, to_additive]\nlemma prod_map_mul : (m.map $ \u03bb i, f i * g i).prod = (m.map f).prod * (m.map g).prod :=\nm.prod_hom\u2082 (*) mul_mul_mul_comm (mul_one _) _ _\n\n@[simp]\nlemma prod_map_neg [has_distrib_neg \u03b1] (s : multiset \u03b1) :\n  (s.map has_neg.neg).prod = (-1) ^ s.card * s.prod :=\nby { refine quotient.ind _ s, simp }\n\n@[to_additive]\nlemma prod_map_pow {n : \u2115} : (m.map $ \u03bb i, f i ^ n).prod = (m.map f).prod ^ n :=\nm.prod_hom' (pow_monoid_hom n : \u03b1 \u2192* \u03b1) f\n\n@[to_additive]\nlemma prod_map_prod_map (m : multiset \u03b2) (n : multiset \u03b3) {f : \u03b2 \u2192 \u03b3 \u2192 \u03b1} :\n  prod (m.map $ \u03bb a, prod $ n.map $ \u03bb b, f a b) = prod (n.map $ \u03bb b, prod $ m.map $ \u03bb a, f a b) :=\nmultiset.induction_on m (by simp) (\u03bb a m ih, by simp [ih])\n\n@[to_additive]\nlemma prod_induction (p : \u03b1 \u2192 Prop) (s : multiset \u03b1) (p_mul : \u2200 a b, p a \u2192 p b \u2192 p (a * b))\n  (p_one : p 1) (p_s : \u2200 a \u2208 s, p a) :\n  p s.prod :=\nbegin\n  rw prod_eq_foldr,\n  exact foldr_induction (*) (\u03bb x y z, by simp [mul_left_comm]) 1 p s p_mul p_one p_s,\nend\n\n@[to_additive]\nlemma prod_induction_nonempty (p : \u03b1 \u2192 Prop) (p_mul : \u2200 a b, p a \u2192 p b \u2192 p (a * b))\n  (hs : s \u2260 \u2205) (p_s : \u2200 a \u2208 s, p a) :\n  p s.prod :=\nbegin\n  revert s,\n  refine multiset.induction _ _,\n  { intro h,\n    exfalso,\n    simpa using h },\n  intros a s hs hsa hpsa,\n  rw prod_cons,\n  by_cases hs_empty : s = \u2205,\n  { simp [hs_empty, hpsa a] },\n  have hps : \u2200 x, x \u2208 s \u2192 p x, from \u03bb x hxs, hpsa x (mem_cons_of_mem hxs),\n  exact p_mul a s.prod (hpsa a (mem_cons_self a s)) (hs hs_empty hps),\nend\n\nlemma prod_dvd_prod_of_le (h : s \u2264 t) : s.prod \u2223 t.prod :=\nby { obtain \u27e8z, rfl\u27e9 := exists_add_of_le h, simp only [prod_add, dvd_mul_right] }\n\nend comm_monoid\n\nlemma prod_dvd_prod_of_dvd [comm_monoid \u03b2] {S : multiset \u03b1} (g1 g2 : \u03b1 \u2192 \u03b2)\n  (h : \u2200 a \u2208 S, g1 a \u2223 g2 a) :\n  (multiset.map g1 S).prod \u2223 (multiset.map g2 S).prod :=\nbegin\n  apply multiset.induction_on' S, { simp },\n  intros a T haS _ IH,\n  simp [mul_dvd_mul (h a haS) IH]\nend\n\n\nsection add_comm_monoid\nvariables [add_comm_monoid \u03b1]\n\n/-- `multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`add_comm_monoid`s. -/\ndef sum_add_monoid_hom : multiset \u03b1 \u2192+ \u03b1 :=\n{ to_fun := sum,\n  map_zero' := sum_zero,\n  map_add' := sum_add }\n\n@[simp] lemma coe_sum_add_monoid_hom : (sum_add_monoid_hom : multiset \u03b1 \u2192 \u03b1) = sum := rfl\n\nend add_comm_monoid\n\nsection comm_monoid_with_zero\nvariables [comm_monoid_with_zero \u03b1]\n\nlemma prod_eq_zero {s : multiset \u03b1} (h : (0 : \u03b1) \u2208 s) : s.prod = 0 :=\nbegin\n  rcases multiset.exists_cons_of_mem h with \u27e8s', hs'\u27e9,\n  simp [hs', multiset.prod_cons]\nend\n\nvariables [no_zero_divisors \u03b1] [nontrivial \u03b1] {s : multiset \u03b1}\n\nlemma prod_eq_zero_iff : s.prod = 0 \u2194 (0 : \u03b1) \u2208 s :=\nquotient.induction_on s $ \u03bb l, by { rw [quot_mk_to_coe, coe_prod], exact list.prod_eq_zero_iff }\n\nlemma prod_ne_zero (h : (0 : \u03b1) \u2209 s) : s.prod \u2260 0 := mt prod_eq_zero_iff.1 h\n\nend comm_monoid_with_zero\n\nsection division_comm_monoid\nvariables [division_comm_monoid \u03b1] {m : multiset \u03b9} {f g : \u03b9 \u2192 \u03b1}\n\n@[to_additive] lemma prod_map_inv' (m : multiset \u03b1) : (m.map has_inv.inv).prod = m.prod\u207b\u00b9 :=\nm.prod_hom (inv_monoid_hom : \u03b1 \u2192* \u03b1)\n\n@[simp, to_additive] lemma prod_map_inv : (m.map $ \u03bb i, (f i)\u207b\u00b9).prod = (m.map f).prod \u207b\u00b9 :=\nby { convert (m.map f).prod_map_inv', rw map_map }\n\n@[simp, to_additive]\nlemma prod_map_div : (m.map $ \u03bb i, f i / g i).prod = (m.map f).prod / (m.map g).prod :=\nm.prod_hom\u2082 (/) mul_div_mul_comm (div_one _) _ _\n\n@[to_additive]\nlemma prod_map_zpow {n : \u2124} : (m.map $ \u03bb i, f i ^ n).prod = (m.map f).prod ^ n :=\nby { convert (m.map f).prod_hom (zpow_group_hom _ : \u03b1 \u2192* \u03b1), rw map_map, refl }\n\nend division_comm_monoid\n\nsection non_unital_non_assoc_semiring\nvariables [non_unital_non_assoc_semiring \u03b1] {a : \u03b1} {s : multiset \u03b9} {f : \u03b9 \u2192 \u03b1}\n\nlemma sum_map_mul_left : sum (s.map (\u03bb i, a * f i)) = a * sum (s.map f) :=\nmultiset.induction_on s (by simp) (\u03bb i s ih, by simp [ih, mul_add])\n\nlemma sum_map_mul_right : sum (s.map (\u03bb i, f i * a)) = sum (s.map f) * a :=\nmultiset.induction_on s (by simp) (\u03bb a s ih, by simp [ih, add_mul])\n\nend non_unital_non_assoc_semiring\n\nsection semiring\nvariables [semiring \u03b1]\n\nlemma dvd_sum {a : \u03b1} {s : multiset \u03b1} : (\u2200 x \u2208 s, a \u2223 x) \u2192 a \u2223 s.sum :=\nmultiset.induction_on s (\u03bb _, dvd_zero _)\n  (\u03bb x s ih h, by { rw sum_cons, exact dvd_add\n    (h _ (mem_cons_self _ _)) (ih $ \u03bb y hy, h _ $ mem_cons.2 $ or.inr hy) })\n\nend semiring\n\n/-! ### Order -/\n\nsection ordered_comm_monoid\nvariables [ordered_comm_monoid \u03b1] {s t : multiset \u03b1} {a : \u03b1}\n\n@[to_additive sum_nonneg]\nlemma one_le_prod_of_one_le : (\u2200 x \u2208 s, (1 : \u03b1) \u2264 x) \u2192 1 \u2264 s.prod :=\nquotient.induction_on s $ \u03bb l hl, by simpa using list.one_le_prod_of_one_le hl\n\n@[to_additive]\nlemma single_le_prod : (\u2200 x \u2208 s, (1 : \u03b1) \u2264 x) \u2192 \u2200 x \u2208 s, x \u2264 s.prod :=\nquotient.induction_on s $ \u03bb l hl x hx, by simpa using list.single_le_prod hl x hx\n\n@[to_additive sum_le_card_nsmul]\nlemma prod_le_pow_card (s : multiset \u03b1) (n : \u03b1) (h : \u2200 x \u2208 s, x \u2264 n) : s.prod \u2264 n ^ s.card :=\nbegin\n  induction s using quotient.induction_on,\n  simpa using list.prod_le_pow_card _ _ h,\nend\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\nlemma all_one_of_le_one_le_of_prod_eq_one :\n  (\u2200 x \u2208 s, (1 : \u03b1) \u2264 x) \u2192 s.prod = 1 \u2192 \u2200 x \u2208 s, x = (1 : \u03b1) :=\nbegin\n  apply quotient.induction_on s,\n  simp only [quot_mk_to_coe, coe_prod, mem_coe],\n  exact \u03bb l, list.all_one_of_le_one_le_of_prod_eq_one,\nend\n\n@[to_additive]\nlemma prod_le_prod_of_rel_le (h : s.rel (\u2264) t) : s.prod \u2264 t.prod :=\nbegin\n  induction h with _ _ _ _ rh _ rt,\n  { refl },\n  { rw [prod_cons, prod_cons],\n    exact mul_le_mul' rh rt }\nend\n\n@[to_additive]\nlemma prod_map_le_prod_map {s : multiset \u03b9} (f : \u03b9 \u2192 \u03b1) (g : \u03b9 \u2192 \u03b1) (h : \u2200 i, i \u2208 s \u2192 f i \u2264 g i) :\n  (s.map f).prod \u2264 (s.map g).prod :=\nprod_le_prod_of_rel_le $ rel_map.2 $ rel_refl_of_refl_on h\n\n@[to_additive]\nlemma prod_map_le_prod (f : \u03b1 \u2192 \u03b1) (h : \u2200 x, x \u2208 s \u2192 f x \u2264 x) : (s.map f).prod \u2264 s.prod :=\nprod_le_prod_of_rel_le $ rel_map_left.2 $ rel_refl_of_refl_on h\n\n@[to_additive]\nlemma prod_le_prod_map (f : \u03b1 \u2192 \u03b1) (h : \u2200 x, x \u2208 s \u2192 x \u2264 f x) : s.prod \u2264 (s.map f).prod :=\n@prod_map_le_prod \u03b1\u1d52\u1d48 _ _ f h\n\n@[to_additive card_nsmul_le_sum]\nlemma pow_card_le_prod (h : \u2200 x \u2208 s, a \u2264 x) : a ^ s.card \u2264 s.prod :=\nby { rw [\u2190multiset.prod_replicate, \u2190multiset.map_const], exact prod_map_le_prod _ h }\n\nend ordered_comm_monoid\n\nlemma prod_nonneg [ordered_comm_semiring \u03b1] {m : multiset \u03b1} (h : \u2200 a \u2208 m, (0 : \u03b1) \u2264 a) :\n  0 \u2264 m.prod :=\nbegin\n  revert h,\n  refine m.induction_on _ _,\n  { rintro -, rw prod_zero, exact zero_le_one },\n  intros a s hs ih,\n  rw prod_cons,\n  exact mul_nonneg (ih _ $ mem_cons_self _ _) (hs $ \u03bb a ha, ih _ $ mem_cons_of_mem ha),\nend\n\n/-- Slightly more general version of `multiset.prod_eq_one_iff` for a non-ordered `monoid` -/\n@[to_additive \"Slightly more general version of `multiset.sum_eq_zero_iff`\n  for a non-ordered `add_monoid`\"]\nlemma prod_eq_one [comm_monoid \u03b1] {m : multiset \u03b1} (h : \u2200 x \u2208 m, x = (1 : \u03b1)) : m.prod = 1 :=\nbegin\n  induction m using quotient.induction_on with l,\n  simp [list.prod_eq_one h],\nend\n\n@[to_additive]\nlemma le_prod_of_mem [canonically_ordered_monoid \u03b1] {m : multiset \u03b1} {a : \u03b1} (h : a \u2208 m) :\n  a \u2264 m.prod :=\nbegin\n  obtain \u27e8m', rfl\u27e9 := exists_cons_of_mem h,\n  rw [prod_cons],\n  exact _root_.le_mul_right (le_refl a),\nend\n\n@[to_additive le_sum_of_subadditive_on_pred]\nlemma le_prod_of_submultiplicative_on_pred [comm_monoid \u03b1] [ordered_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (p : \u03b1 \u2192 Prop) (h_one : f 1 = 1) (hp_one : p 1)\n  (h_mul : \u2200 a b, p a \u2192 p b \u2192 f (a * b) \u2264 f a * f b)\n  (hp_mul : \u2200 a b, p a \u2192 p b \u2192 p (a * b)) (s : multiset \u03b1) (hps : \u2200 a, a \u2208 s \u2192 p a) :\n  f s.prod \u2264 (s.map f).prod :=\nbegin\n  revert s,\n  refine multiset.induction _ _,\n  { simp [le_of_eq h_one] },\n  intros a s hs hpsa,\n  have hps : \u2200 x, x \u2208 s \u2192 p x, from \u03bb x hx, hpsa x (mem_cons_of_mem hx),\n  have hp_prod : p s.prod, from prod_induction p s hp_mul hp_one hps,\n  rw [prod_cons, map_cons, prod_cons],\n  exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _),\nend\n\n@[to_additive le_sum_of_subadditive]\nlemma le_prod_of_submultiplicative [comm_monoid \u03b1] [ordered_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (h_one : f 1 = 1) (h_mul : \u2200 a b, f (a * b) \u2264 f a * f b) (s : multiset \u03b1) :\n  f s.prod \u2264 (s.map f).prod :=\nle_prod_of_submultiplicative_on_pred f (\u03bb i, true) h_one trivial (\u03bb x y _ _ , h_mul x y) (by simp)\n  s (by simp)\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\n\n\n@[to_additive le_sum_nonempty_of_subadditive]\nlemma le_prod_nonempty_of_submultiplicative [comm_monoid \u03b1] [ordered_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (h_mul : \u2200 a b, f (a * b) \u2264 f a * f b) (s : multiset \u03b1) (hs_nonempty : s \u2260 \u2205) :\n  f s.prod \u2264 (s.map f).prod :=\nle_prod_nonempty_of_submultiplicative_on_pred f (\u03bb i, true) (by simp [h_mul]) (by simp) s\n  hs_nonempty (by simp)\n\n@[simp] lemma sum_map_singleton (s : multiset \u03b1) : (s.map (\u03bb a, ({a} : multiset \u03b1))).sum = s :=\nmultiset.induction_on s (by simp) (by simp)\n\nlemma abs_sum_le_sum_abs [linear_ordered_add_comm_group \u03b1] {s : multiset \u03b1} :\n  abs s.sum \u2264 (s.map abs).sum :=\nle_sum_of_subadditive _ abs_zero abs_add s\n\nlemma sum_nat_mod (s : multiset \u2115) (n : \u2115) : s.sum % n = (s.map (% n)).sum % n :=\nby induction s using multiset.induction; simp [nat.add_mod, *]\n\nlemma prod_nat_mod (s : multiset \u2115) (n : \u2115) : s.prod % n = (s.map (% n)).prod % n :=\nby induction s using multiset.induction; simp [nat.mul_mod, *]\n\nlemma sum_int_mod (s : multiset \u2124) (n : \u2124) : s.sum % n = (s.map (% n)).sum % n :=\nby induction s using multiset.induction; simp [int.add_mod, *]\n\nlemma prod_int_mod (s : multiset \u2124) (n : \u2124) : s.prod % n = (s.map (% n)).prod % n :=\nby induction s using multiset.induction; simp [int.mul_mod, *]\n\nend multiset\n\n@[to_additive]\nlemma map_multiset_prod [comm_monoid \u03b1] [comm_monoid \u03b2] {F : Type*} [monoid_hom_class F \u03b1 \u03b2]\n  (f : F) (s : multiset \u03b1) : f s.prod = (s.map f).prod :=\n(s.prod_hom f).symm\n\n@[to_additive]\nprotected lemma monoid_hom.map_multiset_prod [comm_monoid \u03b1] [comm_monoid \u03b2] (f : \u03b1 \u2192* \u03b2)\n  (s : multiset \u03b1) : f s.prod = (s.map f).prod :=\n(s.prod_hom f).symm\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/big_operators/multiset/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7438448541441922}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n-- 1. Importar la teor\u00eda Definicion_de_funciones_acotadas\n-- 2. Declarar f y g como variables de funciones de \u211d en \u211d.\n-- 3. Declarar a y b como variables sobre \u211d.\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_funciones_acotadas -- 1\n\nvariables {f g : \u211d \u2192 \u211d}                  -- 2\nvariables {a b : \u211d}                      -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que si a es una cota inferior de f y b lo es\n-- de g, entonces a + b lo es de f + g.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nlemma fn_lb_add\n  (hfa : fn_lb f a)\n  (hgb : fn_lb g b)\n  : fn_lb (f + g) (a + b) :=\nbegin\n  intro x,\n  change a + b \u2264 f x + g x,\n  apply add_le_add,\n  apply hfa,\n  apply hgb\nend\n\n-- Su desarrollo es\n--\n-- f g : \u211d \u2192 \u211d,\n-- a b : \u211d,\n-- hfa : fn_lb f a,\n-- hgb : fn_lb g b\n-- \u22a2 fn_lb (\u03bb (x : \u211d), f x + g x) (a + b)\n--    >> intro x,\n-- x : \u211d\n-- \u22a2 a + b \u2264 (\u03bb (x : \u211d), f x + g x) x\n--    >> change a + b \u2264 f x + g x,\n-- \u22a2 a + b \u2264 f x + g x\n--    >> apply add_le_add,\n-- | \u22a2 a \u2264 f x\n-- |    >> apply hfa,\n-- | \u22a2 b \u2264 g x\n-- |    >> apply hgb\n-- no goals\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (hfa : fn_lb f a)\n  (hgb : fn_lb g b)\n  : fn_lb (f + g) (a + b) :=\n\u03bb x, add_le_add (hfa x) (hgb x)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que la suma de dos funciones acotadas\n-- inferiormente tambi\u00e9n lo est\u00e1.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (lbf : fn_has_lb f)\n  (lbg : fn_has_lb g)\n  : fn_has_lb (f + g) :=\nbegin\n  cases lbf with a ha,\n  cases lbg with b hb,\n  have h1 : fn_lb (f + g) (a + b) := fn_lb_add ha hb,\n  have h2 : \u2203 z, \u2200 x, z \u2264 (f + g) x :=\n    by exact Exists.intro (a + b) h1,\n  show fn_has_lb (f + g),\n    by exact h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (lbf : fn_has_lb f)\n  (lbg : fn_has_lb g)\n  : fn_has_lb (f + g) :=\nbegin\n  cases lbf with a lbfa,\n  cases lbg with b lbgb,\n  use a + b,\n  apply fn_lb_add lbfa lbgb,\nend\n\n-- Su desarrollo es\n--\n-- f g : \u211d \u2192 \u211d,\n-- lbf : fn_has_lb f,\n-- lbg : fn_has_lb g\n-- \u22a2 fn_has_lb (\u03bb (x : \u211d), f x + g x)\n--    >> cases lbf with a lbfa,\n-- f g : \u211d \u2192 \u211d,\n-- lbg : fn_has_lb g,\n-- a : \u211d,\n-- lbfa : fn_lb f a\n-- \u22a2 fn_has_lb (\u03bb (x : \u211d), f x + g x)\n--    >> cases lbg with b lbgb,\n-- f g : \u211d \u2192 \u211d,\n-- a : \u211d,\n-- lbfa : fn_lb f a,\n-- b : \u211d,\n-- lbgb : fn_lb g b\n-- \u22a2 fn_has_lb (\u03bb (x : \u211d), f x + g x)\n--    >> use a + b,\n-- \u22a2 fn_lb (\u03bb (x : \u211d), f x + g x) (a + b)\n--    >> apply fn_lb_add lbfa lbgb\n-- no goals\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (lbf : fn_has_lb f)\n  (lbg : fn_has_lb g)\n  : fn_has_lb (f + g) :=\nbegin\n  rcases lbf with \u27e8a, lbfa\u27e9,\n  rcases lbg with \u27e8b, lbfb\u27e9,\n  exact \u27e8a + b, fn_lb_add lbfa lbfb\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  fn_has_lb f \u2192 fn_has_lb g \u2192 fn_has_lb (f + g) :=\nbegin\n  rintros \u27e8a, lbfa\u27e9 \u27e8b, lbfb\u27e9,\n  exact \u27e8a + b, fn_lb_add lbfa lbfb\u27e9,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  fn_has_lb f \u2192 fn_has_lb g \u2192 fn_has_lb (f + g) :=\n\u03bb \u27e8a, lbfa\u27e9 \u27e8b, lbfb\u27e9, \u27e8a + b, fn_lb_add lbfa lbfb\u27e9\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Suma_de_funciones_acotadas_inferiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064587, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.743844854062019}}
{"text": "-- Monoton\u00eda del conjunto potencia: \ud835\udcab A \u2286 \ud835\udcab B \u2194 A \u2286 B\n-- ===================================================\n\nimport data.set\nopen set\n\nvariable  {U : Type}\nvariables {A B C : set U}\n\n-- #reduce \ud835\udcab A\n-- #reduce B \u2208 \ud835\udcab A\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B \n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\nbegin\n  intro h,\n  apply subset_of_mem_powerset,\n  apply h,\n  apply mem_powerset,\n  exact subset.rfl,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\nbegin\n  intro h,\n  apply h,\n  exact subset.rfl,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\nbegin\n  intro h,\n  exact (h subset.rfl),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\n\u03bb h, h subset.rfl\n\n-- 5\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\nassume h1 : \ud835\udcab A \u2286 \ud835\udcab B,\nhave h2 : A \u2286 A, from subset.rfl,\nhave h3 : A \u2208 \ud835\udcab A, from h2,\nhave h4 : A \u2208 \ud835\udcab B, from h1 h3,\nshow A \u2286 B, from h4\n\n-- 6\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\nassume h1 : \ud835\udcab A \u2286 \ud835\udcab B,\nhave h2 : A \u2286 A, from subset.rfl,\nhave h3 : A \u2208 \ud835\udcab A, from h2,\nh1 h3\n\n-- 7\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\nassume h1 : \ud835\udcab A \u2286 \ud835\udcab B,\nhave h2 : A \u2286 A, from subset.rfl,\nh1 h2\n\n-- 8\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\nassume h1 : \ud835\udcab A \u2286 \ud835\udcab B,\nh1 subset.rfl\n\n-- 9\u00aa demostraci\u00f3n\nlemma aux1 : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\n\u03bb h, h subset.rfl\n\n-- 10\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2192 A \u2286 B :=\npowerset_mono.mp\n\n-- ----------------------------------------------------\n-- Ej. 2. Demostrar\n--    A \u2286 B \u2192 \ud835\udcab A \u2286 \ud835\udcab B \n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : A \u2286 B \u2192 \ud835\udcab A \u2286 \ud835\udcab B :=\nbegin\n  intro h,\n  intros C hCA,\n  apply mem_powerset,\n  apply subset.trans hCA h,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : A \u2286 B \u2192 \ud835\udcab A \u2286 \ud835\udcab B :=\nbegin\n  intros h C hCA,\n  apply subset.trans hCA h,\nend\n\n-- 3\u00aa demostraci\u00f3n\nlemma aux2 : A \u2286 B \u2192 \ud835\udcab A \u2286 \ud835\udcab B :=\n\u03bb h C hCA, subset.trans hCA h\n\n-- 4\u00aa demostraci\u00f3n\nexample : A \u2286 B \u2192 \ud835\udcab A \u2286 \ud835\udcab B :=\npowerset_mono.mpr\n\n-- ----------------------------------------------------\n-- Ej. 3. Demostrar\n--    \ud835\udcab A \u2286 \ud835\udcab B \u2194 A \u2286 B\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2194 A \u2286 B :=\niff.intro aux1 aux2\n\n-- 2\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2194 A \u2286 B :=\n-- by library_search\npowerset_mono\n\n-- 3\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2194 A \u2286 B :=\n-- by hint\nby finish\n\n-- 4\u00aa demostraci\u00f3n\nexample : \ud835\udcab A \u2286 \ud835\udcab B \u2194 A \u2286 B :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Monotonia_del_conjunto_potencia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.7438448479436359}}
{"text": "/- LoVe Exercise 13: Rational and Real Numbers -/\n\nimport .love05_inductive_predicates_demo\nimport .love13_rational_and_real_numbers_demo\n\nnamespace LoVe\n\nset_option pp.beta true\n\n\n/- Question 1: Rationals -/\n\n/- 1.1. Prove the following lemma.\n\nHint: The lemma `fraction.mk.inj_eq` might be useful. -/\n\n#check fraction.mk.inj_eq\n\nlemma fraction.ext (a b : fraction) (h : fraction.num a = fraction.num b)\n    (h': fraction.denom a = fraction.denom b) :\n  a = b :=\nsorry\n\n/- 1.2. Extending the `fraction.has_mul` instance from the lecture, declare\n`fraction` an instance of `semigroup`.\n\nHint: Use the lemma `fraction.ext` above, and possibly `fraction.mul_num`, and\n`fraction.mul_denom`. -/\n\n#check fraction.ext\n#check fraction.mul_num\n#check fraction.mul_denom\n\ninstance fraction.semigroup : semigroup fraction :=\n{ mul_assoc :=\n    sorry,\n  ..fraction.has_mul }\n\n/- 1.3. Extending the `my\u211a.has_mul` instance from the lecture, declare `my\u211a` an\ninstance of `semigroup`.\n\nHint: The lemma `quotient.induction_on\u2083` might be useful. -/\n\n#check quotient.induction_on\u2083\n\ninstance my\u211a.semigroup : semigroup my\u211a :=\n{ mul_assoc :=\n    sorry,\n  ..my\u211a.has_mul }\n\n\n/- Question 2: Structural Induction on Paper -/\n\n/- This and the next question will exercise your understanding of induction,\nespecially if you need to perform induction proofs on a whiteboard (or on paper\nat the exam).\n\nGuidelines for paper proofs:\n\nWe expect detailed, rigorous, mathematical proofs. You are welcome to use\nstandard mathematical notation or Lean structured commands (e.g., `assume`,\n`have`, `show`, `calc`). You can also use tactical proofs (e.g., `intro`,\n`apply`), but then please indicate some of the intermediate goals, so that we\ncan follow the chain of reasoning.\n\nMajor proof steps, including applications of induction and invocation of the\ninduction hypothesis, must be stated explicitly. For each case of a proof by\ninduction, you must list the inductive hypotheses assumed (if any) and the goal\nto be proved. Minor proof steps corresponding to `refl`, `simp`, or `linarith`\nneed not be justified if you think they are obvious (to humans), but you should\nsay which key lemmas they follow from. You should be explicit whenever you use a\nfunction definition or an introduction rule for an inductive predicate. -/\n\n/- 2.1. Recall the following inductive datatype for binary trees from lecture 4:\n\n    inductive btree (\u03b1 : Type) : Type\n    | empty {} : btree\n    | node     : \u03b1 \u2192 btree \u2192 btree \u2192 btree\n\nWe defined a function `mirror` on these binary trees as follows:\n\n    def mirror {\u03b1 : Type} : btree \u03b1 \u2192 btree \u03b1\n    | empty        := empty\n    | (node a l r) := node a (mirror r) (mirror l)\n\nProve the following lemma by structural induction, as a paper proof:\n\n    lemma mirror_mirror {\u03b1 : Type} :\n      \u2200t : btree \u03b1, mirror (mirror t) = t -/\n\n-- enter your \"paper\" proof here\n\n/- 2.2. Prove the same lemma in Lean and compare it with your paper proof. -/\n\nlemma mirror_mirror\u2082 {\u03b1 : Type} :\n  \u2200t : btree \u03b1, mirror (mirror t) = t :=\nsorry\n\n\n/- Question 3: Rule Induction on Paper -/\n\n/- 3.1. Recall the following inductive predicate from lecture 5:\n\n    inductive even : \u2115 \u2192 Prop\n    | zero    : even 0\n    | add_two : \u2200n, even n \u2192 even (n + 2)\n\nProve the following lemma by rule induction, as a paper proof, following the\nguidelines given at the beginning of question 2. This is a good exercise to\ndevelop a deeper understanding of how rule induction works (and is good\npractice for the final exam).\n\n    lemma exists_of_even (n : \u2115) (h : even n) :\n      \u2203k : \u2115, n = 2 * k -/\n\n-- enter your \"paper\" proof here\n\n/- 3.2. Prove the same lemma in Lean and compare it with your paper proof. -/\n\nlemma exists_of_even (n : \u2115) (h : even n) :\n  \u2203k : \u2115, n = 2 * k :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love13_rational_and_real_numbers_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.7438448464294476}}
{"text": "/-  Math40001 : Introduction to university mathematics.\n\nProblem Sheet 4, October 2020.\n\nThis is a Lean file. It can be read with the Lean theorem prover.\n\nYou can work on this file online via the link at\nhttps://github.com/ImperialCollegeLondon/M40001_lean/blob/master/README.md\n\n\nor you can install Lean and its maths library following the\ninstructions at\nhttps://leanprover-community.github.io/get_started.html\n\nand then just clone the project onto your own computer\nwith `leanproject get ImperialCollegeLondon/M40001_lean`.\n\nThere are advantages to installing Lean on your own computer\n(for example it's faster), but it's more hassle than\njust using it online.\n\nIn the below, delete \"sorry\" and replace it with some\ntactics which prove the result.\n\n-/\n\nimport data.real.basic -- the real numbers\n\n/- Question 1. \n\nFor each of the sets~$X$ and binary relations~$R$ below, figure out whether~$R$ is (a) reflexive, (b) symmetric, (c) antisymmetric, (d) transitive. \n  \n  \\begin{enumerate}\n  \\item Let $X$ be the set $\\{1,2\\}$ and define~$R$ like this: $R(1,1)$ is true, $R(1,2)$ is true, $R(2,1)$ is true and $R(2,2)$ is false. \n  \\item Let~$X=\\R$ and define $R(a,b)$ to be the proposition $a=-b$.\n  \\item Let~$X=\\R$ and define $R(a,b)$ to be false for all real numbers~$a$ and~$b$.\n  \\item Let~$X$ be the empty set and define~$R$ to be the empty binary relation (we don't have to say what its value is on any pair $(a,b)$ because no such pairs exist).\n  \\end{enumerate}\n\n-/\n\nnamespace Q1a\n\ninductive X : Type\n| one : X\n| two : X\n\nnamespace X\n\ndef R : X \u2192 X \u2192 Prop\n| one one := true\n| one two := true\n| two one := true\n| two two := false\n\n-- insert \"\u00ac\" if you think it's not reflexive\nlemma Q1a_refl : reflexive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not symmetric\nlemma Q1a_symm : symmetric R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not transitive\nlemma Q1a_trans : transitive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not an equiv reln\nlemma Q1a_equiv : equivalence R := \nbegin\n  sorry\nend\n\nend X\nend Q1a\n\nnamespace Q1b\n\ndef R (a b : \u211d) : Prop := a = -b\n\n-- insert \"\u00ac\" if you think it's not reflexive\nlemma Q1b_refl : reflexive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not symmetric\nlemma Q1b_symm : symmetric R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not transitive\nlemma Q1b_trans : transitive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not an equiv reln\nlemma Q1b_equiv : equivalence R := \nbegin\n  sorry\nend\n\nend Q1b\n\nnamespace Q1c\n\ndef R (a b : \u211d) : Prop := false\n\n-- insert \"\u00ac\" if you think it's not reflexive\nlemma Q1c_refl : reflexive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not symmetric\nlemma Q1c_symm : symmetric R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not transitive\nlemma Q1c_trans : transitive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not an equiv reln\nlemma Q1c_equiv : equivalence R := \nbegin\n  sorry\nend\n\nend Q1c\n\nnamespace Q1d\n\ndef R (a b : empty) : Prop := by cases a -- i.e. \"I'll define it in all cases -- oh look there are no cases\"\n\n-- insert \"\u00ac\" if you think it's not reflexive\nlemma Q1d_refl : reflexive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not symmetric\nlemma Q1d_symm : symmetric R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not transitive\nlemma Q1d_trans : transitive R := \nbegin\n  sorry\nend\n\n-- insert \"\u00ac\" if you think it's not an equiv reln\nlemma Q1d_equiv : equivalence R := \nbegin\n  sorry\nend\n\nend Q1d\n\n-- `set \u2124` is the type of subsets of the integers.\n\ndef Q2a : partial_order (set \u2124) :=\n{ le := \u03bb A B, A \u2286 B,\n  le_refl := begin sorry end,\n  le_antisymm := begin sorry end,\n  le_trans := begin sorry end\n   }\n\n-- insert \u00ac at the beginning if you think it's wrong\nlemma Q2b : is_total (set \u2124) (\u03bb A B, A \u2286 B) :=\nbegin\n  sorry\nend\n\n-- put \u00ac in front if you think it's wrong\nlemma Q3a : symmetric (\u03bb a b : \u211d, a < b) :=\nbegin\n  sorry\nend\n\n-- put \u00ac in front if you think it's wrong\nlemma Q3b : symmetric (\u03bb a b : (\u2205 : set \u211d), a < b) :=\nbegin\n  sorry\nend\n\n-- type in the proof in the question. Where do you get stuck?\nlemma Q4 (X : Type) (R : X \u2192 (X \u2192 Prop)) (hs : symmetric R) (ht : transitive R) : reflexive R :=\nbegin\n  sorry\nend \n\nopen function\n\ndefinition pals {X Y Z : Type} (f : X \u2192 Y) (g : X \u2192 Z) := \u2203 h : Y \u2192 Z, bijective h \u2227 g = h \u2218 f\n\nlemma Q5 (X Y Z: Type) (f : X \u2192 Y) (g : X \u2192 Z) (hf : surjective f) (hg : surjective g) : pals f g \u2194 \u2200 a b : X, (f a = f b) \u2194 (g a = g b) :=\nbegin\n  sorry\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/problem_sheets/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7438261703201001}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, S\u00e9bastien Gou\u00ebzel, Heather Macbeth\n-/\nimport analysis.inner_product_space.projection\nimport analysis.normed_space.pi_Lp\n\n/-!\n# `L\u00b2` inner product space structure on finite products of inner product spaces\n\nThe `L\u00b2` norm on a finite product of inner product spaces is compatible with an inner product\n$$\n\\langle x, y\\rangle = \\sum \\langle x_i, y_i \\rangle.\n$$\nThis is recorded in this file as an inner product space instance on `pi_Lp 2`.\n\n## Main definitions\n\n- `euclidean_space \ud835\udd5c n`: defined to be `pi_Lp 2 (n \u2192 \ud835\udd5c)` for any `fintype n`, i.e., the space\n  from functions to `n` to `\ud835\udd5c` with the `L\u00b2` norm. We register several instances on it (notably\n  that it is a finite-dimensional inner product space).\n\n- `orthonormal_basis \ud835\udd5c \u03b9`: defined to be an isometry to Euclidean space from a given\n  finite-dimensional innner product space, `E \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9`.\n\n- `basis.to_orthonormal_basis`: constructs an `orthonormal_basis` for a finite-dimensional\n  Euclidean space from a `basis` which is `orthonormal`.\n\n- `linear_isometry_equiv.of_inner_product_space`: provides an arbitrary isometry to Euclidean space\n  from a given finite-dimensional inner product space, induced by choosing an arbitrary basis.\n\n- `complex.isometry_euclidean`: standard isometry from `\u2102` to `euclidean_space \u211d (fin 2)`\n\n-/\n\nopen real set filter is_R_or_C\nopen_locale big_operators uniformity topological_space nnreal ennreal complex_conjugate direct_sum\n\nnoncomputable theory\n\nvariables {\u03b9 : Type*} {\u03b9' : Type*}\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {E : Type*} [inner_product_space \ud835\udd5c E]\nvariables {E' : Type*} [inner_product_space \ud835\udd5c E']\nvariables {F : Type*} [inner_product_space \u211d F]\nvariables {F' : Type*} [inner_product_space \u211d F']\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\n\n/-\n If `\u03b9` is a finite type and each space `f i`, `i : \u03b9`, is an inner product space,\nthen `\u03a0 i, f i` is an inner product space as well. Since `\u03a0 i, f i` is endowed with the sup norm,\nwe use instead `pi_Lp 2 f` for the product space, which is endowed with the `L^2` norm.\n-/\ninstance pi_Lp.inner_product_space {\u03b9 : Type*} [fintype \u03b9] (f : \u03b9 \u2192 Type*)\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] : inner_product_space \ud835\udd5c (pi_Lp 2 f) :=\n{ inner := \u03bb x y, \u2211 i, inner (x i) (y i),\n  norm_sq_eq_inner :=\n  begin\n    intro x,\n    have h\u2082 : 0 \u2264 \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d) :=\n      finset.sum_nonneg (\u03bb j hj, rpow_nonneg_of_nonneg (norm_nonneg (x j)) 2),\n    simp only [norm, add_monoid_hom.map_sum, \u2190 norm_sq_eq_inner, one_div],\n    rw [\u2190 rpow_nat_cast ((\u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d)) ^ (2 : \u211d)\u207b\u00b9) 2, \u2190 rpow_mul h\u2082],\n    norm_num,\n  end,\n  conj_sym :=\n  begin\n    intros x y,\n    unfold inner,\n    rw ring_hom.map_sum,\n    apply finset.sum_congr rfl,\n    rintros z -,\n    apply inner_conj_sym,\n  end,\n  add_left := \u03bb x y z,\n    show \u2211 i, inner (x i + y i) (z i) = \u2211 i, inner (x i) (z i) + \u2211 i, inner (y i) (z i),\n    by simp only [inner_add_left, finset.sum_add_distrib],\n  smul_left := \u03bb x y r,\n    show \u2211 (i : \u03b9), inner (r \u2022 x i) (y i) = (conj r) * \u2211 i, inner (x i) (y i),\n    by simp only [finset.mul_sum, inner_smul_left] }\n\n@[simp] lemma pi_Lp.inner_apply {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 Type*}\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] (x y : pi_Lp 2 f) :\n  \u27eax, y\u27eb = \u2211 i, \u27eax i, y i\u27eb :=\nrfl\n\n/-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional\nspace use `euclidean_space \ud835\udd5c (fin n)`. -/\n@[reducible, nolint unused_arguments]\ndef euclidean_space (\ud835\udd5c : Type*) [is_R_or_C \ud835\udd5c]\n  (n : Type*) [fintype n] : Type* := pi_Lp 2 (\u03bb (i : n), \ud835\udd5c)\n\nlemma euclidean_space.norm_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x : euclidean_space \ud835\udd5c n) : \u2225x\u2225 = real.sqrt (\u2211 i, \u2225x i\u2225 ^ 2) :=\npi_Lp.norm_eq_of_L2 x\n\nlemma euclidean_space.nnnorm_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x : euclidean_space \ud835\udd5c n) : \u2225x\u2225\u208a = nnreal.sqrt (\u2211 i, \u2225x i\u2225\u208a ^ 2) :=\npi_Lp.nnnorm_eq_of_L2 x\n\nlemma euclidean_space.dist_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x y : euclidean_space \ud835\udd5c n) : dist x y = (\u2211 i, dist (x i) (y i) ^ 2).sqrt :=\n(pi_Lp.dist_eq_of_L2 x y : _)\n\nlemma euclidean_space.nndist_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x y : euclidean_space \ud835\udd5c n) : nndist x y = (\u2211 i, nndist (x i) (y i) ^ 2).sqrt :=\n(pi_Lp.nndist_eq_of_L2 x y : _)\n\nlemma euclidean_space.edist_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x y : euclidean_space \ud835\udd5c n) : edist x y = (\u2211 i, edist (x i) (y i) ^ 2) ^ (1 / 2 : \u211d) :=\n(pi_Lp.edist_eq_of_L2 x y : _)\n\nvariables [fintype \u03b9]\n\nsection\nlocal attribute [reducible] pi_Lp\n\ninstance : finite_dimensional \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\ninstance : inner_product_space \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\n\n@[simp] lemma finrank_euclidean_space :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) = fintype.card \u03b9 := by simp\n\nlemma finrank_euclidean_space_fin {n : \u2115} :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c (fin n)) = n := by simp\n\nlemma euclidean_space.inner_eq_star_dot_product (x y : euclidean_space \ud835\udd5c \u03b9) :\n  \u27eax, y\u27eb = matrix.dot_product (star $ pi_Lp.equiv _ _ x) (pi_Lp.equiv _ _ y) := rfl\n\n/-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry\nfrom `E` to `pi_Lp 2` of the subspaces equipped with the `L2` inner product. -/\ndef direct_sum.is_internal.isometry_L2_of_orthogonal_family\n  [decidable_eq \u03b9] {V : \u03b9 \u2192 submodule \ud835\udd5c E} (hV : direct_sum.is_internal V)\n  (hV' : @orthogonal_family \ud835\udd5c _ _ _ _ (\u03bb i, V i) _ (\u03bb i, (V i).subtype\u2097\u1d62)) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] pi_Lp 2 (\u03bb i, V i) :=\nbegin\n  let e\u2081 := direct_sum.linear_equiv_fun_on_fintype \ud835\udd5c \u03b9 (\u03bb i, V i),\n  let e\u2082 := linear_equiv.of_bijective (direct_sum.coe_linear_map V) hV.injective hV.surjective,\n  refine (e\u2082.symm.trans e\u2081).isometry_of_inner _,\n  suffices : \u2200 v w, \u27eav, w\u27eb = \u27eae\u2082 (e\u2081.symm v), e\u2082 (e\u2081.symm w)\u27eb,\n  { intros v\u2080 w\u2080,\n    convert this (e\u2081 (e\u2082.symm v\u2080)) (e\u2081 (e\u2082.symm w\u2080));\n    simp only [linear_equiv.symm_apply_apply, linear_equiv.apply_symm_apply] },\n  intros v w,\n  transitivity \u27ea(\u2211 i, (V i).subtype\u2097\u1d62 (v i)), \u2211 i, (V i).subtype\u2097\u1d62 (w i)\u27eb,\n  { simp only [sum_inner, hV'.inner_right_fintype, pi_Lp.inner_apply] },\n  { congr; simp }\nend\n\n@[simp] lemma direct_sum.is_internal.isometry_L2_of_orthogonal_family_symm_apply\n  [decidable_eq \u03b9] {V : \u03b9 \u2192 submodule \ud835\udd5c E} (hV : direct_sum.is_internal V)\n  (hV' : @orthogonal_family \ud835\udd5c _ _ _ _ (\u03bb i, V i) _ (\u03bb i, (V i).subtype\u2097\u1d62))\n  (w : pi_Lp 2 (\u03bb i, V i)) :\n  (hV.isometry_L2_of_orthogonal_family hV').symm w = \u2211 i, (w i : E) :=\nbegin\n  classical,\n  let e\u2081 := direct_sum.linear_equiv_fun_on_fintype \ud835\udd5c \u03b9 (\u03bb i, V i),\n  let e\u2082 := linear_equiv.of_bijective (direct_sum.coe_linear_map V) hV.injective hV.surjective,\n  suffices : \u2200 v : \u2a01 i, V i, e\u2082 v = \u2211 i, e\u2081 v i,\n  { exact this (e\u2081.symm w) },\n  intros v,\n  simp [e\u2082, direct_sum.coe_linear_map, direct_sum.to_module, dfinsupp.sum_add_hom_apply]\nend\n\nend\n\n/-- The vector given in euclidean space by being `1 : \ud835\udd5c` at coordinate `i : \u03b9` and `0 : \ud835\udd5c` at\nall other coordinates. -/\ndef euclidean_space.single [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) :\n  euclidean_space \ud835\udd5c \u03b9 :=\n(pi_Lp.equiv _ _).symm (pi.single i a)\n\n@[simp] lemma pi_Lp.equiv_single [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) :\n  pi_Lp.equiv _ _ (euclidean_space.single i a) = pi.single i a := rfl\n\n@[simp] lemma pi_Lp.equiv_symm_single [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) :\n  (pi_Lp.equiv _ _).symm (pi.single i a) = euclidean_space.single i a := rfl\n\n@[simp] theorem euclidean_space.single_apply [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) (j : \u03b9) :\n  (euclidean_space.single i a) j = ite (j = i) a 0 :=\nby { rw [euclidean_space.single, pi_Lp.equiv_symm_apply, \u2190 pi.single_apply i a j] }\n\nlemma euclidean_space.inner_single_left [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) (v : euclidean_space \ud835\udd5c \u03b9) :\n  \u27eaeuclidean_space.single i (a : \ud835\udd5c), v\u27eb = conj a * (v i) :=\nby simp [apply_ite conj]\n\nlemma euclidean_space.inner_single_right [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c)\n  (v : euclidean_space \ud835\udd5c \u03b9) :\n  \u27eav, euclidean_space.single i (a : \ud835\udd5c)\u27eb =  a * conj (v i) :=\nby simp [apply_ite conj, mul_comm]\n\nvariables (\u03b9 \ud835\udd5c E)\n\n/-- An orthonormal basis on E is an identification of `E` with its dimensional-matching\n`euclidean_space \ud835\udd5c \u03b9`. -/\nstructure orthonormal_basis := of_repr :: (repr : E \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9)\n\nvariables {\u03b9 \ud835\udd5c E}\n\nnamespace orthonormal_basis\n\ninstance : inhabited (orthonormal_basis \u03b9 \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9)) :=\n\u27e8of_repr (linear_isometry_equiv.refl \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9))\u27e9\n\n/-- `b i` is the `i`th basis vector. -/\ninstance : has_coe_to_fun (orthonormal_basis \u03b9 \ud835\udd5c E) (\u03bb _, \u03b9 \u2192 E) :=\n{ coe := \u03bb b i, by classical; exact b.repr.symm (euclidean_space.single i (1 : \ud835\udd5c)) }\n\n@[simp] protected lemma repr_symm_single [decidable_eq \u03b9] (b : orthonormal_basis \u03b9 \ud835\udd5c E) (i : \u03b9) :\n  b.repr.symm (euclidean_space.single i (1:\ud835\udd5c)) = b i :=\nby { classical, congr, simp, }\n\n@[simp] protected lemma repr_self [decidable_eq \u03b9] (b : orthonormal_basis \u03b9 \ud835\udd5c E) (i : \u03b9) :\n  b.repr (b i) = euclidean_space.single i (1:\ud835\udd5c) :=\nby rw [\u2190 b.repr_symm_single i, linear_isometry_equiv.apply_symm_apply]\n\nprotected lemma repr_apply_apply (b : orthonormal_basis \u03b9 \ud835\udd5c E) (v : E) (i : \u03b9) :\n  b.repr v i = \u27eab i, v\u27eb :=\nbegin\n  classical,\n  rw [\u2190 b.repr.inner_map_map (b i) v, b.repr_self i, euclidean_space.inner_single_left],\n  simp only [one_mul, eq_self_iff_true, map_one],\nend\n\n@[simp]\nprotected lemma orthonormal (b : orthonormal_basis \u03b9 \ud835\udd5c E) : orthonormal \ud835\udd5c b :=\nbegin\n  classical,\n  rw orthonormal_iff_ite,\n  intros i j,\n  rw [\u2190 b.repr.inner_map_map (b i) (b j), b.repr_self i, b.repr_self j],\n  rw euclidean_space.inner_single_left,\n  rw euclidean_space.single_apply,\n  simp only [mul_boole, map_one],\nend\n\n/-- The `basis \u03b9 \ud835\udd5c E` underlying the `orthonormal_basis` --/\nprotected def to_basis (b : orthonormal_basis \u03b9 \ud835\udd5c E) : basis \u03b9 \ud835\udd5c E :=\nbasis.of_equiv_fun b.repr.to_linear_equiv\n\n@[simp] protected lemma coe_to_basis (b : orthonormal_basis \u03b9 \ud835\udd5c E) :\n  (\u21d1b.to_basis : \u03b9 \u2192 E) = \u21d1b :=\nbegin\n  change \u21d1(basis.of_equiv_fun b.repr.to_linear_equiv) = b,\n  ext j,\n  rw basis.coe_of_equiv_fun,\n  simp only [orthonormal_basis.repr_symm_single],\n  congr,\nend\n\n@[simp] protected lemma coe_to_basis_repr (b : orthonormal_basis \u03b9 \ud835\udd5c E) :\n  b.to_basis.equiv_fun = b.repr.to_linear_equiv :=\nbegin\n  change (basis.of_equiv_fun b.repr.to_linear_equiv).equiv_fun = b.repr.to_linear_equiv,\n  ext x j,\n  simp only [basis.of_equiv_fun_repr_apply, eq_self_iff_true,\n    linear_isometry_equiv.coe_to_linear_equiv, basis.equiv_fun_apply],\nend\n\nprotected lemma sum_repr_symm (b : orthonormal_basis \u03b9 \ud835\udd5c E) (v : euclidean_space \ud835\udd5c \u03b9) :\n  \u2211 i , v i \u2022 b i = (b.repr.symm v) :=\nby { classical, simpa using (b.to_basis.equiv_fun_symm_apply v).symm }\n\nvariable {v : \u03b9 \u2192 E}\n\n/-- A basis that is orthonormal is an orthonormal basis. -/\ndef _root_.basis.to_orthonormal_basis (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  orthonormal_basis \u03b9 \ud835\udd5c E :=\northonormal_basis.of_repr $\nlinear_equiv.isometry_of_inner v.equiv_fun\nbegin\n  intros x y,\n  let p : euclidean_space \ud835\udd5c \u03b9 := v.equiv_fun x,\n  let q : euclidean_space \ud835\udd5c \u03b9 := v.equiv_fun y,\n  have key : \u27eap, q\u27eb = \u27ea\u2211 i, p i \u2022 v i, \u2211 i, q i \u2022 v i\u27eb,\n  { simp [sum_inner, inner_smul_left, hv.inner_right_fintype] },\n  convert key,\n  { rw [\u2190 v.equiv_fun.symm_apply_apply x, v.equiv_fun_symm_apply] },\n  { rw [\u2190 v.equiv_fun.symm_apply_apply y, v.equiv_fun_symm_apply] }\nend\n\n@[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  ((v.to_orthonormal_basis hv).repr : E \u2192 euclidean_space \ud835\udd5c \u03b9) = v.equiv_fun :=\nrfl\n\n@[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr_symm\n  (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  ((v.to_orthonormal_basis hv).repr.symm : euclidean_space \ud835\udd5c \u03b9 \u2192 E) = v.equiv_fun.symm :=\nrfl\n\n@[simp] lemma _root_.basis.to_basis_to_orthonormal_basis (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  (v.to_orthonormal_basis hv).to_basis = v :=\nby simp [basis.to_orthonormal_basis, orthonormal_basis.to_basis]\n\n@[simp] lemma _root_.basis.coe_to_orthonormal_basis (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  (v.to_orthonormal_basis hv : \u03b9 \u2192 E) = (v : \u03b9 \u2192 E) :=\ncalc (v.to_orthonormal_basis hv : \u03b9 \u2192 E) = ((v.to_orthonormal_basis hv).to_basis : \u03b9 \u2192 E) :\n  by { classical, rw orthonormal_basis.coe_to_basis }\n... = (v : \u03b9 \u2192 E) : by simp\n\n/-- An orthonormal set that spans is an orthonormal basis -/\nprotected def mk (hon : orthonormal \ud835\udd5c v) (hsp: submodule.span \ud835\udd5c (set.range v) = \u22a4):\n  orthonormal_basis \u03b9 \ud835\udd5c E :=\n(basis.mk (orthonormal.linear_independent hon) hsp).to_orthonormal_basis (by rwa basis.coe_mk)\n\n@[simp]\nprotected lemma coe_mk (hon : orthonormal \ud835\udd5c v) (hsp: submodule.span \ud835\udd5c (set.range v) = \u22a4) :\n  \u21d1(orthonormal_basis.mk hon hsp) = v :=\nby classical; rw [orthonormal_basis.mk, _root_.basis.coe_to_orthonormal_basis, basis.coe_mk]\n\nend orthonormal_basis\n\n/-- If `f : E \u2243\u2097\u1d62[\ud835\udd5c] E'` is a linear isometry of inner product spaces then an orthonormal basis `v`\nof `E` determines a linear isometry `e : E' \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9`. This result states that\n`e` may be obtained either by transporting `v` to `E'` or by composing with the linear isometry\n`E \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9` provided by `v`. -/\n@[simp] lemma basis.map_isometry_euclidean_of_orthonormal (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v)\n  (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') :\n  ((v.map f.to_linear_equiv).to_orthonormal_basis (hv.map_linear_isometry_equiv f)).repr =\n    f.symm.trans (v.to_orthonormal_basis hv).repr :=\nlinear_isometry_equiv.to_linear_equiv_injective $ v.map_equiv_fun _\n\n/-- `\u2102` is isometric to `\u211d\u00b2` with the Euclidean inner product. -/\ndef complex.isometry_euclidean : \u2102 \u2243\u2097\u1d62[\u211d] (euclidean_space \u211d (fin 2)) :=\n(complex.basis_one_I.to_orthonormal_basis\nbegin\n  rw orthonormal_iff_ite,\n  intros i, fin_cases i;\n  intros j; fin_cases j;\n  simp [real_inner_eq_re_inner]\nend).repr\n\n@[simp] lemma complex.isometry_euclidean_symm_apply (x : euclidean_space \u211d (fin 2)) :\n  complex.isometry_euclidean.symm x = (x 0) + (x 1) * I :=\nbegin\n  convert complex.basis_one_I.equiv_fun_symm_apply x,\n  { simpa },\n  { simp },\nend\n\nlemma complex.isometry_euclidean_proj_eq_self (z : \u2102) :\n  \u2191(complex.isometry_euclidean z 0) + \u2191(complex.isometry_euclidean z 1) * (I : \u2102) = z :=\nby rw [\u2190 complex.isometry_euclidean_symm_apply (complex.isometry_euclidean z),\n  complex.isometry_euclidean.symm_apply_apply z]\n\n@[simp] lemma complex.isometry_euclidean_apply_zero (z : \u2102) :\n  complex.isometry_euclidean z 0 = z.re :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\n@[simp] lemma complex.isometry_euclidean_apply_one (z : \u2102) :\n  complex.isometry_euclidean z 1 = z.im :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\n/-- The isometry between `\u2102` and a two-dimensional real inner product space given by a basis. -/\ndef complex.isometry_of_orthonormal {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v) : \u2102 \u2243\u2097\u1d62[\u211d] F :=\ncomplex.isometry_euclidean.trans (v.to_orthonormal_basis hv).repr.symm\n\n@[simp] lemma complex.map_isometry_of_orthonormal {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v)\n  (f : F \u2243\u2097\u1d62[\u211d] F') :\n  complex.isometry_of_orthonormal (hv.map_linear_isometry_equiv f) =\n    (complex.isometry_of_orthonormal hv).trans f :=\nby simp [complex.isometry_of_orthonormal, linear_isometry_equiv.trans_assoc]\n\nlemma complex.isometry_of_orthonormal_symm_apply\n  {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v) (f : F) :\n  (complex.isometry_of_orthonormal hv).symm f = (v.coord 0 f : \u2102) + (v.coord 1 f : \u2102) * I :=\nby simp [complex.isometry_of_orthonormal]\n\nlemma complex.isometry_of_orthonormal_apply\n  {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v) (z : \u2102) :\n  complex.isometry_of_orthonormal hv z = z.re \u2022 v 0 + z.im \u2022 v 1 :=\nby simp [complex.isometry_of_orthonormal, (dec_trivial : (finset.univ : finset (fin 2)) = {0, 1})]\n\nopen finite_dimensional\n\n/-- Given a natural number `n` equal to the `finrank` of a finite-dimensional inner product space,\nthere exists an isometry from the space to `euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.of_inner_product_space\n  [finite_dimensional \ud835\udd5c E] {n : \u2115} (hn : finrank \ud835\udd5c E = n) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\n((fin_std_orthonormal_basis hn).to_orthonormal_basis\n  (fin_std_orthonormal_basis_orthonormal hn)).repr\n\nlocal attribute [instance] fact_finite_dimensional_of_finrank_eq_succ\n\n/-- Given a natural number `n` one less than the `finrank` of a finite-dimensional inner product\nspace, there exists an isometry from the orthogonal complement of a nonzero singleton to\n`euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.from_orthogonal_span_singleton\n  (n : \u2115) [fact (finrank \ud835\udd5c E = n + 1)] {v : E} (hv : v \u2260 0) :\n  (\ud835\udd5c \u2219 v)\u15ee \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\nlinear_isometry_equiv.of_inner_product_space (finrank_orthogonal_span_singleton hv)\n\nsection linear_isometry\n\nvariables {V : Type*} [inner_product_space \ud835\udd5c V] [finite_dimensional \ud835\udd5c V]\n\nvariables {S : submodule \ud835\udd5c V} {L : S \u2192\u2097\u1d62[\ud835\udd5c] V}\n\nopen finite_dimensional\n\n/-- Let `S` be a subspace of a finite-dimensional complex inner product space `V`.  A linear\nisometry mapping `S` into `V` can be extended to a full isometry of `V`.\n\nTODO:  The case when `S` is a finite-dimensional subspace of an infinite-dimensional `V`.-/\nnoncomputable def linear_isometry.extend (L : S \u2192\u2097\u1d62[\ud835\udd5c] V): V \u2192\u2097\u1d62[\ud835\udd5c] V :=\nbegin\n  -- Build an isometry from S\u15ee to L(S)\u15ee through euclidean_space\n  let d := finrank \ud835\udd5c S\u15ee,\n  have dim_S_perp : finrank \ud835\udd5c S\u15ee = d := rfl,\n  let LS := L.to_linear_map.range,\n  have E : S\u15ee \u2243\u2097\u1d62[\ud835\udd5c] LS\u15ee,\n  { have dim_LS_perp : finrank \ud835\udd5c LS\u15ee = d,\n    calc  finrank \ud835\udd5c LS\u15ee = finrank \ud835\udd5c V - finrank \ud835\udd5c LS : by simp only\n        [\u2190 LS.finrank_add_finrank_orthogonal, add_tsub_cancel_left]\n      ...               = finrank \ud835\udd5c V - finrank \ud835\udd5c S : by simp only\n        [linear_map.finrank_range_of_inj L.injective]\n      ...               = finrank \ud835\udd5c S\u15ee : by simp only\n        [\u2190 S.finrank_add_finrank_orthogonal, add_tsub_cancel_left]\n      ...               = d : dim_S_perp,\n    let BS := ((fin_std_orthonormal_basis dim_S_perp).to_orthonormal_basis\n      (fin_std_orthonormal_basis_orthonormal dim_S_perp)),\n    let BLS := ((fin_std_orthonormal_basis dim_LS_perp).to_orthonormal_basis\n      (fin_std_orthonormal_basis_orthonormal dim_LS_perp)),\n    exact BS.repr.trans BLS.repr.symm },\n  let L3 := (LS)\u15ee.subtype\u2097\u1d62.comp E.to_linear_isometry,\n  -- Project onto S and S\u15ee\n  haveI : complete_space S := finite_dimensional.complete \ud835\udd5c S,\n  haveI : complete_space V := finite_dimensional.complete \ud835\udd5c V,\n  let p1 := (orthogonal_projection S).to_linear_map,\n  let p2 := (orthogonal_projection S\u15ee).to_linear_map,\n  -- Build a linear map from the isometries on S and S\u15ee\n  let M := L.to_linear_map.comp p1 + L3.to_linear_map.comp p2,\n  -- Prove that M is an isometry\n  have M_norm_map : \u2200 (x : V), \u2225M x\u2225 = \u2225x\u2225,\n  { intro x,\n    -- Apply M to the orthogonal decomposition of x\n    have Mx_decomp : M x = L (p1 x) + L3 (p2 x),\n    { simp only [linear_map.add_apply, linear_map.comp_apply, linear_map.comp_apply,\n      linear_isometry.coe_to_linear_map]},\n    -- Mx_decomp is the orthogonal decomposition of M x\n    have Mx_orth : \u27ea L (p1 x), L3 (p2 x) \u27eb = 0,\n    { have Lp1x : L (p1 x) \u2208 L.to_linear_map.range := L.to_linear_map.mem_range_self (p1 x),\n      have Lp2x : L3 (p2 x) \u2208 (L.to_linear_map.range)\u15ee,\n      { simp only [L3, linear_isometry.coe_comp, function.comp_app, submodule.coe_subtype\u2097\u1d62,\n          \u2190 submodule.range_subtype (LS\u15ee)],\n        apply linear_map.mem_range_self},\n      apply submodule.inner_right_of_mem_orthogonal Lp1x Lp2x},\n    -- Apply the Pythagorean theorem and simplify\n    rw [\u2190 sq_eq_sq (norm_nonneg _) (norm_nonneg _), norm_sq_eq_add_norm_sq_projection x S],\n    simp only [sq, Mx_decomp],\n    rw norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (L (p1 x)) (L3 (p2 x)) Mx_orth,\n    simp only [linear_isometry.norm_map, p1, p2, continuous_linear_map.to_linear_map_eq_coe,\n      add_left_inj, mul_eq_mul_left_iff, norm_eq_zero, true_or, eq_self_iff_true,\n      continuous_linear_map.coe_coe, submodule.coe_norm, submodule.coe_eq_zero] },\n  exact { to_linear_map := M, norm_map' := M_norm_map },\nend\n\nlemma linear_isometry.extend_apply (L : S \u2192\u2097\u1d62[\ud835\udd5c] V) (s : S):\n  L.extend s = L s :=\nbegin\n  haveI : complete_space S := finite_dimensional.complete \ud835\udd5c S,\n  simp only [linear_isometry.extend, continuous_linear_map.to_linear_map_eq_coe,\n    \u2190linear_isometry.coe_to_linear_map],\n  simp only [add_right_eq_self, linear_isometry.coe_to_linear_map,\n    linear_isometry_equiv.coe_to_linear_isometry, linear_isometry.coe_comp, function.comp_app,\n    orthogonal_projection_mem_subspace_eq_self, linear_map.coe_comp, continuous_linear_map.coe_coe,\n    submodule.coe_subtype, linear_map.add_apply, submodule.coe_eq_zero,\n    linear_isometry_equiv.map_eq_zero_iff, submodule.coe_subtype\u2097\u1d62,\n    orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero,\n    submodule.orthogonal_orthogonal, submodule.coe_mem],\nend\n\nend linear_isometry\n\nsection matrix\n\nopen_locale matrix\n\nvariables {n m : \u2115}\n\nlocal notation `\u27ea`x`, `y`\u27eb\u2098` := @inner \ud835\udd5c (euclidean_space \ud835\udd5c (fin m)) _ x y\nlocal notation `\u27ea`x`, `y`\u27eb\u2099` := @inner \ud835\udd5c (euclidean_space \ud835\udd5c (fin n)) _ x y\n\n/-- The inner product of a row of A and a row of B is an entry of B \u2b1d A\u1d34. -/\nlemma inner_matrix_row_row (A B : matrix (fin n) (fin m) \ud835\udd5c) (i j : (fin n)) :\n  \u27eaA i, B j\u27eb\u2098 = (B \u2b1d A\u1d34) j i := by {simp only [inner, matrix.mul_apply, star_ring_end_apply,\n    matrix.conj_transpose_apply,mul_comm]}\n\n/-- The inner product of a column of A and a column of B is an entry of A\u1d34 \u2b1d B -/\nlemma inner_matrix_col_col (A B : matrix (fin n) (fin m) \ud835\udd5c) (i j : (fin m)) :\n  \u27eaA\u1d40 i, B\u1d40 j\u27eb\u2099 = (A\u1d34 \u2b1d B) i j := rfl\n\nend matrix\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/inner_product_space/pi_L2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.743801781538357}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Yury Kudryashov\n-/\nimport data.set.pointwise\n\n/-!\n# Torsors of additive group actions\n\nThis file defines torsors of additive group actions.\n\n## Notations\n\nThe group elements are referred to as acting on points.  This file\ndefines the notation `+\u1d65` for adding a group element to a point and\n`-\u1d65` for subtracting two points to produce a group element.\n\n## Implementation notes\n\nAffine spaces are the motivating example of torsors of additive group actions. It may be appropriate\nto refactor in terms of the general definition of group actions, via `to_additive`, when there is a\nuse for multiplicative torsors (currently mathlib only develops the theory of group actions for\nmultiplicative group actions).\n\n## Notations\n\n* `v +\u1d65 p` is a notation for `has_vadd.vadd`, the left action of an additive monoid;\n\n* `p\u2081 -\u1d65 p\u2082` is a notation for `has_vsub.vsub`, difference between two points in an additive torsor\n  as an element of the corresponding additive group;\n\n## References\n\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n* https://en.wikipedia.org/wiki/Affine_space\n\n-/\n\n/-- An `add_torsor G P` gives a structure to the nonempty type `P`,\nacted on by an `add_group G` with a transitive and free action given\nby the `+\u1d65` operation and a corresponding subtraction given by the\n`-\u1d65` operation. In the case of a vector space, it is an affine\nspace. -/\nclass add_torsor (G : out_param Type*) (P : Type*) [out_param $ add_group G]\n  extends add_action G P, has_vsub G P :=\n[nonempty : nonempty P]\n(vsub_vadd' : \u2200 (p1 p2 : P), (p1 -\u1d65 p2 : G) +\u1d65 p2 = p1)\n(vadd_vsub' : \u2200 (g : G) (p : P), g +\u1d65 p -\u1d65 p = g)\n\nattribute [instance, priority 100, nolint dangerous_instance] add_torsor.nonempty\nattribute [nolint dangerous_instance] add_torsor.to_has_vsub\n\n/-- An `add_group G` is a torsor for itself. -/\n@[nolint instance_priority]\ninstance add_group_is_add_torsor (G : Type*) [add_group G] :\n  add_torsor G G :=\n{ vsub := has_sub.sub,\n  vsub_vadd' := sub_add_cancel,\n  vadd_vsub' := add_sub_cancel }\n\n/-- Simplify subtraction for a torsor for an `add_group G` over\nitself. -/\n@[simp] lemma vsub_eq_sub {G : Type*} [add_group G] (g1 g2 : G) : g1 -\u1d65 g2 = g1 - g2 :=\nrfl\n\nsection general\n\nvariables {G : Type*} {P : Type*} [add_group G] [T : add_torsor G P]\ninclude T\n\n/-- Adding the result of subtracting from another point produces that\npoint. -/\n@[simp] lemma vsub_vadd (p1 p2 : P) : p1 -\u1d65 p2 +\u1d65 p2 = p1 :=\nadd_torsor.vsub_vadd' p1 p2\n\n/-- Adding a group element then subtracting the original point\nproduces that group element. -/\n@[simp] lemma vadd_vsub (g : G) (p : P) : g +\u1d65 p -\u1d65 p = g :=\nadd_torsor.vadd_vsub' g p\n\n/-- If the same point added to two group elements produces equal\nresults, those group elements are equal. -/\nlemma vadd_right_cancel {g1 g2 : G} (p : P) (h : g1 +\u1d65 p = g2 +\u1d65 p) : g1 = g2 :=\nby rw [\u2190vadd_vsub g1, h, vadd_vsub]\n\n@[simp] lemma vadd_right_cancel_iff {g1 g2 : G} (p : P) :  g1 +\u1d65 p = g2 +\u1d65 p \u2194 g1 = g2 :=\n\u27e8vadd_right_cancel p, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Adding a group element to the point `p` is an injective\nfunction. -/\nlemma vadd_right_injective (p : P) : function.injective ((+\u1d65 p) : G \u2192 P) :=\n\u03bb g1 g2, vadd_right_cancel p\n\n/-- Adding a group element to a point, then subtracting another point,\nproduces the same result as subtracting the points then adding the\ngroup element. -/\nlemma vadd_vsub_assoc (g : G) (p1 p2 : P) : g +\u1d65 p1 -\u1d65 p2 = g + (p1 -\u1d65 p2) :=\nbegin\n  apply vadd_right_cancel p2,\n  rw [vsub_vadd, add_vadd, vsub_vadd]\nend\n\n/-- Subtracting a point from itself produces 0. -/\n@[simp] lemma vsub_self (p : P) : p -\u1d65 p = (0 : G) :=\nby rw [\u2190zero_add (p -\u1d65 p), \u2190vadd_vsub_assoc, vadd_vsub]\n\n/-- If subtracting two points produces 0, they are equal. -/\nlemma eq_of_vsub_eq_zero {p1 p2 : P} (h : p1 -\u1d65 p2 = (0 : G)) : p1 = p2 :=\nby rw [\u2190vsub_vadd p1 p2, h, zero_vadd]\n\n/-- Subtracting two points produces 0 if and only if they are\nequal. -/\n@[simp] lemma vsub_eq_zero_iff_eq {p1 p2 : P} : p1 -\u1d65 p2 = (0 : G) \u2194 p1 = p2 :=\niff.intro eq_of_vsub_eq_zero (\u03bb h, h \u25b8 vsub_self _)\n\n/-- Cancellation adding the results of two subtractions. -/\n@[simp] lemma vsub_add_vsub_cancel (p1 p2 p3 : P) : p1 -\u1d65 p2 + (p2 -\u1d65 p3) = (p1 -\u1d65 p3) :=\nbegin\n  apply vadd_right_cancel p3,\n  rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd]\nend\n\n/-- Subtracting two points in the reverse order produces the negation\nof subtracting them. -/\n@[simp] lemma neg_vsub_eq_vsub_rev (p1 p2 : P) : -(p1 -\u1d65 p2) = (p2 -\u1d65 p1) :=\nbegin\n  refine neg_eq_of_add_eq_zero (vadd_right_cancel p1 _),\n  rw [vsub_add_vsub_cancel, vsub_self],\nend\n\n/-- Subtracting the result of adding a group element produces the same result\nas subtracting the points and subtracting that group element. -/\nlemma vsub_vadd_eq_vsub_sub (p1 p2 : P) (g : G) : p1 -\u1d65 (g +\u1d65 p2) = (p1 -\u1d65 p2) - g :=\nby rw [\u2190add_right_inj (p2 -\u1d65 p1 : G), vsub_add_vsub_cancel, \u2190neg_vsub_eq_vsub_rev, vadd_vsub,\n       \u2190add_sub_assoc, \u2190neg_vsub_eq_vsub_rev, neg_add_self, zero_sub]\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_right (p1 p2 p3 : P) :\n  (p1 -\u1d65 p3) - (p2 -\u1d65 p3) = (p1 -\u1d65 p2) :=\nby rw [\u2190vsub_vadd_eq_vsub_sub, vsub_vadd]\n\n/-- Convert between an equality with adding a group element to a point\nand an equality of a subtraction of two points with a group\nelement. -/\nlemma eq_vadd_iff_vsub_eq (p1 : P) (g : G) (p2 : P) : p1 = g +\u1d65 p2 \u2194 p1 -\u1d65 p2 = g :=\n\u27e8\u03bb h, h.symm \u25b8 vadd_vsub _ _, \u03bb h, h \u25b8 (vsub_vadd _ _).symm\u27e9\n\nlemma vadd_eq_vadd_iff_neg_add_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 - v\u2081 + v\u2082 = p\u2081 -\u1d65 p\u2082 :=\nby rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, \u2190 add_right_inj (-v\u2081), neg_add_cancel_left, eq_comm]\n\nnamespace set\nopen_locale pointwise\n\n@[simp] lemma singleton_vsub_self (p : P) : ({p} : set P) -\u1d65 {p} = {(0:G)} :=\nby rw [set.singleton_vsub_singleton, vsub_self]\n\nend set\n\n@[simp] lemma vadd_vsub_vadd_cancel_right (v\u2081 v\u2082 : G) (p : P) :\n  (v\u2081 +\u1d65 p) -\u1d65 (v\u2082 +\u1d65 p) = v\u2081 - v\u2082 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero]\n\n/-- If the same point subtracted from two points produces equal\nresults, those points are equal. -/\nlemma vsub_left_cancel {p1 p2 p : P} (h : p1 -\u1d65 p = p2 -\u1d65 p) : p1 = p2 :=\nby rwa [\u2190sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h\n\n/-- The same point subtracted from two points produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_left_cancel_iff {p1 p2 p : P} : (p1 -\u1d65 p) = p2 -\u1d65 p \u2194 p1 = p2 :=\n\u27e8vsub_left_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting the point `p` is an injective function. -/\nlemma vsub_left_injective (p : P) : function.injective ((-\u1d65 p) : P \u2192 G) :=\n\u03bb p2 p3, vsub_left_cancel\n\n/-- If subtracting two points from the same point produces equal\nresults, those points are equal. -/\nlemma vsub_right_cancel {p1 p2 p : P} (h : p -\u1d65 p1 = p -\u1d65 p2) : p1 = p2 :=\nbegin\n  refine vadd_left_cancel (p -\u1d65 p2) _,\n  rw [vsub_vadd, \u2190 h, vsub_vadd]\nend\n\n/-- Subtracting two points from the same point produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_right_cancel_iff {p1 p2 p : P} : p -\u1d65 p1 = p -\u1d65 p2 \u2194 p1 = p2 :=\n\u27e8vsub_right_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting a point from the point `p` is an injective\nfunction. -/\nlemma vsub_right_injective (p : P) : function.injective ((-\u1d65) p : P \u2192 G) :=\n\u03bb p2 p3, vsub_right_cancel\n\nend general\n\nsection comm\n\nvariables {G : Type*} {P : Type*} [add_comm_group G] [add_torsor G P]\n\ninclude G\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_left (p1 p2 p3 : P) :\n  (p3 -\u1d65 p2) - (p3 -\u1d65 p1) = (p1 -\u1d65 p2) :=\nby rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]\n\n@[simp] lemma vadd_vsub_vadd_cancel_left (v : G) (p1 p2 : P) :\n  (v +\u1d65 p1) -\u1d65 (v +\u1d65 p2) = p1 -\u1d65 p2 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel']\n\nlemma vsub_vadd_comm (p1 p2 p3 : P) : (p1 -\u1d65 p2 : G) +\u1d65 p3 = p3 -\u1d65 p2 +\u1d65 p1 :=\nbegin\n  rw [\u2190@vsub_eq_zero_iff_eq G, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub],\n  simp\nend\n\nlemma vadd_eq_vadd_iff_sub_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 v\u2082 - v\u2081 = p\u2081 -\u1d65 p\u2082 :=\nby rw [vadd_eq_vadd_iff_neg_add_eq_vsub, neg_add_eq_sub]\n\nlemma vsub_sub_vsub_comm (p\u2081 p\u2082 p\u2083 p\u2084 : P) :\n  (p\u2081 -\u1d65 p\u2082) - (p\u2083 -\u1d65 p\u2084) = (p\u2081 -\u1d65 p\u2083) - (p\u2082 -\u1d65 p\u2084) :=\nby rw [\u2190 vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub]\n\nend comm\n\nnamespace prod\n\nvariables {G : Type*} {P : Type*} {G' : Type*} {P' : Type*} [add_group G] [add_group G']\n  [add_torsor G P] [add_torsor G' P']\n\ninstance : add_torsor (G \u00d7 G') (P \u00d7 P') :=\n{ vadd := \u03bb v p, (v.1 +\u1d65 p.1, v.2 +\u1d65 p.2),\n  zero_vadd := \u03bb p, by simp,\n  add_vadd := by simp [add_vadd],\n  vsub := \u03bb p\u2081 p\u2082, (p\u2081.1 -\u1d65 p\u2082.1, p\u2081.2 -\u1d65 p\u2082.2),\n  nonempty := prod.nonempty,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, show (p\u2081.1 -\u1d65 p\u2082.1 +\u1d65 p\u2082.1, _) = p\u2081, by simp,\n  vadd_vsub' := \u03bb v p, show (v.1 +\u1d65 p.1 -\u1d65 p.1, v.2 +\u1d65 p.2 -\u1d65 p.2)  =v, by simp }\n\n@[simp] lemma fst_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).1 = v.1 +\u1d65 p.1 := rfl\n@[simp] lemma snd_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).2 = v.2 +\u1d65 p.2 := rfl\n@[simp] lemma mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') :\n  (v, v') +\u1d65 (p, p') = (v +\u1d65 p, v' +\u1d65 p') := rfl\n\n@[simp] lemma fst_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').1 = p\u2081.1 -\u1d65 p\u2082.1 := rfl\n@[simp] lemma snd_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').2 = p\u2081.2 -\u1d65 p\u2082.2 := rfl\n@[simp] lemma mk_vsub_mk (p\u2081 p\u2082 : P) (p\u2081' p\u2082' : P') :\n  ((p\u2081, p\u2081') -\u1d65 (p\u2082, p\u2082') : G \u00d7 G') = (p\u2081 -\u1d65 p\u2082, p\u2081' -\u1d65 p\u2082') := rfl\n\nend prod\n\nnamespace pi\n\nuniverses u v w\nvariables {I : Type u} {fg : I \u2192 Type v} [\u2200 i, add_group (fg i)] {fp : I \u2192 Type w}\n\nopen add_action add_torsor\n\n/-- A product of `add_torsor`s is an `add_torsor`. -/\ninstance [T : \u2200 i, add_torsor (fg i) (fp i)] : add_torsor (\u03a0 i, fg i) (\u03a0 i, fp i) :=\n{ vadd := \u03bb g p, \u03bb i, g i +\u1d65 p i,\n  zero_vadd := \u03bb p, funext $ \u03bb i, zero_vadd (fg i) (p i),\n  add_vadd := \u03bb g\u2081 g\u2082 p, funext $ \u03bb i, add_vadd (g\u2081 i) (g\u2082 i) (p i),\n  vsub := \u03bb p\u2081 p\u2082, \u03bb i, p\u2081 i -\u1d65 p\u2082 i,\n  nonempty := \u27e8\u03bb i, classical.choice (T i).nonempty\u27e9,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, funext $ \u03bb i, vsub_vadd (p\u2081 i) (p\u2082 i),\n  vadd_vsub' := \u03bb g p, funext $ \u03bb i, vadd_vsub (g i) (p i) }\n\nend pi\n\nnamespace equiv\n\nvariables {G : Type*} {P : Type*} [add_group G] [add_torsor G P]\n\ninclude G\n\n/-- `v \u21a6 v +\u1d65 p` as an equivalence. -/\ndef vadd_const (p : P) : G \u2243 P :=\n{ to_fun := \u03bb v, v +\u1d65 p,\n  inv_fun := \u03bb p', p' -\u1d65 p,\n  left_inv := \u03bb v, vadd_vsub _ _,\n  right_inv := \u03bb p', vsub_vadd _ _ }\n\n@[simp] lemma coe_vadd_const (p : P) : \u21d1(vadd_const p) = \u03bb v, v+\u1d65 p := rfl\n\n@[simp] lemma coe_vadd_const_symm (p : P) : \u21d1(vadd_const p).symm = \u03bb p', p' -\u1d65 p := rfl\n\n/-- `p' \u21a6 p -\u1d65 p'` as an equivalence. -/\ndef const_vsub (p : P) : P \u2243 G :=\n{ to_fun := (-\u1d65) p,\n  inv_fun := \u03bb v, -v +\u1d65 p,\n  left_inv := \u03bb p', by simp,\n  right_inv := \u03bb v, by simp [vsub_vadd_eq_vsub_sub] }\n\n@[simp] lemma coe_const_vsub (p : P) : \u21d1(const_vsub p) = (-\u1d65) p := rfl\n\n@[simp] lemma coe_const_vsub_symm (p : P) : \u21d1(const_vsub p).symm = \u03bb v, -v +\u1d65 p := rfl\n\nvariables (P)\n\n/-- The permutation given by `p \u21a6 v +\u1d65 p`. -/\ndef const_vadd (v : G) : equiv.perm P :=\n{ to_fun := (+\u1d65) v,\n  inv_fun := (+\u1d65) (-v),\n  left_inv := \u03bb p, by simp [vadd_vadd],\n  right_inv := \u03bb p, by simp [vadd_vadd] }\n\n@[simp] lemma coe_const_vadd (v : G) : \u21d1(const_vadd P v) = (+\u1d65) v := rfl\n\nvariable (G)\n\n@[simp] lemma const_vadd_zero : const_vadd P (0:G) = 1 := ext $ zero_vadd G\n\nvariable {G}\n\n@[simp] lemma const_vadd_add (v\u2081 v\u2082 : G) :\n  const_vadd P (v\u2081 + v\u2082) = const_vadd P v\u2081 * const_vadd P v\u2082 :=\next $ add_vadd v\u2081 v\u2082\n\n/-- `equiv.const_vadd` as a homomorphism from `multiplicative G` to `equiv.perm P` -/\ndef const_vadd_hom : multiplicative G \u2192* equiv.perm P :=\n{ to_fun := \u03bb v, const_vadd P v.to_add,\n  map_one' := const_vadd_zero G P,\n  map_mul' := const_vadd_add P }\n\nvariable {P}\n\nopen function\n\n/-- Point reflection in `x` as a permutation. -/\ndef point_reflection (x : P) : perm P := (const_vsub x).trans (vadd_const x)\n\nlemma point_reflection_apply (x y : P) : point_reflection x y = x -\u1d65 y +\u1d65 x := rfl\n\n@[simp] lemma point_reflection_symm (x : P) : (point_reflection x).symm = point_reflection x :=\next $ by simp [point_reflection]\n\n@[simp] lemma point_reflection_self (x : P) : point_reflection x x = x := vsub_vadd _ _\n\nlemma point_reflection_involutive (x : P) : involutive (point_reflection x : P \u2192 P) :=\n\u03bb y, (equiv.apply_eq_iff_eq_symm_apply _).2 $ by rw point_reflection_symm\n\n/-- `x` is the only fixed point of `point_reflection x`. This lemma requires\n`x + x = y + y \u2194 x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/\nlemma point_reflection_fixed_iff_of_injective_bit0 {x y : P} (h : injective (bit0 : G \u2192 G)) :\n  point_reflection x y = y \u2194 y = x :=\nby rw [point_reflection_apply, eq_comm, eq_vadd_iff_vsub_eq, \u2190 neg_vsub_eq_vsub_rev,\n  neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero, h.eq_iff, vsub_eq_zero_iff_eq, eq_comm]\n\nomit G\n\nlemma injective_point_reflection_left_of_injective_bit0 {G P : Type*} [add_comm_group G]\n  [add_torsor G P] (h : injective (bit0 : G \u2192 G)) (y : P) :\n  injective (\u03bb x : P, point_reflection x y) :=\n\u03bb x\u2081 x\u2082 (hy : point_reflection x\u2081 y = point_reflection x\u2082 y),\n  by rwa [point_reflection_apply, point_reflection_apply, vadd_eq_vadd_iff_sub_eq_vsub,\n    vsub_sub_vsub_cancel_right, \u2190 neg_vsub_eq_vsub_rev, neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero,\n    h.eq_iff, vsub_eq_zero_iff_eq] at hy\n\nend equiv\n\nlemma add_torsor.subsingleton_iff (G P : Type*) [add_group G] [add_torsor G P] :\n  subsingleton G \u2194 subsingleton P :=\nbegin\n  inhabit P,\n  exact (equiv.vadd_const default).subsingleton_congr,\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/add_torsor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7437938450494953}}
{"text": "import game.world3.level9 -- hide\nimport mynat.pow -- new import\nnamespace mynat -- hide\n\n\n/- Axiom : pow_zero (a : mynat) :\na ^ 0 = 1\n-/\n\n/- Axiom : pow_succ (a b : mynat) :\na ^ succ(b) = a ^ b * a\n-/\n\n/- \n\n# Power World\n\nA new world with seven levels. And a new import!\nThis import gives you the power to make powers of your\nnatural numbers. It is defined by recursion, just like addition and multiplication.\nHere are the two new axioms:\n\n  * `pow_zero (a : mynat) : a ^ 0 = 1`\n  * `pow_succ (a b : mynat) : a ^ succ(b) = a ^ b * a`\n\nThe power function has various relations to addition and multiplication.\nIf you have gone through levels 1--6 of addition world and levels 1--9 of\nmultiplication world, you should have no trouble with this world:\nThe usual tactics `induction`, `rw` and `refl` should see you through.\nYou might want to fiddle with the\ndrop-down menus on the left so you can see which theorems of Power World\nyou have proved at any given time. Addition and multiplication -- we\nhave a solid API for them now, i.e. if you need something about addition\nor multiplication, it's probably already in the library we have built.\nCollectibles are indication that we are proving the right things.\n\nThe levels in this world were designed by Sian Carey, a UROP student\nat Imperial College London, funded by a Mary Lister McCammon Fellowship,\nin the summer of 2019. Thanks Sian!\n\n## Level 1: `zero_pow_zero`\n-/\n\n/- Lemma\n$0 ^ 0 = 1$.\n-/\nlemma zero_pow_zero : (0 : mynat) ^ (0 : mynat) = 1 :=\nbegin [nat_num_game]\n  rw pow_zero,\n  refl,\n\n\nend\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world4/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7437938351957575}}
{"text": "/-\nCopyright (c) 2022 Matej Penciak. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Matej Penciak, Moritz Doll, Fabien Clery\n\n! This file was ported from Lean 3 source module linear_algebra.symplectic_group\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Matrix.NonsingularInverse\n\n/-!\n# The Symplectic Group\n\nThis file defines the symplectic group and proves elementary properties.\n\n## Main Definitions\n\n`matrix.J`: the canonical `2n \u00d7 2n` skew-symmetric matrix\n`symplectic_group`: the group of symplectic matrices\n\n## TODO\n* Every symplectic matrix has determinant 1.\n* For `n = 1` the symplectic group coincides with the special linear group.\n-/\n\n\nopen Matrix\n\nvariable {l R : Type _}\n\nnamespace Matrix\n\nvariable (l) [DecidableEq l] (R) [CommRing R]\n\nsection JMatrixLemmas\n\n/-- The matrix defining the canonical skew-symmetric bilinear form. -/\ndef j : Matrix (Sum l l) (Sum l l) R :=\n  Matrix.fromBlocks 0 (-1) 1 0\n#align matrix.J Matrix.j\n\n@[simp]\ntheorem j_transpose : (j l R)\u1d40 = -j l R :=\n  by\n  rw [J, from_blocks_transpose, \u2190 neg_one_smul R (from_blocks _ _ _ _), from_blocks_smul,\n    Matrix.transpose_zero, Matrix.transpose_one, transpose_neg]\n  simp [from_blocks]\n#align matrix.J_transpose Matrix.j_transpose\n\nvariable [Fintype l]\n\ntheorem j_squared : j l R \u2b1d j l R = -1 :=\n  by\n  rw [J, from_blocks_multiply]\n  simp only [Matrix.zero_mul, Matrix.neg_mul, zero_add, neg_zero, Matrix.one_mul, add_zero]\n  rw [\u2190 neg_zero, \u2190 Matrix.fromBlocks_neg, \u2190 from_blocks_one]\n#align matrix.J_squared Matrix.j_squared\n\ntheorem j_inv : (j l R)\u207b\u00b9 = -j l R :=\n  by\n  refine' Matrix.inv_eq_right_inv _\n  rw [Matrix.mul_neg, J_squared]\n  exact neg_neg 1\n#align matrix.J_inv Matrix.j_inv\n\ntheorem j_det_mul_j_det : det (j l R) * det (j l R) = 1 :=\n  by\n  rw [\u2190 det_mul, J_squared]\n  rw [\u2190 one_smul R (-1 : Matrix _ _ R)]\n  rw [smul_neg, \u2190 neg_smul, det_smul]\n  simp only [Fintype.card_sum, det_one, mul_one]\n  apply Even.neg_one_pow\n  exact even_add_self _\n#align matrix.J_det_mul_J_det Matrix.j_det_mul_j_det\n\ntheorem isUnit_det_j : IsUnit (det (j l R)) :=\n  isUnit_iff_exists_inv.mpr \u27e8det (j l R), j_det_mul_j_det _ _\u27e9\n#align matrix.is_unit_det_J Matrix.isUnit_det_j\n\nend JMatrixLemmas\n\nvariable [Fintype l]\n\n/-- The group of symplectic matrices over a ring `R`. -/\ndef symplecticGroup : Submonoid (Matrix (Sum l l) (Sum l l) R)\n    where\n  carrier := { A | A \u2b1d j l R \u2b1d A\u1d40 = j l R }\n  mul_mem' := by\n    intro a b ha hb\n    simp only [mul_eq_mul, Set.mem_setOf_eq, transpose_mul] at *\n    rw [\u2190 Matrix.mul_assoc, a.mul_assoc, a.mul_assoc, hb]\n    exact ha\n  one_mem' := by simp\n#align matrix.symplectic_group Matrix.symplecticGroup\n\nend Matrix\n\nnamespace SymplecticGroup\n\nvariable {l} {R} [DecidableEq l] [Fintype l] [CommRing R]\n\nopen Matrix\n\ntheorem mem_iff {A : Matrix (Sum l l) (Sum l l) R} :\n    A \u2208 symplecticGroup l R \u2194 A \u2b1d j l R \u2b1d A\u1d40 = j l R := by simp [symplectic_group]\n#align symplectic_group.mem_iff SymplecticGroup.mem_iff\n\ninstance coeMatrix : Coe (symplecticGroup l R) (Matrix (Sum l l) (Sum l l) R) := by infer_instance\n#align symplectic_group.coe_matrix SymplecticGroup.coeMatrix\n\nsection SymplecticJ\n\nvariable (l) (R)\n\ntheorem j_mem : j l R \u2208 symplecticGroup l R :=\n  by\n  rw [mem_iff, J, from_blocks_multiply, from_blocks_transpose, from_blocks_multiply]\n  simp\n#align symplectic_group.J_mem SymplecticGroup.j_mem\n\n/-- The canonical skew-symmetric matrix as an element in the symplectic group. -/\ndef symJ : symplecticGroup l R :=\n  \u27e8j l R, j_mem l R\u27e9\n#align symplectic_group.sym_J SymplecticGroup.symJ\n\nvariable {l} {R}\n\n@[simp]\ntheorem coe_j : \u2191(symJ l R) = j l R :=\n  rfl\n#align symplectic_group.coe_J SymplecticGroup.coe_j\n\nend SymplecticJ\n\nvariable {R} {A : Matrix (Sum l l) (Sum l l) R}\n\ntheorem neg_mem (h : A \u2208 symplecticGroup l R) : -A \u2208 symplecticGroup l R :=\n  by\n  rw [mem_iff] at h\u22a2\n  simp [h]\n#align symplectic_group.neg_mem SymplecticGroup.neg_mem\n\ntheorem symplectic_det (hA : A \u2208 symplecticGroup l R) : IsUnit <| det A :=\n  by\n  rw [isUnit_iff_exists_inv]\n  use A.det\n  refine' (is_unit_det_J l R).mul_left_cancel _\n  rw [mul_one]\n  rw [mem_iff] at hA\n  apply_fun det  at hA\n  simp only [det_mul, det_transpose] at hA\n  rw [mul_comm A.det, mul_assoc] at hA\n  exact hA\n#align symplectic_group.symplectic_det SymplecticGroup.symplectic_det\n\ntheorem transpose_mem (hA : A \u2208 symplecticGroup l R) : A\u1d40 \u2208 symplecticGroup l R :=\n  by\n  rw [mem_iff] at hA\u22a2\n  rw [transpose_transpose]\n  have huA := symplectic_det hA\n  have huAT : IsUnit A\u1d40.det := by\n    rw [Matrix.det_transpose]\n    exact huA\n  calc\n    A\u1d40 \u2b1d J l R \u2b1d A = (-A\u1d40) \u2b1d (J l R)\u207b\u00b9 \u2b1d A := by\n      rw [J_inv]\n      simp\n    _ = (-A\u1d40) \u2b1d (A \u2b1d J l R \u2b1d A\u1d40)\u207b\u00b9 \u2b1d A := by rw [hA]\n    _ = (-A\u1d40 \u2b1d (A\u1d40\u207b\u00b9 \u2b1d (J l R)\u207b\u00b9)) \u2b1d A\u207b\u00b9 \u2b1d A := by\n      simp only [Matrix.mul_inv_rev, Matrix.mul_assoc, Matrix.neg_mul]\n    _ = -(J l R)\u207b\u00b9 := by\n      rw [mul_nonsing_inv_cancel_left _ _ huAT, nonsing_inv_mul_cancel_right _ _ huA]\n    _ = J l R := by simp [J_inv]\n    \n#align symplectic_group.transpose_mem SymplecticGroup.transpose_mem\n\n@[simp]\ntheorem transpose_mem_iff : A\u1d40 \u2208 symplecticGroup l R \u2194 A \u2208 symplecticGroup l R :=\n  \u27e8fun hA => by simpa using transpose_mem hA, transpose_mem\u27e9\n#align symplectic_group.transpose_mem_iff SymplecticGroup.transpose_mem_iff\n\ntheorem mem_iff' : A \u2208 symplecticGroup l R \u2194 A\u1d40 \u2b1d j l R \u2b1d A = j l R := by\n  rw [\u2190 transpose_mem_iff, mem_iff, transpose_transpose]\n#align symplectic_group.mem_iff' SymplecticGroup.mem_iff'\n\ninstance : Inv (symplecticGroup l R)\n    where inv A :=\n    \u27e8(-j l R) \u2b1d (A : Matrix (Sum l l) (Sum l l) R)\u1d40 \u2b1d j l R,\n      mul_mem (mul_mem (neg_mem <| j_mem _ _) <| transpose_mem A.2) <| j_mem _ _\u27e9\n\ntheorem coe_inv (A : symplecticGroup l R) : (\u2191A\u207b\u00b9 : Matrix _ _ _) = (-j l R) \u2b1d (\u2191A)\u1d40 \u2b1d j l R :=\n  rfl\n#align symplectic_group.coe_inv SymplecticGroup.coe_inv\n\ntheorem inv_left_mul_aux (hA : A \u2208 symplecticGroup l R) : -j l R \u2b1d A\u1d40 \u2b1d j l R \u2b1d A = 1 :=\n  calc\n    -j l R \u2b1d A\u1d40 \u2b1d j l R \u2b1d A = (-j l R) \u2b1d (A\u1d40 \u2b1d j l R \u2b1d A) := by\n      simp only [Matrix.mul_assoc, Matrix.neg_mul]\n    _ = (-j l R) \u2b1d j l R := by\n      rw [mem_iff'] at hA\n      rw [hA]\n    _ = (-1 : R) \u2022 j l R \u2b1d j l R := by simp only [Matrix.neg_mul, neg_smul, one_smul]\n    _ = (-1 : R) \u2022 -1 := by rw [J_squared]\n    _ = 1 := by simp only [neg_smul_neg, one_smul]\n    \n#align symplectic_group.inv_left_mul_aux SymplecticGroup.inv_left_mul_aux\n\ntheorem coe_inv' (A : symplecticGroup l R) : (\u2191A\u207b\u00b9 : Matrix (Sum l l) (Sum l l) R) = A\u207b\u00b9 :=\n  by\n  refine' (coe_inv A).trans (inv_eq_left_inv _).symm\n  simp [inv_left_mul_aux, coe_inv]\n#align symplectic_group.coe_inv' SymplecticGroup.coe_inv'\n\ntheorem inv_eq_symplectic_inv (A : Matrix (Sum l l) (Sum l l) R) (hA : A \u2208 symplecticGroup l R) :\n    A\u207b\u00b9 = (-j l R) \u2b1d A\u1d40 \u2b1d j l R :=\n  inv_eq_left_inv (by simp only [Matrix.neg_mul, inv_left_mul_aux hA])\n#align symplectic_group.inv_eq_symplectic_inv SymplecticGroup.inv_eq_symplectic_inv\n\ninstance : Group (symplecticGroup l R) :=\n  { SymplecticGroup.hasInv, Submonoid.toMonoid _ with\n    mul_left_inv := fun A => by\n      apply Subtype.ext\n      simp only [Submonoid.coe_one, Submonoid.coe_mul, Matrix.neg_mul, coe_inv]\n      rw [Matrix.mul_eq_mul, Matrix.neg_mul]\n      exact inv_left_mul_aux A.2 }\n\nend SymplecticGroup\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/SymplecticGroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7437938330821665}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\nBorel (measurable) space -- the smallest \u03c3-algebra generated by open sets\n\nIt would be nice to encode this in the topological space type class, i.e. each topological space\ncarries a measurable space, the Borel space. This would be similar how each uniform space carries a\ntopological space. The idea is to allow definitional equality for product instances.\nWe would like to have definitional equality for\n\n  borel t\u2081 \u00d7 borel t\u2082 = borel (t\u2081 \u00d7 t\u2082)\n\nUnfortunately, this only holds if t\u2081 and t\u2082 are second-countable topologies.\n-/\nimport analysis.measure_theory.measurable_space analysis.real\n\nopen classical set lattice real\nlocal attribute [instance] prop_decidable\n\nuniverses u v w x y\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} {\u03b9 : Sort y} {s t u : set \u03b1}\n\nnamespace measure_theory\nopen measurable_space topological_space\n\n@[instance] def borel (\u03b1 : Type u) [topological_space \u03b1] : measurable_space \u03b1 :=\ngenerate_from {s : set \u03b1 | is_open s}\n\nlemma borel_eq_generate_from_of_subbasis {s : set (set \u03b1)}\n  [t : topological_space \u03b1] [second_countable_topology \u03b1] (hs : t = generate_from s) :\n  borel \u03b1 = generate_from s :=\nle_antisymm\n  (generate_from_le $ assume u (hu : t.is_open u),\n    begin\n      rw [hs] at hu,\n      induction hu,\n      case generate_open.basic : u hu\n      { exact generate_measurable.basic u hu },\n      case generate_open.univ\n      { exact @is_measurable_univ \u03b1 (generate_from s) },\n      case generate_open.inter : s\u2081 s\u2082 _ _ hs\u2081 hs\u2082\n      { exact @is_measurable.inter \u03b1 (generate_from s) _ _ hs\u2081 hs\u2082 },\n      case generate_open.sUnion : f hf ih {\n        rcases is_open_sUnion_countable _ f (by rwa hs) with \u27e8v, hv, vf, vu\u27e9,\n        rw \u2190 vu,\n        exact @is_measurable.sUnion \u03b1 (generate_from s) _ hv\n          (\u03bb x xv, ih _ (vf xv)) }\n    end)\n  (generate_from_le $ assume u hu, generate_measurable.basic _ $\n    show t.is_open u, by rw [hs]; exact generate_open.basic _ hu)\n\nlemma borel_comap {f : \u03b1 \u2192 \u03b2} {t : topological_space \u03b2} :\n  @borel \u03b1 (t.induced f) = (@borel \u03b2 t).comap f :=\ncalc @borel \u03b1 (t.induced f) =\n    measurable_space.generate_from (preimage f '' {s | is_open s }) :\n      congr_arg measurable_space.generate_from $ set.ext $ assume s : set \u03b1,\n      show (t.induced f).is_open s \u2194 s \u2208 preimage f '' {s | is_open s},\n        by simp [topological_space.induced, set.image, eq_comm]; refl\n  ... = (@borel \u03b2 t).comap f : comap_generate_from.symm\n\nsection\nvariables [topological_space \u03b1]\n\nlemma is_measurable_of_is_open : is_open s \u2192 is_measurable s := generate_measurable.basic s\n\nlemma is_measurable_interior : is_measurable (interior s) :=\nis_measurable_of_is_open is_open_interior\n\nlemma is_measurable_of_is_closed (h : is_closed s) : is_measurable s :=\nis_measurable.compl_iff.1 $ is_measurable_of_is_open h\n\nlemma is_measurable_closure : is_measurable (closure s) :=\nis_measurable_of_is_closed is_closed_closure\n\nlemma measurable_of_continuous [topological_space \u03b2] {f : \u03b1 \u2192 \u03b2} (h : continuous f) : measurable f :=\nmeasurable_generate_from $ assume t ht, is_measurable_of_is_open $ h t ht\n\nlemma borel_prod_le [topological_space \u03b2] :\n  prod.measurable_space \u2264 borel (\u03b1 \u00d7 \u03b2) :=\nsup_le\n  (comap_le_iff_le_map.mpr $ measurable_of_continuous continuous_fst)\n  (comap_le_iff_le_map.mpr $ measurable_of_continuous continuous_snd)\n\nlemma borel_prod [second_countable_topology \u03b1] [topological_space \u03b2] [second_countable_topology \u03b2] :\n  prod.measurable_space = borel (\u03b1 \u00d7 \u03b2) :=\nlet \u27e8a, ha\u2081, ha\u2082, ha\u2083, ha\u2084, ha\u2085\u27e9 := @is_open_generated_countable_inter \u03b1 _ _ in\nlet \u27e8b, hb\u2081, hb\u2082, hb\u2083, hb\u2084, hb\u2085\u27e9 := @is_open_generated_countable_inter \u03b2 _ _ in\nle_antisymm borel_prod_le begin\n    have : prod.topological_space = generate_from {g | \u2203u\u2208a, \u2203v\u2208b, g = set.prod u v},\n    { rw [ha\u2085, hb\u2085], exact prod_generate_from_generate_from_eq ha\u2084 hb\u2084 },\n    rw [borel_eq_generate_from_of_subbasis this],\n    exact generate_from_le (assume p \u27e8u, hu, v, hv, eq\u27e9,\n      have hu : is_open u, by rw [ha\u2085]; exact generate_open.basic _ hu,\n      have hv : is_open v, by rw [hb\u2085]; exact generate_open.basic _ hv,\n      eq.symm \u25b8 is_measurable_set_prod (is_measurable_of_is_open hu) (is_measurable_of_is_open hv))\nend\n\nlemma measurable_of_continuous2\n  [topological_space \u03b1] [second_countable_topology \u03b1]\n  [topological_space \u03b2] [second_countable_topology \u03b2]\n  [topological_space \u03b3] [measurable_space \u03b4] {f : \u03b4 \u2192 \u03b1} {g : \u03b4 \u2192 \u03b2} {c : \u03b1 \u2192 \u03b2 \u2192 \u03b3}\n  (h : continuous (\u03bbp:\u03b1\u00d7\u03b2, c p.1 p.2)) (hf : measurable f) (hg : measurable g) :\n  measurable (\u03bba, c (f a) (g a)) :=\nshow measurable ((\u03bbp:\u03b1\u00d7\u03b2, c p.1 p.2) \u2218 (\u03bba, (f a, g a))),\nbegin\n  apply measurable.comp,\n  { rw \u2190 borel_prod,\n    exact measurable_prod_mk hf hg },\n  { exact measurable_of_continuous h }\nend\n\nlemma measurable_add\n  [add_monoid \u03b1] [topological_add_monoid \u03b1] [second_countable_topology \u03b1] [measurable_space \u03b2]\n  {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} : measurable f \u2192 measurable g \u2192 measurable (\u03bba, f a + g a) :=\nmeasurable_of_continuous2 continuous_add'\n\nlemma measurable_neg\n  [add_group \u03b1] [topological_add_group \u03b1] [measurable_space \u03b2] {f : \u03b2 \u2192 \u03b1}\n  (hf : measurable f) : measurable (\u03bba, - f a) :=\nhf.comp (measurable_of_continuous continuous_neg')\n\nlemma measurable_sub\n  [add_group \u03b1] [topological_add_group \u03b1] [second_countable_topology \u03b1] [measurable_space \u03b2]\n  {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} : measurable f \u2192 measurable g \u2192 measurable (\u03bba, f a - g a) :=\nmeasurable_of_continuous2 continuous_sub'\n\nlemma measurable_mul\n  [monoid \u03b1] [topological_monoid \u03b1] [second_countable_topology \u03b1] [measurable_space \u03b2]\n  {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} : measurable f \u2192 measurable g \u2192 measurable (\u03bba, f a * g a) :=\nmeasurable_of_continuous2 continuous_mul'\n\nsection ordered_topology\nvariables [linear_order \u03b1] [topological_space \u03b1] [ordered_topology \u03b1] {a b c : \u03b1}\n\nlemma is_measurable_Ioo : is_measurable (Ioo a b) := is_measurable_of_is_open is_open_Ioo\n\nlemma is_measurable_Iio : is_measurable (Iio a) := is_measurable_of_is_open is_open_Iio\n\nlemma is_measurable_Ico : is_measurable (Ico a b) :=\n(is_measurable_of_is_closed $ is_closed_le continuous_const continuous_id).inter\n  is_measurable_Iio\n\nend ordered_topology\n\nend\n\nend measure_theory\n\nnamespace real\nopen measure_theory measurable_space\n\nlemma borel_eq_generate_from_Ioo_rat :\n  borel \u211d = generate_from (\u22c3(a b : \u211a) (h : a < b), {Ioo a b}) :=\nborel_eq_generate_from_of_subbasis is_topological_basis_Ioo_rat.2.2\n\nlemma borel_eq_generate_from_Iio_rat :\n  borel \u211d = generate_from (\u22c3a:\u211a, {Iio a}) :=\nbegin\n  let g, swap,\n  apply le_antisymm (_ : _ \u2264 g) (measurable_space.generate_from_le (\u03bb t, _)),\n  { rw borel_eq_generate_from_Ioo_rat,\n    refine generate_from_le (\u03bb t, _),\n    simp only [mem_Union], rintro \u27e8a, b, h, rfl|\u27e8\u27e8\u27e9\u27e9\u27e9,\n    rw (set.ext (\u03bb x, _) : Ioo (a:\u211d) b = (\u22c3c>a, - Iio c) \u2229 Iio b),\n    { have hg : \u2200q:\u211a, g.is_measurable (Iio q) :=\n        \u03bb q, generate_measurable.basic _ (by simp; exact \u27e8_, rfl\u27e9),\n      refine @is_measurable.inter _ g _ _ _ (hg _),\n      refine @is_measurable.bUnion _ _ g _ _ (countable_encodable _) (\u03bb c h, _),\n      exact @is_measurable.compl _ _ g (hg _) },\n    { simp [Ioo, Iio],\n      refine and_congr _ iff.rfl,\n      exact \u27e8\u03bb h,\n        let \u27e8c, ac, cx\u27e9 := exists_rat_btwn h in\n        \u27e8c, rat.cast_lt.1 ac, le_of_lt cx\u27e9,\n       \u03bb \u27e8c, ac, cx\u27e9, lt_of_lt_of_le (rat.cast_lt.2 ac) cx\u27e9 } },\n  { simp, rintro r rfl,\n    exact is_measurable_of_is_open (is_open_gt' _) }\nend\n\nend real\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/analysis/measure_theory/borel_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7437938306828888}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que en los ret\u00edculos se verifica que\n--     (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z)\n-- ----------------------------------------------------------------------\n\nimport order.lattice\n\nvariables {\u03b1 : Type*} [lattice \u03b1]\nvariables x y z : \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\nbegin\n  have h1 : (x \u2293 y) \u2293 z \u2264 x \u2293 (y \u2293 z),\n    { have h1a : (x \u2293 y) \u2293 z \u2264 x, calc\n        (x \u2293 y) \u2293 z \u2264 x \u2293 y : by exact inf_le_left\n                ... \u2264 x     : by exact inf_le_left,\n      have h1b : (x \u2293 y) \u2293 z \u2264 y \u2293 z,\n        { have h1b1 : (x \u2293 y) \u2293 z \u2264 y, calc\n            (x \u2293 y) \u2293 z \u2264 x \u2293 y : by exact inf_le_left\n                    ... \u2264 y     : by exact inf_le_right,\n          have h1b2 : (x \u2293 y) \u2293 z \u2264 z,\n            by exact inf_le_right,\n          show (x \u2293 y) \u2293 z \u2264 y \u2293 z,\n            by exact le_inf h1b1 h1b2, },\n      show (x \u2293 y) \u2293 z \u2264 x \u2293 (y \u2293 z),\n        by exact le_inf h1a h1b, },\n  have h2 : x \u2293 (y \u2293 z) \u2264 (x \u2293 y) \u2293 z,\n    { have h2a : x \u2293 (y \u2293 z) \u2264 x \u2293 y,\n        { have h2a1 : x \u2293 (y \u2293 z) \u2264 x,\n            by exact inf_le_left,\n          have h2a2 : x \u2293 (y \u2293 z) \u2264 y, calc\n            x \u2293 (y \u2293 z) \u2264 y \u2293 z : by exact inf_le_right\n                    ... \u2264 y     : by exact inf_le_left,\n          show x \u2293 (y \u2293 z) \u2264 x \u2293 y,\n            by exact le_inf h2a1 h2a2, },\n      have h2b : x \u2293 (y \u2293 z) \u2264 z, calc\n        x \u2293 (y \u2293 z) \u2264 y \u2293 z : by exact inf_le_right\n                ... \u2264 z     : by exact inf_le_right,\n      show x \u2293 (y \u2293 z) \u2264 (x \u2293 y) \u2293 z,\n        by exact le_inf h2a h2b, },\n  show (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z),\n    by exact le_antisymm h1 h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\nbegin\n  apply le_antisymm,\n  { apply le_inf,\n    { apply inf_le_of_left_le inf_le_left, },\n    { apply le_inf (inf_le_of_left_le inf_le_right) inf_le_right}},\n  {apply le_inf,\n    { apply le_inf inf_le_left (inf_le_of_right_le inf_le_left), },\n    { apply inf_le_of_right_le inf_le_right, },},\nend\n\n-- Su desarrollo es\n--\n-- \u22a2 x \u2293 y \u2293 z = x \u2293 (y \u2293 z)\n--    apply le_antisymm,\n-- \u22a2 x \u2293 y \u2293 z \u2264 x \u2293 (y \u2293 z)\n-- |   { apply le_inf,\n-- | \u22a2 x \u2293 y \u2293 z \u2264 x\n-- | |     { apply inf_le_left_of_le inf_le_left },\n-- | \u22a2 x \u2293 y \u2293 z \u2264 y \u2293 z\n-- | |     { apply le_inf (inf_le_left_of_le inf_le_right) inf_le_right}},\n-- \u22a2 x \u2293 (y \u2293 z) \u2264 x \u2293 y \u2293 z\n-- |   {apply le_inf,\n-- | \u22a2 x \u2293 (y \u2293 z) \u2264 x \u2293 y\n-- | |     { apply le_inf inf_le_left (inf_le_right_of_le inf_le_left)},\n-- | \u22a2 x \u2293 (y \u2293 z) \u2264 z\n--      { apply inf_le_right_of_le inf_le_right, },},\n-- no goals\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\nle_antisymm\n  (le_inf\n    (inf_le_of_left_le inf_le_left)\n    (le_inf (inf_le_of_left_le inf_le_right) inf_le_right))\n  (le_inf\n    (le_inf inf_le_left (inf_le_of_right_le inf_le_left))\n    (inf_le_of_right_le inf_le_right))\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\n-- by library_search\ninf_assoc\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\n-- by hint\nby finish\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Basicos/Asociatividad_del_infimo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181418, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7437938303972016}}
{"text": "import tactic\n\n-- Use the definition of an irreducible element.\ndef prime (n: \u2115) : Prop := 1 \u2260 n \u2227 \u2200 a b, a * b = n \u2192 a = 1 \u2228 b = 1\ndef composite (n : \u2115) : Prop := \u00ac prime n\n\n-- 3.1 Products of primes\n\ndef constructive_composite (n: \u2115) : Prop :=\n  2 \u2264 n \u2192 \u2203 a b,\n    a * b = n \u2227\n    a < n \u2227 b < n \u2227\n    2 \u2264 a \u2227 2 \u2264 b\n\nlemma constructive_composite_of_composite {n: \u2115} (hcomp: composite n)\n  : constructive_composite n :=\nbegin\n  intro two_le_n,\n  unfold composite prime at hcomp,\n  push_neg at hcomp,\n  obtain \u27e8a, b, \u27e8prod, a_ne_1, b_ne_1\u27e9\u27e9 := hcomp (by linarith),\n  have h\u2081 : 2 \u2264 a,\n  { cases a,\n    { linarith },\n    { cases a,\n      { exfalso, exact a_ne_1 rfl },\n      { refine nat.succ_le_succ _,\n        refine nat.succ_le_succ _,\n        linarith, } } },\n  have h\u2082 : 2 \u2264 b,\n  { cases b,\n    { linarith },\n    { cases b,\n      { exfalso, exact b_ne_1 rfl, },\n      { refine nat.succ_le_succ _,\n        refine nat.succ_le_succ _,\n        linarith, } } },\n  have a_lt_n : a < n,\n  { rw \u2190 prod,\n    rw lt_mul_iff_one_lt_right; linarith },\n  have b_lt_n : b < n,\n  { rw \u2190 prod,\n    rw lt_mul_iff_one_lt_left; linarith },\n  refine \u27e8a, b, \u27e8prod, a_lt_n, b_lt_n, h\u2081, h\u2082\u27e9\u27e9\nend\n\nlemma prod_primes (n: \u2115) (hn: 2 \u2264 n) :\n  \u2203 ps: multiset \u2115,\n  (\u2200 p \u2208 ps, prime p) \u2227 ps.prod = n :=\nbegin\n  revert hn,\n  refine nat.strong_induction_on n _,\n  clear n,\n  intros n hyp hn,\n  by_cases hprime: prime n,\n  { refine \u27e8[n], _\u27e9,\n    split,\n    { intros p hp,\n      simp at hp,\n      rw hp,\n      exact hprime, },\n    { simp } },\n  { obtain \u27e8a, \u27e8b, \u27e8hprod, ha, hb, ha2, hb2\u27e9\u27e9\u27e9 :=\n      (constructive_composite_of_composite hprime) hn,\n    obtain \u27e8ps\u2081, \u27e8hps\u2081_prime, hps\u2081_prod\u27e9\u27e9 := hyp a ha ha2,\n    obtain \u27e8ps\u2082, \u27e8hps\u2082_prime, hps\u2082_prod\u27e9\u27e9 := hyp b hb hb2,\n    refine \u27e8ps\u2081 + ps\u2082, _\u27e9,\n    split,\n    { intros p hp,\n      simp at hp,\n      cases hp,\n      { exact hps\u2081_prime p hp },\n      { exact hps\u2082_prime p hp } },\n    { rw multiset.prod_add,\n      rw hps\u2081_prod,\n      rwa hps\u2082_prod } }\nend\n\n-- 3.2 Infinite primes\n\ndef primes : set \u2115 := {x | prime x}\n\nlemma zero_composite : composite 0 :=\nbegin\n  intro h,\n  have := (or_self _).1 (h.2 0 0 (by linarith)),\n  exact nat.zero_ne_one this\nend\n\nlemma one_composite : composite 1 :=\nbegin\n  intro h,\n  exact h.1 rfl,\nend\n\nlemma two_prime : prime 2 :=\nbegin\n  split,\n  { simp },\n  { intros a b h,\n    cases a,\n    { simp at h,\n      contradiction, },\n    cases b,\n      { simp at h,\n        contradiction },\n    cases a,\n    { left,\n      refl },\n    { right,\n      rw nat.succ_mul at h,\n      rw nat.succ_mul at h,\n      rw nat.succ_eq_add_one at *,\n      have : a * (b + 1) + b + b = 0 := by linarith,\n      rw add_eq_zero_iff at this,\n      rw this.right, } }\nend\n\nlemma two_le_prime {n: \u2115} (h: prime n) : 2 \u2264 n :=\nbegin\n  cases n,\n  { exfalso,\n    exact zero_composite h, },\n  { cases n,\n    { exfalso,\n      exact one_composite h, },\n    { refine nat.succ_le_succ _,\n      refine nat.succ_le_succ _,\n      exact zero_le _, } }\nend\n\nlemma infinite_primes : set.infinite primes :=\nbegin\n  intro hfinite,\n  obtain \u27e8all_ps, h\u27e9 := hfinite.exists_finset,\n  let P := all_ps.val.prod + 1,\n  have two_le_P : 2 \u2264 P,\n  { refine nat.succ_le_succ _,\n    rw nat.one_le_iff_ne_zero,\n    by_contradiction hzero,\n    rw multiset.prod_eq_zero_iff at hzero,\n    have := (h 0).1 hzero,\n    exact zero_composite this },\n  obtain \u27e8ps, all_prime, prod\u27e9 := prod_primes P two_le_P,\n  have : \u2200 p, prime p \u2192 p \u2209 ps,\n  { intros p,\n    contrapose!,\n    intro p_mem,\n    exfalso,\n    have := multiset.dvd_prod p_mem,\n    rw prod at this,\n    -- Technically we've not done division yet.\n    -- This is a pretty elementary argument, however.\n    have mod_eq_zero : P % p = 0,\n    { rwa nat.mod_eq_zero_of_dvd },\n    have : all_ps.val.prod % p = 0,\n    { rw nat.mod_eq_zero_of_dvd,\n      apply multiset.dvd_prod,\n      exact (h p).2 (all_prime p p_mem), },\n    have mod_eq_one : P % p = 1,\n    { rw nat.add_mod,\n      rw this,\n      simp,\n      obtain \u27e8p\u2081, hp\u2081\u27e9 := nat.le.dest (two_le_prime (all_prime p p_mem)),\n      rw \u2190 hp\u2081,\n      ring_nf },\n    rw mod_eq_one at mod_eq_zero,\n    exact one_ne_zero mod_eq_zero },\n  have : \u2203 p, p \u2208 ps,\n  { cases multiset.empty_or_exists_mem ps with hempty hmem,\n    { exfalso,\n      rw hempty at prod,\n      simp at prod,\n      change 2 \u2264 all_ps.val.prod + 1 at two_le_P,\n      rw prod at two_le_P,\n      linarith },\n    assumption },\n  obtain \u27e8p, hp\u27e9 := this,\n  exact this p (all_prime p hp) hp,\nend\n", "meta": {"author": "zeramorphic", "repo": "notes-formalised", "sha": "5327eb3d4f7a2723924b54f49f54e3b561aee875", "save_path": "github-repos/lean/zeramorphic-notes-formalised", "path": "github-repos/lean/zeramorphic-notes-formalised/notes-formalised-5327eb3d4f7a2723924b54f49f54e3b561aee875/src/ia/ns/primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7437228285592687}}
{"text": "/- LoVe Exercise 9: Hoare Logic -/\n\nimport .love09_hoare_logic_demo\n\nnamespace LoVe\n\n\n/- Question 1: Program Verification -/\n\nsection GAUSS\n\n/- The following WHILE program is intended to compute the Gaussian sum up to\n`n`, leaving the result in `r`. -/\n\ndef GAUSS : program :=\nassign \"r\" (\u03bbs, 0) ;;\nwhile (\u03bbs, s \"n\" \u2260 0)\n  (assign \"r\" (\u03bbs, s \"r\" + s \"n\") ;;\n   assign \"n\" (\u03bbs, s \"n\" - 1))\n\n/- The summation function: -/\n\ndef sum_upto : \u2115 \u2192 \u2115\n| 0       := 0\n| (n + 1) := n + 1 + sum_upto n\n\n/- 1.1. Prove the correctness of `GAUSS`, using `vcg`. The main challenge is to\nfigure out which invariant to use for the while loop. The invariant should\ncapture both the work that has been done already (the intermediate result) and\nthe work that remains to be done. -/\n\nlemma GAUSS_correct (n : \u2115) :\n  {* \u03bbs, s \"n\" = n *} GAUSS {* \u03bbs, s \"r\" = sum_upto n *} :=\nsorry\n\nend GAUSS\n\nsection MUL\n\n/- The following WHILE program is intended to compute the product of `n` and\n`m`, leaving the result in `r`. -/\n\ndef MUL : program :=\nassign \"r\" (\u03bbs, 0) ;;\nwhile (\u03bbs, s \"n\" \u2260 0)\n  (assign \"r\" (\u03bbs, s \"r\" + s \"m\") ;;\n   assign \"n\" (\u03bbs, s \"n\" - 1))\n\n/- 1.2 Prove the correctness of `MUL`, using `vcg`.\n\nHint: If a variable `x` does not change in a program, it might be useful to\nrecord this in the invariant, by adding a conjunct `s \"x\" = x`. -/\n\nlemma MUL_correct (n m : \u2115) :\n  {* \u03bbs, s \"n\" = n \u2227 s \"m\" = m *} MUL {* \u03bbs, s \"r\" = n * m *} :=\nsorry\n\nend MUL\n\n\n/- Question 2: Hoare Triples for Total Correctness -/\n\ndef total_hoare (P : state \u2192 Prop) (p : program) (Q : state \u2192 Prop) : Prop :=\n\u2200s, P s \u2192 \u2203t, (p, s) \u27f9 t \u2227 Q t\n\nnotation `[* ` P : 1 ` *] ` p : 1 ` [* ` Q : 1 ` *]` := total_hoare P p Q\n\nnamespace total_hoare\n\nvariables {P P' P\u2081 P\u2082 P\u2083 Q Q' : state \u2192 Prop} {x : string}\nvariables {S S\u2080 S\u2081 S\u2082 : program}\nvariables {b : state \u2192 Prop} {a : state \u2192 \u2115} {s s\u2080 s\u2081 s\u2082 t u : state}\n\n/- 2.1. Prove the consequence rule. -/\n\nlemma consequence (h : [* P *] S [* Q *]) (hp : \u2200s, P' s \u2192 P s)\n    (hq : \u2200s, Q s \u2192 Q' s) :\n  [* P' *] S [* Q' *] :=\nsorry\n\n/- 2.2. Prove the rule for `skip`. -/\n\nlemma skip_intro :\n  [* P *] skip [* P *] :=\nsorry\n\n/- 2.3. Prove the rule for `assign`. -/\n\nlemma assign_intro (P : state \u2192 Prop) :\n  [* \u03bbs, P (s{x \u21a6 a s}) *] assign x a [* P *] :=\nsorry\n\n/- 2.4. Prove the rule for `seq`. -/\n\nlemma seq_intro (h\u2081 : [* P\u2081 *] S\u2081 [* P\u2082 *])\n    (h\u2082 : [* P\u2082 *] S\u2082 [* P\u2083 *]) :\n  [* P\u2081 *] S\u2081 ;; S\u2082 [* P\u2083 *] :=\nsorry\n\n/- 2.5 **optional**. Prove the rule for `ite`. This requires `b s \u2228 \u00ac b s`.\n`classical.em (b s)` provides a proof, even when `b` is not decidable. -/\n\nlemma ite_intro (h\u2081 : [* \u03bbs, P s \u2227 b s *] S\u2081 [* Q *])\n  (h\u2082 : [* \u03bbs, P s \u2227 \u00ac b s *] S\u2082 [* Q *]) :\n  [* P *] ite b S\u2081 S\u2082 [* Q *] :=\nsorry\n\n/- 2.6 **optional**. Try to prove the rule for `while`.\n\nBefore we prove our final goal, we introduce an auxiliary proof. This proof\nrequires well-founded induction. When using `while_intro.aux` as induction\nhypothesis we recommend to do it directly after proving that the argument is\nless than `n`:\n\n    have ih : \u2203u, (while c p, t) \u27f9 u \u2227 I u \u2227 \u00ac c u :=\n      have M < n := \u2026,\n        -- necessary for Lean to figure out the well-founded induction\n      while_intro.aux M \u2026,\n\nSimilar to `ite`, this requires `c s \u2228 \u00ac c s`. `classical.em (c s)` provides a\nproof. -/\n\nlemma while_intro.aux\n  (I : state \u2192 Prop)\n  (V : state \u2192 \u2115)\n  (h_inv : \u2200n, [* \u03bbs, I s \u2227 b s \u2227 V s = n *] S [* \u03bbs, I s \u2227 V s < n *]) :\n  \u2200n s, V s = n \u2192 I s \u2192 \u2203t, (while b S, s) \u27f9 t \u2227 I t \u2227 \u00ac b t\n| n s V_eq hs :=\nsorry\n\nlemma while_intro\n  (I : state \u2192 Prop)   -- invariant in the loop\n  (V : state \u2192 \u2115)      -- variant in the loop body (a.k.a. termination measure)\n  (h_inv : \u2200n, [* \u03bbs, I s \u2227 b s \u2227 V s = n *] S [* \u03bbs, I s \u2227 V s < n *]) :\n  [* I *] while b S [* \u03bbs, I s \u2227 \u00ac b s *] :=\nsorry\n\nend total_hoare\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love09_hoare_logic_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7437156355849728}}
{"text": "/-\nCopyright (c) 2021 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport data.zmod.defs\nimport set_theory.cardinal.basic\n\n/-!\n# Finite Cardinality Functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main Definitions\n\n* `nat.card \u03b1` is the cardinality of `\u03b1` as a natural number.\n  If `\u03b1` is infinite, `nat.card \u03b1 = 0`.\n* `part_enat.card \u03b1` is the cardinality of `\u03b1` as an extended natural number\n  (`part \u2115` implementation). If `\u03b1` is infinite, `part_enat.card \u03b1 = \u22a4`.\n-/\n\nopen cardinal\nnoncomputable theory\nopen_locale big_operators\n\nvariables {\u03b1 \u03b2 : Type*}\n\nnamespace nat\n\n/-- `nat.card \u03b1` is the cardinality of `\u03b1` as a natural number.\n  If `\u03b1` is infinite, `nat.card \u03b1 = 0`. -/\nprotected def card (\u03b1 : Type*) : \u2115 := (mk \u03b1).to_nat\n\n@[simp]\nlemma card_eq_fintype_card [fintype \u03b1] : nat.card \u03b1 = fintype.card \u03b1 := mk_to_nat_eq_card\n\n@[simp]\nlemma card_eq_zero_of_infinite [infinite \u03b1] : nat.card \u03b1 = 0 := mk_to_nat_of_infinite\n\nlemma finite_of_card_ne_zero (h : nat.card \u03b1 \u2260 0) : finite \u03b1 :=\nnot_infinite_iff_finite.mp $ h \u2218 @nat.card_eq_zero_of_infinite \u03b1\n\nlemma card_congr (f : \u03b1 \u2243 \u03b2) : nat.card \u03b1 = nat.card \u03b2 :=\ncardinal.to_nat_congr f\n\nlemma card_eq_of_bijective (f : \u03b1 \u2192 \u03b2) (hf : function.bijective f) : nat.card \u03b1 = nat.card \u03b2 :=\ncard_congr (equiv.of_bijective f hf)\n\nlemma card_eq_of_equiv_fin {\u03b1 : Type*} {n : \u2115}\n  (f : \u03b1 \u2243 fin n) : nat.card \u03b1 = n :=\nby simpa using card_congr f\n\n/-- If the cardinality is positive, that means it is a finite type, so there is\nan equivalence between `\u03b1` and `fin (nat.card \u03b1)`. See also `finite.equiv_fin`. -/\ndef equiv_fin_of_card_pos {\u03b1 : Type*} (h : nat.card \u03b1 \u2260 0) :\n  \u03b1 \u2243 fin (nat.card \u03b1) :=\nbegin\n  casesI fintype_or_infinite \u03b1,\n  { simpa using fintype.equiv_fin \u03b1 },\n  { simpa using h },\nend\n\nlemma card_of_subsingleton (a : \u03b1) [subsingleton \u03b1] : nat.card \u03b1 = 1 :=\nbegin\n  letI := fintype.of_subsingleton a,\n  rw [card_eq_fintype_card, fintype.card_of_subsingleton a]\nend\n\n@[simp] lemma card_unique [unique \u03b1] : nat.card \u03b1 = 1 :=\ncard_of_subsingleton default\n\nlemma card_eq_one_iff_unique : nat.card \u03b1 = 1 \u2194 subsingleton \u03b1 \u2227 nonempty \u03b1 :=\ncardinal.to_nat_eq_one_iff_unique\n\nlemma card_eq_two_iff : nat.card \u03b1 = 2 \u2194 \u2203 x y : \u03b1, x \u2260 y \u2227 {x, y} = @set.univ \u03b1 :=\n(to_nat_eq_iff two_ne_zero).trans $ iff.trans (by rw [nat.cast_two]) mk_eq_two_iff\n\nlemma card_eq_two_iff' (x : \u03b1) : nat.card \u03b1 = 2 \u2194 \u2203! y, y \u2260 x :=\n(to_nat_eq_iff two_ne_zero).trans $ iff.trans (by rw [nat.cast_two]) (mk_eq_two_iff' x)\n\ntheorem card_of_is_empty [is_empty \u03b1] : nat.card \u03b1 = 0 := by simp\n\n@[simp] lemma card_prod (\u03b1 \u03b2 : Type*) : nat.card (\u03b1 \u00d7 \u03b2) = nat.card \u03b1 * nat.card \u03b2 :=\nby simp only [nat.card, mk_prod, to_nat_mul, to_nat_lift]\n\n@[simp] lemma card_ulift (\u03b1 : Type*) : nat.card (ulift \u03b1) = nat.card \u03b1 :=\ncard_congr equiv.ulift\n\n@[simp] lemma card_plift (\u03b1 : Type*) : nat.card (plift \u03b1) = nat.card \u03b1 :=\ncard_congr equiv.plift\n\nlemma card_pi {\u03b2 : \u03b1 \u2192 Type*} [fintype \u03b1] : nat.card (\u03a0 a, \u03b2 a) = \u220f a, nat.card (\u03b2 a) :=\nby simp_rw [nat.card, mk_pi, prod_eq_of_fintype, to_nat_lift, to_nat_finset_prod]\n\nlemma card_fun [finite \u03b1] : nat.card (\u03b1 \u2192 \u03b2) = nat.card \u03b2 ^ nat.card \u03b1 :=\nbegin\n  haveI := fintype.of_finite \u03b1,\n  rw [nat.card_pi, finset.prod_const, finset.card_univ, \u2190nat.card_eq_fintype_card],\nend\n\n@[simp] lemma card_zmod (n : \u2115) : nat.card (zmod n) = n :=\nbegin\n  cases n,\n  { exact nat.card_eq_zero_of_infinite },\n  { rw [nat.card_eq_fintype_card, zmod.card] },\nend\n\nend nat\n\nnamespace part_enat\n\n/-- `part_enat.card \u03b1` is the cardinality of `\u03b1` as an extended natural number.\n  If `\u03b1` is infinite, `part_enat.card \u03b1 = \u22a4`. -/\ndef card (\u03b1 : Type*) : part_enat := (mk \u03b1).to_part_enat\n\n@[simp]\nlemma card_eq_coe_fintype_card [fintype \u03b1] : card \u03b1 = fintype.card \u03b1 := mk_to_part_enat_eq_coe_card\n\n@[simp]\nlemma card_eq_top_of_infinite [infinite \u03b1] : card \u03b1 = \u22a4 := mk_to_part_enat_of_infinite\n\nend part_enat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/set_theory/cardinal/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8670357546485408, "lm_q1q2_score": 0.7437156225285273}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\n-/\nimport data.nat.sqrt\nimport data.nat.gcd\nimport algebra.group_power\nimport tactic.wlog\nimport tactic.norm_num\n\n/-!\n# Prime numbers\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\nAll the following declarations exist in the namespace `nat`.\n\n- `prime`: the predicate that expresses that a natural number `p` is prime\n- `primes`: the subtype of natural numbers that are prime\n- `min_fac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers\n- `factors n`: the prime factorization of `n`\n- `factors_unique`: uniqueness of the prime factorisation\n\n-/\n\nopen bool subtype\nopen_locale nat\n\nnamespace nat\n\n/-- `prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\n@[pp_nodot]\ndef prime (p : \u2115) := 2 \u2264 p \u2227 \u2200 m \u2223 p, m = 1 \u2228 m = p\n\ntheorem prime.two_le {p : \u2115} : prime p \u2192 2 \u2264 p := and.left\n\ntheorem prime.one_lt {p : \u2115} : prime p \u2192 1 < p := prime.two_le\n\ninstance prime.one_lt' (p : \u2115) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := \u27e8hp.1.one_lt\u27e9\n\nlemma prime.ne_one {p : \u2115} (hp : p.prime) : p \u2260 1 :=\nne.symm $ ne_of_lt hp.one_lt\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\nand_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h l d, (h d).resolve_right (ne_of_lt l),\n \u03bb h d, (decidable.lt_or_eq_of_le $\n   le_of_dvd (le_of_succ_le p2) d).imp_left (\u03bb l, h l d)\u27e9\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00ac m \u2223 p :=\nprime_def_lt.trans $ and_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h m2 l d, not_lt_of_ge m2 ((h l d).symm \u25b8 dec_trivial),\n\u03bb h l d, begin\n  rcases m with _|_|m,\n  { rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },\n  { refl },\n  { exact (h dec_trivial l).elim d }\nend\u27e9\n\ntheorem prime_def_le_sqrt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227\n  \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac m \u2223 p :=\nprime_def_lt'.trans $ and_congr_right $ \u03bb p2,\n\u27e8\u03bb a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,\n \u03bb a, have \u2200 {m k}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k, from\n  \u03bb m k mk m1 e, a m m1\n    (le_sqrt.2 (e.symm \u25b8 mul_le_mul_left m mk)) \u27e8k, e\u27e9,\n  \u03bb m m2 l \u27e8k, e\u27e9, begin\n    cases (le_total m k) with mk km,\n    { exact this mk m2 e },\n    { rw [mul_comm] at e,\n      refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,\n      rwa [one_mul, \u2190 e] }\n  end\u27e9\n\nsection\n\n/--\n  This instance is slower than the instance `decidable_prime` defined below,\n  but has the advantage that it works in the kernel for small values.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\nlocal attribute [instance]\ndef decidable_prime_1 (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_lt'\n\nlemma prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 :=\nby { rintro rfl, revert h, dec_trivial }\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : 0 < p :=\nlt_of_succ_lt pp.one_lt\n\ntheorem not_prime_zero : \u00ac prime 0 := by simp [prime]\n\ntheorem not_prime_one : \u00ac prime 1 := by simp [prime]\n\ntheorem prime_two : prime 2 := dec_trivial\n\nend\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : 0 < pred p :=\nlt_pred_iff.2 pp.one_lt\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : succ (pred p) = p :=\nsucc_pred_eq_of_pos pp.pos\n\ntheorem dvd_prime {p m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n\u27e8\u03bb d, pp.2 m d, \u03bb h, h.elim (\u03bb e, e.symm \u25b8 one_dvd _) (\u03bb e, e.symm \u25b8 dvd_refl _)\u27e9\n\ntheorem dvd_prime_two_le {p m : \u2115} (pp : prime p) (H : 2 \u2264 m) : m \u2223 p \u2194 m = p :=\n(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H\n\ntheorem prime_dvd_prime_iff_eq {p q : \u2115} (pp : p.prime) (qp : q.prime) : p \u2223 q \u2194 p = q :=\ndvd_prime_two_le qp (prime.two_le pp)\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00ac p \u2223 1\n| d := (not_le_of_gt pp.one_lt) $ le_of_dvd dec_trivial d\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00ac prime (a * b) :=\n\u03bb h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $\nby simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)\n\nlemma not_prime_mul' {a b n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) : \u00ac prime n :=\nby { rw \u2190 h, exact not_prime_mul h\u2081 h\u2082 }\n\nsection min_fac\n  private lemma min_fac_lemma (n k : \u2115) (h : \u00ac n < k * k) :\n    sqrt n - k < sqrt n + 2 - k :=\n  (nat.sub_lt_sub_right_iff $ le_sqrt.2 $ le_of_not_gt h).2 $\n  nat.lt_add_of_pos_right dec_trivial\n\n  /-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.\n    Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.\n    If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/\n  def min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115 | k :=\n  if h : n < k * k then n else\n  if k \u2223 n then k else\n  have _, from min_fac_lemma n k h,\n  min_fac_aux (k + 2)\n  using_well_founded {rel_tac :=\n    \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n  /-- Returns the smallest prime factor of `n \u2260 1`. -/\n  def min_fac : \u2115 \u2192 \u2115\n  | 0 := 2\n  | 1 := 1\n  | (n+2) := if 2 \u2223 n then 2 else min_fac_aux (n + 2) 3\n\n  @[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl\n  @[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\n  theorem min_fac_eq : \u2200 n, min_fac n = if 2 \u2223 n then 2 else min_fac_aux n 3\n  | 0     := by simp\n  | 1     := by simp [show 2\u22601, from dec_trivial]; rw min_fac_aux; refl\n  | (n+2) :=\n    have 2 \u2223 n + 2 \u2194 2 \u2223 n, from\n      (nat.dvd_add_iff_left (by refl)).symm,\n    by simp [min_fac, this]; congr\n\n  private def min_fac_prop (n k : \u2115) :=\n    2 \u2264 k \u2227 k \u2223 n \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m\n\n  theorem min_fac_aux_has_prop {n : \u2115} (n2 : 2 \u2264 n) (nd2 : \u00ac 2 \u2223 n) :\n    \u2200 k i, k = 2*i+3 \u2192 (\u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k)\n  | k := \u03bb i e a, begin\n    rw min_fac_aux,\n    by_cases h : n < k*k; simp [h],\n    { have pp : prime n :=\n        prime_def_le_sqrt.2 \u27e8n2, \u03bb m m2 l d,\n          not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9,\n      from \u27e8n2, dvd_refl _, \u03bb m m2 d, le_of_eq\n        ((dvd_prime_two_le pp m2).1 d).symm\u27e9 },\n    have k2 : 2 \u2264 k, { subst e, exact dec_trivial },\n    by_cases dk : k \u2223 n; simp [dk],\n    { exact \u27e8k2, dk, a\u27e9 },\n    { refine have _, from min_fac_lemma n k h,\n        min_fac_aux_has_prop (k+2) (i+1)\n          (by simp [e, left_distrib]) (\u03bb m m2 d, _),\n      cases nat.eq_or_lt_of_le (a m m2 d) with me ml,\n      { subst me, contradiction },\n      apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,\n      rw [\u2190 me, e] at d, change 2 * (i + 2) \u2223 n at d,\n      have := dvd_of_mul_right_dvd d, contradiction }\n  end\n  using_well_founded {rel_tac :=\n    \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n  theorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) :\n    min_fac_prop n (min_fac n) :=\n  begin\n    by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},\n    have n2 : 2 \u2264 n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },\n    simp [min_fac_eq],\n    by_cases d2 : 2 \u2223 n; simp [d2],\n    { exact \u27e8le_refl _, d2, \u03bb k k2 d, k2\u27e9 },\n    { refine min_fac_aux_has_prop n2 d2 3 0 rfl\n        (\u03bb m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),\n      exact \u03bb e, e.symm \u25b8 d }\n  end\n\n  theorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\n  if n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1\n\n  theorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) :=\n  let \u27e8f2, fd, a\u27e9 := min_fac_has_prop n1 in\n  prime_def_lt'.2 \u27e8f2, \u03bb m m2 l d, not_le_of_gt l (a m m2 (dvd_trans d fd))\u27e9\n\n  theorem min_fac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, 2 \u2264 m \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\n  by by_cases n1 : n = 1;\n    [exact \u03bb m m2 d, n1.symm \u25b8 le_trans dec_trivial m2,\n     exact (min_fac_has_prop n1).2.2]\n\n  theorem min_fac_pos (n : \u2115) : 0 < min_fac n :=\n  by by_cases n1 : n = 1;\n     [exact n1.symm \u25b8 dec_trivial, exact (min_fac_prime n1).pos]\n\n  theorem min_fac_le {n : \u2115} (H : 0 < n) : min_fac n \u2264 n :=\n  le_of_dvd H (min_fac_dvd n)\n\n  theorem prime_def_min_fac {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 min_fac p = p :=\n  \u27e8\u03bb pp, \u27e8pp.two_le,\n    let \u27e8f2, fd, a\u27e9 := min_fac_has_prop $ ne_of_gt pp.one_lt in\n    ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n   \u03bb \u27e8p2, e\u27e9, e \u25b8 min_fac_prime (ne_of_gt p2)\u27e9\n\n  /--\n  This instance is faster in the virtual machine than `decidable_prime_1`,\n  but slower in the kernel.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\n  instance decidable_prime (p : \u2115) : decidable (prime p) :=\n  decidable_of_iff' _ prime_def_min_fac\n\n  theorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : 2 \u2264 n) : \u00ac prime n \u2194 min_fac n < n :=\n  (not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $\n    (lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm\n\n  lemma min_fac_le_div {n : \u2115} (pos : 0 < n) (np : \u00ac prime n) : min_fac n \u2264 n / min_fac n :=\n  match min_fac_dvd n with\n  | \u27e80, h0\u27e9     := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial\n  | \u27e81, h1\u27e9     :=\n    begin\n      rw mul_one at h1,\n      rw [prime_def_min_fac, not_and_distrib, \u2190 h1, eq_self_iff_true, not_true, or_false,\n        not_le] at np,\n      rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]\n    end\n  | \u27e8(x+2), hx\u27e9 :=\n    begin\n      conv_rhs { congr, rw hx },\n      rw [nat.mul_div_cancel_left _ (min_fac_pos _)],\n      exact min_fac_le_of_dvd dec_trivial \u27e8min_fac n, by rwa mul_comm\u27e9\n    end\n  end\n\n  /--\n  The square of the smallest prime factor of a composite number `n` is at most `n`.\n  -/\n  lemma min_fac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00ac prime n) : (min_fac n)^2 \u2264 n :=\n  have t : (min_fac n) \u2264 (n/min_fac n) := min_fac_le_div w h,\n  calc\n  (min_fac n)^2 = (min_fac n) * (min_fac n)   : sq (min_fac n)\n            ... \u2264 (n/min_fac n) * (min_fac n) : mul_le_mul_right (min_fac n) t\n            ... \u2264 n                           : div_mul_le_self n (min_fac n)\n\n  @[simp]\n  lemma min_fac_eq_one_iff {n : \u2115} : min_fac n = 1 \u2194 n = 1 :=\n  begin\n    split,\n    { intro h,\n      by_contradiction hn,\n      have := min_fac_prime hn,\n      rw h at this,\n      exact not_prime_one this, },\n    { rintro rfl, refl, }\n  end\n\n  @[simp]\n  lemma min_fac_eq_two_iff (n : \u2115) : min_fac n = 2 \u2194 2 \u2223 n :=\n  begin\n    split,\n    { intro h,\n      convert min_fac_dvd _,\n      rw h, },\n    { intro h,\n      have ub := min_fac_le_of_dvd (le_refl 2) h,\n      have lb := min_fac_pos n,\n      -- If `interval_cases` and `norm_num` were already available here,\n      -- this would be easy and pleasant.\n      -- But they aren't, so it isn't.\n      cases h : n.min_fac with m,\n      { rw h at lb, cases lb, },\n      { cases m with m,\n        { simp at h, subst h, cases h with n h, cases n; cases h, },\n        { cases m with m,\n          { refl, },\n          { rw h at ub,\n            cases ub with _ ub, cases ub with _ ub, cases ub, } } } }\n  end\n\nend min_fac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n\u27e8min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,\n  ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 2 \u2264 m \u2227 m < n :=\n\u27e8min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,\n  (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_prime_and_dvd {n : \u2115} (n2 : 2 \u2264 n) : \u2203 p, prime p \u2227 p \u2223 n :=\n\u27e8min_fac n, min_fac_prime (ne_of_gt n2), min_fac_dvd _\u27e9\n\n/-- Euclid's theorem. There exist infinitely many prime numbers.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, n \u2264 p \u2227 prime p :=\nlet p := min_fac (n! + 1) in\nhave f1 : n! + 1 \u2260 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,\nhave pp : prime p, from min_fac_prime f1,\nhave np : n \u2264 p, from le_of_not_ge $ \u03bb h,\n  have h\u2081 : p \u2223 n!, from dvd_factorial (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  pp.not_dvd_one h\u2082,\n\u27e8p, np, pp\u27e9\n\nlemma prime.eq_two_or_odd {p : \u2115} (hp : prime p) : p = 2 \u2228 p % 2 = 1 :=\n(nat.mod_two_eq_zero_or_one p).elim\n  (\u03bb h, or.inl ((hp.2 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)\n  or.inr\n\ntheorem coprime_of_dvd {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 \u00ac k \u2223 n) : coprime m n :=\nbegin\n  cases eq_zero_or_pos (gcd m n) with g0 g1,\n  { rw [eq_zero_of_gcd_eq_zero_left g0, eq_zero_of_gcd_eq_zero_right g0] at H,\n    exfalso,\n    exact H 2 prime_two (dvd_zero _) (dvd_zero _) },\n  apply eq.symm,\n  change 1 \u2264 _ at g1,\n  apply (lt_or_eq_of_le g1).resolve_left,\n  intro g2,\n  obtain \u27e8p, hp, hpdvd\u27e9 := exists_prime_and_dvd g2,\n  apply H p hp; apply dvd_trans hpdvd,\n  { exact gcd_dvd_left _ _ },\n  { exact gcd_dvd_right _ _ }\nend\n\ntheorem coprime_of_dvd' {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) : coprime m n :=\ncoprime_of_dvd $ \u03bbk kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn\n\ntheorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=\ndiv_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 list \u2115\n| 0 := []\n| 1 := []\n| n@(k+2) :=\n  let m := min_fac n in have n / m < n := factors_lemma,\n  m :: factors (n / m)\n\n@[simp] lemma factors_zero : factors 0 = [] := by rw factors\n@[simp] lemma factors_one : factors 1 = [] := by rw factors\n\nlemma prime_of_mem_factors : \u2200 {n p}, p \u2208 factors n \u2192 prime p\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb p h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  have h\u2081 : p = m \u2228 p \u2208 (factors (n / m)) :=\n    (list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),\n  or.cases_on h\u2081 (\u03bb h\u2082, h\u2082.symm \u25b8 min_fac_prime dec_trivial)\n    prime_of_mem_factors\n\nlemma prod_factors : \u2200 {n}, 0 < n \u2192 list.prod (factors n) = n\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  show (factors n).prod = n, from\n  have h\u2081 : 0 < n / m :=\n    nat.pos_of_ne_zero $ \u03bb h,\n    have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,\n    by rw zero_mul at this; exact (show k + 2 \u2260 0, from dec_trivial) this,\n  by rw [factors, list.prod_cons, prod_factors h\u2081, nat.mul_div_cancel' (min_fac_dvd _)]\n\nlemma factors_prime {p : \u2115} (hp : nat.prime p) : p.factors = [p] :=\nbegin\n  have : p = (p - 2) + 2 := (nat.sub_eq_iff_eq_add hp.1).mp rfl,\n  rw [this, nat.factors],\n  simp only [eq.symm this],\n  have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,\n  split,\n  { exact this, },\n  { simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },\nend\n\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\nlemma factors_add_two (n : \u2115) :\n  factors (n+2) = (min_fac (n+2)) :: (factors ((n+2) / (min_fac (n+2)))) :=\nby rw factors\n\n@[simp]\nlemma factors_eq_nil (n : \u2115) : n.factors = [] \u2194 n = 0 \u2228 n = 1 :=\nbegin\n  split; intro h,\n  { rcases n with (_ | _ | n),\n    { exact or.inl rfl },\n    { exact or.inr rfl },\n    { rw factors at h, injection h }, },\n  { rcases h with (rfl | rfl),\n    { exact factors_zero },\n    { exact factors_one }, }\nend\n\ntheorem prime.coprime_iff_not_dvd {p n : \u2115} (pp : prime p) : coprime p n \u2194 \u00ac p \u2223 n :=\n\u27e8\u03bb co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),\n \u03bb nd, coprime_of_dvd $ \u03bb m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm \u25b8 nd\u27e9\n\ntheorem prime.dvd_iff_not_coprime {p n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00ac coprime p n :=\niff_not_comm.2 pp.coprime_iff_not_dvd\n\ntheorem prime.not_coprime_iff_dvd {m n : \u2115} :\n  \u00ac coprime m n \u2194 \u2203p, prime p \u2227 p \u2223 m \u2227 p \u2223 n :=\nbegin\n  apply iff.intro,\n  { intro h,\n    exact \u27e8min_fac (gcd m n), min_fac_prime h,\n      (dvd.trans (min_fac_dvd (gcd m n)) (gcd_dvd_left m n)),\n      (dvd.trans (min_fac_dvd (gcd m n)) (gcd_dvd_right m n))\u27e9 },\n  { intro h,\n    cases h with p hp,\n    apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }\nend\n\ntheorem prime.dvd_mul {p m n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n\u27e8\u03bb H, or_iff_not_imp_left.2 $ \u03bb h,\n  (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n or.rec (\u03bb h, dvd_mul_of_dvd_left h _) (\u03bb h, dvd_mul_of_dvd_right h _)\u27e9\n\ntheorem prime.not_dvd_mul {p m n : \u2115} (pp : prime p)\n  (Hm : \u00ac p \u2223 m) (Hn : \u00ac p \u2223 n) : \u00ac p \u2223 m * n :=\nmt pp.dvd_mul.1 $ by simp [Hm, Hn]\n\ntheorem prime.dvd_of_dvd_pow {p m n : \u2115} (pp : prime p) (h : p \u2223 m^n) : p \u2223 m :=\nby induction n with n IH;\n   [exact pp.not_dvd_one.elim h,\n    by { rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH } ]\n\nlemma prime.pow_not_prime {x n : \u2115} (hn : 2 \u2264 n) : \u00ac (x ^ n).prime :=\n\u03bb hp, (hp.2 x $ dvd_trans \u27e8x, sq _\u27e9 (pow_dvd_pow _ hn)).elim\n  (\u03bb hx1, hp.ne_one $ hx1.symm \u25b8 one_pow _)\n  (\u03bb hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm\n     ... < x ^ n : nat.pow_right_strict_mono (hxn.symm \u25b8 hp.two_le) hn\n     ... = x : hxn.symm)\n\nlemma prime.mul_eq_prime_sq_iff {x y p : \u2115} (hp : p.prime) (hx : x \u2260 1) (hy : y \u2260 1) :\n  x * y = p ^ 2 \u2194 x = p \u2227 y = p :=\n\u27e8\u03bb h, have pdvdxy : p \u2223 x * y, by rw h; simp [sq],\nbegin\n  wlog := hp.dvd_mul.1 pdvdxy using x y,\n  cases case with a ha,\n  have hap : a \u2223 p, from \u27e8y, by rwa [ha, sq,\n        mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at h\u27e9,\n  exact ((nat.dvd_prime hp).1 hap).elim\n    (\u03bb _, by clear_aux_decl; simp [*, sq, nat.mul_right_inj hp.pos] at *\n      {contextual := tt})\n    (\u03bb _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,\n      nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *\n      {contextual := tt})\nend,\n\u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.symm \u25b8 h\u2082.symm \u25b8 (sq _).symm\u27e9\n\nlemma prime.dvd_factorial : \u2200 {n p : \u2115} (hp : prime p), p \u2223 n! \u2194 p \u2264 n\n| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)\n| (n+1) p hp := begin\n  rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],\n  exact \u27e8\u03bb h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,\n    \u03bb h, (_root_.lt_or_eq_of_le h).elim (or.inr \u2218 le_of_lt_succ)\n      (\u03bb h, or.inl $ by rw h)\u27e9\nend\n\ntheorem prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : prime p) (h : \u00ac p \u2223 a) : coprime a (p^m) :=\n(pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n\ntheorem coprime_primes {p q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\npp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : prime p) (pq : prime q) (h : p \u2260 q) :\n  coprime (p^n) (q^m) :=\n((coprime_primes pp pq).2 h).pow _ _\n\ntheorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\nby rw [pp.dvd_iff_not_coprime]; apply em\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m i : \u2115} : i \u2223 (p^m) \u2194 \u2203 k \u2264 m, i = p^k :=\nbegin\n  induction m with m IH generalizing i, {simp [pow_succ, le_zero_iff] at *},\n  by_cases p \u2223 i,\n  { cases h with a e, subst e,\n    rw [pow_succ, nat.mul_dvd_mul_iff_left pp.pos, IH],\n    split; intro h; rcases h with \u27e8k, h, e\u27e9,\n    { exact \u27e8succ k, succ_le_succ h, by rw [e, pow_succ]; refl\u27e9 },\n    cases k with k,\n    { apply pp.not_dvd_one.elim,\n      simp at e, rw \u2190 e, apply dvd_mul_right },\n    { refine \u27e8k, le_of_succ_le_succ h, _\u27e9,\n      rwa [mul_comm, pow_succ', nat.mul_left_inj pp.pos] at e } },\n  { split; intro d,\n    { rw (pp.coprime_pow_of_not_dvd h).eq_one_of_dvd d,\n      exact \u27e80, zero_le _, rfl\u27e9 },\n    { rcases d with \u27e8k, l, e\u27e9,\n      rw e, exact pow_dvd_pow _ l } }\nend\n\n/--\nIf `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\nlemma eq_prime_pow_of_dvd_least_prime_pow\n  {a p k : \u2115} (pp : prime p) (h\u2081 : \u00ac(a \u2223 p^k)) (h\u2082 : a \u2223 p^(k+1)) :\n  a = p^(k+1) :=\nbegin\n  obtain \u27e8l, \u27e8h, rfl\u27e9\u27e9 := (dvd_prime_pow pp).1 h\u2082,\n  congr,\n  exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h\u2081)),\nend\n\nsection\nopen list\n\nlemma mem_list_primes_of_dvd_prod {p : \u2115} (hp : prime p) :\n  \u2200 {l : list \u2115}, (\u2200 p \u2208 l, prime p) \u2192 p \u2223 prod l \u2192 p \u2208 l\n| []       := \u03bb h\u2081 h\u2082, absurd h\u2082 (prime.not_dvd_one hp)\n| (q :: l) := \u03bb h\u2081 h\u2082,\n  have h\u2083 : p \u2223 q * prod l := @prod_cons _ _ l q \u25b8 h\u2082,\n  have hq : prime q := h\u2081 q (mem_cons_self _ _),\n  or.cases_on ((prime.dvd_mul hp).1 h\u2083)\n    (\u03bb h, by rw [prime.dvd_iff_not_coprime hp, coprime_primes hp hq, ne.def, not_not] at h;\n      exact h \u25b8 mem_cons_self _ _)\n    (\u03bb h, have hl : \u2200 p \u2208 l, prime p := \u03bb p hlp, h\u2081 p ((mem_cons_iff _ _ _).2 (or.inr hlp)),\n    (mem_cons_iff _ _ _).2 (or.inr (mem_list_primes_of_dvd_prod hl h)))\n\nlemma mem_factors_iff_dvd {n p : \u2115} (hn : 0 < n) (hp : prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n\u27e8\u03bb h, prod_factors hn \u25b8 list.dvd_prod h,\n \u03bb h, mem_list_primes_of_dvd_prod hp (@prime_of_mem_factors n) ((prod_factors hn).symm \u25b8 h)\u27e9\n\nlemma mem_factors {n p} (hn : 0 < n) : p \u2208 factors n \u2194 prime p \u2227 p \u2223 n :=\n\u27e8\u03bb h, \u27e8prime_of_mem_factors h, (mem_factors_iff_dvd hn $ prime_of_mem_factors h).mp h\u27e9,\n \u03bb \u27e8hprime, hdvd\u27e9, (mem_factors_iff_dvd hn hprime).mpr hdvd\u27e9\n\nlemma perm_of_prod_eq_prod : \u2200 {l\u2081 l\u2082 : list \u2115}, prod l\u2081 = prod l\u2082 \u2192\n  (\u2200 p \u2208 l\u2081, prime p) \u2192 (\u2200 p \u2208 l\u2082, prime p) \u2192 l\u2081 ~ l\u2082\n| []        []        _  _  _  := perm.nil\n| []        (a :: l)  h\u2081 h\u2082 h\u2083 :=\n  have ha : a \u2223 1 := @prod_nil \u2115 _ \u25b8 h\u2081.symm \u25b8 (@prod_cons _ _ l a).symm \u25b8 dvd_mul_right _ _,\n  absurd ha (prime.not_dvd_one (h\u2083 a (mem_cons_self _ _)))\n| (a :: l)  []        h\u2081 h\u2082 h\u2083 :=\n  have ha : a \u2223 1 := @prod_nil \u2115 _ \u25b8 h\u2081 \u25b8 (@prod_cons _ _ l a).symm \u25b8 dvd_mul_right _ _,\n  absurd ha (prime.not_dvd_one (h\u2082 a (mem_cons_self _ _)))\n| (a :: l\u2081) (b :: l\u2082) h hl\u2081 hl\u2082 :=\n  have hl\u2081' : \u2200 p \u2208 l\u2081, prime p := \u03bb p hp, hl\u2081 p (mem_cons_of_mem _ hp),\n  have hl\u2082' : \u2200 p \u2208 (b :: l\u2082).erase a, prime p := \u03bb p hp, hl\u2082 p (mem_of_mem_erase hp),\n  have ha : a \u2208 (b :: l\u2082) := mem_list_primes_of_dvd_prod (hl\u2081 a (mem_cons_self _ _)) hl\u2082\n    (h \u25b8 by rw prod_cons; exact dvd_mul_right _ _),\n  have hb : b :: l\u2082 ~ a :: (b :: l\u2082).erase a := perm_cons_erase ha,\n  have hl : prod l\u2081 = prod ((b :: l\u2082).erase a) :=\n  (nat.mul_right_inj (prime.pos (hl\u2081 a (mem_cons_self _ _)))).1 $\n    by rwa [\u2190 prod_cons, \u2190 prod_cons, \u2190 hb.prod_eq],\n  perm.trans ((perm_of_prod_eq_prod hl hl\u2081' hl\u2082').cons _) hb.symm\n\nlemma factors_unique {n : \u2115} {l : list \u2115} (h\u2081 : prod l = n) (h\u2082 : \u2200 p \u2208 l, prime p) :\n  l ~ factors n :=\nhave hn : 0 < n := nat.pos_of_ne_zero $ \u03bb h, begin\n  rw h at *, clear h,\n  induction l with a l hi,\n  { exact absurd h\u2081 dec_trivial },\n  { rw prod_cons at h\u2081,\n    exact nat.mul_ne_zero (ne_of_lt (prime.pos (h\u2082 a (mem_cons_self _ _)))).symm\n      (hi (\u03bb p hp, h\u2082 p (mem_cons_of_mem _ hp))) h\u2081 }\nend,\nperm_of_prod_eq_prod (by rwa prod_factors hn) h\u2082 (@prime_of_mem_factors _)\n\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m n k l : \u2115}\n      (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k+l+1) \u2223 m*n) :\n      p ^ (k+1) \u2223 m \u2228 p ^ (l+1) \u2223 n :=\nhave hpd : p^(k+l)*p \u2223 m*n, by rwa pow_succ' at hpmn,\nhave hpd2 : p \u2223 (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,\nhave hpd3 : p \u2223 (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,\nhave hpd4 : p \u2223 (m / p^k) * (n / p^l), by simpa [nat.div_mul_div hpm hpn] using hpd3,\nhave hpd5 : p \u2223 (m / p^k) \u2228 p \u2223 (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,\nsuffices p^k*p \u2223 m \u2228 p^l*p \u2223 n, by rwa [pow_succ', pow_succ'],\n  hpd5.elim\n    (assume : p \u2223 m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)\n    (assume : p \u2223 n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)\n\n/-- The type of prime numbers -/\ndef primes := {p : \u2115 // p.prime}\n\nnamespace primes\n\ninstance : has_repr nat.primes := \u27e8\u03bb p, repr p.val\u27e9\ninstance inhabited_primes : inhabited primes := \u27e8\u27e82, prime_two\u27e9\u27e9\n\ninstance coe_nat : has_coe nat.primes \u2115 := \u27e8subtype.val\u27e9\n\ntheorem coe_nat_inj (p q : nat.primes) : (p : \u2115) = (q : \u2115) \u2192 p = q :=\n\u03bb h, subtype.eq h\n\nend primes\n\ninstance monoid.prime_pow {\u03b1 : Type*} [monoid \u03b1] : has_pow \u03b1 primes := \u27e8\u03bb x p, x^p.val\u27e9\n\nend nat\n\n/-! ### Primality prover -/\n\nnamespace tactic\nnamespace norm_num\nopen norm_num\n\nlemma is_prime_helper (n : \u2115)\n  (h\u2081 : 1 < n) (h\u2082 : nat.min_fac n = n) : nat.prime n :=\nnat.prime_def_min_fac.2 \u27e8h\u2081, h\u2082\u27e9\n\nlemma min_fac_bit0 (n : \u2115) : nat.min_fac (bit0 n) = 2 :=\nby simp [nat.min_fac_eq, show 2 \u2223 bit0 n, by simp [bit0_eq_two_mul n]]\n\n/-- A predicate representing partial progress in a proof of `min_fac`. -/\ndef min_fac_helper (n k : \u2115) : Prop :=\n0 < k \u2227 bit1 k \u2264 nat.min_fac (bit1 n)\n\ntheorem min_fac_helper.n_pos {n k : \u2115} (h : min_fac_helper n k) : 0 < n :=\npos_iff_ne_zero.2 $ \u03bb e,\nby rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2\n\nlemma min_fac_ne_bit0 {n k : \u2115} : nat.min_fac (bit1 n) \u2260 bit0 k :=\nby rw bit0_eq_two_mul; exact \u03bb e, absurd\n  ((nat.dvd_add_iff_right (by simp [bit0_eq_two_mul n])).2\n    (dvd_trans \u27e8_, e\u27e9 (nat.min_fac_dvd _)))\n  (by norm_num)\n\nlemma min_fac_helper_0 (n : \u2115) (h : 0 < n) : min_fac_helper n 1 :=\nbegin\n  refine \u27e8zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symm\u27e9,\n  refine @lt_of_le_of_ne \u2115 _ _ _ (nat.min_fac_pos _) _,\n  intro e,\n  have := nat.min_fac_prime _,\n  { rw \u2190 e at this, exact nat.not_prime_one this },\n  { exact ne_of_gt (nat.bit1_lt h) }\nend\n\nlemma min_fac_helper_1 {n k k' : \u2115} (e : k + 1 = k')\n  (np : nat.min_fac (bit1 n) \u2260 bit1 k)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  rw \u2190 e,\n  refine \u27e8nat.succ_pos _,\n    (lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)\n      min_fac_ne_bit0.symm : bit0 (k+1) < _)\u27e9,\n  { rw add_right_comm, exact h.2 },\n  { rw add_right_comm, exact np.symm }\nend\n\nlemma min_fac_helper_2 (n k k' : \u2115) (e : k + 1 = k')\n  (np : \u00ac nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  intro e\u2081, rw \u2190 e\u2081 at np,\n  exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)\nend\n\nlemma min_fac_helper_3 (n k k' c : \u2115) (e : k + 1 = k')\n  (nc : bit1 n % bit1 k = c) (c0 : 0 < c)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  refine mt _ (ne_of_gt c0), intro e\u2081,\n  rw [\u2190 nc, \u2190 nat.dvd_iff_mod_eq_zero, \u2190 e\u2081],\n  apply nat.min_fac_dvd\nend\n\nlemma min_fac_helper_4 (n k : \u2115) (hd : bit1 n % bit1 k = 0)\n  (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=\nby rw \u2190 nat.dvd_iff_mod_eq_zero at hd; exact\nle_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2\n\nlemma min_fac_helper_5 (n k k' : \u2115) (e : bit1 k * bit1 k = k')\n  (hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=\nbegin\n  refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2\n    \u27e8nat.bit1_lt h.n_pos, _\u27e9)).2,\n  rw \u2190 e at hd,\n  intros m m2 hm md,\n  have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),\n  rw nat.le_sqrt at this,\n  exact not_le_of_lt hd this\nend\n\n/-- Given `e` a natural numeral and `d : nat` a factor of it, return `\u22a2 \u00ac prime e`. -/\nmeta def prove_non_prime (e : expr) (n d\u2081 : \u2115) : tactic expr :=\ndo let e\u2081 := reflect d\u2081,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n  let d\u2082 := n / d\u2081, let e\u2082 := reflect d\u2082,\n  (c, e', p) \u2190 prove_mul_nat c e\u2081 e\u2082,\n  guard (e' =\u2090 e),\n  (c, p\u2082) \u2190 prove_lt_nat c `(1) e\u2082,\n  return $ `(@nat.not_prime_mul').mk_app [e\u2081, e\u2082, e, p, p\u2081, p\u2082]\n\n/-- Given `a`,`a1 := bit1 a`, `n1` the value of `a1`, `b` and `p : min_fac_helper a b`,\n  returns `(c, \u22a2 min_fac a1 = c)`. -/\nmeta def prove_min_fac_aux (a a1 : expr) (n1 : \u2115) :\n  instance_cache \u2192 expr \u2192 expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| ic b p := do\n  k \u2190 b.to_nat,\n  let k1 := bit1 k,\n  let b1 := `(bit1:\u2115\u2192\u2115).mk_app [b],\n  if n1 < k1*k1 then do\n    (ic, e', p\u2081) \u2190 prove_mul_nat ic b1 b1,\n    (ic, p\u2082) \u2190 prove_lt_nat ic a1 e',\n    return (ic, a1, `(min_fac_helper_5).mk_app [a, b, e', p\u2081, p\u2082, p])\n  else let d := k1.min_fac in\n  if to_bool (d < k1) then do\n    let k' := k+1, let e' := reflect k',\n    (ic, p\u2081) \u2190 prove_succ ic b e',\n    p\u2082 \u2190 prove_non_prime b1 k1 d,\n    prove_min_fac_aux ic e' $ `(min_fac_helper_2).mk_app [a, b, e', p\u2081, p\u2082, p]\n  else do\n    let nc := n1 % k1,\n    (ic, c, pc) \u2190 prove_div_mod ic a1 b1 tt,\n    if nc = 0 then\n      return (ic, b1, `(min_fac_helper_4).mk_app [a, b, pc, p])\n    else do\n      (ic, p\u2080) \u2190 prove_pos ic c,\n      let k' := k+1, let e' := reflect k',\n      (ic, p\u2081) \u2190 prove_succ ic b e',\n      prove_min_fac_aux ic e' $ `(min_fac_helper_3).mk_app [a, b, e', c, p\u2081, pc, p\u2080, p]\n\n/-- Given `a` a natural numeral, returns `(b, \u22a2 min_fac a = b)`. -/\nmeta def prove_min_fac (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\nmatch match_numeral e with\n| match_numeral_result.zero := return (ic, `(2:\u2115), `(nat.min_fac_zero))\n| match_numeral_result.one := return (ic, `(1:\u2115), `(nat.min_fac_one))\n| match_numeral_result.bit0 e := return (ic, `(2), `(min_fac_bit0).mk_app [e])\n| match_numeral_result.bit1 e := do\n  n \u2190 e.to_nat,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p) \u2190 prove_pos c e,\n  let a1 := `(bit1:\u2115\u2192\u2115).mk_app [e],\n  prove_min_fac_aux e a1 (bit1 n) c `(1) (`(min_fac_helper_0).mk_app [e, p])\n| _ := failed\nend\n\n/-- Evaluates the `prime` and `min_fac` functions. -/\n@[norm_num] meta def eval_prime : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.prime %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := false_intro `(nat.not_prime_zero)\n  | 1 := false_intro `(nat.not_prime_one)\n  | _ := let d\u2081 := n.min_fac in\n    if d\u2081 < n then prove_non_prime e n d\u2081 >>= false_intro\n    else do\n      let e\u2081 := reflect d\u2081,\n      c \u2190 mk_instance_cache `(nat),\n      (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n      (c, e\u2081, p) \u2190 prove_min_fac c e,\n      true_intro $ `(is_prime_helper).mk_app [e, p\u2081, p]\n  end\n| `(nat.min_fac %%e) := do\n  ic \u2190 mk_instance_cache `(\u2115),\n  prod.snd <$> prove_min_fac ic e\n| _ := failed\n\nend norm_num\nend tactic\n\nnamespace nat\n\ntheorem prime_three : prime 3 := by norm_num\n\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8577680995361898, "lm_q1q2_score": 0.7437156188625039}}
{"text": "-- Union_con_la_imagen_inversa.lean\n-- Uni\u00f3n con la imagen inversa\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 22 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariable  s : set \u03b1\nvariable  v : set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\nbegin\n  intros x hx,\n  rw mem_preimage,\n  cases hx with xs xv,\n  { apply mem_union_left,\n    apply mem_image_of_mem,\n    exact xs, },\n  { apply mem_union_right,\n    rw \u2190 mem_preimage,\n    exact xv, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\nbegin\n  intros x hx,\n  cases hx with xs xv,\n  { apply mem_union_left,\n    apply mem_image_of_mem,\n    exact xs, },\n  { apply mem_union_right,\n    exact xv, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\nbegin\n  rintros x (xs | xv),\n  { left,\n    exact mem_image_of_mem f xs, },\n  { right,\n    exact xv, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\nbegin\n  rintros x (xs | xv),\n  { exact or.inl (mem_image_of_mem f xs), },\n  { exact or.inr xv, },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\nbegin\n  intros x h,\n  exact or.elim h (\u03bb xs, or.inl (mem_image_of_mem f xs)) or.inr,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\n\u03bb x h, or.elim h (\u03bb xs, or.inl (mem_image_of_mem f xs)) or.inr\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\nbegin\n  rintros x (xs | xv),\n  { show f x \u2208 f '' s \u222a v,\n    use [x, xs, rfl] },\n  { show f x \u2208 f '' s \u222a v,\n    right,\n    apply xv },\nend\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u222a v) :=\nunion_preimage_subset s v f\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Union_con_la_imagen_inversa.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.7437155991929548}}
{"text": "-- Neutro_derecha.lean\n-- Si G es un grupo y a \u2208 G, entonces a * 1 = a\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 15-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si G es un grupo y a \u2208 G, entonces\n--    a * 1 = a\n-- ----------------------------------------------------------------------\n\nimport algebra.group\nvariables {G : Type*} [group G]\nvariables a : G\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * 1 = a :=\ncalc\n  a * 1 = a * (a\u207b\u00b9 * a) : congr_arg (\u03bb x, a * x) (mul_left_inv a).symm\n    ... = (a * a\u207b\u00b9) * a : (mul_assoc a a\u207b\u00b9 a).symm\n    ... = 1 * a         : congr_arg (\u03bb x, x* a) (mul_right_inv a)\n    ... = a             : one_mul a\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * 1 = a :=\ncalc\n  a * 1 = a * (a\u207b\u00b9 * a) : by rw mul_left_inv\n    ... = (a * a\u207b\u00b9) * a : by rw mul_assoc\n    ... = 1 * a         : by rw mul_right_inv\n    ... = a             : by rw one_mul\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * 1 = a :=\ncalc\n  a * 1 = a * (a\u207b\u00b9 * a) : by simp\n    ... = (a * a\u207b\u00b9) * a : by simp\n    ... = 1 * a         : by simp\n    ... = a             : by simp\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * 1 = a :=\nby simp\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * 1 = a :=\n-- by library_search\nmul_one a\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Neutro_derecha.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7436980445085951}}
{"text": "/-\nCopyright (c) 2021 Martin Zinkevich. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Martin Zinkevich, R\u00e9my Degenne\n-/\nimport logic.encodable.lattice\nimport measure_theory.measurable_space_def\n\n/-!\n# Induction principles for measurable sets, related to \u03c0-systems and \u03bb-systems.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main statements\n\n* The main theorem of this file is Dynkin's \u03c0-\u03bb theorem, which appears\n  here as an induction principle `induction_on_inter`. Suppose `s` is a\n  collection of subsets of `\u03b1` such that the intersection of two members\n  of `s` belongs to `s` whenever it is nonempty. Let `m` be the \u03c3-algebra\n  generated by `s`. In order to check that a predicate `C` holds on every\n  member of `m`, it suffices to check that `C` holds on the members of `s` and\n  that `C` is preserved by complementation and *disjoint* countable\n  unions.\n\n* The proof of this theorem relies on the notion of `is_pi_system`, i.e., a collection of sets\n  which is closed under binary non-empty intersections. Note that this is a small variation around\n  the usual notion in the literature, which often requires that a \u03c0-system is non-empty, and closed\n  also under disjoint intersections. This variation turns out to be convenient for the\n  formalization.\n\n* The proof of Dynkin's \u03c0-\u03bb theorem also requires the notion of `dynkin_system`, i.e., a collection\n  of sets which contains the empty set, is closed under complementation and under countable union\n  of pairwise disjoint sets. The disjointness condition is the only difference with `\u03c3`-algebras.\n\n* `generate_pi_system g` gives the minimal \u03c0-system containing `g`.\n  This can be considered a Galois insertion into both measurable spaces and sets.\n\n* `generate_from_generate_pi_system_eq` proves that if you start from a collection of sets `g`,\n  take the generated \u03c0-system, and then the generated \u03c3-algebra, you get the same result as\n  the \u03c3-algebra generated from `g`. This is useful because there are connections between\n  independent sets that are \u03c0-systems and the generated independent spaces.\n\n* `mem_generate_pi_system_Union_elim` and `mem_generate_pi_system_Union_elim'` show that any\n  element of the \u03c0-system generated from the union of a set of \u03c0-systems can be\n  represented as the intersection of a finite number of elements from these sets.\n\n* `pi_Union_Inter` defines a new \u03c0-system from a family of \u03c0-systems `\u03c0 : \u03b9 \u2192 set (set \u03b1)` and a\n  set of indices `S : set \u03b9`. `pi_Union_Inter \u03c0 S` is the set of sets that can be written\n  as `\u22c2 x \u2208 t, f x` for some finset `t \u2208 S` and sets `f x \u2208 \u03c0 x`.\n\n## Implementation details\n\n* `is_pi_system` is a predicate, not a type. Thus, we don't explicitly define the galois\n  insertion, nor do we define a complete lattice. In theory, we could define a complete\n  lattice and galois insertion on the subtype corresponding to `is_pi_system`.\n-/\n\nopen measurable_space set\nopen_locale classical measure_theory\n\n/-- A \u03c0-system is a collection of subsets of `\u03b1` that is closed under binary intersection of\n  non-disjoint sets. Usually it is also required that the collection is nonempty, but we don't do\n  that here. -/\ndef is_pi_system {\u03b1} (C : set (set \u03b1)) : Prop :=\n\u2200 s t \u2208 C, (s \u2229 t : set \u03b1).nonempty \u2192 s \u2229 t \u2208 C\n\nnamespace measurable_space\n\nlemma is_pi_system_measurable_set {\u03b1:Type*} [measurable_space \u03b1] :\n  is_pi_system {s : set \u03b1 | measurable_set s} :=\n\u03bb s hs t ht _, hs.inter ht\n\nend measurable_space\n\nlemma is_pi_system.singleton {\u03b1} (S : set \u03b1) : is_pi_system ({S} : set (set \u03b1)) :=\nbegin\n  intros s h_s t h_t h_ne,\n  rw [set.mem_singleton_iff.1 h_s, set.mem_singleton_iff.1 h_t, set.inter_self,\n      set.mem_singleton_iff],\nend\n\nlemma is_pi_system.insert_empty {\u03b1} {S : set (set \u03b1)} (h_pi : is_pi_system S) :\n  is_pi_system (insert \u2205 S) :=\nbegin\n  intros s hs t ht hst,\n  cases hs,\n  { simp [hs], },\n  { cases ht,\n    { simp [ht], },\n    { exact set.mem_insert_of_mem _ (h_pi s hs t ht hst), }, },\nend\n\nlemma is_pi_system.insert_univ {\u03b1} {S : set (set \u03b1)} (h_pi : is_pi_system S) :\n  is_pi_system (insert set.univ S) :=\nbegin\n  intros s hs t ht hst,\n  cases hs,\n  { cases ht; simp [hs, ht], },\n  { cases ht,\n    { simp [hs, ht], },\n    { exact set.mem_insert_of_mem _ (h_pi s hs t ht hst), }, },\nend\n\nlemma is_pi_system.comap {\u03b1 \u03b2} {S : set (set \u03b2)} (h_pi : is_pi_system S) (f : \u03b1 \u2192 \u03b2) :\n  is_pi_system {s : set \u03b1 | \u2203 t \u2208 S, f \u207b\u00b9' t = s} :=\nbegin\n  rintros _ \u27e8s, hs_mem, rfl\u27e9 _ \u27e8t, ht_mem, rfl\u27e9 hst,\n  rw \u2190 set.preimage_inter at hst \u22a2,\n  refine \u27e8s \u2229 t, h_pi s hs_mem t ht_mem _, rfl\u27e9,\n  by_contra,\n  rw set.not_nonempty_iff_eq_empty at h,\n  rw h at hst,\n  simpa using hst,\nend\n\nlemma is_pi_system_Union_of_directed_le {\u03b1 \u03b9} (p : \u03b9 \u2192 set (set \u03b1))\n  (hp_pi : \u2200 n, is_pi_system (p n)) (hp_directed : directed (\u2264) p) :\n  is_pi_system (\u22c3 n, p n) :=\nbegin\n  intros t1 ht1 t2 ht2 h,\n  rw set.mem_Union at ht1 ht2 \u22a2,\n  cases ht1 with n ht1,\n  cases ht2 with m ht2,\n  obtain \u27e8k, hpnk, hpmk\u27e9 : \u2203 k, p n \u2264 p k \u2227 p m \u2264 p k := hp_directed n m,\n  exact \u27e8k, hp_pi k t1 (hpnk ht1) t2 (hpmk ht2) h\u27e9,\nend\n\nlemma is_pi_system_Union_of_monotone {\u03b1 \u03b9} [semilattice_sup \u03b9] (p : \u03b9 \u2192 set (set \u03b1))\n  (hp_pi : \u2200 n, is_pi_system (p n)) (hp_mono : monotone p) :\n  is_pi_system (\u22c3 n, p n) :=\nis_pi_system_Union_of_directed_le p hp_pi (monotone.directed_le hp_mono)\n\nsection order\n\nvariables {\u03b1 : Type*} {\u03b9 \u03b9' : Sort*} [linear_order \u03b1]\n\nlemma is_pi_system_image_Iio (s : set \u03b1) : is_pi_system (Iio '' s) :=\nbegin\n  rintro _ \u27e8a, ha, rfl\u27e9 _ \u27e8b, hb, rfl\u27e9 -,\n  exact \u27e8a \u2293 b, inf_ind a b ha hb, Iio_inter_Iio.symm\u27e9\nend\n\nlemma is_pi_system_Iio : is_pi_system (range Iio : set (set \u03b1)) :=\n@image_univ \u03b1 _ Iio \u25b8 is_pi_system_image_Iio univ\n\nlemma is_pi_system_image_Ioi (s : set \u03b1) : is_pi_system (Ioi '' s) :=\n@is_pi_system_image_Iio \u03b1\u1d52\u1d48 _ s\n\nlemma is_pi_system_Ioi : is_pi_system (range Ioi : set (set \u03b1)) :=\n@image_univ \u03b1 _ Ioi \u25b8 is_pi_system_image_Ioi univ\n\nlemma is_pi_system_Ixx_mem {Ixx : \u03b1 \u2192 \u03b1 \u2192 set \u03b1} {p : \u03b1 \u2192 \u03b1 \u2192 Prop}\n  (Hne : \u2200 {a b}, (Ixx a b).nonempty \u2192 p a b)\n  (Hi : \u2200 {a\u2081 b\u2081 a\u2082 b\u2082}, Ixx a\u2081 b\u2081 \u2229 Ixx a\u2082 b\u2082 = Ixx (max a\u2081 a\u2082) (min b\u2081 b\u2082)) (s t : set \u03b1) :\n  is_pi_system {S | \u2203 (l \u2208 s) (u \u2208 t) (hlu : p l u), Ixx l u = S} :=\nbegin\n  rintro _ \u27e8l\u2081, hls\u2081, u\u2081, hut\u2081, hlu\u2081, rfl\u27e9 _ \u27e8l\u2082, hls\u2082, u\u2082, hut\u2082, hlu\u2082, rfl\u27e9,\n  simp only [Hi, \u2190 sup_eq_max, \u2190 inf_eq_min],\n  exact \u03bb H, \u27e8l\u2081 \u2294 l\u2082, sup_ind l\u2081 l\u2082 hls\u2081 hls\u2082, u\u2081 \u2293 u\u2082, inf_ind u\u2081 u\u2082 hut\u2081 hut\u2082, Hne H, rfl\u27e9\nend\n\nlemma is_pi_system_Ixx {Ixx : \u03b1 \u2192 \u03b1 \u2192 set \u03b1} {p : \u03b1 \u2192 \u03b1 \u2192 Prop}\n  (Hne : \u2200 {a b}, (Ixx a b).nonempty \u2192 p a b)\n  (Hi : \u2200 {a\u2081 b\u2081 a\u2082 b\u2082}, Ixx a\u2081 b\u2081 \u2229 Ixx a\u2082 b\u2082 = Ixx (max a\u2081 a\u2082) (min b\u2081 b\u2082))\n  (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n  @is_pi_system \u03b1 ({S | \u2203 i j (h : p (f i) (g j)), Ixx (f i) (g j) = S}) :=\nby simpa only [exists_range_iff] using is_pi_system_Ixx_mem @Hne @Hi (range f) (range g)\n\nlemma is_pi_system_Ioo_mem (s t : set \u03b1) :\n  is_pi_system {S | \u2203 (l \u2208 s) (u \u2208 t) (h : l < u), Ioo l u = S} :=\nis_pi_system_Ixx_mem (\u03bb a b \u27e8x, hax, hxb\u27e9, hax.trans hxb) (\u03bb _ _ _ _, Ioo_inter_Ioo) s t\n\nlemma is_pi_system_Ioo (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n  @is_pi_system \u03b1 {S | \u2203 l u (h : f l < g u), Ioo (f l) (g u) = S} :=\nis_pi_system_Ixx (\u03bb a b \u27e8x, hax, hxb\u27e9, hax.trans hxb) (\u03bb _ _ _ _, Ioo_inter_Ioo) f g\n\nlemma is_pi_system_Ioc_mem (s t : set \u03b1) :\n  is_pi_system {S | \u2203 (l \u2208 s) (u \u2208 t) (h : l < u), Ioc l u = S} :=\nis_pi_system_Ixx_mem (\u03bb a b \u27e8x, hax, hxb\u27e9, hax.trans_le hxb) (\u03bb _ _ _ _, Ioc_inter_Ioc) s t\n\nlemma is_pi_system_Ioc (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n  @is_pi_system \u03b1 {S | \u2203 i j (h : f i < g j), Ioc (f i) (g j) = S} :=\nis_pi_system_Ixx (\u03bb a b \u27e8x, hax, hxb\u27e9, hax.trans_le hxb) (\u03bb _ _ _ _, Ioc_inter_Ioc) f g\n\nlemma is_pi_system_Ico_mem (s t : set \u03b1) :\n  is_pi_system {S | \u2203 (l \u2208 s) (u \u2208 t) (h : l < u), Ico l u = S} :=\nis_pi_system_Ixx_mem (\u03bb a b \u27e8x, hax, hxb\u27e9, hax.trans_lt hxb) (\u03bb _ _ _ _, Ico_inter_Ico) s t\n\nlemma is_pi_system_Ico (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n  @is_pi_system \u03b1 {S | \u2203 i j (h : f i < g j), Ico (f i) (g j) = S} :=\nis_pi_system_Ixx (\u03bb a b \u27e8x, hax, hxb\u27e9, hax.trans_lt hxb) (\u03bb _ _ _ _, Ico_inter_Ico) f g\n\nlemma is_pi_system_Icc_mem (s t : set \u03b1) :\n  is_pi_system {S | \u2203 (l \u2208 s) (u \u2208 t) (h : l \u2264 u), Icc l u = S} :=\nis_pi_system_Ixx_mem (\u03bb a b, nonempty_Icc.1) (\u03bb _ _ _ _, Icc_inter_Icc) s t\n\nlemma is_pi_system_Icc (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n  @is_pi_system \u03b1 {S | \u2203 i j (h : f i \u2264 g j), Icc (f i) (g j) = S} :=\nis_pi_system_Ixx (\u03bb a b, nonempty_Icc.1) (\u03bb _ _ _ _, Icc_inter_Icc) f g\n\nend order\n\n/-- Given a collection `S` of subsets of `\u03b1`, then `generate_pi_system S` is the smallest\n\u03c0-system containing `S`. -/\ninductive generate_pi_system {\u03b1} (S : set (set \u03b1)) : set (set \u03b1)\n| base {s : set \u03b1} (h_s : s \u2208 S) : generate_pi_system s\n| inter {s t : set \u03b1} (h_s : generate_pi_system s) (h_t : generate_pi_system t)\n  (h_nonempty : (s \u2229 t).nonempty) : generate_pi_system (s \u2229 t)\n\nlemma is_pi_system_generate_pi_system {\u03b1} (S : set (set \u03b1)) :\n  is_pi_system (generate_pi_system S) :=\n\u03bb s h_s t h_t h_nonempty, generate_pi_system.inter h_s h_t h_nonempty\n\nlemma subset_generate_pi_system_self {\u03b1} (S : set (set \u03b1)) : S \u2286 generate_pi_system S :=\n\u03bb s, generate_pi_system.base\n\nlemma generate_pi_system_subset_self {\u03b1} {S : set (set \u03b1)} (h_S : is_pi_system S) :\n  generate_pi_system S \u2286 S :=\nbegin\n  intros x h,\n  induction h with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,\n  { exact h_s, },\n  { exact h_S _ h_s _ h_u h_nonempty, },\nend\n\nlemma generate_pi_system_eq {\u03b1} {S : set (set \u03b1)} (h_pi : is_pi_system S) :\n  generate_pi_system S = S :=\nset.subset.antisymm (generate_pi_system_subset_self h_pi) (subset_generate_pi_system_self S)\n\nlemma generate_pi_system_mono {\u03b1} {S T : set (set \u03b1)} (hST : S \u2286 T) :\n  generate_pi_system S \u2286 generate_pi_system T :=\nbegin\n  intros t ht,\n  induction ht with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,\n  { exact generate_pi_system.base (set.mem_of_subset_of_mem hST h_s),},\n  { exact is_pi_system_generate_pi_system T _ h_s _ h_u h_nonempty, },\nend\n\nlemma generate_pi_system_measurable_set {\u03b1} [M : measurable_space \u03b1] {S : set (set \u03b1)}\n  (h_meas_S : \u2200 s \u2208 S, measurable_set s) (t : set \u03b1)\n  (h_in_pi : t \u2208 generate_pi_system S) : measurable_set t :=\nbegin\n  induction h_in_pi with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,\n  { apply h_meas_S _ h_s, },\n  { apply measurable_set.inter h_s h_u, },\nend\n\nlemma generate_from_measurable_set_of_generate_pi_system {\u03b1} {g : set (set \u03b1)} (t : set \u03b1)\n  (ht : t \u2208 generate_pi_system g) :\n  measurable_set[generate_from g] t :=\n@generate_pi_system_measurable_set \u03b1 (generate_from g) g\n  (\u03bb s h_s_in_g, measurable_set_generate_from h_s_in_g) t ht\n\nlemma generate_from_generate_pi_system_eq {\u03b1} {g : set (set \u03b1)} :\n  generate_from (generate_pi_system g) = generate_from g :=\nbegin\n  apply le_antisymm; apply generate_from_le,\n  { exact \u03bb t h_t, generate_from_measurable_set_of_generate_pi_system t h_t, },\n  { exact \u03bb t h_t, measurable_set_generate_from (generate_pi_system.base h_t), },\nend\n\n/- Every element of the \u03c0-system generated by the union of a family of \u03c0-systems\nis a finite intersection of elements from the \u03c0-systems.\nFor an indexed union version, see `mem_generate_pi_system_Union_elim'`. -/\nlemma mem_generate_pi_system_Union_elim {\u03b1 \u03b2} {g : \u03b2 \u2192 set (set \u03b1)}\n  (h_pi : \u2200 b, is_pi_system (g b)) (t : set \u03b1) (h_t : t \u2208 generate_pi_system (\u22c3 b, g b)) :\n  \u2203 (T : finset \u03b2) (f : \u03b2 \u2192 set \u03b1), (t = \u22c2 b \u2208 T, f b) \u2227 (\u2200 b \u2208 T, f b \u2208 g b) :=\nbegin\n  induction h_t with s h_s s t' h_gen_s h_gen_t' h_nonempty h_s h_t',\n  { rcases h_s with \u27e8t', \u27e8\u27e8b, rfl\u27e9, h_s_in_t'\u27e9\u27e9,\n    refine \u27e8{b}, (\u03bb _, s), _\u27e9,\n    simpa using h_s_in_t', },\n  { rcases h_t' with \u27e8T_t', \u27e8f_t', \u27e8rfl, h_t'\u27e9\u27e9\u27e9,\n    rcases h_s with \u27e8T_s, \u27e8f_s, \u27e8rfl, h_s\u27e9 \u27e9 \u27e9,\n    use [(T_s \u222a T_t'), (\u03bb (b:\u03b2),\n      if (b \u2208 T_s) then (if (b \u2208 T_t') then (f_s b \u2229 (f_t' b)) else (f_s b))\n      else (if (b \u2208 T_t') then (f_t' b) else (\u2205 : set \u03b1)))],\n    split,\n    { ext a,\n      simp_rw [set.mem_inter_iff, set.mem_Inter, finset.mem_union, or_imp_distrib],\n      rw \u2190 forall_and_distrib,\n      split; intros h1 b; by_cases hbs : b \u2208 T_s; by_cases hbt : b \u2208 T_t'; specialize h1 b;\n        simp only [hbs, hbt, if_true, if_false, true_implies_iff, and_self, false_implies_iff,\n          and_true, true_and] at h1 \u22a2,\n      all_goals { exact h1, }, },\n    intros b h_b,\n    split_ifs with hbs hbt hbt,\n    { refine h_pi b (f_s b) (h_s b hbs) (f_t' b) (h_t' b hbt) (set.nonempty.mono _ h_nonempty),\n      exact set.inter_subset_inter (set.bInter_subset_of_mem hbs) (set.bInter_subset_of_mem hbt), },\n    { exact h_s b hbs, },\n    { exact h_t' b hbt, },\n    { rw finset.mem_union at h_b,\n      apply false.elim (h_b.elim hbs hbt), }, },\nend\n\n/- Every element of the \u03c0-system generated by an indexed union of a family of \u03c0-systems\nis a finite intersection of elements from the \u03c0-systems.\nFor a total union version, see `mem_generate_pi_system_Union_elim`. -/\nlemma mem_generate_pi_system_Union_elim' {\u03b1 \u03b2} {g : \u03b2 \u2192 set (set \u03b1)} {s : set \u03b2}\n  (h_pi : \u2200 b \u2208 s, is_pi_system (g b)) (t : set \u03b1) (h_t : t \u2208 generate_pi_system (\u22c3 b \u2208 s, g b)) :\n  \u2203 (T : finset \u03b2) (f : \u03b2 \u2192 set \u03b1), (\u2191T \u2286 s) \u2227 (t = \u22c2 b \u2208 T, f b) \u2227 (\u2200 b \u2208 T, f b \u2208 g b) :=\nbegin\n  have : t \u2208 generate_pi_system (\u22c3 (b : subtype s), (g \u2218 subtype.val) b),\n  { suffices h1 : (\u22c3 (b : subtype s), (g \u2218 subtype.val) b) = (\u22c3 b \u2208 s, g b), by rwa h1,\n    ext x,\n    simp only [exists_prop, set.mem_Union, function.comp_app, subtype.exists, subtype.coe_mk],\n    refl },\n  rcases @mem_generate_pi_system_Union_elim \u03b1 (subtype s) (g \u2218 subtype.val)\n    (\u03bb b, h_pi b.val b.property) t this with \u27e8T, \u27e8f, \u27e8rfl, h_t'\u27e9\u27e9\u27e9,\n  refine \u27e8T.image subtype.val, function.extend subtype.val f (\u03bb b : \u03b2, (\u2205 : set \u03b1)), by simp, _, _\u27e9,\n  { ext a, split;\n    { simp only [set.mem_Inter, subtype.forall, finset.set_bInter_finset_image],\n      intros h1 b h_b h_b_in_T,\n      have h2 := h1 b h_b h_b_in_T,\n      revert h2,\n      rw subtype.val_injective.extend_apply,\n      apply id } },\n  { intros b h_b,\n    simp_rw [finset.mem_image, exists_prop, subtype.exists,\n             exists_and_distrib_right, exists_eq_right] at h_b,\n    cases h_b,\n    have h_b_alt : b = (subtype.mk b h_b_w).val := rfl,\n    rw [h_b_alt, subtype.val_injective.extend_apply],\n    apply h_t',\n    apply h_b_h },\nend\n\nsection Union_Inter\n\nvariables {\u03b1 \u03b9 : Type*}\n\n/-! ### \u03c0-system generated by finite intersections of sets of a \u03c0-system family -/\n\n/-- From a set of indices `S : set \u03b9` and a family of sets of sets `\u03c0 : \u03b9 \u2192 set (set \u03b1)`,\ndefine the set of sets that can be written as `\u22c2 x \u2208 t, f x` for some finset `t \u2286 S` and sets\n`f x \u2208 \u03c0 x`. If `\u03c0` is a family of \u03c0-systems, then it is a \u03c0-system. -/\ndef pi_Union_Inter (\u03c0 : \u03b9 \u2192 set (set \u03b1)) (S : set \u03b9) : set (set \u03b1) :=\n{s : set \u03b1 | \u2203 (t : finset \u03b9) (htS : \u2191t \u2286 S) (f : \u03b9 \u2192 set \u03b1) (hf : \u2200 x, x \u2208 t \u2192 f x \u2208 \u03c0 x),\n  s = \u22c2 x \u2208 t, f x}\n\nlemma pi_Union_Inter_singleton (\u03c0 : \u03b9 \u2192 set (set \u03b1)) (i : \u03b9) :\n  pi_Union_Inter \u03c0 {i} = \u03c0 i \u222a {univ} :=\nbegin\n  ext1 s,\n  simp only [pi_Union_Inter, exists_prop, mem_union],\n  refine \u27e8_, \u03bb h, _\u27e9,\n  { rintros \u27e8t, hti, f, hf\u03c0, rfl\u27e9,\n    simp only [subset_singleton_iff, finset.mem_coe] at hti,\n    by_cases hi : i \u2208 t,\n    { have ht_eq_i : t = {i},\n      { ext1 x, rw finset.mem_singleton, exact \u27e8\u03bb h, hti x h, \u03bb h, h.symm \u25b8 hi\u27e9, },\n      simp only [ht_eq_i, finset.mem_singleton, Inter_Inter_eq_left],\n      exact or.inl (hf\u03c0 i hi), },\n     { have ht_empty : t = \u2205,\n      { ext1 x,\n        simp only [finset.not_mem_empty, iff_false],\n        exact \u03bb hx, hi (hti x hx \u25b8 hx), },\n      simp only [ht_empty, Inter_false, Inter_univ, set.mem_singleton univ, or_true], }, },\n  { cases h with hs hs,\n    { refine \u27e8{i}, _, \u03bb _, s, \u27e8\u03bb x hx, _, _\u27e9\u27e9,\n      { rw finset.coe_singleton, },\n      { rw finset.mem_singleton at hx,\n        rwa hx, },\n      { simp only [finset.mem_singleton, Inter_Inter_eq_left], }, },\n    { refine \u27e8\u2205, _\u27e9,\n      simpa only [finset.coe_empty, subset_singleton_iff, mem_empty_iff_false, is_empty.forall_iff,\n        implies_true_iff, finset.not_mem_empty, Inter_false, Inter_univ, true_and, exists_const]\n        using hs, }, },\nend\n\nlemma pi_Union_Inter_singleton_left (s : \u03b9 \u2192 set \u03b1) (S : set \u03b9) :\n  pi_Union_Inter (\u03bb i, ({s i} : set (set \u03b1))) S\n    = {s' : set \u03b1 | \u2203 (t : finset \u03b9) (htS : \u2191t \u2286 S), s' = \u22c2 i \u2208 t, s i} :=\nbegin\n  ext1 s',\n  simp_rw [pi_Union_Inter, set.mem_singleton_iff, exists_prop, set.mem_set_of_eq],\n  refine \u27e8\u03bb h, _, \u03bb \u27e8t, htS, h_eq\u27e9, \u27e8t, htS, s, \u03bb _ _, rfl, h_eq\u27e9\u27e9,\n  obtain \u27e8t, htS, f, hft_eq, rfl\u27e9 := h,\n  refine \u27e8t, htS, _\u27e9,\n  congr' with i x,\n  simp_rw set.mem_Inter,\n  exact \u27e8\u03bb h hit, by { rw \u2190 hft_eq i hit, exact h hit, },\n    \u03bb h hit, by { rw hft_eq i hit, exact h hit, }\u27e9,\nend\n\nlemma generate_from_pi_Union_Inter_singleton_left (s : \u03b9 \u2192 set \u03b1) (S : set \u03b9) :\n  generate_from (pi_Union_Inter (\u03bb k, {s k}) S) = generate_from {t | \u2203 k \u2208 S, s k = t} :=\nbegin\n  refine le_antisymm (generate_from_le _) (generate_from_mono _),\n  { rintro _ \u27e8I, hI, f, hf, rfl\u27e9,\n    refine finset.measurable_set_bInter _ (\u03bb m hm, measurable_set_generate_from _),\n    exact \u27e8m, hI hm, (hf m hm).symm\u27e9, },\n  { rintro _ \u27e8k, hk, rfl\u27e9,\n    refine \u27e8{k}, \u03bb m hm, _, s, \u03bb i hi, _, _\u27e9,\n    { rw [finset.mem_coe, finset.mem_singleton] at hm,\n      rwa hm, },\n    { exact set.mem_singleton _, },\n    { simp only [finset.mem_singleton, set.Inter_Inter_eq_left], }, },\nend\n\n/-- If `\u03c0` is a family of \u03c0-systems, then `pi_Union_Inter \u03c0 S` is a \u03c0-system. -/\nlemma is_pi_system_pi_Union_Inter (\u03c0 : \u03b9 \u2192 set (set \u03b1))\n  (hpi : \u2200 x, is_pi_system (\u03c0 x)) (S : set \u03b9) :\n  is_pi_system (pi_Union_Inter \u03c0 S) :=\nbegin\n  rintros t1 \u27e8p1, hp1S, f1, hf1m, ht1_eq\u27e9 t2 \u27e8p2, hp2S, f2, hf2m, ht2_eq\u27e9 h_nonempty,\n  simp_rw [pi_Union_Inter, set.mem_set_of_eq],\n  let g := \u03bb n, (ite (n \u2208 p1) (f1 n) set.univ) \u2229 (ite (n \u2208 p2) (f2 n) set.univ),\n  have hp_union_ss : \u2191(p1 \u222a p2) \u2286 S,\n  { simp only [hp1S, hp2S, finset.coe_union, union_subset_iff, and_self], },\n  use [p1 \u222a p2, hp_union_ss, g],\n  have h_inter_eq : t1 \u2229 t2 = \u22c2 i \u2208 p1 \u222a p2, g i,\n  { rw [ht1_eq, ht2_eq],\n    simp_rw [\u2190 set.inf_eq_inter, g],\n    ext1 x,\n    simp only [inf_eq_inter, mem_inter_iff, mem_Inter, finset.mem_union],\n    refine \u27e8\u03bb h i hi_mem_union, _, \u03bb h, \u27e8\u03bb i hi1, _, \u03bb i hi2, _\u27e9\u27e9,\n    { split_ifs,\n      exacts [\u27e8h.1 i h_1, h.2 i h_2\u27e9, \u27e8h.1 i h_1, set.mem_univ _\u27e9,\n        \u27e8set.mem_univ _, h.2 i h_2\u27e9, \u27e8set.mem_univ _, set.mem_univ _\u27e9], },\n    { specialize h i (or.inl hi1),\n      rw if_pos hi1 at h,\n      exact h.1, },\n    { specialize h i (or.inr hi2),\n      rw if_pos hi2 at h,\n      exact h.2, }, },\n  refine \u27e8\u03bb n hn, _, h_inter_eq\u27e9,\n  simp_rw g,\n  split_ifs with hn1 hn2,\n  { refine hpi n (f1 n) (hf1m n hn1) (f2 n) (hf2m n hn2) (set.nonempty_iff_ne_empty.2 (\u03bb h, _)),\n    rw h_inter_eq at h_nonempty,\n    suffices h_empty : (\u22c2 i \u2208 p1 \u222a p2, g i) = \u2205,\n      from (set.not_nonempty_iff_eq_empty.mpr h_empty) h_nonempty,\n    refine le_antisymm (set.Inter_subset_of_subset n _) (set.empty_subset _),\n    refine set.Inter_subset_of_subset hn _,\n    simp_rw [g, if_pos hn1, if_pos hn2],\n    exact h.subset, },\n  { simp [hf1m n hn1], },\n  { simp [hf2m n h], },\n  { exact absurd hn (by simp [hn1, h]), },\nend\n\nlemma pi_Union_Inter_mono_left {\u03c0 \u03c0' : \u03b9 \u2192 set (set \u03b1)} (h_le : \u2200 i, \u03c0 i \u2286 \u03c0' i) (S : set \u03b9) :\n  pi_Union_Inter \u03c0 S \u2286 pi_Union_Inter \u03c0' S :=\n\u03bb s \u27e8t, ht_mem, ft, hft_mem_pi, h_eq\u27e9, \u27e8t, ht_mem, ft, \u03bb x hxt, h_le x (hft_mem_pi x hxt), h_eq\u27e9\n\nlemma pi_Union_Inter_mono_right {\u03c0 : \u03b9 \u2192 set (set \u03b1)} {S T : set \u03b9} (hST : S \u2286 T) :\n  pi_Union_Inter \u03c0 S \u2286 pi_Union_Inter \u03c0 T :=\n\u03bb s \u27e8t, ht_mem, ft, hft_mem_pi, h_eq\u27e9, \u27e8t, ht_mem.trans hST, ft, hft_mem_pi, h_eq\u27e9\n\nlemma generate_from_pi_Union_Inter_le {m : measurable_space \u03b1}\n  (\u03c0 : \u03b9 \u2192 set (set \u03b1)) (h : \u2200 n, generate_from (\u03c0 n) \u2264 m) (S : set \u03b9) :\n  generate_from (pi_Union_Inter \u03c0 S) \u2264 m :=\nbegin\n  refine generate_from_le _,\n  rintros t \u27e8ht_p, ht_p_mem, ft, hft_mem_pi, rfl\u27e9,\n  refine finset.measurable_set_bInter _ (\u03bb x hx_mem, (h x) _ _),\n  exact measurable_set_generate_from (hft_mem_pi x hx_mem),\nend\n\nlemma subset_pi_Union_Inter {\u03c0 : \u03b9 \u2192 set (set \u03b1)} {S : set \u03b9} {i : \u03b9} (his : i \u2208 S) :\n  \u03c0 i \u2286 pi_Union_Inter \u03c0 S :=\nbegin\n  have h_ss : {i} \u2286 S,\n  { intros j hj, rw mem_singleton_iff at hj, rwa hj, },\n  refine subset.trans _ (pi_Union_Inter_mono_right h_ss),\n  rw pi_Union_Inter_singleton,\n  exact subset_union_left _ _,\nend\n\nlemma mem_pi_Union_Inter_of_measurable_set (m : \u03b9 \u2192 measurable_space \u03b1)\n  {S : set \u03b9} {i : \u03b9} (hiS : i \u2208 S) (s : set \u03b1)\n  (hs : measurable_set[m i] s) :\n  s \u2208 pi_Union_Inter (\u03bb n, {s | measurable_set[m n] s}) S :=\nsubset_pi_Union_Inter hiS hs\n\nlemma le_generate_from_pi_Union_Inter {\u03c0 : \u03b9 \u2192 set (set \u03b1)} (S : set \u03b9) {x : \u03b9} (hxS : x \u2208 S) :\n  generate_from (\u03c0 x) \u2264 generate_from (pi_Union_Inter \u03c0 S) :=\ngenerate_from_mono (subset_pi_Union_Inter hxS)\n\nlemma measurable_set_supr_of_mem_pi_Union_Inter (m : \u03b9 \u2192 measurable_space \u03b1)\n  (S : set \u03b9) (t : set \u03b1) (ht : t \u2208 pi_Union_Inter (\u03bb n, {s | measurable_set[m n] s}) S) :\n  measurable_set[\u2a06 i \u2208 S, m i] t :=\nbegin\n  rcases ht with \u27e8pt, hpt, ft, ht_m, rfl\u27e9,\n  refine pt.measurable_set_bInter (\u03bb i hi, _),\n  suffices h_le : m i \u2264 (\u2a06 i \u2208 S, m i), from h_le (ft i) (ht_m i hi),\n  have hi' : i \u2208 S := hpt hi,\n  exact le_supr\u2082 i hi',\nend\n\nlemma generate_from_pi_Union_Inter_measurable_set (m : \u03b9 \u2192 measurable_space \u03b1) (S : set \u03b9) :\n  generate_from (pi_Union_Inter (\u03bb n, {s | measurable_set[m n] s}) S) = \u2a06 i \u2208 S, m i :=\nbegin\n  refine le_antisymm _ _,\n  { rw \u2190 @generate_from_measurable_set \u03b1 (\u2a06 i \u2208 S, m i),\n    exact generate_from_mono (measurable_set_supr_of_mem_pi_Union_Inter m S), },\n  { refine supr\u2082_le (\u03bb i hi, _),\n    rw \u2190 @generate_from_measurable_set \u03b1 (m i),\n    exact generate_from_mono (mem_pi_Union_Inter_of_measurable_set m hi), },\nend\n\nend Union_Inter\n\nnamespace measurable_space\nvariable {\u03b1 : Type*}\n\n/-! ## Dynkin systems and \u03a0-\u03bb theorem -/\n\n/-- A Dynkin system is a collection of subsets of a type `\u03b1` that contains the empty set,\n  is closed under complementation and under countable union of pairwise disjoint sets.\n  The disjointness condition is the only difference with `\u03c3`-algebras.\n\n  The main purpose of Dynkin systems is to provide a powerful induction rule for \u03c3-algebras\n  generated by a collection of sets which is stable under intersection.\n\n  A Dynkin system is also known as a \"\u03bb-system\" or a \"d-system\".\n-/\nstructure dynkin_system (\u03b1 : Type*) :=\n(has : set \u03b1 \u2192 Prop)\n(has_empty : has \u2205)\n(has_compl : \u2200 {a}, has a \u2192 has a\u1d9c)\n(has_Union_nat : \u2200 {f : \u2115 \u2192 set \u03b1}, pairwise (disjoint on f) \u2192 (\u2200 i, has (f i)) \u2192 has (\u22c3 i, f i))\n\nnamespace dynkin_system\n\n@[ext] lemma ext : \u2200 {d\u2081 d\u2082 : dynkin_system \u03b1}, (\u2200 s : set \u03b1, d\u2081.has s \u2194 d\u2082.has s) \u2192 d\u2081 = d\u2082\n| \u27e8s\u2081, _, _, _\u27e9 \u27e8s\u2082, _, _, _\u27e9 h := have s\u2081 = s\u2082, from funext $ assume x, propext $ h x,\n  by subst this\n\nvariable (d : dynkin_system \u03b1)\n\nlemma has_compl_iff {a} : d.has a\u1d9c \u2194 d.has a :=\n\u27e8\u03bb h, by simpa using d.has_compl h, \u03bb h, d.has_compl h\u27e9\n\nlemma has_univ : d.has univ :=\nby simpa using d.has_compl d.has_empty\n\nlemma has_Union {\u03b2} [countable \u03b2] {f : \u03b2 \u2192 set \u03b1} (hd : pairwise (disjoint on f))\n  (h : \u2200 i, d.has (f i)) : d.has (\u22c3 i, f i) :=\nby { casesI nonempty_encodable \u03b2, rw \u2190 encodable.Union_decode\u2082, exact\n  d.has_Union_nat (encodable.Union_decode\u2082_disjoint_on hd)\n    (\u03bb n, encodable.Union_decode\u2082_cases d.has_empty h) }\n\ntheorem has_union {s\u2081 s\u2082 : set \u03b1}\n  (h\u2081 : d.has s\u2081) (h\u2082 : d.has s\u2082) (h : disjoint s\u2081 s\u2082) : d.has (s\u2081 \u222a s\u2082) :=\nby { rw union_eq_Union, exact\n  d.has_Union (pairwise_disjoint_on_bool.2 h) (bool.forall_bool.2 \u27e8h\u2082, h\u2081\u27e9) }\n\nlemma has_diff {s\u2081 s\u2082 : set \u03b1} (h\u2081 : d.has s\u2081) (h\u2082 : d.has s\u2082) (h : s\u2082 \u2286 s\u2081) : d.has (s\u2081 \\ s\u2082) :=\nbegin\n  apply d.has_compl_iff.1,\n  simp [diff_eq, compl_inter],\n  exact d.has_union (d.has_compl h\u2081) h\u2082 (disjoint_compl_left.mono_right h),\nend\n\ninstance : has_le (dynkin_system \u03b1) :=\n{ le          := \u03bb m\u2081 m\u2082, m\u2081.has \u2264 m\u2082.has }\n\nlemma le_def {\u03b1} {a b : dynkin_system \u03b1} : a \u2264 b \u2194 a.has \u2264 b.has := iff.rfl\n\ninstance : partial_order (dynkin_system \u03b1) :=\n{ le_refl     := assume a b, le_rfl,\n  le_trans    := assume a b c hab hbc, le_def.mpr (le_trans hab hbc),\n  le_antisymm := assume a b h\u2081 h\u2082, ext $ assume s, \u27e8h\u2081 s, h\u2082 s\u27e9,\n  ..dynkin_system.has_le }\n\n/-- Every measurable space (\u03c3-algebra) forms a Dynkin system -/\ndef of_measurable_space (m : measurable_space \u03b1) : dynkin_system \u03b1 :=\n{ has       := m.measurable_set',\n  has_empty := m.measurable_set_empty,\n  has_compl := m.measurable_set_compl,\n  has_Union_nat := assume f _ hf, m.measurable_set_Union f hf }\n\nlemma of_measurable_space_le_of_measurable_space_iff {m\u2081 m\u2082 : measurable_space \u03b1} :\n  of_measurable_space m\u2081 \u2264 of_measurable_space m\u2082 \u2194 m\u2081 \u2264 m\u2082 :=\niff.rfl\n\n/-- The least Dynkin system containing a collection of basic sets.\n  This inductive type gives the underlying collection of sets. -/\ninductive generate_has (s : set (set \u03b1)) : set \u03b1 \u2192 Prop\n| basic : \u2200 t \u2208 s, generate_has t\n| empty : generate_has \u2205\n| compl : \u2200 {a}, generate_has a \u2192 generate_has a\u1d9c\n| Union : \u2200 {f : \u2115 \u2192 set \u03b1}, pairwise (disjoint on f) \u2192\n    (\u2200 i, generate_has (f i)) \u2192 generate_has (\u22c3 i, f i)\n\nlemma generate_has_compl {C : set (set \u03b1)} {s : set \u03b1} : generate_has C s\u1d9c \u2194 generate_has C s :=\nby { refine \u27e8_, generate_has.compl\u27e9, intro h, convert generate_has.compl h, simp }\n\n/-- The least Dynkin system containing a collection of basic sets. -/\ndef generate (s : set (set \u03b1)) : dynkin_system \u03b1 :=\n{ has := generate_has s,\n  has_empty := generate_has.empty,\n  has_compl := assume a, generate_has.compl,\n  has_Union_nat := assume f, generate_has.Union }\n\nlemma generate_has_def {C : set (set \u03b1)} : (generate C).has = generate_has C := rfl\n\ninstance : inhabited (dynkin_system \u03b1) := \u27e8generate univ\u27e9\n\n/-- If a Dynkin system is closed under binary intersection, then it forms a `\u03c3`-algebra. -/\ndef to_measurable_space (h_inter : \u2200 s\u2081 s\u2082, d.has s\u2081 \u2192 d.has s\u2082 \u2192 d.has (s\u2081 \u2229 s\u2082)) :=\n{ measurable_space .\n  measurable_set'      := d.has,\n  measurable_set_empty := d.has_empty,\n  measurable_set_compl := assume s h, d.has_compl h,\n  measurable_set_Union := \u03bb f hf,\n    begin\n      rw \u2190Union_disjointed,\n      exact d.has_Union (disjoint_disjointed _)\n        (\u03bb n, disjointed_rec (\u03bb t i h, h_inter _ _ h $ d.has_compl $ hf i) (hf n)),\n    end }\n\nlemma of_measurable_space_to_measurable_space\n  (h_inter : \u2200 s\u2081 s\u2082, d.has s\u2081 \u2192 d.has s\u2082 \u2192 d.has (s\u2081 \u2229 s\u2082)) :\n  of_measurable_space (d.to_measurable_space h_inter) = d :=\next $ assume s, iff.rfl\n\n/-- If `s` is in a Dynkin system `d`, we can form the new Dynkin system `{s \u2229 t | t \u2208 d}`. -/\ndef restrict_on {s : set \u03b1} (h : d.has s) : dynkin_system \u03b1 :=\n{ has       := \u03bb t, d.has (t \u2229 s),\n  has_empty := by simp [d.has_empty],\n  has_compl := assume t hts,\n    have t\u1d9c \u2229 s = ((t \u2229 s)\u1d9c) \\ s\u1d9c,\n      from set.ext $ assume x, by { by_cases x \u2208 s; simp [h] },\n    by { rw [this], exact d.has_diff (d.has_compl hts) (d.has_compl h)\n      (compl_subset_compl.mpr $ inter_subset_right _ _) },\n  has_Union_nat := assume f hd hf,\n    begin\n      rw [Union_inter],\n      refine d.has_Union_nat _ hf,\n      exact hd.mono (\u03bb i j,\n        disjoint.mono (inter_subset_left _ _) (inter_subset_left _ _)),\n    end }\n\nlemma generate_le {s : set (set \u03b1)} (h : \u2200 t \u2208 s, d.has t) : generate s \u2264 d :=\n\u03bb t ht, ht.rec_on h d.has_empty\n  (assume a _ h, d.has_compl h)\n  (assume f hd _ hf, d.has_Union hd hf)\n\nlemma generate_has_subset_generate_measurable {C : set (set \u03b1)} {s : set \u03b1}\n  (hs : (generate C).has s) : measurable_set[generate_from C] s :=\ngenerate_le (of_measurable_space (generate_from C)) (\u03bb t, measurable_set_generate_from) s hs\n\nlemma generate_inter {s : set (set \u03b1)}\n  (hs : is_pi_system s) {t\u2081 t\u2082 : set \u03b1}\n  (ht\u2081 : (generate s).has t\u2081) (ht\u2082 : (generate s).has t\u2082) : (generate s).has (t\u2081 \u2229 t\u2082) :=\nhave generate s \u2264 (generate s).restrict_on ht\u2082,\n  from generate_le _ $ assume s\u2081 hs\u2081,\n  have (generate s).has s\u2081, from generate_has.basic s\u2081 hs\u2081,\n  have generate s \u2264 (generate s).restrict_on this,\n    from generate_le _ $ assume s\u2082 hs\u2082,\n      show (generate s).has (s\u2082 \u2229 s\u2081), from\n        (s\u2082 \u2229 s\u2081).eq_empty_or_nonempty.elim\n        (\u03bb h,  h.symm \u25b8 generate_has.empty)\n        (\u03bb h, generate_has.basic _ $ hs _ hs\u2082 _ hs\u2081 h),\n  have (generate s).has (t\u2082 \u2229 s\u2081), from this _ ht\u2082,\n  show (generate s).has (s\u2081 \u2229 t\u2082), by rwa [inter_comm],\nthis _ ht\u2081\n\n/--\n  **Dynkin's \u03c0-\u03bb theorem**:\n  Given a collection of sets closed under binary intersections, then the Dynkin system it\n  generates is equal to the \u03c3-algebra it generates.\n  This result is known as the \u03c0-\u03bb theorem.\n  A collection of sets closed under binary intersection is called a \u03c0-system (often requiring\n  additionnally that is is non-empty, but we drop this condition in the formalization).\n-/\nlemma generate_from_eq {s : set (set \u03b1)} (hs : is_pi_system s) :\n  generate_from s = (generate s).to_measurable_space (\u03bb t\u2081 t\u2082, generate_inter hs) :=\nle_antisymm\n  (generate_from_le $ assume t ht, generate_has.basic t ht)\n  (of_measurable_space_le_of_measurable_space_iff.mp $\n    by { rw [of_measurable_space_to_measurable_space],\n    exact (generate_le _ $ assume t ht, measurable_set_generate_from ht) })\n\nend dynkin_system\n\ntheorem induction_on_inter {C : set \u03b1 \u2192 Prop} {s : set (set \u03b1)} [m : measurable_space \u03b1]\n  (h_eq : m = generate_from s) (h_inter : is_pi_system s)\n  (h_empty : C \u2205) (h_basic : \u2200 t \u2208 s, C t) (h_compl : \u2200 t, measurable_set t \u2192 C t \u2192 C t\u1d9c)\n  (h_union : \u2200 f : \u2115 \u2192 set \u03b1, pairwise (disjoint on f) \u2192\n    (\u2200 i, measurable_set (f i)) \u2192 (\u2200 i, C (f i)) \u2192 C (\u22c3 i, f i)) :\n  \u2200 \u2983t\u2984, measurable_set t \u2192 C t :=\nhave eq : measurable_set = dynkin_system.generate_has s,\n  by { rw [h_eq, dynkin_system.generate_from_eq h_inter], refl },\nassume t ht,\nhave dynkin_system.generate_has s t, by rwa [eq] at ht,\nthis.rec_on h_basic h_empty\n  (assume t ht, h_compl t $ by { rw [eq], exact ht })\n  (assume f hf ht, h_union f hf $ assume i, by { rw [eq], exact ht _ })\n\nend measurable_space\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/pi_system.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740728, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7436948407853488}}
{"text": "/-\nCopyright (c) 2021 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n-/\nimport data.fintype.card\nimport logic.equiv.fin\nimport logic.equiv.embedding\n\n/-!\n# Number of embeddings\n\nThis file establishes the cardinality of `\u03b1 \u21aa \u03b2` in full generality.\n-/\n\nlocal notation `|` x `|` := finset.card x\nlocal notation `\u2016` x `\u2016` := fintype.card x\n\nopen function\nopen_locale nat big_operators\n\nnamespace fintype\n\nlemma card_embedding_eq_of_unique {\u03b1 \u03b2 : Type*} [unique \u03b1] [fintype \u03b2] [fintype (\u03b1 \u21aa \u03b2)] :\n  \u2016\u03b1 \u21aa \u03b2\u2016 = \u2016\u03b2\u2016 := card_congr equiv.unique_embedding_equiv_result\n\n/- Establishes the cardinality of the type of all injections between two finite types. -/\n@[simp] theorem card_embedding_eq {\u03b1 \u03b2} [fintype \u03b1] [fintype \u03b2] [fintype (\u03b1 \u21aa \u03b2)] :\n  \u2016\u03b1 \u21aa \u03b2\u2016 = (\u2016\u03b2\u2016.desc_factorial \u2016\u03b1\u2016) :=\nbegin\n  classical,\n  unfreezingI { induction \u2039fintype \u03b1\u203a using fintype.induction_empty_option'\n    with \u03b1\u2081 \u03b1\u2082 h\u2082 e ih \u03b1 h ih },\n  { letI := fintype.of_equiv _ e.symm,\n    rw [\u2190 card_congr (equiv.embedding_congr e (equiv.refl \u03b2)), ih, card_congr e] },\n  { rw [card_pempty, nat.desc_factorial_zero, card_eq_one_iff],\n    exact \u27e8embedding.of_is_empty, \u03bb x, fun_like.ext _ _ is_empty_elim\u27e9 },\n  { rw [card_option, nat.desc_factorial_succ, card_congr (embedding.option_embedding_equiv \u03b1 \u03b2),\n      card_sigma, \u2190 ih],\n    simp only [fintype.card_compl_set, fintype.card_range, finset.sum_const, finset.card_univ,\n      smul_eq_mul, mul_comm] },\nend\n\n/- The cardinality of embeddings from an infinite type to a finite type is zero.\nThis is a re-statement of the pigeonhole principle. -/\n@[simp] lemma card_embedding_eq_of_infinite {\u03b1 \u03b2} [infinite \u03b1] [fintype \u03b2] [fintype (\u03b1 \u21aa \u03b2)] :\n  \u2016\u03b1 \u21aa \u03b2\u2016 = 0 :=\ncard_eq_zero_iff.mpr function.embedding.is_empty\n\nend fintype\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/fintype/card_embedding.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7436948238002244}}
{"text": "import tactic.gptf\nimport data.list.sigma\n\nsection gptf\n\nexample {\u03b1} (a : \u03b1) : a = a :=\nbegin\n  refl\nend\n\nexample : \u2203 n : \u2115, 8 = 2*n :=\nbegin\n  exact \u27e84, rfl\u27e9\nend\n\nexample {P Q R : Prop} : P \u2192 (P \u2192 R) \u2192 R :=\nbegin\n  intro h1, exact \u03bb h2, h2 h1\nend\n\nexample {p q r : Prop} (h\u2081 : p) (h\u2082 : q) : (p \u2227 q) \u2228 r :=\nbegin\n  exact or.inl \u27e8h\u2081, h\u2082\u27e9\nend\n\nexample {P Q : Prop} : (\u00ac P) \u2227 (\u00ac Q) \u2192 \u00ac (P \u2228 Q) :=\nbegin\n  exact not_or_distrib.mpr -- `gptf {pfx := \"exact\"}`\nend\n\nexample {P Q R : Prop} : (P \u2227 Q) \u2192 ((P \u2192 R) \u2192 \u00ac (Q \u2192 \u00ac R)) :=\nbegin\n  rintros \u27e8h\u2081, h\u2082\u27e9 h\u2083, try {exact \u03bb h, h\u2081 _ h}, rw [imp_not_comm],\n  apply not_imp_not.mpr (\u03bb con, _), exact id, apply con, apply h\u2083,\n  apply h\u2081, exact h\u2082\nend\n\nexample (n : \u2115) (m : \u2115) : nat.succ n < nat.succ n + 1  :=\nbegin\n  {[smt] eblast_using  [nat.add_one], exact nat.lt_succ_self _}\nend\n\nexample : \u2200 (F1 F2 F3 : Prop), ((\u00acF1 \u2227 F3) \u2228 (F2 \u2227 \u00acF3)) \u2192 (F2 \u2192 F1) \u2192 (F2 \u2192 F3) \u2192  \u00acF2 :=\nbegin\n  intros P Q R H\u2081 H\u2082 H\u2083 H\u2084,\n  apply H\u2081.elim, -- `gptf {pfx := \"apply\"}`\n  { assume h, simp * at * }, -- `gptf`\n  cc -- `gptf`\nend\n\nexample : \u2200 (f : nat \u2192 Prop), f 2 \u2192 \u2203 x, f x :=\nbegin\n  exact \u03bb f hf, \u27e8_, hf\u27e9 -- by `gptf {pfx := \"exact\"}` :D\nend\n\nexample {G : Type} [group G] (x y z : G) : (x * z) * (z\u207b\u00b9 * y) = x * y :=\nbegin\n  simp [mul_assoc]  \nend\nuniverses u v\n\nexample {\u03b1 : Type u} {\u03b2 : \u03b1 \u2192 Type v} [_inst_1 : decidable_eq \u03b1] {a : \u03b1} {l\u2081 l\u2082 : list (sigma \u03b2)} :\n  (list.kerase a l\u2081).kunion (list.kerase a l\u2082) = list.kerase a (l\u2081.kunion l\u2082) :=\nbegin\n  induction l\u2081 generalizing l\u2082, case list.nil { refl }, simp\nend\n\nend gptf\n", "meta": {"author": "jesse-michael-han", "repo": "lean-gptf", "sha": "e2adeef81f6cf089cde493fa1b7f4af5d53c747a", "save_path": "github-repos/lean/jesse-michael-han-lean-gptf", "path": "github-repos/lean/jesse-michael-han-lean-gptf/lean-gptf-e2adeef81f6cf089cde493fa1b7f4af5d53c747a/src/example.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.74369481847206}}
{"text": "-- ----------------------------------------------------\n-- Ejercicio. Demostrar o refutar\n--    ((\u2203x, P x) \u2228 (\u2203x, Q x)) \u27f7 (\u2203x, P x \u2228 Q x)\n-- ----------------------------------------------------\n\nimport tactic\n\nvariable  (U : Type)\nvariables (P Q : U \u2192 Prop)\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  ((\u2203x, P x) \u2228 (\u2203x, Q x)) \u2194 (\u2203x, P x \u2228 Q x) :=\nbegin\n  split,\n  { rintro (\u27e8a, h1\u27e9 | \u27e8a, h2\u27e9),\n    { use a,\n      left,\n      exact h1, },\n    { use a,\n      right,\n      exact h2, }},\n  { rintro \u27e8a, (h3 | h4)\u27e9,\n    { left,\n      use a,\n      exact h3, },\n    { right,\n      use a,\n      exact h4, }},\nend\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/2_LPO/Ejercicios/((\u2203x, P x) \u2228 (\u2203x, Q x)) \u27f7 (\u2203x, P x \u2228 Q x).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009619539553, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7436930868829597}}
{"text": "import data.real.basic\n\n#check le_refl\n#check le_trans\n#check @add_le_add\n\n-- BEGIN\n\nexample (x : \u211d) : x \u2264 x :=\nbegin\n  apply le_refl,\nend  \n\n/- in this context, the apply and exact tactics are equivalent -/\nexample (x : \u211d) : x \u2264 x :=\nbegin\n  exact le_refl x,\nend  \n\nexample (x y z : \u211d) (h\u2080 : x \u2264 y) (h\u2081 : y \u2264 z) : x \u2264 z :=\nbegin\n  apply le_trans,\n  { apply h\u2080 },\n  apply h\u2081,\nend\n\nexample (x y z : \u211d) (h\u2080 : x \u2264 y) (h\u2081 : y \u2264 z) : x \u2264 z :=\nbegin\n  apply le_trans h\u2080,\n  apply h\u2081,\nend\n\nexample (x y z : \u211d) (h\u2080 : x \u2264 y) (h\u2081 : y \u2264 z) : x \u2264 z :=\nbegin \n  apply le_trans h\u2080 h\u2081,\nend  \n\nexample (x y z : \u211d) (h\u2080 : x \u2264 y) (h\u2081 : y \u2264 z) : x \u2264 z :=\nbegin\n  exact le_trans h\u2080 h\u2081,\nend \n\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.1_apply/ex1_apply_le_trans_refl.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7436930829230592}}
{"text": "import data.polynomial\nimport data.real.basic\nimport algebra.big_operators\n\nnoncomputable theory\nopen_locale big_operators\n\n-- The basic building block in the Lagrange polynomial\n-- this is (x - b)/(a - b)\ndef scaled_binomial (a b : \u211d) : polynomial \u211d := \n    ((1 : \u211d)/(a - b)) \u2022 (polynomial.X - polynomial.C b)\n\n@[simp] lemma bin_zero (a b : \u211d) (h : a \u2260 b) : polynomial.eval b (scaled_binomial a b) = 0 :=\nbegin\n    unfold scaled_binomial, -- doesn't work without this\n    rw [polynomial.eval_smul, polynomial.eval_sub, polynomial.eval_X, polynomial.eval_C],\n    rw [sub_self, algebra.id.smul_eq_mul, mul_zero],\n    done\nend\n\n@[simp] lemma bin_one (a b : \u211d) (h : a \u2260 b) : polynomial.eval a (scaled_binomial a b) = 1 :=\nbegin\n    unfold scaled_binomial, -- doesn't work without this\n    rw [polynomial.eval_smul, polynomial.eval_sub, polynomial.eval_X, polynomial.eval_C],\n    rw algebra.id.smul_eq_mul,\n    have h1 : a - b \u2260 0, exact sub_ne_zero_of_ne h,\n    exact div_mul_cancel 1 h1, done\nend\n\n-- This version, using scalar multiplication (`smul`) seems simplest.\n-- Must add hypothesis that data points are distinct\ndef lagrange_interpolant (n : \u2115) (i : \u2115) (xData : \u2115 \u2192 \u211d) : polynomial \u211d :=\n    \u220f j in ( finset.range (n+1) \\ {i} ), scaled_binomial (xData i) (xData j) \n\n-- This has been PR'd into mathlib\nvariables  {\u03b9 : Type*} [decidable_eq \u03b9]\nlemma polynomial.eval_finset.prod (s : finset \u03b9) (p : \u03b9 \u2192 polynomial \u211d) (x : \u211d) :\n  polynomial.eval x (\u220f j in s, p j) = \u220f j in s, polynomial.eval x (p j) :=\nbegin\n    apply finset.induction_on s,\n    { repeat {rw finset.prod_empty}, rw polynomial.eval_one },\n    intros j s hj hpj,\n    have h0 : \u220f i in insert j s, polynomial.eval x (p i) = \n            (polynomial.eval x (p j)) * \u220f i in s, polynomial.eval x (p i),\n    { apply finset.prod_insert hj },\n    rw [h0, \u2190 hpj], \n    rw finset.prod_insert hj,\n    rw polynomial.eval_mul, done\nend\n\n-- The Lagrange interpolant `L\u1d62 x` is one for `x = xData i` \n@[simp]\nlemma lagrange_interpolant_one (n : \u2115) (xData : \u2115 \u2192 \u211d) (i : \u2115) (hi: i \u2208 finset.range (n+1)) \n    (hne : \u2200 (i j : \u2115), i \u2260 j \u2192 xData i \u2260 xData j) : \n    polynomial.eval (xData i) (lagrange_interpolant n i xData)= (1:\u211d) :=\nbegin\n    unfold lagrange_interpolant,\n    rw polynomial.eval_finset.prod,\n    --simp only [bin_one], -- simp fails, need better lemma\n    apply finset.prod_eq_one,\n    intros j hj,\n    have h0 : i \u2260 j, \n        { intro heq, rw heq at hj, \n          rw [finset.mem_sdiff, finset.mem_singleton] at hj,\n          exact hj.2 rfl \n        },\n    exact bin_one (xData i) (xData j) (hne i j h0),\n    done\nend\n\n-- The Lagrange interpolant `L\u1d62 x` is zero for `x = xData j, j \u2260 i` \n@[simp]\nlemma lagrange_interpolant_zero (n : \u2115) (xData : \u2115 \u2192 \u211d) (i : \u2115) (hi: i \u2208 finset.range (n+1)) \n    (j : \u2115) (hj : j \u2208 finset.range (n+1)) (hij : i \u2260 j) \n    (hne : \u2200 (i j : \u2115), i \u2260 j \u2192 xData i \u2260 xData j) : \n    polynomial.eval (xData j) (lagrange_interpolant n i xData) = (0:\u211d) :=\nbegin\n    sorry,\nend\n\n\n--------------------- Scratch space below here\n\n#eval (\u2211 k in ((finset.range 5) \\ {0}), k)\n\n-- These will be useful for defining the Lagrange polynomials\ndef binomial_R (a : \u211d) : polynomial \u211d := polynomial.X - polynomial.C a\n-- To work with their values use this technique:\nexample : polynomial.eval (5 : \u211d) (binomial_R (2:\u211d)) = 3 :=\nbegin\n    unfold binomial_R,  -- otherwise can't rw below\n    rw polynomial.eval_sub,\n    rw polynomial.eval_C,\n    rw polynomial.eval_X,\n    norm_num, done\nend\n\n-- Must show that one can commute polynomial.eval with finset.prod\n-- So a lemma like this would be useful\nlemma eval_comm_prod (n : \u2115) (pj : \u2115 \u2192 polynomial \u211d) (x : \u211d) :\n    polynomial.eval x ( \u220f j in finset.range n, pj j) = \n    \u220f j in finset.range n, polynomial.eval x (pj j) :=\nbegin\n    induction n with d hd,\n    { -- base case n = 0\n        repeat { rw finset.prod_range_zero _ },\n        rw polynomial.eval_one,\n    },\n    { -- induction step\n        rw [finset.prod_range_succ, polynomial.eval_mul, hd, finset.prod_range_succ  ],\n    },\n    done\nend\n\n-- Maybe even better, working with `smul`? Maybe not!\ndef lagrange_interpolant_v3 (n : \u2115) (i : \u2115) (xData : \u2115 \u2192 \u211d): polynomial \u211d :=\n    \u220f j in ( finset.range (n+1) \\ {i} ), \n    ((1 : \u211d)/(xData i - xData j)) \u2022 (binomial_R (xData j))\n\n-- Either this way (working with \u2115):\ndef lagrange_interpolant_v2 (n : \u2115) (i : \u2115) (xData : \u2115 \u2192 \u211d): polynomial \u211d :=\n    \u220f j in ( finset.range (n+1) \\ {i} ), \n    (binomial_R (xData j)) * polynomial.C (1/(xData i - xData j))\n\n-- Or this way (working with `fin`):\ndef lagrange_interpolant_v1 (n : \u2115) (i : fin (n+1) ) (xData : fin (n+1) \u2192 \u211d): polynomial \u211d :=\n    \u220f j in ( finset.fin_range (n+1) \\ { i } ), \n    binomial_R (xData j) * polynomial.C (1/(xData i - xData j))\n\n\n\n-- Check that I can work with this definition\ndef myX : \u2115 \u2192 \u211d \n| 0     := (1 : \u211d)\n| 1     := (2 : \u211d)\n| (n+2) := (5 : \u211d)\n\n@[simp] lemma myX_0 : myX 0 = (1:\u211d) := rfl\n@[simp] lemma myX_1 : myX 1 = (2:\u211d) := rfl\n@[simp] lemma myX_all (n : \u2115): myX (nat.succ (nat.succ n)) = (5:\u211d) := rfl \n@[simp] lemma myX_n (n : \u2115) (hn : 1 < n) : myX n = (5:\u211d) := \nbegin\n    -- should I use rec_on or something else instead of induction?\n    induction n with d hd,\n    { -- base case\n        exfalso, linarith, \n    },\n    { -- induction step, how to best prove this?\n        have h1 : 0 < d, \n            rw nat.succ_eq_add_one at hn,\n            linarith,\n        have h2 : \u2203 m : \u2115, d = m.succ,\n        use d - 1, rw nat.succ_eq_add_one, omega, -- a little \u2115 subtraction problem, thx `omega`!\n        cases h2 with m hm,\n        rw hm,\n        exact myX_all m,\n    },\n    done\nend\n\n-- Maybe I can use this lemma below:\n@[simp] lemma finset_range_2_0 : finset.range 2 \\ {0} = {1} := \nbegin\n    have h1 : 2 = nat.succ 1, refl,\n    rw [ h1, finset.range_succ, finset.range_one ],\n    refl,\nend\n@[simp] lemma finset_range_2_1 : finset.range 2 \\ {1} = {0} := \nbegin\n    have h1 : 2 = nat.succ 1, refl,\n    rw h1,\n    rw finset.range_succ,\n    rw finset.range_one,\n    refl,\nend\n@[simp] lemma finset_range_20 : finset.range 2 \\ {0} = {1} := dec_trivial -- wow!\n\nexample : polynomial.eval (1 : \u211d) (lagrange_interpolant 1 0 myX) = 1 :=\nbegin\n    unfold lagrange_interpolant,\n    simp * at *, -- still doesn't use the simp lemmas for scaled_binomial\n    have h : (1:\u211d) \u2260 2, linarith,\n    exact bin_one 1 2 h,\nend\n\n\n-- The first interpolant (i=0) evaluated at the first point (x 0 = 1.0):\nexample : polynomial.eval (1 : \u211d) (lagrange_interpolant_v2 1 0 myX) = 1 :=\nbegin\n    unfold lagrange_interpolant_v2,\n    unfold finset.prod,\n    have h1 : 1 + 1 = 2, refl,\n    rw h1,\n    simp * at *,\n    unfold binomial_R,\n    rw [polynomial.eval_sub, polynomial.eval_X, polynomial.eval_C],\n    norm_num,\nend\n-- The first interpolant (i=0) evaluated at the first point (x 0 = 1.0):\nexample : polynomial.eval (1 : \u211d) (lagrange_interpolant_v3 1 0 myX) = (1 : \u211d) :=\nbegin\n    unfold lagrange_interpolant_v3,\n    unfold finset.prod,\n    have h1 : 1 + 1 = 2, refl,\n    rw h1,\n    rw finset_range_2_0, \n    unfold binomial_R, simp only [one_div_eq_inv, myX_0],\n    simp * at *,\n    norm_num,\nend\n\n-- To remember:\nexample (j : \u2115) (n : \u2115) (i : fin n) : j = i := \nbegin\n    sorry,  -- can coerce from `fin n` to `\u2115` but not the other way around. Of course...\nend\n \n-- Experiment with products of binomial terms\n-- If the interpolation points are placed in a `finset`:\nvariable x : finset \u211d\n#check finset.prod x binomial_R --this works\n#check  finset.has_sdiff -- this can be used to remove elements\n#check  finset.fin_range -- this returns a finset of `fin k`\n-- Probably `fin n` would be even better, is there something similar for `fin`?\n#check fin\n#check fin.prod_univ_succ\n#check  fin.sum_univ_eq_sum_range\n#check  list.sum_of_fn\n#check  list.prod_of_fn\n#check polynomial.coeff_mul_X_sub_C\nvariables a b : \u211d\n#check (binomial_R a) * (binomial_R b)\n#check finset.range\n#check polynomial.eval_mul\n\n-- #lint-", "meta": {"author": "stanescuUW", "repo": "numerical-analysis-with-Lean", "sha": "98e6974f8b68cc5232ceff40535d776a33444c73", "save_path": "github-repos/lean/stanescuUW-numerical-analysis-with-Lean", "path": "github-repos/lean/stanescuUW-numerical-analysis-with-Lean/numerical-analysis-with-Lean-98e6974f8b68cc5232ceff40535d776a33444c73/src/Interpolation/lagrange_v0.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7436930817876117}}
{"text": "import data.real.basic\n\nvariables a b c : \u211d\n\n#check le_antisymm\n#check le_min\n#check le_trans\n#check max_le\n#check min_le_right a b \n#check min_le_left b c\n#check le_max_left\n#check le_max_right\n\n-- BEGIN\n\nexample : max a b = max b a :=\nbegin\n  apply le_antisymm,\n  { show max a b \u2264 max b a,\n    apply max_le,\n      apply le_max_right, \n      apply le_max_left },\n  { show max b a \u2264 max a b, \n    apply max_le,\n      apply le_max_right,\n      apply le_max_left },\nend\n\nexample : min (min a b) c = min a (min b c) :=\nbegin\n  apply le_antisymm, \n  { apply le_min,\n    exact le_trans (min_le_left (min a b) c) (min_le_left a b),\n    apply le_min,\n    exact le_trans (min_le_left (min a b) c) (min_le_right a b),\n    exact min_le_right (min a b) c,\n  },\n  { apply le_min,\n    apply le_min,\n    exact min_le_left a (min b c),\n    exact le_trans (min_le_right a (min b c)) (min_le_left b c),\n    exact le_trans (min_le_right a (min b c)) (min_le_right b c),\n  },\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.2_exact/ex9_exact_max_min.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7436300646074193}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.finrank\nimport linear_algebra.free_module.finite.basic\nimport linear_algebra.matrix.to_lin\n\n/-!\n# Finite and free modules using matrices\n\nWe provide some instances for finite and free modules involving matrices.\n\n## Main results\n\n* `module.free.linear_map` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N` is free.\n* `module.finite.of_basis` : A free module with a basis indexed by a `fintype` is finite.\n* `module.finite.linear_map` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N`\n  is finite.\n-/\n\nuniverses u v w\n\nvariables (R : Type u) (M : Type v) (N : Type w)\n\nnamespace module.free\n\nsection comm_ring\n\nvariables [comm_ring R] [add_comm_group M] [module R M] [module.free R M]\nvariables [add_comm_group N] [module R N] [module.free R N]\n\ninstance linear_map [module.finite R M] [module.finite R N] : module.free R (M \u2192\u2097[R] N) :=\nbegin\n  casesI subsingleton_or_nontrivial R,\n  { apply module.free.of_subsingleton' },\n  classical,\n  exact of_equiv\n    (linear_map.to_matrix (module.free.choose_basis R M) (module.free.choose_basis R N)).symm,\nend\n\nvariables {R}\n\ninstance _root_.module.finite.linear_map [module.finite R M] [module.finite R N] :\n  module.finite R (M \u2192\u2097[R] N) :=\nbegin\n  casesI subsingleton_or_nontrivial R,\n  { apply_instance },\n  classical,\n  have f := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)).symm,\n  exact module.finite.of_surjective f.to_linear_map (linear_equiv.surjective f),\nend\n\nend comm_ring\n\nsection integer\n\nvariables [add_comm_group M] [module.finite \u2124 M] [module.free \u2124 M]\nvariables [add_comm_group N] [module.finite \u2124 N] [module.free \u2124 N]\n\ninstance _root_.module.finite.add_monoid_hom : module.finite \u2124 (M \u2192+ N) :=\nmodule.finite.equiv (add_monoid_hom_lequiv_int \u2124).symm\n\ninstance add_monoid_hom : module.free \u2124 (M \u2192+ N) :=\nbegin\n  letI : module.free \u2124 (M \u2192\u2097[\u2124] N) := module.free.linear_map _ _ _,\n  exact module.free.of_equiv (add_monoid_hom_lequiv_int \u2124).symm\nend\n\nend integer\n\nsection comm_ring\n\nopen finite_dimensional\n\nvariables [comm_ring R] [strong_rank_condition R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M]\nvariables [add_comm_group N] [module R N] [module.free R N] [module.finite R N]\n\n/-- The finrank of `M \u2192\u2097[R] N` is `(finrank R M) * (finrank R N)`. -/\n--TODO: this should follow from `linear_equiv.finrank_eq`, that is over a field.\nlemma finrank_linear_hom : finrank R (M \u2192\u2097[R] N) = (finrank R M) * (finrank R N) :=\nbegin\n  classical,\n  letI := nontrivial_of_invariant_basis_number R,\n  have h := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)),\n  let b := (matrix.std_basis _ _ _).map h.symm,\n  rw [finrank, dim_eq_card_basis b, \u2190 cardinal.mk_fintype, cardinal.mk_to_nat_eq_card, finrank,\n    finrank, rank_eq_card_choose_basis_index, rank_eq_card_choose_basis_index,\n    cardinal.mk_to_nat_eq_card, cardinal.mk_to_nat_eq_card, fintype.card_prod, mul_comm]\nend\n\nend comm_ring\n\nend module.free\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/free_module/finite/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7435992688211039}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.derivative\n! leanprover-community/mathlib commit bbeb185db4ccee8ed07dc48449414ebfa39cb821\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Hom.Iterate\nimport Mathlib.Data.Polynomial.Eval\n\n/-!\n# The derivative map on polynomials\n\n## Main definitions\n * `Polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map.\n\n-/\n\n\nnoncomputable section\n\nopen Finset\n\nopen BigOperators Classical Polynomial\n\nnamespace Polynomial\n\nuniverse u v w y z\n\nvariable {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type y} {A : Type z} {a b : R} {n : \u2115}\n\nsection Derivative\n\nsection Semiring\n\nvariable [Semiring R]\n\n/-- `derivative p` is the formal derivative of the polynomial `p` -/\ndef derivative : R[X] \u2192\u2097[R] R[X] where\n  toFun p := p.sum fun n a => C (a * n) * X ^ (n - 1)\n  map_add' p q := by\n    dsimp only\n    rw [sum_add_index] <;>\n      simp only [add_mul, forall_const, RingHom.map_add, eq_self_iff_true, zero_mul,\n        RingHom.map_zero]\n  map_smul' a p := by\n    dsimp; rw [sum_smul_index] <;>\n      simp only [mul_sum, \u2190 C_mul', mul_assoc, coeff_C_mul, RingHom.map_mul, forall_const, zero_mul,\n        RingHom.map_zero, sum]\n#align polynomial.derivative Polynomial.derivative\n\ntheorem derivative_apply (p : R[X]) : derivative p = p.sum fun n a => C (a * n) * X ^ (n - 1) :=\n  rfl\n#align polynomial.derivative_apply Polynomial.derivative_apply\n\ntheorem coeff_derivative (p : R[X]) (n : \u2115) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) :=\n  by\n  rw [derivative_apply]\n  simp only [coeff_X_pow, coeff_sum, coeff_C_mul]\n  rw [sum, Finset.sum_eq_single (n + 1)]\n  simp only [Nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true]; norm_cast\n  \u00b7 intro b\n    cases b\n    \u00b7 intros\n      rw [Nat.cast_zero, mul_zero, zero_mul]\n    \u00b7 intro _ H\n      rw [Nat.succ_sub_one, if_neg (mt (congr_arg Nat.succ) H.symm), mul_zero]\n  \u00b7 rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, Nat.cast_add, Nat.cast_one,\n      mem_support_iff]\n    intro h\n    push_neg  at h\n    simp [h]\n#align polynomial.coeff_derivative Polynomial.coeff_derivative\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_zero : derivative (0 : R[X]) = 0 :=\n  derivative.map_zero\n#align polynomial.derivative_zero Polynomial.derivative_zero\n\n@[simp]\ntheorem iterate_derivative_zero {k : \u2115} : (derivative^[k]) (0 : R[X]) = 0 := by\n  induction' k with k ih\n  \u00b7 simp\n  \u00b7 simp [ih]\n#align polynomial.iterate_derivative_zero Polynomial.iterate_derivative_zero\n\n@[simp]\ntheorem derivative_monomial (a : R) (n : \u2115) :\n    derivative (monomial n a) = monomial (n - 1) (a * n) := by\n  rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial]\n  simp\n#align polynomial.derivative_monomial Polynomial.derivative_monomial\n\ntheorem derivative_C_mul_X (a : R) : derivative (C a * X) = C a := by\n  simp [C_mul_X_eq_monomial, derivative_monomial, Nat.cast_one, mul_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_C_mul_X Polynomial.derivative_C_mul_X\n\ntheorem derivative_C_mul_X_pow (a : R) (n : \u2115) :\n    derivative (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by\n  rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_C_mul_X_pow Polynomial.derivative_C_mul_X_pow\n\ntheorem derivative_C_mul_X_sq (a : R) : derivative (C a * X ^ 2) = C (a * 2) * X := by\n  rw [derivative_C_mul_X_pow, Nat.cast_two, pow_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_C_mul_X_sq Polynomial.derivative_C_mul_X_sq\n\n@[simp]\ntheorem derivative_X_pow (n : \u2115) : derivative (X ^ n : R[X]) = C (n : R) * X ^ (n - 1) := by\n  convert derivative_C_mul_X_pow (1 : R) n <;> simp\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X_pow Polynomial.derivative_X_pow\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_X_sq : derivative (X ^ 2 : R[X]) = C 2 * X := by\n  rw [derivative_X_pow, Nat.cast_two, pow_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X_sq Polynomial.derivative_X_sq\n\n@[simp]\ntheorem derivative_C {a : R} : derivative (C a) = 0 := by simp [derivative_apply]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_C Polynomial.derivative_C\n\ntheorem derivative_of_natDegree_zero {p : R[X]} (hp : p.natDegree = 0) : derivative p = 0 := by\n  rw [eq_C_of_natDegree_eq_zero hp, derivative_C]\n#align polynomial.derivative_of_nat_degree_zero Polynomial.derivative_of_natDegree_zero\n\n@[simp]\ntheorem derivative_X : derivative (X : R[X]) = 1 :=\n  (derivative_monomial _ _).trans <| by simp\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X Polynomial.derivative_X\n\n@[simp]\ntheorem derivative_one : derivative (1 : R[X]) = 0 :=\n  derivative_C\n#align polynomial.derivative_one Polynomial.derivative_one\n\nset_option linter.deprecated false in\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_bit0 {a : R[X]} : derivative (bit0 a) = bit0 (derivative a) := by simp [bit0]\n#align polynomial.derivative_bit0 Polynomial.derivative_bit0\n\nset_option linter.deprecated false in\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_bit1 {a : R[X]} : derivative (bit1 a) = bit0 (derivative a) := by simp [bit1]\n#align polynomial.derivative_bit1 Polynomial.derivative_bit1\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_add {f g : R[X]} : derivative (f + g) = derivative f + derivative g :=\n  derivative.map_add f g\n#align polynomial.derivative_add Polynomial.derivative_add\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_X_add_C (c : R) : derivative (X + C c) = 1 := by\n  rw [derivative_add, derivative_X, derivative_C, add_zero]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X_add_C Polynomial.derivative_X_add_C\n\n@[simp]\ntheorem iterate_derivative_add {f g : R[X]} {k : \u2115} :\n    (derivative^[k]) (f + g) = (derivative^[k]) f + (derivative^[k]) g :=\n  derivative.toAddMonoidHom.iterate_map_add _ _ _\n#align polynomial.iterate_derivative_add Polynomial.iterate_derivative_add\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_sum {s : Finset \u03b9} {f : \u03b9 \u2192 R[X]} :\n    derivative (\u2211 b in s, f b) = \u2211 b in s, derivative (f b) :=\n  derivative.map_sum\n#align polynomial.derivative_sum Polynomial.derivative_sum\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_smul {S : Type _} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S)\n    (p : R[X]) : derivative (s \u2022 p) = s \u2022 derivative p :=\n  derivative.map_smul_of_tower s p\n#align polynomial.derivative_smul Polynomial.derivative_smul\n\n@[simp]\ntheorem iterate_derivative_smul {S : Type _} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R]\n    (s : S) (p : R[X]) (k : \u2115) : (derivative^[k]) (s \u2022 p) = s \u2022 (derivative^[k]) p := by\n  induction' k with k ih generalizing p\n  \u00b7 simp\n  \u00b7 simp [ih]\n#align polynomial.iterate_derivative_smul Polynomial.iterate_derivative_smul\n\n@[simp]\ntheorem iterate_derivative_C_mul (a : R) (p : R[X]) (k : \u2115) :\n    (derivative^[k]) (C a * p) = C a * (derivative^[k]) p := by\n  simp_rw [\u2190 smul_eq_C_mul, iterate_derivative_smul]\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_C_mul Polynomial.iterate_derivative_C_mul\n\ntheorem of_mem_support_derivative {p : R[X]} {n : \u2115} (h : n \u2208 p.derivative.support) :\n    n + 1 \u2208 p.support :=\n  mem_support_iff.2 fun h1 : p.coeff (n + 1) = 0 =>\n    mem_support_iff.1 h <| show p.derivative.coeff n = 0 by rw [coeff_derivative, h1, zero_mul]\n#align polynomial.of_mem_support_derivative Polynomial.of_mem_support_derivative\n\ntheorem degree_derivative_lt {p : R[X]} (hp : p \u2260 0) : p.derivative.degree < p.degree :=\n  (Finset.sup_lt_iff <| bot_lt_iff_ne_bot.2 <| mt degree_eq_bot.1 hp).2 fun n hp =>\n    lt_of_lt_of_le (WithBot.some_lt_some.2 n.lt_succ_self) <|\n      Finset.le_sup <| of_mem_support_derivative hp\n#align polynomial.degree_derivative_lt Polynomial.degree_derivative_lt\n\ntheorem degree_derivative_le {p : R[X]} : p.derivative.degree \u2264 p.degree :=\n  if H : p = 0 then le_of_eq <| by rw [H, derivative_zero] else (degree_derivative_lt H).le\n#align polynomial.degree_derivative_le Polynomial.degree_derivative_le\n\ntheorem natDegree_derivative_lt {p : R[X]} (hp : p.natDegree \u2260 0) :\n    p.derivative.natDegree < p.natDegree := by\n  cases' eq_or_ne (derivative p) 0 with hp' hp'\n  \u00b7 rw [hp', Polynomial.natDegree_zero]\n    exact hp.bot_lt\n  \u00b7 rw [natDegree_lt_natDegree_iff hp']\n    exact degree_derivative_lt fun h => hp (h.symm \u25b8 natDegree_zero)\n#align polynomial.nat_degree_derivative_lt Polynomial.natDegree_derivative_lt\n\ntheorem natDegree_derivative_le (p : R[X]) : p.derivative.natDegree \u2264 p.natDegree - 1 := by\n  by_cases p0 : p.natDegree = 0\n  \u00b7 simp [p0, derivative_of_natDegree_zero]\n  \u00b7 exact Nat.le_pred_of_lt (natDegree_derivative_lt p0)\n#align polynomial.nat_degree_derivative_le Polynomial.natDegree_derivative_le\n\n@[simp]\ntheorem derivative_nat_cast {n : \u2115} : derivative (n : R[X]) = 0 := by\n  rw [\u2190 map_natCast C n]\n  exact derivative_C\n#align polynomial.derivative_nat_cast Polynomial.derivative_nat_cast\n\n--Porting note: new theorem\n@[simp]\ntheorem derivative_ofNat (n : \u2115) [n.AtLeastTwo] : derivative (OfNat.ofNat n : R[X]) = 0 :=\n  derivative_nat_cast\n\ntheorem iterate_derivative_eq_zero {p : R[X]} {x : \u2115} (hx : p.natDegree < x) :\n    (Polynomial.derivative^[x]) p = 0 := by\n  induction' h : p.natDegree using Nat.strong_induction_on with _ ih generalizing p x\n  subst h\n  obtain \u27e8t, rfl\u27e9 := Nat.exists_eq_succ_of_ne_zero (pos_of_gt hx).ne'\n  rw [Function.iterate_succ_apply]\n  by_cases hp : p.natDegree = 0\n  \u00b7 rw [derivative_of_natDegree_zero hp, iterate_derivative_zero]\n  have := natDegree_derivative_lt hp\n  exact ih _ this (this.trans_le <| Nat.le_of_lt_succ hx) rfl\n#align polynomial.iterate_derivative_eq_zero Polynomial.iterate_derivative_eq_zero\n\n@[simp]\ntheorem iterate_derivative_C {k} (h : 0 < k) : (derivative^[k]) (C a : R[X]) = 0 :=\n  iterate_derivative_eq_zero <| (natDegree_C _).trans_lt h\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_C Polynomial.iterate_derivative_C\n\n@[simp]\ntheorem iterate_derivative_one {k} (h : 0 < k) : (derivative^[k]) (1 : R[X]) = 0 :=\n  iterate_derivative_C h\n#align polynomial.iterate_derivative_one Polynomial.iterate_derivative_one\n\n@[simp]\ntheorem iterate_derivative_x {k} (h : 1 < k) : (derivative^[k]) (X : R[X]) = 0 :=\n  iterate_derivative_eq_zero <| natDegree_X_le.trans_lt h\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_X Polynomial.iterate_derivative_x\n\ntheorem natDegree_eq_zero_of_derivative_eq_zero [NoZeroSMulDivisors \u2115 R] {f : R[X]}\n    (h : derivative f = 0) : f.natDegree = 0 := by\n  rcases eq_or_ne f 0 with (rfl | hf)\n  \u00b7 exact natDegree_zero\n  rw [natDegree_eq_zero_iff_degree_le_zero]\n  by_contra' f_nat_degree_pos\n  rw [\u2190 natDegree_pos_iff_degree_pos] at f_nat_degree_pos\n  let m := f.natDegree - 1\n  have hm : m + 1 = f.natDegree := tsub_add_cancel_of_le f_nat_degree_pos\n  have h2 := coeff_derivative f m\n  rw [Polynomial.ext_iff] at h\n  rw [h m, coeff_zero, \u2190 Nat.cast_add_one, \u2190 nsmul_eq_mul', eq_comm, smul_eq_zero] at h2\n  replace h2 := h2.resolve_left m.succ_ne_zero\n  rw [hm, \u2190 leadingCoeff, leadingCoeff_eq_zero] at h2\n  exact hf h2\n#align polynomial.nat_degree_eq_zero_of_derivative_eq_zero Polynomial.natDegree_eq_zero_of_derivative_eq_zero\n\ntheorem eq_c_of_derivative_eq_zero [NoZeroSMulDivisors \u2115 R] {f : R[X]} (h : derivative f = 0) :\n    f = C (f.coeff 0) :=\n  eq_C_of_natDegree_eq_zero <| natDegree_eq_zero_of_derivative_eq_zero h\nset_option linter.uppercaseLean3 false in\n#align polynomial.eq_C_of_derivative_eq_zero Polynomial.eq_c_of_derivative_eq_zero\n\n@[simp]\ntheorem derivative_mul {f g : R[X]} : derivative (f * g) = derivative f * g + f * derivative g :=\n  calc\n    derivative (f * g) =\n        f.sum fun n a => g.sum fun m b => (n + m) \u2022 (C (a * b) * X ^ (n + m - 1)) :=\n      by\n      rw [mul_eq_sum_sum]\n      trans; exact derivative_sum\n      trans;\n      \u00b7 apply Finset.sum_congr rfl\n        intro x _\n        exact derivative_sum\n      apply Finset.sum_congr rfl; intro n _; apply Finset.sum_congr rfl; intro m _\n      trans\n      \u00b7 exact congr_arg _ C_mul_X_pow_eq_monomial.symm\n      dsimp; rw [\u2190 smul_mul_assoc, smul_C, nsmul_eq_mul']; exact derivative_C_mul_X_pow _ _\n    _ =\n        f.sum fun n a =>\n          g.sum fun m b =>\n            n \u2022 (C a * X ^ (n - 1)) * (C b * X ^ m) + C a * X ^ n * m \u2022 (C b * X ^ (m - 1)) :=\n      (sum_congr rfl fun n hn =>\n        sum_congr rfl fun m hm => by\n          cases n <;> cases m <;>\n              simp_rw [add_smul, mul_smul_comm, smul_mul_assoc, X_pow_mul_assoc, \u2190 mul_assoc, \u2190\n                C_mul, mul_assoc, \u2190 pow_add] <;>\n            simp [Nat.add_succ, Nat.succ_add, Nat.succ_sub_one, zero_smul, add_comm])\n    _ = derivative f * g + f * derivative g :=\n      by\n      conv =>\n        rhs\n        congr\n        \u00b7rw [\u2190 sum_C_mul_X_pow_eq g]\n        \u00b7rw [\u2190 sum_C_mul_X_pow_eq f]\n      simp only [sum, sum_add_distrib, Finset.mul_sum, Finset.sum_mul, derivative_apply]\n      simp_rw [\u2190 smul_mul_assoc, smul_C, nsmul_eq_mul']\n      rw [Finset.sum_comm]\n      congr 1\n      rw [Finset.sum_comm]\n#align polynomial.derivative_mul Polynomial.derivative_mul\n\ntheorem derivative_eval (p : R[X]) (x : R) :\n    p.derivative.eval x = p.sum fun n a => a * n * x ^ (n - 1) := by\n  simp_rw [derivative_apply, eval_sum, eval_mul_X_pow, eval_C]\n#align polynomial.derivative_eval Polynomial.derivative_eval\n\n@[simp]\ntheorem derivative_map [Semiring S] (p : R[X]) (f : R \u2192+* S) :\n    derivative (p.map f) = p.derivative.map f := by\n  let n := max p.natDegree (map f p).natDegree\n  rw [derivative_apply, derivative_apply]\n  rw [sum_over_range' _ _ (n + 1) ((le_max_left _ _).trans_lt (lt_add_one _))]\n  rw [sum_over_range' _ _ (n + 1) ((le_max_right _ _).trans_lt (lt_add_one _))]\n  simp only [Polynomial.map_sum, Polynomial.map_mul, Polynomial.map_C, map_mul, coeff_map,\n    map_natCast, Polynomial.map_nat_cast, Polynomial.map_pow, map_X]\n  all_goals intro n; rw [zero_mul, C_0, zero_mul]\n#align polynomial.derivative_map Polynomial.derivative_map\n\n@[simp]\ntheorem iterate_derivative_map [Semiring S] (p : R[X]) (f : R \u2192+* S) (k : \u2115) :\n    (Polynomial.derivative^[k]) (p.map f) = ((Polynomial.derivative^[k]) p).map f := by\n  induction' k with k ih generalizing p\n  \u00b7 simp\n  \u00b7 simp only [ih, Function.iterate_succ, Polynomial.derivative_map, Function.comp_apply]\n#align polynomial.iterate_derivative_map Polynomial.iterate_derivative_map\n\ntheorem derivative_nat_cast_mul {n : \u2115} {f : R[X]} :\n    derivative ((n : R[X]) * f) = n * derivative f := by\n  simp\n#align polynomial.derivative_nat_cast_mul Polynomial.derivative_nat_cast_mul\n\n@[simp]\ntheorem iterate_derivative_nat_cast_mul {n k : \u2115} {f : R[X]} :\n    (derivative^[k]) ((n : R[X]) * f) = n * (derivative^[k]) f := by\n  induction' k with k ih generalizing f <;> simp [*]\n#align polynomial.iterate_derivative_nat_cast_mul Polynomial.iterate_derivative_nat_cast_mul\n\ntheorem mem_support_derivative [NoZeroSMulDivisors \u2115 R] (p : R[X]) (n : \u2115) :\n    n \u2208 (derivative p).support \u2194 n + 1 \u2208 p.support := by\n  suffices \u00acp.coeff (n + 1) * (n + 1 : \u2115) = 0 \u2194 coeff p (n + 1) \u2260 0 by\n    simpa only [mem_support_iff, coeff_derivative, Ne.def, Nat.cast_succ]\n  rw [\u2190 nsmul_eq_mul', smul_eq_zero]\n  simp only [Nat.succ_ne_zero, false_or_iff]\n#align polynomial.mem_support_derivative Polynomial.mem_support_derivative\n\n@[simp]\ntheorem degree_derivative_eq [NoZeroSMulDivisors \u2115 R] (p : R[X]) (hp : 0 < natDegree p) :\n    degree (derivative p) = (natDegree p - 1 : \u2115) := by\n  apply le_antisymm\n  \u00b7 rw [derivative_apply]\n    apply le_trans (degree_sum_le _ _) (Finset.sup_le _)\n    intro n hn\n    simp only [Nat.cast_withBot]\n    apply le_trans (degree_C_mul_X_pow_le _ _) (WithBot.coe_le_coe.2 (tsub_le_tsub_right _ _))\n    apply le_natDegree_of_mem_supp _ hn\n  \u00b7 refine' le_sup _\n    rw [mem_support_derivative, tsub_add_cancel_of_le, mem_support_iff]\n    \u00b7 show \u00acleadingCoeff p = 0\n      rw [leadingCoeff_eq_zero]\n      intro h\n      rw [h, natDegree_zero] at hp\n      exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp)\n    exact hp\n#align polynomial.degree_derivative_eq Polynomial.degree_derivative_eq\n\ntheorem coeff_iterate_derivative_as_prod_Ico {k} (p : R[X]) :\n    \u2200 m : \u2115, ((derivative^[k]) p).coeff m = (\u220f i in Ico m.succ (m + k.succ), i) \u2022 p.coeff (m + k) :=\n  by\n  induction' k with k ih\n  \u00b7 simp  [add_zero, forall_const, one_smul, Ico_self, eq_self_iff_true,\n      Function.iterate_zero_apply, prod_empty]\n  \u00b7 intro m\n    rw [Function.iterate_succ_apply', coeff_derivative, ih (m + 1), \u2190 Nat.cast_add_one, \u2190\n      nsmul_eq_mul', smul_smul, mul_comm]\n    apply congr_arg\u2082\n    \u00b7 have set_eq : Ico m.succ (m + k.succ.succ) = Ico (m + 1).succ (m + 1 + k.succ) \u222a {m + 1} :=\n        by\n        simp_rw [\u2190 Nat.Ico_succ_singleton, union_comm, Nat.succ_eq_add_one, add_comm (k + 1),\n          add_assoc]\n        rw [Ico_union_Ico_eq_Ico] <;> simp\n      rw [set_eq, prod_union, prod_singleton]\n      \u00b7 rw [disjoint_singleton_right, mem_Ico]\n        exact fun h => (Nat.lt_succ_self _).not_le h.1\n    \u00b7 exact congr_arg _ (Nat.succ_add m k)\n#align polynomial.coeff_iterate_derivative_as_prod_Ico Polynomial.coeff_iterate_derivative_as_prod_Ico\n\ntheorem coeff_iterate_derivative_as_prod_range {k} (p : R[X]) :\n    \u2200 m : \u2115, ((derivative^[k]) p).coeff m = (\u220f i in range k, (m + k - i)) \u2022 p.coeff (m + k) := by\n  induction' k with k ih\n  \u00b7 simp\n  intro m\n  calc\n    ((derivative^[k + 1]) p).coeff m =\n        (\u220f i in range k, (m + k.succ - i)) \u2022 p.coeff (m + k.succ) * (m + 1) :=\n      by rw [Function.iterate_succ_apply', coeff_derivative, ih m.succ, Nat.succ_add, Nat.add_succ]\n    _ = ((\u220f i in range k, (m + k.succ - i)) * (m + 1)) \u2022 p.coeff (m + k.succ) := by\n      rw [\u2190 Nat.cast_add_one, \u2190 nsmul_eq_mul', smul_smul, mul_comm]\n    _ = (\u220f i in range k.succ, (m + k.succ - i)) \u2022 p.coeff (m + k.succ) := by\n      rw [prod_range_succ, add_tsub_assoc_of_le k.le_succ, Nat.succ_sub le_rfl, tsub_self]\n#align polynomial.coeff_iterate_derivative_as_prod_range Polynomial.coeff_iterate_derivative_as_prod_range\n\ntheorem iterate_derivative_mul {n} (p q : R[X]) :\n    (derivative^[n]) (p * q) =\n      \u2211 k in range n.succ, (n.choose k \u2022 ((derivative^[n - k]) p * (derivative^[k]) q)) := by\n  induction' n with n IH\n  \u00b7 simp [Finset.range]\n  calc\n    (derivative^[n + 1]) (p * q) =\n        derivative (\u2211 k : \u2115 in range n.succ,\n            n.choose k \u2022 ((derivative^[n - k]) p * (derivative^[k]) q)) :=\n      by rw [Function.iterate_succ_apply', IH]\n    _ =\n        (\u2211 k : \u2115 in range n.succ, n.choose k \u2022 ((derivative^[n - k + 1]) p * (derivative^[k]) q)) +\n          \u2211 k : \u2115 in range n.succ, n.choose k \u2022 ((derivative^[n - k]) p * (derivative^[k + 1]) q) :=\n      by\n      simp_rw [derivative_sum, derivative_smul, derivative_mul, Function.iterate_succ_apply',\n        smul_add, sum_add_distrib]\n    _ =\n        (\u2211 k : \u2115 in range n.succ,\n              n.choose k.succ \u2022 ((derivative^[n - k]) p * (derivative^[k + 1]) q)) +\n            1 \u2022 ((derivative^[n + 1]) p * (derivative^[0]) q) +\n          \u2211 k : \u2115 in range n.succ, n.choose k \u2022 ((derivative^[n - k]) p * (derivative^[k + 1]) q) :=\n      ?_\n    _ =\n        ((\u2211 k : \u2115 in range n.succ, n.choose k \u2022 ((derivative^[n - k]) p * (derivative^[k + 1]) q)) +\n            \u2211 k : \u2115 in range n.succ,\n              n.choose k.succ \u2022 ((derivative^[n - k]) p * (derivative^[k + 1]) q)) +\n          1 \u2022 ((derivative^[n + 1]) p * (derivative^[0]) q) :=\n      by rw [add_comm, add_assoc]\n    _ =\n        (\u2211 i : \u2115 in range n.succ,\n            (n + 1).choose (i + 1) \u2022 ((derivative^[n + 1 - (i + 1)]) p * (derivative^[i + 1]) q)) +\n          1 \u2022 ((derivative^[n + 1]) p * (derivative^[0]) q) :=\n      by simp_rw [Nat.choose_succ_succ, Nat.succ_sub_succ, add_smul, sum_add_distrib]\n    _ =\n        \u2211 k : \u2115 in range n.succ.succ,\n          n.succ.choose k \u2022 ((derivative^[n.succ - k]) p * (derivative^[k]) q) :=\n      by rw [sum_range_succ' _ n.succ, Nat.choose_zero_right, tsub_zero]\n\n  congr\n  refine' (sum_range_succ' _ _).trans (congr_arg\u2082 (\u00b7 + \u00b7) _ _)\n  \u00b7 rw [sum_range_succ, Nat.choose_succ_self, zero_smul, add_zero]\n    refine' sum_congr rfl fun k hk => _\n    rw [mem_range] at hk\n    congr\n    rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hk), Nat.succ_sub_succ]\n  \u00b7 rw [Nat.choose_zero_right, tsub_zero]\n#align polynomial.iterate_derivative_mul Polynomial.iterate_derivative_mul\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem derivative_pow_succ (p : R[X]) (n : \u2115) :\n    derivative (p ^ (n + 1)) = C (n + 1 : R) * p ^ n * derivative p :=\n  Nat.recOn n (by simp) fun n ih => by\n    rw [pow_succ', derivative_mul, ih, Nat.add_one, mul_right_comm, C_add,\n      add_mul, add_mul, pow_succ', \u2190 mul_assoc, C_1, one_mul]; simp [add_mul]\n#align polynomial.derivative_pow_succ Polynomial.derivative_pow_succ\n\ntheorem derivative_pow (p : R[X]) (n : \u2115) :\n    derivative (p ^ n) = C (n : R) * p ^ (n - 1) * derivative p :=\n  Nat.casesOn n (by rw [pow_zero, derivative_one, Nat.cast_zero, C_0, zero_mul, zero_mul]) fun n =>\n    by rw [p.derivative_pow_succ n, n.succ_sub_one, n.cast_succ]\n#align polynomial.derivative_pow Polynomial.derivative_pow\n\ntheorem derivative_sq (p : R[X]) : derivative (p ^ 2) = C 2 * p * derivative p := by\n  rw [derivative_pow_succ, Nat.cast_one, one_add_one_eq_two, pow_one]\n#align polynomial.derivative_sq Polynomial.derivative_sq\n\ntheorem dvd_iterate_derivative_pow (f : R[X]) (n : \u2115) {m : \u2115} (c : R) (hm : m \u2260 0) :\n    (n : R) \u2223 eval c ((derivative^[m]) (f ^ n)) := by\n  obtain \u27e8m, rfl\u27e9 := Nat.exists_eq_succ_of_ne_zero hm\n  rw [Function.iterate_succ_apply, derivative_pow, mul_assoc, C_eq_nat_cast,\n    iterate_derivative_nat_cast_mul, eval_mul, eval_nat_cast]\n  exact dvd_mul_right _ _\n#align polynomial.dvd_iterate_derivative_pow Polynomial.dvd_iterate_derivative_pow\n\ntheorem iterate_derivative_X_pow_eq_nat_cast_mul (n k : \u2115) :\n    (derivative^[k]) (X ^ n : R[X]) = \u2191(Nat.descFactorial n k : R[X]) * X ^ (n - k) := by\n  induction' k with k ih\n  \u00b7 erw [Function.iterate_zero_apply, tsub_zero, Nat.descFactorial_zero, Nat.cast_one, one_mul]\n  \u00b7 rw [Function.iterate_succ_apply', ih, derivative_nat_cast_mul, derivative_X_pow, C_eq_nat_cast,\n      Nat.succ_eq_add_one, Nat.descFactorial_succ, Nat.sub_sub, Nat.cast_mul];\n    simp [mul_comm, mul_assoc, mul_left_comm]\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_X_pow_eq_nat_cast_mul Polynomial.iterate_derivative_X_pow_eq_nat_cast_mul\n\ntheorem iterate_derivative_X_pow_eq_C_mul (n k : \u2115) :\n    (derivative^[k]) (X ^ n : R[X]) = C (Nat.descFactorial n k : R) * X ^ (n - k) := by\n  rw [iterate_derivative_X_pow_eq_nat_cast_mul n k, C_eq_nat_cast]\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_X_pow_eq_C_mul Polynomial.iterate_derivative_X_pow_eq_C_mul\n\ntheorem iterate_derivative_X_pow_eq_smul (n : \u2115) (k : \u2115) :\n    (derivative^[k]) (X ^ n : R[X]) = (Nat.descFactorial n k : R) \u2022 X ^ (n - k) := by\n  rw [iterate_derivative_X_pow_eq_C_mul n k, smul_eq_C_mul]\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_X_pow_eq_smul Polynomial.iterate_derivative_X_pow_eq_smul\n\ntheorem derivative_X_add_C_pow (c : R) (m : \u2115) :\n    derivative ((X + C c) ^ m) = C (m : R) * (X + C c) ^ (m - 1) := by\n  rw [derivative_pow, derivative_X_add_C, mul_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X_add_C_pow Polynomial.derivative_X_add_C_pow\n\ntheorem derivative_X_add_C_sq (c : R) : derivative ((X + C c) ^ 2) = C 2 * (X + C c) := by\n  rw [derivative_sq, derivative_X_add_C, mul_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X_add_C_sq Polynomial.derivative_X_add_C_sq\n\ntheorem iterate_derivative_X_add_pow (n k : \u2115) (c : R) :\n    (derivative^[k]) ((X + C c) ^ n) =\n     ((\u220f i in Finset.range k, (n - i) : \u2115) : R[X]) * (X + C c) ^ (n - k) := by\n  induction' k with k IH\n  \u00b7 simp\n  \u00b7 simp only [Function.iterate_succ_apply', IH, derivative_mul, zero_mul, derivative_nat_cast,\n      zero_add, Finset.prod_range_succ, C_eq_nat_cast, Nat.sub_sub, \u2190 mul_assoc,\n      derivative_X_add_C_pow, Nat.succ_eq_add_one, Nat.cast_mul]\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_X_add_pow Polynomial.iterate_derivative_X_add_pow\n\ntheorem derivative_comp (p q : R[X]) : derivative (p.comp q) = derivative q * p.derivative.comp q :=\n  by\n  induction p using Polynomial.induction_on'\n  \u00b7 simp [*, mul_add]\n  \u00b7 simp only [derivative_pow, derivative_mul, monomial_comp, derivative_monomial, derivative_C,\n      zero_mul, C_eq_nat_cast, zero_add, RingHom.map_mul]\n    -- is there a tactic for this? (a multiplicative `abel`):\n    rw [mul_comm (derivative q)]\n    simp only [mul_assoc]\n#align polynomial.derivative_comp Polynomial.derivative_comp\n\n/-- Chain rule for formal derivative of polynomials. -/\ntheorem derivative_eval\u2082_C (p q : R[X]) :\n    derivative (p.eval\u2082 C q) = p.derivative.eval\u2082 C q * derivative q :=\n  Polynomial.induction_on p (fun r => by rw [eval\u2082_C, derivative_C, eval\u2082_zero, zero_mul])\n    (fun p\u2081 p\u2082 ih\u2081 ih\u2082 => by\n      rw [eval\u2082_add, derivative_add, ih\u2081, ih\u2082, derivative_add, eval\u2082_add, add_mul])\n    fun n r ih => by\n    rw [pow_succ', \u2190 mul_assoc, eval\u2082_mul, eval\u2082_X, derivative_mul, ih, @derivative_mul _ _ _ X,\n      derivative_X, mul_one, eval\u2082_add, @eval\u2082_mul _ _ _ _ X, eval\u2082_X, add_mul, mul_right_comm]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_eval\u2082_C Polynomial.derivative_eval\u2082_C\n\ntheorem derivative_prod {s : Multiset \u03b9} {f : \u03b9 \u2192 R[X]} :\n    derivative (Multiset.map f s).prod =\n      (Multiset.map (fun i => (Multiset.map f (s.erase i)).prod * derivative (f i)) s).sum := by\n  refine' Multiset.induction_on s (by simp) fun i s h => _\n  rw [Multiset.map_cons, Multiset.prod_cons, derivative_mul, Multiset.map_cons _ i s,\n    Multiset.sum_cons, Multiset.erase_cons_head, mul_comm (derivative (f i))]\n  congr\n  rw [h, \u2190 AddMonoidHom.coe_mul_left, (AddMonoidHom.mulLeft (f i)).map_multiset_sum _,\n    AddMonoidHom.coe_mul_left]\n  simp only [Function.comp_apply, Multiset.map_map]\n  refine' congr_arg _ (Multiset.map_congr rfl fun j hj => _)\n  rw [\u2190 mul_assoc, \u2190 Multiset.prod_cons, \u2190 Multiset.map_cons]\n  by_cases hij : i = j\n  \u00b7 simp [hij, \u2190 Multiset.prod_cons, \u2190 Multiset.map_cons, Multiset.cons_erase hj]\n  \u00b7 simp [hij]\n#align polynomial.derivative_prod Polynomial.derivative_prod\n\nend CommSemiring\n\nsection Ring\n\nvariable [Ring R]\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_neg (f : R[X]) : derivative (-f) = -derivative f :=\n  LinearMap.map_neg derivative f\n#align polynomial.derivative_neg Polynomial.derivative_neg\n\n@[simp]\ntheorem iterate_derivative_neg {f : R[X]} {k : \u2115} : (derivative^[k]) (-f) = -(derivative^[k]) f :=\n  (@derivative R _).toAddMonoidHom.iterate_map_neg _ _\n#align polynomial.iterate_derivative_neg Polynomial.iterate_derivative_neg\n\n--Porting note: removed `simp`: `simp` can prove it.\ntheorem derivative_sub {f g : R[X]} : derivative (f - g) = derivative f - derivative g :=\n  LinearMap.map_sub derivative f g\n#align polynomial.derivative_sub Polynomial.derivative_sub\n\n--Porting note: removed `simp`: `simp` can prove it.\n\n\n@[simp]\ntheorem iterate_derivative_sub {k : \u2115} {f g : R[X]} :\n    (derivative^[k]) (f - g) = (derivative^[k]) f - (derivative^[k]) g := by\n  induction' k with k ih generalizing f g <;> simp [*]\n#align polynomial.iterate_derivative_sub Polynomial.iterate_derivative_sub\n\n@[simp]\ntheorem derivative_int_cast {n : \u2124} : derivative (n : R[X]) = 0 := by\n  rw [\u2190 C_eq_int_cast n]\n  exact derivative_C\n#align polynomial.derivative_int_cast Polynomial.derivative_int_cast\n\ntheorem derivative_int_cast_mul {n : \u2124} {f : R[X]} : derivative ((n : R[X]) * f) =\n    n * derivative f := by\n  simp\n#align polynomial.derivative_int_cast_mul Polynomial.derivative_int_cast_mul\n\n@[simp]\ntheorem iterate_derivative_int_cast_mul {n : \u2124} {k : \u2115} {f : R[X]} :\n    (derivative^[k]) ((n : R[X]) * f) = n * (derivative^[k]) f := by\n  induction' k with k ih generalizing f <;> simp [*]\n#align polynomial.iterate_derivative_int_cast_mul Polynomial.iterate_derivative_int_cast_mul\n\nend Ring\n\nsection CommRing\n\nvariable [CommRing R]\n\ntheorem derivative_comp_one_sub_X (p : R[X]) :\n    derivative (p.comp (1 - X)) = -p.derivative.comp (1 - X) := by simp [derivative_comp]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_comp_one_sub_X Polynomial.derivative_comp_one_sub_X\n\n@[simp]\ntheorem iterate_derivative_comp_one_sub_X (p : R[X]) (k : \u2115) :\n    (derivative^[k]) (p.comp (1 - X)) = (-1) ^ k * ((derivative^[k]) p).comp (1 - X) := by\n  induction' k with k ih generalizing p\n  \u00b7 simp\n  \u00b7 simp [ih (derivative p), iterate_derivative_neg, derivative_comp, pow_succ]\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_comp_one_sub_X Polynomial.iterate_derivative_comp_one_sub_X\n\ntheorem eval_multiset_prod_X_sub_C_derivative {S : Multiset R} {r : R} (hr : r \u2208 S) :\n    eval r (derivative (Multiset.map (fun a => X - C a) S).prod) =\n      (Multiset.map (fun a => r - a) (S.erase r)).prod := by\n  nth_rw 1 [\u2190 Multiset.cons_erase hr]\n  have := (evalRingHom r).map_multiset_prod (Multiset.map (fun a => X - C a) (S.erase r))\n  simpa using this\nset_option linter.uppercaseLean3 false in\n#align polynomial.eval_multiset_prod_X_sub_C_derivative Polynomial.eval_multiset_prod_X_sub_C_derivative\n\ntheorem derivative_X_sub_C_pow (c : R) (m : \u2115) :\n    derivative ((X - C c) ^ m) = C (m : R) * (X - C c) ^ (m - 1) := by\n  rw [derivative_pow, derivative_X_sub_C, mul_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X_sub_C_pow Polynomial.derivative_X_sub_C_pow\n\ntheorem derivative_X_sub_C_sq (c : R) : derivative ((X - C c) ^ 2) = C 2 * (X - C c) := by\n  rw [derivative_sq, derivative_X_sub_C, mul_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.derivative_X_sub_C_sq Polynomial.derivative_X_sub_C_sq\n\ntheorem iterate_derivative_X_sub_pow (n k : \u2115) (c : R) :\n    (derivative^[k]) ((X - C c) ^ n) = ((\u220f i in Finset.range k, (n - i) : \u2115) : R[X]) *\n    (X - C c) ^ (n - k) := by\n  rw [sub_eq_add_neg, \u2190 C_neg, iterate_derivative_X_add_pow]\nset_option linter.uppercaseLean3 false in\n#align polynomial.iterate_derivative_X_sub_pow Polynomial.iterate_derivative_X_sub_pow\n\nend CommRing\n\nend Derivative\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Derivative.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658466, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7435992664190837}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Bhavik Mehta, Stuart Presnell\n\n! This file was ported from Lean 3 source module data.nat.choose.basic\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Factorial.Basic\n\n/-!\n# Binomial coefficients\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines binomial coefficients and proves simple lemmas (i.e. those not\nrequiring more imports).\n\n## Main definition and results\n\n* `nat.choose`: binomial coefficients, defined inductively\n* `nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`\n* `nat.choose_symm`: symmetry of binomial coefficients\n* `nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`\n* `nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`\n* `nat.desc_factorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending\n  factorial. This is used to prove `nat.choose_le_pow` and variants. We provide similar statements\n  for the ascending factorial.\n* `nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations.\nThe fact that this is indeed the correct counting function for multisets is proved in\n`sym.card_sym_eq_multichoose` in `data/sym/card`.\n* `nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`.\nThis is central to the \"stars and bars\" technique in informal mathematics, where we switch between\ncounting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements\n(\"stars\") separated by `n-1` dividers (\"bars\").  See `data/sym/card` for more detail.\n\n## Tags\n\nbinomial coefficient, combination, multicombination, stars and bars\n-/\n\n\nopen Nat\n\nnamespace Nat\n\n#print Nat.choose /-\n/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial\ncoefficients. -/\ndef choose : \u2115 \u2192 \u2115 \u2192 \u2115\n  | _, 0 => 1\n  | 0, k + 1 => 0\n  | n + 1, k + 1 => choose n k + choose n (k + 1)\n#align nat.choose Nat.choose\n-/\n\n#print Nat.choose_zero_right /-\n@[simp]\ntheorem choose_zero_right (n : \u2115) : choose n 0 = 1 := by cases n <;> rfl\n#align nat.choose_zero_right Nat.choose_zero_right\n-/\n\n#print Nat.choose_zero_succ /-\n@[simp]\ntheorem choose_zero_succ (k : \u2115) : choose 0 (succ k) = 0 :=\n  rfl\n#align nat.choose_zero_succ Nat.choose_zero_succ\n-/\n\n#print Nat.choose_succ_succ /-\ntheorem choose_succ_succ (n k : \u2115) : choose (succ n) (succ k) = choose n k + choose n (succ k) :=\n  rfl\n#align nat.choose_succ_succ Nat.choose_succ_succ\n-/\n\n#print Nat.choose_eq_zero_of_lt /-\ntheorem choose_eq_zero_of_lt : \u2200 {n k}, n < k \u2192 choose n k = 0\n  | _, 0, hk => absurd hk (by decide)\n  | 0, k + 1, hk => choose_zero_succ _\n  | n + 1, k + 1, hk => by\n    have hnk : n < k := lt_of_succ_lt_succ hk\n    have hnk1 : n < k + 1 := lt_of_succ_lt hk\n    rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]\n#align nat.choose_eq_zero_of_lt Nat.choose_eq_zero_of_lt\n-/\n\n#print Nat.choose_self /-\n@[simp]\ntheorem choose_self (n : \u2115) : choose n n = 1 := by\n  induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]\n#align nat.choose_self Nat.choose_self\n-/\n\n#print Nat.choose_succ_self /-\n@[simp]\ntheorem choose_succ_self (n : \u2115) : choose n (succ n) = 0 :=\n  choose_eq_zero_of_lt (lt_succ_self _)\n#align nat.choose_succ_self Nat.choose_succ_self\n-/\n\n#print Nat.choose_one_right /-\n@[simp]\ntheorem choose_one_right (n : \u2115) : choose n 1 = n := by induction n <;> simp [*, choose, add_comm]\n#align nat.choose_one_right Nat.choose_one_right\n-/\n\n#print Nat.triangle_succ /-\n-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number\ntheorem triangle_succ (n : \u2115) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n :=\n  by\n  rw [\u2190 add_mul_div_left, mul_comm 2 n, \u2190 mul_add, add_tsub_cancel_right, mul_comm]\n  cases n <;> rfl; apply zero_lt_succ\n#align nat.triangle_succ Nat.triangle_succ\n-/\n\n#print Nat.choose_two_right /-\n/-- `choose n 2` is the `n`-th triangle number. -/\ntheorem choose_two_right (n : \u2115) : choose n 2 = n * (n - 1) / 2 :=\n  by\n  induction' n with n ih\n  simp\n  \u00b7 rw [triangle_succ n]\n    simp [choose, ih]\n    rw [add_comm]\n#align nat.choose_two_right Nat.choose_two_right\n-/\n\n#print Nat.choose_pos /-\ntheorem choose_pos : \u2200 {n k}, k \u2264 n \u2192 0 < choose n k\n  | 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk] <;> exact by decide\n  | n + 1, 0, hk => by simp <;> exact by decide\n  | n + 1, k + 1, hk => by\n    rw [choose_succ_succ] <;>\n      exact add_pos_of_pos_of_nonneg (choose_pos (le_of_succ_le_succ hk)) (Nat.zero_le _)\n#align nat.choose_pos Nat.choose_pos\n-/\n\n#print Nat.choose_eq_zero_iff /-\ntheorem choose_eq_zero_iff {n k : \u2115} : n.choose k = 0 \u2194 n < k :=\n  \u27e8fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt\u27e9\n#align nat.choose_eq_zero_iff Nat.choose_eq_zero_iff\n-/\n\n#print Nat.succ_mul_choose_eq /-\ntheorem succ_mul_choose_eq : \u2200 n k, succ n * choose n k = choose (succ n) (succ k) * succ k\n  | 0, 0 => by decide\n  | 0, k + 1 => by simp [choose]\n  | n + 1, 0 => by simp\n  | n + 1, k + 1 => by\n    rw [choose_succ_succ (succ n) (succ k), add_mul, \u2190 succ_mul_choose_eq, mul_succ, \u2190\n      succ_mul_choose_eq, add_right_comm, \u2190 mul_add, \u2190 choose_succ_succ, \u2190 succ_mul]\n#align nat.succ_mul_choose_eq Nat.succ_mul_choose_eq\n-/\n\n#print Nat.choose_mul_factorial_mul_factorial /-\ntheorem choose_mul_factorial_mul_factorial : \u2200 {n k}, k \u2264 n \u2192 choose n k * k ! * (n - k)! = n !\n  | 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]\n  | n + 1, 0, hk => by simp\n  | n + 1, succ k, hk => by\n    cases' lt_or_eq_of_le hk with hk\u2081 hk\u2081\n    \u00b7 have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by\n        rw [\u2190 choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)] <;>\n          simp [factorial_succ, mul_comm, mul_left_comm]\n      have h\u2081 : (n - k)! = (n - k) * (n - k.succ)! := by\n        rw [\u2190 succ_sub_succ, succ_sub (le_of_lt_succ hk\u2081), factorial_succ]\n      have h\u2082 : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by\n        rw [\u2190 choose_mul_factorial_mul_factorial (le_of_lt_succ hk\u2081)] <;>\n          simp [factorial_succ, mul_comm, mul_left_comm, mul_assoc]\n      have h\u2083 : k * n ! \u2264 n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk)\n      rw [choose_succ_succ, add_mul, add_mul, succ_sub_succ, h, h\u2081, h\u2082, add_mul, tsub_mul,\n        factorial_succ, \u2190 add_tsub_assoc_of_le h\u2083, add_assoc, \u2190 add_mul, add_tsub_cancel_left,\n        add_comm]\n    \u00b7 simp [hk\u2081, mul_comm, choose, tsub_self]\n#align nat.choose_mul_factorial_mul_factorial Nat.choose_mul_factorial_mul_factorial\n-/\n\n#print Nat.choose_mul /-\ntheorem choose_mul {n k s : \u2115} (hkn : k \u2264 n) (hsk : s \u2264 k) :\n    n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=\n  by\n  have h : (n - k)! * (k - s)! * s ! \u2260 0 := by apply_rules [mul_ne_zero, factorial_ne_zero]\n  refine' mul_right_cancel\u2080 h _\n  calc\n    n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) =\n        n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! :=\n      by\n      rw [mul_assoc, mul_assoc, mul_assoc, mul_assoc _ s !, mul_assoc, mul_comm (n - k)!,\n        mul_comm s !]\n    _ = n ! := by\n      rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]\n    _ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by\n      rw [choose_mul_factorial_mul_factorial (tsub_le_tsub_right hkn _),\n        choose_mul_factorial_mul_factorial (hsk.trans hkn)]\n    _ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by\n      rw [tsub_tsub_tsub_cancel_right hsk, mul_assoc, mul_left_comm s !, mul_assoc,\n        mul_comm (k - s)!, mul_comm s !, mul_right_comm, \u2190 mul_assoc]\n    \n#align nat.choose_mul Nat.choose_mul\n-/\n\n#print Nat.choose_eq_factorial_div_factorial /-\ntheorem choose_eq_factorial_div_factorial {n k : \u2115} (hk : k \u2264 n) :\n    choose n k = n ! / (k ! * (n - k)!) :=\n  by\n  rw [\u2190 choose_mul_factorial_mul_factorial hk, mul_assoc]\n  exact (mul_div_left _ (mul_pos (factorial_pos _) (factorial_pos _))).symm\n#align nat.choose_eq_factorial_div_factorial Nat.choose_eq_factorial_div_factorial\n-/\n\n#print Nat.add_choose /-\ntheorem add_choose (i j : \u2115) : (i + j).choose j = (i + j)! / (i ! * j !) := by\n  rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), add_tsub_cancel_right, mul_comm]\n#align nat.add_choose Nat.add_choose\n-/\n\n#print Nat.add_choose_mul_factorial_mul_factorial /-\ntheorem add_choose_mul_factorial_mul_factorial (i j : \u2115) :\n    (i + j).choose j * i ! * j ! = (i + j)! := by\n  rw [\u2190 choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), add_tsub_cancel_right,\n    mul_right_comm]\n#align nat.add_choose_mul_factorial_mul_factorial Nat.add_choose_mul_factorial_mul_factorial\n-/\n\n#print Nat.factorial_mul_factorial_dvd_factorial /-\ntheorem factorial_mul_factorial_dvd_factorial {n k : \u2115} (hk : k \u2264 n) : k ! * (n - k)! \u2223 n ! := by\n  rw [\u2190 choose_mul_factorial_mul_factorial hk, mul_assoc] <;> exact dvd_mul_left _ _\n#align nat.factorial_mul_factorial_dvd_factorial Nat.factorial_mul_factorial_dvd_factorial\n-/\n\n#print Nat.factorial_mul_factorial_dvd_factorial_add /-\ntheorem factorial_mul_factorial_dvd_factorial_add (i j : \u2115) : i ! * j ! \u2223 (i + j)! :=\n  by\n  convert factorial_mul_factorial_dvd_factorial (le.intro rfl)\n  rw [add_tsub_cancel_left]\n#align nat.factorial_mul_factorial_dvd_factorial_add Nat.factorial_mul_factorial_dvd_factorial_add\n-/\n\n#print Nat.choose_symm /-\n@[simp]\ntheorem choose_symm {n k : \u2115} (hk : k \u2264 n) : choose n (n - k) = choose n k := by\n  rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _),\n    tsub_tsub_cancel_of_le hk, mul_comm]\n#align nat.choose_symm Nat.choose_symm\n-/\n\n#print Nat.choose_symm_of_eq_add /-\ntheorem choose_symm_of_eq_add {n a b : \u2115} (h : n = a + b) : Nat.choose n a = Nat.choose n b :=\n  by\n  convert Nat.choose_symm (Nat.le_add_left _ _)\n  rw [add_tsub_cancel_right]\n#align nat.choose_symm_of_eq_add Nat.choose_symm_of_eq_add\n-/\n\n#print Nat.choose_symm_add /-\ntheorem choose_symm_add {a b : \u2115} : choose (a + b) a = choose (a + b) b :=\n  choose_symm_of_eq_add rfl\n#align nat.choose_symm_add Nat.choose_symm_add\n-/\n\n#print Nat.choose_symm_half /-\ntheorem choose_symm_half (m : \u2115) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m :=\n  by\n  apply choose_symm_of_eq_add\n  rw [add_comm m 1, add_assoc 1 m m, add_comm (2 * m) 1, two_mul m]\n#align nat.choose_symm_half Nat.choose_symm_half\n-/\n\n#print Nat.choose_succ_right_eq /-\ntheorem choose_succ_right_eq (n k : \u2115) : choose n (k + 1) * (k + 1) = choose n k * (n - k) :=\n  by\n  have e : (n + 1) * choose n k = choose n k * (k + 1) + choose n (k + 1) * (k + 1)\n  rw [\u2190 right_distrib, \u2190 choose_succ_succ, succ_mul_choose_eq]\n  rw [\u2190 tsub_eq_of_eq_add_rev e, mul_comm, \u2190 mul_tsub, add_tsub_add_eq_tsub_right]\n#align nat.choose_succ_right_eq Nat.choose_succ_right_eq\n-/\n\n#print Nat.choose_succ_self_right /-\n@[simp]\ntheorem choose_succ_self_right : \u2200 n : \u2115, (n + 1).choose n = n + 1\n  | 0 => rfl\n  | n + 1 => by rw [choose_succ_succ, choose_succ_self_right, choose_self]\n#align nat.choose_succ_self_right Nat.choose_succ_self_right\n-/\n\n#print Nat.choose_mul_succ_eq /-\ntheorem choose_mul_succ_eq (n k : \u2115) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) :=\n  by\n  induction' k with k ih; \u00b7 simp\n  obtain hk | hk := le_or_lt (k + 1) (n + 1)\n  \u00b7\n    rw [choose_succ_succ, add_mul, succ_sub_succ, \u2190 choose_succ_right_eq, \u2190 succ_sub_succ, mul_tsub,\n      add_tsub_cancel_of_le (Nat.mul_le_mul_left _ hk)]\n  rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk),\n    MulZeroClass.zero_mul, MulZeroClass.zero_mul]\n#align nat.choose_mul_succ_eq Nat.choose_mul_succ_eq\n-/\n\n#print Nat.ascFactorial_eq_factorial_mul_choose /-\ntheorem ascFactorial_eq_factorial_mul_choose (n k : \u2115) :\n    n.ascFactorial k = k ! * (n + k).choose k :=\n  by\n  rw [mul_comm]\n  apply mul_right_cancel\u2080 (factorial_ne_zero (n + k - k))\n  rw [choose_mul_factorial_mul_factorial, add_tsub_cancel_right, \u2190 factorial_mul_asc_factorial,\n    mul_comm]\n  exact Nat.le_add_left k n\n#align nat.asc_factorial_eq_factorial_mul_choose Nat.ascFactorial_eq_factorial_mul_choose\n-/\n\n#print Nat.factorial_dvd_ascFactorial /-\ntheorem factorial_dvd_ascFactorial (n k : \u2115) : k ! \u2223 n.ascFactorial k :=\n  \u27e8(n + k).choose k, ascFactorial_eq_factorial_mul_choose _ _\u27e9\n#align nat.factorial_dvd_asc_factorial Nat.factorial_dvd_ascFactorial\n-/\n\n#print Nat.choose_eq_asc_factorial_div_factorial /-\ntheorem choose_eq_asc_factorial_div_factorial (n k : \u2115) :\n    (n + k).choose k = n.ascFactorial k / k ! :=\n  by\n  apply mul_left_cancel\u2080 (factorial_ne_zero k)\n  rw [\u2190 asc_factorial_eq_factorial_mul_choose]\n  exact (Nat.mul_div_cancel' <| factorial_dvd_asc_factorial _ _).symm\n#align nat.choose_eq_asc_factorial_div_factorial Nat.choose_eq_asc_factorial_div_factorial\n-/\n\n#print Nat.descFactorial_eq_factorial_mul_choose /-\ntheorem descFactorial_eq_factorial_mul_choose (n k : \u2115) : n.descFactorial k = k ! * n.choose k :=\n  by\n  obtain h | h := Nat.lt_or_ge n k\n  \u00b7 rw [desc_factorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, MulZeroClass.mul_zero]\n  rw [mul_comm]\n  apply mul_right_cancel\u2080 (factorial_ne_zero (n - k))\n  rw [choose_mul_factorial_mul_factorial h, \u2190 factorial_mul_desc_factorial h, mul_comm]\n#align nat.desc_factorial_eq_factorial_mul_choose Nat.descFactorial_eq_factorial_mul_choose\n-/\n\n#print Nat.factorial_dvd_descFactorial /-\ntheorem factorial_dvd_descFactorial (n k : \u2115) : k ! \u2223 n.descFactorial k :=\n  \u27e8n.choose k, descFactorial_eq_factorial_mul_choose _ _\u27e9\n#align nat.factorial_dvd_desc_factorial Nat.factorial_dvd_descFactorial\n-/\n\n#print Nat.choose_eq_descFactorial_div_factorial /-\ntheorem choose_eq_descFactorial_div_factorial (n k : \u2115) : n.choose k = n.descFactorial k / k ! :=\n  by\n  apply mul_left_cancel\u2080 (factorial_ne_zero k)\n  rw [\u2190 desc_factorial_eq_factorial_mul_choose]\n  exact (Nat.mul_div_cancel' <| factorial_dvd_desc_factorial _ _).symm\n#align nat.choose_eq_desc_factorial_div_factorial Nat.choose_eq_descFactorial_div_factorial\n-/\n\n/-! ### Inequalities -/\n\n\n#print Nat.choose_le_succ_of_lt_half_left /-\n/-- Show that `nat.choose` is increasing for small values of the right argument. -/\ntheorem choose_le_succ_of_lt_half_left {r n : \u2115} (h : r < n / 2) : choose n r \u2264 choose n (r + 1) :=\n  by\n  refine' le_of_mul_le_mul_right _ (lt_tsub_iff_left.mpr (lt_of_lt_of_le h (n.div_le_self 2)))\n  rw [\u2190 choose_succ_right_eq]\n  apply Nat.mul_le_mul_left\n  rw [\u2190 Nat.lt_iff_add_one_le, lt_tsub_iff_left, \u2190 mul_two]\n  exact lt_of_lt_of_le (mul_lt_mul_of_pos_right h zero_lt_two) (n.div_mul_le_self 2)\n#align nat.choose_le_succ_of_lt_half_left Nat.choose_le_succ_of_lt_half_left\n-/\n\n/-- Show that for small values of the right argument, the middle value is largest. -/\nprivate theorem choose_le_middle_of_le_half_left {n r : \u2115} (hr : r \u2264 n / 2) :\n    choose n r \u2264 choose n (n / 2) :=\n  decreasingInduction\n    (fun _ k a =>\n      (eq_or_lt_of_le a).elim (fun t => t.symm \u25b8 le_rfl) fun h =>\n        (choose_le_succ_of_lt_half_left h).trans (k h))\n    hr (fun _ => le_rfl) hr\n#align nat.choose_le_middle_of_le_half_left nat.choose_le_middle_of_le_half_left\n\n#print Nat.choose_le_middle /-\n/-- `choose n r` is maximised when `r` is `n/2`. -/\ntheorem choose_le_middle (r n : \u2115) : choose n r \u2264 choose n (n / 2) :=\n  by\n  cases' le_or_gt r n with b b\n  \u00b7 cases' le_or_lt r (n / 2) with a h\n    \u00b7 apply choose_le_middle_of_le_half_left a\n    \u00b7 rw [\u2190 choose_symm b]\n      apply choose_le_middle_of_le_half_left\n      rw [div_lt_iff_lt_mul' zero_lt_two] at h\n      rw [le_div_iff_mul_le' zero_lt_two, tsub_mul, tsub_le_iff_tsub_le, mul_two,\n        add_tsub_cancel_right]\n      exact le_of_lt h\n  \u00b7 rw [choose_eq_zero_of_lt b]\n    apply zero_le\n#align nat.choose_le_middle Nat.choose_le_middle\n-/\n\n/-! #### Inequalities about increasing the first argument -/\n\n\n#print Nat.choose_le_succ /-\ntheorem choose_le_succ (a c : \u2115) : choose a c \u2264 choose a.succ c := by\n  cases c <;> simp [Nat.choose_succ_succ]\n#align nat.choose_le_succ Nat.choose_le_succ\n-/\n\n#print Nat.choose_le_add /-\ntheorem choose_le_add (a b c : \u2115) : choose a c \u2264 choose (a + b) c :=\n  by\n  induction' b with b_n b_ih\n  \u00b7 simp\n  exact le_trans b_ih (choose_le_succ (a + b_n) c)\n#align nat.choose_le_add Nat.choose_le_add\n-/\n\n#print Nat.choose_le_choose /-\ntheorem choose_le_choose {a b : \u2115} (c : \u2115) (h : a \u2264 b) : choose a c \u2264 choose b c :=\n  add_tsub_cancel_of_le h \u25b8 choose_le_add a (b - a) c\n#align nat.choose_le_choose Nat.choose_le_choose\n-/\n\n#print Nat.choose_mono /-\ntheorem choose_mono (b : \u2115) : Monotone fun a => choose a b := fun _ _ => choose_le_choose b\n#align nat.choose_mono Nat.choose_mono\n-/\n\n/-! #### Multichoose\n\nWhereas `choose n k` is the number of subsets of cardinality `k` from a type of cardinality `n`,\n`multichoose n k` is the number of multisets of cardinality `k` from a type of cardinality `n`.\n\nAlternatively, whereas `choose n k` counts the number of combinations,\ni.e. ways to select `k` items (up to permutation) from `n` items without replacement,\n`multichoose n k` counts the number of multicombinations,\ni.e. ways to select `k` items (up to permutation) from `n` items with replacement.\n\nNote that `multichoose` is *not* the multinomial coefficient, although it can be computed\nin terms of multinomial coefficients. For details see https://mathworld.wolfram.com/Multichoose.html\n\nTODO: Prove that `choose (-n) k = (-1)^k * multichoose n k`,\nwhere `choose` is the generalized binomial coefficient.\n<https://github.com/leanprover-community/mathlib/pull/15072#issuecomment-1171415738>\n\n-/\n\n\n#print Nat.multichoose /-\n/--\n`multichoose n k` is the number of multisets of cardinality `k` from a type of cardinality `n`. -/\ndef multichoose : \u2115 \u2192 \u2115 \u2192 \u2115\n  | _, 0 => 1\n  | 0, k + 1 => 0\n  | n + 1, k + 1 => multichoose n (k + 1) + multichoose (n + 1) k\n#align nat.multichoose Nat.multichoose\n-/\n\n#print Nat.multichoose_zero_right /-\n@[simp]\ntheorem multichoose_zero_right (n : \u2115) : multichoose n 0 = 1 := by cases n <;> simp [multichoose]\n#align nat.multichoose_zero_right Nat.multichoose_zero_right\n-/\n\n#print Nat.multichoose_zero_succ /-\n@[simp]\ntheorem multichoose_zero_succ (k : \u2115) : multichoose 0 (k + 1) = 0 := by simp [multichoose]\n#align nat.multichoose_zero_succ Nat.multichoose_zero_succ\n-/\n\n#print Nat.multichoose_succ_succ /-\ntheorem multichoose_succ_succ (n k : \u2115) :\n    multichoose (n + 1) (k + 1) = multichoose n (k + 1) + multichoose (n + 1) k := by\n  simp [multichoose]\n#align nat.multichoose_succ_succ Nat.multichoose_succ_succ\n-/\n\n#print Nat.multichoose_one /-\n@[simp]\ntheorem multichoose_one (k : \u2115) : multichoose 1 k = 1 :=\n  by\n  induction' k with k IH; \u00b7 simp\n  simp [multichoose_succ_succ 0 k, IH]\n#align nat.multichoose_one Nat.multichoose_one\n-/\n\n#print Nat.multichoose_two /-\n@[simp]\ntheorem multichoose_two (k : \u2115) : multichoose 2 k = k + 1 :=\n  by\n  induction' k with k IH; \u00b7 simp\n  simp [multichoose_succ_succ 1 k, IH]\n  rw [add_comm]\n#align nat.multichoose_two Nat.multichoose_two\n-/\n\n#print Nat.multichoose_one_right /-\n@[simp]\ntheorem multichoose_one_right (n : \u2115) : multichoose n 1 = n :=\n  by\n  induction' n with n IH; \u00b7 simp\n  simp [multichoose_succ_succ n 0, IH]\n#align nat.multichoose_one_right Nat.multichoose_one_right\n-/\n\n#print Nat.multichoose_eq /-\ntheorem multichoose_eq : \u2200 n k : \u2115, multichoose n k = (n + k - 1).choose k\n  | _, 0 => by simp\n  | 0, k + 1 => by simp\n  | n + 1, k + 1 =>\n    by\n    rw [multichoose_succ_succ, add_comm, Nat.succ_add_sub_one, \u2190 add_assoc, Nat.choose_succ_succ]\n    simp [multichoose_eq]\n#align nat.multichoose_eq Nat.multichoose_eq\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Choose/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7435992590958623}}
{"text": "import data.fintype\n\nstructure finite_graph :=\n(vertices : Type)\n(vertices_are_finite : fintype vertices)\n(edges : vertices \u2192 vertices \u2192 Prop)\n(no_loops : \u2200 v : vertices, \u00ac (edges v v))\n(edges_symm : \u2200 v w : vertices, edges v w \u2192 edges w v)\n\nopen finite_graph \n\nvariable {G : finite_graph} \n\nnotation : v ` E ` w := edges v w -- notation for edges -- can be anything.\n\nexample (v w : G.vertices) : v E w \u2192 w E v := sorry -- curses\n\n/-\n\nCan we prove that a graph has a Hamilton cycle or Euler cycle, iff it's connected and all but at most 2 degrees are even\n-/", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/graph_theory/paths.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7435992477712181}}
{"text": "import data.real.basic\n\ntheorem indonesia_MO_Probel_4_2017 (x y : \u211d): \n(x^100 - y^100 = 2^99 * (x-y)) \u2227 (x^200 - y^200 = 2^199 * (x-y)) \u2192 \n((x,y) = (0,2) \u2228  (x,y) = (2,0)) := sorry", "meta": {"author": "ahayat16", "repo": "lean_exos", "sha": "682f2552d5b04a8c8eb9e4ab15f875a91b03845c", "save_path": "github-repos/lean/ahayat16-lean_exos", "path": "github-repos/lean/ahayat16-lean_exos/lean_exos-682f2552d5b04a8c8eb9e4ab15f875a91b03845c/src_icannos_totilas/aops/2017-Indonesia_MO-Problem_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9566342012360932, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7435916219453691}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport algebra.group_power.basic\nimport algebra.hom.iterate\nimport algebra.regular.basic\n\n/-!\n# Regular elements\n\n## Implementation details\n\nGroup powers and other definitions import a lot of the algebra hierarchy.\nLemmas about them are kept separate to be able to provide `is_regular` early in the\nalgebra hierarchy.\n\n-/\n\nvariables {R : Type*} {a b : R}\n\nsection monoid\n\nvariable [monoid R]\n\n/--  Any power of a left-regular element is left-regular. -/\nlemma is_left_regular.pow (n : \u2115) (rla : is_left_regular a) : is_left_regular (a ^ n) :=\nby simp only [is_left_regular, \u2190 mul_left_iterate, rla.iterate n]\n\n/--  Any power of a right-regular element is right-regular. -/\nlemma is_right_regular.pow (n : \u2115) (rra : is_right_regular a) : is_right_regular (a ^ n) :=\nby { rw [is_right_regular, \u2190 mul_right_iterate], exact rra.iterate n }\n\n/--  Any power of a regular element is regular. -/\nlemma is_regular.pow (n : \u2115) (ra : is_regular a) : is_regular (a ^ n) :=\n\u27e8is_left_regular.pow n ra.left, is_right_regular.pow n ra.right\u27e9\n\n/--  An element `a` is left-regular if and only if a positive power of `a` is left-regular. -/\nlemma is_left_regular.pow_iff {n : \u2115} (n0 : 0 < n) :\n  is_left_regular (a ^ n) \u2194 is_left_regular a :=\nbegin\n  refine \u27e8_, is_left_regular.pow n\u27e9,\n  rw [\u2190 nat.succ_pred_eq_of_pos n0, pow_succ'],\n  exact is_left_regular.of_mul,\nend\n\n/--  An element `a` is right-regular if and only if a positive power of `a` is right-regular. -/\nlemma is_right_regular.pow_iff {n : \u2115} (n0 : 0 < n) :\n  is_right_regular (a ^ n) \u2194 is_right_regular a :=\nbegin\n  refine \u27e8_, is_right_regular.pow n\u27e9,\n  rw [\u2190 nat.succ_pred_eq_of_pos n0, pow_succ],\n  exact is_right_regular.of_mul,\nend\n\n/--  An element `a` is regular if and only if a positive power of `a` is regular. -/\nlemma is_regular.pow_iff {n : \u2115} (n0 : 0 < n) :\n  is_regular (a ^ n) \u2194 is_regular a :=\n\u27e8\u03bb h, \u27e8(is_left_regular.pow_iff n0).mp h.left, (is_right_regular.pow_iff n0).mp h.right\u27e9,\n  \u03bb h, \u27e8is_left_regular.pow n h.left, is_right_regular.pow n h.right\u27e9\u27e9\n\nend monoid\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/regular/pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.868826769445233, "lm_q1q2_score": 0.7435863935344116}}
{"text": "/- Comments -/\n\n\nimport Lean.Parser.Term\n\n#check Prop \n\nvariable (A B C D E : Prop)\n\n#check D \n\n/- truth and falsity -/\n\n#check True \n#check False \n\n/- Connectives -/ \n\n/- Negation -/ \n\n#check \u00ac A \n/- type \\neg -/ \n#check Not  \n#reduce \u00ac A \n\n/- Implication -/ \n\ndef Implies (P Q : Prop) : Prop := P \u2192 Q \n#check A \u2192 B \n#check Implies A B\n/- \\to  -/\n#check A -> B \n\n/- And -/\n\n#check And A B \n#check A /\\ B\n#check A \u2227 B \n/- \\and -/ \n\n/- Or -/ \n\n#check Or A B \n#check A \\/ B \n#check A \u2228 B \n/- \\or -/\n\n/- Bi-implication -/\n\n#check Iff A B \n#check A \u2194 B \n#check Iff \n/- \\iff -/\n\n/- Examples -/\n\n#check A \u2227 B \u2192 C \n#check \u00ac A \u2228 C \u2194 A \u2192 B \n#check (A \u2192 B) \u2192 False  \n\n#check Classical.em A\n#check em A\n\n/- What is a proof? -/ \n\nvariable (h : A) \n\n#check h \n\nexample (h : A) : A := h\n\ntheorem identity (h : A) : A := h \n\nvariable {G H : Prop}\n\ntheorem superProof (h : G) : H := sorry \n\n#check superProof\n\nexample : A \u2192 B := fun (h : A) => (superProof h)\n\n#check And\n\n#check Or.elim\n#check Or.inl \nexample (h : A \u2228 B) : B \u2228 A := Or.elim h (fun (a:A) => Or.inr a) _ \n\n#reduce Not A \n\n#check Iff.intro\n\nopen Lean Parser Term\nmacro \"assume \" var:funBinder \", \" exp:term : term => `(fun $var => $exp)\n\n#check assume (a:A)\n\nexample : (A \u2192 A) := \n  assume (a : A), a\n  show A from a \n\nexample (h : A \u2192 B \u2227 C) : A \u2192 C := fun (a : A) => And.right (h a)\n\nexample : A \u2227 B \u2192 A \u2228 B := fun (p : A \u2227 B) => Or.inl (And.left p)\n\nexample  (h : A \u2227 B) : (B \u2227 B) := And.intro (And.right h) (And.right h)\n\nexample : (A \u2192 B) \u2192 (\u00ac B \u2192 \u00ac A) := \n  fun (f: A \u2192 B) => fun (h : \u00ac B) => fun (a : A) => h (f a) \n\n#check @Classical.byContradiction A  \n\nexample : \u00ac \u00ac A \u2192 A := fun (h : \u00ac \u00ac A) => Classical.byContradiction (fun (n : \u00ac A) => h n) \n\n#check Classical.em\n\n#check False.elim  \n\nexample (h : \u00ac B \u2192 \u00ac A) : (A \u2192 B) := \n  Or.elim (Classical.em B) (fun (b : B) (_ : A) => b) (fun (n : \u00ac B) (a : A) => False.elim (h n a)) \n\nexample : False := by sorry \n\nexample (A B C : Prop) : (A \u2192 B \u2227 C) \u2192 (A \u2192 B) \u2227 (A \u2192 C) := by \n  intro (h : A \u2192 B \u2227 C)\n  have (f : A \u2192 B) := fun (a:A) => And.left (h a)\n  have (g : A \u2192 C) := fun (a:A) => And.right (h a)\n  exact And.intro f g  \n\nexample (a : A) (b : B) : A \u2227 B := by\n  apply And.intro\n  case left => exact a\n  case right => exact b \n\nexample (h : A \u2228 B) : B \u2228 A := by \n  cases h with \n  | inl a => exact Or.inr a\n  | inr b => exact Or.inl b \n\nexample (p q : Prop) (h : p \u2228 q): q \u2228 p := by\n  cases h with\n  | inr hq => apply Or.inl; exact hq\n  | inl hp => apply Or.inr; exact hp ", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "lean-notes", "sha": "40c1fe4cff620355bc3c9fa31ad886cb7836f7f3", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-lean-notes", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-lean-notes/lean-notes-40c1fe4cff620355bc3c9fa31ad886cb7836f7f3/Notes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7434810571062468}}
{"text": "/-\nCopyright (c) 2020 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Lacker, Bryan Gin-ge Chen\n-/\nimport data.nat.prime\nimport data.int.basic\n/-!\n# Lemmas about nat.prime using `int`s\n-/\n\nopen nat\n\nnamespace int\n\nlemma not_prime_of_int_mul {a b : \u2124} {c : \u2115}\n  (ha : 1 < a.nat_abs) (hb : 1 < b.nat_abs) (hc : a*b = (c : \u2124)) : \u00ac nat.prime c :=\nnot_prime_mul' (nat_abs_mul_nat_abs_eq hc) ha hb\n\nend int\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/int/nat_prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7434810487959448}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport tactic.rcases\nimport computability.language\n\n/-!\n# Regular Expressions\n\nThis file contains the formal definition for regular expressions and basic lemmas. Note these are\nregular expressions in terms of formal language theory. Note this is different to regex's used in\ncomputer science such as the POSIX standard.\n\nTODO\n* Show that this regular expressions and DFA/NFA's are equivalent.\n* `attribute [pattern] has_mul.mul` has been added into this file, it could be moved.\n-/\n\nuniverse u\n\nvariables {\u03b1 : Type u} [dec : decidable_eq \u03b1]\n\n/--\nThis is the definition of regular expressions. The names used here is to mirror the definition\nof a Kleene algebra (https://en.wikipedia.org/wiki/Kleene_algebra).\n* `0` (`zero`) matches nothing\n* `1` (`epsilon`) matches only the empty string\n* `char a` matches only the string 'a'\n* `star P` matches any finite concatenation of strings which match `P`\n* `P + Q` (`plus P Q`) matches anything which match `P` or `Q`\n* `P * Q` (`comp P Q`) matches `x ++ y` if `x` matches `P` and `y` matches `Q`\n-/\ninductive regular_expression (\u03b1 : Type u) : Type u\n| zero : regular_expression\n| epsilon : regular_expression\n| char : \u03b1 \u2192 regular_expression\n| plus : regular_expression \u2192 regular_expression \u2192 regular_expression\n| comp : regular_expression \u2192 regular_expression \u2192 regular_expression\n| star : regular_expression \u2192 regular_expression\n\nnamespace regular_expression\n\ninstance : inhabited (regular_expression \u03b1) := \u27e8zero\u27e9\n\ninstance : has_add (regular_expression \u03b1) := \u27e8plus\u27e9\ninstance : has_mul (regular_expression \u03b1) := \u27e8comp\u27e9\ninstance : has_one (regular_expression \u03b1) := \u27e8epsilon\u27e9\ninstance : has_zero (regular_expression \u03b1) := \u27e8zero\u27e9\n\nattribute [pattern] has_mul.mul\n\n@[simp] lemma zero_def : (zero : regular_expression \u03b1) = 0 := rfl\n@[simp] lemma one_def : (epsilon : regular_expression \u03b1) = 1 := rfl\n\n@[simp] lemma plus_def (P Q : regular_expression \u03b1) : plus P Q = P + Q := rfl\n@[simp] lemma comp_def (P Q : regular_expression \u03b1) : comp P Q = P * Q := rfl\n\n/-- `matches P` provides a language which contains all strings that `P` matches -/\ndef matches : regular_expression \u03b1 \u2192 language \u03b1\n| 0 := 0\n| 1 := 1\n| (char a) := {[a]}\n| (P + Q) := P.matches + Q.matches\n| (P * Q) := P.matches * Q.matches\n| (star P) := P.matches.star\n\n@[simp] lemma matches_zero_def : (0 : regular_expression \u03b1).matches = 0 := rfl\n@[simp] lemma matches_epsilon_def : (1 : regular_expression \u03b1).matches = 1 := rfl\n@[simp] lemma matches_add_def (P Q : regular_expression \u03b1) :\n  (P + Q).matches = P.matches + Q.matches := rfl\n@[simp] lemma matches_mul_def (P Q : regular_expression \u03b1) :\n  (P * Q).matches = P.matches * Q.matches := rfl\n@[simp] lemma matches_star_def (P : regular_expression \u03b1) : P.star.matches = P.matches.star := rfl\n\n/-- `match_epsilon P` is true if and only if `P` matches the empty string -/\ndef match_epsilon : regular_expression \u03b1 \u2192 bool\n| 0 := ff\n| 1 := tt\n| (char _) := ff\n| (P + Q) := P.match_epsilon || Q.match_epsilon\n| (P * Q) := P.match_epsilon && Q.match_epsilon\n| (star P) := tt\n\ninclude dec\n\n/-- `P.deriv a` matches `x` if `P` matches `a :: x`, the Brzozowski derivative of `P` with respect\n  to `a` -/\ndef deriv : regular_expression \u03b1 \u2192 \u03b1 \u2192 regular_expression \u03b1\n| 0 _ := 0\n| 1 _ := 0\n| (char a\u2081) a\u2082 := if a\u2081 = a\u2082 then 1 else 0\n| (P + Q) a := deriv P a + deriv Q a\n| (P * Q) a :=\n  if P.match_epsilon then\n    deriv P a * Q + deriv Q a\n  else\n    deriv P a * Q\n| (star P) a := deriv P a * star P\n\n/-- `P.rmatch x` is true if and only if `P` matches `x`. This is a computable definition equivalent\n  to `matches`. -/\ndef rmatch : regular_expression \u03b1 \u2192 list \u03b1 \u2192 bool\n| P [] := match_epsilon P\n| P (a::as) := rmatch (P.deriv a) as\n\n@[simp] lemma zero_rmatch (x : list \u03b1) : rmatch 0 x = ff :=\nby induction x; simp [rmatch, match_epsilon, deriv, *]\n\n\n\nlemma char_rmatch_iff (a : \u03b1) (x : list \u03b1) : rmatch (char a) x \u2194 x = [a] :=\nbegin\n  cases x with _ x,\n    dec_trivial,\n  cases x,\n    rw [rmatch, deriv],\n    split_ifs;\n    tauto,\n  rw [rmatch, deriv],\n  split_ifs,\n    rw one_rmatch_iff,\n    tauto,\n  rw zero_rmatch,\n  tauto\nend\n\nlemma add_rmatch_iff (P Q : regular_expression \u03b1) (x : list \u03b1) :\n  (P + Q).rmatch x \u2194 P.rmatch x \u2228 Q.rmatch x :=\nbegin\n  induction x with _ _ ih generalizing P Q,\n  { repeat {rw rmatch},\n    rw match_epsilon,\n    finish },\n  { repeat {rw rmatch},\n    rw deriv,\n    exact ih _ _ }\nend\n\nlemma mul_rmatch_iff (P Q : regular_expression \u03b1) (x : list \u03b1) :\n  (P * Q).rmatch x \u2194 \u2203 t u : list \u03b1, x = t ++ u \u2227 P.rmatch t \u2227 Q.rmatch u :=\nbegin\n  induction x with a x ih generalizing P Q,\n  { rw [rmatch, match_epsilon],\n    split,\n    { intro h,\n      refine \u27e8 [], [], rfl, _ \u27e9,\n      rw [rmatch, rmatch],\n      rwa band_coe_iff at h },\n    { rintro \u27e8 t, u, h\u2081, h\u2082 \u27e9,\n      cases list.append_eq_nil.1 h\u2081.symm with ht hu,\n      subst ht,\n      subst hu,\n      repeat {rw rmatch at h\u2082},\n      finish } },\n  { rw [rmatch, deriv],\n    split_ifs with hepsilon,\n    { rw [add_rmatch_iff, ih],\n      split,\n      { rintro (\u27e8 t, u, _ \u27e9 | h),\n        { exact \u27e8 a :: t, u, by tauto \u27e9 },\n        { exact \u27e8 [], a :: x, rfl, hepsilon, h \u27e9 } },\n      { rintro \u27e8 t, u, h, hP, hQ \u27e9,\n        cases t with b t,\n        { right,\n          rw list.nil_append at h,\n          rw \u2190h at hQ,\n          exact hQ },\n        { left,\n          refine \u27e8 t, u, by finish, _, hQ \u27e9,\n          rw rmatch at hP,\n          convert hP,\n          finish } } },\n    { rw ih,\n      split;\n      rintro \u27e8 t, u, h, hP, hQ \u27e9,\n      { exact \u27e8 a :: t, u, by tauto \u27e9 },\n      { cases t with b t,\n        { contradiction },\n        { refine \u27e8 t, u, by finish, _, hQ \u27e9,\n          rw rmatch at hP,\n          convert hP,\n          finish } } } }\nend\n\nlemma star_rmatch_iff (P : regular_expression \u03b1) : \u2200 (x : list \u03b1),\n  (star P).rmatch x \u2194 \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 t \u2208 S, t \u2260 [] \u2227 P.rmatch t\n| x :=\nbegin\n  have A : \u2200 (m n : \u2115), n < m + n + 1,\n  { assume m n,\n    convert add_lt_add_of_le_of_lt (add_le_add (zero_le m) (le_refl n)) zero_lt_one,\n    simp },\n  have IH := \u03bb t (h : list.length t < list.length x), star_rmatch_iff t,\n  clear star_rmatch_iff,\n  split,\n  { cases x with a x,\n    { intro,\n      fconstructor,\n      exact [],\n      tauto },\n    { rw [rmatch, deriv, mul_rmatch_iff],\n      rintro \u27e8 t, u, hs, ht, hu \u27e9,\n      have hwf : u.length < (list.cons a x).length,\n      { rw [hs, list.length_cons, list.length_append],\n        apply A },\n      rw IH _ hwf at hu,\n      rcases hu with \u27e8 S', hsum, helem \u27e9,\n      use (a :: t) :: S',\n      split,\n      { finish },\n      { intros t' ht',\n        cases ht' with ht' ht',\n        { rw ht',\n          exact \u27e8 dec_trivial, ht \u27e9 },\n        { exact helem _ ht' } } } },\n  { rintro \u27e8 S, hsum, helem \u27e9,\n    cases x with a x,\n    { dec_trivial },\n    { rw [rmatch, deriv, mul_rmatch_iff],\n      cases S with t' U,\n      { exact \u27e8 [], [], by tauto \u27e9 },\n      { cases t' with b t,\n        { finish },\n        refine \u27e8 t, U.join, by finish, _, _ \u27e9,\n        { specialize helem (b :: t) _,\n          { finish },\n          rw rmatch at helem,\n          convert helem.2,\n          finish },\n        { have hwf : U.join.length < (list.cons a x).length,\n          { rw hsum,\n            simp only\n              [list.join, list.length_append, list.cons_append, list.length_join, list.length],\n            apply A },\n          rw IH _ hwf,\n          refine \u27e8 U, rfl, \u03bb t h, helem t _ \u27e9,\n          right,\n          assumption } } } }\nend\nusing_well_founded\n{ rel_tac := \u03bb _ _, `[exact \u27e8(\u03bb L\u2081 L\u2082 : list _, L\u2081.length < L\u2082.length), inv_image.wf _ nat.lt_wf\u27e9] }\n\n@[simp] lemma rmatch_iff_matches (P : regular_expression \u03b1) :\n  \u2200 x : list \u03b1, P.rmatch x \u2194 x \u2208 P.matches :=\nbegin\n  intro x,\n  induction P generalizing x,\n  all_goals\n  { try {rw zero_def},\n    try {rw one_def},\n    try {rw plus_def},\n    try {rw comp_def},\n    rw matches },\n  case zero :\n  { rw zero_rmatch,\n    tauto },\n  case epsilon :\n  { rw one_rmatch_iff,\n    refl },\n  case char :\n  { rw char_rmatch_iff,\n    refl },\n  case plus : _ _ ih\u2081 ih\u2082\n  { rw [add_rmatch_iff, ih\u2081, ih\u2082],\n    refl },\n  case comp : P Q ih\u2081 ih\u2082\n  { simp only [mul_rmatch_iff, comp_def, language.mul_def, exists_and_distrib_left, set.mem_image2,\n      set.image_prod],\n    split,\n    { rintro \u27e8 x, y, hsum, hmatch\u2081, hmatch\u2082 \u27e9,\n      rw ih\u2081 at hmatch\u2081,\n      rw ih\u2082 at hmatch\u2082,\n      exact \u27e8 x, hmatch\u2081, y, hmatch\u2082, hsum.symm \u27e9 },\n    { rintro \u27e8 x, hmatch\u2081, y, hmatch\u2082, hsum \u27e9,\n      rw \u2190ih\u2081 at hmatch\u2081,\n      rw \u2190ih\u2082 at hmatch\u2082,\n      exact \u27e8 x, y, hsum.symm, hmatch\u2081, hmatch\u2082 \u27e9 } },\n  case star : _ ih\n  { rw [star_rmatch_iff, language.star_def_nonempty],\n    split,\n    all_goals\n    { rintro \u27e8 S, hx, hS \u27e9,\n      refine \u27e8 S, hx, _ \u27e9,\n      intro y,\n      specialize hS y },\n    { rw \u2190ih y,\n      tauto },\n    { rw ih y,\n      tauto } }\nend\n\ninstance (P : regular_expression \u03b1) : decidable_pred P.matches :=\nbegin\n  intro x,\n  change decidable (x \u2208 P.matches),\n  rw \u2190rmatch_iff_matches,\n  exact eq.decidable _ _\nend\n\nend regular_expression\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/computability/regular_expressions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7434544665924506}}
{"text": "/-\nCopyright (c) 2023 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport data.set.image\nimport data.list.basic\nimport data.fin.basic\n\n/-!\n# Lemmas about `list`s and `set.range`\n\nIn this file we prove lemmas about range of some operations on lists.\n-/\n\nopen list\nvariables {\u03b1 \u03b2 : Type*} (l : list \u03b1)\n\nnamespace set\n\nlemma range_list_map (f : \u03b1 \u2192 \u03b2) : range (map f) = {l | \u2200 x \u2208 l, x \u2208 range f} :=\nbegin\n  refine subset.antisymm (range_subset_iff.2 $ \u03bb l, forall_mem_map_iff.2 $ \u03bb y _, mem_range_self _)\n    (\u03bb l hl, _),\n  induction l with a l ihl, { exact \u27e8[], rfl\u27e9 },\n  rcases ihl (\u03bb x hx, hl x $ subset_cons _ _ hx) with \u27e8l, rfl\u27e9,\n  rcases hl a (mem_cons_self _ _) with \u27e8a, rfl\u27e9,\n  exact \u27e8a :: l, map_cons _ _ _\u27e9\nend\n\nlemma range_list_map_coe (s : set \u03b1) : range (map (coe : s \u2192 \u03b1)) = {l | \u2200 x \u2208 l, x \u2208 s} :=\nby rw [range_list_map, subtype.range_coe]\n\n@[simp] lemma range_list_nth_le : range (\u03bb k : fin l.length, l.nth_le k k.2) = {x | x \u2208 l} :=\nbegin\n  ext x,\n  rw [mem_set_of_eq, mem_iff_nth_le],\n  exact \u27e8\u03bb \u27e8\u27e8n, h\u2081\u27e9, h\u2082\u27e9, \u27e8n, h\u2081, h\u2082\u27e9, \u03bb \u27e8n, h\u2081, h\u2082\u27e9, \u27e8\u27e8n, h\u2081\u27e9, h\u2082\u27e9\u27e9\nend\n\nlemma range_list_nth : range l.nth = insert none (some '' {x | x \u2208 l}) :=\nbegin\n  rw [\u2190 range_list_nth_le, \u2190 range_comp],\n  refine (range_subset_iff.2 $ \u03bb n, _).antisymm (insert_subset.2 \u27e8_, _\u27e9),\n  exacts [(le_or_lt l.length n).imp nth_eq_none_iff.2 (\u03bb hlt, \u27e8\u27e8_, _\u27e9, (nth_le_nth hlt).symm\u27e9),\n    \u27e8_, nth_eq_none_iff.2 le_rfl\u27e9, range_subset_iff.2 $ \u03bb k, \u27e8_, nth_le_nth _\u27e9]\nend\n\n@[simp] lemma range_list_nthd (d : \u03b1) : range (\u03bb n, l.nthd n d) = insert d {x | x \u2208 l} :=\ncalc range (\u03bb n, l.nthd n d) = (\u03bb o : option \u03b1, o.get_or_else d) '' range l.nth :\n  by simp only [\u2190 range_comp, (\u2218), nthd_eq_get_or_else_nth]\n... = insert d {x | x \u2208 l} :\n  by simp only [range_list_nth, image_insert_eq, option.get_or_else, image_image, image_id']\n\n@[simp]\nlemma range_list_inth [inhabited \u03b1] (l : list \u03b1) : range l.inth = insert default {x | x \u2208 l} :=\nrange_list_nthd l default\n\nend set\n\n/-- If each element of a list can be lifted to some type, then the whole list can be lifted to this\ntype. -/\ninstance list.can_lift (c) (p) [can_lift \u03b1 \u03b2 c p] :\n  can_lift (list \u03b1) (list \u03b2) (list.map c) (\u03bb l, \u2200 x \u2208 l, p x) :=\n{ prf  := \u03bb l H,\n    begin\n      rw [\u2190 set.mem_range, set.range_list_map],\n      exact \u03bb a ha, can_lift.prf a (H a ha),\n    end}\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/set/list.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7434141207677198}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\nimport order.rel_classes\nimport data.set.intervals.basic\n\n/-!\n# Bounded and unbounded sets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe prove miscellaneous lemmas about bounded and unbounded sets. Many of these are just variations on\nthe same ideas, or similar results with a few minor differences. The file is divided into these\ndifferent general ideas.\n-/\n\nnamespace set\nvariables {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s t : set \u03b1}\n\n/-! ### Subsets of bounded and unbounded sets -/\n\ntheorem bounded.mono (hst : s \u2286 t) (hs : bounded r t) : bounded r s :=\nhs.imp $ \u03bb a ha b hb, ha b (hst hb)\n\ntheorem unbounded.mono (hst : s \u2286 t) (hs : unbounded r s) : unbounded r t :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := hs a in \u27e8b, hst hb, hb'\u27e9\n\n/-! ### Alternate characterizations of unboundedness on orders -/\n\nlemma unbounded_le_of_forall_exists_lt [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, a < b) : unbounded (\u2264) s :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := h a in \u27e8b, hb, \u03bb hba, hba.not_lt hb'\u27e9\n\nlemma unbounded_le_iff [linear_order \u03b1] : unbounded (\u2264) s \u2194 \u2200 a, \u2203 b \u2208 s, a < b :=\nby simp only [unbounded, not_le]\n\nlemma unbounded_lt_of_forall_exists_le [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, a \u2264 b) : unbounded (<) s :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := h a in \u27e8b, hb, \u03bb hba, hba.not_le hb'\u27e9\n\nlemma unbounded_lt_iff [linear_order \u03b1] : unbounded (<) s \u2194 \u2200 a, \u2203 b \u2208 s, a \u2264 b :=\nby simp only [unbounded, not_lt]\n\nlemma unbounded_ge_of_forall_exists_gt [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, b < a) : unbounded (\u2265) s :=\n@unbounded_le_of_forall_exists_lt \u03b1\u1d52\u1d48 _ _ h\n\nlemma unbounded_ge_iff [linear_order \u03b1] : unbounded (\u2265) s \u2194 \u2200 a, \u2203 b \u2208 s, b < a :=\n\u27e8\u03bb h a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, lt_of_not_ge hba\u27e9, unbounded_ge_of_forall_exists_gt\u27e9\n\nlemma unbounded_gt_of_forall_exists_ge [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, b \u2264 a) : unbounded (>) s :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := h a in \u27e8b, hb, \u03bb hba, not_le_of_gt hba hb'\u27e9\n\nlemma unbounded_gt_iff [linear_order \u03b1] : unbounded (>) s \u2194 \u2200 a, \u2203 b \u2208 s, b \u2264 a :=\n\u27e8\u03bb h a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, le_of_not_gt hba\u27e9, unbounded_gt_of_forall_exists_ge\u27e9\n\n/-! ### Relation between boundedness by strict and nonstrict orders. -/\n\n/-! #### Less and less or equal -/\n\nlemma bounded.rel_mono {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (h : bounded r s) (hrr' : r \u2264 r') : bounded r' s :=\nlet \u27e8a, ha\u27e9 := h in \u27e8a, \u03bb b hb, hrr' b a (ha b hb)\u27e9\n\nlemma bounded_le_of_bounded_lt [preorder \u03b1] (h : bounded (<) s) : bounded (\u2264) s :=\nh.rel_mono $ \u03bb _ _, le_of_lt\n\nlemma unbounded.rel_mono {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (hr : r' \u2264 r) (h : unbounded r s) : unbounded r' s :=\n\u03bb a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, \u03bb hba', hba (hr b a hba')\u27e9\n\nlemma unbounded_lt_of_unbounded_le [preorder \u03b1] (h : unbounded (\u2264) s) :\n  unbounded (<) s :=\nh.rel_mono $ \u03bb _ _, le_of_lt\n\nlemma bounded_le_iff_bounded_lt [preorder \u03b1] [no_max_order \u03b1] : bounded (\u2264) s \u2194 bounded (<) s :=\nbegin\n  refine \u27e8\u03bb h, _, bounded_le_of_bounded_lt\u27e9,\n  cases h with a ha,\n  cases exists_gt a with b hb,\n  exact \u27e8b, \u03bb c hc, lt_of_le_of_lt (ha c hc) hb\u27e9\nend\n\nlemma unbounded_lt_iff_unbounded_le [preorder \u03b1] [no_max_order \u03b1] :\n  unbounded (<) s \u2194 unbounded (\u2264) s :=\nby simp_rw [\u2190 not_bounded_iff, bounded_le_iff_bounded_lt]\n\n/-! #### Greater and greater or equal -/\n\nlemma bounded_ge_of_bounded_gt [preorder \u03b1] (h : bounded (>) s) : bounded (\u2265) s :=\nlet \u27e8a, ha\u27e9 := h in \u27e8a, \u03bb b hb, le_of_lt (ha b hb)\u27e9\n\nlemma unbounded_gt_of_unbounded_ge [preorder \u03b1] (h : unbounded (\u2265) s) : unbounded (>) s :=\n\u03bb a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, \u03bb hba', hba (le_of_lt hba')\u27e9\n\nlemma bounded_ge_iff_bounded_gt [preorder \u03b1] [no_min_order \u03b1] : bounded (\u2265) s \u2194 bounded (>) s :=\n@bounded_le_iff_bounded_lt \u03b1\u1d52\u1d48 _ _ _\n\nlemma unbounded_gt_iff_unbounded_ge [preorder \u03b1] [no_min_order \u03b1] :\n  unbounded (>) s \u2194 unbounded (\u2265) s :=\n@unbounded_lt_iff_unbounded_le \u03b1\u1d52\u1d48 _ _ _\n\n/-! ### The universal set -/\n\ntheorem unbounded_le_univ [has_le \u03b1] [no_top_order \u03b1] : unbounded (\u2264) (@set.univ \u03b1) :=\n\u03bb a, let \u27e8b, hb\u27e9 := exists_not_le a in \u27e8b, \u27e8\u27e9, hb\u27e9\n\ntheorem unbounded_lt_univ [preorder \u03b1] [no_top_order \u03b1] : unbounded (<) (@set.univ \u03b1) :=\nunbounded_lt_of_unbounded_le unbounded_le_univ\n\ntheorem unbounded_ge_univ [has_le \u03b1] [no_bot_order \u03b1] : unbounded (\u2265) (@set.univ \u03b1) :=\n\u03bb a, let \u27e8b, hb\u27e9 := exists_not_ge a in \u27e8b, \u27e8\u27e9, hb\u27e9\n\ntheorem unbounded_gt_univ [preorder \u03b1] [no_bot_order \u03b1] : unbounded (>) (@set.univ \u03b1) :=\nunbounded_gt_of_unbounded_ge unbounded_ge_univ\n\n/-! ### Bounded and unbounded intervals -/\n\ntheorem bounded_self (a : \u03b1) : bounded r {b | r b a} :=\n\u27e8a, \u03bb x, id\u27e9\n\n/-! #### Half-open bounded intervals -/\n\n\n\ntheorem bounded_le_Iio [preorder \u03b1] (a : \u03b1) : bounded (\u2264) (set.Iio a) :=\nbounded_le_of_bounded_lt (bounded_lt_Iio a)\n\ntheorem bounded_le_Iic [preorder \u03b1] (a : \u03b1) : bounded (\u2264) (set.Iic a) :=\nbounded_self a\n\ntheorem bounded_lt_Iic [preorder \u03b1] [no_max_order \u03b1] (a : \u03b1) : bounded (<) (set.Iic a) :=\nby simp only [\u2190 bounded_le_iff_bounded_lt, bounded_le_Iic]\n\ntheorem bounded_gt_Ioi [preorder \u03b1] (a : \u03b1) : bounded (>) (set.Ioi a) :=\nbounded_self a\n\ntheorem bounded_ge_Ioi [preorder \u03b1] (a : \u03b1) : bounded (\u2265) (set.Ioi a) :=\nbounded_ge_of_bounded_gt (bounded_gt_Ioi a)\n\ntheorem bounded_ge_Ici [preorder \u03b1] (a : \u03b1) : bounded (\u2265) (set.Ici a) :=\nbounded_self a\n\ntheorem bounded_gt_Ici [preorder \u03b1] [no_min_order \u03b1] (a : \u03b1) : bounded (>) (set.Ici a) :=\nby simp only [\u2190 bounded_ge_iff_bounded_gt, bounded_ge_Ici]\n\n/-! #### Other bounded intervals -/\n\ntheorem bounded_lt_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (<) (set.Ioo a b) :=\n(bounded_lt_Iio b).mono set.Ioo_subset_Iio_self\n\ntheorem bounded_lt_Ico [preorder \u03b1] (a b : \u03b1) : bounded (<) (set.Ico a b) :=\n(bounded_lt_Iio b).mono set.Ico_subset_Iio_self\n\ntheorem bounded_lt_Ioc [preorder \u03b1] [no_max_order \u03b1] (a b : \u03b1) : bounded (<) (set.Ioc a b) :=\n(bounded_lt_Iic b).mono set.Ioc_subset_Iic_self\n\ntheorem bounded_lt_Icc [preorder \u03b1] [no_max_order \u03b1] (a b : \u03b1) : bounded (<) (set.Icc a b) :=\n(bounded_lt_Iic b).mono set.Icc_subset_Iic_self\n\ntheorem bounded_le_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Ioo a b) :=\n(bounded_le_Iio b).mono set.Ioo_subset_Iio_self\n\ntheorem bounded_le_Ico [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Ico a b) :=\n(bounded_le_Iio b).mono set.Ico_subset_Iio_self\n\ntheorem bounded_le_Ioc [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Ioc a b) :=\n(bounded_le_Iic b).mono set.Ioc_subset_Iic_self\n\ntheorem bounded_le_Icc [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Icc a b) :=\n(bounded_le_Iic b).mono set.Icc_subset_Iic_self\n\ntheorem bounded_gt_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (>) (set.Ioo a b) :=\n(bounded_gt_Ioi a).mono set.Ioo_subset_Ioi_self\n\ntheorem bounded_gt_Ioc [preorder \u03b1] (a b : \u03b1) : bounded (>) (set.Ioc a b) :=\n(bounded_gt_Ioi a).mono set.Ioc_subset_Ioi_self\n\ntheorem bounded_gt_Ico [preorder \u03b1] [no_min_order \u03b1] (a b : \u03b1) : bounded (>) (set.Ico a b) :=\n(bounded_gt_Ici a).mono set.Ico_subset_Ici_self\n\ntheorem bounded_gt_Icc [preorder \u03b1] [no_min_order \u03b1] (a b : \u03b1) : bounded (>) (set.Icc a b) :=\n(bounded_gt_Ici a).mono set.Icc_subset_Ici_self\n\ntheorem bounded_ge_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Ioo a b) :=\n(bounded_ge_Ioi a).mono set.Ioo_subset_Ioi_self\n\ntheorem bounded_ge_Ioc [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Ioc a b) :=\n(bounded_ge_Ioi a).mono set.Ioc_subset_Ioi_self\n\ntheorem bounded_ge_Ico [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Ico a b) :=\n(bounded_ge_Ici a).mono set.Ico_subset_Ici_self\n\ntheorem bounded_ge_Icc [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Icc a b) :=\n(bounded_ge_Ici a).mono set.Icc_subset_Ici_self\n\n/-! #### Unbounded intervals -/\n\ntheorem unbounded_le_Ioi [semilattice_sup \u03b1] [no_max_order \u03b1] (a : \u03b1) : unbounded (\u2264) (set.Ioi a) :=\n\u03bb b, let \u27e8c, hc\u27e9 := exists_gt (a \u2294 b) in\n  \u27e8c, le_sup_left.trans_lt hc, (le_sup_right.trans_lt hc).not_le\u27e9\n\ntheorem unbounded_le_Ici [semilattice_sup \u03b1] [no_max_order \u03b1] (a : \u03b1) : unbounded (\u2264) (set.Ici a) :=\n(unbounded_le_Ioi a).mono set.Ioi_subset_Ici_self\n\ntheorem unbounded_lt_Ioi [semilattice_sup \u03b1] [no_max_order \u03b1] (a : \u03b1) : unbounded (<) (set.Ioi a) :=\nunbounded_lt_of_unbounded_le (unbounded_le_Ioi a)\n\ntheorem unbounded_lt_Ici [semilattice_sup \u03b1] (a : \u03b1) : unbounded (<) (set.Ici a) :=\n\u03bb b, \u27e8a \u2294 b, le_sup_left, le_sup_right.not_lt\u27e9\n\n/-! ### Bounded initial segments -/\n\ntheorem bounded_inter_not (H : \u2200 a b, \u2203 m, \u2200 c, r c a \u2228 r c b \u2192 r c m) (a : \u03b1) :\n  bounded r (s \u2229 {b | \u00ac r b a}) \u2194 bounded r s :=\nbegin\n  refine \u27e8_, bounded.mono (set.inter_subset_left s _)\u27e9,\n  rintro \u27e8b, hb\u27e9,\n  cases H a b with m hm,\n  exact \u27e8m, \u03bb c hc, hm c (or_iff_not_imp_left.2 (\u03bb hca, (hb c \u27e8hc, hca\u27e9)))\u27e9\nend\n\ntheorem unbounded_inter_not (H : \u2200 a b, \u2203 m, \u2200 c, r c a \u2228 r c b \u2192 r c m) (a : \u03b1) :\n  unbounded r (s \u2229 {b | \u00ac r b a}) \u2194 unbounded r s :=\nby simp_rw [\u2190 not_bounded_iff, bounded_inter_not H]\n\n/-! #### Less or equal -/\n\ntheorem bounded_le_inter_not_le [semilattice_sup \u03b1] (a : \u03b1) :\n  bounded (\u2264) (s \u2229 {b | \u00ac b \u2264 a}) \u2194 bounded (\u2264) s :=\nbounded_inter_not (\u03bb x y, \u27e8x \u2294 y, \u03bb z h, h.elim le_sup_of_le_left le_sup_of_le_right\u27e9) a\n\ntheorem unbounded_le_inter_not_le [semilattice_sup \u03b1] (a : \u03b1) :\n  unbounded (\u2264) (s \u2229 {b | \u00ac b \u2264 a}) \u2194 unbounded (\u2264) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_le_inter_not_le a\nend\n\ntheorem bounded_le_inter_lt [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2264) (s \u2229 {b | a < b}) \u2194 bounded (\u2264) s :=\nby simp_rw [\u2190 not_le, bounded_le_inter_not_le]\n\ntheorem unbounded_le_inter_lt [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2264) (s \u2229 {b | a < b}) \u2194 unbounded (\u2264) s :=\nby { convert unbounded_le_inter_not_le a, ext, exact lt_iff_not_le }\n\ntheorem bounded_le_inter_le [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2264) (s \u2229 {b | a \u2264 b}) \u2194 bounded (\u2264) s :=\nbegin\n  refine \u27e8_, bounded.mono (set.inter_subset_left s _)\u27e9,\n  rw \u2190@bounded_le_inter_lt _ s _ a,\n  exact bounded.mono (\u03bb x \u27e8hx, hx'\u27e9, \u27e8hx, le_of_lt hx'\u27e9)\nend\n\ntheorem unbounded_le_inter_le [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2264) (s \u2229 {b | a \u2264 b}) \u2194 unbounded (\u2264) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_le_inter_le a\nend\n\n/-! #### Less than -/\n\ntheorem bounded_lt_inter_not_lt [semilattice_sup \u03b1] (a : \u03b1) :\n  bounded (<) (s \u2229 {b | \u00ac b < a}) \u2194 bounded (<) s :=\nbounded_inter_not (\u03bb x y, \u27e8x \u2294 y, \u03bb z h, h.elim lt_sup_of_lt_left lt_sup_of_lt_right\u27e9) a\n\ntheorem unbounded_lt_inter_not_lt [semilattice_sup \u03b1] (a : \u03b1) :\n  unbounded (<) (s \u2229 {b | \u00ac b < a}) \u2194 unbounded (<) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_lt_inter_not_lt a\nend\n\ntheorem bounded_lt_inter_le [linear_order \u03b1] (a : \u03b1) :\n  bounded (<) (s \u2229 {b | a \u2264 b}) \u2194 bounded (<) s :=\nby { convert bounded_lt_inter_not_lt a, ext, exact not_lt.symm }\n\ntheorem unbounded_lt_inter_le [linear_order \u03b1] (a : \u03b1) :\n  unbounded (<) (s \u2229 {b | a \u2264 b}) \u2194 unbounded (<) s :=\nby { convert unbounded_lt_inter_not_lt a, ext, exact not_lt.symm }\n\ntheorem bounded_lt_inter_lt [linear_order \u03b1] [no_max_order \u03b1] (a : \u03b1) :\n  bounded (<) (s \u2229 {b | a < b}) \u2194 bounded (<) s :=\nbegin\n  rw [\u2190bounded_le_iff_bounded_lt, \u2190bounded_le_iff_bounded_lt],\n  exact bounded_le_inter_lt a\nend\n\ntheorem unbounded_lt_inter_lt [linear_order \u03b1] [no_max_order \u03b1] (a : \u03b1) :\n  unbounded (<) (s \u2229 {b | a < b}) \u2194 unbounded (<) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_lt_inter_lt a\nend\n\n/-! #### Greater or equal -/\n\ntheorem bounded_ge_inter_not_ge [semilattice_inf \u03b1] (a : \u03b1) :\n  bounded (\u2265) (s \u2229 {b | \u00ac a \u2264 b}) \u2194 bounded (\u2265) s :=\n@bounded_le_inter_not_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_ge_inter_not_ge [semilattice_inf \u03b1] (a : \u03b1) :\n  unbounded (\u2265) (s \u2229 {b | \u00ac a \u2264 b}) \u2194 unbounded (\u2265) s :=\n@unbounded_le_inter_not_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_ge_inter_gt [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2265) (s \u2229 {b | b < a}) \u2194 bounded (\u2265) s :=\n@bounded_le_inter_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_ge_inter_gt [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2265) (s \u2229 {b | b < a}) \u2194 unbounded (\u2265) s :=\n@unbounded_le_inter_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_ge_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2265) (s \u2229 {b | b \u2264 a}) \u2194 bounded (\u2265) s :=\n@bounded_le_inter_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_ge_iff_unbounded_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2265) (s \u2229 {b | b \u2264 a}) \u2194 unbounded (\u2265) s :=\n@unbounded_le_inter_le \u03b1\u1d52\u1d48 s _ a\n\n/-! #### Greater than -/\n\ntheorem bounded_gt_inter_not_gt [semilattice_inf \u03b1] (a : \u03b1) :\n  bounded (>) (s \u2229 {b | \u00ac a < b}) \u2194 bounded (>) s :=\n@bounded_lt_inter_not_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_gt_inter_not_gt [semilattice_inf \u03b1] (a : \u03b1) :\n  unbounded (>) (s \u2229 {b | \u00ac a < b}) \u2194 unbounded (>) s :=\n@unbounded_lt_inter_not_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_gt_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  bounded (>) (s \u2229 {b | b \u2264 a}) \u2194 bounded (>) s :=\n@bounded_lt_inter_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  unbounded (>) (s \u2229 {b | b \u2264 a}) \u2194 unbounded (>) s :=\n@unbounded_lt_inter_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_gt_inter_gt [linear_order \u03b1] [no_min_order \u03b1] (a : \u03b1) :\n  bounded (>) (s \u2229 {b | b < a}) \u2194 bounded (>) s :=\n@bounded_lt_inter_lt \u03b1\u1d52\u1d48 s _ _ a\n\ntheorem unbounded_gt_inter_gt [linear_order \u03b1] [no_min_order \u03b1] (a : \u03b1) :\n  unbounded (>) (s \u2229 {b | b < a}) \u2194 unbounded (>) s :=\n@unbounded_lt_inter_lt \u03b1\u1d52\u1d48 s _ _ a\n\nend set\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/bounded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7434141012082301}}
{"text": "/-\nCopyright (c) 2022 John Nicol. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: John Nicol\n\n! This file was ported from Lean 3 source module number_theory.wilson\n! leanprover-community/mathlib commit e985d48324225202b17a7f9eb50b29ba09b77b44\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.NumberTheory.LegendreSymbol.GaussEisensteinLemmas\n\n/-!\n# Wilson's theorem.\n\nThis file contains a proof of Wilson's theorem.\n\nThe heavy lifting is mostly done by the previous `wilsons_lemma`,\nbut here we also prove the other logical direction.\n\nThis could be generalized to similar results about finite abelian groups.\n\n## References\n\n* [Wilson's Theorem](https://en.wikipedia.org/wiki/Wilson%27s_theorem)\n\n## TODO\n\n* Move `wilsons_lemma` into this file, and give it a descriptive name.\n-/\n\n\nopen Nat\n\nnamespace Nat\n\nvariable {n : \u2115}\n\n/-- For `n \u2260 1`, `(n-1)!` is congruent to `-1` modulo `n` only if n is prime. -/\ntheorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n \u2260 1) : Prime n :=\n  by\n  rcases eq_or_ne n 0 with (rfl | h0)\n  \u00b7 norm_num at h\n  replace h1 : 1 < n := n.two_le_iff.mpr \u27e8h0, h1\u27e9\n  by_contra h2\n  obtain \u27e8m, hm1, hm2 : 1 < m, hm3\u27e9 := exists_dvd_of_not_prime2 h1 h2\n  have hm : m \u2223 (n - 1)! := Nat.dvd_factorial (pos_of_gt hm2) (le_pred_of_lt hm3)\n  refine' hm2.ne' (nat.dvd_one.mp ((Nat.dvd_add_right hm).mp (hm1.trans _)))\n  rw [\u2190 ZMod.nat_cast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]\n#align nat.prime_of_fac_equiv_neg_one Nat.prime_of_fac_equiv_neg_one\n\n/-- **Wilson's Theorem**: For `n \u2260 1`, `(n-1)!` is congruent to `-1` modulo `n` iff n is prime. -/\ntheorem prime_iff_fac_equiv_neg_one (h : n \u2260 1) : Prime n \u2194 ((n - 1)! : ZMod n) = -1 :=\n  by\n  refine' \u27e8fun h1 => _, fun h2 => prime_of_fac_equiv_neg_one h2 h\u27e9\n  haveI := Fact.mk h1\n  exact ZMod.wilsons_lemma n\n#align nat.prime_iff_fac_equiv_neg_one Nat.prime_iff_fac_equiv_neg_one\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/Wilson.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7433142523329476}}
{"text": "/- Here we prove Edmonds' matroid intersection theorem: given two matroids M\u2081 and M\u2082 on \u03b1, the size \nof the largest set that is independent in both matroids is equal to the minimum of M\u2081.r X + M\u2082.r X\u1d9c,\ntaken over all X \u2286 \u03b1. The proof is really by induction on the size of the ground set, but to make \nthings easier we instead do induction on the number of nonloops, applying the induction hypothesis \nto loopifications and projections of M\u2081 and M\u2082.  -/\n\nimport matroid.submatroid.projection \nimport prelim.minmax \nimport .basic \n\nopen_locale classical \nnoncomputable theory \nopen matroid set \n\nvariables {\u03b1 : Type*} [fintype \u03b1]\n\nsection intersection \n\n/-- the parameter \u03bd is nonnegative -/\nlemma \u03bd_nonneg (M\u2081 M\u2082 : matroid \u03b1) : \n  0 \u2264 \u03bd M\u2081 M\u2082 := \nby {apply lb_le_max, intro X, apply size_nonneg}\n\n/-- function that provides an upper bound on \u03bd M\u2081 M\u2082 -/\ndef matroid_inter_ub_fn (M\u2081 M\u2082 : matroid \u03b1) (X : set \u03b1): \u2124 := \n  M\u2081.r X + M\u2082.r X\u1d9c\n\n/-- the easy direction of matroid intersection, stated for a specific pair of sets. -/\ntheorem matroid_intersection_pair_le {M\u2081 M\u2082 : matroid \u03b1} {I : common_ind M\u2081 M\u2082} (A : set \u03b1) : \n  size (I : set \u03b1) \u2264 M\u2081.r A + M\u2082.r A\u1d9c := \nbegin\n  rcases I with \u27e8I, \u27e8h\u2081, h\u2082\u27e9\u27e9, \n  unfold_coes, dsimp only, \n  rw \u2190(compl_inter_size A I), \n  have h\u2081i := indep_of_subset_indep (inter_subset_right A I) h\u2081, \n  have h\u2082i := indep_of_subset_indep (inter_subset_right A\u1d9c I) h\u2082, \n  rw [\u2190indep_iff_r.mp h\u2081i, \u2190indep_iff_r.mp h\u2082i], \n  linarith [rank_mono_inter_left M\u2081 A I, rank_mono_inter_left M\u2082 A\u1d9c I], \nend\n\n/-- the easy direction of matroid intersection, stated as an upper bound on \u03bd -/\nlemma \u03bd_ub (M\u2081 M\u2082 : matroid \u03b1) : \n  \u03bd M\u2081 M\u2082 \u2264 min_val (matroid_inter_ub_fn M\u2081 M\u2082)  := \nbegin\n  rcases max_spec (\u03bb (X : common_ind M\u2081 M\u2082), size X.val) with \u27e8X, hX1, hX2\u27e9,\n  rcases min_spec (matroid_inter_ub_fn M\u2081 M\u2082) with \u27e8A, hA1, hA2\u27e9, \n  rw [\u03bd, \u2190hX1, \u2190hA1], \n  apply matroid_intersection_pair_le, \nend\n\n/-- Edmonds' matroid intersection theorem: the size of a largest common independent set \n    is equal to the minimum value of a natural upper bound on the size of any such set. \n    Implies many other minmax theorems in combinatorics.                             -/\ntheorem matroid_intersection (M\u2081 M\u2082 : matroid \u03b1) : \n  \u03bd M\u2081 M\u2082 = min_val (\u03bb X, M\u2081.r X + M\u2082.r X\u1d9c) := \nbegin\n  -- the hard direction suffices\n  refine le_antisymm (\u03bd_ub M\u2081 M\u2082) _, \n\n  --induction boilerplate \n  convert  nonneg_int_strong_induction_param \n    (\u03bb p : matroid \u03b1 \u00d7 matroid \u03b1, min_val (matroid_inter_ub_fn p.1 p.2) \u2264 \u03bd p.1 p.2)\n    (\u03bb p : matroid \u03b1 \u00d7 matroid \u03b1, size (nonloops p.1 \u2229 nonloops p.2))\n    (\u03bb p, size_nonneg _)\n    _ _ \u27e8M\u2081,M\u2082\u27e9,\n\n  -- base case, when everything is a loop. Here the LHS is obviously 0.\n  rintros \u27e8N\u2081,N\u2082\u27e9 hN, dsimp only at \u22a2 hN, \n\n  have h' : (matroid_inter_ub_fn N\u2081 N\u2082) (loops N\u2081) = 0 :=  by \n  { rw [size_zero_iff_empty, N\u2082.nonloops_eq_compl_loops, \u2190 subset_iff_disjoint_compl] at hN, \n    rw [matroid_inter_ub_fn, rank_loops, \u2190 nonloops_eq_compl_loops, zero_add, \n      rank_zero_of_subset_rank_zero hN N\u2082.rank_loops]},\n\n  linarith [\u03bd_nonneg N\u2081 N\u2082, min_is_lb (matroid_inter_ub_fn N\u2081 N\u2082) (loops N\u2081)],  \n  \n  -- we now assume that the result holds for any strictly loopier pair of matroids, \n  -- and that there is at least one common nonloop; call it e. \n  \n  rintros \u27e8N\u2081,N\u2082\u27e9 hsize IH, dsimp only at hsize IH \u22a2, \n  set k := \u03bd N\u2081 N\u2082 with hk, \n  --rw \u2190hsize at hn, \n  obtain \u27e8e, he_mem\u27e9  := exists_mem_of_size_pos hsize, \n  have  h_e_nl := he_mem, \n  rw [mem_inter_iff, \u2190 nonloop_iff_mem_nonloops] at h_e_nl, \n  \n  -- contract and delete (loopify/project) e from both elements of the pairs, to get \n  -- strictly loopier pairs to which we'll apply the IH, along with the associated maximizers \n  set N\u2081d := N\u2081 \u27cd {e} with hN\u2081d, \n  set N\u2082d := N\u2082 \u27cd {e} with hN\u2082d,  \n  set N\u2081c := N\u2081 \u27cb {e} with hN\u2081c, \n  set N\u2082c := N\u2082 \u27cb {e} with hN\u2082c, \n\n  obtain \u27e8\u27e8Id,hId_ind\u27e9, \u27e8hId_eq_max, hId_ub\u27e9\u27e9 := max_spec (\u03bb (X : common_ind N\u2081d N\u2082d), size X.val),\n  obtain \u27e8\u27e8Ic,hIc_ind\u27e9, \u27e8hIc_eq_max, hIc_ub\u27e9\u27e9 := max_spec (\u03bb (X : common_ind N\u2081c N\u2082c), size X.val),\n\n  -- e doesn't belong to Ic, because Ic is independent in M/e \n  have heIc : e \u2209 Ic := \u03bb heIc, by \n  { have := projected_set_rank_zero N\u2081 {e}, \n    rw [\u2190hN\u2081c, mem_indep_r heIc hIc_ind.1] at this, \n    exact one_ne_zero this},\n  \n  -- \u03bd does not get larger upon deletion \n  have h_nu_d : \u03bd N\u2081d N\u2082d \u2264 k :=  by \n  { rw [\u03bd, \u2190hId_eq_max, hk, \u03bd],\n    convert max_is_ub (\u03bb (X : common_ind N\u2081 N\u2082), size X.val) \u27e8Id, _\u27e9, \n    from \u27e8indep_of_loopify_indep hId_ind.1, indep_of_loopify_indep hId_ind.2\u27e9},\n  \n  -- \u03bd goes down upon contraction \n  have h_nu_c : \u03bd N\u2081c N\u2082c \u2264 k-1 := by \n  { rw [hk, \u03bd, \u03bd, \u2190hIc_eq_max], \n    have := max_is_ub (\u03bb (X : common_ind N\u2081 N\u2082), size X.val) \u27e8Ic \u222a {e}, _\u27e9, \n    dsimp only at this \u22a2,\n    linarith only [size_union_nonmem_singleton heIc, this], \n    split, all_goals {apply indep_union_project_set_of_project_indep}, \n    exact hIc_ind.1, exact (nonloop_iff_indep.mp h_e_nl.1), \n    exact hIc_ind.2, exact (nonloop_iff_indep.mp h_e_nl.2)},                             \n  \n  -- `(N\u2081 \u27cd e, N\u2082 \u27cd e)` is loopier than `(N\u2081, N\u2082)`.\n  have h_fewer_nonloops_d : size (N\u2081d.nonloops \u2229 N\u2082d.nonloops) < size (N\u2081.nonloops \u2229 N\u2082.nonloops),\n  { rw [hN\u2081d, hN\u2082d, loopify_nonloops_eq, loopify_nonloops_eq, diff_inter_diff_right, \n        size_remove_mem he_mem],\n    apply sub_one_lt, },\n\n  -- so is `(N\u2081 \u27cb e , N\u2082 \u27cb e)`.  \n  have h_fewer_nonloops_c : size (N\u2081c.nonloops \u2229 N\u2082c.nonloops) < size (N\u2081.nonloops \u2229 N\u2082.nonloops),\n  { rw [hN\u2081c, hN\u2082c, project_nonloops_eq, project_nonloops_eq],\n    refine size_strict_monotone ((ssubset_iff_of_subset _).mpr \u27e8e, he_mem, _\u27e9), \n    { intros x hx, simp_rw [mem_inter_iff, mem_diff_iff] at hx, exact \u27e8hx.1.1, hx.2.1\u27e9}, \n    refine nonmem_of_nonmem_supset (nonmem_diff_of_mem _ _) (inter_subset_left _ _), \n    apply mem_cl_single},\n\n  -- apply IH to deletion and then contraction, getting minimizers Ac and Ad\n  have hd := IH \u27e8N\u2081d, N\u2082d\u27e9 h_fewer_nonloops_d, \n  obtain \u27e8Ad, \u27e8hAd_eq_min, hAd_lb\u27e9\u27e9 := min_spec (matroid_inter_ub_fn N\u2081d N\u2082d), \n  rw [\u2190hAd_eq_min] at hd, \n\n  have hc := IH \u27e8N\u2081c, N\u2082c\u27e9 h_fewer_nonloops_c, \n  obtain \u27e8Ac, \u27e8hAc_eq_min, hAc_lb\u27e9\u27e9 := min_spec (matroid_inter_ub_fn N\u2081c N\u2082c), \n  rw [\u2190hAc_eq_min] at hc, \n\n  -- this gives upper bounds on certain rank expressions\n  have hAd_ub : N\u2081.r (Ad \\ {e}) + N\u2082.r (Ad\u1d9c \\ {e}) \u2264 k := le_trans hd h_nu_d,\n\n  have hAc_ub : N\u2081.r (Ac \u222a {e}) + N\u2082.r (Ac\u1d9c \u222a {e}) \u2264 k+1 := by \n  { suffices : (N\u2081.r (Ac \u222a {e}) - N\u2081.r {e}) + (N\u2082.r (Ac\u1d9c \u222a {e}) - N\u2082.r {e}) \u2264 k-1, \n      by linarith [rank_nonloop h_e_nl.1, rank_nonloop h_e_nl.2],\n    from le_trans hc h_nu_c},\n\n  -- use contradiction, and replace the IH with a bound applying to all sets \n  by_contra h_contr, push_neg at h_contr, \n  replace h_contr : \u2200 X, k + 1 \u2264 matroid_inter_ub_fn N\u2081 N\u2082 X := \n    \u03bb X, by linarith [min_is_lb (matroid_inter_ub_fn N\u2081 N\u2082) X],\n\n  -- apply the bound to sets for which we know a bound in the other direction; \n  have hi := h_contr (Ac \u2229 Ad \\ {e}), \n  have hu := h_contr (Ac \u222a Ad \u222a {e}), \n  unfold matroid_inter_ub_fn at hi hu, \n  rw [compl_union, compl_union, \u2190diff_eq] at hu, \n  rw [compl_diff, compl_inter] at hi, \n  \n  -- contradict submodularity. \n  have sm1 := N\u2081.rank_submod (Ac \u222a {e}) (Ad \\ {e}), \n  have sm2 := N\u2082.rank_submod (Ac\u1d9c \u222a {e}) (Ad\u1d9c \\ {e}),\n  rw [union_union_diff, union_inter_diff] at sm1 sm2, \n  linarith only [sm1, sm2, hi, hu, hAd_ub, hAc_ub], \nend\n\n/-- restatement of matroid intersection theorem as the existence of a matching maximizer/minimizer-/\ntheorem matroid_intersection_exists_pair_eq (M\u2081 M\u2082 : matroid \u03b1) : \n  \u2203 I A, is_common_ind M\u2081 M\u2082 I \u2227 size I =  M\u2081.r A + M\u2082.r A\u1d9c  := \nbegin\n  rcases max_spec (\u03bb (I : common_ind M\u2081 M\u2082), size I.val) with \u27e8\u27e8I,h_ind\u27e9,h_eq_max, hI_ub\u27e9, \n  rcases min_spec (\u03bb X, M\u2081.r X + M\u2082.r X\u1d9c) with \u27e8A, hA_eq_min, hA_lb\u27e9, \n  refine \u27e8I, A, \u27e8h_ind,_\u27e9\u27e9,  \n  dsimp only at *, \n  rw [h_eq_max, hA_eq_min], \n  apply matroid_intersection, \nend \n\nend intersection \n\n\n\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/intersection-union/matroid_inter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7433142459167368}}
{"text": "import .love10_denotational_semantics_demo\n\n\n/-! # LoVe Homework 10: Denotational Semantics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (7 points): Denotational Semantics of DOWHILE -/\n\nnamespace do_while\n\n/-! Consider the following DOWHILE language: -/\n\ninductive stmt : Type\n| skip     : stmt\n| assign   : string \u2192 (state \u2192 \u2115) \u2192 stmt\n| seq      : stmt \u2192 stmt \u2192 stmt\n| unless   : stmt \u2192 (state \u2192 Prop) \u2192 stmt\n| while    : (state \u2192 Prop) \u2192 stmt \u2192 stmt\n| do_while : stmt \u2192 (state \u2192 Prop) \u2192 stmt\n\ninfixr ` ;; ` : 90 := stmt.seq\n\n/-! The `skip`, `assign`, `seq`, and `while` constructs are as for the WHILE\nlanguage.\n\n`unless S b` executes `S` if `b` is false in the current state; otherwise, it\ndoes nothing. This statement is inspired by Perl's `unless` conditional.\n\n`do_while S b` first executes `S`. Then, if `b` is true in the resulting state,\nit re-enters the loop and executes `S` again, and continues executing `S` until\n`b` becomes `false`. The semantics is almost the same as `while b S`, except\nthat `p` is always executed at least once, even if the condition is not true\ninitially. This statement is inspired by C's and Java's `do { \u2026 } while (\u2026)`\nloop.\n\n1.1 (2 points). Give a denotational semantics of DOWHILE.\n\nHint: Your definition should make it easy to prove lemma `do_while_while` in\nquestion 1.2. -/\n\ndef denote : stmt \u2192 set (state \u00d7 state)\n| stmt.skip           := Id\n-- enter the missing cases here\n\nnotation `\u27e6` S `\u27e7`:= denote S\n\n/-! 1.2 (1 point). Prove the following correspondence between `do_while` and\n`while`. -/\n\nlemma do_while_while (S : stmt) (b : state \u2192 Prop) :\n  \u27e6stmt.do_while S b\u27e7 = \u27e6S\u27e7 \u25ef \u27e6stmt.while b S\u27e7 :=\nsorry\n\n/-! 1.3 (4 points). Prove the following lemmas.\n\nHint: For all of these, short proofs are possible. It may help, however, to\nknow what basic expressions such as `p \u21c3 (\u03bbx, false)` and `p \u21c3 (\u03bbx, true)` mean.\nMake sure to simplify the expressions involving `\u21c3` before trying to figure out\nwhat to do about `lfp`. -/\n\nlemma lfp_const {\u03b1 : Type} [complete_lattice \u03b1] (a : \u03b1) :\n  lfp (\u03bbX, a) = a :=\nsorry\n\nlemma while_false (S : stmt) :\n  \u27e6stmt.while (\u03bb_, false) S\u27e7 = Id :=\nsorry\n\nlemma comp_Id {\u03b1 : Type} (r : set (\u03b1 \u00d7 \u03b1)) :\n  r \u25ef Id = r :=\nsorry\n\nlemma do_while_false (S : stmt) :\n  \u27e6stmt.do_while S (\u03bb_, false)\u27e7 = \u27e6S\u27e7 :=\nsorry\n\nend do_while\n\n\n/-! ## Question 2 (2 points + 2 bonus points): Kleene's Theorem\n\nWe can compute the fixpoint by iteration by taking the union of all finite\niterations of `f`:\n\n    `lfp f = \u22c3i, (f ^^ i) \u2205`\n\nwhere\n\n    `f ^^ i = f \u2218 \u22ef \u2218 f`\n\niterates the function `f` `i` times. However, the above characterization of\n`lfp` only holds for continuous functions, a concept we will introduce below. -/\n\ndef iterate {\u03b1 : Type} (f : \u03b1 \u2192 \u03b1) : \u2115 \u2192 \u03b1 \u2192 \u03b1\n| 0       a := a\n| (n + 1) a := f (iterate n a)\n\nnotation f`^^`n := iterate f n\n\n/-! 2.1 (2 points). Fill in the missing proofs below.\n\nHint: Bear in mind that `\u2264` works on lattices in general, including sets. On\nsets, it can be unfolded to `\u2286` using `simp [(\u2264)]`. Moreover, when you see\n`h : A \u2286 B` in a goal, you can imagine that you have `?a \u2208 A \u2192 ?a \u2208 B` by\ndefinition, or unfold the definition using `simp [(\u2286), set.subset]`. -/\n\ndef Union {\u03b1 : Type} (s : \u2115 \u2192 set \u03b1) : set \u03b1 :=\n{a | \u2203n, a \u2208 s n}\n\nlemma Union_le {\u03b1 : Type} {s : \u2115 \u2192 set \u03b1} (A : set \u03b1) (h : \u2200i, s i \u2264 A) :\n  Union s \u2264 A :=\nsorry\n\n/-! A continuous function `f` is a function that commutes with the union of any\nmonotone sequence `s`: -/\n\ndef continuous {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) : Prop :=\n\u2200s : \u2115 \u2192 set \u03b1, monotone s \u2192 f (Union s) = Union (\u03bbi, f (s i))\n\n/-! We need to prove that each continuous function is monotone. To achieve this,\nwe will need the following sequence: -/\n\ndef bi_seq {\u03b1 : Type} (A B : set \u03b1) : \u2115 \u2192 set \u03b1\n| 0       := A\n| (n + 1) := B\n\n/-! For example, `bi_seq A B` is the sequence A, B, B, B, \u2026. -/\n\nlemma monotone_bi_seq {\u03b1 : Type} (A B : set \u03b1) (h : A \u2264 B) :\n  monotone (bi_seq A B)\n| 0       0       _ := le_refl _\n| 0       (n + 1) _ := h\n| (n + 1) (m + 1) _ := le_refl _\n\nlemma Union_bi_seq {\u03b1 : Type} (A B : set \u03b1) (ha : A \u2264 B) :\n  Union (bi_seq A B) = B :=\nbegin\n  apply le_antisymm,\n  { sorry },\n  { sorry }\nend\n\nlemma monotone_of_continuous {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1)\n    (hf : continuous f) :\n  monotone f :=\nsorry\n\n/-! 2.2 (1 bonus point). Provide the following proof, using a similar case\ndistinction as for `monotone_bi_seq` above. -/\n\nlemma monotone_iterate {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) (hf : monotone f) :\n  monotone (\u03bbi, (f ^^ i) \u2205) :=\nsorry\n\n/-! 2.3 (1 bonus point). Prove the main theorem. A proof sketch is given below.\n\nWe break the proof into two proofs of inclusion.\n\nCase 1. `lfp f \u2264 Union (\u03bbi, (f ^^ i) \u2205)`: The key is to use the lemma `lfp_le`\ntogether with continuity of `f`.\n\nCase 2. `Union (\u03bbi, (f ^^ i) \u2205) \u2264 lfp f`: The lemma `Union_le` gives us a\nnatural number `i`, on which you can perform induction. We also need the lemma\n`lfp_eq` to unfold one iteration of `lfp f`. -/\n\nlemma lfp_Kleene {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) (hf : continuous f) :\n  lfp f = Union (\u03bbi, (f ^^ i) \u2205) :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2022", "sha": "5aee593fbef9b63d4338288b4789d85851d258aa", "save_path": "github-repos/lean/blanchette-logical_verification_2022", "path": "github-repos/lean/blanchette-logical_verification_2022/logical_verification_2022-5aee593fbef9b63d4338288b4789d85851d258aa/lean/love10_denotational_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7433142456288088}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport solutions.sheet01\n\n/-! Two-by-two matrices\n\nThis file defines two-by-two matrices and shows that they form a vector space.\n-/\n\n/- Here is one way to define a 2x2 matrix, via specifying its two rows. In hard mode you could try to take a \n  different approach (either as its two columns or as its four entries and see what gets easier and what gets \n  harder). -/\nstructure two_matrix : Type :=\n(fst_row : \u211d\u00b2) \n(snd_row : \u211d\u00b2)\n\nnamespace two_matrix\n\nnotation `Mat\u2082` := two_matrix\n\n/-- Two matrices are equal if and only if their first and second rows coincide. -/\n@[ext] theorem ext {A B : Mat\u2082}\n  (h_first_row : A.fst_row = B.fst_row ) \n  (h_second_row : A.snd_row = B.snd_row ) : \n  A = B :=\nbegin\n  cases A,\n  cases B,\n  simp * at *,\nend\n\n/- Again we want to be able to write `A + B` if `A` and `B` are matrices without too complicated notation. -/\ninstance : has_add Mat\u2082 := \u27e8\u03bb A B, \u27e8A.fst_row + B.fst_row, A.snd_row + B.snd_row\u27e9\u27e9\n\n@[simp] lemma add_fst_row (A B : Mat\u2082) : (A + B).fst_row = A.fst_row + B.fst_row := rfl\n@[simp] lemma add_snd_row (A B : Mat\u2082) : (A + B).snd_row = A.snd_row + B.snd_row := rfl\n\nlemma add_assoc (A B C : Mat\u2082) : A + B + C = A + (B + C) :=\nbegin\n  ext;\n  simp;\n  ring,\nend\n\nlemma add_comm (A B : Mat\u2082) : A + B = B + A :=\nbegin\n  ext;\n  simp;\n  ring,\nend\n\ndef zero_matrix : Mat\u2082 := \u27e80,0\u27e9\n\n/- We even want to be able to write `0` for the zero matrix.-/\ninstance : has_zero Mat\u2082 := \u27e8zero_matrix\u27e9 \n\n/- The following lemmas have each two zeros in them, see which is which. -/\n@[simp] lemma zero_fst_row : (0 : Mat\u2082).fst_row = 0 := rfl\n@[simp] lemma zero_snd_row : (0 : Mat\u2082).snd_row = 0 := rfl\n\n@[simp] lemma add_zero (A : Mat\u2082) : A + 0 = A :=\nbegin\n  ext;\n  simp,\nend\n\n@[simp] lemma zero_add (A : Mat\u2082) : 0 + A = A :=\nbegin\n  ext;\n  simp,\nend\n\n/- We want to define the negation of a matrix. -/\ninstance : has_neg Mat\u2082 := \u27e8\u03bb A, \u27e8-A.fst_row, -A.snd_row\u27e9\u27e9\n\n@[simp] lemma neg_fst_row (A : Mat\u2082) : (-A).fst_row = -A.fst_row := rfl\n@[simp] lemma neg_snd_row (A : Mat\u2082) : (-A).snd_row = -A.snd_row := rfl\n\n\n@[simp] lemma add_neg_self (A : Mat\u2082) : A + -A = 0 :=\nbegin\n  ext;\n  simp,\nend \n\n@[simp] lemma neg_add_self (A : Mat\u2082) : -A + A = 0 :=\nbegin\n  ext;\n  simp,\nend\n\n/- Finally we set up subtraction and scalar multiplication of matrices. -/\ninstance : has_sub Mat\u2082 := \u27e8\u03bb A B, A + (-B)\u27e9\n\ninstance : has_scalar \u211d Mat\u2082 := \u27e8\u03bb a A, \u27e8a \u2022 A.fst_row, a \u2022 A.snd_row\u27e9\u27e9 \n\n@[simp] lemma smul_fst_row (a : \u211d) (A : Mat\u2082) : (a \u2022 A).fst_row = a \u2022 A.fst_row := rfl\n@[simp] lemma smul_snd_row (a : \u211d) (A : Mat\u2082) : (a \u2022 A).snd_row = a \u2022 A.snd_row := rfl\n\nlemma smul_assoc (a b : \u211d) (A : Mat\u2082) : (a * b) \u2022 A = a \u2022 (b \u2022 A) :=\nbegin\n  ext;\n  simp;\n  ring,\nend \n\n@[simp] lemma one_smul (A : Mat\u2082) : (1 : \u211d) \u2022 A = A :=\nbegin\n  ext;\n  simp,\nend   \n\n@[simp] lemma smul_add (a : \u211d) (A B : Mat\u2082) : a \u2022 (A + B) = a \u2022 A + a \u2022 B :=\nbegin\n  ext;\n  simp,\nend \n\n@[simp] lemma add_smul (a b : \u211d) (A : Mat\u2082) : (a + b) \u2022 A = a \u2022 A + b \u2022 A :=\nbegin\n  ext;\n  simp,\nend\n\nend two_matrix", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/solutions/sheet02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7433142452860771}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\n\nimport data.W\n\n/-!\n# W types\n\nThe file `data/W.lean` shows that if `\u03b1` is an an encodable fintype and for every `a : \u03b1`,\n`\u03b2 a` is encodable, then `W \u03b2` is encodable.\n\nAs an example of how this can be used, we show that the type of propositional formulas with\nvariables labeled from an encodable type is encodable.\n\nThe strategy is to define a type of labels corresponding to the constructors.\nFrom the definition (using `sum`, `unit`, and an encodable type), Lean can infer\nthat it is encodable. We then define a map from propositional formulas to the\ncorresponding `Wfin` type, and show that map has a left inverse.\n\nWe mark the auxiliary constructions `private`, since their only purpose is to\nshow encodability.\n-/\n\n/-- Propositional formulas with labels from `\u03b1`. -/\ninductive prop_form (\u03b1 : Type*)\n| var : \u03b1 \u2192 prop_form\n| not : prop_form \u2192 prop_form\n| and : prop_form \u2192 prop_form \u2192 prop_form\n| or  : prop_form \u2192 prop_form \u2192 prop_form\n\n/-!\nThe next three functions make it easier to construct functions from a small\n`fin`.\n-/\n\nsection\nvariable {\u03b1 : Type*}\n\n/-- the trivial function out of `fin 0`. -/\ndef mk_fn0 : fin 0 \u2192 \u03b1\n| \u27e8_, h\u27e9 := absurd h dec_trivial\n\n/-- defines a function out of `fin 1` -/\ndef mk_fn1 (t : \u03b1) : fin 1 \u2192 \u03b1\n| \u27e80, _\u27e9   := t\n| \u27e8n+1, h\u27e9 := absurd h dec_trivial\n\n/-- defines a function out of `fin 2` -/\ndef mk_fn2 (s t : \u03b1) : fin 2 \u2192 \u03b1\n| \u27e80, _\u27e9   := s\n| \u27e81, _\u27e9   := t\n| \u27e8n+2, h\u27e9 := absurd h dec_trivial\n\nattribute [simp] mk_fn0 mk_fn1 mk_fn2\nend\n\nnamespace prop_form\n\nprivate def constructors (\u03b1 : Type*) := \u03b1 \u2295 unit \u2295 unit \u2295 unit\n\nlocal notation `cvar` a := sum.inl a\nlocal notation `cnot`   := sum.inr (sum.inl unit.star)\nlocal notation `cand`   := sum.inr (sum.inr (sum.inr unit.star))\nlocal notation `cor`    := sum.inr (sum.inr (sum.inl unit.star))\n\n@[simp]\nprivate def arity (\u03b1 : Type*) : constructors \u03b1 \u2192 nat\n| (cvar a) := 0\n| cnot     := 1\n| cand     := 2\n| cor      := 2\n\nvariable {\u03b1 : Type*}\n\nprivate def f : prop_form \u03b1 \u2192 W_type (\u03bb i, fin (arity \u03b1 i))\n| (var a)   := \u27e8cvar a, mk_fn0\u27e9\n| (not p)   := \u27e8cnot, mk_fn1 (f p)\u27e9\n| (and p q) := \u27e8cand, mk_fn2 (f p) (f q)\u27e9\n| (or  p q) := \u27e8cor, mk_fn2 (f p) (f q)\u27e9\n\nprivate def finv : W_type (\u03bb i, fin (arity \u03b1 i)) \u2192 prop_form \u03b1\n| \u27e8cvar a, fn\u27e9 := var a\n| \u27e8cnot, fn\u27e9   := not (finv (fn \u27e80, dec_trivial\u27e9))\n| \u27e8cand, fn\u27e9   := and (finv (fn \u27e80, dec_trivial\u27e9)) (finv (fn \u27e81, dec_trivial\u27e9))\n| \u27e8cor, fn\u27e9    := or  (finv (fn \u27e80, dec_trivial\u27e9)) (finv (fn \u27e81, dec_trivial\u27e9))\n\ninstance [encodable \u03b1] : encodable (prop_form \u03b1) :=\nbegin\n  haveI : encodable (constructors \u03b1) :=\n    by { unfold constructors, apply_instance },\n  exact encodable.of_left_inverse f finv\n    (by { intro p, induction p; simp [f, finv, *] })\nend\n\nend prop_form\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/examples/prop_encodable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7433142382666085}}
{"text": "-- import the reals...\nimport data.real.basic\n\n-- ...and now we can build the complex numbers as an ordered pair of reals.\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\n/-\nWhat we have so far:\n\n*) a new type called `complex` or \u2102 for short;\n*) Two functions `complex.re` and `complex.im` from \u2102 to \u211d,\n   plus the cool abbreviation z.re for complex.re z and z.im similarly;\n*) A way of making a complex number from two real numbers x and y;\n   the official name is of this function is `complex.mk x y`\n   but in practice we will just use the abbreviation \u27e8x, y\u27e9\n   as you're about to see.\n-/\n\n-- how to make 3 + 4i\nexample : \u2102 := \u27e83, 4\u27e9\n\n-- In type theory, \"eta conversion\" is about simplifying a term\n-- which involves a constructor applied to an eliminator. \n-- In this context, our eliminators are re and im, and our constructor\n-- is \u27e8x, y\u27e9. So `eta z` should be the theorem that \u27e8re z, im z\u27e9 = z.\ntheorem eta (z : \u2102) : (\u27e8z.re, z.im\u27e9 : \u2102) = z := by cases z with x y; refl\n\n-- Now we should prove the extensionality lemma for complex numbers;\n-- two complex numbers are equal if and only if their real and imaginary\n-- parts are equal. One way is trivial; here's the other way.\n@[extensionality] theorem ext (z w : \u2102) (Hre : re z = re w) (Him : im z = im w) :\nz = w := \nbegin\n  cases w with x y,\n  rw \u2190eta z,\n  -- this is the goal now:\n  show (\u27e8re z, im z\u27e9 : \u2102) = \u27e8x, y\u27e9,\n  rw Hre, -- z.re = x\n  rw Him, -- z.im = y\n  -- goal is now true by definition, so gets automatically closed.\nend\n\n-- Now we start on the data we need to make the complexes a ring,\n-- namely 0, 1, addition and multiplication.\n\n-- Here the 0's are (0 : \u211d)\ndefinition zero : \u2102 := \u27e80, 0\u27e9\n\n-- zero notation\ninstance : has_zero \u2102 := \u27e8complex.zero\u27e9\n\n-- For our simp lemmas we will use the numeral 0 rather than complex.zero .\n-- It's important that we stick to one convention!\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n\n-- Now  `simp` will expand out 0.re and 0.im as the real number 0.\n\n-- Same for 1:\ndefinition one : \u2102 := \u27e81, 0\u27e9\n\ninstance : has_one \u2102 := \u27e8complex.one\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n\n-- Next addition\ndefinition add (z w : \u2102) : \u2102 := \u27e8z.re + w.re, z.im + w.im\u27e9\n\n-- add the notation\ninstance : has_add \u2102 := \u27e8complex.add\u27e9\n\n-- These lemmas is true by definition, but we need to tell\n-- them to Lean explicitly so we can train `simp` to expand\n-- out whenever it sees the left hand side.\n@[simp] lemma add_re (a b : \u2102) : (a + b).re = a.re + b.re := rfl\n\n@[simp] lemma add_im (a b : \u2102) : (a + b).im = a.im + b.im := rfl\n\n-- Next negation\ndefinition neg (z : \u2102) : \u2102 := \u27e8-z.re, -z.im\u27e9\n\ninstance : has_neg \u2102 := \u27e8complex.neg\u27e9\n\n@[simp] lemma neg_re (a : \u2102) : (-a).re = -a.re := rfl\n@[simp] lemma neg_im (a : \u2102) : (-a).im = -a.im := rfl\n\ndefinition mul (z w : \u2102) : \u2102 :=\n\u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9 \n\n-- add the notation\ninstance : has_mul \u2102 := \u27e8complex.mul\u27e9\n\n@[simp] lemma mul_re (a b : \u2102) : \n(a * b).re = a.re * b.re - a.im * b.im := rfl\n\n@[simp] lemma mul_im (a b : \u2102) : \n(a * b).im = a.re * b.im + a.im * b.re := rfl\n\n -- Sanity check! \nexample : (\u27e81, 2\u27e9 : \u2102) * (\u27e81, 2\u27e9 : \u2102) = (\u27e8-3, 4\u27e9 : \u2102) :=\nbegin\n  apply complex.ext, -- \"suffices to prove real and imag parts are equal\"\n    -- long-winded method for real part:\n    rw mul_re, norm_num,\n    -- automation for imag part\n    simp, norm_num,\n    -- actually just norm_num seems to work.\nend  \n\n-- For a general theorem, simp is very useful\nexample (a b c : \u2102) :\n(a + b) * c = a * c + b * c := \nbegin\n  apply ext,\n  -- again let's do the real part by hand\n  { rw [add_re,mul_re,add_re,add_im, mul_re, mul_re],\n    ring },\n  -- and now let's note that automation also works\n  { simp, ring },\nend\n\n-- Now let's do it in term mode:\nexample (a b c : \u2102) :\na * (b + c) = a * b + a * c := by apply ext; simp; ring\n\n-- and now let's prove all of the axioms of a commutative ring using\n-- the same technique.\ninstance : comm_ring \u2102 :=\nby refine { zero := 0, add := (+), neg := has_neg.neg, one := 1, mul := (*), ..};\n{ intros, apply ext; simp; ring }\n\ndef conj (z : \u2102) : \u2102 := \u27e8z.re, -z.im\u27e9\n\nnoncomputable def inv (z : \u2102) : \u2102 :=\n  \u27e8z.re*(z.re*z.re+z.im*z.im)\u207b\u00b9, -z.im*(z.re*z.re+z.im*z.im)\u207b\u00b9\u27e9\n\nnoncomputable instance : has_inv \u2102 := \u27e8complex.inv\u27e9\n\nexample : zero_ne_one_class \u211d := by apply_instance\n\nexample : (0 : \u211d) \u2260 (1 : \u211d) := zero_ne_one_class.zero_ne_one \u211d\n\n--set_option pp.numerals false\ninstance : zero_ne_one_class \u2102 := { \n  zero := 0,\n  one := 1,\n  zero_ne_one := begin\n    intro h,\n    apply zero_ne_one_class.zero_ne_one \u211d,\n    show (0 : \u2102).re = (1 : \u2102).re,\n    rw h,\n  end }\n\nlemma norm_sq_ne_zero_of_ne_zero {x y : \u211d} (h : (\u27e8x, y\u27e9 : \u2102) \u2260 0) : x * x + y * y \u2260 0 :=\nbegin\n  intro h2,\n  apply h,\n  ext,\n    dsimp,\n    exact eq_zero_of_mul_self_add_mul_self_eq_zero h2,\n  rw add_comm at h2,\n  exact eq_zero_of_mul_self_add_mul_self_eq_zero h2,\nend\n\ntheorem mul_inv_cancel {z : \u2102} (hz : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nbegin\n  cases z with x y,\n  unfold has_inv.inv inv,\n  dsimp,\n  ext;dsimp,\n  { rw \u2190mul_assoc,\n    rw neg_mul_eq_neg_mul,\n    rw \u2190mul_assoc,\n    rw neg_mul_neg,\n    rw \u2190add_mul,\n    apply div_self,\n    apply norm_sq_ne_zero_of_ne_zero,\n    assumption,\n  },\n  { ring,\n  }\nend\n\ntheorem inv_mul_cancel {z : \u2102} (hz : z \u2260 0) : z\u207b\u00b9 * z = 1 := (mul_comm z z\u207b\u00b9) \u25b8 mul_inv_cancel hz\n\n/-\n(has_decidable_eq : decidable_eq \u03b1)\n(inv_zero : inv zero = zero)\n(mul_inv_cancel : \u2200 {a : \u03b1}, a \u2260 0 \u2192 a * a\u207b\u00b9 = 1)\n(inv_mul_cancel : \u2200 {a : \u03b1}, a \u2260 0 \u2192 a\u207b\u00b9 * a = 1)\n-/\nnoncomputable instance : field \u2102 :=\nbegin\n  refine { \n    inv := has_inv.inv,\n    zero_ne_one := zero_ne_one_class.zero_ne_one _,\n    mul_inv_cancel := \u03bb _, mul_inv_cancel,\n    inv_mul_cancel := \u03bb _, inv_mul_cancel,\n    ..complex.comm_ring,\n    ..},\nend\n\nnoncomputable instance : discrete_field \u2102 :=\nbegin\n  refine {..complex.field, ..},\n    intros x y,\n    apply classical.prop_decidable,\n  show (0 : \u2102) \u207b\u00b9 = 0,\n  ext,\n    refine zero_mul _,\n  dsimp,\n  unfold has_inv.inv inv,\n  dsimp,\n  rw neg_zero,\n  rw zero_mul,      \nend\n\nend complex\n\n\n\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/blog/xena_complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121366457407, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.743314234112513}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Chris Hughes, Floris van Doorn, Ya\u00ebl Dillies\n-/\nimport data.nat.basic\nimport data.nat.pow\n\n/-!\n# Factorial and variants\n\nThis file defines the factorial, along with the ascending and descending variants.\n\n## Main declarations\n\n* `factorial`: The factorial.\n* `asc_factorial`: The ascending factorial. Note that it runs from `n + 1` to `n + k` and *not*\n  from`n`\n  to `n + k - 1`. We might want to change that in the future.\n* `desc_factorial`: The descending factorial. It runs from `n - k` to `n`.\n-/\n\nnamespace nat\n\n/-- `nat.factorial n` is the factorial of `n`. -/\n@[simp] def factorial : \u2115 \u2192 \u2115\n| 0        := 1\n| (succ n) := succ n * factorial n\n\nlocalized \"notation n `!`:10000 := nat.factorial n\" in nat\n\nsection factorial\n\nvariables {m n : \u2115}\n\n@[simp] theorem factorial_zero : 0! = 1 := rfl\n\n@[simp] theorem factorial_succ (n : \u2115) : n.succ! = (n + 1) * n! := rfl\n\n@[simp] theorem factorial_one : 1! = 1 := rfl\n\n@[simp] theorem factorial_two : 2! = 2 := rfl\n\ntheorem mul_factorial_pred (hn : 0 < n) : n * (n - 1)! = n! :=\ntsub_add_cancel_of_le (nat.succ_le_of_lt hn) \u25b8 rfl\n\ntheorem factorial_pos : \u2200 n, 0 < n!\n| 0        := zero_lt_one\n| (succ n) := mul_pos (succ_pos _) (factorial_pos n)\n\ntheorem factorial_ne_zero (n : \u2115) : n! \u2260 0 := ne_of_gt (factorial_pos _)\n\ntheorem factorial_dvd_factorial {m n} (h : m \u2264 n) : m! \u2223 n! :=\nbegin\n  induction n with n IH; simp,\n  { have := nat.eq_zero_of_le_zero h, subst m, simp },\n  obtain he | hl := h.eq_or_lt,\n  { subst m, simp },\n  exact (IH (le_of_lt_succ hl)).mul_left _,\nend\n\ntheorem dvd_factorial : \u2200 {m n}, 0 < m \u2192 m \u2264 n \u2192 m \u2223 n!\n| (succ m) n _ h := dvd_of_mul_right_dvd (factorial_dvd_factorial h)\n\n@[mono] theorem factorial_le {m n} (h : m \u2264 n) : m! \u2264 n! :=\nle_of_dvd (factorial_pos _) (factorial_dvd_factorial h)\n\nlemma factorial_mul_pow_le_factorial : \u2200 {m n : \u2115}, m! * m.succ ^ n \u2264 (m + n)!\n| m 0     := by simp\n| m (n+1) :=\nby  rw [\u2190 add_assoc, nat.factorial_succ, mul_comm (nat.succ _), pow_succ', \u2190 mul_assoc];\n  exact mul_le_mul factorial_mul_pow_le_factorial\n    (nat.succ_le_succ (nat.le_add_right _ _)) (nat.zero_le _) (nat.zero_le _)\n\nlemma monotone_factorial : monotone factorial := \u03bb n m, factorial_le\n\n\n\nlemma one_lt_factorial : 1 < n! \u2194 1 < n :=\nby { convert factorial_lt _, refl, exact one_pos }\n\nlemma factorial_eq_one : n! = 1 \u2194 n \u2264 1 :=\nbegin\n  split; intro h,\n  { rw [\u2190 not_lt, \u2190 one_lt_factorial, h],\n    apply lt_irrefl },\n  cases h with h h, refl, cases h, refl,\nend\n\nlemma factorial_inj (hn : 1 < n!) : n! = m! \u2194 n = m :=\nbegin\n  split; intro h,\n  { obtain hnm | hnm | hnm := lt_trichotomy n m,\n    { exfalso, rw [\u2190 factorial_lt, h] at hnm, exact lt_irrefl _ hnm,\n      rw [one_lt_factorial] at hn, exact lt_trans one_pos hn },\n    { exact hnm },\n    exfalso,\n    rw [h, one_lt_factorial] at hn,\n    rw [\u2190factorial_lt (lt_trans one_pos hn), h] at hnm, exact lt_irrefl _ hnm, },\n  { rw h },\nend\n\nlemma self_le_factorial : \u2200 n : \u2115, n \u2264 n!\n| 0       := zero_le_one\n| (k + 1) := le_mul_of_one_le_right k.zero_lt_succ.le (nat.one_le_of_lt $ nat.factorial_pos _)\n\nlemma lt_factorial_self {n : \u2115} (hi : 3 \u2264 n) : n < n! :=\nbegin\n  rw [\u2190 succ_pred_eq_of_pos ((zero_lt_two.trans (lt.base 2)).trans_le hi), factorial_succ],\n  exact lt_mul_of_one_lt_right ((pred n).succ_pos) ((one_lt_two.trans_le\n    (le_pred_of_lt (succ_le_iff.mp hi))).trans_le (self_le_factorial _)),\nend\n\nlemma add_factorial_succ_lt_factorial_add_succ {i : \u2115} (n : \u2115) (hi : 2 \u2264 i) :\n  i + (n + 1)! < (i + n + 1)! :=\nbegin\n  rw [factorial_succ (i + _), add_mul, one_mul],\n  have : i \u2264 i + n := le.intro rfl,\n  exact add_lt_add_of_lt_of_le (this.trans_lt ((lt_mul_iff_one_lt_right (zero_lt_two.trans_le\n    (hi.trans this))).mpr (lt_iff_le_and_ne.mpr \u27e8(i + n).factorial_pos, \u03bb g,\n    nat.not_succ_le_self 1 ((hi.trans this).trans (factorial_eq_one.mp g.symm))\u27e9))) (factorial_le\n    ((le_of_eq (add_comm n 1)).trans ((add_le_add_iff_right n).mpr (one_le_two.trans hi)))),\nend\n\nlemma add_factorial_lt_factorial_add {i n : \u2115} (hi : 2 \u2264 i) (hn : 1 \u2264 n) :\n  i + n! < (i + n)! :=\nbegin\n  cases hn,\n  { rw factorial_one,\n    exact lt_factorial_self (succ_le_succ hi) },\n  exact add_factorial_succ_lt_factorial_add_succ _ hi,\nend\n\nlemma add_factorial_succ_le_factorial_add_succ (i : \u2115) (n : \u2115) :\n  i + (n + 1)! \u2264 (i + (n + 1))! :=\nbegin\n  obtain i2 | (_ | \u27e8_, i0\u27e9) := le_or_lt 2 i,\n  { exact (n.add_factorial_succ_lt_factorial_add_succ i2).le },\n  { change 1 + (n + 1)! \u2264 (1 + n + 1) * (1 + n)!,\n    rw [add_mul, one_mul, add_comm 1 n],\n    exact (add_le_add_iff_right _).mpr (one_le_mul (nat.le_add_left 1 n) (n + 1).factorial_pos) },\n  rw [nat.le_zero_iff.mp (nat.succ_le_succ_iff.mp i0), zero_add, zero_add]\nend\n\nlemma add_factorial_le_factorial_add (i : \u2115) {n : \u2115} (n1 : 1 \u2264 n) :\n  i + n! \u2264 (i + n)! :=\nbegin\n  cases n1 with h,\n  { exact self_le_factorial _ },\n  exact add_factorial_succ_le_factorial_add_succ i h,\nend\n\nlemma factorial_mul_pow_sub_le_factorial {n m : \u2115} (hnm : n \u2264 m) : n! * n ^ (m - n) \u2264 m! :=\nbegin\n  suffices : n! * (n + 1) ^ (m - n) \u2264 m!,\n  { apply trans _ this,\n    rw mul_le_mul_left,\n    apply pow_le_pow_of_le_left (zero_le n) (le_succ n),\n    exact factorial_pos n,},\n  convert nat.factorial_mul_pow_le_factorial,\n  exact (add_tsub_cancel_of_le hnm).symm,\nend\n\n\nend factorial\n\n/-! ### Ascending and descending factorials -/\n\nsection asc_factorial\n\n/-- `n.asc_factorial k = (n + k)! / n!` (as seen in `nat.asc_factorial_eq_div`), but implemented\nrecursively to allow for \"quick\" computation when using `norm_num`. This is closely related to\n`pochhammer`, but much less general. -/\ndef asc_factorial (n : \u2115) : \u2115 \u2192 \u2115\n| 0 := 1\n| (k + 1) := (n + k + 1) * asc_factorial k\n\n@[simp] lemma asc_factorial_zero (n : \u2115) : n.asc_factorial 0 = 1 := rfl\n\n@[simp] lemma zero_asc_factorial (k : \u2115) : (0 : \u2115).asc_factorial k = k! :=\nbegin\n  induction k with t ht, refl,\n  unfold asc_factorial, rw [ht, zero_add, nat.factorial_succ],\nend\n\nlemma asc_factorial_succ {n k : \u2115} : n.asc_factorial k.succ = (n + k + 1) * n.asc_factorial k := rfl\n\nlemma succ_asc_factorial (n : \u2115) :\n  \u2200 k, (n + 1) * n.succ.asc_factorial k = (n + k + 1) * n.asc_factorial k\n| 0 := by rw [add_zero, asc_factorial_zero, asc_factorial_zero]\n| (k + 1) := by rw [asc_factorial, mul_left_comm, succ_asc_factorial, asc_factorial, succ_add,\n  \u2190add_assoc]\n\n/-- `n.asc_factorial k = (n + k)! / n!` but without \u2115-division. See `nat.asc_factorial_eq_div` for\nthe version with \u2115-division. -/\ntheorem factorial_mul_asc_factorial (n : \u2115) : \u2200 k, n! * n.asc_factorial k = (n + k)!\n| 0 := by rw [asc_factorial, add_zero, mul_one]\n| (k + 1) := by rw [asc_factorial_succ, mul_left_comm, factorial_mul_asc_factorial, \u2190 add_assoc,\n  factorial]\n\n/-- Avoid in favor of `nat.factorial_mul_asc_factorial` if you can. \u2115-division isn't worth it. -/\nlemma asc_factorial_eq_div (n k : \u2115) : n.asc_factorial k = (n + k)! / n! :=\nbegin\n  apply mul_left_cancel\u2080 (factorial_ne_zero n),\n  rw factorial_mul_asc_factorial,\n  exact (nat.mul_div_cancel' $ factorial_dvd_factorial $ le.intro rfl).symm\nend\n\nlemma asc_factorial_of_sub {n k : \u2115} (h : k < n) :\n  (n - k) * (n - k).asc_factorial k = (n - (k + 1)).asc_factorial (k + 1) :=\nbegin\n  set t := n - k.succ with ht,\n  suffices h' : n - k = t.succ, by rw [\u2190ht, h', succ_asc_factorial, asc_factorial_succ],\n  rw [ht, succ_eq_add_one, \u2190tsub_tsub_assoc (succ_le_of_lt h) (succ_pos _), succ_sub_one],\nend\n\nlemma pow_succ_le_asc_factorial (n : \u2115) : \u2200 (k : \u2115), (n + 1)^k \u2264 n.asc_factorial k\n| 0 := by rw [asc_factorial_zero, pow_zero]\n| (k + 1) := begin\n  rw pow_succ,\n  exact nat.mul_le_mul (nat.add_le_add_right le_self_add _) (pow_succ_le_asc_factorial k),\nend\n\nlemma pow_lt_asc_factorial' (n k : \u2115) : (n + 1)^(k + 2) < n.asc_factorial (k + 2) :=\nbegin\n  rw pow_succ,\n  exact nat.mul_lt_mul (nat.add_lt_add_right (nat.lt_add_of_pos_right succ_pos') 1)\n    (pow_succ_le_asc_factorial n _) (pow_pos succ_pos' _),\nend\n\nlemma pow_lt_asc_factorial (n : \u2115) : \u2200 {k : \u2115}, 2 \u2264 k \u2192 (n + 1)^k < n.asc_factorial k\n| 0 := by rintro \u27e8\u27e9\n| 1 := by rintro (_ | \u27e8_, \u27e8\u27e9\u27e9)\n| (k + 2) := \u03bb _, pow_lt_asc_factorial' n k\n\nlemma asc_factorial_le_pow_add (n : \u2115) : \u2200 (k : \u2115), n.asc_factorial k \u2264 (n + k)^k\n| 0 := by rw [asc_factorial_zero, pow_zero]\n| (k + 1) := begin\n  rw [asc_factorial_succ, pow_succ],\n  exact nat.mul_le_mul_of_nonneg_left ((asc_factorial_le_pow_add k).trans (nat.pow_le_pow_of_le_left\n  (le_succ _) _)),\nend\n\nlemma asc_factorial_lt_pow_add (n : \u2115) : \u2200 {k : \u2115}, 2 \u2264 k \u2192 n.asc_factorial k < (n + k)^k\n| 0 := by rintro \u27e8\u27e9\n| 1 := by rintro (_ | \u27e8_, \u27e8\u27e9\u27e9)\n| (k + 2) := \u03bb _, begin\n  rw [asc_factorial_succ, pow_succ],\n  refine nat.mul_lt_mul' (le_refl _) ((asc_factorial_le_pow_add n _).trans_lt\n    (pow_lt_pow_of_lt_left (lt_add_one _) (succ_pos _))) (succ_pos _),\nend\n\nlemma asc_factorial_pos (n k : \u2115) : 0 < n.asc_factorial k :=\n(pow_pos (succ_pos n) k).trans_le (pow_succ_le_asc_factorial n k)\n\nend asc_factorial\n\nsection desc_factorial\n\n/-- `n.desc_factorial k = n! / (n - k)!` (as seen in `nat.desc_factorial_eq_div`), but\nimplemented recursively to allow for \"quick\" computation when using `norm_num`. This is closely\nrelated to `pochhammer`, but much less general. -/\ndef desc_factorial (n : \u2115) : \u2115 \u2192 \u2115\n| 0 := 1\n| (k + 1) := (n - k) * desc_factorial k\n\n@[simp] lemma desc_factorial_zero (n : \u2115) : n.desc_factorial 0 = 1 := rfl\n\n@[simp] lemma desc_factorial_succ (n k : \u2115) :\n  n.desc_factorial k.succ = (n - k) * n.desc_factorial k := rfl\n\nlemma zero_desc_factorial_succ (k : \u2115) :\n  (0 : \u2115).desc_factorial k.succ = 0 :=\nby rw [desc_factorial_succ, zero_tsub, zero_mul]\n\n@[simp] lemma desc_factorial_one (n : \u2115) :\n  n.desc_factorial 1 = n :=\nby rw [desc_factorial_succ, desc_factorial_zero, mul_one, tsub_zero]\n\n@[simp] lemma succ_desc_factorial_succ (n : \u2115) :\n  \u2200 k : \u2115, (n + 1).desc_factorial (k + 1) = (n + 1) * n.desc_factorial k\n| 0        := by rw [desc_factorial_zero, desc_factorial_one, mul_one]\n| (succ k) := by rw [desc_factorial_succ, succ_desc_factorial_succ, desc_factorial_succ,\n  succ_sub_succ, mul_left_comm]\n\nlemma succ_desc_factorial (n : \u2115) :\n  \u2200 k, (n + 1 - k) * (n + 1).desc_factorial k = (n + 1) * n.desc_factorial k\n| 0 := by rw [tsub_zero, desc_factorial_zero, desc_factorial_zero]\n| (k + 1) := by rw [desc_factorial, succ_desc_factorial, desc_factorial_succ, succ_sub_succ,\n  mul_left_comm]\n\nlemma desc_factorial_self : \u2200 n : \u2115, n.desc_factorial n = n!\n| 0        := by rw [desc_factorial_zero, factorial_zero]\n| (succ n) := by rw [succ_desc_factorial_succ, desc_factorial_self, factorial_succ]\n\n@[simp] lemma desc_factorial_eq_zero_iff_lt {n : \u2115} : \u2200 {k : \u2115}, n.desc_factorial k = 0 \u2194 n < k\n| 0        := by simp only [desc_factorial_zero, nat.one_ne_zero, nat.not_lt_zero]\n| (succ k) := begin\n  rw [desc_factorial_succ, mul_eq_zero, desc_factorial_eq_zero_iff_lt, lt_succ_iff,\n    tsub_eq_zero_iff_le, lt_iff_le_and_ne, or_iff_left_iff_imp, and_imp],\n  exact \u03bb h _, h,\nend\n\nalias nat.desc_factorial_eq_zero_iff_lt \u2194 _ nat.desc_factorial_of_lt\n\nlemma add_desc_factorial_eq_asc_factorial (n : \u2115) :\n  \u2200 k : \u2115, (n + k).desc_factorial k = n.asc_factorial k\n| 0        := by rw [asc_factorial_zero, desc_factorial_zero]\n| (succ k) := by rw [nat.add_succ, succ_desc_factorial_succ, asc_factorial_succ,\n  add_desc_factorial_eq_asc_factorial]\n\n/-- `n.desc_factorial k = n! / (n - k)!` but without \u2115-division. See `nat.desc_factorial_eq_div`\nfor the version using \u2115-division. -/\ntheorem factorial_mul_desc_factorial : \u2200 {n k : \u2115}, k \u2264 n \u2192 (n - k)! * n.desc_factorial k = n!\n| n        0        := \u03bb _, by rw [desc_factorial_zero, mul_one, tsub_zero]\n| 0        (succ k) := \u03bb h, by { exfalso, exact not_succ_le_zero k h }\n| (succ n) (succ k) := \u03bb h, by rw [succ_desc_factorial_succ, succ_sub_succ, \u2190mul_assoc,\n  mul_comm (n - k)!, mul_assoc, factorial_mul_desc_factorial (nat.succ_le_succ_iff.1 h),\n    factorial_succ]\n\n/-- Avoid in favor of `nat.factorial_mul_desc_factorial` if you can. \u2115-division isn't worth it. -/\nlemma desc_factorial_eq_div {n k : \u2115} (h : k \u2264 n) : n.desc_factorial k = n! / (n - k)! :=\nbegin\n  apply mul_left_cancel\u2080 (factorial_ne_zero (n - k)),\n  rw factorial_mul_desc_factorial h,\n  exact (nat.mul_div_cancel' $ factorial_dvd_factorial $ nat.sub_le n k).symm,\nend\n\nlemma pow_sub_le_desc_factorial (n : \u2115) : \u2200 (k : \u2115), (n + 1 - k)^k \u2264 n.desc_factorial k\n| 0 := by rw [desc_factorial_zero, pow_zero]\n| (k + 1) := begin\n  rw [desc_factorial_succ, pow_succ, succ_sub_succ],\n  exact nat.mul_le_mul_of_nonneg_left (le_trans (nat.pow_le_pow_of_le_left\n    (tsub_le_tsub_right (le_succ _) _) k) (pow_sub_le_desc_factorial k)),\nend\n\nlemma pow_sub_lt_desc_factorial' {n : \u2115} :\n  \u2200 {k : \u2115}, k + 2 \u2264 n \u2192 (n - (k + 1))^(k + 2) < n.desc_factorial (k + 2)\n| 0 := \u03bb h, begin\n  rw [desc_factorial_succ, pow_succ, pow_one, desc_factorial_one],\n  exact nat.mul_lt_mul_of_pos_left (tsub_lt_self (lt_of_lt_of_le zero_lt_two h) zero_lt_one)\n    (tsub_pos_of_lt h),\nend\n| (k + 1) := \u03bb h, begin\n  rw [desc_factorial_succ, pow_succ],\n  refine nat.mul_lt_mul_of_pos_left ((nat.pow_le_pow_of_le_left (tsub_le_tsub_right\n    (le_succ n) _) _).trans_lt _) (tsub_pos_of_lt h),\n  rw succ_sub_succ,\n  exact (pow_sub_lt_desc_factorial' ((le_succ _).trans h)),\nend\n\nlemma pow_sub_lt_desc_factorial {n : \u2115} :\n  \u2200 {k : \u2115}, 2 \u2264 k \u2192 k \u2264 n \u2192 (n + 1 - k)^k < n.desc_factorial k\n| 0 := by rintro \u27e8\u27e9\n| 1 := by rintro (_ | \u27e8_, \u27e8\u27e9\u27e9)\n| (k + 2) := \u03bb _ h, by { rw succ_sub_succ, exact pow_sub_lt_desc_factorial' h }\n\nlemma desc_factorial_le_pow (n : \u2115) : \u2200 (k : \u2115), n.desc_factorial k \u2264 n^k\n| 0 := by rw [desc_factorial_zero, pow_zero]\n| (k + 1) := begin\n  rw [desc_factorial_succ, pow_succ],\n  exact nat.mul_le_mul (nat.sub_le _ _) (desc_factorial_le_pow k),\nend\n\nlemma desc_factorial_lt_pow {n : \u2115} (hn : 1 \u2264 n) : \u2200 {k : \u2115}, 2 \u2264 k \u2192 n.desc_factorial k < n^k\n| 0 := by rintro \u27e8\u27e9\n| 1 := by rintro (_ | \u27e8_, \u27e8\u27e9\u27e9)\n| (k + 2) := \u03bb _, begin\n  rw [desc_factorial_succ, pow_succ', mul_comm],\n  exact nat.mul_lt_mul' (desc_factorial_le_pow _ _) (tsub_lt_self hn k.zero_lt_succ)\n    (pow_pos hn _),\nend\n\nend desc_factorial\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/factorial/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7433003465485263}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module data.list.nat_antidiagonal\n! leanprover-community/mathlib commit f2f413b9d4be3a02840d0663dace76e8fe3da053\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.List.Nodup\nimport Mathbin.Data.List.Range\n\n/-!\n# Antidiagonals in \u2115 \u00d7 \u2115 as lists\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the antidiagonals of \u2115 \u00d7 \u2115 as lists: the `n`-th antidiagonal is the list of\npairs `(i, j)` such that `i + j = n`. This is useful for polynomial multiplication and more\ngenerally for sums going from `0` to `n`.\n\n## Notes\n\nFiles `data.multiset.nat_antidiagonal` and `data.finset.nat_antidiagonal` successively turn the\n`list` definition we have here into `multiset` and `finset`.\n-/\n\n\nopen List Function Nat\n\nnamespace List\n\nnamespace Nat\n\n#print List.Nat.antidiagonal /-\n/-- The antidiagonal of a natural number `n` is the list of pairs `(i, j)` such that `i + j = n`. -/\ndef antidiagonal (n : \u2115) : List (\u2115 \u00d7 \u2115) :=\n  (range (n + 1)).map fun i => (i, n - i)\n#align list.nat.antidiagonal List.Nat.antidiagonal\n-/\n\n#print List.Nat.mem_antidiagonal /-\n/-- A pair (i, j) is contained in the antidiagonal of `n` if and only if `i + j = n`. -/\n@[simp]\ntheorem mem_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} : x \u2208 antidiagonal n \u2194 x.1 + x.2 = n :=\n  by\n  rw [antidiagonal, mem_map]; constructor\n  \u00b7 rintro \u27e8i, hi, rfl\u27e9\n    rw [mem_range, lt_succ_iff] at hi\n    exact add_tsub_cancel_of_le hi\n  \u00b7 rintro rfl\n    refine' \u27e8x.fst, _, _\u27e9\n    \u00b7 rw [mem_range, add_assoc, lt_add_iff_pos_right]\n      exact zero_lt_succ _\n    \u00b7 exact Prod.ext rfl (add_tsub_cancel_left _ _)\n#align list.nat.mem_antidiagonal List.Nat.mem_antidiagonal\n-/\n\n#print List.Nat.length_antidiagonal /-\n/-- The length of the antidiagonal of `n` is `n + 1`. -/\n@[simp]\ntheorem length_antidiagonal (n : \u2115) : (antidiagonal n).length = n + 1 := by\n  rw [antidiagonal, length_map, length_range]\n#align list.nat.length_antidiagonal List.Nat.length_antidiagonal\n-/\n\n#print List.Nat.antidiagonal_zero /-\n/-- The antidiagonal of `0` is the list `[(0, 0)]` -/\n@[simp]\ntheorem antidiagonal_zero : antidiagonal 0 = [(0, 0)] :=\n  rfl\n#align list.nat.antidiagonal_zero List.Nat.antidiagonal_zero\n-/\n\n#print List.Nat.nodup_antidiagonal /-\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\ntheorem nodup_antidiagonal (n : \u2115) : Nodup (antidiagonal n) :=\n  (nodup_range _).map (@LeftInverse.injective \u2115 (\u2115 \u00d7 \u2115) Prod.fst (fun i => (i, n - i)) fun i => rfl)\n#align list.nat.nodup_antidiagonal List.Nat.nodup_antidiagonal\n-/\n\n#print List.Nat.antidiagonal_succ /-\n@[simp]\ntheorem antidiagonal_succ {n : \u2115} :\n    antidiagonal (n + 1) = (0, n + 1) :: (antidiagonal n).map (Prod.map Nat.succ id) :=\n  by\n  simp only [antidiagonal, range_succ_eq_map, map_cons, true_and_iff, Nat.add_succ_sub_one,\n    add_zero, id.def, eq_self_iff_true, tsub_zero, map_map, Prod.map_mk]\n  apply congr (congr rfl _) rfl\n  ext <;> simp\n#align list.nat.antidiagonal_succ List.Nat.antidiagonal_succ\n-/\n\n#print List.Nat.antidiagonal_succ' /-\ntheorem antidiagonal_succ' {n : \u2115} :\n    antidiagonal (n + 1) = (antidiagonal n).map (Prod.map id Nat.succ) ++ [(n + 1, 0)] :=\n  by\n  simp only [antidiagonal, range_succ, add_tsub_cancel_left, map_append, append_assoc, tsub_self,\n    singleton_append, map_map, map]\n  congr 1\n  apply map_congr\n  simp (config := { contextual := true }) [le_of_lt, Nat.succ_eq_add_one, Nat.sub_add_comm]\n#align list.nat.antidiagonal_succ' List.Nat.antidiagonal_succ'\n-/\n\n#print List.Nat.antidiagonal_succ_succ' /-\ntheorem antidiagonal_succ_succ' {n : \u2115} :\n    antidiagonal (n + 2) =\n      (0, n + 2) :: (antidiagonal n).map (Prod.map Nat.succ Nat.succ) ++ [(n + 2, 0)] :=\n  by\n  rw [antidiagonal_succ']\n  simpa\n#align list.nat.antidiagonal_succ_succ' List.Nat.antidiagonal_succ_succ'\n-/\n\n#print List.Nat.map_swap_antidiagonal /-\ntheorem map_swap_antidiagonal {n : \u2115} : (antidiagonal n).map Prod.swap = (antidiagonal n).reverse :=\n  by\n  rw [antidiagonal, map_map, Prod.swap, \u2190 List.map_reverse, range_eq_range', reverse_range', \u2190\n    range_eq_range', map_map]\n  apply map_congr\n  simp (config := { contextual := true }) [Nat.sub_sub_self, lt_succ_iff]\n#align list.nat.map_swap_antidiagonal List.Nat.map_swap_antidiagonal\n-/\n\nend Nat\n\nend List\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/List/NatAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7433003377151809}}
{"text": "-- El_limite_de_u_es_a_syss_el_de_u-a_es_0.lean\n-- El l\u00edmite de u es a syss el de u-a es 0.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 16 de julio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, una sucesi\u00f3n u\u2080, u\u2081, u\u2082, ... se puede representar mediante\n-- una funci\u00f3n (u : \u2115 \u2192 \u211d) de forma que u(n) es u\u2099.\n--\n-- Se define que a es el l\u00edmite de la sucesi\u00f3n u, por\n--    def limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n--    \u03bb u a, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - a| < \u03b5\n-- donde se usa la notaci\u00f3n |x| para el valor absoluto de x\n--    notation `|`x`|` := abs x\n--\n-- Demostrar que el l\u00edmite de u(i) es a si y solo si el de u(i)-a es\n-- 0.\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\nimport tactic\n\nvariable  {u : \u2115 \u2192 \u211d}\nvariables {a c x : \u211d}\n\nnotation `|`x`|` := abs x\n\ndef limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n\u03bb u c, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - c| < \u03b5\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  : limite u a \u2194 limite (\u03bb i, u i - a) 0 :=\nbegin\n  rw iff_eq_eq,\n  calc limite u a\n       = \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - a| < \u03b5       : rfl\n   ... = \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |(u n - a) - 0| < \u03b5 : by simp\n   ... = limite (\u03bb i, u i - a) 0                    : rfl,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  : limite u a \u2194 limite (\u03bb i, u i - a) 0 :=\nbegin\n  split,\n  { intros h \u03b5 h\u03b5,\n    convert h \u03b5 h\u03b5,\n    norm_num, },\n  { intros h \u03b5 h\u03b5,\n    convert h \u03b5 h\u03b5,\n    norm_num, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  : limite u a \u2194 limite (\u03bb i, u i - a) 0 :=\nbegin\n  split;\n  { intros h \u03b5 h\u03b5,\n    convert h \u03b5 h\u03b5,\n    norm_num, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nlemma limite_con_suma\n  (c : \u211d)\n  (h : limite u a)\n  : limite (\u03bb i, u i + c) (a + c) :=\n\u03bb \u03b5 h\u03b5, (by convert h \u03b5 h\u03b5; norm_num)\n\nlemma CNS_limite_con_suma\n  (c : \u211d)\n  : limite u a \u2194 limite (\u03bb i, u i + c) (a + c) :=\nbegin\n  split,\n  { apply limite_con_suma },\n  { intro h,\n    convert limite_con_suma (-c) h; simp, },\nend\n\nexample\n  (u : \u2115 \u2192 \u211d)\n  (a : \u211d)\n  : limite u a \u2194 limite (\u03bb i, u i - a) 0 :=\nbegin\n  convert CNS_limite_con_suma (-a),\n  simp,\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/El_limite_de_u_es_a_syss_el_de_u-a_es_0.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8723473713594991, "lm_q1q2_score": 0.7431987905985203}}
{"text": "-- Razonamiento sobre \u00e1rboles binarios: La funci\u00f3n espejo es involutiva\n-- ====================================================================\n\nimport tactic\n\nvariable {\u03b1 : Type}\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir un tipo de dato para los\n-- \u00e1rboles binarios, con los constructores hoja y nodo.\n-- ----------------------------------------------------\n\ninductive arbol (\u03b1 : Type) : Type\n| hoja : \u03b1 \u2192 arbol\n| nodo : \u03b1 \u2192 arbol \u2192 arbol \u2192 arbol\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Abrir el espacio de nombres arbol\n-- ----------------------------------------------------\n\nnamespace arbol\n\n-- #print prefix arbol\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Definir el \u00e1rbol correspondiente a\n--        3\n--       / \\\n--      2   4\n--     / \\\n--    1   5\n-- ----------------------------------------------------\n\ndef ejArbol : arbol \u2115 :=\n  nodo 3 (nodo 2 (hoja 1) (hoja 5)) (hoja 4)\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Definir la funci\u00f3n\n--    repr : arbol \u03b1 \u2192 string\n-- tal que (repr a) es la cadena que representa al\n-- \u00e1rbol a. Por ejemplo,\n--     #eval repr ejArbol\n--     Da: \"N 3 (N 2 (H 1) (H 5)) (H 4)\"\n-- ----------------------------------------------------\n\ndef repr [has_repr \u03b1] : arbol \u03b1 \u2192 string\n| (hoja x)     := \"H \" ++ has_repr.repr x\n| (nodo x i d) := \"N \" ++ has_repr.repr x ++ \" (\" ++ repr i ++ \") (\" ++ repr d ++ \")\"\n\n-- #eval repr ejArbol\n\n-- ----------------------------------------------------\n-- Ejercicio 4. Declarar repr la funci\u00f3n para\n-- representar los \u00e1rboles. Por ejemplo,\n--    #eval ejArbol\n--    -- Da: N 3 (N 2 (H 1) (H 5)) (H 4)\n-- ----------------------------------------------------\n\ninstance [has_repr \u03b1] : has_repr (arbol \u03b1) := \u27e8repr\u27e9\n\n-- #eval ejArbol\n-- -- Da: N 3 (N 2 (H 1) (H 5)) (H 4)\n\n-- --------------------------------------------------------------\n-- Ejercicio 5. Definir la funci\u00f3n\n--    espejo : arbol \u03b1 \u2192 arbol \u03b1\n-- tal que (espejo a) es la imagen especular de a. Por ejmplo,\n--    #eval espejo ejArbol\n--    -- Da: N 3 (H 4) (N 2 (H 5) (H 1))\n-- ----------------------------------------------------\n\ndef espejo : arbol \u03b1 \u2192 arbol \u03b1\n| (hoja x)     := hoja x\n| (nodo x i d) := nodo x (espejo d) (espejo i)\n\n-- #eval espejo ejArbol\n-- -- Da: N 3 (H 4) (N 2 (H 5) (H 1))\n\n-- ----------------------------------------------------\n-- Ejercicio 6. Declarar las siguientes variables:\n-- + a i d como variables sobre \u00e1rboles de tipo \u03b1.\n-- + x como variable sobre elementos de tipo \u03b1.\n-- ----------------------------------------------------\n\nvariables (a i d : arbol \u03b1)\nvariable  (x : \u03b1)\n\n-- ----------------------------------------------------\n-- Ejercicio 7. Demostrar los siguientes lemas\n-- + espejo_1 :\n--      espejo (hoja x) = hoja x\n-- + espejo_2 :\n--      espejo (nodo x i d) = nodo x (espejo d) (espejo i)\n-- ----------------------------------------------------\n\n@[simp]\nlemma espejo_1 :\n  espejo (hoja x) = hoja x :=\nespejo.equations._eqn_1 x\n\n@[simp]\nlemma espejo_2 :\n  espejo (nodo x i d) = nodo x (espejo d) (espejo i) :=\nespejo.equations._eqn_2 x i d\n\n-- ----------------------------------------------------\n-- Ejercicio 8. Demostrar que\n--    espejo (espejo a) = a\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  espejo (espejo a) = a :=\nbegin\n  induction a with x x i d Hi Hd,\n  { rw espejo_1,\n    rw espejo_1, },\n  { rw espejo_2,\n    rw espejo_2,\n    rw Hi,\n    rw Hd, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  espejo (espejo a) = a :=\nbegin\n  induction a with x x i d Hi Hd,\n  { calc espejo (espejo (hoja x))\n         = espejo (hoja x)\n             : by exact congr_arg espejo (espejo_1 x)\n     ... = hoja x\n             : by rw espejo_1, },\n  { calc espejo (espejo (nodo x i d))\n         = espejo (nodo x (espejo d) (espejo i))\n             :by exact congr_arg espejo (espejo_2 i d x)\n     ... = nodo x (espejo (espejo i)) (espejo (espejo d))\n             :by rw espejo_2\n     ... = nodo x i (espejo (espejo d))\n             :by rw Hi\n     ... = nodo x i d\n             :by rw Hd, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  espejo (espejo a) = a :=\nbegin\n  induction a with _ x i d Hi Hd,\n  { simp, },\n  { simp [Hi, Hd], },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  espejo (espejo a) = a :=\nby induction a ; simp [*]\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  espejo (espejo a) = a :=\narbol.rec_on a\n  ( assume x,\n    calc espejo (espejo (hoja x))\n         = espejo (hoja x)\n             : by exact congr_arg espejo (espejo_1 x)\n     ... = hoja x\n             : by rw espejo_1 )\n  ( assume x i d,\n    assume Hi : espejo (espejo i) = i,\n    assume Hd : espejo (espejo d) = d,\n    calc espejo (espejo (nodo x i d))\n         = espejo (nodo x (espejo d) (espejo i))\n             :by exact congr_arg espejo (espejo_2 i d x)\n     ... = nodo x (espejo (espejo i)) (espejo (espejo d))\n             :by rw espejo_2\n     ... = nodo x i (espejo (espejo d))\n             :by rw Hi\n     ... = nodo x i d\n             :by rw Hd )\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  espejo (espejo a) = a :=\narbol.rec_on a\n  (\u03bb x, by simp )\n  (\u03bb x i d Hi Hd, by simp [Hi,Hd])\n\n-- 7\u00aa demostraci\u00f3n\nlemma espejo_espejo :\n  \u2200 a : arbol \u03b1, espejo (espejo a) = a\n| (hoja x)     := by simp\n| (nodo x i d) := by simp [espejo_espejo i, espejo_espejo d]\n\n-- ----------------------------------------------------\n-- Ejercicio 9. Cerrar el espacio de nombres arbol.\n-- ----------------------------------------------------\n\nend arbol\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/8_Inductivos/Pruebas_de_que_la_funcion_espejo_de_los_arboles_binarios_es_involutiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7431987852281428}}
{"text": "/-\nCopyright (c) 2018 Mitchell Rowett. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mitchell Rowett, Scott Morrison\n-/\n\nimport algebra.quotient\nimport group_theory.subgroup.basic\n\n/-!\n# Cosets\n\nThis file develops the basic theory of left and right cosets.\n\n## Main definitions\n\n* `left_coset a s`: the left coset `a * s` for an element `a : \u03b1` and a subset `s \u2286 \u03b1`, for an\n  `add_group` this is `left_add_coset a s`.\n* `right_coset s a`: the right coset `s * a` for an element `a : \u03b1` and a subset `s \u2286 \u03b1`, for an\n  `add_group` this is `right_add_coset s a`.\n* `quotient_group.quotient s`: the quotient type representing the left cosets with respect to a\n  subgroup `s`, for an `add_group` this is `quotient_add_group.quotient s`.\n* `quotient_group.mk`: the canonical map from `\u03b1` to `\u03b1/s` for a subgroup `s` of `\u03b1`, for an\n  `add_group` this is `quotient_add_group.mk`.\n* `subgroup.left_coset_equiv_subgroup`: the natural bijection between a left coset and the subgroup,\n  for an `add_group` this is `add_subgroup.left_coset_equiv_add_subgroup`.\n\n## Notation\n\n* `a *l s`: for `left_coset a s`.\n* `a +l s`: for `left_add_coset a s`.\n* `s *r a`: for `right_coset s a`.\n* `s +r a`: for `right_add_coset s a`.\n\n* `G \u29f8 H` is the quotient of the (additive) group `G` by the (additive) subgroup `H`\n\n## TODO\n\nAdd `to_additive` to `preimage_mk_equiv_subgroup_times_set`.\n-/\n\nopen set function\n\nvariable {\u03b1 : Type*}\n\n/-- The left coset `a * s` for an element `a : \u03b1` and a subset `s : set \u03b1` -/\n@[to_additive left_add_coset \"The left coset `a+s` for an element `a : \u03b1`\nand a subset `s : set \u03b1`\"]\ndef left_coset [has_mul \u03b1] (a : \u03b1) (s : set \u03b1) : set \u03b1 := (\u03bb x, a * x) '' s\n\n/-- The right coset `s * a` for an element `a : \u03b1` and a subset `s : set \u03b1` -/\n@[to_additive right_add_coset \"The right coset `s+a` for an element `a : \u03b1`\nand a subset `s : set \u03b1`\"]\ndef right_coset [has_mul \u03b1] (s : set \u03b1) (a : \u03b1) : set \u03b1 := (\u03bb x, x * a) '' s\n\nlocalized \"infix ` *l `:70 := left_coset\" in coset\nlocalized \"infix ` +l `:70 := left_add_coset\" in coset\nlocalized \"infix ` *r `:70 := right_coset\" in coset\nlocalized \"infix ` +r `:70 := right_add_coset\" in coset\n\nsection coset_mul\nvariable [has_mul \u03b1]\n\n@[to_additive mem_left_add_coset]\nlemma mem_left_coset {s : set \u03b1} {x : \u03b1} (a : \u03b1) (hxS : x \u2208 s) : a * x \u2208 a *l s :=\nmem_image_of_mem (\u03bb b : \u03b1, a * b) hxS\n\n@[to_additive mem_right_add_coset]\nlemma mem_right_coset {s : set \u03b1} {x : \u03b1} (a : \u03b1) (hxS : x \u2208 s) : x * a \u2208 s *r a :=\nmem_image_of_mem (\u03bb b : \u03b1, b * a) hxS\n\n/-- Equality of two left cosets `a * s` and `b * s`. -/\n@[to_additive left_add_coset_equivalence \"Equality of two left cosets `a + s` and `b + s`.\"]\ndef left_coset_equivalence (s : set \u03b1) (a b : \u03b1) := a *l s = b *l s\n\n@[to_additive left_add_coset_equivalence_rel]\nlemma left_coset_equivalence_rel (s : set \u03b1) : equivalence (left_coset_equivalence s) :=\nmk_equivalence (left_coset_equivalence s) (\u03bb a, rfl) (\u03bb a b, eq.symm) (\u03bb a b c, eq.trans)\n\n/-- Equality of two right cosets `s * a` and `s * b`. -/\n@[to_additive right_add_coset_equivalence \"Equality of two right cosets `s + a` and `s + b`.\"]\ndef right_coset_equivalence (s : set \u03b1) (a b : \u03b1) := s *r a = s *r b\n\n@[to_additive right_add_coset_equivalence_rel]\nlemma right_coset_equivalence_rel (s : set \u03b1) : equivalence (right_coset_equivalence s) :=\nmk_equivalence (right_coset_equivalence s) (\u03bb a, rfl) (\u03bb a b, eq.symm) (\u03bb a b c, eq.trans)\n\nend coset_mul\n\nsection coset_semigroup\nvariable [semigroup \u03b1]\n\n@[simp, to_additive left_add_coset_assoc] lemma left_coset_assoc (s : set \u03b1) (a b : \u03b1) :\n  a *l (b *l s) = (a * b) *l s :=\nby simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc]\n\n@[simp, to_additive right_add_coset_assoc] lemma right_coset_assoc (s : set \u03b1) (a b : \u03b1) :\n  s *r a *r b = s *r (a * b) :=\nby simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc]\n\n@[to_additive left_add_coset_right_add_coset]\nlemma left_coset_right_coset (s : set \u03b1) (a b : \u03b1) : a *l s *r b = a *l (s *r b) :=\nby simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc]\n\nend coset_semigroup\n\nsection coset_monoid\nvariables [monoid \u03b1] (s : set \u03b1)\n\n@[simp, to_additive zero_left_add_coset] lemma one_left_coset : 1 *l s = s :=\nset.ext $ by simp [left_coset]\n\n@[simp, to_additive right_add_coset_zero] lemma right_coset_one : s *r 1 = s :=\nset.ext $ by simp [right_coset]\n\nend coset_monoid\n\nsection coset_submonoid\nopen submonoid\nvariables [monoid \u03b1] (s : submonoid \u03b1)\n\n@[to_additive mem_own_left_add_coset]\nlemma mem_own_left_coset (a : \u03b1) : a \u2208 a *l s :=\nsuffices a * 1 \u2208 a *l s, by simpa,\nmem_left_coset a (one_mem s)\n\n@[to_additive mem_own_right_add_coset]\nlemma mem_own_right_coset (a : \u03b1) : a \u2208 (s : set \u03b1) *r a :=\nsuffices 1 * a \u2208 (s : set \u03b1) *r a, by simpa,\nmem_right_coset a (one_mem s)\n\n@[to_additive mem_left_add_coset_left_add_coset]\nlemma mem_left_coset_left_coset {a : \u03b1} (ha : a *l s = s) : a \u2208 s :=\nby rw [\u2190set_like.mem_coe, \u2190ha]; exact mem_own_left_coset s a\n\n@[to_additive mem_right_add_coset_right_add_coset]\nlemma mem_right_coset_right_coset {a : \u03b1} (ha : (s : set \u03b1) *r a = s) : a \u2208 s :=\nby rw [\u2190set_like.mem_coe, \u2190ha]; exact mem_own_right_coset s a\n\nend coset_submonoid\n\nsection coset_group\nvariables [group \u03b1] {s : set \u03b1} {x : \u03b1}\n\n@[to_additive mem_left_add_coset_iff]\nlemma mem_left_coset_iff (a : \u03b1) : x \u2208 a *l s \u2194 a\u207b\u00b9 * x \u2208 s :=\niff.intro\n  (assume \u27e8b, hb, eq\u27e9, by simp [eq.symm, hb])\n  (assume h, \u27e8a\u207b\u00b9 * x, h, by simp\u27e9)\n\n@[to_additive mem_right_add_coset_iff]\nlemma mem_right_coset_iff (a : \u03b1) : x \u2208 s *r a \u2194 x * a\u207b\u00b9 \u2208 s :=\niff.intro\n  (assume \u27e8b, hb, eq\u27e9, by simp [eq.symm, hb])\n  (assume h, \u27e8x * a\u207b\u00b9, h, by simp\u27e9)\n\nend coset_group\n\nsection coset_subgroup\nopen subgroup\n\nvariables [group \u03b1] (s : subgroup \u03b1)\n\n@[to_additive left_add_coset_mem_left_add_coset]\nlemma left_coset_mem_left_coset {a : \u03b1} (ha : a \u2208 s) : a *l s = s :=\nset.ext $ by simp [mem_left_coset_iff, mul_mem_cancel_left s (s.inv_mem ha)]\n\n@[to_additive right_add_coset_mem_right_add_coset]\nlemma right_coset_mem_right_coset {a : \u03b1} (ha : a \u2208 s) : (s : set \u03b1) *r a = s :=\nset.ext $ assume b, by simp [mem_right_coset_iff, mul_mem_cancel_right s (s.inv_mem ha)]\n\n@[to_additive eq_add_cosets_of_normal]\ntheorem eq_cosets_of_normal (N : s.normal) (g : \u03b1) : g *l s = s *r g :=\nset.ext $ assume a, by simp [mem_left_coset_iff, mem_right_coset_iff]; rw [N.mem_comm_iff]\n\n@[to_additive normal_of_eq_add_cosets]\ntheorem normal_of_eq_cosets (h : \u2200 g : \u03b1, g *l s = s *r g) : s.normal :=\n\u27e8assume a ha g, show g * a * g\u207b\u00b9 \u2208 (s : set \u03b1),\n  by rw [\u2190 mem_right_coset_iff, \u2190 h]; exact mem_left_coset g ha\u27e9\n\n@[to_additive normal_iff_eq_add_cosets]\ntheorem normal_iff_eq_cosets : s.normal \u2194 \u2200 g : \u03b1, g *l s = s *r g :=\n\u27e8@eq_cosets_of_normal _ _ s, normal_of_eq_cosets s\u27e9\n\n@[to_additive left_add_coset_eq_iff]\nlemma left_coset_eq_iff {x y : \u03b1} : left_coset x s = left_coset y s \u2194 x\u207b\u00b9 * y \u2208 s :=\nbegin\n  rw set.ext_iff,\n  simp_rw [mem_left_coset_iff, set_like.mem_coe],\n  split,\n  { intro h, apply (h y).mpr, rw mul_left_inv, exact s.one_mem },\n  { intros h z, rw \u2190mul_inv_cancel_right x\u207b\u00b9 y, rw mul_assoc, exact s.mul_mem_cancel_left h },\nend\n\n@[to_additive right_add_coset_eq_iff]\nlemma right_coset_eq_iff {x y : \u03b1} : right_coset \u2191s x = right_coset s y \u2194 y * x\u207b\u00b9 \u2208 s :=\nbegin\n  rw set.ext_iff,\n  simp_rw [mem_right_coset_iff, set_like.mem_coe],\n  split,\n  { intro h, apply (h y).mpr, rw mul_right_inv, exact s.one_mem },\n  { intros h z, rw \u2190inv_mul_cancel_left y x\u207b\u00b9, rw \u2190mul_assoc, exact s.mul_mem_cancel_right h },\nend\n\nend coset_subgroup\n\nrun_cmd to_additive.map_namespace `quotient_group `quotient_add_group\n\nnamespace quotient_group\n\nvariables [group \u03b1] (s : subgroup \u03b1)\n\n/-- The equivalence relation corresponding to the partition of a group by left cosets\nof a subgroup.-/\n@[to_additive \"The equivalence relation corresponding to the partition of a group by left cosets\nof a subgroup.\"]\ndef left_rel : setoid \u03b1 :=\n\u27e8\u03bb x y, x\u207b\u00b9 * y \u2208 s, by { simp_rw \u2190left_coset_eq_iff, exact left_coset_equivalence_rel s }\u27e9\n\nlemma left_rel_r_eq_left_coset_equivalence :\n  @setoid.r _ (quotient_group.left_rel s) = left_coset_equivalence s :=\nby { ext, exact (left_coset_eq_iff s).symm }\n\n@[to_additive]\ninstance left_rel_decidable [decidable_pred (\u2208 s)] :\n  decidable_rel (left_rel s).r := \u03bb x y, \u2039decidable_pred (\u2208 s)\u203a _\n\n/-- `\u03b1 \u29f8 s` is the quotient type representing the left cosets of `s`.\n  If `s` is a normal subgroup, `\u03b1 \u29f8 s` is a group -/\n@[to_additive \"`\u03b1 \u29f8 s` is the quotient type representing the left cosets of `s`.  If `s` is a\nnormal subgroup, `\u03b1 \u29f8 s` is a group\"]\ninstance : has_quotient \u03b1 (subgroup \u03b1) := \u27e8\u03bb s, quotient (left_rel s)\u27e9\n\n/-- The equivalence relation corresponding to the partition of a group by right cosets of a\nsubgroup. -/\n@[to_additive \"The equivalence relation corresponding to the partition of a group by right cosets of\na subgroup.\"]\ndef right_rel : setoid \u03b1 :=\n\u27e8\u03bb x y, y * x\u207b\u00b9 \u2208 s, by { simp_rw \u2190right_coset_eq_iff, exact right_coset_equivalence_rel s }\u27e9\n\nlemma right_rel_r_eq_right_coset_equivalence :\n  @setoid.r _ (quotient_group.right_rel s) = right_coset_equivalence s :=\nby { ext, exact (right_coset_eq_iff s).symm }\n\n@[to_additive]\ninstance right_rel_decidable [decidable_pred (\u2208 s)] :\n  decidable_rel (right_rel s).r := \u03bb x y, \u2039decidable_pred (\u2208 s)\u203a _\n\nend quotient_group\n\nnamespace quotient_group\n\nvariables [group \u03b1] {s : subgroup \u03b1}\n\n@[to_additive]\ninstance fintype [fintype \u03b1] (s : subgroup \u03b1) [decidable_rel (left_rel s).r] :\n  fintype (\u03b1 \u29f8 s) :=\nquotient.fintype (left_rel s)\n\n/-- The canonical map from a group `\u03b1` to the quotient `\u03b1 \u29f8 s`. -/\n@[to_additive \"The canonical map from an `add_group` `\u03b1` to the quotient `\u03b1 \u29f8 s`.\"]\nabbreviation mk (a : \u03b1) : \u03b1 \u29f8 s :=\nquotient.mk' a\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on {C : \u03b1 \u29f8 s \u2192 Prop} (x : \u03b1 \u29f8 s)\n  (H : \u2200 z, C (quotient_group.mk z)) : C x :=\nquotient.induction_on' x H\n\n@[to_additive]\ninstance : has_coe_t \u03b1 (\u03b1 \u29f8 s) := \u27e8mk\u27e9 -- note [use has_coe_t]\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on' {C : \u03b1 \u29f8 s \u2192 Prop} (x : \u03b1 \u29f8 s)\n  (H : \u2200 z : \u03b1, C z) : C x :=\nquotient.induction_on' x H\n\n@[to_additive]\nlemma forall_coe {C : \u03b1 \u29f8 s \u2192 Prop} :\n  (\u2200 x : \u03b1 \u29f8 s, C x) \u2194 \u2200 x : \u03b1, C x :=\n\u27e8\u03bb hx x, hx _, quot.ind\u27e9\n\n@[to_additive]\ninstance (s : subgroup \u03b1) : inhabited (\u03b1 \u29f8 s) :=\n\u27e8((1 : \u03b1) : \u03b1 \u29f8 s)\u27e9\n\n@[to_additive quotient_add_group.eq]\nprotected lemma eq {a b : \u03b1} : (a : \u03b1 \u29f8 s) = b \u2194 a\u207b\u00b9 * b \u2208 s :=\nquotient.eq'\n\n@[to_additive quotient_add_group.eq']\nlemma eq' {a b : \u03b1} : (mk a : \u03b1 \u29f8 s) = mk b \u2194 a\u207b\u00b9 * b \u2208 s :=\nquotient_group.eq\n\n@[to_additive quotient_add_group.out_eq']\nlemma out_eq' (a : \u03b1 \u29f8 s) : mk a.out' = a :=\nquotient.out_eq' a\n\nvariables (s)\n\n/- It can be useful to write `obtain \u27e8h, H\u27e9 := mk_out'_eq_mul ...`, and then `rw [H]` or\n  `simp_rw [H]` or `simp only [H]`. In order for `simp_rw` and `simp only` to work, this lemma is\n  stated in terms of an arbitrary `h : s`, rathern that the specific `h = g\u207b\u00b9 * (mk g).out'`. -/\n@[to_additive quotient_add_group.mk_out'_eq_mul]\nlemma mk_out'_eq_mul (g : \u03b1) : \u2203 h : s, (mk g : \u03b1 \u29f8 s).out' = g * h :=\n\u27e8\u27e8g\u207b\u00b9 * (mk g).out', eq'.mp (mk g).out_eq'.symm\u27e9, by rw [s.coe_mk, mul_inv_cancel_left]\u27e9\n\nvariables {s}\n\n@[to_additive quotient_add_group.mk_mul_of_mem]\nlemma mk_mul_of_mem (g\u2081 g\u2082 : \u03b1) (hg\u2082 : g\u2082 \u2208 s) : (mk (g\u2081 * g\u2082) : \u03b1 \u29f8 s) = mk g\u2081 :=\nby rwa [eq', mul_inv_rev, inv_mul_cancel_right, s.inv_mem_iff]\n\n@[to_additive]\nlemma eq_class_eq_left_coset (s : subgroup \u03b1) (g : \u03b1) :\n  {x : \u03b1 | (x : \u03b1 \u29f8 s) = g} = left_coset g s :=\nset.ext $ \u03bb z,\n  by rw [mem_left_coset_iff, set.mem_set_of_eq, eq_comm, quotient_group.eq, set_like.mem_coe]\n\n@[to_additive]\nlemma preimage_image_coe (N : subgroup \u03b1) (s : set \u03b1) :\n  coe \u207b\u00b9' ((coe : \u03b1 \u2192 \u03b1 \u29f8 N) '' s) = \u22c3 x : N, (\u03bb y : \u03b1, y * x) \u207b\u00b9' s :=\nbegin\n  ext x,\n  simp only [quotient_group.eq, set_like.exists, exists_prop, set.mem_preimage, set.mem_Union,\n    set.mem_image, subgroup.coe_mk, \u2190 eq_inv_mul_iff_mul_eq],\n  exact \u27e8\u03bb \u27e8y, hs, hN\u27e9, \u27e8_, N.inv_mem hN, by simpa using hs\u27e9,\n         \u03bb \u27e8z, hz, hxz\u27e9, \u27e8x*z, hxz, by simpa using hz\u27e9\u27e9,\nend\n\nend quotient_group\n\nnamespace subgroup\nopen quotient_group\nvariables [group \u03b1] {s : subgroup \u03b1}\n\n/-- The natural bijection between a left coset `g * s` and `s`. -/\n@[to_additive \"The natural bijection between the cosets `g + s` and `s`.\"]\ndef left_coset_equiv_subgroup (g : \u03b1) : left_coset g s \u2243 s :=\n\u27e8\u03bb x, \u27e8g\u207b\u00b9 * x.1, (mem_left_coset_iff _).1 x.2\u27e9,\n \u03bb x, \u27e8g * x.1, x.1, x.2, rfl\u27e9,\n \u03bb \u27e8x, hx\u27e9, subtype.eq $ by simp,\n \u03bb \u27e8g, hg\u27e9, subtype.eq $ by simp\u27e9\n\n/-- The natural bijection between a right coset `s * g` and `s`. -/\n@[to_additive \"The natural bijection between the cosets `s + g` and `s`.\"]\ndef right_coset_equiv_subgroup (g : \u03b1) : right_coset \u2191s g \u2243 s :=\n\u27e8\u03bb x, \u27e8x.1 * g\u207b\u00b9, (mem_right_coset_iff _).1 x.2\u27e9,\n \u03bb x, \u27e8x.1 * g, x.1, x.2, rfl\u27e9,\n \u03bb \u27e8x, hx\u27e9, subtype.eq $ by simp,\n \u03bb \u27e8g, hg\u27e9, subtype.eq $ by simp\u27e9\n\n/-- A (non-canonical) bijection between a group `\u03b1` and the product `(\u03b1/s) \u00d7 s` -/\n@[to_additive \"A (non-canonical) bijection between an add_group `\u03b1` and the product `(\u03b1/s) \u00d7 s`\"]\nnoncomputable def group_equiv_quotient_times_subgroup :\n  \u03b1 \u2243 (\u03b1 \u29f8 s) \u00d7 s :=\ncalc \u03b1 \u2243 \u03a3 L : \u03b1 \u29f8 s, {x : \u03b1 // (x : \u03b1 \u29f8 s) = L} :\n  (equiv.sigma_preimage_equiv quotient_group.mk).symm\n    ... \u2243 \u03a3 L : \u03b1 \u29f8 s, left_coset (quotient.out' L) s :\n  equiv.sigma_congr_right (\u03bb L,\n    begin\n      rw \u2190 eq_class_eq_left_coset,\n      show _root_.subtype (\u03bb x : \u03b1, quotient.mk' x = L) \u2243\n        _root_.subtype (\u03bb x : \u03b1, quotient.mk' x = quotient.mk' _),\n      simp [-quotient.eq'],\n    end)\n    ... \u2243 \u03a3 L : \u03b1 \u29f8 s, s :\n  equiv.sigma_congr_right (\u03bb L, left_coset_equiv_subgroup _)\n    ... \u2243 (\u03b1 \u29f8 s) \u00d7 s :\n  equiv.sigma_equiv_prod _ _\n\nvariables {t : subgroup \u03b1}\n\n/-- If `H \u2264 K`, then `G/H \u2243 G/K \u00d7 K/H` constructively, using the provided right inverse\nof the quotient map `G \u2192 G/K`. The classical version is `quotient_equiv_prod_of_le`. -/\n@[to_additive \"If `H \u2264 K`, then `G/H \u2243 G/K \u00d7 K/H` constructively, using the provided right inverse\nof the quotient map `G \u2192 G/K`. The classical version is `quotient_equiv_prod_of_le`.\", simps]\ndef quotient_equiv_prod_of_le' (h_le : s \u2264 t)\n  (f : \u03b1 \u29f8 t \u2192 \u03b1) (hf : function.right_inverse f quotient_group.mk) :\n  \u03b1 \u29f8 s \u2243 (\u03b1 \u29f8 t) \u00d7 (t \u29f8 s.subgroup_of t) :=\n{ to_fun := \u03bb a, \u27e8a.map' id (\u03bb b c h, h_le h),\n    a.map' (\u03bb g : \u03b1, \u27e8(f (quotient.mk' g))\u207b\u00b9 * g, quotient.exact' (hf g)\u27e9) (\u03bb b c h, by\n    { change ((f b)\u207b\u00b9 * b)\u207b\u00b9 * ((f c)\u207b\u00b9 * c) \u2208 s,\n      have key : f b = f c := congr_arg f (quotient.sound' (h_le h)),\n      rwa [key, mul_inv_rev, inv_inv, mul_assoc, mul_inv_cancel_left] })\u27e9,\n  inv_fun := \u03bb a, a.2.map' (\u03bb b, f a.1 * b) (\u03bb b c h, by\n  { change (f a.1 * b)\u207b\u00b9 * (f a.1 * c) \u2208 s,\n    rwa [mul_inv_rev, mul_assoc, inv_mul_cancel_left] }),\n  left_inv := by\n  { refine quotient.ind' (\u03bb a, _),\n    simp_rw [quotient.map'_mk', id.def, t.coe_mk, mul_inv_cancel_left] },\n  right_inv := by\n  { refine prod.rec _,\n    refine quotient.ind' (\u03bb a, _),\n    refine quotient.ind' (\u03bb b, _),\n    have key : quotient.mk' (f (quotient.mk' a) * b) = quotient.mk' a :=\n      (quotient_group.mk_mul_of_mem (f a) \u2191b b.2).trans (hf a),\n    simp_rw [quotient.map'_mk', id.def, key, inv_mul_cancel_left, subtype.coe_eta] } }\n\n/-- If `H \u2264 K`, then `G/H \u2243 G/K \u00d7 K/H` nonconstructively.\nThe constructive version is `quotient_equiv_prod_of_le'`. -/\n@[to_additive \"If `H \u2264 K`, then `G/H \u2243 G/K \u00d7 K/H` nonconstructively.\nThe constructive version is `quotient_equiv_prod_of_le'`.\", simps]\nnoncomputable def quotient_equiv_prod_of_le (h_le : s \u2264 t) :\n  \u03b1 \u29f8 s \u2243 (\u03b1 \u29f8 t) \u00d7 (t \u29f8 s.subgroup_of t) :=\nquotient_equiv_prod_of_le' h_le quotient.out' quotient.out_eq'\n\n@[to_additive] lemma card_eq_card_quotient_mul_card_subgroup\n  [fintype \u03b1] (s : subgroup \u03b1) [fintype s] [decidable_pred (\u03bb a, a \u2208 s)] :\n  fintype.card \u03b1 = fintype.card (\u03b1 \u29f8 s) * fintype.card s :=\nby rw \u2190 fintype.card_prod;\n  exact fintype.card_congr (subgroup.group_equiv_quotient_times_subgroup)\n\n/-- **Order of a Subgroup** -/\n@[to_additive] lemma card_subgroup_dvd_card [fintype \u03b1] (s : subgroup \u03b1) [fintype s] :\n  fintype.card s \u2223 fintype.card \u03b1 :=\nby classical; simp [card_eq_card_quotient_mul_card_subgroup s, @dvd_mul_left \u2115]\n\n@[to_additive] lemma card_quotient_dvd_card [fintype \u03b1] (s : subgroup \u03b1)\n  [decidable_pred (\u03bb a, a \u2208 s)] [fintype s] : fintype.card (\u03b1 \u29f8 s) \u2223 fintype.card \u03b1 :=\nby simp [card_eq_card_quotient_mul_card_subgroup s, @dvd_mul_right \u2115]\n\nopen fintype\n\nvariables {H : Type*} [group H]\n\n@[to_additive] lemma card_dvd_of_injective [fintype \u03b1] [fintype H] (f : \u03b1 \u2192* H)\n  (hf : function.injective f) : card \u03b1 \u2223 card H :=\nby classical;\ncalc card \u03b1 = card (f.range : subgroup H) : card_congr (equiv.of_injective f hf)\n...\u2223 card H : card_subgroup_dvd_card _\n\n@[to_additive] lemma card_dvd_of_le {H K : subgroup \u03b1} [fintype H] [fintype K] (hHK : H \u2264 K) :\n  card H \u2223 card K :=\ncard_dvd_of_injective (inclusion hHK) (inclusion_injective hHK)\n\n@[to_additive] lemma card_comap_dvd_of_injective (K : subgroup H) [fintype K]\n  (f : \u03b1 \u2192* H) [fintype (K.comap f)] (hf : function.injective f) :\n  fintype.card (K.comap f) \u2223 fintype.card K :=\nby haveI : fintype ((K.comap f).map f) :=\n  fintype.of_equiv _ (equiv_map_of_injective _ _ hf).to_equiv;\ncalc fintype.card (K.comap f) = fintype.card ((K.comap f).map f) :\n       fintype.card_congr (equiv_map_of_injective _ _ hf).to_equiv\n... \u2223 fintype.card K : card_dvd_of_le (map_comap_le _ _)\n\nend subgroup\n\nnamespace quotient_group\n\nvariables [group \u03b1]\n\n-- FIXME -- why is there no `to_additive`?\n\n/-- If `s` is a subgroup of the group `\u03b1`, and `t` is a subset of `\u03b1/s`, then\nthere is a (typically non-canonical) bijection between the preimage of `t` in\n`\u03b1` and the product `s \u00d7 t`. -/\nnoncomputable def preimage_mk_equiv_subgroup_times_set\n  (s : subgroup \u03b1) (t : set (\u03b1 \u29f8 s)) : quotient_group.mk \u207b\u00b9' t \u2243 s \u00d7 t :=\nhave h : \u2200 {x : \u03b1 \u29f8 s} {a : \u03b1}, x \u2208 t \u2192 a \u2208 s \u2192\n  (quotient.mk' (quotient.out' x * a) : \u03b1 \u29f8 s) = quotient.mk' (quotient.out' x) :=\n    \u03bb x a hx ha, quotient.sound' (show (quotient.out' x * a)\u207b\u00b9 * quotient.out' x \u2208 s,\n      from (s.inv_mem_iff).1 $\n        by rwa [mul_inv_rev, inv_inv, \u2190 mul_assoc, inv_mul_self, one_mul]),\n{ to_fun := \u03bb \u27e8a, ha\u27e9, \u27e8\u27e8(quotient.out' (quotient.mk' a))\u207b\u00b9 * a,\n    @quotient.exact' _ (left_rel s) _ _ $ (quotient.out_eq' _)\u27e9,\n      \u27e8quotient.mk' a, ha\u27e9\u27e9,\n  inv_fun := \u03bb \u27e8\u27e8a, ha\u27e9, \u27e8x, hx\u27e9\u27e9, \u27e8quotient.out' x * a, show quotient.mk' _ \u2208 t,\n    by simp [h hx ha, hx]\u27e9,\n  left_inv := \u03bb \u27e8a, ha\u27e9, subtype.eq $ show _ * _ = a, by simp,\n  right_inv := \u03bb \u27e8\u27e8a, ha\u27e9, \u27e8x, hx\u27e9\u27e9, show (_, _) = _, by simp [h hx ha] }\n\nend quotient_group\n\n/--\nWe use the class `has_coe_t` instead of `has_coe` if the first argument is a variable,\nor if the second argument is a variable not occurring in the first.\nUsing `has_coe` would cause looping of type-class inference. See\n<https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/remove.20all.20instances.20with.20variable.20domain>\n-/\nlibrary_note \"use has_coe_t\"\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/group_theory/coset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7431987837559191}}
{"text": "set_option trace.simplify.rewrite true\nopen nat\nopen classical\n\n\nlemma fst_of_two_props :\n\u2200a b : Prop, a \u2192 b \u2192 a :=\nassume a b : Prop,\nassume ha : a,\nassume hb : b,\nshow a, from\nha\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\na \u2192 c :=\nbegin\n  assume ha : a,\n  have hb : b :=\n  hab ha,\n  have hc : c :=\n  hbc hb,\n  show c, from\n  hc\nend\n\n\n--------\n\n--Prueba mixta\nlemma forall.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n(\u2200x, x = t \u2192 p x) \u2194 p t :=\niff.intro\n  (assume hall : \u2200x, x = t \u2192 p x,\n  show p t, from\n    begin\n    apply hall t,\n    refl\n    end)\n  (assume hp : p t,\n  assume x,\n  assume heq : x = t,\n  show p x, from\n    begin\n    rw heq,\n    exact hp\n    end\n)\n\n--Prueba by tactics\nlemma forall.one_point2 {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n(\u2200x, x = t \u2192 p x) \u2194 p t :=\nbegin\n  split,\n  {assume h1,\n  apply h1 t,\n  refl},\n  {assume h1,\n  assume x,\n  assume h2: x=t,\n  rw h2,\n  exact h1\n  }\nend\n\n-- Prueba sin tactics\nlemma forall.one_point3 {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n(\u2200x, x = t \u2192 p x) \u2194 p t :=\niff.intro \n(assume h1: \u2200x, x = t \u2192 p x,\nhave h2 : t=t \u2192 p t, from\n  h1 t,\nshow p t, from\n h2 (eq.refl t)\n) \n(assume h1 : p t,\nassume x : \u03b1,\nassume h2 : x=t,\nshow p x, from\n  eq.subst (eq.symm h2) h1\n)\n\n\n------------\n\n\n\nlemma beast_666 (beast : \u2115) :\n(\u2200n, n = 666 \u2192 beast \u2265 n) \u2194 beast \u2265 666 :=\nforall.one_point 666 (\u03bb n:\u2115, beast \u2265 n)\n\nlemma beast_666_2 (beast : \u2115) :\n(\u2200n, n = 666 \u2192 beast \u2265 n) \u2194 beast \u2265 666 :=\nforall.one_point 666 (\u03bb n:\u2115, beast \u2265 n)\n\n\nlemma exists.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n(\u2203x : \u03b1, x = t \u2227 p x) \u2194 p t :=\niff.intro\n(assume hex : \u2203x, x = t \u2227 p x,\nshow p t, from\n  exists.elim hex\n  (assume x,\n  assume hand : x = t \u2227 p x,\n  show p t, from\n    by cc))\n(assume hp : p t,\nshow \u2203x : \u03b1, x = t \u2227 p x, from\n  exists.intro t\n  (show t = t \u2227 p t, from\n    by cc))\n\nlemma prop_comp\u2083 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  have hb : b :=\n    hab ha,\n  let c' := c,\n  have hc : c' :=\n    hbc hb,\n  exact hc\nend", "meta": {"author": "raulmom", "repo": "Colab", "sha": "6c0b668e7ac308047faa34b21bb06759ef0b9f6c", "save_path": "github-repos/lean/raulmom-Colab", "path": "github-repos/lean/raulmom-Colab/Colab-6c0b668e7ac308047faa34b21bb06759ef0b9f6c/UACourse/Tema 1/22_01/22_01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7431987779338216}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Sets in Lean, example sheet 2 : \"the\" empty set and the \"universal set\".\n\nLean notation for the empty subset of `X` is `\u2205`. Unlike in\nset theory, there is more than one empty set in Lean! Every\ntype has an empty subset, and it *doesn't make sense*\nto ask if `\u2205 : set \u2115` and `\u2205 : set \u2124` are equal, because\nthey have different types. \n\nAt the other extreme, the subset of `X` containing all the terms of type `X`\nis...well...mathematicians would just call it `X`, but `X` is a type not a subset. \nThe subset of `X` consisting of every element of `X` is called `set.univ : set X`, \nor just `univ : set X` if we have opened the `set` namespace. Let's do that now.\n\n-/\n\nopen set\n\n/-\n\n## Definition of \u2205 and univ\n\n`x \u2208 \u2205` is *by definition* equal to `false` and `x \u2208 univ` is *by definition*\nequal to `true`. You can use the `change` tactic to make these changes\nif you like. But you don't have to. Remember that `triv` proves `true`\nand `cases h` will solve a goal if `h : false`.\n\n-/\n\n\n-- set up variables\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D E : set X) -- A,B,C,D,E are subsets of `X`\n  (x y z : X) -- x,y,z are elements of `X` or, more precisely, terms of type `X`\n\nopen set\n\nexample : x \u2208 (univ : set X) := \nbegin\n  triv,\nend\n\nexample : x \u2208 (\u2205 : set X) \u2192 false :=\nbegin\n  exact id,\nend\n\nexample : A \u2286 univ :=\nbegin\n  intros x hxA,\n  triv,\nend\n\nexample : \u2205 \u2286 A :=\nbegin\n  -- rintros x \u27e8\u27e9, -- solves goal in one line\n  intros x hx,\n  change false at hx, -- unnecessary line\n  exfalso,\n  exact hx,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/solutions/section05sets/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7431987767459894}}
{"text": "/-\nCopyright (c) 2022 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n\n! This file was ported from Lean 3 source module data.int.associated\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Associated\nimport Mathbin.Data.Int.Units\n\n/-!\n# Associated elements and the integers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains some results on equality up to units in the integers.\n\n## Main results\n\n * `int.nat_abs_eq_iff_associated`: the absolute value is equal iff integers are associated\n-/\n\n\n/- warning: int.nat_abs_eq_iff_associated -> Int.natAbs_eq_iff_associated is a dubious translation:\nlean 3 declaration is\n  forall {a : Int} {b : Int}, Iff (Eq.{1} Nat (Int.natAbs a) (Int.natAbs b)) (Associated.{0} Int Int.monoid a b)\nbut is expected to have type\n  forall {a : Int} {b : Int}, Iff (Eq.{1} Nat (Int.natAbs a) (Int.natAbs b)) (Associated.{0} Int Int.instMonoidInt a b)\nCase conversion may be inaccurate. Consider using '#align int.nat_abs_eq_iff_associated Int.natAbs_eq_iff_associated\u2093'. -/\ntheorem Int.natAbs_eq_iff_associated {a b : \u2124} : a.natAbs = b.natAbs \u2194 Associated a b :=\n  by\n  refine' int.nat_abs_eq_nat_abs_iff.trans _\n  constructor\n  \u00b7 rintro (rfl | rfl)\n    \u00b7 rfl\n    \u00b7 exact \u27e8-1, by simp\u27e9\n  \u00b7 rintro \u27e8u, rfl\u27e9\n    obtain rfl | rfl := Int.units_eq_one_or u\n    \u00b7 exact Or.inl (by simp)\n    \u00b7 exact Or.inr (by simp)\n#align int.nat_abs_eq_iff_associated Int.natAbs_eq_iff_associated\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Int/Associated.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033684, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.743198773918605}}
{"text": "\nimport tactic \nimport .size .num_lemmas \n\nopen_locale classical \nopen_locale big_operators \nnoncomputable theory \n\nuniverses u v w\n \nopen set \n\nvariables {\u03b1 : Type*} [fintype \u03b1]\n\ndef list_union : list (set \u03b1) \u2192 set \u03b1 := \n  \u03bb Xs, (\u22c3 (X \u2208 Xs), X) \n\ndef list_inter : list (set \u03b1) \u2192 set \u03b1 := \n  \u03bb Xs, (\u22c2 (X \u2208 Xs), X)\n\n@[simp] lemma list_empty_union_eq_empty (Xs : list (set \u03b1)) : \n  Xs = list.nil \u2192 list_union Xs = \u2205 :=\n\u03bb h, by {unfold list_union, rw h, simp,}\n\n@[simp] lemma list_empty_inter_eq_univ (Xs : list (set \u03b1)) : \n  Xs = list.nil \u2192 list_inter Xs = univ :=\n\u03bb h, by {unfold list_inter, rw h, simp,}\n\n@[simp] lemma list_single_union (Xs : list (set \u03b1)) :\n  Xs.length = 1 \u2192 list_union Xs = Xs.head := \nbegin\n  intro h, unfold list_union, rw list.eq_cons_of_length_one h, \n  ext, simp, \nend\n\n@[simp] lemma list_single_inter (Xs : list (set \u03b1)) :\n  Xs.length = 1 \u2192 list_inter Xs = Xs.head := \nbegin\n  intro h, unfold list_inter, rw list.eq_cons_of_length_one h, \n  ext, simp, \nend\n\n@[simp] lemma list_union_cons (Xs: list (set \u03b1)) (Y : set \u03b1) :\n  list_union (Y :: Xs) = Y \u222a list_union Xs := \nbegin\n  unfold list_union, ext, \n  simp_rw[set.mem_union, set.mem_Union], \n  simp only [exists_prop, list.mem_cons_iff],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9; finish, \nend\n\n@[simp] lemma list_inter_cons (Xs: list (set \u03b1)) (Y : set \u03b1) :\n  list_inter (Y :: Xs) = Y \u2229 list_inter Xs := \nbegin\n  unfold list_inter, ext, \n  simp_rw [set.mem_inter_iff, set.mem_Inter], \n  simp only [exists_prop, list.mem_cons_iff],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9; finish, \nend\n\n\nnamespace seq\n\n@[simp] lemma fin_zero_Union (Xs : fin 0 \u2192 set \u03b1) : \nset.Union Xs = \u2205  := \nby {rw [set.Union_eq_empty], exact \u03bb i, fin_zero_elim i}\n\n@[simp] lemma fin_zero_Inter (Xs : fin 0 \u2192 set \u03b1) : \nset.Inter Xs = univ  := \nby {rw [set.Inter_eq_univ], exact \u03bb i, fin_zero_elim i}\n\n\nlemma Union_cons {n : \u2115} (Xs : fin n \u2192 set \u03b1) (Y : set \u03b1) :\nset.Union (fin.cons Y Xs) = set.Union Xs \u222a Y  :=\nbegin\n  ext, rw [iff.comm, set.mem_union, set.mem_Union, set.mem_Union],   \n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9, \n  rcases h with (\u27e8i, hi\u27e9 | h), \n    {use fin.succ i, simp [hi]},\n    {use 0, convert h,},\n  cases h with i hi, \n  revert i, refine \u03bb i, fin.cases (\u03bb h, _) (\u03bb i\u2080 h, _) i,\n    {right, convert h,}, \n  left, use i\u2080, \n  convert h, simp, \nend\n\nlemma Inter_cons {n : \u2115} (Xs : fin n \u2192 set \u03b1) (Y : set \u03b1) :\nset.Inter (fin.cons Y Xs) = set.Inter Xs \u2229 Y  :=\nbegin\n  ext, rw [iff.comm, set.mem_inter_iff, set.mem_Inter, set.mem_Inter],   \n  refine \u27e8\u03bb h, \u03bb i, _, \u03bb h, \u27e8\u03bb i, _, _\u27e9\u27e9, \n    {revert i, refine \u03bb i, fin.cases (by convert h.2) (\u03bb i\u2080, _) i, convert h.1 i\u2080, simp,  },\n    {convert h (i.succ), simp,},\n  convert h 0, \nend\n\nend seq\n\n\n\nnamespace list\n\nlemma nil_of_unzip_nil_left {\u03b1 \u03b2 : Type*} (L : list (\u03b1 \u00d7 \u03b2)) : \n  L.unzip.1 = list.nil \u2192 L = list.nil := \n\u03bb h, by {rw [\u2190L.zip_unzip, h], simp only [zip_nil_left]} \n\nlemma nil_of_unzip_nil_right {\u03b1 \u03b2 : Type*} (L : list (\u03b1 \u00d7 \u03b2)) : \n  L.unzip.2 = list.nil \u2192 L = list.nil := \n\u03bb h, by {rw [\u2190L.zip_unzip, h], simp only [zip_nil_right]} \n\n\nend list \n\n\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_aux/prelim/setlist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8333245994514082, "lm_q1q2_score": 0.7431680870182713}}
{"text": "/-\nCopyright (c) 2021 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport topology.stone_cech\nimport topology.algebra.semigroup\nimport data.stream.init\n\n/-!\n# Hindman's theorem on finite sums\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe prove Hindman's theorem on finite sums, using idempotent ultrafilters.\n\nGiven an infinite sequence `a\u2080, a\u2081, a\u2082, \u2026` of positive integers, the set `FS(a\u2080, \u2026)` is the set\nof positive integers that can be expressed as a finite sum of `a\u1d62`'s, without repetition. Hindman's\ntheorem asserts that whenever the positive integers are finitely colored, there exists a sequence\n`a\u2080, a\u2081, a\u2082, \u2026` such that `FS(a\u2080, \u2026)` is monochromatic. There is also a stronger version, saying\nthat whenever a set of the form `FS(a\u2080, \u2026)` is finitely colored, there exists a sequence\n`b\u2080, b\u2081, b\u2082, \u2026` such that `FS(b\u2080, \u2026)` is monochromatic and contained in `FS(a\u2080, \u2026)`. We prove both\nthese versions for a general semigroup `M` instead of `\u2115+` since it is no harder, although this\nspecial case implies the general case.\n\nThe idea of the proof is to extend the addition `(+) : M \u2192 M \u2192 M` to addition `(+) : \u03b2M \u2192 \u03b2M \u2192 \u03b2M`\non the space `\u03b2M` of ultrafilters on `M`. One can prove that if `U` is an _idempotent_ ultrafilter,\ni.e. `U + U = U`, then any `U`-large subset of `M` contains some set `FS(a\u2080, \u2026)` (see\n`exists_FS_of_large`). And with the help of a general topological argument one can show that any set\nof the form `FS(a\u2080, \u2026)` is `U`-large according to some idempotent ultrafilter `U` (see\n`exists_idempotent_ultrafilter_le_FS`). This is enough to prove the theorem since in any finite\npartition of a `U`-large set, one of the parts is `U`-large.\n\n## Main results\n\n- `FS_partition_regular`: the strong form of Hindman's theorem\n- `exists_FS_of_finite_cover`: the weak form of Hindman's theorem\n\n## Tags\n\nRamsey theory, ultrafilter\n\n-/\n\nopen filter\n\n/-- Multiplication of ultrafilters given by `\u2200\u1da0 m in U*V, p m \u2194 \u2200\u1da0 m in U, \u2200\u1da0 m' in V, p (m*m')`. -/\n@[to_additive \"Addition of ultrafilters given by\n`\u2200\u1da0 m in U+V, p m \u2194 \u2200\u1da0 m in U, \u2200\u1da0 m' in V, p (m+m')`.\" ]\ndef ultrafilter.has_mul {M} [has_mul M] : has_mul (ultrafilter M) :=\n{ mul := \u03bb U V, (*) <$> U <*> V }\n\nlocal attribute [instance] ultrafilter.has_mul ultrafilter.has_add\n\n/- We could have taken this as the definition of `U * V`, but then we would have to prove that it\ndefines an ultrafilter. -/\n@[to_additive]\nlemma ultrafilter.eventually_mul {M} [has_mul M] (U V : ultrafilter M) (p : M \u2192 Prop) :\n  (\u2200\u1da0 m in \u2191(U * V), p m) \u2194 \u2200\u1da0 m in U, \u2200\u1da0 m' in V, p (m * m') := iff.rfl\n\n/-- Semigroup structure on `ultrafilter M` induced by a semigroup structure on `M`. -/\n@[to_additive \"Additive semigroup structure on `ultrafilter M` induced by an additive semigroup\nstructure on `M`.\"]\ndef ultrafilter.semigroup {M} [semigroup M] : semigroup (ultrafilter M) :=\n{ mul_assoc := \u03bb U V W, ultrafilter.coe_inj.mp $ filter.ext' $ \u03bb p,\n    by simp only [ultrafilter.eventually_mul, mul_assoc]\n  ..ultrafilter.has_mul }\n\nlocal attribute [instance] ultrafilter.semigroup ultrafilter.add_semigroup\n\n/- We don't prove `continuous_mul_right`, because in general it is false! -/\n@[to_additive]\nlemma ultrafilter.continuous_mul_left {M} [semigroup M] (V : ultrafilter M) : continuous (* V) :=\ntopological_space.is_topological_basis.continuous ultrafilter_basis_is_basis _ $\nset.forall_range_iff.mpr $ \u03bb s, ultrafilter_is_open_basic { m : M | \u2200\u1da0 m' in V, m * m' \u2208 s }\n\nnamespace hindman\n\n/-- `FS a` is the set of finite sums in `a`, i.e. `m \u2208 FS a` if `m` is the sum of a nonempty\nsubsequence of `a`. We give a direct inductive definition instead of talking about subsequences. -/\ninductive FS {M} [add_semigroup M] : stream M \u2192 set M\n| head (a : stream M) : FS a a.head\n| tail (a : stream M) (m : M) (h : FS a.tail m) : FS a m\n| cons (a : stream M) (m : M) (h : FS a.tail m) : FS a (a.head + m)\n\n/-- `FP a` is the set of finite products in `a`, i.e. `m \u2208 FP a` if `m` is the product of a nonempty\nsubsequence of `a`. We give a direct inductive definition instead of talking about subsequences. -/\n@[to_additive FS]\ninductive FP {M} [semigroup M] : stream M \u2192 set M\n| head (a : stream M) : FP a a.head\n| tail (a : stream M) (m : M) (h : FP a.tail m) : FP a m\n| cons (a : stream M) (m : M) (h : FP a.tail m) : FP a (a.head * m)\n\n/-- If `m` and `m'` are finite products in `M`, then so is `m * m'`, provided that `m'` is obtained\nfrom a subsequence of `M` starting sufficiently late. -/\n@[to_additive \"If `m` and `m'` are finite sums in `M`, then so is `m + m'`, provided that `m'`\nis obtained from a subsequence of `M` starting sufficiently late.\"]\nlemma FP.mul {M} [semigroup M] {a : stream M} {m : M} (hm : m \u2208 FP a) :\n  \u2203 n, \u2200 m' \u2208 FP (a.drop n), m * m' \u2208 FP a :=\nbegin\n  induction hm with a a m hm ih a m hm ih,\n  { exact \u27e81, \u03bb m hm, FP.cons a m hm\u27e9, },\n  { cases ih with n hn, use n+1, intros m' hm', exact FP.tail _ _ (hn _ hm'), },\n  { cases ih with n hn, use n+1, intros m' hm', rw mul_assoc, exact FP.cons _ _ (hn _ hm'), },\nend\n\n@[to_additive exists_idempotent_ultrafilter_le_FS]\nlemma exists_idempotent_ultrafilter_le_FP {M} [semigroup M] (a : stream M) :\n  \u2203 U : ultrafilter M, U * U = U \u2227 \u2200\u1da0 m in U, m \u2208 FP a :=\nbegin\n  let S : set (ultrafilter M) := \u22c2 n, { U | \u2200\u1da0 m in U, m \u2208 FP (a.drop n) },\n  obtain \u27e8U, hU, U_idem\u27e9 := exists_idempotent_in_compact_subsemigroup _ S _ _ _,\n  { refine \u27e8U, U_idem, _\u27e9, convert set.mem_Inter.mp hU 0, },\n  { exact ultrafilter.continuous_mul_left },\n  { apply is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed,\n    { intros n U hU,\n      apply eventually.mono hU,\n      rw [add_comm, \u2190stream.drop_drop, \u2190stream.tail_eq_drop],\n      exact FP.tail _ },\n    { intro n, exact \u27e8pure _, mem_pure.mpr $ FP.head _\u27e9, },\n    { exact (ultrafilter_is_closed_basic _).is_compact, },\n    { intro n, apply ultrafilter_is_closed_basic, }, },\n  { exact is_closed.is_compact (is_closed_Inter $ \u03bb i, ultrafilter_is_closed_basic _) },\n  { intros U hU V hV,\n    rw set.mem_Inter at *,\n    intro n,\n    rw [set.mem_set_of_eq, ultrafilter.eventually_mul],\n    apply eventually.mono (hU n),\n    intros m hm,\n    obtain \u27e8n', hn\u27e9 := FP.mul hm,\n    apply eventually.mono (hV (n' + n)),\n    intros m' hm',\n    apply hn,\n    simpa only [stream.drop_drop] using hm', }\nend\n\n@[to_additive exists_FS_of_large]\nlemma exists_FP_of_large {M} [semigroup M] (U : ultrafilter M) (U_idem : U * U = U)\n  (s\u2080 : set M) (sU : s\u2080 \u2208 U) : \u2203 a, FP a \u2286 s\u2080 :=\nbegin\n/- Informally: given a `U`-large set `s\u2080`, the set `s\u2080 \u2229 { m | \u2200\u1da0 m' in U, m * m' \u2208 s\u2080 }` is also\n`U`-large (since `U` is idempotent). Thus in particular there is an `a\u2080` in this intersection. Now\nlet `s\u2081` be the intersection `s\u2080 \u2229 { m | a\u2080 * m \u2208 s\u2080 }`. By choice of `a\u2080`, this is again `U`-large,\nso we can repeat the argument starting from `s\u2081`, obtaining `a\u2081`, `s\u2082`, etc. This gives the desired\ninfinite sequence. -/\n  have exists_elem : \u2200 {s : set M} (hs : s \u2208 U), (s \u2229 { m | \u2200\u1da0 m' in U, m * m' \u2208 s }).nonempty :=\n    \u03bb s hs, ultrafilter.nonempty_of_mem (inter_mem hs $ by { rw \u2190U_idem at hs, exact hs }),\n  let elem : { s // s \u2208 U } \u2192 M := \u03bb p, (exists_elem p.property).some,\n  let succ : { s // s \u2208 U } \u2192 { s // s \u2208 U } := \u03bb p, \u27e8p.val \u2229 { m | elem p * m \u2208 p.val },\n    inter_mem p.2 $ show _, from set.inter_subset_right _ _ (exists_elem p.2).some_mem\u27e9,\n  use stream.corec elem succ (subtype.mk s\u2080 sU),\n  suffices : \u2200 (a : stream M) (m \u2208 FP a), \u2200 p, a = stream.corec elem succ p \u2192 m \u2208 p.val,\n  { intros m hm, exact this _ m hm \u27e8s\u2080, sU\u27e9 rfl, },\n  clear sU s\u2080,\n  intros a m h,\n  induction h with b b n h ih b n h ih,\n  { rintros p rfl,\n    rw [stream.corec_eq, stream.head_cons],\n    exact set.inter_subset_left _ _ (set.nonempty.some_mem _), },\n  { rintros p rfl,\n    refine set.inter_subset_left _ _ (ih (succ p) _),\n    rw [stream.corec_eq, stream.tail_cons], },\n  { rintros p rfl,\n    have := set.inter_subset_right _ _ (ih (succ p) _),\n    { simpa only using this },\n    rw [stream.corec_eq, stream.tail_cons], },\nend\n\n/-- The strong form of **Hindman's theorem**: in any finite cover of an FP-set, one the parts\ncontains an FP-set. -/\n@[to_additive FS_partition_regular \"The strong form of **Hindman's theorem**: in any finite cover of\nan FS-set, one the parts contains an FS-set.\"]\nlemma FP_partition_regular {M} [semigroup M] (a : stream M) (s : set (set M)) (sfin : s.finite)\n  (scov : FP a \u2286 \u22c3\u2080 s) : \u2203 (c \u2208 s) (b : stream M), FP b \u2286 c :=\nlet \u27e8U, idem, aU\u27e9 := exists_idempotent_ultrafilter_le_FP a in\nlet \u27e8c, cs, hc\u27e9 := (ultrafilter.finite_sUnion_mem_iff sfin).mp (mem_of_superset aU scov) in\n\u27e8c, cs, exists_FP_of_large U idem c hc\u27e9\n\n/-- The weak form of **Hindman's theorem**: in any finite cover of a nonempty semigroup, one of the\nparts contains an FP-set. -/\n@[to_additive exists_FS_of_finite_cover \"The weak form of **Hindman's theorem**: in any finite cover\nof a nonempty additive semigroup, one of the parts contains an FS-set.\"]\n\n\n@[to_additive FS_iter_tail_sub_FS]\nlemma FP_drop_subset_FP {M} [semigroup M] (a : stream M) (n : \u2115) :\n  FP (a.drop n) \u2286 FP a :=\nbegin\n  induction n with n ih, { refl },\n  rw [nat.succ_eq_one_add, \u2190stream.drop_drop],\n  exact trans (FP.tail _) ih,\nend\n\n@[to_additive]\nlemma FP.singleton {M} [semigroup M] (a : stream M) (i : \u2115) : a.nth i \u2208 FP a :=\nby { induction i with i ih generalizing a, { apply FP.head }, { apply FP.tail, apply ih } }\n\n@[to_additive]\nlemma FP.mul_two {M} [semigroup M] (a : stream M) (i j : \u2115) (ij : i < j) :\n  a.nth i * a.nth j \u2208 FP a :=\nbegin\n  refine FP_drop_subset_FP _ i _,\n  rw \u2190stream.head_drop,\n  apply FP.cons,\n  rcases le_iff_exists_add.mp (nat.succ_le_of_lt ij) with \u27e8d, hd\u27e9,\n  have := FP.singleton (a.drop i).tail d,\n  rw [stream.tail_eq_drop, stream.nth_drop, stream.nth_drop] at this,\n  convert this,\n  rw [hd, add_comm, nat.succ_add, nat.add_succ],\nend\n\n@[to_additive]\nlemma FP.finset_prod {M} [comm_monoid M] (a : stream M) (s : finset \u2115) (hs : s.nonempty) :\n  s.prod (\u03bb i, a.nth i) \u2208 FP a :=\nbegin\n  refine FP_drop_subset_FP _ (s.min' hs) _,\n  induction s using finset.strong_induction with s ih,\n  rw [\u2190finset.mul_prod_erase _ _ (s.min'_mem hs), \u2190stream.head_drop],\n  cases (s.erase (s.min' hs)).eq_empty_or_nonempty with h h,\n  { rw [h, finset.prod_empty, mul_one], exact FP.head _ },\n  { apply FP.cons, rw [stream.tail_eq_drop, stream.drop_drop, add_comm],\n    refine set.mem_of_subset_of_mem _ (ih _ (finset.erase_ssubset $ s.min'_mem hs) h),\n    have : s.min' hs + 1 \u2264 (s.erase (s.min' hs)).min' h :=\n      nat.succ_le_of_lt (finset.min'_lt_of_mem_erase_min' _ _ $ finset.min'_mem _ _),\n    cases le_iff_exists_add.mp this with d hd,\n    rw [hd, add_comm, \u2190stream.drop_drop],\n    apply FP_drop_subset_FP }\nend\n\nend hindman\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/hindman.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110483133801, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7431680864678627}}
{"text": "-- 1\nsection\n  variable A : Type\n  variable f : A \u2192 A\n  variable P : A \u2192 Prop\n  variable h : \u2200x, P x \u2192 P (f x)\n\n  example : \u2200y, P y \u2192 P (f (f y)) :=\n\n  assume y : A,\n  assume h0: P y,\n  have h1: (P y \u2192 P (f y)), from h y,\n  have h2: P (f y), from h1 h0,\n  have h3: P (f y) \u2192 P (f (f y)), from h (f y),\n  show P (f (f y)), from h3 h2\nend\n\n-- 2\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2200x, A x \u2227 B x) \u2192 \u2200x, A x :=\n  assume h : (\u2200x, A x \u2227 B x),\n  assume y,\n  have h1: A y \u2227 B y, from h y,\n  show A y, from and.left h1\nend\n\n-- 3\nsection\n  variable U : Type\n  variables A B C : U \u2192 Prop\n\n  variable h1 : \u2200x, A x \u2228 B x\n  variable h2 : \u2200x, A x \u2192 C x\n  variable h3 : \u2200x, B x \u2192 C x\n\n  example : \u2200x, C x :=\n  assume y : U,\n\n  have h0: A y \u2228 B y, from h1 y,\n\n  or.elim h0\n  ( \n    assume Ay,\n    have ha: A y \u2192 C y, from h2 y,\n    have hb: C y, from ha Ay,\n    show C y, from hb\n  )\n  (\n    assume By,\n    have ha: B y \u2192 C y, from h3 y,\n    have hb: C y, from ha By,\n    show C y, from hb\n  )\nend\n\n-- 4\nopen classical\n\naxiom not_iff_not_self (P : Prop) : \u00ac(P \u2194 \u00acP)\n\nexample (Q : Prop) : \u00ac(Q \u2194 \u00acQ) :=\nnot_iff_not_self Q\n\nsection\n  variable Person : Type\n  variable shaves : Person \u2192 Person \u2192 Prop\n  variable barber : Person\n  variable h : \u2200x, shaves barber x \u2194 \u00acshaves x x\n\n  example : false :=\n    not_iff_not_self\n    (shaves barber barber)\n    (h barber)\nend\n\n-- 5\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2203x, A x) \u2192 \u2203x, A x \u2228 B x :=\n\n  assume h1 : \u2203x, A x,\n\n  exists.elim h1\n  (\n    assume a (h0: A a),\n    have h2: A a \u2228 B a, from or.inl h0,\n    show \u2203x, A x \u2228 B x, from exists.intro a h2\n  )\nend\n\n-- 6\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  variable h1 : \u2200x, A x \u2192 B x\n  variable h2 : \u2203x, A x\n\n  example : \u2203x, B x :=\n  \n  exists.elim h2\n  (\n    assume y (h3: A y),\n    have h0: A y \u2192 B y, from h1 y,\n    have h4: B y, from h0 h3,\n    show \u2203x, B x, from exists.intro y h4\n  )\nend\n\n-- 7\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example (h1 : \u2203x, A x \u2227 B x) (h2 : \u2200x, B x \u2192 C x) :\n      \u2203x, A x \u2227 C x :=\n\n  exists.elim h1\n  (\n  assume a (h0 : A a \u2227 B a),\n  have ha : B a, from h0.right,\n  have hb : B a \u2192 C a, from h2 a,\n  have hc : C a, from hb ha,\n  have hd : A a, from and.left h0,\n  have he : A a \u2227 C a, from and.intro hd hc,\n  show \u2203x, A x \u2227 C x, from exists.intro a he\n  )\nend\n\n-- 8\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example : (\u00ac\u2203x, A x) \u2192 \u2200x, \u00acA x :=\n  \n  assume h1 : \u00ac \u2203 x, A x,\n\n  assume y : U,\n  assume h2 : A y,\n\n  have h2 : \u2203 x, A x, from exists.intro y h2,\n\n  show false, from h1 h2\nend\n\n-- 9\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example : (\u2200x, \u00acA x) \u2192 \u00ac\u2203x, A x :=\n\n  assume h01: \u2200x, \u00acA x,\n\n  show \u00ac\u2203x, A x, from not.intro\n  (\n    assume h1: \u2203x, A x,\n\n    exists.elim h1\n    (\n      assume y (h2: A y),\n      have h3: \u00acA y, from h01 y,\n      show false, from h3 h2\n    )\n  )\nend\n\n-- 10\nsection\n  variable  U : Type\n  variables R : U \u2192 U \u2192 Prop\n\n  example : (\u2203x, \u2200y, R x y) \u2192 \u2200y, \u2203x, R x y :=\n  \n  assume h1: \u2203x, \u2200y, R x y,\n  \n  show \u2200y, \u2203x, R x y, from \n    exists.elim h1 \n    (\n      assume x (h2:(\u2200y, R x y)),\n      assume y : U,\n      \n      have h3: (R x y), from h2 y,\n    \n      exists.intro x h3\n    )\nend\n", "meta": {"author": "ju211256", "repo": "CS205", "sha": "3bf7e3f8d51dff3f51fac07eb0dba377703ee587", "save_path": "github-repos/lean/ju211256-CS205", "path": "github-repos/lean/ju211256-CS205/CS205-3bf7e3f8d51dff3f51fac07eb0dba377703ee587/LEAN/hw2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7431680774335373}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nGiven a poset `P`, we define `subdiv P` to be the poset of \nfinite nonempty chains `s \u2286 P`.  Any such `s` has a largest \nelement, and the map `max : (subdiv P) \u2192 P` is a morphism \nof posets.  There is an approach to the homotopy theory of\nfinite complexes based on finite posets, and the above map\n`max` plays a key role in this. \n-/\n\nimport data.list.sort\nimport basic sort_rank\n\nuniverses uP uQ uR uS\n\nvariables (P : Type uP) [partial_order P] [decidable_eq P]\nvariables (Q : Type uQ) [partial_order Q] [decidable_eq Q]\nvariables (R : Type uR) [partial_order R] [decidable_eq R]\nvariables (S : Type uS) [partial_order S] [decidable_eq S]\n\nvariable [decidable_rel (has_le.le : P \u2192 P \u2192 Prop)]\nvariable [decidable_rel (has_le.le : Q \u2192 Q \u2192 Prop)]\nvariable [decidable_rel (has_le.le : R \u2192 R \u2192 Prop)]\nvariable [decidable_rel (has_le.le : S \u2192 S \u2192 Prop)]\n\nnamespace poset \nopen poset\n\nvariable {P}\n\n/-- Definition of chains \n  LaTeX: defn-subdiv\n-/\ndef is_chain (s : finset P) : Prop := \n \u2200 (p \u2208 s) (q \u2208 s), (p \u2264 q \u2228 q \u2264 p)\n\ninstance decidable_is_chain (s : finset P) : decidable (is_chain s) := \nby { unfold is_chain, apply_instance }\n\n/-- Definition of simplices as nonempty chains \n  LaTeX: defn-subdiv\n-/\ndef is_simplex (s : finset P) : Prop := s \u2260 \u2205 \u2227 (is_chain s)\n\ninstance decidable_is_simplex (s : finset P) : decidable (is_simplex s) := \nby { unfold is_simplex, apply_instance }\n\nvariable (P)\n\n/-- Definition of subdiv P as a type \n  LaTeX: defn-subdiv\n-/\ndef subdiv := {s : finset P // is_simplex s}\n\n/-- Vertices as 0-simplices -/\nvariable {P}\ndef vertex (p : P) : subdiv P := \u27e8 \nfinset.singleton p,\nbegin\n  split,\n  {exact finset.ne_empty_of_mem (finset.mem_singleton_self p)},\n  {intros x hx y hy,\n   rw [finset.mem_singleton.mp hx, finset.mem_singleton.mp hy],\n   left, exact le_refl p }\nend\u27e9 \nvariable (P)\n\nnamespace subdiv\n\ninstance : decidable_eq (subdiv P) := \n  by { unfold subdiv, apply_instance }\n\n/-- Definition of the partial order on subdiv P \n  LaTeX: defn-subdiv\n-/\ninstance : partial_order (subdiv P) := \n{ le := \u03bb s t, s.val \u2286 t.val,\n  le_refl := \u03bb s, (le_refl s.val),\n  le_antisymm := \u03bb s t hst hts, subtype.eq (le_antisymm hst hts),\n  le_trans := \u03bb s t u (hst : s.val \u2286 t.val) (htu : t.val \u2286 u.val) p hs, \n                (htu (hst hs)) }\n\ninstance decidable_le : decidable_rel\n (has_le.le : (subdiv P) \u2192 (subdiv P) \u2192 Prop) := \n  \u03bb s t, by { apply_instance }\n\nvariable {P}\n\n/-- Definition of the dimension of a simplex, as one less than \n  the cardinality.  We use the predecessor operation on \n  natural numbers, which sends zero to zero.  Because of this,\n  we need a small argument to show that the cardinality is \n  strictly positive and thus equal to one more than the dimension.\n\n  LaTeX: defn-subdiv\n-/\ndef dim (s : subdiv P) : \u2115 := s.val.card.pred\n\nlemma card_eq (s : subdiv P) : s.val.card = s.dim.succ := \nbegin \n  by_cases h : s.val.card = 0,\n  { exact (s.property.left (finset.card_eq_zero.mp h)).elim },\n  { replace h := nat.pos_of_ne_zero h,\n    exact (nat.succ_pred_eq_of_pos h).symm }\nend\n\n/-- The dimension function dim : subdiv P \u2192 \u2115 is monotone. -/\nlemma dim_mono : monotone (dim : (subdiv P) \u2192 \u2115) := \nbegin\n  intros s t hst,\n  let h := finset.card_le_of_subset hst,\n  rw[card_eq,card_eq] at h,\n  exact nat.le_of_succ_le_succ h\nend\n\n/-- If we have simplices s \u2264 t with dim s \u2265 dim t then s = t. -/\nlemma eq_of_le_of_dim_ge (s t : subdiv P)\n (hst : s \u2264 t) (hd : s.dim \u2265 t.dim) : s = t := \nbegin\n  let hc := nat.succ_le_succ hd,\n  rw [\u2190 card_eq, \u2190 card_eq] at hc,\n  exact subtype.eq (finset.eq_of_subset_of_card_le hst hc)\nend\n\n/-- This allows us to treat a simplex as a type in its own right. -/\ninstance : has_coe_to_sort (subdiv P) := \n  \u27e8_,\u03bb s, {p : P // p \u2208 s.val}\u27e9\n\nsection els\n\nvariable (s : subdiv P)\n\ninstance els_decidable_eq : decidable_eq s := by { apply_instance }\ninstance els_fintype : fintype s           := by { apply_instance }\n\nlemma card_eq' : fintype.card s = s.dim.succ := \n (fintype.card_coe s.val).trans s.card_eq\n\n/-- If s is a simplex, we can treat it as a linearly ordered set. -/\ninstance els_order : decidable_linear_order s := \n{ le := \u03bb p q,p.val \u2264 q.val,\n  le_refl := \u03bb p, ((le_refl (p.val : P)) : p.val \u2264 p.val),\n  le_antisymm := \u03bb p q (hpq : p.val \u2264 q.val) (hqp : q.val \u2264 p.val),\n                 subtype.eq (le_antisymm hpq hqp),\n  le_trans := \u03bb p q r (hpq : p.val \u2264 q.val) (hqr : q.val \u2264 r.val), \n                 le_trans hpq hqr,\n  le_total := \u03bb p q,s.property.right p.val p.property q.val q.property,\n  lt := \u03bb p q,p.val < q.val,\n  lt_iff_le_not_le := \u03bb p q, \n  begin \n    change p.val < q.val \u2194 p.val \u2264 q.val \u2227 \u00ac q.val \u2264 p.val,\n    apply lt_iff_le_not_le, \n  end,\n  decidable_le := \u03bb p q, by { apply_instance } }\n\nvariable {s}\n\n/-- The inclusion of a simplex in the full poset P. -/\ndef inc : s \u2192 P := \u03bb p, p.val\n\n/-- The inclusion map is injective. -/\nlemma inc_inj (p\u2080 p\u2081 : s) : (inc p\u2080) = (inc p\u2081) \u2192 p\u2080 = p\u2081 := subtype.eq\n\n/-- The inclusion map is monotone. -/\nlemma inc_mono : monotone (inc : s \u2192 P) := \u03bb p\u2080 p\u2081 hp, hp\n\nvariable (s)\nvariables {d : \u2115} (e : s.dim = d)\n\n/-- If dim s = d, then we have a canonical bijection from s \n  to the set  fin d.succ = { 0,1,...,d }.  We define \n  rank_equiv s to be a package consisting of this bijection\n  and its inverse.  We define seq s and rank s to be \n  auxiliary functions defined in terms of rank_equiv s,\n  and we prove some lemmas about the behaviour of these.\n-/\n\ndef rank_equiv : s \u2243 fin d.succ := \n fintype.rank_equiv (s.card_eq'.trans (congr_arg nat.succ e))\n\ndef seq : (fin d.succ) \u2192 P := \u03bb i, inc ((rank_equiv s e).inv_fun i)\n\ndef rank (p : P) (hp : p \u2208 s.val) : fin d.succ := \n (rank_equiv s e).to_fun \u27e8p,hp\u27e9\n\nlemma seq_mem (i : fin d.succ) : seq s e i \u2208 s.val := \n  ((rank_equiv s e).inv_fun i).property\n\nlemma seq_rank (p : P) (hp : p \u2208 s.val) : \n seq s e (rank s e p hp) = p := \n  congr_arg inc ((rank_equiv s e).left_inv \u27e8p,hp\u27e9)\n\nlemma seq_eq (i : fin d.succ) :\n ((rank_equiv s e).inv_fun i) = \u27e8seq s e i,seq_mem s e i\u27e9 := \n  by { apply subtype.eq, refl }\n\nlemma rank_seq (i : fin d.succ) : \n rank s e (seq s e i) (seq_mem s e i) = i := \nbegin\n  dsimp [rank], \n  rw [\u2190 seq_eq, (rank_equiv s e).right_inv]\nend\n\nlemma seq_le (i\u2080 i\u2081 : fin d.succ) :\n i\u2080 \u2264 i\u2081 \u2194 seq s e i\u2080 \u2264 seq s e i\u2081 := \n  fintype.seq_le (s.card_eq'.trans (congr_arg nat.succ e)) i\u2080 i\u2081\n\nlemma seq_lt (i\u2080 i\u2081 : fin d.succ) :\n i\u2080 < i\u2081 \u2194 seq s e i\u2080 < seq s e i\u2081 := \n  fintype.seq_lt (s.card_eq'.trans (congr_arg nat.succ e)) i\u2080 i\u2081\n\n\nvariables {P Q}\n\ndef map (f : poset.hom P Q) : (poset.hom (subdiv P) (subdiv Q)) := \nbegin\n  let sf : subdiv P \u2192 subdiv Q := \u03bb s, \n  begin\n    let t0 : finset Q := s.val.image f.val,\n    have : is_simplex t0 := \n    begin \n      split,\n      { rcases finset.exists_mem_of_ne_empty s.property.1 \n          with \u27e8p,p_in_s\u27e9, \n        exact finset.ne_empty_of_mem\n         (finset.mem_image_of_mem f.val p_in_s) },\n      { intros q\u2080 hq\u2080 q\u2081 hq\u2081, \n        rcases finset.mem_image.mp hq\u2080 with \u27e8p\u2080,hp\u2080,hfp\u2080\u27e9,\n        rcases finset.mem_image.mp hq\u2081 with \u27e8p\u2081,hp\u2081,hfp\u2081\u27e9,\n        rw [\u2190 hfp\u2080, \u2190 hfp\u2081],\n        rcases s.property.2 p\u2080 hp\u2080 p\u2081 hp\u2081 with h\u2080\u2081 | h\u2081\u2080,\n        { left,  exact f.property h\u2080\u2081 },\n        { right, exact f.property h\u2081\u2080 } }\n    end,\n    exact \u27e8t0,this\u27e9\n  end,\n  have : monotone sf := \u03bb s\u2080 s\u2081 hs, \n  begin\n    change s\u2080.val.image f.val \u2286 s\u2081.val.image f.val, \n    intros q hq, \n    rcases finset.mem_image.mp hq with \u27e8p,hp,hfp\u27e9,\n    exact finset.mem_image.mpr \u27e8p,hs hp,hfp\u27e9\n  end,\n  exact \u27e8sf, this\u27e9\nend\n\nlemma map_val (f : poset.hom P Q) (s : subdiv P) : \n ((subdiv.map f).val s).val = s.val.image f.val := rfl\n\nsection interleave \n\nvariables [fintype P] {f g : poset.hom P Q} (hfg : f \u2264 g)\ninclude hfg\n\ndef interleave :\n \u2200 (r : fin_ranking P) (m : \u2115), hom (subdiv P) (subdiv Q) \n| \u27e8n,r,r_mono\u27e9 m := \n  \u27e8 \u03bb (\u03c3 : subdiv P), \n    \u27e8 ((\u03c3.val.filter (\u03bb p, 2 * (r p).val < m)).image f) \u222a  \n      ((\u03c3.val.filter (\u03bb p, 2 * (r p).val + 1 \u2265 m)).image g),  \n      begin \n        split,\n        { rcases finset.exists_mem_of_ne_empty \u03c3.property.1\n            with \u27e8p, p_in_\u03c3\u27e9,\n          by_cases h : 2 * (r p).val < m,\n          { apply @finset.ne_empty_of_mem Q (f p),\n            apply finset.mem_union_left,\n            apply finset.mem_image_of_mem,\n            rw [finset.mem_filter],\n            exact \u27e8p_in_\u03c3, h\u27e9 },\n          { replace h := le_trans (le_of_not_gt h) (nat.le_succ _), \n            apply @finset.ne_empty_of_mem Q (g p),\n            apply finset.mem_union_right,\n            apply finset.mem_image_of_mem,\n            rw [finset.mem_filter],\n            exact \u27e8p_in_\u03c3, h\u27e9 } },\n        { intros q\u2080 h\u2080 q\u2081 h\u2081,\n          rcases finset.mem_union.mp h\u2080 with h\u2080 | h\u2080;\n          rcases finset.mem_union.mp h\u2081 with h\u2081 | h\u2081;\n          rcases finset.mem_image.mp h\u2080 with \u27e8p\u2080,hf\u2080,he\u2080\u27e9;\n          rcases finset.mem_image.mp h\u2081 with \u27e8p\u2081,hf\u2081,he\u2081\u27e9;\n          rw [finset.mem_filter] at hf\u2080 hf\u2081; \n          rw [\u2190 he\u2080, \u2190 he\u2081];\n          let r\u2080 := (r p\u2080).val ; let r\u2081 := (r p\u2081).val ; \n          rcases \u03c3.property.right p\u2080 hf\u2080.1 p\u2081 hf\u2081.1 with hpp | hpp;\n          let hfpp := f.property hpp;\n          let hgpp := g.property hpp,\n          { left , exact hfpp },\n          { right, exact hfpp },\n          { left , exact le_trans hfpp (hfg p\u2081) },\n          { by_cases hrr : r\u2080 = r\u2081, \n            { rw [r.injective (fin.eq_of_veq hrr)],\n              left, exact hfg p\u2081 },\n            { exfalso, \n              change r\u2080 \u2260 r\u2081 at hrr,\n              replace hrr : r\u2081 < r\u2080 := lt_of_le_of_ne (r_mono hpp) hrr.symm, \n              change r\u2081 + 1 \u2264 r\u2080 at hrr,\n              have := calc\n                2 * r\u2081 + 2 = 2 * (r\u2081 + 1) : by rw [mul_add, mul_one]\n                ... \u2264 2 * r\u2080 : nat.mul_le_mul_left 2 hrr\n                ... < m : hf\u2080.2\n                ... \u2264 2 * r\u2081 + 1 : hf\u2081.2 \n                ... < 2 * r\u2081 + 2 : nat.lt_succ_self _, \n              exact lt_irrefl _ this } }, \n          { by_cases hrr : r\u2080 = r\u2081, \n            { rw [r.injective (fin.eq_of_veq hrr)],\n              right, exact hfg p\u2081 },\n            { exfalso, \n              change r\u2080 \u2260 r\u2081 at hrr,\n              replace hrr : r\u2080 < r\u2081 := lt_of_le_of_ne (r_mono hpp) hrr, \n              change r\u2080 + 1 \u2264 r\u2081 at hrr,\n              have := calc\n                2 * r\u2081 < m : hf\u2081.2 \n                ... \u2264 2 * r\u2080 + 1 : hf\u2080.2 \n                ... < 2 * r\u2080 + 2 : nat.lt_succ_self _\n                ... = 2 * (r\u2080 + 1) : by rw [mul_add, mul_one]\n                ... \u2264 2 * r\u2081 : nat.mul_le_mul_left 2 hrr,\n              exact lt_irrefl _ this } }, \n          { right, exact le_trans hfpp (hfg p\u2080) },\n          { left , exact hgpp },\n          { right, exact hgpp } }\n      end \u27e9,\n      begin \n        intros \u03c3\u2080 \u03c3\u2081 h_le q hq,\n        rw [finset.mem_union] at hq \u22a2, \n        rcases hq with hq | hq;\n        rcases finset.mem_image.mp hq with \u27e8p,hm,he\u27e9;\n        rw [\u2190 he];\n        rw [finset.mem_filter] at hm;\n        replace hm := and.intro (h_le hm.1) hm.2,\n        { left , apply finset.mem_image_of_mem, \n          rw [finset.mem_filter], exact hm },\n        { right, apply finset.mem_image_of_mem, \n          rw [finset.mem_filter], exact hm }\n      end \u27e9 \n\nlemma interleave_start :\n \u2200 (r : fin_ranking P), interleave hfg r 0 = subdiv.map g \n| \u27e8n,r,r_mono\u27e9 := \nbegin\n  ext \u03c3,\n  apply subtype.eq,\n  change _ \u222a _ = \u03c3.val.image g.val,\n  ext q,\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val < 0) = \u2205 := \n  begin\n    ext p, rw [finset.mem_filter],\n    simp [nat.not_lt_zero, finset.not_mem_empty] \n  end,\n  rw [this, finset.image_empty],\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val + 1 \u2265 0) = \u03c3.val := \n  begin\n    ext p, rw [finset.mem_filter], \n    have : _ \u2265 0 := nat.zero_le (2 * (r p).val + 1),\n    simp only [this, and_true]\n  end,\n  rw [this, finset.mem_union],\n  have : (g : P \u2192 Q) = g.val := rfl, rw [this], \n  simp [finset.not_mem_empty],\nend\n\nlemma interleave_end :\n \u2200 (r : fin_ranking P) (m : \u2115) (hm : m \u2265 2 * r.card), \n  interleave hfg r m = subdiv.map f \n| \u27e8n,r,r_mono\u27e9 m hm := \nbegin\n  change m \u2265 2 * n at hm,\n  ext \u03c3,\n  apply subtype.eq,\n  change _ \u222a _ = \u03c3.val.image f.val,\n  ext q,\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val < m) = \u03c3.val := \n  begin\n    ext p, rw [finset.mem_filter], \n    have := calc\n      2 * (r p).val < 2 * n :\n        nat.mul_lt_mul_of_pos_left (r p).is_lt (dec_trivial : 2 > 0)\n      ... \u2264 m : hm,\n    simp [this]\n  end,\n  rw [this],\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val + 1 \u2265 m) = \u2205 := \n  begin\n    ext p, rw [finset.mem_filter],\n    have := calc \n      2 * (r p).val + 1 < 2 * (r p).val + 2 : nat.lt_succ_self _\n      ... = 2 * ((r p).val + 1) : by rw [mul_add, mul_one]\n      ... \u2264 2 * n : nat.mul_le_mul_left 2 (r p).is_lt\n      ... \u2264 m : hm,\n    have : \u00ac (_ \u2265 m) := not_le_of_gt this,\n    simp only [this, finset.not_mem_empty, and_false]\n  end,\n  rw [this, finset.image_empty, finset.union_empty],\n  have : (f : P \u2192 Q) = f.val := rfl, rw [this]\nend\n\nlemma interleave_even_step : \n \u2200 (r : fin_ranking P) (k : \u2115), \n  interleave hfg r (2 * k) \u2264 interleave hfg r (2 * k + 1)\n| \u27e8n,r,r_mono\u27e9 k := \nbegin\n  intros \u03c3 q h,\n  change q \u2208 _ \u222a _ at h,\n  change q \u2208 _ \u222a _, \n  rw [finset.mem_union] at h \u22a2,  \n  rcases h with h | h;\n  rcases finset.mem_image.mp h with \u27e8p,hf,he\u27e9; \n  rw [finset.mem_filter] at hf;\n  rw [\u2190 he],\n  { left, \n    apply finset.mem_image_of_mem, \n    rw [finset.mem_filter],\n    exact \u27e8hf.1, lt_trans hf.2 (nat.lt_succ_self _)\u27e9 },\n  { right,\n    apply finset.mem_image_of_mem,\n    rw [finset.mem_filter],\n    rcases le_or_gt k (r p).val with hk | hk,\n    { exact \u27e8hf.1, nat.succ_le_succ (nat.mul_le_mul_left 2 hk)\u27e9 },\n    { exfalso, \n      have := calc\n        2 * (r p).val + 2 = 2 * ((r p).val + 1) : by rw [mul_add, mul_one]\n        ... \u2264 2 * k : nat.mul_le_mul_left 2 hk\n        ... \u2264 2 * (r p).val + 1 : hf.2\n        ... < 2 * (r p).val + 2 : nat.lt_succ_self _,\n      exact lt_irrefl _ this } }\nend\n\nlemma interleave_odd_step : \n \u2200 (r : fin_ranking P) (k : \u2115), \n  interleave hfg r (2 * k + 2) \u2264 interleave hfg r (2 * k + 1)\n| \u27e8n,r,r_mono\u27e9 k := \nbegin\n  intros \u03c3 q h,\n  change q \u2208 _ \u222a _ at h,\n  change q \u2208 _ \u222a _, \n  rw [finset.mem_union] at h \u22a2,  \n  rcases h with h | h;\n  rcases finset.mem_image.mp h with \u27e8p,hf,he\u27e9; \n  rw [finset.mem_filter] at hf;\n  rw [\u2190 he],\n  { left, \n    apply finset.mem_image_of_mem, \n    rw [finset.mem_filter],\n    rcases le_or_gt (r p).val k with hk | hk,\n    { have := calc\n       2 * (r p).val \u2264 2 * k : nat.mul_le_mul_left 2 hk\n       ... < 2 * k + 1 : nat.lt_succ_self _,\n      exact \u27e8hf.1, this\u27e9 },\n    { exfalso, \n      have := calc\n        2 * k + 2 = 2 * (k + 1) : by rw [mul_add, mul_one]\n        ... \u2264 2 * (r p).val : nat.mul_le_mul_left 2 hk\n        ... < 2 * k + 2 : hf.2,\n      exact lt_irrefl _ this } },\n  { right,\n    apply finset.mem_image_of_mem,\n    rw [finset.mem_filter],\n    exact \u27e8hf.1, le_trans (le_of_lt (nat.lt_succ_self (2 * k + 1))) hf.2\u27e9 }\nend\n\nlemma interleave_component (r : fin_ranking P) (m : \u2115) : \n  component (interleave hfg r m) = component (interleave hfg r 0) := \nzigzag (interleave hfg r) \n  (interleave_even_step hfg r)\n  (interleave_odd_step hfg r) m\n\nend interleave \n\ndef subdiv.map\u2095 [fintype P] :\n  \u03c0\u2080 (hom P Q) \u2192 \u03c0\u2080 (hom (subdiv P) (subdiv Q)) := \n\u03c0\u2080.lift (\u03bb f, component (subdiv.map f))\nbegin\n  intros f g hfg,\n  rcases exists_fin_ranking P with \u27e8r\u27e9,\n  let n := r.card,\n  let c := interleave hfg r,\n  have : c 0 = subdiv.map g := interleave_start hfg r,\n  rw [\u2190 this],\n  have : c (2 * n) = subdiv.map f := interleave_end hfg r (2 * n) (le_refl _),\n  rw [\u2190 this],\n  apply interleave_component\nend\n\n/-- For a simplex s, we define max s to be the largest element. -/\n\ndef max\u2080 : P := seq s rfl (fin.last s.dim)\n\nlemma max\u2080_mem : s.max\u2080 \u2208 s.val := seq_mem s rfl (fin.last s.dim)\n\nlemma le_max\u2080 (p : P) (hp : p \u2208 s.val) : p \u2264 s.max\u2080 := \nbegin\n  rw [\u2190 seq_rank s rfl p hp],\n  apply (seq_le s rfl (rank s rfl p hp) (fin.last s.dim)).mp,\n  apply fin.le_last\nend\n\nend els\n\n/-- The function max : subdiv P \u2192 P is monotone. -/\nlemma max\u2080_mono : monotone (max\u2080 : subdiv P \u2192 P) := \n  \u03bb s t hst, t.le_max\u2080 s.max\u2080 (hst s.max\u2080_mem)\n\nvariable (P)\n\ndef max : hom (subdiv P) P := \u27e8max\u2080,max\u2080_mono\u27e9\n\nlemma max_mem (s : subdiv P) : max P s \u2208 s.val := max\u2080_mem s\n\nlemma le_max (s : subdiv P) (p : P) (hp : p \u2208 s.val) : p \u2264 max P s := \nle_max\u2080 s p hp\n\nlemma max_cofinal : cofinal\u2095 (max P) := \nbegin\n  intro p,\n  let C := comma (max P) p,\n  let c : C := \u27e8vertex p,le_refl _\u27e9, \n  let T := punit.{uP + 1},\n  let f : hom C T := const C punit.star, \n  let g : hom T C := const T c,\n  have hfg : comp f g = id T := \n  by { ext t, rcases t, refl },\n  let m\u2080 : C \u2192 C := \u03bb x, \n  begin\n    let \u03c4\u2080 := x.val.val \u222a finset.singleton p,\n    have h\u2080 : \u03c4\u2080 \u2260 \u2205 := \n      finset.ne_empty_of_mem\n       (finset.mem_union_right _ (finset.mem_singleton_self p)),\n    have h\u2081 : is_chain \u03c4\u2080 := \u03bb a ha b hb, \n    begin\n      rcases finset.mem_union.mp ha with hax | hap;\n      rcases finset.mem_union.mp hb with hbx | hbp,\n      { exact x.val.property.2 a hax b hbx },\n      { left, \n        rw [finset.mem_singleton.mp hbp],\n        exact le_trans (le_max P x.val a hax) x.property },\n      { right,\n        rw [finset.mem_singleton.mp hap],\n        exact le_trans (le_max P x.val b hbx) x.property },\n      { left, \n        rw [finset.mem_singleton.mp hbp],\n        rw [finset.mem_singleton.mp hap] }\n    end,\n    let \u03c4 : subdiv P := \u27e8\u03c4\u2080,\u27e8h\u2080,h\u2081\u27e9\u27e9,\n    have h\u2082 : max P \u03c4 \u2264 p := \n    begin\n      rcases finset.mem_union.mp (max_mem P \u03c4) with h | h,\n      { exact le_trans (le_max P x.val _ h) x.property },\n      { rw [finset.mem_singleton.mp h] } \n    end,\n    exact \u27e8\u03c4,h\u2082\u27e9\n  end,\n  have m\u2080_mono : monotone m\u2080 := \u03bb x\u2080 x\u2081 h,\n  begin\n    change x\u2080.val.val \u2286 x\u2081.val.val at h,\n    change x\u2080.val.val \u222a finset.singleton p \u2286 x\u2081.val.val \u222a finset.singleton p,\n    intros a ha,\n    rcases finset.mem_union.mp ha with hax | hap,\n    { exact finset.mem_union_left _ (h hax) },\n    { exact finset.mem_union_right _ hap }\n  end,\n  let m : hom C C := \u27e8m\u2080,m\u2080_mono\u27e9,\n  have hm\u2080 : comp g f \u2264 m := \u03bb x a ha, \n  begin\n    change a \u2208 finset.singleton p at ha,\n    change a \u2208 x.val.val \u222a finset.singleton p,\n    exact finset.mem_union_right _ ha\n  end,\n  have hm\u2081 : id C \u2264 m := \u03bb x a ha,\n  begin\n    change a \u2208 x.val.val at ha,\n    change a \u2208 x.val.val \u222a finset.singleton p,\n    exact finset.mem_union_left _ ha\n  end,\n  let hgf := (\u03c0\u2080.sound hm\u2080).trans (\u03c0\u2080.sound hm\u2081).symm,\n  have e : equiv\u2095 C T := \n  { to_fun := component f,\n    inv_fun := component g,\n    left_inv := hgf,\n    right_inv := congr_arg component hfg },\n  exact \u27e8e\u27e9 \nend\n\nend subdiv\n\nend poset", "meta": {"author": "NeilStrickland", "repo": "itloc", "sha": "5b13b5b418766d10926b983eb3dd2ac42abf63d8", "save_path": "github-repos/lean/NeilStrickland-itloc", "path": "github-repos/lean/NeilStrickland-itloc/itloc-5b13b5b418766d10926b983eb3dd2ac42abf63d8/src/subdiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7431680706008476}}
{"text": "/-\n# Formalising IUM 2021 in Lean (unofficial version)\n\nThings about the logical foundations of Lean are skipped here...\n(I just assumed the basic knowledge of \"universes\", \"\u03a0 types\", \"inductive types\" and their \"recursors\",\n also you need to know about how the logical connectives, the naturals and equality are defined in Lean...)\n(For them you may want to read *Theorem Proving in Lean*:\n https://leanprover.github.io/theorem_proving_in_lean/\n I also made some notes about that...)\n-/\n\nimport tactic\n\nuniverse u\n\n--------------------------------------------------------------------------------\n-- ## Using sets in Lean\n\nnamespace using_sets_in_lean\n\n#print set\n/-\nIn Lean, the `set` is a \"type constructor\":\n  `def set : Type u \u2192 Type u :=`\n  `  \u03bb (\u03b1 : Type u), \u03b1 \u2192 Prop`\n\"A set on a type \u03b1\" (`set \u03b1`) is just the type `\u03b1 \u2192 Prop`!\n\nNote that:\n1. This is a function type, which contains all \"predicates on `\u03b1`\"\n    (i.e. function that receives an element of `\u03b1` and returns a `Prop`).\n2. This function type lives in the same universe as `\u03b1`.\n-/\n\n#check set \u2115\n#reduce set \u2115 -- `set \u2115` and `\u2115 \u2192 Prop` are the same (definitionally equal)!\n\n-- This is the set {0, 1, 12}.\ndef some_subset : set \u2115 := \u03bb n, n = 0 \u2228 n = 1 \u2228 n = 12\n-- You can also define it as:\n-- `def some_subset : \u2115 \u2192 Prop := \u03bb n, n = 0 \u2228 n = 1 \u2228 n = 12`\n\n#print notation \u2208\n#print set.mem\n/-\nThe `mem` is defined as:\n  `def set.mem : \u03a0 {\u03b1 : Type u} (a : \u03b1) (s : set \u03b1), Prop :=`\n    `\u03bb \u03b1 a s, s a`\nwhich is just a function that \"takes an implicit `\u03b1 : Type`,\n  an element of `a`, and a \"set\" `s` on `\u03b1` (i.e. `s : \u03b1 \u2192 Prop`),\n  and returns the proposition obtained by putting `a` into the predicate `s`.\"\n  (i.e. it is just an application of the predicate `s` on `a`!)\n-/\n\n#check (set.mem 4 some_subset) -- `Prop`\n#check (4 \u2208 some_subset) -- An alternative notation for the above line\n#check (some_subset 4) -- An alternative notation for the above line!\n\n#reduce (4 \u2208 some_subset) -- `4 = 0 \u2228 4 = 1 \u2228 4 = 12`\n\n-- Let's prove that 1 \u2208 {0, 1, 12}...\nlemma l1 : (1 \u2208 some_subset) :=\nbegin\n  unfold some_subset,\n  right, left, refl,\nend\n-- (Term mode version)\nexample : (1 \u2208 some_subset) := or.inr (or.inl rfl)\n\n-- Now prove that 4 \u2209 {0, 1, 12}...\nexample : (4 \u2209 some_subset) :=\nbegin\n  intros h,\n  unfold some_subset at h,\n  cases h with h\u2081 h\u2082,\n  { injection h\u2081 },\n  { cases h\u2082 with h\u2082 h\u2083,\n    { injections },\n    { injections }}\nend\n-- (Term mode version)\nexample : (4 \u2209 some_subset) :=\n  (\u03bb h : (some_subset 4), h.elim\n    (\u03bb h, nat.no_confusion h)\n    (\u03bb h, h.elim\n      (\u03bb h, nat.no_confusion (nat.succ.inj h))\n      (\u03bb h, nat.no_confusion ((nat.succ.inj \u2218 nat.succ.inj \u2218 nat.succ.inj \u2218 nat.succ.inj) h))))\n\n#print notation \u2286\n#print set.subset\n/-\nIn Lean, the `subset` takes two `set`s and emits a `Prop`:\n  `def set.subset : \u03a0 {\u03b1 : Type u}, set \u03b1 \u2192 set \u03b1 \u2192 Prop :=`\n  `  \u03bb \u03b1 s\u2081 s\u2082, (\u2200 (a : \u03b1), a \u2208 s\u2081 \u2192 a \u2208 s\u2082)`\n-/\n\n#print set.univ\n#print notation \u2205\n#print set.has_emptyc\n/-\nIn Lean, the `univ` emits a `set` (\u03b1 is implicit):\n  `def set.univ : \u03a0 {\u03b1 : Type u}, set \u03b1 :=`\n  `  \u03bb \u03b1, (\u03bb a, true)`\n-/\n\n#reduce (some_subset \u2286 (set.univ : set \u2115))\n-- `\u2200 (a : \u2115), (a = 0 \u2228 a = 1 \u2228 a = 12) \u2192 true`\nexample : some_subset \u2286 (set.univ : set \u2115) :=\n  \u03bb x (hx : some_subset x), trivial\n\n-- TODO: intersection, union, complement\n-- TODO: indexed intersection / union\n-- TODO: extensionality of sets\n-- https://leanprover.github.io/logic_and_proof/sets_in_lean.html\n\nend using_sets_in_lean\n\n\n--------------------------------------------------------------------------------\n-- ## Using functions in Lean\n\n-- TODO: complete\n\n\n\n", "meta": {"author": "bridgekat", "repo": "lean-notes", "sha": "18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d", "save_path": "github-repos/lean/bridgekat-lean-notes", "path": "github-repos/lean/bridgekat-lean-notes/lean-notes-18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d/src/1_intro_to_uni_maths/0_lean_notations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.743168067654255}}
{"text": "/-\nCopyright (c) 2020 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\nimport tactic\n\n/-!\n# Logic\n\nA Lean companion to the \"Logic\" part of the intro module.\n\nWe develop the basic theory of the five symbols\n\u2192, \u00ac, \u2227, \u2194, \u2228\n\n# Background\n\nIt is hard to ask you difficult questions\nabout the basic theory of these logical operators,\nbecause every question can be proved by \"check all the cases\".\n\nHowever, there is this cool theorem, that says that if\na theorem in the basic theory of logical propositions can be proved\nby \"check all the cases\", then it can be proved in the Lean theorem\nprover using only the eight constructive tactics `intro`, `apply`,\n`assumption`, `exfalso`, `split`, `cases`, `have`, `left` and `right`,\nas well as one extra rule called the Law of the Excluded Middle,\nwhich in Lean is the tactic `by_cases`. Note that the tactic `finish`\nis a general \"check all the cases\" tactic, and it uses `by_cases`.\n\n## Reference\n\n* The first half of section 1 of the M40001/40009 course notes.\n\n-/\n\nnamespace xena\n\nvariables (P Q R : Prop)\n\n/- \n\n## Level 1 : implies\n\nIn Lean, `P \u2192 Q` is the notation for `P \u21d2 Q` . \n\nLet's start by learning how to control implications. We will\nlearn the three tactics `intro`, `apply` and `exact`.\n\n-/\n\n/-- Every proposition implies itself. -/\ndef id : P \u2192 P :=\nbegin\n  /- \n  Click here!\n  \n  See that\n  \n  `\u22a2 P \u2192 P`\n\n  on the top right? That funny symbol `\u22a2 X` means \"you have to prove `X`\".\n\n  So we have to prove that `P` implies `P`.\n\n  How do we prove that `X` implies `Y`? We assume `X`, and try and deduce `Y`.\n  -/\n  -- assume P is true. Call this hypothesis hP.\n  intro hP,\n  -- goal now `\u22a2 P` and we also have hypothesis `hP: P`\n  -- So we know that P is true, by hypothesis hP.\n  exact hP,\nend\n\n-- implication isn't associative!\n-- Try it when P, Q, R are all false.\n-- `false \u2192 (false \u2192 false)` is `true`,\n-- and\n-- `(false \u2192 false) \u2192 false` is `false`.\n\n-- in Lean, `P \u2192 Q \u2192 R` is _defined_ to be `P \u2192 (Q \u2192 R)`\n-- Here's a proof of what I just said.\nexample : (P \u2192 Q \u2192 R) \u2194 (P \u2192 (Q \u2192 R)) :=\nbegin\n  -- \u22a2 P \u2192 Q \u2192 R \u2194 P \u2192 Q \u2192 R\n  refl -- that closes goals of the form X = X and X \u2194 X.\nend\n\n-- Another way to see it is just to uncomment out the line below:\n-- #check P \u2192 (Q \u2192 R) -- output is `P \u2192 Q \u2192 R : Prop`\n\nexample : P \u2192 Q \u2192 P :=\nbegin\n  -- remember that by definition the goal is P \u2192 (Q \u2192 P),\n  -- so it's P implies something, so let's assume \n  -- that P is true and call this hypothesis hP.\n  intro hP,\n  -- Now we have to prove that Q implies P, so let's\n  -- assume that Q is true, and let's call this hypothesis hQ\n  intro hQ,\n  -- We now have to prove that P is true.\n  -- But this is exactly our hypothesis hP.\n  exact hP,\nend\n\n/-- If we know `P`, and we also know `P \u2192 Q`, we can deduce `Q`. -/\nlemma modus_ponens : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  -- remember this means \"P implies that ((P implies Q) implies Q)\"\n  -- so let's assume P is true\n  intro hP,\n  -- and let's assume hypothesis hPQ, that P implies Q\n  intro hPQ,\n  -- now `hPQ` says `P \u2192 Q` and we're trying to prove `Q`!\n  -- So by applying the hypothesis `hPQ`, we can reduce\n  -- this puzzle to proving `P`.\n  apply hPQ,\n  -- Now we have to prove `P`. But this is just an assumption\n  exact hP, -- or `assumption`\nend\n\n-- See if you can do this one yourself. Replace the `sorry` with a proof.\nlemma transitivity : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  sorry,\nend\n\n-- Of course you can always cheat with the `finish` tactic\nexample : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  finish,\nend\n\n-- finish just checks all the cases. It's slower than a constructive proof.\n-- constructivists regard it as cheating.\n\n-- This one is a \"relative modus ponens\" -- in the\n-- presence of P, if Q -> R and Q then R.\n-- Something fun happens in this one. I'll start you off.\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  -- Let `hPQR` be the hypothesis that `P \u2192 Q \u2192 R`. \n  intro hPQR,\n  -- We now need to prove that `(P \u2192 Q)` implies something.\n  -- So let `hPQ` be hypothesis that `P \u2192 Q`\n  intro hPQ,\n  -- We now need to prove that `P` implies something, so \n  -- let `hP` be the hypothesis that `P` is true.\n  intro hP,\n  -- We now have to prove `R`.\n  -- We know the hypothesis `hPQR : P \u2192 (Q \u2192 R)`.\n  -- Can we apply it?\n  apply hPQR,\n  -- exercise: what just happened?\n  sorry, sorry\nend\n\n/-\n\n### Level 2 : not\n\n`not P`, with notation `\u00ac P`, is defined to mean `P \u2192 false` in Lean,\ni.e., the proposition that P implies false. Note that `true \u2192 false` is `false`,\nand `false \u2192 false` is `true`, so `P \u2192 false` is indeed equivalent\nto `\u00ac P`. But we need to remember the fact that in Lean, `\u00ac P` was\n*defined* to mean `P \u2192 false` and not in any other way.\n\nWe develop a basic interface for `\u00ac`.\n-/\n\ntheorem not_not_intro : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  -- we have to prove that P implies (not (not P)),\n  -- so let's assume P is true, and let's call this assumption hP\n  intro hP,\n  -- now we have to prove `not (not P)`, a.k.a. `\u00ac (\u00ac P)`, and\n  -- by definition this means we have to prove `(\u00ac P) \u2192 false`\n  -- In fact we can `change` our goal to this\n  change \u00ac P \u2192 false,\n  -- The `change` tactic will make changes to the goal, as long\n  -- as they are true *by definition*.\n\n  -- So let's let hnP be the hypothesis that `\u00ac P` is true.\n  intro hnP,\n  -- and now we have to prove `false`!\n  -- Sometimes this can be difficult, but it's OK if you have\n  -- *contradictory hypotheses*, because with contradictory\n  -- assumptions you can prove false conclusions, and once you've\n  -- proved one false thing you've proved all false things because\n  -- you've made mathematics collapse.\n\n  -- How are we going to use hypothesis `hnP : \u00ac P`? \n\n  -- Well, what does it _mean_? It means `P \u2192 false`,\n  -- We could `change` `hnP` to remind us of this:\n  change P \u2192 false at hnP,\n\n  -- Now our _goal_ is false, so why don't we apply \n  -- hypothesis hnP, which will reduce our problem\n  -- to proving `P`.\n\n  apply hnP,\n\n  -- now our goal is `P`, and this is an assumption!\n  exact hP\nend\n\n-- What do you think of this proof?\ntheorem not_not_intro'' : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  apply modus_ponens,\n  -- Go back and look at modus ponens. Can you see how this proof worked?\nend\n\n-- If you're into lambda calculus or functional programming,\n-- here's a functional proof\ntheorem not_not_intro' : P \u2192 \u00ac (\u00ac P) :=\n\u03bb hP hnP, hnP hP\n\n-- This one is straightforward -- give it a go:\ntheorem contra1 : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  sorry\nend\n\n-- This way is impossible using constructive logic -- you have to use\n-- a classical tactic like `finish` or check manually on cases.\ntheorem contra2 : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n  intro h,\n  intro hP,\n  -- stuck\n  finish,\nend\n\n\n/-!\n\n### Level 3 : and\n\nThe hypothesis `hPaQ : P \u2227 Q` in Lean, is equivalent to\nhypotheses `hP : P` and `hQ : Q`. \n\nIf you have `hPaQ` as a hypothesis, and you want to get to\n`hP` and `hQ`, you can use the `cases` tactic.\n\nIf you have `\u22a2 P \u2227 Q` as a goal, and want to turn the goal\ninto two goals `\u22a2 P` and `\u22a2 Q`, then use the `split` tactic.\n\nNote that after `split` it's good etiquette to use indentation\nor brackets, because you have two goals.\n\nExample:\n\nexample (hP : P) (hQ : Q) : P \u2227 Q :=\nbegin\n  split,\n    exact hP, -- we had two goals here\n  exact hQ  -- we are back to one goal\nend\n\nor\n\nexample (hP : P) (hQ : Q) : P \u2227 Q :=\nbegin\n  split,\n  { exact hP },\n  { exact hQ }\nend\n\n-/\n\ntheorem and.elim_left : P \u2227 Q \u2192 P :=\nbegin\n  intro hPaQ,\n  -- You can use the `cases` tactic on an `and` hypothesis\n  cases hPaQ with hP hQ,\n  exact hP,\nend\n\n-- try this one\ntheorem and.elim_right : P \u2227 Q \u2192 Q :=\nbegin\n  sorry\nend\n\n-- functional proof\ntheorem and.elim_right' : P \u2227 Q \u2192 Q := \u03bb hPaQ, hPaQ.2\n\n-- Can you construct the full eliminator for `and`?\ntheorem and.elim : P \u2227 Q \u2192 (P \u2192 Q \u2192 R) \u2192 R :=\nbegin\n  sorry\nend\n\n-- Here's how to solve `and` goals.\ntheorem and.intro : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  intro hP,\n  intro hQ,\n  -- use `split` on an and goal; you'll get two goals.\n  split,\n    assumption, -- just means \"the goal is one of the hypotheses\"\n  assumption,\nend\n\n\n-- there's a two-line proof of this which starts\n-- `apply function.swap`, but you don't need to do this\ntheorem and.rec : (P \u2192 Q \u2192 R) \u2192 P \u2227 Q \u2192 R :=\nbegin\n  sorry\nend\n\ntheorem and.symm : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  sorry\nend\n\ntheorem and.trans : (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n  sorry,\nend\n\n/-\nExtra credit\n\nRecall that the convention for the implies sign \u2192\nis that it is _right associative_, by which\nI mean that `P \u2192 Q \u2192 R` means `P \u2192 (Q \u2192 R)` by definition.\nThis does actually simplify! If `P` implies `Q \u2192 R`\nthen this means that `P` and `Q` together, imply `R`,\nso `P \u2192 Q \u2192 R` is logically equivalent to `(P \u2227 Q) \u2192 R`.\n\nWe proved that `P \u2192 Q \u2192 R` implied `(P \u2227 Q) \u2192 R`; this was `and.rec`.\nLet's go the other way.\n-/\n\nexample : ((P \u2227 Q) \u2192 R) \u2192 (P \u2192 Q \u2192 R) :=\nbegin\n  sorry\nend\n\n\n/-!\n\n### Level 4 : iff\n\nThe basic theory of `iff`.\n\nIn Lean, `P \u2194 Q` is *defined to mean* `(P \u2192 Q) \u2227 (Q \u2192 P)`.\n\nIt is _not_ defined by a truth table. You can attack a `P \u2194 Q` goal\nwith the `split` tactic, because it is really an `\u2227` statement.\n-/\n\n/-- `P \u2194 P` is true for all propositions `P`. -/\ndef iff.refl : P \u2194 P :=\nbegin\n  -- By Lean's definition I need to prove (P \u2192 P) \u2227 (P \u2192 P)\n  split,\n    -- need to prove P \u2192 P\n    -- We proved that a long time ago and called it `id`.\n    apply id,\n  -- need to prove P \u2192 P\n  apply id\nend\n\n-- If you get stuck, there is always the \"truth table\" tactic `finish`\ndef iff.refl' : P \u2194 P :=\nbegin\n  finish,\nend\n\n-- The refl tactic also works\ndef iff.refl'' : P \u2194 P :=\nbegin\n  refl\nend\n\n\ndef iff.symm : (P \u2194 Q) \u2192 (Q \u2194 P) :=\nbegin\n  -- Try this one using `cases` and `split`.\n  sorry\nend\n\n-- I'll now show you a better way: the `rewrite` tactic.\ndef iff.symm' : (P \u2194 Q) \u2192 (Q \u2194 P) :=\nbegin\n  intro h,\n  -- `h : P \u2194 Q`\n  -- The `rw h` tactic will change all P's in the goal to Q's.\n  -- And then it will try `refl`, just for luck\n  rw h,\n  -- finished! Goal becamse `Q \u2194 Q` and then `refl` finished it.\nend\n\ndef iff.comm : (P \u2194 Q) \u2194 (Q \u2194 P) :=\nbegin\n  sorry,\nend\n\n-- without rw or cc this is ugly\ndef iff.trans :  (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  sorry\nend\n\n-- This is a cute question. Can you prove it constructively,\n-- using only `intro`, `cases`, `have`, `apply`, and `assumption`?\ndef iff.boss : \u00ac (P \u2194 \u00ac P) :=\nbegin\n  sorry\nend\n\n-- Now we have iff we can go back to and.\n\n/-! ### iff epilogue: \u2194 and \u2227 -/\n\ntheorem and.comm : P \u2227 Q \u2194 Q \u2227 P :=\nbegin\n  sorry\nend\n\n-- \u2227 is \"right associative\" in Lean, which means\n-- that `P \u2227 Q \u2227 R` is _defined to mean_ `P \u2227 (Q \u2227 R)`.\n-- Associativity can hence be written like this:\ntheorem and_assoc : ((P \u2227 Q) \u2227 R) \u2194 (P \u2227 Q \u2227 R) :=\nbegin\n  sorry,\nend\n\n\n\n/-!\n\n## Level 5 (final level) : Or\n\n`P \u2228 Q` is true when at least one of `P` and `Q` are true.\nHere is how to work with `\u2228` in Lean.\n\nIf you have a _hypothesis_ `hPoQ : P \u2228 Q` then you \ncan break into the two cases `hP : P` and `hQ : Q` using\n`cases hPoQ with hP hQ`\n\nIf you have a _goal_ of the form `\u22a2 P \u2228 Q` then you\nneed to decide whether you're going to prove `P` or `Q`.\nIf you want to prove `P` then use the `left` tactic,\nand if you want to prove `Q` then use the `right` tactic.\nDon't get lost! You can't go back.\n-/\n\n-- recall that P, Q, R are Propositions. We'll need S for this one.\nvariable (S : Prop)\n\n-- use the `left` tactic to reduce from `\u22a2 P \u2228 Q` to `\u22a2 P`\ntheorem or.intro_left : P \u2192 P \u2228 Q :=\nbegin\n  intro hP,\n  -- \u22a2 P \u2228 Q\n  left,\n  -- \u22a2 P\n  exact hP\nend\n\n-- use the `right` tactic to reduce from `\u22a2 P \u2228 Q`\ntheorem or.intro_right : Q \u2192 P \u2228 Q :=\nbegin\n  sorry,\nend\n\ntheorem or.elim : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  intro hPoQ,\n  intros hpq hqr,\n  -- use the `cases h` tactic if `h : X \u2228 Y`\n  cases hPoQ with hP hQ,\n    sorry,\n  sorry\nend\n\n\ntheorem or.symm : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  sorry\nend\n\ntheorem or.comm : P \u2228 Q \u2194 Q \u2228 P :=\nbegin\n  sorry\nend\n\ntheorem or.assoc : (P \u2228 Q) \u2228 R \u2194 P \u2228 Q \u2228 R :=\nbegin\n  sorry,\nend\n\ntheorem or.cases_on : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  sorry,\nend\n\n\n\ntheorem or.imp : (P \u2192 R) \u2192 (Q \u2192 S) \u2192 P \u2228 Q \u2192 R \u2228 S :=\nbegin\n  sorry,\nend\n\ntheorem or.imp_left : (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R :=\nbegin\n  sorry,\nend\n\ntheorem or.imp_right : (P \u2192 Q) \u2192 R \u2228 P \u2192 R \u2228 Q :=\nbegin\n  sorry,\nend\n\ntheorem or.left_comm : P \u2228 Q \u2228 R \u2194 Q \u2228 P \u2228 R :=\nbegin\n  sorry,\nend\n\ntheorem or.rec : (P \u2192 R) \u2192 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R :=\nbegin\n  sorry\nend\n\ntheorem or.resolve_left : P \u2228 Q \u2192 \u00acP \u2192 Q :=\nbegin\n  sorry,\nend\n\ntheorem or_congr : (P \u2194 R) \u2192 (Q \u2194 S) \u2192 (P \u2228 Q \u2194 R \u2228 S) :=\nbegin\n  sorry,\nend\n\n/-!\n\n# Appendix: `exfalso` and classical logic\n\n-/\n\n-- useful lemma about false\ntheorem false.elim' : false \u2192 P :=\nbegin\n  -- Let's assume that a false proposition is true. Let's\n  -- call this assumption h.\n  intro h,\n  -- We now have to prove P. \n  -- The `exfalso` tactic changes any goal to `false`.\n  exfalso,\n  -- Now our goal is an assumption! It's exactly `h`.\n  exact h,\nend\n\n-- Is that confusing? What about this proof?\ntheorem false.elim'' : false \u2192 P :=\nbegin\n  -- Let's assume that a false proposition is true. Let's\n  -- call this assumption h.\n  intro h,\n  -- Now let's deal with all the cases.\n  cases h,\n  -- There are no cases.\nend\n\n-- This next one cannot be proved using the tactics we know\n-- which are constructive. This one needs the assumption\n-- that every statement is true or false.\n-- We give a \"by cases\" proof explicitly -- `finish` just does the\n-- job immediately.\ntheorem double_negation_elimination : \u00ac (\u00ac P) \u2192 P :=\nbegin\n  -- `finish` works\n  classical,\n  intro hnnP,\n  by_cases hP : P,\n    -- hypothesis hP : P\n    assumption,\n  -- hypothesis hP : \u00ac P\n  -- `contradiction` works from here\n  exfalso,\n  apply hnnP,\n  exact hP,\nend\n\nend xena\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/logic/questions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7431402928471862}}
{"text": "/-\nCopyright (c) 2021 Tian Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tian Chen\n-/\nimport data.pnat.basic\n\n/-!\n# IMO 1977 Q6\n\nSuppose `f : \u2115+ \u2192 \u2115+` satisfies `f(f(n)) < f(n + 1)` for all `n`.\nProve that `f(n) = n` for all `n`.\n\nWe first prove the problem statement for `f : \u2115 \u2192 \u2115`\nthen we use it to prove the statement for positive naturals.\n-/\n\ntheorem imo1977_q6_nat (f : \u2115 \u2192 \u2115) (h : \u2200 n, f (f n) < f (n + 1)) :\n  \u2200 n, f n = n :=\nbegin\n  have h' : \u2200 (k n : \u2115), k \u2264 n \u2192 k \u2264 f n,\n  { intro k,\n    induction k with k h_ind,\n    { intros, exact nat.zero_le _ },\n    { intros n hk,\n      apply nat.succ_le_of_lt,\n      calc k \u2264 f (f (n - 1)) : h_ind _ (h_ind (n - 1) (le_tsub_of_add_le_right hk))\n         ... < f n           : tsub_add_cancel_of_le\n        (le_trans (nat.succ_le_succ (nat.zero_le _)) hk) \u25b8 h _ } },\n  have hf : \u2200 n, n \u2264 f n := \u03bb n, h' n n rfl.le,\n  have hf_mono : strict_mono f := strict_mono_nat_of_lt_succ (\u03bb _, lt_of_le_of_lt (hf _) (h _)),\n  intro,\n  exact nat.eq_of_le_of_lt_succ (hf _) (hf_mono.lt_iff_lt.mp (h _))\nend\n\ntheorem imo1977_q6 (f : \u2115+ \u2192 \u2115+) (h : \u2200 n, f (f n) < f (n + 1)) :\n  \u2200 n, f n = n :=\nbegin\n  intro n,\n  simpa using imo1977_q6_nat (\u03bb m, if 0 < m then f m.to_pnat' else 0) _ n,\n  { intro x, cases x,\n    { simp },\n    { simpa using h _ } }\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo1977_q6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7431402717641052}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport measure_theory.measure.complex_lebesgue\nimport measure_theory.integral.divergence_theorem\nimport measure_theory.integral.circle_integral\nimport analysis.calculus.dslope\nimport analysis.analytic.basic\nimport analysis.complex.re_im_topology\nimport analysis.calculus.diff_on_int_cont\nimport data.real.cardinality\n\n/-!\n# Cauchy integral formula\n\nIn this file we prove the Cauchy-Goursat theorem and the Cauchy integral formula for integrals over\ncircles. Most results are formulated for a function `f : \u2102 \u2192 E` that takes values in a complex\nBanach space with second countable topology.\n\n## Main statements\n\nIn the following theorems, if the name ends with `off_countable`, then the actual theorem assumes\ndifferentiability at all but countably many points of the set mentioned below.\n\n* `complex.integral_boundary_rect_of_has_fderiv_within_at_real_off_countable`: If a function\n  `f : \u2102 \u2192 E` is continuous on a closed rectangle and *real* differentiable on its interior, then\n  its integral over the boundary of this rectangle is equal to the integral of\n  `I \u2022 f' (x + y * I) 1 - f' (x + y * I) I` over the rectangle, where `f' z w : E` is the derivative\n  of `f` at `z` in the direction `w` and `I = complex.I` is the imaginary unit.\n\n* `complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable`: If a function\n  `f : \u2102 \u2192 E` is continuous on a closed rectangle and is *complex* differentiable on its interior,\n  then its integral over the boundary of this rectangle is equal to zero.\n\n* `complex.circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable`: If a\n  function `f : \u2102 \u2192 E` is continuous on a closed annulus `{z | r \u2264 |z - c| \u2264 R}` and is complex\n  differentiable on its interior `{z | r < |z - c| < R}`, then the integrals of `(z - c)\u207b\u00b9 \u2022 f z`\n  over the outer boundary and over the inner boundary are equal.\n\n* `complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto`,\n  `complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable`:\n  If a function `f : \u2102 \u2192 E` is continuous on a punctured closed disc `{z | |z - c| \u2264 R \u2227 z \u2260 c}`, is\n  complex differentiable on the corresponding punctured open disc, and tends to `y` as `z \u2192 c`,\n  `z \u2260 c`, then the integral of `(z - c)\u207b\u00b9 \u2022 f z` over the circle `|z - c| = R` is equal to\n  `2\u03c0iy`. In particular, if `f` is continuous on the whole closed disc and is complex differentiable\n  on the corresponding open disc, then this integral is equal to `2\u03c0if(c)`.\n\n* `complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable`,\n  `complex.two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable`\n  **Cauchy integral formula**: if `f : \u2102 \u2192 E` is continuous on a closed disc of radius `R` and is\n  complex differentiable on the corresponding open disc, then for any `w` in the corresponding open\n  disc the integral of `(z - w)\u207b\u00b9 \u2022 f z` over the boundary of the disc is equal to `2\u03c0if(w)`.\n  Two versions of the lemma put the multiplier `2\u03c0i` at the different sides of the equality.\n\n* `complex.has_fpower_series_on_ball_of_differentiable_off_countable`: If `f : \u2102 \u2192 E` is continuous\n  on a closed disc of positive radius and is complex differentiable on the corresponding open disc,\n  then it is analytic on the corresponding open disc, and the coefficients of the power series are\n  given by Cauchy integral formulas.\n\n* `differentiable_on.has_fpower_series_on_ball`: If `f : \u2102 \u2192 E` is complex differentiable on a\n  closed disc of positive radius, then it is analytic on the corresponding open disc, and the\n  coefficients of the power series are given by Cauchy integral formulas.\n\n* `differentiable_on.analytic_at`, `differentiable.analytic_at`: If `f : \u2102 \u2192 E` is differentiable\n  on a neighborhood of a point, then it is analytic at this point. In particular, if `f : \u2102 \u2192 E`\n  is differentiable on the whole `\u2102`, then it is analytic at every point `z : \u2102`.\n\n* `differentiable.has_power_series_on_ball`: If `f : \u2102 \u2192 E` is differentiable everywhere then the\n  `cauchy_power_series f z R` is a formal power series representing `f` at `z` with infinite\n  radius of convergence (this holds for any choice of `0 < R`).\n\n## Implementation details\n\nThe proof of the Cauchy integral formula in this file is based on a very general version of the\ndivergence theorem, see `measure_theory.integral_divergence_of_has_fderiv_within_at_off_countable`\n(a version for functions defined on `fin (n + 1) \u2192 \u211d`),\n`measure_theory.integral_divergence_prod_Icc_of_has_fderiv_within_at_off_countable_of_le`, and\n`measure_theory.integral2_divergence_prod_of_has_fderiv_within_at_off_countable` (versions for\nfunctions defined on `\u211d \u00d7 \u211d`).\n\nUsually, the divergence theorem is formulated for a $C^1$ smooth function. The theorems formulated\nabove deal with a function that is\n\n* continuous on a closed box/rectangle;\n* differentiable at all but countably many points of its interior;\n* have divergence integrable over the closed box/rectangle.\n\nFirst, we reformulate the theorem for a *real*-differentiable map `\u2102 \u2192 E`, and relate the integral\nof `f` over the boundary of a rectangle in `\u2102` to the integral of the derivative\n$\\frac{\\partial f}{\\partial \\bar z}$ over the interior of this box. In particular, for a *complex*\ndifferentiable function, the latter derivative is zero, hence the integral over the boundary of a\nrectangle is zero. Thus we get the Cauchy-Goursat theorem for a rectangle in `\u2102`.\n\nNext, we apply the this theorem to the function $F(z)=f(c+e^{z})$ on the rectangle\n$[\\ln r, \\ln R]\\times [0, 2\\pi]$ to prove that\n$$\n  \\oint_{|z-c|=r}\\frac{f(z)\\,dz}{z-c}=\\oint_{|z-c|=R}\\frac{f(z)\\,dz}{z-c}\n$$\nprovided that `f` is continuous on the closed annulus `r \u2264 |z - c| \u2264 R` and is complex\ndifferentiable on its interior `r < |z - c| < R` (possibly, at all but countably many points).\n\nHere and below, we write $\\frac{f(z)}{z-c}$ in the documentation while the actual lemmas use\n`(z - c)\u207b\u00b9 \u2022 f z` because `f z` belongs to some Banach space over `\u2102` and `f z / (z - c)` is\nundefined.\n\nTaking the limit of this equality as `r` tends to `\ud835\udcdd[>] 0`, we prove\n$$\n  \\oint_{|z-c|=R}\\frac{f(z)\\,dz}{z-c}=2\\pi if(c)\n$$\nprovided that `f` is continuous on the closed disc `|z - c| \u2264 R` and is differentiable at all but\ncountably many points of its interior. This is the Cauchy integral formula for the center of a\ncircle. In particular, if we apply this function to `F z = (z - c) \u2022 f z`, then we get\n$$\n  \\oint_{|z-c|=R} f(z)\\,dz=0.\n$$\n\nIn order to deduce the Cauchy integral formula for any point `w`, `|w - c| < R`, we consider the\nslope function `g : \u2102 \u2192 E` given by `g z = (z - w)\u207b\u00b9 \u2022 (f z - f w)` if `z \u2260 w` and `g w = f' w`.\nThis function satisfies assumptions of the previous theorem, so we have\n$$\n  \\oint_{|z-c|=R} \\frac{f(z)\\,dz}{z-w}=\\oint_{|z-c|=R} \\frac{f(w)\\,dz}{z-w}=\n  \\left(\\oint_{|z-c|=R} \\frac{dz}{z-w}\\right)f(w).\n$$\nThe latter integral was computed in `circle_integral.integral_sub_inv_of_mem_ball` and is equal to\n`2 * \u03c0 * complex.I`.\n\nThere is one more step in the actual proof. Since we allow `f` to be non-differentiable on a\ncountable set `s`, we cannot immediately claim that `g` is continuous at `w` if `w \u2208 s`. So, we use\nthe proof outlined in the previous paragraph for `w \u2209 s` (see\n`complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable_aux`), then use continuity\nof both sides of the formula and density of `s\u1d9c` to prove the formula for all points of the open\nball, see `complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable`.\n\nFinally, we use the properties of the Cauchy integrals established elsewhere (see\n`has_fpower_series_on_cauchy_integral`) and Cauchy integral formula to prove that the original\nfunction is analytic on the open ball.\n\n## Tags\n\nCauchy-Goursat theorem, Cauchy integral formula\n-/\n\nopen topological_space set measure_theory interval_integral metric filter function\nopen_locale interval real nnreal ennreal topological_space big_operators\n\nnoncomputable theory\n\nuniverses u\n\nvariables {E : Type u} [normed_group E] [normed_space \u2102 E] [complete_space E]\n\nnamespace complex\n\n/-- Suppose that a function `f : \u2102 \u2192 E` is continuous on a closed rectangle with opposite corners at\n`z w : \u2102`, is *real* differentiable at all but countably many points of the corresponding open\nrectangle, and $\\frac{\\partial f}{\\partial \\bar z}$ is integrable on this rectangle. Then the\nintegral of `f` over the boundary of the rectangle is equal to the integral of\n$2i\\frac{\\partial f}{\\partial \\bar z}=i\\frac{\\partial f}{\\partial x}-\\frac{\\partial f}{\\partial y}$\nover the rectangle. -/\nlemma integral_boundary_rect_of_has_fderiv_at_real_off_countable (f : \u2102 \u2192 E)\n  (f' : \u2102 \u2192 \u2102 \u2192L[\u211d] E) (z w : \u2102) (s : set \u2102) (hs : countable s)\n  (Hc : continuous_on f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n  (Hd : \u2200 x \u2208 (Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im)) \\ s,\n    has_fderiv_at f (f' x) x)\n  (Hi : integrable_on (\u03bb z, I \u2022 f' z 1 - f' z I) ([z.re, w.re] \u00d7\u2102 [z.im, w.im])) :\n  (\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - (\u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n    (I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) - I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I) =\n    \u222b x : \u211d in z.re..w.re, \u222b y : \u211d in z.im..w.im, I \u2022 f' (x + y * I) 1 - f' (x + y * I) I :=\nbegin\n  set e : (\u211d \u00d7 \u211d) \u2243L[\u211d] \u2102 := equiv_real_prod\u2097.symm,\n  have he : \u2200 x y : \u211d, \u2191x + \u2191y * I = e (x, y), from \u03bb x y, (mk_eq_add_mul_I x y).symm,\n  have he\u2081 : e (1, 0) = 1 := rfl, have he\u2082 : e (0, 1) = I := rfl,\n  simp only [he] at *,\n  set F : (\u211d \u00d7 \u211d) \u2192 E := f \u2218 e,\n  set F' : (\u211d \u00d7 \u211d) \u2192 (\u211d \u00d7 \u211d) \u2192L[\u211d] E := \u03bb p, (f' (e p)).comp (e : (\u211d \u00d7 \u211d) \u2192L[\u211d] \u2102),\n  have hF' : \u2200 p : \u211d \u00d7 \u211d, (-(I \u2022 F' p)) (1, 0) + F' p (0, 1) = -(I \u2022 f' (e p) 1 - f' (e p) I),\n  { rintro \u27e8x, y\u27e9, simp [F', he\u2081, he\u2082, \u2190 sub_eq_neg_add], },\n  set R : set (\u211d \u00d7 \u211d) := [z.re, w.re] \u00d7\u02e2 [w.im, z.im],\n  set t : set (\u211d \u00d7 \u211d) := e \u207b\u00b9' s,\n  rw [interval_swap z.im] at Hc Hi, rw [min_comm z.im, max_comm z.im] at Hd,\n  have hR : e \u207b\u00b9' ([z.re, w.re] \u00d7\u2102 [w.im, z.im]) = R := rfl,\n  have htc : continuous_on F R, from Hc.comp e.continuous_on hR.ge,\n  have htd : \u2200 p \u2208 Ioo (min z.re w.re) (max z.re w.re) \u00d7\u02e2 Ioo (min w.im z.im) (max w.im z.im) \\ t,\n    has_fderiv_at F (F' p) p := \u03bb p hp, (Hd (e p) hp).comp p e.has_fderiv_at,\n  simp_rw [\u2190 interval_integral.integral_smul, interval_integral.integral_symm w.im z.im,\n    \u2190 interval_integral.integral_neg, \u2190 hF'],\n  refine (integral2_divergence_prod_of_has_fderiv_within_at_off_countable\n      (\u03bb p, -(I \u2022 F p)) F (\u03bb p, - (I \u2022 F' p)) F' z.re w.im w.re z.im t (hs.preimage e.injective)\n      (htc.const_smul _).neg htc (\u03bb p hp, ((htd p hp).const_smul I).neg) htd _).symm,\n  rw [\u2190 volume_preserving_equiv_real_prod.symm.integrable_on_comp_preimage\n    (measurable_equiv.measurable_embedding _)] at Hi,\n  simpa only [hF'] using Hi.neg\nend\n\n/-- Suppose that a function `f : \u2102 \u2192 E` is continuous on a closed rectangle with opposite corners at\n`z w : \u2102`, is *real* differentiable on the corresponding open rectangle, and\n$\\frac{\\partial f}{\\partial \\bar z}$ is integrable on this rectangle. Then the integral of `f` over\nthe boundary of the rectangle is equal to the integral of\n$2i\\frac{\\partial f}{\\partial \\bar z}=i\\frac{\\partial f}{\\partial x}-\\frac{\\partial f}{\\partial y}$\nover the rectangle. -/\nlemma integral_boundary_rect_of_continuous_on_of_has_fderiv_at_real (f : \u2102 \u2192 E)\n  (f' : \u2102 \u2192 \u2102 \u2192L[\u211d] E) (z w : \u2102)\n  (Hc : continuous_on f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n  (Hd : \u2200 x \u2208 (Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im)),\n    has_fderiv_at f (f' x) x)\n  (Hi : integrable_on (\u03bb z, I \u2022 f' z 1 - f' z I) ([z.re, w.re] \u00d7\u2102 [z.im, w.im])) :\n  (\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - (\u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n    (I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) - I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I) =\n    \u222b x : \u211d in z.re..w.re, \u222b y : \u211d in z.im..w.im, I \u2022 f' (x + y * I) 1 - f' (x + y * I) I :=\nintegral_boundary_rect_of_has_fderiv_at_real_off_countable f f' z w \u2205 countable_empty Hc\n  (\u03bb x hx, Hd x hx.1) Hi\n\n/-- Suppose that a function `f : \u2102 \u2192 E` is *real* differentiable on a closed rectangle with opposite\ncorners at `z w : \u2102` and $\\frac{\\partial f}{\\partial \\bar z}$ is integrable on this rectangle. Then\nthe integral of `f` over the boundary of the rectangle is equal to the integral of\n$2i\\frac{\\partial f}{\\partial \\bar z}=i\\frac{\\partial f}{\\partial x}-\\frac{\\partial f}{\\partial y}$\nover the rectangle. -/\nlemma integral_boundary_rect_of_differentiable_on_real (f : \u2102 \u2192 E) (z w : \u2102)\n  (Hd : differentiable_on \u211d f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n  (Hi : integrable_on (\u03bb z, I \u2022 fderiv \u211d f z 1 - fderiv \u211d f z I) ([z.re, w.re] \u00d7\u2102 [z.im, w.im])) :\n  (\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - (\u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n    (I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) - I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I) =\n    \u222b x : \u211d in z.re..w.re, \u222b y : \u211d in z.im..w.im,\n      I \u2022 fderiv \u211d f (x + y * I) 1 - fderiv \u211d f (x + y * I) I :=\nintegral_boundary_rect_of_has_fderiv_at_real_off_countable f (fderiv \u211d f) z w \u2205 countable_empty\n  Hd.continuous_on\n  (\u03bb x hx, Hd.has_fderiv_at $ by simpa only [\u2190 mem_interior_iff_mem_nhds,\n    interior_re_prod_im, interval, interior_Icc] using hx.1) Hi\n\n/-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function\nover the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed\nrectangle and is complex differentiable at all but countably many points of the corresponding open\nrectangle, then its integral over the boundary of the rectangle equals zero. -/\nlemma integral_boundary_rect_eq_zero_of_differentiable_on_off_countable (f : \u2102 \u2192 E)\n  (z w : \u2102) (s : set \u2102) (hs : countable s) (Hc : continuous_on f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n  (Hd : \u2200 x \u2208 (Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im)) \\ s,\n    differentiable_at \u2102 f x) :\n  (\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - (\u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n    (I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n      I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I) = 0 :=\nby refine (integral_boundary_rect_of_has_fderiv_at_real_off_countable f\n  (\u03bb z, (fderiv \u2102 f z).restrict_scalars \u211d) z w s hs Hc\n  (\u03bb x hx, (Hd x hx).has_fderiv_at.restrict_scalars \u211d) _).trans _;\n    simp [\u2190 continuous_linear_map.map_smul]\n\n/-- **Cauchy-Goursat theorem for a rectangle**: the integral of a complex differentiable function\nover the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed\nrectangle and is complex differentiable on the corresponding open rectangle, then its integral over\nthe boundary of the rectangle equals zero. -/\nlemma integral_boundary_rect_eq_zero_of_continuous_on_of_differentiable_on (f : \u2102 \u2192 E) (z w : \u2102)\n  (Hc : continuous_on f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n  (Hd : differentiable_on \u2102 f\n    (Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im))) :\n  (\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - (\u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n    (I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n      I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I) = 0 :=\nintegral_boundary_rect_eq_zero_of_differentiable_on_off_countable f z w \u2205 countable_empty\n  Hc $ \u03bb x hx, Hd.differentiable_at $ (is_open_Ioo.re_prod_im is_open_Ioo).mem_nhds hx.1\n\n/-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function\nover the boundary of a rectangle equals zero. More precisely, if `f` is complex differentiable on a\nclosed rectangle, then its integral over the boundary of the rectangle equals zero. -/\n\n\n/-- If `f : \u2102 \u2192 E` is continuous the closed annulus `r \u2264 \u2225z - c\u2225 \u2264 R`, `0 < r \u2264 R`, and is complex\ndifferentiable at all but countably many points of its interior, then the integrals of\n`f z / (z - c)` (formally, `(z - c)\u207b\u00b9 \u2022 f z`) over the circles `\u2225z - c\u2225 = r` and `\u2225z - c\u2225 = R` are\nequal to each other. -/\nlemma circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable\n  {c : \u2102} {r R : \u211d} (h0 : 0 < r) (hle : r \u2264 R) {f : \u2102 \u2192 E} {s : set \u2102} (hs : countable s)\n  (hc : continuous_on f (closed_ball c R \\ ball c r))\n  (hd : \u2200 z \u2208 ball c R \\ closed_ball c r \\ s, differentiable_at \u2102 f z) :\n  \u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z = \u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 f z :=\nbegin\n  /- We apply the previous lemma to `\u03bb z, f (c + exp z)` on the rectangle\n  `[log r, log R] \u00d7 [0, 2 * \u03c0]`. -/\n  set A := closed_ball c R \\ ball c r,\n  obtain \u27e8a, rfl\u27e9 : \u2203 a, real.exp a = r, from \u27e8real.log r, real.exp_log h0\u27e9,\n  obtain \u27e8b, rfl\u27e9 : \u2203 b, real.exp b = R, from \u27e8real.log R, real.exp_log (h0.trans_le hle)\u27e9,\n  rw [real.exp_le_exp] at hle,\n  -- Unfold definition of `circle_integral` and cancel some terms.\n  suffices : \u222b \u03b8 in 0..2 * \u03c0, I \u2022 f (circle_map c (real.exp b) \u03b8) =\n    \u222b \u03b8 in 0..2 * \u03c0, I \u2022 f (circle_map c (real.exp a) \u03b8),\n    by simpa only [circle_integral, add_sub_cancel', of_real_exp, \u2190 exp_add, smul_smul,\n      \u2190 div_eq_mul_inv, mul_div_cancel_left _ (circle_map_ne_center (real.exp_pos _).ne'),\n      circle_map_sub_center, deriv_circle_map],\n  set R := [a, b] \u00d7\u2102 [0, 2 * \u03c0],\n  set g : \u2102 \u2192 \u2102 := (+) c \u2218 exp,\n  have hdg : differentiable \u2102 g := differentiable_exp.const_add _,\n  replace hs : countable (g \u207b\u00b9' s) := (hs.preimage (add_right_injective c)).preimage_cexp,\n  have h_maps : maps_to g R A,\n  { rintro z \u27e8h, -\u27e9, simpa [dist_eq, g, abs_exp, hle] using h.symm },\n  replace hc : continuous_on (f \u2218 g) R, from hc.comp hdg.continuous.continuous_on h_maps,\n  replace hd : \u2200 z \u2208 (Ioo (min a b) (max a b) \u00d7\u2102 Ioo (min 0 (2 * \u03c0)) (max 0 (2 * \u03c0))) \\ g \u207b\u00b9' s,\n    differentiable_at \u2102 (f \u2218 g) z,\n  { refine \u03bb z hz, (hd (g z) \u27e8_, hz.2\u27e9).comp z (hdg _),\n    simpa [g, dist_eq, abs_exp, hle, and.comm] using hz.1.1 },\n  simpa [g, circle_map, exp_periodic _, sub_eq_zero, \u2190 exp_add]\n    using integral_boundary_rect_eq_zero_of_differentiable_on_off_countable _ \u27e8a, 0\u27e9 \u27e8b, 2 * \u03c0\u27e9\n      _ hs hc hd\nend\n\n/-- **Cauchy-Goursat theorem** for an annulus. If `f : \u2102 \u2192 E` is continuous on the closed annulus\n`r \u2264 \u2225z - c\u2225 \u2264 R`, `0 < r \u2264 R`, and is complex differentiable at all but countably many points of\nits interior, then the integrals of `f` over the circles `\u2225z - c\u2225 = r` and `\u2225z - c\u2225 = R` are equal\nto each other. -/\nlemma circle_integral_eq_of_differentiable_on_annulus_off_countable\n  {c : \u2102} {r R : \u211d} (h0 : 0 < r) (hle : r \u2264 R) {f : \u2102 \u2192 E} {s : set \u2102} (hs : countable s)\n  (hc : continuous_on f (closed_ball c R \\ ball c r))\n  (hd : \u2200 z \u2208 ball c R \\ closed_ball c r \\ s, differentiable_at \u2102 f z) :\n  \u222e z in C(c, R), f z = \u222e z in C(c, r), f z :=\ncalc \u222e z in C(c, R), f z = \u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 (z - c) \u2022 f z :\n  (circle_integral.integral_sub_inv_smul_sub_smul _ _ _ _).symm\n... = \u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 (z - c) \u2022 f z :\n  circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable h0 hle hs\n    ((continuous_on_id.sub continuous_on_const).smul hc)\n    (\u03bb z hz, (differentiable_at_id.sub_const _).smul (hd z hz))\n... = \u222e z in C(c, r), f z : circle_integral.integral_sub_inv_smul_sub_smul _ _ _ _\n\n/-- **Cauchy integral formula** for the value at the center of a disc. If `f` is continuous on a\npunctured closed disc of radius `R`, is differentiable at all but countably many points of the\ninterior of this disc, and has a limit `y` at the center of the disc, then the integral\n$\\oint_{\u2225z-c\u2225=R} \\frac{f(z)}{z-c}\\,dz$ is equal to $2\u03c0iy`. -/\nlemma circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto\n  {c : \u2102} {R : \u211d} (h0 : 0 < R) {f : \u2102 \u2192 E} {y : E} {s : set \u2102} (hs : countable s)\n  (hc : continuous_on f (closed_ball c R \\ {c}))\n  (hd : \u2200 z \u2208 ball c R \\ {c} \\ s, differentiable_at \u2102 f z) (hy : tendsto f (\ud835\udcdd[{c}\u1d9c] c) (\ud835\udcdd y)) :\n  \u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z = (2 * \u03c0 * I : \u2102) \u2022 y :=\nbegin\n  rw [\u2190 sub_eq_zero, \u2190 norm_le_zero_iff],\n  refine le_of_forall_le_of_dense (\u03bb \u03b5 \u03b50, _),\n  obtain \u27e8\u03b4, \u03b40, h\u03b4\u27e9 :\n    \u2203 \u03b4 > (0 : \u211d), \u2200 z \u2208 closed_ball c \u03b4 \\ {c}, dist (f z) y < \u03b5 / (2 * \u03c0),\n    from ((nhds_within_has_basis nhds_basis_closed_ball _).tendsto_iff nhds_basis_ball).1 hy _\n      (div_pos \u03b50 real.two_pi_pos),\n  obtain \u27e8r, hr0, hr\u03b4, hrR\u27e9 : \u2203 r, 0 < r \u2227 r \u2264 \u03b4 \u2227 r \u2264 R :=\n    \u27e8min \u03b4 R, lt_min \u03b40 h0, min_le_left _ _, min_le_right _ _\u27e9,\n  have hsub : closed_ball c R \\ ball c r \u2286 closed_ball c R \\ {c},\n    from diff_subset_diff_right (singleton_subset_iff.2 $ mem_ball_self hr0),\n  have hsub' : ball c R \\ closed_ball c r \u2286 ball c R \\ {c},\n    from diff_subset_diff_right (singleton_subset_iff.2 $ mem_closed_ball_self hr0.le),\n  have hzne : \u2200 z \u2208 sphere c r, z \u2260 c,\n    from \u03bb z hz, ne_of_mem_of_not_mem hz (\u03bb h, hr0.ne' $ dist_self c \u25b8 eq.symm h),\n  /- The integral `\u222e z in C(c, r), f z / (z - c)` does not depend on `0 < r \u2264 R` and tends to\n  `2\u03c0Iy` as `r \u2192 0`. -/\n  calc \u2225(\u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z) - (2 * \u2191\u03c0 * I) \u2022 y\u2225\n      = \u2225(\u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 f z) - \u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 y\u2225 :\n    begin\n      congr' 2,\n      { exact circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable\n          hr0 hrR hs (hc.mono hsub) (\u03bb z hz, hd z \u27e8hsub' hz.1, hz.2\u27e9) },\n      { simp [hr0.ne'] }\n    end\n  ... = \u2225\u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 (f z - y)\u2225 :\n    begin\n      simp only [smul_sub],\n      have hc' : continuous_on (\u03bb z, (z - c)\u207b\u00b9) (sphere c r),\n        from (continuous_on_id.sub continuous_on_const).inv\u2080 (\u03bb z hz, sub_ne_zero.2 $ hzne _ hz),\n      rw circle_integral.integral_sub; refine (hc'.smul _).circle_integrable hr0.le,\n      { exact hc.mono (subset_inter (sphere_subset_closed_ball.trans $\n          closed_ball_subset_closed_ball hrR) hzne) },\n      { exact continuous_on_const }\n    end\n  ... \u2264 2 * \u03c0 * r * (r\u207b\u00b9 * (\u03b5 / (2 * \u03c0))) :\n    begin\n      refine circle_integral.norm_integral_le_of_norm_le_const hr0.le (\u03bb z hz, _),\n      specialize hzne z hz,\n      rw [mem_sphere, dist_eq_norm] at hz,\n      rw [norm_smul, norm_inv, hz, \u2190 dist_eq_norm],\n      refine mul_le_mul_of_nonneg_left (h\u03b4 _ \u27e8_, hzne\u27e9).le (inv_nonneg.2 hr0.le),\n      rwa [mem_closed_ball_iff_norm, hz]\n    end\n  ... = \u03b5 : by { field_simp [hr0.ne', real.two_pi_pos.ne'], ac_refl }\nend\n\n/-- **Cauchy integral formula** for the value at the center of a disc. If `f : \u2102 \u2192 E` is continuous\non a closed disc of radius `R` and is complex differentiable at all but countably many points of its\ninterior, then the integral $\\oint_{|z-c|=R} \\frac{f(z)}{z-c}\\,dz$ is equal to $2\u03c0iy`. -/\nlemma circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable {R : \u211d} (h0 : 0 < R)\n  {f : \u2102 \u2192 E} {c : \u2102} {s : set \u2102} (hs : countable s)\n  (hc : continuous_on f (closed_ball c R)) (hd : \u2200 z \u2208 ball c R \\ s, differentiable_at \u2102 f z) :\n  \u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z = (2 * \u03c0 * I : \u2102) \u2022 f c :=\ncircle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto h0 hs\n  (hc.mono $ diff_subset _ _) (\u03bb z hz, hd z \u27e8hz.1.1, hz.2\u27e9)\n  (hc.continuous_at $ closed_ball_mem_nhds _ h0).continuous_within_at\n\n/-- **Cauchy-Goursat theorem** for a disk: if `f : \u2102 \u2192 E` is continuous on a closed disk\n`{z | \u2225z - c\u2225 \u2264 R}` and is complex differentiable at all but countably many points of its interior,\nthen the integral $\\oint_{|z-c|=R}f(z)\\,dz$ equals zero. -/\nlemma circle_integral_eq_zero_of_differentiable_on_off_countable {R : \u211d} (h0 : 0 \u2264 R) {f : \u2102 \u2192 E}\n  {c : \u2102} {s : set \u2102} (hs : countable s) (hc : continuous_on f (closed_ball c R))\n  (hd : \u2200 z \u2208 ball c R \\ s, differentiable_at \u2102 f z) :\n  \u222e z in C(c, R), f z = 0 :=\nbegin\n  rcases h0.eq_or_lt with rfl|h0, { apply circle_integral.integral_radius_zero },\n  calc \u222e z in C(c, R), f z = \u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 (z - c) \u2022 f z :\n    (circle_integral.integral_sub_inv_smul_sub_smul _ _ _ _).symm\n  ... = (2 * \u2191\u03c0 * I : \u2102) \u2022 (c - c) \u2022 f c :\n    circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable h0 hs\n      ((continuous_on_id.sub continuous_on_const).smul hc)\n      (\u03bb z hz, (differentiable_at_id.sub_const _).smul (hd z hz))\n  ... = 0 : by rw [sub_self, zero_smul, smul_zero]\nend\n\n/-- An auxiliary lemma for\n`complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable`. This lemma assumes\n`w \u2209 s` while the main lemma drops this assumption. -/\nlemma circle_integral_sub_inv_smul_of_differentiable_on_off_countable_aux {R : \u211d} {c w : \u2102}\n  {f : \u2102 \u2192 E} {s : set \u2102} (hs : countable s) (hw : w \u2208 ball c R \\ s)\n  (hc : continuous_on f (closed_ball c R)) (hd : \u2200 x \u2208 ball c R \\ s, differentiable_at \u2102 f x) :\n  \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z = (2 * \u03c0 * I : \u2102) \u2022 f w :=\nbegin\n  have hR : 0 < R := dist_nonneg.trans_lt hw.1,\n  set F : \u2102 \u2192 E := dslope f w,\n  have hws : countable (insert w s) := hs.insert _,\n  have hnhds : closed_ball c R \u2208 \ud835\udcdd w, from closed_ball_mem_nhds_of_mem hw.1,\n  have hcF : continuous_on F (closed_ball c R),\n    from (continuous_on_dslope $ closed_ball_mem_nhds_of_mem hw.1).2 \u27e8hc, hd _ hw\u27e9,\n  have hdF : \u2200 z \u2208 ball (c : \u2102) R \\ (insert w s), differentiable_at \u2102 F z,\n    from \u03bb z hz, (differentiable_at_dslope_of_ne\n      (ne_of_mem_of_not_mem (mem_insert _ _) hz.2).symm).2\n      (hd _ (diff_subset_diff_right (subset_insert _ _) hz)),\n  have HI := circle_integral_eq_zero_of_differentiable_on_off_countable hR.le hws hcF hdF,\n  have hne : \u2200 z \u2208 sphere c R, z \u2260 w, from \u03bb z hz, ne_of_mem_of_not_mem hz (ne_of_lt hw.1),\n  have hFeq : eq_on F (\u03bb z, (z - w)\u207b\u00b9 \u2022 f z - (z - w)\u207b\u00b9 \u2022 f w) (sphere c R),\n  { intros z hz,\n    calc F z = (z - w)\u207b\u00b9 \u2022 (f z - f w) : update_noteq (hne z hz) _ _\n    ... = (z - w)\u207b\u00b9 \u2022 f z - (z - w)\u207b\u00b9 \u2022 f w : smul_sub _ _ _ },\n  have hc' : continuous_on (\u03bb z, (z - w)\u207b\u00b9) (sphere c R),\n    from (continuous_on_id.sub continuous_on_const).inv\u2080 (\u03bb z hz, sub_ne_zero.2 $ hne z hz),\n  rw [\u2190 circle_integral.integral_sub_inv_of_mem_ball hw.1, \u2190 circle_integral.integral_smul_const,\n    \u2190 sub_eq_zero, \u2190 circle_integral.integral_sub, \u2190 circle_integral.integral_congr hR.le hFeq, HI],\n  exacts [(hc'.smul (hc.mono sphere_subset_closed_ball)).circle_integrable hR.le,\n    (hc'.smul continuous_on_const).circle_integrable hR.le]\nend\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is continuous on a closed disc of radius `R` and is\ncomplex differentiable at all but countably many points of its interior, then for any `w` in this\ninterior we have $\\frac{1}{2\u03c0i}\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=f(w)$.\n-/\nlemma two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable\n  {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E} {s : set \u2102} (hs : countable s) (hw : w \u2208 ball c R)\n  (hc : continuous_on f (closed_ball c R)) (hd : \u2200 x \u2208 ball c R \\ s, differentiable_at \u2102 f x) :\n  (2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z = f w :=\nbegin\n  have hR : 0 < R := dist_nonneg.trans_lt hw,\n  suffices : w \u2208 closure (ball c R \\ s),\n  { lift R to \u211d\u22650 using hR.le,\n    have A : continuous_at (\u03bb w, (2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) w,\n    { have := has_fpower_series_on_cauchy_integral\n      ((hc.mono sphere_subset_closed_ball).circle_integrable R.coe_nonneg) hR,\n      refine this.continuous_on.continuous_at (emetric.is_open_ball.mem_nhds _),\n      rwa metric.emetric_ball_nnreal },\n    have B : continuous_at f w, from hc.continuous_at (closed_ball_mem_nhds_of_mem hw),\n    refine tendsto_nhds_unique_of_frequently_eq A B ((mem_closure_iff_frequently.1 this).mono _),\n    intros z hz,\n    rw [circle_integral_sub_inv_smul_of_differentiable_on_off_countable_aux hs hz hc hd,\n      inv_smul_smul\u2080],\n    simp [real.pi_ne_zero, I_ne_zero] },\n  refine mem_closure_iff_nhds.2 (\u03bb t ht, _),\n  -- TODO: generalize to any vector space over `\u211d`\n  set g : \u211d \u2192 \u2102 := \u03bb x, w + x,\n  have : tendsto g (\ud835\udcdd 0) (\ud835\udcdd w),\n    from (continuous_const.add continuous_of_real).tendsto' 0 w (add_zero _),\n  rcases mem_nhds_iff_exists_Ioo_subset.1 (this $ inter_mem ht $ is_open_ball.mem_nhds hw)\n    with \u27e8l, u, hlu\u2080, hlu_sub\u27e9,\n  obtain \u27e8x, hx\u27e9 : (Ioo l u \\ g \u207b\u00b9' s).nonempty,\n  { refine nonempty_diff.2 (\u03bb hsub, _),\n    have : countable (Ioo l u),\n      from (hs.preimage ((add_right_injective w).comp of_real_injective)).mono hsub,\n    rw [\u2190 cardinal.mk_set_le_omega, cardinal.mk_Ioo_real (hlu\u2080.1.trans hlu\u2080.2)] at this,\n    exact this.not_lt cardinal.omega_lt_continuum },\n  exact \u27e8g x, (hlu_sub hx.1).1, (hlu_sub hx.1).2, hx.2\u27e9\nend\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is continuous on a closed disc of radius `R` and is\ncomplex differentiable at all but countably many points of its interior, then for any `w` in this\ninterior we have $\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=2\u03c0if(w)$.\n-/\nlemma circle_integral_sub_inv_smul_of_differentiable_on_off_countable\n  {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E} {s : set \u2102} (hs : countable s) (hw : w \u2208 ball c R)\n  (hc : continuous_on f (closed_ball c R)) (hd : \u2200 x \u2208 ball c R \\ s, differentiable_at \u2102 f x) :\n  \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z = (2 * \u03c0 * I : \u2102) \u2022 f w :=\nby { rw [\u2190 two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable\n  hs hw hc hd, smul_inv_smul\u2080], simp [real.pi_ne_zero, I_ne_zero] }\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is continuous on a closed disc of radius `R` and is\ncomplex differentiable on its interior, then for any `w` in this interior we have\n$\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=2\u03c0if(w)$.\n-/\nlemma _root_.diff_on_int_cont.circle_integral_sub_inv_smul {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E}\n  (h : diff_on_int_cont \u2102 f (closed_ball c R)) (hw : w \u2208 ball c R) :\n  \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z = (2 * \u03c0 * I : \u2102) \u2022 f w :=\ncircle_integral_sub_inv_smul_of_differentiable_on_off_countable countable_empty hw\n  h.continuous_on $ \u03bb z hz, h.differentiable_at $ ball_subset_interior_closed_ball hz.1\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is complex differentiable on a closed disc of radius\n`R`, then for any `w` in its interior we have $\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=2\u03c0if(w)$. -/\nlemma _root_.differentiable_on.circle_integral_sub_inv_smul {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E}\n  (hd : differentiable_on \u2102 f (closed_ball c R)) (hw : w \u2208 ball c R)  :\n  \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z = (2 * \u03c0 * I : \u2102) \u2022 f w :=\nhd.diff_on_int_cont.circle_integral_sub_inv_smul hw\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 \u2102` is continuous on a closed disc of radius `R` and is\ncomplex differentiable at all but countably many points of its interior, then for any `w` in this\ninterior we have $\\oint_{|z-c|=R}\\frac{f(z)}{z-w}dz=2\\pi i\\,f(w)$.\n-/\nlemma circle_integral_div_sub_of_differentiable_on_off_countable {R : \u211d} {c w : \u2102} {s : set \u2102}\n  (hs : countable s) (hw : w \u2208 ball c R) {f : \u2102 \u2192 \u2102} (hc : continuous_on f (closed_ball c R))\n  (hd : \u2200 z \u2208 ball c R \\ s, differentiable_at \u2102 f z) :\n  \u222e z in C(c, R), f z / (z - w) = 2 * \u03c0 * I * f w :=\nby simpa only [smul_eq_mul, div_eq_inv_mul]\n  using circle_integral_sub_inv_smul_of_differentiable_on_off_countable hs hw hc hd\n\n/-- If `f : \u2102 \u2192 E` is continuous on a closed ball of positive radius and is differentiable at all\nbut countably many points of the corresponding open ball, then it is analytic on the open ball with\ncoefficients of the power series given by Cauchy integral formulas. -/\nlemma has_fpower_series_on_ball_of_differentiable_off_countable {R : \u211d\u22650} {c : \u2102} {f : \u2102 \u2192 E}\n  {s : set \u2102} (hs : countable s) (hc : continuous_on f (closed_ball c R))\n  (hd : \u2200 z \u2208 ball c R \\ s, differentiable_at \u2102 f z) (hR : 0 < R) :\n  has_fpower_series_on_ball f (cauchy_power_series f c R) c R :=\n{ r_le := le_radius_cauchy_power_series _ _ _,\n  r_pos := ennreal.coe_pos.2 hR,\n  has_sum := \u03bb w hw,\n    begin\n      have hw' : c + w \u2208 ball c R,\n        by simpa only [add_mem_ball_iff_norm, \u2190 coe_nnnorm, mem_emetric_ball_zero_iff,\n          nnreal.coe_lt_coe, ennreal.coe_lt_coe] using hw,\n      rw \u2190 two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable hs\n        hw' hc hd,\n      exact (has_fpower_series_on_cauchy_integral\n        ((hc.mono sphere_subset_closed_ball).circle_integrable R.2) hR).has_sum hw\n    end }\n\n/-- If `f : \u2102 \u2192 E` is continuous on a closed ball of positive radius and is complex differentiable\non its interior, then it is analytic on the open ball with coefficients of the power series given by\nCauchy integral formulas. -/\nlemma _root_.diff_on_int_cont.has_fpower_series_on_ball {R : \u211d\u22650} {c : \u2102} {f : \u2102 \u2192 E}\n  (hf : diff_on_int_cont \u2102 f (closed_ball c R)) (hR : 0 < R) :\n  has_fpower_series_on_ball f (cauchy_power_series f c R) c R :=\nhas_fpower_series_on_ball_of_differentiable_off_countable countable_empty hf.continuous_on\n  (\u03bb z hz, hf.differentiable_at $ ball_subset_interior_closed_ball hz.1) hR\n\n/-- If `f : \u2102 \u2192 E` is complex differentiable on a closed disc of positive radius, then it is\nanalytic on the corresponding open disc, and the coefficients of the power series are given by\nCauchy integral formulas. See also\n`complex.has_fpower_series_on_ball_of_differentiable_off_countable` for a version of this lemma with\nweaker assumptions. -/\nprotected lemma _root_.differentiable_on.has_fpower_series_on_ball {R : \u211d\u22650} {c : \u2102} {f : \u2102 \u2192 E}\n  (hd : differentiable_on \u2102 f (closed_ball c R)) (hR : 0 < R) :\n  has_fpower_series_on_ball f (cauchy_power_series f c R) c R :=\nhd.diff_on_int_cont.has_fpower_series_on_ball hR\n\n/-- If `f : \u2102 \u2192 E` is complex differentiable on some set `s`, then it is analytic at any point `z`\nsuch that `s \u2208 \ud835\udcdd z` (equivalently, `z \u2208 interior s`). -/\nprotected lemma _root_.differentiable_on.analytic_at {s : set \u2102} {f : \u2102 \u2192 E} {z : \u2102}\n  (hd : differentiable_on \u2102 f s) (hz : s \u2208 \ud835\udcdd z) : analytic_at \u2102 f z :=\nbegin\n  rcases nhds_basis_closed_ball.mem_iff.1 hz with \u27e8R, hR0, hRs\u27e9,\n  lift R to \u211d\u22650 using hR0.le,\n  exact ((hd.mono hRs).has_fpower_series_on_ball hR0).analytic_at\nend\n\n/-- A complex differentiable function `f : \u2102 \u2192 E` is analytic at every point. -/\nprotected lemma _root_.differentiable.analytic_at {f : \u2102 \u2192 E} (hf : differentiable \u2102 f) (z : \u2102) :\n  analytic_at \u2102 f z :=\nhf.differentiable_on.analytic_at univ_mem\n\n/-- When `f : \u2102 \u2192 E` is differentiable, the `cauchy_power_series f z R` represents `f` as a power\nseries centered at `z` in the entirety of `\u2102`, regardless of `R : \u211d\u22650`, with  `0 < R`. -/\nprotected lemma _root_.differentiable.has_fpower_series_on_ball {f : \u2102 \u2192 E}\n  (h : differentiable \u2102 f) (z : \u2102) {R : \u211d\u22650} (hR : 0 < R) :\n  has_fpower_series_on_ball f (cauchy_power_series f z R) z \u221e :=\n(h.differentiable_on.has_fpower_series_on_ball hR).r_eq_top_of_exists $ \u03bb r hr,\n  \u27e8_, h.differentiable_on.has_fpower_series_on_ball hr\u27e9\n\nend complex\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/complex/cauchy_integral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7431204681234429}}
{"text": "/-\nCopyright (c) 2022 Kalle Kyt\u00f6l\u00e4. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kyt\u00f6l\u00e4\n-/\nimport measure_theory.integral.interval_integral\nimport analysis.special_functions.integrals\n\n/-!\n# The layer cake formula / Cavalieri's principle / tail probability formula\n\nIn this file we prove the following layer cake formula.\n\nConsider a non-negative measurable function `f` on a sigma-finite measure space. Apply pointwise\nto it an increasing absolutely continuous function `G : \u211d\u22650 \u2192 \u211d\u22650` vanishing at the origin, with\nderivative `G' = g` on the positive real line (in other words, `G` a primitive of a non-negative\nlocally integrable function `g` on the positive real line). Then the integral of the result,\n`\u222b G \u2218 f`, can be written as the integral over the positive real line of the \"tail measures\" of `f`\n(i.e., a function giving the measures of the sets on which `f` exceeds different positive real\nvalues) weighted by `g`. In probability theory contexts, the \"tail measures\" could be referred to\nas \"tail probabilities\" of the random variable `f`, or as values of the \"complementary cumulative\ndistribution function\" of the random variable `f`. The terminology \"tail probability formula\" is\ntherefore occasionally used for the layer cake formula (or a standard application of it).\n\nThe essence of the (mathematical) proof is Fubini's theorem.\n\nWe also give the two most common applications of the layer cake formula\n * a representation of the integral of a nonnegative function f:\n   \u222b f(\u03c9) \u2202\u03bc(\u03c9) = \u222b \u03bc {\u03c9 | f(\u03c9) \u2265 t} dt\n * a representation of the integral of the p:th power of a nonnegative function f:\n   \u222b f(\u03c9)^p \u2202\u03bc(\u03c9) = p * \u222b t^(p-1) * \u03bc {\u03c9 | f(\u03c9) \u2265 t} dt .\n\nVariants of the formulas with measures of sets of the form {\u03c9 | f(\u03c9) > t} instead of {\u03c9 | f(\u03c9) \u2265 t}\nare also included.\n\n## Main results\n\n * `lintegral_comp_eq_lintegral_meas_le_mul` and `lintegral_comp_eq_lintegral_meas_lt_mul`:\n   The general layer cake formulas with Lebesgue integrals, written in terms of measures of\n   sets of the forms {\u03c9 | t \u2264 f(\u03c9)} and {\u03c9 | t < f(\u03c9)}, respectively.\n * `lintegral_eq_lintegral_meas_le` and `lintegral_eq_lintegral_meas_lt`:\n   The most common special cases of the layer cake formulas, stating that for a nonnegative\n   function f we have \u222b f(\u03c9) \u2202\u03bc(\u03c9) = \u222b \u03bc {\u03c9 | f(\u03c9) \u2265 t} dt and\n   \u222b f(\u03c9) \u2202\u03bc(\u03c9) = \u222b \u03bc {\u03c9 | f(\u03c9) > t} dt, respectively.\n * `lintegral_rpow_eq_lintegral_meas_le_mul` and `lintegral_rpow_eq_lintegral_meas_lt_mul`:\n   Other common special cases of the layer cake formulas, stating that for a nonnegative function f\n   and p > 0, we have \u222b f(\u03c9)^p \u2202\u03bc(\u03c9) = p * \u222b \u03bc {\u03c9 | f(\u03c9) \u2265 t} * t^(p-1) dt and\n   \u222b f(\u03c9)^p \u2202\u03bc(\u03c9) = p * \u222b \u03bc {\u03c9 | f(\u03c9) > t} * t^(p-1) dt, respectively.\n\n## Tags\n\nlayer cake representation, Cavalieri's principle, tail probability formula\n-/\n\nnoncomputable theory\nopen_locale ennreal measure_theory\nopen set measure_theory filter\n\n/-! ### Layercake formula -/\nsection layercake\n\nnamespace measure_theory\n\nvariables {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d} {g : \u211d \u2192 \u211d} {s : set \u03b1}\n\n/-- An auxiliary version of the layer cake formula (Cavalieri's principle, tail probability\nformula), with a measurability assumption that would also essentially follow from the\nintegrability assumptions.\n\nSee `measure_theory.lintegral_comp_eq_lintegral_meas_le_mul` and\n`measure_theory.lintegral_comp_eq_lintegral_meas_lt_mul` for the main formulations of the layer\ncake formula. -/\nlemma lintegral_comp_eq_lintegral_meas_le_mul_of_measurable (\u03bc : measure \u03b1) [sigma_finite \u03bc]\n  (f_nn : 0 \u2264 f) (f_mble : measurable f)\n  (g_intble : \u2200 t > 0, interval_integrable g volume 0 t)\n  (g_mble : measurable g) (g_nn : \u2200 t > 0, 0 \u2264 g t) :\n  \u222b\u207b \u03c9, ennreal.of_real (\u222b t in 0 .. (f \u03c9), g t) \u2202\u03bc\n    = \u222b\u207b t in Ioi 0, (\u03bc {a : \u03b1 | t \u2264 f a}) * ennreal.of_real (g t) :=\nbegin\n  have g_intble' : \u2200 (t : \u211d), 0 \u2264 t \u2192 interval_integrable g volume 0 t,\n  { intros t ht,\n    cases eq_or_lt_of_le ht,\n    { simp [\u2190 h], },\n    { exact g_intble t h, }, },\n  have integrand_eq : \u2200 \u03c9, ennreal.of_real (\u222b t in 0 .. (f \u03c9), g t)\n                           = \u222b\u207b t in Ioc 0 (f \u03c9), ennreal.of_real (g t),\n  { intro \u03c9,\n    have g_ae_nn : 0 \u2264\u1d50[volume.restrict (Ioc 0 (f \u03c9))] g,\n    { filter_upwards [self_mem_ae_restrict (measurable_set_Ioc : measurable_set (Ioc 0 (f \u03c9)))]\n        with x hx using g_nn x hx.1, },\n    rw \u2190 of_real_integral_eq_lintegral_of_real (g_intble' (f \u03c9) (f_nn \u03c9)).1 g_ae_nn,\n    congr,\n    exact interval_integral.integral_of_le (f_nn \u03c9), },\n  simp_rw [integrand_eq, \u2190 lintegral_indicator (\u03bb t, ennreal.of_real (g t)) measurable_set_Ioc,\n           \u2190 lintegral_indicator _ measurable_set_Ioi],\n  rw lintegral_lintegral_swap,\n  { apply congr_arg,\n    funext s,\n    have aux\u2081 : (\u03bb x, (Ioc 0 (f x)).indicator (\u03bb (t : \u211d), ennreal.of_real (g t)) s)\n                = (\u03bb x, (ennreal.of_real (g s) * (Ioi (0 : \u211d)).indicator (\u03bb _, 1) s)\n                             * (Ici s).indicator (\u03bb (t : \u211d), (1 : \u211d\u22650\u221e)) (f x)),\n    { funext a,\n      by_cases s \u2208 Ioc (0 : \u211d) (f a),\n      { simp only [h, (show s \u2208 Ioi (0 : \u211d), from h.1),\n                   (show f a \u2208 Ici s, from h.2), indicator_of_mem, mul_one], },\n      { have h_copy := h,\n        simp only [mem_Ioc, not_and, not_le] at h,\n        by_cases h' : 0 < s,\n        { simp only [h_copy, h h', indicator_of_not_mem, not_false_iff, mem_Ici, not_le,\n                     mul_zero], },\n        { have : s \u2209 Ioi (0 : \u211d) := h',\n          simp only [this, h', indicator_of_not_mem, not_false_iff, mul_zero, zero_mul, mem_Ioc,\n                     false_and], }, }, },\n    simp_rw aux\u2081,\n    rw lintegral_const_mul',\n    swap, { apply ennreal.mul_ne_top ennreal.of_real_ne_top,\n            by_cases s \u2208 Ioi (0 : \u211d); { simp [h], }, },\n    simp_rw [(show (\u03bb a, (Ici s).indicator (\u03bb (t : \u211d), (1 : \u211d\u22650\u221e)) (f a))\n                   = (\u03bb a, {a : \u03b1 | s \u2264 f a}.indicator (\u03bb _, 1) a),\n              by { funext a, by_cases s \u2264 f a; simp [h], })],\n    rw lintegral_indicator,\n    swap, { exact f_mble measurable_set_Ici, },\n    rw [lintegral_one, measure.restrict_apply measurable_set.univ, univ_inter, indicator_mul_left,\n        mul_assoc,\n        (show (Ioi 0).indicator (\u03bb (_x : \u211d), (1 : \u211d\u22650\u221e)) s * \u03bc {a : \u03b1 | s \u2264 f a}\n              = (Ioi 0).indicator (\u03bb (_x : \u211d), 1 * \u03bc {a : \u03b1 | s \u2264 f a}) s,\n        by { by_cases 0 < s; simp [h], })],\n    simp_rw [mul_comm _ (ennreal.of_real _), one_mul],\n    refl, },\n  have aux\u2082 : function.uncurry\n              (\u03bb (x : \u03b1) (y : \u211d), (Ioc 0 (f x)).indicator (\u03bb (t : \u211d), ennreal.of_real (g t)) y)\n              = {p : \u03b1 \u00d7 \u211d | p.2 \u2208 Ioc 0 (f p.1)}.indicator (\u03bb p, ennreal.of_real (g p.2)),\n  { funext p,\n    cases p,\n    rw function.uncurry_apply_pair,\n    by_cases p_snd \u2208 Ioc 0 (f p_fst),\n    { have h' : (p_fst, p_snd) \u2208 {p : \u03b1 \u00d7 \u211d | p.snd \u2208 Ioc 0 (f p.fst)} := h,\n      rw [set.indicator_of_mem h', set.indicator_of_mem h], },\n    { have h' : (p_fst, p_snd) \u2209 {p : \u03b1 \u00d7 \u211d | p.snd \u2208 Ioc 0 (f p.fst)} := h,\n      rw [set.indicator_of_not_mem h', set.indicator_of_not_mem h], }, },\n  rw aux\u2082,\n  have mble := measurable_set_region_between_oc measurable_zero f_mble measurable_set.univ,\n  simp_rw [mem_univ, pi.zero_apply, true_and] at mble,\n  exact (ennreal.measurable_of_real.comp (g_mble.comp measurable_snd)).ae_measurable.indicator mble,\nend\n\n/-- The layer cake formula / Cavalieri's principle / tail probability formula:\n\nLet `f` be a non-negative measurable function on a sigma-finite measure space. Let `G` be an\nincreasing absolutely continuous function on the positive real line, vanishing at the origin,\nwith derivative `G' = g`. Then the integral of the composition `G \u2218 f` can be written as\nthe integral over the positive real line of the \"tail measures\" `\u03bc {\u03c9 | f(\u03c9) \u2265 t}` of `f`\nweighted by `g`.\n\nRoughly speaking, the statement is: `\u222b\u207b (G \u2218 f) \u2202\u03bc = \u222b\u207b t in 0 .. \u221e, g(t) * \u03bc {\u03c9 | f(\u03c9) \u2265 t}`.\n\nSee `lintegral_comp_eq_lintegral_meas_lt_mul` for a version with sets of the form `{\u03c9 | f(\u03c9) > t}`\ninstead. -/\ntheorem lintegral_comp_eq_lintegral_meas_le_mul (\u03bc : measure \u03b1) [sigma_finite \u03bc]\n  (f_nn : 0 \u2264 f) (f_mble : measurable f)\n  (g_intble : \u2200 t > 0, interval_integrable g volume 0 t)\n  (g_nn : \u2200\u1d50 t \u2202(volume.restrict (Ioi 0)), 0 \u2264 g t) :\n  \u222b\u207b \u03c9, ennreal.of_real (\u222b t in 0 .. f \u03c9, g t) \u2202\u03bc\n    = \u222b\u207b t in Ioi 0, \u03bc {a : \u03b1 | t \u2264 f a} * ennreal.of_real (g t) :=\nbegin\n  have ex_G : \u2203 (G : \u211d \u2192 \u211d), measurable G \u2227 0 \u2264 G \u2227 g =\u1d50[volume.restrict (Ioi 0)] G,\n  { refine ae_measurable.exists_measurable_nonneg _ g_nn,\n    exact ae_measurable_Ioi_of_forall_Ioc (\u03bb t ht, (g_intble t ht).1.1.ae_measurable), },\n  rcases ex_G with \u27e8G, G_mble, G_nn, g_eq_G\u27e9,\n  have g_eq_G_on : \u2200 t, g =\u1d50[volume.restrict (Ioc 0 t)] G,\n    from \u03bb t, ae_mono (measure.restrict_mono Ioc_subset_Ioi_self le_rfl) g_eq_G,\n  have G_intble : \u2200 t > 0, interval_integrable G volume 0 t,\n  { refine \u03bb t t_pos, \u27e8integrable_on.congr_fun' (g_intble t t_pos).1 (g_eq_G_on t), _\u27e9,\n    rw Ioc_eq_empty_of_le t_pos.lt.le,\n    exact integrable_on_empty, },\n  have eq\u2081 : \u222b\u207b t in Ioi 0, \u03bc {a : \u03b1 | t \u2264 f a} * ennreal.of_real (g t)\n             = \u222b\u207b t in Ioi 0, \u03bc {a : \u03b1 | t \u2264 f a} * ennreal.of_real (G t),\n  { apply lintegral_congr_ae,\n    filter_upwards [g_eq_G] with a ha,\n    rw [ha], },\n  have eq\u2082 : \u2200 \u03c9, \u222b t in 0..f \u03c9, g t = \u222b t in 0..f \u03c9, G t,\n  { refine \u03bb \u03c9, interval_integral.integral_congr_ae _,\n    have f\u03c9_nn : 0 \u2264 f \u03c9 := f_nn \u03c9,\n    rw [uIoc_of_le f\u03c9_nn,\n        \u2190 ae_restrict_iff' (measurable_set_Ioc : measurable_set (Ioc (0 : \u211d) (f \u03c9)))],\n    exact g_eq_G_on (f \u03c9), },\n  simp_rw [eq\u2081, eq\u2082],\n  exact lintegral_comp_eq_lintegral_meas_le_mul_of_measurable \u03bc f_nn f_mble\n    G_intble G_mble (\u03bb t t_pos, G_nn t),\nend\n\n/-- The standard case of the layer cake formula / Cavalieri's principle / tail probability formula:\n\nFor a nonnegative function `f` on a sigma-finite measure space, the Lebesgue integral of `f` can\nbe written (roughly speaking) as: `\u222b\u207b f \u2202\u03bc = \u222b\u207b t in 0 .. \u221e, \u03bc {\u03c9 | f(\u03c9) \u2265 t}`.\n\nSee `lintegral_eq_lintegral_meas_lt` for a version with sets of the form `{\u03c9 | f(\u03c9) > t}`\ninstead. -/\ntheorem lintegral_eq_lintegral_meas_le (\u03bc : measure \u03b1) [sigma_finite \u03bc]\n  (f_nn : 0 \u2264 f) (f_mble : measurable f) :\n  \u222b\u207b \u03c9, ennreal.of_real (f \u03c9) \u2202\u03bc = \u222b\u207b t in Ioi 0, (\u03bc {a : \u03b1 | t \u2264 f a}) :=\nbegin\n  set cst := \u03bb (t : \u211d), (1 : \u211d) with def_cst,\n  have cst_intble : \u2200 t > 0, interval_integrable cst volume 0 t,\n    from \u03bb _ _, interval_integrable_const,\n  have key := lintegral_comp_eq_lintegral_meas_le_mul \u03bc f_nn f_mble cst_intble\n              (eventually_of_forall (\u03bb t, zero_le_one)),\n  simp_rw [def_cst, ennreal.of_real_one, mul_one] at key,\n  rw \u2190 key,\n  congr' with \u03c9,\n  simp only [interval_integral.integral_const, sub_zero, algebra.id.smul_eq_mul, mul_one],\nend\n\n/-- An application of the layer cake formula / Cavalieri's principle / tail probability formula:\n\nFor a nonnegative function `f` on a sigma-finite measure space, the Lebesgue integral of `f` can\nbe written (roughly speaking) as: `\u222b\u207b f^p \u2202\u03bc = p * \u222b\u207b t in 0 .. \u221e, t^(p-1) * \u03bc {\u03c9 | f(\u03c9) \u2265 t}`.\n\nSee `lintegral_rpow_eq_lintegral_meas_lt_mul` for a version with sets of the form `{\u03c9 | f(\u03c9) > t}`\ninstead. -/\ntheorem lintegral_rpow_eq_lintegral_meas_le_mul (\u03bc : measure \u03b1) [sigma_finite \u03bc]\n  (f_nn : 0 \u2264 f) (f_mble : measurable f) {p : \u211d} (p_pos: 0 < p) :\n  \u222b\u207b \u03c9, ennreal.of_real ((f \u03c9)^p) \u2202\u03bc\n    = (ennreal.of_real p) * \u222b\u207b t in Ioi 0, (\u03bc {a : \u03b1 | t \u2264 f a}) * ennreal.of_real (t^(p-1)) :=\nbegin\n  have one_lt_p : -1 < p - 1 := by linarith,\n  have obs : \u2200 (x : \u211d), (\u222b (t : \u211d) in 0..x, t^(p-1)) = x^p / p,\n  { intros x,\n    rw integral_rpow (or.inl one_lt_p),\n    simp [real.zero_rpow p_pos.ne.symm], },\n  set g := \u03bb (t : \u211d), t^(p-1) with g_def,\n  have g_nn : \u2200\u1d50 t \u2202(volume.restrict (Ioi (0 : \u211d))), 0 \u2264 g t,\n  { filter_upwards [self_mem_ae_restrict (measurable_set_Ioi : measurable_set (Ioi (0 : \u211d)))],\n    intros t t_pos,\n    rw g_def,\n    exact real.rpow_nonneg_of_nonneg (mem_Ioi.mp t_pos).le (p - 1), },\n  have g_intble : \u2200 t > 0, interval_integrable g volume 0 t,\n    from \u03bb _ _, interval_integral.interval_integrable_rpow' one_lt_p,\n  have key := lintegral_comp_eq_lintegral_meas_le_mul \u03bc f_nn f_mble g_intble g_nn,\n  simp_rw [g_def] at key,\n  rw [\u2190 key, \u2190 lintegral_const_mul (ennreal.of_real p)]; simp_rw obs,\n  { congr' with \u03c9,\n    rw [\u2190 ennreal.of_real_mul p_pos.le, mul_div_cancel' ((f \u03c9)^p) p_pos.ne.symm], },\n  { exact ((f_mble.pow measurable_const).div_const p).ennreal_of_real, },\nend\n\nend measure_theory\n\nend layercake\n\nsection layercake_lt\n\nopen measure_theory\n\nvariables {\u03b1 : Type*} [measurable_space \u03b1] (\u03bc : measure \u03b1)\nvariables {\u03b2 : Type*} [measurable_space \u03b2] [measurable_singleton_class \u03b2]\n\nnamespace measure\n\nlemma meas_le_ne_meas_lt_subset_meas_pos {R : Type*} [linear_order R]\n  [measurable_space R] [measurable_singleton_class R] {g : \u03b1 \u2192 R} (g_mble : measurable g) {t : R}\n  (ht : \u03bc {a : \u03b1 | t \u2264 g a} \u2260 \u03bc {a : \u03b1 | t < g a}) :\n  0 < \u03bc {a : \u03b1 | g a = t} :=\nbegin\n  have uni : {a : \u03b1 | t \u2264 g a } = {a : \u03b1 | t < g a} \u222a {a : \u03b1 | t = g a},\n  { ext a,\n    simp only [mem_set_of_eq, mem_union],\n    apply le_iff_lt_or_eq, },\n  rw (show {a : \u03b1 | t = g a} = {a : \u03b1 | g a = t}, by simp_rw [eq_comm]) at uni,\n  have disj : {a : \u03b1 | t < g a} \u2229 {a : \u03b1 | g a = t} = \u2205,\n  { ext a,\n    simp only [mem_inter_iff, mem_set_of_eq, mem_empty_iff_false, iff_false, not_and],\n    exact ne_of_gt, },\n  have \u03bc_add : \u03bc {a : \u03b1 | t \u2264 g a} = \u03bc {a : \u03b1 | t < g a} + \u03bc {a : \u03b1 | g a = t},\n    by rw [uni, measure_union (disjoint_iff_inter_eq_empty.mpr disj)\n                              (g_mble (finite.measurable_set (finite_singleton t)))],\n  by_contra con,\n  rw [not_lt, nonpos_iff_eq_zero] at con,\n  rw [con, add_zero] at \u03bc_add,\n  exact ht \u03bc_add,\nend\n\nlemma countable_meas_le_ne_meas_lt [sigma_finite \u03bc] {R : Type*} [linear_order R]\n  [measurable_space R] [measurable_singleton_class R] {g : \u03b1 \u2192 R} (g_mble : measurable g) :\n  {t : R | \u03bc {a : \u03b1 | t \u2264 g a } \u2260 \u03bc {a : \u03b1 | t < g a}}.countable :=\ncountable.mono (show _, from \u03bb t ht, meas_le_ne_meas_lt_subset_meas_pos \u03bc g_mble ht)\n               (measure.countable_meas_level_set_pos g_mble)\n\nlemma meas_le_ae_eq_meas_lt [sigma_finite \u03bc] {R : Type*} [linear_order R] [measurable_space R]\n  [measurable_singleton_class R] (\u03bd : measure R) [has_no_atoms \u03bd]\n  {g : \u03b1 \u2192 R} (g_mble : measurable g) :\n  (\u03bb t, \u03bc {a : \u03b1 | t \u2264 g a}) =\u1d50[\u03bd] (\u03bb t, \u03bc {a : \u03b1 | t < g a}) :=\nset.countable.measure_zero (measure.countable_meas_le_ne_meas_lt \u03bc g_mble) _\n\nend measure\n\nvariables {f : \u03b1 \u2192 \u211d} {g : \u211d \u2192 \u211d} {s : set \u03b1}\n\n/-- The layer cake formula / Cavalieri's principle / tail probability formula:\n\nLet `f` be a non-negative measurable function on a sigma-finite measure space. Let `G` be an\nincreasing absolutely continuous function on the positive real line, vanishing at the origin,\nwith derivative `G' = g`. Then the integral of the composition `G \u2218 f` can be written as\nthe integral over the positive real line of the \"tail measures\" `\u03bc {\u03c9 | f(\u03c9) > t}` of `f`\nweighted by `g`.\n\nRoughly speaking, the statement is: `\u222b\u207b (G \u2218 f) \u2202\u03bc = \u222b\u207b t in 0 .. \u221e, g(t) * \u03bc {\u03c9 | f(\u03c9) > t}`.\n\nSee `lintegral_comp_eq_lintegral_meas_le_mul` for a version with sets of the form `{\u03c9 | f(\u03c9) \u2265 t}`\ninstead. -/\ntheorem lintegral_comp_eq_lintegral_meas_lt_mul (\u03bc : measure \u03b1) [sigma_finite \u03bc]\n  (f_nn : 0 \u2264 f) (f_mble : measurable f)\n  (g_intble : \u2200 t > 0, interval_integrable g volume 0 t)\n  (g_nn : \u2200\u1d50 t \u2202(volume.restrict (Ioi 0)), 0 \u2264 g t) :\n  \u222b\u207b \u03c9, ennreal.of_real (\u222b t in 0 .. f \u03c9, g t) \u2202\u03bc\n    = \u222b\u207b t in Ioi 0, \u03bc {a : \u03b1 | t < f a} * ennreal.of_real (g t) :=\nbegin\n  rw lintegral_comp_eq_lintegral_meas_le_mul \u03bc f_nn f_mble g_intble g_nn,\n  apply lintegral_congr_ae,\n  filter_upwards [measure.meas_le_ae_eq_meas_lt \u03bc (volume.restrict (Ioi 0)) f_mble] with t ht,\n  rw ht,\nend\n\n/-- The standard case of the layer cake formula / Cavalieri's principle / tail probability formula:\n\nFor a nonnegative function `f` on a sigma-finite measure space, the Lebesgue integral of `f` can\nbe written (roughly speaking) as: `\u222b\u207b f \u2202\u03bc = \u222b\u207b t in 0 .. \u221e, \u03bc {\u03c9 | f(\u03c9) > t}`.\n\nSee `lintegral_eq_lintegral_meas_le` for a version with sets of the form `{\u03c9 | f(\u03c9) \u2265 t}`\ninstead. -/\ntheorem lintegral_eq_lintegral_meas_lt (\u03bc : measure \u03b1) [sigma_finite \u03bc]\n  (f_nn : 0 \u2264 f) (f_mble : measurable f) :\n  \u222b\u207b \u03c9, ennreal.of_real (f \u03c9) \u2202\u03bc = \u222b\u207b t in Ioi 0, (\u03bc {a : \u03b1 | t < f a}) :=\nbegin\n  rw lintegral_eq_lintegral_meas_le \u03bc f_nn f_mble,\n  apply lintegral_congr_ae,\n  filter_upwards [measure.meas_le_ae_eq_meas_lt \u03bc (volume.restrict (Ioi 0)) f_mble] with t ht,\n  rw ht,\nend\n\n/-- An application of the layer cake formula / Cavalieri's principle / tail probability formula:\n\nFor a nonnegative function `f` on a sigma-finite measure space, the Lebesgue integral of `f` can\nbe written (roughly speaking) as: `\u222b\u207b f^p \u2202\u03bc = p * \u222b\u207b t in 0 .. \u221e, t^(p-1) * \u03bc {\u03c9 | f(\u03c9) > t}`.\n\nSee `lintegral_rpow_eq_lintegral_meas_le_mul` for a version with sets of the form `{\u03c9 | f(\u03c9) \u2265 t}`\ninstead. -/\ntheorem lintegral_rpow_eq_lintegral_meas_lt_mul (\u03bc : measure \u03b1) [sigma_finite \u03bc]\n  (f_nn : 0 \u2264 f) (f_mble : measurable f) {p : \u211d} (p_pos: 0 < p) :\n  \u222b\u207b \u03c9, ennreal.of_real ((f \u03c9)^p) \u2202\u03bc\n    = (ennreal.of_real p) * \u222b\u207b t in Ioi 0, (\u03bc {a : \u03b1 | t < f a}) * ennreal.of_real (t^(p-1)) :=\nbegin\n  rw lintegral_rpow_eq_lintegral_meas_le_mul \u03bc f_nn f_mble p_pos,\n  apply congr_arg (\u03bb z, (ennreal.of_real p * z)),\n  apply lintegral_congr_ae,\n  filter_upwards [measure.meas_le_ae_eq_meas_lt \u03bc (volume.restrict (Ioi 0)) f_mble] with t ht,\n  rw ht,\nend\n\nend layercake_lt\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/integral/layercake.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7429404624257258}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport solutions.section03groups.sheet1 -- imports our definition of `mygroup`\n\n/-!\n\n# Challenge sheet\n\nThis is an optional \"puzzle\" sheet, which won't teach you any\nnew Lean concepts but will give you some practice in rewriteology,\nand will teach you pretty much all there is to know about the\nquestion \"which axioms of a group can I safely drop?\" If you're\nnot into puzzles like this, just move on to sheet 3.\n\nIt turns out that two of the axioms in our definition of a group\nare not needed; they can be deduced from the others. Let's define\na \"weak group\" class, where we only have three of the group axioms.\nThe question is: can you prove that a weak group is a group?\nThe last def, `to_mygroup`, does this, but you need to fill in the\nsorrys first. Note that the simplifier is less use to you now; we've\ntrained it to solve problems about `mygroup`s but it doesn't\nknow anything about `myweakgroup`.\n\n-/\n\n-- removing `mul_one` and `mul_inv_self`\nclass myweakgroup (G : Type)\n  extends has_one G, has_mul G, has_inv G : Type :=\n(mul_assoc : \u2200 a b c : G, (a * b) * c = a * (b * c))\n(one_mul : \u2200 a : G, 1 * a = a)\n(inv_mul_self : \u2200 a : G, a\u207b\u00b9 * a = 1)\n\nnamespace myweakgroup\n\nvariables {G : Type} [myweakgroup G] (a b c : G)\n\n/-\n\nOne way of doing it: try proving \n\n`mul_left_cancel : a * b = a * c \u2192 b = c`\n\nand then\n\n`mul_eq_of_eq_inv_mul : b = a\u207b\u00b9 * c \u2192 a * b = c`\n\nfirst.\n\n-/\n\nlemma mul_left_cancel (h : a * b = a * c) : b = c :=\nbegin\ncalc \n     b = 1 * b         : by rw one_mul\n...    = a\u207b\u00b9 * a * b   : by rw inv_mul_self\n...    = a\u207b\u00b9 * (a * b) : by rw mul_assoc\n...    = a\u207b\u00b9 * (a * c) : by rw h\n...    = a\u207b\u00b9 * a * c   : by rw mul_assoc\n...    = 1 * c         : by rw inv_mul_self\n...    = c             : by rw one_mul\nend\n\nlemma mul_eq_of_eq_inv_mul (h : b = a\u207b\u00b9 * c) : a * b = c :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rw [\u2190 mul_assoc, inv_mul_self, one_mul, h],\nend\n\nlemma mul_one (a : G) : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw inv_mul_self,\nend\n\nlemma mul_inv_self (a : G) : a * a\u207b\u00b9 = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\ndef to_mygroup (G : Type) [myweakgroup G] : mygroup G :=\n{ mul_assoc := mul_assoc,\n  one_mul := one_mul,\n  mul_one := mul_one,\n  inv_mul_self := inv_mul_self,\n  mul_inv_self := mul_inv_self }\n\nend myweakgroup\n\n/-\nIf you want to take this further: prove that if we make\na new class `my_even_weaker_group` by replacing\n`one_mul` by `mul_one` in the definition of `myweakgroup`\nthen it is no longer true that you can prove `mul_inv_self`;\nthere are structures which satisfy `mul_assoc`, `mul_one`\nand `inv_mul_self` but which really are not groups.\nCan you find an example? Try it on paper first. \n-/\n\n-- claim: not a group in general\nclass my_even_weaker_group (G : Type)\n  extends has_one G, has_mul G, has_inv G : Type :=\n(mul_assoc : \u2200 a b c : G, (a * b) * c = a * (b * c))\n(mul_one : \u2200 a : G, a * 1 = a)\n(inv_mul_self : \u2200 a : G, a\u207b\u00b9 * a = 1)\n\ninstance : my_even_weaker_group bool :=\n{ one := tt,\n  mul := \u03bb x y, x, -- x * y = x for all x and y\n  inv := \u03bb x, tt, -- define x\u207b\u00b9 := 1 for all x\n  mul_assoc := dec_trivial,\n  mul_one := dec_trivial,\n  inv_mul_self := dec_trivial }\n\nexample : \u00ac (\u2200 g : bool, 1 * g = g) :=\nbegin\n  intro h,\n  specialize h ff,\n  cases h,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/solutions/section03groups/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7429375554773335}}
{"text": "/-\nIf a function, f, takes a type, T, as its first \nargument, and a value, t, of that very type, T, as \nits second argument, then when you fully apply the\nfunction (to all its arguments), you will have to \ngive two arguments: a value for T, in other words\na type; and a value, t, of that type.  \n\nBut why should you have to write out \"nat\" when Lean\nknows from 4 that nat is all it can be? Good news: if\nyou specify the argument as implicit, then it will be\ninferred, and if Lean can't infer it it will tell you.\n-/\n\n\n-- identity function on natural numbers\ndef id_nat : \u2115 \u2192 \u2115 \n| n := n\n\nexample : id_nat 5 = 5 := rfl\n\ndef id_string : string \u2192 string \n| s := s\n\ndef id_bool : bool \u2192 bool \n| b := b\n\n-- def id_T (T : Type) (a : T)\ndef id_T' (T : Type) : T \u2192 T\n| t := t\n\ndef id_T'' : \u2200 (T : Type), T \u2192 T\n| T t := t\n\n#eval id_T' nat 3\n#eval id_T' bool tt\n#eval id_T' string \"I love logic\"\n\n#eval id_T'' nat 3\n#eval id_T'' bool tt\n#eval id_T'' string \"I love logic\"\n\ndef id_T {T : Type} : T \u2192 T\n| t := t\n\n#eval id_T 3\n#eval id_T tt\n#eval id_T \"This is so cool\"\n\n\n#eval @id_T nat 3\n\n#check id_T\n#check @id_T\n\n\n\n\n\ndef identity1 : \u2200 (T : Type) (t : T), T := \nbegin\nassume T t,\nexact t,\nend \n\n#eval identity1 nat 1 \n#eval identity1 string \"Hi!\"\n\n  /-\n This pair of examples is really very cool, as \n it illustrates what in computer science we call\n parametric polymorphism. That means that you \n specify a type as a parameter and then values\n of the given types as additional arguments,\nand what this gives you is a whole family of\nfunctions, here one for each type you might pass\nas the actual value of the first parameter. \nAnd, here's the real key idea: the \"code\" is the\nsame no matter the value of the type parameter. \nParametric polymorphism.\n\nTry it out. Use #eval\n\nas nat, bool, string, 0 = 0, etc) you might \npass as the first argument, the \"type \" \n  -/\n\n/-=\n  arguments that are to \nbe inferred from context rather than specified explicitly. When\nyou #check a type, it prints implicit arguments as numbered\n\"meta-variables.\" To make Lean print the type making all of\nthe arguments explicit, you can use @.\n-/\n\n\ndef example1A { T : Type } (t : T) := t\ndef example1B { T : Type } (t : T) : T := t\n\n/-\nWhen we specify arguments of a function or predicate, we can\ndeclare them as named arguments (just in in Java or Python)m\nbefore the colon. We can then continue the argument list after\nthe colon using arrown notation. \nfunction \n-/\n", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/99_Lean_Prover/04_Implicit_Arguments.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938799869521, "lm_q2_score": 0.8962513828326956, "lm_q1q2_score": 0.7429375456667333}}
{"text": "-- ----------------------------------------------------\n-- Ejercicio 30. Demostrar o refutar\n--    (\u00ac(\u2200 x, P x)) \u2194 (\u2203x, \u00acP x)\n-- ----------------------------------------------------\n\nimport tactic\n\nvariable (U : Type)\nvariable (P : U -> Prop)\n\nopen_locale classical\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (\u00ac(\u2200 x, P x)) \u2194 (\u2203x, \u00acP x) :=\nbegin\n  split,\n  { intro h1,\n    by_contradiction h2,\n    apply h1,\n    intro a,\n    by_contradiction h3,\n    apply h2,\n    use a, },\n  { rintro \u27e8a, h4\u27e9 h5,\n    apply h4,\n    exact h5 a, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (\u00ac(\u2200 x, P x)) \u2194 (\u2203x, \u00acP x) :=\nbegin\n  split,\n  { intro h1,\n    push_neg at h1,\n    exact h1, },\n  { intro h2,\n    push_neg,\n    exact h2, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  (\u00ac(\u2200 x, P x)) \u2194 (\u2203x, \u00acP x) :=\nbegin\n  push_neg,\n  trivial,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  (\u00ac(\u2200 x, P x)) \u2194 (\u2203x, \u00acP x) :=\n-- by library_search\nnot_forall\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/2_LPO/Ejercicios/(\u00ac(\u2200 x, P x)) \u27f7 (\u2203x, \u00acP x).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7429375410109343}}
{"text": "import data.set.basic\nimport data.list.basic\nimport tactic\n\nopen set list\n\n-- \u0411\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a\u044b \u043d\u0430\u0434 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043e\u043c \u03b1\n-- \u042f\u0437\u044b\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e set (list \u03b1)\nnamespace languages\n\nvariables {\u03b1 : Type} {L M : set (list \u03b1)}\n\n\n-- \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0439: \u03b5 = \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a, 0 = \u2205, 1 = {\u03b5}, A + B = A \u222a B \ndef \u03b5 {\u03b1} : list \u03b1 := [] \ninstance : has_zero (set (list \u03b1)) := \u27e8(\u2205 : set _)\u27e9\ninstance : has_one (set (list \u03b1)) := \u27e8({[]} : set _)\u27e9\ninstance : has_add (set (list \u03b1)) := \u27e8set.union\u27e9\n\n-- \u041a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044f \u044f\u0437\u044b\u043a\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u043e\u0432 `w`, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u043b\u043e\u0432\u0430 `left \u2208 L` \u0438 `right \u2208 M`, \u0447\u0442\u043e `w = left ++ right`)\ndef append (L M: set (list \u03b1)) := \n    { w : list \u03b1 | \u2203 (left \u2208 L) (right \u2208 M), w = left ++ right}\n\n-- \u0411\u0443\u0434\u0435\u043c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u043a `L * M`\ninstance : has_mul (set (list \u03b1)) := \u27e8append\u27e9\n\n-- \u0418 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043b\u0435\u043c\u043c\u044b\ndef zero_def : (0 : set (list \u03b1)) = \u2205 := rfl\ndef one_def : (1 : set (list \u03b1)) = {[]} := rfl\n@[simp] def mem_zero {w : list \u03b1} : w \u2209 (0 : set (list \u03b1)) := by simp [zero_def]\n@[simp] def mem_one {w : list \u03b1} : w \u2208 (1 : set (list \u03b1)) \u2194 w = [] := by refl\n@[simp] def nil_mem_one : [] \u2208 (1 : set (list \u03b1)) := by simp\n\n\n-- \u0423\u043c\u0435\u043b\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 `rcases` \u0438 `rintro` \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442!\n@[simp] lemma zero_mul (L : set (list \u03b1)) : 0 * L = 0 :=\nbegin\n  ext w, split, {\n    rintro \u27e8left, hleft, right, hright, rfl\u27e9,\n    simpa only using hleft,\n  }, {\n    intro h,\n    exact absurd h mem_zero,\n  }\nend\n\n@[simp] lemma mul_zero (L : set (list \u03b1)) : L * 0 = 0 :=\nbegin\n  ext w, split, {\n    rintro \u27e8left, hleft, right, hright, rfl\u27e9,\n    simpa only using hright,\n  }, {\n    intro h,\n    exact absurd h mem_zero,\n  }\nend\n\n@[simp] lemma append_one (A : set (list \u03b1)) : A * 1 = A :=\nbegin\n  apply subset.antisymm, {\n    rintro _ \u27e8left, right, hleft, hright, rfl\u27e9,\n    rw mem_one at hright,\n    rwa [hright, list.append_nil],\n  }, {\n    rintro x xa,\n    use [x, xa],\n    use [[], nil_mem_one],\n    exact (append_nil x).symm,\n  },\nend\n\n@[simp] lemma one_append (A : set (list \u03b1)) : 1 * A = A :=\nbegin\n  apply subset.antisymm, {\n    rintro _ \u27e8 left, hleft, right, hright, rfl \u27e9,\n    rw mem_one at hleft,\n    rwa [hleft, list.nil_append],\n  }, {\n    rintro x xa,\n    use [[], nil_mem_one, x, xa],\n    exact (nil_append x).symm,\n  },\nend\n\nlemma append_assoc (A B C : set (list \u03b1)): \n    (A * B) * C = A * (B * C) :=\nbegin\n  apply subset.antisymm, {\n    rintro _ \u27e8_, \u27e8left, hleft, mid, hmid, rfl \u27e9, right, hright, rfl \u27e9,\n    use [left, hleft],\n    use [mid ++ right],\n    use [mid, hmid, right, hright],\n    exact append_assoc left mid right,\n  }, {\n    rintro _ \u27e8left, hleft, _, \u27e8mid, hmid, right, hright, rfl\u27e9, rfl \u27e9,\n    refine \u27e8left ++ mid, \u27e8left, hleft, mid, hmid, rfl\u27e9, right, hright, _\u27e9,\n    exact (append_assoc left mid right).symm,\n  },\nend\n\n@[simp] lemma left_distrib (A B C : set (list \u03b1)) : A * (B + C) = A * B + A * C :=\nbegin\n  ext w, split, {\n    rintro \u27e8left, hleft, right, (hB | hC), rfl\u27e9,\n    { left, exact \u27e8left, hleft, right, hB, rfl\u27e9 },\n    { right, exact \u27e8left, hleft, right, hC, rfl\u27e9 },\n  }, {\n    rintro (\u27e8left, hleft, right, hB, rfl\u27e9 | \u27e8left, hleft, right, hC, rfl\u27e9),\n    { exact \u27e8left, hleft, right, (or.inl hB), rfl\u27e9, },\n    { exact \u27e8left, hleft, right, (or.inr hC), rfl\u27e9, },\n  }\nend\n\n@[simp] lemma right_distrib (A B C : set (list \u03b1)) : (A + B) * C = A * C + B * C :=\nbegin\n    ext w, split, {\n    rintro \u27e8left, (hA | hB), right, hright, rfl\u27e9,\n    { left, exact \u27e8left, hA, right, hright, rfl\u27e9 },\n    { right, exact \u27e8left, hB, right, hright, rfl\u27e9 },\n  }, {\n    rintro (\u27e8left, hA, right, hright, rfl\u27e9 | \u27e8left, hB, right, hright, rfl\u27e9),\n    { exact \u27e8left, (or.inl hA), right, hright, rfl\u27e9, },\n    { exact \u27e8left, (or.inr hB), right, hright, rfl\u27e9, },\n  }\nend\n\n-- \u0414\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u044f\u0437\u044b\u043a\u043e\u0432 \u0441 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 + = \u222a \u0438 * = append \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u043f\u043e\u043b\u0443\u043a\u043e\u043b\u044c\u0446\u043e:\n-- A + B - \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u0438\u0434: 0, \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\n-- A * B - \u043f\u043e\u043b\u0443\u0433\u0440\u0443\u043f\u043f\u0430: 1, \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\n-- \u0414\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 0\n-- \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 (+) \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u0440\u043e `set.union`, \u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 (*) \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c\ninstance : semiring (set (list \u03b1)) := {\n  add := (+),\n  add_assoc := set.union_assoc,\n  zero := 0,\n  zero_add := set.empty_union,\n  add_zero := set.union_empty,\n  add_comm := set.union_comm,\n  mul := (*),\n  mul_assoc := append_assoc,\n  zero_mul := zero_mul,\n  mul_zero := mul_zero,\n  one := 1,\n  one_mul := one_append,\n  mul_one := append_one,\n  left_distrib := left_distrib,\n  right_distrib := right_distrib,\n}\n\n-- \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c L^n = L * L * ... * L (n \u0440\u0430\u0437)\n-- \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043b\u0435\u043c\u043c\u044b: `pow_zero`, `pow_succ`, `pow_add`, ...\n\nlemma append_subset_of_subset {A B C D : set (list \u03b1)} : A \u2286 C \u2192 B \u2286 D \u2192 A * B \u2286 C * D :=\nbegin\n  rintro hAC hBD x \u27e8left, hleft, right, hright, rfl\u27e9,\n  use [left, hAC hleft, right, hBD hright],\nend\n\nlemma pow_subset_of_subset {A B : set (list \u03b1)} {n : \u2115} : A \u2286 B \u2192 A^n \u2286 B^n :=\nbegin\n  intro hAB,\n  induction n with n ih, {\n      simp only [pow_zero],\n  }, {\n    rw [pow_succ, pow_succ],\n\n    refine append_subset_of_subset hAB ih,\n  },\nend\n\nlemma contain_eps_subset_power {A : set (list \u03b1)} {n : \u2115} (h : 1 \u2286 A) : A \u2286 A^(n.succ) :=\nbegin\n  induction n with n ih, {\n    rw pow_one, \n  }, {\n    rw pow_succ,\n    nth_rewrite 0 \u2190one_append A,\n    refine append_subset_of_subset h ih,\n  }\nend\n\n-- \u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 \u041a\u043b\u0438\u043d\u0438 \u044f\u0437\u044b\u043a\u0430 L \u0440\u0430\u0432\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e L^n \u043f\u043e \u0432\u0441\u0435\u043c \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u043c n\ndef star (L : set (list \u03b1)) := {w : list \u03b1 | \u2203 (n : \u2115), w \u2208 L^n}\n\n@[simp] lemma mem_star {w : list \u03b1} : w \u2208 star L \u2194 \u2203 (n : \u2115), w \u2208 L^n := by refl\n\nlemma star_eq_Union : star L = \u22c3 (n : \u2115), L^n :=\nbegin\n  ext w, simp only [mem_Union, mem_star],\nend\n\n@[simp] lemma nil_mem_star : [] \u2208 star L :=\nbegin\n  use 0,\n  simp only [nil_mem_one, pow_zero],\nend\n\n@[simp] lemma one_subset_star : 1 \u2286 star L :=\nbegin    \n  simp [one_def],\nend\n\n@[simp] lemma pow_subset_star (n : \u2115) : L^n \u2286 star L :=\nbegin\n  rw star_eq_Union,\n  refine subset_Union _ _,\nend\n\n@[simp] lemma subset_star : L \u2286 star L :=\nbegin\n  -- \u0441\u0434\u0435\u043b\u0430\u0435\u0442 `rw` \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\n  -- conv_lhs {rw \u2190 pow_one L},\n  nth_rewrite 0 [\u2190pow_one L],\n  exact pow_subset_star 1,\nend\n\nlemma star_subset_star : L \u2286 M \u2192 star L \u2286 star M :=\nbegin\n  rintro hAB w \u27e8n, ha\u27e9,\n  use n,\n  exact pow_subset_of_subset hAB ha,\nend\n\nlemma append_subset_star {A B L : set (list \u03b1)} : \n    A \u2286 star L \u2192 B \u2286 star L \u2192 (A * B) \u2286 star L :=\nbegin\n  rintro al bl _ \u27e8left, hleft, right, hright, rfl\u27e9,\n  rcases al hleft with \u27e8an, ah\u27e9,\n  rcases bl hright with \u27e8bn, bh\u27e9,\n  use an + bn,\n  rw pow_add,\n  use [left, ah, right, bh],\nend\n\nlemma star_append_star_eq_star : star L * star L = star L :=\nbegin\n  apply subset.antisymm, {\n    apply append_subset_star (set.subset.refl _) (set.subset.refl _),\n  }, {\n    conv_lhs {rw \u2190 mul_one (star L)},\n    apply append_subset_of_subset,\n    { refl },\n    { exact one_subset_star },\n  }\nend \n\nlemma pow_star_eq_star (n : \u2115) : (star L)^n.succ = star L :=\nbegin\n  induction n with n ih, {\n    rw [pow_one],\n  }, {\n    apply subset.antisymm, {\n      rw [pow_succ, ih, star_append_star_eq_star],\n    }, {\n      apply contain_eps_subset_power,\n      exact one_subset_star,\n    },\n  },\nend\n\n-- \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0432 \u0414\u0417 \u043f\u043e \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043a\u0435!                \ntheorem star_star_eq_star : star (star L) = star L :=\nbegin\n  apply subset.antisymm, {\n    rintro x \u27e8n, hx\u27e9,\n    cases n,\n    { rw [pow_zero] at hx, apply one_subset_star hx },\n    { rwa pow_star_eq_star at hx }\n  }, {\n    exact subset_star,\n  },\nend\n\n-- L^n \u0440\u0430\u0432\u0435\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u043a\u0430\u043a \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044e `n` \u0441\u043b\u043e\u0432 \u0438\u0437 `L`. \n-- \u041a\u0430\u043a \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c, \u0447\u0442\u043e `w` \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044f `n` \u0441\u043b\u043e\u0432 \u0438\u0437 `L`?\n-- `\u2203 (l : list (list \u03b1)) (h : \u2200 x \u2208 l, x \u2208 L), w = list.join l \u2227 l.length = n`\n-- \u0411\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e: \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432 `l`, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432 `l` \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 `L`, `w` \u0440\u0430\u0432\u0435\u043d `list.join l`, \u0438 \u0434\u043b\u0438\u043d\u0430 `l` \u0440\u0430\u0432\u043d\u0430 `n`\n-- \u041d\u0430\u0447\u0430\u043b\u0438\u0441\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f! \u0418\u0437\u0443\u0447\u0438\u0442\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 API `list`, `list.has_mem`, `list.join` \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0432\u0435\u0449\u0438, \u0438\u043b\u0438 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 `simp` :)\n#check list.mem\n#check mem_cons_self\n#check list.join\n#check join_append\n\nlemma pow_eq_list_join {n : \u2115} : \n    L^n = {w | \u2203 (l : list (list \u03b1)) (h : \u2200 x \u2208 l, x \u2208 L), w = list.join l \u2227 l.length = n} :=\nbegin\n  apply subset.antisymm, {\n    induction n with n ih, {\n      simp [one_def], use [[]], simp,\n    }, {\n      rw pow_succ,\n      rintro _ \u27e8left, hleft, right, hright, rfl\u27e9,\n      obtain \u27e8tail, hmem, rfl, rfl\u27e9 := ih hright,\n      clear ih,\n      simp,\n      refine \u27e8left :: tail, _, _, _\u27e9,\n      -- \u0421\u0442\u0430\u043b\u043e 3 \u0446\u0435\u043b\u0438: 1. \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u043f\u0438\u0441\u043a\u0430 \u043b\u0435\u0436\u0430\u0442 \u0432 L\n      -- 2. join \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e - `refl`\n      -- 3. \u0434\u043b\u0438\u043d\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 1 \u0431\u043e\u043b\u044c\u0448\u0435 - `refl`\n      { rintro x (rfl | xtail),\n        { exact hleft, },\n        { exact hmem _ xtail, },\n      },\n      { refl },\n      { refl },\n    }\n  }, {\n    induction n with n ih, {\n      simp [one_def],\n      rintro w l h rfl hlen,\n      rw [length_eq_zero] at hlen,\n      subst hlen,\n      refl,\n    }, {\n      rintro w \u27e8l, hmem, rfl, hlen\u27e9,\n      rw pow_succ,\n      -- \u0414\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e l \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e l.length = n.succ\n      cases l with head tail,\n      { exfalso, exact (ne_nil_of_length_eq_succ hlen) rfl, },\n      rw [join],\n      -- \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e `head \u2208 L` \u0438 `tail.join \u2208 L^n`\n      refine \u27e8head, _, tail.join, _, rfl\u27e9, {\n        apply hmem,\n        apply mem_cons_self,\n      }, {\n        apply ih,\n        simp,\n        refine \u27e8tail, _, _, _\u27e9,\n        { rintro x xtail,\n          apply hmem x,\n          exact mem_cons_of_mem _ xtail, },\n        { refl, },\n        { simpa [nat.add_one] using hlen, },\n      }\n    }\n  }\nend\n\nlemma mem_pow_iff_list_join {w : list \u03b1} {n : \u2115} \n  : w \u2208 L^n \u2194 \u2203 l (h : \u2200 x \u2208 l, x \u2208 L), w = list.join l \u2227 l.length = n :=\nbegin\n  rw pow_eq_list_join,\n  refl,\nend\n\n-- \u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 \u041a\u043b\u0438\u043d\u0438 - \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044e \u0441\u043b\u043e\u0432 \u0438\u0437 L (\u0431\u0435\u0437 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e)\nlemma star_eq_list_join : \n  star L = {w | \u2203 l (h : \u2200 x, x \u2208 l \u2192 x \u2208 L), w = list.join l} :=\nbegin\n  ext w, split, {\n    rintro \u27e8n, hw\u27e9,\n    rw pow_eq_list_join at hw,\n    rcases hw with \u27e8l, h, rfl, rfl\u27e9,\n    use [l, h],\n  }, {\n    rintro \u27e8l, h, rfl\u27e9,\n    apply pow_subset_star l.length,\n    rw [pow_eq_list_join],\n    refine \u27e8l, h, rfl, rfl\u27e9,\n  }\nend\n\nlemma mem_star_iff_list_join {w : list \u03b1} :\n  w \u2208 star L \u2194 \u2203 l (h : \u2200 x \u2208 l, x \u2208 L), w = list.join l :=\nbegin\n  rw star_eq_list_join,\n  refl,\nend\n\n-- \u0415\u0449\u0435 \u043e\u0434\u043d\u043e \u0414\u0417\nlemma union_star_eq_star_mul_star_star : star (L + M) = star (star L * star M) :=\nbegin\n  apply subset.antisymm, {\n    apply star_subset_star,\n    apply union_subset, {\n      conv_lhs {rw \u2190mul_one L},\n      apply append_subset_of_subset (subset_star) (one_subset_star),\n    }, {\n      conv_lhs {rw \u2190one_mul M},\n      apply append_subset_of_subset (one_subset_star) (subset_star),      \n    }\n  }, {\n    rw \u2190 @star_star_eq_star _ (L + M),\n    apply star_subset_star,\n    conv_rhs { rw \u2190 star_append_star_eq_star},\n    apply append_subset_of_subset,\n    { exact star_subset_star (subset_union_left _ _)},\n    { exact star_subset_star (subset_union_right _ _)},\n  }\nend\n\nlemma mul_star_subset_star : L * star L \u2286 star L :=\nbegin\n  rintro _ \u27e8left, hleft, right, \u27e8n, hright\u27e9, rfl\u27e9,\n  apply pow_subset_star (1 + n),\n  rw [pow_add, pow_one],\n  exact \u27e8left, hleft, right, hright, rfl\u27e9,\nend\n\nlemma one_add_mul_star_eq_star : 1 + L * star L = star L :=\nbegin\n  apply subset.antisymm, {\n    exact union_subset one_subset_star mul_star_subset_star,\n  }, {\n    rintro w \u27e8n, hw\u27e9,\n    cases n, {\n      left, exact hw,\n    }, {\n      right,\n      rw [pow_succ] at hw,\n      exact append_subset_of_subset (set.subset.refl _) (pow_subset_star n) hw,\n    }\n  }\nend\n\nlemma mul_star_mul_subset_star_mul : L * ((star L) * M) \u2286 (star L) * M := \nbegin\n  rw \u2190 append_assoc,\n  exact append_subset_of_subset (mul_star_subset_star) (set.subset.refl _), \nend\n\n-- \u0420\u0435\u0448\u0430\u0435\u043c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0432 \u044f\u0437\u044b\u043a\u0430\u0445: \u0435\u0441\u043b\u0438 [] \u2209 A, \u0442\u043e L = A * L + B \u2194 L = star A * b\nlemma linear_eq_iff {A B : set (list \u03b1)} (hnil : [] \u2209 A) : L = A * L + B \u2194 L = star A * B :=\nbegin\n  split, {\n    intro h,\n    ext w,\n    suffices hn : \u2200 (n : \u2115), \u2200 (w : list \u03b1) (hn : n = w.length), (w \u2208 L \u2194 w \u2208 star A * B), {\n      refine hn w.length _ rfl,\n    },\n    clear w,\n    intro n,\n    induction n using nat.strong_induction_on with n ih,\n    dsimp only at ih,\n    rintro w rfl,\n    split, {\n      intro wL,\n      rw h at wL,\n      rcases wL with \u27e8left, hleft, right, hright, rfl\u27e9 | wL, {\n        have right_length : right.length < (left ++ right).length :=\n        begin\n          rw [length_append],\n          have left_neq_nil : left \u2260 [] := \u03bb hln, by {subst hln, exact hnil hleft},\n          have left_length_pos : left.length > 0 := length_pos_of_ne_nil left_neq_nil,\n          simpa only [lt_add_iff_pos_left] using left_length_pos,\n        end,\n        specialize ih right.length right_length right rfl,\n        rw ih at hright,\n        apply mul_star_mul_subset_star_mul,\n        exact \u27e8left, hleft, right, hright, rfl\u27e9,\n      }, {\n        rw \u2190one_mul B at wL,\n        apply append_subset_of_subset (one_subset_star) (set.subset.refl _) wL,\n      },\n    }, {\n      rintro \u27e8left, hleft, right, hright, rfl\u27e9,\n      rw mem_star_iff_list_join at hleft,\n      rcases hleft with \u27e8l, hlist, rfl\u27e9,\n      clear ih,\n      induction l with head tail ih, {\n        simp, rw h, exact or.inr hright,\n      }, {\n        simp, rw h, left,\n        refine \u27e8head, _, tail.join ++ right, _, rfl\u27e9,\n        { apply hlist, exact mem_cons_self head tail},\n        { apply ih, simp only [mem_cons_iff, forall_eq_or_imp] at hlist, exact hlist.2,},\n      }\n    }\n  }, {\n    rintro rfl,\n    rw \u2190append_assoc,\n    -- rw \u2190one_add_mul_star_eq_star,\n    -- nth_rewrite 0 \u2190one_add_mul_star_eq_star,\n    conv_lhs {rw [\u2190one_add_mul_star_eq_star, right_distrib, one_append]},\n    -- https://leanprover-community.github.io/mathlib_docs/tactics.html#abel\n    abel,\n    -- \u0422\u0430\u043a\u0436\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 ac_refl: https://leanprover-community.github.io/mathlib_docs/tactics.html#ac_refl\n  }\nend\n\nend languages\n", "meta": {"author": "VArtem", "repo": "lean-itmo", "sha": "dc44cd06f9f5b984d051831b3aaa7364e64c2dc4", "save_path": "github-repos/lean/VArtem-lean-itmo", "path": "github-repos/lean/VArtem-lean-itmo/lean-itmo-dc44cd06f9f5b984d051831b3aaa7364e64c2dc4/src/week-03/solutions/e01-languages.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7429375410109343}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module algebra.order.group.min_max\n! leanprover-community/mathlib commit 10b4e499f43088dd3bb7b5796184ad5216648ab1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.Group.Abs\nimport Mathlib.Algebra.Order.Monoid.MinMax\n\n/-!\n# `min` and `max` in linearly ordered groups.\n-/\n\n\nsection\n\nvariable {\u03b1 : Type _} [Group \u03b1] [LinearOrder \u03b1] [CovariantClass \u03b1 \u03b1 (. * .) (. \u2264 .)]\n\n@[to_additive (attr := simp)]\ntheorem max_one_div_max_inv_one_eq_self (a : \u03b1) : max a 1 / max a\u207b\u00b9 1 = a := by\n  rcases le_total a 1 with (h | h) <;> simp [h]\n#align max_one_div_max_inv_one_eq_self max_one_div_max_inv_one_eq_self\n#align max_zero_sub_max_neg_zero_eq_self max_zero_sub_max_neg_zero_eq_self\n\nalias max_zero_sub_max_neg_zero_eq_self \u2190 max_zero_sub_eq_self\n#align max_zero_sub_eq_self max_zero_sub_eq_self\n\nend\n\nsection LinearOrderedCommGroup\n\nvariable {\u03b1 : Type _} [LinearOrderedCommGroup \u03b1] {a b c : \u03b1}\n\n@[to_additive min_neg_neg]\ntheorem min_inv_inv' (a b : \u03b1) : min a\u207b\u00b9 b\u207b\u00b9 = (max a b)\u207b\u00b9 :=\n  Eq.symm <| (@Monotone.map_max \u03b1 \u03b1\u1d52\u1d48 _ _ Inv.inv a b) fun _ _ =>\n  -- Porting note: Explicit `\u03b1` necessary to infer `CovariantClass` instance\n    (@inv_le_inv_iff \u03b1 _ _ _).mpr\n#align min_inv_inv' min_inv_inv'\n#align min_neg_neg min_neg_neg\n\n@[to_additive max_neg_neg]\ntheorem max_inv_inv' (a b : \u03b1) : max a\u207b\u00b9 b\u207b\u00b9 = (min a b)\u207b\u00b9 :=\n  Eq.symm <| (@Monotone.map_min \u03b1 \u03b1\u1d52\u1d48 _ _ Inv.inv a b) fun _ _ =>\n  -- Porting note: Explicit `\u03b1` necessary to infer `CovariantClass` instance\n    (@inv_le_inv_iff \u03b1 _ _ _).mpr\n#align max_inv_inv' max_inv_inv'\n#align max_neg_neg max_neg_neg\n\n@[to_additive min_sub_sub_right]\ntheorem min_div_div_right' (a b c : \u03b1) : min (a / c) (b / c) = min a b / c := by\n  simpa only [div_eq_mul_inv] using min_mul_mul_right a b c\u207b\u00b9\n#align min_div_div_right' min_div_div_right'\n#align min_sub_sub_right min_sub_sub_right\n\n@[to_additive max_sub_sub_right]\ntheorem max_div_div_right' (a b c : \u03b1) : max (a / c) (b / c) = max a b / c := by\n  simpa only [div_eq_mul_inv] using max_mul_mul_right a b c\u207b\u00b9\n#align max_div_div_right' max_div_div_right'\n#align max_sub_sub_right max_sub_sub_right\n\n@[to_additive min_sub_sub_left]\ntheorem min_div_div_left' (a b c : \u03b1) : min (a / b) (a / c) = a / max b c := by\n  simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv']\n#align min_div_div_left' min_div_div_left'\n#align min_sub_sub_left min_sub_sub_left\n\n@[to_additive max_sub_sub_left]\ntheorem max_div_div_left' (a b c : \u03b1) : max (a / b) (a / c) = a / min b c := by\n  simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']\n#align max_div_div_left' max_div_div_left'\n#align max_sub_sub_left max_sub_sub_left\n\nend LinearOrderedCommGroup\n\nsection LinearOrderedAddCommGroup\n\nvariable {\u03b1 : Type _} [LinearOrderedAddCommGroup \u03b1] {a b c : \u03b1}\n\ntheorem max_sub_max_le_max (a b c d : \u03b1) : max a b - max c d \u2264 max (a - c) (b - d) := by\n  simp only [sub_le_iff_le_add, max_le_iff]; constructor\n  calc\n    a = a - c + c := (sub_add_cancel a c).symm\n    _ \u2264 max (a - c) (b - d) + max c d := add_le_add (le_max_left _ _) (le_max_left _ _)\n\n  calc\n    b = b - d + d := (sub_add_cancel b d).symm\n    _ \u2264 max (a - c) (b - d) + max c d := add_le_add (le_max_right _ _) (le_max_right _ _)\n\n#align max_sub_max_le_max max_sub_max_le_max\n\ntheorem abs_max_sub_max_le_max (a b c d : \u03b1) : |max a b - max c d| \u2264 max (|a - c|) (|b - d|) := by\n  refine' abs_sub_le_iff.2 \u27e8_, _\u27e9\n  \u00b7 exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _))\n  \u00b7 rw [abs_sub_comm a c, abs_sub_comm b d]\n    exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _))\n#align abs_max_sub_max_le_max abs_max_sub_max_le_max\n\ntheorem abs_min_sub_min_le_max (a b c d : \u03b1) : |min a b - min c d| \u2264 max (|a - c|) (|b - d|) := by\n  simpa only [max_neg_neg, neg_sub_neg, abs_sub_comm] using\n    abs_max_sub_max_le_max (-a) (-b) (-c) (-d)\n#align abs_min_sub_min_le_max abs_min_sub_min_le_max\n\ntheorem abs_max_sub_max_le_abs (a b c : \u03b1) : |max a c - max b c| \u2264 |a - b| := by\n  simpa only [sub_self, abs_zero, max_eq_left (abs_nonneg (a - b))]\n    using abs_max_sub_max_le_max a c b c\n#align abs_max_sub_max_le_abs abs_max_sub_max_le_abs\n\nend LinearOrderedAddCommGroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/Group/MinMax.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.74293752843829}}
{"text": "import data.int.gcd   \nimport algebra.big_operators.basic\nimport data.nat.interval\nimport tactic\n\n\nopen_locale big_operators -- enable notation\nopen finset\n\n\n-- Sierpinski #8\n\nlemma  div_eq_iff_mul_eq' (a b c : \u2124) (hb : b \u2260 0 ) :\n  (a : \u211a) / (b : \u211a) = (c : \u211a) \u2194 (a : \u211a) = (b : \u211a) * (c : \u211a) :=\nbegin\n  split, {\n    intro h,\n    library_search,\n    \n    \n    \n\n  }, {\n\n  }\nend\n\nlemma  sum_of_powers_of_a_minus_1_eq_power_of_a_minus_1 (m a : \u2115) (ha : a > 1) :\n  (a^m - 1) / (a - 1) = \u2211i  in finset.range (m-1), (a^(i+1) - 1) :=\nbegin \n  induction m with k hk,\n  simp,\n  have ha2 : a - 1 > 0 := tsub_pos_of_lt ha,\n  have ha3 : a - 1 \u2260 0 := ne_of_gt ha2,\n  have hk2 : (a ^ k - 1)  = (a - 1) * (\u2211 (i : \u2115) in range (k - 1), (a ^ (i + 1) - 1)) := by library_search,\n\nend\n\nlemma  divides_a_minus_one_a_k_minus_one (a k : \u2115) (h : a > 1) :\n  a - 1 \u2223 a ^ k - 1 :=\nbegin\n  sorry,\nend\n\n\ntheorem  gcd_of_powers_minus_one_over_minus_one_eq_gcd_of_minus_one_and_m (m a : \u2115) (ha : 1 < a) :\n  int.gcd((a^m - 1) / (a - 1)) (a - 1) = int.gcd (a - 1) m := \nbegin\n  have h := sum_of_powers_of_a_minus_1_eq_power_of_a_minus_1 m a ha,\n  set d := int.gcd ((a^m - 1) / (a - 1)) (a - 1),\n  have hd : d \u2223 m := by sorry,\n  set \u03b4 := int.gcd (\u2191a - 1) m,\n  by_contra hc, \n  change (d \u2260 \u03b4) at hc,\n  have hc2 : d < \u03b4 \u2228 d > \u03b4 := ne.lt_or_lt hc,\n  cases hc2,\n  {\n    -- show d \u2223 (a-1), d \u2223 m --> d \u2265 \u03b4\n    sorry,\n  }, {\n\n  }\n  \n\n\nend\n\n\n-- Sierpinski #10\n\ntheorem  odd_gt_1_iff_dvd_sum_of_powers (n : \u2115) (hn : n > 1) :\n  n \u2223 \u2211 i in finset.range n, i^n \u2194 n % 2 = 1 :=\nbegin\n\nend\n", "meta": {"author": "Vilin97", "repo": "LLL", "sha": "ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9", "save_path": "github-repos/lean/Vilin97-LLL", "path": "github-repos/lean/Vilin97-LLL/LLL-ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9/Zachary/Sierpinski.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.742862809237474}}
{"text": "/-\nCopyright (c) 2020 Ruben Van de Velde, Stanislas Polu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ruben Van de Velde, Stanislas Polu\n-/\n\nimport data.real.basic\nimport analysis.normed_space.basic\n\n/-!\n# IMO 1972 B2\n\nProblem: `f` and `g` are real-valued functions defined on the real line. For all `x` and `y`,\n`f(x + y) + f(x - y) = 2f(x)g(y)`. `f` is not identically zero and `|f(x)| \u2264 1` for all `x`.\nProve that `|g(x)| \u2264 1` for all `x`.\n-/\n\n/--\nThis proof begins by introducing the supremum of `f`, `k \u2264 1` as well as `k' = k / \u2225g y\u2225`. We then\nsuppose that the conclusion does not hold (`hneg`) and show that `k \u2264 k'` (by\n`2 * (\u2225f x\u2225 * \u2225g y\u2225) \u2264 2 * k` obtained from the main hypothesis `hf1`) and that `k' < k` (obtained\nfrom `hneg` directly), finally raising a contradiction with `k' < k'`.\n\n(Authored by Stanislas Polu inspired by Ruben Van de Velde).\n-/\ntheorem imo1972_p5 (f g : \u211d \u2192 \u211d)\n  (hf1 : \u2200 x, \u2200 y, (f(x+y) + f(x-y)) = 2 * f(x) * g(y))\n  (hf2 : \u2200 y, \u2225f(y)\u2225 \u2264 1)\n  (hf3 : \u2203 x, f(x) \u2260 0)\n  (y : \u211d) :\n  \u2225g(y)\u2225 \u2264 1 :=\nbegin\n  classical,\n  set S := set.range (\u03bb x, \u2225f x\u2225),\n  -- Introduce `k`, the supremum of `f`.\n  let k : \u211d := Sup (S),\n\n  -- Show that `\u2225f x\u2225 \u2264 k`.\n  have hk\u2081 : \u2200 x, \u2225f x\u2225 \u2264 k,\n  { have h : bdd_above S, from \u27e81, set.forall_range_iff.mpr hf2\u27e9,\n    intro x,\n    exact le_cSup h (set.mem_range_self x), },\n  -- Show that `2 * (\u2225f x\u2225 * \u2225g y\u2225) \u2264 2 * k`.\n  have hk\u2082 : \u2200 x, 2 * (\u2225f x\u2225 * \u2225g y\u2225) \u2264 2 * k,\n  { intro x,\n    calc 2 * (\u2225f x\u2225 * \u2225g y\u2225)\n        = \u22252 * f x * g y\u2225 : by simp [real.norm_eq_abs, abs_mul, mul_assoc]\n    ... = \u2225f (x + y) + f (x - y)\u2225 : by rw hf1\n    ... \u2264 \u2225f (x + y)\u2225 + \u2225f (x - y)\u2225 : norm_add_le _ _\n    ... \u2264 k + k : add_le_add (hk\u2081 _) (hk\u2081 _)\n    ... = 2 * k : (two_mul _).symm, },\n\n  -- Suppose the conclusion does not hold.\n  by_contra' hneg,\n  set k' := k / \u2225g y\u2225,\n\n  -- Demonstrate that `k' < k` using `hneg`.\n  have H\u2081 : k' < k,\n  { have h\u2081 : 0 < k,\n    { obtain \u27e8x, hx\u27e9 := hf3,\n      calc 0\n          < \u2225f x\u2225 : norm_pos_iff.mpr hx\n      ... \u2264 k : hk\u2081 x },\n    rw div_lt_iff,\n    apply lt_mul_of_one_lt_right h\u2081 hneg,\n    exact trans zero_lt_one hneg },\n\n  -- Demonstrate that `k \u2264 k'` using `hk\u2082`.\n  have H\u2082 : k \u2264 k',\n  { have h\u2081 : \u2203 x : \u211d, x \u2208 S,\n    { use \u2225f 0\u2225, exact set.mem_range_self 0, },\n    have h\u2082 : \u2200 x, \u2225f x\u2225 \u2264 k',\n    { intros x,\n      rw le_div_iff,\n      { apply (mul_le_mul_left zero_lt_two).mp (hk\u2082 x) },\n      { exact trans zero_lt_one hneg } },\n    apply cSup_le h\u2081,\n    rintros y' \u27e8yy, rfl\u27e9,\n    exact h\u2082 yy },\n\n  -- Conclude by obtaining a contradiction, `k' < k'`.\n  apply lt_irrefl k',\n  calc k'\n      < k : H\u2081\n  ... \u2264 k' : H\u2082,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/imo/1972/p5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.742862809222478}}
{"text": "import game.world7.level8 -- hide\nimport game.world6.level8 -- hide\nimport tactic.tauto -- useful high-powered tactic\nlocal attribute [instance, priority 10] classical.prop_decidable -- hide\n/- \n# Advanced proposition world. \n\nYou already know enough to embark on advanced addition world. But here are just a couple\nmore things.\n\n## Level 9: `exfalso` and proof by contradiction. \n\nIt's certainly true that $P\\land(\\lnot P)\\implies Q$ for any propositions $P$\nand $Q$, because the left hand side of the implication is false. But how do\nwe prove that `false` implies any proposition $Q$? A cheap way of doing it in\nLean is using the `exfalso` tactic, which changes any goal at all to `false`. \nYou might think this is a step backwards, but if you have a hypothesis `h : \u00ac P`\nthen after `rw not_iff_imp_false at h,` you can `apply h,` to make progress. \nTry solving this level without using `cc` or `tauto`, but using `exfalso` instead.\n\n-/\n\n\n\n/- Lemma : no-side-bar\nIf $P$ and $Q$ are true/false statements, then\n$$(P\\land(\\lnot P))\\implies Q.$$\n-/\nlemma contra (P Q : Prop) : (P \u2227 \u00ac P) \u2192 Q :=\nbegin\n  intro h,\n  cases h with p np,\n  rw not_iff_imp_false at np,\n  exfalso,\n  apply np,\n  exact p,\n\n\nend\n\n\n/-\n## Pro tip.\n\n`\u00ac P` is actually `P \u2192 false` *by definition*. Try\ncommenting out `rw not_iff_imp_false at ...` by putting two minus signs `--`\nbefore the `rw`. Does it still compile?\n-/\n\n/- Tactic : exfalso\n\n## Summary\n\n`exfalso` changes your goal to `false`. \n\n## Details\n\nWe know that `false` implies `P` for any proposition `P`, and so if your goal is `P`\nthen you should be able to `apply` `false \u2192 P` and reduce your goal to `false`. This\nis what the `exfalso` tactic does. The theorem that `false \u2192 P` is called `false.elim`\nso one can achieve the same effect with `apply false.elim`. \n\nThis tactic can be used in a proof by contradiction, where the hypotheses are enough\nto deduce a contradiction and the goal happens to be some random statement (possibly\na false one) which you just want to simplify to `false`.\n-/\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world7/level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7428628072143625}}
{"text": "open nat\n\nuniverse u\n\ninductive pfin (n : nat) : Type u\n| mk (val : nat) (is_lt : val < n) : pfin\n\nnamespace pfin\n\n@[reducible]\ndef val {n} : pfin n \u2192 nat\n| \u27e8v, _\u27e9 := v\n\n@[reducible]\ndef is_lt {n} : \u2200 (a : pfin n), a.val < n\n| \u27e8_, h\u27e9 := h\n\nprotected def lt {n} (a b : pfin n) : Prop :=\na.val < b.val\n\nprotected def le {n} (a b : pfin n) : Prop :=\na.val \u2264 b.val\n\ninstance {n} : has_lt (pfin n)  := \u27e8pfin.lt\u27e9\ninstance {n} : has_le (pfin n)  := \u27e8pfin.le\u27e9\n\ninstance decidable_lt {n} (a b : pfin n) :  decidable (a < b) :=\nnat.decidable_lt _ _\n\ninstance decidable_le {n} (a b : pfin n) : decidable (a \u2264 b) :=\nnat.decidable_le _ _\n\ndef {w} elim0 {\u03b1 : Sort w} : pfin 0 \u2192 \u03b1\n| \u27e8_, h\u27e9 := absurd h (nat.not_lt_zero _)\n\nvariable {n : nat}\n\nlemma eq_of_veq : \u2200 {i j : pfin n}, (val i) = (val j) \u2192 i = j\n| \u27e8iv, ilt\u2081\u27e9 \u27e8.(iv), ilt\u2082\u27e9 rfl := rfl\n\nlemma veq_of_eq : \u2200 {i j : pfin n}, i = j \u2192 (val i) = (val j)\n| \u27e8iv, ilt\u27e9 .(_) rfl := rfl\n\nlemma ne_of_vne {i j : pfin n} (h : val i \u2260 val j) : i \u2260 j :=\n\u03bb h', absurd (veq_of_eq h') h\n\nlemma vne_of_ne {i j : pfin n} (h : i \u2260 j) : val i \u2260 val j :=\n\u03bb h', absurd (eq_of_veq h') h\n\nend pfin\n\nopen pfin\n\ninstance (n : nat) : decidable_eq (pfin n) :=\n\u03bb i j, decidable_of_decidable_of_iff\n  (nat.decidable_eq i.val j.val) \u27e8eq_of_veq, veq_of_eq\u27e9\n", "meta": {"author": "Or7ando", "repo": "lean", "sha": "d41169cf4e416a0d42092fb6bdc14131cee9dd15", "save_path": "github-repos/lean/Or7ando-lean", "path": "github-repos/lean/Or7ando-lean/lean-d41169cf4e416a0d42092fb6bdc14131cee9dd15/.github/workflows/geo/src/pfin/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7428628011525253}}
{"text": "/-\nCopyright (c) 2022 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport model_theory.satisfiability\nimport combinatorics.simple_graph.basic\n\n/-!\n# First-Ordered Structures in Graph Theory\nThis file defines first-order languages, structures, and theories in graph theory.\n\n## Main Definitions\n* `first_order.language.graph` is the language consisting of a single relation representing\nadjacency.\n* `simple_graph.Structure` is the first-order structure corresponding to a given simple graph.\n* `first_order.language.Theory.simple_graph` is the theory of simple graphs.\n* `first_order.language.simple_graph_of_structure` gives the simple graph corresponding to a model\nof the theory of simple graphs.\n\n-/\n\nuniverses u v w w'\n\nnamespace first_order\nnamespace language\nopen_locale first_order\nopen Structure\n\nvariables {L : language.{u v}} {\u03b1 : Type w} {V : Type w'} {n : \u2115}\n\n/-! ### Simple Graphs -/\n\n/-- The language consisting of a single relation representing adjacency. -/\nprotected def graph : language :=\nlanguage.mk\u2082 empty empty empty empty unit\n\n/-- The symbol representing the adjacency relation. -/\ndef adj : language.graph.relations 2 := unit.star\n\n/-- Any simple graph can be thought of as a structure in the language of graphs. -/\ndef _root_.simple_graph.Structure (G : simple_graph V) :\n  language.graph.Structure V :=\nStructure.mk\u2082 empty.elim empty.elim empty.elim empty.elim (\u03bb _, G.adj)\n\nnamespace graph\n\ninstance : is_relational (language.graph) := language.is_relational_mk\u2082\n\ninstance : subsingleton (language.graph.relations n) :=\nlanguage.subsingleton_mk\u2082_relations\n\nend graph\n\n/-- The theory of simple graphs. -/\nprotected def Theory.simple_graph : language.graph.Theory :=\n{adj.irreflexive, adj.symmetric}\n\n@[simp] lemma Theory.simple_graph_model_iff [language.graph.Structure V] :\n  V \u22a8 Theory.simple_graph \u2194\n    irreflexive (\u03bb x y : V, rel_map adj ![x,y]) \u2227 symmetric (\u03bb x y : V, rel_map adj ![x,y]) :=\nby simp [Theory.simple_graph]\n\ninstance simple_graph_model (G : simple_graph V) :\n  @Theory.model _ V G.Structure Theory.simple_graph :=\nbegin\n  simp only [Theory.simple_graph_model_iff, rel_map_apply\u2082],\n  exact \u27e8G.loopless, G.symm\u27e9,\nend\n\nvariables (V)\n\n/-- Any model of the theory of simple graphs represents a simple graph. -/\n@[simps] def simple_graph_of_structure [language.graph.Structure V] [V \u22a8 Theory.simple_graph] :\n  simple_graph V :=\n{ adj := \u03bb x y, rel_map adj ![x,y],\n  symm := relations.realize_symmetric.1 (Theory.realize_sentence_of_mem Theory.simple_graph\n      (set.mem_insert_of_mem _ (set.mem_singleton _))),\n  loopless := relations.realize_irreflexive.1 (Theory.realize_sentence_of_mem Theory.simple_graph\n      (set.mem_insert _ _)) }\n\nvariables {V}\n\n@[simp] lemma _root_.simple_graph.simple_graph_of_structure (G : simple_graph V) :\n  @simple_graph_of_structure V G.Structure _ = G :=\nby { ext, refl }\n\n@[simp] lemma Structure_simple_graph_of_structure\n  [S : language.graph.Structure V] [V \u22a8 Theory.simple_graph] :\n  (simple_graph_of_structure V).Structure = S :=\nbegin\n  ext n f xs,\n  { exact (is_relational.empty_functions n).elim f },\n  { ext n r xs,\n    rw iff_eq_eq,\n    cases n,\n    { exact r.elim },\n    { cases n,\n      { exact r.elim },\n      { cases n,\n        { cases r,\n          change rel_map adj ![xs 0, xs 1] = _,\n          refine congr rfl (funext _),\n          simp [fin.forall_fin_two], },\n        { exact r.elim } } } }\nend\n\ntheorem Theory.simple_graph_is_satisfiable :\n  Theory.is_satisfiable Theory.simple_graph :=\n\u27e8@Theory.Model.of _ _ unit (simple_graph.Structure \u22a5) _ _\u27e9\n\nend language\nend first_order\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/model_theory/graph.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7428627991294138}}
{"text": "import data.nat.basic\nimport tactic.linarith\nimport tactic.ring\n\nnamespace nat\nlemma power_geq_1 {k n : \u2115} : (succ k)^n \u2265 1 := begin\ninduction n,\n{ rw [pow_zero], exact le_refl _ },\n{ rw [pow_succ], exact _root_.le_add_left n_ih }\nend\n\nlemma mul_left_cancel {a b c : \u2115} : a > 0 \u2192 a * b = a * c \u2192 b = c := \u03bb pos eq, calc\n  b = b * a / a : symm (nat.mul_div_cancel _ pos)\n  ... = a * b / a : by rw [mul_comm]\n  ... = a * c / a : by rw [eq]\n  ... = c * a / a : by rw [mul_comm]\n  ... = c : nat.mul_div_cancel _ pos\n\nlemma sub_add_from_add_sub : \u03a0 {a b c : \u2115}, a \u2265 c -> b \u2265 c -> a + (b - c) = (a - c) + b\n| 0 b c a_ge_c b_ge_c := begin have : c = 0 := by linarith, simp [this] end\n| (a+1) 0 c a_ge_c b_ge_c := begin have : c = 0 := by linarith, simp [this] end\n| (a+1) (b+1) 0 a_ge_c b_ge_c := by simp\n| (a+1) (b+1) (c+1) a_ge_c b_ge_c := begin\n  have a_ge_c : a \u2265 c := lt_succ_iff.mp a_ge_c,\n  have b_ge_c : b \u2265 c := lt_succ_iff.mp b_ge_c,\n  repeat { rw [add_one] },\n  repeat { rw [add_succ] <|> rw [succ_add] },\n  repeat { rw [succ_sub_succ] },\n  rw [sub_add_from_add_sub a_ge_c b_ge_c]\nend\nlemma pow_le_pow {a b k : \u2115} : a \u2265 b -> a^k \u2265 b^k := begin\n  intro gt,\n  induction k,\n  { simp },\n  rw [pow_succ, pow_succ],\n  exact (mul_le_mul k_ih gt (by linarith) (by linarith))\nend\nlemma pow_ge_one {a k : \u2115} : a \u2265 1 -> a^k \u2265 1 := \u03bb a_pos, calc\n  a^k \u2265 1^k : pow_le_pow a_pos\n  ... = 1 : by simp\nlemma prime_positive {p : \u2115} : prime p -> p > 0 := \u03bb pr, have h : p \u2265 2 := prime.two_le pr, by linarith\nlemma prime_pow_ge_one {p k : \u2115} : prime p -> p^k \u2265 1 :=\n  \u03bb pr, pow_ge_one (prime_positive pr)\n\nlemma pow_lt_pow_right {a k l : \u2115} : a > 1 -> k < l -> a^k < a^l := begin\n  intros a_big lt,\n  induction lt,\n  { exact calc\n      a^k = 1 * a^k : symm (one_mul _)\n      ... < a * a^k : mul_lt_mul a_big (refl _) (pow_ge_one (by linarith)) (by linarith)\n      ... = a^k * a : mul_comm _ _\n      ... = a^(k + 1) : by simp [pow_succ]},\n  exact calc\n    a^k = 1 * a^k : symm (one_mul _)\n    ... < a * a^lt_b : mul_lt_mul a_big (by linarith) (pow_ge_one (by linarith)) (by linarith)\n    ... = a^lt_b * a : mul_comm _ _\n    ... = a^(lt_b + 1) : by simp [pow_succ]\nend\n\nlemma prod_lt_gt {a a' b b' : \u2115} : b > 0 -> a * b = a' * b' -> a < a' -> b > b' := begin\n  intros b_pos eq a_lt_a',\n  have : a' * b > a' * b' := calc\n  a' * b > a * b : mul_lt_mul_of_pos_right a_lt_a' b_pos\n  ... = a' * b' : eq,\n  apply lt_of_mul_lt_mul_left this (zero_le _)\nend\nlemma prod_gt_lt {a a' b b' : \u2115} : a > 0 -> a * b = a' * b' -> b < b' -> a > a' := begin\n  rw [mul_comm a b, mul_comm a' b'],\n  apply prod_lt_gt\nend\n\nlemma pos_of_mul_pos {a b : \u2115} : a * b > 0 -> a > 0 := begin\n  cases a,\n  { simp },\n  intros _,\n  exact succ_pos a\nend\nlemma pos_of_mul_pos_right {a b : \u2115} : a * b > 0 -> b > 0 := begin\n  cases b,\n  { simp },\n  intros _,\n  exact succ_pos b\nend\n\nlemma pos_of_dvd_pos {a b : \u2115} : b > 0 -> a \u2223 b -> a > 0 := begin\n  rintros gt \u27e8k, prod\u27e9,\n  rw [prod] at gt,\n  apply pos_of_mul_pos gt,\nend\n\nlemma dvd_pow_succ {p k n : \u2115} : prime p -> n \u2223 p^(k + 1) -> n = p^(k + 1) \u2228 n \u2223 p^k := begin\n  rintros pr divides,\n  obtain \u27e8l , bound, pf\u27e9 := (dvd_prime_pow pr).1 divides,\n  rcases lt_trichotomy l (k+1) with h | h | h,\n  { have : l \u2264 k := by linarith,\n    apply or.inr,\n    apply (dvd_prime_pow pr).2,\n    finish },\n  { apply or.inl,\n    rw [pf, h] },\n  have : p^(k + 1) > 0 := prime_pow_ge_one pr,\n  have : n \u2264 p^(k + 1) := le_of_dvd this divides,\n  have : p^(k + 1) < p^(k + 1) := calc\n  p^(k + 1) < p^l : pow_lt_pow_right (prime.two_le pr) h\n  ... = n : symm pf\n  ... \u2264 p^(k + 1) : this,\n  linarith\nend\n\nlemma coprime_gcd {a b c : \u2115} : coprime b c \u2192 coprime (gcd a b) (gcd a c) :=\n  coprime.coprime_dvd_left (gcd_dvd_right a b) \u2218\n  coprime.coprime_dvd_right (gcd_dvd_right a c)\n\nlemma prod_coprime_gcd {a b c : \u2115} : a > 0 -> coprime b c -> gcd a b * gcd a c = gcd a (b * c) := begin\n  intros a_pos coprime,\n  apply le_antisymm;\n  apply le_of_dvd,\n  { exact gcd_pos_of_pos_left _ a_pos },\n  { exact nat.coprime.mul_dvd_of_dvd_of_dvd (coprime_gcd coprime) (gcd_dvd_gcd_mul_right_right a b c) (gcd_dvd_gcd_mul_left_right a c b) },\n  { exact (mul_lt_mul_left (gcd_pos_of_pos_left _ a_pos)).2 (gcd_pos_of_pos_left _ a_pos) },\n  { exact gcd_mul_dvd_mul_gcd _ _ _ }\nend\nlemma prod_coprime_gcd_left {a b c : \u2115} : c > 0 -> coprime a b -> gcd a c * gcd b c = gcd (a * b) c := begin\n  rw [gcd_comm a c, gcd_comm b c, gcd_comm (a * b) c],\n  exact prod_coprime_gcd\nend\n\nopen nat (succ)\n\n@[simp]\nlemma gcd_add {a b : \u2115} : nat.gcd a (a + b) = nat.gcd b a := begin\n  cases a,\n  { simp },\n  cases b,\n  { simp },\n  exact calc\n    nat.gcd (succ a) (succ a + succ b)\n        = nat.gcd (succ b % succ a) (succ a) : by rw [nat.gcd_succ, nat.add_mod_left]\n    ... = nat.gcd (succ b) (succ a) : by rw [\u2190nat.gcd_succ, nat.gcd_comm]\nend\n\ntheorem coprime_sub_one {n : \u2115} : n > 0 -> coprime (n - 1) n := begin\n  intro n_pos,\n  cases n,\n  { linarith },\n  exact calc\n    nat.gcd ((n + 1) - 1) (n + 1) = nat.gcd 1 n : by simp\n    ... = 1 : nat.gcd_one_left _\nend\n\nend nat\n", "meta": {"author": "Vierkantor", "repo": "mersenne-primes", "sha": "5619349a9c93a929d1827f0e1d100f8a508ebd5c", "save_path": "github-repos/lean/Vierkantor-mersenne-primes", "path": "github-repos/lean/Vierkantor-mersenne-primes/mersenne-primes-5619349a9c93a929d1827f0e1d100f8a508ebd5c/src/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582995, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7428627991219157}}
{"text": "import ..prooflab\nimport lectures.lec0_intro\n\n/-! # Homework 0 \nHomework must be done individually.\nReplace the placeholders `sorry` with your proofs. \nrefl, exact, rw\n-/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace PROOFS \n\n\n\n/-! ## Question 1  -/\n\nexample (x y : \u2115) : \n  y + 0 = y :=\nbegin\n  refl, -- 0 added to a number is that number\nend\n\n\n\n\n/-! ## Question 2 -/\n\nexample (m n : \u2115) (h\u2081 : n = 4) (h\u2082: m^2 = n) : \n  n = m^2 := \nbegin\n  rw h\u2082, -- substitute m^2 with n, left with n=n, then applies refl\nend\n\n\n\n\n/-! ## Question 3 -/\n\nexample (x y : \u2115) (h\u2081 : y = x) (h\u2082 : y - 1 = 0) : \n 5^(y - 1) = (2 + 3)^(x - 1) :=\nbegin\n  rw h\u2081, -- replaces y with x in target, simplifies 2+3 to 5, then left with 5^(x-1) = 5^(x-1), then applies refl\nend\n\n\n\n\n/-! ## Question 4 -/\n\nexample (x y : \u2115) (h\u2081 : y = x) (h\u2082 : x - 1 = 0) : \n 5^(y - 1) = 5^0 :=\nbegin\n  rw h\u2081, -- replaces y with x in target, left with 5^(x-1) = 5^0\n  rw h\u2082, -- replaces x-1 in target with 0, left with 5^0 = 5^0, applies refl\nend\n\n\n\n\n/-! ## Question 5 -/\n\nexample (a b c x y z : \u2115) (h\u2081 : 26 = x^2 + y^2 + z^2) \n(h\u2082 : x^2 = 2 * a) (h\u2083 : y^2 = b) (h\u2084 : z^2 = 1) : \n2 * a + b + 1 - z = 26 - z := \nbegin\n  rw h\u2082 at h\u2081, -- replaces x^2 with 2a in h\u2081\n  rw h\u2083 at h\u2081, -- replaces y^2 with b in h\u2081\n  rw h\u2084 at h\u2081, -- replaces z^2 with 1 in h\u2081\n  rw h\u2081, -- replaces 2a + b + 1 in target with 26, left with 26-z = 26-z, applies refl\nend \n\n\n\n\nend PROOFS", "meta": {"author": "cjfaul", "repo": "ProofLab", "sha": "5b2010894e7a5434d5146e431277680f16ecc0cc", "save_path": "github-repos/lean/cjfaul-ProofLab", "path": "github-repos/lean/cjfaul-ProofLab/ProofLab-5b2010894e7a5434d5146e431277680f16ecc0cc/src/homework/hw0.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7428627950831904}}
{"text": "theorem le_antisymm (a b : mynat) (hab : a \u2264 b) (hba : b \u2264 a) : a = b :=\nbegin\ncases hab with c hc,\ncases hba with d hd,\nrw hc at hd,\nrw add_assoc at hd,\nsymmetry at hd,\nhave h1 := eq_zero_of_add_right_eq_self hd,\nhave h2 := add_right_eq_zero h1,\nrw hc,\nrw h2,\nrwa add_zero,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world10/level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.8152324871074607, "lm_q1q2_score": 0.742823307093665}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.algebra.basic\nimport number_theory.class_number.admissible_absolute_value\n\n/-!\n# Admissible absolute value on the integers\nThis file defines an admissible absolute value `absolute_value.abs_is_admissible`\nwhich we use to show the class number of the ring of integers of a number field\nis finite.\n\n## Main results\n\n * `absolute_value.abs_is_admissible` shows the \"standard\" absolute value on `\u2124`,\n   mapping negative `x` to `-x`, is admissible.\n-/\n\nnamespace absolute_value\n\nopen int\n\n/-- We can partition a finite family into `partition_card \u03b5` sets, such that the remainders\nin each set are close together. -/\nlemma exists_partition_int (n : \u2115) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {b : \u2124} (hb : b \u2260 0) (A : fin n \u2192 \u2124) :\n  \u2203 (t : fin n \u2192 fin \u23081 / \u03b5\u2309\u208a),\n  \u2200 i\u2080 i\u2081, t i\u2080 = t i\u2081 \u2192 \u2191(abs (A i\u2081 % b - A i\u2080 % b)) < abs b \u2022 \u03b5 :=\nbegin\n  have hb' : (0 : \u211d) < \u2191(abs b) := int.cast_pos.mpr (abs_pos.mpr hb),\n  have hb\u03b5 : 0 < abs b \u2022 \u03b5,\n  { rw algebra.smul_def,\n    exact mul_pos hb' h\u03b5 },\n  have hfloor : \u2200 i, 0 \u2264 floor ((A i % b : \u2124) / (abs b \u2022 \u03b5) : \u211d),\n  { intro i,\n    exact floor_nonneg.mpr (div_nonneg (cast_nonneg.mpr (mod_nonneg _ hb)) hb\u03b5.le) },\n  refine \u27e8\u03bb i, \u27e8nat_abs (floor ((A i % b : \u2124) / (abs b \u2022 \u03b5) : \u211d)), _\u27e9, _\u27e9,\n  { rw [\u2190 coe_nat_lt, nat_abs_of_nonneg (hfloor i), floor_lt],\n    apply lt_of_lt_of_le _ (nat.le_ceil _),\n    rw [algebra.smul_def, ring_hom.eq_int_cast, \u2190 div_div, div_lt_div_right h\u03b5,\n        div_lt_iff hb', one_mul, cast_lt],\n    exact int.mod_lt _ hb },\n  intros i\u2080 i\u2081 hi,\n  have hi : (\u230a\u2191(A i\u2080 % b) / abs b \u2022 \u03b5\u230b.nat_abs : \u2124) = \u230a\u2191(A i\u2081 % b) / abs b \u2022 \u03b5\u230b.nat_abs :=\n    congr_arg (coe : \u2115 \u2192 \u2124) (subtype.mk_eq_mk.mp hi),\n  rw [nat_abs_of_nonneg (hfloor i\u2080), nat_abs_of_nonneg (hfloor i\u2081)] at hi,\n  have hi := abs_sub_lt_one_of_floor_eq_floor hi,\n  rw [abs_sub_comm, \u2190 sub_div, abs_div, abs_of_nonneg hb\u03b5.le, div_lt_iff hb\u03b5, one_mul] at hi,\n  rwa [int.cast_abs, int.cast_sub]\nend\n\n/-- `abs : \u2124 \u2192 \u2124` is an admissible absolute value -/\nnoncomputable def abs_is_admissible : is_admissible absolute_value.abs :=\n{ card := \u03bb \u03b5, \u23081 / \u03b5\u2309\u208a,\n  exists_partition' := \u03bb n \u03b5 h\u03b5 b hb, exists_partition_int n h\u03b5 hb,\n  .. absolute_value.abs_is_euclidean }\n\nnoncomputable instance : inhabited (is_admissible absolute_value.abs) :=\n\u27e8abs_is_admissible\u27e9\n\nend absolute_value\n", "meta": {"author": "lean-forward", "repo": "class-number-journal", "sha": "34d5872618d289ca3982bd9bc0c6e06af678909a", "save_path": "github-repos/lean/lean-forward-class-number-journal", "path": "github-repos/lean/lean-forward-class-number-journal/class-number-journal-34d5872618d289ca3982bd9bc0c6e06af678909a/src/admissible_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7428150242873272}}
{"text": "/-\nCopyright (c) 2018 Guy Leroy. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport data.nat.prime\n/-!\n# Extended GCD and divisibility over \u2124\n\n## Main definitions\n\n* Given `x y : \u2115`, `xgcd x y` computes the pair of integers `(a, b)` such that\n  `gcd x y = x * a + y * b`. `gcd_a x y` and `gcd_b x y` are defined to be `a` and `b`,\n  respectively.\n\n## Main statements\n\n* `gcd_eq_gcd_ab`: B\u00e9zout's lemma, given `x y : \u2115`, `gcd x y = x * gcd_a x y + y * gcd_b x y`.\n\n## Tags\n\nB\u00e9zout's lemma, Bezout's lemma\n-/\n\n/-! ### Extended Euclidean algorithm -/\nnamespace nat\n\n/-- Helper function for the extended GCD algorithm (`nat.xgcd`). -/\ndef xgcd_aux : \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u00d7 \u2124 \u00d7 \u2124\n| 0          s t r' s' t' := (r', s', t')\n| r@(succ _) s t r' s' t' :=\n  have r' % r < r, from mod_lt _ $ succ_pos _,\n  let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t\n\n@[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=\nby simp [xgcd_aux]\n\ntheorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) :\n  xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=\nby cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}]\n\n/-- Use the extended GCD algorithm to generate the `a` and `b` values\n  satisfying `gcd x y = x * a + y * b`. -/\ndef xgcd (x y : \u2115) : \u2124 \u00d7 \u2124 := (xgcd_aux x 1 0 y 0 1).2\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a (x y : \u2115) : \u2124 := (xgcd x y).1\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b (x y : \u2115) : \u2124 := (xgcd x y).2\n\n@[simp] theorem gcd_a_zero_left {s : \u2115} : gcd_a 0 s = 0 :=\nby { unfold gcd_a, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_b_zero_left {s : \u2115} : gcd_b 0 s = 1 :=\nby { unfold gcd_b, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_a_zero_right {s : \u2115} (h : s \u2260 0) : gcd_a s 0 = 1 :=\nbegin\n  unfold gcd_a xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem gcd_b_zero_right {s : \u2115} (h : s \u2260 0) : gcd_b s 0 = 0 :=\nbegin\n  unfold gcd_b xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem xgcd_aux_fst (x y) : \u2200 s t s' t',\n  (xgcd_aux x s t y s' t').1 = gcd x y :=\ngcd.induction x y (by simp) (\u03bb x y h IH s t s' t', by simp [xgcd_aux_rec, h, IH]; rw \u2190 gcd_rec)\n\ntheorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=\nby rw [xgcd, \u2190 xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl\n\ntheorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nby unfold gcd_a gcd_b; cases xgcd x y; refl\n\nsection\nparameters (x y : \u2115)\n\nprivate def P : \u2115 \u00d7 \u2124 \u00d7 \u2124 \u2192 Prop\n| (r, s, t) := (r : \u2124) = x * s + y * t\n\ntheorem xgcd_aux_P {r r'} : \u2200 {s t s' t'}, P (r, s, t) \u2192 P (r', s', t') \u2192\n  P (xgcd_aux r s t r' s' t') :=\ngcd.induction r r' (by simp) $ \u03bb a b h IH s t s' t' p p', begin\n  rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *,\n  rw [int.mod_def], generalize : (b / a : \u2124) = k,\n  rw [p, p'],\n  simp [mul_add, mul_comm, mul_left_comm, add_comm, add_left_comm, sub_eq_neg_add, mul_assoc]\nend\n\n/-- **B\u00e9zout's lemma**: given `x y : \u2115`, `gcd x y = x * a + y * b`, where `a = gcd_a x y` and\n`b = gcd_b x y` are computed by the extended Euclidean algorithm.\n-/\ntheorem gcd_eq_gcd_ab : (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y :=\nby have := @xgcd_aux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P]);\n   rwa [xgcd_aux_val, xgcd_val] at this\nend\n\nlemma exists_mul_mod_eq_gcd {k n : \u2115} (hk : gcd n k < k) :\n  \u2203 m, n * m % k = gcd n k :=\nbegin\n  have hk' := int.coe_nat_ne_zero.mpr (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk)),\n  have key := congr_arg (\u03bb m, int.nat_mod m k) (gcd_eq_gcd_ab n k),\n  simp_rw int.nat_mod at key,\n  rw [int.add_mul_mod_self_left, \u2190int.coe_nat_mod, int.to_nat_coe_nat, mod_eq_of_lt hk] at key,\n  refine \u27e8(n.gcd_a k % k).to_nat, eq.trans (int.coe_nat_inj _) key.symm\u27e9,\n  rw [int.coe_nat_mod, int.coe_nat_mul, int.to_nat_of_nonneg (int.mod_nonneg _ hk'),\n      int.to_nat_of_nonneg (int.mod_nonneg _ hk'), int.mul_mod, int.mod_mod, \u2190int.mul_mod],\nend\n\nlemma exists_mul_mod_eq_one_of_coprime {k n : \u2115} (hkn : coprime n k) (hk : 1 < k) :\n  \u2203 m, n * m % k = 1 :=\nExists.cases_on (exists_mul_mod_eq_gcd (lt_of_le_of_lt (le_of_eq hkn) hk))\n  (\u03bb m hm, \u27e8m, hm.trans hkn\u27e9)\n\nend nat\n\n/-! ### Divisibility over \u2124 -/\nnamespace int\n\nprotected lemma coe_nat_gcd (m n : \u2115) : int.gcd \u2191m \u2191n = nat.gcd m n := rfl\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a : \u2124 \u2192 \u2124 \u2192 \u2124\n| (of_nat m) n := m.gcd_a n.nat_abs\n| -[1+ m]    n := -m.succ.gcd_a n.nat_abs\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b : \u2124 \u2192 \u2124 \u2192 \u2124\n| m (of_nat n) := m.nat_abs.gcd_b n\n| m -[1+ n]    := -m.nat_abs.gcd_b n.succ\n\n/-- **B\u00e9zout's lemma** -/\ntheorem gcd_eq_gcd_ab : \u2200 x y : \u2124, (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y\n| (m : \u2115) (n : \u2115) := nat.gcd_eq_gcd_ab _ _\n| (m : \u2115) -[1+ n] := show (_ : \u2124) = _ + -(n+1) * -_, by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] (n : \u2115) := show (_ : \u2124) = -(m+1) * -_ + _ , by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] -[1+ n] := show (_ : \u2124) = -(m+1) * -_ + -(n+1) * -_,\n  by { rw [neg_mul_neg, neg_mul_neg], apply nat.gcd_eq_gcd_ab }\n\ntheorem nat_abs_div (a b : \u2124) (H : b \u2223 a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) :=\nbegin\n  cases (nat.eq_zero_or_pos (nat_abs b)),\n  {rw eq_zero_of_nat_abs_eq_zero h, simp [int.div_zero]},\n  calc\n  nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one\n    ... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h\n    ... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ dvd_rfl)\n    ... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b)\n    ... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H,\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : nat.prime p) {m n : \u2124} {k l : \u2115}\n      (hpm : \u2191(p ^ k) \u2223 m)\n      (hpn : \u2191(p ^ l) \u2223 n) (hpmn : \u2191(p ^ (k+l+1)) \u2223 m*n) : \u2191(p ^ (k+1)) \u2223 m \u2228 \u2191(p ^ (l+1)) \u2223 n :=\nhave hpm' : p ^ k \u2223 m.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpm,\nhave hpn' : p ^ l \u2223 n.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpn,\nhave hpmn' : (p ^ (k+l+1)) \u2223 m.nat_abs*n.nat_abs,\n  by rw \u2190int.nat_abs_mul; apply (int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpmn),\nlet hsd := nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn' in\nhsd.elim\n  (\u03bb hsd1, or.inl begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd1 end)\n  (\u03bb hsd2, or.inr begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd2 end)\n\ntheorem dvd_of_mul_dvd_mul_left {i j k : \u2124} (k_non_zero : k \u2260 0) (H : k * i \u2223 k * j) : i \u2223 j :=\ndvd.elim H (\u03bbl H1, by rw mul_assoc at H1; exact \u27e8_, mul_left_cancel\u2080 k_non_zero H1\u27e9)\n\ntheorem dvd_of_mul_dvd_mul_right {i j k : \u2124} (k_non_zero : k \u2260 0) (H : i * k \u2223 j * k) : i \u2223 j :=\nby rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H\n\nlemma prime.dvd_nat_abs_of_coe_dvd_sq {p : \u2115} (hp : p.prime) (k : \u2124) (h : \u2191p \u2223 k ^ 2) :\n  p \u2223 k.nat_abs :=\nbegin\n  apply @nat.prime.dvd_of_dvd_pow _ _ 2 hp,\n  rwa [sq, \u2190 nat_abs_mul, \u2190 coe_nat_dvd_left, \u2190 sq]\nend\n\n/-- \u2124 specific version of least common multiple. -/\ndef lcm (i j : \u2124) : \u2115 := nat.lcm (nat_abs i) (nat_abs j)\n\ntheorem lcm_def (i j : \u2124) : lcm i j = nat.lcm (nat_abs i) (nat_abs j) := rfl\n\nprotected lemma coe_nat_lcm (m n : \u2115) : int.lcm \u2191m \u2191n = nat.lcm m n := rfl\n\ntheorem gcd_dvd_left (i j : \u2124) : (gcd i j : \u2124) \u2223 i :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_left _ _\n\ntheorem gcd_dvd_right (i j : \u2124) : (gcd i j : \u2124) \u2223 j :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_right _ _\n\ntheorem dvd_gcd {i j k : \u2124} (h1 : k \u2223 i) (h2 : k \u2223 j) : k \u2223 gcd i j :=\nnat_abs_dvd.1 $ coe_nat_dvd.2 $ nat.dvd_gcd (nat_abs_dvd_iff_dvd.2 h1) (nat_abs_dvd_iff_dvd.2 h2)\n\ntheorem gcd_mul_lcm (i j : \u2124) : gcd i j * lcm i j = nat_abs (i * j) :=\nby rw [int.gcd, int.lcm, nat.gcd_mul_lcm, nat_abs_mul]\n\ntheorem gcd_comm (i j : \u2124) : gcd i j = gcd j i := nat.gcd_comm _ _\n\ntheorem gcd_assoc (i j k : \u2124) : gcd (gcd i j) k = gcd i (gcd j k) := nat.gcd_assoc _ _ _\n\n@[simp] theorem gcd_self (i : \u2124) : gcd i i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_left (i : \u2124) : gcd 0 i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_right (i : \u2124) : gcd i 0 = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_one_left (i : \u2124) : gcd 1 i = 1 := nat.gcd_one_left _\n\n@[simp] theorem gcd_one_right (i : \u2124) : gcd i 1 = 1 := nat.gcd_one_right _\n\ntheorem gcd_mul_left (i j k : \u2124) : gcd (i * j) (i * k) = nat_abs i * gcd j k :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_left }\n\ntheorem gcd_mul_right (i j k : \u2124) : gcd (i * j) (k * j) = gcd i k * nat_abs j :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_right }\n\ntheorem gcd_pos_of_non_zero_left {i : \u2124} (j : \u2124) (i_non_zero : i \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_left (nat_abs j) (nat_abs_pos_of_ne_zero i_non_zero)\n\ntheorem gcd_pos_of_non_zero_right (i : \u2124) {j : \u2124} (j_non_zero : j \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_right (nat_abs i) (nat_abs_pos_of_ne_zero j_non_zero)\n\ntheorem gcd_eq_zero_iff {i j : \u2124} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 :=\nbegin\n  rw int.gcd,\n  split,\n  { intro h,\n    exact \u27e8nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_left h),\n      nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_right h)\u27e9 },\n  { intro h, rw [nat_abs_eq_zero.mpr h.left, nat_abs_eq_zero.mpr h.right],\n    apply nat.gcd_zero_left }\nend\n\ntheorem gcd_div {i j k : \u2124} (H1 : k \u2223 i) (H2 : k \u2223 j) :\n  gcd (i / k) (j / k) = gcd i j / nat_abs k :=\nby rw [gcd, nat_abs_div i k H1, nat_abs_div j k H2];\nexact nat.gcd_div (nat_abs_dvd_iff_dvd.mpr H1) (nat_abs_dvd_iff_dvd.mpr H2)\n\ntheorem gcd_div_gcd_div_gcd {i j : \u2124} (H : 0 < gcd i j) :\n  gcd (i / gcd i j) (j / gcd i j) = 1 :=\nbegin\n  rw [gcd_div (gcd_dvd_left i j) (gcd_dvd_right i j)],\n  rw [nat_abs_of_nat, nat.div_self H]\nend\n\ntheorem gcd_dvd_gcd_of_dvd_left {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd i j \u2223 gcd k j :=\nint.coe_nat_dvd.1 $ dvd_gcd ((gcd_dvd_left i j).trans H) (gcd_dvd_right i j)\n\ntheorem gcd_dvd_gcd_of_dvd_right {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd j i \u2223 gcd j k :=\nint.coe_nat_dvd.1 $ dvd_gcd (gcd_dvd_left j i) ((gcd_dvd_right j i).trans H)\n\ntheorem gcd_dvd_gcd_mul_left (i j k : \u2124) : gcd i j \u2223 gcd (k * i) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (i j k : \u2124) : gcd i j \u2223 gcd (i * k) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (i j k : \u2124) : gcd i j \u2223 gcd i (k * j) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (i j k : \u2124) : gcd i j \u2223 gcd i (j * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {i j : \u2124} (H : i \u2223 j) : gcd i j = nat_abs i :=\nnat.dvd_antisymm (by unfold gcd; exact nat.gcd_dvd_left _ _)\n                 (by unfold gcd; exact nat.dvd_gcd dvd_rfl (nat_abs_dvd_iff_dvd.mpr H))\n\ntheorem gcd_eq_right {i j : \u2124} (H : j \u2223 i) : gcd i j = nat_abs j :=\nby rw [gcd_comm, gcd_eq_left H]\n\ntheorem ne_zero_of_gcd {x y : \u2124}\n  (hc : gcd x y \u2260 0) : x \u2260 0 \u2228 y \u2260 0 :=\nbegin\n  contrapose! hc,\n  rw [hc.left, hc.right, gcd_zero_right, nat_abs_zero]\nend\n\ntheorem exists_gcd_one {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (m' n' : \u2124), gcd m' n' = 1 \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n\u27e8_, _, gcd_div_gcd_div_gcd H,\n  (int.div_mul_cancel (gcd_dvd_left m n)).symm,\n  (int.div_mul_cancel (gcd_dvd_right m n)).symm\u27e9\n\ntheorem exists_gcd_one' {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (g : \u2115) (m' n' : \u2124), 0 < g \u2227 gcd m' n' = 1 \u2227 m = m' * g \u2227 n = n' * g :=\nlet \u27e8m', n', h\u27e9 := exists_gcd_one H in \u27e8_, m', n', H, h\u27e9\n\ntheorem pow_dvd_pow_iff {m n : \u2124} {k : \u2115} (k0 : 0 < k) : m ^ k \u2223 n ^ k \u2194 m \u2223 n :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, pow_dvd_pow_of_dvd h _\u27e9,\n  apply int.nat_abs_dvd_iff_dvd.mp,\n  apply (nat.pow_dvd_pow_iff k0).mp,\n  rw [\u2190 int.nat_abs_pow, \u2190 int.nat_abs_pow],\n  exact int.nat_abs_dvd_iff_dvd.mpr h\nend\n\n/-! ### lcm -/\n\ntheorem lcm_comm (i j : \u2124) : lcm i j = lcm j i :=\nby { rw [int.lcm, int.lcm], exact nat.lcm_comm _ _ }\n\ntheorem lcm_assoc (i j k : \u2124) : lcm (lcm i j) k = lcm i (lcm j k) :=\nby { rw [int.lcm, int.lcm, int.lcm, int.lcm, nat_abs_of_nat, nat_abs_of_nat], apply nat.lcm_assoc }\n\n@[simp] theorem lcm_zero_left (i : \u2124) : lcm 0 i = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_left }\n\n@[simp] theorem lcm_zero_right (i : \u2124) : lcm i 0 = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_right }\n\n@[simp] theorem lcm_one_left (i : \u2124) : lcm 1 i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_left }\n\n@[simp] theorem lcm_one_right (i : \u2124) : lcm i 1 = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_right }\n\n@[simp] theorem lcm_self (i : \u2124) : lcm i i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_self }\n\ntheorem dvd_lcm_left (i j : \u2124) : i \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_left }\n\ntheorem dvd_lcm_right (i j : \u2124) : j \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_right }\n\ntheorem lcm_dvd {i j k : \u2124}  : i \u2223 k \u2192 j \u2223 k \u2192 (lcm i j : \u2124) \u2223 k :=\nbegin\n  rw int.lcm,\n  intros hi hj,\n  exact coe_nat_dvd_left.mpr\n    (nat.lcm_dvd (nat_abs_dvd_iff_dvd.mpr hi) (nat_abs_dvd_iff_dvd.mpr hj))\nend\n\nend int\n\nlemma pow_gcd_eq_one {M : Type*} [monoid M] (x : M) {m n : \u2115} (hm : x ^ m = 1) (hn : x ^ n = 1) :\n  x ^ m.gcd n = 1 :=\nbegin\n  cases m, { simp only [hn, nat.gcd_zero_left] },\n  obtain \u27e8x, rfl\u27e9 : is_unit x,\n  { apply is_unit_of_pow_eq_one _ _ hm m.succ_pos },\n  simp only [\u2190 units.coe_pow] at *,\n  rw [\u2190 units.coe_one, \u2190 zpow_coe_nat, \u2190 units.ext_iff] at *,\n  simp only [nat.gcd_eq_gcd_ab, zpow_add, zpow_mul, hm, hn, one_zpow, one_mul]\nend\n\nlemma gcd_nsmul_eq_zero {M : Type*} [add_monoid M] (x : M) {m n : \u2115} (hm : m \u2022 x = 0)\n  (hn : n \u2022 x = 0) : (m.gcd n) \u2022 x = 0 :=\nbegin\n  apply multiplicative.of_add.injective,\n  rw [of_add_nsmul, of_add_zero, pow_gcd_eq_one];\n  rwa [\u2190of_add_nsmul, \u2190of_add_zero, equiv.apply_eq_iff_eq]\nend\n\nattribute [to_additive gcd_nsmul_eq_zero] pow_gcd_eq_one\n\n/-! ### GCD prover -/\nopen norm_num\n\nnamespace tactic\nnamespace norm_num\n\nlemma int_gcd_helper' {d : \u2115} {x y a b : \u2124} (h\u2081 : (d:\u2124) \u2223 x) (h\u2082 : (d:\u2124) \u2223 y)\n  (h\u2083 : x * a + y * b = d) : int.gcd x y = d :=\nbegin\n  refine nat.dvd_antisymm _ (int.coe_nat_dvd.1 (int.dvd_gcd h\u2081 h\u2082)),\n  rw [\u2190 int.coe_nat_dvd, \u2190 h\u2083],\n  apply dvd_add,\n  { exact (int.gcd_dvd_left _ _).mul_right _ },\n  { exact (int.gcd_dvd_right _ _).mul_right _ }\nend\n\nlemma nat_gcd_helper_dvd_left (x y a : \u2115) (h : x * a = y) : nat.gcd x y = x :=\nnat.gcd_eq_left \u27e8a, h.symm\u27e9\n\nlemma nat_gcd_helper_dvd_right (x y a : \u2115) (h : y * a = x) : nat.gcd x y = y :=\nnat.gcd_eq_right \u27e8a, h.symm\u27e9\n\nlemma nat_gcd_helper_2 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (hx : x * a = tx) (hy : y * b = ty) (h : ty + d = tx) : nat.gcd x y = d :=\nbegin\n  rw \u2190 int.coe_nat_gcd, apply @int_gcd_helper' _ _ _ a (-b)\n    (int.coe_nat_dvd.2 \u27e8_, hu.symm\u27e9) (int.coe_nat_dvd.2 \u27e8_, hv.symm\u27e9),\n  rw [mul_neg_eq_neg_mul_symm, \u2190 sub_eq_add_neg, sub_eq_iff_eq_add'],\n  norm_cast, rw [hx, hy, h]\nend\n\nlemma nat_gcd_helper_1 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (hx : x * a = tx) (hy : y * b = ty) (h : tx + d = ty) : nat.gcd x y = d :=\n(nat.gcd_comm _ _).trans $ nat_gcd_helper_2 _ _ _ _ _ _ _ _ _ hv hu hy hx h\n\nlemma nat_lcm_helper (x y d m n : \u2115) (hd : nat.gcd x y = d) (d0 : 0 < d)\n  (xy : x * y = n) (dm : d * m = n) : nat.lcm x y = m :=\n(nat.mul_right_inj d0).1 $ by rw [dm, \u2190 xy, \u2190 hd, nat.gcd_mul_lcm]\n\nlemma nat_coprime_helper_zero_left (x : \u2115) (h : 1 < x) : \u00ac nat.coprime 0 x :=\nmt (nat.coprime_zero_left _).1 $ ne_of_gt h\n\nlemma nat_coprime_helper_zero_right (x : \u2115) (h : 1 < x) : \u00ac nat.coprime x 0 :=\nmt (nat.coprime_zero_right _).1 $ ne_of_gt h\n\n\n\nlemma nat_coprime_helper_2 (x y a b tx ty : \u2115)\n  (hx : x * a = tx) (hy : y * b = ty) (h : ty + 1 = tx) : nat.coprime x y :=\nnat_gcd_helper_2 _ _ _ _ _ _ _ _ _ (one_mul _) (one_mul _) hx hy h\n\nlemma nat_not_coprime_helper (d x y u v : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (h : 1 < d) : \u00ac nat.coprime x y :=\nnat.not_coprime_of_dvd_of_dvd h \u27e8_, hu.symm\u27e9 \u27e8_, hv.symm\u27e9\n\nlemma int_gcd_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx:\u2124) = x) (hy : (ny:\u2124) = y)\n  (h : nat.gcd nx ny = d) : int.gcd x y = d :=\nby rwa [\u2190 hx, \u2190 hy, int.coe_nat_gcd]\n\nlemma int_gcd_helper_neg_left (x y : \u2124) (d : \u2115) (h : int.gcd x y = d) : int.gcd (-x) y = d :=\nby rw int.gcd at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_gcd_helper_neg_right (x y : \u2124) (d : \u2115) (h : int.gcd x y = d) : int.gcd x (-y) = d :=\nby rw int.gcd at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_lcm_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx:\u2124) = x) (hy : (ny:\u2124) = y)\n  (h : nat.lcm nx ny = d) : int.lcm x y = d :=\nby rwa [\u2190 hx, \u2190 hy, int.coe_nat_lcm]\n\nlemma int_lcm_helper_neg_left (x y : \u2124) (d : \u2115) (h : int.lcm x y = d) : int.lcm (-x) y = d :=\nby rw int.lcm at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_lcm_helper_neg_right (x y : \u2124) (d : \u2115) (h : int.lcm x y = d) : int.lcm x (-y) = d :=\nby rw int.lcm at h \u22a2; rwa int.nat_abs_neg\n\n/-- Evaluates the `nat.gcd` function. -/\nmeta def prove_gcd_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 0, _ := pure (c, ey, `(nat.gcd_zero_left).mk_app [ey])\n  | _, 0 := pure (c, ex, `(nat.gcd_zero_right).mk_app [ex])\n  | 1, _ := pure (c, `(1:\u2115), `(nat.gcd_one_left).mk_app [ey])\n  | _, 1 := pure (c, `(1:\u2115), `(nat.gcd_one_right).mk_app [ex])\n  | _, _ := do\n    let (d, a, b) := nat.xgcd_aux x 1 0 y 0 1,\n    if d = x then do\n      (c, ea) \u2190 c.of_nat (y / x),\n      (c, _, p) \u2190 prove_mul_nat c ex ea,\n      pure (c, ex, `(nat_gcd_helper_dvd_left).mk_app [ex, ey, ea, p])\n    else if d = y then do\n      (c, ea) \u2190 c.of_nat (x / y),\n      (c, _, p) \u2190 prove_mul_nat c ey ea,\n      pure (c, ey, `(nat_gcd_helper_dvd_right).mk_app [ex, ey, ea, p])\n    else do\n      (c, ed) \u2190 c.of_nat d,\n      (c, ea) \u2190 c.of_nat a.nat_abs,\n      (c, eb) \u2190 c.of_nat b.nat_abs,\n      (c, eu) \u2190 c.of_nat (x / d),\n      (c, ev) \u2190 c.of_nat (y / d),\n      (c, _, pu) \u2190 prove_mul_nat c ed eu,\n      (c, _, pv) \u2190 prove_mul_nat c ed ev,\n      (c, etx, px) \u2190 prove_mul_nat c ex ea,\n      (c, ety, py) \u2190 prove_mul_nat c ey eb,\n      (c, p) \u2190 if a \u2265 0 then prove_add_nat c ety ed etx else prove_add_nat c etx ed ety,\n      let pf : expr := if a \u2265 0 then `(nat_gcd_helper_2) else `(nat_gcd_helper_1),\n      pure (c, ed, pf.mk_app [ed, ex, ey, ea, eb, eu, ev, etx, ety, pu, pv, px, py, p])\n  end\n\n/-- Evaluates the `nat.lcm` function. -/\nmeta def prove_lcm_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 0, _ := pure (c, `(0:\u2115), `(nat.lcm_zero_left).mk_app [ey])\n  | _, 0 := pure (c, `(0:\u2115), `(nat.lcm_zero_right).mk_app [ex])\n  | 1, _ := pure (c, ey, `(nat.lcm_one_left).mk_app [ey])\n  | _, 1 := pure (c, ex, `(nat.lcm_one_right).mk_app [ex])\n  | _, _ := do\n    (c, ed, pd) \u2190 prove_gcd_nat c ex ey,\n    (c, p0) \u2190 prove_pos c ed,\n    (c, en, xy) \u2190 prove_mul_nat c ex ey,\n    d \u2190 ed.to_nat,\n    (c, em) \u2190 c.of_nat ((x * y) / d),\n    (c, _, dm) \u2190 prove_mul_nat c ed em,\n    pure (c, em, `(nat_lcm_helper).mk_app [ex, ey, ed, em, en, pd, p0, xy, dm])\n  end\n\n/-- Evaluates the `int.gcd` function. -/\nmeta def prove_gcd_int (zc nc : instance_cache) : expr \u2192 expr \u2192\n  tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| x y := match match_neg x with\n  | some x := do\n    (zc, nc, d, p) \u2190 prove_gcd_int x y,\n    pure (zc, nc, d, `(int_gcd_helper_neg_left).mk_app [x, y, d, p])\n  | none := match match_neg y with\n    | some y := do\n      (zc, nc, d, p) \u2190 prove_gcd_int x y,\n      pure (zc, nc, d, `(int_gcd_helper_neg_right).mk_app [x, y, d, p])\n    | none := do\n      (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x,\n      (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y,\n      (nc, d, p) \u2190 prove_gcd_nat nc nx ny,\n      pure (zc, nc, d, `(int_gcd_helper).mk_app [x, y, nx, ny, d, px, py, p])\n    end\n  end\n\n/-- Evaluates the `int.lcm` function. -/\nmeta def prove_lcm_int (zc nc : instance_cache) : expr \u2192 expr \u2192\n  tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| x y := match match_neg x with\n  | some x := do\n    (zc, nc, d, p) \u2190 prove_lcm_int x y,\n    pure (zc, nc, d, `(int_lcm_helper_neg_left).mk_app [x, y, d, p])\n  | none := match match_neg y with\n    | some y := do\n      (zc, nc, d, p) \u2190 prove_lcm_int x y,\n      pure (zc, nc, d, `(int_lcm_helper_neg_right).mk_app [x, y, d, p])\n    | none := do\n      (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x,\n      (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y,\n      (nc, d, p) \u2190 prove_lcm_nat nc nx ny,\n      pure (zc, nc, d, `(int_lcm_helper).mk_app [x, y, nx, ny, d, px, py, p])\n    end\n  end\n\n/-- Evaluates the `nat.coprime` function. -/\nmeta def prove_coprime_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 (expr \u2295 expr)) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 1, _ := pure (c, sum.inl $ `(nat.coprime_one_left).mk_app [ey])\n  | _, 1 := pure (c, sum.inl $ `(nat.coprime_one_right).mk_app [ex])\n  | 0, 0 := pure (c, sum.inr `(nat.not_coprime_zero_zero))\n  | 0, _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, p) \u2190 prove_lt_nat c `(1) ey,\n    pure (c, sum.inr $ `(nat_coprime_helper_zero_left).mk_app [ey, p])\n  | _, 0 := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, p) \u2190 prove_lt_nat c `(1) ex,\n    pure (c, sum.inr $ `(nat_coprime_helper_zero_right).mk_app [ex, p])\n  | _, _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    let (d, a, b) := nat.xgcd_aux x 1 0 y 0 1,\n    if d = 1 then do\n      (c, ea) \u2190 c.of_nat a.nat_abs,\n      (c, eb) \u2190 c.of_nat b.nat_abs,\n      (c, etx, px) \u2190 prove_mul_nat c ex ea,\n      (c, ety, py) \u2190 prove_mul_nat c ey eb,\n      (c, p) \u2190 if a \u2265 0 then prove_add_nat c ety `(1) etx else prove_add_nat c etx `(1) ety,\n      let pf : expr := if a \u2265 0 then `(nat_coprime_helper_2) else `(nat_coprime_helper_1),\n      pure (c, sum.inl $ pf.mk_app [ex, ey, ea, eb, etx, ety, px, py, p])\n    else do\n      (c, ed) \u2190 c.of_nat d,\n      (c, eu) \u2190 c.of_nat (x / d),\n      (c, ev) \u2190 c.of_nat (y / d),\n      (c, _, pu) \u2190 prove_mul_nat c ed eu,\n      (c, _, pv) \u2190 prove_mul_nat c ed ev,\n      (c, p) \u2190 prove_lt_nat c `(1) ed,\n      pure (c, sum.inr $ `(nat_not_coprime_helper).mk_app [ed, ex, ey, eu, ev, pu, pv, p])\n  end\n\n/-- Evaluates the `gcd`, `lcm`, and `coprime` functions. -/\n@[norm_num] meta def eval_gcd : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.gcd %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prod.snd <$> prove_gcd_nat c ex ey\n| `(nat.lcm %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prod.snd <$> prove_lcm_nat c ex ey\n| `(nat.coprime %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prove_coprime_nat c ex ey >>= sum.elim true_intro false_intro \u2218 prod.snd\n| `(int.gcd %%ex %%ey) := do\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> prove_gcd_int zc nc ex ey\n| `(int.lcm %%ex %%ey) := do\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> prove_lcm_int zc nc ex ey\n| _ := failed\n\nend norm_num\nend tactic\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/int/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7428150223813565}}
{"text": "/-\nCopyright (c) 2020 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.analysis.calculus.local_extr\nimport Mathlib.topology.algebra.affine\nimport Mathlib.PostPort\n\nuniverses u_2 u_1 \n\nnamespace Mathlib\n\n/-!\n# Minima and maxima of convex functions\n\nWe show that if a function `f : E \u2192 \u03b2` is convex, then a local minimum is also\na global minimum, and likewise for concave functions.\n-/\n\n/--\nHelper lemma for the more general case: `is_min_on.of_is_local_min_on_of_convex_on`.\n-/\ntheorem is_min_on.of_is_local_min_on_of_convex_on_Icc {\u03b2 : Type u_2} [linear_ordered_add_comm_group \u03b2] [semimodule \u211d \u03b2] [ordered_semimodule \u211d \u03b2] {f : \u211d \u2192 \u03b2} {a : \u211d} {b : \u211d} (a_lt_b : a < b) (h_local_min : is_local_min_on f (set.Icc a b) a) (h_conv : convex_on (set.Icc a b) f) (x : \u211d) (H : x \u2208 set.Icc a b) : f a \u2264 f x := sorry\n\n/--\nA local minimum of a convex function is a global minimum, restricted to a set `s`.\n-/\ntheorem is_min_on.of_is_local_min_on_of_convex_on {E : Type u_1} {\u03b2 : Type u_2} [add_comm_group E] [topological_space E] [module \u211d E] [topological_add_group E] [topological_vector_space \u211d E] [linear_ordered_add_comm_group \u03b2] [semimodule \u211d \u03b2] [ordered_semimodule \u211d \u03b2] {s : set E} {f : E \u2192 \u03b2} {a : E} (a_in_s : a \u2208 s) (h_localmin : is_local_min_on f s a) (h_conv : convex_on s f) (x : E) (H : x \u2208 s) : f a \u2264 f x := sorry\n\n/-- A local maximum of a concave function is a global maximum, restricted to a set `s`. -/\ntheorem is_max_on.of_is_local_max_on_of_concave_on {E : Type u_1} {\u03b2 : Type u_2} [add_comm_group E] [topological_space E] [module \u211d E] [topological_add_group E] [topological_vector_space \u211d E] [linear_ordered_add_comm_group \u03b2] [semimodule \u211d \u03b2] [ordered_semimodule \u211d \u03b2] {s : set E} {f : E \u2192 \u03b2} {a : E} (a_in_s : a \u2208 s) (h_localmax : is_local_max_on f s a) (h_conc : concave_on s f) (x : E) (H : x \u2208 s) : f x \u2264 f a :=\n  is_min_on.of_is_local_min_on_of_convex_on a_in_s h_localmax h_conc\n\n/-- A local minimum of a convex function is a global minimum. -/\ntheorem is_min_on.of_is_local_min_of_convex_univ {E : Type u_1} {\u03b2 : Type u_2} [add_comm_group E] [topological_space E] [module \u211d E] [topological_add_group E] [topological_vector_space \u211d E] [linear_ordered_add_comm_group \u03b2] [semimodule \u211d \u03b2] [ordered_semimodule \u211d \u03b2] {f : E \u2192 \u03b2} {a : E} (h_local_min : is_local_min f a) (h_conv : convex_on set.univ f) (x : E) : f a \u2264 f x :=\n  is_min_on.of_is_local_min_on_of_convex_on (set.mem_univ a) (is_local_min.on h_local_min set.univ) h_conv x\n    (set.mem_univ x)\n\n/-- A local maximum of a concave function is a global maximum. -/\ntheorem is_max_on.of_is_local_max_of_convex_univ {E : Type u_1} {\u03b2 : Type u_2} [add_comm_group E] [topological_space E] [module \u211d E] [topological_add_group E] [topological_vector_space \u211d E] [linear_ordered_add_comm_group \u03b2] [semimodule \u211d \u03b2] [ordered_semimodule \u211d \u03b2] {f : E \u2192 \u03b2} {a : E} (h_local_max : is_local_max f a) (h_conc : concave_on set.univ f) (x : E) : f x \u2264 f a :=\n  is_min_on.of_is_local_min_of_convex_univ h_local_max h_conc\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/analysis/convex/extrema.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7428150183066299}}
{"text": "/-\n# Tutorial World \n\n## Level 3: the rewrite (`rw`) tactic (II).\n\nIn the previous level, we learned that `rw h` changes A's into B's when the goal contains one or more A's \nand we have the hypothesis `h : A = B` in the local context. You may be wondering if the opposite case is \nalso possible. That is to say: could we change B's into A's when the goal contains one or more B's and we have \nthe hypothesis `h : A = B` in the local context?\n\nSo the answer is... Yes! The hypotheses in this level are a bit different than before, \nso you should use **`rw \u2190`** instead. To do so, you can type the little left-arrow by typing **\\l** \nand then a space, so the system will change it automatically.\n\n## Did you know?\n\nOn the top right corner of the screen, there is a box named \"View source\" for each level. If you \nclick on it, you will see one possible solution to this level. Again, try to use this tool wisely! \n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nYou may want to use *`rw \u2190`* first. Use it only with one of the hypotheses. Then, think if it's necessary to use it again\nor you just can finish the proof by using `rw` without `\u2190`.\n-/\nvariables {\u03a9 : Type} -- hide\n\n/- Lemma : no-side-bar\nIf A, B and C are points with B = A and B = C, then A = C.\n-/\nlemma example_exact (A B C: \u03a9) (h1 : B = A) (h2 : B = C) : A = C :=\nbegin\n  rw \u2190 h1,\n  rw h2,\n\n  \nend\n\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/tutorial_world/level03_rwbis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.742815011975552}}
{"text": "/- Integers mod 37\n\n  A demonstration of how to use equivalence relations and equivalence classes in Lean.\n\n  We define the \"congruent mod 37\" relation on integers, prove it is an equivalence\n  relation, define Zmod37 to be the equivalence classes, and put a ring structure on\n  the quotient.\n\n-/\n-- this import is helpful for some intermediate calculation\nimport tactic.ring\n\n-- Definition of the equivalence relation\ndefinition cong_mod37 (a b : \u2124) : Prop := \u2203 (k : \u2124), k * 37 = b - a\n\n-- Now check it's an equivalence reln!\n\ntheorem cong_mod_refl : reflexive (cong_mod37) :=\nbegin\n  intro x,\n  -- to prove cong_mod37 x x we just observe that k = 0 will do.\n  use (0:\u2124), -- this is k\n  simp,\nend\n\ntheorem cong_mod_symm : symmetric (cong_mod37) :=\nbegin\n  intros a b H,\n  -- H : cond_mod37 a b\n  cases H with k Hk,\n  -- Hk : k * 37 = (b - a)\n  -- Goal is to find an integer k' with k' * 37 = a - b  \n  use -k,\n  simp [Hk],\nend\n\ntheorem cong_mod_trans : transitive (cong_mod37) :=\nbegin\n  intros a b c Hab Hbc,\n  cases Hab with k Hk,\n  cases Hbc with l Hl,\n  -- Hk : k*37 = b - a, and Hl : l*37 = c - b\n  -- Goal : m * 37 = c - a\n  use (k+l),\n  simp [add_mul,Hk,Hl],\nend\n\n-- so we've now seen a general technique for proving a \u2248 b -- use (the k that works)\n\ntheorem cong_mod_equiv : equivalence (cong_mod37) :=\n\u27e8cong_mod_refl,cong_mod_symm,cong_mod_trans\u27e9\n\ninstance Z_setoid : setoid \u2124 := { r := cong_mod37, iseqv := cong_mod_equiv }\n\ndefinition Zmod37 := quotient (Z_setoid)\n\nnamespace Zmod37\n\ndefinition reduce_mod37 : \u2124 \u2192 Zmod37 := quot.mk (cong_mod37)\n\n-- now a little bit of basic interface\n\n-- Natural map from \u2124 to \u2124mod37\ninstance coe_int_Zmod37 : has_coe \u2124 (Zmod37) := \u27e8reduce_mod37\u27e9\n\n-- Notation for 0 and 1\ninstance : has_zero (Zmod37) := \u27e8reduce_mod37 0\u27e9\ninstance : has_one (Zmod37) := \u27e8reduce_mod37 1\u27e9\n\n-- Add basic facts about 0 and 1 to the set of simp facts\n@[simp] theorem of_int_zero : (0 : (Zmod37))  = reduce_mod37 0 := rfl \n@[simp] theorem of_int_one : (1 : (Zmod37))  = reduce_mod37 1 := rfl \n\n-- now back to the maths\n\n-- here's a useful lemma -- it's needed to prove addition is well-defined on the quotient.\n-- Note the use of quotient.sound to get from Zmod37 back to Z\n\nlemma congr_add (a\u2081 a\u2082 b\u2081 b\u2082 : \u2124) : a\u2081 \u2248 b\u2081 \u2192 a\u2082 \u2248 b\u2082 \u2192 \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7 :=\nbegin\n  intros H1 H2,\n  cases H1 with m Hm, -- Hm : m * 37 = b\u2081 - a\u2081\n  cases H2 with n Hn, -- Hn : n * 37 = b\u2082 - a\u2082\n  -- goal is \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7\n  apply quotient.sound,\n  -- goal now a\u2081 + a\u2082 \u2248 b\u2081 + b\u2082, and we know how to do these.\n  use (m+n),\n  simp [add_mul,Hm,Hn]\nend \n\n-- That lemma above is *exactly* what we need to make sure addition is\n-- well-defined on Zmod37, so let's do this now, using quotient.lift \n\n-- note: stuff like \"add\" is used everywhere so it's best to protect.\nprotected definition add : Zmod37 \u2192 Zmod37 \u2192 Zmod37 :=\nquotient.lift\u2082 (\u03bb a b : \u2124, \u27e6a + b\u27e7) (begin\n  show \u2200 (a\u2081 a\u2082 b\u2081 b\u2082 : \u2124), a\u2081 \u2248 b\u2081 \u2192 a\u2082 \u2248 b\u2082 \u2192 \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7,\n  -- that's what quotient.lift\u2082 reduces us to doing. But we did it already!\n  exact congr_add,\nend)\n\n-- Now here's the lemma we need for the definition of neg\n\n-- I spelt out the proof for add, here's a quick term proof for neg.\n\nlemma congr_neg (a b : \u2124) : a \u2248 b \u2192 \u27e6-a\u27e7 = \u27e6-b\u27e7 :=\n\u03bb \u27e8m,Hm\u27e9,quotient.sound \u27e8-m,by simp [Hm]\u27e9\n\nprotected def neg : Zmod37 \u2192 Zmod37 := quotient.lift (\u03bb a : \u2124, \u27e6-a\u27e7) congr_neg\n\n-- For multiplication I won't even bother proving the lemma, I'll just let ring do it\n\nprotected def mul : Zmod37 \u2192 Zmod37 \u2192 Zmod37 :=\nquotient.lift\u2082 (\u03bb a b : \u2124, \u27e6a*b\u27e7) (\u03bb a\u2081 a\u2082 b\u2081 b\u2082 \u27e8m\u2081,H\u2081\u27e9 \u27e8m\u2082,H\u2082\u27e9,quotient.sound \u27e8b\u2081 * m\u2082 + a\u2082 * m\u2081,\n  by rw [add_mul,mul_assoc,mul_assoc,H\u2081,H\u2082];ring\u27e9)\n\n-- this adds notation to the quotient\n\ninstance : has_add (Zmod37) := \u27e8Zmod37.add\u27e9\ninstance : has_neg (Zmod37) := \u27e8Zmod37.neg\u27e9\ninstance : has_mul (Zmod37) := \u27e8Zmod37.mul\u27e9\n\n-- these are now very cool proofs:\n@[simp] lemma coe_add {a b : \u2124} : (\u2191(a + b) : Zmod37) = \u2191a + \u2191b := rfl\n@[simp] lemma coe_neg {a : \u2124} : (\u2191(-a) : Zmod37) = -\u2191a := rfl\n@[simp] lemma coe_mul {a b : \u2124} : (\u2191(a * b) : Zmod37) = \u2191a * \u2191b := rfl\n\n-- The proof of coe_add would not be rfl at all if you defined addition on the quotient\n-- by choosing representatives and then adding them. Note that choosing reps\n-- and adding them is exactly what mathematicians do; they shoot first and\n-- ask questions later.\n\n-- Now here's how to use quotient.induction_on and quotient.sound\n\ninstance : add_comm_group (Zmod37)  :=\n{ add_comm_group .\n  zero         := 0, -- because we already defined has_zero\n  add          := (+), -- could also have written has_add.add or Zmod37.add\n  neg          := has_neg.neg,\n  zero_add     := \n    \u03bb abar, quotient.induction_on abar (begin\n      -- goal is \u2200 (a : \u2124), 0 + \u27e6a\u27e7 = \u27e6a\u27e7 -- that's what quotient.induction_on does for us\n      intro a,\n      apply quotient.sound, -- works because 0 + \u27e6a\u27e7 is by definition \u27e60\u27e7 + \u27e6a\u27e7 which is by definition \u27e60 + a\u27e7\n      -- goal is now 0 + a \u2248 a\n      -- here's the way we used to do it.\n      use (0 : \u2124),\n      simp,\n      -- but there are tricks now, which I'll show you with add_zero and add_assoc.\n    end),\n  add_assoc    := \u03bb abar bbar cbar,quotient.induction_on\u2083 abar bbar cbar (\u03bb a b c,\n    begin\n      -- goal now \u27e6a\u27e7 + \u27e6b\u27e7 + \u27e6c\u27e7 = \u27e6a\u27e7 + (\u27e6b\u27e7 + \u27e6c\u27e7)\n      apply quotient.sound,\n      -- goal now a + b + c \u2248 a + (b + c)\n      rw add_assoc, -- done :-) because after a rw a goal is closed if it's of the form x \u2248 x, as \u2248 is\n                    -- known to be reflexive.\n    end),\n  add_zero     := -- I will intrroduce some more sneaky stuff now now\n                  -- add_zero for Zmod37 follows from add_zero on Z.\n                  -- Note use of $ instead of the brackets\n    \u03bb abar, quotient.induction_on abar $ \u03bb a, quotient.sound $ by rw add_zero,\n                  -- that's it! Term mode proof.\n  add_left_neg := -- super-slow method not even using quotient.induction_on \n    begin\n      intro abar,\n      cases (quot.exists_rep abar) with a Ha,\n      rw [\u2190Ha],\n      apply quot.sound,\n      use (0:\u2124),\n      simp,\n    end,\n  -- but really all proofs should just look something like this\n  add_comm     := \u03bb abar bbar, quotient.induction_on\u2082 abar bbar $ \u03bb _ _,quotient.sound $ by rw add_comm,\n  -- the noise at the beginning is just the machine; all the work is done by the rewrite\n}\n\n-- Now let's just nail this using all the tricks in the book. All ring axioms on the quotient\n-- follow from the corresponding axioms for Z.\ninstance : comm_ring (Zmod37) :=\n{ \n  mul := Zmod37.mul, -- could have written (*)\n  -- Now look how the proof of mul_assoc is just the same structure as add_comm above\n  -- but with three variables not two\n  mul_assoc := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb _ _ _, quotient.sound $ by rw mul_assoc,\n  one := 1,\n  one_mul := \u03bb a, quotient.induction_on a $ \u03bb _, quotient.sound $ by rw one_mul,\n  mul_one := \u03bb a, quotient.induction_on a $ \u03bb _, quotient.sound $ by rw mul_one,\n  left_distrib := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb _ _ _, quotient.sound $ by rw left_distrib,\n  right_distrib := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb _ _ _, quotient.sound $ by rw right_distrib,\n  mul_comm := \u03bb a b, quotient.induction_on\u2082 a b $ \u03bb _ _, quotient.sound $ by rw mul_comm,\n  ..Zmod37.add_comm_group\n}\n\nend Zmod37\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Examples/zmod37.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.742815005819664}}
{"text": "/-\nCopyright (c) 2022 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n\n! This file was ported from Lean 3 source module data.fin.tuple.monotone\n! leanprover-community/mathlib commit e3d9ab8faa9dea8f78155c6c27d62a621f4c152d\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fin.VecNotation\n\n/-!\n# Monotone finite sequences\n\nIn this file we prove `simp` lemmas that allow to simplify propositions like `Monotone ![a, b, c]`.\n-/\n\n\nopen Set Fin Matrix Function\n\nvariable {\u03b1 : Type _}\n\ntheorem lift_fun_vecCons {n : \u2115} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [IsTrans \u03b1 r] {f : Fin (n + 1) \u2192 \u03b1} {a : \u03b1} :\n    ((\u00b7 < \u00b7) \u21d2 r) (vecCons a f) (vecCons a f) \u2194 r a (f 0) \u2227 ((\u00b7 < \u00b7) \u21d2 r) f f := by\n  simp only [lift_fun_iff_succ r, forall_fin_succ, cons_val_succ, cons_val_zero, \u2190 succ_castSucc,\n    castSucc_zero]\n#align lift_fun_vec_cons lift_fun_vecCons\n\nvariable [Preorder \u03b1] {n : \u2115} {f : Fin (n + 1) \u2192 \u03b1} {a : \u03b1}\n\n@[simp]\ntheorem strictMono_vecCons : StrictMono (vecCons a f) \u2194 a < f 0 \u2227 StrictMono f :=\n  lift_fun_vecCons (\u00b7 < \u00b7)\n#align strict_mono_vec_cons strictMono_vecCons\n\n@[simp]\ntheorem monotone_vecCons : Monotone (vecCons a f) \u2194 a \u2264 f 0 \u2227 Monotone f := by\n  simpa only [monotone_iff_forall_lt] using @lift_fun_vecCons \u03b1 n (\u00b7 \u2264 \u00b7) _ f a\n#align monotone_vec_cons monotone_vecCons\n\n--Porting note: new lemma, in Lean3 would be proven by `Subsingleton.monotone`\n@[simp]\ntheorem monotone_vecEmpty : Monotone (vecCons a vecEmpty)\n  | \u27e80, _\u27e9, \u27e80, _\u27e9, _ => le_refl _\n\n--Porting note: new lemma, in Lean3 would be proven by `Subsingleton.strictMono`\n@[simp]\ntheorem strictMono_vecEmpty : StrictMono (vecCons a vecEmpty)\n  | \u27e80, _\u27e9, \u27e80, _\u27e9, h => (irrefl _ h).elim\n\n@[simp]\ntheorem strictAnti_vecCons : StrictAnti (vecCons a f) \u2194 f 0 < a \u2227 StrictAnti f :=\n  lift_fun_vecCons (\u00b7 > \u00b7)\n#align strict_anti_vec_cons strictAnti_vecCons\n\n@[simp]\ntheorem antitone_vecCons : Antitone (vecCons a f) \u2194 f 0 \u2264 a \u2227 Antitone f :=\n  @monotone_vecCons \u03b1\u1d52\u1d48 _ _ _ _\n#align antitone_vec_cons antitone_vecCons\n\n--Porting note: new lemma, in Lean3 would be proven by `Subsingleton.antitone`\n@[simp]\ntheorem antitone_vecEmpty : Antitone (vecCons a vecEmpty)\n  | \u27e80, _\u27e9, \u27e80, _\u27e9, _ => le_refl _\n\n--Porting note: new lemma, in Lean3 would be proven by `Subsingleton.strictAnti`\n@[simp]\ntheorem strictAnti_vecEmpty : StrictAnti (vecCons a vecEmpty)\n  | \u27e80, _\u27e9, \u27e80, _\u27e9, h => (irrefl _ h).elim\n\ntheorem StrictMono.vecCons (hf : StrictMono f) (ha : a < f 0) : StrictMono (vecCons a f) :=\n  strictMono_vecCons.2 \u27e8ha, hf\u27e9\n#align strict_mono.vec_cons StrictMono.vecCons\n\ntheorem StrictAnti.vecCons (hf : StrictAnti f) (ha : f 0 < a) : StrictAnti (vecCons a f) :=\n  strictAnti_vecCons.2 \u27e8ha, hf\u27e9\n#align strict_anti.vec_cons StrictAnti.vecCons\n\ntheorem Monotone.vecCons (hf : Monotone f) (ha : a \u2264 f 0) : Monotone (vecCons a f) :=\n  monotone_vecCons.2 \u27e8ha, hf\u27e9\n#align monotone.vec_cons Monotone.vecCons\n\ntheorem Antitone.vecCons (hf : Antitone f) (ha : f 0 \u2264 a) : Antitone (vecCons a f) :=\n  antitone_vecCons.2 \u27e8ha, hf\u27e9\n#align antitone.vec_cons Antitone.vecCons\n\nexample : Monotone ![1, 2, 2, 3] := by simp\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Fin/Tuple/Monotone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301018, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7428150058196639}}
{"text": "import data.finset\nimport data.real.basic\nimport algebra.group.basic\nimport algebra.order.floor\n\n#check finset.sum_range_induction\n\nsection commutators\n\nvariables {G H : Type*} [group G] [group H]\n\ndef \u03b3 (a b : G) : G := a * b * a\u207b\u00b9 * b\u207b\u00b9 \n\nlemma map_\u03b3 (f : monoid_hom G H) (a b : G) : f (\u03b3 a b) = \u03b3 (f a) (f b) := by {\n  dsimp[\u03b3], simp[f.map_mul, f.map_inv]\n}\n\nlemma cube_\u03b3 (a b : G) : (\u03b3 a b) ^ 3 = \n   (\u03b3 (a * b * a\u207b\u00b9) (b\u207b\u00b9 * a * b * (a\u207b\u00b9 ^ 2))) * (\u03b3 (b\u207b\u00b9 * a * b) (b ^ 2)) := \nbegin\n  dsimp[\u03b3], repeat { rw[pow_succ] }, repeat { rw[pow_zero] },\n  repeat { rw[mul_inv_rev] }, repeat { rw[inv_inv] }, repeat { rw[one_inv] },\n  repeat { rw[mul_one] }, repeat { rw[one_mul] },\n  repeat { rw[mul_assoc] },\n  simp,\nend\n\nend commutators\n\nlemma sandwich {c x : \u211d} (h : \u2200 n : \u2115+, (abs x) \u2264 c / n) : x = 0 := \nbegin\n  by_cases hc : c > 0,\n  { by_contra hx,\n    replace hx : abs x > 0 := abs_pos.mpr hx,\n    rcases (archimedean.arch (c + 1) hx) with \u27e8n,hn\u27e9,\n    cases n with n,\n    { rw[zero_smul] at hn, \n      exact lt_asymm (lt_of_lt_of_le (lt_add_one c) hn) hc },\n    rw[nsmul_eq_mul, mul_comm] at hn,\n    have np : (n.succ : \u211d) > 0 := nat.cast_pos.mpr n.succ_pos,\n    have h' : abs x \u2264 c / n.succ := h \u27e8n.succ, n.succ_pos\u27e9,\n    exact not_lt_of_ge (le_trans hn ((le_div_iff np).mp h')) (lt_add_one c)\n  },\n  { have h' := (h 1), \n    have : (1 : \u211d) = (1 : \u2115+) := by norm_num, rw[\u2190 this, div_one] at h',\n    exact abs_nonpos_iff.mp (le_trans h' (le_of_not_gt hc))\n  }\nend", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/exercises/loh/exercises_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684336, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7428150039136936}}
{"text": "/-\nCopyright (c) 2020 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n-/\nimport analysis.asymptotics.asymptotics\nimport analysis.normed.order.basic\n\n/-!\n# Asymptotic equivalence\n\nIn this file, we define the relation `is_equivalent l u v`, which means that `u-v` is little o of\n`v` along the filter `l`.\n\nUnlike `is_[oO]` relations, this one requires `u` and `v` to have the same codomain `\u03b2`. While the\ndefinition only requires `\u03b2` to be a `normed_add_comm_group`, most interesting properties require it\nto be a `normed_field`.\n\n## Notations\n\nWe introduce the notation `u ~[l] v := is_equivalent l u v`, which you can use by opening the\n`asymptotics` locale.\n\n## Main results\n\nIf `\u03b2` is a `normed_add_comm_group` :\n\n- `_ ~[l] _` is an equivalence relation\n- Equivalent statements for `u ~[l] const _ c` :\n  - If `c \u2260 0`, this is true iff `tendsto u l (\ud835\udcdd c)` (see `is_equivalent_const_iff_tendsto`)\n  - For `c = 0`, this is true iff `u =\u1da0[l] 0` (see `is_equivalent_zero_iff_eventually_zero`)\n\nIf `\u03b2` is a `normed_field` :\n\n- Alternative characterization of the relation (see `is_equivalent_iff_exists_eq_mul`) :\n\n  `u ~[l] v \u2194 \u2203 (\u03c6 : \u03b1 \u2192 \u03b2) (h\u03c6 : tendsto \u03c6 l (\ud835\udcdd 1)), u =\u1da0[l] \u03c6 * v`\n\n- Provided some non-vanishing hypothesis, this can be seen as `u ~[l] v \u2194 tendsto (u/v) l (\ud835\udcdd 1)`\n  (see `is_equivalent_iff_tendsto_one`)\n- For any constant `c`, `u ~[l] v` implies `tendsto u l (\ud835\udcdd c) \u2194 tendsto v l (\ud835\udcdd c)`\n  (see `is_equivalent.tendsto_nhds_iff`)\n- `*` and `/` are compatible with `_ ~[l] _` (see `is_equivalent.mul` and `is_equivalent.div`)\n\nIf `\u03b2` is a `normed_linear_ordered_field` :\n\n- If `u ~[l] v`, we have `tendsto u l at_top \u2194 tendsto v l at_top`\n  (see `is_equivalent.tendsto_at_top_iff`)\n\n## Implementation Notes\n\nNote that `is_equivalent` takes the parameters `(l : filter \u03b1) (u v : \u03b1 \u2192 \u03b2)` in that order.\nThis is to enable `calc` support, as `calc` requires that the last two explicit arguments are `u v`.\n\n-/\n\nnamespace asymptotics\n\nopen filter function\nopen_locale topology\n\nsection normed_add_comm_group\n\nvariables {\u03b1 \u03b2 : Type*} [normed_add_comm_group \u03b2]\n\n/-- Two functions `u` and `v` are said to be asymptotically equivalent along a filter `l` when\n    `u x - v x = o(v x)` as x converges along `l`. -/\ndef is_equivalent (l : filter \u03b1) (u v : \u03b1 \u2192 \u03b2) := (u - v) =o[l] v\n\nlocalized \"notation (name := asymptotics.is_equivalent)\n  u ` ~[`:50 l:50 `] `:0 v:50 := asymptotics.is_equivalent l u v\" in asymptotics\n\nvariables {u v w : \u03b1 \u2192 \u03b2} {l : filter \u03b1}\n\nlemma is_equivalent.is_o (h : u ~[l] v) : (u - v) =o[l] v := h\n\nlemma is_equivalent.is_O (h : u ~[l] v) : u =O[l] v :=\n(is_O.congr_of_sub h.is_O.symm).mp (is_O_refl _ _)\n\nlemma is_equivalent.is_O_symm (h : u ~[l] v) : v =O[l] u :=\nbegin\n  convert h.is_o.right_is_O_add,\n  ext,\n  simp\nend\n\n@[refl] lemma is_equivalent.refl : u ~[l] u :=\nbegin\n  rw [is_equivalent, sub_self],\n  exact is_o_zero _ _\nend\n\n@[symm] lemma is_equivalent.symm (h : u ~[l] v) : v ~[l] u :=\n(h.is_o.trans_is_O h.is_O_symm).symm\n\n@[trans] lemma is_equivalent.trans {l : filter \u03b1} {u v w : \u03b1 \u2192 \u03b2}\n  (huv : u ~[l] v) (hvw : v ~[l] w) : u ~[l] w :=\n(huv.is_o.trans_is_O hvw.is_O).triangle hvw.is_o\n\nlemma is_equivalent.congr_left {u v w : \u03b1 \u2192 \u03b2} {l : filter \u03b1} (huv : u ~[l] v)\n  (huw : u =\u1da0[l] w) : w ~[l] v :=\nhuv.congr' (huw.sub (eventually_eq.refl _ _)) (eventually_eq.refl _ _)\n\nlemma is_equivalent.congr_right {u v w : \u03b1 \u2192 \u03b2} {l : filter \u03b1} (huv : u ~[l] v)\n  (hvw : v =\u1da0[l] w) : u ~[l] w :=\n(huv.symm.congr_left hvw).symm\n\nlemma is_equivalent_zero_iff_eventually_zero : u ~[l] 0 \u2194 u =\u1da0[l] 0 :=\nbegin\n  rw [is_equivalent, sub_zero],\n  exact is_o_zero_right_iff\nend\n\nlemma is_equivalent_zero_iff_is_O_zero : u ~[l] 0 \u2194 u =O[l] (0 : \u03b1 \u2192 \u03b2) :=\nbegin\n  refine \u27e8is_equivalent.is_O, \u03bb h, _\u27e9,\n  rw [is_equivalent_zero_iff_eventually_zero, eventually_eq_iff_exists_mem],\n  exact \u27e8{x : \u03b1 | u x = 0}, is_O_zero_right_iff.mp h, \u03bb x hx, hx\u27e9,\nend\n\nlemma is_equivalent_const_iff_tendsto {c : \u03b2} (h : c \u2260 0) : u ~[l] const _ c \u2194 tendsto u l (\ud835\udcdd c) :=\nbegin\n  rw [is_equivalent, is_o_const_iff h],\n  split; intro h;\n  [ { have := h.sub tendsto_const_nhds, rw zero_sub (-c) at this },\n    { have := h.sub tendsto_const_nhds, rw \u2190 sub_self c} ];\n  convert this; try { ext }; simp\nend\n\nlemma is_equivalent.tendsto_const {c : \u03b2} (hu : u ~[l] const _ c) : tendsto u l (\ud835\udcdd c) :=\nbegin\n  rcases (em $ c = 0) with \u27e8rfl, h\u27e9,\n  { exact (tendsto_congr' $ is_equivalent_zero_iff_eventually_zero.mp hu).mpr tendsto_const_nhds },\n  { exact (is_equivalent_const_iff_tendsto h).mp hu }\nend\n\n\n\nlemma is_equivalent.tendsto_nhds_iff {c : \u03b2} (huv : u ~[l] v) :\n  tendsto u l (\ud835\udcdd c) \u2194 tendsto v l (\ud835\udcdd c) := \u27e8huv.tendsto_nhds, huv.symm.tendsto_nhds\u27e9\n\nlemma is_equivalent.add_is_o (huv : u ~[l] v) (hwv : w =o[l] v) : (u + w) ~[l] v :=\nby simpa only [is_equivalent, add_sub_right_comm] using huv.add hwv\n\nlemma is_equivalent.sub_is_o (huv : u ~[l] v) (hwv : w =o[l] v) : (u - w) ~[l] v :=\nby simpa only [sub_eq_add_neg] using huv.add_is_o hwv.neg_left\n\nlemma is_o.add_is_equivalent (hu : u =o[l] w) (hv : v ~[l] w) : (u + v) ~[l] w :=\nadd_comm v u \u25b8 hv.add_is_o hu\n\nlemma is_o.is_equivalent (huv : (u - v) =o[l] v) : u ~[l] v := huv\n\nlemma is_equivalent.neg (huv : u ~[l] v) : (\u03bb x, - u x) ~[l] (\u03bb x, - v x) :=\nbegin\n  rw is_equivalent,\n  convert huv.is_o.neg_left.neg_right,\n  ext,\n  simp,\nend\n\nend normed_add_comm_group\n\nopen_locale asymptotics\n\nsection normed_field\n\nvariables {\u03b1 \u03b2 : Type*} [normed_field \u03b2] {t u v w : \u03b1 \u2192 \u03b2} {l : filter \u03b1}\n\nlemma is_equivalent_iff_exists_eq_mul : u ~[l] v \u2194\n  \u2203 (\u03c6 : \u03b1 \u2192 \u03b2) (h\u03c6 : tendsto \u03c6 l (\ud835\udcdd 1)), u =\u1da0[l] \u03c6 * v :=\nbegin\n  rw [is_equivalent, is_o_iff_exists_eq_mul],\n  split; rintros \u27e8\u03c6, h\u03c6, h\u27e9; [use (\u03c6 + 1), use (\u03c6 - 1)]; split,\n  { conv in (\ud835\udcdd _) { rw \u2190 zero_add (1 : \u03b2) },\n    exact h\u03c6.add (tendsto_const_nhds) },\n  { convert h.add (eventually_eq.refl l v); ext; simp [add_mul] },\n  { conv in (\ud835\udcdd _) { rw \u2190 sub_self (1 : \u03b2) },\n    exact h\u03c6.sub (tendsto_const_nhds) },\n  { convert h.sub (eventually_eq.refl l v); ext; simp [sub_mul] }\nend\n\nlemma is_equivalent.exists_eq_mul (huv : u ~[l] v) :\n  \u2203 (\u03c6 : \u03b1 \u2192 \u03b2) (h\u03c6 : tendsto \u03c6 l (\ud835\udcdd 1)), u =\u1da0[l] \u03c6 * v :=\nis_equivalent_iff_exists_eq_mul.mp huv\n\nlemma is_equivalent_of_tendsto_one (hz : \u2200\u1da0 x in l, v x = 0 \u2192 u x = 0)\n  (huv : tendsto (u/v) l (\ud835\udcdd 1)) : u ~[l] v :=\nbegin\n  rw is_equivalent_iff_exists_eq_mul,\n  refine \u27e8u/v, huv, hz.mono $ \u03bb x hz', (div_mul_cancel_of_imp hz').symm\u27e9,\nend\n\nlemma is_equivalent_of_tendsto_one' (hz : \u2200 x, v x = 0 \u2192 u x = 0) (huv : tendsto (u/v) l (\ud835\udcdd 1)) :\n  u ~[l] v :=\nis_equivalent_of_tendsto_one (eventually_of_forall hz) huv\n\nlemma is_equivalent_iff_tendsto_one (hz : \u2200\u1da0 x in l, v x \u2260 0) :\n  u ~[l] v \u2194 tendsto (u/v) l (\ud835\udcdd 1) :=\nbegin\n  split,\n  { intro hequiv,\n    have := hequiv.is_o.tendsto_div_nhds_zero,\n    simp only [pi.sub_apply, sub_div] at this,\n    have key : tendsto (\u03bb x, v x / v x) l (\ud835\udcdd 1),\n    { exact (tendsto_congr' $ hz.mono $ \u03bb x hnz, @div_self _ _ (v x) hnz).mpr tendsto_const_nhds },\n    convert this.add key,\n    { ext, simp },\n    { norm_num } },\n  { exact is_equivalent_of_tendsto_one (hz.mono $ \u03bb x hnvz hz, (hnvz hz).elim) }\nend\n\nend normed_field\n\nsection smul\n\nlemma is_equivalent.smul {\u03b1 E \ud835\udd5c : Type*} [normed_field \ud835\udd5c] [normed_add_comm_group E]\n  [normed_space \ud835\udd5c E] {a b : \u03b1 \u2192 \ud835\udd5c} {u v : \u03b1 \u2192 E} {l : filter \u03b1} (hab : a ~[l] b) (huv : u ~[l] v) :\n  (\u03bb x, a x \u2022 u x) ~[l] (\u03bb x, b x \u2022 v x) :=\nbegin\n  rcases hab.exists_eq_mul with \u27e8\u03c6, h\u03c6, hab\u03c6\u27e9,\n  have : (\u03bb (x : \u03b1), a x \u2022 u x) - (\u03bb (x : \u03b1), b x \u2022 v x) =\u1da0[l] \u03bb x, b x \u2022 ((\u03c6 x \u2022 u x) - v x),\n  { convert (hab\u03c6.comp\u2082 (\u2022) $ eventually_eq.refl _ u).sub (eventually_eq.refl _ (\u03bb x, b x \u2022 v x)),\n    ext,\n    rw [pi.mul_apply, mul_comm, mul_smul, \u2190 smul_sub] },\n  refine (is_o_congr this.symm $ eventually_eq.rfl).mp ((is_O_refl b l).smul_is_o _),\n\n  rcases huv.is_O.exists_pos with \u27e8C, hC, hCuv\u27e9,\n  rw is_equivalent at *,\n  rw is_o_iff at *,\n  rw is_O_with at hCuv,\n  simp only [metric.tendsto_nhds, dist_eq_norm] at h\u03c6,\n  intros c hc,\n  specialize h\u03c6 ((c/2)/C) (div_pos (by linarith) hC),\n  specialize huv (show 0 < c/2, by linarith),\n  refine h\u03c6.mp (huv.mp $ hCuv.mono $ \u03bb x hCuvx huvx h\u03c6x, _),\n\n  have key :=\n    calc \u2016\u03c6 x - 1\u2016 * \u2016u x\u2016\n            \u2264 (c/2) / C * \u2016u x\u2016 : mul_le_mul_of_nonneg_right h\u03c6x.le (norm_nonneg $ u x)\n        ... \u2264 (c/2) / C * (C*\u2016v x\u2016) : mul_le_mul_of_nonneg_left hCuvx (div_pos (by linarith) hC).le\n        ... = c/2 * \u2016v x\u2016 : by {field_simp [hC.ne.symm], ring},\n\n  calc \u2016((\u03bb (x : \u03b1), \u03c6 x \u2022 u x) - v) x\u2016\n          = \u2016(\u03c6 x - 1) \u2022 u x + (u x - v x)\u2016 : by simp [sub_smul, sub_add]\n      ... \u2264 \u2016(\u03c6 x - 1) \u2022 u x\u2016 + \u2016u x - v x\u2016 : norm_add_le _ _\n      ... = \u2016\u03c6 x - 1\u2016 * \u2016u x\u2016 + \u2016u x - v x\u2016 : by rw norm_smul\n      ... \u2264 c / 2 * \u2016v x\u2016 + \u2016u x - v x\u2016 : add_le_add_right key _\n      ... \u2264 c / 2 * \u2016v x\u2016 + c / 2 * \u2016v x\u2016 : add_le_add_left huvx _\n      ... = c * \u2016v x\u2016 : by ring,\nend\n\nend smul\n\nsection mul_inv\n\nvariables {\u03b1 \u03b2 : Type*} [normed_field \u03b2] {t u v w : \u03b1 \u2192 \u03b2} {l : filter \u03b1}\n\nlemma is_equivalent.mul (htu : t ~[l] u) (hvw : v ~[l] w) : t * v ~[l] u * w :=\nhtu.smul hvw\n\nlemma is_equivalent.inv (huv : u ~[l] v) : (\u03bb x, (u x)\u207b\u00b9) ~[l] (\u03bb x, (v x)\u207b\u00b9) :=\nbegin\n  rw is_equivalent_iff_exists_eq_mul at *,\n  rcases huv with \u27e8\u03c6, h\u03c6, h\u27e9,\n  rw \u2190 inv_one,\n  refine \u27e8\u03bb x, (\u03c6 x)\u207b\u00b9, tendsto.inv\u2080 h\u03c6 (by norm_num) , _\u27e9,\n  convert h.inv,\n  ext,\n  simp [mul_inv]\nend\n\nlemma is_equivalent.div (htu : t ~[l] u) (hvw : v ~[l] w) :\n  (\u03bb x, t x / v x) ~[l] (\u03bb x, u x / w x) :=\nby simpa only [div_eq_mul_inv] using htu.mul hvw.inv\n\nend mul_inv\n\nsection normed_linear_ordered_field\n\nvariables {\u03b1 \u03b2 : Type*} [normed_linear_ordered_field \u03b2] {u v : \u03b1 \u2192 \u03b2} {l : filter \u03b1}\n\nlemma is_equivalent.tendsto_at_top [order_topology \u03b2] (huv : u ~[l] v) (hu : tendsto u l at_top) :\n  tendsto v l at_top :=\nlet \u27e8\u03c6, h\u03c6, h\u27e9 := huv.symm.exists_eq_mul in\ntendsto.congr' h.symm ((mul_comm u \u03c6) \u25b8 (hu.at_top_mul zero_lt_one h\u03c6))\n\nlemma is_equivalent.tendsto_at_top_iff [order_topology \u03b2] (huv : u ~[l] v) :\n  tendsto u l at_top \u2194 tendsto v l at_top := \u27e8huv.tendsto_at_top, huv.symm.tendsto_at_top\u27e9\n\nlemma is_equivalent.tendsto_at_bot [order_topology \u03b2] (huv : u ~[l] v) (hu : tendsto u l at_bot) :\n  tendsto v l at_bot :=\nbegin\n  convert tendsto_neg_at_top_at_bot.comp\n    (huv.neg.tendsto_at_top $ tendsto_neg_at_bot_at_top.comp hu),\n  ext,\n  simp\nend\n\nlemma is_equivalent.tendsto_at_bot_iff [order_topology \u03b2] (huv : u ~[l] v) :\n  tendsto u l at_bot \u2194 tendsto v l at_bot := \u27e8huv.tendsto_at_bot, huv.symm.tendsto_at_bot\u27e9\n\nend normed_linear_ordered_field\n\nend asymptotics\n\nopen filter asymptotics\nopen_locale asymptotics\n\nvariables {\u03b1 \u03b2 : Type*} [normed_add_comm_group \u03b2]\n\nlemma filter.eventually_eq.is_equivalent {u v : \u03b1 \u2192 \u03b2} {l : filter \u03b1} (h : u =\u1da0[l] v) : u ~[l] v :=\nis_equivalent.congr_right (is_o_refl_left _ _) h\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/asymptotics/asymptotic_equivalent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7427299123374079}}
{"text": "import GMLAlgebra.Basic\nimport GMLAlgebra.Group\n\nnamespace Algebra\nvariable {\u03b1} (s : SemiringSig \u03b1)\n\nlocal infixr:70 \" \u22c6 \" => s.mul\nlocal infixr:65 \" \u22b9 \" => s.add\n\nclass Semiring : Prop where\n  protected add_assoc (x y z) : (x \u22b9 y) \u22b9 z = x \u22b9 (y \u22b9 z)\n  protected add_comm (x y) : x \u22b9 y = y \u22b9 x\n  protected mul_assoc (x y z) : (x \u22c6 y) \u22c6 z = x \u22c6 (y \u22c6 z)\n  protected mul_left_distrib (x y z) : x \u22c6 (y \u22b9 z) = x \u22c6 y \u22b9 x \u22c6 z\n  protected mul_right_distrib (x y z) : (x \u22b9 y) \u22c6 z = x \u22c6 z \u22b9 y \u22c6 z\n\nprotected def Semiring.infer [OpAssoc s.add] [OpComm s.add] [OpAssoc s.mul] [OpLeftDistrib s.mul s.add] [OpRightDistrib s.mul s.add] : Semiring s where\n  add_assoc := op_assoc _\n  add_comm := op_comm _\n  mul_assoc := op_assoc _\n  mul_left_distrib := op_left_distrib _\n  mul_right_distrib := op_right_distrib _\n\nnamespace Semiring\nvariable {s} [self : Semiring s]\n\nlocal instance : OpAssoc (no_index s.add) := \u27e8Semiring.add_assoc\u27e9\nlocal instance : OpComm (no_index s.add) := \u27e8Semiring.add_comm\u27e9\nlocal instance : OpAssoc (no_index s.mul) := \u27e8Semiring.mul_assoc\u27e9\ninstance : OpLeftDistrib (no_index s.mul) (no_index s.add) := \u27e8Semiring.mul_left_distrib\u27e9\ninstance : OpRightDistrib (no_index s.mul) (no_index s.add) := \u27e8Semiring.mul_right_distrib\u27e9\n\ninstance toAddCommSemigroup : CommSemigroup (no_index s.toAddSemigroupSig) := CommSemigroup.infer _\n\ninstance toMulSemigroup : Semigroup (no_index s.toMulSemigroupSig) := Semigroup.infer _\n\nend Semiring\n\nclass CommSemiring : Prop where\n  protected add_assoc (x y z) : (x \u22b9 y) \u22b9 z = x \u22b9 (y \u22b9 z)\n  protected add_comm (x y) : x \u22b9 y = y \u22b9 x\n  protected mul_assoc (x y z) : (x \u22c6 y) \u22c6 z = x \u22c6 (y \u22c6 z)\n  protected mul_comm (x y) : x \u22c6 y = y \u22c6 x\n  protected mul_right_distrib (x y z) : (x \u22b9 y) \u22c6 z = x \u22c6 z \u22b9 y \u22c6 z\n\nprotected def CommSemiring.infer [OpAssoc s.add] [OpComm s.add] [OpAssoc s.mul] [OpComm s.mul] [OpRightDistrib s.mul s.add] : CommSemiring s where\n  add_assoc := op_assoc _\n  add_comm := op_comm _\n  mul_assoc := op_assoc _\n  mul_comm := op_comm _\n  mul_right_distrib := op_right_distrib _\n\nnamespace CommSemiring\nvariable {s} [self : CommSemiring s]\n\nlocal instance : OpAssoc (no_index s.add) := \u27e8CommSemiring.add_assoc\u27e9\nlocal instance : OpComm (no_index s.add) := \u27e8CommSemiring.add_comm\u27e9\nlocal instance : OpAssoc (no_index s.mul) := \u27e8CommSemiring.mul_assoc\u27e9\nlocal instance : OpComm (no_index s.mul) := \u27e8CommSemiring.mul_comm\u27e9\nlocal instance : OpRightDistrib (no_index s.mul) (no_index s.add) := \u27e8CommSemiring.mul_right_distrib\u27e9\n\nprotected theorem mul_left_distrib (x y z) : x \u22c6 (y \u22b9 z) = x \u22c6 y \u22b9 x \u22c6 z := calc\n  _ = (y \u22b9 z) \u22c6 x := by rw [op_comm (.\u22c6.) x (y \u22b9 z)]\n  _ = y \u22c6 x \u22b9 z \u22c6 x := by rw [op_right_distrib (.\u22c6.) y z x]\n  _ = x \u22c6 y \u22b9 z \u22c6 x := by rw [op_comm (.\u22c6.) x y]\n  _ = x \u22c6 y \u22b9 x \u22c6 z := by rw [op_comm (.\u22c6.) x z]\nlocal instance : OpLeftDistrib (no_index s.mul) (no_index s.add) := \u27e8CommSemiring.mul_left_distrib\u27e9\n\ninstance toSemiring : Semiring s := Semiring.infer s\n\ninstance toMulCommSemigroup : CommSemigroup (no_index s.toMulSemigroupSig) := CommSemigroup.infer _\n\nend CommSemiring\n", "meta": {"author": "fgdorais", "repo": "GMLAlgebra", "sha": "12ec5a9a4a95db6c2465353415be28413ce36501", "save_path": "github-repos/lean/fgdorais-GMLAlgebra", "path": "github-repos/lean/fgdorais-GMLAlgebra/GMLAlgebra-12ec5a9a4a95db6c2465353415be28413ce36501/GMLAlgebra/Semiring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7427299002761831}}
{"text": "import tactic\n\nopen_locale classical\n\n-- BEGIN\nexample (P Q : Prop) : (P \u2192 Q) \u2194 \u00ac P \u2228 Q :=\nbegin\nsplit,\n  intro hpq,\n    by_contra h',\n    push_neg at h',\n    cases h' with h'p h'nq,\n    apply h'nq (hpq (h'p)),\n  intros hnpq hp,\n    cases hnpq with hnp hq,\n    contradiction,\n    exact hq,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/5_split/5.2_iff/ex2_split_not_p_or_q.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218262741298, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.7427298968196505}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n\n! This file was ported from Lean 3 source module analysis.special_functions.complex.circle\n! leanprover-community/mathlib commit f333194f5ecd1482191452c5ea60b37d4d6afa08\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Complex.Circle\nimport Mathbin.Analysis.SpecialFunctions.Complex.Log\n\n/-!\n# Maps on the unit circle\n\nIn this file we prove some basic lemmas about `exp_map_circle` and the restriction of `complex.arg`\nto the unit circle. These two maps define a local equivalence between `circle` and `\u211d`, see\n`circle.arg_local_equiv` and `circle.arg_equiv`, that sends the whole circle to `(-\u03c0, \u03c0]`.\n-/\n\n\nopen Complex Function Set\n\nopen Real\n\nnamespace circle\n\ntheorem injective_arg : Injective fun z : circle => arg z := fun z w h =>\n  Subtype.ext <| ext_abs_arg ((abs_coe_circle z).trans (abs_coe_circle w).symm) h\n#align circle.injective_arg circle.injective_arg\n\n@[simp]\ntheorem arg_eq_arg {z w : circle} : arg z = arg w \u2194 z = w :=\n  injective_arg.eq_iff\n#align circle.arg_eq_arg circle.arg_eq_arg\n\nend circle\n\ntheorem arg_expMapCircle {x : \u211d} (h\u2081 : -\u03c0 < x) (h\u2082 : x \u2264 \u03c0) : arg (expMapCircle x) = x := by\n  rw [expMapCircle_apply, exp_mul_I, arg_cos_add_sin_mul_I \u27e8h\u2081, h\u2082\u27e9]\n#align arg_exp_map_circle arg_expMapCircle\n\n@[simp]\ntheorem expMapCircle_arg (z : circle) : expMapCircle (arg z) = z :=\n  circle.injective_arg <| arg_expMapCircle (neg_pi_lt_arg _) (arg_le_pi _)\n#align exp_map_circle_arg expMapCircle_arg\n\nnamespace circle\n\n/-- `complex.arg \u2218 coe` and `exp_map_circle` define a local equivalence between `circle and `\u211d` with\n`source = set.univ` and `target = set.Ioc (-\u03c0) \u03c0`. -/\n@[simps (config := { fullyApplied := false })]\nnoncomputable def argLocalEquiv : LocalEquiv circle \u211d\n    where\n  toFun := arg \u2218 coe\n  invFun := expMapCircle\n  source := univ\n  target := Ioc (-\u03c0) \u03c0\n  map_source' z _ := \u27e8neg_pi_lt_arg _, arg_le_pi _\u27e9\n  map_target' := mapsTo_univ _ _\n  left_inv' z _ := expMapCircle_arg z\n  right_inv' x hx := arg_expMapCircle hx.1 hx.2\n#align circle.arg_local_equiv circle.argLocalEquiv\n\n/-- `complex.arg` and `exp_map_circle` define an equivalence between `circle and `(-\u03c0, \u03c0]`. -/\n@[simps (config := { fullyApplied := false })]\nnoncomputable def argEquiv : circle \u2243 Ioc (-\u03c0) \u03c0\n    where\n  toFun z := \u27e8arg z, neg_pi_lt_arg _, arg_le_pi _\u27e9\n  invFun := expMapCircle \u2218 coe\n  left_inv z := argLocalEquiv.left_inv trivial\n  right_inv x := Subtype.ext <| argLocalEquiv.right_inv x.2\n#align circle.arg_equiv circle.argEquiv\n\nend circle\n\ntheorem leftInverse_expMapCircle_arg : LeftInverse expMapCircle (arg \u2218 coe) :=\n  expMapCircle_arg\n#align left_inverse_exp_map_circle_arg leftInverse_expMapCircle_arg\n\ntheorem invOn_arg_expMapCircle : InvOn (arg \u2218 coe) expMapCircle (Ioc (-\u03c0) \u03c0) univ :=\n  circle.argLocalEquiv.symm.InvOn\n#align inv_on_arg_exp_map_circle invOn_arg_expMapCircle\n\ntheorem surjOn_expMapCircle_neg_pi_pi : SurjOn expMapCircle (Ioc (-\u03c0) \u03c0) univ :=\n  circle.argLocalEquiv.symm.SurjOn\n#align surj_on_exp_map_circle_neg_pi_pi surjOn_expMapCircle_neg_pi_pi\n\ntheorem expMapCircle_eq_expMapCircle {x y : \u211d} :\n    expMapCircle x = expMapCircle y \u2194 \u2203 m : \u2124, x = y + m * (2 * \u03c0) :=\n  by\n  rw [Subtype.ext_iff, expMapCircle_apply, expMapCircle_apply, exp_eq_exp_iff_exists_int]\n  refine' exists_congr fun n => _\n  rw [\u2190 mul_assoc, \u2190 add_mul, mul_left_inj' I_ne_zero, \u2190 of_real_one, \u2190 of_real_bit0, \u2190 of_real_mul,\n    \u2190 of_real_int_cast, \u2190 of_real_mul, \u2190 of_real_add, of_real_inj]\n#align exp_map_circle_eq_exp_map_circle expMapCircle_eq_expMapCircle\n\ntheorem periodic_expMapCircle : Periodic expMapCircle (2 * \u03c0) := fun z =>\n  expMapCircle_eq_expMapCircle.2 \u27e81, by rw [Int.cast_one, one_mul]\u27e9\n#align periodic_exp_map_circle periodic_expMapCircle\n\n@[simp]\ntheorem expMapCircle_two_pi : expMapCircle (2 * \u03c0) = 1 :=\n  periodic_expMapCircle.Eq.trans expMapCircle_zero\n#align exp_map_circle_two_pi expMapCircle_two_pi\n\ntheorem expMapCircle_sub_two_pi (x : \u211d) : expMapCircle (x - 2 * \u03c0) = expMapCircle x :=\n  periodic_expMapCircle.sub_eq x\n#align exp_map_circle_sub_two_pi expMapCircle_sub_two_pi\n\ntheorem expMapCircle_add_two_pi (x : \u211d) : expMapCircle (x + 2 * \u03c0) = expMapCircle x :=\n  periodic_expMapCircle x\n#align exp_map_circle_add_two_pi expMapCircle_add_two_pi\n\n/-- `exp_map_circle`, applied to a `real.angle`. -/\nnoncomputable def Real.Angle.expMapCircle (\u03b8 : Real.Angle) : circle :=\n  periodic_expMapCircle.lift \u03b8\n#align real.angle.exp_map_circle Real.Angle.expMapCircle\n\n@[simp]\ntheorem Real.Angle.expMapCircle_coe (x : \u211d) : Real.Angle.expMapCircle x = expMapCircle x :=\n  rfl\n#align real.angle.exp_map_circle_coe Real.Angle.expMapCircle_coe\n\ntheorem Real.Angle.coe_expMapCircle (\u03b8 : Real.Angle) : (\u03b8.expMapCircle : \u2102) = \u03b8.cos + \u03b8.sin * I :=\n  by\n  induction \u03b8 using Real.Angle.induction_on\n  simp [Complex.exp_mul_I]\n#align real.angle.coe_exp_map_circle Real.Angle.coe_expMapCircle\n\n@[simp]\ntheorem Real.Angle.expMapCircle_zero : Real.Angle.expMapCircle 0 = 1 := by\n  rw [\u2190 Real.Angle.coe_zero, Real.Angle.expMapCircle_coe, expMapCircle_zero]\n#align real.angle.exp_map_circle_zero Real.Angle.expMapCircle_zero\n\n@[simp]\ntheorem Real.Angle.expMapCircle_neg (\u03b8 : Real.Angle) :\n    Real.Angle.expMapCircle (-\u03b8) = (Real.Angle.expMapCircle \u03b8)\u207b\u00b9 :=\n  by\n  induction \u03b8 using Real.Angle.induction_on\n  simp_rw [\u2190 Real.Angle.coe_neg, Real.Angle.expMapCircle_coe, expMapCircle_neg]\n#align real.angle.exp_map_circle_neg Real.Angle.expMapCircle_neg\n\n@[simp]\ntheorem Real.Angle.expMapCircle_add (\u03b8\u2081 \u03b8\u2082 : Real.Angle) :\n    Real.Angle.expMapCircle (\u03b8\u2081 + \u03b8\u2082) = Real.Angle.expMapCircle \u03b8\u2081 * Real.Angle.expMapCircle \u03b8\u2082 :=\n  by\n  induction \u03b8\u2081 using Real.Angle.induction_on\n  induction \u03b8\u2082 using Real.Angle.induction_on\n  exact expMapCircle_add \u03b8\u2081 \u03b8\u2082\n#align real.angle.exp_map_circle_add Real.Angle.expMapCircle_add\n\n@[simp]\ntheorem Real.Angle.arg_expMapCircle (\u03b8 : Real.Angle) :\n    (arg (Real.Angle.expMapCircle \u03b8) : Real.Angle) = \u03b8 :=\n  by\n  induction \u03b8 using Real.Angle.induction_on\n  rw [Real.Angle.expMapCircle_coe, expMapCircle_apply, exp_mul_I, \u2190 of_real_cos, \u2190 of_real_sin, \u2190\n    Real.Angle.cos_coe, \u2190 Real.Angle.sin_coe, arg_cos_add_sin_mul_I_coe_angle]\n#align real.angle.arg_exp_map_circle Real.Angle.arg_expMapCircle\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/SpecialFunctions/Complex/Circle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7426977927615679}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport field_theory.finite.basic\n\n/-!\n# IMO 2005 Q4\n\nProblem: Determine all positive integers relatively prime to all the terms of the infinite sequence\n`a n = 2 ^ n + 3 ^ n + 6 ^ n - 1`, for `n \u2265 1`.\n\nThis is quite an easy problem, in which the key point is a modular arithmetic calculation with\nthe sequence `a n` relative to an arbitrary prime.\n-/\n\n/-- The sequence considered in the problem, `2 ^ n + 3 ^ n + 6 ^ n - 1`. -/\ndef a (n : \u2115) : \u2124 := 2 ^ n + 3 ^ n + 6 ^ n - 1\n\n/-- Key lemma (a modular arithmetic calculation):  Given a prime `p` other than `2` or `3`, the\n`p - 2`th term of the sequence has `p` as a factor. -/\nlemma find_specified_factor {p : \u2115} (hp : nat.prime p) (hp' : is_coprime (6:\u2124) p) :\n  \u2191p \u2223 a (p - 2) :=\nbegin\n  rw [\u2190 int.modeq_zero_iff_dvd],\n  -- Since `p` and `6` are coprime, `6` has an inverse mod `p`\n  obtain \u27e8b, hb\u27e9 : \u2203 (b : \u2124), 6 * b \u2261 1 [ZMOD p],\n  { refine int.mod_coprime _,\n    exact nat.is_coprime_iff_coprime.mp hp' },\n  -- Also since `p` is coprime to `6`, it's coprime to `2` and `3`\n  have hp\u2082 : is_coprime (2:\u2124) p := (id hp' : is_coprime (3 * 2 : \u2124) p).of_mul_left_right,\n  have hp\u2083 : is_coprime (3:\u2124) p := (id hp' : is_coprime (2 * 3 : \u2124) p).of_mul_left_right,\n  -- Slightly painful nat-subtraction calculation\n  have hp_sub_one : p - 1 = (p - 2) + 1,\n  { have : 1 \u2264 p - 1 := le_tsub_of_add_le_right hp.two_le,\n    conv_lhs { rw \u2190 nat.sub_add_cancel this },\n    refl },\n  -- Main calculation: `6 * a (p - 2)` is a multiple of `p`\n  have H : (6:\u2124) * a (p - 2) \u2261 0 [ZMOD p],\n  calc (6:\u2124) * a (p - 2)\n      = 3 * 2 ^ (p - 1) + 2 * 3 ^ (p - 1) + 6 ^ (p - 1) - 6 :\n  by { simp only [a, mul_add, mul_sub, hp_sub_one, pow_succ], ring, }\n  ... \u2261 3 * 1 + 2 * 1 + 1 - 6 [ZMOD p] : -- At this step we use Fermat's little theorem\n  by { apply_rules [int.modeq.sub_right, int.modeq.add, int.modeq.mul_left,\n    int.modeq.pow_card_sub_one_eq_one hp] }\n  ... = 0 : by norm_num,\n  -- Since `6` has an inverse mod `p`, `a (p - 2)` itself is a multiple of `p`\n  calc (a (p - 2) : \u2124) = 1 * a (p - 2) : by ring\n  ... \u2261 (6 * b) * a (p - 2) [ZMOD p] : int.modeq.mul_right _ hb.symm\n  ... = b * (6 * a (p - 2)) : by ring\n  ... \u2261 b * 0 [ZMOD p] : int.modeq.mul_left _ H\n  ... = 0 : by ring,\nend\n\n/-- Main statement:  The only positive integer coprime to all terms of the sequence `a` is `1`. -/\nexample {k : \u2115} (hk : 0 < k) : (\u2200 n : \u2115, 1 \u2264 n \u2192 is_coprime (a n) k) \u2194 k = 1 :=\nbegin\n  split, rotate,\n  { -- The property is clearly true for `k = 1`\n    rintros rfl n hn,\n    exact is_coprime_one_right },\n  intros h,\n  -- Conversely, suppose `k` is a number with the property, and let `p` be `k.min_fac` (by\n  -- definition this is the minimal prime factor of `k` if `k \u2260 1`, and otherwise `1`.\n  let p := k.min_fac,\n  -- Testing the special property of `k` for `48`, the second term of the sequence, we see that `p`\n  -- is coprime to `6`.\n  have hp\u2086 : is_coprime (6:\u2124) p,\n  { refine is_coprime.of_coprime_of_dvd_right _ (int.coe_nat_dvd.mpr k.min_fac_dvd),\n    exact (id (h 2 one_le_two) : is_coprime (8 * 6 : \u2124) k).of_mul_left_right, },\n  -- In particular `p` is coprime to `2` (we record the `nat.coprime` version since that's what's\n  -- needed later).\n  have hp\u2082 : nat.coprime 2 p,\n  { rw \u2190 nat.is_coprime_iff_coprime,\n    exact (id hp\u2086 : is_coprime (3 * 2 : \u2124) p).of_mul_left_right },\n  -- Suppose for the sake of contradiction that `k \u2260 1`.  Then `p` is genuinely a prime factor of\n  -- `k`.\n  by_contra hk',\n  have hp : nat.prime p := nat.min_fac_prime hk',\n  -- So `3 \u2264 p`\n  have hp\u2083 : 3 \u2264 p,\n  { have : 2 \u2260 p := by rwa nat.coprime_primes nat.prime_two hp at hp\u2082,\n    apply nat.lt_of_le_and_ne hp.two_le this, },\n  -- Testing the special property of `k` for the `p - 2`th term of the sequence, we see that `p` is\n  -- coprime to `a (p - 2)`.\n  have : is_coprime \u2191p (a (p - 2)),\n  { refine ((h (p - 2) _).of_coprime_of_dvd_right (int.coe_nat_dvd.mpr k.min_fac_dvd)).symm,\n    exact le_tsub_of_add_le_right hp\u2083 },\n  rw (nat.prime_iff_prime_int.mp hp).coprime_iff_not_dvd at this,\n  -- But also, by our previous lemma, `p` divides `a (p - 2)`.\n  have : \u2191p \u2223 a (p - 2) := find_specified_factor hp hp\u2086,\n  -- Contradiction!\n  contradiction,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2005_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7426977749240635}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies, Junyan Xu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Junyan Xu\n-/\nimport data.prod.lex\nimport set_theory.ordinal.arithmetic\n\n/-!\n# Extend a well-founded order to a well-order\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file constructs a well-order (linear well-founded order) which is an extension of a given\nwell-founded order.\n\n## Proof idea\n\nWe can map our order into two well-orders:\n* the first map respects the order but isn't necessarily injective. Namely, this is the *rank*\n  function `rank : \u03b1 \u2192 ordinal`.\n* the second map is injective but doesn't necessarily respect the order. This is an arbitrary\n  well-order on `\u03b1`.\n\nThen their lexicographic product is a well-founded linear order which our original order injects in.\n-/\n\nuniverse u\n\nvariables {\u03b1 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nnamespace well_founded\nvariable (hwf : well_founded r)\ninclude hwf\n\n/-- An arbitrary well order on `\u03b1` that extends `r`.\n\nThe construction maps `r` into two well-orders: the first map is `well_founded.rank`, which is not\nnecessarily injective but respects the order `r`; the other map is the identity (with an arbitrarily\nchosen well-order on `\u03b1`), which is injective but doesn't respect `r`.\n\nBy taking the lexicographic product of the two, we get both properties, so we can pull it back and\nget an well-order that extend our original order `r`. Another way to view this is that we choose an\narbitrary well-order to serve as a tiebreak between two elements of same rank.\n-/\nnoncomputable def well_order_extension : linear_order \u03b1 :=\nlet l : linear_order \u03b1 := is_well_order.linear_order well_ordering_rel in by exactI\n  @linear_order.lift' \u03b1 (ordinal \u00d7\u2097 \u03b1) _\n    (\u03bb a : \u03b1, (well_founded.rank.{u} hwf a, a)) (\u03bb _ _, congr_arg prod.snd)\n\ninstance well_order_extension.is_well_founded_lt : is_well_founded \u03b1 hwf.well_order_extension.lt :=\n\u27e8inv_image.wf _ $ prod.lex_wf ordinal.well_founded_lt.wf well_ordering_rel.is_well_order.wf\u27e9\n\n/-- Any well-founded relation can be extended to a well-ordering on that type. -/\nlemma exists_well_order_ge : \u2203 s, r \u2264 s \u2227 is_well_order \u03b1 s :=\n\u27e8hwf.well_order_extension.lt, \u03bb a b h, prod.lex.left _ _ (hwf.rank_lt_of_rel h), by split\u27e9\n\nend well_founded\n\n/-- A type alias for `\u03b1`, intended to extend a well-founded order on `\u03b1` to a well-order. -/\ndef well_order_extension (\u03b1) : Type* := \u03b1\n\ninstance [inhabited \u03b1] : inhabited (well_order_extension \u03b1) := \u2039inhabited (well_order_extension \u03b1)\u203a\n\n/-- \"Identity\" equivalence between a well-founded order and its well-order extension. -/\ndef to_well_order_extension : \u03b1 \u2243 well_order_extension \u03b1 := equiv.refl _\n\nnoncomputable instance [has_lt \u03b1] [well_founded_lt \u03b1] : linear_order (well_order_extension \u03b1) :=\n(is_well_founded.wf : @well_founded \u03b1 (<)).well_order_extension\n\ninstance well_order_extension.well_founded_lt [has_lt \u03b1] [well_founded_lt \u03b1] :\n  well_founded_lt (well_order_extension \u03b1) :=\nwell_founded.well_order_extension.is_well_founded_lt _\n\nlemma to_well_order_extension_strict_mono [preorder \u03b1] [well_founded_lt \u03b1] :\n  strict_mono (to_well_order_extension : \u03b1 \u2192 well_order_extension \u03b1) :=\n\u03bb a b h, prod.lex.left _ _ $ well_founded.rank_lt_of_rel _ h\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/extension/well.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7426917880081613}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 / 2), from\n    by {rw [add_mul,add_mul,add_mul], rw \u2190 add_assoc, rw mul_assoc, rw mul_comm _ 3, ring, },\n  have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 / (2 * (a + b + c))), from\n    by {rw mul_assoc, rw div_mul_cancel, rw add_left_cancel, rw add_left_cancel, rw add_left_cancel, rw mul_comm _ 2, ring,},\n  have h3 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from\n    by {rw [div_mul,div_mul,div_mul], rw mul_comm _ 3, rw mul_assoc, rw div_mul_cancel, rw add_left_cancel, rw mul_comm _ 2, ring,},\n  have h4 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) \u2265 (3 / (2 * (a + b + c))), from\n    by {rw mul_assoc, rw div_mul_cancel, rw add_left_cancel, rw add_left_cancel, rw add_left_cancel, rw mul_comm _ 2, ring,},\n  have h5 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) \u2265 (3 / 2), from\n    by {rw mul_comm _ 2, rw mul_assoc, rw div_mul_cancel, rw add_left_cancel, rw add_left_cancel, rw add_left_cancel, ring,},\n  have h6 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from\n    by {rw [div_mul,div_mul,div_mul], rw add_mul, rw add_mul, rw add_mul, rw mul_comm _ 2, rw mul_comm _ 3, ring,},\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from\n    by {rw [div_mul,div_mul,div_mul], rw add_mul, rw add_mul, rw add_mul, rw mul_comm _ 2, rw mul_comm _ 3, ring,},\nend\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) \u2265 (3 / (a + b + c)), from by {\n    rw [one_mul,mul_comm 3 (a+b+c),mul_assoc,mul_comm (3/2) (a+b+c),div_eq_mul_inv,add_mul],\n    apply arithmetic_mean_never_less_than_harmonic_mean (a + b + c) (b + c) (a + c) (a + b),\n    simp,\n    have h2 : 0 < a + b + c, from add_pos ha (add_pos hb hc),\n    have h3 : 0 < b + c, from add_pos hb hc,\n    have h4 : 0 < a + c, from add_pos ha hc,\n    have h5 : 0 < a + b, from add_pos ha hb,\n    exact \u27e8h2,h3,h4,h5\u27e9,\n  },\n  rw [mul_comm 3 (a + b + c),mul_assoc,mul_comm (3 / 2) (a + b + c),div_eq_mul_inv,add_mul],\n  exact h1,\nend\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 / 2), from by {\n    rw [div_add_div_same,div_add_div_same,div_add_div_same],\n    have h1 : (b + c) + (a + c) + (a + b) > 0, from by {repeat {rw lt_add_iff_pos_right},exact \u27e8hb,hc\u27e9},\n    have h2 : (b + c) * (a + c) * (a + b) > 0, from by {rw mul_pos h1,apply lt_add_iff_pos_right.mpr,exact \u27e8hb,hc\u27e9},\n    have h3 : (a + b + c)^2 > 0, from by {rw \u2190 sq,exact sq_pos (a + b + c)},\n    have h4 : (a + b + c)^2 * (b + c) * (a + c) * (a + b) > 0, from by {apply mul_pos h3,exact h2},\n    have h5 : (a + b + c)^2 * (b + c) * (a + c) * (a + b) = (a + b + c) * ((a + b + c) * (b + c) * (a + c) * (a + b)), from by rw mul_left_comm (a + b + c),\n    have h6 : (a + b + c) * ((a + b + c) * (b + c) * (a + c) * (a + b)) > 0, from by {rw \u2190 h5,exact h4},\n    have h7 : ((a + b + c) * (b + c) * (a + c) * (a + b)) > 0, from by {rw mul_left_comm (a + b + c),exact h6},\n    have h8 : (b + c) * (a + c) * (a + b) > 0, from by {rw \u2190 mul_left_comm (a + b + c),exact h7},\n    have h9 : (b + c) * (a + c) * (a + b) = (b + c) * (a + c) * (a + b) * 1, from by rw mul_one,\n    have h10 : (b + c) * (a + c) * (a + b) * 1 > 0, from by {rw \u2190 h9,exact h8},\n    have h11 : (b + c) * (a + c) * (a + b) * 1 = ((b + c) * (a + c) * (a + b)) * 1, from by rw mul_left_comm ((b + c) * (a + c) * (a + b)),\n    have h12 : ((b + c) * (a + c) * (a + b)) * 1 > 0, from by {rw \u2190 h11,exact h10},\n    have h13 : ((b + c) * (a + c) * (a + b)) * 1 = ((b + c) * (a + c) * (a + b)) * (1 * 1), from by rw mul_left_comm ((b + c) * (a + c) * (a + b)),\n    have h14 : ((b + c) * (a + c) * (a + b)) * (1 * 1) > 0, from by {rw \u2190 h13,exact h12},\n    have h15 : ((b + c) * (a + c) * (a + b)) * (1 * 1) = (((b + c) * (a + c) * (a + b)) * 1) * 1, from by rw mul_left_comm (((b + c) * (a + c) * (a + b)) * 1),\n    have h16 : (((b + c) * (a + c) * (a + b)) * 1) * 1 > 0, from by {rw \u2190 h15,exact h14},\n    have h17 : (((b + c) * (a + c) * (a + b)) * 1) * 1 = (((b + c) * (a + c) * (a + b)) * 1) * (1 * 1), from by rw mul_left_comm (((b + c) * (a + c) * (a + b)) * 1),\n    have h18 : (((b + c) * (a + c) * (a + b)) * 1) * (1 * 1) > 0, from by {rw \u2190 h17,exact h16},\n    have h19 : (((b + c) * (a + c) * (a + b)) * 1) * (1 * 1) = (((b + c) * (a + c) * (a + b)) * 1) * ((1 * 1) * 1), from by rw mul_left_comm (((b + c) * (a + c) * (a + b)) * 1),\n    have h20 : (((b + c) * (a + c) * (a + b)) * 1) * ((1 * 1) * 1) > 0, from by {rw \u2190 h19,exact h18},\n    have h21 : (((b + c) * (a + c) * (a + b)) * 1) * ((1 * 1) * 1) = ((((b + c) * (a + c) * (a + b)) * 1) * (1 * 1)) * 1, from by rw mul_left_comm ((((b + c) * (a + c) * (a + b)) * 1) * (1 * 1)),\n    have h22 : ((((b + c) * (a + c) * (a + b)) * 1) * (1 * 1)) * 1 > 0, from by {rw \u2190 h21,exact h20},\n    have h23 : ((((b + c) * (a + c) * (a + b)) * 1) * (1 * 1)) * 1 = (((b + c) * (a + c) * (a + b) * 1) * 1) * 1, from by rw mul_left_comm (((b + c) * (a + c) * (a + b) * 1) * 1),\n    have h24 : (((b + c) * (a + c) * (a + b) * 1) * 1) * 1 > 0, from by {rw \u2190 h23,exact h22},\n    have h25 : (((b + c) * (a + c) * (a + b) * 1) * 1) * 1 = ((b + c) * (a + c) * (a + b) * 1) * (1 * 1), from by rw mul_left_comm ((b + c) * (a + c) * (a + b) * 1),\n    have h26 : ((b + c) * (a + c) * (a + b) * 1) * (1 * 1) > 0, from by {rw \u2190 h25,exact h24},\n    have h27 : ((b + c) * (a + c) * (a + b) * 1) * (1 * 1) = ((b + c) * (a + c) * (a + b) * 1) * ((1 * 1) * 1), from by rw mul_left_comm ((b + c) * (a + c) * (a + b) * 1),\n    have h28 : ((b + c) * (a + c) * (a + b) * 1) * ((1 * 1) * 1) > 0, from by {rw \u2190 h27,exact h26},\n    have h29 : ((b + c) * (a + c) * (a + b) * 1) * ((1 * 1) * 1) = (((b + c) * (a + c) * (a + b)) * 1) * ((1 * 1) * 1), from by rw mul_left_comm (((b + c) * (a + c) * (a + b)) * 1),\n    have h30 : (((b + c) * (a + c) * (a + b)) * 1) * ((1 * 1) * 1) > 0,\nend --Needs more than 2000 tokens!\n\n--OUTPUT 4\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : a + b + c > 0, from by {apply add_pos,exact ha,exact hb,exact hc,},\n  have h2 : (a + b + c) / 3 = 1 / 2, from by {\n    have h3 : 3 * ((a + b + c) / 3) = a + b + c, from by {rw div_mul,ring},\n    have h4 : ((a + b + c) / 3) * 3 = a + b + c, from by {rw mul_comm,apply h3},\n    have h5 : ((a + b + c) / 3) * 6 = 2 * (a + b + c), from by {rw h4,rw mul_comm,rw mul_assoc,ring},\n    have h6 : 6 * ((a + b + c) / 3) = 2 * (a + b + c), from by {rw mul_comm,apply h5},\n    have h7 : ((a + b + c) / 3) * 2 = (a + b + c) * 2, from by {rw \u2190 h6,rw div_mul,ring},\n    have h8 : 2 * ((a + b + c) / 3) = (a + b + c) * 2, from by {rw mul_comm,apply h7},\n    have h9 : ((a + b + c) / 3) * 2 = (a + b + c) * 2, from by {rw \u2190 h8,rw mul_assoc,ring},\n    have h10 : ((a + b + c) / 3) * 2 = 2 * (a + b + c), from by {rw \u2190 h9,rw mul_comm,rw mul_assoc,ring},\n    have h11 : 2 * ((a + b + c) / 3) = 2 * (a + b + c), from by {rw \u2190 h10,rw mul_comm,rw mul_assoc,ring},\n    have h12 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw \u2190 h11,rw div_mul,ring},\n    have h13 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_comm,apply h12},\n    have h14 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_assoc,apply h13},\n    have h15 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_comm,apply h14},\n    have h16 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_assoc,apply h15},\n    have h17 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_comm,apply h16},\n    have h18 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_assoc,apply h17},\n    have h19 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_comm,apply h18},\n    have h20 : ((a + b + c) / 3) = (a + b + c) / 2, from by {rw mul_assoc,apply h19},\n    rw \u2190 h20,rw mul_comm,rw mul_assoc,ring,\n  },\n  have h3 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 9 / 2, from by {\n    rw \u2190 add_assoc,rw \u2190 add_assoc,rw \u2190 add_assoc,\n    have h4 : (b + c) * (a / (b + c)) = a, from by {rw mul_comm,rw div_mul,ring},\n    have h5 : (a + c) * (b / (a + c)) = b, from by {rw mul_comm,rw div_mul,ring},\n    have h6 : (a + b) * (c / (a + b)) = c, from by {rw mul_comm,rw div_mul,ring},\n    have h7 : (b + c) + (a + c) + (a + b) = 3 * (a + b + c), from by {ring},\n    have h8 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) =\n      ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)), from by {\n        rw h4,rw h5,rw h6,ring,\n      },\n    rw h8,rw h2,rw mul_comm,rw mul_assoc,ring,\n  },\n  have h4 : 9 / 2 \u2265 3 / 2, from by {rw mul_comm,rw mul_assoc,ring},\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 3 / 2, from by {apply le_of_lt h3,exact h4},\nend\n\n--OUTPUT 5\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / ((b + c) + (a + c) + (a + b)) = (1 / 2), from (add_div_add_div_add_div a b c).symm,\n  have h2 : (3 * (a + b + c)) / (3 * ((b + c) + (a + c) + (a + b))) = (1 / 2), from by rw [\u2190 mul_div_assoc, \u2190 h1, mul_comm 3 (a + b + c), mul_comm 3 ((b + c) + (a + c) + (a + b))],\n  have h3 : (3 * (a + b + c)) / (3 * ((b + c) + (a + c) + (a + b))) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from\n    mul_div_ge_div_mul_of_nonneg (le_of_lt (add_three_pos ha hb hc)) h2 (add_three_pos ha hb hc) (by norm_num),\n  have h4 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 * (a + b + c)) / (3 * ((b + c) + (a + c) + (a + b))), from\n    add_div_add_div_add_div a b c,\n  have h5 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from\n    le_trans h4 h3,\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from le_trans h5 (by norm_num),\nend\n\n--OUTPUT 6\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have habc : 0 < (a + b + c), from by {apply lt_add_of_pos_of_pos ha hb, apply lt_add_of_pos_of_pos ha hc, apply lt_add_of_pos_of_pos hb hc,},\n  have hab : 0 < (a + b), from by {apply lt_add_of_pos_of_pos ha hb,},\n  have hac : 0 < (a + c), from by {apply lt_add_of_pos_of_pos ha hc,},\n  have hbc : 0 < (b + c), from by {apply lt_add_of_pos_of_pos hb hc,},\n\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + 3 : by rw add_zero\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a + b + c) / (a + b + c) : by rw div_self habc\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (1 / (a + b + c)) * (a + b + c) : by rw div_mul_cancel habc\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + ((1 / (b + c)) * (b + c) + (1 / (a + c)) * (a + c) + (1 / (a + b)) * (a + b)) : by rw mul_assoc\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + ((1 / (b + c)) * b + (1 / (b + c)) * c + (1 / (a + c)) * a + (1 / (a + c)) * c + (1 / (a + b)) * a + (1 / (a + b)) * b) : by ring\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (b / (b + c) + c / (b + c) + a / (a + c) + c / (a + c) + a / (a + b) + b / (a + b)) : by rw [div_mul_cancel hbc,div_mul_cancel hac,div_mul_cancel hab]\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (b / (b + c) + c / (b + c) + a / (a + c) + c / (a + c) + a / (a + b) + b / (a + b)) + 1 : by rw add_zero\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (b / (b + c) + c / (b + c) + a / (a + c) + c / (a + c) + a / (a + b) + b / (a + b)) + (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) : by rw add_comm\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (b / (b + c) + c / (b + c) + a / (a + c) + c / (a + c) + a / (a + b) + b / (a + b)) + ((1 / (b + c)) * (b + c) + (1 / (a + c)) * (a + c) + (1 / (a + b)) * (a + b)) : by rw [div_mul_cancel hbc,div_mul_cancel hac,div_mul_cancel hab]\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (b / (b + c) + c / (b + c) + a / (a + c) + c / (a + c) + a / (a + b) + b / (a + b)) + ((1 / (b + c)) * b + (1 / (b + c)) * c + (1 / (a + c)) * a + (1 / (a + c)) * c + (1 / (a + b)) * a + (1 / (a + b)) * b) : by ring\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (b / (b + c) + c / (b + c) + a / (a + c) + c / (a + c) + a / (a + b) + b / (a + b)) + (b / (b + c) + c / (b + c) + a / (a + c) + c / (a + c) + a / (a + b) + b / (a + b)) : by ring\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + c) + b / (a + c) + c / (a + c) + a / (a + b) + b / (a + b) + c / (a + b)) : by {rw add_comm, rw add_assoc,}\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + c) + b / (a + c) + a / (a + b) + b / (a + b) + c / (a + c) + c / (a + b)) : by rw add_comm\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + c) + a / (a + b) + b / (a + c) + b / (a + b) + c / (a + c) + c / (a + b)) : by rw add_comm\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + b) + b / (a + b) + a / (a + c) + b / (a + c) + c / (a + b) + c / (a + c)) : by rw add_comm\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + b) + b / (a + b) + c / (a + b) + a / (a + c) + b / (a + c) + c / (a + c)) : by rw add_comm\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + b) + b / (a + b) + c / (a + b)) + (a / (a + c) + b / (a + c) + c / (a + c)) : by rw add_assoc\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + c) + b / (a + c) + c / (a + c)) + (a / (a + b) + b / (a + b) + c / (a + b)) : by rw add_comm\n  ... = (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (a / (a + c) + b / (a + c) + c / (a + c)) + (a / (a + b)) + (b / (a + b)) + (c / (a + b)) : by rw add_assoc\n  ...\nend --Needs more than 2000 tokens!\n\n--OUTPUT 7\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) > 0, from by {linarith,},\n  have h2 : (a + b + c) / 2 = (3/2) * (a + b + c), from by {repeat {rw \u2190 mul_one}, rw mul_comm, ring},\n  have h3 : (a + b + c) / (b + c) = (a + b + c) * (2 / (b + c)), from by {rw \u2190 mul_one, rw mul_comm, ring},\n  have h4 : (a + b + c) / (a + c) = (a + b + c) * (2 / (a + c)), from by {rw \u2190 mul_one, rw mul_comm, ring},\n  have h5 : (a + b + c) / (a + b) = (a + b + c) * (2 / (a + b)), from by {rw \u2190 mul_one, rw mul_comm, ring},\n  have h6 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 3, from by {\n    rw [\u2190 add_mul,\u2190 add_mul,\u2190 add_mul,\u2190 add_mul,\u2190 add_mul,\u2190 add_mul,\u2190 add_mul], ring,\n  },\n  have h7 : (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 3 = (a + b + c) * (2 / (b + c) + 2 / (a + c) + 2 / (a + b)) / 6, from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h8 : (a + b + c) * (2 / (b + c) + 2 / (a + c) + 2 / (a + b)) / 6 = (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 2, from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h9 : (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 2 = (a + b + c) / 2 * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 div_mul}, ring,\n  },\n  have h10 : (a + b + c) / 2 * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) = (3 / 2) * (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h11 : (3 / 2) * (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) = (3 / 2) * ((a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b)), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h12 : (3 / 2) * ((a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b)) = (3 / 2) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 div_mul, rw \u2190 div_mul, rw \u2190 div_mul, rw \u2190 div_mul, rw \u2190 div_mul, rw \u2190 div_mul, rw \u2190 div_mul, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h13 : (3 / 2) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) = (3 / 2) * (2 / (b + c) + 2 / (a + c) + 2 / (a + b)) / 6, from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h14 : (3 / 2) * (2 / (b + c) + 2 / (a + c) + 2 / (a + b)) / 6 = (3 / 2) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 3, from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h15 : (3 / 2) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 3 = (3 / 2) / ((b + c) + (a + c) + (a + b)), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 div_mul}, ring,\n  },\n  have h16 : (3 / 2) / ((b + c) + (a + c) + (a + b)) = (a + b + c) / ((b + c) + (a + c) + (a + b)) * (3 / 2), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 div_mul, rw \u2190 div_mul, ring,\n  },\n  have h17 : (a + b + c) / ((b + c) + (a + c) + (a + b)) * (3 / 2) = (a + b + c) / 2 * (3 / 2), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 div_mul}, ring,\n  },\n  have h18 : (a + b + c) / 2 * (3 / 2) = (3 / 2) * (a + b + c) / 2, from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h19 : (3 / 2) * (a + b + c) / 2 = (3 / 2) * (a + b + c), from by {\n    rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, rw \u2190 mul_one, repeat {rw \u2190 mul_add}, ring,\n  },\n  have h20 : (3 / 2) * (a\nend --Needs more than 2000 tokens!\n\n--OUTPUT 8\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) > 0, from by linarith,\n  have h2 : (a + b + c) / 2 = 1 / 2 * (a + b + c), from by rw div_mul_cancel h1,\n  have h3 : (a + b + c) / 2 = 1 / 2 * ((a + b + c) + (a + b + c)), from by ring,\n  have h4 : (a + b + c) / 2 = ((a + b + c) / 2) + ((a + b + c) / 2), from by rw \u2190 h3,\n  have h5 : (a + b + c) / 2 = ((a + b + c) / 2) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h6 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw add_comm ((a + b + c) / 2) (1 / 2 * (a + b + c)),\n  have h7 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw \u2190 h3,\n  have h8 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h4,\n  have h9 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h10 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h5,\n  have h11 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h12 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h7,\n  have h13 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h14 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h9,\n  have h15 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h16 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h11,\n  have h17 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h18 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h13,\n  have h19 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h20 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h15,\n  have h21 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)), from by rw h2,\n  have h22 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + ((a + b + c) / 2), from by rw \u2190 h17,\n  have h23 : (a + b + c) / 2 = (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (1 / 2 * (a + b + c)) + (\nend --Needs more than 2000 tokens!\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB},\n  have h2 : (A \u2229 B) \u2286 A, from by apply set.inter_subset_left,\n  have h3 : (A \u2229 B) \u2286 S, from by {apply set.subset.trans h2 h1.left},\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by {apply set.mem_powerset h3},\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  calc (x + y)^2 = (x+y)*(x+y) : by rw sq\n  ... = x*(x+y) + y*(x+y) : by rw add_mul\n  ... = x*x + x*y + y*x + y*y : by {rw [mul_comm x (x+y),mul_comm y (x+y)], rw [add_mul,add_mul], ring}\n  ... = x^2 + 2*x*y + y^2 : by {repeat {rw \u2190 sq}, rw mul_comm y x, ring}\nend\n\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by {\n    assume a b : G, use a\u207b\u00b9 * b, obviously, },\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by {\n    assume a b : G, use b * a\u207b\u00b9, obviously, }, \n\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from \n    assume a : G, h1 a a,\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from\n    assume a : G, h2 a a,\n\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from assume a :G,\n    exists_unique.unique (h3 a) (classical.some_spec (exists_unique.exists (h3 a)))\n    (mul_one a),\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from assume a : G,\n    exists_unique.unique (h4 a) (classical.some_spec (exists_unique.exists (h4 a))) (one_mul a), \n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by {\n    use (1 : G),\n    have h7 : \u2200 e : G, (\u2200 a : G, e * a = a \u2227 a * e = a) \u2192 e = 1, from by {\n      assume (e : G) (hident : \u2200 a : G, e * a = a \u2227 a * e = a),\n      have h8 : \u2200 a : G, e = classical.some (h3 a).exists, from assume (a : G),\n        exists_unique.unique (h3 a) (hident a).right\n        (classical.some_spec (exists_unique.exists (h3 a))), \n      have h9 : \u2200 a : G, e = classical.some (h4 a).exists, from assume (a : G),\n        exists_unique.unique (h4 a) (hident a).left\n        (classical.some_spec (exists_unique.exists (h4 a))),\n      show e = (1 : G), from eq.trans (h9 e) (h6 _),     \n    },\n    exact \u27e8by obviously, h7\u27e9,\n  }\nend\n\n/--`theorem`\nNesbitt's inequality\nLet $a$, $b$ and $c$ be positive real numbers.\n\nThen:\n:$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n\n`proof`\n{{begin-eqn}}\n{{eqn | l = \\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}\n      | o = \\ge\n      | r = \\dfrac 3 2\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac 9 2\n      | c = by adding $3$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3\n      | o = \\ge\n      | r = \\frac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = dividing by $3 \\paren {a + b + c}$\n}}\n{{end-eqn}}\nThese are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n\nFrom Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n\nThus Nesbitt's Inequality holds.\n{{qed}}\n\n-/\ntheorem  nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof-Natural-Language-Proof-Translation/Correct_statement-lean_proof-3_few_shot_temperature_0.6_max_tokens_2000_n_8/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7426917811212483}}
{"text": "/-\nCopyright (c) 2021 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n\n! This file was ported from Lean 3 source module measure_theory.decomposition.signed_hahn\n! leanprover-community/mathlib commit bc7d81beddb3d6c66f71449c5bc76c38cb77cf9e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.VectorMeasure\nimport Mathbin.Order.SymmDiff\n\n/-!\n# Hahn decomposition\n\nThis file proves the Hahn decomposition theorem (signed version). The Hahn decomposition theorem\nstates that, given a signed measure `s`, there exist complementary, measurable sets `i` and `j`,\nsuch that `i` is positive and `j` is negative with respect to `s`; that is, `s` restricted on `i`\nis non-negative and `s` restricted on `j` is non-positive.\n\nThe Hahn decomposition theorem leads to many other results in measure theory, most notably,\nthe Jordan decomposition theorem, the Lebesgue decomposition theorem and the Radon-Nikodym theorem.\n\n## Main results\n\n* `measure_theory.signed_measure.exists_is_compl_positive_negative` : the Hahn decomposition\n  theorem.\n* `measure_theory.signed_measure.exists_subset_restrict_nonpos` : A measurable set of negative\n  measure contains a negative subset.\n\n## Notation\n\nWe use the notations `0 \u2264[i] s` and `s \u2264[i] 0` to denote the usual definitions of a set `i`\nbeing positive/negative with respect to the signed measure `s`.\n\n## Tags\n\nHahn decomposition theorem\n-/\n\n\nnoncomputable section\n\nopen Classical BigOperators NNReal ENNReal MeasureTheory\n\nvariable {\u03b1 \u03b2 : Type _} [MeasurableSpace \u03b1]\n\nvariable {M : Type _} [AddCommMonoid M] [TopologicalSpace M] [OrderedAddCommMonoid M]\n\nnamespace MeasureTheory\n\nnamespace SignedMeasure\n\nopen Filter VectorMeasure\n\nvariable {s : SignedMeasure \u03b1} {i j : Set \u03b1}\n\nsection ExistsSubsetRestrictNonpos\n\n/-! ### exists_subset_restrict_nonpos\n\nIn this section we will prove that a set `i` whose measure is negative contains a negative subset\n`j` with respect to the signed measure `s` (i.e. `s \u2264[j] 0`), whose measure is negative. This lemma\nis used to prove the Hahn decomposition theorem.\n\nTo prove this lemma, we will construct a sequence of measurable sets $(A_n)_{n \\in \\mathbb{N}}$,\nsuch that, for all $n$, $s(A_{n + 1})$ is close to maximal among subsets of\n$i \\setminus \\bigcup_{k \\le n} A_k$.\n\nThis sequence of sets does not necessarily exist. However, if this sequence terminates; that is,\nthere does not exists any sets satisfying the property, the last $A_n$ will be a negative subset\nof negative measure, hence proving our claim.\n\nIn the case that the sequence does not terminate, it is easy to see that\n$i \\setminus \\bigcup_{k = 0}^\\infty A_k$ is the required negative set.\n\nTo implement this in Lean, we define several auxilary definitions.\n\n- given the sets `i` and the natural number `n`, `exists_one_div_lt s i n` is the property that\n  there exists a measurable set `k \u2286 i` such that `1 / (n + 1) < s k`.\n- given the sets `i` and that `i` is not negative, `find_exists_one_div_lt s i` is the\n  least natural number `n` such that `exists_one_div_lt s i n`.\n- given the sets `i` and that `i` is not negative, `some_exists_one_div_lt` chooses the set\n  `k` from `exists_one_div_lt s i (find_exists_one_div_lt s i)`.\n- lastly, given the set `i`, `restrict_nonpos_seq s i` is the sequence of sets defined inductively\n  where\n  `restrict_nonpos_seq s i 0 = some_exists_one_div_lt s (i \\ \u2205)` and\n  `restrict_nonpos_seq s i (n + 1) = some_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq k)`.\n  This definition represents the sequence $(A_n)$\u00a0in the proof as described above.\n\nWith these definitions, we are able consider the case where the sequence terminates separately,\nallowing us to prove `exists_subset_restrict_nonpos`.\n-/\n\n\n/-- Given the set `i` and the natural number `n`, `exists_one_div_lt s i j` is the property that\nthere exists a measurable set `k \u2286 i` such that `1 / (n + 1) < s k`. -/\nprivate def exists_one_div_lt (s : SignedMeasure \u03b1) (i : Set \u03b1) (n : \u2115) : Prop :=\n  \u2203 k : Set \u03b1, k \u2286 i \u2227 MeasurableSet k \u2227 (1 / (n + 1) : \u211d) < s k\n#align measure_theory.signed_measure.exists_one_div_lt measure_theory.signed_measure.exists_one_div_lt\n\nprivate theorem exists_nat_one_div_lt_measure_of_not_negative (hi : \u00acs \u2264[i] 0) :\n    \u2203 n : \u2115, ExistsOneDivLt s i n :=\n  let \u27e8k, hj\u2081, hj\u2082, hj\u27e9 := exists_pos_measure_of_not_restrict_le_zero s hi\n  let \u27e8n, hn\u27e9 := exists_nat_one_div_lt hj\n  \u27e8n, k, hj\u2082, hj\u2081, hn\u27e9\n#align measure_theory.signed_measure.exists_nat_one_div_lt_measure_of_not_negative measure_theory.signed_measure.exists_nat_one_div_lt_measure_of_not_negative\n\n/-- Given the set `i`, if `i` is not negative, `find_exists_one_div_lt s i` is the\nleast natural number `n` such that `exists_one_div_lt s i n`, otherwise, it returns 0. -/\nprivate def find_exists_one_div_lt (s : SignedMeasure \u03b1) (i : Set \u03b1) : \u2115 :=\n  if hi : \u00acs \u2264[i] 0 then Nat.find (exists_nat_one_div_lt_measure_of_not_negative hi) else 0\n#align measure_theory.signed_measure.find_exists_one_div_lt measure_theory.signed_measure.find_exists_one_div_lt\n\nprivate theorem find_exists_one_div_lt_spec (hi : \u00acs \u2264[i] 0) :\n    ExistsOneDivLt s i (findExistsOneDivLt s i) :=\n  by\n  rw [find_exists_one_div_lt, dif_pos hi]\n  convert Nat.find_spec _\n#align measure_theory.signed_measure.find_exists_one_div_lt_spec measure_theory.signed_measure.find_exists_one_div_lt_spec\n\nprivate theorem find_exists_one_div_lt_min (hi : \u00acs \u2264[i] 0) {m : \u2115}\n    (hm : m < findExistsOneDivLt s i) : \u00acExistsOneDivLt s i m :=\n  by\n  rw [find_exists_one_div_lt, dif_pos hi] at hm\n  exact Nat.find_min _ hm\n#align measure_theory.signed_measure.find_exists_one_div_lt_min measure_theory.signed_measure.find_exists_one_div_lt_min\n\n/-- Given the set `i`, if `i` is not negative, `some_exists_one_div_lt` chooses the set\n`k` from `exists_one_div_lt s i (find_exists_one_div_lt s i)`, otherwise, it returns the\nempty set. -/\nprivate def some_exists_one_div_lt (s : SignedMeasure \u03b1) (i : Set \u03b1) : Set \u03b1 :=\n  if hi : \u00acs \u2264[i] 0 then Classical.choose (findExistsOneDivLt_spec hi) else \u2205\n#align measure_theory.signed_measure.some_exists_one_div_lt measure_theory.signed_measure.some_exists_one_div_lt\n\nprivate theorem some_exists_one_div_lt_spec (hi : \u00acs \u2264[i] 0) :\n    someExistsOneDivLt s i \u2286 i \u2227\n      MeasurableSet (someExistsOneDivLt s i) \u2227\n        (1 / (findExistsOneDivLt s i + 1) : \u211d) < s (someExistsOneDivLt s i) :=\n  by\n  rw [some_exists_one_div_lt, dif_pos hi]\n  exact Classical.choose_spec (find_exists_one_div_lt_spec hi)\n#align measure_theory.signed_measure.some_exists_one_div_lt_spec measure_theory.signed_measure.some_exists_one_div_lt_spec\n\nprivate theorem some_exists_one_div_lt_subset : someExistsOneDivLt s i \u2286 i :=\n  by\n  by_cases hi : \u00acs \u2264[i] 0\n  \u00b7\n    exact\n      let \u27e8h, _\u27e9 := some_exists_one_div_lt_spec hi\n      h\n  \u00b7 rw [some_exists_one_div_lt, dif_neg hi]\n    exact Set.empty_subset _\n#align measure_theory.signed_measure.some_exists_one_div_lt_subset measure_theory.signed_measure.some_exists_one_div_lt_subset\n\nprivate theorem some_exists_one_div_lt_subset' : someExistsOneDivLt s (i \\ j) \u2286 i :=\n  Set.Subset.trans someExistsOneDivLt_subset (Set.diff_subset _ _)\n#align measure_theory.signed_measure.some_exists_one_div_lt_subset' measure_theory.signed_measure.some_exists_one_div_lt_subset'\n\nprivate theorem some_exists_one_div_lt_measurable_set : MeasurableSet (someExistsOneDivLt s i) :=\n  by\n  by_cases hi : \u00acs \u2264[i] 0\n  \u00b7\n    exact\n      let \u27e8_, h, _\u27e9 := some_exists_one_div_lt_spec hi\n      h\n  \u00b7 rw [some_exists_one_div_lt, dif_neg hi]\n    exact MeasurableSet.empty\n#align measure_theory.signed_measure.some_exists_one_div_lt_measurable_set measure_theory.signed_measure.some_exists_one_div_lt_measurable_set\n\nprivate theorem some_exists_one_div_lt_lt (hi : \u00acs \u2264[i] 0) :\n    (1 / (findExistsOneDivLt s i + 1) : \u211d) < s (someExistsOneDivLt s i) :=\n  let \u27e8_, _, h\u27e9 := someExistsOneDivLt_spec hi\n  h\n#align measure_theory.signed_measure.some_exists_one_div_lt_lt measure_theory.signed_measure.some_exists_one_div_lt_lt\n\n/-- Given the set `i`, `restrict_nonpos_seq s i` is the sequence of sets defined inductively where\n`restrict_nonpos_seq s i 0 = some_exists_one_div_lt s (i \\ \u2205)` and\n`restrict_nonpos_seq s i (n + 1) = some_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq k)`.\n\nFor each `n : \u2115`,`s (restrict_nonpos_seq s i n)` is close to maximal among all subsets of\n`i \\ \u22c3 k \u2264 n, restrict_nonpos_seq s i k`. -/\nprivate def restrict_nonpos_seq (s : SignedMeasure \u03b1) (i : Set \u03b1) : \u2115 \u2192 Set \u03b1\n  | 0 => someExistsOneDivLt s (i \\ \u2205)\n  |-- I used `i \\ \u2205` instead of `i` to simplify some proofs\n      n +\n      1 =>\n    someExistsOneDivLt s\n      (i \\\n        \u22c3 k \u2264 n,\n          have : k < n + 1 := Nat.lt_succ_iff.mpr H\n          restrict_nonpos_seq k)\n#align measure_theory.signed_measure.restrict_nonpos_seq measure_theory.signed_measure.restrict_nonpos_seq\n\nprivate theorem restrict_nonpos_seq_succ (n : \u2115) :\n    restrictNonposSeq s i n.succ = someExistsOneDivLt s (i \\ \u22c3 k \u2264 n, restrictNonposSeq s i k) := by\n  rw [restrict_nonpos_seq]\n#align measure_theory.signed_measure.restrict_nonpos_seq_succ measure_theory.signed_measure.restrict_nonpos_seq_succ\n\nprivate theorem restrict_nonpos_seq_subset (n : \u2115) : restrictNonposSeq s i n \u2286 i := by\n  cases n <;>\n    \u00b7 rw [restrict_nonpos_seq]\n      exact some_exists_one_div_lt_subset'\n#align measure_theory.signed_measure.restrict_nonpos_seq_subset measure_theory.signed_measure.restrict_nonpos_seq_subset\n\nprivate theorem restrict_nonpos_seq_lt (n : \u2115) (hn : \u00acs \u2264[i \\ \u22c3 k \u2264 n, restrictNonposSeq s i k] 0) :\n    (1 / (findExistsOneDivLt s (i \\ \u22c3 k \u2264 n, restrictNonposSeq s i k) + 1) : \u211d) <\n      s (restrictNonposSeq s i n.succ) :=\n  by\n  rw [restrict_nonpos_seq_succ]\n  apply some_exists_one_div_lt_lt hn\n#align measure_theory.signed_measure.restrict_nonpos_seq_lt measure_theory.signed_measure.restrict_nonpos_seq_lt\n\nprivate theorem measure_of_restrict_nonpos_seq (hi\u2082 : \u00acs \u2264[i] 0) (n : \u2115)\n    (hn : \u00acs \u2264[i \\ \u22c3 k < n, restrictNonposSeq s i k] 0) : 0 < s (restrictNonposSeq s i n) :=\n  by\n  cases n\n  \u00b7 rw [restrict_nonpos_seq]\n    rw [\u2190 @Set.diff_empty _ i] at hi\u2082\n    rcases some_exists_one_div_lt_spec hi\u2082 with \u27e8_, _, h\u27e9\n    exact lt_trans Nat.one_div_pos_of_nat h\n  \u00b7 rw [restrict_nonpos_seq_succ]\n    have h\u2081 : \u00acs \u2264[i \\ \u22c3 (k : \u2115) (H : k \u2264 n), restrict_nonpos_seq s i k] 0 :=\n      by\n      refine' mt (restrict_le_zero_subset _ _ (by simp [Nat.lt_succ_iff])) hn\n      convert measurable_of_not_restrict_le_zero _ hn\n      exact funext fun x => by rw [Nat.lt_succ_iff]\n    rcases some_exists_one_div_lt_spec h\u2081 with \u27e8_, _, h\u27e9\n    exact lt_trans Nat.one_div_pos_of_nat h\n#align measure_theory.signed_measure.measure_of_restrict_nonpos_seq measure_theory.signed_measure.measure_of_restrict_nonpos_seq\n\nprivate theorem restrict_nonpos_seq_measurable_set (n : \u2115) :\n    MeasurableSet (restrictNonposSeq s i n) := by\n  cases n <;>\n    \u00b7 rw [restrict_nonpos_seq]\n      exact some_exists_one_div_lt_measurable_set\n#align measure_theory.signed_measure.restrict_nonpos_seq_measurable_set measure_theory.signed_measure.restrict_nonpos_seq_measurable_set\n\nprivate theorem restrict_nonpos_seq_disjoint' {n m : \u2115} (h : n < m) :\n    restrictNonposSeq s i n \u2229 restrictNonposSeq s i m = \u2205 :=\n  by\n  rw [Set.eq_empty_iff_forall_not_mem]\n  rintro x \u27e8hx\u2081, hx\u2082\u27e9\n  cases m; \u00b7 linarith\n  \u00b7 rw [restrict_nonpos_seq] at hx\u2082\n    exact\n      (some_exists_one_div_lt_subset hx\u2082).2\n        (Set.mem_union\u1d62.2 \u27e8n, Set.mem_union\u1d62.2 \u27e8nat.lt_succ_iff.mp h, hx\u2081\u27e9\u27e9)\n#align measure_theory.signed_measure.restrict_nonpos_seq_disjoint' measure_theory.signed_measure.restrict_nonpos_seq_disjoint'\n\nprivate theorem restrict_nonpos_seq_disjoint : Pairwise (Disjoint on restrictNonposSeq s i) :=\n  by\n  intro n m h\n  rw [Function.onFun, Set.disjoint_iff_inter_eq_empty]\n  rcases lt_or_gt_of_ne h with (h | h)\n  \u00b7 rw [restrict_nonpos_seq_disjoint' h]\n  \u00b7 rw [Set.inter_comm, restrict_nonpos_seq_disjoint' h]\n#align measure_theory.signed_measure.restrict_nonpos_seq_disjoint measure_theory.signed_measure.restrict_nonpos_seq_disjoint\n\nprivate theorem exists_subset_restrict_nonpos' (hi\u2081 : MeasurableSet i) (hi\u2082 : s i < 0)\n    (hn : \u00ac\u2200 n : \u2115, \u00acs \u2264[i \\ \u22c3 l < n, restrictNonposSeq s i l] 0) :\n    \u2203 j : Set \u03b1, MeasurableSet j \u2227 j \u2286 i \u2227 s \u2264[j] 0 \u2227 s j < 0 :=\n  by\n  by_cases s \u2264[i] 0; \u00b7 exact \u27e8i, hi\u2081, Set.Subset.refl _, h, hi\u2082\u27e9\n  push_neg  at hn\n  set k := Nat.find hn with hk\u2081\n  have hk\u2082 : s \u2264[i \\ \u22c3 l < k, restrict_nonpos_seq s i l] 0 := Nat.find_spec hn\n  have hmeas : MeasurableSet (\u22c3 (l : \u2115) (H : l < k), restrict_nonpos_seq s i l) :=\n    MeasurableSet.union\u1d62 fun _ => MeasurableSet.union\u1d62 fun _ => restrict_nonpos_seq_measurable_set _\n  refine' \u27e8i \\ \u22c3 l < k, restrict_nonpos_seq s i l, hi\u2081.diff hmeas, Set.diff_subset _ _, hk\u2082, _\u27e9\n  rw [of_diff hmeas hi\u2081, s.of_disjoint_Union_nat]\n  \u00b7 have h\u2081 : \u2200 l < k, 0 \u2264 s (restrict_nonpos_seq s i l) :=\n      by\n      intro l hl\n      refine' le_of_lt (measure_of_restrict_nonpos_seq h _ _)\n      refine' mt (restrict_le_zero_subset _ (hi\u2081.diff _) (Set.Subset.refl _)) (Nat.find_min hn hl)\n      exact\n        MeasurableSet.union\u1d62 fun _ =>\n          MeasurableSet.union\u1d62 fun _ => restrict_nonpos_seq_measurable_set _\n    suffices 0 \u2264 \u2211' l : \u2115, s (\u22c3 H : l < k, restrict_nonpos_seq s i l)\n      by\n      rw [sub_neg]\n      exact lt_of_lt_of_le hi\u2082 this\n    refine' tsum_nonneg _\n    intro l\n    by_cases l < k\n    \u00b7 convert h\u2081 _ h\n      ext x\n      rw [Set.mem_union\u1d62, exists_prop, and_iff_right_iff_imp]\n      exact fun _ => h\n    \u00b7 convert le_of_eq s.empty.symm\n      ext\n      simp only [exists_prop, Set.mem_empty_iff_false, Set.mem_union\u1d62, not_and, iff_false_iff]\n      exact fun h' => False.elim (h h')\n  \u00b7 intro\n    exact MeasurableSet.union\u1d62 fun _ => restrict_nonpos_seq_measurable_set _\n  \u00b7 intro a b hab\n    refine' set.disjoint_Union_left.mpr fun ha => _\n    refine' set.disjoint_Union_right.mpr fun hb => _\n    exact restrict_nonpos_seq_disjoint hab\n  \u00b7 apply Set.union\u1d62_subset\n    intro a x\n    simp only [and_imp, exists_prop, Set.mem_union\u1d62]\n    intro _ hx\n    exact restrict_nonpos_seq_subset _ hx\n  \u00b7 infer_instance\n#align measure_theory.signed_measure.exists_subset_restrict_nonpos' measure_theory.signed_measure.exists_subset_restrict_nonpos'\n\n/-- A measurable set of negative measure has a negative subset of negative measure. -/\ntheorem exists_subset_restrict_nonpos (hi : s i < 0) :\n    \u2203 j : Set \u03b1, MeasurableSet j \u2227 j \u2286 i \u2227 s \u2264[j] 0 \u2227 s j < 0 :=\n  by\n  have hi\u2081 : MeasurableSet i := by_contradiction fun h => ne_of_lt hi <| s.not_measurable h\n  by_cases s \u2264[i] 0\n  \u00b7 exact \u27e8i, hi\u2081, Set.Subset.refl _, h, hi\u27e9\n  by_cases hn : \u2200 n : \u2115, \u00acs \u2264[i \\ \u22c3 l < n, restrict_nonpos_seq s i l] 0\n  swap\n  \u00b7 exact exists_subset_restrict_nonpos' hi\u2081 hi hn\n  set A := i \\ \u22c3 l, restrict_nonpos_seq s i l with hA\n  set bdd : \u2115 \u2192 \u2115 := fun n => find_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq s i k) with\n    hbdd\n  have hn' : \u2200 n : \u2115, \u00acs \u2264[i \\ \u22c3 l \u2264 n, restrict_nonpos_seq s i l] 0 :=\n    by\n    intro n\n    convert hn (n + 1) <;>\n      \u00b7 ext l\n        simp only [exists_prop, Set.mem_union\u1d62, and_congr_left_iff]\n        exact fun _ => nat.lt_succ_iff.symm\n  have h\u2081 : s i = s A + \u2211' l, s (restrict_nonpos_seq s i l) :=\n    by\n    rw [hA, \u2190 s.of_disjoint_Union_nat, add_comm, of_add_of_diff]\n    exact MeasurableSet.union\u1d62 fun _ => restrict_nonpos_seq_measurable_set _\n    exacts[hi\u2081, Set.union\u1d62_subset fun _ => restrict_nonpos_seq_subset _, fun _ =>\n      restrict_nonpos_seq_measurable_set _, restrict_nonpos_seq_disjoint]\n  have h\u2082 : s A \u2264 s i := by\n    rw [h\u2081]\n    apply le_add_of_nonneg_right\n    exact tsum_nonneg fun n => le_of_lt (measure_of_restrict_nonpos_seq h _ (hn n))\n  have h\u2083' : Summable fun n => (1 / (bdd n + 1) : \u211d) :=\n    by\n    have : Summable fun l => s (restrict_nonpos_seq s i l) :=\n      HasSum.summable\n        (s.m_Union (fun _ => restrict_nonpos_seq_measurable_set _) restrict_nonpos_seq_disjoint)\n    refine'\n      summable_of_nonneg_of_le (fun n => _) (fun n => _)\n        (Summable.comp_injective this Nat.succ_injective)\n    \u00b7 exact le_of_lt Nat.one_div_pos_of_nat\n    \u00b7 exact le_of_lt (restrict_nonpos_seq_lt n (hn' n))\n  have h\u2083 : tendsto (fun n => (bdd n : \u211d) + 1) at_top at_top :=\n    by\n    simp only [one_div] at h\u2083'\n    exact Summable.tendsto_atTop_of_pos h\u2083' fun n => Nat.cast_add_one_pos (bdd n)\n  have h\u2084 : tendsto (fun n => (bdd n : \u211d)) at_top at_top :=\n    by\n    convert at_top.tendsto_at_top_add_const_right (-1) h\u2083\n    simp\n  have A_meas : MeasurableSet A :=\n    hi\u2081.diff (MeasurableSet.union\u1d62 fun _ => restrict_nonpos_seq_measurable_set _)\n  refine' \u27e8A, A_meas, Set.diff_subset _ _, _, h\u2082.trans_lt hi\u27e9\n  by_contra hnn\n  rw [restrict_le_restrict_iff _ _ A_meas] at hnn\n  push_neg  at hnn\n  obtain \u27e8E, hE\u2081, hE\u2082, hE\u2083\u27e9 := hnn\n  have : \u2203 k, 1 \u2264 bdd k \u2227 1 / (bdd k : \u211d) < s E :=\n    by\n    rw [tendsto_at_top_at_top] at h\u2084\n    obtain \u27e8k, hk\u27e9 := h\u2084 (max (1 / s E + 1) 1)\n    refine' \u27e8k, _, _\u27e9\n    \u00b7 have hle := le_of_max_le_right (hk k le_rfl)\n      norm_cast  at hle\n      exact hle\n    \u00b7 have : 1 / s E < bdd k := by\n        linarith (config := { restrict_type := \u211d }) [le_of_max_le_left (hk k le_rfl)]\n      rw [one_div] at this\u22a2\n      rwa [inv_lt (lt_trans (inv_pos.2 hE\u2083) this) hE\u2083]\n  obtain \u27e8k, hk\u2081, hk\u2082\u27e9 := this\n  have hA' : A \u2286 i \\ \u22c3 l \u2264 k, restrict_nonpos_seq s i l :=\n    by\n    apply Set.diff_subset_diff_right\n    intro x\n    simp only [Set.mem_union\u1d62]\n    rintro \u27e8n, _, hn\u2082\u27e9\n    exact \u27e8n, hn\u2082\u27e9\n  refine'\n    find_exists_one_div_lt_min (hn' k) (Buffer.lt_aux_2 hk\u2081) \u27e8E, Set.Subset.trans hE\u2082 hA', hE\u2081, _\u27e9\n  convert hk\u2082\n  norm_cast\n  exact tsub_add_cancel_of_le hk\u2081\n#align measure_theory.signed_measure.exists_subset_restrict_nonpos MeasureTheory.SignedMeasure.exists_subset_restrict_nonpos\n\nend ExistsSubsetRestrictNonpos\n\n/-- The set of measures of the set of measurable negative sets. -/\ndef measureOfNegatives (s : SignedMeasure \u03b1) : Set \u211d :=\n  s '' { B | MeasurableSet B \u2227 s \u2264[B] 0 }\n#align measure_theory.signed_measure.measure_of_negatives MeasureTheory.SignedMeasure.measureOfNegatives\n\ntheorem zero_mem_measureOfNegatives : (0 : \u211d) \u2208 s.measureOfNegatives :=\n  \u27e8\u2205, \u27e8MeasurableSet.empty, le_restrict_empty _ _\u27e9, s.Empty\u27e9\n#align measure_theory.signed_measure.zero_mem_measure_of_negatives MeasureTheory.SignedMeasure.zero_mem_measureOfNegatives\n\ntheorem bddBelow_measureOfNegatives : BddBelow s.measureOfNegatives :=\n  by\n  simp_rw [BddBelow, Set.Nonempty, mem_lowerBounds]\n  by_contra' h\n  have h' : \u2200 n : \u2115, \u2203 y : \u211d, y \u2208 s.measure_of_negatives \u2227 y < -n := fun n => h (-n)\n  choose f hf using h'\n  have hf' : \u2200 n : \u2115, \u2203 B, MeasurableSet B \u2227 s \u2264[B] 0 \u2227 s B < -n :=\n    by\n    intro n\n    rcases hf n with \u27e8\u27e8B, \u27e8hB\u2081, hBr\u27e9, hB\u2082\u27e9, hlt\u27e9\n    exact \u27e8B, hB\u2081, hBr, hB\u2082.symm \u25b8 hlt\u27e9\n  choose B hmeas hr h_lt using hf'\n  set A := \u22c3 n, B n with hA\n  have hfalse : \u2200 n : \u2115, s A \u2264 -n := by\n    intro n\n    refine' le_trans _ (le_of_lt (h_lt _))\n    rw [hA, \u2190 Set.diff_union_of_subset (Set.subset_union\u1d62 _ n),\n      of_union Set.disjoint_sdiff_left _ (hmeas n)]\n    \u00b7 refine' add_le_of_nonpos_left _\n      have : s \u2264[A] 0 := restrict_le_restrict_Union _ _ hmeas hr\n      refine' nonpos_of_restrict_le_zero _ (restrict_le_zero_subset _ _ (Set.diff_subset _ _) this)\n      exact MeasurableSet.union\u1d62 hmeas\n    \u00b7 infer_instance\n    \u00b7 exact (MeasurableSet.union\u1d62 hmeas).diff\u2093 (hmeas n)\n  rcases exists_nat_gt (-s A) with \u27e8n, hn\u27e9\n  exact lt_irrefl _ ((neg_lt.1 hn).trans_le (hfalse n))\n#align measure_theory.signed_measure.bdd_below_measure_of_negatives MeasureTheory.SignedMeasure.bddBelow_measureOfNegatives\n\n/-- Alternative formulation of `measure_theory.signed_measure.exists_is_compl_positive_negative`\n(the Hahn decomposition theorem) using set complements. -/\ntheorem exists_compl_positive_negative (s : SignedMeasure \u03b1) :\n    \u2203 i : Set \u03b1, MeasurableSet i \u2227 0 \u2264[i] s \u2227 s \u2264[i\u1d9c] 0 :=\n  by\n  obtain \u27e8f, _, hf\u2082, hf\u2081\u27e9 :=\n    exists_seq_tendsto_inf\u209b \u27e80, @zero_mem_measure_of_negatives _ _ s\u27e9 bdd_below_measure_of_negatives\n  choose B hB using hf\u2081\n  have hB\u2081 : \u2200 n, MeasurableSet (B n) := fun n => (hB n).1.1\n  have hB\u2082 : \u2200 n, s \u2264[B n] 0 := fun n => (hB n).1.2\n  set A := \u22c3 n, B n with hA\n  have hA\u2081 : MeasurableSet A := MeasurableSet.union\u1d62 hB\u2081\n  have hA\u2082 : s \u2264[A] 0 := restrict_le_restrict_Union _ _ hB\u2081 hB\u2082\n  have hA\u2083 : s A = Inf s.measure_of_negatives :=\n    by\n    apply le_antisymm\n    \u00b7 refine' le_of_tendsto_of_tendsto tendsto_const_nhds hf\u2082 (eventually_of_forall fun n => _)\n      rw [\u2190 (hB n).2, hA, \u2190 Set.diff_union_of_subset (Set.subset_union\u1d62 _ n),\n        of_union Set.disjoint_sdiff_left _ (hB\u2081 n)]\n      \u00b7 refine' add_le_of_nonpos_left _\n        have : s \u2264[A] 0 :=\n          restrict_le_restrict_Union _ _ hB\u2081 fun m =>\n            let \u27e8_, h\u27e9 := (hB m).1\n            h\n        refine'\n          nonpos_of_restrict_le_zero _ (restrict_le_zero_subset _ _ (Set.diff_subset _ _) this)\n        exact MeasurableSet.union\u1d62 hB\u2081\n      \u00b7 infer_instance\n      \u00b7 exact (MeasurableSet.union\u1d62 hB\u2081).diff\u2093 (hB\u2081 n)\n    \u00b7 exact cinf\u209b_le bdd_below_measure_of_negatives \u27e8A, \u27e8hA\u2081, hA\u2082\u27e9, rfl\u27e9\n  refine' \u27e8A\u1d9c, hA\u2081.compl, _, (compl_compl A).symm \u25b8 hA\u2082\u27e9\n  rw [restrict_le_restrict_iff _ _ hA\u2081.compl]\n  intro C hC hC\u2081\n  by_contra' hC\u2082\n  rcases exists_subset_restrict_nonpos hC\u2082 with \u27e8D, hD\u2081, hD, hD\u2082, hD\u2083\u27e9\n  have : s (A \u222a D) < Inf s.measure_of_negatives :=\n    by\n    rw [\u2190 hA\u2083,\n      of_union (Set.disjoint_of_subset_right (Set.Subset.trans hD hC\u2081) disjoint_compl_right) hA\u2081\n        hD\u2081]\n    linarith\n    infer_instance\n  refine' not_le.2 this _\n  refine' cinf\u209b_le bdd_below_measure_of_negatives \u27e8A \u222a D, \u27e8_, _\u27e9, rfl\u27e9\n  \u00b7 exact hA\u2081.union hD\u2081\n  \u00b7 exact restrict_le_restrict_union _ _ hA\u2081 hA\u2082 hD\u2081 hD\u2082\n#align measure_theory.signed_measure.exists_compl_positive_negative MeasureTheory.SignedMeasure.exists_compl_positive_negative\n\n/-- **The Hahn decomposition thoerem**: Given a signed measure `s`, there exist\ncomplement measurable sets `i` and `j` such that `i` is positive, `j` is negative. -/\ntheorem exists_isCompl_positive_negative (s : SignedMeasure \u03b1) :\n    \u2203 i j : Set \u03b1, MeasurableSet i \u2227 0 \u2264[i] s \u2227 MeasurableSet j \u2227 s \u2264[j] 0 \u2227 IsCompl i j :=\n  let \u27e8i, hi\u2081, hi\u2082, hi\u2083\u27e9 := exists_compl_positive_negative s\n  \u27e8i, i\u1d9c, hi\u2081, hi\u2082, hi\u2081.compl, hi\u2083, isCompl_compl\u27e9\n#align measure_theory.signed_measure.exists_is_compl_positive_negative MeasureTheory.SignedMeasure.exists_isCompl_positive_negative\n\n/-- The symmetric difference of two Hahn decompositions has measure zero. -/\ntheorem of_symmDiff_compl_positive_negative {s : SignedMeasure \u03b1} {i j : Set \u03b1}\n    (hi : MeasurableSet i) (hj : MeasurableSet j) (hi' : 0 \u2264[i] s \u2227 s \u2264[i\u1d9c] 0)\n    (hj' : 0 \u2264[j] s \u2227 s \u2264[j\u1d9c] 0) : s (i \u2206 j) = 0 \u2227 s (i\u1d9c \u2206 j\u1d9c) = 0 :=\n  by\n  rw [restrict_le_restrict_iff s 0, restrict_le_restrict_iff 0 s] at hi' hj'\n  constructor\n  \u00b7 rw [symmDiff_def, Set.diff_eq_compl_inter, Set.diff_eq_compl_inter, Set.sup_eq_union, of_union,\n      le_antisymm (hi'.2 (hi.compl.inter hj) (Set.inter_subset_left _ _))\n        (hj'.1 (hi.compl.inter hj) (Set.inter_subset_right _ _)),\n      le_antisymm (hj'.2 (hj.compl.inter hi) (Set.inter_subset_left _ _))\n        (hi'.1 (hj.compl.inter hi) (Set.inter_subset_right _ _)),\n      zero_apply, zero_apply, zero_add]\n    \u00b7\n      exact\n        Set.disjoint_of_subset_left (Set.inter_subset_left _ _)\n          (Set.disjoint_of_subset_right (Set.inter_subset_right _ _)\n            (disjoint_comm.1 (IsCompl.disjoint isCompl_compl)))\n    \u00b7 exact hj.compl.inter hi\n    \u00b7 exact hi.compl.inter hj\n  \u00b7 rw [symmDiff_def, Set.diff_eq_compl_inter, Set.diff_eq_compl_inter, compl_compl, compl_compl,\n      Set.sup_eq_union, of_union,\n      le_antisymm (hi'.2 (hj.inter hi.compl) (Set.inter_subset_right _ _))\n        (hj'.1 (hj.inter hi.compl) (Set.inter_subset_left _ _)),\n      le_antisymm (hj'.2 (hi.inter hj.compl) (Set.inter_subset_right _ _))\n        (hi'.1 (hi.inter hj.compl) (Set.inter_subset_left _ _)),\n      zero_apply, zero_apply, zero_add]\n    \u00b7\n      exact\n        Set.disjoint_of_subset_left (Set.inter_subset_left _ _)\n          (Set.disjoint_of_subset_right (Set.inter_subset_right _ _)\n            (IsCompl.disjoint isCompl_compl))\n    \u00b7 exact hj.inter hi.compl\n    \u00b7 exact hi.inter hj.compl\n  all_goals measurability\n#align measure_theory.signed_measure.of_symm_diff_compl_positive_negative MeasureTheory.SignedMeasure.of_symmDiff_compl_positive_negative\n\nend SignedMeasure\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Decomposition/SignedHahn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7426917788598025}}
{"text": "import Mathlib.Tactic.LeftRight\nimport Mathlib.Tactic.Basic\nimport Lean.Meta.Tactic.Apply\nimport Lean.Meta.Tactic.Cases\nimport PropositionWorld.Level8 -- not_iff_imp_false\n/-!\n# Advanced proposition world.\n\nYou already know enough to embark on advanced addition world. But here are just a couple\nmore things.\n\n## Level 9: `exfalso` and proof by contradiction.\n\nIt's certainly true that `P \u2227 (\u00ac P) \u27f9 Q` for any propositions `P`\nand `Q`, because the left hand side of the implication is false. But how do\nwe prove that `false` implies any proposition `Q`? A cheap way of doing it in\nLean is using the [`exfalso` tactic](../Tactics/exfalso.lean.md), which changes any goal at all to `false`.\nYou might think this is a step backwards, but if you have a hypothesis `h : \u00ac P`\nthen after `rw not_iff_imp_false at h,` you can `apply h,` to make progress.\n\n## Lemma\nIf `P` and `Q` are true/false statements, then `(P \u2227 (\u00ac P)) \u27f9 Q.`\n-/\nlemma contra (P Q : Prop) : (P \u2227 \u00ac P) \u2192 Q := by\n  intro h\n  cases h with\n  | intro p np =>\n    exfalso\n    apply np\n    assumption\n\n\n/-!\n## Pro tip.\n\n`\u00ac P` is actually `P \u2192 false` *by definition* and since `np: \u00ac P` is a hypothesis,\n`apply q` changes `\u22a2 False` to `\u22a2 P`.  Neat trick.  We started with `\u22a2 Q`, but\ncould not prove it so we jumped to `False` so we could use `np: \u00ac P` to get to\nthe desired goal `\u22a2 P`.\n\nNext up [Level 10](./Level10.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedPropositionWorld/Level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172572644806, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7426819425127843}}
{"text": "import algebra.group_power\n\ntheorem Q3a (n : int) : (3:\u2124) \u2223 n ^ 2 \u2192 (3:\u2124) \u2223 n := sorry\n\ndef exists_sqrt_3 := square_root.exists_unique_square_root 3 (by norm_num) \n\nnoncomputable def sqrt3 := classical.some (exists_sqrt_3)\ndef sqrt3_proof := classical.some_spec (exists_sqrt_3)\n\nexample : sqrt3 ** 2 = 3 := sqrt3_proof.right.left\n\nnoncomputable example : monoid \u211d := by apply_instance\n\ntheorem no_rational_squared_is_three : \u00ac (\u2203 (q:\u211a),q**2=3) := sorry\n\ntheorem Q3b : M1F.is_irrational (sqrt3) := sorry\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1F/problem_bank/0203/Q0203.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582535657921, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7426794707680673}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Eric Wieser\n-/\n\nimport algebra.char_p.basic\nimport ring_theory.ideal.quotient\n\n/-!\n# Characteristic of quotients rings\n-/\n\nuniverses u v\n\nnamespace char_p\n\ntheorem quotient (R : Type u) [comm_ring R] (p : \u2115) [hp1 : fact p.prime] (hp2 : \u2191p \u2208 nonunits R) :\n  char_p (R \u29f8 (ideal.span {p} : ideal R)) p :=\nhave hp0 : (p : R \u29f8 (ideal.span {p} : ideal R)) = 0,\n  from map_nat_cast (ideal.quotient.mk (ideal.span {p} : ideal R)) p \u25b8\n    ideal.quotient.eq_zero_iff_mem.2 (ideal.subset_span $ set.mem_singleton _),\nring_char.of_eq $ or.resolve_left ((nat.dvd_prime hp1.1).1 $ ring_char.dvd hp0) $ \u03bb h1,\nhp2 $ is_unit_iff_dvd_one.2 $ ideal.mem_span_singleton.1 $ ideal.quotient.eq_zero_iff_mem.1 $\n@@subsingleton.elim (@@char_p.subsingleton _ $ ring_char.of_eq h1) _ _\n\n/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient\ninherits the characteristic of the underlying ring. -/\nlemma quotient' {R : Type*} [comm_ring R] (p : \u2115) [char_p R p] (I : ideal R)\n  (h : \u2200 x : \u2115, (x : R) \u2208 I \u2192 (x : R) = 0) :\n  char_p (R \u29f8 I) p :=\n\u27e8\u03bb x, begin\n  rw [\u2190cast_eq_zero_iff R p x, \u2190map_nat_cast (ideal.quotient.mk I)],\n  refine ideal.quotient.eq.trans (_ : \u2191x - 0 \u2208 I \u2194 _),\n  rw sub_zero,\n  exact \u27e8h x, \u03bb h', h'.symm \u25b8 I.zero_mem\u27e9,\nend\u27e9\n\nend char_p\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/char_p/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7426786907400823}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport tactic\n\n/-!\n# Conjuntos\n-/\n\n/- Definimos un tipo `\u03a9` y tres conjuntos `X`, `Y`, `Z` cuyos elementos son de tipo `\u03a9`.\n  Para nuestro modelo mental, podemos pensar que estamos definiendo un conjunto `\u03a9` y tres \n  subconjuntos `X`, `Y`, `Z` del mismo.\n  Definimos tambi\u00e9n elementos `a, b, c, x, y, z` de `\u03a9`.\n -/\nvariables (\u03a9 : Type) (X Y Z : set \u03a9) (a b c x y z : \u03a9)\n\n-- Abrimos un `namespace` para evitar conflictos con los nombres.\nnamespace conjuntos\n\n/-!\n\n# Subconjuntos\n\nEl s\u00edmbolo `\u2286` se escribe mediante `\\sub` o `\\ss`\n-/\n\n-- `X \u2286 Y` significa `\u2200 a, a \u2208 X \u2192 a \u2208 Y`, por definici\u00f3n.\n\nlemma subset_def : X \u2286 Y \u2194 \u2200 a, a \u2208 X \u2192 a \u2208 Y :=\nbegin\n  refl -- por definici\u00f3n\nend\n\nlemma subset_refl : X \u2286 X :=\nbegin\n  sorry,\nend\n\n/- En este lema, tras empezar con `rw subset_def at *`, la hip\u00f3tesis `hYZ` se transforma en\n`hYZ : \u2200 (a : \u03a9), a \u2208 Y \u2192 a \u2208 Z` (y similarmente para `hXY`).\nComo `hYZ` es una implicaci\u00f3n, una vez reducimos la meta a `a \u2208 Z`, podemos avanzar en la \ndemostraci\u00f3n utilizando `apply hYZ`.\nFrecuentemente, tambi\u00e9n es \u00fatil pensar en `hYZ` como una funci\u00f3n, que dados un t\u00e9rmino `a` de\ntipo `\u03a9` y una demostraci\u00f3n `haY` de que `a \u2208 Y`, devuelve una demostraci\u00f3n `haZ` de `a \u2208 Z`.\n-/\nlemma subset_trans (hXY : X \u2286 Y) (hYZ : Y \u2286 Z) : X \u2286 Z :=\nbegin\n  rw subset_def at *,\n  sorry\nend\n\n/-!\n\n# Igualdad de conjuntos\nDos conjuntos son iguales si y s\u00f3lo si tienen los mismos elementos.\nEn Lean, el nombre de este lema es `set.ext_iff`.\n-/\n\nexample : X = Y \u2194 (\u2200 a, a \u2208 X \u2194 a \u2208 Y) :=\nbegin\n  exact set.ext_iff\nend\n\n/- Cuando queremos reducir la meta `\u22a2 X = Y` a demostrar `a \u2208 X \u2194 a \u2208 Y` para `a : \u03a9`\n  arbitrario, utilizamos la t\u00e1ctica `ext`. -/\n\nlemma subset.antisymm (hXY : X \u2286 Y) (hYX : Y \u2286 X) : X = Y :=\nbegin\n  ext a,\n  sorry\nend\n\n/-!\n\n### Uniones e intersecciones\n\nNotaci\u00f3n: `\\cup` o `\\un` para obtener `\u222a`, y `\\cap` o `\\i` para `\u2229`\n\n-/\n\nlemma union_def : a \u2208 X \u222a Y \u2194 a \u2208 X \u2228 a \u2208 Y :=\nbegin\n  refl,\nend\n\nlemma inter_def : a \u2208 X \u2229 Y \u2194 a \u2208 X \u2227 a \u2208 Y :=\nbegin\n  refl,\nend\n\n/- Uniones. -/\n\nlemma union_self : X \u222a X = X :=\nbegin\n  sorry\nend\n\nlemma subset_union_left : X \u2286 X \u222a Y :=\nbegin\n  sorry\nend\n\nlemma subset_union_right : Y \u2286 X \u222a Y :=\nbegin\n  sorry\nend\n\nlemma union_subset_iff : X \u222a Y \u2286 Z \u2194 X \u2286 Z \u2227 Y \u2286 Z :=\nbegin\n  sorry\nend\n\nvariable (W : set \u03a9)\n\nlemma union_subset_union (hWX : W \u2286 X) (hYZ : Y \u2286 Z) : W \u222a Y \u2286 X \u222a Z :=\nbegin\n  sorry\nend\n\nlemma union_subset_union_left (hXY : X \u2286 Y) : X \u222a Z \u2286 Y \u222a Z :=\nbegin\n  sorry\nend\n\n/- Intersecciones -/\n\nlemma inter_subset_left : X \u2229 Y \u2286 X :=\nbegin\n  sorry\nend\n\nlemma inter_self : X \u2229 X = X :=\nbegin\n  sorry\nend\n\nlemma inter_comm : X \u2229 Y = Y \u2229 X :=\nbegin\n  sorry\nend\n\nlemma inter_assoc : X \u2229 (Y \u2229 Z) = (X \u2229 Y) \u2229 Z :=\nbegin\n  sorry\nend\n\n/-!\n\n### Para todo y existe\n\n-/\n\nlemma not_exists_iff_forall_not : \u00ac (\u2203 a, a \u2208 X) \u2194 \u2200 b, \u00ac (b \u2208 X) :=\nbegin\n  sorry,\nend\n\nexample : \u00ac (\u2200 a, a \u2208 X) \u2194 \u2203 b, \u00ac (b \u2208 X) :=\nbegin\n  sorry,\nend\n\nend conjuntos", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_2/conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7426786641228778}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n-/\nimport order.bounds\nimport data.set.intervals.image_preimage\n\n/-!\n# Intervals without endpoints ordering\n\nIn any decidable linear order `\u03b1`, we define the set of elements lying between two elements `a` and\n`b` as `Icc (min a b) (max a b)`.\n\n`Icc a b` requires the assumption `a \u2264 b` to be meaningful, which is sometimes inconvenient. The\ninterval as defined in this file is always the set of things lying between `a` and `b`, regardless\nof the relative order of `a` and `b`.\n\nFor real numbers, `Icc (min a b) (max a b)` is the same as `segment a b`.\n\n## Notation\n\nWe use the localized notation `[a, b]` for `interval a b`. One can open the locale `interval` to\nmake the notation available.\n\n-/\n\nuniverse u\n\nnamespace set\n\nsection linear_order\n\nvariables {\u03b1 : Type u} [linear_order \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 x : \u03b1}\n\n/-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/\ndef interval (a b : \u03b1) := Icc (min a b) (max a b)\n\nlocalized \"notation `[`a `, ` b `]` := interval a b\" in interval\n\n@[simp] lemma interval_of_le (h : a \u2264 b) : [a, b] = Icc a b :=\nby rw [interval, min_eq_left h, max_eq_right h]\n\n@[simp] lemma interval_of_ge (h : b \u2264 a) : [a, b] = Icc b a :=\nby { rw [interval, min_eq_right h, max_eq_left h] }\n\nlemma interval_swap (a b : \u03b1) : [a, b] = [b, a] :=\nor.elim (le_total a b) (by simp {contextual := tt}) (by simp {contextual := tt})\n\nlemma interval_of_lt (h : a < b) : [a, b] = Icc a b :=\ninterval_of_le (le_of_lt h)\n\nlemma interval_of_gt (h : b < a) : [a, b] = Icc b a :=\ninterval_of_ge (le_of_lt h)\n\nlemma interval_of_not_le (h : \u00ac a \u2264 b) : [a, b] = Icc b a :=\ninterval_of_gt (lt_of_not_ge h)\n\nlemma interval_of_not_ge (h : \u00ac b \u2264 a) : [a, b] = Icc a b :=\ninterval_of_lt (lt_of_not_ge h)\n\n@[simp] lemma interval_self : [a, a] = {a} :=\nset.ext $ by simp [le_antisymm_iff, and_comm]\n\n@[simp] lemma nonempty_interval : set.nonempty [a, b] :=\nby { simp only [interval, min_le_iff, le_max_iff, nonempty_Icc], left, left, refl }\n\n@[simp] lemma left_mem_interval : a \u2208 [a, b] :=\nby { rw [interval, mem_Icc], exact \u27e8min_le_left _ _, le_max_left _ _\u27e9 }\n\n@[simp] lemma right_mem_interval : b \u2208 [a, b] :=\nby { rw interval_swap, exact left_mem_interval }\n\nlemma Icc_subset_interval : Icc a b \u2286 [a, b] :=\nby { assume x h, rwa interval_of_le, exact le_trans h.1 h.2 }\n\nlemma Icc_subset_interval' : Icc b a \u2286 [a, b] :=\nby { rw interval_swap, apply Icc_subset_interval }\n\nlemma mem_interval_of_le (ha : a \u2264 x) (hb : x \u2264 b) : x \u2208 [a, b] :=\nIcc_subset_interval \u27e8ha, hb\u27e9\n\nlemma mem_interval_of_ge (hb : b \u2264 x) (ha : x \u2264 a) : x \u2208 [a, b] :=\nIcc_subset_interval' \u27e8hb, ha\u27e9\n\nlemma not_mem_interval_of_lt {c : \u03b1} (ha : c < a) (hb : c < b) : c \u2209 interval a b :=\nnot_mem_Icc_of_lt $ lt_min_iff.mpr \u27e8ha, hb\u27e9\n\nlemma not_mem_interval_of_gt {c : \u03b1} (ha : a < c) (hb : b < c) : c \u2209 interval a b :=\nnot_mem_Icc_of_gt $ max_lt_iff.mpr \u27e8ha, hb\u27e9\n\nlemma interval_subset_interval (h\u2081 : a\u2081 \u2208 [a\u2082, b\u2082]) (h\u2082 : b\u2081 \u2208 [a\u2082, b\u2082]) : [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] :=\nIcc_subset_Icc (le_min h\u2081.1 h\u2082.1) (max_le h\u2081.2 h\u2082.2)\n\nlemma interval_subset_interval_iff_mem : [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] \u2194 a\u2081 \u2208 [a\u2082, b\u2082] \u2227 b\u2081 \u2208 [a\u2082, b\u2082] :=\niff.intro (\u03bbh, \u27e8h left_mem_interval, h right_mem_interval\u27e9) (\u03bb h, interval_subset_interval h.1 h.2)\n\nlemma interval_subset_interval_iff_le :\n  [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] \u2194 min a\u2082 b\u2082 \u2264 min a\u2081 b\u2081 \u2227 max a\u2081 b\u2081 \u2264 max a\u2082 b\u2082 :=\nby { rw [interval, interval, Icc_subset_Icc_iff], exact min_le_max }\n\nlemma interval_subset_interval_right (h : x \u2208 [a, b]) : [x, b] \u2286 [a, b] :=\ninterval_subset_interval h right_mem_interval\n\nlemma interval_subset_interval_left (h : x \u2208 [a, b]) : [a, x] \u2286 [a, b] :=\ninterval_subset_interval left_mem_interval h\n\nlemma bdd_below_bdd_above_iff_subset_interval (s : set \u03b1) :\n  bdd_below s \u2227 bdd_above s \u2194 \u2203 a b, s \u2286 [a, b] :=\nbegin\n  rw [bdd_below_bdd_above_iff_subset_Icc],\n  split,\n  { rintro \u27e8a, b, h\u27e9, exact \u27e8a, b, \u03bb x hx, Icc_subset_interval (h hx)\u27e9 },\n  { rintro \u27e8a, b, h\u27e9, exact \u27e8min a b, max a b, h\u27e9 }\nend\n\nend linear_order\n\nopen_locale interval\n\nsection ordered_add_comm_group\n\nvariables {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a b c x y : \u03b1)\n\n@[simp] lemma preimage_const_add_interval : (\u03bb x, a + x) \u207b\u00b9' [b, c] = [b - a, c - a] :=\nby simp only [interval, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right]\n\n@[simp] lemma preimage_add_const_interval : (\u03bb x, x + a) \u207b\u00b9' [b, c] = [b - a, c - a] :=\nby simpa only [add_comm] using preimage_const_add_interval a b c\n\n@[simp] lemma preimage_neg_interval : -([a, b]) = [-a, -b] :=\nby simp only [interval, preimage_neg_Icc, min_neg_neg, max_neg_neg]\n\n@[simp] lemma preimage_sub_const_interval : (\u03bb x, x - a) \u207b\u00b9' [b, c] = [b + a, c + a] :=\nby simp [sub_eq_add_neg]\n\n@[simp] lemma preimage_const_sub_interval : (\u03bb x, a - x) \u207b\u00b9' [b, c] = [a - b, a - c] :=\nby { rw [interval, interval, preimage_const_sub_Icc],\n  simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg], }\n\n@[simp] lemma image_const_add_interval : (\u03bb x, a + x) '' [b, c] = [a + b, a + c] :=\nby simp [add_comm]\n\n@[simp] lemma image_add_const_interval : (\u03bb x, x + a) '' [b, c] = [b + a, c + a] :=\nby simp\n\n@[simp] lemma image_const_sub_interval : (\u03bb x, a - x) '' [b, c] = [a - b, a - c] :=\nby simp [sub_eq_add_neg, image_comp (\u03bb x, a + x) (\u03bb x, -x)]\n\n@[simp] lemma image_sub_const_interval : (\u03bb x, x - a) '' [b, c] = [b - a, c - a] :=\nby simp [sub_eq_add_neg, add_comm]\n\nlemma image_neg_interval : has_neg.neg '' [a, b] = [-a, -b] := by simp\n\nvariables {a b c x y}\n\n/-- If `[x, y]` is a subinterval of `[a, b]`, then the distance between `x` and `y`\nis less than or equal to that of `a` and `b` -/\nlemma abs_sub_le_of_subinterval (h : [x, y] \u2286 [a, b]) : abs (y - x) \u2264 abs (b - a) :=\nbegin\n  rw [\u2190 max_sub_min_eq_abs, \u2190 max_sub_min_eq_abs],\n  rw [interval_subset_interval_iff_le] at h,\n  exact sub_le_sub h.2 h.1,\nend\n\n/-- If `x \u2208 [a, b]`, then the distance between `a` and `x` is less than or equal to\nthat of `a` and `b`  -/\nlemma abs_sub_left_of_mem_interval (h : x \u2208 [a, b]) : abs (x - a) \u2264 abs (b - a) :=\nabs_sub_le_of_subinterval (interval_subset_interval_left h)\n\n/-- If `x \u2208 [a, b]`, then the distance between `x` and `b` is less than or equal to\nthat of `a` and `b`  -/\nlemma abs_sub_right_of_mem_interval (h : x \u2208 [a, b]) : abs (b - x) \u2264 abs (b - a) :=\nabs_sub_le_of_subinterval (interval_subset_interval_right h)\n\nend ordered_add_comm_group\n\nsection linear_ordered_field\n\nvariables {k : Type u} [linear_ordered_field k] {a : k}\n\n@[simp] lemma preimage_mul_const_interval (ha : a \u2260 0) (b c : k) :\n  (\u03bb x, x * a) \u207b\u00b9' [b, c] = [b / a, c / a] :=\n(lt_or_gt_of_ne ha).elim\n  (\u03bb ha, by simp [interval, ha, ha.le, min_div_div_right_of_nonpos, max_div_div_right_of_nonpos])\n  (\u03bb (ha : 0 < a), by simp [interval, ha, ha.le, min_div_div_right, max_div_div_right])\n\n@[simp] lemma preimage_const_mul_interval (ha : a \u2260 0) (b c : k) :\n  (\u03bb x, a * x) \u207b\u00b9' [b, c] = [b / a, c / a] :=\nby simp only [\u2190 preimage_mul_const_interval ha, mul_comm]\n\n@[simp] lemma preimage_div_const_interval (ha : a \u2260 0) (b c : k) :\n  (\u03bb x, x / a) \u207b\u00b9' [b, c] = [b * a, c * a] :=\nby simp only [div_eq_mul_inv, preimage_mul_const_interval (inv_ne_zero ha), inv_inv']\n\n@[simp] lemma image_mul_const_interval (a b c : k) : (\u03bb x, x * a) '' [b, c] = [b * a, c * a] :=\nif ha : a = 0 then by simp [ha] else\ncalc (\u03bb x, x * a) '' [b, c] = (\u03bb x, x * a\u207b\u00b9) \u207b\u00b9' [b, c] :\n  (units.mk0 a ha).mul_right.image_eq_preimage _\n... = (\u03bb x, x / a) \u207b\u00b9' [b, c] : by simp only [div_eq_mul_inv]\n... = [b * a, c * a] : preimage_div_const_interval ha _ _\n\n@[simp] lemma image_const_mul_interval (a b c : k) : (\u03bb x, a * x) '' [b, c] = [a * b, a * c] :=\nby simpa only [mul_comm] using image_mul_const_interval a b c\n\n@[simp] lemma image_div_const_interval (a b c : k) : (\u03bb x, x / a) '' [b, c] = [b / a, c / a] :=\nby simp only [div_eq_mul_inv, image_mul_const_interval]\n\nend linear_ordered_field\n\nend set\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/set/intervals/unordered_interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198947, "lm_q2_score": 0.8757869981319863, "lm_q1q2_score": 0.7426391409872596}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport data.set.basic\n\n/-!\n# Circular order hierarchy\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines circular preorders, circular partial orders and circular orders.\n\n## Hierarchy\n\n* A ternary \"betweenness\" relation `btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` forms a `circular_order` if it is\n  - reflexive: `btw a a a`\n  - cyclic: `btw a b c \u2192 btw b c a`\n  - antisymmetric: `btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a`\n  - total: `btw a b c \u2228 btw c b a`\n  along with a strict betweenness relation `sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` which respects\n  `sbtw a b c \u2194 btw a b c \u2227 \u00ac btw c b a`, analogously to how `<` and `\u2264` are related, and is\n  - transitive: `sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c`.\n* A `circular_partial_order` drops totality.\n* A `circular_preorder` further drops antisymmetry.\n\nThe intuition is that a circular order is a circle and `btw a b c` means that going around\nclockwise from `a` you reach `b` before `c` (`b` is between `a` and `c` is meaningless on an\nunoriented circle). A circular partial order is several, potentially intersecting, circles. A\ncircular preorder is like a circular partial order, but several points can coexist.\n\nNote that the relations between `circular_preorder`, `circular_partial_order` and `circular_order`\nare subtler than between `preorder`, `partial_order`, `linear_order`. In particular, one cannot\nsimply extend the `btw` of a `circular_partial_order` to make it a `circular_order`.\n\nOne can translate from usual orders to circular ones by \"closing the necklace at infinity\". See\n`has_le.to_has_btw` and `has_lt.to_has_sbtw`. Going the other way involves \"cutting the necklace\" or\n\"rolling the necklace open\".\n\n## Examples\n\nSome concrete circular orders one encounters in the wild are `zmod n` for `0 < n`, `circle`,\n`real.angle`...\n\n## Main definitions\n\n* `set.cIcc`: Closed-closed circular interval.\n* `set.cIoo`: Open-open circular interval.\n\n## Notes\n\nThere's an unsolved diamond on `order_dual \u03b1` here. The instances `has_le \u03b1 \u2192 has_btw \u03b1\u1d52\u1d48` and\n`has_lt \u03b1 \u2192 has_sbtw \u03b1\u1d52\u1d48` can each be inferred in two ways:\n* `has_le \u03b1` \u2192 `has_btw \u03b1` \u2192 `has_btw \u03b1\u1d52\u1d48` vs\n  `has_le \u03b1` \u2192 `has_le \u03b1\u1d52\u1d48` \u2192 `has_btw \u03b1\u1d52\u1d48`\n* `has_lt \u03b1` \u2192 `has_sbtw \u03b1` \u2192 `has_sbtw \u03b1\u1d52\u1d48` vs\n  `has_lt \u03b1` \u2192 `has_lt \u03b1\u1d52\u1d48` \u2192 `has_sbtw \u03b1\u1d52\u1d48`\nThe fields are propeq, but not defeq. It is temporarily fixed by turning the circularizing instances\ninto definitions.\n\n## TODO\n\nAntisymmetry is quite weak in the sense that there's no way to discriminate which two points are\nequal. This prevents defining closed-open intervals `cIco` and `cIoc` in the neat `=`-less way. We\ncurrently haven't defined them at all.\n\nWhat is the correct generality of \"rolling the necklace\" open? At least, this works for `\u03b1 \u00d7 \u03b2` and\n`\u03b2 \u00d7 \u03b1` where `\u03b1` is a circular order and `\u03b2` is a linear order.\n\nWhat's next is to define circular groups and provide instances for `zmod n`, the usual circle group\n`circle`, `real.angle`, and `roots_of_unity M`. What conditions do we need on `M` for this last one\nto work?\n\nWe should have circular order homomorphisms. The typical example is\n`days_to_month : days_of_the_year \u2192c months_of_the_year` which relates the circular order of days\nand the circular order of months. Is `\u03b1 \u2192c \u03b2` a good notation?\n\n## References\n\n* https://en.wikipedia.org/wiki/Cyclic_order\n* https://en.wikipedia.org/wiki/Partial_cyclic_order\n\n## Tags\n\ncircular order, cyclic order, circularly ordered set, cyclically ordered set\n-/\n\n/-- Syntax typeclass for a betweenness relation. -/\nclass has_btw (\u03b1 : Type*) :=\n(btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop)\n\nexport has_btw (btw)\n\n/-- Syntax typeclass for a strict betweenness relation. -/\nclass has_sbtw (\u03b1 : Type*) :=\n(sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop)\n\nexport has_sbtw (sbtw)\n\n/-- A circular preorder is the analogue of a preorder where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive and cyclic. `sbtw` is transitive.\n-/\nclass circular_preorder (\u03b1 : Type*) extends has_btw \u03b1, has_sbtw \u03b1 :=\n(btw_refl (a : \u03b1) : btw a a a)\n(btw_cyclic_left {a b c : \u03b1} : btw a b c \u2192 btw b c a)\n(sbtw := \u03bb a b c, btw a b c \u2227 \u00acbtw c b a)\n(sbtw_iff_btw_not_btw {a b c : \u03b1} : sbtw a b c \u2194 (btw a b c \u2227 \u00acbtw c b a) . order_laws_tac)\n(sbtw_trans_left {a b c d : \u03b1} : sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c)\n\nexport circular_preorder (btw_refl) (btw_cyclic_left) (sbtw_trans_left)\n\n/-- A circular partial order is the analogue of a partial order where you can loop around. `\u2264` and\n`<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic and\nantisymmetric. `sbtw` is transitive. -/\nclass circular_partial_order (\u03b1 : Type*) extends circular_preorder \u03b1 :=\n(btw_antisymm {a b c : \u03b1} : btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a)\n\nexport circular_partial_order (btw_antisymm)\n\n/-- A circular order is the analogue of a linear order where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic, antisymmetric and total.\n`sbtw` is transitive. -/\nclass circular_order (\u03b1 : Type*) extends circular_partial_order \u03b1 :=\n(btw_total : \u2200 a b c : \u03b1, btw a b c \u2228 btw c b a)\n\nexport circular_order (btw_total)\n\n/-! ### Circular preorders -/\n\nsection circular_preorder\nvariables {\u03b1 : Type*} [circular_preorder \u03b1]\n\nlemma btw_rfl {a : \u03b1} : btw a a a :=\nbtw_refl _\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_cyclic_left        \u2190 has_btw.btw.cyclic_left\nlemma has_btw.btw.cyclic_left {a b c : \u03b1} (h : btw a b c) : btw b c a :=\nbtw_cyclic_left h\n\nlemma btw_cyclic_right {a b c : \u03b1} (h : btw a b c) : btw c a b :=\nh.cyclic_left.cyclic_left\n\nalias btw_cyclic_right \u2190 has_btw.btw.cyclic_right\n\n/-- The order of the `\u2194` has been chosen so that `rw btw_cyclic` cycles to the right while\n`rw \u2190btw_cyclic` cycles to the left (thus following the prepended arrow). -/\nlemma btw_cyclic {a b c : \u03b1} : btw a b c \u2194 btw c a b :=\n\u27e8btw_cyclic_right, btw_cyclic_left\u27e9\n\nlemma sbtw_iff_btw_not_btw {a b c : \u03b1} : sbtw a b c \u2194 btw a b c \u2227 \u00acbtw c b a :=\ncircular_preorder.sbtw_iff_btw_not_btw\n\nlemma btw_of_sbtw {a b c : \u03b1} (h : sbtw a b c) : btw a b c :=\n(sbtw_iff_btw_not_btw.1 h).1\n\nalias btw_of_sbtw \u2190 has_sbtw.sbtw.btw\n\nlemma not_btw_of_sbtw {a b c : \u03b1} (h : sbtw a b c) : \u00acbtw c b a :=\n(sbtw_iff_btw_not_btw.1 h).2\n\nalias not_btw_of_sbtw \u2190 has_sbtw.sbtw.not_btw\n\nlemma not_sbtw_of_btw {a b c : \u03b1} (h : btw a b c) : \u00acsbtw c b a :=\n\u03bb h', h'.not_btw h\n\nalias not_sbtw_of_btw \u2190 has_btw.btw.not_sbtw\n\nlemma sbtw_of_btw_not_btw {a b c : \u03b1} (habc : btw a b c) (hcba : \u00acbtw c b a) : sbtw a b c :=\nsbtw_iff_btw_not_btw.2 \u27e8habc, hcba\u27e9\n\nalias sbtw_of_btw_not_btw \u2190 has_btw.btw.sbtw_of_not_btw\n\nlemma sbtw_cyclic_left {a b c : \u03b1} (h : sbtw a b c) : sbtw b c a :=\nh.btw.cyclic_left.sbtw_of_not_btw (\u03bb h', h.not_btw h'.cyclic_left)\n\nalias sbtw_cyclic_left \u2190 has_sbtw.sbtw.cyclic_left\n\nlemma sbtw_cyclic_right {a b c : \u03b1} (h : sbtw a b c) : sbtw c a b :=\nh.cyclic_left.cyclic_left\n\nalias sbtw_cyclic_right \u2190 has_sbtw.sbtw.cyclic_right\n\n/-- The order of the `\u2194` has been chosen so that `rw sbtw_cyclic` cycles to the right while\n`rw \u2190sbtw_cyclic` cycles to the left (thus following the prepended arrow). -/\nlemma sbtw_cyclic {a b c : \u03b1} : sbtw a b c \u2194 sbtw c a b :=\n\u27e8sbtw_cyclic_right, sbtw_cyclic_left\u27e9\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_trans_left        \u2190 has_btw.btw.trans_left\nlemma has_sbtw.sbtw.trans_left {a b c d : \u03b1} (h : sbtw a b c) : sbtw b d c \u2192 sbtw a d c :=\nsbtw_trans_left h\n\nlemma sbtw_trans_right {a b c d : \u03b1} (hbc : sbtw a b c) (hcd : sbtw a c d) : sbtw a b d :=\n(hbc.cyclic_left.trans_left hcd.cyclic_left).cyclic_right\n\nalias sbtw_trans_right \u2190 has_sbtw.sbtw.trans_right\n\nlemma sbtw_asymm {a b c : \u03b1} (h : sbtw a b c) : \u00ac sbtw c b a :=\nh.btw.not_sbtw\n\nalias sbtw_asymm \u2190 has_sbtw.sbtw.not_sbtw\n\nlemma sbtw_irrefl_left_right {a b : \u03b1} : \u00ac sbtw a b a := \u03bb h, h.not_btw h.btw\nlemma sbtw_irrefl_left {a b : \u03b1} : \u00ac sbtw a a b := \u03bb h, sbtw_irrefl_left_right h.cyclic_left\nlemma sbtw_irrefl_right {a b : \u03b1} : \u00ac sbtw a b b := \u03bb h, sbtw_irrefl_left_right h.cyclic_right\nlemma sbtw_irrefl (a : \u03b1) : \u00ac sbtw a a a := sbtw_irrefl_left_right\n\nend circular_preorder\n\n/-! ### Circular partial orders -/\n\nsection circular_partial_order\nvariables {\u03b1 : Type*} [circular_partial_order \u03b1]\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_antisymm        \u2190 has_btw.btw.antisymm\nlemma has_btw.btw.antisymm {a b c : \u03b1} (h : btw a b c) : btw c b a \u2192 a = b \u2228 b = c \u2228 c = a :=\nbtw_antisymm h\n\nend circular_partial_order\n\n/-! ### Circular orders -/\n\nsection circular_order\nvariables {\u03b1 : Type*} [circular_order \u03b1]\n\nlemma btw_refl_left_right (a b : \u03b1) : btw a b a :=\n(or_self _).1 (btw_total a b a)\n\nlemma btw_rfl_left_right {a b : \u03b1} : btw a b a :=\nbtw_refl_left_right _ _\n\nlemma btw_refl_left (a b : \u03b1) : btw a a b :=\nbtw_rfl_left_right.cyclic_right\n\nlemma btw_rfl_left {a b : \u03b1} : btw a a b :=\nbtw_refl_left _ _\n\nlemma btw_refl_right (a b : \u03b1) : btw a b b :=\nbtw_rfl_left_right.cyclic_left\n\nlemma btw_rfl_right {a b : \u03b1} : btw a b b :=\nbtw_refl_right _ _\n\nlemma sbtw_iff_not_btw {a b c : \u03b1} : sbtw a b c \u2194 \u00ac btw c b a :=\nbegin\n  rw sbtw_iff_btw_not_btw,\n  exact and_iff_right_of_imp (btw_total _ _ _).resolve_left,\nend\n\nlemma btw_iff_not_sbtw {a b c : \u03b1} : btw a b c \u2194 \u00ac sbtw c b a :=\niff_not_comm.1 sbtw_iff_not_btw\n\nend circular_order\n\n/-! ### Circular intervals -/\n\nnamespace set\n\nsection circular_preorder\nvariables {\u03b1 : Type*} [circular_preorder \u03b1]\n\n/-- Closed-closed circular interval -/\ndef cIcc (a b : \u03b1) : set \u03b1 := {x | btw a x b}\n\n/-- Open-open circular interval -/\ndef cIoo (a b : \u03b1) : set \u03b1 := {x | sbtw a x b}\n\n@[simp] lemma mem_cIcc {a b x : \u03b1} : x \u2208 cIcc a b \u2194 btw a x b := iff.rfl\n@[simp] lemma mem_cIoo {a b x : \u03b1} : x \u2208 cIoo a b \u2194 sbtw a x b := iff.rfl\n\nend circular_preorder\n\nsection circular_order\nvariables {\u03b1 : Type*} [circular_order \u03b1]\n\nlemma left_mem_cIcc (a b : \u03b1) : a \u2208 cIcc a b := btw_rfl_left\nlemma right_mem_cIcc (a b : \u03b1) : b \u2208 cIcc a b := btw_rfl_right\n\nlemma compl_cIcc {a b : \u03b1} : (cIcc a b)\u1d9c = cIoo b a :=\nbegin\n  ext,\n  rw [set.mem_cIoo, sbtw_iff_not_btw],\n  refl,\nend\n\nlemma compl_cIoo {a b : \u03b1} : (cIoo a b)\u1d9c = cIcc b a :=\nbegin\n  ext,\n  rw [set.mem_cIcc, btw_iff_not_sbtw],\n  refl,\nend\n\nend circular_order\nend set\n\n/-! ### Circularizing instances -/\n\n/-- The betweenness relation obtained from \"looping around\" `\u2264`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef has_le.to_has_btw (\u03b1 : Type*) [has_le \u03b1] : has_btw \u03b1 :=\n{ btw := \u03bb a b c, (a \u2264 b \u2227 b \u2264 c) \u2228 (b \u2264 c \u2227 c \u2264 a) \u2228 (c \u2264 a \u2227 a \u2264 b) }\n\n/-- The strict betweenness relation obtained from \"looping around\" `<`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef has_lt.to_has_sbtw (\u03b1 : Type*) [has_lt \u03b1] : has_sbtw \u03b1 :=\n{ sbtw := \u03bb a b c, (a < b \u2227 b < c) \u2228 (b < c \u2227 c < a) \u2228 (c < a \u2227 a < b) }\n\n/-- The circular preorder obtained from \"looping around\" a preorder.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef preorder.to_circular_preorder (\u03b1 : Type*) [preorder \u03b1] : circular_preorder \u03b1 :=\n{ btw := \u03bb a b c, (a \u2264 b \u2227 b \u2264 c) \u2228 (b \u2264 c \u2227 c \u2264 a) \u2228 (c \u2264 a \u2227 a \u2264 b),\n  sbtw := \u03bb a b c, (a < b \u2227 b < c) \u2228 (b < c \u2227 c < a) \u2228 (c < a \u2227 a < b),\n  btw_refl := \u03bb a, or.inl \u27e8le_rfl, le_rfl\u27e9,\n  btw_cyclic_left := \u03bb a b c h, begin\n    unfold btw at \u22a2 h,\n    rwa [\u2190or.assoc, or_comm],\n  end,\n  sbtw_trans_left := \u03bb a b c d, begin\n    rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hbd, hdc\u27e9 | \u27e8hdc, hcb\u27e9 | \u27e8hcb, hbd\u27e9),\n    { exact or.inl \u27e8hab.trans hbd, hdc\u27e9 },\n    { exact (hbc.not_lt hcb).elim },\n    { exact (hbc.not_lt hcb).elim },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact (hbc.not_lt hcb).elim },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact or.inr (or.inr \u27e8hca, hab.trans hbd\u27e9) }\n  end,\n  sbtw_iff_btw_not_btw := \u03bb a b c, begin\n    simp_rw lt_iff_le_not_le,\n    set x\u2080 := a \u2264 b,\n    set x\u2081 := b \u2264 c,\n    set x\u2082 := c \u2264 a,\n    have : x\u2080 \u2192 x\u2081 \u2192 a \u2264 c := le_trans,\n    have : x\u2081 \u2192 x\u2082 \u2192 b \u2264 a := le_trans,\n    have : x\u2082 \u2192 x\u2080 \u2192 c \u2264 b := le_trans,\n    clear_value x\u2080 x\u2081 x\u2082,\n    tauto!,\n  end }\n\n/-- The circular partial order obtained from \"looping around\" a partial order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef partial_order.to_circular_partial_order (\u03b1 : Type*) [partial_order \u03b1] :\n  circular_partial_order \u03b1 :=\n{ btw_antisymm := \u03bb a b c, begin\n    rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hcb, hba\u27e9 | \u27e8hba, hac\u27e9 | \u27e8hac, hcb\u27e9),\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inr (or.inl $ hbc.antisymm hcb) },\n    { exact or.inr (or.inl $ hbc.antisymm hcb) },\n    { exact or.inr (or.inr $ hca.antisymm hac) },\n    { exact or.inr (or.inl $ hbc.antisymm hcb) },\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inr (or.inr $ hca.antisymm hac) }\n  end,\n  .. preorder.to_circular_preorder \u03b1 }\n\n/-- The circular order obtained from \"looping around\" a linear order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef linear_order.to_circular_order (\u03b1 : Type*) [linear_order \u03b1] :\n  circular_order \u03b1 :=\n{ btw_total := \u03bb a b c, begin\n    cases le_total a b with hab hba; cases le_total b c with hbc hcb;\n      cases le_total c a with hca hac,\n    { exact or.inl (or.inl \u27e8hab, hbc\u27e9) },\n    { exact or.inl (or.inl \u27e8hab, hbc\u27e9) },\n    { exact or.inl (or.inr $ or.inr \u27e8hca, hab\u27e9) },\n    { exact or.inr (or.inr $ or.inr \u27e8hac, hcb\u27e9) },\n    { exact or.inl (or.inr $ or.inl \u27e8hbc, hca\u27e9) },\n    { exact or.inr (or.inr $ or.inl \u27e8hba, hac\u27e9) },\n    { exact or.inr (or.inl \u27e8hcb, hba\u27e9) },\n    { exact or.inr (or.inr $ or.inl \u27e8hba, hac\u27e9) }\n  end,\n  .. partial_order.to_circular_partial_order \u03b1 }\n\n/-! ### Dual constructions -/\n\nsection order_dual\n\ninstance (\u03b1 : Type*) [has_btw \u03b1] : has_btw \u03b1\u1d52\u1d48 := \u27e8\u03bb a b c : \u03b1, btw c b a\u27e9\ninstance (\u03b1 : Type*) [has_sbtw \u03b1] : has_sbtw \u03b1\u1d52\u1d48 := \u27e8\u03bb a b c : \u03b1, sbtw c b a\u27e9\n\ninstance (\u03b1 : Type*) [h : circular_preorder \u03b1] : circular_preorder \u03b1\u1d52\u1d48 :=\n{ btw_refl := btw_refl,\n  btw_cyclic_left := \u03bb a b c, btw_cyclic_right,\n  sbtw_trans_left := \u03bb a b c d habc hbdc, hbdc.trans_right habc,\n  sbtw_iff_btw_not_btw := \u03bb a b c, @sbtw_iff_btw_not_btw \u03b1 _ c b a,\n  .. order_dual.has_btw \u03b1,\n  .. order_dual.has_sbtw \u03b1 }\n\ninstance (\u03b1 : Type*) [circular_partial_order \u03b1] : circular_partial_order \u03b1\u1d52\u1d48 :=\n{ btw_antisymm := \u03bb a b c habc hcba, @btw_antisymm \u03b1 _ _ _ _ hcba habc,\n  .. order_dual.circular_preorder \u03b1 }\n\ninstance (\u03b1 : Type*) [circular_order \u03b1] : circular_order \u03b1\u1d52\u1d48 :=\n{ btw_total := \u03bb a b c, btw_total c b a, .. order_dual.circular_partial_order \u03b1 }\n\nend order_dual\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/circular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.742543345983668}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson, Ya\u00ebl Dillies\n-/\nimport order.cover\nimport order.lattice_intervals\n\n/-!\n# Modular Lattices\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines (semi)modular lattices, a kind of lattice useful in algebra.\nFor examples, look to the subobject lattices of abelian groups, submodules, and ideals, or consider\nany distributive lattice.\n\n## Typeclasses\n\nWe define (semi)modularity typeclasses as Prop-valued mixins.\n\n* `is_weak_upper_modular_lattice`: Weakly upper modular lattices. Lattice where `a \u2294 b` covers `a`\n  and `b` if `a` and `b` both cover `a \u2293 b`.\n* `is_weak_lower_modular_lattice`: Weakly lower modular lattices. Lattice where `a` and `b` cover\n  `a \u2293 b` if `a \u2294 b` covers both `a` and `b`\n* `is_upper_modular_lattice`: Upper modular lattices. Lattices where `a \u2294 b` covers `a` if `b`\n  covers `a \u2293 b`.\n* `is_lower_modular_lattice`: Lower modular lattices. Lattices where `a` covers `a \u2293 b` if `a \u2294 b`\n  covers `b`.\n- `is_modular_lattice`: Modular lattices. Lattices where `a \u2264 c \u2192 (a \u2294 b) \u2293 c = a \u2294 (b \u2293 c)`. We\n  only require an inequality because the other direction holds in all lattices.\n\n## Main Definitions\n\n- `inf_Icc_order_iso_Icc_sup` gives an order isomorphism between the intervals\n  `[a \u2293 b, a]` and `[b, a \u2294 b]`.\n  This corresponds to the diamond (or second) isomorphism theorems of algebra.\n\n## Main Results\n\n- `is_modular_lattice_iff_inf_sup_inf_assoc`:\n  Modularity is equivalent to the `inf_sup_inf_assoc`: `(x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z`\n- `distrib_lattice.is_modular_lattice`: Distributive lattices are modular.\n\n## References\n\n* [Manfred Stern, *Semimodular lattices. {Theory} and applications*][stern2009]\n* [Wikipedia, *Modular Lattice*][https://en.wikipedia.org/wiki/Modular_lattice]\n\n## TODO\n\n- Relate atoms and coatoms in modular lattices\n-/\n\nopen set\n\nvariable {\u03b1 : Type*}\n\n/-- A weakly upper modular lattice is a lattice where `a \u2294 b` covers `a` and `b` if `a` and `b` both\ncover `a \u2293 b`. -/\nclass is_weak_upper_modular_lattice (\u03b1 : Type*) [lattice \u03b1] : Prop :=\n(covby_sup_of_inf_covby_covby {a b : \u03b1} : a \u2293 b \u22d6 a \u2192 a \u2293 b \u22d6 b \u2192 a \u22d6 a \u2294 b)\n\n/-- A weakly lower modular lattice is a lattice where `a` and `b` cover `a \u2293 b` if `a \u2294 b` covers\nboth `a` and `b`. -/\nclass is_weak_lower_modular_lattice (\u03b1 : Type*) [lattice \u03b1] : Prop :=\n(inf_covby_of_covby_covby_sup {a b : \u03b1} : a \u22d6 a \u2294 b \u2192 b \u22d6 a \u2294 b \u2192 a \u2293 b \u22d6 a)\n\n/-- An upper modular lattice, aka semimodular lattice, is a lattice where `a \u2294 b` covers `a` and `b`\nif either `a` or `b` covers `a \u2293 b`. -/\nclass is_upper_modular_lattice (\u03b1 : Type*) [lattice \u03b1] : Prop :=\n(covby_sup_of_inf_covby {a b : \u03b1} : a \u2293 b \u22d6 a \u2192 b \u22d6 a \u2294 b)\n\n/-- A lower modular lattice is a lattice where `a` and `b` both cover `a \u2293 b` if `a \u2294 b` covers\neither `a` or `b`. -/\nclass is_lower_modular_lattice (\u03b1 : Type*) [lattice \u03b1] : Prop :=\n(inf_covby_of_covby_sup {a b : \u03b1} : a \u22d6 a \u2294 b \u2192 a \u2293 b \u22d6 b)\n\n/-- A modular lattice is one with a limited associativity between `\u2293` and `\u2294`. -/\nclass is_modular_lattice (\u03b1 : Type*) [lattice \u03b1] : Prop :=\n(sup_inf_le_assoc_of_le : \u2200 {x : \u03b1} (y : \u03b1) {z : \u03b1}, x \u2264 z \u2192 (x \u2294 y) \u2293 z \u2264 x \u2294 (y \u2293 z))\n\nsection weak_upper_modular\nvariables [lattice \u03b1] [is_weak_upper_modular_lattice \u03b1] {a b : \u03b1}\n\nlemma covby_sup_of_inf_covby_of_inf_covby_left : a \u2293 b \u22d6 a \u2192 a \u2293 b \u22d6 b \u2192 a \u22d6 a \u2294 b :=\nis_weak_upper_modular_lattice.covby_sup_of_inf_covby_covby\n\nlemma covby_sup_of_inf_covby_of_inf_covby_right : a \u2293 b \u22d6 a \u2192 a \u2293 b \u22d6 b \u2192 b \u22d6 a \u2294 b :=\nby { rw [inf_comm, sup_comm], exact \u03bb ha hb, covby_sup_of_inf_covby_of_inf_covby_left hb ha }\n\nalias covby_sup_of_inf_covby_of_inf_covby_left \u2190 covby.sup_of_inf_of_inf_left\nalias covby_sup_of_inf_covby_of_inf_covby_right \u2190 covby.sup_of_inf_of_inf_right\n\ninstance : is_weak_lower_modular_lattice (order_dual \u03b1) :=\n\u27e8\u03bb a b ha hb, (ha.of_dual.sup_of_inf_of_inf_left hb.of_dual).to_dual\u27e9\n\nend weak_upper_modular\n\nsection weak_lower_modular\nvariables [lattice \u03b1] [is_weak_lower_modular_lattice \u03b1] {a b : \u03b1}\n\nlemma inf_covby_of_covby_sup_of_covby_sup_left : a \u22d6 a \u2294 b \u2192 b \u22d6 a \u2294 b \u2192 a \u2293 b \u22d6 a :=\nis_weak_lower_modular_lattice.inf_covby_of_covby_covby_sup\n\nlemma inf_covby_of_covby_sup_of_covby_sup_right : a \u22d6 a \u2294 b \u2192 b \u22d6 a \u2294 b \u2192 a \u2293 b \u22d6 b :=\nby { rw [sup_comm, inf_comm], exact \u03bb ha hb, inf_covby_of_covby_sup_of_covby_sup_left hb ha }\n\nalias inf_covby_of_covby_sup_of_covby_sup_left \u2190 covby.inf_of_sup_of_sup_left\nalias inf_covby_of_covby_sup_of_covby_sup_right \u2190 covby.inf_of_sup_of_sup_right\n\ninstance : is_weak_upper_modular_lattice (order_dual \u03b1) :=\n\u27e8\u03bb a b ha hb, (ha.of_dual.inf_of_sup_of_sup_left hb.of_dual).to_dual\u27e9\n\nend weak_lower_modular\n\nsection upper_modular\nvariables [lattice \u03b1] [is_upper_modular_lattice \u03b1] {a b : \u03b1}\n\nlemma covby_sup_of_inf_covby_left : a \u2293 b \u22d6 a \u2192 b \u22d6 a \u2294 b :=\nis_upper_modular_lattice.covby_sup_of_inf_covby\n\nlemma covby_sup_of_inf_covby_right : a \u2293 b \u22d6 b \u2192 a \u22d6 a \u2294 b :=\nby { rw [sup_comm, inf_comm], exact covby_sup_of_inf_covby_left }\n\nalias covby_sup_of_inf_covby_left \u2190 covby.sup_of_inf_left\nalias covby_sup_of_inf_covby_right \u2190 covby.sup_of_inf_right\n\n@[priority 100] -- See note [lower instance priority]\ninstance is_upper_modular_lattice.to_is_weak_upper_modular_lattice :\n  is_weak_upper_modular_lattice \u03b1 :=\n\u27e8\u03bb a b _, covby.sup_of_inf_right\u27e9\n\ninstance : is_lower_modular_lattice (order_dual \u03b1) := \u27e8\u03bb a b h, h.of_dual.sup_of_inf_left.to_dual\u27e9\n\nend upper_modular\n\nsection lower_modular\nvariables [lattice \u03b1] [is_lower_modular_lattice \u03b1] {a b : \u03b1}\n\nlemma inf_covby_of_covby_sup_left : a \u22d6 a \u2294 b \u2192 a \u2293 b \u22d6 b :=\nis_lower_modular_lattice.inf_covby_of_covby_sup\n\nlemma inf_covby_of_covby_sup_right : b \u22d6 a \u2294 b \u2192 a \u2293 b \u22d6 a :=\nby { rw [inf_comm, sup_comm], exact inf_covby_of_covby_sup_left }\n\nalias inf_covby_of_covby_sup_left \u2190 covby.inf_of_sup_left\nalias inf_covby_of_covby_sup_right \u2190 covby.inf_of_sup_right\n\n@[priority 100] -- See note [lower instance priority]\ninstance is_lower_modular_lattice.to_is_weak_lower_modular_lattice :\n  is_weak_lower_modular_lattice \u03b1 :=\n\u27e8\u03bb a b _, covby.inf_of_sup_right\u27e9\n\ninstance : is_upper_modular_lattice (order_dual \u03b1) := \u27e8\u03bb a b h, h.of_dual.inf_of_sup_left.to_dual\u27e9\n\nend lower_modular\n\nsection is_modular_lattice\nvariables [lattice \u03b1] [is_modular_lattice \u03b1]\n\ntheorem sup_inf_assoc_of_le {x : \u03b1} (y : \u03b1) {z : \u03b1} (h : x \u2264 z) :\n  (x \u2294 y) \u2293 z = x \u2294 (y \u2293 z) :=\nle_antisymm (is_modular_lattice.sup_inf_le_assoc_of_le y h)\n  (le_inf (sup_le_sup_left inf_le_left _) (sup_le h inf_le_right))\n\ntheorem is_modular_lattice.inf_sup_inf_assoc {x y z : \u03b1} :\n  (x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z :=\n(sup_inf_assoc_of_le y inf_le_right).symm\n\nlemma inf_sup_assoc_of_le {x : \u03b1} (y : \u03b1) {z : \u03b1} (h : z \u2264 x) :\n  (x \u2293 y) \u2294 z = x \u2293 (y \u2294 z) :=\nby rw [inf_comm, sup_comm, \u2190 sup_inf_assoc_of_le y h, inf_comm, sup_comm]\n\ninstance : is_modular_lattice \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb x y z xz, le_of_eq (by { rw [inf_comm, sup_comm, eq_comm, inf_comm, sup_comm],\n  exact @sup_inf_assoc_of_le \u03b1 _ _ _ y _ xz })\u27e9\n\nvariables {x y z : \u03b1}\n\ntheorem is_modular_lattice.sup_inf_sup_assoc :\n  (x \u2294 z) \u2293 (y \u2294 z) = ((x \u2294 z) \u2293 y) \u2294 z :=\n@is_modular_lattice.inf_sup_inf_assoc \u03b1\u1d52\u1d48 _ _ _ _ _\n\ntheorem eq_of_le_of_inf_le_of_sup_le (hxy : x \u2264 y) (hinf : y \u2293 z \u2264 x \u2293 z) (hsup : y \u2294 z \u2264 x \u2294 z) :\n  x = y :=\nle_antisymm hxy $\n  have h : y \u2264 x \u2294 z,\n    from calc y \u2264 y \u2294 z : le_sup_left\n      ... \u2264 x \u2294 z : hsup,\n  calc y \u2264 (x \u2294 z) \u2293 y : le_inf h le_rfl\n    ... = x \u2294 (z \u2293 y) : sup_inf_assoc_of_le _ hxy\n    ... \u2264 x \u2294 (z \u2293 x) : sup_le_sup_left\n      (by rw [inf_comm, @inf_comm _ _ z]; exact hinf) _\n    ... \u2264 x : sup_le le_rfl inf_le_right\n\ntheorem sup_lt_sup_of_lt_of_inf_le_inf (hxy : x < y) (hinf : y \u2293 z \u2264 x \u2293 z) : x \u2294 z < y \u2294 z :=\nlt_of_le_of_ne\n  (sup_le_sup_right (le_of_lt hxy) _)\n  (\u03bb hsup, ne_of_lt hxy $ eq_of_le_of_inf_le_of_sup_le (le_of_lt hxy) hinf\n    (le_of_eq hsup.symm))\n\ntheorem inf_lt_inf_of_lt_of_sup_le_sup (hxy : x < y) (hinf : y \u2294 z \u2264 x \u2294 z) : x \u2293 z < y \u2293 z :=\n@sup_lt_sup_of_lt_of_inf_le_inf \u03b1\u1d52\u1d48 _ _ _ _ _ hxy hinf\n\n/-- A generalization of the theorem that if `N` is a submodule of `M` and\n  `N` and `M / N` are both Artinian, then `M` is Artinian. -/\ntheorem well_founded_lt_exact_sequence\n  {\u03b2 \u03b3 : Type*} [partial_order \u03b2] [preorder \u03b3]\n  (h\u2081 : well_founded ((<) : \u03b2 \u2192 \u03b2 \u2192 Prop))\n  (h\u2082 : well_founded ((<) : \u03b3 \u2192 \u03b3 \u2192 Prop))\n  (K : \u03b1) (f\u2081 : \u03b2 \u2192 \u03b1) (f\u2082 : \u03b1 \u2192 \u03b2) (g\u2081 : \u03b3 \u2192 \u03b1) (g\u2082 : \u03b1 \u2192 \u03b3)\n  (gci : galois_coinsertion f\u2081 f\u2082)\n  (gi : galois_insertion g\u2082 g\u2081)\n  (hf : \u2200 a, f\u2081 (f\u2082 a) = a \u2293 K)\n  (hg : \u2200 a, g\u2081 (g\u2082 a) = a \u2294 K) :\n  well_founded ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\nsubrelation.wf\n  (\u03bb A B hAB, show prod.lex (<) (<) (f\u2082 A, g\u2082 A) (f\u2082 B, g\u2082 B),\n    begin\n      simp only [prod.lex_def, lt_iff_le_not_le, \u2190 gci.l_le_l_iff,\n        \u2190 gi.u_le_u_iff, hf, hg, le_antisymm_iff],\n      simp only [gci.l_le_l_iff, gi.u_le_u_iff, \u2190 lt_iff_le_not_le, \u2190 le_antisymm_iff],\n      cases lt_or_eq_of_le (inf_le_inf_right K (le_of_lt hAB)) with h h,\n      { exact or.inl h },\n      { exact or.inr \u27e8h, sup_lt_sup_of_lt_of_inf_le_inf hAB (le_of_eq h.symm)\u27e9 }\n    end)\n  (inv_image.wf _ (prod.lex_wf h\u2081 h\u2082))\n\n/-- A generalization of the theorem that if `N` is a submodule of `M` and\n  `N` and `M / N` are both Noetherian, then `M` is Noetherian.  -/\ntheorem well_founded_gt_exact_sequence\n  {\u03b2 \u03b3 : Type*} [preorder \u03b2] [partial_order \u03b3]\n  (h\u2081 : well_founded ((>) : \u03b2 \u2192 \u03b2 \u2192 Prop))\n  (h\u2082 : well_founded ((>) : \u03b3 \u2192 \u03b3 \u2192 Prop))\n  (K : \u03b1) (f\u2081 : \u03b2 \u2192 \u03b1) (f\u2082 : \u03b1 \u2192 \u03b2) (g\u2081 : \u03b3 \u2192 \u03b1) (g\u2082 : \u03b1 \u2192 \u03b3)\n  (gci : galois_coinsertion f\u2081 f\u2082)\n  (gi : galois_insertion g\u2082 g\u2081)\n  (hf : \u2200 a, f\u2081 (f\u2082 a) = a \u2293 K)\n  (hg : \u2200 a, g\u2081 (g\u2082 a) = a \u2294 K) :\n  well_founded ((>) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n@well_founded_lt_exact_sequence \u03b1\u1d52\u1d48 _ _ \u03b3\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ h\u2082 h\u2081 K g\u2081 g\u2082 f\u2081 f\u2082 gi.dual gci.dual hg hf\n\n/-- The diamond isomorphism between the intervals `[a \u2293 b, a]` and `[b, a \u2294 b]` -/\n@[simps]\ndef inf_Icc_order_iso_Icc_sup (a b : \u03b1) : set.Icc (a \u2293 b) a \u2243o set.Icc b (a \u2294 b) :=\n{ to_fun := \u03bb x, \u27e8x \u2294 b, \u27e8le_sup_right, sup_le_sup_right x.prop.2 b\u27e9\u27e9,\n  inv_fun := \u03bb x, \u27e8a \u2293 x, \u27e8inf_le_inf_left a x.prop.1, inf_le_left\u27e9\u27e9,\n  left_inv := \u03bb x, subtype.ext (by { change a \u2293 (\u2191x \u2294 b) = \u2191x,\n    rw [sup_comm, \u2190 inf_sup_assoc_of_le _ x.prop.2, sup_eq_right.2 x.prop.1] }),\n  right_inv := \u03bb x, subtype.ext (by { change a \u2293 \u2191x \u2294 b = \u2191x,\n    rw [inf_comm, inf_sup_assoc_of_le _ x.prop.1, inf_eq_left.2 x.prop.2] }),\n  map_rel_iff' := \u03bb x y, begin\n    simp only [subtype.mk_le_mk, equiv.coe_fn_mk, and_true, le_sup_right],\n    rw [\u2190 subtype.coe_le_coe],\n    refine \u27e8\u03bb h, _, \u03bb h, sup_le_sup_right h _\u27e9,\n    rw [\u2190 sup_eq_right.2 x.prop.1, inf_sup_assoc_of_le _ x.prop.2, sup_comm,\n      \u2190 sup_eq_right.2 y.prop.1, inf_sup_assoc_of_le _ y.prop.2, @sup_comm _ _ b],\n    exact inf_le_inf_left _ h\n  end }\n\nlemma inf_strict_mono_on_Icc_sup {a b : \u03b1} : strict_mono_on (\u03bb c, a \u2293 c) (Icc b (a \u2294 b)) :=\nstrict_mono.of_restrict (inf_Icc_order_iso_Icc_sup a b).symm.strict_mono\n\nlemma sup_strict_mono_on_Icc_inf {a b : \u03b1} : strict_mono_on (\u03bb c, c \u2294 b) (Icc (a \u2293 b) a) :=\nstrict_mono.of_restrict (inf_Icc_order_iso_Icc_sup a b).strict_mono\n\n/-- The diamond isomorphism between the intervals `]a \u2293 b, a[` and `}b, a \u2294 b[`. -/\n@[simps]\ndef inf_Ioo_order_iso_Ioo_sup (a b : \u03b1) : Ioo (a \u2293 b) a \u2243o Ioo b (a \u2294 b) :=\n{ to_fun := \u03bb c, \u27e8c \u2294 b,\n    le_sup_right.trans_lt $ sup_strict_mono_on_Icc_inf (left_mem_Icc.2 inf_le_left)\n      (Ioo_subset_Icc_self c.2) c.2.1,\n    sup_strict_mono_on_Icc_inf (Ioo_subset_Icc_self c.2) (right_mem_Icc.2 inf_le_left) c.2.2\u27e9,\n  inv_fun := \u03bb c, \u27e8a \u2293 c,\n    inf_strict_mono_on_Icc_sup (left_mem_Icc.2 le_sup_right) (Ioo_subset_Icc_self c.2) c.2.1,\n    inf_le_left.trans_lt' $ inf_strict_mono_on_Icc_sup (Ioo_subset_Icc_self c.2)\n      (right_mem_Icc.2 le_sup_right) c.2.2\u27e9,\n  left_inv := \u03bb c, subtype.ext $\n    by { dsimp, rw [sup_comm, \u2190inf_sup_assoc_of_le _ c.prop.2.le, sup_eq_right.2 c.prop.1.le] },\n  right_inv := \u03bb c, subtype.ext $\n    by { dsimp, rw [inf_comm, inf_sup_assoc_of_le _ c.prop.1.le, inf_eq_left.2 c.prop.2.le] },\n  map_rel_iff' := \u03bb c d, @order_iso.le_iff_le _ _ _ _ (inf_Icc_order_iso_Icc_sup _ _)\n    \u27e8c.1, Ioo_subset_Icc_self c.2\u27e9 \u27e8d.1, Ioo_subset_Icc_self d.2\u27e9 }\n\n@[priority 100] -- See note [lower instance priority]\ninstance is_modular_lattice.to_is_lower_modular_lattice : is_lower_modular_lattice \u03b1 :=\n\u27e8\u03bb a b, by { simp_rw [covby_iff_Ioo_eq, @sup_comm _ _ a, @inf_comm _ _ a, \u2190is_empty_coe_sort,\n  right_lt_sup, inf_lt_left, (inf_Ioo_order_iso_Ioo_sup _ _).symm.to_equiv.is_empty_congr],\n    exact id }\u27e9\n\n@[priority 100] -- See note [lower instance priority]\ninstance is_modular_lattice.to_is_upper_modular_lattice : is_upper_modular_lattice \u03b1 :=\n\u27e8\u03bb a b, by { simp_rw [covby_iff_Ioo_eq, \u2190is_empty_coe_sort,\n  right_lt_sup, inf_lt_left, (inf_Ioo_order_iso_Ioo_sup _ _).to_equiv.is_empty_congr], exact id }\u27e9\n\nend is_modular_lattice\n\nnamespace is_compl\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_modular_lattice \u03b1]\n\n/-- The diamond isomorphism between the intervals `set.Iic a` and `set.Ici b`. -/\ndef Iic_order_iso_Ici {a b : \u03b1} (h : is_compl a b) : set.Iic a \u2243o set.Ici b :=\n(order_iso.set_congr (set.Iic a) (set.Icc (a \u2293 b) a) (h.inf_eq_bot.symm \u25b8 set.Icc_bot.symm)).trans $\n  (inf_Icc_order_iso_Icc_sup a b).trans\n  (order_iso.set_congr (set.Icc b (a \u2294 b)) (set.Ici b) (h.sup_eq_top.symm \u25b8 set.Icc_top))\n\nend is_compl\n\ntheorem is_modular_lattice_iff_inf_sup_inf_assoc [lattice \u03b1] :\n  is_modular_lattice \u03b1 \u2194 \u2200 (x y z : \u03b1), (x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z :=\n\u27e8\u03bb h, @is_modular_lattice.inf_sup_inf_assoc _ _ h, \u03bb h, \u27e8\u03bb x y z xz, by rw [\u2190 inf_eq_left.2 xz, h]\u27e9\u27e9\n\nnamespace distrib_lattice\n\n@[priority 100]\ninstance [distrib_lattice \u03b1] : is_modular_lattice \u03b1 :=\n\u27e8\u03bb x y z xz, by rw [inf_sup_right, inf_eq_left.2 xz]\u27e9\n\nend distrib_lattice\n\ntheorem disjoint.disjoint_sup_right_of_disjoint_sup_left\n  [lattice \u03b1] [order_bot \u03b1] [is_modular_lattice \u03b1] {a b c : \u03b1}\n  (h : disjoint a b) (hsup : disjoint (a \u2294 b) c) :\n  disjoint a (b \u2294 c) :=\nbegin\n  rw [disjoint_iff_inf_le, \u2190 h.eq_bot, sup_comm],\n  apply le_inf inf_le_left,\n  apply (inf_le_inf_right (c \u2294 b) le_sup_right).trans,\n  rw [sup_comm, is_modular_lattice.sup_inf_sup_assoc, hsup.eq_bot, bot_sup_eq]\nend\n\ntheorem disjoint.disjoint_sup_left_of_disjoint_sup_right\n  [lattice \u03b1] [order_bot \u03b1] [is_modular_lattice \u03b1] {a b c : \u03b1}\n  (h : disjoint b c) (hsup : disjoint a (b \u2294 c)) :\n  disjoint (a \u2294 b) c :=\nbegin\n  rw [disjoint.comm, sup_comm],\n  apply disjoint.disjoint_sup_right_of_disjoint_sup_left h.symm,\n  rwa [sup_comm, disjoint.comm] at hsup,\nend\n\nnamespace is_modular_lattice\n\nvariables [lattice \u03b1] [is_modular_lattice \u03b1] {a : \u03b1}\n\ninstance is_modular_lattice_Iic : is_modular_lattice (set.Iic a) :=\n\u27e8\u03bb x y z xz, (sup_inf_le_assoc_of_le (y : \u03b1) xz : (\u2191x \u2294 \u2191y) \u2293 \u2191z \u2264 \u2191x \u2294 \u2191y \u2293 \u2191z)\u27e9\n\ninstance is_modular_lattice_Ici : is_modular_lattice (set.Ici a) :=\n\u27e8\u03bb x y z xz, (sup_inf_le_assoc_of_le (y : \u03b1) xz : (\u2191x \u2294 \u2191y) \u2293 \u2191z \u2264 \u2191x \u2294 \u2191y \u2293 \u2191z)\u27e9\n\nsection complemented_lattice\nvariables [bounded_order \u03b1] [complemented_lattice \u03b1]\n\ninstance complemented_lattice_Iic : complemented_lattice (set.Iic a) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, let \u27e8y, hy\u27e9 := exists_is_compl x in\n  \u27e8\u27e8y \u2293 a, set.mem_Iic.2 inf_le_right\u27e9, begin\n    split,\n    { rw disjoint_iff_inf_le,\n      change x \u2293 (y \u2293 a) \u2264 \u22a5, -- improve lattice subtype API\n      rw \u2190 inf_assoc,\n      exact le_trans inf_le_left hy.1.le_bot },\n    { rw codisjoint_iff_le_sup,\n      change a \u2264 x \u2294 (y \u2293 a), -- improve lattice subtype API\n      rw [\u2190 sup_inf_assoc_of_le _ (set.mem_Iic.1 hx), hy.2.eq_top, top_inf_eq] }\n  end\u27e9\u27e9\n\ninstance complemented_lattice_Ici : complemented_lattice (set.Ici a) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, let \u27e8y, hy\u27e9 := exists_is_compl x in\n  \u27e8\u27e8y \u2294 a, set.mem_Ici.2 le_sup_right\u27e9, begin\n    split,\n    { rw disjoint_iff_inf_le,\n      change x \u2293 (y \u2294 a) \u2264 a, -- improve lattice subtype API\n      rw [\u2190 inf_sup_assoc_of_le _ (set.mem_Ici.1 hx), hy.1.eq_bot, bot_sup_eq] },\n    { rw codisjoint_iff_le_sup,\n      change \u22a4 \u2264 x \u2294 (y \u2294 a), -- improve lattice subtype API\n      rw \u2190 sup_assoc,\n      exact le_trans hy.2.top_le le_sup_left }\n  end\u27e9\u27e9\n\nend complemented_lattice\n\nend is_modular_lattice\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/modular_lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.742543332392339}}
{"text": "section sec_3_redo\nopen classical\n\nvariables p q r s : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\nbegin\n  split; {\n    intro h,\n    cases h with p q,\n    split; assumption\n  }\nend\nexample : p \u2228 q \u2194 q \u2228 p :=\nbegin\n  split; {\n    intro h,\n    cases h with p q; { left; assumption } <|> { right; assumption }\n  }\nend\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\nbegin\n  split; {\n    intro h,\n    cases h with h1 h2,\n    cases h1 with h11 h12 <|> cases h2 with h22 h23,\n    repeat { split }; assumption,\n  }\nend\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\nbegin\n  split; {\n    intro h,\n    cases h; try { cases h },\n    all_goals {\n      { repeat { { left; assumption } <|> right }; assumption } <|>\n      { repeat { { right; assumption } <|> left }; assumption } }\n  }\nend\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  split,\n    intros h,\n    cases h with hp hqr,\n    cases hqr with hq hr;\n    { left; split; assumption } <|> { right; split; assumption },\n  intros h,\n  cases h; cases h with hq hqr; split;\n  { assumption <|> { left; assumption}  <|> { right; assumption} }\nend\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\nbegin\n  split,\n    intros h,\n    cases h with hp hqr;\n    try {cases hqr with hq hr}; {\n      split; {left; assumption} <|> {right; assumption}\n    },\n  intros h,\n  cases h with hpq hpr;\n  cases hpq with hp hq;\n  cases hpr with hp2 hr;\n  { assumption <|> {left; assumption}  <|> { right; split; assumption} }\nend\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\nbegin\n  split,\n    intros hpqr hpq,\n    cases hpq with hp hq,\n    apply hpqr; assumption,\n  intros hpqr hp hq,\n  apply hpqr; split; assumption,\nend\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\nbegin\n  split,\n    intros hpqr,\n    split; intros hpq; apply hpqr; {{left; assumption} <|> {right; assumption}},\n  intros hprqr hpq,\n  cases hprqr with hpr hqr,\n  cases hpq with hp hq; { apply hpr; assumption } <|> { apply hqr; assumption }\nend\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\nbegin\n  split,\n    intros hnpq,\n    split; intros hpq; apply hnpq; {left; assumption}  <|> { right; assumption},\n  intros hnpnq hpq,\n  cases hnpnq with hnp hnq,\n  cases hpq with hp hq;\n  { apply hnp; assumption } <|> { apply hnq; assumption }\nend\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\nbegin\n  intros hnpnq hpq,\n  cases hpq with hp hq,\n  cases hnpnq with hnp hnq;\n  { apply hnp; assumption } <|> { apply hnq; assumption }\nend\nexample : \u00ac(p \u2227 \u00acp) :=\nbegin\n  intros hpnp,\n  cases hpnp with hp hnp,\n  apply hnp,\n  assumption,\nend\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\nbegin\n  intros hpnq hpq,\n  cases hpnq with hp hnq,\n  apply hnq,\n  apply hpq,\n  apply hp,\nend\nexample : \u00acp \u2192 (p \u2192 q) :=\nbegin\n  intros hnp hp,\n  cases (hnp hp),\nend\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\nbegin\n  intros hnpq hp,\n  cases hnpq with hnp hq,\n    cases (hnp hp),\n  apply hq,\nend\n\nexample : \u00ac(p \u2194 \u00acp) :=\nbegin\n  intro heqpnp,\n  cases heqpnp with hpnp hnpp,\n  apply hpnp;\n    apply hnpp;\n      intros p;\n        apply hpnp; assumption,\nend\nend sec_3_redo\n\nexample (p q r : Prop) (hp : p) :\n(p \u2228 q \u2228 r) \u2227 (q \u2228 p \u2228 r) \u2227 (q \u2228 r \u2228 p) :=\nby split; split <|> left; assumption <|> right; {left; assumption} <|> {right; assumption}\n\nexample (p q r : Prop) (hp : p) :\n(p \u2228 q \u2228 r) \u2227 (q \u2228 p \u2228 r) \u2227 (q \u2228 r \u2228 p) :=\nbegin\n  split,\n  all_goals { try {split} },\n  all_goals { repeat { {left; assumption} <|> right } },\n  all_goals { assumption },\nend\n\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/na4zagin3/chp-5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.742543331854763}}
{"text": "import tactic.ring tactic.linarith tactic.omega data.set data.int.basic\n\nlocal attribute [instance] classical.prop_decidable\n\ndef almost_homomorphism (f : \u2124 \u2192 \u2124) : Prop :=\n    \u2203 C : \u2124, \u2200 (p q : \u2124), abs (f (p + q) - f p - f q) < C\n\ninstance int_to_int.add_group : add_comm_group (\u2124 \u2192 \u2124) :=\n{ add := \u03bb f g n,f n + g n,\n  add_assoc := \u03bb f g h,funext (\u03bb n,add_assoc _ _ _),\n  zero := \u03bb n, 0,\n  zero_add := \u03bb f, funext (\u03bb n,zero_add _),\n  add_zero := \u03bb f, funext (\u03bb n,add_zero _),\n  neg := \u03bb f n,-f n,\n  add_left_neg := \u03bb f, funext (\u03bb n, add_left_neg _),\n  add_comm := \u03bb f g, funext (\u03bb n, add_comm _ _) }\n\n@[simp]\nlemma int_to_int_add (f g : \u2124 \u2192 \u2124) (n : \u2124) : (f + g) n = f n + g n := rfl\n@[simp]\nlemma int_to_int_neg (f : \u2124 \u2192 \u2124) (n : \u2124) : (-f) n = -f n := rfl\n@[simp]\nlemma int_to_int_zero : (0:\u2124 \u2192 \u2124) = \u03bb n, 0 := rfl\n\nlemma almost_homomorphism_add {f g : \u2124 \u2192 \u2124}\n    (hf : almost_homomorphism f) (hg : almost_homomorphism g) :\n    almost_homomorphism (f + g) :=\nlet \u27e8Cf, hCf\u27e9:= hf in let \u27e8Cg, hCg\u27e9 := hg in \u27e8Cf+Cg,\u03bb p q, calc\nabs ((f + g) (p + q) - (f + g) p - (f + g) q) \n        = abs (f (p + q) + g (p + q) - (f p + g p) - (f q + g q)) : rfl\n    ... = abs (f (p + q) - f p - f q + (g (p + q) - g p - g q)) : congr_arg abs (by ring)\n    ... \u2264 abs (f (p + q) - f p - f q) + abs (g (p + q) - g p - g q) : abs_add _ _\n    ... < Cf + Cg : by linarith [hCf p q,hCg p q] \u27e9\n\nlemma almost_homomorphism_neg {f : \u2124 \u2192 \u2124}\n    (hf : almost_homomorphism f) :\n    almost_homomorphism (-f) :=\nlet \u27e8Cf,hCf\u27e9:=hf in \u27e8Cf,\u03bb p q, calc\nabs ((-f) (p + q) - (-f) p - (-f) q) \n        = abs (-f (p + q) - -f p - -f q)  : rfl\n    ... = abs (-(f (p + q) - f p - f q)) : by ring\n    ... = abs (f (p + q) - f p - f q) : abs_neg _\n    ... < Cf : hCf p q\u27e9\n\ndef bounded_difference (f g : \u2124 \u2192 \u2124) : Prop := \n    \u2203 C : \u2124, \u2200 p : \u2124, abs (f p - g p) < C\n\nlemma bounded_difference_add {f\u2081 g\u2081 f\u2082 g\u2082 : \u2124 \u2192 \u2124}\n    (hf : bounded_difference f\u2081 f\u2082) (hg : bounded_difference g\u2081 g\u2082) :\n    bounded_difference (f\u2081 + g\u2081) (f\u2082 + g\u2082) :=\nlet \u27e8Cf, hCf\u27e9:=hf in let \u27e8Cg, hCg\u27e9:=hg in \u27e8Cf + Cg,\u03bb p,calc \nabs ((f\u2081 + g\u2081) p - (f\u2082 + g\u2082) p) \n        = abs ( f\u2081 p + g\u2081 p - (f\u2082 p + g\u2082 p)) : rfl\n    ... = abs (f\u2081 p - f\u2082 p + (g\u2081 p - g\u2082 p)) : congr_arg abs (by ring)\n    ... \u2264 abs (f\u2081 p - f\u2082 p) + abs (g\u2081 p - g\u2082 p) : abs_add _ _\n    ... < Cf + Cg : by linarith [hCf p,hCg p]\u27e9\n\nlemma bounded_difference_neg {f\u2081 f\u2082 : \u2124 \u2192 \u2124}\n    (hf : bounded_difference f\u2081 f\u2082) :\n    bounded_difference (-f\u2081) (-f\u2082) :=\nlet \u27e8C,hC\u27e9:=hf in \u27e8C, \u03bb p, calc\nabs ((-f\u2081) p - (-f\u2082) p) \n        = abs (-f\u2081 p - -f\u2082 p) : rfl\n    ... = abs (- (f\u2081 p - f\u2082 p)) : by ring\n    ... = abs (f\u2081 p - f\u2082 p) : abs_neg _\n    ... < C : hC p\u27e9\n\n\nstructure S :=\n(func : \u2124 \u2192 \u2124) \n(AH : almost_homomorphism func)\n\nlemma func_eq : \u2200 {F G : S}, F.func = G.func \u2192 F = G\n| \u27e8f, _\u27e9 \u27e8g, _\u27e9 rfl := rfl\n\nlemma S_eq : \u2200 {F G : S}, F = G \u2192 F.func = G.func := by tidy\n\ninstance : add_comm_group S := \n{ add := \u03bb F G,\u27e8F.func + G.func,almost_homomorphism_add F.AH G.AH\u27e9,\n  add_assoc := \u03bb F G H, func_eq (add_assoc _ _ _),\n  zero := \u27e80,\u27e81,\u03bb p q,by omega\u27e9\u27e9,\n  zero_add := \u03bb F, func_eq (zero_add _),\n  add_zero := \u03bb F, func_eq (add_zero _),\n  neg := \u03bb F,\u27e8-F.func,almost_homomorphism_neg F.AH\u27e9,\n  add_left_neg := \u03bb F, func_eq (add_left_neg _),\n  add_comm := \u03bb F G, func_eq (add_comm _ _) }\n\n@[simp]\nlemma zero_S_func_eq : (0:S).func = (0:\u2124 \u2192 \u2124) := rfl \n\n@[simp]\nlemma neg_S_func_eq (T : S) : (-T).func = -(T.func) := rfl\n\ninstance S.equiv : setoid S := { r := \u03bb F G,bounded_difference F.func G.func,\n  iseqv := \n  \u27e8\u03bb F ,\u27e81,by norm_num\u27e9,\n  \u03bb F G h ,let \u27e8C,hC\u27e9:= h  in \u27e8C,by simp [abs_sub];exact hC\u27e9,\n  \u03bb F G H hFG hGH ,let \u27e8C_FG,hCFH\u27e9:=hFG in let \u27e8C_GH,hCGH\u27e9:= hGH in\n  \u27e8C_FG+C_GH, \u03bb p, calc \n  abs (F.func p - H.func p) \n        = abs (F.func p - G.func p + (G.func p - H.func p)) : by ring\n    ... \u2264 abs (F.func p - G.func p) + abs (G.func p - H.func p) : abs_add _ _\n    ... < C_FG + C_GH : by linarith [hCFH p, hCGH p]\u27e9\u27e9 }\n\ndef E := @quotient S S.equiv\n\ndef mk : S \u2192 E := quotient.mk \n\n@[simp] \nlemma mk_eq_mk (F) :  \u27e6F\u27e7 = (mk F) := rfl\n\n@[simp]\nlemma mk_eq {F G} : mk F = mk G \u2194 F \u2248 G := quotient.eq\n\n@[simp]\nlemma mk_eq_mk' (f : S) : quot.mk setoid.r f = mk f := rfl\n\ninstance : has_zero E := \u27e8mk 0\u27e9 \n\n@[simp] lemma zero_def : 0 = mk 0 := rfl\n\ninstance : has_add E := \n\u27e8\u03bb x y,quotient.lift_on\u2082 x y (\u03bb F G, mk (F + G)) $\n    \u03bb F\u2081 G\u2081 F\u2082 G\u2082 hF hG, quotient.sound $\n    bounded_difference_add hF hG\u27e9\n\n@[simp] theorem mk_add (F G : S) : mk F + mk G = mk (F + G) := rfl\n\ninstance : has_neg E :=\n\u27e8\u03bb x, quotient.lift_on x (\u03bb F, mk (-F)) $\n  \u03bb F\u2081 F\u2082 hF, quotient.sound $\n  bounded_difference_neg hF\u27e9\n\n@[simp] theorem mk_neg (F : S) : -mk F = mk (-F) := rfl\n\ninstance : add_comm_group E :=\n{ add := (+),\n  add_assoc := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp [add_assoc],\n  zero := 0,\n  zero_add := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp,\n  add_zero := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp,\n  neg := \u03bb x,-x,\n  add_left_neg := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp,\n  add_comm := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp [add_comm] }\n\n\ndef int_to_int.mapping : \u2124 \u2192 (\u2124 \u2192 \u2124) := \u03bb A,\u03bb p, A*p\ndef S.mapping : \u2124 \u2192 S := \u03bb A,\u27e8\u03bb p, A*p,\u27e81,\u03bb q r,by simp [left_distrib];norm_num\u27e9\u27e9\ndef E.mapping : \u2124 \u2192 E := \u03bb A,mk \u27e8\u03bb p, A*p,\u27e81,\u03bb q r,by simp [left_distrib];norm_num\u27e9\u27e9\n\nlemma nat.rec_on_sup\n{C : \u2115 \u2192 Prop} (n i : \u2115) (hp : n \u2265 i) (hi : C i)\n(hr : \u2200 (n : \u2115), C n \u2192 C (nat.succ n)) : C n :=\nbegin\n  cases (nat.eq_or_lt_of_le hp).symm,\n    {induction h with k hle ht,\n      {exact hr i hi},\n      replace hle : i + 1 \u2264 k := hle,\n      refine hr k (ht $ le_trans (nat.le_succ i) hle)},\n    rwa \u2190h\nend\n\n\nlemma lemma3 (f : \u2124 \u2192 \u2124) (hf : almost_homomorphism f) \n    (hfi : set.infinite ((f ''{n | n > 0}) \u2229 {n | n>0})) : \u2200 D>0,\u2203 M>0,\u2200 m>0, f (m*M) > (m+1)*D :=\nbegin\n\nintros D hD,\ncases hf with C hC,\nset E:=C+D with HE,\nhave h\u2081 : \u2203 M>0, f M > 2*E,\n{   begin\n        by_contra hh, simp at hh,\n        apply hfi,\n        have h\u2082 : f '' {n | n > 0} \u2229 {n | n>0} \u2286 { n | n \u2264 2*E \u2227 n\u22650}, \n            from \u03bb n hn,let \u27e8x,hx,hx'\u27e9:=(set.mem_image _ _ _).1 hn.1 in \n            \u27e8hx' \u25b8 hh x hx,le_of_lt hn.2\u27e9,\n        apply set.finite.subset _ h\u2082,\n        have h\u2083 : { n : \u2124 | n \u2264 2*E \u2227 n\u22650} \u2286 coe ''{n : \u2115 | \u2191n \u2264 2*E},\n            from \u03bb n hn,let \u27e8n',hn'\u27e9:=int.eq_coe_of_zero_le hn.2 in\n            (set.mem_image _ _ _).2 \u27e8n',\u27e8by simpa [hn'] using hn.1,hn'.symm\u27e9\u27e9,\n        apply set.finite.subset _ h\u2083,\n        apply set.finite.image,\n        cases lt_or_ge E 0 with hE hE,\n        {   have h\u2084 : {n : \u2115 | \u2191n \u2264 2 * E}=\u2205,\n            {   apply set.eq_empty_iff_forall_not_mem.2,\n                intro x, simp,linarith},\n            rw h\u2084, exact set.finite_empty },\n        cases int.eq_coe_of_zero_le hE with  E' hE',\n        have h\u2084 : {n : \u2115 | \u2191n \u2264 2 * E} = {n : \u2115 | n \u2264 2*E'},\n        {   simp [hE',int.coe_nat_le.symm]},\n        rw h\u2084, exact set.finite_le_nat _\n    end},\nhave h\u2082 : C>0,from lt_of_le_of_lt (abs_nonneg _) (hC 0 0),\nrcases h\u2081 with \u27e8M,hM,hM'\u27e9,\nuse M, use hM,\nintros m hm,\nhave h\u2083 : f (m * M) > (m + 1) * E,\n{   rcases int.eq_coe_of_zero_le (le_of_lt hm) with \u27e8m',hhm'\u27e9,\n    rw hhm' at *,\n    apply nat.rec_on_sup m' 1 (int.coe_nat_pos.mp hm),\n    {  calc \n        f (\u21911 * M) \n                = f M : by simp\n            ... > 2*E : hM' },\n    {   intros m hm',\n        calc f (\u2191(m.succ) * M) \n                = f ( (\u2191m+1)*M) : rfl\n            ... = f ( \u2191m * M + M) : by ring\n            ... = f (\u2191m * M) + f M + ( f ( \u2191m * M + M) - f (\u2191m * M) - f M ) : by ring\n            ... > f (\u2191m * M) + f M - C : add_lt_add_left (abs_lt.1 (hC _ _)).1 _\n            ... > f (\u2191m * M) + f M - E : add_lt_add_left (neg_lt_neg ((lt_add_iff_pos_right _).2 hD)) _\n            ... = f (\u2191m * M) + (f M - E) :  add_assoc _ _ _\n            ... > (\u2191m + 1) * E + (f M - E) : add_lt_add_right hm' _ \n            ... = f M + ((\u2191m + 1) * E - E) : by ring\n            ... > 2 * E + ((\u2191m + 1) * E - E) : add_lt_add_right hM' _\n            ... = (\u2191m + 2) * E : by ring\n            ... = ((\u2191m+1) +1)*E : by ring\n            ... = (\u2191(m+1) +1)*E : by simp\n            ... = (\u2191(m.succ) + 1) * E : by ring }\n},\ncalc \nf (m * M) \n        > (m + 1) * E : h\u2083\n    ... = (m + 1) * C + (m + 1) * D : by ring\n    ... > (m + 1) * D : (lt_add_iff_pos_left _).2 (mul_pos (by linarith) h\u2082)\n\nend\n\nlemma finite.exists_max {\u03b1 : Type*} [linear_order \u03b1] (s : set \u03b1) (h : set.finite s) :\n    s.nonempty \u2192 \u2203 x\u2208s, \u2200 y\u2208s, x \u2265 y :=\nset.exists_max_image s id h\n\nlemma finite.exists_min {\u03b1 : Type*} [linear_order \u03b1] (s : set \u03b1) (h : set.finite s) :\n    s.nonempty \u2192 \u2203 x\u2208s, \u2200 y\u2208s, x \u2264 y :=\nset.exists_min_image s id h\n\n\nlemma infinite_or (f : \u2124 \u2192 \u2124) : \n      set.infinite ((f ''{n | n > 0}) \u2229 {n | n>0})\n    \u2228 set.infinite ((f ''{n | n > 0}) \u2229 {n | n<0})\n    \u2228 (\u2203 C,\u2200 n>0,abs (f n) \u2264 C) :=\nbegin\nby_contra H,\nsimp [decidable.not_or_iff_and_not]at H,\nsimp [set.infinite,not_not] at H,\nhave h : set.finite  (f ''{n | n > 0}),\n{   have h':=set.finite.union H.1 H.2.1,\n    simp [set.inter_union_distrib_left.symm] at h',\n    have hh':{n : \u2124 | n>0} \u222a {n | n<0} =  {n : \u2124 | \u00acn = 0},\n    {   ext1,split;intros,\n        {   exact or.elim a (\u03bb ha,ne_of_gt ha) (\u03bb ha,ne_of_lt ha)},\n        {   exact or.symm (lt_or_gt_of_ne a)}},\n    rw hh' at h',\n    have h'':=\n        set.finite.union h' (set.finite.subset (set.finite_singleton 0) (set.inter_subset_right (f ''{n | n > 0}) _)),\n    simp only [set.inter_union_distrib_left.symm] at h'',\n    have hh'':{n : \u2124 | \u00acn = 0} \u222a {0} = set.univ,\n    {   ext1,split;intros,\n        {   exact set.mem_univ _},\n        {   exact or.symm (decidable.em (x=0))}},\n    simp [hh''] at h'',\n    exact h''\n},\nrcases finite.exists_max _ h \u27e8f 1,(set.mem_image _ _ _).2 \u27e81,\u27e8by norm_num,rfl\u27e9\u27e9\u27e9 \n    with \u27e8x,hx,hx'\u27e9,\nrcases finite.exists_min _ h \u27e8f 1,(set.mem_image _ _ _).2 \u27e81,\u27e8by norm_num,rfl\u27e9\u27e9\u27e9 \n    with \u27e8xx,hhx,hhx'\u27e9,\nby_cases hhxx : x \u2265 -xx,\n{   rcases H.2.2 (x) with \u27e8y,hy\u27e9,\n    have hhh:=hx' (f y) ((set.mem_image _ _ _).2 \u27e8y,hy.1,rfl\u27e9),\n    have hhh':=hhx' (f y) ((set.mem_image _ _ _).2 \u27e8y,hy.1,rfl\u27e9),\n    cases (lt_max_iff.1 hy.2) with hhy hhy,\n    {   linarith},\n    {   linarith}\n},\n{\n    rcases H.2.2 (-xx) with \u27e8y,hy\u27e9,\n    have hhh:=hx' (f y) ((set.mem_image _ _ _).2 \u27e8y,hy.1,rfl\u27e9),\n    have hhh':=hhx' (f y) ((set.mem_image _ _ _).2 \u27e8y,hy.1,rfl\u27e9),\n    cases (lt_max_iff.1 hy.2) with hhy hhy,\n    {   linarith},\n    {   linarith}\n}\nend\n\nlemma bounded_lt_of_le (f : \u2124 \u2192 \u2124) : \n    (\u2203 C,\u2200 n>0,abs (f n) \u2264 C) \u2192 (\u2203 C,\u2200 n>0,abs (f n) < C) :=\n\u03bb h,let \u27e8C,hC\u27e9:= h in \u27e8C+1,\u03bb n hn,by linarith [hC n hn]\u27e9\n\nlemma exists_max_of_ico (f : \u2124 \u2192 \u2124) (a b : \u2124) (hab : a > b) :\n    \u2203 E,\u2200 r, b \u2264 r \u2192 r < a \u2192 E > abs (f r) :=\nbegin\n    have hf : set.finite (set.Ico b a),\n        {   refine int.induction_on' b a _ _ _,\n            {   simp},\n            {   intros k hk hk',\n                apply set.finite.subset hk',\n                intros r hr, simp at *, linarith\n            },\n            {   intros k hk hk',\n                convert set.finite.insert (k - 1) hk',\n                ext1;intros,split;intros,\n                {   cases eq_or_lt_of_le a_1.1 with hh hh,\n                    {   exact or.inl hh.symm},\n                    {   exact or.inr \u27e8by linarith,a_1.2\u27e9}},\n                {   cases a_1 with hh hh,\n                    {   simp [hh],linarith},\n                    {   exact \u27e8by linarith [hh.1],hh.2\u27e9}\n                } \n            }\n        },\n    rcases set.exists_max_image (set.Ico b a) f hf \u27e8b,set.left_mem_Ico.mpr hab\u27e9 with \u27e8E,hE,hE'\u27e9,\n    rcases set.exists_min_image (set.Ico b a) f hf \u27e8b,set.left_mem_Ico.mpr hab\u27e9 with \u27e8F,hF,hF'\u27e9,\n    by_cases H : f E>-f F,\n    {   use (f E) + 1, intros r hrb hra,\n        have hhE:= hE' r \u27e8hrb,hra\u27e9,\n        have hhF:= hF' r \u27e8hrb,hra\u27e9, simp [abs_lt],\n        split;linarith\n    },\n    {   use (-f F) + 1, intros r hrb hra,\n        have hhE:= hE' r \u27e8hrb,hra\u27e9,\n        have hhF:= hF' r \u27e8hrb,hra\u27e9, simp [abs_lt] at *,\n        exact \u27e8by linarith,by linarith\u27e9\n    }\nend\n\nlemma lemma5_aux (f : \u2124 \u2192 \u2124) (hf : almost_homomorphism f)\n    (h : (f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite) :\n    (\u2200 C>0,\u2203 N>0,\u2200 p>N, f p > C) :=\nbegin\n    intros C hC,\n    rcases hf with \u27e8D,hD\u27e9,\n    have hl := lemma3 f \u27e8D,hD\u27e9 h D (lt_of_le_of_lt (abs_nonneg _) (hD 0 0)),\n    rcases hl with \u27e8M,hM,hM'\u27e9,\n    set g:=\u03bb p:\u2124,f (( p / M : \u2124 ) * M) with hg,\n    rcases exists_max_of_ico f M 0 hM with \u27e8E,hE\u27e9,\n    have hh: \u2200 p:\u2124,abs ((f-g) p) < E+D,from \u03bb p, \n        have h\u2081 : p = p/M * M + p%M,by simp [int.mod_def];ring,\n        have h\u2082 : g (p/M * M + p%M) = f (p/M * M),by rw [\u2190h\u2081],\n        calc\n        abs ((f-g) p)\n                = abs ((f-g) (p/M * M + p%M)) : congr_arg (abs) (congr_arg (f-g) h\u2081)\n            ... = abs (f (p/M * M + p%M) - g (p/M * M + p%M)) : rfl\n            ... = abs ( f (p/M * M) + f (p%M) + (f (p/M * M + p%M) - f (p/M * M) - f (p%M)) - f (p/M * M)) \n                    : by rw [h\u2082];exact congr_arg abs (by ring)\n            ... = abs ( f (p%M) + (f (p/M * M + p%M) - f (p/M * M) - f (p%M))) : congr_arg abs (by ring)\n            ... \u2264 abs ( f (p%M) ) + abs (f (p/M * M + p%M) - f (p/M * M) - f (p%M)) : abs_add _ _\n            ... < E + D : add_lt_add \n                            (hE _ (int.mod_nonneg _ (ne_of_gt hM)) (int.mod_lt_of_pos p hM))\n                            (hD _ _),\n    have h\u2083 : \u2203 n>0, (n+1)*D > (E + D) + C,from\n    \u27e8((E + D) + C)/D + 1,add_pos_of_nonneg_of_pos (int.div_nonneg \n    (le_of_lt (by linarith [lt_of_le_of_lt (abs_nonneg _) (hD 1 1),lt_of_le_of_lt (abs_nonneg _) (hE 0 (le_refl _) hM)]))\n    (le_trans (abs_nonneg _) (le_of_lt (hD 1 1)))) (by norm_num),\n    have h':(E + D + C) / D + 1 + 1> (E + D + C) / D,by linarith,\n    int.lt_mul_of_div_lt (by linarith [lt_of_le_of_lt (abs_nonneg _) (hD 1 1),lt_of_le_of_lt (abs_nonneg _) (hE 0 (le_refl _) hM)]) h'\u27e9,\n    rcases h\u2083 with \u27e8n,hn,hn'\u27e9,\n    set N:=n*M with hN,\n    use N, split, {exact mul_pos hn hM}, intros p hp,\n    have h\u2081 : p = p/M * M + p%M,by simp [int.mod_def];ring,\n    have h\u2082 : g (p/M * M + p%M) = f (p/M * M),by rw [\u2190h\u2081],\n    have h\u2084 : p/M \u2265 n,\n    {   rw [hN] at hp,\n        exact (int.le_div_iff_mul_le hM).2 (le_of_lt hp)},\n    have h\u2085 : g p > (E + D) + C, from calc\n        g p = f (p/M * M) : by rw [\u2190h\u2082,\u2190h\u2081]\n        ... > (p/M +1) * D : hM' _ (gt_of_ge_of_gt h\u2084 hn)\n        ... \u2265 (n + 1) * D : (mul_le_mul_right (lt_of_le_of_lt (abs_nonneg (f (0 + 0) - f 0 - f 0)) (hD 0 0))).2 (add_le_add_right h\u2084 _)\n        ... > (E + D) + C : hn',\n    exact calc f p > g p - (E + D) : lt_sub_iff_add_lt'.mp (abs_lt.1 (hh p)).1\n         ... > C : lt_sub_iff_add_lt'.mpr h\u2085\nend\n\nlemma lemma5_aux' (f : \u2124 \u2192 \u2124) (hf : almost_homomorphism f)\n    (h : (f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite) :\n    (\u2200 C\u22650,\u2203 N>0,\u2200 p\u2265N, f p \u2265 C) :=\nbegin\n    intros C hC,\n    rcases hf with \u27e8D,hD\u27e9,\n    have hl := lemma3 f \u27e8D,hD\u27e9 h D (lt_of_le_of_lt (abs_nonneg _) (hD 0 0)),\n    rcases hl with \u27e8M,hM,hM'\u27e9,\n    set g:=\u03bb p:\u2124,f (( p / M : \u2124 ) * M) with hg,\n    rcases exists_max_of_ico f M 0 hM with \u27e8E,hE\u27e9,\n    have hh: \u2200 p:\u2124,abs ((f-g) p) < E+D,from \u03bb p, \n        have h\u2081 : p = p/M * M + p%M,by simp [int.mod_def];ring,\n        have h\u2082 : g (p/M * M + p%M) = f (p/M * M),by rw [\u2190h\u2081],\n        calc\n        abs ((f-g) p)\n                = abs ((f-g) (p/M * M + p%M)) : congr_arg (abs) (congr_arg (f-g) h\u2081)\n            ... = abs (f (p/M * M + p%M) - g (p/M * M + p%M)) : rfl\n            ... = abs ( f (p/M * M) + f (p%M) + (f (p/M * M + p%M) - f (p/M * M) - f (p%M)) - f (p/M * M)) \n                    : by rw [h\u2082];exact congr_arg abs (by ring)\n            ... = abs ( f (p%M) + (f (p/M * M + p%M) - f (p/M * M) - f (p%M))) : congr_arg abs (by ring)\n            ... \u2264 abs ( f (p%M) ) + abs (f (p/M * M + p%M) - f (p/M * M) - f (p%M)) : abs_add _ _\n            ... < E + D : add_lt_add \n                            (hE _ (int.mod_nonneg _ (ne_of_gt hM)) (int.mod_lt_of_pos p hM))\n                            (hD _ _),\n    have h\u2083 : \u2203 n>0, (n+1)*D > (E + D) + C,from\n    \u27e8((E + D) + C)/D + 1,add_pos_of_nonneg_of_pos (int.div_nonneg \n    (le_of_lt (by linarith [lt_of_le_of_lt (abs_nonneg _) (hD 1 1),lt_of_le_of_lt (abs_nonneg _) (hE 0 (le_refl _) hM)]))\n    (le_trans (abs_nonneg _) (le_of_lt (hD 1 1)))) (by norm_num),\n    have h':(E + D + C) / D + 1 + 1> (E + D + C) / D,by linarith,\n    int.lt_mul_of_div_lt (by linarith [lt_of_le_of_lt (abs_nonneg _) (hD 1 1),lt_of_le_of_lt (abs_nonneg _) (hE 0 (le_refl _) hM)]) h'\u27e9,\n    rcases h\u2083 with \u27e8n,hn,hn'\u27e9,\n    set N:=n*M with hN,\n    use N,split,{exact mul_pos hn hM}, intros p hp,\n    have h\u2081 : p = p/M * M + p%M,by simp [int.mod_def];ring,\n    have h\u2082 : g (p/M * M + p%M) = f (p/M * M),by rw [\u2190h\u2081],\n    have h\u2084 : p/M \u2265 n,\n    {   rw [hN] at hp,\n        exact (int.le_div_iff_mul_le hM).2 hp},\n    have h\u2085 : g p > (E + D) + C, from calc\n        g p = f (p/M * M) : by rw [\u2190h\u2082,\u2190h\u2081]\n        ... > (p/M +1) * D : hM' _ (gt_of_ge_of_gt h\u2084 hn)\n        ... \u2265 (n + 1) * D : (mul_le_mul_right (lt_of_le_of_lt (abs_nonneg (f (0 + 0) - f 0 - f 0)) (hD 0 0))).2 (add_le_add_right h\u2084 _)\n        ... > (E + D) + C : hn',\n    exact calc f p \u2265 g p - (E + D) : le_of_lt (lt_sub_iff_add_lt'.mp (abs_lt.1 (hh p)).1)\n         ... \u2265 C : le_of_lt (lt_sub_iff_add_lt'.mpr h\u2085)\nend\n\nlemma lemma5_neg_aux (f : \u2124 \u2192 \u2124) (hf : almost_homomorphism f)\n    (h : set.infinite ((f ''{n | n > 0}) \u2229 {n | n<0})) :\n    (\u2200 C>0,\u2203 N>0,\u2200 p>N, f p < -C) :=\nbegin\n    have := lemma5_aux (-f) (almost_homomorphism_neg hf) _,\n    {   simp only [lt_neg];exact this},\n    {   intro hh,\n        apply h,\n        have h\u2081 : {n : \u2124 | n > 0} = (\u03bb x,-x) ''{n : \u2124 | n < 0},\n        {   ext1;intros,split;intros,\n            {   apply (set.mem_image _ _ _).2,\n                use (-x),exact \u27e8set.mem_def.2 (neg_lt_zero.2 a),neg_neg x\u27e9},\n            {   rcases (set.mem_image _ _ _).1 a with \u27e8y,hy,hy'\u27e9,\n                rw \u2190hy', exact set.mem_def.2 (neg_pos.2 hy)}},\n        have h\u2082 : (-f) '' {n : \u2124 | n > 0} = (\u03bb x,-x) '' (f ''{n : \u2124 | n > 0}),\n        {   ext1;intros,split;intros,\n            {   apply (set.mem_image _ _ _).2,\n                apply (set.mem_image _ _ _).2,\n                rcases (set.mem_image _ _ _).1 a with \u27e8y,hy,hy'\u27e9,\n                rw \u2190hy',\n                use (f y),\n                exact \u27e8(set.mem_image _ _ _).2 \u27e8y,hy,rfl\u27e9,rfl\u27e9\n                },\n            {   apply (set.mem_image _ _ _).2,\n                rcases (set.mem_image _ _ _).1 a with \u27e8y,hy,hy'\u27e9,\n                rcases (set.mem_image _ _ _).1 hy with \u27e8z,hz,hz'\u27e9,\n                rw [\u2190hy',\u2190hz'] at *,\n                use z, exact \u27e8hz,rfl\u27e9\n            }},\n        have h\u2083 : (-f) '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0} = (\u03bb x,-x) '' (f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n < 0}),\n        {   rw [\u2190set.image_inter neg_injective,\u2190h\u2081,\u2190h\u2082]},\n        rw h\u2083 at hh,\n        apply (@set.finite_image_iff _ _ _ has_neg.neg _).1 hh,\n        apply set.inj_on.mono (set.subset_univ _),\n        exact set.injective_iff_inj_on_univ.1 neg_injective\n    }\nend\n\nlemma lemma5_not_i_of_ii (f : \u2124 \u2192 \u2124) : \n    (\u2200 C>0,\u2203 N,\u2200 p>N, f p > C) \u2192 \u00ac(\u2203 C, \u2200 p, abs (f p) < C) :=\nbegin\n    intros h hn,\n    rcases hn with \u27e8C,hC\u27e9,\n    rcases h C (lt_of_le_of_lt (abs_nonneg _) (hC 0)) with \u27e8N,hN\u27e9,\n    have h\u2081 := (abs_lt.1 (hC (N+1))).2,\n    have h\u2082 := hN (N+1) (by linarith),\n    linarith\nend\n\nlemma lemma5_not_iii_of_i (f : \u2124 \u2192 \u2124) : \n    (\u2203 C, \u2200 p, abs (f p) < C) \u2192 \u00ac(\u2200 C>0,\u2203 N,\u2200 p>N, f p < -C) :=\nbegin\n    intros h hn,\n    rcases h with \u27e8C,hC\u27e9,\n    rcases hn C (lt_of_le_of_lt (abs_nonneg _) (hC 0)) with \u27e8N,hN\u27e9,\n    have h\u2081 := (abs_lt.1 (hC (N+1))).1,\n    have h\u2082 := hN (N+1) (lt_add_one _),\n    linarith\nend\n\nlemma lemma5_not_iii_of_ii (f : \u2124 \u2192 \u2124) :\n    (\u2200 C>0,\u2203 N>0,\u2200 p>N, f p > C) \u2192 \u00ac(\u2200 C>0,\u2203 N>0,\u2200 p>N, f p < -C) :=\nbegin\n    intros h hn,\n    rcases h 1 (by linarith) with \u27e8N,hN,hN'\u27e9,\n    rcases hn 1 (by linarith) with \u27e8M,hM,hM'\u27e9,\n    have h\u2081 := hN' (max (N+1) (M+1)) (lt_max_iff.2 (or.inl (lt_add_one N))),\n    have h\u2082 := hM' (max (N+1) (M+1)) (lt_max_iff.2 (or.inr (lt_add_one M))),\n    linarith\nend\n\nlemma lemma5_not_ii_of_iii (f : \u2124 \u2192 \u2124) :\n    (\u2200 C>0,\u2203 N>0,\u2200 p>N, f p < -C) \u2192 \u00ac(\u2200 C>0,\u2203 N>0,\u2200 p>N, f p > C) :=\nbegin\n    intros h hn,\n    rcases h 1 (by linarith) with \u27e8N,hN,hN'\u27e9,\n    rcases hn 1 (by linarith) with \u27e8M,hM,hM'\u27e9,\n    have h\u2081 := hN' (max (N+1) (M+1)) (lt_max_iff.2 (or.inl (lt_add_one N))),\n    have h\u2082 := hM' (max (N+1) (M+1)) (lt_max_iff.2 (or.inr (lt_add_one M))),\n    linarith\nend\n\nlemma lemma5_aux_iff (f : \u2124 \u2192 \u2124) (hf : almost_homomorphism f) :\n    set.infinite ((f ''{n | n > 0}) \u2229 {n | n>0}) \u2194 (\u2200 C>0,\u2203 N>0,\u2200 p>N, f p > C) :=\n\u27e8\u03bb h,lemma5_aux f hf h,\u03bb h hn,\n    begin\n        replace hn : \u00ac(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite,\n        {   simp [set.infinite,not_not],exact hn},\n        have h\u2081 := or.resolve_left (infinite_or f) hn,\n        cases h\u2081 with h' h',\n        {   have h\u2082 := lemma5_neg_aux f hf h',\n            exact lemma5_not_iii_of_ii f h h\u2082},\n        {   replace h':=bounded_lt_of_le f h',\n            rcases h' with \u27e8C,hC\u27e9,\n            rcases h C (lt_of_le_of_lt (abs_nonneg _) (hC 1 (by linarith))) with \u27e8N,hN,hN'\u27e9,\n            have h\u2082 := hN' (max (N+1) 1) (lt_max_iff.2 (or.inl (lt_add_one N))),\n            have h\u2083 := (abs_lt.1 (hC (max (N+1) 1) (lt_max_iff.2 (or.inr (int.one_pos))))).2,\n            linarith }\n    end\u27e9\n\n\nlemma lemma5 (f : \u2124 \u2192 \u2124) (hf : almost_homomorphism f) :\n      (\u2203 C, \u2200 p, abs (f p) < C) \n    \u2228 (\u2200 C>0,\u2203 N>0,\u2200 p>N, f p > C)\n    \u2228 (\u2200 C>0,\u2203 N>0,\u2200 p>N, f p < -C):=\nbegin\ncases infinite_or f with h h',\n{   \n    apply or.inr, apply or.inl,\n    exact lemma5_aux f hf h\n}, \n{   cases h' with h h,\n{   apply or.inr, apply or.inr,\n    exact lemma5_neg_aux f hf h\n},\n\n{   apply or.inl,\n    rcases bounded_lt_of_le f h with \u27e8C,hC\u27e9,\n    rcases hf with \u27e8D,hD\u27e9,\n    use (C+D+abs (f 0)), intro p,\n    cases lt_trichotomy 0 p with hp hp',\n    {   linarith [hC p hp,abs_nonneg (f 0),lt_of_le_of_lt (abs_nonneg _) (hD 1 1)]},\n    cases hp' with hp hp,\n    {   rw [\u2190hp],linarith [lt_of_le_of_lt (abs_nonneg _) (hD 1 1),lt_of_le_of_lt (abs_nonneg _) (hC 1 (by norm_num))]},\n    {   have h\u2081 : f p = f 0 - f (-p) - (f (p + (-p)) - f p - f (-p)),\n        {   simp,ring},\n        have h\u2082 : abs (f (p + -p) - f p - f (-p)) < D,from hD _ _,\n        have h\u2083 : abs (f (-p)) < C,from hC _ (by linarith),\n        calc abs (f p) \n                = abs (f 0 + -f (-p) + -(f (p + (-p)) - f p - f (-p))) : congr_arg _ h\u2081\n            ... \u2264 abs (f 0) + abs (-f (-p)) + abs (-(f (p + (-p)) - f p - f (-p))) : abs_add_three _ _ _\n            ... = abs (f 0) + abs (f (-p)) + abs (f (p + (-p)) - f p - f (-p)) : by rw [abs_neg,abs_neg]\n            ... < C + D + abs (f 0) : by linarith\n}}},\n\nend\n\nclass pos_add_comm_group (\u03b1 : Type*) extends add_comm_group \u03b1 :=\n(pos : \u03b1 \u2192 Prop)\n(zero_nonpos : \u00ac pos 0)\n(add_pos : \u2200 {x y}, pos x \u2192 pos y \u2192 pos (x + y))\n(pos_antisymm : \u2200 {x}, (pos x \u2194 pos (-x)) \u2192 x = 0) -- if x\u22600, then either x or -x is positive\n\nsection\n\nopen pos_add_comm_group\n\ninstance pos_add_comm_group.to_nonneg_add_comm_group (\u03b1 : Type*) [s : pos_add_comm_group \u03b1] : \n nonneg_add_comm_group \u03b1 := \n{ \n  nonneg := \u03bb x,\u00ac pos (-x),\n  pos := pos,\n  pos_iff := \u03bb x,\u27e8\u03bb h,\u27e8or.elim (classical.em (x = 0)) (\u03bb hx,false.elim (zero_nonpos (by rwa hx at h))) \n    (\u03bb hx hn,hx (pos_antisymm (iff_of_true h hn))),\n    by simp;exact h\u27e9,\u03bb h,by simp at h;exact h.2\u27e9,\n  zero_nonneg := by simp;exact zero_nonpos,\n  add_nonneg := \u03bb x y hx hy hn,\n  begin\n    by_cases hx':x=0,\n    {   simp [hx'] at hn,\n        apply hy hn},\n    {   by_cases hy':y=0,\n        {   simp [hy'] at hn,\n        apply hx hn},\n        {   have h\u2081 : \u2200 {p q : Prop},\u00ac(p\u2194q) \u2192 (p \u2227 \u00acq) \u2228 (\u00acp \u2227 q),tauto,\n            have hhx:= h\u2081 ((mt pos_antisymm) hx'),\n            have hhy:= h\u2081 ((mt pos_antisymm) hy'),\n            cases hhx with hhx' hhx',\n            {   cases hhy with hhy' hhy',\n                {   have h\u2082 := add_pos hhx'.1 hhy'.1,\n                    have h\u2083 := add_pos h\u2082 hn,\n                    rw [\u2190sub_eq_add_neg,sub_self] at h\u2083 ,\n                    exact zero_nonpos h\u2083 },\n                {   exact hy hhy'.2}},\n            {   exact hx hhx'.2}}},\n  end,\n  nonneg_antisymm := \u03bb x h hh,\n  begin\n    rw [neg_neg] at hh,\n    exact pos_antisymm (iff_of_false hh h)\n  end,\n  ..s }\n\nend\n\n\nlemma iff_infinite_pos_of_pos_of_bounded_difference (f g : \u2124 \u2192 \u2124) \n    (hf : almost_homomorphism f) (hg : almost_homomorphism g) (h : bounded_difference f g): \n    (f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite \u2194\n    (g '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite :=\nbegin\nrcases h with \u27e8C,hC\u27e9,\nsimp [lemma5_aux_iff f hf,lemma5_aux_iff g hg],\nsplit,\n{   intros hh D hD,\n    rcases hh (D+C) (add_pos hD (lt_of_le_of_lt (abs_nonneg _) (hC 0))) with \u27e8N,hN,hN'\u27e9,\n    use N,split,{exact hN}, intros p hp,\n    have h\u2081:f p - C < g p, linarith [(abs_lt.1 (hC p)).2],\n    linarith [h\u2081,hN' p hp]\n    },\n{   intros hh D hD,\n    rcases hh (D+C) (add_pos hD (lt_of_le_of_lt (abs_nonneg _) (hC 0))) with \u27e8N,hN,hN'\u27e9,\n    use N,split,{exact hN}, intros p hp,\n    have h\u2081:g p - C < f p, linarith [(abs_lt.1 (hC p)).1],\n    linarith [h\u2081,hN' p hp]}\nend\n\n@[simp]\ndef S.pos (T : S) : Prop := (T.func '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite\n\nlemma S.zero_nonpos : \u00acS.pos 0 := \nbegin \n    simp [set.infinite,not_not],\n    rw [@set.nonempty.image_const _ _ ({n : \u2124 | n > 0}) \u27e81,by norm_num\u27e9],\n    apply @set.finite.subset _ ({0}:set \u2124) (set.finite_singleton 0) ({0} \u2229 {n : \u2124 | n > 0}),\n    exact ({0}:set \u2124).inter_subset_left {n : \u2124 | n > 0}\nend\n\n\nlemma S.add_pos {T\u2081 T\u2082 : S} : S.pos T\u2081 \u2192 S.pos T\u2082 \u2192 S.pos (T\u2081 + T\u2082) :=\n\u03bb hT\u2081 hT\u2082,\n(lemma5_aux_iff _ (T\u2081 + T\u2082).AH).2\n(\u03bb C hC,let \u27e8N,hN,hN'\u27e9:=lemma5_aux _ T\u2081.AH hT\u2081 C hC in \nlet \u27e8M,hM,hM'\u27e9:=lemma5_aux _ T\u2082.AH hT\u2082 C hC in\n\u27e8max N M,lt_max_iff.2 (or.inl hN),\u03bb p hp,calc\n    (T\u2081 + T\u2082).func p \n            = T\u2081.func p + T\u2082.func p : rfl\n        ... > C + C : add_lt_add (hN' _ (max_lt_iff.1 hp).1) (hM' _ (max_lt_iff.1 hp).2)\n        ... > C : lt_add_of_pos_left C hC\n    \u27e9)\n\ndef E.pos (A : E) : Prop := quot.rec_on A (\u03bb T,S.pos T) \n    (\u03bb T\u2081 T\u2082 h,by simp at *;exact iff_infinite_pos_of_pos_of_bounded_difference _ _ T\u2081.AH T\u2082.AH h)\n\n\nlemma pos_mk (T : S) : E.pos (mk T) \u2194 S.pos T := iff.rfl\n\nlemma pos_mk_setoid (T : S) : E.pos (quot.mk setoid.r T) \u2194 S.pos T := iff.rfl\n\nlemma neg_mk_setoid (T : S) : (-quot.mk setoid.r T:E) = quot.mk setoid.r (-T):= rfl\n\n\ninstance : pos_add_comm_group E := \n{ pos := \u03bb A, E.pos A,\n zero_nonpos := by simp [pos_mk];exact S.zero_nonpos,\n  add_pos := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};intros;exact S.add_pos a_1 a_2,\n  pos_antisymm :=\n  begin\n    intro A,\n    induction A with T,\n    {   simp only [pos_mk_setoid,neg_mk_setoid,S.pos],\n        rw [lemma5_aux_iff T.func T.AH,lemma5_aux_iff (-T).func (-T).AH],\n        intro h,\n        have h\u2081 : \u2200 {p q r : Prop}, (p \u2228 q \u2228 r) \u2227 (q \u2194 r) \u2227 (r \u2192 \u00acq) \u2194 (p \u2227 \u00acq \u2227 \u00acr), tauto,\n        rw [neg_S_func_eq] at h,\n        simp only [int_to_int_neg] at h,\n        have h\u2082 : (\u2200 (C : \u2124), C > 0 \u2192 (\u2203 N>0, \u2200 (p : \u2124), p > N \u2192 -T.func p > C)) \u2194 \n            (\u2200 (C : \u2124), C > 0 \u2192 (\u2203 N>0, \u2200 (p : \u2124), p > N \u2192 T.func p < -C)), simp [lt_neg],\n        rw h\u2082 at h,\n        have h\u2083 := h\u2081.1 \u27e8lemma5 T.func T.AH, h,lemma5_not_ii_of_iii _\u27e9,\n        apply quotient.eq.2,\n        simp [(\u2248),setoid.r,bounded_difference],\n        exact h\u2083.1},\n    {   tauto}\n  end,\n  .. E.add_comm_group }\n\ninstance int_to_int.has_mul : has_mul (\u2124 \u2192 \u2124) := \u27e8\u03bb f g, f \u2218 g\u27e9\n\ninstance int_to_int.has_one : has_one (\u2124 \u2192 \u2124) := \u27e8id\u27e9\n\n@[simp] \nlemma int_to_int.one_def : (1:\u2124 \u2192 \u2124) = id := rfl\n\n@[simp]\nlemma int_to_int.mul_def (f g : \u2124 \u2192 \u2124) : f * g = f \u2218 g := rfl\n\nlemma int_to_int.one_mul (f : \u2124 \u2192 \u2124) : 1 * f = f := rfl\n\nlemma int_to_int.mul_one (f : \u2124 \u2192 \u2124) : f * 1 = f := rfl\n\nlemma int_to_int.mul_assoc (f g h : \u2124 \u2192 \u2124) : f * g * h = f * (g * h) := rfl\n\nlemma int_to_int.right_distrib (f g h : \u2124 \u2192 \u2124) : (f + g) * h = f * h + g * h := rfl\n\nlemma almost_homomorphism_three (f : \u2124 \u2192 \u2124) (hf : almost_homomorphism f) :\n    \u2203 C,\u2200 p q r, abs (f (p + q + r) - f p - f q - f r) < C :=\nlet \u27e8C,hC\u27e9:=hf in \u27e8C+C,\u03bb p q r,calc\n    abs (f (p + q + r) - f p - f q - f r) \n            = abs (f (p + q + r) - f (p + q) - f r + (f (p + q) - f p - f q)) : congr_arg abs (by ring)\n        ... \u2264 abs ( f (p + q + r) - f (p + q) - f r) + abs (f (p + q) - f p - f q) : abs_add _ _\n        ... < C + C : add_lt_add (hC _ _) (hC _ _)  \u27e9\n\n\nlemma bounded_image (f : \u2124 \u2192 \u2124) (g : \u2124 \u2192 \u2124 \u2192 \u2124) (hg : \u2203 C,\u2200 p q,abs (g p q) < C) :\n    \u2203 C, \u2200 p q, abs (f (g p q)) < C :=\nlet \u27e8C,hC\u27e9:=hg in let \u27e8E,hE\u27e9:=exists_max_of_ico f C (-C) \n(lt_trans (neg_lt_zero.2 (lt_of_le_of_lt (abs_nonneg _) (hC 0 0))) (lt_of_le_of_lt (abs_nonneg _) (hC 0 0))) in\n\u27e8E,\u03bb p q,hE _ (le_of_lt (abs_lt.1 (hC p q)).1) (abs_lt.1 (hC p q)).2\u27e9\n\nlemma almost_homomorphism_mul (f g : \u2124 \u2192 \u2124) \n    (hf : almost_homomorphism f) (hg : almost_homomorphism g) :\n    almost_homomorphism (f * g) :=\nlet \u27e8Cf,hCf\u27e9:=almost_homomorphism_three f hf in \nlet \u27e8E,hE\u27e9 := bounded_image f _ hg in\n\u27e8Cf + E,\u03bb p q, calc\n    abs ((f * g) (p + q) - (f * g) p - (f * g) q) \n            = abs ( f (g (p + q)) - f (g p) - f (g q) ) : rfl\n        ... = abs ( f (g p + g q + (g (p + q) - g p - g q)) - f (g p) - f (g q) - f (g (p + q) - g p - g q) + f (g (p + q) - g p - g q)) : congr_arg abs $ by simp;ring\n        ... \u2264 abs (f (g p + g q + (g (p + q) - g p - g q)) - f (g p) - f (g q) - f (g (p + q) - g p - g q)) + abs (f (g (p + q) - g p - g q)) : abs_add _ _\n        ... < Cf + E : add_lt_add (hCf _ _ _) (hE _ _)\u27e9\n\ninstance : has_mul S := \u27e8\u03bb T\u2081 T\u2082, \u27e8T\u2081.func*T\u2082.func,almost_homomorphism_mul _ _ T\u2081.AH T\u2082.AH\u27e9\u27e9\n\ninstance : has_one S := \u27e8\u27e81,\u27e81,\u03bb p q,by simp;exact int.one_pos\u27e9\u27e9\u27e9\n\n@[simp]\nlemma S.mul_func (T\u2081 T\u2082 : S) : (T\u2081 * T\u2082).func = T\u2081.func * T\u2082.func := rfl \n@[simp]\nlemma S.one_mul (T :S) : 1 * T = T := func_eq rfl\n@[simp]\nlemma S.mul_one (T :S) : T * 1 = T := func_eq rfl\n@[simp]\nlemma S.mul_assoc (T\u2081 T\u2082 T\u2083 : S) : T\u2081 * T\u2082 * T\u2083 = T\u2081 * (T\u2082 * T\u2083) := rfl\n@[simp]\nlemma S.right_distrib (T\u2081 T\u2082 T\u2083 : S) : (T\u2081 + T\u2082) * T\u2083 = T\u2081 * T\u2083 + T\u2082 * T\u2083 := rfl\n\n\nlemma aux_bounded_difference {f\u2081 f\u2082 : \u2124 \u2192 \u2124} (h : bounded_difference f\u2081 f\u2082) :\n\u2203 (g : \u2124 \u2192 \u2124) (hg : \u2203 C, \u2200 p, abs (g p) < C), f\u2081 = f\u2082 + g :=\n\u27e8f\u2081-f\u2082,h,eq_add_of_sub_eq' rfl\u27e9\n\nlemma bounded_difference_mul {f\u2081 g\u2081 f\u2082 g\u2082 : \u2124 \u2192 \u2124}\n    (hf : bounded_difference f\u2081 f\u2082) (hg : bounded_difference g\u2081 g\u2082) (hf\u2082 : almost_homomorphism f\u2082) :\n    bounded_difference (f\u2081 * g\u2081) (f\u2082 * g\u2082) :=\nlet \u27e8Cf,hff\u27e9 := hf\u2082 in\nlet \u27e8f,\u27e8Cf',hCf\u27e9,hhf\u27e9:=aux_bounded_difference hf in\nlet \u27e8g,\u27e8Cg',hCg\u27e9,hhg\u27e9:=aux_bounded_difference hg in\nlet \u27e8E,hE\u27e9:=exists_max_of_ico f\u2082 Cg' (-Cg')\n(lt_trans (neg_lt_zero.2 (lt_of_le_of_lt (abs_nonneg (g 0)) (hCg 0))) (lt_of_le_of_lt (abs_nonneg (g 0)) (hCg 0))) in\n\u27e8E + Cf + Cf' + 1,\u03bb p,by rw [hhf,hhg];simp;\nexact calc abs (f\u2082 (g\u2082 p + g p) + f (g\u2082 p + g p) - f\u2082 (g\u2082 p))\n        = abs (f\u2082 (g\u2082 p + g p) - f\u2082 (g\u2082 p) + f (g\u2082 p + g p)) : congr_arg abs (by ring)\n    ... \u2264 abs (f\u2082 (g\u2082 p + g p) - f\u2082 (g\u2082 p)) + abs (f (g\u2082 p + g p)) : abs_add _ _\n    ... \u2264 abs (f\u2082 (g\u2082 p + g p) - f\u2082 (g\u2082 p)) + Cf' : add_le_add_left (le_of_lt (hCf _)) _\n    ... = abs (f\u2082(g p) + (f\u2082 (g\u2082 p + g p) - f\u2082 (g\u2082 p) - f\u2082 (g p))) + Cf' : by simp;exact congr_arg abs (by ring)\n    ... \u2264 abs (f\u2082 (g p)) + abs (f\u2082 (g\u2082 p + g p) - f\u2082 (g\u2082 p) - f\u2082 (g p)) + Cf' : add_le_add_right (abs_add _ _) _\n    ... \u2264 abs (f\u2082 (g p)) + Cf + Cf' : add_le_add_right (add_le_add_left (le_of_lt (hff _ _)) _) _\n    ... \u2264 E + Cf + Cf' : add_le_add_right (add_le_add_right (le_of_lt (hE _ (le_of_lt (abs_lt.1 (hCg _)).1) ((abs_lt.1 (hCg _)).2))) _) _\n    ... < E + Cf + Cf' + 1 : lt_add_one (E + Cf + Cf')\u27e9\n\ninstance : has_one E := \u27e8mk 1\u27e9\n\ninstance : has_mul E := \u27e8\u03bb x y,quotient.lift_on\u2082 x y (\u03bb F G, mk (F * G)) $\n    \u03bb F\u2081 G\u2081 F\u2082 G\u2082 hF hG, quotient.sound $\n    (by dsimp [(\u2248),setoid.r] at *;exact bounded_difference_mul hF hG F\u2082.AH)\u27e9\n\n@[simp] theorem mk_mul (F G : S) : mk F * mk G = mk (F * G) := rfl\n@[simp] theorem mk_one : 1 = mk 1  := rfl\n\n\n@[simp]\nlemma E.mul_func (T\u2081 T\u2082 : E) : (T\u2081 * T\u2082) = T\u2081 * T\u2082 := rfl \n@[simp]\nlemma E.one_mul: \u2200 T:E, 1 * T = T := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp\n@[simp]\nlemma E.mul_one: \u2200 T:E, T * 1 = T := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp\n@[simp]\nlemma E.mul_assoc : \u2200 (T\u2081 T\u2082 T\u2083 : E), T\u2081 * T\u2082 * T\u2083 = T\u2081 * (T\u2082 * T\u2083) := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp\n@[simp]\nlemma E.right_distrib : \u2200 (T\u2081 T\u2082 T\u2083 : E), (T\u2081 + T\u2082) * T\u2083 = T\u2081 * T\u2083 + T\u2082 * T\u2083 := by repeat {refine \u03bb a, quotient.induction_on a (\u03bb _, _)};simp\n\nlemma lemma7_aux {f : \u2124 \u2192 \u2124} {C : \u2124} (hC : \u2200 (p q : \u2124), abs (f (p + q) - f p - f q) < C) : \u2200 p q,abs (f (p*q) - p * f q) < ( abs p + 1) * C :=\n\u03bb p q,\nhave h\u2082:\u2200 p,abs (f ((p+1)*q) - f (p*q) - f q) < C,from \u03bbp, calc\n    abs (f ((p+1)*q) - f (p*q) - f q) \n            = abs (f (p*q + q) - f (p*q) - f q) : by rw [right_distrib,one_mul]\n        ... < C : hC _ _,\nhave h\u2082':\u2200 p:\u2115,abs (f ((-\u2191p - 1) * q) - f (-\u2191p * q) + f q) < C,from \u03bbp, calc\n    abs (f ((-\u2191p - 1) * q) - f (-\u2191p * q) + f q)\n            = abs (- (f ((-\u2191p-1)*q + q) - f ((-\u2191p-1)*q) - f q)) : have hh: (-\u2191p - 1) * q + q=-p*q,from by ring,congr_arg abs (by rw [hh];ring)\n        ... = abs (f ((-\u2191p-1)*q + q) - f ((-\u2191p-1)*q) - f q) : abs_neg _\n        ... < C : hC _ _,\nint.induction_on p (by have h\u2081:=hC 0 0;simp at *;exact h\u2081) \n    (\u03bb i hi,calc\n    abs (f ((\u2191i + 1) * q) - (\u2191i + 1) * f q)\n            = abs ((f ((\u2191i + 1) * q) - f (\u2191i * q) - f q) + (f (\u2191i * q) - \u2191i * f q)) : congr_arg abs (by ring)\n        ... \u2264 abs (f ((\u2191i + 1) * q) - f (\u2191i * q) - f q) + abs (f (\u2191i * q) - \u2191i * f q) : abs_add _ _\n        ... < C + (abs \u2191i + 1) * C : add_lt_add (h\u2082 _) hi\n        ... = ( abs \u2191i + 1 + 1) * C: by ring\n        ... = ( abs \u2191(i + 1) + 1) * C : have h\u2083:abs (\u2191i:\u2124) = \u2191i,from abs_of_nonneg (int.coe_zero_le i),\n                                        have h\u2083':abs (\u2191i+1:\u2124) = \u2191i+1,from abs_of_nonneg (int.coe_zero_le _),\n                                    by simp [h\u2083,h\u2083'])\n    (\u03bb i hi,by simp at *;exact calc\n    abs (f ((-\u2191i - 1) * q) - (-\u2191i - 1) * f q) \n            = abs ((f ((-\u2191i - 1) * q) - f (-\u2191i * q) + f q) + (f (-\u2191i * q) - -\u2191i * f q)) : congr_arg abs (by ring)\n        ... \u2264 abs (f ((-\u2191i - 1) * q) - f (-\u2191i * q) + f q) + abs (f (-\u2191i * q) - -\u2191i * f q) : abs_add _ _\n        ... < C + (\u2191i + 1) * C : have hh':\u2200 q:\u2124,-(\u2191i * q)=-\u2191i * q,from \u03bbq,neg_mul_eq_neg_mul \u2191i q,add_lt_add (hh' q \u25b8 h\u2082' i) (by rw [\u2190hh',\u2190hh',sub_neg_eq_add];exact hi)\n        ... = (\u2191(i + 1) + 1) * C : by ring\n        ... = (abs (\u2191(i + 1)) + 1) * C : by rw [abs_of_nonneg (int.coe_zero_le (i+1))]\n        ... = (abs (-(\u2191i + 1)) + 1)*C:by ring\n        ... = (abs (-\u2191i - 1) + 1) * C : by rw [neg_add,\u2190sub_eq_add_neg])\n\n\nlemma lemma7 {f : \u2124 \u2192 \u2124} (C : \u2124) (hC : \u2200 (p q : \u2124), abs (f (p + q) - f p - f q) < C) : \u2200 p q, abs (p * f q - q * f p) < (abs p + abs q + 2) * C :=\n\u03bb p q,\nbegin\nhave h\u2081 := lemma7_aux hC p q,\nhave h\u2082 := lemma7_aux hC q p,\nrw [\u2190abs_neg,neg_sub,mul_comm p q] at h\u2081,\nexact calc abs (p * f q - q * f p) \n        \u2264 abs (p * f q - f (q * p)) + abs (f (q * p) - q * f p) : abs_sub_le _ _ _\n    ... < (abs p + 1) * C + (abs q + 1) * C : add_lt_add h\u2081 h\u2082 \n    ... = (abs p + abs q + 2) * C : by ring\nend\n\nlemma upper_bound {f : \u2124 \u2192 \u2124} (hf : almost_homomorphism f) : \u2203 A B,\u2200 p,abs (f p) < A * abs p + B :=\nlet \u27e8C,hC\u27e9:=hf in \u27e8C + abs (f 1),3*C,\u03bb p,\nbegin\n    have h\u2081:=lemma7 C hC p 1,\n    simp [abs_sub] at h\u2081,ring at h\u2081,rw [mul_comm (f 1)] at h\u2081,\n    exact calc \n        abs (f p) = abs (f p - p * f 1 + p * f 1) : by ring\n            ... \u2264 abs (f p - p * f 1) + abs (p * f 1) : abs_add _ _\n            ... < C * abs p + 3 * C + abs (p * f 1) : add_lt_add_right h\u2081 _\n            ... = (C + abs (f 1)) * abs p + 3 * C : by rw [abs_mul];ring\nend\u27e9\n\n--lemma mul_eq_mk (A B : S) : (quot.mk setoid.r A:E) * (quot.mk setoid.r B:E) = quot.mk setoid.r B * quot.mk setoid.r A\n@[simp]\nlemma E.mul_comm (F G : E) : F * G = G * F :=\nbegin\ninduction F with f,induction G with g,\n{refine mk_eq.mpr _,\nsimp [(\u2248),setoid.r],\nrcases upper_bound f.AH with \u27e8A,B,hf\u27e9,\nrcases upper_bound g.AH with \u27e8C,D,hg\u27e9,\nrcases f.AH with \u27e8Cf,hCf\u27e9,\nrcases g.AH with \u27e8Cg,hCg\u27e9,\nset C':=max Cf Cg,\nuse max ((B + D + 4) * C' + (2 + A + C) * C' + 1) (abs (f.func (g.func 0) - g.func (f.func 0))+1),\nintro p,\nby_cases hp:p=0,\n{   simp [hp],\n    exact or.inr int.one_pos},\n{\nhave h\u2081:=lemma7 C' (\u03bb p q,lt_of_lt_of_le (hCf p q) (le_max_left _ _)) p (g.func p),\nhave h\u2082:=lemma7 C' (\u03bb p q,lt_of_lt_of_le (hCg p q) (le_max_right _ _)) p (f.func p),\nrw [abs_sub,mul_comm (f.func p)] at h\u2082,\nhave h\u2083:abs (p)*abs(f.func (g.func p) - g.func (f.func p)) < ((2 + A + C)*C') * abs p + (B + D + 4)*C',\n    from calc\n        abs p * abs (f.func (g.func p) - g.func (f.func p))     \n            = abs (p*f.func (g.func p) - p*g.func (f.func p)) : by rw [\u2190abs_mul,mul_sub]\n        ... \u2264 abs (p * f.func (g.func p) - g.func p * f.func p) + abs (g.func p * f.func p - p * g.func (f.func p)) : abs_sub_le _ _ _\n        ... < (abs p + abs (g.func p) + 2) * C' + (abs p + abs (f.func p) + 2) * C' : add_lt_add h\u2081 h\u2082\n        ... = ( 2*abs p + abs (f.func p) + abs (g.func p) + 4)*C' : by ring\n        ... < (2*abs p + (A * abs p + B) + (C * abs p + D) + 4) * C' : \n            mul_lt_mul_of_pos_right (add_lt_add_right (add_lt_add (add_lt_add_left (hf p) _) (hg p)) _)\n            (lt_max_iff.2 (or.inl (lt_of_le_of_lt (abs_nonneg _) (hCf 1 1))))\n        ... = ((2 + A + C)*C') * abs p + (B + D + 4)*C' : by ring,\nrw [mul_comm (abs p)] at h\u2083,\nhave B_nonneg : B \u2265 0,{\nhave h':=hf 0, simp at h',\nexact le_of_lt (lt_of_le_of_lt (abs_nonneg _) h')\n},\nhave D_nonneg : D \u2265 0,{\nhave h':=hg 0, simp at h',\nexact le_of_lt (lt_of_le_of_lt (abs_nonneg _) h')\n},\nhave C'_nonneg : C'\u22650,{\n    exact le_max_left_of_le (le_of_lt (lt_of_le_of_lt (abs_nonneg _) (hCf 0 0)))\n},\nhave h\u2084:=int.le_div_of_mul_le (abs_pos.mpr hp) (le_of_lt h\u2083),\nrw [add_comm ((2 + A + C) * C' * abs p),int.add_mul_div_right _ _ (mt ((@abs_eq_zero _ _ p).1) hp)] at h\u2084,\nexact calc\nabs ((f.func \u2218 g.func) p - (g.func \u2218 f.func) p)\n        \u2264 (B + D + 4) * C' / abs p + (2 + A + C) * C' : h\u2084\n    ... \u2264 (B + D + 4) * C' + (2 + A + C) * C' : add_le_add_right (int.div_le_self _ \n    (mul_nonneg (add_nonneg (add_nonneg B_nonneg D_nonneg) (by norm_num)) C'_nonneg)) _\n    ... < (B + D + 4) * C' + (2 + A + C) * C' + 1 : lt_add_one ((B + D + 4) * C' + (2 + A + C) * C')\n    ... \u2264 max ((B + D + 4) * C' + (2 + A + C) * C' + 1) (abs (f.func (g.func 0) - g.func (f.func 0))+1) : le_max_left _ _,\n},\n},\n{refl},{refl}\nend\n\n@[simp]\nlemma E.left_distrib : \u2200 (T\u2083 T\u2081 T\u2082 : E), T\u2083 * (T\u2081 + T\u2082) = T\u2083 * T\u2081 + T\u2083 * T\u2082 :=\n\u03bb T\u2083 T\u2081 T\u2082,by rw [E.mul_comm,E.right_distrib,E.mul_comm,E.mul_comm T\u2082]\n\ninstance : comm_ring E := { add := _,\n  mul := (*),\n  mul_assoc := E.mul_assoc,\n  one := 1,\n  one_mul := E.one_mul,\n  mul_one := E.mul_one,\n  left_distrib := E.left_distrib,\n  right_distrib := E.right_distrib,\n  mul_comm := E.mul_comm,\n  ..E.add_comm_group }\n\nlemma almost_homomorphism_of_pos {f : \u2124 \u2192 \u2124} \n    (h\u2081 : \u2200 p<0, f p = - f (-p)) \n    (h\u2082:\u2203 C,\u2200 m n:\u2115, abs (f (m+n) - f m - f n) < C) :\n    almost_homomorphism f := \nlet \u27e8C,hC\u27e9:=h\u2082 in \u27e8C,\u03bb p q,\nbegin\ncases le_or_gt 0 p with hp hp;\ncases le_or_gt 0 q with hq hq,\n{   rcases int.eq_coe_of_zero_le hp with \u27e8m,hm\u27e9,\n    rcases int.eq_coe_of_zero_le hq with \u27e8n,hn\u27e9,\n    simp [hm,hn],\n    exact hC _ _},\n{   cases lt_or_ge (p+q) 0 with hpq hpq,\n    {   have h\u2081:abs (f (p + q) - f p - f q) = abs (f (p + -(p+q)) - f p - f (-(p+q))),\n        {rw [h\u2081 (p+q) hpq,h\u2081 q hq];simp;exact congr_arg abs (by ring)},\n        rcases int.eq_coe_of_zero_le hp with \u27e8m,hm\u27e9,\n        rcases int.eq_coe_of_zero_le ((neg_nonneg.2 (le_of_lt hpq))) with \u27e8n,hn\u27e9,\n        rw [h\u2081,hn,hm],exact hC _ _},\n    {   have h\u2081:abs (f (p + q) - f p - f q) = abs (f ((p+q) + -q) - f (p+q) - f (-q)),\n        {rw [h\u2081 q hq];simp;rw [\u2190abs_neg];exact congr_arg abs (by ring)},\n        rcases int.eq_coe_of_zero_le hpq with \u27e8m,hm\u27e9,\n        rcases int.eq_coe_of_zero_le (neg_nonneg.2 (le_of_lt hq)) with \u27e8n,hn\u27e9,\n        rw [h\u2081,hm,hn],exact hC _ _}},\n{   cases lt_or_ge (p+q) 0 with hpq hpq,\n    {   have h\u2081:abs (f (p + q) - f p - f q) = abs (f (q + -(p+q)) - f q - f (-(p+q))),\n        {rw [h\u2081 (p+q) hpq,h\u2081 p hp];simp;exact congr_arg abs (by ring)},\n        rcases int.eq_coe_of_zero_le hq with \u27e8m,hm\u27e9,\n        rcases int.eq_coe_of_zero_le ((neg_nonneg.2 (le_of_lt hpq))) with \u27e8n,hn\u27e9,\n        rw [h\u2081,hn,hm],exact hC _ _},\n    {   have h\u2081:abs (f (p + q) - f p - f q) = abs (f ((p+q) + -p) - f (p+q) - f (-p)),\n        {rw [h\u2081 p hp];simp;rw [\u2190abs_neg];exact congr_arg abs (by ring)},\n        rcases int.eq_coe_of_zero_le hpq with \u27e8m,hm\u27e9,\n        rcases int.eq_coe_of_zero_le (neg_nonneg.2 (le_of_lt hp)) with \u27e8n,hn\u27e9,\n        rw [h\u2081,hm,hn],exact hC _ _}},\n{   have hp':-p\u22650,from (neg_nonneg.mpr (le_of_lt hp)),\n    have hq':-q\u22650,from (neg_nonneg.mpr (le_of_lt hq)),\n    rcases int.eq_coe_of_zero_le hp' with \u27e8m,hm\u27e9,\n    rcases int.eq_coe_of_zero_le hq' with \u27e8n,hn\u27e9,\n    have h':abs (f (p + q) - f p - f q) = abs (f (-p + -q) - f (-p) - f (-q)),\n    by rw [h\u2081 p hp,h\u2081 q hq,h\u2081 (p+q) (add_neg hp hq),neg_add,\u2190abs_neg];exact congr_arg abs (by ring),\n    rw [h',hm,hn], exact hC _ _}\nend\u27e9\n\nlemma quot_exists (F : E) : \u2203 f:S, F = mk f := quot.induction_on F (\u03bb f,\u27e8f,rfl\u27e9)\n\nlemma exists_min_of_set_nat (s : set \u2115) (h : \u2203 k,s k) : \u2203 n:\u2115, n \u2208 s \u2227 \u2200 m:\u2115, m \u2208 s \u2192 n \u2264 m :=\nbegin\nuse nat.find h,\nsplit,\n{   exact nat.find_spec h},\n{   intro k,\n    exact nat.find_min' h}\nend\n\nlemma exists_min (f : \u2124 \u2192 \u2124) (hf:almost_homomorphism f) \n(h:(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite) (p : \u2124) (hp : p \u2265 0): \n\u2203 n:\u2124, n>0 \u2227 (f n \u2265 p \u2227 (\u2200 m>0,f m \u2265 p \u2192 n \u2264 m)) :=\nbegin\nhave hh := lemma5_aux' f hf h p hp,\nsimp at hh,\nhave hh_nat : \u2203 (N : \u2115), 0 < N \u2227 p \u2264 f \u2191N,\n    from exists.elim hh (\u03bb N hN,exists.elim (@int.eq_coe_of_zero_le N (le_of_lt hN.1)) \n    (\u03bb M hM,exists.intro M (by rw [hM] at *;exact \u27e8int.coe_nat_pos.mp hN.left,hN.2 _ (le_refl _)\u27e9))),\nhave hh':= exists_min_of_set_nat _ hh_nat,\nrcases hh' with \u27e8N,hN\u27e9, simp [(\u2208)] at hN, unfold set.mem at hN,\nuse N,split,\n{   exact int.coe_nat_pos.mpr hN.1.1}, split,\n{   exact hN.1.2},\nintros m hm hm',\nrcases @int.eq_coe_of_zero_le m (le_of_lt hm) with \u27e8M,hM\u27e9,\nrw [hM] at *,\napply int.coe_nat_le.2,\nexact hN.2 _ \u27e8int.coe_nat_pos.mp hm,hm'\u27e9\nend\n\n\nnoncomputable def g (f : \u2124 \u2192 \u2124) (hf:almost_homomorphism f) (h:(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite): \n    \u2124 \u2192 \u2124\n| (int.of_nat n) := classical.some (exists_min f hf h \u2191n (int.coe_zero_le n))\n| (int.neg_succ_of_nat n) := - classical.some (exists_min f hf h (\u2191n+1) (int.coe_zero_le (n+1)))\n\nlemma g_of_nat_def (f : \u2124 \u2192 \u2124) (hf:almost_homomorphism f) (h:(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite)\n    (p : \u2115) : g f hf h \u2191p = classical.some (exists_min f hf h \u2191p (int.coe_zero_le p)) := rfl\n\nlemma g_nonneg_def (f : \u2124 \u2192 \u2124) (hf:almost_homomorphism f) (h:(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite)\n    (p : \u2124) (hp:p\u22650) : g f hf h p = classical.some (exists_min f hf h p hp) := \n    exists.elim (int.eq_coe_of_zero_le hp) (\u03bb p' hp',by simp [hp',g_of_nat_def])\n\nlemma g_nonneg_def' (f : \u2124 \u2192 \u2124) (hf:almost_homomorphism f) (h:(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite)\n    (p : \u2124) (hp:p\u22650) : g f hf h p > 0 \u2227 (f (g f hf h p) \u2265 p \u2227 (\u2200 m>0,f m \u2265 p \u2192 (g f hf h p) \u2264 m)) :=\n    by simp [g_nonneg_def f hf h p hp];exact classical.some_spec (exists_min f hf h p hp)\n\nlemma g_neg_def (f : \u2124 \u2192 \u2124) (hf:almost_homomorphism f) (h:(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite)\n    (p : \u2124) (hp:p<0) : g f hf h p = - g f hf h (-p) := \nbegin\n    rcases int.eq_neg_succ_of_lt_zero hp with \u27e8p',hp'\u27e9,\n    rw [hp',int.neg_neg_of_nat_succ],\n    refl\nend\n\n-- lemma g_almost_homomorphism (f : \u2124 \u2192 \u2124) (hf:almost_homomorphism f) (h:(f '' {n : \u2124 | n > 0} \u2229 {n : \u2124 | n > 0}).infinite) :\n--     almost_homomorphism (g f hf h) :=\n-- begin\n-- apply almost_homomorphism_of_pos (g_neg_def f hf h),\n-- simp,\n-- end", "meta": {"author": "assassane", "repo": "Eudoxus_reals", "sha": "0ed3ddb22b27439c9005bcb25e0dddaa4ebc3cd5", "save_path": "github-repos/lean/assassane-Eudoxus_reals", "path": "github-repos/lean/assassane-Eudoxus_reals/Eudoxus_reals-0ed3ddb22b27439c9005bcb25e0dddaa4ebc3cd5/src/main.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7425433305720043}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.fintype.sort\n! leanprover-community/mathlib commit 327c3c0d9232d80e250dc8f65e7835b82b266ea5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Finset.Sort\nimport Mathbin.Data.Fintype.Basic\n\n/-!\n# Sorting a finite type\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides two equivalences for linearly ordered fintypes:\n* `mono_equiv_of_fin`: Order isomorphism between `\u03b1` and `fin (card \u03b1)`.\n* `fin_sum_equiv_of_finset`: Equivalence between `\u03b1` and `fin m \u2295 fin n` where `m` and `n` are\n  respectively the cardinalities of some `finset \u03b1` and its complement.\n-/\n\n\nopen Finset\n\n#print monoEquivOfFin /-\n/-- Given a linearly ordered fintype `\u03b1` of cardinal `k`, the order isomorphism\n`mono_equiv_of_fin \u03b1 h` is the increasing bijection between `fin k` and `\u03b1`. Here, `h` is a proof\nthat the cardinality of `\u03b1` is `k`. We use this instead of an isomorphism `fin (card \u03b1) \u2243o \u03b1` to\navoid casting issues in further uses of this function. -/\ndef monoEquivOfFin (\u03b1 : Type _) [Fintype \u03b1] [LinearOrder \u03b1] {k : \u2115} (h : Fintype.card \u03b1 = k) :\n    Fin k \u2243o \u03b1 :=\n  (univ.orderIsoOfFin h).trans <| (OrderIso.setCongr _ _ coe_univ).trans OrderIso.Set.univ\n#align mono_equiv_of_fin monoEquivOfFin\n-/\n\nvariable {\u03b1 : Type _} [DecidableEq \u03b1] [Fintype \u03b1] [LinearOrder \u03b1] {m n : \u2115} {s : Finset \u03b1}\n\n#print finSumEquivOfFinset /-\n/-- If `\u03b1` is a linearly ordered fintype, `s : finset \u03b1` has cardinality `m` and its complement has\ncardinality `n`, then `fin m \u2295 fin n \u2243 \u03b1`. The equivalence sends elements of `fin m` to\nelements of `s` and elements of `fin n` to elements of `s\u1d9c` while preserving order on each\n\"half\" of `fin m \u2295 fin n` (using `set.order_iso_of_fin`). -/\ndef finSumEquivOfFinset (hm : s.card = m) (hn : s\u1d9c.card = n) : Sum (Fin m) (Fin n) \u2243 \u03b1 :=\n  calc\n    Sum (Fin m) (Fin n) \u2243 Sum (s : Set \u03b1) (s\u1d9c : Set \u03b1) :=\n      Equiv.sumCongr (s.orderIsoOfFin hm).toEquiv <|\n        (s\u1d9c.orderIsoOfFin hn).toEquiv.trans <| Equiv.Set.ofEq s.coe_compl\n    _ \u2243 \u03b1 := Equiv.Set.sumCompl _\n    \n#align fin_sum_equiv_of_finset finSumEquivOfFinset\n-/\n\n#print finSumEquivOfFinset_inl /-\n@[simp]\ntheorem finSumEquivOfFinset_inl (hm : s.card = m) (hn : s\u1d9c.card = n) (i : Fin m) :\n    finSumEquivOfFinset hm hn (Sum.inl i) = s.orderEmbOfFin hm i :=\n  rfl\n#align fin_sum_equiv_of_finset_inl finSumEquivOfFinset_inl\n-/\n\n#print finSumEquivOfFinset_inr /-\n@[simp]\ntheorem finSumEquivOfFinset_inr (hm : s.card = m) (hn : s\u1d9c.card = n) (i : Fin n) :\n    finSumEquivOfFinset hm hn (Sum.inr i) = s\u1d9c.orderEmbOfFin hn i :=\n  rfl\n#align fin_sum_equiv_of_finset_inr finSumEquivOfFinset_inr\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Fintype/Sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7424875203254104}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\n\nimport topology.algebra.filter_basis\nimport topology.algebra.uniform_group\n\n/-!\n# Uniform properties of neighborhood bases in topological algebra\n\nThis files contains properties of filter bases on algebraic structures that also require the theory\nof uniform spaces.\n\nThe only result so far is a characterization of Cauchy filters in topological groups.\n\n-/\n\nopen_locale uniformity filter\nopen filter\n\nnamespace add_group_filter_basis\n\nvariables {G : Type*} [add_comm_group G] (B : add_group_filter_basis G)\n\n/-- The uniform space structure associated to an abelian group filter basis via the associated\ntopological abelian group structure. -/\nprotected def uniform_space : uniform_space G :=\n@topological_add_group.to_uniform_space G _ B.topology B.is_topological_add_group\n\n/-- The uniform space structure associated to an abelian group filter basis via the associated\ntopological abelian group structure is compatible with its group structure. -/\nprotected lemma uniform_add_group : @uniform_add_group G B.uniform_space _:=\n@topological_add_comm_group_is_uniform G _ B.topology B.is_topological_add_group\n\nlemma cauchy_iff {F : filter G} :\n  @cauchy G B.uniform_space F \u2194 F.ne_bot \u2227 \u2200 U \u2208 B, \u2203 M \u2208 F, \u2200 x y \u2208 M, y - x \u2208 U :=\nbegin\n  letI := B.uniform_space,\n  haveI := B.uniform_add_group,\n  suffices : F \u00d7\u1da0 F \u2264 \ud835\udce4 G \u2194 \u2200 U \u2208 B, \u2203 M \u2208 F, \u2200 x y \u2208 M, y - x \u2208 U,\n    by split ; rintros \u27e8h', h\u27e9 ; refine \u27e8h', _\u27e9 ; [rwa \u2190 this, rwa this],\n  rw [uniformity_eq_comap_nhds_zero G, \u2190 map_le_iff_le_comap],\n  change tendsto _ _ _ \u2194 _,\n  simp [(basis_sets F).prod_self.tendsto_iff B.nhds_zero_has_basis, @forall_swap (_ \u2208 _) G]\nend\n\nend add_group_filter_basis\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/uniform_filter_basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7424875177474966}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Eric Rodriguez\n\n! This file was ported from Lean 3 source module data.nat.choose.bounds\n! leanprover-community/mathlib commit 550b58538991c8977703fdeb7c9d51a5aa27df11\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.GroupPower.Lemmas\nimport Mathlib.Algebra.Order.Field.Basic\nimport Mathlib.Data.Nat.Choose.Basic\n\n/-!\n# Inequalities for binomial coefficients\n\nThis file proves exponential bounds on binomial coefficients. We might want to add here the\nbounds `n^r/r^r \u2264 n.choose r \u2264 e^r n^r/r^r` in the future.\n\n## Main declarations\n\n* `Nat.choose_le_pow`: `n.choose r \u2264 n^r / r!`\n* `Nat.pow_le_choose`: `(n + 1 - r)^r / r! \u2264 n.choose r`. Beware of the fishy \u2115-subtraction.\n-/\n\n\nopen Nat\n\nvariable {\u03b1 : Type _} [LinearOrderedSemifield \u03b1]\n\nnamespace Nat\n\ntheorem choose_le_pow (r n : \u2115) : (n.choose r : \u03b1)  \u2264 (n ^ r : \u03b1) / r ! := by\n  rw [le_div_iff']\n  \u00b7 norm_cast\n    rw [\u2190 Nat.descFactorial_eq_factorial_mul_choose]\n    exact n.descFactorial_le_pow r\n  exact_mod_cast r.factorial_pos\n#align nat.choose_le_pow Nat.choose_le_pow\n\n-- horrific casting is due to \u2115-subtraction\ntheorem pow_le_choose (r n : \u2115) : ((n + 1 - r : \u2115) ^ r : \u03b1) / r ! \u2264 n.choose r := by\n  rw [div_le_iff']\n  \u00b7 norm_cast\n    rw [\u2190 Nat.descFactorial_eq_factorial_mul_choose]\n    exact n.pow_sub_le_descFactorial r\n  exact_mod_cast r.factorial_pos\n#align nat.pow_le_choose Nat.pow_le_choose\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Choose/Bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.742452528307295}}
{"text": "import Aesop\nimport Mathlib.Combinatorics.Pigeonhole\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.LibrarySearch\n\n/-!\n# International Mathematical Olympiad 1964, Problem 4\n\nSeventeen people correspond by mail with one another -- each one with\nall the rest. In their letters only three different topics are\ndiscussed. Each pair of correspondents deals with only one of the topics.\nProve that there are at least three people who write to each other\nabout the same topic.\n\n-/\n\n/--\n Smaller version of the problem, with 6 (or more) people and 2 topics.\n-/\ntheorem lemma1\n    (Person Topic : Type)\n    [Fintype Person]\n    [Fintype Topic]\n    (card_person : 5 < Fintype.card Person)\n    (card_topic : Fintype.card Topic = 2)\n    (discusses : Person \u2192 Person \u2192 Topic)\n    (discussion_sym : \u2200 p1 p2 : Person, discusses p1 p2 = discusses p2 p1) :\n    \u2203 t : Topic, \u2203 s : Finset Person,\n      2 < s.card \u2227\n        \u2200 p1 \u2208 s, \u2200 p2 \u2208 s, p1 \u2260 p2 \u2192 discusses p1 p2 = t := by\n  -- Choose a person p2.\n  have p2 : Person := (truncOfCardPos (by linarith)).out\n  let Person' := {p3 // p3 \u2260 p2}\n  have hf\u03b1 : Fintype Person' := Fintype.ofFinite Person'\n  have hfc\u03b1 : 4 < Fintype.card Person' := by\n    rw[Fintype.card_subtype_compl, Fintype.card_ofSubsingleton]\n    exact lt_tsub_of_add_lt_left card_person\n  have h1 : Fintype.card Topic * 2 < Fintype.card Person' := by linarith\n\n  have := Classical.decEq Topic\n\n  -- By the pigeonhole principle, there must be some topic t2 such that the\n  -- size of the set {p3 // p3 \u2260 p2 \u2227 discusses p2 p3 = t2} is at least 3.\n  have h2 := Fintype.exists_lt_card_fiber_of_mul_lt_card\n              (fun (p3: Person') \u21a6 discusses p2 p3.val) h1\n  obtain \u27e8t2, ht2\u27e9 := h2\n  -- Call that set \u03b1.\n  let \u03b1 := (Finset.filter (fun (x : Person') \u21a6 discusses p2 \u2191x = t2) Finset.univ)\n\n  -- If any pair of people p4 p5 in \u03b1 discusses topic t2, then we are done.\n  -- So the people in \u03b1 must all discuss only the remaining one topic t3.\n  let Topic' := {t3 // t3 \u2260 t2}\n  have h3 : Fintype Topic' := Fintype.ofFinite Topic'\n  have h4 : Fintype.card Topic' = 1 := by\n    simp[Fintype.card_subtype_compl, card_topic]\n\n  -- let t3 be the other element of Topic\n  obtain \u27e8t3, ht3\u27e9 := Fintype.card_eq_one_iff.mp h4\n\n  obtain h6 | h7 := Classical.em (\u2203 p3 p4 : \u03b1, p3 \u2260 p4 \u2227\n                                    discusses p3.val p4.val = t2)\n  \u00b7 obtain \u27e8p3, p4, hp1, hp2\u27e9 := h6\n    use t2\n    -- the set we want is {p2,p3,p4}\n    let s1 : Finset Person := {p3.val.val}\n    let s2 : Finset Person := Finset.cons p4.val s1\n                               (by rw[Finset.mem_singleton]; intro hp\n                                   exact (hp1 (Subtype.val_injective\n                                          (Subtype.val_injective hp)).symm).elim)\n    let s3 : Finset Person := Finset.cons p2 s2\n                               (by rw[Finset.mem_cons, Finset.mem_singleton]\n                                   intro hp\n                                   cases hp with\n                                   | inl hp =>\n                                     exact (p4.val.property.symm hp).elim\n                                   | inr hp =>\n                                     exact (p3.val.property.symm hp).elim)\n    use s3\n    constructor\n    \u00b7 simp only[Finset.card_cons, Finset.card_singleton]\n    \u00b7 intros p1' hp1' p2' hp2' hp1p2\n      rw[Finset.mem_cons, Finset.mem_cons, Finset.mem_singleton] at hp1' hp2'\n      have hp4d : discusses p2 \u2191\u2191p4 = t2 := by\n         have := p4.property; simp at this; exact this\n      have hp3d : discusses p2 \u2191\u2191p3 = t2 := by\n         have := p3.property; simp at this; exact this\n      aesop\n\n  \u00b7 push_neg at h7\n    use t3\n    let \u03b1' := Finset.map \u27e8\u03bb (x :Person') => x.val, Subtype.coe_injective\u27e9 \u03b1\n    use \u03b1'\n    constructor\n    \u00b7 rw[Finset.card_map]; exact ht2\n    \u00b7 intros p3' hp3' p4' hp4' hp3p4'\n      rw[Finset.mem_map] at hp3' hp4'\n      obtain \u27e8\u27e8p3, p3_ne\u27e9, p3_mem_\u03b1, p3_eq\u27e9 := hp3'\n      obtain \u27e8\u27e8p4, p4_ne\u27e9, p4_mem_\u03b1, p4_eq\u27e9 := hp4'\n      dsimp at p3_eq p4_eq\n      rw [\u2190p3_eq, \u2190p4_eq]\n      have hne : p3 \u2260 p4 := by rwa[p3_eq, p4_eq]\n      have h8 := h7 \u27e8\u27e8p3, p3_ne\u27e9, p3_mem_\u03b1\u27e9 \u27e8\u27e8p4, p4_ne\u27e9, p4_mem_\u03b1\u27e9 (by simp[hne])\n      let t3': Topic' := \u27e8discusses p3 p4, h8\u27e9\n      have h9 := ht3 t3'\n      rw[\u2190h9]\n\ntheorem imo1964_q4\n    (Person Topic : Type)\n    [Fintype Person]\n    [Fintype Topic]\n    (card_person : Fintype.card Person = 17)\n    (card_topic : Fintype.card Topic = 3)\n    (discusses : Person \u2192 Person \u2192 Topic)\n    (discussion_sym : \u2200 p1 p2 : Person, discusses p1 p2 = discusses p2 p1) :\n    \u2203 t : Topic, \u2203 s : Finset Person,\n      2 < s.card \u2227\n        \u2200 p1 \u2208 s, \u2200 p2 \u2208 s, p1 \u2260 p2 \u2192 discusses p1 p2 = t := by\n  -- Choose a person p1.\n  have p1 : Person := (truncOfCardPos (by linarith)).out\n  let Person' := {p2 // p2 \u2260 p1}\n\n  -- By the pigeonhole principle, there must be some topic t1 such\n  -- that the size of the set {p2 // p2 \u2260 p1 \u2227 discusses p1 p2 = t1}\n  -- is at least 6.\n\n  have hf\u03b1 : Fintype Person' := Fintype.ofFinite Person'\n  have hfc\u03b1 : Fintype.card Person' = 16 := by\n      simp[Fintype.card_subtype_compl, card_person]\n  have h1 : Fintype.card Topic * 5 < Fintype.card Person' := by\n      rw[hfc\u03b1, card_topic]; norm_num\n\n  have := Classical.decEq Topic; have := Classical.decEq Person\n\n  have h2 := Fintype.exists_lt_card_fiber_of_mul_lt_card\n              (fun (p2: Person') \u21a6 discusses p1 p2.val) h1\n  clear h1\n  obtain \u27e8t1, ht1\u27e9 := h2\n  -- Call that set \u03b1.\n  let \u03b1 := (Finset.filter (fun (x : Person') \u21a6 discusses p1 \u2191x = t1) Finset.univ)\n  have card\u03b1 : 5 < Fintype.card \u03b1 := by rw[Fintype.card_coe]; exact ht1;\n\n  -- If any pair of people p2 p3 in \u03b1 discusses topic t1, then we are done.\n  obtain h6 | h7 := Classical.em (\u2203 p2 p3 : \u03b1, p2 \u2260 p3 \u2227\n                                    discusses p2.val p3.val = t1)\n  \u00b7 obtain \u27e8p3, p4, hp1, hp2\u27e9 := h6\n    use t1\n    -- the set we want is {p1,p3,p4}\n    let s1 : Finset Person := {p3.val.val}\n\n    have hs1 : \u00ac p4.val.val \u2208 s1 := by\n      rw[Finset.mem_singleton]; intro hp\n      exact (hp1 (Subtype.val_injective (Subtype.val_injective hp)).symm).elim\n\n    let s2 : Finset Person := Finset.cons p4.val s1 hs1\n\n    have hs2 : \u00ac p1 \u2208 s2 := by\n      rw[Finset.mem_cons, Finset.mem_singleton]; intro hp\n      cases hp with\n      | inl hp => exact (p4.val.property.symm hp).elim\n      | inr hp => exact (p3.val.property.symm hp).elim\n\n    let s3 : Finset Person := Finset.cons p1 s2 hs2\n    use s3\n    constructor\n    \u00b7 simp only[Finset.card_cons, Finset.card_singleton]\n    \u00b7 intros p1' hp1' p2' hp2' hp1p2\n      rw[Finset.mem_cons, Finset.mem_cons, Finset.mem_singleton] at hp1' hp2'\n      have hp4d : discusses p1 \u2191\u2191p4 = t1 := by\n         have := p4.property; simp at this; exact this\n      have hp3d : discusses p1 \u2191\u2191p3 = t1 := by\n         have := p3.property; simp at this; exact this\n      aesop\n\n  \u00b7 -- So the people in \u03b1 must all discuss only the remaining two topics.\n    push_neg at h7\n    let Topic' := {t2 // t2 \u2260 t1}\n    have h3 : Fintype Topic' := Fintype.ofFinite Topic'\n    have h4 : Fintype.card Topic' = 2 := by\n      simp[Fintype.card_subtype_compl, card_topic]\n    have t0 : Topic' := (truncOfCardPos (by linarith)).out\n\n    let discusses' : \u03b1 \u2192 \u03b1 \u2192 Topic' :=\n      fun (p2 p3 : \u03b1) \u21a6\n        if heq : p2 = p3 then t0\n        else\n        \u27e8discusses p2.val p3.val, h7 \u27e8p2, p2.property\u27e9 \u27e8p3, p3.property\u27e9 heq\u27e9\n    have discusses_sym' :\n        \u2200 (p1 p2 : { x // x \u2208 \u03b1 }), discusses' p1 p2 = discusses' p2 p1 := by\n      intros p3 p4\n      simp\n      split_ifs with hf1 hf2 hf3\n      \u00b7 rfl\n      \u00b7 exact (hf2 hf1.symm).elim\n      \u00b7 exact (hf1 hf3.symm).elim\n      \u00b7 simp[discussion_sym]\n    have h5 := lemma1 \u03b1 Topic' card\u03b1 h4 discusses' discusses_sym'\n    obtain \u27e8t2, s, hs1, hs2\u27e9 := h5\n    use t2\n    let s' := Finset.map \u27e8\u03bb (x : \u03b1) => x.val.val,\n                          fun x y hxy \u21a6 Subtype.coe_injective (Subtype.coe_injective hxy)\u27e9 s\n    use s'\n    constructor\n    \u00b7 rwa[Finset.card_map]\n    \u00b7 intros p3 hp3 p4 hp4 hp34\n      rw[Finset.mem_map] at hp3 hp4\n      obtain \u27e8\u27e8\u27e8p3', p3_mem_person'\u27e9, p3_mem_\u03b1\u27e9, p3_mem_s, hp3eq\u27e9 := hp3\n      obtain \u27e8\u27e8\u27e8p4', p4_mem_person'\u27e9, p4_mem_\u03b1\u27e9, p4_mem_s, hp4eq\u27e9 := hp4\n      dsimp at hp3eq hp4eq\n      rw [\u2190hp3eq, \u2190hp4eq]\n      have hne : p3' \u2260 p4' := by rwa[hp3eq, hp4eq]\n      have h6 := hs2 \u27e8\u27e8p3', p3_mem_person'\u27e9, p3_mem_\u03b1\u27e9 p3_mem_s\n                     \u27e8\u27e8p4', p4_mem_person'\u27e9, p4_mem_\u03b1\u27e9 p4_mem_s (by simp[hne])\n      simp[hne] at h6\n      exact (congrArg Subtype.val h6)\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean4", "sha": "dcf38981b8b9ff59a62f1e19a4f135fcdb4c9a63", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean4", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean4/math-puzzles-in-lean4-dcf38981b8b9ff59a62f1e19a4f135fcdb4c9a63/MathPuzzles/Imo1964Q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7424525268830655}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, R\u00e9my Degenne\nPorted by: Winston Yin\n\n! This file was ported from Lean 3 source module data.set.intervals.group\n! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Intervals.Basic\nimport Mathlib.Data.Set.Pairwise.Basic\nimport Mathlib.Algebra.Order.Group.Abs\nimport Mathlib.Algebra.GroupPower.Lemmas\n\n/-! ### Lemmas about arithmetic operations and intervals. -/\n\n\nvariable {\u03b1 : Type _}\n\nnamespace Set\n\nsection OrderedCommGroup\n\nvariable [OrderedCommGroup \u03b1] {a b c d : \u03b1}\n\n/-! `inv_mem_Ixx_iff`, `sub_mem_Ixx_iff` -/\n\n\n@[to_additive]\ntheorem inv_mem_Icc_iff : a\u207b\u00b9 \u2208 Set.Icc c d \u2194 a \u2208 Set.Icc d\u207b\u00b9 c\u207b\u00b9 :=\n  and_comm.trans <| and_congr inv_le' le_inv'\n#align set.inv_mem_Icc_iff Set.inv_mem_Icc_iff\n#align set.neg_mem_Icc_iff Set.neg_mem_Icc_iff\n\n@[to_additive]\ntheorem inv_mem_Ico_iff : a\u207b\u00b9 \u2208 Set.Ico c d \u2194 a \u2208 Set.Ioc d\u207b\u00b9 c\u207b\u00b9 :=\n  and_comm.trans <| and_congr inv_lt' le_inv'\n#align set.inv_mem_Ico_iff Set.inv_mem_Ico_iff\n#align set.neg_mem_Ico_iff Set.neg_mem_Ico_iff\n\n@[to_additive]\ntheorem inv_mem_Ioc_iff : a\u207b\u00b9 \u2208 Set.Ioc c d \u2194 a \u2208 Set.Ico d\u207b\u00b9 c\u207b\u00b9 :=\n  and_comm.trans <| and_congr inv_le' lt_inv'\n#align set.inv_mem_Ioc_iff Set.inv_mem_Ioc_iff\n#align set.neg_mem_Ioc_iff Set.neg_mem_Ioc_iff\n\n@[to_additive]\ntheorem inv_mem_Ioo_iff : a\u207b\u00b9 \u2208 Set.Ioo c d \u2194 a \u2208 Set.Ioo d\u207b\u00b9 c\u207b\u00b9 :=\n  and_comm.trans <| and_congr inv_lt' lt_inv'\n#align set.inv_mem_Ioo_iff Set.inv_mem_Ioo_iff\n#align set.neg_mem_Ioo_iff Set.neg_mem_Ioo_iff\n\nend OrderedCommGroup\n\nsection OrderedAddCommGroup\n\nvariable [OrderedAddCommGroup \u03b1] {a b c d : \u03b1}\n\n/-! `add_mem_Ixx_iff_left` -/\n\n\n-- Porting note: instance search needs help `(\u03b1 := \u03b1)`\ntheorem add_mem_Icc_iff_left : a + b \u2208 Set.Icc c d \u2194 a \u2208 Set.Icc (c - b) (d - b) :=\n  (and_congr (sub_le_iff_le_add (\u03b1 := \u03b1)) (le_sub_iff_add_le (\u03b1 := \u03b1))).symm\n#align set.add_mem_Icc_iff_left Set.add_mem_Icc_iff_left\n\ntheorem add_mem_Ico_iff_left : a + b \u2208 Set.Ico c d \u2194 a \u2208 Set.Ico (c - b) (d - b) :=\n  (and_congr (sub_le_iff_le_add (\u03b1 := \u03b1)) (lt_sub_iff_add_lt (\u03b1 := \u03b1))).symm\n#align set.add_mem_Ico_iff_left Set.add_mem_Ico_iff_left\n\ntheorem add_mem_Ioc_iff_left : a + b \u2208 Set.Ioc c d \u2194 a \u2208 Set.Ioc (c - b) (d - b) :=\n  (and_congr (sub_lt_iff_lt_add (\u03b1 := \u03b1)) (le_sub_iff_add_le (\u03b1 := \u03b1))).symm\n#align set.add_mem_Ioc_iff_left Set.add_mem_Ioc_iff_left\n\ntheorem add_mem_Ioo_iff_left : a + b \u2208 Set.Ioo c d \u2194 a \u2208 Set.Ioo (c - b) (d - b) :=\n  (and_congr (sub_lt_iff_lt_add (\u03b1 := \u03b1)) (lt_sub_iff_add_lt (\u03b1 := \u03b1))).symm\n#align set.add_mem_Ioo_iff_left Set.add_mem_Ioo_iff_left\n\n/-! `add_mem_Ixx_iff_right` -/\n\n\ntheorem add_mem_Icc_iff_right : a + b \u2208 Set.Icc c d \u2194 b \u2208 Set.Icc (c - a) (d - a) :=\n  (and_congr sub_le_iff_le_add' le_sub_iff_add_le').symm\n#align set.add_mem_Icc_iff_right Set.add_mem_Icc_iff_right\n\ntheorem add_mem_Ico_iff_right : a + b \u2208 Set.Ico c d \u2194 b \u2208 Set.Ico (c - a) (d - a) :=\n  (and_congr sub_le_iff_le_add' lt_sub_iff_add_lt').symm\n#align set.add_mem_Ico_iff_right Set.add_mem_Ico_iff_right\n\ntheorem add_mem_Ioc_iff_right : a + b \u2208 Set.Ioc c d \u2194 b \u2208 Set.Ioc (c - a) (d - a) :=\n  (and_congr sub_lt_iff_lt_add' le_sub_iff_add_le').symm\n#align set.add_mem_Ioc_iff_right Set.add_mem_Ioc_iff_right\n\ntheorem add_mem_Ioo_iff_right : a + b \u2208 Set.Ioo c d \u2194 b \u2208 Set.Ioo (c - a) (d - a) :=\n  (and_congr sub_lt_iff_lt_add' lt_sub_iff_add_lt').symm\n#align set.add_mem_Ioo_iff_right Set.add_mem_Ioo_iff_right\n\n/-! `sub_mem_Ixx_iff_left` -/\n\n\ntheorem sub_mem_Icc_iff_left : a - b \u2208 Set.Icc c d \u2194 a \u2208 Set.Icc (c + b) (d + b) :=\n  and_congr le_sub_iff_add_le sub_le_iff_le_add\n#align set.sub_mem_Icc_iff_left Set.sub_mem_Icc_iff_left\n\ntheorem sub_mem_Ico_iff_left : a - b \u2208 Set.Ico c d \u2194 a \u2208 Set.Ico (c + b) (d + b) :=\n  and_congr le_sub_iff_add_le sub_lt_iff_lt_add\n#align set.sub_mem_Ico_iff_left Set.sub_mem_Ico_iff_left\n\ntheorem sub_mem_Ioc_iff_left : a - b \u2208 Set.Ioc c d \u2194 a \u2208 Set.Ioc (c + b) (d + b) :=\n  and_congr lt_sub_iff_add_lt sub_le_iff_le_add\n#align set.sub_mem_Ioc_iff_left Set.sub_mem_Ioc_iff_left\n\ntheorem sub_mem_Ioo_iff_left : a - b \u2208 Set.Ioo c d \u2194 a \u2208 Set.Ioo (c + b) (d + b) :=\n  and_congr lt_sub_iff_add_lt sub_lt_iff_lt_add\n#align set.sub_mem_Ioo_iff_left Set.sub_mem_Ioo_iff_left\n\n/-! `sub_mem_Ixx_iff_right` -/\n\n\ntheorem sub_mem_Icc_iff_right : a - b \u2208 Set.Icc c d \u2194 b \u2208 Set.Icc (a - d) (a - c) :=\n  and_comm.trans <| and_congr sub_le_comm le_sub_comm\n#align set.sub_mem_Icc_iff_right Set.sub_mem_Icc_iff_right\n\ntheorem sub_mem_Ico_iff_right : a - b \u2208 Set.Ico c d \u2194 b \u2208 Set.Ioc (a - d) (a - c) :=\n  and_comm.trans <| and_congr sub_lt_comm le_sub_comm\n#align set.sub_mem_Ico_iff_right Set.sub_mem_Ico_iff_right\n\ntheorem sub_mem_Ioc_iff_right : a - b \u2208 Set.Ioc c d \u2194 b \u2208 Set.Ico (a - d) (a - c) :=\n  and_comm.trans <| and_congr sub_le_comm lt_sub_comm\n#align set.sub_mem_Ioc_iff_right Set.sub_mem_Ioc_iff_right\n\ntheorem sub_mem_Ioo_iff_right : a - b \u2208 Set.Ioo c d \u2194 b \u2208 Set.Ioo (a - d) (a - c) :=\n  and_comm.trans <| and_congr sub_lt_comm lt_sub_comm\n#align set.sub_mem_Ioo_iff_right Set.sub_mem_Ioo_iff_right\n\n-- I think that symmetric intervals deserve attention and API: they arise all the time,\n-- for instance when considering metric balls in `\u211d`.\ntheorem mem_Icc_iff_abs_le {R : Type _} [LinearOrderedAddCommGroup R] {x y z : R} :\n    |x - y| \u2264 z \u2194 y \u2208 Icc (x - z) (x + z) :=\n  abs_le.trans <| and_comm.trans <| and_congr sub_le_comm neg_le_sub_iff_le_add\n#align set.mem_Icc_iff_abs_le Set.mem_Icc_iff_abs_le\n\nend OrderedAddCommGroup\n\nsection LinearOrderedAddCommGroup\n\nvariable [LinearOrderedAddCommGroup \u03b1]\n\n/-- If we remove a smaller interval from a larger, the result is nonempty -/\ntheorem nonempty_Ico_sdiff {x dx y dy : \u03b1} (h : dy < dx) (hx : 0 < dx) :\n    Nonempty \u2191(Ico x (x + dx) \\ Ico y (y + dy)) := by\n  cases' lt_or_le x y with h' h'\n  \u00b7 use x\n    simp [*, not_le.2 h']\n  \u00b7 use max x (x + dy)\n    simp [*, le_refl]\n#align set.nonempty_Ico_sdiff Set.nonempty_Ico_sdiff\n\nend LinearOrderedAddCommGroup\n\n/-! ### Lemmas about disjointness of translates of intervals -/\n\nsection PairwiseDisjoint\n\nsection OrderedCommGroup\n\nvariable [OrderedCommGroup \u03b1] (a b : \u03b1)\n\n@[to_additive]\ntheorem pairwise_disjoint_Ioc_mul_zpow :\n    Pairwise (Disjoint on fun n : \u2124 => Ioc (a * b ^ n) (a * b ^ (n + 1))) := by\n  simp_rw [Function.onFun, Set.disjoint_iff]\n  intro m n hmn x hx\n  apply hmn\n  have hb : 1 < b := by\n    have : a * b ^ m < a * b ^ (m + 1) := hx.1.1.trans_le hx.1.2\n    rwa [mul_lt_mul_iff_left, \u2190 mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this\n  have i1 := hx.1.1.trans_le hx.2.2\n  have i2 := hx.2.1.trans_le hx.1.2\n  rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, Int.lt_add_one_iff] at i1 i2\n  exact le_antisymm i1 i2\n#align set.pairwise_disjoint_Ioc_mul_zpow Set.pairwise_disjoint_Ioc_mul_zpow\n#align set.pairwise_disjoint_Ioc_add_zsmul Set.pairwise_disjoint_Ioc_add_zsmul\n\n@[to_additive]\ntheorem pairwise_disjoint_Ico_mul_zpow :\n    Pairwise (Disjoint on fun n : \u2124 => Ico (a * b ^ n) (a * b ^ (n + 1))) :=\n  by\n  simp_rw [Function.onFun, Set.disjoint_iff]\n  intro m n hmn x hx\n  apply hmn\n  have hb : 1 < b :=\n    by\n    have : a * b ^ m < a * b ^ (m + 1) := hx.1.1.trans_lt hx.1.2\n    rwa [mul_lt_mul_iff_left, \u2190 mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this\n  have i1 := hx.1.1.trans_lt hx.2.2\n  have i2 := hx.2.1.trans_lt hx.1.2\n  rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, Int.lt_add_one_iff] at i1 i2\n  exact le_antisymm i1 i2\n#align set.pairwise_disjoint_Ico_mul_zpow Set.pairwise_disjoint_Ico_mul_zpow\n#align set.pairwise_disjoint_Ico_add_zsmul Set.pairwise_disjoint_Ico_add_zsmul\n\n@[to_additive]\ntheorem pairwise_disjoint_Ioo_mul_zpow :\n    Pairwise (Disjoint on fun n : \u2124 => Ioo (a * b ^ n) (a * b ^ (n + 1))) := fun _ _ hmn =>\n  (pairwise_disjoint_Ioc_mul_zpow a b hmn).mono Ioo_subset_Ioc_self Ioo_subset_Ioc_self\n#align set.pairwise_disjoint_Ioo_mul_zpow Set.pairwise_disjoint_Ioo_mul_zpow\n#align set.pairwise_disjoint_Ioo_add_zsmul Set.pairwise_disjoint_Ioo_add_zsmul\n\n@[to_additive]\ntheorem pairwise_disjoint_Ioc_zpow :\n    Pairwise (Disjoint on fun n : \u2124 => Ioc (b ^ n) (b ^ (n + 1))) := by\n  simpa only [one_mul] using pairwise_disjoint_Ioc_mul_zpow 1 b\n#align set.pairwise_disjoint_Ioc_zpow Set.pairwise_disjoint_Ioc_zpow\n#align set.pairwise_disjoint_Ioc_zsmul Set.pairwise_disjoint_Ioc_zsmul\n\n@[to_additive]\ntheorem pairwise_disjoint_Ico_zpow :\n    Pairwise (Disjoint on fun n : \u2124 => Ico (b ^ n) (b ^ (n + 1))) := by\n  simpa only [one_mul] using pairwise_disjoint_Ico_mul_zpow 1 b\n#align set.pairwise_disjoint_Ico_zpow Set.pairwise_disjoint_Ico_zpow\n#align set.pairwise_disjoint_Ico_zsmul Set.pairwise_disjoint_Ico_zsmul\n\n@[to_additive]\n\n\nend OrderedCommGroup\n\nsection OrderedRing\n\nvariable [OrderedRing \u03b1] (a : \u03b1)\n\ntheorem pairwise_disjoint_Ioc_add_int_cast :\n    Pairwise (Disjoint on fun n : \u2124 => Ioc (a + n) (a + n + 1)) := by\n  simpa only [zsmul_one, Int.cast_add, Int.cast_one, \u2190 add_assoc] using\n    pairwise_disjoint_Ioc_add_zsmul a (1 : \u03b1)\n#align set.pairwise_disjoint_Ioc_add_int_cast Set.pairwise_disjoint_Ioc_add_int_cast\n\ntheorem pairwise_disjoint_Ico_add_int_cast :\n    Pairwise (Disjoint on fun n : \u2124 => Ico (a + n) (a + n + 1)) := by\n  simpa only [zsmul_one, Int.cast_add, Int.cast_one, \u2190 add_assoc] using\n    pairwise_disjoint_Ico_add_zsmul a (1 : \u03b1)\n#align set.pairwise_disjoint_Ico_add_int_cast Set.pairwise_disjoint_Ico_add_int_cast\n\ntheorem pairwise_disjoint_Ioo_add_int_cast :\n    Pairwise (Disjoint on fun n : \u2124 => Ioo (a + n) (a + n + 1)) := by\n  simpa only [zsmul_one, Int.cast_add, Int.cast_one, \u2190 add_assoc] using\n    pairwise_disjoint_Ioo_add_zsmul a (1 : \u03b1)\n#align set.pairwise_disjoint_Ioo_add_int_cast Set.pairwise_disjoint_Ioo_add_int_cast\n\nvariable (\u03b1)\n\ntheorem pairwise_disjoint_Ico_int_cast : Pairwise (Disjoint on fun n : \u2124 => Ico (n : \u03b1) (n + 1)) :=\n  by simpa only [zero_add] using pairwise_disjoint_Ico_add_int_cast (0 : \u03b1)\n#align set.pairwise_disjoint_Ico_int_cast Set.pairwise_disjoint_Ico_int_cast\n\ntheorem pairwise_disjoint_Ioo_int_cast : Pairwise (Disjoint on fun n : \u2124 => Ioo (n : \u03b1) (n + 1)) :=\n  by simpa only [zero_add] using pairwise_disjoint_Ioo_add_int_cast (0 : \u03b1)\n#align set.pairwise_disjoint_Ioo_int_cast Set.pairwise_disjoint_Ioo_int_cast\n\ntheorem pairwise_disjoint_Ioc_int_cast : Pairwise (Disjoint on fun n : \u2124 => Ioc (n : \u03b1) (n + 1)) :=\n  by simpa only [zero_add] using pairwise_disjoint_Ioc_add_int_cast (0 : \u03b1)\n#align set.pairwise_disjoint_Ioc_int_cast Set.pairwise_disjoint_Ioc_int_cast\n\nend OrderedRing\n\nend PairwiseDisjoint\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Intervals/Group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7424525266241561}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.reverse\nimport algebra.associated\nimport algebra.regular.smul\n\n/-!\n# Theory of monic polynomials\n\nWe give several tools for proving that polynomials are monic, e.g.\n`monic.mul`, `monic.map`, `monic.pow`.\n-/\n\nnoncomputable theory\n\nopen finset\nopen_locale big_operators classical polynomial\n\nnamespace polynomial\nuniverses u v y\nvariables {R : Type u} {S : Type v} {a b : R} {m n : \u2115} {\u03b9 : Type y}\n\nsection semiring\nvariables [semiring R] {p q r : R[X]}\n\nlemma monic.as_sum (hp : p.monic) :\n  p = X^(p.nat_degree) + (\u2211 i in range p.nat_degree, C (p.coeff i) * X^i) :=\nbegin\n  conv_lhs { rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] },\n  suffices : C (p.coeff p.nat_degree) = 1,\n  { rw [this, one_mul] },\n  exact congr_arg C hp\nend\n\nlemma ne_zero_of_ne_zero_of_monic (hp : p \u2260 0) (hq : monic q) : q \u2260 0 :=\nbegin\n  rintro rfl,\n  rw [monic.def, leading_coeff_zero] at hq,\n  rw [\u2190 mul_one p, \u2190 C_1, \u2190 hq, C_0, mul_zero] at hp,\n  exact hp rfl\nend\n\nlemma monic.map [semiring S] (f : R \u2192+* S) (hp : monic p) : monic (p.map f) :=\nbegin\n  nontriviality,\n  have : f (leading_coeff p) \u2260 0,\n  { rw [show _ = _, from hp, f.map_one],\n    exact one_ne_zero, },\n  rw [monic, leading_coeff, coeff_map],\n  suffices : p.coeff (map f p).nat_degree = 1,\n  { simp [this], },\n  rwa nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero f this),\nend\n\nlemma monic_C_mul_of_mul_leading_coeff_eq_one {b : R} (hp : b * p.leading_coeff = 1) :\n  monic (C b * p) :=\nby { nontriviality, rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp] }\n\nlemma monic_mul_C_of_leading_coeff_mul_eq_one {b : R} (hp : p.leading_coeff * b = 1) :\n  monic (p * C b) :=\nby { nontriviality, rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp] }\n\ntheorem monic_of_degree_le (n : \u2115) (H1 : degree p \u2264 n) (H2 : coeff p n = 1) : monic p :=\ndecidable.by_cases\n  (assume H : degree p < n, eq_of_zero_eq_one\n    (H2 \u25b8 (coeff_eq_zero_of_degree_lt H).symm) _ _)\n  (assume H : \u00acdegree p < n,\n    by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H])\n\ntheorem monic_X_pow_add {n : \u2115} (H : degree p \u2264 n) : monic (X ^ (n+1) + p) :=\nhave H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)),\nmonic_of_degree_le (n+1)\n  (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1)))\n  (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero])\n\ntheorem monic_X_add_C (x : R) : monic (X + C x) :=\npow_one (X : R[X]) \u25b8 monic_X_pow_add degree_C_le\n\nlemma monic.mul (hp : monic p) (hq : monic q) : monic (p * q) :=\nif h0 : (0 : R) = 1 then by haveI := subsingleton_of_zero_eq_one h0;\n  exact subsingleton.elim _ _\nelse\n  have leading_coeff p * leading_coeff q \u2260 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0],\n  by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul]\n\nlemma monic.pow (hp : monic p) : \u2200 (n : \u2115), monic (p ^ n)\n| 0     := monic_one\n| (n+1) := by { rw pow_succ, exact hp.mul (monic.pow n) }\n\nlemma monic.add_of_left (hp : monic p) (hpq : degree q < degree p) :\n  monic (p + q) :=\nby rwa [monic, add_comm, leading_coeff_add_of_degree_lt hpq]\n\nlemma monic.add_of_right (hq : monic q) (hpq : degree p < degree q) :\n  monic (p + q) :=\nby rwa [monic, leading_coeff_add_of_degree_lt hpq]\n\nlemma monic.of_mul_monic_left (hp : p.monic) (hpq : (p * q).monic) : q.monic :=\nbegin\n  contrapose! hpq,\n  rw monic.def at hpq \u22a2,\n  rwa leading_coeff_monic_mul hp,\nend\n\nlemma monic.of_mul_monic_right (hq : q.monic) (hpq : (p * q).monic) : p.monic :=\nbegin\n  contrapose! hpq,\n  rw monic.def at hpq \u22a2,\n  rwa leading_coeff_mul_monic hq,\nend\n\nnamespace monic\n\n@[simp]\nlemma nat_degree_eq_zero_iff_eq_one {p : R[X]} (hp : p.monic) :\n  p.nat_degree = 0 \u2194 p = 1 :=\nbegin\n  split; intro h,\n  swap, { rw h, exact nat_degree_one },\n  have : p = C (p.coeff 0),\n  { rw \u2190 polynomial.degree_le_zero_iff,\n    rwa polynomial.nat_degree_eq_zero_iff_degree_le_zero at h },\n  rw this, convert C_1, rw \u2190 h, apply hp,\nend\n\n@[simp]\nlemma degree_le_zero_iff_eq_one {p : R[X]} (hp : p.monic) :\n  p.degree \u2264 0 \u2194 p = 1 :=\nby rw [\u2190hp.nat_degree_eq_zero_iff_eq_one, nat_degree_eq_zero_iff_degree_le_zero]\n\nlemma nat_degree_mul {p q : R[X]} (hp : p.monic) (hq : q.monic) :\n  (p * q).nat_degree = p.nat_degree + q.nat_degree :=\nbegin\n  nontriviality R,\n  apply nat_degree_mul',\n  simp [hp.leading_coeff, hq.leading_coeff]\nend\n\nlemma degree_mul_comm {p : R[X]} (hp : p.monic) (q : R[X]) :\n  (p * q).degree = (q * p).degree :=\nbegin\n  by_cases h : q = 0,\n  { simp [h] },\n  rw [degree_mul', hp.degree_mul],\n  { exact add_comm _ _ },\n  { rwa [hp.leading_coeff, one_mul, leading_coeff_ne_zero] }\nend\n\nlemma nat_degree_mul' {p q : R[X]} (hp : p.monic) (hq : q \u2260 0) :\n  (p * q).nat_degree = p.nat_degree + q.nat_degree :=\nbegin\n  rw [nat_degree_mul', add_comm],\n  simpa [hp.leading_coeff, leading_coeff_ne_zero]\nend\n\nlemma nat_degree_mul_comm {p : R[X]} (hp : p.monic) (q : R[X]) :\n  (p * q).nat_degree = (q * p).nat_degree :=\nbegin\n  by_cases h : q = 0,\n  { simp [h] },\n  rw [hp.nat_degree_mul' h, polynomial.nat_degree_mul', add_comm],\n  simpa [hp.leading_coeff, leading_coeff_ne_zero]\nend\n\nlemma next_coeff_mul {p q : R[X]} (hp : monic p) (hq : monic q) :\n  next_coeff (p * q) = next_coeff p + next_coeff q :=\nbegin\n  nontriviality,\n  simp only [\u2190 coeff_one_reverse],\n  rw reverse_mul;\n    simp [coeff_mul, nat.antidiagonal, hp.leading_coeff, hq.leading_coeff, add_comm]\nend\n\nlemma eq_one_of_map_eq_one {S : Type*} [semiring S] [nontrivial S]\n  (f : R \u2192+* S) (hp : p.monic) (map_eq : p.map f = 1) : p = 1 :=\nbegin\n  nontriviality R,\n  have hdeg : p.degree = 0,\n  { rw [\u2190 degree_map_eq_of_leading_coeff_ne_zero f _, map_eq, degree_one],\n    { rw [hp.leading_coeff, f.map_one],\n      exact one_ne_zero } },\n  have hndeg : p.nat_degree = 0 :=\n    with_bot.coe_eq_coe.mp ((degree_eq_nat_degree hp.ne_zero).symm.trans hdeg),\n  convert eq_C_of_degree_eq_zero hdeg,\n  rw [\u2190 hndeg, \u2190 polynomial.leading_coeff, hp.leading_coeff, C.map_one]\nend\n\nlemma nat_degree_pow (hp : p.monic) (n : \u2115) :\n  (p ^ n).nat_degree = n * p.nat_degree :=\nbegin\n  induction n with n hn,\n  { simp },\n  { rw [pow_succ, hp.nat_degree_mul (hp.pow n), hn],\n    ring }\nend\n\nend monic\n\n@[simp] lemma nat_degree_pow_X_add_C [nontrivial R] (n : \u2115) (r : R) :\n  ((X + C r) ^ n).nat_degree = n :=\nby rw [(monic_X_add_C r).nat_degree_pow, nat_degree_X_add_C, mul_one]\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R] {p : R[X]}\n\nlemma monic_multiset_prod_of_monic (t : multiset \u03b9) (f : \u03b9 \u2192 R[X])\n  (ht : \u2200 i \u2208 t, monic (f i)) :\n  monic (t.map f).prod :=\nbegin\n  revert ht,\n  refine t.induction_on _ _, { simp },\n  intros a t ih ht,\n  rw [multiset.map_cons, multiset.prod_cons],\n  exact (ht _ (multiset.mem_cons_self _ _)).mul (ih (\u03bb _ hi, ht _ (multiset.mem_cons_of_mem hi)))\nend\n\nlemma monic_prod_of_monic (s : finset \u03b9) (f : \u03b9 \u2192 R[X]) (hs : \u2200 i \u2208 s, monic (f i)) :\n  monic (\u220f i in s, f i) :=\nmonic_multiset_prod_of_monic s.1 f hs\n\nlemma is_unit_C {x : R} : is_unit (C x) \u2194 is_unit x :=\nbegin\n  rw [is_unit_iff_dvd_one, is_unit_iff_dvd_one],\n  split,\n  { rintros \u27e8g, hg\u27e9,\n    replace hg := congr_arg (eval 0) hg,\n    rw [eval_one, eval_mul, eval_C] at hg,\n    exact \u27e8g.eval 0, hg\u27e9 },\n  { rintros \u27e8y, hy\u27e9,\n    exact \u27e8C y, by rw [\u2190 C_mul, \u2190 hy, C_1]\u27e9 }\nend\n\nlemma eq_one_of_is_unit_of_monic (hm : monic p) (hpu : is_unit p) : p = 1 :=\nhave degree p \u2264 0,\n  from calc degree p \u2264 degree (1 : R[X]) :\n    let \u27e8u, hu\u27e9 := is_unit_iff_dvd_one.1 hpu in\n    if hu0 : u = 0\n    then begin\n        rw [hu0, mul_zero] at hu,\n        rw [\u2190 mul_one p, hu, mul_zero],\n        simp\n      end\n    else have p.leading_coeff * u.leading_coeff \u2260 0,\n        by rw [hm.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero];\n          exact hu0,\n      by rw [hu, degree_mul' this];\n        exact le_add_of_nonneg_right (degree_nonneg_iff_ne_zero.2 hu0)\n  ... \u2264 0 : degree_one_le,\nby rw [eq_C_of_degree_le_zero this, \u2190 nat_degree_eq_zero_iff_degree_le_zero.2 this,\n    \u2190 leading_coeff, hm.leading_coeff, C_1]\n\nlemma monic.next_coeff_multiset_prod (t : multiset \u03b9) (f : \u03b9 \u2192 R[X])\n  (h : \u2200 i \u2208 t, monic (f i)) :\n  next_coeff (t.map f).prod = (t.map (\u03bb i, next_coeff (f i))).sum :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _),\n  { simp only [multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, multiset.map_zero,\n               multiset.prod_zero, multiset.sum_zero, not_false_iff, forall_true_iff],\n    rw \u2190 C_1, rw next_coeff_C_eq_zero },\n  { rw [multiset.map_cons, multiset.prod_cons, multiset.map_cons, multiset.sum_cons,\n        monic.next_coeff_mul, ih],\n    exacts [\u03bb i hi, ht i (multiset.mem_cons_of_mem hi), ht a (multiset.mem_cons_self _ _),\n            monic_multiset_prod_of_monic _ _ (\u03bb b bs, ht _ (multiset.mem_cons_of_mem bs))] }\nend\n\nlemma monic.next_coeff_prod (s : finset \u03b9) (f : \u03b9 \u2192 R[X]) (h : \u2200 i \u2208 s, monic (f i)) :\n  next_coeff (\u220f i in s, f i) = \u2211 i in s, next_coeff (f i) :=\nmonic.next_coeff_multiset_prod s.1 f h\n\nend comm_semiring\n\nsection ring\nvariables [ring R] {p : R[X]}\n\ntheorem monic_X_sub_C (x : R) : monic (X - C x) :=\nby simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)\n\ntheorem monic_X_pow_sub {n : \u2115} (H : degree p \u2264 n) : monic (X ^ (n+1) - p) :=\nby simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) \u2264 n, by rwa \u2190degree_neg p at H)\n\n/-- `X ^ n - a` is monic. -/\nlemma monic_X_pow_sub_C {R : Type u} [ring R] (a : R) {n : \u2115} (h : n \u2260 0) : (X ^ n - C a).monic :=\nbegin\n  obtain \u27e8k, hk\u27e9 := nat.exists_eq_succ_of_ne_zero h,\n  convert monic_X_pow_sub _,\n  exact le_trans degree_C_le nat.with_bot.coe_nonneg,\nend\n\nlemma not_is_unit_X_pow_sub_one (R : Type*) [comm_ring R] [nontrivial R] (n : \u2115) :\n  \u00ac is_unit (X ^ n - 1 : R[X]) :=\nbegin\n  intro h,\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simpa using h },\n  apply hn,\n  rwa [\u2190 @nat_degree_X_pow_sub_C _ _ _ n (1 : R),\n      eq_one_of_is_unit_of_monic (monic_X_pow_sub_C (1 : R) hn),\n      nat_degree_one]\nend\n\nlemma monic_sub_of_left {p q : R[X]} (hp : monic p) (hpq : degree q < degree p) :\n  monic (p - q) :=\nby { rw sub_eq_add_neg, apply hp.add_of_left, rwa degree_neg }\n\nlemma monic_sub_of_right {p q : R[X]}\n  (hq : q.leading_coeff = -1) (hpq : degree p < degree q) : monic (p - q) :=\nhave (-q).coeff (-q).nat_degree = 1 :=\nby rw [nat_degree_neg, coeff_neg, show q.coeff q.nat_degree = -1, from hq, neg_neg],\nby { rw sub_eq_add_neg, apply monic.add_of_right this, rwa degree_neg }\n\n@[simp]\nlemma monic.nat_degree_map [semiring S] [nontrivial S] {P : polynomial R} (hmo : P.monic)\n  (f : R \u2192+* S) : (P.map f).nat_degree = P.nat_degree :=\nbegin\n  refine le_antisymm (nat_degree_map_le _ _) (le_nat_degree_of_ne_zero _),\n  rw [coeff_map, monic.coeff_nat_degree hmo, ring_hom.map_one],\n  exact one_ne_zero\nend\n\n@[simp]\nlemma monic.degree_map [semiring S] [nontrivial S] {P : polynomial R} (hmo : P.monic)\n  (f : R \u2192+* S) : (P.map f).degree = P.degree :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP] },\n  { refine le_antisymm (degree_map_le _ _) _,\n    rw [degree_eq_nat_degree hP],\n    refine le_degree_of_ne_zero _,\n    rw [coeff_map, monic.coeff_nat_degree hmo, ring_hom.map_one],\n    exact one_ne_zero }\nend\n\nsection injective\nopen function\nvariables [semiring S] {f : R \u2192+* S} (hf : injective f)\ninclude hf\n\nlemma degree_map_eq_of_injective (p : R[X]) : degree (p.map f) = degree p :=\nif h : p = 0 then by simp [h]\nelse degree_map_eq_of_leading_coeff_ne_zero _\n  (by rw [\u2190 f.map_zero]; exact mt hf.eq_iff.1\n    (mt leading_coeff_eq_zero.1 h))\n\nlemma nat_degree_map_eq_of_injective (p : R[X]) :\n  nat_degree (p.map f) = nat_degree p :=\nnat_degree_eq_of_degree_eq (degree_map_eq_of_injective hf p)\n\nlemma leading_coeff_map' (p : R[X]) :\n  leading_coeff (p.map f) = f (leading_coeff p) :=\nbegin\n  unfold leading_coeff,\n  rw [coeff_map, nat_degree_map_eq_of_injective hf p],\nend\n\nlemma next_coeff_map (p : R[X]) :\n  (p.map f).next_coeff = f p.next_coeff :=\nbegin\n  unfold next_coeff,\n  rw nat_degree_map_eq_of_injective hf,\n  split_ifs; simp\nend\n\nlemma leading_coeff_of_injective (p : R[X]) :\n  leading_coeff (p.map f) = f (leading_coeff p) :=\nbegin\n  delta leading_coeff,\n  rw [coeff_map f, nat_degree_map_eq_of_injective hf p]\nend\n\nlemma monic_of_injective {p : R[X]} (hp : (p.map f).monic) : p.monic :=\nbegin\n  apply hf,\n  rw [\u2190 leading_coeff_of_injective hf, hp.leading_coeff, f.map_one]\nend\n\nend injective\nend ring\n\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : R[X]}\n\n@[simp] lemma not_monic_zero : \u00acmonic (0 : R[X]) :=\nby simpa only [monic, leading_coeff_zero] using (zero_ne_one : (0 : R) \u2260 1)\n\nend nonzero_semiring\n\nsection not_zero_divisor\n\n-- TODO: using gh-8537, rephrase lemmas that involve commutation around `*` using the op-ring\n\nvariables [semiring R] {p : R[X]}\n\nlemma monic.mul_left_ne_zero (hp : monic p) {q : R[X]} (hq : q \u2260 0) :\n  q * p \u2260 0 :=\nbegin\n  by_cases h : p = 1,\n  { simpa [h] },\n  rw [ne.def, \u2190degree_eq_bot, hp.degree_mul, with_bot.add_eq_bot, not_or_distrib, degree_eq_bot],\n  refine \u27e8hq, _\u27e9,\n  rw [\u2190hp.degree_le_zero_iff_eq_one, not_le] at h,\n  refine (lt_trans _ h).ne',\n  simp\nend\n\nlemma monic.mul_right_ne_zero (hp : monic p) {q : R[X]} (hq : q \u2260 0) :\n  p * q \u2260 0 :=\nbegin\n  by_cases h : p = 1,\n  { simpa [h] },\n  rw [ne.def, \u2190degree_eq_bot, hp.degree_mul_comm, hp.degree_mul, with_bot.add_eq_bot,\n      not_or_distrib, degree_eq_bot],\n  refine \u27e8hq, _\u27e9,\n  rw [\u2190hp.degree_le_zero_iff_eq_one, not_le] at h,\n  refine (lt_trans _ h).ne',\n  simp\nend\n\nlemma monic.mul_nat_degree_lt_iff (h : monic p) {q : R[X]} :\n  (p * q).nat_degree < p.nat_degree \u2194 p \u2260 1 \u2227 q = 0 :=\nbegin\n  by_cases hq : q = 0,\n  { suffices : 0 < p.nat_degree \u2194 p.nat_degree \u2260 0,\n    { simpa [hq, \u2190h.nat_degree_eq_zero_iff_eq_one] },\n    exact \u27e8\u03bb h, h.ne', \u03bb h, lt_of_le_of_ne (nat.zero_le _) h.symm \u27e9 },\n  { simp [h.nat_degree_mul', hq] }\nend\n\nlemma monic.mul_right_eq_zero_iff (h : monic p) {q : R[X]} :\n  p * q = 0 \u2194 q = 0 :=\nbegin\n  by_cases hq : q = 0;\n  simp [h.mul_right_ne_zero, hq]\nend\n\nlemma monic.mul_left_eq_zero_iff (h : monic p) {q : R[X]} :\n  q * p = 0 \u2194 q = 0 :=\nbegin\n  by_cases hq : q = 0;\n  simp [h.mul_left_ne_zero, hq]\nend\n\nlemma monic.is_regular {R : Type*} [ring R] {p : R[X]} (hp : monic p) : is_regular p :=\nbegin\n  split,\n  { intros q r h,\n    rw [\u2190sub_eq_zero, \u2190hp.mul_right_eq_zero_iff, mul_sub, h, sub_self] },\n  { intros q r h,\n    simp only at h,\n    rw [\u2190sub_eq_zero, \u2190hp.mul_left_eq_zero_iff, sub_mul, h, sub_self] }\nend\n\nlemma degree_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]\n  {k : S} (p : R[X]) (h : is_smul_regular R k) :\n  (k \u2022 p).degree = p.degree :=\nbegin\n  refine le_antisymm _ _,\n  { rw degree_le_iff_coeff_zero,\n    intros m hm,\n    rw degree_lt_iff_coeff_zero at hm,\n    simp [hm m le_rfl] },\n  { rw degree_le_iff_coeff_zero,\n    intros m hm,\n    rw degree_lt_iff_coeff_zero at hm,\n    refine h _,\n    simpa using hm m le_rfl },\nend\n\nlemma nat_degree_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]\n  {k : S} (p : R[X]) (h : is_smul_regular R k) :\n  (k \u2022 p).nat_degree = p.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp] },\n  rw [\u2190with_bot.coe_eq_coe, \u2190degree_eq_nat_degree hp, \u2190degree_eq_nat_degree,\n      degree_smul_of_smul_regular p h],\n  contrapose! hp,\n  rw \u2190smul_zero k at hp,\n  exact h.polynomial hp\nend\n\nlemma leading_coeff_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]\n  {k : S} (p : R[X]) (h : is_smul_regular R k) :\n  (k \u2022 p).leading_coeff = k \u2022 p.leading_coeff :=\nby rw [leading_coeff, leading_coeff, coeff_smul, nat_degree_smul_of_smul_regular p h]\n\nlemma monic_of_is_unit_leading_coeff_inv_smul (h : is_unit p.leading_coeff) :\n  monic (h.unit\u207b\u00b9 \u2022 p) :=\nbegin\n  rw [monic.def, leading_coeff_smul_of_smul_regular _ (is_smul_regular_of_group _), units.smul_def],\n  obtain \u27e8k, hk\u27e9 := h,\n  simp only [\u2190hk, smul_eq_mul, \u2190units.coe_mul, units.coe_eq_one, inv_mul_eq_iff_eq_mul],\n  simp [units.ext_iff, is_unit.unit_spec]\nend\n\nlemma is_unit_leading_coeff_mul_right_eq_zero_iff (h : is_unit p.leading_coeff) {q : R[X]} :\n  p * q = 0 \u2194 q = 0 :=\nbegin\n  split,\n  { intro hp,\n    rw \u2190smul_eq_zero_iff_eq (h.unit)\u207b\u00b9 at hp,\n    have : (h.unit)\u207b\u00b9 \u2022 (p * q) = ((h.unit)\u207b\u00b9 \u2022 p) * q,\n    { ext,\n      simp only [units.smul_def, coeff_smul, coeff_mul, smul_eq_mul, mul_sum],\n      refine sum_congr rfl (\u03bb x hx, _),\n      rw \u2190mul_assoc },\n    rwa [this, monic.mul_right_eq_zero_iff] at hp,\n    exact monic_of_is_unit_leading_coeff_inv_smul _ },\n  { rintro rfl,\n    simp }\nend\n\n\n\nend not_zero_divisor\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/polynomial/monic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7424525078511683}}
{"text": "/-\nCopyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mathieu Guay-Paquet\n\n! This file was ported from Lean 3 source module order.pfilter\n! leanprover-community/mathlib commit 23aa88e32dcc9d2a24cca7bc23268567ed4cd7d6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.Ideal\n\n/-!\n# Order filters\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections\nrequire more structure, such as a bottom element, a top element, or\na join-semilattice structure.\n\n- `order.pfilter P`: The type of nonempty, downward directed, upward closed\n               subsets of `P`. This is dual to `order.ideal`, so it\n               simply wraps `order.ideal P\u1d52\u1d48`.\n- `order.is_pfilter P`: a predicate for when a `set P` is a filter.\n\n\nNote the relation between `order/filter` and `order/pfilter`: for any\ntype `\u03b1`, `filter \u03b1` represents the same mathematical object as\n`pfilter (set \u03b1)`.\n\n## References\n\n- <https://en.wikipedia.org/wiki/Filter_(mathematics)>\n\n## Tags\n\npfilter, filter, ideal, dual\n\n-/\n\n\nnamespace Order\n\nvariable {P : Type _}\n\n#print Order.PFilter /-\n/-- A filter on a preorder `P` is a subset of `P` that is\n  - nonempty\n  - downward directed\n  - upward closed. -/\nstructure PFilter (P) [Preorder P] where\n  dual : Ideal P\u1d52\u1d48\n#align order.pfilter Order.PFilter\n-/\n\n#print Order.IsPFilter /-\n/-- A predicate for when a subset of `P` is a filter. -/\ndef IsPFilter [Preorder P] (F : Set P) : Prop :=\n  @IsIdeal P\u1d52\u1d48 _ F\n#align order.is_pfilter Order.IsPFilter\n-/\n\n#print Order.IsPFilter.of_def /-\ntheorem IsPFilter.of_def [Preorder P] {F : Set P} (nonempty : F.Nonempty)\n    (directed : DirectedOn (\u00b7 \u2265 \u00b7) F) (mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F) :\n    IsPFilter F :=\n  \u27e8fun _ _ _ _ => mem_of_le \u2039_\u203a \u2039_\u203a, Nonempty, Directed\u27e9\n#align order.is_pfilter.of_def Order.IsPFilter.of_def\n-/\n\n#print Order.IsPFilter.toPFilter /-\n/-- Create an element of type `order.pfilter` from a set satisfying the predicate\n`order.is_pfilter`. -/\ndef IsPFilter.toPFilter [Preorder P] {F : Set P} (h : IsPFilter F) : PFilter P :=\n  \u27e8h.toIdeal\u27e9\n#align order.is_pfilter.to_pfilter Order.IsPFilter.toPFilter\n-/\n\nnamespace Pfilter\n\nsection Preorder\n\nvariable [Preorder P] {x y : P} (F s t : PFilter P)\n\ninstance [Inhabited P] : Inhabited (PFilter P) :=\n  \u27e8\u27e8default\u27e9\u27e9\n\n/-- A filter on `P` is a subset of `P`. -/\ninstance : Coe (PFilter P) (Set P) :=\n  \u27e8fun F => F.dual.carrier\u27e9\n\n/-- For the notation `x \u2208 F`. -/\ninstance : Membership P (PFilter P) :=\n  \u27e8fun x F => x \u2208 (F : Set P)\u27e9\n\n@[simp]\ntheorem SetLike.mem_coe : x \u2208 (F : Set P) \u2194 x \u2208 F :=\n  iff_of_eq rfl\n#align order.pfilter.mem_coe SetLike.mem_coe\u2093\n\n#print Order.PFilter.isPFilter /-\ntheorem isPFilter : IsPFilter (F : Set P) :=\n  F.dual.IsIdeal\n#align order.pfilter.is_pfilter Order.PFilter.isPFilter\n-/\n\n#print Order.PFilter.nonempty /-\ntheorem nonempty : (F : Set P).Nonempty :=\n  F.dual.Nonempty\n#align order.pfilter.nonempty Order.PFilter.nonempty\n-/\n\n#print Order.PFilter.directed /-\ntheorem directed : DirectedOn (\u00b7 \u2265 \u00b7) (F : Set P) :=\n  F.dual.Directed\n#align order.pfilter.directed Order.PFilter.directed\n-/\n\n#print Order.PFilter.mem_of_le /-\ntheorem mem_of_le {F : PFilter P} : x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F := fun h => F.dual.lower h\n#align order.pfilter.mem_of_le Order.PFilter.mem_of_le\n-/\n\n#print Order.PFilter.ext /-\n/-- Two filters are equal when their underlying sets are equal. -/\n@[ext]\ntheorem ext (h : (s : Set P) = t) : s = t := by\n  cases s\n  cases t\n  exact congr_arg _ (Ideal.ext h)\n#align order.pfilter.ext Order.PFilter.ext\n-/\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : PartialOrder (PFilter P) :=\n  PartialOrder.lift coe ext\n\n/- warning: order.pfilter.mem_of_mem_of_le -> Order.PFilter.mem_of_mem_of_le is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {x : P} {F : Order.PFilter.{u1} P _inst_1} {G : Order.PFilter.{u1} P _inst_1}, (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (Order.PFilter.hasMem.{u1} P _inst_1) x F) -> (LE.le.{u1} (Order.PFilter.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.PFilter.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (Order.PFilter.partialOrder.{u1} P _inst_1))) F G) -> (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (Order.PFilter.hasMem.{u1} P _inst_1) x G)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {x : P} {F : Order.PFilter.{u1} P _inst_1} {G : Order.PFilter.{u1} P _inst_1}, (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1)) x F) -> (LE.le.{u1} (Order.PFilter.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.PFilter.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (SetLike.instPartialOrder.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1)))) F G) -> (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1)) x G)\nCase conversion may be inaccurate. Consider using '#align order.pfilter.mem_of_mem_of_le Order.PFilter.mem_of_mem_of_le\u2093'. -/\n@[trans]\ntheorem mem_of_mem_of_le {F G : PFilter P} : x \u2208 F \u2192 F \u2264 G \u2192 x \u2208 G :=\n  Ideal.mem_of_mem_of_le\n#align order.pfilter.mem_of_mem_of_le Order.PFilter.mem_of_mem_of_le\n\n#print Order.PFilter.principal /-\n/-- The smallest filter containing a given element. -/\ndef principal (p : P) : PFilter P :=\n  \u27e8Ideal.principal p\u27e9\n#align order.pfilter.principal Order.PFilter.principal\n-/\n\n#print Order.PFilter.mem_mk /-\n@[simp]\ntheorem mem_mk (x : P) (I : Ideal P\u1d52\u1d48) : x \u2208 (\u27e8I\u27e9 : PFilter P) \u2194 OrderDual.toDual x \u2208 I :=\n  Iff.rfl\n#align order.pfilter.mem_def Order.PFilter.mem_mk\n-/\n\n/- warning: order.pfilter.principal_le_iff -> Order.PFilter.principal_le_iff is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {x : P} {F : Order.PFilter.{u1} P _inst_1}, Iff (LE.le.{u1} (Order.PFilter.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.PFilter.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (Order.PFilter.partialOrder.{u1} P _inst_1))) (Order.PFilter.principal.{u1} P _inst_1 x) F) (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (Order.PFilter.hasMem.{u1} P _inst_1) x F)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {x : P} {F : Order.PFilter.{u1} P _inst_1}, Iff (LE.le.{u1} (Order.PFilter.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.PFilter.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (SetLike.instPartialOrder.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1)))) (Order.PFilter.principal.{u1} P _inst_1 x) F) (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1)) x F)\nCase conversion may be inaccurate. Consider using '#align order.pfilter.principal_le_iff Order.PFilter.principal_le_iff\u2093'. -/\n@[simp]\ntheorem principal_le_iff {F : PFilter P} : principal x \u2264 F \u2194 x \u2208 F :=\n  Ideal.principal_le_iff\n#align order.pfilter.principal_le_iff Order.PFilter.principal_le_iff\n\n#print Order.PFilter.mem_principal /-\n@[simp]\ntheorem mem_principal : x \u2208 principal y \u2194 y \u2264 x :=\n  Ideal.mem_principal\n#align order.pfilter.mem_principal Order.PFilter.mem_principal\n-/\n\n/- warning: order.pfilter.antitone_principal -> Order.PFilter.antitone_principal is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P], Antitone.{u1, u1} P (Order.PFilter.{u1} P _inst_1) _inst_1 (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (Order.PFilter.partialOrder.{u1} P _inst_1)) (Order.PFilter.principal.{u1} P _inst_1)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P], Antitone.{u1, u1} P (Order.PFilter.{u1} P _inst_1) _inst_1 (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (SetLike.instPartialOrder.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1))) (Order.PFilter.principal.{u1} P _inst_1)\nCase conversion may be inaccurate. Consider using '#align order.pfilter.antitone_principal Order.PFilter.antitone_principal\u2093'. -/\n-- defeq abuse\ntheorem antitone_principal : Antitone (principal : P \u2192 PFilter P) := by delta Antitone <;> simp\n#align order.pfilter.antitone_principal Order.PFilter.antitone_principal\n\n/- warning: order.pfilter.principal_le_principal_iff -> Order.PFilter.principal_le_principal_iff is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {p : P} {q : P}, Iff (LE.le.{u1} (Order.PFilter.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.PFilter.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (Order.PFilter.partialOrder.{u1} P _inst_1))) (Order.PFilter.principal.{u1} P _inst_1 q) (Order.PFilter.principal.{u1} P _inst_1 p)) (LE.le.{u1} P (Preorder.toLE.{u1} P _inst_1) p q)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {p : P} {q : P}, Iff (LE.le.{u1} (Order.PFilter.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.PFilter.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P _inst_1) (SetLike.instPartialOrder.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1)))) (Order.PFilter.principal.{u1} P _inst_1 q) (Order.PFilter.principal.{u1} P _inst_1 p)) (LE.le.{u1} P (Preorder.toLE.{u1} P _inst_1) p q)\nCase conversion may be inaccurate. Consider using '#align order.pfilter.principal_le_principal_iff Order.PFilter.principal_le_principal_iff\u2093'. -/\ntheorem principal_le_principal_iff {p q : P} : principal q \u2264 principal p \u2194 p \u2264 q := by simp\n#align order.pfilter.principal_le_principal_iff Order.PFilter.principal_le_principal_iff\n\nend Preorder\n\nsection OrderTop\n\nvariable [Preorder P] [OrderTop P] {F : PFilter P}\n\n/- warning: order.pfilter.top_mem -> Order.PFilter.top_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] [_inst_2 : OrderTop.{u1} P (Preorder.toLE.{u1} P _inst_1)] {F : Order.PFilter.{u1} P _inst_1}, Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (Order.PFilter.hasMem.{u1} P _inst_1) (Top.top.{u1} P (OrderTop.toHasTop.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2)) F\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] [_inst_2 : OrderTop.{u1} P (Preorder.toLE.{u1} P _inst_1)] {F : Order.PFilter.{u1} P _inst_1}, Membership.mem.{u1, u1} P (Order.PFilter.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P _inst_1) P (Order.PFilter.instSetLikePFilter.{u1} P _inst_1)) (Top.top.{u1} P (OrderTop.toTop.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2)) F\nCase conversion may be inaccurate. Consider using '#align order.pfilter.top_mem Order.PFilter.top_mem\u2093'. -/\n/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/\n@[simp]\ntheorem top_mem : \u22a4 \u2208 F :=\n  Ideal.bot_mem _\n#align order.pfilter.top_mem Order.PFilter.top_mem\n\n/-- There is a bottom filter when `P` has a top element. -/\ninstance : OrderBot (PFilter P) where\n  bot := \u27e8\u22a5\u27e9\n  bot_le F := (bot_le : \u22a5 \u2264 F.dual)\n\nend OrderTop\n\n/-- There is a top filter when `P` has a bottom element. -/\ninstance {P} [Preorder P] [OrderBot P] : OrderTop (PFilter P)\n    where\n  top := \u27e8\u22a4\u27e9\n  le_top F := (le_top : F.dual \u2264 \u22a4)\n\nsection SemilatticeInf\n\nvariable [SemilatticeInf P] {x y : P} {F : PFilter P}\n\n/- warning: order.pfilter.inf_mem -> Order.PFilter.inf_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeInf.{u1} P] {x : P} {y : P} {F : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))}, (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.hasMem.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) x F) -> (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.hasMem.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) y F) -> (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.hasMem.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Inf.inf.{u1} P (SemilatticeInf.toHasInf.{u1} P _inst_1) x y) F)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeInf.{u1} P] {x : P} {y : P} {F : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))}, (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1)))) x F) -> (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1)))) y F) -> (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Inf.inf.{u1} P (SemilatticeInf.toInf.{u1} P _inst_1) x y) F)\nCase conversion may be inaccurate. Consider using '#align order.pfilter.inf_mem Order.PFilter.inf_mem\u2093'. -/\n/-- A specific witness of `pfilter.directed` when `P` has meets. -/\ntheorem inf_mem (hx : x \u2208 F) (hy : y \u2208 F) : x \u2293 y \u2208 F :=\n  Ideal.sup_mem hx hy\n#align order.pfilter.inf_mem Order.PFilter.inf_mem\n\n/- warning: order.pfilter.inf_mem_iff -> Order.PFilter.inf_mem_iff is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeInf.{u1} P] {x : P} {y : P} {F : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))}, Iff (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.hasMem.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Inf.inf.{u1} P (SemilatticeInf.toHasInf.{u1} P _inst_1) x y) F) (And (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.hasMem.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) x F) (Membership.Mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.hasMem.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) y F))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeInf.{u1} P] {x : P} {y : P} {F : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))}, Iff (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Inf.inf.{u1} P (SemilatticeInf.toInf.{u1} P _inst_1) x y) F) (And (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1)))) x F) (Membership.mem.{u1, u1} P (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instMembership.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P _inst_1)))) y F))\nCase conversion may be inaccurate. Consider using '#align order.pfilter.inf_mem_iff Order.PFilter.inf_mem_iff\u2093'. -/\n@[simp]\ntheorem inf_mem_iff : x \u2293 y \u2208 F \u2194 x \u2208 F \u2227 y \u2208 F :=\n  Ideal.sup_mem_iff\n#align order.pfilter.inf_mem_iff Order.PFilter.inf_mem_iff\n\nend SemilatticeInf\n\nsection CompleteSemilatticeInf\n\nvariable [CompleteSemilatticeInf P] {F : PFilter P}\n\n/- warning: order.pfilter.Inf_gc -> Order.PFilter.inf\u209b_gc is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : CompleteSemilatticeInf.{u1} P], GaloisConnection.{u1, u1} P (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) (OrderDual.preorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.partialOrder.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (fun (x : P) => coeFn.{succ u1, succ u1} (Equiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (fun (_x : Equiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) => (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) -> (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (Equiv.hasCoeToFun.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (OrderDual.toDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.principal.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) x)) (fun (F : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => InfSet.inf\u209b.{u1} P (CompleteSemilatticeInf.toHasInf.{u1} P _inst_1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (coeBase.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (Order.PFilter.Set.hasCoe.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))))) (coeFn.{succ u1, succ u1} (Equiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (fun (_x : Equiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) -> (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Equiv.hasCoeToFun.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (OrderDual.ofDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) F)))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : CompleteSemilatticeInf.{u1} P], GaloisConnection.{u1, u1} P (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) (OrderDual.preorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instPartialOrder.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))))) (fun (x : P) => FunLike.coe.{succ u1, succ u1, succ u1} (Equiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (fun (_x : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) => OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (OrderDual.toDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.principal.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) x)) (fun (F : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => InfSet.inf\u209b.{u1} P (CompleteSemilatticeInf.toInfSet.{u1} P _inst_1) (SetLike.coe.{u1, u1} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) F) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (FunLike.coe.{succ u1, succ u1, succ u1} (Equiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (fun (_x : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (OrderDual.ofDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) F)))\nCase conversion may be inaccurate. Consider using '#align order.pfilter.Inf_gc Order.PFilter.inf\u209b_gc\u2093'. -/\ntheorem inf\u209b_gc :\n    GaloisConnection (fun x => OrderDual.toDual (principal x)) fun F =>\n      inf\u209b (OrderDual.ofDual F : PFilter P) :=\n  fun x F => by\n  simp\n  rfl\n#align order.pfilter.Inf_gc Order.PFilter.inf\u209b_gc\n\n/- warning: order.pfilter.Inf_gi -> Order.PFilter.infGi is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : CompleteSemilatticeInf.{u1} P], GaloisCoinsertion.{u1, u1} P (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) (OrderDual.preorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Order.PFilter.partialOrder.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (fun (x : P) => coeFn.{succ u1, succ u1} (Equiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (fun (_x : Equiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) => (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) -> (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (Equiv.hasCoeToFun.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (OrderDual.toDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.principal.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) x)) (fun (F : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => InfSet.inf\u209b.{u1} P (CompleteSemilatticeInf.toHasInf.{u1} P _inst_1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (coeBase.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (Set.{u1} P) (Order.PFilter.Set.hasCoe.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))))) (coeFn.{succ u1, succ u1} (Equiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (fun (_x : Equiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) -> (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Equiv.hasCoeToFun.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (OrderDual.ofDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) F)))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : CompleteSemilatticeInf.{u1} P], GaloisCoinsertion.{u1, u1} P (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) (OrderDual.preorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (PartialOrder.toPreorder.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (SetLike.instPartialOrder.{u1, u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))))) (fun (x : P) => FunLike.coe.{succ u1, succ u1, succ u1} (Equiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (fun (_x : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) => OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))))) (OrderDual.toDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.principal.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)) x)) (fun (F : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => InfSet.inf\u209b.{u1} P (CompleteSemilatticeInf.toInfSet.{u1} P _inst_1) (SetLike.coe.{u1, u1} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) F) P (Order.PFilter.instSetLikePFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) (FunLike.coe.{succ u1, succ u1, succ u1} (Equiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (fun (_x : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) => Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1))) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u1} (OrderDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) (OrderDual.ofDual.{u1} (Order.PFilter.{u1} P (PartialOrder.toPreorder.{u1} P (CompleteSemilatticeInf.toPartialOrder.{u1} P _inst_1)))) F)))\nCase conversion may be inaccurate. Consider using '#align order.pfilter.Inf_gi Order.PFilter.infGi\u2093'. -/\n/-- If a poset `P` admits arbitrary `Inf`s, then `principal` and `Inf` form a Galois coinsertion. -/\ndef infGi :\n    GaloisCoinsertion (fun x => OrderDual.toDual (principal x)) fun F =>\n      inf\u209b (OrderDual.ofDual F : PFilter P)\n    where\n  choice F _ := inf\u209b (id F : PFilter P)\n  gc := inf\u209b_gc\n  u_l_le s := inf\u209b_le <| mem_principal.2 <| le_refl s\n  choice_eq _ _ := rfl\n#align order.pfilter.Inf_gi Order.PFilter.infGi\n\nend CompleteSemilatticeInf\n\nend Pfilter\n\nend Order\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/Pfilter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7423578197499502}}
{"text": "variable {p : Prop}\nvariable {q : Prop}\n\ntheorem t1 : p \u2192 q \u2192 p := fun hp : p => fun hq : q => hp\n\n#print t1\n\nnamespace unsound\naxiom unsound : False -- void, uninhabited, etc\ntheorem ex : 1 = 0 :=\n  False.elim unsound\nend unsound\n\n-- we can also use universal quantification explicitly instead of with variable\ntheorem t1alt : \u2200 {p q : Prop}, p \u2192 q \u2192 p :=\n  fun {p q : Prop} (hp : p) (hq : q) => hp\n\n/-\nLean defines all the standard logical connectives and notation. The propositional connectives come with the following notation:\n\nAscii Unicode Editor_shortcut Definition\nTrue\t\t\t                    True\nFalse\t\t\t                    False\nNot\t  \u00ac\t      \\not, \\neg\t    Not\n/\\\t  \u2227\t      \\and\t          And\n\\/\t  \u2228\t      \\or           \tOr\n->\t\u2192\t       \\to, \\r, \\imp\t If\n<->\t\u2194\t       \\iff, \\lr\t     Iff\n-/\n\n#check p \u2192 q \u2192 p \u2227 q\n#check \u00ac p \u2192 p \u2194 False\n#check p \u2228 q -> q \u2228 p\n\n/- \nThe expression And.intro invokes the and-introduction rule: given proof of p and\na proof of q, get a proof of p ^ q.\n-/\n\nexample (hp : p) (hq : q) : p \u2227 q := And.intro hp hq\n\n#check fun (hp : p) (hq : q) => And.intro hp hq\n\n/-\nLikewise, And.left and And.right return, respectively, p and q given p ^ q.\n-/\n\nexample (hpq : p \u2227 q) : p := And.left hpq\nexample (hpq : p \u2227 q) : q := And.right hpq\n\nexample (hpq : p \u2227 q) : q \u2227 p :=\n  And.intro (And.right hpq) (And.left hpq)\n\n-- Note that And is really a constructor for an ordered pair, the more fundamental\n-- type in a props-as-types correspondence:\n\nvariable (hp : p) (hq : q)\n\n#check (\u27e8hp, hq\u27e9 : p \u2227 q) -- this is \\langle and \\rangle or \\< and \\> \n\n-- We can also just say hpq.right, hpq.left\n\nexample (hpq : p \u2227 q) : q \u2227 p :=\n  \u27e8 hpq.right, hpq.left \u27e9 \n\nexample (h: p \u2227 q) : q \u2227 p \u2227 q :=\n  \u27e8h.right,\u27e8h.left,h.right\u27e9\u27e9\n\n\nvariable (xs : List Nat)\n#check xs.length\n\n-- Likewise we can use Or introduction rules:\n\nexample (hp:p) : (p \u2228 q) := Or.intro_left q hp\nexample (hq:q) : (p \u2228 q) := Or.intro_right p hq\n\nexample (h:p\u2228q) : q\u2228p :=\n  Or.elim h \n    (fun hp : p => show q\u2228p from Or.inr hp) -- Or.inr = Or.intro_right _\n    (fun hq : q => show q\u2228p from Or.inl hq)\n\n-- There's also negation:\n\nexample (hpq: p\u2192q) (hnq: \u00acq) : \u00acp :=\n  fun hp:p => show False from (hnq (hpq hp))\n\nexample (hp:p) (hnp: \u00acp) : q := False.elim (hnp hp) -- can obtain anything from contradiction\n\nexample (hp:p) (hnp: \u00acp) : q := absurd hp hnp\n\nvariable (r: Prop)\n\nexample (hnp : \u00acp) (hq:q) (hqp:q->p) : r :=\n  absurd (hqp hq) hnp\n\n-- And logical equivalence; Iff.intro gives p<->q from p->q and q->p. Iff.mp givs\n-- a proof of p->q from p<->q, and Iff.mpr gives q->p.\n\n\nvariable (p q : Prop)\ntheorem and_swap : p \u2227 q \u2194 q\u2227p :=\n  Iff.intro\n    (fun h: p\u2227q => show q\u2227p from And.intro (And.right h) (And.left h))\n    (fun h:q\u2227p => show p\u2227q from And.intro (And.right h) (And.left h))\n  \n#check and_swap p q\n\n-- we can rewrite this more concisely using type inference / pair-And equivalence:\n\nvariable (p q : Prop)\ntheorem and_swap' : p\u2227q \u2194 q\u2227p :=\n  \u27e8fun h => \u27e8h.right,h.left\u27e9, fun h => \u27e8h.right,h.left\u27e9\u27e9 \n\n-- auxillary subgoals: Lean lets us break up proofs into subgoals for structuring\n-- particularly long proofs:\n\nvariable (p q : Prop)\nexample (h : p\u2227q) : q \u2227 p :=\n  have hp:p := h.left\n  have hq:q := h.right\n  show q \u2227 p from And.intro hq hp\n\n-- Internally, `have hp:p:=s;t` produces the term `(fun (h:p) => t) s` - meaning\n-- s is a proof of p, t is a proof of the desired conclusion assuming h:p, \n-- and the two are combined by lambda application and abstraction.\n\n-- All the constructs we used have been constructive. To use full classical logic\n-- (eg law of excluded middle) we will need to use the Classical namespace\n\nopen Classical\n\nvariable (p:Prop)\n#check em p\n\n-- In particular this allows us to use the principle of double-negation \n-- elimination:\n\ntheorem dne {p:Prop} (h: \u00ac\u00acp) : p :=\n  Or.elim (em p)\n    (fun hp : p => hp)\n    (fun hnp : \u00acp => absurd hnp h)\n\n-- This means we can use proof by contradiction: to prove p, we assume \u00acp and\n-- derive False. We can also use dne to prove em alternatively:\n\ntheorem em' (p:Prop) : p\u2228\u00acp :=\n  dne (fun hcontra:\u00ac(p\u2228\u00acp) => hcontra (byCases Or.inl Or.inr)) \n  -- isn't byCases \"cheating?\" I don't think so! A quick check indicates that you\n  -- can only prove one direction with intutionistic logic (along with a \n  -- non-intuitionistic assumption)\n\n\n-- Exercises\nvariable (p q r : Prop)\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := \n  Iff.intro\n    (fun \u27e8hp,hq\u27e9 => \u27e8hq,hp\u27e9)\n    (fun \u27e8hq,hp\u27e9 => \u27e8hp,hq\u27e9)\n\nexample : p \u2228 q \u2194 q \u2228 p := \n  Iff.intro\n    (fun hpq => Or.elim hpq (fun hp => Or.inr hp) (fun hq => Or.inl hq))\n    (fun hqp => Or.elim hqp (fun hp => Or.inr hp) (fun hq => Or.inl hq))\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := \n  Iff.intro\n    (fun \u27e8\u27e8p,q\u27e9,r\u27e9 => \u27e8p,\u27e8q,r\u27e9\u27e9)\n    (fun \u27e8p,\u27e8q,r\u27e9\u27e9 => \u27e8\u27e8p,q\u27e9,r\u27e9)\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := \n  Iff.intro\n    (fun hpqr => Or.elim hpqr \n        (fun hpq => Or.elim hpq Or.inl (fun hq => Or.inr (Or.inl hq))) \n        (fun hr => Or.inr (Or.inr hr)))\n    (fun hpqr => Or.elim hpqr \n        (fun hp => Or.inl (Or.inl hp))\n        (fun hqr => Or.elim hqr (fun hq => Or.inl (Or.inr hq)) Or.inr))\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := \n  Iff.intro\n    (fun \u27e8hp,hqr\u27e9 => Or.elim hqr \n                      (fun hq => Or.inl \u27e8hp,hq\u27e9) \n                      (fun hr => Or.inr \u27e8hp,hr\u27e9))\n    (fun hpqpr => Or.elim hpqpr \n                    (fun \u27e8hp,hq\u27e9 => \u27e8hp,Or.inl hq\u27e9) \n                    (fun \u27e8hp,hr\u27e9 => \u27e8hp,Or.inr hr\u27e9))\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := \n  Iff.intro\n    (fun hpqr => Or.elim hpqr \n                  (fun hp => \u27e8Or.inl hp, Or.inl hp\u27e9) \n                  (fun \u27e8hq,hr\u27e9 => \u27e8Or.inr hq, Or.inr hr\u27e9))\n    (fun \u27e8hpq,hpr\u27e9 => \n      Or.elim hpq (fun hp => Or.inl hp) \n                  (fun hq => Or.elim hpr \n                    (fun hp => Or.inl hp) -- This should never be reached, can we rewrite to avoid?\n                    (fun hr => Or.inr \u27e8hq,hr\u27e9)))\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := \n  Iff.intro\n    (fun htqtr => fun \u27e8hp,hq\u27e9 => (htqtr hp) hq)\n    (fun hpqtr => fun hp => fun hq => hpqtr \u27e8hp,hq\u27e9)\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := \n  Iff.intro\n    (fun hqtr => \u27e8fun hp => hqtr (Or.inl hp),fun hq => hqtr (Or.inr hq)\u27e9)\n    (fun \u27e8hptr,hqtr\u27e9 => fun hpoq => Or.elim hpoq hptr hqtr)\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := \n  Iff.intro\n    (fun notpq => \u27e8fun hp => notpq (Or.inl hp),fun hq => notpq (Or.inr hq) \u27e9 )\n    (fun \u27e8notP,notQ\u27e9 => fun pOq => Or.elim pOq notP notQ)\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := \n  fun npOnQ => Or.elim npOnQ \n                      (fun np => fun \u27e8hp,hq\u27e9 => np hp) \n                      (fun nq => fun \u27e8hp,hq\u27e9 => nq hq)\n\nexample : \u00ac(p \u2227 \u00acp) := (fun \u27e8hp,hnp\u27e9 => hnp hp)\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := \n  fun \u27e8hp,nq\u27e9 => (fun ptq => nq (ptq hp))\n\nexample : \u00acp \u2192 (p \u2192 q) := \n  fun np => fun hp => False.elim (np hp)\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := \n  fun npOq => Or.elim npOq \n                     (fun np => fun hp => False.elim (np hp)) \n                     (fun hq => fun hp => hq)\n\nexample : p \u2228 False \u2194 p := \n  Iff.intro\n    (fun pOf => Or.elim pOf id False.elim)\n    Or.inl\n\nexample : p \u2227 False \u2194 False := \n  Iff.intro\n    (fun \u27e8p,contra\u27e9 => contra)\n    False.elim\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := \n  fun ptq => fun nq => (fun p => nq (ptq p))\n\n\n-- These require classical reasoning.\nopen Classical\n\nvariable (p q r s : Prop)\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := fun ptrOs =>\n  byCases\n    (fun hp : p => Or.elim (ptrOs hp) (fun hr:r => Or.inl (fun hp':p => hr)) (fun hs:s => Or.inr (fun hp':p => hs)))\n    (fun hnp: \u00acp => (Or.inl (fun hp:p => False.elim (hnp hp))))\n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := fun npAq =>\n  byCases\n    (fun hp:p => byCases (fun hq:q => False.elim (npAq \u27e8hp,hq\u27e9)) Or.inr)\n    Or.inl\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := fun npTq =>\n  byCases\n    (fun hp:p => \u27e8hp,(fun hq:q => npTq (fun hp2 => hq))\u27e9)\n    (fun hnp:\u00acp => False.elim (npTq (fun hp:p => False.elim (hnp hp))))\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := fun pTq =>\n  byCases\n    (fun hp:p => Or.inr (pTq hp))\n    Or.inl\n\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := fun nqTnp =>\n  byCases\n    (fun hq:q => fun hp:p => hq)\n    (fun hnq:\u00acq => fun hp:p => False.elim ((nqTnp hnq) hp))\n\nexample : p \u2228 \u00acp := \n  byCases Or.inl Or.inr\n\nexample : ((p \u2192 q) \u2192 p) \u2192 p := fun pqp =>\n  byCases\n    (fun hp:p => hp)\n    (fun hnp:\u00acp => pqp (fun hp:p => False.elim (hnp hp)))\n\n-- This does NOT require classical logic\nexample: \u00ac(p \u2194 \u00acp) := \n  fun \u27e8c,d\u27e9 => \n    let r := (fun hp:p => (c hp) hp)\n    r (d r)\n", "meta": {"author": "nicklecompte", "repo": "LeanLearning", "sha": "cb1a51f159569194b951441bb1940650e09ccc34", "save_path": "github-repos/lean/nicklecompte-LeanLearning", "path": "github-repos/lean/nicklecompte-LeanLearning/LeanLearning-cb1a51f159569194b951441bb1940650e09ccc34/src/PropsAndProofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7423578163917851}}
{"text": "open classical \nvariables (\u03b1 : Type) (p q : \u03b1 -> Prop)\nvariable a : \u03b1 \nvariable r : Prop\nvariable z : Prop\ntheorem dne {z: Prop} (h: \u00ac\u00acz): z :=\n  by_contradiction\n    (assume h1 : not z,\n    show false, from h h1)\nexample : (\u00ac \u2200 x, p x) \u2194  (\u2203 x, \u00ac p x) :=\n    iff.intro\n      (assume h: \u00ac\u2200 x, p x,\n      by_contradiction\n        (assume h1 : \u00ac(\u2203 x, \u00acp x),\n        have h2 : \u2200 x, \u00ac\u00acp x, from forall_not_of_not_exists h1,\n        have h3 : \u2200 x, p x, from \n        (assume x, dne (h2 x)),\n        show false, from h h3))\n      (assume h: \u2203 x, \u00acp x,\n      exists.elim h $\n      assume x(hx : \u00ac p x),\n        assume hno: \u2200 x, p x,\n        have h1 : p x, from hno x,\n        show false,from hx h1 \n      )\n", "meta": {"author": "ucmani", "repo": "leanexamples", "sha": "387daef46eaf61bd4a08db076f60ac237daff559", "save_path": "github-repos/lean/ucmani-leanexamples", "path": "github-repos/lean/ucmani-leanexamples/leanexamples-387daef46eaf61bd4a08db076f60ac237daff559/i8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7423275871924951}}
{"text": "/-\nCopyright (c) 2022. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Moritz Firsching, Fabian Kruse, Nikolas Kuhn\n-/\nimport analysis.p_series\nimport analysis.special_functions.log.deriv\nimport tactic.positivity\nimport data.real.pi.wallis\n\n/-!\n# Stirling's formula\n\nThis file proves Stirling's formula for the factorial.\nIt states that $n!$ grows asymptotically like $\\sqrt{2\\pi n}(\\frac{n}{e})^n$.\n\n## Proof outline\n\nThe proof follows: <https://proofwiki.org/wiki/Stirling%27s_Formula>.\n\nWe proceed in two parts.\n\n**Part 1**: We consider the sequence $a_n$ of fractions $\\frac{n!}{\\sqrt{2n}(\\frac{n}{e})^n}$\nand prove that this sequence converges to a real, positive number $a$. For this the two main\ningredients are\n - taking the logarithm of the sequence and\n - using the series expansion of $\\log(1 + x)$.\n\n**Part 2**: We use the fact that the series defined in part 1 converges againt a real number $a$\nand prove that $a = \\sqrt{\\pi}$. Here the main ingredient is the convergence of Wallis' product\nformula for `\u03c0`.\n-/\n\nopen_locale topology real big_operators nat\nopen finset filter nat real\n\nnamespace stirling\n/-!\n ### Part 1\n https://proofwiki.org/wiki/Stirling%27s_Formula#Part_1\n-/\n\n/--\nDefine `stirling_seq n` as $\\frac{n!}{\\sqrt{2n}(\\frac{n}{e})^n}$.\nStirling's formula states that this sequence has limit $\\sqrt(\u03c0)$.\n-/\nnoncomputable def stirling_seq (n : \u2115) : \u211d :=\nn! / (sqrt (2 * n) * (n / exp 1) ^ n)\n\n@[simp] lemma stirling_seq_zero : stirling_seq 0 = 0 :=\nby rw [stirling_seq, cast_zero, mul_zero, real.sqrt_zero, zero_mul, div_zero]\n\n@[simp] lemma stirling_seq_one : stirling_seq 1 = exp 1 / sqrt 2 :=\nby rw [stirling_seq, pow_one, factorial_one, cast_one, mul_one, mul_one_div, one_div_div]\n\n/--\nWe have the expression\n`log (stirling_seq (n + 1)) = log(n + 1)! - 1 / 2 * log(2 * n) - n * log ((n + 1) / e)`.\n-/\nlemma log_stirling_seq_formula (n : \u2115) : log (stirling_seq n.succ) =\n  log n.succ!- 1 / 2 * log (2 * n.succ) - n.succ * log (n.succ / exp 1) :=\nby rw [stirling_seq, log_div, log_mul, sqrt_eq_rpow, log_rpow, real.log_pow, tsub_tsub];\n  try { apply ne_of_gt }; positivity -- TODO: Make `positivity` handle `\u2260 0` goals\n\n/--\nThe sequence `log (stirling_seq (m + 1)) - log (stirling_seq (m + 2))` has the series expansion\n   `\u2211 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))`\n-/\nlemma log_stirling_seq_diff_has_sum (m : \u2115) :\n  has_sum (\u03bb k : \u2115, (1 : \u211d) / (2 * k.succ + 1) * ((1 / (2 * m.succ + 1)) ^ 2) ^ k.succ)\n  (log (stirling_seq m.succ) - log (stirling_seq m.succ.succ)) :=\nbegin\n  change has_sum ((\u03bb b : \u2115, 1 / (2 * (b : \u211d) + 1) * ((1 / (2 * m.succ + 1)) ^ 2) ^ b) \u2218 succ) _,\n  refine (has_sum_nat_add_iff 1).mpr _,\n  convert (has_sum_log_one_add_inv $ cast_pos.mpr (succ_pos m)).mul_left ((m.succ : \u211d) + 1 / 2),\n  { ext k,\n    rw [\u2190 pow_mul, pow_add],\n    push_cast,\n    have : 2 * (k : \u211d) + 1 \u2260 0, {norm_cast, exact succ_ne_zero (2*k)},\n    have : 2 * ((m : \u211d) + 1) + 1 \u2260 0, {norm_cast, exact succ_ne_zero (2*m.succ)},\n    field_simp,\n    ring },\n  { have h : \u2200 (x : \u211d) (hx : x \u2260 0), 1 + x\u207b\u00b9 = (x + 1) / x,\n    { intros, rw [_root_.add_div, div_self hx, inv_eq_one_div], },\n    simp only [log_stirling_seq_formula, log_div, log_mul, log_exp, factorial_succ, cast_mul,\n      cast_succ, cast_zero, range_one, sum_singleton, h] { discharger :=\n      `[norm_cast, apply_rules [mul_ne_zero, succ_ne_zero, factorial_ne_zero, exp_ne_zero]] },\n    ring },\nend\n\n/-- The sequence `log \u2218 stirling_seq \u2218 succ` is monotone decreasing -/\nlemma log_stirling_seq'_antitone : antitone (real.log \u2218 stirling_seq \u2218 succ) :=\nantitone_nat_of_succ_le $ \u03bb n, sub_nonneg.mp $ (log_stirling_seq_diff_has_sum n).nonneg $ \u03bb m,\n  by positivity\n\n/--\nWe have a bound for successive elements in the sequence `log (stirling_seq k)`.\n-/\nlemma log_stirling_seq_diff_le_geo_sum (n : \u2115) :\n  log (stirling_seq n.succ) - log (stirling_seq n.succ.succ) \u2264\n  (1 / (2 * n.succ + 1)) ^ 2 / (1 - (1 / (2 * n.succ + 1)) ^ 2) :=\nbegin\n  have h_nonneg : 0 \u2264 ((1 / (2 * (n.succ : \u211d) + 1)) ^ 2) := sq_nonneg _,\n  have g : has_sum (\u03bb k : \u2115, ((1 / (2 * (n.succ : \u211d) + 1)) ^ 2) ^ k.succ)\n    ((1 / (2 * n.succ + 1)) ^ 2 / (1 - (1 / (2 * n.succ + 1)) ^ 2)),\n  { have := (has_sum_geometric_of_lt_1 h_nonneg _).mul_left ((1 / (2 * (n.succ : \u211d) + 1)) ^ 2),\n    { simp_rw \u2190pow_succ at this,\n      exact this, },\n    rw [one_div, inv_pow],\n    exact inv_lt_one (one_lt_pow ((lt_add_iff_pos_left 1).mpr $ by positivity) two_ne_zero) },\n  have hab : \u2200 (k : \u2115), (1 / (2 * (k.succ : \u211d) + 1)) * ((1 / (2 * n.succ + 1)) ^ 2) ^ k.succ \u2264\n    ((1 / (2 * n.succ + 1)) ^ 2) ^ k.succ,\n  { refine \u03bb k, mul_le_of_le_one_left (pow_nonneg h_nonneg k.succ) _,\n    rw one_div,\n    exact inv_le_one (le_add_of_nonneg_left $ by positivity) },\n  exact has_sum_le hab (log_stirling_seq_diff_has_sum n) g,\nend\n\n/--\nWe have the bound  `log (stirling_seq n) - log (stirling_seq (n+1))` \u2264 1/(4 n^2)\n-/\nlemma log_stirling_seq_sub_log_stirling_seq_succ (n : \u2115) :\n  log (stirling_seq n.succ) - log (stirling_seq n.succ.succ) \u2264 1 / (4 * n.succ ^ 2) :=\nbegin\n  have h\u2081 : 0 < 4 * ((n : \u211d) + 1) ^ 2 := by positivity,\n  have h\u2083 : 0 < (2 * ((n : \u211d) + 1) + 1) ^ 2 := by positivity,\n  have h\u2082 : 0 < 1 - (1 / (2 * ((n : \u211d) + 1) + 1)) ^ 2,\n  { rw \u2190 mul_lt_mul_right h\u2083,\n    have H : 0 < (2 * ((n : \u211d) + 1) + 1) ^ 2 - 1 := by nlinarith [@cast_nonneg \u211d _ n],\n    convert H using 1; field_simp [h\u2083.ne'] },\n  refine (log_stirling_seq_diff_le_geo_sum n).trans _,\n  push_cast,\n  rw div_le_div_iff h\u2082 h\u2081,\n  field_simp [h\u2083.ne'],\n  rw div_le_div_right h\u2083,\n  ring_nf,\n  norm_cast,\n  linarith,\nend\n\n/-- For any `n`, we have `log_stirling_seq 1 - log_stirling_seq n \u2264 1/4 * \u2211' 1/k^2`  -/\nlemma log_stirling_seq_bounded_aux :\n  \u2203 (c : \u211d), \u2200 (n : \u2115), log (stirling_seq 1) - log (stirling_seq n.succ) \u2264 c :=\nbegin\n  let d := \u2211' k : \u2115, (1 : \u211d) / k.succ ^ 2,\n  use (1 / 4 * d : \u211d),\n  let log_stirling_seq' : \u2115 \u2192 \u211d := \u03bb k, log (stirling_seq k.succ),\n  intro n,\n  have h\u2081 : \u2200 k, log_stirling_seq' k - log_stirling_seq' (k + 1) \u2264 1 / 4 * (1 / k.succ ^ 2) :=\n  by { intro k, convert log_stirling_seq_sub_log_stirling_seq_succ k using 1, field_simp, },\n  have h\u2082 : \u2211 (k : \u2115) in range n, (1 : \u211d) / (k.succ) ^ 2 \u2264 d := by\n  { exact sum_le_tsum (range n) (\u03bb k _, by positivity)\n      ((summable_nat_add_iff 1).mpr $ real.summable_one_div_nat_pow.mpr one_lt_two) },\n  calc\n  log (stirling_seq 1) - log (stirling_seq n.succ) = log_stirling_seq' 0 - log_stirling_seq' n : rfl\n  ... = \u2211 k in range n, (log_stirling_seq' k - log_stirling_seq' (k + 1)) : by\n    rw \u2190 sum_range_sub' log_stirling_seq' n\n  ... \u2264 \u2211 k in range n, (1/4) * (1 / k.succ^2) : sum_le_sum (\u03bb k _, h\u2081 k)\n  ... = 1 / 4 * \u2211 k in range n, 1 / k.succ ^ 2 : by rw mul_sum\n  ... \u2264 1 / 4 * d : mul_le_mul_of_nonneg_left h\u2082 $ by positivity,\nend\n\n/-- The sequence `log_stirling_seq` is bounded below for `n \u2265 1`. -/\nlemma log_stirling_seq_bounded_by_constant : \u2203 c, \u2200 (n : \u2115), c \u2264 log (stirling_seq n.succ) :=\nbegin\n  obtain \u27e8d, h\u27e9 := log_stirling_seq_bounded_aux,\n  exact \u27e8log (stirling_seq 1) - d, \u03bb n, sub_le_comm.mp (h n)\u27e9,\nend\n\n/-- The sequence `stirling_seq` is positive for `n > 0`  -/\nlemma stirling_seq'_pos (n : \u2115) : 0 < stirling_seq n.succ := by { unfold stirling_seq, positivity }\n\n/--\nThe sequence `stirling_seq` has a positive lower bound.\n-/\nlemma stirling_seq'_bounded_by_pos_constant : \u2203 a, 0 < a \u2227 \u2200 n : \u2115, a \u2264 stirling_seq n.succ :=\nbegin\n  cases log_stirling_seq_bounded_by_constant with c h,\n  refine \u27e8exp c, exp_pos _, \u03bb n, _\u27e9,\n  rw \u2190 le_log_iff_exp_le (stirling_seq'_pos n),\n  exact h n,\nend\n\n/-- The sequence `stirling_seq \u2218 succ` is monotone decreasing -/\nlemma stirling_seq'_antitone : antitone (stirling_seq \u2218 succ) :=\n\u03bb n m h, (log_le_log (stirling_seq'_pos m) (stirling_seq'_pos n)).mp (log_stirling_seq'_antitone h)\n\n/-- The limit `a` of the sequence `stirling_seq` satisfies `0 < a` -/\nlemma stirling_seq_has_pos_limit_a :\n  \u2203 (a : \u211d), 0 < a \u2227 tendsto stirling_seq at_top (\ud835\udcdd a) :=\nbegin\n  obtain \u27e8x, x_pos, hx\u27e9 := stirling_seq'_bounded_by_pos_constant,\n  have hx' : x \u2208 lower_bounds (set.range (stirling_seq \u2218 succ)) := by simpa [lower_bounds] using hx,\n  refine \u27e8_, lt_of_lt_of_le x_pos (le_cInf (set.range_nonempty _) hx'), _\u27e9,\n  rw \u2190filter.tendsto_add_at_top_iff_nat 1,\n  exact tendsto_at_top_cinfi stirling_seq'_antitone \u27e8x, hx'\u27e9,\nend\n\n/-!\n ### Part 2\n https://proofwiki.org/wiki/Stirling%27s_Formula#Part_2\n-/\n\n/-- The sequence `n / (2 * n + 1)` tends to `1/2` -/\nlemma tendsto_self_div_two_mul_self_add_one :\n  tendsto (\u03bb (n : \u2115), (n : \u211d) / (2 * n + 1)) at_top (\ud835\udcdd (1 / 2)) :=\nbegin\n  conv { congr, skip, skip, rw [one_div, \u2190add_zero (2 : \u211d)] },\n  refine (((tendsto_const_div_at_top_nhds_0_nat 1).const_add (2 : \u211d)).inv\u2080\n    ((add_zero (2 : \u211d)).symm \u25b8 two_ne_zero)).congr' (eventually_at_top.mpr \u27e81, \u03bb n hn, _\u27e9),\n  rw [add_div' (1 : \u211d) 2 n (cast_ne_zero.mpr (one_le_iff_ne_zero.mp hn)), inv_div],\nend\n\n/-- For any `n \u2260 0`, we have the identity\n`(stirling_seq n)^4 / (stirling_seq (2*n))^2 * (n / (2 * n + 1)) = W n`, where `W n` is the\n`n`-th partial product of Wallis' formula for `\u03c0 / 2`. -/\nlemma stirling_seq_pow_four_div_stirling_seq_pow_two_eq (n : \u2115) (hn : n \u2260 0) :\n  ((stirling_seq n) ^ 4 / (stirling_seq (2 * n)) ^ 2) * (n / (2 * n + 1)) = wallis.W n :=\nbegin\n  rw [bit0_eq_two_mul, stirling_seq, pow_mul, stirling_seq, wallis.W_eq_factorial_ratio],\n  simp_rw [div_pow, mul_pow],\n  rw [sq_sqrt, sq_sqrt],\n  any_goals { positivity },\n  have : (n : \u211d) \u2260 0, from cast_ne_zero.mpr hn,\n  have : (exp 1) \u2260 0, from exp_ne_zero 1,\n  have : ((2 * n)!: \u211d) \u2260 0, from cast_ne_zero.mpr (factorial_ne_zero (2 * n)),\n  have : 2 * (n : \u211d) + 1 \u2260 0, by {norm_cast, exact succ_ne_zero (2*n)},\n  field_simp,\n  simp only [mul_pow, mul_comm 2 n, mul_comm 4 n, pow_mul],\n  ring,\nend\n\n/--\nSuppose the sequence `stirling_seq` (defined above) has the limit `a \u2260 0`.\nThen the Wallis sequence `W n` has limit `a^2 / 2`.\n-/\nlemma second_wallis_limit (a : \u211d) (hane : a \u2260 0) (ha : tendsto stirling_seq at_top (\ud835\udcdd a)) :\n  tendsto wallis.W at_top (\ud835\udcdd (a ^ 2 / 2)):=\nbegin\n  refine tendsto.congr' (eventually_at_top.mpr \u27e81, \u03bb n hn,\n    stirling_seq_pow_four_div_stirling_seq_pow_two_eq n (one_le_iff_ne_zero.mp hn)\u27e9) _,\n  have h : a ^ 2 / 2 = (a ^ 4 / a ^ 2) * (1 / 2),\n  { rw [mul_one_div, \u2190mul_one_div (a ^ 4) (a ^ 2), one_div, \u2190pow_sub_of_lt a],\n    norm_num },\n  rw h,\n  exact ((ha.pow 4).div ((ha.comp (tendsto_id.const_mul_at_top' two_pos)).pow 2)\n    (pow_ne_zero 2 hane)).mul tendsto_self_div_two_mul_self_add_one,\nend\n\n/-- **Stirling's Formula** -/\ntheorem tendsto_stirling_seq_sqrt_pi : tendsto (\u03bb (n : \u2115), stirling_seq n) at_top (\ud835\udcdd (sqrt \u03c0)) :=\nbegin\n  obtain \u27e8a, hapos, halimit\u27e9 := stirling_seq_has_pos_limit_a,\n  have h\u03c0 : \u03c0 / 2 = a ^ 2 / 2 := tendsto_nhds_unique wallis.tendsto_W_nhds_pi_div_two\n    (second_wallis_limit a hapos.ne' halimit),\n  rwa [(div_left_inj' (two_ne_zero' \u211d)).mp h\u03c0, sqrt_sq hapos.le],\nend\n\nend stirling\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/stirling.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.7422948624682922}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Julian Kuelshammer\n-/\nimport algebra.big_operators.order\nimport group_theory.coset\nimport data.nat.totient\nimport data.int.gcd\nimport data.set.finite\nimport dynamics.periodic_pts\nimport algebra.iterate_hom\n\n/-!\n# Order of an element\n\nThis file defines the order of an element of a finite group. For a finite group `G` the order of\n`x \u2208 G` is the minimal `n \u2265 1` such that `x ^ n = 1`.\n\n## Main definitions\n\n* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite\n  order.\n* `is_of_fin_add_order` is the additive analogue of `is_of_find_order`.\n* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`\n  if `x` has infinite order.\n* `add_order_of` is the additive analogue of `order_of`.\n\n## Tags\norder of an element\n-/\n\nopen function nat\n\nuniverses u v\n\nvariables {G : Type u} {A : Type v}\nvariables {x y : G} {a b : A} {n m : \u2115}\n\nsection monoid_add_monoid\n\nvariables [monoid G] [add_monoid A]\n\nsection is_of_fin_order\n\nlemma is_periodic_pt_add_iff_nsmul_eq_zero (a : A) :\n  is_periodic_pt ((+) a) n 0 \u2194 n \u2022 a = 0 :=\nby rw [is_periodic_pt, is_fixed_pt, add_left_iterate, add_zero]\n\n@[to_additive is_periodic_pt_add_iff_nsmul_eq_zero]\nlemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 \u2194 x ^ n = 1 :=\nby rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]\n\n/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite\norder, i.e. there exists `n \u2265 1` such that `n \u2022 a = 0`.-/\ndef is_of_fin_add_order (a : A) : Prop :=\n(0 : A) \u2208 periodic_pts ((+) a)\n\n/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there\nexists `n \u2265 1` such that `x ^ n = 1`.-/\n@[to_additive is_of_fin_add_order]\ndef is_of_fin_order (x : G) : Prop :=\n(1 : G) \u2208 periodic_pts ((*) x)\n\nlemma is_of_fin_add_order_of_mul_iff :\n  is_of_fin_add_order (additive.of_mul x) \u2194 is_of_fin_order x := iff.rfl\n\nlemma is_of_fin_order_of_add_iff :\n  is_of_fin_order (multiplicative.of_add a) \u2194 is_of_fin_add_order a := iff.rfl\n\nlemma is_of_fin_add_order_iff_nsmul_eq_zero (a : A) :\n  is_of_fin_add_order a \u2194 \u2203 n, 0 < n \u2227 n \u2022 a = 0 :=\nby { convert iff.rfl, simp only [exists_prop, is_periodic_pt_add_iff_nsmul_eq_zero] }\n\n@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]\nlemma is_of_fin_order_iff_pow_eq_one (x : G) :\n  is_of_fin_order x \u2194 \u2203 n, 0 < n \u2227 x ^ n = 1 :=\nby { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }\n\nend is_of_fin_order\n\n/-- `add_order_of a` is the order of the element `a`, i.e. the `n \u2265 1`, s.t. `n \u2022 a = 0` if it\nexists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention.-/\nnoncomputable def add_order_of (a : A) : \u2115 :=\nminimal_period ((+) a) 0\n\n/-- `order_of x` is the order of the element `x`, i.e. the `n \u2265 1`, s.t. `x ^ n = 1` if it exists.\nOtherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/\n@[to_additive add_order_of]\nnoncomputable def order_of (x : G) : \u2115 :=\nminimal_period ((*) x) 1\n\nattribute [to_additive add_order_of] order_of\n\n@[to_additive]\nlemma commute.order_of_mul_dvd_lcm (h : commute x y) :\n  order_of (x * y) \u2223 nat.lcm (order_of x) (order_of y) :=\nbegin\n  convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,\n  rw [order_of, comp_mul_left],\nend\n\n@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :\n  add_order_of (additive.of_mul x) = order_of x := rfl\n\n@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :\n  order_of (multiplicative.of_add a) = add_order_of a := rfl\n\n@[to_additive add_order_of_pos']\nlemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=\nminimal_period_pos_of_mem_periodic_pts h\n\nlemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=\nbegin\n  convert is_periodic_pt_minimal_period ((*) x) _,\n  rw [order_of, mul_left_iterate, mul_one],\nend\n\nlemma add_order_of_nsmul_eq_zero (a : A) : add_order_of a \u2022 a = 0 :=\nbegin\n  convert is_periodic_pt_minimal_period ((+) a) _,\n  rw [add_order_of, add_left_iterate, add_zero],\nend\n\nattribute [to_additive add_order_of_nsmul_eq_zero] pow_order_of_eq_one\n\n@[to_additive add_order_of_eq_zero]\nlemma order_of_eq_zero (h : \u00ac is_of_fin_order x) : order_of x = 0 :=\nby rwa [order_of, minimal_period, dif_neg]\n\nlemma nsmul_ne_zero_of_lt_add_order_of' (n0 : n \u2260 0) (h : n < add_order_of a) :\n  n \u2022 a \u2260 0 :=\n\u03bb j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h\n  ((is_periodic_pt_add_iff_nsmul_eq_zero a).mpr j)\n\n@[to_additive nsmul_ne_zero_of_lt_add_order_of']\nlemma pow_eq_one_of_lt_order_of' (n0 : n \u2260 0) (h : n < order_of x) : x ^ n \u2260 1 :=\n\u03bb j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h\n  ((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)\n\nlemma add_order_of_le_of_nsmul_eq_zero (hn : 0 < n) (h : n \u2022 a = 0) : add_order_of a \u2264 n :=\nis_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_add_iff_nsmul_eq_zero)\n\n@[to_additive add_order_of_le_of_nsmul_eq_zero]\nlemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x \u2264 n :=\nis_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)\n\n@[simp] lemma order_of_one : order_of (1 : G) = 1 :=\nby rw [order_of, one_mul_eq_id, minimal_period_id]\n\n@[simp] lemma add_order_of_zero : add_order_of (0 : A) = 1 :=\nby simp only [\u2190order_of_of_add_eq_add_order_of, order_of_one, of_add_zero]\n\nattribute [to_additive add_order_of_zero] order_of_one\n\n@[simp] lemma order_of_eq_one_iff : order_of x = 1 \u2194 x = 1 :=\nby rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]\n\n@[simp] lemma add_order_of_eq_one_iff : add_order_of a = 1 \u2194 a = 0 :=\nby simp [\u2190 order_of_of_add_eq_add_order_of]\n\nattribute [to_additive add_order_of_eq_one_iff] order_of_eq_one_iff\n\nlemma pow_eq_mod_order_of {n : \u2115} : x ^ n = x ^ (n % order_of x) :=\ncalc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]\n       ... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]\n\nlemma nsmul_eq_mod_add_order_of {n : \u2115} : n \u2022 a = (n % add_order_of a) \u2022 a :=\nbegin\n  apply multiplicative.of_add.injective,\n  rw [\u2190 order_of_of_add_eq_add_order_of, of_add_nsmul, of_add_nsmul, pow_eq_mod_order_of],\nend\n\nattribute [to_additive nsmul_eq_mod_add_order_of] pow_eq_mod_order_of\n\nlemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x \u2223 n :=\nis_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)\n\nlemma add_order_of_dvd_of_nsmul_eq_zero (h : n \u2022 a = 0) : add_order_of a \u2223 n :=\nis_periodic_pt.minimal_period_dvd ((is_periodic_pt_add_iff_nsmul_eq_zero _).mpr h)\n\nattribute [to_additive add_order_of_dvd_of_nsmul_eq_zero] order_of_dvd_of_pow_eq_one\n\nlemma add_order_of_dvd_iff_nsmul_eq_zero {n : \u2115} : add_order_of a \u2223 n \u2194 n \u2022 a = 0 :=\n\u27e8\u03bb h, by rw [nsmul_eq_mod_add_order_of, nat.mod_eq_zero_of_dvd h, zero_nsmul],\n  add_order_of_dvd_of_nsmul_eq_zero\u27e9\n\n@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]\nlemma order_of_dvd_iff_pow_eq_one {n : \u2115} : order_of x \u2223 n \u2194 x ^ n = 1 :=\n\u27e8\u03bb h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one\u27e9\n\nlemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :\n  \u2203 m : \u2115, (x ^ n) ^ m = x :=\nbegin\n  by_cases h0 : order_of x = 0,\n  { rw [h0, coprime_zero_right] at h,\n    exact \u27e81, by rw [h, pow_one, pow_one]\u27e9 },\n  by_cases h1 : order_of x = 1,\n  { exact \u27e80, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]\u27e9 },\n  obtain \u27e8m, hm\u27e9 :=\n    exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr \u27e8h0, h1\u27e9),\n  exact \u27e8m, by rw [\u2190pow_mul, pow_eq_mod_order_of, hm, pow_one]\u27e9,\nend\n\nlemma exists_nsmul_eq_self_of_coprime (a : A)\n  (h : coprime n (add_order_of a)) : \u2203 m : \u2115, m \u2022 (n \u2022 a) = a :=\nbegin\n  change n.coprime (order_of (multiplicative.of_add a)) at h,\n  exact exists_pow_eq_self_of_coprime h,\nend\n\nattribute [to_additive exists_nsmul_eq_self_of_coprime] exists_pow_eq_self_of_coprime\n\nlemma add_order_of_eq_add_order_of_iff {B : Type*} [add_monoid B] {b : B} :\n  add_order_of a = add_order_of b \u2194 \u2200 n : \u2115, n \u2022 a = 0 \u2194 n \u2022 b = 0 :=\nbegin\n  simp_rw \u2190 add_order_of_dvd_iff_nsmul_eq_zero,\n  exact \u27e8\u03bb h n, by rw h, \u03bb h, nat.dvd_antisymm ((h _).mpr (dvd_refl _)) ((h _).mp (dvd_refl _))\u27e9,\nend\n\n@[to_additive add_order_of_eq_add_order_of_iff]\nlemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :\n  order_of x = order_of y \u2194 \u2200 n : \u2115, x ^ n = 1 \u2194 y ^ n = 1 :=\nby simp_rw [\u2190 is_periodic_pt_mul_iff_pow_eq_one, \u2190 minimal_period_eq_minimal_period_iff, order_of]\n\nlemma add_order_of_injective {B : Type*} [add_monoid B] (f : A \u2192+ B)\n  (hf : function.injective f) (a : A) : add_order_of (f a) = add_order_of a :=\nby simp_rw [add_order_of_eq_add_order_of_iff, \u2190f.map_nsmul, \u2190f.map_zero, hf.eq_iff, iff_self,\n            forall_const]\n\n@[to_additive add_order_of_injective]\nlemma order_of_injective {H : Type*} [monoid H] (f : G \u2192* H)\n  (hf : function.injective f) (x : G) : order_of (f x) = order_of x :=\nby simp_rw [order_of_eq_order_of_iff, \u2190f.map_pow, \u2190f.map_one, hf.eq_iff, iff_self, forall_const]\n\n@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}\n  (y : H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\nvariables (x)\n\nlemma order_of_pow' (h : n \u2260 0) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd h,\n  simp only [order_of, mul_left_iterate],\nend\n\nvariables (a)\n\nlemma add_order_of_nsmul' (h : n \u2260 0) :\n  add_order_of (n \u2022 a) = add_order_of a / gcd (add_order_of a) n :=\nby simpa [\u2190 order_of_of_add_eq_add_order_of, of_add_nsmul] using order_of_pow' _ h\n\nattribute [to_additive add_order_of_nsmul'] order_of_pow'\n\nvariable (n)\n\nlemma order_of_pow'' (h : is_of_fin_order x) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd' h,\n  simp only [order_of, mul_left_iterate],\nend\n\nlemma add_order_of_nsmul'' (h : is_of_fin_add_order a) :\n  add_order_of (n \u2022 a) = add_order_of a / gcd (add_order_of a) n :=\nby simp [\u2190 order_of_of_add_eq_add_order_of, of_add_nsmul,\n  order_of_pow'' _ n (is_of_fin_order_of_add_iff.mpr h)]\n\nattribute [to_additive add_order_of_nsmul''] order_of_pow''\n\nsection p_prime\n\nvariables {a x n} {p : \u2115} [hp : fact p.prime]\ninclude hp\n\nlemma add_order_of_eq_prime (hg : p \u2022 a = 0) (hg1 : a \u2260 0) : add_order_of a = p :=\nminimal_period_eq_prime ((is_periodic_pt_add_iff_nsmul_eq_zero _).mpr hg)\n  (by rwa [is_fixed_pt, add_zero])\n\n@[to_additive add_order_of_eq_prime]\nlemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x \u2260 1) : order_of x = p :=\nminimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)\n  (by rwa [is_fixed_pt, mul_one])\n\nlemma add_order_of_eq_prime_pow (hnot : \u00ac (p ^ n) \u2022 a = 0) (hfin : (p ^ (n + 1)) \u2022 a = 0) :\n  add_order_of a = p ^ (n + 1) :=\nbegin\n  apply minimal_period_eq_prime_pow;\n  rwa is_periodic_pt_add_iff_nsmul_eq_zero,\nend\n\n@[to_additive add_order_of_eq_prime_pow]\nlemma order_of_eq_prime_pow (hnot : \u00ac x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :\n  order_of x = p ^ (n + 1) :=\nbegin\n  apply minimal_period_eq_prime_pow;\n  rwa is_periodic_pt_mul_iff_pow_eq_one,\nend\n\nomit hp\n-- An example on how to determine the order of an element of a finite group.\nexample : order_of (-1 : units \u2124) = 2 :=\nbegin\n  haveI : fact (prime 2) := \u27e8prime_two\u27e9,\n  exact order_of_eq_prime (int.units_mul_self _) dec_trivial,\nend\n\nend p_prime\n\nend monoid_add_monoid\n\nsection cancel_monoid\nvariables [left_cancel_monoid G] (x)\nvariables [add_left_cancel_monoid A] (a)\n\nlemma pow_injective_aux (h : n \u2264 m)\n  (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\nby_contradiction $ assume ne : n \u2260 m,\n  have h\u2081 : m - n > 0, from nat.pos_of_ne_zero (by simp [nat.sub_eq_iff_eq_add h, ne.symm]),\n  have h\u2082 : m = n + (m - n) := (nat.add_sub_of_le h).symm,\n  have h\u2083 : x ^ (m - n) = 1,\n    by { rw [h\u2082, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (x ^ n) },\n  have le : order_of x \u2264 m - n, from order_of_le_of_pow_eq_one h\u2081 h\u2083,\n  have lt : m - n < order_of x,\n    from (nat.sub_lt_left_iff_lt_add h).mpr $ nat.lt_add_left _ _ _ hm,\n  lt_irrefl _ (le.trans_lt lt)\n\n-- TODO: This lemma was originally private, but this doesn't seem to work with `to_additive`,\n-- therefore the private got removed.\nlemma nsmul_injective_aux {n m : \u2115} (h : n \u2264 m)\n  (hm : m < add_order_of a) (eq : n \u2022 a = m \u2022 a) : n = m :=\nbegin\n  apply_fun multiplicative.of_add at eq,\n  rw [of_add_nsmul, of_add_nsmul] at eq,\n  rw \u2190 order_of_of_add_eq_add_order_of at hm,\n  exact pow_injective_aux (multiplicative.of_add a) h hm eq,\nend\n\nattribute [to_additive nsmul_injective_aux] pow_injective_aux\n\nlemma nsmul_injective_of_lt_add_order_of {n m : \u2115}\n  (hn : n < add_order_of a) (hm : m < add_order_of a) (eq : n \u2022 a = m \u2022 a) : n = m :=\n(le_total n m).elim\n  (assume h, nsmul_injective_aux a h hm eq)\n  (assume h, (nsmul_injective_aux a h hn eq.symm).symm)\n\n@[to_additive nsmul_injective_of_lt_add_order_of]\nlemma pow_injective_of_lt_order_of\n  (hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\n(le_total n m).elim\n  (assume h, pow_injective_aux x h hm eq)\n  (assume h, (pow_injective_aux x h hn eq.symm).symm)\n\nend cancel_monoid\n\nsection group\nvariables [group G] [add_group A] {x a} {i : \u2124}\n\n@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}\n  (y: H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\nlemma gpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=\ncalc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :\n    by rw [int.mod_add_div]\n       ... = x ^ (i % order_of x) :\n    by simp [gpow_add, gpow_mul, pow_order_of_eq_one]\n\nlemma gsmul_eq_mod_add_order_of : i \u2022 a = (i % add_order_of a) \u2022 a :=\nbegin\n  apply multiplicative.of_add.injective,\n  simp [of_add_gsmul, gpow_eq_mod_order_of],\nend\n\nattribute [to_additive gsmul_eq_mod_add_order_of] gpow_eq_mod_order_of\n\nend group\n\nsection fintype\nvariables [fintype G] [fintype A]\n\nsection finite_monoid\nvariables [monoid G] [add_monoid A]\nopen_locale big_operators\n\nlemma sum_card_add_order_of_eq_card_nsmul_eq_zero [decidable_eq A] (hn : 0 < n) :\n  \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb a : A, add_order_of a = m)).card\n  = (finset.univ.filter (\u03bb a : A, n \u2022 a = 0)).card :=\ncalc \u2211 m in (finset.range n.succ).filter (\u2223 n),\n        (finset.univ.filter (\u03bb a : A, add_order_of a = m)).card\n    = _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm\n... = _ : congr_arg finset.card (finset.ext (begin\n  assume a,\n  suffices : add_order_of a \u2264 n \u2227 add_order_of a \u2223 n \u2194 n \u2022 a = 0,\n  { simpa [nat.lt_succ_iff], },\n  exact \u27e8\u03bb h, let \u27e8m, hm\u27e9 := h.2 in\n                by rw [hm, mul_comm, mul_nsmul, add_order_of_nsmul_eq_zero, nsmul_zero],\n    \u03bb h, \u27e8add_order_of_le_of_nsmul_eq_zero hn h, add_order_of_dvd_of_nsmul_eq_zero h\u27e9\u27e9\nend))\n\n@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]\nlemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :\n  \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n  = (finset.univ.filter (\u03bb x : G, x ^ n = 1)).card :=\ncalc \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n    = _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm\n... = _ : congr_arg finset.card (finset.ext (begin\n  assume x,\n  suffices : order_of x \u2264 n \u2227 order_of x \u2223 n \u2194 x ^ n = 1,\n  { simpa [nat.lt_succ_iff], },\n  exact \u27e8\u03bb h, let \u27e8m, hm\u27e9 := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],\n    \u03bb h, \u27e8order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h\u27e9\u27e9\nend))\n\nend finite_monoid\n\nsection finite_cancel_monoid\n-- TODO: Of course everything also works for right_cancel_monoids.\nvariables [left_cancel_monoid G] [add_left_cancel_monoid A]\n\n-- TODO: Use this to show that a finite left cancellative monoid is a group.\nlemma exists_pow_eq_one (x : G) : is_of_fin_order x :=\nbegin\n  refine (is_of_fin_order_iff_pow_eq_one _).mpr _,\n  obtain \u27e8i, j, a_eq, ne\u27e9 : \u2203(i j : \u2115), x ^ i = x ^ j \u2227 i \u2260 j :=\n    by simpa only [not_forall, exists_prop] using (not_injective_infinite_fintype (\u03bbi:\u2115, x^i)),\n  wlog h'' : j \u2264 i,\n  refine \u27e8i - j, nat.sub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _\u27e9,\n  rw [mul_one, \u2190 pow_add, \u2190 a_eq, nat.add_sub_cancel' h''],\nend\n\nlemma exists_nsmul_eq_zero (a : A) : is_of_fin_add_order a :=\nbegin\n  rcases exists_pow_eq_one (multiplicative.of_add a) with \u27e8i, hi1, hi2\u27e9,\n  refine \u27e8i, hi1, multiplicative.of_add.injective _\u27e9,\n  rw [add_left_iterate, of_add_zero, of_add_eq_one, add_zero],\n  exact (is_periodic_pt_mul_iff_pow_eq_one (multiplicative.of_add a)).mp hi2,\nend\n\nattribute [to_additive exists_nsmul_eq_zero] exists_pow_eq_one\n\nlemma add_order_of_le_card_univ : add_order_of a \u2264 fintype.card A :=\nfinset.le_card_of_inj_on_range (\u2022 a)\n  (assume n _, finset.mem_univ _)\n  (assume i hi j hj, nsmul_injective_of_lt_add_order_of a hi hj)\n\n@[to_additive add_order_of_le_card_univ]\nlemma order_of_le_card_univ : order_of x \u2264 fintype.card G :=\nfinset.le_card_of_inj_on_range ((^) x)\n  (assume n _, finset.mem_univ _)\n  (assume i hi j hj, pow_injective_of_lt_order_of x hi hj)\n\n/-- This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative additive monoid.-/\nlemma add_order_of_pos (a : A) : 0 < add_order_of a := add_order_of_pos' (exists_nsmul_eq_zero _)\n\n/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative monoid.-/\n@[to_additive add_order_of_pos]\nlemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)\n\nopen nat\n\n/-- This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less\nwhich is automatic in the case of a finite cancellative additive monoid. -/\nlemma add_order_of_nsmul (a : A) :\n  add_order_of (n \u2022 a) = add_order_of a / gcd (add_order_of a) n :=\nadd_order_of_nsmul'' _ _ (exists_nsmul_eq_zero _)\n\n/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is\nautomatic in the case of a finite cancellative monoid.-/\n@[to_additive add_order_of_nsmul]\nlemma order_of_pow (x : G) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)\n\nlemma mem_multiples_iff_mem_range_add_order_of [decidable_eq A] :\n  b \u2208 add_submonoid.multiples a \u2194\n  b \u2208 (finset.range (add_order_of a)).image ((\u2022 a) : \u2115 \u2192 A)  :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' (add_order_of_pos a)\n  (assume i, nsmul_eq_mod_add_order_of.symm)\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of]\nlemma mem_powers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)\n  (assume i, pow_eq_mod_order_of.symm)\n\nnoncomputable instance decidable_multiples [decidable_eq A] :\n  decidable_pred (add_submonoid.multiples a : set A) :=\nbegin\n  assume b,\n  apply decidable_of_iff' (b \u2208 (finset.range (add_order_of a)).image (\u2022 a)),\n  exact mem_multiples_iff_mem_range_add_order_of,\nend\n\n@[to_additive decidable_multiples]\nnoncomputable instance decidable_powers [decidable_eq G] :\n  decidable_pred (submonoid.powers x : set G) :=\nbegin\n  assume y,\n  apply decidable_of_iff'\n    (y \u2208 (finset.range (order_of x)).image ((^) x)),\n  exact mem_powers_iff_mem_range_order_of\nend\n\n/-- The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`. -/\nnoncomputable def fin_equiv_powers (x : G) :\n  fin (order_of x) \u2243 (submonoid.powers x : set G) :=\nequiv.of_bijective (\u03bb n, \u27e8x ^ \u2191n, \u27e8n, rfl\u27e9\u27e9) \u27e8\u03bb \u27e8i, hi\u27e9 \u27e8j, hj\u27e9 ij,\n  subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),\n  \u03bb \u27e8_, i, rfl\u27e9, \u27e8\u27e8i % order_of x, mod_lt i (order_of_pos x)\u27e9, subtype.eq pow_eq_mod_order_of.symm\u27e9\u27e9\n\n/-- The equivalence between `fin (add_order_of a)` and `add_submonoid.multiples a`,\n  sending `i` to `i \u2022 a`.\"-/\nnoncomputable def fin_equiv_multiples (a : A) :\n  fin (add_order_of a) \u2243 (add_submonoid.multiples a : set A) :=\nfin_equiv_powers (multiplicative.of_add a)\n\nattribute [to_additive fin_equiv_multiples] fin_equiv_powers\n\n@[simp] lemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :\n  fin_equiv_powers x n = \u27e8x ^ \u2191n, n, rfl\u27e9 := rfl\n\n@[simp] lemma fin_equiv_multiples_apply {a : A} {n : fin (add_order_of a)} :\n  fin_equiv_multiples a n = \u27e8nsmul \u2191n a, n, rfl\u27e9 := rfl\n\nattribute [to_additive fin_equiv_multiples_apply] fin_equiv_powers_apply\n\n@[simp] lemma fin_equiv_powers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2115), x ^ m = x ^ n} :\n  ((fin_equiv_powers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,\n  pow_eq_mod_order_of, fin.coe_mk]\n\n@[simp] lemma fin_equiv_multiples_symm_apply (a : A) (n : \u2115)\n  {hn : \u2203 (m : \u2115), m \u2022 a = n \u2022 a} :\n  ((fin_equiv_multiples a).symm \u27e8n \u2022 a, hn\u27e9) =\n    \u27e8n % add_order_of a, nat.mod_lt _ (add_order_of_pos a)\u27e9 :=\nfin_equiv_powers_symm_apply (multiplicative.of_add a) n\n\nattribute [to_additive fin_equiv_multiples_symm_apply] fin_equiv_powers_symm_apply\n\n/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\nnoncomputable def powers_equiv_powers (h : order_of x = order_of y) :\n  (submonoid.powers x : set G) \u2243 (submonoid.powers y : set G) :=\n(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))\n\n/-- The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`. -/\nnoncomputable def multiples_equiv_multiples (h : add_order_of a = add_order_of b) :\n  (add_submonoid.multiples a : set A) \u2243 (add_submonoid.multiples b : set A) :=\n(fin_equiv_multiples a).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_multiples b))\n\nattribute [to_additive multiples_equiv_multiples] powers_equiv_powers\n\n@[simp]\nlemma powers_equiv_powers_apply (h : order_of x = order_of y)\n  (n : \u2115) : powers_equiv_powers h \u27e8x ^ n, n, rfl\u27e9 = \u27e8y ^ n, n, rfl\u27e9 :=\nbegin\n  rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_powers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_powers_symm_apply],\n  simp [h]\nend\n\n@[simp]\nlemma multiples_equiv_multiples_apply (h : add_order_of a = add_order_of b)\n  (n : \u2115) : multiples_equiv_multiples h \u27e8n \u2022 a, n, rfl\u27e9 = \u27e8n \u2022 b, n, rfl\u27e9 :=\npowers_equiv_powers_apply h n\n\nattribute [to_additive multiples_equiv_multiples_apply] powers_equiv_powers_apply\n\nlemma order_eq_card_powers [decidable_eq G] :\n  order_of x = fintype.card (submonoid.powers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_powers x\u27e9)\n\nlemma add_order_of_eq_card_multiples [decidable_eq A] :\n  add_order_of a = fintype.card (add_submonoid.multiples a : set A) :=\n(fintype.card_fin (add_order_of a)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_multiples a\u27e9)\n\nattribute [to_additive add_order_of_eq_card_multiples] order_eq_card_powers\n\nend finite_cancel_monoid\n\nsection finite_group\nvariables [group G] [add_group A]\n\nlemma exists_gpow_eq_one (x : G) : \u2203 (i : \u2124) (H : i \u2260 0), x ^ (i : \u2124) = 1 :=\n--lemma exists_gpow_eq_one (a : \u03b1) : \u2203 (i : \u2124) (H : i \u2260 0), a ^ (i : \u2124) = 1 :=\nbegin\n  rcases exists_pow_eq_one x with \u27e8w, hw1, hw2\u27e9,\n  refine \u27e8w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _\u27e9,\n  rw gpow_coe_nat,\n  exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,\nend\n\nlemma exists_gsmul_eq_zero (a : A) : \u2203 (i : \u2124) (H : i \u2260 0), i \u2022 a = 0 :=\n@exists_gpow_eq_one (multiplicative A) _ _ a\n\nattribute [to_additive] exists_gpow_eq_one\n\nlemma mem_multiples_iff_mem_gmultiples :\n  b \u2208 add_submonoid.multiples a \u2194 b \u2208 add_subgroup.gmultiples a :=\n\u27e8\u03bb \u27e8n, hn\u27e9, \u27e8n, by simp * at *\u27e9, \u03bb \u27e8i, hi\u27e9, \u27e8(i % add_order_of a).nat_abs,\n  by { simp only [nsmul_eq_smul] at hi \u22a2,\n       rwa  [\u2190 gsmul_coe_nat,\n       int.nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2\n          (add_order_of_pos a))), \u2190 gsmul_eq_mod_add_order_of] } \u27e9\u27e9\n\nopen subgroup\n\n@[to_additive mem_multiples_iff_mem_gmultiples]\nlemma mem_powers_iff_mem_gpowers : y \u2208 submonoid.powers x \u2194 y \u2208 gpowers x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, \u27e8n, by simp * at *\u27e9,\n\u03bb \u27e8i, hi\u27e9, \u27e8(i % order_of x).nat_abs,\n  by rwa [\u2190 gpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _\n    (int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),\n    \u2190 gpow_eq_mod_order_of]\u27e9\u27e9\n\nlemma multiples_eq_gmultiples (a : A) :\n  (add_submonoid.multiples a : set A) = add_subgroup.gmultiples a :=\nset.ext $ \u03bb y, mem_multiples_iff_mem_gmultiples\n\n@[to_additive multiples_eq_gmultiples]\nlemma powers_eq_gpowers (x : G) : (submonoid.powers x : set G) = gpowers x :=\nset.ext $ \u03bb x, mem_powers_iff_mem_gpowers\n\nlemma mem_gmultiples_iff_mem_range_add_order_of [decidable_eq A] :\n  b \u2208 add_subgroup.gmultiples a \u2194 b \u2208 (finset.range (add_order_of a)).image (\u2022 a) :=\nby rw [\u2190 mem_multiples_iff_mem_gmultiples, mem_multiples_iff_mem_range_add_order_of]\n\n@[to_additive mem_gmultiples_iff_mem_range_add_order_of]\nlemma mem_gpowers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 subgroup.gpowers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nby rw [\u2190 mem_powers_iff_mem_gpowers, mem_powers_iff_mem_range_order_of]\n\nnoncomputable instance decidable_gmultiples [decidable_eq A] :\n  decidable_pred (add_subgroup.gmultiples a : set A) :=\nbegin\n  rw \u2190 multiples_eq_gmultiples,\n  exact decidable_multiples,\nend\n\n@[to_additive decidable_gmultiples]\nnoncomputable instance decidable_gpowers [decidable_eq G] :\n  decidable_pred (subgroup.gpowers x : set G) :=\nbegin\n  rw \u2190 powers_eq_gpowers,\n  exact decidable_powers,\nend\n\n/-- The equivalence between `fin (order_of x)` and `subgroup.gpowers x`, sending `i` to `x ^ i`. -/\nnoncomputable def fin_equiv_gpowers (x : G) :\n  fin (order_of x) \u2243 (subgroup.gpowers x : set G) :=\n(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_gpowers x))\n\n/-- The equivalence between `fin (add_order_of a)` and `subgroup.gmultiples a`,\n  sending `i` to `i \u2022 a`. -/\nnoncomputable def fin_equiv_gmultiples (a : A) :\n  fin (add_order_of a) \u2243 (add_subgroup.gmultiples a : set A) :=\nfin_equiv_gpowers (multiplicative.of_add a)\n\nattribute [to_additive fin_equiv_gmultiples] fin_equiv_gpowers\n\n@[simp] lemma fin_equiv_gpowers_apply {n : fin (order_of x)} :\n  fin_equiv_gpowers x n = \u27e8x ^ (n : \u2115), n, gpow_coe_nat x n\u27e9 := rfl\n\n@[simp] lemma fin_equiv_gmultiples_apply {n : fin (add_order_of a)} :\n  fin_equiv_gmultiples a n = \u27e8(n : \u2115) \u2022 a, n, gsmul_coe_nat a n\u27e9 :=\nfin_equiv_gpowers_apply\n\nattribute [to_additive fin_equiv_gmultiples_apply] fin_equiv_gpowers_apply\n\n@[simp] lemma fin_equiv_gpowers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2124), x ^ m = x ^ n} :\n  ((fin_equiv_gpowers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby { rw [fin_equiv_gpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],\n  exact fin_equiv_powers_symm_apply x n }\n\n@[simp] lemma fin_equiv_gmultiples_symm_apply (a : A) (n : \u2115)\n  {hn : \u2203 (m : \u2124), m \u2022 a = n \u2022 a} :\n  ((fin_equiv_gmultiples a).symm \u27e8n \u2022 a, hn\u27e9) =\n    \u27e8n % add_order_of a, nat.mod_lt _ (add_order_of_pos a)\u27e9 :=\nfin_equiv_gpowers_symm_apply (multiplicative.of_add a) n\n\nattribute [to_additive fin_equiv_gmultiples_symm_apply] fin_equiv_gpowers_symm_apply\n\n/-- The equivalence between `subgroup.gpowers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\nnoncomputable def gpowers_equiv_gpowers (h : order_of x = order_of y) :\n  (subgroup.gpowers x : set G) \u2243 (subgroup.gpowers y : set G) :=\n(fin_equiv_gpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_gpowers y))\n\n/-- The equivalence between `subgroup.gmultiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`. -/\nnoncomputable def gmultiples_equiv_gmultiples (h : add_order_of a = add_order_of b) :\n  (add_subgroup.gmultiples a : set A) \u2243 (add_subgroup.gmultiples b : set A) :=\n(fin_equiv_gmultiples a).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_gmultiples b))\n\nattribute [to_additive gmultiples_equiv_gmultiples] gpowers_equiv_gpowers\n\n@[simp]\nlemma gpowers_equiv_gpowers_apply (h : order_of x = order_of y)\n  (n : \u2115) : gpowers_equiv_gpowers h \u27e8x ^ n, n, gpow_coe_nat x n\u27e9 = \u27e8y ^ n, n, gpow_coe_nat y n\u27e9 :=\nbegin\n  rw [gpowers_equiv_gpowers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_gpowers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_gpowers_symm_apply],\n  simp [h]\nend\n\n@[simp]\nlemma gmultiples_equiv_gmultiples_apply (h : add_order_of a = add_order_of b) (n : \u2115) :\n  gmultiples_equiv_gmultiples h \u27e8n \u2022 a, n, gsmul_coe_nat a n\u27e9 = \u27e8n \u2022 b, n, gsmul_coe_nat b n\u27e9 :=\ngpowers_equiv_gpowers_apply h n\n\nattribute [to_additive gmultiples_equiv_gmultiples_apply] gpowers_equiv_gpowers_apply\n\nlemma order_eq_card_gpowers [decidable_eq G] :\n  order_of x = fintype.card (subgroup.gpowers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_gpowers x\u27e9)\n\nlemma add_order_eq_card_gmultiples [decidable_eq A] :\n  add_order_of a = fintype.card (add_subgroup.gmultiples a : set A) :=\n(fintype.card_fin (add_order_of a)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_gmultiples a\u27e9)\n\nattribute [to_additive add_order_eq_card_gmultiples] order_eq_card_gpowers\n\nopen quotient_group\n\n/- TODO: use cardinal theory, introduce `card : set G \u2192 \u2115`, or setup decidability for cosets -/\nlemma order_of_dvd_card_univ : order_of x \u2223 fintype.card G :=\nbegin\n  classical,\n  have ft_prod : fintype (quotient (gpowers x) \u00d7 (gpowers x)),\n    from fintype.of_equiv G group_equiv_quotient_times_subgroup,\n  have ft_s : fintype (gpowers x),\n    from @fintype.fintype_prod_right _ _ _ ft_prod _,\n  have ft_cosets : fintype (quotient (gpowers x)),\n    from @fintype.fintype_prod_left _ _ _ ft_prod \u27e8\u27e81, (gpowers x).one_mem\u27e9\u27e9,\n  have eq\u2081 : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,\n    from calc fintype.card G = @fintype.card _ ft_prod :\n        @fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup\n      ... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :\n        congr_arg (@fintype.card _) $ subsingleton.elim _ _\n      ... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :\n        @fintype.card_prod _ _ ft_cosets ft_s,\n  have eq\u2082 : order_of x = @fintype.card _ ft_s,\n    from calc order_of x = _ : order_eq_card_gpowers\n      ... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,\n  exact dvd.intro (@fintype.card (quotient (subgroup.gpowers x)) ft_cosets)\n          (by rw [eq\u2081, eq\u2082, mul_comm])\nend\n\nlemma add_order_of_dvd_card_univ : add_order_of a \u2223 fintype.card A :=\nbegin\n  rw \u2190 order_of_of_add_eq_add_order_of,\n  exact order_of_dvd_card_univ,\nend\n\nattribute [to_additive add_order_of_dvd_card_univ] order_of_dvd_card_univ\n\n@[simp] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=\nlet \u27e8m, hm\u27e9 := @order_of_dvd_card_univ _ x _ _ in\nby simp [hm, pow_mul, pow_order_of_eq_one]\n\n@[simp] lemma card_nsmul_eq_zero {a : A} : fintype.card A \u2022 a = 0 :=\nbegin\n  apply multiplicative.of_add.injective,\n  rw [of_add_nsmul, of_add_zero],\n  exact pow_card_eq_one,\nend\n\nattribute [to_additive card_nsmul_eq_zero] pow_card_eq_one\n\nvariable (a)\n\nlemma image_range_add_order_of [decidable_eq A] :\n  finset.image (\u03bb i, i \u2022 a) (finset.range (add_order_of a)) =\n  (add_subgroup.gmultiples a : set A).to_finset :=\nby {ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gmultiples_iff_mem_range_add_order_of] }\n\n/-- TODO: Generalise to `submonoid.powers`.-/\n@[to_additive image_range_add_order_of]\nlemma image_range_order_of [decidable_eq G] :\n  finset.image (\u03bb i, x ^ i) (finset.range (order_of x)) = (gpowers x : set G).to_finset :=\nby { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gpowers_iff_mem_range_order_of] }\n\nlemma gcd_nsmul_card_eq_zero_iff : n \u2022 a = 0 \u2194 (gcd n (fintype.card A)) \u2022 a = 0 :=\n\u27e8\u03bb h, gcd_nsmul_eq_zero _ h $ card_nsmul_eq_zero,\n  \u03bb h, let \u27e8m, hm\u27e9 := gcd_dvd_left n (fintype.card A) in\n    by rw [hm, mul_comm, mul_nsmul, h, nsmul_zero]\u27e9\n\n/-- TODO: Generalise to `finite_cancel_monoid`. -/\n@[to_additive gcd_nsmul_card_eq_zero_iff]\nlemma pow_gcd_card_eq_one_iff : x ^ n = 1 \u2194 x ^ (gcd n (fintype.card G)) = 1 :=\n\u27e8\u03bb h, pow_gcd_eq_one _ h $ pow_card_eq_one,\n  \u03bb h, let \u27e8m, hm\u27e9 := gcd_dvd_left n (fintype.card G) in\n    by rw [hm, pow_mul, h, one_pow]\u27e9\n\nend finite_group\n\nend fintype\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/order_of_element.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7422948594090171}}
{"text": "/-\nCopyright (c) 2015 Leonardo de Moura. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n-/\nimport data.list.comb data.list.perm\n\nnamespace list\nvariable {A : Type}\nvariable (R : A \u2192 A \u2192 Prop)\n\ninductive locally_sorted : list A \u2192 Prop :=\n| base0 : locally_sorted []\n| base  : \u2200 a, locally_sorted [a]\n| step  : \u2200 {a b l}, R a b \u2192 locally_sorted (b::l) \u2192 locally_sorted (a::b::l)\n\ninductive hd_rel (a : A) : list A \u2192 Prop :=\n| base : hd_rel a []\n| step : \u2200 {b} (l), R a b \u2192 hd_rel a (b::l)\n\ninductive sorted : list A \u2192 Prop :=\n| base : sorted []\n| step : \u2200 {a : A} {l : list A}, hd_rel R a l \u2192 sorted l \u2192 sorted (a::l)\n\nvariable {R}\n\nlemma hd_rel_inv : \u2200 {a b l}, hd_rel R a (b::l) \u2192 R a b :=\nbegin intros a b l h, cases h, assumption end\n\nlemma sorted_inv : \u2200 {a l}, sorted R (a::l) \u2192 hd_rel R a l \u2227 sorted R l :=\nbegin intros a l h, cases h, split, repeat assumption end\n\nlemma sorted.rect_on {P : list A \u2192 Type} : \u2200 {l}, sorted R l \u2192 P [] \u2192 (\u2200 a l, sorted R l \u2192 P l \u2192 hd_rel R a l \u2192 P (a::l)) \u2192 P l\n| []     s h\u2081 h\u2082 := h\u2081\n| (a::l) s h\u2081 h\u2082 :=\n  have hd_rel R a l, from and.left (sorted_inv s),\n  have sorted R l,   from and.right (sorted_inv s),\n  have P l,          from sorted.rect_on this h\u2081 h\u2082,\n  h\u2082 a l `sorted R l` `P l` `hd_rel R a l`\n\nlemma sorted_singleton (a : A) : sorted R [a] :=\nsorted.step !hd_rel.base !sorted.base\n\nlemma sorted_of_locally_sorted : \u2200 {l}, locally_sorted R l \u2192 sorted R l\n| []        h := !sorted.base\n| [a]       h := !sorted_singleton\n| (a::b::l) (locally_sorted.step h\u2081 h\u2082) :=\n  have sorted R (b::l), from sorted_of_locally_sorted h\u2082,\n  sorted.step (hd_rel.step _ h\u2081) this\n\nlemma locally_sorted_of_sorted : \u2200 {l}, sorted R l \u2192 locally_sorted R l\n| []        h := !locally_sorted.base0\n| [a]       h := !locally_sorted.base\n| (a::b::l) (sorted.step (hd_rel.step _ h\u2081) h\u2082) :=\n  have locally_sorted R (b::l), from locally_sorted_of_sorted h\u2082,\n  locally_sorted.step h\u2081 this\n\nlemma locally_sorted_eq_sorted : @locally_sorted = @sorted :=\nfunext (\u03bb A, funext (\u03bb R, funext (\u03bb l, propext (iff.intro sorted_of_locally_sorted locally_sorted_of_sorted))))\n\nvariable (R)\n\ninductive strongly_sorted : list A \u2192 Prop :=\n| base : strongly_sorted []\n| step : \u2200 {a l}, all l (R a) \u2192 strongly_sorted l \u2192 strongly_sorted (a::l)\n\nvariable {R}\n\nlemma sorted_of_strongly_sorted : \u2200 {l}, strongly_sorted R l \u2192 sorted R l\n| []        h := !sorted.base\n| [a]       h := !sorted_singleton\n| (a::b::l) (strongly_sorted.step h\u2081 h\u2082) :=\n  have hd_rel R a (b::l), from hd_rel.step _ (of_all_cons h\u2081),\n  have sorted R (b::l),   from sorted_of_strongly_sorted h\u2082,\n  sorted.step `hd_rel R a (b::l)` `sorted R (b::l)`\n\nlemma sorted_extends (trans : transitive R) : \u2200 {a l}, sorted R (a::l) \u2192 all l (R a)\n| a []     h := !all_nil\n| a (b::l) h :=\n  have hd_rel R a (b::l), from and.left (sorted_inv h),\n  have R a b,             from hd_rel_inv this,\n  have all l (R b),       from sorted_extends (and.right (sorted_inv h)),\n  all_of_forall (take x, suppose x \u2208 b::l,\n    or.elim (eq_or_mem_of_mem_cons this)\n      (suppose x = b, by subst x; assumption)\n      (suppose x \u2208 l,\n        have R b x, from of_mem_of_all this `all l (R b)`,\n        trans `R a b` `R b x`))\n\ntheorem strongly_sorted_of_sorted_of_transitive (trans : transitive R) : \u2200 {l}, sorted R l \u2192 strongly_sorted R l\n| []     h := !strongly_sorted.base\n| (a::l) h :=\n  have sorted R l,          from and.right (sorted_inv h),\n  have strongly_sorted R l, from strongly_sorted_of_sorted_of_transitive this,\n  have all l (R a),         from sorted_extends trans h,\n  strongly_sorted.step `all l (R a)` `strongly_sorted R l`\n\nopen perm\n\nlemma eq_of_sorted_of_perm (tr : transitive R) (anti : anti_symmetric R) : \u2200 {l\u2081 l\u2082 : list A}, l\u2081 ~ l\u2082 \u2192 sorted R l\u2081 \u2192 sorted R l\u2082 \u2192 l\u2081 = l\u2082\n| []       []       h\u2081 h\u2082 h\u2083 := rfl\n| (a\u2081::l\u2081) []       h\u2081 h\u2082 h\u2083 := absurd (perm.symm h\u2081) !not_perm_nil_cons\n| []       (a\u2082::l\u2082) h\u2081 h\u2082 h\u2083 := absurd h\u2081 !not_perm_nil_cons\n| (a::l\u2081)  l\u2082       h\u2081 h\u2082 h\u2083 :=\n  have aux : \u2200 {t}, l\u2082 = a::t \u2192 a::l\u2081 = l\u2082, from\n    take t, suppose l\u2082 = a::t,\n    have l\u2081 ~ t,      by rewrite [this at h\u2081]; apply perm_cons_inv h\u2081,\n    have sorted R l\u2081, from and.right (sorted_inv h\u2082),\n    have sorted R t,  by rewrite [`l\u2082 = a::t` at h\u2083]; exact and.right (sorted_inv h\u2083),\n    have l\u2081 = t,      from eq_of_sorted_of_perm `l\u2081 ~ t` `sorted R l\u2081` `sorted R t`,\n    show a :: l\u2081 = l\u2082,  by rewrite [`l\u2082 = a::t`, this],\n  have   a \u2208 l\u2082,                       from mem_perm h\u2081 !mem_cons,\n  obtain s t (e\u2081 : l\u2082 = s ++ (a::t)),  from mem_split this,\n  begin\n    cases s with b s,\n    { have l\u2082 = a::t, by exact e\u2081,\n      exact aux this },\n    { have e\u2081   : l\u2082 = b::(s++(a::t)), by exact e\u2081,\n      have b \u2208 l\u2082,                by rewrite e\u2081; apply mem_cons,\n      have hall\u2082 : all (s++(a::t)) (R b), begin rewrite [e\u2081 at h\u2083], apply sorted_extends tr h\u2083 end,\n      have a \u2208 s++(a::t),         from mem_append_right _ !mem_cons,\n      have R b a,                 from of_mem_of_all this hall\u2082,\n      have b \u2208 a::l\u2081,             from mem_perm (perm.symm h\u2081) `b \u2208 l\u2082`,\n      have hall\u2081 : all l\u2081 (R a),  from sorted_extends tr h\u2082,\n      apply or.elim (eq_or_mem_of_mem_cons `b \u2208 a::l\u2081`),\n        suppose b = a,  by rewrite this at e\u2081; exact aux e\u2081,\n        suppose b \u2208 l\u2081,\n          have R a b, from of_mem_of_all this hall\u2081,\n          have b = a, from anti `R b a` `R a b`,\n          by rewrite this at e\u2081; exact aux e\u2081 }\n  end\nend list\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/list/sorted.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7422948522840339}}
{"text": "variables A B C D E F P Q R: Prop\n\nopen classical\n\ntheorem exercise_1 (h1 : \u00ac A \u2192 false) (h2 : A \u2228 \u00ac A) : A :=\n  or.elim h2\n    (assume h3 : A, h3)\n    (assume h4 : \u00ac A,\n    have h5 : false, from h1 h4,\n    show A, from false.elim h5)\n\ntheorem exercise_2 (h1 : \u00ac A \u2228 \u00ac B) : \u00ac (A \u2227 B) :=\n  assume h2 : A \u2227 B,\n  have h3 : A, from and.left h2,\n  have h4 : B, from and.right h2,\n  show false, from or.elim h1\n    (assume h5 : \u00ac A, h5 h3)\n    (assume h6 : \u00ac B, h6 h4)\n\ntheorem exercise_3 (h1 : \u00ac (A \u2227 B)) : \u00ac A \u2228 \u00ac B :=\n  by_contradiction\n  (assume h2 : \u00ac (\u00ac A \u2228 \u00ac B),\n  have h4 : A, from\n    by_contradiction\n    (assume h6 : \u00ac A,\n    have h7 : \u00ac A \u2228 \u00ac B, from or.inl h6,\n    show false, from h2 h7),\n  have h5 : B, from\n    by_contradiction\n    (assume h6 : \u00ac B,\n    have h7 : \u00ac A \u2228 \u00ac B, from or.inr h6,\n    show false, from h2 h7),\n  have h3 : A \u2227 B, from and.intro h4 h5,\n  show false, from h1 h3)\n\ntheorem exercise_4 (h1 : \u00ac P \u2192 (Q \u2228 R)) (h2 : \u00ac Q) (h3 : \u00ac R) : P :=\n  by_contradiction\n  (assume h4 : \u00ac P,\n  have h5 : Q \u2228 R, from h1 h4,\n  show false, from or.elim h5\n    (assume h6 : Q, h2 h6)\n    (assume h6 : R, h3 h6))\n\ntheorem exercise_5 (h1 : A \u2192 B) : \u00ac A \u2228 B :=\n  by_contradiction\n  (assume h2 : \u00ac (\u00ac A \u2228 B),\n  have h4 : \u00ac A, from\n    assume h5 : A,\n    have h7 : B, from h1 h5,\n    have h6 : \u00ac A \u2228 B, from or.inr h7,\n    show false, from h2 h6,\n  have h3 : \u00ac A \u2228 B, from or.inl h4,\n  show false, from h2 h3)\n\ntheorem exercise_6 : A \u2192 ((A \u2227 B) \u2228 (A \u2227 \u00ac B)) :=\n  assume h1 : A,\n    by_contradiction\n    (assume h2 : \u00ac (((A \u2227 B) \u2228 (A \u2227 \u00ac B))),\n    have h5 : \u00ac B, from\n      assume h6 : B,\n      have h8 : A \u2227 B, from and.intro h1 h6,\n      have h7 : (A \u2227 B) \u2228 (A \u2227 \u00ac B), from or.inl h8,\n      show false, from h2 h7,\n    have h4 : A \u2227 \u00ac B, from and.intro h1 h5,\n    have h3 : (A \u2227 B) \u2228 (A \u2227 \u00ac B), from or.inr h4,\n    show false, from h2 h3)\n\n-- Exercise 7\n\nlemma fourth {A B C D E F : Prop} (h1 : A \u2228 B) (h2 : C \u2228 D) (h3 : E \u2228 F) :\n(((A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F))) \u2228 ((A \u2227 (D \u2227 E)) \u2228 (A \u2227 (D \u2227 F)))) \u2228\n(((B \u2227 (C \u2227 E)) \u2228 (B \u2227 (C \u2227 F))) \u2228 ((B \u2227 (D \u2227 E)) \u2228 (B \u2227 (D \u2227 F)))) :=\n-- I will now suppose very each case above, and include the other terms of conjunction\n    or.elim h1\n    (assume h4 : A,\n        or.elim h2\n        (assume h5 : C,\n            or.elim h3\n            (assume h6 : E,\n            -- I have now A \u2227 C \u2227 E, so I can have all the proposition, like bellow\n            or.inl (or.inl (or.inl (and.intro h4 (and.intro h5 h6)))))\n            (assume h6 : F,\n            or.inl (or.inl (or.inr (and.intro h4 (and.intro h5 h6))))))\n        (assume h5 : D,\n            or.elim h3\n            (assume h6 : E,\n            or.inl (or.inr (or.inl (and.intro h4 (and.intro h5 h6)))))\n            (assume h6 : F,\n            or.inl (or.inr (or.inr (and.intro h4 (and.intro h5 h6)))))))\n    (assume h4 : B,\n        or.elim h2\n        (assume h5 : C,\n            or.elim h3\n            (assume h6 : E,\n            or.inr (or.inl (or.inl (and.intro h4 (and.intro h5 h6)))))\n            (assume h6 : F,\n            or.inr (or.inl (or.inr (and.intro h4 (and.intro h5 h6))))))\n        (assume h5 : D,\n            or.elim h3\n            (assume h6 : E,\n            or.inr (or.inr (or.inl (and.intro h4 (and.intro h5 h6)))))\n            (assume h6 : F,\n            or.inr (or.inr (or.inr (and.intro h4 (and.intro h5 h6)))))))\n\nlemma third {A B C D E F : Prop} (h1 : (A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F))): (A \u2228 B) \u2227 (C \u2228 D) \u2227 (E \u2228 F) :=\n    or.elim h1\n    (assume h2 : A \u2227 (C \u2227 E),\n    have h3 : A \u2228 B, from or.inl (and.left h2),\n    have h4 : C \u2227 E, from and.right h2,\n    have h5 : C \u2228 D, from or.inl (and.left h4),\n    have h6 : E \u2228 F, from or.inl (and.right h4),\n    and.intro h3 (and.intro h5 h6))\n    (assume h2 : A \u2227 (C \u2227 F),\n    have h3 : A \u2228 B, from or.inl (and.left h2),\n    have h4 : C \u2227 F, from and.right h2,\n    have h5 : C \u2228 D, from or.inl (and.left h4),\n    have h6 : E \u2228 F, from or.inr (and.right h4),\n    and.intro h3 (and.intro h5 h6))\n\nlemma switch {A B : Prop} (h1 : A \u2228 B) : B \u2228 A :=\n    or.elim h1\n    (assume h2 : A, or.inr h2)\n    (assume h2 : B, or.inl h2)\n\nlemma second {A B C D E F : Prop}\n(h1 : ((A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F))) \u2228 ((A \u2227 (D \u2227 E)) \u2228 (A \u2227 (D \u2227 F)))): (A \u2228 B) \u2227 (C \u2228 D) \u2227 (E \u2228 F) :=\n    or.elim h1\n    (assume h2 : (A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F)),\n    third h2)\n    (assume h2 : (A \u2227 (D \u2227 E)) \u2228 (A \u2227 (D \u2227 F)),\n    -- Now I can use third lemma again, but later I will have to switch C and D\n    have h3 : (A \u2228 B) \u2227 (D \u2228 C) \u2227 (E \u2228 F), from third h2,\n    have h4 : A \u2228 B, from and.left h3,\n    have h5 : D \u2228 C, from and.left (and.right h3),\n    have h6 : C \u2228 D, from switch h5,\n    have h7 : E \u2228 F, from and.right (and.right h3),\n    and.intro h4 (and.intro h6 h7))\n\nlemma first {A B C D E F : Prop}\n(h1 : (((A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F))) \u2228 ((A \u2227 (D \u2227 E)) \u2228 (A \u2227 (D \u2227 F)))) \u2228\n(((B \u2227 (C \u2227 E)) \u2228 (B \u2227 (C \u2227 F))) \u2228 ((B \u2227 (D \u2227 E)) \u2228 (B \u2227 (D \u2227 F))))): (A \u2228 B) \u2227 (C \u2228 D) \u2227 (E \u2228 F) :=\n    or.elim h1\n    (assume h2 : ((A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F))) \u2228 ((A \u2227 (D \u2227 E)) \u2228 (A \u2227 (D \u2227 F))),\n    second h2)\n    (assume h2 : ((B \u2227 (C \u2227 E)) \u2228 (B \u2227 (C \u2227 F))) \u2228 ((B \u2227 (D \u2227 E)) \u2228 (B \u2227 (D \u2227 F))),\n    have h3 : (B \u2228 A) \u2227 (C \u2228 D) \u2227 (E \u2228 F), from second h2,\n    have h4 : B \u2228 A, from and.left h3,\n    have h5 : A \u2228 B, from switch h4,\n    have h6 : (C \u2228 D) \u2227 (E \u2228 F), from and.right h3,\n    and.intro h5 h6)\n\ntheorem exercise_7 : (A \u2228 B) \u2227 (C \u2228 D) \u2227 (E \u2228 F) \u2194\n(((A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F))) \u2228 ((A \u2227 (D \u2227 E)) \u2228 (A \u2227 (D \u2227 F)))) \u2228\n(((B \u2227 (C \u2227 E)) \u2228 (B \u2227 (C \u2227 F))) \u2228 ((B \u2227 (D \u2227 E)) \u2228 (B \u2227 (D \u2227 F)))) :=\n    iff.intro\n    (assume h1 : (A \u2228 B) \u2227 (C \u2228 D) \u2227 (E \u2228 F),\n    have h2 : A \u2228 B, from h1.left,\n    have h3 : C \u2228 D, from (h1.right).left,\n    have h4 : E \u2228 F, from (h1.right).right,\n    fourth h2 h3 h4)\n    (assume h1 : (((A \u2227 (C \u2227 E)) \u2228 (A \u2227 (C \u2227 F))) \u2228 ((A \u2227 (D \u2227 E)) \u2228 (A \u2227 (D \u2227 F)))) \u2228\n    (((B \u2227 (C \u2227 E)) \u2228 (B \u2227 (C \u2227 F))) \u2228 ((B \u2227 (D \u2227 E)) \u2228 (B \u2227 (D \u2227 F)))),\n    first h1)\n\n-- Exercise 8\n\n-- Prove \u00ac (A \u2227 B) \u2192 \u00ac A \u2228 \u00ac B by replacing the sorry's below\n-- by proofs.\n\nlemma step1 {A B : Prop} (h\u2081 : \u00ac (A \u2227 B)) (h\u2082 : A) : \u00ac A \u2228 \u00ac B :=\n    have \u00ac B, from \n        assume h\u2083 : B,\n        show false, from h\u2081 (and.intro h\u2082 h\u2083),\n    show \u00ac A \u2228 \u00ac B, from or.inr this\n\nlemma step2 {A B : Prop} (h\u2081 : \u00ac (A \u2227 B)) (h\u2082 : \u00ac (\u00ac A \u2228 \u00ac B)) : false :=\n    have \u00ac A, from\n        assume : A,\n        have \u00ac A \u2228 \u00ac B, from step1 h\u2081 \u2039A\u203a,\n        show false, from h\u2082 this,\n    show false, from h\u2082 (or.inl this)\n\ntheorem step3 (h : \u00ac (A \u2227 B)) : \u00ac A \u2228 \u00ac B :=\n    by_contradiction\n    (assume h' : \u00ac (\u00ac A \u2228 \u00ac B),\n    show false, from step2 h h')\n\n-- Exercise 9\n\nexample (h : \u00ac B \u2192 \u00ac A) : A \u2192 B :=\n  assume h1 : A,\n    by_contradiction\n    (assume h2 : \u00ac B,\n    show false, from (h h2) h1)\n\nexample (h : A \u2192 B) : \u00ac A \u2228 B :=\n  by_contradiction\n  (assume h1 : \u00ac (\u00ac A \u2228 B),\n  have h3 : \u00ac A, from\n    assume h4 : A,\n    have h6 : B, from h h4,\n    have h5 : \u00ac A \u2228 B, from or.inr h6,\n    show false, from h1 h5,\n  have h2 : \u00ac A \u2228 B, from or.inl h3,\n  show false, from h1 h2)\n", "meta": {"author": "lucasresck", "repo": "Discrete-Mathematics", "sha": "0a08081c5f393e5765259d3f1253c3a6dd043dac", "save_path": "github-repos/lean/lucasresck-Discrete-Mathematics", "path": "github-repos/lean/lucasresck-Discrete-Mathematics/Discrete-Mathematics-0a08081c5f393e5765259d3f1253c3a6dd043dac/Lists of exercises/List 3/capitulo-05-LucasDomingues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7422480847781977}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n-/\nimport data.real.sqrt\n\n/-!\n# The complex numbers\n\nThe complex numbers are modelled as \u211d^2 in the obvious way and it is shown that they form a field\nof characteristic zero. The result that the complex numbers are algebraically closed, see\n`field_theory.algebraic_closure`.\n-/\n\nopen_locale big_operators\nopen set function\n\n/-! ### Definition and basic arithmmetic -/\n\n/-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\nopen_locale complex_conjugate\n\nnoncomputable instance : decidable_eq \u2102 := classical.dec_eq _\n\n/-- The equivalence between the complex numbers and `\u211d \u00d7 \u211d`. -/\n@[simps apply]\ndef equiv_real_prod : \u2102 \u2243 (\u211d \u00d7 \u211d) :=\n{ to_fun := \u03bb z, \u27e8z.re, z.im\u27e9,\n  inv_fun := \u03bb p, \u27e8p.1, p.2\u27e9,\n  left_inv := \u03bb \u27e8x, y\u27e9, rfl,\n  right_inv := \u03bb \u27e8x, y\u27e9, rfl }\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8a, b\u27e9 := rfl\n\n@[ext]\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\ntheorem re_surjective : surjective re := \u03bb x, \u27e8\u27e8x, 0\u27e9, rfl\u27e9\ntheorem im_surjective : surjective im := \u03bb y, \u27e8\u27e80, y\u27e9, rfl\u27e9\n\n@[simp] theorem range_re : range re = univ := re_surjective.range_eq\n@[simp] theorem range_im : range im = univ := im_surjective.range_eq\n\ninstance : has_coe \u211d \u2102 := \u27e8\u03bb r, \u27e8r, 0\u27e9\u27e9\n\n@[simp, norm_cast] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\nlemma of_real_def (r : \u211d) : (r : \u2102) = \u27e8r, 0\u27e9 := rfl\n\n@[simp, norm_cast] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\ntheorem of_real_injective : function.injective (coe : \u211d \u2192 \u2102) :=\n\u03bb z w, congr_arg re\n\ninstance : can_lift \u2102 \u211d :=\n{ cond := \u03bb z, z.im = 0,\n  coe := coe,\n  prf := \u03bb z hz, \u27e8z.re, ext rfl hz.symm\u27e9 }\n\n/-- The product of a set on the real axis and a set on the imaginary axis of the complex plane,\ndenoted by `s \u00d7\u2102 t`. -/\ndef _root_.set.re_prod_im (s t : set \u211d) : set \u2102 := re \u207b\u00b9' s \u2229 im \u207b\u00b9' t\n\ninfix ` \u00d7\u2102 `:72 := set.re_prod_im\n\nlemma mem_re_prod_im {z : \u2102} {s t : set \u211d} : z \u2208 s \u00d7\u2102 t \u2194 z.re \u2208 s \u2227 z.im \u2208 t := iff.rfl\n\ninstance : has_zero \u2102 := \u27e8(0 : \u211d)\u27e9\ninstance : inhabited \u2102 := \u27e80\u27e9\n\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\ninstance : has_one \u2102 := \u27e8(1 : \u211d)\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\n@[simp] theorem of_real_eq_one {z : \u211d} : (z : \u2102) = 1 \u2194 z = 1 := of_real_inj\ntheorem of_real_ne_one {z : \u211d} : (z : \u2102) \u2260 1 \u2194 z \u2260 1 := not_congr of_real_eq_one\n\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n\n@[simp] lemma bit0_re (z : \u2102) : (bit0 z).re = bit0 z.re := rfl\n@[simp] lemma bit1_re (z : \u2102) : (bit1 z).re = bit1 z.re := rfl\n@[simp] lemma bit0_im (z : \u2102) : (bit0 z).im = bit0 z.im := eq.refl _\n@[simp] lemma bit1_im (z : \u2102) : (bit1 z).im = bit0 z.im := add_zero _\n\n@[simp, norm_cast] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s :=\next_iff.2 $ by simp\n\n@[simp, norm_cast] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r :=\next_iff.2 $ by simp [bit0]\n\n@[simp, norm_cast] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r :=\next_iff.2 $ by simp [bit1]\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n@[simp, norm_cast] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\ninstance : has_sub \u2102 := \u27e8\u03bb z w, \u27e8z.re - w.re, z.im - w.im\u27e9\u27e9\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp, norm_cast] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\nlemma of_real_mul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp\nlemma of_real_mul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp\nlemma of_real_mul' (r : \u211d) (z : \u2102) : (\u2191r * z) = \u27e8r * z.re, r * z.im\u27e9 :=\next (of_real_mul_re _ _) (of_real_mul_im _ _)\n\n/-! ### The imaginary unit, `I` -/\n\n/-- The imaginary unit. -/\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := rfl\n@[simp] lemma I_im : I.im = 1 := rfl\n\n@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp\nlemma I_mul (z : \u2102) : I * z = \u27e8-z.im, z.re\u27e9 :=\next_iff.2 $ by simp\n\nlemma I_ne_zero : (I : \u2102) \u2260 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\next_iff.2 $ by simp\n\nlemma mul_I_re (z : \u2102) : (z * I).re = -z.im := by simp\nlemma mul_I_im (z : \u2102) : (z * I).im = z.re := by simp\nlemma I_mul_re (z : \u2102) : (I * z).re = -z.im := by simp\nlemma I_mul_im (z : \u2102) : (I * z).im = z.re := by simp\n\n@[simp] lemma equiv_real_prod_symm_apply (p : \u211d \u00d7 \u211d) :\n  equiv_real_prod.symm p = p.1 + p.2 * I :=\nby { ext; simp [equiv_real_prod] }\n\n/-! ### Commutative ring instance and lemmas -/\n\n/- We use a nonstandard formula for the `\u2115` and `\u2124` actions to make sure there is no\ndiamond from the other actions they inherit through the `\u211d`-action on `\u2102` and action transitivity\ndefined in `data.complex.module.lean`. -/\n\ninstance : add_comm_group \u2102 :=\nby refine_struct\n  { zero := (0 : \u2102),\n    add := (+),\n    neg := has_neg.neg,\n    sub := has_sub.sub,\n    nsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9,\n    zsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9 };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\ninstance : add_group_with_one \u2102 :=\n{ nat_cast := \u03bb n, \u27e8n, 0\u27e9,\n  nat_cast_zero := by ext; simp [nat.cast],\n  nat_cast_succ := \u03bb _, by ext; simp [nat.cast],\n  int_cast := \u03bb n, \u27e8n, 0\u27e9,\n  int_cast_of_nat := \u03bb _, by ext; simp [\u03bb n, show @coe \u2115 \u2102 \u27e8_\u27e9 n = \u27e8n, 0\u27e9, from rfl],\n  int_cast_neg_succ_of_nat := \u03bb _, by ext; simp [\u03bb n, show @coe \u2115 \u2102 \u27e8_\u27e9 n = \u27e8n, 0\u27e9, from rfl],\n  one := 1,\n  .. complex.add_comm_group }\n\ninstance : comm_ring \u2102 :=\nby refine_struct\n  { zero := (0 : \u2102),\n    add := (+),\n    one := 1,\n    mul := (*),\n    npow := @npow_rec _ \u27e8(1 : \u2102)\u27e9 \u27e8(*)\u27e9,\n    .. complex.add_group_with_one };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\n/-- This shortcut instance ensures we do not find `ring` via the noncomputable `complex.field`\ninstance. -/\ninstance : ring \u2102 := by apply_instance\n\n/-- This shortcut instance ensures we do not find `comm_semiring` via the noncomputable\n`complex.field` instance. -/\ninstance : comm_semiring \u2102 := infer_instance\n\n/-- The \"real part\" map, considered as an additive group homomorphism. -/\ndef re_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := re,\n  map_zero' := zero_re,\n  map_add' := add_re }\n\n@[simp] lemma coe_re_add_group_hom : (re_add_group_hom : \u2102 \u2192 \u211d) = re := rfl\n\n/-- The \"imaginary part\" map, considered as an additive group homomorphism. -/\ndef im_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := im,\n  map_zero' := zero_im,\n  map_add' := add_im }\n\n@[simp] lemma coe_im_add_group_hom : (im_add_group_hom : \u2102 \u2192 \u211d) = im := rfl\n\n@[simp] lemma I_pow_bit0 (n : \u2115) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [pow_bit0', I_mul_I]\n\n@[simp] lemma I_pow_bit1 (n : \u2115) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [pow_bit1', I_mul_I]\n\n/-! ### Complex conjugation -/\n\n/-- This defines the complex conjugate as the `star` operation of the `star_ring \u2102`. It\nis recommended to use the ring endomorphism version `star_ring_end`, available under the\nnotation `conj` in the locale `complex_conjugate`. -/\ninstance : star_ring \u2102 :=\n{ star := \u03bb z, \u27e8z.re, -z.im\u27e9,\n  star_involutive := \u03bb x, by simp only [eta, neg_neg],\n  star_mul := \u03bb a b, by ext; simp [add_comm]; ring,\n  star_add := \u03bb a b, by ext; simp [add_comm] }\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := rfl\n\nlemma conj_of_real (r : \u211d) : conj (r : \u2102) = r := ext_iff.2 $ by simp [conj]\n\n@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp\n\nlemma conj_bit0 (z : \u2102) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]\nlemma conj_bit1 (z : \u2102) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0]\n\n@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp\n\nlemma eq_conj_iff_real {z : \u2102} : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n\u27e8\u03bb h, \u27e8z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)\u27e9,\n \u03bb \u27e8h, e\u27e9, by rw [e, conj_of_real]\u27e9\n\nlemma eq_conj_iff_re {z : \u2102} : conj z = z \u2194 (z.re : \u2102) = z :=\neq_conj_iff_real.trans \u27e8by rintro \u27e8r, rfl\u27e9; simp, \u03bb h, \u27e8_, h.symm\u27e9\u27e9\n\nlemma eq_conj_iff_im {z : \u2102} : conj z = z \u2194 z.im = 0 :=\n\u27e8\u03bb h, add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)),\n  \u03bb h, ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))\u27e9\n\n-- `simp_nf` complains about this being provable by `is_R_or_C.star_def` even\n-- though it's not imported by this file.\n@[simp, nolint simp_nf] lemma star_def : (has_star.star : \u2102 \u2192 \u2102) = conj := rfl\n\n/-! ### Norm squared -/\n\n/-- The norm squared function. -/\n@[pp_nodot] def norm_sq : \u2102 \u2192*\u2080 \u211d :=\n{ to_fun := \u03bb z, z.re * z.re + z.im * z.im,\n  map_zero' := by simp,\n  map_one' := by simp,\n  map_mul' := \u03bb z w, by { dsimp, ring } }\n\nlemma norm_sq_apply (z : \u2102) : norm_sq z = z.re * z.re + z.im * z.im := rfl\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mk (x y : \u211d) : norm_sq \u27e8x, y\u27e9 = x * x + y * y := rfl\n\nlemma norm_sq_add_mul_I (x y : \u211d) : norm_sq (x + y * I) = x ^ 2 + y ^ 2 :=\nby rw [\u2190 mk_eq_add_mul_I, norm_sq_mk, sq, sq]\n\nlemma norm_sq_eq_conj_mul_self {z : \u2102} : (norm_sq z : \u2102) = conj z * z :=\nby { ext; simp [norm_sq, mul_comm], }\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := norm_sq.map_zero\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := norm_sq.map_one\n@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\n@[simp] lemma range_norm_sq : range norm_sq = Ici 0 :=\nsubset.antisymm (range_subset_iff.2 norm_sq_nonneg) $ \u03bb x hx,\n  \u27e8real.sqrt x, by rw [norm_sq_of_real, real.mul_self_sqrt hx]\u27e9\n\nlemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\n\u27e8\u03bb h, ext\n  (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n  (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),\n \u03bb h, h.symm \u25b8 norm_sq_zero\u27e9\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\n(norm_sq_nonneg z).lt_iff_ne.trans $ not_congr (eq_comm.trans norm_sq_eq_zero)\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\nlemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nnorm_sq.map_mul z w\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nby dsimp [norm_sq]; ring\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\next_iff.2 $ by simp [two_mul]\n\n/-- The coercion `\u211d \u2192 \u2102` as a `ring_hom`. -/\ndef of_real : \u211d \u2192+* \u2102 := \u27e8coe, of_real_one, of_real_mul, of_real_zero, of_real_add\u27e9\n\n@[simp] lemma of_real_eq_coe (r : \u211d) : of_real r = r := rfl\n\n@[simp] lemma I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]\n\n@[simp] lemma sub_re (z w : \u2102) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : \u2102) : (z - w).im = z.im - w.im := rfl\n@[simp, norm_cast] lemma of_real_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s := ext_iff.2 $ by simp\n@[simp, norm_cast] lemma of_real_pow (r : \u211d) (n : \u2115) : ((r ^ n : \u211d) : \u2102) = r ^ n :=\nby induction n; simp [*, of_real_mul, pow_succ]\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\next_iff.2 $ by simp [two_mul, sub_eq_add_neg]\n\nlemma norm_sq_sub (z w : \u2102) : norm_sq (z - w) =\n  norm_sq z + norm_sq w - 2 * (z * conj w).re :=\nby { rw [sub_eq_add_neg, norm_sq_add],\n     simp only [ring_hom.map_neg, mul_neg, neg_re,\n                tactic.ring.add_neg_eq_sub, norm_sq_neg] }\n\n/-! ### Inversion -/\n\nnoncomputable instance : has_inv \u2102 := \u27e8\u03bb z, conj z * ((norm_sq z)\u207b\u00b9:\u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((norm_sq z)\u207b\u00b9:\u211d) := rfl\n@[simp] lemma inv_re (z : \u2102) : (z\u207b\u00b9).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : \u2102) : (z\u207b\u00b9).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\n@[simp, norm_cast] lemma of_real_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = r\u207b\u00b9 :=\next_iff.2 $ by simp\n\nprotected lemma inv_zero : (0\u207b\u00b9 : \u2102) = 0 :=\nby rw [\u2190 of_real_zero, \u2190 of_real_inv, inv_zero]\n\nprotected theorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nby rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 of_real_mul,\n  mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]\n\n/-! ### Field instance and lemmas -/\n\nnoncomputable instance : field \u2102 :=\n{ inv := has_inv.inv,\n  exists_pair_ne := \u27e80, 1, mt (congr_arg re) zero_ne_one\u27e9,\n  mul_inv_cancel := @complex.mul_inv_cancel,\n  inv_zero := complex.inv_zero,\n  ..complex.comm_ring }\n\n@[simp] lemma I_zpow_bit0 (n : \u2124) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [zpow_bit0', I_mul_I]\n\n@[simp] lemma I_zpow_bit1 (n : \u2124) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [zpow_bit1', I_mul_I]\n\nlemma div_re (z w : \u2102) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]\nlemma div_im (z w : \u2102) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]\n\nlemma conj_inv (x : \u2102) : conj (x\u207b\u00b9) = (conj x)\u207b\u00b9 := star_inv' _\n\n@[simp, norm_cast] lemma of_real_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\nof_real.map_div r s\n\n@[simp, norm_cast] lemma of_real_zpow (r : \u211d) (n : \u2124) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n :=\nof_real.map_zpow r n\n\n@[simp] lemma div_I (z : \u2102) : z / I = -(z * I) :=\n(div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc]\n\n@[simp] lemma inv_I : I\u207b\u00b9 = -I :=\nby simp [inv_eq_one_div]\n\n@[simp] lemma norm_sq_inv (z : \u2102) : norm_sq z\u207b\u00b9 = (norm_sq z)\u207b\u00b9 :=\nnorm_sq.map_inv z\n\n@[simp] lemma norm_sq_div (z w : \u2102) : norm_sq (z / w) = norm_sq z / norm_sq w :=\nnorm_sq.map_div z w\n\n/-! ### Cast lemmas -/\n\n@[simp, norm_cast] theorem of_real_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\nmap_nat_cast of_real n\n\n@[simp, norm_cast] lemma nat_cast_re (n : \u2115) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_nat_cast, of_real_re]\n\n@[simp, norm_cast] lemma nat_cast_im (n : \u2115) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_nat_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_int_cast (n : \u2124) : ((n : \u211d) : \u2102) = n :=\nof_real.map_int_cast n\n\n@[simp, norm_cast] lemma int_cast_re (n : \u2124) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_int_cast, of_real_re]\n\n@[simp, norm_cast] lemma int_cast_im (n : \u2124) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_int_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_rat_cast (n : \u211a) : ((n : \u211d) : \u2102) = n := map_rat_cast of_real n\n\n@[simp, norm_cast] lemma rat_cast_re (q : \u211a) : (q : \u2102).re = q :=\nby rw [\u2190 of_real_rat_cast, of_real_re]\n\n@[simp, norm_cast] lemma rat_cast_im (q : \u211a) : (q : \u2102).im = 0 :=\nby rw [\u2190 of_real_rat_cast, of_real_im]\n\n/-! ### Characteristic zero -/\n\ninstance char_zero_complex : char_zero \u2102 :=\nchar_zero_of_inj_zero $ \u03bb n h,\nby rwa [\u2190 of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h\n\n/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 :=\nby simp only [add_conj, of_real_mul, of_real_one, of_real_bit0,\n     mul_div_cancel_left (z.re:\u2102) two_ne_zero']\n\n/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/\ntheorem im_eq_sub_conj (z : \u2102) : (z.im : \u2102) = (z - conj(z))/(2 * I) :=\nby simp only [sub_conj, of_real_mul, of_real_one, of_real_bit0, mul_right_comm,\n     mul_div_cancel_left _ (mul_ne_zero two_ne_zero' I_ne_zero : 2 * I \u2260 0)]\n\n/-! ### Absolute value -/\n\n/-- The complex absolute value function, defined as the square root of the norm squared. -/\n@[pp_nodot] noncomputable def abs (z : \u2102) : \u211d := (norm_sq z).sqrt\n\nlocal notation `abs'` := has_abs.abs\n\n@[simp, norm_cast] lemma abs_of_real (r : \u211d) : abs r = |r| :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\nlemma abs_of_nat (n : \u2115) : complex.abs n = n :=\ncalc complex.abs n = complex.abs (n:\u211d) : by rw [of_real_nat_cast]\n  ... = _ : abs_of_nonneg (nat.cast_nonneg n)\n\nlemma mul_self_abs (z : \u2102) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\nlemma sq_abs (z : \u2102) : abs z ^ 2 = norm_sq z :=\nreal.sq_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma sq_abs_sub_sq_re (z : \u2102) : abs z ^ 2 - z.re ^ 2 = z.im ^ 2 :=\nby rw [sq_abs, norm_sq_apply, \u2190 sq, \u2190 sq, add_sub_cancel']\n\n@[simp] lemma sq_abs_sub_sq_im (z : \u2102) : abs z ^ 2 - z.im ^ 2 = z.re ^ 2 :=\nby rw [\u2190 sq_abs_sub_sq_re, sub_sub_cancel]\n\n@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]\n@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]\n@[simp] lemma abs_I : abs I = 1 := by simp [abs]\n\n@[simp] lemma abs_two : abs 2 = 2 :=\ncalc abs 2 = abs (2 : \u211d) : by rw [of_real_bit0, of_real_one]\n... = (2 : \u211d) : abs_of_nonneg (by norm_num)\n\nlemma abs_nonneg (z : \u2102) : 0 \u2264 abs z :=\nreal.sqrt_nonneg _\n\n@[simp] lemma range_abs : range abs = Ici 0 :=\nsubset.antisymm (range_subset_iff.2 abs_nonneg) $ \u03bb x hx, \u27e8x, abs_of_nonneg hx\u27e9\n\n@[simp] lemma abs_eq_zero {z : \u2102} : abs z = 0 \u2194 z = 0 :=\n(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero\n\nlemma abs_ne_zero {z : \u2102} : abs z \u2260 0 \u2194 z \u2260 0 :=\nnot_congr abs_eq_zero\n\n@[simp] lemma abs_conj (z : \u2102) : abs (conj z) = abs z :=\nby simp [abs]\n\n@[simp] lemma abs_mul (z w : \u2102) : abs (z * w) = abs z * abs w :=\nby rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl\n\n/-- `complex.abs` as a `monoid_with_zero_hom`. -/\n@[simps] noncomputable def abs_hom : \u2102 \u2192*\u2080 \u211d :=\n{ to_fun := abs,\n  map_zero' := abs_zero,\n  map_one' := abs_one,\n  map_mul' := abs_mul }\n\n@[simp] lemma abs_prod {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 \u2102) :\n  abs (s.prod f) = s.prod (\u03bb i, abs (f i)) :=\nmap_prod abs_hom _ _\n\n@[simp] lemma abs_pow (z : \u2102) (n : \u2115) : abs (z ^ n) = abs z ^ n :=\nmap_pow abs_hom z n\n\n@[simp] lemma abs_zpow (z : \u2102) (n : \u2124) : abs (z ^ n) = abs z ^ n :=\nabs_hom.map_zpow z n\n\nlemma abs_re_le_abs (z : \u2102) : |z.re| \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply re_sq_le_norm_sq\n\nlemma abs_im_le_abs (z : \u2102) : |z.im| \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply im_sq_le_norm_sq\n\nlemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : \u2102) : z.im \u2264 abs z :=\n(abs_le.1 (abs_im_le_abs _)).2\n\n@[simp] lemma abs_re_lt_abs {z : \u2102} : |z.re| < abs z \u2194 z.im \u2260 0 :=\nby rw [abs, real.lt_sqrt (_root_.abs_nonneg _), norm_sq_apply, _root_.sq_abs, \u2190 sq,\n  lt_add_iff_pos_right, mul_self_pos]\n\n@[simp] lemma abs_im_lt_abs {z : \u2102} : |z.im| < abs z \u2194 z.re \u2260 0 :=\nby simpa using @abs_re_lt_abs (z * I)\n\n/--\nThe **triangle inequality** for complex numbers.\n-/\nlemma abs_add (z w : \u2102) : abs (z + w) \u2264 abs z + abs w :=\n(mul_self_le_mul_self_iff (abs_nonneg _)\n  (add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $\nbegin\n  rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,\n      add_right_comm, norm_sq_add, add_le_add_iff_left,\n      mul_assoc, mul_le_mul_left (@zero_lt_two \u211d _ _)],\n  simpa [-mul_re] using re_le_abs (z * conj w)\nend\n\ninstance : is_absolute_value abs :=\n{ abv_nonneg  := abs_nonneg,\n  abv_eq_zero := \u03bb _, abs_eq_zero,\n  abv_add     := abs_add,\n  abv_mul     := abs_mul }\nopen is_absolute_value\n\n@[simp] lemma abs_abs (z : \u2102) : |(abs z)| = abs z :=\n_root_.abs_of_nonneg (abs_nonneg _)\n\n@[simp] lemma abs_pos {z : \u2102} : 0 < abs z \u2194 z \u2260 0 := abv_pos abs\n@[simp] lemma abs_neg : \u2200 z, abs (-z) = abs z := abv_neg abs\nlemma abs_sub_comm : \u2200 z w, abs (z - w) = abs (w - z) := abv_sub abs\nlemma abs_sub_le : \u2200 a b c, abs (a - c) \u2264 abs (a - b) + abs (b - c) := abv_sub_le abs\n@[simp] theorem abs_inv : \u2200 z, abs z\u207b\u00b9 = (abs z)\u207b\u00b9 := abv_inv abs\n@[simp] theorem abs_div : \u2200 z w, abs (z / w) = abs z / abs w := abv_div abs\n\nlemma abs_abs_sub_le_abs_sub : \u2200 z w, |abs z - abs w| \u2264 abs (z - w) :=\nabs_abv_sub_le_abv_sub abs\n\nlemma abs_le_abs_re_add_abs_im (z : \u2102) : abs z \u2264 |z.re| + |z.im| :=\nby simpa [re_add_im] using abs_add z.re (z.im * I)\n\nlemma abs_le_sqrt_two_mul_max (z : \u2102) : abs z \u2264 real.sqrt 2 * max (|z.re|) (|z.im|) :=\nbegin\n  cases z with x y,\n  simp only [abs, norm_sq_mk, \u2190 sq],\n  wlog hle : |x| \u2264 |y| := le_total (|x|) (|y|) using [x y, y x] tactic.skip,\n  { calc real.sqrt (x ^ 2 + y ^ 2) \u2264 real.sqrt (y ^ 2 + y ^ 2) :\n      real.sqrt_le_sqrt (add_le_add_right (sq_le_sq.2 hle) _)\n    ... = real.sqrt 2 * max (|x|) (|y|) :\n      by rw [max_eq_right hle, \u2190 two_mul, real.sqrt_mul two_pos.le, real.sqrt_sq_eq_abs] },\n  { rwa [add_comm, max_comm] }\nend\n\nlemma abs_re_div_abs_le_one (z : \u2102) : |z.re / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }\n\nlemma abs_im_div_abs_le_one (z : \u2102) : |z.im / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }\n\n@[simp, norm_cast] lemma abs_cast_nat (n : \u2115) : abs (n : \u2102) = n :=\nby rw [\u2190 of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]\n\n@[simp, norm_cast] lemma int_cast_abs (n : \u2124) : \u2191|n| = abs n :=\nby rw [\u2190 of_real_int_cast, abs_of_real, int.cast_abs]\n\nlemma norm_sq_eq_abs (x : \u2102) : norm_sq x = abs x ^ 2 :=\nby rw [abs, sq, real.mul_self_sqrt (norm_sq_nonneg _)]\n\n/--\nWe put a partial order on \u2102 so that `z \u2264 w` exactly if `w - z` is real and nonnegative.\nComplex numbers with different imaginary parts are incomparable.\n-/\nprotected def partial_order : partial_order \u2102 :=\n{ le := \u03bb z w, z.re \u2264 w.re \u2227 z.im = w.im,\n  lt := \u03bb z w, z.re < w.re \u2227 z.im = w.im,\n  lt_iff_le_not_le := \u03bb z w, by { dsimp, rw lt_iff_le_not_le, tauto },\n  le_refl := \u03bb x, \u27e8le_rfl, rfl\u27e9,\n  le_trans := \u03bb x y z h\u2081 h\u2082, \u27e8h\u2081.1.trans h\u2082.1, h\u2081.2.trans h\u2082.2\u27e9,\n  le_antisymm := \u03bb z w h\u2081 h\u2082, ext (h\u2081.1.antisymm h\u2082.1) h\u2081.2 }\n\nsection complex_order\n\nlocalized \"attribute [instance] complex.partial_order\" in complex_order\n\nlemma le_def {z w : \u2102} : z \u2264 w \u2194 z.re \u2264 w.re \u2227 z.im = w.im := iff.rfl\nlemma lt_def {z w : \u2102} : z < w \u2194 z.re < w.re \u2227 z.im = w.im := iff.rfl\n\n@[simp, norm_cast] lemma real_le_real {x y : \u211d} : (x : \u2102) \u2264 (y : \u2102) \u2194 x \u2264 y := by simp [le_def]\n\n@[simp, norm_cast] lemma real_lt_real {x y : \u211d} : (x : \u2102) < (y : \u2102) \u2194 x < y := by simp [lt_def]\n\n@[simp, norm_cast] lemma zero_le_real {x : \u211d} : (0 : \u2102) \u2264 (x : \u2102) \u2194 0 \u2264 x := real_le_real\n@[simp, norm_cast] lemma zero_lt_real {x : \u211d} : (0 : \u2102) < (x : \u2102) \u2194 0 < x := real_lt_real\n\nlemma not_le_iff {z w : \u2102} : \u00ac(z \u2264 w) \u2194 w.re < z.re \u2228 z.im \u2260 w.im :=\nby rw [le_def, not_and_distrib, not_le]\n\nlemma not_lt_iff {z w : \u2102} : \u00ac(z < w) \u2194 w.re \u2264 z.re \u2228 z.im \u2260 w.im :=\nby rw [lt_def, not_and_distrib, not_lt]\n\nlemma not_le_zero_iff {z : \u2102} : \u00acz \u2264 0 \u2194 0 < z.re \u2228 z.im \u2260 0 := not_le_iff\nlemma not_lt_zero_iff {z : \u2102} : \u00acz < 0 \u2194 0 \u2264 z.re \u2228 z.im \u2260 0 := not_lt_iff\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is an ordered ring.\n-/\nprotected def ordered_comm_ring : ordered_comm_ring \u2102 :=\n{ zero_le_one := \u27e8zero_le_one, rfl\u27e9,\n  add_le_add_left := \u03bb w z h y, \u27e8add_le_add_left h.1 _, congr_arg2 (+) rfl h.2\u27e9,\n  mul_pos := \u03bb z w hz hw,\n    by simp [lt_def, mul_re, mul_im, \u2190 hz.2, \u2190 hw.2, mul_pos hz.1 hw.1],\n  .. complex.partial_order,\n  .. complex.comm_ring }\n\nlocalized \"attribute [instance] complex.ordered_comm_ring\" in complex_order\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a star ordered ring.\n(That is, a star ring in which the nonnegative elements are those of the form `star z * z`.)\n-/\nprotected def star_ordered_ring : star_ordered_ring \u2102 :=\n{ nonneg_iff := \u03bb r, by\n  { refine \u27e8\u03bb hr, \u27e8real.sqrt r.re, _\u27e9, \u03bb h, _\u27e9,\n    { have h\u2081 : 0 \u2264 r.re := by { rw [le_def] at hr, exact hr.1 },\n      have h\u2082 : r.im = 0 := by { rw [le_def] at hr, exact hr.2.symm },\n      ext,\n      { simp only [of_real_im, star_def, of_real_re, sub_zero, conj_re, mul_re, mul_zero,\n                   \u2190real.sqrt_mul h\u2081 r.re, real.sqrt_mul_self h\u2081] },\n      { simp only [h\u2082, add_zero, of_real_im, star_def, zero_mul, conj_im,\n                   mul_im, mul_zero, neg_zero] } },\n    { obtain \u27e8s, rfl\u27e9 := h,\n      simp only [\u2190norm_sq_eq_conj_mul_self, norm_sq_nonneg, zero_le_real, star_def] } },\n  ..complex.ordered_comm_ring }\n\nlocalized \"attribute [instance] complex.star_ordered_ring\" in complex_order\n\nend complex_order\n\n/-! ### Cauchy sequences -/\n\ntheorem is_cau_seq_re (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).re) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n\ntheorem is_cau_seq_im (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).im) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n\n/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_re (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_re f\u27e9\n\n/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_im (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_im f\u27e9\n\nlemma is_cau_seq_abs {f : \u2115 \u2192 \u2102} (hf : is_cau_seq abs f) :\n  is_cau_seq abs' (abs \u2218 f) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := hf \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9\n\n/-- The limit of a Cauchy sequence of complex numbers. -/\nnoncomputable def lim_aux (f : cau_seq \u2102 abs) : \u2102 :=\n\u27e8cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)\u27e9\n\ntheorem equiv_lim_aux (f : cau_seq \u2102 abs) : f \u2248 cau_seq.const abs (lim_aux f) :=\n\u03bb \u03b5 \u03b50, (exists_forall_ge_and\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_re f\u27e9 _ (half_pos \u03b50))\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_im f\u27e9 _ (half_pos \u03b50))).imp $\n\u03bb i H j ij, begin\n  cases H _ ij with H\u2081 H\u2082,\n  apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),\n  dsimp [lim_aux] at *,\n  have := add_lt_add H\u2081 H\u2082,\n  rwa add_halves at this,\nend\n\ninstance : cau_seq.is_complete \u2102 abs :=\n\u27e8\u03bb f, \u27e8lim_aux f, equiv_lim_aux f\u27e9\u27e9\n\nopen cau_seq\n\nlemma lim_eq_lim_im_add_lim_re (f : cau_seq \u2102 abs) : lim f =\n  \u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I :=\nlim_eq_of_equiv_const $\ncalc f \u2248 _ : equiv_lim_aux f\n... = cau_seq.const abs (\u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I) :\n  cau_seq.ext (\u03bb _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))\n\nlemma lim_re (f : cau_seq \u2102 abs) : lim (cau_seq_re f) = (lim f).re :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma lim_im (f : cau_seq \u2102 abs) : lim (cau_seq_im f) = (lim f).im :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma is_cau_seq_conj (f : cau_seq \u2102 abs) : is_cau_seq abs (\u03bb n, conj (f n)) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := f.2 \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, by rw [\u2190 ring_hom.map_sub, abs_conj]; exact hi j hj\u27e9\n\n/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/\nnoncomputable def cau_seq_conj (f : cau_seq \u2102 abs) : cau_seq \u2102 abs :=\n\u27e8_, is_cau_seq_conj f\u27e9\n\nlemma lim_conj (f : cau_seq \u2102 abs) : lim (cau_seq_conj f) = conj (lim f) :=\ncomplex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])\n  (by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)\n\n/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_abs (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_abs f.2\u27e9\n\nlemma lim_abs (f : cau_seq \u2102 abs) : lim (cau_seq_abs f) = abs (lim f) :=\nlim_eq_of_equiv_const (\u03bb \u03b5 \u03b50,\nlet \u27e8i, hi\u27e9 := equiv_lim f \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9)\n\nvariables {\u03b1 : Type*} (s : finset \u03b1)\n\n@[simp, norm_cast] lemma of_real_prod (f : \u03b1 \u2192 \u211d) :\n  ((\u220f i in s, f i : \u211d) : \u2102) = \u220f i in s, (f i : \u2102) :=\nring_hom.map_prod of_real _ _\n\n@[simp, norm_cast] lemma of_real_sum (f : \u03b1 \u2192 \u211d) :\n  ((\u2211 i in s, f i : \u211d) : \u2102) = \u2211 i in s, (f i : \u2102) :=\nring_hom.map_sum of_real _ _\n\n@[simp] lemma re_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).re = \u2211 i in s, (f i).re :=\nre_add_group_hom.map_sum f s\n\n@[simp] lemma im_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).im = \u2211 i in s, (f i).im :=\nim_add_group_hom.map_sum f s\n\nend complex\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.742226455949581}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module algebraic_geometry.prime_spectrum.is_open_comap_C\n! leanprover-community/mathlib commit 052f6013363326d50cb99c6939814a4b8eb7b301\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.AlgebraicGeometry.PrimeSpectrum.Basic\nimport Mathbin.RingTheory.Polynomial.Basic\n\n/-!\nThe morphism `Spec R[x] --> Spec R` induced by the natural inclusion `R --> R[x]` is an open map.\n\nThe main result is the first part of the statement of Lemma 00FB in the Stacks Project.\n\nhttps://stacks.math.columbia.edu/tag/00FB\n-/\n\n\nopen Ideal Polynomial PrimeSpectrum Set\n\nopen Polynomial\n\nnamespace AlgebraicGeometry\n\nnamespace Polynomial\n\nvariable {R : Type _} [CommRing R] {f : R[X]}\n\n/-- Given a polynomial `f \u2208 R[x]`, `image_of_Df` is the subset of `Spec R` where at least one\nof the coefficients of `f` does not vanish.  Lemma `image_of_Df_eq_comap_C_compl_zero_locus`\nproves that `image_of_Df` is the image of `(zero_locus {f})\u1d9c` under the morphism\n`comap C : Spec R[x] \u2192 Spec R`. -/\ndef imageOfDf (f) : Set (PrimeSpectrum R) :=\n  { p : PrimeSpectrum R | \u2203 i : \u2115, coeff f i \u2209 p.asIdeal }\n#align algebraic_geometry.polynomial.image_of_Df AlgebraicGeometry.Polynomial.imageOfDf\n\ntheorem isOpen_imageOfDf : IsOpen (imageOfDf f) :=\n  by\n  rw [image_of_Df, set_of_exists fun i (x : PrimeSpectrum R) => coeff f i \u2209 x.asIdeal]\n  exact isOpen_union\u1d62 fun i => is_open_basic_open\n#align algebraic_geometry.polynomial.is_open_image_of_Df AlgebraicGeometry.Polynomial.isOpen_imageOfDf\n\n/-- If a point of `Spec R[x]` is not contained in the vanishing set of `f`, then its image in\n`Spec R` is contained in the open set where at least one of the coefficients of `f` is non-zero.\nThis lemma is a reformulation of `exists_C_coeff_not_mem`. -/\ntheorem comap_c_mem_imageOfDf {I : PrimeSpectrum R[X]}\n    (H : I \u2208 (zeroLocus {f} : Set (PrimeSpectrum R[X]))\u1d9c) :\n    PrimeSpectrum.comap (Polynomial.C : R \u2192+* R[X]) I \u2208 imageOfDf f :=\n  exists_C_coeff_not_mem (mem_compl_zeroLocus_iff_not_mem.mp H)\n#align algebraic_geometry.polynomial.comap_C_mem_image_of_Df AlgebraicGeometry.Polynomial.comap_c_mem_imageOfDf\n\n/-- The open set `image_of_Df f` coincides with the image of `basic_open f` under the\nmorphism `C\u207a : Spec R[x] \u2192 Spec R`. -/\ntheorem imageOfDf_eq_comap_c_compl_zeroLocus :\n    imageOfDf f = PrimeSpectrum.comap (C : R \u2192+* R[X]) '' zeroLocus {f}\u1d9c :=\n  by\n  ext x\n  refine' \u27e8fun hx => \u27e8\u27e8map C x.as_ideal, is_prime_map_C_of_is_prime x.is_prime\u27e9, \u27e8_, _\u27e9\u27e9, _\u27e9\n  \u00b7 rw [mem_compl_iff, mem_zero_locus, singleton_subset_iff]\n    cases' hx with i hi\n    exact fun a => hi (mem_map_C_iff.mp a i)\n  \u00b7 ext x\n    refine' \u27e8fun h => _, fun h => subset_span (mem_image_of_mem C.1 h)\u27e9\n    rw [\u2190 @coeff_C_zero R x _]\n    exact mem_map_C_iff.mp h 0\n  \u00b7 rintro \u27e8xli, complement, rfl\u27e9\n    exact comap_C_mem_image_of_Df complement\n#align algebraic_geometry.polynomial.image_of_Df_eq_comap_C_compl_zero_locus AlgebraicGeometry.Polynomial.imageOfDf_eq_comap_c_compl_zeroLocus\n\n/-- The morphism `C\u207a : Spec R[x] \u2192 Spec R` is open.\nStacks Project \"Lemma 00FB\", first part.\n\nhttps://stacks.math.columbia.edu/tag/00FB\n-/\ntheorem isOpenMap_comap_c : IsOpenMap (PrimeSpectrum.comap (C : R \u2192+* R[X])) :=\n  by\n  rintro U \u27e8s, z\u27e9\n  rw [\u2190 compl_compl U, \u2190 z, \u2190 Union_of_singleton_coe s, zero_locus_Union, compl_Inter, image_Union]\n  simp_rw [\u2190 image_of_Df_eq_comap_C_compl_zero_locus]\n  exact isOpen_union\u1d62 fun f => is_open_image_of_Df\n#align algebraic_geometry.polynomial.is_open_map_comap_C AlgebraicGeometry.Polynomial.isOpenMap_comap_c\n\nend Polynomial\n\nend AlgebraicGeometry\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/AlgebraicGeometry/PrimeSpectrum/IsOpenComapC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7421937675669373}}
{"text": "-- begin header\nimport tactic.ring\n\nnamespace M40001\n-- end header\n\n/- Section\nSets and Logic\n-/\n\n/- Sub-section\n1.3 Relations\n-/\n\n/- Sub-section \n1.3.1 The Law of the Excluded Middle\n-/\n\n/-\nThe Law of the Excluded Middle states that for any proposition $P$, either $P$, or its negation $\u00ac P$ is true.\n-/\n\n/- Theorem\nIf $P$ is a proposition, then $ \u00ac (\u00ac P) \u21d4 P$.\n-/\ntheorem not_not_P_is_P\n    (P : Prop) : \u00ac (\u00ac P) \u2194 P :=\nbegin\n    -- We need to show that $\u00ac (\u00ac P)$ is true 'if and only if' $P$ is true. So we consider both directions of the implication.\n    split,\n    -- Let's first consider the forward implication, i.e. $\u00ac (\u00ac P)$ is true implies that $P$ is also true.\n    intro hp,\n    -- We will prove this by contradiction so given $\u00ac (\u00ac P)$ is true let's make a dubious assumption that $\u00ac P$ is true.\n    apply classical.by_contradiction,\n    intro hnp,\n    -- But $\u00ac P$ is true implies that $\u00ac (\u00ac P)$ is false which is a contradiction to our premis that $\u00ac (\u00ac P)$ is true. Thus, $\u00ac P$ must be false which by the Law of the excluded middle implies $P$ is true, resulting in the first part of the proof!\n    contradiction,\n    -- Now we need to proof that the backwards implication is also correct, i.e. $P$ is true implies $\u00ac (\u00ac P)$ is also true.\n    -- To show that $\u00ac (\u00ac P)$ is true when $P$ is true, we can simply show that $P$ is true implies $\u00ac P$ is false.\n    intros hp hnp,\n    -- But this is true by definition, so we have nothing left to prove!\n    contradiction,\nend\n\n/-\nRemark. Note that for many simple propositions alike the one above, LEAN is able to use automation to complete our proof. Indeed, by using the tactic $\\tt{finish}$, the above proof becomes a one-liner!\n-/\n\n/- Theorem\nIf $P$ is a proposition, then $ \u00ac (\u00ac P) \u21d4 P$. (This time proven using $\\tt{finish}$)\n-/\ntheorem not_not_P_is_P_tauto\n    (P : Prop) : \u00ac (\u00ac P) \u2194 P :=\nbegin\n    -- As we can see, $\\tt{finish}$ finished the proof!\n    finish\nend\n\n/- Sub-section\n1.3.2 De Morgan's Laws\n-/\n\n/- Theorem\n(1) Let $P$ and $Q$ be propositions, then $\u00ac (P \u2228 Q) \u21d4 (\u00ac P) \u2227 (\u00ac Q)$\n-/\ntheorem demorgan_a\n    (P Q : Prop) : \u00ac (P \u2228 Q) \u2194 (\u00ac P) \u2227 (\u00ac Q) :=\nbegin\n    -- Again we have an 'if and only if' statement so we need to consider both directions of the argument.\n    split,\n    -- We first show that $\u00ac (P \u2228 Q) \u21d2 \u00ac P \u2227 \u00ac Q$ through contradiction. Suppose $\u00ac (P \u2228 Q)$ is true, and we make a dubious assumption that $P$ is true.\n    intro h,\n    split,\n    intro hp,\n    -- But then $\u00ac (P \u2228 Q)$ is false! A contradiction! Therefore $P$ must be false.\n    apply h,\n    left, exact hp,\n    -- Similarly, supposing $Q$ is true also results in a contradiction! Therefore $Q$ is also false. \n    intro hq,\n    apply h,\n    right, exact hq,\n    -- With that, we now focus our attention on the backwards implication, i.e. $(\u00ac P) \u2227 (\u00ac Q) \u21d2 \u00ac (P \u2228 Q)$.\n    -- Again, let's approach this by contradiction. Given $\u00ac P \u2227 \u00ac Q$ suppose we have $P$ or $Q$.\n    intros h hpq,\n    -- But $P$ can't be true, as we have $\u00ac P$,\n    cases h with hnp hnq,\n    cases hpq with hp hq,\n    contradiction, \n    -- Therefore, $Q$ must be true.\n    -- But $Q$ also can't be true as we have $\u00ac Q$! Contradiction! Therefore, given $(\u00ac P) \u2227 (\u00ac Q)$, $(P \u2228 Q)$ must not be true, i.e. $\u00ac (P \u2228 Q)$ is true, which is exactly what we need!\n    contradiction,\nend\n\n/- Theorem\n(2) Let $P$ and $Q$ be propositions, then $\u00ac (P \u2227 Q) \u21d4 (\u00ac P) \u2228 (\u00ac Q)$\n-/\ntheorem demorgan_b\n    (P Q : Prop) : \u00ac (P \u2227 Q) \u2194 (\u00ac P) \u2228 (\u00ac Q) :=\nbegin\n    -- Once again, we have an 'if and only' if statement, therefore, we need to consider both directions. \n    split,\n    -- We first show that $\u00ac (P \u2227 Q) \u21d2 \u00ac P \u2228 \u00ac Q$. Suppose $\u00ac (P \u2227 Q)$.\n    intro h,\n    -- By the law of the excluded middle, we have either $P$ or $\u00ac P$.\n    cases (classical.em P) with hp hnp,\n    -- Suppose first that we have $P$. Then, we must have $\u00ac Q$ as having $Q$ implies $P \u2227 Q$ which contradicts with $\u00ac (P \u2227 Q)$,\n    have hnq : \u00ac Q,\n        intro hq,\n        have hpq : P \u2227 Q,\n            split, exact hp, exact hq,\n        contradiction,\n    -- hence, we have $\u00ac P \u2228 \u00ac Q$.\n    right, exact hnq,\n    -- Now let's suppose $\u00ac P$. But as $\u00ac P$ implies $\u00ac P \u2228 \u00ac Q$, we have nothing left to prove.\n    left, exact hnp,\n    -- With the forward implication dealt with, let's consider the reverse, i.e. $\u00ac P \u2228 \u00ac Q \u21d2 \u00ac (P \u2227 Q)$.\n    -- Given $\u00ac P \u2228 \u00ac Q$ let's suppose that $P \u2227 Q$.\n    intros h hpq,\n    -- But this is a contradiction as $P \u2227 Q$ implies that neither $P$ nor $Q$ is false!\n    cases h with hnp hnq,\n        cases hpq with hp hq,\n        contradiction,\n        cases hpq with hp hq,\n    -- Therefore, $P \u2227 Q$ must be false by contradiction which results in the second part of our proof!\n        contradiction,\nend\n\n/-\nExcercise. As you can see, writing LEAN proofs is so much more fun than drawing truth tables! Why don't you try it out by proving $\\lnot P \\iff (P \\implies \\tt{false})$ <a href=\"https://leanprover-community.github.io/lean-web-editor/#url=https%3A%2F%2Fraw.githubusercontent.com%2FJasonKYi%2FM4000x_LEAN_formalisation%2Fmaster%2Fsrc%2FExercises%2FExercies1.lean\">here</a>?\n-/\n\n/- Sub-section\n1.3.3 Transitivity of Implications, and the Contrapositive\n-/\n\n/- Theorem\n$\u21d2$ is transitive, i.e. if $P$, $Q$, and $R$ are propositions, then $P \u21d2 Q$ and $Q \u21d2 R$ means $P \u21d2 R$.\n-/\ntheorem imp_trans\n    (P Q R : Prop) : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n    -- Suppose $P \u21d2 Q$ and $Q \u21d2 R$ are both true, we then would like to prove that $P \u21d2 R$ is true.\n    intro h,\n    cases h with hpq hqr,\n    -- Say that $P$ is true,\n    intro hp,\n    -- then by $P \u21d2 Q$, $Q$ must be true. But we also have $Q \u21d2 R$, therefore $R$ is also true, which is exactly what we wish to prove!\n    exact hqr (hpq hp),\nend\n\n/- Theorem\nIf $P$ and $Q$ are propositions, then $(P \u21d2 Q) \u21d4 (\u00ac Q \u21d2 \u00ac P)$.\n-/\ntheorem contra\n    (P Q : Prop) : (P \u2192 Q) \u2194 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n    -- Let's first consider the implication from left to right, i.e. $(P \u21d2 Q) \u21d2 (\u00ac Q \u21d2 \u00ac P)$.\n    split,\n    -- We will prove this by contradiction, so suppose we have $P \u21d2 Q$, $\u00ac Q$ and not $\u00ac P$. \n    intros h hnq hp,\n    -- But not $\u00ac P$ is simply $P$, and $P$ implies $Q$, a contradiction to $\u00ac Q$! Therefore, $P \u21d2 Q$ must imply $\u00ac Q \u21d2 \u00ac P$ as required.\n    exact hnq (h hp),\n    -- Now lets consider reverse, $(\u00ac Q \u21d2 \u00ac P) \u21d2 (P \u21d2 Q)$. Suppose we have $\u00ac Q \u21d2 \u00ac P$ and $P$.\n    intros h hp,\n    -- If $Q$ is true then we have nothing left to prove, so suppose $\u00ac Q$ is true.\n    cases (classical.em Q) with hq hnq,\n    exact hq,\n    exfalso,\n    -- But $\u00ac Q$ implies $\u00ac P$ which contradicts with $P$, therefore, $\u00ac Q$ must be false as requied.\n    exact h hnq hp,\nend\n\n/-\nExcercise. What can we deduce if we apply the contrapositive to $\\lnot Q \\implies \\lnot P$? Try it out <a href=\"https://leanprover-community.github.io/lean-web-editor/#url=https%3A%2F%2Fraw.githubusercontent.com%2FJasonKYi%2FM4000x_LEAN_formalisation%2Fmaster%2Fsrc%2FExercises%2FExercies2.lean\">here</a>?\n-/\n\n/- Sub-section\n1.3.4 Distributivity\n-/\n\n/- Theorem\n(1) If $P$, $Q$, and $R$ are propositions. Then, $P \u2227 (Q \u2228 R) \u21d4 (P \u2227 Q) \u2228 (P \u2227 R)$;\n-/\ntheorem dis_and_or\n    (P Q R : Prop) : P \u2227 (Q \u2228 R) \u2194 (P \u2227 Q) \u2228 (P \u2227 R) :=\nbegin\n    -- Let's first consider the foward implication, $P \u2227 (Q \u2228 R) \u21d2 (P \u2227 Q) \u2228 (P \u2227 R)$\n    split,\n    -- Suppose $P$ is true and either $Q$ or $R$ is true.\n    rintro \u27e8hp, hqr\u27e9,\n    -- But this means either $P$ and $Q$ is true or $P$ and $R$ is true which is exactly what we need.\n    cases hqr with hq hr,\n    left, split, repeat {assumption},\n    right, split, repeat {assumption},\n    -- With that, we now need to prove the backwards implication. Suppose $(P \u2227 Q) \u2228 (P \u2227 R)$.\n    intro h,\n    -- Let's consider both cases.\n    cases h with hpq hpr,\n    -- If $P \u2227 Q$ is true, then $P$ is true and $Q \u2228 R$ is also true.\n    cases hpq with hp hq,\n    split, assumption, left, assumption,\n    -- Similarly, is $P \u2227 R$ is true, then $P$ is true and $Q \u2228 R$ is also true. \n    cases hpr with hp hr,\n    -- Therefore, by considering bothe cases, we see that either $P \u2227 Q$ or $P \u2227 R$ implies $P \u2227 (Q \u2228 R)$.\n    split, assumption, right, assumption,\nend\n\n/- Theorem\n(2) $P \u2228 (Q \u2227 R) \u21d4 (P \u2228 Q) \u2227 (P \u2228 R)$.\n-/\ntheorem dis_or_and\n    (P Q R : Prop) : P \u2228 (Q \u2227 R) \u2194 (P \u2228 Q) \u2227 (P \u2228 R) :=\nbegin\n    -- We first consider the forward implication $P \u2228 (Q \u2227 R) \u21d2 (P \u2228 Q) \u2227 (P \u2228 R)$.\n    split,\n    -- Suppose we have $P \u2228 (Q \u2227 R)$, then either $P$ is true or $Q$ and $R$ is true$.\n    intro h,\n    -- Let's consider both cases. If $P$ is true, then both $P \u2228 Q$ and $P \u2228 R$ are true.\n    cases h with hp hqr,\n    split, repeat {left, assumption},\n    -- Similarly, if $P$ and $Q$ are true, then both $P \u2228 Q$ and $P \u2228 R$ are true. \n    cases hqr with hq hr,\n    split, repeat {right, assumption},\n    -- Now let's consider the backwards implication. Suppose that $(P \u2228 Q)$ and $(P \u2228 R)$ is true and lets consider all the cases.\n    intro h,\n    cases h with hpq hpr,\n    -- If $P$ is true the $P \u2228 (Q \u2227 R)$ is also true.\n    cases hpq with hp hq,\n    cases hpr with hp hr,\n    repeat {left, assumption},\n    -- If $\u00ac P$ is true then from $(P \u2228 Q)$ and $(P \u2228 R)$, $Q$ and $R$ must be true, and therefore, $P \u2228 (Q \u2227 R)$ is also true.\n    cases hpr with hp hr,\n    left, assumption,\n    right, split, repeat {assumption},\nend\n\n/- Sub-section\n1.7 Sets and Propositions\n-/\n\nuniverse u\nvariable {\u03a9 : Type*}\n\n-- Let $\u03a9$ be a fixed set with subsets $X$ and $Y$, then\n\n/- Theorem\n(1) $\\bar{X \u222a Y} = \\bar{X} \u2229 \\bar{Y}$.\n-/\ntheorem de_morg_set_a (X Y : set \u03a9) : - (X \u222a Y) = - X \u2229 - Y :=\nbegin\n    -- What exactly does $\\bar{(X \u222a Y)}$ and $\\bar{X} \u2229 \\bar{Y}$ mean? Well, lets find out!\n    ext,\n    -- As we can see, to show that $\\bar{X \u222a Y} = \\bar{X} \u2229 \\bar{Y}$, we in fact need to prove $x \u2208 \\bar{(X \u222a Y)} \u2194 x \u2208 \\bar{X} \u2229 \\bar{Y}$.\n    split,\n    -- So let's first prove that $x \u2208 \\bar{X \u222a Y} \u2192 x \u2208 \\bar{X} \u2229 \\bar{Y}$. Suppose $x \u2208 \\bar{X \u222a Y}$, then $x$ is not in $X$ and $x$ is not in $Y$.\n    dsimp, intro h,\n    push_neg at h,\n    -- But this is exactly what we need!\n    assumption,\n    -- Now, let's consider the backwards implication. Similarly, $x \u2208 \\bar{X} \u2229 \\bar{Y}$ means $x$ is not in $X$ and $x$ is not in $Y$.\n    dsimp, intro h,\n    -- But this is what $x \u2208 \\bar{X \u222a Y}$ means, so we're done!\n    push_neg,\n    assumption\n    \nend\n\n/- Theorem\n(2) $\\bar{X \u2229 Y} = \\bar{X} \u222a \\bar{Y}$.\n-/\ntheorem de_morg_set_b (X Y : set \u03a9) : - (X \u2229 Y) = - X \u222a - Y :=\nbegin\n    -- Rather than proving this manually, why not try some automation this time.\n    ext, finish\nend\n\n/-\nRemark. Would you look at that! Proving the de Morgan's law with one single line. Now thats a nice proof if I ever seen one!\n-/\n\n/- Sub-section\n1.7.1 \"For All\" and \"There Exists\"\n-/\n\n/- Theorem\nGiven a propositon $P$ whose truth value is dependent on $x \u2208 X$, then $\u2200 x \u2208 X, \u00ac P(x) \u21d4 \u00ac (\u2203 x \u2208 X, P(x))$, and\n-/\ntheorem neg_exist_is_all (X : Type) (P : X \u2192 Prop) : (\u2200 x : X, \u00ac P x) \u2194 \u00ac (\u2203 x : X, P x) :=\nbegin\n    -- (\u21d2) Let's first prove the forward implication, i.e. suppose that $\u2200 x \u2208 X, \u00ac P(x)$, we need to show that $\u00ac \u2203 x \u2208 X, P(x)$.\n    split,\n    -- Let's prove this by contradiction! Let's suppose that $\u00ac \u2203 x \u2208 X, P(x)$ is in fact $\\tt{false}$ and there is actually a $x$ out there where $P(x)$ is true!\n    rintro h \u27e8x, hx\u27e9,\n    -- But, by our assumption $\u2200 x \u2208 X$, $P(x)$ is false, thus a contradiction! \n    from (h x) hx,\n    -- (\u21d0) Now let's consider the other direction. Suppose that there does not exist a $x$ such that $P(x)$ is true, i.e. $\u00ac \u2203 x \u2208 X, P(x)$.\n    intro ha,\n    -- Similarly, let's suppose that $\u2200 x \u2208 X, \u00acP x$ is not true.\n    intros x hx,\n    -- But then, there must be a $x$ such that $P(x)$ is true, again, a contradiction!\n    have : \u2203 (x : X), P x,  \n        existsi x, assumption,\n    contradiction,\nend\n\n/- Theorem\n$\u00ac (\u2200 x \u2208 X, \u00ac P(x)) \u21d4 \u2203 x \u2208 X, P(x)$.\n-/\ntheorem neg_all_is_exist (X : Type) (P : X \u2192 Prop) : \u00ac (\u2200 x : X, \u00ac P x) \u2194 \u2203 x : X, P x :=\nbegin\n    -- Now that we have gone through quite a lot of LEAN proofs, try to understand this one yourself!\n    split,\n        {intro h,\n        apply classical.by_contradiction,\n        push_neg, contradiction\n        },\n        {rintro \u27e8x, hx\u27e9 h,\n        from (h x) hx\n        }\nend\n\nend M40001\n", "meta": {"author": "JasonKYi", "repo": "M4000x_LEAN_formalisation", "sha": "6e99793f2fcbe88596e27644f430e46aa2a464df", "save_path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation", "path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation/M4000x_LEAN_formalisation-6e99793f2fcbe88596e27644f430e46aa2a464df/src/M40001/M40001_C1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7421616292388489}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport data.set.equitable\nimport order.partition.finpartition\n\n/-!\n# Finite equipartitions\n\nThis file defines finite equipartitions, the partitions whose parts all are the same size up to a\ndifference of `1`.\n\n## Main declarations\n\n* `finpartition.is_equipartition`: Predicate for a `finpartition` to be an equipartition.\n-/\n\nopen finset fintype\n\nnamespace finpartition\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] {s t : finset \u03b1} (P : finpartition s)\n\n/-- An equipartition is a partition whose parts are all the same size, up to a difference of `1`. -/\ndef is_equipartition : Prop := (P.parts : set (finset \u03b1)).equitable_on card\n\nlemma is_equipartition_iff_card_parts_eq_average : P.is_equipartition \u2194\n  \u2200 a : finset \u03b1, a \u2208 P.parts \u2192 a.card = s.card/P.parts.card \u2228 a.card = s.card/P.parts.card + 1 :=\nby simp_rw [is_equipartition, finset.equitable_on_iff, P.sum_card_parts]\n\nvariables {P}\n\nlemma _root_.set.subsingleton.is_equipartition (h : (P.parts : set (finset \u03b1)).subsingleton) :\n  P.is_equipartition :=\nh.equitable_on _\n\nlemma is_equipartition.card_parts_eq_average (hP : P.is_equipartition) (ht : t \u2208 P.parts) :\n  t.card = s.card / P.parts.card \u2228 t.card = s.card / P.parts.card + 1 :=\nP.is_equipartition_iff_card_parts_eq_average.1 hP _ ht\n\nlemma is_equipartition.average_le_card_part (hP : P.is_equipartition) (ht : t \u2208 P.parts) :\n  s.card / P.parts.card \u2264 t.card :=\nby { rw \u2190P.sum_card_parts, exact equitable_on.le hP ht }\n\nlemma is_equipartition.card_part_le_average_add_one (hP : P.is_equipartition) (ht : t \u2208 P.parts) :\n  t.card \u2264 s.card / P.parts.card + 1 :=\nby { rw \u2190P.sum_card_parts, exact equitable_on.le_add_one hP ht }\n\n/-! ### Discrete and indiscrete finpartition -/\n\nvariables (s)\n\nlemma bot_is_equipartition : (\u22a5 : finpartition s).is_equipartition :=\nset.equitable_on_iff_exists_eq_eq_add_one.2 \u27e81, by simp\u27e9\n\nlemma top_is_equipartition : (\u22a4 : finpartition s).is_equipartition :=\n(parts_top_subsingleton _).is_equipartition\n\nlemma indiscrete_is_equipartition {hs : s \u2260 \u2205} : (indiscrete hs).is_equipartition :=\nby { rw [is_equipartition, indiscrete_parts, coe_singleton], exact set.equitable_on_singleton s _ }\n\nend finpartition\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/order/partition/equipartition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8652240860523327, "lm_q1q2_score": 0.7421616246849039}}
{"text": "/-\nCopyright (c) 2022 Jake Levinson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jake Levinson\n\n! This file was ported from Lean 3 source module combinatorics.young.young_diagram\n! leanprover-community/mathlib commit 59694bd07f0a39c5beccba34bd9f413a160782bf\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.UpperLower.Basic\nimport Mathlib.Data.Finset.Preimage\n\n/-!\n# Young diagrams\n\nA Young diagram is a finite set of up-left justified boxes:\n\n```text\n\u25a1\u25a1\u25a1\u25a1\u25a1\n\u25a1\u25a1\u25a1\n\u25a1\u25a1\u25a1\n\u25a1\n```\nThis Young diagram corresponds to the [5, 3, 3, 1] partition of 12.\n\nWe represent it as a lower set in `\u2115 \u00d7 \u2115` in the product partial order. We write `(i, j) \u2208 \u03bc`\nto say that `(i, j)` (in matrix coordinates) is in the Young diagram `\u03bc`.\n\n## Main definitions\n\n- `YoungDiagram` : Young diagrams\n- `YoungDiagram.card` : the number of cells in a Young diagram (its *cardinality*)\n- `YoungDiagram.instDistribLatticeYoungDiagram` : a distributive lattice instance for Young diagrams\n  ordered by containment, with `(\u22a5 : YoungDiagram)` the empty diagram.\n- `YoungDiagram.row` and `YoungDiagram.rowLen`: rows of a Young diagram and their lengths\n- `YoungDiagram.col` and `YoungDiagram.colLen`: columns of a Young diagram and their lengths\n\n## Notation\n\nIn \"English notation\", a Young diagram is drawn so that (i1, j1) \u2264 (i2, j2)\nmeans (i1, j1) is weakly up-and-left of (i2, j2). This terminology is used\nbelow, e.g. in `YoungDiagram.up_left_mem`.\n\n## Tags\n\nYoung diagram\n\n## References\n\n<https://en.wikipedia.org/wiki/Young_tableau>\n\n-/\n\n\nopen Function\n\n/-- A Young diagram is a finite collection of cells on the `\u2115 \u00d7 \u2115` grid such that whenever\na cell is present, so are all the ones above and to the left of it. Like matrices, an `(i, j)` cell\nis a cell in row `i` and column `j`, where rows are enumerated downward and columns rightward.\n\nYoung diagrams are modeled as finite sets in `\u2115 \u00d7 \u2115` that are lower sets with respect to the\nstandard order on products. -/\n@[ext]\nstructure YoungDiagram where\n  /-- A finite set which represents a finite collection of cells on the `\u2115 \u00d7 \u2115` grid. -/\n  cells : Finset (\u2115 \u00d7 \u2115)\n  /-- Cells are up-left justified, witnessed by the fact that `cells` is a lower set in `\u2115 \u00d7 \u2115`. -/\n  isLowerSet : IsLowerSet (cells : Set (\u2115 \u00d7 \u2115))\n#align young_diagram YoungDiagram\n\nnamespace YoungDiagram\n\ninstance : SetLike YoungDiagram (\u2115 \u00d7 \u2115)\n    where\n  -- porting note: TODO: figure out how to do this correcly\n  coe := fun y => y.cells\n  coe_injective' \u03bc \u03bd h := by rwa [YoungDiagram.ext_iff, \u2190 Finset.coe_inj]\n\n@[simp]\ntheorem mem_cells {\u03bc : YoungDiagram} (c : \u2115 \u00d7 \u2115) : c \u2208 \u03bc.cells \u2194 c \u2208 \u03bc :=\n  Iff.rfl\n#align young_diagram.mem_cells YoungDiagram.mem_cells\n\n@[simp]\ntheorem mem_mk (c : \u2115 \u00d7 \u2115) (cells) (isLowerSet) :\n    c \u2208 YoungDiagram.mk cells isLowerSet \u2194 c \u2208 cells :=\n  Iff.rfl\n#align young_diagram.mem_mk YoungDiagram.mem_mk\n\ninstance decidableMem (\u03bc : YoungDiagram) : DecidablePred (\u00b7 \u2208 \u03bc) :=\n  inferInstanceAs (DecidablePred (\u00b7 \u2208 \u03bc.cells))\n#align young_diagram.decidable_mem YoungDiagram.decidableMem\n\n/-- In \"English notation\", a Young diagram is drawn so that (i1, j1) \u2264 (i2, j2)\n    means (i1, j1) is weakly up-and-left of (i2, j2). -/\ntheorem up_left_mem (\u03bc : YoungDiagram) {i1 i2 j1 j2 : \u2115} (hi : i1 \u2264 i2) (hj : j1 \u2264 j2)\n    (hcell : (i2, j2) \u2208 \u03bc) : (i1, j1) \u2208 \u03bc :=\n  \u03bc.isLowerSet (Prod.mk_le_mk.mpr \u27e8hi, hj\u27e9) hcell\n#align young_diagram.up_left_mem YoungDiagram.up_left_mem\n\nsection DistribLattice\n\n@[simp]\ntheorem cells_subset_iff {\u03bc \u03bd : YoungDiagram} : \u03bc.cells \u2286 \u03bd.cells \u2194 \u03bc \u2264 \u03bd :=\n  Iff.rfl\n#align young_diagram.cells_subset_iff YoungDiagram.cells_subset_iff\n\n@[simp]\ntheorem cells_ssubset_iff {\u03bc \u03bd : YoungDiagram} : \u03bc.cells \u2282 \u03bd.cells \u2194 \u03bc < \u03bd :=\n  Iff.rfl\n#align young_diagram.cells_ssubset_iff YoungDiagram.cells_ssubset_iff\n\ninstance : Sup YoungDiagram\n    where sup \u03bc \u03bd :=\n    { cells := \u03bc.cells \u222a \u03bd.cells\n      isLowerSet := by\n        rw [Finset.coe_union]\n        exact \u03bc.isLowerSet.union \u03bd.isLowerSet }\n\n@[simp]\ntheorem cells_sup (\u03bc \u03bd : YoungDiagram) : (\u03bc \u2294 \u03bd).cells = \u03bc.cells \u222a \u03bd.cells :=\n  rfl\n#align young_diagram.cells_sup YoungDiagram.cells_sup\n\n@[simp, norm_cast]\ntheorem coe_sup (\u03bc \u03bd : YoungDiagram) : \u2191(\u03bc \u2294 \u03bd) = (\u03bc \u222a \u03bd : Set (\u2115 \u00d7 \u2115)) :=\n  Finset.coe_union _ _\n#align young_diagram.coe_sup YoungDiagram.coe_sup\n\n@[simp]\ntheorem mem_sup {\u03bc \u03bd : YoungDiagram} {x : \u2115 \u00d7 \u2115} : x \u2208 \u03bc \u2294 \u03bd \u2194 x \u2208 \u03bc \u2228 x \u2208 \u03bd :=\n  Finset.mem_union\n#align young_diagram.mem_sup YoungDiagram.mem_sup\n\ninstance : Inf YoungDiagram\n    where inf \u03bc \u03bd :=\n    { cells := \u03bc.cells \u2229 \u03bd.cells\n      isLowerSet := by\n        rw [Finset.coe_inter]\n        exact \u03bc.isLowerSet.inter \u03bd.isLowerSet }\n\n@[simp]\ntheorem cells_inf (\u03bc \u03bd : YoungDiagram) : (\u03bc \u2293 \u03bd).cells = \u03bc.cells \u2229 \u03bd.cells :=\n  rfl\n#align young_diagram.cells_inf YoungDiagram.cells_inf\n\n@[simp, norm_cast]\ntheorem coe_inf (\u03bc \u03bd : YoungDiagram) : \u2191(\u03bc \u2293 \u03bd) = (\u03bc \u2229 \u03bd : Set (\u2115 \u00d7 \u2115)) :=\n  Finset.coe_inter _ _\n#align young_diagram.coe_inf YoungDiagram.coe_inf\n\n@[simp]\ntheorem mem_inf {\u03bc \u03bd : YoungDiagram} {x : \u2115 \u00d7 \u2115} : x \u2208 \u03bc \u2293 \u03bd \u2194 x \u2208 \u03bc \u2227 x \u2208 \u03bd :=\n  Finset.mem_inter\n#align young_diagram.mem_inf YoungDiagram.mem_inf\n\n/-- The empty Young diagram is (\u22a5 : young_diagram). -/\ninstance : OrderBot YoungDiagram where\n  bot :=\n    { cells := \u2205\n      isLowerSet := by\n        intros a b _ h\n        simp only [Finset.coe_empty, Set.mem_empty_iff_false]\n        simp only [Finset.coe_empty, Set.mem_empty_iff_false] at h }\n  bot_le _ _ := by\n    intro y\n    simp only [mem_mk, Finset.not_mem_empty] at y\n\n@[simp]\ntheorem cells_bot : (\u22a5 : YoungDiagram).cells = \u2205 :=\n  rfl\n#align young_diagram.cells_bot YoungDiagram.cells_bot\n\n-- porting note: removed `\u2191`, added `.cells` and changed proof\n-- @[simp] -- Porting note: simp can prove this\n@[norm_cast]\ntheorem coe_bot : (\u22a5 : YoungDiagram).cells = (\u2205 : Set (\u2115 \u00d7 \u2115)) := by\n  refine' Set.eq_of_subset_of_subset _ _\n  intros x h\n  simp [mem_mk, Finset.coe_empty, Set.mem_empty_iff_false] at h\n  simp only [cells_bot, Finset.coe_empty, Set.empty_subset]\n#align young_diagram.coe_bot YoungDiagram.coe_bot\n\n@[simp]\ntheorem not_mem_bot (x : \u2115 \u00d7 \u2115) : x \u2209 (\u22a5 : YoungDiagram) :=\n  Finset.not_mem_empty x\n#align young_diagram.not_mem_bot YoungDiagram.not_mem_bot\n\ninstance : Inhabited YoungDiagram :=\n  \u27e8\u22a5\u27e9\n\ninstance : DistribLattice YoungDiagram :=\n  Function.Injective.distribLattice YoungDiagram.cells (fun \u03bc \u03bd h => by rwa [YoungDiagram.ext_iff])\n    (fun _ _ => rfl) fun _ _ => rfl\n\nend DistribLattice\n\n/-- Cardinality of a Young diagram -/\n@[reducible]\nprotected def card (\u03bc : YoungDiagram) : \u2115 :=\n  \u03bc.cells.card\n#align young_diagram.card YoungDiagram.card\n\nsection Transpose\n\n/-- The `transpose` of a Young diagram is obtained by swapping i's with j's. -/\ndef transpose (\u03bc : YoungDiagram) : YoungDiagram where\n  cells := (Equiv.prodComm _ _).finsetCongr \u03bc.cells\n  isLowerSet _ _ h := by\n    simp only [Finset.mem_coe, Equiv.finsetCongr_apply, Finset.mem_map_equiv]\n    intro hcell\n    apply \u03bc.isLowerSet _ hcell\n    simp [h]\n#align young_diagram.transpose YoungDiagram.transpose\n\n@[simp]\ntheorem mem_transpose {\u03bc : YoungDiagram} {c : \u2115 \u00d7 \u2115} : c \u2208 \u03bc.transpose \u2194 c.swap \u2208 \u03bc := by\n  simp [transpose]\n#align young_diagram.mem_transpose YoungDiagram.mem_transpose\n\n@[simp]\ntheorem transpose_transpose (\u03bc : YoungDiagram) : \u03bc.transpose.transpose = \u03bc := by\n  ext x\n  simp\n#align young_diagram.transpose_transpose YoungDiagram.transpose_transpose\n\ntheorem transpose_eq_iff_eq_transpose {\u03bc \u03bd : YoungDiagram} : \u03bc.transpose = \u03bd \u2194 \u03bc = \u03bd.transpose := by\n  constructor <;>\n    \u00b7 rintro rfl\n      simp\n#align young_diagram.transpose_eq_iff_eq_transpose YoungDiagram.transpose_eq_iff_eq_transpose\n\n@[simp]\ntheorem transpose_eq_iff {\u03bc \u03bd : YoungDiagram} : \u03bc.transpose = \u03bd.transpose \u2194 \u03bc = \u03bd := by\n  rw [transpose_eq_iff_eq_transpose]\n  simp\n#align young_diagram.transpose_eq_iff YoungDiagram.transpose_eq_iff\n\n-- This is effectively both directions of `transpose_le_iff` below.\nprotected theorem le_of_transpose_le {\u03bc \u03bd : YoungDiagram} (h_le : \u03bc.transpose \u2264 \u03bd) :\n    \u03bc \u2264 \u03bd.transpose := fun c hc => by\n  simp only [mem_cells, mem_transpose]\n  apply h_le\n  simpa\n#align young_diagram.le_of_transpose_le YoungDiagram.le_of_transpose_le\n\n@[simp]\ntheorem transpose_le_iff {\u03bc \u03bd : YoungDiagram} : \u03bc.transpose \u2264 \u03bd.transpose \u2194 \u03bc \u2264 \u03bd :=\n  \u27e8fun h => by\n    convert YoungDiagram.le_of_transpose_le h\n    simp, fun h => by\n    rw [\u2190transpose_transpose \u03bc] at h\n    exact YoungDiagram.le_of_transpose_le h \u27e9\n#align young_diagram.transpose_le_iff YoungDiagram.transpose_le_iff\n\n@[mono]\nprotected theorem transpose_mono {\u03bc \u03bd : YoungDiagram} (h_le : \u03bc \u2264 \u03bd) : \u03bc.transpose \u2264 \u03bd.transpose :=\n  transpose_le_iff.mpr h_le\n#align young_diagram.transpose_mono YoungDiagram.transpose_mono\n\n/-- Transposing Young diagrams is an `OrderIso`. -/\n@[simps]\ndef transposeOrderIso : YoungDiagram \u2243o YoungDiagram :=\n  \u27e8\u27e8transpose, transpose, fun _ => by simp, fun _ => by simp\u27e9, by simp\u27e9\n#align young_diagram.transpose_order_iso YoungDiagram.transposeOrderIso\n\nend Transpose\n\nsection Rows\n\n/-! ### Rows and row lengths of Young diagrams.\n\nThis section defines `\u03bc.row` and `\u03bc.rowLen`, with the following API:\n      1.  `(i, j) \u2208 \u03bc \u2194 j < \u03bc.rowLen i`\n      2.  `\u03bc.row i = {i} \u00d7\u1da0 (finset.range (\u03bc.rowLen i))`\n      3.  `\u03bc.rowLen i = (\u03bc.row i).card`\n      4.  `\u2200 {i1 i2}, i1 \u2264 i2 \u2192 \u03bc.rowLen i2 \u2264 \u03bc.rowLen i1`\n\nNote: #3 is not convenient for defining `\u03bc.rowLen`; instead, `\u03bc.rowLen` is defined\nas the smallest `j` such that `(i, j) \u2209 \u03bc`. -/\n\n\n/-- The `i`-th row of a Young diagram consists of the cells whose first coordinate is `i`. -/\ndef row (\u03bc : YoungDiagram) (i : \u2115) : Finset (\u2115 \u00d7 \u2115) :=\n  \u03bc.cells.filter fun c => c.fst = i\n#align young_diagram.row YoungDiagram.row\n\ntheorem mem_row_iff {\u03bc : YoungDiagram} {i : \u2115} {c : \u2115 \u00d7 \u2115} : c \u2208 \u03bc.row i \u2194 c \u2208 \u03bc \u2227 c.fst = i := by\n  simp [row]\n#align young_diagram.mem_row_iff YoungDiagram.mem_row_iff\n\ntheorem mk_mem_row_iff {\u03bc : YoungDiagram} {i j : \u2115} : (i, j) \u2208 \u03bc.row i \u2194 (i, j) \u2208 \u03bc := by simp [row]\n#align young_diagram.mk_mem_row_iff YoungDiagram.mk_mem_row_iff\n\nprotected theorem exists_not_mem_row (\u03bc : YoungDiagram) (i : \u2115) : \u2203 j, (i, j) \u2209 \u03bc := by\n  obtain \u27e8j, hj\u27e9 :=\n    Infinite.exists_not_mem_finset\n      (\u03bc.cells.preimage (Prod.mk i) fun _ _ _ _ h => by\n        cases h\n        rfl)\n  rw [Finset.mem_preimage] at hj\n  exact \u27e8j, hj\u27e9\n#align young_diagram.exists_not_mem_row YoungDiagram.exists_not_mem_row\n\n/-- Length of a row of a Young diagram -/\ndef rowLen (\u03bc : YoungDiagram) (i : \u2115) : \u2115 :=\n  Nat.find <| \u03bc.exists_not_mem_row i\n#align young_diagram.row_len YoungDiagram.rowLen\n\ntheorem mem_iff_lt_rowLen {\u03bc : YoungDiagram} {i j : \u2115} : (i, j) \u2208 \u03bc \u2194 j < \u03bc.rowLen i := by\n  rw [rowLen, Nat.lt_find_iff]\n  push_neg\n  exact \u27e8fun h _ hmj => \u03bc.up_left_mem (by rfl) hmj h, fun h => h _ (by rfl)\u27e9\n#align young_diagram.mem_iff_lt_row_len YoungDiagram.mem_iff_lt_rowLen\n\ntheorem row_eq_prod {\u03bc : YoungDiagram} {i : \u2115} : \u03bc.row i = {i} \u00d7\u1da0 Finset.range (\u03bc.rowLen i) := by\n  ext \u27e8a, b\u27e9\n  simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_row_iff,\n    mem_iff_lt_rowLen, and_comm, and_congr_right_iff]\n  rintro rfl\n  rfl\n#align young_diagram.row_eq_prod YoungDiagram.row_eq_prod\n\ntheorem rowLen_eq_card (\u03bc : YoungDiagram) {i : \u2115} : \u03bc.rowLen i = (\u03bc.row i).card := by\n  simp [row_eq_prod]\n#align young_diagram.row_len_eq_card YoungDiagram.rowLen_eq_card\n\n@[mono]\ntheorem rowLen_anti (\u03bc : YoungDiagram) (i1 i2 : \u2115) (hi : i1 \u2264 i2) : \u03bc.rowLen i2 \u2264 \u03bc.rowLen i1 := by\n  by_contra' h_lt\n  rw [\u2190 lt_self_iff_false (\u03bc.rowLen i1)]\n  rw [\u2190 mem_iff_lt_rowLen] at h_lt\u22a2\n  exact \u03bc.up_left_mem hi (by rfl) h_lt\n#align young_diagram.row_len_anti YoungDiagram.rowLen_anti\n\nend Rows\n\nsection Columns\n\n/-! ### Columns and column lengths of Young diagrams.\n\nThis section has an identical API to the rows section. -/\n\n\n/-- The `j`-th column of a Young diagram consists of the cells whose second coordinate is `j`. -/\ndef col (\u03bc : YoungDiagram) (j : \u2115) : Finset (\u2115 \u00d7 \u2115) :=\n  \u03bc.cells.filter fun c => c.snd = j\n#align young_diagram.col YoungDiagram.col\n\ntheorem mem_col_iff {\u03bc : YoungDiagram} {j : \u2115} {c : \u2115 \u00d7 \u2115} : c \u2208 \u03bc.col j \u2194 c \u2208 \u03bc \u2227 c.snd = j := by\n  simp [col]\n#align young_diagram.mem_col_iff YoungDiagram.mem_col_iff\n\ntheorem mk_mem_col_iff {\u03bc : YoungDiagram} {i j : \u2115} : (i, j) \u2208 \u03bc.col j \u2194 (i, j) \u2208 \u03bc := by simp [col]\n#align young_diagram.mk_mem_col_iff YoungDiagram.mk_mem_col_iff\n\nprotected theorem exists_not_mem_col (\u03bc : YoungDiagram) (j : \u2115) : \u2203 i, (i, j) \u2209 \u03bc.cells := by\n  convert \u03bc.transpose.exists_not_mem_row j using 1\n  simp\n#align young_diagram.exists_not_mem_col YoungDiagram.exists_not_mem_col\n\n/-- Length of a column of a Young diagram -/\ndef colLen (\u03bc : YoungDiagram) (j : \u2115) : \u2115 :=\n  Nat.find <| \u03bc.exists_not_mem_col j\n#align young_diagram.col_len YoungDiagram.colLen\n\n@[simp]\ntheorem colLen_transpose (\u03bc : YoungDiagram) (j : \u2115) : \u03bc.transpose.colLen j = \u03bc.rowLen j := by\n  simp [rowLen, colLen]\n#align young_diagram.col_len_transpose YoungDiagram.colLen_transpose\n\n@[simp]\ntheorem rowLen_transpose (\u03bc : YoungDiagram) (i : \u2115) : \u03bc.transpose.rowLen i = \u03bc.colLen i := by\n  simp [rowLen, colLen]\n#align young_diagram.row_len_transpose YoungDiagram.rowLen_transpose\n\ntheorem mem_iff_lt_colLen {\u03bc : YoungDiagram} {i j : \u2115} : (i, j) \u2208 \u03bc \u2194 i < \u03bc.colLen j := by\n  rw [\u2190 rowLen_transpose, \u2190 mem_iff_lt_rowLen]\n  simp\n#align young_diagram.mem_iff_lt_col_len YoungDiagram.mem_iff_lt_colLen\n\ntheorem col_eq_prod {\u03bc : YoungDiagram} {j : \u2115} : \u03bc.col j = Finset.range (\u03bc.colLen j) \u00d7\u1da0 {j} := by\n  ext \u27e8a, b\u27e9\n  simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_col_iff,\n    mem_iff_lt_colLen, and_comm, and_congr_right_iff]\n  rintro rfl\n  rfl\n#align young_diagram.col_eq_prod YoungDiagram.col_eq_prod\n\ntheorem colLen_eq_card (\u03bc : YoungDiagram) {j : \u2115} : \u03bc.colLen j = (\u03bc.col j).card := by\n  simp [col_eq_prod]\n#align young_diagram.col_len_eq_card YoungDiagram.colLen_eq_card\n\n@[mono]\ntheorem colLen_anti (\u03bc : YoungDiagram) (j1 j2 : \u2115) (hj : j1 \u2264 j2) : \u03bc.colLen j2 \u2264 \u03bc.colLen j1 := by\n  convert \u03bc.transpose.rowLen_anti j1 j2 hj using 1 <;> simp\n#align young_diagram.col_len_anti YoungDiagram.colLen_anti\n\nend Columns\n\nsection RowLens\n\n/-! ### The list of row lengths of a Young diagram\n\nThis section defines `\u03bc.rowLens : list \u2115`, the list of row lengths of a Young diagram `\u03bc`.\n  1. `YoungDiagram.rowLens_sorted` : It is weakly decreasing (`List.Sorted (\u00b7 \u2265 \u00b7)`).\n  2. `YoungDiagram.rowLens_pos` : It is strictly positive.\n\n-/\n\n\n/-- List of row lengths of a Young diagram -/\ndef rowLens (\u03bc : YoungDiagram) : List \u2115 :=\n  (List.range <| \u03bc.colLen 0).map \u03bc.rowLen\n#align young_diagram.row_lens YoungDiagram.rowLens\n\n-- Porting note: use `List.get` instead of `List.nthLe` because it has been deprecated\n@[simp]\ntheorem get_rowLens {\u03bc : YoungDiagram} {i} :\n    \u03bc.rowLens.get i = \u03bc.rowLen i := by simp only [rowLens, List.get_range, List.get_map]\n#align young_diagram.nth_le_row_lens YoungDiagram.get_rowLens\n\n@[simp]\n\n\ntheorem rowLens_sorted (\u03bc : YoungDiagram) : \u03bc.rowLens.Sorted (\u00b7 \u2265 \u00b7) :=\n  (List.pairwise_le_range _).map _ \u03bc.rowLen_anti\n#align young_diagram.row_lens_sorted YoungDiagram.rowLens_sorted\n\ntheorem pos_of_mem_rowLens (\u03bc : YoungDiagram) (x : \u2115) (hx : x \u2208 \u03bc.rowLens) : 0 < x := by\n  rw [rowLens, List.mem_map] at hx\n  obtain \u27e8i, hi, rfl : \u03bc.rowLen i = x\u27e9 := hx\n  rwa [List.mem_range, \u2190 mem_iff_lt_colLen, mem_iff_lt_rowLen] at hi\n#align young_diagram.pos_of_mem_row_lens YoungDiagram.pos_of_mem_rowLens\n\nend RowLens\n\nsection EquivListRowLens\n\n/-! ### Equivalence between Young diagrams and lists of natural numbers\n\nThis section defines the equivalence between Young diagrams `\u03bc` and weakly decreasing lists `w`\nof positive natural numbers, corresponding to row lengths of the diagram:\n  `YoungDiagram.equivListRowLens :`\n  `YoungDiagram \u2243 {w : List \u2115 // w.Sorted (\u00b7 \u2265 \u00b7) \u2227 \u2200 x \u2208 w, 0 < x}`\n\nThe two directions are `YoungDiagram.rowLens` (defined above) and `YoungDiagram.ofRowLens`.\n\n-/\n\n\n/-- The cells making up a `YoungDiagram` from a list of row lengths -/\nprotected def cellsOfRowLens : List \u2115 \u2192 Finset (\u2115 \u00d7 \u2115)\n  | [] => \u2205\n  | w::ws =>\n    ({0} : Finset \u2115) \u00d7\u1da0 Finset.range w \u222a\n      (YoungDiagram.cellsOfRowLens ws).map\n        (Embedding.prodMap \u27e8_, Nat.succ_injective\u27e9 (Embedding.refl \u2115))\n#align young_diagram.cells_of_row_lens YoungDiagram.cellsOfRowLens\n\n-- Porting note: use `List.get` instead of `List.nthLe` because it has been deprecated\nprotected theorem mem_cellsOfRowLens {w : List \u2115} {c : \u2115 \u00d7 \u2115} :\n    c \u2208 YoungDiagram.cellsOfRowLens w \u2194 \u2203 h : c.fst < w.length, c.snd < w.get \u27e8c.fst, h\u27e9  := by\n  induction' w with w_hd w_tl w_ih generalizing c <;> rw [YoungDiagram.cellsOfRowLens]\n  \u00b7 simp [YoungDiagram.cellsOfRowLens]\n  \u00b7 rcases c with \u27e8\u27e8_, _\u27e9, _\u27e9\n    \u00b7 simp\n    -- Porting note: was `simpa`\n    \u00b7 simp [w_ih, -Finset.singleton_product, Nat.succ_lt_succ_iff]\n#align young_diagram.mem_cells_of_row_lens YoungDiagram.mem_cellsOfRowLens\n\n-- Porting note: use `List.get` instead of `List.nthLe` because it has been deprecated\n/-- Young diagram from a sorted list -/\ndef ofRowLens (w : List \u2115) (hw : w.Sorted (\u00b7 \u2265 \u00b7)) : YoungDiagram\n    where\n  cells := YoungDiagram.cellsOfRowLens w\n  isLowerSet := by\n    rintro \u27e8i2, j2\u27e9 \u27e8i1, j1\u27e9 \u27e8hi : i1 \u2264 i2, hj : j1 \u2264 j2\u27e9 hcell\n    rw [Finset.mem_coe, YoungDiagram.mem_cellsOfRowLens] at hcell\u22a2\n    obtain \u27e8h1, h2\u27e9 := hcell\n    refine' \u27e8hi.trans_lt h1, _\u27e9\n    calc\n      j1 \u2264 j2 := hj\n      _ < w.get \u27e8i2, _\u27e9  := h2\n      _ \u2264 w.get \u27e8i1, _\u27e9 :=\n      by\n        obtain rfl | h := eq_or_lt_of_le hi\n        \u00b7 convert le_refl (w.get \u27e8i1, h1\u27e9)\n        \u00b7 exact List.pairwise_iff_get.mp hw _ _ h\n#align young_diagram.of_row_lens YoungDiagram.ofRowLens\n\n-- Porting note: use `List.get` instead of `List.nthLe` because it has been deprecated\ntheorem mem_ofRowLens {w : List \u2115} {hw : w.Sorted (\u00b7 \u2265 \u00b7)} {c : \u2115 \u00d7 \u2115} :\n    c \u2208 ofRowLens w hw \u2194 \u2203 h : c.fst < w.length, c.snd < w.get \u27e8c.fst, h\u27e9 :=\n  YoungDiagram.mem_cellsOfRowLens\n#align young_diagram.mem_of_row_lens YoungDiagram.mem_ofRowLens\n\n/-- The number of rows in `ofRowLens w hw` is the length of `w` -/\ntheorem rowLens_length_ofRowLens {w : List \u2115} {hw : w.Sorted (\u00b7 \u2265 \u00b7)} (hpos : \u2200 x \u2208 w, 0 < x) :\n    (ofRowLens w hw).rowLens.length = w.length := by\n  simp only [length_rowLens, colLen, Nat.find_eq_iff, mem_cells, mem_ofRowLens,\n    lt_self_iff_false, IsEmpty.exists_iff, Classical.not_not]\n  refine' \u27e8True.intro, fun n hn => \u27e8hn, hpos _ (List.get_mem _ _ hn)\u27e9\u27e9\n#align young_diagram.row_lens_length_of_row_lens YoungDiagram.rowLens_length_ofRowLens\n\n-- Porting note: use `List.get` instead of `List.nthLe` because it has been deprecated\n/-- The length of the `i`th row in `ofRowLens w hw` is the `i`th entry of `w` -/\ntheorem rowLen_ofRowLens {w : List \u2115} {hw : w.Sorted (\u00b7 \u2265 \u00b7)} (i : Fin w.length) :\n    (ofRowLens w hw).rowLen i = w.get i := by\n  simp [rowLen, Nat.find_eq_iff, mem_ofRowLens]\n#align young_diagram.row_len_of_row_lens YoungDiagram.rowLen_ofRowLens\n\n/-- The left_inv direction of the equivalence -/\ntheorem ofRowLens_to_rowLens_eq_self {\u03bc : YoungDiagram} : ofRowLens _ (rowLens_sorted \u03bc) = \u03bc := by\n  ext \u27e8i, j\u27e9\n  simp only [mem_cells, mem_ofRowLens, length_rowLens, get_rowLens]\n  simpa [\u2190 mem_iff_lt_colLen, mem_iff_lt_rowLen] using j.zero_le.trans_lt\n#align young_diagram.of_row_lens_to_row_lens_eq_self YoungDiagram.ofRowLens_to_rowLens_eq_self\n\n/-- The right_inv direction of the equivalence -/\ntheorem rowLens_ofRowLens_eq_self {w : List \u2115} {hw : w.Sorted (\u00b7 \u2265 \u00b7)} (hpos : \u2200 x \u2208 w, 0 < x) :\n    (ofRowLens w hw).rowLens = w :=\n  -- Porting note: golf by `List.get`\n  List.ext_get (rowLens_length_ofRowLens hpos) fun i _ h\u2082 =>\n    get_rowLens.trans <| rowLen_ofRowLens \u27e8i, h\u2082\u27e9\n#align young_diagram.row_lens_of_row_lens_eq_self YoungDiagram.rowLens_ofRowLens_eq_self\n\n/-- Equivalence between Young diagrams and weakly decreasing lists of positive natural numbers.\nA Young diagram `\u03bc` is equivalent to a list of row lengths. -/\n@[simps]\ndef equivListRowLens : YoungDiagram \u2243 { w : List \u2115 // w.Sorted (\u00b7 \u2265 \u00b7) \u2227 \u2200 x \u2208 w, 0 < x }\n    where\n  toFun \u03bc := \u27e8\u03bc.rowLens, \u03bc.rowLens_sorted, \u03bc.pos_of_mem_rowLens\u27e9\n  invFun ww := ofRowLens ww.1 ww.2.1\n  left_inv _ := ofRowLens_to_rowLens_eq_self\n  right_inv := fun \u27e8_, hw\u27e9 => Subtype.mk_eq_mk.mpr (rowLens_ofRowLens_eq_self hw.2)\n#align young_diagram.equiv_list_row_lens YoungDiagram.equivListRowLens\n\nend EquivListRowLens\n\nend YoungDiagram\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/Young/YoungDiagram.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7421616154121012}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.complex.basic\n! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Real.Sqrt\n\n/-!\n# The complex numbers\n\nThe complex numbers are modelled as \u211d^2 in the obvious way and it is shown that they form a field\nof characteristic zero. The result that the complex numbers are algebraically closed, see\n`FieldTheory.AlgebraicClosure`.\n-/\n\n\nopen BigOperators\n\nopen Set Function\n\n/-! ### Definition and basic arithmmetic -/\n\n\n/-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/\nstructure Complex : Type where\n  re : \u211d\n  im : \u211d\n#align complex Complex\n\n\nnotation \"\u2102\" => Complex\n\nnamespace Complex\n\nopen ComplexConjugate\n\nnoncomputable instance : DecidableEq \u2102 :=\n  Classical.decEq _\n\n/-- The equivalence between the complex numbers and `\u211d \u00d7 \u211d`. -/\n@[simps apply]\ndef equivRealProd : \u2102 \u2243 \u211d \u00d7 \u211d where\n  toFun z := \u27e8z.re, z.im\u27e9\n  invFun p := \u27e8p.1, p.2\u27e9\n  left_inv := fun \u27e8_, _\u27e9 => rfl\n  right_inv := fun \u27e8_, _\u27e9 => rfl\n#align complex.equiv_real_prod Complex.equivRealProd\n\n@[simp]\ntheorem eta : \u2200 z : \u2102, Complex.mk z.re z.im = z\n  | \u27e8_, _\u27e9 => rfl\n#align complex.eta Complex.eta\n\n@[ext]\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n  | \u27e8_, _\u27e9, \u27e8_, _\u27e9, rfl, rfl => rfl\n#align complex.ext Complex.ext\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n  \u27e8fun H => by simp [H], fun h => ext h.1 h.2\u27e9\n#align complex.ext_iff Complex.ext_iff\n\ntheorem re_surjective : Surjective re := fun x => \u27e8\u27e8x, 0\u27e9, rfl\u27e9\n#align complex.re_surjective Complex.re_surjective\n\ntheorem im_surjective : Surjective im := fun y => \u27e8\u27e80, y\u27e9, rfl\u27e9\n#align complex.im_surjective Complex.im_surjective\n\n@[simp]\ntheorem range_re : range re = univ :=\n  re_surjective.range_eq\n#align complex.range_re Complex.range_re\n\n@[simp]\ntheorem range_im : range im = univ :=\n  im_surjective.range_eq\n#align complex.range_im Complex.range_im\n\n-- Porting note: refactored instance to allow `norm_cast` to work\n/-- The natural inclusion of the real numbers into the complex numbers.\nThe name `Complex.ofReal` is reserved for the bundled homomorphism. -/\n@[coe]\ndef ofReal' (r : \u211d) : \u2102 :=\n  \u27e8r, 0\u27e9\ninstance : Coe \u211d \u2102 :=\n  \u27e8ofReal'\u27e9\n\n/- Porting note: `simp` attribute removed as this has a variable as head symbol of\nthe left-hand side (after whnfR)-/\n@[norm_cast]\ntheorem ofReal_re (r : \u211d) : Complex.re (r : \u2102) = r :=\n  rfl\n#align complex.of_real_re Complex.ofReal_re\n\n@[simp, norm_cast]\ntheorem ofReal_im (r : \u211d) : (r : \u2102).im = 0 :=\n  rfl\n#align complex.of_real_im Complex.ofReal_im\n\ntheorem ofReal_def (r : \u211d) : (r : \u2102) = \u27e8r, 0\u27e9 :=\n  rfl\n#align complex.of_real_def Complex.ofReal_def\n\n@[simp, norm_cast]\ntheorem ofReal_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n  \u27e8congrArg re, by apply congrArg\u27e9\n#align complex.of_real_inj Complex.ofReal_inj\n\n-- Porting note: made coercion explicit\ntheorem ofReal_injective : Function.Injective ((\u2191) : \u211d \u2192 \u2102) := fun _ _ => congrArg re\n#align complex.of_real_injective Complex.ofReal_injective\n\n-- Porting note: made coercion explicit\ninstance canLift : CanLift \u2102 \u211d (\u2191) fun z => z.im = 0 where\n  prf z hz := \u27e8z.re, ext rfl hz.symm\u27e9\n#align complex.can_lift Complex.canLift\n\n/-- The product of a set on the real axis and a set on the imaginary axis of the complex plane,\ndenoted by `s \u00d7\u2102 t`. -/\ndef Set.reProdIm (s t : Set \u211d) : Set \u2102 :=\n  re \u207b\u00b9' s \u2229 im \u207b\u00b9' t\n#align set.re_prod_im Complex.Set.reProdIm\n\ninfixl:72 \" \u00d7\u2102 \" => Set.reProdIm\n\ntheorem mem_reProdIm {z : \u2102} {s t : Set \u211d} : z \u2208 s \u00d7\u2102 t \u2194 z.re \u2208 s \u2227 z.im \u2208 t :=\n  Iff.rfl\n#align complex.mem_re_prod_im Complex.mem_reProdIm\n\ninstance : Zero \u2102 :=\n  \u27e8(0 : \u211d)\u27e9\n\ninstance : Inhabited \u2102 :=\n  \u27e80\u27e9\n\n@[simp]\ntheorem zero_re : (0 : \u2102).re = 0 :=\n  rfl\n#align complex.zero_re Complex.zero_re\n\n@[simp]\ntheorem zero_im : (0 : \u2102).im = 0 :=\n  rfl\n#align complex.zero_im Complex.zero_im\n\n@[simp, norm_cast]\ntheorem ofReal_zero : ((0 : \u211d) : \u2102) = 0 :=\n  rfl\n#align complex.of_real_zero Complex.ofReal_zero\n\n@[simp]\ntheorem ofReal_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 :=\n  ofReal_inj\n#align complex.of_real_eq_zero Complex.ofReal_eq_zero\n\ntheorem ofReal_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 :=\n  not_congr ofReal_eq_zero\n#align complex.of_real_ne_zero Complex.ofReal_ne_zero\n\ninstance : One \u2102 :=\n  \u27e8(1 : \u211d)\u27e9\n\n@[simp]\ntheorem one_re : (1 : \u2102).re = 1 :=\n  rfl\n#align complex.one_re Complex.one_re\n\n@[simp]\ntheorem one_im : (1 : \u2102).im = 0 :=\n  rfl\n#align complex.one_im Complex.one_im\n\n@[simp, norm_cast]\ntheorem ofReal_one : ((1 : \u211d) : \u2102) = 1 :=\n  rfl\n#align complex.of_real_one Complex.ofReal_one\n\n@[simp]\ntheorem ofReal_eq_one {z : \u211d} : (z : \u2102) = 1 \u2194 z = 1 :=\n  ofReal_inj\n#align complex.of_real_eq_one Complex.ofReal_eq_one\n\ntheorem ofReal_ne_one {z : \u211d} : (z : \u2102) \u2260 1 \u2194 z \u2260 1 :=\n  not_congr ofReal_eq_one\n#align complex.of_real_ne_one Complex.ofReal_ne_one\n\ninstance : Add \u2102 :=\n  \u27e8fun z w => \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp]\ntheorem add_re (z w : \u2102) : (z + w).re = z.re + w.re :=\n  rfl\n#align complex.add_re Complex.add_re\n\n@[simp]\ntheorem add_im (z w : \u2102) : (z + w).im = z.im + w.im :=\n  rfl\n#align complex.add_im Complex.add_im\n\nsection\nset_option linter.deprecated false\n@[simp]\ntheorem bit0_re (z : \u2102) : (bit0 z).re = bit0 z.re :=\n  rfl\n#align complex.bit0_re Complex.bit0_re\n\n@[simp]\ntheorem bit1_re (z : \u2102) : (bit1 z).re = bit1 z.re :=\n  rfl\n#align complex.bit1_re Complex.bit1_re\n\n@[simp]\ntheorem bit0_im (z : \u2102) : (bit0 z).im = bit0 z.im :=\n  Eq.refl _\n#align complex.bit0_im Complex.bit0_im\n\n@[simp]\ntheorem bit1_im (z : \u2102) : (bit1 z).im = bit0 z.im :=\n  add_zero _\n#align complex.bit1_im Complex.bit1_im\n\n@[simp, norm_cast]\ntheorem ofReal_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s :=\n  ext_iff.2 <| by simp [ofReal']\n#align complex.of_real_add Complex.ofReal_add\n\n@[simp, norm_cast]\ntheorem ofReal_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 (r : \u2102)  :=\n  ext_iff.2 <| by simp [bit0]\n#align complex.of_real_bit0 Complex.ofReal_bit0\n\n@[simp,  norm_cast]\ntheorem ofReal_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 (r : \u2102) :=\n  ext_iff.2 <| by simp [bit1]\n#align complex.of_real_bit1 Complex.ofReal_bit1\n\nend\n\ninstance : Neg \u2102 :=\n  \u27e8fun z => \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp]\ntheorem neg_re (z : \u2102) : (-z).re = -z.re :=\n  rfl\n#align complex.neg_re Complex.neg_re\n\n@[simp]\ntheorem neg_im (z : \u2102) : (-z).im = -z.im :=\n  rfl\n#align complex.neg_im Complex.neg_im\n\n@[simp, norm_cast]\ntheorem ofReal_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r :=\n  ext_iff.2 <| by simp [ofReal']\n#align complex.of_real_neg Complex.ofReal_neg\n\ninstance : Sub \u2102 :=\n  \u27e8fun z w => \u27e8z.re - w.re, z.im - w.im\u27e9\u27e9\n\ninstance : Mul \u2102 :=\n  \u27e8fun z w => \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp]\ntheorem mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im :=\n  rfl\n#align complex.mul_re Complex.mul_re\n\n@[simp]\ntheorem mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re :=\n  rfl\n#align complex.mul_im Complex.mul_im\n\n@[simp, norm_cast]\ntheorem ofReal_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s :=\n  ext_iff.2 <| by simp [ofReal']\n#align complex.of_real_mul Complex.ofReal_mul\n\ntheorem ofReal_mul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp [ofReal']\n#align complex.of_real_mul_re Complex.ofReal_mul_re\n\ntheorem ofReal_mul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp [ofReal']\n#align complex.of_real_mul_im Complex.ofReal_mul_im\n\ntheorem ofReal_mul' (r : \u211d) (z : \u2102) : \u2191r * z = \u27e8r * z.re, r * z.im\u27e9 :=\n  ext (ofReal_mul_re _ _) (ofReal_mul_im _ _)\n#align complex.of_real_mul' Complex.ofReal_mul'\n\n/-! ### The imaginary unit, `I` -/\n\n\n/-- The imaginary unit. -/\ndef I : \u2102 :=\n  \u27e80, 1\u27e9\nset_option linter.uppercaseLean3 false in\n#align complex.I Complex.I\n\n@[simp]\ntheorem I_re : I.re = 0 :=\n  rfl\nset_option linter.uppercaseLean3 false in\n#align complex.I_re Complex.I_re\n\n@[simp]\ntheorem I_im : I.im = 1 :=\n  rfl\nset_option linter.uppercaseLean3 false in\n#align complex.I_im Complex.I_im\n\n@[simp]\ntheorem I_mul_I : I * I = -1 :=\n  ext_iff.2 <| by simp\nset_option linter.uppercaseLean3 false in\n#align complex.I_mul_I Complex.I_mul_I\n\ntheorem I_mul (z : \u2102) : I * z = \u27e8-z.im, z.re\u27e9 :=\n  ext_iff.2 <| by simp\nset_option linter.uppercaseLean3 false in\n#align complex.I_mul Complex.I_mul\n\ntheorem I_ne_zero : (I : \u2102) \u2260 0 :=\n  mt (congr_arg im) zero_ne_one.symm\nset_option linter.uppercaseLean3 false in\n#align complex.I_ne_zero Complex.I_ne_zero\n\ntheorem mk_eq_add_mul_I (a b : \u211d) : Complex.mk a b = a + b * I :=\n  ext_iff.2 <| by simp [ofReal']\nset_option linter.uppercaseLean3 false in\n#align complex.mk_eq_add_mul_I Complex.mk_eq_add_mul_I\n\n@[simp]\ntheorem re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\n  ext_iff.2 <| by simp [ofReal']\n#align complex.re_add_im Complex.re_add_im\n\ntheorem mul_I_re (z : \u2102) : (z * I).re = -z.im := by simp\nset_option linter.uppercaseLean3 false in\n#align complex.mul_I_re Complex.mul_I_re\n\ntheorem mul_I_im (z : \u2102) : (z * I).im = z.re := by simp\nset_option linter.uppercaseLean3 false in\n#align complex.mul_I_im Complex.mul_I_im\n\ntheorem I_mul_re (z : \u2102) : (I * z).re = -z.im := by simp\nset_option linter.uppercaseLean3 false in\n#align complex.I_mul_re Complex.I_mul_re\n\ntheorem I_mul_im (z : \u2102) : (I * z).im = z.re := by simp\nset_option linter.uppercaseLean3 false in\n#align complex.I_mul_im Complex.I_mul_im\n\n@[simp]\ntheorem equivRealProd_symm_apply (p : \u211d \u00d7 \u211d) : equivRealProd.symm p = p.1 + p.2 * I := by\n  ext <;> simp [Complex.equivRealProd, ofReal']\n#align complex.equiv_real_prod_symm_apply Complex.equivRealProd_symm_apply\n\n/-! ### Commutative ring instance and lemmas -/\n\n\n/- We use a nonstandard formula for the `\u2115` and `\u2124` actions to make sure there is no\ndiamond from the other actions they inherit through the `\u211d`-action on `\u2102` and action transitivity\ndefined in `Data.Complex.Module`. -/\ninstance : Nontrivial \u2102 :=\n  pullback_nonzero re rfl rfl\n\n-- Porting note: proof needed modifications and rewritten fields\ninstance addCommGroup : AddCommGroup \u2102 :=\n{ zero := (0 : \u2102)\n  add := (\u00b7 + \u00b7)\n  neg := Neg.neg\n  sub := Sub.sub\n  nsmul := fun n z => \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9\n  zsmul := fun n z => \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9\n  zsmul_zero':= by intros; ext <;> simp\n  nsmul_zero := by intros; ext <;> simp\n  nsmul_succ := by\n    intros; ext <;> simp [AddMonoid.nsmul_succ, add_mul, add_comm]\n  zsmul_succ' := by\n    intros; ext <;> simp [SubNegMonoid.zsmul_succ', add_mul, add_comm]\n  zsmul_neg' := by\n    intros; ext <;> simp [zsmul_neg', add_mul]\n  add_assoc := by intros; ext <;> simp [add_assoc]\n  zero_add := by intros; ext <;> simp\n  add_zero := by intros; ext <;> simp\n  add_comm := by intros; ext <;> simp [add_comm]\n  add_left_neg := by intros; ext <;> simp }\n\n\ninstance Complex.addGroupWithOne : AddGroupWithOne \u2102 :=\n  { Complex.addCommGroup with\n    natCast := fun n => \u27e8n, 0\u27e9\n    natCast_zero := by\n      ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_zero]\n    natCast_succ := fun _ => by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_succ]\n    intCast := fun n => \u27e8n, 0\u27e9\n    intCast_ofNat := fun _ => by ext <;> rfl\n    intCast_negSucc := fun n => by\n      ext\n      \u00b7 simp [AddGroupWithOne.intCast_negSucc]\n        show -(1: \u211d) + (-n) = -(\u2191(n + 1))\n        simp [Nat.cast_add, add_comm]\n      \u00b7 simp [AddGroupWithOne.intCast_negSucc]\n        show im \u27e8n, 0\u27e9 = 0\n        rfl\n    one := 1 }\n\n-- Porting note: proof needed modifications and rewritten fields\ninstance commRing : CommRing \u2102 :=\n  { Complex.addGroupWithOne with\n    zero := (0 : \u2102)\n    add := (\u00b7 + \u00b7)\n    one := 1\n    mul := (\u00b7 * \u00b7)\n    npow := @npowRec _ \u27e8(1 : \u2102)\u27e9 \u27e8(\u00b7 * \u00b7)\u27e9\n    add_comm := by intros; ext <;> simp [add_comm]\n    left_distrib := by\n      intros; ext <;> simp [mul_re, mul_im] <;> ring\n    right_distrib := by\n      intros; ext <;> simp [mul_re, mul_im] <;> ring\n    zero_mul := by intros; ext <;> simp [zero_mul]\n    mul_zero := by intros; ext <;> simp [mul_zero]\n    mul_assoc := by intros; ext <;> simp [mul_assoc] <;> ring\n    one_mul := by intros; ext <;> simp [one_mul]\n    mul_one := by intros; ext <;> simp [mul_one]\n    mul_comm := by intros; ext <;> simp [mul_comm] ; ring }\n\n/-- This shortcut instance ensures we do not find `Ring` via the noncomputable `Complex.field`\ninstance. -/\ninstance : Ring \u2102 := by infer_instance\n\n/-- This shortcut instance ensures we do not find `CommSemiring` via the noncomputable\n`Complex.field` instance. -/\ninstance : CommSemiring \u2102 :=\n  inferInstance\n\n/-- The \"real part\" map, considered as an additive group homomorphism. -/\ndef reAddGroupHom : \u2102 \u2192+ \u211d where\n  toFun := re\n  map_zero' := zero_re\n  map_add' := add_re\n#align complex.re_add_group_hom Complex.reAddGroupHom\n\n@[simp]\ntheorem coe_reAddGroupHom : (reAddGroupHom : \u2102 \u2192 \u211d) = re :=\n  rfl\n#align complex.coe_re_add_group_hom Complex.coe_reAddGroupHom\n\n/-- The \"imaginary part\" map, considered as an additive group homomorphism. -/\ndef imAddGroupHom : \u2102 \u2192+ \u211d where\n  toFun := im\n  map_zero' := zero_im\n  map_add' := add_im\n#align complex.im_add_group_hom Complex.imAddGroupHom\n\n@[simp]\ntheorem coe_imAddGroupHom : (imAddGroupHom : \u2102 \u2192 \u211d) = im :=\n  rfl\n#align complex.coe_im_add_group_hom Complex.coe_imAddGroupHom\n\nsection\nset_option linter.deprecated false\n@[simp]\ntheorem I_pow_bit0 (n : \u2115) : I ^ bit0 n = (-1) ^ n := by rw [pow_bit0', Complex.I_mul_I]\nset_option linter.uppercaseLean3 false in\n#align complex.I_pow_bit0 Complex.I_pow_bit0\n\n@[simp]\ntheorem I_pow_bit1 (n : \u2115) : I ^ bit1 n = (-1) ^ n * I := by rw [pow_bit1', Complex.I_mul_I]\nset_option linter.uppercaseLean3 false in\n#align complex.I_pow_bit1 Complex.I_pow_bit1\n\n--Porting note: new theorem\n@[simp, norm_cast]\ntheorem ofReal_ofNat (n : \u2115) [n.AtLeastTwo] : ((OfNat.ofNat n : \u211d) : \u2102) = OfNat.ofNat n :=\n  rfl\n\n@[simp]\ntheorem re_ofNat (n : \u2115) [n.AtLeastTwo] : (OfNat.ofNat n : \u2102).re = OfNat.ofNat n :=\n  rfl\n\n@[simp]\ntheorem im_ofNat (n : \u2115) [n.AtLeastTwo] : (OfNat.ofNat n : \u2102).im = 0 :=\n  rfl\n\nend\n/-! ### Complex conjugation -/\n\n\n/-- This defines the complex conjugate as the `star` operation of the `StarRing \u2102`. It\nis recommended to use the ring endomorphism version `starRingEnd`, available under the\nnotation `conj` in the locale `ComplexConjugate`. -/\ninstance : StarRing \u2102 where\n  star z := \u27e8z.re, -z.im\u27e9\n  star_involutive x := by simp only [eta, neg_neg]\n  star_mul a b := by ext <;> simp [add_comm] <;> ring\n  star_add a b := by ext <;> simp [add_comm]\n\n@[simp]\ntheorem conj_re (z : \u2102) : (conj z).re = z.re :=\n  rfl\n#align complex.conj_re Complex.conj_re\n\n@[simp]\ntheorem conj_im (z : \u2102) : (conj z).im = -z.im :=\n  rfl\n#align complex.conj_im Complex.conj_im\n\ntheorem conj_ofReal (r : \u211d) : conj (r : \u2102) = r :=\n  ext_iff.2 <| by simp [star]\n#align complex.conj_of_real Complex.conj_ofReal\n\n@[simp]\ntheorem conj_I : conj I = -I :=\n  ext_iff.2 <| by simp\n  set_option linter.uppercaseLean3 false in\n#align complex.conj_I Complex.conj_I\n\n\nsection\nset_option linter.deprecated false\ntheorem conj_bit0 (z : \u2102) : conj (bit0 z) = bit0 (conj z) :=\n  ext_iff.2 <| by simp [bit0]\n#align complex.conj_bit0 Complex.conj_bit0\n\ntheorem conj_bit1 (z : \u2102) : conj (bit1 z) = bit1 (conj z) :=\n  ext_iff.2 <| by simp [bit0]\n#align complex.conj_bit1 Complex.conj_bit1\nend\n-- @[simp]\n/- Porting note: `simp` attribute removed as the result could be proved\nby `simp only [@map_neg, Complex.conj_i, @neg_neg]`\n-/\ntheorem conj_neg_I : conj (-I) = I :=\n  ext_iff.2 <| by simp\nset_option linter.uppercaseLean3 false in\n#align complex.conj_neg_I Complex.conj_neg_I\n\ntheorem eq_conj_iff_real {z : \u2102} : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n  \u27e8fun h => \u27e8z.re, ext rfl <| eq_zero_of_neg_eq (congr_arg im h)\u27e9, fun \u27e8h, e\u27e9 => by\n    rw [e, conj_ofReal]\u27e9\n#align complex.eq_conj_iff_real Complex.eq_conj_iff_real\n\ntheorem eq_conj_iff_re {z : \u2102} : conj z = z \u2194 (z.re : \u2102) = z :=\n  eq_conj_iff_real.trans \u27e8by rintro \u27e8r, rfl\u27e9 ; simp [ofReal'], fun h => \u27e8_, h.symm\u27e9\u27e9\n#align complex.eq_conj_iff_re Complex.eq_conj_iff_re\n\ntheorem eq_conj_iff_im {z : \u2102} : conj z = z \u2194 z.im = 0 :=\n  \u27e8fun h => add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)), fun h =>\n    ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))\u27e9\n#align complex.eq_conj_iff_im Complex.eq_conj_iff_im\n\n-- `simpNF` complains about this being provable by `is_R_or_C.star_def` even\n-- though it's not imported by this file.\n-- Porting note: linter `simpNF` not found\n@[simp]\ntheorem star_def : (Star.star : \u2102 \u2192 \u2102) = conj :=\n  rfl\n#align complex.star_def Complex.star_def\n\n/-! ### Norm squared -/\n\n\n/-- The norm squared function. -/\n-- Porting note: `@[pp_nodot]` not found\n-- @[pp_nodot]\ndef normSq : \u2102 \u2192*\u2080 \u211d where\n  toFun z := z.re * z.re + z.im * z.im\n  map_zero' := by simp\n  map_one' := by simp\n  map_mul' z w := by\n    dsimp\n    ring\n#align complex.norm_sq Complex.normSq\n\ntheorem normSq_apply (z : \u2102) : normSq z = z.re * z.re + z.im * z.im :=\n  rfl\n#align complex.norm_sq_apply Complex.normSq_apply\n\n@[simp]\ntheorem normSq_ofReal (r : \u211d) : normSq r = r * r := by\n  simp [normSq, ofReal']\n#align complex.norm_sq_of_real Complex.normSq_ofReal\n\n@[simp]\ntheorem normSq_mk (x y : \u211d) : normSq \u27e8x, y\u27e9 = x * x + y * y :=\n  rfl\n#align complex.norm_sq_mk Complex.normSq_mk\n\ntheorem normSq_add_mul_I (x y : \u211d) : normSq (x + y * I) = x ^ 2 + y ^ 2 := by\n  rw [\u2190 mk_eq_add_mul_I, normSq_mk, sq, sq]\nset_option linter.uppercaseLean3 false in\n#align complex.norm_sq_add_mul_I Complex.normSq_add_mul_I\n\ntheorem normSq_eq_conj_mul_self {z : \u2102} : (normSq z : \u2102) = conj z * z := by\n  ext <;> simp [normSq, mul_comm, ofReal']\n#align complex.norm_sq_eq_conj_mul_self Complex.normSq_eq_conj_mul_self\n\n-- @[simp]\n/- Porting note: `simp` attribute removed as linter reports this can be proved\nby `simp only [@map_zero]` -/\ntheorem normSq_zero : normSq 0 = 0 :=\n  normSq.map_zero\n#align complex.norm_sq_zero Complex.normSq_zero\n\n-- @[simp]\n/- Porting note: `simp` attribute removed as linter reports this can be proved\nby `simp only [@map_one]` -/\ntheorem normSq_one : normSq 1 = 1 :=\n  normSq.map_one\n#align complex.norm_sq_one Complex.normSq_one\n\n@[simp]\ntheorem normSq_I : normSq I = 1 := by simp [normSq]\nset_option linter.uppercaseLean3 false in\n#align complex.norm_sq_I Complex.normSq_I\n\ntheorem normSq_nonneg (z : \u2102) : 0 \u2264 normSq z :=\n  add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n#align complex.norm_sq_nonneg Complex.normSq_nonneg\n\n@[simp]\ntheorem range_normSq : range normSq = Ici 0 :=\n  Subset.antisymm (range_subset_iff.2 normSq_nonneg) fun x hx =>\n    \u27e8Real.sqrt x, by rw [normSq_ofReal, Real.mul_self_sqrt hx]\u27e9\n#align complex.range_norm_sq Complex.range_normSq\n\ntheorem normSq_eq_zero {z : \u2102} : normSq z = 0 \u2194 z = 0 :=\n  \u27e8fun h =>\n    ext (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n      (eq_zero_of_mul_self_add_mul_self_eq_zero <| (add_comm _ _).trans h),\n    fun h => h.symm \u25b8 normSq_zero\u27e9\n#align complex.norm_sq_eq_zero Complex.normSq_eq_zero\n\n@[simp]\ntheorem normSq_pos {z : \u2102} : 0 < normSq z \u2194 z \u2260 0 :=\n  (normSq_nonneg z).lt_iff_ne.trans <| not_congr (eq_comm.trans normSq_eq_zero)\n#align complex.norm_sq_pos Complex.normSq_pos\n\n@[simp]\ntheorem normSq_neg (z : \u2102) : normSq (-z) = normSq z := by simp [normSq]\n#align complex.norm_sq_neg Complex.normSq_neg\n\n@[simp]\ntheorem normSq_conj (z : \u2102) : normSq (conj z) = normSq z := by simp [normSq]\n#align complex.norm_sq_conj Complex.normSq_conj\n\ntheorem normSq_mul (z w : \u2102) : normSq (z * w) = normSq z * normSq w :=\n  normSq.map_mul z w\n#align complex.norm_sq_mul Complex.normSq_mul\n\ntheorem normSq_add (z w : \u2102) : normSq (z + w) = normSq z + normSq w + 2 * (z * conj w).re := by\n  dsimp [normSq] ; ring\n#align complex.norm_sq_add Complex.normSq_add\n\ntheorem re_sq_le_normSq (z : \u2102) : z.re * z.re \u2264 normSq z :=\n  le_add_of_nonneg_right (mul_self_nonneg _)\n#align complex.re_sq_le_norm_sq Complex.re_sq_le_normSq\n\ntheorem im_sq_le_normSq (z : \u2102) : z.im * z.im \u2264 normSq z :=\n  le_add_of_nonneg_left (mul_self_nonneg _)\n#align complex.im_sq_le_norm_sq Complex.im_sq_le_normSq\n\ntheorem mul_conj (z : \u2102) : z * conj z = normSq z :=\n  ext_iff.2 <| by simp [normSq, mul_comm, sub_eq_neg_add, add_comm, ofReal']\n#align complex.mul_conj Complex.mul_conj\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\n  ext_iff.2 <| by simp [two_mul, ofReal']\n#align complex.add_conj Complex.add_conj\n\n/-- The coercion `\u211d \u2192 \u2102` as a `RingHom`. -/\ndef ofReal : \u211d \u2192+* \u2102 where\n  toFun x := (x : \u2102)\n  map_one' := ofReal_one\n  map_zero' := ofReal_zero\n  map_mul' := ofReal_mul\n  map_add' := ofReal_add\n#align complex.of_real Complex.ofReal\n\n@[simp]\ntheorem ofReal_eq_coe (r : \u211d) : ofReal r = r :=\n  rfl\n#align complex.of_real_eq_coe Complex.ofReal_eq_coe\n\n@[simp]\ntheorem I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]\nset_option linter.uppercaseLean3 false in\n#align complex.I_sq Complex.I_sq\n\n@[simp]\ntheorem sub_re (z w : \u2102) : (z - w).re = z.re - w.re :=\n  rfl\n#align complex.sub_re Complex.sub_re\n\n@[simp]\n\n\n@[simp, norm_cast]\ntheorem ofReal_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s :=\n  ext_iff.2 <| by simp [ofReal']\n#align complex.of_real_sub Complex.ofReal_sub\n\n@[simp, norm_cast]\ntheorem ofReal_pow (r : \u211d) (n : \u2115) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n := by\n  induction n <;> simp [*, ofReal_mul, pow_succ]\n#align complex.of_real_pow Complex.ofReal_pow\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\n  ext_iff.2 <| by simp [two_mul, sub_eq_add_neg, ofReal']\n#align complex.sub_conj Complex.sub_conj\n\ntheorem normSq_sub (z w : \u2102) : normSq (z - w) = normSq z + normSq w - 2 * (z * conj w).re := by\n  rw [sub_eq_add_neg, normSq_add]\n  simp only [RingHom.map_neg, mul_neg, neg_re, normSq_neg]\n  ring\n#align complex.norm_sq_sub Complex.normSq_sub\n\n/-! ### Inversion -/\n\n\nnoncomputable instance : Inv \u2102 :=\n  \u27e8fun z => conj z * ((normSq z)\u207b\u00b9 : \u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((normSq z)\u207b\u00b9 : \u211d) :=\n  rfl\n#align complex.inv_def Complex.inv_def\n\n@[simp]\ntheorem inv_re (z : \u2102) : z\u207b\u00b9.re = z.re / normSq z := by simp [inv_def, division_def, ofReal']\n#align complex.inv_re Complex.inv_re\n\n@[simp]\ntheorem inv_im (z : \u2102) : z\u207b\u00b9.im = -z.im / normSq z := by simp [inv_def, division_def, ofReal']\n#align complex.inv_im Complex.inv_im\n\n@[simp, norm_cast]\ntheorem ofReal_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = (r : \u2102)\u207b\u00b9 :=\n  ext_iff.2 <| by simp [ofReal']\n#align complex.of_real_inv Complex.ofReal_inv\n\nprotected theorem inv_zero : (0\u207b\u00b9 : \u2102) = 0 := by\n  rw [\u2190 ofReal_zero, \u2190 ofReal_inv, inv_zero]\n#align complex.inv_zero Complex.inv_zero\n\nprotected theorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 := by\n  rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 ofReal_mul, mul_inv_cancel (mt normSq_eq_zero.1 h),\n    ofReal_one]\n#align complex.mul_inv_cancel Complex.mul_inv_cancel\n\n/-! ### Field instance and lemmas -/\n\n\nnoncomputable instance : Field \u2102 :=\n{ inv := Inv.inv\n  mul_inv_cancel := @Complex.mul_inv_cancel\n  inv_zero := Complex.inv_zero }\n\nsection\nset_option linter.deprecated false\n@[simp]\ntheorem I_zpow_bit0 (n : \u2124) : I ^ bit0 n = (-1) ^ n := by rw [zpow_bit0', I_mul_I]\nset_option linter.uppercaseLean3 false in\n#align complex.I_zpow_bit0 Complex.I_zpow_bit0\n\n@[simp]\ntheorem I_zpow_bit1 (n : \u2124) : I ^ bit1 n = (-1) ^ n * I := by rw [zpow_bit1', I_mul_I]\nset_option linter.uppercaseLean3 false in\n#align complex.I_zpow_bit1 Complex.I_zpow_bit1\n\nend\n\ntheorem div_re (z w : \u2102) : (z / w).re = z.re * w.re / normSq w + z.im * w.im / normSq w := by\n  simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]\n#align complex.div_re Complex.div_re\n\ntheorem div_im (z w : \u2102) : (z / w).im = z.im * w.re / normSq w - z.re * w.im / normSq w := by\n  simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]\n#align complex.div_im Complex.div_im\n\ntheorem conj_inv (x : \u2102) : conj x\u207b\u00b9 = (conj x)\u207b\u00b9 :=\n  star_inv' _\n#align complex.conj_inv Complex.conj_inv\n\n@[simp, norm_cast]\ntheorem ofReal_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\n  map_div\u2080 ofReal r s\n#align complex.of_real_div Complex.ofReal_div\n\n@[simp, norm_cast]\ntheorem ofReal_zpow (r : \u211d) (n : \u2124) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n :=\n  map_zpow\u2080 ofReal r n\n#align complex.of_real_zpow Complex.ofReal_zpow\n\n@[simp]\ntheorem div_I (z : \u2102) : z / I = -(z * I) :=\n  (div_eq_iff_mul_eq I_ne_zero).2 <| by simp [mul_assoc]\nset_option linter.uppercaseLean3 false in\n#align complex.div_I Complex.div_I\n\n@[simp]\ntheorem inv_I : I\u207b\u00b9 = -I := by\n  rw [inv_eq_one_div, div_I, one_mul]\nset_option linter.uppercaseLean3 false in\n#align complex.inv_I Complex.inv_I\n\n-- @[simp]\n/- Porting note: `simp` attribute removed as linter reports this can be proved\nby `simp only [@map_inv\u2080]` -/\ntheorem normSq_inv (z : \u2102) : normSq z\u207b\u00b9 = (normSq z)\u207b\u00b9 :=\n  map_inv\u2080 normSq z\n#align complex.norm_sq_inv Complex.normSq_inv\n\n-- @[simp]\n/- Porting note: `simp` attribute removed as linter reports this can be proved\nby `simp only [@map_div\u2080]` -/\ntheorem normSq_div (z w : \u2102) : normSq (z / w) = normSq z / normSq w :=\n  map_div\u2080 normSq z w\n#align complex.norm_sq_div Complex.normSq_div\n\n/-! ### Cast lemmas -/\n\n\n@[simp, norm_cast]\ntheorem ofReal_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\n  map_natCast ofReal n\n#align complex.of_real_nat_cast Complex.ofReal_nat_cast\n\n@[simp, norm_cast]\ntheorem nat_cast_re (n : \u2115) : (n : \u2102).re = n := by rw [\u2190 ofReal_nat_cast, ofReal_re]\n#align complex.nat_cast_re Complex.nat_cast_re\n\n@[simp, norm_cast]\ntheorem nat_cast_im (n : \u2115) : (n : \u2102).im = 0 := by rw [\u2190 ofReal_nat_cast, ofReal_im]\n#align complex.nat_cast_im Complex.nat_cast_im\n\n@[simp, norm_cast]\ntheorem ofReal_int_cast (n : \u2124) : ((n : \u211d) : \u2102) = n :=\n  map_intCast ofReal n\n#align complex.of_real_int_cast Complex.ofReal_int_cast\n\n@[simp, norm_cast]\ntheorem int_cast_re (n : \u2124) : (n : \u2102).re = n := by rw [\u2190 ofReal_int_cast, ofReal_re]\n#align complex.int_cast_re Complex.int_cast_re\n\n@[simp, norm_cast]\ntheorem int_cast_im (n : \u2124) : (n : \u2102).im = 0 := by rw [\u2190 ofReal_int_cast, ofReal_im]\n#align complex.int_cast_im Complex.int_cast_im\n\n@[simp, norm_cast]\ntheorem ofReal_rat_cast (n : \u211a) : ((n : \u211d) : \u2102) = (n : \u2102) :=\n  map_ratCast ofReal n\n#align complex.of_real_rat_cast Complex.ofReal_rat_cast\n\n-- Porting note: removed `norm_cast` attribute because the RHS can't start with `\u2191`\n@[simp]\ntheorem rat_cast_re (q : \u211a) : (q : \u2102).re = (q : \u2102) := by\n rw [\u2190 ofReal_rat_cast, ofReal_re]\n#align complex.rat_cast_re Complex.rat_cast_re\n\n-- Porting note: removed `norm_cast` attribute because the RHS can't start with `\u2191`\n@[simp]\ntheorem rat_cast_im (q : \u211a) : (q : \u2102).im = 0 := by\n rw [\u2190 ofReal_rat_cast, ofReal_im]\n#align complex.rat_cast_im Complex.rat_cast_im\n\n/-! ### Characteristic zero -/\n\n\ninstance charZero : CharZero \u2102 :=\n  charZero_of_inj_zero fun n h => by\n    rwa [\u2190 ofReal_nat_cast, ofReal_eq_zero, Nat.cast_eq_zero] at h\n#align complex.char_zero_complex Complex.charZero\n\n/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 := by\n  have : (\u2191(\u21912 : \u211d) : \u2102)  = (2 : \u2102) := by rfl\n  simp only [add_conj, ofReal_mul, ofReal_one, ofReal_bit0, this,\n    mul_div_cancel_left (z.re : \u2102) two_ne_zero]\n#align complex.re_eq_add_conj Complex.re_eq_add_conj\n\n/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/\ntheorem im_eq_sub_conj (z : \u2102) : (z.im : \u2102) = (z - conj z) / (2 * I) := by\n  have : (\u21912 : \u211d ) * I = 2 * I := by rfl\n  simp only [sub_conj, ofReal_mul, ofReal_one, ofReal_bit0, mul_right_comm, this,\n    mul_div_cancel_left _ (mul_ne_zero two_ne_zero I_ne_zero : 2 * I \u2260 0)]\n#align complex.im_eq_sub_conj Complex.im_eq_sub_conj\n\n/-! ### Absolute value -/\n\n\nnamespace AbsTheory\n\n-- We develop enough theory to bundle `abs` into an `AbsoluteValue` before making things public;\n-- this is so there's not two versions of it hanging around.\nlocal notation \"abs\" z => Real.sqrt (normSq z)\n\nprivate theorem mul_self_abs (z : \u2102) : ((abs z) * abs z) = normSq z :=\n  Real.mul_self_sqrt (normSq_nonneg _)\n\nprivate theorem abs_nonneg' (z : \u2102) : 0 \u2264 abs z :=\n  Real.sqrt_nonneg _\n\ntheorem abs_conj (z : \u2102) : (abs conj z) = abs z := by simp\n#align complex.abs_theory.abs_conj Complex.AbsTheory.abs_conj\n\nprivate theorem abs_re_le_abs (z : \u2102) : |z.re| \u2264 abs z := by\n  rw [mul_self_le_mul_self_iff (abs_nonneg z.re) (abs_nonneg' _), abs_mul_abs_self, mul_self_abs]\n  apply re_sq_le_normSq\n\nprivate theorem re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n  (abs_le.1 (abs_re_le_abs _)).2\n\nprivate theorem abs_mul (z w : \u2102) : (abs z * w) = (abs z) * abs w := by\n  rw [normSq_mul, Real.sqrt_mul (normSq_nonneg _)]\n\nprivate theorem abs_add (z w : \u2102) : (abs z + w) \u2264 (abs z) + abs w :=\n  (mul_self_le_mul_self_iff (abs_nonneg' (z + w)) (add_nonneg (abs_nonneg' z) (abs_nonneg' w))).2 <|\n    by\n    rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs, add_right_comm, normSq_add,\n      add_le_add_iff_left, mul_assoc, mul_le_mul_left (zero_lt_two' \u211d), \u2190\n      Real.sqrt_mul <| normSq_nonneg z, \u2190 normSq_conj w, \u2190 map_mul]\n    exact re_le_abs (z * conj w)\n\n/-- The complex absolute value function, defined as the square root of the norm squared. -/\nnoncomputable def _root_.Complex.abs : AbsoluteValue \u2102 \u211d where\n  toFun x := abs x\n  map_mul' := abs_mul\n  nonneg' := abs_nonneg'\n  eq_zero' _ := (Real.sqrt_eq_zero <| normSq_nonneg _).trans normSq_eq_zero\n  add_le' := abs_add\n#align complex.abs Complex.abs\n\nend AbsTheory\n\ntheorem abs_def : (Complex.abs : \u2102 \u2192 \u211d) = fun z => (normSq z).sqrt :=\n  rfl\n#align complex.abs_def Complex.abs_def\n\ntheorem abs_apply {z : \u2102} : Complex.abs z = (normSq z).sqrt :=\n  rfl\n#align complex.abs_apply Complex.abs_apply\n\n@[simp, norm_cast]\ntheorem abs_ofReal (r : \u211d) : Complex.abs r = |r| := by\n  simp [Complex.abs, normSq_ofReal, Real.sqrt_mul_self_eq_abs]\n#align complex.abs_of_real Complex.abs_ofReal\n\nnonrec theorem abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : Complex.abs r = r :=\n  (Complex.abs_ofReal _).trans (abs_of_nonneg h)\n#align complex.abs_of_nonneg Complex.abs_of_nonneg\n\ntheorem abs_of_nat (n : \u2115) : Complex.abs n = n :=\n  calc\n    Complex.abs n = Complex.abs (n : \u211d) := by rw [ofReal_nat_cast]\n    _ = _ := Complex.abs_of_nonneg (Nat.cast_nonneg n)\n\n#align complex.abs_of_nat Complex.abs_of_nat\n\ntheorem mul_self_abs (z : \u2102) : Complex.abs z * Complex.abs z = normSq z :=\n  Real.mul_self_sqrt (normSq_nonneg _)\n#align complex.mul_self_abs Complex.mul_self_abs\n\ntheorem sq_abs (z : \u2102) : Complex.abs z ^ 2 = normSq z :=\n  Real.sq_sqrt (normSq_nonneg _)\n#align complex.sq_abs Complex.sq_abs\n\n@[simp]\ntheorem sq_abs_sub_sq_re (z : \u2102) : Complex.abs z ^ 2 - z.re ^ 2 = z.im ^ 2 := by\n  rw [sq_abs, normSq_apply, \u2190 sq, \u2190 sq, add_sub_cancel']\n#align complex.sq_abs_sub_sq_re Complex.sq_abs_sub_sq_re\n\n@[simp]\ntheorem sq_abs_sub_sq_im (z : \u2102) : Complex.abs z ^ 2 - z.im ^ 2 = z.re ^ 2 := by\n  rw [\u2190 sq_abs_sub_sq_re, sub_sub_cancel]\n#align complex.sq_abs_sub_sq_im Complex.sq_abs_sub_sq_im\n\n@[simp]\ntheorem abs_I : Complex.abs I = 1 := by simp [Complex.abs]\nset_option linter.uppercaseLean3 false in\n#align complex.abs_I Complex.abs_I\n\n@[simp]\ntheorem abs_two : Complex.abs 2 = 2 :=\n  calc\n    Complex.abs 2 = Complex.abs (2 : \u211d) := by rfl\n    _ = (2 : \u211d) := Complex.abs_of_nonneg (by norm_num)\n#align complex.abs_two Complex.abs_two\n\n@[simp]\ntheorem range_abs : range Complex.abs = Ici 0 :=\n  Subset.antisymm\n    (by simp only [range_subset_iff, Ici, mem_setOf_eq, map_nonneg, forall_const])\n    (fun x hx => \u27e8x, Complex.abs_of_nonneg hx\u27e9)\n#align complex.range_abs Complex.range_abs\n\n@[simp]\ntheorem abs_conj (z : \u2102) : Complex.abs (conj z) = Complex.abs z :=\n  AbsTheory.abs_conj z\n#align complex.abs_conj Complex.abs_conj\n\n@[simp]\ntheorem abs_prod {\u03b9 : Type _} (s : Finset \u03b9) (f : \u03b9 \u2192 \u2102) :\n    Complex.abs (s.prod f) = s.prod fun I => Complex.abs (f I) :=\n  map_prod Complex.abs _ _\n#align complex.abs_prod Complex.abs_prod\n\n-- @[simp]\n/- Porting note: `simp` attribute removed as linter reports this can be proved\nby `simp only [@map_pow]` -/\ntheorem abs_pow (z : \u2102) (n : \u2115) : Complex.abs (z ^ n) = Complex.abs z ^ n :=\n  map_pow Complex.abs z n\n#align complex.abs_pow Complex.abs_pow\n\n-- @[simp]\n/- Porting note: `simp` attribute removed as linter reports this can be proved\nby `simp only [@map_zpow\u2080]` -/\ntheorem abs_zpow (z : \u2102) (n : \u2124) : Complex.abs (z ^ n) = Complex.abs z ^ n :=\n  map_zpow\u2080 Complex.abs z n\n#align complex.abs_zpow Complex.abs_zpow\n\ntheorem abs_re_le_abs (z : \u2102) : |z.re| \u2264 Complex.abs z :=\n  Real.abs_le_sqrt <| by\n    rw [normSq_apply, \u2190 sq]\n    exact le_add_of_nonneg_right (mul_self_nonneg _)\n#align complex.abs_re_le_abs Complex.abs_re_le_abs\n\ntheorem abs_im_le_abs (z : \u2102) : |z.im| \u2264 Complex.abs z :=\n  Real.abs_le_sqrt <| by\n    rw [normSq_apply, \u2190 sq, \u2190 sq]\n    exact le_add_of_nonneg_left (sq_nonneg _)\n#align complex.abs_im_le_abs Complex.abs_im_le_abs\n\ntheorem re_le_abs (z : \u2102) : z.re \u2264 Complex.abs z :=\n  (abs_le.1 (abs_re_le_abs _)).2\n#align complex.re_le_abs Complex.re_le_abs\n\ntheorem im_le_abs (z : \u2102) : z.im \u2264 Complex.abs z :=\n  (abs_le.1 (abs_im_le_abs _)).2\n#align complex.im_le_abs Complex.im_le_abs\n\n@[simp]\ntheorem abs_re_lt_abs {z : \u2102} : |z.re| < Complex.abs z \u2194 z.im \u2260 0 := by\n  rw [Complex.abs, AbsoluteValue.coe_mk, MulHom.coe_mk, Real.lt_sqrt (abs_nonneg _), normSq_apply,\n    _root_.sq_abs, \u2190 sq, lt_add_iff_pos_right, mul_self_pos]\n#align complex.abs_re_lt_abs Complex.abs_re_lt_abs\n\n@[simp]\ntheorem abs_im_lt_abs {z : \u2102} : |z.im| < Complex.abs z \u2194 z.re \u2260 0 := by\n  simpa using @abs_re_lt_abs (z * I)\n#align complex.abs_im_lt_abs Complex.abs_im_lt_abs\n\n@[simp]\ntheorem abs_abs (z : \u2102) : |Complex.abs z| = Complex.abs z :=\n  _root_.abs_of_nonneg (AbsoluteValue.nonneg _ z)\n#align complex.abs_abs Complex.abs_abs\n\n-- Porting note: probably should be golfed\ntheorem abs_le_abs_re_add_abs_im (z : \u2102) : Complex.abs z \u2264 |z.re| + |z.im| := by\n  simpa [re_add_im] using Complex.abs.add_le z.re (z.im * I)\n#align complex.abs_le_abs_re_add_abs_im Complex.abs_le_abs_re_add_abs_im\n\n-- Porting note: added so `two_pos` in the next proof works\n-- TODO: move somewhere else\ninstance : NeZero (1 : \u211d) :=\n \u27e8by apply one_ne_zero\u27e9\n\ntheorem abs_le_sqrt_two_mul_max (z : \u2102) : Complex.abs z \u2264 Real.sqrt 2 * max (|z.re|) (|z.im|) := by\n  cases' z with x y\n  simp only [abs_apply, normSq_mk, \u2190 sq]\n  by_cases hle : |x| \u2264 |y|\n  \u00b7 calc\n      Real.sqrt (x ^ 2 + y ^ 2) \u2264 Real.sqrt (y ^ 2 + y ^ 2) :=\n        Real.sqrt_le_sqrt (add_le_add_right (sq_le_sq.2 hle) _)\n      _ = Real.sqrt 2 * max (|x|) (|y|) := by\n        rw [max_eq_right hle, \u2190 two_mul, Real.sqrt_mul two_pos.le, Real.sqrt_sq_eq_abs]\n  \u00b7 have hle' := le_of_not_le hle\n    rw [add_comm]\n    calc\n      Real.sqrt (y ^ 2 + x ^ 2) \u2264 Real.sqrt (x ^ 2 + x ^ 2) :=\n        Real.sqrt_le_sqrt (add_le_add_right (sq_le_sq.2 hle') _)\n      _ = Real.sqrt 2 * max (|x|) (|y|) := by\n        rw [max_eq_left hle', \u2190 two_mul, Real.sqrt_mul two_pos.le, Real.sqrt_sq_eq_abs]\n#align complex.abs_le_sqrt_two_mul_max Complex.abs_le_sqrt_two_mul_max\n\ntheorem abs_re_div_abs_le_one (z : \u2102) : |z.re / Complex.abs z| \u2264 1 :=\n  if hz : z = 0 then by simp [hz, zero_le_one]\n  else by simp_rw [_root_.abs_div, abs_abs,\n    div_le_iff (AbsoluteValue.pos Complex.abs hz), one_mul, abs_re_le_abs]\n#align complex.abs_re_div_abs_le_one Complex.abs_re_div_abs_le_one\n\ntheorem abs_im_div_abs_le_one (z : \u2102) : |z.im / Complex.abs z| \u2264 1 :=\n  if hz : z = 0 then by simp [hz, zero_le_one]\n  else by simp_rw [_root_.abs_div, abs_abs,\n    div_le_iff (AbsoluteValue.pos Complex.abs hz), one_mul, abs_im_le_abs]\n#align complex.abs_im_div_abs_le_one Complex.abs_im_div_abs_le_one\n\n-- Porting note: removed `norm_cast` attribute because the RHS can't start with `\u2191`\n@[simp]\ntheorem abs_cast_nat (n : \u2115) : Complex.abs (n : \u2102) = n := by\n  rw [\u2190 ofReal_nat_cast, abs_of_nonneg (Nat.cast_nonneg n)]\n#align complex.abs_cast_nat Complex.abs_cast_nat\n\n@[simp, norm_cast]\ntheorem int_cast_abs (n : \u2124) : (|\u2191n|) = Complex.abs n := by\n  rw [\u2190 ofReal_int_cast, abs_ofReal]\n#align complex.int_cast_abs Complex.int_cast_abs\n\ntheorem normSq_eq_abs (x : \u2102) : normSq x = (Complex.abs x) ^ 2 := by\n  simp [abs, sq, abs_def, Real.mul_self_sqrt (normSq_nonneg _)]\n#align complex.norm_sq_eq_abs Complex.normSq_eq_abs\n\n/-- We put a partial order on \u2102 so that `z \u2264 w` exactly if `w - z` is real and nonnegative.\nComplex numbers with different imaginary parts are incomparable.\n-/\nprotected def partialOrder : PartialOrder \u2102 where\n  le z w := z.re \u2264 w.re \u2227 z.im = w.im\n  lt z w := z.re < w.re \u2227 z.im = w.im\n  lt_iff_le_not_le z w := by\n    dsimp\n    rw [lt_iff_le_not_le]\n    tauto\n  le_refl x := \u27e8le_rfl, rfl\u27e9\n  le_trans x y z h\u2081 h\u2082 := \u27e8h\u2081.1.trans h\u2082.1, h\u2081.2.trans h\u2082.2\u27e9\n  le_antisymm z w h\u2081 h\u2082 := ext (h\u2081.1.antisymm h\u2082.1) h\u2081.2\n#align complex.partial_order Complex.partialOrder\n\nnamespace _root_.ComplexOrder\n\n-- Porting note: made section into namespace to allow scoping\nscoped[ComplexOrder] attribute [instance] Complex.partialOrder\n\nend _root_.ComplexOrder\n\nsection ComplexOrder\n\nopen ComplexOrder\n\ntheorem le_def {z w : \u2102} : z \u2264 w \u2194 z.re \u2264 w.re \u2227 z.im = w.im :=\n  Iff.rfl\n#align complex.le_def Complex.le_def\n\ntheorem lt_def {z w : \u2102} : z < w \u2194 z.re < w.re \u2227 z.im = w.im :=\n  Iff.rfl\n#align complex.lt_def Complex.lt_def\n\n\n@[simp, norm_cast]\ntheorem real_le_real {x y : \u211d} : (x : \u2102) \u2264 (y : \u2102) \u2194 x \u2264 y := by simp [le_def, ofReal']\n#align complex.real_le_real Complex.real_le_real\n\n@[simp, norm_cast]\ntheorem real_lt_real {x y : \u211d} : (x : \u2102) < (y : \u2102) \u2194 x < y := by simp [lt_def, ofReal']\n#align complex.real_lt_real Complex.real_lt_real\n\n\n@[simp, norm_cast]\ntheorem zero_le_real {x : \u211d} : (0 : \u2102) \u2264 (x : \u2102) \u2194 0 \u2264 x :=\n  real_le_real\n#align complex.zero_le_real Complex.zero_le_real\n\n@[simp, norm_cast]\ntheorem zero_lt_real {x : \u211d} : (0 : \u2102) < (x : \u2102) \u2194 0 < x :=\n  real_lt_real\n#align complex.zero_lt_real Complex.zero_lt_real\n\ntheorem not_le_iff {z w : \u2102} : \u00acz \u2264 w \u2194 w.re < z.re \u2228 z.im \u2260 w.im := by\n  rw [le_def, not_and_or, not_le]\n#align complex.not_le_iff Complex.not_le_iff\n\ntheorem not_lt_iff {z w : \u2102} : \u00acz < w \u2194 w.re \u2264 z.re \u2228 z.im \u2260 w.im := by\n  rw [lt_def, not_and_or, not_lt]\n#align complex.not_lt_iff Complex.not_lt_iff\n\ntheorem not_le_zero_iff {z : \u2102} : \u00acz \u2264 0 \u2194 0 < z.re \u2228 z.im \u2260 0 :=\n  not_le_iff\n#align complex.not_le_zero_iff Complex.not_le_zero_iff\n\ntheorem not_lt_zero_iff {z : \u2102} : \u00acz < 0 \u2194 0 \u2264 z.re \u2228 z.im \u2260 0 :=\n  not_lt_iff\n#align complex.not_lt_zero_iff Complex.not_lt_zero_iff\n\ntheorem eq_re_ofReal_le {r : \u211d} {z : \u2102} (hz : (r : \u2102) \u2264 z) : z = z.re := by\n  ext\n  rfl\n  simp only [\u2190 (Complex.le_def.1 hz).2, Complex.zero_im, Complex.ofReal_im]\n#align complex.eq_re_of_real_le Complex.eq_re_ofReal_le\n\n/-- With `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a strictly ordered ring.\n-/\nprotected def strictOrderedCommRing : StrictOrderedCommRing \u2102 :=\n{ zero_le_one := \u27e8zero_le_one, rfl\u27e9\n  add_le_add_left := fun w z h y => \u27e8add_le_add_left h.1 _, congr_arg\u2082 (\u00b7 + \u00b7) rfl h.2\u27e9\n  mul_pos := fun z w hz hw => by\n    simp [lt_def, mul_re, mul_im, \u2190 hz.2, \u2190 hw.2, mul_pos hz.1 hw.1]\n  mul_comm := by intros; ext <;> ring_nf }\n\n#align complex.strict_ordered_comm_ring Complex.strictOrderedCommRing\n\nscoped[ComplexOrder] attribute [instance] Complex.strictOrderedCommRing\n\n/-- With `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a star ordered ring.\n(That is, a star ring in which the nonnegative elements are those of the form `star z * z`.)\n-/\nprotected def starOrderedRing : StarOrderedRing \u2102 :=\n{ nonneg_iff := fun r => by\n    refine' \u27e8fun hr => \u27e8Real.sqrt r.re, _\u27e9, fun h => _\u27e9\n    \u00b7 have h\u2081 : 0 \u2264 r.re := by\n        rw [le_def] at hr\n        exact hr.1\n      have h\u2082 : r.im = 0 := by\n        rw [le_def] at hr\n        exact hr.2.symm\n      ext\n      \u00b7 simp only [ofReal_im, star_def, ofReal_re, sub_zero, conj_re, mul_re, mul_zero, \u2190\n          Real.sqrt_mul h\u2081 r.re, Real.sqrt_mul_self h\u2081]\n      \u00b7 simp only [h\u2082, add_zero, ofReal_im, star_def, zero_mul, conj_im, mul_im, mul_zero,\n          neg_zero]\n    \u00b7 obtain \u27e8s, rfl\u27e9 := h\n      simp only [\u2190 normSq_eq_conj_mul_self, normSq_nonneg, zero_le_real, star_def]\n  add_le_add_left := by intros; simp [le_def] at *; assumption }\n#align complex.star_ordered_ring Complex.starOrderedRing\n\nscoped[ComplexOrder] attribute [instance] Complex.starOrderedRing\n\nend ComplexOrder\n\n/-! ### Cauchy sequences -/\n\nlocal notation \"abs'\" => Abs.abs\n\ntheorem isCauSeq_re (f : CauSeq \u2102 Complex.abs) : IsCauSeq abs' fun n => (f n).re := fun \u03b5 \u03b50 =>\n  (f.cauchy \u03b50).imp fun i H j ij =>\n    lt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n#align complex.is_cau_seq_re Complex.isCauSeq_re\n\ntheorem isCauSeq_im (f : CauSeq \u2102 Complex.abs) : IsCauSeq abs' fun n => (f n).im := fun \u03b5 \u03b50 =>\n  (f.cauchy \u03b50).imp fun i H j ij =>\n    lt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n#align complex.is_cau_seq_im Complex.isCauSeq_im\n\n/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cauSeqRe (f : CauSeq \u2102 Complex.abs) : CauSeq \u211d abs' :=\n  \u27e8_, isCauSeq_re f\u27e9\n#align complex.cau_seq_re Complex.cauSeqRe\n\n/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cauSeqIm (f : CauSeq \u2102 Complex.abs) : CauSeq \u211d abs' :=\n  \u27e8_, isCauSeq_im f\u27e9\n#align complex.cau_seq_im Complex.cauSeqIm\n\ntheorem isCauSeq_abs {f : \u2115 \u2192 \u2102} (hf : IsCauSeq Complex.abs f) :\n  IsCauSeq abs' (Complex.abs \u2218 f) := fun \u03b5 \u03b50 =>\n  let \u27e8i, hi\u27e9 := hf \u03b5 \u03b50\n  \u27e8i, fun j hj => lt_of_le_of_lt\n    (Complex.abs.abs_abv_sub_le_abv_sub _ _) (hi j hj)\u27e9\n#align complex.is_cau_seq_abs Complex.isCauSeq_abs\n\n/-- The limit of a Cauchy sequence of complex numbers. -/\nnoncomputable def limAux (f : CauSeq \u2102 Complex.abs) : \u2102 :=\n  \u27e8CauSeq.lim (cauSeqRe f), CauSeq.lim (cauSeqIm f)\u27e9\n#align complex.lim_aux Complex.limAux\n\ntheorem equiv_limAux (f : CauSeq \u2102 Complex.abs) :\n  f \u2248 CauSeq.const Complex.abs (limAux f) := fun \u03b5 \u03b50 =>\n  (exists_forall_ge_and\n  (CauSeq.equiv_lim \u27e8_, isCauSeq_re f\u27e9 _ (half_pos \u03b50))\n        (CauSeq.equiv_lim \u27e8_, isCauSeq_im f\u27e9 _ (half_pos \u03b50))).imp\n    fun i H j ij => by\n    cases' H _ ij with H\u2081 H\u2082\n    apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _)\n    dsimp [limAux] at *\n    have := add_lt_add H\u2081 H\u2082\n    rwa [add_halves] at this\n#align complex.equiv_lim_aux Complex.equiv_limAux\n\ninstance : CauSeq.IsComplete \u2102 Complex.abs :=\n  \u27e8fun f => \u27e8limAux f, equiv_limAux f\u27e9\u27e9\n\nopen CauSeq\n\ntheorem lim_eq_lim_im_add_lim_re (f : CauSeq \u2102 Complex.abs) :\n    lim f = \u2191(lim (cauSeqRe f)) + \u2191(lim (cauSeqIm f)) * I :=\n  lim_eq_of_equiv_const <|\n    calc\n      f \u2248 _ := equiv_limAux f\n      _ = CauSeq.const Complex.abs (\u2191(lim (cauSeqRe f)) + \u2191(lim (cauSeqIm f)) * I) :=\n        CauSeq.ext fun _ =>\n          Complex.ext (by simp [limAux, cauSeqRe, ofReal']) (by simp [limAux, cauSeqIm, ofReal'])\n\n#align complex.lim_eq_lim_im_add_lim_re Complex.lim_eq_lim_im_add_lim_re\n\ntheorem lim_re (f : CauSeq \u2102 Complex.abs) : lim (cauSeqRe f) = (lim f).re := by\n  rw [lim_eq_lim_im_add_lim_re] ; simp [ofReal']\n#align complex.lim_re Complex.lim_re\n\ntheorem lim_im (f : CauSeq \u2102 Complex.abs) : lim (cauSeqIm f) = (lim f).im := by\n  rw [lim_eq_lim_im_add_lim_re] ; simp [ofReal']\n#align complex.lim_im Complex.lim_im\n\ntheorem isCauSeq_conj (f : CauSeq \u2102 Complex.abs) :\n  IsCauSeq Complex.abs fun n => conj (f n) := fun \u03b5 \u03b50 =>\n  let \u27e8i, hi\u27e9 := f.2 \u03b5 \u03b50\n  \u27e8i, fun j hj => by\n    rw [\u2190 RingHom.map_sub, abs_conj] ; exact hi j hj\u27e9\n#align complex.is_cau_seq_conj Complex.isCauSeq_conj\n\n/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/\nnoncomputable def cauSeqConj (f : CauSeq \u2102 Complex.abs) : CauSeq \u2102 Complex.abs :=\n  \u27e8_, isCauSeq_conj f\u27e9\n#align complex.cau_seq_conj Complex.cauSeqConj\n\ntheorem lim_conj (f : CauSeq \u2102 Complex.abs) : lim (cauSeqConj f) = conj (lim f) :=\n  Complex.ext (by simp [cauSeqConj, (lim_re _).symm, cauSeqRe])\n    (by simp [cauSeqConj, (lim_im _).symm, cauSeqIm, (lim_neg _).symm] ; rfl)\n#align complex.lim_conj Complex.lim_conj\n\n/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cauSeqAbs (f : CauSeq \u2102 Complex.abs) : CauSeq \u211d abs' :=\n  \u27e8_, isCauSeq_abs f.2\u27e9\n#align complex.cau_seq_abs Complex.cauSeqAbs\n\ntheorem lim_abs (f : CauSeq \u2102 Complex.abs) : lim (cauSeqAbs f) = Complex.abs (lim f) :=\n  lim_eq_of_equiv_const fun \u03b5 \u03b50 =>\n    let \u27e8i, hi\u27e9 := equiv_lim f \u03b5 \u03b50\n    \u27e8i, fun j hj => lt_of_le_of_lt (Complex.abs.abs_abv_sub_le_abv_sub _ _) (hi j hj)\u27e9\n#align complex.lim_abs Complex.lim_abs\n\nvariable {\u03b1 : Type _} (s : Finset \u03b1)\n\n@[simp, norm_cast]\ntheorem ofReal_prod (f : \u03b1 \u2192 \u211d) : ((\u220f i in s, f i : \u211d) : \u2102) = \u220f i in s, (f i : \u2102) :=\n  map_prod ofReal _ _\n#align complex.of_real_prod Complex.ofReal_prod\n\n@[simp, norm_cast]\ntheorem ofReal_sum (f : \u03b1 \u2192 \u211d) : ((\u2211 i in s, f i : \u211d) : \u2102) = \u2211 i in s, (f i : \u2102) :=\n  map_sum ofReal _ _\n#align complex.of_real_sum Complex.ofReal_sum\n\n@[simp]\ntheorem re_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).re = \u2211 i in s, (f i).re :=\n  reAddGroupHom.map_sum f s\n#align complex.re_sum Complex.re_sum\n\n@[simp]\ntheorem im_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).im = \u2211 i in s, (f i).im :=\n  imAddGroupHom.map_sum f s\n#align complex.im_sum Complex.im_sum\n\nend Complex\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Complex/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7421616122661961}}
{"text": "import tactic\nopen_locale classical\n-- tells Lean to allow the law of excluded middle\n\nvariables P Q R : Prop\n\n/--------------------------------------------------------------------------\n``push_neg``\n\n  Simplifies negations in the target, if possible. \n  If ``hp : P`` is a hypothesis, then \n  ``push_neg at hp,`` simplyfies the negations at ``hp``, if possible.\n--------------------------------------------------------------------------/\n\ntheorem ex1 : \u00ac \u00ac P \u2192 P := \nbegin \n  push_neg,\n  intro hp,\n  exact hp,\nend\n\ntheorem ex2 : \u00ac \u00ac P \u2192 P := \nbegin \n  intro hp,\n  push_neg at hp,\n  exact hp,\nend\n\n/--------------------------------------------------------------------------\n``by_contradiction``\n\n  If the current target is ``P``,\n  then ``by_contradiction hnp,`` changes the target to  ``false``\n  and adds a hypothesis ``hnp : \u00acP``.\n--------------------------------------------------------------------------/\n\ntheorem ex3 : P \u2228 \u00ac P := \nbegin \n  by_contradiction h,\n  push_neg at h,\n  cases h,\n  apply h_left,\n  exact h_right,\nend\n\n/--------------------------------------------------------------------------\n``by_cases``\n\n  If ``P`` is a proposition,\n  then ``by_cases P,`` creates two hypothesis ``h : P`` and ``h : \u00acP``.\n\nThis is the law of excluded middle.\n--------------------------------------------------------------------------/\n\ntheorem ex4 : P \u2228 \u00ac P := \nbegin \n  by_cases P,\n  left, \n  exact h,\n  right, \n  exact h,\nend\n\n/--------------------------------------------------------------------------\nDelete the ``sorry,`` below and replace them with valid proofs.\n--------------------------------------------------------------------------/\n\ntheorem de_morgan1 : \u00acP \u2227 \u00acQ \u2192 \u00ac(P \u2228 Q) := \nbegin \n  sorry,\nend\n\ntheorem de_morgan1_converse : \u00ac(P \u2228 Q) \u2192 \u00acP \u2227 \u00acQ := \nbegin \n  sorry,\nend\n\ntheorem de_morgan2 : \u00acP \u2228 \u00acQ \u2192 \u00ac(P \u2227 Q) := \nbegin \n  sorry,\nend\n\ntheorem de_morgan2_converse : \u00ac(P \u2227 Q) \u2192 (\u00acP \u2228 \u00acQ):= \nbegin \n  sorry,\nend\n\ntheorem contrapositive_converse : (\u00acQ \u2192 \u00acP) \u2192 (P \u2192 Q) :=\nbegin\n  sorry,\nend", "meta": {"author": "apurvanakade", "repo": "uwo2021-CUMC", "sha": "0be9402011feda35e510725449686c0af3c3761e", "save_path": "github-repos/lean/apurvanakade-uwo2021-CUMC", "path": "github-repos/lean/apurvanakade-uwo2021-CUMC/uwo2021-CUMC-0be9402011feda35e510725449686c0af3c3761e/src/law_of_excluded_middle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7421352873832003}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\n\nimport algebra.char_p.basic\nimport data.polynomial.algebra_map\nimport data.mv_polynomial.variables\nimport linear_algebra.finsupp_vector_space\n\n/-!\n# Multivariate polynomials over commutative rings\n\nThis file contains basic facts about multivariate polynomials over commutative rings, for example\nthat the monomials form a basis.\n\n## Main definitions\n\n* `restrict_total_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` of total degree at most `m`.\n* `restrict_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` such that the degree in each individual variable is at most `m`.\n\n## Main statements\n\n* The multivariate polynomial ring over a commutative ring of positive characteristic has positive\n  characteristic.\n* `basis_monomials`: shows that the monomials form a basis of the vector space of multivariate\n  polynomials.\n\n## TODO\n\nGeneralise to noncommutative (semi)rings\n-/\n\nnoncomputable theory\n\nopen_locale classical\n\nopen set linear_map submodule\nopen_locale big_operators polynomial\n\nuniverses u v\nvariables (\u03c3 : Type u) (R : Type v) [comm_ring R] (p m : \u2115)\n\nnamespace mv_polynomial\n\nsection char_p\n\ninstance [char_p R p] : char_p (mv_polynomial \u03c3 R) p :=\n{ cast_eq_zero_iff := \u03bb n, by rw [\u2190 C_eq_coe_nat, \u2190 C_0, C_inj, char_p.cast_eq_zero_iff R p] }\n\nend char_p\n\nsection homomorphism\n\nlemma map_range_eq_map {R S : Type*} [comm_ring R] [comm_ring S] (p : mv_polynomial \u03c3 R)\n  (f : R \u2192+* S) :\n  finsupp.map_range f f.map_zero p = map f p :=\nbegin\n  -- `finsupp.map_range_finset_sum` expects `f : R \u2192+ S`\n  change finsupp.map_range (f : R \u2192+ S) (f : R \u2192+ S).map_zero p = map f p,\n  rw [p.as_sum, finsupp.map_range_finset_sum, (map f).map_sum],\n  refine finset.sum_congr rfl (assume n _, _),\n  rw [map_monomial, \u2190 single_eq_monomial, finsupp.map_range_single, single_eq_monomial,\n    f.coe_add_monoid_hom],\nend\n\nend homomorphism\n\nsection degree\n\n/-- The submodule of polynomials of total degree less than or equal to `m`.-/\ndef restrict_total_degree : submodule R (mv_polynomial \u03c3 R) :=\nfinsupp.supported _ _ {n | n.sum (\u03bbn e, e) \u2264 m }\n\n/-- The submodule of polynomials such that the degree with respect to each individual variable is\nless than or equal to `m`.-/\ndef restrict_degree (m : \u2115) : submodule R (mv_polynomial \u03c3 R) :=\nfinsupp.supported _ _ {n | \u2200i, n i \u2264 m }\n\nvariable {R}\n\nlemma mem_restrict_total_degree (p : mv_polynomial \u03c3 R) :\n  p \u2208 restrict_total_degree \u03c3 R m \u2194 p.total_degree \u2264 m :=\nbegin\n  rw [total_degree, finset.sup_le_iff],\n  refl\nend\n\nlemma mem_restrict_degree (p : mv_polynomial \u03c3 R) (n : \u2115) :\n  p \u2208 restrict_degree \u03c3 R n \u2194 (\u2200s \u2208 p.support, \u2200i, (s : \u03c3 \u2192\u2080 \u2115) i \u2264 n) :=\nbegin\n  rw [restrict_degree, finsupp.mem_supported],\n  refl\nend\n\nlemma mem_restrict_degree_iff_sup (p : mv_polynomial \u03c3 R) (n : \u2115) :\n  p \u2208 restrict_degree \u03c3 R n \u2194 \u2200i, p.degrees.count i \u2264 n :=\nbegin\n  simp only [mem_restrict_degree, degrees, multiset.count_finset_sup, finsupp.count_to_multiset,\n    finset.sup_le_iff],\n  exact \u27e8assume h n s hs, h s hs n, assume h s hs n, h n s hs\u27e9\nend\n\nvariables (\u03c3 R)\n\n/-- The monomials form a basis on `mv_polynomial \u03c3 R`. -/\ndef basis_monomials : basis (\u03c3 \u2192\u2080 \u2115) R (mv_polynomial \u03c3 R) := finsupp.basis_single_one\n\n@[simp] lemma coe_basis_monomials :\n  (basis_monomials \u03c3 R : (\u03c3 \u2192\u2080 \u2115) \u2192 mv_polynomial \u03c3 R) = \u03bb s, monomial s 1 :=\nrfl\n\nlemma linear_independent_X : linear_independent R (X : \u03c3 \u2192 mv_polynomial \u03c3 R) :=\n(basis_monomials \u03c3 R).linear_independent.comp\n  (\u03bb s : \u03c3, finsupp.single s 1) (finsupp.single_left_injective one_ne_zero)\n\nend degree\n\nend mv_polynomial\n\n\n/- this is here to avoid import cycle issues -/\nnamespace polynomial\n\n/-- The monomials form a basis on `R[X]`. -/\nnoncomputable def basis_monomials : basis \u2115 R R[X] :=\nbasis.of_repr (to_finsupp_iso_alg R).to_linear_equiv\n\n@[simp] lemma coe_basis_monomials :\n  (basis_monomials R : \u2115 \u2192 R[X]) = \u03bb s, monomial s 1 :=\n_root_.funext $ \u03bb n, of_finsupp_single _ _\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/mv_polynomial/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7421352851204909}}
{"text": "-- IMO 1962 Q4\n-- Resolver la ecuaci\u00f3n cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1`\n\nimport analysis.special_functions.trigonometric\n\nopen real\nopen_locale real\nnoncomputable theory\n\ndef problema (x : \u211d) : Prop :=\ncos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1\n\ndef funAuxiliar (x : \u211d) : \u211d :=\ncos x * (cos x ^ 2 - 1/2) * cos (3 * x)\n\nlemma Igualdad {x : \u211d} :\n  (cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 - 1) / 4 = funAuxiliar x :=\nbegin\n  rw funAuxiliar,\n  rw real.cos_two_mul,\n  rw cos_three_mul,\n  ring_nf,\nend\n\nlemma Equivalencia\n  {x : \u211d}\n  : problema x \u2194 funAuxiliar x = 0 :=\nbegin\n  split,\n  { intro h1,\n    rw problema at h1,\n    rw \u2190 Igualdad,\n    rw div_eq_zero_iff,\n    norm_num,\n    rw sub_eq_zero,\n    exact h1, },\n  { intro h2,\n    rw problema,\n    rw \u2190 Igualdad at h2,\n    rw div_eq_zero_iff at h2,\n    norm_num at h2,\n    rw sub_eq_zero at h2,\n    exact h2, },\nend\n\nlemma CasosSolucion\n  {x : \u211d}\n  : funAuxiliar x = 0 \u2194 cos x ^ 2 = 1/2 \u2228 cos (3 * x) = 0 :=\nbegin\n  rw funAuxiliar,\n  rw mul_assoc,\n  rw mul_eq_zero,\n  rw mul_eq_zero,\n  rw sub_eq_zero,\n  split,\n  { intro h1,\n    cases h1 with h11 h12,\n    right,\n    rw cos_three_mul,\n    rw h11,\n    ring,\n    exact h12,},\n  { intro h2,\n    right,\n    exact h2,},\nend\n\nlemma SolucionCosenoCuadrado\n  {x : \u211d}\n  : cos x ^ 2 = 1/2 \u2194 \u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 4 :=\nbegin\n  rw cos_sq,\n  rw add_right_eq_self,\n  rw div_eq_zero_iff,\n  norm_num,\n  split,\n  { intro h1,\n    rw cos_eq_zero_iff at h1,\n    cases h1 with k1 hk1,\n    use k1,\n    linarith, },\n  { intro h2,\n    cases h2 with k2 hk2,\n    rw cos_eq_zero_iff,\n    use k2,\n    linarith,},\nend\n\nlemma SolucionCosenoTriple\n  {x : \u211d}\n  : cos (3 * x) = 0 \u2194 \u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 6 :=\nbegin\n  rw cos_eq_zero_iff,\n  split,\n  { intro h1,\n    cases h1 with k1 hk1,\n    use k1,\n    linarith,},\n  { intro h2,\n    cases h2 with k2 hk2,\n    use k2,\n    linarith,},\nend\n\ndef Solucion : set \u211d :=\n{x : \u211d | \u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 4 \u2228 x = (2 * k + 1) * \u03c0 / 6}\n\ntheorem imo1962_q4\n  {x : \u211d}\n  : problema x \u2194 x \u2208 Solucion :=\nbegin\n  rw Equivalencia,\n  rw CasosSolucion,\n  rw SolucionCosenoTriple,\n  rw SolucionCosenoCuadrado,\n  rw Solucion,\n  exact exists_or_distrib.symm,\nend\n", "meta": {"author": "saradiazr11", "repo": "IMO_en_Lean", "sha": "d8fb219af4d0c1afaecb36556ac5ecf8dd03b453", "save_path": "github-repos/lean/saradiazr11-IMO_en_Lean", "path": "github-repos/lean/saradiazr11-IMO_en_Lean/IMO_en_Lean-d8fb219af4d0c1afaecb36556ac5ecf8dd03b453/src/IMO/imo1962_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7421352821650384}}
{"text": "-- Base-level definition of naturals\ninductive mynat : Type\n    | zero : mynat\n    | succ : mynat -> mynat\n\nopen mynat\n\n-------------------------------------------------------------------------------\n--                                Addition                                   --\n-------------------------------------------------------------------------------\n\n-- Addition on naturals\ndef add : mynat -> mynat -> mynat\n    | m zero     := m\n    | m (succ n) := succ (add m n)\n\n-------------------------\n-- Prerequisite Proofs --\n\n-- Proving that zero is the additive identity\nlemma mynat_add_zero (n : mynat) : (add n zero) = n :=\n    begin\n        rw add,\n    end\n\n-- Proving that zero is the additive identity, even in reverse order.\nlemma mynat_zero_add (n : mynat) :\n    (add zero n) = n :=\n    begin\n        induction n with d hd,\n\n        -- Base case\n        rw mynat_add_zero,\n\n        -- Inductive case\n        rw add,\n        rw hd,\n    end\n\nlemma mynat_add_succ (x y : mynat) :\n    succ (add x y) = add (succ x) y :=\n    begin\n        induction y with d hd,\n\n        -- Base case\n        rw [mynat_add_zero, mynat_add_zero],\n\n        -- Inductive case\n        rw add,\n        rw hd,\n        rw add,\n    end\n\n-------------------------\n-- Commutativity Proof --\nlemma add_commutativity (x y : mynat) :\n    add x y = add y x :=\n    begin\n        induction y with d hd,\n\n        -- Base case\n        rw mynat_add_zero,\n        rw mynat_zero_add,\n\n        -- Inductive case\n        rw add,\n        rw <- mynat_add_succ,\n        rw hd,\n    end\n\n-------------------------\n-- Associativity Proof --\nlemma add_associativity (x y z : mynat) :\n    add x (add y z) = add (add x y) z :=\n    begin\n        induction x with d hd,\n\n        -- Base case\n        rw [mynat_zero_add, mynat_zero_add],\n\n        -- Inductive case\n        rw <- mynat_add_succ,\n        rw hd,\n        rw <- mynat_add_succ,\n        rw <- mynat_add_succ,\n    end\n\n-------------------------------------------------------------------------------\n--                              Multiplication                               --\n-------------------------------------------------------------------------------\n\n-- Multiplication on naturals\ndef mul : mynat -> mynat -> mynat\n    | m zero     := zero\n    | m (succ n) := add m (mul m n)\n\n-------------------------\n-- Prerequisite Proofs --\n\nlemma mynat_zero_mul (n : mynat) :\n    mul zero n = zero :=\n    begin\n        induction n with d hd,\n\n        -- Base case\n        rw mul,\n\n        -- Inductive case\n        rw mul,\n        rw hd,\n        rw add,\n    end\n\nlemma mynat_mul_succ (x y : mynat) :\n    mul (succ x) y = add y (mul x y) :=\n    begin\n        -- this is a lie\n        sorry,\n    end\n\n-------------------------\n-- Commutativity Proof --\nlemma mul_commutativity (x y : mynat) :\n    mul x y = mul y x :=\n    begin\n        induction y with d hd,\n\n        -- Base case\n        rw mul,\n        rw mynat_zero_mul,\n\n        -- Inductive case\n        rw mul,\n        rw mynat_mul_succ,\n        rw hd,\n    end\n\n-------------------------\n-- Associativity Proof --\nlemma mul_associativity (x y z : mynat) :\n    mul x (mul y z) = mul (mul x y) z :=\n    begin\n        induction z with d hd,\n\n        -- Base Case\n        sorry,\n\n        -- Inductive Case\n        sorry,\n    end\n", "meta": {"author": "crockeo", "repo": "math-exercises", "sha": "cf9150ef9e025f1b7929ba070a783e7a71f24f31", "save_path": "github-repos/lean/crockeo-math-exercises", "path": "github-repos/lean/crockeo-math-exercises/math-exercises-cf9150ef9e025f1b7929ba070a783e7a71f24f31/number-game/nats.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947163538936, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7421124691428261}}
{"text": "import MyNat.Definition\nimport AdditionWorld.Level4 -- add_comm\nimport AdvancedAdditionWorld.Level5 -- add_right_cancel\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Advanced Addition World\n\n## Level 7: `add_right_cancel_iff`\n\nIt's sometimes convenient to have the \"if and only if\" version\nof theorems like `add_right_cancel`. Remember that you can use `constructor`\nto split an `\u2194` goal into the `\u2192` goal and the `\u2190` goal.\n\n## Pro tip:\n\nNotice `exact add_right_cancel _ _ _` means \"let Lean figure out the missing inputs\"\nso we don't have to spell it out like we did in Level 6.\n\n## Theorem\nFor all naturals `a`, `b` and `t`, `a + t = b + t \u2194 a = b.`\n-/\ntheorem add_right_cancel_iff (t a b : MyNat) :  a + t = b + t \u2194 a = b := by\n  constructor\n  exact add_right_cancel _ _ _\n  intro h\n  rw [h]\n\n/-!\nNext up [Level 8](./Level8.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedAdditionWorld/Level7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947148047777, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7421124536815114}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# Prove that for every positive integer n the number 3(1^5 +2^5 +...+n^5)\n# is divisible by 1^3+2^3+...+n^3\n\nThis is question 9 in Sierpinski's book\n\n-/\n\nopen_locale big_operators\n\nopen finset\n\nexample (n : \u2115) : (\u2211 i in range n, i^3) \u2223 (3 * \u2211 i in range n, i^5) :=\nbegin\n  sorry,\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section15number_theory/sheet7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545304202038, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7420849752091351}}
{"text": "variables (real : Type) [ordered_ring real]\nvariables (log exp : real \u2192 real)\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\neq.symm $ calc\n  log x + log y = log (exp(log x + log y)): by rw [log_exp_eq]\n  ... = log(exp(log x) * exp(log y)): by rw [exp_add]\n  ... = log(x * y): by rw [exp_log_eq hx, exp_log_eq hy]", "meta": {"author": "ntabee", "repo": "lean-exercise", "sha": "5b23b9be3d361fff5e981d5be3a0a1175504b9f6", "save_path": "github-repos/lean/ntabee-lean-exercise", "path": "github-repos/lean/ntabee-lean-exercise/lean-exercise-5b23b9be3d361fff5e981d5be3a0a1175504b9f6/4.6.6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541528387691, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.7419586731497784}}
{"text": "-- Distributiva_de_la_interseccion_respecto_de_la_union_general.lean\n-- Distributiva de la intersecci\u00f3n respecto de la uni\u00f3n general\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 28-abril-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport data.set.lattice\nimport tactic\n\nopen set\n\nvariable {\u03b1 : Type}\nvariable s : set \u03b1\nvariable A : \u2115 \u2192 set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    rw mem_Union,\n    cases h with xs xUAi,\n    rw mem_Union at xUAi,\n    cases xUAi with i xAi,\n    use i,\n    split,\n    { exact xAi, },\n    { exact xs, }},\n  { intro h,\n    rw mem_Union at h,\n    cases h with i hi,\n    cases hi with xAi xs,\n    split,\n    { exact xs, },\n    { rw mem_Union,\n      use i,\n      exact xAi, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  simp,\n  split,\n  { rintros \u27e8xs, \u27e8i, xAi\u27e9\u27e9,\n    exact \u27e8\u27e8i, xAi\u27e9, xs\u27e9, },\n  { rintros \u27e8\u27e8i, xAi\u27e9, xs\u27e9,\n    exact \u27e8xs, \u27e8i, xAi\u27e9\u27e9 },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  finish,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nby ext; finish\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nby finish [ext_iff]\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nby tidy\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Distributiva_de_la_interseccion_respecto_de_la_union_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7419076576516512}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth, Yury Kudryashov\n-/\nimport topology.order.basic\n\n/-!\n# Bounded monotone sequences converge\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove a few theorems of the form \u201cif the range of a monotone function `f : \u03b9 \u2192 \u03b1`\nadmits a least upper bound `a`, then `f x` tends to `a` as `x \u2192 \u221e`\u201d, as well as version of this\nstatement for (conditionally) complete lattices that use `\u2a06 x, f x` instead of `is_lub`.\n\nThese theorems work for linear orders with order topologies as well as their products (both in terms\nof `prod` and in terms of function types). In order to reduce code duplication, we introduce two\ntypeclasses (one for the property formulated above and one for the dual property), prove theorems\nassuming one of these typeclasses, and provide instances for linear orders and their products.\n\nWe also prove some \"inverse\" results: if `f n` is a monotone sequence and `a` is its limit,\nthen `f n \u2264 a` for all `n`.\n\n## Tags\n\nmonotone convergence\n-/\n\nopen filter set function\nopen_locale filter topology classical\n\nvariables {\u03b1 \u03b2 : Type*}\n\n/-- We say that `\u03b1` is a `Sup_convergence_class` if the following holds. Let `f : \u03b9 \u2192 \u03b1` be a\nmonotone function, let `a : \u03b1` be a least upper bound of `set.range f`. Then `f x` tends to `\ud835\udcdd a` as\n`x \u2192 \u221e` (formally, at the filter `filter.at_top`). We require this for `\u03b9 = (s : set \u03b1)`, `f = coe`\nin the definition, then prove it for any `f` in `tendsto_at_top_is_lub`.\n\nThis property holds for linear orders with order topology as well as their products. -/\nclass Sup_convergence_class (\u03b1 : Type*) [preorder \u03b1] [topological_space \u03b1] : Prop :=\n(tendsto_coe_at_top_is_lub : \u2200 (a : \u03b1) (s : set \u03b1), is_lub s a \u2192 tendsto (coe : s \u2192 \u03b1) at_top (\ud835\udcdd a))\n\n/-- We say that `\u03b1` is an `Inf_convergence_class` if the following holds. Let `f : \u03b9 \u2192 \u03b1` be a\nmonotone function, let `a : \u03b1` be a greatest lower bound of `set.range f`. Then `f x` tends to `\ud835\udcdd a`\nas `x \u2192 -\u221e` (formally, at the filter `filter.at_bot`). We require this for `\u03b9 = (s : set \u03b1)`,\n`f = coe` in the definition, then prove it for any `f` in `tendsto_at_bot_is_glb`.\n\nThis property holds for linear orders with order topology as well as their products. -/\nclass Inf_convergence_class (\u03b1 : Type*) [preorder \u03b1] [topological_space \u03b1] : Prop :=\n(tendsto_coe_at_bot_is_glb : \u2200 (a : \u03b1) (s : set \u03b1), is_glb s a \u2192 tendsto (coe : s \u2192 \u03b1) at_bot (\ud835\udcdd a))\n\ninstance order_dual.Sup_convergence_class [preorder \u03b1] [topological_space \u03b1]\n  [Inf_convergence_class \u03b1] : Sup_convergence_class \u03b1\u1d52\u1d48 :=\n\u27e8\u2039Inf_convergence_class \u03b1\u203a.1\u27e9\n\ninstance order_dual.Inf_convergence_class [preorder \u03b1] [topological_space \u03b1]\n  [Sup_convergence_class \u03b1] : Inf_convergence_class \u03b1\u1d52\u1d48 :=\n\u27e8\u2039Sup_convergence_class \u03b1\u203a.1\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_order.Sup_convergence_class [topological_space \u03b1] [linear_order \u03b1]\n  [order_topology \u03b1] : Sup_convergence_class \u03b1 :=\nbegin\n  refine \u27e8\u03bb a s ha, tendsto_order.2 \u27e8\u03bb b hb, _, \u03bb b hb, _\u27e9\u27e9,\n  { rcases ha.exists_between hb with \u27e8c, hcs, bc, bca\u27e9,\n    lift c to s using hcs,\n    refine (eventually_ge_at_top c).mono (\u03bb x hx, bc.trans_le hx) },\n  { exact eventually_of_forall (\u03bb x, (ha.1 x.2).trans_lt hb) }\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_order.Inf_convergence_class [topological_space \u03b1] [linear_order \u03b1]\n  [order_topology \u03b1] : Inf_convergence_class \u03b1 :=\nshow Inf_convergence_class \u03b1\u1d52\u1d48\u1d52\u1d48, from order_dual.Inf_convergence_class\n\nsection\n\nvariables {\u03b9 : Type*} [preorder \u03b9] [topological_space \u03b1]\n\nsection is_lub\n\nvariables [preorder \u03b1] [Sup_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_top_is_lub (h_mono : monotone f) (ha : is_lub (set.range f) a) :\n  tendsto f at_top (\ud835\udcdd a) :=\nbegin\n  suffices : tendsto (range_factorization f) at_top at_top,\n    from (Sup_convergence_class.tendsto_coe_at_top_is_lub _ _ ha).comp this,\n  exact h_mono.range_factorization.tendsto_at_top_at_top (\u03bb b, b.2.imp $ \u03bb a ha, ha.ge)\nend\n\nlemma tendsto_at_bot_is_lub (h_anti : antitone f) (ha : is_lub (set.range f) a) :\n  tendsto f at_bot (\ud835\udcdd a) :=\nby convert tendsto_at_top_is_lub h_anti.dual_left ha\n\nend is_lub\n\nsection is_glb\n\nvariables [preorder \u03b1] [Inf_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_bot_is_glb (h_mono : monotone f) (ha : is_glb (set.range f) a) :\n  tendsto f at_bot (\ud835\udcdd a) :=\nby convert tendsto_at_top_is_lub h_mono.dual ha.dual\n\nlemma tendsto_at_top_is_glb (h_anti : antitone f) (ha : is_glb (set.range f) a) :\n  tendsto f at_top (\ud835\udcdd a) :=\nby convert tendsto_at_bot_is_lub h_anti.dual ha.dual\n\nend is_glb\n\nsection csupr\n\nvariables [conditionally_complete_lattice \u03b1] [Sup_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_top_csupr (h_mono : monotone f) (hbdd : bdd_above $ range f) :\n  tendsto f at_top (\ud835\udcdd (\u2a06i, f i)) :=\nbegin\n  casesI is_empty_or_nonempty \u03b9,\n  exacts [tendsto_of_is_empty, tendsto_at_top_is_lub h_mono (is_lub_csupr hbdd)]\nend\n\nlemma tendsto_at_bot_csupr (h_anti : antitone f) (hbdd : bdd_above $ range f) :\n  tendsto f at_bot (\ud835\udcdd (\u2a06 i, f i)) :=\nby convert tendsto_at_top_csupr h_anti.dual hbdd.dual\n\nend csupr\n\nsection cinfi\n\nvariables [conditionally_complete_lattice \u03b1] [Inf_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_bot_cinfi (h_mono : monotone f) (hbdd : bdd_below $ range f) :\n  tendsto f at_bot (\ud835\udcdd (\u2a05 i, f i)) :=\nby convert tendsto_at_top_csupr h_mono.dual hbdd.dual\n\nlemma tendsto_at_top_cinfi (h_anti : antitone f) (hbdd : bdd_below $ range f) :\n  tendsto f at_top (\ud835\udcdd (\u2a05 i, f i)) :=\nby convert tendsto_at_bot_csupr h_anti.dual hbdd.dual\n\nend cinfi\n\nsection supr\n\nvariables [complete_lattice \u03b1] [Sup_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_top_supr (h_mono : monotone f) : tendsto f at_top (\ud835\udcdd (\u2a06i, f i)) :=\ntendsto_at_top_csupr h_mono (order_top.bdd_above _)\n\nlemma tendsto_at_bot_supr (h_anti : antitone f) :\n  tendsto f at_bot (\ud835\udcdd (\u2a06i, f i)) :=\ntendsto_at_bot_csupr h_anti (order_top.bdd_above _)\n\nend supr\n\nsection infi\n\nvariables [complete_lattice \u03b1] [Inf_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_bot_infi (h_mono : monotone f) : tendsto f at_bot (\ud835\udcdd (\u2a05i, f i)) :=\ntendsto_at_bot_cinfi h_mono (order_bot.bdd_below _)\n\nlemma tendsto_at_top_infi (h_anti : antitone f) :\n  tendsto f at_top (\ud835\udcdd (\u2a05i, f i)) :=\ntendsto_at_top_cinfi h_anti (order_bot.bdd_below _)\n\nend infi\n\nend\n\ninstance [preorder \u03b1] [preorder \u03b2] [topological_space \u03b1] [topological_space \u03b2]\n  [Sup_convergence_class \u03b1] [Sup_convergence_class \u03b2] : Sup_convergence_class (\u03b1 \u00d7 \u03b2) :=\nbegin\n  constructor,\n  rintro \u27e8a, b\u27e9 s h,\n  rw [is_lub_prod, \u2190 range_restrict, \u2190 range_restrict] at h,\n  have A : tendsto (\u03bb x : s, (x : \u03b1 \u00d7 \u03b2).1) at_top (\ud835\udcdd a),\n    from tendsto_at_top_is_lub (monotone_fst.restrict s) h.1,\n  have B : tendsto (\u03bb x : s, (x : \u03b1 \u00d7 \u03b2).2) at_top (\ud835\udcdd b),\n    from tendsto_at_top_is_lub (monotone_snd.restrict s) h.2,\n  convert A.prod_mk_nhds B,\n  ext1 \u27e8\u27e8x, y\u27e9, h\u27e9, refl\nend\n\ninstance [preorder \u03b1] [preorder \u03b2] [topological_space \u03b1] [topological_space \u03b2]\n  [Inf_convergence_class \u03b1] [Inf_convergence_class \u03b2] : Inf_convergence_class (\u03b1 \u00d7 \u03b2) :=\nshow Inf_convergence_class (\u03b1\u1d52\u1d48 \u00d7 \u03b2\u1d52\u1d48)\u1d52\u1d48, from order_dual.Inf_convergence_class\n\ninstance {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, topological_space (\u03b1 i)]\n  [\u03a0 i, Sup_convergence_class (\u03b1 i)] : Sup_convergence_class (\u03a0 i, \u03b1 i) :=\nbegin\n  refine \u27e8\u03bb f s h, _\u27e9,\n  simp only [is_lub_pi, \u2190 range_restrict] at h,\n  exact tendsto_pi_nhds.2 (\u03bb i, tendsto_at_top_is_lub ((monotone_eval _).restrict _) (h i))\nend\n\ninstance {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, topological_space (\u03b1 i)]\n  [\u03a0 i, Inf_convergence_class (\u03b1 i)] : Inf_convergence_class (\u03a0 i, \u03b1 i) :=\nshow Inf_convergence_class (\u03a0 i, (\u03b1 i)\u1d52\u1d48)\u1d52\u1d48, from order_dual.Inf_convergence_class\n\ninstance pi.Sup_convergence_class' {\u03b9 : Type*} [preorder \u03b1] [topological_space \u03b1]\n  [Sup_convergence_class \u03b1] : Sup_convergence_class (\u03b9 \u2192 \u03b1) :=\npi.Sup_convergence_class\n\ninstance pi.Inf_convergence_class' {\u03b9 : Type*} [preorder \u03b1] [topological_space \u03b1]\n  [Inf_convergence_class \u03b1] : Inf_convergence_class (\u03b9 \u2192 \u03b1) :=\npi.Inf_convergence_class\n\nlemma tendsto_of_monotone {\u03b9 \u03b1 : Type*} [preorder \u03b9] [topological_space \u03b1]\n  [conditionally_complete_linear_order \u03b1] [order_topology \u03b1] {f : \u03b9 \u2192 \u03b1} (h_mono : monotone f) :\n  tendsto f at_top at_top \u2228 (\u2203 l, tendsto f at_top (\ud835\udcdd l)) :=\nif H : bdd_above (range f) then or.inr \u27e8_, tendsto_at_top_csupr h_mono H\u27e9\nelse or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H\n\nlemma tendsto_iff_tendsto_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type*} [semilattice_sup \u03b9\u2081] [preorder \u03b9\u2082]\n  [nonempty \u03b9\u2081] [topological_space \u03b1] [conditionally_complete_linear_order \u03b1] [order_topology \u03b1]\n  [no_max_order \u03b1] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} {l : \u03b1} (hf : monotone f)\n  (hg : tendsto \u03c6 at_top at_top) :\n  tendsto f at_top (\ud835\udcdd l) \u2194 tendsto (f \u2218 \u03c6) at_top (\ud835\udcdd l) :=\nbegin\n  split; intro h,\n  { exact h.comp hg },\n  { rcases tendsto_of_monotone hf with h' | \u27e8l', hl'\u27e9,\n    { exact (not_tendsto_at_top_of_tendsto_nhds h (h'.comp hg)).elim },\n    { rwa tendsto_nhds_unique h (hl'.comp hg) } }\nend\n\n/-! The next family of results, such as `is_lub_of_tendsto_at_top` and `supr_eq_of_tendsto`, are\nconverses to the standard fact that bounded monotone functions converge. They state, that if a\nmonotone function `f` tends to `a` along `filter.at_top`, then that value `a` is a least upper bound\nfor the range of `f`.\n\nRelated theorems above (`is_lub.is_lub_of_tendsto`, `is_glb.is_glb_of_tendsto` etc) cover the case\nwhen `f x` tends to `a` as `x` tends to some point `b` in the domain. -/\n\nlemma monotone.ge_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) (b : \u03b2) :\n  f b \u2264 a :=\nbegin\n  haveI : nonempty \u03b2 := nonempty.intro b,\n  exact ge_of_tendsto ha ((eventually_ge_at_top b).mono (\u03bb _ hxy, hf hxy))\nend\n\nlemma monotone.le_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) (b : \u03b2) :\n  a \u2264 f b :=\nhf.dual.ge_of_tendsto ha b\n\nlemma antitone.le_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) (b : \u03b2) :\n  a \u2264 f b :=\nhf.dual_right.ge_of_tendsto ha b\n\nlemma antitone.ge_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) (b : \u03b2) :\n  f b \u2264 a :=\nhf.dual_right.le_of_tendsto ha b\n\nlemma is_lub_of_tendsto_at_top [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) :\n  is_lub (set.range f) a :=\nbegin\n  split,\n  { rintros _ \u27e8b, rfl\u27e9,\n    exact hf.ge_of_tendsto ha b },\n  { exact \u03bb _ hb, le_of_tendsto' ha (\u03bb x, hb (set.mem_range_self x)) }\nend\n\nlemma is_glb_of_tendsto_at_bot [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) :\n  is_glb (set.range f) a :=\n@is_lub_of_tendsto_at_top \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ hf.dual ha\n\nlemma is_lub_of_tendsto_at_bot [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) :\n  is_lub (set.range f) a :=\n@is_lub_of_tendsto_at_top \u03b1 \u03b2\u1d52\u1d48  _ _ _ _ _ _ _ hf.dual_left ha\n\nlemma is_glb_of_tendsto_at_top [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) :\n  is_glb (set.range f) a :=\n@is_glb_of_tendsto_at_bot \u03b1 \u03b2\u1d52\u1d48  _ _ _ _ _ _ _ hf.dual_left ha\n\nlemma supr_eq_of_tendsto {\u03b1 \u03b2} [topological_space \u03b1] [complete_linear_order \u03b1] [order_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f) :\n  tendsto f at_top (\ud835\udcdd a) \u2192 supr f = a :=\ntendsto_nhds_unique (tendsto_at_top_supr hf)\n\nlemma infi_eq_of_tendsto {\u03b1} [topological_space \u03b1] [complete_linear_order \u03b1] [order_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f) :\n  tendsto f at_top (\ud835\udcdd a) \u2192 infi f = a :=\ntendsto_nhds_unique (tendsto_at_top_infi hf)\n\nlemma supr_eq_supr_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type*} [preorder \u03b9\u2082] [complete_lattice \u03b1]\n  {l : filter \u03b9\u2081} [l.ne_bot] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} (hf : monotone f)\n  (h\u03c6 : tendsto \u03c6 l at_top) :\n  (\u2a06 i, f i) = (\u2a06 i, f (\u03c6 i)) :=\nle_antisymm\n  (supr_mono' $ \u03bb i, exists_imp_exists (\u03bb j (hj : i \u2264 \u03c6 j), hf hj)\n    (h\u03c6.eventually $ eventually_ge_at_top i).exists)\n  (supr_mono' $ \u03bb i, \u27e8\u03c6 i, le_rfl\u27e9)\n\nlemma infi_eq_infi_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type*} [preorder \u03b9\u2082] [complete_lattice \u03b1]\n  {l : filter \u03b9\u2081} [l.ne_bot] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} (hf : monotone f)\n  (h\u03c6 : tendsto \u03c6 l at_bot) :\n  (\u2a05 i, f i) = (\u2a05 i, f (\u03c6 i)) :=\nsupr_eq_supr_subseq_of_monotone hf.dual h\u03c6\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/order/monotone_convergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7419076549795172}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module measure_theory.function.jacobian\n! leanprover-community/mathlib commit 57ac39bd365c2f80589a700f9fbb664d3a1a30c2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Covering.BesicovitchVectorSpace\nimport Mathbin.MeasureTheory.Measure.HaarLebesgue\nimport Mathbin.Analysis.NormedSpace.Pointwise\nimport Mathbin.MeasureTheory.Constructions.Polish\n\n/-!\n# Change of variables in higher-dimensional integrals\n\nLet `\u03bc` be a Lebesgue measure on a finite-dimensional real vector space `E`.\nLet `f : E \u2192 E` be a function which is injective and differentiable on a measurable set `s`,\nwith derivative `f'`. Then we prove that `f '' s` is measurable, and\nits measure is given by the formula `\u03bc (f '' s) = \u222b\u207b x in s, |(f' x).det| \u2202\u03bc` (where `(f' x).det`\nis almost everywhere measurable, but not Borel-measurable in general). This formula is proved in\n`lintegral_abs_det_fderiv_eq_add_haar_image`. We deduce the change of variables\nformula for the Lebesgue and Bochner integrals, in `lintegral_image_eq_lintegral_abs_det_fderiv_mul`\nand `integral_image_eq_integral_abs_det_fderiv_smul` respectively.\n\n## Main results\n\n* `add_haar_image_eq_zero_of_differentiable_on_of_add_haar_eq_zero`: if `f` is differentiable on a\n  set `s` with zero measure, then `f '' s` also has zero measure.\n* `add_haar_image_eq_zero_of_det_fderiv_within_eq_zero`: if `f` is differentiable on a set `s`, and\n  its derivative is never invertible, then `f '' s` has zero measure (a version of Sard's lemma).\n* `ae_measurable_fderiv_within`: if `f` is differentiable on a measurable set `s`, then `f'`\n  is almost everywhere measurable on `s`.\n\nFor the next statements, `s` is a measurable set and `f` is differentiable on `s`\n(with a derivative `f'`) and injective on `s`.\n\n* `measurable_image_of_fderiv_within`: the image `f '' s` is measurable.\n* `measurable_embedding_of_fderiv_within`: the function `s.restrict f` is a measurable embedding.\n* `lintegral_abs_det_fderiv_eq_add_haar_image`: the image measure is given by\n    `\u03bc (f '' s) = \u222b\u207b x in s, |(f' x).det| \u2202\u03bc`.\n* `lintegral_image_eq_lintegral_abs_det_fderiv_mul`: for `g : E \u2192 \u211d\u22650\u221e`, one has\n    `\u222b\u207b x in f '' s, g x \u2202\u03bc = \u222b\u207b x in s, ennreal.of_real (|(f' x).det|) * g (f x) \u2202\u03bc`.\n* `integral_image_eq_integral_abs_det_fderiv_smul`: for `g : E \u2192 F`, one has\n    `\u222b x in f '' s, g x \u2202\u03bc = \u222b x in s, |(f' x).det| \u2022 g (f x) \u2202\u03bc`.\n* `integrable_on_image_iff_integrable_on_abs_det_fderiv_smul`: for `g : E \u2192 F`, the function `g` is\n  integrable on `f '' s` if and only if `|(f' x).det| \u2022 g (f x))` is integrable on `s`.\n\n## Implementation\n\nTypical versions of these results in the literature have much stronger assumptions: `s` would\ntypically be open, and the derivative `f' x` would depend continuously on `x` and be invertible\neverywhere, to have the local inverse theorem at our disposal. The proof strategy under our weaker\nassumptions is more involved. We follow [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2].\n\nThe first remark is that, if `f` is sufficiently well approximated by a linear map `A` on a set\n`s`, then `f` expands the volume of `s` by at least `A.det - \u03b5` and at most `A.det + \u03b5`, where\nthe closeness condition depends on `A` in a non-explicit way (see `add_haar_image_le_mul_of_det_lt`\nand `mul_le_add_haar_image_of_lt_det`). This fact holds for balls by a simple inclusion argument,\nand follows for general sets using the Besicovitch covering theorem to cover the set by balls with\nmeasures adding up essentially to `\u03bc s`.\n\nWhen `f` is differentiable on `s`, one may partition `s` into countably many subsets `s \u2229 t n`\n(where `t n` is measurable), on each of which `f` is well approximated by a linear map, so that the\nabove results apply. See `exists_partition_approximates_linear_on_of_has_fderiv_within_at`, which\nfollows from the pointwise differentiability (in a non-completely trivial way, as one should ensure\na form of uniformity on the sets of the partition).\n\nCombining the above two results would give the conclusion, except for two difficulties: it is not\nobvious why `f '' s` and `f'` should be measurable, which prevents us from using countable\nadditivity for the measure and the integral. It turns out that `f '' s` is indeed measurable,\nand that `f'` is almost everywhere measurable, which is enough to recover countable additivity.\n\nThe measurability of `f '' s` follows from the deep Lusin-Souslin theorem ensuring that, in a\nPolish space, a continuous injective image of a measurable set is measurable.\n\nThe key point to check the almost everywhere measurability of `f'` is that, if `f` is approximated\nup to `\u03b4` by a linear map on a set `s`, then `f'` is within `\u03b4` of `A` on a full measure subset\nof `s` (namely, its density points). With the above approximation argument, it follows that `f'`\nis the almost everywhere limit of a sequence of measurable functions (which are constant on the\npieces of the good discretization), and is therefore almost everywhere measurable.\n\n## Tags\nChange of variables in integrals\n\n## References\n[Fremlin, *Measure Theory* (volume 2)][fremlin_vol2]\n-/\n\n\nopen\n  MeasureTheory MeasureTheory.Measure Metric Filter Set FiniteDimensional Asymptotics TopologicalSpace\n\nopen NNReal ENNReal Topology Pointwise\n\nvariable {E F : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] [FiniteDimensional \u211d E]\n  [NormedAddCommGroup F] [NormedSpace \u211d F] {s : Set E} {f : E \u2192 E} {f' : E \u2192 E \u2192L[\u211d] E}\n\n/-!\n### Decomposition lemmas\n\nWe state lemmas ensuring that a differentiable function can be approximated, on countably many\nmeasurable pieces, by linear maps (with a prescribed precision depending on the linear map).\n-/\n\n\n/-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may cover `s`\nwith countably many closed sets `t n` on which `f` is well approximated by linear maps `A n`. -/\ntheorem exists_closed_cover_approximatesLinearOn_of_hasFderivWithinAt [SecondCountableTopology F]\n    (f : E \u2192 F) (s : Set E) (f' : E \u2192 E \u2192L[\u211d] F) (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x)\n    (r : (E \u2192L[\u211d] F) \u2192 \u211d\u22650) (rpos : \u2200 A, r A \u2260 0) :\n    \u2203 (t : \u2115 \u2192 Set E)(A : \u2115 \u2192 E \u2192L[\u211d] F),\n      (\u2200 n, IsClosed (t n)) \u2227\n        (s \u2286 \u22c3 n, t n) \u2227\n          (\u2200 n, ApproximatesLinearOn f (A n) (s \u2229 t n) (r (A n))) \u2227\n            (s.Nonempty \u2192 \u2200 n, \u2203 y \u2208 s, A n = f' y) :=\n  by\n  /- Choose countably many linear maps `f' z`. For every such map, if `f` has a derivative at `x`\n    close enough to `f' z`, then `f y - f x` is well approximated by `f' z (y - x)` for `y` close\n    enough to `x`, say on a ball of radius `r` (or even `u n` for some `n`, where `u` is a fixed\n    sequence tending to `0`).\n    Let `M n z` be the points where this happens. Then this set is relatively closed inside `s`,\n    and moreover in every closed ball of radius `u n / 3` inside it the map is well approximated by\n    `f' z`. Using countably many closed balls to split `M n z` into small diameter subsets `K n z p`,\n    one obtains the desired sets `t q` after reindexing.\n    -/\n  -- exclude the trivial case where `s` is empty\n  rcases eq_empty_or_nonempty s with (rfl | hs)\n  \u00b7 refine' \u27e8fun n => \u2205, fun n => 0, _, _, _, _\u27e9 <;> simp\n  -- we will use countably many linear maps. Select these from all the derivatives since the\n  -- space of linear maps is second-countable\n  obtain \u27e8T, T_count, hT\u27e9 :\n    \u2203 T : Set s,\n      T.Countable \u2227 (\u22c3 x \u2208 T, ball (f' (x : E)) (r (f' x))) = \u22c3 x : s, ball (f' x) (r (f' x)) :=\n    TopologicalSpace.isOpen_union\u1d62_countable _ fun x => is_open_ball\n  -- fix a sequence `u` of positive reals tending to zero.\n  obtain \u27e8u, u_anti, u_pos, u_lim\u27e9 :\n    \u2203 u : \u2115 \u2192 \u211d, StrictAnti u \u2227 (\u2200 n : \u2115, 0 < u n) \u2227 tendsto u at_top (\ud835\udcdd 0) :=\n    exists_seq_strictAnti_tendsto (0 : \u211d)\n  -- `M n z` is the set of points `x` such that `f y - f x` is close to `f' z (y - x)` for `y`\n  -- in the ball of radius `u n` around `x`.\n  let M : \u2115 \u2192 T \u2192 Set E := fun n z =>\n    { x | x \u2208 s \u2227 \u2200 y \u2208 s \u2229 ball x (u n), \u2016f y - f x - f' z (y - x)\u2016 \u2264 r (f' z) * \u2016y - x\u2016 }\n  -- As `f` is differentiable everywhere on `s`, the sets `M n z` cover `s` by design.\n  have s_subset : \u2200 x \u2208 s, \u2203 (n : \u2115)(z : T), x \u2208 M n z :=\n    by\n    intro x xs\n    obtain \u27e8z, zT, hz\u27e9 : \u2203 z \u2208 T, f' x \u2208 ball (f' (z : E)) (r (f' z)) :=\n      by\n      have : f' x \u2208 \u22c3 z \u2208 T, ball (f' (z : E)) (r (f' z)) :=\n        by\n        rw [hT]\n        refine' mem_Union.2 \u27e8\u27e8x, xs\u27e9, _\u27e9\n        simpa only [mem_ball, Subtype.coe_mk, dist_self] using (rpos (f' x)).bot_lt\n      rwa [mem_Union\u2082] at this\n    obtain \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9 : \u2203 \u03b5 : \u211d, 0 < \u03b5 \u2227 \u2016f' x - f' z\u2016 + \u03b5 \u2264 r (f' z) :=\n      by\n      refine' \u27e8r (f' z) - \u2016f' x - f' z\u2016, _, le_of_eq (by abel)\u27e9\n      simpa only [sub_pos] using mem_ball_iff_norm.mp hz\n    obtain \u27e8\u03b4, \u03b4pos, h\u03b4\u27e9 :\n      \u2203 (\u03b4 : \u211d)(H : 0 < \u03b4), ball x \u03b4 \u2229 s \u2286 { y | \u2016f y - f x - (f' x) (y - x)\u2016 \u2264 \u03b5 * \u2016y - x\u2016 } :=\n      Metric.mem_nhdsWithin_iff.1 (is_o.def (hf' x xs) \u03b5pos)\n    obtain \u27e8n, hn\u27e9 : \u2203 n, u n < \u03b4 := ((tendsto_order.1 u_lim).2 _ \u03b4pos).exists\n    refine' \u27e8n, \u27e8z, zT\u27e9, \u27e8xs, _\u27e9\u27e9\n    intro y hy\n    calc\n      \u2016f y - f x - (f' z) (y - x)\u2016 = \u2016f y - f x - (f' x) (y - x) + (f' x - f' z) (y - x)\u2016 :=\n        by\n        congr 1\n        simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply]\n        abel\n      _ \u2264 \u2016f y - f x - (f' x) (y - x)\u2016 + \u2016(f' x - f' z) (y - x)\u2016 := (norm_add_le _ _)\n      _ \u2264 \u03b5 * \u2016y - x\u2016 + \u2016f' x - f' z\u2016 * \u2016y - x\u2016 :=\n        by\n        refine' add_le_add (h\u03b4 _) (ContinuousLinearMap.le_op_norm _ _)\n        rw [inter_comm]\n        exact inter_subset_inter_right _ (ball_subset_ball hn.le) hy\n      _ \u2264 r (f' z) * \u2016y - x\u2016 := by\n        rw [\u2190 add_mul, add_comm]\n        exact mul_le_mul_of_nonneg_right h\u03b5 (norm_nonneg _)\n      \n  -- the sets `M n z` are relatively closed in `s`, as all the conditions defining it are clearly\n  -- closed\n  have closure_M_subset : \u2200 n z, s \u2229 closure (M n z) \u2286 M n z :=\n    by\n    rintro n z x \u27e8xs, hx\u27e9\n    refine' \u27e8xs, fun y hy => _\u27e9\n    obtain \u27e8a, aM, a_lim\u27e9 : \u2203 a : \u2115 \u2192 E, (\u2200 k, a k \u2208 M n z) \u2227 tendsto a at_top (\ud835\udcdd x) :=\n      mem_closure_iff_seq_limit.1 hx\n    have L1 :\n      tendsto (fun k : \u2115 => \u2016f y - f (a k) - (f' z) (y - a k)\u2016) at_top\n        (\ud835\udcdd \u2016f y - f x - (f' z) (y - x)\u2016) :=\n      by\n      apply tendsto.norm\n      have L : tendsto (fun k => f (a k)) at_top (\ud835\udcdd (f x)) :=\n        by\n        apply (hf' x xs).ContinuousWithinAt.Tendsto.comp\n        apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ a_lim\n        exact eventually_of_forall fun k => (aM k).1\n      apply tendsto.sub (tendsto_const_nhds.sub L)\n      exact ((f' z).Continuous.Tendsto _).comp (tendsto_const_nhds.sub a_lim)\n    have L2 : tendsto (fun k : \u2115 => (r (f' z) : \u211d) * \u2016y - a k\u2016) at_top (\ud835\udcdd (r (f' z) * \u2016y - x\u2016)) :=\n      (tendsto_const_nhds.sub a_lim).norm.const_mul _\n    have I : \u2200\u1da0 k in at_top, \u2016f y - f (a k) - (f' z) (y - a k)\u2016 \u2264 r (f' z) * \u2016y - a k\u2016 :=\n      by\n      have L : tendsto (fun k => dist y (a k)) at_top (\ud835\udcdd (dist y x)) :=\n        tendsto_const_nhds.dist a_lim\n      filter_upwards [(tendsto_order.1 L).2 _ hy.2]\n      intro k hk\n      exact (aM k).2 y \u27e8hy.1, hk\u27e9\n    exact le_of_tendsto_of_tendsto L1 L2 I\n  -- choose a dense sequence `d p`\n  rcases TopologicalSpace.exists_dense_seq E with \u27e8d, hd\u27e9\n  -- split `M n z` into subsets `K n z p` of small diameters by intersecting with the ball\n  -- `closed_ball (d p) (u n / 3)`.\n  let K : \u2115 \u2192 T \u2192 \u2115 \u2192 Set E := fun n z p => closure (M n z) \u2229 closed_ball (d p) (u n / 3)\n  -- on the sets `K n z p`, the map `f` is well approximated by `f' z` by design.\n  have K_approx : \u2200 (n) (z : T) (p), ApproximatesLinearOn f (f' z) (s \u2229 K n z p) (r (f' z)) :=\n    by\n    intro n z p x hx y hy\n    have yM : y \u2208 M n z := closure_M_subset _ _ \u27e8hy.1, hy.2.1\u27e9\n    refine' yM.2 _ \u27e8hx.1, _\u27e9\n    calc\n      dist x y \u2264 dist x (d p) + dist y (d p) := dist_triangle_right _ _ _\n      _ \u2264 u n / 3 + u n / 3 := (add_le_add hx.2.2 hy.2.2)\n      _ < u n := by linarith [u_pos n]\n      \n  -- the sets `K n z p` are also closed, again by design.\n  have K_closed : \u2200 (n) (z : T) (p), IsClosed (K n z p) := fun n z p =>\n    is_closed_closure.inter is_closed_ball\n  -- reindex the sets `K n z p`, to let them only depend on an integer parameter `q`.\n  obtain \u27e8F, hF\u27e9 : \u2203 F : \u2115 \u2192 \u2115 \u00d7 T \u00d7 \u2115, Function.Surjective F :=\n    by\n    haveI : Encodable T := T_count.to_encodable\n    have : Nonempty T := by\n      rcases eq_empty_or_nonempty T with (rfl | hT)\n      \u00b7 rcases hs with \u27e8x, xs\u27e9\n        rcases s_subset x xs with \u27e8n, z, hnz\u27e9\n        exact False.elim z.2\n      \u00b7 exact hT.coe_sort\n    inhabit \u2115 \u00d7 T \u00d7 \u2115\n    exact \u27e8_, Encodable.surjective_decode_iget _\u27e9\n  -- these sets `t q = K n z p` will do\n  refine'\n    \u27e8fun q => K (F q).1 (F q).2.1 (F q).2.2, fun q => f' (F q).2.1, fun n => K_closed _ _ _,\n      fun x xs => _, fun q => K_approx _ _ _, fun h's q => \u27e8(F q).2.1, (F q).2.1.1.2, rfl\u27e9\u27e9\n  -- the only fact that needs further checking is that they cover `s`.\n  -- we already know that any point `x \u2208 s` belongs to a set `M n z`.\n  obtain \u27e8n, z, hnz\u27e9 : \u2203 (n : \u2115)(z : T), x \u2208 M n z := s_subset x xs\n  -- by density, it also belongs to a ball `closed_ball (d p) (u n / 3)`.\n  obtain \u27e8p, hp\u27e9 : \u2203 p : \u2115, x \u2208 closed_ball (d p) (u n / 3) :=\n    by\n    have : Set.Nonempty (ball x (u n / 3)) :=\n      by\n      simp only [nonempty_ball]\n      linarith [u_pos n]\n    obtain \u27e8p, hp\u27e9 : \u2203 p : \u2115, d p \u2208 ball x (u n / 3) := hd.exists_mem_open is_open_ball this\n    exact \u27e8p, (mem_ball'.1 hp).le\u27e9\n  -- choose `q` for which `t q = K n z p`.\n  obtain \u27e8q, hq\u27e9 : \u2203 q, F q = (n, z, p) := hF _\n  -- then `x` belongs to `t q`.\n  apply mem_Union.2 \u27e8q, _\u27e9\n  simp only [hq, subset_closure hnz, hp, mem_inter_iff, and_self_iff]\n#align exists_closed_cover_approximates_linear_on_of_has_fderiv_within_at exists_closed_cover_approximatesLinearOn_of_hasFderivWithinAt\n\nvariable [MeasurableSpace E] [BorelSpace E] (\u03bc : Measure E) [IsAddHaarMeasure \u03bc]\n\n/-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may\npartition `s` into countably many disjoint relatively measurable sets (i.e., intersections\nof `s` with measurable sets `t n`) on which `f` is well approximated by linear maps `A n`. -/\ntheorem exists_partition_approximatesLinearOn_of_hasFderivWithinAt [SecondCountableTopology F]\n    (f : E \u2192 F) (s : Set E) (f' : E \u2192 E \u2192L[\u211d] F) (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x)\n    (r : (E \u2192L[\u211d] F) \u2192 \u211d\u22650) (rpos : \u2200 A, r A \u2260 0) :\n    \u2203 (t : \u2115 \u2192 Set E)(A : \u2115 \u2192 E \u2192L[\u211d] F),\n      Pairwise (Disjoint on t) \u2227\n        (\u2200 n, MeasurableSet (t n)) \u2227\n          (s \u2286 \u22c3 n, t n) \u2227\n            (\u2200 n, ApproximatesLinearOn f (A n) (s \u2229 t n) (r (A n))) \u2227\n              (s.Nonempty \u2192 \u2200 n, \u2203 y \u2208 s, A n = f' y) :=\n  by\n  rcases exists_closed_cover_approximatesLinearOn_of_hasFderivWithinAt f s f' hf' r rpos with\n    \u27e8t, A, t_closed, st, t_approx, ht\u27e9\n  refine'\n    \u27e8disjointed t, A, disjoint_disjointed _,\n      MeasurableSet.disjointed fun n => (t_closed n).MeasurableSet, _, _, ht\u27e9\n  \u00b7 rw [union\u1d62_disjointed]\n    exact st\n  \u00b7 intro n\n    exact (t_approx n).monoSet (inter_subset_inter_right _ (disjointed_subset _ _))\n#align exists_partition_approximates_linear_on_of_has_fderiv_within_at exists_partition_approximatesLinearOn_of_hasFderivWithinAt\n\nnamespace MeasureTheory\n\n/-!\n### Local lemmas\n\nWe check that a function which is well enough approximated by a linear map expands the volume\nessentially like this linear map, and that its derivative (if it exists) is almost everywhere close\nto the approximating linear map.\n-/\n\n\n/-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear\nmap `A`. Then it expands the volume of any set by at most `m` for any `m > det A`. -/\ntheorem add_haar_image_le_mul_of_det_lt (A : E \u2192L[\u211d] E) {m : \u211d\u22650}\n    (hm : ENNReal.ofReal (|A.det|) < m) :\n    \u2200\u1da0 \u03b4 in \ud835\udcdd[>] (0 : \u211d\u22650),\n      \u2200 (s : Set E) (f : E \u2192 E) (hf : ApproximatesLinearOn f A s \u03b4), \u03bc (f '' s) \u2264 m * \u03bc s :=\n  by\n  apply nhdsWithin_le_nhds\n  let d := ENNReal.ofReal (|A.det|)\n  -- construct a small neighborhood of `A '' (closed_ball 0 1)` with measure comparable to\n  -- the determinant of `A`.\n  obtain \u27e8\u03b5, h\u03b5, \u03b5pos\u27e9 :\n    \u2203 \u03b5 : \u211d, \u03bc (closed_ball 0 \u03b5 + A '' closed_ball 0 1) < m * \u03bc (closed_ball 0 1) \u2227 0 < \u03b5 :=\n    by\n    have HC : IsCompact (A '' closed_ball 0 1) :=\n      (ProperSpace.isCompact_closedBall _ _).image A.continuous\n    have L0 :\n      tendsto (fun \u03b5 => \u03bc (cthickening \u03b5 (A '' closed_ball 0 1))) (\ud835\udcdd[>] 0)\n        (\ud835\udcdd (\u03bc (A '' closed_ball 0 1))) :=\n      by\n      apply tendsto.mono_left _ nhdsWithin_le_nhds\n      exact tendsto_measure_cthickening_of_isCompact HC\n    have L1 :\n      tendsto (fun \u03b5 => \u03bc (closed_ball 0 \u03b5 + A '' closed_ball 0 1)) (\ud835\udcdd[>] 0)\n        (\ud835\udcdd (\u03bc (A '' closed_ball 0 1))) :=\n      by\n      apply L0.congr' _\n      filter_upwards [self_mem_nhdsWithin]with r hr\n      rw [\u2190 HC.add_closed_ball_zero (le_of_lt hr), add_comm]\n    have L2 :\n      tendsto (fun \u03b5 => \u03bc (closed_ball 0 \u03b5 + A '' closed_ball 0 1)) (\ud835\udcdd[>] 0)\n        (\ud835\udcdd (d * \u03bc (closed_ball 0 1))) :=\n      by\n      convert L1\n      exact (add_haar_image_continuous_linear_map _ _ _).symm\n    have I : d * \u03bc (closed_ball 0 1) < m * \u03bc (closed_ball 0 1) :=\n      (ENNReal.mul_lt_mul_right (measure_closed_ball_pos \u03bc _ zero_lt_one).ne'\n            measure_closed_ball_lt_top.ne).2\n        hm\n    have H :\n      \u2200\u1da0 b : \u211d in \ud835\udcdd[>] 0, \u03bc (closed_ball 0 b + A '' closed_ball 0 1) < m * \u03bc (closed_ball 0 1) :=\n      (tendsto_order.1 L2).2 _ I\n    exact (H.and self_mem_nhdsWithin).exists\n  have : Iio (\u27e8\u03b5, \u03b5pos.le\u27e9 : \u211d\u22650) \u2208 \ud835\udcdd (0 : \u211d\u22650) :=\n    by\n    apply Iio_mem_nhds\n    exact \u03b5pos\n  filter_upwards [this]\n  -- fix a function `f` which is close enough to `A`.\n  intro \u03b4 h\u03b4 s f hf\n  -- This function expands the volume of any ball by at most `m`\n  have I : \u2200 x r, x \u2208 s \u2192 0 \u2264 r \u2192 \u03bc (f '' (s \u2229 closed_ball x r)) \u2264 m * \u03bc (closed_ball x r) :=\n    by\n    intro x r xs r0\n    have K : f '' (s \u2229 closed_ball x r) \u2286 A '' closed_ball 0 r + closed_ball (f x) (\u03b5 * r) :=\n      by\n      rintro y \u27e8z, \u27e8zs, zr\u27e9, rfl\u27e9\n      apply Set.mem_add.2 \u27e8A (z - x), f z - f x - A (z - x) + f x, _, _, _\u27e9\n      \u00b7 apply mem_image_of_mem\n        simpa only [dist_eq_norm, mem_closed_ball, mem_closedBall_zero_iff] using zr\n      \u00b7 rw [mem_closedBall_iff_norm, add_sub_cancel]\n        calc\n          \u2016f z - f x - A (z - x)\u2016 \u2264 \u03b4 * \u2016z - x\u2016 := hf _ zs _ xs\n          _ \u2264 \u03b5 * r :=\n            mul_le_mul (le_of_lt h\u03b4) (mem_closedBall_iff_norm.1 zr) (norm_nonneg _) \u03b5pos.le\n          \n      \u00b7 simp only [map_sub, Pi.sub_apply]\n        abel\n    have :\n      A '' closed_ball 0 r + closed_ball (f x) (\u03b5 * r) =\n        {f x} + r \u2022 (A '' closed_ball 0 1 + closed_ball 0 \u03b5) :=\n      by\n      rw [smul_add, \u2190 add_assoc, add_comm {f x}, add_assoc, smul_closedBall _ _ \u03b5pos.le, smul_zero,\n        singleton_add_closedBall_zero, \u2190 image_smul_set \u211d E E A, smul_closedBall _ _ zero_le_one,\n        smul_zero, Real.norm_eq_abs, abs_of_nonneg r0, mul_one, mul_comm]\n    rw [this] at K\n    calc\n      \u03bc (f '' (s \u2229 closed_ball x r)) \u2264 \u03bc ({f x} + r \u2022 (A '' closed_ball 0 1 + closed_ball 0 \u03b5)) :=\n        measure_mono K\n      _ = ENNReal.ofReal (r ^ finrank \u211d E) * \u03bc (A '' closed_ball 0 1 + closed_ball 0 \u03b5) := by\n        simp only [abs_of_nonneg r0, add_haar_smul, image_add_left, abs_pow, singleton_add,\n          measure_preimage_add]\n      _ \u2264 ENNReal.ofReal (r ^ finrank \u211d E) * (m * \u03bc (closed_ball 0 1)) :=\n        by\n        rw [add_comm]\n        exact mul_le_mul_left' h\u03b5.le _\n      _ = m * \u03bc (closed_ball x r) :=\n        by\n        simp only [add_haar_closed_ball' _ _ r0]\n        ring\n      \n  -- covering `s` by closed balls with total measure very close to `\u03bc s`, one deduces that the\n  -- measure of `f '' s` is at most `m * (\u03bc s + a)` for any positive `a`.\n  have J : \u2200\u1da0 a in \ud835\udcdd[>] (0 : \u211d\u22650\u221e), \u03bc (f '' s) \u2264 m * (\u03bc s + a) :=\n    by\n    filter_upwards [self_mem_nhdsWithin]with a ha\n    change 0 < a at ha\n    obtain \u27e8t, r, t_count, ts, rpos, st, \u03bct\u27e9 :\n      \u2203 (t : Set E)(r : E \u2192 \u211d),\n        t.Countable \u2227\n          t \u2286 s \u2227\n            (\u2200 x : E, x \u2208 t \u2192 0 < r x) \u2227\n              (s \u2286 \u22c3 x \u2208 t, closed_ball x (r x)) \u2227\n                (\u2211' x : \u21a5t, \u03bc (closed_ball (\u2191x) (r \u2191x))) \u2264 \u03bc s + a :=\n      Besicovitch.exists_closedBall_covering_tsum_measure_le \u03bc ha.ne' (fun x => Ioi 0) s\n        fun x xs \u03b4 \u03b4pos => \u27e8\u03b4 / 2, by simp [half_pos \u03b4pos, half_lt_self \u03b4pos]\u27e9\n    haveI : Encodable t := t_count.to_encodable\n    calc\n      \u03bc (f '' s) \u2264 \u03bc (\u22c3 x : t, f '' (s \u2229 closed_ball x (r x))) :=\n        by\n        rw [bUnion_eq_Union] at st\n        apply measure_mono\n        rw [\u2190 image_Union, \u2190 inter_Union]\n        exact image_subset _ (subset_inter (subset.refl _) st)\n      _ \u2264 \u2211' x : t, \u03bc (f '' (s \u2229 closed_ball x (r x))) := (measure_Union_le _)\n      _ \u2264 \u2211' x : t, m * \u03bc (closed_ball x (r x)) :=\n        (ENNReal.tsum_le_tsum fun x => I x (r x) (ts x.2) (rpos x x.2).le)\n      _ \u2264 m * (\u03bc s + a) := by\n        rw [ENNReal.tsum_mul_left]\n        exact mul_le_mul_left' \u03bct _\n      \n  -- taking the limit in `a`, one obtains the conclusion\n  have L : tendsto (fun a => (m : \u211d\u22650\u221e) * (\u03bc s + a)) (\ud835\udcdd[>] 0) (\ud835\udcdd (m * (\u03bc s + 0))) :=\n    by\n    apply tendsto.mono_left _ nhdsWithin_le_nhds\n    apply ENNReal.Tendsto.const_mul (tendsto_const_nhds.add tendsto_id)\n    simp only [ENNReal.coe_ne_top, Ne.def, or_true_iff, not_false_iff]\n  rw [add_zero] at L\n  exact ge_of_tendsto L J\n#align measure_theory.add_haar_image_le_mul_of_det_lt MeasureTheory.add_haar_image_le_mul_of_det_lt\n\n/-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear\nmap `A`. Then it expands the volume of any set by at least `m` for any `m < det A`. -/\ntheorem mul_le_add_haar_image_of_lt_det (A : E \u2192L[\u211d] E) {m : \u211d\u22650}\n    (hm : (m : \u211d\u22650\u221e) < ENNReal.ofReal (|A.det|)) :\n    \u2200\u1da0 \u03b4 in \ud835\udcdd[>] (0 : \u211d\u22650),\n      \u2200 (s : Set E) (f : E \u2192 E) (hf : ApproximatesLinearOn f A s \u03b4),\n        (m : \u211d\u22650\u221e) * \u03bc s \u2264 \u03bc (f '' s) :=\n  by\n  apply nhdsWithin_le_nhds\n  -- The assumption `hm` implies that `A` is invertible. If `f` is close enough to `A`, it is also\n  -- invertible. One can then pass to the inverses, and deduce the estimate from\n  -- `add_haar_image_le_mul_of_det_lt` applied to `f\u207b\u00b9` and `A\u207b\u00b9`.\n  -- exclude first the trivial case where `m = 0`.\n  rcases eq_or_lt_of_le (zero_le m) with (rfl | mpos)\n  \u00b7 apply eventually_of_forall\n    simp only [forall_const, MulZeroClass.zero_mul, imp_true_iff, zero_le, ENNReal.coe_zero]\n  have hA : A.det \u2260 0 := by\n    intro h\n    simpa only [h, ENNReal.not_lt_zero, ENNReal.ofReal_zero, abs_zero] using hm\n  -- let `B` be the continuous linear equiv version of `A`.\n  let B := A.to_continuous_linear_equiv_of_det_ne_zero hA\n  -- the determinant of `B.symm` is bounded by `m\u207b\u00b9`\n  have I : ENNReal.ofReal (|(B.symm : E \u2192L[\u211d] E).det|) < (m\u207b\u00b9 : \u211d\u22650) :=\n    by\n    simp only [ENNReal.ofReal, abs_inv, Real.toNNReal_inv, ContinuousLinearEquiv.det_coe_symm,\n      ContinuousLinearMap.coe_toContinuousLinearEquivOfDetNeZero, ENNReal.coe_lt_coe] at hm\u22a2\n    exact NNReal.inv_lt_inv mpos.ne' hm\n  -- therefore, we may apply `add_haar_image_le_mul_of_det_lt` to `B.symm` and `m\u207b\u00b9`.\n  obtain \u27e8\u03b4\u2080, \u03b4\u2080pos, h\u03b4\u2080\u27e9 :\n    \u2203 \u03b4 : \u211d\u22650,\n      0 < \u03b4 \u2227\n        \u2200 (t : Set E) (g : E \u2192 E),\n          ApproximatesLinearOn g (B.symm : E \u2192L[\u211d] E) t \u03b4 \u2192 \u03bc (g '' t) \u2264 \u2191m\u207b\u00b9 * \u03bc t :=\n    by\n    have :\n      \u2200\u1da0 \u03b4 : \u211d\u22650 in \ud835\udcdd[>] 0,\n        \u2200 (t : Set E) (g : E \u2192 E),\n          ApproximatesLinearOn g (B.symm : E \u2192L[\u211d] E) t \u03b4 \u2192 \u03bc (g '' t) \u2264 \u2191m\u207b\u00b9 * \u03bc t :=\n      add_haar_image_le_mul_of_det_lt \u03bc B.symm I\n    rcases(this.and self_mem_nhdsWithin).exists with \u27e8\u03b4\u2080, h, h'\u27e9\n    exact \u27e8\u03b4\u2080, h', h\u27e9\n  -- record smallness conditions for `\u03b4` that will be needed to apply `h\u03b4\u2080` below.\n  have L1 : \u2200\u1da0 \u03b4 in \ud835\udcdd (0 : \u211d\u22650), Subsingleton E \u2228 \u03b4 < \u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a\u207b\u00b9 :=\n    by\n    by_cases Subsingleton E\n    \u00b7 simp only [h, true_or_iff, eventually_const]\n    simp only [h, false_or_iff]\n    apply Iio_mem_nhds\n    simpa only [h, false_or_iff, inv_pos] using B.subsingleton_or_nnnorm_symm_pos\n  have L2 :\n    \u2200\u1da0 \u03b4 in \ud835\udcdd (0 : \u211d\u22650), \u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a * (\u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a\u207b\u00b9 - \u03b4)\u207b\u00b9 * \u03b4 < \u03b4\u2080 :=\n    by\n    have :\n      tendsto (fun \u03b4 => \u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a * (\u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a\u207b\u00b9 - \u03b4)\u207b\u00b9 * \u03b4) (\ud835\udcdd 0)\n        (\ud835\udcdd (\u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a * (\u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a\u207b\u00b9 - 0)\u207b\u00b9 * 0)) :=\n      by\n      rcases eq_or_ne \u2016(B.symm : E \u2192L[\u211d] E)\u2016\u208a 0 with (H | H)\n      \u00b7 simpa only [H, MulZeroClass.zero_mul] using tendsto_const_nhds\n      refine' tendsto.mul (tendsto_const_nhds.mul _) tendsto_id\n      refine' (tendsto.sub tendsto_const_nhds tendsto_id).inv\u2080 _\n      simpa only [tsub_zero, inv_eq_zero, Ne.def] using H\n    simp only [MulZeroClass.mul_zero] at this\n    exact (tendsto_order.1 this).2 \u03b4\u2080 \u03b4\u2080pos\n  -- let `\u03b4` be small enough, and `f` approximated by `B` up to `\u03b4`.\n  filter_upwards [L1, L2]\n  intro \u03b4 h1\u03b4 h2\u03b4 s f hf\n  have hf' : ApproximatesLinearOn f (B : E \u2192L[\u211d] E) s \u03b4 :=\n    by\n    convert hf\n    exact A.coe_to_continuous_linear_equiv_of_det_ne_zero _\n  let F := hf'.to_local_equiv h1\u03b4\n  -- the condition to be checked can be reformulated in terms of the inverse maps\n  suffices H : \u03bc (F.symm '' F.target) \u2264 (m\u207b\u00b9 : \u211d\u22650) * \u03bc F.target\n  \u00b7 change (m : \u211d\u22650\u221e) * \u03bc F.source \u2264 \u03bc F.target\n    rwa [\u2190 F.symm_image_target_eq_source, mul_comm, \u2190 ENNReal.le_div_iff_mul_le, div_eq_mul_inv,\n      mul_comm, \u2190 ENNReal.coe_inv mpos.ne']\n    \u00b7 apply Or.inl\n      simpa only [ENNReal.coe_eq_zero, Ne.def] using mpos.ne'\n    \u00b7 simp only [ENNReal.coe_ne_top, true_or_iff, Ne.def, not_false_iff]\n  -- as `f\u207b\u00b9` is well approximated by `B\u207b\u00b9`, the conclusion follows from `h\u03b4\u2080`\n  -- and our choice of `\u03b4`.\n  exact h\u03b4\u2080 _ _ ((hf'.to_inv h1\u03b4).mono_num h2\u03b4.le)\n#align measure_theory.mul_le_add_haar_image_of_lt_det MeasureTheory.mul_le_add_haar_image_of_lt_det\n\n/-- If a differentiable function `f` is approximated by a linear map `A` on a set `s`, up to `\u03b4`,\nthen at almost every `x` in `s` one has `\u2016f' x - A\u2016 \u2264 \u03b4`. -/\ntheorem ApproximatesLinearOn.norm_fderiv_sub_le {A : E \u2192L[\u211d] E} {\u03b4 : \u211d\u22650}\n    (hf : ApproximatesLinearOn f A s \u03b4) (hs : MeasurableSet s) (f' : E \u2192 E \u2192L[\u211d] E)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) : \u2200\u1d50 x \u2202\u03bc.restrict s, \u2016f' x - A\u2016\u208a \u2264 \u03b4 :=\n  by\n  /- The conclusion will hold at the Lebesgue density points of `s` (which have full measure).\n    At such a point `x`, for any `z` and any `\u03b5 > 0` one has for small `r`\n    that `{x} + r \u2022 closed_ball z \u03b5` intersects `s`. At a point `y` in the intersection,\n    `f y - f x` is close both to `f' x (r z)` (by differentiability) and to `A (r z)`\n    (by linear approximation), so these two quantities are close, i.e., `(f' x - A) z` is small. -/\n  filter_upwards [Besicovitch.ae_tendsto_measure_inter_div \u03bc s, ae_restrict_mem hs]\n  -- start from a Lebesgue density point `x`, belonging to `s`.\n  intro x hx xs\n  -- consider an arbitrary vector `z`.\n  apply ContinuousLinearMap.op_norm_le_bound _ \u03b4.2 fun z => _\n  -- to show that `\u2016(f' x - A) z\u2016 \u2264 \u03b4 \u2016z\u2016`, it suffices to do it up to some error that vanishes\n  -- asymptotically in terms of `\u03b5 > 0`.\n  suffices H : \u2200 \u03b5, 0 < \u03b5 \u2192 \u2016(f' x - A) z\u2016 \u2264 (\u03b4 + \u03b5) * (\u2016z\u2016 + \u03b5) + \u2016f' x - A\u2016 * \u03b5\n  \u00b7 have :\n      tendsto (fun \u03b5 : \u211d => ((\u03b4 : \u211d) + \u03b5) * (\u2016z\u2016 + \u03b5) + \u2016f' x - A\u2016 * \u03b5) (\ud835\udcdd[>] 0)\n        (\ud835\udcdd ((\u03b4 + 0) * (\u2016z\u2016 + 0) + \u2016f' x - A\u2016 * 0)) :=\n      tendsto.mono_left (Continuous.tendsto (by continuity) 0) nhdsWithin_le_nhds\n    simp only [add_zero, MulZeroClass.mul_zero] at this\n    apply le_of_tendsto_of_tendsto tendsto_const_nhds this\n    filter_upwards [self_mem_nhdsWithin]\n    exact H\n  -- fix a positive `\u03b5`.\n  intro \u03b5 \u03b5pos\n  -- for small enough `r`, the rescaled ball `r \u2022 closed_ball z \u03b5` intersects `s`, as `x` is a\n  -- density point\n  have B\u2081 : \u2200\u1da0 r in \ud835\udcdd[>] (0 : \u211d), (s \u2229 ({x} + r \u2022 closed_ball z \u03b5)).Nonempty :=\n    eventually_nonempty_inter_smul_of_density_one \u03bc s x hx _ measurableSet_closedBall\n      (measure_closed_ball_pos \u03bc z \u03b5pos).ne'\n  obtain \u27e8\u03c1, \u03c1pos, h\u03c1\u27e9 :\n    \u2203 \u03c1 > 0, ball x \u03c1 \u2229 s \u2286 { y : E | \u2016f y - f x - (f' x) (y - x)\u2016 \u2264 \u03b5 * \u2016y - x\u2016 } :=\n    mem_nhds_within_iff.1 (is_o.def (hf' x xs) \u03b5pos)\n  -- for small enough `r`, the rescaled ball `r \u2022 closed_ball z \u03b5` is included in the set where\n  -- `f y - f x` is well approximated by `f' x (y - x)`.\n  have B\u2082 : \u2200\u1da0 r in \ud835\udcdd[>] (0 : \u211d), {x} + r \u2022 closed_ball z \u03b5 \u2286 ball x \u03c1 :=\n    nhdsWithin_le_nhds\n      (eventually_singleton_add_smul_subset bounded_closed_ball (ball_mem_nhds x \u03c1pos))\n  -- fix a small positive `r` satisfying the above properties, as well as a corresponding `y`.\n  obtain \u27e8r, \u27e8y, \u27e8ys, hy\u27e9\u27e9, r\u03c1, rpos\u27e9 :\n    \u2203 r : \u211d,\n      (s \u2229 ({x} + r \u2022 closed_ball z \u03b5)).Nonempty \u2227 {x} + r \u2022 closed_ball z \u03b5 \u2286 ball x \u03c1 \u2227 0 < r :=\n    (B\u2081.and (B\u2082.and self_mem_nhdsWithin)).exists\n  -- write `y = x + r a` with `a \u2208 closed_ball z \u03b5`.\n  obtain \u27e8a, az, ya\u27e9 : \u2203 a, a \u2208 closed_ball z \u03b5 \u2227 y = x + r \u2022 a :=\n    by\n    simp only [mem_smul_set, image_add_left, mem_preimage, singleton_add] at hy\n    rcases hy with \u27e8a, az, ha\u27e9\n    exact \u27e8a, az, by simp only [ha, add_neg_cancel_left]\u27e9\n  have norm_a : \u2016a\u2016 \u2264 \u2016z\u2016 + \u03b5 :=\n    calc\n      \u2016a\u2016 = \u2016z + (a - z)\u2016 := by simp only [add_sub_cancel'_right]\n      _ \u2264 \u2016z\u2016 + \u2016a - z\u2016 := (norm_add_le _ _)\n      _ \u2264 \u2016z\u2016 + \u03b5 := add_le_add_left (mem_closedBall_iff_norm.1 az) _\n      \n  -- use the approximation properties to control `(f' x - A) a`, and then `(f' x - A) z` as `z` is\n  -- close to `a`.\n  have I : r * \u2016(f' x - A) a\u2016 \u2264 r * (\u03b4 + \u03b5) * (\u2016z\u2016 + \u03b5) :=\n    calc\n      r * \u2016(f' x - A) a\u2016 = \u2016(f' x - A) (r \u2022 a)\u2016 := by\n        simp only [ContinuousLinearMap.map_smul, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le]\n      _ = \u2016f y - f x - A (y - x) - (f y - f x - (f' x) (y - x))\u2016 :=\n        by\n        congr 1\n        simp only [ya, add_sub_cancel', sub_sub_sub_cancel_left, ContinuousLinearMap.coe_sub',\n          eq_self_iff_true, sub_left_inj, Pi.sub_apply, ContinuousLinearMap.map_smul, smul_sub]\n      _ \u2264 \u2016f y - f x - A (y - x)\u2016 + \u2016f y - f x - (f' x) (y - x)\u2016 := (norm_sub_le _ _)\n      _ \u2264 \u03b4 * \u2016y - x\u2016 + \u03b5 * \u2016y - x\u2016 := (add_le_add (hf _ ys _ xs) (h\u03c1 \u27e8r\u03c1 hy, ys\u27e9))\n      _ = r * (\u03b4 + \u03b5) * \u2016a\u2016 :=\n        by\n        simp only [ya, add_sub_cancel', norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le]\n        ring\n      _ \u2264 r * (\u03b4 + \u03b5) * (\u2016z\u2016 + \u03b5) :=\n        mul_le_mul_of_nonneg_left norm_a (mul_nonneg rpos.le (add_nonneg \u03b4.2 \u03b5pos.le))\n      \n  show \u2016(f' x - A) z\u2016 \u2264 (\u03b4 + \u03b5) * (\u2016z\u2016 + \u03b5) + \u2016f' x - A\u2016 * \u03b5\n  exact\n    calc\n      \u2016(f' x - A) z\u2016 = \u2016(f' x - A) a + (f' x - A) (z - a)\u2016 :=\n        by\n        congr 1\n        simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply]\n        abel\n      _ \u2264 \u2016(f' x - A) a\u2016 + \u2016(f' x - A) (z - a)\u2016 := (norm_add_le _ _)\n      _ \u2264 (\u03b4 + \u03b5) * (\u2016z\u2016 + \u03b5) + \u2016f' x - A\u2016 * \u2016z - a\u2016 :=\n        by\n        apply add_le_add\n        \u00b7 rw [mul_assoc] at I\n          exact (mul_le_mul_left rpos).1 I\n        \u00b7 apply ContinuousLinearMap.le_op_norm\n      _ \u2264 (\u03b4 + \u03b5) * (\u2016z\u2016 + \u03b5) + \u2016f' x - A\u2016 * \u03b5 :=\n        add_le_add le_rfl\n          (mul_le_mul_of_nonneg_left (mem_closedBall_iff_norm'.1 az) (norm_nonneg _))\n      \n#align approximates_linear_on.norm_fderiv_sub_le ApproximatesLinearOn.norm_fderiv_sub_le\n\n/-!\n### Measure zero of the image, over non-measurable sets\n\nIf a set has measure `0`, then its image under a differentiable map has measure zero. This doesn't\nrequire the set to be measurable. In the same way, if `f` is differentiable on a set `s` with\nnon-invertible derivative everywhere, then `f '' s` has measure `0`, again without measurability\nassumptions.\n-/\n\n\n/-- A differentiable function maps sets of measure zero to sets of measure zero. -/\ntheorem add_haar_image_eq_zero_of_differentiableOn_of_add_haar_eq_zero (hf : DifferentiableOn \u211d f s)\n    (hs : \u03bc s = 0) : \u03bc (f '' s) = 0 :=\n  by\n  refine' le_antisymm _ (zero_le _)\n  have :\n    \u2200 A : E \u2192L[\u211d] E,\n      \u2203 \u03b4 : \u211d\u22650,\n        0 < \u03b4 \u2227\n          \u2200 (t : Set E) (hf : ApproximatesLinearOn f A t \u03b4),\n            \u03bc (f '' t) \u2264 (Real.toNNReal (|A.det|) + 1 : \u211d\u22650) * \u03bc t :=\n    by\n    intro A\n    let m : \u211d\u22650 := Real.toNNReal (|A.det|) + 1\n    have I : ENNReal.ofReal (|A.det|) < m := by\n      simp only [ENNReal.ofReal, m, lt_add_iff_pos_right, zero_lt_one, ENNReal.coe_lt_coe]\n    rcases((add_haar_image_le_mul_of_det_lt \u03bc A I).And self_mem_nhdsWithin).exists with \u27e8\u03b4, h, h'\u27e9\n    exact \u27e8\u03b4, h', fun t ht => h t f ht\u27e9\n  choose \u03b4 h\u03b4 using this\n  obtain \u27e8t, A, t_disj, t_meas, t_cover, ht, -\u27e9 :\n    \u2203 (t : \u2115 \u2192 Set E)(A : \u2115 \u2192 E \u2192L[\u211d] E),\n      Pairwise (Disjoint on t) \u2227\n        (\u2200 n : \u2115, MeasurableSet (t n)) \u2227\n          (s \u2286 \u22c3 n : \u2115, t n) \u2227\n            (\u2200 n : \u2115, ApproximatesLinearOn f (A n) (s \u2229 t n) (\u03b4 (A n))) \u2227\n              (s.nonempty \u2192 \u2200 n, \u2203 y \u2208 s, A n = fderivWithin \u211d f s y) :=\n    exists_partition_approximatesLinearOn_of_hasFderivWithinAt f s (fderivWithin \u211d f s)\n      (fun x xs => (hf x xs).HasFderivWithinAt) \u03b4 fun A => (h\u03b4 A).1.ne'\n  calc\n    \u03bc (f '' s) \u2264 \u03bc (\u22c3 n, f '' (s \u2229 t n)) :=\n      by\n      apply measure_mono\n      rw [\u2190 image_Union, \u2190 inter_Union]\n      exact image_subset f (subset_inter subset.rfl t_cover)\n    _ \u2264 \u2211' n, \u03bc (f '' (s \u2229 t n)) := (measure_Union_le _)\n    _ \u2264 \u2211' n, (Real.toNNReal (|(A n).det|) + 1 : \u211d\u22650) * \u03bc (s \u2229 t n) :=\n      by\n      apply ENNReal.tsum_le_tsum fun n => _\n      apply (h\u03b4 (A n)).2\n      exact ht n\n    _ \u2264 \u2211' n, (Real.toNNReal (|(A n).det|) + 1 : \u211d\u22650) * 0 :=\n      by\n      refine' ENNReal.tsum_le_tsum fun n => mul_le_mul_left' _ _\n      exact le_trans (measure_mono (inter_subset_left _ _)) (le_of_eq hs)\n    _ = 0 := by simp only [tsum_zero, MulZeroClass.mul_zero]\n    \n#align measure_theory.add_haar_image_eq_zero_of_differentiable_on_of_add_haar_eq_zero MeasureTheory.add_haar_image_eq_zero_of_differentiableOn_of_add_haar_eq_zero\n\n/-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and\na set where the differential is not invertible, then the image of this set has zero measure.\nHere, we give an auxiliary statement towards this result. -/\ntheorem add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (R : \u211d) (hs : s \u2286 closedBall 0 R) (\u03b5 : \u211d\u22650)\n    (\u03b5pos : 0 < \u03b5) (h'f' : \u2200 x \u2208 s, (f' x).det = 0) : \u03bc (f '' s) \u2264 \u03b5 * \u03bc (closedBall 0 R) :=\n  by\n  rcases eq_empty_or_nonempty s with (rfl | h's)\n  \u00b7 simp only [measure_empty, zero_le, image_empty]\n  have :\n    \u2200 A : E \u2192L[\u211d] E,\n      \u2203 \u03b4 : \u211d\u22650,\n        0 < \u03b4 \u2227\n          \u2200 (t : Set E) (hf : ApproximatesLinearOn f A t \u03b4),\n            \u03bc (f '' t) \u2264 (Real.toNNReal (|A.det|) + \u03b5 : \u211d\u22650) * \u03bc t :=\n    by\n    intro A\n    let m : \u211d\u22650 := Real.toNNReal (|A.det|) + \u03b5\n    have I : ENNReal.ofReal (|A.det|) < m := by\n      simp only [ENNReal.ofReal, m, lt_add_iff_pos_right, \u03b5pos, ENNReal.coe_lt_coe]\n    rcases((add_haar_image_le_mul_of_det_lt \u03bc A I).And self_mem_nhdsWithin).exists with \u27e8\u03b4, h, h'\u27e9\n    exact \u27e8\u03b4, h', fun t ht => h t f ht\u27e9\n  choose \u03b4 h\u03b4 using this\n  obtain \u27e8t, A, t_disj, t_meas, t_cover, ht, Af'\u27e9 :\n    \u2203 (t : \u2115 \u2192 Set E)(A : \u2115 \u2192 E \u2192L[\u211d] E),\n      Pairwise (Disjoint on t) \u2227\n        (\u2200 n : \u2115, MeasurableSet (t n)) \u2227\n          (s \u2286 \u22c3 n : \u2115, t n) \u2227\n            (\u2200 n : \u2115, ApproximatesLinearOn f (A n) (s \u2229 t n) (\u03b4 (A n))) \u2227\n              (s.nonempty \u2192 \u2200 n, \u2203 y \u2208 s, A n = f' y) :=\n    exists_partition_approximatesLinearOn_of_hasFderivWithinAt f s f' hf' \u03b4 fun A => (h\u03b4 A).1.ne'\n  calc\n    \u03bc (f '' s) \u2264 \u03bc (\u22c3 n, f '' (s \u2229 t n)) :=\n      by\n      apply measure_mono\n      rw [\u2190 image_Union, \u2190 inter_Union]\n      exact image_subset f (subset_inter subset.rfl t_cover)\n    _ \u2264 \u2211' n, \u03bc (f '' (s \u2229 t n)) := (measure_Union_le _)\n    _ \u2264 \u2211' n, (Real.toNNReal (|(A n).det|) + \u03b5 : \u211d\u22650) * \u03bc (s \u2229 t n) :=\n      by\n      apply ENNReal.tsum_le_tsum fun n => _\n      apply (h\u03b4 (A n)).2\n      exact ht n\n    _ = \u2211' n, \u03b5 * \u03bc (s \u2229 t n) := by\n      congr with n\n      rcases Af' h's n with \u27e8y, ys, hy\u27e9\n      simp only [hy, h'f' y ys, Real.toNNReal_zero, abs_zero, zero_add]\n    _ \u2264 \u03b5 * \u2211' n, \u03bc (closed_ball 0 R \u2229 t n) :=\n      by\n      rw [ENNReal.tsum_mul_left]\n      refine' mul_le_mul_left' (ENNReal.tsum_le_tsum fun n => measure_mono _) _\n      exact inter_subset_inter_left _ hs\n    _ = \u03b5 * \u03bc (\u22c3 n, closed_ball 0 R \u2229 t n) :=\n      by\n      rw [measure_Union]\n      \u00b7 exact pairwise_disjoint_mono t_disj fun n => inter_subset_right _ _\n      \u00b7 intro n\n        exact measurable_set_closed_ball.inter (t_meas n)\n    _ \u2264 \u03b5 * \u03bc (closed_ball 0 R) := by\n      rw [\u2190 inter_Union]\n      exact mul_le_mul_left' (measure_mono (inter_subset_left _ _)) _\n    \n#align measure_theory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux MeasureTheory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux\n\n/-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and\na set where the differential is not invertible, then the image of this set has zero measure. -/\ntheorem add_haar_image_eq_zero_of_det_fderiv_within_eq_zero\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (h'f' : \u2200 x \u2208 s, (f' x).det = 0) :\n    \u03bc (f '' s) = 0 := by\n  suffices H : \u2200 R, \u03bc (f '' (s \u2229 closed_ball 0 R)) = 0\n  \u00b7 apply le_antisymm _ (zero_le _)\n    rw [\u2190 Union_inter_closed_ball_nat s 0]\n    calc\n      \u03bc (f '' \u22c3 n : \u2115, s \u2229 closed_ball 0 n) \u2264 \u2211' n : \u2115, \u03bc (f '' (s \u2229 closed_ball 0 n)) :=\n        by\n        rw [image_Union]\n        exact measure_Union_le _\n      _ \u2264 0 := by simp only [H, tsum_zero, nonpos_iff_eq_zero]\n      \n  intro R\n  have A : \u2200 (\u03b5 : \u211d\u22650) (\u03b5pos : 0 < \u03b5), \u03bc (f '' (s \u2229 closed_ball 0 R)) \u2264 \u03b5 * \u03bc (closed_ball 0 R) :=\n    fun \u03b5 \u03b5pos =>\n    add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux \u03bc\n      (fun x hx => (hf' x hx.1).mono (inter_subset_left _ _)) R (inter_subset_right _ _) \u03b5 \u03b5pos\n      fun x hx => h'f' x hx.1\n  have B : tendsto (fun \u03b5 : \u211d\u22650 => (\u03b5 : \u211d\u22650\u221e) * \u03bc (closed_ball 0 R)) (\ud835\udcdd[>] 0) (\ud835\udcdd 0) :=\n    by\n    have :\n      tendsto (fun \u03b5 : \u211d\u22650 => (\u03b5 : \u211d\u22650\u221e) * \u03bc (closed_ball 0 R)) (\ud835\udcdd 0)\n        (\ud835\udcdd (((0 : \u211d\u22650) : \u211d\u22650\u221e) * \u03bc (closed_ball 0 R))) :=\n      ENNReal.Tendsto.mul_const (ENNReal.tendsto_coe.2 tendsto_id)\n        (Or.inr measure_closed_ball_lt_top.Ne)\n    simp only [MulZeroClass.zero_mul, ENNReal.coe_zero] at this\n    exact tendsto.mono_left this nhdsWithin_le_nhds\n  apply le_antisymm _ (zero_le _)\n  apply ge_of_tendsto B\n  filter_upwards [self_mem_nhdsWithin]\n  exact A\n#align measure_theory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero MeasureTheory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero\n\n/-!\n### Weak measurability statements\n\nWe show that the derivative of a function on a set is almost everywhere measurable, and that the\nimage `f '' s` is measurable if `f` is injective on `s`. The latter statement follows from the\nLusin-Souslin theorem.\n-/\n\n\n/-- The derivative of a function on a measurable set is almost everywhere measurable on this set\nwith respect to Lebesgue measure. Note that, in general, it is not genuinely measurable there,\nas `f'` is not unique (but only on a set of measure `0`, as the argument shows). -/\ntheorem aeMeasurableFderivWithin (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) : AeMeasurable f' (\u03bc.restrict s) :=\n  by\n  /- It suffices to show that `f'` can be uniformly approximated by a measurable function.\n    Fix `\u03b5 > 0`. Thanks to `exists_partition_approximates_linear_on_of_has_fderiv_within_at`, one\n    can find a countable measurable partition of `s` into sets `s \u2229 t n` on which `f` is well\n    approximated by linear maps `A n`. On almost all of `s \u2229 t n`, it follows from\n    `approximates_linear_on.norm_fderiv_sub_le` that `f'` is uniformly approximated by `A n`, which\n    gives the conclusion. -/\n  -- fix a precision `\u03b5`\n  refine' aeMeasurableOfUnifApprox fun \u03b5 \u03b5pos => _\n  let \u03b4 : \u211d\u22650 := \u27e8\u03b5, le_of_lt \u03b5pos\u27e9\n  have \u03b4pos : 0 < \u03b4 := \u03b5pos\n  -- partition `s` into sets `s \u2229 t n` on which `f` is approximated by linear maps `A n`.\n  obtain \u27e8t, A, t_disj, t_meas, t_cover, ht, Af'\u27e9 :\n    \u2203 (t : \u2115 \u2192 Set E)(A : \u2115 \u2192 E \u2192L[\u211d] E),\n      Pairwise (Disjoint on t) \u2227\n        (\u2200 n : \u2115, MeasurableSet (t n)) \u2227\n          (s \u2286 \u22c3 n : \u2115, t n) \u2227\n            (\u2200 n : \u2115, ApproximatesLinearOn f (A n) (s \u2229 t n) \u03b4) \u2227\n              (s.nonempty \u2192 \u2200 n, \u2203 y \u2208 s, A n = f' y) :=\n    exists_partition_approximatesLinearOn_of_hasFderivWithinAt f s f' hf' (fun A => \u03b4) fun A =>\n      \u03b4pos.ne'\n  -- define a measurable function `g` which coincides with `A n` on `t n`.\n  obtain \u27e8g, g_meas, hg\u27e9 :\n    \u2203 g : E \u2192 E \u2192L[\u211d] E, Measurable g \u2227 \u2200 (n : \u2115) (x : E), x \u2208 t n \u2192 g x = A n :=\n    exists_measurable_piecewise_nat t t_meas t_disj (fun n x => A n) fun n => measurable_const\n  refine' \u27e8g, g_meas.ae_measurable, _\u27e9\n  -- reduce to checking that `f'` and `g` are close on almost all of `s \u2229 t n`, for all `n`.\n  suffices H : \u2200\u1d50 x : E \u2202Sum fun n => \u03bc.restrict (s \u2229 t n), dist (g x) (f' x) \u2264 \u03b5\n  \u00b7 have : \u03bc.restrict s \u2264 Sum fun n => \u03bc.restrict (s \u2229 t n) :=\n      by\n      have : s = \u22c3 n, s \u2229 t n := by\n        rw [\u2190 inter_Union]\n        exact subset.antisymm (subset_inter subset.rfl t_cover) (inter_subset_left _ _)\n      conv_lhs => rw [this]\n      exact restrict_Union_le\n    exact ae_mono this H\n  -- fix such an `n`.\n  refine' ae_sum_iff.2 fun n => _\n  -- on almost all `s \u2229 t n`, `f' x` is close to `A n` thanks to\n  -- `approximates_linear_on.norm_fderiv_sub_le`.\n  have E\u2081 : \u2200\u1d50 x : E \u2202\u03bc.restrict (s \u2229 t n), \u2016f' x - A n\u2016\u208a \u2264 \u03b4 :=\n    (ht n).norm_fderiv_sub_le \u03bc (hs.inter (t_meas n)) f' fun x hx =>\n      (hf' x hx.1).mono (inter_subset_left _ _)\n  -- moreover, `g x` is equal to `A n` there.\n  have E\u2082 : \u2200\u1d50 x : E \u2202\u03bc.restrict (s \u2229 t n), g x = A n :=\n    by\n    suffices H : \u2200\u1d50 x : E \u2202\u03bc.restrict (t n), g x = A n\n    exact ae_mono (restrict_mono (inter_subset_right _ _) le_rfl) H\n    filter_upwards [ae_restrict_mem (t_meas n)]\n    exact hg n\n  -- putting these two properties together gives the conclusion.\n  filter_upwards [E\u2081, E\u2082]with x hx1 hx2\n  rw [\u2190 nndist_eq_nnnorm] at hx1\n  rw [hx2, dist_comm]\n  exact hx1\n#align measure_theory.ae_measurable_fderiv_within MeasureTheory.aeMeasurableFderivWithin\n\ntheorem aeMeasurableOfRealAbsDetFderivWithin (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) :\n    AeMeasurable (fun x => ENNReal.ofReal (|(f' x).det|)) (\u03bc.restrict s) :=\n  by\n  apply ennreal.measurable_of_real.comp_ae_measurable\n  refine' continuous_abs.measurable.comp_ae_measurable _\n  refine' continuous_linear_map.continuous_det.measurable.comp_ae_measurable _\n  exact ae_measurable_fderiv_within \u03bc hs hf'\n#align measure_theory.ae_measurable_of_real_abs_det_fderiv_within MeasureTheory.aeMeasurableOfRealAbsDetFderivWithin\n\ntheorem aeMeasurableToNnrealAbsDetFderivWithin (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) :\n    AeMeasurable (fun x => |(f' x).det|.toNNReal) (\u03bc.restrict s) :=\n  by\n  apply measurable_real_to_nnreal.comp_ae_measurable\n  refine' continuous_abs.measurable.comp_ae_measurable _\n  refine' continuous_linear_map.continuous_det.measurable.comp_ae_measurable _\n  exact ae_measurable_fderiv_within \u03bc hs hf'\n#align measure_theory.ae_measurable_to_nnreal_abs_det_fderiv_within MeasureTheory.aeMeasurableToNnrealAbsDetFderivWithin\n\n/-- If a function is differentiable and injective on a measurable set,\nthen the image is measurable.-/\ntheorem measurable_image_of_fderiv_within (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) : MeasurableSet (f '' s) :=\n  haveI : DifferentiableOn \u211d f s := fun x hx => (hf' x hx).DifferentiableWithinAt\n  hs.image_of_continuous_on_inj_on (DifferentiableOn.continuousOn this) hf\n#align measure_theory.measurable_image_of_fderiv_within MeasureTheory.measurable_image_of_fderiv_within\n\n/-- If a function is differentiable and injective on a measurable set `s`, then its restriction\nto `s` is a measurable embedding. -/\ntheorem measurableEmbedding_of_fderiv_within (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) :\n    MeasurableEmbedding (s.restrict f) :=\n  haveI : DifferentiableOn \u211d f s := fun x hx => (hf' x hx).DifferentiableWithinAt\n  this.continuous_on.measurable_embedding hs hf\n#align measure_theory.measurable_embedding_of_fderiv_within MeasureTheory.measurableEmbedding_of_fderiv_within\n\n/-!\n### Proving the estimate for the measure of the image\n\nWe show the formula `\u222b\u207b x in s, ennreal.of_real (|(f' x).det|) \u2202\u03bc = \u03bc (f '' s)`,\nin `lintegral_abs_det_fderiv_eq_add_haar_image`. For this, we show both inequalities in both\ndirections, first up to controlled errors and then letting these errors tend to `0`.\n-/\n\n\ntheorem add_haar_image_le_lintegral_abs_det_fderiv_aux1 (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) {\u03b5 : \u211d\u22650} (\u03b5pos : 0 < \u03b5) :\n    \u03bc (f '' s) \u2264 (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) + 2 * \u03b5 * \u03bc s :=\n  by\n  /- To bound `\u03bc (f '' s)`, we cover `s` by sets where `f` is well-approximated by linear maps\n    `A n` (and where `f'` is almost everywhere close to `A n`), and then use that `f` expands the\n    measure of such a set by at most `(A n).det + \u03b5`. -/\n  have :\n    \u2200 A : E \u2192L[\u211d] E,\n      \u2203 \u03b4 : \u211d\u22650,\n        0 < \u03b4 \u2227\n          (\u2200 B : E \u2192L[\u211d] E, \u2016B - A\u2016 \u2264 \u03b4 \u2192 |B.det - A.det| \u2264 \u03b5) \u2227\n            \u2200 (t : Set E) (g : E \u2192 E) (hf : ApproximatesLinearOn g A t \u03b4),\n              \u03bc (g '' t) \u2264 (ENNReal.ofReal (|A.det|) + \u03b5) * \u03bc t :=\n    by\n    intro A\n    let m : \u211d\u22650 := Real.toNNReal (|A.det|) + \u03b5\n    have I : ENNReal.ofReal (|A.det|) < m := by\n      simp only [ENNReal.ofReal, m, lt_add_iff_pos_right, \u03b5pos, ENNReal.coe_lt_coe]\n    rcases((add_haar_image_le_mul_of_det_lt \u03bc A I).And self_mem_nhdsWithin).exists with \u27e8\u03b4, h, \u03b4pos\u27e9\n    obtain \u27e8\u03b4', \u03b4'pos, h\u03b4'\u27e9 : \u2203 (\u03b4' : \u211d)(H : 0 < \u03b4'), \u2200 B, dist B A < \u03b4' \u2192 dist B.det A.det < \u2191\u03b5 :=\n      continuous_at_iff.1 continuous_linear_map.continuous_det.continuous_at \u03b5 \u03b5pos\n    let \u03b4'' : \u211d\u22650 := \u27e8\u03b4' / 2, (half_pos \u03b4'pos).le\u27e9\n    refine' \u27e8min \u03b4 \u03b4'', lt_min \u03b4pos (half_pos \u03b4'pos), _, _\u27e9\n    \u00b7 intro B hB\n      rw [\u2190 Real.dist_eq]\n      apply (h\u03b4' B _).le\n      rw [dist_eq_norm]\n      calc\n        \u2016B - A\u2016 \u2264 (min \u03b4 \u03b4'' : \u211d\u22650) := hB\n        _ \u2264 \u03b4'' := by simp only [le_refl, NNReal.coe_min, min_le_iff, or_true_iff]\n        _ < \u03b4' := half_lt_self \u03b4'pos\n        \n    \u00b7 intro t g htg\n      exact h t g (htg.mono_num (min_le_left _ _))\n  choose \u03b4 h\u03b4 using this\n  obtain \u27e8t, A, t_disj, t_meas, t_cover, ht, -\u27e9 :\n    \u2203 (t : \u2115 \u2192 Set E)(A : \u2115 \u2192 E \u2192L[\u211d] E),\n      Pairwise (Disjoint on t) \u2227\n        (\u2200 n : \u2115, MeasurableSet (t n)) \u2227\n          (s \u2286 \u22c3 n : \u2115, t n) \u2227\n            (\u2200 n : \u2115, ApproximatesLinearOn f (A n) (s \u2229 t n) (\u03b4 (A n))) \u2227\n              (s.nonempty \u2192 \u2200 n, \u2203 y \u2208 s, A n = f' y) :=\n    exists_partition_approximatesLinearOn_of_hasFderivWithinAt f s f' hf' \u03b4 fun A => (h\u03b4 A).1.ne'\n  calc\n    \u03bc (f '' s) \u2264 \u03bc (\u22c3 n, f '' (s \u2229 t n)) :=\n      by\n      apply measure_mono\n      rw [\u2190 image_Union, \u2190 inter_Union]\n      exact image_subset f (subset_inter subset.rfl t_cover)\n    _ \u2264 \u2211' n, \u03bc (f '' (s \u2229 t n)) := (measure_Union_le _)\n    _ \u2264 \u2211' n, (ENNReal.ofReal (|(A n).det|) + \u03b5) * \u03bc (s \u2229 t n) :=\n      by\n      apply ENNReal.tsum_le_tsum fun n => _\n      apply (h\u03b4 (A n)).2.2\n      exact ht n\n    _ = \u2211' n, \u222b\u207b x in s \u2229 t n, ENNReal.ofReal (|(A n).det|) + \u03b5 \u2202\u03bc := by\n      simp only [lintegral_const, MeasurableSet.univ, measure.restrict_apply, univ_inter]\n    _ \u2264 \u2211' n, \u222b\u207b x in s \u2229 t n, ENNReal.ofReal (|(f' x).det|) + 2 * \u03b5 \u2202\u03bc :=\n      by\n      apply ENNReal.tsum_le_tsum fun n => _\n      apply lintegral_mono_ae\n      filter_upwards [(ht n).norm_fderiv_sub_le \u03bc (hs.inter (t_meas n)) f' fun x hx =>\n          (hf' x hx.1).mono (inter_subset_left _ _)]\n      intro x hx\n      have I : |(A n).det| \u2264 |(f' x).det| + \u03b5 :=\n        calc\n          |(A n).det| = |(f' x).det - ((f' x).det - (A n).det)| :=\n            by\n            congr 1\n            abel\n          _ \u2264 |(f' x).det| + |(f' x).det - (A n).det| := (abs_sub _ _)\n          _ \u2264 |(f' x).det| + \u03b5 := add_le_add le_rfl ((h\u03b4 (A n)).2.1 _ hx)\n          \n      calc\n        ENNReal.ofReal (|(A n).det|) + \u03b5 \u2264 ENNReal.ofReal (|(f' x).det| + \u03b5) + \u03b5 :=\n          add_le_add (ENNReal.ofReal_le_ofReal I) le_rfl\n        _ = ENNReal.ofReal (|(f' x).det|) + 2 * \u03b5 := by\n          simp only [ENNReal.ofReal_add, abs_nonneg, two_mul, add_assoc, NNReal.zero_le_coe,\n            ENNReal.ofReal_coe_nnreal]\n        \n    _ = \u222b\u207b x in \u22c3 n, s \u2229 t n, ENNReal.ofReal (|(f' x).det|) + 2 * \u03b5 \u2202\u03bc :=\n      by\n      have M : \u2200 n : \u2115, MeasurableSet (s \u2229 t n) := fun n => hs.inter (t_meas n)\n      rw [lintegral_Union M]\n      exact pairwise_disjoint_mono t_disj fun n => inter_subset_right _ _\n    _ = \u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) + 2 * \u03b5 \u2202\u03bc :=\n      by\n      have : s = \u22c3 n, s \u2229 t n := by\n        rw [\u2190 inter_Union]\n        exact subset.antisymm (subset_inter subset.rfl t_cover) (inter_subset_left _ _)\n      rw [\u2190 this]\n    _ = (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) + 2 * \u03b5 * \u03bc s := by\n      simp only [lintegral_add_right' _ aeMeasurableConst, set_lintegral_const]\n    \n#align measure_theory.add_haar_image_le_lintegral_abs_det_fderiv_aux1 MeasureTheory.add_haar_image_le_lintegral_abs_det_fderiv_aux1\n\ntheorem add_haar_image_le_lintegral_abs_det_fderiv_aux2 (hs : MeasurableSet s) (h's : \u03bc s \u2260 \u221e)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) :\n    \u03bc (f '' s) \u2264 \u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc :=\n  by\n  -- We just need to let the error tend to `0` in the previous lemma.\n  have :\n    tendsto (fun \u03b5 : \u211d\u22650 => (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) + 2 * \u03b5 * \u03bc s) (\ud835\udcdd[>] 0)\n      (\ud835\udcdd ((\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) + 2 * (0 : \u211d\u22650) * \u03bc s)) :=\n    by\n    apply tendsto.mono_left _ nhdsWithin_le_nhds\n    refine' tendsto_const_nhds.add _\n    refine' ENNReal.Tendsto.mul_const _ (Or.inr h's)\n    exact ENNReal.Tendsto.const_mul (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr ENNReal.coe_ne_top)\n  simp only [add_zero, MulZeroClass.zero_mul, MulZeroClass.mul_zero, ENNReal.coe_zero] at this\n  apply ge_of_tendsto this\n  filter_upwards [self_mem_nhdsWithin]\n  rintro \u03b5 (\u03b5pos : 0 < \u03b5)\n  exact add_haar_image_le_lintegral_abs_det_fderiv_aux1 \u03bc hs hf' \u03b5pos\n#align measure_theory.add_haar_image_le_lintegral_abs_det_fderiv_aux2 MeasureTheory.add_haar_image_le_lintegral_abs_det_fderiv_aux2\n\ntheorem add_haar_image_le_lintegral_abs_det_fderiv (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) :\n    \u03bc (f '' s) \u2264 \u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc :=\n  by\n  /- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using\n    `spanning_sets \u03bc`, and apply the previous result to each of these parts. -/\n  let u n := disjointed (spanning_sets \u03bc) n\n  have u_meas : \u2200 n, MeasurableSet (u n) := by\n    intro n\n    apply MeasurableSet.disjointed fun i => _\n    exact measurable_spanning_sets \u03bc i\n  have A : s = \u22c3 n, s \u2229 u n := by\n    rw [\u2190 inter_Union, union\u1d62_disjointed, Union_spanning_sets, inter_univ]\n  calc\n    \u03bc (f '' s) \u2264 \u2211' n, \u03bc (f '' (s \u2229 u n)) :=\n      by\n      conv_lhs => rw [A, image_Union]\n      exact measure_Union_le _\n    _ \u2264 \u2211' n, \u222b\u207b x in s \u2229 u n, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc :=\n      by\n      apply ENNReal.tsum_le_tsum fun n => _\n      apply\n        add_haar_image_le_lintegral_abs_det_fderiv_aux2 \u03bc (hs.inter (u_meas n)) _ fun x hx =>\n          (hf' x hx.1).mono (inter_subset_left _ _)\n      have : \u03bc (u n) < \u221e :=\n        lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanning_sets_lt_top \u03bc n)\n      exact ne_of_lt (lt_of_le_of_lt (measure_mono (inter_subset_right _ _)) this)\n    _ = \u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc :=\n      by\n      conv_rhs => rw [A]\n      rw [lintegral_Union]\n      \u00b7 intro n\n        exact hs.inter (u_meas n)\n      \u00b7 exact pairwise_disjoint_mono (disjoint_disjointed _) fun n => inter_subset_right _ _\n    \n#align measure_theory.add_haar_image_le_lintegral_abs_det_fderiv MeasureTheory.add_haar_image_le_lintegral_abs_det_fderiv\n\ntheorem lintegral_abs_det_fderiv_le_add_haar_image_aux1 (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) {\u03b5 : \u211d\u22650} (\u03b5pos : 0 < \u03b5) :\n    (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) \u2264 \u03bc (f '' s) + 2 * \u03b5 * \u03bc s :=\n  by\n  /- To bound `\u222b\u207b x in s, ennreal.of_real (|(f' x).det|) \u2202\u03bc`, we cover `s` by sets where `f` is\n    well-approximated by linear maps `A n` (and where `f'` is almost everywhere close to `A n`),\n    and then use that `f` expands the measure of such a set by at least `(A n).det - \u03b5`. -/\n  have :\n    \u2200 A : E \u2192L[\u211d] E,\n      \u2203 \u03b4 : \u211d\u22650,\n        0 < \u03b4 \u2227\n          (\u2200 B : E \u2192L[\u211d] E, \u2016B - A\u2016 \u2264 \u03b4 \u2192 |B.det - A.det| \u2264 \u03b5) \u2227\n            \u2200 (t : Set E) (g : E \u2192 E) (hf : ApproximatesLinearOn g A t \u03b4),\n              ENNReal.ofReal (|A.det|) * \u03bc t \u2264 \u03bc (g '' t) + \u03b5 * \u03bc t :=\n    by\n    intro A\n    obtain \u27e8\u03b4', \u03b4'pos, h\u03b4'\u27e9 : \u2203 (\u03b4' : \u211d)(H : 0 < \u03b4'), \u2200 B, dist B A < \u03b4' \u2192 dist B.det A.det < \u2191\u03b5 :=\n      continuous_at_iff.1 continuous_linear_map.continuous_det.continuous_at \u03b5 \u03b5pos\n    let \u03b4'' : \u211d\u22650 := \u27e8\u03b4' / 2, (half_pos \u03b4'pos).le\u27e9\n    have I'' : \u2200 B : E \u2192L[\u211d] E, \u2016B - A\u2016 \u2264 \u2191\u03b4'' \u2192 |B.det - A.det| \u2264 \u2191\u03b5 :=\n      by\n      intro B hB\n      rw [\u2190 Real.dist_eq]\n      apply (h\u03b4' B _).le\n      rw [dist_eq_norm]\n      exact hB.trans_lt (half_lt_self \u03b4'pos)\n    rcases eq_or_ne A.det 0 with (hA | hA)\n    \u00b7 refine' \u27e8\u03b4'', half_pos \u03b4'pos, I'', _\u27e9\n      simp only [hA, forall_const, MulZeroClass.zero_mul, ENNReal.ofReal_zero, imp_true_iff,\n        zero_le, abs_zero]\n    let m : \u211d\u22650 := Real.toNNReal (|A.det|) - \u03b5\n    have I : (m : \u211d\u22650\u221e) < ENNReal.ofReal (|A.det|) :=\n      by\n      simp only [ENNReal.ofReal, WithTop.coe_sub]\n      apply ENNReal.sub_lt_self ENNReal.coe_ne_top\n      \u00b7 simpa only [abs_nonpos_iff, Real.toNNReal_eq_zero, ENNReal.coe_eq_zero, Ne.def] using hA\n      \u00b7 simp only [\u03b5pos.ne', ENNReal.coe_eq_zero, Ne.def, not_false_iff]\n    rcases((mul_le_add_haar_image_of_lt_det \u03bc A I).And self_mem_nhdsWithin).exists with \u27e8\u03b4, h, \u03b4pos\u27e9\n    refine' \u27e8min \u03b4 \u03b4'', lt_min \u03b4pos (half_pos \u03b4'pos), _, _\u27e9\n    \u00b7 intro B hB\n      apply I'' _ (hB.trans _)\n      simp only [le_refl, NNReal.coe_min, min_le_iff, or_true_iff]\n    \u00b7 intro t g htg\n      rcases eq_or_ne (\u03bc t) \u221e with (ht | ht)\n      \u00b7\n        simp only [ht, \u03b5pos.ne', WithTop.mul_top, ENNReal.coe_eq_zero, le_top, Ne.def,\n          not_false_iff, _root_.add_top]\n      have := h t g (htg.mono_num (min_le_left _ _))\n      rwa [WithTop.coe_sub, ENNReal.sub_mul, tsub_le_iff_right] at this\n      simp only [ht, imp_true_iff, Ne.def, not_false_iff]\n  choose \u03b4 h\u03b4 using this\n  obtain \u27e8t, A, t_disj, t_meas, t_cover, ht, -\u27e9 :\n    \u2203 (t : \u2115 \u2192 Set E)(A : \u2115 \u2192 E \u2192L[\u211d] E),\n      Pairwise (Disjoint on t) \u2227\n        (\u2200 n : \u2115, MeasurableSet (t n)) \u2227\n          (s \u2286 \u22c3 n : \u2115, t n) \u2227\n            (\u2200 n : \u2115, ApproximatesLinearOn f (A n) (s \u2229 t n) (\u03b4 (A n))) \u2227\n              (s.nonempty \u2192 \u2200 n, \u2203 y \u2208 s, A n = f' y) :=\n    exists_partition_approximatesLinearOn_of_hasFderivWithinAt f s f' hf' \u03b4 fun A => (h\u03b4 A).1.ne'\n  have s_eq : s = \u22c3 n, s \u2229 t n := by\n    rw [\u2190 inter_Union]\n    exact subset.antisymm (subset_inter subset.rfl t_cover) (inter_subset_left _ _)\n  calc\n    (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) =\n        \u2211' n, \u222b\u207b x in s \u2229 t n, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc :=\n      by\n      conv_lhs => rw [s_eq]\n      rw [lintegral_Union]\n      \u00b7 exact fun n => hs.inter (t_meas n)\n      \u00b7 exact pairwise_disjoint_mono t_disj fun n => inter_subset_right _ _\n    _ \u2264 \u2211' n, \u222b\u207b x in s \u2229 t n, ENNReal.ofReal (|(A n).det|) + \u03b5 \u2202\u03bc :=\n      by\n      apply ENNReal.tsum_le_tsum fun n => _\n      apply lintegral_mono_ae\n      filter_upwards [(ht n).norm_fderiv_sub_le \u03bc (hs.inter (t_meas n)) f' fun x hx =>\n          (hf' x hx.1).mono (inter_subset_left _ _)]\n      intro x hx\n      have I : |(f' x).det| \u2264 |(A n).det| + \u03b5 :=\n        calc\n          |(f' x).det| = |(A n).det + ((f' x).det - (A n).det)| :=\n            by\n            congr 1\n            abel\n          _ \u2264 |(A n).det| + |(f' x).det - (A n).det| := (abs_add _ _)\n          _ \u2264 |(A n).det| + \u03b5 := add_le_add le_rfl ((h\u03b4 (A n)).2.1 _ hx)\n          \n      calc\n        ENNReal.ofReal (|(f' x).det|) \u2264 ENNReal.ofReal (|(A n).det| + \u03b5) :=\n          ENNReal.ofReal_le_ofReal I\n        _ = ENNReal.ofReal (|(A n).det|) + \u03b5 := by\n          simp only [ENNReal.ofReal_add, abs_nonneg, NNReal.zero_le_coe, ENNReal.ofReal_coe_nnreal]\n        \n    _ = \u2211' n, ENNReal.ofReal (|(A n).det|) * \u03bc (s \u2229 t n) + \u03b5 * \u03bc (s \u2229 t n) := by\n      simp only [set_lintegral_const, lintegral_add_right _ measurable_const]\n    _ \u2264 \u2211' n, \u03bc (f '' (s \u2229 t n)) + \u03b5 * \u03bc (s \u2229 t n) + \u03b5 * \u03bc (s \u2229 t n) :=\n      by\n      refine' ENNReal.tsum_le_tsum fun n => add_le_add_right _ _\n      exact (h\u03b4 (A n)).2.2 _ _ (ht n)\n    _ = \u03bc (f '' s) + 2 * \u03b5 * \u03bc s := by\n      conv_rhs => rw [s_eq]\n      rw [image_Union, measure_Union]; rotate_left\n      \u00b7 intro i j hij\n        apply Disjoint.image _ hf (inter_subset_left _ _) (inter_subset_left _ _)\n        exact Disjoint.mono (inter_subset_right _ _) (inter_subset_right _ _) (t_disj hij)\n      \u00b7 intro i\n        exact\n          measurable_image_of_fderiv_within (hs.inter (t_meas i))\n            (fun x hx => (hf' x hx.1).mono (inter_subset_left _ _))\n            (hf.mono (inter_subset_left _ _))\n      rw [measure_Union]; rotate_left\n      \u00b7 exact pairwise_disjoint_mono t_disj fun i => inter_subset_right _ _\n      \u00b7 exact fun i => hs.inter (t_meas i)\n      rw [\u2190 ENNReal.tsum_mul_left, \u2190 ENNReal.tsum_add]\n      congr 1\n      ext1 i\n      rw [mul_assoc, two_mul, add_assoc]\n    \n#align measure_theory.lintegral_abs_det_fderiv_le_add_haar_image_aux1 MeasureTheory.lintegral_abs_det_fderiv_le_add_haar_image_aux1\n\ntheorem lintegral_abs_det_fderiv_le_add_haar_image_aux2 (hs : MeasurableSet s) (h's : \u03bc s \u2260 \u221e)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) :\n    (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) \u2264 \u03bc (f '' s) :=\n  by\n  -- We just need to let the error tend to `0` in the previous lemma.\n  have :\n    tendsto (fun \u03b5 : \u211d\u22650 => \u03bc (f '' s) + 2 * \u03b5 * \u03bc s) (\ud835\udcdd[>] 0)\n      (\ud835\udcdd (\u03bc (f '' s) + 2 * (0 : \u211d\u22650) * \u03bc s)) :=\n    by\n    apply tendsto.mono_left _ nhdsWithin_le_nhds\n    refine' tendsto_const_nhds.add _\n    refine' ENNReal.Tendsto.mul_const _ (Or.inr h's)\n    exact ENNReal.Tendsto.const_mul (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr ENNReal.coe_ne_top)\n  simp only [add_zero, MulZeroClass.zero_mul, MulZeroClass.mul_zero, ENNReal.coe_zero] at this\n  apply ge_of_tendsto this\n  filter_upwards [self_mem_nhdsWithin]\n  rintro \u03b5 (\u03b5pos : 0 < \u03b5)\n  exact lintegral_abs_det_fderiv_le_add_haar_image_aux1 \u03bc hs hf' hf \u03b5pos\n#align measure_theory.lintegral_abs_det_fderiv_le_add_haar_image_aux2 MeasureTheory.lintegral_abs_det_fderiv_le_add_haar_image_aux2\n\ntheorem lintegral_abs_det_fderiv_le_add_haar_image (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) :\n    (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) \u2264 \u03bc (f '' s) :=\n  by\n  /- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using\n    `spanning_sets \u03bc`, and apply the previous result to each of these parts. -/\n  let u n := disjointed (spanning_sets \u03bc) n\n  have u_meas : \u2200 n, MeasurableSet (u n) := by\n    intro n\n    apply MeasurableSet.disjointed fun i => _\n    exact measurable_spanning_sets \u03bc i\n  have A : s = \u22c3 n, s \u2229 u n := by\n    rw [\u2190 inter_Union, union\u1d62_disjointed, Union_spanning_sets, inter_univ]\n  calc\n    (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) =\n        \u2211' n, \u222b\u207b x in s \u2229 u n, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc :=\n      by\n      conv_lhs => rw [A]\n      rw [lintegral_Union]\n      \u00b7 intro n\n        exact hs.inter (u_meas n)\n      \u00b7 exact pairwise_disjoint_mono (disjoint_disjointed _) fun n => inter_subset_right _ _\n    _ \u2264 \u2211' n, \u03bc (f '' (s \u2229 u n)) :=\n      by\n      apply ENNReal.tsum_le_tsum fun n => _\n      apply\n        lintegral_abs_det_fderiv_le_add_haar_image_aux2 \u03bc (hs.inter (u_meas n)) _\n          (fun x hx => (hf' x hx.1).mono (inter_subset_left _ _)) (hf.mono (inter_subset_left _ _))\n      have : \u03bc (u n) < \u221e :=\n        lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanning_sets_lt_top \u03bc n)\n      exact ne_of_lt (lt_of_le_of_lt (measure_mono (inter_subset_right _ _)) this)\n    _ = \u03bc (f '' s) := by\n      conv_rhs => rw [A, image_Union]\n      rw [measure_Union]\n      \u00b7 intro i j hij\n        apply Disjoint.image _ hf (inter_subset_left _ _) (inter_subset_left _ _)\n        exact\n          Disjoint.mono (inter_subset_right _ _) (inter_subset_right _ _)\n            (disjoint_disjointed _ hij)\n      \u00b7 intro i\n        exact\n          measurable_image_of_fderiv_within (hs.inter (u_meas i))\n            (fun x hx => (hf' x hx.1).mono (inter_subset_left _ _))\n            (hf.mono (inter_subset_left _ _))\n    \n#align measure_theory.lintegral_abs_det_fderiv_le_add_haar_image MeasureTheory.lintegral_abs_det_fderiv_le_add_haar_image\n\n/-- Change of variable formula for differentiable functions, set version: if a function `f` is\ninjective and differentiable on a measurable set `s`, then the measure of `f '' s` is given by the\nintegral of `|(f' x).det|` on `s`.\nNote that the measurability of `f '' s` is given by `measurable_image_of_fderiv_within`. -/\ntheorem lintegral_abs_det_fderiv_eq_add_haar_image (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) :\n    (\u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) \u2202\u03bc) = \u03bc (f '' s) :=\n  le_antisymm (lintegral_abs_det_fderiv_le_add_haar_image \u03bc hs hf' hf)\n    (add_haar_image_le_lintegral_abs_det_fderiv \u03bc hs hf')\n#align measure_theory.lintegral_abs_det_fderiv_eq_add_haar_image MeasureTheory.lintegral_abs_det_fderiv_eq_add_haar_image\n\n/-- Change of variable formula for differentiable functions, set version: if a function `f` is\ninjective and differentiable on a measurable set `s`, then the pushforward of the measure with\ndensity `|(f' x).det|` on `s` is the Lebesgue measure on the image set. This version requires\nthat `f` is measurable, as otherwise `measure.map f` is zero per our definitions.\nFor a version without measurability assumption but dealing with the restricted\nfunction `s.restrict f`, see `restrict_map_with_density_abs_det_fderiv_eq_add_haar`.\n-/\ntheorem map_withDensity_abs_det_fderiv_eq_add_haar (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) (h'f : Measurable f) :\n    Measure.map f ((\u03bc.restrict s).withDensity fun x => ENNReal.ofReal (|(f' x).det|)) =\n      \u03bc.restrict (f '' s) :=\n  by\n  apply measure.ext fun t ht => _\n  rw [map_apply h'f ht, with_density_apply _ (h'f ht), measure.restrict_apply ht,\n    restrict_restrict (h'f ht),\n    lintegral_abs_det_fderiv_eq_add_haar_image \u03bc ((h'f ht).inter hs)\n      (fun x hx => (hf' x hx.2).mono (inter_subset_right _ _)) (hf.mono (inter_subset_right _ _)),\n    image_preimage_inter]\n#align measure_theory.map_with_density_abs_det_fderiv_eq_add_haar MeasureTheory.map_withDensity_abs_det_fderiv_eq_add_haar\n\n/-- Change of variable formula for differentiable functions, set version: if a function `f` is\ninjective and differentiable on a measurable set `s`, then the pushforward of the measure with\ndensity `|(f' x).det|` on `s` is the Lebesgue measure on the image set. This version is expressed\nin terms of the restricted function `s.restrict f`.\nFor a version for the original function, but with a measurability assumption,\nsee `map_with_density_abs_det_fderiv_eq_add_haar`.\n-/\ntheorem restrict_map_withDensity_abs_det_fderiv_eq_add_haar (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) :\n    Measure.map (s.restrict f) (comap coe (\u03bc.withDensity fun x => ENNReal.ofReal (|(f' x).det|))) =\n      \u03bc.restrict (f '' s) :=\n  by\n  obtain \u27e8u, u_meas, uf\u27e9 : \u2203 u, Measurable u \u2227 eq_on u f s := by\n    classical\n      refine' \u27e8piecewise s f 0, _, piecewise_eq_on _ _ _\u27e9\n      refine' ContinuousOn.measurable_piecewise _ continuous_zero.continuous_on hs\n      have : DifferentiableOn \u211d f s := fun x hx => (hf' x hx).DifferentiableWithinAt\n      exact this.continuous_on\n  have u' : \u2200 x \u2208 s, HasFderivWithinAt u (f' x) s x := fun x hx =>\n    (hf' x hx).congr (fun y hy => uf hy) (uf hx)\n  set F : s \u2192 E := u \u2218 coe with hF\n  have A :\n    measure.map F (comap coe (\u03bc.with_density fun x => ENNReal.ofReal (|(f' x).det|))) =\n      \u03bc.restrict (u '' s) :=\n    by\n    rw [hF, \u2190 measure.map_map u_meas measurable_subtype_coe, map_comap_subtype_coe hs,\n      restrict_with_density hs]\n    exact map_with_density_abs_det_fderiv_eq_add_haar \u03bc hs u' (hf.congr uf.symm) u_meas\n  rw [uf.image_eq] at A\n  have : F = s.restrict f := by\n    ext x\n    exact uf x.2\n  rwa [this] at A\n#align measure_theory.restrict_map_with_density_abs_det_fderiv_eq_add_haar MeasureTheory.restrict_map_withDensity_abs_det_fderiv_eq_add_haar\n\n/-! ### Change of variable formulas in integrals -/\n\n\n/- Change of variable formula for differentiable functions: if a function `f` is\ninjective and differentiable on a measurable set `s`, then the Lebesgue integral of a function\n`g : E \u2192 \u211d\u22650\u221e` on `f '' s` coincides with the integral of `|(f' x).det| * g \u2218 f` on `s`.\nNote that the measurability of `f '' s` is given by `measurable_image_of_fderiv_within`. -/\ntheorem lintegral_image_eq_lintegral_abs_det_fderiv_mul (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) (g : E \u2192 \u211d\u22650\u221e) :\n    (\u222b\u207b x in f '' s, g x \u2202\u03bc) = \u222b\u207b x in s, ENNReal.ofReal (|(f' x).det|) * g (f x) \u2202\u03bc :=\n  by\n  rw [\u2190 restrict_map_with_density_abs_det_fderiv_eq_add_haar \u03bc hs hf' hf,\n    (measurable_embedding_of_fderiv_within hs hf' hf).lintegral_map]\n  have : \u2200 x : s, g (s.restrict f x) = (g \u2218 f) x := fun x => rfl\n  simp only [this]\n  rw [\u2190 (MeasurableEmbedding.subtype_coe hs).lintegral_map, map_comap_subtype_coe hs,\n    set_lintegral_with_density_eq_set_lintegral_mul_non_measurable\u2080 _ _ _ hs]\n  \u00b7 rfl\n  \u00b7 simp only [eventually_true, ENNReal.ofReal_lt_top]\n  \u00b7 exact ae_measurable_of_real_abs_det_fderiv_within \u03bc hs hf'\n#align measure_theory.lintegral_image_eq_lintegral_abs_det_fderiv_mul MeasureTheory.lintegral_image_eq_lintegral_abs_det_fderiv_mul\n\n/-- Integrability in the change of variable formula for differentiable functions: if a\nfunction `f` is injective and differentiable on a measurable set `s`, then a function\n`g : E \u2192 F` is integrable on `f '' s` if and only if `|(f' x).det| \u2022 g \u2218 f` is\nintegrable on `s`. -/\ntheorem integrableOn_image_iff_integrableOn_abs_det_fderiv_smul (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) (g : E \u2192 F) :\n    IntegrableOn g (f '' s) \u03bc \u2194 IntegrableOn (fun x => |(f' x).det| \u2022 g (f x)) s \u03bc :=\n  by\n  rw [integrable_on, \u2190 restrict_map_with_density_abs_det_fderiv_eq_add_haar \u03bc hs hf' hf,\n    (measurable_embedding_of_fderiv_within hs hf' hf).integrable_map_iff]\n  change integrable ((g \u2218 f) \u2218 (coe : s \u2192 E)) _ \u2194 _\n  rw [\u2190 (MeasurableEmbedding.subtype_coe hs).integrable_map_iff, map_comap_subtype_coe hs]\n  simp only [ENNReal.ofReal]\n  rw [restrict_with_density hs, integrable_with_density_iff_integrable_coe_smul\u2080, integrable_on]\n  \u00b7 congr 2 with x\n    rw [Real.coe_toNNReal]\n    exact abs_nonneg _\n  \u00b7 exact ae_measurable_to_nnreal_abs_det_fderiv_within \u03bc hs hf'\n#align measure_theory.integrable_on_image_iff_integrable_on_abs_det_fderiv_smul MeasureTheory.integrableOn_image_iff_integrableOn_abs_det_fderiv_smul\n\n/-- Change of variable formula for differentiable functions: if a function `f` is\ninjective and differentiable on a measurable set `s`, then the Bochner integral of a function\n`g : E \u2192 F` on `f '' s` coincides with the integral of `|(f' x).det| \u2022 g \u2218 f` on `s`. -/\ntheorem integral_image_eq_integral_abs_det_fderiv_smul [CompleteSpace F] (hs : MeasurableSet s)\n    (hf' : \u2200 x \u2208 s, HasFderivWithinAt f (f' x) s x) (hf : InjOn f s) (g : E \u2192 F) :\n    (\u222b x in f '' s, g x \u2202\u03bc) = \u222b x in s, |(f' x).det| \u2022 g (f x) \u2202\u03bc :=\n  by\n  rw [\u2190 restrict_map_with_density_abs_det_fderiv_eq_add_haar \u03bc hs hf' hf,\n    (measurable_embedding_of_fderiv_within hs hf' hf).integral_map]\n  have : \u2200 x : s, g (s.restrict f x) = (g \u2218 f) x := fun x => rfl\n  simp only [this, ENNReal.ofReal]\n  rw [\u2190 (MeasurableEmbedding.subtype_coe hs).integral_map, map_comap_subtype_coe hs,\n    set_integral_withDensity_eq_set_integral_smul\u2080\n      (ae_measurable_to_nnreal_abs_det_fderiv_within \u03bc hs hf') _ hs]\n  congr with x\n  conv_rhs => rw [\u2190 Real.coe_toNNReal _ (abs_nonneg (f' x).det)]\n  rfl\n#align measure_theory.integral_image_eq_integral_abs_det_fderiv_smul MeasureTheory.integral_image_eq_integral_abs_det_fderiv_smul\n\n/-- Change of variable formula for differentiable functions (one-variable version): if a function\n`f` is injective and differentiable on a measurable set `s \u2286 \u211d`, then the Bochner integral of a\nfunction `g : \u211d \u2192 F` on `f '' s` coincides with the integral of `|(f' x).det| \u2022 g \u2218 f` on `s`. -/\ntheorem integral_image_eq_integral_abs_deriv_smul {s : Set \u211d} {f : \u211d \u2192 \u211d} {f' : \u211d \u2192 \u211d}\n    [CompleteSpace F] (hs : MeasurableSet s) (hf' : \u2200 x \u2208 s, HasDerivWithinAt f (f' x) s x)\n    (hf : InjOn f s) (g : \u211d \u2192 F) : (\u222b x in f '' s, g x) = \u222b x in s, |f' x| \u2022 g (f x) :=\n  by\n  convert integral_image_eq_integral_abs_det_fderiv_smul volume hs\n      (fun x hx => (hf' x hx).HasFderivWithinAt) hf g\n  ext1 x\n  rw [(by\n      ext\n      simp : (1 : \u211d \u2192L[\u211d] \u211d).smul_right (f' x) = f' x \u2022 (1 : \u211d \u2192L[\u211d] \u211d))]\n  rw [ContinuousLinearMap.det, ContinuousLinearMap.coe_smul]\n  have : ((1 : \u211d \u2192L[\u211d] \u211d) : \u211d \u2192\u2097[\u211d] \u211d) = (1 : \u211d \u2192\u2097[\u211d] \u211d) := by rfl\n  rw [this, LinearMap.det_smul, FiniteDimensional.finrank_self]\n  suffices (1 : \u211d \u2192\u2097[\u211d] \u211d).det = 1 by\n    rw [this]\n    simp\n  exact LinearMap.det_id\n#align measure_theory.integral_image_eq_integral_abs_deriv_smul MeasureTheory.integral_image_eq_integral_abs_deriv_smul\n\ntheorem integral_target_eq_integral_abs_det_fderiv_smul [CompleteSpace F] {f : LocalHomeomorph E E}\n    (hf' : \u2200 x \u2208 f.source, HasFderivAt f (f' x) x) (g : E \u2192 F) :\n    (\u222b x in f.target, g x \u2202\u03bc) = \u222b x in f.source, |(f' x).det| \u2022 g (f x) \u2202\u03bc :=\n  by\n  have : f '' f.source = f.target := LocalEquiv.image_source_eq_target f.to_local_equiv\n  rw [\u2190 this]\n  apply integral_image_eq_integral_abs_det_fderiv_smul \u03bc f.open_source.measurable_set _ f.inj_on\n  intro x hx\n  exact (hf' x hx).HasFderivWithinAt\n#align measure_theory.integral_target_eq_integral_abs_det_fderiv_smul MeasureTheory.integral_target_eq_integral_abs_det_fderiv_smul\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Function/Jacobian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7419040798664469}}
{"text": "import NBG.SetTheory.Defs\n\n\n-- 1. AxiomExtensionality\naxiom AxiomExtensionality :\n  \u2200X Y: Class, (X\uff1dY \u2194 \u2200z, (z \u2208 X \u2194 z \u2208 Y))\n\ndef ClassSubset (X Y : Class) : Prop :=\n  \u2200z:Class, z \u2208 X \u2192 z \u2208 Y\ninstance : HasSubset Class where\n  Subset := ClassSubset\nnotation:50 X \" \u228a \" Y => (ClassSubset X Y) \u2227 \u00ac (X\uff1dY)\nnotation:50 X \" \u2284 \" Y => \u00ac ClassSubset X Y\nnotation:50 X \" \u2288 \" Y => \u00ac ClassSubset X Y\n\n-- class equality\ntheorem ClassEq.refl (X : Class):\n  X\uff1dX := by {\n  rw [AxiomExtensionality];\n  intro z;\n  exact \u27e8fun h => h,fun h => h\u27e9;\n}\n\ntheorem ClassEq.symm {X Y : Class}:\n  X\uff1dY \u2192 Y\uff1dX := by {\n  rw [AxiomExtensionality, AxiomExtensionality];\n  intro h;\n  exact fun z => (h z).symm;\n}\n\ntheorem ClassEq.trans {X Y Z : Class}:\n  X\uff1dY \u2192 Y\uff1dZ \u2192 X\uff1dZ := by {\n  rw [AxiomExtensionality,\n      AxiomExtensionality,\n      AxiomExtensionality];\n  intro h1 h2 z;\n  rw [h1,h2];\n  exact \u27e8fun h => h,fun h => h\u27e9;\n}\n\n-- -- class in\n-- private theorem EqClassEqIn' {X Y Z: Class}:\n--   X \uff1d Y \u2192 (X \u2208 Z \u2192 Y \u2208 Z) := by {\n--   intro h hx;\n--   by_cases hy: Y \u2208 Z;\n--   {exact hy;}\n--   {\n--     apply False.elim;\n--     sorry;\n--   }\n-- }\n\n-- theorem EqClassEqIn (X Y Z: Class):\n--   X \uff1d Y \u2192 (X \u2208 Z \u2194 Y \u2208 Z) := by {\n--   intro h;\n--   apply Iff.intro;\n--   {exact EqClassEqIn' h;}\n--   {exact EqClassEqIn' (ClassEq.symm h);}\n-- }\n\n\n-- class subset\ntheorem ClassSubset.refl (X : Class):\n  X\u2282X := fun _ => (fun h => h)\n\ntheorem ClassSubsetSymmImplyEq {X Y : Class}:\n  X\u2282Y \u2192 Y\u2282X \u2192 X\uff1dY := by {\n  rw [AxiomExtensionality];\n  exact fun h1 h2 z => \u27e8h1 z,h2 z\u27e9;\n}\n\ntheorem ClassSubset.trans {X Y Z : Class}:\n  X\u2282Y \u2192 Y\u2282Z \u2192 X\u2282Z :=\nfun h1 h2 z h => h2 z (h1 z h)\n\ninstance : LE Class where\n  le := ClassSubset\n\nexample {X Y : Class} : X \u2264 Y \u2192 Y \u2264 Z \u2192 X \u2264 Z :=\nClassSubset.trans\n\ntheorem EqIffSubsetMutually (X Y : Class):\n  X\uff1dY \u2194 (X \u2282 Y \u2227 Y \u2282 X) := by {\n    rw [AxiomExtensionality];\n    apply Iff.intro;\n    case mp => {\n      intro h;\n      exact \u27e8fun z => (h z).1,fun z => (h z).2\u27e9\n    }\n    case mpr => {\n      exact fun h z => \u27e8h.1 z,h.2 z\u27e9\n    }\n}\n\ntheorem ClassEqMenberImpMenber {x y z: Class}:\n  x \uff1d y \u2192 y \u2208 z \u2192 x \u2208 z :=\n  fun h1 h2 => @RewiteClass (fun x => x \u2208 z) x y \u27e8h1,h2\u27e9\n\n\ndef isUnique (p : Class \u2192 Prop) :=\n  \u2200 (X Y : Class), p X \u2192 p Y \u2192 (X \uff1d Y)\n\n\n", "meta": {"author": "furea2", "repo": "NBG", "sha": "51b45e0b08c1d0090430b0d898de4fc1b7bc09d7", "save_path": "github-repos/lean/furea2-NBG", "path": "github-repos/lean/furea2-NBG/NBG-51b45e0b08c1d0090430b0d898de4fc1b7bc09d7/NBG/SetTheory/Axioms/Extensionality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7419040769513959}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\n\nimport algebra.triv_sq_zero_ext\n\n/-!\n# Dual numbers\n\nThe dual numbers over `R` are of the form `a + b\u03b5`, where `a` and `b` are typically elements of a\ncommutative ring `R`, and `\u03b5` is a symbol satisfying `\u03b5^2 = 0`. They are a special case of\n`triv_sq_zero_ext R M` with `M = R`.\n\n## Notation\n\nIn the `dual_number` locale:\n\n* `R[\u03b5]` is a shorthand for `dual_number R`\n* `\u03b5` is a shorthand for `dual_number.eps`\n\n## Main definitions\n\n* `dual_number`\n* `dual_number.eps`\n* `dual_number.lift`\n\n## Implementation notes\n\nRather than duplicating the API of `triv_sq_zero_ext`, this file reuses the functions there.\n\n## References\n\n* https://en.wikipedia.org/wiki/Dual_number\n-/\n\nvariables {R : Type*}\n\n/-- The type of dual numbers, numbers of the form $a + b\u03b5$ where $\u03b5^2 = 0$.-/\nabbreviation dual_number (R : Type*) : Type* := triv_sq_zero_ext R R\n\n/-- The unit element $\u03b5$ that squares to zero. -/\ndef dual_number.eps [has_zero R] [has_one R] : dual_number R := triv_sq_zero_ext.inr 1\n\nlocalized \"notation `\u03b5` := dual_number.eps\" in dual_number\nlocalized \"postfix `[\u03b5]`:1025 := dual_number\" in dual_number\n\nopen_locale dual_number\n\nnamespace dual_number\n\nopen triv_sq_zero_ext\n\n@[simp] \n\n/-- A version of `triv_sq_zero_ext.snd_mul` with `*` instead of `\u2022`. -/\n@[simp] lemma snd_mul [semiring R] (x y : R[\u03b5]) : snd (x * y) = fst x * snd y + fst y * snd x :=\nsnd_mul _ _\n\n@[simp] lemma eps_mul_eps [semiring R] : (\u03b5 * \u03b5 : R[\u03b5]) = 0 := inr_mul_inr _ _ _\n\n@[simp] lemma inr_eq_smul_eps [mul_zero_one_class R] (r : R) : inr r = (r \u2022 \u03b5 : R[\u03b5]) :=\next (mul_zero r).symm (mul_one r).symm\n\n/-- For two algebra morphisms out of `R[\u03b5]` to agree, it suffices for them to agree on `\u03b5`. -/\n@[ext] lemma alg_hom_ext {A} [comm_semiring R] [semiring A] [algebra R A]\n  \u2983f g : R[\u03b5] \u2192\u2090[R] A\u2984 (h : f \u03b5 = g \u03b5) : f = g :=\nalg_hom_ext' $ linear_map.ext_ring $ h\n\nvariables {A : Type*} [comm_semiring R] [semiring A] [algebra R A]\n\n/-- A universal property of the dual numbers, providing a unique `R[\u03b5] \u2192\u2090[R] A` for every element\nof `A` which squares to `0`.\n\nThis isomorphism is named to match the very similar `complex.lift`. -/\n@[simps {attrs := []}]\ndef lift : {e : A // e * e = 0} \u2243 (R[\u03b5] \u2192\u2090[R] A) :=\nequiv.trans\n  (show {e : A // e * e = 0} \u2243 {f : R \u2192\u2097[R] A // \u2200 x y, f x * f y = 0}, from\n    (linear_map.ring_lmap_equiv_self R \u2115 A).symm.to_equiv.subtype_equiv $ \u03bb a, begin\n      dsimp,\n      simp_rw smul_mul_smul,\n      refine \u27e8\u03bb h x y, h.symm \u25b8 smul_zero _, \u03bb h, by simpa using h 1 1\u27e9,\n    end)\n  triv_sq_zero_ext.lift\n\n/- When applied to `\u03b5`, `dual_number.lift` produces the element of `A` that squares to 0. -/\n@[simp]\nlemma lift_apply_eps (e : {e : A // e * e = 0}) : lift e (\u03b5 : R[\u03b5]) = e :=\n(triv_sq_zero_ext.lift_aux_apply_inr _ _ _).trans $ one_smul _ _\n\n/- Lifting `dual_number.eps` itself gives the identity. -/\n@[simp]\nlemma lift_eps : lift \u27e8\u03b5, by exact eps_mul_eps\u27e9 = alg_hom.id R R[\u03b5] :=\nalg_hom_ext $ lift_apply_eps _\n\nend dual_number\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/dual_number.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7419040762747813}}
{"text": "-- Notes 12/5/2019\n\n/- Talking about logics\n\nWe don't have just one logic; we have many\n- predicate logic\n    - the language of predicate logic: variables, functions, \n- propositional logic\n- some other logics (temporal logic)\n\n\n- functions\n- inductive types\n\ntypes we have:\n- true\n- false\n- a = b\n    - introduction rule: eq.refl\n- P \u2227 Q\n    - introduction rule: and.intro\n- P \u2228 Q\n    - introduction rule: or.intro_left / or.intro_right\n- P \u2192 Q\n- P \u2194 Q\n    - introduction rule: iff.intro\n- \u00acP\n- \u2200 (p : P), Q\n- \u2203 (p: P), Q\n-/\n\n\n/-\n\nSample propositions:\n\nIf there's some P everyone likes, then everyone likes some P\n-/\n\ninductive Person : Type\ninductive Likes : Person \u2192 Person \u2192 Prop\n\nexample : (\u2203 (p : Person), \u2200 (q : Person), Likes q p) \u2192 \u2200 (q : Person), (\u2203 (p : Person), Likes q p) :=\nbegin\n    assume someone_everyone_likes,\n    assume q,\n    apply exists.elim someone_everyone_likes,\n    assume a,\n    assume hypothesis,\n    have q_likes_a := hypothesis q,\n    apply exists.intro,\n    exact q_likes_a,\nend\n\naxiom f : false\n\nexample : (\u2203 (p : Person), \u2200 (q : Person), Likes q p) \u2192 \u2200 (q : Person), (\u2203 (p : Person), Likes q p) :=\nbegin\n    assume h,\n    assume p,\n    -- \"identify a witness\"\n    cases h with w pf,\n    apply exists.intro w _,\n    exact pf p\nend\n\n\ninductive jlist (\u03b1 : Type) : Type \n| nil : jlist\n| cons (a : \u03b1) (t : jlist) : jlist\n\ndef len {\u03b1 : Type} : jlist \u03b1 \u2192 nat\n| (jlist.nil \u03b1):= 0\n| (jlist.cons a t) := nat.succ (len t)\n\n\n\nexample : (\u2203 (p : Person), \u2200 (q : Person), Likes q p) \u2192 \u2200 (q : Person), (\u2203 (p : Person), Likes q p) :=\nbegin\n    assume h,\n    assume p,\n    cases h with w pf,\n    apply exists.intro w (pf p)\nend\n\n-- \"Proof of an exists is just a pair\"\n    -- that pair is \"a witness\" and \"a proof that witness satisfies p\"\n\ndef even : nat \u2192 Prop := \u03bb (q : nat), \u2203 (n : nat), n * 2 = q\n\ntheorem two_even : even 2 :=\nbegin\n    exact exists.intro 1 (eq.refl _),\nend\n\nexample : \u2200 (b : bool), bor b tt = tt := \nbegin\n    assume b,\n    cases b,\n\n    exact eq.refl tt,\n    exact eq.refl tt,\nend\n\nexample : \u2200 (n : \u2115), n = 0 \u2228 n \u2260 0 :=\nbegin\n    assume n,\n    cases n with p z,\n    apply or.inl,\n    refl,\n\n    apply or.inr,\n    apply not.intro,\n    assume ridiculous,\n    cases ridiculous,\nend\n\nexample : \u2200 (n : \u2115), n = 0 \u2228 n \u2260 0 := \u03bb (n : nat), classical.em _", "meta": {"author": "joek13", "repo": "cs2102-notes", "sha": "25bb18788641b20af9cf3c429afe1da9b2f5eafb", "save_path": "github-repos/lean/joek13-cs2102-notes", "path": "github-repos/lean/joek13-cs2102-notes/cs2102-notes-25bb18788641b20af9cf3c429afe1da9b2f5eafb/12-5-2019.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7419040751087607}}
{"text": "import algebra.direct_sum.module\n\n-- finset: Defines a type for the finite subsets of \u03b1. Constructing a finset requires two pieces of data: val, a multiset \u03b1 of elements, and nodup, a proof that val has no duplicates.\n\n#check finset \u2115 \n\ndef empty_fs : finset \u2115 := finset.empty\ndef singleton_fs : finset \u2115 := { 0 }\ndef range_fs : finset \u2115 := finset.range 2 -- [0,..,1]\ndef fs_from_subtype : finset { r : \u2115 | r \u2208 range_fs } := finset.attach range_fs\n\n-- finset.has_mem: Defines membership a \u2208 (s : finset \u03b1).\n\nexample : 0 \u2208 range_fs := sorry\n\n\n-- finset.has_coe: Provides a coercion s : finset \u03b1 to s : set \u03b1.\n-- recall: a set in Lean is represented by its membership predicate \n-- KS: it's has_coe_t; it's still applied by the lift operator, \u2191.\ndef set_from_fs : set \u2115 := \u2191range_fs\n#reduce set_from_fs\n\n/-\nfinset.has_coe_to_sort: Coerce s : finset \u03b1 to the type of all x \u2208 s.\nhttps://leanprover.github.io/theorem_proving_in_lean/type_classes.html\nhttps://leanprover-community.github.io/mathlib_docs/data/subtype.html\n\nnotation `\u2191`:max x:max := coe x\nnotation `\u21d1`:max x:max := coe_fn x\nnotation `\u21a5`:max x:max := coe_sort x\n-/\n\n#check {n : \u2115 // n \u2208 range_fs}    -- subtype (//) of \u2115 in range_fs \n#reduce {n : \u2115 // n \u2208 range_fs}   -- expanding membership predicate\n\ndef sort_from_fs : Type := @has_coe_to_sort range_fs {n : \u2115 // n \u2208 range_fs} \n#reduce sort_from_fs\nexample : sort_from_fs := _ \n-- KS: hmm, instantiate one; \u27e8,\u27e9 doesn't work\n\n\n\n-- finset.induction_on: \n\n/-\nInduction on finsets. To prove a proposition about an \narbitrary finset \u03b1, it suffices to prove it for the empty\nfinset, and to show that if it holds for some finset \u03b1, \nthen it holds for ANY finset obtained by inserting any \nnew element into it.\n-/\n\n\n\n/- finset.choose: Given a proof h of existence and uniqueness \nof aN element satisfying a predicate, choose s h returns the\nelement of s satisfying that predicate.\n-/\n\n\n\n/-\nfinsets from functions (predicates)\n-/\n\n/- \nfinset.filter: Given a predicate p : \u03b1 \u2192 Prop, s.filter p \nis the finset consisting of the elements in s that satisfy p.\n-/\ndef just_zero_fs := range_fs.filter (\u03bb v, v %2 = 0)\n#check just_zero_fs  -- cool\n#eval just_zero_fs\n-- The data.equiv files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from s to t given that s \u2243 t. TODO: examples\n\n/-\nLattice structure\n-/\n\n/-\nOperations on two or more finsets\n-/\n\ndef range_3_fs :finset \u2115 := \n  finset.cons \n    2 \n    range_fs \n    begin  -- pf 2 \u2209 range_fs\n      assume h,\n      repeat {cases h},\n    end\n\n-- KS: finset insert no longer in mathlib?\n\ndef range_3_fs' := range_fs \u222a {2}\n#eval range_3_fs'\n\ndef just_1_fs := range_fs \u2229 {1}\n#eval just_1_fs\n\ndef just_1_fs' := range_fs.erase 0\n#eval just_1_fs'\nexample : just_1_fs = just_1_fs' := rfl\n\n-- finset difference is s \\ t\n\n\n-- finset product\n\ndef by_3_3 := range_fs \u00d7 range_fs\n#reduce by_3_3\n\n/-\nfinset.bUnion: Finite unions of finsets; given an \nindexing function f : \u03b1 \u2192 finset \u03b2 and a s : finset \u03b1, \ns.bUnion f is the union of all  finsets of the form,\nf a, for a \u2208 s.\n-/\n\n-- contstant map, (_ : fin 2) -> range_fs \ndef an_f (a : nat) := range_fs\n\n/-\nfinset.bUnion : \n  \u03a0 {\u03b1 : Type} \n    {\u03b2 : Type u_1} [_inst_1 : decidable_eq \u03b2], \n    finset \u03b1 \u2192            -- fin nat\n    (\u03b1 \u2192 finset \u03b2) \u2192      -- nar \u2192 finset \u03b2 \n    finset \u03b2\n\n-- KS: fix docs re implicit third arg, finset \u03b1\n-/\ndef bun := range_fs.bUnion an_f\n#reduce bun\n\n\n/-\nMaps constructed using finsets\n-/\n\n/-\nfinset.piecewise: Given two functions f, g, \ns.piecewise f g is a function that is equal to \nf on s and equal to g on the complement of s\n(within its potentially larger element type).\n-/\n\n\n\n/-\nPredicates on finsets\n\n- disjoint\n- empty\n\nlater.\n-/\n\n\n\n/-\nEquivalences between finsets\n\nThe data.equiv files describe a general type of \nequivalence, so look in there for any lemmas.\n-/\n\n/-\nThe standard library defines a coercion from subtype \n{x : \u03b1 // p x} to \u03b1 as follows. \n\ninstance coe_subtype {\u03b1 : Type*} {p : \u03b1 \u2192 Prop} :\n  has_coe {x // p x} \u03b1 := \u27e8\u03bb s, subtype.val s\u27e9.\n-/", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/tutorials/finset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7419040708404796}}
{"text": "import MyNat.Definition\nimport MyNat.Addition\nimport AdditionWorld.Level4 -- add_comm\nimport AdvancedAdditionWorld.Level10 -- add_left_eq_zero\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Advanced Addition World\n\n## Level 11: `add_right_eq_zero`\n\nWe just proved `add_left_eq_zero (a b : MyNat) : a + b = 0 \u2192 b = 0`.\nHopefully `add_right_eq_zero` shouldn't be too hard now.\n\n## Lemma\nIf `a` and `b` are natural numbers such that if `a + b = 0` then `a = 0`.\n-/\nlemma add_right_eq_zero {a b : MyNat} : a + b = 0 \u2192 a = 0 := by\n  intro h\n  rw [add_comm] at h\n  exact add_left_eq_zero h\n\n\n/-!\nNext up [Level 12](./Level12.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedAdditionWorld/Level11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9511422213778251, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7418841846709522}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.complex.upper_half_plane.topology\nimport analysis.special_functions.arsinh\nimport geometry.euclidean.inversion\n\n/-!\n# Metric on the upper half-plane\n\nIn this file we define a `metric_space` structure on the `upper_half_plane`. We use hyperbolic\n(Poincar\u00e9) distance given by\n`dist z w = 2 * arsinh (dist (z : \u2102) w / (2 * real.sqrt (z.im * w.im)))` instead of the induced\nEuclidean distance because the hyperbolic distance is invariant under holomorphic automorphisms of\nthe upper half-plane. However, we ensure that the projection to `topological_space` is\ndefinitionally equal to the induced topological space structure.\n\nWe also prove that a metric ball/closed ball/sphere in Poincar\u00e9 metric is a Euclidean ball/closed\nball/sphere with another center and radius.\n\n-/\n\nnoncomputable theory\n\nopen_locale upper_half_plane complex_conjugate nnreal topology matrix_groups\nopen set metric filter real\n\nvariables {z w : \u210d} {r R : \u211d}\n\nnamespace upper_half_plane\n\ninstance : has_dist \u210d :=\n\u27e8\u03bb z w, 2 * arsinh (dist (z : \u2102) w / (2 * sqrt (z.im * w.im)))\u27e9\n\nlemma dist_eq (z w : \u210d) : dist z w = 2 * arsinh (dist (z : \u2102) w / (2 * sqrt (z.im * w.im))) :=\nrfl\n\nlemma sinh_half_dist (z w : \u210d) :\n  sinh (dist z w / 2) = dist (z : \u2102) w / (2 * sqrt (z.im * w.im)) :=\nby rw [dist_eq, mul_div_cancel_left (arsinh _) two_ne_zero, sinh_arsinh]\n\nlemma cosh_half_dist (z w : \u210d) :\n  cosh (dist z w / 2) = dist (z : \u2102) (conj (w : \u2102)) / (2 * sqrt (z.im * w.im)) :=\nbegin\n  have H\u2081 : (2 ^ 2 : \u211d) = 4, by norm_num1,\n  have H\u2082 : 0 < z.im * w.im, from mul_pos z.im_pos w.im_pos,\n  have H\u2083 : 0 < 2 * sqrt (z.im * w.im), from mul_pos two_pos (sqrt_pos.2 H\u2082),\n  rw [\u2190 sq_eq_sq (cosh_pos _).le (div_nonneg dist_nonneg H\u2083.le), cosh_sq', sinh_half_dist, div_pow,\n    div_pow, one_add_div (pow_ne_zero 2 H\u2083.ne'), mul_pow, sq_sqrt H\u2082.le, H\u2081],\n  congr' 1,\n  simp only [complex.dist_eq, complex.sq_abs, complex.norm_sq_sub, complex.norm_sq_conj,\n    complex.conj_conj, complex.mul_re, complex.conj_re, complex.conj_im, coe_im],\n  ring\nend\n\nlemma tanh_half_dist (z w : \u210d) :\n  tanh (dist z w / 2) = dist (z : \u2102) w / dist (z : \u2102) (conj \u2191w) :=\nbegin\n  rw [tanh_eq_sinh_div_cosh, sinh_half_dist, cosh_half_dist, div_div_div_comm, div_self, div_one],\n  exact (mul_pos (zero_lt_two' \u211d) (sqrt_pos.2 $ mul_pos z.im_pos w.im_pos)).ne'\nend\n\nlemma exp_half_dist (z w : \u210d) :\n  exp (dist z w / 2) = (dist (z : \u2102) w + dist (z : \u2102) (conj \u2191w)) / (2 * sqrt (z.im * w.im)) :=\nby rw [\u2190 sinh_add_cosh, sinh_half_dist, cosh_half_dist, add_div]\n\nlemma cosh_dist (z w : \u210d) : cosh (dist z w) = 1 + dist (z : \u2102) w ^ 2 / (2 * z.im * w.im) :=\nby rw [dist_eq, cosh_two_mul, cosh_sq', add_assoc, \u2190 two_mul, sinh_arsinh, div_pow, mul_pow,\n  sq_sqrt (mul_pos z.im_pos w.im_pos).le, sq (2 : \u211d), mul_assoc, \u2190 mul_div_assoc,\n  mul_assoc, mul_div_mul_left _ _ (two_ne_zero' \u211d)]\n\nlemma sinh_half_dist_add_dist (a b c : \u210d) :\n  sinh ((dist a b + dist b c) / 2) =\n    (dist (a : \u2102) b * dist (c : \u2102) (conj \u2191b) + dist (b : \u2102) c * dist (a : \u2102) (conj \u2191b)) /\n      (2 * sqrt (a.im * c.im) * dist (b : \u2102) (conj \u2191b)) :=\nbegin\n  simp only [add_div _ _ (2 : \u211d), sinh_add, sinh_half_dist, cosh_half_dist, div_mul_div_comm],\n  rw [\u2190 add_div, complex.dist_self_conj, coe_im, abs_of_pos b.im_pos, mul_comm (dist \u2191b _),\n    dist_comm (b : \u2102), complex.dist_conj_comm, mul_mul_mul_comm, mul_mul_mul_comm _ _ _ b.im],\n  congr' 2,\n  rw [sqrt_mul, sqrt_mul, sqrt_mul, mul_comm (sqrt a.im), mul_mul_mul_comm, mul_self_sqrt,\n    mul_comm]; exact (im_pos _).le\nend\n\nprotected lemma dist_comm (z w : \u210d) : dist z w = dist w z :=\nby simp only [dist_eq, dist_comm (z : \u2102), mul_comm]\n\nlemma dist_le_iff_le_sinh :\n  dist z w \u2264 r \u2194 dist (z : \u2102) w / (2 * sqrt (z.im * w.im)) \u2264 sinh (r / 2) :=\nby rw [\u2190 div_le_div_right (zero_lt_two' \u211d), \u2190 sinh_le_sinh, sinh_half_dist]\n\nlemma dist_eq_iff_eq_sinh :\n  dist z w = r \u2194 dist (z : \u2102) w / (2 * sqrt (z.im * w.im)) = sinh (r / 2) :=\nby rw [\u2190 div_left_inj' (two_ne_zero' \u211d), \u2190 sinh_inj, sinh_half_dist]\n\nlemma dist_eq_iff_eq_sq_sinh (hr : 0 \u2264 r) :\n  dist z w = r \u2194 dist (z : \u2102) w ^ 2 / (4 * z.im * w.im) = sinh (r / 2) ^ 2 :=\nbegin\n  rw [dist_eq_iff_eq_sinh, \u2190 sq_eq_sq, div_pow, mul_pow, sq_sqrt, mul_assoc],\n  { norm_num },\n  { exact (mul_pos z.im_pos w.im_pos).le },\n  { exact div_nonneg dist_nonneg (mul_nonneg zero_le_two $ sqrt_nonneg _) },\n  { exact sinh_nonneg_iff.2 (div_nonneg hr zero_le_two) }\nend\n\nprotected lemma dist_triangle (a b c : \u210d) : dist a c \u2264 dist a b + dist b c :=\nbegin\n  rw [dist_le_iff_le_sinh, sinh_half_dist_add_dist,\n    div_mul_eq_div_div _ _ (dist _ _), le_div_iff, div_mul_eq_mul_div],\n  { exact div_le_div_of_le (mul_nonneg zero_le_two (sqrt_nonneg _))\n      (euclidean_geometry.mul_dist_le_mul_dist_add_mul_dist (a : \u2102) b c (conj \u2191b)) },\n  { rw [dist_comm, dist_pos, ne.def, complex.eq_conj_iff_im],\n    exact b.im_ne_zero }\nend\n\nlemma dist_le_dist_coe_div_sqrt (z w : \u210d) :\n  dist z w \u2264 dist (z : \u2102) w / sqrt (z.im * w.im) :=\nbegin\n  rw [dist_le_iff_le_sinh, \u2190 div_mul_eq_div_div_swap, self_le_sinh_iff],\n  exact div_nonneg dist_nonneg (mul_nonneg zero_le_two (sqrt_nonneg _))\nend\n\n/-- An auxiliary `metric_space` instance on the upper half-plane. This instance has bad projection\nto `topological_space`. We replace it later. -/\ndef metric_space_aux : metric_space \u210d :=\n{ dist := dist,\n  dist_self := \u03bb z, by rw [dist_eq, dist_self, zero_div, arsinh_zero, mul_zero],\n  dist_comm := upper_half_plane.dist_comm,\n  dist_triangle := upper_half_plane.dist_triangle,\n  eq_of_dist_eq_zero := \u03bb z w h,\n    by simpa [dist_eq, real.sqrt_eq_zero', (mul_pos z.im_pos w.im_pos).not_le, subtype.coe_inj]\n      using h }\n\nopen complex\n\nlemma cosh_dist' (z w : \u210d) :\n  real.cosh (dist z w) = ((z.re - w.re) ^ 2 + z.im ^ 2 + w.im ^ 2) / (2 * z.im * w.im) :=\nhave H : 0 < 2 * z.im * w.im, from mul_pos (mul_pos two_pos z.im_pos) w.im_pos,\nby { field_simp [cosh_dist, complex.dist_eq, complex.sq_abs, norm_sq_apply, H, H.ne'], ring }\n\n/-- Euclidean center of the circle with center `z` and radius `r` in the hyperbolic metric. -/\ndef center (z : \u210d) (r : \u211d) : \u210d := \u27e8\u27e8z.re, z.im * cosh r\u27e9, mul_pos z.im_pos (cosh_pos _)\u27e9\n\n@[simp] lemma center_re (z r) : (center z r).re = z.re := rfl\n@[simp] lemma center_im (z r) : (center z r).im = z.im * cosh r := rfl\n\n@[simp] lemma center_zero (z : \u210d) : center z 0 = z :=\nsubtype.ext $ ext rfl $ by rw [coe_im, coe_im, center_im, real.cosh_zero, mul_one]\n\nlemma dist_coe_center_sq (z w : \u210d) (r : \u211d) :\n  dist (z : \u2102) (w.center r) ^ 2 =\n    2 * z.im * w.im * (cosh (dist z w) - cosh r) + (w.im * sinh r) ^ 2 :=\nbegin\n  have H : 2 * z.im * w.im \u2260 0, by apply_rules [mul_ne_zero, two_ne_zero, im_ne_zero],\n  simp only [complex.dist_eq, complex.sq_abs, norm_sq_apply, coe_re, coe_im, center_re, center_im,\n    cosh_dist', mul_div_cancel' _ H, sub_sq z.im, mul_pow, real.cosh_sq, sub_re, sub_im, mul_sub,\n    \u2190 sq],\n  ring\nend\n\nlemma dist_coe_center (z w : \u210d) (r : \u211d) :\n  dist (z : \u2102) (w.center r) =\n    sqrt (2 * z.im * w.im * (cosh (dist z w) - cosh r) + (w.im * sinh r) ^ 2) :=\nby rw [\u2190 sqrt_sq dist_nonneg, dist_coe_center_sq]\n\nlemma cmp_dist_eq_cmp_dist_coe_center (z w : \u210d) (r : \u211d) :\n  cmp (dist z w) r = cmp (dist (z : \u2102) (w.center r)) (w.im * sinh r) :=\nbegin\n  letI := metric_space_aux,\n  cases lt_or_le r 0 with hr\u2080 hr\u2080,\n  { transitivity ordering.gt,\n    exacts [(hr\u2080.trans_le dist_nonneg).cmp_eq_gt,\n      ((mul_neg_of_pos_of_neg w.im_pos (sinh_neg_iff.2 hr\u2080)).trans_le\n        dist_nonneg).cmp_eq_gt.symm] },\n  have hr\u2080' : 0 \u2264 w.im * sinh r, from mul_nonneg w.im_pos.le (sinh_nonneg_iff.2 hr\u2080),\n  have hzw\u2080 : 0 < 2 * z.im * w.im, from mul_pos (mul_pos two_pos z.im_pos) w.im_pos,\n  simp only [\u2190 cosh_strict_mono_on.cmp_map_eq dist_nonneg hr\u2080,\n    \u2190 (@strict_mono_on_pow \u211d _ _ two_pos).cmp_map_eq dist_nonneg hr\u2080', dist_coe_center_sq],\n  rw [\u2190 cmp_mul_pos_left hzw\u2080, \u2190 cmp_sub_zero, \u2190 mul_sub, \u2190 cmp_add_right, zero_add],\nend\n\nlemma dist_eq_iff_dist_coe_center_eq : dist z w = r \u2194 dist (z : \u2102) (w.center r) = w.im * sinh r :=\neq_iff_eq_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r)\n\n@[simp] lemma dist_self_center (z : \u210d) (r : \u211d) : dist (z : \u2102) (z.center r) = z.im * (cosh r - 1) :=\nbegin\n  rw [dist_of_re_eq (z.center_re r).symm, dist_comm, real.dist_eq, mul_sub, mul_one],\n  exact abs_of_nonneg (sub_nonneg.2 $ le_mul_of_one_le_right z.im_pos.le (one_le_cosh _))\nend\n\n@[simp] lemma dist_center_dist (z w : \u210d) :\n  dist (z : \u2102) (w.center (dist z w)) = w.im * sinh (dist z w) :=\ndist_eq_iff_dist_coe_center_eq.1 rfl\n\nlemma dist_lt_iff_dist_coe_center_lt :\n  dist z w < r \u2194 dist (z : \u2102) (w.center r) < w.im * sinh r :=\nlt_iff_lt_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r)\n\nlemma lt_dist_iff_lt_dist_coe_center :\n  r < dist z w \u2194 w.im * sinh r < dist (z : \u2102) (w.center r) :=\nlt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 $ cmp_dist_eq_cmp_dist_coe_center z w r)\n\nlemma dist_le_iff_dist_coe_center_le :\n  dist z w \u2264 r \u2194 dist (z : \u2102) (w.center r) \u2264 w.im * sinh r :=\nle_iff_le_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r)\n\nlemma le_dist_iff_le_dist_coe_center :\n  r < dist z w \u2194 w.im * sinh r < dist (z : \u2102) (w.center r) :=\nlt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 $ cmp_dist_eq_cmp_dist_coe_center z w r)\n\n/-- For two points on the same vertical line, the distance is equal to the distance between the\nlogarithms of their imaginary parts. -/\nlemma dist_of_re_eq (h : z.re = w.re) : dist z w = dist (log z.im) (log w.im) :=\nbegin\n  have h\u2080 : 0 < z.im / w.im, from div_pos z.im_pos w.im_pos,\n  rw [dist_eq_iff_dist_coe_center_eq, real.dist_eq, \u2190 abs_sinh, \u2190 log_div z.im_ne_zero w.im_ne_zero,\n    sinh_log h\u2080, dist_of_re_eq, coe_im, coe_im, center_im, cosh_abs, cosh_log h\u2080, inv_div];\n    [skip, exact h],\n  nth_rewrite 3 [\u2190 abs_of_pos w.im_pos],\n  simp only [\u2190 _root_.abs_mul, coe_im, real.dist_eq],\n  congr' 1,\n  field_simp [z.im_pos, w.im_pos, z.im_ne_zero, w.im_ne_zero],\n  ring\nend\n\n/-- Hyperbolic distance between two points is greater than or equal to the distance between the\nlogarithms of their imaginary parts. -/\nlemma dist_log_im_le (z w : \u210d) : dist (log z.im) (log w.im) \u2264 dist z w :=\ncalc dist (log z.im) (log w.im) = @dist \u210d _ \u27e8\u27e80, z.im\u27e9, z.im_pos\u27e9 \u27e8\u27e80, w.im\u27e9, w.im_pos\u27e9 :\n  eq.symm $ @dist_of_re_eq \u27e8\u27e80, z.im\u27e9, z.im_pos\u27e9 \u27e8\u27e80, w.im\u27e9, w.im_pos\u27e9 rfl\n... \u2264 dist z w :\n  mul_le_mul_of_nonneg_left (arsinh_le_arsinh.2 $ div_le_div_of_le\n    (mul_nonneg zero_le_two (sqrt_nonneg _)) $\n      by simpa [sqrt_sq_eq_abs] using complex.abs_im_le_abs (z - w)) zero_le_two\n\nlemma im_le_im_mul_exp_dist (z w : \u210d) : z.im \u2264 w.im * exp (dist z w) :=\nbegin\n  rw [\u2190 div_le_iff' w.im_pos, \u2190 exp_log z.im_pos, \u2190 exp_log w.im_pos, \u2190 real.exp_sub, exp_le_exp],\n  exact (le_abs_self _).trans (dist_log_im_le z w)\nend\n\n\n\n/-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance\nand the imaginary part of one of the points. -/\nlemma dist_coe_le (z w : \u210d) : dist (z : \u2102) w \u2264 w.im * (exp (dist z w) - 1) :=\ncalc dist (z : \u2102) w \u2264 dist (z : \u2102) (w.center (dist z w)) + dist (w : \u2102) (w.center (dist z w)) :\n  dist_triangle_right _ _ _\n... = w.im  * (exp (dist z w) - 1) :\n  by rw [dist_center_dist, dist_self_center, \u2190 mul_add, \u2190 add_sub_assoc, real.sinh_add_cosh]\n\n/-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance\nand the imaginary part of one of the points. -/\nlemma le_dist_coe (z w : \u210d) : w.im * (1 - exp (-dist z w)) \u2264 dist (z : \u2102) w :=\ncalc w.im * (1 - exp (-dist z w))\n    = dist (z : \u2102) (w.center (dist z w)) - dist (w : \u2102) (w.center (dist z w)) :\n  by { rw [dist_center_dist, dist_self_center, \u2190 real.cosh_sub_sinh], ring }\n... \u2264 dist (z : \u2102) w : sub_le_iff_le_add.2 $ dist_triangle _ _ _\n\n/-- The hyperbolic metric on the upper half plane. We ensure that the projection to\n`topological_space` is definitionally equal to the subtype topology. -/\ninstance : metric_space \u210d := metric_space_aux.replace_topology $\nbegin\n  refine le_antisymm (continuous_id_iff_le.1 _) _,\n  { refine (@continuous_iff_continuous_dist _ _ metric_space_aux.to_pseudo_metric_space _ _).2 _,\n    have : \u2200 (x : \u210d \u00d7 \u210d), 2 * real.sqrt (x.1.im * x.2.im) \u2260 0,\n      from \u03bb x, mul_ne_zero two_ne_zero (real.sqrt_pos.2 $ mul_pos x.1.im_pos x.2.im_pos).ne',\n    -- `continuity` fails to apply `continuous.div`\n    apply_rules [continuous.div, continuous.mul, continuous_const, continuous.arsinh,\n      continuous.dist, continuous_coe.comp, continuous_fst, continuous_snd,\n      real.continuous_sqrt.comp, continuous_im.comp] },\n  { letI : metric_space \u210d := metric_space_aux,\n    refine le_of_nhds_le_nhds (\u03bb z, _),\n    rw [nhds_induced],\n    refine (nhds_basis_ball.le_basis_iff (nhds_basis_ball.comap _)).2 (\u03bb R hR, _),\n    have h\u2081 : 1 < R / im z + 1, from lt_add_of_pos_left _ (div_pos hR z.im_pos),\n    have h\u2080 : 0 < R / im z + 1, from one_pos.trans h\u2081,\n    refine \u27e8log (R / im z + 1), real.log_pos h\u2081, _\u27e9,\n    refine \u03bb w hw, (dist_coe_le w z).trans_lt _,\n    rwa [\u2190 lt_div_iff' z.im_pos, sub_lt_iff_lt_add, \u2190 real.lt_log_iff_exp_lt h\u2080] }\nend\n\nlemma im_pos_of_dist_center_le {z : \u210d} {r : \u211d} {w : \u2102} (h : dist w (center z r) \u2264 z.im * sinh r) :\n  0 < w.im :=\ncalc 0 < z.im * (cosh r - sinh r) : mul_pos z.im_pos (sub_pos.2 $ sinh_lt_cosh _)\n... = (z.center r).im - z.im * sinh r : mul_sub _ _ _\n... \u2264 (z.center r).im - dist (z.center r : \u2102) w : sub_le_sub_left (by rwa [dist_comm]) _\n... \u2264 w.im : sub_le_comm.1 $ (le_abs_self _).trans (abs_im_le_abs $ z.center r - w)\n\nlemma image_coe_closed_ball (z : \u210d) (r : \u211d) :\n  (coe : \u210d \u2192 \u2102) '' closed_ball z r = closed_ball (z.center r) (z.im * sinh r) :=\nbegin\n  ext w, split,\n  { rintro \u27e8w, hw, rfl\u27e9,\n    exact dist_le_iff_dist_coe_center_le.1 hw },\n  { intro hw,\n    lift w to \u210d using im_pos_of_dist_center_le hw,\n    exact mem_image_of_mem _ (dist_le_iff_dist_coe_center_le.2 hw) },\nend\n\nlemma image_coe_ball (z : \u210d) (r : \u211d) :\n  (coe : \u210d \u2192 \u2102) '' ball z r = ball (z.center r) (z.im * sinh r) :=\nbegin\n  ext w, split,\n  { rintro \u27e8w, hw, rfl\u27e9,\n    exact dist_lt_iff_dist_coe_center_lt.1 hw },\n  { intro hw,\n    lift w to \u210d using im_pos_of_dist_center_le (ball_subset_closed_ball hw),\n    exact mem_image_of_mem _ (dist_lt_iff_dist_coe_center_lt.2 hw) },\nend\n\nlemma image_coe_sphere (z : \u210d) (r : \u211d) :\n  (coe : \u210d \u2192 \u2102) '' sphere z r = sphere (z.center r) (z.im * sinh r) :=\nbegin\n  ext w, split,\n  { rintro \u27e8w, hw, rfl\u27e9,\n    exact dist_eq_iff_dist_coe_center_eq.1 hw },\n  { intro hw,\n    lift w to \u210d using im_pos_of_dist_center_le (sphere_subset_closed_ball hw),\n    exact mem_image_of_mem _ (dist_eq_iff_dist_coe_center_eq.2 hw) },\nend\n\ninstance : proper_space \u210d :=\nbegin\n  refine \u27e8\u03bb z r, _\u27e9,\n  rw [\u2190 inducing_coe.is_compact_iff, image_coe_closed_ball],\n  apply is_compact_closed_ball\nend\n\nlemma isometry_vertical_line (a : \u211d) : isometry (\u03bb y, mk \u27e8a, exp y\u27e9 (exp_pos y)) :=\nbegin\n  refine isometry.of_dist_eq (\u03bb y\u2081 y\u2082, _),\n  rw [dist_of_re_eq],\n  exacts [congr_arg2 _ (log_exp _) (log_exp _), rfl]\nend\n\nlemma isometry_real_vadd (a : \u211d) : isometry ((+\u1d65) a : \u210d \u2192 \u210d) :=\nisometry.of_dist_eq $ \u03bb y\u2081 y\u2082, by simp only [dist_eq, coe_vadd, vadd_im, dist_add_left]\n\nlemma isometry_pos_mul (a : {x : \u211d // 0 < x}) : isometry ((\u2022) a : \u210d \u2192 \u210d) :=\nbegin\n  refine isometry.of_dist_eq (\u03bb y\u2081 y\u2082, _),\n  simp only [dist_eq, coe_pos_real_smul, pos_real_im], congr' 2,\n  rw [dist_smul\u2080, mul_mul_mul_comm, real.sqrt_mul (mul_self_nonneg _), real.sqrt_mul_self_eq_abs,\n    real.norm_eq_abs, mul_left_comm],\n  exact mul_div_mul_left _ _ (mt _root_.abs_eq_zero.1 a.2.ne')\nend\n\n/-- `SL(2, \u211d)` acts on the upper half plane as an isometry.-/\ninstance : has_isometric_smul SL(2, \u211d) \u210d :=\n\u27e8\u03bb g,\nbegin\n  have h\u2080 : isometry (\u03bb z, modular_group.S \u2022 z : \u210d \u2192 \u210d) := isometry.of_dist_eq (\u03bb y\u2081 y\u2082, by\n  { have h\u2081 : 0 \u2264 im y\u2081 * im y\u2082 := mul_nonneg y\u2081.property.le y\u2082.property.le,\n    have h\u2082 : complex.abs (y\u2081 * y\u2082) \u2260 0, { simp [y\u2081.ne_zero, y\u2082.ne_zero], },\n    simp only [dist_eq, modular_S_smul, inv_neg, neg_div, div_mul_div_comm, coe_mk, mk_im, div_one,\n      complex.inv_im, complex.neg_im, coe_im, neg_neg, complex.norm_sq_neg, mul_eq_mul_left_iff,\n      real.arsinh_inj, bit0_eq_zero, one_ne_zero, or_false, dist_neg_neg, mul_neg, neg_mul,\n      dist_inv_inv\u2080 y\u2081.ne_zero y\u2082.ne_zero, \u2190 absolute_value.map_mul,\n      \u2190 complex.norm_sq_mul, real.sqrt_div h\u2081, \u2190 complex.abs_apply, mul_div (2 : \u211d),\n      div_div_div_comm, div_self h\u2082, complex.norm_eq_abs], }),\n  by_cases hc : g 1 0 = 0,\n  { obtain \u27e8u, v, h\u27e9 := exists_SL2_smul_eq_of_apply_zero_one_eq_zero g hc,\n    rw h,\n    exact (isometry_real_vadd v).comp (isometry_pos_mul u), },\n  { obtain \u27e8u, v, w, h\u27e9 := exists_SL2_smul_eq_of_apply_zero_one_ne_zero g hc,\n    rw h,\n    exact (isometry_real_vadd w).comp (h\u2080.comp $ (isometry_real_vadd v).comp $ isometry_pos_mul u) }\nend\u27e9\n\nend upper_half_plane\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/complex/upper_half_plane/metric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.7418670385711746}}
{"text": "import analysis.real tactic.norm_num algebra.group_power\n\nlemma avg_lt_max {mn mx: \u211d} (H : mn < mx) : (mn+mx) / 2 < mx :=\nbegin\n  apply (mul_lt_mul_right (show (0:\u211d)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_ne_zero)],\n  simp [H,mul_two],\nend\n\nlemma min_lt_avg {mn mx: \u211d} (H : mn < mx) : mn < (mn+mx) / 2 :=\nbegin\n  apply (mul_lt_mul_right (show (0:\u211d)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_ne_zero)],\n  simp [H,mul_two],\nend\n\nlemma lub_open (y : \u211d) : is_lub {x : \u211d | x < y} y :=\nbegin\nsplit,\n{ intro a,\n  exact le_of_lt },\nunfold lower_bounds,\nintro b,\nintro Hb,\nrefine le_of_not_gt _,\nintro Hnb,\nlet c:=(b+y)/2,\nunfold upper_bounds at Hb,\nhave H2 := Hb c,\nclear Hb,\nhave H : c \u2208 {x : \u211d | x < y},\n{ exact avg_lt_max Hnb,\n},\nhave Hcleb := H2 H,\nhave Hbltc : b < c := min_lt_avg Hnb,\nexact not_lt.2 Hcleb Hbltc,\nend\n\ndef S3a : set \u211d := {x : \u211d | x<0}\n\ntheorem Q3a : is_lub (S3a) 0 := sorry\n\ndef S3b : set \u211d := {x : \u211d | \u2203 y : \u211a, x = \u2191y}\n\ntheorem Q3b : \u2200 b : \u211d, \u00ac (is_lub (S3b) b) := sorry\n\nlemma pow_two_eq_mul_self {x : \u211d} : x^2=x*x :=\nbegin\nunfold monoid.pow,simp,\nend\n\ndef S3c : set \u211d := {x : \u211d | (x+1)^2 < x^2} -- x<-0.5\n\ntheorem Q3c : is_lub (S3c) (-1/2) := sorry\n\ndef S3d : set \u211d := {x : \u211d | (\u2203 q : \u211a, x=\u2191q) \u2227 1 < x \u2227 x < 2}\n\ntheorem Q3d : is_lub S3d 2 := sorry", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/problem_bank/PB0603/S0603.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.741867030318205}}
{"text": "/-\nopen classical\nvariables {A B C : Prop}\n\nexample (h : \u00ac B \u2192 \u00ac A) : A \u2192 B :=\nsorry\n\nexample (h : A \u2192 B) : \u00ac A \u2228 B :=\nsorry\n-/\n\nopen classical\nvariables {A B C : Prop}\n\nexample (h : \u00ac B \u2192 \u00ac A) : A \u2192 B :=\n  assume hA: A,\n  show B, from (\n    by_contradiction(\n      assume hnB: \u00ac B,\n      have hnA: \u00ac A, from h(hnB),\n      show false, from hnA(hA)\n    )\n  )\n\nexample (h : A \u2192 B) : \u00ac A \u2228 B :=\n  or.elim(em(A))(\n    \u03bb hA: A,\n    have B, from h(hA),\n    show \u00ac A \u2228 B, from or.inr this\n  )(\n    assume : \u00ac A, or.inl this\n  )", "meta": {"author": "chanind", "repo": "logic-and-proof-exercises", "sha": "8d797d400d937cb4f21954b1d7a5092ceb4f6dd7", "save_path": "github-repos/lean/chanind-logic-and-proof-exercises", "path": "github-repos/lean/chanind-logic-and-proof-exercises/logic-and-proof-exercises-8d797d400d937cb4f21954b1d7a5092ceb4f6dd7/chapters/chapter5/ex9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7418288939520976}}
{"text": "import tactic\nimport data.nat.prime\nopen nat\n\ntheorem simproot2 {x y : \u2115} (coprime : gcd x y = 1) : x^2 \u2260 2 * y^2 :=\n  -- For Contradiction, will show false\n  assume contr : x^2 = 2 * y^2,\n  have twodivxsquare : 2 \u2223 x^2,\n  by exact dvd.intro (y ^ 2) (eq.symm contr),\n  have twodivx: 2 \u2223 x,\n  from prime.dvd_of_dvd_pow prime_two twodivxsquare,\n  exists.elim twodivx $\n  assume (z : nat) (introz : x = 2 * z),\n  have subst : 2 * (2 * z^2) = 2 * y^2,\n  by \n  begin\n  rw introz at contr,\n  simp[eq.symm contr, nat.pow],\n  simp [nat.pow_succ, mul_comm, mul_assoc, mul_left_comm],\n  end,\n  have subst2 : 2 * z^2 = y^2,\n  from eq_of_mul_eq_mul_left dec_trivial subst,\n  have revsubst : y^2 = 2 * z^2,\n  by rw \u2190subst2,\n  have twodivysquare : 2 \u2223 y^2,\n  by exact dvd.intro (z ^ 2) (eq.symm revsubst),\n  have twodivy: 2 \u2223 y,\n  from prime.dvd_of_dvd_pow prime_two twodivysquare,\n  have fin : 2 \u2223 gcd x y, \n  from dvd_gcd twodivx twodivy, \n  have last : 2 \u2223 1,\n  from \n  begin\n  rw coprime at fin,\n  use fin,\n  end,\n  show false, \n  from absurd last dec_trivial\n", "meta": {"author": "AlexKontorovich", "repo": "Spring2020Math492", "sha": "659108c5d864ff5c75b9b3b13b847aa5cff4348a", "save_path": "github-repos/lean/AlexKontorovich-Spring2020Math492", "path": "github-repos/lean/AlexKontorovich-Spring2020Math492/Spring2020Math492-659108c5d864ff5c75b9b3b13b847aa5cff4348a/root2final.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7418288916650677}}
{"text": "import basic_definitions.sub_module\nimport Tools.tools\nimport linear_algebra.matrix\nimport group_theory.group_action\nimport init.algebra.functions\n--set_option trace.simplify.rewrite true   --- a reprednre peut etre un peu ! \nopen_locale big_operators\nnamespace general\nuniverses u v  w w' \nvariables (G : Type u) (R : Type v) (X : Type w) [group G] [ring R]  [mul_action G X] \n\n/--\n    Permutation representation : let `\u2022` an action of `G` on `X`. Let `R` be a ring, \n    let `M = R \u2192 X` be the free-module over `M` of base `X`. For `v : R \u2192 X` and `g \u2208 G` the formula  \n    `\u03c1 g v := g\u207b\u00b9 \u2022 v` define a permutation de representation.  \n -/\n\ndef rho  (g : G)  : (X \u2192 R) \u2192 (X \u2192 R)  := \u03bb  v x,  v (g\u207b\u00b9 \u2022  x)\n\ndef rho_linear (g : G) : (X \u2192 R) \u2192\u2097[R] (X \u2192 R) := { \n  to_fun := rho G R X g,\n  add := by { intros, exact rfl},\n  smul := by {intros, exact rfl}\n}\n\n@[simp]lemma rho_apply (g : G)(v : X \u2192 R)(x : X) : rho G R  X g v x  = v (g\u207b\u00b9 \u2022 x) := rfl  \n\n@[simp]lemma rho_mul (\u03c3 \u03c4  : G) : rho G R X (\u03c3 * \u03c4) = rho G R X \u03c3  \u2218  rho G R X \u03c4 := begin \n        ext v x, rw rho_apply, rw  mul_inv_rev, rw  mul_smul, exact rfl,    \nend \n@[simp]lemma rho_one  : rho G R X (1 : G) = id := begin \n   ext x v, rw rho_apply, rw one_inv, rw one_smul, exact rfl,\nend\n@[simp]lemma rho_right_inv (g : G) : (rho G R X g : (X \u2192 R) \u2192  (X \u2192 R)) \u2218  (rho G R X g\u207b\u00b9) = id  := begin \n    rw \u2190 rho_mul, rw mul_inv_self, rw rho_one,\nend\n\n@[simp]lemma rho_left_inv  (g : G) : (  rho G R X (g\u207b\u00b9 )  : \n(X \u2192 R) \u2192 (X \u2192 R) ) \u2218    (rho G R X g : (X \u2192 R) \u2192 (X \u2192 R))  = id  :=  \nbegin \n    rw \u2190 rho_mul, rw inv_mul_self, rw rho_one, \nend\n\n\ndef Perm : group_representation G R (X \u2192 R) := { \n  to_fun    :=  rho_linear G R X,\n  map_one'  := \n    begin  \n        unfold rho_linear,congr,\n        exact rho_one G R X, \n    end,\n  map_mul'  := \n    begin  \n        unfold rho_linear, intros, congr,\n        exact rho_mul G R X _ _,\n    end \n}\nvariables (g : G) (x y : X \u2192 R)\n\nexample (g : G) (x y : X \u2192 R) (r : R) : true := begin \n        let \u03c1 := @Perm G R X,\n        have f : \u03c1 1 = 1,\n            rw \u03c1.map_one,  \n        have : \u03c1 g (x+y) = \u03c1 g x +\u03c1 g y, \n            rw (\u03c1 g).map_add,\n        \n        trivial,\n        end\nend general \nnamespace finite_action\nopen classical_basis general\nuniverses u v  w w' \nvariables {G : Type u} (R : Type v) (X : Type w) [fintype X] [decidable_eq X][group G] [comm_ring R]  [mul_action G X] \n/-!\n    Goal : study more the representation \n-/\n\n@[simp]theorem action_on_basis (g : G)(x : X) : rho G R X g (\u03b5 x) = \u03b5 (g \u2022 x) := begin \n    funext y, simp,  \n    unfold \u03b5, \n    split_ifs, \n        {exact rfl},\n        {rw [h, \u2190 mul_smul,mul_inv_self,one_smul] at h_1, trivial},\n        {rw [\u2190 h_1, \u2190 mul_smul,inv_mul_self,one_smul] at h, trivial},\n        {exact rfl},\nend \n@[simp]theorem action_on_basis_apply (g : G) (x y : X) : rho G R X g (\u03b5 x) y = if g \u2022 x = y then 1 else 0 := \nbegin simp, exact rfl,\n   -- rw action_on_basis, exact rfl, \nend\n@[simp]theorem trace (g : G) :  \u2211 (x : X), rho G R X g (\u03b5 x) x =  fintype.card {x : X |  g \u2022 x = x } := \nbegin simp, exact rfl,\n    --have r :  (\u03bb (x : X), rho G R X g (\u03b5 x) x) = \u03bb x,if g \u2022 x = x then 1 else 0,\n    --   funext, rw action_on_basis_apply,\n    --rw r,\n    --rw finset.sum_boole,simp, exact rfl, --- filter ? \nend\nvariables (g : G)\n@[simp]lemma  Perm_ext (g : G) :  rho G R X g = (Perm G R X) g    := rfl  \n\nend finite_action", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep_2/permutation_representation/action_representation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7418288779428882}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport order.lattice\n\n/-!\n# `max` and `min`\n\nThis file proves basic properties about maxima and minima on a `linear_order`.\n\n## Tags\n\nmin, max\n-/\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\n\nattribute [simp] max_eq_left max_eq_right min_eq_left min_eq_right\n\nsection\nvariables [linear_order \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a b c d : \u03b1}\n\n-- translate from lattices to linear orders (sup \u2192 max, inf \u2192 min)\n@[simp] lemma le_min_iff : c \u2264 min a b \u2194 c \u2264 a \u2227 c \u2264 b := le_inf_iff\n@[simp] lemma max_le_iff : max a b \u2264 c \u2194 a \u2264 c \u2227 b \u2264 c := sup_le_iff\nlemma max_le_max : a \u2264 c \u2192 b \u2264 d \u2192 max a b \u2264 max c d := sup_le_sup\nlemma min_le_min : a \u2264 c \u2192 b \u2264 d \u2192 min a b \u2264 min c d := inf_le_inf\nlemma le_max_of_le_left : a \u2264 b \u2192 a \u2264 max b c := le_sup_of_le_left\nlemma le_max_of_le_right : a \u2264 c \u2192 a \u2264 max b c := le_sup_of_le_right\nlemma lt_max_of_lt_left (h : a < b) : a < max b c := h.trans_le (le_max_left b c)\nlemma lt_max_of_lt_right (h : a < c) : a < max b c := h.trans_le (le_max_right b c)\nlemma min_le_of_left_le : a \u2264 c \u2192 min a b \u2264 c := inf_le_of_left_le\nlemma min_le_of_right_le : b \u2264 c \u2192 min a b \u2264 c := inf_le_of_right_le\nlemma min_lt_of_left_lt (h : a < c) : min a b < c := (min_le_left a b).trans_lt h\nlemma min_lt_of_right_lt (h : b < c) : min a b < c := (min_le_right a b).trans_lt h\nlemma max_min_distrib_left : max a (min b c) = min (max a b) (max a c) := sup_inf_left\nlemma max_min_distrib_right : max (min a b) c = min (max a c) (max b c) := sup_inf_right\nlemma min_max_distrib_left : min a (max b c) = max (min a b) (min a c) := inf_sup_left\nlemma min_max_distrib_right : min (max a b) c = max (min a c) (min b c) := inf_sup_right\nlemma min_le_max : min a b \u2264 max a b := le_trans (min_le_left a b) (le_max_left a b)\n\n@[simp] lemma min_eq_left_iff : min a b = a \u2194 a \u2264 b := inf_eq_left\n@[simp] lemma min_eq_right_iff : min a b = b \u2194 b \u2264 a := inf_eq_right\n@[simp] lemma max_eq_left_iff : max a b = a \u2194 b \u2264 a := sup_eq_left\n@[simp] lemma max_eq_right_iff : max a b = b \u2194 a \u2264 b := sup_eq_right\n\n/-- For elements `a` and `b` of a linear order, either `min a b = a` and `a \u2264 b`,\n    or `min a b = b` and `b < a`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma min_cases (a b : \u03b1) : min a b = a \u2227 a \u2264 b \u2228 min a b = b \u2227 b < a :=\nbegin\n  by_cases a \u2264 b,\n  { left,\n    exact \u27e8min_eq_left h, h\u27e9 },\n  { right,\n    exact \u27e8min_eq_right (le_of_lt (not_le.mp h)), (not_le.mp h)\u27e9 }\nend\n\n/-- For elements `a` and `b` of a linear order, either `max a b = a` and `b \u2264 a`,\n    or `max a b = b` and `a < b`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma max_cases (a b : \u03b1) : max a b = a \u2227 b \u2264 a \u2228 max a b = b \u2227 a < b :=\n@min_cases (order_dual \u03b1) _ a b\n\nlemma min_eq_iff : min a b = c \u2194 a = c \u2227 a \u2264 b \u2228 b = c \u2227 b \u2264 a :=\nbegin\n  split,\n  { intro h,\n    refine or.imp (\u03bb h', _) (\u03bb h', _) (le_total a b);\n    exact \u27e8by simpa [h'] using h, h'\u27e9 },\n  { rintro (\u27e8rfl, h\u27e9|\u27e8rfl, h\u27e9);\n    simp [h] }\nend\n\nlemma max_eq_iff : max a b = c \u2194 a = c \u2227 b \u2264 a \u2228 b = c \u2227 a \u2264 b :=\n@min_eq_iff (order_dual \u03b1) _ a b c\n\n/-- An instance asserting that `max a a = a` -/\ninstance max_idem : is_idempotent \u03b1 max := by apply_instance -- short-circuit type class inference\n\n/-- An instance asserting that `min a a = a` -/\ninstance min_idem : is_idempotent \u03b1 min := by apply_instance -- short-circuit type class inference\n\n@[simp] lemma max_lt_iff : max a b < c \u2194 (a < c \u2227 b < c) :=\nsup_lt_iff\n\n@[simp] lemma lt_min_iff : a < min b c \u2194 (a < b \u2227 a < c) :=\nlt_inf_iff\n\n@[simp] lemma lt_max_iff : a < max b c \u2194 a < b \u2228 a < c :=\nlt_sup_iff\n\n@[simp] lemma min_lt_iff : min a b < c \u2194 a < c \u2228 b < c :=\n@lt_max_iff (order_dual \u03b1) _ _ _ _\n\n@[simp] lemma min_le_iff : min a b \u2264 c \u2194 a \u2264 c \u2228 b \u2264 c :=\ninf_le_iff\n\n@[simp] lemma le_max_iff : a \u2264 max b c \u2194 a \u2264 b \u2228 a \u2264 c :=\n@min_le_iff (order_dual \u03b1) _ _ _ _\n\nlemma min_lt_max : min a b < max a b \u2194 a \u2260 b := inf_lt_sup\n\nlemma max_lt_max (h\u2081 : a < c) (h\u2082 : b < d) : max a b < max c d :=\nby simp [lt_max_iff, max_lt_iff, *]\n\nlemma min_lt_min (h\u2081 : a < c) (h\u2082 : b < d) : min a b < min c d :=\n@max_lt_max (order_dual \u03b1) _ _ _ _ _ h\u2081 h\u2082\n\ntheorem min_right_comm (a b c : \u03b1) : min (min a b) c = min (min a c) b :=\nright_comm min min_comm min_assoc a b c\n\ntheorem max.left_comm (a b c : \u03b1) : max a (max b c) = max b (max a c) :=\nleft_comm max max_comm max_assoc a b c\n\ntheorem max.right_comm (a b c : \u03b1) : max (max a b) c = max (max a c) b :=\nright_comm max max_comm max_assoc a b c\n\nlemma monotone_on.map_max (hf : monotone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (max a b) = max (f a) (f b) :=\nby cases le_total a b; simp only [max_eq_right, max_eq_left, hf ha hb, hf hb ha, h]\n\nlemma monotone_on.map_min (hf : monotone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (min a b) = min (f a) (f b) :=\nhf.dual.map_max ha hb\n\nlemma antitone_on.map_max (hf : antitone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (max a b) = min (f a) (f b) :=\nhf.dual_right.map_max ha hb\n\nlemma antitone_on.map_min (hf : antitone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (min a b) = max (f a) (f b) :=\nhf.dual.map_max ha hb\n\nlemma monotone.map_max (hf : monotone f) : f (max a b) = max (f a) (f b) :=\nby cases le_total a b; simp [h, hf h]\n\nlemma monotone.map_min (hf : monotone f) : f (min a b) = min (f a) (f b) :=\nhf.dual.map_max\n\nlemma antitone.map_max (hf : antitone f) : f (max a b) = min (f a) (f b) :=\nby cases le_total a b; simp [h, hf h]\n\nlemma antitone.map_min (hf : antitone f) : f (min a b) = max (f a) (f b) :=\nhf.dual.map_max\n\nlemma min_rec {p : \u03b1 \u2192 Prop} {x y : \u03b1} (hx : x \u2264 y \u2192 p x) (hy : y \u2264 x \u2192 p y) : p (min x y) :=\n(le_total x y).rec (\u03bb h, (min_eq_left h).symm.subst (hx h))\n  (\u03bb h, (min_eq_right h).symm.subst (hy h))\n\nlemma max_rec {p : \u03b1 \u2192 Prop} {x y : \u03b1} (hx : y \u2264 x \u2192 p x) (hy : x \u2264 y \u2192 p y) : p (max x y) :=\n@min_rec (order_dual \u03b1) _ _ _ _ hx hy\n\nlemma min_rec' (p : \u03b1 \u2192 Prop) {x y : \u03b1} (hx : p x) (hy : p y) : p (min x y) :=\nmin_rec (\u03bb _, hx) (\u03bb _, hy)\n\nlemma max_rec' (p : \u03b1 \u2192 Prop) {x y : \u03b1} (hx : p x) (hy : p y) : p (max x y) :=\nmax_rec (\u03bb _, hx) (\u03bb _, hy)\n\ntheorem min_choice (a b : \u03b1) : min a b = a \u2228 min a b = b :=\nby cases le_total a b; simp *\n\ntheorem max_choice (a b : \u03b1) : max a b = a \u2228 max a b = b :=\n@min_choice (order_dual \u03b1) _ a b\n\nlemma le_of_max_le_left {a b c : \u03b1} (h : max a b \u2264 c) : a \u2264 c :=\nle_trans (le_max_left _ _) h\n\nlemma le_of_max_le_right {a b c : \u03b1} (h : max a b \u2264 c) : b \u2264 c :=\nle_trans (le_max_right _ _) h\n\nlemma max_commutative : commutative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_comm\n\nlemma max_associative : associative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_assoc\n\nlemma max_left_commutative : left_commutative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_left_comm\n\nlemma min_commutative : commutative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_comm\n\nlemma min_associative : associative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_assoc\n\nlemma min_left_commutative : left_commutative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_left_comm\n\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/order/min_max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.8856314662716159, "lm_q1q2_score": 0.7418225855355266}}
{"text": "/-\nCopyright (c) 2020 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.set.lattice\nimport Mathlib.PostPort\n\nuniverses u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# Accumulate\n\nThe function `accumulate` takes a set `s` and returns `\u22c3 y \u2264 x, s y`.\n-/\n\nnamespace set\n\n\n/-- `accumulate s` is the union of `s y` for `y \u2264 x`. -/\ndef accumulate {\u03b1 : Type u_1} {\u03b2 : Type u_2} [HasLessEq \u03b1] (s : \u03b1 \u2192 set \u03b2) (x : \u03b1) : set \u03b2 :=\n  Union fun (y : \u03b1) => Union fun (H : y \u2264 x) => s y\n\ntheorem accumulate_def {\u03b1 : Type u_1} {\u03b2 : Type u_2} {s : \u03b1 \u2192 set \u03b2} [HasLessEq \u03b1] {x : \u03b1} : accumulate s x = Union fun (y : \u03b1) => Union fun (H : y \u2264 x) => s y :=\n  rfl\n\n@[simp] theorem mem_accumulate {\u03b1 : Type u_1} {\u03b2 : Type u_2} {s : \u03b1 \u2192 set \u03b2} [HasLessEq \u03b1] {x : \u03b1} {z : \u03b2} : z \u2208 accumulate s x \u2194 \u2203 (y : \u03b1), \u2203 (H : y \u2264 x), z \u2208 s y :=\n  mem_bUnion_iff\n\ntheorem subset_accumulate {\u03b1 : Type u_1} {\u03b2 : Type u_2} {s : \u03b1 \u2192 set \u03b2} [preorder \u03b1] {x : \u03b1} : s x \u2286 accumulate s x :=\n  fun (z : \u03b2) => mem_bUnion le_rfl\n\ntheorem monotone_accumulate {\u03b1 : Type u_1} {\u03b2 : Type u_2} {s : \u03b1 \u2192 set \u03b2} [preorder \u03b1] : monotone (accumulate s) :=\n  fun (x y : \u03b1) (hxy : x \u2264 y) =>\n    bUnion_subset_bUnion_left fun (z : \u03b1) (hz : z \u2208 fun (y : \u03b1) => preorder.le y x) => le_trans hz hxy\n\ntheorem bUnion_accumulate {\u03b1 : Type u_1} {\u03b2 : Type u_2} {s : \u03b1 \u2192 set \u03b2} [preorder \u03b1] (x : \u03b1) : (Union fun (y : \u03b1) => Union fun (H : y \u2264 x) => accumulate s y) = Union fun (y : \u03b1) => Union fun (H : y \u2264 x) => s y :=\n  subset.antisymm (bUnion_subset fun (x_1 : \u03b1) (hx : x_1 \u2208 fun (y : \u03b1) => preorder.le y x) => monotone_accumulate hx)\n    (bUnion_subset_bUnion_right fun (x_1 : \u03b1) (hx : x_1 \u2208 fun (y : \u03b1) => preorder.le y x) => subset_accumulate)\n\ntheorem Union_accumulate {\u03b1 : Type u_1} {\u03b2 : Type u_2} {s : \u03b1 \u2192 set \u03b2} [preorder \u03b1] : (Union fun (x : \u03b1) => accumulate s x) = Union fun (x : \u03b1) => s x := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/set/accumulate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7417953201723859}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.game.basic\nimport set_theory.ordinal.natural_ops\n\n/-!\n# Ordinals as games\n\nWe define the canonical map `ordinal \u2192 pgame`, where every ordinal is mapped to the game whose left\nset consists of all previous ordinals.\n\nThe map to surreals is defined in `ordinal.to_surreal`.\n\n# Main declarations\n\n- `ordinal.to_pgame`: The canonical map between ordinals and pre-games.\n- `ordinal.to_pgame_embedding`: The order embedding version of the previous map.\n-/\n\nuniverse u\n\nopen pgame\n\nopen_locale natural_ops pgame\n\nnamespace ordinal\n\n/-- Converts an ordinal into the corresponding pre-game. -/\nnoncomputable! def to_pgame : \u03a0 o : ordinal.{u}, pgame.{u}\n| o := \u27e8o.out.\u03b1, pempty, \u03bb x, let hwf := ordinal.typein_lt_self x in\n        (typein (<) x).to_pgame, pempty.elim\u27e9\nusing_well_founded { dec_tac := tactic.assumption }\n\ntheorem to_pgame_def (o : ordinal) :\n  o.to_pgame = \u27e8o.out.\u03b1, pempty, \u03bb x, (typein (<) x).to_pgame, pempty.elim\u27e9 :=\nby rw to_pgame\n\n@[simp] theorem to_pgame_left_moves (o : ordinal) : o.to_pgame.left_moves = o.out.\u03b1 :=\nby rw [to_pgame, left_moves]\n\n@[simp] theorem to_pgame_right_moves (o : ordinal) : o.to_pgame.right_moves = pempty :=\nby rw [to_pgame, right_moves]\n\ninstance : is_empty (to_pgame 0).left_moves :=\nby { rw to_pgame_left_moves, apply_instance }\n\ninstance (o : ordinal) : is_empty o.to_pgame.right_moves :=\nby { rw to_pgame_right_moves, apply_instance }\n\n/-- Converts an ordinal less than `o` into a move for the `pgame` corresponding to `o`, and vice\nversa. -/\nnoncomputable def to_left_moves_to_pgame {o : ordinal} : set.Iio o \u2243 o.to_pgame.left_moves :=\n(enum_iso_out o).to_equiv.trans (equiv.cast (to_pgame_left_moves o).symm)\n\n@[simp] theorem to_left_moves_to_pgame_symm_lt {o : ordinal} (i : o.to_pgame.left_moves) :\n  \u2191(to_left_moves_to_pgame.symm i) < o :=\n(to_left_moves_to_pgame.symm i).prop\n\ntheorem to_pgame_move_left_heq {o : ordinal} :\n  o.to_pgame.move_left == \u03bb x : o.out.\u03b1, (typein (<) x).to_pgame :=\nby { rw to_pgame, refl }\n\n@[simp] theorem to_pgame_move_left' {o : ordinal} (i) :\n  o.to_pgame.move_left i = (to_left_moves_to_pgame.symm i).val.to_pgame :=\n(congr_heq to_pgame_move_left_heq.symm (cast_heq _ i)).symm\n\ntheorem to_pgame_move_left {o : ordinal} (i) :\n  o.to_pgame.move_left (to_left_moves_to_pgame i) = i.val.to_pgame :=\nby simp\n\ntheorem to_pgame_lf {a b : ordinal} (h : a < b) : a.to_pgame \u29cf b.to_pgame :=\nby { convert move_left_lf (to_left_moves_to_pgame \u27e8a, h\u27e9), rw to_pgame_move_left }\n\ntheorem to_pgame_le {a b : ordinal} (h : a \u2264 b) : a.to_pgame \u2264 b.to_pgame :=\nbegin\n  refine le_iff_forall_lf.2 \u27e8\u03bb i, _, is_empty_elim\u27e9,\n  rw to_pgame_move_left',\n  exact to_pgame_lf ((to_left_moves_to_pgame_symm_lt i).trans_le h)\nend\n\ntheorem to_pgame_lt {a b : ordinal} (h : a < b) : a.to_pgame < b.to_pgame :=\n\u27e8to_pgame_le h.le, to_pgame_lf h\u27e9 \n\n@[simp] theorem to_pgame_lf_iff {a b : ordinal} : a.to_pgame \u29cf b.to_pgame \u2194 a < b :=\n\u27e8by { contrapose, rw [not_lt, not_lf], exact to_pgame_le }, to_pgame_lf\u27e9\n\n@[simp] theorem to_pgame_le_iff {a b : ordinal} : a.to_pgame \u2264 b.to_pgame \u2194 a \u2264 b :=\n\u27e8by { contrapose, rw [not_le, pgame.not_le], exact to_pgame_lf }, to_pgame_le\u27e9\n\n@[simp] theorem to_pgame_lt_iff {a b : ordinal} : a.to_pgame < b.to_pgame \u2194 a < b :=\n\u27e8by { contrapose, rw not_lt, exact \u03bb h, not_lt_of_le (to_pgame_le h) }, to_pgame_lt\u27e9\n\n@[simp] theorem to_pgame_equiv_iff {a b : ordinal} : a.to_pgame \u2248 b.to_pgame \u2194 a = b :=\nby rw [pgame.equiv, le_antisymm_iff, to_pgame_le_iff, to_pgame_le_iff]\n\ntheorem to_pgame_injective : function.injective ordinal.to_pgame :=\n\u03bb a b h, to_pgame_equiv_iff.1 $ equiv_of_eq h\n\n@[simp] theorem to_pgame_eq_iff {a b : ordinal} : a.to_pgame = b.to_pgame \u2194 a = b :=\nto_pgame_injective.eq_iff\n\n/-- The order embedding version of `to_pgame`. -/\n@[simps] noncomputable def to_pgame_embedding : ordinal.{u} \u21aao pgame.{u} :=\n{ to_fun := ordinal.to_pgame,\n  inj' := to_pgame_injective,\n  map_rel_iff' := @to_pgame_le_iff }\n\n/-- The sum of ordinals as games corresponds to natural addition of ordinals. -/\ntheorem to_pgame_add : \u2200 a b : ordinal.{u}, a.to_pgame + b.to_pgame \u2248 (a \u266f b).to_pgame\n| a b := begin\n  refine \u27e8le_of_forall_lf (\u03bb i, _) is_empty_elim, le_of_forall_lf (\u03bb i, _) is_empty_elim\u27e9,\n  { apply left_moves_add_cases i;\n    intro i;\n    let wf := to_left_moves_to_pgame_symm_lt i;\n    try { rw add_move_left_inl }; try { rw add_move_left_inr };\n    rw [to_pgame_move_left', lf_congr_left (to_pgame_add _ _), to_pgame_lf_iff],\n    { exact nadd_lt_nadd_right wf _ },\n    { exact nadd_lt_nadd_left wf _ } },\n  { rw to_pgame_move_left',\n    rcases lt_nadd_iff.1 (to_left_moves_to_pgame_symm_lt i) with \u27e8c, hc, hc'\u27e9 | \u27e8c, hc, hc'\u27e9;\n    rw [\u2190to_pgame_le_iff, \u2190le_congr_right (to_pgame_add _ _)] at hc';\n    apply lf_of_le_of_lf hc',\n    { apply add_lf_add_right,\n      rwa to_pgame_lf_iff },\n    { apply add_lf_add_left,\n      rwa to_pgame_lf_iff } }\nend\nusing_well_founded { dec_tac := `[solve_by_elim [psigma.lex.left, psigma.lex.right]] }\n\n@[simp] theorem to_pgame_add_mk (a b : ordinal) :\n  \u27e6a.to_pgame\u27e7 + \u27e6b.to_pgame\u27e7 = \u27e6(a \u266f b).to_pgame\u27e7 :=\nquot.sound (to_pgame_add a b)\n\nend ordinal\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/set_theory/game/ordinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7417857515182595}}
{"text": "import data.int.basic data.nat.gcd\n\nnamespace int\n\nlemma dvd_mod_iff {k m n : \u2124} (h : k \u2223 n) : k \u2223 m % n \u2194 k \u2223 m :=\nlet t := @dvd_add_iff_left _ _ _ (m % n) _ (dvd_trans h (dvd_mul_right n (m / n))) in\nby rwa mod_add_div at t\n\n@[simp] lemma gcd_zero_left (a : \u2124) : gcd 0 a = a.nat_abs := nat.gcd_zero_left _\n\n@[simp] lemma  gcd_zero_right (a : \u2124) : gcd a 0 = a.nat_abs := nat.gcd_zero_right _\n\n@[simp] lemma gcd_one_left (a : \u2124) : gcd 1 a = 1 := nat.gcd_one_left _\n\n@[simp] lemma gcd_one_right (a : \u2124) : gcd a 1 = 1 := nat.gcd_one_right _\n\nlemma gcd_comm (a b : \u2124) : gcd a b = gcd b a := nat.gcd_comm _ _\n\nlemma gcd_mul_left (a b c : \u2124) : gcd (a * b) (a * c) = a.nat_abs * gcd b c := \nby unfold gcd;\n  rw [nat_abs_mul, nat_abs_mul, nat.gcd_mul_left]\n\nlemma gcd_mul_right (a b c : \u2124) : gcd (b * a) (c * a) = gcd b c * a.nat_abs :=\nby rw [mul_comm b, mul_comm c, gcd_mul_left, mul_comm (gcd b c)]\n\nlemma gcd_pos_of_ne_zero_left {a : \u2124} (b : \u2124) (hb : b \u2260 0) : 0 < gcd a b :=\nby unfold gcd; exact nat.gcd_pos_of_pos_right _ (nat_abs_pos_of_ne_zero hb)\n\n@[simp] lemma gcd_neg (a b : \u2124) : gcd (-a) b = gcd a b :=\nby unfold gcd; rw nat_abs_neg\n\n@[simp] lemma gcd_neg' (a b : \u2124) : gcd a (-b) = gcd a b :=\nby unfold gcd; rw nat_abs_neg\n\nlemma gcd_dvd_left (a b : \u2124) : (gcd a b : \u2124) \u2223 a :=\ndvd_nat_abs.1 $ int.coe_nat_dvd.2 $ nat.gcd_dvd_left _ _\n\nlemma gcd_dvd_right (a b : \u2124) : (gcd a b : \u2124) \u2223 b :=\ndvd_nat_abs.1 $ int.coe_nat_dvd.2 $ nat.gcd_dvd_right _ _ \n\nlemma dvd_gcd {a b c : \u2124} (hb : a \u2223 b) (hc : a \u2223 c) : a \u2223 gcd b c :=\nnat_abs_dvd.1 $ int.coe_nat_dvd.2 (begin\n  rw [\u2190 nat_abs_dvd, \u2190 dvd_nat_abs, int.coe_nat_dvd] at hb hc,\n  exact nat.dvd_gcd hb hc\nend)\n\nlemma gcd_mod (a b : \u2124) : gcd (b % a) a = gcd a b:=\nnat.dvd_antisymm\n  (int.coe_nat_dvd.1 (dvd_gcd (gcd_dvd_right (b % a) a) \n    ((dvd_mod_iff (gcd_dvd_right (b % a) a)).1 (gcd_dvd_left (b % a) a))))\n  (int.coe_nat_dvd.1 (dvd_gcd ((dvd_mod_iff (gcd_dvd_left a b)).2 \n    (gcd_dvd_right a b)) (gcd_dvd_left a b)))\n\nlemma gcd_assoc (a b c : \u2124) : gcd (gcd a b) c = gcd a (gcd b c) := nat.gcd_assoc _ _ _\n\nend int", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/int_gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7417857496785043}}
{"text": "import data.real.basic\n\n/-\n A large rectangle in the plane is partitioned into smaller rectangles, each of which has either integer\nheight or integer width (or both). Prove that the large rectangle also has this property.\n-/\n\nstructure point := mk ::\n(x : \u211d) (y : \u211d)\n\nstructure rect := mk ::\n(bottom_left : point)\n(top_right : point)\n(positive_width : 0 < top_right.x - bottom_left.x)\n(positive_height : 0 < top_right.y - bottom_left.y)\n\ndef rect_width (r : rect) : \u211d := r.top_right.x - r.bottom_left.x\ndef rect_height (r : rect) : \u211d := r.top_right.y - r.bottom_left.y\n\ndef rect_contains_point (r : rect) (p : point) : Prop :=\n  r.bottom_left.x \u2264 p.x \u2227 p.x < r.top_right.x \u2227\n  r.bottom_left.y \u2264 p.y \u2227 p.y < r.top_right.y\n\ndef rects_intersect (r1 : rect) (r2 : rect) : Prop :=\n  \u2203 p : point, rect_contains_point r1 p \u2227 rect_contains_point r2 p\n\ntheorem integers_and_rectangles\n  (big_rect : rect)\n  (n : \u2115)\n  (small_rects : fin n \u2192 rect)\n  (h_cover : \u2200 p : point, rect_contains_point big_rect p \u2192\n             \u2203 m : fin n, rect_contains_point (small_rects m) p)\n  (h_no_overlap : \u2200 m1 m2 : fin n, m1 \u2260 m2 \u2192\n                  \u00ac rects_intersect (small_rects m1) (small_rects m2))\n  (h_integer_sides : \u2200 m : fin n,\n                     \u2203 k : \u2115, rect_width (small_rects m) = k \u2228\n                              rect_height (small_rects m) = k) :\n  \u2203k : \u2115, rect_width big_rect = k \u2228 rect_height big_rect = k :=\nbegin\n  sorry\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/integers_and_rectangles.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7417857494252956}}
{"text": "import tactic.norm_num\n\n/-\nBulgarian Mathematical Olympiad 1998, Problem 1\n\nFind the least natural number n (n \u2265 3) with the following property:\nfor any coloring in 2 colors of n distinct collinear points A_1, A_2, ..., A_n,\nthere exist three points A_i, A_j, A_{2j - i}, 1 \u2264 i < 2j - i \u2264 n, which are colored\nthe same color.\n\nSolution: 9\n\n-/\n\n\ndef coloring_has_desired_points (n: \u2115) (hn: 2 < n) (f: fin n \u2192 fin 2) : Prop :=\n  \u2203 i j : fin n,\n  (\u2203 c : fin 2,\n  (i < j \u2227\n   2 * j.val + 1 < n + i.val \u2227\n   f i = c \u2227 f j = c \u2227\n   f (\u27e82, hn\u27e9 * j + \u27e81, lt_trans one_lt_two hn\u27e9 - i) = c))\n\n\ntheorem bulgaria1998_q1a (f: fin 9 \u2192 fin 2) : coloring_has_desired_points 9 (by norm_num) f :=\nbegin\n  sorry\nend\n\ndef coloring_of_eight : fin 8 \u2192 fin 2\n| \u27e80, _\u27e9 := 0\n| \u27e81, _\u27e9 := 1\n| \u27e82, _\u27e9 := 0\n| \u27e83, _\u27e9 := 1\n| \u27e84, _\u27e9 := 1\n| \u27e85, _\u27e9 := 0\n| \u27e86, _\u27e9 := 1\n| \u27e87, _\u27e9 := 0\n| _ := 0 -- unreachable\n\ntheorem bulgaria1998_q1b :\n  \u2203 f: fin 8 \u2192 fin 2, (\u00ac coloring_has_desired_points 8 (by norm_num) f) :=\nbegin\n  use coloring_of_eight,\n  intro h,\n  obtain \u27e8i, j, c, hij1, hij2, hc1, hc2, hc3\u27e9 := h,\n  sorry\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/bulgaria1998_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7417857374752139}}
{"text": "import number_theory.padics.padic_norm\nimport basic\nimport order.filter.basic\nimport analysis.special_functions.log.base\nimport analysis.normed.ring.seminorm\nimport data.nat.digits\n\nopen_locale big_operators\n\n/-!\n# Ostrowski's theorem for \u211a\n\nThis file states some basic lemmas about mul_ring_norm \u211a\n\n-/\n\nnoncomputable theory\n\nvariable {f : mul_ring_norm \u211a}\n\n-- TODO: remove this\n-- I think this is a missing lemma in mathlib and maybe we can use this for now.\n-- (Done)\nlemma f_mul_eq : mul_eq f := f.map_mul'\n\n-- The norm of -1 is 1\n-- (Done)\nlemma norm_neg_one_eq_one : f (-1) = 1 :=\nbegin\n  have H\u2081 : f (-1) * f (-1) = 1,\n  calc\n    f (-1) * f (-1)  = f ((-1) * (-1)) : by simp\n    ... = f 1 : by norm_num\n    ... = 1 : f.map_one',\n  have H\u2082: f (-1) \u2265 0 := map_nonneg f (-1),\n  rw mul_self_eq_one_iff at H\u2081,\n  cases H\u2081,\n  { exact H\u2081 },\n  { rw H\u2081 at H\u2082,\n    have h' : \u00ac(-1 \u2265 (0 : \u211d)) := by norm_num,\n    contradiction },\nend\n\n-- If x is non-zero, then the norm of x is larger than zero.\n-- (Done)\nlemma norm_pos_of_ne_zero {x : \u211a} (h : x \u2260 0) : f x > 0 :=\nlt_of_le_of_ne (map_nonneg f x) (\u03bb h', h (f.eq_zero_of_map_eq_zero' x h'.symm))\n\n--TODO: generalise to division rings, get rid of field_simp\n-- (Done)\nlemma ring_norm.div_eq (p : \u211a) {q : \u211a} (hq : q \u2260 0) : f (p / q) = (f p) / (f q) :=\nbegin\n  have H : f q \u2260 0,\n  { intro fq0,\n    have := f.eq_zero_of_map_eq_zero' q fq0,\n    exact hq this },\n  calc f (p / q) = f (p / q) * f q / f q : by field_simp\n  ... = f (p / q * q)  / f q : by simp\n  ... = f p / f q : by field_simp,\nend\n\n-- This lemma look a bit strange to me.\n-- (Done)\nlemma int_norm_bound_iff_nat_norm_bound :\n  (\u2200 n : \u2115, f n \u2264 1) \u2194 (\u2200 z : \u2124, f z \u2264 1) :=\nbegin\n  split,\n  { intros h z,\n    obtain \u27e8n, rfl | rfl\u27e9 := z.eq_coe_or_neg,\n    { exact h n },\n    { have : \u2191((-1 : \u2124) * n) = (-1 : \u211a) * n := by norm_cast,\n      rw [neg_eq_neg_one_mul, this, f_mul_eq, norm_neg_one_eq_one, one_mul],\n      exact h n } },\n  { intros h n,\n    exact_mod_cast (h n) },\nend\n\n-- (Done)\nlemma mul_eq_pow {a : \u211a} {n : \u2115} : f (a ^ n) = (f a) ^ n :=\nbegin\n  induction n with d hd,\n  simp only [pow_zero],\n  exact f.map_one',\n  rw [pow_succ, pow_succ, \u2190hd, f_mul_eq],\nend", "meta": {"author": "mariainesdff", "repo": "ostrowski", "sha": "b29d8bd9d98923ec2fab923cb67c76a54aa70386", "save_path": "github-repos/lean/mariainesdff-ostrowski", "path": "github-repos/lean/mariainesdff-ostrowski/ostrowski-b29d8bd9d98923ec2fab923cb67c76a54aa70386/src/mul_ring_norm_rat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912849, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7417257109688747}}
{"text": "import data.set\nimport data.finset\nimport logic.basic\n\nnamespace mth1001\n\nopen set\n\nnamespace set_membership\n\n-- We use `finset \u2115` to denote the type of finite sets of elements of `\u2115`.\n\ndef A := ({1, 2, 3, 4} : finset \u2115) -- This defines `A` to be `{1, 2, 3, 4}`.\ndef B := ({1, 3, 5, 6} : finset \u2115)\ndef C := ({5, 7, 9} : finset \u2115)\n\n/-\nType `\u2208` as `\\in`,\ntype `\u2209` as `\\notin`,\ntype `\u2229` as `\\cap`, \ntype `\u222a` as `\\cup`,\ntype `\u2286` as `\\sub`,\ntype `\u2205` as `\\empty`\ntype `\\` as `\\`,\ntype `\u2115` as `\\N` and `\u2124` as `\\Z`.\n-/\n\n/-\n`dec_trivial` proves results by 'decidability'. You don't need to know what this means.\nLean can use `dec_trivial` to prove results for particular finite sets.\n-/ \n\nexample : 2 \u2208 A := dec_trivial\n\nexample : 5 \u2209 A := dec_trivial\n\nexample : 3 \u2208 (A \u2229 B) := dec_trivial\n\nend set_membership\n\nsection set_equality\n\n/-\nWhenever an mathematical object is defined by its external properties, the Lean tactic `ext`\ntransforms a proof of equality of two objects into a proof of checking that they have the same\nexternal properties. This corresponds to the mathematical principle of *extensionality*.\n\nIn the case of proving two sets `S` and `T` on a type `A` are equal, the `ext` tactic transforms\n`\u22a2 S = T` into an assumption `x : A` and a new goal `\u22a2 x \u2208 S \u2194 x \u2208 T`.\n-/\n\n-- We'll look at sets over a type A.\n\nvariable A : Type*\n\ntheorem set_refl : \u2200 S : set A, S = S :=\nbegin\n  intro S, -- Assume S is a set.\n  ext, -- Assume `x : A`. It suffices to prove `x \u2208 S \u2194 x \u2208 S`.\n  refl, -- The result follows by reflexivity of `\u2194`.\nend\n\ntheorem set_symm : \u2200 S T : set A, S = T \u2192 T = S:=\nbegin\n  intros S T, -- Assume S and T are sets.\n  intro h, -- Assume `h : \u2200 x, x \u2208 S \u2194 x \u2208 T`. It suffices to prove `\u2200 x, x \u2208 T \u2194 x \u2208 S`.\n  ext,       -- Assume `x : A`. It suffices to prove `x \u2208 T \u2194 x \u2208 S`.\n  symmetry, -- By symmetry of `\u2194`, it suffices to prove `x \u2208 S \u2194 x \u2208 T`.\n  rw h, -- This follows from `h`.\nend\n\n-- Exercise 127:\n-- In this exercise, it will be helpful to use the `iff.trans` function. If\n-- `h\u2081 : p \u2194 q` and `h\u2082 : q \u2194 r`, then `iff.trans h\u2081 h\u2082` is a proof of `p \u2194 r`.\ntheorem set_trans : \u2200 S T U : set A, (S = T) \u2227 (T = U) \u2192 S = U :=\nbegin\n  intros S T U, -- Assume S, T, and U are sets.\n  intro h, -- Assume `h : S = T \u2227 T = U`.\n  ext, -- Assume `x : A`. It suffices to prove `x \u2208 S \u2194 x \u2208 U`.\n  have h\u2082 : x \u2208 S \u2194 x \u2208 T, sorry, \n  have h\u2083 : x \u2208 T \u2194 x \u2208 U, sorry, \n  sorry  \nend\n\nend set_equality\n\nsection finite_set_equality\n\n/-\nIn the next example, we show `{5, 6, 7, 8} = {5, 7, 5, 8, 6}`. Note that we must explicitly\nspecify the type of the set. For example, `({5, 6, 7, 8 } : set \u2124)` is the Lean way to\nwrite `{5, 6, 7, 8}`.\n-/\n\nexample : ({5, 6, 7, 8} : finset \u2124) = ({5, 7, 5, 8, 6} : finset \u2124) := dec_trivial\n\n-- Likewise, we can prove two particular finite sets are not equal by `dec_trivial`.\n\nexample : ({5, 6, 7, 8} : finset \u2124) \u2260 ({5, 5, 8, 6} : finset \u2124) := dec_trivial\n\n\n/-\nThe proofs are a bit challenging if we don't use `dec_trivial`. The `finish` tactic proves goals\nby applying rules of logic.\n-/\n\nexample : ({5, 6, 7, 8} : set \u2124) = ({5, 7, 5, 8, 6} : set \u2124) :=\nbegin\n  ext,        -- Use set extensionality.\n  finish,     -- Finish using rules of logic.\nend\n\n/-\nTo prove set inequalities, we can use the `finish` tactic, but we also need to identify an element\nthat belongs to one set but not to the other. We also the set-specific function extenstionality\nresult `ext_iff`.\n-/\n\nexample : ({5, 6, 7, 8} : set \u2124) \u2260 ({5, 5, 8, 6} : set \u2124) :=\nbegin\n  intro h, -- Assume `h : {5, 6, 7, 8} = {5, 5, 8, 6}`.-- It suffices to prove `\u22a5`\n  rw ext_iff at h, -- By definition, `h : \u2200 x, x \u2208 {5, 6, 7, 8} \u2194 x \u2208 {5, 5, 8, 6}`.\n  contrapose! h,   -- Negating this, the goal is `\u2203 x, \u00ac(x \u2208 {5, 6, 7, 8} \u2194 x \u2208 {5, 5, 8, 6})`.\n  use 7, -- By `\u2203` intro. on `7`, it suffices to prove `\u00ac(7 \u2208 {5, 6, 7, 8} \u2194 7 \u2208 {5, 5, 8, 6})`.\n  finish, -- Finish using rules of logic.\nend\n\nend finite_set_equality\n\n\nend mth1001\n\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_22_set_equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7417257096637899}}
{"text": "import tactic basic\n\nnamespace complex\n\n/-! # `ext` : A mathematical triviality -/\n\n/- \nTwo complex numbers with the same and imaginary parts are equal.\nThis is an \"extensionality lemma\", i.e. a lemma of the form \"if two things\nare made from the same pieces, they are equal\".\nThis is not hard to prove, but we want to give the result a name\nso we can tag it with the `ext` attribute, meaning that the\n`ext` tactic will know it. To add to the confusion, let's call the theorem `ext` :-)\n-/\n\n/-- If two complex numbers z and w have equal real and imaginary parts, they are equal -/\n@[ext] theorem ext {z w : \u2102} (hre : re(z) = re(w)) (him : im(z) = im(w)) : z = w :=\nbegin\n  cases z with zr zi,\n  cases w with ww wi,\n  simp at *,\n  /- goal now a logic puzzle\n  \n  hre : zr = ww,\n  him : zi = wi\n  \u22a2 zr = ww \u2227 zi = wi\n  \n  -/\n  cc,\nend\n\n/-! # Theorem:  The complex numbers are a commutative ring -/\n\n-- Proof: we've defined all the structure, and every axiom can be checked by reducing it\n-- to checking real and imaginary parts with `ext`, expanding everything out with `simp`\n-- and then using the fact that the real numbers are a commutative ring.\ninstance : comm_ring \u2102 :=\nbegin\n  -- first the data\n  refine_struct {\n      zero := (0 : \u2102), add := (+), neg := has_neg.neg, one := 1, mul := (*),\n  ..},\n  -- now the axioms\n  -- of which there seem to be 11\n  -- introduce the variables\n  all_goals {intros},\n  -- we now have to prove an equality between two complex numbers.\n  -- It suffices to check on real and imaginary parts\n  all_goals {ext},\n  -- the simplifier can simplify stuff like re(a+0)\n  all_goals {simp},\n  -- all the goals now are identities between *real* numbers,\n  -- and the reals are already known to be a ring\n  all_goals {ring},\nend\n\n\n-- That is the end of the proof that the complexes form a ring. We built\n-- a basic API which was honed towards the general idea that to prove\n-- certain statements about the complex numbers, for example distributivity,\n-- we could just check on real and imaginary parts. We trained the\n-- simplifier to expand out things like re(z*w) in terms\n-- of re(z), im(z), re(w), im(w).\n\n/-!\n\n# Optional section for mathematicians : more basic infrastructure, and term mode\n\n-/\n\n/-! \n## `ext` revisited\n\nRecall extensionality:\n\n`theorem ext {z w : \u2102} (hre : re(z) = re(w)) (him : im(z) = im(w)) : z = w := ...`\n\nHere is another tactic mode proof of extensionality. Note that we have moved\nthe hypotheses to the other side of the colon; this does not\nchange the theorem. This proof shows the power\nof the `rintros` tactic.\n-/\n\ntheorem ext' : \u2200 z w : \u2102, z.re = w.re \u2192 z.im = w.im \u2192 z = w :=\nbegin\n  rintros \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 \u27e8rfl\u27e9 \u27e8rfl\u27e9,\n  refl,\nend\n\n\n/-\nExplanation: `rintros` does `cases` as many times as you like using this cool `\u27e8 \u27e9` syntax\nfor the case splits. Note that if you say that a proof of `a = b` is `rfl` then\nLean will define a to be b, or b to be a, and not even introduce new notation for it.\n-/\n\n-- Here is the same proof in term mode.\n\ntheorem ext'' : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\n/-!\n## `eta`\n-/\n\n/-\nWe prove the mathematically obvious statement that the\ncomplex number whose real part is re(z) and whose imaginary\npart is im(z) is of course equal to z.\n-/\n\n/-- \u27e8z.re, z.im\u27e9 is equal to z -/\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z :=\nbegin\n  intro z,\n  cases z with x y, \n  /-\n    goal now looks complicated, and contains terms which look\n    like {re := a, im := b}.re which obviously simplify to a.\n    The `dsimp` tactic will do some tidying up for us, although\n    it is not logically necessary. `dsimp` does definitional simplification.\n  -/\n  dsimp,\n  -- Now we see the goal can be solved by reflexivity\n  refl,\nend\n\n/-\nThe proof was \"unfold everything, and it's true by definition\".\nThis proof does not teach a mathematician anything, so we may as well write\nit in term mode. Many tactics have term mode equivalent.\nThe equation compiler does the `intro` and `cases` steps,\nand `dsimp` was unnecessary -- the two sides of the equation \nwere definitionally equal.\n-/\n\ntheorem eta' : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8x, y\u27e9 := rfl\n\n/-!\n## ext_iff\n-/\n\n/-\nNote that `ext` is an implication -- if re(z)=re(w) and im(z)=im(w) then z=w.\nThe below variant `ext_iff` is the two-way implication: two complex\nnumbers are equal if and only if they have the same real and imaginary part.\nLet's first see a tactic mode proof. See how the `ext` tactic is used?\nAfter it is applied, we have two goals, both of which are hypotheses.\nThe semicolon means \"apply the next tactic to all the goals produced by this one\"\n-/\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\nbegin\n  split,\n  { intro H,\n    simp [H]},\n  {\n    rintro \u27e8hre, him\u27e9,\n    ext; assumption,\n  }\nend\n\n-- Again this is easy to write in term mode, and no mathematician\n-- wants to read the proof anyway.\n\ntheorem ext_iff' {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\nend complex\n\n/-!\n\n# some last comments on the `simp` tactic\n\nSome equalities, even if obvious, had to be given names, because we want `simp`\nto be able to use them. In short, the `simp` tactic tries to solve\ngoals of the form A = B, when `refl` doesn't work (i.e. the goals are\nnot definitionally equal) but when any mathematician would be able\nto simplify A and B via \"obvious\" steps such as `0 + x = x` or\n`\u27e8z.re, z.im\u27e9 = z`. These things are sometimes not true by definition,\nbut they should be tagged as being well-known ways to simplify an equality.\nWhen building our API for the complex numbers, if we prove a theorem of the\nform `A = B` where `B` is a bit simpler than `A`, we should probably\ntag it with the `@[simp]` attribute, so `simp` can use it.\n\nNote: `simp` does *not* prove \"all simple things\". It proves *equalities*.\nIt proves `A = B` when, and only when, it can do it by applying \nits \"simplification rules\", where a simplification rule is simply a proof\nof a theorem of the form `A = B` and `B` is simpler than `A`.  \n-/\n\n\n------------------ VERY INTERESTING BITS -------------------------\n\n/-- The canonical map from \u211d to \u2102. -/\ndef of_real (r : \u211d) : \u2102 := \u27e8r, 0\u27e9 \n\n/-\nWe make this map into a *coercion*, which means that if `(r : \u211d)` is a real\nnumber, then `(r : \u2102)` or `(\u2191r : \u2102)` will indicate the corresponding\ncomplex number with no imaginary part. This is the notation we shall\nuse in our `simp` lemmas.\n-/\n\n/-- The coercion from \u211d to \u2102 sending `r` to the complex number `\u27e8r, 0\u27e9` -/\ninstance : has_coe \u211d \u2102 := \u27e8of_real\u27e9", "meta": {"author": "jamesa9283", "repo": "MATH1001", "sha": "468ae6863a4a5090fe171f4a11ca55b3f65d4359", "save_path": "github-repos/lean/jamesa9283-MATH1001", "path": "github-repos/lean/jamesa9283-MATH1001/MATH1001-468ae6863a4a5090fe171f4a11ca55b3f65d4359/src/ext_comm_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856561, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.7417257010805139}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module measure_theory.measure.open_pos\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.MeasureSpace\n\n/-!\n# Measures positive on nonempty opens\n\nIn this file we define a typeclass for measures that are positive on nonempty opens, see\n`measure_theory.measure.is_open_pos_measure`. Examples include (additive) Haar measures, as well as\nmeasures that have positive density with respect to a Haar measure. We also prove some basic facts\nabout these measures.\n\n-/\n\n\nopen Topology ENNReal MeasureTheory\n\nopen Set Function Filter\n\nnamespace MeasureTheory\n\nnamespace Measure\n\nsection Basic\n\nvariable {X Y : Type _} [TopologicalSpace X] {m : MeasurableSpace X} [TopologicalSpace Y]\n  [T2Space Y] (\u03bc \u03bd : Measure X)\n\n/-- A measure is said to be `is_open_pos_measure` if it is positive on nonempty open sets. -/\nclass IsOpenPosMeasure : Prop where\n  open_pos : \u2200 U : Set X, IsOpen U \u2192 U.Nonempty \u2192 \u03bc U \u2260 0\n#align measure_theory.measure.is_open_pos_measure MeasureTheory.Measure.IsOpenPosMeasure\n\nvariable [IsOpenPosMeasure \u03bc] {s U : Set X} {x : X}\n\ntheorem IsOpen.measure_ne_zero (hU : IsOpen U) (hne : U.Nonempty) : \u03bc U \u2260 0 :=\n  IsOpenPosMeasure.open_pos U hU hne\n#align is_open.measure_ne_zero IsOpen.measure_ne_zero\n\ntheorem IsOpen.measure_pos (hU : IsOpen U) (hne : U.Nonempty) : 0 < \u03bc U :=\n  (hU.measure_ne_zero \u03bc hne).bot_lt\n#align is_open.measure_pos IsOpen.measure_pos\n\ntheorem IsOpen.measure_pos_iff (hU : IsOpen U) : 0 < \u03bc U \u2194 U.Nonempty :=\n  \u27e8fun h => nonempty_iff_ne_empty.2 fun he => h.ne' <| he.symm \u25b8 measure_empty, hU.measure_pos \u03bc\u27e9\n#align is_open.measure_pos_iff IsOpen.measure_pos_iff\n\ntheorem IsOpen.measure_eq_zero_iff (hU : IsOpen U) : \u03bc U = 0 \u2194 U = \u2205 := by\n  simpa only [not_lt, nonpos_iff_eq_zero, not_nonempty_iff_eq_empty] using\n    not_congr (hU.measure_pos_iff \u03bc)\n#align is_open.measure_eq_zero_iff IsOpen.measure_eq_zero_iff\n\ntheorem measure_pos_of_nonempty_interior (h : (interior s).Nonempty) : 0 < \u03bc s :=\n  (isOpen_interior.measure_pos \u03bc h).trans_le (measure_mono interior_subset)\n#align measure_theory.measure.measure_pos_of_nonempty_interior MeasureTheory.Measure.measure_pos_of_nonempty_interior\n\ntheorem measure_pos_of_mem_nhds (h : s \u2208 \ud835\udcdd x) : 0 < \u03bc s :=\n  measure_pos_of_nonempty_interior _ \u27e8x, mem_interior_iff_mem_nhds.2 h\u27e9\n#align measure_theory.measure.measure_pos_of_mem_nhds MeasureTheory.Measure.measure_pos_of_mem_nhds\n\ntheorem isOpenPosMeasureSmul {c : \u211d\u22650\u221e} (h : c \u2260 0) : IsOpenPosMeasure (c \u2022 \u03bc) :=\n  \u27e8fun U Uo Une => mul_ne_zero h (Uo.measure_ne_zero \u03bc Une)\u27e9\n#align measure_theory.measure.is_open_pos_measure_smul MeasureTheory.Measure.isOpenPosMeasureSmul\n\nvariable {\u03bc \u03bd}\n\nprotected theorem AbsolutelyContinuous.isOpenPosMeasure (h : \u03bc \u226a \u03bd) : IsOpenPosMeasure \u03bd :=\n  \u27e8fun U ho hne h\u2080 => ho.measure_ne_zero \u03bc hne (h h\u2080)\u27e9\n#align measure_theory.measure.absolutely_continuous.is_open_pos_measure MeasureTheory.Measure.AbsolutelyContinuous.isOpenPosMeasure\n\ntheorem LE.le.isOpenPosMeasure (h : \u03bc \u2264 \u03bd) : IsOpenPosMeasure \u03bd :=\n  h.AbsolutelyContinuous.IsOpenPosMeasure\n#align has_le.le.is_open_pos_measure LE.le.isOpenPosMeasure\n\ntheorem IsOpen.eq_empty_of_measure_zero (hU : IsOpen U) (h\u2080 : \u03bc U = 0) : U = \u2205 :=\n  (hU.measure_eq_zero_iff \u03bc).mp h\u2080\n#align is_open.eq_empty_of_measure_zero IsOpen.eq_empty_of_measure_zero\n\ntheorem interior_eq_empty_of_null (hs : \u03bc s = 0) : interior s = \u2205 :=\n  isOpen_interior.eq_empty_of_measure_zero <| measure_mono_null interior_subset hs\n#align measure_theory.measure.interior_eq_empty_of_null MeasureTheory.Measure.interior_eq_empty_of_null\n\n/-- If two functions are a.e. equal on an open set and are continuous on this set, then they are\nequal on this set. -/\ntheorem eqOn_open_of_ae_eq {f g : X \u2192 Y} (h : f =\u1d50[\u03bc.restrict U] g) (hU : IsOpen U)\n    (hf : ContinuousOn f U) (hg : ContinuousOn g U) : EqOn f g U :=\n  by\n  replace h := ae_imp_of_ae_restrict h\n  simp only [eventually_eq, ae_iff, not_imp] at h\n  have : IsOpen (U \u2229 { a | f a \u2260 g a }) :=\n    by\n    refine' is_open_iff_mem_nhds.mpr fun a ha => inter_mem (hU.mem_nhds ha.1) _\n    rcases ha with \u27e8ha : a \u2208 U, ha' : (f a, g a) \u2208 diagonal Y\u1d9c\u27e9\n    exact\n      (hf.continuous_at (hU.mem_nhds ha)).prod_mk_nhds (hg.continuous_at (hU.mem_nhds ha))\n        (is_closed_diagonal.is_open_compl.mem_nhds ha')\n  replace := (this.eq_empty_of_measure_zero h).le\n  exact fun x hx => Classical.not_not.1 fun h => this \u27e8hx, h\u27e9\n#align measure_theory.measure.eq_on_open_of_ae_eq MeasureTheory.Measure.eqOn_open_of_ae_eq\n\n/-- If two continuous functions are a.e. equal, then they are equal. -/\ntheorem eq_of_ae_eq {f g : X \u2192 Y} (h : f =\u1d50[\u03bc] g) (hf : Continuous f) (hg : Continuous g) : f = g :=\n  suffices EqOn f g univ from funext fun x => this trivial\n  eqOn_open_of_ae_eq (ae_restrict_of_ae h) isOpen_univ hf.ContinuousOn hg.ContinuousOn\n#align measure_theory.measure.eq_of_ae_eq MeasureTheory.Measure.eq_of_ae_eq\n\ntheorem eqOn_of_ae_eq {f g : X \u2192 Y} (h : f =\u1d50[\u03bc.restrict s] g) (hf : ContinuousOn f s)\n    (hg : ContinuousOn g s) (hU : s \u2286 closure (interior s)) : EqOn f g s :=\n  have : interior s \u2286 s := interior_subset\n  (eqOn_open_of_ae_eq (ae_restrict_of_ae_restrict_of_subset this h) isOpen_interior (hf.mono this)\n        (hg.mono this)).of_subset_closure\n    hf hg this hU\n#align measure_theory.measure.eq_on_of_ae_eq MeasureTheory.Measure.eqOn_of_ae_eq\n\nvariable (\u03bc)\n\ntheorem Continuous.ae_eq_iff_eq {f g : X \u2192 Y} (hf : Continuous f) (hg : Continuous g) :\n    f =\u1d50[\u03bc] g \u2194 f = g :=\n  \u27e8fun h => eq_of_ae_eq h hf hg, fun h => h \u25b8 EventuallyEq.rfl\u27e9\n#align continuous.ae_eq_iff_eq Continuous.ae_eq_iff_eq\n\nend Basic\n\nsection LinearOrder\n\nvariable {X Y : Type _} [TopologicalSpace X] [LinearOrder X] [OrderTopology X]\n  {m : MeasurableSpace X} [TopologicalSpace Y] [T2Space Y] (\u03bc : Measure X) [IsOpenPosMeasure \u03bc]\n\ntheorem measure_Ioi_pos [NoMaxOrder X] (a : X) : 0 < \u03bc (Ioi a) :=\n  isOpen_Ioi.measure_pos \u03bc nonempty_Ioi\n#align measure_theory.measure.measure_Ioi_pos MeasureTheory.Measure.measure_Ioi_pos\n\ntheorem measure_Iio_pos [NoMinOrder X] (a : X) : 0 < \u03bc (Iio a) :=\n  isOpen_Iio.measure_pos \u03bc nonempty_Iio\n#align measure_theory.measure.measure_Iio_pos MeasureTheory.Measure.measure_Iio_pos\n\ntheorem measure_Ioo_pos [DenselyOrdered X] {a b : X} : 0 < \u03bc (Ioo a b) \u2194 a < b :=\n  (isOpen_Ioo.measure_pos_iff \u03bc).trans nonempty_Ioo\n#align measure_theory.measure.measure_Ioo_pos MeasureTheory.Measure.measure_Ioo_pos\n\ntheorem measure_Ioo_eq_zero [DenselyOrdered X] {a b : X} : \u03bc (Ioo a b) = 0 \u2194 b \u2264 a :=\n  (isOpen_Ioo.measure_eq_zero_iff \u03bc).trans (Ioo_eq_empty_iff.trans not_lt)\n#align measure_theory.measure.measure_Ioo_eq_zero MeasureTheory.Measure.measure_Ioo_eq_zero\n\ntheorem eqOn_Ioo_of_ae_eq {a b : X} {f g : X \u2192 Y} (hfg : f =\u1d50[\u03bc.restrict (Ioo a b)] g)\n    (hf : ContinuousOn f (Ioo a b)) (hg : ContinuousOn g (Ioo a b)) : EqOn f g (Ioo a b) :=\n  eqOn_of_ae_eq hfg hf hg Ioo_subset_closure_interior\n#align measure_theory.measure.eq_on_Ioo_of_ae_eq MeasureTheory.Measure.eqOn_Ioo_of_ae_eq\n\ntheorem eqOn_Ioc_of_ae_eq [DenselyOrdered X] {a b : X} {f g : X \u2192 Y}\n    (hfg : f =\u1d50[\u03bc.restrict (Ioc a b)] g) (hf : ContinuousOn f (Ioc a b))\n    (hg : ContinuousOn g (Ioc a b)) : EqOn f g (Ioc a b) :=\n  eqOn_of_ae_eq hfg hf hg (Ioc_subset_closure_interior _ _)\n#align measure_theory.measure.eq_on_Ioc_of_ae_eq MeasureTheory.Measure.eqOn_Ioc_of_ae_eq\n\ntheorem eqOn_Ico_of_ae_eq [DenselyOrdered X] {a b : X} {f g : X \u2192 Y}\n    (hfg : f =\u1d50[\u03bc.restrict (Ico a b)] g) (hf : ContinuousOn f (Ico a b))\n    (hg : ContinuousOn g (Ico a b)) : EqOn f g (Ico a b) :=\n  eqOn_of_ae_eq hfg hf hg (Ico_subset_closure_interior _ _)\n#align measure_theory.measure.eq_on_Ico_of_ae_eq MeasureTheory.Measure.eqOn_Ico_of_ae_eq\n\ntheorem eqOn_Icc_of_ae_eq [DenselyOrdered X] {a b : X} (hne : a \u2260 b) {f g : X \u2192 Y}\n    (hfg : f =\u1d50[\u03bc.restrict (Icc a b)] g) (hf : ContinuousOn f (Icc a b))\n    (hg : ContinuousOn g (Icc a b)) : EqOn f g (Icc a b) :=\n  eqOn_of_ae_eq hfg hf hg (closure_interior_Icc hne).symm.Subset\n#align measure_theory.measure.eq_on_Icc_of_ae_eq MeasureTheory.Measure.eqOn_Icc_of_ae_eq\n\nend LinearOrder\n\nend Measure\n\nend MeasureTheory\n\nopen MeasureTheory MeasureTheory.Measure\n\nnamespace Metric\n\nvariable {X : Type _} [PseudoMetricSpace X] {m : MeasurableSpace X} (\u03bc : Measure X)\n  [IsOpenPosMeasure \u03bc]\n\ntheorem measure_ball_pos (x : X) {r : \u211d} (hr : 0 < r) : 0 < \u03bc (ball x r) :=\n  isOpen_ball.measure_pos \u03bc (nonempty_ball.2 hr)\n#align metric.measure_ball_pos Metric.measure_ball_pos\n\ntheorem measure_closedBall_pos (x : X) {r : \u211d} (hr : 0 < r) : 0 < \u03bc (closedBall x r) :=\n  (measure_ball_pos \u03bc x hr).trans_le (measure_mono ball_subset_closedBall)\n#align metric.measure_closed_ball_pos Metric.measure_closedBall_pos\n\nend Metric\n\nnamespace Emetric\n\nvariable {X : Type _} [PseudoEMetricSpace X] {m : MeasurableSpace X} (\u03bc : Measure X)\n  [IsOpenPosMeasure \u03bc]\n\ntheorem measure_ball_pos (x : X) {r : \u211d\u22650\u221e} (hr : r \u2260 0) : 0 < \u03bc (ball x r) :=\n  isOpen_ball.measure_pos \u03bc \u27e8x, mem_ball_self hr.bot_lt\u27e9\n#align emetric.measure_ball_pos Emetric.measure_ball_pos\n\ntheorem measure_closedBall_pos (x : X) {r : \u211d\u22650\u221e} (hr : r \u2260 0) : 0 < \u03bc (closedBall x r) :=\n  (measure_ball_pos \u03bc x hr).trans_le (measure_mono ball_subset_closedBall)\n#align emetric.measure_closed_ball_pos Emetric.measure_closedBall_pos\n\nend Emetric\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Measure/OpenPos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7417169552470692}}
{"text": "/-\nCopyright (c) 2018 Keji Neri, Blair Shi. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Keji Neri, Blair Shi\n\n* `finite_free_module R n`: the set of maps from (fin n) to R (R ^ n)\n\n-- Proved R^n is an abellian group and module R (R ^ n)\n\n* `matrix_to_linear_map` : constructs a matrix based on the given linear map\n\n* `linear_map_to_matrix` : constructs the linear map based on the given matrix\n\n-- Proved the a x b matrices and R-linear maps R^b -> R^a are equivalent \n\n-- Proved the product of two matrix is equivalent to the component of two \n-- corresponding linear maps\n\n-- Proved Hom(R^b,R^a)\n\n* `linear_map_to_vec V n` : constructs the basis based on the linear map \n\n* `vec_to_linear_map V n M` : construct the linear map based on the given basis\n\n-- proved a basis v1,v2,...,vn of a fdvs V/k is just an isomorphism k^n -> V\n-/\n\nimport xenalib.Ellen_Arlt_matrix_rings  algebra.big_operators\nimport data.set.finite algebra.module  data.finsupp\nimport algebra.group linear_algebra.basic data.fintype\nimport data.equiv.basic linear_algebra.linear_map_module\nimport algebra.pi_instances algebra.module data.list.basic\n\nopen function  \n\nuniverse u\nvariables {\u03b1 : Type u}\nvariables {\u03b2 : Type*} [add_comm_group \u03b1] [add_comm_group \u03b2]\n\n/-- Predicate for group homomorphism. -/\nclass is_add_group_hom (f : \u03b1 \u2192 \u03b2) : Prop :=\n(add : \u2200 a b : \u03b1, f (a + b) = (f a) + (f b))\nnamespace is_add_group_hom\nvariables (f : \u03b1 \u2192 \u03b2) [is_add_group_hom f]\n\ntheorem zero : f 0 = 0 :=\nadd_self_iff_eq_zero.1 $ by simp [(add f 0 _).symm]\n\ntheorem inv (a : \u03b1) : f(-a)  = -(f a) :=\neq.symm $ neg_eq_of_add_eq_zero $ by simp [(add f a (-a)).symm, zero f]\n\ninstance id : is_add_group_hom (@id \u03b1) :=\n\u27e8\u03bb _ _, rfl\u27e9\n\ninstance comp {\u03b3} [add_comm_group \u03b3] (g : \u03b2 \u2192 \u03b3) [is_add_group_hom g] :\n  is_add_group_hom (g \u2218 f) :=\n\u27e8\u03bb x y, calc\n  g (f (x + y)) = g (f x + f y)       : by rw add f\n  ...           = g (f x) + g (f y)   : by rw add g\u27e9\n\nend is_add_group_hom\n\ndefinition finite_free_module (R : Type) (n : nat) := (fin n) \u2192 R\n\ndef add (R : Type) (n : nat) [ring R] := \n\u03bb (a b :finite_free_module R n), (\u03bb i, (a i) +(b i))\n\ndef smul {R : Type} {n : nat} [ring R] (s : R) (rn : finite_free_module R n) : \nfinite_free_module R n := \u03bb I, s * (rn I)\n\ntheorem add__assoc {R : Type} {n : nat} [ring R] (a b c :(fin n) \u2192 R) : \n  add R n (add R n a b) c = add R n a (add R n b c):=\nbegin \nunfold add,\nfunext,\nsimp,\nend\ntheorem add__comm {R : Type} {n : nat} [ring R] (a b :(fin n) \u2192 R):\n add R n a b =add R n b a :=\nbegin \nunfold add,\nfunext,\nexact add_comm (a i) (b i),\nend\n\ndef zero (R : Type) (n : nat) [ring R]: finite_free_module R n := \u03bb (i:fin n),(0 :R)\n#check zero\ntheorem zero__add {R : Type} {n : nat} [ring R] (a:finite_free_module R n): add R n (zero R n) a = a:=\nbegin \nunfold add,\nfunext,\nunfold zero,\nsimp,\nend\n\ndef neg (R : Type) (n : nat) [ring R]:= \u03bb (a:finite_free_module R n),(\u03bb i, -(a i))\ntheorem add__left__neg {R : Type} {n : nat} [ring R] (a :finite_free_module R n): add R n (neg R n a) a = zero R n:=\nbegin \nunfold add,\nunfold zero,\nfunext,\nunfold neg,\nsimp,\nend \n\ndef add__zero {R : Type} {n : nat} [ring R] (a :finite_free_module R n): add R n a (zero R n) =a:=\nbegin\nunfold add,\nfunext,\nunfold zero,\nsimp,\nend\n\nlemma is_add_group_hom_right_inv {\u03b1 \u03b2 : Type*} [add_comm_group \u03b1] [add_comm_group \u03b2] \n{f: \u03b1 \u2192 \u03b2} [is_add_group_hom f] (hf : injective f) { g :\u03b2 \u2192 \u03b1} (h: right_inverse g f):\nis_add_group_hom g:= \u27e8 \u03bb a b, hf $ by  rw[h(a+b),is_add_group_hom.add f,h a,h b]\u27e9 \n\ninstance (R : Type) [ring R] (n : nat) : add_comm_group (finite_free_module R n) := \n{add:=add R n,\nadd_assoc := add__assoc,\nzero := zero R n,\nzero_add:= zero__add,\nneg:=neg R n,\nadd_left_neg:= add__left__neg, \nadd_zero:= add__zero ,\nadd_comm:= add__comm,\n}\n\nnamespace R_module\nvariables (R : Type) (n : nat)\nvariable [ring R] \n\ntheorem smul_add (s : R) (rn rm : finite_free_module R n) : \n    smul s (add R n rn rm) = add R n (smul s rn) (smul s rm) := \n-- s \u2022 (rn + rm) = s \u2022 rn + s \u2022 rm \n    begin\n      apply funext,\n      intro,\n      unfold smul add,\n      apply mul_add,\n    end \n\ntheorem add_smul (s t : R) (rn: finite_free_module R n): \n    smul (s + t) rn = add R n (smul s rn) (smul t rn) := \n    begin\n      apply funext,\n      intro,\n      unfold smul add,\n      apply add_mul,\n    end\n\ntheorem mul_smul (s t : R) (rn : finite_free_module R n): \n    smul (s * t) rn = smul s (smul t rn) :=\n    begin\n      apply funext,\n      intro,\n      unfold smul,\n      apply mul_assoc,\n    end\n\ntheorem one_smul (rn : finite_free_module R n): \n    smul (1 : R) rn = rn :=\n    begin\n      apply funext,\n      intro,\n      unfold smul,\n      apply one_mul,\n    end\nend R_module\n\ninstance (R : Type) [ring R] (n : nat) : has_scalar R (finite_free_module R n) :=\n{ \n    smul := smul\n}\n\ninstance {R : Type} {n : nat} [ring R] : module R (finite_free_module R n) :=\n{   \n    smul_add := R_module.smul_add R n,\n    add_smul := R_module.add_smul R n,\n    mul_smul := R_module.mul_smul R n,\n    one_smul := R_module.one_smul R n,\n}\n\nnamespace map_matrix\n\ndefinition matrix_to_map {R : Type} [ring R] {a b : nat} (M : matrix R a b) :\n(finite_free_module R a) \u2192 (finite_free_module R b) := \u03bb v ,(\u03bb i,finset.sum finset.univ (\u03bb K, (v K) *M K i ) )\n\ninstance hg {R : Type} [ring R] {a b : nat} (M : matrix R a b) : is_add_group_hom (matrix_to_map M) := \n\u27e8begin\nintros,\nfunext,\nunfold matrix_to_map,\n\nshow (finset.sum finset.univ (\u03bb (K : fin a), (a_1 K + b_1 K)  * M K i) =_),\nconv in ( (a_1 _ + b_1 _) * M _ i)\n  begin\n    rw [add_mul],\n  end,\n\nrw finset.sum_add_distrib,\nrefl,\nend\u27e9 \n\ntheorem smul_ {R: Type} [ring R] {a b : nat} (M : matrix R a b): \u2200 (c : R) (x : finite_free_module R a), \nmatrix_to_map M (smul c x) = smul c (matrix_to_map M x):=\nbegin \nintros,\nunfold matrix_to_map,\nfunext,\nunfold smul,\nrw [finset.mul_sum],\nsimp[mul_assoc],\nend\n\ndef module_hom {R: Type} [ring R] {a b : nat} (M : matrix R a b) : \n  @is_linear_map R _ _ _ _ _ (matrix_to_map M) :=\n { add:= \n begin \nexact is_add_group_hom.add _,\n end,\n smul:= smul_ _,\n}\n\ndef matrix_to_linear_map {R : Type} [ring R] {a b : nat} (M : matrix R a b) : \n(@linear_map R (finite_free_module R a)  (finite_free_module R b) _ _ _) :=\n\u27e8matrix_to_map M, module_hom M\u27e9 \n\ndef e (R : Type) [ring R] (a: nat) (i: fin a): finite_free_module R a:= \u03bb j, if i =j then 1 else 0\n\ndefinition linear_map_to_matrix {R : Type} [ring R] {a b : nat} \n(f: @linear_map R (finite_free_module R a) (finite_free_module R b) _ _ _) : matrix R a b :=\n    \u03bb i j, f.1 (e R a i) j\n\ntheorem finset.sum_single {\u03b1 : Type*} [fintype \u03b1]\n  {\u03b2 : Type*} [add_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) {i : \u03b1}\n  (h : \u2200 (j : \u03b1), i \u2260 j \u2192 f j = 0) :\nf i = finset.sum finset.univ (\u03bb (K : \u03b1), f K) :=\nbegin\n  have H : finset.sum (finset.singleton i) (\u03bb (K : \u03b1), f K)\n    = finset.sum finset.univ (\u03bb (K : \u03b1), f K),\n  from finset.sum_subset (\u03bb _ _, finset.mem_univ _)\n    (\u03bb _ _ H, h _ $ mt (\u03bb h, finset.mem_singleton.2 h.symm) H),\n  rw [\u2190 H, finset.sum_singleton]\nend \n\ntheorem apply_function_to_sum {R : Type}[ring R] {n p : nat} (f: fin n \u2192 finite_free_module R p ) (i : fin p ): \n(finset.sum finset.univ (\u03bb (K : fin n),f K)) i = finset.sum finset.univ (\u03bb (K : fin n), f K i):=\nbegin\nrw finset.sum_hom (\u03bb (v: finite_free_module R p), v i ) _,\nintros,\nsimp,\nrefl,\nend\n\ntheorem span {R : Type} {n : nat} [ring R] (v : finite_free_module R n): \nv  = finset.sum finset.univ (\u03bb K, smul (v K) (e R n K)):=\nbegin \nfunext,\nrw [apply_function_to_sum (\u03bb i, smul (v i) (e R n i))],\nsimp,\nunfold smul,\n  have H1 : \u2200 (j : fin n), x \u2260 j \u2192 v j * (e R n j) x = 0,\n    intros,\n    unfold e,\n    split_ifs,\n      exact false.elim (a h.symm),\n    simp,\n  have H2: finset.sum finset.univ (\u03bb (K : fin n), v K * e R n K x) = v x * e R n x x,\n    have Htemp := finset.sum_single (\u03bb (K:fin n), v K * e R n K x ) H1,\n    rw \u2190Htemp,\n  rw H2,\n  unfold e,\n  split_ifs,\n  simp,\n  simp,  \nend \n\ntheorem equiv_one {R : Type} [ring R] {a b : nat} (f : (@linear_map R (finite_free_module R a) (finite_free_module R b) _ _ _)) :\n    matrix_to_map (linear_map_to_matrix f ) = f := \nbegin\nfunext,\nunfold linear_map_to_matrix,\nunfold matrix_to_map,\nconv begin\nto_rhs,\nrw [span v],\nend,\nrw [\u2190 finset.sum_hom f _],\nswap 3,\nexact is_linear_map.zero f.2,\nswap 2,\nexact f.2.add,\nrw[apply_function_to_sum (\u03bb j,f (smul (v j) (e R a j)))],\nsimp,\nshow _ = finset.sum finset.univ (\u03bb (K : fin a), f ((v K) \u2022 (e R a K)) i),\ncongr,\nfunext,\nrw[( linear_map.is_linear_map_coe).smul],\nrefl,\nend \n\ntheorem equiv_two {R : Type} [ring R] {p b : nat} (M : matrix R p b):\n  linear_map_to_matrix \u27e8 matrix_to_map M, module_hom M\u27e9  = M := \n  begin\n   funext,\n   unfold linear_map_to_matrix,\n   show (matrix_to_map M) (e R p i) j =_,\n   unfold matrix_to_map,\n    have H1: \u2200 (K : fin p), i \u2260 K \u2192  e R p i K * M K j = 0,\n    intros,\n    unfold e,\n    split_ifs,\n    exact false.elim (a h),\n    simp,\n    have H2: finset.sum finset.univ (\u03bb (K : fin p), e R p i K * M K j) = e R p i i * M i j,\n       have Htemp := finset.sum_single (\u03bb (K : fin p), e R p i K * M K j) H1,\n    rw \u2190 Htemp,\n    rw H2,\n    unfold e,\n    split_ifs,\n    simp,\n    simp,\n  end\n\ndef matrix_transpose {R : Type} [ring R] {a b : nat} (M : matrix R a b) :\nmatrix R b a := \u03bb I, \u03bb J, M J I\n\ndefinition matrix_to_map_right {R : Type} [ring R] {a b : nat} (M : matrix R a b) :\n(finite_free_module R a) \u2192 (finite_free_module R b) := \n\u03bb v, (\u03bb I, finset.sum finset.univ (\u03bb K, (matrix_transpose M) I K * (v K)))\n\n-- end\n\ndef matrix_to_linear_map_equiv {R : Type} [ring R] {a b : nat} :\n  equiv  (matrix R a b)  (@linear_map R (finite_free_module R a)  (finite_free_module R b) _ _ _):= \n    {to_fun := matrix_to_linear_map,\n    inv_fun := linear_map_to_matrix,\n    right_inv:= \n    begin \n     unfold function.right_inverse,\n     unfold function.left_inverse,\n     intros,\n    apply subtype.eq,\n    dsimp,\n    exact equiv_one x, \n    end,\n\n    left_inv:= \n    begin \n    unfold function.left_inverse,\n    intros,\n    exact equiv_two x,\n    end  \n   }\n\ninstance {R : Type} [ring R] {a b : nat}:  is_add_group_hom (@matrix_to_linear_map R _ a b):=\n  { \n  add:= \n  begin \n  intros,\n  unfold matrix_to_linear_map,\n  apply linear_map.ext, \n  intro x,\n  show _ = matrix_to_map a_1 x + matrix_to_map b_1 x,\n  show matrix_to_map (a_1 + b_1) x = _,\n  unfold matrix_to_map,\n  funext,\n  show _ = (finset.sum finset.univ (\u03bb (K : fin a), x K * a_1 K i)) +\n       ( finset.sum finset.univ (\u03bb (K : fin a), x K * b_1 K i)), \n      \n  rw[\u2190 finset.sum_add_distrib],\n  congr,\n  funext,\n  have H1: x K * (a_1 + b_1) K i = x K * (a_1 K i + b_1 K i),\n  refl,\n  rw[H1],\n  rw[mul_add],\n  end\n}\n\ntheorem comp_is_linear_map {R : Type} [ring R] {a b c : nat} \n(f : (@linear_map R (finite_free_module R b)  (finite_free_module R a) _ _ _)) \n(g : (@linear_map R (finite_free_module R c)  (finite_free_module R b) _ _ _)):\n  @is_linear_map R _ _ _ _ _ (f.1 \u2218 g.1):= \n{ \n  add:= \n    begin \n      intros,\n      simp,\n      have H1: f.val (g.val (x) + g.val(y)) = f.val (g.val (x + y)),\n      rw[g.2.add],\n      rw[\u2190 H1],\n      rw[f.2.add],\n    end,\n\n  smul:= \n    begin \n      intros,\n      simp,\n      have H1: f.val (g.val (c_1 \u2022 x)) = f.val(c_1 \u2022 g.val(x)),\n      rw[g.2.smul],\n      rw[H1],\n      rw[f.2.smul],\n    end \n}\n\ntheorem comp_equal_product_one {R : Type} [ring R] {a b c : nat} \n(f : (@linear_map R (finite_free_module R b)  (finite_free_module R a) _ _ _)) \n(g : (@linear_map R (finite_free_module R c)  (finite_free_module R b) _ _ _)):\n  (@linear_map_to_matrix R _ c a (\u27e8 f.1 \u2218 g.1,  comp_is_linear_map f g\u27e9))  \n  = @matrix.mul _ _ b c a (@linear_map_to_matrix R _ c b g ) (@linear_map_to_matrix R _ b a f) :=\nbegin\n  unfold linear_map_to_matrix,\n  unfold matrix.mul,\n  funext,\n  simp,\n  conv\n  begin\n    to_lhs,\n    rw [span (g.1 (e R c i))],\n  end,\n  rw [is_linear_map.sum f.2],\n  rw [apply_function_to_sum ],\n  congr,\n  funext,\n  show  f.1 ((g.1 (e R c i) K) \u2022 (e R b K)) j = _,\n  rw [is_linear_map.smul f.2],\n  refl,\nend\n\ntheorem comp_equal_product_two {R : Type} [ring R] {a b c : nat} \n(M : matrix R b a) (N : matrix R c b):\n@matrix_to_linear_map _ _ _ _ (@matrix.mul _ _ b c a N M) = \n\u27e8(@matrix_to_linear_map _ _ _ _ M).1 \u2218 (@matrix_to_linear_map _ _ _ _ N).1,  \ncomp_is_linear_map (@matrix_to_linear_map _ _ _ _ M) (@matrix_to_linear_map _ _ _ _ N)\u27e9  :=\nbegin\n  unfold matrix_to_linear_map,\n  funext,\n  apply subtype.eq,\n  simp,\n  unfold matrix_to_map,\n  unfold matrix.mul,\n  funext,\n  simp,\n  conv in (v _ * finset.sum _ _)\n  begin \n  rw [finset.mul_sum],\n  end,\n  simp only [ finset.sum_mul],\n  conv\n  begin\n    to_lhs,\n    rw [finset.sum_comm],\n  end,\n  congr,\n  funext,\n  congr,\n  funext,\n  rw [mul_assoc],\n  end\n\n-- R-module structure on Hom(R^b, R^a)  \n\ntheorem left_inv {R : Type} [ring R] {a b : nat} : left_inverse (@linear_map_to_matrix R _ a b ) (matrix_to_linear_map) := \n    begin \n    unfold function.left_inverse,\n    intros,\n    exact equiv_two x,\n    end  \ntheorem right_inv {R : Type} [ring R] {a b : nat} : right_inverse (@linear_map_to_matrix R _ a b ) (matrix_to_linear_map) := \n    begin \n     unfold function.right_inverse,\n     unfold function.left_inverse,\n     intros,\n    apply subtype.eq,\n    dsimp,\n    exact equiv_one x, \n    end\n\ninstance keji  {R : Type} [ring R] {a b : nat}:  is_add_group_hom (@linear_map_to_matrix R _ a b):=\nbegin\n exact is_add_group_hom_right_inv  (injective_of_left_inverse left_inv ) right_inv,\nend\n\ndef Hom {R : Type} [comm_ring R] {a b : nat} := {f: finite_free_module R a \u2192 finite_free_module R b // is_add_group_hom f}\n\ndef module_Hom {R: Type} [ring R] {a b : nat} (M : matrix R a b) : \n  @is_linear_map R _ _ _ _ _ (matrix_to_map M) :=\n { add:= \n begin \nexact is_add_group_hom.add _,\n end,\n smul:= smul_ _,\n}\n\n\n-- definition matrix_to_map {R : Type} [ring R] {a b : nat} (M : matrix R a b) :\n-- (finite_free_module R a) \u2192 (finite_free_module R b) := \u03bb v ,(\u03bb i,finset.sum finset.univ (\u03bb K, (v K) *M K i ) )\n  \ndef vec_to_mat {R : Type} [ring R] {n : nat} (vc : vector R n) :\nmatrix R n 1 := \u03bb I, \u03bb J, vector.nth vc I\n\n\ndef mat_mul_vec {R : Type} [ring R] {n m : nat} (M : matrix R n m) (vc : vector R m) :\nmatrix R n 1 := @matrix.mul _ _ m n 1 M (vec_to_mat vc)\n\ntheorem mat_mat_vec_assoc {R : Type} [ring R] {a b c : nat} (M : matrix R a b) \n(N : matrix R b c) (vc : vector R c) :\n@matrix.mul _ _ b a 1 M (@mat_mul_vec _ _ b c N vc) = \n@mat_mul_vec _ _ a c (@matrix.mul _ _ b a c M N) vc :=\nbegin\napply matrix.mul_assoc,\nend\n\nend map_matrix\n\nnamespace vector_space \n\nvariables {k : Type} {V : Type}\nvariable [field k]\nvariable (n : nat)\n\n--  a basis v1,v2,...,vn of a fdvs V/k is just an isomorphism k^n -> V.\n\n\nopen map_matrix\n-- helper function to get basis\ndef simp_fun (V : Type*) [vector_space k V] (n : \u2115) (lm : linear_map (finite_free_module k n) V) :\n(fin n \u2192 V) :=\n\u03bb I, lm (e k n I)\n\ndef linear_map_to_vec (V : Type*) [vector_space k V] (n : \u2115) :\n(linear_map (finite_free_module k n) V) \u2192 vector V n :=\n\u03bb lm, vector.of_fn (simp_fun V n lm)\n\ndef vec_to_map (V : Type*) [vector_space k V] (n : \u2115) (M : vector V n):\n(finite_free_module k n) \u2192 V := \n\u03bb sp, finset.sum finset.univ (\u03bb K : fin n, (sp K) \u2022 (vector.nth M K))\n\ninstance vc_to_map_add_group (V : Type*) [vector_space k V] (n : \u2115) (M : vector V n) : \nis_add_group_hom (@vec_to_map k _ _ _ n M) :=\n\u27e8 begin\nintros a b,\nunfold vec_to_map,\nshow (finset.sum finset.univ (\u03bb (K : fin n), (a K + b K) \u2022 vector.nth M K))=_,\nconv in ((a _ + b _) \u2022 _) \n  begin\n    rw [add_smul],\n  end,\nrw [\u2190 finset.sum_add_distrib],\nend\n\u27e9\n\ntheorem smul' (V : Type*) [vector_space k V] (n : \u2115) (M : vector V n) :\n\u2200 (c : k) (x : finite_free_module k n), @vec_to_map k _ _ _ n M (smul c x) = \nc \u2022 (@vec_to_map k _ _ _ n M x):= \nbegin\nintros c x,\nunfold vec_to_map,\nfunext,\nunfold smul,\nconv \n  begin\n  to_rhs,\n  rw [finset.smul_sum],\n  end,\ncongr,\nfunext,\nrw [smul_smul],\nend\n\ndef module_hom' (V : Type*) [vector_space k V] (n : \u2115) (M : vector V n) :\n  @is_linear_map _ _ _ _ _ _ (@vec_to_map k _ _ _ n M) :=\n  {\n      add:=\n        begin\n          exact is_add_group_hom.add _,\n        end,\n      smul:= @smul' _ _ _ _ _ _,\n  }\n\ndef vec_to_linear_map (V : Type*) [vector_space k V] (n : \u2115) (M : vector V n):\n(linear_map (finite_free_module k n) V) := \n\u27e8 @vec_to_map k _ _ _ n M , @module_hom' _ _ _ _ n M\u27e9 \n\nlemma ext {\u03b1 : Type*} {n : \u2115} : \u2200 (v w : vector \u03b1 n),\n  (\u2200 m : fin n, vector.nth v m = vector.nth w m) \u2192 v = w :=\n\u03bb \u27e8v, hv\u27e9 \u27e8w, hw\u27e9 h, subtype.eq (list.ext_le (by simp [hv, hw])\n(\u03bb m hm hn, h \u27e8m, hv \u25b8 hm\u27e9))\n\ndef left_inv_ (V : Type*) [vector_space k V] (n : \u2115) (M : vector V n):\n  (@linear_map_to_vec k _ _ _ n) (@vec_to_linear_map k _ _ _ n M) = M :=\nbegin\nunfold vec_to_linear_map,\nunfold linear_map_to_vec,\nunfold vec_to_map,\ndsimp,\nunfold simp_fun,\napply ext,\nassume m,\nrw vector.nth_of_fn,\nunfold_coes, dsimp,\nrw [\u2190 @finset.sum_single _ _ _ _ (\u03bb (K : fin n), e k n m K \u2022 vector.nth M K) m ],\nsimp,\nunfold e,\nsplit_ifs,\nexact one_smul,\ncontradiction,\nintros,\nsimp,\nunfold e,\nsplit_ifs,\ncontradiction,\nexact zero_smul,\nend\n\ndef right_inv_ (V : Type*) [vector_space k V] (n : \u2115) (lm : linear_map (finite_free_module k n) V) :\n@vec_to_linear_map k _ _ _ n (@linear_map_to_vec k _ _ _ n lm) = lm :=\nbegin\nunfold vec_to_linear_map,\nunfold linear_map_to_vec,\nunfold vec_to_map,\napply subtype.eq,\ndsimp,\nfunext,\nsimp,\nunfold simp_fun,\nunfold_coes,\nconv \n  begin\n    to_rhs,\n    rw[span sp],\n  end,\nrw [is_linear_map.sum lm.2],\ncongr,\nfunext,\nrw[\u2190 is_linear_map.smul lm.2],\nrefl,\nend\n\ndef n_tuples_eq_linear_maps (V : Type*) [vector_space k V] (n : \u2115) :\nequiv (vector V n) (linear_map (finite_free_module k n) V) := \n{ to_fun := vec_to_linear_map V n,\n  inv_fun := linear_map_to_vec V n,\n  left_inv := left_inv_ V n,\n  right_inv := right_inv_ V n,\n}\nend vector_space", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/finite_dimensional_vector_spaces/linear_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7417169532564504}}
{"text": "/-\nCopyright (c) 2022 Wrenna Robson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Wrenna Robson\n\n! This file was ported from Lean 3 source module information_theory.hamming\n! leanprover-community/mathlib commit cb3ceec8485239a61ed51d944cb9a95b68c6bafc\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Normed.Group.Basic\n\n/-!\n# Hamming spaces\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe Hamming metric counts the number of places two members of a (finite) Pi type\ndiffer. The Hamming norm is the same as the Hamming metric over additive groups, and\ncounts the number of places a member of a (finite) Pi type differs from zero.\n\nThis is a useful notion in various applications, but in particular it is relevant\nin coding theory, in which it is fundamental for defining the minimum distance of a\ncode.\n\n## Main definitions\n* `hamming_dist x y`: the Hamming distance between `x` and `y`, the number of entries which differ.\n* `hamming_norm x`: the Hamming norm of `x`, the number of non-zero entries.\n* `hamming \u03b2`: a type synonym for `\u03a0 i, \u03b2 i` with `dist` and `norm` provided by the above.\n* `hamming.to_hamming`, `hamming.of_hamming`: functions for casting between `hamming \u03b2` and\n`\u03a0 i, \u03b2 i`.\n* `hamming.normed_add_comm_group`: the Hamming norm forms a normed group on `hamming \u03b2`.\n-/\n\n\nsection HammingDistNorm\n\nopen Finset Function\n\nvariable {\u03b1 \u03b9 : Type _} {\u03b2 : \u03b9 \u2192 Type _} [Fintype \u03b9] [\u2200 i, DecidableEq (\u03b2 i)]\n\nvariable {\u03b3 : \u03b9 \u2192 Type _} [\u2200 i, DecidableEq (\u03b3 i)]\n\n#print hammingDist /-\n/-- The Hamming distance function to the naturals. -/\ndef hammingDist (x y : \u2200 i, \u03b2 i) : \u2115 :=\n  (univ.filter\u2093 fun i => x i \u2260 y i).card\n#align hamming_dist hammingDist\n-/\n\n/- warning: hamming_dist_self -> hammingDist_self is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x x) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x x) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))\nCase conversion may be inaccurate. Consider using '#align hamming_dist_self hammingDist_self\u2093'. -/\n/-- Corresponds to `dist_self`. -/\n@[simp]\ntheorem hammingDist_self (x : \u2200 i, \u03b2 i) : hammingDist x x = 0 :=\n  by\n  rw [hammingDist, card_eq_zero, filter_eq_empty_iff]\n  exact fun _ _ H => H rfl\n#align hamming_dist_self hammingDist_self\n\n/- warning: hamming_dist_nonneg -> hammingDist_nonneg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat Nat.hasLe (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat instLENat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_nonneg hammingDist_nonneg\u2093'. -/\n/-- Corresponds to `dist_nonneg`. -/\ntheorem hammingDist_nonneg {x y : \u2200 i, \u03b2 i} : 0 \u2264 hammingDist x y :=\n  zero_le _\n#align hamming_dist_nonneg hammingDist_nonneg\n\n/- warning: hamming_dist_comm -> hammingDist_comm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) y x)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) y x)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_comm hammingDist_comm\u2093'. -/\n/-- Corresponds to `dist_comm`. -/\ntheorem hammingDist_comm (x y : \u2200 i, \u03b2 i) : hammingDist x y = hammingDist y x := by\n  simp_rw [hammingDist, ne_comm]\n#align hamming_dist_comm hammingDist_comm\n\n/- warning: hamming_dist_triangle -> hammingDist_triangle is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) (z : forall (i : \u03b9), \u03b2 i), LE.le.{0} Nat Nat.hasLe (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x z) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) y z))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) (z : forall (i : \u03b9), \u03b2 i), LE.le.{0} Nat instLENat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x z) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) y z))\nCase conversion may be inaccurate. Consider using '#align hamming_dist_triangle hammingDist_triangle\u2093'. -/\n/-- Corresponds to `dist_triangle`. -/\ntheorem hammingDist_triangle (x y z : \u2200 i, \u03b2 i) :\n    hammingDist x z \u2264 hammingDist x y + hammingDist y z := by\n  classical\n    simp_rw [hammingDist]\n    refine' le_trans (card_mono _) (card_union_le _ _)\n    rw [\u2190 filter_or]\n    refine' monotone_filter_right _ _\n    intro i h\n    by_contra' H\n    exact h (Eq.trans H.1 H.2)\n#align hamming_dist_triangle hammingDist_triangle\n\n/- warning: hamming_dist_triangle_left -> hammingDist_triangle_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) (z : forall (i : \u03b9), \u03b2 i), LE.le.{0} Nat Nat.hasLe (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) z x) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) z y))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) (z : forall (i : \u03b9), \u03b2 i), LE.le.{0} Nat instLENat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) z x) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) z y))\nCase conversion may be inaccurate. Consider using '#align hamming_dist_triangle_left hammingDist_triangle_left\u2093'. -/\n/-- Corresponds to `dist_triangle_left`. -/\ntheorem hammingDist_triangle_left (x y z : \u2200 i, \u03b2 i) :\n    hammingDist x y \u2264 hammingDist z x + hammingDist z y :=\n  by\n  rw [hammingDist_comm z]\n  exact hammingDist_triangle _ _ _\n#align hamming_dist_triangle_left hammingDist_triangle_left\n\n/- warning: hamming_dist_triangle_right -> hammingDist_triangle_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) (z : forall (i : \u03b9), \u03b2 i), LE.le.{0} Nat Nat.hasLe (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x z) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) y z))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) (z : forall (i : \u03b9), \u03b2 i), LE.le.{0} Nat instLENat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x z) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) y z))\nCase conversion may be inaccurate. Consider using '#align hamming_dist_triangle_right hammingDist_triangle_right\u2093'. -/\n/-- Corresponds to `dist_triangle_right`. -/\ntheorem hammingDist_triangle_right (x y z : \u2200 i, \u03b2 i) :\n    hammingDist x y \u2264 hammingDist x z + hammingDist y z :=\n  by\n  rw [hammingDist_comm y]\n  exact hammingDist_triangle _ _ _\n#align hamming_dist_triangle_right hammingDist_triangle_right\n\n/- warning: swap_hamming_dist -> swap_hammingDist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)], Eq.{max (max (succ u1) (succ u2)) 1} ((forall (i : \u03b9), \u03b2 i) -> (forall (i : \u03b9), \u03b2 i) -> Nat) (Function.swap.{max (succ u1) (succ u2), max (succ u1) (succ u2), 1} (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (fun (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) => Nat) (hammingDist.{u1, u2} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b))) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)], Eq.{max (succ u2) (succ u1)} ((forall (i : \u03b9), \u03b2 i) -> (forall (i : \u03b9), \u03b2 i) -> Nat) (Function.swap.{max (succ u2) (succ u1), max (succ u2) (succ u1), 1} (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (fun (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i) => Nat) (hammingDist.{u2, u1} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b))) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b))\nCase conversion may be inaccurate. Consider using '#align swap_hamming_dist swap_hammingDist\u2093'. -/\n/-- Corresponds to `swap_dist`. -/\ntheorem swap_hammingDist : swap (@hammingDist _ \u03b2 _ _) = hammingDist :=\n  by\n  funext x y\n  exact hammingDist_comm _ _\n#align swap_hamming_dist swap_hammingDist\n\n/- warning: eq_of_hamming_dist_eq_zero -> eq_of_hammingDist_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, (Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, (Eq.{1} Nat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x y)\nCase conversion may be inaccurate. Consider using '#align eq_of_hamming_dist_eq_zero eq_of_hammingDist_eq_zero\u2093'. -/\n/-- Corresponds to `eq_of_dist_eq_zero`. -/\ntheorem eq_of_hammingDist_eq_zero {x y : \u2200 i, \u03b2 i} : hammingDist x y = 0 \u2192 x = y := by\n  simp_rw [hammingDist, card_eq_zero, filter_eq_empty_iff, Classical.not_not, funext_iff, mem_univ,\n    forall_true_left, imp_self]\n#align eq_of_hamming_dist_eq_zero eq_of_hammingDist_eq_zero\n\n/- warning: hamming_dist_eq_zero -> hammingDist_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{1} Nat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (Eq.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_eq_zero hammingDist_eq_zero\u2093'. -/\n/-- Corresponds to `dist_eq_zero`. -/\n@[simp]\ntheorem hammingDist_eq_zero {x y : \u2200 i, \u03b2 i} : hammingDist x y = 0 \u2194 x = y :=\n  \u27e8eq_of_hammingDist_eq_zero, fun H => by\n    rw [H]\n    exact hammingDist_self _\u27e9\n#align hamming_dist_eq_zero hammingDist_eq_zero\n\n/- warning: hamming_zero_eq_dist -> hamming_zero_eq_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{1} Nat (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)) (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{1} Nat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)) (Eq.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_zero_eq_dist hamming_zero_eq_dist\u2093'. -/\n/-- Corresponds to `zero_eq_dist`. -/\n@[simp]\ntheorem hamming_zero_eq_dist {x y : \u2200 i, \u03b2 i} : 0 = hammingDist x y \u2194 x = y := by\n  rw [eq_comm, hammingDist_eq_zero]\n#align hamming_zero_eq_dist hamming_zero_eq_dist\n\n/- warning: hamming_dist_ne_zero -> hammingDist_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Ne.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (Ne.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Ne.{1} Nat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (Ne.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_ne_zero hammingDist_ne_zero\u2093'. -/\n/-- Corresponds to `dist_ne_zero`. -/\ntheorem hammingDist_ne_zero {x y : \u2200 i, \u03b2 i} : hammingDist x y \u2260 0 \u2194 x \u2260 y :=\n  hammingDist_eq_zero.Not\n#align hamming_dist_ne_zero hammingDist_ne_zero\n\n/- warning: hamming_dist_pos -> hammingDist_pos is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)) (Ne.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)) (Ne.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_pos hammingDist_pos\u2093'. -/\n/-- Corresponds to `dist_pos`. -/\n@[simp]\ntheorem hammingDist_pos {x y : \u2200 i, \u03b2 i} : 0 < hammingDist x y \u2194 x \u2260 y := by\n  rw [\u2190 hammingDist_ne_zero, iff_not_comm, not_lt, le_zero_iff]\n#align hamming_dist_pos hammingDist_pos\n\n/- warning: hamming_dist_lt_one -> hammingDist_lt_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat Nat.hasLt (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat instLTNat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Eq.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_lt_one hammingDist_lt_one\u2093'. -/\n@[simp]\ntheorem hammingDist_lt_one {x y : \u2200 i, \u03b2 i} : hammingDist x y < 1 \u2194 x = y := by\n  rw [Nat.lt_one_iff, hammingDist_eq_zero]\n#align hamming_dist_lt_one hammingDist_lt_one\n\n/- warning: hamming_dist_le_card_fintype -> hammingDist_le_card_fintype is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat Nat.hasLe (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (Fintype.card.{u1} \u03b9 _inst_1)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat instLENat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (Fintype.card.{u2} \u03b9 _inst_1)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_le_card_fintype hammingDist_le_card_fintype\u2093'. -/\ntheorem hammingDist_le_card_fintype {x y : \u2200 i, \u03b2 i} : hammingDist x y \u2264 Fintype.card \u03b9 :=\n  card_le_univ _\n#align hamming_dist_le_card_fintype hammingDist_le_card_fintype\n\n/- warning: hamming_dist_comp_le_hamming_dist -> hammingDist_comp_le_hammingDist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {\u03b3 : \u03b9 -> Type.{u3}} [_inst_3 : forall (i : \u03b9), DecidableEq.{succ u3} (\u03b3 i)] (f : forall (i : \u03b9), (\u03b3 i) -> (\u03b2 i)) {x : forall (i : \u03b9), \u03b3 i} {y : forall (i : \u03b9), \u03b3 i}, LE.le.{0} Nat Nat.hasLe (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => f i (x i)) (fun (i : \u03b9) => f i (y i))) (hammingDist.{u1, u3} \u03b9 (fun (i : \u03b9) => \u03b3 i) _inst_1 (fun (i : \u03b9) (a : \u03b3 i) (b : \u03b3 i) => _inst_3 i a b) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u3} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {\u03b3 : \u03b9 -> Type.{u1}} [_inst_3 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b3 i)] (f : forall (i : \u03b9), (\u03b3 i) -> (\u03b2 i)) {x : forall (i : \u03b9), \u03b3 i} {y : forall (i : \u03b9), \u03b3 i}, LE.le.{0} Nat instLENat (hammingDist.{u3, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => f i (x i)) (fun (i : \u03b9) => f i (y i))) (hammingDist.{u3, u1} \u03b9 (fun (i : \u03b9) => \u03b3 i) _inst_1 (fun (i : \u03b9) (a : \u03b3 i) (b : \u03b3 i) => _inst_3 i a b) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_comp_le_hamming_dist hammingDist_comp_le_hammingDist\u2093'. -/\ntheorem hammingDist_comp_le_hammingDist (f : \u2200 i, \u03b3 i \u2192 \u03b2 i) {x y : \u2200 i, \u03b3 i} :\n    (hammingDist (fun i => f i (x i)) fun i => f i (y i)) \u2264 hammingDist x y :=\n  card_mono (monotone_filter_right _ fun i H1 H2 => H1 <| congr_arg (f i) H2)\n#align hamming_dist_comp_le_hamming_dist hammingDist_comp_le_hammingDist\n\n#print hammingDist_comp /-\ntheorem hammingDist_comp (f : \u2200 i, \u03b3 i \u2192 \u03b2 i) {x y : \u2200 i, \u03b3 i} (hf : \u2200 i, Injective (f i)) :\n    (hammingDist (fun i => f i (x i)) fun i => f i (y i)) = hammingDist x y :=\n  by\n  refine' le_antisymm (hammingDist_comp_le_hammingDist _) _\n  exact card_mono (monotone_filter_right _ fun i H1 H2 => H1 <| hf i H2)\n#align hamming_dist_comp hammingDist_comp\n-/\n\n/- warning: hamming_dist_smul_le_hamming_dist -> hammingDist_smul_le_hammingDist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u3} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), SMul.{u1, u3} \u03b1 (\u03b2 i)] {k : \u03b1} {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat Nat.hasLe (hammingDist.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)) k x) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)) k y)) (hammingDist.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), SMul.{u3, u2} \u03b1 (\u03b2 i)] {k : \u03b1} {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat instLENat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))) k x) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))) k y)) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_smul_le_hamming_dist hammingDist_smul_le_hammingDist\u2093'. -/\ntheorem hammingDist_smul_le_hammingDist [\u2200 i, SMul \u03b1 (\u03b2 i)] {k : \u03b1} {x y : \u2200 i, \u03b2 i} :\n    hammingDist (k \u2022 x) (k \u2022 y) \u2264 hammingDist x y :=\n  hammingDist_comp_le_hammingDist fun i => (\u00b7 \u2022 \u00b7) k\n#align hamming_dist_smul_le_hamming_dist hammingDist_smul_le_hammingDist\n\n/- warning: hamming_dist_smul -> hammingDist_smul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u3} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), SMul.{u1, u3} \u03b1 (\u03b2 i)] {k : \u03b1} {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, (forall (i : \u03b9), IsSMulRegular.{u1, u3} \u03b1 (\u03b2 i) (_inst_4 i) k) -> (Eq.{1} Nat (hammingDist.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)) k x) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)) k y)) (hammingDist.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), SMul.{u3, u2} \u03b1 (\u03b2 i)] {k : \u03b1} {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, (forall (i : \u03b9), IsSMulRegular.{u3, u2} \u03b1 (\u03b2 i) (_inst_4 i) k) -> (Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))) k x) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))) k y)) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y))\nCase conversion may be inaccurate. Consider using '#align hamming_dist_smul hammingDist_smul\u2093'. -/\n/-- Corresponds to `dist_smul` with the discrete norm on `\u03b1`. -/\ntheorem hammingDist_smul [\u2200 i, SMul \u03b1 (\u03b2 i)] {k : \u03b1} {x y : \u2200 i, \u03b2 i}\n    (hk : \u2200 i, IsSMulRegular (\u03b2 i) k) : hammingDist (k \u2022 x) (k \u2022 y) = hammingDist x y :=\n  hammingDist_comp (fun i => (\u00b7 \u2022 \u00b7) k) hk\n#align hamming_dist_smul hammingDist_smul\n\nsection Zero\n\nvariable [\u2200 i, Zero (\u03b2 i)] [\u2200 i, Zero (\u03b3 i)]\n\n#print hammingNorm /-\n/-- The Hamming weight function to the naturals. -/\ndef hammingNorm (x : \u2200 i, \u03b2 i) : \u2115 :=\n  (univ.filter\u2093 fun i => x i \u2260 0).card\n#align hamming_norm hammingNorm\n-/\n\n/- warning: hamming_dist_zero_right -> hammingDist_zero_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x (OfNat.ofNat.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (OfNat.mk.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (Zero.zero.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)))))) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x (OfNat.ofNat.{max u2 u1} (forall (i : \u03b9), \u03b2 i) 0 (Zero.toOfNat0.{max u2 u1} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))))) (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)\nCase conversion may be inaccurate. Consider using '#align hamming_dist_zero_right hammingDist_zero_right\u2093'. -/\n/-- Corresponds to `dist_zero_right`. -/\n@[simp]\ntheorem hammingDist_zero_right (x : \u2200 i, \u03b2 i) : hammingDist x 0 = hammingNorm x :=\n  rfl\n#align hamming_dist_zero_right hammingDist_zero_right\n\n/- warning: hamming_dist_zero_left -> hammingDist_zero_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)], Eq.{max (max (succ u1) (succ u2)) 1} ((forall (i : \u03b9), \u03b2 i) -> Nat) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (OfNat.ofNat.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (OfNat.mk.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (Zero.zero.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)))))) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)], Eq.{max (succ u2) (succ u1)} ((forall (i : \u03b9), \u03b2 i) -> Nat) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (OfNat.ofNat.{max u2 u1} (forall (i : \u03b9), \u03b2 i) 0 (Zero.toOfNat0.{max u2 u1} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))))) (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i))\nCase conversion may be inaccurate. Consider using '#align hamming_dist_zero_left hammingDist_zero_left\u2093'. -/\n/-- Corresponds to `dist_zero_left`. -/\n@[simp]\ntheorem hammingDist_zero_left : hammingDist (0 : \u2200 i, \u03b2 i) = hammingNorm :=\n  funext fun x => by rw [hammingDist_comm, hammingDist_zero_right]\n#align hamming_dist_zero_left hammingDist_zero_left\n\n/- warning: hamming_norm_nonneg -> hammingNorm_nonneg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat Nat.hasLe (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat instLENat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)\nCase conversion may be inaccurate. Consider using '#align hamming_norm_nonneg hammingNorm_nonneg\u2093'. -/\n/-- Corresponds to `norm_nonneg`. -/\n@[simp]\ntheorem hammingNorm_nonneg {x : \u2200 i, \u03b2 i} : 0 \u2264 hammingNorm x :=\n  zero_le _\n#align hamming_norm_nonneg hammingNorm_nonneg\n\n/- warning: hamming_norm_zero -> hammingNorm_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)], Eq.{1} Nat (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (OfNat.ofNat.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (OfNat.mk.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (Zero.zero.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)))))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)], Eq.{1} Nat (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (OfNat.ofNat.{max u2 u1} (forall (i : \u03b9), \u03b2 i) 0 (Zero.toOfNat0.{max u2 u1} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))\nCase conversion may be inaccurate. Consider using '#align hamming_norm_zero hammingNorm_zero\u2093'. -/\n/-- Corresponds to `norm_zero`. -/\n@[simp]\ntheorem hammingNorm_zero : hammingNorm (0 : \u2200 i, \u03b2 i) = 0 :=\n  hammingDist_self _\n#align hamming_norm_zero hammingNorm_zero\n\n/- warning: hamming_norm_eq_zero -> hammingNorm_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{1} Nat (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (OfNat.mk.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (Zero.zero.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{1} Nat (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (Eq.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u2 u1} (forall (i : \u03b9), \u03b2 i) 0 (Zero.toOfNat0.{max u2 u1} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)))))\nCase conversion may be inaccurate. Consider using '#align hamming_norm_eq_zero hammingNorm_eq_zero\u2093'. -/\n/-- Corresponds to `norm_eq_zero`. -/\n@[simp]\ntheorem hammingNorm_eq_zero {x : \u2200 i, \u03b2 i} : hammingNorm x = 0 \u2194 x = 0 :=\n  hammingDist_eq_zero\n#align hamming_norm_eq_zero hammingNorm_eq_zero\n\n/- warning: hamming_norm_ne_zero_iff -> hammingNorm_ne_zero_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (Ne.{1} Nat (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (Ne.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (OfNat.mk.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (Zero.zero.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (Ne.{1} Nat (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (Ne.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u2 u1} (forall (i : \u03b9), \u03b2 i) 0 (Zero.toOfNat0.{max u2 u1} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)))))\nCase conversion may be inaccurate. Consider using '#align hamming_norm_ne_zero_iff hammingNorm_ne_zero_iff\u2093'. -/\n/-- Corresponds to `norm_ne_zero_iff`. -/\ntheorem hammingNorm_ne_zero_iff {x : \u2200 i, \u03b2 i} : hammingNorm x \u2260 0 \u2194 x \u2260 0 :=\n  hammingNorm_eq_zero.Not\n#align hamming_norm_ne_zero_iff hammingNorm_ne_zero_iff\n\n/- warning: hamming_norm_pos_iff -> hammingNorm_pos_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)) (Ne.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (OfNat.mk.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (Zero.zero.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)) (Ne.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u2 u1} (forall (i : \u03b9), \u03b2 i) 0 (Zero.toOfNat0.{max u2 u1} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)))))\nCase conversion may be inaccurate. Consider using '#align hamming_norm_pos_iff hammingNorm_pos_iff\u2093'. -/\n/-- Corresponds to `norm_pos_iff`. -/\n@[simp]\ntheorem hammingNorm_pos_iff {x : \u2200 i, \u03b2 i} : 0 < hammingNorm x \u2194 x \u2260 0 :=\n  hammingDist_pos\n#align hamming_norm_pos_iff hammingNorm_pos_iff\n\n/- warning: hamming_norm_lt_one -> hammingNorm_lt_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat Nat.hasLt (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (OfNat.mk.{max u1 u2} (forall (i : \u03b9), \u03b2 i) 0 (Zero.zero.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, Iff (LT.lt.{0} Nat instLTNat (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Eq.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x (OfNat.ofNat.{max u2 u1} (forall (i : \u03b9), \u03b2 i) 0 (Zero.toOfNat0.{max u2 u1} (forall (i : \u03b9), \u03b2 i) (Pi.instZero.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_4 i)))))\nCase conversion may be inaccurate. Consider using '#align hamming_norm_lt_one hammingNorm_lt_one\u2093'. -/\n@[simp]\ntheorem hammingNorm_lt_one {x : \u2200 i, \u03b2 i} : hammingNorm x < 1 \u2194 x = 0 :=\n  hammingDist_lt_one\n#align hamming_norm_lt_one hammingNorm_lt_one\n\n/- warning: hamming_norm_le_card_fintype -> hammingNorm_le_card_fintype is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat Nat.hasLe (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (Fintype.card.{u1} \u03b9 _inst_1)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u1} (\u03b2 i)] {x : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat instLENat (hammingNorm.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x) (Fintype.card.{u2} \u03b9 _inst_1)\nCase conversion may be inaccurate. Consider using '#align hamming_norm_le_card_fintype hammingNorm_le_card_fintype\u2093'. -/\ntheorem hammingNorm_le_card_fintype {x : \u2200 i, \u03b2 i} : hammingNorm x \u2264 Fintype.card \u03b9 :=\n  hammingDist_le_card_fintype\n#align hamming_norm_le_card_fintype hammingNorm_le_card_fintype\n\n/- warning: hamming_norm_comp_le_hamming_norm -> hammingNorm_comp_le_hammingNorm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] {\u03b3 : \u03b9 -> Type.{u3}} [_inst_3 : forall (i : \u03b9), DecidableEq.{succ u3} (\u03b3 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] [_inst_5 : forall (i : \u03b9), Zero.{u3} (\u03b3 i)] (f : forall (i : \u03b9), (\u03b3 i) -> (\u03b2 i)) {x : forall (i : \u03b9), \u03b3 i}, (forall (i : \u03b9), Eq.{succ u2} (\u03b2 i) (f i (OfNat.ofNat.{u3} (\u03b3 i) 0 (OfNat.mk.{u3} (\u03b3 i) 0 (Zero.zero.{u3} (\u03b3 i) (_inst_5 i))))) (OfNat.ofNat.{u2} (\u03b2 i) 0 (OfNat.mk.{u2} (\u03b2 i) 0 (Zero.zero.{u2} (\u03b2 i) (_inst_4 i))))) -> (LE.le.{0} Nat Nat.hasLe (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (fun (i : \u03b9) => f i (x i))) (hammingNorm.{u1, u3} \u03b9 (fun (i : \u03b9) => \u03b3 i) _inst_1 (fun (i : \u03b9) (a : \u03b3 i) (b : \u03b3 i) => _inst_3 i a b) (fun (i : \u03b9) => _inst_5 i) x))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u3} (\u03b2 i)] {\u03b3 : \u03b9 -> Type.{u2}} [_inst_3 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b3 i)] [_inst_4 : forall (i : \u03b9), Zero.{u3} (\u03b2 i)] [_inst_5 : forall (i : \u03b9), Zero.{u2} (\u03b3 i)] (f : forall (i : \u03b9), (\u03b3 i) -> (\u03b2 i)) {x : forall (i : \u03b9), \u03b3 i}, (forall (i : \u03b9), Eq.{succ u3} (\u03b2 i) (f i (OfNat.ofNat.{u2} (\u03b3 i) 0 (Zero.toOfNat0.{u2} (\u03b3 i) (_inst_5 i)))) (OfNat.ofNat.{u3} (\u03b2 i) 0 (Zero.toOfNat0.{u3} (\u03b2 i) (_inst_4 i)))) -> (LE.le.{0} Nat instLENat (hammingNorm.{u1, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (fun (i : \u03b9) => f i (x i))) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b3 i) _inst_1 (fun (i : \u03b9) (a : \u03b3 i) (b : \u03b3 i) => _inst_3 i a b) (fun (i : \u03b9) => _inst_5 i) x))\nCase conversion may be inaccurate. Consider using '#align hamming_norm_comp_le_hamming_norm hammingNorm_comp_le_hammingNorm\u2093'. -/\ntheorem hammingNorm_comp_le_hammingNorm (f : \u2200 i, \u03b3 i \u2192 \u03b2 i) {x : \u2200 i, \u03b3 i} (hf : \u2200 i, f i 0 = 0) :\n    (hammingNorm fun i => f i (x i)) \u2264 hammingNorm x :=\n  by\n  convert hammingDist_comp_le_hammingDist f\n  simp_rw [hf]\n  rfl\n#align hamming_norm_comp_le_hamming_norm hammingNorm_comp_le_hammingNorm\n\n#print hammingNorm_comp /-\ntheorem hammingNorm_comp (f : \u2200 i, \u03b3 i \u2192 \u03b2 i) {x : \u2200 i, \u03b3 i} (hf\u2081 : \u2200 i, Injective (f i))\n    (hf\u2082 : \u2200 i, f i 0 = 0) : (hammingNorm fun i => f i (x i)) = hammingNorm x :=\n  by\n  convert hammingDist_comp f hf\u2081\n  simp_rw [hf\u2082]\n  rfl\n#align hamming_norm_comp hammingNorm_comp\n-/\n\n/- warning: hamming_norm_smul_le_hamming_norm -> hammingNorm_smul_le_hammingNorm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u3} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u3} (\u03b2 i)] [_inst_6 : Zero.{u1} \u03b1] [_inst_7 : forall (i : \u03b9), SMulWithZero.{u1, u3} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i)] {k : \u03b1} {x : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat Nat.hasLe (hammingNorm.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => SMulZeroClass.toHasSmul.{u1, u3} \u03b1 (\u03b2 i) (_inst_4 i) (SMulWithZero.toSmulZeroClass.{u1, u3} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i) (_inst_7 i)))) k x)) (hammingNorm.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] [_inst_6 : Zero.{u3} \u03b1] [_inst_7 : forall (i : \u03b9), SMulWithZero.{u3, u2} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i)] {k : \u03b1} {x : forall (i : \u03b9), \u03b2 i}, LE.le.{0} Nat instLENat (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => SMulZeroClass.toSMul.{u3, u2} \u03b1 (\u03b2 i) (_inst_4 i) (SMulWithZero.toSMulZeroClass.{u3, u2} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i) (_inst_7 i))))) k x)) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x)\nCase conversion may be inaccurate. Consider using '#align hamming_norm_smul_le_hamming_norm hammingNorm_smul_le_hammingNorm\u2093'. -/\ntheorem hammingNorm_smul_le_hammingNorm [Zero \u03b1] [\u2200 i, SMulWithZero \u03b1 (\u03b2 i)] {k : \u03b1}\n    {x : \u2200 i, \u03b2 i} : hammingNorm (k \u2022 x) \u2264 hammingNorm x :=\n  hammingNorm_comp_le_hammingNorm (fun i (c : \u03b2 i) => k \u2022 c) fun i => by simp_rw [smul_zero]\n#align hamming_norm_smul_le_hamming_norm hammingNorm_smul_le_hammingNorm\n\n/- warning: hamming_norm_smul -> hammingNorm_smul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u3} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u3} (\u03b2 i)] [_inst_6 : Zero.{u1} \u03b1] [_inst_7 : forall (i : \u03b9), SMulWithZero.{u1, u3} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i)] {k : \u03b1}, (forall (i : \u03b9), IsSMulRegular.{u1, u3} \u03b1 (\u03b2 i) (SMulZeroClass.toHasSmul.{u1, u3} \u03b1 (\u03b2 i) (_inst_4 i) (SMulWithZero.toSmulZeroClass.{u1, u3} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i) (_inst_7 i))) k) -> (forall (x : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingNorm.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => SMulZeroClass.toHasSmul.{u1, u3} \u03b1 (\u03b2 i) (_inst_4 i) (SMulWithZero.toSmulZeroClass.{u1, u3} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i) (_inst_7 i)))) k x)) (hammingNorm.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] [_inst_6 : Zero.{u3} \u03b1] [_inst_7 : forall (i : \u03b9), SMulWithZero.{u3, u2} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i)] {k : \u03b1}, (forall (i : \u03b9), IsSMulRegular.{u3, u2} \u03b1 (\u03b2 i) (SMulZeroClass.toSMul.{u3, u2} \u03b1 (\u03b2 i) (_inst_4 i) (SMulWithZero.toSMulZeroClass.{u3, u2} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i) (_inst_7 i))) k) -> (forall (x : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => SMulZeroClass.toSMul.{u3, u2} \u03b1 (\u03b2 i) (_inst_4 i) (SMulWithZero.toSMulZeroClass.{u3, u2} \u03b1 (\u03b2 i) _inst_6 (_inst_4 i) (_inst_7 i))))) k x)) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_4 i) x))\nCase conversion may be inaccurate. Consider using '#align hamming_norm_smul hammingNorm_smul\u2093'. -/\ntheorem hammingNorm_smul [Zero \u03b1] [\u2200 i, SMulWithZero \u03b1 (\u03b2 i)] {k : \u03b1}\n    (hk : \u2200 i, IsSMulRegular (\u03b2 i) k) (x : \u2200 i, \u03b2 i) : hammingNorm (k \u2022 x) = hammingNorm x :=\n  hammingNorm_comp (fun i (c : \u03b2 i) => k \u2022 c) hk fun i => by simp_rw [smul_zero]\n#align hamming_norm_smul hammingNorm_smul\n\nend Zero\n\n/- warning: hamming_dist_eq_hamming_norm -> hammingDist_eq_hammingNorm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), AddGroup.{u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => AddZeroClass.toHasZero.{u2} (\u03b2 i) (AddMonoid.toAddZeroClass.{u2} (\u03b2 i) (SubNegMonoid.toAddMonoid.{u2} (\u03b2 i) (AddGroup.toSubNegMonoid.{u2} (\u03b2 i) (_inst_4 i))))) (HSub.hSub.{max u1 u2, max u1 u2, max u1 u2} (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSub.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instSub.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => SubNegMonoid.toHasSub.{u2} (\u03b2 i) (AddGroup.toSubNegMonoid.{u2} (\u03b2 i) (_inst_4 i))))) x y))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_4 : forall (i : \u03b9), AddGroup.{u2} (\u03b2 i)] (x : forall (i : \u03b9), \u03b2 i) (y : forall (i : \u03b9), \u03b2 i), Eq.{1} Nat (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) x y) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => NegZeroClass.toZero.{u2} (\u03b2 i) (SubNegZeroMonoid.toNegZeroClass.{u2} (\u03b2 i) (SubtractionMonoid.toSubNegZeroMonoid.{u2} (\u03b2 i) (AddGroup.toSubtractionMonoid.{u2} (\u03b2 i) (_inst_4 i))))) (HSub.hSub.{max u1 u2, max u1 u2, max u1 u2} (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSub.{max u1 u2} (forall (i : \u03b9), \u03b2 i) (Pi.instSub.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => SubNegMonoid.toSub.{u2} (\u03b2 i) (AddGroup.toSubNegMonoid.{u2} (\u03b2 i) (_inst_4 i))))) x y))\nCase conversion may be inaccurate. Consider using '#align hamming_dist_eq_hamming_norm hammingDist_eq_hammingNorm\u2093'. -/\n/-- Corresponds to `dist_eq_norm`. -/\ntheorem hammingDist_eq_hammingNorm [\u2200 i, AddGroup (\u03b2 i)] (x y : \u2200 i, \u03b2 i) :\n    hammingDist x y = hammingNorm (x - y) := by\n  simp_rw [hammingNorm, hammingDist, Pi.sub_apply, sub_ne_zero]\n#align hamming_dist_eq_hamming_norm hammingDist_eq_hammingNorm\n\nend HammingDistNorm\n\n/-! ### The `hamming` type synonym -/\n\n\n#print Hamming /-\n/-- Type synonym for a Pi type which inherits the usual algebraic instances, but is equipped with\nthe Hamming metric and norm, instead of `pi.normed_add_comm_group` which uses the sup norm. -/\ndef Hamming {\u03b9 : Type _} (\u03b2 : \u03b9 \u2192 Type _) : Type _ :=\n  \u2200 i, \u03b2 i\n#align hamming Hamming\n-/\n\nnamespace Hamming\n\nvariable {\u03b1 \u03b9 : Type _} {\u03b2 : \u03b9 \u2192 Type _}\n\n/-! Instances inherited from normal Pi types. -/\n\n\ninstance [\u2200 i, Inhabited (\u03b2 i)] : Inhabited (Hamming \u03b2) :=\n  \u27e8fun i => default\u27e9\n\ninstance [DecidableEq \u03b9] [Fintype \u03b9] [\u2200 i, Fintype (\u03b2 i)] : Fintype (Hamming \u03b2) :=\n  Pi.fintype\n\ninstance [Inhabited \u03b9] [\u2200 i, Nonempty (\u03b2 i)] [Nontrivial (\u03b2 default)] : Nontrivial (Hamming \u03b2) :=\n  Pi.nontrivial\n\ninstance [Fintype \u03b9] [\u2200 i, DecidableEq (\u03b2 i)] : DecidableEq (Hamming \u03b2) :=\n  Fintype.decidablePiFintype\n\ninstance [\u2200 i, Zero (\u03b2 i)] : Zero (Hamming \u03b2) :=\n  Pi.instZero\n\ninstance [\u2200 i, Neg (\u03b2 i)] : Neg (Hamming \u03b2) :=\n  Pi.instNeg\n\ninstance [\u2200 i, Add (\u03b2 i)] : Add (Hamming \u03b2) :=\n  Pi.instAdd\n\ninstance [\u2200 i, Sub (\u03b2 i)] : Sub (Hamming \u03b2) :=\n  Pi.instSub\n\ninstance [\u2200 i, SMul \u03b1 (\u03b2 i)] : SMul \u03b1 (Hamming \u03b2) :=\n  Pi.instSMul\n\ninstance [Zero \u03b1] [\u2200 i, Zero (\u03b2 i)] [\u2200 i, SMulWithZero \u03b1 (\u03b2 i)] : SMulWithZero \u03b1 (Hamming \u03b2) :=\n  Pi.smulWithZero _\n\ninstance [\u2200 i, AddMonoid (\u03b2 i)] : AddMonoid (Hamming \u03b2) :=\n  Pi.addMonoid\n\ninstance [\u2200 i, AddCommMonoid (\u03b2 i)] : AddCommMonoid (Hamming \u03b2) :=\n  Pi.addCommMonoid\n\ninstance [\u2200 i, AddCommGroup (\u03b2 i)] : AddCommGroup (Hamming \u03b2) :=\n  Pi.addCommGroup\n\ninstance (\u03b1) [Semiring \u03b1] (\u03b2 : \u03b9 \u2192 Type _) [\u2200 i, AddCommMonoid (\u03b2 i)] [\u2200 i, Module \u03b1 (\u03b2 i)] :\n    Module \u03b1 (Hamming \u03b2) :=\n  Pi.module _ _ _\n\n/-! API to/from the type synonym. -/\n\n\n#print Hamming.toHamming /-\n/-- `to_hamming` is the identity function to the `hamming` of a type.  -/\n@[match_pattern]\ndef toHamming : (\u2200 i, \u03b2 i) \u2243 Hamming \u03b2 :=\n  Equiv.refl _\n#align hamming.to_hamming Hamming.toHamming\n-/\n\n#print Hamming.ofHamming /-\n/-- `of_hamming` is the identity function from the `hamming` of a type.  -/\n@[match_pattern]\ndef ofHamming : Hamming \u03b2 \u2243 \u2200 i, \u03b2 i :=\n  Equiv.refl _\n#align hamming.of_hamming Hamming.ofHamming\n-/\n\n/- warning: hamming.to_hamming_symm_eq -> Hamming.toHamming_symm_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}}, Eq.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2))} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Equiv.symm.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.toHamming.{u1, u2} \u03b9 \u03b2)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}}, Eq.{max (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Equiv.symm.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 \u03b2) (Hamming.toHamming.{u2, u1} \u03b9 \u03b2)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2)\nCase conversion may be inaccurate. Consider using '#align hamming.to_hamming_symm_eq Hamming.toHamming_symm_eq\u2093'. -/\n@[simp]\ntheorem toHamming_symm_eq : (@toHamming _ \u03b2).symm = ofHamming :=\n  rfl\n#align hamming.to_hamming_symm_eq Hamming.toHamming_symm_eq\n\n/- warning: hamming.of_hamming_symm_eq -> Hamming.ofHamming_symm_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}}, Eq.{max 1 (max (max (succ u1) (succ u2)) (succ (max u1 u2))) (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 \u03b2)) (Equiv.symm.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2)) (Hamming.toHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}}, Eq.{max (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 \u03b2)) (Equiv.symm.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2)) (Hamming.toHamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))\nCase conversion may be inaccurate. Consider using '#align hamming.of_hamming_symm_eq Hamming.ofHamming_symm_eq\u2093'. -/\n@[simp]\ntheorem ofHamming_symm_eq : (@ofHamming _ \u03b2).symm = toHamming :=\n  rfl\n#align hamming.of_hamming_symm_eq Hamming.ofHamming_symm_eq\n\n/- warning: hamming.to_hamming_of_hamming -> Hamming.toHamming_ofHamming is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} (x : Hamming.{u1, u2} \u03b9 \u03b2), Eq.{succ (max u1 u2)} (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ (max u1 u2))) (succ (max u1 u2)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ (max u1 u2))} (Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (fun (_x : Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) => (forall (i : \u03b9), \u03b2 i) -> (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x)) x\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} (x : Hamming.{u2, u1} \u03b9 \u03b2), Eq.{max (succ u2) (succ u1)} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (a : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) a) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) x)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (forall (i : \u03b9), \u03b2 i) (fun (_x : forall (i : \u03b9), \u03b2 i) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (_x : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) x)) x\nCase conversion may be inaccurate. Consider using '#align hamming.to_hamming_of_hamming Hamming.toHamming_ofHamming\u2093'. -/\n@[simp]\ntheorem toHamming_ofHamming (x : Hamming \u03b2) : toHamming (ofHamming x) = x :=\n  rfl\n#align hamming.to_hamming_of_hamming Hamming.toHamming_ofHamming\n\n/- warning: hamming.of_hamming_to_hamming -> Hamming.ofHamming_toHamming is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} (x : forall (i : \u03b9), \u03b2 i), Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ (max u1 u2))) (succ (max u1 u2)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ (max u1 u2))} (Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (fun (_x : Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) => (forall (i : \u03b9), \u03b2 i) -> (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x)) x\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} (x : forall (i : \u03b9), \u03b2 i), Eq.{max (succ u2) (succ u1)} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) => forall (i : \u03b9), \u03b2 i) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (forall (i : \u03b9), \u03b2 i) (fun (a : forall (i : \u03b9), \u03b2 i) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) a) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (fun (_x : Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (forall (i : \u03b9), \u03b2 i) (fun (_x : forall (i : \u03b9), \u03b2 i) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x)) x\nCase conversion may be inaccurate. Consider using '#align hamming.of_hamming_to_hamming Hamming.ofHamming_toHamming\u2093'. -/\n@[simp]\ntheorem ofHamming_toHamming (x : \u2200 i, \u03b2 i) : ofHamming (toHamming x) = x :=\n  rfl\n#align hamming.of_hamming_to_hamming Hamming.ofHamming_toHamming\n\n/- warning: hamming.to_hamming_inj -> Hamming.toHamming_inj is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{succ (max u1 u2)} (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ (max u1 u2))) (succ (max u1 u2)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ (max u1 u2))} (Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (fun (_x : Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) => (forall (i : \u03b9), \u03b2 i) -> (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x) (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ (max u1 u2))) (succ (max u1 u2)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ (max u1 u2))} (Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (fun (_x : Equiv.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) => (forall (i : \u03b9), \u03b2 i) -> (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ (max u1 u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) y)) (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} {x : forall (i : \u03b9), \u03b2 i} {y : forall (i : \u03b9), \u03b2 i}, Iff (Eq.{max (succ u2) (succ u1)} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (forall (i : \u03b9), \u03b2 i) (fun (_x : forall (i : \u03b9), \u03b2 i) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (forall (i : \u03b9), \u03b2 i) (fun (_x : forall (i : \u03b9), \u03b2 i) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i)) y)) (Eq.{max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) x y)\nCase conversion may be inaccurate. Consider using '#align hamming.to_hamming_inj Hamming.toHamming_inj\u2093'. -/\n@[simp]\ntheorem toHamming_inj {x y : \u2200 i, \u03b2 i} : toHamming x = toHamming y \u2194 x = y :=\n  Iff.rfl\n#align hamming.to_hamming_inj Hamming.toHamming_inj\n\n/- warning: hamming.of_hamming_inj -> Hamming.ofHamming_inj is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} {x : Hamming.{u1, u2} \u03b9 \u03b2} {y : Hamming.{u1, u2} \u03b9 \u03b2}, Iff (Eq.{max (succ u1) (succ u2)} (forall (i : \u03b9), \u03b2 i) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) y)) (Eq.{succ (max u1 u2)} (Hamming.{u1, u2} \u03b9 \u03b2) x y)\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} {x : Hamming.{u2, u1} \u03b9 \u03b2} {y : Hamming.{u2, u1} \u03b9 \u03b2}, Iff (Eq.{max (succ u2) (succ u1)} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (_x : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (_x : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) y)) (Eq.{max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) x y)\nCase conversion may be inaccurate. Consider using '#align hamming.of_hamming_inj Hamming.ofHamming_inj\u2093'. -/\n@[simp]\ntheorem ofHamming_inj {x y : Hamming \u03b2} : ofHamming x = ofHamming y \u2194 x = y :=\n  Iff.rfl\n#align hamming.of_hamming_inj Hamming.ofHamming_inj\n\n#print Hamming.toHamming_zero /-\n@[simp]\ntheorem toHamming_zero [\u2200 i, Zero (\u03b2 i)] : toHamming (0 : \u2200 i, \u03b2 i) = 0 :=\n  rfl\n#align hamming.to_hamming_zero Hamming.toHamming_zero\n-/\n\n#print Hamming.ofHamming_zero /-\n@[simp]\ntheorem ofHamming_zero [\u2200 i, Zero (\u03b2 i)] : ofHamming (0 : Hamming \u03b2) = 0 :=\n  rfl\n#align hamming.of_hamming_zero Hamming.ofHamming_zero\n-/\n\n#print Hamming.toHamming_neg /-\n@[simp]\ntheorem toHamming_neg [\u2200 i, Neg (\u03b2 i)] {x : \u2200 i, \u03b2 i} : toHamming (-x) = -toHamming x :=\n  rfl\n#align hamming.to_hamming_neg Hamming.toHamming_neg\n-/\n\n#print Hamming.ofHamming_neg /-\n@[simp]\ntheorem ofHamming_neg [\u2200 i, Neg (\u03b2 i)] {x : Hamming \u03b2} : ofHamming (-x) = -ofHamming x :=\n  rfl\n#align hamming.of_hamming_neg Hamming.ofHamming_neg\n-/\n\n#print Hamming.toHamming_add /-\n@[simp]\ntheorem toHamming_add [\u2200 i, Add (\u03b2 i)] {x y : \u2200 i, \u03b2 i} :\n    toHamming (x + y) = toHamming x + toHamming y :=\n  rfl\n#align hamming.to_hamming_add Hamming.toHamming_add\n-/\n\n#print Hamming.ofHamming_add /-\n@[simp]\ntheorem ofHamming_add [\u2200 i, Add (\u03b2 i)] {x y : Hamming \u03b2} :\n    ofHamming (x + y) = ofHamming x + ofHamming y :=\n  rfl\n#align hamming.of_hamming_add Hamming.ofHamming_add\n-/\n\n#print Hamming.toHamming_sub /-\n@[simp]\ntheorem toHamming_sub [\u2200 i, Sub (\u03b2 i)] {x y : \u2200 i, \u03b2 i} :\n    toHamming (x - y) = toHamming x - toHamming y :=\n  rfl\n#align hamming.to_hamming_sub Hamming.toHamming_sub\n-/\n\n#print Hamming.ofHamming_sub /-\n@[simp]\ntheorem ofHamming_sub [\u2200 i, Sub (\u03b2 i)] {x y : Hamming \u03b2} :\n    ofHamming (x - y) = ofHamming x - ofHamming y :=\n  rfl\n#align hamming.of_hamming_sub Hamming.ofHamming_sub\n-/\n\n/- warning: hamming.to_hamming_smul -> Hamming.toHamming_smul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_1 : forall (i : \u03b9), SMul.{u1, u3} \u03b1 (\u03b2 i)] {r : \u03b1} {x : forall (i : \u03b9), \u03b2 i}, Eq.{succ (max u2 u3)} (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (coeFn.{max 1 (max (max (succ u2) (succ u3)) (succ (max u2 u3))) (succ (max u2 u3)) (succ u2) (succ u3), max (max (succ u2) (succ u3)) (succ (max u2 u3))} (Equiv.{max (succ u2) (succ u3), succ (max u2 u3)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (fun (_x : Equiv.{max (succ u2) (succ u3), succ (max u2 u3)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) => (forall (i : \u03b9), \u03b2 i) -> (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Equiv.hasCoeToFun.{max (succ u2) (succ u3), succ (max u2 u3)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_1 i)) r x)) (SMul.smul.{u1, max u2 u3} \u03b1 (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (Hamming.hasSmul.{u1, u2, u3} \u03b1 \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_1 i)) r (coeFn.{max 1 (max (max (succ u2) (succ u3)) (succ (max u2 u3))) (succ (max u2 u3)) (succ u2) (succ u3), max (max (succ u2) (succ u3)) (succ (max u2 u3))} (Equiv.{max (succ u2) (succ u3), succ (max u2 u3)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (fun (_x : Equiv.{max (succ u2) (succ u3), succ (max u2 u3)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) => (forall (i : \u03b9), \u03b2 i) -> (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Equiv.hasCoeToFun.{max (succ u2) (succ u3), succ (max u2 u3)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u2, u3} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : forall (i : \u03b9), SMul.{u3, u2} \u03b1 (\u03b2 i)] {r : \u03b1} {x : forall (i : \u03b9), \u03b2 i}, Eq.{max (succ u1) (succ u2)} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_1 i))) r x)) (FunLike.coe.{max (succ u2) (succ u1), max (succ u2) (succ u1), max (succ u2) (succ u1)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (forall (i : \u03b9), \u03b2 i) (fun (_x : forall (i : \u03b9), \u03b2 i) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (forall (i : \u03b9), \u03b2 i) (instHSMul.{u3, max u1 u2} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_1 i))) r x)) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x) ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x) (instHSMul.{u3, max u1 u2} \u03b1 ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x) (Hamming.instSMulHamming.{u3, u1, u2} \u03b1 \u03b9 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_1 i))) r (FunLike.coe.{max (succ u2) (succ u1), max (succ u2) (succ u1), max (succ u2) (succ u1)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (forall (i : \u03b9), \u03b2 i) (fun (_x : forall (i : \u03b9), \u03b2 i) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : forall (i : \u03b9), \u03b2 i) => Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (forall (i : \u03b9), \u03b2 i) (Hamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i))) (Hamming.toHamming.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i)) x))\nCase conversion may be inaccurate. Consider using '#align hamming.to_hamming_smul Hamming.toHamming_smul\u2093'. -/\n@[simp]\ntheorem toHamming_smul [\u2200 i, SMul \u03b1 (\u03b2 i)] {r : \u03b1} {x : \u2200 i, \u03b2 i} :\n    toHamming (r \u2022 x) = r \u2022 toHamming x :=\n  rfl\n#align hamming.to_hamming_smul Hamming.toHamming_smul\n\n/- warning: hamming.of_hamming_smul -> Hamming.ofHamming_smul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_1 : forall (i : \u03b9), SMul.{u1, u3} \u03b1 (\u03b2 i)] {r : \u03b1} {x : Hamming.{u2, u3} \u03b9 \u03b2}, Eq.{max (succ u2) (succ u3)} (forall (i : \u03b9), \u03b2 i) (coeFn.{max 1 (max (succ (max u2 u3)) (succ u2) (succ u3)) (max (succ u2) (succ u3)) (succ (max u2 u3)), max (succ (max u2 u3)) (succ u2) (succ u3)} (Equiv.{succ (max u2 u3), max (succ u2) (succ u3)} (Hamming.{u2, u3} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u2 u3), max (succ u2) (succ u3)} (Hamming.{u2, u3} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u2, u3} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u2 u3), max (succ u2) (succ u3)} (Hamming.{u2, u3} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u3} \u03b9 \u03b2) (SMul.smul.{u1, max u2 u3} \u03b1 (Hamming.{u2, u3} \u03b9 \u03b2) (Hamming.hasSmul.{u1, u2, u3} \u03b1 \u03b9 \u03b2 (fun (i : \u03b9) => _inst_1 i)) r x)) (SMul.smul.{u1, max u2 u3} \u03b1 (forall (i : \u03b9), \u03b2 i) (Pi.instSMul.{u2, u3, u1} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_1 i)) r (coeFn.{max 1 (max (succ (max u2 u3)) (succ u2) (succ u3)) (max (succ u2) (succ u3)) (succ (max u2 u3)), max (succ (max u2 u3)) (succ u2) (succ u3)} (Equiv.{succ (max u2 u3), max (succ u2) (succ u3)} (Hamming.{u2, u3} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u2 u3), max (succ u2) (succ u3)} (Hamming.{u2, u3} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u2, u3} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u2 u3), max (succ u2) (succ u3)} (Hamming.{u2, u3} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u3} \u03b9 \u03b2) x))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : forall (i : \u03b9), SMul.{u3, u2} \u03b1 (\u03b2 i)] {r : \u03b1} {x : Hamming.{u1, u2} \u03b9 \u03b2}, Eq.{max (succ u1) (succ u2)} ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.{u1, u2} \u03b9 \u03b2) (instHSMul.{u3, max u1 u2} \u03b1 (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.instSMulHamming.{u3, u1, u2} \u03b1 \u03b9 \u03b2 (fun (i : \u03b9) => _inst_1 i))) r x)) (FunLike.coe.{max (succ u2) (succ u1), max (succ u2) (succ u1), max (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u1, u2} \u03b9 \u03b2) (fun (_x : Hamming.{u1, u2} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.{u1, u2} \u03b9 \u03b2) (instHSMul.{u3, max u1 u2} \u03b1 (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.instSMulHamming.{u3, u1, u2} \u03b1 \u03b9 \u03b2 (fun (i : \u03b9) => _inst_1 i))) r x)) (HSMul.hSMul.{u3, max u1 u2, max u1 u2} \u03b1 ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) x) ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) x) (instHSMul.{u3, max u1 u2} \u03b1 ((fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) x) (Pi.instSMul.{u1, u2, u3} \u03b9 \u03b1 (fun (i : \u03b9) => \u03b2 i) (fun (i : \u03b9) => _inst_1 i))) r (FunLike.coe.{max (succ u2) (succ u1), max (succ u2) (succ u1), max (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u1, u2} \u03b9 \u03b2) (fun (_x : Hamming.{u1, u2} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x))\nCase conversion may be inaccurate. Consider using '#align hamming.of_hamming_smul Hamming.ofHamming_smul\u2093'. -/\n@[simp]\ntheorem ofHamming_smul [\u2200 i, SMul \u03b1 (\u03b2 i)] {r : \u03b1} {x : Hamming \u03b2} :\n    ofHamming (r \u2022 x) = r \u2022 ofHamming x :=\n  rfl\n#align hamming.of_hamming_smul Hamming.ofHamming_smul\n\nsection\n\n/-! Instances equipping `hamming` with `hamming_norm` and `hamming_dist`. -/\n\n\nvariable [Fintype \u03b9] [\u2200 i, DecidableEq (\u03b2 i)]\n\ninstance : Dist (Hamming \u03b2) :=\n  \u27e8fun x y => hammingDist (ofHamming x) (ofHamming y)\u27e9\n\n/- warning: hamming.dist_eq_hamming_dist -> Hamming.dist_eq_hammingDist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] (x : Hamming.{u1, u2} \u03b9 \u03b2) (y : Hamming.{u1, u2} \u03b9 \u03b2), Eq.{1} Real (Dist.dist.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.hasDist.{u1, u2} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b)) x y) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Real (HasLiftT.mk.{1, 1} Nat Real (CoeTC\u2093.coe.{1, 1} Nat Real (Nat.castCoe.{0} Real Real.hasNatCast))) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) y)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] (x : Hamming.{u2, u1} \u03b9 \u03b2) (y : Hamming.{u2, u1} \u03b9 \u03b2), Eq.{1} Real (Dist.dist.{max u2 u1} (Hamming.{u2, u1} \u03b9 \u03b2) (Hamming.instDistHamming.{u2, u1} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b)) x y) (Nat.cast.{0} Real Real.natCast (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (_x : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (_x : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) y)))\nCase conversion may be inaccurate. Consider using '#align hamming.dist_eq_hamming_dist Hamming.dist_eq_hammingDist\u2093'. -/\n@[simp, push_cast]\ntheorem dist_eq_hammingDist (x y : Hamming \u03b2) :\n    dist x y = hammingDist (ofHamming x) (ofHamming y) :=\n  rfl\n#align hamming.dist_eq_hamming_dist Hamming.dist_eq_hammingDist\n\ninstance : PseudoMetricSpace (Hamming \u03b2) :=\n  {\n    Hamming.hasDist with\n    dist_self := by\n      push_cast\n      exact_mod_cast hammingDist_self\n    dist_comm := by\n      push_cast\n      exact_mod_cast hammingDist_comm\n    dist_triangle := by\n      push_cast\n      exact_mod_cast hammingDist_triangle\n    toUniformSpace := \u22a5\n    uniformity_dist :=\n      uniformity_dist_of_mem_uniformity _ _ fun s =>\n        by\n        push_cast\n        constructor\n        \u00b7 refine' fun hs => \u27e81, zero_lt_one, fun _ _ hab => _\u27e9\n          rw_mod_cast [hammingDist_lt_one]  at hab\n          rw [of_hamming_inj, \u2190 mem_idRel] at hab\n          exact hs hab\n        \u00b7 rintro \u27e8_, h\u03b5, hs\u27e9 \u27e8_, _\u27e9 hab\n          rw [mem_idRel] at hab\n          rw [hab]\n          refine' hs (lt_of_eq_of_lt _ h\u03b5)\n          exact_mod_cast hammingDist_self _\n    toBornology := \u27e8\u22a5, bot_le\u27e9\n    cobounded_sets := by\n      ext\n      push_cast\n      refine' iff_of_true (filter.mem_sets.mpr Filter.mem_bot) \u27e8Fintype.card \u03b9, fun _ _ _ _ => _\u27e9\n      exact_mod_cast hammingDist_le_card_fintype }\n\n/- warning: hamming.nndist_eq_hamming_dist -> Hamming.nndist_eq_hammingDist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] (x : Hamming.{u1, u2} \u03b9 \u03b2) (y : Hamming.{u1, u2} \u03b9 \u03b2), Eq.{1} NNReal (NNDist.nndist.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (PseudoMetricSpace.toNNDist.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.pseudoMetricSpace.{u1, u2} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b))) x y) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat NNReal (HasLiftT.mk.{1, 1} Nat NNReal (CoeTC\u2093.coe.{1, 1} Nat NNReal (Nat.castCoe.{0} NNReal (AddMonoidWithOne.toNatCast.{0} NNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} NNReal (NonAssocSemiring.toAddCommMonoidWithOne.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))))) (hammingDist.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) y)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_1 : Fintype.{u2} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u1} (\u03b2 i)] (x : Hamming.{u2, u1} \u03b9 \u03b2) (y : Hamming.{u2, u1} \u03b9 \u03b2), Eq.{1} NNReal (NNDist.nndist.{max u2 u1} (Hamming.{u2, u1} \u03b9 \u03b2) (PseudoMetricSpace.toNNDist.{max u2 u1} (Hamming.{u2, u1} \u03b9 \u03b2) (Hamming.instPseudoMetricSpaceHamming.{u2, u1} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b))) x y) (Nat.cast.{0} NNReal (CanonicallyOrderedCommSemiring.toNatCast.{0} NNReal instNNRealCanonicallyOrderedCommSemiring) (hammingDist.{u2, u1} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (_x : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u2, u1} \u03b9 \u03b2) (fun (_x : Hamming.{u2, u1} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u2, u1} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Hamming.{u2, u1} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u2, u1} \u03b9 \u03b2) y)))\nCase conversion may be inaccurate. Consider using '#align hamming.nndist_eq_hamming_dist Hamming.nndist_eq_hammingDist\u2093'. -/\n@[simp, push_cast]\ntheorem nndist_eq_hammingDist (x y : Hamming \u03b2) :\n    nndist x y = hammingDist (ofHamming x) (ofHamming y) :=\n  rfl\n#align hamming.nndist_eq_hamming_dist Hamming.nndist_eq_hammingDist\n\ninstance : MetricSpace (Hamming \u03b2) :=\n  { Hamming.pseudoMetricSpace with\n    eq_of_dist_eq_zero := by\n      push_cast\n      exact_mod_cast @eq_of_hammingDist_eq_zero _ _ _ _ }\n\ninstance [\u2200 i, Zero (\u03b2 i)] : Norm (Hamming \u03b2) :=\n  \u27e8fun x => hammingNorm (ofHamming x)\u27e9\n\n/- warning: hamming.norm_eq_hamming_norm -> Hamming.norm_eq_hammingNorm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_3 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] (x : Hamming.{u1, u2} \u03b9 \u03b2), Eq.{1} Real (Norm.norm.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.hasNorm.{u1, u2} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_3 i)) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Real (HasLiftT.mk.{1, 1} Nat Real (CoeTC\u2093.coe.{1, 1} Nat Real (Nat.castCoe.{0} Real Real.hasNatCast))) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_3 i) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_3 : forall (i : \u03b9), Zero.{u2} (\u03b2 i)] (x : Hamming.{u1, u2} \u03b9 \u03b2), Eq.{1} Real (Norm.norm.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.instNormHamming.{u1, u2} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_3 i)) x) (Nat.cast.{0} Real Real.natCast (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_3 i) (FunLike.coe.{max (succ u2) (succ u1), max (succ u2) (succ u1), max (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u1, u2} \u03b9 \u03b2) (fun (_x : Hamming.{u1, u2} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x)))\nCase conversion may be inaccurate. Consider using '#align hamming.norm_eq_hamming_norm Hamming.norm_eq_hammingNorm\u2093'. -/\n@[simp, push_cast]\ntheorem norm_eq_hammingNorm [\u2200 i, Zero (\u03b2 i)] (x : Hamming \u03b2) : \u2016x\u2016 = hammingNorm (ofHamming x) :=\n  rfl\n#align hamming.norm_eq_hamming_norm Hamming.norm_eq_hammingNorm\n\ninstance [\u2200 i, AddCommGroup (\u03b2 i)] : SeminormedAddCommGroup (Hamming \u03b2) :=\n  { Pi.addCommGroup with\n    dist_eq := by\n      push_cast\n      exact_mod_cast hammingDist_eq_hammingNorm }\n\n/- warning: hamming.nnnorm_eq_hamming_norm -> Hamming.nnnorm_eq_hammingNorm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_3 : forall (i : \u03b9), AddCommGroup.{u2} (\u03b2 i)] (x : Hamming.{u1, u2} \u03b9 \u03b2), Eq.{1} NNReal (NNNorm.nnnorm.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (SeminormedAddGroup.toNNNorm.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (SeminormedAddCommGroup.toSeminormedAddGroup.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.seminormedAddCommGroup.{u1, u2} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_3 i)))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat NNReal (HasLiftT.mk.{1, 1} Nat NNReal (CoeTC\u2093.coe.{1, 1} Nat NNReal (Nat.castCoe.{0} NNReal (AddMonoidWithOne.toNatCast.{0} NNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} NNReal (NonAssocSemiring.toAddCommMonoidWithOne.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))))) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => AddZeroClass.toHasZero.{u2} (\u03b2 i) (AddMonoid.toAddZeroClass.{u2} (\u03b2 i) (SubNegMonoid.toAddMonoid.{u2} (\u03b2 i) (AddGroup.toSubNegMonoid.{u2} (\u03b2 i) (AddCommGroup.toAddGroup.{u2} (\u03b2 i) (_inst_3 i)))))) (coeFn.{max 1 (max (succ (max u1 u2)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ (max u1 u2)), max (succ (max u1 u2)) (succ u1) (succ u2)} (Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (fun (_x : Equiv.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) => (Hamming.{u1, u2} \u03b9 \u03b2) -> (forall (i : \u03b9), \u03b2 i)) (Equiv.hasCoeToFun.{succ (max u1 u2), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b2 : \u03b9 -> Type.{u2}} [_inst_1 : Fintype.{u1} \u03b9] [_inst_2 : forall (i : \u03b9), DecidableEq.{succ u2} (\u03b2 i)] [_inst_3 : forall (i : \u03b9), AddCommGroup.{u2} (\u03b2 i)] (x : Hamming.{u1, u2} \u03b9 \u03b2), Eq.{1} NNReal (NNNorm.nnnorm.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (SeminormedAddGroup.toNNNorm.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (SeminormedAddCommGroup.toSeminormedAddGroup.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (NormedAddCommGroup.toSeminormedAddCommGroup.{max u1 u2} (Hamming.{u1, u2} \u03b9 \u03b2) (Hamming.instNormedAddCommGroupHamming.{u1, u2} \u03b9 \u03b2 _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => _inst_3 i))))) x) (Nat.cast.{0} NNReal (CanonicallyOrderedCommSemiring.toNatCast.{0} NNReal instNNRealCanonicallyOrderedCommSemiring) (hammingNorm.{u1, u2} \u03b9 (fun (i : \u03b9) => \u03b2 i) _inst_1 (fun (i : \u03b9) (a : \u03b2 i) (b : \u03b2 i) => _inst_2 i a b) (fun (i : \u03b9) => NegZeroClass.toZero.{u2} (\u03b2 i) (SubNegZeroMonoid.toNegZeroClass.{u2} (\u03b2 i) (SubtractionMonoid.toSubNegZeroMonoid.{u2} (\u03b2 i) (SubtractionCommMonoid.toSubtractionMonoid.{u2} (\u03b2 i) (AddCommGroup.toDivisionAddCommMonoid.{u2} (\u03b2 i) (_inst_3 i)))))) (FunLike.coe.{max (succ u2) (succ u1), max (succ u2) (succ u1), max (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.{u1, u2} \u03b9 \u03b2) (fun (_x : Hamming.{u1, u2} \u03b9 \u03b2) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : Hamming.{u1, u2} \u03b9 \u03b2) => forall (i : \u03b9), \u03b2 i) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Hamming.{u1, u2} \u03b9 \u03b2) (forall (i : \u03b9), \u03b2 i)) (Hamming.ofHamming.{u1, u2} \u03b9 \u03b2) x)))\nCase conversion may be inaccurate. Consider using '#align hamming.nnnorm_eq_hamming_norm Hamming.nnnorm_eq_hammingNorm\u2093'. -/\n@[simp, push_cast]\ntheorem nnnorm_eq_hammingNorm [\u2200 i, AddCommGroup (\u03b2 i)] (x : Hamming \u03b2) :\n    \u2016x\u2016\u208a = hammingNorm (ofHamming x) :=\n  rfl\n#align hamming.nnnorm_eq_hamming_norm Hamming.nnnorm_eq_hammingNorm\n\ninstance [\u2200 i, AddCommGroup (\u03b2 i)] : NormedAddCommGroup (Hamming \u03b2) :=\n  { Hamming.seminormedAddCommGroup with }\n\nend\n\nend Hamming\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/InformationTheory/Hamming.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7417169531393799}}
{"text": "/-\nAn example of why eq and heq for structures is not completely unreasonable.\n-/\n\n/-\nWe want equality of foo's to mean:\n* equivalent predicates P, and\n* functions f which agree on the subset defined by P.\n-/ \nstructure foo : Type :=\n  (P : nat \u2192 Prop)\n  (f : subtype P \u2192 bool)\n\nlemma foo.congr_P (A B : foo) :\n  (A = B) \u2192 forall (n : nat),\n  A.P n \u2194 B.P n :=\nfun (h : A = B) n, eq.to_iff (congr_fun (congr_arg foo.P h) n)\n\nlemma foo.congr_f (A B : foo) :\n  (A = B) \u2192 forall (n : nat) (hA : A.P n) (hB : B.P n),\n  A.f \u27e8n, hA\u27e9 = B.f \u27e8n, hB\u27e9 :=\nfun (h : A = B) n hA hB,\n  @eq.rec foo A\n  (fun C, forall hC : C.P n, A.f \u27e8n, hA\u27e9 = C.f \u27e8n, hC\u27e9)\n  (fun _, eq.refl (A.f \u27e8n, hA\u27e9))\n  B h hB\n\nlemma foo.ext : forall (A B : foo),\n  (forall (n : nat), A.P n \u2194 B.P n) \u2192\n  (forall (n : nat) (hA : A.P n) (hB : B.P n), A.f \u27e8n, hA\u27e9 = B.f \u27e8n, hB\u27e9) \u2192\n  (A = B) :=\n@foo.rec\n(fun A, forall (B : foo),\n  (forall (n : nat), A.P n \u2194 B.P n) \u2192\n  (forall (n : nat) (hA : A.P n) (hB : B.P n), A.f \u27e8n, hA\u27e9 = B.f \u27e8n, hB\u27e9) \u2192\n  (A = B))\n(fun A_P A_f, @foo.rec\n  (fun B,\n    (forall (n : nat), A_P n \u2194 B.P n) \u2192\n    (forall (n : nat) (hA : A_P n) (hB : B.P n), A_f \u27e8n, hA\u27e9 = B.f \u27e8n, hB\u27e9) \u2192\n    (foo.mk A_P A_f = B))\n  (fun B_P B_f,\n    fun (hP_iff : forall (n : nat), A_P n \u2194 B_P n),\n    let hP_eq : A_P = B_P := funext (fun n, propext (hP_iff n)) in\n    @eq.rec (nat \u2192 Prop) A_P\n    (fun C_P, forall (C_f : subtype C_P \u2192 bool),\n      (forall (n : nat) (hA : A_P n) (hC : C_P n), A_f \u27e8n, hA\u27e9 = C_f \u27e8n, hC\u27e9) \u2192\n      (foo.mk A_P A_f = foo.mk C_P C_f))\n    (fun C_f,\n      fun (hf_ext : forall (n : nat) (hA hC : A_P n), A_f \u27e8n, hA\u27e9 = C_f \u27e8n, hC\u27e9),\n      let hf_eq : A_f = C_f := funext (@subtype.rec nat A_P (fun nhA, A_f nhA = C_f nhA) (fun n hA, hf_ext n hA hA)) in\n      @eq.rec (subtype A_P \u2192 bool) A_f\n      (fun f, foo.mk A_P A_f = foo.mk A_P f)\n      (eq.refl (foo.mk A_P A_f))\n      C_f hf_eq)\n    B_P hP_eq B_f))\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old/struct_eq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302033, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7417169429521453}}
{"text": "/-\nCopyright (c) 2014 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Ya\u00ebl Dillies, Patrick Stevens\n\n! This file was ported from Lean 3 source module data.nat.cast.field\n! leanprover-community/mathlib commit acee671f47b8e7972a1eb6f4eed74b4b3abce829\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.Field.Basic\nimport Mathlib.Algebra.Order.Ring.CharZero\nimport Mathlib.Data.Nat.Cast.Basic\n\n/-!\n# Cast of naturals into fields\n\nThis file concerns the canonical homomorphism `\u2115 \u2192 F`, where `F` is a field.\n\n## Main results\n\n * `Nat.cast_div`: if `n` divides `m`, then `\u2191(m / n) = \u2191m / \u2191n`\n * `Nat.cast_div_le`: in all cases, `\u2191(m / n) \u2264 \u2191m / \u2191 n`\n-/\n\n\nnamespace Nat\n\nvariable {\u03b1 : Type _}\n\n@[simp]\ntheorem cast_div [DivisionSemiring \u03b1] {m n : \u2115} (n_dvd : n \u2223 m) (n_nonzero : (n : \u03b1) \u2260 0) :\n    ((m / n : \u2115) : \u03b1) = m / n := by\n  rcases n_dvd with \u27e8k, rfl\u27e9\n  have : n \u2260 0 := by\n    rintro rfl\n    simp at n_nonzero\n  rw [Nat.mul_div_cancel_left _ this.bot_lt, mul_comm n k,cast_mul, mul_div_cancel _ n_nonzero]\n#align nat.cast_div Nat.cast_div\n\ntheorem cast_div_div_div_cancel_right [DivisionSemiring \u03b1] [CharZero \u03b1] {m n d : \u2115}\n  (hn : d \u2223 n) (hm : d \u2223 m) :\n    (\u2191(m / d) : \u03b1) / (\u2191(n / d) : \u03b1) = (m : \u03b1) / n := by\n  rcases eq_or_ne d 0 with (rfl | hd); \u00b7 simp [zero_dvd_iff.mp hm]\n  replace hd : (d : \u03b1) \u2260 0;\n  \u00b7 norm_cast\n  rw [cast_div hm, cast_div hn, div_div_div_cancel_right _ hd] <;> exact hd\n\n#align nat.cast_div_div_div_cancel_right Nat.cast_div_div_div_cancel_right\n\nsection LinearOrderedSemifield\n\nvariable [LinearOrderedSemifield \u03b1]\n\n/-- Natural division is always less than division in the field. -/\ntheorem cast_div_le {m n : \u2115} : ((m / n : \u2115) : \u03b1) \u2264 m / n := by\n  cases n\n  \u00b7 rw [cast_zero, div_zero, Nat.div_zero, cast_zero]\n  rw [le_div_iff, \u2190 Nat.cast_mul, @Nat.cast_le]\n  exact (Nat.div_mul_le_self m _)\n  \u00b7 exact Nat.cast_pos.2 (Nat.succ_pos _)\n#align nat.cast_div_le Nat.cast_div_le\n\ntheorem inv_pos_of_nat {n : \u2115} : 0 < ((n : \u03b1) + 1)\u207b\u00b9 :=\n  inv_pos.2 <| add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one\n#align nat.inv_pos_of_nat Nat.inv_pos_of_nat\n\n\n\ntheorem one_div_le_one_div {n m : \u2115} (h : n \u2264 m) : 1 / ((m : \u03b1) + 1) \u2264 1 / ((n : \u03b1) + 1) := by\n  refine' one_div_le_one_div_of_le _ _\n  exact Nat.cast_add_one_pos _\n  simpa\n#align nat.one_div_le_one_div Nat.one_div_le_one_div\n\ntheorem one_div_lt_one_div {n m : \u2115} (h : n < m) : 1 / ((m : \u03b1) + 1) < 1 / ((n : \u03b1) + 1) := by\n  refine' one_div_lt_one_div_of_lt _ _\n  exact Nat.cast_add_one_pos _\n  simpa\n#align nat.one_div_lt_one_div Nat.one_div_lt_one_div\n\nend LinearOrderedSemifield\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Cast/Field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7417169387367668}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n-/\nimport data.real.sqrt\n\n/-!\n# The complex numbers\n\nThe complex numbers are modelled as \u211d^2 in the obvious way and it is shown that they form a field\nof characteristic zero. The result that the complex numbers are algebraically closed, see\n`field_theory.algebraic_closure`.\n-/\n\nopen_locale big_operators\nopen set function\n\n/-! ### Definition and basic arithmmetic -/\n\n/-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\nopen_locale complex_conjugate\n\nnoncomputable instance : decidable_eq \u2102 := classical.dec_eq _\n\n/-- The equivalence between the complex numbers and `\u211d \u00d7 \u211d`. -/\n@[simps] def equiv_real_prod : \u2102 \u2243 (\u211d \u00d7 \u211d) :=\n{ to_fun := \u03bb z, \u27e8z.re, z.im\u27e9,\n  inv_fun := \u03bb p, \u27e8p.1, p.2\u27e9,\n  left_inv := \u03bb \u27e8x, y\u27e9, rfl,\n  right_inv := \u03bb \u27e8x, y\u27e9, rfl }\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8a, b\u27e9 := rfl\n\n@[ext]\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\ntheorem re_surjective : surjective re := \u03bb x, \u27e8\u27e8x, 0\u27e9, rfl\u27e9\ntheorem im_surjective : surjective im := \u03bb y, \u27e8\u27e80, y\u27e9, rfl\u27e9\n\n@[simp] theorem range_re : range re = univ := re_surjective.range_eq\n@[simp] theorem range_im : range im = univ := im_surjective.range_eq\n\ninstance : has_coe \u211d \u2102 := \u27e8\u03bb r, \u27e8r, 0\u27e9\u27e9\n\n@[simp, norm_cast] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\nlemma of_real_def (r : \u211d) : (r : \u2102) = \u27e8r, 0\u27e9 := rfl\n\n@[simp, norm_cast] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\ntheorem of_real_injective : function.injective (coe : \u211d \u2192 \u2102) :=\n\u03bb z w, congr_arg re\n\ninstance : can_lift \u2102 \u211d :=\n{ cond := \u03bb z, z.im = 0,\n  coe := coe,\n  prf := \u03bb z hz, \u27e8z.re, ext rfl hz.symm\u27e9 }\n\n/-- The product of a set on the real axis and a set on the imaginary axis of the complex plane,\ndenoted by `s \u00d7\u2102 t`. -/\ndef _root_.set.re_prod_im (s t : set \u211d) : set \u2102 := re \u207b\u00b9' s \u2229 im \u207b\u00b9' t\n\ninfix ` \u00d7\u2102 `:72 := set.re_prod_im\n\nlemma mem_re_prod_im {z : \u2102} {s t : set \u211d} : z \u2208 s \u00d7\u2102 t \u2194 z.re \u2208 s \u2227 z.im \u2208 t := iff.rfl\n\ninstance : has_zero \u2102 := \u27e8(0 : \u211d)\u27e9\ninstance : inhabited \u2102 := \u27e80\u27e9\n\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\ninstance : has_one \u2102 := \u27e8(1 : \u211d)\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\n@[simp] theorem of_real_eq_one {z : \u211d} : (z : \u2102) = 1 \u2194 z = 1 := of_real_inj\ntheorem of_real_ne_one {z : \u211d} : (z : \u2102) \u2260 1 \u2194 z \u2260 1 := not_congr of_real_eq_one\n\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n\n@[simp] lemma bit0_re (z : \u2102) : (bit0 z).re = bit0 z.re := rfl\n@[simp] lemma bit1_re (z : \u2102) : (bit1 z).re = bit1 z.re := rfl\n@[simp] lemma bit0_im (z : \u2102) : (bit0 z).im = bit0 z.im := eq.refl _\n@[simp] lemma bit1_im (z : \u2102) : (bit1 z).im = bit0 z.im := add_zero _\n\n@[simp, norm_cast] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s :=\next_iff.2 $ by simp\n\n@[simp, norm_cast] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r :=\next_iff.2 $ by simp [bit0]\n\n@[simp, norm_cast] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r :=\next_iff.2 $ by simp [bit1]\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n@[simp, norm_cast] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\ninstance : has_sub \u2102 := \u27e8\u03bb z w, \u27e8z.re - w.re, z.im - w.im\u27e9\u27e9\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp, norm_cast] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\nlemma of_real_mul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp\nlemma of_real_mul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp\nlemma of_real_mul' (r : \u211d) (z : \u2102) : (\u2191r * z) = \u27e8r * z.re, r * z.im\u27e9 :=\next (of_real_mul_re _ _) (of_real_mul_im _ _)\n\n/-! ### The imaginary unit, `I` -/\n\n/-- The imaginary unit. -/\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := rfl\n@[simp] lemma I_im : I.im = 1 := rfl\n\n@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp\nlemma I_mul (z : \u2102) : I * z = \u27e8-z.im, z.re\u27e9 :=\next_iff.2 $ by simp\n\nlemma I_ne_zero : (I : \u2102) \u2260 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\next_iff.2 $ by simp\n\nlemma mul_I_re (z : \u2102) : (z * I).re = -z.im := by simp\nlemma mul_I_im (z : \u2102) : (z * I).im = z.re := by simp\nlemma I_mul_re (z : \u2102) : (I * z).re = -z.im := by simp\nlemma I_mul_im (z : \u2102) : (I * z).im = z.re := by simp\n\n/-! ### Commutative ring instance and lemmas -/\n\n/- We use a nonstandard formula for the `\u2115` and `\u2124` actions to make sure there is no\ndiamond from the other actions they inherit through the `\u211d`-action on `\u2102` and action transitivity\ndefined in `data.complex.module.lean`. -/\n\ninstance : add_comm_group \u2102 :=\nby refine_struct\n  { zero := (0 : \u2102),\n    add := (+),\n    neg := has_neg.neg,\n    sub := has_sub.sub,\n    nsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9,\n    zsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9 };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\ninstance : add_group_with_one \u2102 :=\n{ nat_cast := \u03bb n, \u27e8n, 0\u27e9,\n  nat_cast_zero := by ext; simp [nat.cast],\n  nat_cast_succ := \u03bb _, by ext; simp [nat.cast],\n  int_cast := \u03bb n, \u27e8n, 0\u27e9,\n  int_cast_of_nat := \u03bb _, by ext; simp [\u03bb n, show @coe \u2115 \u2102 \u27e8_\u27e9 n = \u27e8n, 0\u27e9, from rfl],\n  int_cast_neg_succ_of_nat := \u03bb _, by ext; simp [\u03bb n, show @coe \u2115 \u2102 \u27e8_\u27e9 n = \u27e8n, 0\u27e9, from rfl],\n  one := 1,\n  .. complex.add_comm_group }\n\ninstance : comm_ring \u2102 :=\nby refine_struct\n  { zero := (0 : \u2102),\n    add := (+),\n    one := 1,\n    mul := (*),\n    npow := @npow_rec _ \u27e8(1 : \u2102)\u27e9 \u27e8(*)\u27e9,\n    .. complex.add_group_with_one };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\n/-- This shortcut instance ensures we do not find `ring` via the noncomputable `complex.field`\ninstance. -/\ninstance : ring \u2102 := by apply_instance\n\n/-- This shortcut instance ensures we do not find `comm_semiring` via the noncomputable\n`complex.field` instance. -/\ninstance : comm_semiring \u2102 := infer_instance\n\n/-- The \"real part\" map, considered as an additive group homomorphism. -/\ndef re_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := re,\n  map_zero' := zero_re,\n  map_add' := add_re }\n\n@[simp] lemma coe_re_add_group_hom : (re_add_group_hom : \u2102 \u2192 \u211d) = re := rfl\n\n/-- The \"imaginary part\" map, considered as an additive group homomorphism. -/\ndef im_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := im,\n  map_zero' := zero_im,\n  map_add' := add_im }\n\n@[simp] lemma coe_im_add_group_hom : (im_add_group_hom : \u2102 \u2192 \u211d) = im := rfl\n\n@[simp] lemma I_pow_bit0 (n : \u2115) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [pow_bit0', I_mul_I]\n\n@[simp] lemma I_pow_bit1 (n : \u2115) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [pow_bit1', I_mul_I]\n\n/-! ### Complex conjugation -/\n\n/-- This defines the complex conjugate as the `star` operation of the `star_ring \u2102`. It\nis recommended to use the ring endomorphism version `star_ring_end`, available under the\nnotation `conj` in the locale `complex_conjugate`. -/\ninstance : star_ring \u2102 :=\n{ star := \u03bb z, \u27e8z.re, -z.im\u27e9,\n  star_involutive := \u03bb x, by simp only [eta, neg_neg],\n  star_mul := \u03bb a b, by ext; simp [add_comm]; ring,\n  star_add := \u03bb a b, by ext; simp [add_comm] }\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := rfl\n\nlemma conj_of_real (r : \u211d) : conj (r : \u2102) = r := ext_iff.2 $ by simp [conj]\n\n@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp\n\nlemma conj_bit0 (z : \u2102) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]\nlemma conj_bit1 (z : \u2102) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0]\n\n@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp\n\nlemma eq_conj_iff_real {z : \u2102} : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n\u27e8\u03bb h, \u27e8z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)\u27e9,\n \u03bb \u27e8h, e\u27e9, by rw [e, conj_of_real]\u27e9\n\nlemma eq_conj_iff_re {z : \u2102} : conj z = z \u2194 (z.re : \u2102) = z :=\neq_conj_iff_real.trans \u27e8by rintro \u27e8r, rfl\u27e9; simp, \u03bb h, \u27e8_, h.symm\u27e9\u27e9\n\nlemma eq_conj_iff_im {z : \u2102} : conj z = z \u2194 z.im = 0 :=\n\u27e8\u03bb h, add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)),\n  \u03bb h, ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))\u27e9\n\n-- `simp_nf` complains about this being provable by `is_R_or_C.star_def` even\n-- though it's not imported by this file.\n@[simp, nolint simp_nf] lemma star_def : (has_star.star : \u2102 \u2192 \u2102) = conj := rfl\n\n/-! ### Norm squared -/\n\n/-- The norm squared function. -/\n@[pp_nodot] def norm_sq : \u2102 \u2192*\u2080 \u211d :=\n{ to_fun := \u03bb z, z.re * z.re + z.im * z.im,\n  map_zero' := by simp,\n  map_one' := by simp,\n  map_mul' := \u03bb z w, by { dsimp, ring } }\n\nlemma norm_sq_apply (z : \u2102) : norm_sq z = z.re * z.re + z.im * z.im := rfl\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mk (x y : \u211d) : norm_sq \u27e8x, y\u27e9 = x * x + y * y := rfl\n\nlemma norm_sq_add_mul_I (x y : \u211d) : norm_sq (x + y * I) = x ^ 2 + y ^ 2 :=\nby rw [\u2190 mk_eq_add_mul_I, norm_sq_mk, sq, sq]\n\nlemma norm_sq_eq_conj_mul_self {z : \u2102} : (norm_sq z : \u2102) = conj z * z :=\nby { ext; simp [norm_sq, mul_comm], }\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := norm_sq.map_zero\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := norm_sq.map_one\n@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\n@[simp] lemma range_norm_sq : range norm_sq = Ici 0 :=\nsubset.antisymm (range_subset_iff.2 norm_sq_nonneg) $ \u03bb x hx,\n  \u27e8real.sqrt x, by rw [norm_sq_of_real, real.mul_self_sqrt hx]\u27e9\n\nlemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\n\u27e8\u03bb h, ext\n  (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n  (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),\n \u03bb h, h.symm \u25b8 norm_sq_zero\u27e9\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\n(norm_sq_nonneg z).lt_iff_ne.trans $ not_congr (eq_comm.trans norm_sq_eq_zero)\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\nlemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nnorm_sq.map_mul z w\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nby dsimp [norm_sq]; ring\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\next_iff.2 $ by simp [two_mul]\n\n/-- The coercion `\u211d \u2192 \u2102` as a `ring_hom`. -/\ndef of_real : \u211d \u2192+* \u2102 := \u27e8coe, of_real_one, of_real_mul, of_real_zero, of_real_add\u27e9\n\n@[simp] lemma of_real_eq_coe (r : \u211d) : of_real r = r := rfl\n\n@[simp] lemma I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]\n\n@[simp] lemma sub_re (z w : \u2102) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : \u2102) : (z - w).im = z.im - w.im := rfl\n@[simp, norm_cast] lemma of_real_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s := ext_iff.2 $ by simp\n@[simp, norm_cast] lemma of_real_pow (r : \u211d) (n : \u2115) : ((r ^ n : \u211d) : \u2102) = r ^ n :=\nby induction n; simp [*, of_real_mul, pow_succ]\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\next_iff.2 $ by simp [two_mul, sub_eq_add_neg]\n\nlemma norm_sq_sub (z w : \u2102) : norm_sq (z - w) =\n  norm_sq z + norm_sq w - 2 * (z * conj w).re :=\nby { rw [sub_eq_add_neg, norm_sq_add],\n     simp only [ring_hom.map_neg, mul_neg, neg_re,\n                tactic.ring.add_neg_eq_sub, norm_sq_neg] }\n\n/-! ### Inversion -/\n\nnoncomputable instance : has_inv \u2102 := \u27e8\u03bb z, conj z * ((norm_sq z)\u207b\u00b9:\u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((norm_sq z)\u207b\u00b9:\u211d) := rfl\n@[simp] lemma inv_re (z : \u2102) : (z\u207b\u00b9).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : \u2102) : (z\u207b\u00b9).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\n@[simp, norm_cast] lemma of_real_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = r\u207b\u00b9 :=\next_iff.2 $ by simp\n\nprotected \n\nprotected theorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nby rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 of_real_mul,\n  mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]\n\n/-! ### Field instance and lemmas -/\n\nnoncomputable instance : field \u2102 :=\n{ inv := has_inv.inv,\n  exists_pair_ne := \u27e80, 1, mt (congr_arg re) zero_ne_one\u27e9,\n  mul_inv_cancel := @complex.mul_inv_cancel,\n  inv_zero := complex.inv_zero,\n  ..complex.comm_ring }\n\n@[simp] lemma I_zpow_bit0 (n : \u2124) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [zpow_bit0', I_mul_I]\n\n@[simp] lemma I_zpow_bit1 (n : \u2124) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [zpow_bit1', I_mul_I]\n\nlemma div_re (z w : \u2102) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]\nlemma div_im (z w : \u2102) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]\n\nlemma conj_inv (x : \u2102) : conj (x\u207b\u00b9) = (conj x)\u207b\u00b9 := star_inv' _\n\n@[simp, norm_cast] lemma of_real_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\nof_real.map_div r s\n\n@[simp, norm_cast] lemma of_real_zpow (r : \u211d) (n : \u2124) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n :=\nof_real.map_zpow r n\n\n@[simp] lemma div_I (z : \u2102) : z / I = -(z * I) :=\n(div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc]\n\n@[simp] lemma inv_I : I\u207b\u00b9 = -I :=\nby simp [inv_eq_one_div]\n\n@[simp] lemma norm_sq_inv (z : \u2102) : norm_sq z\u207b\u00b9 = (norm_sq z)\u207b\u00b9 :=\nnorm_sq.map_inv z\n\n@[simp] lemma norm_sq_div (z w : \u2102) : norm_sq (z / w) = norm_sq z / norm_sq w :=\nnorm_sq.map_div z w\n\n/-! ### Cast lemmas -/\n\n@[simp, norm_cast] theorem of_real_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\nmap_nat_cast of_real n\n\n@[simp, norm_cast] lemma nat_cast_re (n : \u2115) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_nat_cast, of_real_re]\n\n@[simp, norm_cast] lemma nat_cast_im (n : \u2115) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_nat_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_int_cast (n : \u2124) : ((n : \u211d) : \u2102) = n :=\nof_real.map_int_cast n\n\n@[simp, norm_cast] lemma int_cast_re (n : \u2124) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_int_cast, of_real_re]\n\n@[simp, norm_cast] lemma int_cast_im (n : \u2124) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_int_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_rat_cast (n : \u211a) : ((n : \u211d) : \u2102) = n := map_rat_cast of_real n\n\n@[simp, norm_cast] lemma rat_cast_re (q : \u211a) : (q : \u2102).re = q :=\nby rw [\u2190 of_real_rat_cast, of_real_re]\n\n@[simp, norm_cast] lemma rat_cast_im (q : \u211a) : (q : \u2102).im = 0 :=\nby rw [\u2190 of_real_rat_cast, of_real_im]\n\n/-! ### Characteristic zero -/\n\ninstance char_zero_complex : char_zero \u2102 :=\nchar_zero_of_inj_zero $ \u03bb n h,\nby rwa [\u2190 of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h\n\n/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 :=\nby simp only [add_conj, of_real_mul, of_real_one, of_real_bit0,\n     mul_div_cancel_left (z.re:\u2102) two_ne_zero']\n\n/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/\ntheorem im_eq_sub_conj (z : \u2102) : (z.im : \u2102) = (z - conj(z))/(2 * I) :=\nby simp only [sub_conj, of_real_mul, of_real_one, of_real_bit0, mul_right_comm,\n     mul_div_cancel_left _ (mul_ne_zero two_ne_zero' I_ne_zero : 2 * I \u2260 0)]\n\n/-! ### Absolute value -/\n\n/-- The complex absolute value function, defined as the square root of the norm squared. -/\n@[pp_nodot] noncomputable def abs (z : \u2102) : \u211d := (norm_sq z).sqrt\n\nlocal notation `abs'` := has_abs.abs\n\n@[simp, norm_cast] lemma abs_of_real (r : \u211d) : abs r = |r| :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\nlemma abs_of_nat (n : \u2115) : complex.abs n = n :=\ncalc complex.abs n = complex.abs (n:\u211d) : by rw [of_real_nat_cast]\n  ... = _ : abs_of_nonneg (nat.cast_nonneg n)\n\nlemma mul_self_abs (z : \u2102) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\nlemma sq_abs (z : \u2102) : abs z ^ 2 = norm_sq z :=\nreal.sq_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma sq_abs_sub_sq_re (z : \u2102) : abs z ^ 2 - z.re ^ 2 = z.im ^ 2 :=\nby rw [sq_abs, norm_sq_apply, \u2190 sq, \u2190 sq, add_sub_cancel']\n\n@[simp] lemma sq_abs_sub_sq_im (z : \u2102) : abs z ^ 2 - z.im ^ 2 = z.re ^ 2 :=\nby rw [\u2190 sq_abs_sub_sq_re, sub_sub_cancel]\n\n@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]\n@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]\n@[simp] lemma abs_I : abs I = 1 := by simp [abs]\n\n@[simp] lemma abs_two : abs 2 = 2 :=\ncalc abs 2 = abs (2 : \u211d) : by rw [of_real_bit0, of_real_one]\n... = (2 : \u211d) : abs_of_nonneg (by norm_num)\n\nlemma abs_nonneg (z : \u2102) : 0 \u2264 abs z :=\nreal.sqrt_nonneg _\n\n@[simp] lemma range_abs : range abs = Ici 0 :=\nsubset.antisymm (range_subset_iff.2 abs_nonneg) $ \u03bb x hx, \u27e8x, abs_of_nonneg hx\u27e9\n\n@[simp] lemma abs_eq_zero {z : \u2102} : abs z = 0 \u2194 z = 0 :=\n(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero\n\nlemma abs_ne_zero {z : \u2102} : abs z \u2260 0 \u2194 z \u2260 0 :=\nnot_congr abs_eq_zero\n\n@[simp] lemma abs_conj (z : \u2102) : abs (conj z) = abs z :=\nby simp [abs]\n\n@[simp] lemma abs_mul (z w : \u2102) : abs (z * w) = abs z * abs w :=\nby rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl\n\n/-- `complex.abs` as a `monoid_with_zero_hom`. -/\n@[simps] noncomputable def abs_hom : \u2102 \u2192*\u2080 \u211d :=\n{ to_fun := abs,\n  map_zero' := abs_zero,\n  map_one' := abs_one,\n  map_mul' := abs_mul }\n\n@[simp] lemma abs_prod {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 \u2102) :\n  abs (s.prod f) = s.prod (\u03bb i, abs (f i)) :=\nmap_prod abs_hom _ _\n\n@[simp] lemma abs_pow (z : \u2102) (n : \u2115) : abs (z ^ n) = abs z ^ n :=\nmap_pow abs_hom z n\n\n@[simp] lemma abs_zpow (z : \u2102) (n : \u2124) : abs (z ^ n) = abs z ^ n :=\nabs_hom.map_zpow z n\n\nlemma abs_re_le_abs (z : \u2102) : |z.re| \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply re_sq_le_norm_sq\n\nlemma abs_im_le_abs (z : \u2102) : |z.im| \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply im_sq_le_norm_sq\n\nlemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : \u2102) : z.im \u2264 abs z :=\n(abs_le.1 (abs_im_le_abs _)).2\n\n@[simp] lemma abs_re_lt_abs {z : \u2102} : |z.re| < abs z \u2194 z.im \u2260 0 :=\nby rw [abs, real.lt_sqrt (_root_.abs_nonneg _), norm_sq_apply, _root_.sq_abs, \u2190 sq,\n  lt_add_iff_pos_right, mul_self_pos]\n\n@[simp] lemma abs_im_lt_abs {z : \u2102} : |z.im| < abs z \u2194 z.re \u2260 0 :=\nby simpa using @abs_re_lt_abs (z * I)\n\n/--\nThe **triangle inequality** for complex numbers.\n-/\nlemma abs_add (z w : \u2102) : abs (z + w) \u2264 abs z + abs w :=\n(mul_self_le_mul_self_iff (abs_nonneg _)\n  (add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $\nbegin\n  rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,\n      add_right_comm, norm_sq_add, add_le_add_iff_left,\n      mul_assoc, mul_le_mul_left (@zero_lt_two \u211d _ _)],\n  simpa [-mul_re] using re_le_abs (z * conj w)\nend\n\ninstance : is_absolute_value abs :=\n{ abv_nonneg  := abs_nonneg,\n  abv_eq_zero := \u03bb _, abs_eq_zero,\n  abv_add     := abs_add,\n  abv_mul     := abs_mul }\nopen is_absolute_value\n\n@[simp] lemma abs_abs (z : \u2102) : |(abs z)| = abs z :=\n_root_.abs_of_nonneg (abs_nonneg _)\n\n@[simp] lemma abs_pos {z : \u2102} : 0 < abs z \u2194 z \u2260 0 := abv_pos abs\n@[simp] lemma abs_neg : \u2200 z, abs (-z) = abs z := abv_neg abs\nlemma abs_sub_comm : \u2200 z w, abs (z - w) = abs (w - z) := abv_sub abs\nlemma abs_sub_le : \u2200 a b c, abs (a - c) \u2264 abs (a - b) + abs (b - c) := abv_sub_le abs\n@[simp] theorem abs_inv : \u2200 z, abs z\u207b\u00b9 = (abs z)\u207b\u00b9 := abv_inv abs\n@[simp] theorem abs_div : \u2200 z w, abs (z / w) = abs z / abs w := abv_div abs\n\nlemma abs_abs_sub_le_abs_sub : \u2200 z w, |abs z - abs w| \u2264 abs (z - w) :=\nabs_abv_sub_le_abv_sub abs\n\nlemma abs_le_abs_re_add_abs_im (z : \u2102) : abs z \u2264 |z.re| + |z.im| :=\nby simpa [re_add_im] using abs_add z.re (z.im * I)\n\nlemma abs_le_sqrt_two_mul_max (z : \u2102) : abs z \u2264 real.sqrt 2 * max (|z.re|) (|z.im|) :=\nbegin\n  cases z with x y,\n  simp only [abs, norm_sq_mk, \u2190 sq],\n  wlog hle : |x| \u2264 |y| := le_total (|x|) (|y|) using [x y, y x] tactic.skip,\n  { calc real.sqrt (x ^ 2 + y ^ 2) \u2264 real.sqrt (y ^ 2 + y ^ 2) :\n      real.sqrt_le_sqrt (add_le_add_right (sq_le_sq.2 hle) _)\n    ... = real.sqrt 2 * max (|x|) (|y|) :\n      by rw [max_eq_right hle, \u2190 two_mul, real.sqrt_mul two_pos.le, real.sqrt_sq_eq_abs] },\n  { rwa [add_comm, max_comm] }\nend\n\nlemma abs_re_div_abs_le_one (z : \u2102) : |z.re / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }\n\nlemma abs_im_div_abs_le_one (z : \u2102) : |z.im / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }\n\n@[simp, norm_cast] lemma abs_cast_nat (n : \u2115) : abs (n : \u2102) = n :=\nby rw [\u2190 of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]\n\n@[simp, norm_cast] lemma int_cast_abs (n : \u2124) : \u2191|n| = abs n :=\nby rw [\u2190 of_real_int_cast, abs_of_real, int.cast_abs]\n\nlemma norm_sq_eq_abs (x : \u2102) : norm_sq x = abs x ^ 2 :=\nby rw [abs, sq, real.mul_self_sqrt (norm_sq_nonneg _)]\n\n/--\nWe put a partial order on \u2102 so that `z \u2264 w` exactly if `w - z` is real and nonnegative.\nComplex numbers with different imaginary parts are incomparable.\n-/\nprotected def partial_order : partial_order \u2102 :=\n{ le := \u03bb z w, z.re \u2264 w.re \u2227 z.im = w.im,\n  lt := \u03bb z w, z.re < w.re \u2227 z.im = w.im,\n  lt_iff_le_not_le := \u03bb z w, by { dsimp, rw lt_iff_le_not_le, tauto },\n  le_refl := \u03bb x, \u27e8le_rfl, rfl\u27e9,\n  le_trans := \u03bb x y z h\u2081 h\u2082, \u27e8h\u2081.1.trans h\u2082.1, h\u2081.2.trans h\u2082.2\u27e9,\n  le_antisymm := \u03bb z w h\u2081 h\u2082, ext (h\u2081.1.antisymm h\u2082.1) h\u2081.2 }\n\nsection complex_order\n\nlocalized \"attribute [instance] complex.partial_order\" in complex_order\n\nlemma le_def {z w : \u2102} : z \u2264 w \u2194 z.re \u2264 w.re \u2227 z.im = w.im := iff.rfl\nlemma lt_def {z w : \u2102} : z < w \u2194 z.re < w.re \u2227 z.im = w.im := iff.rfl\n\n@[simp, norm_cast] lemma real_le_real {x y : \u211d} : (x : \u2102) \u2264 (y : \u2102) \u2194 x \u2264 y := by simp [le_def]\n\n@[simp, norm_cast] lemma real_lt_real {x y : \u211d} : (x : \u2102) < (y : \u2102) \u2194 x < y := by simp [lt_def]\n\n@[simp, norm_cast] lemma zero_le_real {x : \u211d} : (0 : \u2102) \u2264 (x : \u2102) \u2194 0 \u2264 x := real_le_real\n@[simp, norm_cast] lemma zero_lt_real {x : \u211d} : (0 : \u2102) < (x : \u2102) \u2194 0 < x := real_lt_real\n\nlemma not_le_iff {z w : \u2102} : \u00ac(z \u2264 w) \u2194 w.re < z.re \u2228 z.im \u2260 w.im :=\nby rw [le_def, not_and_distrib, not_le]\n\nlemma not_lt_iff {z w : \u2102} : \u00ac(z < w) \u2194 w.re \u2264 z.re \u2228 z.im \u2260 w.im :=\nby rw [lt_def, not_and_distrib, not_lt]\n\nlemma not_le_zero_iff {z : \u2102} : \u00acz \u2264 0 \u2194 0 < z.re \u2228 z.im \u2260 0 := not_le_iff\nlemma not_lt_zero_iff {z : \u2102} : \u00acz < 0 \u2194 0 \u2264 z.re \u2228 z.im \u2260 0 := not_lt_iff\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is an ordered ring.\n-/\nprotected def ordered_comm_ring : ordered_comm_ring \u2102 :=\n{ zero_le_one := \u27e8zero_le_one, rfl\u27e9,\n  add_le_add_left := \u03bb w z h y, \u27e8add_le_add_left h.1 _, congr_arg2 (+) rfl h.2\u27e9,\n  mul_pos := \u03bb z w hz hw,\n    by simp [lt_def, mul_re, mul_im, \u2190 hz.2, \u2190 hw.2, mul_pos hz.1 hw.1],\n  .. complex.partial_order,\n  .. complex.comm_ring }\n\nlocalized \"attribute [instance] complex.ordered_comm_ring\" in complex_order\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a star ordered ring.\n(That is, a star ring in which the nonnegative elements are those of the form `star z * z`.)\n-/\nprotected def star_ordered_ring : star_ordered_ring \u2102 :=\n{ nonneg_iff := \u03bb r, by\n  { refine \u27e8\u03bb hr, \u27e8real.sqrt r.re, _\u27e9, \u03bb h, _\u27e9,\n    { have h\u2081 : 0 \u2264 r.re := by { rw [le_def] at hr, exact hr.1 },\n      have h\u2082 : r.im = 0 := by { rw [le_def] at hr, exact hr.2.symm },\n      ext,\n      { simp only [of_real_im, star_def, of_real_re, sub_zero, conj_re, mul_re, mul_zero,\n                   \u2190real.sqrt_mul h\u2081 r.re, real.sqrt_mul_self h\u2081] },\n      { simp only [h\u2082, add_zero, of_real_im, star_def, zero_mul, conj_im,\n                   mul_im, mul_zero, neg_zero] } },\n    { obtain \u27e8s, rfl\u27e9 := h,\n      simp only [\u2190norm_sq_eq_conj_mul_self, norm_sq_nonneg, zero_le_real, star_def] } },\n  ..complex.ordered_comm_ring }\n\nlocalized \"attribute [instance] complex.star_ordered_ring\" in complex_order\n\nend complex_order\n\n/-! ### Cauchy sequences -/\n\ntheorem is_cau_seq_re (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).re) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n\ntheorem is_cau_seq_im (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).im) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n\n/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_re (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_re f\u27e9\n\n/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_im (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_im f\u27e9\n\nlemma is_cau_seq_abs {f : \u2115 \u2192 \u2102} (hf : is_cau_seq abs f) :\n  is_cau_seq abs' (abs \u2218 f) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := hf \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9\n\n/-- The limit of a Cauchy sequence of complex numbers. -/\nnoncomputable def lim_aux (f : cau_seq \u2102 abs) : \u2102 :=\n\u27e8cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)\u27e9\n\ntheorem equiv_lim_aux (f : cau_seq \u2102 abs) : f \u2248 cau_seq.const abs (lim_aux f) :=\n\u03bb \u03b5 \u03b50, (exists_forall_ge_and\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_re f\u27e9 _ (half_pos \u03b50))\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_im f\u27e9 _ (half_pos \u03b50))).imp $\n\u03bb i H j ij, begin\n  cases H _ ij with H\u2081 H\u2082,\n  apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),\n  dsimp [lim_aux] at *,\n  have := add_lt_add H\u2081 H\u2082,\n  rwa add_halves at this,\nend\n\ninstance : cau_seq.is_complete \u2102 abs :=\n\u27e8\u03bb f, \u27e8lim_aux f, equiv_lim_aux f\u27e9\u27e9\n\nopen cau_seq\n\nlemma lim_eq_lim_im_add_lim_re (f : cau_seq \u2102 abs) : lim f =\n  \u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I :=\nlim_eq_of_equiv_const $\ncalc f \u2248 _ : equiv_lim_aux f\n... = cau_seq.const abs (\u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I) :\n  cau_seq.ext (\u03bb _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))\n\nlemma lim_re (f : cau_seq \u2102 abs) : lim (cau_seq_re f) = (lim f).re :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma lim_im (f : cau_seq \u2102 abs) : lim (cau_seq_im f) = (lim f).im :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma is_cau_seq_conj (f : cau_seq \u2102 abs) : is_cau_seq abs (\u03bb n, conj (f n)) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := f.2 \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, by rw [\u2190 ring_hom.map_sub, abs_conj]; exact hi j hj\u27e9\n\n/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/\nnoncomputable def cau_seq_conj (f : cau_seq \u2102 abs) : cau_seq \u2102 abs :=\n\u27e8_, is_cau_seq_conj f\u27e9\n\nlemma lim_conj (f : cau_seq \u2102 abs) : lim (cau_seq_conj f) = conj (lim f) :=\ncomplex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])\n  (by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)\n\n/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_abs (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_abs f.2\u27e9\n\nlemma lim_abs (f : cau_seq \u2102 abs) : lim (cau_seq_abs f) = abs (lim f) :=\nlim_eq_of_equiv_const (\u03bb \u03b5 \u03b50,\nlet \u27e8i, hi\u27e9 := equiv_lim f \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9)\n\nvariables {\u03b1 : Type*} (s : finset \u03b1)\n\n@[simp, norm_cast] lemma of_real_prod (f : \u03b1 \u2192 \u211d) :\n  ((\u220f i in s, f i : \u211d) : \u2102) = \u220f i in s, (f i : \u2102) :=\nring_hom.map_prod of_real _ _\n\n@[simp, norm_cast] lemma of_real_sum (f : \u03b1 \u2192 \u211d) :\n  ((\u2211 i in s, f i : \u211d) : \u2102) = \u2211 i in s, (f i : \u2102) :=\nring_hom.map_sum of_real _ _\n\n@[simp] lemma re_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).re = \u2211 i in s, (f i).re :=\nre_add_group_hom.map_sum f s\n\n@[simp] lemma im_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).im = \u2211 i in s, (f i).im :=\nim_add_group_hom.map_sum f s\n\nend complex\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272544, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.741707775467595}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.special_functions.exp_deriv\n\n/-!\n# Gr\u00f6nwall's inequality\n\nThe main technical result of this file is the Gr\u00f6nwall-like inequality\n`norm_le_gronwall_bound_of_norm_deriv_right_le`. It states that if `f : \u211d \u2192 E` satisfies `\u2225f a\u2225 \u2264 \u03b4`\nand `\u2200 x \u2208 [a, b), \u2225f' x\u2225 \u2264 K * \u2225f x\u2225 + \u03b5`, then for all `x \u2208 [a, b]` we have `\u2225f x\u2225 \u2264 \u03b4 * exp (K *\nx) + (\u03b5 / K) * (exp (K * x) - 1)`.\n\nThen we use this inequality to prove some estimates on the possible rate of growth of the distance\nbetween two approximate or exact solutions of an ordinary differential equation.\n\nThe proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*,\nSec. 4.5][HubbardWest-ode], where `norm_le_gronwall_bound_of_norm_deriv_right_le` is called\n\u201cFundamental Inequality\u201d.\n\n## TODO\n\n- Once we have FTC, prove an inequality for a function satisfying `\u2225f' x\u2225 \u2264 K x * \u2225f x\u2225 + \u03b5`,\n  or more generally `liminf_{y\u2192x+0} (f y - f x)/(y - x) \u2264 K x * f x + \u03b5` with any sign\n  of `K x` and `f x`.\n-/\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E]\n          {F : Type*} [normed_group F] [normed_space \u211d F]\n\nopen metric set asymptotics filter real\nopen_locale classical topological_space nnreal\n\n/-! ### Technical lemmas about `gronwall_bound` -/\n\n/-- Upper bound used in several Gr\u00f6nwall-like inequalities. -/\nnoncomputable def gronwall_bound (\u03b4 K \u03b5 x : \u211d) : \u211d :=\nif K = 0 then \u03b4 + \u03b5 * x else \u03b4 * exp (K * x) + (\u03b5 / K) * (exp (K * x) - 1)\n\nlemma gronwall_bound_K0 (\u03b4 \u03b5 : \u211d) : gronwall_bound \u03b4 0 \u03b5 = \u03bb x, \u03b4 + \u03b5 * x :=\nfunext $ \u03bb x, if_pos rfl\n\nlemma gronwall_bound_of_K_ne_0 {\u03b4 K \u03b5 : \u211d} (hK : K \u2260 0) :\n  gronwall_bound \u03b4 K \u03b5 = \u03bb x, \u03b4 * exp (K * x) + (\u03b5 / K) * (exp (K * x) - 1) :=\nfunext $ \u03bb x, if_neg hK\n\nlemma has_deriv_at_gronwall_bound (\u03b4 K \u03b5 x : \u211d) :\n  has_deriv_at (gronwall_bound \u03b4 K \u03b5) (K * (gronwall_bound \u03b4 K \u03b5 x) + \u03b5) x :=\nbegin\n  by_cases hK : K = 0,\n  { subst K,\n    simp only [gronwall_bound_K0, zero_mul, zero_add],\n    convert ((has_deriv_at_id x).const_mul \u03b5).const_add \u03b4,\n    rw [mul_one] },\n  { simp only [gronwall_bound_of_K_ne_0 hK],\n    convert (((has_deriv_at_id x).const_mul K).exp.const_mul \u03b4).add\n      ((((has_deriv_at_id x).const_mul K).exp.sub_const 1).const_mul (\u03b5 / K)) using 1,\n    simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel' _ hK],\n    ring }\nend\n\nlemma has_deriv_at_gronwall_bound_shift (\u03b4 K \u03b5 x a : \u211d) :\n  has_deriv_at (\u03bb y, gronwall_bound \u03b4 K \u03b5 (y - a)) (K * (gronwall_bound \u03b4 K \u03b5 (x - a)) + \u03b5) x :=\nbegin\n  convert (has_deriv_at_gronwall_bound \u03b4 K \u03b5 _).comp x ((has_deriv_at_id x).sub_const a),\n  rw [id, mul_one]\nend\n\nlemma gronwall_bound_x0 (\u03b4 K \u03b5 : \u211d) : gronwall_bound \u03b4 K \u03b5 0 = \u03b4 :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound, if_pos hK, mul_zero, add_zero] },\n  { simp only [gronwall_bound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] }\nend\n\nlemma gronwall_bound_\u03b50 (\u03b4 K x : \u211d) : gronwall_bound \u03b4 K 0 x = \u03b4 * exp (K * x) :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] },\n  { simp only [gronwall_bound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] }\nend\n\nlemma gronwall_bound_\u03b50_\u03b40 (K x : \u211d) : gronwall_bound 0 K 0 x = 0 :=\nby simp only [gronwall_bound_\u03b50, zero_mul]\n\nlemma gronwall_bound_continuous_\u03b5 (\u03b4 K x : \u211d) : continuous (\u03bb \u03b5, gronwall_bound \u03b4 K \u03b5 x) :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound_K0, hK],\n    exact continuous_const.add (continuous_id.mul continuous_const) },\n  { simp only [gronwall_bound_of_K_ne_0 hK],\n    exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) }\nend\n\n/-! ### Inequality and corollaries -/\n\n/-- A Gr\u00f6nwall-like inequality: if `f : \u211d \u2192 \u211d` is continuous on `[a, b]` and satisfies\nthe inequalities `f a \u2264 \u03b4` and\n`\u2200 x \u2208 [a, b), liminf_{z\u2192x+0} (f z - f x)/(z - x) \u2264 K * (f x) + \u03b5`, then `f x`\nis bounded by `gronwall_bound \u03b4 K \u03b5 (x - a)` on `[a, b]`.\n\nSee also `norm_le_gronwall_bound_of_norm_deriv_right_le` for a version bounding `\u2225f x\u2225`,\n`f : \u211d \u2192 E`. -/\ntheorem le_gronwall_bound_of_liminf_deriv_right_le {f f' : \u211d \u2192 \u211d} {\u03b4 K \u03b5 : \u211d} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 x \u2208 Ico a b, \u2200 r, f' x < r \u2192\n    \u2203\u1da0 z in \ud835\udcdd[Ioi x] x, (z - x)\u207b\u00b9 * (f z - f x) < r)\n  (ha : f a \u2264 \u03b4) (bound : \u2200 x \u2208 Ico a b, f' x \u2264 K * f x + \u03b5) :\n  \u2200 x \u2208 Icc a b, f x \u2264 gronwall_bound \u03b4 K \u03b5 (x - a) :=\nbegin\n  have H : \u2200 x \u2208 Icc a b, \u2200 \u03b5' \u2208 Ioi \u03b5, f x \u2264 gronwall_bound \u03b4 K \u03b5' (x - a),\n  { assume x hx \u03b5' h\u03b5',\n    apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf',\n    { rwa [sub_self, gronwall_bound_x0] },\n    { exact \u03bb x, has_deriv_at_gronwall_bound_shift \u03b4 K \u03b5' x a },\n    { assume x hx hfB,\n      rw [\u2190 hfB],\n      apply lt_of_le_of_lt (bound x hx),\n      exact add_lt_add_left h\u03b5' _ },\n    { exact hx } },\n  assume x hx,\n  change f x \u2264 (\u03bb \u03b5', gronwall_bound \u03b4 K \u03b5' (x - a)) \u03b5,\n  convert continuous_within_at_const.closure_le _ _ (H x hx),\n  { simp only [closure_Ioi, left_mem_Ici] },\n  exact (gronwall_bound_continuous_\u03b5 \u03b4 K (x - a)).continuous_within_at\nend\n\n/-- A Gr\u00f6nwall-like inequality: if `f : \u211d \u2192 E` is continuous on `[a, b]`, has right derivative\n`f' x` at every point `x \u2208 [a, b)`, and satisfies the inequalities `\u2225f a\u2225 \u2264 \u03b4`,\n`\u2200 x \u2208 [a, b), \u2225f' x\u2225 \u2264 K * \u2225f x\u2225 + \u03b5`, then `\u2225f x\u2225` is bounded by `gronwall_bound \u03b4 K \u03b5 (x - a)`\non `[a, b]`. -/\ntheorem norm_le_gronwall_bound_of_norm_deriv_right_le {f f' : \u211d \u2192 E} {\u03b4 K \u03b5 : \u211d} {a b : \u211d}\n  (hf : continuous_on f (Icc a b)) (hf' : \u2200 x \u2208 Ico a b, has_deriv_within_at f (f' x) (Ici x) x)\n  (ha : \u2225f a\u2225 \u2264 \u03b4) (bound : \u2200 x \u2208 Ico a b, \u2225f' x\u2225 \u2264 K * \u2225f x\u2225 + \u03b5) :\n  \u2200 x \u2208 Icc a b, \u2225f x\u2225 \u2264 gronwall_bound \u03b4 K \u03b5 (x - a) :=\nle_gronwall_bound_of_liminf_deriv_right_le (continuous_norm.comp_continuous_on hf)\n  (\u03bb x hx r hr, (hf' x hx).liminf_right_slope_norm_le hr) ha bound\n\n/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in some time-dependent set `s t`,\nand assumes that the solutions never leave this set. -/\ntheorem dist_le_of_approx_trajectories_ODE_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g f' g' : \u211d \u2192 E} {a b : \u211d} {\u03b5f \u03b5g \u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (f' t) (Ici t) t)\n  (f_bound : \u2200 t \u2208 Ico a b, dist (f' t) (v t (f t)) \u2264 \u03b5f)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (g' t) (Ici t) t)\n  (g_bound : \u2200 t \u2208 Ico a b, dist (g' t) (v t (g t)) \u2264 \u03b5g)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 gronwall_bound \u03b4 K (\u03b5f + \u03b5g) (t - a) :=\nbegin\n  simp only [dist_eq_norm] at ha \u22a2,\n  have h_deriv : \u2200 t \u2208 Ico a b, has_deriv_within_at (\u03bb t, f t - g t) (f' t - g' t) (Ici t) t,\n    from \u03bb t ht, (hf' t ht).sub (hg' t ht),\n  apply norm_le_gronwall_bound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha,\n  assume t ht,\n  have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)),\n  rw [dist_eq_norm] at this,\n  apply le_trans this,\n  apply le_trans (add_le_add (add_le_add (f_bound t ht) (g_bound t ht))\n    (hv t (f t) (g t) (hfs t ht) (hgs t ht))),\n  rw [dist_eq_norm, add_comm]\nend\n\n/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in the whole space. -/\ntheorem dist_le_of_approx_trajectories_ODE {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g f' g' : \u211d \u2192 E} {a b : \u211d} {\u03b5f \u03b5g \u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (f' t) (Ici t) t)\n  (f_bound : \u2200 t \u2208 Ico a b, dist (f' t) (v t (f t)) \u2264 \u03b5f)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (g' t) (Ici t) t)\n  (g_bound : \u2200 t \u2208 Ico a b, dist (g' t) (v t (g t)) \u2264 \u03b5g)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 gronwall_bound \u03b4 K (\u03b5f + \u03b5g) (t - a) :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\ndist_le_of_approx_trajectories_ODE_of_mem_set (\u03bb t x y hx hy, (hv t).dist_le_mul x y)\n  hf hf' f_bound hfs hg hg' g_bound (\u03bb t ht, trivial) ha\n\n/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in some time-dependent set `s t`,\nand assumes that the solutions never leave this set. -/\ntheorem dist_le_of_trajectories_ODE_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g : \u211d \u2192 E} {a b : \u211d} {\u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 \u03b4 * exp (K * (t - a)) :=\nbegin\n  have f_bound : \u2200 t \u2208 Ico a b, dist (v t (f t)) (v t (f t)) \u2264 0,\n    by { intros, rw [dist_self] },\n  have g_bound : \u2200 t \u2208 Ico a b, dist (v t (g t)) (v t (g t)) \u2264 0,\n    by { intros, rw [dist_self] },\n  assume t ht,\n  have := dist_le_of_approx_trajectories_ODE_of_mem_set hv hf hf' f_bound hfs hg hg' g_bound\n    hgs ha t ht,\n  rwa [zero_add, gronwall_bound_\u03b50] at this,\nend\n\n/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in the whole space. -/\ntheorem dist_le_of_trajectories_ODE {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g : \u211d \u2192 E} {a b : \u211d} {\u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 \u03b4 * exp (K * (t - a)) :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\ndist_le_of_trajectories_ODE_of_mem_set (\u03bb t x y hx hy, (hv t).dist_le_mul x y)\n  hf hf' hfs hg hg' (\u03bb t ht, trivial) ha\n\n/-- There exists only one solution of an ODE \\(\\dot x=v(t, x)\\) in a set `s \u2286 \u211d \u00d7 E` with\na given initial value provided that RHS is Lipschitz continuous in `x` within `s`,\nand we consider only solutions included in `s`. -/\ntheorem ODE_solution_unique_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g : \u211d \u2192 E} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : f a = g a) :\n  \u2200 t \u2208 Icc a b, f t = g t :=\nbegin\n  assume t ht,\n  have := dist_le_of_trajectories_ODE_of_mem_set hv hf hf' hfs hg hg' hgs\n    (dist_le_zero.2 ha) t ht,\n  rwa [zero_mul, dist_le_zero] at this\nend\n\n/-- There exists only one solution of an ODE \\(\\dot x=v(t, x)\\) with\na given initial value provided that RHS is Lipschitz continuous in `x`. -/\ntheorem ODE_solution_unique {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g : \u211d \u2192 E} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (ha : f a = g a) :\n  \u2200 t \u2208 Icc a b, f t = g t :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\nODE_solution_unique_of_mem_set (\u03bb t x y hx hy, (hv t).dist_le_mul x y)\n  hf hf' hfs hg hg' (\u03bb t ht, trivial) ha\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/ODE/gronwall.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7417077687164783}}
{"text": "import data.set.basic\nopen set\n\nvariables {\u03b1 :Type} {\u03b2 : Type}\n\ndef edges (G:set \u03b1\u00d7 set \u03b2 \u00d7 (\u03b1\u2192  set \u03b2)) :set \u03b1 := G.1\ndef vertices (G:set \u03b1\u00d7 set \u03b2 \u00d7 (\u03b1\u2192  set \u03b2)) :set \u03b2  := G.2.1\ndef termini (G:set \u03b1\u00d7 set \u03b2 \u00d7 (\u03b1\u2192 set \u03b2)) :\u03b1 \u2192  set \u03b2 := G.2.2\n\ndef connects  (G:set \u03b1\u00d7 set \u03b2 \u00d7 (\u03b1\u2192  set \u03b2))  (e:\u03b1) (a:\u03b2  \u00d7 \u03b2 ):Prop:= termini G e\n={a.1,a.2}\n\ndef delete_edge (e:\u03b1) (G:set \u03b1\u00d7 set \u03b2 \u00d7 (\u03b1\u2192  set \u03b2)):set \u03b1\u00d7 set \u03b2 \u00d7 (\u03b1\u2192  set \u03b2):=\n((edges G) \\ {e}, vertices G, termini G )\n\n\ndef eulerian  :(set \u03b1\u00d7 set \u03b2 \u00d7 (\u03b1\u2192  set \u03b2))  \u2192 list \u03b1 \u2192 \u03b2 \u00d7 \u03b2 \u2192 Prop \n|G []         a :=  edges G = {} \u2227 a.1=a.2 \u2227 a.1 \u2208 vertices G\n|G (ee :: l)  a := \u2203 (c:\u03b2), ee \u2208 edges(G) \u2227  connects G ee a \n                  \u2227   eulerian (delete_edge ee G)   l (a.2,c)\n\ndef V:set \u2115 :={1,2,3,4}\n\ndef E:set \u2115 :={1,2,3,4,5,6,7}\n\ndef Ter (e:\u2115):set \u2115 :=\nmatch e with\n|1     :={1,2}\n|2     :={1,2}\n|3     :={1,4}\n|4     :={1,4}\n|5     :={1,3}\n|6     :={2,3}\n|7     :={3,4}\n|_     :={}\nend\n\ntheorem konigsberg : \u00ac (\u2203 l a b, eulerian (E,V,Ter) l (a,b)) :=\nsorry\n", "meta": {"author": "truonghoangle", "repo": "formalabstracts", "sha": "b889ec60143315053a51b1829a5dc4d82ba503b3", "save_path": "github-repos/lean/truonghoangle-formalabstracts", "path": "github-repos/lean/truonghoangle-formalabstracts/formalabstracts-b889ec60143315053a51b1829a5dc4d82ba503b3/konigsberg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7416839839525299}}
{"text": "/-\nWR Scott's Group Theory in Lean\n\nDefinitions and First Properties\n-/\n--import .preliminaries\nnamespace definitions\nvariables {A : Type}\n\n-- A group is an ordered pair (G , \u2b1d), \u2b1d is an associative binary operation on G\n-- \u2203 e \u2208 G such that\n-- (i) a \u2208 G \u2192 a \u2b1d e = a\n-- (ii) a \u2208 G -> \u2203 a\u207b\u00b9 \u2208 G, a\u207b\u00b9 \u2b1d a = e \nclass Group (A : Type) :=\n  (one : A)\n  (mul : A \u2192 A \u2192 A)\n  (inv : A \u2192 A)\n  (mul_assoc : \u2200 a b c, mul (mul a b) c = mul a (mul b c))\n  (mul_one : \u2200 a, mul a one = a) \n  (mul_inv : \u2200 a, mul a (inv a) = one)\n\npostfix \u207b\u00b9 := Group.inv \ninfix * := Group.mul\nnotation `one` := Group.one\n\nvariables [G : Group A] (a b : A)\n#check a * a\u207b\u00b9 = one\n\n-- Exercise 1.2.1\nlemma inv_mul [G : Group A] (a : A): a\u207b\u00b9 * a = one :=\ncalc  a\u207b\u00b9 * a = a\u207b\u00b9 * a * one : by rw Group.mul_one\n          ... = a\u207b\u00b9 * a * (a\u207b\u00b9 * (a\u207b\u00b9)\u207b\u00b9) : by rw Group.mul_inv\n          ... = a\u207b\u00b9 * (a * a\u207b\u00b9) * (a\u207b\u00b9)\u207b\u00b9 : by simp [\u2190Group.mul_assoc]\n          ... = a\u207b\u00b9 * one * (a\u207b\u00b9)\u207b\u00b9 : by rw Group.mul_inv\n          ... = ((a\u207b\u00b9) * (a\u207b\u00b9)\u207b\u00b9) : by simp [Group.mul_one]\n          ... = one : by rw Group.mul_inv\n\n-- Exercise 1.2.2\nlemma one_mul [G : Group A] (a : A): one * a = a :=\ncalc  one * a = a * a\u207b\u00b9 * a : by rw  Group.mul_inv\n          ... = a * one : by simp [Group.mul_assoc, inv_mul]\n          ... = a : by simp [Group.mul_one]\n\n-- this is essentially the proof strategy for Exercise 1.2.3\nlemma prod_to_inv [G : Group A] (a b c : A): a * b = c \u2194 b = a\u207b\u00b9 * c :=\nbegin\n  split,\n  intro p,\n  calc b = one * b : by rw one_mul\n        ... = a\u207b\u00b9 * a * b : by rw \u2190inv_mul\n        ... = a\u207b\u00b9 * (a * b) : by rw Group.mul_assoc\n        ... = a\u207b\u00b9 * c : by rw p,\n  intro p,\n  calc (a * b) = a * (a\u207b\u00b9 * c) : by rw \u2190p\n        ... = (a * a\u207b\u00b9) * c : by rw Group.mul_assoc\n        ... = one * c : by rw Group.mul_inv\n        ... = c : by rw one_mul,\nend\n\nlemma prod_to_inv_r [G : Group A] (a b c : A): a * b = c \u2194 a = c * b\u207b\u00b9 :=\nbegin\n  split,\n  intro p,\n  calc a = a * one : by rw Group.mul_one\n        ... = a * (b * b\u207b\u00b9) : by rw \u2190 Group.mul_inv\n        ... = (a * b) * b\u207b\u00b9: by rw Group.mul_assoc\n        ... = c * b\u207b\u00b9 : by rw p,\n  intro p,\n  calc (a * b) = c * b\u207b\u00b9 * b : by rw \u2190p\n        ... = c * (b\u207b\u00b9 * b) : by rw Group.mul_assoc\n        ... = c * one : by rw inv_mul\n        ... = c : by rw Group.mul_one,\nend\n\n-- Exercise 1.2.3\nexample [G : Group A] (a b : A) : \u2203 x, (a * x = b) :=\nbegin \n  split,\n  rw prod_to_inv,\nend\n\n-- Exercise 1.2.4\nexample [G : Group A] (a b : A) : \u2203 x, (x * a = b) :=\nbegin \n  split,\n  rw prod_to_inv_r,\nend\n\n-- Exercise 1.2.5\nexample [G : Group A] (a x : A) : a * x = a \u2194 x = one :=\nbegin\n  split,\n  intro p,\n  rw prod_to_inv at p,\n  rw inv_mul at p,\n  exact p,\n  intro p,\n  rw prod_to_inv,\n  rw inv_mul,\n  exact p,\nend\n\n-- Exercise 1.2.6\nlemma prod_one_inv [G : Group A] (a b : A) : a * b = one \u2194 b = a\u207b\u00b9 :=\nbegin\n  split,\n  intro p,\n  rw prod_to_inv at p,\n  rw Group.mul_one at p,\n  exact p,\n  intro q,\n  rw q,\n  rw Group.mul_inv,\nend\n\n-- Exercise 1.2.7\nexample [G : Group A] (a b : A) : (b\u207b\u00b9 * a\u207b\u00b9) = (a * b)\u207b\u00b9 :=\nbegin\n  rw \u2190prod_one_inv,\n  calc a * b * (b\u207b\u00b9 * a\u207b\u00b9) = a * (b * b\u207b\u00b9) * a\u207b\u00b9 : by simp [Group.mul_assoc]\n                      ... = a * one * a\u207b\u00b9 : by rw [Group.mul_inv] \n                      ... = a * a\u207b\u00b9 : by rw Group.mul_one\n                      ... = one : by rw Group.mul_inv,\nend \n\n-- Exercise 1.2.8\nlemma inv_inv [G : Group A] (a : A) : (a\u207b\u00b9)\u207b\u00b9 = a :=\n  calc  (a\u207b\u00b9)\u207b\u00b9 = (a\u207b\u00b9)\u207b\u00b9 * one : by rw Group.mul_one\n            ... = (a\u207b\u00b9)\u207b\u00b9 * (a\u207b\u00b9 * a) : by rw inv_mul\n            ... = ((a\u207b\u00b9)\u207b\u00b9 * a\u207b\u00b9) * a : by simp [Group.mul_assoc]\n            ... =  one * a : by rw inv_mul\n            ... = a : by rw one_mul\n\n-- Exercise 1.2.9\nconstant pow : \u2115 \u2192 \u2115 \u2192 \u2115\ninfix ^ := pow\naxiom pow_zero (a : \u2115) : a ^ 0 = 1\naxiom pow_succ (a b : \u2115) : a ^ (b.succ) = a ^ b * a\nlemma one_add (a b : \u2115) : 1 + a = a.succ := by rw nat.add_comm\nlemma succ_group (a b : \u2115) : (a + b).succ = a.succ + b := by admit\nexample (a b : \u2115) (r s : \u2115) : a^r * a^s = a^(r + s) :=\nbegin\n  induction r with rh r,\n  induction s with sh s,\n  rw [nat.zero_add, pow_zero, nat.mul_one],\n  rw [nat.zero_add, pow_zero, nat.one_mul],\n  calc a^rh.succ * a^s = a^rh * (a * a^s) : by rw [pow_succ, nat.mul_assoc]\n                  ... = a * (a^s * a^rh) : by rw [nat.mul_comm, nat.mul_assoc]\n                  ... = a * (a^rh * a^s) : by simp [nat.mul_comm]\n                  ... = a * a^(rh + s): by rw r\n                  ... = a^(rh + s) * a: by rw nat.mul_comm\n                  ... = a^((rh + s).succ) : by rw \u2190pow_succ\n                  ... = a^(rh.succ + s) : by rw succ_group,\nend\nend definitions", "meta": {"author": "EthanJamesLew", "repo": "group-theory-lean", "sha": "7cc60f4fa895bbfcd370de06d1da97f9d86ece3b", "save_path": "github-repos/lean/EthanJamesLew-group-theory-lean", "path": "github-repos/lean/EthanJamesLew-group-theory-lean/group-theory-lean-7cc60f4fa895bbfcd370de06d1da97f9d86ece3b/src/definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7415493853030201}}
{"text": "import Chap6\nnamespace HTPI\nset_option pp.funBinderTypes true\n\n/- Section 6.1 -/\n-- 1.\ntheorem Like_Exercise_6_1_1 :\n    \u2200 (n : Nat), 2 * Sum i from 0 to n, i = n * (n + 1) := sorry\n\n-- 2.\ntheorem Like_Exercise_6_1_4 :\n    \u2200 (n : Nat), Sum i from 0 to n, 2 * i + 1 = (n + 1) ^ 2 := sorry\n\n-- 3.\ntheorem Exercise_6_1_9a : \u2200 (n : Nat), 2 \u2223 n ^ 2 + n := sorry\n\n-- 4.\ntheorem Exercise_6_1_13 :\n    \u2200 (a b : Int) (n : Nat), (a - b) \u2223 (a ^ n - b ^ n) := sorry\n\n-- 5.\ntheorem Exercise_6_1_15 : \u2200 n \u2265 10, 2 ^ n > n ^ 3 := sorry\n\n-- 6.\ntheorem Exercise_6_1_16a1 :\n    \u2200 (n : Nat), nat_even n \u2228 nat_odd n := sorry\n\n-- 7.\ntheorem Exercise_6_1_16a2 :\n    \u2200 (n : Nat), \u00ac(nat_even n \u2227 nat_odd n) := sorry\n\n/- Section 6.2 -/\n-- 1.\nlemma Lemma_6_2_1_2_ex {A : Type} {R : BinRel A} {B : Set A} {b c : A}\n    (h1 : partial_order R) (h2 : b \u2208 B) (h3 : minimalElt R c (B \\ {b}))\n    (h4 : \u00acR b c) : minimalElt R c B := sorry\n\n-- 2.\nlemma extendPO_is_ref_ex {A : Type} (R : BinRel A) (b : A)\n    (h : partial_order R) : reflexive (extendPO R b) := sorry\n\n-- 3.\nlemma extendPO_is_trans_ex {A : Type} (R : BinRel A) (b : A)\n    (h : partial_order R) : transitive (extendPO R b) := sorry\n\n-- 4.\nlemma extendPO_is_antisymm_ex {A : Type} (R : BinRel A) (b : A)\n    (h : partial_order R) : antisymmetric (extendPO R b) := sorry\n\n-- 5.\ntheorem Exercise_6_2_3 (A : Type) (R : BinRel A)\n    (h : total_order R) : \u2200 n \u2265 1, \u2200 (B : Set A),\n    numElts B n \u2192 \u2203 (b : A), smallestElt R b B := sorry\n\n-- 6.\n--Hint:  First prove that R is reflexive\ntheorem Exercise_6_2_4a {A : Type} (R : BinRel A)\n    (h : \u2200 (x y : A), R x y \u2228 R y x) : \u2200 n \u2265 1, \u2200 (B : Set A),\n    numElts B n \u2192 \u2203 x \u2208 B, \u2200 y \u2208 B, \u2203 (z : A), R x z \u2227 R z y := sorry\n\n-- 7.\ntheorem Like_Exercise_6_2_16 (f : Nat \u2192 Nat) (h : one_to_one f) :\n    \u2200 (n : Nat) (A : Set Nat), numElts A n \u2192\n    closed f A \u2192 \u2200 y \u2208 A, \u2203 x \u2208 A, f x = y := sorry\n\n-- 8.\n--Hint:  Use Exercise_6_2_2\ntheorem Example_6_2_2 {A : Type} (R : BinRel A)\n    (h1 : \u2203 (n : Nat), numElts { x : A | x = x } n)\n    (h2 : partial_order R) : \u2203 (T : BinRel A),\n      total_order T \u2227 \u2200 (x y : A), R x y \u2192 T x y := sorry\n\n/- Section 6.3 -/\n-- 1.\ntheorem Exercise_6_3_4 : \u2200 (n : Nat),\n    3 * (Sum i from 0 to n, (2 * i + 1) ^ 2) =\n    (n + 1) * (2 * n + 1) * (2 * n + 3) := sorry\n\n-- 2.\ntheorem Exercise_6_3_7b (f : Nat \u2192 Real) (c : Real) : \u2200 (n : Nat),\n    Sum i from 0 to n, c * f i = c * Sum i from 0 to n, f i := sorry\n\n-- 3.\ntheorem fact_pos : \u2200 (n : Nat), fact n \u2265 1 := sorry\n\n-- 4.\n--Hint:  Use the theorem fact_pos from the previous exercise\ntheorem Exercise_6_3_13a (k : Nat) : \u2200 (n : Nat),\n    fact (k ^ 2 + n) \u2265 k ^ (2 * n) := sorry\n\n-- 5.\n--Hint:  Use the theorem in the previous exercise.\n--You may find it useful to first prove a lemma:\n--\u2200 (k : Nat), 2 * k ^ 2 + 1 \u2265 k\ntheorem Exercise_6_3_13b (k : Nat) : \u2200 n \u2265 2 * k ^ 2,\n    fact n \u2265 k ^ n := sorry\n\n-- 6.\ndef seq_6_3_15 (k : Nat) : Int :=\n    match k with\n      | 0 => 0\n      | n + 1 => 2 * seq_6_3_15 n + n\n\ntheorem Exercise_6_3_15 : \u2200 (n : Nat),\n    seq_6_3_15 n = 2 ^ n - n - 1 := sorry\n\n-- 7.\ndef seq_6_3_16 (k : Nat) : Nat :=\n    match k with\n      | 0 => 2\n      | n + 1 => (seq_6_3_16 n) ^ 2\n\ntheorem Exercise_6_3_16 : \u2200 (n : Nat),\n    seq_6_3_16 n = ___ := sorry\n\n/- Section 6.4 -/\n-- 1.\n--Hint: Use Exercise_6_1_16a1 and Exercise_6_1_16a2\nlemma sq_even_iff_even_ex (n : Nat) :\n    nat_even (n * n) \u2194 nat_even n := sorry\n\n-- 2.\n--This theorem proves that the square root of 6 is irrational\ntheorem Exercise_6_4_4a :\n    \u00ac\u2203 (q p : Nat), p * p = 6 * (q * q) \u2227 q \u2260 0 := sorry\n\n-- 3.\ntheorem Exercise_6_4_5 :\n    \u2200 n \u2265 12, \u2203 (a b : Nat), 3 * a + 7 * b = n := sorry\n\n-- 4.\ntheorem Exercise_6_4_7a : \u2200 (n : Nat),\n    (Sum i from 0 to n, Fib i) + 1 = Fib (n + 2) := sorry\n\n-- 5.\ntheorem Exercise_6_4_7c : \u2200 (n : Nat),\n    Sum i from 0 to n, Fib (2 * i + 1) = Fib (2 * n + 2) := sorry\n\n-- 6.\ntheorem Exercise_6_4_8a : \u2200 (m n : Nat) ,\n    Fib (m + n + 1) = Fib m * Fib n + Fib (m + 1) * Fib (n + 1) := sorry\n\n-- 7.\ntheorem Exercise_6_4_8d : \u2200 (m k : Nat), Fib m \u2223 Fib (m * k) := sorry\n\n-- 8.\ndef Fib_like (n : Nat) : Nat :=\n  match n with\n    | 0 => 1\n    | 1 => 2\n    | k + 2 => 2 * (Fib_like k) + Fib_like (k + 1)\n\ntheorem Fib_like_formula : \u2200 (n : Nat), Fib_like n = 2 ^ n := sorry\n\n-- 9.\ndef triple_rec (n : Nat) : Nat :=\n  match n with\n    | 0 => 0\n    | 1 => 2\n    | 2 => 4\n    | k + 3 => 4 * triple_rec k +\n                6 * triple_rec (k + 1) + triple_rec (k + 2)\n\ntheorem triple_rec_formula :\n    \u2200 (n : Nat), triple_rec n = 2 ^ n * Fib n := sorry\n\n-- 10.\nlemma quot_rem_unique_lemma {m q r q' r' : Nat}\n    (h1 : q * m + r = q' * m + r') (h2 : r' < m) : q \u2264 q' := sorry\n\ntheorem quot_rem_unique (m q r q' r' : Nat)\n    (h1 : q * m + r = q' * m + r') (h2 : r < m) (h3 : r' < m) :\n    q = q' \u2227 r = r' := sorry\n\n/- Section 6.5 -/\n-- 1.\ntheorem rep_image_family_base {A : Type}\n    (F : Set (A \u2192 A)) (B : Set A) : rep_image_family F 0 B = B := by rfl\n\ntheorem rep_image_family_step {A : Type}\n    (F : Set (A \u2192 A)) (n : Nat) (B : Set A) :\n    rep_image_family F (n + 1) B =\n    { x : A | \u2203 f \u2208 F, x \u2208 image f (rep_image_family F n B) } := by rfl\n\nlemma rep_image_family_sub_closed {A : Type}\n    (F : Set (A \u2192 A)) (B D : Set A)\n    (h1 : B \u2286 D) (h2 : closed_family F D) :\n    \u2200 (n : Nat), rep_image_family F n B \u2286 D := sorry\n\ntheorem Exercise_6_5_3 {A : Type} (F : Set (A \u2192 A)) (B : Set A) :\n    closure_family F B (cumul_image_family F B) := sorry\n\n-- 2.\ntheorem rep_image2_base {A : Type} (f : A \u2192 A \u2192 A) (B : Set A) :\n    rep_image2 f 0 B = B := by rfl\n\ntheorem rep_image2_step {A : Type}\n    (f : A \u2192 A \u2192 A) (n : Nat) (B : Set A) :\n    rep_image2 f (n + 1) B = image2 f (rep_image2 f n B) := by rfl\n\n--You won't be able to complete this proof\ntheorem Exercise_6_5_6 {A : Type} (f : A \u2192 A \u2192 A) (B : Set A) :\n    closed2 f (cumul_image2 f B) := sorry\n\n-- 3.\ntheorem rep_un_image2_base {A : Type} (f : A \u2192 A \u2192 A) (B : Set A) :\n    rep_un_image2 f 0 B = B := by rfl\n\ntheorem rep_un_image2_step {A : Type}\n    (f : A \u2192 A \u2192 A) (n : Nat) (B : Set A) :\n    rep_un_image2 f (n + 1) B =\n    un_image2 f (rep_un_image2 f n B) := by rfl\n\ntheorem Exercise_6_5_8a {A : Type} (f : A \u2192 A \u2192 A) (B : Set A) :\n    \u2200 (m n : Nat), m \u2264 n \u2192\n    rep_un_image2 f m B \u2286 rep_un_image2 f n B := sorry\n\nlemma rep_un_image2_sub_closed {A : Type} {f : A \u2192 A \u2192 A} {B D : Set A}\n    (h1 : B \u2286 D) (h2 : closed2 f D) :\n    \u2200 (n : Nat), rep_un_image2 f n B \u2286 D := sorry\n\nlemma closed_lemma\n    {A : Type} {f : A \u2192 A \u2192 A} {B : Set A} {x y : A} {nx ny n : Nat}\n    (h1 : x \u2208 rep_un_image2 f nx B) (h2 : y \u2208 rep_un_image2 f ny B)\n    (h3 : nx \u2264 n) (h4 : ny \u2264 n) :\n    f x y \u2208 cumul_un_image2 f B := sorry\n\ntheorem Exercise_6_5_8b {A : Type} (f : A \u2192 A \u2192 A) (B : Set A) :\n    closure2 f B (cumul_un_image2 f B) := sorry\n\n-- 4.\ntheorem rep_comp_one {A : Type} (R : Set (A \u00d7 A)) :\n    rep_comp R 1 = R := sorry\n\n-- 5.\ntheorem Exercise_6_5_11 {A : Type} (R : Set (A \u00d7 A)) :\n    \u2200 (m n : Nat), rep_comp R (m + n) =\n    comp (rep_comp R m) (rep_comp R n) := sorry\n\n-- 6.\nlemma rep_comp_sub_trans {A : Type} {R S : Set (A \u00d7 A)}\n    (h1 : R \u2286 S) (h2 : transitive (RelFromExt S)) :\n    \u2200 n \u2265 1, rep_comp R n \u2286 S := sorry\n\n-- 7.\ntheorem Exercise_6_5_14 {A : Type} (R : Set (A \u00d7 A)) :\n    smallestElt (sub (A \u00d7 A)) (cumul_comp R)\n    { S : Set (A \u00d7 A) | R \u2286 S \u2227 transitive (RelFromExt S) } := sorry", "meta": {"author": "djvelleman", "repo": "HTPILeanPackage", "sha": "b4a0ab0d0d5473ef27fbbbfba3f5d3208d5377da", "save_path": "github-repos/lean/djvelleman-HTPILeanPackage", "path": "github-repos/lean/djvelleman-HTPILeanPackage/HTPILeanPackage-b4a0ab0d0d5473ef27fbbbfba3f5d3208d5377da/Chap6Ex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.741549380967935}}
{"text": "import init.data.set\nimport set_theory.cardinal.basic\n\nopen set\n\n-- proof:\n-- First notice that B' \u2286 A. Now suppose f(B') \u2208 B, \n-- then there is X \u2286 A such that f(B') = f(X) with f(X) \u2209 X, \n-- but f is injective by assumption and so B' = X. \n-- So together with f(X) \u2209 X we get f(B') \u2209 B'. \n-- Conversely if f(B') \u2209 B' then combined with B' \u2286 A and f(B') = f(B'),\n-- we have that \u2203X [f(B') = f(X) \u2227 f(X) \u2209 X \u2227 X \u2286 A], namely X = B'. \n-- But that means that f(B') \u2208 B.\n\ntheorem cantor_injective {\u03b1 : Type} (f : set \u03b1 \u2192 \u03b1) :\n  \u00acfunction.injective f :=\nbegin \n  set B := {x : set \u03b1 | f x \u2209 x},\n  set B' := {y : \u03b1 | \u2203 x : set \u03b1, f x = y \u2227 x \u2208 B},\n  by_contradiction h,\n  by_cases hp : f(B') \u2208 B',\n  { have : \u2203 X, f(X) = f(B') \u2227 f(X) \u2209 X := mem_set_of.mp hp,\n    cases this with s hs,\n    rw \u2190 (h hs.1) at hp,\n    have hp' := hs.2,\n    contradiction, },\n  { have : f(B') \u2208 B',\n    { rw mem_set_of,\n      use B',\n      split,\n      { refl, },\n      { rw mem_set_of,\n        exact hp, }, },\n    contradiction, }\nend\n\ntheorem cantor_injective' {\u03b1 : Type} (f : set \u03b1 \u2192 \u03b1) :\n  \u00acfunction.injective f :=\nbegin\n  set B := {x : set \u03b1 | f x \u2209 x},\n  set B' := {y : \u03b1 | \u2203 x : set \u03b1, f x = y \u2227 x \u2208 B},\n  intro h,\n  by_cases hp : f B' \u2208 B',\n  { obtain \u27e8s, hs\u27e9 : \u2203 X, f X = f B' \u2227 f X \u2209 X := mem_set_of_eq.mp hp,\n    rw \u2190 (h hs.1) at hp,\n    exact hs.2 hp, },\n  { exact hp \u27e8B', rfl, hp\u27e9, }\nend", "meta": {"author": "crabbo-rave", "repo": "cantor", "sha": "2e690e45029d2d096ced1253897c200020eb5216", "save_path": "github-repos/lean/crabbo-rave-cantor", "path": "github-repos/lean/crabbo-rave-cantor/cantor-2e690e45029d2d096ced1253897c200020eb5216/src/cantor_injective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539553, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7415079394681126}}
{"text": "-- import Ints.Lemmas\nimport Sets.Basic\n\nsection Eg\n\nvariable (n m : Nat) \n\n#check n < m \n\nend Eg \n\n-- What are the natural numbers in Lean? How do we prove things about them? We \n-- will come back to these \nnamespace Nat\n\ntheorem mul_nonzero_cancel {a b c : Nat} (h : a \u2260 0) (h' : a*b = a*c) : b = c := sorry \n\ntheorem prod_eq_one { a b : Nat } (h : a*b = 1) : a = 1 \u2227 b = 1 := sorry\n\nend Nat \n\nnamespace Relations \n\nvariable { \u03b1 : Type } \n\ndef Reflexive (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop := \u2200 x, R x x \n\ndef Irreflexive (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop := \u2200 x, \u00ac R x x \n\ndef Symmetric (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop := \u2200 \u2983x y\u2984, R x y \u2192 R y x \n\ndef Asymmetric (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop := \u2200 \u2983x y\u2984, R x y \u2192 \u00ac R y x\n\ndef AntiSymmetric (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop := \u2200 \u2983x y\u2984, R x y \u2192 R y x \u2192 x = y \n\ndef Total (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop := \u2200 x y, R x y \u2228 R y x \n\ndef Transitive (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop := \u2200 \u2983x y z\u2984, R x y \u2192 R y z \u2192 R x z \n\nclass Equiv (R : \u03b1 \u2192 \u03b1 \u2192 Prop) where \n  refl : Reflexive R\n  symm : Symmetric R\n  trans : Transitive R \n\ninstance : Equiv (@Eq \u03b1) where \n  refl := Eq.refl\n  symm := @Eq.symm \u03b1 \n  trans := @Eq.trans \u03b1 \n\nclass PartialOrder (R : \u03b1 \u2192 \u03b1 \u2192 Prop) where\n  refl : Reflexive R \n  antisymm : AntiSymmetric R \n  trans : Transitive R \n\nclass TotalOrder (R : \u03b1 \u2192 \u03b1 \u2192 Prop) where \n  antisymm : AntiSymmetric R \n  total : Total R \n\ntheorem refl_not_irrefl { R : \u03b1 \u2192 \u03b1 \u2192 Prop } (a : \u03b1) (h : Reflexive R) : \u00ac Irreflexive R := \n  fun h' => h' a (h a) \n\ntheorem irrefl_not_refl { R : \u03b1 \u2192 \u03b1 \u2192 Prop } (a : \u03b1) (h : Irreflexive R) : \u00ac Reflexive R := \n  fun h' => h a (h' a) \n\n-- theorem eq_or {P : Prop} (h : P \u2228 P) : P := by cases h; repeat assumption \n\ntheorem total_refl { R : \u03b1 \u2192 \u03b1 \u2192 Prop } (h : Total R) : Reflexive R := fun a => eq_or (h a a) where \n  eq_or {P : Prop} (h : P \u2228 P) : P := by cases h; repeat assumption \n\ndef Divides (a b : Nat) : Prop := \u2203 c, b = c*a \ninfix:60 \" | \" => Divides\n\ntheorem div_refl : Reflexive Divides := by\n  intro a \n  have : a = 1*a := Eq.symm (Nat.one_mul a)\n  exists 1\n\ntheorem div_not_irrefl : \u00ac Irreflexive Divides := refl_not_irrefl 0 div_refl \n\ntheorem div_antisym : AntiSymmetric Divides := by\n  intro a b h\u2081 h\u2082 \n  have \u27e8c\u2081,h\u2081\u27e9 := h\u2081 \n  have \u27e8c\u2082,h\u2082\u27e9 := h\u2082 \n  by_cases h : a = 0\n  \u00b7 rw [h,Nat.mul_zero,\u2190h] at h\u2081 \n    exact Eq.symm h\u2081 \n  \u00b7 rw [h\u2081,\u2190Nat.mul_assoc,Nat.mul_comm] at h\u2082 \n    conv at h\u2082 => lhs ; rw [\u2190Nat.mul_one a] \n    have : 1 = c\u2082 * c\u2081 := Nat.mul_nonzero_cancel h h\u2082\n    have : c\u2081 = 1 := (Nat.prod_eq_one (Eq.symm this)).right \n    rw [this,Nat.one_mul a] at h\u2081 \n    exact Eq.symm h\u2081 \n\ntheorem div_trans : Transitive Divides := by \n  intro a b c h\u2081 h\u2082 \n  have \u27e8d\u2081,h\u2081\u27e9 := h\u2081 \n  have \u27e8d\u2082,h\u2082\u27e9 := h\u2082 \n  rw [h\u2081,\u2190Nat.mul_assoc] at h\u2082 \n  exists d\u2082*d\u2081 \n\ninstance : PartialOrder Divides where \n  refl := div_refl \n  antisymm := div_antisym\n  trans := div_trans \n\nend Relations \n", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "homework11", "sha": "9d20602c16245bce112678877635bbfa4f87dc4e", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework11", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework11/homework11-9d20602c16245bce112678877635bbfa4f87dc4e/Relations/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7415079313052954}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.metric_space.gluing\nimport topology.metric_space.hausdorff_distance\nimport topology.continuous_function.bounded\n\n/-!\n# The Gromov-Hausdorff distance is realized\n\nIn this file, we construct of a good coupling between nonempty compact metric spaces, minimizing\ntheir Hausdorff distance. This construction is instrumental to study the Gromov-Hausdorff\ndistance between nonempty compact metric spaces.\n\nGiven two nonempty compact metric spaces `X` and `Y`, we define `optimal_GH_coupling X Y` as a\ncompact metric space, together with two isometric embeddings `optimal_GH_injl` and `optimal_GH_injr`\nrespectively of `X` and `Y` into `optimal_GH_coupling X Y`. The main property of the optimal\ncoupling is that the Hausdorff distance between `X` and `Y` in `optimal_GH_coupling X Y` is smaller\nthan the corresponding distance in any other coupling. We do not prove completely this fact in this\nfile, but we show a good enough approximation of this fact in `Hausdorff_dist_optimal_le_HD`, that\nwill suffice to obtain the full statement once the Gromov-Hausdorff distance is properly defined,\nin `Hausdorff_dist_optimal`.\n\nThe key point in the construction is that the set of possible distances coming from isometric\nembeddings of `X` and `Y` in metric spaces is a set of equicontinuous functions. By Arzela-Ascoli,\nit is compact, and one can find such a distance which is minimal. This distance defines a premetric\nspace structure on `X \u2295 Y`. The corresponding metric quotient is `optimal_GH_coupling X Y`.\n-/\n\nnoncomputable theory\nopen_locale classical topology nnreal\nuniverses u v w\n\nopen classical set function topological_space filter metric quotient\nopen bounded_continuous_function\nopen sum (inl inr)\n\nlocal attribute [instance] metric_space_sum\n\nnamespace Gromov_Hausdorff\n\nsection Gromov_Hausdorff_realized\n/- This section shows that the Gromov-Hausdorff distance\nis realized. For this, we consider candidate distances on the disjoint union\n`X \u2295 Y` of two compact nonempty metric spaces, almost realizing the Gromov-Hausdorff\ndistance, and show that they form a compact family by applying Arzela-Ascoli\ntheorem. The existence of a minimizer follows. -/\n\nsection definitions\nvariables (X : Type u) (Y : Type v)\n  [metric_space X] [compact_space X] [nonempty X]\n  [metric_space Y] [compact_space Y] [nonempty Y]\n\n@[reducible] private def prod_space_fun : Type* := ((X \u2295 Y) \u00d7 (X \u2295 Y)) \u2192 \u211d\n@[reducible] private def Cb : Type* := bounded_continuous_function ((X \u2295 Y) \u00d7 (X \u2295 Y)) \u211d\n\nprivate def max_var : \u211d\u22650 :=\n2 * \u27e8diam (univ : set X), diam_nonneg\u27e9 + 1 + 2 * \u27e8diam (univ : set Y), diam_nonneg\u27e9\n\nprivate lemma one_le_max_var : 1 \u2264 max_var X Y := calc\n  (1 : real) = 2 * 0 + 1 + 2 * 0 : by simp\n  ... \u2264 2 * diam (univ : set X) + 1 + 2 * diam (univ : set Y) :\n  by apply_rules [add_le_add, mul_le_mul_of_nonneg_left, diam_nonneg]; norm_num\n\n/-- The set of functions on `X \u2295 Y` that are candidates distances to realize the\nminimum of the Hausdorff distances between `X` and `Y` in a coupling -/\ndef candidates : set (prod_space_fun X Y) :=\n  {f | (((((\u2200 x y : X, f (sum.inl x, sum.inl y) = dist x y)\n    \u2227 (\u2200 x y : Y, f (sum.inr x, sum.inr y) = dist x y))\n    \u2227 (\u2200 x y,     f (x, y) = f (y, x)))\n    \u2227 (\u2200 x y z,   f (x, z) \u2264 f (x, y) + f (y, z)))\n    \u2227 (\u2200 x,       f (x, x) = 0))\n    \u2227 (\u2200 x y,     f (x, y) \u2264 max_var X Y) }\n\n/-- Version of the set of candidates in bounded_continuous_functions, to apply\nArzela-Ascoli -/\nprivate def candidates_b : set (Cb X Y) := {f : Cb X Y | (f : _ \u2192 \u211d) \u2208 candidates X Y}\n\nend definitions --section\n\nsection constructions\n\nvariables {X : Type u} {Y : Type v}\n[metric_space X] [compact_space X] [nonempty X] [metric_space Y] [compact_space Y] [nonempty Y]\n{f : prod_space_fun X Y} {x y z t : X \u2295 Y}\nlocal attribute [instance, priority 10] inhabited_of_nonempty'\n\nprivate lemma max_var_bound : dist x y \u2264 max_var X Y := calc\n  dist x y \u2264 diam (univ : set (X \u2295 Y)) :\n    dist_le_diam_of_mem bounded_of_compact_space (mem_univ _) (mem_univ _)\n  ... = diam (range inl \u222a range inr : set (X \u2295 Y)) :\n    by rw [range_inl_union_range_inr]\n  ... \u2264 diam (range inl : set (X \u2295 Y)) + dist (inl default) (inr default) +\n          diam (range inr : set (X \u2295 Y)) :\n    diam_union (mem_range_self _) (mem_range_self _)\n  ... = diam (univ : set X) + (dist default default + 1 + dist default default) +\n          diam (univ : set Y) :\n    by { rw [isometry_inl.diam_range, isometry_inr.diam_range], refl }\n  ... = 1 * diam (univ : set X) + 1 + 1 * diam (univ : set Y) : by simp\n  ... \u2264 2 * diam (univ : set X) + 1 + 2 * diam (univ : set Y) :\n  begin\n    apply_rules [add_le_add, mul_le_mul_of_nonneg_right, diam_nonneg, le_refl],\n    norm_num, norm_num\n  end\n\nprivate lemma candidates_symm (fA : f \u2208 candidates X Y) : f (x, y) = f (y, x) := fA.1.1.1.2 x y\n\nprivate lemma candidates_triangle (fA : f \u2208 candidates X Y) : f (x, z) \u2264 f (x, y) + f (y, z) :=\n  fA.1.1.2 x y z\n\nprivate lemma candidates_refl (fA : f \u2208 candidates X Y) : f (x, x) = 0 := fA.1.2 x\n\nprivate lemma candidates_nonneg (fA : f \u2208 candidates X Y) : 0 \u2264 f (x, y) :=\nbegin\n  have : 0 \u2264 2 * f (x, y) := calc\n    0 = f (x, x) : (candidates_refl fA).symm\n    ... \u2264 f (x, y) + f (y, x) : candidates_triangle fA\n    ... = f (x, y) + f (x, y) : by rw [candidates_symm fA]\n    ... = 2 * f (x, y) : by ring,\n  by linarith\nend\n\nprivate lemma candidates_dist_inl (fA : f \u2208 candidates X Y) (x y: X) :\n  f (inl x, inl y) = dist x y :=\nfA.1.1.1.1.1 x y\n\nprivate lemma candidates_dist_inr (fA : f \u2208 candidates X Y) (x y : Y) :\n  f (inr x, inr y) = dist x y :=\nfA.1.1.1.1.2 x y\n\nprivate lemma candidates_le_max_var (fA : f \u2208 candidates X Y) : f (x, y) \u2264 max_var X Y :=\nfA.2 x y\n\n/-- candidates are bounded by `max_var X Y` -/\nprivate lemma candidates_dist_bound  (fA : f \u2208 candidates X Y) :\n  \u2200 {x y : X \u2295 Y}, f (x, y) \u2264 max_var X Y * dist x y\n| (inl x) (inl y) := calc\n    f (inl x, inl y) = dist x y : candidates_dist_inl fA x y\n    ... = dist (inl x) (inl y) : by { rw @sum.dist_eq X Y, refl }\n    ... = 1 * dist (inl x) (inl y) : by simp\n    ... \u2264 max_var X Y * dist (inl x) (inl y) :\n      mul_le_mul_of_nonneg_right (one_le_max_var X Y) dist_nonneg\n| (inl x) (inr y) := calc\n    f (inl x, inr y) \u2264 max_var X Y : candidates_le_max_var fA\n    ... = max_var X Y * 1 : by simp\n    ... \u2264 max_var X Y * dist (inl x) (inr y) :\n      mul_le_mul_of_nonneg_left sum.one_dist_le (le_trans (zero_le_one) (one_le_max_var X Y))\n| (inr x) (inl y) := calc\n    f (inr x, inl y) \u2264 max_var X Y : candidates_le_max_var fA\n    ... = max_var X Y * 1 : by simp\n    ... \u2264 max_var X Y * dist (inl x) (inr y) :\n      mul_le_mul_of_nonneg_left sum.one_dist_le (le_trans (zero_le_one) (one_le_max_var X Y))\n| (inr x) (inr y) := calc\n    f (inr x, inr y) = dist x y : candidates_dist_inr fA x y\n    ... = dist (inr x) (inr y) : by { rw @sum.dist_eq X Y, refl }\n    ... = 1 * dist (inr x) (inr y) : by simp\n    ... \u2264 max_var X Y * dist (inr x) (inr y) :\n      mul_le_mul_of_nonneg_right (one_le_max_var X Y) dist_nonneg\n\n/-- Technical lemma to prove that candidates are Lipschitz -/\nprivate lemma candidates_lipschitz_aux (fA : f \u2208 candidates X Y) :\n  f (x, y) - f (z, t) \u2264 2 * max_var X Y * dist (x, y) (z, t) :=\ncalc\n  f (x, y) - f(z, t) \u2264 f (x, t) + f (t, y) - f (z, t) : sub_le_sub_right (candidates_triangle fA) _\n  ... \u2264 (f (x, z) + f (z, t) + f(t, y)) - f (z, t) :\n    sub_le_sub_right (add_le_add_right (candidates_triangle fA) _ ) _\n  ... = f (x, z) + f (t, y) : by simp [sub_eq_add_neg, add_assoc]\n  ... \u2264 max_var X Y * dist x z + max_var X Y * dist t y :\n    add_le_add (candidates_dist_bound fA) (candidates_dist_bound fA)\n  ... \u2264 max_var X Y * max (dist x z) (dist t y) + max_var X Y * max (dist x z) (dist t y) :\n  begin\n    apply add_le_add,\n    apply mul_le_mul_of_nonneg_left (le_max_left (dist x z) (dist t y))\n      (zero_le_one.trans (one_le_max_var X Y)),\n    apply mul_le_mul_of_nonneg_left (le_max_right (dist x z) (dist t y))\n      (zero_le_one.trans (one_le_max_var X Y)),\n  end\n  ... = 2 * max_var X Y * max (dist x z) (dist y t) :\n    by { simp [dist_comm], ring }\n  ... = 2 * max_var X Y * dist (x, y) (z, t) : by refl\n\n/-- Candidates are Lipschitz -/\nprivate lemma candidates_lipschitz (fA : f \u2208 candidates X Y) :\n  lipschitz_with (2 * max_var X Y) f :=\nbegin\n  apply lipschitz_with.of_dist_le_mul,\n  rintros \u27e8x, y\u27e9 \u27e8z, t\u27e9,\n  rw [real.dist_eq, abs_sub_le_iff],\n  use candidates_lipschitz_aux fA,\n  rw [dist_comm],\n  exact candidates_lipschitz_aux fA\nend\n\n/-- candidates give rise to elements of bounded_continuous_functions -/\ndef candidates_b_of_candidates (f : prod_space_fun X Y) (fA : f \u2208 candidates X Y) : Cb X Y :=\nbounded_continuous_function.mk_of_compact \u27e8f, (candidates_lipschitz fA).continuous\u27e9\n\nlemma candidates_b_of_candidates_mem (f : prod_space_fun X Y) (fA : f \u2208 candidates X Y) :\n  candidates_b_of_candidates f fA \u2208 candidates_b X Y := fA\n\n/-- The distance on `X \u2295 Y` is a candidate -/\nprivate lemma dist_mem_candidates : (\u03bbp : (X \u2295 Y) \u00d7 (X \u2295 Y), dist p.1 p.2) \u2208 candidates X Y :=\nbegin\n  simp only [candidates, dist_comm, forall_const, and_true, add_comm, eq_self_iff_true,\n             and_self, sum.forall, set.mem_set_of_eq, dist_self],\n  repeat { split\n    <|> exact (\u03bba y z, dist_triangle_left _ _ _)\n    <|> exact (\u03bbx y, by refl)\n    <|> exact (\u03bbx y, max_var_bound) }\nend\n\n/-- The distance on `X \u2295 Y` as a candidate -/\ndef candidates_b_dist (X : Type u) (Y : Type v) [metric_space X] [compact_space X] [inhabited X]\n  [metric_space Y] [compact_space Y] [inhabited Y] : Cb X Y :=\ncandidates_b_of_candidates _ dist_mem_candidates\n\nlemma candidates_b_dist_mem_candidates_b : candidates_b_dist X Y \u2208 candidates_b X Y :=\ncandidates_b_of_candidates_mem _ _\n\nprivate lemma candidates_b_nonempty : (candidates_b X Y).nonempty :=\n\u27e8_,  candidates_b_dist_mem_candidates_b\u27e9\n\n/-- To apply Arzela-Ascoli, we need to check that the set of candidates is closed and\nequicontinuous. Equicontinuity follows from the Lipschitz control, we check closedness. -/\nprivate lemma closed_candidates_b : is_closed (candidates_b X Y) :=\nbegin\n  have I1 : \u2200 x y, is_closed {f : Cb X Y | f (inl x, inl y) = dist x y} :=\n    \u03bbx y, is_closed_eq continuous_eval_const continuous_const,\n  have I2 : \u2200 x y, is_closed {f : Cb X Y | f (inr x, inr y) = dist x y } :=\n    \u03bbx y, is_closed_eq continuous_eval_const continuous_const,\n  have I3 : \u2200 x y, is_closed {f : Cb X Y | f (x, y) = f (y, x)} :=\n    \u03bbx y, is_closed_eq continuous_eval_const continuous_eval_const,\n  have I4 : \u2200 x y z, is_closed {f : Cb X Y | f (x, z) \u2264 f (x, y) + f (y, z)} :=\n    \u03bbx y z, is_closed_le continuous_eval_const (continuous_eval_const.add continuous_eval_const),\n  have I5 : \u2200 x, is_closed {f : Cb X Y | f (x, x) = 0} :=\n    \u03bbx, is_closed_eq continuous_eval_const continuous_const,\n  have I6 : \u2200 x y, is_closed {f : Cb X Y | f (x, y) \u2264 max_var X Y} :=\n    \u03bbx y, is_closed_le continuous_eval_const continuous_const,\n  have : candidates_b X Y = (\u22c2x y, {f : Cb X Y | f ((@inl X Y x), (@inl X Y y)) = dist x y})\n               \u2229 (\u22c2x y, {f : Cb X Y | f ((@inr X Y x), (@inr X Y y)) = dist x y})\n               \u2229 (\u22c2x y, {f : Cb X Y | f (x, y) = f (y, x)})\n               \u2229 (\u22c2x y z, {f : Cb X Y | f (x, z) \u2264 f (x, y) + f (y, z)})\n               \u2229 (\u22c2x, {f : Cb X Y | f (x, x) = 0})\n               \u2229 (\u22c2x y, {f : Cb X Y | f (x, y) \u2264 max_var X Y}),\n  { ext, simp only [candidates_b, candidates, mem_inter_iff, mem_Inter, mem_set_of_eq] },\n  rw this,\n  repeat { apply is_closed.inter _ _\n       <|> apply is_closed_Inter _\n       <|> apply I1 _ _\n       <|> apply I2 _ _\n       <|> apply I3 _ _\n       <|> apply I4 _ _ _\n       <|> apply I5 _\n       <|> apply I6 _ _\n       <|> assume x },\nend\n\n/-- Compactness of candidates (in bounded_continuous_functions) follows. -/\nprivate lemma is_compact_candidates_b : is_compact (candidates_b X Y) :=\nbegin\n  refine arzela_ascoli\u2082 (Icc 0 (max_var X Y)) is_compact_Icc (candidates_b X Y)\n  closed_candidates_b _ _,\n  { rintros f \u27e8x1, x2\u27e9 hf,\n    simp only [set.mem_Icc],\n    exact \u27e8candidates_nonneg hf, candidates_le_max_var hf\u27e9 },\n  { refine equicontinuous_of_continuity_modulus (\u03bbt, 2 * max_var X Y * t) _ _ _,\n    { have : tendsto (\u03bb (t : \u211d), 2 * (max_var X Y : \u211d) * t) (\ud835\udcdd 0) (\ud835\udcdd (2 * max_var X Y * 0)) :=\n        tendsto_const_nhds.mul tendsto_id,\n      simpa using this },\n    { rintros x y \u27e8f, hf\u27e9,\n      exact (candidates_lipschitz hf).dist_le_mul _ _ } }\nend\n\n/-- We will then choose the candidate minimizing the Hausdorff distance. Except that we are not\nin a metric space setting, so we need to define our custom version of Hausdorff distance,\ncalled HD, and prove its basic properties. -/\ndef HD (f : Cb X Y) := max (\u2a06 x, \u2a05 y, f (inl x, inr y)) (\u2a06 y, \u2a05 x, f (inl x, inr y))\n\n/- We will show that HD is continuous on bounded_continuous_functions, to deduce that its\nminimum on the compact set candidates_b is attained. Since it is defined in terms of\ninfimum and supremum on `\u211d`, which is only conditionnally complete, we will need all the time\nto check that the defining sets are bounded below or above. This is done in the next few\ntechnical lemmas -/\n\nlemma HD_below_aux1 {f : Cb X Y} (C : \u211d) {x : X} :\n  bdd_below (range (\u03bb (y : Y), f (inl x, inr y) + C)) :=\nlet \u27e8cf, hcf\u27e9 := (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 in\n\u27e8cf + C, forall_range_iff.2 (\u03bbi, add_le_add_right ((\u03bbx, hcf (mem_range_self x)) _) _)\u27e9\n\nprivate lemma HD_bound_aux1 (f : Cb X Y) (C : \u211d) :\n  bdd_above (range (\u03bb (x : X), \u2a05 y, f (inl x, inr y) + C)) :=\nbegin\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).2 with \u27e8Cf, hCf\u27e9,\n  refine \u27e8Cf + C, forall_range_iff.2 (\u03bbx, _)\u27e9,\n  calc (\u2a05 y, f (inl x, inr y) + C) \u2264 f (inl x, inr default) + C :\n    cinfi_le (HD_below_aux1 C) default\n    ... \u2264 Cf + C : add_le_add ((\u03bbx, hCf (mem_range_self x)) _) le_rfl\nend\n\nlemma HD_below_aux2 {f : Cb X Y} (C : \u211d) {y : Y} :\n  bdd_below (range (\u03bb (x : X), f (inl x, inr y) + C)) :=\nlet \u27e8cf, hcf\u27e9 := (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 in\n\u27e8cf + C, forall_range_iff.2 (\u03bbi, add_le_add_right ((\u03bbx, hcf (mem_range_self x)) _) _)\u27e9\n\nprivate lemma HD_bound_aux2 (f : Cb X Y) (C : \u211d) :\n  bdd_above (range (\u03bb (y : Y), \u2a05 x, f (inl x, inr y) + C)) :=\nbegin\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).2 with \u27e8Cf, hCf\u27e9,\n  refine \u27e8Cf + C, forall_range_iff.2 (\u03bby, _)\u27e9,\n  calc (\u2a05 x, f (inl x, inr y) + C) \u2264 f (inl default, inr y) + C :\n    cinfi_le (HD_below_aux2 C) default\n  ... \u2264 Cf + C : add_le_add ((\u03bbx, hCf (mem_range_self x)) _) le_rfl\nend\n\n/-- Explicit bound on `HD (dist)`. This means that when looking for minimizers it will\nbe sufficient to look for functions with `HD(f)` bounded by this bound. -/\nlemma HD_candidates_b_dist_le :\n  HD (candidates_b_dist X Y) \u2264 diam (univ : set X) + 1 + diam (univ : set Y) :=\nbegin\n  refine max_le (csupr_le (\u03bbx, _)) (csupr_le (\u03bby, _)),\n  { have A : (\u2a05 y, candidates_b_dist X Y (inl x, inr y)) \u2264\n      candidates_b_dist X Y (inl x, inr default) :=\n      cinfi_le (by simpa using HD_below_aux1 0) default,\n    have B : dist (inl x) (inr default) \u2264 diam (univ : set X) + 1 + diam (univ : set Y) := calc\n      dist (inl x) (inr (default : Y)) = dist x (default : X) + 1 + dist default default : rfl\n      ... \u2264 diam (univ : set X) + 1 + diam (univ : set Y) :\n      begin\n        apply add_le_add (add_le_add _ le_rfl),\n        exact dist_le_diam_of_mem bounded_of_compact_space (mem_univ _) (mem_univ _),\n        any_goals { exact ordered_add_comm_monoid.to_covariant_class_left \u211d },\n        any_goals { exact ordered_add_comm_monoid.to_covariant_class_right \u211d },\n        exact dist_le_diam_of_mem bounded_of_compact_space (mem_univ _) (mem_univ _),\n      end,\n    exact le_trans A B },\n  { have A : (\u2a05 x, candidates_b_dist X Y (inl x, inr y)) \u2264\n      candidates_b_dist X Y (inl default, inr y) :=\n      cinfi_le (by simpa using HD_below_aux2 0) default,\n    have B : dist (inl default) (inr y) \u2264 diam (univ : set X) + 1 + diam (univ : set Y) := calc\n      dist (inl (default : X)) (inr y) = dist default default + 1 + dist default y : rfl\n      ... \u2264 diam (univ : set X) + 1 + diam (univ : set Y) :\n      begin\n        apply add_le_add (add_le_add _ le_rfl),\n        exact dist_le_diam_of_mem bounded_of_compact_space (mem_univ _) (mem_univ _),\n        any_goals { exact ordered_add_comm_monoid.to_covariant_class_left \u211d },\n        any_goals { exact ordered_add_comm_monoid.to_covariant_class_right \u211d },\n        exact dist_le_diam_of_mem bounded_of_compact_space (mem_univ _) (mem_univ _)\n      end,\n    exact le_trans A B },\nend\n\n/- To check that HD is continuous, we check that it is Lipschitz. As HD is a max, we\nprove separately inequalities controlling the two terms (relying too heavily on copy-paste...) -/\nprivate lemma HD_lipschitz_aux1 (f g : Cb X Y) :\n  (\u2a06 x, \u2a05 y, f (inl x, inr y)) \u2264 (\u2a06 x, \u2a05 y, g (inl x, inr y)) + dist f g :=\nbegin\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 g.bounded_range).1 with \u27e8cg, hcg\u27e9,\n  have Hcg : \u2200 x, cg \u2264 g x := \u03bbx, hcg (mem_range_self x),\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 with \u27e8cf, hcf\u27e9,\n  have Hcf : \u2200 x, cf \u2264 f x := \u03bbx, hcf (mem_range_self x),\n\n  -- prove the inequality but with `dist f g` inside, by using inequalities comparing\n  -- supr to supr and infi to infi\n  have Z : (\u2a06 x, \u2a05 y, f (inl x, inr y)) \u2264 \u2a06 x, \u2a05 y, g (inl x, inr y) + dist f g :=\n    csupr_mono (HD_bound_aux1 _ (dist f g))\n      (\u03bbx, cinfi_mono \u27e8cf, forall_range_iff.2(\u03bbi, Hcf _)\u27e9 (\u03bby, coe_le_coe_add_dist)),\n  -- move the `dist f g` out of the infimum and the supremum, arguing that continuous monotone maps\n  -- (here the addition of `dist f g`) preserve infimum and supremum\n  have E1 : \u2200 x, (\u2a05 y, g (inl x, inr y)) + dist f g = \u2a05 y, g (inl x, inr y) + dist f g,\n  { assume x,\n    refine monotone.map_cinfi_of_continuous_at (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { show bdd_below (range (\u03bb (y : Y), g (inl x, inr y))),\n        from \u27e8cg, forall_range_iff.2(\u03bbi, Hcg _)\u27e9 } },\n  have E2 : (\u2a06 x, \u2a05 y, g (inl x, inr y)) + dist f g = \u2a06 x, (\u2a05 y, g (inl x, inr y)) + dist f g,\n  { refine monotone.map_csupr_of_continuous_at (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { simpa using HD_bound_aux1 _ 0 } },\n  -- deduce the result from the above two steps\n  simpa [E2, E1, function.comp]\nend\n\nprivate lemma HD_lipschitz_aux2 (f g : Cb X Y) :\n  (\u2a06 y, \u2a05 x, f (inl x, inr y)) \u2264 (\u2a06 y, \u2a05 x, g (inl x, inr y)) + dist f g :=\nbegin\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 g.bounded_range).1 with \u27e8cg, hcg\u27e9,\n  have Hcg : \u2200 x, cg \u2264 g x := \u03bbx, hcg (mem_range_self x),\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 with \u27e8cf, hcf\u27e9,\n  have Hcf : \u2200 x, cf \u2264 f x := \u03bbx, hcf (mem_range_self x),\n\n  -- prove the inequality but with `dist f g` inside, by using inequalities comparing\n  -- supr to supr and infi to infi\n  have Z : (\u2a06 y, \u2a05 x, f (inl x, inr y)) \u2264 \u2a06 y, \u2a05 x, g (inl x, inr y) + dist f g :=\n    csupr_mono (HD_bound_aux2 _ (dist f g))\n      (\u03bby, cinfi_mono  \u27e8cf, forall_range_iff.2(\u03bbi, Hcf _)\u27e9 (\u03bby, coe_le_coe_add_dist)),\n  -- move the `dist f g` out of the infimum and the supremum, arguing that continuous monotone maps\n  -- (here the addition of `dist f g`) preserve infimum and supremum\n  have E1 : \u2200 y, (\u2a05 x, g (inl x, inr y)) + dist f g = \u2a05 x, g (inl x, inr y) + dist f g,\n  { assume y,\n    refine monotone.map_cinfi_of_continuous_at (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { show bdd_below (range (\u03bbx:X, g (inl x, inr y))),\n        from \u27e8cg, forall_range_iff.2 (\u03bbi, Hcg _)\u27e9 } },\n  have E2 : (\u2a06 y, \u2a05 x, g (inl x, inr y)) + dist f g = \u2a06 y, (\u2a05 x, g (inl x, inr y)) + dist f g,\n  { refine monotone.map_csupr_of_continuous_at (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { simpa using HD_bound_aux2 _ 0 } },\n  -- deduce the result from the above two steps\n  simpa [E2, E1]\nend\n\nprivate lemma HD_lipschitz_aux3 (f g : Cb X Y) : HD f \u2264 HD g + dist f g :=\nmax_le (le_trans (HD_lipschitz_aux1 f g) (add_le_add_right (le_max_left _ _) _))\n       (le_trans (HD_lipschitz_aux2 f g) (add_le_add_right (le_max_right _ _) _))\n\n/-- Conclude that HD, being Lipschitz, is continuous -/\nprivate lemma HD_continuous : continuous (HD : Cb X Y \u2192 \u211d) :=\nlipschitz_with.continuous (lipschitz_with.of_le_add HD_lipschitz_aux3)\n\nend constructions --section\n\nsection consequences\nvariables (X : Type u) (Y : Type v) [metric_space X] [compact_space X] [nonempty X] [metric_space Y]\n  [compact_space Y] [nonempty Y]\n\n/- Now that we have proved that the set of candidates is compact, and that HD is continuous,\nwe can finally select a candidate minimizing HD. This will be the candidate realizing the\noptimal coupling. -/\nprivate lemma exists_minimizer : \u2203 f \u2208 candidates_b X Y, \u2200 g \u2208 candidates_b X Y, HD f \u2264 HD g :=\nis_compact_candidates_b.exists_forall_le candidates_b_nonempty HD_continuous.continuous_on\n\nprivate definition optimal_GH_dist : Cb X Y := classical.some (exists_minimizer X Y)\n\nprivate lemma optimal_GH_dist_mem_candidates_b : optimal_GH_dist X Y \u2208 candidates_b X Y :=\nby cases (classical.some_spec (exists_minimizer X Y)); assumption\n\nprivate lemma HD_optimal_GH_dist_le (g : Cb X Y) (hg : g \u2208 candidates_b X Y) :\n  HD (optimal_GH_dist X Y) \u2264 HD g :=\nlet \u27e8Z1, Z2\u27e9 := classical.some_spec (exists_minimizer X Y) in Z2 g hg\n\n/-- With the optimal candidate, construct a premetric space structure on `X \u2295 Y`, on which the\npredistance is given by the candidate. Then, we will identify points at `0` predistance\nto obtain a genuine metric space -/\ndef premetric_optimal_GH_dist : pseudo_metric_space (X \u2295 Y) :=\n{ dist := \u03bbp q, optimal_GH_dist X Y (p, q),\n  dist_self := \u03bbx, candidates_refl (optimal_GH_dist_mem_candidates_b X Y),\n  dist_comm := \u03bbx y, candidates_symm (optimal_GH_dist_mem_candidates_b X Y),\n  dist_triangle := \u03bbx y z, candidates_triangle (optimal_GH_dist_mem_candidates_b X Y) }\n\nlocal attribute [instance] premetric_optimal_GH_dist\n\n/-- A metric space which realizes the optimal coupling between `X` and `Y` -/\n@[derive metric_space, nolint has_nonempty_instance]\ndefinition optimal_GH_coupling : Type* :=\n@uniform_space.separation_quotient (X \u2295 Y) (premetric_optimal_GH_dist X Y).to_uniform_space\n\n/-- Injection of `X` in the optimal coupling between `X` and `Y` -/\ndef optimal_GH_injl (x : X) : optimal_GH_coupling X Y := quotient.mk' (inl x)\n\n/-- The injection of `X` in the optimal coupling between `X` and `Y` is an isometry. -/\nlemma isometry_optimal_GH_injl : isometry (optimal_GH_injl X Y) :=\nisometry.of_dist_eq $ \u03bb x y, candidates_dist_inl (optimal_GH_dist_mem_candidates_b X Y) _ _\n\n/-- Injection of `Y` in the optimal coupling between `X` and `Y` -/\ndef optimal_GH_injr (y : Y) : optimal_GH_coupling X Y := quotient.mk' (inr y)\n\n/-- The injection of `Y` in the optimal coupling between `X` and `Y` is an isometry. -/\nlemma isometry_optimal_GH_injr : isometry (optimal_GH_injr X Y) :=\nisometry.of_dist_eq $ \u03bb x y, candidates_dist_inr (optimal_GH_dist_mem_candidates_b X Y) _ _\n\n/-- The optimal coupling between two compact spaces `X` and `Y` is still a compact space -/\ninstance compact_space_optimal_GH_coupling : compact_space (optimal_GH_coupling X Y) :=\n\u27e8begin\n  rw [\u2190 range_quotient_mk'],\n  exact is_compact_range (continuous_sum_dom.2 \u27e8(isometry_optimal_GH_injl X Y).continuous,\n    (isometry_optimal_GH_injr X Y).continuous\u27e9)\nend\u27e9\n\n/-- For any candidate `f`, `HD(f)` is larger than or equal to the Hausdorff distance in the\noptimal coupling. This follows from the fact that HD of the optimal candidate is exactly\nthe Hausdorff distance in the optimal coupling, although we only prove here the inequality\nwe need. -/\nlemma Hausdorff_dist_optimal_le_HD {f} (h : f \u2208 candidates_b X Y) :\n  Hausdorff_dist (range (optimal_GH_injl X Y)) (range (optimal_GH_injr X Y)) \u2264 HD f :=\nbegin\n  refine le_trans (le_of_forall_le_of_dense (\u03bb r hr, _)) (HD_optimal_GH_dist_le X Y f h),\n  have A : \u2200 x \u2208 range (optimal_GH_injl X Y), \u2203 y \u2208 range (optimal_GH_injr X Y), dist x y \u2264 r,\n  { rintro _ \u27e8z, rfl\u27e9,\n    have I1 : (\u2a06 x, \u2a05 y, optimal_GH_dist X Y (inl x, inr y)) < r :=\n      lt_of_le_of_lt (le_max_left _ _) hr,\n    have I2 : (\u2a05 y, optimal_GH_dist X Y (inl z, inr y)) \u2264\n        \u2a06 x, \u2a05 y, optimal_GH_dist X Y (inl x, inr y) :=\n      le_cSup (by simpa using HD_bound_aux1 _ 0) (mem_range_self _),\n    have I : (\u2a05 y, optimal_GH_dist X Y (inl z, inr y)) < r := lt_of_le_of_lt I2 I1,\n    rcases exists_lt_of_cInf_lt (range_nonempty _) I with \u27e8r', \u27e8z', rfl\u27e9, hr'\u27e9,\n    exact \u27e8optimal_GH_injr X Y z', mem_range_self _, le_of_lt hr'\u27e9 },\n  refine Hausdorff_dist_le_of_mem_dist _ A _,\n  { inhabit X,\n    rcases A _ (mem_range_self default) with \u27e8y, -, hy\u27e9,\n    exact le_trans dist_nonneg hy },\n  { rintro _ \u27e8z, rfl\u27e9,\n    have I1 : (\u2a06 y, \u2a05 x, optimal_GH_dist X Y (inl x, inr y)) < r :=\n      lt_of_le_of_lt (le_max_right _ _) hr,\n    have I2 : (\u2a05 x, optimal_GH_dist X Y (inl x, inr z)) \u2264\n        \u2a06 y, \u2a05 x, optimal_GH_dist X Y (inl x, inr y) :=\n      le_cSup (by simpa using HD_bound_aux2 _ 0) (mem_range_self _),\n    have I : (\u2a05 x, optimal_GH_dist X Y (inl x, inr z)) < r := lt_of_le_of_lt I2 I1,\n    rcases exists_lt_of_cInf_lt (range_nonempty _) I with \u27e8r', \u27e8z', rfl\u27e9, hr'\u27e9,\n    refine \u27e8optimal_GH_injl X Y z', mem_range_self _, le_of_lt _\u27e9,\n    rwa dist_comm }\nend\n\nend consequences\n/- We are done with the construction of the optimal coupling -/\nend Gromov_Hausdorff_realized\n\nend Gromov_Hausdorff\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/metric_space/gromov_hausdorff_realized.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320035, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7415079198083406}}
{"text": "-- Calcular el n-\u00e9simo n\u00famero primo.\n\nimport data.nat.prime\nopen nat\n\ndef ith_prime : \u2115 \u2192 \u2115\n| 0       := 2\n| (i + 1) := nat.find (exists_infinite_primes $ ith_prime i + 1)\n\n-- #eval ith_prime 4\n\n-- Ver https://bit.ly/3aV0Vhs\n\n-- ------------------------------------------------------------------------\n\ndef find_prime : \u2115 \u2192 \u2115 \u2192 \u2115\n| 0 n     := 0\n| (i+1) n := by haveI := decidable_prime_1 n;\n                exact if nat.prime n then n else find_prime i (n+1)\n\ndef ith_prime2 : \u2115 \u2192 \u2115\n| 0 := 2\n| (i + 1) := let n := ith_prime2 i in find_prime n (n+1)\n\nexample : ith_prime2 4 = 11 := dec_trivial\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/N-esimo_primo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810525948928, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.7414796079396463}}
{"text": "/-\nCopyright (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\nExamples from the tutorial.\n-/\nimport tactic.finish\nopen auto\n\nsection\nvariables p q r s : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := by finish\nexample : p \u2228 q \u2194 q \u2228 p := by finish\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := by finish\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := by finish\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by finish [iff_def]\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := by finish [iff_def]\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := by finish [iff_def]\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := by finish [iff_def]\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := by finish\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := by finish\nexample : \u00ac(p \u2227 \u00ac p) := by finish\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := by finish\nexample : \u00acp \u2192 (p \u2192 q) := by finish\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := by finish\nexample : p \u2228 false \u2194 p := by finish\nexample : p \u2227 false \u2194 false := by finish\nexample : \u00ac(p \u2194 \u00acp) := by finish\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := by finish\n\n-- these require classical reasoning\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := by finish\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := by finish\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := by finish\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := by finish\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := by finish\nexample : p \u2228 \u00acp := by finish\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := by finish\nend\n\n\nsection\n\nvariables (A : Type) (p q : A \u2192 Prop)\nvariable a : A\nvariable r : Prop\n\nexample : (\u2203 x : A, r) \u2192 r := by finish\n-- TODO(Jeremy): can we get these automatically?\nexample (a : A) : r \u2192 (\u2203 x : A, r) := begin safe; apply a_2; assumption end\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := by finish\n\ntheorem foo': (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\nby finish [iff_def]\n\nexample (h : \u2200 x, \u00ac \u00ac p x) : p a := by finish\nexample (h : \u2200 x, \u00ac \u00ac p x) : \u2200 x, p x := by finish\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := by finish\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := by finish\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) := by finish\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := by finish\nexample : (\u2203 x, \u00ac p x) \u2192 (\u00ac \u2200 x, p x) := by finish\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := by finish [iff_def]\n-- TODO(Jeremy): can we get these automatically?\nexample (a : A) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := begin safe [iff_def]; exact h a end\nexample (a : A) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := begin safe [iff_def]; exact h a end\n\nexample : (\u2203 x, p x \u2192 r) \u2192 (\u2200 x, p x) \u2192 r := by finish\nexample : (\u2203 x, r \u2192 p x) \u2192 (r \u2192 \u2203 x, p x) := by finish\n\nend\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/tests/finish3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7414775755342544}}
{"text": "open list\n\n-- Exercise: 1 star (snd_fst_is_swap)\ndef swap : \u2115 \u00d7 \u2115 \u2192 \u2115 \u00d7 \u2115\n| (a, b) := (b, a) \n\nlemma snd_fst_is_swap : \u2200 p : \u2115 \u00d7 \u2115, (p.snd, p.fst) = swap p\n| (a, b) := rfl \n\n-- Exercise: 1 star, optional (fst_swap_is_snd)\ntheorem fst_swap_is_snd : \u2200 p : \u2115 \u00d7 \u2115, (swap p).fst = p.snd\n| (a, b) := rfl\n\n-- Exercise: 2 stars, recommended (list_funs)\ndef nonzeros : list \u2115 \u2192 list \u2115\n| nil := nil  \n| (cons x xs) := if x \u2260 0 then [x] ++ nonzeros xs else nonzeros xs\n\nlemma test_nonzeros : nonzeros [0, 1, 0, 2, 3, 0, 0] = [1, 2, 3] := rfl\n\ndef oddmembers : list \u2115 \u2192 list \u2115\n| nil := nil\n| (cons x xs) := if nat.bodd x then [x] ++ oddmembers xs else oddmembers xs\n\nlemma test_oddmembers : oddmembers [0, 1, 0, 2, 3, 0, 0] = [1, 3] := rfl\n\ndef countoddmembers (l : list \u2115) : \u2115 := length (oddmembers l)\n\nlemma test_countoddmembers1 : countoddmembers [1, 0, 3, 1, 4, 5] = 4 := rfl\nlemma test_countoddmembers2 : countoddmembers [0, 2, 4] = 0 := rfl \nlemma test_countoddmembers3 : countoddmembers nil = 0 := rfl\n\n-- Exercise: 3 stars, advanced (alternate)\ndef alternate : list \u2115 \u2192 list \u2115 \u2192 list \u2115 \n| [] [] := []\n| [] (y :: ys) := [y] ++ alternate [] ys\n| (x :: xs) [] := [x] ++ alternate xs [] \n| (x :: xs) (y :: ys) := [x, y] ++ alternate xs ys\n\nlemma test_alternate1 : alternate [1,2,3] [4,5,6] = [1,4,2,5,3,6] := rfl\nlemma test_alternate2 : alternate [1] [4, 5, 6] = [1,4,5,6] := rfl\nlemma test_alternate3 : alternate [1,2,3] [4] = [1,4,2,3] := rfl\nlemma test_alternate4 : alternate [] [20,30] = [20, 30] := rfl\n\n-- Exercise: 3 stars, recommended (bag_functions)\ndef bag : Type := list \u2115\n\ndef count : \u2115 \u2192 bag \u2192 \u2115\n| n [] := 0\n| n (x::xs) := if x = n then 1 + count n xs else count n xs \n\nlemma test_count1 : count 1 [1,2,3,1,4,1] = 3 := rfl\nlemma test_count2 : count 6 [1,2,3,1,4,1] = 0 := rfl\n\ndef bag.sum : bag \u2192 bag \u2192 bag := \u03bb a b, @list.append \u2115 a b\n\nlemma test_sum1 : count 1 (bag.sum [1,2,3] [1,4,1]) = 3 := rfl\n\ndef bag.add : \u2115 \u2192 bag \u2192 bag := \u03bb a b, list.append b [a]\n\nlemma test_add1 : count 1 (bag.add 1 [1,4,1]) = 3 := rfl\nlemma test_add2 : count 5 (bag.add 1 [1,4,1]) = 0 := rfl \n\ndef bag.mem : \u2115 \u2192 bag \u2192 bool \n| n [] := ff\n| n (x::xs) := if n = x then tt else bag.mem n xs\n\nlemma test_mem1 : bag.mem 1 [1,4,1] = tt := rfl \nlemma test_mem2 : bag.mem 2 [1,4,1] = ff := rfl\n\n-- Exercise: 3 stars, optional (bag_more_functions)\ndef remove_one : \u2115 \u2192 bag \u2192 bag \n| n [] := [] \n| n (x::xs) := if n = x then xs else x :: (remove_one n xs)\n\nlemma test_remove_one1 : count 5 (remove_one 5 [2,1,5,4,1]) = 0 := rfl\nlemma test_remove_one2 : count 5 (remove_one 5 [2,1,4,1]) = 0 := rfl \nlemma test_remove_one3 : count 4 (remove_one 5 [2,1,4,5,1,4]) = 2 :=  rfl  \nlemma test_remove_one4 : count 5 (remove_one 5 [2,1,5,4,5,1,4]) = 1 := rfl\n\ndef remove_all : \u2115 \u2192 bag \u2192 bag\n| n [] := []\n| n (x::xs) := if n = x then remove_all n xs else x :: remove_all n xs\n\nlemma test_remove_all1 : count 5 (remove_all 5 [2,1,5,4,1]) = 0 := rfl \nlemma test_remove_all2 : count 5 (remove_all 5 [2,1,4,1]) = 0 := rfl\nlemma test_remove_all3 : count 4 (remove_all 5 [2,1,4,5,1,4]) = 2 := rfl \nlemma test_remove_all4 : \n  count 5 (remove_all 5 [2,1,5,4,5,1,4,5,1,4]) = 0 := rfl \n\ndef bag.subset : bag \u2192 bag \u2192 bool\n| [] [] := tt\n| [] (y::ys) := tt \n| (x::xs) [] := ff\n| (x::xs) y := if bag.mem x y then bag.subset xs (remove_one x y) else ff\n\nlemma test_subset1 : bag.subset [1,2] [2,1,4,1] = tt := rfl   \nlemma test_subset2 : bag.subset [1,2,2] [2,1,4,1] = ff := rfl \n\n-- Exercise: 4 stars, advanced (rev_injective)\ndef rev : list \u2115 \u2192 list \u2115 \n| nil := nil\n| (x::xs) := (rev xs) ++ [x]\n\nlemma test_rev1 : rev [3,2,1] = [1,2,3] := rfl\nlemma test_rev2 : rev [] = [] := rfl \n\nlemma rev_step : \u2200 (hd : \u2115) (tl : list \u2115), rev (hd :: tl) = rev tl ++ [hd] :=\nby intros; refl\n\nlemma rev_distrib : \u2200 l1 l2 : list \u2115, rev (l1 ++ l2) = rev l2 ++ rev l1 := \nbegin\n  intros,\n  induction l1 with x xs ihl1,\n    induction l2 with y ys ihl2,\n      refl,\n      simp [rev],\n    induction l2 with y ys ihl2,\n      simp [rev],\n      { simp [rev], \n        rw [ihl1, rev_step, \u2190cons_append],\n        simp * }\nend \n\nlemma rev_involutive : \u2200 l : list \u2115, rev (rev l) = l\n| nil := rfl\n| (x::xs) := by simp [*, rev, rev_step, rev_distrib]\n\nlemma rev_nil : rev nil = nil := rfl\nlemma rev_singleton : \u2200 n : \u2115, rev [n] = [n] := \u03bb n, rfl \n\nlemma ceqa (hd : \u2115) (tl : list \u2115) : hd :: tl = [hd] ++ tl := rfl\n\ntheorem rev_injective : function.injective rev := \n\u03bb a b h, by rw [\u2190rev_involutive a, \u2190rev_involutive b, h]", "meta": {"author": "alashworth", "repo": "sf-lean", "sha": "bec3ef4ffbe1fcd83772570b84ac3ff074bb7476", "save_path": "github-repos/lean/alashworth-sf-lean", "path": "github-repos/lean/alashworth-sf-lean/sf-lean-bec3ef4ffbe1fcd83772570b84ac3ff074bb7476/src/lists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156295, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7414701342515524}}
{"text": "-- \u041a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 `--`\n-- Lean \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0440\u0443\u0432\u0435\u0440, \u0438 \u0432 \u043d\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442,\n-- \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0432\u0435\u0434\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\n\n-- \u041a\u043e\u043c\u0430\u043d\u0434\u0430 `#check` \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\n#check ((\u03bb\u03b1 \u03b2: Type => \u03bbx:\u03b1 => \u03bb_:\u03b2 => x) : \u2200\u03b1 \u03b2: Type, \u03b1 \u2192 \u03b2 \u2192 \u03b1)\n-- Lean \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043e\u0436\u0435\u0442 \u0441\u0430\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0438\u043f, \u0438 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0435\u0433\u043e \u0443\u043a\u0430\u0437\u044b\u0430\u0442\u044c\n#check \u03bb(\u03b1 \u03b2: Type)(x:\u03b1)(_:\u03b2) => x\n\n-- \u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u0442\u0438\u043f, \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\n-- \u041f\u0440\u0438\u043c\u0435\u0440 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0438\u043c\u0435\u043d\u0438\nexample: \u2200\u03b1 \u03b2: Type, \u03b1 \u2192 \u03b2 \u2192 \u03b1 := \u03bb(\u03b1 \u03b2: Type)(x:\u03b1)(_:\u03b2) => x\n-- `\u2200\u03b1 \u03b2: Type` \u0438 `\u03bb(\u03b1 \u03b2: Type)` \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0442 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430. \u041d\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c:\nexample (\u03b1 \u03b2: Type): \u03b1 \u2192 \u03b2 \u2192 \u03b1 := \u03bb(x:\u03b1)(_:\u03b2) => x\n-- \u0418\u043b\u0438 \u0434\u0430\u0436\u0435:\nexample (\u03b1 \u03b2: Type)(x:\u03b1)(_:\u03b2): \u03b1 := x\n\n-- \u041c\u043e\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\ndef f1 (\u03b1 \u03b2: Type)(x:\u03b1)(_:\u03b2): \u03b1 := x\n-- \u0418 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e:\n#check f1 Nat Nat 3 5\n-- \u041a\u043e\u043c\u0430\u043d\u0434\u0430 `#reduce` \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435:\n#reduce f1 Nat Nat 3 5\n-- \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u0439, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c Lean \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0438\u043f \u0437\u0430 \u043d\u0430\u0441:\n#check f1 _ _ 3 5\n\n-- \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0430\u043a:\ndef f2 {\u03b1 \u03b2: Type}(x:\u03b1)(_:\u03b2): \u03b1 := x\n-- `\u03b1` \u0438 `\u03b2` \u044d\u0442\u043e \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438:\n#check f2 3 5\n-- \u041d\u043e \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0445 \u0432\u0441\u0435 \u044f\u0432\u043d\u043e:\n#check @f2 Nat Nat 3 5\n-- \u0418\u043b\u0438 \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043f\u043e \u0438\u043c\u0435\u043d\u0438:\n#check f2 (\u03b2 := Nat) 3 5\n\n-- Lean \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0437\u0443 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0441\u0435\u043b\u0435\u043d\u043d\u044b\u0445:\nexample {\u03b1 \u03b2: Sort u}(x:\u03b1)(_:\u03b2): \u03b1 := x\n-- \u0418 \u044f\u0432\u043d\u043e\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c\nexample (x:\u03b1)(_:\u03b2): \u03b1 := x\n\n-- \u0422\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445\n\n#print Bool\n\n-- inductive Bool : Type where\n  -- /-- The boolean value `false`, not to be confused with the proposition `False`. -/\n  -- | false : Bool\n  -- /-- The boolean value `true`, not to be confused with the proposition `True`. -/\n  -- | true : Bool\n--\n-- export Bool (false true)\n\n#print false\n#print true\n\ndef neg (b:Bool): Bool :=\n  match b with\n  | false => true\n  | true  => false\n\n#reduce neg false\n#reduce neg true\n\nexample: Bool \u2192 Bool\n| false => true    | true  => false\n\nexample: Bool \u2192 Bool \u2192 Bool\n| false, false => false    | false, true  => true\n| true,  false => true     | true,  true  => false\n\n#print Nat\n\ndef pred: Nat \u2192 Nat\n| Nat.zero   => 0\n| Nat.succ n => n\n\n#reduce pred (pred 5)\n\ndef add1 (n:Nat): Nat \u2192 Nat\n| 0          => n\n| Nat.succ k => add1 n.succ k\n\ndef add2 (n:Nat): Nat \u2192 Nat\n| 0          => n\n| Nat.succ k => (add2 n k).succ\n\n-- def il: Nat \u2192 Nat\n-- | 0 => 0\n-- | Nat.succ n => il n.succ\n\n#print add2\n#print Nat.brecOn\n#print Nat.rec\n\n-- recursor Nat.rec.{u} : {motive : Nat \u2192 Sort u} \u2192\n  -- motive Nat.zero \u2192 ((n : Nat) \u2192 motive n \u2192 motive (Nat.succ n)) \u2192 (t : Nat) \u2192 motive t\n\ndef natRec {M: Nat \u2192 Sort u}(z: M Nat.zero)(f: \u2200n:Nat, M n \u2192 M n.succ): (t: Nat) \u2192 M t\n| Nat.zero   => z\n| Nat.succ n => f n (natRec z f n)\n\n#reduce (\u03bbn => Nat.rec (motive := \u03bb_ => Nat) n (\u03bb_ s => s.succ)) 2 3\n\n#reduce (Nat.rec 2 (\u03bb_ s => s.succ) : Nat \u2192 Nat) 3\n#reduce (\u03bb_ s => s.succ) 2 $ (Nat.rec 2 (\u03bb_ s => s.succ) : Nat \u2192 Nat) 2\n#reduce (\u03bb_ s => s.succ) 2 $ (\u03bb_ s => s.succ) 1 $ (Nat.rec 2 (\u03bb_ s => s.succ) : Nat \u2192 Nat) 1\n#reduce (\u03bb_ s => s.succ) 2 $ (\u03bb_ s => s.succ) 1 $ (\u03bb_ s => s.succ) 0 $\n  (Nat.rec 2 (\u03bb_ s => s.succ) : Nat \u2192 Nat) 0\n#reduce (\u03bb_ s => s.succ) 2 $ (\u03bb_ s => s.succ) 1 $ (\u03bb_ s => s.succ) 0 $ 2\n\n#print Bool.rec\n#print Nat.casesOn\n\n#print Prod\n\n#reduce ( (Prod.mk 2 3).casesOn (\u03bbx y => (y,x)) : Nat\u00d7Nat )\n\n-- structure Prod (\u03b1 : Type u) (\u03b2 : Type v) where\n--   /-- The first projection out of a pair. if `p : \u03b1 \u00d7 \u03b2` then `p.1 : \u03b1`. -/\n--   fst : \u03b1\n--   /-- The second projection out of a pair. if `p : \u03b1 \u00d7 \u03b2` then `p.2 : \u03b2`. -/\n--   snd : \u03b2\n\n#reduce (2,3).fst\n#reduce (2,3).snd\n\n#reduce ( {snd := 3, fst := 2} : Nat\u00d7Nat )\n#reduce ( \u27e82,3\u27e9 : Nat\u00d7Nat )\n\n#print Sum\n\n-- inductive Sum (\u03b1 : Type u) (\u03b2 : Type v) where\n--   /-- Left injection into the sum type `\u03b1 \u2295 \u03b2`. If `a : \u03b1` then `.inl a : \u03b1 \u2295 \u03b2`. -/\n--   | inl (val : \u03b1) : Sum \u03b1 \u03b2\n--   /-- Right injection into the sum type `\u03b1 \u2295 \u03b2`. If `b : \u03b2` then `.inr b : \u03b1 \u2295 \u03b2`. -/\n--   | inr (val : \u03b2) : Sum \u03b1 \u03b2\n\n#reduce ( (Sum.inl 3).casesOn pred Nat.succ : Nat )\n#reduce ( (Sum.inr 3).casesOn pred Nat.succ : Nat )\n\n#print Empty\n\n#check \u03bbe:Empty => e\n\n#print Empty.rec\n\n#check \u03bbe:Empty => (e.rec : Nat)\n\ndef BoolEq (a: Bool)(b: Bool): Prop :=\n  a.rec (b.rec True False) (b.rec False True)\n\nexample: \u2200b:Bool, BoolEq b b := Bool.rec \u27e8\u27e9 \u27e8\u27e9\n\nexample (P Q: Type)(pq: P \u2295 Q): Prop := pq.rec (\u03bb_ => False) (\u03bb_ => True)\n-- example (P Q: Prop)(pq: P \u2228 Q): Prop := pq.rec (\u03bb_ => False) (\u03bb_ => True)\n\n#check Decidable.byContradiction\n#check Bool.and_true\n#check decidable_of_decidable_of_iff\n\ninstance {P Q: Prop}: [Decidable P] \u2192 [Decidable Q] \u2192 Decidable (P \u2227 Q)\n| isFalse np, _          => isFalse $ \u03bbpq => np pq.left\n| _,          isFalse nq => isFalse $ \u03bbpq => nq pq.right\n| isTrue p,   isTrue q   => isTrue  $ \u27e8p,q\u27e9\n\ninstance {P Q: Prop}: [Decidable P] \u2192 [Decidable Q] \u2192 Decidable (P \u2228 Q)\n| isFalse np, isFalse nq => isFalse $ \u03bbpq => pq.elim np nq\n| isTrue p,   _          => isTrue  $ Or.inl p\n| _,          isTrue q   => isTrue  $ Or.inr q\n\ntheorem decide_and {P Q: Prop}[dp: Decidable P][dq:Decidable Q]\n  : decide (P \u2227 Q) = (decide P && decide Q) :=\nby\n  apply dite P <;> (intro; simp [*])\n\ntheorem decide_or {P Q: Prop}[dp: Decidable P][dq:Decidable Q]\n  : decide (P \u2228 Q) = (decide P || decide Q) :=\nby\n  apply dite P <;> (intro; simp [*])\n", "meta": {"author": "suhr", "repo": "tmath", "sha": "60116239b291524c664e6fbefa4c6fb12f2547aa", "save_path": "github-repos/lean/suhr-tmath", "path": "github-repos/lean/suhr-tmath/tmath-60116239b291524c664e6fbefa4c6fb12f2547aa/Tmath/Basics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7414701208162287}}
{"text": "import data.real.basic\nimport data.matrix.basic\nimport algebra.big_operators.basic\n\nopen_locale big_operators matrix\n\n\n\nvariables {d n : \u2115} {\u03b9 : Type*}\n\nvariables (M : matrix (fin n) (fin n) \u211d)\n\nvariables {f : fin n \u2192 \u211d} {g : fin n.succ \u2192 \u211d}\n\ndef n_set : finset (fin n) := @finset.univ (fin n) (fin.fintype n)\n\n\ntheorem blah : \u2211 i : (fin n), \u2211 j : (fin n), M i j = \u2211 j : (fin n), \u2211 i : (fin n), M i j :=\n  finset.sum_comm\n\n\ntheorem sum_split_singleton (k : fin n) :\n  \u2211 (i : fin n), f i = f k + \u2211 (i : fin n) in finset.univ \\ {k}, f i :=\n  finset.sum_eq_add_sum_diff_singleton (finset.mem_univ k) f\n\n-- theorem sum_split_singleton (k : fin n) : \u2211 (i : fin n), f i \n--   = \u2211 (i : fin n) in finset.univ.filter (\u03bb x : fin n, x \u2260 k) , f i + f k :=\n-- begin\n--   classical,\n--   rw \u2190 finset.sum_filter_add_sum_filter_not _ (\u03bb x : fin n, x \u2260 k),\n--   simp only [add_right_inj, finset.filter_congr_decidable, finset.sum_congr],\n--   simp_rw not_ne_iff,\n--   rw finset.sum_filter,\n--   simp only [finset.mem_univ, if_true, eq_self_iff_true, finset.sum_ite_eq'],\n-- end\n\ntheorem sum_succ_eq_sum :\n  \u2211 (i : fin n.succ), g i = (\u2211 (i : fin n), g i) + g (fin.last n) :=\nbegin\n  rw fin.sum_univ_cast_succ,\n  norm_cast,\nend\n\ntheorem sum_succ_eq_sum :\n  \u2211 (i : fin n.succ), g i = (\u2211 (i : fin n), g i) + g (fin.last n) :=\nbegin\n  rw fin.sum_univ_cast_succ,\n  norm_cast,\nend\n\ntheorem sum_n_succ_ne_n_eq_sum_n: \n  \u2211 (i : fin n.succ) in finset.univ.filter (\u03bb x : fin n.succ, x \u2260 n), g i \n  = \u2211 i : fin n, g i :=\nbegin\n  let n_set := @finset.univ (fin n) _,\n  have h : n_set.map (fin.succ_above (n)).to_embedding = (@finset.univ (fin n.succ) _).filter (\u03bb x : fin n.succ, x \u2260 n) :=\n  begin\n    ext,\n    rw finset.mem_filter,\n    rw finset.mem_map,\n    split,\n    intro h,\n    cases h with i h,\n    cases h with hi h,\n    split,\n    exact finset.mem_univ a,\n    intro c,\n    rw c at h,\n    simp only [nat.cast_succ, rel_embedding.coe_fn_to_embedding] at h,\n    exact fin.succ_above_ne (n) i h,\n    intro h,\n    use (\u2191a),\n    have := fin.is_le a,\n    cases h with h1 h2,\n    rw fin.ne_iff_vne at h2,\n    rw fin.val_eq_coe at h2,\n    rw fin.val_eq_coe at h2,\n    rw fin.coe_of_nat_eq_mod at h2,\n    rw nat.mod_eq_of_lt at h2,\n    exact lt_of_le_of_ne this h2,\n    exact nat.lt_succ_self n,\n    split,\n    simp only [finset.mem_univ],\n    simp only [rel_embedding.coe_fn_to_embedding],\n    rw fin.succ_above_below,\n    simp only [eq_self_iff_true, fin.cast_succ_mk, fin.eta],\n    simp only [fin.cast_succ_mk, fin.eta],\n    have := fin.is_le a,\n    cases h with h1 h2,\n    rw fin.lt_def,\n    simp only [fin.val_eq_coe, fin.coe_of_nat_eq_mod],\n    rw nat.mod_eq_of_lt,\n    rw fin.ne_iff_vne at h2,\n    rw fin.val_eq_coe at h2,\n    rw fin.val_eq_coe at h2,\n    rw fin.coe_of_nat_eq_mod at h2,\n    rw nat.mod_eq_of_lt at h2,\n    apply lt_of_le_of_ne this _,\n    exact h2,\n    exact nat.lt_succ_self n,\n    exact nat.lt_succ_self n,\n  end,\n  rw \u2190 h,\n  simp only [fin.coe_eq_cast_succ, finset.sum_map, rel_embedding.coe_fn_to_embedding, finset.sum_congr],\n  congr,\n  ext,\n  rw fin.succ_above_below,\n  have := fin.cast_succ_lt_last x,\n  rw fin.lt_def at this,\n  simp only [fin.val_eq_coe, fin.coe_last, fin.coe_cast_succ] at this,\n  rw fin.lt_def,\n  simp only [fin.val_eq_coe, fin.coe_cast_succ, fin.coe_of_nat_eq_mod],\n  rw nat.mod_eq_of_lt,\n  exact this,\n  exact nat.lt_succ_self n,\nend\n\n\ntheorem sum_split_last (f : fin n.succ \u2192 \u211d) : \u2211 (i : fin n.succ), f i \n  = \u2211 (i : fin n), f i + f n :=\nbegin\n  rw sum_split_singleton (n : fin n.succ),\n  rw sum_n_succ_ne_n_eq_sum_n,\nend\n\ntheorem sum_nonneg_of_nonneg (h : \u2200 i : fin n, 0 \u2264 f i) : 0 \u2264 \u2211 i : fin n, f i :=\nbegin\n  have : \u2200 (i : fin n), i \u2208 @finset.univ (fin n) _ \u2192 0 \u2264 f i :=\n  begin\n    intros i hi,\n    exact h i,\n  end,\n  exact finset.sum_nonneg this,\nend\n\n-- theorem sum_nonneg_of_nonneg (h : \u2200 i : fin n, 0 \u2264 f i) : 0 \u2264 \u2211 i : fin n, f i :=\n-- begin\n--   induction n with n h0,\n--   simp only [le_refl, finset.sum_empty, finset.sum_congr, fintype.univ_of_is_empty],\n--   rw sum_split_singleton (n : fin n.succ),\n--   rw sum_n_succ_ne_n_eq_sum_n,\n--   let g := f \u2218 fin.succ_above n,\n--   have : \u2200 i : fin n, 0 \u2264 g i :=\n--   begin\n--     intro i,\n--     change 0 \u2264 (f \u2218 fin.succ_above n) i,\n--     rw function.comp_app,\n--     exact h _,\n--   end,\n--   have hg: \u2200 i : fin n, g i = f i := \u03bb i,\n--   begin\n--     simp only [g],\n--     rw function.comp_app,\n--     rw fin.succ_above_below,\n--     rw fin.coe_eq_cast_succ,\n--     rw [fin.lt_def, fin.val_eq_coe, fin.val_eq_coe, fin.coe_cast_succ, fin.coe_of_nat_eq_mod],\n--     rw nat.mod_eq_of_lt (nat.lt_succ_self n),\n--     apply fin.cast_succ_lt_last,\n--   end,\n--   simp_rw \u2190 hg,\n--   apply add_nonneg,\n--   exact h0 this,\n--   exact h n,\n-- end\n\n#check (fintype(fin n))\n#check @finset.univ (fin n) (fin.fintype n) -- : finset (fin n)", "meta": {"author": "Daniel-Packer", "repo": "paulsen-made-simple", "sha": "64f0b91375c6f9dfb959e47f347fa8a87b395e9a", "save_path": "github-repos/lean/Daniel-Packer-paulsen-made-simple", "path": "github-repos/lean/Daniel-Packer-paulsen-made-simple/paulsen-made-simple-64f0b91375c6f9dfb959e47f347fa8a87b395e9a/src/summation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.741291344978964}}
{"text": "-- =====================================================================\n-- \u00a7 Resumen                                                          --\n-- =====================================================================\n\n-- En esta relaci\u00f3n se demostrar\u00e1 que\n-- + la imagen de un espacio compacto mediante una funci\u00f3n continua es\n--   compacta.\n-- + Los subconjuntos cerrados de un espacio compacto son compactos.\n--\n-- Concretamente, lo que demostraremos es que\n-- + Si `f : X \u2192 Y` es una funci\u00f3n continua y `S : set X` es un conjunto\n--   compacto (con la subtopolog\u00eda), entonces `f '' S` (la imagen de `S`\n--   por `f`) es compacto (con la subtopolog\u00eda).\n-- + Si `X` es unespacio topol\u00f3gico, `S` es un subconjunto compacto y\n--   `C` es un subconjunto cerrado, entonces `S \u2229 C` es un subconjunto\n--   compacto.\n--\n-- Los resultados originales son los casos particulares cuando `S` es\n-- `univ : set X`.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Importar la teor\u00eda de las propiedades de los subconjuntos\n-- de los espacios topol\u00f3gicos.\n-- ---------------------------------------------------------------------\n\nimport topology.subset_properties\n\n-- =====================================================================\n-- \u00a7 Introducci\u00f3n                                                     --\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar\n-- + X e Y como variables sobre espacios topol\u00f3gicos.\n-- + f como variable sobre las funciones de x en Y.\n-- ---------------------------------------------------------------------\n\nvariables (X Y : Type) [topological_space X] [topological_space Y]\nvariable  (f : X \u2192 Y)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir es espacion de nombre set (de los conjuntos).\n-- ---------------------------------------------------------------------\n\nopen set\n\n-- =====================================================================\n-- \u00a7 Subespacios compactos                                            --\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que un subconjunto de un espacio topol\u00f3gico es\n-- compacto si de todo recubrimiento abierto se puede extraer un\n-- subrecubrimiento finito.\n-- ---------------------------------------------------------------------\n\nlemma compact_iff_finite_subcover'\n  {\u03b1 : Type} [topological_space \u03b1]\n  {S : set \u03b1}\n  : is_compact S \u2194\n    (\u2200 {\u03b9 : Type} (U : \u03b9 \u2192 set \u03b1),\n       (\u2200 i, is_open (U i))\n       \u2192 S \u2286 (\u22c3 i, U i)\n       \u2192 (\u2203 (t : set \u03b9), t.finite \u2227 S \u2286 (\u22c3 i \u2208 t, U i))) :=\nbegin\n  rw compact_iff_finite_subcover,\n  split,\n  { intros hs \u03b9 U hU hsU,\n    cases hs U hU hsU with F hF,\n    use [(\u2191F : set \u03b9), finset.finite_to_set F],\n    exact hF },\n  { intros hs \u03b9 U hU hsU,\n    rcases hs U hU hsU with \u27e8F, hFfin, hF\u27e9,\n    use hFfin.to_finset,\n    convert hF,\n    ext,\n    simp }\nend\n\n-- =====================================================================\n-- \u00a7 La imagen continua de compactos es compacta                      --\n-- =====================================================================\n\n-- Nota: Lemas \u00fatiles sobre topolog\u00eda\n-- + is_open_compl_iff\n--      {\u03b1 : Type u} [topological_space \u03b1]\n--      {s : set \u03b1}\n--      : is_open s\u1d9c \u2194 is_closed s\n-- + is_open_preimage\n--      {\u03b1 : Type u_1} [topological_space \u03b1]\n--      {\u03b2 : Type u_2} [topological_space \u03b2]\n--      {f : \u03b1 \u2192 \u03b2}\n--      (hf : continuous f)\n--      {s : set \u03b2}\n--      (h : is_open s)\n--      : is_open (f \u207b\u00b9' s)\n\n\n\n\n/-!\n\n## Continuous image of compact is compact\n\nI would start with `rw compact_iff_finite_subcover' at hS \u22a2,`\n\nThe proof that I recommend formalising is this. Say `S` is a compact\nsubset of `X`, and `f : X \u2192 Y` is continuous. We want to prove that\nevery cover of `f '' S` by open subsets of `Y` has a finite subcover.\nSo let's cover `f '' S` with opens `U i : set Y`, for `i : \u03b9` and `\u03b9` an index type.\nPull these opens back to `V i : set X` and observe that they cover `S`.\nChoose a finite subcover corresponding to some `F : set \u03b9` such that `F` is finite\n(Lean writes this `h : F.finite`) and then check that the corresponding cover\nof `f '' S` by the `U i` with `i \u2208 F` is a finite subcover.\n\nGood luck! Please ask questions (or DM me on discord if you don't want to\nask publically). Also feel free to DM me if you manage to do it!\n\nUseful theorems:\n\n`continuous.is_open_preimage` -- preimage of an open set under a\ncontinuous map is open.\n\n`is_open_compl_iff` -- complement `S\u1d9c` of `S` is open iff `S` is closed.\n\n## Some useful tactics:\n\n### `specialize`\n\n`specialize` can be used with `_`. If you have a hypothesis\n\n`hS : \u2200 {\u03b9 : Type} (U : \u03b9 \u2192 set X), (\u2200 (i : \u03b9), is_open (U i)) \u2192 ...`\n\nand `U : \u03b9 \u2192 set X`, then\n\n`specialize hS U` will change `hS` to\n\n`hS : (\u2200 (i : \u03b9), is_open (U i)) \u2192 ...`\n\nBut what if you now want to prove `\u2200 i, is_open (U i)` so you can feed it\ninto `hS` as an input? You can put\n\n`specialize hS _`\n\nand then that goal will pop out. Unfortunately it pops out _under_ the\ncurrent goal! You can swap two goals with the `swap` tactic though :-)\n\n### `change`\n\nIf your goal is `\u22a2 P` and `P` is definitionally equal to `Q`, then you\ncan write `change Q` and the goal will change to `Q`. Sometimes useful\nbecause rewriting works up to syntactic equality, which is stronger\nthan definitional equality.\n\n### `rwa`\n\n`rwa h` just means `rw h, assumption`\n\n### `contradiction`\n\nIf you have `h1 : P` and `h2 : \u00ac P` as hypotheses, then you can prove any goal with\nthe `contradiction` tactic, which just does `exfalso, apply h2, exact h1`.\n\n### `set`\n\nNote : The `set` tactic is totally unrelated to the `set X` type of subsets of `X`!\n\nThe `set` tactic can be used to define things. For example\n`set T := f '' S with hT_def,` will define `T` to be `f '' S`\nand will also define `hT_def : T = f '' S`.\n\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es continua y S es compacto, entoces la\n-- imagen de S por f es compacto.\n-- ---------------------------------------------------------------------\n\n\n-- La idea de la demostraci\u00f3n es la siguiente: Sea `S` un subconjunto\n-- compacto de `X` y `f : X \u2192 Y` continua. Dado `U i : set Y` un\n-- recubrimiento abierto de `f '' S`, para cada `i` se define\n-- `V i = f \u207b\u00b9' (U i)`. Se rprueba que `V` es un recubriemiento abierto\n-- de `S` y, como `S`es compacto, tiene un subrecubrimiento finito. La\n-- im\u00e1genes de cada conjunto de dicho subrecubrimiento forman un\n-- subrecubrimiento finito de `f '' S`.\n\nlemma image_compact_of_compact\n  (hf : continuous f)\n  (S : set X)\n  (hS : is_compact S)\n  : is_compact (f '' S) :=\nbegin\n  rw compact_iff_finite_subcover' at *,\n  set T := f '' S with hT_def,\n  intros \u03b9 U hU hcoverU,\n  set V : \u03b9 \u2192 set X := \u03bb i, f \u207b\u00b9' (U i) with hV_def,\n  specialize hS V _,\n  swap,\n  { intro i,\n    rw hV_def, dsimp only,\n    apply continuous.is_open_preimage hf _ (hU i), },\n  { specialize hS _,\n    swap,\n    { intros x hx,\n      have hfx : f x \u2208 T,\n      { rw hT_def,\n        rw mem_image,\n        use x,\n        use hx,},\n      { specialize hcoverU hfx,\n        rw mem_Union at hcoverU \u22a2,\n        exact hcoverU, }},\n    { rcases hS with \u27e8F, hFfinite, hF\u27e9,\n      use F,\n      use hFfinite,\n      rintros y \u27e8x, hxs, rfl\u27e9,\n      rw subset_def at hF,\n      specialize hF x hxs,\n      rw mem_bUnion_iff at hF \u22a2,\n      exact hF, }},\nend\n\n-- =====================================================================\n-- \u00a7 Subconjuntos cerrados de compactos                               --\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si S es compacto y C es cerrado, entonces\n-- `S \u2229 C` es compacto.\n-- ---------------------------------------------------------------------\n\n\nlemma closed_of_compact\n  (S : set X)\n  (hS : is_compact S)\n  (C : set X)\n  (hC : is_closed C)\n  : is_compact (S \u2229 C) :=\nbegin\n  rw compact_iff_finite_subcover' at *,\n  intros \u03b9 U hUopen hSCcover,\n  let V : option \u03b9 \u2192 set X := \u03bb x, option.rec C\u1d9c U x,\n  specialize hS V _,\n  swap,\n  { intros i,\n    cases i with i,\n    { change is_open C\u1d9c,\n      rwa is_open_compl_iff },\n    { change is_open (U i),\n      apply hUopen } },\n  specialize hS _,\n  swap,\n  { intros x hxS,\n    by_cases hxC : x \u2208 C,\n    { rw subset_def at hSCcover,\n      specialize hSCcover x \u27e8hxS, hxC\u27e9,\n      rw mem_Union at \u22a2 hSCcover,\n      cases hSCcover with i hi,\n      use (some i),\n      exact hi },\n    { rw mem_Union,\n      use none } },\n  rcases hS with \u27e8F, hFfinite, hFcover\u27e9,\n  use (some : \u03b9 \u2192 option \u03b9) \u207b\u00b9' F,\n  split,\n  { apply finite.preimage _ hFfinite,\n    intros i hi j hj,\n    exact option.some_inj.mp },\n  rintros x \u27e8hxS, hxC\u27e9,\n  rw subset_def at hFcover,\n  specialize hFcover x hxS,\n  rw mem_bUnion_iff at hFcover \u22a2,\n  rcases hFcover with \u27e8i, hiF, hxi\u27e9,\n  cases i with i,\n  { contradiction },\n  { use [i, hiF, hxi] },\nend\n", "meta": {"author": "jaalonso", "repo": "Formalizacion_de_las_matematicas_en_Lean", "sha": "52bf9748d17a22d819cac19502fca9bc7340f7ae", "save_path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean/Formalizacion_de_las_matematicas_en_Lean-52bf9748d17a22d819cac19502fca9bc7340f7ae/src/4_Topologia/Topologia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7412448246179575}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura\n\n! This file was ported from Lean 3 source module init.data.fin.ops\n! leanprover-community/mathlib commit 3d2e3b75617386cb32de6cbc7e1cd341c6a16adf\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nprelude\nimport Leanbin.Init.Data.Nat.Default\nimport Leanbin.Init.Data.Fin.Basic\n\nnamespace Fin\n\nopen Nat\n\nvariable {n : Nat}\n\n#print Fin.succ /-\nprotected def succ : Fin n \u2192 Fin (succ n)\n  | \u27e8a, h\u27e9 => \u27e8Nat.succ a, succ_lt_succ h\u27e9\n#align fin.succ Fin.succ\n-/\n\n#print Fin.ofNat /-\ndef ofNat {n : Nat} (a : Nat) : Fin (succ n) :=\n  \u27e8a % succ n, Nat.mod_lt _ (Nat.zero_lt_succ _)\u27e9\n#align fin.of_nat Fin.ofNat\n-/\n\nprivate theorem mlt {n b : Nat} : \u2200 {a}, n > a \u2192 b % n < n\n  | 0, h => Nat.mod_lt _ h\n  | a + 1, h =>\n    have : n > 0 := lt_trans (Nat.zero_lt_succ _) h\n    Nat.mod_lt _ this\n#align fin.mlt fin.mlt\n\n#print Fin.add /-\nprotected def add : Fin n \u2192 Fin n \u2192 Fin n\n  | \u27e8a, h\u27e9, \u27e8b, _\u27e9 => \u27e8(a + b) % n, mlt h\u27e9\n#align fin.add Fin.add\n-/\n\n#print Fin.mul /-\nprotected def mul : Fin n \u2192 Fin n \u2192 Fin n\n  | \u27e8a, h\u27e9, \u27e8b, _\u27e9 => \u27e8a * b % n, mlt h\u27e9\n#align fin.mul Fin.mul\n-/\n\nprivate theorem sublt {a b n : Nat} (h : a < n) : a - b < n :=\n  lt_of_le_of_lt (Nat.sub_le a b) h\n#align fin.sublt fin.sublt\n\n#print Fin.sub /-\nprotected def sub : Fin n \u2192 Fin n \u2192 Fin n\n  | \u27e8a, h\u27e9, \u27e8b, _\u27e9 => \u27e8(a + (n - b)) % n, mlt h\u27e9\n#align fin.sub Fin.sub\n-/\n\nprivate theorem modlt {a b n : Nat} (h\u2081 : a < n) (h\u2082 : b < n) : a % b < n :=\n  by\n  cases' b with b\n  \u00b7 simp [mod_zero]\n    assumption\n  \u00b7 have h : a % succ b < succ b\n    apply Nat.mod_lt _ (Nat.zero_lt_succ _)\n    exact lt_trans h h\u2082\n#align fin.modlt fin.modlt\n\n#print Fin.mod /-\nprotected def mod : Fin n \u2192 Fin n \u2192 Fin n\n  | \u27e8a, h\u2081\u27e9, \u27e8b, h\u2082\u27e9 => \u27e8a % b, modlt h\u2081 h\u2082\u27e9\n#align fin.mod Fin.mod\n-/\n\nprivate theorem divlt {a b n : Nat} (h : a < n) : a / b < n :=\n  lt_of_le_of_lt (Nat.div_le_self a b) h\n#align fin.divlt fin.divlt\n\n#print Fin.div /-\nprotected def div : Fin n \u2192 Fin n \u2192 Fin n\n  | \u27e8a, h\u27e9, \u27e8b, _\u27e9 => \u27e8a / b, divlt h\u27e9\n#align fin.div Fin.div\n-/\n\ninstance : Zero (Fin (succ n)) :=\n  \u27e8\u27e80, succ_pos n\u27e9\u27e9\n\ninstance : One (Fin (succ n)) :=\n  \u27e8ofNat 1\u27e9\n\ninstance : Add (Fin n) :=\n  \u27e8Fin.add\u27e9\n\ninstance : Sub (Fin n) :=\n  \u27e8Fin.sub\u27e9\n\ninstance : Mul (Fin n) :=\n  \u27e8Fin.mul\u27e9\n\ninstance : Mod (Fin n) :=\n  \u27e8Fin.mod\u27e9\n\ninstance : Div (Fin n) :=\n  \u27e8Fin.div\u27e9\n\ntheorem ofNat_zero : @ofNat n 0 = 0 :=\n  rfl\n#align fin.of_nat_zero Fin.ofNat_zero\n\n/- warning: fin.add_def -> Fin.add_def is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} Nat (Fin.val n (HAdd.hAdd.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHAdd.{0} (Fin n) (Fin.hasAdd n)) a b)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Fin.val n a) (Fin.val n b)) n)\nbut is expected to have type\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} (Fin n) (HAdd.hAdd.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHAdd.{0} (Fin n) (Fin.instAddFin n)) a b) (Fin.mk n (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Fin.val n a) (Fin.val n b)) n) (Nat.mod_lt (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Fin.val n a) (Fin.val n b)) n (Fin.size_positive n a)))\nCase conversion may be inaccurate. Consider using '#align fin.add_def Fin.add_def\u2093'. -/\ntheorem add_def (a b : Fin n) : (a + b).val = (a.val + b.val) % n :=\n  show (Fin.add a b).val = (a.val + b.val) % n by cases a <;> cases b <;> simp [Fin.add]\n#align fin.add_def Fin.add_def\n\n/- warning: fin.mul_def -> Fin.mul_def is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} Nat (Fin.val n (HMul.hMul.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHMul.{0} (Fin n) (Fin.hasMul n)) a b)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Fin.val n a) (Fin.val n b)) n)\nbut is expected to have type\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} (Fin n) (HMul.hMul.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHMul.{0} (Fin n) (Fin.instMulFin n)) a b) (Fin.mk n (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Fin.val n a) (Fin.val n b)) n) (Nat.mod_lt (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Fin.val n a) (Fin.val n b)) n (Fin.size_positive n a)))\nCase conversion may be inaccurate. Consider using '#align fin.mul_def Fin.mul_def\u2093'. -/\ntheorem mul_def (a b : Fin n) : (a * b).val = a.val * b.val % n :=\n  show (Fin.mul a b).val = a.val * b.val % n by cases a <;> cases b <;> simp [Fin.mul]\n#align fin.mul_def Fin.mul_def\n\n/- warning: fin.sub_def -> Fin.sub_def is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} Nat (Fin.val n (HSub.hSub.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHSub.{0} (Fin n) (Fin.hasSub n)) a b)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Fin.val n a) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n (Fin.val n b))) n)\nbut is expected to have type\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} (Fin n) (HSub.hSub.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHSub.{0} (Fin n) (Fin.instSubFin n)) a b) (Fin.mk n (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Fin.val n a) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n (Fin.val n b))) n) (Nat.mod_lt (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Fin.val n a) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n (Fin.val n b))) n (Fin.size_positive n a)))\nCase conversion may be inaccurate. Consider using '#align fin.sub_def Fin.sub_def\u2093'. -/\ntheorem sub_def (a b : Fin n) : (a - b).val = (a.val + (n - b.val)) % n := by\n  cases a <;> cases b <;> rfl\n#align fin.sub_def Fin.sub_def\n\n/- warning: fin.mod_def -> Fin.mod_def is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} Nat (Fin.val n (HMod.hMod.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHMod.{0} (Fin n) (Fin.hasMod n)) a b)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (Fin.val n a) (Fin.val n b))\nbut is expected to have type\n  forall {n : Nat} (a : Fin n) (b : Fin n), Eq.{1} (Fin n) (HMod.hMod.{0, 0, 0} (Fin n) (Fin n) (Fin n) (instHMod.{0} (Fin n) (Fin.instModFin n)) a b) (Fin.mk n (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (Fin.val n a) (Fin.val n b)) n) (Nat.mod_lt (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (Fin.val n a) (Fin.val n b)) n (Fin.size_positive n a)))\nCase conversion may be inaccurate. Consider using '#align fin.mod_def Fin.mod_def\u2093'. -/\ntheorem mod_def (a b : Fin n) : (a % b).val = a.val % b.val :=\n  show (Fin.mod a b).val = a.val % b.val by cases a <;> cases b <;> simp [Fin.mod]\n#align fin.mod_def Fin.mod_def\n\ntheorem div_def (a b : Fin n) : (a / b).val = a.val / b.val :=\n  show (Fin.div a b).val = a.val / b.val by cases a <;> cases b <;> simp [Fin.div]\n#align fin.div_def Fin.div_def\n\ntheorem lt_def (a b : Fin n) : (a < b) = (a.val < b.val) :=\n  show Fin.Lt a b = (a.val < b.val) by cases a <;> cases b <;> simp [Fin.Lt]\n#align fin.lt_def Fin.lt_def\n\ntheorem le_def (a b : Fin n) : (a \u2264 b) = (a.val \u2264 b.val) :=\n  show Fin.Le a b = (a.val \u2264 b.val) by cases a <;> cases b <;> simp [Fin.Le]\n#align fin.le_def Fin.le_def\n\n/- warning: fin.val_zero clashes with fin.coe_zero -> Fin.val_zero\nwarning: fin.val_zero -> Fin.val_zero is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat}, Eq.{1} Nat (Fin.val (Nat.succ n) (OfNat.ofNat.{0} (Fin (Nat.succ n)) 0 (OfNat.mk.{0} (Fin (Nat.succ n)) 0 (Zero.zero.{0} (Fin (Nat.succ n)) (Fin.hasZero n))))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))\nbut is expected to have type\n  forall (n : Nat) [inst._@.Mathlib.Data.Fin.Basic._hyg.2326 : NeZero.{0} Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero) n], Eq.{1} Nat (Fin.val n (OfNat.ofNat.{0} (Fin n) 0 (Zero.toOfNat0.{0} (Fin n) (Fin.instZeroFin n inst._@.Mathlib.Data.Fin.Basic._hyg.2326)))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))\nCase conversion may be inaccurate. Consider using '#align fin.val_zero Fin.val_zero\u2093'. -/\ntheorem val_zero : (0 : Fin (succ n)).val = 0 :=\n  rfl\n#align fin.val_zero Fin.val_zero\n\n#print Fin.pred /-\ndef pred {n : Nat} : \u2200 i : Fin (succ n), i \u2260 0 \u2192 Fin n\n  | \u27e8a, h\u2081\u27e9, h\u2082 =>\n    \u27e8a.pred,\n      haveI : a \u2260 0 := by\n        have aux\u2081 := vne_of_ne h\u2082\n        dsimp at aux\u2081\n        rw [val_zero] at aux\u2081\n        exact aux\u2081\n      Nat.pred_lt_pred this h\u2081\u27e9\n#align fin.pred Fin.pred\n-/\n\nend Fin\n\n", "meta": {"author": "leanprover-community", "repo": "lean3port", "sha": "9ed1898f23e4379865ee93d62cb6353e5ed6c270", "save_path": "github-repos/lean/leanprover-community-lean3port", "path": "github-repos/lean/leanprover-community-lean3port/lean3port-9ed1898f23e4379865ee93d62cb6353e5ed6c270/Leanbin/Init/Data/Fin/Ops.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7412448209836544}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\nimport order.min_max\nimport order.rel_classes\nimport data.set.intervals.basic\n\n/-!\n# Bounded and unbounded sets\n\nWe prove miscellaneous lemmas about bounded and unbounded sets. Many of these are just variations on\nthe same ideas, or similar results with a few minor differences. The file is divided into these\ndifferent general ideas.\n-/\n\nnamespace set\nvariables {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s t : set \u03b1}\n\n/-! ### Subsets of bounded and unbounded sets -/\n\ntheorem bounded.mono (hst : s \u2286 t) (hs : bounded r t) : bounded r s :=\nhs.imp $ \u03bb a ha b hb, ha b (hst hb)\n\ntheorem unbounded.mono (hst : s \u2286 t) (hs : unbounded r s) : unbounded r t :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := hs a in \u27e8b, hst hb, hb'\u27e9\n\n/-! ### Alternate characterizations of unboundedness on orders -/\n\nlemma unbounded_le_of_forall_exists_lt [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, a < b) : unbounded (\u2264) s :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := h a in \u27e8b, hb, \u03bb hba, hba.not_lt hb'\u27e9\n\nlemma unbounded_le_iff [linear_order \u03b1] : unbounded (\u2264) s \u2194 \u2200 a, \u2203 b \u2208 s, a < b :=\nby simp only [unbounded, not_le]\n\nlemma unbounded_lt_of_forall_exists_le [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, a \u2264 b) : unbounded (<) s :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := h a in \u27e8b, hb, \u03bb hba, hba.not_le hb'\u27e9\n\nlemma unbounded_lt_iff [linear_order \u03b1] : unbounded (<) s \u2194 \u2200 a, \u2203 b \u2208 s, a \u2264 b :=\nby simp only [unbounded, not_lt]\n\nlemma unbounded_ge_of_forall_exists_gt [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, b < a) : unbounded (\u2265) s :=\n@unbounded_le_of_forall_exists_lt \u03b1\u1d52\u1d48 _ _ h\n\nlemma unbounded_ge_iff [linear_order \u03b1] : unbounded (\u2265) s \u2194 \u2200 a, \u2203 b \u2208 s, b < a :=\n\u27e8\u03bb h a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, lt_of_not_ge hba\u27e9, unbounded_ge_of_forall_exists_gt\u27e9\n\nlemma unbounded_gt_of_forall_exists_ge [preorder \u03b1] (h : \u2200 a, \u2203 b \u2208 s, b \u2264 a) : unbounded (>) s :=\n\u03bb a, let \u27e8b, hb, hb'\u27e9 := h a in \u27e8b, hb, \u03bb hba, not_le_of_gt hba hb'\u27e9\n\nlemma unbounded_gt_iff [linear_order \u03b1] : unbounded (>) s \u2194 \u2200 a, \u2203 b \u2208 s, b \u2264 a :=\n\u27e8\u03bb h a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, le_of_not_gt hba\u27e9, unbounded_gt_of_forall_exists_ge\u27e9\n\n/-! ### Relation between boundedness by strict and nonstrict orders. -/\n\n/-! #### Less and less or equal -/\n\nlemma bounded.rel_mono {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (h : bounded r s) (hrr' : r \u2264 r') : bounded r' s :=\nlet \u27e8a, ha\u27e9 := h in \u27e8a, \u03bb b hb, hrr' b a (ha b hb)\u27e9\n\nlemma bounded_le_of_bounded_lt [preorder \u03b1] (h : bounded (<) s) : bounded (\u2264) s :=\nh.rel_mono $ \u03bb _ _, le_of_lt\n\nlemma unbounded.rel_mono {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (hr : r' \u2264 r) (h : unbounded r s) : unbounded r' s :=\n\u03bb a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, \u03bb hba', hba (hr b a hba')\u27e9\n\nlemma unbounded_lt_of_unbounded_le [preorder \u03b1] (h : unbounded (\u2264) s) :\n  unbounded (<) s :=\nh.rel_mono $ \u03bb _ _, le_of_lt\n\nlemma bounded_le_iff_bounded_lt [preorder \u03b1] [no_max_order \u03b1] : bounded (\u2264) s \u2194 bounded (<) s :=\nbegin\n  refine \u27e8\u03bb h, _, bounded_le_of_bounded_lt\u27e9,\n  cases h with a ha,\n  cases exists_gt a with b hb,\n  exact \u27e8b, \u03bb c hc, lt_of_le_of_lt (ha c hc) hb\u27e9\nend\n\nlemma unbounded_lt_iff_unbounded_le [preorder \u03b1] [no_max_order \u03b1] :\n  unbounded (<) s \u2194 unbounded (\u2264) s :=\nby simp_rw [\u2190 not_bounded_iff, bounded_le_iff_bounded_lt]\n\n/-! #### Greater and greater or equal -/\n\nlemma bounded_ge_of_bounded_gt [preorder \u03b1] (h : bounded (>) s) : bounded (\u2265) s :=\nlet \u27e8a, ha\u27e9 := h in \u27e8a, \u03bb b hb, le_of_lt (ha b hb)\u27e9\n\nlemma unbounded_gt_of_unbounded_ge [preorder \u03b1] (h : unbounded (\u2265) s) : unbounded (>) s :=\n\u03bb a, let \u27e8b, hb, hba\u27e9 := h a in \u27e8b, hb, \u03bb hba', hba (le_of_lt hba')\u27e9\n\nlemma bounded_ge_iff_bounded_gt [preorder \u03b1] [no_min_order \u03b1] : bounded (\u2265) s \u2194 bounded (>) s :=\n@bounded_le_iff_bounded_lt \u03b1\u1d52\u1d48 _ _ _\n\nlemma unbounded_gt_iff_unbounded_ge [preorder \u03b1] [no_min_order \u03b1] :\n  unbounded (>) s \u2194 unbounded (\u2265) s :=\n@unbounded_lt_iff_unbounded_le \u03b1\u1d52\u1d48 _ _ _\n\n/-! ### The universal set -/\n\ntheorem unbounded_le_univ [has_le \u03b1] [no_top_order \u03b1] : unbounded (\u2264) (@set.univ \u03b1) :=\n\u03bb a, let \u27e8b, hb\u27e9 := exists_not_le a in \u27e8b, \u27e8\u27e9, hb\u27e9\n\ntheorem unbounded_lt_univ [preorder \u03b1] [no_top_order \u03b1] : unbounded (<) (@set.univ \u03b1) :=\nunbounded_lt_of_unbounded_le unbounded_le_univ\n\ntheorem unbounded_ge_univ [has_le \u03b1] [no_bot_order \u03b1] : unbounded (\u2265) (@set.univ \u03b1) :=\n\u03bb a, let \u27e8b, hb\u27e9 := exists_not_ge a in \u27e8b, \u27e8\u27e9, hb\u27e9\n\ntheorem unbounded_gt_univ [preorder \u03b1] [no_bot_order \u03b1] : unbounded (>) (@set.univ \u03b1) :=\nunbounded_gt_of_unbounded_ge unbounded_ge_univ\n\n/-! ### Bounded and unbounded intervals -/\n\ntheorem bounded_self (a : \u03b1) : bounded r {b | r b a} :=\n\u27e8a, \u03bb x, id\u27e9\n\n/-! #### Half-open bounded intervals -/\n\n\n\ntheorem bounded_le_Iio [preorder \u03b1] (a : \u03b1) : bounded (\u2264) (set.Iio a) :=\nbounded_le_of_bounded_lt (bounded_lt_Iio a)\n\ntheorem bounded_le_Iic [preorder \u03b1] (a : \u03b1) : bounded (\u2264) (set.Iic a) :=\nbounded_self a\n\ntheorem bounded_lt_Iic [preorder \u03b1] [no_max_order \u03b1] (a : \u03b1) : bounded (<) (set.Iic a) :=\nby simp only [\u2190 bounded_le_iff_bounded_lt, bounded_le_Iic]\n\ntheorem bounded_gt_Ioi [preorder \u03b1] (a : \u03b1) : bounded (>) (set.Ioi a) :=\nbounded_self a\n\ntheorem bounded_ge_Ioi [preorder \u03b1] (a : \u03b1) : bounded (\u2265) (set.Ioi a) :=\nbounded_ge_of_bounded_gt (bounded_gt_Ioi a)\n\ntheorem bounded_ge_Ici [preorder \u03b1] (a : \u03b1) : bounded (\u2265) (set.Ici a) :=\nbounded_self a\n\ntheorem bounded_gt_Ici [preorder \u03b1] [no_min_order \u03b1] (a : \u03b1) : bounded (>) (set.Ici a) :=\nby simp only [\u2190 bounded_ge_iff_bounded_gt, bounded_ge_Ici]\n\n/-! #### Other bounded intervals -/\n\ntheorem bounded_lt_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (<) (set.Ioo a b) :=\n(bounded_lt_Iio b).mono set.Ioo_subset_Iio_self\n\ntheorem bounded_lt_Ico [preorder \u03b1] (a b : \u03b1) : bounded (<) (set.Ico a b) :=\n(bounded_lt_Iio b).mono set.Ico_subset_Iio_self\n\ntheorem bounded_lt_Ioc [preorder \u03b1] [no_max_order \u03b1] (a b : \u03b1) : bounded (<) (set.Ioc a b) :=\n(bounded_lt_Iic b).mono set.Ioc_subset_Iic_self\n\ntheorem bounded_lt_Icc [preorder \u03b1] [no_max_order \u03b1] (a b : \u03b1) : bounded (<) (set.Icc a b) :=\n(bounded_lt_Iic b).mono set.Icc_subset_Iic_self\n\ntheorem bounded_le_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Ioo a b) :=\n(bounded_le_Iio b).mono set.Ioo_subset_Iio_self\n\ntheorem bounded_le_Ico [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Ico a b) :=\n(bounded_le_Iio b).mono set.Ico_subset_Iio_self\n\ntheorem bounded_le_Ioc [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Ioc a b) :=\n(bounded_le_Iic b).mono set.Ioc_subset_Iic_self\n\ntheorem bounded_le_Icc [preorder \u03b1] (a b : \u03b1) : bounded (\u2264) (set.Icc a b) :=\n(bounded_le_Iic b).mono set.Icc_subset_Iic_self\n\ntheorem bounded_gt_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (>) (set.Ioo a b) :=\n(bounded_gt_Ioi a).mono set.Ioo_subset_Ioi_self\n\ntheorem bounded_gt_Ioc [preorder \u03b1] (a b : \u03b1) : bounded (>) (set.Ioc a b) :=\n(bounded_gt_Ioi a).mono set.Ioc_subset_Ioi_self\n\ntheorem bounded_gt_Ico [preorder \u03b1] [no_min_order \u03b1] (a b : \u03b1) : bounded (>) (set.Ico a b) :=\n(bounded_gt_Ici a).mono set.Ico_subset_Ici_self\n\ntheorem bounded_gt_Icc [preorder \u03b1] [no_min_order \u03b1] (a b : \u03b1) : bounded (>) (set.Icc a b) :=\n(bounded_gt_Ici a).mono set.Icc_subset_Ici_self\n\ntheorem bounded_ge_Ioo [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Ioo a b) :=\n(bounded_ge_Ioi a).mono set.Ioo_subset_Ioi_self\n\ntheorem bounded_ge_Ioc [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Ioc a b) :=\n(bounded_ge_Ioi a).mono set.Ioc_subset_Ioi_self\n\ntheorem bounded_ge_Ico [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Ico a b) :=\n(bounded_ge_Ici a).mono set.Ico_subset_Ici_self\n\ntheorem bounded_ge_Icc [preorder \u03b1] (a b : \u03b1) : bounded (\u2265) (set.Icc a b) :=\n(bounded_ge_Ici a).mono set.Icc_subset_Ici_self\n\n/-! #### Unbounded intervals -/\n\ntheorem unbounded_le_Ioi [semilattice_sup \u03b1] [no_max_order \u03b1] (a : \u03b1) : unbounded (\u2264) (set.Ioi a) :=\n\u03bb b, let \u27e8c, hc\u27e9 := exists_gt (a \u2294 b) in\n  \u27e8c, le_sup_left.trans_lt hc, (le_sup_right.trans_lt hc).not_le\u27e9\n\ntheorem unbounded_le_Ici [semilattice_sup \u03b1] [no_max_order \u03b1] (a : \u03b1) : unbounded (\u2264) (set.Ici a) :=\n(unbounded_le_Ioi a).mono set.Ioi_subset_Ici_self\n\ntheorem unbounded_lt_Ioi [semilattice_sup \u03b1] [no_max_order \u03b1] (a : \u03b1) : unbounded (<) (set.Ioi a) :=\nunbounded_lt_of_unbounded_le (unbounded_le_Ioi a)\n\ntheorem unbounded_lt_Ici [semilattice_sup \u03b1] (a : \u03b1) : unbounded (<) (set.Ici a) :=\n\u03bb b, \u27e8a \u2294 b, le_sup_left, le_sup_right.not_lt\u27e9\n\n/-! ### Bounded initial segments -/\n\ntheorem bounded_inter_not (H : \u2200 a b, \u2203 m, \u2200 c, r c a \u2228 r c b \u2192 r c m) (a : \u03b1) :\n  bounded r (s \u2229 {b | \u00ac r b a}) \u2194 bounded r s :=\nbegin\n  refine \u27e8_, bounded.mono (set.inter_subset_left s _)\u27e9,\n  rintro \u27e8b, hb\u27e9,\n  cases H a b with m hm,\n  exact \u27e8m, \u03bb c hc, hm c (or_iff_not_imp_left.2 (\u03bb hca, (hb c \u27e8hc, hca\u27e9)))\u27e9\nend\n\ntheorem unbounded_inter_not (H : \u2200 a b, \u2203 m, \u2200 c, r c a \u2228 r c b \u2192 r c m) (a : \u03b1) :\n  unbounded r (s \u2229 {b | \u00ac r b a}) \u2194 unbounded r s :=\nby simp_rw [\u2190 not_bounded_iff, bounded_inter_not H]\n\n/-! #### Less or equal -/\n\ntheorem bounded_le_inter_not_le [semilattice_sup \u03b1] (a : \u03b1) :\n  bounded (\u2264) (s \u2229 {b | \u00ac b \u2264 a}) \u2194 bounded (\u2264) s :=\nbounded_inter_not (\u03bb x y, \u27e8x \u2294 y, \u03bb z h, h.elim le_sup_of_le_left le_sup_of_le_right\u27e9) a\n\ntheorem unbounded_le_inter_not_le [semilattice_sup \u03b1] (a : \u03b1) :\n  unbounded (\u2264) (s \u2229 {b | \u00ac b \u2264 a}) \u2194 unbounded (\u2264) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_le_inter_not_le a\nend\n\ntheorem bounded_le_inter_lt [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2264) (s \u2229 {b | a < b}) \u2194 bounded (\u2264) s :=\nby simp_rw [\u2190 not_le, bounded_le_inter_not_le]\n\ntheorem unbounded_le_inter_lt [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2264) (s \u2229 {b | a < b}) \u2194 unbounded (\u2264) s :=\nby { convert unbounded_le_inter_not_le a, ext, exact lt_iff_not_le }\n\ntheorem bounded_le_inter_le [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2264) (s \u2229 {b | a \u2264 b}) \u2194 bounded (\u2264) s :=\nbegin\n  refine \u27e8_, bounded.mono (set.inter_subset_left s _)\u27e9,\n  rw \u2190@bounded_le_inter_lt _ s _ a,\n  exact bounded.mono (\u03bb x \u27e8hx, hx'\u27e9, \u27e8hx, le_of_lt hx'\u27e9)\nend\n\ntheorem unbounded_le_inter_le [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2264) (s \u2229 {b | a \u2264 b}) \u2194 unbounded (\u2264) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_le_inter_le a\nend\n\n/-! #### Less than -/\n\ntheorem bounded_lt_inter_not_lt [semilattice_sup \u03b1] (a : \u03b1) :\n  bounded (<) (s \u2229 {b | \u00ac b < a}) \u2194 bounded (<) s :=\nbounded_inter_not (\u03bb x y, \u27e8x \u2294 y, \u03bb z h, h.elim lt_sup_of_lt_left lt_sup_of_lt_right\u27e9) a\n\ntheorem unbounded_lt_inter_not_lt [semilattice_sup \u03b1] (a : \u03b1) :\n  unbounded (<) (s \u2229 {b | \u00ac b < a}) \u2194 unbounded (<) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_lt_inter_not_lt a\nend\n\ntheorem bounded_lt_inter_le [linear_order \u03b1] (a : \u03b1) :\n  bounded (<) (s \u2229 {b | a \u2264 b}) \u2194 bounded (<) s :=\nby { convert bounded_lt_inter_not_lt a, ext, exact not_lt.symm }\n\ntheorem unbounded_lt_inter_le [linear_order \u03b1] (a : \u03b1) :\n  unbounded (<) (s \u2229 {b | a \u2264 b}) \u2194 unbounded (<) s :=\nby { convert unbounded_lt_inter_not_lt a, ext, exact not_lt.symm }\n\ntheorem bounded_lt_inter_lt [linear_order \u03b1] [no_max_order \u03b1] (a : \u03b1) :\n  bounded (<) (s \u2229 {b | a < b}) \u2194 bounded (<) s :=\nbegin\n  rw [\u2190bounded_le_iff_bounded_lt, \u2190bounded_le_iff_bounded_lt],\n  exact bounded_le_inter_lt a\nend\n\ntheorem unbounded_lt_inter_lt [linear_order \u03b1] [no_max_order \u03b1] (a : \u03b1) :\n  unbounded (<) (s \u2229 {b | a < b}) \u2194 unbounded (<) s :=\nbegin\n  rw [\u2190not_bounded_iff, \u2190not_bounded_iff, not_iff_not],\n  exact bounded_lt_inter_lt a\nend\n\n/-! #### Greater or equal -/\n\ntheorem bounded_ge_inter_not_ge [semilattice_inf \u03b1] (a : \u03b1) :\n  bounded (\u2265) (s \u2229 {b | \u00ac a \u2264 b}) \u2194 bounded (\u2265) s :=\n@bounded_le_inter_not_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_ge_inter_not_ge [semilattice_inf \u03b1] (a : \u03b1) :\n  unbounded (\u2265) (s \u2229 {b | \u00ac a \u2264 b}) \u2194 unbounded (\u2265) s :=\n@unbounded_le_inter_not_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_ge_inter_gt [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2265) (s \u2229 {b | b < a}) \u2194 bounded (\u2265) s :=\n@bounded_le_inter_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_ge_inter_gt [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2265) (s \u2229 {b | b < a}) \u2194 unbounded (\u2265) s :=\n@unbounded_le_inter_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_ge_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  bounded (\u2265) (s \u2229 {b | b \u2264 a}) \u2194 bounded (\u2265) s :=\n@bounded_le_inter_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_ge_iff_unbounded_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  unbounded (\u2265) (s \u2229 {b | b \u2264 a}) \u2194 unbounded (\u2265) s :=\n@unbounded_le_inter_le \u03b1\u1d52\u1d48 s _ a\n\n/-! #### Greater than -/\n\ntheorem bounded_gt_inter_not_gt [semilattice_inf \u03b1] (a : \u03b1) :\n  bounded (>) (s \u2229 {b | \u00ac a < b}) \u2194 bounded (>) s :=\n@bounded_lt_inter_not_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_gt_inter_not_gt [semilattice_inf \u03b1] (a : \u03b1) :\n  unbounded (>) (s \u2229 {b | \u00ac a < b}) \u2194 unbounded (>) s :=\n@unbounded_lt_inter_not_lt \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_gt_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  bounded (>) (s \u2229 {b | b \u2264 a}) \u2194 bounded (>) s :=\n@bounded_lt_inter_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem unbounded_inter_ge [linear_order \u03b1] (a : \u03b1) :\n  unbounded (>) (s \u2229 {b | b \u2264 a}) \u2194 unbounded (>) s :=\n@unbounded_lt_inter_le \u03b1\u1d52\u1d48 s _ a\n\ntheorem bounded_gt_inter_gt [linear_order \u03b1] [no_min_order \u03b1] (a : \u03b1) :\n  bounded (>) (s \u2229 {b | b < a}) \u2194 bounded (>) s :=\n@bounded_lt_inter_lt \u03b1\u1d52\u1d48 s _ _ a\n\ntheorem unbounded_gt_inter_gt [linear_order \u03b1] [no_min_order \u03b1] (a : \u03b1) :\n  unbounded (>) (s \u2229 {b | b < a}) \u2194 unbounded (>) s :=\n@unbounded_lt_inter_lt \u03b1\u1d52\u1d48 s _ _ a\n\nend set\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/bounded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.8872045952083047, "lm_q1q2_score": 0.7412448188018441}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthors: Leonardo de Moura\n\nClassical proof that if f is injective, then f has a left inverse (if domain is not empty).\nThe proof uses the classical axioms: choice and excluded middle.\nThe excluded middle is being used \"behind the scenes\" to allow us to write the if-then-else expression\nwith (\u2203 a : A, f a = b).\n-/\nopen function classical\n\nnoncomputable definition mk_left_inv {A B : Type} [h : nonempty A] (f : A \u2192 B) : B \u2192 A :=\n\u03bb b : B, if ex : (\u2203 a : A, f a = b) then some ex else inhabited.value (inhabited_of_nonempty h)\n\ntheorem has_left_inverse_of_injective {A B : Type} {f : A \u2192 B} : nonempty A \u2192 injective f \u2192 has_left_inverse f :=\nassume h : nonempty A,\nassume inj  : \u2200 a\u2081 a\u2082, f a\u2081 = f a\u2082 \u2192 a\u2081 = a\u2082,\nlet  finv : B \u2192 A := mk_left_inv f in\nhave linv : left_inverse finv f, from\n  \u03bb a,\n    have ex : \u2203 a\u2081 : A, f a\u2081 = f a, from exists.intro a rfl,\n    have h\u2081 : f (some ex) = f a,    from !some_spec,\n    begin\n      esimp [mk_left_inv, comp, id],\n      rewrite [dif_pos ex],\n      exact (!inj h\u2081)\n    end,\nexists.intro finv linv\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/logic/examples/leftinv_of_inj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7412422104758775}}
{"text": "/-\nIf P and Q are propositions, then P \u2192 Q\nis a proposition, as well. We just such\nan implication to be true if whenever P\nis true Q must be true as well. To prove\nP \u2192 Q, we thus *assume* that P is true\n(and in constructive logic this means we\nassume we have a proof of it, p : P), and\nin the context of this assumption, we show\nthat Q must be true, in the sense that we\ncan produce evidence (q : Q) that this is\nthe case.\n\nThis is a long way of saying that to prove\nP \u2192 Q, we assume we have a proof of P and\nin this context we must produce a proof of\nQ. In the constructive logic of Lean, this\nmeans we prove P \u2192 Q by showing that there\nis a function of type P to Q! Of course a\nfunction of this type is really a function\nof type \u2200 (p : P), Q, which is notation for\n\u03a0 (p : P), Q which is just a non-dependent\nfunction type, P \u2192 Q. It all makes sense! \n-/\n\nlemma and_commutes' : \u2200 {P Q : Prop}, P \u2227 Q \u2192 Q \u2227 P :=\n\u03bb P Q, \u03bb h, and.intro (h.right) (h.left) \n\n/-\nThis is the introduction rule for \u2192. Assume \nyou have a proof of the antcedent (P \u2227 Q in \nthis case) and show that in that context\nthere is a proof of the conclusion (Q \u2227 P).\n-/\n\n/-\nElimination\n-/\naxioms (Person : Type) (fromCville : Person \u2192 Prop)\naxioms (Kevin Liu : Person) (kfc : fromCville Kevin) (lfc : fromCville Liu)\n\n-- let's construct a proof of fromCville Kevin \u2227 fromCville Liu (P \u2227 Q)\ntheorem bfc : fromCville Kevin \u2227 fromCville Liu := and.intro kfc lfc\n\n#check bfc\n#reduce bfc\n\n-- now we can *apply* and_commutes' to derive a proof of (Q \u2227 P)\n\n#check and_commutes' bfc\n#reduce and_commutes' bfc", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/inClassNotes/predicate_logic/impl.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7412422019960033}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport group_theory.quotient_group\nimport set_theory.fincard\n\n/-!\n# Index of a Subgroup\n\nIn this file we define the index of a subgroup, and prove several divisibility properties.\nSeveral theorems proved in this file are known as Lagrange's theorem.\n\n## Main definitions\n\n- `H.index` : the index of `H : subgroup G` as a natural number,\n  and returns 0 if the index is infinite.\n- `H.relindex K` : the relative index of `H : subgroup G` in `K : subgroup G` as a natural number,\n  and returns 0 if the relative index is infinite.\n\n# Main results\n\n- `card_mul_index` : `nat.card H * H.index = nat.card G`\n- `index_mul_card` : `H.index * fintype.card H = fintype.card G`\n- `index_dvd_card` : `H.index \u2223 fintype.card G`\n- `index_eq_mul_of_le` : If `H \u2264 K`, then `H.index = K.index * (H.subgroup_of K).index`\n- `index_dvd_of_le` : If `H \u2264 K`, then `K.index \u2223 H.index`\n- `relindex_mul_relindex` : `relindex` is multiplicative in towers\n\n-/\n\nnamespace subgroup\n\nopen_locale cardinal\n\nvariables {G : Type*} [group G] (H K L : subgroup G)\n\n/-- The index of a subgroup as a natural number, and returns 0 if the index is infinite. -/\n@[to_additive \"The index of a subgroup as a natural number,\nand returns 0 if the index is infinite.\"]\nnoncomputable def index : \u2115 :=\nnat.card (G \u29f8 H)\n\n/-- The relative index of a subgroup as a natural number,\n  and returns 0 if the relative index is infinite. -/\n@[to_additive \"The relative index of a subgroup as a natural number,\n  and returns 0 if the relative index is infinite.\"]\nnoncomputable def relindex : \u2115 :=\n(H.subgroup_of K).index\n\n@[to_additive] lemma index_comap_of_surjective {G' : Type*} [group G'] {f : G' \u2192* G}\n  (hf : function.surjective f) : (H.comap f).index = H.index :=\nbegin\n  letI := quotient_group.left_rel H,\n  letI := quotient_group.left_rel (H.comap f),\n  have key : \u2200 x y : G', setoid.r x y \u2194 setoid.r (f x) (f y) :=\n  \u03bb x y, iff_of_eq (congr_arg (\u2208 H) (by rw [f.map_mul, f.map_inv])),\n  refine cardinal.to_nat_congr (equiv.of_bijective (quotient.map' f (\u03bb x y, (key x y).mp)) \u27e8_, _\u27e9),\n  { simp_rw [\u2190quotient.eq'] at key,\n    refine quotient.ind' (\u03bb x, _),\n    refine quotient.ind' (\u03bb y, _),\n    exact (key x y).mpr },\n  { refine quotient.ind' (\u03bb x, _),\n    obtain \u27e8y, hy\u27e9 := hf x,\n    exact \u27e8y, (quotient.map'_mk' f _ y).trans (congr_arg quotient.mk' hy)\u27e9 },\nend\n\n@[to_additive] lemma index_comap {G' : Type*} [group G'] (f : G' \u2192* G) :\n  (H.comap f).index = H.relindex f.range :=\neq.trans (congr_arg index (by refl))\n  ((H.subgroup_of f.range).index_comap_of_surjective f.range_restrict_surjective)\n\nvariables {H K L}\n\n@[to_additive] lemma relindex_mul_index (h : H \u2264 K) : H.relindex K * K.index = H.index :=\n((mul_comm _ _).trans (cardinal.to_nat_mul _ _).symm).trans\n  (congr_arg cardinal.to_nat (equiv.cardinal_eq (quotient_equiv_prod_of_le h))).symm\n\n@[to_additive] lemma index_dvd_of_le (h : H \u2264 K) : K.index \u2223 H.index :=\ndvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h)\n\n@[to_additive] lemma relindex_subgroup_of (hKL : K \u2264 L) :\n  (H.subgroup_of L).relindex (K.subgroup_of L) = H.relindex K :=\n((index_comap (H.subgroup_of L) (inclusion hKL)).trans (congr_arg _ (inclusion_range hKL))).symm\n\n@[to_additive] lemma relindex_mul_relindex (hHK : H \u2264 K) (hKL : K \u2264 L) :\n  H.relindex K * K.relindex L = H.relindex L :=\nbegin\n  rw [\u2190relindex_subgroup_of hKL],\n  exact relindex_mul_index (\u03bb x hx, hHK hx),\nend\n\nvariables (H K L)\n\nlemma inf_relindex_right : (H \u2293 K).relindex K = H.relindex K :=\nbegin\n  rw [\u2190subgroup_of_map_subtype, relindex, relindex, subgroup_of, comap_map_eq_self_of_injective],\n  exact subtype.coe_injective,\nend\n\nlemma inf_relindex_left : (H \u2293 K).relindex H = K.relindex H :=\nby rw [inf_comm, inf_relindex_right]\n\nlemma inf_relindex_eq_relindex_sup [K.normal] : (H \u2293 K).relindex H = K.relindex (H \u2294 K) :=\ncardinal.to_nat_congr (quotient_group.quotient_inf_equiv_prod_normal_quotient H K).to_equiv\n\nlemma relindex_eq_relindex_sup [K.normal] : K.relindex H = K.relindex (H \u2294 K) :=\nby rw [\u2190inf_relindex_left, inf_relindex_eq_relindex_sup]\n\nvariables {H K}\n\nlemma relindex_dvd_of_le_left (hHK : H \u2264 K) :\n  K.relindex L \u2223 H.relindex L :=\nbegin\n  apply dvd_of_mul_left_eq ((H \u2293 L).relindex (K \u2293 L)),\n  rw [\u2190inf_relindex_right H L, \u2190inf_relindex_right K L],\n  exact relindex_mul_relindex (inf_le_inf_right L hHK) inf_le_right,\nend\n\nvariables (H K)\n\n@[simp, to_additive] lemma index_top : (\u22a4 : subgroup G).index = 1 :=\ncardinal.to_nat_eq_one_iff_unique.mpr \u27e8quotient_group.subsingleton_quotient_top, \u27e81\u27e9\u27e9\n\n@[simp, to_additive] lemma index_bot : (\u22a5 : subgroup G).index = nat.card G :=\ncardinal.to_nat_congr (quotient_group.quotient_bot.to_equiv)\n\n@[to_additive] lemma index_bot_eq_card [fintype G] : (\u22a5 : subgroup G).index = fintype.card G :=\nindex_bot.trans nat.card_eq_fintype_card\n\n@[simp, to_additive] lemma relindex_top_left : (\u22a4 : subgroup G).relindex H = 1 :=\nindex_top\n\n@[simp, to_additive] lemma relindex_top_right : H.relindex \u22a4 = H.index :=\nby rw [\u2190relindex_mul_index (show H \u2264 \u22a4, from le_top), index_top, mul_one]\n\n@[simp, to_additive] lemma relindex_bot_left : (\u22a5 : subgroup G).relindex H = nat.card H :=\nby rw [relindex, bot_subgroup_of, index_bot]\n\n@[to_additive] lemma relindex_bot_left_eq_card [fintype H] :\n  (\u22a5 : subgroup G).relindex H = fintype.card H :=\nH.relindex_bot_left.trans nat.card_eq_fintype_card\n\n@[simp, to_additive] lemma relindex_bot_right : H.relindex \u22a5 = 1 :=\nby rw [relindex, subgroup_of_bot_eq_top, index_top]\n\n@[simp, to_additive] lemma relindex_self : H.relindex H = 1 :=\nby rw [relindex, subgroup_of_self, index_top]\n\n@[simp, to_additive card_mul_index]\nlemma card_mul_index : nat.card H * H.index = nat.card G :=\nby { rw [\u2190relindex_bot_left, \u2190index_bot], exact relindex_mul_index bot_le }\n\n@[to_additive] lemma index_map {G' : Type*} [group G'] (f : G \u2192* G') :\n  (H.map f).index = (H \u2294 f.ker).index * f.range.index :=\nby rw [\u2190comap_map_eq, index_comap, relindex_mul_index (H.map_le_range f)]\n\n@[to_additive] lemma index_map_dvd {G' : Type*} [group G'] {f : G \u2192* G'}\n  (hf : function.surjective f) : (H.map f).index \u2223 H.index :=\nbegin\n  rw [index_map, f.range_top_of_surjective hf, index_top, mul_one],\n  exact index_dvd_of_le le_sup_left,\nend\n\n@[to_additive] lemma dvd_index_map {G' : Type*} [group G'] {f : G \u2192* G'}\n  (hf : f.ker \u2264 H) : H.index \u2223 (H.map f).index :=\nbegin\n  rw [index_map, sup_of_le_left hf],\n  apply dvd_mul_right,\nend\n\n@[to_additive] lemma index_map_eq {G' : Type*} [group G'] {f : G \u2192* G'}\n  (hf1 : function.surjective f) (hf2 : f.ker \u2264 H) : (H.map f).index = H.index :=\nnat.dvd_antisymm (H.index_map_dvd hf1) (H.dvd_index_map hf2)\n\n@[to_additive] lemma index_eq_card [fintype (G \u29f8 H)] :\n  H.index = fintype.card (G \u29f8 H) :=\nnat.card_eq_fintype_card\n\n@[to_additive index_mul_card] lemma index_mul_card [fintype G] [hH : fintype H] :\n  H.index * fintype.card H = fintype.card G :=\nby rw [\u2190relindex_bot_left_eq_card, \u2190index_bot_eq_card, mul_comm]; exact relindex_mul_index bot_le\n\n@[to_additive] lemma index_dvd_card [fintype G] : H.index \u2223 fintype.card G :=\nbegin\n  classical,\n  exact \u27e8fintype.card H, H.index_mul_card.symm\u27e9,\nend\n\nvariables {H}\n\n@[simp] lemma index_eq_one : H.index = 1 \u2194 H = \u22a4 :=\n\u27e8\u03bb h, quotient_group.subgroup_eq_top_of_subsingleton H (cardinal.to_nat_eq_one_iff_unique.mp h).1,\n  \u03bb h, (congr_arg index h).trans index_top\u27e9\n\nlemma index_ne_zero_of_fintype [hH : fintype (G \u29f8 H)] : H.index \u2260 0 :=\nby { rw index_eq_card, exact fintype.card_ne_zero }\n\nlemma one_lt_index_of_ne_top [fintype (G \u29f8 H)] (hH : H \u2260 \u22a4) : 1 < H.index :=\nnat.one_lt_iff_ne_zero_and_ne_one.mpr \u27e8index_ne_zero_of_fintype, mt index_eq_one.mp hH\u27e9\n\nend subgroup\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/group_theory/index.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7412421959292209}}
{"text": "/-\nCopyright (c) 2021 Arthur Paulino. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Arthur Paulino, Kyle Miller\n-/\n\nimport combinatorics.simple_graph.coloring\n\n/-!\n# Graph partitions\n\nThis module provides an interface for dealing with partitions on simple graphs. A partition of\na graph `G`, with vertices `V`, is a set `P` of disjoint nonempty subsets of `V` such that:\n\n* The union of the subsets in `P` is `V`.\n\n* Each element of `P` is an independent set. (Each subset contains no pair of adjacent vertices.)\n\nGraph partitions are graph colorings that do not name their colors.  They are adjoint in the\nfollowing sense. Given a graph coloring, there is an associated partition from the set of color\nclasses, and given a partition, there is an associated graph coloring from using the partition's\nsubsets as colors.  Going from graph colorings to partitions and back makes a coloring \"canonical\":\nall colors are given a canonical name and unused colors are removed.  Going from partitions to\ngraph colorings and back is the identity.\n\n## Main definitions\n\n* `simple_graph.partition` is a structure to represent a partition of a simple graph\n\n* `simple_graph.partition.parts_card_le` is whether a given partition is an `n`-partition.\n  (a partition with at most `n` parts).\n\n* `simple_graph.partitionable n` is whether a given graph is `n`-partite\n\n* `simple_graph.partition.to_coloring` creates colorings from partitions\n\n* `simple_graph.coloring.to_partition` creates partitions from colorings\n\n## Main statements\n\n* `simple_graph.partitionable_iff_colorable` is that `n`-partitionability and\n  `n`-colorability are equivalent.\n\n-/\n\nuniverses u v\n\nnamespace simple_graph\nvariables {V : Type u} (G : simple_graph V)\n\n/--\nA `partition` of a simple graph `G` is a structure constituted by\n* `parts`: a set of subsets of the vertices `V` of `G`\n* `is_partition`: a proof that `parts` is a proper partition of `V`\n* `independent`: a proof that each element of `parts` doesn't have a pair of adjacent vertices\n-/\nstructure partition :=\n(parts : set (set V))\n(is_partition : setoid.is_partition parts)\n(independent : \u2200 (s \u2208 parts), is_antichain G.adj s)\n\n/-- Whether a partition `P` has at most `n` parts. A graph with a partition\nsatisfying this predicate called `n`-partite. (See `simple_graph.partitionable`.) -/\ndef partition.parts_card_le {G : simple_graph V} (P : G.partition) (n : \u2115) : Prop :=\n\u2203 (h : P.parts.finite), h.to_finset.card \u2264 n\n\n/-- Whether a graph is `n`-partite, which is whether its vertex set\ncan be partitioned in at most `n` independent sets. -/\ndef partitionable (n : \u2115) : Prop :=\n\u2203 (P : G.partition), P.parts_card_le n\n\nnamespace partition\nvariables {G} (P : G.partition)\n\n/-- The part in the partition that `v` belongs to -/\ndef part_of_vertex (v : V) : set V :=\nclassical.some (P.is_partition.2 v)\n\nlemma part_of_vertex_mem (v : V) : P.part_of_vertex v \u2208 P.parts :=\nby { obtain \u27e8h, -\u27e9 := (P.is_partition.2 v).some_spec.1, exact h, }\n\nlemma mem_part_of_vertex (v : V) : v \u2208 P.part_of_vertex v :=\nby { obtain \u27e8\u27e8h1, h2\u27e9, h3\u27e9 := (P.is_partition.2 v).some_spec, exact h2.1 }\n\nlemma part_of_vertex_ne_of_adj {v w : V} (h : G.adj v w) :\n  P.part_of_vertex v \u2260 P.part_of_vertex w :=\nbegin\n  intro hn,\n  have hw := P.mem_part_of_vertex w,\n  rw \u2190hn at hw,\n  have h' := P.independent _ (P.part_of_vertex_mem v) _ (P.mem_part_of_vertex v),\n  exact h' w hw (G.ne_of_adj h) h,\nend\n\n/-- Create a coloring using the parts themselves as the colors.\nEach vertex is colored by the part it's contained in. -/\ndef to_coloring : G.coloring P.parts :=\ncoloring.mk (\u03bb v, \u27e8P.part_of_vertex v, P.part_of_vertex_mem v\u27e9) $ \u03bb _ _ hvw,\nby { rw [ne.def, subtype.mk_eq_mk], exact P.part_of_vertex_ne_of_adj hvw }\n\n/-- Like `simple_graph.partition.to_coloring` but uses `set V` as the coloring type. -/\ndef to_coloring' : G.coloring (set V) :=\ncoloring.mk P.part_of_vertex $ \u03bb _ _ hvw, P.part_of_vertex_ne_of_adj hvw\n\nlemma to_colorable [fintype P.parts] : G.colorable (fintype.card P.parts) :=\nP.to_coloring.to_colorable\n\nend partition\n\nvariables {G}\n\n/-- Creates a partition from a coloring. -/\n@[simps]\ndef coloring.to_partition {\u03b1 : Type v} (C : G.coloring \u03b1) : G.partition :=\n{ parts := C.color_classes,\n  is_partition := C.color_classes_is_partition,\n  independent := begin\n    rintros s \u27e8c, rfl\u27e9,\n    apply C.color_classes_independent,\n  end }\n\ninstance : inhabited (partition G) := \u27e8G.self_coloring.to_partition\u27e9\n\nlemma partitionable_iff_colorable {n : \u2115} :\n  G.partitionable n \u2194 G.colorable n :=\nbegin\n  split,\n  { rintro \u27e8P, hf, h\u27e9,\n    haveI : fintype P.parts := hf.fintype,\n    rw set.finite.card_to_finset at h,\n    apply P.to_colorable.of_le h, },\n  { rintro \u27e8C\u27e9,\n    refine \u27e8C.to_partition, C.color_classes_finite_of_fintype, le_trans _ (fintype.card_fin n).le\u27e9,\n    generalize_proofs h,\n    haveI : fintype C.color_classes := C.color_classes_finite_of_fintype.fintype,\n    rw h.card_to_finset,\n    exact C.card_color_classes_le },\nend\n\nend simple_graph\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/combinatorics/simple_graph/partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7412421956360975}}
{"text": "/-\nA logic is a \"formal language\" that has\na mathematically defined syntax and a\nmathematically defined semantics. \n\nWe now drill down on the notions of the\nsyntax and semantics of a formal language.\nThe syntax of a language defines the set\nof valid expressions in the language. In\npredicate logic, for example, \u2200 p: Person,\n\u2203 m : Person, motherOf p m is syntactically\nwell formed, but ()\u2200 \u2203 r() is not.\n\nThe semantics of a language then assigns \na meaning each \"well formed\" expression\nin the language.\n\nWhen the formal language is a logic, the\nsyntax defines a language of propositions,\npredicates, etc., while a semantics tells\nus how to evaluate the truth of any such\nexpression.\n-/\n\n/-\nIn this unit we formalize the syntax and\nsemantics of what we call propositional \n(as opposed to predicate) logic. \n\nPropositional logic is a very simple logic.\nIt essentially mirrors (is \"isomorphic to\") \nthe language of Boolean expressions.\n\nThere are only a few kinds of expressions\nin propositional logic. These constitute\nthe syntax of this formal language.\n\n* \"literal expressions\" for true and false\n* \"variable expressions\"\n* \"not expressions\"\n* \"and expressions\"\n* \"or expressions\"\n* etc.\n\nThe semantics then gives us a way to decide\nwhat each expression in a language means.\nIn propositional logic an expression means\n(\"is\") either true or false. Here are the\nrules.\n\n* literal true evaluates to true\n\n* literal false evaluates to false\n\n* the value of an \"and\" expression, \ne1 \u2227 e2, is the Boolean conjunction \nof the values of e1 and e2, resp.\n\n* the value of a \"not\" expression,\n\u00ac e, is the Boolean negation of the \nvalue of e\n\n* this leaves the question of the value \nof a variable expression. For this we \nneed an additional idea: that of an \ninterpretation. An interpretation is an\nassignment of Boolean values to each of\nthe variables that might appear in some \nexpression. Now, to evaluate a variable \nexpression, X, we just \"look up\" its value\nin a given interpretation. A variable \nexpression will thus have different values \nunder different interpretations. Thus, \nexpressions, in general, because they \ngenerally involve variables, will have \ndifferent values under different \ninterpretations.\n\nWe now show you how not only to make these\nideas precise, but how to automate them, in\nLean. You are about to implement your own\nsimple automated logical reasoning system!\n-/\n\n-- Syntax\n\n/-\nWe formalize the syntax of a language \nwith an inductive definition of the set\nof valid expressions.\n\nAn expression in propositional logic \nis built from a (1) a logical constant,\ntrue or false, (2) a propositional (you\ncan think \"Boolean\") variable, or (3) a\nlogical connective (and, or, not, etc)\nand one or more smaller expressions.\n-/\n\n/-\nTo formalize this idea, we need to \ndefine what we mean by a variable. \nWe do with with a new type, pVar,\nwhere each such variable holds a \u2115\nvalue that distinguishes it from any\nother propVar. \n-/\n\ninductive pVar : Type \n| mk : \u2115 \u2192 pVar\n\n-- Examples\n\n#check (pVar.mk 0)\n\n-- Nice names for a few pVars\n\ndef X := pVar.mk 0\ndef Y := pVar.mk 1\ndef Z := pVar.mk 2\ndef W := pVar.mk 3\n\n/-\nNow we formalize a language of\nexpressions in propositional logic. \n-/\n\ninductive pExp : Type\n| mk_lit_pexp : bool \u2192 pExp\n| mk_var_pexp : pVar \u2192 pExp\n| mk_not_pexp : pExp \u2192 pExp\n| mk_and_pexp : pExp \u2192 pExp \u2192 pExp\n\nopen pExp\n\n-- Examples of expressions\n\ndef false_exp := mk_lit_pexp ff\n#check false_exp\n\ndef true_exp := mk_lit_pexp tt\n\ndef X_exp := mk_var_pexp X\ndef Y_exp := mk_var_pexp Y\ndef Z_exp := mk_var_pexp Z\n#reduce Z_exp\n\ndef not_X_exp := mk_not_pexp X_exp\ndef and_X_Y_exp := mk_and_pexp X_exp Y_exp\ndef and_X_Z_exp := mk_and_pexp X_exp Z_exp\n#reduce and_X_Z_exp\n\n-- syntactic sugar!\n\nnotation e1 \u2227 e2 :=  mk_and_pexp e1 e2\nnotation \u00ac e := mk_not_pexp e\n\n-- expressions using our notation!\ndef not_X_exp' := \u00ac X_exp\ndef and_X_Y_exp' := X_exp \u2227 Y_exp\ndef and_X_Z_exp' := X_exp \u2227 Z_exp\n\n\n-- Quiz\n\ndef tf := (mk_lit_pexp tt) \u2227 (mk_lit_pexp ff)\ndef nt := \u00ac (mk_lit_pexp tt)\ndef nxy := \u00ac (X_exp \u2227 Y_exp)\ndef foo := nt \u2227 nxy\ndef bar := (\u00ac nxy) \u2227 foo\ndef baz : pExp := tf\n\ndef jab := \u00ac (X_exp \u2227 Y_exp)\n#reduce jab \n\n-- Semantics\n\n/-\nTo formalize a semantics for our\nrealization of propositional logic,\nwe need to formally define what we\nmean by an interpretation.\n\nAn interpretation in propositional \nlogic is a function from propositional\nvariables to corresponding (Boolean)\ntruth values. An interpretation tells\nus what each variable \"means\" -- i.e.,\nwhether it means true, or false. \n\nWe now define a name for the type\nof an interpretation (pVar \u2192 bool).\nThen we present several examples of\ninterpretations.\n-/\n\ndef pInterp := pVar \u2192 bool\n\n-- an \"all false\" interpretation\ndef falseInterp (v : pVar) : bool :=\n    ff\n\n-- an \"all true\" interpretation\ndef trueInterp (v : pVar) :=\n    tt\n\n-- X = tt, Y=ff, Z=tt, _ = ff\n\ndef anInterp: pInterp :=\n\u03bb(v: pVar),\n  match v with\n  | (pVar.mk 0) := tt     -- X\n  | (pVar.mk 1) := ff     -- Y\n  | (pVar.mk 2) := tt     -- Z\n  | _ := ff               -- otherwise\n  end\n\n-- Semantics\n\n/-\nWe now define a semantics for our\nlanguage in the form of a function\nthat, when given any expression in\nour language *and* an interpretation\nfor the variables that might appear\nin it, evaluates its truth value and\nreturns it as a result.\n\nThe definition is by cases, i.e., \nwith one rule for each possible form\n(constructor) of expression.\n\nNote: Lean \"overloads\" logical\noperator notations, such as \u2227, \u2228, \nand \u00ac. Here they are applied not to\nvalues of type Prop, but to values \nof type bool, where they have their\nusual means from Boolean algebra.\n-/\n\ndef pEval : pExp \u2192 pInterp \u2192 bool \n-- how to evaluate literal expression\n| (mk_lit_pexp b) i := b\n-- how to evaluate variable expression\n| (mk_var_pexp v) i := i v\n-- how to evaluate a \"not\" expression\n| (mk_not_pexp e) i := bnot (pEval e i)\n-- how to evaluate an \"and\" expression\n| (mk_and_pexp e1 e2) i := \n    band (pEval e1 i) (pEval e2 i)\n\n/-\nAnd now we have a formal language, with\na syntax, interpretations, and semantics.\nLet's evaluate some of our expressions\nunder varying interpretations.\n-/\n\n-- literal expressions\n\n/-\n#reduce pEval tt_exp falseInterp\n#reduce pEval tt_exp trueInterp\n#reduce pEval tt_exp anInterp\n\n#reduce pEval ff_exp falseInterp\n#reduce pEval ff_exp trueInterp\n#reduce pEval ff_exp anInterp\n-/\n\n-- variable expressions\n#reduce pEval X_exp falseInterp\n#reduce pEval X_exp trueInterp\n#reduce pEval X_exp anInterp\n\n#reduce pEval Y_exp falseInterp\n#reduce pEval Y_exp trueInterp\n#reduce pEval Y_exp anInterp\n\n#reduce pEval Z_exp falseInterp\n#reduce pEval Z_exp trueInterp\n#reduce pEval Z_exp anInterp\n\n#reduce pEval (mk_var_pexp W) falseInterp\n#reduce pEval (mk_var_pexp W) trueInterp\n#reduce pEval (mk_var_pexp W) anInterp\n\n-- We don't have to give variables names\n#reduce pEval (mk_var_pexp (pVar.mk 10)) anInterp\n\n-- not expression\n#reduce pEval not_X_exp falseInterp\n#reduce pEval not_X_exp trueInterp\n#reduce pEval not_X_exp anInterp\n\n-- and expressio\n#reduce pEval and_X_Z_exp falseInterp\n#reduce pEval and_X_Z_exp trueInterp\n#reduce pEval and_X_Z_exp anInterp\n\n#reduce pEval and_X_Z_exp' falseInterp\n#reduce pEval and_X_Z_exp' trueInterp\n#reduce pEval and_X_Z_exp' anInterp\n\n#reduce pEval and_X_Y_exp anInterp\n\n/-\nSo there you have it: a complete\nformal definition of the syntax,\ninterpretation, and semantics of\npropositional logic, in Lean, with\na nice \"surface syntax,\" to boot.\n(Ok, it's complete except for the\ndefinitions for the other logical\nconnectives. You will add some of\nthem in homework and on the exam.)\n-/\n\n/-\nFrom here, we can define richer\nfunctions, such as functions that\nanalyze expressions; and we can\neven state and prove theorems \nabout our language.\n-/\n\n/-\nLet's define a function that \nreturns the set of variables \nin a given pExp. This will be\nuseful in the future.\n-/\n\n/-\nWe start by defining a recursive \nhelper function that adds all the \nvariables in given expression to \nthe given, often already non-empty, \nset of variables.\n\nUnderstand the type and purpose of\nthis function, then go on to read \nthe following main function. Study\nits purpose, type, and implementation,\nthen come back for a deeper look at \nhow this function is implemented.\nLearn to use functions knowing only\ntheir type and purpose, ignoring, at\nleast at first, their implementation\ndetails. Pratice mental abstracting.\n\nWe implement (prove) this recursive \nfunction (type) by case analysis on \npossible forms of the given pExp.\n-/\ndef vars_in_exp_helper: \n    pExp \u2192 set pVar \u2192 set pVar\n\n-- literal expressions add no variables to the set\n| (mk_lit_pexp _) s := s\n-- a variable expression adds variable v to the set\n| (mk_var_pexp v) s := s \u222a { v }\n-- a (not e) expression adds the variables in e\n| (mk_not_pexp e) s := \n    s \u222a (vars_in_exp_helper e s)\n-- an (and e1 e2), add the variables in e1 and e2 \n| (mk_and_pexp e1 e2) s := \n    s \u222a \n    (vars_in_exp_helper e1 s) \u222a \n    (vars_in_exp_helper e2 s)\n\n/-\nMain function: a non-recursive function\nthat passes an initially empty set of\nvariables to the helper function and \nthen gets back a set of all, and only,\nthe variables in the given expression.\n-/\ndef vars_in_exp (e: pExp) : set pVar :=\n    vars_in_exp_helper e ({}: set pVar)\n\n\n/-\nExamples of its use\n-/\n#reduce vars_in_exp and_X_Y_exp\n-- A predicate defining the set { X, Y \n\n/-\nAnother example\n-/\n#reduce vars_in_exp and_X_Z_exp\n\n/-\nEXERCISE: Write a function that when\ngiven an expression, e, returns the \n\"nesting depth\" of the expression. The\nnesting depth of a literal or variable\nexpression is 1. The depth of a (not e) \nexpression is 1 + the depth of e. And\nthe depth of an (and e1 e2) expression\nis 1 + the max of the depths of e1 and\ne2. You can use the Lean-provided max \nfunction in your answer.\n-/\n\n#reduce max 5 7\n#reduce max 7 5\n\n/-\nWe can also prove theorems about\nour language in general. Here's a\nproof that evaluation under a given\ninterpretation is \"deterministic:: \nit always produces the same result.\n\nThis is really just a corollary of\nthe facts that (1) functions in Lean \nare single valued and (2) we defined \nthe semantics of expressions with a\nfunction. There's one and only one \nanswer for the value of any given\nexpression.\n-/\n\ntheorem pEval_deterministic :\n\u2200 e : pExp, \n\u2200 i : pInterp,\n\u2200 v1 v2 : bool,\nv1 = pEval e i \u2192 v2 = pEval e i \u2192 v1 = v2 :=\nbegin\nintros e i v1 v2 h_v1 h_v2,\nrw h_v1, \nrw h_v2,\nend\n\n\n/-\nWe can also prove theorems (\"reason\nabout\") particular expressions, or\ncertain classes of expressions, in \nour language. For example, if X_exp \nis any variable expression, then the \nexpression (X_exp \u2227 (\u00ac X_exp)) is \nfalse under any interpretation. We\ncan easily prove this proposition.\n-/\n\ntheorem contra :\n\u2200 V : pVar,\n\u2200 i : pInterp,\npEval \n    ((mk_var_pexp V) \u2227 \u00ac (mk_var_pexp V)) i = ff \n:=\nbegin\nintros X i,\nsimp [pEval],\n-- case analysis on result of function!\ncases (i X),\nleft, apply rfl,\nright, apply rfl,\nend\n\n/-\nNote that it is quantified over all\npossible interpretations: over all\npossible functions from pVar \u2192 bool.\nLean supports what is called higher\norder predicate logic. Quantifying\nover functions and relations is ok\nin a higher-order predicate logic. \nIt is not allowed in the first-order\npredicate logic of everyday math and\ncomputer science. Here you can see\nthat it gives you great expressive\npower to be able to quantify over\nfunctions. It gives us a way to say,\n\"under any possible interpretation\",\nwhich is exactly what we need to be\nable to say to define satisfiability,\nvalidity, unsatisfiability, etc.\n-/\n\n\n\n/-\nExercise: Prove that for any \nvariable, V, the logical expression\n(mk_var_exp V) \u2228 (\u00ac (mk_var_exp V))\nalways evaluates to true.\n-/\n\ndef valid (e : pExp) : Prop :=\n    \u2200 i : pInterp, pEval e i = tt\n\n/-\nAn expression in propositional logic\nis unsatisfiable if it does'ot evaluate \nto true under any interpretation.\n-/\n\ndef unsatisfiable (e : pExp) : Prop :=\n    \u2200 i, pEval e i = ff\n\n/-\nYou could also have said there does not\nexist an i that makes (pEval e i) = tt.\n-/\n\n/-\nAn interpretation that makes an\nexpression, e, evaluate to true,\nis said to be a \"model\" of that\nexpression. Here's a predicate\nasserting that i is a model of e.\n-/\n\ndef isModel (i: pInterp) (e : pExp) :=\n    pEval e i = tt\n\n/-\nAn expression is said to be satisfiable \nif there is at least one interpretation \nunder which it evaluates to true.\n-/\ndef satisfiable (e : pExp) : Prop :=\n    \u2203 i, isModel i e\n\n/-\nExample: X \u2227 \u00ac X is unsatisfiable.\n-/\n\nexample : unsatisfiable (X_exp \u2227 (\u00ac (X_exp))) :=\nbegin\nunfold unsatisfiable,\nintro i,\nrw pEval, -- you can do this\nrw pEval, -- and do it again\ncases (pEval X_exp i), -- cool!\ntrivial,\ntrivial,\nend\n\n/-\nEXERCISE: Once you've extended\nour logic with an or operator,\nformulize and prove the proposition\nthat (our rendering of) X \u2228 (\u00ac X)\nis valid.\n\nEXERCISE: Prove the proposition\nthat (X \u2228 Y) \u2227 Z is satisfiable.\nHint: You'll need a witness. There\nis an element of search involved\nin solving a problem like this.\n-/\n\n/-\nEXERCISE: Write a SAT solver based\non what we've done here.\n-/\n\n-- m'th bit from right in binary rep of n\ndef mrbn: \u2115 \u2192 \u2115 \u2192 bool \n| 0 n := n % 2 = 1\n| (nat.succ m') n := mrbn m' (n/2) \n\n/- smoke test\n#reduce mrbn 0 15\n#reduce mrbn 2 15\n#reduce mrbn 2 15\n#reduce mrbn 3 15\n#reduce mrbn 4 15\n#reduce mrbn 5 15\n-/\n\n/-\nThe mth canonical interpretation\namong the 2^n-1 interpretations\nfor a set of variables of size n.\n\nThe values of the first n-indexed\nvariables in the mth interpretation\nare determined by the bits in the \nbinary representation of m. The\nleftmost bit gives the value for \nthe variable with index 0. Each\nbit to the left gives the value of\nthe next indexed variable. All \nsubsequent values are ff. m thus \neffectively enumerates the 2^n \ninterpretations on the n first \nvariables in the index set of all\nvariables. \n-/\n\ndef mthInterpOf2toN (m n: \u2115) : pInterp :=\n    if (m >= 2^n)\n    then falseInterp \n    else\n    \u03bb v : pVar, \n        match v with\n        | (pVar.mk i) := \n        if i >= n then \n        ff \n        else \n        (mrbn i m)\n        end\n\n/-\nExamples:\n-/\n\n#reduce pEval and_X_Y_exp (mthInterpOf2toN 3 3)\n\n-- unincorporated\n\n#reduce mthInterpOf2toN 3 5\n\ndef first_n_true_inter (n : \u2115) : pInterp :=\n\u03bb v, \n    match v with\n    | (pVar.mk n') := if n' < n then tt else ff\n    end\n\ndef all_models (e : pExp) :=\n    { m | isModel m e}\n\n\ndef sat_solve (e : pExp) : option pInterp :=\nnone\n\n\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm-lean", "sha": "a06a94e98be77170ca1df486c8189338b16cf6c6", "save_path": "github-repos/lean/kevinsullivan-cs-dm-lean", "path": "github-repos/lean/kevinsullivan-cs-dm-lean/cs-dm-lean-a06a94e98be77170ca1df486c8189338b16cf6c6/src/15_Formal_Languages/00_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7412421904486844}}
{"text": "variables P Q R :  Prop\n\ntheorem basic_logic : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\nintro H, -- H is \"P implies Q and Q implies R\"\nintro HP, -- we want P -> R so let's assume P.\nhave HQ : Q,\nexact H.left HP, -- apply P->Q to P to get Q.\n-- now we can get the goal\nexact H.right HQ\nend", "meta": {"author": "Samyak-Surti", "repo": "LeanCode", "sha": "944eac3e5f43e2614ed246083b97fbdf24181d83", "save_path": "github-repos/lean/Samyak-Surti-LeanCode", "path": "github-repos/lean/Samyak-Surti-LeanCode/LeanCode-944eac3e5f43e2614ed246083b97fbdf24181d83/lean_test/src/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.963779946215714, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7412241146206586}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# Prove that there exists infinitely many positive integers n such that\n# 4n\u00b2 + 1 is divisible both by 5 and 13.\n\nThis is the third question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\nMaths proof: if n=4 then 4n^2+1=65 is divisible by both 5 and 13\nso if n is congruent to 4 mod 5 and mod 13 (i.e if n=4+65*t)\nthen this will work.\n\nThere are various ways to formalise the statement that some set\nof naturals is infinite. We suggest two here (although proving\nthey're the same is fiddly)\n\n-/\n\n-- The number-theoretic heart of the argument.\n-- Note that \"divides\" is `\\|` not `|`\nlemma divides_of_cong_four (t : \u2115) : 5 \u2223 4 * (65 * t + 4)^2 + 1 \u2227\n13 \u2223 4 * (65 * t + 4)^2 + 1 :=\nbegin\n  sorry,\nend\n\n-- There are arbitrarily large solutions to `5 \u2223 4*n^2+1 \u2227 13 \u2223 4*n^2+1`\nlemma arb_large_soln : \u2200 N : \u2115, \u2203 n > N, 5 \u2223 4*n^2+1 \u2227 13 \u2223 4*n^2+1 :=\nbegin\n  sorry,\nend\n\n-- This is not number theory any more, it's switching between two\n-- interpretations of \"this set of naturals is infinite\".\n-- One way is `set.infinite.exists_nat_lt`, the other\n-- way is `finset.sup`.\nlemma infinite_iff_arb_large (S : set \u2115) : S.infinite \u2194 \u2200 N, \u2203 n > N, n \u2208 S :=\nbegin\n  sorry,\nend\n\n-- Another way of stating the question (note different \"|\" symbols:\n-- there's `|` for \"such that\" in set theory and `\\|` for \"divides\" in number theory)\nlemma infinite_set_of_solutions : {n : \u2115 | 5 \u2223 4*n^2+1 \u2227 13 \u2223 4*n^2+1}.infinite :=\nbegin\n  rw infinite_iff_arb_large,\n  exact arb_large_soln,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section15number_theory/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7412225485539549}}
{"text": "import Fd.Init\n\n/-!\n# Magma and Other Group-Like Structures\n\nSee [magma on wikipedia][magma]. In particular, see [classification by properties][details] for a\nbreakdown of group-like structures, some of which will appear below.\n\nWe avoid mentioning associativity as a desperate attempt to include `Float`s, which have\nnon-commutative addition/multiplication. However, these operations are **supposed to be**\ncommutative: most *standards* do require commutativity, but some *implementations* don't actually\nrespect that. See Ariane 5's crash for instance (I think).\n\n[magma]: https://en.wikipedia.org/wiki/Magma_(algebra)\n[details]: https://en.wikipedia.org/wiki/Magma_(algebra)#Classification_by_properties\n-/\n\n\n--- A *magma* is just an `\u03b1`-closed operation `law`.\nclass Magma (\u03b1 : Type u) where\n  law : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n\nopen Magma (law)\n\ninfix:65 \" \u00b7\u2098 \" => law\n\n\n\nsection AddMagma\n  --- Addition magma.\n  class AddMagma (\u03b1 : Type u)\n  extends HAdd \u03b1 \u03b1 \u03b1\n\n  infix:65 \" +\u2098 \" => AddMagma.law\n\n  --- `Add \u2192 AddMagma`\n  @[simp, inline]\n  instance Add_to_AddMagma [HAdd \u03b1 \u03b1 \u03b1] : AddMagma \u03b1 :=\n    {}\n\n  --- `AddMagma \u2192 Magma`\n  @[simp, inline]\n  instance AddMagma_to_Magma [inst : AddMagma \u03b1] : Magma \u03b1 where\n    law := inst.hAdd\n\n  example : AddMagma Nat :=\n    inferInstance\n  example : Magma Nat :=\n    inferInstance\n  example : AddMagma Int :=\n    inferInstance\n  example : Magma Int :=\n    inferInstance\nend AddMagma\n\n\n\nsection MulMagma\n  --- Multiplication magma.\n  class MulMagma (\u03b1 : Type u)\n  extends HMul \u03b1 \u03b1 \u03b1\n\n  infix:70 \" *\u2098 \" => MulMagma.law\n\n  --- `Mul \u2192 MulMagma`\n  @[simp, inline]\n  instance Mul_to_MulMagma [HMul \u03b1 \u03b1 \u03b1] : MulMagma \u03b1 :=\n    {}\n\n  --- `MulMagma \u2192 Magma`\n  @[simp, inline]\n  instance MulMagma_to_Magma [inst : MulMagma \u03b1] : Magma \u03b1 where\n    law := inst.hMul\n\n  example : MulMagma Nat :=\n    inferInstance\n  example : Magma Nat :=\n    inferInstance\n  example : MulMagma Int :=\n    inferInstance\n  example : Magma Int :=\n    inferInstance\nend MulMagma\n\n\n\nsection UMagma\n  --- A *unital magma* is a `Magma` with a unit element.\n  class Magma.Unital (\u03b1 : Type u)\n  extends\n    Magma \u03b1\n  where\n    unitElm : \u03b1\n    unit_left :\n      \u2200 (a : \u03b1), unitElm \u00b7\u2098 a = a\n    unit_right :\n      \u2200 (a : \u03b1), a \u00b7\u2098 unitElm = a\n\n  notation \"unit\u2098\" => Magma.Unital.unitElm\n  notation \"<0>\" => unit\u2098\n  notation \"<1>\" => unit\u2098\n\n\n\n  class Magma.AddUnital (\u03b1 : Type u)\n  extends\n    AddMagma \u03b1,\n    Zero \u03b1\n  where\n    zero_add :\n      \u2200 a, zero + a = a\n    add_zero :\n      \u2200 a, a + zero = a\n  \n  --- `AddUnital \u2192 Unital`.\n  instance [M : Magma.AddUnital \u03b1] : Magma.Unital \u03b1 where\n    unitElm :=\n      M.zero\n    unit_left :=\n      M.zero_add\n    unit_right :=\n      M.add_zero\n\n\n\n  class Magma.MulUnital (\u03b1 : Type u)\n  extends\n    MulMagma \u03b1,\n    One \u03b1\n  where\n    one_mul :\n      \u2200 a, one * a = a\n    mul_one :\n      \u2200 a, a * one = a\n  \n  --- `MulUnital \u2192 Unital`.\n  instance [M : Magma.MulUnital \u03b1] : Magma.Unital \u03b1 where\n    unitElm :=\n      M.one\n    unit_left :=\n      M.one_mul\n    unit_right :=\n      M.mul_one\n\n\n\n  instance instUnitalZeroNat : Magma.AddUnital Nat :=\n    \u27e8Nat.zero_add, Nat.add_zero\u27e9\n\n  instance instUnitalOneNat : Magma.MulUnital Nat :=\n    \u27e8Nat.one_mul, Nat.mul_one\u27e9\n\n  instance instUnitalZeroInt : Magma.AddUnital Int :=\n    \u27e8Int.zero_add, Int.add_zero\u27e9\n\n  instance instUnitalOneInt : Magma.MulUnital Int :=\n    \u27e8Int.one_mul, Int.mul_one\u27e9\nend UMagma\n\n\n\nsection Comm\n  --- A *commutative unital magma* is a `Magma.Unital` with a commutative law.\n  ---\n  --- Just called `Comm` and not, say, `CommUnital` for brievety.\n  class Magma.Comm (\u03b1 : Type u)\n  extends\n    Unital \u03b1\n  where\n    comm : commutes law\n\n\n  class Magma.AddComm (\u03b1 : Type u)\n  extends\n    AddUnital \u03b1\n  where\n    comm : commutes toAddUnital.hAdd\n  \n  --- `AddComm \u2192 Comm`\n  instance [inst : Magma.AddComm \u03b1] : Magma.Comm \u03b1 :=\n    \u27e8inst.comm\u27e9\n\n\n  class Magma.MulComm (\u03b1 : Type u)\n  extends\n    MulUnital \u03b1\n  where\n    comm : commutes toMulUnital.hMul\n  \n  --- `MulComm \u2192 Comm`\n  instance [inst : Magma.MulComm \u03b1] : Magma.Comm \u03b1 :=\n    \u27e8inst.comm\u27e9\n\n\n\n  instance instNatAddCommMagma : Magma.AddComm Nat where\n    comm :=\n      Nat.add_comm\n\n  instance instNatMulCommMagma : Magma.MulComm Nat where\n    comm :=\n      Nat.mul_comm\n\n  instance instIntAddCommMagma : Magma.AddComm Int where\n    comm :=\n      Int.add_comm\n\n  instance instIntMulCommMagma : Magma.MulComm Int where\n    comm :=\n      Int.mul_comm\nend Comm\n", "meta": {"author": "AdrienChampion", "repo": "experimentalean4", "sha": "5071a8b007029f61b2e996d9ac89d90999603fcc", "save_path": "github-repos/lean/AdrienChampion-experimentalean4", "path": "github-repos/lean/AdrienChampion-experimentalean4/experimentalean4-5071a8b007029f61b2e996d9ac89d90999603fcc/fdlean/Fd/Magma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7411893098679158}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la operaci\u00f3n m\u00ednimo en los ret\u00edculos es\n-- asociativa; es decir,\n--    (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z)\n-- ----------------------------------------------------------------------\n\nimport order.lattice\nimport tactic\n\nvariables {\u03b1 : Type*} [lattice \u03b1]\nvariables x y z : \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\nbegin\n  apply le_antisymm,\n  { apply le_inf,\n    calc\n        (x \u2293 y) \u2293 z  \u2264 (x \u2293 y)     : inf_le_left\n                    ... \u2264  x       : inf_le_left,\n    apply le_inf,\n    calc\n        (x \u2293 y) \u2293 z  \u2264 (x \u2293 y)     : inf_le_left\n                    ... \u2264  y       : inf_le_right,\n    calc\n        (x \u2293 y) \u2293 z  \u2264 z           : inf_le_right },\n  { apply le_inf,\n    apply le_inf,\n    calc\n        x \u2293 (y \u2293 z)  \u2264 x           : inf_le_left,\n    calc\n        x \u2293 (y \u2293 z)  \u2264 (y \u2293 z)     : inf_le_right\n                    ... \u2264  y       : inf_le_left,\n    calc\n        x \u2293 (y \u2293 z)  \u2264 (y \u2293 z)     : inf_le_right\n                    ... \u2264  z       : inf_le_right\n  }\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nprivate meta def infs :=\n`[refl <|>\n  {apply inf_le_of_left_le, infs} <|>\n  {apply inf_le_of_right_le, infs}]\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\nby apply le_antisymm; repeat {apply le_inf}; {infs}\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nmeta def tactic.interactive.lattice :=\n`[apply le_antisymm; repeat {apply le_inf}; infs]\n\nexample : (x \u2293 y) \u2293 z = x \u2293 (y \u2293 z) :=\nby lattice\n\nexample : x \u2293 y = y \u2293 x :=\nby lattice\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Asociatividad_del_minimo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7411893054072549}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro\n-/\nimport data.prod\nimport data.subtype\n\n/-!\n# Basic definitions about `\u2264` and `<`\n\nThis file proves basic results about orders, provides extensive dot notation, defines useful order\nclasses and allows to transfer order instances.\n\n## Type synonyms\n\n* `order_dual \u03b1` : A type synonym reversing the meaning of all inequalities.\n* `as_linear_order \u03b1`: A type synonym to promote `partial_order \u03b1` to `linear_order \u03b1` using\n  `is_total \u03b1 (\u2264)`.\n\n### Transfering orders\n\n- `order.preimage`, `preorder.lift`: Transfers a (pre)order on `\u03b2` to an order on `\u03b1`\n  using a function `f : \u03b1 \u2192 \u03b2`.\n- `partial_order.lift`, `linear_order.lift`: Transfers a partial (resp., linear) order on `\u03b2` to a\n  partial (resp., linear) order on `\u03b1` using an injective function `f`.\n\n### Extra class\n\n- `densely_ordered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such\n  that `a < c < b`.\n\n## Notes\n\n`\u2264` and `<` are highly favored over `\u2265` and `>` in mathlib. The reason is that we can formulate all\nlemmas using `\u2264`/`<`, and `rw` has trouble unifying `\u2264` and `\u2265`. Hence choosing one direction spares\nus useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.\n\nDot notation is particularly useful on `\u2264` (`has_le.le`) and `<` (`has_lt.lt`). To that end, we\nprovide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with\n`has_le.le.trans` and can be used to construct `hab.trans hbc : a \u2264 c` when `hab : a \u2264 b`,\n`hbc : b \u2264 c`, `lt_of_le_of_lt` is aliased as `has_le.le.trans_lt` and can be used to construct\n`hab.trans hbc : a < c` when `hab : a \u2264 b`, `hbc : b < c`.\n\n## TODO\n\n- expand module docs\n- automatic construction of dual definitions / theorems\n\n## Tags\n\npreorder, order, partial order, poset, linear order, chain\n-/\n\nopen function\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nlemma ge_antisymm [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) (hba : b \u2264 a) : b = a :=\nle_antisymm hba hab\n\nattribute [simp] le_refl\nattribute [ext] has_le\n\nalias le_trans        \u2190 has_le.le.trans\nalias lt_of_le_of_lt  \u2190 has_le.le.trans_lt\nalias le_antisymm     \u2190 has_le.le.antisymm\nalias ge_antisymm     \u2190 has_le.le.antisymm'\nalias lt_of_le_of_ne  \u2190 has_le.le.lt_of_ne\nalias lt_of_le_not_le \u2190 has_le.le.lt_of_not_le\nalias lt_or_eq_of_le  \u2190 has_le.le.lt_or_eq\nalias decidable.lt_or_eq_of_le \u2190 has_le.le.lt_or_eq_dec\n\nalias le_of_lt        \u2190 has_lt.lt.le\nalias lt_trans        \u2190 has_lt.lt.trans\nalias lt_of_lt_of_le  \u2190 has_lt.lt.trans_le\nalias ne_of_lt        \u2190 has_lt.lt.ne\nalias lt_asymm        \u2190 has_lt.lt.asymm has_lt.lt.not_lt\n\nalias le_of_eq        \u2190 eq.le\n\nattribute [nolint decidable_classical] has_le.le.lt_or_eq_dec\n\n/-- A version of `le_refl` where the argument is implicit -/\nlemma le_rfl [preorder \u03b1] {x : \u03b1} : x \u2264 x := le_refl x\n\n@[simp] lemma lt_self_iff_false [preorder \u03b1] (x : \u03b1) : x < x \u2194 false :=\n\u27e8lt_irrefl x, false.elim\u27e9\n\nnamespace eq\n\n/-- If `x = y` then `y \u2264 x`. Note: this lemma uses `y \u2264 x` instead of `x \u2265 y`, because `le` is used\nalmost exclusively in mathlib. -/\nprotected \n\nlemma trans_le [preorder \u03b1] {x y z : \u03b1} (h1 : x = y) (h2 : y \u2264 z) : x \u2264 z := h1.le.trans h2\n\nlemma not_lt [partial_order \u03b1] {x y : \u03b1} (h : x = y) : \u00ac(x < y) := \u03bb h', h'.ne h\n\nlemma not_gt [partial_order \u03b1] {x y : \u03b1} (h : x = y) : \u00ac(y < x) := h.symm.not_lt\n\nend eq\n\nnamespace has_le.le\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma ge [has_le \u03b1] {x y : \u03b1} (h : x \u2264 y) : y \u2265 x := h\n\nlemma trans_eq [preorder \u03b1] {x y z : \u03b1} (h1 : x \u2264 y) (h2 : y = z) : x \u2264 z := h1.trans h2.le\n\nlemma lt_iff_ne [partial_order \u03b1] {x y : \u03b1} (h : x \u2264 y) : x < y \u2194 x \u2260 y := \u27e8\u03bb h, h.ne, h.lt_of_ne\u27e9\n\nlemma le_iff_eq [partial_order \u03b1] {x y : \u03b1} (h : x \u2264 y) : y \u2264 x \u2194 y = x :=\n\u27e8\u03bb h', h'.antisymm h, eq.le\u27e9\n\nlemma lt_or_le [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a < c \u2228 c \u2264 b :=\n(lt_or_ge a c).imp id $ \u03bb hc, le_trans hc h\n\nlemma le_or_lt [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a \u2264 c \u2228 c < b :=\n(le_or_gt a c).imp id $ \u03bb hc, lt_of_lt_of_le hc h\n\nlemma le_or_le [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a \u2264 c \u2228 c \u2264 b :=\n(h.le_or_lt c).elim or.inl (\u03bb h, or.inr $ le_of_lt h)\n\nend has_le.le\n\nnamespace has_lt.lt\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma gt [has_lt \u03b1] {x y : \u03b1} (h : x < y) : y > x := h\nprotected lemma false [preorder \u03b1] {x : \u03b1} : x < x \u2192 false := lt_irrefl x\n\nlemma ne' [preorder \u03b1] {x y : \u03b1} (h : x < y) : y \u2260 x := h.ne.symm\n\nlemma lt_or_lt [linear_order \u03b1] {x y : \u03b1} (h : x < y) (z : \u03b1) : x < z \u2228 z < y :=\n(lt_or_ge z y).elim or.inr (\u03bb hz, or.inl $ h.trans_le hz)\n\nend has_lt.lt\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma ge.le [has_le \u03b1] {x y : \u03b1} (h : x \u2265 y) : y \u2264 x := h\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma gt.lt [has_lt \u03b1] {x y : \u03b1} (h : x > y) : y < x := h\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\ntheorem ge_of_eq [preorder \u03b1] {a b : \u03b1} (h : a = b) : a \u2265 b := h.ge\n\n@[simp, nolint ge_or_gt] -- see Note [nolint_ge]\nlemma ge_iff_le [preorder \u03b1] {a b : \u03b1} : a \u2265 b \u2194 b \u2264 a := iff.rfl\n@[simp, nolint ge_or_gt] -- see Note [nolint_ge]\nlemma gt_iff_lt [preorder \u03b1] {a b : \u03b1} : a > b \u2194 b < a := iff.rfl\n\nlemma not_le_of_lt [preorder \u03b1] {a b : \u03b1} (h : a < b) : \u00ac b \u2264 a := (le_not_le_of_lt h).right\n\nalias not_le_of_lt \u2190 has_lt.lt.not_le\n\nlemma not_lt_of_le [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) : \u00ac b < a := \u03bb hba, hba.not_le h\n\nalias not_lt_of_le \u2190 has_le.le.not_lt\n\nlemma ne_of_not_le [preorder \u03b1] {a b : \u03b1} (h : \u00ac a \u2264 b) : a \u2260 b :=\n\u03bb hab, h (le_of_eq hab)\n\n-- See Note [decidable namespace]\nprotected lemma decidable.le_iff_eq_or_lt [partial_order \u03b1] [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} : a \u2264 b \u2194 a = b \u2228 a < b := decidable.le_iff_lt_or_eq.trans or.comm\n\nlemma le_iff_eq_or_lt [partial_order \u03b1] {a b : \u03b1} : a \u2264 b \u2194 a = b \u2228 a < b :=\nle_iff_lt_or_eq.trans or.comm\n\nlemma lt_iff_le_and_ne [partial_order \u03b1] {a b : \u03b1} : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\n\u27e8\u03bb h, \u27e8le_of_lt h, ne_of_lt h\u27e9, \u03bb \u27e8h1, h2\u27e9, h1.lt_of_ne h2\u27e9\n\n-- See Note [decidable namespace]\nprotected lemma decidable.eq_iff_le_not_lt [partial_order \u03b1] [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 \u00ac a < b :=\n\u27e8\u03bb h, \u27e8h.le, h \u25b8 lt_irrefl _\u27e9, \u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.antisymm $\n  decidable.by_contradiction $ \u03bb h\u2083, h\u2082 (h\u2081.lt_of_not_le h\u2083)\u27e9\n\nlemma eq_iff_le_not_lt [partial_order \u03b1] {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 \u00ac a < b :=\nby haveI := classical.dec; exact decidable.eq_iff_le_not_lt\n\nlemma eq_or_lt_of_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2264 b) : a = b \u2228 a < b := h.lt_or_eq.symm\nlemma eq_or_gt_of_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2264 b) : b = a \u2228 a < b :=\nh.lt_or_eq.symm.imp eq.symm id\n\nalias decidable.eq_or_lt_of_le \u2190 has_le.le.eq_or_lt_dec\nalias eq_or_lt_of_le \u2190 has_le.le.eq_or_lt\nalias eq_or_gt_of_le \u2190 has_le.le.eq_or_gt\n\nattribute [nolint decidable_classical] has_le.le.eq_or_lt_dec\n\nlemma eq_of_le_of_not_lt [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) (hba : \u00ac a < b) : a = b :=\nhab.eq_or_lt.resolve_right hba\n\nlemma eq_of_ge_of_not_gt [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) (hba : \u00ac a < b) : b = a :=\n(hab.eq_or_lt.resolve_right hba).symm\n\nalias eq_of_le_of_not_lt \u2190 has_le.le.eq_of_not_lt\nalias eq_of_ge_of_not_gt \u2190 has_le.le.eq_of_not_gt\n\nlemma ne.le_iff_lt [partial_order \u03b1] {a b : \u03b1} (h : a \u2260 b) : a \u2264 b \u2194 a < b :=\n\u27e8\u03bb h', lt_of_le_of_ne h' h, \u03bb h, h.le\u27e9\n\n-- See Note [decidable namespace]\nprotected lemma decidable.ne_iff_lt_iff_le [partial_order \u03b1] [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} : (a \u2260 b \u2194 a < b) \u2194 a \u2264 b :=\n\u27e8\u03bb h, decidable.by_cases le_of_eq (le_of_lt \u2218 h.mp), \u03bb h, \u27e8lt_of_le_of_ne h, ne_of_lt\u27e9\u27e9\n\n@[simp] lemma ne_iff_lt_iff_le [partial_order \u03b1] {a b : \u03b1} : (a \u2260 b \u2194 a < b) \u2194 a \u2264 b :=\nby haveI := classical.dec; exact decidable.ne_iff_lt_iff_le\n\nlemma lt_of_not_ge' [linear_order \u03b1] {a b : \u03b1} (h : \u00ac b \u2264 a) : a < b :=\n((le_total _ _).resolve_right h).lt_of_not_le h\n\nlemma lt_iff_not_ge' [linear_order \u03b1] {x y : \u03b1} : x < y \u2194 \u00ac y \u2264 x := \u27e8not_le_of_gt, lt_of_not_ge'\u27e9\n\nlemma ne.lt_or_lt [linear_order \u03b1] {x y : \u03b1} (h : x \u2260 y) : x < y \u2228 y < x := lt_or_gt_of_ne h\n\n/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/\n@[simp] lemma lt_or_lt_iff_ne [linear_order \u03b1] {x y : \u03b1} : x < y \u2228 y < x \u2194 x \u2260 y :=\nne_iff_lt_or_gt.symm\n\nlemma not_lt_iff_eq_or_lt [linear_order \u03b1] {a b : \u03b1} : \u00ac a < b \u2194 a = b \u2228 b < a :=\nnot_lt.trans $ decidable.le_iff_eq_or_lt.trans $ or_congr eq_comm iff.rfl\n\nlemma exists_ge_of_linear [linear_order \u03b1] (a b : \u03b1) : \u2203 c, a \u2264 c \u2227 b \u2264 c :=\nmatch le_total a b with\n| or.inl h := \u27e8_, h, le_rfl\u27e9\n| or.inr h := \u27e8_, le_rfl, h\u27e9\nend\n\nlemma lt_imp_lt_of_le_imp_le {\u03b2} [linear_order \u03b1] [preorder \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2192 c \u2264 d) (h : d < c) : b < a :=\nlt_of_not_ge' $ \u03bb h', (H h').not_lt h\n\nlemma le_imp_le_iff_lt_imp_lt {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2} :\n  (a \u2264 b \u2192 c \u2264 d) \u2194 (d < c \u2192 b < a) :=\n\u27e8lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt\u27e9\n\nlemma lt_iff_lt_of_le_iff_le' {\u03b2} [preorder \u03b1] [preorder \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2194 c \u2264 d) (H' : b \u2264 a \u2194 d \u2264 c) : b < a \u2194 d < c :=\nlt_iff_le_not_le.trans $ (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm\n\nlemma lt_iff_lt_of_le_iff_le {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2194 c \u2264 d) : b < a \u2194 d < c :=\nnot_le.symm.trans $ (not_congr H).trans $ not_le\n\nlemma le_iff_le_iff_lt_iff_lt {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2} :\n  (a \u2264 b \u2194 c \u2264 d) \u2194 (b < a \u2194 d < c) :=\n\u27e8lt_iff_lt_of_le_iff_le, \u03bb H, not_lt.symm.trans $ (not_congr H).trans $ not_lt\u27e9\n\nlemma eq_of_forall_le_iff [partial_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c \u2264 a \u2194 c \u2264 b) : a = b :=\n((H _).1 le_rfl).antisymm ((H _).2 le_rfl)\n\nlemma le_of_forall_le [preorder \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c \u2264 a \u2192 c \u2264 b) : a \u2264 b :=\nH _ le_rfl\n\nlemma le_of_forall_le' [preorder \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a \u2264 c \u2192 b \u2264 c) : b \u2264 a :=\nH _ le_rfl\n\nlemma le_of_forall_lt [linear_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c < a \u2192 c < b) : a \u2264 b :=\nle_of_not_lt $ \u03bb h, lt_irrefl _ (H _ h)\n\nlemma forall_lt_iff_le [linear_order \u03b1] {a b : \u03b1} :\n  (\u2200 \u2983c\u2984, c < a \u2192 c < b) \u2194 a \u2264 b :=\n\u27e8le_of_forall_lt, \u03bb h c hca, lt_of_lt_of_le hca h\u27e9\n\nlemma le_of_forall_lt' [linear_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a < c \u2192 b < c) : b \u2264 a :=\nle_of_not_lt $ \u03bb h, lt_irrefl _ (H _ h)\n\nlemma forall_lt_iff_le' [linear_order \u03b1] {a b : \u03b1} :\n  (\u2200 \u2983c\u2984, a < c \u2192 b < c) \u2194 b \u2264 a :=\n\u27e8le_of_forall_lt', \u03bb h c hac, lt_of_le_of_lt h hac\u27e9\n\nlemma eq_of_forall_ge_iff [partial_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a \u2264 c \u2194 b \u2264 c) : a = b :=\n((H _).2 le_rfl).antisymm ((H _).1 le_rfl)\n\n/-- monotonicity of `\u2264` with respect to `\u2192` -/\nlemma le_implies_le_of_le_of_le {a b c d : \u03b1} [preorder \u03b1] (hca : c \u2264 a) (hbd : b \u2264 d) :\n  a \u2264 b \u2192 c \u2264 d :=\n\u03bb hab, (hca.trans hab).trans hbd\n\n@[ext]\nlemma preorder.to_has_le_injective {\u03b1 : Type*} :\n  function.injective (@preorder.to_has_le \u03b1) :=\n\u03bb A B h, begin\n  cases A, cases B,\n  injection h with h_le,\n  have : A_lt = B_lt,\n  { funext a b,\n    dsimp [(\u2264)] at A_lt_iff_le_not_le B_lt_iff_le_not_le h_le,\n    simp [A_lt_iff_le_not_le, B_lt_iff_le_not_le, h_le], },\n  congr',\nend\n\n@[ext]\nlemma partial_order.to_preorder_injective {\u03b1 : Type*} :\n  function.injective (@partial_order.to_preorder \u03b1) :=\n\u03bb A B h, by { cases A, cases B, injection h, congr' }\n\n@[ext]\nlemma linear_order.to_partial_order_injective {\u03b1 : Type*} :\n  function.injective (@linear_order.to_partial_order \u03b1) :=\nbegin\n  intros A B h,\n  cases A, cases B, injection h,\n  obtain rfl : A_le = B_le := \u2039_\u203a, obtain rfl : A_lt = B_lt := \u2039_\u203a,\n  obtain rfl : A_decidable_le = B_decidable_le := subsingleton.elim _ _,\n  obtain rfl : A_max = B_max := A_max_def.trans B_max_def.symm,\n  obtain rfl : A_min = B_min := A_min_def.trans B_min_def.symm,\n  congr\nend\n\ntheorem preorder.ext {\u03b1} {A B : preorder \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\ntheorem partial_order.ext {\u03b1} {A B : partial_order \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\ntheorem linear_order.ext {\u03b1} {A B : linear_order \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\n/-- Given a relation `R` on `\u03b2` and a function `f : \u03b1 \u2192 \u03b2`, the preimage relation on `\u03b1` is defined\nby `x \u2264 y \u2194 f x \u2264 f y`. It is the unique relation on `\u03b1` making `f` a `rel_embedding` (assuming `f`\nis injective). -/\n@[simp] def order.preimage {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) (x y : \u03b1) : Prop := s (f x) (f y)\n\ninfix ` \u207b\u00b9'o `:80 := order.preimage\n\n/-- The preimage of a decidable order is decidable. -/\ninstance order.preimage.decidable {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) [H : decidable_rel s] :\n  decidable_rel (f \u207b\u00b9'o s) :=\n\u03bb x y, H _ _\n\n/-! ### Order dual -/\n\n/-- Type synonym to equip a type with the dual order: `\u2264` means `\u2265` and `<` means `>`. -/\ndef order_dual (\u03b1 : Type*) : Type* := \u03b1\n\nnamespace order_dual\n\ninstance (\u03b1 : Type*) [h : nonempty \u03b1] : nonempty (order_dual \u03b1) := h\ninstance (\u03b1 : Type*) [h : subsingleton \u03b1] : subsingleton (order_dual \u03b1) := h\ninstance (\u03b1 : Type*) [has_le \u03b1] : has_le (order_dual \u03b1) := \u27e8\u03bb x y : \u03b1, y \u2264 x\u27e9\ninstance (\u03b1 : Type*) [has_lt \u03b1] : has_lt (order_dual \u03b1) := \u27e8\u03bb x y : \u03b1, y < x\u27e9\ninstance (\u03b1 : Type*) [has_zero \u03b1] : has_zero (order_dual \u03b1) := \u27e8(0 : \u03b1)\u27e9\n\n-- `dual_le` and `dual_lt` should not be simp lemmas:\n-- they cause a loop since `\u03b1` and `order_dual \u03b1` are definitionally equal\n\nlemma dual_le [has_le \u03b1] {a b : \u03b1} :\n  @has_le.le (order_dual \u03b1) _ a b \u2194 @has_le.le \u03b1 _ b a := iff.rfl\n\nlemma dual_lt [has_lt \u03b1] {a b : \u03b1} :\n  @has_lt.lt (order_dual \u03b1) _ a b \u2194 @has_lt.lt \u03b1 _ b a := iff.rfl\n\ninstance (\u03b1 : Type*) [preorder \u03b1] : preorder (order_dual \u03b1) :=\n{ le_refl          := le_refl,\n  le_trans         := \u03bb a b c hab hbc, hbc.trans hab,\n  lt_iff_le_not_le := \u03bb _ _, lt_iff_le_not_le,\n  .. order_dual.has_le \u03b1,\n  .. order_dual.has_lt \u03b1 }\n\ninstance (\u03b1 : Type*) [partial_order \u03b1] : partial_order (order_dual \u03b1) :=\n{ le_antisymm := \u03bb a b hab hba, @le_antisymm \u03b1 _ a b hba hab, .. order_dual.preorder \u03b1 }\n\ninstance (\u03b1 : Type*) [linear_order \u03b1] : linear_order (order_dual \u03b1) :=\n{ le_total     := \u03bb a b : \u03b1, le_total b a,\n  decidable_le := (infer_instance : decidable_rel (\u03bb a b : \u03b1, b \u2264 a)),\n  decidable_lt := (infer_instance : decidable_rel (\u03bb a b : \u03b1, b < a)),\n  min := @max \u03b1 _,\n  max := @min \u03b1 _,\n  min_def := @linear_order.max_def \u03b1 _,\n  max_def := @linear_order.min_def \u03b1 _,\n  .. order_dual.partial_order \u03b1 }\n\ninstance : \u03a0 [inhabited \u03b1], inhabited (order_dual \u03b1) := id\n\ntheorem preorder.dual_dual (\u03b1 : Type*) [H : preorder \u03b1] :\n  order_dual.preorder (order_dual \u03b1) = H :=\npreorder.ext $ \u03bb _ _, iff.rfl\n\ntheorem partial_order.dual_dual (\u03b1 : Type*) [H : partial_order \u03b1] :\n  order_dual.partial_order (order_dual \u03b1) = H :=\npartial_order.ext $ \u03bb _ _, iff.rfl\n\ntheorem linear_order.dual_dual (\u03b1 : Type*) [H : linear_order \u03b1] :\n  order_dual.linear_order (order_dual \u03b1) = H :=\nlinear_order.ext $ \u03bb _ _, iff.rfl\n\nend order_dual\n\n/-! ### Order instances on the function space -/\n\ninstance pi.has_le {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_le (\u03b1 i)] : has_le (\u03a0 i, \u03b1 i) :=\n{ le       := \u03bb x y, \u2200 i, x i \u2264 y i }\n\nlemma pi.le_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_le (\u03b1 i)] {x y : \u03a0 i, \u03b1 i} :\n  x \u2264 y \u2194 \u2200 i, x i \u2264 y i :=\niff.rfl\n\ninstance pi.preorder {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] : preorder (\u03a0 i, \u03b1 i) :=\n{ le_refl  := \u03bb a i, le_refl (a i),\n  le_trans := \u03bb a b c h\u2081 h\u2082 i, le_trans (h\u2081 i) (h\u2082 i),\n  ..pi.has_le }\n\nlemma pi.lt_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] {x y : \u03a0 i, \u03b1 i} :\n  x < y \u2194 x \u2264 y \u2227 \u2203 i, x i < y i :=\nby simp [lt_iff_le_not_le, pi.le_def] {contextual := tt}\n\nlemma le_update_iff {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] [decidable_eq \u03b9]\n  {x y : \u03a0 i, \u03b1 i} {i : \u03b9} {a : \u03b1 i} :\n  x \u2264 function.update y i a \u2194 x i \u2264 a \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nfunction.forall_update_iff _ (\u03bb j z, x j \u2264 z)\n\nlemma update_le_iff {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] [decidable_eq \u03b9]\n  {x y : \u03a0 i, \u03b1 i} {i : \u03b9} {a : \u03b1 i} :\n  function.update x i a \u2264 y \u2194 a \u2264 y i \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nfunction.forall_update_iff _ (\u03bb j z, z \u2264 y j)\n\nlemma update_le_update_iff {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] [decidable_eq \u03b9]\n  {x y : \u03a0 i, \u03b1 i} {i : \u03b9} {a b : \u03b1 i} :\n  function.update x i a \u2264 function.update y i b \u2194 a \u2264 b \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nby simp [update_le_iff] {contextual := tt}\n\ninstance pi.partial_order {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, partial_order (\u03b1 i)] :\n  partial_order (\u03a0 i, \u03b1 i) :=\n{ le_antisymm := \u03bb f g h1 h2, funext (\u03bb b, (h1 b).antisymm (h2 b)),\n  ..pi.preorder }\n\n/-! ### Lifts of order instances -/\n\n/-- Transfer a `preorder` on `\u03b2` to a `preorder` on `\u03b1` using a function `f : \u03b1 \u2192 \u03b2`.\nSee note [reducible non-instances]. -/\n@[reducible] def preorder.lift {\u03b1 \u03b2} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) : preorder \u03b1 :=\n{ le               := \u03bb x y, f x \u2264 f y,\n  le_refl          := \u03bb a, le_rfl,\n  le_trans         := \u03bb a b c, le_trans,\n  lt               := \u03bb x y, f x < f y,\n  lt_iff_le_not_le := \u03bb a b, lt_iff_le_not_le }\n\n/-- Transfer a `partial_order` on `\u03b2` to a `partial_order` on `\u03b1` using an injective\nfunction `f : \u03b1 \u2192 \u03b2`. See note [reducible non-instances]. -/\n@[reducible] def partial_order.lift {\u03b1 \u03b2} [partial_order \u03b2] (f : \u03b1 \u2192 \u03b2) (inj : injective f) :\n  partial_order \u03b1 :=\n{ le_antisymm := \u03bb a b h\u2081 h\u2082, inj (h\u2081.antisymm h\u2082), .. preorder.lift f }\n\n/-- Transfer a `linear_order` on `\u03b2` to a `linear_order` on `\u03b1` using an injective\nfunction `f : \u03b1 \u2192 \u03b2`. See note [reducible non-instances]. -/\n@[reducible] def linear_order.lift {\u03b1 \u03b2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (inj : injective f) :\n  linear_order \u03b1 :=\n{ le_total     := \u03bb x y, le_total (f x) (f y),\n  decidable_le := \u03bb x y, (infer_instance : decidable (f x \u2264 f y)),\n  decidable_lt := \u03bb x y, (infer_instance : decidable (f x < f y)),\n  decidable_eq := \u03bb x y, decidable_of_iff _ inj.eq_iff,\n  .. partial_order.lift f inj }\n\ninstance subtype.preorder {\u03b1} [preorder \u03b1] (p : \u03b1 \u2192 Prop) : preorder (subtype p) :=\npreorder.lift (coe : subtype p \u2192 \u03b1)\n\n@[simp] lemma subtype.mk_le_mk {\u03b1} [preorder \u03b1] {p : \u03b1 \u2192 Prop} {x y : \u03b1} {hx : p x} {hy : p y} :\n  (\u27e8x, hx\u27e9 : subtype p) \u2264 \u27e8y, hy\u27e9 \u2194 x \u2264 y :=\niff.rfl\n\n@[simp] lemma subtype.mk_lt_mk {\u03b1} [preorder \u03b1] {p : \u03b1 \u2192 Prop} {x y : \u03b1} {hx : p x} {hy : p y} :\n  (\u27e8x, hx\u27e9 : subtype p) < \u27e8y, hy\u27e9 \u2194 x < y :=\niff.rfl\n\n@[simp, norm_cast] lemma subtype.coe_le_coe {\u03b1} [preorder \u03b1] {p : \u03b1 \u2192 Prop} {x y : subtype p} :\n  (x : \u03b1) \u2264 y \u2194 x \u2264 y :=\niff.rfl\n\n@[simp, norm_cast] lemma subtype.coe_lt_coe {\u03b1} [preorder \u03b1] {p : \u03b1 \u2192 Prop} {x y : subtype p} :\n  (x : \u03b1) < y \u2194 x < y :=\niff.rfl\n\ninstance subtype.partial_order {\u03b1} [partial_order \u03b1] (p : \u03b1 \u2192 Prop) :\n  partial_order (subtype p) :=\npartial_order.lift coe subtype.coe_injective\n\n/-- A subtype of a linear order is a linear order. We explicitly give the proof of decidable\n  equality as the existing instance, in order to not have two instances of decidable equality that\n  are not definitionally equal. -/\ninstance subtype.linear_order {\u03b1} [linear_order \u03b1] (p : \u03b1 \u2192 Prop) : linear_order (subtype p) :=\n{ decidable_eq := subtype.decidable_eq,\n  .. linear_order.lift coe subtype.coe_injective }\n\n/-!\n### Pointwise order on `\u03b1 \u00d7 \u03b2`\n\nThe lexicographic order is defined in `order.lexicographic`, and the instances are available via the\ntype synonym `\u03b1 \u00d7\u2097 \u03b2 = \u03b1 \u00d7 \u03b2`.\n-/\n\nnamespace prod\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [has_le \u03b1] [has_le \u03b2] : has_le (\u03b1 \u00d7 \u03b2) :=\n\u27e8\u03bb p q, p.1 \u2264 q.1 \u2227 p.2 \u2264 q.2\u27e9\n\nlemma le_def [has_le \u03b1] [has_le \u03b2] {x y : \u03b1 \u00d7 \u03b2} : x \u2264 y \u2194 x.1 \u2264 y.1 \u2227 x.2 \u2264 y.2 := iff.rfl\n\n@[simp] lemma mk_le_mk [has_le \u03b1] [has_le \u03b2] {x\u2081 x\u2082 : \u03b1} {y\u2081 y\u2082 : \u03b2} :\n  (x\u2081, y\u2081) \u2264 (x\u2082, y\u2082) \u2194 x\u2081 \u2264 x\u2082 \u2227 y\u2081 \u2264 y\u2082 :=\niff.rfl\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [preorder \u03b1] [preorder \u03b2] : preorder (\u03b1 \u00d7 \u03b2) :=\n{ le_refl  := \u03bb \u27e8a, b\u27e9, \u27e8le_refl a, le_refl b\u27e9,\n  le_trans := \u03bb \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9 \u27e8hac, hbd\u27e9 \u27e8hce, hdf\u27e9,\n    \u27e8le_trans hac hce, le_trans hbd hdf\u27e9,\n  .. prod.has_le \u03b1 \u03b2 }\n\nlemma lt_iff [preorder \u03b1] [preorder \u03b2] {a b : \u03b1 \u00d7 \u03b2} :\n  a < b \u2194 a.1 < b.1 \u2227 a.2 \u2264 b.2 \u2228 a.1 \u2264 b.1 \u2227 a.2 < b.2 :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { by_cases h\u2081 : b.1 \u2264 a.1,\n    { exact or.inr \u27e8h.1.1, h.1.2.lt_of_not_le $ \u03bb h\u2082, h.2 \u27e8h\u2081, h\u2082\u27e9\u27e9 },\n    { exact or.inl \u27e8h.1.1.lt_of_not_le h\u2081, h.1.2\u27e9 } },\n  { rintro (\u27e8h\u2081, h\u2082\u27e9 | \u27e8h\u2081, h\u2082\u27e9),\n    { exact \u27e8\u27e8h\u2081.le, h\u2082\u27e9, \u03bb h, h\u2081.not_le h.1\u27e9 },\n    { exact \u27e8\u27e8h\u2081, h\u2082.le\u27e9, \u03bb h, h\u2082.not_le h.2\u27e9 } }\nend\n\n@[simp] lemma mk_lt_mk [preorder \u03b1] [preorder \u03b2] {x\u2081 x\u2082 : \u03b1} {y\u2081 y\u2082 : \u03b2} :\n  (x\u2081, y\u2081) < (x\u2082, y\u2082) \u2194 x\u2081 < x\u2082 \u2227 y\u2081 \u2264 y\u2082 \u2228 x\u2081 \u2264 x\u2082 \u2227 y\u2081 < y\u2082 :=\nlt_iff\n\n/-- The pointwise partial order on a product.\n    (The lexicographic ordering is defined in order/lexicographic.lean, and the instances are\n    available via the type synonym `\u03b1 \u00d7\u2097 \u03b2 = \u03b1 \u00d7 \u03b2`.) -/\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [partial_order \u03b1] [partial_order \u03b2] :\n  partial_order (\u03b1 \u00d7 \u03b2) :=\n{ le_antisymm := \u03bb \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8hac, hbd\u27e9 \u27e8hca, hdb\u27e9,\n    prod.ext (hac.antisymm hca) (hbd.antisymm hdb),\n  .. prod.preorder \u03b1 \u03b2 }\n\nend prod\n\n/-! ### Additional order classes -/\n\n/-- An order is dense if there is an element between any pair of distinct elements. -/\nclass densely_ordered (\u03b1 : Type u) [has_lt \u03b1] : Prop :=\n(dense : \u2200 a\u2081 a\u2082 : \u03b1, a\u2081 < a\u2082 \u2192 \u2203 a, a\u2081 < a \u2227 a < a\u2082)\n\nlemma exists_between [has_lt \u03b1] [densely_ordered \u03b1] :\n  \u2200 {a\u2081 a\u2082 : \u03b1}, a\u2081 < a\u2082 \u2192 \u2203 a, a\u2081 < a \u2227 a < a\u2082 :=\ndensely_ordered.dense\n\ninstance order_dual.densely_ordered (\u03b1 : Type u) [has_lt \u03b1] [densely_ordered \u03b1] :\n  densely_ordered (order_dual \u03b1) :=\n\u27e8\u03bb a\u2081 a\u2082 ha, (@exists_between \u03b1 _ _ _ _ ha).imp $ \u03bb a, and.symm\u27e9\n\nlemma le_of_forall_le_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h : \u2200 a, a\u2082 < a \u2192 a\u2081 \u2264 a) :\n  a\u2081 \u2264 a\u2082 :=\nle_of_not_gt $ \u03bb ha,\n  let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between ha in\n  lt_irrefl a $ lt_of_lt_of_le \u2039a < a\u2081\u203a (h _ \u2039a\u2082 < a\u203a)\n\nlemma eq_of_le_of_forall_le_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : \u2200 a, a\u2082 < a \u2192 a\u2081 \u2264 a) : a\u2081 = a\u2082 :=\nle_antisymm (le_of_forall_le_of_dense h\u2082) h\u2081\n\nlemma le_of_forall_ge_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h : \u2200 a\u2083 < a\u2081, a\u2083 \u2264 a\u2082) :\n  a\u2081 \u2264 a\u2082 :=\nle_of_not_gt $ \u03bb ha,\n  let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between ha in\n  lt_irrefl a $ lt_of_le_of_lt (h _ \u2039a < a\u2081\u203a) \u2039a\u2082 < a\u203a\n\nlemma eq_of_le_of_forall_ge_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : \u2200 a\u2083 < a\u2081, a\u2083 \u2264 a\u2082) : a\u2081 = a\u2082 :=\n(le_of_forall_ge_of_dense h\u2082).antisymm h\u2081\n\nlemma dense_or_discrete [linear_order \u03b1] (a\u2081 a\u2082 : \u03b1) :\n  (\u2203 a, a\u2081 < a \u2227 a < a\u2082) \u2228 ((\u2200 a, a\u2081 < a \u2192 a\u2082 \u2264 a) \u2227 (\u2200 a < a\u2082, a \u2264 a\u2081)) :=\nor_iff_not_imp_left.2 $ \u03bb h,\n  \u27e8\u03bb a ha\u2081, le_of_not_gt $ \u03bb ha\u2082, h \u27e8a, ha\u2081, ha\u2082\u27e9,\n    \u03bb a ha\u2082, le_of_not_gt $ \u03bb ha\u2081, h \u27e8a, ha\u2081, ha\u2082\u27e9\u27e9\n\nvariables {s : \u03b2 \u2192 \u03b2 \u2192 Prop} {t : \u03b3 \u2192 \u03b3 \u2192 Prop}\n\n/-! ### Linear order from a total partial order -/\n\n/-- Type synonym to create an instance of `linear_order` from a `partial_order` and\n`is_total \u03b1 (\u2264)` -/\ndef as_linear_order (\u03b1 : Type u) := \u03b1\n\ninstance {\u03b1} [inhabited \u03b1] : inhabited (as_linear_order \u03b1) :=\n\u27e8 (default : \u03b1) \u27e9\n\nnoncomputable instance as_linear_order.linear_order {\u03b1} [partial_order \u03b1] [is_total \u03b1 (\u2264)] :\n  linear_order (as_linear_order \u03b1) :=\n{ le_total     := @total_of \u03b1 (\u2264) _,\n  decidable_le := classical.dec_rel _,\n  .. (_ : partial_order \u03b1) }\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7411893009465936}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level2 -- add_assoc\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 14: `add_le_add_left`\n\nI know these are easy and we've done several already, but this is one\nof the axioms for an ordered commutative monoid! The nature of formalizing\nis that we should formalize all \"obvious\" lemmas, and then when we're\nactually using ` \u2264` in real life, everything will be there. Note also,\nof course, that all of these lemmas are already formalized in Lean's\nmaths library already, for Lean's inbuilt natural numbers.\n\n## Lemma : add_le_add_left\nIf `a \u2264 b` then for all `t`, `t+a \u2264 t+b`.\n-/\ntheorem add_le_add_left {a b : MyNat} (h : a \u2264 b) (t : MyNat) :\n  t + a \u2264 t + b := by\n  cases h with\n  | _ c hc =>\n    use c\n    rw [hc]\n    rw [add_assoc]\n\n/-!\nNext up [Level 15](./Level15.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level14.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.7410743635556989}}
{"text": "import data.nat.prime\nimport tactic.linarith\n\nopen nat\n\ntheorem infinitude_of_primes : \u2200 N : \u2115, \u2203 p \u2265 N, nat.prime p :=\nbegin\n  intro N,\n\n  let M := factorial N + 1,\n  let p := min_fac M,\n\n  have pp : nat.prime p :=\n  begin\n    refine min_fac_prime _,\n    have : factorial N > 0 := factorial_pos N,\n    linarith,\n  end,\n\n  use p,\n  split,\n  { by_contradiction,\n    have h\u2081 : p \u2223 factorial N + 1 := min_fac_dvd M,\n    have h\u2082 : p \u2223 factorial N := (prime.dvd_factorial pp).mpr (le_of_not_ge h),\n    have h : p \u2223 1 := (nat.dvd_add_right h\u2082).mp h\u2081,\n    exact nat.prime.not_dvd_one pp h, },\n  { exact pp, },\nend\n\n-- Comentario: Ver su desarrollo en https://youtu.be/b59fpAJ8Mfs\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Infinitud_de_los_primos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7410743616615396}}
{"text": "import algebra.group.basic\nimport data.zmod.basic\nimport data.equiv.basic\nimport tactic\n\nimport data.set.basic\n\nuniverses u v\n\nopen equiv function set\n\nvariables (G : Type u) [group G]\n\nlemma perms_eq_fun_eq {X : Type u} (p : perm X) (q : perm X) (h : p.to_fun = q.to_fun) : p = q := \nbegin \n  apply perm.ext,\n  intro x,\n  exact congr_fun h x,\nend \n\ndef lift_to_perm (G : Type*) [group G] : G \u2192* perm G := {\n  to_fun := \u03bb g, {\n    to_fun    := \u03bb x, g * x,\n    inv_fun   := \u03bb x, g\u207b\u00b9 * x,\n    left_inv  := \u03bb h, by simp,\n    right_inv := \u03bb h, by simp\n  },\n  map_one' := by {ext, simp},\n  map_mul' := \u03bb g h, by {ext, simp [mul_assoc _ _ _]},\n}\n\nlemma lift_to_perm_inj {G : Type*} [group G] : injective (lift_to_perm G) := \nbegin \n  intros g\u2081 g\u2082 h,\n  have H : ((lift_to_perm G) g\u2081) 1 = ((lift_to_perm G) g\u2082) 1, rw h,\n  exact (mul_left_inj 1).mp H,\nend\n\ndef iso_induces_perm_iso {X : Type u} {Y : Type v} : X \u2243 Y \u2192 perm X \u2243* perm Y := \u03bb h,\n{ to_fun    := \u03bb p, ({\n                 to_fun    := h.1 \u2218 p.1 \u2218 h.2,\n                 inv_fun   := h.1 \u2218 p.2 \u2218 h.2,\n                 left_inv  := \u03bb y, by simp,\n                 right_inv := \u03bb y, by simp,\n               } : perm Y),\n  inv_fun   := \u03bb (p : perm Y), ({\n                 to_fun    := h.2 \u2218 p.1 \u2218 h.1,\n                 inv_fun   := h.2 \u2218 p.2 \u2218 h.1,\n                 left_inv  := \u03bb y, by simp,\n                 right_inv := \u03bb y, by simp,\n               } : perm X),\n  left_inv  := \u03bb x, by {ext, simp},\n  right_inv := \u03bb x, by {ext, simp},\n  map_mul'  := \u03bb p q, perms_eq_fun_eq _ _ (conj_comp h p.to_fun q.to_fun)\n}\n\ntheorem cayleys (G : Type*) [group G] : \u2203 (f : G \u2192* perm G), injective f := \nbegin\n  use lift_to_perm G,\n  exact lift_to_perm_inj,\nend\n\nvariables {G\u2081 : Type*} {G\u2082 : Type*} [group G\u2081] [group G\u2082]\n\nnoncomputable \ndef inj_hom_induces_iso (f : G\u2081 \u2192* G\u2082) (h_inj : injective f) : G\u2081 \u2243* range f :=\n{ to_fun    := \u03bb g, \u27e8f g, set.mem_range_self g\u27e9,\n  inv_fun   := begin \n    rintro \u27e8a, b\u27e9,\n    choose h hk using b,\n    exact h,\n  end,\n  left_inv  := begin\n    intro x,\n    simp,\n    apply h_inj,\n    have H : f x \u2208 range f := set.mem_range_self x,\n    rw classical.some_spec H,\n  end,\n  right_inv := begin \n    intro y,\n    ext,\n    rcases y with \u27e8y, \u27e8x, hx\u27e9\u27e9,\n    simp,\n    have H := Exists.intro x hx,\n    rw classical.some_spec H,\n  end,\n  map_mul'  := \u03bb x y, by {ext, simp},\n}\n\nnoncomputable \ntheorem cayleys2 {G : Type*} [group G] : G \u2243* range (lift_to_perm G) \n  := inj_hom_induces_iso (lift_to_perm G) lift_to_perm_inj", "meta": {"author": "th-char", "repo": "cayleys_theorem", "sha": "c4862adbe1e6a8892fd607217c803f260ee74be2", "save_path": "github-repos/lean/th-char-cayleys_theorem", "path": "github-repos/lean/th-char-cayleys_theorem/cayleys_theorem-c4862adbe1e6a8892fd607217c803f260ee74be2/src/cayleys.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7410436298741124}}
{"text": "import tactic\n\n/-\n\n# Prove that for every positive integer n the number 3(1^5 +2^5 +...+n^5)\n# is divisible by 1^3+2^3+...+n^3\n\nThis is question 9 in Sierpinski's book\n\n-/\n\nopen_locale big_operators\n\nopen finset\n\nexample (a b : \u2124) : (a : \u211a) = b \u2194 a = b := int.cast_inj\n\nlemma sum_cubes (n : \u2115) : \u2211 i in range n, (i : \u211a)^3 = (n*(n-1)/2)^2 :=\nbegin\n  induction n with d hd,\n  { simp, ring, },\n  { rw [finset.sum_range_succ, hd],\n    simp,\n    ring }\nend\n\nlemma sum_fifths (n : \u2115) : \u2211 i in range n, (i : \u211a)^5 = (4 * (n * (n-1)/2)^3-(n*(n-1)/2)^2)/3 :=\nbegin\n  induction n with d hd,\n  { simp, ring, },\n  { rw [finset.sum_range_succ, hd],\n    simp,\n    ring }\nend\n\nexample (n : \u2115) : (\u2211 i in range n, i^3) \u2223 (3 * \u2211 i in range n, i^5) :=\nbegin\n  rw \u2190 int.coe_nat_dvd,\n  use 2 * n * (n-1) - 1,\n  rw \u2190 @int.cast_inj \u211a _ _ _ _,\n  push_cast,\n  rw sum_cubes,\n  rw sum_fifths,\n  ring,\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section08numbertheory/examples/example07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7410436213212925}}
{"text": "/- Exercise 3.1: Program Semantics \u2014 Operational Semantics -/\n\n/- We start by repeating some material from the lecture. We use the same `program` syntax and the\nbig-step semantics as presented in the lecture. -/\n\nattribute [pattern] or.intro_left or.intro_right\n\ninductive program (\u03c3 : Type) : Type\n| skip {} : program\n| assign  : (\u03c3 \u2192 \u03c3) \u2192 program\n| seq     : program \u2192 program \u2192 program\n| ite     : (\u03c3 \u2192 Prop) \u2192 program \u2192 program \u2192 program\n| while   : (\u03c3 \u2192 Prop) \u2192 program \u2192 program\n\nnamespace program\n\nvariables {\u03c3 : Type} {c : \u03c3 \u2192 Prop} {f : \u03c3 \u2192 \u03c3} {p p\u2080 p\u2081 p\u2082 : program \u03c3} {s s\u2080 s\u2081 s\u2082 t u : \u03c3}\n\ninductive big_step : (program \u03c3 \u00d7 \u03c3) \u2192 \u03c3 \u2192 Prop\n| skip {s} :\n  big_step (skip, s) s\n| assign {f s} :\n  big_step (assign f, s) (f s)\n| seq {p\u2081 p\u2082 s u} (t) (h\u2081 : big_step (p\u2081, s) t) (h\u2082 : big_step (p\u2082, t) u) :\n  big_step (seq p\u2081 p\u2082, s) u\n| ite_true {c : \u03c3 \u2192 Prop} {p\u2081 p\u2080 s t} (hs : c s) (h : big_step (p\u2081, s) t) :\n  big_step (ite c p\u2081 p\u2080, s) t\n| ite_false {c : \u03c3 \u2192 Prop} {p\u2081 p\u2080 s t} (hs : \u00ac c s) (h : big_step (p\u2080, s) t) :\n  big_step (ite c p\u2081 p\u2080, s) t\n| while_true {c : \u03c3 \u2192 Prop} {p s u} (t) (hs : c s) (hp : big_step (p, s) t)\n  (hw : big_step (while c p, t) u) :\n  big_step (while c p, s) u\n| while_false {c : \u03c3 \u2192 Prop} {p s} (hs : \u00ac c s) : big_step (while c p, s) s\n\ninfix ` \u27f9 `:110 := big_step\n\n/- We copy also the inversion rules from the lecture. Do not prove these. -/\n\n@[simp] lemma big_step_skip_iff :\n  (skip, s) \u27f9 t \u2194 t = s := sorry\n@[simp] lemma big_step_assign_iff :\n  (assign f, s) \u27f9 t \u2194 t = f s := sorry\n@[simp] lemma big_step_seq_iff :\n  (seq p\u2081 p\u2082, s) \u27f9 t \u2194 (\u2203u, (p\u2081, s) \u27f9 u \u2227 (p\u2082, u) \u27f9 t) := sorry\n@[simp] lemma big_step_ite_iff :\n  (ite c p\u2081 p\u2080, s) \u27f9 t \u2194 ((c s \u2227 (p\u2081, s) \u27f9 t) \u2228 (\u00ac c s \u2227 (p\u2080, s) \u27f9 t)) := sorry\nlemma big_step_while_iff :\n  (while c p, s) \u27f9 t \u2194 (\u2203u, c s \u2227 (p, s) \u27f9 u \u2227 (while c p, u) \u27f9 t) \u2228 (\u00ac c s \u2227 t = s) := sorry\n@[simp] lemma big_step_while_true_iff (hs : c s) :\n  (while c p, s) \u27f9 t \u2194 (\u2203u, (p, s) \u27f9 u \u2227 (while c p, u) \u27f9 t) := sorry\n@[simp] lemma big_step_while_false_iff (hs : \u00ac c s) :\n  (while c p, s) \u27f9 t \u2194 t = s := sorry\n\n\n/- Question 1: Program equivalence -/\n\n/- For this question, we introduce the notation of program equivalence `p\u2081 \u2248 p\u2082`. `\u2248` is entered as\n`\\approx`. -/\n\ndef program_equiv (p\u2081 p\u2082 : program \u03c3) : Prop :=\n\u2200s t, (p\u2081, s) \u27f9 t \u2194 (p\u2082, s) \u27f9 t\n\nlocal infix ` \u2248 ` := program_equiv\n\n/- Program equivalence is a equivalence relation, i.e. it is reflexive, symmetric, and\ntransitive. -/\n\n@[refl] lemma program_equiv.refl :\n  p \u2248 p :=\nassume s t, by refl\n\n@[symm] lemma program_equiv.symm :\n  p\u2081 \u2248 p\u2082 \u2192 p\u2082 \u2248 p\u2081 :=\nassume h s t, (h s t).symm\n\n@[trans] lemma program_equiv.trans {p\u2083} (h\u2081\u2082 : p\u2081 \u2248 p\u2082) (h\u2082\u2083 : p\u2082 \u2248 p\u2083) :\n  p\u2081 \u2248 p\u2083 :=\nassume s t, iff.trans (h\u2081\u2082 s t) (h\u2082\u2083 s t)\n\n\n/- 1.1. Prove the following program equivalences. -/\n\nlemma program_equiv_seq_skip1 {p : program \u03c3} : seq skip p \u2248 p :=\nbegin\nintros s t,\napply iff.intro,\nintro h,\ncases h,\ncases h_h\u2081,\nassumption,\nintro h,\napply big_step.seq s,\n\nend\n\n\n\n\nlemma program_equiv_seq_skip2 {p : program \u03c3} : seq p skip \u2248 p :=\nbegin\nintros s t,\napply iff.intro,\nintro h,\ncases h,\ncases h_h\u2082,\nassumption,\nintro h,\napply big_step.seq t,\nassumption,\napply big_step.skip\nend\n\nlemma program_equiv_seq_congr {p\u2081 p\u2082 p\u2083 p\u2084 : program \u03c3}\n  (h\u2081\u2082 : p\u2081 \u2248 p\u2082) (h\u2083\u2084 : p\u2083 \u2248 p\u2084) :\n  seq p\u2081 p\u2083 \u2248 seq p\u2082 p\u2084 :=\nbegin\nintros s t,\napply iff.intro,\nintro h,\napply big_step.seq t,\ncases h,\napply big_step.seq h_t h\u2081\u2082 h_h\u2081,\nend\n\nlemma program_equiv.ite_seq_while :\n  ite c (seq p (while c p)) skip \u2248 while c p :=\nbegin\nintros s t,\napply iff.intro,\nintro h,\ncases h,\ncases h_h,\napply big_step.while_true h_h_t h_hs h_h_h\u2081 h_h_h\u2082,\ncases h_h,\napply big_step.while_false h_hs,\nintro h,\ncases h,\napply big_step.ite_true h_hs,\napply big_step.seq h_t h_hp h_hw,\napply big_step.ite_false h_hs,\napply big_step.skip\nend\n\n\nlemma program_equiv.ite_seq_while' :\n  ite c (seq p (while c p)) skip \u2248 while c p :=\nbegin\nintros s t,\napply iff.intro,\nintro h,\ncases h,\ncases h_h,\napply big_step.while_true h_h_t h_hs h_h_h\u2081 h_h_h\u2082,\ncases h_h,\napply big_step.while_false,\nassumption,\nintro h,\ncases h,\napply big_step.ite_true h_hs,\napply big_step.seq h_t h_hp h_hw,\napply big_step.ite_false,\nassumption,\napply big_step.skip\nend\n\n/- 1.2. Prove one more equivalence. `@id \u03c3` is the identity function on states. -/\n\nlemma program_equiv.skip_assign_id : assign (@id \u03c3) \u2248 skip :=\nsorry\n\n\n/- 1.3. Why do you think `@id \u03c3` is necessary, as opposed to `id`? -/\n\n/- Answer: enter your answer here. -/\n\n\nexample {p p' : program \u03c3} : seq (while (\u03bb_, true) p) p' \u2248 while (\u03bb_, true) p :=\nbegin\nintros l t,\napply iff.intro,\nintro s,\ncases s,\napply big_step.while_true s_t s_h\u2081 s_h\u2082,\n\nend\n\nend program\n\n\n/- Question 2: The guarded command language (GCL) -/\n\n/- In 1976, E. W. Dijkstra introduced the guarded command language, as a language with\nbuilt-in nondeterminism. Its grammar is as follows:\n\n    p  ::=  x := e        -- assignment\n         |  assert b      -- assertion\n         |  p ; p         -- sequential composition\n         |  p | ... | p   -- nondeterministic choice\n         |  loop p        -- nondeterministic iteration\n\nAssignment and sequential composition are as in the WHILE language. The other statements have the\nfollowing semantics:\n\n* `assert b` aborts if `b` evaluates to false; otherwise, the command is a no-op.\n\n* `p | ... | p` chooses **any** of the branches and executes it, ignoring the other branches.\n\n* `loop p` executes `p` **any** number of times.\n\nIn Lean, GCL is captured by the following inductive type: -/\n\ninductive gcl (\u03c3 : Type) : Type\n| assign : (\u03c3 \u2192 \u03c3) \u2192 gcl\n| assert : (\u03c3 \u2192 Prop) \u2192 gcl\n| seq    : gcl \u2192 gcl \u2192 gcl\n| choice : list gcl \u2192 gcl\n| loop   : gcl \u2192 gcl\n\nnamespace gcl\n\nvariable {\u03c3 : Type}\nvariables {c : \u03c3 \u2192 Prop} {f : \u03c3 \u2192 \u03c3} {p p\u2080 p\u2081 p\u2082 : gcl \u03c3} {ps : list (gcl \u03c3)} {s s\u2080 s\u2081 s\u2082 t u : \u03c3}\n\n/- The big-step semantics is defined as follows: -/\n\ninductive big_step : (gcl \u03c3 \u00d7 \u03c3) \u2192 \u03c3 \u2192 Prop\n| assign {f s} :\n  big_step (assign f, s) (f s)\n| assert {c : \u03c3 \u2192 Prop} {s} (hs : c s) :\n  big_step (assert c, s) s\n| seq {p\u2081 p\u2082 s u} (t) (h\u2081 : big_step (p\u2081, s) t) (h\u2082 : big_step (p\u2082, t) u) :\n  big_step (seq p\u2081 p\u2082, s) u\n| choice {ps : list (gcl \u03c3)} {s t} (i : \u2115) (hi : i < list.length ps)\n  (h : big_step (list.nth_le ps i hi, s) t) :\n  big_step (choice ps, s) t\n| loop_base {p s} :\n  big_step (loop p, s) s\n| loop_step {p s t} (u) (h\u2081 : big_step (p, s) u) (h\u2082 : big_step (loop p, u) t) :\n  big_step (loop p, s) t\n\n/- Some convenience syntax: -/\n\ninfix ` ~> `:110 := big_step\n\n/- 2.1. Prove the following inversion rules, as we did in the lecture for the WHILE language. -/\n\n@[simp] lemma big_step_assign : (assign f, s) ~> t \u2194 t = f s :=\nbegin \napply iff.intro,\nintro h,\ncases h,\ntrivial,\nintro h,\ncases h,\napply big_step.assign\nend\n\n\n@[simp] lemma big_step_assert : (assert c, s) ~> t \u2194 (t = s \u2227 c s) :=\nbegin\napply iff.intro,\nintro h,\ncases h,\napply and.intro,\ntrivial,\nassumption,\nintro h,\ncases h,\ncases h_left,\napply big_step.assert h_right\nend\n\n@[simp] lemma big_step_seq : (seq p\u2081 p\u2082, s) ~> t \u2194 (\u2203u, (p\u2081, s) ~> u \u2227 (p\u2082, u) ~> t) :=\nbegin\napply iff.intro,\nintro h,\ncases h,\napply exists.intro h_t,\napply and.intro,\nassumption,\nassumption,\nintro h,\ncases h,\ncases h_h,\napply big_step.seq h_w h_h_left h_h_right\nend\n\n\nlemma big_step_loop : (loop p, s) ~> t \u2194 (s = t \u2228 (\u2203u, (p, s) ~> u \u2227 (loop p, u) ~> t)) :=\nbegin\napply iff.intro,\nintro h,\ncases h,\napply or.intro_left,\ntrivial,\napply or.intro_right,\napply exists.intro h_u,\napply and.intro,\nrepeat{assumption},\nintro h,\ncases h,\ncases h,\nexact big_step.loop_base,\ncases h,\ncases h_h,\nexact big_step.loop_step h_w h_h_left h_h_right\nend\n\n@[simp] lemma big_step_choice :\n  (choice ps, s) ~> t \u2194 (\u2203(i : \u2115) (hi : i < list.length ps), (list.nth_le ps i hi, s) ~> t) :=\nbegin\napply iff.intro,\nintro h,\napply exists.intro,\napply exists.intro,\ncases h,\n\nend\n\n/- 2.2. Fill in the translation below of a deterministic program to a GCL program, by filling in the\n`sorry` placeholders below. -/\n\n-- def of_program : program \u03c3 \u2192 gcl \u03c3\n-- | program.skip          := assign id\n-- | (program.assign f)    := assign f\n-- | (program.seq p\u2081 p\u2082)   :=\n--   seq (of_program p\u2081) (of_program p\u2082) \n-- | (program.ite c p\u2081 p\u2082) :=\n--   choice [\n--     seq (assert c) (of_program p\u2081),\n--     seq (assert (\u03bbs, \u00ac c s)) (of_program p\u2082)\n--   ]\n-- | (program.while c p)   := seq (loop (seq (assert c) (of_program p))) (assert (\u03bbs, \u00ac c s))\n\n\n-- inductive program (\u03c3 : Type) : Type\n-- | skip {} : program\n-- | assign  : (\u03c3 \u2192 \u03c3) \u2192 program\n-- | seq     : program \u2192 program \u2192 program\n-- | ite     : (\u03c3 \u2192 Prop) \u2192 program \u2192 program \u2192 program\n-- | while   : (\u03c3 \u2192 Prop) \u2192 program \u2192 program\n\n\n-- inductive gcl (\u03c3 : Type) : Type\n-- | assign : (\u03c3 \u2192 \u03c3) \u2192 gcl\n-- | assert : (\u03c3 \u2192 Prop) \u2192 gcl\n-- | seq    : gcl \u2192 gcl \u2192 gcl\n-- | choice : list gcl \u2192 gcl\n-- | loop   : gcl \u2192 gcl\n\n\n\ndef of_program : program \u03c3 \u2192 gcl \u03c3\n| program.skip          := assign id\n| (program.assign f)    := assign f\n| (program.seq f s)     := seq (of_program f) (of_program s)\n| (program.ite c p1 p2) := choice [seq (assert c) (of_program p1), seq(assert (\u03bbs,\u00acc s)) (of_program p2)]\n| (program.while c p)   := seq(loop(seq(assert c) (of_program p))) (assert(\u03bbs, \u00ac c s))\n\n\n\n\n\n/- 2.3. Prove that `of_program` is correct, in the sense that whenever the deterministic program `p`\ncan make a big step, the corresponding GCL program makes a big step.\n\nThis is a difficult exercise. Try to get as far as possible.\n\n**Hints:**\n\n* In the each induction subgoal, use `cases h` on an equality `h : (p, s) = (q, t)`. When one side\nis a variable, it will be replaced by the other side. In our case, one side is always a variable.\n\n* Use `specialize h rfl` to instantiate a hypothesis, i.e. to replace a hypothesis of the form\n`h : \u2200{x y}, (x, y) = (p, s) \u2192 q x y` with `h : q p s`.\n\n* At some point you need to prove statements such as `0 < 1 + 1`. Here, you can use use the\n`dec_trival` proof term (e.g. in tactic mode, you must write `exact dec_trivial`)\n\n* You need to use `cases` in the `while_true` case, to cope with a hypothesis of the form\n`h : of_program (while c p, s) ~> t`. This breaks the hypothesis down and will allow you to retrieve\nthe intermediate states and steps.\n\n* You may want to use lemmas from the `program` namespace, e.g. the inversion rules\n(`program.big_step_while_iff`, etc.). -/\n\nlemma big_step_of_program {p : program \u03c3} {s t} :\n  (p, s) \u27f9 t \u2192 (of_program p, s) ~> t :=\nbegin\n  /- The term `(p, s)` needs to be replaced by a variable. We use the same tools as in the lecture:\n\n  * `generalize` replaces a term in our goal by a new variable and an equality assumption.\n\n  * `generalizing p s` tells the `induction` tactic that `p` and `s` should be quantified. -/\n  generalize eq : (p, s) = ps,\n  intro h,\n  induction h generalizing p s;\n    cases eq;\n    clear eq,\n  { simp [of_program] },\n  { sorry },\n  { sorry },\n  { sorry },\n  { sorry },\n  { sorry },\n  { sorry }\nend\n\nend gcl\n", "meta": {"author": "KjellZijlemaker", "repo": "Logical_Verification_VU", "sha": "4578b93bf1615466996157bb333c84122b201d99", "save_path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU", "path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU/Logical_Verification_VU-4578b93bf1615466996157bb333c84122b201d99/Exercises 8/31_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7410046559627566}}
{"text": "import tactic\n\n-- \u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u044b \u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439: \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438, \u0441\u044e\u0440\u044a\u0435\u043a\u0446\u0438\u0438 \u0438 \u0431\u0438\u0435\u043a\u0446\u0438\u0438. \n-- \u041f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043e \u0438\u0437 \u043a\u0443\u0440\u0441\u0430 Formalising Mathematics:\n-- https://github.com/ImperialCollegeLondon/formalising-mathematics/blob/master/src/week_1/Part_C_functions.lean\n-- https://github.com/ImperialCollegeLondon/formalising-mathematics/blob/master/src/week_4/Part_A_sets.lean\n\nopen function\n\n-- \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c namespace, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f\u043c \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439\nnamespace itmo.lean\n\n-- \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0442\u0438\u043f\u044b `X, Y, Z`, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 `f : X \u2192 Y`, `g : Y \u2192 Z` \u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b `(x : X) (y : Y) (z : Z)` \nvariables {X Y Z : Type} {f : X \u2192 Y} {g : Y \u2192 Z} (x : X) (y : Y) (z : Z)\n\n-- \u0424\u0443\u043d\u043a\u0446\u0438\u044f `f` \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0435\u0439, \u0435\u0441\u043b\u0438 \u0438\u0437 `f a = f b` \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e `a = b` (\u0442\u043e \u0435\u0441\u0442\u044c, \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0445\u043e\u0434\u043e\u0432 \u043e\u043d\u0430 \u0432\u044b\u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b)\nlemma injective_def : injective f \u2194 \u2200 a b : X, f a = f b \u2192 a = b :=\nbegin\n  -- \u0432\u0435\u0440\u043d\u043e \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e\n  refl,\nend\n\n-- \u0422\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f id : X \u2192 X \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430, \u043a\u0430\u043a `id x = x`:\nlemma id_def : id x = x :=\nbegin\n  refl\nend\n\n/-- \u0422\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043d\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u0430 -/\nlemma injective_id : injective (id : X \u2192 X) :=\nbegin\n  rintro a b h,\n  exact h,\nend\n\n-- \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 `g \u2218 f` (\u2218 = \\o \u0438\u043b\u0438 \\circ) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430, \u043a\u0430\u043a `(g \u2218 f) x = g (f x)`\nlemma comp_def : (g \u2218 f) x = g (f x) :=\nbegin\n  -- \u0432\u0435\u0440\u043d\u043e \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e\n  refl,\nend\n\n/-- \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0435\u0439 -/\nlemma injective_comp (hf : injective f) (hg : injective g) : injective (g \u2218 f) :=\nbegin\n  rintro x y h,\n  apply hf,\n  apply hg,\n  exact h,\nend\n\n-- \u0424\u0443\u043d\u043a\u0446\u0438\u044f `f : X \u2192 Y` \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u044e\u0440\u044a\u0435\u043a\u0446\u0438\u0435\u0439, \u0435\u0441\u043b\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e `y : Y` \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 `x : X`, \u0447\u0442\u043e `f x = y`\nlemma surjective_def : surjective f \u2194 \u2200 y : Y, \u2203 x : X, f x = y :=\nbegin\n  -- \u0432\u0435\u0440\u043d\u043e \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e\n  refl\nend\n\n/-- \u0422\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f - \u0441\u044e\u0440\u044a\u0435\u043a\u0446\u0438\u044f -/\nlemma surjective_id : surjective (id : X \u2192 X) :=\nbegin\n  intro y,\n  use y,\n  refl,\nend\n\n-- \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0441\u044e\u0440\u044a\u0435\u043a\u0446\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u044e\u0440\u044a\u0435\u043a\u0446\u0438\u0435\u0439\nlemma surjective_comp (hf : surjective f) (hg : surjective g) : surjective (g \u2218 f) :=\nbegin\n  intro z,\n  rcases hg z with \u27e8y, rfl\u27e9,\n  rcases hf y with \u27e8x, rfl\u27e9,\n  use x,\nend\n\n\n-- \u0424\u0443\u043d\u043a\u0446\u0438\u044f `f` \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u0438\u0435\u043a\u0446\u0438\u0435\u0439, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0435\u0439 \u0438 \u0441\u044e\u0440\u044a\u0435\u043a\u0446\u0438\u0435\u0439\nlemma bijective_def : bijective f \u2194 injective f \u2227 surjective f :=\nbegin\n  -- \u0432\u0435\u0440\u043d\u043e \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e\n  refl\nend\n\n-- \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u043d\u0435\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\n-- \u0422\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f - \u0431\u0438\u0435\u043a\u0446\u0438\u044f\nlemma bijective_id : bijective (id : X \u2192 X) :=\nbegin\n  exact \u27e8injective_id, surjective_id\u27e9,\nend\n\n-- \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0431\u0438\u0435\u043a\u0446\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0438\u0435\u043a\u0446\u0438\u0435\u0439\nlemma bijective_comp (hf : bijective f) (hg : bijective g) : bijective (g \u2218 f) :=\nbegin\n  exact \u27e8injective_comp hf.1 hg.1, surjective_comp hf.2 hg.2\u27e9,\nend\n\n\nvariables (S : set X) (T : set Y)\n\n-- \u041e\u0431\u0440\u0430\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 `S : set X` \u043f\u043e\u0434 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 `f : X \u2192 Y` \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a `(f '' S) : set Y`\n-- `y \u2208 f '' S` \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0440\u0430\u0432\u043d\u043e `\u2203 x : X, x \u2208 S \u2227 f x = y`\n-- \u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u044d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f `set.image : (X \u2192 Y) \u2192 set X \u2192 set Y` \n#check set.image\nexample : set.image f S = f '' S := rfl\n\nlemma mem_image : y \u2208 f '' S = \u2203 x : X, x \u2208 S \u2227 f x = y :=\nbegin\n  refl,\nend\n\n-- \u041e\u0431\u0440\u0430\u0437 \u0442\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\nlemma image_id : id '' S = S :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8x\u2081, x\u2081S, hx\u2081\u27e9,\n    rw [\u2190 hx\u2081, id],\n    exact x\u2081S, },\n  { intro xS,\n    use x,\n    rw id,\n    use xS,\n    -- \u043e\u0441\u0442\u0430\u0432\u0448\u0430\u044f \u0446\u0435\u043b\u044c \u0437\u0430\u043a\u0440\u044b\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e `refl` \u043f\u043e\u0441\u043b\u0435 `use`\n  }\nend\n\n-- `simp` \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u0446\u0435\u043b\u044c\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f `set.image_id'`, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0430\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c `@[simp]`, \u0447\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0435\u0435 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 `simp` \u043b\u0435\u043c\u043c \nexample : id '' S = S :=  \nbegin\n  ext, simp,\nend\n\n-- \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u043c\u0435\u0441\u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c `rintro \u27e8...\u27e9` \u0438 `refine \u27e8...\u27e9`\n-- \u0422\u0430\u043a\u0442\u0438\u043a\u0430 `refine` \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 `exact` \u0438 `apply`, \u043d\u043e \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c `_` \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044f \u0446\u0435\u043b\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432\n-- \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\n-- x : X\n-- xS : x \u2208 S\n-- h: (g \u2218 f) x = z\n-- \u22a2 z \u2208 g '' (f '' S)\n-- \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f `refine \u27e8f x, _, h\u27e9`, \u0446\u0435\u043b\u044c \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\n-- \u22a2 f x \u2208 f '' S\n-- \u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u0439 \u043d\u0435\u0442, \u0438 \u0432\u0441\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e, `refine` \u0437\u0430\u043a\u0440\u043e\u0435\u0442 \u0446\u0435\u043b\u044c\n\nlemma image_comp (S : set X) : (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z, split,\n  { rintro \u27e8x, xS, h\u27e9,\n    refine \u27e8f x, _, h\u27e9,\n    refine \u27e8x, xS, rfl\u27e9, }, \n  { rintro \u27e8y, \u27e8x, xS, rfl\u27e9, h\u27e9,\n    refine \u27e8x, xS, h\u27e9, }\nend\n\n-- \u0415\u0441\u043b\u0438 `f` - \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f `\u03bb S, f '' S` (\u0442\u043e \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e `S` \u0432 `f '' S`) - \u0442\u043e\u0436\u0435\n-- \u0422\u0430\u043a\u0442\u0438\u043a\u0430 `dsimp` (`definitional simp`) \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a `simp`, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430, \u0432\u0435\u0440\u043d\u044b\u0435 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e\n-- \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e `dsimp` \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \"\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435\" \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u0435, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u03bb-\u0444\u0443\u043d\u043a\u0446\u0438\u0439:\n-- `h : (\u03bb (S : set X), f '' S) S = (\u03bb (S : set X), f '' S) T`\n-- `dsimp at h`\n-- `h : f '' S = f '' T`\n-- \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e `simp`, `dsimp only [h\u2081, h\u2082, h\u2083]` \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u043c\u043c\u044b `h\u2081`, `h\u2082` \u0438 `h\u2083`, \u0430 `dsimp only at h` \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043b\u0435\u043c\u043c (\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043b\u044f\u043c\u0431\u0434 \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0432\u0435\u0449\u0438)\n\n-- \u0414\u043b\u044f \u0441\u0435\u0431\u044f \u044f \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043b\u0435\u043c\u043c\u0443 `image_subset_of_subset: \u2200 S T, f '' S \u2286 f '' T \u2192 S \u2286 T`\n\nlemma image_injective : injective f \u2192 injective (\u03bb S, f '' S) :=\nbegin\n  intro hf,\n  rintro S T hST,\n  simp only at hST,\n  have image_subset : \u2200 S T, f '' S \u2286 f '' T \u2192 S \u2286 T, {\n    clear hST S T,\n    rintro S T hST x xS,\n    -- \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e `rcases hST \u27e8x, xS, rfl\u27e9 with  \u27e8y, yT, hy\u27e9`\n    obtain \u27e8y, yT, hy\u27e9 := hST \u27e8x, xS, rfl\u27e9,\n    rwa (hf hy) at yT,\n  },\n  apply set.subset.antisymm (image_subset S T (eq.subset hST)) (image_subset T S (eq.subset hST.symm)),\nend\n\n-- \u041f\u0440\u043e\u043e\u0431\u0440\u0430\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 `f : X \u2192 Y` \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f `f \u207b\u00b9' : set Y \u2192 set X\n-- \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e: `x \u2208 f \u207b\u00b9' T \u2194 f x \u2208 T`\n\nlemma mem_preimage : x \u2208 f \u207b\u00b9' T \u2194 f x \u2208 T :=\nbegin\n  refl,\nend\n\nlemma comp_preimage (T : set Z) : (g \u2218 f) \u207b\u00b9' T = f \u207b\u00b9' (g \u207b\u00b9' T) :=\nbegin\n  refl,\nend\n\nlemma preimage_injective (hf : surjective f) : injective (\u03bb T, f \u207b\u00b9' T) :=\nbegin\n  rintro S T hST,\n  dsimp at hST,\n  -- \"\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u2200 {S T}, f \u207b\u00b9' S \u2286 f \u207b\u00b9' T \u2192 S \u2286 T\"\n  -- \n  suffices : \u2200 {S T}, f \u207b\u00b9' S \u2286 f \u207b\u00b9' T \u2192 S \u2286 T, { \n    apply set.subset.antisymm (this $ eq.subset hST) (this $ eq.subset hST.symm), \n  },\n  clear hST S T,\n  rintro S T hST y yS, \n  obtain \u27e8y\u2081, rfl\u27e9 := hf y,\n  exact hST yS,  \nend \n\nlemma image_surjective (hf : surjective f) : surjective (\u03bb S, f '' S) :=\nbegin\n  intro T,\n  use [f \u207b\u00b9' T],\n  dsimp only,\n  ext y,\n  split, {\n    rintro \u27e8x, h, rfl\u27e9,\n    exact h,\n  }, {\n    intro yt,\n    obtain \u27e8x, rfl\u27e9 := hf y,\n    exact \u27e8x, yt, rfl\u27e9,\n  }\nend\n\nlemma preimage_surjective (hf : injective f) : surjective (\u03bb S, f \u207b\u00b9' S) :=\nbegin\n  intro T,\n  dsimp only,\n  use [f '' T],\n  ext x,\n  split, {\n    rintro \u27e8x', x'T, fx'\u27e9,\n    rwa \u2190(hf fx'),\n  }, {\n    rintro xT,\n    refine \u27e8x, xT, rfl\u27e9,\n  }\nend\n\n\n\nvariables (\u03b9 : Type) \n\n-- \u041e\u0431\u0440\u0430\u0437 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 `G i` \u043f\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 `f`, \u0440\u0430\u0432\u0435\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e \u043e\u0431\u0440\u0430\u0437\u043e\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 `G i`\n-- \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 `set.mem_Union` \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f\nlemma image_Union (G : \u03b9 \u2192 set X) :  f '' (\u22c3 (i : \u03b9), G i) = \u22c3 (i : \u03b9), f '' (G i) :=\nbegin\n  ext y,\n  split, {\n    dsimp only,\n    rintro \u27e8y, \u27e8_, \u27e8i, rfl\u27e9, yFi\u27e9, rfl\u27e9,\n    rw set.mem_Union,\n    refine \u27e8i, y, yFi, rfl\u27e9,\n  }, {\n    rw set.mem_Union,\n    rintro \u27e8i, \u27e8x, xFi, rfl\u27e9\u27e9,\n    refine \u27e8x, _, rfl\u27e9,\n    rw set.mem_Union,\n    use [i, xFi],\n  }\nend\n\n-- \u041f\u0440\u043e\u043e\u0431\u0440\u0430\u0437 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0440\u0430\u0432\u0435\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u043e\u0431\u0440\u0430\u0437\u043e\u0432\n-- \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 `set.mem_bUnion_iff` \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f\nlemma preimage_bUnion (F : \u03b9 \u2192 set Y) (Z : set \u03b9) :\n  f \u207b\u00b9' (\u22c3 (i \u2208 Z), F i) = \u22c3 (i \u2208 Z), f \u207b\u00b9' (F i) :=\nbegin\n  ext x,\n  rw [mem_preimage, set.mem_bUnion_iff, set.mem_bUnion_iff],\n  refl,\nend\n\nend itmo.lean", "meta": {"author": "VArtem", "repo": "lean-itmo", "sha": "dc44cd06f9f5b984d051831b3aaa7364e64c2dc4", "save_path": "github-repos/lean/VArtem-lean-itmo", "path": "github-repos/lean/VArtem-lean-itmo/lean-itmo-dc44cd06f9f5b984d051831b3aaa7364e64c2dc4/src/week-02/solutions/e02-functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.8824278556326344, "lm_q1q2_score": 0.7410046550126791}}
{"text": "/- \n  Continuous Linear Maps\n\n  These are a well-behaved subset of all linear maps. In finite dimensional normed vector spaces, all linear maps are continuous. For a certain type of normed space (which?), continuous linear maps and bounded linear maps are the same.\n\n  The derivative of f : E \u2192 F is f' : E \u2192 continuous_linear_map E F.\n-/\n\nimport differentiability.normed_space\n\nuniverses u v w x\n\n-- TODO: maybe continuous should be a structure and not a regular prop\nstructure is_continuous_linear_map {k : Type u} {E : Type v} {F : Type w} [normed_field k] [normed_space k E] [normed_space k F] (L : E \u2192 F) extends is_linear_map L : Prop :=\n(continuous : continuous L)\n\nnamespace is_continuous_linear_map\nvariables {k : Type u} {E : Type v} {F : Type w} {G : Type x}\nvariables [normed_field k] [normed_space k E] [normed_space k F] [normed_space k G]\nvariable {L : E \u2192 F}\ninclude k\n\nsection\nvariable (hL : is_continuous_linear_map L)\ninclude hL\n\n-- linear map simp lemmas\n-- TODO: should there be an smul lemma\n@[simp] lemma zero : L 0 = 0 := hL.to_is_linear_map.zero\n@[simp] lemma neg (v : E) : L (- v) = - L v := hL.to_is_linear_map.neg _\n@[simp] lemma sub (v w : E) : L (v - w) = L v - L w := hL.to_is_linear_map.sub _ _\n@[simp] lemma sum {\u03b9 : Type x} {t : finset \u03b9} {f : \u03b9 \u2192 E} : L (t.sum f) = t.sum (\u03bbi, L (f i)) := hL.to_is_linear_map.sum\n\nend\n\n-- TODO: is_linear_map and continuous have different order conventions for this theorem. adopting is_linear_map's\nlemma comp {M : G \u2192 E} : is_continuous_linear_map L \u2192 is_continuous_linear_map M \u2192 is_continuous_linear_map (L \u2218 M)\n| \u27e8L_lin, L_cont\u27e9 \u27e8M_lin, M_cont\u27e9 := \u27e8is_linear_map.comp L_lin M_lin, continuous.comp M_cont L_cont\u27e9\n\nlemma id : is_continuous_linear_map (id : E \u2192 E) := \u27e8is_linear_map.id, continuous_id\u27e9\n\n-- no inverse thm except for special circumstances\n\nlemma map_zero : is_continuous_linear_map (\u03bbv, 0 : E \u2192 F) := \u27e8is_linear_map.map_zero, continuous_const\u27e9\n\n-- TODO: could move hypothesis to the left if continuous was a structure b/c then I could use to_is_continuous\nlemma map_neg : is_continuous_linear_map L \u2192 is_continuous_linear_map (\u03bbv, - L v)\n| \u27e8lin, cont\u27e9 := \u27e8is_linear_map.map_neg lin, continuous_neg cont\u27e9\n\nlemma map_add {M : E \u2192 F} : is_continuous_linear_map L \u2192 is_continuous_linear_map M \u2192 is_continuous_linear_map (\u03bbv, L v + M v)\n| \u27e8L_lin, L_cont\u27e9 \u27e8M_lin, M_cont\u27e9 := \u27e8is_linear_map.map_add L_lin M_lin, continuous_add L_cont M_cont\u27e9\n\n-- TODO: I don't understand this lemma so I don't want to translate it\n/- lemma map_sum [decidable_eq \u03b4] {t : finset \u03b4} {f : \u03b4 \u2192 \u03b2 \u2192 \u03b3} :\n  (\u2200d\u2208t, is_linear_map (f d)) \u2192 is_linear_map (\u03bbb, t.sum $ \u03bbd, f d b) -/\n\nlemma map_sub {M : E \u2192 F} : is_continuous_linear_map L \u2192 is_continuous_linear_map M \u2192 is_continuous_linear_map (\u03bbv, L v - M v)\n| \u27e8L_lin, L_cont\u27e9 \u27e8M_lin, M_cont\u27e9 := \u27e8is_linear_map.map_sub L_lin M_lin, continuous_sub L_cont M_cont\u27e9\n\n-- TODO: this requires topological vector spaces\nlemma map_smul_right {c : k} : is_continuous_linear_map L \u2192\n  is_continuous_linear_map (\u03bbv, c \u2022 L v)\n| \u27e8lin, cont\u27e9 := \u27e8is_linear_map.map_smul_right lin, sorry\u27e9\n\n-- TODO: this requires topological vector spaces and normed_field.to_normed_space (see ring.to_module in module.lean)\nlemma map_smul_left {L : E \u2192 k} {v : F} : is_continuous_linear_map L \u2192 is_continuous_linear_map (\u03bbc, L c \u2022 v)\n| \u27e8lin, cont\u27e9 := sorry\n\nend is_continuous_linear_map\n\n-- begins diverging from homeos approach\n-- draw from linear_map_module and poly\n-- TODO: convert poly-like theorems\ndef continuous_linear_map {k : Type u} (E : Type v) (F : Type w) [normed_field k] [normed_space k E] [normed_space k F] :=\nsubtype (@is_continuous_linear_map k E F _ _ _)\n\nnamespace continuous_linear_map\nvariables {k : Type u} {E : Type v} {F : Type w} {G : Type x}\nvariables [normed_field k] [normed_space k E] [normed_space k F] [normed_space k G]\nvariables {c : k} {v w : E} {L M : continuous_linear_map E F}\ninclude k\n\ninstance : has_coe_to_fun (continuous_linear_map E F) := \u27e8_, subtype.val\u27e9\n\n@[extensionality]\ntheorem ext {M : continuous_linear_map E F} (h : \u2200 v, L v = M v) : L = M := subtype.eq $ funext h\n\nlemma is_clm (L : continuous_linear_map E F) : is_continuous_linear_map L := L.property\n\ndef subst (L : continuous_linear_map E F) (M : E \u2192 F) (e : \u2200 v, L v = M v) : continuous_linear_map E F :=\n\u27e8M, by rw \u2190 (funext e : coe_fn L = M); exact L.is_clm\u27e9\n\ndef comp (L :continuous_linear_map F G) (M : continuous_linear_map E F) : continuous_linear_map E G := \u27e8\u03bbv, L (M v), is_continuous_linear_map.comp L.is_clm M.is_clm\u27e9\n\n@[simp] lemma map_add  : L (v + w) = L v + L w := L.is_clm.add v w\n@[simp] lemma map_zero : L 0 = 0 := L.is_clm.zero\n@[simp] lemma map_smul : L (c \u2022 v) = c \u2022 L v := L.is_clm.smul c v\n@[simp] lemma map_neg  : L (-v) = -L v := L.is_clm.neg _\n@[simp] lemma map_sub  : L (v - w) = L v - L w := L.is_clm.sub _ _\n\nsection add_comm_group\n\ndef add : continuous_linear_map E F \u2192 continuous_linear_map E F \u2192 continuous_linear_map E F := \u03bb L M, \u27e8L + M, is_continuous_linear_map.map_add L.is_clm M.is_clm\u27e9\n\ndef zero : continuous_linear_map E F := \u27e8\u03bbv, 0, is_continuous_linear_map.map_zero\u27e9\n\ndef neg : continuous_linear_map E F \u2192 continuous_linear_map E F := \u03bb L, \u27e8\u03bbv, -(L v), is_continuous_linear_map.map_neg L.is_clm\u27e9\n\ninstance : has_add (continuous_linear_map E F) := \u27e8add\u27e9\ninstance : has_zero (continuous_linear_map E F) := \u27e8zero\u27e9\ninstance : has_neg (continuous_linear_map E F) := \u27e8neg\u27e9\n\n@[simp] lemma add_app : (L + M) v = L v + M v := rfl\n@[simp] lemma zero_app : (0 : continuous_linear_map E F) v = 0 := rfl\n@[simp] lemma neg_app : (-L) v = -L v := rfl\n\ninstance : add_comm_group (continuous_linear_map E F) :=\nby refine {add := (+), zero := 0, neg := has_neg.neg, ..}; { intros, apply ext, simp }\n\nend add_comm_group\n\nsection module\n\n-- TODO: need to prove topological vector space stuff\ndef smul : k \u2192 continuous_linear_map E F \u2192 continuous_linear_map E F := \u03bb c L, \u27e8\u03bb v, c\u2022(L v), is_continuous_linear_map.smul_right c L.is_clm\u27e9\n\ninstance : has_scalar k (continuous_linear_map E F) := \u27e8smul\u27e9\n\n@[simp] lemma smul_app : (c \u2022 L) v = c \u2022 (L v) := rfl\n\ninstance : module k (continuous_linear_map E F) :=\nby refine {smul := (\u2022), ..continuous_linear_map.add_comm_group, ..};\n  { intros, apply ext, simp [smul_add, add_smul, mul_smul] }\n\nend module\n\nsection metric_space\n\n-- TODO!\n\nend metric_space\n\nsection normed_space\n\n-- TODO!\n\nend normed_space\n\nend continuous_linear_map\n", "meta": {"author": "joshpoll", "repo": "differential_geometry", "sha": "57e00a7e37b7c4c73c847429171ff63d3a48def5", "save_path": "github-repos/lean/joshpoll-differential_geometry", "path": "github-repos/lean/joshpoll-differential_geometry/differential_geometry-57e00a7e37b7c4c73c847429171ff63d3a48def5/src/continuous_linear_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7409415832902523}}
{"text": "open Classical\n\nvariable (p q r : Prop)\n\nexample : (p \u2192 q \u2228 r) \u2192 ((p \u2192 q) \u2228 (p \u2192 r)) :=\n    (fun hpqr : p \u2192 q \u2228 r =>\n      Or.elim\n        (em p)\n        (fun hp : p =>\n          Or.elim\n            (hpqr hp)\n            (fun hq : q => Or.intro_left (p \u2192 r) (fun p => hq))\n            (fun hr : r => Or.intro_right (p \u2192 q) (fun p => hr))\n        )\n        (fun hnp : \u00acp =>\n          Or.intro_right (p \u2192 q) (fun hp : p => False.elim (hnp hp))\n        )\n    )\n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n    (fun hpq : \u00ac(p \u2227 q) =>\n      Or.elim\n        (em p)\n        (fun hp : p =>\n          Or.inr (show \u00acq from fun hq : q =>\n            show False from hpq \u27e8hp, hq\u27e9)\n        )\n        (fun hnp : \u00acp => Or.inl hnp)\n    )\n\n-- basically a truth-table proof via syntax...\n-- hackish\n-- would be better if you proved by contradiction using deMorgan\n-- but you had to prove deMorgan as an example, not a named theorem, so csf\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n    (fun hyp : \u00ac(p \u2192 q) =>\n      byCases\n      -- case 1 : p\n        (fun hp : p =>\n          byCases\n          -- case 1.a : p and q\n            (fun hq : q =>\n              \u27e8\n                hp, show \u00acq from (fun q => show False from hyp (fun p => hq))\n              \u27e9\n            )\n          -- case 1.b : p and non q\n            (fun hnq : \u00acq => \u27e8hp, hnq\u27e9)\n        )\n      -- case 2 : non p\n        (fun hnp : \u00acp => show (p \u2227 \u00acq) from False.elim\n          (show False from hyp\n            (show (p \u2192 q) from fun p : p =>\n              (show q from False.elim (hnp p))\n            )\n          )\n        )\n    )\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n  (fun h : p \u2192 q =>\n    byCases\n      (fun hp : p => Or.inr (h hp))\n      (fun hnp : \u00acp => Or.inl hnp)\n  )\n\n--- again, would be cleaner by contradiction\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n    (fun hyp : (\u00acq \u2192 \u00acp) =>\n      byCases\n        (fun hq : q =>\n          byCases\n            (fun hp : p => (fun p => hq))\n            (fun hnp : \u00acp => (fun p => show q from False.elim (hnp p)))\n        )\n        (fun hnq : \u00acq => (fun hp : p => show q from False.elim ((hyp hnq) hp)))\n    )\n\nexample : p \u2228 \u00acp :=\n  byContradiction\n    (fun hyp : \u00ac(p \u2228 \u00acp) =>\n      absurd (fun hp : p => show False from (hyp (Or.inl hp)))\n             (fun hnp : \u00acp => show False from (hyp (Or.inr hnp)))\n    )\n\n-- ugly\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\n    (fun impl : (p \u2192 q) \u2192 p =>\n      byContradiction\n      -- suppose not p\n        (fun hyp : \u00acp =>\n          -- we reach the absurd conclusion that p\n          -- by the implication that (p->q)->p\n          absurd (impl\n            -- since we can show that (p->q)\n            (show (p \u2192 q) from (fun hp : p => show q from\n              False.elim (hyp hp)\n              )\n            )\n          ) hyp\n        )\n    )", "meta": {"author": "Pasarel", "repo": "lean-warmup", "sha": "abddd28c30cb2d0e16229979769d72a00d179d09", "save_path": "github-repos/lean/Pasarel-lean-warmup", "path": "github-repos/lean/Pasarel-lean-warmup/lean-warmup-abddd28c30cb2d0e16229979769d72a00d179d09/Classical_Proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.80563219364797, "lm_q1q2_score": 0.740893633313379}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module data.nat.choose.vandermonde\n! leanprover-community/mathlib commit 69c6a5a12d8a2b159f20933e60115a4f2de62b58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Polynomial.Coeff\nimport Mathbin.Data.Nat.Choose.Basic\n\n/-!\n\n# Vandermonde's identity\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove Vandermonde's identity (`nat.add_choose_eq`):\n`(m + n).choose k = \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, m.choose ij.1 * n.choose ij.2`\n\nWe follow the algebraic proof from\nhttps://en.wikipedia.org/wiki/Vandermonde%27s_identity#Algebraic_proof .\n\n-/\n\n\nopen BigOperators\n\nopen Polynomial Finset.Nat\n\n#print Nat.add_choose_eq /-\n/-- Vandermonde's identity -/\ntheorem Nat.add_choose_eq (m n k : \u2115) :\n    (m + n).choose k = \u2211 ij : \u2115 \u00d7 \u2115 in antidiagonal k, m.choose ij.1 * n.choose ij.2 :=\n  by\n  calc\n    (m + n).choose k = ((X + 1) ^ (m + n)).coeff k := _\n    _ = ((X + 1) ^ m * (X + 1) ^ n).coeff k := by rw [pow_add]\n    _ = \u2211 ij : \u2115 \u00d7 \u2115 in antidiagonal k, m.choose ij.1 * n.choose ij.2 := _\n    \n  \u00b7 rw [coeff_X_add_one_pow, Nat.cast_id]\n  \u00b7 rw [coeff_mul, Finset.sum_congr rfl]\n    simp only [coeff_X_add_one_pow, Nat.cast_id, eq_self_iff_true, imp_true_iff]\n#align nat.add_choose_eq Nat.add_choose_eq\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Choose/Vandermonde.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7408936233271729}}
{"text": "-- Pruebas de (A \u2229 B\u1d9c) \u222a B = A \u222a B\n-- ===============================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    (A \u2229 B\u1d9c) \u222a B = A \u222a B\n-- ----------------------------------------------------\n\nimport data.set\n\nopen set\n\nvariable  U : Type\nvariables A B C : set U\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (A \u2229 B\u1d9c) \u222a B = A \u222a B :=\ncalc\n  (A \u2229 B\u1d9c) \u222a B = (A \u222a B) \u2229 (B\u1d9c \u222a B) : by rw union_distrib_right\n           ... = (A \u222a B) \u2229 univ     : by rw compl_union_self\n           ... = A \u222a B              : by rw inter_univ\n\nexample : (A \u2229 B) \u222a C = (A \u222a C) \u2229 (B \u222a C) :=\n-- by library_search \nunion_distrib_right A B C\n\nexample : B\u1d9c \u222a B = univ :=\n-- by library_search\ncompl_union_self B\n\nexample : A \u2229 univ = A :=\n-- by library_search\ninter_univ A\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (A \u2229 B\u1d9c) \u222a B = A \u222a B :=\nbegin\n  rw union_distrib_right,\n  rw compl_union_self,\n  rw inter_univ,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (A \u2229 B\u1d9c) \u222a B = A \u222a B :=\nby rw [union_distrib_right, compl_union_self, inter_univ]\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (A \u2229 B\u1d9c) \u222a B = A \u222a B :=\nby simp [union_distrib_right]\n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Prueba_de_(A\u2229B\u1d9c)\u222aB_igual_A\u222aB.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7408653873800286}}
{"text": "/-\nCopyright (c) 2022 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n\n! This file was ported from Lean 3 source module topology.uniform_space.equicontinuity\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.UniformSpace.UniformConvergenceTopology\n\n/-!\n# Equicontinuity of a family of functions\n\nLet `X` be a topological space and `\u03b1` a `UniformSpace`. A family of functions `F : \u03b9 \u2192 X \u2192 \u03b1`\nis said to be *equicontinuous at a point `x\u2080 : X`* when, for any entourage `U` in `\u03b1`, there is a\nneighborhood `V` of `x\u2080` such that, for all `x \u2208 V`, and *for all `i`*, `F i x` is `U`-close to\n`F i x\u2080`. In other words, one has `\u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200 i, (F i x\u2080, F i x) \u2208 U`.\nFor maps between metric spaces, this corresponds to\n`\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, \u2200 i, dist x\u2080 x < \u03b4 \u2192 dist (F i x\u2080) (F i x) < \u03b5`.\n\n`F` is said to be *equicontinuous* if it is equicontinuous at each point.\n\nA closely related concept is that of ***uniform*** *equicontinuity* of a family of functions\n`F : \u03b9 \u2192 \u03b2 \u2192 \u03b1` between uniform spaces, which means that, for any entourage `U` in `\u03b1`, there is an\nentourage `V` in `\u03b2` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and\n`F i y` are `U`-close. In other words, one has\n`\u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 xy in \ud835\udce4 \u03b2, \u2200 i, (F i xy.1, F i xy.2) \u2208 U`.\nFor maps between metric spaces, this corresponds to\n`\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x y, \u2200 i, dist x y < \u03b4 \u2192 dist (F i x\u2080) (F i x) < \u03b5`.\n\n## Main definitions\n\n* `EquicontinuousAt`: equicontinuity of a family of functions at a point\n* `Equicontinuous`: equicontinuity of a family of functions on the whole domain\n* `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain\n\n## Main statements\n\n* `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity\n  condition between well-chosen function spaces. This is really useful for building up the theory.\n* `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure\n  *for the topology of uniform convergence* is also equicontinuous.\n\n## Notations\n\nThroughout this file, we use :\n- `\u03b9`, `\u03ba` for indexing types\n- `X`, `Y`, `Z` for topological spaces\n- `\u03b1`, `\u03b2`, `\u03b3` for uniform spaces\n\n## Implementation details\n\nWe choose to express equicontinuity as a properties of indexed families of functions rather\nthan sets of functions for the following reasons:\n- it is really easy to express equicontinuity of `H : set (X \u2192 \u03b1)` using our setup: it is just\n  equicontinuity of the family `(\u2191) : \u21a5H \u2192 (X \u2192 \u03b1)`. On the other hand, going the other way around\n  would require working with the range of the family, which is always annoying because it\n  introduces useless existentials.\n- in most applications, one doesn't work with bare functions but with a more specific hom type\n  `hom`. Equicontinuity of a set `H : set hom` would then have to be expressed as equicontinuity\n  of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families,\n  because equicontinuity of a family `\ud835\udcd5 : \u03b9 \u2192 hom` would simply be expressed as equicontinuity\n  of `coe_fn \u2218 \ud835\udcd5`, which doesn't introduce any nasty existentials.\n\nTo simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous`\nand `Set.UniformEquicontinuous` asserting the corresponding fact about the family\n`(\u2191) : \u21a5H \u2192 (X \u2192 \u03b1)` where `H : Set (X \u2192 \u03b1)`. Note however that these won't work for sets of hom\ntypes, and in that case one should go back to the family definition rather than using `Set.image`.\n\nSince we have no use case for it yet, we don't introduce any relative version\n(i.e no `EquicontinuousWithinAt` or `EquicontinuousOn`), but this is more of a conservative\nposition than a design decision, so anyone needing relative versions should feel free to add them,\nand that should hopefully be a straightforward task.\n\n## References\n\n* [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966]\n\n## Tags\n\nequicontinuity, uniform convergence, ascoli\n-/\n\n\nsection\n\nopen UniformSpace Filter Set\n\nopen Uniformity Topology UniformConvergence\n\nvariable {\u03b9 \u03ba X Y Z \u03b1 \u03b2 \u03b3 \ud835\udcd5 : Type _} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z]\n  [UniformSpace \u03b1] [UniformSpace \u03b2] [UniformSpace \u03b3]\n\n/-- A family `F : \u03b9 \u2192 X \u2192 \u03b1` of functions from a topological space to a uniform space is\n*equicontinuous at `x\u2080 : X`* if, for all entourage `U \u2208 \ud835\udce4 \u03b1`, there is a neighborhood `V` of `x\u2080`\nsuch that, for all `x \u2208 V` and for all `i : \u03b9`, `F i x` is `U`-close to `F i x\u2080`. -/\ndef EquicontinuousAt (F : \u03b9 \u2192 X \u2192 \u03b1) (x\u2080 : X) : Prop :=\n  \u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200 i, (F i x\u2080, F i x) \u2208 U\n#align equicontinuous_at EquicontinuousAt\n\n/-- We say that a set `H : set (X \u2192 \u03b1)` of functions is equicontinuous at a point if the family\n`(\u2191) : \u21a5H \u2192 (X \u2192 \u03b1)` is equicontinuous at that point. -/\nprotected abbrev Set.EquicontinuousAt (H : Set <| X \u2192 \u03b1) (x\u2080 : X) : Prop :=\n  EquicontinuousAt ((\u2191) : H \u2192 X \u2192 \u03b1) x\u2080\n#align set.equicontinuous_at Set.EquicontinuousAt\n\n/-- A family `F : \u03b9 \u2192 X \u2192 \u03b1` of functions from a topological space to a uniform space is\n*equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/\ndef Equicontinuous (F : \u03b9 \u2192 X \u2192 \u03b1) : Prop :=\n  \u2200 x\u2080, EquicontinuousAt F x\u2080\n#align equicontinuous Equicontinuous\n\n/-- We say that a set `H : set (X \u2192 \u03b1)` of functions is equicontinuous if the family\n`(\u2191) : \u21a5H \u2192 (X \u2192 \u03b1)` is equicontinuous. -/\nprotected abbrev Set.Equicontinuous (H : Set <| X \u2192 \u03b1) : Prop :=\n  Equicontinuous ((\u2191) : H \u2192 X \u2192 \u03b1)\n#align set.equicontinuous Set.Equicontinuous\n\n/-- A family `F : \u03b9 \u2192 \u03b2 \u2192 \u03b1` of functions between uniform spaces is *uniformly equicontinuous* if,\nfor all entourage `U \u2208 \ud835\udce4 \u03b1`, there is an entourage `V \u2208 \ud835\udce4 \u03b2` such that, whenever `x` and `y` are\n`V`-close, we have that, *for all `i : \u03b9`*, `F i x` is `U`-close to `F i x\u2080`. -/\ndef UniformEquicontinuous (F : \u03b9 \u2192 \u03b2 \u2192 \u03b1) : Prop :=\n  \u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 xy : \u03b2 \u00d7 \u03b2 in \ud835\udce4 \u03b2, \u2200 i, (F i xy.1, F i xy.2) \u2208 U\n#align uniform_equicontinuous UniformEquicontinuous\n\n/-- We say that a set `H : set (X \u2192 \u03b1)` of functions is uniformly equicontinuous if the family\n`(\u2191) : \u21a5H \u2192 (X \u2192 \u03b1)` is uniformly equicontinuous. -/\nprotected abbrev Set.UniformEquicontinuous (H : Set <| \u03b2 \u2192 \u03b1) : Prop :=\n  UniformEquicontinuous ((\u2191) : H \u2192 \u03b2 \u2192 \u03b1)\n#align set.uniform_equicontinuous Set.UniformEquicontinuous\n\n/-- Reformulation of equicontinuity at `x\u2080` comparing two variables near `x\u2080` instead of comparing\nonly one with `x\u2080`. -/\ntheorem equicontinuousAt_iff_pair {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} :\n    EquicontinuousAt F x\u2080 \u2194\n      \u2200 U \u2208 \ud835\udce4 \u03b1, \u2203 V \u2208 \ud835\udcdd x\u2080, \u2200 x \u2208 V, \u2200 y \u2208 V, \u2200 i, (F i x, F i y) \u2208 U := by\n  constructor <;> intro H U hU\n  \u00b7 rcases comp_symm_mem_uniformity_sets hU with \u27e8V, hV, hVsymm, hVU\u27e9\n    refine' \u27e8_, H V hV, fun x hx y hy i => hVU (prod_mk_mem_compRel _ (hy i))\u27e9\n    exact hVsymm.mk_mem_comm.mp (hx i)\n  \u00b7 rcases H U hU with \u27e8V, hV, hVU\u27e9\n    filter_upwards [hV]using fun x hx i => hVU x\u2080 (mem_of_mem_nhds hV) x hx i\n#align equicontinuous_at_iff_pair equicontinuousAt_iff_pair\n\n/-- Uniform equicontinuity implies equicontinuity. -/\ntheorem UniformEquicontinuous.equicontinuous {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h : UniformEquicontinuous F) :\n    Equicontinuous F := fun x\u2080 U hU =>\n  mem_of_superset (ball_mem_nhds x\u2080 (h U hU)) fun _ hx i => hx i\n#align uniform_equicontinuous.equicontinuous UniformEquicontinuous.equicontinuous\n\n/-- Each function of a family equicontinuous at `x\u2080` is continuous at `x\u2080`. -/\ntheorem EquicontinuousAt.continuousAt {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (h : EquicontinuousAt F x\u2080) (i : \u03b9) :\n    ContinuousAt (F i) x\u2080 := by\n  intro U hU\n  rw [UniformSpace.mem_nhds_iff] at hU\n  rcases hU with \u27e8V, hV\u2081, hV\u2082\u27e9\n  exact mem_map.mpr (mem_of_superset (h V hV\u2081) fun x hx => hV\u2082 (hx i))\n#align equicontinuous_at.continuous_at EquicontinuousAt.continuousAt\n\nprotected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X \u2192 \u03b1} {x\u2080 : X}\n    (h : H.EquicontinuousAt x\u2080) {f : X \u2192 \u03b1} (hf : f \u2208 H) : ContinuousAt f x\u2080 :=\n  h.continuousAt \u27e8f, hf\u27e9\n#align set.equicontinuous_at.continuous_at_of_mem Set.EquicontinuousAt.continuousAt_of_mem\n\n/-- Each function of an equicontinuous family is continuous. -/\ntheorem Equicontinuous.continuous {F : \u03b9 \u2192 X \u2192 \u03b1} (h : Equicontinuous F) (i : \u03b9) :\n    Continuous (F i) :=\n  continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i\n#align equicontinuous.continuous Equicontinuous.continuous\n\nprotected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X \u2192 \u03b1} (h : H.Equicontinuous)\n    {f : X \u2192 \u03b1} (hf : f \u2208 H) : Continuous f :=\n  h.continuous \u27e8f, hf\u27e9\n#align set.equicontinuous.continuous_of_mem Set.Equicontinuous.continuous_of_mem\n\n/-- Each function of a uniformly equicontinuous family is uniformly continuous. -/\ntheorem UniformEquicontinuous.uniformContinuous {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h : UniformEquicontinuous F)\n    (i : \u03b9) : UniformContinuous (F i) := fun U hU =>\n  mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i)\n#align uniform_equicontinuous.uniform_continuous UniformEquicontinuous.uniformContinuous\n\nprotected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| \u03b2 \u2192 \u03b1}\n    (h : H.UniformEquicontinuous) {f : \u03b2 \u2192 \u03b1} (hf : f \u2208 H) : UniformContinuous f :=\n  h.uniformContinuous \u27e8f, hf\u27e9\n#align set.uniform_equicontinuous.uniform_continuous_of_mem Set.UniformEquicontinuous.uniformContinuous_of_mem\n\n/-- Taking sub-families preserves equicontinuity at a point. -/\ntheorem EquicontinuousAt.comp {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (h : EquicontinuousAt F x\u2080) (u : \u03ba \u2192 \u03b9) :\n    EquicontinuousAt (F \u2218 u) x\u2080 := fun U hU => (h U hU).mono fun _ H k => H (u k)\n#align equicontinuous_at.comp EquicontinuousAt.comp\n\nprotected theorem Set.EquicontinuousAt.mono {H H' : Set <| X \u2192 \u03b1} {x\u2080 : X}\n    (h : H.EquicontinuousAt x\u2080) (hH : H' \u2286 H) : H'.EquicontinuousAt x\u2080 :=\n  h.comp (inclusion hH)\n#align set.equicontinuous_at.mono Set.EquicontinuousAt.mono\n\n/-- Taking sub-families preserves equicontinuity. -/\ntheorem Equicontinuous.comp {F : \u03b9 \u2192 X \u2192 \u03b1} (h : Equicontinuous F) (u : \u03ba \u2192 \u03b9) :\n    Equicontinuous (F \u2218 u) := fun x => (h x).comp u\n#align equicontinuous.comp Equicontinuous.comp\n\nprotected theorem Set.Equicontinuous.mono {H H' : Set <| X \u2192 \u03b1} (h : H.Equicontinuous)\n    (hH : H' \u2286 H) : H'.Equicontinuous :=\n  h.comp (inclusion hH)\n#align set.equicontinuous.mono Set.Equicontinuous.mono\n\n/-- Taking sub-families preserves uniform equicontinuity. -/\ntheorem UniformEquicontinuous.comp {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h : UniformEquicontinuous F) (u : \u03ba \u2192 \u03b9) :\n    UniformEquicontinuous (F \u2218 u) := fun U hU => (h U hU).mono fun _ H k => H (u k)\n#align uniform_equicontinuous.comp UniformEquicontinuous.comp\n\nprotected theorem Set.UniformEquicontinuous.mono {H H' : Set <| \u03b2 \u2192 \u03b1} (h : H.UniformEquicontinuous)\n    (hH : H' \u2286 H) : H'.UniformEquicontinuous :=\n  h.comp (inclusion hH)\n#align set.uniform_equicontinuous.mono Set.UniformEquicontinuous.mono\n\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous at `x\u2080` iff `range \ud835\udcd5` is equicontinuous at `x\u2080`,\ni.e the family `(\u2191) : range F \u2192 X \u2192 \u03b1` is equicontinuous at `x\u2080`. -/\ntheorem equicontinuousAt_iff_range {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} :\n    EquicontinuousAt F x\u2080 \u2194 EquicontinuousAt ((\u2191) : range F \u2192 X \u2192 \u03b1) x\u2080 :=\n  \u27e8fun h => by rw [\u2190 comp_rangeSplitting F]; exact h.comp _, fun h =>\n    h.comp (rangeFactorization F)\u27e9\n#align equicontinuous_at_iff_range equicontinuousAt_iff_range\n\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous iff `range \ud835\udcd5` is equicontinuous,\ni.e the family `(\u2191) : range F \u2192 X \u2192 \u03b1` is equicontinuous. -/\ntheorem equicontinuous_iff_range {F : \u03b9 \u2192 X \u2192 \u03b1} :\n    Equicontinuous F \u2194 Equicontinuous ((\u2191) : range F \u2192 X \u2192 \u03b1) :=\n  forall_congr' fun _ => equicontinuousAt_iff_range\n#align equicontinuous_iff_range equicontinuous_iff_range\n\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous iff `range \ud835\udcd5` is uniformly equicontinuous,\ni.e the family `(\u2191) : range F \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous. -/\ntheorem uniformEquicontinuous_at_iff_range {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} :\n    UniformEquicontinuous F \u2194 UniformEquicontinuous ((\u2191) : range F \u2192 \u03b2 \u2192 \u03b1) :=\n  \u27e8fun h => by rw [\u2190 comp_rangeSplitting F]; exact h.comp _, fun h =>\n    h.comp (rangeFactorization F)\u27e9\n#align uniform_equicontinuous_at_iff_range uniformEquicontinuous_at_iff_range\n\nsection\n\nopen UniformFun\n\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous at `x\u2080` iff the function `swap \ud835\udcd5 : X \u2192 \u03b9 \u2192 \u03b1` is\ncontinuous at `x\u2080` *when `\u03b9 \u2192 \u03b1` is equipped with the topology of uniform convergence*. This is\nvery useful for developping the equicontinuity API, but it should not be used directly for other\npurposes. -/\ntheorem equicontinuousAt_iff_continuousAt {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} :\n    EquicontinuousAt F x\u2080 \u2194 ContinuousAt (ofFun \u2218 Function.swap F : X \u2192 \u03b9 \u2192\u1d64 \u03b1) x\u2080 := by\n  rw [ContinuousAt, (UniformFun.hasBasis_nhds \u03b9 \u03b1 _).tendsto_right_iff]\n  rfl\n#align equicontinuous_at_iff_continuous_at equicontinuousAt_iff_continuousAt\n\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous iff the function `swap \ud835\udcd5 : X \u2192 \u03b9 \u2192 \u03b1` is\ncontinuous *when `\u03b9 \u2192 \u03b1` is equipped with the topology of uniform convergence*. This is\nvery useful for developping the equicontinuity API, but it should not be used directly for other\npurposes. -/\ntheorem equicontinuous_iff_continuous {F : \u03b9 \u2192 X \u2192 \u03b1} :\n    Equicontinuous F \u2194 Continuous (ofFun \u2218 Function.swap F : X \u2192 \u03b9 \u2192\u1d64 \u03b1) := by\n  simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt]\n#align equicontinuous_iff_continuous equicontinuous_iff_continuous\n\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous iff the function `swap \ud835\udcd5 : \u03b2 \u2192 \u03b9 \u2192 \u03b1` is\nuniformly continuous *when `\u03b9 \u2192 \u03b1` is equipped with the uniform structure of uniform convergence*.\nThis is very useful for developping the equicontinuity API, but it should not be used directly\nfor other purposes. -/\ntheorem uniformEquicontinuous_iff_uniformContinuous {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} :\n    UniformEquicontinuous F \u2194 UniformContinuous (ofFun \u2218 Function.swap F : \u03b2 \u2192 \u03b9 \u2192\u1d64 \u03b1) := by\n  rw [UniformContinuous, (UniformFun.hasBasis_uniformity \u03b9 \u03b1).tendsto_right_iff]\n  rfl\n#align uniform_equicontinuous_iff_uniform_continuous uniformEquicontinuous_iff_uniformContinuous\n\n-- Porting note: changed from `\u2203 k (_ : p k), _` to `\u2203 k, p k \u2227 _` since Lean 4 generates the\n-- second one when parsing expressions like `\u2203 \u03b4 > 0, _`.\ntheorem Filter.HasBasis.equicontinuousAt_iff_left {\u03ba : Type _} {p : \u03ba \u2192 Prop} {s : \u03ba \u2192 Set X}\n    {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (hX : (\ud835\udcdd x\u2080).HasBasis p s) :\n    EquicontinuousAt F x\u2080 \u2194 \u2200 U \u2208 \ud835\udce4 \u03b1, \u2203 k, p k \u2227 \u2200 x \u2208 s k, \u2200 i, (F i x\u2080, F i x) \u2208 U := by\n  rw [equicontinuousAt_iff_continuousAt, ContinuousAt,\n    hX.tendsto_iff (UniformFun.hasBasis_nhds \u03b9 \u03b1 _)]\n  simp only [Function.comp_apply, mem_setOf_eq, exists_prop]\n  rfl\n#align filter.has_basis.equicontinuous_at_iff_left Filter.HasBasis.equicontinuousAt_iff_left\n\ntheorem Filter.HasBasis.equicontinuousAt_iff_right {\u03ba : Type _} {p : \u03ba \u2192 Prop} {s : \u03ba \u2192 Set (\u03b1 \u00d7 \u03b1)}\n    {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p s) :\n    EquicontinuousAt F x\u2080 \u2194 \u2200 k, p k \u2192 \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200 i, (F i x\u2080, F i x) \u2208 s k := by\n  rw [equicontinuousAt_iff_continuousAt, ContinuousAt,\n    (UniformFun.hasBasis_nhds_of_basis \u03b9 \u03b1 _ h\u03b1).tendsto_right_iff]\n  rfl\n#align filter.has_basis.equicontinuous_at_iff_right Filter.HasBasis.equicontinuousAt_iff_right\n\n-- Porting note: changed from `\u2203 k (_ : p k), _` to `\u2203 k, p k \u2227 _` since Lean 4 generates the\n-- second one when parsing expressions like `\u2203 \u03b4 > 0, _`.\ntheorem Filter.HasBasis.equicontinuousAt_iff {\u03ba\u2081 \u03ba\u2082 : Type _} {p\u2081 : \u03ba\u2081 \u2192 Prop} {s\u2081 : \u03ba\u2081 \u2192 Set X}\n    {p\u2082 : \u03ba\u2082 \u2192 Prop} {s\u2082 : \u03ba\u2082 \u2192 Set (\u03b1 \u00d7 \u03b1)} {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (hX : (\ud835\udcdd x\u2080).HasBasis p\u2081 s\u2081)\n    (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p\u2082 s\u2082) :\n    EquicontinuousAt F x\u2080 \u2194\n      \u2200 k\u2082, p\u2082 k\u2082 \u2192 \u2203 k\u2081, p\u2081 k\u2081 \u2227 \u2200 x \u2208 s\u2081 k\u2081, \u2200 i, (F i x\u2080, F i x) \u2208 s\u2082 k\u2082 := by\n  rw [equicontinuousAt_iff_continuousAt, ContinuousAt,\n    hX.tendsto_iff (UniformFun.hasBasis_nhds_of_basis \u03b9 \u03b1 _ h\u03b1)]\n  simp only [Function.comp_apply, mem_setOf_eq, exists_prop]\n  rfl\n#align filter.has_basis.equicontinuous_at_iff Filter.HasBasis.equicontinuousAt_iff\n\n-- Porting note: changed from `\u2203 k (_ : p k), _` to `\u2203 k, p k \u2227 _` since Lean 4 generates the\n-- second one when parsing expressions like `\u2203 \u03b4 > 0, _`.\ntheorem Filter.HasBasis.uniformEquicontinuous_iff_left {\u03ba : Type _} {p : \u03ba \u2192 Prop}\n    {s : \u03ba \u2192 Set (\u03b2 \u00d7 \u03b2)} {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h\u03b2 : (\ud835\udce4 \u03b2).HasBasis p s) :\n    UniformEquicontinuous F \u2194\n      \u2200 U \u2208 \ud835\udce4 \u03b1, \u2203 k, p k \u2227 \u2200 x y, (x, y) \u2208 s k \u2192 \u2200 i, (F i x, F i y) \u2208 U := by\n  rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous,\n    h\u03b2.tendsto_iff (UniformFun.hasBasis_uniformity \u03b9 \u03b1)]\n  simp only [Prod.forall, Function.comp_apply, mem_setOf_eq, exists_prop]\n  rfl\n#align filter.has_basis.uniform_equicontinuous_iff_left Filter.HasBasis.uniformEquicontinuous_iff_left\n\ntheorem Filter.HasBasis.uniformEquicontinuous_iff_right {\u03ba : Type _} {p : \u03ba \u2192 Prop}\n    {s : \u03ba \u2192 Set (\u03b1 \u00d7 \u03b1)} {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p s) :\n    UniformEquicontinuous F \u2194 \u2200 k, p k \u2192 \u2200\u1da0 xy : \u03b2 \u00d7 \u03b2 in \ud835\udce4 \u03b2, \u2200 i, (F i xy.1, F i xy.2) \u2208 s k := by\n  rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous,\n    (UniformFun.hasBasis_uniformity_of_basis \u03b9 \u03b1 h\u03b1).tendsto_right_iff]\n  rfl\n#align filter.has_basis.uniform_equicontinuous_iff_right Filter.HasBasis.uniformEquicontinuous_iff_right\n\n-- Porting note: changed from `\u2203 k (_ : p k), _` to `\u2203 k, p k \u2227 _` since Lean 4 generates the\n-- second one when parsing expressions like `\u2203 \u03b4 > 0, _`.\ntheorem Filter.HasBasis.uniformEquicontinuous_iff {\u03ba\u2081 \u03ba\u2082 : Type _} {p\u2081 : \u03ba\u2081 \u2192 Prop}\n    {s\u2081 : \u03ba\u2081 \u2192 Set (\u03b2 \u00d7 \u03b2)} {p\u2082 : \u03ba\u2082 \u2192 Prop} {s\u2082 : \u03ba\u2082 \u2192 Set (\u03b1 \u00d7 \u03b1)} {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1}\n    (h\u03b2 : (\ud835\udce4 \u03b2).HasBasis p\u2081 s\u2081) (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p\u2082 s\u2082) :\n    UniformEquicontinuous F \u2194\n      \u2200 k\u2082, p\u2082 k\u2082 \u2192 \u2203 k\u2081, p\u2081 k\u2081 \u2227 \u2200 x y, (x, y) \u2208 s\u2081 k\u2081 \u2192 \u2200 i, (F i x, F i y) \u2208 s\u2082 k\u2082 := by\n  rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous,\n    h\u03b2.tendsto_iff (UniformFun.hasBasis_uniformity_of_basis \u03b9 \u03b1 h\u03b1)]\n  simp only [Prod.forall, Function.comp_apply, mem_setOf_eq, exists_prop]\n  rfl\n#align filter.has_basis.uniform_equicontinuous_iff Filter.HasBasis.uniformEquicontinuous_iff\n\n/-- Given `u : \u03b1 \u2192 \u03b2` a uniform inducing map, a family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous at a point\n`x\u2080 : X` iff the family `\ud835\udcd5'`, obtained by precomposing each function of `\ud835\udcd5` by `u`, is\nequicontinuous at `x\u2080`. -/\ntheorem UniformInducing.equicontinuousAt_iff {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} {u : \u03b1 \u2192 \u03b2}\n    (hu : UniformInducing u) : EquicontinuousAt F x\u2080 \u2194 EquicontinuousAt ((\u00b7 \u2218 \u00b7) u \u2218 F) x\u2080 := by\n  have := (UniformFun.postcomp_uniformInducing (\u03b1 := \u03b9) hu).inducing\n  rw [equicontinuousAt_iff_continuousAt, equicontinuousAt_iff_continuousAt, this.continuousAt_iff]\n  rfl\n#align uniform_inducing.equicontinuous_at_iff UniformInducing.equicontinuousAt_iff\n\n/-- Given `u : \u03b1 \u2192 \u03b2` a uniform inducing map, a family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous iff the\nfamily `\ud835\udcd5'`, obtained by precomposing each function of `\ud835\udcd5` by `u`, is equicontinuous. -/\ntheorem UniformInducing.equicontinuous_iff {F : \u03b9 \u2192 X \u2192 \u03b1} {u : \u03b1 \u2192 \u03b2} (hu : UniformInducing u) :\n    Equicontinuous F \u2194 Equicontinuous ((\u00b7 \u2218 \u00b7) u \u2218 F) := by\n  have : \u2200 x, EquicontinuousAt F x \u2194 EquicontinuousAt ((fun x x_1 => x \u2218 x_1) u \u2218 F) x := by\n    intro\n    rw [hu.equicontinuousAt_iff]\n  exact \u27e8fun h x => (this x).mp (h x), fun h x => (this x).mpr (h x)\u27e9\n  -- Porting note: proof was:\n  -- congrm (\u2200 x, _ : Prop)\n  -- rw [hu.equicontinuousAt_iff]\n#align uniform_inducing.equicontinuous_iff UniformInducing.equicontinuous_iff\n\n/-- Given `u : \u03b1 \u2192 \u03b3` a uniform inducing map, a family `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous\niff the family `\ud835\udcd5'`, obtained by precomposing each function of `\ud835\udcd5` by `u`, is uniformly\nequicontinuous. -/\ntheorem UniformInducing.uniformEquicontinuous_iff {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} {u : \u03b1 \u2192 \u03b3}\n    (hu : UniformInducing u) : UniformEquicontinuous F \u2194 UniformEquicontinuous ((\u00b7 \u2218 \u00b7) u \u2218 F) := by\n  have := UniformFun.postcomp_uniformInducing (\u03b1 := \u03b9) hu\n  rw [uniformEquicontinuous_iff_uniformContinuous, uniformEquicontinuous_iff_uniformContinuous,\n    this.uniformContinuous_iff]\n  rfl\n#align uniform_inducing.uniform_equicontinuous_iff UniformInducing.uniformEquicontinuous_iff\n\n/-- A version of `EquicontinuousAt.closure` applicable to subsets of types which embed continuously\ninto `X \u2192 \u03b1` with the product topology. It turns out we don't need any other condition on the\nembedding than continuity, but in practice this will mostly be applied to `fun_like` types where\nthe coercion is injective. -/\ntheorem EquicontinuousAt.closure' {A : Set Y} {u : Y \u2192 X \u2192 \u03b1} {x\u2080 : X}\n    (hA : EquicontinuousAt (u \u2218 (\u2191) : A \u2192 X \u2192 \u03b1) x\u2080) (hu : Continuous u) :\n    EquicontinuousAt (u \u2218 (\u2191) : closure A \u2192 X \u2192 \u03b1) x\u2080 := by\n  intro U hU\n  rcases mem_uniformity_isClosed hU with \u27e8V, hV, hVclosed, hVU\u27e9\n  filter_upwards [hA V hV]with x hx\n  rw [SetCoe.forall] at *\n  have hx : A \u2286 (fun f => (u f x\u2080, u f x)) \u207b\u00b9' V := hx\n  -- Porting note: was\n  -- change A \u2286 (fun f => (u f x\u2080, u f x)) \u207b\u00b9' V at hx\n  refine' (closure_minimal hx <| hVclosed.preimage <| _).trans (preimage_mono hVU)\n  exact Continuous.prod_mk ((continuous_apply x\u2080).comp hu) ((continuous_apply x).comp hu)\n#align equicontinuous_at.closure' EquicontinuousAt.closure'\n\n/-- If a set of functions is equicontinuous at some `x\u2080`, its closure for the product topology is\nalso equicontinuous at `x\u2080`. -/\ntheorem EquicontinuousAt.closure {A : Set <| X \u2192 \u03b1} {x\u2080 : X} (hA : A.EquicontinuousAt x\u2080) :\n    (closure A).EquicontinuousAt x\u2080 :=\n  EquicontinuousAt.closure' (u := id) hA continuous_id\n#align equicontinuous_at.closure EquicontinuousAt.closure\n\n/-- If `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` tends to `f : X \u2192 \u03b1` *pointwise* along some nontrivial filter, and if the\nfamily `\ud835\udcd5` is equicontinuous at some `x\u2080 : X`, then the limit is continuous at `x\u2080`. -/\ntheorem Filter.Tendsto.continuousAt_of_equicontinuousAt {l : Filter \u03b9} [l.NeBot] {F : \u03b9 \u2192 X \u2192 \u03b1}\n    {f : X \u2192 \u03b1} {x\u2080 : X} (h\u2081 : Tendsto F l (\ud835\udcdd f)) (h\u2082 : EquicontinuousAt F x\u2080) :\n    ContinuousAt f x\u2080 :=\n  (equicontinuousAt_iff_range.mp h\u2082).closure.continuousAt\n    \u27e8f, mem_closure_of_tendsto h\u2081 <| eventually_of_forall mem_range_self\u27e9\n#align filter.tendsto.continuous_at_of_equicontinuous_at Filter.Tendsto.continuousAt_of_equicontinuousAt\n\n/-- A version of `Equicontinuous.closure` applicable to subsets of types which embed continuously\ninto `X \u2192 \u03b1` with the product topology. It turns out we don't need any other condition on the\nembedding than continuity, but in practice this will mostly be applied to `fun_like` types where\nthe coercion is injective. -/\ntheorem Equicontinuous.closure' {A : Set Y} {u : Y \u2192 X \u2192 \u03b1}\n    (hA : Equicontinuous (u \u2218 (\u2191) : A \u2192 X \u2192 \u03b1)) (hu : Continuous u) :\n    Equicontinuous (u \u2218 (\u2191) : closure A \u2192 X \u2192 \u03b1) := fun x => (hA x).closure' hu\n#align equicontinuous.closure' Equicontinuous.closure'\n\n/-- If a set of functions is equicontinuous, its closure for the product topology is also\nequicontinuous. -/\ntheorem Equicontinuous.closure {A : Set <| X \u2192 \u03b1} (hA : A.Equicontinuous) :\n    (closure A).Equicontinuous := fun x => (hA x).closure\n#align equicontinuous.closure Equicontinuous.closure\n\n/-- If `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` tends to `f : X \u2192 \u03b1` *pointwise* along some nontrivial filter, and if the\nfamily `\ud835\udcd5` is equicontinuous, then the limit is continuous. -/\ntheorem Filter.Tendsto.continuous_of_equicontinuous_at {l : Filter \u03b9} [l.NeBot] {F : \u03b9 \u2192 X \u2192 \u03b1}\n    {f : X \u2192 \u03b1} (h\u2081 : Tendsto F l (\ud835\udcdd f)) (h\u2082 : Equicontinuous F) : Continuous f :=\n  continuous_iff_continuousAt.mpr fun x => h\u2081.continuousAt_of_equicontinuousAt (h\u2082 x)\n#align filter.tendsto.continuous_of_equicontinuous_at Filter.Tendsto.continuous_of_equicontinuous_at\n\n/-- A version of `UniformEquicontinuous.closure` applicable to subsets of types which embed\ncontinuously into `\u03b2 \u2192 \u03b1` with the product topology. It turns out we don't need any other condition\non the embedding than continuity, but in practice this will mostly be applied to `fun_like` types\nwhere the coercion is injective. -/\ntheorem UniformEquicontinuous.closure' {A : Set Y} {u : Y \u2192 \u03b2 \u2192 \u03b1}\n    (hA : UniformEquicontinuous (u \u2218 (\u2191) : A \u2192 \u03b2 \u2192 \u03b1)) (hu : Continuous u) :\n    UniformEquicontinuous (u \u2218 (\u2191) : closure A \u2192 \u03b2 \u2192 \u03b1) := by\n  intro U hU\n  rcases mem_uniformity_isClosed hU with \u27e8V, hV, hVclosed, hVU\u27e9\n  filter_upwards [hA V hV]\n  rintro \u27e8x, y\u27e9 hxy\n  rw [SetCoe.forall] at *\n  have hxy : A \u2286 (fun f => (u f x, u f y)) \u207b\u00b9' V := hxy\n  -- Porting note: was\n  -- change A \u2286 (fun f => (u f x, u f y)) \u207b\u00b9' V at hxy\n  refine' (closure_minimal hxy <| hVclosed.preimage <| _).trans (preimage_mono hVU)\n  exact Continuous.prod_mk ((continuous_apply x).comp hu) ((continuous_apply y).comp hu)\n#align uniform_equicontinuous.closure' UniformEquicontinuous.closure'\n\n/-- If a set of functions is uniformly equicontinuous, its closure for the product topology is also\nuniformly equicontinuous. -/\ntheorem UniformEquicontinuous.closure {A : Set <| \u03b2 \u2192 \u03b1} (hA : A.UniformEquicontinuous) :\n    (closure A).UniformEquicontinuous :=\n  UniformEquicontinuous.closure' (u := id) hA continuous_id\n#align uniform_equicontinuous.closure UniformEquicontinuous.closure\n\n/-- If `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` tends to `f : \u03b2 \u2192 \u03b1` *pointwise* along some nontrivial filter, and if the\nfamily `\ud835\udcd5` is uniformly equicontinuous, then the limit is uniformly continuous. -/\ntheorem Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous {l : Filter \u03b9} [l.NeBot]\n    {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} {f : \u03b2 \u2192 \u03b1} (h\u2081 : Tendsto F l (\ud835\udcdd f)) (h\u2082 : UniformEquicontinuous F) :\n    UniformContinuous f :=\n  (uniformEquicontinuous_at_iff_range.mp h\u2082).closure.uniformContinuous\n    \u27e8f, mem_closure_of_tendsto h\u2081 <| eventually_of_forall mem_range_self\u27e9\n#align filter.tendsto.uniform_continuous_of_uniform_equicontinuous Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous\n\nend\n\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/UniformSpace/Equicontinuity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.740865385403169}}
{"text": "import tactic -- hide\n\n\n/-Lemma \nIf $P,Q$ are logical statements, then $P$ implies $(Q \\implies P)$\n-/\nlemma lemma_2 (P Q : Prop) : P \u2192 Q \u2192 P :=\nbegin\n  intro hP,\n  intro hQ,\n  exact hP,\n\n\n\nend\n\n/-Hint : Caution\n\nNote that implies `\u2192` is not associative: in general `P \u2192 (Q \u2192 R)` and `(P \u2192 Q) \u2192 R`\nmight not be equivalent. This is like subtraction on numbers -- in general\n`a - (b - c)` and `(a - b) - c` might not be equal.\nSo if we write `P \u2192 Q \u2192 R` then we'd better know what this means.\nThe convention in Lean is that it means `P \u2192 (Q \u2192 R)`. If you think\nabout it, this means that to deduce `R` you will need to prove both `P`\nand `Q`. \n-/", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic_1/logic4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7408242338931406}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n/-!\n# Advanced proposition world.\n\n## Level 3: and_trans.\n\nWith this proof we can use the first `cases` tactic to extract hypotheses `p : P` `q : Q` from\n`hpq : P \u2227 Q` and then we can use another `cases` tactic to extract hypotheses `q' : Q` and `r : R` from\n`hpr : Q \u2227 R` then we can split the resulting goal `\u22a2 P \u2227 R` using `constructor` and easily pick off the\nresulting sub-goals `\u22a2 P` and `\u22a2 R` using our given hypotheses.\n\n## Lemma\nIf `P`, `Q` and `R` are true/false statements, then `P \u2227 Q` and\n`Q \u2227 R` together imply `P \u2227 R`.\n-/\nlemma and_trans (P Q R : Prop) : P \u2227 Q \u2192 Q \u2227 R \u2192 P \u2227 R := by\n  intro hpq\n  intro hqr\n  cases hpq with\n  | intro p q =>\n    cases hqr with\n    | intro q' r =>\n      constructor\n      assumption\n      assumption\n\n/-!\n\nNext up [Level 4](./Level4.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedPropositionWorld/Level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7408242283939724}}
{"text": "import analysis.special_functions.integrals\nimport analysis.special_functions.non_integrable\nimport data.real.basic\nimport data.nat.basic\nimport data.int.basic\nimport data.set.basic\nimport data.set.intervals.basic\nimport measure_theory.integral.interval_integral\n\nopen real measure_theory\n\nlemma log_eq_integral_inv {x : \u211d} : 1 \u2264 x \u2192 log x = \u222b (t : \u211d) in 1..x, t\u207b\u00b9 :=\nbegin\n  intro hx,\n  rw integral_inv_of_pos zero_lt_one (lt_of_lt_of_le zero_lt_one hx),\n  simp,\nend\n\nnoncomputable def harmonic (n : \u2115) : nnreal := (finset.Icc 1 n).sum (\u03bb k, (\u2191k)\u207b\u00b9)\n\nnoncomputable def staircase (x : \u211d) : \u211d := (\u2191\u230ax\u230b)\u207b\u00b9\n\n\n-- Show that staircase is antitone on [1, \u221e).\n-- This will be used to show that it is integrable.\n\nlemma antitone_on_staircase : antitone_on staircase (set.Ici 1) :=\nbegin\n  rw antitone_on_iff_forall_lt,\n  simp,\n  intro a, intro ha,\n  intro b, intro hb,\n  intro hab,\n  rw staircase, rw staircase,\n  rw inv_le_inv,\n  { simp,\n    rw int.le_floor,\n    have h := int.floor_le a,\n    exact le_trans h (le_of_lt hab) },\n  { have h := int.lt_floor_add_one b,\n    rw \u2190 add_lt_add_iff_right (1 : \u211d), rw zero_add,\n    exact lt_of_le_of_lt hb h },\n  { have h := int.lt_floor_add_one a,\n    rw \u2190 add_lt_add_iff_right (1 : \u211d), rw zero_add,\n    exact lt_of_le_of_lt ha h },\nend\n\n-- To be used with antitone_on.interval_integrable.\nlemma antitone_on_staircase_uIcc {a b : \u211d} (ha : 1 \u2264 a) (hb : 1 \u2264 b) :\n  antitone_on staircase (set.uIcc a b) :=\nbegin\n  apply antitone_on.mono antitone_on_staircase,\n  cases le_or_lt a b with hab hba,\n  { rw set.uIcc_of_le hab,\n    rw set.Icc_subset_Ici_iff hab,\n    exact ha },\n  { have hba := le_of_lt hba,\n    rw set.uIcc_comm,\n    rw set.uIcc_of_le hba,\n    rw set.Icc_subset_Ici_iff hba,\n    exact hb },\nend\n\n-- Trivial but used in two places.\nlemma interval_integrable_staircase {a b : \u211d} (ha : 1 \u2264 a) (hb : 1 \u2264 b)\n  : interval_integrable staircase volume a b :=\nbegin\n  apply antitone_on.interval_integrable,\n  apply antitone_on_staircase_uIcc ha hb,\nend\n\n\n-- After proving staircase is integrable, prove value of integral.\n\nnoncomputable def const_fun (n : \u2115) : \u211d \u2192 \u211d := \u03bb _, (n : \u211d)\u207b\u00b9\n\nlemma piece_integral_staircase_eq {n : \u2115} :\n  \u222b (t : \u211d) in \u2191n..\u2191n + 1, staircase t = (n : \u211d)\u207b\u00b9 :=\nbegin\n  -- rw interval_integral.integral_of_le (by simp : (n : \u211d) \u2264 (n : \u211d) + 1),\n  rw interval_integral.integral_congr_ae\n    (_ : \u2200\u1d50 (x : \u211d) \u2202_, x \u2208 _ \u2192 staircase x = const_fun n x),\n  { rw const_fun, simp, },\n  { -- Need to prove staircase is ae-equal to const_fun in the interval.\n    rw ae_iff,\n    -- Use volume set \u2264 volume {b} = 0.\n    rw \u2190 le_zero_iff,\n    apply le_of_le_of_eq (measure_mono (_ : _ \u2286 ({\u2191n + 1} : set \u211d))),\n    { exact volume_singleton, },\n    { simp,\n      intros x hax hxb hnp,\n      rw le_iff_lt_or_eq at hxb,\n      cases hxb,\n      { exfalso,\n        apply hnp,\n        rw [staircase, const_fun], simp,\n        rw [\u2190 int.cast_coe_nat, int.cast_inj],\n        rw int.floor_eq_iff, simp,\n        apply and.intro _ hxb,\n        exact le_of_lt hax, },\n      { exact hxb, }, }, },\nend\n\n-- Specialized for natural numbers.\n-- (Could use finset.range instead and shift indices?)\nlemma finset_Ico_succ {a b : \u2115} : finset.Ico a b.succ = finset.Icc a b :=\nbegin\n  ext x,\n  rw finset.mem_Icc,\n  rw finset.mem_Ico,\n  rw nat.lt_succ_iff,\nend\n\n-- Use this function to partition the integral into pieces.\ndef step (k : \u2115) := (k : \u211d)\n\nlemma integral_staircase_eq_harmonic {n : \u2115} :\n  \u222b (t : \u211d) in 1..(\u2191n + 1), staircase t = harmonic n :=\nbegin\n  simp,\n  have ha : step 1 = 1 := by { rw step, simp },\n  have hb : step (n + 1) = (\u2191n + 1) := by { rw step, simp },\n  rw \u2190 hb,\n  rw \u2190 ha,  -- Replaces (1 : \u211d) not (1 : \u2115).\n  have hmn : 1 \u2264 n + 1 := by simp,\n  rw \u2190 interval_integral.sum_integral_adjacent_intervals_Ico hmn,\n  { -- Prove sums are equal.\n    simp_rw step,\n    push_cast,\n    simp_rw piece_integral_staircase_eq,\n    rw harmonic,\n    push_cast,\n    rw finset_Ico_succ, },\n  { -- Prove each interval is integrable.\n    simp_rw step,\n    push_cast,\n    intros k hk,\n    have hp : (1 : \u211d) \u2264 1 := by simp,\n    have hq : (1 : \u211d) \u2264 \u2191k + 1 := by simp,\n    -- TODO: Use mono?\n    apply interval_integrable.mono_set (interval_integrable_staircase hp hq),\n    apply set.uIcc_subset_uIcc_right,\n    simp, exact hk.left, },\nend\n\n\n-- Prove that integral of x\u207b\u00b9 is less than integral of staircase.\n\nlemma inv_le_staircase {x : \u211d} : 1 \u2264 x \u2192 x\u207b\u00b9 \u2264 staircase x :=\nbegin\n  rw staircase,\n  intro hx,\n  rw inv_le_inv,\n  { apply int.floor_le },\n  { apply lt_of_lt_of_le zero_lt_one hx },\n  { rw \u2190 add_lt_add_iff_right (1 : \u211d),\n    rw zero_add,\n    apply lt_of_le_of_lt hx,\n    apply int.lt_floor_add_one },\nend\n\nlemma integral_inv_le_integral_staircase {x : \u211d} :\n  1 \u2264 x \u2192 \u222b (t : \u211d) in 1..x, t\u207b\u00b9 \u2264 \u222b (t : \u211d) in 1..x, staircase t :=\nbegin\n  intro hx,\n  rw \u2190 sub_nonneg,\n  rw \u2190 interval_integral.integral_sub,\n  { apply interval_integral.integral_nonneg hx,\n    intro u, intro hu,\n    simp,\n    apply inv_le_staircase hu.left },\n  { apply interval_integrable_staircase _ hx, simp },\n  { rw interval_integrable_inv_iff,\n    apply or.inr,\n    rw set.uIcc_of_le hx, simp,\n    intro h, exfalso,\n    exact not_le_of_lt zero_lt_one h }\nend\n\n-- Could instead prove \u2200 x : \u211d, log x \u2264 harmonic \u230ax\u230b\u208a\n-- However, the proof only requires a proof for integer values.\nlemma log_add_one_le_harmonic {n : \u2115} : log (\u2191n + 1) \u2264 harmonic n :=\nbegin\n  have hn : (1 : \u211d) \u2264 (\u2191n + 1) := by simp,\n  rw log_eq_integral_inv hn,\n  apply le_trans (integral_inv_le_integral_staircase hn),\n  rw integral_staircase_eq_harmonic,\nend\n", "meta": {"author": "jvlmdr", "repo": "from_the_book", "sha": "d4f557b920d52b69791fc939092a0dd407e895bc", "save_path": "github-repos/lean/jvlmdr-from_the_book", "path": "github-repos/lean/jvlmdr-from_the_book/from_the_book-d4f557b920d52b69791fc939092a0dd407e895bc/src/ch01_integral/log_harmonic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7408242217907959}}
{"text": "/-\nCopyright (c) 2022 Jun Yoshida. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n-/\n\nimport Algdata.Init.Nat\nimport Algdata.Data.Nat.Rec\n\n/-!\n# Power functions\n-/\n\nnamespace Nat\n\nuniverse u\nvariable {\u03b1 : Type u} [OfNat \u03b1 (nat_lit 1)] [HMul \u03b1 \u03b1 \u03b1]\n\n\n/-!\n## Naive generic power function\n-/\n--- naive power\ndef gpow (a : \u03b1) (n : @& Nat) : \u03b1 :=\n  match n with\n  | 0 => 1\n  | (k+1) => a * gpow a k\n\nsection ExponentLaw\n\n@[simp]\ntheorem gpow_zero (a : \u03b1) : gpow a 0 = 1 := rfl\n\n@[simp]\ntheorem gpow_one (mul_one : \u2200 (a : \u03b1), a * 1 = a) (a : \u03b1) : gpow a 1 = a := mul_one a\n\nvariable (one_mul : \u2200 (a : \u03b1), 1 * a = a) (assoc : \u2200 (a b c : \u03b1), (a * b) * c = a * (b * c))\n\n--- Exponent law 1: a\u1d50\u207a\u207f = a\u1d50a\u207f\ndef gpow_add (a : \u03b1) (m n : Nat) : gpow a (m+n) = gpow a m * gpow a n := by\n  induction m\n  case zero =>\n    rw [Nat.zero_add]\n    have : gpow a Nat.zero = 1 := rfl; rw [this]; clear this\n    rw [one_mul]\n  case succ m h_ind =>\n    rw [Nat.succ_add]; dsimp [gpow]\n    rw [h_ind, assoc]\n\n--- Exponent law 2: a\u1d50\u207f = (a\u1d50)\u207f\ndef gpow_mul (a : \u03b1) (m n : Nat) : gpow a (m*n) = gpow (gpow a m) n := by\n  induction n\n  case zero =>\n    rw [Nat.mul_zero]\n    rfl\n  case succ n h_ind =>\n    conv => lhs; rw [Nat.mul_succ, Nat.add_comm _ m, gpow_add one_mul assoc]\n    conv => rhs; dsimp [gpow]\n    rw [h_ind]\n\nend ExponentLaw\n\n\n/-!\n## Power using exponentiation by squaring\n-/\n\n--- exponentiation by squaring\n@[specialize,inline]\ndef sqPow (a : \u03b1) (n : @& Nat) : \u03b1 :=\n  n.recBase2 (motive:=\u03bb _ => \u03b1) 1 a $ \u03bb n x => if n % 2 = 1 then a * x * x else x * x\n\n\n/-!\n## Comparison of powers\n-/\n\ntheorem sqPow_eq_gpow {\u03b1 : Type _} [OfNat \u03b1 (nat_lit 1)] [HMul \u03b1 \u03b1 \u03b1] (mul_one : \u2200 (a : \u03b1), a * 1 = a) (one_mul : \u2200 (a : \u03b1), 1 * a = a) (assoc : \u2200 (a b c : \u03b1), (a*b)*c = a*(b*c)) : \u2200 (a : \u03b1) (n : Nat), sqPow a n = gpow a n := by\n  intro a n\n  unfold sqPow\n  induction n using recBase2 generalizing a\n  case zero => rfl\n  case one =>\n    rw [recBase2_one]\n    exact (mul_one a).symm\n  case div2 n h_ind =>\n    rw [recBase2_div2]\n    rw [h_ind a]\n    by_cases n % 2 = 1\n    case pos hodd =>\n      rw [if_pos hodd]\n      conv =>\n        lhs; change gpow a (n/2 + 2) * gpow a (n/2 + 1)\n        rw [\u2190gpow_add one_mul assoc]\n      apply congrArg\n      conv =>\n        lhs; rw [Nat.add_assoc, \u2190Nat.add_assoc 2 (n/2) 1, Nat.add_comm 2, Nat.add_assoc _ 2 1, \u2190Nat.add_assoc]\n        rw [\u2190Nat.mul_two, Nat.mul_comm, Nat.add_comm 2 1, \u2190Nat.add_assoc, \u2190hodd]\n        rw [Nat.div_add_mod]\n    case neg heven =>\n      rw [if_neg heven]\n      rw [\u2190gpow_add one_mul assoc]\n      have : n % 2 = 0 := Or.resolve_right (Nat.mod_two_eq_zero_or_one n) heven\n      apply congrArg\n      conv =>\n        lhs; rw [Nat.add_assoc, \u2190Nat.add_assoc 1, Nat.add_comm 1, Nat.add_assoc _ 1 1, \u2190Nat.add_assoc]\n        rw [\u2190Nat.mul_two, Nat.mul_comm, \u2190Nat.add_zero (2*(n/2)), \u2190this]\n        rw [Nat.div_add_mod]\n\nend Nat\n", "meta": {"author": "Junology", "repo": "algdata", "sha": "ef0e552747c3f1004705755a3afc7ccedec92bf6", "save_path": "github-repos/lean/Junology-algdata", "path": "github-repos/lean/Junology-algdata/algdata-ef0e552747c3f1004705755a3afc7ccedec92bf6/Algdata/Data/Nat/Pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7407348380777065}}
{"text": "import inner_product_spaces.real_ip.basic\n\nnoncomputable theory\n\nvariables {\u03b1 : Type*}\nvariables [decidable_eq \u03b1] [add_comm_group \u03b1] [vector_space \u211d \u03b1] [\u211d_inner_product_space \u03b1]\n\nopen real\n\ninstance ip_space_has_dist : has_dist \u03b1 := \u27e8\u03bb x y, sqrt (norm_sq (x-y))\u27e9\n\nlemma ip_dist_self (x : \u03b1) : dist x x = 0 :=\nby {dsimp [dist],\n    rw [add_right_neg, norm_sq_zero, sqrt_zero]}\n\nlemma ip_eq_of_dist_eq_zero (x y : \u03b1) (h : dist x y = 0) : x = y :=\nbegin\n    dsimp [dist] at h,\n    rw [real.sqrt_eq_zero (norm_sq_nonneg (x+-y)), zero_iff_norm_sq_zero] at h,\n    exact (eq_of_sub_eq_zero h),\nend\n\nlemma ip_dist_comm (x y : \u03b1) : dist x y = dist y x :=\nby {dsimp [dist],\n    rw [\u2190sub_eq_add_neg, \u2190sub_eq_add_neg, real.sqrt_inj (norm_sq_nonneg (x-y)) (norm_sq_nonneg (y-x)),\n    \u2190neg_sub x y, norm_sq_neg_eq, sub_eq_add_neg]}\n\ninstance ip_space_has_norm : has_norm \u03b1 := \u27e8\u03bb x, sqrt ((norm_sq x))\u27e9\n\n@[simp] lemma sqr_norm {x : \u03b1} : \u2225x\u2225^2 = (norm_sq x) := real.sqr_sqrt (norm_sq_nonneg x)\n\nlemma ip_norm_nonneg {x : \u03b1} : \u2225x\u2225 \u2265 0 := real.sqrt_nonneg (norm_sq x)\n\n@[reducible] def orthog (x y : \u03b1) := \u27eax \u2225 y\u27eb = 0\n\ninfix `\u22a5` := orthog\n\nlemma orthog_symm {x y : \u03b1} (h : x \u22a5 y) : y \u22a5 x :=\nby {dsimp [orthog] at *,\n    rw [\u2190conj_symm x y],\n    exact h}\n\nlemma zero_of_orthog_self {x : \u03b1} : x \u22a5 x \u2192 x = 0 :=\n(zero_iff_norm_sq_zero x).1\n\nlemma add_orthog {x y z : \u03b1} (hx : x \u22a5 z) (hy : y \u22a5 z) : (x+y)\u22a5z :=\nby {dsimp [orthog] at *, rw [add_left, hx, hy, add_zero]}\n\nlemma mul_orthog (x y : \u03b1) (a b : \u211d) (h : x \u22a5 y) : (a\u2022x) \u22a5 (b\u2022y) :=\nby {simp [orthog], repeat {right}, exact h}\n\ntheorem pythagoras {x y : \u03b1} (h : x \u22a5 y) : \u2225x+y\u2225^2 = \u2225x\u2225^2+\u2225y\u2225^2 :=\nby {dsimp [orthog] at h, simp [sqr_norm, norm_sq], rw [\u2190conj_symm x y, h, zero_add, zero_add]}\n\nlemma orthog_of_pythagoras {x y : \u03b1} (h : \u2225x+y\u2225^2 = \u2225x\u2225^2 + \u2225y\u2225^2) : x \u22a5 y :=\nbegin\n    rw [sqr_norm, sqr_norm, sqr_norm, norm_sq_add, add_assoc] at h,\n    conv at h {to_rhs, rw [\u2190add_zero (norm_sq y)]},\n    have w := (add_left_inj _).mp h,\n    have k := congr_arg (\u03bb (r : \u211d), 1/2 * r) w,\n    simp at k,\n    rw [left_distrib, \u2190mul_assoc, inv_mul_cancel two_ne_zero, one_mul] at k,\n    conv at k {to_rhs, rw [\u2190add_zero (2\u207b\u00b9 * norm_sq y)]},\n    exact (add_left_inj _).mp k,\nend\n\nlemma pythagoras_iff_orthog {x y : \u03b1} : \u2225x+y\u2225^2 = \u2225x\u2225^2 + \u2225y\u2225^2 \u2194 x \u22a5 y :=\n\u27e8orthog_of_pythagoras, pythagoras\u27e9\n\n-- Scott: maybe even provide the instance of `normed_group`?\n-- I wonder where in mathlib this belongs. Possibly even `data.real.basic`.\ninstance : has_norm \u211d := \u27e8abs\u27e9\n\ninstance \u211d_normed_space : normed_space \u211d \u211d := by apply_instance\n\nlemma norm_leq_of_norm_sq_leq (x y : \u03b1) (h : \u2225\u27eax \u2225 y\u27eb\u2225^2\u2264\u2225x\u2225^2*\u2225y\u2225^2) : \u2225\u27eax \u2225 y\u27eb\u2225\u2264\u2225x\u2225*\u2225y\u2225 :=\nby {have w := sqrt_le_sqrt h,\n        dsimp [norm] at *,\n        rw [sqrt_mul (pow_two_nonneg _), sqrt_sqr (abs_nonneg _), sqr_sqrt (norm_sq_nonneg _), sqr_sqrt (norm_sq_nonneg _)] at w,\n        exact w}\n\nlemma norm_sq_ip_eq_ip_sqr (x y : \u03b1) : \u2225\u27eax \u2225 y\u27eb\u2225^2 = \u27eax \u2225 y\u27eb^2 :=\nby {dsimp [norm], rw [\u2190sqrt_sqr_eq_abs, sqr_sqrt (pow_two_nonneg _)]}\n\ntheorem cauchy_schwarz (x y : \u03b1) : \u2225\u27eax \u2225 y\u27eb\u2225\u2264\u2225x\u2225*\u2225y\u2225 :=\nbegin\n    by_cases (y=0),\n\n    { dsimp [norm],\n      rw [h],\n      simp },\n    apply norm_leq_of_norm_sq_leq,\n    let c := \u27eax \u2225 y\u27eb/\u2225y\u2225^2,\n    have w := pow_two_nonneg (\u2225x-c\u2022y\u2225),\n    rw [sqr_norm, sqr_norm] at *,\n    rw [norm_sq_ip_eq_ip_sqr],\n    dsimp [norm_sq] at *,\n    simp at w,\n    repeat {rw [\u2190neg_one_smul \u211d (c\u2022y)] at w},\n    repeat {rw [mul_left] at w},\n    repeat {rw [mul_right] at w},\n    rw [conj_symm y x] at w,\n    simp at w,\n    have k\u2081 : c = \u27eax \u2225 y\u27eb/\u2225y\u2225^2 := by refl,\n    rw [k\u2081] at w,\n    have k\u2082 := (neq_zero_iff_norm_sq_neq_zero y).2 h,\n    simp only [sqr_norm] at w,\n    have w\u2081 := div_mul_cancel \u27eax \u2225 y\u27eb k\u2082,\n    dsimp [norm_sq] at *,\n    rw [w\u2081] at w,\n    simp at w,\n    have w\u2082 := le_of_sub_nonneg w,\n    have w\u2083 : \u27eax \u2225 y\u27eb/\u27eay \u2225 y\u27eb = \u27eax \u2225 y\u27eb*\u27eay \u2225 y\u27eb\u207b\u00b9 := by refl,\n    rw [mul_comm, w\u2083, \u2190mul_assoc, \u2190pow_two] at w\u2082,\n    have w\u2084 := norm_sq_nonneg y,\n    dsimp [norm_sq] at w\u2084,\n    have w\u2085 := mul_le_mul_of_nonneg_right w\u2082 w\u2084,\n    rw [mul_assoc, inv_mul_cancel k\u2082, mul_one] at w\u2085,\n    exact w\u2085,\nend\n\nlemma sqr_nonneg (r : \u211d) : r^2 \u2265 0 :=\nby {rw [pow_two], exact mul_self_nonneg r}\n\nlemma norm_sqr_eq_sqr (r : \u211d) : \u2225r^2\u2225 = r^2 := abs_of_nonneg (sqr_nonneg r)\n\nlemma sqr_pos_iff_neq_zero (r : \u211d) : r^2 > 0 \u2194 r \u2260 0 :=\nbegin\n    constructor,\n\n    rw [awesome_mt],\n    simp,\n    intros k,\n    rw [k, pow_two, mul_zero],\n\n    rw [awesome_mt],\n    simp,\n    intros k,\n    rw [le_iff_eq_or_lt] at k,\n    cases k,\n    exact pow_eq_zero k,\n\n    have l := sqr_nonneg r,\n    dsimp [(\u2265)] at l,\n    rw [\u2190not_lt] at l,\n    exact absurd k l,\nend\n\nlemma norm_add_leq_of_norm_add_sqr_leq (x y : \u03b1) (h : \u2225x+y\u2225^2\u2264(\u2225x\u2225+\u2225y\u2225)^2) : \u2225x+y\u2225\u2264\u2225x\u2225+\u2225y\u2225 :=\nby {rw [\u2190sqrt_le (sqr_nonneg _) (sqr_nonneg _),\n            sqrt_sqr (ip_norm_nonneg),\n            sqrt_sqr (add_nonneg ip_norm_nonneg ip_norm_nonneg)] at h,\n        exact h}\n\ntheorem triangle_ineq (x y : \u03b1) : \u2225x+y\u2225\u2264\u2225x\u2225+\u2225y\u2225 :=\nbegin\n    apply norm_add_leq_of_norm_add_sqr_leq,\n    rw [sqr_norm, pow_two, left_distrib, right_distrib, right_distrib, \u2190pow_two,\n    \u2190pow_two, sqr_norm, sqr_norm, norm_sq_add, add_assoc, add_assoc, add_le_add_iff_left,\n    \u2190add_assoc, add_le_add_iff_right (norm_sq y), mul_comm \u2225y\u2225, \u2190mul_two, mul_comm],\n    apply mul_le_mul_of_nonneg_right,\n    apply le_trans (le_abs_self \u27eax \u2225 y\u27eb),\n    exact cauchy_schwarz x y,\n\n    rw [le_iff_eq_or_lt],\n    right,\n    exact two_pos,\nend\n\nlemma ip_dist_eq (x y : \u03b1) : dist x y = norm (x - y) := rfl\n\nlemma ip_dist_triangle (x y z : \u03b1) : dist x z \u2264 dist x y + dist y z :=\nbegin\n    repeat {rw [ip_dist_eq]},\n    have w : x - z = (x-y) + (y-z) := by simp,\n    rw [w],\n    exact triangle_ineq (x-y) (y-z),\nend\n\ndef ip_space_is_metric_space : metric_space \u03b1 :=\n{dist_self := ip_dist_self,\n eq_of_dist_eq_zero := ip_eq_of_dist_eq_zero,\n dist_comm := ip_dist_comm,\n dist_triangle := ip_dist_triangle}\n\ndef ip_space_is_normed_group : normed_group \u03b1 :=\n{dist_eq := ip_dist_eq,\n..ip_space_is_metric_space}\n\nlemma sqr_abs (r : \u211d) : r^2 = (abs r)^2 :=\nby rw [\u2190sqrt_sqr_eq_abs, sqr_sqrt (pow_two_nonneg r)]\n\nlemma ip_norm_smul (a : \u211d) (x : \u03b1) : \u2225a \u2022 x\u2225 = \u2225a\u2225*\u2225x\u2225:=\nbegin\n    dsimp [norm],\n    have h\u2081 := real.sqrt_sqr (abs_nonneg a),\n    have h\u2082 := pow_two_nonneg (abs a),\n    rw [\u2190h\u2081, \u2190real.sqrt_mul h\u2082],\n    have h\u2083 := mul_nonneg h\u2082 (norm_sq_nonneg x),\n    rw [real.sqrt_inj (norm_sq_nonneg (a\u2022x)) h\u2083],\n    simp only [norm_sq, mul_left, mul_right],\n    rw [\u2190mul_assoc, \u2190pow_two, sqr_abs],\nend\n\ndef ip_space_is_normed_space : normed_space \u211d \u03b1 :=\n{norm_smul := ip_norm_smul,\n .. ip_space_is_normed_group}\n\nlemma norm_neq_zero_iff_neq_zero {\u03b2 : Type*} [normed_space \u211d \u03b2] (x : \u03b2) : \u2225x\u2225 \u2260 (0 : \u211d) \u2194 x \u2260 (0 : \u03b2) :=\n\u27e8by {apply mt, exact (norm_eq_zero x).2}, by {apply mt, exact (norm_eq_zero x).1}\u27e9\n\nlemma norm_eq_iff_norm_sq_eq {\u03b2 : Type*} [normed_space \u211d \u03b2] {x y : \u03b2} : \u2225x\u2225=\u2225y\u2225 \u2194 \u2225x\u2225^2 = \u2225y\u2225^2 :=\n\u27e8by {apply congr_arg (\u03bb (r : \u211d), r^2)}, \n by {intros h, have w := congr_arg (\u03bb (r : \u211d), sqrt r) h, simp at w, exact w}\u27e9\n\nlemma norm_sqr_leq_iff_norm_leq {\u03b2 : Type*} [normed_space \u211d \u03b2] {x : \u03b2} {a : \u211d} {k : a \u2265 0}: \u2225x\u2225^2 \u2264 a^2 \u2194 \u2225x\u2225 \u2264 a :=\nbegin\n    have w := sqrt_le (mul_nonneg (norm_nonneg x) (norm_nonneg x)) (mul_nonneg k k),\n    rw [\u2190pow_two, \u2190pow_two, sqrt_sqr (norm_nonneg _), sqrt_sqr k] at w,\n    exact w.symm,\nend\n\n-- Scott: are these abandoned? Maybe move them closer to the point of use?\n\nlemma four_ne_zero : (4 : \u211d) \u2260 0 :=\nne.symm (ne_of_lt four_pos)\n\nlemma leq_of_add_nonneg {a b c : \u211d} {ha : a \u2265 0} {hb : b \u2265 0} {hc : c \u2265 0} : a = b + c \u2192 b \u2264 a :=\nby {intros h, linarith}\n\n", "meta": {"author": "MartinSkilleter", "repo": "real_ip_spaces", "sha": "1ad1e0456602038711cbb0de7aa92b88d6eff06f", "save_path": "github-repos/lean/MartinSkilleter-real_ip_spaces", "path": "github-repos/lean/MartinSkilleter-real_ip_spaces/real_ip_spaces-1ad1e0456602038711cbb0de7aa92b88d6eff06f/src/inner_product_spaces/real_ip/ip_normed_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7407141630896225}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris Van Doorn, Yury Kudryashov\n\n! This file was ported from Lean 3 source module measure_theory.measure.regular\n! leanprover-community/mathlib commit 57ac39bd365c2f80589a700f9fbb664d3a1a30c2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Constructions.BorelSpace\n\n/-!\n# Regular measures\n\nA measure is `outer_regular` if the measure of any measurable set `A` is the infimum of `\u03bc U` over\nall open sets `U` containing `A`.\n\nA measure is `regular` if it satisfies the following properties:\n* it is finite on compact sets;\n* it is outer regular;\n* it is inner regular for open sets with respect to compacts sets: the measure of any open set `U`\n  is the supremum of `\u03bc K` over all compact sets `K` contained in `U`.\n\nA measure is `weakly_regular` if it satisfies the following properties:\n* it is outer regular;\n* it is inner regular for open sets with respect to closed sets: the measure of any open set `U`\n  is the supremum of `\u03bc F` over all closed sets `F` contained in `U`.\n\nIn a Hausdorff topological space, regularity implies weak regularity. These three conditions are\nregistered as typeclasses for a measure `\u03bc`, and this implication is recorded as an instance.\n\nIn order to avoid code duplication, we also define a measure `\u03bc` to be `inner_regular` for sets\nsatisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set\n`U \u2208 {U | q U}` and a number `r < \u03bc U` there exists `F \u2286 U` such that `p F` and `r < \u03bc F`.\n\nWe prove that inner regularity for open sets with respect to compact sets or closed sets implies\ninner regularity for all measurable sets of finite measure (with respect to\ncompact sets or closed sets respectively), and register some corollaries for (weakly) regular\nmeasures.\n\nNote that a similar statement for measurable sets of infinite mass can fail. For a counterexample,\nconsider the group `\u211d \u00d7 \u211d` where the first factor has the discrete topology and the second one the\nusual topology. It is a locally compact Hausdorff topological group, with Haar measure equal to\nLebesgue measure on each vertical fiber. The set `\u211d \u00d7 {0}` has infinite measure (by outer\nregularity), but any compact set it contains has zero measure (as it is finite).\n\nSeveral authors require as a definition of regularity that all measurable sets are inner regular.\nWe have opted for the slightly weaker definition above as it holds for all Haar measures, it is\nenough for essentially all applications, and it is equivalent to the other definition when the\nmeasure is finite.\n\nThe interest of the notion of weak regularity is that it is enough for many applications, and it\nis automatically satisfied by any finite measure on a metric space.\n\n## Main definitions\n\n* `measure_theory.measure.outer_regular \u03bc`: a typeclass registering that a measure `\u03bc` on a\n  topological space is outer regular.\n* `measure_theory.measure.regular \u03bc`: a typeclass registering that a measure `\u03bc` on a topological\n  space is regular.\n* `measure_theory.measure.weakly_regular \u03bc`: a typeclass registering that a measure `\u03bc` on a\n  topological space is weakly regular.\n* `measure_theory.measure.inner_regular \u03bc p q`: a non-typeclass predicate saying that a measure `\u03bc`\n  is inner regular for sets satisfying `q` with respect to sets satisfying `p`.\n\n## Main results\n\n### Outer regular measures\n\n* `set.measure_eq_infi_is_open` asserts that, when `\u03bc` is outer regular, the measure of a\n  set is the infimum of the measure of open sets containing it.\n* `set.exists_is_open_lt_of_lt` asserts that, when `\u03bc` is outer regular, for every set `s`\n  and `r > \u03bc s` there exists an open superset `U \u2287 s` of measure less than `r`.\n* push forward of an outer regular measure is outer regular, and scalar multiplication of a regular\n  measure by a finite number is outer regular.\n\n### Weakly regular measures\n\n* `is_open.measure_eq_supr_is_closed` asserts that the measure of an open set is the supremum of\n  the measure of closed sets it contains.\n* `is_open.exists_lt_is_closed`: for an open set `U` and `r < \u03bc U`, there exists a closed `F \u2286 U`\n  of measure greater than `r`;\n* `measurable_set.measure_eq_supr_is_closed_of_ne_top` asserts that the measure of a measurable set\n  of finite measure is the supremum of the measure of closed sets it contains.\n*  `measurable_set.exists_lt_is_closed_of_ne_top` and `measurable_set.exists_is_closed_lt_add`:\n  a measurable set of finite measure can be approximated by a closed subset (stated as\n  `r < \u03bc F` and `\u03bc s < \u03bc F + \u03b5`, respectively).\n* `measure_theory.measure.weakly_regular.of_pseudo_emetric_space_of_is_finite_measure` is an\n  instance registering that a finite measure on a metric space is weakly regular (in fact, a pseudo\n  emetric space is enough);\n* `measure_theory.measure.weakly_regular.of_pseudo_emetric_second_countable_of_locally_finite`\n  is an instance registering that a locally finite measure on a second countable metric space (or\n  even a pseudo emetric space) is weakly regular.\n\n### Regular measures\n\n* `is_open.measure_eq_supr_is_compact` asserts that the measure of an open set is the supremum of\n  the measure of compact sets it contains.\n* `is_open.exists_lt_is_compact`: for an open set `U` and `r < \u03bc U`, there exists a compact `K \u2286 U`\n  of measure greater than `r`;\n* `measurable_set.measure_eq_supr_is_compact_of_ne_top` asserts that the measure of a measurable set\n  of finite measure is the supremum of the measure of compact sets it contains.\n*  `measurable_set.exists_lt_is_compact_of_ne_top` and `measurable_set.exists_is_compact_lt_add`:\n  a measurable set of finite measure can be approximated by a compact subset (stated as\n  `r < \u03bc K` and `\u03bc s < \u03bc K + \u03b5`, respectively).\n* `measure_theory.measure.regular.of_sigma_compact_space_of_is_locally_finite_measure` is an\n  instance registering that a locally finite measure on a `\u03c3`-compact metric space is regular (in\n  fact, an emetric space is enough).\n\n## Implementation notes\n\nThe main nontrivial statement is `measure_theory.measure.inner_regular.weakly_regular_of_finite`,\nexpressing that in a finite measure space, if every open set can be approximated from inside by\nclosed sets, then the measure is in fact weakly regular. To prove that we show that any measurable\nset can be approximated from inside by closed sets and from outside by open sets. This statement is\nproved by measurable induction, starting from open sets and checking that it is stable by taking\ncomplements (this is the point of this condition, being symmetrical between inside and outside) and\ncountable disjoint unions.\n\nOnce this statement is proved, one deduces results for `\u03c3`-finite measures from this statement, by\nrestricting them to finite measure sets (and proving that this restriction is weakly regular, using\nagain the same statement).\n\n## References\n\n[Halmos, Measure Theory, \u00a752][halmos1950measure]. Note that Halmos uses an unusual definition of\nBorel sets (for him, they are elements of the `\u03c3`-algebra generated by compact sets!), so his\nproofs or statements do not apply directly.\n\n[Billingsley, Convergence of Probability Measures][billingsley1999]\n-/\n\n\nopen Set Filter\n\nopen ENNReal Topology NNReal BigOperators\n\nnamespace MeasureTheory\n\nnamespace Measure\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb U) -/\n/-- We say that a measure `\u03bc` is *inner regular* with respect to predicates `p q : set \u03b1 \u2192 Prop`,\nif for every `U` such that `q U` and `r < \u03bc U`, there exists a subset `K \u2286 U` satisfying `p K`\nof measure greater than `r`.\n\nThis definition is used to prove some facts about regular and weakly regular measures without\nrepeating the proofs. -/\ndef InnerRegular {\u03b1} {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (p q : Set \u03b1 \u2192 Prop) :=\n  \u2200 \u2983U\u2984, q U \u2192 \u2200 r < \u03bc U, \u2203 (K : _)(_ : K \u2286 U), p K \u2227 r < \u03bc K\n#align measure_theory.measure.inner_regular MeasureTheory.Measure.InnerRegular\n\nnamespace InnerRegular\n\nvariable {\u03b1 : Type _} {m : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {p q : Set \u03b1 \u2192 Prop} {U : Set \u03b1}\n  {\u03b5 : \u211d\u22650\u221e}\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb U) -/\ntheorem measure_eq_sup\u1d62 (H : InnerRegular \u03bc p q) (hU : q U) :\n    \u03bc U = \u2a06 (K) (_ : K \u2286 U) (hK : p K), \u03bc K :=\n  by\n  refine'\n    le_antisymm (le_of_forall_lt fun r hr => _) (sup\u1d62\u2082_le fun K hK => sup\u1d62_le fun _ => \u03bc.mono hK)\n  simpa only [lt_sup\u1d62_iff, exists_prop] using H hU r hr\n#align measure_theory.measure.inner_regular.measure_eq_supr MeasureTheory.Measure.InnerRegular.measure_eq_sup\u1d62\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb U) -/\ntheorem exists_subset_lt_add (H : InnerRegular \u03bc p q) (h0 : p \u2205) (hU : q U) (h\u03bcU : \u03bc U \u2260 \u221e)\n    (h\u03b5 : \u03b5 \u2260 0) : \u2203 (K : _)(_ : K \u2286 U), p K \u2227 \u03bc U < \u03bc K + \u03b5 :=\n  by\n  cases' eq_or_ne (\u03bc U) 0 with h\u2080 h\u2080\n  \u00b7 refine' \u27e8\u2205, empty_subset _, h0, _\u27e9\n    rwa [measure_empty, h\u2080, zero_add, pos_iff_ne_zero]\n  \u00b7 rcases H hU _ (ENNReal.sub_lt_self h\u03bcU h\u2080 h\u03b5) with \u27e8K, hKU, hKc, hrK\u27e9\n    exact \u27e8K, hKU, hKc, ENNReal.lt_add_of_sub_lt_right (Or.inl h\u03bcU) hrK\u27e9\n#align measure_theory.measure.inner_regular.exists_subset_lt_add MeasureTheory.Measure.InnerRegular.exists_subset_lt_add\n\ntheorem map {\u03b1 \u03b2} [MeasurableSpace \u03b1] [MeasurableSpace \u03b2] {\u03bc : Measure \u03b1} {pa qa : Set \u03b1 \u2192 Prop}\n    (H : InnerRegular \u03bc pa qa) (f : \u03b1 \u2243 \u03b2) (hf : AeMeasurable f \u03bc) {pb qb : Set \u03b2 \u2192 Prop}\n    (hAB : \u2200 U, qb U \u2192 qa (f \u207b\u00b9' U)) (hAB' : \u2200 K, pa K \u2192 pb (f '' K))\n    (hB\u2081 : \u2200 K, pb K \u2192 MeasurableSet K) (hB\u2082 : \u2200 U, qb U \u2192 MeasurableSet U) :\n    InnerRegular (map f \u03bc) pb qb := by\n  intro U hU r hr\n  rw [map_apply_of_ae_measurable hf (hB\u2082 _ hU)] at hr\n  rcases H (hAB U hU) r hr with \u27e8K, hKU, hKc, hK\u27e9\n  refine' \u27e8f '' K, image_subset_iff.2 hKU, hAB' _ hKc, _\u27e9\n  rwa [map_apply_of_ae_measurable hf (hB\u2081 _ <| hAB' _ hKc), f.preimage_image]\n#align measure_theory.measure.inner_regular.map MeasureTheory.Measure.InnerRegular.map\n\ntheorem smul (H : InnerRegular \u03bc p q) (c : \u211d\u22650\u221e) : InnerRegular (c \u2022 \u03bc) p q :=\n  by\n  intro U hU r hr\n  rw [smul_apply, H.measure_eq_supr hU, smul_eq_mul] at hr\n  simpa only [ENNReal.mul_sup\u1d62, lt_sup\u1d62_iff, exists_prop] using hr\n#align measure_theory.measure.inner_regular.smul MeasureTheory.Measure.InnerRegular.smul\n\ntheorem trans {q' : Set \u03b1 \u2192 Prop} (H : InnerRegular \u03bc p q) (H' : InnerRegular \u03bc q q') :\n    InnerRegular \u03bc p q' := by\n  intro U hU r hr\n  rcases H' hU r hr with \u27e8F, hFU, hqF, hF\u27e9; rcases H hqF _ hF with \u27e8K, hKF, hpK, hrK\u27e9\n  exact \u27e8K, hKF.trans hFU, hpK, hrK\u27e9\n#align measure_theory.measure.inner_regular.trans MeasureTheory.Measure.InnerRegular.trans\n\nend InnerRegular\n\nvariable {\u03b1 \u03b2 : Type _} [MeasurableSpace \u03b1] [TopologicalSpace \u03b1] {\u03bc : Measure \u03b1}\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (U \u00abexpr \u2287 \u00bb A) -/\n/-- A measure `\u03bc` is outer regular if `\u03bc(A) = inf {\u03bc(U) | A \u2286 U open}` for a measurable set `A`.\n\nThis definition implies the same equality for any (not necessarily measurable) set, see\n`set.measure_eq_infi_is_open`. -/\n@[protect_proj]\nclass OuterRegular (\u03bc : Measure \u03b1) : Prop where\n  OuterRegular :\n    \u2200 \u2983A : Set \u03b1\u2984, MeasurableSet A \u2192 \u2200 r > \u03bc A, \u2203 (U : _)(_ : U \u2287 A), IsOpen U \u2227 \u03bc U < r\n#align measure_theory.measure.outer_regular MeasureTheory.Measure.OuterRegular\n\n/-- A measure `\u03bc` is regular if\n  - it is finite on all compact sets;\n  - it is outer regular: `\u03bc(A) = inf {\u03bc(U) | A \u2286 U open}` for `A` measurable;\n  - it is inner regular for open sets, using compact sets:\n    `\u03bc(U) = sup {\u03bc(K) | K \u2286 U compact}` for `U` open. -/\n@[protect_proj]\nclass Regular (\u03bc : Measure \u03b1) extends IsFiniteMeasureOnCompacts \u03bc, OuterRegular \u03bc : Prop where\n  InnerRegular : InnerRegular \u03bc IsCompact IsOpen\n#align measure_theory.measure.regular MeasureTheory.Measure.Regular\n\n/-- A measure `\u03bc` is weakly regular if\n  - it is outer regular: `\u03bc(A) = inf {\u03bc(U) | A \u2286 U open}` for `A` measurable;\n  - it is inner regular for open sets, using closed sets:\n    `\u03bc(U) = sup {\u03bc(F) | F \u2286 U compact}` for `U` open. -/\n@[protect_proj]\nclass WeaklyRegular (\u03bc : Measure \u03b1) extends OuterRegular \u03bc : Prop where\n  InnerRegular : InnerRegular \u03bc IsClosed IsOpen\n#align measure_theory.measure.weakly_regular MeasureTheory.Measure.WeaklyRegular\n\n-- see Note [lower instance priority]\n/-- A regular measure is weakly regular. -/\ninstance (priority := 100) Regular.weaklyRegular [T2Space \u03b1] [Regular \u03bc] : WeaklyRegular \u03bc\n    where InnerRegular U hU r hr :=\n    let \u27e8K, hKU, hcK, hK\u27e9 := Regular.innerRegular hU r hr\n    \u27e8K, hKU, hcK.IsClosed, hK\u27e9\n#align measure_theory.measure.regular.weakly_regular MeasureTheory.Measure.Regular.weaklyRegular\n\nnamespace OuterRegular\n\ninstance zero : OuterRegular (0 : Measure \u03b1) :=\n  \u27e8fun A hA r hr => \u27e8univ, subset_univ A, isOpen_univ, hr\u27e9\u27e9\n#align measure_theory.measure.outer_regular.zero MeasureTheory.Measure.OuterRegular.zero\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (U \u00abexpr \u2287 \u00bb A) -/\n/-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with\nmeasure less than `r`. -/\ntheorem Set.exists_isOpen_lt_of_lt [OuterRegular \u03bc] (A : Set \u03b1) (r : \u211d\u22650\u221e) (hr : \u03bc A < r) :\n    \u2203 (U : _)(_ : U \u2287 A), IsOpen U \u2227 \u03bc U < r :=\n  by\n  rcases outer_regular.outer_regular (measurable_set_to_measurable \u03bc A) r\n      (by rwa [measure_to_measurable]) with\n    \u27e8U, hAU, hUo, hU\u27e9\n  exact \u27e8U, (subset_to_measurable _ _).trans hAU, hUo, hU\u27e9\n#align set.exists_is_open_lt_of_lt Set.exists_isOpen_lt_of_lt\n\n/-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets\ncontaining it. -/\ntheorem Set.measure_eq_inf\u1d62_isOpen (A : Set \u03b1) (\u03bc : Measure \u03b1) [OuterRegular \u03bc] :\n    \u03bc A = \u2a05 (U : Set \u03b1) (h : A \u2286 U) (h2 : IsOpen U), \u03bc U :=\n  by\n  refine' le_antisymm (le_inf\u1d62\u2082 fun s hs => le_inf\u1d62 fun h2s => \u03bc.mono hs) _\n  refine' le_of_forall_lt' fun r hr => _\n  simpa only [inf\u1d62_lt_iff, exists_prop] using A.exists_is_open_lt_of_lt r hr\n#align set.measure_eq_infi_is_open Set.measure_eq_inf\u1d62_isOpen\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (U \u00abexpr \u2287 \u00bb A) -/\ntheorem Set.exists_isOpen_lt_add [OuterRegular \u03bc] (A : Set \u03b1) (hA : \u03bc A \u2260 \u221e) {\u03b5 : \u211d\u22650\u221e}\n    (h\u03b5 : \u03b5 \u2260 0) : \u2203 (U : _)(_ : U \u2287 A), IsOpen U \u2227 \u03bc U < \u03bc A + \u03b5 :=\n  A.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hA h\u03b5)\n#align set.exists_is_open_lt_add Set.exists_isOpen_lt_add\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (U \u00abexpr \u2287 \u00bb A) -/\ntheorem Set.exists_isOpen_le_add (A : Set \u03b1) (\u03bc : Measure \u03b1) [OuterRegular \u03bc] {\u03b5 : \u211d\u22650\u221e}\n    (h\u03b5 : \u03b5 \u2260 0) : \u2203 (U : _)(_ : U \u2287 A), IsOpen U \u2227 \u03bc U \u2264 \u03bc A + \u03b5 :=\n  by\n  rcases eq_or_ne (\u03bc A) \u221e with (H | H)\n  \u00b7 exact \u27e8univ, subset_univ _, isOpen_univ, by simp only [H, _root_.top_add, le_top]\u27e9\n  \u00b7 rcases A.exists_is_open_lt_add H h\u03b5 with \u27e8U, AU, U_open, hU\u27e9\n    exact \u27e8U, AU, U_open, hU.le\u27e9\n#align set.exists_is_open_le_add Set.exists_isOpen_le_add\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (U \u00abexpr \u2287 \u00bb A) -/\ntheorem MeasurableSet.exists_isOpen_diff_lt [OuterRegular \u03bc] {A : Set \u03b1} (hA : MeasurableSet A)\n    (hA' : \u03bc A \u2260 \u221e) {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) :\n    \u2203 (U : _)(_ : U \u2287 A), IsOpen U \u2227 \u03bc U < \u221e \u2227 \u03bc (U \\ A) < \u03b5 :=\n  by\n  rcases A.exists_is_open_lt_add hA' h\u03b5 with \u27e8U, hAU, hUo, hU\u27e9\n  use U, hAU, hUo, hU.trans_le le_top\n  exact measure_diff_lt_of_lt_add hA hAU hA' hU\n#align measurable_set.exists_is_open_diff_lt MeasurableSet.exists_isOpen_diff_lt\n\nprotected theorem map [OpensMeasurableSpace \u03b1] [MeasurableSpace \u03b2] [TopologicalSpace \u03b2]\n    [BorelSpace \u03b2] (f : \u03b1 \u2243\u209c \u03b2) (\u03bc : Measure \u03b1) [OuterRegular \u03bc] : (Measure.map f \u03bc).OuterRegular :=\n  by\n  refine' \u27e8fun A hA r hr => _\u27e9\n  rw [map_apply f.measurable hA, \u2190 f.image_symm] at hr\n  rcases Set.exists_isOpen_lt_of_lt _ r hr with \u27e8U, hAU, hUo, hU\u27e9\n  have : IsOpen (f.symm \u207b\u00b9' U) := hUo.preimage f.symm.continuous\n  refine' \u27e8f.symm \u207b\u00b9' U, image_subset_iff.1 hAU, this, _\u27e9\n  rwa [map_apply f.measurable this.measurable_set, f.preimage_symm, f.preimage_image]\n#align measure_theory.measure.outer_regular.map MeasureTheory.Measure.OuterRegular.map\n\nprotected theorem smul (\u03bc : Measure \u03b1) [OuterRegular \u03bc] {x : \u211d\u22650\u221e} (hx : x \u2260 \u221e) :\n    (x \u2022 \u03bc).OuterRegular := by\n  rcases eq_or_ne x 0 with (rfl | h0)\n  \u00b7 rw [zero_smul]\n    exact outer_regular.zero\n  \u00b7 refine' \u27e8fun A hA r hr => _\u27e9\n    rw [smul_apply, A.measure_eq_infi_is_open, smul_eq_mul] at hr\n    simpa only [ENNReal.mul_inf\u1d62_of_ne h0 hx, gt_iff_lt, inf\u1d62_lt_iff, exists_prop] using hr\n#align measure_theory.measure.outer_regular.smul MeasureTheory.Measure.OuterRegular.smul\n\nend OuterRegular\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (U \u00abexpr \u2287 \u00bb A n) -/\n/-- If a measure `\u03bc` admits finite spanning open sets such that the restriction of `\u03bc` to each set\nis outer regular, then the original measure is outer regular as well. -/\nprotected theorem FiniteSpanningSetsIn.outerRegular [OpensMeasurableSpace \u03b1] {\u03bc : Measure \u03b1}\n    (s : \u03bc.FiniteSpanningSetsIn { U | IsOpen U \u2227 OuterRegular (\u03bc.restrict U) }) : OuterRegular \u03bc :=\n  by\n  refine' \u27e8fun A hA r hr => _\u27e9\n  have hm : \u2200 n, MeasurableSet (s.set n) := fun n => (s.set_mem n).1.MeasurableSet\n  haveI : \u2200 n, outer_regular (\u03bc.restrict (s.set n)) := fun n => (s.set_mem n).2\n  -- Note that `A = \u22c3 n, A \u2229 disjointed s n`. We replace `A` with this sequence.\n  obtain \u27e8A, hAm, hAs, hAd, rfl\u27e9 :\n    \u2203 A' : \u2115 \u2192 Set \u03b1,\n      (\u2200 n, MeasurableSet (A' n)) \u2227\n        (\u2200 n, A' n \u2286 s.set n) \u2227 Pairwise (Disjoint on A') \u2227 A = \u22c3 n, A' n :=\n    by\n    refine'\n      \u27e8fun n => A \u2229 disjointed s.set n, fun n => hA.inter (MeasurableSet.disjointed hm _), fun n =>\n        (inter_subset_right _ _).trans (disjointed_subset _ _),\n        (disjoint_disjointed s.set).mono fun k l hkl => hkl.mono inf_le_right inf_le_right, _\u27e9\n    rw [\u2190 inter_Union, union\u1d62_disjointed, s.spanning, inter_univ]\n  rcases ENNReal.exists_pos_sum_of_countable' (tsub_pos_iff_lt.2 hr).ne' \u2115 with \u27e8\u03b4, \u03b40, h\u03b4\u03b5\u27e9\n  rw [lt_tsub_iff_right, add_comm] at h\u03b4\u03b5\n  have : \u2200 n, \u2203 (U : _)(_ : U \u2287 A n), IsOpen U \u2227 \u03bc U < \u03bc (A n) + \u03b4 n :=\n    by\n    intro n\n    have H\u2081 : \u2200 t, \u03bc.restrict (s.set n) t = \u03bc (t \u2229 s.set n) := fun t => restrict_apply' (hm n)\n    have Ht : \u03bc.restrict (s.set n) (A n) \u2260 \u22a4 := by\n      rw [H\u2081]\n      exact ((measure_mono <| inter_subset_right _ _).trans_lt (s.finite n)).Ne\n    rcases(A n).exists_isOpen_lt_add Ht (\u03b40 n).ne' with \u27e8U, hAU, hUo, hU\u27e9\n    rw [H\u2081, H\u2081, inter_eq_self_of_subset_left (hAs _)] at hU\n    exact \u27e8U \u2229 s.set n, subset_inter hAU (hAs _), hUo.inter (s.set_mem n).1, hU\u27e9\n  choose U hAU hUo hU\n  refine' \u27e8\u22c3 n, U n, Union_mono hAU, isOpen_union\u1d62 hUo, _\u27e9\n  calc\n    \u03bc (\u22c3 n, U n) \u2264 \u2211' n, \u03bc (U n) := measure_Union_le _\n    _ \u2264 \u2211' n, \u03bc (A n) + \u03b4 n := (ENNReal.tsum_le_tsum fun n => (hU n).le)\n    _ = (\u2211' n, \u03bc (A n)) + \u2211' n, \u03b4 n := ENNReal.tsum_add\n    _ = \u03bc (\u22c3 n, A n) + \u2211' n, \u03b4 n := (congr_arg\u2082 (\u00b7 + \u00b7) (measure_Union hAd hAm).symm rfl)\n    _ < r := h\u03b4\u03b5\n    \n#align measure_theory.measure.finite_spanning_sets_in.outer_regular MeasureTheory.Measure.FiniteSpanningSetsIn.outerRegular\n\nnamespace InnerRegular\n\nvariable {p q : Set \u03b1 \u2192 Prop} {U s : Set \u03b1} {\u03b5 r : \u211d\u22650\u221e}\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (\u03b5 \u00abexpr \u2260 \u00bb 0) -/\n/-- If a measure is inner regular (using closed or compact sets), then every measurable set of\nfinite measure can by approximated by a (closed or compact) subset. -/\ntheorem measurableSetOfOpen [OuterRegular \u03bc] (H : InnerRegular \u03bc p IsOpen) (h0 : p \u2205)\n    (hd : \u2200 \u2983s U\u2984, p s \u2192 IsOpen U \u2192 p (s \\ U)) :\n    InnerRegular \u03bc p fun s => MeasurableSet s \u2227 \u03bc s \u2260 \u221e :=\n  by\n  rintro s \u27e8hs, h\u03bcs\u27e9 r hr\n  obtain \u27e8\u03b5, h\u03b5, h\u03b5s, rfl\u27e9 : \u2203 (\u03b5 : _)(_ : \u03b5 \u2260 0), \u03b5 + \u03b5 \u2264 \u03bc s \u2227 r = \u03bc s - (\u03b5 + \u03b5) :=\n    by\n    use (\u03bc s - r) / 2\n    simp [*, hr.le, ENNReal.add_halves, ENNReal.sub_sub_cancel, le_add_right]\n  rcases hs.exists_is_open_diff_lt h\u03bcs h\u03b5 with \u27e8U, hsU, hUo, hUt, h\u03bcU\u27e9\n  rcases(U \\ s).exists_isOpen_lt_of_lt _ h\u03bcU with \u27e8U', hsU', hU'o, h\u03bcU'\u27e9\n  replace hsU' := diff_subset_comm.1 hsU'\n  rcases H.exists_subset_lt_add h0 hUo hUt.ne h\u03b5 with \u27e8K, hKU, hKc, hKr\u27e9\n  refine' \u27e8K \\ U', fun x hx => hsU' \u27e8hKU hx.1, hx.2\u27e9, hd hKc hU'o, ENNReal.sub_lt_of_lt_add h\u03b5s _\u27e9\n  calc\n    \u03bc s \u2264 \u03bc U := \u03bc.mono hsU\n    _ < \u03bc K + \u03b5 := hKr\n    _ \u2264 \u03bc (K \\ U') + \u03bc U' + \u03b5 := (add_le_add_right (tsub_le_iff_right.1 le_measure_diff) _)\n    _ \u2264 \u03bc (K \\ U') + \u03b5 + \u03b5 := by\n      mono*\n      exacts[h\u03bcU'.le, le_rfl]\n    _ = \u03bc (K \\ U') + (\u03b5 + \u03b5) := add_assoc _ _ _\n    \n#align measure_theory.measure.inner_regular.measurable_set_of_open MeasureTheory.Measure.InnerRegular.measurableSetOfOpen\n\nopen Finset\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (\u03b5 \u00abexpr \u2260 \u00bb 0) -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (F \u00abexpr \u2286 \u00bb s) -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (U \u00abexpr \u2287 \u00bb s) -/\n/-- In a finite measure space, assume that any open set can be approximated from inside by closed\nsets. Then the measure is weakly regular. -/\ntheorem weaklyRegularOfFinite [BorelSpace \u03b1] (\u03bc : Measure \u03b1) [IsFiniteMeasure \u03bc]\n    (H : InnerRegular \u03bc IsClosed IsOpen) : WeaklyRegular \u03bc :=\n  by\n  have hfin : \u2200 {s}, \u03bc s \u2260 \u22a4 := measure_ne_top \u03bc\n  suffices\n    \u2200 s,\n      MeasurableSet s \u2192\n        \u2200 (\u03b5) (_ : \u03b5 \u2260 0),\n          \u2203 (F : _)(_ : F \u2286 s)(U : _)(_ : U \u2287 s),\n            IsClosed F \u2227 IsOpen U \u2227 \u03bc s \u2264 \u03bc F + \u03b5 \u2227 \u03bc U \u2264 \u03bc s + \u03b5\n    by\n    refine'\n      { OuterRegular := fun s hs r hr => _\n        InnerRegular := H }\n    rcases exists_between hr with \u27e8r', hsr', hr'r\u27e9\n    rcases this s hs _ (tsub_pos_iff_lt.2 hsr').ne' with \u27e8-, -, U, hsU, -, hUo, -, H\u27e9\n    refine' \u27e8U, hsU, hUo, _\u27e9\n    rw [add_tsub_cancel_of_le hsr'.le] at H\n    exact H.trans_lt hr'r\n  refine' MeasurableSet.induction_on_open _ _ _\n  /- The proof is by measurable induction: we should check that the property is true for the empty\n    set, for open sets, and is stable by taking the complement and by taking countable disjoint\n    unions. The point of the property we are proving is that it is stable by taking complements\n    (exchanging the roles of closed and open sets and thanks to the finiteness of the measure). -/\n  -- check for open set\n  \u00b7 intro U hU \u03b5 h\u03b5\n    rcases H.exists_subset_lt_add isClosed_empty hU hfin h\u03b5 with \u27e8F, hsF, hFc, hF\u27e9\n    exact \u27e8F, hsF, U, subset.rfl, hFc, hU, hF.le, le_self_add\u27e9\n  -- check for complements\n  \u00b7 rintro s hs H \u03b5 h\u03b5\n    rcases H \u03b5 h\u03b5 with \u27e8F, hFs, U, hsU, hFc, hUo, hF, hU\u27e9\n    refine'\n      \u27e8U\u1d9c, compl_subset_compl.2 hsU, F\u1d9c, compl_subset_compl.2 hFs, hUo.is_closed_compl,\n        hFc.is_open_compl, _\u27e9\n    simp only [measure_compl_le_add_iff, *, hUo.measurable_set, hFc.measurable_set, true_and_iff]\n  -- check for disjoint unions\n  \u00b7 intro s hsd hsm H \u03b5 \u03b50\n    have \u03b50' : \u03b5 / 2 \u2260 0 := (ENNReal.half_pos \u03b50).ne'\n    rcases ENNReal.exists_pos_sum_of_countable' \u03b50' \u2115 with \u27e8\u03b4, \u03b40, h\u03b4\u03b5\u27e9\n    choose F hFs U hsU hFc hUo hF hU using fun n => H n (\u03b4 n) (\u03b40 n).ne'\n    -- the approximating closed set is constructed by considering finitely many sets `s i`, which\n    -- cover all the measure up to `\u03b5/2`, approximating each of these by a closed set `F i`, and\n    -- taking the union of these (finitely many) `F i`.\n    have : tendsto (fun t => (\u2211 k in t, \u03bc (s k)) + \u03b5 / 2) at_top (\ud835\udcdd <| \u03bc (\u22c3 n, s n) + \u03b5 / 2) :=\n      by\n      rw [measure_Union hsd hsm]\n      exact tendsto.add ennreal.summable.has_sum tendsto_const_nhds\n    rcases(this.eventually <| lt_mem_nhds <| ENNReal.lt_add_right hfin \u03b50').exists with \u27e8t, ht\u27e9\n    -- the approximating open set is constructed by taking for each `s n` an approximating open set\n    -- `U n` with measure at most `\u03bc (s n) + \u03b4 n` for a summable `\u03b4`, and taking the union of these.\n    refine'\n      \u27e8\u22c3 k \u2208 t, F k, Union_mono fun k => Union_subset fun _ => hFs _, \u22c3 n, U n, Union_mono hsU,\n        isClosed_bunion\u1d62 t.finite_to_set fun k _ => hFc k, isOpen_union\u1d62 hUo, ht.le.trans _, _\u27e9\n    \u00b7 calc\n        (\u2211 k in t, \u03bc (s k)) + \u03b5 / 2 \u2264 ((\u2211 k in t, \u03bc (F k)) + \u2211 k in t, \u03b4 k) + \u03b5 / 2 :=\n          by\n          rw [\u2190 sum_add_distrib]\n          exact add_le_add_right (sum_le_sum fun k hk => hF k) _\n        _ \u2264 (\u2211 k in t, \u03bc (F k)) + \u03b5 / 2 + \u03b5 / 2 :=\n          (add_le_add_right (add_le_add_left ((ENNReal.sum_le_tsum _).trans h\u03b4\u03b5.le) _) _)\n        _ = \u03bc (\u22c3 k \u2208 t, F k) + \u03b5 := _\n        \n      rw [measure_bUnion_finset, add_assoc, ENNReal.add_halves]\n      exacts[fun k _ n _ hkn => (hsd hkn).mono (hFs k) (hFs n), fun k hk => (hFc k).MeasurableSet]\n    \u00b7\n      calc\n        \u03bc (\u22c3 n, U n) \u2264 \u2211' n, \u03bc (U n) := measure_Union_le _\n        _ \u2264 \u2211' n, \u03bc (s n) + \u03b4 n := (ENNReal.tsum_le_tsum hU)\n        _ = \u03bc (\u22c3 n, s n) + \u2211' n, \u03b4 n := by rw [measure_Union hsd hsm, ENNReal.tsum_add]\n        _ \u2264 \u03bc (\u22c3 n, s n) + \u03b5 := add_le_add_left (h\u03b4\u03b5.le.trans ENNReal.half_le_self) _\n        \n#align measure_theory.measure.inner_regular.weakly_regular_of_finite MeasureTheory.Measure.InnerRegular.weaklyRegularOfFinite\n\n/-- In a metric space (or even a pseudo emetric space), an open set can be approximated from inside\nby closed sets. -/\ntheorem ofPseudoEmetricSpace {X : Type _} [PseudoEMetricSpace X] [MeasurableSpace X]\n    (\u03bc : Measure X) : InnerRegular \u03bc IsClosed IsOpen :=\n  by\n  intro U hU r hr\n  rcases hU.exists_Union_is_closed with \u27e8F, F_closed, -, rfl, F_mono\u27e9\n  rw [measure_Union_eq_supr F_mono.directed_le] at hr\n  rcases lt_sup\u1d62_iff.1 hr with \u27e8n, hn\u27e9\n  exact \u27e8F n, subset_Union _ _, F_closed n, hn\u27e9\n#align measure_theory.measure.inner_regular.of_pseudo_emetric_space MeasureTheory.Measure.InnerRegular.ofPseudoEmetricSpace\n\n/-- In a `\u03c3`-compact space, any closed set can be approximated by a compact subset. -/\ntheorem isCompactIsClosed {X : Type _} [TopologicalSpace X] [SigmaCompactSpace X]\n    [MeasurableSpace X] (\u03bc : Measure X) : InnerRegular \u03bc IsCompact IsClosed :=\n  by\n  intro F hF r hr\n  set B : \u2115 \u2192 Set X := compactCovering X\n  have hBc : \u2200 n, IsCompact (F \u2229 B n) := fun n => (isCompact_compactCovering X n).inter_left hF\n  have hBU : (\u22c3 n, F \u2229 B n) = F := by rw [\u2190 inter_Union, union\u1d62_compactCovering, Set.inter_univ]\n  have : \u03bc F = \u2a06 n, \u03bc (F \u2229 B n) :=\n    by\n    rw [\u2190 measure_Union_eq_supr, hBU]\n    exact Monotone.directed_le fun m n h => inter_subset_inter_right _ (compactCovering_subset _ h)\n  rw [this] at hr\n  rcases lt_sup\u1d62_iff.1 hr with \u27e8n, hn\u27e9\n  exact \u27e8_, inter_subset_left _ _, hBc n, hn\u27e9\n#align measure_theory.measure.inner_regular.is_compact_is_closed MeasureTheory.Measure.InnerRegular.isCompactIsClosed\n\nend InnerRegular\n\nnamespace Regular\n\ninstance zero : Regular (0 : Measure \u03b1) :=\n  \u27e8fun U hU r hr => \u27e8\u2205, empty_subset _, isCompact_empty, hr\u27e9\u27e9\n#align measure_theory.measure.regular.zero MeasureTheory.Measure.Regular.zero\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb U) -/\n/-- If `\u03bc` is a regular measure, then any open set can be approximated by a compact subset. -/\ntheorem IsOpen.exists_lt_isCompact [Regular \u03bc] \u2983U : Set \u03b1\u2984 (hU : IsOpen U) {r : \u211d\u22650\u221e}\n    (hr : r < \u03bc U) : \u2203 (K : _)(_ : K \u2286 U), IsCompact K \u2227 r < \u03bc K :=\n  Regular.innerRegular hU r hr\n#align is_open.exists_lt_is_compact IsOpen.exists_lt_isCompact\n\n/-- The measure of an open set is the supremum of the measures of compact sets it contains. -/\ntheorem IsOpen.measure_eq_sup\u1d62_isCompact \u2983U : Set \u03b1\u2984 (hU : IsOpen U) (\u03bc : Measure \u03b1) [Regular \u03bc] :\n    \u03bc U = \u2a06 (K : Set \u03b1) (h : K \u2286 U) (h2 : IsCompact K), \u03bc K :=\n  Regular.innerRegular.measure_eq_sup\u1d62 hU\n#align is_open.measure_eq_supr_is_compact IsOpen.measure_eq_sup\u1d62_isCompact\n\ntheorem exists_compact_not_null [Regular \u03bc] : (\u2203 K, IsCompact K \u2227 \u03bc K \u2260 0) \u2194 \u03bc \u2260 0 := by\n  simp_rw [Ne.def, \u2190 measure_univ_eq_zero, is_open_univ.measure_eq_supr_is_compact,\n    ENNReal.sup\u1d62_eq_zero, not_forall, exists_prop, subset_univ, true_and_iff]\n#align measure_theory.measure.regular.exists_compact_not_null MeasureTheory.Measure.Regular.exists_compact_not_null\n\n/-- If `\u03bc` is a regular measure, then any measurable set of finite measure can be approximated by a\ncompact subset. See also `measurable_set.exists_is_compact_lt_add` and\n`measurable_set.exists_lt_is_compact_of_ne_top`. -/\ntheorem innerRegularMeasurable [Regular \u03bc] :\n    InnerRegular \u03bc IsCompact fun s => MeasurableSet s \u2227 \u03bc s \u2260 \u221e :=\n  Regular.innerRegular.measurableSetOfOpen isCompact_empty fun _ _ => IsCompact.diff\n#align measure_theory.measure.regular.inner_regular_measurable MeasureTheory.Measure.Regular.innerRegularMeasurable\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb A) -/\n/-- If `\u03bc` is a regular measure, then any measurable set of finite measure can be approximated by a\ncompact subset. See also `measurable_set.exists_lt_is_compact_of_ne_top`. -/\ntheorem MeasurableSet.exists_isCompact_lt_add [Regular \u03bc] \u2983A : Set \u03b1\u2984 (hA : MeasurableSet A)\n    (h'A : \u03bc A \u2260 \u221e) {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) : \u2203 (K : _)(_ : K \u2286 A), IsCompact K \u2227 \u03bc A < \u03bc K + \u03b5 :=\n  Regular.innerRegularMeasurable.exists_subset_lt_add isCompact_empty \u27e8hA, h'A\u27e9 h'A h\u03b5\n#align measurable_set.exists_is_compact_lt_add MeasurableSet.exists_isCompact_lt_add\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb A) -/\n/-- If `\u03bc` is a regular measure, then any measurable set of finite measure can be approximated by a\ncompact subset. See also `measurable_set.exists_is_compact_lt_add` and\n`measurable_set.exists_lt_is_compact_of_ne_top`. -/\ntheorem MeasurableSet.exists_isCompact_diff_lt [OpensMeasurableSpace \u03b1] [T2Space \u03b1] [Regular \u03bc]\n    \u2983A : Set \u03b1\u2984 (hA : MeasurableSet A) (h'A : \u03bc A \u2260 \u221e) {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) :\n    \u2203 (K : _)(_ : K \u2286 A), IsCompact K \u2227 \u03bc (A \\ K) < \u03b5 :=\n  by\n  rcases hA.exists_is_compact_lt_add h'A h\u03b5 with \u27e8K, hKA, hKc, hK\u27e9\n  exact\n    \u27e8K, hKA, hKc,\n      measure_diff_lt_of_lt_add hKc.measurable_set hKA (ne_top_of_le_ne_top h'A <| measure_mono hKA)\n        hK\u27e9\n#align measurable_set.exists_is_compact_diff_lt MeasurableSet.exists_isCompact_diff_lt\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb A) -/\n/-- If `\u03bc` is a regular measure, then any measurable set of finite measure can be approximated by a\ncompact subset. See also `measurable_set.exists_is_compact_lt_add`. -/\ntheorem MeasurableSet.exists_lt_isCompact_of_ne_top [Regular \u03bc] \u2983A : Set \u03b1\u2984 (hA : MeasurableSet A)\n    (h'A : \u03bc A \u2260 \u221e) {r : \u211d\u22650\u221e} (hr : r < \u03bc A) : \u2203 (K : _)(_ : K \u2286 A), IsCompact K \u2227 r < \u03bc K :=\n  Regular.innerRegularMeasurable \u27e8hA, h'A\u27e9 _ hr\n#align measurable_set.exists_lt_is_compact_of_ne_top MeasurableSet.exists_lt_isCompact_of_ne_top\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb A) -/\n/-- Given a regular measure, any measurable set of finite mass can be approximated from\ninside by compact sets. -/\ntheorem MeasurableSet.measure_eq_sup\u1d62_isCompact_of_ne_top [Regular \u03bc] \u2983A : Set \u03b1\u2984\n    (hA : MeasurableSet A) (h'A : \u03bc A \u2260 \u221e) : \u03bc A = \u2a06 (K) (_ : K \u2286 A) (h : IsCompact K), \u03bc K :=\n  Regular.innerRegularMeasurable.measure_eq_sup\u1d62 \u27e8hA, h'A\u27e9\n#align measurable_set.measure_eq_supr_is_compact_of_ne_top MeasurableSet.measure_eq_sup\u1d62_isCompact_of_ne_top\n\nprotected theorem map [OpensMeasurableSpace \u03b1] [MeasurableSpace \u03b2] [TopologicalSpace \u03b2] [T2Space \u03b2]\n    [BorelSpace \u03b2] [Regular \u03bc] (f : \u03b1 \u2243\u209c \u03b2) : (Measure.map f \u03bc).regular :=\n  by\n  haveI := outer_regular.map f \u03bc\n  haveI := IsFiniteMeasureOnCompacts.map \u03bc f\n  exact\n    \u27e8regular.inner_regular.map f.to_equiv f.measurable.ae_measurable\n        (fun U hU => hU.Preimage f.continuous) (fun K hK => hK.image f.continuous)\n        (fun K hK => hK.MeasurableSet) fun U hU => hU.MeasurableSet\u27e9\n#align measure_theory.measure.regular.map MeasureTheory.Measure.Regular.map\n\nprotected theorem smul [Regular \u03bc] {x : \u211d\u22650\u221e} (hx : x \u2260 \u221e) : (x \u2022 \u03bc).regular :=\n  by\n  haveI := outer_regular.smul \u03bc hx\n  haveI := is_finite_measure_on_compacts.smul \u03bc hx\n  exact \u27e8regular.inner_regular.smul x\u27e9\n#align measure_theory.measure.regular.smul MeasureTheory.Measure.Regular.smul\n\n-- see Note [lower instance priority]\n/-- A regular measure in a \u03c3-compact space is \u03c3-finite. -/\ninstance (priority := 100) sigmaFinite [SigmaCompactSpace \u03b1] [Regular \u03bc] : SigmaFinite \u03bc :=\n  \u27e8\u27e8{   Set := compactCovering \u03b1\n        set_mem := fun n => trivial\n        Finite := fun n => (isCompact_compactCovering \u03b1 n).measure_lt_top\n        spanning := union\u1d62_compactCovering \u03b1 }\u27e9\u27e9\n#align measure_theory.measure.regular.sigma_finite MeasureTheory.Measure.Regular.sigmaFinite\n\nend Regular\n\nnamespace WeaklyRegular\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (F \u00abexpr \u2286 \u00bb U) -/\n/-- If `\u03bc` is a weakly regular measure, then any open set can be approximated by a closed subset. -/\ntheorem IsOpen.exists_lt_isClosed [WeaklyRegular \u03bc] \u2983U : Set \u03b1\u2984 (hU : IsOpen U) {r : \u211d\u22650\u221e}\n    (hr : r < \u03bc U) : \u2203 (F : _)(_ : F \u2286 U), IsClosed F \u2227 r < \u03bc F :=\n  WeaklyRegular.innerRegular hU r hr\n#align is_open.exists_lt_is_closed IsOpen.exists_lt_isClosed\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (F \u00abexpr \u2286 \u00bb U) -/\n/-- If `\u03bc` is a weakly regular measure, then any open set can be approximated by a closed subset. -/\ntheorem IsOpen.measure_eq_sup\u1d62_isClosed \u2983U : Set \u03b1\u2984 (hU : IsOpen U) (\u03bc : Measure \u03b1)\n    [WeaklyRegular \u03bc] : \u03bc U = \u2a06 (F) (_ : F \u2286 U) (h : IsClosed F), \u03bc F :=\n  WeaklyRegular.innerRegular.measure_eq_sup\u1d62 hU\n#align is_open.measure_eq_supr_is_closed IsOpen.measure_eq_sup\u1d62_isClosed\n\ntheorem innerRegularMeasurable [WeaklyRegular \u03bc] :\n    InnerRegular \u03bc IsClosed fun s => MeasurableSet s \u2227 \u03bc s \u2260 \u221e :=\n  WeaklyRegular.innerRegular.measurableSetOfOpen isClosed_empty fun _ _ h\u2081 h\u2082 =>\n    h\u2081.inter h\u2082.isClosed_compl\n#align measure_theory.measure.weakly_regular.inner_regular_measurable MeasureTheory.Measure.WeaklyRegular.innerRegularMeasurable\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb s) -/\n/-- If `s` is a measurable set, a weakly regular measure `\u03bc` is finite on `s`, and `\u03b5` is a positive\nnumber, then there exist a closed set `K \u2286 s` such that `\u03bc s < \u03bc K + \u03b5`. -/\ntheorem MeasurableSet.exists_isClosed_lt_add [WeaklyRegular \u03bc] {s : Set \u03b1} (hs : MeasurableSet s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) : \u2203 (K : _)(_ : K \u2286 s), IsClosed K \u2227 \u03bc s < \u03bc K + \u03b5 :=\n  innerRegularMeasurable.exists_subset_lt_add isClosed_empty \u27e8hs, h\u03bcs\u27e9 h\u03bcs h\u03b5\n#align measurable_set.exists_is_closed_lt_add MeasurableSet.exists_isClosed_lt_add\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (F \u00abexpr \u2286 \u00bb A) -/\ntheorem MeasurableSet.exists_isClosed_diff_lt [OpensMeasurableSpace \u03b1] [WeaklyRegular \u03bc] \u2983A : Set \u03b1\u2984\n    (hA : MeasurableSet A) (h'A : \u03bc A \u2260 \u221e) {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) :\n    \u2203 (F : _)(_ : F \u2286 A), IsClosed F \u2227 \u03bc (A \\ F) < \u03b5 :=\n  by\n  rcases hA.exists_is_closed_lt_add h'A h\u03b5 with \u27e8F, hFA, hFc, hF\u27e9\n  exact\n    \u27e8F, hFA, hFc,\n      measure_diff_lt_of_lt_add hFc.measurable_set hFA (ne_top_of_le_ne_top h'A <| measure_mono hFA)\n        hF\u27e9\n#align measurable_set.exists_is_closed_diff_lt MeasurableSet.exists_isClosed_diff_lt\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb A) -/\n/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from\ninside by closed sets. -/\ntheorem MeasurableSet.exists_lt_isClosed_of_ne_top [WeaklyRegular \u03bc] \u2983A : Set \u03b1\u2984\n    (hA : MeasurableSet A) (h'A : \u03bc A \u2260 \u221e) {r : \u211d\u22650\u221e} (hr : r < \u03bc A) :\n    \u2203 (K : _)(_ : K \u2286 A), IsClosed K \u2227 r < \u03bc K :=\n  innerRegularMeasurable \u27e8hA, h'A\u27e9 _ hr\n#align measurable_set.exists_lt_is_closed_of_ne_top MeasurableSet.exists_lt_isClosed_of_ne_top\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (K \u00abexpr \u2286 \u00bb A) -/\n/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from\ninside by closed sets. -/\ntheorem MeasurableSet.measure_eq_sup\u1d62_isClosed_of_ne_top [WeaklyRegular \u03bc] \u2983A : Set \u03b1\u2984\n    (hA : MeasurableSet A) (h'A : \u03bc A \u2260 \u221e) : \u03bc A = \u2a06 (K) (_ : K \u2286 A) (h : IsClosed K), \u03bc K :=\n  innerRegularMeasurable.measure_eq_sup\u1d62 \u27e8hA, h'A\u27e9\n#align measurable_set.measure_eq_supr_is_closed_of_ne_top MeasurableSet.measure_eq_sup\u1d62_isClosed_of_ne_top\n\n/-- The restriction of a weakly regular measure to a measurable set of finite measure is\nweakly regular. -/\ntheorem restrictOfMeasurableSet [BorelSpace \u03b1] [WeaklyRegular \u03bc] (A : Set \u03b1) (hA : MeasurableSet A)\n    (h'A : \u03bc A \u2260 \u221e) : WeaklyRegular (\u03bc.restrict A) :=\n  by\n  haveI : Fact (\u03bc A < \u221e) := \u27e8h'A.lt_top\u27e9\n  refine' inner_regular.weakly_regular_of_finite _ fun V V_open => _\n  simp only [restrict_apply' hA]\n  intro r hr\n  have : \u03bc (V \u2229 A) \u2260 \u221e := ne_top_of_le_ne_top h'A (measure_mono <| inter_subset_right _ _)\n  rcases(V_open.measurable_set.inter hA).exists_lt_isClosed_of_ne_top this hr with\n    \u27e8F, hFVA, hFc, hF\u27e9\n  refine' \u27e8F, hFVA.trans (inter_subset_left _ _), hFc, _\u27e9\n  rwa [inter_eq_self_of_subset_left (hFVA.trans <| inter_subset_right _ _)]\n#align measure_theory.measure.weakly_regular.restrict_of_measurable_set MeasureTheory.Measure.WeaklyRegular.restrictOfMeasurableSet\n\n-- see Note [lower instance priority]\n/-- Any finite measure on a metric space (or even a pseudo emetric space) is weakly regular. -/\ninstance (priority := 100) ofPseudoEmetricSpaceOfIsFiniteMeasure {X : Type _} [PseudoEMetricSpace X]\n    [MeasurableSpace X] [BorelSpace X] (\u03bc : Measure X) [IsFiniteMeasure \u03bc] : WeaklyRegular \u03bc :=\n  (InnerRegular.ofPseudoEmetricSpace \u03bc).weaklyRegularOfFinite \u03bc\n#align measure_theory.measure.weakly_regular.of_pseudo_emetric_space_of_is_finite_measure MeasureTheory.Measure.WeaklyRegular.ofPseudoEmetricSpaceOfIsFiniteMeasure\n\n-- see Note [lower instance priority]\n/-- Any locally finite measure on a second countable metric space (or even a pseudo emetric space)\nis weakly regular. -/\ninstance (priority := 100) ofPseudoEmetricSecondCountableOfLocallyFinite {X : Type _}\n    [PseudoEMetricSpace X] [TopologicalSpace.SecondCountableTopology X] [MeasurableSpace X]\n    [BorelSpace X] (\u03bc : Measure X) [IsLocallyFiniteMeasure \u03bc] : WeaklyRegular \u03bc :=\n  haveI : outer_regular \u03bc :=\n    by\n    refine' (\u03bc.finite_spanning_sets_in_open'.mono' fun U hU => _).OuterRegular\n    have : Fact (\u03bc U < \u221e) := \u27e8hU.2\u27e9\n    exact \u27e8hU.1, inferInstance\u27e9\n  \u27e8inner_regular.of_pseudo_emetric_space \u03bc\u27e9\n#align measure_theory.measure.weakly_regular.of_pseudo_emetric_second_countable_of_locally_finite MeasureTheory.Measure.WeaklyRegular.ofPseudoEmetricSecondCountableOfLocallyFinite\n\nend WeaklyRegular\n\nattribute [local instance] EMetric.secondCountable_of_sigmaCompact\n\n-- see Note [lower instance priority]\n/-- Any locally finite measure on a `\u03c3`-compact (e)metric space is regular. -/\ninstance (priority := 100) Regular.ofSigmaCompactSpaceOfIsLocallyFiniteMeasure {X : Type _}\n    [EMetricSpace X] [SigmaCompactSpace X] [MeasurableSpace X] [BorelSpace X] (\u03bc : Measure X)\n    [IsLocallyFiniteMeasure \u03bc] : Regular \u03bc\n    where\n  lt_top_of_isCompact K hK := hK.measure_lt_top\n  InnerRegular := (InnerRegular.isCompactIsClosed \u03bc).trans (InnerRegular.ofPseudoEmetricSpace \u03bc)\n#align measure_theory.measure.regular.of_sigma_compact_space_of_is_locally_finite_measure MeasureTheory.Measure.Regular.ofSigmaCompactSpaceOfIsLocallyFiniteMeasure\n\nend Measure\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Measure/Regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7406682130366117}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module data.polynomial.reverse\n! leanprover-community/mathlib commit 44de64f183393284a16016dfb2a48ac97382f2bd\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.Degree.TrailingDegree\nimport Mathlib.Data.Polynomial.EraseLead\nimport Mathlib.Data.Polynomial.Eval\n\n/-!\n# Reverse of a univariate polynomial\n\nThe main definition is `reverse`.  Applying `reverse` to a polynomial `f : R[X]` produces\nthe polynomial with a reversed list of coefficients, equivalent to `X^f.natDegree * f(1/X)`.\n\nThe main result is that `reverse (f * g) = reverse f * reverse g`, provided the leading\ncoefficients of `f` and `g` do not multiply to zero.\n-/\n\n\nnamespace Polynomial\n\nopen Polynomial Finsupp Finset\n\nopen Classical Polynomial\n\nsection Semiring\n\nvariable {R : Type _} [Semiring R] {f : R[X]}\n\n/-- If `i \u2264 N`, then `revAtFun N i` returns `N - i`, otherwise it returns `i`.\nThis is the map used by the embedding `revAt`.\n-/\ndef revAtFun (N i : \u2115) : \u2115 :=\n  ite (i \u2264 N) (N - i) i\n#align polynomial.rev_at_fun Polynomial.revAtFun\n\ntheorem revAtFun_invol {N i : \u2115} : revAtFun N (revAtFun N i) = i := by\n  unfold revAtFun\n  split_ifs with h j\n  \u00b7 exact tsub_tsub_cancel_of_le h\n  \u00b7 exfalso\n    apply j\n    exact Nat.sub_le N i\n  \u00b7 rfl\n#align polynomial.rev_at_fun_invol Polynomial.revAtFun_invol\n\ntheorem revAtFun_inj {N : \u2115} : Function.Injective (revAtFun N) := by\n  intro a b hab\n  rw [\u2190 @revAtFun_invol N a, hab, revAtFun_invol]\n#align polynomial.rev_at_fun_inj Polynomial.revAtFun_inj\n\n/-- If `i \u2264 N`, then `revAt N i` returns `N - i`, otherwise it returns `i`.\nEssentially, this embedding is only used for `i \u2264 N`.\nThe advantage of `revAt N i` over `N - i` is that `revAt` is an involution.\n-/\ndef revAt (N : \u2115) : Function.Embedding \u2115 \u2115\n    where\n  toFun i := ite (i \u2264 N) (N - i) i\n  inj' := revAtFun_inj\n#align polynomial.rev_at Polynomial.revAt\n\n/-- We prefer to use the bundled `revAt` over unbundled `revAtfun`. -/\n@[simp]\ntheorem revAtFun_eq (N i : \u2115) : revAtFun N i = revAt N i :=\n  rfl\n#align polynomial.rev_at_fun_eq Polynomial.revAtFun_eq\n\n@[simp]\ntheorem revAt_invol {N i : \u2115} : (revAt N) (revAt N i) = i :=\n  revAtFun_invol\n#align polynomial.rev_at_invol Polynomial.revAt_invol\n\n@[simp]\ntheorem revAt_le {N i : \u2115} (H : i \u2264 N) : revAt N i = N - i :=\n  if_pos H\n#align polynomial.rev_at_le Polynomial.revAt_le\n\ntheorem revAt_add {N O n o : \u2115} (hn : n \u2264 N) (ho : o \u2264 O) :\n    revAt (N + O) (n + o) = revAt N n + revAt O o := by\n  rcases Nat.le.dest hn with \u27e8n', rfl\u27e9\n  rcases Nat.le.dest ho with \u27e8o', rfl\u27e9\n  repeat' rw [revAt_le (le_add_right rfl.le)]\n  rw [add_assoc, add_left_comm n' o, \u2190 add_assoc, revAt_le (le_add_right rfl.le)]\n  repeat' rw [add_tsub_cancel_left]\n#align polynomial.rev_at_add Polynomial.revAt_add\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem revAt_zero (N : \u2115) : revAt N 0 = N := by simp\n#align polynomial.rev_at_zero Polynomial.revAt_zero\n\n/-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (revAt N i)`.\nIn other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`.\n\nIn practice, `reflect` is only used when `N` is at least as large as the degree of `f`.\n\nEventually, it will be used with `N` exactly equal to the degree of `f`.  -/\nnoncomputable def reflect (N : \u2115) : R[X] \u2192 R[X]\n  | \u27e8f\u27e9 => \u27e8Finsupp.embDomain (revAt N) f\u27e9\n#align polynomial.reflect Polynomial.reflect\n\ntheorem reflect_support (N : \u2115) (f : R[X]) :\n    (reflect N f).support = Finset.image (revAt N) f.support := by\n  rcases f with \u27e8\u27e9\n  ext1\n  simp only [reflect, support_ofFinsupp, support_embDomain, Finset.mem_map, Finset.mem_image]\n#align polynomial.reflect_support Polynomial.reflect_support\n\n@[simp]\ntheorem coeff_reflect (N : \u2115) (f : R[X]) (i : \u2115) : coeff (reflect N f) i = f.coeff (revAt N i) := by\n  rcases f with \u27e8f\u27e9\n  simp only [reflect, coeff]\n  calc\n    Finsupp.embDomain (revAt N) f i = Finsupp.embDomain (revAt N) f (revAt N (revAt N i)) := by\n      rw [revAt_invol]\n    _ = f (revAt N i) := Finsupp.embDomain_apply _ _ _\n\n#align polynomial.coeff_reflect Polynomial.coeff_reflect\n\n@[simp]\ntheorem reflect_zero {N : \u2115} : reflect N (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.reflect_zero Polynomial.reflect_zero\n\n@[simp]\ntheorem reflect_eq_zero_iff {N : \u2115} {f : R[X]} : reflect N (f : R[X]) = 0 \u2194 f = 0 := by\n  rw [ofFinsupp_eq_zero, reflect, embDomain_eq_zero, ofFinsupp_eq_zero]\n#align polynomial.reflect_eq_zero_iff Polynomial.reflect_eq_zero_iff\n\n@[simp]\ntheorem reflect_add (f g : R[X]) (N : \u2115) : reflect N (f + g) = reflect N f + reflect N g := by\n  ext\n  simp only [coeff_add, coeff_reflect]\n#align polynomial.reflect_add Polynomial.reflect_add\n\n@[simp]\ntheorem reflect_C_mul (f : R[X]) (r : R) (N : \u2115) : reflect N (C r * f) = C r * reflect N f := by\n  ext\n  simp only [coeff_reflect, coeff_C_mul]\nset_option linter.uppercaseLean3 false in\n#align polynomial.reflect_C_mul Polynomial.reflect_C_mul\n\n-- @[simp] -- Porting note: simp can prove this (once `reflect_monomial` is in simp scope)\ntheorem reflect_C_mul_X_pow (N n : \u2115) {c : R} : reflect N (C c * X ^ n) = C c * X ^ revAt N n := by\n  ext\n  rw [reflect_C_mul, coeff_C_mul, coeff_C_mul, coeff_X_pow, coeff_reflect]\n  split_ifs with h\n  \u00b7 rw [h, revAt_invol, coeff_X_pow_self]\n  \u00b7 rw [not_mem_support_iff.mp]\n    intro a\n    rw [\u2190 one_mul (X ^ n), \u2190 C_1] at a\n    apply h\n    rw [\u2190 mem_support_C_mul_X_pow a, revAt_invol]\nset_option linter.uppercaseLean3 false in\n#align polynomial.reflect_C_mul_X_pow Polynomial.reflect_C_mul_X_pow\n\n@[simp]\ntheorem reflect_C (r : R) (N : \u2115) : reflect N (C r) = C r * X ^ N := by\n  conv_lhs => rw [\u2190 mul_one (C r), \u2190 pow_zero X, reflect_C_mul_X_pow, revAt_zero]\nset_option linter.uppercaseLean3 false in\n#align polynomial.reflect_C Polynomial.reflect_C\n\n@[simp]\ntheorem reflect_monomial (N n : \u2115) : reflect N ((X : R[X]) ^ n) = X ^ revAt N n := by\n  rw [\u2190 one_mul (X ^ n), \u2190 one_mul (X ^ revAt N n), \u2190 C_1, reflect_C_mul_X_pow]\n#align polynomial.reflect_monomial Polynomial.reflect_monomial\n\ntheorem reflect_mul_induction (cf cg : \u2115) :\n    \u2200 N O : \u2115,\n      \u2200 f g : R[X],\n        f.support.card \u2264 cf.succ \u2192\n          g.support.card \u2264 cg.succ \u2192\n            f.natDegree \u2264 N \u2192\n              g.natDegree \u2264 O \u2192 reflect (N + O) (f * g) = reflect N f * reflect O g := by\n  induction' cf with cf hcf\n  --first induction (left): base case\n  \u00b7 induction' cg with cg hcg\n    -- second induction (right): base case\n    \u00b7 intro N O f g Cf Cg Nf Og\n      rw [\u2190 C_mul_X_pow_eq_self Cf, \u2190 C_mul_X_pow_eq_self Cg]\n      simp_rw [mul_assoc, X_pow_mul, mul_assoc, \u2190 pow_add (X : R[X]), reflect_C_mul,\n        reflect_monomial, add_comm, revAt_add Nf Og, mul_assoc, X_pow_mul, mul_assoc, \u2190\n        pow_add (X : R[X]), add_comm]\n    -- second induction (right): induction step\n    \u00b7 intro N O f g Cf Cg Nf Og\n      by_cases g0 : g = 0\n      \u00b7 rw [g0, reflect_zero, mul_zero, mul_zero, reflect_zero]\n      rw [\u2190 eraseLead_add_C_mul_X_pow g, mul_add, reflect_add, reflect_add, mul_add, hcg, hcg] <;>\n        try assumption\n      \u00b7 exact le_add_left card_support_C_mul_X_pow_le_one\n      \u00b7 exact le_trans (natDegree_C_mul_X_pow_le g.leadingCoeff g.natDegree) Og\n      \u00b7 exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cg (eraseLead_support_card_lt g0))\n      \u00b7 exact le_trans eraseLead_natDegree_le_aux Og\n  --first induction (left): induction step\n  \u00b7 intro N O f g Cf Cg Nf Og\n    by_cases f0 : f = 0\n    \u00b7 rw [f0, reflect_zero, zero_mul, zero_mul, reflect_zero]\n    rw [\u2190 eraseLead_add_C_mul_X_pow f, add_mul, reflect_add, reflect_add, add_mul, hcf, hcf] <;>\n      try assumption\n    \u00b7 exact le_add_left card_support_C_mul_X_pow_le_one\n    \u00b7 exact le_trans (natDegree_C_mul_X_pow_le f.leadingCoeff f.natDegree) Nf\n    \u00b7 exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cf (eraseLead_support_card_lt f0))\n    \u00b7 exact le_trans eraseLead_natDegree_le_aux Nf\n#align polynomial.reflect_mul_induction Polynomial.reflect_mul_induction\n\n@[simp]\ntheorem reflect_mul (f g : R[X]) {F G : \u2115} (Ff : f.natDegree \u2264 F) (Gg : g.natDegree \u2264 G) :\n    reflect (F + G) (f * g) = reflect F f * reflect G g :=\n  reflect_mul_induction _ _ F G f g f.support.card.le_succ g.support.card.le_succ Ff Gg\n#align polynomial.reflect_mul Polynomial.reflect_mul\n\nsection Eval\u2082\n\nvariable {S : Type _} [CommSemiring S]\n\ntheorem eval\u2082_reflect_mul_pow (i : R \u2192+* S) (x : S) [Invertible x] (N : \u2115) (f : R[X])\n    (hf : f.natDegree \u2264 N) : eval\u2082 i (\u215f x) (reflect N f) * x ^ N = eval\u2082 i x f := by\n  refine'\n    induction_with_natDegree_le (fun f => eval\u2082 i (\u215f x) (reflect N f) * x ^ N = eval\u2082 i x f) _ _ _\n      _ f hf\n  \u00b7 simp\n  \u00b7 intro n r _ hnN\n    simp only [revAt_le hnN, reflect_C_mul_X_pow, eval\u2082_X_pow, eval\u2082_C, eval\u2082_mul]\n    conv in x ^ N => rw [\u2190 Nat.sub_add_cancel hnN]\n    rw [pow_add, \u2190 mul_assoc, mul_assoc (i r), \u2190 mul_pow, invOf_mul_self, one_pow, mul_one]\n  \u00b7 intros\n    simp [*, add_mul]\n#align polynomial.eval\u2082_reflect_mul_pow Polynomial.eval\u2082_reflect_mul_pow\n\ntheorem eval\u2082_reflect_eq_zero_iff (i : R \u2192+* S) (x : S) [Invertible x] (N : \u2115) (f : R[X])\n    (hf : f.natDegree \u2264 N) : eval\u2082 i (\u215f x) (reflect N f) = 0 \u2194 eval\u2082 i x f = 0 := by\n  conv_rhs => rw [\u2190 eval\u2082_reflect_mul_pow i x N f hf]\n  constructor\n  \u00b7 intro h\n    rw [h, zero_mul]\n  \u00b7 intro h\n    rw [\u2190 mul_one (eval\u2082 i (\u215f x) _), \u2190 one_pow N, \u2190 mul_invOf_self x, mul_pow, \u2190 mul_assoc, h,\n      zero_mul]\n#align polynomial.eval\u2082_reflect_eq_zero_iff Polynomial.eval\u2082_reflect_eq_zero_iff\n\nend Eval\u2082\n\n/-- The reverse of a polynomial f is the polynomial obtained by \"reading f backwards\".\nEven though this is not the actual definition, `reverse f = f (1/X) * X ^ f.natDegree`. -/\nnoncomputable def reverse (f : R[X]) : R[X] :=\n  reflect f.natDegree f\n#align polynomial.reverse Polynomial.reverse\n\ntheorem coeff_reverse (f : R[X]) (n : \u2115) : f.reverse.coeff n = f.coeff (revAt f.natDegree n) := by\n  rw [reverse, coeff_reflect]\n#align polynomial.coeff_reverse Polynomial.coeff_reverse\n\n@[simp]\ntheorem coeff_zero_reverse (f : R[X]) : coeff (reverse f) 0 = leadingCoeff f := by\n  rw [coeff_reverse, revAt_le (zero_le f.natDegree), tsub_zero, leadingCoeff]\n#align polynomial.coeff_zero_reverse Polynomial.coeff_zero_reverse\n\n@[simp]\ntheorem reverse_zero : reverse (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.reverse_zero Polynomial.reverse_zero\n\n@[simp]\ntheorem reverse_eq_zero : f.reverse = 0 \u2194 f = 0 := by simp [reverse]\n#align polynomial.reverse_eq_zero Polynomial.reverse_eq_zero\n\n\n\ntheorem natDegree_eq_reverse_natDegree_add_natTrailingDegree (f : R[X]) :\n    f.natDegree = f.reverse.natDegree + f.natTrailingDegree := by\n  by_cases hf : f = 0\n  \u00b7 rw [hf, reverse_zero, natDegree_zero, natTrailingDegree_zero]\n  apply le_antisymm\n  \u00b7 refine' tsub_le_iff_right.mp _\n    apply le_natDegree_of_ne_zero\n    rw [reverse, coeff_reflect, \u2190 revAt_le f.natTrailingDegree_le_natDegree, revAt_invol]\n    exact trailingCoeff_nonzero_iff_nonzero.mpr hf\n  \u00b7 rw [\u2190 le_tsub_iff_left f.reverse_natDegree_le]\n    apply natTrailingDegree_le_of_ne_zero\n    have key := mt leadingCoeff_eq_zero.mp (mt reverse_eq_zero.mp hf)\n    rwa [leadingCoeff, coeff_reverse, revAt_le f.reverse_natDegree_le] at key\n#align polynomial.nat_degree_eq_reverse_nat_degree_add_nat_trailing_degree Polynomial.natDegree_eq_reverse_natDegree_add_natTrailingDegree\n\ntheorem reverse_natDegree (f : R[X]) : f.reverse.natDegree = f.natDegree - f.natTrailingDegree := by\n  rw [f.natDegree_eq_reverse_natDegree_add_natTrailingDegree, add_tsub_cancel_right]\n#align polynomial.reverse_nat_degree Polynomial.reverse_natDegree\n\ntheorem reverse_leadingCoeff (f : R[X]) : f.reverse.leadingCoeff = f.trailingCoeff := by\n  rw [leadingCoeff, reverse_natDegree, \u2190 revAt_le f.natTrailingDegree_le_natDegree,\n    coeff_reverse, revAt_invol, trailingCoeff]\n#align polynomial.reverse_leading_coeff Polynomial.reverse_leadingCoeff\n\ntheorem reverse_natTrailingDegree (f : R[X]) : f.reverse.natTrailingDegree = 0 := by\n  by_cases hf : f = 0\n  \u00b7 rw [hf, reverse_zero, natTrailingDegree_zero]\n  \u00b7 rw [\u2190 le_zero_iff]\n    apply natTrailingDegree_le_of_ne_zero\n    rw [coeff_zero_reverse]\n    exact mt leadingCoeff_eq_zero.mp hf\n#align polynomial.reverse_nat_trailing_degree Polynomial.reverse_natTrailingDegree\n\ntheorem reverse_trailingCoeff (f : R[X]) : f.reverse.trailingCoeff = f.leadingCoeff := by\n  rw [trailingCoeff, reverse_natTrailingDegree, coeff_zero_reverse]\n#align polynomial.reverse_trailing_coeff Polynomial.reverse_trailingCoeff\n\ntheorem reverse_mul {f g : R[X]} (fg : f.leadingCoeff * g.leadingCoeff \u2260 0) :\n    reverse (f * g) = reverse f * reverse g := by\n  unfold reverse\n  rw [natDegree_mul' fg, reflect_mul f g rfl.le rfl.le]\n#align polynomial.reverse_mul Polynomial.reverse_mul\n\n@[simp]\ntheorem reverse_mul_of_domain {R : Type _} [Ring R] [NoZeroDivisors R] (f g : R[X]) :\n    reverse (f * g) = reverse f * reverse g := by\n  by_cases f0 : f = 0\n  \u00b7 simp only [f0, zero_mul, reverse_zero]\n  by_cases g0 : g = 0\n  \u00b7 rw [g0, mul_zero, reverse_zero, mul_zero]\n  simp [reverse_mul, *]\n#align polynomial.reverse_mul_of_domain Polynomial.reverse_mul_of_domain\n\ntheorem trailingCoeff_mul {R : Type _} [Ring R] [NoZeroDivisors R] (p q : R[X]) :\n    (p * q).trailingCoeff = p.trailingCoeff * q.trailingCoeff := by\n  rw [\u2190 reverse_leadingCoeff, reverse_mul_of_domain, leadingCoeff_mul, reverse_leadingCoeff,\n    reverse_leadingCoeff]\n#align polynomial.trailing_coeff_mul Polynomial.trailingCoeff_mul\n\n@[simp]\ntheorem coeff_one_reverse (f : R[X]) : coeff (reverse f) 1 = nextCoeff f := by\n  rw [coeff_reverse, nextCoeff]\n  split_ifs with hf\n  \u00b7 have : coeff f 1 = 0 := coeff_eq_zero_of_natDegree_lt (by simp only [hf, zero_lt_one])\n    simp [*, revAt]\n  \u00b7 rw [revAt_le]\n    exact Nat.succ_le_iff.2 (pos_iff_ne_zero.2 hf)\n#align polynomial.coeff_one_reverse Polynomial.coeff_one_reverse\n\nsection Eval\u2082\n\nvariable {S : Type _} [CommSemiring S]\n\ntheorem eval\u2082_reverse_mul_pow (i : R \u2192+* S) (x : S) [Invertible x] (f : R[X]) :\n    eval\u2082 i (\u215f x) (reverse f) * x ^ f.natDegree = eval\u2082 i x f :=\n  eval\u2082_reflect_mul_pow i _ _ f le_rfl\n#align polynomial.eval\u2082_reverse_mul_pow Polynomial.eval\u2082_reverse_mul_pow\n\n@[simp]\ntheorem eval\u2082_reverse_eq_zero_iff (i : R \u2192+* S) (x : S) [Invertible x] (f : R[X]) :\n    eval\u2082 i (\u215f x) (reverse f) = 0 \u2194 eval\u2082 i x f = 0 :=\n  eval\u2082_reflect_eq_zero_iff i x _ _ le_rfl\n#align polynomial.eval\u2082_reverse_eq_zero_iff Polynomial.eval\u2082_reverse_eq_zero_iff\n\nend Eval\u2082\n\nend Semiring\n\nsection Ring\n\nvariable {R : Type _} [Ring R]\n\n@[simp]\ntheorem reflect_neg (f : R[X]) (N : \u2115) : reflect N (-f) = -reflect N f := by\n  rw [neg_eq_neg_one_mul, \u2190 C_1, \u2190 C_neg, reflect_C_mul, C_neg, C_1, \u2190 neg_eq_neg_one_mul]\n#align polynomial.reflect_neg Polynomial.reflect_neg\n\n@[simp]\ntheorem reflect_sub (f g : R[X]) (N : \u2115) : reflect N (f - g) = reflect N f - reflect N g := by\n  rw [sub_eq_add_neg, sub_eq_add_neg, reflect_add, reflect_neg]\n#align polynomial.reflect_sub Polynomial.reflect_sub\n\n@[simp]\ntheorem reverse_neg (f : R[X]) : reverse (-f) = -reverse f := by\n  rw [reverse, reverse, reflect_neg, natDegree_neg]\n#align polynomial.reverse_neg Polynomial.reverse_neg\n\nend Ring\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Reverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7406682088011509}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport order.monotone.union\nimport algebra.order.group.instances\n\n/-!\n# Monotonicity of odd functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nAn odd function on a linear ordered additive commutative group `G` is monotone on the whole group\nprovided that is is monotone on `set.Ici 0`, see `monotone_of_odd_of_monotone_on_nonneg`. We also\nprove versions of this lemma for `antitone`, `strict_mono`, and `strict_anti`.\n-/\n\nopen set\nvariables {G H : Type*} [linear_ordered_add_comm_group G] [ordered_add_comm_group H]\n\n/-- An odd function on a linear ordered additive commutative group is strictly monotone on the whole\ngroup provided that it is strictly monotone on `set.Ici 0`. -/\nlemma strict_mono_of_odd_strict_mono_on_nonneg {f : G \u2192 H} (h\u2081 : \u2200 x, f (-x) = -f x)\n  (h\u2082 : strict_mono_on f (Ici 0)) :\n  strict_mono f :=\nbegin\n  refine strict_mono_on.Iic_union_Ici (\u03bb x hx y hy hxy, neg_lt_neg_iff.1 _) h\u2082,\n  rw [\u2190 h\u2081, \u2190 h\u2081],\n  exact h\u2082 (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_lt_neg hxy)\nend\n\n/-- An odd function on a linear ordered additive commutative group is strictly antitone on the whole\ngroup provided that it is strictly antitone on `set.Ici 0`. -/\nlemma strict_anti_of_odd_strict_anti_on_nonneg {f : G \u2192 H} (h\u2081 : \u2200 x, f (-x) = -f x)\n  (h\u2082 : strict_anti_on f (Ici 0)) :\n  strict_anti f :=\n@strict_mono_of_odd_strict_mono_on_nonneg G H\u1d52\u1d48 _ _ _ h\u2081 h\u2082\n\n/-- An odd function on a linear ordered additive commutative group is monotone on the whole group\nprovided that it is monotone on `set.Ici 0`. -/\nlemma monotone_of_odd_of_monotone_on_nonneg {f : G \u2192 H} (h\u2081 : \u2200 x, f (-x) = -f x)\n  (h\u2082 : monotone_on f (Ici 0)) : monotone f :=\nbegin\n  refine monotone_on.Iic_union_Ici (\u03bb x hx y hy hxy, neg_le_neg_iff.1 _) h\u2082,\n  rw [\u2190 h\u2081, \u2190 h\u2081],\n  exact h\u2082 (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_le_neg hxy)\nend\n\n/-- An odd function on a linear ordered additive commutative group is antitone on the whole group\nprovided that it is monotone on `set.Ici 0`. -/\nlemma antitone_of_odd_of_monotone_on_nonneg {f : G \u2192 H} (h\u2081 : \u2200 x, f (-x) = -f x)\n  (h\u2082 : antitone_on f (Ici 0)) : antitone f :=\n@monotone_of_odd_of_monotone_on_nonneg G H\u1d52\u1d48 _ _ _ h\u2081 h\u2082\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/monotone/odd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7406681928021713}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.fintype.lattice\n! leanprover-community/mathlib commit 509de852e1de55e1efa8eacfa11df0823f26f226\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Data.Finset.Lattice\n\n/-!\n# Lemmas relating fintypes and order/lattice structure.\n-/\n\n\nopen Function\n\nopen Nat\n\nuniverse u v\n\nvariable {\u03b1 \u03b2 : Type _}\n\nnamespace Finset\n\nvariable [Fintype \u03b1] {s : Finset \u03b1}\n\n/-- A special case of `Finset.sup_eq_sup\u1d62` that omits the useless `x \u2208 univ` binder. -/\ntheorem sup_univ_eq_sup\u1d62 [CompleteLattice \u03b2] (f : \u03b1 \u2192 \u03b2) : Finset.univ.sup f = sup\u1d62 f :=\n  (sup_eq_sup\u1d62 _ f).trans <| congr_arg _ <| funext fun _ => sup\u1d62_pos (mem_univ _)\n#align finset.sup_univ_eq_supr Finset.sup_univ_eq_sup\u1d62\n\n/-- A special case of `Finset.inf_eq_inf\u1d62` that omits the useless `x \u2208 univ` binder. -/\ntheorem inf_univ_eq_inf\u1d62 [CompleteLattice \u03b2] (f : \u03b1 \u2192 \u03b2) : Finset.univ.inf f = inf\u1d62 f :=\n  @sup_univ_eq_sup\u1d62 _ \u03b2\u1d52\u1d48 _ _ (f : \u03b1 \u2192 \u03b2\u1d52\u1d48)\n#align finset.inf_univ_eq_infi Finset.inf_univ_eq_inf\u1d62\n\n@[simp]\ntheorem fold_inf_univ [SemilatticeInf \u03b1] [OrderBot \u03b1] (a : \u03b1) :\n    -- Porting note: added `haveI`\n    haveI : IsCommutative \u03b1 (\u00b7 \u2293 \u00b7) := inferInstance\n    (Finset.univ.fold (\u00b7 \u2293 \u00b7) a fun x => x) = \u22a5 :=\n  eq_bot_iff.2 <|\n    ((Finset.fold_op_rel_iff_and <| @le_inf_iff \u03b1 _).1 le_rfl).2 \u22a5 <| Finset.mem_univ _\n#align finset.fold_inf_univ Finset.fold_inf_univ\n\n@[simp]\ntheorem fold_sup_univ [SemilatticeSup \u03b1] [OrderTop \u03b1] (a : \u03b1) :\n    -- Porting note: added `haveI`\n    haveI : IsCommutative \u03b1 (\u00b7 \u2294 \u00b7) := inferInstance\n    (Finset.univ.fold (\u00b7 \u2294 \u00b7) a fun x => x) = \u22a4 :=\n  @fold_inf_univ \u03b1\u1d52\u1d48 _ _ _ _\n#align finset.fold_sup_univ Finset.fold_sup_univ\n\nend Finset\n\nopen Finset Function\n\ntheorem Finite.exists_max [Finite \u03b1] [Nonempty \u03b1] [LinearOrder \u03b2] (f : \u03b1 \u2192 \u03b2) :\n    \u2203 x\u2080 : \u03b1, \u2200 x, f x \u2264 f x\u2080 := by\n  cases nonempty_fintype \u03b1\n  simpa using exists_max_image univ f univ_nonempty\n#align finite.exists_max Finite.exists_max\n\ntheorem Finite.exists_min [Finite \u03b1] [Nonempty \u03b1] [LinearOrder \u03b2] (f : \u03b1 \u2192 \u03b2) :\n    \u2203 x\u2080 : \u03b1, \u2200 x, f x\u2080 \u2264 f x := by\n  cases nonempty_fintype \u03b1\n  simpa using exists_min_image univ f univ_nonempty\n#align finite.exists_min Finite.exists_min\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Fintype/Lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7406245613094369}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport data.list.join\nimport data.set.lattice\n\n/-!\n# Languages\n\nThis file contains the definition and operations on formal languages over an alphabet. Note strings\nare implemented as lists over the alphabet.\nThe operations in this file define a [Kleene algebra](https://en.wikipedia.org/wiki/Kleene_algebra)\nover the languages.\n-/\n\nuniverses u v\n\nvariables {\u03b1 : Type u}\n\n/-- A language is a set of strings over an alphabet. -/\n@[derive [has_mem (list \u03b1), has_singleton (list \u03b1), has_insert (list \u03b1), complete_boolean_algebra]]\ndef language (\u03b1) := set (list \u03b1)\n\nnamespace language\n\nlocal attribute [reducible] language\n\n/-- Zero language has no elements. -/\ninstance : has_zero (language \u03b1) := \u27e8(\u2205 : set _)\u27e9\n/-- `1 : language \u03b1` contains only one element `[]`. -/\ninstance : has_one (language \u03b1) := \u27e8{[]}\u27e9\n\ninstance : inhabited (language \u03b1) := \u27e80\u27e9\n\n/-- The sum of two languages is the union of  -/\ninstance : has_add (language \u03b1) := \u27e8set.union\u27e9\ninstance : has_mul (language \u03b1) := \u27e8set.image2 (++)\u27e9\n\nlemma zero_def : (0 : language \u03b1) = (\u2205 : set _) := rfl\nlemma one_def : (1 : language \u03b1) = {[]} := rfl\n\nlemma add_def (l m : language \u03b1) : l + m = l \u222a m := rfl\nlemma mul_def (l m : language \u03b1) : l * m = set.image2 (++) l m := rfl\n\n/-- The star of a language `L` is the set of all strings which can be written by concatenating\n  strings from `L`. -/\ndef star (l : language \u03b1) : language \u03b1 :=\n{ x | \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l}\n\nlemma star_def (l : language \u03b1) :\n  l.star = { x | \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l} := rfl\n\n@[simp] lemma mem_one (x : list \u03b1) : x \u2208 (1 : language \u03b1) \u2194 x = [] := by refl\n@[simp] lemma mem_add (l m : language \u03b1) (x : list \u03b1) : x \u2208 l + m \u2194 x \u2208 l \u2228 x \u2208 m :=\nby simp [add_def]\nlemma mem_mul (l m : language \u03b1) (x : list \u03b1) : x \u2208 l * m \u2194 \u2203 a b, a \u2208 l \u2227 b \u2208 m \u2227 a ++ b = x :=\nby simp [mul_def]\nlemma mem_star (l : language \u03b1) (x : list \u03b1) :\n  x \u2208 l.star \u2194 \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l :=\niff.rfl\n\ninstance : semiring (language \u03b1) :=\n{ add := (+),\n  add_assoc := set.union_assoc,\n  zero := 0,\n  zero_add := set.empty_union,\n  add_zero := set.union_empty,\n  add_comm := set.union_comm,\n  mul := (*),\n  mul_assoc := \u03bb l m n,\n    by simp only [mul_def, set.image2_image2_left, set.image2_image2_right, list.append_assoc],\n  zero_mul := by simp [zero_def, mul_def],\n  mul_zero := by simp [zero_def, mul_def],\n  one := 1,\n  one_mul := \u03bb l, by simp [mul_def, one_def],\n  mul_one := \u03bb l, by simp [mul_def, one_def],\n  left_distrib := \u03bb l m n, by simp only [mul_def, add_def, set.image2_union_right],\n  right_distrib := \u03bb l m n, by simp only [mul_def, add_def, set.image2_union_left] }\n\n@[simp] lemma add_self (l : language \u03b1) : l + l = l := sup_idem\n\nlemma star_def_nonempty (l : language \u03b1) :\n  l.star = {x | \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l \u2227 y \u2260 []} :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8S, rfl, h\u27e9,\n    refine \u27e8S.filter (\u03bb l, \u00aclist.empty l), by simp, \u03bb y hy, _\u27e9,\n    rw [list.mem_filter, list.empty_iff_eq_nil] at hy,\n    exact \u27e8h y hy.1, hy.2\u27e9 },\n  { rintro \u27e8S, hx, h\u27e9,\n    exact \u27e8S, hx, \u03bb y hy, (h y hy).1\u27e9 }\nend\n\n\n\nlemma le_mul_congr {l\u2081 l\u2082 m\u2081 m\u2082 : language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 * l\u2082 \u2264 m\u2081 * m\u2082 :=\nbegin\n  intros h\u2081 h\u2082 x hx,\n  simp only [mul_def, exists_and_distrib_left, set.mem_image2, set.image_prod] at hx \u22a2,\n  tauto\nend\n\nlemma le_add_congr {l\u2081 l\u2082 m\u2081 m\u2082 : language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 + l\u2082 \u2264 m\u2081 + m\u2082 := sup_le_sup\n\nlemma mem_supr {\u03b9 : Sort v} {l : \u03b9 \u2192 language \u03b1} {x : list \u03b1} :\n  x \u2208 (\u2a06 i, l i) \u2194 \u2203 i, x \u2208 l i :=\nset.mem_Union\n\nlemma supr_mul {\u03b9 : Sort v} (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  (\u2a06 i, l i) * m = \u2a06 i, l i * m :=\nset.image2_Union_left _ _ _\n\nlemma mul_supr {\u03b9 : Sort v} (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  m * (\u2a06 i, l i) = \u2a06 i, m * l i :=\nset.image2_Union_right _ _ _\n\nlemma supr_add {\u03b9 : Sort v} [nonempty \u03b9] (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  (\u2a06 i, l i) + m = \u2a06 i, l i + m := supr_sup\n\nlemma add_supr {\u03b9 : Sort v} [nonempty \u03b9] (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  m + (\u2a06 i, l i) = \u2a06 i, m + l i := sup_supr\n\nlemma mem_pow {l : language \u03b1} {x : list \u03b1} {n : \u2115} :\n  x \u2208 l ^ n \u2194 \u2203 S : list (list \u03b1), x = S.join \u2227 S.length = n \u2227 \u2200 y \u2208 S, y \u2208 l :=\nbegin\n  induction n with n ihn generalizing x,\n  { simp only [mem_one, pow_zero, list.length_eq_zero],\n    split,\n    { rintro rfl, exact \u27e8[], rfl, rfl, \u03bb y h, h.elim\u27e9 },\n    { rintro \u27e8_, rfl, rfl, _\u27e9, refl } },\n  { simp only [pow_succ, mem_mul, ihn],\n    split,\n    { rintro \u27e8a, b, ha, \u27e8S, rfl, rfl, hS\u27e9, rfl\u27e9,\n      exact \u27e8a :: S, rfl, rfl, list.forall_mem_cons.2 \u27e8ha, hS\u27e9\u27e9 },\n    { rintro \u27e8_|\u27e8a, S\u27e9, rfl, hn, hS\u27e9; cases hn,\n      rw list.forall_mem_cons at hS,\n      exact \u27e8a, _, hS.1, \u27e8S, rfl, rfl, hS.2\u27e9, rfl\u27e9 } }\nend\n\nlemma star_eq_supr_pow (l : language \u03b1) : l.star = \u2a06 i : \u2115, l ^ i :=\nbegin\n  ext x,\n  simp only [mem_star, mem_supr, mem_pow],\n  split,\n  { rintro \u27e8S, rfl, hS\u27e9, exact \u27e8_, S, rfl, rfl, hS\u27e9 },\n  { rintro \u27e8_, S, rfl, rfl, hS\u27e9, exact \u27e8S, rfl, hS\u27e9 }\nend\n\nlemma mul_self_star_comm (l : language \u03b1) : l.star * l = l * l.star :=\nby simp only [star_eq_supr_pow, mul_supr, supr_mul, \u2190 pow_succ, \u2190 pow_succ']\n\n@[simp] lemma one_add_self_mul_star_eq_star (l : language \u03b1) : 1 + l * l.star = l.star :=\nbegin\n  simp only [star_eq_supr_pow, mul_supr, \u2190 pow_succ, \u2190 pow_zero l],\n  exact sup_supr_nat_succ _\nend\n\n@[simp] lemma one_add_star_mul_self_eq_star (l : language \u03b1) : 1 + l.star * l = l.star :=\nby rw [mul_self_star_comm, one_add_self_mul_star_eq_star]\n\nlemma star_mul_le_right_of_mul_le_right (l m : language \u03b1) : l * m \u2264 m \u2192 l.star * m \u2264 m :=\nbegin\n  intro h,\n  rw [star_eq_supr_pow, supr_mul],\n  refine supr_le _,\n  intro n,\n  induction n with n ih,\n  { simp },\n  rw [pow_succ', mul_assoc (l^n) l m],\n  exact le_trans (le_mul_congr (le_refl _) h) ih,\nend\n\nlemma star_mul_le_left_of_mul_le_left (l m : language \u03b1) : m * l \u2264 m \u2192 m * l.star \u2264 m :=\nbegin\n  intro h,\n  rw [star_eq_supr_pow, mul_supr],\n  refine supr_le _,\n  intro n,\n  induction n with n ih,\n  { simp },\n  rw [pow_succ, \u2190mul_assoc m l (l^n)],\n  exact le_trans (le_mul_congr h (le_refl _)) ih\nend\n\nend language\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/computability/language.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7406245600776464}}
{"text": "/-\nCopyright (c) 2021 Henry Swanson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henry Swanson, Patrick Massot\n-/\nimport analysis.special_functions.exponential\nimport combinatorics.derangements.finite\nimport order.filter.basic\n\n/-!\n# Derangement exponential series\n\nThis file proves that the probability of a permutation on n elements being a derangement is 1/e.\nThe specific lemma is `num_derangements_tendsto_inv_e`.\n-/\nopen filter\n\nopen_locale big_operators\nopen_locale topological_space\n\ntheorem num_derangements_tendsto_inv_e :\n  tendsto (\u03bb n, (num_derangements n : \u211d) / n.factorial) at_top\n  (\ud835\udcdd (real.exp (-1))) :=\nbegin\n  -- we show that d(n)/n! is the partial sum of exp(-1), but offset by 1.\n  -- this isn't entirely obvious, since we have to ensure that asc_factorial and\n  -- factorial interact in the right way, e.g., that k \u2264 n always\n  let s : \u2115 \u2192 \u211d := \u03bb n, \u2211 k in finset.range n, (-1 : \u211d)^k / k.factorial,\n  suffices : \u2200 n : \u2115, (num_derangements n : \u211d) / n.factorial = s(n+1),\n  { simp_rw this,\n    -- shift the function by 1, and then use the fact that the partial sums\n    -- converge to the infinite sum\n    rw tendsto_add_at_top_iff_nat 1,\n    apply has_sum.tendsto_sum_nat,\n    -- there's no specific lemma for \u211d that \u2211 x^k/k! sums to exp(x), but it's\n    -- true in more general fields, so use that lemma\n    rw real.exp_eq_exp_\u211d,\n    exact exp_series_div_has_sum_exp \u211d (-1 : \u211d) },\n  intro n,\n  rw [\u2190 int.cast_coe_nat, num_derangements_sum],\n  push_cast,\n  rw finset.sum_div,\n  -- get down to individual terms\n  refine finset.sum_congr (refl _) _,\n  intros k hk,\n  have h_le : k \u2264 n := finset.mem_range_succ_iff.mp hk,\n  rw [nat.asc_factorial_eq_div, add_tsub_cancel_of_le h_le],\n  push_cast [nat.factorial_dvd_factorial h_le],\n  field_simp [nat.factorial_ne_zero],\n  ring,\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/combinatorics/derangements/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.7405898034905448}}
{"text": "universe u\nvariables (\u03b1 : Type u) (a b c d : \u03b1)\nvariables (hab : a = b) (hcb : c = b) (hcd : c = d)\n\nexample : a = d := eq.trans (eq.trans hab (eq.symm hcb)) hcd\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0203.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7405870505432351}}
{"text": "\ntheorem and_commutative (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\n  fun hpq : p \u2227 q =>\n  have hp : p := And.left hpq\n  have hq : q := And.right hpq\n  show q \u2227 p from And.intro hq hp\n", "meta": {"author": "palutz", "repo": "lean4_intro", "sha": "8504683372b21e2c3418b238e3d29bc25d8422e3", "save_path": "github-repos/lean/palutz-lean4_intro", "path": "github-repos/lean/palutz-lean4_intro/lean4_intro-8504683372b21e2c3418b238e3d29bc25d8422e3/theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.939913354875362, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.7405870464867442}}
{"text": "import tactic\nimport data.real.basic \nimport data.complex.exponential \nimport analysis.special_functions.pow\n\n import wonky_sq.basic\n\n/-! \n# Defining the functions at zero\n\n## Wonky Square GTFs\n\nLet us show that these functions follow general trigonometric convention. We \nare going to show here that they have have values at 0 apart from csc\u2098, but \nthats \u221e -/\n\nnoncomputable theory\nopen_locale classical\n \nopen real\n\n/- 008 \nHere we prove that sin\u2098 0 = 0.\n-/\nlemma sinm_zero (m : \u211d): sinm 0 m = 0 :=\nbegin\n  unfold sinm,\n  rw sin_zero,\n  rw zero_mul,\nend\n\n-- we know that p q > 0 because the negative values get funny and annoying.\n\n-- #print instances has_pow\n\n/- 009\nHere we prove a lemma similar to 008, but for cos\u2098\n-/\nlemma cosm_zero (m : \u211d) (hm : m \u2260 0) : cosm 0 m = 1 :=\nbegin\n  unfold cosm,\n  unfold radius,\n  rw [cos_zero, one_mul, sin_zero, abs_zero, abs_one],\n  simp,\n  rw [zero_rpow, zero_add, one_rpow],\n  simp, exact hm,\n  end \n\n/- 010 \nSimilar to 008, but for tan\u2098\n-/\nlemma tanm_zero (m : \u211d) : tanm 0 m = 0 :=\nbegin \n  unfold tanm,\n  rw [sinm_zero, zero_div],\nend\n\n/- 011\nSimilar to 008, but for sec\u2098\n-/\nlemma secm_zero (m : \u211d) (hm : m \u2260 0) : secm 0 m = 1 :=\nbegin\n  unfold secm,\n  rw cosm_zero, \n  norm_num,\n  exact hm,\nend\n\n/-!\n## p-GTFs\nnothing yet\n-/\n\n", "meta": {"author": "jamesa9283", "repo": "Generalised-Trigonometric-Functions-for-Lean", "sha": "33775fb8286eacfc17397fe41af9d446cbdd78f3", "save_path": "github-repos/lean/jamesa9283-Generalised-Trigonometric-Functions-for-Lean", "path": "github-repos/lean/jamesa9283-Generalised-Trigonometric-Functions-for-Lean/Generalised-Trigonometric-Functions-for-Lean-33775fb8286eacfc17397fe41af9d446cbdd78f3/src/wonky_sq/zero_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.7405155595667705}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport algebra.order.module\nimport algebra.pointwise\nimport data.real.basic\n\n/-!\n# Pointwise operations on sets of reals\n\nThis file relates `Inf (a \u2022 s)`/`Sup (a \u2022 s)` with `a \u2022 Inf s`/`a \u2022 Sup s` for `s : set \u211d`.\n\n# TODO\n\nThis is true more generally for conditionally complete linear order whose default value is `0`. We\ndon't have those yet.\n-/\n\nopen set\nopen_locale pointwise\n\nvariables {\u03b1 : Type*} [linear_ordered_field \u03b1]\n\nsection mul_action_with_zero\nvariables [mul_action_with_zero \u03b1 \u211d] [ordered_smul \u03b1 \u211d] {a : \u03b1}\n\nlemma real.Inf_smul_of_nonneg (ha : 0 \u2264 a) (s : set \u211d) : Inf (a \u2022 s) = a \u2022 Inf s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Inf_empty, smul_zero'] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cInf_singleton 0 },\n  by_cases bdd_below s,\n  { exact ((order_iso.smul_left \u211d ha').map_cInf' hs h).symm },\n  { rw [real.Inf_of_not_bdd_below (mt (bdd_below_smul_iff_of_pos ha').1 h),\n      real.Inf_of_not_bdd_below h, smul_zero'] }\nend\n\nlemma real.Sup_smul_of_nonneg (ha : 0 \u2264 a) (s : set \u211d) : Sup (a \u2022 s) = a \u2022 Sup s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Sup_empty, smul_zero'] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cSup_singleton 0 },\n  by_cases bdd_above s,\n  { exact ((order_iso.smul_left \u211d ha').map_cSup' hs h).symm },\n  { rw [real.Sup_of_not_bdd_above (mt (bdd_above_smul_iff_of_pos ha').1 h),\n      real.Sup_of_not_bdd_above h, smul_zero'] }\nend\n\nend mul_action_with_zero\n\nsection module\nvariables [module \u03b1 \u211d] [ordered_smul \u03b1 \u211d] {a : \u03b1}\n\nlemma real.Inf_smul_of_nonpos (ha : a \u2264 0) (s : set \u211d) : Inf (a \u2022 s) = a \u2022 Sup s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Inf_empty, real.Sup_empty, smul_zero'] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cInf_singleton 0 },\n  by_cases bdd_above s,\n  { exact ((order_iso.smul_left_dual \u211d ha').map_cSup' hs h).symm },\n  { rw [real.Inf_of_not_bdd_below (mt (bdd_below_smul_iff_of_neg ha').1 h),\n      real.Sup_of_not_bdd_above h, smul_zero'] }\nend\n\nlemma real.Sup_smul_of_nonpos (ha : a \u2264 0) (s : set \u211d) : Sup (a \u2022 s) = a \u2022 Inf s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Sup_empty, real.Inf_empty, smul_zero] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cSup_singleton 0 },\n  by_cases bdd_below s,\n  { exact ((order_iso.smul_left_dual \u211d ha').map_cInf' hs h).symm },\n  { rw [real.Sup_of_not_bdd_above (mt (bdd_above_smul_iff_of_neg ha').1 h),\n      real.Inf_of_not_bdd_below h, smul_zero] }\nend\n\nend module\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/real/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7405155550118167}}
{"text": "/-\nCopyright (c) 2022 Alex J. Best. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex J. Best\n-/\nimport data.finsupp.order\nimport order.well_founded_set\n\n/-!\n# Partial well ordering on finsupps\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains the fact that finitely supported functions from a fintype are\npartially well ordered when the codomain is a linear order that is well ordered.\nIt is in a separate file for now so as to not add imports to the file `order.well_founded_set`.\n\n## Main statements\n\n* `finsupp.is_pwo` - finitely supported functions from a fintype are partially well ordered when\n  the codomain is a linear order that is well ordered\n\n## Tags\n\nDickson, order, partial well order\n-/\n\n/-- A version of **Dickson's lemma** any subset of functions `\u03c3 \u2192\u2080 \u03b1` is partially well\nordered, when `\u03c3` is `finite` and `\u03b1` is a linear well order.\nThis version uses finsupps on a finite type as it is intended for use with `mv_power_series`.\n-/\nlemma finsupp.is_pwo {\u03b1 \u03c3 : Type*} [has_zero \u03b1] [linear_order \u03b1] [is_well_order \u03b1 (<)] [finite \u03c3]\n  (S : set (\u03c3 \u2192\u2080 \u03b1)) : S.is_pwo :=\nfinsupp.equiv_fun_on_finite.symm_image_image S \u25b8\n  set.partially_well_ordered_on.image_of_monotone_on (pi.is_pwo _) (\u03bb a b ha hb, id)\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/finsupp/pwo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620468, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.740515554223927}}
{"text": "-- begin header\nimport tactic.linarith\nimport data.real.basic\nimport algebra.pi_instances\nimport data.set.function\nnoncomputable theory\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n-- We introduce the usual mathematical notation for absolute value\nlocal notation `|` x `|` := abs x\n-- end header\n\n/- Section\nLimits of sequences\n-/\n\n/- Sub-section\nBasic definitions\n-/\n\n/-\nIn this file, we introduce limits of sequences of real numbers.\n\nWe model a sequence $a\u2080, a\u2081, a\u2082, \\dots$ of real numbers as a function\nfrom $\u2115 := \\{0,1,2,\\dots\\}$ to $\u211d$, sending $n$ to $a_n$. So in the below\ndefinition of the limit of a sequence, $a : \u2115 \u2192 \u211d$ is the sequence.\n-/\n\n/- Definition\nA sequence $a$ converges to a real number $l$ if, for all positive\n$\u03b5$, there is some $N$ such that, for every $n \u2265 N$, $|a_n - l| < \u03b5$.\n-/\ndefinition is_limit (a : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < \u03b5\n\n/- Definition\nA sequence converges if and only if it has a limit.\n-/\ndefinition has_limit (a : \u2115 \u2192 \u211d) : Prop := \u2203 l : \u211d, is_limit a l\n\n/-\nThe difference between the above definition and the preceding one is that we\ndon't specify the limit, we just claim that it exists.\n-/\n\n/- Sub-section\nBasic lemmas\n-/\n\n/- Lemma\nThe constant sequence with value $a$ converges to $a$.\n-/\nlemma tendsto_const (a : \u211d) : is_limit (\u03bb n, a) a :=\nbegin\n  -- Let $\u03b5$ be any positive real number.\n  intros \u03b5 \u03b5pos,\n  -- We choose $N = 0$ in the definition of a limit,\n  use 0,\n  -- and observe that, for every $n \u2265 N$, |a - a| < \u03b5\n  intros n _,\n  simpa [sub_self] using \u03b5pos\nend\n\n/-\nWe will need an easy reformulation of the limit definition\n-/\n/- Lemma\nA sequence $a_n$ converges to a number $l$ if and only if the sequence\n$a_n - l$ converges to zero.\n-/\nlemma tendsto_iff_sub_tendsto_zero {a : \u2115 \u2192 \u211d} {l : \u211d} :\n  is_limit (\u03bb n, a n - l) 0 \u2194 is_limit a l :=\nbegin\n  -- We need to prove both implications, but both proofs are the same.\n  split ; \n  { -- We assume the premise, and consider any positive $\u03b5$.\n    intros h \u03b5 \u03b5pos,\n    -- By the premise specialized to our $\u03b5$, we get some $N$,\n    rcases h \u03b5 \u03b5pos with \u27e8N, H\u27e9,\n    -- and use that $N$ to prove the other condition\n    use N,\n    -- which is immediate.\n    intros n hn,\n    simpa using H n hn }\nend\n\n/- \nIn the definition of a limit, the final \u03b5 can be replaced \nby a constant multiple of \u03b5. We could assume this constant is positive\nbut we don't want to deal with this when applying the lemma.\n-/\n/- Lemma\nLet $a$ be a sequence. In order to prove that $a$ converges to some limit \n$l$, it is sufficient to find some number $K$ such that,\nfor all $\u03b5 > 0$, there is some $N$ such that, for all $n \u2265 N$, \n$|a_n - l| < K\u03b5$.\n-/\nlemma tendsto_of_mul_eps (a : \u2115 \u2192 \u211d) (l : \u211d) (K : \u211d)\n  (h : \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < K*\u03b5) : is_limit a l :=\nbegin\n  -- Let $\u03b5$ be any positive number.\n  intros \u03b5 \u03b5pos,\n  -- $K$ is either non positive or positive\n  cases le_or_gt K 0 with Knonpos Kpos,\n  { -- If $K$ is non positive then our assumed bound quickly\n    -- gives a contradiction. \n    exfalso,\n    -- Indeed we can apply our assumption to $\u03b5 = 1$ to get $N$ such that\n    -- for all $n \u2265 N$, $|a n - l| < K * 1$ \n    rcases h 1 (by linarith) with \u27e8N, H\u27e9,\n    -- in particular this holds when $n = N$\n    specialize H N (by linarith),\n    -- but $|a N - l| \u2265 0$ so we get a contradiction.\n    have : |a N - l| \u2265 0, from abs_nonneg _,\n    linarith },\n  { -- Now assume $K$ is positive. Our assumption gives $N$ such that,\n    -- for all $n \u2265 N$, $|a n - l| < K * (\u03b5 / K)$\n    rcases h (\u03b5/K) (div_pos \u03b5pos Kpos) with \u27e8N, H\u27e9,\n    -- we can simplify that $K (\u03b5 / K)$ and we are done.\n    rw mul_div_cancel' _ (ne_of_gt Kpos) at H,\n    tauto }\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1P1-lean", "sha": "3723468cc50f8bebd00a9811caf25224a578de17", "save_path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean", "path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean/M1P1-lean-3723468cc50f8bebd00a9811caf25224a578de17/src/lean_format_tests/patrick.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.7405155519464505}}
{"text": "/- Problem 1: Programming in Lean -/\n\n/-\nDefine the following list functions. Example uses are given via\nexample. Once you have defined the function (replaced the _ with\nan implementation), the examples will work (the red highlighting\nwill go away).\n-/\n\n-- part p1-a\ndef nonzeros : List Nat -> List Nat := _\nexample : nonzeros [0,1,0,2,3,0,0] = [1,2,3] := by rfl\n\ndef oddmembers : List Nat -> List Nat := _\nexample : oddmembers [0,1,0,2,3,0,0] = [1,3] := by rfl\n\ndef countoddmembers : List Nat -> Nat := _\nexample : countoddmembers [1,0,3,1,4,5] = 4 := by rfl\nexample : countoddmembers [0,2,4] = 0 := by rfl\nexample : countoddmembers [] = 0 := by rfl\n\n-- part p1-a\n\n\n/- A bag (or multiset) is like a set, except that each element\ncan appear multiple times rather than just once. One possible\nrepresentation for a bag of numbers is as a list.\n-/\n\n-- part p1-b\ndef Bag := List Nat\n-- part p1-b\n\n/- Complete the following definitions for the functions count,\nunion, add, and member for bags.\n-/\n\n-- part p1-c\ndef count : Nat -> Bag -> Nat := _\nexample : count 1 [1,2,3,1,4,1] = 3 := by rfl\nexample : count 6 [1,2,3,1,4,1] = 0 := by rfl\n\ndef union : Bag -> Bag -> Bag := _\nexample : count 1 (union [1,2,3] [1,4,1]) = 3 := by rfl\n\ndef add : Nat -> Bag -> Bag := _\nexample : count 1 (add 1 [1,4,1]) = 3 := by rfl\nexample : count 5 (add 1 [1,4,1]) = 0 := by rfl\n\n\ndef member : Nat -> Bag -> Bool := _\nexample : member 1 [1,4,1] = true := by rfl\nexample : member 2 [1,4,1] = false := by rfl\n\ndef remove_one : Nat -> Bag -> Bag := _\nexample : count 5 (remove_one 5 [2,1,5,4,1]) = 0 := by rfl\nexample : count 5 (remove_one 5 [2,1,4,1]) = 0 := by rfl\nexample : count 4 (remove_one 5 [2,1,4,5,1,4]) = 2 := by rfl\nexample : count 5 (remove_one 5 [2,1,5,4,5,1,4]) = 1 := by rfl\n\ndef remove_all : Nat -> Bag -> Bag := _\nexample : count 5 (remove_all 5 [2,1,5,4,1]) = 0 := by rfl\nexample : count 5 (remove_all 5 [2,1,4,1]) = 0 := by rfl\nexample : count 4 (remove_all 5 [2,1,4,5,1,4]) = 2 := by rfl\nexample : count 5 (remove_all 5 [2,1,5,4,5,1,4,5,1,4]) = 0 := by rfl\n\ndef subset : Bag -> Bag -> Bool := _\nexample : subset [1,2] [2,1,4,1] = true := by rfl\nexample : subset [1,2,2] [2,1,4,1] = false := by rfl\n\n-- part p1-c\n\n/- Proofs in minimal propositional logic -/\n\n-- part p1-d\n\nvariable (P Q R S : Prop)\n\ntheorem t1 : P -> P := _\n\ntheorem t2 : P -> Q -> P := _\n\ntheorem t3 : (P -> Q) -> (Q -> R) -> P -> R := _\n\ntheorem t4 : P -> Q -> (Q -> P -> R) -> R := _\n\ntheorem t5 : (P -> Q) -> (P -> R) -> (R -> Q -> S) -> P -> S := _\n\ntheorem t6 : (P -> Q -> R) -> (P -> Q) -> P -> R := _\n\n-- part p1-d\n\n/- Proofs in propositional logic -/\n\n-- part p1-e\n\ntheorem p1 : P \u2227 Q -> Q \u2227 P := _\n\ntheorem p2 : P \u2227 Q -> P := _\n\ntheorem p3 : P \u2227 Q -> (Q -> R) -> R \u2227 P := _\n\ntheorem p4 : P \u2228 Q -> (P -> R) -> (Q -> R) -> R := _\n\ntheorem p5 : P \u2228 Q -> (P -> R) -> R \u2228 Q := _\n\ntheorem p6 : \u00ac Q -> (R -> Q) -> (R \u2228 \u00ac S) -> S -> False := _\n\n-- part p1-e\n", "meta": {"author": "logiccomp", "repo": "s23-hw5", "sha": "22a81c565f0b5fc4eb3dc7949e74c8ef7cf96937", "save_path": "github-repos/lean/logiccomp-s23-hw5", "path": "github-repos/lean/logiccomp-s23-hw5/s23-hw5-22a81c565f0b5fc4eb3dc7949e74c8ef7cf96937/hw5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7405155513878556}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport linear_algebra.matrix.determinant\nimport data.mv_polynomial.basic\nimport data.mv_polynomial.comm_ring\n\n/-!\n# Matrices of multivariate polynomials\n\nIn this file, we prove results about matrices over an mv_polynomial ring.\nIn particular, we provide `matrix.mv_polynomial_X` which associates every entry of a matrix with a\nunique variable.\n\n## Tags\n\nmatrix determinant, multivariate polynomial\n-/\nvariables {m n R S : Type*}\n\nnamespace matrix\n\nvariables (m n R)\n\n/-- The matrix with variable `X (i,j)` at location `(i,j)`. -/\n@[simp] noncomputable def mv_polynomial_X [comm_semiring R] : matrix m n (mv_polynomial (m \u00d7 n) R)\n| i j := mv_polynomial.X (i, j)\n\nvariables {m n R S}\n\n/-- Any matrix `A` can be expressed as the evaluation of `matrix.mv_polynomial_X`.\n\nThis is of particular use when `mv_polynomial (m \u00d7 n) R` is an integral domain but `S` is\nnot, as if the `mv_polynomial.eval\u2082` can be pulled to the outside of a goal, it can be solved in\nunder cancellative assumptions. -/\nlemma mv_polynomial_X_map_eval\u2082 [comm_semiring R] [comm_semiring S]\n  (f : R \u2192+* S) (A : matrix m n S) :\n  (mv_polynomial_X m n R).map (mv_polynomial.eval\u2082 f $ \u03bb p : m \u00d7 n, A p.1 p.2) = A :=\next $ \u03bb i j, mv_polynomial.eval\u2082_X _ (\u03bb p : m \u00d7 n, A p.1 p.2) (i, j)\n\n/-- A variant of `matrix.mv_polynomial_X_map_eval\u2082` with a bundled `ring_hom` on the LHS. -/\nlemma mv_polynomial_X_map_matrix_eval [fintype m] [decidable_eq m]\n  [comm_semiring R] (A : matrix m m R) :\n  (mv_polynomial.eval $ \u03bb p : m \u00d7 m, A p.1 p.2).map_matrix (mv_polynomial_X m m R) = A :=\nmv_polynomial_X_map_eval\u2082 _ A\n\nvariables (R)\n\n/-- A variant of `matrix.mv_polynomial_X_map_eval\u2082` with a bundled `alg_hom` on the LHS. -/\nlemma mv_polynomial_X_map_matrix_aeval [fintype m] [decidable_eq m]\n  [comm_semiring R] [comm_semiring S] [algebra R S] (A : matrix m m S) :\n  (mv_polynomial.aeval $ \u03bb p : m \u00d7 m, A p.1 p.2).map_matrix (mv_polynomial_X m m R) = A :=\nmv_polynomial_X_map_eval\u2082 _ A\n\nvariables (m R)\n\n/-- In a nontrivial ring, `matrix.mv_polynomial_X m m R` has non-zero determinant. -/\nlemma det_mv_polynomial_X_ne_zero [decidable_eq m] [fintype m] [comm_ring R] [nontrivial R] :\n  det (mv_polynomial_X m m R) \u2260 0 :=\nbegin\n  intro h_det,\n  have := congr_arg matrix.det (mv_polynomial_X_map_matrix_eval (1 : matrix m m R)),\n  rw [det_one, \u2190ring_hom.map_det, h_det, ring_hom.map_zero] at this,\n  exact zero_ne_one this,\nend\n\nend matrix\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/matrix/mv_polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.740515549668974}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module algebra.module.submodule.pointwise\n! leanprover-community/mathlib commit 48085f140e684306f9e7da907cd5932056d1aded\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.GroupTheory.Subgroup.Pointwise\nimport Mathlib.LinearAlgebra.Span\n\n/-! # Pointwise instances on `Submodule`s\n\nThis file provides:\n\n* `Submodule.pointwiseNeg`\n\nand the actions\n\n* `Submodule.pointwiseDistribMulAction`\n* `Submodule.pointwiseMulActionWithZero`\n\nwhich matches the action of `Set.mulActionSet`.\n\nThese actions are available in the `Pointwise` locale.\n\n## Implementation notes\n\nMost of the lemmas in this file are direct copies of lemmas from\n`GroupTheory/Submonoid/Pointwise.lean`.\n-/\n\n\nvariable {\u03b1 : Type _} {R : Type _} {M : Type _}\n\nopen Pointwise\n\nnamespace Submodule\n\nsection Neg\n\nsection Semiring\n\nvariable [Semiring R] [AddCommGroup M] [Module R M]\n\n/-- The submodule with every element negated. Note if `R` is a ring and not just a semiring, this\nis a no-op, as shown by `Submodule.neg_eq_self`.\n\nRecall that When `R` is the semiring corresponding to the nonnegative elements of `R'`,\n`Submodule R' M` is the type of cones of `M`. This instance reflects such cones about `0`.\n\nThis is available as an instance in the `Pointwise` locale. -/\nprotected def pointwiseNeg : Neg (Submodule R M)\n    where neg p :=\n    { -p.toAddSubmonoid with\n      carrier := -(p : Set M)\n      smul_mem' := fun r m hm => Set.mem_neg.2 <| smul_neg r m \u25b8 p.smul_mem r <| Set.mem_neg.1 hm }\n#align submodule.has_pointwise_neg Submodule.pointwiseNeg\n\nscoped[Pointwise] attribute [instance] Submodule.pointwiseNeg\n\nopen Pointwise\n\n@[simp]\ntheorem coe_set_neg (S : Submodule R M) : \u2191(-S) = -(S : Set M) :=\n  rfl\n#align submodule.coe_set_neg Submodule.coe_set_neg\n\n@[simp]\ntheorem neg_toAddSubmonoid (S : Submodule R M) : (-S).toAddSubmonoid = -S.toAddSubmonoid :=\n  rfl\n#align submodule.neg_to_add_submonoid Submodule.neg_toAddSubmonoid\n\n@[simp]\ntheorem mem_neg {g : M} {S : Submodule R M} : g \u2208 -S \u2194 -g \u2208 S :=\n  Iff.rfl\n#align submodule.mem_neg Submodule.mem_neg\n\n/-- `Submodule.pointwiseNeg` is involutive.\n\nThis is available as an instance in the `Pointwise` locale. -/\nprotected def involutivePointwiseNeg : InvolutiveNeg (Submodule R M)\n    where\n  neg := Neg.neg\n  neg_neg _S := SetLike.coe_injective <| neg_neg _\n#align submodule.has_involutive_pointwise_neg Submodule.involutivePointwiseNeg\n\nscoped[Pointwise] attribute [instance] Submodule.involutivePointwiseNeg\n\n@[simp]\ntheorem neg_le_neg (S T : Submodule R M) : -S \u2264 -T \u2194 S \u2264 T :=\n  SetLike.coe_subset_coe.symm.trans Set.neg_subset_neg\n#align submodule.neg_le_neg Submodule.neg_le_neg\n\ntheorem neg_le (S T : Submodule R M) : -S \u2264 T \u2194 S \u2264 -T :=\n  SetLike.coe_subset_coe.symm.trans Set.neg_subset\n#align submodule.neg_le Submodule.neg_le\n\n/-- `Submodule.pointwiseNeg` as an order isomorphism. -/\ndef negOrderIso : Submodule R M \u2243o Submodule R M\n    where\n  toEquiv := Equiv.neg _\n  map_rel_iff' := @neg_le_neg _ _ _ _ _\n#align submodule.neg_order_iso Submodule.negOrderIso\n\ntheorem closure_neg (s : Set M) : span R (-s) = -span R s := by\n  apply le_antisymm\n  \u00b7 rw [span_le, coe_set_neg, \u2190 Set.neg_subset, neg_neg]\n    exact subset_span\n  \u00b7 rw [neg_le, span_le, coe_set_neg, \u2190 Set.neg_subset]\n    exact subset_span\n#align submodule.closure_neg Submodule.closure_neg\n\n@[simp]\ntheorem neg_inf (S T : Submodule R M) : -(S \u2293 T) = -S \u2293 -T :=\n  SetLike.coe_injective Set.inter_neg\n#align submodule.neg_inf Submodule.neg_inf\n\n@[simp]\ntheorem neg_sup (S T : Submodule R M) : -(S \u2294 T) = -S \u2294 -T :=\n  (negOrderIso : Submodule R M \u2243o Submodule R M).map_sup S T\n#align submodule.neg_sup Submodule.neg_sup\n\n@[simp]\ntheorem neg_bot : -(\u22a5 : Submodule R M) = \u22a5 :=\n  SetLike.coe_injective <| (Set.neg_singleton 0).trans <| congr_arg _ neg_zero\n#align submodule.neg_bot Submodule.neg_bot\n\n@[simp]\ntheorem neg_top : -(\u22a4 : Submodule R M) = \u22a4 :=\n  SetLike.coe_injective <| Set.neg_univ\n#align submodule.neg_top Submodule.neg_top\n\n@[simp]\ntheorem neg_inf\u1d62 {\u03b9 : Sort _} (S : \u03b9 \u2192 Submodule R M) : (-\u2a05 i, S i) = \u2a05 i, -S i :=\n  (negOrderIso : Submodule R M \u2243o Submodule R M).map_inf\u1d62 _\n#align submodule.neg_infi Submodule.neg_inf\u1d62\n\n@[simp]\ntheorem neg_sup\u1d62 {\u03b9 : Sort _} (S : \u03b9 \u2192 Submodule R M) : (-\u2a06 i, S i) = \u2a06 i, -S i :=\n  (negOrderIso : Submodule R M \u2243o Submodule R M).map_sup\u1d62 _\n#align submodule.neg_supr Submodule.neg_sup\u1d62\n\nend Semiring\n\nopen Pointwise\n\n@[simp]\ntheorem neg_eq_self [Ring R] [AddCommGroup M] [Module R M] (p : Submodule R M) : -p = p :=\n  ext fun _ => p.neg_mem_iff\n#align submodule.neg_eq_self Submodule.neg_eq_self\n\nend Neg\n\nvariable [Semiring R] [AddCommMonoid M] [Module R M]\n\ninstance pointwiseAddCommMonoid : AddCommMonoid (Submodule R M)\n    where\n  add := (\u00b7 \u2294 \u00b7)\n  add_assoc _ _ _ := sup_assoc\n  zero := \u22a5\n  zero_add _ := bot_sup_eq\n  add_zero _ := sup_bot_eq\n  add_comm _ _ := sup_comm\n#align submodule.pointwise_add_comm_monoid Submodule.pointwiseAddCommMonoid\n\n@[simp]\ntheorem add_eq_sup (p q : Submodule R M) : p + q = p \u2294 q :=\n  rfl\n#align submodule.add_eq_sup Submodule.add_eq_sup\n\n@[simp]\ntheorem zero_eq_bot : (0 : Submodule R M) = \u22a5 :=\n  rfl\n#align submodule.zero_eq_bot Submodule.zero_eq_bot\n\ninstance : CanonicallyOrderedAddMonoid (Submodule R M) :=\n  { Submodule.pointwiseAddCommMonoid,\n    Submodule.completeLattice with\n    zero := 0\n    bot := \u22a5\n    add := (\u00b7 + \u00b7)\n    add_le_add_left := fun _a _b => sup_le_sup_left\n    exists_add_of_le := @fun _a b h => \u27e8b, (sup_eq_right.2 h).symm\u27e9\n    le_self_add := fun _a _b => le_sup_left }\n\nsection\n\nvariable [Monoid \u03b1] [DistribMulAction \u03b1 M] [SMulCommClass \u03b1 R M]\n\n/-- The action on a submodule corresponding to applying the action to every element.\n\nThis is available as an instance in the `Pointwise` locale. -/\nprotected def pointwiseDistribMulAction : DistribMulAction \u03b1 (Submodule R M)\n    where\n  smul a S := S.map (DistribMulAction.toLinearMap R M a : M \u2192\u2097[R] M)\n  one_smul S :=\n    (congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| one_smul \u03b1)).trans S.map_id\n  mul_smul _a\u2081 _a\u2082 S :=\n    (congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| mul_smul _ _)).trans\n      (S.map_comp _ _)\n  smul_zero _a := map_bot _\n  smul_add _a _S\u2081 _S\u2082 := map_sup _ _ _\n#align submodule.pointwise_distrib_mul_action Submodule.pointwiseDistribMulAction\n\nscoped[Pointwise] attribute [instance] Submodule.pointwiseDistribMulAction\n\nopen Pointwise\n\n@[simp]\ntheorem coe_pointwise_smul (a : \u03b1) (S : Submodule R M) : \u2191(a \u2022 S) = a \u2022 (S : Set M) :=\n  rfl\n#align submodule.coe_pointwise_smul Submodule.coe_pointwise_smul\n\n@[simp]\ntheorem pointwise_smul_toAddSubmonoid (a : \u03b1) (S : Submodule R M) :\n    (a \u2022 S).toAddSubmonoid = a \u2022 S.toAddSubmonoid :=\n  rfl\n#align submodule.pointwise_smul_to_add_submonoid Submodule.pointwise_smul_toAddSubmonoid\n\n@[simp]\ntheorem pointwise_smul_toAddSubgroup {R M : Type _} [Ring R] [AddCommGroup M] [DistribMulAction \u03b1 M]\n    [Module R M] [SMulCommClass \u03b1 R M] (a : \u03b1) (S : Submodule R M) :\n    (a \u2022 S).toAddSubgroup = a \u2022 S.toAddSubgroup :=\n  rfl\n#align submodule.pointwise_smul_to_add_subgroup Submodule.pointwise_smul_toAddSubgroup\n\ntheorem smul_mem_pointwise_smul (m : M) (a : \u03b1) (S : Submodule R M) : m \u2208 S \u2192 a \u2022 m \u2208 a \u2022 S :=\n  (Set.smul_mem_smul_set : _ \u2192 _ \u2208 a \u2022 (S : Set M))\n#align submodule.smul_mem_pointwise_smul Submodule.smul_mem_pointwise_smul\n\n/-- See also `Submodule.smul_bot`. -/\n@[simp]\ntheorem smul_bot' (a : \u03b1) : a \u2022 (\u22a5 : Submodule R M) = \u22a5 :=\n  map_bot _\n#align submodule.smul_bot' Submodule.smul_bot'\n\n/-- See also `Submodule.smul_sup`. -/\ntheorem smul_sup' (a : \u03b1) (S T : Submodule R M) : a \u2022 (S \u2294 T) = a \u2022 S \u2294 a \u2022 T :=\n  map_sup _ _ _\n#align submodule.smul_sup' Submodule.smul_sup'\n\ntheorem smul_span (a : \u03b1) (s : Set M) : a \u2022 span R s = span R (a \u2022 s) :=\n  map_span _ _\n#align submodule.smul_span Submodule.smul_span\n\ntheorem span_smul (a : \u03b1) (s : Set M) : span R (a \u2022 s) = a \u2022 span R s :=\n  Eq.symm (span_image _).symm\n#align submodule.span_smul Submodule.span_smul\n\ninstance pointwiseCentralScalar [DistribMulAction \u03b1\u1d50\u1d52\u1d56 M] [SMulCommClass \u03b1\u1d50\u1d52\u1d56 R M]\n    [IsCentralScalar \u03b1 M] : IsCentralScalar \u03b1 (Submodule R M) :=\n  \u27e8fun _a S => (congr_arg fun f : Module.End R M => S.map f) <| LinearMap.ext <| op_smul_eq_smul _\u27e9\n#align submodule.pointwise_central_scalar Submodule.pointwiseCentralScalar\n\n@[simp]\ntheorem smul_le_self_of_tower {\u03b1 : Type _} [Semiring \u03b1] [Module \u03b1 R] [Module \u03b1 M]\n    [SMulCommClass \u03b1 R M] [IsScalarTower \u03b1 R M] (a : \u03b1) (S : Submodule R M) : a \u2022 S \u2264 S := by\n  rintro y \u27e8x, hx, rfl\u27e9\n  exact smul_of_tower_mem _ a hx\n#align submodule.smul_le_self_of_tower Submodule.smul_le_self_of_tower\n\nend\n\nsection\n\nvariable [Semiring \u03b1] [Module \u03b1 M] [SMulCommClass \u03b1 R M]\n\n/-- The action on a submodule corresponding to applying the action to every element.\n\nThis is available as an instance in the `Pointwise` locale.\n\nThis is a stronger version of `Submodule.pointwiseDistribMulAction`. Note that `add_smul` does\nnot hold so this cannot be stated as a `Module`. -/\nprotected def pointwiseMulActionWithZero : MulActionWithZero \u03b1 (Submodule R M) :=\n  { Submodule.pointwiseDistribMulAction with\n    zero_smul := fun S =>\n      (congr_arg (fun f : M \u2192\u2097[R] M => S.map f) (LinearMap.ext <| zero_smul \u03b1)).trans S.map_zero }\n#align submodule.pointwise_mul_action_with_zero Submodule.pointwiseMulActionWithZero\n\nscoped[Pointwise] attribute [instance] Submodule.pointwiseMulActionWithZero\n\nend\n\nend Submodule\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Module/Submodule/Pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7405030189957613}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\n\nimport data.polynomial.basic\nimport data.finset.nat_antidiagonal\nimport data.nat.choose.sum\n\n/-!\n# Theory of univariate polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe theorems include formulas for computing coefficients, such as\n`coeff_add`, `coeff_sum`, `coeff_mul`\n\n-/\n\nnoncomputable theory\n\nopen finsupp finset add_monoid_algebra\nopen_locale big_operators polynomial\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b : R} {n m : \u2115}\n\nvariables [semiring R] {p q r : R[X]}\n\nsection coeff\n\nlemma coeff_one (n : \u2115) : coeff (1 : R[X]) n = if 0 = n then 1 else 0 :=\ncoeff_monomial\n\n@[simp]\nlemma coeff_add (p q : R[X]) (n : \u2115) : coeff (p + q) n = coeff p n + coeff q n :=\nby { rcases p, rcases q, simp_rw [\u2190of_finsupp_add, coeff], exact finsupp.add_apply _ _ _ }\n\n@[simp] lemma coeff_bit0 (p : R[X]) (n : \u2115) : coeff (bit0 p) n = bit0 (coeff p n) := by simp [bit0]\n\n@[simp] lemma coeff_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) (n : \u2115) :\n  coeff (r \u2022 p) n = r \u2022 coeff p n :=\nby { rcases p, simp_rw [\u2190of_finsupp_smul, coeff], exact finsupp.smul_apply _ _ _ }\n\nlemma support_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) :\n  support (r \u2022 p) \u2286 support p :=\nbegin\n  assume i hi,\n  simp [mem_support_iff] at hi \u22a2,\n  contrapose! hi,\n  simp [hi]\nend\n\n/-- `polynomial.sum` as a linear map. -/\n@[simps] def lsum {R A M : Type*} [semiring R] [semiring A] [add_comm_monoid M]\n  [module R A] [module R M] (f : \u2115 \u2192 A \u2192\u2097[R] M) :\n  A[X] \u2192\u2097[R] M :=\n{ to_fun := \u03bb p, p.sum (\u03bb n r, f n r),\n  map_add' := \u03bb p q, sum_add_index p q _ (\u03bb n, (f n).map_zero) (\u03bb n _ _, (f n).map_add _ _),\n  map_smul' := \u03bb c p,\n  begin\n    rw [sum_eq_of_subset _ (\u03bb n r, f n r) (\u03bb n, (f n).map_zero) _ (support_smul c p)],\n    simp only [sum_def, finset.smul_sum, coeff_smul, linear_map.map_smul, ring_hom.id_apply]\n  end }\n\nvariable (R)\n/-- The nth coefficient, as a linear map. -/\ndef lcoeff (n : \u2115) : R[X] \u2192\u2097[R] R :=\n{ to_fun := \u03bb p, coeff p n,\n  map_add' := \u03bb p q, coeff_add p q n,\n  map_smul' := \u03bb r p, coeff_smul r p n }\n\nvariable {R}\n\n@[simp] lemma lcoeff_apply (n : \u2115) (f : R[X]) : lcoeff R n f = coeff f n := rfl\n\n@[simp] lemma finset_sum_coeff {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 R[X]) (n : \u2115) :\n  coeff (\u2211 b in s, f b) n = \u2211 b in s, coeff (f b) n :=\n(lcoeff R n).map_sum\n\nlemma coeff_sum [semiring S] (n : \u2115) (f : \u2115 \u2192 R \u2192 S[X]) :\n  coeff (p.sum f) n = p.sum (\u03bb a b, coeff (f a b) n) :=\nby { rcases p, simp [polynomial.sum, support, coeff] }\n\n/-- Decomposes the coefficient of the product `p * q` as a sum\nover `nat.antidiagonal`. A version which sums over `range (n + 1)` can be obtained\nby using `finset.nat.sum_antidiagonal_eq_sum_range_succ`. -/\nlemma coeff_mul (p q : R[X]) (n : \u2115) :\n  coeff (p * q) n = \u2211 x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 :=\nbegin\n  rcases p, rcases q,\n  simp_rw [\u2190of_finsupp_mul, coeff],\n  exact add_monoid_algebra.mul_apply_antidiagonal p q n _ (\u03bb x, nat.mem_antidiagonal)\nend\n\n@[simp] lemma mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 :=\nby simp [coeff_mul]\n\n/-- `constant_coeff p` returns the constant term of the polynomial `p`,\n  defined as `coeff p 0`. This is a ring homomorphism. -/\n@[simps] def constant_coeff : R[X] \u2192+* R :=\n{ to_fun := \u03bb p, coeff p 0,\n  map_one' := coeff_one_zero,\n  map_mul' := mul_coeff_zero,\n  map_zero' := coeff_zero 0,\n  map_add' :=  \u03bb p q, coeff_add p q 0 }\n\nlemma is_unit_C {x : R} : is_unit (C x) \u2194 is_unit x :=\n\u27e8\u03bb h, (congr_arg is_unit coeff_C_zero).mp (h.map $ @constant_coeff R _), \u03bb h, h.map C\u27e9\n\nlemma coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp\n\nlemma coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp\n\nlemma coeff_C_mul_X_pow (x : R) (k n : \u2115) : coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 :=\nby { rw [C_mul_X_pow_eq_monomial, coeff_monomial], congr' 1, simp [eq_comm] }\n\nlemma coeff_C_mul_X (x : R) (n : \u2115) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 :=\nby rw [\u2190 pow_one X, coeff_C_mul_X_pow]\n\n@[simp] lemma coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n :=\nbegin\n  rcases p,\n  simp_rw [\u2190monomial_zero_left, \u2190of_finsupp_single, \u2190of_finsupp_mul, coeff],\n  exact add_monoid_algebra.single_zero_mul_apply p a n\nend\n\nlemma C_mul' (a : R) (f : R[X]) : C a * f = a \u2022 f :=\nby { ext, rw [coeff_C_mul, coeff_smul, smul_eq_mul] }\n\n@[simp] lemma coeff_mul_C (p : R[X]) (n : \u2115) (a : R) :\n  coeff (p * C a) n = coeff p n * a :=\nbegin\n  rcases p,\n  simp_rw [\u2190monomial_zero_left, \u2190of_finsupp_single, \u2190of_finsupp_mul, coeff],\n  exact add_monoid_algebra.mul_single_zero_apply p a n\nend\n\nlemma coeff_X_pow (k n : \u2115) :\n  coeff (X^k : R[X]) n = if n = k then 1 else 0 :=\nby simp only [one_mul, ring_hom.map_one, \u2190 coeff_C_mul_X_pow]\n\n@[simp]\nlemma coeff_X_pow_self (n : \u2115) :\n  coeff (X^n : R[X]) n = 1 :=\nby simp [coeff_X_pow]\n\nsection fewnomials\n\nopen finset\n\nlemma support_binomial {k m : \u2115} (hkm : k \u2260 m) {x y : R} (hx : x \u2260 0) (hy : y \u2260 0) :\n  (C x * X ^ k + C y * X ^ m).support = {k, m} :=\nbegin\n  apply subset_antisymm (support_binomial' k m x y),\n  simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,\n    coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm,\n    mul_zero, zero_add, add_zero, ne.def, hx, hy, and_self, not_false_iff],\nend\n\nlemma support_trinomial {k m n : \u2115} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x \u2260 0)\n  (hy : y \u2260 0) (hz : z \u2260 0) : (C x * X ^ k + C y * X ^ m + C z * X ^ n).support = {k, m, n} :=\nbegin\n  apply subset_antisymm (support_trinomial' k m n x y z),\n  simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,\n    coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne,\n    if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne',\n    mul_zero, add_zero, zero_add, ne.def, hx, hy, hz, and_self, not_false_iff],\nend\n\nlemma card_support_binomial {k m : \u2115} (h : k \u2260 m) {x y : R} (hx : x \u2260 0) (hy : y \u2260 0) :\n  (C x * X ^ k + C y * X ^ m).support.card = 2 :=\nby rw [support_binomial h hx hy, card_insert_of_not_mem (mt mem_singleton.mp h), card_singleton]\n\nlemma card_support_trinomial {k m n : \u2115} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x \u2260 0)\n  (hy : y \u2260 0) (hz : z \u2260 0) : (C x * X ^ k + C y * X ^ m + C z * X ^ n).support.card = 3 :=\nby rw [support_trinomial hkm hmn hx hy hz, card_insert_of_not_mem\n  (mt mem_insert.mp (not_or hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))),\n  card_insert_of_not_mem (mt mem_singleton.mp hmn.ne), card_singleton]\n\nend fewnomials\n\n@[simp]\ntheorem coeff_mul_X_pow (p : R[X]) (n d : \u2115) :\n  coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=\nbegin\n  rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one],\n  { rintros \u27e8i,j\u27e9 h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,\n    rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },\n  { exact \u03bb h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }\nend\n\n@[simp]\ntheorem coeff_X_pow_mul (p : R[X]) (n d : \u2115) :\n  coeff (polynomial.X ^ n * p) (d + n) = coeff p d :=\nby rw [(commute_X_pow p n).eq, coeff_mul_X_pow]\n\nlemma coeff_mul_X_pow' (p : R[X]) (n d : \u2115) :\n  (p * X ^ n).coeff d = ite (n \u2264 d) (p.coeff (d - n)) 0 :=\nbegin\n  split_ifs,\n  { rw [\u2190 tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] },\n  { refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (\u03bb x hx, _)),\n    rw [coeff_X_pow, if_neg, mul_zero],\n    exact ((le_of_add_le_right (finset.nat.mem_antidiagonal.mp hx).le).trans_lt $ not_le.mp h).ne }\nend\n\nlemma coeff_X_pow_mul' (p : R[X]) (n d : \u2115) :\n  (X ^ n * p).coeff d = ite (n \u2264 d) (p.coeff (d - n)) 0 :=\nby rw [(commute_X_pow p n).eq, coeff_mul_X_pow']\n\n@[simp] theorem coeff_mul_X (p : R[X]) (n : \u2115) :\n  coeff (p * X) (n + 1) = coeff p n :=\nby simpa only [pow_one] using coeff_mul_X_pow p 1 n\n\n@[simp] theorem coeff_X_mul (p : R[X]) (n : \u2115) :\n  coeff (X * p) (n + 1) = coeff p n := by rw [(commute_X p).eq, coeff_mul_X]\n\ntheorem coeff_mul_monomial (p : R[X]) (n d : \u2115) (r : R) :\n  coeff (p * monomial n r) (d + n) = coeff p d * r :=\nby rw [\u2190 C_mul_X_pow_eq_monomial, \u2190X_pow_mul, \u2190mul_assoc, coeff_mul_C, coeff_mul_X_pow]\n\ntheorem coeff_monomial_mul (p : R[X]) (n d : \u2115) (r : R) :\n  coeff (monomial n r * p) (d + n) = r * coeff p d :=\nby rw [\u2190 C_mul_X_pow_eq_monomial, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow]\n\n-- This can already be proved by `simp`.\ntheorem coeff_mul_monomial_zero (p : R[X]) (d : \u2115) (r : R) :\n  coeff (p * monomial 0 r) d = coeff p d * r :=\ncoeff_mul_monomial p 0 d r\n\n-- This can already be proved by `simp`.\ntheorem coeff_monomial_zero_mul (p : R[X]) (d : \u2115) (r : R) :\n  coeff (monomial 0 r * p) d = r * coeff p d :=\ncoeff_monomial_mul p 0 d r\n\ntheorem mul_X_pow_eq_zero {p : R[X]} {n : \u2115}\n  (H : p * X ^ n = 0) : p = 0 :=\next $ \u03bb k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n)\n\nlemma mul_X_pow_injective (n : \u2115) : function.injective (\u03bb P : R[X], X ^ n * P) :=\nbegin\n  intros P Q hPQ,\n  simp only at hPQ,\n  ext i,\n  rw [\u2190 coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i]\nend\n\nlemma mul_X_injective : function.injective (\u03bb P : R[X], X * P) :=\npow_one (X : R[X]) \u25b8 mul_X_pow_injective 1\n\nlemma coeff_X_add_C_pow (r : R) (n k : \u2115) :\n  ((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) :=\nbegin\n  rw [(commute_X (C r : R[X])).add_pow, \u2190 lcoeff_apply, linear_map.map_sum],\n  simp only [one_pow, mul_one, lcoeff_apply, \u2190 C_eq_nat_cast, \u2190C_pow, coeff_mul_C, nat.cast_id],\n  rw [finset.sum_eq_single k, coeff_X_pow_self, one_mul],\n  { intros _ _ h,\n    simp [coeff_X_pow, h.symm] },\n  { simp only [coeff_X_pow_self, one_mul, not_lt, finset.mem_range],\n    intro h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero] }\nend\n\nlemma coeff_X_add_one_pow (R : Type*) [semiring R] (n k : \u2115) :\n  ((X + 1) ^ n).coeff k = (n.choose k : R) :=\nby rw [\u2190C_1, coeff_X_add_C_pow, one_pow, one_mul]\n\nlemma coeff_one_add_X_pow (R : Type*) [semiring R] (n k : \u2115) :\n  ((1 + X) ^ n).coeff k = (n.choose k : R) :=\nby rw [add_comm _ X, coeff_X_add_one_pow]\n\nlemma C_dvd_iff_dvd_coeff (r : R) (\u03c6 : R[X]) :\n  C r \u2223 \u03c6 \u2194 \u2200 i, r \u2223 \u03c6.coeff i :=\nbegin\n  split,\n  { rintros \u27e8\u03c6, rfl\u27e9 c, rw coeff_C_mul, apply dvd_mul_right },\n  { intro h,\n    choose c hc using h,\n    classical,\n    let c' : \u2115 \u2192 R := \u03bb i, if i \u2208 \u03c6.support then c i else 0,\n    let \u03c8 : R[X] := \u2211 i in \u03c6.support, monomial i (c' i),\n    use \u03c8,\n    ext i,\n    simp only [\u03c8, c', coeff_C_mul, mem_support_iff, coeff_monomial,\n               finset_sum_coeff, finset.sum_ite_eq'],\n    split_ifs with hi hi,\n    { rw hc },\n    { rw [not_not] at hi, rwa mul_zero } },\nend\n\nlemma coeff_bit0_mul (P Q : R[X]) (n : \u2115) :\n  coeff (bit0 P * Q) n = 2 * coeff (P * Q) n :=\nby simp [bit0, add_mul]\n\n\n\nlemma smul_eq_C_mul (a : R) : a \u2022 p = C a * p := by simp [ext_iff]\n\nlemma update_eq_add_sub_coeff {R : Type*} [ring R] (p : R[X]) (n : \u2115) (a : R) :\n  p.update n a = p + (polynomial.C (a - p.coeff n) * polynomial.X ^ n) :=\nbegin\n  ext,\n  rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow],\n  split_ifs with h;\n  simp [h]\nend\n\nend coeff\n\nsection cast\n\n@[simp] lemma nat_cast_coeff_zero {n : \u2115} {R : Type*} [semiring R] :\n  (n : R[X]).coeff 0 = n :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih], },\nend\n\n@[simp, norm_cast] theorem nat_cast_inj\n  {m n : \u2115} {R : Type*} [semiring R] [char_zero R] : (\u2191m : R[X]) = \u2191n \u2194 m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (\u03bb p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\n@[simp] lemma int_cast_coeff_zero {i : \u2124} {R : Type*} [ring R] :\n  (i : R[X]).coeff 0 = i :=\nby cases i; simp\n\n@[simp, norm_cast] theorem int_cast_inj\n  {m n : \u2124} {R : Type*} [ring R] [char_zero R] : (\u2191m : R[X]) = \u2191n \u2194 m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (\u03bb p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\nend cast\n\ninstance [char_zero R] : char_zero R[X] :=\n{ cast_injective := \u03bb x y, nat_cast_inj.mp }\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/coeff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7404988420671603}}
{"text": "import ..exercises.love02_backward_proofs_exercise_sheet\n\n\n/-! # LoVe Homework 3: Forward Proofs\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (6 points): Connectives and Quantifiers\n\n1.1 (2 points). We have proved or stated three of the six possible implications\nbetween `excluded_middle`, `peirce`, and `double_negation`. Prove the three\nmissing implications using structured proofs, exploiting the three theorems we\nalready have. -/\n\nnamespace backward_proofs\n\n#check peirce_of_em\n#check dn_of_peirce\n#check sorry_lemmas.em_of_dn\n\nlemma peirce_of_dn :\n  double_negation \u2192 peirce :=\nsorry\n\nlemma em_of_peirce :\n  peirce \u2192 excluded_middle :=\nsorry\n\nlemma dn_of_em :\n  excluded_middle \u2192 double_negation :=\nsorry\n\nend backward_proofs\n\n/-! 1.2 (4 points). Supply a structured proof of the commutativity of `\u2227` under\nan `\u2203` quantifier, using no other lemmas than the introduction and elimination\nrules for `\u2203`, `\u2227`, and `\u2194`. -/\n\nlemma exists_and_commute {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2203x, p x \u2227 q x) \u2194 (\u2203x, q x \u2227 p x) :=\nsorry\n\n\n/-! ## Question 2 (4 points): Logic Puzzles\n\nRecall the following tactical proof: -/\n\nlemma weak_peirce :\n  \u2200a b : Prop, ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nbegin\n  intros a b habaab,\n  apply habaab,\n  intro habaa,\n  apply habaa,\n  intro ha,\n  apply habaab,\n  intro haba,\n  apply ha\nend\n\n/-! 2.1 (1 point). Prove the same lemma again, this time by providing a proof\nterm.\n\nHint: There is an easy way. Anything goes! -/\n\nlemma weak_peirce\u2082 :\n  \u2200a b : Prop, ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\n/-! 2.2 (2 points). Prove the same lemma again, this time by providing a\nstructured proof, with `assume`s and `show`s. -/\n\nlemma weak_peirce\u2083 :\n  \u2200a b : Prop, ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\n/-! 2.3 (1 point). In a certain faraway village, there is only one barber for\nthe whole town. He shaves all those who do not shave themselves. Does the barber\nshave himself? \n\nShow that this premise implies `false`.\n-/\naxiom not_iff_not_self (P : Prop) : \u00ac (P \u2194 \u00ac P)\n\n\nexample (Q : Prop) : \u00ac (Q \u2194 \u00ac Q) :=\nnot_iff_not_self Q\n\nsection\n  variable Person : Type\n  variable shaves : Person \u2192 Person \u2192 Prop\n  variable barber : Person\n  variable h : \u2200 x, shaves barber x \u2194 \u00ac shaves x x\n  include h\n  -- Show the following:\n  example : false :=\n    sorry\nend\n\n/-! \nOptional extra challenge: we don't need `not_iff_not_self` to be an axiom. \nState it as a lemma and prove it! \nExtra extra challenge: prove it without using `classical.em` or `classical.by_contradiction`.\n-/\n\n/-! ## Question 3 (2 points): Calc Mode\nUse `calc` mode to prove that the difference of squares formula holds on the\nintegers. (In this particular problem, working on the integers is necessary, but in\npractice not much different from working on \u2115.)\nYou might find some or all of the following subtraction lemmas useful!\n-/\n#check mul_sub\n#check sub_add_eq_sub_sub\n#check sub_self\n#check add_sub_assoc\n#check mul_comm\n#check add_mul\n\nlemma difference_of_squares (a b : \u2124) :\n  (a + b) * (a - b) = a * a - b * b :=\n  sorry\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/homework/love03_forward_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7404988406465923}}
{"text": "import Mathlib.Tactic.Linarith\n\ndef hello := \"world\"\n\ndef a : \u2115 \u2192 \u2124 \n| 0 => 2\n| 1 => 5\n| n + 2 => 5 * a (n + 1) - 6 * a n \n\n#check Nat.two_step_induction\n\nlemma helper (n : \u2115) : a (n + 2) = 5 * a (n + 1) - 6 * a n := rfl\n\nlemma foo (n : \u2115) : a n = 2 ^ n + 3 ^ n := by \n  induction' n using Nat.two_step_induction with n h1 h2\n  . rfl\n  . rfl \n  simp [Nat.succ_eq_add_one] at *\n  calc\n    a (n + 2) \n      = (5 : \u2124) * (2 ^ (n + 1) + 3 ^ (n + 1)) - \n          6 * (2 ^ n + 3 ^ n) := by linarith [helper n]\n    _ = (2 : \u2124) ^ (n + 2) + 3 ^ (n + 2) := by ring\n\ndef odd (k : \u2124) : Prop := \u2203 a, k = 2 * a + 1\n\nlemma bar2 (n : \u2115) : odd (a (n + 1)) := by\n  induction' n with n h1 h2\n  . use 2\n    rfl\n  cases' h1 with k hk\n  use 5*k - 3*a n + 2\n  rw [helper]\n  linarith\n\nlemma bar (n : \u2115) : (n \u2265 1) \u2192 odd (a n) := by\n  induction' n using Nat.two_step_induction with n h1 h2\n  . norm_num\n  . intro h\n    use 2\n    rfl\n  simp only [Nat.succ_eq_add_one] at *\n\n/-\n    calc\n      a (n + 2) \n      -- = 5 * a (n + 1) - 6 * a n := helper n\n       = (5 : \u2124) * (2 ^ (n + 1) + 3 ^ (n + 1)) - \n        6 * (2 ^ n + 3 ^ n) := by linarith [helper n]\n      -- _ = (5 : \u2124) * (2 * 2^n + 3 * 3^n) - 6 * (2 ^ n + 3 ^ n) := by ring\n      -- _ = ((5*2 - 6) : \u2124) * 2^n + (5*3 - 6)*3^n := by ring\n      -- _ = (4 : \u2124) * 2^n + 9 * 3^n := by ring\n      _ = (2 : \u2124) ^ (n + 2) + 3 ^ (n + 2) := by ring\n\n-/\n\n\n", "meta": {"author": "robertylewis", "repo": "leanclass", "sha": "f609276675431388632d46619581bdb7c557be50", "save_path": "github-repos/lean/robertylewis-leanclass", "path": "github-repos/lean/robertylewis-leanclass/leanclass-f609276675431388632d46619581bdb7c557be50/BrownCs22.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7404988330964354}}
{"text": "import tactic\n\nlemma sub_diff\n  (m m' : \u2115)\n  (h : m < m')\n  : \u2203 s : \u2115, 0 < s \u2227 m' = m + s :=\nbegin\n  use m' - m,\n  split,\n  { omega, },\n  { exact (nat.add_sub_of_le (le_of_lt h)).symm }\nend\n\n-- 2\u00aa demostraci\u00f3n\nlemma nat.exists_eq_add_of_lt'\n  (m m' : \u2115)\n  (h : m < m')\n  : \u2203 s : \u2115, 0 < s \u2227 m' = m + s :=\nlet \u27e8k, hk\u27e9 := nat.exists_eq_add_of_lt h\nin \u27e8k.succ, k.zero_lt_succ, hk\u27e9\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/CNS_de_menor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.740498831208896}}
{"text": "/-\nCopyright (c) 2022 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky, Floris van Doorn\n\n! This file was ported from Lean 3 source module data.pnat.find\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Pnat.Basic\n\n/-!\n# Explicit least witnesses to existentials on positive natural numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nImplemented via calling out to `nat.find`.\n\n-/\n\n\nnamespace PNat\n\nvariable {p q : \u2115+ \u2192 Prop} [DecidablePred p] [DecidablePred q] (h : \u2203 n, p n)\n\n#print PNat.decidablePredExistsNat /-\ninstance decidablePredExistsNat : DecidablePred fun n' : \u2115 => \u2203 (n : \u2115+)(hn : n' = n), p n :=\n  fun n' =>\n  decidable_of_iff' (\u2203 h : 0 < n', p \u27e8n', h\u27e9) <|\n    Subtype.exists.trans <| by\n      simp_rw [Subtype.coe_mk, @exists_comm (_ < _) (_ = _), exists_prop, exists_eq_left']\n#align pnat.decidable_pred_exists_nat PNat.decidablePredExistsNat\n-/\n\ninclude h\n\n#print PNat.findX /-\n/-- The `pnat` version of `nat.find_x` -/\nprotected def findX : { n // p n \u2227 \u2200 m : \u2115+, m < n \u2192 \u00acp m } :=\n  by\n  have : \u2203 (n' : \u2115)(n : \u2115+)(hn' : n' = n), p n := Exists.elim h fun n hn => \u27e8n, n, rfl, hn\u27e9\n  have n := Nat.findX this\n  refine' \u27e8\u27e8n, _\u27e9, _, fun m hm pm => _\u27e9\n  \u00b7 obtain \u27e8n', hn', -\u27e9 := n.prop.1\n    rw [hn']\n    exact n'.prop\n  \u00b7 obtain \u27e8n', hn', pn'\u27e9 := n.prop.1\n    simpa [hn', Subtype.coe_eta] using pn'\n  \u00b7 exact n.prop.2 m hm \u27e8m, rfl, pm\u27e9\n#align pnat.find_x PNat.findX\n-/\n\n#print PNat.find /-\n/-- If `p` is a (decidable) predicate on `\u2115+` and `hp : \u2203 (n : \u2115+), p n` is a proof that\nthere exists some positive natural number satisfying `p`, then `pnat.find hp` is the\nsmallest positive natural number satisfying `p`. Note that `pnat.find` is protected,\nmeaning that you can't just write `find`, even if the `pnat` namespace is open.\n\nThe API for `pnat.find` is:\n\n* `pnat.find_spec` is the proof that `pnat.find hp` satisfies `p`.\n* `pnat.find_min` is the proof that if `m < pnat.find hp` then `m` does not satisfy `p`.\n* `pnat.find_min'` is the proof that if `m` does satisfy `p` then `pnat.find hp \u2264 m`.\n-/\nprotected def find : \u2115+ :=\n  PNat.findX h\n#align pnat.find PNat.find\n-/\n\n#print PNat.find_spec /-\nprotected theorem find_spec : p (PNat.find h) :=\n  (PNat.findX h).Prop.left\n#align pnat.find_spec PNat.find_spec\n-/\n\n#print PNat.find_min /-\nprotected theorem find_min : \u2200 {m : \u2115+}, m < PNat.find h \u2192 \u00acp m :=\n  (PNat.findX h).Prop.right\n#align pnat.find_min PNat.find_min\n-/\n\n#print PNat.find_min' /-\nprotected theorem find_min' {m : \u2115+} (hm : p m) : PNat.find h \u2264 m :=\n  le_of_not_lt fun l => PNat.find_min h l hm\n#align pnat.find_min' PNat.find_min'\n-/\n\nvariable {n m : \u2115+}\n\n#print PNat.find_eq_iff /-\ntheorem find_eq_iff : PNat.find h = m \u2194 p m \u2227 \u2200 n < m, \u00acp n :=\n  by\n  constructor\n  \u00b7 rintro rfl\n    exact \u27e8PNat.find_spec h, fun _ => PNat.find_min h\u27e9\n  \u00b7 rintro \u27e8hm, hlt\u27e9\n    exact le_antisymm (PNat.find_min' h hm) (not_lt.1 <| imp_not_comm.1 (hlt _) <| PNat.find_spec h)\n#align pnat.find_eq_iff PNat.find_eq_iff\n-/\n\n/- warning: pnat.find_lt_iff -> PNat.find_lt_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : PNat -> Prop} [_inst_1 : DecidablePred.{1} PNat p] (h : Exists.{1} PNat (fun (n : PNat) => p n)) (n : PNat), Iff (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) (PNat.find (fun (n : PNat) => p n) (fun (a : PNat) => _inst_1 a) h) n) (Exists.{1} PNat (fun (m : PNat) => Exists.{0} (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) m n) (fun (H : LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) m n) => p m)))\nbut is expected to have type\n  forall {p : PNat -> Prop} [_inst_1 : DecidablePred.{1} PNat p] (h : Exists.{1} PNat (fun (n : PNat) => p n)) (n : PNat), Iff (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) (PNat.find (fun (n : PNat) => p n) (fun (a : PNat) => _inst_1 a) h) n) (Exists.{1} PNat (fun (m : PNat) => And (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) m n) (p m)))\nCase conversion may be inaccurate. Consider using '#align pnat.find_lt_iff PNat.find_lt_iff\u2093'. -/\n@[simp]\ntheorem find_lt_iff (n : \u2115+) : PNat.find h < n \u2194 \u2203 m < n, p m :=\n  \u27e8fun h2 => \u27e8PNat.find h, h2, PNat.find_spec h\u27e9, fun \u27e8m, hmn, hm\u27e9 =>\n    (PNat.find_min' h hm).trans_lt hmn\u27e9\n#align pnat.find_lt_iff PNat.find_lt_iff\n\n/- warning: pnat.find_le_iff -> PNat.find_le_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : PNat -> Prop} [_inst_1 : DecidablePred.{1} PNat p] (h : Exists.{1} PNat (fun (n : PNat) => p n)) (n : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) (PNat.find (fun (n : PNat) => p n) (fun (a : PNat) => _inst_1 a) h) n) (Exists.{1} PNat (fun (m : PNat) => Exists.{0} (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) m n) (fun (H : LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) m n) => p m)))\nbut is expected to have type\n  forall {p : PNat -> Prop} [_inst_1 : DecidablePred.{1} PNat p] (h : Exists.{1} PNat (fun (n : PNat) => p n)) (n : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) (PNat.find (fun (n : PNat) => p n) (fun (a : PNat) => _inst_1 a) h) n) (Exists.{1} PNat (fun (m : PNat) => And (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) m n) (p m)))\nCase conversion may be inaccurate. Consider using '#align pnat.find_le_iff PNat.find_le_iff\u2093'. -/\n@[simp]\ntheorem find_le_iff (n : \u2115+) : PNat.find h \u2264 n \u2194 \u2203 m \u2264 n, p m := by\n  simp only [exists_prop, \u2190 lt_add_one_iff, find_lt_iff]\n#align pnat.find_le_iff PNat.find_le_iff\n\n#print PNat.le_find_iff /-\n@[simp]\ntheorem le_find_iff (n : \u2115+) : n \u2264 PNat.find h \u2194 \u2200 m < n, \u00acp m := by\n  simp_rw [\u2190 not_lt, find_lt_iff, not_exists]\n#align pnat.le_find_iff PNat.le_find_iff\n-/\n\n#print PNat.lt_find_iff /-\n@[simp]\ntheorem lt_find_iff (n : \u2115+) : n < PNat.find h \u2194 \u2200 m \u2264 n, \u00acp m := by\n  simp only [\u2190 add_one_le_iff, le_find_iff, add_le_add_iff_right]\n#align pnat.lt_find_iff PNat.lt_find_iff\n-/\n\n#print PNat.find_eq_one /-\n@[simp]\ntheorem find_eq_one : PNat.find h = 1 \u2194 p 1 := by simp [find_eq_iff]\n#align pnat.find_eq_one PNat.find_eq_one\n-/\n\n#print PNat.one_le_find /-\n@[simp]\ntheorem one_le_find : 1 < PNat.find h \u2194 \u00acp 1 :=\n  not_iff_not.mp <| by simp\n#align pnat.one_le_find PNat.one_le_find\n-/\n\n#print PNat.find_mono /-\ntheorem find_mono (h : \u2200 n, q n \u2192 p n) {hp : \u2203 n, p n} {hq : \u2203 n, q n} :\n    PNat.find hp \u2264 PNat.find hq :=\n  PNat.find_min' _ (h _ (PNat.find_spec hq))\n#align pnat.find_mono PNat.find_mono\n-/\n\n#print PNat.find_le /-\ntheorem find_le {h : \u2203 n, p n} (hn : p n) : PNat.find h \u2264 n :=\n  (PNat.find_le_iff _ _).2 \u27e8n, le_rfl, hn\u27e9\n#align pnat.find_le PNat.find_le\n-/\n\n/- warning: pnat.find_comp_succ -> PNat.find_comp_succ is a dubious translation:\nlean 3 declaration is\n  forall {p : PNat -> Prop} [_inst_1 : DecidablePred.{1} PNat p] (h : Exists.{1} PNat (fun (n : PNat) => p n)) (h\u2082 : Exists.{1} PNat (fun (n : PNat) => p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))))), (Not (p (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne))))) -> (Eq.{1} PNat (PNat.find (fun (n : PNat) => p n) (fun (a : PNat) => _inst_1 a) h) (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) (PNat.find (fun (n : PNat) => p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne))))) (fun (a : PNat) => _inst_1 (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) a (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne))))) h\u2082) (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))))\nbut is expected to have type\n  forall {p : PNat -> Prop} [_inst_1 : DecidablePred.{1} PNat p] (h : Exists.{1} PNat (fun (n : PNat) => p n)) (h\u2082 : Exists.{1} PNat (fun (n : PNat) => p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))), (Not (p (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))) -> (Eq.{1} PNat (PNat.find (fun (n : PNat) => p n) (fun (a : PNat) => _inst_1 a) h) (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) (PNat.find (fun (n : PNat) => p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))) (fun (a : PNat) => _inst_1 (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) a (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))) h\u2082) (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))\nCase conversion may be inaccurate. Consider using '#align pnat.find_comp_succ PNat.find_comp_succ\u2093'. -/\ntheorem find_comp_succ (h : \u2203 n, p n) (h\u2082 : \u2203 n, p (n + 1)) (h1 : \u00acp 1) :\n    PNat.find h = PNat.find h\u2082 + 1 :=\n  by\n  refine' (find_eq_iff _).2 \u27e8PNat.find_spec h\u2082, fun n => PNat.recOn n _ _\u27e9\n  \u00b7 simp [h1]\n  intro m IH hm\n  simp only [add_lt_add_iff_right, lt_find_iff] at hm\n  exact hm _ le_rfl\n#align pnat.find_comp_succ PNat.find_comp_succ\n\nend PNat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Pnat/Find.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7404983608573064}}
{"text": "import .love01_definitions_and_statements_demo\n\n\n/-! # LoVe Demo 2: Backward Proofs\n\nA __tactic__ operates on a proof goal and either proves it or creates new\nsubgoals. Tactics are a __backward__ proof mechanism: They start from the goal\nand work towards the available hypotheses and lemmas. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace backward_proofs\n\n\n/-! ## Tactic Mode\n\nSyntax of tactical proofs:\n\n    begin\n      _tactic\u2081_,\n      \u2026,\n      _tacticN_\n    end -/\n\nlemma fst_of_two_props :\n  \u2200a b : Prop, a \u2192 b \u2192 a :=\nbegin\n  intros a b,\n  intros ha hb,\n  apply ha\nend\n\n\n/-! ## Basic Tactics\n\n`intro`(`s`) moves `\u2200`-quantified variables, or the assumptions of\nimplications `\u2192`, from the goal's conclusion (after `\u22a2`) into the goal's\nhypotheses (before `\u22a2`).\n\n`apply` matches the goal's conclusion with the conclusion of the specified lemma\nand adds the lemma's hypotheses as new goals. -/\n\nlemma fst_of_two_props\u2082 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nbegin\n  apply ha\nend\n\n/-! Terminal tactic syntax:\n\n    by _tactic_\n\nabbreviates\n\n    begin\n      _tactic_\n    end -/\n\nlemma fst_of_two_props\u2083 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nby apply ha\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  apply hbc,\n  apply hab,\n  apply ha\nend\n\n/-! `exact` matches the goal's conclusion with the specified lemma, closing the\ngoal. We can often use `apply` in such situations, but `exact` communicates our\nintentions better. -/\n\nlemma fst_of_two_props\u2084 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nby exact ha\n\n/-! `assumption` finds a hypothesis from the local context that matches the\ngoal's conclusion and applies it to prove the goal. -/\n\nlemma fst_of_two_props\u2085 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nby assumption\n\n/-! ## Reasoning about Logical Connectives and Quantifiers\n\nIntroduction rules: \n\nThe relevant symbol appears in the *conclusion* of the statement.\n(On the right side of the ->)\n\nWe apply these rules when the symbol appears in our *goal*.\n-/\n\n#check true.intro\n#check not.intro\n#check and.intro\n#check or.intro_left\n#check or.intro_right\n#check iff.intro\n#check exists.intro\n\n/-! Elimination rules: \n\nThe relevant symbol appears in a *hypothesis* of the statement.\n(On the left side of the ->)\n\nWe apply these rules when the symbol appears in our *context*.\n-/\n\n#check false.elim\n#check and.elim_left\n#check and.elim_right\n#check or.elim\n#check iff.elim_left\n#check iff.elim_right\n#check exists.elim\n\n/-! Definition of `\u00ac` and related lemmas: -/\n\n#print not\n#check not_def\n#check classical.em\n#check classical.by_contradiction\n\nlemma and_swap (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intro hab,\n  apply and.intro,\n  apply and.elim_right,\n  exact hab,\n  apply and.elim_left,\n  exact hab\nend\n\n/-! The `{ \u2026 }` combinator focuses on the first subgoal. The tactic inside must\nfully prove it. -/\n\nlemma and_swap\u2082 :\n  \u2200a b : Prop, a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intros a b hab,\n  apply and.intro,\n  { exact and.elim_right hab },\n  { exact and.elim_left hab }\nend\n\n/-! Notice above how we pass the hypothesis `hab` directly to the lemmas\n`and.elim_right` and `and.elim_left`, instead of waiting for the lemmas's\nassumptions to appear as new subgoals. This is a small forward step in an\notherwise backward proof. -/\n\nlemma or_swap (a b : Prop) :\n  a \u2228 b \u2192 b \u2228 a :=\nbegin\n  intros hab,\n  apply or.elim hab,\n  { intro ha,\n    exact or.intro_right _ ha },\n  { intro hb,\n    exact or.intro_left _ hb }\nend\n\nlemma modus_ponens (a b : Prop) :\n  (a \u2192 b) \u2192 a \u2192 b :=\nbegin\n  intros hab ha,\n  apply hab,\n  exact ha\nend\n\nlemma not_not_intro (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nbegin\n  intro ha,\n  apply not.intro,\n  intro hna,\n  apply hna,\n  exact ha\nend\n\nlemma not_not_intro\u2082 (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nbegin\n  intros ha hna,\n  apply hna,\n  exact ha\nend\n\n\ndef double (n : \u2115) : \u2115 :=\nn + n\n\nlemma nat_exists_double_iden :\n  \u2203n : \u2115, double n = n :=\nbegin\n  apply exists.intro 0,\n  refl\nend\n\n\n/-! ## Reasoning about Equality\n\n*Syntactic* equality:\n  x = x\n  [2, 1, 3] = [2, 1, 3]\n  \n*Definitional* equality (*intensional*, *up to computation*):\n  2 + 2 = 4\n  quicksort [2, 1, 3] = mergesort [2, 1, 3]\n  all of the `by refl` examples below\n\n*Propositional* equality (*provable*):\n  x + y = y + x\n  quicksort = mergesort\n -/\n\n\n\n/-! `refl` proves `l = r`, where the two sides are equal up to\ncomputation. Computation means unfolding of definitions, \u03b2-reduction\n(application of \u03bb to an argument), `let`, and more. -/\n\nlemma \u03b1_example {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) :\n  (\u03bbx, f x) = (\u03bby, f y) :=\nbegin\n  refl\nend\n\nlemma \u03b1_example\u2082 {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) :\n  (\u03bbx, f x) = (\u03bby, f y) :=\nby refl\n\nlemma \u03b2_example {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :\n  (\u03bbx, f x) a = f a :=\nby refl\n\nlemma \u03b4_example :\n  double 5 = 5 + 5 :=\nby refl\n\nlemma \u03b6_example :\n  (let n : \u2115 := 2 in n + n) = 2 + 2 :=\nby refl\n\nlemma \u03b7_example {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) :\n  (\u03bbx, f x) = f :=\nby refl\n\ninductive my_prod (\u03b1 \u03b2 : Type) : Type\n| mk : \u03b1 \u2192 \u03b2 \u2192 my_prod\n\ndef my_prod.first {\u03b1 \u03b2 : Type} : my_prod \u03b1 \u03b2 \u2192 \u03b1\n| (my_prod.mk a b) := a\n\nlemma \u03b9_example {\u03b1 \u03b2 : Type} (a : \u03b1) (b : \u03b2) :\n  my_prod.first (my_prod.mk a b) = a :=\nby refl\n\n/-!\n\nWhich ones of these are *reduction rules*?\n\n-/\n\n\n#check eq.refl\n#check eq.symm\n#check eq.trans\n#check eq.subst\n\n/-! The above rules can be used directly: -/\n\nlemma cong_fst_arg {\u03b1 : Type} (a a' b : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') :\n  f a b = f a' b :=\nbegin\n  apply eq.subst ha,\n  apply eq.refl\nend\n\nlemma cong_two_args {\u03b1 : Type} (a a' b b' : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  f a b = f a' b' :=\nbegin\n  apply eq.subst ha,\n  apply eq.subst hb,\n  apply eq.refl\nend\n\n/-! `rw` applies a single equation as a left-to-right rewrite rule, once. To\napply an equation right-to-left, prefix its name with `\u2190`. -/\n\nlemma cong_two_args\u2082 {\u03b1 : Type} (a a' b b' : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  f a b = f a' b' :=\nbegin\n  rw ha,\n  rw hb\nend\n\n#check add_comm\n#check add_assoc\n\nlemma nat_comm_example (a b c : \u2115) : \n  a + b + c = c + b + a :=\nbegin \n  rw add_comm,\n  rw add_comm a,\n  rw add_assoc\nend\n\nlemma nat_comm_example\u2082 (a b c : \u2115) : \n  a + b + c = c + b + a :=\nbegin \n  rw [add_comm, add_comm a, add_assoc]\nend\n\nlemma double_example (n : \u2115) :\n  double n = n + n + 0 :=\nbegin \n  rw double,\n  refl\nend\n\nlemma a_proof_of_negation\u2083 (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nbegin\n  rw not_def,\n  rw not_def,\n  intro ha,\n  intro hna,\n  apply hna,\n  exact ha\nend\n\n/-! `simp` applies a standard set of rewrite rules (the __simp set__)\nexhaustively. The set can be extended using the `@[simp]` attribute. Lemmas can\nbe temporarily added to the simp set with the syntax\n`simp [_lemma\u2081_, \u2026, _lemmaN_]`. -/\n\nlemma cong_two_args_etc {\u03b1 : Type} (a a' b b' : \u03b1)\n    (g : \u03b1 \u2192 \u03b1 \u2192 \u2115 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  g a b (1 + 1) = g a' b' 2 :=\nby simp [ha, hb]\n\n\n/-! `cc` applies __congruence closure__ to derive new equalities. -/\n\nlemma cong_two_args\u2083 {\u03b1 : Type} (a a' b b' : \u03b1)\n    (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (ha : a = a') (hb : b = b') :\n  f a b = f a' b' :=\nby cc\n\n/-! `cc` can also reason up to associativity and commutativity of `+`, `*`,\nand other binary operators. -/\n\nlemma cong_assoc_comm (a a' b c : \u211d) (f : \u211d \u2192 \u211d)\n    (ha : a = a') :\n  f (a + b + c) = f (c + b + a') :=\nby cc\n\n\n/-! ## Proofs by Mathematical Induction\n\n`induction'` performs induction on the specified variable. It gives rise to one\nsubgoal per constructor. -/\n\nlemma add_zero (n : \u2115) :\n  add 0 n = n :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, ih] }\nend\n\n/-! We use `induction'`, a variant of Lean's built-in `induction` tactic. The\ntwo tactics are similar, but `induction'` is more user-friendly. -/\n\nlemma add_succ (i j : \u2115) :\n  add (nat.succ i) j = nat.succ (add i j) :=\nbegin\n  induction' j,\n  { refl },\n  { simp [add, ih] }\nend\n\nlemma add_comm (i j : \u2115) :\n  add i j = add j i :=\nbegin\n  induction' j,\n  { simp [add, add_zero] },\n  { simp [add, add_succ, ih] }\nend\n\nlemma add_assoc (i j k : \u2115) :\n  add (add i j) k = add i (add j k) :=\nbegin\n  induction' k,\n  { refl },\n  { simp [add, ih] }\nend\n\n/-! `cc` is extensible. We can register `add` as a commutative and associative\noperator using the type class instance mechanism (explained in lecture 4). This\nis useful for the `cc` invocation below. -/\n\n@[instance] def add.is_commutative : is_commutative \u2115 add :=\n{ comm := add_comm }\n\n@[instance] def add.is_associative : is_associative \u2115 add :=\n{ assoc := add_assoc }\n\nlemma mul_add (i j k : \u2115) :\n  mul i (add j k) = add (mul i j) (mul i k) :=\nbegin\n  induction' k,\n  { refl },\n  { simp [add, mul, ih],\n    cc }\nend\n\n\n/-! ## Cleanup Tactics\n\n`rename` changes the name of a variable or hypothesis.\n\n`clear` removes unused variables or hypotheses. -/\n\nlemma cleanup_example (a b c : Prop) (ha : a) (hb : b)\n    (hab : a \u2192 b) (hbc : b \u2192 c) :\n  c :=\nbegin\n  clear ha hab a,\n  apply hbc,\n  clear hbc c,\n  rename hb h,\n  exact h\nend\n\nend backward_proofs\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/lectures/love02_backward_proofs_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.8774767746654976, "lm_q1q2_score": 0.7404983493005574}}
{"text": "import tactic\n\nvariables (x y : \u2115)\n\nopen nat\n\ntheorem Q1a : x + y = y + x :=\nbegin\n  induction y with d hd,\n  { rw [add_zero, zero_add] },\n  { rw [add_succ, succ_add, hd] }\nend\n\ntheorem Q1b : x + y = x \u2192 y = 0 :=\nbegin\n  intro h,\n  induction x with d hd,\n  { convert h, rw zero_add },\n  { apply hd,\n    rw succ_add at h,\n    rw \u2190 succ_inj',\n    assumption,\n  }\nend\n\ntheorem Q1c : x + y = 0 \u2192 x = 0 \u2227 y = 0 :=\nbegin\n  intro h,\n  induction y with d hd,\n  { split,\n    { exact h },\n    { refl },\n  },\n  { rw add_succ at h,\n    exfalso,\n    apply succ_ne_zero (x + d),\n    assumption },\nend\n\ntheorem Q1d : x * y = y * x :=\nbegin\n  induction y with d hd,\n  { rw [mul_zero, zero_mul]},\n  { rw [mul_succ, succ_mul, hd]},\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/problem_sheets/Part_II/sheet1_q1_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813463747182, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7404872565243728}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module analysis.complex.re_im_topology\n! leanprover-community/mathlib commit 468b141b14016d54b479eb7a0fff1e360b7e3cf6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Complex.Basic\nimport Mathbin.Topology.FiberBundle.IsHomeomorphicTrivialBundle\n\n/-!\n# Closure, interior, and frontier of preimages under `re` and `im`\n\nIn this fact we use the fact that `\u2102` is naturally homeomorphic to `\u211d \u00d7 \u211d` to deduce some\ntopological properties of `complex.re` and `complex.im`.\n\n## Main statements\n\nEach statement about `complex.re` listed below has a counterpart about `complex.im`.\n\n* `complex.is_homeomorphic_trivial_fiber_bundle_re`: `complex.re` turns `\u2102` into a trivial\n  topological fiber bundle over `\u211d`;\n* `complex.is_open_map_re`, `complex.quotient_map_re`: in particular, `complex.re` is an open map\n  and is a quotient map;\n* `complex.interior_preimage_re`, `complex.closure_preimage_re`, `complex.frontier_preimage_re`:\n  formulas for `interior (complex.re \u207b\u00b9' s)` etc;\n* `complex.interior_set_of_re_le` etc: particular cases of the above formulas in the cases when `s`\n  is one of the infinite intervals `set.Ioi a`, `set.Ici a`, `set.Iio a`, and `set.Iic a`,\n  formulated as `interior {z : \u2102 | z.re \u2264 a} = {z | z.re < a}` etc.\n\n## Tags\n\ncomplex, real part, imaginary part, closure, interior, frontier\n-/\n\n\nopen Set\n\nnoncomputable section\n\nnamespace Complex\n\n/-- `complex.re` turns `\u2102` into a trivial topological fiber bundle over `\u211d`. -/\ntheorem isHomeomorphicTrivialFiberBundle_re : IsHomeomorphicTrivialFiberBundle \u211d re :=\n  \u27e8equivRealProdClm.toHomeomorph, fun z => rfl\u27e9\n#align complex.is_homeomorphic_trivial_fiber_bundle_re Complex.isHomeomorphicTrivialFiberBundle_re\n\n/-- `complex.im` turns `\u2102` into a trivial topological fiber bundle over `\u211d`. -/\ntheorem isHomeomorphicTrivialFiberBundle_im : IsHomeomorphicTrivialFiberBundle \u211d im :=\n  \u27e8equivRealProdClm.toHomeomorph.trans (Homeomorph.prodComm \u211d \u211d), fun z => rfl\u27e9\n#align complex.is_homeomorphic_trivial_fiber_bundle_im Complex.isHomeomorphicTrivialFiberBundle_im\n\ntheorem isOpenMap_re : IsOpenMap re :=\n  isHomeomorphicTrivialFiberBundle_re.isOpenMap_proj\n#align complex.is_open_map_re Complex.isOpenMap_re\n\ntheorem isOpenMap_im : IsOpenMap im :=\n  isHomeomorphicTrivialFiberBundle_im.isOpenMap_proj\n#align complex.is_open_map_im Complex.isOpenMap_im\n\ntheorem quotientMap_re : QuotientMap re :=\n  isHomeomorphicTrivialFiberBundle_re.quotientMap_proj\n#align complex.quotient_map_re Complex.quotientMap_re\n\ntheorem quotientMap_im : QuotientMap im :=\n  isHomeomorphicTrivialFiberBundle_im.quotientMap_proj\n#align complex.quotient_map_im Complex.quotientMap_im\n\ntheorem interior_preimage_re (s : Set \u211d) : interior (re \u207b\u00b9' s) = re \u207b\u00b9' interior s :=\n  (isOpenMap_re.preimage_interior_eq_interior_preimage continuous_re _).symm\n#align complex.interior_preimage_re Complex.interior_preimage_re\n\ntheorem interior_preimage_im (s : Set \u211d) : interior (im \u207b\u00b9' s) = im \u207b\u00b9' interior s :=\n  (isOpenMap_im.preimage_interior_eq_interior_preimage continuous_im _).symm\n#align complex.interior_preimage_im Complex.interior_preimage_im\n\ntheorem closure_preimage_re (s : Set \u211d) : closure (re \u207b\u00b9' s) = re \u207b\u00b9' closure s :=\n  (isOpenMap_re.preimage_closure_eq_closure_preimage continuous_re _).symm\n#align complex.closure_preimage_re Complex.closure_preimage_re\n\ntheorem closure_preimage_im (s : Set \u211d) : closure (im \u207b\u00b9' s) = im \u207b\u00b9' closure s :=\n  (isOpenMap_im.preimage_closure_eq_closure_preimage continuous_im _).symm\n#align complex.closure_preimage_im Complex.closure_preimage_im\n\ntheorem frontier_preimage_re (s : Set \u211d) : frontier (re \u207b\u00b9' s) = re \u207b\u00b9' frontier s :=\n  (isOpenMap_re.preimage_frontier_eq_frontier_preimage continuous_re _).symm\n#align complex.frontier_preimage_re Complex.frontier_preimage_re\n\ntheorem frontier_preimage_im (s : Set \u211d) : frontier (im \u207b\u00b9' s) = im \u207b\u00b9' frontier s :=\n  (isOpenMap_im.preimage_frontier_eq_frontier_preimage continuous_im _).symm\n#align complex.frontier_preimage_im Complex.frontier_preimage_im\n\n@[simp]\ntheorem interior_setOf_re_le (a : \u211d) : interior { z : \u2102 | z.re \u2264 a } = { z | z.re < a } := by\n  simpa only [interior_Iic] using interior_preimage_re (Iic a)\n#align complex.interior_set_of_re_le Complex.interior_setOf_re_le\n\n@[simp]\ntheorem interior_setOf_im_le (a : \u211d) : interior { z : \u2102 | z.im \u2264 a } = { z | z.im < a } := by\n  simpa only [interior_Iic] using interior_preimage_im (Iic a)\n#align complex.interior_set_of_im_le Complex.interior_setOf_im_le\n\n@[simp]\ntheorem interior_setOf_le_re (a : \u211d) : interior { z : \u2102 | a \u2264 z.re } = { z | a < z.re } := by\n  simpa only [interior_Ici] using interior_preimage_re (Ici a)\n#align complex.interior_set_of_le_re Complex.interior_setOf_le_re\n\n@[simp]\ntheorem interior_setOf_le_im (a : \u211d) : interior { z : \u2102 | a \u2264 z.im } = { z | a < z.im } := by\n  simpa only [interior_Ici] using interior_preimage_im (Ici a)\n#align complex.interior_set_of_le_im Complex.interior_setOf_le_im\n\n@[simp]\ntheorem closure_setOf_re_lt (a : \u211d) : closure { z : \u2102 | z.re < a } = { z | z.re \u2264 a } := by\n  simpa only [closure_Iio] using closure_preimage_re (Iio a)\n#align complex.closure_set_of_re_lt Complex.closure_setOf_re_lt\n\n@[simp]\ntheorem closure_setOf_im_lt (a : \u211d) : closure { z : \u2102 | z.im < a } = { z | z.im \u2264 a } := by\n  simpa only [closure_Iio] using closure_preimage_im (Iio a)\n#align complex.closure_set_of_im_lt Complex.closure_setOf_im_lt\n\n@[simp]\ntheorem closure_setOf_lt_re (a : \u211d) : closure { z : \u2102 | a < z.re } = { z | a \u2264 z.re } := by\n  simpa only [closure_Ioi] using closure_preimage_re (Ioi a)\n#align complex.closure_set_of_lt_re Complex.closure_setOf_lt_re\n\n@[simp]\ntheorem closure_setOf_lt_im (a : \u211d) : closure { z : \u2102 | a < z.im } = { z | a \u2264 z.im } := by\n  simpa only [closure_Ioi] using closure_preimage_im (Ioi a)\n#align complex.closure_set_of_lt_im Complex.closure_setOf_lt_im\n\n@[simp]\ntheorem frontier_setOf_re_le (a : \u211d) : frontier { z : \u2102 | z.re \u2264 a } = { z | z.re = a } := by\n  simpa only [frontier_Iic] using frontier_preimage_re (Iic a)\n#align complex.frontier_set_of_re_le Complex.frontier_setOf_re_le\n\n@[simp]\ntheorem frontier_setOf_im_le (a : \u211d) : frontier { z : \u2102 | z.im \u2264 a } = { z | z.im = a } := by\n  simpa only [frontier_Iic] using frontier_preimage_im (Iic a)\n#align complex.frontier_set_of_im_le Complex.frontier_setOf_im_le\n\n@[simp]\ntheorem frontier_setOf_le_re (a : \u211d) : frontier { z : \u2102 | a \u2264 z.re } = { z | z.re = a } := by\n  simpa only [frontier_Ici] using frontier_preimage_re (Ici a)\n#align complex.frontier_set_of_le_re Complex.frontier_setOf_le_re\n\n@[simp]\ntheorem frontier_setOf_le_im (a : \u211d) : frontier { z : \u2102 | a \u2264 z.im } = { z | z.im = a } := by\n  simpa only [frontier_Ici] using frontier_preimage_im (Ici a)\n#align complex.frontier_set_of_le_im Complex.frontier_setOf_le_im\n\n@[simp]\ntheorem frontier_setOf_re_lt (a : \u211d) : frontier { z : \u2102 | z.re < a } = { z | z.re = a } := by\n  simpa only [frontier_Iio] using frontier_preimage_re (Iio a)\n#align complex.frontier_set_of_re_lt Complex.frontier_setOf_re_lt\n\n@[simp]\ntheorem frontier_setOf_im_lt (a : \u211d) : frontier { z : \u2102 | z.im < a } = { z | z.im = a } := by\n  simpa only [frontier_Iio] using frontier_preimage_im (Iio a)\n#align complex.frontier_set_of_im_lt Complex.frontier_setOf_im_lt\n\n@[simp]\ntheorem frontier_setOf_lt_re (a : \u211d) : frontier { z : \u2102 | a < z.re } = { z | z.re = a } := by\n  simpa only [frontier_Ioi] using frontier_preimage_re (Ioi a)\n#align complex.frontier_set_of_lt_re Complex.frontier_setOf_lt_re\n\n@[simp]\ntheorem frontier_setOf_lt_im (a : \u211d) : frontier { z : \u2102 | a < z.im } = { z | z.im = a } := by\n  simpa only [frontier_Ioi] using frontier_preimage_im (Ioi a)\n#align complex.frontier_set_of_lt_im Complex.frontier_setOf_lt_im\n\ntheorem closure_reProdIm (s t : Set \u211d) : closure (s \u00d7\u2102 t) = closure s \u00d7\u2102 closure t := by\n  simpa only [\u2190 preimage_eq_preimage equiv_real_prod_clm.symm.to_homeomorph.surjective,\n    equiv_real_prod_clm.symm.to_homeomorph.preimage_closure] using @closure_prod_eq _ _ _ _ s t\n#align complex.closure_re_prod_im Complex.closure_reProdIm\n\ntheorem interior_reProdIm (s t : Set \u211d) : interior (s \u00d7\u2102 t) = interior s \u00d7\u2102 interior t := by\n  rw [re_prod_im, re_prod_im, interior_inter, interior_preimage_re, interior_preimage_im]\n#align complex.interior_re_prod_im Complex.interior_reProdIm\n\ntheorem frontier_reProdIm (s t : Set \u211d) :\n    frontier (s \u00d7\u2102 t) = closure s \u00d7\u2102 frontier t \u222a frontier s \u00d7\u2102 closure t := by\n  simpa only [\u2190 preimage_eq_preimage equiv_real_prod_clm.symm.to_homeomorph.surjective,\n    equiv_real_prod_clm.symm.to_homeomorph.preimage_frontier] using frontier_prod_eq s t\n#align complex.frontier_re_prod_im Complex.frontier_reProdIm\n\ntheorem frontier_setOf_le_re_and_le_im (a b : \u211d) :\n    frontier { z | a \u2264 re z \u2227 b \u2264 im z } = { z | a \u2264 re z \u2227 im z = b \u2228 re z = a \u2227 b \u2264 im z } := by\n  simpa only [closure_Ici, frontier_Ici] using frontier_re_prod_im (Ici a) (Ici b)\n#align complex.frontier_set_of_le_re_and_le_im Complex.frontier_setOf_le_re_and_le_im\n\ntheorem frontier_setOf_le_re_and_im_le (a b : \u211d) :\n    frontier { z | a \u2264 re z \u2227 im z \u2264 b } = { z | a \u2264 re z \u2227 im z = b \u2228 re z = a \u2227 im z \u2264 b } := by\n  simpa only [closure_Ici, closure_Iic, frontier_Ici, frontier_Iic] using\n    frontier_re_prod_im (Ici a) (Iic b)\n#align complex.frontier_set_of_le_re_and_im_le Complex.frontier_setOf_le_re_and_im_le\n\nend Complex\n\nopen Complex Metric\n\nvariable {s t : Set \u211d}\n\ntheorem IsOpen.reProdIm (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s \u00d7\u2102 t) :=\n  (hs.Preimage continuous_re).inter (ht.Preimage continuous_im)\n#align is_open.re_prod_im IsOpen.reProdIm\n\ntheorem IsClosed.reProdIm (hs : IsClosed s) (ht : IsClosed t) : IsClosed (s \u00d7\u2102 t) :=\n  (hs.Preimage continuous_re).inter (ht.Preimage continuous_im)\n#align is_closed.re_prod_im IsClosed.reProdIm\n\ntheorem Metric.Bounded.reProdIm (hs : Bounded s) (ht : Bounded t) : Bounded (s \u00d7\u2102 t) :=\n  antilipschitz_equivRealProd.bounded_preimage (hs.Prod ht)\n#align metric.bounded.re_prod_im Metric.Bounded.reProdIm\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/Complex/ReImTopology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7404634557013817}}
{"text": "/-\nCopyright (c) 2018 Jan-David Salchow. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jan-David Salchow, Patrick Massot\n-/\nimport topology.subset_properties\nimport topology.metric_space.basic\n\n/-!\n# Sequences in topological spaces\n\nIn this file we define sequences in topological spaces and show how they are related to\nfilters and the topology. In particular, we\n* define the sequential closure of a set and prove that it's contained in the closure,\n* define a type class \"sequential_space\" in which closure and sequential closure agree,\n* define sequential continuity and show that it coincides with continuity in sequential spaces,\n* provide an instance that shows that every first-countable (and in particular metric) space is\n  a sequential space.\n* define sequential compactness, prove that compactness implies sequential compactness in first\n  countable spaces, and prove they are equivalent for uniform spaces having a countable uniformity\n  basis (in particular metric spaces).\n-/\n\nopen set function filter\nopen_locale topological_space\n\nvariables {X Y : Type*}\n\nlocal notation x ` \u27f6 ` a := tendsto x at_top (\ud835\udcdd a)\n\n/-! ### Sequential closures, sequential continuity, and sequential spaces. -/\nsection topological_space\nvariables [topological_space X] [topological_space Y]\n\n/-- The sequential closure of a set `s : set X` in a topological space `X` is\nthe set of all `a : X` which arise as limit of sequences in `s`. -/\ndef seq_closure (s : set X) : set X :=\n{a | \u2203 x : \u2115 \u2192 X, (\u2200 n : \u2115, x n \u2208 s) \u2227 (x \u27f6 a)}\n\nlemma subset_seq_closure (s : set X) : s \u2286 seq_closure s :=\n\u03bb a ha, \u27e8const \u2115 a, \u03bb n, ha, tendsto_const_nhds\u27e9\n\n/-- A set `s` is sequentially closed if for any converging sequence `x n` of elements of `s`,\nthe limit belongs to `s` as well. -/\ndef is_seq_closed (s : set X) : Prop := s = seq_closure s\n\n/-- A convenience lemma for showing that a set is sequentially closed. -/\nlemma is_seq_closed_of_def {s : set X}\n  (h : \u2200 (x : \u2115 \u2192 X) (a : X), (\u2200 n : \u2115, x n \u2208 s) \u2192 (x \u27f6 a) \u2192 a \u2208 s) : is_seq_closed s :=\nshow s = seq_closure s, from subset.antisymm\n  (subset_seq_closure s)\n  (show \u2200 a, a \u2208 seq_closure s \u2192 a \u2208 s, from\n    (assume a \u27e8x, _, _\u27e9, show a \u2208 s, from h x a \u2039\u2200 n : \u2115, ((x n) \u2208 s)\u203a \u2039(x \u27f6 a)\u203a))\n\n/-- The sequential closure of a set is contained in the closure of that set.\nThe converse is not true. -/\nlemma seq_closure_subset_closure (s : set X) : seq_closure s \u2286 closure s :=\nassume a \u27e8x, xM, xa\u27e9,\nmem_closure_of_tendsto xa (eventually_of_forall xM)\n\n/-- A set is sequentially closed if it is closed. -/\nlemma is_closed.is_seq_closed {s : set X} (hs : is_closed s) : is_seq_closed s :=\nsuffices seq_closure s \u2286 s, from (subset_seq_closure s).antisymm this,\ncalc seq_closure s \u2286 closure s : seq_closure_subset_closure s\n               ... = s         : hs.closure_eq\n\n/-- The limit of a convergent sequence in a sequentially closed set is in that set.-/\nlemma is_seq_closed.mem_of_tendsto {s : set X} (hs : is_seq_closed s) {x : \u2115 \u2192 X}\n  (hmem : \u2200 n, x n \u2208 s) {a : X} (ha : (x \u27f6 a)) : a \u2208 s :=\nhave a \u2208 seq_closure s, from\n  show \u2203 x : \u2115 \u2192 X, (\u2200 n : \u2115, x n \u2208 s) \u2227 (x \u27f6 a), from \u27e8x, \u2039\u2200 n, x n \u2208 s\u203a, \u2039(x \u27f6 a)\u203a\u27e9,\neq.subst (eq.symm \u2039is_seq_closed s\u203a) \u2039a \u2208 seq_closure s\u203a\n\n/-- A sequential space is a space in which 'sequences are enough to probe the topology'. This can be\n formalised by demanding that the sequential closure and the closure coincide. The following\n statements show that other topological properties can be deduced from sequences in sequential\n spaces. -/\nclass sequential_space (X : Type*) [topological_space X] : Prop :=\n(seq_closure_eq_closure : \u2200 s : set X, seq_closure s = closure s)\n\n/-- In a sequential space, a set is closed iff it's sequentially closed. -/\nlemma is_seq_closed_iff_is_closed [sequential_space X] {s : set X} :\n  is_seq_closed s \u2194 is_closed s :=\niff.intro\n  (assume _, closure_eq_iff_is_closed.mp (eq.symm\n    (calc s = seq_closure s : by assumption\n        ... = closure s     : sequential_space.seq_closure_eq_closure s)))\n  is_closed.is_seq_closed\n\nalias is_seq_closed_iff_is_closed \u2194 is_seq_closed.is_closed _\n\n/-- In a sequential space, a point belongs to the closure of a set iff it is a limit of a sequence\ntaking values in this set. -/\nlemma mem_closure_iff_seq_limit [sequential_space X] {s : set X} {a : X} :\n  a \u2208 closure s \u2194 \u2203 x : \u2115 \u2192 X, (\u2200 n : \u2115, x n \u2208 s) \u2227 (x \u27f6 a) :=\nby { rw \u2190 sequential_space.seq_closure_eq_closure, exact iff.rfl }\n\n/-- A function between topological spaces is sequentially continuous if it commutes with limit of\n convergent sequences. -/\ndef seq_continuous (f : X \u2192 Y) : Prop :=\n\u2200 (x : \u2115 \u2192 X), \u2200 {a : X}, (x \u27f6 a) \u2192 (f \u2218 x \u27f6 f a)\n\n/- A continuous function is sequentially continuous. -/\nprotected lemma continuous.seq_continuous {f : X \u2192 Y} (hf : continuous f) : seq_continuous f :=\nassume x a (_ : x \u27f6 a),\nhave tendsto f (\ud835\udcdd a) (\ud835\udcdd (f a)), from continuous.tendsto \u2039continuous f\u203a a,\nshow (f \u2218 x) \u27f6 (f a), from tendsto.comp this \u2039(x \u27f6 a)\u203a\n\n/-- In a sequential space, continuity and sequential continuity coincide. -/\nlemma continuous_iff_seq_continuous {f : X \u2192 Y} [sequential_space X] :\n  continuous f \u2194 seq_continuous f :=\niff.intro\n  continuous.seq_continuous\n  (assume : seq_continuous f, show continuous f, from\n    suffices h : \u2200 {s : set Y}, is_closed s \u2192 is_seq_closed (f \u207b\u00b9' s), from\n      continuous_iff_is_closed.mpr (assume s _, is_seq_closed_iff_is_closed.mp $ h \u2039is_closed s\u203a),\n    assume s (_ : is_closed s),\n      is_seq_closed_of_def $\n        assume (x : \u2115 \u2192 X) a (_ : \u2200 n, f (x n) \u2208 s) (_ : x \u27f6 a),\n        have (f \u2218 x) \u27f6 (f a), from \u2039seq_continuous f\u203a x \u2039(x \u27f6 a)\u203a,\n        show f a \u2208 s,\n          from \u2039is_closed s\u203a.is_seq_closed.mem_of_tendsto \u2039\u2200 n, f (x n) \u2208 s\u203a \u2039(f\u2218x \u27f6 f a)\u203a)\n\nalias continuous_iff_seq_continuous \u2194 _ seq_continuous.continuous\n\nend topological_space\n\nnamespace topological_space\n\nnamespace first_countable_topology\n\nvariables [topological_space X] [first_countable_topology X]\n\n/-- Every first-countable space is sequential. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance : sequential_space X :=\n\u27e8show \u2200 s, seq_closure s = closure s, from assume s,\n  suffices closure s \u2286 seq_closure s,\n    from set.subset.antisymm (seq_closure_subset_closure s) this,\n  -- For every a \u2208 closure s, we need to construct a sequence `x` in `s` that converges to `a`:\n  assume (a : X) (ha : a \u2208 closure s),\n  -- Since we are in a first-countable space, the neighborhood filter around `a` has a decreasing\n  -- basis `U` indexed by `\u2115`.\n  let \u27e8U, hU\u27e9 := (\ud835\udcdd a).exists_antitone_basis in\n  -- Since `p \u2208 closure M`, there is an element in each `M \u2229 U i`\n  have ha : \u2200 (i : \u2115), \u2203 (y : X), y \u2208 s \u2227 y \u2208 U i,\n    by simpa using (mem_closure_iff_nhds_basis hU.1).mp ha,\n  begin\n    -- The axiom of (countable) choice builds our sequence from the later fact\n    choose u hu using ha,\n    rw forall_and_distrib at hu,\n    -- It clearly takes values in `M`\n    use [u, hu.1],\n    -- and converges to `p` because the basis is decreasing.\n    apply hU.tendsto hu.2,\n  end\u27e9\n\n\nend first_countable_topology\n\nend topological_space\n\nsection seq_compact\nopen topological_space topological_space.first_countable_topology\nvariables [topological_space X]\n\n/-- A set `s` is sequentially compact if every sequence taking values in `s` has a\nconverging subsequence. -/\ndef is_seq_compact (s : set X) :=\n\u2200 \u2983x : \u2115 \u2192 X\u2984, (\u2200 n, x n \u2208 s) \u2192 \u2203 (a \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a)\n\n/-- A space `X` is sequentially compact if every sequence in `X` has a\nconverging subsequence. -/\nclass seq_compact_space (X : Type*) [topological_space X] : Prop :=\n(seq_compact_univ : is_seq_compact (univ : set X))\n\nlemma is_seq_compact.subseq_of_frequently_in {s : set X} (hs : is_seq_compact s) {x : \u2115 \u2192 X}\n  (hx : \u2203\u1da0 n in at_top, x n \u2208 s) :\n  \u2203 (a \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a) :=\nlet \u27e8\u03c8, h\u03c8, hu\u03c8\u27e9 := extraction_of_frequently_at_top hx, \u27e8a, a_in, \u03c6, h\u03c6, h\u27e9 := hs hu\u03c8 in\n\u27e8a, a_in, \u03c8 \u2218 \u03c6, h\u03c8.comp h\u03c6, h\u27e9\n\nlemma seq_compact_space.tendsto_subseq [seq_compact_space X] (x : \u2115 \u2192 X) :\n  \u2203 a (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a) :=\nlet \u27e8a, _, \u03c6, mono, h\u27e9 := seq_compact_space.seq_compact_univ (\u03bb n, mem_univ (x n)) in\n\u27e8a, \u03c6, mono, h\u27e9\n\nsection first_countable_topology\nvariables [first_countable_topology X]\nopen topological_space.first_countable_topology\n\nlemma is_compact.is_seq_compact {s : set X} (hs : is_compact s) : is_seq_compact s :=\n\u03bb x x_in,\nlet \u27e8a, a_in, ha\u27e9 := @hs (map x at_top) _\n  (le_principal_iff.mpr (univ_mem' x_in : _)) in \u27e8a, a_in, tendsto_subseq ha\u27e9\n\nlemma is_compact.tendsto_subseq' {s : set X} {x : \u2115 \u2192 X} (hs : is_compact s)\n  (hx : \u2203\u1da0 n in at_top, x n \u2208 s) :\n  \u2203 (a \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a) :=\nhs.is_seq_compact.subseq_of_frequently_in hx\n\nlemma is_compact.tendsto_subseq {s : set X} {x : \u2115 \u2192 X} (hs : is_compact s) (hx : \u2200 n, x n \u2208 s) :\n  \u2203 (a \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a) :=\nhs.is_seq_compact hx\n\n@[priority 100] -- see Note [lower instance priority]\ninstance first_countable_topology.seq_compact_of_compact [compact_space X] : seq_compact_space X :=\n\u27e8compact_univ.is_seq_compact\u27e9\n\nlemma compact_space.tendsto_subseq [compact_space X] (x : \u2115 \u2192 X) :\n  \u2203 a (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a) :=\nseq_compact_space.tendsto_subseq x\n\nend first_countable_topology\nend seq_compact\n\nsection uniform_space_seq_compact\n\nopen_locale uniformity\nopen uniform_space prod\n\nvariables [uniform_space X] {s : set X}\n\nlemma lebesgue_number_lemma_seq {\u03b9 : Type*} [is_countably_generated (\ud835\udce4 X)] {c : \u03b9 \u2192 set X}\n  (hs : is_seq_compact s) (hc\u2081 : \u2200 i, is_open (c i)) (hc\u2082 : s \u2286 \u22c3 i, c i) :\n  \u2203 V \u2208 \ud835\udce4 X, symmetric_rel V \u2227 \u2200 x \u2208 s, \u2203 i, ball x V \u2286 c i :=\nbegin\n  classical,\n  obtain \u27e8V, hV, Vsymm\u27e9 :\n    \u2203 V : \u2115 \u2192 set (X \u00d7 X), (\ud835\udce4 X).has_antitone_basis V \u2227 \u2200 n, swap \u207b\u00b9' V n = V n,\n      from uniform_space.has_seq_basis X,\n  suffices : \u2203 n, \u2200 x \u2208 s, \u2203 i, ball x (V n) \u2286 c i,\n  { cases this with n hn,\n    exact \u27e8V n, hV.to_has_basis.mem_of_mem trivial, Vsymm n, hn\u27e9 },\n  by_contradiction H,\n  obtain \u27e8x, x_in, hx\u27e9 : \u2203 x : \u2115 \u2192 X, (\u2200 n, x n \u2208 s) \u2227 \u2200 n i, \u00ac ball (x n) (V n) \u2286 c i,\n  { push_neg at H,\n    choose x hx using H,\n    exact \u27e8x, forall_and_distrib.mp hx\u27e9 }, clear H,\n  obtain \u27e8x\u2080, x\u2080_in, \u03c6, \u03c6_mono, hlim\u27e9 : \u2203 (x\u2080 \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 x\u2080),\n    from hs x_in, clear hs,\n  obtain \u27e8i\u2080, x\u2080_in\u27e9 : \u2203 i\u2080, x\u2080 \u2208 c i\u2080,\n  { rcases hc\u2082 x\u2080_in with \u27e8_, \u27e8i\u2080, rfl\u27e9, x\u2080_in_c\u27e9,\n    exact \u27e8i\u2080, x\u2080_in_c\u27e9 }, clear hc\u2082,\n  obtain \u27e8n\u2080, hn\u2080\u27e9 : \u2203 n\u2080, ball x\u2080 (V n\u2080) \u2286 c i\u2080,\n  { rcases (nhds_basis_uniformity hV.to_has_basis).mem_iff.mp\n      (is_open_iff_mem_nhds.mp (hc\u2081 i\u2080) _ x\u2080_in) with \u27e8n\u2080, _, h\u27e9,\n    use n\u2080,\n    rwa \u2190 ball_eq_of_symmetry (Vsymm n\u2080) at h }, clear hc\u2081,\n  obtain \u27e8W, W_in, hWW\u27e9 : \u2203 W \u2208 \ud835\udce4 X, W \u25cb W \u2286 V n\u2080,\n    from comp_mem_uniformity_sets (hV.to_has_basis.mem_of_mem trivial),\n  obtain \u27e8N, x_\u03c6_N_in, hVNW\u27e9 : \u2203 N, x (\u03c6 N) \u2208 ball x\u2080 W \u2227 V (\u03c6 N) \u2286 W,\n  { obtain \u27e8N\u2081, h\u2081\u27e9 : \u2203 N\u2081, \u2200 n \u2265 N\u2081, x (\u03c6 n) \u2208 ball x\u2080 W,\n      from tendsto_at_top'.mp hlim _ (mem_nhds_left x\u2080 W_in),\n    obtain \u27e8N\u2082, h\u2082\u27e9 : \u2203 N\u2082, V (\u03c6 N\u2082) \u2286 W,\n    { rcases hV.to_has_basis.mem_iff.mp W_in with \u27e8N, _, hN\u27e9,\n      use N,\n      exact subset.trans (hV.antitone $ \u03c6_mono.id_le _) hN },\n    have : \u03c6 N\u2082 \u2264 \u03c6 (max N\u2081 N\u2082),\n      from \u03c6_mono.le_iff_le.mpr (le_max_right _ _),\n    exact \u27e8max N\u2081 N\u2082, h\u2081 _ (le_max_left _ _), trans (hV.antitone this) h\u2082\u27e9 },\n  suffices : ball (x (\u03c6 N)) (V (\u03c6 N)) \u2286 c i\u2080,\n    from hx (\u03c6 N) i\u2080 this,\n  calc\n    ball (x $ \u03c6 N) (V $ \u03c6 N) \u2286 ball (x $ \u03c6 N) W : preimage_mono hVNW\n                         ... \u2286 ball x\u2080 (V n\u2080)   : ball_subset_of_comp_subset x_\u03c6_N_in hWW\n                         ... \u2286 c i\u2080             : hn\u2080,\nend\n\nlemma is_seq_compact.totally_bounded (h : is_seq_compact s) : totally_bounded s :=\nbegin\n  classical,\n  apply totally_bounded_of_forall_symm,\n  unfold is_seq_compact at h,\n  contrapose! h,\n  rcases h with \u27e8V, V_in, V_symm, h\u27e9,\n  simp_rw [not_subset] at h,\n  have : \u2200 (t : set X), t.finite \u2192 \u2203 a, a \u2208 s \u2227 a \u2209 \u22c3 y \u2208 t, ball y V,\n  { intros t ht,\n    obtain \u27e8a, a_in, H\u27e9 : \u2203 a \u2208 s, \u2200 x \u2208 t, (x, a) \u2209 V,\n      by simpa [ht] using h t,\n    use [a, a_in],\n    intro H',\n    obtain \u27e8x, x_in, hx\u27e9 := mem_Union\u2082.mp H',\n    exact H x x_in hx },\n  cases seq_of_forall_finite_exists this with u hu, clear h this,\n  simp [forall_and_distrib] at hu,\n  cases hu with u_in hu,\n  use [u, u_in], clear u_in,\n  intros x x_in \u03c6,\n  intros h\u03c6 hu\u03c6,\n  obtain \u27e8N, hN\u27e9 : \u2203 N, \u2200 p q, p \u2265 N \u2192 q \u2265 N \u2192 (u (\u03c6 p), u (\u03c6 q)) \u2208 V,\n    from hu\u03c6.cauchy_seq.mem_entourage V_in,\n  specialize hN N (N+1) (le_refl N) (nat.le_succ N),\n  specialize hu (\u03c6 $ N+1) (\u03c6 N) (h\u03c6 $ lt_add_one N),\n  exact hu hN,\nend\n\nprotected lemma is_seq_compact.is_compact [is_countably_generated $ \ud835\udce4 X] (hs : is_seq_compact s) :\n  is_compact s :=\nbegin\n  classical,\n  rw is_compact_iff_finite_subcover,\n  intros \u03b9 U Uop s_sub,\n  rcases lebesgue_number_lemma_seq hs Uop s_sub with \u27e8V, V_in, Vsymm, H\u27e9,\n  rcases totally_bounded_iff_subset.mp hs.totally_bounded V V_in with \u27e8t,t_sub, tfin,  ht\u27e9,\n  have : \u2200 x : t, \u2203 (i : \u03b9), ball x.val V \u2286 U i,\n  { rintros \u27e8x, x_in\u27e9,\n    exact H x (t_sub x_in) },\n  choose i hi using this,\n  haveI : fintype t := tfin.fintype,\n  use finset.image i finset.univ,\n  transitivity \u22c3 y \u2208 t, ball y V,\n  { intros x x_in,\n    specialize ht x_in,\n    rw mem_Union\u2082 at *,\n    simp_rw ball_eq_of_symmetry Vsymm,\n    exact ht },\n  { refine Union\u2082_mono' (\u03bb x x_in, _),\n    exact \u27e8i \u27e8x, x_in\u27e9, finset.mem_image_of_mem _ (finset.mem_univ _), hi \u27e8x, x_in\u27e9\u27e9 },\nend\n\n/-- A version of Bolzano-Weistrass: in a uniform space with countably generated uniformity filter\n(e.g., in a metric space), a set is compact if and only if it is sequentially compact. -/\nprotected lemma uniform_space.compact_iff_seq_compact [is_countably_generated $ \ud835\udce4 X] :\n is_compact s \u2194 is_seq_compact s :=\n\u27e8\u03bb H, H.is_seq_compact, \u03bb H, H.is_compact\u27e9\n\nlemma uniform_space.compact_space_iff_seq_compact_space [is_countably_generated $ \ud835\udce4 X] :\n  compact_space X \u2194 seq_compact_space X :=\nhave key : is_compact (univ : set X) \u2194 is_seq_compact univ := uniform_space.compact_iff_seq_compact,\n\u27e8\u03bb \u27e8h\u27e9, \u27e8key.mp h\u27e9, \u03bb \u27e8h\u27e9, \u27e8key.mpr h\u27e9\u27e9\n\nend uniform_space_seq_compact\n\nsection metric_seq_compact\n\nvariables [pseudo_metric_space X]\nopen metric\n\nlemma seq_compact.lebesgue_number_lemma_of_metric {\u03b9 : Sort*} {c : \u03b9 \u2192 set X}\n  {s : set X} (hs : is_seq_compact s) (hc\u2081 : \u2200 i, is_open (c i)) (hc\u2082 : s \u2286 \u22c3 i, c i) :\n  \u2203 \u03b4 > 0, \u2200 a \u2208 s, \u2203 i, ball a \u03b4 \u2286 c i :=\nlebesgue_number_lemma_of_metric hs.is_compact hc\u2081 hc\u2082\n\nvariables [proper_space X] {s : set X}\n\n/-- A version of **Bolzano-Weistrass**: in a proper metric space (eg. $\u211d^n$),\nevery bounded sequence has a converging subsequence. This version assumes only\nthat the sequence is frequently in some bounded set. -/\nlemma tendsto_subseq_of_frequently_bounded (hs : bounded s)\n  {x : \u2115 \u2192 X} (hx : \u2203\u1da0 n in at_top, x n \u2208 s) :\n  \u2203 a \u2208 closure s, \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a) :=\nhave hcs : is_seq_compact (closure s), from hs.is_compact_closure.is_seq_compact,\nhave hu' : \u2203\u1da0 n in at_top, x n \u2208 closure s, from hx.mono (\u03bb n hn, subset_closure hn),\nhcs.subseq_of_frequently_in hu'\n\n/-- A version of Bolzano-Weistrass: in a proper metric space (eg. $\u211d^n$),\nevery bounded sequence has a converging subsequence. -/\nlemma tendsto_subseq_of_bounded (hs : bounded s) {x : \u2115 \u2192 X} (hx : \u2200 n, x n \u2208 s) :\n  \u2203 a \u2208 closure s, \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 a) :=\ntendsto_subseq_of_frequently_bounded hs $ frequently_of_forall hx\n\nend metric_seq_compact\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/topology/sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8221891392358014, "lm_q1q2_score": 0.7404058097044707}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Eric Wieser\n-/\n\nimport algebra.char_p.basic\nimport ring_theory.ideal.quotient\n\n/-!\n# Characteristic of quotients rings\n-/\n\nuniverses u v\n\nnamespace char_p\n\ntheorem quotient (R : Type u) [comm_ring R] (p : \u2115) [hp1 : fact p.prime] (hp2 : \u2191p \u2208 nonunits R) :\n  char_p (R \u29f8 (ideal.span {p} : ideal R)) p :=\nhave hp0 : (p : R \u29f8 (ideal.span {p} : ideal R)) = 0,\n  from (ideal.quotient.mk (ideal.span {p} : ideal R)).map_nat_cast p \u25b8\n    ideal.quotient.eq_zero_iff_mem.2 (ideal.subset_span $ set.mem_singleton _),\nring_char.of_eq $ or.resolve_left ((nat.dvd_prime hp1.1).1 $ ring_char.dvd hp0) $ \u03bb h1,\nhp2 $ is_unit_iff_dvd_one.2 $ ideal.mem_span_singleton.1 $ ideal.quotient.eq_zero_iff_mem.1 $\n@@subsingleton.elim (@@char_p.subsingleton _ $ ring_char.of_eq h1) _ _\n\n/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient\ninherits the characteristic of the underlying ring. -/\nlemma quotient' {R : Type*} [comm_ring R] (p : \u2115) [char_p R p] (I : ideal R)\n  (h : \u2200 x : \u2115, (x : R) \u2208 I \u2192 (x : R) = 0) :\n  char_p (R \u29f8 I) p :=\n\u27e8\u03bb x, begin\n  rw [\u2190cast_eq_zero_iff R p x, \u2190(ideal.quotient.mk I).map_nat_cast],\n  refine quotient.eq'.trans (_ : \u2191x - 0 \u2208 I \u2194 _),\n  rw sub_zero,\n  exact \u27e8h x, \u03bb h', h'.symm \u25b8 I.zero_mem\u27e9,\nend\u27e9\n\nend char_p\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/char_p/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7404058079758207}}
{"text": "import algebra.pi_instances\nset_option old_structure_cmd true\n\nuniverse variables u\n\n/-\n  A non-unital ring or rng is a ring without unit. According to ncatlab\n  https://ncatlab.org/nlab/show/nonunital+ring\n\n  Definition 2.1. A nonunital ring or rng is a set R with operations of addition and multiplication, such that:\n\n  * R is a semigroup under multiplication;\n  * R is an abelian group under addition;\n  * multiplication distributes over addition.\n-/\n\n/- Define rng in Lean. Use a definition similar to `ring`. Replace the following definition with the correct definition. -/\nclass rng (\u03b1 : Type u) extends ring \u03b1\n\n/- Formulate and show that every ring is a rng. -/\n\nvariables {\u03b1 : Type u} [rng \u03b1] {a b c x y z w : \u03b1} {n m : \u2124}\n\n/- Prove the following lemma. -/\nlemma distrib2 : (x + y) * (z + w) = x * z + x * w + y * z + y * w :=\nsorry\n\n/- Construct the following instance.\nFor each field, first write a lemma that proves that field.\nThere are very similar lemmas proven for rings, try to copy those and modify where needed -/\n\ninstance rng.mul_zero_class : mul_zero_class \u03b1 :=\nsorry\n\n/- Formulate and prove lemmas that state -(a * b) = a * -b = -a * b (see mathlib for similar lemmas) -/\n\n/- Prove that a * (b - c) = a * b - a * c (see mathlib for similar lemmas) -/\n\n/- Prove the following lemmas by induction on n.\n  Try to prove one with the `induction` tactic, and one with the equation compiler. -/\nlemma rng.nat_smul_mul_left : n \u2022 a * b = n \u2022 (a * b) := sorry\n\nlemma rng.nat_smul_mul_right : a * n \u2022 b = n \u2022 (a * b) := sorry\n\n/-\n  The following lemmas are tricky, so they are provided for you.\n  You can uncomment them in VSCode by selecting them and pressing `ctrl+/`\n  The proof assumes that `rng.neg_mul_eq_neg_mul` is the name of the lemma that `-(a * b) = -a * b`.\n  Make sure you understand the proofs.\n-/\n-- lemma rng.smul_mul_left : \u2200{n : \u2124}, n \u2022 a * b = n \u2022 (a * b)\n-- | (n : \u2115) := rng.nat_smul_mul_left\n-- | -[1+n]  := show (-\u2191(n+1) : \u2124) \u2022 a * b  = (-\u2191(n+1) : \u2124) \u2022 (a * b),\n--   by { rw [neg_smul, neg_smul, \u2190rng.neg_mul_eq_neg_mul], congr' 1,\n--        apply rng.nat_smul_mul_left }\n\n-- lemma rng.smul_mul_right : \u2200{n : \u2124}, a * n \u2022 b = n \u2022 (a * b)\n-- | (n : \u2115) := rng.nat_smul_mul_right\n-- | -[1+n]  := show a * (-\u2191(n+1) : \u2124) \u2022 b  = (-\u2191(n+1) : \u2124) \u2022 (a * b),\n--   by { rw [neg_smul, neg_smul, \u2190rng.neg_mul_eq_mul_neg], congr' 1,\n--        apply rng.nat_smul_mul_right }\n\n\n/- Prove that n \u2022 (m \u2022 a) = m \u2022 (n \u2022 a) -/\n\n/- We will now construct the unitisation of a non-unital ring. See ncatlab:\n\nDefinition 3.1. Given a non-unital ring A, then its unitisation is the ring F(A) obtained by freely adjoining an identity element, hence the ring whose underlying abelian group is the direct sum Z\u2295A of A with the integers, and whose product operation is defined by\n\n(n\u2081,a\u2081)(n\u2082,a\u2082) = (n\u2081n\u2082, n\u2081a\u2082 + n\u2082a\u2081 + a\u2081a\u2082),\nwhere for n\u2208Z and a\u2208A we set na = a + a + \u22ef + a with n summands.\n-/\ndef unitisation (\u03b1 : Type u) : Type u := \u2124 \u00d7 \u03b1\n\nnamespace unitisation\n\n/- Define multiplication so that (n\u2081,a\u2081)(n\u2082,a\u2082) = (n\u2081n\u2082, n\u2081a\u2082 + n\u2082a\u2081 + a\u2081a\u2082).\n  Use `\u2022` to multiply a integer with a element of \u03b1. -/\ninstance : has_mul (unitisation \u03b1) :=\nsorry\n\n/- Fill in the blanks, Prove the following rewrite rules. Also add them as simplification lemmas. -/\nlemma mk_mul_mk : (\u27e8n, a\u27e9 * \u27e8m, b\u27e9 : unitisation \u03b1) = sorry :=\nsorry\n\nlemma mul_fst {x y : unitisation \u03b1} : (x * y).fst = sorry :=\nsorry\n\nlemma mul_snd {x y : unitisation \u03b1} :\n  (x * y).snd = sorry :=\nsorry\n\n/- Now prove that this is a ring. Lean already knows it is a commutative group under addition using instance `prod.add_comm_group`. -/\ninstance : ring (unitisation \u03b1) := sorry\n\n\nend unitisation\n", "meta": {"author": "jesse-michael-han", "repo": "hanoi-lean-2019", "sha": "a5a9f368e394d563bfcc13e3773863924505b1ce", "save_path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019", "path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019/hanoi-lean-2019-a5a9f368e394d563bfcc13e3773863924505b1ce/src/floris/exercises-library-building.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8221891218080991, "lm_q1q2_score": 0.7404057940103057}}
{"text": "\n-- TODO ask Mario why instance : distrib nat            := by apply_instance\n-- is in lemmas.lean in core nat\n\nimport data.nat.dist -- distance function\nimport data.nat.gcd -- gcd\nimport data.nat.modeq -- modular arithmetic\nimport data.nat.prime -- prime number stuff \nimport data.nat.sqrt  -- square roots\n\nopen nat \n\nexample : fact 4 = 24 := rfl -- factorial \n\nexample (a : \u2115) : fact a > 0 := fact_pos a\n\nexample : dist 6 4 = 2 := rfl -- distance function\n\nexample (a b : \u2115) : a \u2260 b \u2192 dist a b > 0 := dist_pos_of_ne \n\nexample (a b : \u2115) : gcd a b \u2223 a \u2227 gcd a b \u2223 b := gcd_dvd a b \n\nexample : lcm 6 4 = 12 := rfl \n\nexample (a b : \u2115) : lcm a b = lcm b a := lcm_comm a b\nexample (a b : \u2115) : gcd a b * lcm a b = a * b := gcd_mul_lcm a b\n\nexample (a b : \u2115) : (\u2200 k : \u2115, k > 1 \u2192 k \u2223 a \u2192 \u00ac (k \u2223 b) ) \u2192 coprime a b := coprime_of_dvd \n\n-- type the congruence symbol with \\== \n\nexample : 5 \u2261 8 [MOD 3] := rfl\n\nexample (a b c d m : \u2115) : a \u2261 b [MOD m] \u2192 c \u2261 d [MOD m] \u2192 a * c \u2261 b * d [MOD m] := modeq.modeq_mul\n\n-- nat.sqrt is integer square root (it rounds down).\n\n#eval sqrt 1000047\n-- returns 1000\n\nexample (a : \u2115) : sqrt (a * a) = a := sqrt_eq a\n\nexample (a b : \u2115) : sqrt a < b \u2194 a < b * b := sqrt_lt \n\n-- nat.prime n returns whether n is prime or not.\n-- We can prove 59 is prime if we first tell Lean that primality \n-- is decidable. But it's slow because the algorithms are\n-- not optimised for the kernel.\n\ninstance : decidable (prime 59) := decidable_prime_1 59 \nexample : prime 59 := dec_trivial \n\nexample (p : \u2115) : prime p \u2192 p \u2265 2 := prime.ge_two\n\nexample (p : \u2115) : prime p \u2194 p \u2265 2 \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac (m \u2223 p) := prime_def_le_sqrt\n\nexample (p : \u2115) : prime p \u2192 (\u2200 m, coprime p m \u2228 p \u2223 m) := coprime_or_dvd_of_prime\n\nexample : \u2200 n, \u2203 p, p \u2265 n \u2227 prime p := exists_infinite_primes \n\n-- min_fac returns the smallest prime factor of n (or junk if it doesn't have one)\n\nexample : min_fac 12 = 2 := rfl \n\n-- `factors n` is the prime factorization of `n`, listed in increasing order.\n-- As far as I can see this isn't decidable, and doesn't seem to reduce either.\n-- But we can evaluate it in the virtual machine using #eval .\n\n#eval factors (2^32+1)\n-- [641, 6700417]\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/leanmap/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787538, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.740405793544065}}
{"text": "/-\nCopyright (c) 2022 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n-/\n\nimport algebra.is_prime_pow\nimport number_theory.arithmetic_function\nimport analysis.special_functions.log\n\n/-!\n# The von Mangoldt Function\n\nIn this file we define the von Mangoldt function: the function on natural numbers that returns\n`log p` if the input can be expressed as `p^k` for a prime `p`.\n\n## Main Results\n\nThe main definition for this file is\n\n- `nat.arithmetic_function.von_mangoldt`: The von Mangoldt function `\u039b`.\n\nWe then prove the classical summation property of the von Mangoldt function in\n`nat.arithmetic_function.von_mangoldt_sum`, that `\u2211 i in n.divisors, \u039b i = real.log n`, and use this\nto deduce alternative expressions for the von Mangoldt function via M\u00f6bius inversion, see\n`nat.arithmetic_function.sum_moebius_mul_log_eq`.\n\n## Notation\n\nWe use the standard notation `\u039b` to represent the von Mangoldt function.\n\n-/\n\nnamespace nat\nnamespace arithmetic_function\n\nopen finset\n\nopen_locale arithmetic_function\n\n/-- `log` as an arithmetic function `\u2115 \u2192 \u211d`. Note this is in the `nat.arithmetic_function`\nnamespace to indicate that it is bundled as an `arithmetic_function` rather than being the usual\nreal logarithm. -/\nnoncomputable def log : arithmetic_function \u211d :=\n\u27e8\u03bb n, real.log n, by simp\u27e9\n\n@[simp] lemma log_apply {n : \u2115} : log n = real.log n := rfl\n\n/--\nThe `von_mangoldt` function is the function on natural numbers that returns `log p` if the input can\nbe expressed as `p^k` for a prime `p`.\nIn the case when `n` is a prime power, `min_fac` will give the appropriate prime, as it is the\nsmallest prime factor.\n\nIn the `arithmetic_function` locale, we have the notation `\u039b` for this function.\n-/\nnoncomputable def von_mangoldt : arithmetic_function \u211d :=\n\u27e8\u03bb n, if is_prime_pow n then real.log (min_fac n) else 0, if_neg not_is_prime_pow_zero\u27e9\n\nlocalized \"notation `\u039b` := nat.arithmetic_function.von_mangoldt\" in arithmetic_function\n\nlemma von_mangoldt_apply {n : \u2115} :\n  \u039b n = if is_prime_pow n then real.log (min_fac n) else 0 := rfl\n\n@[simp] lemma von_mangoldt_apply_one : \u039b 1 = 0 := by simp [von_mangoldt_apply]\n\n@[simp] lemma von_mangoldt_nonneg {n : \u2115} : 0 \u2264 \u039b n :=\nbegin\n  rw [von_mangoldt_apply],\n  split_ifs,\n  { exact real.log_nonneg (one_le_cast.2 (nat.min_fac_pos n)) },\n  refl\nend\n\nlemma von_mangoldt_apply_pow {n k : \u2115} (hk : k \u2260 0) : \u039b (n ^ k) = \u039b n :=\nby simp only [von_mangoldt_apply, is_prime_pow_pow_iff hk, pow_min_fac hk]\n\nlemma von_mangoldt_apply_prime {p : \u2115} (hp : p.prime) : \u039b p = real.log p :=\nby rw [von_mangoldt_apply, prime.min_fac_eq hp, if_pos (nat.prime_iff.1 hp).is_prime_pow]\n\nopen_locale big_operators\n\nlemma von_mangoldt_sum {n : \u2115} :\n  \u2211 i in n.divisors, \u039b i = real.log n :=\nbegin\n  refine rec_on_prime_coprime _ _ _ n,\n  { simp },\n  { intros p k hp,\n    rw [sum_divisors_prime_pow hp, cast_pow, real.log_pow, finset.sum_range_succ', pow_zero,\n      von_mangoldt_apply_one],\n    simp [von_mangoldt_apply_pow (nat.succ_ne_zero _), von_mangoldt_apply_prime hp] },\n  intros a b ha' hb' hab ha hb,\n  simp only [von_mangoldt_apply, \u2190sum_filter] at ha hb \u22a2,\n  rw [mul_divisors_filter_prime_pow hab, filter_union,\n    sum_union (disjoint_divisors_filter_prime_pow hab), ha, hb, nat.cast_mul,\n    real.log_mul (nat.cast_ne_zero.2 ha'.ne') (nat.cast_ne_zero.2 hb'.ne')],\nend\n\n@[simp] lemma von_mangoldt_mul_zeta : \u039b * \u03b6 = log :=\nby { ext n, rw [coe_mul_zeta_apply, von_mangoldt_sum], refl }\n\n@[simp] lemma zeta_mul_von_mangoldt : (\u03b6 : arithmetic_function \u211d) * \u039b = log :=\nby { rw [mul_comm], simp }\n\n@[simp] \n\n@[simp] lemma moebius_mul_log_eq_von_mangoldt : (\u03bc : arithmetic_function \u211d) * log = \u039b :=\nby { rw [mul_comm], simp }\n\nlemma sum_moebius_mul_log_eq {n : \u2115} :\n  \u2211 d in n.divisors, (\u03bc d : \u211d) * log d = - \u039b n :=\nbegin\n  simp only [\u2190log_mul_moebius_eq_von_mangoldt, mul_comm log, mul_apply, log_apply, int_coe_apply,\n    \u2190finset.sum_neg_distrib, neg_mul_eq_mul_neg],\n  rw sum_divisors_antidiagonal (\u03bb i j, (\u03bc i : \u211d) * -real.log j),\n  have : \u2211 (i : \u2115) in n.divisors, (\u03bc i : \u211d) * -real.log (n / i : \u2115) =\n         \u2211 (i : \u2115) in n.divisors, ((\u03bc i : \u211d) * real.log i - \u03bc i * real.log n),\n  { apply sum_congr rfl,\n    simp only [and_imp, int.cast_eq_zero, mul_eq_mul_left_iff, ne.def, neg_inj, mem_divisors],\n    intros m mn hn,\n    have : (m : \u211d) \u2260 0,\n    { rw [cast_ne_zero],\n      rintro rfl,\n      exact hn (by simpa using mn) },\n    rw [nat.cast_dvd mn this, real.log_div (cast_ne_zero.2 hn) this, neg_sub, mul_sub] },\n  rw [this, sum_sub_distrib, \u2190sum_mul, \u2190int.cast_sum, \u2190coe_mul_zeta_apply, eq_comm, sub_eq_self,\n    moebius_mul_coe_zeta, mul_eq_zero, int.cast_eq_zero],\n  rcases eq_or_ne n 1 with hn | hn;\n  simp [hn],\nend\n\nend arithmetic_function\nend nat\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/number_theory/von_mangoldt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7404057915822941}}
{"text": "import algebra.group.basic\n\n\nlemma right_inverse_eq_left_inverse {T : Type} [monoid T]\n  {a b c : T} (inv_right : a * b = 1) (inv_left : c * a = 1) :\n  b = c :=\ncalc b = 1 * b : (one_mul b).symm\n... = (c * a) * b : by rw inv_left\n... = c * (a * b) : mul_assoc c a b\n... = c * 1 : by rw inv_right\n... = c : mul_one c\n\n\nlemma right_inverse_unique {T : Type} [group T]\n  {a b c : T} (inv_ab : a * b = 1) (inv_ac : a * c = 1) :\n  b = c :=\ncalc b = 1 * b : (one_mul b).symm\n... = (a\u207b\u00b9 * a) * b : by rw mul_left_inv\n... = a\u207b\u00b9 * (a * b) : mul_assoc a\u207b\u00b9 a b\n... = a\u207b\u00b9 * 1 : by rw inv_ab\n... = a\u207b\u00b9 * (a * c) : by rw inv_ac\n... = (a\u207b\u00b9 * a) * c : (mul_assoc a\u207b\u00b9 a c).symm\n... = 1 * c : by rw mul_left_inv\n... = c : one_mul c\n\nlemma right_inverse_unique_aux {T : Type} [group T]\n  {a b : T} (inv_ab : a * b = 1) :\n  b = a\u207b\u00b9 :=\ncalc b = 1 * b : (one_mul b).symm\n... = (a\u207b\u00b9 * a) * b : by rw mul_left_inv\n... = a\u207b\u00b9 * (a * b) : mul_assoc a\u207b\u00b9 a b\n... = a\u207b\u00b9 * 1 : by rw inv_ab\n... = a\u207b\u00b9 : mul_one a\u207b\u00b9\n\nlemma right_inverse_unique' {T : Type} [group T]\n  {a b c : T} (inv_ab : a * b = 1) (inv_ac : a * c = 1) :\n  b = c :=\nbegin\n  rw right_inverse_unique_aux inv_ab,\n  rw right_inverse_unique_aux inv_ac,\nend\n", "meta": {"author": "madvorak", "repo": "Lean-first-steps", "sha": "4cfee162afaa53b589ec7a94986d78d75cf1c85e", "save_path": "github-repos/lean/madvorak-Lean-first-steps", "path": "github-repos/lean/madvorak-Lean-first-steps/Lean-first-steps-4cfee162afaa53b589ec7a94986d78d75cf1c85e/src/Group_oida.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.740372896816216}}
{"text": "import tactic\nimport tactic.suggest\nimport tactic.nth_rewrite\nimport data.fintype.basic\nimport data.setoid.partition\n\nvariables {\u03b1 : Type} {\u03b2 : Type} {\u03b3 : Type}\n\nopen_locale classical\nopen_locale big_operators\n\nlemma lift_disjoint_to_finset (s1 s2 : set \u03b1) [fintype \u03b1] (h : disjoint s1 s2) : disjoint s1.to_finset s2.to_finset :=\nbegin\n    intros a hinter,\n    have hset : a \u2208 \u2205,\n    {\n        rw \u2190set.bot_eq_empty,\n        rw \u2190le_bot_iff.mp h,\n        apply (set.mem_inter_iff a s1 s2).mpr ,\n        split,\n        exact set.mem_to_finset.mp (finset.mem_of_mem_inter_left hinter),\n        exact set.mem_to_finset.mp (finset.mem_of_mem_inter_right hinter),\n    },\n    exfalso,\n    apply set.not_mem_empty a hset,\nend\n\nlemma to_finset_bind_eq_univ_of_partition {c : set (set \u03b1)} [fintype \u03b1] (h : setoid.is_partition c) :\n    (set.to_finset c).bind(\u03bb (x : set \u03b1), x.to_finset) = finset.univ :=\nbegin\n    ext,\n    split,\n    {\n        simp,\n    },\n    {\n        intro ha,\n        rw finset.mem_bind,\n        cases h.2 a with s hs,\n        simp at hs,\n        use s,\n        rcases hs with \u27e8\u27e8hmemsc, hmemas\u27e9, _\u27e9,\n        split,\n        {\n            exact set.mem_to_finset.mpr hmemsc,\n        },\n        {\n            exact set.mem_to_finset.mpr hmemas,\n        }\n    }\nend\n\nlemma sum_card_partition {c : set (set \u03b1)} [fintype \u03b1] (h : setoid.is_partition c):\n    fintype.card \u03b1 = \u2211 x in (set.to_finset c), (set.to_finset x).card := begin\n    /- proof idea: |\u03b1| = \u2211 x in \u03b1, 1 = \u2211 x in (\u22c3 s in c, s), 1\n                       = \u2211 s in c, (\u2211 x in s, 1)\n                       = \u2211 s in c, |s|  -/\n    conv\n    begin\n        to_rhs,\n        congr,\n        skip,\n        funext,\n        rw finset.card_eq_sum_ones,\n    end,\n    have hdisjoint : \u2200 (x : set \u03b1), x \u2208 c.to_finset \u2192 \u2200 (y : set \u03b1), y \u2208 c.to_finset \u2192 x \u2260 y \u2192 disjoint x.to_finset y.to_finset,\n    {\n        intros x hx y hy hne,\n        apply lift_disjoint_to_finset,\n        exact setoid.is_partition.pairwise_disjoint h x (set.mem_to_finset.mp hx) y (set.mem_to_finset.mp hy) hne,\n    },\n    rw \u2190 finset.sum_bind hdisjoint,\n    rw \u2190finset.card_eq_sum_ones,\n    rw to_finset_bind_eq_univ_of_partition h,\n    exact finset.card_univ.symm,\nend\n\n", "meta": {"author": "cfbolz", "repo": "lean-carddisjointunion", "sha": "33b9013419de7eb9d62a40bf132537dfa224fd0f", "save_path": "github-repos/lean/cfbolz-lean-carddisjointunion", "path": "github-repos/lean/cfbolz-lean-carddisjointunion/lean-carddisjointunion-33b9013419de7eb9d62a40bf132537dfa224fd0f/src/carddisjointunion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7403728808249094}}
{"text": "import data.nat.digits\n\nopen nat\nopen int\n\n/-\n(a) Prove the \"rule of 9\": an integer is divisible by 9 if and only if the sum of its digits is divisible by 9.\n(b) Prove the \"rule of 11\" stated in Example 13.6. Use this rule to decide in your head whether the number 82918073579 is divisible by 11.\n-/\n\nlemma part_a (n : \u2124) : 9 \u2223 n \u2194 9 \u2223 (digits 10 n.nat_abs).sum :=\nbegin\n  sorry\nend\n\nlemma part_b (n : \u2124) : 11 \u2223 n \u2194 (11 : \u2124) \u2223 ((digits 10 n.nat_abs).map (\u03bb (n : \u2115), \u2191n)).alternating_sum :=\nbegin\n  sorry\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "m1fexplained_lean3", "sha": "570c9a3ff8cfc3805047f2796864516a49f51510", "save_path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3", "path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3/m1fexplained_lean3-570c9a3ff8cfc3805047f2796864516a49f51510/src/chapter13/exercises/exercise04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7403266501033186}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nimport AdditionWorld.Level1 -- zero_add\nimport AdditionWorld.Level2 -- add_assoc\nnamespace MyNat\nopen MyNat\n\n/-!\n# Multiplication World\n\n## Level 4: `mul_add`\n\nWhere are we going? Well we want to prove `mul_comm`\nand `mul_assoc`, i.e. that `a * b = b * a` and\n`(a * b) * c = a * (b * c)`. But we *also* want to\nestablish the way multiplication interacts with addition,\ni.e. we want to prove that we can \"expand out the brackets\"\nand show `a * (b + c) = (a * b) + (a * c)`.\nThe technical term for this is \"left distributivity of\nmultiplication over addition\" (there is also right distributivity,\nwhich we'll get to later).\n\nNote the name of this proof -- `mul_add`. And note the left\nhand side -- `a * (b + c)`, a multiplication and then an addition.\nI think `mul_add` is much easier to remember than \"left_distrib\",\nan alternative name for the proof of this lemma.\n\n## Lemma\n\nMultiplication is distributive over addition.\nIn other words, for all natural numbers `a`, `b` and `t`, we have\n` t(a + b) = ta + tb. `\n-/\n\nlemma mul_add (t a b : MyNat) : t * (a + b) = t * a + t * b := by\n  induction b with\n  | zero =>\n     rw [zero_is_0, add_zero, mul_zero, add_zero]\n  | succ b ih =>\n    rw [add_succ]\n    rw [mul_succ]\n    rw [ih]\n    rw [mul_succ]\n    rw [add_assoc]\n\ndef left_distrib := mul_add -- the \"proper\" name for this lemma\n\n\n/-!\nNext up is [Multiplication Level 5](./Level5.lean.md).\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/MultiplicationWorld/Level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7403266424316635}}
{"text": "import algebra.group group_theory.subgroup\n\nvariables {G: Type*}\n\ndef normaliser (a: G) [group G]: set G :=\n  { x: G | a * x = x * a }\n\ntheorem Q_13 (a: G) [group G]:\n  is_subgroup (normaliser a) := {\n  one_mem := calc\n    a * 1 = 1 * a: by rw [mul_one, one_mul],\n\n  mul_mem := \u03bb g h hg hh, calc\n    a * (g * h) = (a * g) * h  : (mul_assoc _ _ _).symm\n    ...         = (g * a) * h  : hg \u25b8 rfl\n    ...         =  g * (a * h) : mul_assoc _ _ _\n    ...         =  g * (h * a) : hh \u25b8 rfl\n    ...         = (g * h) * a  : (mul_assoc _ _ _).symm,\n\n  inv_mem := \u03bb g hg, calc\n    a * g\u207b\u00b9 = (g\u207b\u00b9 * g) * (a * g\u207b\u00b9)  : (mul_left_inv g).symm \u25b8 (one_mul _).symm\n    ...     =  g\u207b\u00b9 * (g * a) * g\u207b\u00b9   : by rw [ \u2190mul_assoc, mul_assoc g\u207b\u00b9 ]\n    ...     =  g\u207b\u00b9 * (a * g) * g\u207b\u00b9   : hg \u25b8 rfl\n    ...     = (g\u207b\u00b9 * a) * g  * g\u207b\u00b9   : mul_assoc g\u207b\u00b9 a g \u25b8 rfl\n    ...     =  g\u207b\u00b9 * a               : mul_inv_cancel_right (g\u207b\u00b9 * a) g\n}\n", "meta": {"author": "group-study-group", "repo": "herstein", "sha": "f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66", "save_path": "github-repos/lean/group-study-group-herstein", "path": "github-repos/lean/group-study-group-herstein/herstein-f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66/src/herstein/ex2_5/Q_13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.7403266416172452}}
{"text": "/-\nCopyright (c) 2022 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport data.nat.log\nimport algebra.order.floor\nimport algebra.field_power\n\n/-!\n# Integer logarithms in a field with respect to a natural base\n\nThis file defines two `\u2124`-valued analogs of the logarithm of `r : R` with base `b : \u2115`:\n\n* `int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `\u2191b^k \u2264 r`.\n* `int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r \u2264 \u2191b^k`.\n\nNote that `int.log` gives the position of the left-most non-zero digit:\n```lean\n#eval (int.log 10 (0.09 : \u211a), int.log 10 (0.10 : \u211a), int.log 10 (0.11 : \u211a))\n--    (-2,                    -1,                    -1)\n#eval (int.log 10 (9 : \u211a),    int.log 10 (10 : \u211a),   int.log 10 (11 : \u211a))\n--    (0,                     1,                     1)\n```\nwhich means it can be used for computing digit expansions\n```lean\nimport data.fin.vec_notation\n\ndef digits (b : \u2115) (q : \u211a) (n : \u2115) : \u2115 :=\n\u230aq*b^(\u2191n - int.log b q)\u230b\u208a % b\n\n#eval digits 10 (1/7) \u2218 (coe : fin 8 \u2192 \u2115)\n-- ![1, 4, 2, 8, 5, 7, 1, 4]\n```\n\n## Main results\n\n* For `int.log`:\n  * `int.zpow_log_le_self`, `int.lt_zpow_succ_log_self`: the bounds formed by `int.log`,\n    `(b : R) ^ log b r \u2264 r < (b : R) ^ (log b r + 1)`.\n  * `int.zpow_log_gi`: the galois coinsertion between `zpow` and `int.log`.\n* For `int.clog`:\n  * `int.zpow_pred_clog_lt_self`, `int.self_le_zpow_clog`: the bounds formed by `int.clog`,\n    `(b : R) ^ (clog b r - 1) < r \u2264 (b : R) ^ clog b r`.\n  * `int.clog_zpow_gi`:  the galois insertion between `int.clog` and `zpow`.\n* `int.neg_log_inv_eq_clog`, `int.neg_clog_inv_eq_log`: the link between the two definitions.\n-/\n\nvariables {R : Type*} [linear_ordered_semifield R] [floor_semiring R]\n\nnamespace int\n\n/-- The greatest power of `b` such that `b ^ log b r \u2264 r`. -/\ndef log (b : \u2115) (r : R) : \u2124 :=\nif 1 \u2264 r then\n  nat.log b \u230ar\u230b\u208a\nelse\n  -nat.clog b \u2308r\u207b\u00b9\u2309\u208a\n\nlemma log_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : log b r = nat.log b \u230ar\u230b\u208a :=\nif_pos hr\n\nlemma log_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : log b r = -nat.clog b \u2308r\u207b\u00b9\u2309\u208a :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [log, if_pos hr, inv_one, nat.ceil_one, nat.floor_one, nat.log_one_right, nat.clog_one_right,\n        int.coe_nat_zero, neg_zero], },\n  { exact if_neg hr.not_le }\nend\n\n@[simp, norm_cast] lemma log_nat_cast (b : \u2115) (n : \u2115) : log b (n : R) = nat.log b n :=\nbegin\n  cases n,\n  { simp [log_of_right_le_one _ _, nat.log_zero_right] },\n  { have : 1 \u2264 (n.succ : R) := by simp,\n    simp [log_of_one_le_right _ this, \u2190nat.cast_succ] }\nend\n\nlemma log_of_left_le_one {b : \u2115} (hb : b \u2264 1) (r : R) : log b r = 0 :=\nbegin\n  cases le_total 1 r,\n  { rw [log_of_one_le_right _ h, nat.log_of_left_le_one hb, int.coe_nat_zero] },\n  { rw [log_of_right_le_one _ h, nat.clog_of_left_le_one hb, int.coe_nat_zero, neg_zero] },\nend\n\nlemma log_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : log b r = 0 :=\nby rw [log_of_right_le_one _ (hr.trans zero_le_one),\n    nat.clog_of_right_le_one ((nat.ceil_eq_zero.mpr $ inv_nonpos.2 hr).trans_le zero_le_one),\n    int.coe_nat_zero, neg_zero]\n\nlemma zpow_log_le_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) :\n  (b : R) ^ log b r \u2264 r :=\nbegin\n  cases le_total 1 r with hr1 hr1,\n  { rw log_of_one_le_right _ hr1,\n    refine le_trans _ (nat.floor_le hr.le),\n    rw [zpow_coe_nat, \u2190nat.cast_pow, nat.cast_le],\n    exact nat.pow_log_le_self hb (nat.floor_pos.mpr hr1) },\n  { rw [log_of_right_le_one _ hr1, zpow_neg, zpow_coe_nat, \u2190 nat.cast_pow],\n    apply inv_le_of_inv_le hr,\n    refine (nat.le_ceil _).trans (nat.cast_le.2 _),\n    exact nat.le_pow_clog hb _ },\nend\n\nlemma lt_zpow_succ_log_self {b : \u2115} (hb : 1 < b) (r : R) :\n  r < (b : R) ^ (log b r + 1) :=\nbegin\n  cases le_or_lt r 0 with hr hr,\n  { rw [log_of_right_le_zero _ hr, zero_add, zpow_one],\n    exact hr.trans_lt (zero_lt_one.trans_le $ by exact_mod_cast hb.le) },\n  cases le_or_lt 1 r with hr1 hr1,\n  { rw log_of_one_le_right _ hr1,\n    rw [int.coe_nat_add_one_out, zpow_coe_nat, \u2190nat.cast_pow],\n    apply nat.lt_of_floor_lt,\n    exact nat.lt_pow_succ_log_self hb _, },\n  { rw log_of_right_le_one _ hr1.le,\n    have hcri : 1 < r\u207b\u00b9 := one_lt_inv hr hr1,\n    have : 1 \u2264 nat.clog b \u2308r\u207b\u00b9\u2309\u208a :=\n      nat.succ_le_of_lt (nat.clog_pos hb $ nat.one_lt_cast.1 $ hcri.trans_le (nat.le_ceil _)),\n    rw [neg_add_eq_sub, \u2190neg_sub, \u2190int.coe_nat_one, \u2190 int.coe_nat_sub this,\n      zpow_neg, zpow_coe_nat, lt_inv hr (pow_pos (nat.cast_pos.mpr $ zero_lt_one.trans hb) _),\n      \u2190nat.cast_pow],\n    refine nat.lt_ceil.1 _,\n    exact (nat.pow_pred_clog_lt_self hb $ nat.one_lt_cast.1 $ hcri.trans_le $ nat.le_ceil _), }\nend\n\n@[simp] lemma log_zero_right (b : \u2115) : log b (0 : R) = 0 :=\nlog_of_right_le_zero b le_rfl\n\n@[simp] lemma log_one_right (b : \u2115) : log b (1 : R) = 0 :=\nby rw [log_of_one_le_right _ le_rfl, nat.floor_one, nat.log_one_right, int.coe_nat_zero]\n\nlemma log_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : log b (b ^ z : R) = z :=\nbegin\n  obtain \u27e8n, rfl | rfl\u27e9 := z.eq_coe_or_neg,\n  { rw [log_of_one_le_right _ (one_le_zpow_of_nonneg _ $ int.coe_nat_nonneg _),\n      zpow_coe_nat, \u2190nat.cast_pow, nat.floor_coe, nat.log_pow hb],\n    exact_mod_cast hb.le, },\n  { rw [log_of_right_le_one _ (zpow_le_one_of_nonpos _ $ neg_nonpos.mpr (int.coe_nat_nonneg _)),\n      zpow_neg, inv_inv, zpow_coe_nat, \u2190nat.cast_pow, nat.ceil_coe, nat.clog_pow _ _ hb],\n    exact_mod_cast hb.le, },\nend\n\n@[mono] lemma log_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) :\n  log b r\u2081 \u2264 log b r\u2082 :=\nbegin\n  cases le_or_lt b 1 with hb hb,\n  { rw [log_of_left_le_one hb, log_of_left_le_one hb], },\n  cases le_total r\u2081 1 with h\u2081 h\u2081; cases le_total r\u2082 1 with h\u2082 h\u2082,\n  { rw [log_of_right_le_one _ h\u2081, log_of_right_le_one _ h\u2082, neg_le_neg_iff, int.coe_nat_le],\n    exact nat.clog_mono_right _ (nat.ceil_mono $ inv_le_inv_of_le h\u2080 h), },\n  { rw [log_of_right_le_one _ h\u2081, log_of_one_le_right _ h\u2082],\n    exact (neg_nonpos.mpr (int.coe_nat_nonneg _)).trans (int.coe_nat_nonneg _) },\n  { obtain rfl := le_antisymm h (h\u2082.trans h\u2081), refl, },\n  { rw [log_of_one_le_right _ h\u2081, log_of_one_le_right _ h\u2082, int.coe_nat_le],\n    exact nat.log_mono_right (nat.floor_mono h), },\nend\n\nvariables (R)\n\n/-- Over suitable subtypes, `zpow` and `int.log` form a galois coinsertion -/\ndef zpow_log_gi {b : \u2115} (hb : 1 < b) :\n  galois_coinsertion\n    (\u03bb z : \u2124, subtype.mk ((b : R) ^ z) $ zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z)\n    (\u03bb r : set.Ioi (0 : R), int.log b (r : R)) :=\ngalois_coinsertion.monotone_intro\n  (\u03bb r\u2081 r\u2082, log_mono_right r\u2081.prop)\n  (\u03bb z\u2081 z\u2082 hz, subtype.coe_le_coe.mp $ (zpow_strict_mono $ by exact_mod_cast hb).monotone hz)\n  (\u03bb r, subtype.coe_le_coe.mp $ zpow_log_le_self hb r.prop)\n  (\u03bb _, log_zpow hb _)\n\nvariables {R}\n\n/-- `zpow b` and `int.log b` (almost) form a Galois connection. -/\nlemma lt_zpow_iff_log_lt {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  r < (b : R) ^ x \u2194 log b r < x :=\n@galois_connection.lt_iff_lt _ _ _ _ _ _ (zpow_log_gi R hb).gc x \u27e8r, hr\u27e9\n\n/-- `zpow b` and `int.log b` (almost) form a Galois connection. -/\nlemma zpow_le_iff_le_log {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  (b : R) ^ x \u2264 r \u2194 x \u2264 log b r :=\n@galois_connection.le_iff_le _ _ _ _ _ _ (zpow_log_gi R hb).gc x \u27e8r, hr\u27e9\n\n/-- The least power of `b` such that `r \u2264 b ^ log b r`. -/\ndef clog (b : \u2115) (r : R) : \u2124 :=\nif 1 \u2264 r then\n  nat.clog b \u2308r\u2309\u208a\nelse\n  -nat.log b \u230ar\u207b\u00b9\u230b\u208a\n\nlemma clog_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : clog b r = nat.clog b \u2308r\u2309\u208a :=\nif_pos hr\n\nlemma clog_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : clog b r = -nat.log b \u230ar\u207b\u00b9\u230b\u208a :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [clog, if_pos hr, inv_one, nat.ceil_one, nat.floor_one, nat.log_one_right,\n        nat.clog_one_right, int.coe_nat_zero, neg_zero], },\n  { exact if_neg hr.not_le }\nend\n\nlemma clog_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : clog b r = 0 :=\nbegin\n  rw [clog, if_neg (hr.trans_lt zero_lt_one).not_le, neg_eq_zero, int.coe_nat_eq_zero,\n    nat.log_eq_zero_iff],\n  cases le_or_lt b 1 with hb hb,\n  { exact or.inr hb },\n  { refine or.inl (lt_of_le_of_lt _ hb),\n    exact nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one) },\nend\n\n@[simp] lemma clog_inv (b : \u2115) (r : R) : clog b r\u207b\u00b9 = -log b r :=\nbegin\n  cases lt_or_le 0 r with hrp hrp,\n  { obtain hr | hr := le_total 1 r,\n    { rw [clog_of_right_le_one _ (inv_le_one hr), log_of_one_le_right _ hr, inv_inv] },\n    { rw [clog_of_one_le_right _ (one_le_inv hrp hr),  log_of_right_le_one _ hr, neg_neg] }, },\n  { rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero], },\nend\n\n@[simp] lemma log_inv (b : \u2115) (r : R) : log b r\u207b\u00b9 = -clog b r :=\nby rw [\u2190inv_inv r, clog_inv, neg_neg, inv_inv]\n\n-- note this is useful for writing in reverse\nlemma neg_log_inv_eq_clog (b : \u2115) (r : R) : -log b r\u207b\u00b9 = clog b r :=\nby rw [log_inv, neg_neg]\n\nlemma neg_clog_inv_eq_log (b : \u2115) (r : R) : -clog b r\u207b\u00b9 = log b r :=\nby rw [clog_inv, neg_neg]\n\n@[simp, norm_cast] lemma clog_nat_cast (b : \u2115) (n : \u2115) : clog b (n : R) = nat.clog b n :=\nbegin\n  cases n,\n  { simp [clog_of_right_le_one _ _, nat.clog_zero_right] },\n  { have : 1 \u2264 (n.succ : R) := by simp,\n    simp [clog_of_one_le_right _ this, \u2190nat.cast_succ] }\nend\n\nlemma clog_of_left_le_one {b : \u2115} (hb : b \u2264 1) (r : R) : clog b r = 0 :=\nby rw [\u2190neg_log_inv_eq_clog, log_of_left_le_one hb, neg_zero]\n\nlemma self_le_zpow_clog {b : \u2115} (hb : 1 < b) (r : R) : r \u2264 (b : R) ^ clog b r :=\nbegin\n  cases le_or_lt r 0 with hr hr,\n  { rw [clog_of_right_le_zero _ hr, zpow_zero],\n    exact hr.trans zero_le_one },\n  rw [\u2190neg_log_inv_eq_clog, zpow_neg, le_inv hr (zpow_pos_of_pos _ _)],\n  { exact zpow_log_le_self hb (inv_pos.mpr hr), },\n  { exact nat.cast_pos.mpr (zero_le_one.trans_lt hb), },\nend\n\nlemma zpow_pred_clog_lt_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) :\n  (b : R) ^ (clog b r - 1) < r :=\nbegin\n  rw [\u2190neg_log_inv_eq_clog, \u2190neg_add', zpow_neg, inv_lt _ hr],\n  { exact lt_zpow_succ_log_self hb _, },\n  { exact zpow_pos_of_pos (nat.cast_pos.mpr $ zero_le_one.trans_lt hb) _ }\nend\n\n@[simp] lemma clog_zero_right (b : \u2115) : clog b (0 : R) = 0 :=\nclog_of_right_le_zero _ le_rfl\n\n@[simp] lemma clog_one_right (b : \u2115) : clog b (1 : R) = 0 :=\nby rw [clog_of_one_le_right _ le_rfl, nat.ceil_one, nat.clog_one_right, int.coe_nat_zero]\n\nlemma clog_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : clog b (b ^ z : R) = z :=\nby rw [\u2190neg_log_inv_eq_clog, \u2190zpow_neg, log_zpow hb, neg_neg]\n\n@[mono] lemma clog_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) :\n  clog b r\u2081 \u2264 clog b r\u2082 :=\nbegin\n  rw [\u2190neg_log_inv_eq_clog, \u2190neg_log_inv_eq_clog, neg_le_neg_iff],\n  exact log_mono_right (inv_pos.mpr $ h\u2080.trans_le h) (inv_le_inv_of_le h\u2080 h),\nend\n\nvariables (R)\n/-- Over suitable subtypes, `int.clog` and `zpow` form a galois insertion -/\ndef clog_zpow_gi {b : \u2115} (hb : 1 < b) :\n  galois_insertion\n    (\u03bb r : set.Ioi (0 : R), int.clog b (r : R))\n    (\u03bb z : \u2124, \u27e8(b : R) ^ z, zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z\u27e9) :=\ngalois_insertion.monotone_intro\n  (\u03bb z\u2081 z\u2082 hz, subtype.coe_le_coe.mp $ (zpow_strict_mono $ by exact_mod_cast hb).monotone hz)\n  (\u03bb r\u2081 r\u2082, clog_mono_right r\u2081.prop)\n  (\u03bb r, subtype.coe_le_coe.mp $ self_le_zpow_clog hb _)\n  (\u03bb _, clog_zpow hb _)\nvariables {R}\n\n/-- `int.clog b` and `zpow b` (almost) form a Galois connection. -/\nlemma zpow_lt_iff_lt_clog {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  (b : R) ^ x < r \u2194 x < clog b r :=\n(@galois_connection.lt_iff_lt _ _ _ _ _ _ (clog_zpow_gi R hb).gc \u27e8r, hr\u27e9 x).symm\n\n/-- `int.clog b` and `zpow b` (almost) form a Galois connection. -/\nlemma le_zpow_iff_clog_le {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  r \u2264 (b : R) ^ x \u2194 clog b r \u2264 x :=\n(@galois_connection.le_iff_le _ _ _ _ _ _ (clog_zpow_gi R hb).gc \u27e8r, hr\u27e9 x).symm\n\nend int\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/data/int/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7402781305916751}}
{"text": "import tactic\nimport data.nat.basic\nimport data.nat.parity\n\n\nnoncomputable theory\nopen_locale classical\n\nopen nat\n\n--BEGIN--\n/-\nnat.prime.dvd_of_dvd_pow : \u2200 {p m n : \u2115}, p.prime \u2192 p \u2223 m ^ n \u2192 p \u2223 m\n\nChallenge mode: start with nat.even_or_odd instead\n-/\nlemma two_dvd_of_two_dvd_sq {k : \u2115} (hk : 2 \u2223 k^2) :\n  2 \u2223 k :=\nbegin\n  sorry,\nend\n\nlemma division_lemma_n {m n : \u2115}\n  (hmn : 2 * m ^ 2 = n ^ 2)\n: 2 \u2223 n :=\nbegin\n  sorry,\nend\n\nlemma div_2 {m n : \u2115} (hnm : 2 * m = 2 * n) : (m = n) :=\nbegin\n  linarith,\nend\n\nlemma division_lemma_m {m n : \u2115}\n  (hmn : 2 * m ^ 2 = n ^ 2)\n: 2 \u2223 m :=\nbegin\n  sorry,\nend\n--END--", "meta": {"author": "awainverse", "repo": "mc2022-lean-examples", "sha": "91d4db1f785dbaa806831f3cdd8846ca45e2891e", "save_path": "github-repos/lean/awainverse-mc2022-lean-examples", "path": "github-repos/lean/awainverse-mc2022-lean-examples/mc2022-lean-examples-91d4db1f785dbaa806831f3cdd8846ca45e2891e/src/day4/coprime_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7402091172729871}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar el teorema de Cantor: No existe singuna\n-- aplicaci\u00f3n suprayectiva de un conjunto en su conjunto potencia.\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\n\nopen function\n\nvariable {\u03b1 : Type*}\n\ntheorem Cantor : \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f :=\nbegin\n  intros f surjf,\n  let S := {i | i \u2209 f i},\n  cases surjf S with j hj,\n  have h\u2081 : j \u2209 f j,\n  { intro h',\n    have : j \u2209 f j,\n      { by rwa hj at h' },\n    contradiction },\n  have h\u2082 : j \u2208 S,\n    from h\u2081,\n  have h\u2083 : j \u2209 S,\n    by rwa hj at h\u2081,\n  contradiction,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1\n\u22a2 \u2200 (f : \u03b1 \u2192 set \u03b1), \u00acsurjective f\n  >> intros f surjf,\nf : \u03b1 \u2192 set \u03b1,\nsurjf : surjective f\n\u22a2 false\n  >> let S := { i | i \u2209 f i},\nS : set \u03b1 := {i : \u03b1 | i \u2209 f i}\n\u22a2 false\n  >> rcases surjf S with j,\nj : \u03b1,\nh : f j = S\n\u22a2 false\n  >> have h\u2081 : j \u2209 f j,\n| \u22a2 j \u2209 f j\n|   >> { intro h',\n| h' : j \u2208 f j\n| \u22a2 false\n|   >>   have : j \u2209 f j,\n| | \u22a2 j \u2209 f j\n| |   >>     { by rwa h at h' },\n| this : j \u2209 f j\n| \u22a2 false\n|   >>   contradiction },\nh\u2081 : j \u2209 f j\n\u22a2 false\n  >> have h\u2082 : j \u2208 S,\n| \u22a2 j \u2208 S\n|   >>   from h\u2081,\nh\u2082 : j \u2208 S\n\u22a2 false\n  >> have h\u2083 : j \u2209 S,\n  >>   by rwa h at h\u2081,\nh\u2083 : j \u2209 S\n\u22a2 false\n  >> contradiction,\nno goals\n-/\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Teorema_de_Cantor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7401155865993606}}
{"text": "/-\nCopyright (c) 2022 Kalle Kyt\u00f6l\u00e4. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kyt\u00f6l\u00e4\n\n! This file was ported from Lean 3 source module topology.metric_space.thickened_indicator\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Real.Ennreal\nimport Mathbin.Topology.ContinuousFunction.Bounded\nimport Mathbin.Topology.MetricSpace.HausdorffDistance\n\n/-!\n# Thickened indicators\n\nThis file is about thickened indicators of sets in (pseudo e)metric spaces. For a decreasing\nsequence of thickening radii tending to 0, the thickened indicators of a closed set form a\ndecreasing pointwise converging approximation of the indicator function of the set, where the\nmembers of the approximating sequence are nonnegative bounded continuous functions.\n\n## Main definitions\n\n * `thickened_indicator_aux \u03b4 E`: The `\u03b4`-thickened indicator of a set `E` as an\n   unbundled `\u211d\u22650\u221e`-valued function.\n * `thickened_indicator \u03b4 E`: The `\u03b4`-thickened indicator of a set `E` as a bundled\n   bounded continuous `\u211d\u22650`-valued function.\n\n## Main results\n\n * For a sequence of thickening radii tending to 0, the `\u03b4`-thickened indicators of a set `E` tend\n   pointwise to the indicator of `closure E`.\n   - `thickened_indicator_aux_tendsto_indicator_closure`: The version is for the\n     unbundled `\u211d\u22650\u221e`-valued functions.\n   - `thickened_indicator_tendsto_indicator_closure`: The version is for the bundled `\u211d\u22650`-valued\n     bounded continuous functions.\n\n-/\n\n\nnoncomputable section\n\nopen Classical NNReal ENNReal Topology BoundedContinuousFunction\n\nopen NNReal ENNReal Set Metric Emetric Filter\n\nsection thickenedIndicator\n\nvariable {\u03b1 : Type _} [PseudoEMetricSpace \u03b1]\n\n/-- The `\u03b4`-thickened indicator of a set `E` is the function that equals `1` on `E`\nand `0` outside a `\u03b4`-thickening of `E` and interpolates (continuously) between\nthese values using `inf_edist _ E`.\n\n`thickened_indicator_aux` is the unbundled `\u211d\u22650\u221e`-valued function. See `thickened_indicator`\nfor the (bundled) bounded continuous function with `\u211d\u22650`-values. -/\ndef thickenedIndicatorAux (\u03b4 : \u211d) (E : Set \u03b1) : \u03b1 \u2192 \u211d\u22650\u221e := fun x : \u03b1 =>\n  (1 : \u211d\u22650\u221e) - infEdist x E / ENNReal.ofReal \u03b4\n#align thickened_indicator_aux thickenedIndicatorAux\n\ntheorem continuous_thickenedIndicatorAux {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) :\n    Continuous (thickenedIndicatorAux \u03b4 E) :=\n  by\n  unfold thickenedIndicatorAux\n  let f := fun x : \u03b1 => (\u27e81, inf_edist x E / ENNReal.ofReal \u03b4\u27e9 : \u211d\u22650 \u00d7 \u211d\u22650\u221e)\n  let sub := fun p : \u211d\u22650 \u00d7 \u211d\u22650\u221e => (p.1 : \u211d\u22650\u221e) - p.2\n  rw [show (fun x : \u03b1 => (1 : \u211d\u22650\u221e) - inf_edist x E / ENNReal.ofReal \u03b4) = sub \u2218 f by rfl]\n  apply (@ENNReal.continuous_nnreal_sub 1).comp\n  apply (ENNReal.continuous_div_const (ENNReal.ofReal \u03b4) _).comp continuous_inf_edist\n  norm_num [\u03b4_pos]\n#align continuous_thickened_indicator_aux continuous_thickenedIndicatorAux\n\ntheorem thickenedIndicatorAux_le_one (\u03b4 : \u211d) (E : Set \u03b1) (x : \u03b1) :\n    thickenedIndicatorAux \u03b4 E x \u2264 1 := by apply @tsub_le_self _ _ _ _ (1 : \u211d\u22650\u221e)\n#align thickened_indicator_aux_le_one thickenedIndicatorAux_le_one\n\ntheorem thickenedIndicatorAux_lt_top {\u03b4 : \u211d} {E : Set \u03b1} {x : \u03b1} :\n    thickenedIndicatorAux \u03b4 E x < \u221e :=\n  lt_of_le_of_lt (thickenedIndicatorAux_le_one _ _ _) one_lt_top\n#align thickened_indicator_aux_lt_top thickenedIndicatorAux_lt_top\n\ntheorem thickenedIndicatorAux_closure_eq (\u03b4 : \u211d) (E : Set \u03b1) :\n    thickenedIndicatorAux \u03b4 (closure E) = thickenedIndicatorAux \u03b4 E := by\n  simp_rw [thickenedIndicatorAux, inf_edist_closure]\n#align thickened_indicator_aux_closure_eq thickenedIndicatorAux_closure_eq\n\ntheorem thickenedIndicatorAux_one (\u03b4 : \u211d) (E : Set \u03b1) {x : \u03b1} (x_in_E : x \u2208 E) :\n    thickenedIndicatorAux \u03b4 E x = 1 := by\n  simp [thickenedIndicatorAux, inf_edist_zero_of_mem x_in_E, tsub_zero]\n#align thickened_indicator_aux_one thickenedIndicatorAux_one\n\ntheorem thickenedIndicatorAux_one_of_mem_closure (\u03b4 : \u211d) (E : Set \u03b1) {x : \u03b1}\n    (x_mem : x \u2208 closure E) : thickenedIndicatorAux \u03b4 E x = 1 := by\n  rw [\u2190 thickenedIndicatorAux_closure_eq, thickenedIndicatorAux_one \u03b4 (closure E) x_mem]\n#align thickened_indicator_aux_one_of_mem_closure thickenedIndicatorAux_one_of_mem_closure\n\ntheorem thickenedIndicatorAux_zero {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) {x : \u03b1}\n    (x_out : x \u2209 thickening \u03b4 E) : thickenedIndicatorAux \u03b4 E x = 0 :=\n  by\n  rw [thickening, mem_set_of_eq, not_lt] at x_out\n  unfold thickenedIndicatorAux\n  apply le_antisymm _ bot_le\n  have key := tsub_le_tsub (@rfl _ (1 : \u211d\u22650\u221e)).le (ENNReal.div_le_div x_out rfl.le)\n  rw [ENNReal.div_self (ne_of_gt (ennreal.of_real_pos.mpr \u03b4_pos)) of_real_ne_top] at key\n  simpa using key\n#align thickened_indicator_aux_zero thickenedIndicatorAux_zero\n\ntheorem thickenedIndicatorAux_mono {\u03b4\u2081 \u03b4\u2082 : \u211d} (hle : \u03b4\u2081 \u2264 \u03b4\u2082) (E : Set \u03b1) :\n    thickenedIndicatorAux \u03b4\u2081 E \u2264 thickenedIndicatorAux \u03b4\u2082 E := fun _ =>\n  tsub_le_tsub (@rfl \u211d\u22650\u221e 1).le (ENNReal.div_le_div rfl.le (ofReal_le_ofReal hle))\n#align thickened_indicator_aux_mono thickenedIndicatorAux_mono\n\ntheorem indicator_le_thickenedIndicatorAux (\u03b4 : \u211d) (E : Set \u03b1) :\n    (E.indicator fun _ => (1 : \u211d\u22650\u221e)) \u2264 thickenedIndicatorAux \u03b4 E :=\n  by\n  intro a\n  by_cases a \u2208 E\n  \u00b7 simp only [h, indicator_of_mem, thickenedIndicatorAux_one \u03b4 E h, le_refl]\n  \u00b7 simp only [h, indicator_of_not_mem, not_false_iff, zero_le]\n#align indicator_le_thickened_indicator_aux indicator_le_thickenedIndicatorAux\n\ntheorem thickenedIndicatorAux_subset (\u03b4 : \u211d) {E\u2081 E\u2082 : Set \u03b1} (subset : E\u2081 \u2286 E\u2082) :\n    thickenedIndicatorAux \u03b4 E\u2081 \u2264 thickenedIndicatorAux \u03b4 E\u2082 := fun _ =>\n  tsub_le_tsub (@rfl \u211d\u22650\u221e 1).le (ENNReal.div_le_div (infEdist_anti subset) rfl.le)\n#align thickened_indicator_aux_subset thickenedIndicatorAux_subset\n\n/-- As the thickening radius \u03b4 tends to 0, the \u03b4-thickened indicator of a set E (in \u03b1) tends\npointwise (i.e., w.r.t. the product topology on `\u03b1 \u2192 \u211d\u22650\u221e`) to the indicator function of the\nclosure of E.\n\nThis statement is for the unbundled `\u211d\u22650\u221e`-valued functions `thickened_indicator_aux \u03b4 E`, see\n`thickened_indicator_tendsto_indicator_closure` for the version for bundled `\u211d\u22650`-valued\nbounded continuous functions. -/\ntheorem thickenedIndicatorAux_tendsto_indicator_closure {\u03b4seq : \u2115 \u2192 \u211d}\n    (\u03b4seq_lim : Tendsto \u03b4seq atTop (\ud835\udcdd 0)) (E : Set \u03b1) :\n    Tendsto (fun n => thickenedIndicatorAux (\u03b4seq n) E) atTop\n      (\ud835\udcdd (indicator (closure E) fun x => (1 : \u211d\u22650\u221e))) :=\n  by\n  rw [tendsto_pi_nhds]\n  intro x\n  by_cases x_mem_closure : x \u2208 closure E\n  \u00b7 simp_rw [thickenedIndicatorAux_one_of_mem_closure _ E x_mem_closure]\n    rw [show (indicator (closure E) fun _ => (1 : \u211d\u22650\u221e)) x = 1 by\n        simp only [x_mem_closure, indicator_of_mem]]\n    exact tendsto_const_nhds\n  \u00b7 rw [show (closure E).indicator (fun _ => (1 : \u211d\u22650\u221e)) x = 0 by\n        simp only [x_mem_closure, indicator_of_not_mem, not_false_iff]]\n    rcases exists_real_pos_lt_inf_edist_of_not_mem_closure x_mem_closure with \u27e8\u03b5, \u27e8\u03b5_pos, \u03b5_lt\u27e9\u27e9\n    rw [Metric.tendsto_nhds] at \u03b4seq_lim\n    specialize \u03b4seq_lim \u03b5 \u03b5_pos\n    simp only [dist_zero_right, Real.norm_eq_abs, eventually_at_top, ge_iff_le] at \u03b4seq_lim\n    rcases \u03b4seq_lim with \u27e8N, hN\u27e9\n    apply @tendsto_atTop_of_eventually_const _ _ _ _ _ _ _ N\n    intro n n_large\n    have key : x \u2209 thickening \u03b5 E := by simpa only [thickening, mem_set_of_eq, not_lt] using \u03b5_lt.le\n    refine' le_antisymm _ bot_le\n    apply (thickenedIndicatorAux_mono (lt_of_abs_lt (hN n n_large)).le E x).trans\n    exact (thickenedIndicatorAux_zero \u03b5_pos E key).le\n#align thickened_indicator_aux_tendsto_indicator_closure thickenedIndicatorAux_tendsto_indicator_closure\n\n/-- The `\u03b4`-thickened indicator of a set `E` is the function that equals `1` on `E`\nand `0` outside a `\u03b4`-thickening of `E` and interpolates (continuously) between\nthese values using `inf_edist _ E`.\n\n`thickened_indicator` is the (bundled) bounded continuous function with `\u211d\u22650`-values.\nSee `thickened_indicator_aux` for the unbundled `\u211d\u22650\u221e`-valued function. -/\n@[simps]\ndef thickenedIndicator {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) : \u03b1 \u2192\u1d47 \u211d\u22650\n    where\n  toFun := fun x : \u03b1 => (thickenedIndicatorAux \u03b4 E x).toNNReal\n  continuous_toFun :=\n    by\n    apply\n      ContinuousOn.comp_continuous continuous_on_to_nnreal\n        (continuous_thickenedIndicatorAux \u03b4_pos E)\n    intro x\n    exact (lt_of_le_of_lt (@thickenedIndicatorAux_le_one _ _ \u03b4 E x) one_lt_top).Ne\n  map_bounded' := by\n    use 2\n    intro x y\n    rw [NNReal.dist_eq]\n    apply (abs_sub _ _).trans\n    rw [NNReal.abs_eq, NNReal.abs_eq, \u2190 one_add_one_eq_two]\n    have key := @thickenedIndicatorAux_le_one _ _ \u03b4 E\n    apply add_le_add <;>\n      \u00b7 norm_cast\n        refine'\n          (to_nnreal_le_to_nnreal (lt_of_le_of_lt (key _) one_lt_top).Ne one_ne_top).mpr (key _)\n#align thickened_indicator thickenedIndicator\n\ntheorem thickenedIndicator.coeFn_eq_comp {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) :\n    \u21d1(thickenedIndicator \u03b4_pos E) = ENNReal.toNNReal \u2218 thickenedIndicatorAux \u03b4 E :=\n  rfl\n#align thickened_indicator.coe_fn_eq_comp thickenedIndicator.coeFn_eq_comp\n\ntheorem thickenedIndicator_le_one {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) (x : \u03b1) :\n    thickenedIndicator \u03b4_pos E x \u2264 1 :=\n  by\n  rw [thickenedIndicator.coeFn_eq_comp]\n  simpa using\n    (to_nnreal_le_to_nnreal thickened_indicator_aux_lt_top.ne one_ne_top).mpr\n      (thickenedIndicatorAux_le_one \u03b4 E x)\n#align thickened_indicator_le_one thickenedIndicator_le_one\n\ntheorem thickenedIndicator_one_of_mem_closure {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) {x : \u03b1}\n    (x_mem : x \u2208 closure E) : thickenedIndicator \u03b4_pos E x = 1 := by\n  rw [thickenedIndicator_apply, thickenedIndicatorAux_one_of_mem_closure \u03b4 E x_mem, one_to_nnreal]\n#align thickened_indicator_one_of_mem_closure thickenedIndicator_one_of_mem_closure\n\ntheorem thickenedIndicator_one {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) {x : \u03b1} (x_in_E : x \u2208 E) :\n    thickenedIndicator \u03b4_pos E x = 1 :=\n  thickenedIndicator_one_of_mem_closure _ _ (subset_closure x_in_E)\n#align thickened_indicator_one thickenedIndicator_one\n\ntheorem thickenedIndicator_zero {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) {x : \u03b1}\n    (x_out : x \u2209 thickening \u03b4 E) : thickenedIndicator \u03b4_pos E x = 0 := by\n  rw [thickenedIndicator_apply, thickenedIndicatorAux_zero \u03b4_pos E x_out, zero_to_nnreal]\n#align thickened_indicator_zero thickenedIndicator_zero\n\ntheorem indicator_le_thickenedIndicator {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) (E : Set \u03b1) :\n    (E.indicator fun _ => (1 : \u211d\u22650)) \u2264 thickenedIndicator \u03b4_pos E :=\n  by\n  intro a\n  by_cases a \u2208 E\n  \u00b7 simp only [h, indicator_of_mem, thickenedIndicator_one \u03b4_pos E h, le_refl]\n  \u00b7 simp only [h, indicator_of_not_mem, not_false_iff, zero_le]\n#align indicator_le_thickened_indicator indicator_le_thickenedIndicator\n\ntheorem thickenedIndicator_mono {\u03b4\u2081 \u03b4\u2082 : \u211d} (\u03b4\u2081_pos : 0 < \u03b4\u2081) (\u03b4\u2082_pos : 0 < \u03b4\u2082) (hle : \u03b4\u2081 \u2264 \u03b4\u2082)\n    (E : Set \u03b1) : \u21d1(thickenedIndicator \u03b4\u2081_pos E) \u2264 thickenedIndicator \u03b4\u2082_pos E :=\n  by\n  intro x\n  apply\n    (to_nnreal_le_to_nnreal thickened_indicator_aux_lt_top.ne thickened_indicator_aux_lt_top.ne).mpr\n  apply thickenedIndicatorAux_mono hle\n#align thickened_indicator_mono thickenedIndicator_mono\n\ntheorem thickenedIndicator_subset {\u03b4 : \u211d} (\u03b4_pos : 0 < \u03b4) {E\u2081 E\u2082 : Set \u03b1} (subset : E\u2081 \u2286 E\u2082) :\n    \u21d1(thickenedIndicator \u03b4_pos E\u2081) \u2264 thickenedIndicator \u03b4_pos E\u2082 := fun x =>\n  (toNNReal_le_toNNReal thickenedIndicatorAux_lt_top.Ne thickenedIndicatorAux_lt_top.Ne).mpr\n    (thickenedIndicatorAux_subset \u03b4 subset x)\n#align thickened_indicator_subset thickenedIndicator_subset\n\n/-- As the thickening radius \u03b4 tends to 0, the \u03b4-thickened indicator of a set E (in \u03b1) tends\npointwise to the indicator function of the closure of E.\n\nNote: This version is for the bundled bounded continuous functions, but the topology is not\nthe topology on `\u03b1 \u2192\u1d47 \u211d\u22650`. Coercions to functions `\u03b1 \u2192 \u211d\u22650` are done first, so the topology\ninstance is the product topology (the topology of pointwise convergence). -/\ntheorem thickenedIndicator_tendsto_indicator_closure {\u03b4seq : \u2115 \u2192 \u211d} (\u03b4seq_pos : \u2200 n, 0 < \u03b4seq n)\n    (\u03b4seq_lim : Tendsto \u03b4seq atTop (\ud835\udcdd 0)) (E : Set \u03b1) :\n    Tendsto (fun n : \u2115 => (coeFn : (\u03b1 \u2192\u1d47 \u211d\u22650) \u2192 \u03b1 \u2192 \u211d\u22650) (thickenedIndicator (\u03b4seq_pos n) E)) atTop\n      (\ud835\udcdd (indicator (closure E) fun x => (1 : \u211d\u22650))) :=\n  by\n  have key := thickenedIndicatorAux_tendsto_indicator_closure \u03b4seq_lim E\n  rw [tendsto_pi_nhds] at *\n  intro x\n  rw [show\n      indicator (closure E) (fun x => (1 : \u211d\u22650)) x =\n        (indicator (closure E) (fun x => (1 : \u211d\u22650\u221e)) x).toNNReal\n      by refine' (congr_fun (comp_indicator_const 1 ENNReal.toNNReal zero_to_nnreal) x).symm]\n  refine' tendsto.comp (tendsto_to_nnreal _) (key x)\n  by_cases x_mem : x \u2208 closure E <;> simp [x_mem]\n#align thickened_indicator_tendsto_indicator_closure thickenedIndicator_tendsto_indicator_closure\n\nend thickenedIndicator\n\n-- section\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/MetricSpace/ThickenedIndicator.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7400882975090403}}
{"text": "/-\nCopyright (c) 2020 Kevin Buzzard\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, and whoever else wants to join in.\n-/\n\nimport data.mv_polynomial\n\n-- We want to be able to talk about V \u2286 W if V and W are affine algebraic sets\n-- We will need import order.lattice at some point I guess\n\nimport affine_algebraic_set.V_and_I\n\n/-!\n# Affine algebraic sets\n\nThis file defines affine algebraic subsets of affine n-space and proves basic properties\nabout them.\n\n## Important definitions\n\n* `affine_algebraic_set k n` -- the type of affine algebraic subsets of k\u207f.\n\n## Notation\n\nNone as yet -- do we need \ud835\udd38\u207f for affine n-space?\n\n## Implementation notes\n\nNone yet. \n\n## References\n\nMartin Orr's lecture notes https://homepages.warwick.ac.uk/staff/Martin.Orr/2017-8/alg-geom/\n\n## Tags\n\nalgebraic geometry, algebraic variety\n-/\n\n-- let k be a commutative ring (or even a semiring like \u2115)\nvariables {k : Type*} [comm_semiring k]\n\n-- and let \u03c3 be any set -- but think of it as {1,2,3,...,n}. It's the set\n-- which indexes the variables of the polynomial ring we're thinking about.\nvariable {\u03c3 : Type*}\n\n-- In Lean, the multivariable polynomial ring k[X\u2081, X\u2082, ..., X\u2099] is\n-- denoted `mv_polynomial \u03c3 k`. We could use better notation.\n-- The set \ud835\udd38\u207f or k\u207f is denoted `\u03c3 \u2192 k` (which means maps from {1,2,...,n} to k).\n-- We use local notation for this.\n\nlocal notation `\ud835\udd38\u207f` := \u03c3 \u2192 k\n\n-- We now make some definitions which we'll need in the course.\n\nnamespace mv_polynomial -- means \"multivariable polynomial\"\n\n/-- The set of zeros in k\u207f of a function f \u2208 k[X\u2081, X\u2082, ..., X\u2099] -/\ndef zeros (f : mv_polynomial \u03c3 k) : set (\u03c3 \u2192 k) :=\n{x | f.eval x = 0} -- I just want to write f(x) = 0 really\n\n/-- x is in the zeros of f iff f(x) = 0 -/\n@[simp] lemma mem_zeros (f : mv_polynomial \u03c3 k) (x : \u03c3 \u2192 k) :\n  x \u2208 f.zeros \u2194 f.eval x = 0 := iff.rfl\n\n-- note that the next result needs that k is a field. \n\n/-- The zeros of f * g are the union of the zeros of f and of g -/\nlemma zeros_mul {k : Type*} [discrete_field k] (f g : mv_polynomial \u03c3 k) :\n  zeros (f * g) = zeros f \u222a zeros g :=\nbegin\n  -- two sets are equal if they have the same elements\n  ext,\n  -- and now it's not hard to prove using `mem_zeros` and other\n  -- equalities known to Lean's simplifier.\n  simp, -- TODO -- should I give the full proof here?\nend\n\nend mv_polynomial\n\nopen mv_polynomial\n\n/-- An affine algebraic subset of k\u207f is the common zeros of a set of polynomials -/\nstructure affine_algebraic_set (k : Type*) [comm_semiring k] (\u03c3 : Type*) := \n-- imagine \u03c3 = {1,2,3,...,n}, the general case is no different.\n-- Maps \u03c3 \u2192 k are another way of thinking about k\u207f.\n\n-- To give an affine algebraic set is to give two things: the set itself\n-- (called `carrier` in Lean) and the proof that it's in the image of \ud835\udd4d.\n\n-- carrier \u2286 k\u207f\n(carrier : set (\u03c3 \u2192 k))\n\n-- proof that there's a set S of polynomials such that the carrier is equal to the \n-- intersection of the zeros of the polynomials in the set.\n(is_algebraic' : \u2203 S : set (mv_polynomial \u03c3 k), carrier = \ud835\udd4d S)\n\nnamespace affine_algebraic_set\n\n-- this is invisible notation so mathematicians don't need to understand the definition\n/-- An affine algebraic set can be regarded as a subset of \ud835\udd38\u207f -/\ninstance : has_coe_to_fun (affine_algebraic_set k \u03c3) :=\n{ F := \u03bb _, _,\n  coe := carrier\n}\n\n-- use `is_algebraic'` not `is_alegbraic` because the notation's right -- no \"carrier\".\ndef is_algebraic (V : affine_algebraic_set k \u03c3) :\n  \u2203 S : set (mv_polynomial \u03c3 k), (V : set _) = \ud835\udd4d S :=\naffine_algebraic_set.is_algebraic' V\n\n-- Now some basic facts about affine algebraic subsets. \n\n/-- Two affine algebraic subsets with the same carrier are equal! -/\nlemma ext {V W : affine_algebraic_set k \u03c3} : (V : set _) = W \u2192 V = W :=\nbegin\n  intro h,\n  cases V,\n  cases W,\n  simpa, -- TODO -- why no debugging output?\nend\n\n/-- We can talk about elements of affine algebraic subsets of k\u207f  -/\ninstance foo : has_mem \ud835\udd38\u207f (affine_algebraic_set k \u03c3) :=\n\u27e8\u03bb x V, x \u2208 V.carrier\u27e9\n\n-- Computer scientists insist on using \u2264 for any order relation such as \u2286 .\n-- It is some sort of problem with notation I think. \ninstance : has_le (affine_algebraic_set k \u03c3) :=\n\u27e8\u03bb V W, (V : set \ud835\udd38\u207f) \u2286 W\u27e9\n\ninstance : partial_order (affine_algebraic_set k \u03c3) :=\n{ le := (\u2264),\n  le_refl := \u03bb _ _, id,\n  le_trans := \u03bb _ _ _, set.subset.trans,\n  le_antisymm := \u03bb U V hUV hVU, ext (set.subset.antisymm hUV hVU)\n}\n\n/-- Mathematicians want to talk about affine algebraic subsets of k\u207f\n    being subsets of one another -/\ninstance : has_subset (affine_algebraic_set k \u03c3) :=\n\u27e8affine_algebraic_set.has_le.le\u27e9\n\nend affine_algebraic_set\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M4P33", "sha": "1a179372db71ad6802d11eacbc1f02f327d55f8f", "save_path": "github-repos/lean/ImperialCollegeLondon-M4P33", "path": "github-repos/lean/ImperialCollegeLondon-M4P33/M4P33-1a179372db71ad6802d11eacbc1f02f327d55f8f/src/affine_algebraic_set/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7400882966858724}}
{"text": "\n\ndef even (n : Nat) : Prop :=\n  \u2203 m : Nat, n = 2 * m\n\n\ndef prime (n : Nat) : Prop :=\n  \u00ac(\n    \u2203 p q : Nat,\n      (p > 1)\n    \u2227 (q > 1)\n    \u2227 (n = p * q)\n  )\n\n\ndef infinitely_many_primes : Prop :=\n  \u2200 n : Nat,\n  \u2203 p : Nat,\n    (p > n)\n  \u2227 (prime p)\n\n\ndef Fermat_prime (n : Nat) : Prop :=\n  \u2203 k : Nat,\n    (k > 0)\n  \u2227 (n = 2^k + 1)\n  \u2227 (prime n)\n\n\ndef infinitely_many_Fermat_primes : Prop :=\n  \u2200 n : Nat,\n  \u2203 p : Nat,\n    (p > n)\n  \u2227 (Fermat_prime p)\n\n\ndef goldbach_conjecture : Prop :=\n  \u2200 n : Nat, (n > 2) \u2227 (even n) \u2192\n    (\n      \u2203 p q : Nat,\n        (prime p) \u2227 (prime q)\n      \u2227 (p + q = n)\n    )\n\ndef Goldbach's_weak_conjecture : Prop :=\n  \u2200 n : Nat, (n > 7) \u2227 \u00ac(even n) \u2192\n    (\n      \u2203 p q r : Nat,\n        \u00ac(even p) \u2227 \u00ac(even q) \u2227 \u00ac(even r)\n      \u2227 (prime p) \u2227 (prime q) \u2227 (prime r)\n      \u2227 (p + q + r = n)\n    )\n\n\ndef Fermat's_last_theorem : Prop :=\n  \u00ac(\n    \u2203 a b c : Nat,\n    \u2203 n : Nat,\n      (a > 0) \u2227 (b > 0) \u2227 (c > 0)\n    \u2227 (n > 2)\n    \u2227 (a^n + b^n = c^n)\n  )\n", "meta": {"author": "bwbush", "repo": "lean4-exercises", "sha": "e6359ed8786210e48ff7a56c4d55c76a77b26594", "save_path": "github-repos/lean/bwbush-lean4-exercises", "path": "github-repos/lean/bwbush-lean4-exercises/lean4-exercises-e6359ed8786210e48ff7a56c4d55c76a77b26594/Exercises-4/Exercises-4-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191271831558, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7399743175199074}}
{"text": "/-\nCopyright (c) 2022 David Loeffler. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Loeffler\n-/\nimport measure_theory.integral.exp_decay\nimport analysis.calculus.parametric_integral\n\n/-!\n# The Gamma function\n\nThis file defines the `\u0393` function (of a real or complex variable `s`). We define this by Euler's\nintegral `\u0393(s) = \u222b x in Ioi 0, exp (-x) * x ^ (s - 1)` in the range where this integral converges\n(i.e., for `0 < s` in the real case, and `0 < re s` in the complex case).\n\nWe show that this integral satisfies `\u0393(1) = 1` and `\u0393(s + 1) = s * \u0393(s)`; hence we can define\n`\u0393(s)` for all `s` as the unique function satisfying this recurrence and agreeing with Euler's\nintegral in the convergence range. In the complex case we also prove that the resulting function is\nholomorphic on `\u2102` away from the points `{-n : n \u2208 \u2124}`.\n\n## Tags\n\nGamma\n-/\n\nnoncomputable theory\nopen filter interval_integral set real measure_theory asymptotics\nopen_locale topological_space\n\nlemma integral_exp_neg_Ioi : \u222b (x : \u211d) in Ioi 0, exp (-x) = 1 :=\nbegin\n  refine tendsto_nhds_unique (interval_integral_tendsto_integral_Ioi _ _ tendsto_id) _,\n  { simpa only [neg_mul, one_mul] using exp_neg_integrable_on_Ioi 0 zero_lt_one, },\n  { simpa using tendsto_exp_neg_at_top_nhds_0.const_sub 1, },\nend\n\nnamespace real\n\n/-- Asymptotic bound for the `\u0393` function integrand. -/\nlemma Gamma_integrand_is_o (s : \u211d) :\n  (\u03bb x:\u211d, exp (-x) * x ^ s) =o[at_top] (\u03bb x:\u211d, exp (-(1/2) * x)) :=\nbegin\n  refine is_o_of_tendsto (\u03bb x hx, _) _,\n  { exfalso, exact (exp_pos (-(1 / 2) * x)).ne' hx },\n  have : (\u03bb (x:\u211d), exp (-x) * x ^ s / exp (-(1 / 2) * x)) = (\u03bb (x:\u211d), exp ((1 / 2) * x) / x ^ s )\u207b\u00b9,\n  { ext1 x,\n    field_simp [exp_ne_zero, exp_neg, \u2190 real.exp_add],\n    left,\n    ring },\n  rw this,\n  exact (tendsto_exp_mul_div_rpow_at_top s (1 / 2) one_half_pos).inv_tendsto_at_top,\nend\n\n/-- Euler's integral for the `\u0393` function (of a real variable `s`), defined as\n`\u222b x in Ioi 0, exp (-x) * x ^ (s - 1)`.\n\nSee `Gamma_integral_convergent` for a proof of the convergence of the integral for `0 < s`. -/\ndef Gamma_integral (s : \u211d) : \u211d := \u222b x in Ioi (0:\u211d), exp (-x) * x ^ (s - 1)\n\n/-- The integral defining the `\u0393` function converges for positive real `s`. -/\nlemma Gamma_integral_convergent {s : \u211d} (h : 0 < s) :\n  integrable_on (\u03bb x:\u211d, exp (-x) * x ^ (s - 1)) (Ioi 0) :=\nbegin\n  rw [\u2190Ioc_union_Ioi_eq_Ioi (@zero_le_one \u211d _ _ _ _), integrable_on_union],\n  split,\n  { rw \u2190integrable_on_Icc_iff_integrable_on_Ioc,\n    refine integrable_on.continuous_on_mul continuous_on_id.neg.exp _ is_compact_Icc,\n    refine (interval_integrable_iff_integrable_Icc_of_le zero_le_one).mp _,\n    exact interval_integrable_rpow' (by linarith), },\n  { refine integrable_of_is_O_exp_neg one_half_pos _ (Gamma_integrand_is_o _ ).is_O,\n    refine continuous_on_id.neg.exp.mul (continuous_on_id.rpow_const _),\n    intros x hx,\n    exact or.inl ((zero_lt_one : (0 : \u211d) < 1).trans_le hx).ne' }\nend\n\nlemma Gamma_integral_one : Gamma_integral 1 = 1 :=\nby simpa only [Gamma_integral, sub_self, rpow_zero, mul_one] using integral_exp_neg_Ioi\n\nend real\n\nnamespace complex\n/- Technical note: In defining the Gamma integrand exp (-x) * x ^ (s - 1) for s complex, we have to\nmake a choice between \u2191(real.exp (-x)), complex.exp (\u2191(-x)), and complex.exp (-\u2191x), all of which are\nequal but not definitionally so. We use the first of these throughout. -/\n\n\n/-- The integral defining the `\u0393` function converges for complex `s` with `0 < re s`.\n\nThis is proved by reduction to the real case. -/\nlemma Gamma_integral_convergent {s : \u2102} (hs : 0 < s.re) :\n  integrable_on (\u03bb x, (-x).exp * x ^ (s - 1) : \u211d \u2192 \u2102) (Ioi 0) :=\nbegin\n  split,\n  { refine continuous_on.ae_strongly_measurable _ measurable_set_Ioi,\n    apply (continuous_of_real.comp continuous_neg.exp).continuous_on.mul,\n    apply continuous_at.continuous_on,\n    intros x hx,\n    have : continuous_at (\u03bb x:\u2102, x ^ (s - 1)) \u2191x,\n    { apply continuous_at_cpow_const, rw of_real_re, exact or.inl hx, },\n    exact continuous_at.comp this continuous_of_real.continuous_at },\n  { rw \u2190has_finite_integral_norm_iff,\n    refine has_finite_integral.congr (real.Gamma_integral_convergent hs).2 _,\n    refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    dsimp only,\n    rw [norm_eq_abs, abs_mul, abs_of_nonneg $ le_of_lt $ exp_pos $ -x,\n      abs_cpow_eq_rpow_re_of_pos hx _],\n    simp }\nend\n\n/-- Euler's integral for the `\u0393` function (of a complex variable `s`), defined as\n`\u222b x in Ioi 0, exp (-x) * x ^ (s - 1)`.\n\nSee `complex.Gamma_integral_convergent` for a proof of the convergence of the integral for\n`0 < re s`. -/\ndef Gamma_integral (s : \u2102) : \u2102 := \u222b x in Ioi (0:\u211d), \u2191(-x).exp * \u2191x ^ (s - 1)\n\nlemma Gamma_integral_of_real (s : \u211d) :\n  Gamma_integral \u2191s = \u2191(s.Gamma_integral) :=\nbegin\n  rw [real.Gamma_integral, \u2190integral_of_real],\n  refine set_integral_congr measurable_set_Ioi _,\n  intros x hx, dsimp only,\n  rw [of_real_mul, of_real_cpow (mem_Ioi.mp hx).le],\n  simp,\nend\n\nlemma Gamma_integral_one : Gamma_integral 1 = 1 :=\nbegin\n  rw [\u2190of_real_one, Gamma_integral_of_real, of_real_inj],\n  exact real.Gamma_integral_one,\nend\n\nend complex\n\n/-! Now we establish the recurrence relation `\u0393(s + 1) = s * \u0393(s)` using integration by parts. -/\n\nnamespace complex\n\nsection Gamma_recurrence\n\n/-- The indefinite version of the `\u0393` function, `\u0393(s, X) = \u222b x \u2208 0..X, exp(-x) x ^ (s - 1)`. -/\ndef partial_Gamma (s : \u2102) (X : \u211d) : \u2102 := \u222b x in 0..X, (-x).exp * x ^ (s - 1)\n\nlemma tendsto_partial_Gamma {s : \u2102} (hs: 0 < s.re) :\n  tendsto (\u03bb X:\u211d, partial_Gamma s X) at_top (\ud835\udcdd $ Gamma_integral s) :=\ninterval_integral_tendsto_integral_Ioi 0 (Gamma_integral_convergent hs) tendsto_id\n\nprivate lemma Gamma_integrand_interval_integrable (s : \u2102) {X : \u211d} (hs : 0 < s.re) (hX : 0 \u2264 X):\n  interval_integrable (\u03bb x, (-x).exp * x ^ (s - 1) : \u211d \u2192 \u2102) volume 0 X :=\nbegin\n  rw interval_integrable_iff_integrable_Ioc_of_le hX,\n  exact integrable_on.mono_set (Gamma_integral_convergent hs) Ioc_subset_Ioi_self\nend\n\nprivate lemma Gamma_integrand_deriv_integrable_A {s : \u2102} (hs : 0 < s.re) {X : \u211d} (hX : 0 \u2264 X):\n interval_integrable (\u03bb x, -((-x).exp * x ^ s) : \u211d \u2192 \u2102) volume 0 X :=\nbegin\n  convert (Gamma_integrand_interval_integrable (s+1) _ hX).neg,\n  { ext1, simp only [add_sub_cancel, pi.neg_apply] },\n  { simp only [add_re, one_re], linarith,},\nend\n\nprivate lemma Gamma_integrand_deriv_integrable_B {s : \u2102} (hs : 0 < s.re) {Y : \u211d} (hY : 0 \u2264 Y) :\n  interval_integrable (\u03bb (x : \u211d), (-x).exp * (s * x ^ (s - 1)) : \u211d \u2192 \u2102) volume 0 Y :=\nbegin\n  have : (\u03bb x, (-x).exp * (s * x ^ (s - 1)) : \u211d \u2192 \u2102) =\n    (\u03bb x, s * ((-x).exp * x ^ (s - 1)) : \u211d \u2192 \u2102),\n  { ext1, ring, },\n  rw [this, interval_integrable_iff_integrable_Ioc_of_le hY],\n  split,\n  { refine (continuous_on_const.mul _).ae_strongly_measurable measurable_set_Ioc,\n    apply (continuous_of_real.comp continuous_neg.exp).continuous_on.mul,\n    apply continuous_at.continuous_on,\n    intros x hx,\n    refine (_ : continuous_at (\u03bb x:\u2102, x ^ (s - 1)) _).comp continuous_of_real.continuous_at,\n    apply continuous_at_cpow_const, rw of_real_re, exact or.inl hx.1, },\n  rw \u2190has_finite_integral_norm_iff,\n  simp_rw [norm_eq_abs, complex.abs_mul],\n  refine (((real.Gamma_integral_convergent hs).mono_set\n    Ioc_subset_Ioi_self).has_finite_integral.congr _).const_mul _,\n  rw [eventually_eq, ae_restrict_iff'],\n  { apply ae_of_all, intros x hx,\n    rw [abs_of_nonneg (exp_pos _).le,abs_cpow_eq_rpow_re_of_pos hx.1],\n    simp },\n  { exact measurable_set_Ioc},\nend\n\n/-- The recurrence relation for the indefinite version of the `\u0393` function. -/\nlemma partial_Gamma_add_one {s : \u2102} (hs: 0 < s.re) {X : \u211d} (hX : 0 \u2264 X) :\n  partial_Gamma (s + 1) X = s * partial_Gamma s X - (-X).exp * X ^ s :=\nbegin\n  rw [partial_Gamma, partial_Gamma, add_sub_cancel],\n  have F_der_I: (\u2200 (x:\u211d), (x \u2208 Ioo 0 X) \u2192 has_deriv_at (\u03bb x, (-x).exp * x ^ s : \u211d \u2192 \u2102)\n    ( -((-x).exp * x ^ s) + (-x).exp * (s * x ^ (s - 1))) x),\n  { intros x hx,\n    have d1 : has_deriv_at (\u03bb (y: \u211d), (-y).exp) (-(-x).exp) x,\n    { simpa using (has_deriv_at_neg x).exp },\n    have d1b : has_deriv_at (\u03bb y, \u2191(-y).exp : \u211d \u2192 \u2102) (\u2191-(-x).exp) x,\n    { convert has_deriv_at.scomp x of_real_clm.has_deriv_at d1, simp, },\n    have d2: has_deriv_at (\u03bb (y : \u211d), \u2191y ^ s) (s * x ^ (s - 1)) x,\n    { have t := @has_deriv_at.cpow_const _ _ _ s (has_deriv_at_id \u2191x),\n      simp only [id.def, of_real_re, of_real_im,\n        ne.def, eq_self_iff_true, not_true, or_false, mul_one] at t,\n      simpa using has_deriv_at.comp x (t hx.left) of_real_clm.has_deriv_at, },\n    simpa only [of_real_neg, neg_mul] using d1b.mul d2 },\n  have cont := (continuous_of_real.comp continuous_neg.exp).mul\n    (continuous_of_real_cpow_const hs),\n  have der_ible := (Gamma_integrand_deriv_integrable_A hs hX).add\n    (Gamma_integrand_deriv_integrable_B hs hX),\n  have int_eval := integral_eq_sub_of_has_deriv_at_of_le hX cont.continuous_on F_der_I der_ible,\n  -- We are basically done here but manipulating the output into the right form is fiddly.\n  apply_fun (\u03bb x:\u2102, -x) at int_eval,\n  rw [interval_integral.integral_add (Gamma_integrand_deriv_integrable_A hs hX)\n    (Gamma_integrand_deriv_integrable_B hs hX), interval_integral.integral_neg, neg_add, neg_neg]\n    at int_eval,\n  replace int_eval := eq_sub_of_add_eq int_eval,\n  rw [int_eval, sub_neg_eq_add, neg_sub, add_comm, add_sub],\n  simp only [sub_left_inj, add_left_inj],\n  have : (\u03bb x, (-x).exp * (s * x ^ (s - 1)) : \u211d \u2192 \u2102) = (\u03bb x, s * (-x).exp * x ^ (s - 1) : \u211d \u2192 \u2102),\n  { ext1, ring,},\n  rw this,\n  have t := @integral_const_mul (0:\u211d) X volume _ _ s (\u03bb x:\u211d, (-x).exp * x ^ (s - 1)),\n  dsimp at t, rw [\u2190t, of_real_zero, zero_cpow],\n  { rw [mul_zero, add_zero], congr', ext1, ring },\n  { contrapose! hs, rw [hs, zero_re] }\nend\n\n/-- The recurrence relation for the `\u0393` integral. -/\ntheorem Gamma_integral_add_one {s : \u2102} (hs: 0 < s.re) :\n  Gamma_integral (s + 1) = s * Gamma_integral s :=\nbegin\n  suffices : tendsto (s+1).partial_Gamma at_top (\ud835\udcdd $ s * Gamma_integral s),\n  { refine tendsto_nhds_unique _ this,\n    apply tendsto_partial_Gamma, rw [add_re, one_re], linarith, },\n  have : (\u03bb X:\u211d, s * partial_Gamma s X - X ^ s * (-X).exp) =\u1da0[at_top] (s+1).partial_Gamma,\n  { apply eventually_eq_of_mem (Ici_mem_at_top (0:\u211d)),\n    intros X hX,\n    rw partial_Gamma_add_one hs (mem_Ici.mp hX),\n    ring_nf, },\n  refine tendsto.congr' this _,\n  suffices : tendsto (\u03bb X, -X ^ s * (-X).exp : \u211d \u2192 \u2102) at_top (\ud835\udcdd 0),\n  { simpa using tendsto.add (tendsto.const_mul s (tendsto_partial_Gamma hs)) this },\n  rw tendsto_zero_iff_norm_tendsto_zero,\n  have : (\u03bb (e : \u211d), \u2225-(e:\u2102) ^ s * (-e).exp\u2225 ) =\u1da0[at_top] (\u03bb (e : \u211d), e ^ s.re * (-1 * e).exp ),\n  { refine eventually_eq_of_mem (Ioi_mem_at_top 0) _,\n    intros x hx, dsimp only,\n    rw [norm_eq_abs, abs_mul, abs_neg, abs_cpow_eq_rpow_re_of_pos hx,\n      abs_of_nonneg (exp_pos(-x)).le, neg_mul, one_mul],},\n  exact (tendsto_congr' this).mpr (tendsto_rpow_mul_exp_neg_mul_at_top_nhds_0 _ _ zero_lt_one),\nend\n\nend Gamma_recurrence\n\n/-! Now we define `\u0393(s)` on the whole complex plane, by recursion. -/\n\nsection Gamma_def\n\n/-- The `n`th function in this family is `\u0393(s)` if `-n < s.re`, and junk otherwise. -/\nnoncomputable def Gamma_aux : \u2115 \u2192 (\u2102 \u2192 \u2102)\n| 0      := Gamma_integral\n| (n+1)  := \u03bb s:\u2102, (Gamma_aux n (s+1)) / s\n\nlemma Gamma_aux_recurrence1 (s : \u2102) (n : \u2115) (h1 : -s.re < \u2191n) :\n  Gamma_aux n s = Gamma_aux n (s+1) / s :=\nbegin\n  induction n with n hn generalizing s,\n  { simp only [nat.cast_zero, neg_lt_zero] at h1,\n    dsimp only [Gamma_aux], rw Gamma_integral_add_one h1,\n    rw [mul_comm, mul_div_cancel], contrapose! h1, rw h1,\n    simp },\n  { dsimp only [Gamma_aux],\n    have hh1 : -(s+1).re < n,\n    { rw [nat.succ_eq_add_one, nat.cast_add, nat.cast_one] at h1,\n      rw [add_re, one_re], linarith, },\n    rw \u2190(hn (s+1) hh1) }\nend\n\nlemma Gamma_aux_recurrence2 (s : \u2102) (n : \u2115) (h1 : -s.re < \u2191n) :\n  Gamma_aux n s = Gamma_aux (n+1) s :=\nbegin\n  cases n,\n  { simp only [nat.cast_zero, neg_lt_zero] at h1,\n    dsimp only [Gamma_aux],\n    rw [Gamma_integral_add_one h1, mul_div_cancel_left],\n    rintro rfl,\n    rw [zero_re] at h1,\n    exact h1.false },\n  { dsimp only [Gamma_aux],\n    have : (Gamma_aux n (s + 1 + 1)) / (s+1) = Gamma_aux n (s + 1),\n    { have hh1 : -(s+1).re < n,\n      { rw [nat.succ_eq_add_one, nat.cast_add, nat.cast_one] at h1,\n        rw [add_re, one_re], linarith, },\n      rw Gamma_aux_recurrence1 (s+1) n hh1, },\n    rw this },\nend\n\n\n/-- The `\u0393` function (of a complex variable `s`). -/\ndef Gamma (s : \u2102) : \u2102 := Gamma_aux \u230a1 - s.re\u230b\u208a s\n\nlemma Gamma_eq_Gamma_aux (s : \u2102) (n : \u2115) (h1 : -s.re < \u2191n) : Gamma s = Gamma_aux n s :=\nbegin\n  have u : \u2200 (k : \u2115), Gamma_aux (\u230a1 - s.re\u230b\u208a + k) s = Gamma s,\n  { intro k, induction k with k hk,\n    { simp [Gamma],},\n    { rw [\u2190hk, nat.succ_eq_add_one, \u2190add_assoc],\n      refine (Gamma_aux_recurrence2 s (\u230a1 - s.re\u230b\u208a + k) _).symm,\n      rw nat.cast_add,\n      have i0 := nat.sub_one_lt_floor (1 - s.re),\n      simp only [sub_sub_cancel_left] at i0,\n      refine lt_add_of_lt_of_nonneg i0 _,\n      rw [\u2190nat.cast_zero, nat.cast_le], exact nat.zero_le k, } },\n  convert (u $ n - \u230a1 - s.re\u230b\u208a).symm, rw nat.add_sub_of_le,\n  by_cases (0 \u2264 1 - s.re),\n  { apply nat.le_of_lt_succ,\n    exact_mod_cast lt_of_le_of_lt (nat.floor_le h) (by linarith : 1 - s.re < n + 1) },\n  { rw nat.floor_of_nonpos, linarith, linarith },\nend\n\n/-- The recurrence relation for the `\u0393` function. -/\ntheorem Gamma_add_one (s : \u2102) (h2 : s \u2260 0) : Gamma (s+1) = s * Gamma s :=\nbegin\n  let n := \u230a1 - s.re\u230b\u208a,\n  have t1 : -s.re < n,\n  { simpa only [sub_sub_cancel_left] using nat.sub_one_lt_floor (1 - s.re) },\n  have t2 : -(s+1).re < n,\n  { rw [add_re, one_re], linarith, },\n  rw [Gamma_eq_Gamma_aux s n t1, Gamma_eq_Gamma_aux (s+1) n t2, Gamma_aux_recurrence1 s n t1],\n  field_simp, ring,\nend\n\ntheorem Gamma_eq_integral (s : \u2102) (hs : 0 < s.re) : Gamma s = Gamma_integral s :=\nGamma_eq_Gamma_aux s 0 (by { norm_cast, linarith })\n\ntheorem Gamma_nat_eq_factorial (n : \u2115) : Gamma (n+1) = nat.factorial n :=\nbegin\n  induction n with n hn,\n  { rw [nat.cast_zero, zero_add], rw Gamma_eq_integral,\n    simpa using Gamma_integral_one, simp,},\n  rw (Gamma_add_one n.succ $ nat.cast_ne_zero.mpr $ nat.succ_ne_zero n),\n  { simp only [nat.cast_succ, nat.factorial_succ, nat.cast_mul], congr, exact hn },\nend\n\nend Gamma_def\n\nend complex\n\n/-! Now check that the `\u0393` function is differentiable, wherever this makes sense. -/\n\nsection Gamma_has_deriv\n\n/-- Integrand for the derivative of the `\u0393` function -/\ndef dGamma_integrand (s : \u2102) (x : \u211d) : \u2102 := exp (-x) * log x * x ^ (s - 1)\n\n/-- Integrand for the absolute value of the derivative of the `\u0393` function -/\ndef dGamma_integrand_real (s x : \u211d) : \u211d := |exp (-x) * log x * x ^ (s - 1)|\n\nlemma dGamma_integrand_is_o_at_top (s : \u211d) :\n  (\u03bb x : \u211d, exp (-x) * log x * x ^ (s - 1)) =o[at_top] (\u03bb x, exp (-(1/2) * x)) :=\nbegin\n  refine is_o_of_tendsto (\u03bb x hx, _) _,\n  { exfalso, exact (-(1/2) * x).exp_pos.ne' hx, },\n  have : eventually_eq at_top (\u03bb (x : \u211d), exp (-x) * log x * x ^ (s - 1) / exp (-(1 / 2) * x))\n    (\u03bb (x : \u211d),  (\u03bb z:\u211d, exp (1 / 2 * z) / z ^ s) x * (\u03bb z:\u211d, z / log z) x)\u207b\u00b9,\n  { refine eventually_of_mem (Ioi_mem_at_top 1) _,\n    intros x hx, dsimp,\n    replace hx := lt_trans zero_lt_one (mem_Ioi.mp hx),\n    rw [real.exp_neg, neg_mul, real.exp_neg, rpow_sub hx],\n    have : exp x = exp(x/2) * exp(x/2),\n    { rw [\u2190real.exp_add, add_halves], },\n    rw this, field_simp [hx.ne', exp_ne_zero (x/2)], ring, },\n  refine tendsto.congr' this.symm (tendsto.inv_tendsto_at_top _),\n  apply tendsto.at_top_mul_at_top (tendsto_exp_mul_div_rpow_at_top s (1/2) one_half_pos),\n  refine tendsto.congr' _ ((tendsto_exp_div_pow_at_top 1).comp tendsto_log_at_top),\n  apply eventually_eq_of_mem (Ioi_mem_at_top (0:\u211d)),\n  intros x hx, simp [exp_log hx],\nend\n\n/-- Absolute convergence of the integral which will give the derivative of the `\u0393` function on\n`1 < re s`. -/\nlemma dGamma_integral_abs_convergent (s : \u211d) (hs : 1 < s) :\n  integrable_on (\u03bb x:\u211d, \u2225exp (-x) * log x * x ^ (s-1)\u2225) (Ioi 0) :=\nbegin\n  rw [\u2190Ioc_union_Ioi_eq_Ioi (@zero_le_one \u211d _ _ _ _), integrable_on_union],\n  refine \u27e8\u27e8_, _\u27e9, _\u27e9,\n  { refine continuous_on.ae_strongly_measurable (continuous_on.mul _ _).norm measurable_set_Ioc,\n    { refine (continuous_exp.comp continuous_neg).continuous_on.mul (continuous_on_log.mono _),\n      simp, },\n    { apply continuous_on_id.rpow_const, intros x hx, right, linarith }, },\n  { apply has_finite_integral_of_bounded,\n    swap, { exact 1 / (s - 1), },\n    refine (ae_restrict_iff' measurable_set_Ioc).mpr (ae_of_all _ (\u03bb x hx, _)),\n    rw [norm_norm, norm_eq_abs, mul_assoc, abs_mul, \u2190one_mul (1 / (s - 1))],\n    refine mul_le_mul _ _ (abs_nonneg _) zero_le_one,\n    { rw [abs_of_pos (exp_pos(-x)), exp_le_one_iff, neg_le, neg_zero], exact hx.1.le },\n    { exact (abs_log_mul_self_rpow_lt x (s-1) hx.1 hx.2 (sub_pos.mpr hs)).le }, },\n  { have := (dGamma_integrand_is_o_at_top s).is_O.norm_left,\n    refine integrable_of_is_O_exp_neg one_half_pos (continuous_on.mul _ _).norm this,\n    { refine (continuous_exp.comp continuous_neg).continuous_on.mul (continuous_on_log.mono _),\n      simp, },\n    { apply continuous_at.continuous_on (\u03bb x hx, _),\n      apply continuous_at_id.rpow continuous_at_const,\n      dsimp, right, linarith, }, }\nend\n\n/-- A uniform bound for the `s`-derivative of the `\u0393` integrand for `s` in vertical strips. -/\nlemma loc_unif_bound_dGamma_integrand {t : \u2102} {s1 s2 x : \u211d} (ht1 : s1 \u2264 t.re)\n  (ht2: t.re \u2264 s2) (hx : 0 < x) :\n  \u2225dGamma_integrand t x\u2225 \u2264 dGamma_integrand_real s1 x + dGamma_integrand_real s2 x :=\nbegin\n  rcases le_or_lt 1 x with h|h,\n  { -- case 1 \u2264 x\n    refine le_add_of_nonneg_of_le (abs_nonneg _) _,\n    rw [dGamma_integrand, dGamma_integrand_real, complex.norm_eq_abs, complex.abs_mul, abs_mul,\n      \u2190complex.of_real_mul, complex.abs_of_real],\n    refine mul_le_mul_of_nonneg_left _ (abs_nonneg _),\n    rw complex.abs_cpow_eq_rpow_re_of_pos hx,\n    refine le_trans _ (le_abs_self _),\n    apply rpow_le_rpow_of_exponent_le h,\n    rw [complex.sub_re, complex.one_re], linarith, },\n  { refine le_add_of_le_of_nonneg _ (abs_nonneg _),\n    rw [dGamma_integrand, dGamma_integrand_real, complex.norm_eq_abs, complex.abs_mul, abs_mul,\n      \u2190complex.of_real_mul, complex.abs_of_real],\n    refine mul_le_mul_of_nonneg_left _ (abs_nonneg _),\n    rw complex.abs_cpow_eq_rpow_re_of_pos hx,\n    refine le_trans _ (le_abs_self _),\n    apply rpow_le_rpow_of_exponent_ge hx h.le,\n    rw [complex.sub_re, complex.one_re], linarith, },\nend\n\nnamespace complex\n\n/-- The derivative of the `\u0393` integral, at any `s \u2208 \u2102` with `1 < re s`, is given by the integral\nof `exp (-x) * log x * x ^ (s - 1)` over `[0, \u221e)`. -/\ntheorem has_deriv_at_Gamma_integral {s : \u2102} (hs : 1 < s.re) :\n  (integrable_on (\u03bb x, real.exp (-x) * real.log x * x ^ (s - 1) : \u211d \u2192 \u2102) (Ioi 0) volume) \u2227\n  (has_deriv_at Gamma_integral (\u222b x:\u211d in Ioi 0, real.exp (-x) * real.log x * x ^ (s - 1)) s) :=\nbegin\n  let \u03b5 := (s.re - 1) / 2,\n  let \u03bc := volume.restrict (Ioi (0:\u211d)),\n  let bound := (\u03bb x:\u211d, dGamma_integrand_real (s.re - \u03b5) x + dGamma_integrand_real (s.re + \u03b5) x),\n  have cont : \u2200 (t : \u2102), continuous_on (\u03bb x, real.exp (-x) * x ^ (t - 1) : \u211d \u2192 \u2102) (Ioi 0),\n  { intro t, apply (continuous_of_real.comp continuous_neg.exp).continuous_on.mul,\n    apply continuous_at.continuous_on, intros x hx,\n    refine (continuous_at_cpow_const _).comp continuous_of_real.continuous_at,\n    exact or.inl hx, },\n  have eps_pos: 0 < \u03b5 := div_pos (sub_pos.mpr hs) zero_lt_two,\n  have hF_meas : \u2200\u1da0 (t : \u2102) in \ud835\udcdd s,\n    ae_strongly_measurable (\u03bb x, real.exp(-x) * x ^ (t - 1) : \u211d \u2192 \u2102) \u03bc,\n  { apply eventually_of_forall, intro t,\n    exact (cont t).ae_strongly_measurable measurable_set_Ioi, },\n  have hF'_meas : ae_strongly_measurable (dGamma_integrand s) \u03bc,\n  { refine continuous_on.ae_strongly_measurable _ measurable_set_Ioi,\n    have : dGamma_integrand s = (\u03bb x, real.exp (-x) * x ^ (s - 1) * real.log x : \u211d \u2192 \u2102),\n    { ext1, simp only [dGamma_integrand], ring },\n    rw this,\n    refine continuous_on.mul (cont s) (continuous_at.continuous_on _),\n    exact \u03bb x hx, continuous_of_real.continuous_at.comp (continuous_at_log (mem_Ioi.mp hx).ne'), },\n  have h_bound : \u2200\u1d50 (x : \u211d) \u2202\u03bc, \u2200 (t : \u2102), t \u2208 metric.ball s \u03b5 \u2192 \u2225 dGamma_integrand t x \u2225 \u2264 bound x,\n  { refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    intros t ht,\n    rw [metric.mem_ball, complex.dist_eq] at ht,\n    replace ht := lt_of_le_of_lt (complex.abs_re_le_abs $ t - s ) ht,\n    rw [complex.sub_re, @abs_sub_lt_iff \u211d _ t.re s.re ((s.re - 1) / 2) ] at ht,\n    refine loc_unif_bound_dGamma_integrand _ _ hx,\n    all_goals { simp only [\u03b5], linarith } },\n  have bound_integrable : integrable bound \u03bc,\n  { apply integrable.add,\n    { refine dGamma_integral_abs_convergent (s.re - \u03b5) _,\n      field_simp, rw one_lt_div,\n      { linarith }, { exact zero_lt_two }, },\n    { refine dGamma_integral_abs_convergent (s.re + \u03b5) _, linarith, }, },\n  have h_diff : \u2200\u1d50 (x : \u211d) \u2202\u03bc, \u2200 (t : \u2102), t \u2208 metric.ball s \u03b5\n    \u2192 has_deriv_at (\u03bb u, real.exp (-x) * x ^ (u - 1) : \u2102 \u2192 \u2102) (dGamma_integrand t x) t,\n  { refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    intros t ht, rw mem_Ioi at hx,\n    simp only [dGamma_integrand],\n    rw mul_assoc,\n    apply has_deriv_at.const_mul,\n    rw [of_real_log hx.le, mul_comm],\n    have := ((has_deriv_at_id t).sub_const 1).const_cpow (or.inl (of_real_ne_zero.mpr hx.ne')),\n    rwa mul_one at this },\n  exact (has_deriv_at_integral_of_dominated_loc_of_deriv_le eps_pos hF_meas\n    (Gamma_integral_convergent (zero_lt_one.trans hs)) hF'_meas h_bound bound_integrable h_diff),\nend\n\nlemma differentiable_at_Gamma_aux (s : \u2102) (n : \u2115) (h1 : (1 - s.re) < n ) (h2 : \u2200 m:\u2115, s + m \u2260 0) :\n  differentiable_at \u2102 (Gamma_aux n) s :=\nbegin\n  induction n with n hn generalizing s,\n  { refine (has_deriv_at_Gamma_integral _).2.differentiable_at,\n    rw nat.cast_zero at h1, linarith },\n  { dsimp only [Gamma_aux],\n    specialize hn (s + 1),\n    have a : 1 - (s + 1).re < \u2191n,\n    { rw nat.cast_succ at h1, rw [complex.add_re, complex.one_re], linarith },\n    have b : \u2200 m:\u2115, s + 1 + m \u2260 0,\n    { intro m, have := h2 (1 + m), rwa [nat.cast_add, nat.cast_one, \u2190add_assoc] at this },\n    refine differentiable_at.div (differentiable_at.comp _ (hn a b) _) _ _,\n    simp, simp, simpa using h2 0 }\nend\n\ntheorem differentiable_at_Gamma (s : \u2102) (hs : \u2200 m:\u2115, s + m \u2260 0) : differentiable_at \u2102 Gamma s :=\nbegin\n  let n := \u230a1 - s.re\u230b\u208a + 1,\n  have hn : 1 - s.re < n := by exact_mod_cast nat.lt_floor_add_one (1 - s.re),\n  apply (differentiable_at_Gamma_aux s n hn hs).congr_of_eventually_eq,\n  let S := { t : \u2102 | 1 - t.re < n },\n  have : S \u2208 \ud835\udcdd s,\n  { rw mem_nhds_iff, use S,\n    refine \u27e8subset.rfl, _, hn\u27e9,\n    have : S = re\u207b\u00b9' Ioi (1 - n : \u211d),\n    { ext, rw [preimage,Ioi, mem_set_of_eq, mem_set_of_eq, mem_set_of_eq], exact sub_lt },\n    rw this,\n    refine continuous.is_open_preimage continuous_re _ is_open_Ioi, },\n  apply eventually_eq_of_mem this,\n  intros t ht, rw mem_set_of_eq at ht,\n  apply Gamma_eq_Gamma_aux, linarith,\nend\n\nend complex\n\nend Gamma_has_deriv\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/special_functions/gamma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7399618640371882}}
{"text": "/-\nCopyright (c) 2020 Markus Himmel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Markus Himmel\n-/\nimport linear_algebra.finite_dimensional\nimport ring_theory.ideal.basic\n\n/-!\n# Invariant basis number property\n\nWe say that a ring `R` satisfies the invariant basis number property if there is a well-defined\nnotion of the rank of a finitely generated free (left) `R`-module. Since a finitely generated free\nmodule with a basis consisting of `n` elements is linearly equivalent to `fin n \u2192 R`, it is\nsufficient that `(fin n \u2192 R) \u2243\u2097[R] (fin m \u2192 R)` implies `n = m`.\n\n## Main definitions\n\n`invariant_basis_number R` is a type class stating that `R` has the invariant basis number property.\n\n## Main results\n\nWe show that every nontrivial commutative ring has the invariant basis number property.\n\n## Future work\n\nSo far, there is no API at all for the `invariant_basis_number` class. There are several natural\nways to formulate that a module `M` is finitely generated and free, for example\n`M \u2243\u2097[R] (fin n \u2192 R)`, `M \u2243\u2097[R] (\u03b9 \u2192 R)`, where `\u03b9` is a fintype, or prividing a basis indexed by\na finite type. There should be lemmas applying the invariant basis number property to each\nsituation.\n\nThe finite version of the invariant basis number property implies the infinite analogue, i.e., that\n`(\u03b9 \u2192\u2080 R) \u2243\u2097[R] (\u03b9' \u2192\u2080 R)` implies that `cardinal.mk \u03b9 = cardinal.mk \u03b9'`. This fact (and its\nvariants) should be formalized.\n\n## References\n\n* https://en.wikipedia.org/wiki/Invariant_basis_number\n\n## Tags\n\nfree module, rank, invariant basis number, IBN\n\n-/\n\nnoncomputable theory\n\nopen_locale classical big_operators\n\nuniverses u v w\n\nsection\nvariables (R : Type u) [ring R]\n\n/-- We say that `R` has the invariant basis number property if `(fin n \u2192 R) \u2243\u2097[R] (fin m \u2192 R)`\n    implies `n = m`. This gives rise to a well-defined notion of rank of a finitely generated free\n    module. -/\nclass invariant_basis_number : Prop :=\n(eq_of_fin_equiv : \u2200 {n m : \u2115}, ((fin n \u2192 R) \u2243\u2097[R] (fin m \u2192 R)) \u2192 n = m)\n\nend\n\nsection\nvariables (R : Type u) [ring R] [invariant_basis_number R]\n\nlemma eq_of_fin_equiv {n m : \u2115} : ((fin n \u2192 R) \u2243\u2097[R] (fin m \u2192 R)) \u2192 n = m :=\ninvariant_basis_number.eq_of_fin_equiv\n\nlemma nontrivial_of_invariant_basis_number : nontrivial R :=\nbegin\n  by_contra h,\n  refine zero_ne_one (eq_of_fin_equiv R _),\n  haveI := not_nontrivial_iff_subsingleton.1 h,\n  haveI : subsingleton (fin 1 \u2192 R) := \u27e8\u03bb a b, funext $ \u03bb x, subsingleton.elim _ _\u27e9,\n  refine { .. }; { intros, exact 0 } <|> tidy\nend\n\nend\n\nsection\nopen finite_dimensional\n\n/-- A field has invariant basis number. This will be superseded below by the fact that any nonzero\n    commutative ring has invariant basis number. -/\nlemma invariant_basis_number_field {K : Type u} [field K] : invariant_basis_number K :=\n\u27e8\u03bb n m e,\n  calc n = fintype.card (fin n) : eq.symm $ fintype.card_fin n\n     ... = finrank K (fin n \u2192 K) : eq.symm $ finrank_eq_card_basis (pi.is_basis_fun K (fin n))\n     ... = finrank K (fin m \u2192 K) : linear_equiv.finrank_eq e\n     ... = fintype.card (fin m) : finrank_eq_card_basis (pi.is_basis_fun K (fin m))\n     ... = m                    : fintype.card_fin m\u27e9\n\nend\n\n/-!\n  We want to show that nontrivial commutative rings have invariant basis number. The idea is to\n  take a maximal ideal `I` of `R` and use an isomorphism `R^n \u2243 R^m` of `R` modules to produce an\n  isomorphism `(R/I)^n \u2243 (R/I)^m` of `R/I`-modules, which will imply `n = m` since `R/I` is a field\n  and we know that fields have invariant basis number.\n\n  We construct the isomorphism in two steps:\n  1. We construct the ring `R^n/I^n`, show that it is an `R/I`-module and show that there is an\n     isomorphism of `R/I`-modules `R^n/I^n \u2243 (R/I)^n`. This isomorphism is called\n    `ideal.pi_quot_equiv` and is located in the file `ring_theory/ideals.lean`.\n  2. We construct an isomorphism of `R/I`-modules `R^n/I^n \u2243 R^m/I^m` using the isomorphism\n     `R^n \u2243 R^m`.\n-/\n\nsection\nvariables {R : Type u} [comm_ring R] (I : ideal R) {\u03b9 : Type v} [fintype \u03b9] {\u03b9' : Type w}\n\n/-- An `R`-linear map `R^n \u2192 R^m` induces a function `R^n/I^n \u2192 R^m/I^m`. -/\nprivate def induced_map (I : ideal R) (e : (\u03b9 \u2192 R) \u2192\u2097[R] (\u03b9' \u2192 R)) :\n  (I.pi \u03b9).quotient \u2192 (I.pi \u03b9').quotient :=\n\u03bb x, quotient.lift_on' x (\u03bb y, ideal.quotient.mk _ (e y))\nbegin\n  refine \u03bb a b hab, ideal.quotient.eq.2 (\u03bb h, _),\n  rw \u2190linear_map.map_sub,\n  exact ideal.map_pi _ _ hab e h,\nend\n\n/-- An isomorphism of `R`-modules `R^n \u2243 R^m` induces an isomorphism `R/I`-modules\n    `R^n/I^n \u2243 R^m/I^m`. -/\nprivate def induced_equiv [fintype \u03b9'] (I : ideal R) (e : (\u03b9 \u2192 R) \u2243\u2097[R] (\u03b9' \u2192 R)) :\n  (I.pi \u03b9).quotient \u2243\u2097[I.quotient] (I.pi \u03b9').quotient :=\nbegin\n  refine { to_fun := induced_map I e, inv_fun := induced_map I e.symm, .. },\n  all_goals { rintro \u27e8a\u27e9 \u27e8b\u27e9 <|> rintro \u27e8a\u27e9,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr, simp }\nend\n\nend\n\nsection\nlocal attribute [instance] invariant_basis_number_field\nlocal attribute [instance, priority 1] ideal.quotient.field\n\n/-- Nontrivial commutative rings have the invariant basis number property. -/\n@[priority 100]\ninstance invariant_basis_number_of_nontrivial_of_comm_ring {R : Type u} [comm_ring R]\n  [nontrivial R] : invariant_basis_number R :=\n\u27e8\u03bb n m e, let \u27e8I, hI\u27e9 := ideal.exists_maximal R in\n  by exactI eq_of_fin_equiv I.quotient\n    ((ideal.pi_quot_equiv _ _).symm.trans ((induced_equiv _ e).trans (ideal.pi_quot_equiv _ _)))\u27e9\n\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/linear_algebra/invariant_basis_number.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.73996185956645}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Kenny Lau\n\n! This file was ported from Lean 3 source module number_theory.basic\n! leanprover-community/mathlib commit 168ad7fc5d8173ad38be9767a22d50b8ecf1cd00\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.GeomSum\nimport Mathlib.RingTheory.Ideal.Quotient\n\n/-!\n# Basic results in number theory\n\nThis file should contain basic results in number theory. So far, it only contains the essential\nlemma in the construction of the ring of Witt vectors.\n\n## Main statement\n\n`dvd_sub_pow_of_dvd_sub` proves that for elements `a` and `b` in a commutative ring `R` and for\nall natural numbers `p` and `k` if `p` divides `a-b` in `R`, then `p ^ (k + 1)` divides\n`a ^ (p ^ k) - b ^ (p ^ k)`.\n-/\n\n\nsection\n\nopen Ideal Ideal.Quotient\n\ntheorem dvd_sub_pow_of_dvd_sub {R : Type _} [CommRing R] {p : \u2115} {a b : R} (h : (p : R) \u2223 a - b)\n    (k : \u2115) : (p ^ (k + 1) : R) \u2223 a ^ p ^ k - b ^ p ^ k := by\n  induction' k with k ih\n  \u00b7 rwa [pow_one, pow_zero, pow_one, pow_one]\n  rw [pow_succ' p k, pow_mul, pow_mul, \u2190 geom_sum\u2082_mul, pow_succ, Nat.cast_mul]\n  refine' mul_dvd_mul _ ih\n  let f : R \u2192+* R \u29f8 span {(p : R)} := mk (span {(p : R)})\n  have hf : \u2200 r : R, (p : R) \u2223 r \u2194 f r = 0 := fun r \u21a6 by rw [eq_zero_iff_mem, mem_span_singleton]\n  rw [hf, map_sub, sub_eq_zero] at h\n  rw [hf, RingHom.map_geom_sum\u2082, map_pow, map_pow, h, geom_sum\u2082_self, mul_eq_zero_of_left]\n  rw [\u2190 map_natCast f, eq_zero_iff_mem, mem_span_singleton]\n#align dvd_sub_pow_of_dvd_sub dvd_sub_pow_of_dvd_sub\n\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/NumberTheory/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7399618577045841}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\n\nimport topology.algebra.filter_basis\nimport topology.algebra.uniform_group\n\n/-!\n# Uniform properties of neighborhood bases in topological algebra\n\nThis files contains properties of filter bases on algebraic structures that also require the theory\nof uniform spaces.\n\nThe only result so far is a characterization of Cauchy filters in topological groups.\n\n-/\n\nopen_locale uniformity filter\nopen filter\n\nnamespace add_group_filter_basis\n\nvariables {G : Type*} [add_comm_group G] (B : add_group_filter_basis G)\n\n/-- The uniform space structure associated to an abelian group filter basis via the associated\ntopological abelian group structure. -/\nprotected def uniform_space : uniform_space G :=\n@topological_add_group.to_uniform_space G _ B.topology B.is_topological_add_group\n\n/-- The uniform space structure associated to an abelian group filter basis via the associated\ntopological abelian group structure is compatible with its group structure. -/\nprotected lemma uniform_add_group : @uniform_add_group G B.uniform_space _:=\n@topological_add_group_is_uniform G _ B.topology B.is_topological_add_group\n\nlemma cauchy_iff {F : filter G} :\n  @cauchy G B.uniform_space F \u2194 F.ne_bot \u2227 \u2200 U \u2208 B, \u2203 M \u2208 F, \u2200 x y \u2208 M, y - x \u2208 U :=\nbegin\n  letI := B.uniform_space,\n  haveI := B.uniform_add_group,\n  suffices : F \u00d7\u1da0 F \u2264 \ud835\udce4 G \u2194 \u2200 U \u2208 B, \u2203 M \u2208 F, \u2200 x y \u2208 M, y - x \u2208 U,\n    by split ; rintros \u27e8h', h\u27e9 ; refine \u27e8h', _\u27e9 ; [rwa \u2190 this, rwa this],\n  rw [uniformity_eq_comap_nhds_zero G, \u2190 map_le_iff_le_comap],\n  change tendsto _ _ _ \u2194 _,\n  simp [(basis_sets F).prod_self.tendsto_iff B.nhds_zero_has_basis, @forall_swap (_ \u2208 _) G]\nend\n\nend add_group_filter_basis\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/topology/algebra/uniform_filter_basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7399572592095396}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n-/\nimport number_theory.legendre_symbol.zmod_char\nimport field_theory.finite.basic\n\n/-!\n# Quadratic characters of finite fields\n\nThis file defines the quadratic character on a finite field `F` and proves\nsome basic statements about it.\n\n## Tags\n\nquadratic character\n-/\n\nnamespace char\n\n/-!\n### Definition of the quadratic character\n\nWe define the quadratic character of a finite field `F` with values in \u2124.\n-/\n\nsection define\n\n/-- Define the quadratic character with values in \u2124 on a monoid with zero `\u03b1`.\nIt takes the value zero at zero; for non-zero argument `a : \u03b1`, it is `1`\nif `a` is a square, otherwise it is `-1`.\n\nThis only deserves the name \"character\" when it is multiplicative,\ne.g., when `\u03b1` is a finite field. See `quadratic_char_mul`.\n-/\ndef quadratic_char (\u03b1 : Type*) [monoid_with_zero \u03b1] [decidable_eq \u03b1]\n  [decidable_pred (is_square : \u03b1 \u2192 Prop)] (a : \u03b1) : \u2124 :=\nif a = 0 then 0 else if is_square a then 1 else -1\n\nend define\n\n/-!\n### Basic properties of the quadratic character\n\nWe prove some properties of the quadratic character.\nWe work with a finite field `F` here.\nThe interesting case is when the characteristic of `F` is odd.\n-/\n\nsection quadratic_char\n\nvariables {F : Type*} [field F] [fintype F] [decidable_eq F]\n\n/-- Some basic API lemmas -/\nlemma quadratic_char_eq_zero_iff (a : F) : quadratic_char F a = 0 \u2194 a = 0 :=\nbegin\n  simp only [quadratic_char],\n  by_cases ha : a = 0,\n  { simp only [ha, eq_self_iff_true, if_true], },\n  { simp only [ha, if_false, iff_false],\n    split_ifs; simp only [neg_eq_zero, one_ne_zero, not_false_iff], },\nend\n\n@[simp]\nlemma quadratic_char_zero : quadratic_char F 0 = 0 :=\nby simp only [quadratic_char, eq_self_iff_true, if_true, id.def]\n\n@[simp]\nlemma quadratic_char_one : quadratic_char F 1 = 1 :=\nby simp only [quadratic_char, one_ne_zero, is_square_one, if_true, if_false, id.def]\n\n/-- For nonzero `a : F`, `quadratic_char F a = 1 \u2194 is_square a`. -/\nlemma quadratic_char_one_iff_is_square {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = 1 \u2194 is_square a :=\nby { simp only [quadratic_char, ha, (dec_trivial : (-1 : \u2124) \u2260 1), if_false, ite_eq_left_iff],\n     tauto, }\n\n/-- The quadratic character takes the value `1` on nonzero squares. -/\nlemma quadratic_char_sq_one' {a : F} (ha : a \u2260 0) : quadratic_char F (a ^ 2) = 1 :=\nby simp only [quadratic_char, ha, pow_eq_zero_iff, nat.succ_pos', is_square_sq, if_true, if_false]\n\n/-- If `ring_char F = 2`, then `quadratic_char F` takes the value `1` on nonzero elements. -/\nlemma quadratic_char_eq_one_of_char_two (hF : ring_char F = 2) {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = 1 :=\nbegin\n  simp only [quadratic_char, ha, if_false, ite_eq_left_iff],\n  intro h,\n  exfalso,\n  exact h (finite_field.is_square_of_char_two hF a),\nend\n\n/-- If `ring_char F` is odd, then `quadratic_char F a` can be computed in\nterms of `a ^ (fintype.card F / 2)`. -/\nlemma quadratic_char_eq_pow_of_char_ne_two (hF : ring_char F \u2260 2) {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = if a ^ (fintype.card F / 2) = 1 then 1 else -1 :=\nbegin\n  simp only [quadratic_char, ha, if_false],\n  simp_rw finite_field.is_square_iff hF ha,\nend\n\n/-- The quadratic character is multiplicative. -/\nlemma quadratic_char_mul (a b : F) :\n  quadratic_char F (a * b) = quadratic_char F a * quadratic_char F b :=\nbegin\n  by_cases ha : a = 0,\n  { rw [ha, zero_mul, quadratic_char_zero, zero_mul], },\n  -- now `a \u2260 0`\n  by_cases hb : b = 0,\n  { rw [hb, mul_zero, quadratic_char_zero, mul_zero], },\n  -- now `a \u2260 0` and `b \u2260 0`\n  have hab := mul_ne_zero ha hb,\n  by_cases hF : ring_char F = 2,\n  { -- case `ring_char F = 2`\n    rw [quadratic_char_eq_one_of_char_two hF ha,\n        quadratic_char_eq_one_of_char_two hF hb,\n        quadratic_char_eq_one_of_char_two hF hab,\n        mul_one], },\n  { -- case of odd characteristic\n    rw [quadratic_char_eq_pow_of_char_ne_two hF ha,\n        quadratic_char_eq_pow_of_char_ne_two hF hb,\n        quadratic_char_eq_pow_of_char_ne_two hF hab,\n        mul_pow],\n    cases finite_field.pow_dichotomy hF hb with hb' hb',\n    { simp only [hb', mul_one, eq_self_iff_true, if_true], },\n    { have h := ring.neg_one_ne_one_of_char_ne_two hF, -- `-1 \u2260 1`\n      simp only [hb', h, mul_neg, mul_one, if_false, ite_mul, neg_mul],\n      cases finite_field.pow_dichotomy hF ha with ha' ha';\n        simp only [ha', h, neg_neg, eq_self_iff_true, if_true, if_false], }, },\nend\n\n/-- The quadratic character is a homomorphism of monoids with zero. -/\n@[simps] def quadratic_char_hom : F \u2192*\u2080 \u2124 :=\n{ to_fun := quadratic_char F,\n  map_zero' := quadratic_char_zero,\n  map_one' := quadratic_char_one,\n  map_mul' := quadratic_char_mul }\n\n/-- The square of the quadratic character on nonzero arguments is `1`. -/\nlemma quadratic_char_sq_one {a : F} (ha : a \u2260 0) : (quadratic_char F a) ^ 2 = 1 :=\nby rwa [pow_two, \u2190 quadratic_char_mul, \u2190 pow_two, quadratic_char_sq_one']\n\n/-- The quadratic character is `1` or `-1` on nonzero arguments. -/\nlemma quadratic_char_dichotomy {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = 1 \u2228 quadratic_char F a = -1 :=\nsq_eq_one_iff.1 $ quadratic_char_sq_one ha\n\n/-- A variant -/\nlemma quadratic_char_eq_neg_one_iff_not_one {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = -1 \u2194 \u00ac quadratic_char F a = 1 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h\u2082, (or_iff_right h\u2082).mp (quadratic_char_dichotomy ha)\u27e9,\n  rw h,\n  norm_num,\nend\n\n/-- For `a : F`, `quadratic_char F a = -1 \u2194 \u00ac is_square a`. -/\nlemma quadratic_char_neg_one_iff_not_is_square {a : F} :\n  quadratic_char F a = -1 \u2194 \u00ac is_square a :=\nbegin\n  by_cases ha : a = 0,\n  { simp only [ha, is_square_zero, quadratic_char_zero, zero_eq_neg, one_ne_zero, not_true], },\n  { rw [quadratic_char_eq_neg_one_iff_not_one ha, quadratic_char_one_iff_is_square ha] },\nend\n\n/-- If `F` has odd characteristic, then `quadratic_char F` takes the value `-1`. -/\nlemma quadratic_char_exists_neg_one (hF : ring_char F \u2260 2) : \u2203 a, quadratic_char F a = -1 :=\n(finite_field.exists_nonsquare hF).imp (\u03bb b h\u2081, quadratic_char_neg_one_iff_not_is_square.mpr h\u2081)\n\n/-- The number of solutions to `x^2 = a` is determined by the quadratic character. -/\nlemma quadratic_char_card_sqrts (hF : ring_char F \u2260 2) (a : F) :\n  \u2191{x : F | x^2 = a}.to_finset.card = quadratic_char F a + 1 :=\nbegin\n  -- we consider the cases `a = 0`, `a` is a nonzero square and `a` is a nonsquare in turn\n  by_cases h\u2080 : a = 0,\n  { simp only [h\u2080, pow_eq_zero_iff, nat.succ_pos', int.coe_nat_succ, int.coe_nat_zero, zero_add,\n               quadratic_char_zero, add_zero, set.set_of_eq_eq_singleton, set.to_finset_card,\n               set.card_singleton], },\n  { set s := {x : F | x^2 = a}.to_finset with hs,\n    by_cases h : is_square a,\n    { rw (quadratic_char_one_iff_is_square h\u2080).mpr h,\n      rcases h with \u27e8b, h\u27e9,\n      rw [h, mul_self_eq_zero] at h\u2080,\n      have h\u2081 : s = [b, -b].to_finset := by\n      { ext x,\n        simp only [finset.mem_filter, finset.mem_univ, true_and, list.to_finset_cons,\n                   list.to_finset_nil, insert_emptyc_eq, finset.mem_insert, finset.mem_singleton],\n        rw \u2190 pow_two at h,\n        simp only [hs, set.mem_to_finset, set.mem_set_of_eq, h],\n        split,\n        { exact eq_or_eq_neg_of_sq_eq_sq _ _, },\n        { rintro (h\u2082 | h\u2082); rw h\u2082,\n          simp only [neg_sq], }, },\n      norm_cast,\n      rw  [h\u2081, list.to_finset_cons, list.to_finset_cons, list.to_finset_nil],\n      exact finset.card_doubleton\n              (ne.symm (mt (ring.eq_self_iff_eq_zero_of_char_ne_two hF).mp h\u2080)), },\n    { rw quadratic_char_neg_one_iff_not_is_square.mpr h,\n      simp only [int.coe_nat_eq_zero, finset.card_eq_zero, set.to_finset_card,\n                 fintype.card_of_finset, set.mem_set_of_eq, add_left_neg],\n      ext x,\n      simp only [iff_false, finset.mem_filter, finset.mem_univ, true_and, finset.not_mem_empty],\n      rw is_square_iff_exists_sq at h,\n      exact \u03bb h', h \u27e8_, h'.symm\u27e9, }, },\nend\n\nopen_locale big_operators\n\n/-- The sum over the values of the quadratic character is zero when the characteristic is odd. -/\nlemma quadratic_char_sum_zero (hF : ring_char F \u2260 2) : \u2211 (a : F), quadratic_char F a = 0 :=\nbegin\n  cases (quadratic_char_exists_neg_one hF) with b hb,\n  have h\u2080 : b \u2260 0 := by\n  { intro hf,\n    rw [hf, quadratic_char_zero, zero_eq_neg] at hb,\n    exact one_ne_zero hb, },\n  have h\u2081 : \u2211 (a : F), quadratic_char F (b * a) = \u2211 (a : F), quadratic_char F a :=\n    fintype.sum_bijective _ (mul_left_bijective\u2080 b h\u2080) _ _ (\u03bb x, rfl),\n  simp only [quadratic_char_mul] at h\u2081,\n  rw [\u2190 finset.mul_sum, hb, neg_mul, one_mul] at h\u2081,\n  exact eq_zero_of_neg_eq h\u2081,\nend\n\nend quadratic_char\n\nend char\n\n/-!\n### Special values of the quadratic character\n\nWe express `quadratic_char F (-1)` in terms of `\u03c7\u2084`.\n-/\n\nsection special_values\n\nnamespace char\n\nopen zmod\n\nvariables {F : Type*} [field F] [fintype F]\n\n/-- The value of the quadratic character at `-1` -/\nlemma quadratic_char_neg_one [decidable_eq F] (hF : ring_char F \u2260 2) :\n  quadratic_char F (-1) = \u03c7\u2084 (fintype.card F) :=\nbegin\n  have h\u2081 : (-1 : F) \u2260 0 := by { rw neg_ne_zero, exact one_ne_zero },\n  have h := quadratic_char_eq_pow_of_char_ne_two hF h\u2081,\n  rw [h, \u03c7\u2084_eq_neg_one_pow (finite_field.odd_card_of_char_ne_two hF)],\n  set n := fintype.card F / 2,\n  cases (nat.even_or_odd n) with h\u2082 h\u2082,\n  { simp only [even.neg_one_pow h\u2082, eq_self_iff_true, if_true], },\n  { simp only [odd.neg_one_pow h\u2082, ite_eq_right_iff],\n    exact \u03bb (hf : -1 = 1),\n            false.rec (1 = -1) (ring.neg_one_ne_one_of_char_ne_two hF hf), },\nend\n\n/-- The interpretation in terms of whether `-1` is a square in `F` -/\nlemma is_square_neg_one_iff : is_square (-1 : F) \u2194 fintype.card F % 4 \u2260 3 :=\nbegin\n  classical, -- suggested by the linter (instead of `[decidable_eq F]`)\n  by_cases hF : (ring_char F = 2),\n  { simp only [finite_field.is_square_of_char_two hF, ne.def, true_iff],\n    exact (\u03bb hf, one_ne_zero ((nat.odd_of_mod_four_eq_three hf).symm.trans\n                                (finite_field.even_card_of_char_two hF)))},\n  { have h\u2081 : (-1 : F) \u2260 0 := by { rw neg_ne_zero, exact one_ne_zero },\n    have h\u2082 := finite_field.odd_card_of_char_ne_two hF,\n    rw [\u2190 quadratic_char_one_iff_is_square h\u2081, quadratic_char_neg_one hF,\n        \u03c7\u2084_nat_eq_if_mod_four, h\u2082],\n    have h\u2083 := nat.odd_mod_four_iff.mp h\u2082,\n    simp only [nat.one_ne_zero, if_false, ite_eq_left_iff, ne.def],\n    norm_num,\n    split,\n    { intros h h',\n      have t := (of_not_not h).symm.trans h',\n      norm_num at t, },\n    exact \u03bb h h', h' ((or_iff_left h).mp h\u2083), },\nend\n\nend char\n\nend special_values\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/number_theory/legendre_symbol/quadratic_char.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7399572470415492}}
{"text": "import tactic\nimport sym2\n\nuniverse u\nvariables (V : Type u)\n\nstructure simple_graph :=\n(adj : V \u2192 V \u2192 Prop)\n(sym : symmetric adj . obviously)\n(loopless : irreflexive adj . obviously)\n\nnamespace simple_graph\n\ndef induced_subgraph (G : simple_graph V) (S : set V) : simple_graph S :=\n{adj := \u03bb a b, G.adj a b,\nsym := \u03bb a b h, G.sym h, \nloopless := \u03bb x h, G.loopless x h}\n\nvariables {V} (T : simple_graph V)\n\ndef E : Type u := {x : sym2 V // x \u2208 sym2.from_rel T.sym}\n\ninstance has_mem : has_mem V T.E := { mem := \u03bb v e, v \u2208 e.val }\n\nstructure path :=\n(head : V)\n(tail : list V)\n(edges : list T.E)\n(length_eq : edges.length = tail.length)\n(adj : \u2200 (n : \u2115) (hn : n < edges.length), \n  let u := (list.cons head tail).nth_le n (by { simp; omega }) in\n  let v := (list.cons head tail).nth_le (n + 1) (by { simp, cc }) in\n  u \u2260 v \u2227 u \u2208 edges.nth_le n hn \u2227 v \u2208 edges.nth_le n hn)\n\nnamespace path\nvariables {T} \nvariables (p : T.path)\n\ndef vertices : list V := p.head :: p.tail \n\ndef is_tour : Prop := list.nodup p.vertices\n\nsection classical\nopen_locale classical\nnoncomputable def last : V := if h : p.tail = list.nil then p.head else p.tail.last h\n\nend classical\nend path\n\ndef acyclic : Prop := \u2200 (p : T.path), p.head \u2260 p.last \u2227 p.is_tour\n\nlemma acyclic_subgraph_acyclic (t : acyclic T) (s : set V) : acyclic (induced_subgraph V T s) :=\nbegin\n    -- Proof outline:\n    -- T has no cycles so T \\ {x} has no cycles\n    sorry,\nend\n\nend simple_graph", "meta": {"author": "agusakov", "repo": "graph_theory_2020", "sha": "83a8afc31aa28dbec39a768d6042d3cb515f7a16", "save_path": "github-repos/lean/agusakov-graph_theory_2020", "path": "github-repos/lean/agusakov-graph_theory_2020/graph_theory_2020-83a8afc31aa28dbec39a768d6042d3cb515f7a16/src/mwe_scratchwork.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7399572452438393}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.ordinal.fixed_point\n\n/-!\n### Principal ordinals\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define principal or indecomposable ordinals, and we prove the standard properties about them.\n\n### Main definitions and results\n* `principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and\n  any other typically excluded edge cases for simplicity.\n* `unbounded_principal`: Principal ordinals are unbounded.\n* `principal_add_iff_zero_or_omega_opow`: The main characterization theorem for additive principal\n  ordinals.\n* `principal_mul_iff_le_two_or_omega_opow_opow`: The main characterization theorem for\n  multiplicative principal ordinals.\n\n### Todo\n* Prove that exponential principal ordinals are 0, 1, 2, \u03c9, or epsilon numbers, i.e. fixed points\n  of `\u03bb x, \u03c9 ^ x`.\n-/\n\nuniverse u\n\nnoncomputable theory\n\nopen order\n\nnamespace ordinal\nlocal infixr (name := ordinal.pow) ^ := @pow ordinal ordinal ordinal.has_pow\n\n/-! ### Principal ordinals -/\n\n/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of\nordinals less than it is closed under that operation. In standard mathematical usage, this term is\nalmost exclusively used for additive and multiplicative principal ordinals.\n\nFor simplicity, we break usual convention and regard 0 as principal. -/\ndef principal (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : Prop :=\n\u2200 \u2983a b\u2984, a < o \u2192 b < o \u2192 op a b < o\n\ntheorem principal_iff_principal_swap {op : ordinal \u2192 ordinal \u2192 ordinal} {o : ordinal} :\n  principal op o \u2194 principal (function.swap op) o :=\nby split; exact \u03bb h a b ha hb, h hb ha\n\ntheorem principal_zero {op : ordinal \u2192 ordinal \u2192 ordinal} : principal op 0 :=\n\u03bb a _ h, (ordinal.not_lt_zero a h).elim\n\n@[simp] theorem principal_one_iff {op : ordinal \u2192 ordinal \u2192 ordinal} :\n  principal op 1 \u2194 op 0 0 = 0 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h a b ha hb, _\u27e9,\n  { rwa \u2190lt_one_iff_zero,\n    exact h zero_lt_one zero_lt_one },\n  { rwa [lt_one_iff_zero, ha, hb] at * }\nend\n\ntheorem principal.iterate_lt {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal} (hao : a < o)\n  (ho : principal op o) (n : \u2115) : (op a)^[n] a < o :=\nbegin\n  induction n with n hn,\n  { rwa function.iterate_zero },\n  { rw function.iterate_succ', exact ho hao hn }\nend\n\ntheorem op_eq_self_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal.{u}}\n  (hao : a < o) (H : is_normal (op a)) (ho : principal op o) (ho' : is_limit o) : op a o = o :=\nbegin\n  refine le_antisymm _ (H.self_le _),\n  rw [\u2190is_normal.bsup_eq.{u u} H ho', bsup_le_iff],\n  exact \u03bb b hbo, (ho hao hbo).le\nend\n\ntheorem nfp_le_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal}\n  {a o : ordinal} (hao : a < o) (ho : principal op o) : nfp (op a) a \u2264 o :=\nnfp_le $ \u03bb n, (ho.iterate_lt hao n).le\n\n/-! ### Principal ordinals are unbounded -/\n\n/-- The least strict upper bound of `op` applied to all pairs of ordinals less than `o`. This is\nessentially a two-argument version of `ordinal.blsub`. -/\ndef blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : ordinal :=\nlsub (\u03bb x : o.out.\u03b1 \u00d7 o.out.\u03b1, op (typein (<) x.1) (typein (<) x.2))\n\ntheorem lt_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) {o : ordinal} {a b : ordinal} (ha : a < o)\n  (hb : b < o) : op a b < blsub\u2082 op o :=\nbegin\n  convert lt_lsub _ (prod.mk (enum (<) a (by rwa type_lt)) (enum (<) b (by rwa type_lt))),\n  simp only [typein_enum]\nend\n\ntheorem principal_nfp_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) :\n  principal op (nfp (blsub\u2082.{u u} op) o) :=\n\u03bb a b ha hb, begin\n  rw lt_nfp at *,\n  cases ha with m hm,\n  cases hb with n hn,\n  cases le_total ((blsub\u2082.{u u} op)^[m] o) ((blsub\u2082.{u u} op)^[n] o) with h h,\n  { use n + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op (hm.trans_le h) hn },\n  { use m + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op hm (hn.trans_le h) },\nend\n\ntheorem unbounded_principal (op : ordinal \u2192 ordinal \u2192 ordinal) :\n  set.unbounded (<) {o | principal op o} :=\n\u03bb o, \u27e8_, principal_nfp_blsub\u2082 op o, (le_nfp _ o).not_lt\u27e9\n\n/-! #### Additive principal ordinals -/\n\ntheorem principal_add_one : principal (+) 1 :=\nprincipal_one_iff.2 $ zero_add 0\n\ntheorem principal_add_of_le_one {o : ordinal} (ho : o \u2264 1) : principal (+) o :=\nbegin\n  rcases le_one_iff.1 ho with rfl | rfl,\n  { exact principal_zero },\n  { exact principal_add_one }\nend\n\ntheorem principal_add_is_limit {o : ordinal} (ho\u2081 : 1 < o) (ho : principal (+) o) :\n  o.is_limit :=\nbegin\n  refine \u27e8\u03bb ho\u2080, _, \u03bb a hao, _\u27e9,\n  { rw ho\u2080 at ho\u2081,\n    exact not_lt_of_gt zero_lt_one ho\u2081 },\n  { cases eq_or_ne a 0 with ha ha,\n    { rw [ha, succ_zero],\n      exact ho\u2081 },\n    { refine lt_of_le_of_lt _ (ho hao hao),\n      rwa [\u2190add_one_eq_succ, add_le_add_iff_left, one_le_iff_ne_zero] } }\nend\n\ntheorem principal_add_iff_add_left_eq_self {o : ordinal} :\n  principal (+) o \u2194 \u2200 a < o, a + o = o :=\nbegin\n  refine \u27e8\u03bb ho a hao, _, \u03bb h a b hao hbo, _\u27e9,\n  { cases lt_or_le 1 o with ho\u2081 ho\u2081,\n    { exact op_eq_self_of_principal hao (add_is_normal a) ho (principal_add_is_limit ho\u2081 ho) },\n    { rcases le_one_iff.1 ho\u2081 with rfl | rfl,\n      { exact (ordinal.not_lt_zero a hao).elim },\n      { rw lt_one_iff_zero at hao,\n        rw [hao, zero_add] }}},\n  { rw \u2190h a hao,\n    exact (add_is_normal a).strict_mono hbo }\nend\n\ntheorem exists_lt_add_of_not_principal_add {a} (ha : \u00ac principal (+) a) :\n  \u2203 (b c) (hb : b < a) (hc : c < a), b + c = a :=\nbegin\n  unfold principal at ha,\n  push_neg at ha,\n  rcases ha with \u27e8b, c, hb, hc, H\u27e9,\n  refine \u27e8b, _, hb, lt_of_le_of_ne (sub_le_self a b) (\u03bb hab, _),\n    ordinal.add_sub_cancel_of_le hb.le\u27e9,\n  rw [\u2190sub_le, hab] at H,\n  exact H.not_lt hc\nend\n\ntheorem principal_add_iff_add_lt_ne_self {a} :\n  principal (+) a \u2194 \u2200 \u2983b c\u2984, b < a \u2192 c < a \u2192 b + c \u2260 a :=\n\u27e8\u03bb ha b c hb hc, (ha hb hc).ne, \u03bb H, begin\n  by_contra' ha,\n  rcases exists_lt_add_of_not_principal_add ha with \u27e8b, c, hb, hc, rfl\u27e9,\n  exact (H hb hc).irrefl\nend\u27e9\n\ntheorem add_omega {a : ordinal} (h : a < omega) : a + omega = omega :=\nbegin\n  rcases lt_omega.1 h with \u27e8n, rfl\u27e9,\n  clear h, induction n with n IH,\n  { rw [nat.cast_zero, zero_add] },\n  { rwa [nat.cast_succ, add_assoc, one_add_of_omega_le (le_refl _)] }\nend\n\ntheorem principal_add_omega : principal (+) omega :=\nprincipal_add_iff_add_left_eq_self.2 (\u03bb a, add_omega)\n\ntheorem add_omega_opow {a b : ordinal} (h : a < omega ^ b) : a + omega ^ b = omega ^ b :=\nbegin\n  refine le_antisymm _ (le_add_left _ _),\n  revert h, refine limit_rec_on b (\u03bb h, _) (\u03bb b _ h, _) (\u03bb b l IH h, _),\n  { rw [opow_zero, \u2190 succ_zero, lt_succ_iff, ordinal.le_zero] at h,\n    rw [h, zero_add] },\n  { rw opow_succ at h,\n    rcases (lt_mul_of_limit omega_is_limit).1 h with \u27e8x, xo, ax\u27e9,\n    refine le_trans (add_le_add_right (le_of_lt ax) _) _,\n    rw [opow_succ, \u2190 mul_add, add_omega xo] },\n  { rcases (lt_opow_of_limit omega_ne_zero l).1 h with \u27e8x, xb, ax\u27e9,\n    exact (((add_is_normal a).trans (opow_is_normal one_lt_omega)).limit_le l).2 (\u03bb y yb,\n      (add_le_add_left (opow_le_opow_right omega_pos (le_max_right _ _)) _).trans\n      (le_trans (IH _ (max_lt xb yb) (ax.trans_le $ opow_le_opow_right omega_pos (le_max_left _ _)))\n      (opow_le_opow_right omega_pos $ le_of_lt $ max_lt xb yb))) }\nend\n\ntheorem principal_add_omega_opow (o : ordinal) : principal (+) (omega ^ o) :=\nprincipal_add_iff_add_left_eq_self.2 (\u03bb a, add_omega_opow)\n\n/-- The main characterization theorem for additive principal ordinals. -/\ntheorem principal_add_iff_zero_or_omega_opow {o : ordinal} :\n  principal (+) o \u2194 o = 0 \u2228 \u2203 a, o = omega ^ a :=\nbegin\n  rcases eq_or_ne o 0 with rfl | ho,\n  { simp only [principal_zero, or.inl] },\n  { rw [principal_add_iff_add_left_eq_self],\n    simp only [ho, false_or],\n    refine \u27e8\u03bb H, \u27e8_, ((lt_or_eq_of_le (opow_log_le_self _ ho))\n        .resolve_left $ \u03bb h, _).symm\u27e9, \u03bb \u27e8b, e\u27e9, e.symm \u25b8 \u03bb a, add_omega_opow\u27e9,\n    have := H _ h,\n    have := lt_opow_succ_log_self one_lt_omega o,\n    rw [opow_succ, lt_mul_of_limit omega_is_limit] at this,\n    rcases this with \u27e8a, ao, h'\u27e9,\n    rcases lt_omega.1 ao with \u27e8n, rfl\u27e9, clear ao,\n    revert h', apply not_lt_of_le,\n    suffices e : omega ^ log omega o * \u2191n + o = o,\n    { simpa only [e] using le_add_right (omega ^ log omega o * \u2191n) o },\n    induction n with n IH, {simp only [nat.cast_zero, mul_zero, zero_add]},\n    simp only [nat.cast_succ, mul_add_one, add_assoc, this, IH] }\nend\n\ntheorem opow_principal_add_of_principal_add {a} (ha : principal (+) a) (b : ordinal) :\n  principal (+) (a ^ b) :=\nbegin\n  rcases principal_add_iff_zero_or_omega_opow.1 ha with rfl | \u27e8c, rfl\u27e9,\n  { rcases eq_or_ne b 0 with rfl | hb,\n    { rw opow_zero, exact principal_add_one },\n    { rwa zero_opow hb } },\n  { rw \u2190opow_mul, exact principal_add_omega_opow _ }\nend\n\ntheorem add_absorp {a b c : ordinal} (h\u2081 : a < omega ^ b) (h\u2082 : omega ^ b \u2264 c) : a + c = c :=\nby rw [\u2190 ordinal.add_sub_cancel_of_le h\u2082, \u2190 add_assoc, add_omega_opow h\u2081]\n\ntheorem mul_principal_add_is_principal_add (a : ordinal.{u}) {b : ordinal.{u}} (hb\u2081 : b \u2260 1)\n  (hb : principal (+) b) : principal (+) (a * b) :=\nbegin\n  rcases eq_zero_or_pos a with rfl | ha,\n  { rw zero_mul,\n    exact principal_zero },\n  { rcases eq_zero_or_pos b with rfl | hb\u2081',\n    { rw mul_zero,\n      exact principal_zero },\n    { rw [\u2190 succ_le_iff, succ_zero] at hb\u2081',\n      intros c d hc hd,\n      rw lt_mul_of_limit (principal_add_is_limit (lt_of_le_of_ne hb\u2081' hb\u2081.symm) hb) at *,\n      { rcases hc with \u27e8x, hx, hx'\u27e9,\n        rcases hd with \u27e8y, hy, hy'\u27e9,\n        use [x + y, hb hx hy],\n        rw mul_add,\n        exact left.add_lt_add hx' hy' },\n      assumption' } }\nend\n\n/-! #### Multiplicative principal ordinals -/\n\ntheorem principal_mul_one : principal (*) 1 :=\nby { rw principal_one_iff, exact zero_mul _ }\n\ntheorem principal_mul_two : principal (*) 2 :=\n\u03bb a b ha hb, begin\n  have h\u2082 : succ (1 : ordinal) = 2 := rfl,\n  rw [\u2190h\u2082, lt_succ_iff] at *,\n  convert mul_le_mul' ha hb,\n  exact (mul_one 1).symm\nend\n\ntheorem principal_mul_of_le_two {o : ordinal} (ho : o \u2264 2) : principal (*) o :=\nbegin\n  rcases lt_or_eq_of_le ho with ho | rfl,\n  { have h\u2082 : succ (1 : ordinal) = 2 := rfl,\n    rw [\u2190h\u2082, lt_succ_iff] at ho,\n    rcases lt_or_eq_of_le ho with ho | rfl,\n    { rw lt_one_iff_zero.1 ho,\n      exact principal_zero },\n    { exact principal_mul_one } },\n  { exact principal_mul_two }\nend\n\ntheorem principal_add_of_principal_mul {o : ordinal} (ho : principal (*) o) (ho\u2082 : o \u2260 2) :\n  principal (+) o :=\nbegin\n  cases lt_or_gt_of_ne ho\u2082 with ho\u2081 ho\u2082,\n  { change o < succ 1 at ho\u2081,\n    rw lt_succ_iff at ho\u2081,\n    exact principal_add_of_le_one ho\u2081 },\n  { refine \u03bb a b hao hbo, lt_of_le_of_lt _ (ho (max_lt hao hbo) ho\u2082),\n    rw mul_two,\n    exact add_le_add (le_max_left a b) (le_max_right a b) }\nend\n\ntheorem principal_mul_is_limit {o : ordinal.{u}} (ho\u2082 : 2 < o) (ho : principal (*) o) :\n  o.is_limit :=\nprincipal_add_is_limit\n  ((lt_succ 1).trans ho\u2082)\n  (principal_add_of_principal_mul ho (ne_of_gt ho\u2082))\n\ntheorem principal_mul_iff_mul_left_eq {o : ordinal} :\n  principal (*) o \u2194 \u2200 a, 0 < a \u2192 a < o \u2192 a * o = o :=\nbegin\n  refine \u27e8\u03bb h a ha\u2080 hao, _, \u03bb h a b hao hbo, _\u27e9,\n  { cases le_or_gt o 2 with ho ho,\n    { convert one_mul o,\n      apply le_antisymm,\n      { have : a < succ 1 := hao.trans_le ho,\n        rwa lt_succ_iff at this },\n      { rwa [\u2190succ_le_iff, succ_zero] at ha\u2080 } },\n    { exact op_eq_self_of_principal hao (mul_is_normal ha\u2080) h (principal_mul_is_limit ho h) } },\n  { rcases eq_or_ne a 0 with rfl | ha, { rwa zero_mul },\n    rw \u2190ordinal.pos_iff_ne_zero at ha,\n    rw \u2190h a ha hao,\n    exact (mul_is_normal ha).strict_mono hbo }\nend\n\ntheorem principal_mul_omega : principal (*) omega :=\n\u03bb a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by { rw [\u2190 nat_cast_mul], apply nat_lt_omega }\nend\n\ntheorem mul_omega {a : ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega :=\nprincipal_mul_iff_mul_left_eq.1 (principal_mul_omega) a a0 ha\n\ntheorem mul_lt_omega_opow {a b c : ordinal}\n  (c0 : 0 < c) (ha : a < omega ^ c) (hb : b < omega) : a * b < omega ^ c :=\nbegin\n  rcases zero_or_succ_or_limit c with rfl|\u27e8c,rfl\u27e9|l,\n  { exact (lt_irrefl _).elim c0 },\n  { rw opow_succ at ha,\n    rcases ((mul_is_normal $ opow_pos _ omega_pos).limit_lt\n      omega_is_limit).1 ha with \u27e8n, hn, an\u27e9,\n    apply (mul_le_mul_right' (le_of_lt an) _).trans_lt,\n    rw [opow_succ, mul_assoc, mul_lt_mul_iff_left (opow_pos _ omega_pos)],\n    exact principal_mul_omega hn hb },\n  { rcases ((opow_is_normal one_lt_omega).limit_lt l).1 ha with \u27e8x, hx, ax\u27e9,\n    refine (mul_le_mul' (le_of_lt ax) (le_of_lt hb)).trans_lt _,\n    rw [\u2190 opow_succ, opow_lt_opow_iff_right one_lt_omega],\n    exact l.2 _ hx }\nend\n\ntheorem mul_omega_opow_opow {a b : ordinal} (a0 : 0 < a) (h : a < omega ^ omega ^ b) :\n  a * omega ^ omega ^ b = omega ^ omega ^ b :=\nbegin\n  by_cases b0 : b = 0, {rw [b0, opow_zero, opow_one] at h \u22a2, exact mul_omega a0 h},\n  refine le_antisymm _\n    (by simpa only [one_mul] using mul_le_mul_right' (one_le_iff_pos.2 a0) (omega ^ omega ^ b)),\n  rcases (lt_opow_of_limit omega_ne_zero (opow_is_limit_left omega_is_limit b0)).1 h\n    with \u27e8x, xb, ax\u27e9,\n  apply (mul_le_mul_right' (le_of_lt ax) _).trans,\n  rw [\u2190 opow_add, add_omega_opow xb]\nend\n\ntheorem principal_mul_omega_opow_opow (o : ordinal) : principal (*) (omega ^ omega ^ o) :=\nprincipal_mul_iff_mul_left_eq.2 (\u03bb a, mul_omega_opow_opow)\n\ntheorem principal_add_of_principal_mul_opow {o b : ordinal} (hb : 1 < b)\n  (ho : principal (*) (b ^ o)) : principal (+) o :=\n\u03bb x y hx hy, begin\n  have := ho ((opow_lt_opow_iff_right hb).2 hx) ((opow_lt_opow_iff_right hb).2 hy),\n  rwa [\u2190opow_add, opow_lt_opow_iff_right hb] at this\nend\n\n/-- The main characterization theorem for multiplicative principal ordinals. -/\ntheorem principal_mul_iff_le_two_or_omega_opow_opow {o : ordinal} :\n  principal (*) o \u2194 o \u2264 2 \u2228 \u2203 a, o = omega ^ omega ^ a :=\nbegin\n  refine \u27e8\u03bb ho, _, _\u27e9,\n  { cases le_or_lt o 2 with ho\u2082 ho\u2082,\n    { exact or.inl ho\u2082 },\n    rcases principal_add_iff_zero_or_omega_opow.1 (principal_add_of_principal_mul ho ho\u2082.ne')\n      with rfl | \u27e8a, rfl\u27e9,\n    { exact (ordinal.not_lt_zero 2 ho\u2082).elim },\n    rcases principal_add_iff_zero_or_omega_opow.1\n      (principal_add_of_principal_mul_opow one_lt_omega ho) with rfl | \u27e8b, rfl\u27e9,\n    { rw opow_zero at ho\u2082,\n      exact ((lt_succ 1).not_le ho\u2082.le).elim },\n    exact or.inr \u27e8b, rfl\u27e9 },\n  { rintro (ho\u2082 | \u27e8a, rfl\u27e9),\n    { exact principal_mul_of_le_two ho\u2082 },\n    { exact principal_mul_omega_opow_opow a } }\nend\n\n\n\ntheorem mul_eq_opow_log_succ {a b : ordinal.{u}} (ha : a \u2260 0) (hb : principal (*) b) (hb\u2082 : 2 < b) :\n  a * b = b ^ succ (log b a) :=\nbegin\n  apply le_antisymm,\n  { have hbl := principal_mul_is_limit hb\u2082 hb,\n    rw [\u2190is_normal.bsup_eq.{u u} (mul_is_normal (ordinal.pos_iff_ne_zero.2 ha)) hbl, bsup_le_iff],\n    intros c hcb,\n    have hb\u2081 : 1 < b := (lt_succ 1).trans hb\u2082,\n    have hbo\u2080 : b ^ b.log a \u2260 0 := ordinal.pos_iff_ne_zero.1 (opow_pos _ (zero_lt_one.trans hb\u2081)),\n    apply le_trans (mul_le_mul_right' (le_of_lt (lt_mul_succ_div a hbo\u2080)) c),\n    rw [mul_assoc, opow_succ],\n    refine mul_le_mul_left' (le_of_lt (hb (hbl.2 _ _) hcb)) _,\n    rw [div_lt hbo\u2080, \u2190opow_succ],\n    exact lt_opow_succ_log_self hb\u2081 _ },\n  { rw opow_succ,\n    exact mul_le_mul_right' (opow_log_le_self b ha) b }\nend\n\n/-! #### Exponential principal ordinals -/\n\ntheorem principal_opow_omega : principal (^) omega :=\n\u03bb a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by { simp_rw \u2190nat_cast_opow, apply nat_lt_omega }\nend\n\ntheorem opow_omega {a : ordinal} (a1 : 1 < a) (h : a < omega) : a ^ omega = omega :=\nle_antisymm\n  ((opow_le_of_limit (one_le_iff_ne_zero.1 $ le_of_lt a1) omega_is_limit).2\n    (\u03bb b hb, (principal_opow_omega h hb).le))\n  (right_le_opow _ a1)\n\nend ordinal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/set_theory/ordinal/principal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7399529685531822}}
{"text": "\n\n--------------------------------------------------------------------------------\n/- SYNTAX -/\n--------------------------------------------------------------------------------\n\n/-\n\nIn our aim to formalize modal logic, we first need to capture its syntax. \nTo do this, we'll implement a deep embedding in Lean.\n\n-/\n\n--------------------------------------------------------------------------------\n\n/- \n\n\u00a7 Formulas\n\nWe will aim to define formulas reflecting the classical definition i.e. \n\n1. '\u22a5' is an (atomic) formula\n2. '\u22a4' is an (atomic) formula\n3. Every sentence symbol 'p\u1d62' is a formula\n4. If 'A' is a formula, so is '\u00acA' \n5. If 'A' and 'B' are formulas, so are:\n    - 'A \u2227 B'\n    - 'A \u2228 B'\n    - 'A \u2192 B'\n    - 'A \u2194 B'\n6. If 'A' is a formula, so are:\n    - '\u25a1 A'\n    - '\u25c7 A'\n7. Nothing else is a formula\n\nThis is an inductive definition, so we'll define these formulas \nin Lean similarly. Furthermore, we'll define only a select amount of these \nformulas, namely:\n- '\u22a5' as \"bot\"\n- sentence symbols 'p\u1d62' as \"var\" + a natural number to identify them\n- '\u2227' as \"and\", and will be denoted in Lean as \"&\"\n- '\u2192' as \"impl\" \n- '\u25a1' as \"box\"\nThe other formulas can be defined in terms of these basic ones.\n\n-/\n\ninductive form : Type\n  | bot               : form\n  | var  (n : nat)    : form \n  | and  (A B : form) : form\n  | impl (A B : form) : form\n  | box  (A : form)   : form\n\n\n-- Notation\nnotation `\u22a5`:80  := form.bot\nprefix `p`:80    := form.var\ninfix `&`:79     := form.and\ninfix `\u2283`        := form.impl\nnotation `\u00ac` A   := form.impl A form.bot\nnotation `\u22a4`:80  := \u00ac form.bot\nnotation A `\u2228` B := ((\u00acA) \u2283 B)\nnotation A `\u2194` B := (A \u2283 B) & (B \u2283 A)\nnotation `\u25a1`:80  := form.box \nnotation `\u25c7`:80  := \u03bb A, \u00ac(\u25a1(\u00acA))\n\n--------------------------------------------------------------------------------\n\n/-\n\n\u00a7 Proof system\n\nHere we define the proof system of K for modal logic. K is nice\nbecause it is the smallest normal modal logic, which gives us nice features\nsuch as completeness and soundness. The proof system itself is used to reason\nabout the syntax of the language: it is a set of rules about how to syntactially\n\"get\" new formulas and make reasonings. Later on, we'll define the semantics\nof modal logic which deals with meaning.\n\nWe say that there is a modal derivation (a proof in K) from a \nset of axioms (also referred to as the context) if there is a finite sequence\nof formulas such that each formula B meets one of the following conditions:\n\n1) B is an instance of a tautology\n\n2) B is an instance of some axiom in the ctx\n\n3) B follows by *modus ponens* of two earlier formulas \n  - i.e. both 'A' and 'A \u2192 B' occur in the ctx\n\n4) B follows by *necessitation* of some prior formula\n  - i.e. given that 'A' occurs earlier, let \n    B := \u25a1 A\n\n-/\n\n-- Define a context\n@[reducible] def ctx : Type := set (form)\nnotation \u0393 `\u222a` A := set.insert A \u0393\n\n-- Proof system\ninductive Kproof : ctx \u2192 form \u2192 Prop \n| ax {\u0393} {A} (h : A \u2208 \u0393) : Kproof \u0393 A                               -- axiom in ctx\n| pl1 {\u0393} {A B}           : Kproof \u0393 (A \u2283 (B \u2283 A))                  -- tautologies\n| pl2 {\u0393} {A B C}         : Kproof \u0393 ((A \u2283 (B \u2283 C)) \u2283 ((A \u2283 B) \u2283 (A \u2283 C)))\n| pl3 {\u0393} {A B}           : Kproof \u0393 (((\u00acA) \u2283 (\u00acB)) \u2283 (((\u00acA) \u2283 B) \u2283 A))\n| pl4 {\u0393} {A B}           : Kproof \u0393 (A \u2283 (B \u2283 (A & B)))\n| pl5 {\u0393} {A B}           : Kproof \u0393 ((A & B) \u2283 A)\n| pl6 {\u0393} {A B}           : Kproof \u0393 ((A & B) \u2283 B)\n| pl7 {\u0393} {A B}           : Kproof \u0393 (((\u00acA) \u2283 (\u00acB)) \u2283 (B \u2283 A))\n| kdist {\u0393} {A B}         : Kproof \u0393 ((\u25a1 (A \u2283 B)) \u2283 ((\u25a1 A) \u2283 (\u25a1 B))) -- rule K \n| mp {\u0393} {A B}                                                       -- modus ponens\n  (hpq: Kproof \u0393 (A \u2283 B)) \n  (hp : Kproof \u0393 A)         : Kproof \u0393 B\n| nec {\u0393} {A}                                                        -- necessitation\n  (hp: Kproof \u0393 A)          : Kproof \u0393 (\u25a1 A)\n\n  /-\n\n  Note that we hard coded some tautologies. This is because there are an \n  infinite amount of tautologies; having to prove each instance as a lemma would \n  be tedious. The following are tautologies that are hard coded:\n\n  1) A \u2192 B \u2192 A\n  2) (A \u2192 (B \u2192 C)) \u2192 ((A \u2192 B) \u2192 C)\n  3) (\u00acA \u2192 \u00acB) \u2192 ((\u00acA \u2192 B) \u2192 A) \n  4) A \u2192 (B \u2192 (A \u2227 B))\n  5) (A \u2227 B) \u2192 A\n  6) (A \u2227 B) \u2192 B\n  7) (\u00acA \u2192 \u00acB) \u2192 (B \u2192 A)\n\n  and an important one for modal logics, named K after Saul Kripke, \n  - \u25a1(A \u2192 B) \u2192 (\u25a1A \u2192 \u25a1B)\n\n  -/", "meta": {"author": "7-jack", "repo": "modal-logic", "sha": "88eaa0eae60001ce77b17e23a38b7bb48b8f95d3", "save_path": "github-repos/lean/7-jack-modal-logic", "path": "github-repos/lean/7-jack-modal-logic/modal-logic-88eaa0eae60001ce77b17e23a38b7bb48b8f95d3/src/syntax/syntax.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7399529668803336}}
{"text": "import data.fintype data.nat.basic\n       data.zmod.basic algebra.group_power\n\n\nnamespace Zeroknowledgeproof\nvariables (p : \u2115) (q : \u2115) (r : \u2115+)\n  (Hp : nat.prime p)\n  (Hq : nat.prime q)\n  (Hdiv : p = q * r + 1)\n  (g : zmodp p Hp) /- g is a generator -/\n  (Hg : g^q = 1)   /- of order q -/\n  (w : zmodp q Hq) /- private key-/\n  (h : zmodp p Hp)\n  (Hh : h = g^w.val)\n\n/- \nA Schnorr group is a large prime-order subgroup of \u2124\u2217\ud835\udc5d, \nthe multiplicative group of integers modulo \ud835\udc5d. \nTo generate such a group, we find \ud835\udc5d=\ud835\udc5e\ud835\udc5f+1 such that \ud835\udc5d and \ud835\udc5e\nare prime.Then, we choose any \u210e\nin the range 1<\u210e<\ud835\udc5d such that \u210e^r \u2260 1 (mod\ud835\udc5d)\nThe value \ud835\udc54=\u210e^\ud835\udc5f(mod\ud835\udc5d) is a generator of a subgroup \u2124\u2217\ud835\udc5d of order \ud835\udc5e.\nBy Fermat's little theorem\ng^q = h^(rq) = h^(p-1) = 1 (mod p)\n\n-/\n\ndef elgamal_enc (m : zmodp p Hp) (r : zmodp q Hq) :=\n  (g^r.val, g^m.val * h^r.val)\n\ndef elgamal_dec (c : zmodp p Hp \u00d7 zmodp p Hp) :=\n     c.2 * (c.1^w.val)\u207b\u00b9 \n    \ndef multiply_cipher (c\u2081 c\u2082 : zmodp p Hp \u00d7 zmodp p Hp) :=\n  (c\u2081.1 * c\u2082.1, c\u2081.2 * c\u2082.2)\n\n\n#check elgamal_enc p q Hp Hq g h \n#check elgamal_dec p q Hp Hq w \n#check multiply_cipher p Hp\n\nlemma prime5: nat.prime 5 := \nbegin \n unfold nat.prime,\n split, sorry, \n intros m Hm, sorry \nend \n/- It's pretty fase -/\n#eval (13^1990 : zmodp 5 prime5)\n\ninclude Hh\nlemma elgama_enc_dec_identity :  \n \u2200 m r, elgamal_dec p q Hp Hq w (elgamal_enc p q Hp Hq g h m r) \n        = g^m.val :=\nbegin\n intros m r, \n unfold elgamal_enc elgamal_dec,\n simp, rw Hh, sorry \nend \n         \nend Zeroknowledgeproof\n\nnamespace Interactivezkp\n\nvariables (p : \u2115) (Hp : nat.prime p)\n          (g : zmodp p Hp)\n\n\nuniverses u\ninductive communication : Type u\n| commitment (k : zmodp p Hp) : communication\n| challenge (k : zmodp p Hp) : communication\n| response (k s : zmodp p Hp) : communication\n\n/- zero knowledge proof of zkp {x | g^x = h} \n   r is prover's randomness, c is challenger's randomness \n   Can this be abstracted for some R : A \u2192 B \u2192 bool -/\nopen communication\ninductive zkp_transcript (x h : zmodp p Hp) (Hf : h = g^x.val)  \n    (r c : zmodp p Hp) :  communication p Hp \u2192 Type u\n| commitment_step (k : zmodp p Hp) : k = g^r.val \u2192 zkp_transcript (commitment k)\n| challenge_step (k : zmodp p Hp) : zkp_transcript (commitment k) \u2192 \n    zkp_transcript (challenge k)\n| response_step (k s : zmodp p Hp) : s = r + c * x \u2192\n          zkp_transcript (challenge k) \u2192 zkp_transcript (response k s)\n/- end of zero knowledge proof transcript -/\n\nopen zkp_transcript\n/- I don't care how the transcript is constructed. If it checks out according \n   to defined rule then I will accept it. -/\ndef accept_transcript  (k r c s x h : zmodp p Hp) (Hf : h = g^x.val)\n      (Hzkp : zkp_transcript p Hp g x h Hf r c (response k s)) :=\n      g^s.val =  k * h^c.val \n\n/- A transcript is not valid if it does not check out -/\ndef reject_transcript (k r c s x h : zmodp p Hp) (Hf : h = g^x.val)\n      (Hzkp : zkp_transcript p Hp g x h Hf r c (response k s)) :=\n      g^s.val \u2260  k * h^c.val \n\n /- for any given x h and proof Hf, randomness r c, I can always construct \n    a valid certificate. I will prove this formally that this \n    function always constructs a valid certificate which checks out  -/\n def construct_a_certificate (r c x h : zmodp p Hp) (Hf : h = g^x.val) :\n        zkp_transcript p Hp g x h Hf r c (response (g^r.val) (r + c * x)) := \n    response_step (g^r.val) (r + c * x) rfl (challenge_step (g^r.val) \n      (commitment_step _ _ (g^r.val) rfl))\n\n/- certificate checking is decidable-/\n\n /- Proof that the construct_a_certificate function always constructs \n    a valid certificate. Each valid certificate always checks out : Completeness -/\nlemma proof_of_correctness :\n    \u2200 (r c x h : zmodp p Hp) (Hf : h = g^x.val) \n    (cert = construct_a_certificate p Hp g r c x h Hf), \n    accept_transcript p Hp g _ _ _ _ _ _ _ cert := \n    begin \n      intros, \n      unfold accept_transcript, \n      /- some basic math would solve it, but I don't know \n         the tactics yet.-/\n         sorry \n    end \n\n /- If you give me two valid ceritificate then I can extract a witness x : Soundenss  -/\nlemma extract_witness : \n  \u2200 (r\u2081 c\u2081 r\u2082 c\u2082 x h : zmodp p Hp) (Hf : h = g^x.val)\n  (cert\u2081 = construct_a_certificate p Hp g r\u2081 c\u2081 x h Hf)\n  (cert\u2082 = construct_a_certificate p Hp g r\u2082 c\u2082 x h Hf), \n  accept_transcript p Hp g _ _ _ _ _ _ _ cert\u2081 \u2192\n  accept_transcript p Hp g _ _ _ _ _ _ _ cert\u2082 \u2192  true := \n  begin\n    intros, sorry\n  end \n\n /- Zero knowledge Proof -/\n\n\nend Interactivezkp\n\n\n\nnamespace Elgamal\n\n/- define a group on finite type -/\nuniverse u\nvariables (A : Type u) (Hf : fintype A)\n(gop : A -> A -> A) (e : A) (inv : A -> A)\n\nclass group  :=\n  (associativity : \u2200 x y z : A, gop x (gop y z) = \n                                gop (gop x y) z)\n  (left_identity : \u2200 x : A, gop e x = x)\n  (right_identity : \u2200 x : A, gop x e = x)\n  (left_inverse : \u2200 x : A, gop (inv x) x = e)\n  (right_inverse : \u2200 x : A, gop x (inv x) = e)\n \n\ndef group_pow (x : A) : \u2115 \u2192 A \n| 0 := e\n| (n + 1) := gop x (group_pow n)\n\nvariable (G : group A gop e inv)\ninclude G \n\nlemma group_exp_identity :\n \u2200 (n : \u2115), group_pow A gop e e n = e :=\n  begin\n  intro n, induction n,\n  /- simplification would do the job -/\n  /- simplify it and rewrite in Ih, follwed right_identity -/\n  {simp [group_pow]},\n  {dsimp [group_pow], \n   rewrite n_ih, apply (group.left_identity gop e inv e)}\n  end\n\nlemma group_exp_plus : \u2200 (n m : \u2115) (x : A), \n  group_pow A gop e x (n + m) = \n  gop (group_pow A gop e x n) (group_pow A gop e x m) := \n  begin \n  intros n, \n  induction n, \n  {intros m x, simp [group_pow],\n   rewrite\n   group.left_identity gop e inv (group_pow A gOp e x m)},\n  {intros m x,\n   simp [group_pow],\n   rewrite nat.add_succ,\n   simp [group_pow], rewrite n_ih,\n   rewrite <- (group.associativity gOp e inv x)}\n  end\n\n  lemma group_exp_mult : \u2200 (n m : \u2115) (x : A), \n  group_pow A gop e x (n * m) = \n  group_pow A gop e (group_pow A gop e x n) m := \n  begin \n   intros n, induction n,\n   sorry,\n   sorry\n  end\n\nclass abelian_group := \n  (commutative : \u2200 x y, gop x y = gop y x)\n\n  #check (abelian_group A gop e inv G)\n\nclass cyclic_group (g : A) (order : \u2115+) \n\nend Elgamal\n\n\n\n\n\n", "meta": {"author": "mukeshtiwari", "repo": "Leanplayground", "sha": "773deaf73fbb677cdf518d0db34ad62a79bad642", "save_path": "github-repos/lean/mukeshtiwari-Leanplayground", "path": "github-repos/lean/mukeshtiwari-Leanplayground/Leanplayground-773deaf73fbb677cdf518d0db34ad62a79bad642/Elgamal/src/Elgamal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.739952956843242}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n-/\nimport algebra.order.absolute_value\nimport algebra.field_power\nimport ring_theory.int.basic\nimport tactic.basic\nimport tactic.ring_exp\nimport number_theory.divisors\n\n/-!\n# p-adic norm\n\nThis file defines the p-adic valuation and the p-adic norm on \u211a.\n\nThe p-adic valuation on \u211a is the difference of the multiplicities of `p` in the numerator and\ndenominator of `q`. This function obeys the standard properties of a valuation, with the appropriate\nassumptions on p.\n\nThe valuation induces a norm on \u211a. This norm is a nonarchimedean absolute value.\nIt takes values in {0} \u222a {1/p^k | k \u2208 \u2124}.\n\n## Notations\n\nThis file uses the local notation `/.` for `rat.mk`.\n\n## Implementation notes\n\nMuch, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically\nby taking `[fact (prime p)]` as a type class argument.\n\n## References\n\n* [F. Q. Gou\u00eava, *p-adic numbers*][gouvea1997]\n* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]\n* <https://en.wikipedia.org/wiki/P-adic_number>\n\n## Tags\n\np-adic, p adic, padic, norm, valuation\n-/\n\nuniverse u\n\nopen nat\n\nopen_locale rat\n\nopen multiplicity\n\n/--\nFor `p \u2260 1`, the p-adic valuation of an integer `z \u2260 0` is the largest natural number `n` such that\np^n divides z.\n\n`padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the\nvaluation of `q.denom`.\nIf `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to 0.\n-/\ndef padic_val_rat (p : \u2115) (q : \u211a) : \u2124 :=\nif h : q \u2260 0 \u2227 p \u2260 1\nthen (multiplicity (p : \u2124) q.num).get\n    (multiplicity.finite_int_iff.2 \u27e8h.2, rat.num_ne_zero_of_ne_zero h.1\u27e9) -\n  (multiplicity (p : \u2124) q.denom).get\n    (multiplicity.finite_int_iff.2 \u27e8h.2, by exact_mod_cast rat.denom_ne_zero _\u27e9)\nelse 0\n\n/--\nA simplification of the definition of `padic_val_rat p q` when `q \u2260 0` and `p` is prime.\n-/\nlemma padic_val_rat_def (p : \u2115) [hp : fact p.prime] {q : \u211a} (hq : q \u2260 0) : padic_val_rat p q =\n  (multiplicity (p : \u2124) q.num).get (finite_int_iff.2 \u27e8hp.1.ne_one, rat.num_ne_zero_of_ne_zero hq\u27e9) -\n  (multiplicity (p : \u2124) q.denom).get\n    (finite_int_iff.2 \u27e8hp.1.ne_one, by exact_mod_cast rat.denom_ne_zero _\u27e9) :=\ndif_pos \u27e8hq, hp.1.ne_one\u27e9\n\nnamespace padic_val_rat\nopen multiplicity\nvariables {p : \u2115}\n\n/--\n`padic_val_rat p q` is symmetric in `q`.\n-/\n@[simp] protected lemma neg (q : \u211a) : padic_val_rat p (-q) = padic_val_rat p q :=\nbegin\n  unfold padic_val_rat,\n  split_ifs,\n  { simp [-add_comm]; refl },\n  { exfalso, simp * at * },\n  { exfalso, simp * at * },\n  { refl }\nend\n\n/--\n`padic_val_rat p 1` is 0 for any `p`.\n-/\n@[simp] protected lemma one : padic_val_rat p 1 = 0 :=\nby unfold padic_val_rat; split_ifs; simp *\n\n/--\nFor `p \u2260 0, p \u2260 1, `padic_val_rat p p` is 1.\n-/\n@[simp] lemma padic_val_rat_self (hp : 1 < p) : padic_val_rat p p = 1 :=\nby unfold padic_val_rat; split_ifs; simp [*, nat.one_lt_iff_ne_zero_and_ne_one] at *\n\n/--\nThe p-adic value of an integer `z \u2260 0` is the multiplicity of `p` in `z`.\n-/\nlemma padic_val_rat_of_int (z : \u2124) (hp : p \u2260 1) (hz : z \u2260 0) :\n  padic_val_rat p (z : \u211a) = (multiplicity (p : \u2124) z).get\n    (finite_int_iff.2 \u27e8hp, hz\u27e9) :=\nby rw [padic_val_rat, dif_pos]; simp *; refl\n\nend padic_val_rat\n\n/--\nA convenience function for the case of `padic_val_rat` when both inputs are natural numbers.\n-/\ndef padic_val_nat (p : \u2115) (n : \u2115) : \u2115 :=\nint.to_nat (padic_val_rat p n)\n\nsection padic_val_nat\n\n/--\n`padic_val_nat` is defined as an `int.to_nat` cast;\nthis lemma ensures that the cast is well-behaved.\n-/\nlemma zero_le_padic_val_rat_of_nat (p n : \u2115) : 0 \u2264 padic_val_rat p n :=\nbegin\n  unfold padic_val_rat,\n  split_ifs,\n  { simp, },\n  { trivial, },\nend\n\n/--\n`padic_val_rat` coincides with `padic_val_nat`.\n-/\n@[simp, norm_cast] lemma padic_val_rat_of_nat (p n : \u2115) :\n  \u2191(padic_val_nat p n) = padic_val_rat p n :=\nbegin\n  unfold padic_val_nat,\n  rw int.to_nat_of_nonneg (zero_le_padic_val_rat_of_nat p n),\nend\n\n/--\nA simplification of `padic_val_nat` when one input is prime, by analogy with `padic_val_rat_def`.\n-/\nlemma padic_val_nat_def {p : \u2115} [hp : fact p.prime] {n : \u2115} (hn : n \u2260 0) :\n  padic_val_nat p n =\n  (multiplicity p n).get\n    (multiplicity.finite_nat_iff.2 \u27e8nat.prime.ne_one hp.1, bot_lt_iff_ne_bot.mpr hn\u27e9) :=\nbegin\n  have n_nonzero : (n : \u211a) \u2260 0, by simpa only [cast_eq_zero, ne.def],\n  -- Infinite loop with @simp padic_val_rat_of_nat unless we restrict the available lemmas here,\n  -- hence the very long list\n  simpa only\n    [ int.coe_nat_multiplicity p n, rat.coe_nat_denom n, (padic_val_rat_of_nat p n).symm,\n      int.coe_nat_zero, int.coe_nat_inj', sub_zero, get_one_right, int.coe_nat_succ, zero_add,\n      rat.coe_nat_num ]\n    using padic_val_rat_def p n_nonzero,\nend\n\nlemma one_le_padic_val_nat_of_dvd\n  {n p : nat} [prime : fact p.prime] (nonzero : n \u2260 0) (div : p \u2223 n) :\n  1 \u2264 padic_val_nat p n :=\nbegin\n  rw @padic_val_nat_def _ prime _ nonzero,\n  let one_le_mul : _ \u2264 multiplicity p n :=\n    @multiplicity.le_multiplicity_of_pow_dvd _ _ _ p n 1 (begin norm_num, exact div end),\n  simp only [nat.cast_one] at one_le_mul,\n  rcases one_le_mul with \u27e8_, q\u27e9,\n  dsimp at q,\n  solve_by_elim,\nend\n\n@[simp]\nlemma padic_val_nat_zero (m : nat) : padic_val_nat m 0 = 0 := by simpa\n\n@[simp]\nlemma padic_val_nat_one (m : nat) : padic_val_nat m 1 = 0 := by simp [padic_val_nat]\n\nend padic_val_nat\n\nnamespace padic_val_rat\nopen multiplicity\nvariables (p : \u2115) [p_prime : fact p.prime]\ninclude p_prime\n\n/--\nThe multiplicity of `p : \u2115` in `a : \u2124` is finite exactly when `a \u2260 0`.\n-/\nlemma finite_int_prime_iff {p : \u2115} [p_prime : fact p.prime] {a : \u2124} : finite (p : \u2124) a \u2194 a \u2260 0 :=\nby simp [finite_int_iff, ne.symm (ne_of_lt (p_prime.1.one_lt))]\n\n/--\nA rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`.\n-/\nprotected lemma defn {q : \u211a} {n d : \u2124} (hqz : q \u2260 0) (qdf : q = n /. d) :\n  padic_val_rat p q = (multiplicity (p : \u2124) n).get (finite_int_iff.2\n    \u27e8ne.symm $ ne_of_lt p_prime.1.one_lt, \u03bb hn, by simp * at *\u27e9) -\n  (multiplicity (p : \u2124) d).get (finite_int_iff.2 \u27e8ne.symm $ ne_of_lt p_prime.1.one_lt,\n    \u03bb hd, by simp * at *\u27e9) :=\nhave hn : n \u2260 0, from rat.mk_num_ne_zero_of_ne_zero hqz qdf,\nhave hd : d \u2260 0, from rat.mk_denom_ne_zero_of_ne_zero hqz qdf,\nlet \u27e8c, hc1, hc2\u27e9 := rat.num_denom_mk hn hd qdf in\nby rw [padic_val_rat, dif_pos];\n  simp [hc1, hc2, multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1),\n    (ne.symm (ne_of_lt p_prime.1.one_lt)), hqz]\n\n/--\nA rewrite lemma for `padic_val_rat p (q * r)` with conditions `q \u2260 0`, `r \u2260 0`.\n-/\nprotected lemma mul {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_rat p (q * r) = padic_val_rat p q + padic_val_rat p r :=\nhave q*r = (q.num * r.num) /. (\u2191q.denom * \u2191r.denom), by rw_mod_cast rat.mul_num_denom,\nhave hq' : q.num /. q.denom \u2260 0, by rw rat.num_denom; exact hq,\nhave hr' : r.num /. r.denom \u2260 0, by rw rat.num_denom; exact hr,\nhave hp' : _root_.prime (p : \u2124), from nat.prime_iff_prime_int.1 p_prime.1,\nbegin\n  rw [padic_val_rat.defn p (mul_ne_zero hq hr) this],\n  conv_rhs { rw [\u2190(@rat.num_denom q), padic_val_rat.defn p hq',\n    \u2190(@rat.num_denom r), padic_val_rat.defn p hr'] },\n  rw [multiplicity.mul' hp', multiplicity.mul' hp']; simp [add_comm, add_left_comm, sub_eq_add_neg]\nend\n\n/--\nA rewrite lemma for `padic_val_rat p (q^k)` with condition `q \u2260 0`.\n-/\nprotected lemma pow {q : \u211a} (hq : q \u2260 0) {k : \u2115} :\n    padic_val_rat p (q ^ k) = k * padic_val_rat p q :=\nby induction k; simp [*, padic_val_rat.mul _ hq (pow_ne_zero _ hq),\n  pow_succ, add_mul, add_comm]\n\n/--\nA rewrite lemma for `padic_val_rat p (q\u207b\u00b9)` with condition `q \u2260 0`.\n-/\nprotected lemma inv {q : \u211a} (hq : q \u2260 0) :\n  padic_val_rat p (q\u207b\u00b9) = -padic_val_rat p q :=\nby rw [eq_neg_iff_add_eq_zero, \u2190 padic_val_rat.mul p (inv_ne_zero hq) hq,\n    inv_mul_cancel hq, padic_val_rat.one]\n\n/--\nA rewrite lemma for `padic_val_rat p (q / r)` with conditions `q \u2260 0`, `r \u2260 0`.\n-/\nprotected lemma div {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_rat p (q / r) = padic_val_rat p q - padic_val_rat p r :=\nby rw [div_eq_mul_inv, padic_val_rat.mul p hq (inv_ne_zero hr),\n    padic_val_rat.inv p hr, sub_eq_add_neg]\n\n/--\nA condition for `padic_val_rat p (n\u2081 / d\u2081) \u2264 padic_val_rat p (n\u2082 / d\u2082),\nin terms of divisibility by `p^n`.\n-/\nlemma padic_val_rat_le_padic_val_rat_iff {n\u2081 n\u2082 d\u2081 d\u2082 : \u2124}\n  (hn\u2081 : n\u2081 \u2260 0) (hn\u2082 : n\u2082 \u2260 0) (hd\u2081 : d\u2081 \u2260 0) (hd\u2082 : d\u2082 \u2260 0) :\n  padic_val_rat p (n\u2081 /. d\u2081) \u2264 padic_val_rat p (n\u2082 /. d\u2082) \u2194\n  \u2200 (n : \u2115), \u2191p ^ n \u2223 n\u2081 * d\u2082 \u2192 \u2191p ^ n \u2223 n\u2082 * d\u2081 :=\nhave hf1 : finite (p : \u2124) (n\u2081 * d\u2082),\n  from finite_int_prime_iff.2 (mul_ne_zero hn\u2081 hd\u2082),\nhave hf2 : finite (p : \u2124) (n\u2082 * d\u2081),\n  from finite_int_prime_iff.2 (mul_ne_zero hn\u2082 hd\u2081),\n  by conv\n  { to_lhs,\n    rw [padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn\u2081 hd\u2081) rfl,\n      padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn\u2082 hd\u2082) rfl,\n      sub_le_iff_le_add',\n      \u2190 add_sub_assoc,\n      le_sub_iff_add_le],\n    norm_cast,\n    rw [\u2190 multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf1, add_comm,\n      \u2190 multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf2,\n      enat.get_le_get, multiplicity_le_multiplicity_iff] }\n\n/--\nSufficient conditions to show that the p-adic valuation of `q` is less than or equal to the\np-adic vlauation of `q + r`.\n-/\ntheorem le_padic_val_rat_add_of_le {q r : \u211a}\n  (hq : q \u2260 0) (hr : r \u2260 0) (hqr : q + r \u2260 0)\n  (h : padic_val_rat p q \u2264 padic_val_rat p r) :\n  padic_val_rat p q \u2264 padic_val_rat p (q + r) :=\nhave hqn : q.num \u2260 0, from rat.num_ne_zero_of_ne_zero hq,\nhave hqd : (q.denom : \u2124) \u2260 0, by exact_mod_cast rat.denom_ne_zero _,\nhave hrn : r.num \u2260 0, from rat.num_ne_zero_of_ne_zero hr,\nhave hrd : (r.denom : \u2124) \u2260 0, by exact_mod_cast rat.denom_ne_zero _,\nhave hqreq : q + r = (((q.num * r.denom + q.denom * r.num : \u2124)) /. (\u2191q.denom * \u2191r.denom : \u2124)),\n  from rat.add_num_denom _ _,\nhave hqrd : q.num * \u2191(r.denom) + \u2191(q.denom) * r.num \u2260 0,\n  from rat.mk_num_ne_zero_of_ne_zero hqr hqreq,\nbegin\n  conv_lhs { rw \u2190(@rat.num_denom q) },\n  rw [hqreq, padic_val_rat_le_padic_val_rat_iff p hqn hqrd hqd (mul_ne_zero hqd hrd),\n    \u2190 multiplicity_le_multiplicity_iff, mul_left_comm,\n    multiplicity.mul (nat.prime_iff_prime_int.1 p_prime.1), add_mul],\n  rw [\u2190(@rat.num_denom q), \u2190(@rat.num_denom r),\n    padic_val_rat_le_padic_val_rat_iff p hqn hrn hqd hrd, \u2190 multiplicity_le_multiplicity_iff] at h,\n  calc _ \u2264 min (multiplicity \u2191p (q.num * \u2191(r.denom) * \u2191(q.denom)))\n    (multiplicity \u2191p (\u2191(q.denom) * r.num * \u2191(q.denom))) : (le_min\n    (by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (nat.prime_iff_prime_int.1 p_prime.1), add_comm])\n    (by rw [mul_assoc, @multiplicity.mul _ _ _ _ (q.denom : \u2124)\n        (_ * _) (nat.prime_iff_prime_int.1 p_prime.1)];\n      exact add_le_add_left h _))\n    ... \u2264 _ : min_le_multiplicity_add\nend\n\n/--\nThe minimum of the valuations of `q` and `r` is less than or equal to the valuation of `q + r`.\n-/\ntheorem min_le_padic_val_rat_add {q r : \u211a}\n  (hq : q \u2260 0) (hr : r \u2260 0) (hqr : q + r \u2260 0) :\n  min (padic_val_rat p q) (padic_val_rat p r) \u2264 padic_val_rat p (q + r) :=\n(le_total (padic_val_rat p q) (padic_val_rat p r)).elim\n  (\u03bb h, by rw [min_eq_left h]; exact le_padic_val_rat_add_of_le _ hq hr hqr h)\n  (\u03bb h, by rw [min_eq_right h, add_comm]; exact le_padic_val_rat_add_of_le _ hr hq\n    (by rwa add_comm) h)\n\nopen_locale big_operators\n\n/-- A finite sum of rationals with positive p-adic valuation has positive p-adic valuation\n  (if the sum is non-zero). -/\ntheorem sum_pos_of_pos {n : \u2115} {F : \u2115 \u2192 \u211a}\n  (hF : \u2200 i, i < n \u2192 0 < padic_val_rat p (F i)) (hn0 : \u2211 i in finset.range n, F i \u2260 0) :\n  0 < padic_val_rat p (\u2211 i in finset.range n, F i) :=\nbegin\n  induction n with d hd,\n  { exact false.elim (hn0 rfl) },\n  { rw finset.sum_range_succ at hn0 \u22a2,\n    by_cases h : \u2211 (x : \u2115) in finset.range d, F x = 0,\n    { rw [h, zero_add],\n      exact hF d (lt_add_one _) },\n    { refine lt_of_lt_of_le _ (min_le_padic_val_rat_add p h (\u03bb h1, _) hn0),\n      { refine lt_min (hd (\u03bb i hi, _) h) (hF d (lt_add_one _)),\n        exact hF _ (lt_trans hi (lt_add_one _)) },\n      { have h2 := hF d (lt_add_one _),\n        rw h1 at h2,\n        exact lt_irrefl _ h2 } } }\nend\n\nend padic_val_rat\n\nnamespace padic_val_nat\n\n/--\nA rewrite lemma for `padic_val_nat p (q * r)` with conditions `q \u2260 0`, `r \u2260 0`.\n-/\nprotected lemma mul (p : \u2115) [p_prime : fact p.prime] {q r : \u2115} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_nat p (q * r) = padic_val_nat p q + padic_val_nat p r :=\nbegin\n  apply int.coe_nat_inj,\n  simp only [padic_val_rat_of_nat, nat.cast_mul],\n  rw padic_val_rat.mul,\n  norm_cast,\n  exact cast_ne_zero.mpr hq,\n  exact cast_ne_zero.mpr hr,\nend\n\n/--\nDividing out by a prime factor reduces the padic_val_nat by 1.\n-/\nprotected lemma div {p : \u2115} [p_prime : fact p.prime] {b : \u2115} (dvd : p \u2223 b) :\n  (padic_val_nat p (b / p)) = (padic_val_nat p b) - 1 :=\nbegin\n  by_cases b_split : (b = 0),\n  { simp [b_split], },\n  { have split_frac : padic_val_rat p (b / p) = padic_val_rat p b - padic_val_rat p p :=\n      padic_val_rat.div p (nat.cast_ne_zero.mpr b_split)\n        (nat.cast_ne_zero.mpr (nat.prime.ne_zero p_prime.1)),\n    rw padic_val_rat.padic_val_rat_self (nat.prime.one_lt p_prime.1) at split_frac,\n    have r : 1 \u2264 padic_val_nat p b := one_le_padic_val_nat_of_dvd b_split dvd,\n    exact_mod_cast split_frac, }\nend\n\n/-- A version of `padic_val_rat.pow` for `padic_val_nat` -/\nprotected lemma pow (p q n : \u2115) [fact p.prime] (hq : q \u2260 0) :\n  padic_val_nat p (q ^ n) = n * padic_val_nat p q :=\nbegin\n  apply @nat.cast_injective \u2124,\n  push_cast,\n  exact padic_val_rat.pow _ (cast_ne_zero.mpr hq),\nend\n\nend padic_val_nat\n\nsection padic_val_nat\n\n/--\nIf a prime doesn't appear in `n`, `padic_val_nat p n` is `0`.\n-/\nlemma padic_val_nat_of_not_dvd {p : \u2115} [fact p.prime] {n : \u2115} (not_dvd : \u00ac(p \u2223 n)) :\n  padic_val_nat p n = 0 :=\nbegin\n  by_cases hn : n = 0,\n  { subst hn, simp at not_dvd, trivial, },\n  { rw padic_val_nat_def hn,\n    exact (@multiplicity.unique' _ _ _ p n 0 (by simp) (by simpa using not_dvd)).symm,\n    assumption, },\nend\n\nlemma dvd_of_one_le_padic_val_nat {n p : nat} [prime : fact p.prime] (hp : 1 \u2264 padic_val_nat p n) :\n  p \u2223 n :=\nbegin\n  by_contra h,\n  rw padic_val_nat_of_not_dvd h at hp,\n  exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp),\nend\n\nlemma pow_padic_val_nat_dvd {p n : \u2115} [fact (nat.prime p)] : p ^ (padic_val_nat p n) \u2223 n :=\nbegin\n  cases nat.eq_zero_or_pos n with hn hn,\n  { rw hn, exact dvd_zero (p ^ padic_val_nat p 0) },\n  { rw multiplicity.pow_dvd_iff_le_multiplicity,\n    apply le_of_eq,\n    rw padic_val_nat_def (ne_of_gt hn),\n    { apply enat.coe_get },\n    { apply_instance } }\nend\n\nlemma pow_succ_padic_val_nat_not_dvd {p n : \u2115} [hp : fact (nat.prime p)] (hn : 0 < n) :\n  \u00ac p ^ (padic_val_nat p n + 1) \u2223 n :=\nbegin\n  { rw multiplicity.pow_dvd_iff_le_multiplicity,\n    rw padic_val_nat_def (ne_of_gt hn),\n    { rw [nat.cast_add, enat.coe_get],\n      simp only [nat.cast_one, not_le],\n      apply enat.lt_add_one (ne_top_iff_finite.2 (finite_nat_iff.2 \u27e8hp.elim.ne_one, hn\u27e9)) },\n    { apply_instance } }\nend\n\nlemma padic_val_nat_primes {p q : \u2115} [p_prime : fact p.prime] [q_prime : fact q.prime]\n  (neq : p \u2260 q) : padic_val_nat p q = 0 :=\n@padic_val_nat_of_not_dvd p p_prime q $\n(not_congr (iff.symm (prime_dvd_prime_iff_eq p_prime.1 q_prime.1))).mp neq\n\nprotected lemma padic_val_nat.div' {p : \u2115} [p_prime : fact p.prime] :\n  \u2200 {m : \u2115} (cpm : coprime p m) {b : \u2115} (dvd : m \u2223 b), padic_val_nat p (b / m) = padic_val_nat p b\n| 0 := \u03bb cpm b dvd, by { rw zero_dvd_iff at dvd, rw [dvd, nat.zero_div], }\n| (n + 1) :=\n  \u03bb cpm b dvd,\n  begin\n    rcases dvd with \u27e8c, rfl\u27e9,\n    rw [mul_div_right c (nat.succ_pos _)],by_cases hc : c = 0,\n    { rw [hc, mul_zero] },\n    { rw padic_val_nat.mul,\n      { suffices : \u00ac p \u2223 (n+1),\n        { rw [padic_val_nat_of_not_dvd this, zero_add] },\n        contrapose! cpm,\n        exact p_prime.1.dvd_iff_not_coprime.mp cpm },\n      { exact nat.succ_ne_zero _ },\n      { exact hc } },\n  end\n\nlemma padic_val_nat_eq_factors_count (p : \u2115) [hp : fact p.prime] :\n  \u2200 (n : \u2115), padic_val_nat p n = (factors n).count p\n| 0 := by simp\n| 1 := by simp\n| (m + 2) :=\nlet n := m + 2 in\nlet q := min_fac n in\nhave hq : fact q.prime := \u27e8min_fac_prime (show m + 2 \u2260 1, by linarith)\u27e9,\nhave wf : n / q < n := nat.div_lt_self (nat.succ_pos _) hq.1.one_lt,\nbegin\n  rw factors_add_two,\n  show padic_val_nat p n = list.count p (q :: (factors (n / q))),\n  rw [list.count_cons', \u2190 padic_val_nat_eq_factors_count],\n  split_ifs with h,\n  have p_dvd_n : p \u2223 n,\n  { have: q \u2223 n := nat.min_fac_dvd n,\n    cc },\n  { rw [\u2190h, padic_val_nat.div],\n    { have: 1 \u2264 padic_val_nat p n := one_le_padic_val_nat_of_dvd (by linarith) p_dvd_n,\n      exact (tsub_eq_iff_eq_add_of_le this).mp rfl, },\n    { exact p_dvd_n, }, },\n  { suffices : p.coprime q,\n    { rw [padic_val_nat.div' this (min_fac_dvd n), add_zero], },\n    rwa nat.coprime_primes hp.1 hq.1, },\nend\n\n@[simp] lemma padic_val_nat_self (p : \u2115) [fact p.prime] : padic_val_nat p p = 1 :=\nby simp [padic_val_nat_def (fact.out p.prime).ne_zero]\n\n@[simp] lemma padic_val_nat_prime_pow (p n : \u2115) [fact p.prime] : padic_val_nat p (p ^ n) = n :=\nby rw [padic_val_nat.pow p _ _ (fact.out p.prime).ne_zero, padic_val_nat_self p, mul_one]\n\nopen_locale big_operators\n\nlemma prod_pow_prime_padic_val_nat (n : nat) (hn : n \u2260 0) (m : nat) (pr : n < m) :\n  \u220f p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n :=\nbegin\n  rw \u2190 pos_iff_ne_zero at hn,\n  have H : (factors n : multiset \u2115).prod = n,\n  { rw [multiset.coe_prod, prod_factors hn], },\n  rw finset.prod_multiset_count at H,\n  conv_rhs { rw \u2190 H, },\n  refine finset.prod_bij_ne_one (\u03bb p hp hp', p) _ _ _ _,\n  { rintro p hp hpn,\n    rw [finset.mem_filter, finset.mem_range] at hp,\n    rw [multiset.mem_to_finset, multiset.mem_coe, mem_factors_iff_dvd hn hp.2],\n    contrapose! hpn,\n    haveI Hp : fact p.prime := \u27e8hp.2\u27e9,\n    rw [padic_val_nat_of_not_dvd hpn, pow_zero], },\n  { intros, assumption },\n  { intros p hp hpn,\n    rw [multiset.mem_to_finset, multiset.mem_coe] at hp,\n    haveI Hp : fact p.prime := \u27e8prime_of_mem_factors hp\u27e9,\n    simp only [exists_prop, ne.def, finset.mem_filter, finset.mem_range],\n    refine \u27e8p, \u27e8_, Hp.1\u27e9, \u27e8_, rfl\u27e9\u27e9,\n    { rw mem_factors_iff_dvd hn Hp.1 at hp, exact lt_of_le_of_lt (le_of_dvd hn hp) pr },\n    { rw padic_val_nat_eq_factors_count,\n      simpa [ne.def, multiset.coe_count] using hpn } },\n  { intros p hp hpn,\n    rw [finset.mem_filter, finset.mem_range] at hp,\n    haveI Hp : fact p.prime := \u27e8hp.2\u27e9,\n    rw [padic_val_nat_eq_factors_count, multiset.coe_count] }\nend\n\nlemma range_pow_padic_val_nat_subset_divisors {n : \u2115} (p : \u2115) [fact p.prime] (hn : n \u2260 0) :\n  (finset.range (padic_val_nat p n + 1)).image (pow p) \u2286 n.divisors :=\nbegin\n  intros t ht,\n  simp only [exists_prop, finset.mem_image, finset.mem_range] at ht,\n  obtain \u27e8k, hk, rfl\u27e9 := ht,\n  rw nat.mem_divisors,\n  exact \u27e8(pow_dvd_pow p $ by linarith).trans pow_padic_val_nat_dvd, hn\u27e9\nend\n\nlemma range_pow_padic_val_nat_subset_divisors' {n : \u2115} (p : \u2115) [h : fact p.prime] :\n  (finset.range (padic_val_nat p n)).image (\u03bb t, p ^ (t + 1)) \u2286 (n.divisors \\ {1}) :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  intros t ht,\n  simp only [exists_prop, finset.mem_image, finset.mem_range] at ht,\n  obtain \u27e8k, hk, rfl\u27e9 := ht,\n  rw [finset.mem_sdiff, nat.mem_divisors],\n  refine \u27e8\u27e8(pow_dvd_pow p $ by linarith).trans pow_padic_val_nat_dvd, hn\u27e9, _\u27e9,\n  rw [finset.mem_singleton],\n  nth_rewrite 1 \u2190one_pow (k + 1),\n  exact (nat.pow_lt_pow_of_lt_left h.1.one_lt $ nat.succ_pos k).ne',\nend\n\nend padic_val_nat\n\n/--\nIf `q \u2260 0`, the p-adic norm of a rational `q` is `p ^ (-(padic_val_rat p q))`.\nIf `q = 0`, the p-adic norm of `q` is 0.\n-/\ndef padic_norm (p : \u2115) (q : \u211a) : \u211a :=\nif q = 0 then 0 else (\u2191p : \u211a) ^ (-(padic_val_rat p q))\n\nnamespace padic_norm\n\nsection padic_norm\nopen padic_val_rat\nvariables (p : \u2115)\n\n/--\nUnfolds the definition of the p-adic norm of `q` when `q \u2260 0`.\n-/\n@[simp] protected lemma eq_zpow_of_nonzero {q : \u211a} (hq : q \u2260 0) :\n  padic_norm p q = p ^ (-(padic_val_rat p q)) :=\nby simp [hq, padic_norm]\n\n/--\nThe p-adic norm is nonnegative.\n-/\nprotected lemma nonneg (q : \u211a) : 0 \u2264 padic_norm p q :=\nif hq : q = 0 then by simp [hq, padic_norm]\nelse\n  begin\n    unfold padic_norm; split_ifs,\n    apply zpow_nonneg,\n    exact_mod_cast nat.zero_le _\n  end\n\n/--\nThe p-adic norm of 0 is 0.\n-/\n@[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm]\n\n/--\nThe p-adic norm of 1 is 1.\n-/\n@[simp] protected lemma one : padic_norm p 1 = 1 := by simp [padic_norm]\n\n/--\nThe p-adic norm of `p` is `1/p` if `p > 1`.\n\nSee also `padic_norm.padic_norm_p_of_prime` for a version that assumes `p` is prime.\n-/\nlemma padic_norm_p {p : \u2115} (hp : 1 < p) : padic_norm p p = 1 / p :=\nby simp [padic_norm, (show p \u2260 0, by linarith), padic_val_rat.padic_val_rat_self hp]\n\n/--\nThe p-adic norm of `p` is `1/p` if `p` is prime.\n\nSee also `padic_norm.padic_norm_p` for a version that assumes `1 < p`.\n-/\n@[simp] lemma padic_norm_p_of_prime (p : \u2115) [fact p.prime] : padic_norm p p = 1 / p :=\npadic_norm_p $ nat.prime.one_lt (fact.out _)\n\n/-- The p-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/\nlemma padic_norm_of_prime_of_ne {p q : \u2115} [p_prime : fact p.prime] [q_prime : fact q.prime]\n  (neq : p \u2260 q) : padic_norm p q = 1 :=\nbegin\n  have p : padic_val_rat p q = 0,\n  { exact_mod_cast @padic_val_nat_primes p q p_prime q_prime neq },\n  simp [padic_norm, p, q_prime.1.1, q_prime.1.ne_zero],\nend\n\n/--\nThe p-adic norm of `p` is less than 1 if `1 < p`.\n\nSee also `padic_norm.padic_norm_p_lt_one_of_prime` for a version assuming `prime p`.\n-/\nlemma padic_norm_p_lt_one {p : \u2115} (hp : 1 < p) : padic_norm p p < 1 :=\nbegin\n  rw [padic_norm_p hp, div_lt_iff, one_mul],\n  { exact_mod_cast hp },\n  { exact_mod_cast zero_lt_one.trans hp },\nend\n\n/--\nThe p-adic norm of `p` is less than 1 if `p` is prime.\n\nSee also `padic_norm.padic_norm_p_lt_one` for a version assuming `1 < p`.\n-/\nlemma padic_norm_p_lt_one_of_prime (p : \u2115) [fact p.prime] : padic_norm p p < 1 :=\npadic_norm_p_lt_one $ nat.prime.one_lt (fact.out _)\n\n/--\n`padic_norm p q` takes discrete values `p ^ -z` for `z : \u2124`.\n-/\nprotected theorem values_discrete {q : \u211a} (hq : q \u2260 0) : \u2203 z : \u2124, padic_norm p q = p ^ (-z) :=\n\u27e8 (padic_val_rat p q), by simp [padic_norm, hq] \u27e9\n\n/--\n`padic_norm p` is symmetric.\n-/\n@[simp] protected lemma neg (q : \u211a) : padic_norm p (-q) = padic_norm p q :=\nif hq : q = 0 then by simp [hq]\nelse by simp [padic_norm, hq]\n\nvariable [hp : fact p.prime]\ninclude hp\n\n/--\nIf `q \u2260 0`, then `padic_norm p q \u2260 0`.\n-/\nprotected lemma nonzero {q : \u211a} (hq : q \u2260 0) : padic_norm p q \u2260 0 :=\nbegin\n  rw padic_norm.eq_zpow_of_nonzero p hq,\n  apply zpow_ne_zero_of_ne_zero,\n  exact_mod_cast ne_of_gt hp.1.pos\nend\n\n/--\nIf the p-adic norm of `q` is 0, then `q` is 0.\n-/\nlemma zero_of_padic_norm_eq_zero {q : \u211a} (h : padic_norm p q = 0) : q = 0 :=\nbegin\n  apply by_contradiction, intro hq,\n  unfold padic_norm at h, rw if_neg hq at h,\n  apply absurd h,\n  apply zpow_ne_zero_of_ne_zero,\n  exact_mod_cast hp.1.ne_zero\nend\n\n/--\nThe p-adic norm is multiplicative.\n-/\n@[simp] protected theorem mul (q r : \u211a) : padic_norm p (q*r) = padic_norm p q * padic_norm p r :=\nif hq : q = 0 then\n  by simp [hq]\nelse if hr : r = 0 then\n  by simp [hr]\nelse\n  have q*r \u2260 0, from mul_ne_zero hq hr,\n  have (\u2191p : \u211a) \u2260 0, by simp [hp.1.ne_zero],\n  by simp [padic_norm, *, padic_val_rat.mul, zpow_add\u2080 this, mul_comm]\n\n/--\nThe p-adic norm respects division.\n-/\n@[simp] protected theorem div (q r : \u211a) : padic_norm p (q / r) = padic_norm p q / padic_norm p r :=\nif hr : r = 0 then by simp [hr] else\neq_div_of_mul_eq (padic_norm.nonzero _ hr) (by rw [\u2190padic_norm.mul, div_mul_cancel _ hr])\n\n/--\nThe p-adic norm of an integer is at most 1.\n-/\nprotected theorem of_int (z : \u2124) : padic_norm p \u2191z \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one] else\nbegin\n  unfold padic_norm,\n  rw [if_neg _],\n  { refine zpow_le_one_of_nonpos _ _,\n    { exact_mod_cast le_of_lt hp.1.one_lt, },\n    { rw [padic_val_rat_of_int _ hp.1.ne_one hz, neg_nonpos],\n      norm_cast, simp }},\n  exact_mod_cast hz\nend\n\nprivate lemma nonarchimedean_aux {q r : \u211a} (h : padic_val_rat p q \u2264 padic_val_rat p r) :\n  padic_norm p (q + r) \u2264 max (padic_norm p q) (padic_norm p r) :=\nhave hnqp : padic_norm p q \u2265 0, from padic_norm.nonneg _ _,\nhave hnrp : padic_norm p r \u2265 0, from padic_norm.nonneg _ _,\nif hq : q = 0 then\n  by simp [hq, max_eq_right hnrp, le_max_right]\nelse if hr : r = 0 then\n  by simp [hr, max_eq_left hnqp, le_max_left]\nelse if hqr : q + r = 0 then\n  le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)\nelse\n  begin\n    unfold padic_norm, split_ifs,\n    apply le_max_iff.2,\n    left,\n    apply zpow_le_of_le,\n    { exact_mod_cast le_of_lt hp.1.one_lt },\n    { apply neg_le_neg,\n      have : padic_val_rat p q =\n              min (padic_val_rat p q) (padic_val_rat p r),\n        from (min_eq_left h).symm,\n      rw this,\n      apply min_le_padic_val_rat_add; assumption }\n  end\n\n/--\nThe p-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p` and\nthe norm of `q`.\n-/\nprotected theorem nonarchimedean {q r : \u211a} :\n  padic_norm p (q + r) \u2264 max (padic_norm p q) (padic_norm p r) :=\nbegin\n    wlog hle := le_total (padic_val_rat p q) (padic_val_rat p r) using [q r],\n    exact nonarchimedean_aux p hle\nend\n\n/--\nThe p-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of `p`\nplus the norm of `q`.\n-/\ntheorem triangle_ineq (q r : \u211a) : padic_norm p (q + r) \u2264 padic_norm p q + padic_norm p r :=\ncalc padic_norm p (q + r) \u2264 max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean p\n                       ... \u2264 padic_norm p q + padic_norm p r :\n                         max_le_add_of_nonneg (padic_norm.nonneg p _) (padic_norm.nonneg p _)\n\n/--\nThe p-adic norm of a difference is at most the max of each component. Restates the archimedean\nproperty of the p-adic norm.\n-/\nprotected theorem sub {q r : \u211a} : padic_norm p (q - r) \u2264 max (padic_norm p q) (padic_norm p r) :=\nby rw [sub_eq_add_neg, \u2190padic_norm.neg p r]; apply padic_norm.nonarchimedean\n\n/--\nIf the p-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max of\nthe norms of `q` and `r`.\n-/\nlemma add_eq_max_of_ne {q r : \u211a} (hne : padic_norm p q \u2260 padic_norm p r) :\n  padic_norm p (q + r) = max (padic_norm p q) (padic_norm p r) :=\nbegin\n  wlog hle := le_total (padic_norm p r) (padic_norm p q) using [q r],\n  have hlt : padic_norm p r < padic_norm p q, from lt_of_le_of_ne hle hne.symm,\n  have : padic_norm p q \u2264 max (padic_norm p (q + r)) (padic_norm p r), from calc\n   padic_norm p q = padic_norm p (q + r - r) : by congr; ring\n               ... \u2264 max (padic_norm p (q + r)) (padic_norm p (-r)) : padic_norm.nonarchimedean p\n               ... = max (padic_norm p (q + r)) (padic_norm p r) : by simp,\n  have hnge : padic_norm p r \u2264 padic_norm p (q + r),\n  { apply le_of_not_gt,\n    intro hgt,\n    rw max_eq_right_of_lt hgt at this,\n    apply not_lt_of_ge this,\n    assumption },\n  have : padic_norm p q \u2264 padic_norm p (q + r), by rwa [max_eq_left hnge] at this,\n  apply _root_.le_antisymm,\n  { apply padic_norm.nonarchimedean p },\n  { rw max_eq_left_of_lt hlt,\n    assumption }\nend\n\n/--\nThe p-adic norm is an absolute value: positive-definite and multiplicative, satisfying the triangle\ninequality.\n-/\ninstance : is_absolute_value (padic_norm p) :=\n{ abv_nonneg := padic_norm.nonneg p,\n  abv_eq_zero :=\n    begin\n      intros,\n      constructor; intro,\n      { apply zero_of_padic_norm_eq_zero p, assumption },\n      { simp [*] }\n    end,\n  abv_add := padic_norm.triangle_ineq p,\n  abv_mul := padic_norm.mul p }\n\nvariable {p}\n\nlemma dvd_iff_norm_le {n : \u2115} {z : \u2124} : \u2191(p^n) \u2223 z \u2194 padic_norm p z \u2264 \u2191p ^ (-n : \u2124) :=\nbegin\n  unfold padic_norm, split_ifs with hz,\n  { norm_cast at hz,\n    have : 0 \u2264 (p^n : \u211a), {apply pow_nonneg, exact_mod_cast le_of_lt hp.1.pos },\n    simp [hz, this] },\n  { rw [zpow_le_iff_le, neg_le_neg_iff, padic_val_rat_of_int _ hp.1.ne_one _],\n    { norm_cast,\n      rw [\u2190 enat.coe_le_coe, enat.coe_get, \u2190 multiplicity.pow_dvd_iff_le_multiplicity],\n      simp },\n    { exact_mod_cast hz },\n    { exact_mod_cast hp.1.one_lt } }\nend\n\nend padic_norm\nend padic_norm\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/padics/padic_norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7397330147971599}}
{"text": "/-\nA proof of the second isomorphism theorem for groups.\nAuthor: Adri\u00e1n Do\u00f1a Mateo\n\nThese were contributed to mathlib in\n[#6187](https://github.com/leanprover-community/mathlib/pull/6187/).\n\nAn apostrophe was added at the end of the names to avoid clashes.\n-/\n\nimport group_theory.quotient_group\n\n-- These lemmas were added to src/group_theory/subgroup.lean.\nnamespace subgroup\n\nvariables {G : Type*} [group G]\n\n/-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/\n@[to_additive \"The inclusion homomorphism from a additive subgroup `H` contained in `K` to `K`.\"]\ndef inclusion' {H K : subgroup G} (h : H \u2264 K) : H \u2192* K :=\nmonoid_hom.mk' (\u03bb x, \u27e8x, h x.prop\u27e9) (\u03bb \u27e8a, ha\u27e9  \u27e8b, hb\u27e9, rfl)\n\n@[simp, to_additive]\nlemma coe_inclusion' {H K : subgroup G} {h : H \u2264 K} (a : H) : (inclusion h a : G) = a :=\nby { cases a, simp only [inclusion, coe_mk, monoid_hom.coe_mk'] }\n\n@[simp, to_additive]\nlemma subtype_comp_inclusion' {H K : subgroup G} (hH : H \u2264 K) :\n  K.subtype.comp (inclusion hH) = H.subtype :=\nby { ext, simp }\n\n@[simp, to_additive]\nlemma comap_subtype_inf_left' {H K : subgroup G} : comap H.subtype (H \u2293 K) = comap H.subtype K :=\next $ \u03bb x, and_iff_right_of_imp (\u03bb _, x.prop)\n\n@[simp, to_additive]\nlemma comap_subtype_inf_right' {H K : subgroup G} : comap K.subtype (H \u2293 K) = comap K.subtype H :=\next $ \u03bb x, and_iff_left_of_imp (\u03bb _, x.prop)\n\n@[priority 100, to_additive]\ninstance subgroup.normal_inf' (H N : subgroup G) [hN : N.normal] :\n  ((H \u2293 N).comap H.subtype).normal :=\n\u27e8\u03bb x hx g, begin\n  simp only [subgroup.mem_inf, coe_subtype, subgroup.mem_comap] at hx,\n  simp only [subgroup.coe_mul, subgroup.mem_inf, coe_subtype, subgroup.coe_inv, subgroup.mem_comap],\n  exact \u27e8H.mul_mem (H.mul_mem g.2 hx.1) (H.inv_mem g.2), hN.1 x hx.2 g\u27e9,\nend\u27e9\n\nend subgroup\n\n-- These lemmas were added to src/group_theory/quotient_group.lean.\nnamespace quotient_group\nopen monoid_hom\n\nvariables {G : Type*} [group G]\n\n\n/-- If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are\nisomorphic. -/\n@[to_additive \"If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are\nisomorphic.\"]\ndef equiv_quotient_of_eq' {M N : subgroup G} [M.normal] [N.normal] (h : M = N) :\n  quotient M \u2243* quotient N :=\n{ to_fun := (lift M (mk' N) (\u03bb m hm, quotient_group.eq.mpr (by simpa [\u2190 h] using M.inv_mem hm))),\n  inv_fun := (lift N (mk' M) (\u03bb n hn, quotient_group.eq.mpr (by simpa [\u2190 h] using N.inv_mem hn))),\n  left_inv := \u03bb x, x.induction_on' $ by { intro, refl },\n  right_inv := \u03bb x, x.induction_on' $ by { intro, refl },\n  map_mul' := \u03bb x y, by rw map_mul }\n\n  section snd_isomorphism_thm\n\nopen subgroup\n\n/-- The second isomorphism theorem: given two subgroups `H` and `N` of a group `G`, where `N`\nis normal, defines an isomorphism between `H/(H \u2229 N)` and `(HN)/N`. -/\n@[to_additive \"The second isomorphism theorem: given two subgroups `H` and `N` of a group `G`,\nwhere `N` is normal, defines an isomorphism between `H/(H \u2229 N)` and `(H + N)/N`\"]\nnoncomputable def quotient_inf_equiv_prod_normal_quotient' (H N : subgroup G) [N.normal] :\n  quotient ((H \u2293 N).comap H.subtype) \u2243* quotient (N.comap (H \u2294 N).subtype) :=\n/- \u03c6 is the natural homomorphism H \u2192* (HN)/N. -/\nlet \u03c6 : H \u2192* quotient (N.comap (H \u2294 N).subtype) :=\n  (mk' $ N.comap (H \u2294 N).subtype).comp (inclusion le_sup_left) in\nhave \u03c6_surjective : function.surjective \u03c6 := \u03bb x, x.induction_on' $\n  begin\n    rintro \u27e8y, (hy : y \u2208 \u2191(H \u2294 N))\u27e9, rw mul_normal H N at hy,\n    rcases hy with \u27e8h, n, hh, hn, rfl\u27e9,\n    use [h, hh], apply quotient.eq.mpr, change h\u207b\u00b9 * (h * n) \u2208 N,\n    rwa [\u2190mul_assoc, inv_mul_self, one_mul],\n  end,\n(equiv_quotient_of_eq (by simp [comap_comap, \u2190comap_ker])).trans\n  (quotient_ker_equiv_of_surjective \u03c6 \u03c6_surjective)\n\nend snd_isomorphism_thm\n\nend quotient_group\n", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/to_mathlib/sndiso.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7397330082481319}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro, Anne Baanen\n-/\nimport linear_algebra.quotient\nimport ring_theory.ideal.basic\n/-!\n# Ideal quotients\n\nThis file defines ideal quotients as a special case of submodule quotients and proves some basic\nresults about these quotients.\n\nSee `algebra.ring_quot` for quotients of non-commutative rings.\n\n## Main definitions\n\n - `ideal.quotient`: the quotient of a commutative ring `R` by an ideal `I : ideal R`\n\n## Main results\n\n - `ideal.quotient_inf_ring_equiv_pi_quotient`: the **Chinese Remainder Theorem**\n-/\n\nuniverses u v w\n\nnamespace ideal\n\nopen set\nopen_locale big_operators\n\nvariables {R : Type u} [comm_ring R] (I : ideal R) {a b : R}\nvariables {S : Type v}\n\n/-- The quotient `R/I` of a ring `R` by an ideal `I`.\n\nThe ideal quotient of `I` is defined to equal the quotient of `I` as an `R`-submodule of `R`.\nThis definition is marked `reducible` so that typeclass instances can be shared between\n`ideal.quotient I` and `submodule.quotient I`.\n-/\n-- Note that at present `ideal` means a left-ideal,\n-- so this quotient is only useful in a commutative ring.\n-- We should develop quotients by two-sided ideals as well.\n@[reducible]\ninstance : has_quotient R (ideal R) := submodule.has_quotient\n\nnamespace quotient\nvariables {I} {x y : R}\n\ninstance has_one (I : ideal R) : has_one (R \u29f8 I) := \u27e8submodule.quotient.mk 1\u27e9\n\ninstance has_mul (I : ideal R) : has_mul (R \u29f8 I) :=\n\u27e8\u03bb a b, quotient.lift_on\u2082' a b (\u03bb a b, submodule.quotient.mk (a * b)) $\n \u03bb a\u2081 a\u2082 b\u2081 b\u2082 h\u2081 h\u2082, quot.sound $ begin\n  have F := I.add_mem (I.mul_mem_left a\u2082 h\u2081) (I.mul_mem_right b\u2081 h\u2082),\n  have : a\u2081 * a\u2082 - b\u2081 * b\u2082 = a\u2082 * (a\u2081 - b\u2081) + (a\u2082 - b\u2082) * b\u2081,\n  { rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b\u2081] },\n  rw \u2190 this at F,\n  change _ \u2208 _, convert F,\nend\u27e9\n\ninstance comm_ring (I : ideal R) : comm_ring (R \u29f8 I) :=\n{ mul := (*),\n  one := 1,\n  mul_assoc := \u03bb a b c, quotient.induction_on\u2083' a b c $\n    \u03bb a b c, congr_arg submodule.quotient.mk (mul_assoc a b c),\n  mul_comm := \u03bb a b, quotient.induction_on\u2082' a b $\n    \u03bb a b, congr_arg submodule.quotient.mk (mul_comm a b),\n  one_mul := \u03bb a, quotient.induction_on' a $\n    \u03bb a, congr_arg submodule.quotient.mk (one_mul a),\n  mul_one := \u03bb a, quotient.induction_on' a $\n    \u03bb a, congr_arg submodule.quotient.mk (mul_one a),\n  left_distrib := \u03bb a b c, quotient.induction_on\u2083' a b c $\n    \u03bb a b c, congr_arg submodule.quotient.mk (left_distrib a b c),\n  right_distrib := \u03bb a b c, quotient.induction_on\u2083' a b c $\n    \u03bb a b c, congr_arg submodule.quotient.mk (right_distrib a b c),\n  ..submodule.quotient.add_comm_group I }\n\n/-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/\ndef mk (I : ideal R) : R \u2192+* (R \u29f8 I) :=\n\u27e8\u03bb a, submodule.quotient.mk a, rfl, \u03bb _ _, rfl, rfl, \u03bb _ _, rfl\u27e9\n\n/- Two `ring_homs`s from the quotient by an ideal are equal if their\ncompositions with `ideal.quotient.mk'` are equal.\n\nSee note [partially-applied ext lemmas]. -/\n@[ext]\nlemma ring_hom_ext [non_assoc_semiring S] \u2983f g : R \u29f8 I \u2192+* S\u2984\n  (h : f.comp (mk I) = g.comp (mk I)) : f = g :=\nring_hom.ext $ \u03bb x, quotient.induction_on' x $ (ring_hom.congr_fun h : _)\n\ninstance inhabited : inhabited (R \u29f8 I) := \u27e8mk I 37\u27e9\n\nprotected theorem eq : mk I x = mk I y \u2194 x - y \u2208 I := submodule.quotient.eq I\n\n@[simp] theorem mk_eq_mk (x : R) : (submodule.quotient.mk x : R \u29f8 I) = mk I x := rfl\n\nlemma eq_zero_iff_mem {I : ideal R} : mk I a = 0 \u2194 a \u2208 I :=\nby conv {to_rhs, rw \u2190 sub_zero a }; exact quotient.eq'\n\ntheorem zero_eq_one_iff {I : ideal R} : (0 : R \u29f8 I) = 1 \u2194 I = \u22a4 :=\neq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm\n\ntheorem zero_ne_one_iff {I : ideal R} : (0 : R \u29f8 I) \u2260 1 \u2194 I \u2260 \u22a4 :=\nnot_congr zero_eq_one_iff\n\nprotected theorem nontrivial {I : ideal R} (hI : I \u2260 \u22a4) : nontrivial (R \u29f8 I) :=\n\u27e8\u27e80, 1, zero_ne_one_iff.2 hI\u27e9\u27e9\n\nlemma mk_surjective : function.surjective (mk I) :=\n\u03bb y, quotient.induction_on' y (\u03bb x, exists.intro x rfl)\n\n/-- If `I` is an ideal of a commutative ring `R`, if `q : R \u2192 R/I` is the quotient map, and if\n`s \u2286 R` is a subset, then `q\u207b\u00b9(q(s)) = \u22c3\u1d62(i + s)`, the union running over all `i \u2208 I`. -/\nlemma quotient_ring_saturate (I : ideal R) (s : set R) :\n  mk I \u207b\u00b9' (mk I '' s) = (\u22c3 x : I, (\u03bb y, x.1 + y) '' s) :=\nbegin\n  ext x,\n  simp only [mem_preimage, mem_image, mem_Union, ideal.quotient.eq],\n  exact \u27e8\u03bb \u27e8a, a_in, h\u27e9, \u27e8\u27e8_, I.neg_mem h\u27e9, a, a_in, by simp\u27e9,\n         \u03bb \u27e8\u27e8i, hi\u27e9, a, ha, eq\u27e9,\n           \u27e8a, ha, by rw [\u2190 eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub]; exact I.neg_mem hi\u27e9\u27e9\nend\n\ninstance is_domain (I : ideal R) [hI : I.is_prime] : is_domain (R \u29f8 I) :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero := \u03bb a b,\n    quotient.induction_on\u2082' a b $ \u03bb a b hab,\n      (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim\n        (or.inl \u2218 eq_zero_iff_mem.2)\n        (or.inr \u2218 eq_zero_iff_mem.2),\n  .. quotient.nontrivial hI.1 }\n\nlemma is_domain_iff_prime (I : ideal R) : is_domain (R \u29f8 I) \u2194 I.is_prime :=\n\u27e8 \u03bb \u27e8h1, h2\u27e9, \u27e8zero_ne_one_iff.1 $ @zero_ne_one _ _ \u27e8h2\u27e9, \u03bb x y h,\n    by { simp only [\u2190eq_zero_iff_mem, (mk I).map_mul] at \u22a2 h, exact h1 h}\u27e9,\n  \u03bb h, by { resetI, apply_instance }\u27e9\n\nlemma exists_inv {I : ideal R} [hI : I.is_maximal] :\n  \u2200 {a : (R \u29f8 I)}, a \u2260 0 \u2192 \u2203 b : (R \u29f8 I), a * b = 1 :=\nbegin\n  rintro \u27e8a\u27e9 h,\n  rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with \u27e8b, c, hc, abc\u27e9,\n  rw [mul_comm] at abc,\n  refine \u27e8mk _ b, quot.sound _\u27e9, --quot.sound hb\n  rw \u2190 eq_sub_iff_add_eq' at abc,\n  rw [abc, \u2190 neg_mem_iff, neg_sub] at hc,\n  convert hc,\nend\n\nopen_locale classical\n\n/-- quotient by maximal ideal is a field. def rather than instance, since users will have\ncomputable inverses in some applications.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected noncomputable def field (I : ideal R) [hI : I.is_maximal] : field (R \u29f8 I) :=\n{ inv := \u03bb a, if ha : a = 0 then 0 else classical.some (exists_inv ha),\n  mul_inv_cancel := \u03bb a (ha : a \u2260 0), show a * dite _ _ _ = _,\n    by rw dif_neg ha;\n    exact classical.some_spec (exists_inv ha),\n  inv_zero := dif_pos rfl,\n  ..quotient.comm_ring I,\n  ..quotient.is_domain I }\n\n/-- If the quotient by an ideal is a field, then the ideal is maximal. -/\ntheorem maximal_of_is_field (I : ideal R)\n  (hqf : is_field (R \u29f8 I)) : I.is_maximal :=\nbegin\n  apply ideal.is_maximal_iff.2,\n  split,\n  { intro h,\n    rcases hqf.exists_pair_ne with \u27e8\u27e8x\u27e9, \u27e8y\u27e9, hxy\u27e9,\n    exact hxy (ideal.quotient.eq.2 (mul_one (x - y) \u25b8 I.mul_mem_left _ h)) },\n  { intros J x hIJ hxnI hxJ,\n    rcases hqf.mul_inv_cancel (mt ideal.quotient.eq_zero_iff_mem.1 hxnI) with \u27e8\u27e8y\u27e9, hy\u27e9,\n    rw [\u2190 zero_add (1 : R), \u2190 sub_self (x * y), sub_add],\n    refine J.sub_mem (J.mul_mem_right _ hxJ) (hIJ (ideal.quotient.eq.1 hy)) }\nend\n\n/-- The quotient of a ring by an ideal is a field iff the ideal is maximal. -/\ntheorem maximal_ideal_iff_is_field_quotient (I : ideal R) :\n  I.is_maximal \u2194 is_field (R \u29f8 I) :=\n\u27e8\u03bb h, @field.to_is_field (R \u29f8 I) (@ideal.quotient.field _ _ I h),\n \u03bb h, maximal_of_is_field I h\u27e9\n\nvariable [comm_ring S]\n\n/-- Given a ring homomorphism `f : R \u2192+* S` sending all elements of an ideal to zero,\nlift it to the quotient by this ideal. -/\ndef lift (I : ideal R) (f : R \u2192+* S) (H : \u2200 (a : R), a \u2208 I \u2192 f a = 0) :\n  R \u29f8 I \u2192+* S :=\n{ to_fun := \u03bb x, quotient.lift_on' x f $ \u03bb (a b) (h : _ \u2208 _),\n    eq_of_sub_eq_zero $ by rw [\u2190 f.map_sub, H _ h],\n  map_one' := f.map_one,\n  map_zero' := f.map_zero,\n  map_add' := \u03bb a\u2081 a\u2082, quotient.induction_on\u2082' a\u2081 a\u2082 f.map_add,\n  map_mul' := \u03bb a\u2081 a\u2082, quotient.induction_on\u2082' a\u2081 a\u2082 f.map_mul }\n\n@[simp] lemma lift_mk (I : ideal R) (f : R \u2192+* S) (H : \u2200 (a : R), a \u2208 I \u2192 f a = 0) :\n  lift I f H (mk I a) = f a := rfl\n\n/-- The ring homomorphism from the quotient by a smaller ideal to the quotient by a larger ideal.\n\nThis is the `ideal.quotient` version of `quot.factor` -/\ndef factor (S T : ideal R) (H : S \u2264 T) : R \u29f8 S \u2192+* R \u29f8 T :=\nideal.quotient.lift S (T^.quotient.mk) (\u03bb x hx, eq_zero_iff_mem.2 (H hx))\n\n@[simp] lemma factor_mk (S T : ideal R) (H : S \u2264 T) (x : R) :\n  factor S T H (mk S x) = mk T x := rfl\n\n@[simp] lemma factor_comp_mk (S T : ideal R) (H : S \u2264 T) : (factor S T H).comp (mk S) = mk T :=\nby { ext x, rw [ring_hom.comp_apply, factor_mk] }\n\nend quotient\n\n/-- Quotienting by equal ideals gives equivalent rings.\n\nSee also `submodule.quot_equiv_of_eq`.\n-/\ndef quot_equiv_of_eq {R : Type*} [comm_ring R] {I J : ideal R} (h : I = J) :\n  (R \u29f8 I) \u2243+* R \u29f8 J :=\n{ map_mul' := by { rintro \u27e8x\u27e9 \u27e8y\u27e9, refl },\n  .. submodule.quot_equiv_of_eq I J h }\n\n@[simp]\nlemma quot_equiv_of_eq_mk {R : Type*} [comm_ring R] {I J : ideal R} (h : I = J) (x : R) :\n  quot_equiv_of_eq h (ideal.quotient.mk I x) = ideal.quotient.mk J x :=\nrfl\n\nsection pi\nvariables (\u03b9 : Type v)\n\n/-- `R^n/I^n` is a `R/I`-module. -/\ninstance module_pi : module (R \u29f8 I) ((\u03b9 \u2192 R) \u29f8 I.pi \u03b9) :=\n{ smul := \u03bb c m, quotient.lift_on\u2082' c m (\u03bb r m, submodule.quotient.mk $ r \u2022 m) begin\n    intros c\u2081 m\u2081 c\u2082 m\u2082 hc hm,\n    apply ideal.quotient.eq.2,\n    intro i,\n    exact I.mul_sub_mul_mem hc (hm i),\n  end,\n  one_smul := begin\n    rintro \u27e8a\u27e9,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact one_mul (a i),\n  end,\n  mul_smul := begin\n    rintro \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    simp only [(\u2022)],\n    congr' with i, exact mul_assoc a b (c i),\n  end,\n  smul_add := begin\n    rintro \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact mul_add a (b i) (c i),\n  end,\n  smul_zero := begin\n    rintro \u27e8a\u27e9,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact mul_zero a,\n  end,\n  add_smul := begin\n    rintro \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact add_mul a b (c i),\n  end,\n  zero_smul := begin\n    rintro \u27e8a\u27e9,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact zero_mul (a i),\n  end, }\n\n/-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/\nnoncomputable def pi_quot_equiv : ((\u03b9 \u2192 R) \u29f8 I.pi \u03b9) \u2243\u2097[(R \u29f8 I)] (\u03b9 \u2192 (R \u29f8 I)) :=\n{ to_fun := \u03bb x, quotient.lift_on' x (\u03bb f i, ideal.quotient.mk I (f i)) $\n    \u03bb a b hab, funext (\u03bb i, ideal.quotient.eq.2 (hab i)),\n  map_add' := by { rintros \u27e8_\u27e9 \u27e8_\u27e9, refl },\n  map_smul' := by { rintros \u27e8_\u27e9 \u27e8_\u27e9, refl },\n  inv_fun := \u03bb x, ideal.quotient.mk (I.pi \u03b9) $ \u03bb i, quotient.out' (x i),\n  left_inv :=\n  begin\n    rintro \u27e8x\u27e9,\n    exact ideal.quotient.eq.2 (\u03bb i, ideal.quotient.eq.1 (quotient.out_eq' _))\n  end,\n  right_inv :=\n  begin\n    intro x,\n    ext i,\n    obtain \u27e8r, hr\u27e9 := @quot.exists_rep _ _ (x i),\n    simp_rw \u2190hr,\n    convert quotient.out_eq' _\n  end }\n\n/-- If `f : R^n \u2192 R^m` is an `R`-linear map and `I \u2286 R` is an ideal, then the image of `I^n` is\n    contained in `I^m`. -/\nlemma map_pi {\u03b9} [fintype \u03b9] {\u03b9' : Type w} (x : \u03b9 \u2192 R) (hi : \u2200 i, x i \u2208 I)\n  (f : (\u03b9 \u2192 R) \u2192\u2097[R] (\u03b9' \u2192 R)) (i : \u03b9') : f x i \u2208 I :=\nbegin\n  rw pi_eq_sum_univ x,\n  simp only [finset.sum_apply, smul_eq_mul, linear_map.map_sum, pi.smul_apply, linear_map.map_smul],\n  exact I.sum_mem (\u03bb j hj, I.mul_mem_right _ (hi j))\nend\n\nend pi\n\nsection chinese_remainder\nvariables {\u03b9 : Type v}\n\ntheorem exists_sub_one_mem_and_mem (s : finset \u03b9) {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i \u2208 s, \u2200 j \u2208 s, i \u2260 j \u2192 f i \u2294 f j = \u22a4) (i : \u03b9) (his : i \u2208 s) :\n  \u2203 r : R, r - 1 \u2208 f i \u2227 \u2200 j \u2208 s, j \u2260 i \u2192 r \u2208 f j :=\nbegin\n  have : \u2200 j \u2208 s, j \u2260 i \u2192 \u2203 r : R, \u2203 H : r - 1 \u2208 f i, r \u2208 f j,\n  { intros j hjs hji, specialize hf i his j hjs hji.symm,\n    rw [eq_top_iff_one, submodule.mem_sup] at hf,\n    rcases hf with \u27e8r, hri, s, hsj, hrs\u27e9, refine \u27e81 - r, _, _\u27e9,\n    { rw [sub_right_comm, sub_self, zero_sub], exact (f i).neg_mem hri },\n    { rw [\u2190 hrs, add_sub_cancel'], exact hsj } },\n  classical,\n  have : \u2203 g : \u03b9 \u2192 R, (\u2200 j, g j - 1 \u2208 f i) \u2227 \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2208 f j,\n  { choose g hg1 hg2,\n    refine \u27e8\u03bb j, if H : j \u2208 s \u2227 j \u2260 i then g j H.1 H.2 else 1, \u03bb j, _, \u03bb j, _\u27e9,\n    { split_ifs with h, { apply hg1 }, rw sub_self, exact (f i).zero_mem },\n    { intros hjs hji, rw dif_pos, { apply hg2 }, exact \u27e8hjs, hji\u27e9 } },\n  rcases this with \u27e8g, hgi, hgj\u27e9, use (\u220f x in s.erase i, g x), split,\n  { rw [\u2190 quotient.eq, ring_hom.map_one, ring_hom.map_prod],\n    apply finset.prod_eq_one, intros, rw [\u2190 ring_hom.map_one, quotient.eq], apply hgi },\n  intros j hjs hji, rw [\u2190 quotient.eq_zero_iff_mem, ring_hom.map_prod],\n  refine finset.prod_eq_zero (finset.mem_erase_of_ne_of_mem hji hjs) _,\n  rw quotient.eq_zero_iff_mem, exact hgj j hjs hji\nend\n\ntheorem exists_sub_mem [fintype \u03b9] {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) (g : \u03b9 \u2192 R) :\n  \u2203 r : R, \u2200 i, r - g i \u2208 f i :=\nbegin\n  have : \u2203 \u03c6 : \u03b9 \u2192 R, (\u2200 i, \u03c6 i - 1 \u2208 f i) \u2227 (\u2200 i j, i \u2260 j \u2192 \u03c6 i \u2208 f j),\n  { have := exists_sub_one_mem_and_mem (finset.univ : finset \u03b9) (\u03bb i _ j _ hij, hf i j hij),\n    choose \u03c6 h\u03c6,\n    existsi \u03bb i, \u03c6 i (finset.mem_univ i),\n    exact \u27e8\u03bb i, (h\u03c6 i _).1, \u03bb i j hij, (h\u03c6 i _).2 j (finset.mem_univ j) hij.symm\u27e9 },\n  rcases this with \u27e8\u03c6, h\u03c61, h\u03c62\u27e9,\n  use \u2211 i, g i * \u03c6 i,\n  intros i,\n  rw [\u2190 quotient.eq, ring_hom.map_sum],\n  refine eq.trans (finset.sum_eq_single i _ _) _,\n  { intros j _ hji, rw quotient.eq_zero_iff_mem, exact (f i).mul_mem_left _ (h\u03c62 j i hji) },\n  { intros hi, exact (hi $ finset.mem_univ i).elim },\n  specialize h\u03c61 i, rw [\u2190 quotient.eq, ring_hom.map_one] at h\u03c61,\n  rw [ring_hom.map_mul, h\u03c61, mul_one]\nend\n\n/-- The homomorphism from `R/(\u22c2 i, f i)` to `\u220f i, (R / f i)` featured in the Chinese\n  Remainder Theorem. It is bijective if the ideals `f i` are comaximal. -/\ndef quotient_inf_to_pi_quotient (f : \u03b9 \u2192 ideal R) :\n  R \u29f8 (\u2a05 i, f i) \u2192+* \u03a0 i, R \u29f8 f i :=\nquotient.lift (\u2a05 i, f i)\n  (pi.ring_hom (\u03bb i : \u03b9, (quotient.mk (f i) : _))) $\n  \u03bb r hr, begin\n    rw submodule.mem_infi at hr,\n    ext i,\n    exact quotient.eq_zero_iff_mem.2 (hr i)\n  end\n\ntheorem quotient_inf_to_pi_quotient_bijective [fintype \u03b9] {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) :\n  function.bijective (quotient_inf_to_pi_quotient f) :=\n\u27e8\u03bb x y, quotient.induction_on\u2082' x y $ \u03bb r s hrs, quotient.eq.2 $\n  (submodule.mem_infi _).2 $ \u03bb i, quotient.eq.1 $\n  show quotient_inf_to_pi_quotient f (quotient.mk' r) i = _, by rw hrs; refl,\n\u03bb g, let \u27e8r, hr\u27e9 := exists_sub_mem hf (\u03bb i, quotient.out' (g i)) in\n\u27e8quotient.mk _ r, funext $ \u03bb i, quotient.out_eq' (g i) \u25b8 quotient.eq.2 (hr i)\u27e9\u27e9\n\n/-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/\nnoncomputable def quotient_inf_ring_equiv_pi_quotient [fintype \u03b9] (f : \u03b9 \u2192 ideal R)\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) :\n  R \u29f8 (\u2a05 i, f i) \u2243+* \u03a0 i, R \u29f8 f i :=\n{ .. equiv.of_bijective _ (quotient_inf_to_pi_quotient_bijective hf),\n  .. quotient_inf_to_pi_quotient f }\n\nend chinese_remainder\n\nend ideal\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/ideal/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7397330014262133}}
{"text": "/-\nCopyright (c) 2014 Robert Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Lewis, Leonardo de Moura, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport algebra.ring.basic\n\n/-!\n# Fields and division rings\n\nThis file introduces fields and division rings (also known as skewfields) and proves some basic\nstatements about them. For a more extensive theory of fields, see the `field_theory` folder.\n\n## Main definitions\n\n* `division_ring`: introduces the notion of a division ring as a `ring` such that `0 \u2260 1` and\n  `a * a\u207b\u00b9 = 1` for `a \u2260 0`\n* `field`: a division ring which is also a commutative ring.\n* `is_field`: a predicate on a ring that it is a field, i.e. that the multiplication is commutative,\n  that it has more than one element and that all non-zero elements have a multiplicative inverse.\n  In contrast to `field`, which contains the data of a function associating to an element of the\n  field its multiplicative inverse, this predicate only assumes the existence and can therefore more\n  easily be used to e.g. transfer along ring isomorphisms.\n\n## Implementation details\n\nBy convention `0\u207b\u00b9 = 0` in a field or division ring. This is due to the fact that working with total\nfunctions has the advantage of not constantly having to check that `x \u2260 0` when writing `x\u207b\u00b9`. With\nthis convention in place, some statements like `(a + b) * c\u207b\u00b9 = a * c\u207b\u00b9 + b * c\u207b\u00b9` still remain\ntrue, while others like the defining property `a * a\u207b\u00b9 = 1` need the assumption `a \u2260 0`. If you are\na beginner in using Lean and are confused by that, you can read more about why this convention is\ntaken in Kevin Buzzard's\n[blogpost](https://xenaproject.wordpress.com/2020/07/05/division-by-zero-in-type-theory-a-faq/)\n\nA division ring or field is an example of a `group_with_zero`. If you cannot find\na division ring / field lemma that does not involve `+`, you can try looking for\na `group_with_zero` lemma instead.\n\n## Tags\n\nfield, division ring, skew field, skew-field, skewfield\n-/\n\nopen set\n\nset_option old_structure_cmd true\n\nuniverse u\nvariables {K : Type u}\n\n/-- A `division_ring` is a `ring` with multiplicative inverses for nonzero elements -/\n@[protect_proj, ancestor ring div_inv_monoid nontrivial]\nclass division_ring (K : Type u) extends ring K, div_inv_monoid K, nontrivial K :=\n(mul_inv_cancel : \u2200 {a : K}, a \u2260 0 \u2192 a * a\u207b\u00b9 = 1)\n(inv_zero : (0 : K)\u207b\u00b9 = 0)\n\nsection division_ring\nvariables [division_ring K] {a b : K}\n\n/-- Every division ring is a `group_with_zero`. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance division_ring.to_group_with_zero :\n  group_with_zero K :=\n{ .. \u2039division_ring K\u203a,\n  .. (infer_instance : semiring K) }\n\nattribute [field_simps] inv_eq_one_div\n\nlocal attribute [simp]\n  division_def mul_comm mul_assoc\n  mul_left_comm mul_inv_cancel inv_mul_cancel\n\nlemma one_div_neg_one_eq_neg_one : (1:K) / (-1) = -1 :=\nhave (-1) * (-1) = (1:K), by rw [neg_mul_neg, one_mul],\neq.symm (eq_one_div_of_mul_eq_one this)\n\nlemma one_div_neg_eq_neg_one_div (a : K) : 1 / (- a) = - (1 / a) :=\ncalc\n  1 / (- a) = 1 / ((-1) * a)        : by rw neg_eq_neg_one_mul\n        ... = (1 / a) * (1 / (- 1)) : by rw one_div_mul_one_div_rev\n        ... = (1 / a) * (-1)        : by rw one_div_neg_one_eq_neg_one\n        ... = - (1 / a)             : by rw [mul_neg_eq_neg_mul_symm, mul_one]\n\nlemma div_neg_eq_neg_div (a b : K) : b / (- a) = - (b / a) :=\ncalc\n  b / (- a) = b * (1 / (- a)) : by rw [\u2190 inv_eq_one_div, division_def]\n        ... = b * -(1 / a)    : by rw one_div_neg_eq_neg_one_div\n        ... = -(b * (1 / a))  : by rw neg_mul_eq_mul_neg\n        ... = - (b / a)       : by rw mul_one_div\n\nlemma neg_div (a b : K) : (-b) / a = - (b / a) :=\nby rw [neg_eq_neg_one_mul, mul_div_assoc, \u2190 neg_eq_neg_one_mul]\n\n@[field_simps] lemma neg_div' (a b : K) : - (b / a) = (-b) / a :=\nby simp [neg_div]\n\nlemma neg_div_neg_eq (a b : K) : (-a) / (-b) = a / b :=\nby rw [div_neg_eq_neg_div, neg_div, neg_neg]\n\n@[field_simps] lemma div_add_div_same (a b c : K) : a / c + b / c = (a + b) / c :=\nby simpa only [div_eq_mul_inv] using (right_distrib a b (c\u207b\u00b9)).symm\n\nlemma same_add_div {a b : K} (h : b \u2260 0) : (b + a) / b = 1 + a / b :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_add_div_same b a b).symm\n\nlemma one_add_div {a b : K} (h : b \u2260 0 ) : 1 + a / b = (b + a) / b := (same_add_div h).symm\n\nlemma div_add_same {a b : K} (h : b \u2260 0) : (a + b) / b = a / b + 1 :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_add_div_same a b b).symm\n\nlemma div_add_one {a b : K} (h : b \u2260 0) : a / b + 1 = (a + b) / b := (div_add_same h).symm\n\nlemma div_sub_div_same (a b c : K) : (a / c) - (b / c) = (a - b) / c :=\nby rw [sub_eq_add_neg, \u2190 neg_div, div_add_div_same, sub_eq_add_neg]\n\nlemma same_sub_div {a b : K} (h : b \u2260 0) : (b - a) / b = 1 - a / b :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_sub_div_same b a b).symm\n\nlemma one_sub_div {a b : K} (h : b \u2260 0) : 1 - a / b = (b - a) / b := (same_sub_div h).symm\n\nlemma div_sub_same {a b : K} (h : b \u2260 0) : (a - b) / b = a / b - 1 :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_sub_div_same a b b).symm\n\nlemma div_sub_one {a b : K} (h : b \u2260 0) : a / b - 1 = (a - b) / b := (div_sub_same h).symm\n\nlemma neg_inv : - a\u207b\u00b9 = (- a)\u207b\u00b9 :=\nby rw [inv_eq_one_div, inv_eq_one_div, div_neg_eq_neg_div]\n\nlemma add_div (a b c : K) : (a + b) / c = a / c + b / c :=\n(div_add_div_same _ _ _).symm\n\nlemma sub_div (a b c : K) : (a - b) / c = a / c - b / c :=\n(div_sub_div_same _ _ _).symm\n\nlemma div_neg (a : K) : a / -b = -(a / b) :=\nby rw [\u2190 div_neg_eq_neg_div]\n\nlemma inv_neg : (-a)\u207b\u00b9 = -(a\u207b\u00b9) :=\nby rw neg_inv\n\nlemma one_div_mul_add_mul_one_div_eq_one_div_add_one_div (ha : a \u2260 0) (hb : b \u2260 0) :\n          (1 / a) * (a + b) * (1 / b) = 1 / a + 1 / b :=\nby rw [(left_distrib (1 / a)), (one_div_mul_cancel ha), right_distrib, one_mul,\n       mul_assoc, (mul_one_div_cancel hb), mul_one, add_comm]\n\nlemma one_div_mul_sub_mul_one_div_eq_one_div_add_one_div (ha : a \u2260 0) (hb : b \u2260 0) :\n          (1 / a) * (b - a) * (1 / b) = 1 / a - 1 / b :=\nby rw [(mul_sub_left_distrib (1 / a)), (one_div_mul_cancel ha), mul_sub_right_distrib,\n       one_mul, mul_assoc, (mul_one_div_cancel hb), mul_one]\n\nlemma add_div_eq_mul_add_div (a b : K) {c : K} (hc : c \u2260 0) : a + b / c = (a * c + b) / c :=\n(eq_div_iff_mul_eq hc).2 $ by rw [right_distrib, (div_mul_cancel _ hc)]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance division_ring.is_domain : is_domain K :=\n{ ..\u2039division_ring K\u203a,\n  ..(by apply_instance : no_zero_divisors K) }\n\nend division_ring\n\n/-- A `field` is a `comm_ring` with multiplicative inverses for nonzero elements -/\n@[protect_proj, ancestor comm_ring div_inv_monoid nontrivial]\nclass field (K : Type u) extends comm_ring K, div_inv_monoid K, nontrivial K :=\n(mul_inv_cancel : \u2200 {a : K}, a \u2260 0 \u2192 a * a\u207b\u00b9 = 1)\n(inv_zero : (0 : K)\u207b\u00b9 = 0)\n\nsection field\n\nvariable [field K]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance field.to_division_ring : division_ring K :=\n{ ..show field K, by apply_instance }\n\n/-- Every field is a `comm_group_with_zero`. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance field.to_comm_group_with_zero :\n  comm_group_with_zero K :=\n{ .. (_ : group_with_zero K), .. \u2039field K\u203a }\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\nlemma div_add_div (a : K) {b : K} (c : K) {d : K} (hb : b \u2260 0) (hd : d \u2260 0) :\n      (a / b) + (c / d) = ((a * d) + (b * c)) / (b * d) :=\nby rw [\u2190 mul_div_mul_right _ b hd, \u2190 mul_div_mul_left c d hb, div_add_div_same]\n\nlemma one_div_add_one_div {a b : K} (ha : a \u2260 0) (hb : b \u2260 0) : 1 / a + 1 / b = (a + b) / (a * b) :=\nby rw [div_add_div _ _ ha hb, one_mul, mul_one, add_comm]\n\n@[field_simps] lemma div_sub_div (a : K) {b : K} (c : K) {d : K} (hb : b \u2260 0) (hd : d \u2260 0) :\n  (a / b) - (c / d) = ((a * d) - (b * c)) / (b * d) :=\nbegin\n  simp only [sub_eq_add_neg],\n  rw [neg_eq_neg_one_mul, \u2190 mul_div_assoc, div_add_div _ _ hb hd,\n      \u2190 mul_assoc, mul_comm b, mul_assoc, \u2190 neg_eq_neg_one_mul]\nend\n\nlemma inv_add_inv {a b : K} (ha : a \u2260 0) (hb : b \u2260 0) : a\u207b\u00b9 + b\u207b\u00b9 = (a + b) / (a * b) :=\nby rw [inv_eq_one_div, inv_eq_one_div, one_div_add_one_div ha hb]\n\nlemma inv_sub_inv {a b : K} (ha : a \u2260 0) (hb : b \u2260 0) : a\u207b\u00b9 - b\u207b\u00b9 = (b - a) / (a * b) :=\nby rw [inv_eq_one_div, inv_eq_one_div, div_sub_div _ _ ha hb, one_mul, mul_one]\n\n@[field_simps] lemma add_div' (a b c : K) (hc : c \u2260 0) : b + a / c = (b * c + a) / c :=\nby simpa using div_add_div b a one_ne_zero hc\n\n@[field_simps] lemma sub_div' (a b c : K) (hc : c \u2260 0) : b - a / c = (b * c - a) / c :=\nby simpa using div_sub_div b a one_ne_zero hc\n\n@[field_simps] lemma div_add' (a b c : K) (hc : c \u2260 0) : a / c + b = (a + b * c) / c :=\nby rwa [add_comm, add_div', add_comm]\n\n@[field_simps] lemma div_sub' (a b c : K) (hc : c \u2260 0) : a / c - b = (a - c * b) / c :=\nby simpa using div_sub_div a b hc one_ne_zero\n\n@[priority 100] -- see Note [lower instance priority]\ninstance field.is_domain : is_domain K :=\n{ ..division_ring.is_domain }\n\nend field\n\nsection is_field\n\n/-- A predicate to express that a ring is a field.\n\nThis is mainly useful because such a predicate does not contain data,\nand can therefore be easily transported along ring isomorphisms.\nAdditionaly, this is useful when trying to prove that\na particular ring structure extends to a field. -/\nstructure is_field (R : Type u) [ring R] : Prop :=\n(exists_pair_ne : \u2203 (x y : R), x \u2260 y)\n(mul_comm : \u2200 (x y : R), x * y = y * x)\n(mul_inv_cancel : \u2200 {a : R}, a \u2260 0 \u2192 \u2203 b, a * b = 1)\n\n/-- Transferring from field to is_field -/\nlemma field.to_is_field (R : Type u) [field R] : is_field R :=\n{ mul_inv_cancel := \u03bb a ha, \u27e8a\u207b\u00b9, field.mul_inv_cancel ha\u27e9,\n  ..\u2039field R\u203a }\n\nopen_locale classical\n\n/-- Transferring from is_field to field -/\nnoncomputable def is_field.to_field (R : Type u) [ring R] (h : is_field R) : field R :=\n{ inv := \u03bb a, if ha : a = 0 then 0 else classical.some (is_field.mul_inv_cancel h ha),\n  inv_zero := dif_pos rfl,\n  mul_inv_cancel := \u03bb a ha,\n    begin\n      convert classical.some_spec (is_field.mul_inv_cancel h ha),\n      exact dif_neg ha\n    end,\n  .. \u2039ring R\u203a, ..h }\n\n/-- For each field, and for each nonzero element of said field, there is a unique inverse.\nSince `is_field` doesn't remember the data of an `inv` function and as such,\na lemma that there is a unique inverse could be useful.\n-/\nlemma uniq_inv_of_is_field (R : Type u) [ring R] (hf : is_field R) :\n  \u2200 (x : R), x \u2260 0 \u2192 \u2203! (y : R), x * y = 1 :=\nbegin\n  intros x hx,\n  apply exists_unique_of_exists_of_unique,\n  { exact hf.mul_inv_cancel hx },\n  { intros y z hxy hxz,\n    calc y = y * (x * z) : by rw [hxz, mul_one]\n       ... = (x * y) * z : by rw [\u2190 mul_assoc, hf.mul_comm y x]\n       ... = z           : by rw [hxy, one_mul] }\nend\n\nend is_field\n\nnamespace ring_hom\n\nsection\n\nvariables {R : Type*} [semiring R] [division_ring K] (f : R \u2192+* K)\n\n@[simp] lemma map_units_inv (u : units R) :\n  f \u2191u\u207b\u00b9 = (f \u2191u)\u207b\u00b9 :=\n(f : R \u2192* K).map_units_inv u\n\nend\n\nsection\n\nvariables {R K' : Type*} [division_ring K] [semiring R] [nontrivial R] [division_ring K']\n  (f : K \u2192+* R) (g : K \u2192+* K') {x y : K}\n\nlemma map_ne_zero : f x \u2260 0 \u2194 x \u2260 0 := f.to_monoid_with_zero_hom.map_ne_zero\n\n@[simp] lemma map_eq_zero : f x = 0 \u2194 x = 0 := f.to_monoid_with_zero_hom.map_eq_zero\n\nvariables (x y)\n\nlemma map_inv : g x\u207b\u00b9 = (g x)\u207b\u00b9 := g.to_monoid_with_zero_hom.map_inv x\n\nlemma map_div : g (x / y) = g x / g y := g.to_monoid_with_zero_hom.map_div x y\n\nprotected lemma injective : function.injective f := f.injective_iff.2 $ \u03bb x, f.map_eq_zero.1\n\nend\n\nend ring_hom\n\nsection noncomputable_defs\n\nvariables {R : Type*} [nontrivial R]\n\n/-- Constructs a `division_ring` structure on a `ring` consisting only of units and 0. -/\nnoncomputable def division_ring_of_is_unit_or_eq_zero [hR : ring R]\n  (h : \u2200 (a : R), is_unit a \u2228 a = 0) : division_ring R :=\n{ .. (group_with_zero_of_is_unit_or_eq_zero h), .. hR }\n\n/-- Constructs a `field` structure on a `comm_ring` consisting only of units and 0. -/\nnoncomputable def field_of_is_unit_or_eq_zero [hR : comm_ring R]\n  (h : \u2200 (a : R), is_unit a \u2228 a = 0) : field R :=\n{ .. (group_with_zero_of_is_unit_or_eq_zero h), .. hR }\n\nend noncomputable_defs\n\n/-- Pullback a `division_ring` along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.division_ring [division_ring K] {K'}\n  [has_zero K'] [has_mul K'] [has_add K'] [has_neg K'] [has_sub K'] [has_one K'] [has_inv K']\n  [has_div K']\n  (f : K' \u2192 K) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9) (div : \u2200 x y, f (x / y) = f x / f y) :\n  division_ring K' :=\n{ .. hf.group_with_zero f zero one mul inv div,\n  .. hf.ring f zero one add mul neg sub }\n\n/-- Pullback a `field` along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.field [field K] {K'}\n  [has_zero K'] [has_mul K'] [has_add K'] [has_neg K'] [has_sub K'] [has_one K'] [has_inv K']\n  [has_div K']\n  (f : K' \u2192 K) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9) (div : \u2200 x y, f (x / y) = f x / f y) :\n  field K' :=\n{ .. hf.comm_group_with_zero f zero one mul inv div,\n  .. hf.comm_ring f zero one add mul neg sub }\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/field/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7397329963780095}}
{"text": "import data.nat.sqrt\n\nnamespace hidden\n\n/-\nTry defining other operations on the natural numbers, \nsuch as multiplication, the predecessor function (with pred 0 = 0), \ntruncated subtraction (with n - m = 0 when m is greater than or equal to n), \nand exponentiation. Then try proving some of their basic properties, \nbuilding on the theorems we have already proved.\n\nSince many of these are already defined in Lean\u2019s core library, \nyou should work within a namespace named hide, or something like that, in order to avoid name clashes.\n-/\n\ndef add : \u2115 \u2192 \u2115 \u2192 \u2115\n| nat.zero m := m\n| (nat.succ n) m := nat.succ (add n m) \n\n#reduce add 3 5\n\ndef pred : \u2115 \u2192 \u2115\n| nat.zero := 0\n| (nat.succ n) := n\n\ndef sub : \u2115 \u2192 \u2115 \u2192 \u2115 \n| nat.zero m := 0\n| (nat.succ n) m := sub n (pred m)\n\ndef mul : \u2115 \u2192 \u2115 \u2192 \u2115 \n| nat.zero m := 0\n| (nat.succ n) m := add m (mul n m)\n\ndef exp : \u2115 \u2192 \u2115 \u2192 \u2115\n| m nat.zero := 1\n| m (nat.succ n) := mul m (exp m n)\n\nlemma add_zero : \u2200 a, add a 0 = a :=\nbegin\n    assume a,\n    induction a with k hk,\n    trivial,\n\n    rw add,\n    rw hk,\nend\n\nlemma zero_add : \u2200 a, add 0 a = a :=\nbegin\n    assume a,\n    induction a with k hk,\n    trivial,\n\n    rw add,\nend\n\nlemma one_add : \u2200 a, nat.succ a = add a 1 :=\nbegin\n    assume a,\n    induction a with k hk,\n    trivial,\n\n    rw add,\n    rw hk,\nend\n\nlemma add_one : \u2200 a, nat.succ a = add 1 a :=\nbegin\n    assume a,\n    induction a with k hk,\n    trivial,\n\n    rw add,\n    rw hk,\n    rw zero_add,\nend\n\nlemma pred_succ : \u2200 a, pred (nat.succ a) = a :=\nbegin\n    assume a,\n    induction a with k hk,\n    trivial,\n    rw pred,\nend\n\nlemma add_n_succ_m : \u2200 n m, \n    add n (nat.succ m) = nat.succ (add n m) :=\nbegin\n    assume n m,\n    induction n with k hk,\n    trivial,\n\n    rw add,\n    rw add,\n    rw hk,\nend\n\nlemma add_comm : \u2200 a b, add a b = add b a :=\nbegin\n    assume a b,\n    induction a with ak hk,\n    rw add_zero,\n    trivial,\n\n    rw add_n_succ_m,\n    rw \u2190hk,\n    rw add,\nend\n\nlemma add_assoc : \u2200 a b c, \n    add a (add b c) = add (add a b) c :=\nbegin\n    assume a b c,\n    induction a with ak ah,\n    trivial,\n\n    rw add,\n    rw add,\n    rw add,\n    rw ah,\nend\n\nlemma zero_mul : \u2200 a, mul a 0 = 0 :=\nbegin\n    assume a,\n    induction a with k hk,\n    trivial,\n\n    rw mul,\n    rw hk,\n    trivial,\nend\n\nlemma mul_zero : \u2200 a, mul 0 a = 0 :=\nbegin\n    assume a,\n    trivial,\nend\n\nlemma one_mul : \u2200 a, mul 1 a = a :=\nbegin\n    assume a,\n    induction a with k hk,\n    trivial,\n\n    rw mul,\n    rw add,\n    rw mul_zero,\n    rw add_zero,\nend\n\n#reduce exp 0 0\n\nlemma exp_nonzero : \u2200 a, exp 0 (nat.succ a) = 0 :=\nbegin\n    assume a,\n    rw exp,\n    trivial,\nend\n\nlemma mul_n_succ_m : \u2200 a b, \n    mul a (nat.succ b) = add a (mul a b) :=\nbegin\n    assume a b,\n    induction a with ak ah,\n    trivial,\n\n    simp [mul, add_comm, ah, add, add_assoc],\n    -- rw mul,\n    -- rw mul,\n    -- rw add_comm,\n    -- rw ah,\n    -- rw add,\n    -- rw add_n_succ_m,\n    -- rw add_comm,\n    -- rw add_assoc,\n    -- rw add_assoc,\n    -- rw (add_comm ak b),\nend\n\nlemma mul_comm : \u2200 a b , mul a b = mul b a :=\nbegin\n    assume a b,\n    induction a with ak ah,\n    rw zero_mul,\n    rw mul_zero,\n\n    simp [mul, mul_n_succ_m, add_comm, ah],\nend\n\n-- example : \u2200 a b c, \n--     mul (exp a b) (exp a c) = exp a (add b c) :=\n-- begin\n--     assume a b c,\n--     induction a,\n--     induction b,\n--     induction c,\n--     trivial,\n\n\n--     simp [exp, mul, add, exp_nonzero],\n--     simp [exp, mul, add, exp_nonzero],\n    \n--     simp [exp, mul, add, exp_nonzero, add_comm, add_assoc],\n\n-- end\n#reduce mul 3 5\n#reduce exp 2 6\n\nend hidden\n", "meta": {"author": "hanzhi713", "repo": "lean-proofs", "sha": "4d8356a878645b9ba7cb036f87737f3f1e68ede5", "save_path": "github-repos/lean/hanzhi713-lean-proofs", "path": "github-repos/lean/hanzhi713-lean-proofs/lean-proofs-4d8356a878645b9ba7cb036f87737f3f1e68ede5/src/chapter_exercises/chap7_exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856559, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7397329921484278}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Sets in Lean, example sheet 2 : \"the\" empty set and the \"universal set\".\n\nLean notation for the empty subset of `X` is `\u2205`. Unlike in\nset theory, there is more than one empty set in Lean! Every\ntype has an empty subset, and it *doesn't make sense*\nto ask if `\u2205 : set \u2115` and `\u2205 : set \u2124` are equal, because\nthey have different types. \n\nAt the other extreme, the subset of `X` containing all the terms of type `X`\nis...well...mathematicians would just call it `X`, but `X` is a type not a subset. \nThe subset of `X` consisting of every element of `X` is called `set.univ : set X`, \nor just `univ : set X` if we have opened the `set` namespace. Let's do that now.\n\n-/\n\nopen set\n\n/-\n\n## Definition of \u2205 and univ\n\n`x \u2208 \u2205` is *by definition* equal to `false` and `x \u2208 univ` is *by definition*\nequal to `true`. You can use the `change` tactic to make these changes\nif you like. But you don't have to. Remember that `triv` proves `true`\nand `cases h` will solve a goal if `h : false` (because there are no cases!)\n\n-/\n\n\n-- set up variables\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D E : set X) -- A,B,C,D,E are subsets of `X`\n  (x y z : X) -- x,y,z are elements of `X` or, more precisely, terms of type `X`\n\nopen set\n\nexample : x \u2208 (univ : set X) := \nbegin\n  triv,\nend\n\nexample : x \u2208 (\u2205 : set X) \u2192 false :=\nbegin\n  exact id,\nend\n\nexample : A \u2286 univ :=\nbegin\n  intros x hxA,\n  triv,\nend\n\nexample : \u2205 \u2286 A :=\nbegin\n  -- rintros x \u27e8\u27e9, -- solves goal in one line\n  intros x hx,\n  change false at hx, -- unnecessary line\n  exfalso,\n  exact hx,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section05sets/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7397224388527253}}
{"text": "import .lovelib\n\n\n/- # LoVe Homework 8: Operational Semantics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1 (6 points + 1 bonus point): Semantics of the REPEAT Language\n\nWe introduce REPEAT, a programming language that resembles the WHILE language\nbut whose defining feature is a `repeat` loop.\n\nThe Lean definition of its abstract syntax tree follows: -/\n\ninductive stmt : Type\n| skip   : stmt\n| assign : string \u2192 (state \u2192 \u2115) \u2192 stmt\n| seq    : stmt \u2192 stmt \u2192 stmt\n| unless : (state \u2192 Prop) \u2192 stmt \u2192 stmt\n| repeat : \u2115 \u2192 stmt \u2192 stmt\n\ninfixr ` ;; ` : 90 := stmt.seq\n\n/- The `skip`, `assign`, and `S ;; T` statements have the same syntax and\nsemantics as in the WHILE language.\n\nThe `unless b S` statement executes `S` unless `b` is true\u2014i.e., it executes `S`\nif `b` is false. Otherwise, `unless b S` does nothing. This construct is\ninspired by the Perl language.\n\nThe `repeat n S` statement executes `S` exactly `n` times. Thus, `repeat 5 S` is\nequivalent to `S ;; S ;; S ;; S ;; S` (in terms of a big-step semantics at\nleast) and `repeat 0 S` is equivalent to `skip`.\n\n1.1 (1.5 points). Complete the following definition of a big-step\nsemantics: -/\n\ninductive big_step : stmt \u00d7 state \u2192 state \u2192 Prop\n| skip {s} :\n  big_step (stmt.skip, s) s\n| assign {x a s} :\n  big_step (stmt.assign x a, s) (s{x \u21a6 a s})\n| seq {S T s t u} (hs : big_step (S, s) t)\n    (ht : big_step (T, t) u) :\n  big_step (S ;; T, s) u\n| unless_false {b : state \u2192 Prop} {S s t} (hcond : \u00ac b s)\n    (hbody : big_step (S, s) t) :\n  big_step (stmt.unless b S, s) t\n| unless_true {b : state \u2192 Prop} {S s} (hcond : b s) :\n  big_step (stmt.unless b S, s) s\n| repeat_zero {S s} : big_step (stmt.repeat 0 S, s) s\n| repeat_succ {n S s t u} (hbody : big_step (S, s) t)\n    (hrest : big_step (stmt.repeat n S, t) u) :\n  big_step (stmt.repeat (n + 1) S, s) u\n\ninfix ` \u27f9 ` : 110 := big_step\n\n/- 1.2 (1.5 points). Complete the following definition of a small-step\nsemantics: -/\n\ninductive small_step : stmt \u00d7 state \u2192 stmt \u00d7 state \u2192 Prop\n| assign {x a s} :\n  small_step (stmt.assign x a, s) (stmt.skip, s{x \u21a6 a s})\n| seq_step {S S' T s s'} (hS : small_step (S, s) (S', s')) :\n  small_step (S ;; T, s) (S' ;; T, s')\n| seq_skip {T s} :\n  small_step (stmt.skip ;; T, s) (T, s)\n| unless_false {b : state \u2192 Prop} {S s} (hcond : \u00ac b s) :\n  small_step (stmt.unless b S, s) (S, s)\n| unless_true {b : state \u2192 Prop} {S s} (hcond : b s) :\n  small_step (stmt.unless b S, s) (stmt.skip, s)\n| repeat_zero {S s} :\n  small_step (stmt.repeat 0 S, s) (stmt.skip, s)\n| repeat_succ {n S s} :\n  small_step (stmt.repeat (n + 1) S, s) (S ;; stmt.repeat n S, s)\n\ninfixr ` \u21d2 ` := small_step\ninfixr ` \u21d2* ` : 100 := star small_step\n\n/- 1.3 (1 point). We will now attempt to prove termination of the REPEAT\nlanguage. More precisely, we will show that there cannot be infinite chains of\nthe form\n\n    `(S\u2080, s\u2080) \u21d2 (S\u2081, s\u2081) \u21d2 (S\u2082, s\u2082) \u21d2 \u22ef`\n\nTowards this goal, you are asked to define a __measure__ function: a function\n`mess` that takes a statement `S` and that returns a natural number indicating\nhow \"big\" the statement is. The measure should be defined so that it strictly\ndecreases with each small-step transition. -/\n\ndef mess : stmt \u2192 \u2115\n| stmt.skip         := 0\n| (stmt.assign _ _) := 1\n| (S ;; T)     := mess S + mess T + 1\n| (stmt.unless _ S) := mess S + 1\n| (stmt.repeat n S) := n * (mess S + 2) + 1\n\n/- 1.4 (1 point). Consider the following program `S\u2080`: -/\n\ndef incr (x : string) : stmt :=\nstmt.assign x (\u03bbs, s x + 1)\n\ndef S\u2080 : stmt :=\nstmt.repeat 1 (incr \"m\" ;; incr \"n\")\n\n/- Check that `mess` strictly decreases with each step of its small-step\nevaluation, by giving `S\u2080`, `S\u2081`, `S\u2082`, \u2026, as well as the corresponding values\nof `mess` (which you can obtain using `#eval`). -/\n\ndef S\u2081 : stmt :=\n(incr \"m\" ;; incr \"n\") ;; stmt.repeat 0 (incr \"m\" ;; incr \"n\")\n\ndef S\u2082 : stmt :=\n(stmt.skip ;; incr \"n\") ;; stmt.repeat 0 (incr \"m\" ;; incr \"n\")\n\ndef S\u2083 : stmt :=\nincr \"n\" ;; stmt.repeat 0 (incr \"m\" ;; incr \"n\")\n\ndef S\u2084 : stmt :=\nstmt.skip ;; stmt.repeat 0 (incr \"m\" ;; incr \"n\")\n\ndef S\u2085 : stmt :=\nstmt.repeat 0 (incr \"m\" ;; incr \"n\")\n\ndef S\u2086 : stmt :=\nstmt.skip\n\n#eval mess S\u2080   -- result: 6\n#eval mess S\u2081   -- result: 5\n#eval mess S\u2082   -- result: 4\n#eval mess S\u2083   -- result: 3\n#eval mess S\u2084   -- result: 2\n#eval mess S\u2085   -- result: 1\n#eval mess S\u2086   -- result: 0\n\n/- 1.5 (1 point). Prove that the measure decreases with each small-step\ntransition. If necessary, revise your answer to question 1.3. -/\n\nlemma small_step_mess_decreases {Ss Tt : stmt \u00d7 state} (h : Ss \u21d2 Tt) :\n  mess (prod.fst Ss) > mess (prod.fst Tt) :=\nby induction' h; simp [mess, mul_add, add_mul] at *; linarith\n\n/- 1.6 (1 bonus point). Prove that the inverse of the `\u21d2` relation is well\nfounded. The inverse is simply `\u03bbTt Ss, Ss \u21d2 Tt`. A relation `\u227a` is well founded\nif there exist no infinite left-descending chains of the form\n\n    `\u22ef \u227a x\u2082 \u227a x\u2081 \u227a x\u2080`\n\nProof strategy: The `measure` function from `mathlib` converts a function to `\u2115`\nto a relation, using `<` to compare two numbers. Hence, start by proving that\n`measure mess`, or rather `measure (mess \u2218 prod.fst)`, is well founded. Here,\n`library_search` can help, or just search manually in `wf.lean`, close to the\ndefinition of `measure`. Then prove that `\u03bbTt Ss, Ss \u21d2 Tt` is a subrelation of\n`measure (mess \u2218 prod.fst)` (using lemma `small_step_mess_decreases` from\nquestion 1.5) and therefore (using another lemma from `wf.lean`) that it must be\nwell founded. -/\n\nlemma small_step_wf :\n  well_founded (\u03bbTt Ss, Ss \u21d2 Tt) :=\nbegin\n  apply subrelation.wf _ (measure_wf (mess \u2218 prod.fst)),\n  rw subrelation,\n  intros x y h,\n  rw measure,\n  rw inv_image,\n  exact small_step_mess_decreases h\nend\n\n\n/- ## Question 2 (3 points): Inversion Rules\n\n2.1 (1 point). Prove the following inversion rule for the big-step semantics\nof `unless`. -/\n\nlemma big_step_ite_iff {b S s t} :\n  (stmt.unless b S, s) \u27f9 t \u2194 (b s \u2227 s = t) \u2228 (\u00ac b s \u2227 (S, s) \u27f9 t) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases' h; cc },\n  { intro h,\n    cases' h; cases' h,\n    { cases' right,\n      apply big_step.unless_true,\n      assumption },\n    { apply big_step.unless_false; assumption } }\nend\n\n/- 2.2 (2 points). Prove the following inversion rule for the big-step\nsemantics of `repeat`. -/\n\nlemma big_step_repeat_iff {n S s u} :\n  (stmt.repeat n S, s) \u27f9 u \u2194\n  (n = 0 \u2227 u = s)\n  \u2228 (\u2203m t, n = m + 1 \u2227 (S, s) \u27f9 t \u2227 (stmt.repeat m S, t) \u27f9 u) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases' h,\n    case repeat_zero {\n      apply or.intro_left,\n      apply and.intro; refl },\n    case repeat_succ : m S t' t u hS hr {\n      apply or.intro_right,\n      apply exists.intro m,\n      apply exists.intro t,\n      repeat { apply and.intro },\n      { refl },\n      repeat { assumption } } },\n  { intro h,\n    cases' h,\n    case inl {\n      cases' h with hn hu,\n      cases' hn,\n      cases' hu,\n      apply big_step.repeat_zero },\n    case inr {\n      cases' h with m h,\n      cases' h with t h,\n      cases' h with hn h,\n      cases' h with hS hr,\n      rw hn,\n      rw \u2190nat.succ_eq_add_one,\n      exact big_step.repeat_succ hS hr } }\nend\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love08_operational_semantics_homework_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.7397224383152657}}
{"text": "/-\nCopyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying, Kevin Buzzard, Yury Kudryashov\n\n! This file was ported from Lean 3 source module algebra.big_operators.finprod\n! leanprover-community/mathlib commit 63f84d91dd847f50bae04a01071f3a5491934e36\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.BigOperators.Order\nimport Mathbin.Algebra.IndicatorFunction\n\n/-!\n# Finite products and sums over types and sets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define products and sums over types and subsets of types, with no finiteness hypotheses.\nAll infinite products and sums are defined to be junk values (i.e. one or zero).\nThis approach is sometimes easier to use than `finset.sum`,\nwhen issues arise with `finset` and `fintype` being data.\n\n## Main definitions\n\nWe use the following variables:\n\n* `\u03b1`, `\u03b2` - types with no structure;\n* `s`, `t` - sets\n* `M`, `N` - additive or multiplicative commutative monoids\n* `f`, `g` - functions\n\nDefinitions in this file:\n\n* `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite.\n   Zero otherwise.\n\n* `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if\n   it's finite. One otherwise.\n\n## Notation\n\n* `\u2211\u1da0 i, f i` and `\u2211\u1da0 i : \u03b1, f i` for `finsum f`\n\n* `\u220f\u1da0 i, f i` and `\u220f\u1da0 i : \u03b1, f i` for `finprod f`\n\nThis notation works for functions `f : p \u2192 M`, where `p : Prop`, so the following works:\n\n* `\u2211\u1da0 i \u2208 s, f i`, where `f : \u03b1 \u2192 M`, `s : set \u03b1` : sum over the set `s`;\n* `\u2211\u1da0 n < 5, f n`, where `f : \u2115 \u2192 M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`;\n* `\u220f\u1da0 (n >= -2) (hn : n < 3), f n`, where `f : \u2124 \u2192 M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`.\n\n## Implementation notes\n\n`finsum` and `finprod` is \"yet another way of doing finite sums and products in Lean\". However\nexperiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings\nwhere the user is not interested in computability and wants to do reasoning without running into\ntypeclass diamonds caused by the constructive finiteness used in definitions such as `finset` and\n`fintype`. By sticking solely to `set.finite` we avoid these problems. We are aware that there are\nother solutions but for beginner mathematicians this approach is easier in practice.\n\nAnother application is the construction of a partition of unity from a collection of \u201cbump\u201d\nfunction. In this case the finite set depends on the point and it's convenient to have a definition\nthat does not mention the set explicitly.\n\nThe first arguments in all definitions and lemmas is the codomain of the function of the big\noperator. This is necessary for the heuristic in `@[to_additive]`.\nSee the documentation of `to_additive.attr` for more information.\n\nWe did not add `is_finite (X : Type) : Prop`, because it is simply `nonempty (fintype X)`.\n\n## Tags\n\nfinsum, finprod, finite sum, finite product\n-/\n\n\nopen Function Set\n\n/-!\n### Definition and relation to `finset.sum` and `finset.prod`\n-/\n\n\nsection Sort\n\nvariable {G M N : Type _} {\u03b1 \u03b2 \u03b9 : Sort _} [CommMonoid M] [CommMonoid N]\n\nopen BigOperators\n\nsection\n\n/- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas\nwith `classical.dec` in their statement. -/\nopen Classical\n\n#print finsum /-\n/-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero\notherwise. -/\nnoncomputable irreducible_def finsum {M \u03b1} [AddCommMonoid M] (f : \u03b1 \u2192 M) : M :=\n  if h : (support (f \u2218 PLift.down)).Finite then \u2211 i in h.toFinset, f i.down else 0\n#align finsum finsum\n-/\n\n#print finprod /-\n/-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's\nfinite. One otherwise. -/\n@[to_additive]\nnoncomputable irreducible_def finprod (f : \u03b1 \u2192 M) : M :=\n  if h : (mulSupport (f \u2218 PLift.down)).Finite then \u220f i in h.toFinset, f i.down else 1\n#align finprod finprod\n#align finsum finsum\n-/\n\nend\n\n-- mathport name: finsum\nscoped[BigOperators] notation3\"\u2211\u1da0 \"(...)\", \"r:(scoped f => finsum f) => r\n\n-- mathport name: finprod\nscoped[BigOperators] notation3\"\u220f\u1da0 \"(...)\", \"r:(scoped f => finprod f) => r\n\n/- warning: finprod_eq_prod_plift_of_mul_support_to_finset_subset -> finprod_eq_prod_pLift_of_mulSupport_toFinset_subset is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} (hf : Set.Finite.{u2} (PLift.{u2} \u03b1) (Function.mulSupport.{u2, u1} (PLift.{u2} \u03b1) M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (Function.comp.{succ u2, u2, succ u1} (PLift.{u2} \u03b1) \u03b1 M f (PLift.down.{u2} \u03b1)))) {s : Finset.{u2} (PLift.{u2} \u03b1)}, (HasSubset.Subset.{u2} (Finset.{u2} (PLift.{u2} \u03b1)) (Finset.hasSubset.{u2} (PLift.{u2} \u03b1)) (Set.Finite.toFinset.{u2} (PLift.{u2} \u03b1) (Function.mulSupport.{u2, u1} (PLift.{u2} \u03b1) M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (Function.comp.{succ u2, u2, succ u1} (PLift.{u2} \u03b1) \u03b1 M f (PLift.down.{u2} \u03b1))) hf) s) -> (Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M (PLift.{u2} \u03b1) _inst_1 s (fun (i : PLift.{u2} \u03b1) => f (PLift.down.{u2} \u03b1 i))))\nbut is expected to have type\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} (hf : Set.Finite.{u2} (PLift.{u2} \u03b1) (Function.mulSupport.{u2, u1} (PLift.{u2} \u03b1) M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Function.comp.{succ u2, u2, succ u1} (PLift.{u2} \u03b1) \u03b1 M f (PLift.down.{u2} \u03b1)))) {s : Finset.{u2} (PLift.{u2} \u03b1)}, (HasSubset.Subset.{u2} (Finset.{u2} (PLift.{u2} \u03b1)) (Finset.instHasSubsetFinset.{u2} (PLift.{u2} \u03b1)) (Set.Finite.toFinset.{u2} (PLift.{u2} \u03b1) (Function.mulSupport.{u2, u1} (PLift.{u2} \u03b1) M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Function.comp.{succ u2, u2, succ u1} (PLift.{u2} \u03b1) \u03b1 M f (PLift.down.{u2} \u03b1))) hf) s) -> (Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M (PLift.{u2} \u03b1) _inst_1 s (fun (i : PLift.{u2} \u03b1) => f (PLift.down.{u2} \u03b1 i))))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_prod_plift_of_mul_support_to_finset_subset finprod_eq_prod_pLift_of_mulSupport_toFinset_subset\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_prod_pLift_of_mulSupport_toFinset_subset {f : \u03b1 \u2192 M}\n    (hf : (mulSupport (f \u2218 PLift.down)).Finite) {s : Finset (PLift \u03b1)} (hs : hf.toFinset \u2286 s) :\n    (\u220f\u1da0 i, f i) = \u220f i in s, f i.down :=\n  by\n  rw [finprod, dif_pos]\n  refine' Finset.prod_subset hs fun x hx hxf => _\n  rwa [hf.mem_to_finset, nmem_mul_support] at hxf\n#align finprod_eq_prod_plift_of_mul_support_to_finset_subset finprod_eq_prod_pLift_of_mulSupport_toFinset_subset\n#align finsum_eq_sum_plift_of_support_to_finset_subset finsum_eq_sum_pLift_of_support_toFinset_subset\n\n/- warning: finprod_eq_prod_plift_of_mul_support_subset -> finprod_eq_prod_pLift_of_mulSupport_subset is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Finset.{u2} (PLift.{u2} \u03b1)}, (HasSubset.Subset.{u2} (Set.{u2} (PLift.{u2} \u03b1)) (Set.hasSubset.{u2} (PLift.{u2} \u03b1)) (Function.mulSupport.{u2, u1} (PLift.{u2} \u03b1) M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (Function.comp.{succ u2, u2, succ u1} (PLift.{u2} \u03b1) \u03b1 M f (PLift.down.{u2} \u03b1))) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Finset.{u2} (PLift.{u2} \u03b1)) (Set.{u2} (PLift.{u2} \u03b1)) (HasLiftT.mk.{succ u2, succ u2} (Finset.{u2} (PLift.{u2} \u03b1)) (Set.{u2} (PLift.{u2} \u03b1)) (CoeTC\u2093.coe.{succ u2, succ u2} (Finset.{u2} (PLift.{u2} \u03b1)) (Set.{u2} (PLift.{u2} \u03b1)) (Finset.Set.hasCoeT.{u2} (PLift.{u2} \u03b1)))) s)) -> (Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M (PLift.{u2} \u03b1) _inst_1 s (fun (i : PLift.{u2} \u03b1) => f (PLift.down.{u2} \u03b1 i))))\nbut is expected to have type\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Finset.{u2} (PLift.{u2} \u03b1)}, (HasSubset.Subset.{u2} (Set.{u2} (PLift.{u2} \u03b1)) (Set.instHasSubsetSet.{u2} (PLift.{u2} \u03b1)) (Function.mulSupport.{u2, u1} (PLift.{u2} \u03b1) M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Function.comp.{succ u2, u2, succ u1} (PLift.{u2} \u03b1) \u03b1 M f (PLift.down.{u2} \u03b1))) (Finset.toSet.{u2} (PLift.{u2} \u03b1) s)) -> (Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M (PLift.{u2} \u03b1) _inst_1 s (fun (i : PLift.{u2} \u03b1) => f (PLift.down.{u2} \u03b1 i))))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_prod_plift_of_mul_support_subset finprod_eq_prod_pLift_of_mulSupport_subset\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_prod_pLift_of_mulSupport_subset {f : \u03b1 \u2192 M} {s : Finset (PLift \u03b1)}\n    (hs : mulSupport (f \u2218 PLift.down) \u2286 s) : (\u220f\u1da0 i, f i) = \u220f i in s, f i.down :=\n  finprod_eq_prod_pLift_of_mulSupport_toFinset_subset (s.finite_toSet.Subset hs) fun x hx =>\n    by\n    rw [finite.mem_to_finset] at hx\n    exact hs hx\n#align finprod_eq_prod_plift_of_mul_support_subset finprod_eq_prod_pLift_of_mulSupport_subset\n#align finsum_eq_sum_plift_of_support_subset finsum_eq_sum_pLift_of_support_subset\n\n/- warning: finprod_one -> finprod_one is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M], Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))))) (OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))))\nbut is expected to have type\n  forall {M : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_1 : CommMonoid.{u2} M], Eq.{succ u2} M (finprod.{u2, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))\nCase conversion may be inaccurate. Consider using '#align finprod_one finprod_one\u2093'. -/\n@[simp, to_additive]\ntheorem finprod_one : (\u220f\u1da0 i : \u03b1, (1 : M)) = 1 :=\n  by\n  have : (mul_support fun x : PLift \u03b1 => (fun _ => 1 : \u03b1 \u2192 M) x.down) \u2286 (\u2205 : Finset (PLift \u03b1)) :=\n    fun x h => h rfl\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset this, Finset.prod_empty]\n#align finprod_one finprod_one\n#align finsum_zero finsum_zero\n\n/- warning: finprod_of_is_empty -> finprod_of_isEmpty is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] [_inst_3 : IsEmpty.{u2} \u03b1] (f : \u03b1 -> M), Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))))\nbut is expected to have type\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] [_inst_3 : IsEmpty.{u2} \u03b1] (f : \u03b1 -> M), Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))\nCase conversion may be inaccurate. Consider using '#align finprod_of_is_empty finprod_of_isEmpty\u2093'. -/\n@[to_additive]\ntheorem finprod_of_isEmpty [IsEmpty \u03b1] (f : \u03b1 \u2192 M) : (\u220f\u1da0 i, f i) = 1 :=\n  by\n  rw [\u2190 finprod_one]\n  congr\n#align finprod_of_is_empty finprod_of_isEmpty\n#align finsum_of_is_empty finsum_of_isEmpty\n\n/- warning: finprod_false -> finprod_false is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : False -> M), Eq.{succ u1} M (finprod.{u1, 0} M False _inst_1 (fun (i : False) => f i)) (OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : False -> M), Eq.{succ u1} M (finprod.{u1, 0} M False _inst_1 (fun (i : False) => f i)) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))\nCase conversion may be inaccurate. Consider using '#align finprod_false finprod_false\u2093'. -/\n@[simp, to_additive]\ntheorem finprod_false (f : False \u2192 M) : (\u220f\u1da0 i, f i) = 1 :=\n  finprod_of_isEmpty _\n#align finprod_false finprod_false\n#align finsum_false finsum_false\n\n/- warning: finprod_eq_single -> finprod_eq_single is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (a : \u03b1), (forall (x : \u03b1), (Ne.{u2} \u03b1 x a) -> (Eq.{succ u1} M (f x) (OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))))) -> (Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (x : \u03b1) => f x)) (f a))\nbut is expected to have type\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (a : \u03b1), (forall (x : \u03b1), (Ne.{u2} \u03b1 x a) -> (Eq.{succ u1} M (f x) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))) -> (Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 (fun (x : \u03b1) => f x)) (f a))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_single finprod_eq_single\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (x \u00abexpr \u2260 \u00bb a) -/\n@[to_additive]\ntheorem finprod_eq_single (f : \u03b1 \u2192 M) (a : \u03b1) (ha : \u2200 (x) (_ : x \u2260 a), f x = 1) :\n    (\u220f\u1da0 x, f x) = f a :=\n  by\n  have : mul_support (f \u2218 PLift.down) \u2286 ({PLift.up a} : Finset (PLift \u03b1)) :=\n    by\n    intro x\n    contrapose\n    simpa [PLift.eq_up_iff_down_eq] using ha x.down\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset this, Finset.prod_singleton]\n#align finprod_eq_single finprod_eq_single\n#align finsum_eq_single finsum_eq_single\n\n#print finprod_unique /-\n@[to_additive]\ntheorem finprod_unique [Unique \u03b1] (f : \u03b1 \u2192 M) : (\u220f\u1da0 i, f i) = f default :=\n  finprod_eq_single f default fun x hx => (hx <| Unique.eq_default _).elim\n#align finprod_unique finprod_unique\n#align finsum_unique finsum_unique\n-/\n\n#print finprod_true /-\n@[simp, to_additive]\ntheorem finprod_true (f : True \u2192 M) : (\u220f\u1da0 i, f i) = f trivial :=\n  @finprod_unique M True _ \u27e8\u27e8trivial\u27e9, fun _ => rfl\u27e9 f\n#align finprod_true finprod_true\n#align finsum_true finsum_true\n-/\n\n/- warning: finprod_eq_dif -> finprod_eq_dif is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {p : Prop} [_inst_3 : Decidable p] (f : p -> M), Eq.{succ u1} M (finprod.{u1, 0} M p _inst_1 (fun (i : p) => f i)) (dite.{succ u1} M p _inst_3 (fun (h : p) => f h) (fun (h : Not p) => OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {p : Prop} [_inst_3 : Decidable p] (f : p -> M), Eq.{succ u1} M (finprod.{u1, 0} M p _inst_1 (fun (i : p) => f i)) (dite.{succ u1} M p _inst_3 (fun (h : p) => f h) (fun (h : Not p) => OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_dif finprod_eq_dif\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_dif {p : Prop} [Decidable p] (f : p \u2192 M) :\n    (\u220f\u1da0 i, f i) = if h : p then f h else 1 :=\n  by\n  split_ifs\n  \u00b7 haveI : Unique p := \u27e8\u27e8h\u27e9, fun _ => rfl\u27e9\n    exact finprod_unique f\n  \u00b7 haveI : IsEmpty p := \u27e8h\u27e9\n    exact finprod_of_isEmpty f\n#align finprod_eq_dif finprod_eq_dif\n#align finsum_eq_dif finsum_eq_dif\n\n/- warning: finprod_eq_if -> finprod_eq_if is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {p : Prop} [_inst_3 : Decidable p] {x : M}, Eq.{succ u1} M (finprod.{u1, 0} M p _inst_1 (fun (i : p) => x)) (ite.{succ u1} M p _inst_3 x (OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {p : Prop} [_inst_3 : Decidable p] {x : M}, Eq.{succ u1} M (finprod.{u1, 0} M p _inst_1 (fun (i : p) => x)) (ite.{succ u1} M p _inst_3 x (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_if finprod_eq_if\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : (\u220f\u1da0 i : p, x) = if p then x else 1 :=\n  finprod_eq_dif fun _ => x\n#align finprod_eq_if finprod_eq_if\n#align finsum_eq_if finsum_eq_if\n\n/- warning: finprod_congr -> finprod_congr is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b1 -> M}, (forall (x : \u03b1), Eq.{succ u1} M (f x) (g x)) -> (Eq.{succ u1} M (finprod.{u1, u2} M \u03b1 _inst_1 f) (finprod.{u1, u2} M \u03b1 _inst_1 g))\nbut is expected to have type\n  forall {M : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {g : \u03b1 -> M}, (forall (x : \u03b1), Eq.{succ u2} M (f x) (g x)) -> (Eq.{succ u2} M (finprod.{u2, u1} M \u03b1 _inst_1 f) (finprod.{u2, u1} M \u03b1 _inst_1 g))\nCase conversion may be inaccurate. Consider using '#align finprod_congr finprod_congr\u2093'. -/\n@[to_additive]\ntheorem finprod_congr {f g : \u03b1 \u2192 M} (h : \u2200 x, f x = g x) : finprod f = finprod g :=\n  congr_arg _ <| funext h\n#align finprod_congr finprod_congr\n#align finsum_congr finsum_congr\n\n#print finprod_congr_Prop /-\n@[congr, to_additive]\ntheorem finprod_congr_Prop {p q : Prop} {f : p \u2192 M} {g : q \u2192 M} (hpq : p = q)\n    (hfg : \u2200 h : q, f (hpq.mpr h) = g h) : finprod f = finprod g :=\n  by\n  subst q\n  exact finprod_congr hfg\n#align finprod_congr_Prop finprod_congr_Prop\n#align finsum_congr_Prop finsum_congr_Prop\n-/\n\nattribute [congr] finsum_congr_Prop\n\n/- warning: finprod_induction -> finprod_induction is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} (p : M -> Prop), (p (OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))))) -> (forall (x : M) (y : M), (p x) -> (p y) -> (p (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) x y))) -> (forall (i : \u03b1), p (f i)) -> (p (finprod.{u1, u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {M : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} (p : M -> Prop), (p (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))) -> (forall (x : M) (y : M), (p x) -> (p y) -> (p (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) x y))) -> (forall (i : \u03b1), p (f i)) -> (p (finprod.{u2, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_induction finprod_induction\u2093'. -/\n/-- To prove a property of a finite product, it suffices to prove that the property is\nmultiplicative and holds on the factors. -/\n@[to_additive\n      \"To prove a property of a finite sum, it suffices to prove that the property is\\nadditive and holds on the summands.\"]\ntheorem finprod_induction {f : \u03b1 \u2192 M} (p : M \u2192 Prop) (hp\u2080 : p 1)\n    (hp\u2081 : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (hp\u2082 : \u2200 i, p (f i)) : p (\u220f\u1da0 i, f i) :=\n  by\n  rw [finprod]\n  split_ifs\n  exacts[Finset.prod_induction _ _ hp\u2081 hp\u2080 fun i hi => hp\u2082 _, hp\u2080]\n#align finprod_induction finprod_induction\n#align finsum_induction finsum_induction\n\n/- warning: finprod_nonneg -> finprod_nonneg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Sort.{u1}} {R : Type.{u2}} [_inst_3 : OrderedCommSemiring.{u2} R] {f : \u03b1 -> R}, (forall (x : \u03b1), LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedAddCommMonoid.toPartialOrder.{u2} R (OrderedSemiring.toOrderedAddCommMonoid.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))) (OfNat.ofNat.{u2} R 0 (OfNat.mk.{u2} R 0 (Zero.zero.{u2} R (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (OrderedSemiring.toSemiring.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))))))) (f x)) -> (LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedAddCommMonoid.toPartialOrder.{u2} R (OrderedSemiring.toOrderedAddCommMonoid.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))) (OfNat.ofNat.{u2} R 0 (OfNat.mk.{u2} R 0 (Zero.zero.{u2} R (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (OrderedSemiring.toSemiring.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))))))) (finprod.{u2, u1} R \u03b1 (CommSemiring.toCommMonoid.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3)) (fun (x : \u03b1) => f x)))\nbut is expected to have type\n  forall {\u03b1 : Sort.{u1}} {R : Type.{u2}} [_inst_3 : OrderedCommSemiring.{u2} R] {f : \u03b1 -> R}, (forall (x : \u03b1), LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedSemiring.toPartialOrder.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3)))) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (CommMonoidWithZero.toZero.{u2} R (CommSemiring.toCommMonoidWithZero.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3))))) (f x)) -> (LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedSemiring.toPartialOrder.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3)))) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (CommMonoidWithZero.toZero.{u2} R (CommSemiring.toCommMonoidWithZero.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3))))) (finprod.{u2, u1} R \u03b1 (CommSemiring.toCommMonoid.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3)) (fun (x : \u03b1) => f x)))\nCase conversion may be inaccurate. Consider using '#align finprod_nonneg finprod_nonneg\u2093'. -/\ntheorem finprod_nonneg {R : Type _} [OrderedCommSemiring R] {f : \u03b1 \u2192 R} (hf : \u2200 x, 0 \u2264 f x) :\n    0 \u2264 \u220f\u1da0 x, f x :=\n  finprod_induction (fun x => 0 \u2264 x) zero_le_one (fun x y => mul_nonneg) hf\n#align finprod_nonneg finprod_nonneg\n\n/- warning: one_le_finprod' -> one_le_finprod' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Sort.{u1}} {M : Type.{u2}} [_inst_3 : OrderedCommMonoid.{u2} M] {f : \u03b1 -> M}, (forall (i : \u03b1), LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3))))))) (f i)) -> (LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3))))))) (finprod.{u2, u1} M \u03b1 (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3) (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Sort.{u1}} {M : Type.{u2}} [_inst_3 : OrderedCommMonoid.{u2} M] {f : \u03b1 -> M}, (forall (i : \u03b1), LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3))))) (f i)) -> (LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3))))) (finprod.{u2, u1} M \u03b1 (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3) (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align one_le_finprod' one_le_finprod'\u2093'. -/\n@[to_additive finsum_nonneg]\ntheorem one_le_finprod' {M : Type _} [OrderedCommMonoid M] {f : \u03b1 \u2192 M} (hf : \u2200 i, 1 \u2264 f i) :\n    1 \u2264 \u220f\u1da0 i, f i :=\n  finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf\n#align one_le_finprod' one_le_finprod'\n#align finsum_nonneg finsum_nonneg\n\n/- warning: monoid_hom.map_finprod_plift -> MonoidHom.map_finprod_pLift is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03b1 : Sort.{u3}} [_inst_1 : CommMonoid.{u1} M] [_inst_2 : CommMonoid.{u2} N] (f : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (g : \u03b1 -> M), (Set.Finite.{u3} (PLift.{u3} \u03b1) (Function.mulSupport.{u3, u1} (PLift.{u3} \u03b1) M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (Function.comp.{succ u3, u3, succ u1} (PLift.{u3} \u03b1) \u03b1 M g (PLift.down.{u3} \u03b1)))) -> (Eq.{succ u2} N (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f (finprod.{u1, u3} M \u03b1 _inst_1 (fun (x : \u03b1) => g x))) (finprod.{u2, u3} N \u03b1 _inst_2 (fun (x : \u03b1) => coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f (g x))))\nbut is expected to have type\n  forall {M : Type.{u3}} {N : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] (f : MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (g : \u03b1 -> M), (Set.Finite.{u1} (PLift.{u1} \u03b1) (Function.mulSupport.{u1, u3} (PLift.{u1} \u03b1) M (Monoid.toOne.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Function.comp.{succ u1, u1, succ u3} (PLift.{u1} \u03b1) \u03b1 M g (PLift.down.{u1} \u03b1)))) -> (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, u1} M \u03b1 _inst_1 (fun (x : \u03b1) => g x))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) f (finprod.{u3, u1} M \u03b1 _inst_1 (fun (x : \u03b1) => g x))) (finprod.{u2, u1} N \u03b1 _inst_2 (fun (x : \u03b1) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) f (g x))))\nCase conversion may be inaccurate. Consider using '#align monoid_hom.map_finprod_plift MonoidHom.map_finprod_pLift\u2093'. -/\n@[to_additive]\ntheorem MonoidHom.map_finprod_pLift (f : M \u2192* N) (g : \u03b1 \u2192 M)\n    (h : (mulSupport <| g \u2218 PLift.down).Finite) : f (\u220f\u1da0 x, g x) = \u220f\u1da0 x, f (g x) :=\n  by\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset h.coe_to_finset.ge,\n    finprod_eq_prod_pLift_of_mulSupport_subset, f.map_prod]\n  rw [h.coe_to_finset]\n  exact mul_support_comp_subset f.map_one (g \u2218 PLift.down)\n#align monoid_hom.map_finprod_plift MonoidHom.map_finprod_pLift\n#align add_monoid_hom.map_finsum_plift AddMonoidHom.map_finsum_pLift\n\n/- warning: monoid_hom.map_finprod_Prop -> MonoidHom.map_finprod_Prop is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} [_inst_1 : CommMonoid.{u1} M] [_inst_2 : CommMonoid.{u2} N] {p : Prop} (f : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (g : p -> M), Eq.{succ u2} N (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f (finprod.{u1, 0} M p _inst_1 (fun (x : p) => g x))) (finprod.{u2, 0} N p _inst_2 (fun (x : p) => coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f (g x)))\nbut is expected to have type\n  forall {M : Type.{u2}} {N : Type.{u1}} [_inst_1 : CommMonoid.{u2} M] [_inst_2 : CommMonoid.{u1} N] {p : Prop} (f : MonoidHom.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) (g : p -> M), Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u2, 0} M p _inst_1 (fun (x : p) => g x))) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (MonoidHom.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) M N (MulOneClass.toMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2)) (MonoidHom.monoidHomClass.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))))) f (finprod.{u2, 0} M p _inst_1 (fun (x : p) => g x))) (finprod.{u1, 0} N p _inst_2 (fun (x : p) => FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (MonoidHom.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) M N (MulOneClass.toMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2)) (MonoidHom.monoidHomClass.{u2, u1} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))))) f (g x)))\nCase conversion may be inaccurate. Consider using '#align monoid_hom.map_finprod_Prop MonoidHom.map_finprod_Prop\u2093'. -/\n@[to_additive]\ntheorem MonoidHom.map_finprod_Prop {p : Prop} (f : M \u2192* N) (g : p \u2192 M) :\n    f (\u220f\u1da0 x, g x) = \u220f\u1da0 x, f (g x) :=\n  f.map_finprod_pLift g (Set.toFinite _)\n#align monoid_hom.map_finprod_Prop MonoidHom.map_finprod_Prop\n#align add_monoid_hom.map_finsum_Prop AddMonoidHom.map_finsum_Prop\n\n/- warning: monoid_hom.map_finprod_of_preimage_one -> MonoidHom.map_finprod_of_preimage_one is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03b1 : Sort.{u3}} [_inst_1 : CommMonoid.{u1} M] [_inst_2 : CommMonoid.{u2} N] (f : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))), (forall (x : M), (Eq.{succ u2} N (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f x) (OfNat.ofNat.{u2} N 1 (OfNat.mk.{u2} N 1 (One.one.{u2} N (MulOneClass.toHasOne.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))))) -> (Eq.{succ u1} M x (OfNat.ofNat.{u1} M 1 (OfNat.mk.{u1} M 1 (One.one.{u1} M (MulOneClass.toHasOne.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))))) -> (forall (g : \u03b1 -> M), Eq.{succ u2} N (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f (finprod.{u1, u3} M \u03b1 _inst_1 (fun (i : \u03b1) => g i))) (finprod.{u2, u3} N \u03b1 _inst_2 (fun (i : \u03b1) => coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f (g i))))\nbut is expected to have type\n  forall {M : Type.{u3}} {N : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] (f : MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))), (forall (x : M), (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) x) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) f x) (OfNat.ofNat.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) x) 1 (One.toOfNat1.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) x) (Monoid.toOne.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) x) (CommMonoid.toMonoid.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) x) _inst_2))))) -> (Eq.{succ u3} M x (OfNat.ofNat.{u3} M 1 (One.toOfNat1.{u3} M (Monoid.toOne.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)))))) -> (forall (g : \u03b1 -> M), Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => g i))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) f (finprod.{u3, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => g i))) (finprod.{u2, u1} N \u03b1 _inst_2 (fun (i : \u03b1) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) f (g i))))\nCase conversion may be inaccurate. Consider using '#align monoid_hom.map_finprod_of_preimage_one MonoidHom.map_finprod_of_preimage_one\u2093'. -/\n@[to_additive]\ntheorem MonoidHom.map_finprod_of_preimage_one (f : M \u2192* N) (hf : \u2200 x, f x = 1 \u2192 x = 1) (g : \u03b1 \u2192 M) :\n    f (\u220f\u1da0 i, g i) = \u220f\u1da0 i, f (g i) :=\n  by\n  by_cases hg : (mul_support <| g \u2218 PLift.down).Finite; \u00b7 exact f.map_finprod_plift g hg\n  rw [finprod, dif_neg, f.map_one, finprod, dif_neg]\n  exacts[infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg]\n#align monoid_hom.map_finprod_of_preimage_one MonoidHom.map_finprod_of_preimage_one\n#align add_monoid_hom.map_finsum_of_preimage_zero AddMonoidHom.map_finsum_of_preimage_zero\n\n/- warning: monoid_hom.map_finprod_of_injective -> MonoidHom.map_finprod_of_injective is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03b1 : Sort.{u3}} [_inst_1 : CommMonoid.{u1} M] [_inst_2 : CommMonoid.{u2} N] (g : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))), (Function.Injective.{succ u1, succ u2} M N (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) g)) -> (forall (f : \u03b1 -> M), Eq.{succ u2} N (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) g (finprod.{u1, u3} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (finprod.{u2, u3} N \u03b1 _inst_2 (fun (i : \u03b1) => coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (fun (_x : MonoidHom.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u1, u2} M N (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) g (f i))))\nbut is expected to have type\n  forall {M : Type.{u3}} {N : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] (g : MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))), (Function.Injective.{succ u3, succ u2} M N (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g)) -> (forall (f : \u03b1 -> M), Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (finprod.{u3, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (finprod.{u2, u1} N \u03b1 _inst_2 (fun (i : \u03b1) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (f i))))\nCase conversion may be inaccurate. Consider using '#align monoid_hom.map_finprod_of_injective MonoidHom.map_finprod_of_injective\u2093'. -/\n@[to_additive]\ntheorem MonoidHom.map_finprod_of_injective (g : M \u2192* N) (hg : Injective g) (f : \u03b1 \u2192 M) :\n    g (\u220f\u1da0 i, f i) = \u220f\u1da0 i, g (f i) :=\n  g.map_finprod_of_preimage_one (fun x => (hg.eq_iff' g.map_one).mp) f\n#align monoid_hom.map_finprod_of_injective MonoidHom.map_finprod_of_injective\n#align add_monoid_hom.map_finsum_of_injective AddMonoidHom.map_finsum_of_injective\n\n/- warning: mul_equiv.map_finprod -> MulEquiv.map_finprod is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03b1 : Sort.{u3}} [_inst_1 : CommMonoid.{u1} M] [_inst_2 : CommMonoid.{u2} N] (g : MulEquiv.{u1, u2} M N (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (MulOneClass.toHasMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) (f : \u03b1 -> M), Eq.{succ u2} N (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (MulEquiv.{u1, u2} M N (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (MulOneClass.toHasMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) (fun (_x : MulEquiv.{u1, u2} M N (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (MulOneClass.toHasMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) => M -> N) (MulEquiv.hasCoeToFun.{u1, u2} M N (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (MulOneClass.toHasMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) g (finprod.{u1, u3} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (finprod.{u2, u3} N \u03b1 _inst_2 (fun (i : \u03b1) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (MulEquiv.{u1, u2} M N (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (MulOneClass.toHasMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) (fun (_x : MulEquiv.{u1, u2} M N (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (MulOneClass.toHasMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) => M -> N) (MulEquiv.hasCoeToFun.{u1, u2} M N (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (MulOneClass.toHasMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) g (f i)))\nbut is expected to have type\n  forall {M : Type.{u3}} {N : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] (g : MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) (f : \u03b1 -> M), Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquivClass.instMonoidHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquiv.instMulEquivClassMulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))))) g (finprod.{u3, u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (finprod.{u2, u1} N \u03b1 _inst_2 (fun (i : \u03b1) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquivClass.instMonoidHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquiv.instMulEquivClassMulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))))) g (f i)))\nCase conversion may be inaccurate. Consider using '#align mul_equiv.map_finprod MulEquiv.map_finprod\u2093'. -/\n@[to_additive]\ntheorem MulEquiv.map_finprod (g : M \u2243* N) (f : \u03b1 \u2192 M) : g (\u220f\u1da0 i, f i) = \u220f\u1da0 i, g (f i) :=\n  g.toMonoidHom.map_finprod_of_injective g.Injective f\n#align mul_equiv.map_finprod MulEquiv.map_finprod\n#align add_equiv.map_finsum AddEquiv.map_finsum\n\n/- warning: finsum_smul -> finsum_smul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Sort.{u1}} {R : Type.{u2}} {M : Type.{u3}} [_inst_3 : Ring.{u2} R] [_inst_4 : AddCommGroup.{u3} M] [_inst_5 : Module.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)] [_inst_6 : NoZeroSMulDivisors.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u2} R (NonAssocRing.toNonUnitalNonAssocRing.{u2} R (Ring.toNonAssocRing.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (SubNegMonoid.toAddMonoid.{u3} M (AddGroup.toSubNegMonoid.{u3} M (AddCommGroup.toAddGroup.{u3} M _inst_4))))) (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3)) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (Module.toMulActionWithZero.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) _inst_5))))] (f : \u03b9 -> R) (x : M), Eq.{succ u3} M (SMul.smul.{u2, u3} R M (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3)) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (Module.toMulActionWithZero.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) _inst_5)))) (finsum.{u2, u1} R \u03b9 (AddCommGroup.toAddCommMonoid.{u2} R (NonUnitalNonAssocRing.toAddCommGroup.{u2} R (NonAssocRing.toNonUnitalNonAssocRing.{u2} R (Ring.toNonAssocRing.{u2} R _inst_3)))) (fun (i : \u03b9) => f i)) x) (finsum.{u3, u1} M \u03b9 (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) (fun (i : \u03b9) => SMul.smul.{u2, u3} R M (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3)) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (Module.toMulActionWithZero.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) _inst_5)))) (f i) x))\nbut is expected to have type\n  forall {\u03b9 : Sort.{u1}} {R : Type.{u3}} {M : Type.{u2}} [_inst_3 : Ring.{u3} R] [_inst_4 : AddCommGroup.{u2} M] [_inst_5 : Module.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4)] [_inst_6 : NoZeroSMulDivisors.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulZeroClass.toSMul.{u3, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulWithZero.toSMulZeroClass.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (MulActionWithZero.toSMulWithZero.{u3, u2} R M (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (Module.toMulActionWithZero.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) _inst_5))))] (f : \u03b9 -> R) (x : M), Eq.{succ u2} M (HSMul.hSMul.{u3, u2, u2} R M M (instHSMul.{u3, u2} R M (SMulZeroClass.toSMul.{u3, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulWithZero.toSMulZeroClass.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (MulActionWithZero.toSMulWithZero.{u3, u2} R M (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (Module.toMulActionWithZero.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) _inst_5))))) (finsum.{u3, u1} R \u03b9 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u3} R (NonAssocRing.toNonUnitalNonAssocRing.{u3} R (Ring.toNonAssocRing.{u3} R _inst_3)))) (fun (i : \u03b9) => f i)) x) (finsum.{u2, u1} M \u03b9 (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) (fun (i : \u03b9) => HSMul.hSMul.{u3, u2, u2} R M M (instHSMul.{u3, u2} R M (SMulZeroClass.toSMul.{u3, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulWithZero.toSMulZeroClass.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (MulActionWithZero.toSMulWithZero.{u3, u2} R M (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (Module.toMulActionWithZero.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) _inst_5))))) (f i) x))\nCase conversion may be inaccurate. Consider using '#align finsum_smul finsum_smul\u2093'. -/\ntheorem finsum_smul {R M : Type _} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]\n    (f : \u03b9 \u2192 R) (x : M) : (\u2211\u1da0 i, f i) \u2022 x = \u2211\u1da0 i, f i \u2022 x :=\n  by\n  rcases eq_or_ne x 0 with (rfl | hx); \u00b7 simp\n  exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _\n#align finsum_smul finsum_smul\n\n/- warning: smul_finsum -> smul_finsum is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Sort.{u1}} {R : Type.{u2}} {M : Type.{u3}} [_inst_3 : Ring.{u2} R] [_inst_4 : AddCommGroup.{u3} M] [_inst_5 : Module.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)] [_inst_6 : NoZeroSMulDivisors.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u2} R (NonAssocRing.toNonUnitalNonAssocRing.{u2} R (Ring.toNonAssocRing.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (SubNegMonoid.toAddMonoid.{u3} M (AddGroup.toSubNegMonoid.{u3} M (AddCommGroup.toAddGroup.{u3} M _inst_4))))) (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3)) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (Module.toMulActionWithZero.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) _inst_5))))] (c : R) (f : \u03b9 -> M), Eq.{succ u3} M (SMul.smul.{u2, u3} R M (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3)) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (Module.toMulActionWithZero.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) _inst_5)))) c (finsum.{u3, u1} M \u03b9 (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) (fun (i : \u03b9) => f i))) (finsum.{u3, u1} M \u03b9 (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) (fun (i : \u03b9) => SMul.smul.{u2, u3} R M (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R (Ring.toSemiring.{u2} R _inst_3)) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (AddCommGroup.toAddCommMonoid.{u3} M _inst_4)))) (Module.toMulActionWithZero.{u2, u3} R M (Ring.toSemiring.{u2} R _inst_3) (AddCommGroup.toAddCommMonoid.{u3} M _inst_4) _inst_5)))) c (f i)))\nbut is expected to have type\n  forall {\u03b9 : Sort.{u1}} {R : Type.{u3}} {M : Type.{u2}} [_inst_3 : Ring.{u3} R] [_inst_4 : AddCommGroup.{u2} M] [_inst_5 : Module.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4)] [_inst_6 : NoZeroSMulDivisors.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulZeroClass.toSMul.{u3, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulWithZero.toSMulZeroClass.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (MulActionWithZero.toSMulWithZero.{u3, u2} R M (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (Module.toMulActionWithZero.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) _inst_5))))] (c : R) (f : \u03b9 -> M), Eq.{succ u2} M (HSMul.hSMul.{u3, u2, u2} R M M (instHSMul.{u3, u2} R M (SMulZeroClass.toSMul.{u3, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulWithZero.toSMulZeroClass.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (MulActionWithZero.toSMulWithZero.{u3, u2} R M (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (Module.toMulActionWithZero.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) _inst_5))))) c (finsum.{u2, u1} M \u03b9 (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) (fun (i : \u03b9) => f i))) (finsum.{u2, u1} M \u03b9 (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) (fun (i : \u03b9) => HSMul.hSMul.{u3, u2, u2} R M M (instHSMul.{u3, u2} R M (SMulZeroClass.toSMul.{u3, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (SMulWithZero.toSMulZeroClass.{u3, u2} R M (MonoidWithZero.toZero.{u3} R (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (MulActionWithZero.toSMulWithZero.{u3, u2} R M (Semiring.toMonoidWithZero.{u3} R (Ring.toSemiring.{u3} R _inst_3)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_4))))) (Module.toMulActionWithZero.{u3, u2} R M (Ring.toSemiring.{u3} R _inst_3) (AddCommGroup.toAddCommMonoid.{u2} M _inst_4) _inst_5))))) c (f i)))\nCase conversion may be inaccurate. Consider using '#align smul_finsum smul_finsum\u2093'. -/\ntheorem smul_finsum {R M : Type _} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]\n    (c : R) (f : \u03b9 \u2192 M) : (c \u2022 \u2211\u1da0 i, f i) = \u2211\u1da0 i, c \u2022 f i :=\n  by\n  rcases eq_or_ne c 0 with (rfl | hc); \u00b7 simp\n  exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _\n#align smul_finsum smul_finsum\n\n/- warning: finprod_inv_distrib -> finprod_inv_distrib is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} {\u03b1 : Sort.{u2}} [_inst_3 : DivisionCommMonoid.{u1} G] (f : \u03b1 -> G), Eq.{succ u1} G (finprod.{u1, u2} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u1} G _inst_3) (fun (x : \u03b1) => Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G (DivisionCommMonoid.toDivisionMonoid.{u1} G _inst_3))) (f x))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G (DivisionCommMonoid.toDivisionMonoid.{u1} G _inst_3))) (finprod.{u1, u2} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u1} G _inst_3) (fun (x : \u03b1) => f x)))\nbut is expected to have type\n  forall {G : Type.{u2}} {\u03b1 : Sort.{u1}} [_inst_3 : DivisionCommMonoid.{u2} G] (f : \u03b1 -> G), Eq.{succ u2} G (finprod.{u2, u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (x : \u03b1) => Inv.inv.{u2} G (InvOneClass.toInv.{u2} G (DivInvOneMonoid.toInvOneClass.{u2} G (DivisionMonoid.toDivInvOneMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (f x))) (Inv.inv.{u2} G (InvOneClass.toInv.{u2} G (DivInvOneMonoid.toInvOneClass.{u2} G (DivisionMonoid.toDivInvOneMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (finprod.{u2, u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (x : \u03b1) => f x)))\nCase conversion may be inaccurate. Consider using '#align finprod_inv_distrib finprod_inv_distrib\u2093'. -/\n@[to_additive]\ntheorem finprod_inv_distrib [DivisionCommMonoid G] (f : \u03b1 \u2192 G) : (\u220f\u1da0 x, (f x)\u207b\u00b9) = (\u220f\u1da0 x, f x)\u207b\u00b9 :=\n  ((MulEquiv.inv G).map_finprod f).symm\n#align finprod_inv_distrib finprod_inv_distrib\n#align finsum_neg_distrib finsum_neg_distrib\n\nend Sort\n\nsection Type\n\nvariable {\u03b1 \u03b2 \u03b9 G M N : Type _} [CommMonoid M] [CommMonoid N]\n\nopen BigOperators\n\n/- warning: finprod_eq_mul_indicator_apply -> finprod_eq_mulIndicator_apply is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (s : Set.{u1} \u03b1) (f : \u03b1 -> M) (a : \u03b1), Eq.{succ u2} M (finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) _inst_1 (fun (h : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) => f a)) (Set.mulIndicator.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) s f a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (s : Set.{u2} \u03b1) (f : \u03b1 -> M) (a : \u03b1), Eq.{succ u1} M (finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) _inst_1 (fun (h : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) => f a)) (Set.mulIndicator.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) s f a)\nCase conversion may be inaccurate. Consider using '#align finprod_eq_mul_indicator_apply finprod_eq_mulIndicator_apply\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_mulIndicator_apply (s : Set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n    (\u220f\u1da0 h : a \u2208 s, f a) = mulIndicator s f a := by convert finprod_eq_if\n#align finprod_eq_mul_indicator_apply finprod_eq_mulIndicator_apply\n#align finsum_eq_indicator_apply finsum_eq_indicator_apply\n\n/- warning: finprod_mem_mul_support -> finprod_mem_mulSupport is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (a : \u03b1), Eq.{succ u2} M (finprod.{u2, 0} M (Ne.{succ u2} M (f a) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) _inst_1 (fun (h : Ne.{succ u2} M (f a) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) => f a)) (f a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (a : \u03b1), Eq.{succ u1} M (finprod.{u1, 0} M (Ne.{succ u1} M (f a) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))) _inst_1 (fun (h : Ne.{succ u1} M (f a) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))) => f a)) (f a)\nCase conversion may be inaccurate. Consider using '#align finprod_mem_mul_support finprod_mem_mulSupport\u2093'. -/\n@[simp, to_additive]\ntheorem finprod_mem_mulSupport (f : \u03b1 \u2192 M) (a : \u03b1) : (\u220f\u1da0 h : f a \u2260 1, f a) = f a := by\n  rw [\u2190 mem_mul_support, finprod_eq_mulIndicator_apply, mul_indicator_mul_support]\n#align finprod_mem_mul_support finprod_mem_mulSupport\n#align finsum_mem_support finsum_mem_support\n\n/- warning: finprod_mem_def -> finprod_mem_def is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (s : Set.{u1} \u03b1) (f : \u03b1 -> M), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) => f a))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => Set.mulIndicator.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) s f a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (s : Set.{u2} \u03b1) (f : \u03b1 -> M), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) => f a))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => Set.mulIndicator.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) s f a))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_def finprod_mem_def\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_def (s : Set \u03b1) (f : \u03b1 \u2192 M) : (\u220f\u1da0 a \u2208 s, f a) = \u220f\u1da0 a, mulIndicator s f a :=\n  finprod_congr <| finprod_eq_mulIndicator_apply s f\n#align finprod_mem_def finprod_mem_def\n#align finsum_mem_def finsum_mem_def\n\n/- warning: finprod_eq_prod_of_mul_support_subset -> finprod_eq_prod_of_mulSupport_subset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) {s : Finset.{u1} \u03b1}, (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (Finset.Set.hasCoeT.{u1} \u03b1))) s)) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u2, u1} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) {s : Finset.{u2} \u03b1}, (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f) (Finset.toSet.{u2} \u03b1 s)) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_prod_of_mul_support_subset finprod_eq_prod_of_mulSupport_subset\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_prod_of_mulSupport_subset (f : \u03b1 \u2192 M) {s : Finset \u03b1} (h : mulSupport f \u2286 s) :\n    (\u220f\u1da0 i, f i) = \u220f i in s, f i :=\n  by\n  have A : mul_support (f \u2218 PLift.down) = equiv.plift.symm '' mul_support f :=\n    by\n    rw [mul_support_comp_eq_preimage]\n    exact (equiv.plift.symm.image_eq_preimage _).symm\n  have : mul_support (f \u2218 PLift.down) \u2286 s.map equiv.plift.symm.to_embedding :=\n    by\n    rw [A, Finset.coe_map]\n    exact image_subset _ h\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset this]\n  simp\n#align finprod_eq_prod_of_mul_support_subset finprod_eq_prod_of_mulSupport_subset\n#align finsum_eq_sum_of_support_subset finsum_eq_sum_of_support_subset\n\n/- warning: finprod_eq_prod_of_mul_support_to_finset_subset -> finprod_eq_prod_of_mulSupport_toFinset_subset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (hf : Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) {s : Finset.{u1} \u03b1}, (HasSubset.Subset.{u1} (Finset.{u1} \u03b1) (Finset.hasSubset.{u1} \u03b1) (Set.Finite.toFinset.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f) hf) s) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u2, u1} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (hf : Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) {s : Finset.{u2} \u03b1}, (HasSubset.Subset.{u2} (Finset.{u2} \u03b1) (Finset.instHasSubsetFinset.{u2} \u03b1) (Set.Finite.toFinset.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f) hf) s) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_prod_of_mul_support_to_finset_subset finprod_eq_prod_of_mulSupport_toFinset_subset\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : \u03b1 \u2192 M) (hf : (mulSupport f).Finite)\n    {s : Finset \u03b1} (h : hf.toFinset \u2286 s) : (\u220f\u1da0 i, f i) = \u220f i in s, f i :=\n  finprod_eq_prod_of_mulSupport_subset _ fun x hx => h <| hf.mem_toFinset.2 hx\n#align finprod_eq_prod_of_mul_support_to_finset_subset finprod_eq_prod_of_mulSupport_toFinset_subset\n#align finsum_eq_sum_of_support_to_finset_subset finsum_eq_sum_of_support_toFinset_subset\n\n/- warning: finprod_eq_finset_prod_of_mul_support_subset -> finprod_eq_finset_prod_of_mulSupport_subset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) {s : Finset.{u1} \u03b1}, (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (Finset.Set.hasCoeT.{u1} \u03b1))) s)) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u2, u1} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) {s : Finset.{u2} \u03b1}, (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f) (Finset.toSet.{u2} \u03b1 s)) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_finset_prod_of_mul_support_subset finprod_eq_finset_prod_of_mulSupport_subset\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_finset_prod_of_mulSupport_subset (f : \u03b1 \u2192 M) {s : Finset \u03b1}\n    (h : mulSupport f \u2286 (s : Set \u03b1)) : (\u220f\u1da0 i, f i) = \u220f i in s, f i :=\n  haveI h' : (s.finite_to_set.subset h).toFinset \u2286 s := by\n    simpa [\u2190 Finset.coe_subset, Set.coe_toFinset]\n  finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h'\n#align finprod_eq_finset_prod_of_mul_support_subset finprod_eq_finset_prod_of_mulSupport_subset\n#align finsum_eq_finset_sum_of_support_subset finsum_eq_finset_sum_of_support_subset\n\n/- warning: finprod_def -> finprod_def is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) [_inst_3 : Decidable (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))], Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (dite.{succ u2} M (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) _inst_3 (fun (h : Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) => Finset.prod.{u2, u1} M \u03b1 _inst_1 (Set.Finite.toFinset.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f) h) (fun (i : \u03b1) => f i)) (fun (h : Not (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) => OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) [_inst_3 : Decidable (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))], Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (dite.{succ u1} M (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) _inst_3 (fun (h : Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) => Finset.prod.{u1, u2} M \u03b1 _inst_1 (Set.Finite.toFinset.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f) h) (fun (i : \u03b1) => f i)) (fun (h : Not (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) => OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_def finprod_def\u2093'. -/\n@[to_additive]\ntheorem finprod_def (f : \u03b1 \u2192 M) [Decidable (mulSupport f).Finite] :\n    (\u220f\u1da0 i : \u03b1, f i) = if h : (mulSupport f).Finite then \u220f i in h.toFinset, f i else 1 :=\n  by\n  split_ifs\n  \u00b7 exact finprod_eq_prod_of_mulSupport_toFinset_subset _ h (Finset.Subset.refl _)\n  \u00b7 rw [finprod, dif_neg]\n    rw [mul_support_comp_eq_preimage]\n    exact mt (fun hf => hf.of_preimage equiv.plift.surjective) h\n#align finprod_def finprod_def\n#align finsum_def finsum_def\n\n/- warning: finprod_of_infinite_mul_support -> finprod_of_infinite_mulSupport is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M}, (Set.Infinite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M}, (Set.Infinite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_of_infinite_mul_support finprod_of_infinite_mulSupport\u2093'. -/\n@[to_additive]\ntheorem finprod_of_infinite_mulSupport {f : \u03b1 \u2192 M} (hf : (mulSupport f).Infinite) :\n    (\u220f\u1da0 i, f i) = 1 := by classical rw [finprod_def, dif_neg hf]\n#align finprod_of_infinite_mul_support finprod_of_infinite_mulSupport\n#align finsum_of_infinite_support finsum_of_infinite_support\n\n/- warning: finprod_eq_prod -> finprod_eq_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (hf : Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u2, u1} M \u03b1 _inst_1 (Set.Finite.toFinset.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f) hf) (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (hf : Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M \u03b1 _inst_1 (Set.Finite.toFinset.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f) hf) (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_prod finprod_eq_prod\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_prod (f : \u03b1 \u2192 M) (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 i : \u03b1, f i) = \u220f i in hf.toFinset, f i := by classical rw [finprod_def, dif_pos hf]\n#align finprod_eq_prod finprod_eq_prod\n#align finsum_eq_sum finsum_eq_sum\n\n/- warning: finprod_eq_prod_of_fintype -> finprod_eq_prod_of_fintype is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] [_inst_3 : Fintype.{u1} \u03b1] (f : \u03b1 -> M), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u2, u1} M \u03b1 _inst_1 (Finset.univ.{u1} \u03b1 _inst_3) (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] [_inst_3 : Fintype.{u2} \u03b1] (f : \u03b1 -> M), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (Finset.prod.{u1, u2} M \u03b1 _inst_1 (Finset.univ.{u2} \u03b1 _inst_3) (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_prod_of_fintype finprod_eq_prod_of_fintype\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_prod_of_fintype [Fintype \u03b1] (f : \u03b1 \u2192 M) : (\u220f\u1da0 i : \u03b1, f i) = \u220f i, f i :=\n  finprod_eq_prod_of_mulSupport_toFinset_subset _ (Set.toFinite _) <| Finset.subset_univ _\n#align finprod_eq_prod_of_fintype finprod_eq_prod_of_fintype\n#align finsum_eq_sum_of_fintype finsum_eq_sum_of_fintype\n\n/- warning: finprod_cond_eq_prod_of_cond_iff -> finprod_cond_eq_prod_of_cond_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) {p : \u03b1 -> Prop} {t : Finset.{u1} \u03b1}, (forall {x : \u03b1}, (Ne.{succ u2} M (f x) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) -> (Iff (p x) (Membership.Mem.{u1, u1} \u03b1 (Finset.{u1} \u03b1) (Finset.hasMem.{u1} \u03b1) x t))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (p i) _inst_1 (fun (hi : p i) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 t (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) {p : \u03b1 -> Prop} {t : Finset.{u2} \u03b1}, (forall {x : \u03b1}, (Ne.{succ u1} M (f x) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))) -> (Iff (p x) (Membership.mem.{u2, u2} \u03b1 (Finset.{u2} \u03b1) (Finset.instMembershipFinset.{u2} \u03b1) x t))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (p i) _inst_1 (fun (hi : p i) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 t (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_cond_eq_prod_of_cond_iff finprod_cond_eq_prod_of_cond_iff\u2093'. -/\n@[to_additive]\ntheorem finprod_cond_eq_prod_of_cond_iff (f : \u03b1 \u2192 M) {p : \u03b1 \u2192 Prop} {t : Finset \u03b1}\n    (h : \u2200 {x}, f x \u2260 1 \u2192 (p x \u2194 x \u2208 t)) : (\u220f\u1da0 (i) (hi : p i), f i) = \u220f i in t, f i :=\n  by\n  set s := { x | p x }\n  have : mul_support (s.mul_indicator f) \u2286 t :=\n    by\n    rw [Set.mulSupport_mulIndicator]\n    intro x hx\n    exact (h hx.2).1 hx.1\n  erw [finprod_mem_def, finprod_eq_prod_of_mulSupport_subset _ this]\n  refine' Finset.prod_congr rfl fun x hx => mul_indicator_apply_eq_self.2 fun hxs => _\n  contrapose! hxs\n  exact (h hxs).2 hx\n#align finprod_cond_eq_prod_of_cond_iff finprod_cond_eq_prod_of_cond_iff\n#align finsum_cond_eq_sum_of_cond_iff finsum_cond_eq_sum_of_cond_iff\n\n/- warning: finprod_cond_ne -> finprod_cond_ne is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (a : \u03b1) [_inst_3 : DecidableEq.{succ u1} \u03b1] (hf : Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Ne.{succ u1} \u03b1 i a) _inst_1 (fun (H : Ne.{succ u1} \u03b1 i a) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 (Finset.erase.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_3 a b) (Set.Finite.toFinset.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f) hf) a) (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (a : \u03b1) [_inst_3 : DecidableEq.{succ u2} \u03b1] (hf : Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Ne.{succ u2} \u03b1 i a) _inst_1 (fun (H : Ne.{succ u2} \u03b1 i a) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 (Finset.erase.{u2} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_3 a b) (Set.Finite.toFinset.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f) hf) a) (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_cond_ne finprod_cond_ne\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (i \u00abexpr \u2260 \u00bb a) -/\n@[to_additive]\ntheorem finprod_cond_ne (f : \u03b1 \u2192 M) (a : \u03b1) [DecidableEq \u03b1] (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 (i) (_ : i \u2260 a), f i) = \u220f i in hf.toFinset.erase\u2093 a, f i :=\n  by\n  apply finprod_cond_eq_prod_of_cond_iff\n  intro x hx\n  rw [Finset.mem_erase, finite.mem_to_finset, mem_mul_support]\n  exact \u27e8fun h => And.intro h hx, fun h => h.1\u27e9\n#align finprod_cond_ne finprod_cond_ne\n#align finsum_cond_ne finsum_cond_ne\n\n/- warning: finprod_mem_eq_prod_of_inter_mul_support_eq -> finprod_mem_eq_prod_of_inter_mulSupport_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) {s : Set.{u1} \u03b1} {t : Finset.{u1} \u03b1}, (Eq.{succ u1} (Set.{u1} \u03b1) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (Finset.Set.hasCoeT.{u1} \u03b1))) t) (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 t (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) {s : Set.{u2} \u03b1} {t : Finset.{u2} \u03b1}, (Eq.{succ u2} (Set.{u2} \u03b1) (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) (Finset.toSet.{u2} \u03b1 t) (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 t (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_prod_of_inter_mul_support_eq finprod_mem_eq_prod_of_inter_mulSupport_eq\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_prod_of_inter_mulSupport_eq (f : \u03b1 \u2192 M) {s : Set \u03b1} {t : Finset \u03b1}\n    (h : s \u2229 mulSupport f = t \u2229 mulSupport f) : (\u220f\u1da0 i \u2208 s, f i) = \u220f i in t, f i :=\n  finprod_cond_eq_prod_of_cond_iff _ <| by simpa [Set.ext_iff] using h\n#align finprod_mem_eq_prod_of_inter_mul_support_eq finprod_mem_eq_prod_of_inter_mulSupport_eq\n#align finsum_mem_eq_sum_of_inter_support_eq finsum_mem_eq_sum_of_inter_support_eq\n\n/- warning: finprod_mem_eq_prod_of_subset -> finprod_mem_eq_prod_of_subset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) {s : Set.{u1} \u03b1} {t : Finset.{u1} \u03b1}, (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (Finset.Set.hasCoeT.{u1} \u03b1))) t)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (Finset.Set.hasCoeT.{u1} \u03b1))) t) s) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 t (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) {s : Set.{u2} \u03b1} {t : Finset.{u2} \u03b1}, (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) (Finset.toSet.{u2} \u03b1 t)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Finset.toSet.{u2} \u03b1 t) s) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 t (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_prod_of_subset finprod_mem_eq_prod_of_subset\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_prod_of_subset (f : \u03b1 \u2192 M) {s : Set \u03b1} {t : Finset \u03b1}\n    (h\u2081 : s \u2229 mulSupport f \u2286 t) (h\u2082 : \u2191t \u2286 s) : (\u220f\u1da0 i \u2208 s, f i) = \u220f i in t, f i :=\n  finprod_cond_eq_prod_of_cond_iff _ fun x hx => \u27e8fun h => h\u2081 \u27e8h, hx\u27e9, fun h => h\u2082 h\u27e9\n#align finprod_mem_eq_prod_of_subset finprod_mem_eq_prod_of_subset\n#align finsum_mem_eq_sum_of_subset finsum_mem_eq_sum_of_subset\n\n/- warning: finprod_mem_eq_prod -> finprod_mem_eq_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) {s : Set.{u1} \u03b1} (hf : Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 (Set.Finite.toFinset.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) hf) (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) {s : Set.{u2} \u03b1} (hf : Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 (Set.Finite.toFinset.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) hf) (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_prod finprod_mem_eq_prod\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_prod (f : \u03b1 \u2192 M) {s : Set \u03b1} (hf : (s \u2229 mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in hf.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp [inter_assoc]\n#align finprod_mem_eq_prod finprod_mem_eq_prod\n#align finsum_mem_eq_sum finsum_mem_eq_sum\n\n/- warning: finprod_mem_eq_prod_filter -> finprod_mem_eq_prod_filter is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (s : Set.{u1} \u03b1) [_inst_3 : DecidablePred.{succ u1} \u03b1 (fun (_x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) _x s)] (hf : Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 (Finset.filter.{u1} \u03b1 (fun (_x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) _x s) (fun (a : \u03b1) => _inst_3 a) (Set.Finite.toFinset.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f) hf)) (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (s : Set.{u2} \u03b1) [_inst_3 : DecidablePred.{succ u2} \u03b1 (fun (_x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) _x s)] (hf : Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 (Finset.filter.{u2} \u03b1 (fun (_x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) _x s) (fun (a : \u03b1) => _inst_3 a) (Set.Finite.toFinset.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f) hf)) (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_prod_filter finprod_mem_eq_prod_filter\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_prod_filter (f : \u03b1 \u2192 M) (s : Set \u03b1) [DecidablePred (\u00b7 \u2208 s)]\n    (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in Finset.filter (\u00b7 \u2208 s) hf.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp [inter_comm, inter_left_comm]\n#align finprod_mem_eq_prod_filter finprod_mem_eq_prod_filter\n#align finsum_mem_eq_sum_filter finsum_mem_eq_sum_filter\n\n/- warning: finprod_mem_eq_to_finset_prod -> finprod_mem_eq_toFinset_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (s : Set.{u1} \u03b1) [_inst_3 : Fintype.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s)], Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 (Set.toFinset.{u1} \u03b1 s _inst_3) (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (s : Set.{u2} \u03b1) [_inst_3 : Fintype.{u2} (Set.Elem.{u2} \u03b1 s)], Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 (Set.toFinset.{u2} \u03b1 s _inst_3) (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_to_finset_prod finprod_mem_eq_toFinset_prod\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_toFinset_prod (f : \u03b1 \u2192 M) (s : Set \u03b1) [Fintype s] :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in s.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by rw [coe_to_finset]\n#align finprod_mem_eq_to_finset_prod finprod_mem_eq_toFinset_prod\n#align finsum_mem_eq_to_finset_sum finsum_mem_eq_toFinset_sum\n\n/- warning: finprod_mem_eq_finite_to_finset_prod -> finprod_mem_eq_finite_toFinset_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) {s : Set.{u1} \u03b1} (hs : Set.Finite.{u1} \u03b1 s), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 (Set.Finite.toFinset.{u1} \u03b1 s hs) (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) {s : Set.{u2} \u03b1} (hs : Set.Finite.{u2} \u03b1 s), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 (Set.Finite.toFinset.{u2} \u03b1 s hs) (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_finite_to_finset_prod finprod_mem_eq_finite_toFinset_prod\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_finite_toFinset_prod (f : \u03b1 \u2192 M) {s : Set \u03b1} (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in hs.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by rw [hs.coe_to_finset]\n#align finprod_mem_eq_finite_to_finset_prod finprod_mem_eq_finite_toFinset_prod\n#align finsum_mem_eq_finite_to_finset_sum finsum_mem_eq_finite_toFinset_sum\n\n/- warning: finprod_mem_finset_eq_prod -> finprod_mem_finset_eq_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (s : Finset.{u1} \u03b1), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Finset.{u1} \u03b1) (Finset.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Finset.{u1} \u03b1) (Finset.hasMem.{u1} \u03b1) i s) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (s : Finset.{u2} \u03b1), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Finset.{u2} \u03b1) (Finset.instMembershipFinset.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Finset.{u2} \u03b1) (Finset.instMembershipFinset.{u2} \u03b1) i s) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_finset_eq_prod finprod_mem_finset_eq_prod\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_finset_eq_prod (f : \u03b1 \u2192 M) (s : Finset \u03b1) : (\u220f\u1da0 i \u2208 s, f i) = \u220f i in s, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl\n#align finprod_mem_finset_eq_prod finprod_mem_finset_eq_prod\n#align finsum_mem_finset_eq_sum finsum_mem_finset_eq_sum\n\n/- warning: finprod_mem_coe_finset -> finprod_mem_coe_finset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (s : Finset.{u1} \u03b1), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (Finset.Set.hasCoeT.{u1} \u03b1))) s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (Finset.{u1} \u03b1) (Set.{u1} \u03b1) (Finset.Set.hasCoeT.{u1} \u03b1))) s)) => f i))) (Finset.prod.{u2, u1} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (s : Finset.{u2} \u03b1), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Finset.toSet.{u2} \u03b1 s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Finset.toSet.{u2} \u03b1 s)) => f i))) (Finset.prod.{u1, u2} M \u03b1 _inst_1 s (fun (i : \u03b1) => f i))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_coe_finset finprod_mem_coe_finset\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_coe_finset (f : \u03b1 \u2192 M) (s : Finset \u03b1) :\n    (\u220f\u1da0 i \u2208 (s : Set \u03b1), f i) = \u220f i in s, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl\n#align finprod_mem_coe_finset finprod_mem_coe_finset\n#align finsum_mem_coe_finset finsum_mem_coe_finset\n\n/- warning: finprod_mem_eq_one_of_infinite -> finprod_mem_eq_one_of_infinite is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Set.Infinite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1}, (Set.Infinite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_one_of_infinite finprod_mem_eq_one_of_infinite\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_one_of_infinite {f : \u03b1 \u2192 M} {s : Set \u03b1} (hs : (s \u2229 mulSupport f).Infinite) :\n    (\u220f\u1da0 i \u2208 s, f i) = 1 := by\n  rw [finprod_mem_def]\n  apply finprod_of_infinite_mulSupport\n  rwa [\u2190 mul_support_mul_indicator] at hs\n#align finprod_mem_eq_one_of_infinite finprod_mem_eq_one_of_infinite\n#align finsum_mem_eq_zero_of_infinite finsum_mem_eq_zero_of_infinite\n\n/- warning: finprod_mem_eq_one_of_forall_eq_one -> finprod_mem_eq_one_of_forall_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1}, (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) -> (Eq.{succ u2} M (f x) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1}, (forall (x : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) -> (Eq.{succ u1} M (f x) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_one_of_forall_eq_one finprod_mem_eq_one_of_forall_eq_one\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_eq_one_of_forall_eq_one {f : \u03b1 \u2192 M} {s : Set \u03b1} (h : \u2200 x \u2208 s, f x = 1) :\n    (\u220f\u1da0 i \u2208 s, f i) = 1 := by simp (config := { contextual := true }) [h]\n#align finprod_mem_eq_one_of_forall_eq_one finprod_mem_eq_one_of_forall_eq_one\n#align finsum_mem_eq_zero_of_forall_eq_zero finsum_mem_eq_zero_of_forall_eq_zero\n\n/- warning: finprod_mem_inter_mul_support -> finprod_mem_inter_mulSupport is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (s : Set.{u1} \u03b1), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (s : Set.{u2} \u03b1), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_inter_mul_support finprod_mem_inter_mulSupport\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_inter_mulSupport (f : \u03b1 \u2192 M) (s : Set \u03b1) :\n    (\u220f\u1da0 i \u2208 s \u2229 mulSupport f, f i) = \u220f\u1da0 i \u2208 s, f i := by\n  rw [finprod_mem_def, finprod_mem_def, mul_indicator_inter_mul_support]\n#align finprod_mem_inter_mul_support finprod_mem_inter_mulSupport\n#align finsum_mem_inter_support finsum_mem_inter_support\n\n/- warning: finprod_mem_inter_mul_support_eq -> finprod_mem_inter_mulSupport_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (s : Set.{u1} \u03b1) (t : Set.{u1} \u03b1), (Eq.{succ u1} (Set.{u1} \u03b1) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) t (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (s : Set.{u2} \u03b1) (t : Set.{u2} \u03b1), (Eq.{succ u2} (Set.{u2} \u03b1) (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) t (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_inter_mul_support_eq finprod_mem_inter_mulSupport_eq\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_inter_mulSupport_eq (f : \u03b1 \u2192 M) (s t : Set \u03b1)\n    (h : s \u2229 mulSupport f = t \u2229 mulSupport f) : (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_inter_mulSupport, h, finprod_mem_inter_mulSupport]\n#align finprod_mem_inter_mul_support_eq finprod_mem_inter_mulSupport_eq\n#align finsum_mem_inter_support_eq finsum_mem_inter_support_eq\n\n/- warning: finprod_mem_inter_mul_support_eq' -> finprod_mem_inter_mulSupport_eq' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (f : \u03b1 -> M) (s : Set.{u1} \u03b1) (t : Set.{u1} \u03b1), (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) -> (Iff (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x t))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : \u03b1 -> M) (s : Set.{u2} \u03b1) (t : Set.{u2} \u03b1), (forall (x : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) -> (Iff (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x t))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_inter_mul_support_eq' finprod_mem_inter_mulSupport_eq'\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_inter_mulSupport_eq' (f : \u03b1 \u2192 M) (s t : Set \u03b1)\n    (h : \u2200 x \u2208 mulSupport f, x \u2208 s \u2194 x \u2208 t) : (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 t, f i :=\n  by\n  apply finprod_mem_inter_mulSupport_eq\n  ext x\n  exact and_congr_left (h x)\n#align finprod_mem_inter_mul_support_eq' finprod_mem_inter_mulSupport_eq'\n#align finsum_mem_inter_support_eq' finsum_mem_inter_support_eq'\n\n#print finprod_mem_univ /-\n@[to_additive]\ntheorem finprod_mem_univ (f : \u03b1 \u2192 M) : (\u220f\u1da0 i \u2208 @Set.univ \u03b1, f i) = \u220f\u1da0 i : \u03b1, f i :=\n  finprod_congr fun i => finprod_true _\n#align finprod_mem_univ finprod_mem_univ\n#align finsum_mem_univ finsum_mem_univ\n-/\n\nvariable {f g : \u03b1 \u2192 M} {a b : \u03b1} {s t : Set \u03b1}\n\n/- warning: finprod_mem_congr -> finprod_mem_congr is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {g : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Eq.{succ u1} (Set.{u1} \u03b1) s t) -> (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x t) -> (Eq.{succ u2} M (f x) (g x))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => g i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (Eq.{succ u2} (Set.{u2} \u03b1) s t) -> (forall (x : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x t) -> (Eq.{succ u1} M (f x) (g x))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => g i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_congr finprod_mem_congr\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_congr (h\u2080 : s = t) (h\u2081 : \u2200 x \u2208 t, f x = g x) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 t, g i :=\n  h\u2080.symm \u25b8 finprod_congr fun i => finprod_congr_Prop rfl (h\u2081 i)\n#align finprod_mem_congr finprod_mem_congr\n#align finsum_mem_congr finsum_mem_congr\n\n/- warning: finprod_eq_one_of_forall_eq_one -> finprod_eq_one_of_forall_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M}, (forall (x : \u03b1), Eq.{succ u2} M (f x) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M}, (forall (x : \u03b1), Eq.{succ u2} M (f x) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_one_of_forall_eq_one finprod_eq_one_of_forall_eq_one\u2093'. -/\n@[to_additive]\ntheorem finprod_eq_one_of_forall_eq_one {f : \u03b1 \u2192 M} (h : \u2200 x, f x = 1) : (\u220f\u1da0 i, f i) = 1 := by\n  simp (config := { contextual := true }) [h]\n#align finprod_eq_one_of_forall_eq_one finprod_eq_one_of_forall_eq_one\n#align finsum_eq_zero_of_forall_eq_zero finsum_eq_zero_of_forall_eq_zero\n\n/-!\n### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication\n-/\n\n\n/- warning: finprod_mul_distrib -> finprod_mul_distrib is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {g : \u03b1 -> M}, (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) -> (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) g)) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (f i) (g i))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => g i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b1 -> M}, (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) -> (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) g)) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (f i) (g i))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => g i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mul_distrib finprod_mul_distrib\u2093'. -/\n/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals\nthe product of `f i` multiplied by the product of `g i`. -/\n@[to_additive\n      \"If the additive supports of `f` and `g` are finite, then the sum of `f i + g i`\\nequals the sum of `f i` plus the sum of `g i`.\"]\ntheorem finprod_mul_distrib (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) :\n    (\u220f\u1da0 i, f i * g i) = (\u220f\u1da0 i, f i) * \u220f\u1da0 i, g i := by\n  classical\n    rw [finprod_eq_prod_of_mulSupport_toFinset_subset _ hf (Finset.subset_union_left _ _),\n      finprod_eq_prod_of_mulSupport_toFinset_subset _ hg (Finset.subset_union_right _ _), \u2190\n      Finset.prod_mul_distrib]\n    refine' finprod_eq_prod_of_mulSupport_subset _ _\n    simp [mul_support_mul]\n#align finprod_mul_distrib finprod_mul_distrib\n#align finsum_add_distrib finsum_add_distrib\n\n/- warning: finprod_div_distrib -> finprod_div_distrib is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {G : Type.{u2}} [_inst_3 : DivisionCommMonoid.{u2} G] {f : \u03b1 -> G} {g : \u03b1 -> G}, (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 G (MulOneClass.toHasOne.{u2} G (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3))))) f)) -> (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 G (MulOneClass.toHasOne.{u2} G (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3))))) g)) -> (Eq.{succ u2} G (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toHasDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (f i) (g i))) (HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toHasDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => f i)) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => g i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {G : Type.{u2}} [_inst_3 : DivisionCommMonoid.{u2} G] {f : \u03b1 -> G} {g : \u03b1 -> G}, (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 G (InvOneClass.toOne.{u2} G (DivInvOneMonoid.toInvOneClass.{u2} G (DivisionMonoid.toDivInvOneMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) f)) -> (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 G (InvOneClass.toOne.{u2} G (DivInvOneMonoid.toInvOneClass.{u2} G (DivisionMonoid.toDivInvOneMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) g)) -> (Eq.{succ u2} G (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (f i) (g i))) (HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => f i)) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => g i))))\nCase conversion may be inaccurate. Consider using '#align finprod_div_distrib finprod_div_distrib\u2093'. -/\n/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i`\nequals the product of `f i` divided by the product of `g i`. -/\n@[to_additive\n      \"If the additive supports of `f` and `g` are finite, then the sum of `f i - g i`\\nequals the sum of `f i` minus the sum of `g i`.\"]\ntheorem finprod_div_distrib [DivisionCommMonoid G] {f g : \u03b1 \u2192 G} (hf : (mulSupport f).Finite)\n    (hg : (mulSupport g).Finite) : (\u220f\u1da0 i, f i / g i) = (\u220f\u1da0 i, f i) / \u220f\u1da0 i, g i := by\n  simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mul_support_inv g).symm.rec hg),\n    finprod_inv_distrib]\n#align finprod_div_distrib finprod_div_distrib\n#align finsum_sub_distrib finsum_sub_distrib\n\n/- warning: finprod_mem_mul_distrib' -> finprod_mem_mul_distrib' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {g : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) g))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (f i) (g i)))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => g i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b1 -> M} {s : Set.{u2} \u03b1}, (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) g))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (f i) (g i)))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => g i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_mul_distrib' finprod_mem_mul_distrib'\u2093'. -/\n/-- A more general version of `finprod_mem_mul_distrib` that only requires `s \u2229 mul_support f` and\n`s \u2229 mul_support g` rather than `s` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_add_distrib` that only requires `s \u2229 support f`\\nand `s \u2229 support g` rather than `s` to be finite.\"]\ntheorem finprod_mem_mul_distrib' (hf : (s \u2229 mulSupport f).Finite) (hg : (s \u2229 mulSupport g).Finite) :\n    (\u220f\u1da0 i \u2208 s, f i * g i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 s, g i :=\n  by\n  rw [\u2190 mul_support_mul_indicator] at hf hg\n  simp only [finprod_mem_def, mul_indicator_mul, finprod_mul_distrib hf hg]\n#align finprod_mem_mul_distrib' finprod_mem_mul_distrib'\n#align finsum_mem_add_distrib' finsum_mem_add_distrib'\n\n/- warning: finprod_mem_one -> finprod_mem_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] (s : Set.{u1} \u03b1), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (s : Set.{u2} \u03b1), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_one finprod_mem_one\u2093'. -/\n/-- The product of the constant function `1` over any set equals `1`. -/\n@[to_additive \"The product of the constant function `0` over any set equals `0`.\"]\ntheorem finprod_mem_one (s : Set \u03b1) : (\u220f\u1da0 i \u2208 s, (1 : M)) = 1 := by simp\n#align finprod_mem_one finprod_mem_one\n#align finsum_mem_zero finsum_mem_zero\n\n/- warning: finprod_mem_of_eq_on_one -> finprod_mem_of_eqOn_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Set.EqOn.{u1, u2} \u03b1 M f (OfNat.ofNat.{max u1 u2} (\u03b1 -> M) 1 (OfNat.mk.{max u1 u2} (\u03b1 -> M) 1 (One.one.{max u1 u2} (\u03b1 -> M) (Pi.instOne.{u1, u2} \u03b1 (fun (\u1fb0 : \u03b1) => M) (fun (i : \u03b1) => MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) s) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1}, (Set.EqOn.{u2, u1} \u03b1 M f (OfNat.ofNat.{max u2 u1} (\u03b1 -> M) 1 (One.toOfNat1.{max u2 u1} (\u03b1 -> M) (Pi.instOne.{u2, u1} \u03b1 (fun (a._@.Mathlib.Data.Set.Function._hyg.1349 : \u03b1) => M) (fun (i : \u03b1) => Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))))) s) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_of_eq_on_one finprod_mem_of_eqOn_one\u2093'. -/\n/-- If a function `f` equals `1` on a set `s`, then the product of `f i` over `i \u2208 s` equals `1`. -/\n@[to_additive\n      \"If a function `f` equals `0` on a set `s`, then the product of `f i` over `i \u2208 s`\\nequals `0`.\"]\ntheorem finprod_mem_of_eqOn_one (hf : s.EqOn f 1) : (\u220f\u1da0 i \u2208 s, f i) = 1 :=\n  by\n  rw [\u2190 finprod_mem_one s]\n  exact finprod_mem_congr rfl hf\n#align finprod_mem_of_eq_on_one finprod_mem_of_eqOn_one\n#align finsum_mem_of_eq_on_zero finsum_mem_of_eqOn_zero\n\n/- warning: exists_ne_one_of_finprod_mem_ne_one -> exists_ne_one_of_finprod_mem_ne_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Ne.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) -> (Exists.{succ u1} \u03b1 (fun (x : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) => Ne.{succ u2} M (f x) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Ne.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => f i))) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))) -> (Exists.{succ u1} \u03b1 (fun (x : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) (Ne.{succ u2} M (f x) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))\nCase conversion may be inaccurate. Consider using '#align exists_ne_one_of_finprod_mem_ne_one exists_ne_one_of_finprod_mem_ne_one\u2093'. -/\n/-- If the product of `f i` over `i \u2208 s` is not equal to `1`, then there is some `x \u2208 s` such that\n`f x \u2260 1`. -/\n@[to_additive\n      \"If the product of `f i` over `i \u2208 s` is not equal to `0`, then there is some `x \u2208 s`\\nsuch that `f x \u2260 0`.\"]\ntheorem exists_ne_one_of_finprod_mem_ne_one (h : (\u220f\u1da0 i \u2208 s, f i) \u2260 1) : \u2203 x \u2208 s, f x \u2260 1 :=\n  by\n  by_contra' h'\n  exact h (finprod_mem_of_eqOn_one h')\n#align exists_ne_one_of_finprod_mem_ne_one exists_ne_one_of_finprod_mem_ne_one\n#align exists_ne_zero_of_finsum_mem_ne_zero exists_ne_zero_of_finsum_mem_ne_zero\n\n/- warning: finprod_mem_mul_distrib -> finprod_mem_mul_distrib is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {g : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (f i) (g i)))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => g i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b1 -> M} {s : Set.{u2} \u03b1}, (Set.Finite.{u2} \u03b1 s) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (f i) (g i)))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => g i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_mul_distrib finprod_mem_mul_distrib\u2093'. -/\n/-- Given a finite set `s`, the product of `f i * g i` over `i \u2208 s` equals the product of `f i`\nover `i \u2208 s` times the product of `g i` over `i \u2208 s`. -/\n@[to_additive\n      \"Given a finite set `s`, the sum of `f i + g i` over `i \u2208 s` equals the sum of `f i`\\nover `i \u2208 s` plus the sum of `g i` over `i \u2208 s`.\"]\ntheorem finprod_mem_mul_distrib (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 s, f i * g i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 s, g i :=\n  finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _)\n#align finprod_mem_mul_distrib finprod_mem_mul_distrib\n#align finsum_mem_add_distrib finsum_mem_add_distrib\n\n/- warning: monoid_hom.map_finprod -> MonoidHom.map_finprod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} {N : Type.{u3}} [_inst_1 : CommMonoid.{u2} M] [_inst_2 : CommMonoid.{u3} N] {f : \u03b1 -> M} (g : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))), (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) -> (Eq.{succ u3} N (coeFn.{max (succ u3) (succ u2), max (succ u2) (succ u3)} (MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) (fun (_x : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) g (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (finprod.{u3, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => coeFn.{max (succ u3) (succ u2), max (succ u2) (succ u3)} (MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) (fun (_x : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) g (f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u3}} {N : Type.{u2}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] {f : \u03b1 -> M} (g : MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))), (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u3} \u03b1 M (Monoid.toOne.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) f)) -> (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i))) (finprod.{u2, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (f i))))\nCase conversion may be inaccurate. Consider using '#align monoid_hom.map_finprod MonoidHom.map_finprod\u2093'. -/\n@[to_additive]\ntheorem MonoidHom.map_finprod {f : \u03b1 \u2192 M} (g : M \u2192* N) (hf : (mulSupport f).Finite) :\n    g (\u220f\u1da0 i, f i) = \u220f\u1da0 i, g (f i) :=\n  g.map_finprod_pLift f <| hf.Preimage <| Equiv.plift.Injective.InjOn _\n#align monoid_hom.map_finprod MonoidHom.map_finprod\n#align add_monoid_hom.map_finsum AddMonoidHom.map_finsum\n\n/- warning: finprod_pow -> finprod_pow is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M}, (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) -> (forall (n : Nat), Eq.{succ u2} M (HPow.hPow.{u2, 0, u2} M Nat M (instHPow.{u2, 0} M Nat (Monoid.Pow.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) n) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => HPow.hPow.{u2, 0, u2} M Nat M (instHPow.{u2, 0} M Nat (Monoid.Pow.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (f i) n)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M}, (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) -> (forall (n : Nat), Eq.{succ u1} M (HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) n) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1))) (f i) n)))\nCase conversion may be inaccurate. Consider using '#align finprod_pow finprod_pow\u2093'. -/\n@[to_additive]\ntheorem finprod_pow (hf : (mulSupport f).Finite) (n : \u2115) : (\u220f\u1da0 i, f i) ^ n = \u220f\u1da0 i, f i ^ n :=\n  (powMonoidHom n).map_finprod hf\n#align finprod_pow finprod_pow\n#align finsum_nsmul finsum_nsmul\n\n/- warning: monoid_hom.map_finprod_mem' -> MonoidHom.map_finprod_mem' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} {N : Type.{u3}} [_inst_1 : CommMonoid.{u2} M] [_inst_2 : CommMonoid.{u3} N] {s : Set.{u1} \u03b1} {f : \u03b1 -> M} (g : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))), (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u3} N (coeFn.{max (succ u3) (succ u2), max (succ u2) (succ u3)} (MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) (fun (_x : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) g (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) j s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) j s) => f j)))) (finprod.{u3, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => finprod.{u3, 0} N (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_2 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => coeFn.{max (succ u3) (succ u2), max (succ u2) (succ u3)} (MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) (fun (_x : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) g (f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u3}} {N : Type.{u2}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] {s : Set.{u1} \u03b1} {f : \u03b1 -> M} (g : MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))), (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Function.mulSupport.{u1, u3} \u03b1 M (Monoid.toOne.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) f))) -> (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u3, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) _inst_1 (fun (h._@.Mathlib.Algebra.BigOperators.Finprod._hyg.7346 : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) => f j)))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u3, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) => f j)))) (finprod.{u2, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => finprod.{u2, 0} N (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_2 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (f i)))))\nCase conversion may be inaccurate. Consider using '#align monoid_hom.map_finprod_mem' MonoidHom.map_finprod_mem'\u2093'. -/\n/-- A more general version of `monoid_hom.map_finprod_mem` that requires `s \u2229 mul_support f` rather\nthan `s` to be finite. -/\n@[to_additive\n      \"A more general version of `add_monoid_hom.map_finsum_mem` that requires\\n`s \u2229 support f` rather than `s` to be finite.\"]\ntheorem MonoidHom.map_finprod_mem' {f : \u03b1 \u2192 M} (g : M \u2192* N) (h\u2080 : (s \u2229 mulSupport f).Finite) :\n    g (\u220f\u1da0 j \u2208 s, f j) = \u220f\u1da0 i \u2208 s, g (f i) :=\n  by\n  rw [g.map_finprod]\n  \u00b7 simp only [g.map_finprod_Prop]\n  \u00b7 simpa only [finprod_eq_mulIndicator_apply, mul_support_mul_indicator]\n#align monoid_hom.map_finprod_mem' MonoidHom.map_finprod_mem'\n#align add_monoid_hom.map_finsum_mem' AddMonoidHom.map_finsum_mem'\n\n/- warning: monoid_hom.map_finprod_mem -> MonoidHom.map_finprod_mem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} {N : Type.{u3}} [_inst_1 : CommMonoid.{u2} M] [_inst_2 : CommMonoid.{u3} N] {s : Set.{u1} \u03b1} (f : \u03b1 -> M) (g : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))), (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u3} N (coeFn.{max (succ u3) (succ u2), max (succ u2) (succ u3)} (MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) (fun (_x : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) g (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) j s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) j s) => f j)))) (finprod.{u3, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => finprod.{u3, 0} N (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_2 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => coeFn.{max (succ u3) (succ u2), max (succ u2) (succ u3)} (MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) (fun (_x : MonoidHom.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) => M -> N) (MonoidHom.hasCoeToFun.{u2, u3} M N (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)) (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2))) g (f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u3}} {N : Type.{u2}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] {s : Set.{u1} \u03b1} (f : \u03b1 -> M) (g : MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))), (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u3, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) _inst_1 (fun (h._@.Mathlib.Algebra.BigOperators.Finprod._hyg.7493 : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) => f j)))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u3, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) j s) => f j)))) (finprod.{u2, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => finprod.{u2, 0} N (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_2 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MonoidHom.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MonoidHom.monoidHomClass.{u3, u2} M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))) g (f i)))))\nCase conversion may be inaccurate. Consider using '#align monoid_hom.map_finprod_mem MonoidHom.map_finprod_mem\u2093'. -/\n/-- Given a monoid homomorphism `g : M \u2192* N` and a function `f : \u03b1 \u2192 M`, the value of `g` at the\nproduct of `f i` over `i \u2208 s` equals the product of `g (f i)` over `s`. -/\n@[to_additive\n      \"Given an additive monoid homomorphism `g : M \u2192* N` and a function `f : \u03b1 \u2192 M`, the\\nvalue of `g` at the sum of `f i` over `i \u2208 s` equals the sum of `g (f i)` over `s`.\"]\ntheorem MonoidHom.map_finprod_mem (f : \u03b1 \u2192 M) (g : M \u2192* N) (hs : s.Finite) :\n    g (\u220f\u1da0 j \u2208 s, f j) = \u220f\u1da0 i \u2208 s, g (f i) :=\n  g.map_finprod_mem' (hs.inter_of_left _)\n#align monoid_hom.map_finprod_mem MonoidHom.map_finprod_mem\n#align add_monoid_hom.map_finsum_mem AddMonoidHom.map_finsum_mem\n\n/- warning: mul_equiv.map_finprod_mem -> MulEquiv.map_finprod_mem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} {N : Type.{u3}} [_inst_1 : CommMonoid.{u2} M] [_inst_2 : CommMonoid.{u3} N] (g : MulEquiv.{u2, u3} M N (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toHasMul.{u3} N (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2)))) (f : \u03b1 -> M) {s : Set.{u1} \u03b1}, (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u3} N (coeFn.{max (succ u2) (succ u3), max (succ u2) (succ u3)} (MulEquiv.{u2, u3} M N (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toHasMul.{u3} N (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2)))) (fun (_x : MulEquiv.{u2, u3} M N (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toHasMul.{u3} N (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2)))) => M -> N) (MulEquiv.hasCoeToFun.{u2, u3} M N (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toHasMul.{u3} N (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2)))) g (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i)))) (finprod.{u3, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => finprod.{u3, 0} N (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_2 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => coeFn.{max (succ u2) (succ u3), max (succ u2) (succ u3)} (MulEquiv.{u2, u3} M N (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toHasMul.{u3} N (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2)))) (fun (_x : MulEquiv.{u2, u3} M N (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toHasMul.{u3} N (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2)))) => M -> N) (MulEquiv.hasCoeToFun.{u2, u3} M N (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) (MulOneClass.toHasMul.{u3} N (Monoid.toMulOneClass.{u3} N (CommMonoid.toMonoid.{u3} N _inst_2)))) g (f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u3}} {N : Type.{u2}} [_inst_1 : CommMonoid.{u3} M] [_inst_2 : CommMonoid.{u2} N] (g : MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) (f : \u03b1 -> M) {s : Set.{u1} \u03b1}, (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_1 (fun (h._@.Mathlib.Algebra.BigOperators.Finprod._hyg.7608 : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => f i)))) (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquivClass.instMonoidHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquiv.instMulEquivClassMulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))))) g (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => f i)))) (finprod.{u2, succ u1} N \u03b1 _inst_2 (fun (i : \u03b1) => finprod.{u2, 0} N (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_2 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M (fun (_x : M) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : M) => N) _x) (MulHomClass.toFunLike.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (MonoidHomClass.toMulHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquivClass.instMonoidHomClass.{max u3 u2, u3, u2} (MulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)))) M N (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)) (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2)) (MulEquiv.instMulEquivClassMulEquiv.{u3, u2} M N (MulOneClass.toMul.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (MulOneClass.toMul.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))))))) g (f i)))))\nCase conversion may be inaccurate. Consider using '#align mul_equiv.map_finprod_mem MulEquiv.map_finprod_mem\u2093'. -/\n@[to_additive]\ntheorem MulEquiv.map_finprod_mem (g : M \u2243* N) (f : \u03b1 \u2192 M) {s : Set \u03b1} (hs : s.Finite) :\n    g (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 s, g (f i) :=\n  g.toMonoidHom.map_finprod_mem f hs\n#align mul_equiv.map_finprod_mem MulEquiv.map_finprod_mem\n#align add_equiv.map_finsum_mem AddEquiv.map_finsum_mem\n\n/- warning: finprod_mem_inv_distrib -> finprod_mem_inv_distrib is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {G : Type.{u2}} {s : Set.{u1} \u03b1} [_inst_3 : DivisionCommMonoid.{u2} G] (f : \u03b1 -> G), (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} G (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (x : \u03b1) => finprod.{u2, 0} G (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) => Inv.inv.{u2} G (DivInvMonoid.toHasInv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3))) (f x)))) (Inv.inv.{u2} G (DivInvMonoid.toHasInv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (x : \u03b1) => finprod.{u2, 0} G (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) => f x)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {G : Type.{u2}} {s : Set.{u1} \u03b1} [_inst_3 : DivisionCommMonoid.{u2} G] (f : \u03b1 -> G), (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} G (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (x : \u03b1) => finprod.{u2, 0} G (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) => Inv.inv.{u2} G (InvOneClass.toInv.{u2} G (DivInvOneMonoid.toInvOneClass.{u2} G (DivisionMonoid.toDivInvOneMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (f x)))) (Inv.inv.{u2} G (InvOneClass.toInv.{u2} G (DivInvOneMonoid.toInvOneClass.{u2} G (DivisionMonoid.toDivInvOneMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (x : \u03b1) => finprod.{u2, 0} G (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) => f x)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_inv_distrib finprod_mem_inv_distrib\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_inv_distrib [DivisionCommMonoid G] (f : \u03b1 \u2192 G) (hs : s.Finite) :\n    (\u220f\u1da0 x \u2208 s, (f x)\u207b\u00b9) = (\u220f\u1da0 x \u2208 s, f x)\u207b\u00b9 :=\n  ((MulEquiv.inv G).map_finprod_mem f hs).symm\n#align finprod_mem_inv_distrib finprod_mem_inv_distrib\n#align finsum_mem_neg_distrib finsum_mem_neg_distrib\n\n/- warning: finprod_mem_div_distrib -> finprod_mem_div_distrib is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {G : Type.{u2}} {s : Set.{u1} \u03b1} [_inst_3 : DivisionCommMonoid.{u2} G] (f : \u03b1 -> G) (g : \u03b1 -> G), (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} G (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => finprod.{u2, 0} G (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toHasDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (f i) (g i)))) (HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toHasDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => finprod.{u2, 0} G (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => finprod.{u2, 0} G (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => g i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {G : Type.{u2}} {s : Set.{u1} \u03b1} [_inst_3 : DivisionCommMonoid.{u2} G] (f : \u03b1 -> G) (g : \u03b1 -> G), (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} G (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => finprod.{u2, 0} G (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (f i) (g i)))) (HDiv.hDiv.{u2, u2, u2} G G G (instHDiv.{u2} G (DivInvMonoid.toDiv.{u2} G (DivisionMonoid.toDivInvMonoid.{u2} G (DivisionCommMonoid.toDivisionMonoid.{u2} G _inst_3)))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => finprod.{u2, 0} G (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} G \u03b1 (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (i : \u03b1) => finprod.{u2, 0} G (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) (DivisionCommMonoid.toCommMonoid.{u2} G _inst_3) (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => g i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_div_distrib finprod_mem_div_distrib\u2093'. -/\n/-- Given a finite set `s`, the product of `f i / g i` over `i \u2208 s` equals the product of `f i`\nover `i \u2208 s` divided by the product of `g i` over `i \u2208 s`. -/\n@[to_additive\n      \"Given a finite set `s`, the sum of `f i / g i` over `i \u2208 s` equals the sum of `f i`\\nover `i \u2208 s` minus the sum of `g i` over `i \u2208 s`.\"]\ntheorem finprod_mem_div_distrib [DivisionCommMonoid G] (f g : \u03b1 \u2192 G) (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 s, f i / g i) = (\u220f\u1da0 i \u2208 s, f i) / \u220f\u1da0 i \u2208 s, g i := by\n  simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib g hs]\n#align finprod_mem_div_distrib finprod_mem_div_distrib\n#align finsum_mem_sub_distrib finsum_mem_sub_distrib\n\n/-!\n### `\u220f\u1da0 x \u2208 s, f x` and set operations\n-/\n\n\n/- warning: finprod_mem_empty -> finprod_mem_empty is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M}, Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))) => f i))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M}, Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))) => f i))) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_empty finprod_mem_empty\u2093'. -/\n/-- The product of any function over an empty set is `1`. -/\n@[to_additive \"The sum of any function over an empty set is `0`.\"]\ntheorem finprod_mem_empty : (\u220f\u1da0 i \u2208 (\u2205 : Set \u03b1), f i) = 1 := by simp\n#align finprod_mem_empty finprod_mem_empty\n#align finsum_mem_empty finsum_mem_empty\n\n/- warning: nonempty_of_finprod_mem_ne_one -> nonempty_of_finprod_mem_ne_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Ne.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) -> (Set.Nonempty.{u1} \u03b1 s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1}, (Ne.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => f i))) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))) -> (Set.Nonempty.{u1} \u03b1 s)\nCase conversion may be inaccurate. Consider using '#align nonempty_of_finprod_mem_ne_one nonempty_of_finprod_mem_ne_one\u2093'. -/\n/-- A set `s` is nonempty if the product of some function over `s` is not equal to `1`. -/\n@[to_additive \"A set `s` is nonempty if the sum of some function over `s` is not equal to `0`.\"]\ntheorem nonempty_of_finprod_mem_ne_one (h : (\u220f\u1da0 i \u2208 s, f i) \u2260 1) : s.Nonempty :=\n  nonempty_iff_ne_empty.2 fun h' => h <| h'.symm \u25b8 finprod_mem_empty\n#align nonempty_of_finprod_mem_ne_one nonempty_of_finprod_mem_ne_one\n#align nonempty_of_finsum_mem_ne_zero nonempty_of_finsum_mem_ne_zero\n\n/- warning: finprod_mem_union_inter -> finprod_mem_union_inter is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.Finite.{u1} \u03b1 s) -> (Set.Finite.{u1} \u03b1 t) -> (Eq.{succ u2} M (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) => f i)))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (Set.Finite.{u2} \u03b1 s) -> (Set.Finite.{u2} \u03b1 t) -> (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) => f i)))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_union_inter finprod_mem_union_inter\u2093'. -/\n/-- Given finite sets `s` and `t`, the product of `f i` over `i \u2208 s \u222a t` times the product of\n`f i` over `i \u2208 s \u2229 t` equals the product of `f i` over `i \u2208 s` times the product of `f i`\nover `i \u2208 t`. -/\n@[to_additive\n      \"Given finite sets `s` and `t`, the sum of `f i` over `i \u2208 s \u222a t` plus the sum of\\n`f i` over `i \u2208 s \u2229 t` equals the sum of `f i` over `i \u2208 s` plus the sum of `f i` over `i \u2208 t`.\"]\ntheorem finprod_mem_union_inter (hs : s.Finite) (ht : t.Finite) :\n    ((\u220f\u1da0 i \u2208 s \u222a t, f i) * \u220f\u1da0 i \u2208 s \u2229 t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i :=\n  by\n  lift s to Finset \u03b1 using hs; lift t to Finset \u03b1 using ht\n  classical\n    rw [\u2190 Finset.coe_union, \u2190 Finset.coe_inter]\n    simp only [finprod_mem_coe_finset, Finset.prod_union_inter]\n#align finprod_mem_union_inter finprod_mem_union_inter\n#align finsum_mem_union_inter finsum_mem_union_inter\n\n/- warning: finprod_mem_union_inter' -> finprod_mem_union_inter' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) t (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) => f i)))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) t (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) => f i)))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_union_inter' finprod_mem_union_inter'\u2093'. -/\n/-- A more general version of `finprod_mem_union_inter` that requires `s \u2229 mul_support f` and\n`t \u2229 mul_support f` rather than `s` and `t` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_union_inter` that requires `s \u2229 support f` and\\n`t \u2229 support f` rather than `s` and `t` to be finite.\"]\ntheorem finprod_mem_union_inter' (hs : (s \u2229 mulSupport f).Finite) (ht : (t \u2229 mulSupport f).Finite) :\n    ((\u220f\u1da0 i \u2208 s \u222a t, f i) * \u220f\u1da0 i \u2208 s \u2229 t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i :=\n  by\n  rw [\u2190 finprod_mem_inter_mulSupport f s, \u2190 finprod_mem_inter_mulSupport f t, \u2190\n    finprod_mem_union_inter hs ht, \u2190 union_inter_distrib_right, finprod_mem_inter_mulSupport, \u2190\n    finprod_mem_inter_mulSupport f (s \u2229 t)]\n  congr 2\n  rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm]\n#align finprod_mem_union_inter' finprod_mem_union_inter'\n#align finsum_mem_union_inter' finsum_mem_union_inter'\n\n/- warning: finprod_mem_union' -> finprod_mem_union' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Disjoint.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1))) s t) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) t (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) => f i))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (Disjoint.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) s t) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) t (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) => f i))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_union' finprod_mem_union'\u2093'. -/\n/-- A more general version of `finprod_mem_union` that requires `s \u2229 mul_support f` and\n`t \u2229 mul_support f` rather than `s` and `t` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_union` that requires `s \u2229 support f` and\\n`t \u2229 support f` rather than `s` and `t` to be finite.\"]\ntheorem finprod_mem_union' (hst : Disjoint s t) (hs : (s \u2229 mulSupport f).Finite)\n    (ht : (t \u2229 mulSupport f).Finite) : (\u220f\u1da0 i \u2208 s \u222a t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty,\n    mul_one]\n#align finprod_mem_union' finprod_mem_union'\n#align finsum_mem_union' finsum_mem_union'\n\n/- warning: finprod_mem_union -> finprod_mem_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Disjoint.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1))) s t) -> (Set.Finite.{u1} \u03b1 s) -> (Set.Finite.{u1} \u03b1 t) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) => f i))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (Disjoint.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) s t) -> (Set.Finite.{u2} \u03b1 s) -> (Set.Finite.{u2} \u03b1 t) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) => f i))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_union finprod_mem_union\u2093'. -/\n/-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i \u2208 s \u222a t` equals the\nproduct of `f i` over `i \u2208 s` times the product of `f i` over `i \u2208 t`. -/\n@[to_additive\n      \"Given two finite disjoint sets `s` and `t`, the sum of `f i` over `i \u2208 s \u222a t` equals\\nthe sum of `f i` over `i \u2208 s` plus the sum of `f i` over `i \u2208 t`.\"]\ntheorem finprod_mem_union (hst : Disjoint s t) (hs : s.Finite) (ht : t.Finite) :\n    (\u220f\u1da0 i \u2208 s \u222a t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i :=\n  finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _)\n#align finprod_mem_union finprod_mem_union\n#align finsum_mem_union finsum_mem_union\n\n/- warning: finprod_mem_union'' -> finprod_mem_union'' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Disjoint.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1))) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) t (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) t (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) => f i))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (Disjoint.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) t (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) t (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Union.union.{u2} (Set.{u2} \u03b1) (Set.instUnionSet.{u2} \u03b1) s t)) => f i))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_union'' finprod_mem_union''\u2093'. -/\n/-- A more general version of `finprod_mem_union'` that requires `s \u2229 mul_support f` and\n`t \u2229 mul_support f` rather than `s` and `t` to be disjoint -/\n@[to_additive\n      \"A more general version of `finsum_mem_union'` that requires `s \u2229 support f` and\\n`t \u2229 support f` rather than `s` and `t` to be disjoint\"]\ntheorem finprod_mem_union'' (hst : Disjoint (s \u2229 mulSupport f) (t \u2229 mulSupport f))\n    (hs : (s \u2229 mulSupport f).Finite) (ht : (t \u2229 mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 s \u222a t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_inter_mulSupport f s, \u2190 finprod_mem_inter_mulSupport f t, \u2190\n    finprod_mem_union hst hs ht, \u2190 union_inter_distrib_right, finprod_mem_inter_mulSupport]\n#align finprod_mem_union'' finprod_mem_union''\n#align finsum_mem_union'' finsum_mem_union''\n\n#print finprod_mem_singleton /-\n/-- The product of `f i` over `i \u2208 {a}` equals `f a`. -/\n@[to_additive \"The sum of `f i` over `i \u2208 {a}` equals `f a`.\"]\ntheorem finprod_mem_singleton : (\u220f\u1da0 i \u2208 ({a} : Set \u03b1), f i) = f a := by\n  rw [\u2190 Finset.coe_singleton, finprod_mem_coe_finset, Finset.prod_singleton]\n#align finprod_mem_singleton finprod_mem_singleton\n#align finsum_mem_singleton finsum_mem_singleton\n-/\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (i \u00abexpr = \u00bb a) -/\n#print finprod_cond_eq_left /-\n@[simp, to_additive]\ntheorem finprod_cond_eq_left : (\u220f\u1da0 (i) (_ : i = a), f i) = f a :=\n  finprod_mem_singleton\n#align finprod_cond_eq_left finprod_cond_eq_left\n#align finsum_cond_eq_left finsum_cond_eq_left\n-/\n\n#print finprod_cond_eq_right /-\n@[simp, to_additive]\ntheorem finprod_cond_eq_right : (\u220f\u1da0 (i) (hi : a = i), f i) = f a := by simp [@eq_comm _ a]\n#align finprod_cond_eq_right finprod_cond_eq_right\n#align finsum_cond_eq_right finsum_cond_eq_right\n-/\n\n/- warning: finprod_mem_insert' -> finprod_mem_insert' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {a : \u03b1} {s : Set.{u1} \u03b1} (f : \u03b1 -> M), (Not (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s)) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) => f i))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (f a) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {a : \u03b1} {s : Set.{u2} \u03b1} (f : \u03b1 -> M), (Not (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s)) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a s)) => f i))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (f a) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_insert' finprod_mem_insert'\u2093'. -/\n/-- A more general version of `finprod_mem_insert` that requires `s \u2229 mul_support f` rather than `s`\nto be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_insert` that requires `s \u2229 support f` rather\\nthan `s` to be finite.\"]\ntheorem finprod_mem_insert' (f : \u03b1 \u2192 M) (h : a \u2209 s) (hs : (s \u2229 mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 insert a s, f i) = f a * \u220f\u1da0 i \u2208 s, f i :=\n  by\n  rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton]\n  \u00b7 rwa [disjoint_singleton_left]\n  \u00b7 exact (finite_singleton a).inter_of_left _\n#align finprod_mem_insert' finprod_mem_insert'\n#align finsum_mem_insert' finsum_mem_insert'\n\n/- warning: finprod_mem_insert -> finprod_mem_insert is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {a : \u03b1} {s : Set.{u1} \u03b1} (f : \u03b1 -> M), (Not (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s)) -> (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) => f i))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (f a) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {a : \u03b1} {s : Set.{u2} \u03b1} (f : \u03b1 -> M), (Not (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s)) -> (Set.Finite.{u2} \u03b1 s) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a s)) => f i))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (f a) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_insert finprod_mem_insert\u2093'. -/\n/-- Given a finite set `s` and an element `a \u2209 s`, the product of `f i` over `i \u2208 insert a s` equals\n`f a` times the product of `f i` over `i \u2208 s`. -/\n@[to_additive\n      \"Given a finite set `s` and an element `a \u2209 s`, the sum of `f i` over `i \u2208 insert a s`\\nequals `f a` plus the sum of `f i` over `i \u2208 s`.\"]\ntheorem finprod_mem_insert (f : \u03b1 \u2192 M) (h : a \u2209 s) (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 insert a s, f i) = f a * \u220f\u1da0 i \u2208 s, f i :=\n  finprod_mem_insert' f h <| hs.inter_of_left _\n#align finprod_mem_insert finprod_mem_insert\n#align finsum_mem_insert finsum_mem_insert\n\n/- warning: finprod_mem_insert_of_eq_one_if_not_mem -> finprod_mem_insert_of_eq_one_if_not_mem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {a : \u03b1} {s : Set.{u1} \u03b1}, ((Not (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s)) -> (Eq.{succ u2} M (f a) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {a : \u03b1} {s : Set.{u2} \u03b1}, ((Not (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s)) -> (Eq.{succ u1} M (f a) (OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a s)) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_insert_of_eq_one_if_not_mem finprod_mem_insert_of_eq_one_if_not_mem\u2093'. -/\n/-- If `f a = 1` when `a \u2209 s`, then the product of `f i` over `i \u2208 insert a s` equals the product of\n`f i` over `i \u2208 s`. -/\n@[to_additive\n      \"If `f a = 0` when `a \u2209 s`, then the sum of `f i` over `i \u2208 insert a s` equals the sum\\nof `f i` over `i \u2208 s`.\"]\ntheorem finprod_mem_insert_of_eq_one_if_not_mem (h : a \u2209 s \u2192 f a = 1) :\n    (\u220f\u1da0 i \u2208 insert a s, f i) = \u220f\u1da0 i \u2208 s, f i :=\n  by\n  refine' finprod_mem_inter_mulSupport_eq' _ _ _ fun x hx => \u27e8_, Or.inr\u27e9\n  rintro (rfl | hxs)\n  exacts[not_imp_comm.1 h hx, hxs]\n#align finprod_mem_insert_of_eq_one_if_not_mem finprod_mem_insert_of_eq_one_if_not_mem\n#align finsum_mem_insert_of_eq_zero_if_not_mem finsum_mem_insert_of_eq_zero_if_not_mem\n\n/- warning: finprod_mem_insert_one -> finprod_mem_insert_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {a : \u03b1} {s : Set.{u1} \u03b1}, (Eq.{succ u2} M (f a) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {a : \u03b1} {s : Set.{u1} \u03b1}, (Eq.{succ u2} M (f a) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instInsertSet.{u1} \u03b1) a s)) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instInsertSet.{u1} \u03b1) a s)) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_insert_one finprod_mem_insert_one\u2093'. -/\n/-- If `f a = 1`, then the product of `f i` over `i \u2208 insert a s` equals the product of `f i` over\n`i \u2208 s`. -/\n@[to_additive\n      \"If `f a = 0`, then the sum of `f i` over `i \u2208 insert a s` equals the sum of `f i`\\nover `i \u2208 s`.\"]\ntheorem finprod_mem_insert_one (h : f a = 1) : (\u220f\u1da0 i \u2208 insert a s, f i) = \u220f\u1da0 i \u2208 s, f i :=\n  finprod_mem_insert_of_eq_one_if_not_mem fun _ => h\n#align finprod_mem_insert_one finprod_mem_insert_one\n#align finsum_mem_insert_zero finsum_mem_insert_zero\n\n/- warning: finprod_mem_dvd -> finprod_mem_dvd is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {N : Type.{u2}} [_inst_2 : CommMonoid.{u2} N] {f : \u03b1 -> N} (a : \u03b1), (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 N (MulOneClass.toHasOne.{u2} N (Monoid.toMulOneClass.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) f)) -> (Dvd.Dvd.{u2} N (semigroupDvd.{u2} N (Monoid.toSemigroup.{u2} N (CommMonoid.toMonoid.{u2} N _inst_2))) (f a) (finprod.{u2, succ u1} N \u03b1 _inst_2 f))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {N : Type.{u1}} [_inst_2 : CommMonoid.{u1} N] {f : \u03b1 -> N} (a : \u03b1), (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 N (Monoid.toOne.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2)) f)) -> (Dvd.dvd.{u1} N (semigroupDvd.{u1} N (Monoid.toSemigroup.{u1} N (CommMonoid.toMonoid.{u1} N _inst_2))) (f a) (finprod.{u1, succ u2} N \u03b1 _inst_2 f))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_dvd finprod_mem_dvd\u2093'. -/\n/-- If the multiplicative support of `f` is finite, then for every `x` in the domain of `f`, `f x`\ndivides `finprod f`.  -/\ntheorem finprod_mem_dvd {f : \u03b1 \u2192 N} (a : \u03b1) (hf : (mulSupport f).Finite) : f a \u2223 finprod f :=\n  by\n  by_cases ha : a \u2208 mul_support f\n  \u00b7 rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf (Set.Subset.refl _)]\n    exact Finset.dvd_prod_of_mem f ((finite.mem_to_finset hf).mpr ha)\n  \u00b7 rw [nmem_mul_support.mp ha]\n    exact one_dvd (finprod f)\n#align finprod_mem_dvd finprod_mem_dvd\n\n/- warning: finprod_mem_pair -> finprod_mem_pair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {a : \u03b1} {b : \u03b1}, (Ne.{succ u1} \u03b1 a b) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a (Singleton.singleton.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasSingleton.{u1} \u03b1) b))) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a (Singleton.singleton.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasSingleton.{u1} \u03b1) b))) => f i))) (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (f a) (f b)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {a : \u03b1} {b : \u03b1}, (Ne.{succ u2} \u03b1 a b) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a (Singleton.singleton.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instSingletonSet.{u2} \u03b1) b))) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Insert.insert.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instInsertSet.{u2} \u03b1) a (Singleton.singleton.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instSingletonSet.{u2} \u03b1) b))) => f i))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (f a) (f b)))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_pair finprod_mem_pair\u2093'. -/\n/-- The product of `f i` over `i \u2208 {a, b}`, `a \u2260 b`, is equal to `f a * f b`. -/\n@[to_additive \"The sum of `f i` over `i \u2208 {a, b}`, `a \u2260 b`, is equal to `f a + f b`.\"]\ntheorem finprod_mem_pair (h : a \u2260 b) : (\u220f\u1da0 i \u2208 ({a, b} : Set \u03b1), f i) = f a * f b :=\n  by\n  rw [finprod_mem_insert, finprod_mem_singleton]\n  exacts[h, finite_singleton b]\n#align finprod_mem_pair finprod_mem_pair\n#align finsum_mem_pair finsum_mem_pair\n\n/- warning: finprod_mem_image' -> finprod_mem_image' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b2} {g : \u03b2 -> \u03b1}, (Set.InjOn.{u2, u1} \u03b2 \u03b1 g (Inter.inter.{u2} (Set.{u2} \u03b2) (Set.hasInter.{u2} \u03b2) s (Function.mulSupport.{u2, u3} \u03b2 M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (Function.comp.{succ u2, succ u1, succ u3} \u03b2 \u03b1 M f g)))) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.image.{u2, u1} \u03b2 \u03b1 g s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.image.{u2, u1} \u03b2 \u03b1 g s)) => f i))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u3, 0} M (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j s) _inst_1 (fun (H : Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j s) => f (g j)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u3} \u03b2} {g : \u03b2 -> \u03b1}, (Set.InjOn.{u3, u2} \u03b2 \u03b1 g (Inter.inter.{u3} (Set.{u3} \u03b2) (Set.instInterSet.{u3} \u03b2) s (Function.mulSupport.{u3, u1} \u03b2 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Function.comp.{succ u3, succ u2, succ u1} \u03b2 \u03b1 M f g)))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.image.{u3, u2} \u03b2 \u03b1 g s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.image.{u3, u2} \u03b2 \u03b1 g s)) => f i))) (finprod.{u1, succ u3} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u1, 0} M (Membership.mem.{u3, u3} \u03b2 (Set.{u3} \u03b2) (Set.instMembershipSet.{u3} \u03b2) j s) _inst_1 (fun (H : Membership.mem.{u3, u3} \u03b2 (Set.{u3} \u03b2) (Set.instMembershipSet.{u3} \u03b2) j s) => f (g j)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_image' finprod_mem_image'\u2093'. -/\n/-- The product of `f y` over `y \u2208 g '' s` equals the product of `f (g i)` over `s`\nprovided that `g` is injective on `s \u2229 mul_support (f \u2218 g)`. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 g '' s` equals the sum of `f (g i)` over `s` provided that\\n`g` is injective on `s \u2229 support (f \u2218 g)`.\"]\ntheorem finprod_mem_image' {s : Set \u03b2} {g : \u03b2 \u2192 \u03b1} (hg : (s \u2229 mulSupport (f \u2218 g)).InjOn g) :\n    (\u220f\u1da0 i \u2208 g '' s, f i) = \u220f\u1da0 j \u2208 s, f (g j) := by\n  classical\n    by_cases hs : (s \u2229 mul_support (f \u2218 g)).Finite\n    \u00b7 have hg : \u2200 x \u2208 hs.to_finset, \u2200 y \u2208 hs.to_finset, g x = g y \u2192 x = y := by\n        simpa only [hs.mem_to_finset]\n      rw [finprod_mem_eq_prod _ hs, \u2190 Finset.prod_image hg]\n      refine' finprod_mem_eq_prod_of_inter_mulSupport_eq f _\n      rw [Finset.coe_image, hs.coe_to_finset, \u2190 image_inter_mul_support_eq, inter_assoc, inter_self]\n    \u00b7 rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite]\n      rwa [image_inter_mul_support_eq, infinite_image_iff hg]\n#align finprod_mem_image' finprod_mem_image'\n#align finsum_mem_image' finsum_mem_image'\n\n/- warning: finprod_mem_image -> finprod_mem_image is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b2} {g : \u03b2 -> \u03b1}, (Set.InjOn.{u2, u1} \u03b2 \u03b1 g s) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.image.{u2, u1} \u03b2 \u03b1 g s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.image.{u2, u1} \u03b2 \u03b1 g s)) => f i))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u3, 0} M (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j s) _inst_1 (fun (H : Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j s) => f (g j)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u3} \u03b2} {g : \u03b2 -> \u03b1}, (Set.InjOn.{u3, u2} \u03b2 \u03b1 g s) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.image.{u3, u2} \u03b2 \u03b1 g s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.image.{u3, u2} \u03b2 \u03b1 g s)) => f i))) (finprod.{u1, succ u3} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u1, 0} M (Membership.mem.{u3, u3} \u03b2 (Set.{u3} \u03b2) (Set.instMembershipSet.{u3} \u03b2) j s) _inst_1 (fun (H : Membership.mem.{u3, u3} \u03b2 (Set.{u3} \u03b2) (Set.instMembershipSet.{u3} \u03b2) j s) => f (g j)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_image finprod_mem_image\u2093'. -/\n/-- The product of `f y` over `y \u2208 g '' s` equals the product of `f (g i)` over `s` provided that\n`g` is injective on `s`. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 g '' s` equals the sum of `f (g i)` over `s` provided that\\n`g` is injective on `s`.\"]\ntheorem finprod_mem_image {s : Set \u03b2} {g : \u03b2 \u2192 \u03b1} (hg : s.InjOn g) :\n    (\u220f\u1da0 i \u2208 g '' s, f i) = \u220f\u1da0 j \u2208 s, f (g j) :=\n  finprod_mem_image' <| hg.mono <| inter_subset_left _ _\n#align finprod_mem_image finprod_mem_image\n#align finsum_mem_image finsum_mem_image\n\n/- warning: finprod_mem_range' -> finprod_mem_range' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> M} {g : \u03b2 -> \u03b1}, (Set.InjOn.{u2, u1} \u03b2 \u03b1 g (Function.mulSupport.{u2, u3} \u03b2 M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (Function.comp.{succ u2, succ u1, succ u3} \u03b2 \u03b1 M f g))) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.range.{u1, succ u2} \u03b1 \u03b2 g)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.range.{u1, succ u2} \u03b1 \u03b2 g)) => f i))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => f (g j))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b2 -> \u03b1}, (Set.InjOn.{u3, u2} \u03b2 \u03b1 g (Function.mulSupport.{u3, u1} \u03b2 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (Function.comp.{succ u3, succ u2, succ u1} \u03b2 \u03b1 M f g))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.range.{u2, succ u3} \u03b1 \u03b2 g)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.range.{u2, succ u3} \u03b1 \u03b2 g)) => f i))) (finprod.{u1, succ u3} M \u03b2 _inst_1 (fun (j : \u03b2) => f (g j))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_range' finprod_mem_range'\u2093'. -/\n/-- The product of `f y` over `y \u2208 set.range g` equals the product of `f (g i)` over all `i`\nprovided that `g` is injective on `mul_support (f \u2218 g)`. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 set.range g` equals the sum of `f (g i)` over all `i`\\nprovided that `g` is injective on `support (f \u2218 g)`.\"]\ntheorem finprod_mem_range' {g : \u03b2 \u2192 \u03b1} (hg : (mulSupport (f \u2218 g)).InjOn g) :\n    (\u220f\u1da0 i \u2208 range g, f i) = \u220f\u1da0 j, f (g j) :=\n  by\n  rw [\u2190 image_univ, finprod_mem_image', finprod_mem_univ]\n  rwa [univ_inter]\n#align finprod_mem_range' finprod_mem_range'\n#align finsum_mem_range' finsum_mem_range'\n\n/- warning: finprod_mem_range -> finprod_mem_range is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> M} {g : \u03b2 -> \u03b1}, (Function.Injective.{succ u2, succ u1} \u03b2 \u03b1 g) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.range.{u1, succ u2} \u03b1 \u03b2 g)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Set.range.{u1, succ u2} \u03b1 \u03b2 g)) => f i))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => f (g j))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b2 -> \u03b1}, (Function.Injective.{succ u3, succ u2} \u03b2 \u03b1 g) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.range.{u2, succ u3} \u03b1 \u03b2 g)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Set.range.{u2, succ u3} \u03b1 \u03b2 g)) => f i))) (finprod.{u1, succ u3} M \u03b2 _inst_1 (fun (j : \u03b2) => f (g j))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_range finprod_mem_range\u2093'. -/\n/-- The product of `f y` over `y \u2208 set.range g` equals the product of `f (g i)` over all `i`\nprovided that `g` is injective. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 set.range g` equals the sum of `f (g i)` over all `i`\\nprovided that `g` is injective.\"]\ntheorem finprod_mem_range {g : \u03b2 \u2192 \u03b1} (hg : Injective g) : (\u220f\u1da0 i \u2208 range g, f i) = \u220f\u1da0 j, f (g j) :=\n  finprod_mem_range' (hg.InjOn _)\n#align finprod_mem_range finprod_mem_range\n#align finsum_mem_range finsum_mem_range\n\n/- warning: finprod_mem_eq_of_bij_on -> finprod_mem_eq_of_bijOn is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {s : Set.{u1} \u03b1} {t : Set.{u2} \u03b2} {f : \u03b1 -> M} {g : \u03b2 -> M} (e : \u03b1 -> \u03b2), (Set.BijOn.{u1, u2} \u03b1 \u03b2 e s t) -> (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) -> (Eq.{succ u3} M (f x) (g (e x)))) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u3, 0} M (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j t) _inst_1 (fun (H : Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j t) => g j))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {s : Set.{u3} \u03b1} {t : Set.{u2} \u03b2} {f : \u03b1 -> M} {g : \u03b2 -> M} (e : \u03b1 -> \u03b2), (Set.BijOn.{u3, u2} \u03b1 \u03b2 e s t) -> (forall (x : \u03b1), (Membership.mem.{u3, u3} \u03b1 (Set.{u3} \u03b1) (Set.instMembershipSet.{u3} \u03b1) x s) -> (Eq.{succ u1} M (f x) (g (e x)))) -> (Eq.{succ u1} M (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u3, u3} \u03b1 (Set.{u3} \u03b1) (Set.instMembershipSet.{u3} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u3, u3} \u03b1 (Set.{u3} \u03b1) (Set.instMembershipSet.{u3} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) j t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) j t) => g j))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_eq_of_bij_on finprod_mem_eq_of_bijOn\u2093'. -/\n/-- See also `finset.prod_bij`. -/\n@[to_additive \"See also `finset.sum_bij`.\"]\ntheorem finprod_mem_eq_of_bijOn {s : Set \u03b1} {t : Set \u03b2} {f : \u03b1 \u2192 M} {g : \u03b2 \u2192 M} (e : \u03b1 \u2192 \u03b2)\n    (he\u2080 : s.BijOn e t) (he\u2081 : \u2200 x \u2208 s, f x = g (e x)) : (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 j \u2208 t, g j :=\n  by\n  rw [\u2190 Set.BijOn.image_eq he\u2080, finprod_mem_image he\u2080.2.1]\n  exact finprod_mem_congr rfl he\u2081\n#align finprod_mem_eq_of_bij_on finprod_mem_eq_of_bijOn\n#align finsum_mem_eq_of_bij_on finsum_mem_eq_of_bijOn\n\n/- warning: finprod_eq_of_bijective -> finprod_eq_of_bijective is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> M} {g : \u03b2 -> M} (e : \u03b1 -> \u03b2), (Function.Bijective.{succ u1, succ u2} \u03b1 \u03b2 e) -> (forall (x : \u03b1), Eq.{succ u3} M (f x) (g (e x))) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => g j)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {g : \u03b2 -> M} (e : \u03b1 -> \u03b2), (Function.Bijective.{succ u3, succ u2} \u03b1 \u03b2 e) -> (forall (x : \u03b1), Eq.{succ u1} M (f x) (g (e x))) -> (Eq.{succ u1} M (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)) (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => g j)))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_of_bijective finprod_eq_of_bijective\u2093'. -/\n/-- See `finprod_comp`, `fintype.prod_bijective` and `finset.prod_bij`. -/\n@[to_additive \"See `finsum_comp`, `fintype.sum_bijective` and `finset.sum_bij`.\"]\ntheorem finprod_eq_of_bijective {f : \u03b1 \u2192 M} {g : \u03b2 \u2192 M} (e : \u03b1 \u2192 \u03b2) (he\u2080 : Bijective e)\n    (he\u2081 : \u2200 x, f x = g (e x)) : (\u220f\u1da0 i, f i) = \u220f\u1da0 j, g j :=\n  by\n  rw [\u2190 finprod_mem_univ f, \u2190 finprod_mem_univ g]\n  exact finprod_mem_eq_of_bijOn _ (bijective_iff_bij_on_univ.mp he\u2080) fun x _ => he\u2081 x\n#align finprod_eq_of_bijective finprod_eq_of_bijective\n#align finsum_eq_of_bijective finsum_eq_of_bijective\n\n/- warning: finprod_comp -> finprod_comp is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {g : \u03b2 -> M} (e : \u03b1 -> \u03b2), (Function.Bijective.{succ u1, succ u2} \u03b1 \u03b2 e) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => g (e i))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => g j)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {g : \u03b2 -> M} (e : \u03b1 -> \u03b2), (Function.Bijective.{succ u3, succ u2} \u03b1 \u03b2 e) -> (Eq.{succ u1} M (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (i : \u03b1) => g (e i))) (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => g j)))\nCase conversion may be inaccurate. Consider using '#align finprod_comp finprod_comp\u2093'. -/\n/-- See also `finprod_eq_of_bijective`, `fintype.prod_bijective` and `finset.prod_bij`. -/\n@[to_additive \"See also `finsum_eq_of_bijective`, `fintype.sum_bijective` and `finset.sum_bij`.\"]\ntheorem finprod_comp {g : \u03b2 \u2192 M} (e : \u03b1 \u2192 \u03b2) (he\u2080 : Function.Bijective e) :\n    (\u220f\u1da0 i, g (e i)) = \u220f\u1da0 j, g j :=\n  finprod_eq_of_bijective e he\u2080 fun x => rfl\n#align finprod_comp finprod_comp\n#align finsum_comp finsum_comp\n\n/- warning: finprod_comp_equiv -> finprod_comp_equiv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] (e : Equiv.{succ u1, succ u2} \u03b1 \u03b2) {f : \u03b2 -> M}, Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} \u03b1 \u03b2) (fun (_x : Equiv.{succ u1, succ u2} \u03b1 \u03b2) => \u03b1 -> \u03b2) (Equiv.hasCoeToFun.{succ u1, succ u2} \u03b1 \u03b2) e i))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (i' : \u03b2) => f i'))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (e : Equiv.{succ u3, succ u2} \u03b1 \u03b2) {f : \u03b2 -> M}, Eq.{succ u1} M (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (i : \u03b1) => f (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (Equiv.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : \u03b1) => \u03b2) _x) (Equiv.instFunLikeEquiv.{succ u3, succ u2} \u03b1 \u03b2) e i))) (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (i' : \u03b2) => f i'))\nCase conversion may be inaccurate. Consider using '#align finprod_comp_equiv finprod_comp_equiv\u2093'. -/\n@[to_additive]\ntheorem finprod_comp_equiv (e : \u03b1 \u2243 \u03b2) {f : \u03b2 \u2192 M} : (\u220f\u1da0 i, f (e i)) = \u220f\u1da0 i', f i' :=\n  finprod_comp e e.Bijective\n#align finprod_comp_equiv finprod_comp_equiv\n#align finsum_comp_equiv finsum_comp_equiv\n\n/- warning: finprod_set_coe_eq_finprod_mem -> finprod_set_coe_eq_finprod_mem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} (s : Set.{u1} \u03b1), Eq.{succ u2} M (finprod.{u2, succ u1} M (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) _inst_1 (fun (j : coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) => f ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeBase.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeSubtype.{succ u1} \u03b1 (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))))) j))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} (s : Set.{u2} \u03b1), Eq.{succ u1} M (finprod.{u1, succ u2} M (Set.Elem.{u2} \u03b1 s) _inst_1 (fun (j : Set.Elem.{u2} \u03b1 s) => f (Subtype.val.{succ u2} \u03b1 (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) j))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i)))\nCase conversion may be inaccurate. Consider using '#align finprod_set_coe_eq_finprod_mem finprod_set_coe_eq_finprod_mem\u2093'. -/\n@[to_additive]\ntheorem finprod_set_coe_eq_finprod_mem (s : Set \u03b1) : (\u220f\u1da0 j : s, f j) = \u220f\u1da0 i \u2208 s, f i :=\n  by\n  rw [\u2190 finprod_mem_range, Subtype.range_coe]\n  exact Subtype.coe_injective\n#align finprod_set_coe_eq_finprod_mem finprod_set_coe_eq_finprod_mem\n#align finsum_set_coe_eq_finsum_mem finsum_set_coe_eq_finsum_mem\n\n#print finprod_subtype_eq_finprod_cond /-\n@[to_additive]\ntheorem finprod_subtype_eq_finprod_cond (p : \u03b1 \u2192 Prop) :\n    (\u220f\u1da0 j : Subtype p, f j) = \u220f\u1da0 (i) (hi : p i), f i :=\n  finprod_set_coe_eq_finprod_mem { i | p i }\n#align finprod_subtype_eq_finprod_cond finprod_subtype_eq_finprod_cond\n#align finsum_subtype_eq_finsum_cond finsum_subtype_eq_finsum_cond\n-/\n\n/- warning: finprod_mem_inter_mul_diff' -> finprod_mem_inter_mul_diff' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} (t : Set.{u1} \u03b1), (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) s t)) => f i)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} (t : Set.{u2} \u03b1), (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) s t)) => f i)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_inter_mul_diff' finprod_mem_inter_mul_diff'\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_inter_mul_diff' (t : Set \u03b1) (h : (s \u2229 mulSupport f).Finite) :\n    ((\u220f\u1da0 i \u2208 s \u2229 t, f i) * \u220f\u1da0 i \u2208 s \\ t, f i) = \u220f\u1da0 i \u2208 s, f i :=\n  by\n  rw [\u2190 finprod_mem_union', inter_union_diff]\n  rw [disjoint_iff_inf_le]\n  exacts[fun x hx => hx.2.2 hx.1.2, h.subset fun x hx => \u27e8hx.1.1, hx.2\u27e9,\n    h.subset fun x hx => \u27e8hx.1.1, hx.2\u27e9]\n#align finprod_mem_inter_mul_diff' finprod_mem_inter_mul_diff'\n#align finsum_mem_inter_add_diff' finsum_mem_inter_add_diff'\n\n/- warning: finprod_mem_inter_mul_diff -> finprod_mem_inter_mul_diff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} (t : Set.{u1} \u03b1), (Set.Finite.{u1} \u03b1 s) -> (Eq.{succ u2} M (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) s t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) s t)) => f i)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} (t : Set.{u2} \u03b1), (Set.Finite.{u2} \u03b1 s) -> (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) s t)) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) s t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) s t)) => f i)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_inter_mul_diff finprod_mem_inter_mul_diff\u2093'. -/\n@[to_additive]\ntheorem finprod_mem_inter_mul_diff (t : Set \u03b1) (h : s.Finite) :\n    ((\u220f\u1da0 i \u2208 s \u2229 t, f i) * \u220f\u1da0 i \u2208 s \\ t, f i) = \u220f\u1da0 i \u2208 s, f i :=\n  finprod_mem_inter_mul_diff' _ <| h.inter_of_left _\n#align finprod_mem_inter_mul_diff finprod_mem_inter_mul_diff\n#align finsum_mem_inter_add_diff finsum_mem_inter_add_diff\n\n/- warning: finprod_mem_mul_diff' -> finprod_mem_mul_diff' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (Set.Finite.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) t (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f))) -> (Eq.{succ u2} M (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) t s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) t s)) => f i)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) s t) -> (Set.Finite.{u2} \u03b1 (Inter.inter.{u2} (Set.{u2} \u03b1) (Set.instInterSet.{u2} \u03b1) t (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f))) -> (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) t s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) t s)) => f i)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_mul_diff' finprod_mem_mul_diff'\u2093'. -/\n/-- A more general version of `finprod_mem_mul_diff` that requires `t \u2229 mul_support f` rather than\n`t` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_add_diff` that requires `t \u2229 support f` rather\\nthan `t` to be finite.\"]\ntheorem finprod_mem_mul_diff' (hst : s \u2286 t) (ht : (t \u2229 mulSupport f).Finite) :\n    ((\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t \\ s, f i) = \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst]\n#align finprod_mem_mul_diff' finprod_mem_mul_diff'\n#align finsum_mem_add_diff' finsum_mem_add_diff'\n\n/- warning: finprod_mem_mul_diff -> finprod_mem_mul_diff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (Set.Finite.{u1} \u03b1 t) -> (Eq.{succ u2} M (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) t s)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) t s)) => f i)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i t) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {s : Set.{u2} \u03b1} {t : Set.{u2} \u03b1}, (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) s t) -> (Set.Finite.{u2} \u03b1 t) -> (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i s) => f i))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) t s)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i (SDiff.sdiff.{u2} (Set.{u2} \u03b1) (Set.instSDiffSet.{u2} \u03b1) t s)) => f i)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) i t) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_mul_diff finprod_mem_mul_diff\u2093'. -/\n/-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i \u2208 s`\ntimes the product of `f i` over `t \\ s` equals the product of `f i` over `i \u2208 t`. -/\n@[to_additive\n      \"Given a finite set `t` and a subset `s` of `t`, the sum of `f i` over `i \u2208 s` plus\\nthe sum of `f i` over `t \\\\ s` equals the sum of `f i` over `i \u2208 t`.\"]\ntheorem finprod_mem_mul_diff (hst : s \u2286 t) (ht : t.Finite) :\n    ((\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t \\ s, f i) = \u220f\u1da0 i \u2208 t, f i :=\n  finprod_mem_mul_diff' hst (ht.inter_of_left _)\n#align finprod_mem_mul_diff finprod_mem_mul_diff\n#align finsum_mem_add_diff finsum_mem_add_diff\n\n/- warning: finprod_mem_Union -> finprod_mem_union\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> M} [_inst_3 : Finite.{succ u2} \u03b9] {t : \u03b9 -> (Set.{u1} \u03b1)}, (Pairwise.{u2} \u03b9 (Function.onFun.{succ u2, succ u1, 1} \u03b9 (Set.{u1} \u03b1) Prop (Disjoint.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)))) t)) -> (forall (i : \u03b9), Set.Finite.{u1} \u03b1 (t i)) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (Set.union\u1d62.{u1, succ u2} \u03b1 \u03b9 (fun (i : \u03b9) => t i))) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (Set.union\u1d62.{u1, succ u2} \u03b1 \u03b9 (fun (i : \u03b9) => t i))) => f a))) (finprod.{u3, succ u2} M \u03b9 _inst_1 (fun (i : \u03b9) => finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (t i)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (t i)) => f a)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b9 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} [_inst_3 : Finite.{succ u3} \u03b9] {t : \u03b9 -> (Set.{u2} \u03b1)}, (Pairwise.{u3} \u03b9 (Function.onFun.{succ u3, succ u2, 1} \u03b9 (Set.{u2} \u03b1) Prop (Disjoint.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1))))))) t)) -> (forall (i : \u03b9), Set.Finite.{u2} \u03b1 (t i)) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (Set.union\u1d62.{u2, succ u3} \u03b1 \u03b9 (fun (i : \u03b9) => t i))) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (Set.union\u1d62.{u2, succ u3} \u03b1 \u03b9 (fun (i : \u03b9) => t i))) => f a))) (finprod.{u1, succ u3} M \u03b9 _inst_1 (fun (i : \u03b9) => finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (t i)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (t i)) => f a)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_Union finprod_mem_union\u1d62\u2093'. -/\n/-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the product of\n`f a` over the union `\u22c3 i, t i` is equal to the product over all indexes `i` of the products of\n`f a` over `a \u2208 t i`. -/\n@[to_additive\n      \"Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the\\nsum of `f a` over the union `\u22c3 i, t i` is equal to the sum over all indexes `i` of the sums of `f a`\\nover `a \u2208 t i`.\"]\ntheorem finprod_mem_union\u1d62 [Finite \u03b9] {t : \u03b9 \u2192 Set \u03b1} (h : Pairwise (Disjoint on t))\n    (ht : \u2200 i, (t i).Finite) : (\u220f\u1da0 a \u2208 \u22c3 i : \u03b9, t i, f a) = \u220f\u1da0 i, \u220f\u1da0 a \u2208 t i, f a :=\n  by\n  cases nonempty_fintype \u03b9\n  lift t to \u03b9 \u2192 Finset \u03b1 using ht\n  classical\n    rw [\u2190 bUnion_univ, \u2190 Finset.coe_univ, \u2190 Finset.coe_bunion\u1d62, finprod_mem_coe_finset,\n      Finset.prod_bunion\u1d62]\n    \u00b7 simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype]\n    \u00b7 exact fun x _ y _ hxy => Finset.disjoint_coe.1 (h hxy)\n#align finprod_mem_Union finprod_mem_union\u1d62\n#align finsum_mem_Union finsum_mem_union\u1d62\n\n/- warning: finprod_mem_bUnion -> finprod_mem_bunion\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b9 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> M} {I : Set.{u2} \u03b9} {t : \u03b9 -> (Set.{u1} \u03b1)}, (Set.PairwiseDisjoint.{u1, u2} (Set.{u1} \u03b1) \u03b9 (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1))) I t) -> (Set.Finite.{u2} \u03b9 I) -> (forall (i : \u03b9), (Membership.Mem.{u2, u2} \u03b9 (Set.{u2} \u03b9) (Set.hasMem.{u2} \u03b9) i I) -> (Set.Finite.{u1} \u03b1 (t i))) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (Set.union\u1d62.{u1, succ u2} \u03b1 \u03b9 (fun (x : \u03b9) => Set.union\u1d62.{u1, 0} \u03b1 (Membership.Mem.{u2, u2} \u03b9 (Set.{u2} \u03b9) (Set.hasMem.{u2} \u03b9) x I) (fun (H : Membership.Mem.{u2, u2} \u03b9 (Set.{u2} \u03b9) (Set.hasMem.{u2} \u03b9) x I) => t x)))) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (Set.union\u1d62.{u1, succ u2} \u03b1 \u03b9 (fun (x : \u03b9) => Set.union\u1d62.{u1, 0} \u03b1 (Membership.Mem.{u2, u2} \u03b9 (Set.{u2} \u03b9) (Set.hasMem.{u2} \u03b9) x I) (fun (H : Membership.Mem.{u2, u2} \u03b9 (Set.{u2} \u03b9) (Set.hasMem.{u2} \u03b9) x I) => t x)))) => f a))) (finprod.{u3, succ u2} M \u03b9 _inst_1 (fun (i : \u03b9) => finprod.{u3, 0} M (Membership.Mem.{u2, u2} \u03b9 (Set.{u2} \u03b9) (Set.hasMem.{u2} \u03b9) i I) _inst_1 (fun (H : Membership.Mem.{u2, u2} \u03b9 (Set.{u2} \u03b9) (Set.hasMem.{u2} \u03b9) i I) => finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) j (t i)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) j (t i)) => f j))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b9 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {I : Set.{u3} \u03b9} {t : \u03b9 -> (Set.{u2} \u03b1)}, (Set.PairwiseDisjoint.{u2, u3} (Set.{u2} \u03b1) \u03b9 (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) I t) -> (Set.Finite.{u3} \u03b9 I) -> (forall (i : \u03b9), (Membership.mem.{u3, u3} \u03b9 (Set.{u3} \u03b9) (Set.instMembershipSet.{u3} \u03b9) i I) -> (Set.Finite.{u2} \u03b1 (t i))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (Set.union\u1d62.{u2, succ u3} \u03b1 \u03b9 (fun (x : \u03b9) => Set.union\u1d62.{u2, 0} \u03b1 (Membership.mem.{u3, u3} \u03b9 (Set.{u3} \u03b9) (Set.instMembershipSet.{u3} \u03b9) x I) (fun (H : Membership.mem.{u3, u3} \u03b9 (Set.{u3} \u03b9) (Set.instMembershipSet.{u3} \u03b9) x I) => t x)))) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (Set.union\u1d62.{u2, succ u3} \u03b1 \u03b9 (fun (x : \u03b9) => Set.union\u1d62.{u2, 0} \u03b1 (Membership.mem.{u3, u3} \u03b9 (Set.{u3} \u03b9) (Set.instMembershipSet.{u3} \u03b9) x I) (fun (H : Membership.mem.{u3, u3} \u03b9 (Set.{u3} \u03b9) (Set.instMembershipSet.{u3} \u03b9) x I) => t x)))) => f a))) (finprod.{u1, succ u3} M \u03b9 _inst_1 (fun (i : \u03b9) => finprod.{u1, 0} M (Membership.mem.{u3, u3} \u03b9 (Set.{u3} \u03b9) (Set.instMembershipSet.{u3} \u03b9) i I) _inst_1 (fun (H : Membership.mem.{u3, u3} \u03b9 (Set.{u3} \u03b9) (Set.instMembershipSet.{u3} \u03b9) i I) => finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (j : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) j (t i)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) j (t i)) => f j))))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_bUnion finprod_mem_bunion\u1d62\u2093'. -/\n/-- Given a family of sets `t : \u03b9 \u2192 set \u03b1`, a finite set `I` in the index type such that all sets\n`t i`, `i \u2208 I`, are finite, if all `t i`, `i \u2208 I`, are pairwise disjoint, then the product of `f a`\nover `a \u2208 \u22c3 i \u2208 I, t i` is equal to the product over `i \u2208 I` of the products of `f a` over\n`a \u2208 t i`. -/\n@[to_additive\n      \"Given a family of sets `t : \u03b9 \u2192 set \u03b1`, a finite set `I` in the index type such that\\nall sets `t i`, `i \u2208 I`, are finite, if all `t i`, `i \u2208 I`, are pairwise disjoint, then the sum of\\n`f a` over `a \u2208 \u22c3 i \u2208 I, t i` is equal to the sum over `i \u2208 I` of the sums of `f a` over\\n`a \u2208 t i`.\"]\ntheorem finprod_mem_bunion\u1d62 {I : Set \u03b9} {t : \u03b9 \u2192 Set \u03b1} (h : I.PairwiseDisjoint t) (hI : I.Finite)\n    (ht : \u2200 i \u2208 I, (t i).Finite) : (\u220f\u1da0 a \u2208 \u22c3 x \u2208 I, t x, f a) = \u220f\u1da0 i \u2208 I, \u220f\u1da0 j \u2208 t i, f j :=\n  by\n  haveI := hI.fintype\n  rw [bUnion_eq_Union, finprod_mem_union\u1d62, \u2190 finprod_set_coe_eq_finprod_mem]\n  exacts[fun x y hxy => h x.2 y.2 (subtype.coe_injective.ne hxy), fun b => ht b b.2]\n#align finprod_mem_bUnion finprod_mem_bunion\u1d62\n#align finsum_mem_bUnion finsum_mem_bunion\u1d62\n\n/- warning: finprod_mem_sUnion -> finprod_mem_union\u209b is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {t : Set.{u1} (Set.{u1} \u03b1)}, (Set.PairwiseDisjoint.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1))) t (id.{succ u1} (Set.{u1} \u03b1))) -> (Set.Finite.{u1} (Set.{u1} \u03b1) t) -> (forall (x : Set.{u1} \u03b1), (Membership.Mem.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasMem.{u1} (Set.{u1} \u03b1)) x t) -> (Set.Finite.{u1} \u03b1 x)) -> (Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (Set.union\u209b.{u1} \u03b1 t)) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (Set.union\u209b.{u1} \u03b1 t)) => f a))) (finprod.{u2, succ u1} M (Set.{u1} \u03b1) _inst_1 (fun (s : Set.{u1} \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasMem.{u1} (Set.{u1} \u03b1)) s t) _inst_1 (fun (H : Membership.Mem.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasMem.{u1} (Set.{u1} \u03b1)) s t) => finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) => f a))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} {t : Set.{u2} (Set.{u2} \u03b1)}, (Set.PairwiseDisjoint.{u2, u2} (Set.{u2} \u03b1) (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u2} (Set.{u2} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) t (id.{succ u2} (Set.{u2} \u03b1))) -> (Set.Finite.{u2} (Set.{u2} \u03b1) t) -> (forall (x : Set.{u2} \u03b1), (Membership.mem.{u2, u2} (Set.{u2} \u03b1) (Set.{u2} (Set.{u2} \u03b1)) (Set.instMembershipSet.{u2} (Set.{u2} \u03b1)) x t) -> (Set.Finite.{u2} \u03b1 x)) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (Set.union\u209b.{u2} \u03b1 t)) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a (Set.union\u209b.{u2} \u03b1 t)) => f a))) (finprod.{u1, succ u2} M (Set.{u2} \u03b1) _inst_1 (fun (s : Set.{u2} \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} (Set.{u2} \u03b1) (Set.{u2} (Set.{u2} \u03b1)) (Set.instMembershipSet.{u2} (Set.{u2} \u03b1)) s t) _inst_1 (fun (H : Membership.mem.{u2, u2} (Set.{u2} \u03b1) (Set.{u2} (Set.{u2} \u03b1)) (Set.instMembershipSet.{u2} (Set.{u2} \u03b1)) s t) => finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) => f a))))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_sUnion finprod_mem_union\u209b\u2093'. -/\n/-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a`\nover `a \u2208 \u22c3\u2080 t` is the product over `s \u2208 t` of the products of `f a` over `a \u2208 s`. -/\n@[to_additive\n      \"If `t` is a finite set of pairwise disjoint finite sets, then the sum of `f a` over\\n`a \u2208 \u22c3\u2080 t` is the sum over `s \u2208 t` of the sums of `f a` over `a \u2208 s`.\"]\ntheorem finprod_mem_union\u209b {t : Set (Set \u03b1)} (h : t.PairwiseDisjoint id) (ht\u2080 : t.Finite)\n    (ht\u2081 : \u2200 x \u2208 t, Set.Finite x) : (\u220f\u1da0 a \u2208 \u22c3\u2080 t, f a) = \u220f\u1da0 s \u2208 t, \u220f\u1da0 a \u2208 s, f a :=\n  by\n  rw [Set.union\u209b_eq_bunion\u1d62]\n  exact finprod_mem_bunion\u1d62 h ht\u2080 ht\u2081\n#align finprod_mem_sUnion finprod_mem_union\u209b\n#align finsum_mem_sUnion finsum_mem_union\u209b\n\n/- warning: mul_finprod_cond_ne -> mul_finprod_cond_ne is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} (a : \u03b1), (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))) f)) -> (Eq.{succ u2} M (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) (f a) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Ne.{succ u1} \u03b1 i a) _inst_1 (fun (H : Ne.{succ u1} \u03b1 i a) => f i)))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> M} (a : \u03b1), (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) -> (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))) (f a) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Ne.{succ u2} \u03b1 i a) _inst_1 (fun (H : Ne.{succ u2} \u03b1 i a) => f i)))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (i : \u03b1) => f i)))\nCase conversion may be inaccurate. Consider using '#align mul_finprod_cond_ne mul_finprod_cond_ne\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (i \u00abexpr \u2260 \u00bb a) -/\n@[to_additive]\ntheorem mul_finprod_cond_ne (a : \u03b1) (hf : (mulSupport f).Finite) :\n    (f a * \u220f\u1da0 (i) (_ : i \u2260 a), f i) = \u220f\u1da0 i, f i := by\n  classical\n    rw [finprod_eq_prod _ hf]\n    have h : \u2200 x : \u03b1, f x \u2260 1 \u2192 (x \u2260 a \u2194 x \u2208 hf.to_finset \\ {a}) :=\n      by\n      intro x hx\n      rw [Finset.mem_sdiff, Finset.mem_singleton, finite.mem_to_finset, mem_mul_support]\n      exact \u27e8fun h => And.intro hx h, fun h => h.2\u27e9\n    rw [finprod_cond_eq_prod_of_cond_iff f h, Finset.sdiff_singleton_eq_erase]\n    by_cases ha : a \u2208 mul_support f\n    \u00b7 apply Finset.mul_prod_erase _ _ ((finite.mem_to_finset _).mpr ha)\n    \u00b7 rw [mem_mul_support, Classical.not_not] at ha\n      rw [ha, one_mul]\n      apply Finset.prod_erase _ ha\n#align mul_finprod_cond_ne mul_finprod_cond_ne\n#align add_finsum_cond_ne add_finsum_cond_ne\n\n/- warning: finprod_mem_comm -> finprod_mem_comm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {s : Set.{u1} \u03b1} {t : Set.{u2} \u03b2} (f : \u03b1 -> \u03b2 -> M), (Set.Finite.{u1} \u03b1 s) -> (Set.Finite.{u2} \u03b2 t) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u3, 0} M (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j t) _inst_1 (fun (H : Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j t) => f i j))))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u3, 0} M (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j t) _inst_1 (fun (H : Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) j t) => finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u3, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i j))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {s : Set.{u3} \u03b1} {t : Set.{u2} \u03b2} (f : \u03b1 -> \u03b2 -> M), (Set.Finite.{u3} \u03b1 s) -> (Set.Finite.{u2} \u03b2 t) -> (Eq.{succ u1} M (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u3, u3} \u03b1 (Set.{u3} \u03b1) (Set.instMembershipSet.{u3} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u3, u3} \u03b1 (Set.{u3} \u03b1) (Set.instMembershipSet.{u3} \u03b1) i s) => finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) j t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) j t) => f i j))))) (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (j : \u03b2) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) j t) _inst_1 (fun (H : Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) j t) => finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u3, u3} \u03b1 (Set.{u3} \u03b1) (Set.instMembershipSet.{u3} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u3, u3} \u03b1 (Set.{u3} \u03b1) (Set.instMembershipSet.{u3} \u03b1) i s) => f i j))))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_comm finprod_mem_comm\u2093'. -/\n/-- If `s : set \u03b1` and `t : set \u03b2` are finite sets, then taking the product over `s` commutes with\ntaking the product over `t`. -/\n@[to_additive\n      \"If `s : set \u03b1` and `t : set \u03b2` are finite sets, then summing over `s` commutes with\\nsumming over `t`.\"]\ntheorem finprod_mem_comm {s : Set \u03b1} {t : Set \u03b2} (f : \u03b1 \u2192 \u03b2 \u2192 M) (hs : s.Finite) (ht : t.Finite) :\n    (\u220f\u1da0 i \u2208 s, \u220f\u1da0 j \u2208 t, f i j) = \u220f\u1da0 j \u2208 t, \u220f\u1da0 i \u2208 s, f i j :=\n  by\n  lift s to Finset \u03b1 using hs; lift t to Finset \u03b2 using ht\n  simp only [finprod_mem_coe_finset]\n  exact Finset.prod_comm\n#align finprod_mem_comm finprod_mem_comm\n#align finsum_mem_comm finsum_mem_comm\n\n/- warning: finprod_mem_induction -> finprod_mem_induction is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} (p : M -> Prop), (p (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))))) -> (forall (x : M) (y : M), (p x) -> (p y) -> (p (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toHasMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) x y))) -> (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) -> (p (f x))) -> (p (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) i s) => f i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {f : \u03b1 -> M} {s : Set.{u1} \u03b1} (p : M -> Prop), (p (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1))))) -> (forall (x : M) (y : M), (p x) -> (p y) -> (p (HMul.hMul.{u2, u2, u2} M M M (instHMul.{u2} M (MulOneClass.toMul.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))) x y))) -> (forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) -> (p (f x))) -> (p (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (i : \u03b1) => finprod.{u2, 0} M (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) _inst_1 (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) i s) => f i))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_induction finprod_mem_induction\u2093'. -/\n/-- To prove a property of a finite product, it suffices to prove that the property is\nmultiplicative and holds on factors. -/\n@[to_additive\n      \"To prove a property of a finite sum, it suffices to prove that the property is\\nadditive and holds on summands.\"]\ntheorem finprod_mem_induction (p : M \u2192 Prop) (hp\u2080 : p 1) (hp\u2081 : \u2200 x y, p x \u2192 p y \u2192 p (x * y))\n    (hp\u2082 : \u2200 x \u2208 s, p <| f x) : p (\u220f\u1da0 i \u2208 s, f i) :=\n  finprod_induction _ hp\u2080 hp\u2081 fun x => finprod_induction _ hp\u2080 hp\u2081 <| hp\u2082 x\n#align finprod_mem_induction finprod_mem_induction\n#align finsum_mem_induction finsum_mem_induction\n\n/- warning: finprod_cond_nonneg -> finprod_cond_nonneg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {R : Type.{u2}} [_inst_3 : OrderedCommSemiring.{u2} R] {p : \u03b1 -> Prop} {f : \u03b1 -> R}, (forall (x : \u03b1), (p x) -> (LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedAddCommMonoid.toPartialOrder.{u2} R (OrderedSemiring.toOrderedAddCommMonoid.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))) (OfNat.ofNat.{u2} R 0 (OfNat.mk.{u2} R 0 (Zero.zero.{u2} R (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (OrderedSemiring.toSemiring.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))))))) (f x))) -> (LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedAddCommMonoid.toPartialOrder.{u2} R (OrderedSemiring.toOrderedAddCommMonoid.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))) (OfNat.ofNat.{u2} R 0 (OfNat.mk.{u2} R 0 (Zero.zero.{u2} R (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (OrderedSemiring.toSemiring.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3))))))))) (finprod.{u2, succ u1} R \u03b1 (CommSemiring.toCommMonoid.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3)) (fun (x : \u03b1) => finprod.{u2, 0} R (p x) (CommSemiring.toCommMonoid.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3)) (fun (h : p x) => f x))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {R : Type.{u2}} [_inst_3 : OrderedCommSemiring.{u2} R] {p : \u03b1 -> Prop} {f : \u03b1 -> R}, (forall (x : \u03b1), (p x) -> (LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedSemiring.toPartialOrder.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3)))) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (CommMonoidWithZero.toZero.{u2} R (CommSemiring.toCommMonoidWithZero.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3))))) (f x))) -> (LE.le.{u2} R (Preorder.toLE.{u2} R (PartialOrder.toPreorder.{u2} R (OrderedSemiring.toPartialOrder.{u2} R (OrderedCommSemiring.toOrderedSemiring.{u2} R _inst_3)))) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (CommMonoidWithZero.toZero.{u2} R (CommSemiring.toCommMonoidWithZero.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3))))) (finprod.{u2, succ u1} R \u03b1 (CommSemiring.toCommMonoid.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3)) (fun (x : \u03b1) => finprod.{u2, 0} R (p x) (CommSemiring.toCommMonoid.{u2} R (OrderedCommSemiring.toCommSemiring.{u2} R _inst_3)) (fun (h : p x) => f x))))\nCase conversion may be inaccurate. Consider using '#align finprod_cond_nonneg finprod_cond_nonneg\u2093'. -/\ntheorem finprod_cond_nonneg {R : Type _} [OrderedCommSemiring R] {p : \u03b1 \u2192 Prop} {f : \u03b1 \u2192 R}\n    (hf : \u2200 x, p x \u2192 0 \u2264 f x) : 0 \u2264 \u220f\u1da0 (x) (h : p x), f x :=\n  finprod_nonneg fun x => finprod_nonneg <| hf x\n#align finprod_cond_nonneg finprod_cond_nonneg\n\n/- warning: single_le_finprod -> single_le_finprod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_3 : OrderedCommMonoid.{u2} M] (i : \u03b1) {f : \u03b1 -> M}, (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3)))) f)) -> (forall (j : \u03b1), LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3))))))) (f j)) -> (LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (f i) (finprod.{u2, succ u1} M \u03b1 (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3) (fun (j : \u03b1) => f j)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_3 : OrderedCommMonoid.{u2} M] (i : \u03b1) {f : \u03b1 -> M}, (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3))) f)) -> (forall (j : \u03b1), LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (OfNat.ofNat.{u2} M 1 (One.toOfNat1.{u2} M (Monoid.toOne.{u2} M (CommMonoid.toMonoid.{u2} M (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3))))) (f j)) -> (LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (OrderedCommMonoid.toPartialOrder.{u2} M _inst_3))) (f i) (finprod.{u2, succ u1} M \u03b1 (OrderedCommMonoid.toCommMonoid.{u2} M _inst_3) (fun (j : \u03b1) => f j)))\nCase conversion may be inaccurate. Consider using '#align single_le_finprod single_le_finprod\u2093'. -/\n@[to_additive]\ntheorem single_le_finprod {M : Type _} [OrderedCommMonoid M] (i : \u03b1) {f : \u03b1 \u2192 M}\n    (hf : (mulSupport f).Finite) (h : \u2200 j, 1 \u2264 f j) : f i \u2264 \u220f\u1da0 j, f j := by\n  classical calc\n      f i \u2264 \u220f j in insert i hf.to_finset, f j :=\n        Finset.single_le_prod' (fun j hj => h j) (Finset.mem_insert_self _ _)\n      _ = \u220f\u1da0 j, f j :=\n        (finprod_eq_prod_of_mulSupport_toFinset_subset _ hf (Finset.subset_insert _ _)).symm\n      \n#align single_le_finprod single_le_finprod\n#align single_le_finsum single_le_finsum\n\n/- warning: finprod_eq_zero -> finprod_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M\u2080 : Type.{u2}} [_inst_3 : CommMonoidWithZero.{u2} M\u2080] (f : \u03b1 -> M\u2080) (x : \u03b1), (Eq.{succ u2} M\u2080 (f x) (OfNat.ofNat.{u2} M\u2080 0 (OfNat.mk.{u2} M\u2080 0 (Zero.zero.{u2} M\u2080 (MulZeroClass.toHasZero.{u2} M\u2080 (MulZeroOneClass.toMulZeroClass.{u2} M\u2080 (MonoidWithZero.toMulZeroOneClass.{u2} M\u2080 (CommMonoidWithZero.toMonoidWithZero.{u2} M\u2080 _inst_3)))))))) -> (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M\u2080 (MulOneClass.toHasOne.{u2} M\u2080 (MulZeroOneClass.toMulOneClass.{u2} M\u2080 (MonoidWithZero.toMulZeroOneClass.{u2} M\u2080 (CommMonoidWithZero.toMonoidWithZero.{u2} M\u2080 _inst_3)))) f)) -> (Eq.{succ u2} M\u2080 (finprod.{u2, succ u1} M\u2080 \u03b1 (CommMonoidWithZero.toCommMonoid.{u2} M\u2080 _inst_3) (fun (x : \u03b1) => f x)) (OfNat.ofNat.{u2} M\u2080 0 (OfNat.mk.{u2} M\u2080 0 (Zero.zero.{u2} M\u2080 (MulZeroClass.toHasZero.{u2} M\u2080 (MulZeroOneClass.toMulZeroClass.{u2} M\u2080 (MonoidWithZero.toMulZeroOneClass.{u2} M\u2080 (CommMonoidWithZero.toMonoidWithZero.{u2} M\u2080 _inst_3))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {M\u2080 : Type.{u2}} [_inst_3 : CommMonoidWithZero.{u2} M\u2080] (f : \u03b1 -> M\u2080) (x : \u03b1), (Eq.{succ u2} M\u2080 (f x) (OfNat.ofNat.{u2} M\u2080 0 (Zero.toOfNat0.{u2} M\u2080 (CommMonoidWithZero.toZero.{u2} M\u2080 _inst_3)))) -> (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u2} \u03b1 M\u2080 (Monoid.toOne.{u2} M\u2080 (MonoidWithZero.toMonoid.{u2} M\u2080 (CommMonoidWithZero.toMonoidWithZero.{u2} M\u2080 _inst_3))) f)) -> (Eq.{succ u2} M\u2080 (finprod.{u2, succ u1} M\u2080 \u03b1 (CommMonoidWithZero.toCommMonoid.{u2} M\u2080 _inst_3) (fun (x : \u03b1) => f x)) (OfNat.ofNat.{u2} M\u2080 0 (Zero.toOfNat0.{u2} M\u2080 (CommMonoidWithZero.toZero.{u2} M\u2080 _inst_3))))\nCase conversion may be inaccurate. Consider using '#align finprod_eq_zero finprod_eq_zero\u2093'. -/\ntheorem finprod_eq_zero {M\u2080 : Type _} [CommMonoidWithZero M\u2080] (f : \u03b1 \u2192 M\u2080) (x : \u03b1) (hx : f x = 0)\n    (hf : (mulSupport f).Finite) : (\u220f\u1da0 x, f x) = 0 :=\n  by\n  nontriviality\n  rw [finprod_eq_prod f hf]\n  refine' Finset.prod_eq_zero (hf.mem_to_finset.2 _) hx\n  simp [hx]\n#align finprod_eq_zero finprod_eq_zero\n\n/- warning: finprod_prod_comm -> finprod_prod_comm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] (s : Finset.{u2} \u03b2) (f : \u03b1 -> \u03b2 -> M), (forall (b : \u03b2), (Membership.Mem.{u2, u2} \u03b2 (Finset.{u2} \u03b2) (Finset.hasMem.{u2} \u03b2) b s) -> (Set.Finite.{u1} \u03b1 (Function.mulSupport.{u1, u3} \u03b1 M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (fun (a : \u03b1) => f a b)))) -> (Eq.{succ u3} M (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => Finset.prod.{u3, u2} M \u03b2 _inst_1 s (fun (b : \u03b2) => f a b))) (Finset.prod.{u3, u2} M \u03b2 _inst_1 s (fun (b : \u03b2) => finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => f a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (s : Finset.{u3} \u03b2) (f : \u03b1 -> \u03b2 -> M), (forall (b : \u03b2), (Membership.mem.{u3, u3} \u03b2 (Finset.{u3} \u03b2) (Finset.instMembershipFinset.{u3} \u03b2) b s) -> (Set.Finite.{u2} \u03b1 (Function.mulSupport.{u2, u1} \u03b1 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (fun (a : \u03b1) => f a b)))) -> (Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => Finset.prod.{u1, u3} M \u03b2 _inst_1 s (fun (b : \u03b2) => f a b))) (Finset.prod.{u1, u3} M \u03b2 _inst_1 s (fun (b : \u03b2) => finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => f a b))))\nCase conversion may be inaccurate. Consider using '#align finprod_prod_comm finprod_prod_comm\u2093'. -/\n@[to_additive]\ntheorem finprod_prod_comm (s : Finset \u03b2) (f : \u03b1 \u2192 \u03b2 \u2192 M)\n    (h : \u2200 b \u2208 s, (mulSupport fun a => f a b).Finite) :\n    (\u220f\u1da0 a : \u03b1, \u220f b in s, f a b) = \u220f b in s, \u220f\u1da0 a : \u03b1, f a b :=\n  by\n  have hU :\n    (mul_support fun a => \u220f b in s, f a b) \u2286\n      (s.finite_to_set.bUnion fun b hb => h b (Finset.mem_coe.1 hb)).toFinset :=\n    by\n    rw [finite.coe_to_finset]\n    intro x hx\n    simp only [exists_prop, mem_Union, Ne.def, mem_mul_support, Finset.mem_coe]\n    contrapose! hx\n    rw [mem_mul_support, Classical.not_not, Finset.prod_congr rfl hx, Finset.prod_const_one]\n  rw [finprod_eq_prod_of_mulSupport_subset _ hU, Finset.prod_comm]\n  refine' Finset.prod_congr rfl fun b hb => (finprod_eq_prod_of_mulSupport_subset _ _).symm\n  intro a ha\n  simp only [finite.coe_to_finset, mem_Union]\n  exact \u27e8b, hb, ha\u27e9\n#align finprod_prod_comm finprod_prod_comm\n#align finsum_sum_comm finsum_sum_comm\n\n/- warning: prod_finprod_comm -> prod_finprod_comm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] (s : Finset.{u1} \u03b1) (f : \u03b1 -> \u03b2 -> M), (forall (a : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Finset.{u1} \u03b1) (Finset.hasMem.{u1} \u03b1) a s) -> (Set.Finite.{u2} \u03b2 (Function.mulSupport.{u2, u3} \u03b2 M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (f a)))) -> (Eq.{succ u3} M (Finset.prod.{u3, u1} M \u03b1 _inst_1 s (fun (a : \u03b1) => finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => f a b))) (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => Finset.prod.{u3, u1} M \u03b1 _inst_1 s (fun (a : \u03b1) => f a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (s : Finset.{u3} \u03b1) (f : \u03b1 -> \u03b2 -> M), (forall (a : \u03b1), (Membership.mem.{u3, u3} \u03b1 (Finset.{u3} \u03b1) (Finset.instMembershipFinset.{u3} \u03b1) a s) -> (Set.Finite.{u2} \u03b2 (Function.mulSupport.{u2, u1} \u03b2 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (f a)))) -> (Eq.{succ u1} M (Finset.prod.{u1, u3} M \u03b1 _inst_1 s (fun (a : \u03b1) => finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => f a b))) (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => Finset.prod.{u1, u3} M \u03b1 _inst_1 s (fun (a : \u03b1) => f a b))))\nCase conversion may be inaccurate. Consider using '#align prod_finprod_comm prod_finprod_comm\u2093'. -/\n@[to_additive]\ntheorem prod_finprod_comm (s : Finset \u03b1) (f : \u03b1 \u2192 \u03b2 \u2192 M) (h : \u2200 a \u2208 s, (mulSupport (f a)).Finite) :\n    (\u220f a in s, \u220f\u1da0 b : \u03b2, f a b) = \u220f\u1da0 b : \u03b2, \u220f a in s, f a b :=\n  (finprod_prod_comm s (fun b a => f a b) h).symm\n#align prod_finprod_comm prod_finprod_comm\n#align sum_finsum_comm sum_finsum_comm\n\n/- warning: mul_finsum -> mul_finsum is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {R : Type.{u2}} [_inst_3 : Semiring.{u2} R] (f : \u03b1 -> R) (r : R), (Set.Finite.{u1} \u03b1 (Function.support.{u1, u2} \u03b1 R (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3)))) f)) -> (Eq.{succ u2} R (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (Distrib.toHasMul.{u2} R (NonUnitalNonAssocSemiring.toDistrib.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))))) r (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => f a))) (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (Distrib.toHasMul.{u2} R (NonUnitalNonAssocSemiring.toDistrib.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))))) r (f a))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {R : Type.{u2}} [_inst_3 : Semiring.{u2} R] (f : \u03b1 -> R) (r : R), (Set.Finite.{u1} \u03b1 (Function.support.{u1, u2} \u03b1 R (MonoidWithZero.toZero.{u2} R (Semiring.toMonoidWithZero.{u2} R _inst_3)) f)) -> (Eq.{succ u2} R (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3)))) r (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => f a))) (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3)))) r (f a))))\nCase conversion may be inaccurate. Consider using '#align mul_finsum mul_finsum\u2093'. -/\ntheorem mul_finsum {R : Type _} [Semiring R] (f : \u03b1 \u2192 R) (r : R) (h : (support f).Finite) :\n    (r * \u2211\u1da0 a : \u03b1, f a) = \u2211\u1da0 a : \u03b1, r * f a :=\n  (AddMonoidHom.mulLeft r).map_finsum h\n#align mul_finsum mul_finsum\n\n/- warning: finsum_mul -> finsum_mul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {R : Type.{u2}} [_inst_3 : Semiring.{u2} R] (f : \u03b1 -> R) (r : R), (Set.Finite.{u1} \u03b1 (Function.support.{u1, u2} \u03b1 R (MulZeroClass.toHasZero.{u2} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3)))) f)) -> (Eq.{succ u2} R (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (Distrib.toHasMul.{u2} R (NonUnitalNonAssocSemiring.toDistrib.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))))) (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => f a)) r) (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (Distrib.toHasMul.{u2} R (NonUnitalNonAssocSemiring.toDistrib.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))))) (f a) r)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {R : Type.{u2}} [_inst_3 : Semiring.{u2} R] (f : \u03b1 -> R) (r : R), (Set.Finite.{u1} \u03b1 (Function.support.{u1, u2} \u03b1 R (MonoidWithZero.toZero.{u2} R (Semiring.toMonoidWithZero.{u2} R _inst_3)) f)) -> (Eq.{succ u2} R (HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3)))) (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => f a)) r) (finsum.{u2, succ u1} R \u03b1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3))) (fun (a : \u03b1) => HMul.hMul.{u2, u2, u2} R R R (instHMul.{u2} R (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_3)))) (f a) r)))\nCase conversion may be inaccurate. Consider using '#align finsum_mul finsum_mul\u2093'. -/\ntheorem finsum_mul {R : Type _} [Semiring R] (f : \u03b1 \u2192 R) (r : R) (h : (support f).Finite) :\n    (\u2211\u1da0 a : \u03b1, f a) * r = \u2211\u1da0 a : \u03b1, f a * r :=\n  (AddMonoidHom.mulRight r).map_finsum h\n#align finsum_mul finsum_mul\n\n/- warning: finset.mul_support_of_fiberwise_prod_subset_image -> Finset.mulSupport_of_fiberwise_prod_subset_image is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] [_inst_3 : DecidableEq.{succ u2} \u03b2] (s : Finset.{u1} \u03b1) (f : \u03b1 -> M) (g : \u03b1 -> \u03b2), HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.hasSubset.{u2} \u03b2) (Function.mulSupport.{u2, u3} \u03b2 M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) (fun (b : \u03b2) => Finset.prod.{u3, u1} M \u03b1 _inst_1 (Finset.filter.{u1} \u03b1 (fun (a : \u03b1) => Eq.{succ u2} \u03b2 (g a) b) (fun (a : \u03b1) => _inst_3 (g a) b) s) f)) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Finset.{u2} \u03b2) (Set.{u2} \u03b2) (HasLiftT.mk.{succ u2, succ u2} (Finset.{u2} \u03b2) (Set.{u2} \u03b2) (CoeTC\u2093.coe.{succ u2, succ u2} (Finset.{u2} \u03b2) (Set.{u2} \u03b2) (Finset.Set.hasCoeT.{u2} \u03b2))) (Finset.image.{u1, u2} \u03b1 \u03b2 (fun (a : \u03b2) (b : \u03b2) => _inst_3 a b) g s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] [_inst_3 : DecidableEq.{succ u3} \u03b2] (s : Finset.{u2} \u03b1) (f : \u03b1 -> M) (g : \u03b1 -> \u03b2), HasSubset.Subset.{u3} (Set.{u3} \u03b2) (Set.instHasSubsetSet.{u3} \u03b2) (Function.mulSupport.{u3, u1} \u03b2 M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) (fun (b : \u03b2) => Finset.prod.{u1, u2} M \u03b1 _inst_1 (Finset.filter.{u2} \u03b1 (fun (a : \u03b1) => Eq.{succ u3} \u03b2 (g a) b) (fun (a : \u03b1) => _inst_3 (g a) b) s) f)) (Finset.toSet.{u3} \u03b2 (Finset.image.{u2, u3} \u03b1 \u03b2 (fun (a : \u03b2) (b : \u03b2) => _inst_3 a b) g s))\nCase conversion may be inaccurate. Consider using '#align finset.mul_support_of_fiberwise_prod_subset_image Finset.mulSupport_of_fiberwise_prod_subset_image\u2093'. -/\n@[to_additive]\ntheorem Finset.mulSupport_of_fiberwise_prod_subset_image [DecidableEq \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 M)\n    (g : \u03b1 \u2192 \u03b2) : (mulSupport fun b => (s.filter\u2093 fun a => g a = b).Prod f) \u2286 s.image g :=\n  by\n  simp only [Finset.coe_image, Set.mem_image, Finset.mem_coe, Function.support_subset_iff]\n  intro b h\n  suffices (s.filter fun a : \u03b1 => g a = b).Nonempty by\n    simpa only [s.fiber_nonempty_iff_mem_image g b, Finset.mem_image, exists_prop]\n  exact Finset.nonempty_of_prod_ne_one h\n#align finset.mul_support_of_fiberwise_prod_subset_image Finset.mulSupport_of_fiberwise_prod_subset_image\n#align finset.support_of_fiberwise_sum_subset_image Finset.support_of_fiberwise_sum_subset_image\n\n/- warning: finprod_mem_finset_product' -> finprod_mem_finset_product' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] [_inst_3 : DecidableEq.{succ u1} \u03b1] [_inst_4 : DecidableEq.{succ u2} \u03b2] (s : Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (f : (Prod.{u1, u2} \u03b1 \u03b2) -> M), Eq.{succ u3} M (finprod.{u3, succ (max u1 u2)} M (Prod.{u1, u2} \u03b1 \u03b2) _inst_1 (fun (ab : Prod.{u1, u2} \u03b1 \u03b2) => finprod.{u3, 0} M (Membership.Mem.{max u1 u2, max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Finset.hasMem.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ab s) _inst_1 (fun (h : Membership.Mem.{max u1 u2, max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Finset.hasMem.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ab s) => f ab))) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u3, 0} M (Membership.Mem.{u2, u2} \u03b2 (Finset.{u2} \u03b2) (Finset.hasMem.{u2} \u03b2) b (Finset.image.{max u1 u2, u2} (Prod.{u1, u2} \u03b1 \u03b2) \u03b2 (fun (a : \u03b2) (b : \u03b2) => _inst_4 a b) (Prod.snd.{u1, u2} \u03b1 \u03b2) (Finset.filter.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (fun (ab : Prod.{u1, u2} \u03b1 \u03b2) => Eq.{succ u1} \u03b1 (Prod.fst.{u1, u2} \u03b1 \u03b2 ab) a) (fun (a_1 : Prod.{u1, u2} \u03b1 \u03b2) => _inst_3 (Prod.fst.{u1, u2} \u03b1 \u03b2 a_1) a) s))) _inst_1 (fun (h : Membership.Mem.{u2, u2} \u03b2 (Finset.{u2} \u03b2) (Finset.hasMem.{u2} \u03b2) b (Finset.image.{max u1 u2, u2} (Prod.{u1, u2} \u03b1 \u03b2) \u03b2 (fun (a : \u03b2) (b : \u03b2) => _inst_4 a b) (Prod.snd.{u1, u2} \u03b1 \u03b2) (Finset.filter.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (fun (ab : Prod.{u1, u2} \u03b1 \u03b2) => Eq.{succ u1} \u03b1 (Prod.fst.{u1, u2} \u03b1 \u03b2 ab) a) (fun (a_1 : Prod.{u1, u2} \u03b1 \u03b2) => _inst_3 (Prod.fst.{u1, u2} \u03b1 \u03b2 a_1) a) s))) => f (Prod.mk.{u1, u2} \u03b1 \u03b2 a b)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] [_inst_3 : DecidableEq.{succ u3} \u03b1] [_inst_4 : DecidableEq.{succ u2} \u03b2] (s : Finset.{max u2 u3} (Prod.{u3, u2} \u03b1 \u03b2)) (f : (Prod.{u3, u2} \u03b1 \u03b2) -> M), Eq.{succ u1} M (finprod.{u1, succ (max u3 u2)} M (Prod.{u3, u2} \u03b1 \u03b2) _inst_1 (fun (ab : Prod.{u3, u2} \u03b1 \u03b2) => finprod.{u1, 0} M (Membership.mem.{max u3 u2, max u3 u2} (Prod.{u3, u2} \u03b1 \u03b2) (Finset.{max u2 u3} (Prod.{u3, u2} \u03b1 \u03b2)) (Finset.instMembershipFinset.{max u3 u2} (Prod.{u3, u2} \u03b1 \u03b2)) ab s) _inst_1 (fun (h : Membership.mem.{max u3 u2, max u3 u2} (Prod.{u3, u2} \u03b1 \u03b2) (Finset.{max u2 u3} (Prod.{u3, u2} \u03b1 \u03b2)) (Finset.instMembershipFinset.{max u3 u2} (Prod.{u3, u2} \u03b1 \u03b2)) ab s) => f ab))) (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b2 (Finset.{u2} \u03b2) (Finset.instMembershipFinset.{u2} \u03b2) b (Finset.image.{max u2 u3, u2} (Prod.{u3, u2} \u03b1 \u03b2) \u03b2 (fun (a : \u03b2) (b : \u03b2) => _inst_4 a b) (Prod.snd.{u3, u2} \u03b1 \u03b2) (Finset.filter.{max u2 u3} (Prod.{u3, u2} \u03b1 \u03b2) (fun (ab : Prod.{u3, u2} \u03b1 \u03b2) => Eq.{succ u3} \u03b1 (Prod.fst.{u3, u2} \u03b1 \u03b2 ab) a) (fun (a_1 : Prod.{u3, u2} \u03b1 \u03b2) => _inst_3 (Prod.fst.{u3, u2} \u03b1 \u03b2 a_1) a) s))) _inst_1 (fun (h : Membership.mem.{u2, u2} \u03b2 (Finset.{u2} \u03b2) (Finset.instMembershipFinset.{u2} \u03b2) b (Finset.image.{max u2 u3, u2} (Prod.{u3, u2} \u03b1 \u03b2) \u03b2 (fun (a : \u03b2) (b : \u03b2) => _inst_4 a b) (Prod.snd.{u3, u2} \u03b1 \u03b2) (Finset.filter.{max u2 u3} (Prod.{u3, u2} \u03b1 \u03b2) (fun (ab : Prod.{u3, u2} \u03b1 \u03b2) => Eq.{succ u3} \u03b1 (Prod.fst.{u3, u2} \u03b1 \u03b2 ab) a) (fun (a_1 : Prod.{u3, u2} \u03b1 \u03b2) => _inst_3 (Prod.fst.{u3, u2} \u03b1 \u03b2 a_1) a) s))) => f (Prod.mk.{u3, u2} \u03b1 \u03b2 a b)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_finset_product' finprod_mem_finset_product'\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (a b) -/\n/-- Note that `b \u2208 (s.filter (\u03bb ab, prod.fst ab = a)).image prod.snd` iff `(a, b) \u2208 s` so we can\nsimplify the right hand side of this lemma. However the form stated here is more useful for\niterating this lemma, e.g., if we have `f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M`. -/\n@[to_additive\n      \"Note that `b \u2208 (s.filter (\u03bb ab, prod.fst ab = a)).image prod.snd` iff `(a, b) \u2208 s` so\\nwe can simplify the right hand side of this lemma. However the form stated here is more useful for\\niterating this lemma, e.g., if we have `f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M`.\"]\ntheorem finprod_mem_finset_product' [DecidableEq \u03b1] [DecidableEq \u03b2] (s : Finset (\u03b1 \u00d7 \u03b2))\n    (f : \u03b1 \u00d7 \u03b2 \u2192 M) :\n    (\u220f\u1da0 (ab) (h : ab \u2208 s), f ab) =\n      \u220f\u1da0 (a) (b) (h : b \u2208 (s.filter\u2093 fun ab => Prod.fst ab = a).image Prod.snd), f (a, b) :=\n  by\n  have :\n    \u2200 a,\n      (\u220f i : \u03b2 in (s.filter fun ab => Prod.fst ab = a).image Prod.snd, f (a, i)) =\n        (Finset.filter (fun ab => Prod.fst ab = a) s).Prod f :=\n    by\n    refine' fun a => Finset.prod_bij (fun b _ => (a, b)) _ _ _ _ <;>-- `finish` closes these goals\n      try simp; done\n    suffices \u2200 a' b, (a', b) \u2208 s \u2192 a' = a \u2192 (a, b) \u2208 s \u2227 a' = a by simpa\n    rintro a' b hp rfl\n    exact \u27e8hp, rfl\u27e9\n  rw [finprod_mem_finset_eq_prod]\n  simp_rw [finprod_mem_finset_eq_prod, this]\n  rw [finprod_eq_prod_of_mulSupport_subset _\n      (s.mul_support_of_fiberwise_prod_subset_image f Prod.fst),\n    \u2190 Finset.prod_fiberwise_of_maps_to _ f]\n  -- `finish` could close the goal here\n  simp only [Finset.mem_image, Prod.mk.eta]\n  exact fun x hx => \u27e8x, hx, rfl\u27e9\n#align finprod_mem_finset_product' finprod_mem_finset_product'\n#align finsum_mem_finset_product' finsum_mem_finset_product'\n\n/- warning: finprod_mem_finset_product -> finprod_mem_finset_product is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] (s : Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (f : (Prod.{u1, u2} \u03b1 \u03b2) -> M), Eq.{succ u3} M (finprod.{u3, succ (max u1 u2)} M (Prod.{u1, u2} \u03b1 \u03b2) _inst_1 (fun (ab : Prod.{u1, u2} \u03b1 \u03b2) => finprod.{u3, 0} M (Membership.Mem.{max u1 u2, max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Finset.hasMem.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ab s) _inst_1 (fun (h : Membership.Mem.{max u1 u2, max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Finset.hasMem.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ab s) => f ab))) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u3, 0} M (Membership.Mem.{max u1 u2, max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Finset.hasMem.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Prod.mk.{u1, u2} \u03b1 \u03b2 a b) s) _inst_1 (fun (h : Membership.Mem.{max u1 u2, max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Finset.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Finset.hasMem.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Prod.mk.{u1, u2} \u03b1 \u03b2 a b) s) => f (Prod.mk.{u1, u2} \u03b1 \u03b2 a b)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (s : Finset.{max u3 u2} (Prod.{u2, u3} \u03b1 \u03b2)) (f : (Prod.{u2, u3} \u03b1 \u03b2) -> M), Eq.{succ u1} M (finprod.{u1, succ (max u2 u3)} M (Prod.{u2, u3} \u03b1 \u03b2) _inst_1 (fun (ab : Prod.{u2, u3} \u03b1 \u03b2) => finprod.{u1, 0} M (Membership.mem.{max u2 u3, max u2 u3} (Prod.{u2, u3} \u03b1 \u03b2) (Finset.{max u3 u2} (Prod.{u2, u3} \u03b1 \u03b2)) (Finset.instMembershipFinset.{max u2 u3} (Prod.{u2, u3} \u03b1 \u03b2)) ab s) _inst_1 (fun (h : Membership.mem.{max u2 u3, max u2 u3} (Prod.{u2, u3} \u03b1 \u03b2) (Finset.{max u3 u2} (Prod.{u2, u3} \u03b1 \u03b2)) (Finset.instMembershipFinset.{max u2 u3} (Prod.{u2, u3} \u03b1 \u03b2)) ab s) => f ab))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, succ u3} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u1, 0} M (Membership.mem.{max u3 u2, max u2 u3} (Prod.{u2, u3} \u03b1 \u03b2) (Finset.{max u3 u2} (Prod.{u2, u3} \u03b1 \u03b2)) (Finset.instMembershipFinset.{max u3 u2} (Prod.{u2, u3} \u03b1 \u03b2)) (Prod.mk.{u2, u3} \u03b1 \u03b2 a b) s) _inst_1 (fun (h : Membership.mem.{max u3 u2, max u2 u3} (Prod.{u2, u3} \u03b1 \u03b2) (Finset.{max u3 u2} (Prod.{u2, u3} \u03b1 \u03b2)) (Finset.instMembershipFinset.{max u3 u2} (Prod.{u2, u3} \u03b1 \u03b2)) (Prod.mk.{u2, u3} \u03b1 \u03b2 a b) s) => f (Prod.mk.{u2, u3} \u03b1 \u03b2 a b)))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_finset_product finprod_mem_finset_product\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (a b) -/\n/-- See also `finprod_mem_finset_product'`. -/\n@[to_additive \"See also `finsum_mem_finset_product'`.\"]\ntheorem finprod_mem_finset_product (s : Finset (\u03b1 \u00d7 \u03b2)) (f : \u03b1 \u00d7 \u03b2 \u2192 M) :\n    (\u220f\u1da0 (ab) (h : ab \u2208 s), f ab) = \u220f\u1da0 (a) (b) (h : (a, b) \u2208 s), f (a, b) := by\n  classical\n    rw [finprod_mem_finset_product']\n    simp\n#align finprod_mem_finset_product finprod_mem_finset_product\n#align finsum_mem_finset_product finsum_mem_finset_product\n\n/- warning: finprod_mem_finset_product\u2083 -> finprod_mem_finset_product\u2083 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {\u03b3 : Type.{u4}} (s : Finset.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) (f : (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) -> M), Eq.{succ u3} M (finprod.{u3, succ (max u1 u2 u4)} M (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) _inst_1 (fun (abc : Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) => finprod.{u3, 0} M (Membership.Mem.{max u1 u2 u4, max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) (Finset.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) (Finset.hasMem.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) abc s) _inst_1 (fun (h : Membership.Mem.{max u1 u2 u4, max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) (Finset.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) (Finset.hasMem.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) abc s) => f abc))) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u3, succ u4} M \u03b3 _inst_1 (fun (c : \u03b3) => finprod.{u3, 0} M (Membership.Mem.{max u1 u2 u4, max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) (Finset.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) (Finset.hasMem.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) (Prod.mk.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3) a (Prod.mk.{u2, u4} \u03b2 \u03b3 b c)) s) _inst_1 (fun (h : Membership.Mem.{max u1 u2 u4, max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) (Finset.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) (Finset.hasMem.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3))) (Prod.mk.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3) a (Prod.mk.{u2, u4} \u03b2 \u03b3 b c)) s) => f (Prod.mk.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3) a (Prod.mk.{u2, u4} \u03b2 \u03b3 b c)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {\u03b3 : Type.{u4}} (s : Finset.{max (max u4 u3) u2} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) (f : (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3)) -> M), Eq.{succ u1} M (finprod.{u1, succ (max (max u2 u3) u4)} M (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3)) _inst_1 (fun (abc : Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3)) => finprod.{u1, 0} M (Membership.mem.{max (max u2 u3) u4, max (max u2 u3) u4} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3)) (Finset.{max (max u4 u3) u2} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) (Finset.instMembershipFinset.{max (max u2 u3) u4} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) abc s) _inst_1 (fun (h : Membership.mem.{max (max u2 u3) u4, max (max u2 u3) u4} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3)) (Finset.{max (max u4 u3) u2} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) (Finset.instMembershipFinset.{max (max u2 u3) u4} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) abc s) => f abc))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, succ u3} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u1, succ u4} M \u03b3 _inst_1 (fun (c : \u03b3) => finprod.{u1, 0} M (Membership.mem.{max (max u4 u3) u2, max (max u2 u3) u4} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3)) (Finset.{max (max u4 u3) u2} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) (Finset.instMembershipFinset.{max (max u2 u4) u3} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) (Prod.mk.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3) a (Prod.mk.{u3, u4} \u03b2 \u03b3 b c)) s) _inst_1 (fun (h : Membership.mem.{max (max u4 u3) u2, max (max u2 u3) u4} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3)) (Finset.{max (max u4 u3) u2} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) (Finset.instMembershipFinset.{max (max u2 u4) u3} (Prod.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3))) (Prod.mk.{u2, max u4 u3} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3) a (Prod.mk.{u3, u4} \u03b2 \u03b3 b c)) s) => f (Prod.mk.{u2, max u3 u4} \u03b1 (Prod.{u3, u4} \u03b2 \u03b3) a (Prod.mk.{u3, u4} \u03b2 \u03b3 b c)))))))\nCase conversion may be inaccurate. Consider using '#align finprod_mem_finset_product\u2083 finprod_mem_finset_product\u2083\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (a b c) -/\n@[to_additive]\ntheorem finprod_mem_finset_product\u2083 {\u03b3 : Type _} (s : Finset (\u03b1 \u00d7 \u03b2 \u00d7 \u03b3)) (f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M) :\n    (\u220f\u1da0 (abc) (h : abc \u2208 s), f abc) = \u220f\u1da0 (a) (b) (c) (h : (a, b, c) \u2208 s), f (a, b, c) := by\n  classical\n    rw [finprod_mem_finset_product']\n    simp_rw [finprod_mem_finset_product']\n    simp\n#align finprod_mem_finset_product\u2083 finprod_mem_finset_product\u2083\n#align finsum_mem_finset_product\u2083 finsum_mem_finset_product\u2083\n\n/- warning: finprod_curry -> finprod_curry is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] (f : (Prod.{u1, u2} \u03b1 \u03b2) -> M), (Set.Finite.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Function.mulSupport.{max u1 u2, u3} (Prod.{u1, u2} \u03b1 \u03b2) M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) f)) -> (Eq.{succ u3} M (finprod.{u3, max (succ u1) (succ u2)} M (Prod.{u1, u2} \u03b1 \u03b2) _inst_1 (fun (ab : Prod.{u1, u2} \u03b1 \u03b2) => f ab)) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => f (Prod.mk.{u1, u2} \u03b1 \u03b2 a b)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : (Prod.{u3, u2} \u03b1 \u03b2) -> M), (Set.Finite.{max u3 u2} (Prod.{u3, u2} \u03b1 \u03b2) (Function.mulSupport.{max u3 u2, u1} (Prod.{u3, u2} \u03b1 \u03b2) M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) -> (Eq.{succ u1} M (finprod.{u1, max (succ u3) (succ u2)} M (Prod.{u3, u2} \u03b1 \u03b2) _inst_1 (fun (ab : Prod.{u3, u2} \u03b1 \u03b2) => f ab)) (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => f (Prod.mk.{u3, u2} \u03b1 \u03b2 a b)))))\nCase conversion may be inaccurate. Consider using '#align finprod_curry finprod_curry\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (a b) -/\n@[to_additive]\ntheorem finprod_curry (f : \u03b1 \u00d7 \u03b2 \u2192 M) (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 ab, f ab) = \u220f\u1da0 (a) (b), f (a, b) :=\n  by\n  have h\u2081 : \u2200 a, (\u220f\u1da0 h : a \u2208 hf.to_finset, f a) = f a := by simp\n  have h\u2082 : (\u220f\u1da0 a, f a) = \u220f\u1da0 (a) (h : a \u2208 hf.to_finset), f a := by simp\n  simp_rw [h\u2082, finprod_mem_finset_product, h\u2081]\n#align finprod_curry finprod_curry\n#align finsum_curry finsum_curry\n\n/- warning: finprod_curry\u2083 -> finprod_curry\u2083 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {\u03b3 : Type.{u4}} (f : (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) -> M), (Set.Finite.{max u1 u2 u4} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) (Function.mulSupport.{max u1 u2 u4, u3} (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1))) f)) -> (Eq.{succ u3} M (finprod.{u3, max (succ u1) (succ (max u2 u4))} M (Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) _inst_1 (fun (abc : Prod.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) => f abc)) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u3, succ u4} M \u03b3 _inst_1 (fun (c : \u03b3) => f (Prod.mk.{u1, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3) a (Prod.mk.{u2, u4} \u03b2 \u03b3 b c)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {\u03b3 : Type.{u4}} (f : (Prod.{u3, max u4 u2} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) -> M), (Set.Finite.{max (max u3 u2) u4} (Prod.{u3, max u4 u2} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) (Function.mulSupport.{max (max u3 u2) u4, u1} (Prod.{u3, max u4 u2} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)) f)) -> (Eq.{succ u1} M (finprod.{u1, max (max (succ u3) (succ u2)) (succ u4)} M (Prod.{u3, max u4 u2} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) _inst_1 (fun (abc : Prod.{u3, max u4 u2} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3)) => f abc)) (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => finprod.{u1, succ u4} M \u03b3 _inst_1 (fun (c : \u03b3) => f (Prod.mk.{u3, max u2 u4} \u03b1 (Prod.{u2, u4} \u03b2 \u03b3) a (Prod.mk.{u2, u4} \u03b2 \u03b3 b c)))))))\nCase conversion may be inaccurate. Consider using '#align finprod_curry\u2083 finprod_curry\u2083\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (a b c) -/\n@[to_additive]\ntheorem finprod_curry\u2083 {\u03b3 : Type _} (f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M) (h : (mulSupport f).Finite) :\n    (\u220f\u1da0 abc, f abc) = \u220f\u1da0 (a) (b) (c), f (a, b, c) :=\n  by\n  rw [finprod_curry f h]\n  congr\n  ext a\n  rw [finprod_curry]\n  simp [h]\n#align finprod_curry\u2083 finprod_curry\u2083\n#align finsum_curry\u2083 finsum_curry\u2083\n\n/- warning: finprod_dmem -> finprod_dmem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommMonoid.{u2} M] {s : Set.{u1} \u03b1} [_inst_3 : DecidablePred.{succ u1} \u03b1 (fun (_x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) _x s)] (f : forall (a : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) -> M), Eq.{succ u2} M (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) _inst_1 (fun (h : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) => f a h))) (finprod.{u2, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u2, 0} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) _inst_1 (fun (h : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) => dite.{succ u2} M (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) (_inst_3 a) (fun (h' : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) => f a h') (fun (h' : Not (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s)) => OfNat.ofNat.{u2} M 1 (OfNat.mk.{u2} M 1 (One.one.{u2} M (MulOneClass.toHasOne.{u2} M (Monoid.toMulOneClass.{u2} M (CommMonoid.toMonoid.{u2} M _inst_1)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {s : Set.{u2} \u03b1} [_inst_3 : DecidablePred.{succ u2} \u03b1 (fun (_x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) _x s)] (f : forall (a : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) -> M), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) _inst_1 (fun (h : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) => f a h))) (finprod.{u1, succ u2} M \u03b1 _inst_1 (fun (a : \u03b1) => finprod.{u1, 0} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) _inst_1 (fun (h : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) => dite.{succ u1} M (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) (_inst_3 a) (fun (h' : Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) => f a h') (fun (h' : Not (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s)) => OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))))\nCase conversion may be inaccurate. Consider using '#align finprod_dmem finprod_dmem\u2093'. -/\n@[to_additive]\ntheorem finprod_dmem {s : Set \u03b1} [DecidablePred (\u00b7 \u2208 s)] (f : \u2200 a : \u03b1, a \u2208 s \u2192 M) :\n    (\u220f\u1da0 (a : \u03b1) (h : a \u2208 s), f a h) = \u220f\u1da0 (a : \u03b1) (h : a \u2208 s), if h' : a \u2208 s then f a h' else 1 :=\n  finprod_congr fun a => finprod_congr fun ha => (dif_pos ha).symm\n#align finprod_dmem finprod_dmem\n#align finsum_dmem finsum_dmem\n\n/- warning: finprod_emb_domain' -> finprod_emb_domain' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] {f : \u03b1 -> \u03b2}, (Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 f) -> (forall [_inst_3 : DecidablePred.{succ u2} \u03b2 (fun (_x : \u03b2) => Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) _x (Set.range.{u2, succ u1} \u03b2 \u03b1 f))] (g : \u03b1 -> M), Eq.{succ u3} M (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => dite.{succ u3} M (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) b (Set.range.{u2, succ u1} \u03b2 \u03b1 f)) (_inst_3 b) (fun (h : Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) b (Set.range.{u2, succ u1} \u03b2 \u03b1 f)) => g (Classical.choose.{succ u1} \u03b1 (fun (y : \u03b1) => Eq.{succ u2} \u03b2 (f y) b) h)) (fun (h : Not (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) b (Set.range.{u2, succ u1} \u03b2 \u03b1 f))) => OfNat.ofNat.{u3} M 1 (OfNat.mk.{u3} M 1 (One.one.{u3} M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)))))))) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => g a)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] {f : \u03b1 -> \u03b2}, (Function.Injective.{succ u3, succ u2} \u03b1 \u03b2 f) -> (forall [_inst_3 : DecidablePred.{succ u2} \u03b2 (fun (_x : \u03b2) => Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) _x (Set.range.{u2, succ u3} \u03b2 \u03b1 f))] (g : \u03b1 -> M), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => dite.{succ u1} M (Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) b (Set.range.{u2, succ u3} \u03b2 \u03b1 f)) (_inst_3 b) (fun (h : Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) b (Set.range.{u2, succ u3} \u03b2 \u03b1 f)) => g (Classical.choose.{succ u3} \u03b1 (fun (y : \u03b1) => Eq.{succ u2} \u03b2 (f y) b) h)) (fun (h : Not (Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) b (Set.range.{u2, succ u3} \u03b2 \u03b1 f))) => OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))) (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (a : \u03b1) => g a)))\nCase conversion may be inaccurate. Consider using '#align finprod_emb_domain' finprod_emb_domain'\u2093'. -/\n@[to_additive]\ntheorem finprod_emb_domain' {f : \u03b1 \u2192 \u03b2} (hf : Injective f) [DecidablePred (\u00b7 \u2208 Set.range f)]\n    (g : \u03b1 \u2192 M) :\n    (\u220f\u1da0 b : \u03b2, if h : b \u2208 Set.range f then g (Classical.choose h) else 1) = \u220f\u1da0 a : \u03b1, g a :=\n  by\n  simp_rw [\u2190 finprod_eq_dif]\n  rw [finprod_dmem, finprod_mem_range hf, finprod_congr fun a => _]\n  rw [dif_pos (Set.mem_range_self a), hf (Classical.choose_spec (Set.mem_range_self a))]\n#align finprod_emb_domain' finprod_emb_domain'\n#align finsum_emb_domain' finsum_emb_domain'\n\n/- warning: finprod_emb_domain -> finprod_emb_domain is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommMonoid.{u3} M] (f : Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) [_inst_3 : DecidablePred.{succ u2} \u03b2 (fun (_x : \u03b2) => Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) _x (Set.range.{u2, succ u1} \u03b2 \u03b1 (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) (fun (_x : Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) => \u03b1 -> \u03b2) (Function.Embedding.hasCoeToFun.{succ u1, succ u2} \u03b1 \u03b2) f)))] (g : \u03b1 -> M), Eq.{succ u3} M (finprod.{u3, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => dite.{succ u3} M (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) b (Set.range.{u2, succ u1} \u03b2 \u03b1 (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) (fun (_x : Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) => \u03b1 -> \u03b2) (Function.Embedding.hasCoeToFun.{succ u1, succ u2} \u03b1 \u03b2) f))) (_inst_3 b) (fun (h : Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) b (Set.range.{u2, succ u1} \u03b2 \u03b1 (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) (fun (_x : Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) => \u03b1 -> \u03b2) (Function.Embedding.hasCoeToFun.{succ u1, succ u2} \u03b1 \u03b2) f))) => g (Classical.choose.{succ u1} \u03b1 (fun (y : \u03b1) => Eq.{succ u2} \u03b2 (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) (fun (_x : Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) => \u03b1 -> \u03b2) (Function.Embedding.hasCoeToFun.{succ u1, succ u2} \u03b1 \u03b2) f y) b) h)) (fun (h : Not (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) b (Set.range.{u2, succ u1} \u03b2 \u03b1 (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) (fun (_x : Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) => \u03b1 -> \u03b2) (Function.Embedding.hasCoeToFun.{succ u1, succ u2} \u03b1 \u03b2) f)))) => OfNat.ofNat.{u3} M 1 (OfNat.mk.{u3} M 1 (One.one.{u3} M (MulOneClass.toHasOne.{u3} M (Monoid.toMulOneClass.{u3} M (CommMonoid.toMonoid.{u3} M _inst_1)))))))) (finprod.{u3, succ u1} M \u03b1 _inst_1 (fun (a : \u03b1) => g a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommMonoid.{u1} M] (f : Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) [_inst_3 : DecidablePred.{succ u2} \u03b2 (fun (_x : \u03b2) => Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) _x (Set.range.{u2, succ u3} \u03b2 \u03b1 (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u3, succ u2} \u03b1 \u03b2)) f)))] (g : \u03b1 -> M), Eq.{succ u1} M (finprod.{u1, succ u2} M \u03b2 _inst_1 (fun (b : \u03b2) => dite.{succ u1} M (Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) b (Set.range.{u2, succ u3} \u03b2 \u03b1 (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u3, succ u2} \u03b1 \u03b2)) f))) (_inst_3 b) (fun (h : Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) b (Set.range.{u2, succ u3} \u03b2 \u03b1 (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u3, succ u2} \u03b1 \u03b2)) f))) => g (Classical.choose.{succ u3} \u03b1 (fun (y : \u03b1) => Eq.{succ u2} \u03b2 (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u3, succ u2} \u03b1 \u03b2)) f y) b) h)) (fun (h : Not (Membership.mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.instMembershipSet.{u2} \u03b2) b (Set.range.{u2, succ u3} \u03b2 \u03b1 (FunLike.coe.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u3) (succ u2), succ u3, succ u2} (Function.Embedding.{succ u3, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u3, succ u2} \u03b1 \u03b2)) f)))) => OfNat.ofNat.{u1} M 1 (One.toOfNat1.{u1} M (Monoid.toOne.{u1} M (CommMonoid.toMonoid.{u1} M _inst_1)))))) (finprod.{u1, succ u3} M \u03b1 _inst_1 (fun (a : \u03b1) => g a))\nCase conversion may be inaccurate. Consider using '#align finprod_emb_domain finprod_emb_domain\u2093'. -/\n@[to_additive]\ntheorem finprod_emb_domain (f : \u03b1 \u21aa \u03b2) [DecidablePred (\u00b7 \u2208 Set.range f)] (g : \u03b1 \u2192 M) :\n    (\u220f\u1da0 b : \u03b2, if h : b \u2208 Set.range f then g (Classical.choose h) else 1) = \u220f\u1da0 a : \u03b1, g a :=\n  finprod_emb_domain' f.Injective g\n#align finprod_emb_domain finprod_emb_domain\n#align finsum_emb_domain finsum_emb_domain\n\nend Type\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/BigOperators/Finprod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7396704130851086}}
{"text": "/-\nCopyright (c) 2020 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.derivative\nimport Mathlib.logic.function.iterate\nimport Mathlib.data.finset.intervals\nimport Mathlib.tactic.ring\nimport Mathlib.tactic.linarith.default\nimport Mathlib.PostPort\n\nuniverses u \n\nnamespace Mathlib\n\n/-!\n# Theory of iterated derivative\nWe define and prove some lemmas about iterated (formal) derivative for polynomials over a semiring.\n-/\n\nnamespace polynomial\n\n\n/-- `iterated_deriv f n` is the `n`-th formal derivative of the polynomial `f` -/\ndef iterated_deriv {R : Type u} [semiring R] (f : polynomial R) (n : \u2115) : polynomial R :=\n  nat.iterate (\u21d1derivative) n f\n\n@[simp] theorem iterated_deriv_zero_right {R : Type u} [semiring R] (f : polynomial R) :\n    iterated_deriv f 0 = f :=\n  rfl\n\ntheorem iterated_deriv_succ {R : Type u} [semiring R] (f : polynomial R) (n : \u2115) :\n    iterated_deriv f (n + 1) = coe_fn derivative (iterated_deriv f n) :=\n  sorry\n\n@[simp] theorem iterated_deriv_zero_left {R : Type u} [semiring R] (n : \u2115) :\n    iterated_deriv 0 n = 0 :=\n  sorry\n\n@[simp] theorem iterated_deriv_add {R : Type u} [semiring R] (p : polynomial R) (q : polynomial R)\n    (n : \u2115) : iterated_deriv (p + q) n = iterated_deriv p n + iterated_deriv q n :=\n  sorry\n\n@[simp] theorem iterated_deriv_smul {R : Type u} [semiring R] (r : R) (p : polynomial R) (n : \u2115) :\n    iterated_deriv (r \u2022 p) n = r \u2022 iterated_deriv p n :=\n  sorry\n\n@[simp] theorem iterated_deriv_X_zero {R : Type u} [semiring R] : iterated_deriv X 0 = X := sorry\n\n@[simp] theorem iterated_deriv_X_one {R : Type u} [semiring R] : iterated_deriv X 1 = 1 := sorry\n\n@[simp] theorem iterated_deriv_X {R : Type u} [semiring R] (n : \u2115) (h : 1 < n) :\n    iterated_deriv X n = 0 :=\n  sorry\n\n@[simp] theorem iterated_deriv_C_zero {R : Type u} [semiring R] (r : R) :\n    iterated_deriv (coe_fn C r) 0 = coe_fn C r :=\n  sorry\n\n@[simp] theorem iterated_deriv_C {R : Type u} [semiring R] (r : R) (n : \u2115) (h : 0 < n) :\n    iterated_deriv (coe_fn C r) n = 0 :=\n  sorry\n\n@[simp] theorem iterated_deriv_one_zero {R : Type u} [semiring R] : iterated_deriv 1 0 = 1 := sorry\n\n@[simp] theorem iterated_deriv_one {R : Type u} [semiring R] (n : \u2115) :\n    0 < n \u2192 iterated_deriv 1 n = 0 :=\n  sorry\n\n@[simp] theorem iterated_deriv_neg {R : Type u} [ring R] (p : polynomial R) (n : \u2115) :\n    iterated_deriv (-p) n = -iterated_deriv p n :=\n  sorry\n\n@[simp] theorem iterated_deriv_sub {R : Type u} [ring R] (p : polynomial R) (q : polynomial R)\n    (n : \u2115) : iterated_deriv (p - q) n = iterated_deriv p n - iterated_deriv q n :=\n  sorry\n\ntheorem coeff_iterated_deriv_as_prod_Ico {R : Type u} [comm_semiring R] (f : polynomial R) (k : \u2115)\n    (m : \u2115) :\n    coeff (iterated_deriv f k) m =\n        (finset.prod (finset.Ico (Nat.succ m) (m + Nat.succ k)) fun (i : \u2115) => \u2191i) *\n          coeff f (m + k) :=\n  sorry\n\ntheorem coeff_iterated_deriv_as_prod_range {R : Type u} [comm_semiring R] (f : polynomial R) (k : \u2115)\n    (m : \u2115) :\n    coeff (iterated_deriv f k) m =\n        coeff f (m + k) * finset.prod (finset.range k) fun (i : \u2115) => \u2191(m + k - i) :=\n  sorry\n\ntheorem iterated_deriv_eq_zero_of_nat_degree_lt {R : Type u} [comm_semiring R] (f : polynomial R)\n    (n : \u2115) (h : nat_degree f < n) : iterated_deriv f n = 0 :=\n  sorry\n\ntheorem iterated_deriv_mul {R : Type u} [comm_semiring R] (p : polynomial R) (q : polynomial R)\n    (n : \u2115) :\n    iterated_deriv (p * q) n =\n        finset.sum (finset.range (Nat.succ n))\n          fun (k : \u2115) =>\n            coe_fn C \u2191(nat.choose n k) * iterated_deriv p (n - k) * iterated_deriv q k :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/polynomial/iterated_deriv_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.7396704069488079}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n\nDefine the p-adic numbers (rationals) \u211a_p as the completion of \u211a wrt the p-adic norm.\nShow that the p-adic norm extends to \u211a_p, that \u211a is embedded in \u211a_p, and that \u211a_p is complete\n-/\n\nimport data.real.cau_seq_completion data.padics.padic_norm algebra.archimedean\n\nnoncomputable theory\nlocal attribute [instance] classical.prop_decidable\n\nopen nat padic_val padic_norm cau_seq cau_seq.completion\n\n@[reducible] def padic_seq {p : \u2115} (hp : prime p) := cau_seq _ (padic_norm hp)\n\nnamespace padic_seq\n\nsection\nvariables {p : \u2115} {hp : prime p}\n\nlemma stationary {f : cau_seq \u211a (padic_norm hp)} (hf : \u00ac f \u2248 0) :\n      \u2203 N, \u2200 m n, m \u2265 N \u2192 n \u2265 N \u2192 padic_norm hp (f n) = padic_norm hp (f m) :=\nhave \u2203 \u03b5 > 0, \u2203 N1, \u2200 j \u2265 N1, \u03b5 \u2264 padic_norm hp (f j),\n  from cau_seq.abv_pos_of_not_lim_zero $ not_lim_zero_of_not_congr_zero hf,\nlet \u27e8\u03b5, h\u03b5, N1, hN1\u27e9 := this in\nhave \u2203 N2, \u2200 i j \u2265 N2, padic_norm hp (f i - f j) < \u03b5, from cau_seq.cauchy\u2082 f h\u03b5,\nlet \u27e8N2, hN2\u27e9 := this in\n\u27e8 max N1 N2,\n  \u03bb n m hn hm,\n  have padic_norm hp (f n - f m) < \u03b5, from hN2 _ _ (max_le_iff.1 hn).2 (max_le_iff.1 hm).2,\n  have padic_norm hp (f n - f m) < padic_norm hp (f n),\n    from lt_of_lt_of_le this $ hN1 _ (max_le_iff.1 hn).1,\n  have  padic_norm hp (f n - f m) < max (padic_norm hp (f n)) (padic_norm hp (f m)),\n    from lt_max_iff.2 (or.inl this),\n  begin\n    by_contradiction hne,\n    rw \u2190padic_norm.neg hp (f m) at hne,\n    have hnam := add_eq_max_of_ne hp hne,\n    rw [padic_norm.neg, max_comm] at hnam,\n    rw \u2190hnam at this,\n    apply _root_.lt_irrefl _ (by simp at this; exact this)\n  end \u27e9\n\ndef stationary_point {f : padic_seq hp} (hf : \u00ac f \u2248 0) : \u2115 :=\nclassical.some $ stationary hf\n\nlemma stationary_point_spec {f : padic_seq hp} (hf : \u00ac f \u2248 0) :\n      \u2200 {m n}, m \u2265 stationary_point hf \u2192 n \u2265 stationary_point hf \u2192\n                 padic_norm hp (f n) = padic_norm hp (f m) :=\nclassical.some_spec $ stationary hf\n\ndef norm (f : padic_seq hp) : \u211a :=\nif hf : f \u2248 0 then 0\nelse padic_norm hp (f (stationary_point hf))\n\nlemma norm_zero_iff (f : padic_seq hp) : f.norm = 0 \u2194 f \u2248 0 :=\nbegin\n  constructor,\n  { intro h,\n    by_contradiction hf,\n    unfold norm at h, split_ifs at h,\n    apply hf,\n    intros \u03b5 h\u03b5,\n    existsi stationary_point hf,\n    intros j hj,\n    have heq := stationary_point_spec hf (le_refl _) hj,\n    simpa [h, heq] },\n  { intro h,\n    simp [norm, h] }\nend\n\nend\n\nsection embedding\nopen cau_seq\nvariables {p : \u2115} {hp : prime p}\n\nlemma equiv_zero_of_val_eq_of_equiv_zero {f g : padic_seq hp}\n      (h : \u2200 k, padic_norm hp (f k) = padic_norm hp (g k)) (hf : f \u2248 0) : g \u2248 0 :=\n\u03bb \u03b5 h\u03b5, let \u27e8i, hi\u27e9 := hf _ h\u03b5 in\n\u27e8i, \u03bb j hj, by simpa [h] using hi _ hj\u27e9\n\nlemma norm_nonzero_of_not_equiv_zero {f : padic_seq hp} (hf : \u00ac f \u2248 0) :\n      f.norm \u2260 0 :=\nhf \u2218 f.norm_zero_iff.1\n\nlemma norm_eq_norm_app_of_nonzero {f : padic_seq hp} (hf : \u00ac f \u2248 0) :\n      \u2203 k, f.norm = padic_norm hp k \u2227 k \u2260 0 :=\nhave heq : f.norm = padic_norm hp (f $ stationary_point hf), by simp [norm, hf],\n\u27e8f $ stationary_point hf, heq,\n  \u03bb h, norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)\u27e9\n\nlemma not_lim_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac lim_zero (const (padic_norm hp) q) :=\n\u03bb h', hq $ const_lim_zero.1 h'\n\nlemma not_equiv_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac (const (padic_norm hp) q) \u2248 0 :=\n\u03bb h : lim_zero (const (padic_norm hp) q - 0), not_lim_zero_const_of_nonzero hq $ by simpa using h\n\nlemma norm_nonneg (f : padic_seq hp) : f.norm \u2265 0 :=\nif hf : f \u2248 0 then by simp [hf, norm]\nelse by simp [norm, hf, padic_norm.nonneg]\n\nlemma norm_mul (f g : padic_seq hp) :\n      (f * g).norm = f.norm * g.norm :=\nif hf : f \u2248 0 then\n  have hg : f * g \u2248 0, from mul_equiv_zero' _ hf,\n  by simp [hf, hg, norm]\nelse if hg : g \u2248 0 then\n  have hf : f * g \u2248 0, from mul_equiv_zero _ hg,\n  by simp [hf, hg, norm]\nelse\n  have hfg : \u00ac f * g \u2248 0, by apply mul_not_equiv_zero; assumption,\n  let i := max (stationary_point hfg) (max (stationary_point hf) (stationary_point hg)) in\n  have hpnfg : padic_norm hp ((f * g) (stationary_point hfg)) = padic_norm hp ((f * g) i),\n  { apply stationary_point_spec hfg,\n    apply le_max_left,\n    apply le_refl },\n  have hpnf : padic_norm hp (f (stationary_point hf)) = padic_norm hp (f i),\n  { apply stationary_point_spec hf,\n    apply ge_trans,\n    apply le_max_right,\n    apply le_max_left,\n    apply le_refl },\n  have hpng : padic_norm hp (g (stationary_point hg)) = padic_norm hp (g i),\n  { apply stationary_point_spec hg,\n    apply ge_trans,\n    apply le_max_right,\n    apply le_max_right,\n    apply le_refl },\n  begin\n    unfold norm,\n    split_ifs,\n    rw [hpnfg, hpnf, hpng],\n    apply padic_norm.mul hp\n  end\n\nlemma eq_zero_iff_equiv_zero (f : padic_seq hp) : mk f = 0 \u2194 f \u2248 0 :=\nmk_eq\n\nlemma ne_zero_iff_nequiv_zero (f : padic_seq hp) : mk f \u2260 0 \u2194 \u00ac f \u2248 0 :=\nnot_iff_not.2 (eq_zero_iff_equiv_zero _)\n\nlemma norm_const (q : \u211a) : norm (const (padic_norm hp) q) = padic_norm hp q :=\nif hq : q = 0 then\n  have (const (padic_norm hp) q) \u2248 0,\n    by simp [hq]; apply setoid.refl (const (padic_norm hp) 0),\n  by subst hq; simp [norm, this]\nelse\n  have \u00ac (const (padic_norm hp) q) \u2248 0, from not_equiv_zero_const_of_nonzero hq,\n  by simp [norm, this]\n\nlemma norm_image (a : padic_seq hp) (ha : \u00ac a \u2248 0) :\n      (\u2203 (n : \u2124), a.norm = fpow \u2191p (-n)) :=\nlet \u27e8k, hk, hk'\u27e9 := norm_eq_norm_app_of_nonzero ha in\nby simpa [hk] using padic_norm.image hp hk'\n\nlemma norm_one : norm (1 : padic_seq hp) = 1 :=\nhave h1 : \u00ac (1 : padic_seq hp) \u2248 0, from one_not_equiv_zero _,\nby simp [h1, norm, hp.gt_one]\n\nprivate lemma norm_eq_of_equiv_aux {f g : padic_seq hp} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g)\n        (h : padic_norm hp (f (stationary_point hf)) \u2260 padic_norm hp (g (stationary_point hg)))\n        (hgt : padic_norm hp (f (stationary_point hf)) > padic_norm hp (g (stationary_point hg))) :\n        false :=\nbegin\n  have hpn : padic_norm hp (f (stationary_point hf)) - padic_norm hp (g (stationary_point hg)) > 0,\n    from sub_pos_of_lt hgt,\n  cases hfg _ hpn with N hN,\n  let i := max N (max (stationary_point hf) (stationary_point hg)),\n  have hfi : padic_norm hp (f (stationary_point hf)) = padic_norm hp (f i),\n  { apply stationary_point_spec hf,\n    { apply le_trans,\n      apply le_max_left,\n      tactic.rotate_left 1,\n      apply le_max_right },\n    { apply le_refl } },\n  have hgi : padic_norm hp (g (stationary_point hg)) = padic_norm hp (g i),\n  { apply stationary_point_spec hg,\n    { apply le_trans,\n      apply le_max_right,\n      tactic.rotate_left 1,\n      apply le_max_right },\n    { apply le_refl } },\n  have hi : i \u2265 N, from le_max_left _ _,\n  have hN' := hN _ hi,\n  simp only [hfi, hgi] at hN',\n  have hpne : padic_norm hp (f i) \u2260 padic_norm hp (-(g i)),\n    by rwa [hfi, hgi, \u2190padic_norm.neg hp (g i)] at h,\n  let hpnem := add_eq_max_of_ne hp hpne,\n  have hpeq : padic_norm hp ((f - g) i) = max (padic_norm hp (f i)) (padic_norm hp (g i)),\n  { rwa padic_norm.neg at hpnem },\n  have hfigi : padic_norm hp (g i) < padic_norm hp (f i),\n  { rwa [hfi, hgi] at hgt },\n  rw [hpeq, max_eq_left_of_lt hfigi] at hN',\n  have : padic_norm hp (f i) < padic_norm hp (f i),\n  { apply lt_of_lt_of_le hN', apply sub_le_self, apply padic_norm.nonneg },\n  exact lt_irrefl _ this\nend\n\nprivate lemma norm_eq_of_equiv {f g : padic_seq hp} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g) :\n      padic_norm hp (f (stationary_point hf)) = padic_norm hp (g (stationary_point hg)) :=\nbegin\n  by_contradiction h,\n  cases (decidable.em (padic_norm hp (f (stationary_point hf)) >\n          padic_norm hp (g (stationary_point hg))))\n      with hgt hngt,\n  { exact norm_eq_of_equiv_aux hf hg hfg h hgt },\n  { apply norm_eq_of_equiv_aux hg hf (setoid.symm hfg) (ne.symm h),\n    apply lt_of_le_of_ne,\n    apply le_of_not_gt hngt,\n    apply h }\nend\n\ntheorem norm_equiv {f g : padic_seq hp} (hfg : f \u2248 g) :\n      f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from setoid.trans (setoid.symm hfg) hf,\n  by simp [norm, hf, hg]\nelse have hg : \u00ac g \u2248 0, from hf \u2218 setoid.trans hfg,\nby unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg\n\nprivate lemma norm_nonarchimedean_aux {f g : padic_seq hp}\n        (hfg : \u00ac f + g \u2248 0) (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) :\n        (f + g).norm \u2264 max (f.norm) (g.norm) :=\nlet i := max (stationary_point hfg) (max (stationary_point hf) (stationary_point hg)) in\nhave hpnfg : padic_norm hp ((f + g) (stationary_point hfg)) = padic_norm hp ((f + g) i),\n{ apply stationary_point_spec hfg,\n  apply le_max_left,\n  apply le_refl },\nhave hpnf : padic_norm hp (f (stationary_point hf)) = padic_norm hp (f i),\n{ apply stationary_point_spec hf,\n  apply ge_trans,\n  apply le_max_right,\n  apply le_max_left,\n  apply le_refl },\nhave hpng : padic_norm hp (g (stationary_point hg)) = padic_norm hp (g i),\n{ apply stationary_point_spec hg,\n  apply ge_trans,\n  apply le_max_right,\n  apply le_max_right,\n  apply le_refl },\nbegin\n  unfold norm, split_ifs,\n  rw [hpnfg, hpnf, hpng],\n  apply padic_norm.nonarchimedean\nend\n\ntheorem norm_nonarchimedean (f g : padic_seq hp) :\n      (f + g).norm \u2264 max (f.norm) (g.norm) :=\nif hfg : f + g \u2248 0 then\n  have 0 \u2264 max (f.norm) (g.norm), from le_max_left_of_le (norm_nonneg _),\n  by simpa [hfg, norm]\nelse if hf : f \u2248 0 then\n  have hfg' : f + g \u2248 g,\n  { change lim_zero (f - 0) at hf,\n    show lim_zero (f + g - g), by simpa using hf },\n  have hcfg : (f + g).norm = g.norm, from norm_equiv hfg',\n  have hcl : f.norm = 0, from (norm_zero_iff f).2 hf,\n  have max (f.norm) (g.norm) = g.norm,\n    by rw hcl; exact max_eq_right (norm_nonneg _),\n  by rw [this, hcfg]\nelse if hg : g \u2248 0 then\n  have hfg' : f + g \u2248 f,\n  { change lim_zero (g - 0) at hg,\n    show lim_zero (f + g - f), by  simpa [add_sub_cancel'] using hg },\n  have hcfg : (f + g).norm = f.norm, from norm_equiv hfg',\n  have hcl : g.norm = 0, from (norm_zero_iff g).2 hg,\n  have max (f.norm) (g.norm) = f.norm,\n    by rw hcl; exact max_eq_left (norm_nonneg _),\n  by rw [this, hcfg]\nelse norm_nonarchimedean_aux hfg hf hg\n\nlemma norm_eq {f g : padic_seq hp} (h : \u2200 k, padic_norm hp (f k) = padic_norm hp (g k)) :\n      f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from equiv_zero_of_val_eq_of_equiv_zero h hf,\n  by simp [hf, hg, norm]\nelse\n  have hg : \u00ac g \u2248 0, from \u03bb hg, hf $ equiv_zero_of_val_eq_of_equiv_zero (by simp [h]) hg,\n  begin\n    simp [hg, hf, norm],\n    let i := max (stationary_point hf) (stationary_point hg),\n    have hpf : padic_norm hp (f (stationary_point hf)) = padic_norm hp (f i),\n    { apply stationary_point_spec, apply le_max_left, apply le_refl },\n    have hpg : padic_norm hp (g (stationary_point hg)) = padic_norm hp (g i),\n    { apply stationary_point_spec, apply le_max_right, apply le_refl },\n    rw [hpf, hpg, h]\n  end\n\nlemma norm_neg (a : padic_seq hp) : (-a).norm = a.norm :=\nnorm_eq $ by simp\n\nend embedding\nend padic_seq\n\ndef padic {p : \u2115} (hp : prime p) := @Cauchy _ _ _ _ (padic_norm hp) _\nnotation `\u211a_[` hp `]` := padic hp\n\nnamespace padic\n\nsection completion\nvariables {p : \u2115} {hp : prime p}\n\ninstance discrete_field : discrete_field (padic hp) :=\ncau_seq.completion.discrete_field\n\ndef mk : padic_seq hp \u2192 \u211a_[hp] := quotient.mk\nend completion\n\nsection completion\nvariables {p : \u2115} (hp : prime p)\n\nlemma mk_eq {f g : padic_seq hp} : mk f = mk g \u2194 f \u2248 g := quotient.eq\n\ndef of_rat : \u211a \u2192 \u211a_[hp] := cau_seq.completion.of_rat\n\n@[simp] lemma of_rat_add : \u2200 (x y : \u211a), of_rat hp (x + y) = of_rat hp x + of_rat hp y :=\ncau_seq.completion.of_rat_add\n\n@[simp] lemma of_rat_neg : \u2200 (x : \u211a), of_rat hp (-x) = -of_rat hp x :=\ncau_seq.completion.of_rat_neg\n\n@[simp] lemma of_rat_mul : \u2200 (x y : \u211a), of_rat hp (x * y) = of_rat hp x * of_rat hp y :=\ncau_seq.completion.of_rat_mul\n\n@[simp] lemma of_rat_sub : \u2200 (x y : \u211a), of_rat hp (x - y) = of_rat hp x - of_rat hp y :=\ncau_seq.completion.of_rat_sub\n\n@[simp] lemma of_rat_div : \u2200 (x y : \u211a), of_rat hp (x / y) = of_rat hp x / of_rat hp y :=\ncau_seq.completion.of_rat_div\n\n@[simp] lemma of_rat_one : of_rat hp 1 = 1 := rfl\n\n@[simp] lemma of_rat_zero : of_rat hp 0 = 0 := rfl\n\n@[simp] lemma cast_eq_of_rat_of_nat (n : \u2115) : (\u2191n : \u211a_[hp]) = of_rat hp n :=\nbegin\n  induction n with n ih,\n  { refl },\n  { simp, ring, congr, apply ih }\nend\n\n@[simp] lemma cast_eq_of_rat_of_int (n : \u2124) : (\u2191n : \u211a_[hp]) = of_rat hp n :=\nby induction n; simp\n\nlemma cast_eq_of_rat : \u2200 (q : \u211a), (\u2191q : \u211a_[hp]) = of_rat hp q\n| \u27e8n, d, h1, h2\u27e9 :=\n  show \u2191n / \u2191d = _, from\n    have (\u27e8n, d, h1, h2\u27e9 : \u211a) = rat.mk n d, from rat.num_denom _,\n    by simp [this, rat.mk_eq_div, of_rat_div]\n\nlemma const_equiv {q r : \u211a} : const (padic_norm hp) q \u2248 const (padic_norm hp) r \u2194 q = r :=\n\u27e8 \u03bb heq : lim_zero (const (padic_norm hp) (q - r)),\n    eq_of_sub_eq_zero $ const_lim_zero.1 heq,\n  \u03bb heq, by rw heq; apply setoid.refl _ \u27e9\n\nlemma of_rat_eq {q r : \u211a} : of_rat hp q = of_rat hp r \u2194 q = r :=\n\u27e8(const_equiv hp).1 \u2218 quotient.eq.1, \u03bb h, by rw h\u27e9\n\ninstance : char_zero \u211a_[hp] :=\n\u27e8 \u03bb m n, suffices of_rat hp \u2191m = of_rat hp \u2191n \u2194 m = n, by simpa,\n    by simp [of_rat_eq] \u27e9\n\nend completion\nend padic\n\ndef padic_norm_e {p : \u2115} {hp : prime p} : \u211a_[hp] \u2192 \u211a :=\nquotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _\n\nnamespace padic_norm_e\nsection embedding\nopen padic_seq\nvariables {p : \u2115} {hp : prime p}\n\nlemma defn (f : padic_seq hp) {\u03b5 : \u211a} (h\u03b5 : \u03b5 > 0) :\n      \u2203 N, \u2200 i \u2265 N, padic_norm_e (\u27e6f\u27e7 - f i) < \u03b5 :=\nbegin\n  simp only [padic.cast_eq_of_rat],\n  change \u2203 N, \u2200 i \u2265 N, (f - const _ (f i)).norm < \u03b5,\n  by_contradiction h,\n  cases cauchy\u2082 f h\u03b5 with N hN,\n  have : \u2200 N, \u2203 i \u2265 N, (f - const _ (f i)).norm \u2265 \u03b5,\n    by simpa [not_forall] using h,\n  rcases this N with \u27e8i, hi, hge\u27e9,\n  have hne : \u00ac (f - const (padic_norm hp) (f i)) \u2248 0,\n  { intro h, unfold norm at hge; split_ifs at hge, exact not_lt_of_ge hge h\u03b5 },\n  unfold norm at hge; split_ifs at hge,\n  apply not_le_of_gt _ hge,\n  cases decidable.em ((stationary_point hne) \u2265 N) with hgen hngen,\n  { apply hN; assumption },\n  { have := stationary_point_spec hne (le_refl _) (le_of_not_le hngen),\n    rw \u2190this,\n    apply hN,\n    apply le_refl, assumption }\nend\n\nprotected lemma nonneg (q : \u211a_[hp]) : padic_norm_e q \u2265 0 :=\nquotient.induction_on q $ norm_nonneg\n\nlemma zero_def : (0 : \u211a_[hp]) = \u27e60\u27e7 := rfl\n\nlemma zero_iff (q : \u211a_[hp]) : padic_norm_e q = 0 \u2194 q = 0 :=\nquotient.induction_on q $\n  by simpa only [zero_def, quotient.eq] using norm_zero_iff\n\n@[simp] protected lemma zero : padic_norm_e (0 : \u211a_[hp]) = 0 :=\n(zero_iff _).2 rfl\n\n@[simp] protected lemma one : padic_norm_e (1 : \u211a_[hp]) = 1 :=\nnorm_one\n\n@[simp] protected lemma neg (q : \u211a_[hp]) : padic_norm_e (-q) = padic_norm_e q :=\nquotient.induction_on q $ norm_neg\n\ntheorem nonarchimedean (q r : \u211a_[hp]) :\n      padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_nonarchimedean\n\nprotected lemma add (q r : \u211a_[hp]) :\n      padic_norm_e (q + r) \u2264 (padic_norm_e q) + (padic_norm_e r) :=\ncalc\n  padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) : nonarchimedean _ _\n                      ... \u2264 (padic_norm_e q) + (padic_norm_e r) :\n                              max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)\n\nprotected lemma mul (q r : \u211a_[hp]) :\n      padic_norm_e (q * r) = (padic_norm_e q) * (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_mul\n\ninstance : is_absolute_value (@padic_norm_e _ hp) :=\n{ abv_nonneg := padic_norm_e.nonneg,\n  abv_eq_zero := zero_iff,\n  abv_add := padic_norm_e.add,\n  abv_mul := padic_norm_e.mul }\n\nlemma eq_padic_norm (q : \u211a) : padic_norm_e (padic.of_rat hp q) = padic_norm hp q :=\nnorm_const _\n\nprotected theorem image {q : \u211a_[hp]} : q \u2260 0 \u2192 \u2203 n : \u2124, padic_norm_e q = fpow p (-n) :=\nquotient.induction_on q $ \u03bb f hf,\n  have \u00ac f \u2248 0, from (ne_zero_iff_nequiv_zero f).1 hf,\n  norm_image f this\n\nlemma sub_rev (q r : \u211a_[hp]) : padic_norm_e (q - r) = padic_norm_e (r - q) :=\nby rw \u2190(padic_norm_e.neg); simp\n\nend embedding\nend padic_norm_e\n\nnamespace padic\n\nsection complete\nopen padic_seq padic\n\ntheorem rat_dense {p : \u2115} {hp : prime p} (q : \u211a_[hp]) {\u03b5 : \u211a} (h\u03b5 : \u03b5 > 0) :\n        \u2203 r : \u211a, padic_norm_e (q - r) < \u03b5 :=\nquotient.induction_on q $ \u03bb q',\n  have \u2203 N, \u2200 m n \u2265 N, padic_norm hp (q' m - q' n) < \u03b5, from cauchy\u2082 _ h\u03b5,\n  let \u27e8N, hN\u27e9 := this in\n  \u27e8q' N,\n    begin\n      simp only [padic.cast_eq_of_rat],\n      change padic_seq.norm (q' - const _ (q' N)) < \u03b5,\n      cases decidable.em ((q' - const (padic_norm hp) (q' N)) \u2248 0) with heq hne',\n      { simpa only [heq, norm, dif_pos] },\n      { simp only [norm, dif_neg hne'],\n        change padic_norm hp (q' _ - q' _) < \u03b5,\n        have := stationary_point_spec hne',\n        cases decidable.em (N \u2265 stationary_point hne') with hle hle,\n        { have := eq.symm (this (le_refl _) hle),\n          simp at this, simpa [this] },\n        { apply hN,\n          apply le_of_lt, apply lt_of_not_ge, apply hle, apply le_refl }}\n    end\u27e9\n\nvariables {p : \u2115} {hp : prime p} (f : cau_seq _ (@padic_norm_e _ hp))\nopen classical\n\nprivate lemma cast_succ_nat_pos (n : \u2115) : (\u2191(n + 1) : \u211a) > 0 :=\nnat.cast_pos.2 $ succ_pos _\n\nprivate lemma div_nat_pos (n : \u2115) : (1 / ((n + 1): \u211a)) > 0 :=\ndiv_pos zero_lt_one (cast_succ_nat_pos _)\n\ndef lim_seq : \u2115 \u2192 \u211a := \u03bb n, classical.some (rat_dense (f n) (div_nat_pos n))\n\nlemma exi_rat_seq_conv {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) :\n  \u2203 N, \u2200 i \u2265 N, padic_norm_e (f i - of_rat hp ((lim_seq f) i)) < \u03b5 :=\nbegin\n  refine (exists_nat_gt (1/\u03b5)).imp (\u03bb N hN i hi, _),\n  have h := classical.some_spec (rat_dense (f i) (div_nat_pos i)),\n  rw \u2190 cast_eq_of_rat,\n  refine lt_of_lt_of_le h (div_le_of_le_mul (cast_succ_nat_pos _) _),\n  rw right_distrib,\n  apply le_add_of_le_of_nonneg,\n  { exact le_mul_of_div_le h\u03b5 (le_trans (le_of_lt hN) (nat.cast_le.2 hi)) },\n  { apply le_of_lt, simpa }\nend\n\nlemma exi_rat_seq_conv_cauchy : is_cau_seq (padic_norm hp) (lim_seq f) :=\nassume \u03b5 h\u03b5,\nhave h\u03b53 : \u03b5 / 3 > 0, from div_pos h\u03b5 (by norm_num),\nlet \u27e8N, hN\u27e9 := exi_rat_seq_conv f h\u03b53,\n    \u27e8N2, hN2\u27e9 := f.cauchy\u2082 h\u03b53 in\nbegin\n  existsi max N N2,\n  intros j hj,\n  rw [\u2190padic_norm_e.eq_padic_norm, padic.of_rat_sub],\n  suffices : padic_norm_e ((\u2191(lim_seq f j) - f (max N N2)) + (f (max N N2) - lim_seq f (max N N2))) < \u03b5,\n  { ring at this \u22a2, simpa only [cast_eq_of_rat] },\n  { apply lt_of_le_of_lt,\n    { apply padic_norm_e.add },\n    { have : (3 : \u211a) \u2260 0, by norm_num,\n      have : \u03b5 = \u03b5 / 3 + \u03b5 / 3 + \u03b5 / 3,\n      { apply eq_of_mul_eq_mul_left this, simp [left_distrib, mul_div_cancel' _ this ], ring },\n      rw this,\n      apply add_lt_add,\n      { suffices : padic_norm_e ((\u2191(lim_seq f j) - f j) + (f j - f (max N N2))) < \u03b5 / 3 + \u03b5 / 3,\n          by simpa,\n        apply lt_of_le_of_lt,\n        { apply padic_norm_e.add },\n        { apply add_lt_add,\n          { rw [padic_norm_e.sub_rev, cast_eq_of_rat], apply hN, apply le_of_max_le_left hj },\n          { apply hN2, apply le_of_max_le_right hj, apply le_max_right } } },\n      { rw cast_eq_of_rat, apply hN, apply le_max_left }}}\nend\n\nprivate def lim' : padic_seq hp := \u27e8_, exi_rat_seq_conv_cauchy f\u27e9\n\nprivate def lim : \u211a_[hp] := \u27e6lim' f\u27e7\n\ntheorem complete : \u2203 q : \u211a_[hp], \u2200 \u03b5 > 0, \u2203 N, \u2200 i \u2265 N, padic_norm_e (q - f i) < \u03b5 :=\n\u27e8 lim f,\n  \u03bb \u03b5 h\u03b5,\n  let \u27e8N, hN\u27e9 := exi_rat_seq_conv f (show \u03b5 / 2 > 0, from div_pos h\u03b5 (by norm_num)),\n      \u27e8N2, hN2\u27e9 := padic_norm_e.defn (lim' f) (show \u03b5 / 2 > 0, from div_pos h\u03b5 (by norm_num)) in\n  begin\n    existsi max N N2,\n    intros i hi,\n    suffices : padic_norm_e ((lim f - lim' f i) + (lim' f i - f i)) < \u03b5,\n    { ring at this; exact this },\n    { apply lt_of_le_of_lt,\n      { apply padic_norm_e.add },\n      { have : (2 : \u211a) \u2260 0, by norm_num,\n        have : \u03b5 = \u03b5 / 2 + \u03b5 / 2, by rw \u2190(add_self_div_two \u03b5); simp,\n        rw this,\n        apply add_lt_add,\n        { apply hN2, apply le_of_max_le_right hi },\n        { rw [padic_norm_e.sub_rev, cast_eq_of_rat], apply hN, apply le_of_max_le_left hi } } }\n  end \u27e9\n\nend complete\n\nend padic", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/padics/padic_rationals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7396704028892158}}
{"text": "/-\nCopyright (c) 2021 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport group_theory.subgroup.actions\nimport linear_algebra.linear_independent\n\n/-!\n# Rays in modules\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines rays in modules.\n\n## Main definitions\n\n* `same_ray`: two vectors belong to the same ray if they are proportional with a nonnegative\n  coefficient.\n\n* `module.ray` is a type for the equivalence class of nonzero vectors in a module with some\ncommon positive multiple.\n-/\n\nnoncomputable theory\n\nopen_locale big_operators\n\nsection strict_ordered_comm_semiring\n\nvariables (R : Type*) [strict_ordered_comm_semiring R]\nvariables {M : Type*} [add_comm_monoid M] [module R M]\nvariables {N : Type*} [add_comm_monoid N] [module R N]\nvariables (\u03b9 : Type*) [decidable_eq \u03b9]\n\n/-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them\nare equal (in the typical case over a field, this means one of them is a nonnegative multiple of\nthe other). -/\ndef same_ray (v\u2081 v\u2082 : M) : Prop :=\nv\u2081 = 0 \u2228 v\u2082 = 0 \u2228 \u2203 (r\u2081 r\u2082 : R), 0 < r\u2081 \u2227 0 < r\u2082 \u2227 r\u2081 \u2022 v\u2081 = r\u2082 \u2022 v\u2082\n\nvariables {R}\n\nnamespace same_ray\n\nvariables {x y z : M}\n\n@[simp] lemma zero_left (y : M) : same_ray R 0 y := or.inl rfl\n\n@[simp] lemma zero_right (x : M) : same_ray R x 0 := or.inr $ or.inl rfl\n\n@[nontriviality] lemma of_subsingleton [subsingleton M] (x y : M) : same_ray R x y :=\nby { rw [subsingleton.elim x 0], exact zero_left _ }\n\n@[nontriviality] lemma of_subsingleton' [subsingleton R] (x y : M) : same_ray R x y :=\nby { haveI := module.subsingleton R M, exact of_subsingleton x y }\n\n/-- `same_ray` is reflexive. -/\n@[refl] lemma refl (x : M) : same_ray R x x :=\nbegin\n  nontriviality R,\n  exact or.inr (or.inr $ \u27e81, 1, zero_lt_one, zero_lt_one, rfl\u27e9)\nend\n\nprotected lemma rfl : same_ray R x x := refl _\n\n/-- `same_ray` is symmetric. -/\n@[symm] lemma symm (h : same_ray R x y) : same_ray R y x :=\n(or.left_comm.1 h).imp_right $ or.imp_right $ \u03bb \u27e8r\u2081, r\u2082, h\u2081, h\u2082, h\u27e9, \u27e8r\u2082, r\u2081, h\u2082, h\u2081, h.symm\u27e9\n\n/-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r\u2081 r\u2082`\nsuch that `r\u2081 \u2022 x = r\u2082 \u2022 y`. -/\nlemma exists_pos (h : same_ray R x y) (hx : x \u2260 0) (hy : y \u2260 0) :\n  \u2203 r\u2081 r\u2082 : R, 0 < r\u2081 \u2227 0 < r\u2082 \u2227 r\u2081 \u2022 x = r\u2082 \u2022 y :=\n(h.resolve_left hx).resolve_left hy\n\nlemma _root_.same_ray_comm : same_ray R x y \u2194 same_ray R y x :=\n\u27e8same_ray.symm, same_ray.symm\u27e9\n\n/-- `same_ray` is transitive unless the vector in the middle is zero and both other vectors are\nnonzero. -/\nlemma trans (hxy : same_ray R x y) (hyz : same_ray R y z) (hy : y = 0 \u2192 x = 0 \u2228 z = 0) :\n  same_ray R x z :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hx, { exact zero_left z },\n  rcases eq_or_ne z 0 with rfl|hz, { exact zero_right x },\n  rcases eq_or_ne y 0 with rfl|hy, { exact (hy rfl).elim (\u03bb h, (hx h).elim) (\u03bb h, (hz h).elim) },\n  rcases hxy.exists_pos hx hy with \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u2081\u27e9,\n  rcases hyz.exists_pos hy hz with \u27e8r\u2083, r\u2084, hr\u2083, hr\u2084, h\u2082\u27e9,\n  refine or.inr (or.inr $ \u27e8r\u2083 * r\u2081, r\u2082 * r\u2084, mul_pos hr\u2083 hr\u2081, mul_pos hr\u2082 hr\u2084, _\u27e9),\n  rw [mul_smul, mul_smul, h\u2081, \u2190 h\u2082, smul_comm]\nend\n\n/-- A vector is in the same ray as a nonnegative multiple of itself. -/\nlemma _root_.same_ray_nonneg_smul_right (v : M) {r : R} (h : 0 \u2264 r) : same_ray R v (r \u2022 v) :=\nor.inr $ h.eq_or_lt.imp (\u03bb h, h \u25b8 zero_smul R v) $\n  \u03bb h, \u27e8r, 1, h, by { nontriviality R, exact zero_lt_one }, (one_smul _ _).symm\u27e9\n\n/-- A vector is in the same ray as a positive multiple of itself. -/\nlemma _root_.same_ray_pos_smul_right (v : M) {r : R} (h : 0 < r) : same_ray R v (r \u2022 v) :=\nsame_ray_nonneg_smul_right v h.le\n\n/-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/\nlemma nonneg_smul_right {r : R} (h : same_ray R x y) (hr : 0 \u2264 r) : same_ray R x (r \u2022 y) :=\nh.trans (same_ray_nonneg_smul_right y hr) $ \u03bb hy, or.inr $ by rw [hy, smul_zero]\n\n/-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/\nlemma pos_smul_right {r : R} (h : same_ray R x y) (hr : 0 < r) : same_ray R x (r \u2022 y) :=\nh.nonneg_smul_right hr.le\n\n/-- A nonnegative multiple of a vector is in the same ray as that vector. -/\nlemma _root_.same_ray_nonneg_smul_left (v : M) {r : R} (h : 0 \u2264 r) : same_ray R (r \u2022 v) v :=\n(same_ray_nonneg_smul_right v h).symm\n\n/-- A positive multiple of a vector is in the same ray as that vector. -/\nlemma _root_.same_ray_pos_smul_left (v : M) {r : R} (h : 0 < r) : same_ray R (r \u2022 v) v :=\nsame_ray_nonneg_smul_left v h.le\n\n/-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/\nlemma nonneg_smul_left {r : R} (h : same_ray R x y) (hr : 0 \u2264 r) : same_ray R (r \u2022 x) y :=\n(h.symm.nonneg_smul_right hr).symm\n\n/-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/\nlemma pos_smul_left {r : R} (h : same_ray R x y) (hr : 0 < r) : same_ray R (r \u2022 x) y :=\nh.nonneg_smul_left hr.le\n\n/-- If two vectors are on the same ray then they remain so after applying a linear map. -/\nlemma map (f : M \u2192\u2097[R] N) (h : same_ray R x y) : same_ray R (f x) (f y) :=\nh.imp (\u03bb hx, by rw [hx, map_zero]) $ or.imp (\u03bb hy, by rw [hy, map_zero]) $\n  \u03bb \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9, \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, by rw [\u2190f.map_smul, \u2190f.map_smul, h]\u27e9\n\n/-- The images of two vectors under an injective linear map are on the same ray if and only if the\noriginal vectors are on the same ray. -/\nlemma _root_.function.injective.same_ray_map_iff {F : Type*} [linear_map_class F R M N] {f : F}\n  (hf : function.injective f) : same_ray R (f x) (f y) \u2194 same_ray R x y :=\nby simp only [same_ray, map_zero, \u2190 hf.eq_iff, map_smul]\n\n/-- The images of two vectors under a linear equivalence are on the same ray if and only if the\noriginal vectors are on the same ray. -/\n@[simp] lemma _root_.same_ray_map_iff (e : M \u2243\u2097[R] N) : same_ray R (e x) (e y) \u2194 same_ray R x y :=\nfunction.injective.same_ray_map_iff (equiv_like.injective e)\n\n/-- If two vectors are on the same ray then both scaled by the same action are also on the same\nray. -/\nlemma smul {S : Type*} [monoid S] [distrib_mul_action S M] [smul_comm_class R S M]\n  (h : same_ray R x y) (s : S) : same_ray R (s \u2022 x) (s \u2022 y) :=\nh.map (s \u2022 (linear_map.id : M \u2192\u2097[R] M))\n\n/-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/\nlemma add_left (hx : same_ray R x z) (hy : same_ray R y z) : same_ray R (x + y) z :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hx\u2080, { rwa zero_add },\n  rcases eq_or_ne y 0 with rfl|hy\u2080, { rwa add_zero },\n  rcases eq_or_ne z 0 with rfl|hz\u2080, { apply zero_right },\n  rcases hx.exists_pos hx\u2080 hz\u2080 with \u27e8rx, rz\u2081, hrx, hrz\u2081, Hx\u27e9,\n  rcases hy.exists_pos hy\u2080 hz\u2080 with \u27e8ry, rz\u2082, hry, hrz\u2082, Hy\u27e9,\n  refine or.inr (or.inr \u27e8rx * ry, ry * rz\u2081 + rx * rz\u2082, mul_pos hrx hry, _, _\u27e9),\n  { apply_rules [add_pos, mul_pos] },\n  { simp only [mul_smul, smul_add, add_smul, \u2190 Hx, \u2190 Hy],\n    rw smul_comm }\nend\n\n/-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/\nlemma add_right (hy : same_ray R x y) (hz : same_ray R x z) : same_ray R x (y + z) :=\n(hy.symm.add_left hz.symm).symm\n\nend same_ray\n\n/-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that\n`ray_vector.setoid` can be an instance. -/\n@[nolint unused_arguments has_nonempty_instance]\ndef ray_vector (R M : Type*) [has_zero M] := {v : M // v \u2260 0}\n\ninstance ray_vector.has_coe {R M : Type*} [has_zero M] :\n  has_coe (ray_vector R M) M := coe_subtype\n\ninstance {R M : Type*} [has_zero M] [nontrivial M] : nonempty (ray_vector R M) :=\nlet \u27e8x, hx\u27e9 := exists_ne (0 : M) in \u27e8\u27e8x, hx\u27e9\u27e9\n\nvariables (R M)\n\n/-- The setoid of the `same_ray` relation for the subtype of nonzero vectors. -/\ninstance : setoid (ray_vector R M) :=\n{ r := \u03bb x y, same_ray R (x : M) y,\n  iseqv := \u27e8\u03bb x, same_ray.refl _, \u03bb x y h, h.symm,\n    \u03bb x y z hxy hyz, hxy.trans hyz $ \u03bb hy, (y.2 hy).elim\u27e9 }\n\n/-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/\n@[nolint has_nonempty_instance]\ndef module.ray := quotient (ray_vector.setoid R M)\n\nvariables {R M}\n\n/-- Equivalence of nonzero vectors, in terms of same_ray. -/\nlemma equiv_iff_same_ray {v\u2081 v\u2082 : ray_vector R M} :\n  v\u2081 \u2248 v\u2082 \u2194 same_ray R (v\u2081 : M) v\u2082 :=\niff.rfl\n\nvariables (R)\n\n/-- The ray given by a nonzero vector. -/\nprotected def ray_of_ne_zero (v : M) (h : v \u2260 0) : module.ray R M := \u27e6\u27e8v, h\u27e9\u27e7\n\n/-- An induction principle for `module.ray`, used as `induction x using module.ray.ind`. -/\nlemma module.ray.ind {C : module.ray R M \u2192 Prop}\n  (h : \u2200 v (hv : v \u2260 0), C (ray_of_ne_zero R v hv)) (x : module.ray R M) : C x :=\nquotient.ind (subtype.rec $ by exact h) x\n\nvariable {R}\n\ninstance [nontrivial M] : nonempty (module.ray R M) :=\nnonempty.map quotient.mk infer_instance\n\n/-- The rays given by two nonzero vectors are equal if and only if those vectors\nsatisfy `same_ray`. -/\nlemma ray_eq_iff {v\u2081 v\u2082 : M} (hv\u2081 : v\u2081 \u2260 0) (hv\u2082 : v\u2082 \u2260 0) :\n  ray_of_ne_zero R _ hv\u2081 = ray_of_ne_zero R _ hv\u2082 \u2194 same_ray R v\u2081 v\u2082 :=\nquotient.eq\n\n/-- The ray given by a positive multiple of a nonzero vector. -/\n@[simp] lemma ray_pos_smul {v : M} (h : v \u2260 0) {r : R} (hr : 0 < r)\n  (hrv : r \u2022 v \u2260 0) : ray_of_ne_zero R (r \u2022 v) hrv = ray_of_ne_zero R v h :=\n(ray_eq_iff _ _).2 $ same_ray_pos_smul_left v hr\n\n/-- An equivalence between modules implies an equivalence between ray vectors. -/\ndef ray_vector.map_linear_equiv (e : M \u2243\u2097[R] N) : ray_vector R M \u2243 ray_vector R N :=\nequiv.subtype_equiv e.to_equiv $ \u03bb _, e.map_ne_zero_iff.symm\n\n/-- An equivalence between modules implies an equivalence between rays. -/\ndef module.ray.map (e : M \u2243\u2097[R] N) : module.ray R M \u2243 module.ray R N :=\nquotient.congr (ray_vector.map_linear_equiv e) $ \u03bb \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, (same_ray_map_iff _).symm\n\n@[simp] lemma module.ray.map_apply (e : M \u2243\u2097[R] N) (v : M) (hv : v \u2260 0) :\n  module.ray.map e (ray_of_ne_zero _ v hv) = ray_of_ne_zero _ (e v) (e.map_ne_zero_iff.2 hv) := rfl\n\n@[simp] lemma module.ray.map_refl : (module.ray.map $ linear_equiv.refl R M) = equiv.refl _ :=\nequiv.ext $ module.ray.ind R $ \u03bb _ _, rfl\n\n@[simp] lemma module.ray.map_symm (e : M \u2243\u2097[R] N) :\n  (module.ray.map e).symm = module.ray.map e.symm := rfl\n\nsection action\nvariables {G : Type*} [group G] [distrib_mul_action G M]\n\n/-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest\nwhen `G = R\u02e3` -/\ninstance {R : Type*} : mul_action G (ray_vector R M) :=\n{ smul := \u03bb r, (subtype.map ((\u2022) r) $ \u03bb a, (smul_ne_zero_iff_ne _).2),\n  mul_smul := \u03bb a b m, subtype.ext $ mul_smul a b _,\n  one_smul := \u03bb m, subtype.ext $ one_smul _ _ }\n\nvariables [smul_comm_class R G M]\n\n/-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when\n`G = R\u02e3` -/\ninstance : mul_action G (module.ray R M) :=\n{ smul := \u03bb r, quotient.map ((\u2022) r) (\u03bb a b h, h.smul _),\n  mul_smul := \u03bb a b, quotient.ind $ by exact(\u03bb m, congr_arg quotient.mk $ mul_smul a b _),\n  one_smul := quotient.ind $ by exact (\u03bb m, congr_arg quotient.mk $ one_smul _ _), }\n\n/-- The action via `linear_equiv.apply_distrib_mul_action` corresponds to `module.ray.map`. -/\n@[simp] lemma module.ray.linear_equiv_smul_eq_map (e : M \u2243\u2097[R] M) (v : module.ray R M) :\n  e \u2022 v = module.ray.map e v := rfl\n\n@[simp] lemma smul_ray_of_ne_zero (g : G) (v : M) (hv) :\n  g \u2022 ray_of_ne_zero R v hv = ray_of_ne_zero R (g \u2022 v) ((smul_ne_zero_iff_ne _).2 hv) := rfl\n\nend action\n\nnamespace module.ray\n\n/-- Scaling by a positive unit is a no-op. -/\nlemma units_smul_of_pos (u : R\u02e3) (hu : 0 < (u : R)) (v : module.ray R M) :\n  u \u2022 v = v :=\nbegin\n  induction v using module.ray.ind,\n  rw [smul_ray_of_ne_zero, ray_eq_iff],\n  exact same_ray_pos_smul_left _ hu\nend\n\n/-- An arbitrary `ray_vector` giving a ray. -/\ndef some_ray_vector (x : module.ray R M) : ray_vector R M := quotient.out x\n\n/-- The ray of `some_ray_vector`. -/\n@[simp] lemma some_ray_vector_ray (x : module.ray R M) :\n  (\u27e6x.some_ray_vector\u27e7 : module.ray R M) = x :=\nquotient.out_eq _\n\n/-- An arbitrary nonzero vector giving a ray. -/\ndef some_vector (x : module.ray R M) : M := x.some_ray_vector\n\n/-- `some_vector` is nonzero. -/\n@[simp] lemma some_vector_ne_zero (x : module.ray R M) : x.some_vector \u2260 0 :=\nx.some_ray_vector.property\n\n/-- The ray of `some_vector`. -/\n@[simp] lemma some_vector_ray (x : module.ray R M) :\n  ray_of_ne_zero R _ x.some_vector_ne_zero = x :=\n(congr_arg _ (subtype.coe_eta _ _) : _).trans x.out_eq\n\nend module.ray\n\nend strict_ordered_comm_semiring\n\nsection strict_ordered_comm_ring\n\nvariables {R : Type*} [strict_ordered_comm_ring R]\nvariables {M N : Type*} [add_comm_group M] [add_comm_group N] [module R M] [module R N] {x y : M}\n\n/-- `same_ray.neg` as an `iff`. -/\n@[simp] lemma same_ray_neg_iff : same_ray R (-x) (-y) \u2194 same_ray R x y :=\nby simp only [same_ray, neg_eq_zero, smul_neg, neg_inj]\n\nalias same_ray_neg_iff \u2194 same_ray.of_neg same_ray.neg\n\nlemma same_ray_neg_swap : same_ray R (-x) y \u2194 same_ray R x (-y) :=\nby rw [\u2190 same_ray_neg_iff, neg_neg]\n\nlemma eq_zero_of_same_ray_neg_smul_right [no_zero_smul_divisors R M] {r : R} (hr : r < 0)\n  (h : same_ray R x (r \u2022 x)) :\n  x = 0 :=\nbegin\n  rcases h with rfl|h\u2080|\u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9,\n  { refl },\n  { simpa [hr.ne] using h\u2080 },\n  { rw [\u2190 sub_eq_zero, smul_smul, \u2190 sub_smul, smul_eq_zero] at h,\n    refine h.resolve_left (ne_of_gt $ sub_pos.2 _),\n    exact (mul_neg_of_pos_of_neg hr\u2082 hr).trans hr\u2081 }\nend\n\n/-- If a vector is in the same ray as its negation, that vector is zero. -/\nlemma eq_zero_of_same_ray_self_neg [no_zero_smul_divisors R M] (h : same_ray R x (-x)) :\n  x = 0 :=\nbegin\n  nontriviality M, haveI : nontrivial R := module.nontrivial R M,\n  refine eq_zero_of_same_ray_neg_smul_right (neg_lt_zero.2 (zero_lt_one' R)) _,\n  rwa [neg_one_smul]\nend\n\nnamespace ray_vector\n\n/-- Negating a nonzero vector. -/\ninstance {R : Type*} : has_neg (ray_vector R M) := \u27e8\u03bb v, \u27e8-v, neg_ne_zero.2 v.prop\u27e9\u27e9\n\n/-- Negating a nonzero vector commutes with coercion to the underlying module. -/\n@[simp, norm_cast] lemma coe_neg {R : Type*} (v : ray_vector R M) : \u2191(-v) = -(v : M) := rfl\n\n/-- Negating a nonzero vector twice produces the original vector. -/\ninstance {R : Type*} : has_involutive_neg (ray_vector R M) :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb v, by rw [subtype.ext_iff, coe_neg, coe_neg, neg_neg] }\n\n/-- If two nonzero vectors are equivalent, so are their negations. -/\n@[simp] lemma equiv_neg_iff {v\u2081 v\u2082 : ray_vector R M} : -v\u2081 \u2248 -v\u2082 \u2194 v\u2081 \u2248 v\u2082 :=\nsame_ray_neg_iff\n\nend ray_vector\n\nvariables (R)\n\n/-- Negating a ray. -/\ninstance : has_neg (module.ray R M) :=\n\u27e8quotient.map (\u03bb v, -v) (\u03bb v\u2081 v\u2082, ray_vector.equiv_neg_iff.2)\u27e9\n\n/-- The ray given by the negation of a nonzero vector. -/\n@[simp] lemma neg_ray_of_ne_zero (v : M) (h : v \u2260 0) :\n  -(ray_of_ne_zero R _ h) = ray_of_ne_zero R (-v) (neg_ne_zero.2 h) :=\nrfl\n\nnamespace module.ray\n\nvariables {R}\n\n/-- Negating a ray twice produces the original ray. -/\ninstance : has_involutive_neg (module.ray R M) :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb x, quotient.ind (\u03bb a, congr_arg quotient.mk $ neg_neg _) x }\n\nvariables {R M}\n\n/-- A ray does not equal its own negation. -/\nlemma ne_neg_self [no_zero_smul_divisors R M] (x : module.ray R M) : x \u2260 -x :=\nbegin\n  induction x using module.ray.ind with x hx,\n  rw [neg_ray_of_ne_zero, ne.def, ray_eq_iff],\n  exact mt eq_zero_of_same_ray_self_neg hx\nend\n\nlemma neg_units_smul (u : R\u02e3) (v : module.ray R M) : (-u) \u2022 v = - (u \u2022 v) :=\nbegin\n  induction v using module.ray.ind,\n  simp only [smul_ray_of_ne_zero, units.smul_def, units.coe_neg, neg_smul, neg_ray_of_ne_zero]\nend\n\n/-- Scaling by a negative unit is negation. -/\nlemma units_smul_of_neg (u : R\u02e3) (hu : (u : R) < 0) (v : module.ray R M) :\n  u \u2022 v = -v :=\nbegin\n  rw [\u2190 neg_inj, neg_neg, \u2190 neg_units_smul, units_smul_of_pos],\n  rwa [units.coe_neg, right.neg_pos_iff]\nend\n\n@[simp] protected lemma map_neg (f : M \u2243\u2097[R] N) (v : module.ray R M) : map f (-v) = - map f v :=\nbegin\n  induction v using module.ray.ind with g hg,\n  simp,\nend\n\nend module.ray\n\nend strict_ordered_comm_ring\n\nsection linear_ordered_comm_ring\n\nvariables {R : Type*} [linear_ordered_comm_ring R]\nvariables {M : Type*} [add_comm_group M] [module R M]\n\n/-- `same_ray` follows from membership of `mul_action.orbit` for the `units.pos_subgroup`. -/\nlemma same_ray_of_mem_orbit {v\u2081 v\u2082 : M} (h : v\u2081 \u2208 mul_action.orbit (units.pos_subgroup R) v\u2082) :\n  same_ray R v\u2081 v\u2082 :=\nbegin\n  rcases h with \u27e8\u27e8r, hr : 0 < (r : R)\u27e9, (rfl : r \u2022 v\u2082 = v\u2081)\u27e9,\n  exact same_ray_pos_smul_left _ hr\nend\n\n/-- Scaling by an inverse unit is the same as scaling by itself. -/\n@[simp] lemma units_inv_smul (u : R\u02e3) (v : module.ray R M) :\n  u\u207b\u00b9 \u2022 v = u \u2022 v :=\ncalc u\u207b\u00b9 \u2022 v = (u * u) \u2022 u\u207b\u00b9 \u2022 v :\n  eq.symm $ (u\u207b\u00b9 \u2022 v).units_smul_of_pos _ $ mul_self_pos.2 u.ne_zero\n... = u \u2022 v : by rw [mul_smul, smul_inv_smul]\n\nsection\nvariables [no_zero_smul_divisors R M]\n\n@[simp] lemma same_ray_smul_right_iff {v : M} {r : R} :\n  same_ray R v (r \u2022 v) \u2194 0 \u2264 r \u2228 v = 0 :=\n\u27e8\u03bb hrv, or_iff_not_imp_left.2 $ \u03bb hr, eq_zero_of_same_ray_neg_smul_right (not_le.1 hr) hrv,\n  or_imp_distrib.2 \u27e8same_ray_nonneg_smul_right v, \u03bb h, h.symm \u25b8 same_ray.zero_left _\u27e9\u27e9\n\n/-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple\nis positive. -/\nlemma same_ray_smul_right_iff_of_ne {v : M} (hv : v \u2260 0) {r : R} (hr : r \u2260 0) :\n  same_ray R v (r \u2022 v) \u2194 0 < r :=\nby simp only [same_ray_smul_right_iff, hv, or_false, hr.symm.le_iff_lt]\n\n@[simp] lemma same_ray_smul_left_iff {v : M} {r : R} : same_ray R (r \u2022 v) v \u2194 0 \u2264 r \u2228 v = 0 :=\nsame_ray_comm.trans same_ray_smul_right_iff\n\n/-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple\nis positive. -/\nlemma same_ray_smul_left_iff_of_ne {v : M} (hv : v \u2260 0) {r : R} (hr : r \u2260 0) :\n  same_ray R (r \u2022 v) v \u2194 0 < r :=\nsame_ray_comm.trans (same_ray_smul_right_iff_of_ne hv hr)\n\n@[simp] lemma same_ray_neg_smul_right_iff {v : M} {r : R} :\n  same_ray R (-v) (r \u2022 v) \u2194 r \u2264 0 \u2228 v = 0 :=\nby rw [\u2190 same_ray_neg_iff, neg_neg, \u2190 neg_smul, same_ray_smul_right_iff, neg_nonneg]\n\nlemma same_ray_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v \u2260 0) (hr : r \u2260 0) :\n  same_ray R (-v) (r \u2022 v) \u2194 r < 0 :=\nby simp only [same_ray_neg_smul_right_iff, hv, or_false, hr.le_iff_lt]\n\n@[simp] lemma same_ray_neg_smul_left_iff {v : M} {r : R} :\n  same_ray R (r \u2022 v) (-v) \u2194 r \u2264 0 \u2228 v = 0 :=\nsame_ray_comm.trans same_ray_neg_smul_right_iff\n\nlemma same_ray_neg_smul_left_iff_of_ne {v : M} {r : R} (hv : v \u2260 0) (hr : r \u2260 0) :\n  same_ray R (r \u2022 v) (-v) \u2194 r < 0 :=\nsame_ray_comm.trans $ same_ray_neg_smul_right_iff_of_ne hv hr\n\n@[simp] lemma units_smul_eq_self_iff {u : R\u02e3} {v : module.ray R M} :\n  u \u2022 v = v \u2194 (0 : R) < u :=\nbegin\n  induction v using module.ray.ind with v hv,\n  simp only [smul_ray_of_ne_zero, ray_eq_iff, units.smul_def,\n    same_ray_smul_left_iff_of_ne hv u.ne_zero]\nend\n\n@[simp] lemma units_smul_eq_neg_iff {u : R\u02e3} {v : module.ray R M} :\n  u \u2022 v = -v \u2194 \u2191u < (0 : R) :=\nby rw [\u2190 neg_inj, neg_neg, \u2190 module.ray.neg_units_smul, units_smul_eq_self_iff, units.coe_neg,\n  neg_pos]\n\n/-- Two vectors are in the same ray, or the first is in the same ray as the negation of the\nsecond, if and only if they are not linearly independent. -/\nlemma same_ray_or_same_ray_neg_iff_not_linear_independent {x y : M} :\n  (same_ray R x y \u2228 same_ray R x (-y)) \u2194 \u00ac linear_independent R ![x, y] :=\nbegin\n  by_cases hx : x = 0, { simp [hx, \u03bb h : linear_independent R ![0, y], h.ne_zero 0 rfl] },\n  by_cases hy : y = 0, { simp [hy, \u03bb h : linear_independent R ![x, 0], h.ne_zero 1 rfl] },\n  simp_rw [fintype.not_linear_independent_iff, fin.sum_univ_two, fin.exists_fin_two],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rcases h with (hx0|hy0|\u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9)|(hx0|hy0|\u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9),\n    { exact false.elim (hx hx0) },\n    { exact false.elim (hy hy0) },\n    { refine \u27e8![r\u2081, -r\u2082], _\u27e9, simp [h, hr\u2081.ne.symm] },\n    { exact false.elim (hx hx0) },\n    { exact false.elim (hy (neg_eq_zero.1 hy0)) },\n    { refine \u27e8![r\u2081, r\u2082], _\u27e9, simp [h, hr\u2081.ne.symm] } },\n  { rcases h with \u27e8m, hm, hmne\u27e9,\n    change m 0 \u2022 x + m 1 \u2022 y = 0 at hm,\n    rw add_eq_zero_iff_eq_neg at hm,\n    rcases lt_trichotomy (m 0) 0 with hm0|hm0|hm0; rcases lt_trichotomy (m 1) 0 with hm1|hm1|hm1,\n    { refine or.inr (or.inr (or.inr \u27e8-(m 0), -(m 1), left.neg_pos_iff.2 hm0,\n                                     left.neg_pos_iff.2 hm1, _\u27e9)),\n      simp [hm] },\n    { exfalso, simpa [hm1, hx, hm0.ne] using hm },\n    { refine or.inl (or.inr (or.inr \u27e8-(m 0), m 1, left.neg_pos_iff.2 hm0, hm1, _\u27e9)),\n      simp [hm] },\n    { exfalso, simpa [hm0, hy, hm1.ne] using hm },\n    { refine false.elim (not_and_distrib.2 hmne \u27e8hm0, hm1\u27e9) },\n    { exfalso, simpa [hm0, hy, hm1.ne.symm] using hm },\n    { refine or.inl (or.inr (or.inr \u27e8m 0, -(m 1), hm0, left.neg_pos_iff.2 hm1, _\u27e9)),\n      simp [hm] },\n    { exfalso, simpa [hm1, hx, hm0.ne.symm] using hm },\n    { refine or.inr (or.inr (or.inr \u27e8m 0, m 1, hm0, hm1, _\u27e9)),\n      simp [hm] } }\nend\n\n/-- Two vectors are in the same ray, or they are nonzero and the first is in the same ray as the\nnegation of the second, if and only if they are not linearly independent. -/\nlemma same_ray_or_ne_zero_and_same_ray_neg_iff_not_linear_independent {x y : M} :\n  (same_ray R x y \u2228 x \u2260 0 \u2227 y \u2260 0 \u2227 same_ray R x (-y)) \u2194 \u00ac linear_independent R ![x, y] :=\nbegin\n  rw \u2190same_ray_or_same_ray_neg_iff_not_linear_independent,\n  by_cases hx : x = 0, { simp [hx] },\n  by_cases hy : y = 0;\n    simp [hx, hy]\nend\n\nend\n\nend linear_ordered_comm_ring\n\nnamespace same_ray\n\nvariables {R : Type*} [linear_ordered_field R]\nvariables {M : Type*} [add_comm_group M] [module R M] {x y v\u2081 v\u2082 : M}\n\nlemma exists_pos_left (h : same_ray R x y) (hx : x \u2260 0) (hy : y \u2260 0) :\n  \u2203 r : R, 0 < r \u2227 r \u2022 x = y :=\nlet \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9 := h.exists_pos hx hy in\n  \u27e8r\u2082\u207b\u00b9 * r\u2081, mul_pos (inv_pos.2 hr\u2082) hr\u2081, by rw [mul_smul, h, inv_smul_smul\u2080 hr\u2082.ne']\u27e9\n\nlemma exists_pos_right (h : same_ray R x y) (hx : x \u2260 0) (hy : y \u2260 0) :\n  \u2203 r : R, 0 < r \u2227 x = r \u2022 y :=\n(h.symm.exists_pos_left hy hx).imp $ \u03bb _, and.imp_right eq.symm\n\n/-- If a vector `v\u2082` is on the same ray as a nonzero vector `v\u2081`, then it is equal to `c \u2022 v\u2081` for\nsome nonnegative `c`. -/\nlemma exists_nonneg_left (h : same_ray R x y) (hx : x \u2260 0) : \u2203 r : R, 0 \u2264 r \u2227 r \u2022 x = y :=\nbegin\n  obtain rfl | hy := eq_or_ne y 0,\n  { exact \u27e80, le_rfl, zero_smul _ _\u27e9 },\n  { exact (h.exists_pos_left hx hy).imp (\u03bb _, and.imp_left le_of_lt) }\nend\n\n/-- If a vector `v\u2081` is on the same ray as a nonzero vector `v\u2082`, then it is equal to `c \u2022 v\u2082` for\nsome nonnegative `c`. -/\nlemma exists_nonneg_right (h : same_ray R x y) (hy : y \u2260 0) : \u2203 r : R, 0 \u2264 r \u2227 x = r \u2022 y :=\n(h.symm.exists_nonneg_left hy).imp $ \u03bb _, and.imp_right eq.symm\n\n/-- If vectors `v\u2081` and `v\u2082` are on the same ray, then for some nonnegative `a b`, `a + b = 1`, we\nhave `v\u2081 = a \u2022 (v\u2081 + v\u2082)` and `v\u2082 = b \u2022 (v\u2081 + v\u2082)`. -/\nlemma exists_eq_smul_add (h : same_ray R v\u2081 v\u2082) :\n  \u2203 a b : R, 0 \u2264 a \u2227 0 \u2264 b \u2227 a + b = 1 \u2227 v\u2081 = a \u2022 (v\u2081 + v\u2082) \u2227 v\u2082 = b \u2022 (v\u2081 + v\u2082) :=\nbegin\n  rcases h with rfl|rfl|\u27e8r\u2081, r\u2082, h\u2081, h\u2082, H\u27e9,\n  { use [0, 1], simp },\n  { use [1, 0], simp },\n  { have h\u2081\u2082 : 0 < r\u2081 + r\u2082, from add_pos h\u2081 h\u2082,\n    refine \u27e8r\u2082 / (r\u2081 + r\u2082), r\u2081 / (r\u2081 + r\u2082), div_nonneg h\u2082.le h\u2081\u2082.le, div_nonneg h\u2081.le h\u2081\u2082.le,\n      _, _, _\u27e9,\n    { rw [\u2190 add_div, add_comm, div_self h\u2081\u2082.ne'] },\n    { rw [div_eq_inv_mul, mul_smul, smul_add, \u2190 H, \u2190 add_smul, add_comm r\u2082,\n        inv_smul_smul\u2080 h\u2081\u2082.ne'] },\n    { rw [div_eq_inv_mul, mul_smul, smul_add, H, \u2190 add_smul, add_comm r\u2082,\n        inv_smul_smul\u2080 h\u2081\u2082.ne'] } }\nend\n\n/-- If vectors `v\u2081` and `v\u2082` are on the same ray, then they are nonnegative multiples of the same\nvector. Actually, this vector can be assumed to be `v\u2081 + v\u2082`, see `same_ray.exists_eq_smul_add`. -/\nlemma exists_eq_smul (h : same_ray R v\u2081 v\u2082) :\n  \u2203 (u : M) (a b : R), 0 \u2264 a \u2227 0 \u2264 b \u2227 a + b = 1 \u2227 v\u2081 = a \u2022 u \u2227 v\u2082 = b \u2022 u :=\n\u27e8v\u2081 + v\u2082, h.exists_eq_smul_add\u27e9\n\nend same_ray\n\nsection linear_ordered_field\n\nvariables {R : Type*} [linear_ordered_field R]\nvariables {M : Type*} [add_comm_group M] [module R M] {x y : M}\n\nlemma exists_pos_left_iff_same_ray (hx : x \u2260 0) (hy : y \u2260 0) :\n  (\u2203 r : R, 0 < r \u2227 r \u2022 x = y) \u2194 same_ray R x y :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, h.exists_pos_left hx hy\u27e9,\n  rcases h with \u27e8r, hr, rfl\u27e9,\n  exact same_ray_pos_smul_right x hr\nend\n\nlemma exists_pos_left_iff_same_ray_and_ne_zero (hx : x \u2260 0) :\n  (\u2203 r : R, 0 < r \u2227 r \u2022 x = y) \u2194 (same_ray R x y \u2227 y \u2260 0) :=\nbegin\n  split,\n  { rintro \u27e8r, hr, rfl\u27e9,\n    simp [hx, hr.le, hr.ne'] },\n  { rintro \u27e8hxy, hy\u27e9,\n    exact (exists_pos_left_iff_same_ray hx hy).2 hxy }\nend\n\nlemma exists_nonneg_left_iff_same_ray (hx : x \u2260 0) :\n  (\u2203 r : R, 0 \u2264 r \u2227 r \u2022 x = y) \u2194 same_ray R x y :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, h.exists_nonneg_left hx\u27e9,\n  rcases h with \u27e8r, hr, rfl\u27e9,\n  exact same_ray_nonneg_smul_right x hr\nend\n\nlemma exists_pos_right_iff_same_ray (hx : x \u2260 0) (hy : y \u2260 0) :\n  (\u2203 r : R, 0 < r \u2227 x = r \u2022 y) \u2194 same_ray R x y :=\nby simpa only [same_ray_comm, eq_comm] using exists_pos_left_iff_same_ray hy hx\n\nlemma exists_pos_right_iff_same_ray_and_ne_zero (hy : y \u2260 0) :\n  (\u2203 r : R, 0 < r \u2227 x = r \u2022 y) \u2194 (same_ray R x y \u2227 x \u2260 0) :=\nby simpa only [same_ray_comm, eq_comm] using exists_pos_left_iff_same_ray_and_ne_zero hy\n\nlemma exists_nonneg_right_iff_same_ray (hy : y \u2260 0) :\n  (\u2203 r : R, 0 \u2264 r \u2227 x = r \u2022 y) \u2194 same_ray R x y :=\nby simpa only [same_ray_comm, eq_comm] using exists_nonneg_left_iff_same_ray hy\n\nend linear_ordered_field\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/ray.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7396704008661211}}
{"text": "-- Pruebas de A \u2208 \ud835\udcab (A \u222a B)\n-- ========================\n\nimport data.set\nopen set\n\nvariable  {U : Type}\nvariables (A B : set U)\n\n#reduce powerset A\n#reduce B \u2208 powerset A\n#reduce \ud835\udcab A\n#reduce B \u2208 \ud835\udcab A\n\n-- ?\u00aa demostraci\u00f3n\nexample : A \u2208 \ud835\udcab (A \u222a B) :=\nbegin\n  intros x h,\n  simp,\n  left,\n  exact h,\nend\n\n-- ?\u00aa demostraci\u00f3n\nexample : A \u2208 \ud835\udcab (A \u222a B) :=\nbegin\n  intros x h,\n  exact or.inl h,\nend\n\n-- ?\u00aa demostraci\u00f3n\nexample : A \u2208 \ud835\udcab (A \u222a B) :=\n\u03bb x, or.inl \n\n-- ?\u00aa demostraci\u00f3n\nexample : A \u2208 \ud835\udcab (A \u222a B) :=\nassume x,\nassume : x \u2208 A,\nshow x \u2208 A \u222a B, from or.inl \u2039x \u2208 A\u203a\n\n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Pruebas_de_A\u2208P(A\u222aB).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7396704008460162}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 2 : `true` and `false`\n\nWe learn about the `true` and `false` propositions.\n\n## Tactics you will need\n\nTo solve the levels on this sheet you will need to know all previous\ntactics, plus the following two new ones. Check out their explanations\nin the course book. Or just try them out and hover over them to see\nif you can understand what's going on.\n\n* `triv`\n* `exfalso`\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : true :=\nbegin\n  triv,\nend\n\nexample : true \u2192 true :=\nbegin\n  intro h,\n  exact h,\nend\n\nexample : false \u2192 true :=\nbegin\n  intro h,\n  triv,\nend\n\nexample : false \u2192 false :=\nbegin\n  intro h,\n  exact h,\nend\n\nexample : (true \u2192 false) \u2192 false :=\nbegin\n  intro h,\n  apply h,\n  triv,\nend\n\nexample : false \u2192 P :=\nbegin\n  intro h,\n  exfalso,\n  exact h,\nend\n\nexample : true \u2192 false \u2192 true \u2192 false \u2192 true \u2192 false :=\nbegin\n  intros h1 h2 h3 h4 h5,\n  exact h4,\nend\n\nexample : P \u2192 ((P \u2192 false) \u2192 false) :=\nbegin\n  intros hP h,\n  apply h,\n  assumption,\nend\n\nexample : (P \u2192 false) \u2192 P \u2192 Q :=\nbegin\n  intros h1 h2,\n  exfalso,\n  apply h1,\n  exact h2,\nend\n\nexample : (true \u2192 false) \u2192 P :=\nbegin\n  intro h,\n  exfalso,\n  apply h,\n  triv,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/solutions/section01logic/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.7396336796248631}}
{"text": "/-\nToday we will see in that proofs can be understood as formal\nobjects in their own right. \n\nWe will start to make our way through the valid rules of\ninference from our unit on propositional logic. We will\nemphasize that they are rules for combining and deriving\nBoolean truth values. In predicate logic, by contrast, we\nwill reinterpret them as rules for combining and deriving\n*proofs*. In predicate logic, the existence of a proof is\nour new basis for deciding whether or not a proposition \ncan be judged to be true.\n\nIn particular, we will look at how to (1) *construct* and \n(2) *use* given or assumed proofs of two simple forms of\npropositions, namely conjunctions and disjunctions. \n\nWe will see that we can view proofs as *computational*\nobjects. \n\nIn particular, we will see that we can view a proof of a\nconjunction, P \u2227 Q, as a *pair* of proofs (a proof of P\n*and* a proof of Q), and thus as a value of a *product* \ntype. We will then view a proof of a disjunction, P \u2228 Q,\nas *either* an object constructed from a proof of P *or* \nan object built from a proof of Q, and thus a value of a \n*sum* type.  \n\nUnderstanding proof construction and manipulation as\ncomputations involving logical types (propositions) and\nvalues (proofs) will give you the precise understanding\nof deductive reasoning in predicate logic that you need\nto handle a very wide variety of \"prove it\" problems in\nthe years to come, whether or not (and more likely not)\nyou use an automated proof assistant such as Lean or its\nformalized proofs.\n-/\n\n/-\nTo begin we will review our polymorphic product (pair)\ntype. We will then see that the \u2227 (and) connective in\npredicate logic can be understood and formalized as a\ncompletely analogous polymorphic *logical* type. It's\none costructor implements the and introduction rule,\nand its two projection functions implement the two\nand elimination rules. \n-/\n#check and\n\nnamespace hidden \n\n-- review -- prod abstract data type!\n\n-- be sure you fully understand this type definition\ninductive prod (\u03b1 \u03b2 : Type) : Type\n| mk (a : \u03b1) (b : \u03b2) : prod\n\n\n-- here's a named example of a value of this type\ndef pair1 := prod.mk 1 1\n\n#reduce pair1\n\n-- by the way, we can use \"example\" for unnamed values\nexample : prod nat nat := prod.mk 1 1\n\n-- the first, or left, projection function\n-- implemented by pattern matching (aka elimination!)\ndef fst {\u03b1 \u03b2 : Type} : prod \u03b1 \u03b2 \u2192 \u03b1 \n| (prod.mk a b) := a \n\n-- the second, or right, projection function\ndef snd {\u03b1 \u03b2 : Type} : prod \u03b1 \u03b2 \u2192 \u03b2  \n| (prod.mk a b) := b \n\n-- and a function that from one pair derives its swap\ndef swap  {\u03b1 \u03b2 : Type} : prod \u03b1 \u03b2 \u2192 prod \u03b2 \u03b1\n| (prod.mk a b) := prod.mk b a  \n\n\n/-\nOur implementation of the and connective and its rules\nof inference (introduction and elimination rules) in \nexactly the same way, except that our and polymorphic \npair type now lives in \"Prop,\" the unverse of logical\ntypes (propositions), rather than in \"Type\", which as\nwe know is the universe of computational types.\n\nAs a reminder from propositional logic, here are three \nrules of reasoning that we showed to be semantically valid. \n\ndef and_intro := P >> Q >> P \u2227 Q\ndef and_elim_left := P \u2227 Q >> P\ndef and_elim_right := P \u2227 Q >> Q\n\nIn propositional logic, we read these rules as involving\ntruth values: e.g., if P \"is true\" and Q \"is true\" then\n\"P \u2227 Q\" \"is true\". We now reconceptualize these rules to\ninvolve proofs. E.g., If we have (or assume we have) a \nproof, p, of P, and we have (or assume we have) a proof,\nq, of Q, then we can construct a proof, \u27e8p, q\u27e9, of P \u2227 Q.\nThat's the and introduction rule. Similarly, if we have \na proof (pair!), \u27e8p, q\u27e9, then from it we can derive a \nproof, p, of P, and a proof, q, of Q, by nothing more\ncomplex than projection: we destructure the pair and\nreturn one of the other other of its two components.\n\n-/\n\nstructure and (P Q : Prop) : Prop :=    -- Prop not Type!\nintro :: (left : P) (right : Q)         -- and.intro rule\n\n-- one poassible way to write left elimination rule\ndef and_elim_left {P Q : Prop} : and P Q \u2192 P\n| (and.intro p q) := p\n\n-- here's another, with elim_left in the \"and\" namespace\n-- note that we use projection function from \"structure\" \ndef and.elim_left {P Q : Prop}  (pq : and P Q) : P :=\npq.left \n\n-- and here is the right elimination rule in two forms\ndef and_elim_right {P Q : Prop} : and P Q \u2192 Q\n| (and.intro p q) := q\n\ndef and.elim_right {P Q : Prop}  (pq : and P Q) : Q :=\npq.right\n\n\n/-\nA note on notation. The Lean libraries define the and\nconnective exactly as we've done here. In addition, the\nLean library defined \u2227 as an infix notation for \"and\".\nWe won't define that notation here, so wherever we want\nto use the and connective, e.g., for P \u2227 Q, we'll have\nto write \"and P Q\". Same with or. \n-/\n\n-- tests\n\ndef pf1 : and (1=1) (eq 0 0) :=  -- 1=1 and 0=0\n  and.intro (eq.refl 1) (eq.refl 0) -- proof of it!\n  -- and.intro is a proof constructor\n\n-- We now see that pf1 is basically a pair of proofs\n#reduce pf1\n-- proof, left element 1=1, right element 0=0\n\n\n/- OR\n\nWe also formalize the logical connective, \u2228, as an \ninductive type with two (logical) type arguments,\nP and Q (two propositions). The both \u2227 and \u2228 take\ntwo propositions (logical types) as arguments and\nyield a larger proposition (logical type). We then\ndefine constructors to implement the introduction\nrules for the given connective. \n\nTo build a proof of P \u2227 Q, we need proofs of both\nP and of Q. To build a proof of P \u2228 Q it suffices\nto have either a proof of P or a proof of Q. \n\nHere are the propositional logic rules we validated\nin the last section.\n\ndef or_intro_left := P >> P \u2228 Q\ndef or_intro_right := Q >> P \u2228 Q\ndef or_elim := P \u2228 Q >> (P >> R) >> (Q >> R) >> R\n\nWe now reconceptualize these rules are rules about\nhow *proofs* can be built and derived.\n-/\n\n\n#check or\n\ninductive or (P Q : Prop) : Prop\n| inl {} (p : P) : or   -- Q is implicit\n-- if I have a proof of P I can build a proof of P or Q\n| inr {} (q : Q) : or   -- P is implicit\n-- inl/ inr are just names of constructors (intro left/ intro right)\n\ndef pf2 : or (eq 0 0) (eq 1 0) :=\nor.inl (eq.refl 0)\n\n-- example, proof of 0=0 \u2228 1=0\nexample : or (eq 0 0) (eq 1 0) :=\nor.inl (eq.refl 0)\n\n#check @or.elim\n-- @ turns off implicit types\n\nexample : or (eq 1 0) (eq 0 0) :=\nor.inr (eq.refl 0)\n\n\n/-\nProve that 1=1 and 2=2.\n\nQ: What's the form of this proposition?\nA: Conjunction. Main connective is and.\n\nQ: What rule of reasoning apply?\nA: The \"and\" introduction and elimination rules.\n\nQ: What is the form of the overall proof?\nA: and.intro p q, where p is a proof of P and q is a proof of Q.\n\nQ: So what remains to be done? \nA: It will now suffice to produce a proof of 1=1 and one of 2=2.\n\nQ: How to prove 1=1? \nA: By the reflexive property of equality. \n\nQ: How to prove 2 =2.\nA: Same way. \nQED! \n-/\n\n-- Here it is formally\n\nexample : and (1=1) (2=2) :=\n  and.intro (eq.refl 1) (eq.refl 2)\n\n\n/-\nThe following versions of the introductions rules take two explicit\narguments each: a *proposition* for which a proof is *not* given and\na proof of the other proposition. Notice carefully the change in which\ntype argument is implicit in each case. Sometimes Lean can't infer \nfrom, say, a proof, p, of P, what disjunction, P \u2228 Q, is being proved\n(because it can't figure out what Q is). In such cases, you need to \nprovide the Q type explicitly. These functions are useful in such cases. \n-/\ndef or.intro_left {P : Prop} (Q : Prop) (p : P) : or P Q :=\nor.inl p\n\ndef or.intro_right (P : Prop) {Q : Prop} (q : Q) : or P Q :=\nor.inr q\n\n\n/-\nProve 1=0 or 1=1.\n\nProof: We apply the or introduction on the right rule to a\nproof of 1=1. Now all that remains is to to that 1=1. This is \nby applying the reflexive property of equality (to the value,\n1).\n-/\n\n-- Here is this proof formalized\nexample : or (1=0) (1=1) := or.inr (eq.refl 1) \nexample : or (1=0) (1=1) := or.intro_right (1=0) (eq.refl 1) \n\ndef x : \u2115 := 1\nexample : \u2115 := 1\n\n\n\n\n/-\nNEXT UP: \u2200, \u2192 \n-/\n\n/-\n************************************************************\nUniversal generalizations. Propositions starting with forall.\n************************************************************\n-/\n\n\n/-\nIntroduction rule: To prove \"\u2200 (p : P), Q\" show that if you *assume*\nyou're given an arbitrary but specific p, you can construct a proof\nof Q. This is the \u2200 introduction rule of natural deduction.\n-/\nexample : \u2200 (n : \u2115), or (n = 0) (n \u2260 0) :=\n  \u03bb (n : \u2115),\n    match n with\n    | nat.zero := or.inl (eq.refl 0)\n    | (nat.succ _) := _    -- Homework\n    end \n\n/-\nProof: \nWe start by assuming that we're given an arbitrary but specific \nnatural number, n. Now in this context, all that remains to be\nproved is that n = 0 or n \u2260 0.\n-/\n\n\n/-\nProve that for any propositions, P and Q, P \u2227 Q \u2192 P \u2228 Q\n-/\n\ndef aProp := \u2200 (P Q : Prop), and P Q \u2192 or P Q \n\n/-\nWe start by assuming that P and Q are arbitrary but specific\npropositions. In this context, what remains to be proved is\nthe following implication: and P Q \u2192 or P Q. To prove this is\nto prove an implication. We do this in the same way we prove\na \u2200: by assuming that we're given a proof of the premise, P, \nand showing that, in that context, we can construct a proof \nof the conclusion, Q.\n-/\n\nlemma and_imp_or_1 : aProp := \n  \u03bb (P Q : Prop),\n    \u03bb (pq : and P Q),\n      or.inl (and.elim_left pq)\n\nlemma and_imp_or_2  : aProp := \n  \u03bb (P Q : Prop),\n    \u03bb (pq : and P Q),\n      or.inr (and.elim_right pq)\n\nexample : and_imp_or_1 = and_imp_or_2 := eq.refl and_imp_or_2\n\nexample : \u2200 (P Q : Prop), and P Q \u2192 and Q P :=\n  \u03bb (P Q : Prop),\n    \u03bb (pq : and P Q),\n      and.intro\n        (pq.right)\n        (pq.left)\n\n/-\nProve that the \"and\" connective is commutative.\n-/\n\ntheorem and_commutes : \u2200 {P Q : Prop}, and P Q \u2192 and Q P :=\n\u03bb (P Q : Prop), \n  \u03bb (pq : and P Q),\n    and.intro \n      (pq.right) \n      (pq.left)\n\n/-\nAssume that P and Q are arbitary but specific propositions.\nWe are to show that P \u2227 Q \u2192 Q \u2227 P. Suppose we have a proof,\npq, of P \u2227 Q. In this context we need to prove that we can\nconstruct a proof of Q and P. We do this by applying the and\nintroduction rule to a proof of P and to a proof of Q. What\nremains to be proven is that there is a proof of P and a proof\nof Q. But we can get these by applying the left and right and\neliminations rules to\n\nour proof, pq, of P \u2227 Q.\n-/\n\n/-\nIf a proof of a \u2200 or \u2192 proposition is a function in Lean,\ncan we apply these functions to arguments to get results?\nThe answer is yes, absolutely, and this idea is in fact\nthe *elimination* rule for \u2200 and \u2192. If you're given a \nproof, pf, of either \u2200 (p : P), Q, or of P \u2192 Q, which are\nin fact equivalent(!), then you can apply pf to a proof or\nvalue, p : P, to obtain a corresponding value/proof of Q.\n\nAs an example, let's apply our proof that and is commutative\n-/\nlemma oneeq1_and_2eq2 : and (1=1) (2=2) :=\n  and.intro (eq.refl 1) (eq.refl 2)\n\n#reduce oneeq1_and_2eq2\n\n-- introduction rule used to build proof of bigger prop\n-- elim rule is a rule for using a bigger proof to break\n-- it up and give you pieces\n\n/-\nWe now use the elimination rule for \u2200/\u2192 by *applying* the\n*general* proof of commutative of and to a *specific* proof\nof (and 1=1 2=2) to obtain a specific proof of (and 2=2 1=1)!\n-/\n#reduce and_commutes oneeq1_and_2eq2 \n\n/-\nThe *elimination* rule for \u2200 all and implication is \"apply!\"\n-/\n\n/-\nThis principal is seen very clearly in the proof of the\nrule of reasoning that Aristotle called \"modus ponens.\" \nIt states that if, for any propositions P and Q, you know\nthat P \u2192 Q is true and you also know that P is true then\nyou can conclude that Q is true. If when it's raining the\nstreets are wet (P \u2192 Q) and it's raining (P) then it must\nbe the case that the streets are wet (Q). We now prove that\nthis is a valid form of reasoning.\n-/\n\ntheorem arrow_elim : \u2200 {P Q : Prop}, (P \u2192 Q) \u2192 P \u2192 Q :=\n\u03bb (P Q : Prop),\n  \u03bb (p2q : P \u2192 Q),\n    \u03bb (p : P),\n      p2q p       ---<<< apply proof of P\u2192Q to proof of P!\n\n\n/--- TODAY ---/\n\n/-\nPropositions that use \u00ac\n-/\n\n/-\nSuppose you want to prove \u00acP. We have to show that there's no proof of P.\nKey strategy: Proof by negation. Assume that P is true, and show that this\nassumption leads to a contradiction. Equivalent to a proof of false. So the\nidea is this: assume that there is a proof of P and show that this enables\nyou to construct a proof of false.\n\n\u00ac P ==== P \u2192 false\n-/\n\nexample : 0 \u2260 1 := \n/- the same as\n \u00ac (0 = 1) -/\n/- (0 = 1) \u2192 false -/\n\u03bb (h : 0 = 1), \n  match h with /- NO CASES! -/ end\n\n-- modus tollens\ntheorem mt : \u2200 {P Q}, (P \u2192 Q) \u2192 (\u00acQ \u2192 \u00acP) :=\n\u03bb P Q,\n  \u03bb (h : P \u2192 Q),\n    \u03bb (nq : \u00acQ),\n      \u03bb (p : P),\n       nq (h p)\n\ntheorem non_contradiction: \u2200 (P : Prop), \u00ac (P \u2227 \u00ac P) := \n  \u03bb P,                        -- forall introduction \n    \u03bb (h : P \u2227 \u00acP),           -- proof by negation\n      let p := (h.left) in    -- and.elim_left \n      let np := (h.right) in  -- and.elim_right\n      (np p)    \n\n\ntheorem zornz : \u2200 (n : \u2115), or (n = 0) (n \u2260 0) :=\n\u03bb (n : \u2115),\n  match n with\n  | nat.zero := or.inl (eq.refl 0)\n  | (nat.succ n') := or.inr _         -- complete this proof\n  end\n\n\n/-\nPropositions that use \u2203 \n-/\n\nexample : \u2203 n, n = 0 := exists.intro 0 (eq.refl 0)\n\nexample : \u2203 n, n^2 = 25 := exists.intro 5 rfl -- rfl short for eq.refl 25\n\nexample : \u2203 x : nat, \u2203 y: nat, \u2203 z : \u2115, x^2 +y^2 = z^2 := \nexists.intro 3 \n  (exists.intro 4 \n    (exists.intro 5 (rfl)))\n\n/-\nPropositions that use both \u2203 and \u2200  \n-/\n\n\n\n/- Still to do:\n\ndef iff_intro := (P >> Q) >> (Q >> P) >> (P \u2194 Q)\ndef iff_intro' := (P >> Q) \u2227 (Q >> P) >> (P \u2194 Q)\ndef iff_elim_left := (P \u2194 Q) >> (P >> Q)\ndef iff_elim_right := (P \u2194 Q) >> (Q >> P)\ndef syllogism := (P >> Q) >> (Q >> R) >> (P >> R)\ndef modus_tollens := (P >> Q) >> (\u00ac Q >> \u00ac P)\ndef neg_elim := (\u00ac \u00ac P) >> P         -- not a constructive rule\ndef excluded_middle := P \u2228 (\u00ac P)     -- not a constructive rule\ndef neg_intro := (P >> pFalse) >> (\u00ac P)\ndef true_intro : pExp := pTrue\ndef false_elim := pFalse >> P\n-/\n\n\nend hidden", "meta": {"author": "jngo13", "repo": "Discrete-Mathematics", "sha": "bf674a866e61f60e6e6d128df85fa73819091787", "save_path": "github-repos/lean/jngo13-Discrete-Mathematics", "path": "github-repos/lean/jngo13-Discrete-Mathematics/Discrete-Mathematics-bf674a866e61f60e6e6d128df85fa73819091787/exam_2/predicate_logic/proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7395541474613895}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n\n! This file was ported from Lean 3 source module data.real.cardinality\n! leanprover-community/mathlib commit 7e7aaccf9b0182576cabdde36cf1b5ad3585b70d\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.SpecificLimits.Basic\nimport Mathbin.Data.Rat.Denumerable\nimport Mathbin.Data.Set.Pointwise.Interval\nimport Mathbin.SetTheory.Cardinal.Continuum\n\n/-!\n# The cardinality of the reals\n\nThis file shows that the real numbers have cardinality continuum, i.e. `#\u211d = \ud835\udd20`.\n\nWe show that `#\u211d \u2264 \ud835\udd20` by noting that every real number is determined by a Cauchy-sequence of the\nform `\u2115 \u2192 \u211a`, which has cardinality `\ud835\udd20`. To show that `#\u211d \u2265 \ud835\udd20` we define an injection from\n`{0, 1} ^ \u2115` to `\u211d` with `f \u21a6 \u03a3 n, f n * (1 / 3) ^ n`.\n\nWe conclude that all intervals with distinct endpoints have cardinality continuum.\n\n## Main definitions\n\n* `cardinal.cantor_function` is the function that sends `f` in `{0, 1} ^ \u2115` to `\u211d` by\n  `f \u21a6 \u03a3' n, f n * (1 / 3) ^ n`\n\n## Main statements\n\n* `cardinal.mk_real : #\u211d = \ud835\udd20`: the reals have cardinality continuum.\n* `cardinal.not_countable_real`: the universal set of real numbers is not countable.\n  We can use this same proof to show that all the other sets in this file are not countable.\n* 8 lemmas of the form `mk_Ixy_real` for `x,y \u2208 {i,o,c}` state that intervals on the reals\n  have cardinality continuum.\n\n## Notation\n\n* `\ud835\udd20` : notation for `cardinal.continuum` in locale `cardinal`, defined in `set_theory.continuum`.\n\n## Tags\ncontinuum, cardinality, reals, cardinality of the reals\n-/\n\n\nopen Nat Set\n\nopen Cardinal\n\nnoncomputable section\n\nnamespace Cardinal\n\nvariable {c : \u211d} {f g : \u2115 \u2192 Bool} {n : \u2115}\n\n/-- The body of the sum in `cantor_function`.\n`cantor_function_aux c f n = c ^ n` if `f n = tt`;\n`cantor_function_aux c f n = 0` if `f n = ff`. -/\ndef cantorFunctionAux (c : \u211d) (f : \u2115 \u2192 Bool) (n : \u2115) : \u211d :=\n  cond (f n) (c ^ n) 0\n#align cardinal.cantor_function_aux Cardinal.cantorFunctionAux\n\n@[simp]\ntheorem cantorFunctionAux_true (h : f n = true) : cantorFunctionAux c f n = c ^ n := by\n  simp [cantor_function_aux, h]\n#align cardinal.cantor_function_aux_tt Cardinal.cantorFunctionAux_true\n\n@[simp]\ntheorem cantorFunctionAux_false (h : f n = false) : cantorFunctionAux c f n = 0 := by\n  simp [cantor_function_aux, h]\n#align cardinal.cantor_function_aux_ff Cardinal.cantorFunctionAux_false\n\ntheorem cantorFunctionAux_nonneg (h : 0 \u2264 c) : 0 \u2264 cantorFunctionAux c f n :=\n  by\n  cases h' : f n <;> simp [h']\n  apply pow_nonneg h\n#align cardinal.cantor_function_aux_nonneg Cardinal.cantorFunctionAux_nonneg\n\ntheorem cantorFunctionAux_eq (h : f n = g n) : cantorFunctionAux c f n = cantorFunctionAux c g n :=\n  by simp [cantor_function_aux, h]\n#align cardinal.cantor_function_aux_eq Cardinal.cantorFunctionAux_eq\n\ntheorem cantorFunctionAux_zero (f : \u2115 \u2192 Bool) : cantorFunctionAux c f 0 = cond (f 0) 1 0 := by\n  cases h : f 0 <;> simp [h]\n#align cardinal.cantor_function_aux_zero Cardinal.cantorFunctionAux_zero\n\ntheorem cantorFunctionAux_succ (f : \u2115 \u2192 Bool) :\n    (fun n => cantorFunctionAux c f (n + 1)) = fun n =>\n      c * cantorFunctionAux c (fun n => f (n + 1)) n :=\n  by\n  ext n\n  cases h : f (n + 1) <;> simp [h, pow_succ]\n#align cardinal.cantor_function_aux_succ Cardinal.cantorFunctionAux_succ\n\ntheorem summable_cantor_function (f : \u2115 \u2192 Bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n    Summable (cantorFunctionAux c f) :=\n  by\n  apply (summable_geometric_of_lt_1 h1 h2).summable_of_eq_zero_or_self\n  intro n; cases h : f n <;> simp [h]\n#align cardinal.summable_cantor_function Cardinal.summable_cantor_function\n\n/-- `cantor_function c (f : \u2115 \u2192 bool)` is `\u03a3 n, f n * c ^ n`, where `tt` is interpreted as `1` and\n`ff` is interpreted as `0`. It is implemented using `cantor_function_aux`. -/\ndef cantorFunction (c : \u211d) (f : \u2115 \u2192 Bool) : \u211d :=\n  \u2211' n, cantorFunctionAux c f n\n#align cardinal.cantor_function Cardinal.cantorFunction\n\ntheorem cantorFunction_le (h1 : 0 \u2264 c) (h2 : c < 1) (h3 : \u2200 n, f n \u2192 g n) :\n    cantorFunction c f \u2264 cantorFunction c g :=\n  by\n  apply tsum_le_tsum _ (summable_cantor_function f h1 h2) (summable_cantor_function g h1 h2)\n  intro n; cases h : f n; simp [h, cantor_function_aux_nonneg h1]\n  replace h3 : g n = tt := h3 n h; simp [h, h3]\n#align cardinal.cantor_function_le Cardinal.cantorFunction_le\n\ntheorem cantorFunction_succ (f : \u2115 \u2192 Bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n    cantorFunction c f = cond (f 0) 1 0 + c * cantorFunction c fun n => f (n + 1) :=\n  by\n  rw [cantor_function, tsum_eq_zero_add (summable_cantor_function f h1 h2)]\n  rw [cantor_function_aux_succ, tsum_mul_left, cantor_function_aux, pow_zero]\n  rfl\n#align cardinal.cantor_function_succ Cardinal.cantorFunction_succ\n\n/-- `cantor_function c` is strictly increasing with if `0 < c < 1/2`, if we endow `\u2115 \u2192 bool` with a\nlexicographic order. The lexicographic order doesn't exist for these infinitary products, so we\nexplicitly write out what it means. -/\ntheorem increasing_cantorFunction (h1 : 0 < c) (h2 : c < 1 / 2) {n : \u2115} {f g : \u2115 \u2192 Bool}\n    (hn : \u2200 k < n, f k = g k) (fn : f n = false) (gn : g n = true) :\n    cantorFunction c f < cantorFunction c g :=\n  by\n  have h3 : c < 1 := by\n    apply h2.trans\n    norm_num\n  induction' n with n ih generalizing f g\n  \u00b7 let f_max : \u2115 \u2192 Bool := fun n => Nat.rec ff (fun _ _ => tt) n\n    have hf_max : \u2200 n, f n \u2192 f_max n := by\n      intro n hn\n      cases n\n      rw [fn] at hn\n      contradiction\n      apply rfl\n    let g_min : \u2115 \u2192 Bool := fun n => Nat.rec tt (fun _ _ => ff) n\n    have hg_min : \u2200 n, g_min n \u2192 g n := by\n      intro n hn\n      cases n\n      rw [gn]\n      apply rfl\n      contradiction\n    apply (cantor_function_le (le_of_lt h1) h3 hf_max).trans_lt\n    refine' lt_of_lt_of_le _ (cantor_function_le (le_of_lt h1) h3 hg_min)\n    have : c / (1 - c) < 1 := by\n      rw [div_lt_one, lt_sub_iff_add_lt]\n      \u00b7 convert add_lt_add h2 h2\n        norm_num\n      rwa [sub_pos]\n    convert this\n    \u00b7 rw [cantor_function_succ _ (le_of_lt h1) h3, div_eq_mul_inv, \u2190\n        tsum_geometric_of_lt_1 (le_of_lt h1) h3]\n      apply zero_add\n    \u00b7 refine' (tsum_eq_single 0 _).trans _\n      \u00b7 intro n hn\n        cases n\n        contradiction\n        rfl\n      \u00b7 exact cantor_function_aux_zero _\n  rw [cantor_function_succ f (le_of_lt h1) h3, cantor_function_succ g (le_of_lt h1) h3]\n  rw [hn 0 <| zero_lt_succ n]\n  apply add_lt_add_left\n  rw [mul_lt_mul_left h1]\n  exact ih (fun k hk => hn _ <| Nat.succ_lt_succ hk) fn gn\n#align cardinal.increasing_cantor_function Cardinal.increasing_cantorFunction\n\n/-- `cantor_function c` is injective if `0 < c < 1/2`. -/\ntheorem cantorFunction_injective (h1 : 0 < c) (h2 : c < 1 / 2) :\n    Function.Injective (cantorFunction c) :=\n  by\n  intro f g hfg\n  classical\n    by_contra h\n    revert hfg\n    have : \u2203 n, f n \u2260 g n := by\n      rw [\u2190 not_forall]\n      intro h'\n      apply h\n      ext\n      apply h'\n    let n := Nat.find this\n    have hn : \u2200 k : \u2115, k < n \u2192 f k = g k := by\n      intro k hk\n      apply of_not_not\n      exact Nat.find_min this hk\n    cases fn : f n\n    \u00b7 apply ne_of_lt\n      refine' increasing_cantor_function h1 h2 hn fn _\n      apply Bool.eq_true_of_not_eq_false\n      rw [\u2190 fn]\n      apply Ne.symm\n      exact Nat.find_spec this\n    \u00b7 apply ne_of_gt\n      refine' increasing_cantor_function h1 h2 (fun k hk => (hn k hk).symm) _ fn\n      apply Bool.eq_false_of_not_eq_true\n      rw [\u2190 fn]\n      apply Ne.symm\n      exact Nat.find_spec this\n#align cardinal.cantor_function_injective Cardinal.cantorFunction_injective\n\n/-- The cardinality of the reals, as a type. -/\ntheorem mk_real : (#\u211d) = \ud835\udd20 := by\n  apply le_antisymm\n  \u00b7 rw [real.equiv_Cauchy.cardinal_eq]\n    apply mk_quotient_le.trans\n    apply (mk_subtype_le _).trans_eq\n    rw [\u2190 power_def, mk_nat, mk_rat, aleph_0_power_aleph_0]\n  \u00b7 convert mk_le_of_injective (cantor_function_injective _ _)\n    rw [\u2190 power_def, mk_bool, mk_nat, two_power_aleph_0]\n    exact 1 / 3\n    norm_num\n    norm_num\n#align cardinal.mk_real Cardinal.mk_real\n\n/-- The cardinality of the reals, as a set. -/\ntheorem mk_univ_real : (#(Set.univ : Set \u211d)) = \ud835\udd20 := by rw [mk_univ, mk_real]\n#align cardinal.mk_univ_real Cardinal.mk_univ_real\n\n/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/\ntheorem not_countable_real : \u00ac(Set.univ : Set \u211d).Countable :=\n  by\n  rw [\u2190 le_aleph_0_iff_set_countable, not_le, mk_univ_real]\n  apply cantor\n#align cardinal.not_countable_real Cardinal.not_countable_real\n\n/-- The cardinality of the interval (a, \u221e). -/\ntheorem mk_Ioi_real (a : \u211d) : (#Ioi a) = \ud835\udd20 :=\n  by\n  refine' le_antisymm (mk_real \u25b8 mk_set_le _) _\n  rw [\u2190 not_lt]\n  intro h\n  refine' ne_of_lt _ mk_univ_real\n  have hu : Iio a \u222a {a} \u222a Ioi a = Set.univ :=\n    by\n    convert Iic_union_Ioi\n    exact Iio_union_right\n  rw [\u2190 hu]\n  refine' lt_of_le_of_lt (mk_union_le _ _) _\n  refine' lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) _\n  have h2 : (fun x => a + a - x) '' Ioi a = Iio a :=\n    by\n    convert image_const_sub_Ioi _ _\n    simp\n  rw [\u2190 h2]\n  refine' add_lt_of_lt (cantor _).le _ h\n  refine' add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) _\n  rw [mk_singleton]\n  exact one_lt_aleph_0.trans (cantor _)\n#align cardinal.mk_Ioi_real Cardinal.mk_Ioi_real\n\n/-- The cardinality of the interval [a, \u221e). -/\ntheorem mk_Ici_real (a : \u211d) : (#Ici a) = \ud835\udd20 :=\n  le_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioi_real a \u25b8 mk_le_mk_of_subset Ioi_subset_Ici_self)\n#align cardinal.mk_Ici_real Cardinal.mk_Ici_real\n\n/-- The cardinality of the interval (-\u221e, a). -/\ntheorem mk_Iio_real (a : \u211d) : (#Iio a) = \ud835\udd20 :=\n  by\n  refine' le_antisymm (mk_real \u25b8 mk_set_le _) _\n  have h2 : (fun x => a + a - x) '' Iio a = Ioi a :=\n    by\n    convert image_const_sub_Iio _ _\n    simp\n  exact mk_Ioi_real a \u25b8 h2 \u25b8 mk_image_le\n#align cardinal.mk_Iio_real Cardinal.mk_Iio_real\n\n/-- The cardinality of the interval (-\u221e, a]. -/\ntheorem mk_Iic_real (a : \u211d) : (#Iic a) = \ud835\udd20 :=\n  le_antisymm (mk_real \u25b8 mk_set_le _) (mk_Iio_real a \u25b8 mk_le_mk_of_subset Iio_subset_Iic_self)\n#align cardinal.mk_Iic_real Cardinal.mk_Iic_real\n\n/-- The cardinality of the interval (a, b). -/\ntheorem mk_Ioo_real {a b : \u211d} (h : a < b) : (#Ioo a b) = \ud835\udd20 :=\n  by\n  refine' le_antisymm (mk_real \u25b8 mk_set_le _) _\n  have h1 : (#(fun x => x - a) '' Ioo a b) \u2264 (#Ioo a b) := mk_image_le\n  refine' le_trans _ h1\n  rw [image_sub_const_Ioo, sub_self]\n  replace h := sub_pos_of_lt h\n  have h2 : (#Inv.inv '' Ioo 0 (b - a)) \u2264 (#Ioo 0 (b - a)) := mk_image_le\n  refine' le_trans _ h2\n  rw [image_inv, inv_Ioo_0_left h, mk_Ioi_real]\n#align cardinal.mk_Ioo_real Cardinal.mk_Ioo_real\n\n/-- The cardinality of the interval [a, b). -/\ntheorem mk_Ico_real {a b : \u211d} (h : a < b) : (#Ico a b) = \ud835\udd20 :=\n  le_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Ico_self)\n#align cardinal.mk_Ico_real Cardinal.mk_Ico_real\n\n/-- The cardinality of the interval [a, b]. -/\ntheorem mk_Icc_real {a b : \u211d} (h : a < b) : (#Icc a b) = \ud835\udd20 :=\n  le_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Icc_self)\n#align cardinal.mk_Icc_real Cardinal.mk_Icc_real\n\n/-- The cardinality of the interval (a, b]. -/\ntheorem mk_Ioc_real {a b : \u211d} (h : a < b) : (#Ioc a b) = \ud835\udd20 :=\n  le_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Ioc_self)\n#align cardinal.mk_Ioc_real Cardinal.mk_Ioc_real\n\nend Cardinal\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Real/Cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.7395541405309501}}
{"text": "import tactic                 \nimport data.set.basic  \nimport data.real.basic\nimport algebra.order.floor\nimport algebra.order.ring\nimport algebra.order.field.basic\n\n-- floor function lemmas (Joe Roberts Number Theory)\n\nlemma floor_lemma1 {\u03b1 : \u211d} : (\u03b1 - 1 < (\u230a\u03b1\u230b : \u211d)) \u2227 ((\u230a\u03b1\u230b : \u211d)  \u2264 \u03b1) :=\nbegin\n  split, {\n    exact int.sub_one_lt_floor \u03b1,\n  }, {\n    exact int.floor_le \u03b1, \n  }\nend\n\n\nlemma floor_lemma2 {\u03b1 : \u211d} {n : \u2124} : \u230a\u03b1 + (n : \u211d)\u230b = \u230a\u03b1\u230b + n  :=\nbegin\n  exact int.floor_add_int \u03b1 n,\nend\n\nlemma floor_lemma3 (m n : \u2124) (h_npos : 0 < n): (\u2203 r : \u211d, ((m : \u211d)  = ((\u230a(m : \u211d) / (n : \u211d)\u230b * n) : \u211d)  + r ) \u2227 (0 \u2264 r ) \u2227 (r < n)) :=\nbegin\n have h0 := int.floor_add_fract ((( m : \u211d)) / (n : \u211d )),\n have hfrac := int.fract_lt_one ((m : \u211d)/ (n : \u211d) ),\n have hpos := int.fract_nonneg ((m : \u211d)/ (n : \u211d) ),\n use int.fract ((( m : \u211d)) / (n : \u211d )) * (n : \u211d),\n split, {\n  have h1 : ((\u230a(m : \u211d)  / (n : \u211d)\u230b : \u211d)  + int.fract ((m : \u211d)  / (n : \u211d) )) * (n : \u211d) = ((m : \u211d)  / (n : \u211d)) * (n : \u211d) := congr_fun (congr_arg has_mul.mul h0) \u2191n,\n  rw [add_mul] at h1,\n  rw div_mul at h1,\n  have h_n_neq_zero : n \u2260 0 := ne_of_gt h_npos,\n  have h_n_neq_zero_in_R : (n : \u211d)  \u2260 0 := int.cast_ne_zero.mpr h_n_neq_zero,\n  have h2 : (n : \u211d)  / (n : \u211d)  = 1 := div_self h_n_neq_zero_in_R,\n  rw h2 at h1,\n  rw div_one at h1,\n  linarith,\n }, {\n  have h3 : (n : \u211d) > 0 := int.cast_pos.mpr h_npos,\n  split, {\n    exact (zero_le_mul_right h3).mpr hpos,\n  }, {\n    exact mul_lt_of_lt_one_left h3 hfrac,\n  }\n }\nend\n\n-- lemma floor_lemma3_1 (m n : \u2124) (h_npos : 0 < n): (\u2203 r : \u2124, (m   = (\u230a\u2191m   / (n : \u211a)\u230b * n)   + r ) \u2227 (0 \u2264 r ) \u2227 (\u2191r  < n)) :=\n-- begin\n--   use (m % n) ,\n--   split, {\n--     have hr := nat.floor_div_eq_div\n--   }, {\n\n--   }\n--   have h_n_neq_zero : n \u2260 0 := ne_of_gt h_npos,\n--   have h_n_neq_zero_in_R : (n : \u211d)  \u2260 0 := int.cast_ne_zero.mpr h_n_neq_zero,\n--   have h0 := int.fract_div_mul_self_add_zsmul_eq (n : \u211d) (m : \u211d)  h_n_neq_zero_in_R,\n--   have hmn : \u2191m / (n : \u211d)  = 1 + ((m - n) : \u211d) /(n : \u211d) := by sorry,\n--   have h_int : int.fract (\u2191m / \u2191n) * \u2191n \u2208 \u2124\n--   sorry,\n-- end\n\n-- lemma floor_lemma4 (m n : \u2124) (h_npos : 0 < n): ((m : \u211d )  + 1)/(n : \u211d )  \u2264 \u230a(m : \u211d ) /(n : \u211d )\u230b + 1 :=\n-- begin\n\n--   -- SKETCH\n\n--   -- m/n = (k n + a) / n = k + a/n\n\n--   -- m = \u230am/n\u230b * n + r, 0 \u2264 r < n\n--   -- m/n = \u230am/n\u230b + r/n\n--   -- (m+1)/n = \u230am/n\u230b + (r+1)/n\n--   -- use that (r + 1)/n  \u2264  1 \n--   -- \u2234 (m+1)/n \u2264 \u230am/n\u230b + 1 \u220e\n\n\n--   have h_n_neq_zero : n \u2260 0 := ne_of_gt h_npos,\n--   have h_n_neq_zero_in_R : (n : \u211d)  \u2260 0 := int.cast_ne_zero.mpr h_n_neq_zero,\n\n--   have h0 := floor_lemma3 m n h_npos,\n--   cases h0 with r h0,\n--   have h1 := (div_left_inj' h_n_neq_zero_in_R).mpr h0.1,\n--   rw [add_div, mul_div_assoc] at h1,\n--   rw [(div_self h_n_neq_zero_in_R), mul_one] at h1,\n--   have h2 : \u2191m / \u2191n + 1/ (n : \u211d) = \u2191\u230a\u2191m / \u2191n\u230b + r / \u2191n + 1/(n : \u211d) := congr_fun (congr_arg has_add.add h1) (1 / \u2191n),\n--   rw \u2190 add_div at h2, \n--   rw add_assoc at h2, \n--   rw \u2190 add_div at h2,\n--   have h3 : (r+1)/n \u2264 1, -- true since r \u2208 \u2124 \n--   {\n--     sorry,\n--   },\n--   linarith,\n  \n-- end\n\n-- lemma floor_lemma4_1 (m n : \u2124) (h_npos : 0 < n): ((m : \u211d )  + 1)/(n : \u211d )  \u2264 \u230a(m : \u211d ) /(n : \u211d )\u230b + 1 :=\n-- begin\n\n--   -- SKETCH\n--   -- m = \u230am/n\u230b * n + r, 0 \u2264 r < n\n--   -- m/n = \u230am/n\u230b + r/n\n--   -- (m+1)/n = \u230am/n\u230b + (r+1)/n\n--   -- use that (r + 1)/n  \u2264  1 \n--   -- \u2234 (m+1)/n \u2264 \u230am/n\u230b + 1 \u220e\n  \n  \n  \n-- end\n\n\n-- lemma floor_lemma5 {n : \u2124} (h_npos : 0 < n) (\u03b1 : \u211d) : \u230a(\u230a\u03b1\u230b : \u211d) /(n : \u211d)\u230b  = \u230a\u03b1/(n : \u211d )\u230b :=\n-- begin\n--   have h_npos2 : 0 < (n : \u211d) := int.cast_pos.mpr h_npos,\n\n--   have h0 : (\u230a(\u230a\u03b1\u230b : \u211d) /(n : \u211d)\u230b : \u211d)  \u2264  (\u230a\u03b1\u230b : \u211d) /(n : \u211d ) := int.floor_le (\u2191\u230a\u03b1\u230b / \u2191n),\n\n--   have h1 : (\u230a\u03b1\u230b : \u211d)  / (n : \u211d) \u2264 \u03b1 / (n : \u211d) := (div_le_div_right h_npos2).mpr (int.floor_le \u03b1),\n\n--   have h2k0 :  \u03b1 - 1 < (\u230a\u03b1\u230b : \u211d)  := int.sub_one_lt_floor \u03b1,\n--   have h2k1 : \u03b1 <  (\u230a\u03b1\u230b : \u211d) + 1 := by linarith, \n--   have h2 : \u03b1 / (n : \u211d) <  (\u230a\u03b1\u230b + 1) / (n : \u211d) := (div_lt_div_right h_npos2).mpr h2k1,\n--   clear h2k0 h2k1,\n\n--   have h3 := floor_lemma3 \u230a\u03b1\u230b n h_npos,\n\n--   -- inequality shows floor \n--   have  h4 : (\u230a(\u230a\u03b1\u230b : \u211d) / (n : \u211d)\u230b : \u211d ) \u2264 \u03b1 / (n : \u211d)  := by linarith,\n--   have  h5 :  \u03b1 / (n : \u211d) < (\u230a(\u230a\u03b1\u230b : \u211d) / (n : \u211d)\u230b : \u211d ) + 1 := by linarith,\n--   exact (int.floor_eq_iff.mpr \u27e8h4, h5\u27e9).symm,\n\n-- end\n\nlemma nested_ceil (m n : \u2124 ) (hmpos : m > 0) (hnpos : n > 0) (x : \u211d) : \u2308x / (m * n)\u2309 = \u2308(\u2308x/m\u2309 : \u211d) /(n : \u211d)\u2309 :=\nbegin\n  set k := \u2308x/\u2191m\u2309,\n  have h_le : \u2308x / ((m : \u211d)  * (n : \u211d)\u2309  \u2264 \u2308(k : \u211d) / (n : \u211d)\u2309,\n  {\n    suffices h0 : x/(\u2191m * \u2191n) \u2264 k/\u2191n,\n    {\n      exact int.ceil_mono h0,\n    },\n    suffices h1 : x / \u2191m \u2264 \u2191k,\n    {\n      rw \u2190 div_div,\n      have hnpos' : 0 < (n : \u211d ) := int.cast_pos.mpr hnpos,\n      rwa div_le_div_right hnpos',\n    },\n    exact int.le_ceil (x / \u2191m),\n\n  },\n\n  have h_ge : \u2308x / ((m : \u211d)  * (n : \u211d))\u2309  \u2265 \u2308(k : \u211d) / (n : \u211d)\u2309,\n  {\n    by_contra hc, push_neg at hc,\n    have h1 := int.lt.dest hc,\n    cases h1 with l hl,\n    rw nat.succ_eq_add_one at hl, push_cast at hl,\n    \n    have hl2 : \u2191l \u2265 0 := zero_le \u2191l,\n    have hq1 :  \u2308x / (\u2191m * \u2191n)\u2309 \u2264 \u2308x / (\u2191m * \u2191n)\u2309 + \u2191l  := by linarith, \n    have hq2 :  \u2308x / (\u2191m * \u2191n)\u2309 + \u2191l <  \u2308(k : \u211d)  / (n : \u211d)  \u2309 := by linarith,\n    set q := \u2308x / (\u2191m * \u2191n)\u2309 + \u2191l,\n    have hq1' : x / (\u2191m * \u2191n) \u2264 q := int.ceil_le.mp hq1,\n    have hq2' : (q : \u211d)  < (k : \u211d)  / (n : \u211d)  := int.lt_ceil.mp hq2,\n    have hnpos' : 0 \u2264 n := le_of_lt hnpos,\n    have hnpos'' : 0 \u2264 (n : \u211d)  := int.cast_nonneg.mpr hnpos',\n    have hq'' : (x / (\u2191m * \u2191n)) * \u2191n  \u2264 q * \u2191n  := mul_le_mul_of_nonneg_right hq1' hnpos'',\n    rw div_mul at hq'',\n    have h_n_neq_zero : n  \u2260 0 := ne_of_gt hnpos,   \n    have h_n_neq_zero' : ( n : \u211d )  \u2260 0 := int.cast_ne_zero.mpr h_n_neq_zero, \n    rw \u2190 mul_div at hq'',  \n    rw div_self h_n_neq_zero' at hq'',\n    rw mul_one at hq'',\n    have hqn : (q : \u211d) * (n : \u211d) = \u2191(q * n) := (int.cast_mul q n).symm,\n    have hk : \u2308(x / \u2191m)\u2309 \u2264 (q * n),\n    {\n      refine int.ceil_le.mpr _,\n      rw hqn at hq'',\n      exact hq'',\n    },\n\n    have hq2'' := mul_lt_mul_of_pos_right hq2' (int.cast_pos.mpr hnpos),\n    rw div_mul at hq2'',\n    rw div_self h_n_neq_zero' at hq2'',\n    rw div_one at hq2'',\n    rw hqn at hq2'',\n    have hk' : (\u2308x / \u2191m\u2309 : \u211d)  \u2264 \u2191(q * n) := int.cast_le.mpr hk,\n    linarith,\n  },\n  exact le_antisymm h_le h_ge,\n\nend\n\n\n-- define beatty sequence\n\n\ndef B : \u211d \u2192 set \u2115 := \u03bb r, { n | \u2203 m : \u2115 , ((n : \u2115) = nat.floor ((m : \u211d)  * r) ) }\n\n\n\nlemma mem_b_iff {q : \u211d} {k : \u2115}  : (k \u2208 (B q)) \u2194 \u2203 m : \u2115, (k : \u2115)  = nat.floor ((m : \u211d) * q ) :=\nbegin\n  split, \n  intro hk,\n  rw set.mem_def at hk,\n  assumption,\n  intro h,\n  rw set.mem_def,\n  assumption,\nend\n\nlemma floor_lemma {q : \u211d} {j n : \u2115} (hq : 1 < q ) (hj : j = nat.floor (\u2191n * q)) : ((j : \u211d) \u2264 \u2191n * q)  \u2227 \u2191n * q < (j : \u211d) + 1 :=\nbegin\n  have hn : 0 \u2264 n  := zero_le n, \n  have hn2 : 0 \u2264 (n : \u211d) := nat.cast_nonneg n,\n  have hq2 : 0 \u2264 q := by linarith, \n  have hnq : 0 \u2264 \u2191n * q := mul_nonneg hn2 hq2, \n  exact (nat.floor_eq_iff hnq).mp (eq.symm hj),\nend\n\n-- Forward direction:\n-- complementary beatty sequences partition \u2115 \n\ntheorem beatty_theorem_forward ( q : \u211d ) (hq : irrational q) (h_q_gt_one : q > 1) : \u2200 n : \u2115,  (((n \u2208 (B q)) \u2228 (n \u2208 B ( q/(q-1))))) \u2227 (((B q) \u2229 (B (q/(q-1)))) = \u2205)\n:= \nbegin\n  set p := (q/(q-1)),\n  intro n,\n  split, {\n  -- by contradiction, \n  --by_contra h, push_neg at h, rw mem_b_iff at *, push_neg at h,\n  sorry,\n\n\n  }, {\n  -- by contradiction, \"collision\"\n  by_contra h, change B q \u2229 B p \u2260 \u2205 at h,\n  have hs : set.nonempty (B q \u2229 B p) := set.ne_empty_iff_nonempty.mp h,\n  rw set.nonempty_def at hs,\n  rcases hs with \u27e8x, hxq, hxp\u27e9,\n  rw mem_b_iff at *,\n  cases hxq with m hm,\n  cases hxp with l hl,\n\n  have h_p_gt_one : p > 1 := by sorry,\n\n  have hpq : p + q = 1 := by sorry,\n\n  have hm2 := floor_lemma h_q_gt_one hm,\n  have hl2 := floor_lemma h_p_gt_one hl,\n  sorry,\n  -- have h0: \u2191x / p \u2264 m := by library_search,\n\n  }\nend\n\n\n-- Converse direction\n-- if two beatty sequence B p, B q partition \u2115, then 1/p + 1/ q = 1\n\n\n", "meta": {"author": "Vilin97", "repo": "LLL", "sha": "ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9", "save_path": "github-repos/lean/Vilin97-LLL", "path": "github-repos/lean/Vilin97-LLL/LLL-ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9/Zachary/scratch1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.739534260921129}}
{"text": "/-\nCopyright (c) 2018 Guy Leroy. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport data.nat.prime\nimport data.int.order\n\n/-!\n# Extended GCD and divisibility over \u2124\n\n## Main definitions\n\n* Given `x y : \u2115`, `xgcd x y` computes the pair of integers `(a, b)` such that\n  `gcd x y = x * a + y * b`. `gcd_a x y` and `gcd_b x y` are defined to be `a` and `b`,\n  respectively.\n\n## Main statements\n\n* `gcd_eq_gcd_ab`: B\u00e9zout's lemma, given `x y : \u2115`, `gcd x y = x * gcd_a x y + y * gcd_b x y`.\n\n## Tags\n\nB\u00e9zout's lemma, Bezout's lemma\n-/\n\n/-! ### Extended Euclidean algorithm -/\nnamespace nat\n\n/-- Helper function for the extended GCD algorithm (`nat.xgcd`). -/\ndef xgcd_aux : \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u00d7 \u2124 \u00d7 \u2124\n| 0          s t r' s' t' := (r', s', t')\n| r@(succ _) s t r' s' t' :=\n  have r' % r < r, from mod_lt _ $ succ_pos _,\n  let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t\n\n@[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=\nby simp [xgcd_aux]\n\ntheorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) :\n  xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=\nby cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}]\n\n/-- Use the extended GCD algorithm to generate the `a` and `b` values\n  satisfying `gcd x y = x * a + y * b`. -/\ndef xgcd (x y : \u2115) : \u2124 \u00d7 \u2124 := (xgcd_aux x 1 0 y 0 1).2\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a (x y : \u2115) : \u2124 := (xgcd x y).1\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b (x y : \u2115) : \u2124 := (xgcd x y).2\n\n@[simp] theorem gcd_a_zero_left {s : \u2115} : gcd_a 0 s = 0 :=\nby { unfold gcd_a, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_b_zero_left {s : \u2115} : gcd_b 0 s = 1 :=\nby { unfold gcd_b, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_a_zero_right {s : \u2115} (h : s \u2260 0) : gcd_a s 0 = 1 :=\nbegin\n  unfold gcd_a xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem gcd_b_zero_right {s : \u2115} (h : s \u2260 0) : gcd_b s 0 = 0 :=\nbegin\n  unfold gcd_b xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem xgcd_aux_fst (x y) : \u2200 s t s' t',\n  (xgcd_aux x s t y s' t').1 = gcd x y :=\ngcd.induction x y (by simp) (\u03bb x y h IH s t s' t', by simp [xgcd_aux_rec, h, IH]; rw \u2190 gcd_rec)\n\ntheorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=\nby rw [xgcd, \u2190 xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl\n\ntheorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nby unfold gcd_a gcd_b; cases xgcd x y; refl\n\nsection\nparameters (x y : \u2115)\n\nprivate def P : \u2115 \u00d7 \u2124 \u00d7 \u2124 \u2192 Prop\n| (r, s, t) := (r : \u2124) = x * s + y * t\n\ntheorem xgcd_aux_P {r r'} : \u2200 {s t s' t'}, P (r, s, t) \u2192 P (r', s', t') \u2192\n  P (xgcd_aux r s t r' s' t') :=\ngcd.induction r r' (by simp) $ \u03bb a b h IH s t s' t' p p', begin\n  rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *,\n  rw [int.mod_def], generalize : (b / a : \u2124) = k,\n  rw [p, p'],\n  simp [mul_add, mul_comm, mul_left_comm, add_comm, add_left_comm, sub_eq_neg_add, mul_assoc]\nend\n\n/-- **B\u00e9zout's lemma**: given `x y : \u2115`, `gcd x y = x * a + y * b`, where `a = gcd_a x y` and\n`b = gcd_b x y` are computed by the extended Euclidean algorithm.\n-/\ntheorem gcd_eq_gcd_ab : (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y :=\nby have := @xgcd_aux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P]);\n   rwa [xgcd_aux_val, xgcd_val] at this\nend\n\nlemma exists_mul_mod_eq_gcd {k n : \u2115} (hk : gcd n k < k) :\n  \u2203 m, n * m % k = gcd n k :=\nbegin\n  have hk' := int.coe_nat_ne_zero.mpr (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk)),\n  have key := congr_arg (\u03bb m, int.nat_mod m k) (gcd_eq_gcd_ab n k),\n  simp_rw int.nat_mod at key,\n  rw [int.add_mul_mod_self_left, \u2190int.coe_nat_mod, int.to_nat_coe_nat, mod_eq_of_lt hk] at key,\n  refine \u27e8(n.gcd_a k % k).to_nat, eq.trans (int.coe_nat_inj _) key.symm\u27e9,\n  rw [int.coe_nat_mod, int.coe_nat_mul, int.to_nat_of_nonneg (int.mod_nonneg _ hk'),\n      int.to_nat_of_nonneg (int.mod_nonneg _ hk'), int.mul_mod, int.mod_mod, \u2190int.mul_mod],\nend\n\nlemma exists_mul_mod_eq_one_of_coprime {k n : \u2115} (hkn : coprime n k) (hk : 1 < k) :\n  \u2203 m, n * m % k = 1 :=\nExists.cases_on (exists_mul_mod_eq_gcd (lt_of_le_of_lt (le_of_eq hkn) hk))\n  (\u03bb m hm, \u27e8m, hm.trans hkn\u27e9)\n\nend nat\n\n/-! ### Divisibility over \u2124 -/\nnamespace int\n\nprotected lemma coe_nat_gcd (m n : \u2115) : int.gcd \u2191m \u2191n = nat.gcd m n := rfl\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a : \u2124 \u2192 \u2124 \u2192 \u2124\n| (of_nat m) n := m.gcd_a n.nat_abs\n| -[1+ m]    n := -m.succ.gcd_a n.nat_abs\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b : \u2124 \u2192 \u2124 \u2192 \u2124\n| m (of_nat n) := m.nat_abs.gcd_b n\n| m -[1+ n]    := -m.nat_abs.gcd_b n.succ\n\n/-- **B\u00e9zout's lemma** -/\ntheorem gcd_eq_gcd_ab : \u2200 x y : \u2124, (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y\n| (m : \u2115) (n : \u2115) := nat.gcd_eq_gcd_ab _ _\n| (m : \u2115) -[1+ n] := show (_ : \u2124) = _ + -(n+1) * -_, by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] (n : \u2115) := show (_ : \u2124) = -(m+1) * -_ + _ , by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] -[1+ n] := show (_ : \u2124) = -(m+1) * -_ + -(n+1) * -_,\n  by { rw [neg_mul_neg, neg_mul_neg], apply nat.gcd_eq_gcd_ab }\n\ntheorem nat_abs_div (a b : \u2124) (H : b \u2223 a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) :=\nbegin\n  cases (nat.eq_zero_or_pos (nat_abs b)),\n  {rw eq_zero_of_nat_abs_eq_zero h, simp [int.div_zero]},\n  calc\n  nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one\n    ... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h\n    ... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ dvd_rfl)\n    ... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b)\n    ... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H,\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : nat.prime p) {m n : \u2124} {k l : \u2115}\n      (hpm : \u2191(p ^ k) \u2223 m)\n      (hpn : \u2191(p ^ l) \u2223 n) (hpmn : \u2191(p ^ (k+l+1)) \u2223 m*n) : \u2191(p ^ (k+1)) \u2223 m \u2228 \u2191(p ^ (l+1)) \u2223 n :=\nhave hpm' : p ^ k \u2223 m.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpm,\nhave hpn' : p ^ l \u2223 n.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpn,\nhave hpmn' : (p ^ (k+l+1)) \u2223 m.nat_abs*n.nat_abs,\n  by rw \u2190int.nat_abs_mul; apply (int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpmn),\nlet hsd := nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn' in\nhsd.elim\n  (\u03bb hsd1, or.inl begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd1 end)\n  (\u03bb hsd2, or.inr begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd2 end)\n\ntheorem dvd_of_mul_dvd_mul_left {i j k : \u2124} (k_non_zero : k \u2260 0) (H : k * i \u2223 k * j) : i \u2223 j :=\ndvd.elim H (\u03bbl H1, by rw mul_assoc at H1; exact \u27e8_, mul_left_cancel\u2080 k_non_zero H1\u27e9)\n\ntheorem dvd_of_mul_dvd_mul_right {i j k : \u2124} (k_non_zero : k \u2260 0) (H : i * k \u2223 j * k) : i \u2223 j :=\nby rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H\n\nlemma prime.dvd_nat_abs_of_coe_dvd_sq {p : \u2115} (hp : p.prime) (k : \u2124) (h : \u2191p \u2223 k ^ 2) :\n  p \u2223 k.nat_abs :=\nbegin\n  apply @nat.prime.dvd_of_dvd_pow _ _ 2 hp,\n  rwa [sq, \u2190 nat_abs_mul, \u2190 coe_nat_dvd_left, \u2190 sq]\nend\n\n/-- \u2124 specific version of least common multiple. -/\ndef lcm (i j : \u2124) : \u2115 := nat.lcm (nat_abs i) (nat_abs j)\n\ntheorem lcm_def (i j : \u2124) : lcm i j = nat.lcm (nat_abs i) (nat_abs j) := rfl\n\nprotected lemma coe_nat_lcm (m n : \u2115) : int.lcm \u2191m \u2191n = nat.lcm m n := rfl\n\ntheorem gcd_dvd_left (i j : \u2124) : (gcd i j : \u2124) \u2223 i :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_left _ _\n\ntheorem gcd_dvd_right (i j : \u2124) : (gcd i j : \u2124) \u2223 j :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_right _ _\n\ntheorem dvd_gcd {i j k : \u2124} (h1 : k \u2223 i) (h2 : k \u2223 j) : k \u2223 gcd i j :=\nnat_abs_dvd.1 $ coe_nat_dvd.2 $ nat.dvd_gcd (nat_abs_dvd_iff_dvd.2 h1) (nat_abs_dvd_iff_dvd.2 h2)\n\ntheorem gcd_mul_lcm (i j : \u2124) : gcd i j * lcm i j = nat_abs (i * j) :=\nby rw [int.gcd, int.lcm, nat.gcd_mul_lcm, nat_abs_mul]\n\ntheorem gcd_comm (i j : \u2124) : gcd i j = gcd j i := nat.gcd_comm _ _\n\ntheorem gcd_assoc (i j k : \u2124) : gcd (gcd i j) k = gcd i (gcd j k) := nat.gcd_assoc _ _ _\n\n@[simp] theorem gcd_self (i : \u2124) : gcd i i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_left (i : \u2124) : gcd 0 i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_right (i : \u2124) : gcd i 0 = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_one_left (i : \u2124) : gcd 1 i = 1 := nat.gcd_one_left _\n\n@[simp] theorem gcd_one_right (i : \u2124) : gcd i 1 = 1 := nat.gcd_one_right _\n\ntheorem gcd_mul_left (i j k : \u2124) : gcd (i * j) (i * k) = nat_abs i * gcd j k :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_left }\n\ntheorem gcd_mul_right (i j k : \u2124) : gcd (i * j) (k * j) = gcd i k * nat_abs j :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_right }\n\ntheorem gcd_pos_of_non_zero_left {i : \u2124} (j : \u2124) (i_non_zero : i \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_left (nat_abs j) (nat_abs_pos_of_ne_zero i_non_zero)\n\ntheorem gcd_pos_of_non_zero_right (i : \u2124) {j : \u2124} (j_non_zero : j \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_right (nat_abs i) (nat_abs_pos_of_ne_zero j_non_zero)\n\ntheorem gcd_eq_zero_iff {i j : \u2124} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 :=\nbegin\n  rw int.gcd,\n  split,\n  { intro h,\n    exact \u27e8nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_left h),\n      nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_right h)\u27e9 },\n  { intro h, rw [nat_abs_eq_zero.mpr h.left, nat_abs_eq_zero.mpr h.right],\n    apply nat.gcd_zero_left }\nend\n\ntheorem gcd_div {i j k : \u2124} (H1 : k \u2223 i) (H2 : k \u2223 j) :\n  gcd (i / k) (j / k) = gcd i j / nat_abs k :=\nby rw [gcd, nat_abs_div i k H1, nat_abs_div j k H2];\nexact nat.gcd_div (nat_abs_dvd_iff_dvd.mpr H1) (nat_abs_dvd_iff_dvd.mpr H2)\n\ntheorem gcd_div_gcd_div_gcd {i j : \u2124} (H : 0 < gcd i j) :\n  gcd (i / gcd i j) (j / gcd i j) = 1 :=\nbegin\n  rw [gcd_div (gcd_dvd_left i j) (gcd_dvd_right i j)],\n  rw [nat_abs_of_nat, nat.div_self H]\nend\n\ntheorem gcd_dvd_gcd_of_dvd_left {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd i j \u2223 gcd k j :=\nint.coe_nat_dvd.1 $ dvd_gcd ((gcd_dvd_left i j).trans H) (gcd_dvd_right i j)\n\ntheorem gcd_dvd_gcd_of_dvd_right {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd j i \u2223 gcd j k :=\nint.coe_nat_dvd.1 $ dvd_gcd (gcd_dvd_left j i) ((gcd_dvd_right j i).trans H)\n\ntheorem gcd_dvd_gcd_mul_left (i j k : \u2124) : gcd i j \u2223 gcd (k * i) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (i j k : \u2124) : gcd i j \u2223 gcd (i * k) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (i j k : \u2124) : gcd i j \u2223 gcd i (k * j) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (i j k : \u2124) : gcd i j \u2223 gcd i (j * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {i j : \u2124} (H : i \u2223 j) : gcd i j = nat_abs i :=\nnat.dvd_antisymm (by unfold gcd; exact nat.gcd_dvd_left _ _)\n                 (by unfold gcd; exact nat.dvd_gcd dvd_rfl (nat_abs_dvd_iff_dvd.mpr H))\n\ntheorem gcd_eq_right {i j : \u2124} (H : j \u2223 i) : gcd i j = nat_abs j :=\nby rw [gcd_comm, gcd_eq_left H]\n\ntheorem ne_zero_of_gcd {x y : \u2124}\n  (hc : gcd x y \u2260 0) : x \u2260 0 \u2228 y \u2260 0 :=\nbegin\n  contrapose! hc,\n  rw [hc.left, hc.right, gcd_zero_right, nat_abs_zero]\nend\n\ntheorem exists_gcd_one {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (m' n' : \u2124), gcd m' n' = 1 \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n\u27e8_, _, gcd_div_gcd_div_gcd H,\n  (int.div_mul_cancel (gcd_dvd_left m n)).symm,\n  (int.div_mul_cancel (gcd_dvd_right m n)).symm\u27e9\n\ntheorem exists_gcd_one' {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (g : \u2115) (m' n' : \u2124), 0 < g \u2227 gcd m' n' = 1 \u2227 m = m' * g \u2227 n = n' * g :=\nlet \u27e8m', n', h\u27e9 := exists_gcd_one H in \u27e8_, m', n', H, h\u27e9\n\ntheorem pow_dvd_pow_iff {m n : \u2124} {k : \u2115} (k0 : 0 < k) : m ^ k \u2223 n ^ k \u2194 m \u2223 n :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, pow_dvd_pow_of_dvd h _\u27e9,\n  apply int.nat_abs_dvd_iff_dvd.mp,\n  apply (nat.pow_dvd_pow_iff k0).mp,\n  rw [\u2190 int.nat_abs_pow, \u2190 int.nat_abs_pow],\n  exact int.nat_abs_dvd_iff_dvd.mpr h\nend\n\nlemma gcd_dvd_iff {a b : \u2124} {n : \u2115} : gcd a b \u2223 n \u2194 \u2203 x y : \u2124, \u2191n = a * x + b * y :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190 nat.mul_div_cancel' h, int.coe_nat_mul, gcd_eq_gcd_ab, add_mul, mul_assoc, mul_assoc],\n    refine \u27e8_, _, rfl\u27e9, },\n  { rintro \u27e8x, y, h\u27e9,\n    rw [\u2190int.coe_nat_dvd, h],\n    exact dvd_add (dvd_mul_of_dvd_left (gcd_dvd_left a b) _)\n      (dvd_mul_of_dvd_left (gcd_dvd_right a b) y) }\nend\n\nlemma gcd_greatest {a b d : \u2124} (hd_pos : 0 \u2264 d) (hda : d \u2223 a) (hdb : d \u2223 b)\n  (hd : \u2200 e : \u2124, e \u2223 a \u2192 e \u2223 b \u2192 e \u2223 d) : d = gcd a b :=\ndvd_antisymm hd_pos\n  (coe_zero_le (gcd a b)) (dvd_gcd hda hdb) (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b))\n\n/-- Euclid's lemma: if `a \u2223 b * c` and `gcd a c = 1` then `a \u2223 b`.\nCompare with `is_coprime.dvd_of_dvd_mul_left` and\n`unique_factorization_monoid.dvd_of_dvd_mul_left_of_no_prime_factors` -/\nlemma dvd_of_dvd_mul_left_of_gcd_one {a b c : \u2124} (habc : a \u2223 b * c) (hab : gcd a c = 1) : a \u2223 b :=\nbegin\n  have := gcd_eq_gcd_ab a c,\n  simp only [hab, int.coe_nat_zero, int.coe_nat_succ, zero_add] at this,\n  have : b * a * gcd_a a c + b * c * gcd_b a c = b, { simp [mul_assoc, \u2190mul_add, \u2190this] },\n  rw \u2190this,\n  exact dvd_add (dvd_mul_of_dvd_left (dvd_mul_left a b) _) (dvd_mul_of_dvd_left habc _),\nend\n\n/-- Euclid's lemma: if `a \u2223 b * c` and `gcd a b = 1` then `a \u2223 c`.\nCompare with `is_coprime.dvd_of_dvd_mul_right` and\n`unique_factorization_monoid.dvd_of_dvd_mul_right_of_no_prime_factors` -/\nlemma dvd_of_dvd_mul_right_of_gcd_one {a b c : \u2124} (habc : a \u2223 b * c) (hab : gcd a b = 1) : a \u2223 c :=\nby { rw mul_comm at habc, exact dvd_of_dvd_mul_left_of_gcd_one habc hab }\n\n/-- For nonzero integers `a` and `b`, `gcd a b` is the smallest positive natural number that can be\nwritten in the form `a * x + b * y` for some pair of integers `x` and `y` -/\ntheorem gcd_least_linear {a b : \u2124} (ha : a \u2260 0) :\n  is_least { n : \u2115 | 0 < n \u2227 \u2203 x y : \u2124, \u2191n = a * x + b * y } (a.gcd b) :=\nbegin\n  simp_rw \u2190gcd_dvd_iff,\n  split,\n  { simpa [and_true, dvd_refl, set.mem_set_of_eq] using gcd_pos_of_non_zero_left b ha },\n  { simp only [lower_bounds, and_imp, set.mem_set_of_eq],\n    exact \u03bb n hn_pos hn, nat.le_of_dvd hn_pos hn },\nend\n\n/-! ### lcm -/\n\ntheorem lcm_comm (i j : \u2124) : lcm i j = lcm j i :=\nby { rw [int.lcm, int.lcm], exact nat.lcm_comm _ _ }\n\ntheorem lcm_assoc (i j k : \u2124) : lcm (lcm i j) k = lcm i (lcm j k) :=\nby { rw [int.lcm, int.lcm, int.lcm, int.lcm, nat_abs_of_nat, nat_abs_of_nat], apply nat.lcm_assoc }\n\n@[simp] theorem lcm_zero_left (i : \u2124) : lcm 0 i = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_left }\n\n@[simp] theorem lcm_zero_right (i : \u2124) : lcm i 0 = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_right }\n\n@[simp] theorem lcm_one_left (i : \u2124) : lcm 1 i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_left }\n\n@[simp] theorem lcm_one_right (i : \u2124) : lcm i 1 = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_right }\n\n@[simp] theorem lcm_self (i : \u2124) : lcm i i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_self }\n\ntheorem dvd_lcm_left (i j : \u2124) : i \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_left }\n\ntheorem dvd_lcm_right (i j : \u2124) : j \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_right }\n\ntheorem lcm_dvd {i j k : \u2124}  : i \u2223 k \u2192 j \u2223 k \u2192 (lcm i j : \u2124) \u2223 k :=\nbegin\n  rw int.lcm,\n  intros hi hj,\n  exact coe_nat_dvd_left.mpr\n    (nat.lcm_dvd (nat_abs_dvd_iff_dvd.mpr hi) (nat_abs_dvd_iff_dvd.mpr hj))\nend\n\nend int\n\nlemma pow_gcd_eq_one {M : Type*} [monoid M] (x : M) {m n : \u2115} (hm : x ^ m = 1) (hn : x ^ n = 1) :\n  x ^ m.gcd n = 1 :=\nbegin\n  cases m, { simp only [hn, nat.gcd_zero_left] },\n  obtain \u27e8x, rfl\u27e9 : is_unit x,\n  { apply is_unit_of_pow_eq_one _ _ hm m.succ_pos },\n  simp only [\u2190 units.coe_pow] at *,\n  rw [\u2190 units.coe_one, \u2190 zpow_coe_nat, \u2190 units.ext_iff] at *,\n  simp only [nat.gcd_eq_gcd_ab, zpow_add, zpow_mul, hm, hn, one_zpow, one_mul]\nend\n\nlemma gcd_nsmul_eq_zero {M : Type*} [add_monoid M] (x : M) {m n : \u2115} (hm : m \u2022 x = 0)\n  (hn : n \u2022 x = 0) : (m.gcd n) \u2022 x = 0 :=\nbegin\n  apply multiplicative.of_add.injective,\n  rw [of_add_nsmul, of_add_zero, pow_gcd_eq_one];\n  rwa [\u2190of_add_nsmul, \u2190of_add_zero, equiv.apply_eq_iff_eq]\nend\n\nattribute [to_additive gcd_nsmul_eq_zero] pow_gcd_eq_one\n\n/-! ### GCD prover -/\nopen norm_num\n\nnamespace tactic\nnamespace norm_num\n\nlemma int_gcd_helper' {d : \u2115} {x y a b : \u2124} (h\u2081 : (d:\u2124) \u2223 x) (h\u2082 : (d:\u2124) \u2223 y)\n  (h\u2083 : x * a + y * b = d) : int.gcd x y = d :=\nbegin\n  refine nat.dvd_antisymm _ (int.coe_nat_dvd.1 (int.dvd_gcd h\u2081 h\u2082)),\n  rw [\u2190 int.coe_nat_dvd, \u2190 h\u2083],\n  apply dvd_add,\n  { exact (int.gcd_dvd_left _ _).mul_right _ },\n  { exact (int.gcd_dvd_right _ _).mul_right _ }\nend\n\nlemma nat_gcd_helper_dvd_left (x y a : \u2115) (h : x * a = y) : nat.gcd x y = x :=\nnat.gcd_eq_left \u27e8a, h.symm\u27e9\n\nlemma nat_gcd_helper_dvd_right (x y a : \u2115) (h : y * a = x) : nat.gcd x y = y :=\nnat.gcd_eq_right \u27e8a, h.symm\u27e9\n\nlemma nat_gcd_helper_2 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (hx : x * a = tx) (hy : y * b = ty) (h : ty + d = tx) : nat.gcd x y = d :=\nbegin\n  rw \u2190 int.coe_nat_gcd, apply @int_gcd_helper' _ _ _ a (-b)\n    (int.coe_nat_dvd.2 \u27e8_, hu.symm\u27e9) (int.coe_nat_dvd.2 \u27e8_, hv.symm\u27e9),\n  rw [mul_neg_eq_neg_mul_symm, \u2190 sub_eq_add_neg, sub_eq_iff_eq_add'],\n  norm_cast, rw [hx, hy, h]\nend\n\nlemma nat_gcd_helper_1 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (hx : x * a = tx) (hy : y * b = ty) (h : tx + d = ty) : nat.gcd x y = d :=\n(nat.gcd_comm _ _).trans $ nat_gcd_helper_2 _ _ _ _ _ _ _ _ _ hv hu hy hx h\n\nlemma nat_lcm_helper (x y d m n : \u2115) (hd : nat.gcd x y = d) (d0 : 0 < d)\n  (xy : x * y = n) (dm : d * m = n) : nat.lcm x y = m :=\n(nat.mul_right_inj d0).1 $ by rw [dm, \u2190 xy, \u2190 hd, nat.gcd_mul_lcm]\n\nlemma nat_coprime_helper_zero_left (x : \u2115) (h : 1 < x) : \u00ac nat.coprime 0 x :=\nmt (nat.coprime_zero_left _).1 $ ne_of_gt h\n\nlemma nat_coprime_helper_zero_right (x : \u2115) (h : 1 < x) : \u00ac nat.coprime x 0 :=\nmt (nat.coprime_zero_right _).1 $ ne_of_gt h\n\n\n\nlemma nat_coprime_helper_2 (x y a b tx ty : \u2115)\n  (hx : x * a = tx) (hy : y * b = ty) (h : ty + 1 = tx) : nat.coprime x y :=\nnat_gcd_helper_2 _ _ _ _ _ _ _ _ _ (one_mul _) (one_mul _) hx hy h\n\nlemma nat_not_coprime_helper (d x y u v : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (h : 1 < d) : \u00ac nat.coprime x y :=\nnat.not_coprime_of_dvd_of_dvd h \u27e8_, hu.symm\u27e9 \u27e8_, hv.symm\u27e9\n\nlemma int_gcd_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx:\u2124) = x) (hy : (ny:\u2124) = y)\n  (h : nat.gcd nx ny = d) : int.gcd x y = d :=\nby rwa [\u2190 hx, \u2190 hy, int.coe_nat_gcd]\n\nlemma int_gcd_helper_neg_left (x y : \u2124) (d : \u2115) (h : int.gcd x y = d) : int.gcd (-x) y = d :=\nby rw int.gcd at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_gcd_helper_neg_right (x y : \u2124) (d : \u2115) (h : int.gcd x y = d) : int.gcd x (-y) = d :=\nby rw int.gcd at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_lcm_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx:\u2124) = x) (hy : (ny:\u2124) = y)\n  (h : nat.lcm nx ny = d) : int.lcm x y = d :=\nby rwa [\u2190 hx, \u2190 hy, int.coe_nat_lcm]\n\nlemma int_lcm_helper_neg_left (x y : \u2124) (d : \u2115) (h : int.lcm x y = d) : int.lcm (-x) y = d :=\nby rw int.lcm at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_lcm_helper_neg_right (x y : \u2124) (d : \u2115) (h : int.lcm x y = d) : int.lcm x (-y) = d :=\nby rw int.lcm at h \u22a2; rwa int.nat_abs_neg\n\n/-- Evaluates the `nat.gcd` function. -/\nmeta def prove_gcd_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 0, _ := pure (c, ey, `(nat.gcd_zero_left).mk_app [ey])\n  | _, 0 := pure (c, ex, `(nat.gcd_zero_right).mk_app [ex])\n  | 1, _ := pure (c, `(1:\u2115), `(nat.gcd_one_left).mk_app [ey])\n  | _, 1 := pure (c, `(1:\u2115), `(nat.gcd_one_right).mk_app [ex])\n  | _, _ := do\n    let (d, a, b) := nat.xgcd_aux x 1 0 y 0 1,\n    if d = x then do\n      (c, ea) \u2190 c.of_nat (y / x),\n      (c, _, p) \u2190 prove_mul_nat c ex ea,\n      pure (c, ex, `(nat_gcd_helper_dvd_left).mk_app [ex, ey, ea, p])\n    else if d = y then do\n      (c, ea) \u2190 c.of_nat (x / y),\n      (c, _, p) \u2190 prove_mul_nat c ey ea,\n      pure (c, ey, `(nat_gcd_helper_dvd_right).mk_app [ex, ey, ea, p])\n    else do\n      (c, ed) \u2190 c.of_nat d,\n      (c, ea) \u2190 c.of_nat a.nat_abs,\n      (c, eb) \u2190 c.of_nat b.nat_abs,\n      (c, eu) \u2190 c.of_nat (x / d),\n      (c, ev) \u2190 c.of_nat (y / d),\n      (c, _, pu) \u2190 prove_mul_nat c ed eu,\n      (c, _, pv) \u2190 prove_mul_nat c ed ev,\n      (c, etx, px) \u2190 prove_mul_nat c ex ea,\n      (c, ety, py) \u2190 prove_mul_nat c ey eb,\n      (c, p) \u2190 if a \u2265 0 then prove_add_nat c ety ed etx else prove_add_nat c etx ed ety,\n      let pf : expr := if a \u2265 0 then `(nat_gcd_helper_2) else `(nat_gcd_helper_1),\n      pure (c, ed, pf.mk_app [ed, ex, ey, ea, eb, eu, ev, etx, ety, pu, pv, px, py, p])\n  end\n\n/-- Evaluates the `nat.lcm` function. -/\nmeta def prove_lcm_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 0, _ := pure (c, `(0:\u2115), `(nat.lcm_zero_left).mk_app [ey])\n  | _, 0 := pure (c, `(0:\u2115), `(nat.lcm_zero_right).mk_app [ex])\n  | 1, _ := pure (c, ey, `(nat.lcm_one_left).mk_app [ey])\n  | _, 1 := pure (c, ex, `(nat.lcm_one_right).mk_app [ex])\n  | _, _ := do\n    (c, ed, pd) \u2190 prove_gcd_nat c ex ey,\n    (c, p0) \u2190 prove_pos c ed,\n    (c, en, xy) \u2190 prove_mul_nat c ex ey,\n    d \u2190 ed.to_nat,\n    (c, em) \u2190 c.of_nat ((x * y) / d),\n    (c, _, dm) \u2190 prove_mul_nat c ed em,\n    pure (c, em, `(nat_lcm_helper).mk_app [ex, ey, ed, em, en, pd, p0, xy, dm])\n  end\n\n/-- Evaluates the `int.gcd` function. -/\nmeta def prove_gcd_int (zc nc : instance_cache) : expr \u2192 expr \u2192\n  tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| x y := match match_neg x with\n  | some x := do\n    (zc, nc, d, p) \u2190 prove_gcd_int x y,\n    pure (zc, nc, d, `(int_gcd_helper_neg_left).mk_app [x, y, d, p])\n  | none := match match_neg y with\n    | some y := do\n      (zc, nc, d, p) \u2190 prove_gcd_int x y,\n      pure (zc, nc, d, `(int_gcd_helper_neg_right).mk_app [x, y, d, p])\n    | none := do\n      (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x,\n      (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y,\n      (nc, d, p) \u2190 prove_gcd_nat nc nx ny,\n      pure (zc, nc, d, `(int_gcd_helper).mk_app [x, y, nx, ny, d, px, py, p])\n    end\n  end\n\n/-- Evaluates the `int.lcm` function. -/\nmeta def prove_lcm_int (zc nc : instance_cache) : expr \u2192 expr \u2192\n  tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| x y := match match_neg x with\n  | some x := do\n    (zc, nc, d, p) \u2190 prove_lcm_int x y,\n    pure (zc, nc, d, `(int_lcm_helper_neg_left).mk_app [x, y, d, p])\n  | none := match match_neg y with\n    | some y := do\n      (zc, nc, d, p) \u2190 prove_lcm_int x y,\n      pure (zc, nc, d, `(int_lcm_helper_neg_right).mk_app [x, y, d, p])\n    | none := do\n      (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x,\n      (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y,\n      (nc, d, p) \u2190 prove_lcm_nat nc nx ny,\n      pure (zc, nc, d, `(int_lcm_helper).mk_app [x, y, nx, ny, d, px, py, p])\n    end\n  end\n\n/-- Evaluates the `nat.coprime` function. -/\nmeta def prove_coprime_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 (expr \u2295 expr)) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 1, _ := pure (c, sum.inl $ `(nat.coprime_one_left).mk_app [ey])\n  | _, 1 := pure (c, sum.inl $ `(nat.coprime_one_right).mk_app [ex])\n  | 0, 0 := pure (c, sum.inr `(nat.not_coprime_zero_zero))\n  | 0, _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, p) \u2190 prove_lt_nat c `(1) ey,\n    pure (c, sum.inr $ `(nat_coprime_helper_zero_left).mk_app [ey, p])\n  | _, 0 := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, p) \u2190 prove_lt_nat c `(1) ex,\n    pure (c, sum.inr $ `(nat_coprime_helper_zero_right).mk_app [ex, p])\n  | _, _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    let (d, a, b) := nat.xgcd_aux x 1 0 y 0 1,\n    if d = 1 then do\n      (c, ea) \u2190 c.of_nat a.nat_abs,\n      (c, eb) \u2190 c.of_nat b.nat_abs,\n      (c, etx, px) \u2190 prove_mul_nat c ex ea,\n      (c, ety, py) \u2190 prove_mul_nat c ey eb,\n      (c, p) \u2190 if a \u2265 0 then prove_add_nat c ety `(1) etx else prove_add_nat c etx `(1) ety,\n      let pf : expr := if a \u2265 0 then `(nat_coprime_helper_2) else `(nat_coprime_helper_1),\n      pure (c, sum.inl $ pf.mk_app [ex, ey, ea, eb, etx, ety, px, py, p])\n    else do\n      (c, ed) \u2190 c.of_nat d,\n      (c, eu) \u2190 c.of_nat (x / d),\n      (c, ev) \u2190 c.of_nat (y / d),\n      (c, _, pu) \u2190 prove_mul_nat c ed eu,\n      (c, _, pv) \u2190 prove_mul_nat c ed ev,\n      (c, p) \u2190 prove_lt_nat c `(1) ed,\n      pure (c, sum.inr $ `(nat_not_coprime_helper).mk_app [ed, ex, ey, eu, ev, pu, pv, p])\n  end\n\n/-- Evaluates the `gcd`, `lcm`, and `coprime` functions. -/\n@[norm_num] meta def eval_gcd : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.gcd %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prod.snd <$> prove_gcd_nat c ex ey\n| `(nat.lcm %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prod.snd <$> prove_lcm_nat c ex ey\n| `(nat.coprime %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prove_coprime_nat c ex ey >>= sum.elim true_intro false_intro \u2218 prod.snd\n| `(int.gcd %%ex %%ey) := do\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> prove_gcd_int zc nc ex ey\n| `(int.lcm %%ex %%ey) := do\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> prove_lcm_int zc nc ex ey\n| _ := failed\n\nend norm_num\nend tactic\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/int/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.7395102592392028}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\n\nimport data.nat.sqrt data.int.basic\n\nnamespace int\n\n/-- `sqrt n` is the square root of an integer `n`. If `n` is not a\n  perfect square, and is positive, it returns the largest `k:\u2124` such\n  that `k*k \u2264 n`. If it is negative, it returns 0. For example,\n  `sqrt 2 = 1` and `sqrt 1 = 1` and `sqrt (-1) = 0` -/\ndef sqrt (n : \u2124) : \u2124 :=\nnat.sqrt $ int.to_nat n\n\ntheorem sqrt_eq (n : \u2124) : sqrt (n*n) = n.nat_abs :=\nby rw [sqrt, \u2190 nat_abs_mul_self, to_nat_coe_nat, nat.sqrt_eq]\n\ntheorem exists_mul_self (x : \u2124) :\n  (\u2203 n, n * n = x) \u2194 sqrt x * sqrt x = x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, by rw [\u2190 hn, sqrt_eq, \u2190 int.coe_nat_mul, nat_abs_mul_self],\n\u03bb h, \u27e8sqrt x, h\u27e9\u27e9\n\ntheorem sqrt_nonneg (n : \u2124) : 0 \u2264 sqrt n := trivial\n\nend int\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/data/int/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7395102576265905}}
{"text": "/-\nCopyright (c) 2021 Lu-Ming Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Lu-Ming Zhang.\n-/\nimport symmetric_matrix\n\n/-!\n# Circulant matrices\n\nThis file contains the definition and basic results about circulant matrices.\n\n## Main results\n\n- `matrix.cir`: introduce the definition of a circulant matrix generated by a given vector `v : I \u2192 \u03b1`.\n\n## Implementation notes\n\n`fin.foo` is the `fin n` version of `foo`. \nNamely, the index type of the circulant matrices in discussion is `fin n`.\n\n## Tags\n\ncir, matrix\n-/\n\nvariables {\u03b1 I R : Type*} [fintype I] {n : \u2115}\n\nnamespace matrix\nopen_locale matrix big_operators\n\n/-- Given the condition `[has_sub I]` and a vector `v : I \u2192 \u03b1`, \n    we define `cir v` to be the circulant matrix generated by `v` of type `matrix I I \u03b1`. -/\ndef cir [has_sub I] (v : I \u2192 \u03b1) : matrix I I \u03b1\n| i j := v (i - j)\n\n/-- When `I` is an `add_group`, the 0th column of `cir v` is `v`. -/\nlemma cir_col_zero_eq [add_group I] (v : I \u2192 \u03b1) :\n(\u03bb i, (cir v) i 0) = v := by ext; simp [cir]\n\n/-- When `I` is an `add_group`, `cir v = cir w \u2194 v = w`. -/\nlemma cir_ext_iff [add_group I] {v w : I \u2192 \u03b1} :\ncir v = cir w \u2194 v = w :=\nbegin\n  split,\n  { intro h, rw [\u2190 cir_col_zero_eq v, \u2190 cir_col_zero_eq w, h] },\n  { rintro rfl, refl }\nend\n\nlemma fin.cir_ext_iff {v w : fin n \u2192 \u03b1} :\ncir v = cir w \u2194 v = w :=\nbegin\n  induction n with n ih,\n  {tidy},\n  exact cir_ext_iff\nend\n\n/-- The sum of two circulant matrices `cir v` and `cir w` is also a circulant matrix `cir (v + w)`. -/\nlemma cir_add [has_add \u03b1] [has_sub I] (v w : I \u2192 \u03b1) :\ncir v + cir w = cir (v + w) := by ext; simp [cir]\n\n/-- The product of two circulant matrices `cir v` and `cir w` is also a circulant matrix `cir (mul_vec (cir w) v)`. -/\nlemma cir_mul [comm_semiring \u03b1] [add_comm_group I] (v w : I \u2192 \u03b1) :\ncir v \u2b1d cir w = cir (mul_vec (cir w) v) := \nbegin\n  ext i j,\n  simp [mul_apply, mul_vec, cir, dot_product],\n  refine fintype.sum_equiv ((equiv.add_left (-i)).trans (equiv.neg _)) _ _ _,\n  simp [mul_comm],\n  intro x,\n  congr' 2; abel\nend\n\nlemma fin.cir_mul [comm_semiring \u03b1] (v w : fin n \u2192 \u03b1) :\ncir v \u2b1d cir w = cir (mul_vec (cir w) v) := \nbegin\n  induction n with n ih, {refl},\n  exact cir_mul v w,\nend\n\n/-- Circulant matrices commute in multiplication under certain condations. -/\nlemma cir_mul_comm\n[comm_semigroup \u03b1] [add_comm_monoid \u03b1] [add_comm_group I] (v w : I \u2192 \u03b1) : \ncir v \u2b1d cir w = cir w \u2b1d cir v := \nbegin\n  ext i j,\n  simp [mul_apply, cir, mul_comm],\n  refine fintype.sum_equiv (((equiv.add_right (-i)).trans (equiv.neg _)).trans (equiv.add_right j)) _ _ _,\n  simp,\n  intro x,\n  congr' 2; abel\nend\n\nlemma fin.cir_mul_comm\n[comm_semigroup \u03b1] [add_comm_monoid \u03b1] (v w : fin n \u2192 \u03b1) : \ncir v \u2b1d cir w = cir w \u2b1d cir v := \nbegin\n  induction n with n ih, {refl},\n  exact cir_mul_comm v w,\nend\n\n/-- `k \u2022 cir v` is another circluant matrix `cir (k \u2022 v)`. -/\nlemma smul_cir [has_sub I] [has_scalar R \u03b1] {k : R} {v : I \u2192 \u03b1} : \nk \u2022 cir v = cir (k \u2022 v) := by {ext, simp [cir]}\n\n/-- The identity matrix is a circulant matrix. -/\nlemma one_eq_cir [has_zero \u03b1] [has_one \u03b1] [decidable_eq I] [add_group I]:\n(1 : matrix I I \u03b1) = cir (\u03bb i, ite (i = 0) 1 0) :=\nbegin\n  ext,\n  simp [cir, one_apply],\n  congr' 1,\n  apply propext,\n  exact sub_eq_zero.symm\nend\n\n/-- An alternative version of `one_eq_cir`. -/\nlemma one_eq_cir' [has_zero \u03b1] [has_one \u03b1] [decidable_eq I] [add_group I]:\n(1 : matrix I I \u03b1) = cir (\u03bb i, (1 : matrix I I \u03b1) i 0) := one_eq_cir\n\nlemma fin.one_eq_cir [has_zero \u03b1] [has_one \u03b1] :\n(1 : matrix (fin n) (fin n) \u03b1) = cir (\u03bb i, ite (i.1 = 0) 1 0) :=\nbegin\n  induction n with n, {dec_trivial},\n  convert one_eq_cir,\n  ext, congr' 1,\n  apply propext, \n  exact (fin.ext_iff x 0).symm\nend\n\n/-- For a one-ary predicate `p`, `p` applied to every entry of `cir v` is true if `p` applied to every entry of `v` is true. -/\nlemma pred_cir_entry_of_pred_vec_entry [has_sub I] {p : \u03b1 \u2192 Prop} {v : I \u2192 \u03b1} :\n(\u2200 k, p (v k)) \u2192 \u2200 i j, p ((cir v) i j) :=\nbegin\n  intros h i j,\n  simp [cir],\n  exact h (i - j),\nend\n\n/-- Given a set `S`, every entry of `cir v` is in `S` if every entry of `v` is in `S`. -/\nlemma cir_entry_in_of_vec_entry_in [has_sub I] {S : set \u03b1} {v : I \u2192 \u03b1} :\n(\u2200 k, v k \u2208 S) \u2192 \u2200 i j, (cir v) i j \u2208 S :=\n@pred_cir_entry_of_pred_vec_entry \u03b1 I _ _ S v\n\n/-- The circulant matrix `cir v` is symmetric iff `\u2200 i j, v (j - i) = v (i - j)`. -/\nlemma cir_is_sym_ext_iff' [has_sub I] {v : I \u2192 \u03b1} : \n(cir v).is_sym \u2194 \u2200 i j, v (j - i) = v (i - j) :=\nby simp [is_sym.ext_iff, cir]\n\n/-- The circulant matrix `cir v` is symmetric iff `v (- i) = v i` if `[add_group I]`. -/\nlemma cir_is_sym_ext_iff [add_group I] {v : I \u2192 \u03b1} : \n(cir v).is_sym \u2194 \u2200 i, v (- i) = v i :=\nbegin\n  rw [cir_is_sym_ext_iff'],\n  split,\n  { intros h i, convert h i 0; simp },\n  { intros h i j, convert h (i - j), simp }\nend\n\nlemma fin.cir_is_sym_ext_iff {v : fin n \u2192 \u03b1} : \n(cir v).is_sym \u2194 \u2200 i, v (- i) = v i :=\nbegin\n  induction n with n ih, \n  { rw [cir_is_sym_ext_iff'], \n    split; \n    {intros h i, have :=i.2, simp* at *} },\n  convert cir_is_sym_ext_iff,\nend\n\n/-- If `cir v` is symmetric, `\u2200 i j : I, v (j - i) = v (i - j)`. -/\nlemma cir_is_sym_apply' [has_sub I] {v : I \u2192 \u03b1} (h : (cir v).is_sym) (i j : I) : \nv (j - i) = v (i - j) := cir_is_sym_ext_iff'.1 h i j\n\n/-- If `cir v` is symmetric, `\u2200 i j : I, v (- i) = v i`. -/\nlemma cir_is_sym_apply [add_group I] {v : I \u2192 \u03b1} (h : (cir v).is_sym) (i : I) : \nv (-i) = v i := cir_is_sym_ext_iff.1 h i\n\nlemma fin.cir_is_sym_apply {v : fin n \u2192 \u03b1} (h : (cir v).is_sym) (i : fin n) : \nv (-i) = v i := fin.cir_is_sym_ext_iff.1 h i\n\n/-- The associated polynomial `(v 0) + (v 1) * X + ... + (v (n-1)) * X ^ (n-1)` to `cir v`.-/\nnoncomputable def cir_poly [semiring \u03b1] (v : fin n \u2192 \u03b1) : polynomial \u03b1 := \n\u2211 i : fin n, polynomial.monomial i (v i)\n\n/-- `cir_perm n` is the cyclic permutation over `fin n`. -/\ndef cir_perm : \u03a0 n, equiv.perm (fin n) := \u03bb n, equiv.symm (fin_rotate n) \n\n/-- `cir_P \u03b1 n` is the cyclic permutation matrix of order `n` with entries of type `\u03b1`. -/\ndef cir_P (\u03b1) [has_zero \u03b1] [has_one \u03b1] (n : \u2115) :\nmatrix (fin n) (fin n) \u03b1 := equiv.perm.to_matrix \u03b1 (cir_perm n)\n\nend matrix\n", "meta": {"author": "l534zhan", "repo": "my_project", "sha": "8949e149c242debd7cf932ba252cb67b10e78a43", "save_path": "github-repos/lean/l534zhan-my_project", "path": "github-repos/lean/l534zhan-my_project/my_project-8949e149c242debd7cf932ba252cb67b10e78a43/src/circulant_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7395102494314422}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.degree.default\nimport Mathlib.data.polynomial.degree.trailing_degree\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Erase the leading term of a univariate polynomial\n\n## Definition\n\n* `erase_lead f`: the polynomial `f - leading term of f`\n\n`erase_lead` serves as reduction step in an induction, shaving off one monomial from a polynomial.\nThe definition is set up so that it does not mention subtraction in the definition,\nand thus works for polynomials over semirings as well as rings.\n-/\n\nnamespace polynomial\n\n\n/-- `erase_lead f` for a polynomial `f` is the polynomial obtained by\nsubtracting from `f` the leading term of `f`. -/\ndef erase_lead {R : Type u_1} [semiring R] (f : polynomial R) : polynomial R :=\n  finsupp.erase (nat_degree f) f\n\ntheorem erase_lead_support {R : Type u_1} [semiring R] (f : polynomial R) : finsupp.support (erase_lead f) = finset.erase (finsupp.support f) (nat_degree f) := sorry\n\n-- `rfl` fails because LHS uses `nat.decidable_eq` but RHS is classical.\n\ntheorem erase_lead_coeff {R : Type u_1} [semiring R] {f : polynomial R} (i : \u2115) : coeff (erase_lead f) i = ite (i = nat_degree f) 0 (coeff f i) := sorry\n\n-- `rfl` fails because LHS uses `nat.decidable_eq` but RHS is classical.\n\n@[simp] theorem erase_lead_coeff_nat_degree {R : Type u_1} [semiring R] {f : polynomial R} : coeff (erase_lead f) (nat_degree f) = 0 :=\n  finsupp.erase_same\n\ntheorem erase_lead_coeff_of_ne {R : Type u_1} [semiring R] {f : polynomial R} (i : \u2115) (hi : i \u2260 nat_degree f) : coeff (erase_lead f) i = coeff f i :=\n  finsupp.erase_ne hi\n\n@[simp] theorem erase_lead_zero {R : Type u_1} [semiring R] : erase_lead 0 = 0 :=\n  finsupp.erase_zero (nat_degree 0)\n\n@[simp] theorem erase_lead_add_monomial_nat_degree_leading_coeff {R : Type u_1} [semiring R] (f : polynomial R) : erase_lead f + coe_fn (monomial (nat_degree f)) (leading_coeff f) = f := sorry\n\n@[simp] theorem erase_lead_add_C_mul_X_pow {R : Type u_1} [semiring R] (f : polynomial R) : erase_lead f + coe_fn C (leading_coeff f) * X ^ nat_degree f = f := sorry\n\n@[simp] theorem self_sub_monomial_nat_degree_leading_coeff {R : Type u_1} [ring R] (f : polynomial R) : f - coe_fn (monomial (nat_degree f)) (leading_coeff f) = erase_lead f :=\n  Eq.symm (iff.mpr eq_sub_iff_add_eq (erase_lead_add_monomial_nat_degree_leading_coeff f))\n\n@[simp] theorem self_sub_C_mul_X_pow {R : Type u_1} [ring R] (f : polynomial R) : f - coe_fn C (leading_coeff f) * X ^ nat_degree f = erase_lead f := sorry\n\ntheorem erase_lead_ne_zero {R : Type u_1} [semiring R] {f : polynomial R} (f0 : bit0 1 \u2264 finset.card (finsupp.support f)) : erase_lead f \u2260 0 := sorry\n\n@[simp] theorem nat_degree_not_mem_erase_lead_support {R : Type u_1} [semiring R] {f : polynomial R} : \u00acnat_degree f \u2208 finsupp.support (erase_lead f) := sorry\n\ntheorem ne_nat_degree_of_mem_erase_lead_support {R : Type u_1} [semiring R] {f : polynomial R} {a : \u2115} (h : a \u2208 finsupp.support (erase_lead f)) : a \u2260 nat_degree f := sorry\n\ntheorem erase_lead_support_card_lt {R : Type u_1} [semiring R] {f : polynomial R} (h : f \u2260 0) : finset.card (finsupp.support (erase_lead f)) < finset.card (finsupp.support f) := sorry\n\ntheorem erase_lead_card_support {R : Type u_1} [semiring R] {f : polynomial R} {c : \u2115} (fc : finset.card (finsupp.support f) = c) : finset.card (finsupp.support (erase_lead f)) = c - 1 := sorry\n\ntheorem erase_lead_card_support' {R : Type u_1} [semiring R] {f : polynomial R} {c : \u2115} (fc : finset.card (finsupp.support f) = c + 1) : finset.card (finsupp.support (erase_lead f)) = c :=\n  erase_lead_card_support fc\n\n@[simp] theorem erase_lead_monomial {R : Type u_1} [semiring R] (i : \u2115) (r : R) : erase_lead (coe_fn (monomial i) r) = 0 := sorry\n\n@[simp] theorem erase_lead_C {R : Type u_1} [semiring R] (r : R) : erase_lead (coe_fn C r) = 0 :=\n  erase_lead_monomial 0 r\n\n@[simp] theorem erase_lead_X {R : Type u_1} [semiring R] : erase_lead X = 0 :=\n  erase_lead_monomial 1 1\n\n@[simp] theorem erase_lead_X_pow {R : Type u_1} [semiring R] (n : \u2115) : erase_lead (X ^ n) = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (erase_lead (X ^ n) = 0)) (X_pow_eq_monomial n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (erase_lead (coe_fn (monomial n) 1) = 0)) (erase_lead_monomial n 1))) (Eq.refl 0))\n\n@[simp] theorem erase_lead_C_mul_X_pow {R : Type u_1} [semiring R] (r : R) (n : \u2115) : erase_lead (coe_fn C r * X ^ n) = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (erase_lead (coe_fn C r * X ^ n) = 0)) (C_mul_X_pow_eq_monomial r n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (erase_lead (coe_fn (monomial n) r) = 0)) (erase_lead_monomial n r))) (Eq.refl 0))\n\ntheorem erase_lead_degree_le {R : Type u_1} [semiring R] {f : polynomial R} : degree (erase_lead f) \u2264 degree f := sorry\n\ntheorem erase_lead_nat_degree_le {R : Type u_1} [semiring R] {f : polynomial R} : nat_degree (erase_lead f) \u2264 nat_degree f :=\n  nat_degree_le_nat_degree erase_lead_degree_le\n\ntheorem erase_lead_nat_degree_lt {R : Type u_1} [semiring R] {f : polynomial R} (f0 : bit0 1 \u2264 finset.card (finsupp.support f)) : nat_degree (erase_lead f) < nat_degree f :=\n  lt_of_le_of_ne erase_lead_nat_degree_le\n    (ne_nat_degree_of_mem_erase_lead_support (nat_degree_mem_support_of_nonzero (erase_lead_ne_zero f0)))\n\ntheorem erase_lead_nat_degree_lt_or_erase_lead_eq_zero {R : Type u_1} [semiring R] (f : polynomial R) : nat_degree (erase_lead f) < nat_degree f \u2228 erase_lead f = 0 := sorry\n\n/-- An induction lemma for polynomials. It takes a natural number `N` as a parameter, that is\nrequired to be at least as big as the `nat_degree` of the polynomial.  This is useful to prove\nresults where you want to change each term in a polynomial to something else depending on the\n`nat_degree` of the polynomial itself and not on the specific `nat_degree` of each term. -/\ntheorem induction_with_nat_degree_le {R : Type u_1} [semiring R] {P : polynomial R \u2192 Prop} (N : \u2115) (P_0 : P 0) (P_C_mul_pow : \u2200 (n : \u2115) (r : R), r \u2260 0 \u2192 n \u2264 N \u2192 P (coe_fn C r * X ^ n)) (P_C_add : \u2200 (f g : polynomial R), nat_degree f \u2264 N \u2192 nat_degree g \u2264 N \u2192 P f \u2192 P g \u2192 P (f + g)) (f : polynomial R) : nat_degree f \u2264 N \u2192 P f := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/polynomial/erase_lead.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7394787505783422}}
{"text": "/-\nCopyright (c) 2022 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Devon Tuma\n-/\nimport probability.probability_mass_function.uniform\nimport to_mathlib.pmf_stuff\nimport algebra.big_operators.fin\n\n/-!\n# Uniform constructions on pmf\n-/\n\nvariables {\u03b1 \u03b2 : Type}\n\nopen_locale classical big_operators nnreal ennreal\n\nnamespace pmf\n\nlemma to_outer_measure_uniform_of_fintype_apply' [fintype \u03b1] [nonempty \u03b1] (e : set \u03b1) [decidable_pred (\u2208 e)] :\n  (pmf.uniform_of_fintype \u03b1).to_outer_measure e = (finset.univ.filter (\u2208 e)).card / fintype.card \u03b1 :=\nbegin\n  rw [to_outer_measure_uniform_of_fintype_apply, fintype.card_of_finset],\n  congr,\nend\n\n-- NOTE: PR opened for this\nsection uniform_of_list\n\nnoncomputable def uniform_of_list (l : list \u03b1) (h : \u00ac l.empty) : pmf \u03b1 :=\npmf.of_multiset (quotient.mk l) (\u03bb hl, h ((multiset.coe_eq_zero_iff_empty l).1 hl))\n\nvariables (l : list \u03b1) (h : \u00ac l.empty)\n\n@[simp] lemma support_uniform_of_list : (uniform_of_list l h).support = {x | x \u2208 l} :=\ntrans (pmf.support_of_multiset _) (set.ext $ \u03bb x, by simp only [multiset.quot_mk_to_coe,\n  finset.mem_coe, multiset.mem_to_finset, multiset.mem_coe, set.mem_set_of_eq])\n\nlemma mem_support_uniform_of_list_iff (a : \u03b1) : a \u2208 (uniform_of_list l h).support \u2194 a \u2208 l :=\nby simp only [support_uniform_of_list, set.mem_set_of_eq]\n\n@[simp] lemma uniform_of_list_apply (a : \u03b1) : uniform_of_list l h a = l.count a / l.length :=\nby rw [uniform_of_list, pmf.of_multiset_apply, multiset.quot_mk_to_coe,\n  multiset.coe_count, multiset.coe_card]\n\nlemma uniform_of_list_apply_of_not_mem (a : \u03b1) (ha : a \u2209 l) : uniform_of_list l h a = 0 :=\n(pmf.apply_eq_zero_iff _ a).2 (mt (mem_support_uniform_of_list_iff l h a).1 ha)\n\nsection measure\n\n@[simp] lemma to_outer_measure_uniform_of_list_apply (t : set \u03b1) :\n  (uniform_of_list l h).to_outer_measure t = l.countp t / l.length :=\ncalc (uniform_of_list l h).to_outer_measure t\n  = (\u2211' x, (l.filter t).count x) / l.length : by simpa only [uniform_of_list,\n    to_outer_measure_of_multiset_apply, list.length, multiset.quot_mk_to_coe, multiset.coe_filter,\n    multiset.coe_count, multiset.coe_card]\n  ... = (\u2211 x in l.to_finset, (l.filter t).count x) / l.length : begin\n    refine congr_arg (\u03bb x, x / (l.length : \u211d\u22650\u221e)) (tsum_eq_sum $ \u03bb y hy, _),\n    rw [list.mem_to_finset] at hy,\n    simpa only [nat.cast_eq_zero, list.count_eq_zero, list.mem_filter, not_and]\n      using (false.elim \u2218 hy),\n  end\n  ... = (\u2211 x in (l.to_finset.filter t), \u2191(l.count x)) / l.length : begin\n    refine congr_arg (\u03bb x, x / (l.length : \u211d\u22650\u221e)) _,\n    rw [finset.sum_filter],\n    refine finset.sum_congr rfl (\u03bb x hx, _),\n    split_ifs with hxt,\n    { exact congr_arg coe (list.count_filter hxt) },\n    { simp only [nat.cast_eq_zero, list.count_eq_zero, list.mem_filter,\n        not_and, hxt, not_false_iff, imp_true_iff] }\n  end\n  ... = \u2191(\u2211 x in (l.to_finset.filter t), l.count x) / l.length : by rw nat.cast_sum\n  ... = l.countp t / l.length : by rw [finset.sum_filter_count_eq_countp]\n\n@[simp]\nlemma to_measure_uniform_of_list_apply (t : set \u03b1) [measurable_space \u03b1] (ht : measurable_set t) :\n  (uniform_of_list l h).to_measure t = l.countp t / l.length :=\n(to_measure_apply_eq_to_outer_measure_apply _ t ht).trans\n  (to_outer_measure_uniform_of_list_apply l h t)\n\nend measure\n\n-- NOTE : NOT IN PR\nlemma uniform_of_finset_eq_uniform_of_list_to_list (s : finset \u03b1) (h : s.nonempty) :\n  uniform_of_finset s h = uniform_of_list s.to_list (finset.nonempty.not_empty_to_list h) :=\nbegin\n  ext x,\n  simp only [finset.count_to_list, div_eq_mul_inv, uniform_of_finset_apply, uniform_of_list_apply,\n    nat.cast_ite, nat.cast_one, nat.cast_zero, finset.length_to_list, boole_mul],\nend\n\nend uniform_of_list\n\nsection uniform_of_vector\n\nnoncomputable def uniform_of_vector {n : \u2115} (v : vector \u03b1 (n + 1)) : pmf \u03b1 :=\nuniform_of_list v.1 (vector.not_empty_to_list v)\n\nvariables {n : \u2115} (v : vector \u03b1 (n + 1))\n\n@[simp]\nlemma support_uniform_of_vector : (uniform_of_vector v).support = {x | x \u2208 v.to_list} :=\nsupport_uniform_of_list v.1 (vector.not_empty_to_list v)\n\n@[simp]\nlemma uniform_of_vector_apply (a : \u03b1) : uniform_of_vector v a = v.to_list.count a / \u2191(n + 1) :=\n(uniform_of_list_apply v.1 _ a).trans (congr_arg (\u03bb x, _ / x) (congr_arg coe v.length_coe))\n\nlemma uniform_of_vector_eq_nth_map_uniform_of_fintype :\n  uniform_of_vector v = pmf.map v.nth (uniform_of_fintype $ fin (n + 1)) :=\npmf.ext (\u03bb x, by calc uniform_of_vector v x\n  = v.to_list.count x / n.succ : uniform_of_vector_apply v x\n  ... = \u2191(\u2211 i, ite (x = v.nth i) 1 0) / n.succ :\n    by rw [\u2190 fin.card_filter_univ_eq_vector_nth_eq_count,\n      finset.card_eq_sum_ones, finset.sum_filter]\n  ... = (\u2211 i, ite (x = v.nth i) 1 0) / n.succ : by simp only [finset.sum_boole, nat.cast_id]\n  ... = (\u2211' i, ite (x = v.nth i) 1 0) / n.succ :\n    congr_arg (\u03bb z, z / (n.succ : \u211d\u22650\u221e)) (tsum_eq_sum $ \u03bb y hy, (hy $ finset.mem_univ y).elim).symm\n  ... = pmf.map v.nth (uniform_of_fintype $ fin n.succ) x :\n    by simp only [div_eq_mul_inv, \u2190ennreal.tsum_mul_right, boole_mul, map_apply,\n      uniform_of_fintype_apply, fintype.card_fin])\n\nsection measure\n\n@[simp]\nlemma to_outer_measure_uniform_of_vector_apply (t : set \u03b1) :\n  (uniform_of_vector v).to_outer_measure t = v.to_list.countp t / \u2191(n + 1) :=\n(to_outer_measure_uniform_of_list_apply v.1 _ t).trans\n  (congr_arg (\u03bb x, _ / x) (congr_arg coe v.length_coe))\n\n@[simp]\nlemma to_measure_uniform_of_vector_apply (t : set \u03b1) [measurable_space \u03b1] (ht : measurable_set t) :\n  (uniform_of_vector v).to_measure t = v.to_list.countp t / \u2191(n + 1) :=\n(to_measure_apply_eq_to_outer_measure_apply _ t ht).trans\n  (to_outer_measure_uniform_of_vector_apply v t)\n\nend measure\n\nend uniform_of_vector\n\nend pmf\n\nlemma sum_ite_eq_nth {\u03b2 : Type} [add_comm_monoid_with_one \u03b2]\n  (a : \u03b1) {n : \u2115} (v : vector \u03b1 n) :\n  \u2211 i, ite (v.nth i = a) (1 : \u03b2) 0 = \u2191(v.to_list.count a) :=\nbegin\n  induction n with n hn,\n  { simp [vector.eq_nil v] },\n  { obtain \u27e8x, xs, hxs\u27e9 := vector.exists_eq_cons v,\n    suffices : ite (x = a) 1 0 + (list.count a xs.to_list : \u03b2) =\n      ite (x = a) ((list.count a xs.to_list) + 1) (list.count a xs.to_list),\n    by simpa only [hxs, fin.sum_univ_succ, vector.to_list_cons, list.count_cons,\n      vector.nth_cons_zero, @eq_comm _ a, hn xs, fin.coe_eq_cast_succ, fin.coe_succ_eq_succ,\n      vector.nth_cons_succ, nat.cast_ite, nat.cast_succ] using this,\n    split_ifs,\n    { exact add_comm _ _ },\n    { exact zero_add _ } }\nend\n\nlemma tsum_ite_eq_vector_nth {\u03b2 : Type} [add_comm_monoid_with_one \u03b2]\n  [topological_space \u03b2] [t2_space \u03b2] {n : \u2115} (v : vector \u03b1 n) (a : \u03b1) :\n  \u2211' (i : fin n), ite (v.nth i = a) (1 : \u03b2) 0 = \u2191(v.to_list.count a) :=\ncalc \u2211' (i : fin n), ite (v.nth i = a) (1 : \u03b2) 0\n  = \u2211 (i : fin n), ite (v.nth i = a) (1 : \u03b2) 0 :\n    tsum_eq_sum (\u03bb _ hb, (hb $ finset.mem_univ _).elim)\n  ... = (v.to_list.count a) : (sum_ite_eq_nth a v)\n", "meta": {"author": "dtumad", "repo": "lean-crypto-formalization", "sha": "f975a9a9882120b509553a7ced9aa05b745ff154", "save_path": "github-repos/lean/dtumad-lean-crypto-formalization", "path": "github-repos/lean/dtumad-lean-crypto-formalization/lean-crypto-formalization-f975a9a9882120b509553a7ced9aa05b745ff154/src/to_mathlib/uniform_of_vector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7394190412056698}}
{"text": "import .lovelib\n\n\n/-! # LoVe Homework 1: Definitions and Statements\n\nHomework must be done individually.\n\nReplace the placeholders (e.g., `:= sorry`) with your solutions. -/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (1 points): Snoc\n\n1.1 (1 point). Define the function `snoc` that appends a single element to the\nend of a list. Your function should be defined by recursion and not using `++`\n(`list.append`). -/\n\ndef snoc {\u03b1 : Type} : list \u03b1 \u2192 \u03b1 \u2192 list \u03b1 :=\nsorry\n\n/-! 1.2 (0 point). Convince yourself that your definition of `snoc` works by\ntesting it on a few examples. -/\n\n#reduce snoc [1] 2\n-- invoke `#reduce` or `#eval` here\n\n\n/-! ## Question 2 (3 points): Map\n\n2.1 (1 point). Define a generic `map` function that applies a function to every\nelement in a list. -/\n\ndef map {\u03b1 : Type} {\u03b2 : Type} (f : \u03b1 \u2192 \u03b2) : list \u03b1 \u2192 list \u03b2 :=\nsorry\n\n/-! 2.2 (2 points). State (without proving them) the so-called functorial\nproperties of `map` as lemmas. Schematically:\n\n     map (\u03bbx, x) xs = xs\n     map (\u03bbx, g (f x)) xs = map g (map f xs)\n\nTry to give meaningful names to your lemmas. Also, make sure to state the second\nproperty as generally as possible, for arbitrary types. -/\n\n-- enter your lemma statements here\n\n\n/-! ## Question 3 (5 points): \u03bb-Terms\n\nWe start by declaring four new opaque types. -/\n\nconstants \u03b1 \u03b2 \u03b3 \u03b4 : Type\n\n/-! 3.1 (2 points). Complete the following definitions, by providing terms with\nthe expected type.\n\nPlease use reasonable names for the bound variables, e.g., `a : \u03b1`, `b : \u03b2`,\n`c : \u03b3`.\n\nHint: A procedure for doing so systematically is described in Section 1.1.4 of\nthe Hitchhiker's Guide. As explained there, you can use `_` as a placeholder\nwhile constructing a term. By hovering over `_`, you will see the current\nlogical context. -/\n\ndef B : (\u03b1 \u2192 \u03b2) \u2192 (\u03b3 \u2192 \u03b1) \u2192 \u03b3 \u2192 \u03b2 :=\nsorry\n\ndef S : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 (\u03b1 \u2192 \u03b2) \u2192 \u03b1 \u2192 \u03b3 :=\nsorry\n\ndef more_nonsense : ((\u03b1 \u2192 \u03b2) \u2192 \u03b3 \u2192 \u03b4) \u2192 \u03b3 \u2192 \u03b2 \u2192 \u03b4 :=\nsorry\n\ndef even_more_nonsense : (\u03b1 \u2192 \u03b2) \u2192 (\u03b1 \u2192 \u03b3) \u2192 \u03b1 \u2192 \u03b2 \u2192 \u03b3 :=\nsorry\n\n/-! 3.2 (1 point). Complete the following definition.\n\nThis one looks more difficult, but it should be fairly straightforward if you\nfollow the procedure described in the Hitchhiker's Guide.\n\nNote: Peirce is pronounced like the English word \"purse\". -/\n\ndef weak_peirce : ((((\u03b1 \u2192 \u03b2) \u2192 \u03b1) \u2192 \u03b1) \u2192 \u03b2) \u2192 \u03b2 :=\nsorry\n\n/-! 3.3 (2 points). Show the typing derivation for your definition of `B` above,\nusing ASCII or Unicode art. You might find the characters `\u2013` (to draw\nhorizontal bars) and `\u22a2` useful.\n\nFeel free to introduce abbreviations to avoid repeating large contexts `\u0393`. -/\n\n-- write your solution here\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2021", "sha": "23b469c79afd482fa66da82e4726a317e3a7b5d5", "save_path": "github-repos/lean/blanchette-logical_verification_2021", "path": "github-repos/lean/blanchette-logical_verification_2021/logical_verification_2021-23b469c79afd482fa66da82e4726a317e3a7b5d5/lean/love01_definitions_and_statements_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.874077222043951, "lm_q1q2_score": 0.7394190190065902}}
{"text": "/-\nFinally we implement the function using a Java\nstyle of syntax.\n-/\nnamespace impl_cstyle\n\ndef sub1 (n : \u2115) : \u2115 :=   -- first arg named to left of :\n  match n with            -- match does case analysis after all\n  | 0 := 0\n  | (n' + 1) := n'\n  end\n\ndef add2 (n : \u2115) := n+2   -- n+2 is short for succ(succ n)!\n\n/-\nOur tests suggest our functions are working yet again.\n-/\nexample : sub1 0 = 0 := rfl\nexample : sub1 1 = 0 := rfl\nexample : sub1 2 = 1 := rfl\nexample : sub1 3 = 1 := rfl  -- bad test\nexample : add2 0 = 2 := rfl\nexample : add2 1 = 3 := rfl\nexample : add2 2 = 4 := rfl\nexample : add2 3 = 6 := rfl -- bad test\n\nend impl_cstyle\n\n\n/-\nNext we define functions that implement \nBoolean  \"and.\" Note that in each case we \n\"pattern match\" on both arguments.\n-/\n\ndef my_bool_and : bool \u2192 bool \u2192 bool \n| tt tt := tt\n| tt ff := ff\n| ff tt := ff\n| ff ff := ff\n\n/-\nEvaluation of this \"cases\" syntax\nis, again, in top-to-bottomorder: \nif the arguments match the first \npattern (tt tt), this function return \nthe value expressed to the right of\nthat := (tt). If the arguments don't\nmatch the first pattern, Lean moves\non to the next, until a match is found\nand the corresponding result is returned. \nLean will tell you if you've forgotten \na possible combination of argument \nvalues. Try it by commenting out one\nof the cases. \n-/\n\n\n/-\nA nice property of this syntax is that the \ntruth table for \"Boolean and\" is as clear as \nday. That said, after the first of the rules, \nthe rest all return false. You can use the \n\"wildcard\" character, _ (underscore) in Lean \nto match any value to avoid having to write\nthe three rules separately.\n -/\n\ndef my_bool_and2 : bool \u2192 bool \u2192 bool \n| tt tt := tt\n| _ _ := ff\n\n/-\nMaybe at this point you're not sure that these\ntwo functions have exactly the same meaning. \nLet's check that by stating the proposition \nthat they return the same values for all of\nthe possible combinations of argument values,\nand proving it. The proof is by case analysis\non the possible values of the arguments.\n-/\n\nexample : \n  \u2200 (b1 b2 : bool), \n    my_bool_and b1 b2 = \n    my_bool_and2 b1 b2 \n  :=\nbegin\nassume b1 b2, -- bind argument names\n\n-- case analysis on b1 \ncases b1,     \n\n-- b1 false\n\n-- case analysis on b2\ncases b2,\n-- b2 false \napply rfl,\n-- b2 true\napply rfl,\n\n-- b1 true\n\n-- case analysis on b2\ncases b2,\n-- b2 false\napply rfl,\n-- b2 true\napply rfl,\nend \n\n/-\nHere are test cases\n-/\nexample : my_bool_and tt tt = tt := rfl\nexample : my_bool_and tt ff = ff := rfl\nexample : my_bool_and ff tt = ff := rfl\nexample : my_bool_and ff ff = ff := rfl\n\n\n/-\nFunctions in Lean must be \"total,\" which means that\nthey must be defined to return values of the right\ntypes for *all* possible combinations of arguments.\nIf you delete cases from the my_bool_and definition\nyou'll get a missing cases error and the following\nevaluations will \"block\" on the undefined cases. Try\nit!\n-/\n", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/02_Predicate_Logic/02_Functions_and_Applications/03_function_by_cases_bool.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.8740772286044095, "lm_q1q2_score": 0.7394190109768614}}
{"text": "import plane_separation_world.level02 --hide\nopen IncidencePlane --hide\n\n/-\n# Plane Separation World\n\n## Level 3: proving useful lemmas...\n\nTo solve the following levels, we may want to use the lemma that we are going to prove now. Here you have some hints that could help you to step through it!\n\n**Hint 1:** Whenever you see the word `collinear`, the `unfold` tactic will make progress.\n\n**Hint 2:** Whenever you find a goal or hypothesis of the form `\u2200 {X : \u03a9}, X \u2208 {A, B, C} \u2192 X \u2208 r`, the `simp` tactic will make progress.\n\n**Hint 3:** To solve the first goal, you may want to use the theorem statement `incidence` with the `rewrite` tactic.\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\n... Still bewildered? Click on \"View source\" (located on the top right\ncorner of the game screen) to see the solution. \n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B C P Q R : \u03a9} --hide\nvariables {\u2113 r s t : Line \u03a9} --hide\n\n/- Lemma :\nGiven three distinct points, they are on the same line if and only if they are collinear.\n-/\nlemma collinear_iff_on_line_through (h : A \u2260 B) : collinear ({A, B, C} : set \u03a9) \u2194 C \u2208 line_through A B :=\nbegin\nsplit,\n{\n  intro h1,\n  unfold collinear at h1,\n  cases h1 with \u2113 h\u2113,\n  simp at h\u2113,\n  rw \u2190 (incidence h h\u2113.1 h\u2113.2.1),\n  exact h\u2113.2.2,\n},\n{\n  intro h1,\n  unfold collinear,\n  use line_through A B,\n  simp,\n  exact h1,\n},\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/plane_separation_world/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7393634012335105}}
{"text": "import data.real.basic\nimport data.real.irrational\nimport data.real.sqrt\nimport analysis.special_functions.pow\n\ndef rational (x : \u211d) := \u2203 a b : \u2124, x = a / b\n\nnotation `\u221a` a := real.sqrt a\n\n/- Prove that there exist irrational numbers a and b such that a ^ b is rational.\n   A paper-pencil proof:\n   Let a = b = \u221a2.\n   Since a ^ b is either rational or not rational, we have two cases:\n   Case 1, if a ^ b is rational, then the result is proved.  \n   Case 2, if a ^ b is irrational, take b' = \u221a2.\n      (a ^ b) ^ b' = (\u221a2 ^ \u221a2) ^ \u221a2 = \u221a2 ^ (\u221a2 * \u221a2) = 2, which is rational.\n  In any case, we proved that there exist irrational numbers a and b such that a ^ b is rational. \n  Q.E.D.\n-/\n\nlemma rational_two : rational 2 :=\nbegin\n  use [2, 1],\n  norm_num,\nend\n\nlemma irrational_of_not_rational {x : \u211d} (h : \u00ac rational x) : irrational x :=\nbegin\n  rw irrational_iff_ne_rational,\n  rw rational at h,\n  push_neg at h,\n  exact h,\nend\n\nexample : \u2203 a b : \u211d, irrational a \u2227 irrational b \u2227 rational (a ^ b) :=\nbegin\n  let a := \u221a2,\n  let b := \u221a2,\n  by_cases rational (a ^ b),\n  { use [a, b],\n    exact \u27e8irrational_sqrt_two, irrational_sqrt_two, h\u27e9, },\n  { let b' := \u221a2,\n    use [a ^ b, b'],\n    have rational_exp : rational ((a ^ b) ^ b'),\n    { have exp_eq_2 : (a ^ b) ^ b' = 2,\n      calc (a ^ b) ^ b' = ((\u221a2) ^ \u221a2) ^ \u221a2 : by refl\n      ...               = (\u221a2) ^ ((\u221a2) * \u221a2) : by rw \u2190 real.rpow_mul (real.sqrt_nonneg 2)\n      ...               = 2 : by simp,\n      rw exp_eq_2,\n      exact rational_two, },\n      exact \u27e8irrational_of_not_rational h, irrational_sqrt_two, rational_exp\u27e9,\n    },\nend\n", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/0_Introduction/demos/rational_pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561135, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7393633854194571}}
{"text": "import algebra.big_operators data.fintype\nimport tactic.ring\nimport tidy.tidy\n\n-- https://xenaproject.wordpress.com/2018/03/30/proofs-by-induction/\n\nopen nat\n\ndef odd : \u2115 \u2192 \u2115 := \u03bb i, 2 * i + 1\ndef square : \u2115 \u2192 \u2115 := \u03bb i, i * i\n@[ematch] theorem odd_square_inductive_step (d : \u2115) :\n   odd d + square d = square (d+1) :=\nbegin dsimp [square, odd], ring, end\n\nnamespace def1\n\ndefinition my_sum_to_n (summand : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115\n| 0     := 0\n| (n+1) := my_sum_to_n n + summand n\n\n-- TODO do we really need this? Can we write a tactic that unfolds a definition if it matches a case?\n@[simp] theorem my_successor_theorem (summand : \u2115 \u2192 \u2115) (n : \u2115) :\n  my_sum_to_n summand (n+1) = my_sum_to_n summand n + summand n :=\nby obviously\n\n-- FIXME can't use obviously here: `abstract` causes problems.\ntheorem my_odd_square_theorem : \u2200 (n : \u2115), my_sum_to_n odd n = square n\n| 0     := rfl\n| (n+1) := begin obviously'' end\n\nend def1\n\nnamespace def2\n\ndefinition my_sum_to_n (summand : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115 :=\n\u03bb n, ((list.range n).map summand).sum\n\ntheorem my_zero_theorem (summand : \u2115 \u2192 \u2115) :\n  my_sum_to_n summand 0 = 0 :=\nrfl\n\ntheorem my_successor_theorem (summand : \u2115 \u2192 \u2115) (n : \u2115) :\n  my_sum_to_n summand (succ n) = my_sum_to_n summand n + summand n :=\nby unfold my_sum_to_n; simp [list.range_concat]\n\ntheorem my_odd_square_theorem : \u2200 (n : \u2115), my_sum_to_n odd n = square n\n| 0        := rfl\n| (succ n) := by rw [my_successor_theorem, my_odd_square_theorem n]; simp; exact odd_square_inductive_step n\n\nend def2\n\nnamespace def3\n\ndefinition my_sum_to_n (summand : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115 :=\n\u03bb n, (finset.range n).sum summand\n\ntheorem my_zero_theorem (summand : \u2115 \u2192 \u2115) :\n  my_sum_to_n summand 0 = 0 :=\nrfl\n\ntheorem my_successor_theorem (summand : \u2115 \u2192 \u2115) (n : \u2115) :\n  my_sum_to_n summand (succ n) = my_sum_to_n summand n + summand n :=\nby unfold my_sum_to_n; simp\n\ntheorem my_odd_square_theorem : \u2200 (n : \u2115), my_sum_to_n odd n = square n\n| 0        := rfl\n| (succ n) := by rw [my_successor_theorem, my_odd_square_theorem n]; simp; exact odd_square_inductive_step n\n\nend def3\n\nnamespace def4\n\nopen finset nat\n\n-- Credits to Chris Hughes\ntheorem chris (n : \u2115) (f : \u2115 \u2192 \u2115) (g : fin n \u2192 \u2115) (h : \u2200 i : fin n, f i.1  = g i) :\n    (range n).sum f = univ.sum g :=\nsum_bij\n  (\u03bb i h, \u27e8i, mem_range.1 h\u27e9)\n  (\u03bb i h, mem_univ _)\n  (\u03bb a ha, h \u27e8a, _\u27e9)\n  (\u03bb _ _ _ _, fin.veq_of_eq)\n  (\u03bb \u27e8b, hb\u27e9 _, \u27e8b, mem_range.2 hb, rfl\u27e9)\n\ndefinition my_sum_to_n (summand : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115 :=\n\u03bb n, (@finset.univ (fin n) _).sum (summand \u2218 fin.val)\n\ntheorem my_zero_theorem (summand : \u2115 \u2192 \u2115) :\n  my_sum_to_n summand 0 = 0 :=\nrfl\n\n-- Credits to Mario Carneiro\ntheorem my_successor_theorem (summand : \u2115 \u2192 \u2115) (n : \u2115) :\n  my_sum_to_n summand (succ n) = my_sum_to_n summand n + summand n :=\nby unfold my_sum_to_n;\nrw [\u2190 chris _ _ _ (\u03bb _, rfl), \u2190 chris _ _ _ (\u03bb _, rfl)]; simp\n\ntheorem my_odd_square_theorem : \u2200 (n : \u2115), my_sum_to_n odd n = square n\n| 0        := rfl\n| (succ n) := by rw [my_successor_theorem, my_odd_square_theorem n]; simp; exact odd_square_inductive_step n\n\nend def4\n\nnamespace equality\n\ntheorem def12 : def1.my_sum_to_n = def2.my_sum_to_n :=\nfunext $ \u03bb summand, funext $ \u03bb n, nat.rec_on n rfl $\n\u03bb m ih, by rw [def1.my_successor_theorem, def2.my_successor_theorem, ih]\n\ntheorem def23 : def2.my_sum_to_n = def3.my_sum_to_n :=\nfunext $ \u03bb summand, funext $ \u03bb n, nat.rec_on n rfl $\n\u03bb m ih, by rw [def2.my_successor_theorem, def3.my_successor_theorem, ih]\n\ntheorem def34 : def3.my_sum_to_n = def4.my_sum_to_n :=\nfunext $ \u03bb summand, funext $ \u03bb n, nat.rec_on n rfl $\n\u03bb m ih, by rw [def3.my_successor_theorem, def4.my_successor_theorem, ih]\n\nend equality", "meta": {"author": "semorrison", "repo": "lean-tidy", "sha": "6c1d46de6cff05e1c2c4c9692af812bca3e13b6c", "save_path": "github-repos/lean/semorrison-lean-tidy", "path": "github-repos/lean/semorrison-lean-tidy/lean-tidy-6c1d46de6cff05e1c2c4c9692af812bca3e13b6c/examples/proofs-by-induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7393294152870098}}
{"text": "/-\nCopyright (c) 2020 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n\n! This file was ported from Lean 3 source module ring_theory.prime\n! leanprover-community/mathlib commit 008205aa645b3f194c1da47025c5f110c8406eab\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Associated\nimport Mathlib.Algebra.BigOperators.Basic\n\n/-!\n# Prime elements in rings\nThis file contains lemmas about prime elements of commutative rings.\n-/\n\n\nsection CancelCommMonoidWithZero\n\nvariable {R : Type _} [CancelCommMonoidWithZero R]\n\nopen Finset\n\nopen BigOperators\n\n/-- If `x * y = a * \u220f i in s, p i` where `p i` is always prime, then\n  `x` and `y` can both be written as a divisor of `a` multiplied by\n  a product over a subset of `s`  -/\ntheorem mul_eq_mul_prime_prod {\u03b1 : Type _} [DecidableEq \u03b1] {x y a : R} {s : Finset \u03b1} {p : \u03b1 \u2192 R}\n    (hp : \u2200 i \u2208 s, Prime (p i)) (hx : x * y = a * \u220f i in s, p i) :\n    \u2203 (t u : Finset \u03b1)(b c : R),\n      t \u222a u = s \u2227 Disjoint t u \u2227 a = b * c \u2227 (x = b * \u220f i in t, p i) \u2227 y = c * \u220f i in u, p i := by\n  induction' s using Finset.induction with i s his ih generalizing x y a\n  \u00b7 exact \u27e8\u2205, \u2205, x, y, by simp [hx]\u27e9\n  \u00b7 rw [prod_insert his, \u2190 mul_assoc] at hx\n    have hpi : Prime (p i) := hp i (mem_insert_self _ _)\n    rcases ih (fun i hi \u21a6 hp i (mem_insert_of_mem hi)) hx with\n      \u27e8t, u, b, c, htus, htu, hbc, rfl, rfl\u27e9\n    have hit : i \u2209 t := fun hit \u21a6 his (htus \u25b8 mem_union_left _ hit)\n    have hiu : i \u2209 u := fun hiu \u21a6 his (htus \u25b8 mem_union_right _ hiu)\n    obtain \u27e8d, rfl\u27e9 | \u27e8d, rfl\u27e9 : p i \u2223 b \u2228 p i \u2223 c\n    exact hpi.dvd_or_dvd \u27e8a, by rw [\u2190 hbc, mul_comm]\u27e9\n    \u00b7 rw [mul_assoc, mul_comm a, mul_right_inj' hpi.ne_zero] at hbc\n      exact \u27e8insert i t, u, d, c, by rw [insert_union, htus], disjoint_insert_left.2 \u27e8hiu, htu\u27e9, by\n          simp [hbc, prod_insert hit, mul_assoc, mul_comm, mul_left_comm]\u27e9\n    \u00b7 rw [\u2190 mul_assoc, mul_right_comm b, mul_left_inj' hpi.ne_zero] at hbc\n      exact \u27e8t, insert i u, b, d, by rw [union_insert, htus], disjoint_insert_right.2 \u27e8hit, htu\u27e9, by\n          simp [\u2190 hbc, prod_insert hiu, mul_assoc, mul_comm, mul_left_comm]\u27e9\n#align mul_eq_mul_prime_prod mul_eq_mul_prime_prod\n\n/-- If ` x * y = a * p ^ n` where `p` is prime, then `x` and `y` can both be written\n  as the product of a power of `p` and a divisor of `a`. -/\ntheorem mul_eq_mul_prime_pow {x y a p : R} {n : \u2115} (hp : Prime p) (hx : x * y = a * p ^ n) :\n    \u2203 (i j : \u2115)(b c : R), i + j = n \u2227 a = b * c \u2227 x = b * p ^ i \u2227 y = c * p ^ j := by\n  rcases mul_eq_mul_prime_prod (fun _ _ \u21a6 hp)\n    (show x * y = a * (range n).prod fun _ \u21a6 p by simpa) with\n      \u27e8t, u, b, c, htus, htu, rfl, rfl, rfl\u27e9\n  exact \u27e8t.card, u.card, b, c, by rw [\u2190 card_disjoint_union htu, htus, card_range], by simp\u27e9\n#align mul_eq_mul_prime_pow mul_eq_mul_prime_pow\n\nend CancelCommMonoidWithZero\n\nsection CommRing\n\nvariable {\u03b1 : Type _} [CommRing \u03b1]\n\ntheorem Prime.neg {p : \u03b1} (hp : Prime p) : Prime (-p) := by\n  obtain \u27e8h1, h2, h3\u27e9 := hp\n  exact \u27e8neg_ne_zero.mpr h1, by rwa [IsUnit.neg_iff], by simpa [neg_dvd] using h3\u27e9\n#align prime.neg Prime.neg\n\ntheorem Prime.abs [LinearOrder \u03b1] {p : \u03b1} (hp : Prime p) : Prime (abs p) := by\n  obtain h | h := abs_choice p <;> rw [h]\n  \u00b7 exact hp\n  \u00b7 exact hp.neg\n#align prime.abs Prime.abs\n\nend CommRing\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/Prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7393294071820353}}
{"text": "/-\nCopyright (c) 2022 Pim Otte. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller, Pim Otte\n\n! This file was ported from Lean 3 source module data.nat.factorial.big_operators\n! leanprover-community/mathlib commit 1126441d6bccf98c81214a0780c73d499f6721fe\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Order\n\n/-!\n# Factorial with big operators\n\nThis file contains some lemmas on factorials in combination with big operators.\n\nWhile in terms of semantics they could be in the `Basic.lean` file, importing\n`Algebra.BigOperators.Basic` leads to a cyclic import.\n\n-/\n\n\nopen Nat\nopen BigOperators\n\nnamespace Nat\n\nvariable {\u03b1 : Type _} (s : Finset \u03b1) (f : \u03b1 \u2192 \u2115)\n\ntheorem prod_factorial_pos : 0 < \u220f i in s, (f i)! :=\n  Finset.prod_pos fun i _ => factorial_pos (f i)\n#align nat.prod_factorial_pos Nat.prod_factorial_pos\n\ntheorem prod_factorial_dvd_factorial_sum : (\u220f i in s, (f i)!) \u2223 (\u2211 i in s, f i)! := by\n  classical\n    induction' s using Finset.induction with a' s' has ih\n    \u00b7 simp only [Finset.sum_empty, Finset.prod_empty, factorial]\n    \u00b7 simp only [Finset.prod_insert has, Finset.sum_insert has]\n      refine' dvd_trans (mul_dvd_mul_left (f a')! ih) _\n      apply Nat.factorial_mul_factorial_dvd_factorial_add\n#align nat.prod_factorial_dvd_factorial_sum Nat.prod_factorial_dvd_factorial_sum\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Factorial/BigOperators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.739329396053642}}
{"text": "import topology.metric_space.basic\n\ndef converges_to {X : Type*} [metric_space X] (s : \u2115 \u2192 X) (x : X) :=\n\u2200 (\u03b5 : \u211d) (h\u03b5 : 0 < \u03b5), \u2203 N : \u2115, \u2200 (n : \u2115) (hn : N \u2264 n), dist x (s n) < \u03b5\n\nnotation s ` \u27f6 ` x := converges_to s x\n\n--12\ntheorem limit_unique {X : Type*} [metric_space X] {s : \u2115 \u2192 X}\n  (x\u2080 x\u2081 : X) (h\u2080 : s \u27f6 x\u2080) (h\u2081 : s \u27f6 x\u2081) :\nx\u2080 = x\u2081 :=\nbegin\n  refine classical.by_contradiction _,\n  intro h,\n  have new_h := dist_pos.mpr h,\n  rcases h\u2080 ((dist x\u2080 x\u2081)/2) (by linarith) with \u27e8N,hN\u27e9,\n  rcases h\u2081 ((dist x\u2080 x\u2081)/2) (by linarith) with \u27e8N',hN'\u27e9,\n  have nesda := dist_triangle_right x\u2080 x\u2081 (s (max N N')),\n  have ans := add_lt_add (hN (max N N') (le_max_left _ _)) (hN' (max N N') (le_max_right _ _)),\n  linarith\nend\n", "meta": {"author": "themathqueen", "repo": "lean_katas", "sha": "bc34f9a986dac6957c8ac1b7e9ed38b4ce1b5095", "save_path": "github-repos/lean/themathqueen-lean_katas", "path": "github-repos/lean/themathqueen-lean_katas/lean_katas-bc34f9a986dac6957c8ac1b7e9ed38b4ce1b5095/src/7kyu.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7393014639818385}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.erase_lead\nimport Mathlib.PostPort\n\nuniverses u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# Denominators of evaluation of polynomials at ratios\n\nLet `i : R \u2192 K` be a homomorphism of semirings.  Assume that `K` is commutative.  If `a` and\n`b` are elements of `R` such that `i b \u2208 K` is invertible, then for any polynomial\n`f \u2208 polynomial R` the \"mathematical\" expression `b ^ f.nat_degree * f (a / b) \u2208 K` is in\nthe image of the homomorphism `i`.\n-/\n\n-- TODO: use hypothesis (ub : is_unit (i b)) to work with localizations.\n\n/-- `denoms_clearable` formalizes the property that `b ^ N * f (a / b)`\ndoes not have denominators, if the inequality `f.nat_degree \u2264 N` holds.\n\nIn the implementation, we also use provide an inverse in the existential.\n-/\ndef denoms_clearable {R : Type u_1} {K : Type u_2} [semiring R] [comm_semiring K] (a : R) (b : R) (N : \u2115) (f : polynomial R) (i : R \u2192+* K) :=\n  \u2203 (D : R),\n    \u2203 (bi : K), bi * coe_fn i b = 1 \u2227 coe_fn i D = coe_fn i b ^ N * polynomial.eval (coe_fn i a * bi) (polynomial.map i f)\n\ntheorem denoms_clearable_zero {R : Type u_1} {K : Type u_2} [semiring R] [comm_semiring K] {i : R \u2192+* K} {b : R} {bi : K} (N : \u2115) (a : R) (bu : bi * coe_fn i b = 1) : denoms_clearable a b N 0 i := sorry\n\ntheorem denoms_clearable_C_mul_X_pow {R : Type u_1} {K : Type u_2} [semiring R] [comm_semiring K] {i : R \u2192+* K} {b : R} {bi : K} {N : \u2115} (a : R) (bu : bi * coe_fn i b = 1) {n : \u2115} (r : R) (nN : n \u2264 N) : denoms_clearable a b N (coe_fn polynomial.C r * polynomial.X ^ n) i := sorry\n\ntheorem denoms_clearable.add {R : Type u_1} {K : Type u_2} [semiring R] [comm_semiring K] {i : R \u2192+* K} {a : R} {b : R} {N : \u2115} {f : polynomial R} {g : polynomial R} : denoms_clearable a b N f i \u2192 denoms_clearable a b N g i \u2192 denoms_clearable a b N (f + g) i := sorry\n\ntheorem denoms_clearable_of_nat_degree_le {R : Type u_1} {K : Type u_2} [semiring R] [comm_semiring K] {i : R \u2192+* K} {b : R} {bi : K} (N : \u2115) (a : R) (bu : bi * coe_fn i b = 1) (f : polynomial R) : polynomial.nat_degree f \u2264 N \u2192 denoms_clearable a b N f i := sorry\n\n/-- If `i : R \u2192 K` is a ring homomorphism, `f` is a polynomial with coefficients in `R`,\n`a, b` are elements of `R`, with `i b` invertible, then there is a `D \u2208 R` such that\n`b ^ f.nat_degree * f (a / b)` equals `i D`. -/\ntheorem denoms_clearable_nat_degree {R : Type u_1} {K : Type u_2} [semiring R] [comm_semiring K] {b : R} {bi : K} (i : R \u2192+* K) (f : polynomial R) (a : R) (bu : bi * coe_fn i b = 1) : denoms_clearable a b (polynomial.nat_degree f) f i :=\n  denoms_clearable_of_nat_degree_le (polynomial.nat_degree f) a bu f le_rfl\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/polynomial/denoms_clearable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7393014639818385}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\n\nimport linear_algebra.bilinear_form\nimport ring_theory.power_basis\n\n/-!\n# Trace for (finite) ring extensions.\n\nSuppose we have an `R`-algebra `S` with a finite basis. For each `s : S`,\nthe trace of the linear map given by multiplying by `s` gives information about\nthe roots of the minimal polynomial of `s` over `R`.\n\n## Implementation notes\n\nTypically, the trace is defined specifically for finite field extensions.\nThe definition is as general as possible and the assumption that we have\nfields or that the extension is finite is added to the lemmas as needed.\n\nWe only define the trace for left multiplication (`algebra.left_mul_matrix`,\ni.e. `algebra.lmul_left`).\nFor now, the definitions assume `S` is commutative, so the choice doesn't matter anyway.\n\n## References\n\n * https://en.wikipedia.org/wiki/Field_trace\n\n-/\n\nuniverses u v w\n\nvariables {R S T : Type*} [comm_ring R] [comm_ring S] [comm_ring T]\nvariables [algebra R S] [algebra R T]\nvariables {K L : Type*} [field K] [field L] [algebra K L]\nvariables {\u03b9 : Type w} [fintype \u03b9]\n\nopen finite_dimensional\nopen linear_map\nopen matrix\n\nopen_locale big_operators\nopen_locale matrix\n\nnamespace algebra\n\nvariables {b : \u03b9 \u2192 S} (hb : is_basis R b)\n\nvariables (R S)\n\n/-- The trace of an element `s` of an `R`-algebra is the trace of `(*) s`,\nas an `R`-linear map. -/\n@[simps]\nnoncomputable def trace : S \u2192\u2097[R] R :=\n(linear_map.trace R S).comp (lmul R S).to_linear_map\n\nvariables {S}\n\nlemma trace_eq_zero_of_not_exists_basis\n  (h : \u00ac \u2203 s : finset S, is_basis R (\u03bb x, x : (\u2191s : set S) \u2192 S)) : trace R S = 0 :=\nby { ext s, simp [linear_map.trace, h] }\n\ninclude hb\n\nvariables {R}\n\n-- Can't be a `simp` lemma because it depends on a choice of basis\nlemma trace_eq_matrix_trace [decidable_eq \u03b9] (hb : is_basis R b) (s : S) :\n  trace R S s = matrix.trace _ R _ (algebra.left_mul_matrix hb s) :=\nby rw [trace_apply, linear_map.trace_eq_matrix_trace _ hb, to_matrix_lmul_eq]\n\n/-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. -/\nlemma trace_algebra_map_of_basis (x : R) :\n  trace R S (algebra_map R S x) = fintype.card \u03b9 \u2022 x :=\nbegin\n  haveI := classical.dec_eq \u03b9,\n  rw [trace_apply, linear_map.trace_eq_matrix_trace R hb, trace_diag],\n  convert finset.sum_const _,\n  ext i,\n  simp,\nend\nomit hb\n\n/-- If `x` is in the base field `K`, then the trace is `[L : K] * x`.\n\n(If `L` is not finite-dimensional over `K`, then `trace` and `finrank` return `0`.)\n-/\n@[simp]\nlemma trace_algebra_map (x : K) : trace K L (algebra_map K L x) = finrank K L \u2022 x :=\nbegin\n  by_cases H : \u2203 s : finset L, is_basis K (\u03bb x, x : (\u2191s : set L) \u2192 L),\n  { rw [trace_algebra_map_of_basis H.some_spec, finrank_eq_card_basis H.some_spec] },\n  { simp [trace_eq_zero_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis H] },\nend\n\nsection trace_form\n\nvariables (R S)\n\n/-- The `trace_form` maps `x y : S` to the trace of `x * y`.\nIt is a symmetric bilinear form and is nondegenerate if the extension is separable. -/\nnoncomputable def trace_form : bilin_form R S :=\n(linear_map.compr\u2082 (lmul R S).to_linear_map (trace R S)).to_bilin\n\nvariables {S}\n\n-- This is a nicer lemma than the one produced by `@[simps] def trace_form`.\n@[simp] lemma trace_form_apply (x y : S) : trace_form R S x y = trace R S (x * y) := rfl\n\nlemma trace_form_is_sym : sym_bilin_form.is_sym (trace_form R S) :=\n\u03bb x y, congr_arg (trace R S) (mul_comm _ _)\n\n\n\nlemma trace_form_to_matrix_power_basis (h : power_basis R S) :\n  bilin_form.to_matrix h.is_basis (trace_form R S) = \u03bb i j, (trace R S (h.gen ^ (i + j : \u2115))) :=\nby { ext, rw [trace_form_to_matrix, pow_add] }\n\nend trace_form\n\nend algebra\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7393014555241666}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Violeta Hern\u00e1ndez Palacios\n\n! This file was ported from Lean 3 source module measure_theory.card_measurable_space\n! leanprover-community/mathlib commit f2b108e8e97ba393f22bf794989984ddcc1da89b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.MeasureTheory.MeasurableSpaceDef\nimport Mathlib.SetTheory.Cardinal.Cofinality\nimport Mathlib.SetTheory.Cardinal.Continuum\n\n/-!\n# Cardinal of sigma-algebras\n\nIf a sigma-algebra is generated by a set of sets `s`, then the cardinality of the sigma-algebra is\nbounded by `(max (#s) 2) ^ \u2135\u2080`. This is stated in `MeasurableSpace.cardinal_generate_measurable_le`\nand `MeasurableSpace.cardinalMeasurableSet_le`.\n\nIn particular, if `#s \u2264 \ud835\udd20`, then the generated sigma-algebra has cardinality at most `\ud835\udd20`, see\n`MeasurableSpace.cardinal_measurableSet_le_continuum`.\n\nFor the proof, we rely on an explicit inductive construction of the sigma-algebra generated by\n`s` (instead of the inductive predicate `GenerateMeasurable`). This transfinite inductive\nconstruction is parameterized by an ordinal `< \u03c9\u2081`, and the cardinality bound is preserved along\neach step of the construction. We show in `MeasurableSpace.generateMeasurable_eq_rec` that this\nindeed generates this sigma-algebra.\n-/\n\n\nuniverse u\n\nvariable {\u03b1 : Type u}\n\nopen Cardinal Set\n\n-- porting note: fix universe below, not here\nlocal notation \"\u03c9\u2081\" => (WellOrder.\u03b1 <| Quotient.out <| Cardinal.ord (aleph 1 : Cardinal))\n\nnamespace MeasurableSpace\n\n/-- Transfinite induction construction of the sigma-algebra generated by a set of sets `s`. At each\nstep, we add all elements of `s`, the empty set, the complements of already constructed sets, and\ncountable unions of already constructed sets. We index this construction by an ordinal `< \u03c9\u2081`, as\nthis will be enough to generate all sets in the sigma-algebra.\n\nThis construction is very similar to that of the Borel hierarchy. -/\ndef generateMeasurableRec (s : Set (Set \u03b1)) : (\u03c9\u2081 : Type u) \u2192 Set (Set \u03b1)\n  | i =>\n    let S := \u22c3 j : Iio i, generateMeasurableRec s (j.1)\n    s \u222a {\u2205} \u222a compl '' S \u222a Set.range fun f : \u2115 \u2192 S => \u22c3 n, (f n).1\n  termination_by generateMeasurableRec s i => i\n  decreasing_by exact j.2\n#align measurable_space.generate_measurable_rec MeasurableSpace.generateMeasurableRec\n\ntheorem self_subset_generateMeasurableRec (s : Set (Set \u03b1)) (i : \u03c9\u2081) :\n    s \u2286 generateMeasurableRec s i := by\n  unfold generateMeasurableRec\n  apply_rules [subset_union_of_subset_left]\n  exact subset_rfl\n#align measurable_space.self_subset_generate_measurable_rec MeasurableSpace.self_subset_generateMeasurableRec\n\ntheorem empty_mem_generateMeasurableRec (s : Set (Set \u03b1)) (i : \u03c9\u2081) :\n    \u2205 \u2208 generateMeasurableRec s i := by\n  unfold generateMeasurableRec\n  exact mem_union_left _ (mem_union_left _ (mem_union_right _ (mem_singleton \u2205)))\n#align measurable_space.empty_mem_generate_measurable_rec MeasurableSpace.empty_mem_generateMeasurableRec\n\ntheorem compl_mem_generateMeasurableRec {s : Set (Set \u03b1)} {i j : \u03c9\u2081} (h : j < i) {t : Set \u03b1}\n    (ht : t \u2208 generateMeasurableRec s j) : t\u1d9c \u2208 generateMeasurableRec s i := by\n  unfold generateMeasurableRec\n  exact mem_union_left _ (mem_union_right _ \u27e8t, mem_union\u1d62.2 \u27e8\u27e8j, h\u27e9, ht\u27e9, rfl\u27e9)\n#align measurable_space.compl_mem_generate_measurable_rec MeasurableSpace.compl_mem_generateMeasurableRec\n\ntheorem union\u1d62_mem_generateMeasurableRec {s : Set (Set \u03b1)} {i : \u03c9\u2081} {f : \u2115 \u2192 Set \u03b1}\n    (hf : \u2200 n, \u2203 j < i, f n \u2208 generateMeasurableRec s j) :\n    (\u22c3 n, f n) \u2208 generateMeasurableRec s i := by\n  unfold generateMeasurableRec\n  exact mem_union_right _ \u27e8fun n => \u27e8f n, let \u27e8j, hj, hf\u27e9 := hf n; mem_union\u1d62.2 \u27e8\u27e8j, hj\u27e9, hf\u27e9\u27e9, rfl\u27e9\n#align measurable_space.Union_mem_generate_measurable_rec MeasurableSpace.union\u1d62_mem_generateMeasurableRec\n\ntheorem generateMeasurableRec_subset (s : Set (Set \u03b1)) {i j : \u03c9\u2081} (h : i \u2264 j) :\n    generateMeasurableRec s i \u2286 generateMeasurableRec s j := fun x hx => by\n  rcases eq_or_lt_of_le h with (rfl | h)\n  \u00b7 exact hx\n  \u00b7 convert union\u1d62_mem_generateMeasurableRec fun _ => \u27e8i, h, hx\u27e9\n    exact (union\u1d62_const x).symm\n#align measurable_space.generate_measurable_rec_subset MeasurableSpace.generateMeasurableRec_subset\n\n/-- At each step of the inductive construction, the cardinality bound `\u2264 (max (#s) 2) ^ \u2135\u2080` holds.\n-/\ntheorem cardinal_generateMeasurableRec_le (s : Set (Set \u03b1)) (i : \u03c9\u2081) :\n    (#generateMeasurableRec s i) \u2264 max (#s) 2 ^ aleph0.{u} := by\n  apply (aleph 1).ord.out.wo.wf.induction i\n  intro i IH\n  have A := aleph0_le_aleph 1\n  have B : aleph 1 \u2264 max (#s) 2 ^ aleph0.{u} :=\n    aleph_one_le_continuum.trans (power_le_power_right (le_max_right _ _))\n  have C : \u2135\u2080 \u2264 max (#s) 2 ^ aleph0.{u} := A.trans B\n  have J : (#\u22c3 j : Iio i, generateMeasurableRec s j.1) \u2264 max (#s) 2 ^ aleph0.{u} := by\n    refine (mk_union\u1d62_le _).trans ?_\n    have D : (\u2a06 j : Iio i, #generateMeasurableRec s j) \u2264 _ := csup\u1d62_le' fun \u27e8j, hj\u27e9 => IH j hj\n    apply (mul_le_mul' ((mk_subtype_le _).trans (aleph 1).mk_ord_out.le) D).trans\n    rw [mul_eq_max A C]\n    exact max_le B le_rfl\n  rw [generateMeasurableRec]\n  apply_rules [(mk_union_le _ _).trans, add_le_of_le C, mk_image_le.trans]\n  \u00b7 exact (le_max_left _ _).trans (self_le_power _ one_lt_aleph0.le)\n  \u00b7 rw [mk_singleton]\n    exact one_lt_aleph0.le.trans C\n  \u00b7 apply mk_range_le.trans\n    simp only [mk_pi, prod_const, lift_uzero, mk_denumerable, lift_aleph0]\n    have := @power_le_power_right _ _ \u2135\u2080 J\n    rwa [\u2190 power_mul, aleph0_mul_aleph0] at this\n#align measurable_space.cardinal_generate_measurable_rec_le MeasurableSpace.cardinal_generateMeasurableRec_le\n\n/-- `generateMeasurableRec s` generates precisely the smallest sigma-algebra containing `s`. -/\ntheorem generateMeasurable_eq_rec (s : Set (Set \u03b1)) :\n    { t | GenerateMeasurable s t } =\n        \u22c3 (i : (Quotient.out (aleph 1).ord).\u03b1), generateMeasurableRec s i := by\n  ext t; refine' \u27e8fun ht => _, fun ht => _\u27e9\n  \u00b7 inhabit \u03c9\u2081\n    induction' ht with u hu u _ IH f _ IH\n    \u00b7 exact mem_union\u1d62.2 \u27e8default, self_subset_generateMeasurableRec s _ hu\u27e9\n    \u00b7 exact mem_union\u1d62.2 \u27e8default, empty_mem_generateMeasurableRec s _\u27e9\n    \u00b7 rcases mem_union\u1d62.1 IH with \u27e8i, hi\u27e9\n      obtain \u27e8j, hj\u27e9 := exists_gt i\n      exact mem_union\u1d62.2 \u27e8j, compl_mem_generateMeasurableRec hj hi\u27e9\n    \u00b7 have : \u2200 n, \u2203 i, f n \u2208 generateMeasurableRec s i := fun n => by simpa using IH n\n      choose I hI using this\n      have : IsWellOrder (\u03c9\u2081 : Type u) (\u00b7 < \u00b7) := isWellOrder_out_lt _\n      refine' mem_union\u1d62.2\n        \u27e8Ordinal.enum (\u00b7 < \u00b7) (Ordinal.lsub fun n => Ordinal.typein.{u} (\u00b7 < \u00b7) (I n)) _,\n          union\u1d62_mem_generateMeasurableRec fun n => \u27e8I n, _, hI n\u27e9\u27e9\n      \u00b7 rw [Ordinal.type_lt]\n        refine' Ordinal.lsub_lt_ord_lift _ fun i => Ordinal.typein_lt_self _\n        rw [mk_denumerable, lift_aleph0, isRegular_aleph_one.cof_eq]\n        exact aleph0_lt_aleph_one\n      \u00b7 rw [\u2190 Ordinal.typein_lt_typein (\u00b7 < \u00b7), Ordinal.typein_enum]\n        apply Ordinal.lt_lsub fun n : \u2115 => _\n  \u00b7 rcases ht with \u27e8t, \u27e8i, rfl\u27e9, hx\u27e9\n    revert t\n    apply (aleph 1).ord.out.wo.wf.induction i\n    intro j H t ht\n    unfold generateMeasurableRec at ht\n    rcases ht with (((h | (rfl : t = \u2205)) | \u27e8u, \u27e8-, \u27e8\u27e8k, hk\u27e9, rfl\u27e9, hu\u27e9, rfl\u27e9) | \u27e8f, rfl\u27e9)\n    \u00b7 exact .basic t h\n    \u00b7 exact .empty\n    \u00b7 exact .compl u (H k hk u hu)\n    \u00b7 refine .union\u1d62 _ @fun n => ?_\n      obtain \u27e8-, \u27e8\u27e8k, hk\u27e9, rfl\u27e9, hf\u27e9 := (f n).prop\n      exact H k hk _ hf\n#align measurable_space.generate_measurable_eq_rec MeasurableSpace.generateMeasurable_eq_rec\n\n/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma-algebra has cardinality at\nmost `(max (#s) 2) ^ \u2135\u2080`. -/\ntheorem cardinal_generateMeasurable_le (s : Set (Set \u03b1)) :\n    (#{ t | GenerateMeasurable s t }) \u2264 max (#s) 2 ^ aleph0.{u} := by\n  rw [generateMeasurable_eq_rec]\n  apply (mk_union\u1d62_le _).trans\n  rw [(aleph 1).mk_ord_out]\n  refine le_trans (mul_le_mul' aleph_one_le_continuum\n      (csup\u1d62_le' fun i => cardinal_generateMeasurableRec_le s i)) ?_\n  refine (mul_le_max_of_aleph0_le_left aleph0_le_continuum).trans (max_le ?_ le_rfl)\n  exact power_le_power_right (le_max_right _ _)\n#align measurable_space.cardinal_generate_measurable_le MeasurableSpace.cardinal_generateMeasurable_le\n\n/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma\nalgebra has cardinality at most `(max (#s) 2) ^ \u2135\u2080`. -/\ntheorem cardinalMeasurableSet_le (s : Set (Set \u03b1)) :\n    (#{ t | @MeasurableSet \u03b1 (generateFrom s) t }) \u2264 max (#s) 2 ^ aleph0.{u} :=\n  cardinal_generateMeasurable_le s\n#align measurable_space.cardinal_measurable_set_le MeasurableSpace.cardinalMeasurableSet_le\n\n/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,\nthen the sigma algebra has the same cardinality bound. -/\ntheorem cardinal_generateMeasurable_le_continuum {s : Set (Set \u03b1)} (hs : (#s) \u2264 \ud835\udd20) :\n    (#{ t | GenerateMeasurable s t }) \u2264 \ud835\udd20 :=\n  (cardinal_generateMeasurable_le s).trans\n    (by\n      rw [\u2190 continuum_power_aleph0]\n      exact_mod_cast power_le_power_right (max_le hs (nat_lt_continuum 2).le))\n#align measurable_space.cardinal_generate_measurable_le_continuum MeasurableSpace.cardinal_generateMeasurable_le_continuum\n\n/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,\nthen the sigma algebra has the same cardinality bound. -/\ntheorem cardinal_measurableSet_le_continuum {s : Set (Set \u03b1)} :\n    (#s) \u2264 \ud835\udd20 \u2192 (#{ t | @MeasurableSet \u03b1 (generateFrom s) t }) \u2264 \ud835\udd20 :=\n  cardinal_generateMeasurable_le_continuum\n#align measurable_space.cardinal_measurable_set_le_continuum MeasurableSpace.cardinal_measurableSet_le_continuum\n\nend MeasurableSpace\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/MeasureTheory/CardMeasurableSpace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.739256792790686}}
{"text": "import number_theory.sum_two_squares\n\n/-!\n# Sums of two squares\n\nThe goal of this project is to prove the following statement.\n\n**Theorem.** Let n be a positive natural number. Then n can be written\nas n = a\u00b2 + b\u00b2 with natural numbers a and b if and only if every prime\nq \u2261 3 mod 4 occurs with an even exponent in the prime factorization of n.\n\nmathlib has *Fermat's two-squares theorem* that says that a prime p \u2261 1 mod 4\nis a sum of two squares.\n\ntheorem nat.prime.sq_add_sq {p : \u2115} [fact (nat.prime p)] (hp : p % 4 = 1) :\n  \u2203 (a b : \u2115), a ^ 2 + b ^ 2 = p\n\nFrom this (and the facts that 2 is a sum of two squares and that the set\nof sums of two squares is multiplicative), the \"if\" direction follows\nfairly easily. For the \"only if\" direction, one has to show the following\n\n**Lemma.** If q \u2261 3 mod 4 is a prime and q divides a\u00b2 + b\u00b2, then q\ndivides a and b (and hence q\u00b2 divides a\u00b2 + b\u00b2).\n\nThere are the following lemmas in mathlib, which might be helpful.\n\ntheorem zmod.exists_sq_eq_neg_one_iff {p : \u2115} [fact (nat.prime p)] :\n  is_square (-1 : zmod p) \u2194 p % 4 \u2260 3\n\ntheorem zmod.mod_four_ne_three_of_sq_eq_neg_sq' {p : \u2115} [fact (nat.prime p)]\n  {x y : zmod p} (hy : y \u2260 0) (hxy : x ^ 2 = -y ^ 2) :\n  p % 4 \u2260 3\n-/\n", "meta": {"author": "MichaelStollBayreuth", "repo": "seminar-bayreuth-2022", "sha": "1e5accbfb6054c8ca4b6d3b192818fdbb90ed841", "save_path": "github-repos/lean/MichaelStollBayreuth-seminar-bayreuth-2022", "path": "github-repos/lean/MichaelStollBayreuth-seminar-bayreuth-2022/seminar-bayreuth-2022-1e5accbfb6054c8ca4b6d3b192818fdbb90ed841/src/sum_of_two_squares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7392567890219396}}
{"text": "/-\nCopyright (c) 2021 Sara D\u00edaz Real. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sara D\u00edaz Real\n-/\nimport algebra.associated\nimport tactic.linarith\nimport tactic.linear_combination\n\n/-!\n# IMO 2001 Q6\nLet $a$, $b$, $c$, $d$ be integers with $a > b > c > d > 0$. Suppose that\n\n$$ a*c + b*d = (a + b - c + d) * (-a + b + c + d). $$\n\nProve that $a*b + c*d$ is not prime.\n\n-/\n\nvariables {a b c d : \u2124}\n\ntheorem imo2001_q6 (hd : 0 < d) (hdc : d < c) (hcb : c < b) (hba : b < a)\n  (h : a*c + b*d = (a + b - c + d) * (-a + b + c + d)) :\n  \u00ac prime (a*b + c*d) :=\nbegin\n  assume h0 : prime (a*b + c*d),\n  have ha : 0 < a, { linarith },\n  have hb : 0 < b, { linarith },\n  have hc : 0 < c, { linarith },\n  -- the key step is to show that `a*c + b*d` divides the product `(a*b + c*d) * (a*d + b*c)`\n  have dvd_mul : a*c + b*d \u2223 (a*b + c*d) * (a*d + b*c),\n  { use b^2 + b*d + d^2,\n    linear_combination b*d*h },\n  -- since `a*b + c*d` is prime (by assumption), it must divide `a*c + b*d` or `a*d + b*c`\n  obtain (h1 : a*b + c*d \u2223 a*c + b*d) | (h2 : a*c + b*d \u2223 a*d + b*c) :=\n    h0.left_dvd_or_dvd_right_of_dvd_mul dvd_mul,\n  -- in both cases, we derive a contradiction\n  { have aux : 0 < a*c + b*d,         { nlinarith only [ha, hb, hc, hd] },\n    have : a*b + c*d \u2264 a*c + b*d,     { from int.le_of_dvd aux h1 },\n    nlinarith only [hba, hcb, hdc, h, this] },\n  { have aux : 0 < a*d + b*c,         { nlinarith only [ha, hb, hc, hd] },\n    have : a*c + b*d \u2264 a*d + b*c,     { from int.le_of_dvd aux h2 },\n    nlinarith only [hba, hdc, h, this] },\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2001_q6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7392567813720227}}
{"text": "-- Versions of max\n\nimport analysis.convex.function\nimport data.real.basic\nimport topology.continuous_on\nimport topology.metric_space.basic\n\nopen set (univ)\nnoncomputable theory\n\n-- max expression as a function on pairs\nnoncomputable def pair_max (p : \u211d \u00d7 \u211d) := max p.fst p.snd \nlemma pair_max_eq (x y : \u211d) : pair_max (x,y) = max x y := rfl\nlemma convex_on_pair_max : convex_on \u211d univ pair_max := begin\n  have e : pair_max = (\u03bb p, p.fst) \u2294 (\u03bb p, p.snd), { funext p, simp [pair_max, sup_eq_max] },\n  rw e, apply convex_on.sup, {\n    use convex_univ, intros, simp,\n  }, {\n    use convex_univ, intros, simp,\n  }\nend\n\n-- The max of the first n+1 elements of a sequence (n+1 to avoid empty sets).\n-- I ran into annoying technicalities due to finset.max', so writing out range_max inductively\nnoncomputable def range_max (s : \u2115 \u2192 \u211d) : \u2115 \u2192 \u211d\n| 0 := s 0\n| (n+1) := max (range_max n) (s (n+1))\n\n@[simp] lemma range_max_zero (s : \u2115 \u2192 \u211d) : range_max s 0 = s 0 := rfl\n@[simp] lemma range_max_succ (s : \u2115 \u2192 \u211d) (n : \u2115) : range_max s n.succ = max (range_max s n) (s n.succ) := by simp [range_max]\nlemma monotone.range_max {s : \u2115 \u2192 \u211d} : monotone (range_max s) := begin\n  intros a b ab,\n  generalize hd : b - a = d,\n  have hd' : b = a + d, { rw \u2190hd, rw add_comm, rw nat.sub_add_cancel ab },\n  rw hd', clear hd hd' ab b,\n  induction d with d h, simp,\n  apply trans h,\n  have e : a + d.succ = (a + d).succ := rfl,\n  simp [e]\nend\nlemma le_range_max_self (s : \u2115 \u2192 \u211d) (n : \u2115) : s n \u2264 range_max s n := begin induction n with n, simp, simp end\nlemma le_range_max (s : \u2115 \u2192 \u211d) {a : \u2115} {n : \u2115} (an : a \u2264 n) : s a \u2264 range_max s n := begin\n  transitivity range_max s a, apply le_range_max_self, apply monotone.range_max an,\nend\nlemma range_max_le_iff (s : \u2115 \u2192 \u211d) (n : \u2115) (x : \u211d) : range_max s n \u2264 x \u2194 \u2200 k, k \u2264 n \u2192 s k \u2264 x := begin\n  induction n with n h, simp, simp, constructor, {\n    intros b k kn, by_cases kn' : k \u2264 n, exact h.mp b.1 k kn',\n    simp at kn',\n    have e : k = n+1, { rw nat.succ_eq_add_one at b kn, linarith },\n    rw e, exact b.2,\n  }, {\n    intro b, use [h.mpr (\u03bb _ kn, b _ (trans kn (nat.le_succ _))), b n.succ (by simp)],\n  },\nend\n\nlemma continuous_on.range_max {A : Type} [topological_space A] {f : \u2115 \u2192 A \u2192 \u211d} {s : set A}\n    (fc : \u2200 n, continuous_on (f n) s) (n : \u2115)\n    : continuous_on (\u03bb x, range_max (\u03bb k, f k x) n) s := begin\n  induction n with n h, simp [fc 0], simp [\u2190pair_max_eq], exact continuous_max.comp_continuous_on (h.prod (fc _)),\nend", "meta": {"author": "girving", "repo": "ray", "sha": "e0c501756e067711e2d3667d4b1d18045d83a313", "save_path": "github-repos/lean/girving-ray", "path": "github-repos/lean/girving-ray/ray-e0c501756e067711e2d3667d4b1d18045d83a313/src/max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7392567743337293}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Heather Macbeth\n-/\nimport analysis.normed.field.unit_ball\nimport analysis.normed_space.basic\n\n/-!\n# Multiplicative actions of/on balls and spheres\n\nLet `E` be a normed vector space over a normed field `\ud835\udd5c`. In this file we define the following\nmultiplicative actions.\n\n- The closed unit ball in `\ud835\udd5c` acts on open balls and closed balls centered at `0` in `E`.\n- The unit sphere in `\ud835\udd5c` acts on open balls, closed balls, and spheres centered at `0` in `E`.\n-/\nopen metric set\nvariables {\ud835\udd5c E : Type*} [normed_field \ud835\udd5c] [semi_normed_group E] [normed_space \ud835\udd5c E] {r : \u211d}\n\nsection closed_ball\n\ninstance mul_action_closed_ball_ball : mul_action (closed_ball (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n{ smul := \u03bb c x, \u27e8(c : \ud835\udd5c) \u2022 x, mem_ball_zero_iff.2 $\n    by simpa only [norm_smul, one_mul]\n      using mul_lt_mul' (mem_closed_ball_zero_iff.1 c.2) (mem_ball_zero_iff.1 x.2)\n        (norm_nonneg _) one_pos\u27e9,\n  one_smul := \u03bb x, subtype.ext $ one_smul \ud835\udd5c _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_closed_ball_ball :\n  has_continuous_smul (closed_ball (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n\u27e8continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul\n  (continuous_subtype_val.comp continuous_snd)\u27e9\n\ninstance mul_action_closed_ball_closed_ball :\n  mul_action (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n{ smul := \u03bb c x, \u27e8(c : \ud835\udd5c) \u2022 x, mem_closed_ball_zero_iff.2 $\n    by simpa only [norm_smul, one_mul]\n      using mul_le_mul (mem_closed_ball_zero_iff.1 c.2) (mem_closed_ball_zero_iff.1 x.2)\n        (norm_nonneg _) zero_le_one\u27e9,\n  one_smul := \u03bb x, subtype.ext $ one_smul \ud835\udd5c _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_closed_ball_closed_ball :\n  has_continuous_smul (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n\u27e8continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul\n  (continuous_subtype_val.comp continuous_snd)\u27e9\n\nend closed_ball\n\nsection sphere\n\ninstance mul_action_sphere_ball : mul_action (sphere (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n{ smul := \u03bb c x, inclusion sphere_subset_closed_ball c \u2022 x,\n  one_smul := \u03bb x, subtype.ext $ one_smul _ _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_sphere_ball :\n  has_continuous_smul (sphere (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n\u27e8continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul\n  (continuous_subtype_val.comp continuous_snd)\u27e9\n\ninstance mul_action_sphere_closed_ball : mul_action (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n{ smul := \u03bb c x, inclusion sphere_subset_closed_ball c \u2022 x,\n  one_smul := \u03bb x, subtype.ext $ one_smul _ _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_sphere_closed_ball :\n  has_continuous_smul (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n\u27e8continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul\n  (continuous_subtype_val.comp continuous_snd)\u27e9\n\ninstance mul_action_sphere_sphere : mul_action (sphere (0 : \ud835\udd5c) 1) (sphere (0 : E) r) :=\n{ smul := \u03bb c x, \u27e8(c : \ud835\udd5c) \u2022 x, mem_sphere_zero_iff_norm.2 $\n    by rw [norm_smul, mem_sphere_zero_iff_norm.1 c.coe_prop, mem_sphere_zero_iff_norm.1 x.coe_prop,\n      one_mul]\u27e9,\n  one_smul := \u03bb x, subtype.ext $ one_smul _ _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_sphere_sphere :\n  has_continuous_smul (sphere (0 : \ud835\udd5c) 1) (sphere (0 : E) r) :=\n\u27e8continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul\n  (continuous_subtype_val.comp continuous_snd)\u27e9\n\nend sphere\n\nvariables (\ud835\udd5c) [char_zero \ud835\udd5c]\n\nlemma ne_neg_of_mem_sphere {r : \u211d} (hr : r \u2260 0) (x : sphere (0:E) r) : x \u2260 - x :=\n\u03bb h, ne_zero_of_mem_sphere hr x ((self_eq_neg \ud835\udd5c _).mp (by { conv_lhs {rw h}, simp }))\n\nlemma ne_neg_of_mem_unit_sphere (x : sphere (0:E) 1) : x \u2260 - x :=\nne_neg_of_mem_sphere \ud835\udd5c one_ne_zero x\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/normed_space/ball_action.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7392478214525708}}
{"text": "/-\nCopyright (c) 2021 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n-/\nprelude\nimport Init.Data.Nat.Div\n\nnamespace Nat\n\nprivate def gcdF (x : Nat) : (\u2200 x\u2081, x\u2081 < x \u2192 Nat \u2192 Nat) \u2192 Nat \u2192 Nat :=\n  match x with\n  | 0      => fun _ y => y\n  | succ x => fun f y => f (y % succ x) (mod_lt _ (zero_lt_succ  _)) (succ x)\n\n@[extern \"lean_nat_gcd\"]\ndef gcd (a b : @& Nat) : Nat :=\n  WellFounded.fix (measure id).wf gcdF a b\n\n@[simp] theorem gcd_zero_left (y : Nat) : gcd 0 y = y :=\n  rfl\n\ntheorem gcd_succ (x y : Nat) : gcd (succ x) y = gcd (y % succ x) (succ x) :=\n  rfl\n\n@[simp] theorem gcd_one_left (n : Nat) : gcd 1 n = 1 := by\n  rw [gcd_succ, mod_one]\n  rfl\n\n@[simp] theorem gcd_zero_right (n : Nat) : gcd n 0 = n := by\n  cases n with\n  | zero => simp [gcd_succ]\n  | succ n =>\n    -- `simp [gcd_succ]` produces an invalid term unless `gcd_succ` is proved with `id rfl` instead\n    rw [gcd_succ]\n    exact gcd_zero_left _\n\n@[simp] theorem gcd_self (n : Nat) : gcd n n = n := by\n  cases n <;> simp [gcd_succ]\n\nend Nat\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/src/Init/Data/Nat/Gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7392478187025133}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n\n! This file was ported from Lean 3 source module group_theory.index\n! leanprover-community/mathlib commit dc6c365e751e34d100e80fe6e314c3c3e0fd2988\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finite.Card\nimport Mathlib.GroupTheory.Finiteness\nimport Mathlib.GroupTheory.GroupAction.Quotient\n\n/-!\n# Index of a Subgroup\n\nIn this file we define the index of a subgroup, and prove several divisibility properties.\nSeveral theorems proved in this file are known as Lagrange's theorem.\n\n## Main definitions\n\n- `H.index` : the index of `H : Subgroup G` as a natural number,\n  and returns 0 if the index is infinite.\n- `H.relindex K` : the relative index of `H : Subgroup G` in `K : Subgroup G` as a natural number,\n  and returns 0 if the relative index is infinite.\n\n# Main results\n\n- `card_mul_index` : `Nat.card H * H.index = Nat.card G`\n- `index_mul_card` : `H.index * Fintype.card H = Fintype.card G`\n- `index_dvd_card` : `H.index \u2223 Fintype.card G`\n- `index_eq_mul_of_le` : If `H \u2264 K`, then `H.index = K.index * (H.subgroupOf K).index`\n- `index_dvd_of_le` : If `H \u2264 K`, then `K.index \u2223 H.index`\n- `relindex_mul_relindex` : `relindex` is multiplicative in towers\n\n-/\n\n\nnamespace Subgroup\n\nopen BigOperators Cardinal\n\nvariable {G : Type _} [Group G] (H K L : Subgroup G)\n\n/-- The index of a subgroup as a natural number, and returns 0 if the index is infinite. -/\n@[to_additive \"The index of a subgroup as a natural number,\nand returns 0 if the index is infinite.\"]\nnoncomputable def index : \u2115 :=\n  Nat.card (G \u29f8 H)\n#align subgroup.index Subgroup.index\n#align add_subgroup.index AddSubgroup.index\n\n/-- The relative index of a subgroup as a natural number,\n  and returns 0 if the relative index is infinite. -/\n@[to_additive \"The relative index of a subgroup as a natural number,\nand returns 0 if the relative index is infinite.\"]\nnoncomputable def relindex : \u2115 :=\n  (H.subgroupOf K).index\n#align subgroup.relindex Subgroup.relindex\n#align add_subgroup.relindex AddSubgroup.relindex\n\n@[to_additive]\ntheorem index_comap_of_surjective {G' : Type _} [Group G'] {f : G' \u2192* G}\n    (hf : Function.Surjective f) : (H.comap f).index = H.index := by\n  letI := QuotientGroup.leftRel H\n  letI := QuotientGroup.leftRel (H.comap f)\n  have key : \u2200 x y : G', Setoid.r x y \u2194 Setoid.r (f x) (f y) :=\n    by\n    simp only [QuotientGroup.leftRel_apply]\n    exact fun x y => iff_of_eq (congr_arg (\u00b7 \u2208 H) (by rw [f.map_mul, f.map_inv]))\n  refine' Cardinal.toNat_congr (Equiv.ofBijective (Quotient.map' f fun x y => (key x y).mp) \u27e8_, _\u27e9)\n  \u00b7 simp_rw [\u2190 Quotient.eq''] at key\n    refine' Quotient.ind' fun x => _\n    refine' Quotient.ind' fun y => _\n    exact (key x y).mpr\n  \u00b7 refine' Quotient.ind' fun x => _\n    obtain \u27e8y, hy\u27e9 := hf x\n    exact \u27e8y, (Quotient.map'_mk'' f _ y).trans (congr_arg Quotient.mk'' hy)\u27e9\n#align subgroup.index_comap_of_surjective Subgroup.index_comap_of_surjective\n#align add_subgroup.index_comap_of_surjective AddSubgroup.index_comap_of_surjective\n\n@[to_additive]\ntheorem index_comap {G' : Type _} [Group G'] (f : G' \u2192* G) :\n    (H.comap f).index = H.relindex f.range :=\n  Eq.trans (congr_arg index (by rfl))\n    ((H.subgroupOf f.range).index_comap_of_surjective f.rangeRestrict_surjective)\n#align subgroup.index_comap Subgroup.index_comap\n#align add_subgroup.index_comap AddSubgroup.index_comap\n\n@[to_additive]\ntheorem relindex_comap {G' : Type _} [Group G'] (f : G' \u2192* G) (K : Subgroup G') :\n    relindex (comap f H) K = relindex H (map f K) := by\n  rw [relindex, subgroupOf, comap_comap, index_comap, \u2190 f.map_range, K.subtype_range]\n#align subgroup.relindex_comap Subgroup.relindex_comap\n#align add_subgroup.relindex_comap AddSubgroup.relindex_comap\n\nvariable {H K L}\n\n@[to_additive relindex_mul_index]\ntheorem relindex_mul_index (h : H \u2264 K) : H.relindex K * K.index = H.index :=\n  ((mul_comm _ _).trans (Cardinal.toNat_mul _ _).symm).trans\n    (congr_arg Cardinal.toNat (Equiv.cardinal_eq (quotientEquivProdOfLe h))).symm\n#align subgroup.relindex_mul_index Subgroup.relindex_mul_index\n#align add_subgroup.relindex_mul_index AddSubgroup.relindex_mul_index\n\n@[to_additive]\ntheorem index_dvd_of_le (h : H \u2264 K) : K.index \u2223 H.index :=\n  dvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h)\n#align subgroup.index_dvd_of_le Subgroup.index_dvd_of_le\n#align add_subgroup.index_dvd_of_le AddSubgroup.index_dvd_of_le\n\n@[to_additive]\ntheorem relindex_dvd_index_of_le (h : H \u2264 K) : H.relindex K \u2223 H.index :=\n  dvd_of_mul_right_eq K.index (relindex_mul_index h)\n#align subgroup.relindex_dvd_index_of_le Subgroup.relindex_dvd_index_of_le\n#align add_subgroup.relindex_dvd_index_of_le AddSubgroup.relindex_dvd_index_of_le\n\n@[to_additive]\ntheorem relindex_subgroupOf (hKL : K \u2264 L) :\n    (H.subgroupOf L).relindex (K.subgroupOf L) = H.relindex K :=\n  ((index_comap (H.subgroupOf L) (inclusion hKL)).trans (congr_arg _ (inclusion_range hKL))).symm\n#align subgroup.relindex_subgroup_of Subgroup.relindex_subgroupOf\n#align add_subgroup.relindex_add_subgroup_of AddSubgroup.relindex_addSubgroupOf\n\nvariable (H K L)\n\n@[to_additive relindex_mul_relindex]\ntheorem relindex_mul_relindex (hHK : H \u2264 K) (hKL : K \u2264 L) :\n    H.relindex K * K.relindex L = H.relindex L := by\n  rw [\u2190 relindex_subgroupOf hKL]\n  exact relindex_mul_index fun x hx => hHK hx\n#align subgroup.relindex_mul_relindex Subgroup.relindex_mul_relindex\n#align add_subgroup.relindex_mul_relindex AddSubgroup.relindex_mul_relindex\n\n@[to_additive]\ntheorem inf_relindex_right : (H \u2293 K).relindex K = H.relindex K := by\n  rw [relindex, relindex, inf_subgroupOf_right]\n#align subgroup.inf_relindex_right Subgroup.inf_relindex_right\n#align add_subgroup.inf_relindex_right AddSubgroup.inf_relindex_right\n\n@[to_additive]\ntheorem inf_relindex_left : (H \u2293 K).relindex H = K.relindex H := by\n  rw [inf_comm, inf_relindex_right]\n#align subgroup.inf_relindex_left Subgroup.inf_relindex_left\n#align add_subgroup.inf_relindex_left AddSubgroup.inf_relindex_left\n\n@[to_additive relindex_inf_mul_relindex]\ntheorem relindex_inf_mul_relindex : H.relindex (K \u2293 L) * K.relindex L = (H \u2293 K).relindex L := by\n  rw [\u2190 inf_relindex_right H (K \u2293 L), \u2190 inf_relindex_right K L, \u2190 inf_relindex_right (H \u2293 K) L,\n    inf_assoc, relindex_mul_relindex (H \u2293 (K \u2293 L)) (K \u2293 L) L inf_le_right inf_le_right]\n#align subgroup.relindex_inf_mul_relindex Subgroup.relindex_inf_mul_relindex\n#align add_subgroup.relindex_inf_mul_relindex AddSubgroup.relindex_inf_mul_relindex\n\n@[to_additive (attr := simp)]\ntheorem relindex_sup_right [K.Normal] : K.relindex (H \u2294 K) = K.relindex H :=\n  Nat.card_congr (QuotientGroup.quotientInfEquivProdNormalQuotient H K).toEquiv.symm\n#align subgroup.relindex_sup_right Subgroup.relindex_sup_right\n#align add_subgroup.relindex_sup_right AddSubgroup.relindex_sup_right\n\n@[to_additive (attr := simp)]\ntheorem relindex_sup_left [K.Normal] : K.relindex (K \u2294 H) = K.relindex H := by\n  rw [sup_comm, relindex_sup_right]\n#align subgroup.relindex_sup_left Subgroup.relindex_sup_left\n#align add_subgroup.relindex_sup_left AddSubgroup.relindex_sup_left\n\n@[to_additive]\ntheorem relindex_dvd_index_of_normal [H.Normal] : H.relindex K \u2223 H.index :=\n  relindex_sup_right K H \u25b8 relindex_dvd_index_of_le le_sup_right\n#align subgroup.relindex_dvd_index_of_normal Subgroup.relindex_dvd_index_of_normal\n#align add_subgroup.relindex_dvd_index_of_normal AddSubgroup.relindex_dvd_index_of_normal\n\nvariable {H K}\n\n@[to_additive]\ntheorem relindex_dvd_of_le_left (hHK : H \u2264 K) : K.relindex L \u2223 H.relindex L :=\n  inf_of_le_left hHK \u25b8 dvd_of_mul_left_eq _ (relindex_inf_mul_relindex _ _ _)\n#align subgroup.relindex_dvd_of_le_left Subgroup.relindex_dvd_of_le_left\n#align add_subgroup.relindex_dvd_of_le_left AddSubgroup.relindex_dvd_of_le_left\n\n/-- A subgroup has index two if and only if there exists `a` such that for all `b`, exactly one\nof `b * a` and `b` belong to `H`. -/\n@[to_additive \"An additive subgroup has index two if and only if there exists `a` such that\nfor all `b`, exactly one of `b + a` and `b` belong to `H`.\"]\ntheorem index_eq_two_iff : H.index = 2 \u2194 \u2203 a, \u2200 b, Xor' (b * a \u2208 H) (b \u2208 H) := by\n  simp only [index, Nat.card_eq_two_iff' ((1 : G) : G \u29f8 H), ExistsUnique, inv_mem_iff,\n    QuotientGroup.exists_mk, QuotientGroup.forall_mk, Ne.def, QuotientGroup.eq, mul_one,\n    xor_iff_iff_not]\n  refine'\n    exists_congr fun a => \u27e8fun ha b => \u27e8fun hba hb => _, fun hb => _\u27e9, fun ha => \u27e8_, fun b hb => _\u27e9\u27e9\n  \u00b7 exact ha.1 ((mul_mem_cancel_left hb).1 hba)\n  \u00b7 exact inv_inv b \u25b8 ha.2 _ (mt (inv_mem_iff (x := b)).1 hb)\n  \u00b7 rw [\u2190 inv_mem_iff (x := a), \u2190 ha, inv_mul_self]\n    exact one_mem _\n  \u00b7 rwa [ha, inv_mem_iff (x := b)]\n#align subgroup.index_eq_two_iff Subgroup.index_eq_two_iff\n#align add_subgroup.index_eq_two_iff AddSubgroup.index_eq_two_iff\n\n@[to_additive]\ntheorem mul_mem_iff_of_index_two (h : H.index = 2) {a b : G} : a * b \u2208 H \u2194 (a \u2208 H \u2194 b \u2208 H) := by\n  by_cases ha : a \u2208 H; \u00b7 simp only [ha, true_iff_iff, mul_mem_cancel_left ha]\n  by_cases hb : b \u2208 H; \u00b7 simp only [hb, iff_true_iff, mul_mem_cancel_right hb]\n  simp only [ha, hb, iff_self_iff, iff_true_iff]\n  rcases index_eq_two_iff.1 h with \u27e8c, hc\u27e9\n  refine' (hc _).or.resolve_left _\n  rwa [mul_assoc, mul_mem_cancel_right ((hc _).or.resolve_right hb)]\n#align subgroup.mul_mem_iff_of_index_two Subgroup.mul_mem_iff_of_index_two\n#align add_subgroup.add_mem_iff_of_index_two AddSubgroup.add_mem_iff_of_index_two\n\n@[to_additive]\ntheorem mul_self_mem_of_index_two (h : H.index = 2) (a : G) : a * a \u2208 H := by\n  rw [mul_mem_iff_of_index_two h]\n#align subgroup.mul_self_mem_of_index_two Subgroup.mul_self_mem_of_index_two\n#align add_subgroup.add_self_mem_of_index_two AddSubgroup.add_self_mem_of_index_two\n\n@[to_additive two_smul_mem_of_index_two]\ntheorem sq_mem_of_index_two (h : H.index = 2) (a : G) : a ^ 2 \u2208 H :=\n  (pow_two a).symm \u25b8 mul_self_mem_of_index_two h a\n#align subgroup.sq_mem_of_index_two Subgroup.sq_mem_of_index_two\n#align add_subgroup.two_smul_mem_of_index_two AddSubgroup.two_smul_mem_of_index_two\n\nvariable (H K)\n\n--porting note: had to replace `Cardinal.toNat_eq_one_iff_unique` with `Nat.card_eq_one_iff_unique`\n@[to_additive (attr := simp)]\ntheorem index_top : (\u22a4 : Subgroup G).index = 1 :=\n  Nat.card_eq_one_iff_unique.mpr \u27e8QuotientGroup.subsingleton_quotient_top, \u27e81\u27e9\u27e9\n#align subgroup.index_top Subgroup.index_top\n#align add_subgroup.index_top AddSubgroup.index_top\n\n@[to_additive (attr := simp)]\ntheorem index_bot : (\u22a5 : Subgroup G).index = Nat.card G :=\n  Cardinal.toNat_congr QuotientGroup.quotientBot.toEquiv\n#align subgroup.index_bot Subgroup.index_bot\n#align add_subgroup.index_bot AddSubgroup.index_bot\n\n@[to_additive]\ntheorem index_bot_eq_card [Fintype G] : (\u22a5 : Subgroup G).index = Fintype.card G :=\n  index_bot.trans Nat.card_eq_fintype_card\n#align subgroup.index_bot_eq_card Subgroup.index_bot_eq_card\n#align add_subgroup.index_bot_eq_card AddSubgroup.index_bot_eq_card\n\n@[to_additive (attr := simp)]\ntheorem relindex_top_left : (\u22a4 : Subgroup G).relindex H = 1 :=\n  index_top\n#align subgroup.relindex_top_left Subgroup.relindex_top_left\n#align add_subgroup.relindex_top_left AddSubgroup.relindex_top_left\n\n@[to_additive (attr := simp)]\ntheorem relindex_top_right : H.relindex \u22a4 = H.index := by\n  rw [\u2190 relindex_mul_index (show H \u2264 \u22a4 from le_top), index_top, mul_one]\n#align subgroup.relindex_top_right Subgroup.relindex_top_right\n#align add_subgroup.relindex_top_right AddSubgroup.relindex_top_right\n\n@[to_additive (attr := simp)]\ntheorem relindex_bot_left : (\u22a5 : Subgroup G).relindex H = Nat.card H := by\n  rw [relindex, bot_subgroupOf, index_bot]\n#align subgroup.relindex_bot_left Subgroup.relindex_bot_left\n#align add_subgroup.relindex_bot_left AddSubgroup.relindex_bot_left\n\n@[to_additive]\ntheorem relindex_bot_left_eq_card [Fintype H] : (\u22a5 : Subgroup G).relindex H = Fintype.card H :=\n  H.relindex_bot_left.trans Nat.card_eq_fintype_card\n#align subgroup.relindex_bot_left_eq_card Subgroup.relindex_bot_left_eq_card\n#align add_subgroup.relindex_bot_left_eq_card AddSubgroup.relindex_bot_left_eq_card\n\n@[to_additive (attr := simp)]\ntheorem relindex_bot_right : H.relindex \u22a5 = 1 := by rw [relindex, subgroupOf_bot_eq_top, index_top]\n#align subgroup.relindex_bot_right Subgroup.relindex_bot_right\n#align add_subgroup.relindex_bot_right AddSubgroup.relindex_bot_right\n\n@[to_additive (attr := simp)]\ntheorem relindex_self : H.relindex H = 1 := by rw [relindex, subgroupOf_self, index_top]\n#align subgroup.relindex_self Subgroup.relindex_self\n#align add_subgroup.relindex_self AddSubgroup.relindex_self\n\n@[to_additive]\ntheorem index_ker {H} [Group H] (f : G \u2192* H) : f.ker.index = Nat.card (Set.range f) := by\n  rw [\u2190 MonoidHom.comap_bot, index_comap, relindex_bot_left]\n  rfl\n#align subgroup.index_ker Subgroup.index_ker\n#align add_subgroup.index_ker AddSubgroup.index_ker\n\n@[to_additive]\ntheorem relindex_ker {H} [Group H] (f : G \u2192* H) (K : Subgroup G) :\n    f.ker.relindex K = Nat.card (f '' K) := by\n  rw [\u2190 MonoidHom.comap_bot, relindex_comap, relindex_bot_left]\n  rfl\n#align subgroup.relindex_ker Subgroup.relindex_ker\n#align add_subgroup.relindex_ker AddSubgroup.relindex_ker\n\n@[to_additive (attr := simp) card_mul_index]\ntheorem card_mul_index : Nat.card H * H.index = Nat.card G := by\n  rw [\u2190 relindex_bot_left, \u2190 index_bot]\n  exact relindex_mul_index bot_le\n#align subgroup.card_mul_index Subgroup.card_mul_index\n#align add_subgroup.card_mul_index AddSubgroup.card_mul_index\n\n@[to_additive]\ntheorem nat_card_dvd_of_injective {G H : Type _} [Group G] [Group H] (f : G \u2192* H)\n    (hf : Function.Injective f) : Nat.card G \u2223 Nat.card H := by\n  rw [Nat.card_congr (MonoidHom.ofInjective hf).toEquiv]\n  exact Dvd.intro f.range.index f.range.card_mul_index\n#align subgroup.nat_card_dvd_of_injective Subgroup.nat_card_dvd_of_injective\n#align add_subgroup.nat_card_dvd_of_injective AddSubgroup.nat_card_dvd_of_injective\n\n@[to_additive]\ntheorem nat_card_dvd_of_le (hHK : H \u2264 K) : Nat.card H \u2223 Nat.card K :=\n  nat_card_dvd_of_injective (inclusion hHK) (inclusion_injective hHK)\n#align subgroup.nat_card_dvd_of_le Subgroup.nat_card_dvd_of_le\n#align add_subgroup.nat_card_dvd_of_le AddSubgroup.nat_card_dvd_of_le\n\n@[to_additive]\ntheorem nat_card_dvd_of_surjective {G H : Type _} [Group G] [Group H] (f : G \u2192* H)\n    (hf : Function.Surjective f) : Nat.card H \u2223 Nat.card G := by\n  rw [\u2190 Nat.card_congr (QuotientGroup.quotientKerEquivOfSurjective f hf).toEquiv]\n  exact Dvd.intro_left (Nat.card f.ker) f.ker.card_mul_index\n#align subgroup.nat_card_dvd_of_surjective Subgroup.nat_card_dvd_of_surjective\n#align add_subgroup.nat_card_dvd_of_surjective AddSubgroup.nat_card_dvd_of_surjective\n\n@[to_additive]\ntheorem card_dvd_of_surjective {G H : Type _} [Group G] [Group H] [Fintype G] [Fintype H]\n    (f : G \u2192* H) (hf : Function.Surjective f) : Fintype.card H \u2223 Fintype.card G := by\n  simp only [\u2190 Nat.card_eq_fintype_card, nat_card_dvd_of_surjective f hf]\n#align subgroup.card_dvd_of_surjective Subgroup.card_dvd_of_surjective\n#align add_subgroup.card_dvd_of_surjective AddSubgroup.card_dvd_of_surjective\n\n@[to_additive]\ntheorem index_map {G' : Type _} [Group G'] (f : G \u2192* G') :\n    (H.map f).index = (H \u2294 f.ker).index * f.range.index := by\n  rw [\u2190 comap_map_eq, index_comap, relindex_mul_index (H.map_le_range f)]\n#align subgroup.index_map Subgroup.index_map\n#align add_subgroup.index_map AddSubgroup.index_map\n\n@[to_additive]\ntheorem index_map_dvd {G' : Type _} [Group G'] {f : G \u2192* G'} (hf : Function.Surjective f) :\n    (H.map f).index \u2223 H.index := by\n  rw [index_map, f.range_top_of_surjective hf, index_top, mul_one]\n  exact index_dvd_of_le le_sup_left\n#align subgroup.index_map_dvd Subgroup.index_map_dvd\n#align add_subgroup.index_map_dvd AddSubgroup.index_map_dvd\n\n@[to_additive]\ntheorem dvd_index_map {G' : Type _} [Group G'] {f : G \u2192* G'} (hf : f.ker \u2264 H) :\n    H.index \u2223 (H.map f).index := by\n  rw [index_map, sup_of_le_left hf]\n  apply dvd_mul_right\n#align subgroup.dvd_index_map Subgroup.dvd_index_map\n#align add_subgroup.dvd_index_map AddSubgroup.dvd_index_map\n\n@[to_additive]\ntheorem index_map_eq {G' : Type _} [Group G'] {f : G \u2192* G'} (hf1 : Function.Surjective f)\n    (hf2 : f.ker \u2264 H) : (H.map f).index = H.index :=\n  Nat.dvd_antisymm (H.index_map_dvd hf1) (H.dvd_index_map hf2)\n#align subgroup.index_map_eq Subgroup.index_map_eq\n#align add_subgroup.index_map_eq AddSubgroup.index_map_eq\n\n@[to_additive]\ntheorem index_eq_card [Fintype (G \u29f8 H)] : H.index = Fintype.card (G \u29f8 H) :=\n  Nat.card_eq_fintype_card\n#align subgroup.index_eq_card Subgroup.index_eq_card\n#align add_subgroup.index_eq_card AddSubgroup.index_eq_card\n\n@[to_additive index_mul_card]\ntheorem index_mul_card [Fintype G] [hH : Fintype H] : H.index * Fintype.card H = Fintype.card G :=\n  by\n  rw [\u2190 relindex_bot_left_eq_card, \u2190 index_bot_eq_card, mul_comm];\n    exact relindex_mul_index bot_le\n#align subgroup.index_mul_card Subgroup.index_mul_card\n#align add_subgroup.index_mul_card AddSubgroup.index_mul_card\n\n@[to_additive]\ntheorem index_dvd_card [Fintype G] : H.index \u2223 Fintype.card G := by\n  classical exact \u27e8Fintype.card H, H.index_mul_card.symm\u27e9\n#align subgroup.index_dvd_card Subgroup.index_dvd_card\n#align add_subgroup.index_dvd_card AddSubgroup.index_dvd_card\n\nvariable {H K L}\n\n@[to_additive]\ntheorem relindex_eq_zero_of_le_left (hHK : H \u2264 K) (hKL : K.relindex L = 0) : H.relindex L = 0 :=\n  eq_zero_of_zero_dvd (hKL \u25b8 relindex_dvd_of_le_left L hHK)\n#align subgroup.relindex_eq_zero_of_le_left Subgroup.relindex_eq_zero_of_le_left\n#align add_subgroup.relindex_eq_zero_of_le_left AddSubgroup.relindex_eq_zero_of_le_left\n\n@[to_additive]\ntheorem relindex_eq_zero_of_le_right (hKL : K \u2264 L) (hHK : H.relindex K = 0) : H.relindex L = 0 :=\n  Finite.card_eq_zero_of_embedding (quotientSubgroupOfEmbeddingOfLe H hKL) hHK\n#align subgroup.relindex_eq_zero_of_le_right Subgroup.relindex_eq_zero_of_le_right\n#align add_subgroup.relindex_eq_zero_of_le_right AddSubgroup.relindex_eq_zero_of_le_right\n\n@[to_additive]\ntheorem index_eq_zero_of_relindex_eq_zero (h : H.relindex K = 0) : H.index = 0 :=\n  H.relindex_top_right.symm.trans (relindex_eq_zero_of_le_right le_top h)\n#align subgroup.index_eq_zero_of_relindex_eq_zero Subgroup.index_eq_zero_of_relindex_eq_zero\n#align add_subgroup.index_eq_zero_of_relindex_eq_zero AddSubgroup.index_eq_zero_of_relindex_eq_zero\n\n@[to_additive]\ntheorem relindex_le_of_le_left (hHK : H \u2264 K) (hHL : H.relindex L \u2260 0) :\n    K.relindex L \u2264 H.relindex L :=\n  Nat.le_of_dvd (Nat.pos_of_ne_zero hHL) (relindex_dvd_of_le_left L hHK)\n#align subgroup.relindex_le_of_le_left Subgroup.relindex_le_of_le_left\n#align add_subgroup.relindex_le_of_le_left AddSubgroup.relindex_le_of_le_left\n\n@[to_additive]\ntheorem relindex_le_of_le_right (hKL : K \u2264 L) (hHL : H.relindex L \u2260 0) :\n    H.relindex K \u2264 H.relindex L :=\n  Finite.card_le_of_embedding' (quotientSubgroupOfEmbeddingOfLe H hKL) fun h => (hHL h).elim\n#align subgroup.relindex_le_of_le_right Subgroup.relindex_le_of_le_right\n#align add_subgroup.relindex_le_of_le_right AddSubgroup.relindex_le_of_le_right\n\n@[to_additive]\ntheorem relindex_ne_zero_trans (hHK : H.relindex K \u2260 0) (hKL : K.relindex L \u2260 0) :\n    H.relindex L \u2260 0 := fun h =>\n  mul_ne_zero (mt (relindex_eq_zero_of_le_right (show K \u2293 L \u2264 K from inf_le_left)) hHK) hKL\n    ((relindex_inf_mul_relindex H K L).trans (relindex_eq_zero_of_le_left inf_le_left h))\n#align subgroup.relindex_ne_zero_trans Subgroup.relindex_ne_zero_trans\n#align add_subgroup.relindex_ne_zero_trans AddSubgroup.relindex_ne_zero_trans\n\n@[to_additive]\ntheorem relindex_inf_ne_zero (hH : H.relindex L \u2260 0) (hK : K.relindex L \u2260 0) :\n    (H \u2293 K).relindex L \u2260 0 := by\n  replace hH : H.relindex (K \u2293 L) \u2260 0 := mt (relindex_eq_zero_of_le_right inf_le_right) hH\n  rw [\u2190 inf_relindex_right] at hH hK\u22a2\n  rw [inf_assoc]\n  exact relindex_ne_zero_trans hH hK\n#align subgroup.relindex_inf_ne_zero Subgroup.relindex_inf_ne_zero\n#align add_subgroup.relindex_inf_ne_zero AddSubgroup.relindex_inf_ne_zero\n\n@[to_additive]\n\n\n@[to_additive]\ntheorem relindex_inf_le : (H \u2293 K).relindex L \u2264 H.relindex L * K.relindex L := by\n  by_cases h : H.relindex L = 0\n  \u00b7 exact (le_of_eq (relindex_eq_zero_of_le_left inf_le_left h)).trans (zero_le _)\n  rw [\u2190 inf_relindex_right, inf_assoc, \u2190 relindex_mul_relindex _ _ L inf_le_right inf_le_right,\n    inf_relindex_right, inf_relindex_right]\n  exact mul_le_mul_right' (relindex_le_of_le_right inf_le_right h) (K.relindex L)\n#align subgroup.relindex_inf_le Subgroup.relindex_inf_le\n#align add_subgroup.relindex_inf_le AddSubgroup.relindex_inf_le\n\n@[to_additive]\ntheorem index_inf_le : (H \u2293 K).index \u2264 H.index * K.index := by\n  simp_rw [\u2190 relindex_top_right, relindex_inf_le]\n#align subgroup.index_inf_le Subgroup.index_inf_le\n#align add_subgroup.index_inf_le AddSubgroup.index_inf_le\n\n@[to_additive]\ntheorem relindex_inf\u1d62_ne_zero {\u03b9 : Type _} [_h\u03b9 : Finite \u03b9] {f : \u03b9 \u2192 Subgroup G}\n    (hf : \u2200 i, (f i).relindex L \u2260 0) : (\u2a05 i, f i).relindex L \u2260 0 :=\n  haveI := Fintype.ofFinite \u03b9\n  (Finset.prod_ne_zero_iff.mpr fun i _hi => hf i) \u2218\n    Nat.card_pi.symm.trans \u2218\n      Finite.card_eq_zero_of_embedding (quotientInf\u1d62SubgroupOfEmbedding f L)\n#align subgroup.relindex_infi_ne_zero Subgroup.relindex_inf\u1d62_ne_zero\n#align add_subgroup.relindex_infi_ne_zero AddSubgroup.relindex_inf\u1d62_ne_zero\n\n@[to_additive]\ntheorem relindex_inf\u1d62_le {\u03b9 : Type _} [Fintype \u03b9] (f : \u03b9 \u2192 Subgroup G) :\n    (\u2a05 i, f i).relindex L \u2264 \u220f i, (f i).relindex L :=\n  le_of_le_of_eq\n    (Finite.card_le_of_embedding' (quotientInf\u1d62SubgroupOfEmbedding f L) fun h =>\n      let \u27e8i, _hi, h\u27e9 := Finset.prod_eq_zero_iff.mp (Nat.card_pi.symm.trans h)\n      relindex_eq_zero_of_le_left (inf\u1d62_le f i) h)\n    Nat.card_pi\n#align subgroup.relindex_infi_le Subgroup.relindex_inf\u1d62_le\n#align add_subgroup.relindex_infi_le AddSubgroup.relindex_inf\u1d62_le\n\n@[to_additive]\ntheorem index_inf\u1d62_ne_zero {\u03b9 : Type _} [Finite \u03b9] {f : \u03b9 \u2192 Subgroup G}\n    (hf : \u2200 i, (f i).index \u2260 0) : (\u2a05 i, f i).index \u2260 0 := by\n  simp_rw [\u2190 relindex_top_right] at hf\u22a2\n  exact relindex_inf\u1d62_ne_zero hf\n#align subgroup.index_infi_ne_zero Subgroup.index_inf\u1d62_ne_zero\n#align add_subgroup.index_infi_ne_zero AddSubgroup.index_inf\u1d62_ne_zero\n\n@[to_additive]\ntheorem index_inf\u1d62_le {\u03b9 : Type _} [Fintype \u03b9] (f : \u03b9 \u2192 Subgroup G) :\n    (\u2a05 i, f i).index \u2264 \u220f i, (f i).index := by simp_rw [\u2190 relindex_top_right, relindex_inf\u1d62_le]\n#align subgroup.index_infi_le Subgroup.index_inf\u1d62_le\n#align add_subgroup.index_infi_le AddSubgroup.index_inf\u1d62_le\n\n--porting note: had to replace `Cardinal.toNat_eq_one_iff_unique` with `Nat.card_eq_one_iff_unique`\n@[to_additive (attr := simp) index_eq_one]\ntheorem index_eq_one : H.index = 1 \u2194 H = \u22a4 :=\n  \u27e8fun h =>\n    QuotientGroup.subgroup_eq_top_of_subsingleton H (Nat.card_eq_one_iff_unique.mp h).1,\n    fun h => (congr_arg index h).trans index_top\u27e9\n#align subgroup.index_eq_one Subgroup.index_eq_one\n#align add_subgroup.index_eq_one AddSubgroup.index_eq_one\n\n@[to_additive (attr := simp) relindex_eq_one]\ntheorem relindex_eq_one : H.relindex K = 1 \u2194 K \u2264 H :=\n  index_eq_one.trans subgroupOf_eq_top\n#align subgroup.relindex_eq_one Subgroup.relindex_eq_one\n#align add_subgroup.relindex_eq_one AddSubgroup.relindex_eq_one\n\n@[to_additive (attr := simp) card_eq_one]\ntheorem card_eq_one : Nat.card H = 1 \u2194 H = \u22a5 :=\n  H.relindex_bot_left \u25b8 relindex_eq_one.trans le_bot_iff\n#align subgroup.card_eq_one Subgroup.card_eq_one\n#align add_subgroup.card_eq_one AddSubgroup.card_eq_one\n\n@[to_additive]\ntheorem index_ne_zero_of_finite [hH : Finite (G \u29f8 H)] : H.index \u2260 0 := by\n  cases nonempty_fintype (G \u29f8 H)\n  rw [index_eq_card]\n  exact Fintype.card_ne_zero\n#align subgroup.index_ne_zero_of_finite Subgroup.index_ne_zero_of_finite\n#align add_subgroup.index_ne_zero_of_finite AddSubgroup.index_ne_zero_of_finite\n\n--porting note: changed due to error with `Cardinal.toNat_apply_of_aleph0_le`\n/-- Finite index implies finite quotient. -/\n@[to_additive \"Finite index implies finite quotient.\"]\nnoncomputable def fintypeOfIndexNeZero (hH : H.index \u2260 0) : Fintype (G \u29f8 H) :=\n  @Fintype.ofFinite _ (Nat.finite_of_card_ne_zero hH)\n#align subgroup.fintype_of_index_ne_zero Subgroup.fintypeOfIndexNeZero\n#align add_subgroup.fintype_of_index_ne_zero AddSubgroup.fintypeOfIndexNeZero\n\n@[to_additive one_lt_index_of_ne_top]\ntheorem one_lt_index_of_ne_top [Finite (G \u29f8 H)] (hH : H \u2260 \u22a4) : 1 < H.index :=\n  Nat.one_lt_iff_ne_zero_and_ne_one.mpr \u27e8index_ne_zero_of_finite, mt index_eq_one.mp hH\u27e9\n#align subgroup.one_lt_index_of_ne_top Subgroup.one_lt_index_of_ne_top\n#align add_subgroup.one_lt_index_of_ne_top AddSubgroup.one_lt_index_of_ne_top\n\nsection FiniteIndex\n\nvariable (H K)\n\n/-- Typeclass for finite index subgroups. -/\nclass FiniteIndex : Prop where\n  /-- The subgroup has finite index -/\n  finiteIndex : H.index \u2260 0\n#align subgroup.finite_index Subgroup.FiniteIndex\n\n/-- Typeclass for finite index subgroups. -/\nclass _root_.AddSubgroup.FiniteIndex {G : Type _} [AddGroup G] (H : AddSubgroup G) : Prop where\n  /-- The additive subgroup has finite index -/\n  finiteIndex : H.index \u2260 0\n#align add_subgroup.finite_index AddSubgroup.FiniteIndex\n\n/-- A finite index subgroup has finite quotient. -/\n@[to_additive \"A finite index subgroup has finite quotient\"]\nnoncomputable def fintypeQuotientOfFiniteIndex [FiniteIndex H] : Fintype (G \u29f8 H) :=\n  fintypeOfIndexNeZero FiniteIndex.finiteIndex\n#align subgroup.fintype_quotient_of_finite_index Subgroup.fintypeQuotientOfFiniteIndex\n#align add_subgroup.fintype_quotient_of_finite_index AddSubgroup.fintypeQuotientOfFiniteIndex\n\n@[to_additive]\ninstance finite_quotient_of_finiteIndex [FiniteIndex H] : Finite (G \u29f8 H) :=\n  H.fintypeQuotientOfFiniteIndex.finite\n#align subgroup.finite_quotient_of_finite_index Subgroup.finite_quotient_of_finiteIndex\n#align add_subgroup.finite_quotient_of_finite_index AddSubgroup.finite_quotient_of_finiteIndex\n\n@[to_additive]\ntheorem finiteIndex_of_finite_quotient [Finite (G \u29f8 H)] : FiniteIndex H :=\n  \u27e8index_ne_zero_of_finite\u27e9\n#align subgroup.finite_index_of_finite_quotient Subgroup.finiteIndex_of_finite_quotient\n#align add_subgroup.finite_index_of_finite_quotient AddSubgroup.finiteIndex_of_finite_quotient\n\n--porting note: had to manually provide finite instance for quotient when it should be automatic\n@[to_additive]\ninstance (priority := 100) finiteIndex_of_finite [Finite G] : FiniteIndex H :=\n  @finiteIndex_of_finite_quotient _ _ H (Quotient.finite _)\n#align subgroup.finite_index_of_finite Subgroup.finiteIndex_of_finite\n#align add_subgroup.finite_index_of_finite AddSubgroup.finiteIndex_of_finite\n\n@[to_additive]\ninstance : FiniteIndex (\u22a4 : Subgroup G) :=\n  \u27e8ne_of_eq_of_ne index_top one_ne_zero\u27e9\n\n@[to_additive]\ninstance [FiniteIndex H] [FiniteIndex K] : FiniteIndex (H \u2293 K) :=\n  \u27e8index_inf_ne_zero FiniteIndex.finiteIndex FiniteIndex.finiteIndex\u27e9\n\nvariable {H K}\n\n@[to_additive]\ntheorem finiteIndex_of_le [FiniteIndex H] (h : H \u2264 K) : FiniteIndex K :=\n  \u27e8ne_zero_of_dvd_ne_zero FiniteIndex.finiteIndex (index_dvd_of_le h)\u27e9\n#align subgroup.finite_index_of_le Subgroup.finiteIndex_of_le\n#align add_subgroup.finite_index_of_le AddSubgroup.finiteIndex_of_le\n\nvariable (H K)\n\n@[to_additive]\ninstance finiteIndex_ker {G' : Type _} [Group G'] (f : G \u2192* G') [Finite f.range] :\n    f.ker.FiniteIndex :=\n  @finiteIndex_of_finite_quotient G _ f.ker\n    (Finite.of_equiv f.range (QuotientGroup.quotientKerEquivRange f).symm)\n#align subgroup.finite_index_ker Subgroup.finiteIndex_ker\n#align add_subgroup.finite_index_ker AddSubgroup.finiteIndex_ker\n\ninstance finiteIndex_normalCore [H.FiniteIndex] : H.normalCore.FiniteIndex := by\n  rw [normalCore_eq_ker]\n  infer_instance\n#align subgroup.finite_index_normal_core Subgroup.finiteIndex_normalCore\n\nvariable (G)\n\ninstance finiteIndex_center [Finite (commutatorSet G)] [Group.Fg G] : FiniteIndex (center G) := by\n  obtain \u27e8S, -, hS\u27e9 := Group.rank_spec G\n  exact \u27e8mt (Finite.card_eq_zero_of_embedding (quotientCenterEmbedding hS)) Finite.card_pos.ne'\u27e9\n#align subgroup.finite_index_center Subgroup.finiteIndex_center\n\ntheorem index_center_le_pow [Finite (commutatorSet G)] [Group.Fg G] :\n    (center G).index \u2264 Nat.card (commutatorSet G) ^ Group.rank G := by\n  obtain \u27e8S, hS1, hS2\u27e9 := Group.rank_spec G\n  rw [\u2190 hS1, \u2190 Fintype.card_coe, \u2190 Nat.card_eq_fintype_card, \u2190 Finset.coe_sort_coe, \u2190 Nat.card_fun]\n  exact Finite.card_le_of_embedding (quotientCenterEmbedding hS2)\n#align subgroup.index_center_le_pow Subgroup.index_center_le_pow\n\nend FiniteIndex\n\nend Subgroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/Index.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7392478108677034}}
{"text": "import tactic\nopen_locale big_operators\nopen finset\n\n#check mul_add\n#check sum_range_succ\n#check nat.succ_eq_add_one\n\ntheorem sum_id (n : \u2115) : \u2211 i in range (n + 1), i = n * (n + 1) / 2 :=\nbegin\n  symmetry, \n  apply nat.div_eq_of_eq_mul_right (by norm_num : 0 < 2),\n  induction n with n ih,\n   { simp },\n  rw [finset.sum_range_succ, mul_add 2, \u2190ih, nat.succ_eq_add_one],\n  ring,\nend\n\nexample (n : \u2115) : 2 * \u2211 j in range (n + 1), j = n * (n + 1) :=\nbegin\n  induction n with k h,\n  { simp },\n  { rw sum_range_succ,\n    rw mul_add,\n    rw h,\n    rw nat.succ_eq_add_one,\n    ring },\nend\n", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/10_Induction/ex4_induction_triangle_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7391771803193168}}
{"text": "/-\nCopyright (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\nExamples from the tutorial.\n-/\nimport tactic.finish\nopen auto\n\nsection\nvariables p q r s : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := by finish\nexample : p \u2228 q \u2194 q \u2228 p := by finish\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := by finish\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := by finish\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by finish [iff_def]\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := by finish [iff_def]\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := by finish [iff_def]\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := by finish [iff_def]\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := by finish\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := by finish\nexample : \u00ac(p \u2227 \u00ac p) := by finish\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := by finish\nexample : \u00acp \u2192 (p \u2192 q) := by finish\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := by finish\nexample : p \u2228 false \u2194 p := by finish\nexample : p \u2227 false \u2194 false := by finish\nexample : \u00ac(p \u2194 \u00acp) := by finish\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := by finish\n\n-- these require classical reasoning\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := by finish\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := by finish\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := by finish\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := by finish\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := by finish\nexample : p \u2228 \u00acp := by finish\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := by finish\nend\n\n\nsection\n\nvariables (A : Type) (p q : A \u2192 Prop)\nvariable a : A\nvariable r : Prop\n\nexample : (\u2203 x : A, r) \u2192 r := by finish\n-- TODO(Jeremy): can we get these automatically?\nexample (a : A) : r \u2192 (\u2203 x : A, r) := begin safe; apply_assumption; assumption end\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := by finish\n\ntheorem foo': (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\nby finish [iff_def]\n\nexample (h : \u2200 x, \u00ac \u00ac p x) : p a := by finish\nexample (h : \u2200 x, \u00ac \u00ac p x) : \u2200 x, p x := by finish\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := by finish\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := by finish\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) := by finish\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := by finish\nexample : (\u2203 x, \u00ac p x) \u2192 (\u00ac \u2200 x, p x) := by finish\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := by finish [iff_def]\n-- TODO(Jeremy): can we get these automatically?\nexample (a : A) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := begin safe [iff_def]; exact h a end\nexample (a : A) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := begin safe [iff_def]; exact h a end\n\nexample : (\u2203 x, p x \u2192 r) \u2192 (\u2200 x, p x) \u2192 r := by finish\nexample : (\u2203 x, r \u2192 p x) \u2192 (r \u2192 \u2203 x, p x) := by finish\n\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/test/finish3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7391392007208014}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport algebra.big_operators.order\nimport data.nat.interval\nimport data.nat.prime\n\n/-!\n# Divisor finsets\n\nThis file defines sets of divisors of a natural number. This is particularly useful as background\nfor defining Dirichlet convolution.\n\n## Main Definitions\nLet `n : \u2115`. All of the following definitions are in the `nat` namespace:\n * `divisors n` is the `finset` of natural numbers that divide `n`.\n * `proper_divisors n` is the `finset` of natural numbers that divide `n`, other than `n`.\n * `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n * `perfect n` is true when `n` is positive and the sum of `proper_divisors n` is `n`.\n\n## Implementation details\n * `divisors 0`, `proper_divisors 0`, and `divisors_antidiagonal 0` are defined to be `\u2205`.\n\n## Tags\ndivisors, perfect numbers\n\n-/\n\nopen_locale classical\nopen_locale big_operators\nopen finset\n\nnamespace nat\nvariable (n : \u2115)\n\n/-- `divisors n` is the `finset` of divisors of `n`. As a special case, `divisors 0 = \u2205`. -/\ndef divisors : finset \u2115 := finset.filter (\u03bb x : \u2115, x \u2223 n) (finset.Ico 1 (n + 1))\n\n/-- `proper_divisors n` is the `finset` of divisors of `n`, other than `n`.\n  As a special case, `proper_divisors 0 = \u2205`. -/\ndef proper_divisors : finset \u2115 := finset.filter (\u03bb x : \u2115, x \u2223 n) (finset.Ico 1 n)\n\n/-- `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n  As a special case, `divisors_antidiagonal 0 = \u2205`. -/\ndef divisors_antidiagonal : finset (\u2115 \u00d7 \u2115) :=\n((finset.Ico 1 (n + 1)).product (finset.Ico 1 (n + 1))).filter (\u03bb x, x.fst * x.snd = n)\n\nvariable {n}\n\nlemma proper_divisors.not_self_mem : \u00ac n \u2208 proper_divisors n :=\nbegin\n  rw proper_divisors,\n  simp,\nend\n\n@[simp]\nlemma mem_proper_divisors {m : \u2115} : n \u2208 proper_divisors m \u2194 n \u2223 m \u2227 n < m :=\nbegin\n  rw [proper_divisors, finset.mem_filter, finset.mem_Ico, and_comm],\n  apply and_congr_right,\n  rw and_iff_right_iff_imp,\n  intros hdvd hlt,\n  apply nat.pos_of_ne_zero _,\n  rintro rfl,\n  rw zero_dvd_iff.1 hdvd at hlt,\n  apply lt_irrefl 0 hlt,\nend\n\nlemma divisors_eq_proper_divisors_insert_self_of_pos (h : 0 < n):\n  divisors n = has_insert.insert n (proper_divisors n) :=\nby rw [divisors, proper_divisors, Ico_succ_right_eq_insert_Ico h, finset.filter_insert,\n  if_pos (dvd_refl n)]\n\n@[simp]\nlemma mem_divisors {m : \u2115} :\n  n \u2208 divisors m \u2194 (n \u2223 m \u2227 m \u2260 0) :=\nbegin\n  cases m,\n  { simp [divisors] },\n  simp only [divisors, finset.mem_Ico, ne.def, finset.mem_filter, succ_ne_zero, and_true,\n             and_iff_right_iff_imp, not_false_iff],\n  intro hdvd,\n  split,\n  { apply nat.pos_of_ne_zero,\n    rintro rfl,\n    apply nat.succ_ne_zero,\n    rwa zero_dvd_iff at hdvd },\n  { rw nat.lt_succ_iff,\n    apply nat.le_of_dvd (nat.succ_pos m) hdvd }\nend\n\nlemma mem_divisors_self (n : \u2115) (h : n \u2260 0) : n \u2208 n.divisors := mem_divisors.2 \u27e8dvd_rfl, h\u27e9\n\nlemma dvd_of_mem_divisors {m : \u2115} (h : n \u2208 divisors m) : n \u2223 m :=\nbegin\n  cases m,\n  { apply dvd_zero },\n  { simp [mem_divisors.1 h], }\nend\n\n@[simp]\nlemma mem_divisors_antidiagonal {x : \u2115 \u00d7 \u2115} :\n  x \u2208 divisors_antidiagonal n \u2194 x.fst * x.snd = n \u2227 n \u2260 0 :=\nbegin\n  simp only [divisors_antidiagonal, finset.mem_Ico, ne.def, finset.mem_filter, finset.mem_product],\n  rw and_comm,\n  apply and_congr_right,\n  rintro rfl,\n  split; intro h,\n  { contrapose! h, simp [h], },\n  { rw [nat.lt_add_one_iff, nat.lt_add_one_iff],\n    rw [mul_eq_zero, decidable.not_or_iff_and_not] at h,\n    simp only [succ_le_of_lt (nat.pos_of_ne_zero h.1), succ_le_of_lt (nat.pos_of_ne_zero h.2),\n               true_and],\n    exact \u27e8le_mul_of_pos_right (nat.pos_of_ne_zero h.2),\n      le_mul_of_pos_left (nat.pos_of_ne_zero h.1)\u27e9 }\nend\n\nvariable {n}\n\nlemma divisor_le {m : \u2115}:\nn \u2208 divisors m \u2192 n \u2264 m :=\nbegin\n  cases m,\n  { simp },\n  simp only [mem_divisors, m.succ_ne_zero, and_true, ne.def, not_false_iff],\n  exact nat.le_of_dvd (nat.succ_pos m),\nend\n\nlemma divisors_subset_of_dvd {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) : divisors m \u2286 divisors n :=\nfinset.subset_iff.2 $ \u03bb x hx, nat.mem_divisors.mpr (\u27e8(nat.mem_divisors.mp hx).1.trans h, hzero\u27e9)\n\nlemma divisors_subset_proper_divisors {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) (hdiff : m \u2260 n) :\n  divisors m \u2286 proper_divisors n :=\nbegin\n  apply finset.subset_iff.2,\n  intros x hx,\n  exact nat.mem_proper_divisors.2 (\u27e8(nat.mem_divisors.1 hx).1.trans h,\n    lt_of_le_of_lt (divisor_le hx) (lt_of_le_of_ne (divisor_le (nat.mem_divisors.2\n    \u27e8h, hzero\u27e9)) hdiff)\u27e9)\nend\n\n@[simp]\nlemma divisors_zero : divisors 0 = \u2205 := by { ext, simp }\n\n@[simp]\nlemma proper_divisors_zero : proper_divisors 0 = \u2205 := by { ext, simp }\n\nlemma proper_divisors_subset_divisors : proper_divisors n \u2286 divisors n :=\nbegin\n  cases n,\n  { simp },\n  rw [divisors_eq_proper_divisors_insert_self_of_pos (nat.succ_pos _)],\n  apply subset_insert,\nend\n\n@[simp]\nlemma divisors_one : divisors 1 = {1} := by { ext, simp }\n\n@[simp]\nlemma proper_divisors_one : proper_divisors 1 = \u2205 :=\nbegin\n  ext,\n  simp only [finset.not_mem_empty, nat.dvd_one, not_and, not_lt, mem_proper_divisors, iff_false],\n  apply ge_of_eq,\nend\n\nlemma pos_of_mem_divisors {m : \u2115} (h : m \u2208 n.divisors) : 0 < m :=\nbegin\n  cases m,\n  { rw [mem_divisors, zero_dvd_iff] at h,\n    rcases h with \u27e8rfl, h\u27e9,\n    exfalso,\n    apply h rfl },\n  apply nat.succ_pos,\nend\n\nlemma pos_of_mem_proper_divisors {m : \u2115} (h : m \u2208 n.proper_divisors) : 0 < m :=\npos_of_mem_divisors (proper_divisors_subset_divisors h)\n\nlemma one_mem_proper_divisors_iff_one_lt :\n  1 \u2208 n.proper_divisors \u2194 1 < n :=\nby rw [mem_proper_divisors, and_iff_right (one_dvd _)]\n\n@[simp]\nlemma divisors_antidiagonal_zero : divisors_antidiagonal 0 = \u2205 := by { ext, simp }\n\n@[simp]\nlemma divisors_antidiagonal_one : divisors_antidiagonal 1 = {(1,1)} :=\nby { ext, simp [nat.mul_eq_one_iff, prod.ext_iff], }\n\nlemma swap_mem_divisors_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n  x.swap \u2208 divisors_antidiagonal n :=\nbegin\n  rw [mem_divisors_antidiagonal, mul_comm] at h,\n  simp [h.1, h.2],\nend\n\n\n\nlemma snd_mem_divisors_of_mem_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n  x.snd \u2208 divisors n :=\nbegin\n  rw mem_divisors_antidiagonal at h,\n  simp [dvd.intro_left _ h.1, h.2],\nend\n\n@[simp]\nlemma map_swap_divisors_antidiagonal :\n  (divisors_antidiagonal n).map \u27e8prod.swap, prod.swap_right_inverse.injective\u27e9\n  = divisors_antidiagonal n :=\nbegin\n  ext,\n  simp only [exists_prop, mem_divisors_antidiagonal, finset.mem_map, function.embedding.coe_fn_mk,\n             ne.def, prod.swap_prod_mk, prod.exists],\n  split,\n  { rintros \u27e8x, y, \u27e8\u27e8rfl, h\u27e9, rfl\u27e9\u27e9,\n    simp [mul_comm, h], },\n  { rintros \u27e8rfl, h\u27e9,\n    use [a.snd, a.fst],\n    rw mul_comm,\n    simp [h] }\nend\n\nlemma sum_divisors_eq_sum_proper_divisors_add_self :\n\u2211 i in divisors n, i = \u2211 i in proper_divisors n, i + n :=\nbegin\n  cases n,\n  { simp },\n  { rw [divisors_eq_proper_divisors_insert_self_of_pos (nat.succ_pos _),\n        finset.sum_insert (proper_divisors.not_self_mem), add_comm] }\nend\n\n/-- `n : \u2115` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`\n  is positive. -/\ndef perfect (n : \u2115) : Prop := (\u2211 i in proper_divisors n, i = n) \u2227 0 < n\n\ntheorem perfect_iff_sum_proper_divisors (h : 0 < n) :\n  perfect n \u2194 \u2211 i in proper_divisors n, i = n := and_iff_left h\n\ntheorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) :\n  perfect n \u2194 \u2211 i in divisors n, i = 2 * n :=\nbegin\n  rw [perfect_iff_sum_proper_divisors h, sum_divisors_eq_sum_proper_divisors_add_self, two_mul],\n  split; intro h,\n  { rw h },\n  { apply add_right_cancel h }\nend\n\nlemma mem_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) {x : \u2115} :\n  x \u2208 divisors (p ^ k) \u2194 \u2203 (j : \u2115) (H : j \u2264 k), x = p ^ j :=\nby rw [mem_divisors, nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))]\n\nlemma prime.divisors {p : \u2115} (pp : p.prime) :\n  divisors p = {1, p} :=\nbegin\n  ext,\n  simp only [pp.ne_zero, and_true, ne.def, not_false_iff, finset.mem_insert,\n    finset.mem_singleton, mem_divisors],\n  refine \u27e8pp.2 a, \u03bb h, _\u27e9,\n  rcases h; subst h,\n  apply one_dvd,\nend\n\nlemma prime.proper_divisors {p : \u2115} (pp : p.prime) :\n  proper_divisors p = {1} :=\nby rw [\u2190 erase_insert (proper_divisors.not_self_mem),\n    \u2190 divisors_eq_proper_divisors_insert_self_of_pos pp.pos,\n    pp.divisors, insert_singleton_comm, erase_insert (\u03bb con, pp.ne_one (mem_singleton.1 con))]\n\nlemma divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) :\n  divisors (p ^ k) = (finset.range (k + 1)).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\nby { ext, simp [mem_divisors_prime_pow, pp, nat.lt_succ_iff, @eq_comm _ a] }\n\nlemma eq_proper_divisors_of_subset_of_sum_eq_sum {s : finset \u2115} (hsub : s \u2286 n.proper_divisors) :\n  \u2211 x in s, x = \u2211 x in n.proper_divisors, x \u2192 s = n.proper_divisors :=\nbegin\n  cases n,\n  { rw [proper_divisors_zero, subset_empty] at hsub,\n    simp [hsub] },\n  classical,\n  rw [\u2190 sum_sdiff hsub],\n  intros h,\n  apply subset.antisymm hsub,\n  rw [\u2190 sdiff_eq_empty_iff_subset],\n  contrapose h,\n  rw [\u2190 ne.def, \u2190 nonempty_iff_ne_empty] at h,\n  apply ne_of_lt,\n  rw [\u2190 zero_add (\u2211 x in s, x), \u2190 add_assoc, add_zero],\n  apply add_lt_add_right,\n  have hlt := sum_lt_sum_of_nonempty h (\u03bb x hx, pos_of_mem_proper_divisors (sdiff_subset _ _ hx)),\n  simp only [sum_const_zero] at hlt,\n  apply hlt\nend\n\nlemma sum_proper_divisors_dvd (h : \u2211 x in n.proper_divisors, x \u2223 n) :\n  (\u2211 x in n.proper_divisors, x = 1) \u2228 (\u2211 x in n.proper_divisors, x = n) :=\nbegin\n  cases n,\n  { simp },\n  cases n,\n  { contrapose! h,\n    simp, },\n  rw or_iff_not_imp_right,\n  intro ne_n,\n  have hlt : \u2211 x in n.succ.succ.proper_divisors, x < n.succ.succ :=\n    lt_of_le_of_ne (nat.le_of_dvd (nat.succ_pos _) h) ne_n,\n  symmetry,\n  rw [\u2190 mem_singleton, eq_proper_divisors_of_subset_of_sum_eq_sum (singleton_subset_iff.2\n        (mem_proper_divisors.2 \u27e8h, hlt\u27e9)) sum_singleton, mem_proper_divisors],\n  refine \u27e8one_dvd _, nat.succ_lt_succ (nat.succ_pos _)\u27e9,\nend\n\n@[simp, to_additive]\nlemma prime.prod_proper_divisors {\u03b1 : Type*} [comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in p.proper_divisors, f x = f 1 :=\nby simp [h.proper_divisors]\n\n@[simp, to_additive]\nlemma prime.prod_divisors {\u03b1 : Type*} [comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in p.divisors, f x = f p * f 1 :=\nby rw [divisors_eq_proper_divisors_insert_self_of_pos h.pos,\n       prod_insert proper_divisors.not_self_mem, h.prod_proper_divisors]\n\nlemma proper_divisors_eq_singleton_one_iff_prime :\n  n.proper_divisors = {1} \u2194 n.prime :=\n\u27e8\u03bb h, begin\n  have h1 := mem_singleton.2 rfl,\n  rw [\u2190 h, mem_proper_divisors] at h1,\n  refine \u27e8h1.2, _\u27e9,\n  intros m hdvd,\n  rw [\u2190 mem_singleton, \u2190 h, mem_proper_divisors],\n  cases lt_or_eq_of_le (nat.le_of_dvd (lt_trans (nat.succ_pos _) h1.2) hdvd),\n  { left,\n    exact \u27e8hdvd, h_1\u27e9 },\n  { right,\n    exact h_1 }\nend, prime.proper_divisors\u27e9\n\nlemma sum_proper_divisors_eq_one_iff_prime :\n  \u2211 x in n.proper_divisors, x = 1 \u2194 n.prime :=\nbegin\n  cases n,\n  { simp [nat.not_prime_zero] },\n  cases n,\n  { simp [nat.not_prime_one] },\n  rw [\u2190 proper_divisors_eq_singleton_one_iff_prime],\n  refine \u27e8\u03bb h, _, \u03bb h, h.symm \u25b8 sum_singleton\u27e9,\n  rw [@eq_comm (finset \u2115) _ _],\n  apply eq_proper_divisors_of_subset_of_sum_eq_sum\n    (singleton_subset_iff.2 (one_mem_proper_divisors_iff_one_lt.2 (succ_lt_succ (nat.succ_pos _))))\n    (eq.trans sum_singleton h.symm)\nend\n\nlemma mem_proper_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) {x : \u2115} :\n  x \u2208 proper_divisors (p ^ k) \u2194 \u2203 (j : \u2115) (H : j < k), x = p ^ j :=\nbegin\n  rw [mem_proper_divisors, nat.dvd_prime_pow pp, \u2190 exists_and_distrib_right],\n  simp only [exists_prop, and_assoc],\n  apply exists_congr,\n  intro a,\n  split; intro h,\n  { rcases h with \u27e8h_left, rfl, h_right\u27e9,\n    rwa pow_lt_pow_iff pp.one_lt at h_right,\n    simpa, },\n  { rcases h with \u27e8h_left, rfl\u27e9,\n    rwa pow_lt_pow_iff pp.one_lt,\n    simp [h_left, le_of_lt], },\nend\n\nlemma proper_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) :\n  proper_divisors (p ^ k) = (finset.range k).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\nby { ext, simp [mem_proper_divisors_prime_pow, pp, nat.lt_succ_iff, @eq_comm _ a], }\n\n@[simp, to_additive]\nlemma prod_proper_divisors_prime_pow {\u03b1 : Type*} [comm_monoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1}\n  (h : p.prime) : \u220f x in (p ^ k).proper_divisors, f x = \u220f x in range k, f (p ^ x) :=\nby simp [h, proper_divisors_prime_pow]\n\n@[simp, to_additive]\nlemma prod_divisors_prime_pow {\u03b1 : Type*} [comm_monoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in (p ^ k).divisors, f x = \u220f x in range (k + 1), f (p ^ x) :=\nby simp [h, divisors_prime_pow]\n\n@[simp]\nlemma filter_dvd_eq_divisors {n : \u2115} (h : n \u2260 0) :\n  finset.filter (\u03bb (x : \u2115), x \u2223 n) (finset.range (n : \u2115).succ) = (n : \u2115).divisors :=\nbegin\n  apply finset.ext,\n  simp only [h, mem_filter, and_true, and_iff_right_iff_imp, cast_id, mem_range, ne.def,\n  not_false_iff, mem_divisors],\n  intros a ha,\n  exact nat.lt_succ_of_le (nat.divisor_le (nat.mem_divisors.2 \u27e8ha, h\u27e9))\nend\n\n/-- The factors of `n` are the prime divisors -/\nlemma prime_divisors_eq_to_filter_divisors_prime (n : \u2115) :\n  n.factors.to_finset = (divisors n).filter prime :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { simp },\n  { ext q,\n    simpa [hn, hn.ne', mem_factors] using and_comm (prime q) (q \u2223 n) }\nend\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7391392005351974}}
{"text": "/-\nCopyright (c) 2018 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nIsometries of emetric and metric spaces\nAuthors: S\u00e9bastien Gou\u00ebzel\nWe define isometries, i.e., maps between emetric spaces that preserve\nthe edistance (on metric spaces, these are exactly the maps that preserve distances),\nand prove their basic properties. We also introduce isometric bijections.\n-/\n\nimport topology.metric_space.basic topology.instances.real\n\nnoncomputable theory\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nopen function set\n\n/-- An isometry (also known as isometric embedding) is a map preserving the edistance\nbetween emetric spaces, or equivalently the distance between metric space.  -/\ndef isometry [emetric_space \u03b1] [emetric_space \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200x1 x2 : \u03b1, edist (f x1) (f x2) = edist x1 x2\n\n/-- On metric spaces, a map is an isometry if and only if it preserves distances. -/\nlemma isometry_emetric_iff_metric [metric_space \u03b1] [metric_space \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  isometry f \u2194 (\u2200x y, dist (f x) (f y) = dist x y) :=\n\u27e8assume H x y, by simp [dist_edist, H x y],\nassume H x y, by simp [edist_dist, H x y]\u27e9\n\n/-- An isometry preserves edistances. -/\ntheorem isometry.edist_eq [emetric_space \u03b1] [emetric_space \u03b2] {f : \u03b1 \u2192 \u03b2} {x y : \u03b1} (hf : isometry f) :\n  edist (f x) (f y) = edist x y :=\nhf x y\n\n/-- An isometry preserves distances. -/\ntheorem isometry.dist_eq [metric_space \u03b1] [metric_space \u03b2] {f : \u03b1 \u2192 \u03b2} {x y : \u03b1} (hf : isometry f) :\n  dist (f x) (f y) = dist x y :=\nby rw [dist_edist, dist_edist, hf]\n\nsection emetric_isometry\n\nvariables [emetric_space \u03b1] [emetric_space \u03b2] [emetric_space \u03b3]\nvariables {f : \u03b1 \u2192 \u03b2} {x y z : \u03b1}  {s : set \u03b1}\n\n/-- An isometry is injective -/\nlemma isometry.injective (h : isometry f) : injective f :=\n\u03bbx y hxy, edist_eq_zero.1 $\ncalc edist x y = edist (f x) (f y) : (h x y).symm\n         ...   = 0 : by rw [hxy]; simp\n\n/-- Any map on a subsingleton is an isometry -/\ntheorem isometry_subsingleton [subsingleton \u03b1] : isometry f :=\n\u03bbx y, by rw subsingleton.elim x y; simp\n\n/-- The identity is an isometry -/\nlemma isometry_id : isometry (id : \u03b1 \u2192 \u03b1) :=\n\u03bbx y, rfl\n\n/-- The composition of isometries is an isometry -/\ntheorem isometry.comp {g : \u03b2 \u2192 \u03b3} (hf : isometry f) (hg : isometry g) : isometry (g \u2218 f) :=\nassume x y, calc\n  edist ((g \u2218 f) x) ((g \u2218 f) y) = edist (f x) (f y) : hg _ _\n                            ... = edist x y : hf _ _\n\n/-- An isometry is an embedding -/\ntheorem isometry.uniform_embedding (hf : isometry f) : uniform_embedding f :=\nbegin\n  refine emetric.uniform_embedding_iff.2 \u27e8_, _, _\u27e9,\n  { assume x y hxy,\n    have : edist (f x) (f y) = 0 := by simp [hxy],\n    have : edist x y = 0 :=\n      begin have A := hf x y, rwa this at A, exact eq.symm A end,\n    by simpa using this },\n  { rw emetric.uniform_continuous_iff,\n    assume \u03b5 \u03b5pos,\n    existsi [\u03b5, \u03b5pos],\n    simp [hf.edist_eq] },\n  { assume \u03b4 \u03b4pos,\n    existsi [\u03b4, \u03b4pos],\n    simp [hf.edist_eq] }\nend\n\n/-- An isometry is continuous. -/\nlemma isometry.continuous (hf : isometry f) : continuous f :=\nhf.uniform_embedding.embedding.continuous\n\n/-- The inverse of an isometry is an isometry. -/\nlemma isometry.inv (e : \u03b1 \u2243 \u03b2) (h : isometry e.to_fun) : isometry e.inv_fun :=\n\u03bbx y, by rw [\u2190 h, e.right_inv _, e.right_inv _]\n\n/-- Isometries preserve the diameter -/\nlemma emetric.isometry.diam_image (hf : isometry f) {s : set \u03b1}:\n  emetric.diam (f '' s) = emetric.diam s :=\nbegin\n  refine le_antisymm _ _,\n  { apply lattice.Sup_le _,\n    simp only [and_imp, set.mem_image, set.mem_prod, exists_imp_distrib, prod.exists],\n    assume b x x' z zs xz z' z's x'z' hb,\n    rw [\u2190 hb, \u2190 xz, \u2190 x'z', hf z z'],\n    exact emetric.edist_le_diam_of_mem zs z's },\n  { apply lattice.Sup_le _,\n    simp only [and_imp, set.mem_image, set.mem_prod, exists_imp_distrib, prod.exists],\n    assume b x x' xs x's hb,\n    rw [\u2190 hb, \u2190 hf x x'],\n    exact emetric.edist_le_diam_of_mem (mem_image_of_mem _ xs) (mem_image_of_mem _ x's) }\nend\n\n/-- The injection from a subtype is an isometry -/\nlemma isometry_subtype_val {s : set \u03b1} : isometry (subtype.val : s \u2192 \u03b1) :=\n\u03bbx y, rfl\n\nend emetric_isometry --section\n\n/-- An isometry preserves the diameter in metric spaces -/\nlemma metric.isometry.diam_image [metric_space \u03b1] [metric_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (hf : isometry f) : metric.diam (f '' s) = metric.diam s :=\nby rw [metric.diam, metric.diam, emetric.isometry.diam_image hf]\n\n/-- \u03b1 and \u03b2 are isometric if there is an isometric bijection between them. -/\nstructure isometric (\u03b1 : Type*) (\u03b2 : Type*) [emetric_space \u03b1] [emetric_space \u03b2]\n  extends \u03b1 \u2243 \u03b2 :=\n(isometry_to_fun  : isometry to_fun)\n(isometry_inv_fun : isometry inv_fun)\n\ninfix ` \u2243\u1d62`:50 := isometric\n\nnamespace isometric\nvariables [emetric_space \u03b1] [emetric_space \u03b2] [emetric_space \u03b3]\n\ninstance : has_coe_to_fun (\u03b1 \u2243\u1d62 \u03b2) := \u27e8\u03bb_, \u03b1 \u2192 \u03b2, \u03bbe, e.to_equiv\u27e9\n\nlemma coe_eq_to_equiv (h : \u03b1 \u2243\u1d62 \u03b2) (a : \u03b1) : h a = h.to_equiv a := rfl\n\nprotected def to_homeomorph (h : \u03b1 \u2243\u1d62 \u03b2) : \u03b1 \u2243\u209c \u03b2 :=\n{ continuous_to_fun  := (isometry_to_fun h).continuous,\n  continuous_inv_fun := (isometry_inv_fun h).continuous,\n  .. h.to_equiv }\n\nlemma coe_eq_to_homeomorph (h : \u03b1 \u2243\u1d62 \u03b2) (a : \u03b1) :\n  h a = h.to_homeomorph a := rfl\n\nlemma to_homeomorph_to_equiv (h : \u03b1 \u2243\u1d62 \u03b2) :\n  h.to_homeomorph.to_equiv = h.to_equiv :=\nby ext; refl\n\nprotected def refl (\u03b1 : Type*) [emetric_space \u03b1] : \u03b1 \u2243\u1d62 \u03b1 :=\n{ isometry_to_fun := isometry_id, isometry_inv_fun := isometry_id, .. equiv.refl \u03b1 }\n\nprotected def trans (h\u2081 : \u03b1 \u2243\u1d62 \u03b2) (h\u2082 : \u03b2 \u2243\u1d62 \u03b3) : \u03b1 \u2243\u1d62 \u03b3 :=\n{ isometry_to_fun  := h\u2081.isometry_to_fun.comp h\u2082.isometry_to_fun,\n  isometry_inv_fun := h\u2082.isometry_inv_fun.comp h\u2081.isometry_inv_fun,\n  .. equiv.trans h\u2081.to_equiv h\u2082.to_equiv }\n\nprotected def symm (h : \u03b1 \u2243\u1d62 \u03b2) : \u03b2 \u2243\u1d62 \u03b1 :=\n{ isometry_to_fun  := h.isometry_inv_fun,\n  isometry_inv_fun := h.isometry_to_fun,\n  .. h.to_equiv.symm }\n\nprotected lemma isometry (h : \u03b1 \u2243\u1d62 \u03b2) : isometry h := h.isometry_to_fun\n\nlemma symm_comp_self (h : \u03b1 \u2243\u1d62 \u03b2) : \u21d1h.symm \u2218 \u21d1h = id :=\nfunext $ assume a, h.to_equiv.left_inv a\n\nlemma self_comp_symm (h : \u03b1 \u2243\u1d62 \u03b2) : \u21d1h \u2218 \u21d1h.symm = id :=\nfunext $ assume a, h.to_equiv.right_inv a\n\nlemma range_coe (h : \u03b1 \u2243\u1d62 \u03b2) : range h = univ :=\neq_univ_of_forall $ assume b, \u27e8h.symm b, congr_fun h.self_comp_symm b\u27e9\n\nlemma image_symm (h : \u03b1 \u2243\u1d62 \u03b2) : image h.symm = preimage h :=\nimage_eq_preimage_of_inverse h.symm.to_equiv.left_inv h.symm.to_equiv.right_inv\n\nlemma preimage_symm (h : \u03b1 \u2243\u1d62 \u03b2) : preimage h.symm = image h :=\n(image_eq_preimage_of_inverse h.to_equiv.left_inv h.to_equiv.right_inv).symm\n\nend isometric\n\n/-- An isometry induces an isometric isomorphism between the source space and the\nrange of the isometry. -/\nlemma isometry.isometric_on_range [emetric_space \u03b1] [emetric_space \u03b2] {f : \u03b1 \u2192 \u03b2} (h : isometry f) :\n  \u03b1 \u2243\u1d62 range f :=\n{ isometry_to_fun := \u03bbx y,\n  begin\n    change edist ((equiv.set.range f _) x) ((equiv.set.range f _) y) = edist x y,\n    rw [equiv.set.range_apply f h.injective, equiv.set.range_apply f h.injective],\n    exact h x y\n  end,\n  isometry_inv_fun :=\n  begin\n    apply isometry.inv,\n    assume x y,\n    change edist ((equiv.set.range f _) x) ((equiv.set.range f _) y) = edist x y,\n    rw [equiv.set.range_apply f h.injective, equiv.set.range_apply f h.injective],\n    exact h x y\n  end,\n  .. equiv.set.range f h.injective }\n\nlemma isometry.isometric_on_range_apply [emetric_space \u03b1] [emetric_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : isometry f) (x : \u03b1) : h.isometric_on_range x = \u27e8f x, mem_range_self _\u27e9 :=\nbegin\n  dunfold isometry.isometric_on_range,\n  rw \u2190 equiv.set.range_apply f h.injective x,\n  refl\nend\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/topology/metric_space/isometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.739139199117946}}
{"text": "/-\nCopyright (c) 2022 Junyan Xu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Junyan Xu\n-/\nimport data.dfinsupp.well_founded\nimport data.finsupp.lex\n\n/-!\n# Well-foundedness of the lexicographic and product orders on `finsupp`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n`finsupp.lex.well_founded` and the two variants that follow it essentially say that if\n`(>)` is a well order on `\u03b1`, `(<)` is well-founded on `N`, and `0` is a bottom element in `N`,\nthen the lexicographic `(<)` is well-founded on `\u03b1 \u2192\u2080 N`.\n\n`finsupp.lex.well_founded_lt_of_finite` says that if `\u03b1` is finite and equipped with a linear\norder and `(<)` is well-founded on `N`, then the lexicographic `(<)` is well-founded on `\u03b1 \u2192\u2080 N`.\n\n`finsupp.well_founded_lt` and `well_founded_lt_of_finite` state the same results for the product\norder `(<)`, but without the ordering conditions on `\u03b1`.\n\nAll results are transferred from `dfinsupp` via `finsupp.to_dfinsupp`.\n-/\n\nvariables {\u03b1 N : Type*}\n\nnamespace finsupp\n\nvariables [hz : has_zero N] {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : N \u2192 N \u2192 Prop}\n  (hbot : \u2200 \u2983n\u2984, \u00ac s n 0) (hs : well_founded s)\ninclude hbot hs\n\n/-- Transferred from `dfinsupp.lex.acc`. See the top of that file for an explanation for the\n  appearance of the relation `r\u1d9c \u2293 (\u2260)`. -/\nlemma lex.acc (x : \u03b1 \u2192\u2080 N) (h : \u2200 a \u2208 x.support, acc (r\u1d9c \u2293 (\u2260)) a) : acc (finsupp.lex r s) x :=\nbegin\n  rw lex_eq_inv_image_dfinsupp_lex, classical,\n  refine inv_image.accessible to_dfinsupp (dfinsupp.lex.acc (\u03bb a, hbot) (\u03bb a, hs) _ _),\n  simpa only [to_dfinsupp_support] using h,\nend\n\ntheorem lex.well_founded (hr : well_founded $ r\u1d9c \u2293 (\u2260)) : well_founded (finsupp.lex r s) :=\n\u27e8\u03bb x, lex.acc hbot hs x $ \u03bb a _, hr.apply a\u27e9\n\ntheorem lex.well_founded' [is_trichotomous \u03b1 r]\n  (hr : well_founded r.swap) : well_founded (finsupp.lex r s) :=\n(lex_eq_inv_image_dfinsupp_lex r s).symm \u25b8\n  inv_image.wf _ (dfinsupp.lex.well_founded' (\u03bb a, hbot) (\u03bb a, hs) hr)\n\nomit hbot hs\n\ninstance lex.well_founded_lt [has_lt \u03b1] [is_trichotomous \u03b1 (<)] [h\u03b1 : well_founded_gt \u03b1]\n  [canonically_ordered_add_monoid N] [hN : well_founded_lt N] : well_founded_lt (lex (\u03b1 \u2192\u2080 N)) :=\n\u27e8lex.well_founded' (\u03bb n, (zero_le n).not_lt) hN.wf h\u03b1.wf\u27e9\n\nvariable (r)\n\ntheorem lex.well_founded_of_finite [is_strict_total_order \u03b1 r] [finite \u03b1] [has_zero N]\n  (hs : well_founded s) : well_founded (finsupp.lex r s) :=\ninv_image.wf (@equiv_fun_on_finite \u03b1 N _ _) (pi.lex.well_founded r $ \u03bb a, hs)\n\ntheorem lex.well_founded_lt_of_finite [linear_order \u03b1] [finite \u03b1] [has_zero N] [has_lt N]\n  [hwf : well_founded_lt N] : well_founded_lt (lex (\u03b1 \u2192\u2080 N)) :=\n\u27e8finsupp.lex.well_founded_of_finite (<) hwf.1\u27e9\n\nprotected theorem well_founded_lt [has_zero N] [preorder N] [well_founded_lt N]\n  (hbot : \u2200 n : N, \u00ac n < 0) : well_founded_lt (\u03b1 \u2192\u2080 N) :=\n\u27e8inv_image.wf to_dfinsupp (dfinsupp.well_founded_lt $ \u03bb i a, hbot a).wf\u27e9\n\ninstance well_founded_lt' [canonically_ordered_add_monoid N]\n  [well_founded_lt N] : well_founded_lt (\u03b1 \u2192\u2080 N) :=\nfinsupp.well_founded_lt $ \u03bb a, (zero_le a).not_lt\n\ninstance well_founded_lt_of_finite [finite \u03b1] [has_zero N] [preorder N]\n  [well_founded_lt N] : well_founded_lt (\u03b1 \u2192\u2080 N) :=\n\u27e8inv_image.wf equiv_fun_on_finite function.well_founded_lt.wf\u27e9\n\nend finsupp\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/finsupp/well_founded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7391391969582795}}
{"text": "/-\nCopyright (c) 2016 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Johannes H\u00f6lzl\n\nGalois connections - order theoretic adjoints.\n-/\nimport standard\nopen classical eq.ops algebra set function complete_lattice\n\n/- Move to set? -/\ndefinition kern_image {X Y : Type} (f : X \u2192 Y) (S : set X) : set Y := {y | \u2200x, f x = y \u2192 x \u2208 S }\n\n/- Order theoretic definitions -/\n\n/- TODO: move to order? -/\nsection order\nvariables {A B : Type} {S : set A} {a a' : A} {b b' : B} {f : A \u2192 B} [weak_order A] [weak_order B]\n\ndefinition increasing (f : A \u2192 A) := \u2200\u2983a\u2984, a \u2264 f a\ndefinition decreasing (f : A \u2192 A) := \u2200\u2983a\u2984, f a \u2264 a\n\ndefinition upper_bounds (S : set A) : set A := { x | \u2200\u2080 s \u2208 S, s \u2264 x }\ndefinition lower_bounds (S : set A) : set A := { x | \u2200\u2080 s \u2208 S, x \u2264 s }\ndefinition is_least (S : set A) (a : A) := a \u2208 S \u2227 a \u2208 lower_bounds S\ndefinition is_greatest (S : set A) (a : A) := a \u2208 S \u2227 a \u2208 upper_bounds S\n\ndefinition monotone (f : A \u2192 B) := \u2200\u2983a b\u2984, a \u2264 b \u2192 f a \u2264 f b\n\nlemma eq_of_is_least_of_is_least (Ha : is_least S a) (Hb : is_least S a') : a = a' :=\nle.antisymm\n  begin apply (and.elim_right Ha), apply (and.elim_left Hb) end\n  begin apply (and.elim_right Hb), apply (and.elim_left Ha) end\n\nlemma is_least_iff_eq_of_is_least (Ha : is_least S a) : is_least S a' \u2194 a = a' :=\niff.intro (eq_of_is_least_of_is_least Ha) begin intro H, cases H, apply Ha end\n\nlemma eq_of_is_greatest_of_is_greatest (Ha : is_greatest S a) (Hb : is_greatest S a') : a = a' :=\nle.antisymm\n  begin apply (and.elim_right Hb), apply (and.elim_left Ha) end\n  begin apply (and.elim_right Ha), apply (and.elim_left Hb) end\n\nlemma is_greatest_iff_eq_of_is_greatest (Ha : is_greatest S a) : is_greatest S a' \u2194 a = a' :=\niff.intro (eq_of_is_greatest_of_is_greatest Ha) begin intro H, cases H, apply Ha end\n\ndefinition is_lub (S : set A) := is_least (upper_bounds S)\ndefinition is_glb (S : set A) := is_greatest (lower_bounds S)\n\nlemma eq_of_is_lub_of_is_lub : is_lub S a \u2192 is_lub S a' \u2192 a = a' :=\n!eq_of_is_least_of_is_least\n\nlemma is_lub_iff_eq_of_is_lub : is_lub S a \u2192 (is_lub S a' \u2194 a = a') :=\n!is_least_iff_eq_of_is_least\n\nlemma eq_of_is_glb_of_is_glb : is_glb S a \u2192 is_glb S a' \u2192 a = a' :=\n!eq_of_is_greatest_of_is_greatest\n\nlemma is_glb_iff_eq_of_is_glb : is_glb S a \u2192 (is_glb S a' \u2194 a = a') :=\n!is_greatest_iff_eq_of_is_greatest\n\nlemma mem_upper_bounds_image (Hf : monotone f) (Ha : a \u2208 upper_bounds S) : f a \u2208 upper_bounds (f ' S) :=\nbounded_forall_image_of_bounded_forall (take x H, Hf (Ha `x \u2208 S`))\n\nlemma mem_lower_bounds_image (Hf : monotone f) (Ha : a \u2208 lower_bounds S) : f a \u2208 lower_bounds (f ' S) :=\nbounded_forall_image_of_bounded_forall (take x H, Hf (Ha `x \u2208 S`))\n\nend order\n\ndefinition galois_connection {A B : Type} [weak_order A] [weak_order B] (l : A \u2192 B) (u : B \u2192 A) :=\n  \u2200{a b}, l a \u2264 b \u2194 a \u2264 u b\n\nnamespace galois_connection\n\nsection\nparameters {A B : Type} [weak_order A] [weak_order B] (l : A \u2192 B) (u : B \u2192 A)\n\nlemma monotone_intro (Mu : monotone u) (Ml : monotone l)\n    (Iul : increasing (u \u2218 l)) (Dlu : decreasing (l \u2218 u)) : galois_connection l u :=\nbegin\n  intros a b,\n  apply iff.intro,\n  { intro H, apply le.trans, apply Iul, apply Mu, assumption },\n  { intro H, apply le.trans, apply Ml, assumption, apply Dlu }\nend\n\nparameter (gc : galois_connection l u)\ninclude gc\n\nlemma l_le {a : A} {b : B} : a \u2264 u b \u2192 l a \u2264 b :=\nand.elim_right !gc\n\nlemma le_u {a : A} {b : B} : l a \u2264 b \u2192 a \u2264 u b :=\nand.elim_left !gc\n\nlemma increasing_u_l : increasing (u \u2218 l) :=\ntake a, le_u !le.refl\n\nlemma decreasing_l_u : decreasing (l \u2218 u) :=\ntake a, l_le !le.refl\n\nlemma monotone_u : monotone u :=\ntake a b H, le_u (le.trans !decreasing_l_u H)\n\nlemma monotone_l : monotone l :=\ntake a b H, l_le (le.trans H !increasing_u_l)\n\nlemma u_l_u_eq_u : u \u2218 l \u2218 u = u :=\nfunext (take x, le.antisymm (monotone_u !decreasing_l_u) !increasing_u_l)\n\nlemma l_u_l_eq_l : l \u2218 u \u2218 l = l :=\nfunext (take x, le.antisymm !decreasing_l_u (monotone_l !increasing_u_l))\n\nlemma u_mem_upper_bounds {S : set A} {b : B} (H : b \u2208 upper_bounds (l ' S)) : u b \u2208 upper_bounds S :=\ntake c, suppose c \u2208 S, le_u (H (!mem_image_of_mem `c \u2208 S`))\n\nlemma l_mem_lower_bounds {S : set B} {a : A} (H : a \u2208 lower_bounds (u ' S)) : l a \u2208 lower_bounds S :=\ntake c, suppose c \u2208 S, l_le (H (!mem_image_of_mem `c \u2208 S`))\n\nlemma is_lub_l_image {S : set A} {a : A} (H : is_lub S a) : is_lub (l ' S) (l a) :=\nand.intro\n  (mem_upper_bounds_image monotone_l (and.elim_left `is_lub S a`))\n  (take b Hb, l_le (and.elim_right `is_lub S a` _ (u_mem_upper_bounds Hb)))\n\nlemma is_glb_u_image {S : set B} {b : B} (H : is_glb S b) : is_glb (u ' S) (u b) :=\nand.intro\n  (mem_lower_bounds_image monotone_u (and.elim_left `is_glb S b`))\n  (take a Ha, le_u (and.elim_right `is_glb S b` _ (l_mem_lower_bounds Ha)))\n\nlemma is_glb_l {a : A} : is_glb { b | a \u2264 u b } (l a) :=\nbegin\n  apply and.intro,\n  { intro b, apply l_le },\n  { intro b H, apply H, apply increasing_u_l }  \nend\n\nlemma is_lub_u {b : B} : is_lub { a | l a \u2264 b } (u b) :=\nbegin\n  apply and.intro,\n  { intro a, apply le_u },\n  { intro a H, apply H, apply decreasing_l_u }  \nend\n\nend\n\n/- Constructing Galois connections -/\n\nprotected lemma id {A : Type} [weak_order A] : @galois_connection A A _ _ id id :=\ntake a b, iff.intro (\u03bbx, x) (\u03bbx, x)\n\nprotected lemma dual {A B : Type} [woA : weak_order A] [woB : weak_order B]\n  (l : A \u2192 B) (u : B \u2192 A) (gc : galois_connection l u) :\n  @galois_connection B A (weak_order_dual woB) (weak_order_dual woA) u l :=\ntake a b,\nbegin\n  apply iff.symm,\n  rewrite le_dual_eq_le,\n  rewrite le_dual_eq_le,\n  exact gc, \nend\n\nprotected lemma compose {A B C : Type} [weak_order A] [weak_order B] [weak_order C]\n  (l1 : A \u2192 B) (u1 : B \u2192 A) (l2 : B \u2192 C) (u2 : C \u2192 B)\n  (gc1 : galois_connection l1 u1) (gc2 : galois_connection l2 u2) :\n  galois_connection (l2 \u2218 l1) (u1 \u2218 u2) :=\nby intros; rewrite gc2; rewrite gc1\n\nsection \n  variables {A B : Type} {f : A \u2192 B}\n\n  protected lemma image_preimage : galois_connection (image f) (preimage f) :=\n    @image_subset_iff A B f\n\n  protected lemma preimage_kern_image : galois_connection (preimage f) (kern_image f) :=\n  begin\n    intros X Y, apply iff.intro, all_goals (intro H x Hx),\n    { intro x' eq, apply H, cases eq, exact Hx },\n    { apply H,\n      esimp [preimage, mem, set_of] at Hx, exact Hx, -- TODO: why is esimp necessary?\n      exact rfl }\n  end\nend\n\nend galois_connection\n\n/- Bounds on complete lattices -/\n/- TODO: move to complete lattices? -/\n\nsection\nvariables {A : Type} (S : set A) {a b : A} [complete_lattice A]\n\nlemma is_lub_sup : is_lub '{a, b} (sup a b) :=\nand.intro\n  begin\n    xrewrite [+bounded_forall_insert_iff, bounded_forall_empty_iff, and_true],\n    exact (and.intro !le_sup_left !le_sup_right)\n  end\n  begin\n    intro x Hx,\n    xrewrite [+bounded_forall_insert_iff at Hx, bounded_forall_empty_iff at Hx, and_true at Hx],\n    apply sup_le,\n    apply (and.elim_left Hx),\n    apply (and.elim_right Hx),\n  end\n\nlemma is_lub_Sup : is_lub S (\u2a06S) :=\nand.intro (take x, le_Sup) (take x, Sup_le)\n\nlemma is_lub_iff_Sup_eq {a : A} : is_lub S a \u2194 (\u2a06S) = a :=\n!is_lub_iff_eq_of_is_lub !is_lub_Sup\n\nlemma is_glb_Inf : is_glb S (\u2a05S) :=\nand.intro (take a, Inf_le) (take a, le_Inf)\n\nlemma is_glb_iff_Inf_eq : is_glb S a \u2194 (\u2a05S) = a :=\n!is_glb_iff_eq_of_is_glb !is_glb_Inf\n\nend\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/algebra/galois_connection.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7391391953554245}}
{"text": "/-\nCopyright (c) 2020 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n-/\nimport analysis.convex.function\nimport topology.algebra.affine\nimport topology.local_extr\nimport topology.metric_space.basic\n\n/-!\n# Minima and maxima of convex functions\n\nWe show that if a function `f : E \u2192 \u03b2` is convex, then a local minimum is also\na global minimum, and likewise for concave functions.\n-/\n\nvariables {E \u03b2 : Type*} [add_comm_group E] [topological_space E]\n  [module \u211d E] [topological_add_group E] [has_continuous_smul \u211d E]\n  [ordered_add_comm_group \u03b2] [module \u211d \u03b2] [ordered_smul \u211d \u03b2]\n  {s : set E}\n\nopen set filter function\nopen_locale classical topological_space\n\n/--\nHelper lemma for the more general case: `is_min_on.of_is_local_min_on_of_convex_on`.\n-/\nlemma is_min_on.of_is_local_min_on_of_convex_on_Icc {f : \u211d \u2192 \u03b2} {a b : \u211d} (a_lt_b : a < b)\n  (h_local_min : is_local_min_on f (Icc a b) a) (h_conv : convex_on \u211d (Icc a b) f) :\n  is_min_on f (Icc a b) a :=\nbegin\n  rintro c hc, dsimp only [mem_set_of_eq],\n  rw [is_local_min_on, nhds_within_Icc_eq_nhds_within_Ici a_lt_b] at h_local_min,\n  rcases hc.1.eq_or_lt with rfl|a_lt_c, { exact le_rfl },\n  have H\u2081 : \u2200\u1da0 y in \ud835\udcdd[>] a, f a \u2264 f y,\n    from h_local_min.filter_mono (nhds_within_mono _ Ioi_subset_Ici_self),\n  have H\u2082 : \u2200\u1da0 y in \ud835\udcdd[>] a, y \u2208 Ioc a c,\n    from Ioc_mem_nhds_within_Ioi (left_mem_Ico.2 a_lt_c),\n  rcases (H\u2081.and H\u2082).exists with \u27e8y, hfy, hy_ac\u27e9,\n  rcases (convex.mem_Ioc a_lt_c).mp hy_ac with \u27e8ya, yc, ya\u2080, yc\u2080, yac, rfl\u27e9,\n  suffices : ya \u2022 f a + yc \u2022 f a \u2264 ya \u2022 f a + yc \u2022 f c,\n    from (smul_le_smul_iff_of_pos yc\u2080).1 (le_of_add_le_add_left this),\n  calc ya \u2022 f a + yc \u2022 f a = f a : by rw [\u2190 add_smul, yac, one_smul]\n  ... \u2264 f (ya * a + yc * c)      : hfy\n  ... \u2264 ya \u2022 f a + yc \u2022 f c      : h_conv.2 (left_mem_Icc.2 a_lt_b.le) hc ya\u2080 yc\u2080.le yac\nend\n\n/--\nA local minimum of a convex function is a global minimum, restricted to a set `s`.\n-/\nlemma is_min_on.of_is_local_min_on_of_convex_on {f : E \u2192 \u03b2} {a : E}\n  (a_in_s : a \u2208 s) (h_localmin : is_local_min_on f s a) (h_conv : convex_on \u211d s f) :\n  is_min_on f s a :=\nbegin\n  intros x x_in_s,\n  let g : \u211d \u2192\u1d43[\u211d] E := affine_map.line_map a x,\n  have hg0 : g 0 = a := affine_map.line_map_apply_zero a x,\n  have hg1 : g 1 = x := affine_map.line_map_apply_one a x,\n  have hgc : continuous g, from affine_map.line_map_continuous,\n  have h_maps : maps_to g (Icc 0 1) s,\n  { simpa only [maps_to', \u2190 segment_eq_image_line_map]\n      using h_conv.1.segment_subset a_in_s x_in_s },\n  have fg_local_min_on : is_local_min_on (f \u2218 g) (Icc 0 1) 0,\n  { rw \u2190 hg0 at h_localmin,\n    exact h_localmin.comp_continuous_on h_maps hgc.continuous_on (left_mem_Icc.2 zero_le_one) },\n  have fg_min_on : is_min_on (f \u2218 g) (Icc 0 1 : set \u211d) 0,\n  { refine is_min_on.of_is_local_min_on_of_convex_on_Icc one_pos fg_local_min_on _,\n    exact (h_conv.comp_affine_map g).subset h_maps (convex_Icc 0 1) },\n  simpa only [hg0, hg1, comp_app, mem_set_of_eq] using fg_min_on (right_mem_Icc.2 zero_le_one)\nend\n\n/-- A local maximum of a concave function is a global maximum, restricted to a set `s`. -/\nlemma is_max_on.of_is_local_max_on_of_concave_on {f : E \u2192 \u03b2} {a : E}\n  (a_in_s : a \u2208 s) (h_localmax: is_local_max_on f s a) (h_conc : concave_on \u211d s f) :\n  is_max_on f s a :=\n@is_min_on.of_is_local_min_on_of_convex_on _ \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ s f a a_in_s h_localmax h_conc\n\n/-- A local minimum of a convex function is a global minimum. -/\nlemma is_min_on.of_is_local_min_of_convex_univ {f : E \u2192 \u03b2} {a : E}\n  (h_local_min : is_local_min f a) (h_conv : convex_on \u211d univ f) : \u2200 x, f a \u2264 f x :=\n\u03bb x, (is_min_on.of_is_local_min_on_of_convex_on (mem_univ a)\n        (h_local_min.on univ) h_conv) (mem_univ x)\n\n/-- A local maximum of a concave function is a global maximum. -/\nlemma is_max_on.of_is_local_max_of_convex_univ {f : E \u2192 \u03b2} {a : E}\n  (h_local_max : is_local_max f a) (h_conc : concave_on \u211d univ f) : \u2200 x, f x \u2264 f a :=\n@is_min_on.of_is_local_min_of_convex_univ _ \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ f a h_local_max h_conc\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/convex/extrema.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7391391939381724}}
{"text": "/-\nCopyright (c) 2019 Patrick Massot All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Patrick Massot, Simon Hudon\n\nA tactic pushing negations into an expression\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.logic.basic\nimport Mathlib.algebra.order\nimport Mathlib.PostPort\n\nuniverses u \n\nnamespace Mathlib\n\nnamespace push_neg\n\n\ntheorem not_not_eq (p : Prop) : (\u00ac\u00acp) = p := propext not_not\n\ntheorem not_and_eq (p : Prop) (q : Prop) : (\u00ac(p \u2227 q)) = (p \u2192 \u00acq) := propext not_and\n\ntheorem not_or_eq (p : Prop) (q : Prop) : (\u00ac(p \u2228 q)) = (\u00acp \u2227 \u00acq) := propext not_or_distrib\n\ntheorem not_forall_eq {\u03b1 : Sort u} (s : \u03b1 \u2192 Prop) : (\u00ac\u2200 (x : \u03b1), s x) = \u2203 (x : \u03b1), \u00acs x :=\n  propext not_forall\n\ntheorem not_exists_eq {\u03b1 : Sort u} (s : \u03b1 \u2192 Prop) : (\u00ac\u2203 (x : \u03b1), s x) = \u2200 (x : \u03b1), \u00acs x :=\n  propext not_exists\n\ntheorem not_implies_eq (p : Prop) (q : Prop) : (\u00ac(p \u2192 q)) = (p \u2227 \u00acq) := propext not_imp\n\ntheorem classical.implies_iff_not_or (p : Prop) (q : Prop) : p \u2192 q \u2194 \u00acp \u2228 q := imp_iff_not_or\n\ntheorem not_eq {\u03b1 : Sort u} (a : \u03b1) (b : \u03b1) : \u00aca = b \u2194 a \u2260 b := iff.rfl\n\ntheorem not_le_eq {\u03b2 : Type u} [linear_order \u03b2] (a : \u03b2) (b : \u03b2) : (\u00aca \u2264 b) = (b < a) :=\n  propext not_le\n\ntheorem not_lt_eq {\u03b2 : Type u} [linear_order \u03b2] (a : \u03b2) (b : \u03b2) : (\u00aca < b) = (b \u2264 a) :=\n  propext not_lt\n\nend push_neg\n\n\n/--\nPush negations in the goal of some assumption.\n\nFor instance, a hypothesis `h : \u00ac \u2200 x, \u2203 y, x \u2264 y` will be transformed by `push_neg at h` into\n`h : \u2203 x, \u2200 y, y < x`. Variables names are conserved.\n\nThis tactic pushes negations inside expressions. For instance, given an assumption\n```lean\nh : \u00ac \u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192 |f x - y\u2080| \u2264 \u03b5)\n```\nwriting `push_neg at h` will turn `h` into\n```lean\nh : \u2203 \u03b5, \u03b5 > 0 \u2227 \u2200 \u03b4, \u03b4 > 0 \u2192 (\u2203 x, |x - x\u2080| \u2264 \u03b4 \u2227 \u03b5 < |f x - y\u2080|),\n```\n\n(the pretty printer does *not* use the abreviations `\u2200 \u03b4 > 0` and `\u2203 \u03b5 > 0` but this issue\nhas nothing to do with `push_neg`).\nNote that names are conserved by this tactic, contrary to what would happen with `simp`\nusing the relevant lemmas. One can also use this tactic at the goal using `push_neg`,\nat every assumption and the goal using `push_neg at *` or at selected assumptions and the goal\nusing say `push_neg at h h' \u22a2` as usual.\n-/\ntheorem imp_of_not_imp_not (P : Prop) (Q : Prop) : (\u00acQ \u2192 \u00acP) \u2192 P \u2192 Q :=\n  fun (h : \u00acQ \u2192 \u00acP) (hP : P) => classical.by_contradiction fun (h' : \u00acQ) => h h' hP\n\n/-- Matches either an identifier \"h\" or a pair of identifiers \"h with k\" -/\n/--\nTransforms the goal into its contrapositive.\n\n* `contrapose`     turns a goal `P \u2192 Q` into `\u00ac Q \u2192 \u00ac P`\n* `contrapose!`    turns a goal `P \u2192 Q` into `\u00ac Q \u2192 \u00ac P` and pushes negations inside `P` and `Q`\n  using `push_neg`\n* `contrapose h`   first reverts the local assumption `h`, and then uses `contrapose` and `intro h`\n* `contrapose! h`  first reverts the local assumption `h`, and then uses `contrapose!` and `intro h`\n* `contrapose h with new_h` uses the name `new_h` for the introduced hypothesis\n-/\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/tactic/push_neg_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8438951045175642, "lm_q1q2_score": 0.739072363059641}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# Basic Number Theory\n\nLean has enough machinery to make number theory a feasible topic for\na final project. In this section I will work through a bunch of examples,\ntaken from Sierpinski's old book \"250 elementary problems in number theory\".\n\n## Switching between naturals and integers\n\nSometimes when doing number theory in Lean you find yourself having to switch \nbetween naturals, integers and rationals. For example, if you want to do `a ^ n`\nwith `a` an integer, then `n` had better be a natural number, because in general\nyou can't raise an integer to the power of an integer. However subtraction is\n\"broken\" on naturals:\n\n-/\n\nexample : (2 : \u2115) - 3 = 0 := rfl -- subtraction on naturals \"rounds up to 0\" as it must return a natural\n\nexample : (2 : \u2124) - 3 = -1 := rfl -- subtraction on integers works correctly\n\n/-\n\nso sometimes you need to dance between the two. There are coercions between\nall of these objects:\n\n-/\n\nexample (n : \u2115) : \u2124 := n -- works fine\nexample (n : \u2115) : \u2124 := \u2191n -- what it does under the hood\nexample (n : \u2115) (z : \u2124) : \u211a := n + z -- gets translated to \u2191n + \u2191z where the two \u2191s \n                                     -- represent different functions (\u2115 \u2192 \u211a and \u2124 \u2192 \u211a)\n\n/-\n\nThe big problem with this is that you end up with goals and hypotheses with `\u2191` in\nwhich you want to \"cancel\". The `norm_cast` tactic does this.\n\n-/\n\nexample (a b : \u2115) (h : a + b = 37) : (a : \u2124) + b = 37 :=\nbegin\n  /-\n  a b : \u2115\n  h : a + b = 37\n  \u22a2 \u2191a + \u2191b = 37\n  \n  exact `h` fails, because of the coercions (the goal is about the integer 37,\n  not the natural 37)\n  -/\n  \n  norm_cast, -- goal now becomes `a + b = 37`\n  exact h,\nend\n\n-- There are several shortcuts you can take here, for example\nexample (a b : \u2115) (h : a + b = 37) : (a : \u2124) + b = 37 :=\nbegin\n  exact_mod_cast h, -- `h` is \"correct modulo coercions\"\nend\n\nexample (a b : \u2115) (h : a + b = 37) : (a : \u2124) + b = 37 :=\nbegin\n  assumption_mod_cast, -- \"it's an assumption, modulo coercions\"\nend\n\n-- The `ring` tactic can't deal with the `\u2191`s here (it's not its job)\nexample (a b : \u2115) : ((a + b : \u2115) : \u2124)^2=a^2+2*a*b+b^2 :=\nbegin\n  norm_cast, -- all the \u2191s are gone now\n  ring,\nend\n\n-- Another approach:\nexample (a b : \u2115) : ((a + b : \u2115) : \u2124)^2=a^2+2*a*b+b^2 :=\nbegin\n  push_cast, -- does the \"opposite\" to `norm_cast`. The `norm_cast` tactic\n             -- tries to pull `\u2191`s out as much as possible (so it changes `\u2191a + \u2191b`\n             -- to `\u2191(a + b)`), and then tries to cancel them. `push_cast` pushes\n             -- the \u2191s \"inwards\", i.e. as tightly up to the variables as it can.\n\n             -- Goal is now\n             -- \u22a2 (\u2191a + \u2191b) ^ 2 = \u2191a ^ 2 + 2 * \u2191a * \u2191b + \u2191b ^ 2\n  ring,      -- works fine, with variables \u2191a and \u2191b.  \nend\n\n/-\n\nThese `cast` tactics do not quite solve all your problems, however.\nSometimes you have statements about naturals, and you would rather\nthey were about integers (for example because you want to start\nusing subtraction). You can use the `zify` tactic to change statements\nabout naturals to statements about integers, and the `lift` tactic to\nchange statements about integers to statements about naturals. Check\nout the Lean 3 documentation for these tactics if you want to know\nmore (I didn't cover them in the course notes):\n\nhttps://leanprover-community.github.io/mathlib_docs/tactic/zify.html#tactic.interactive.zify\nhttps://leanprover-community.github.io/mathlib_docs/tactic/lift.html#tactic.interactive.lift\n\n\n## For which positive integers n does n+1 divide n^2+1?\n\nThis is the first question in Sierpinski's book.\n\nHint: n+1 divides n^2-1.\n\n-/\n\nexample (n : \u2115) (hn : 0 < n) : (n + 1) \u2223 (n^2 + 1) \u2194 n = 1 :=\nbegin\n  sorry,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section15number_theory/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7390723593069809}}
{"text": "-- Chapter 3\n\nvariables p q r s: Prop\n\n-- #check p \u2192 q \u2192 p \u2227 q\n-- #check \u00acp \u2192 p \u2194 false\n-- #check p \u2228 q \u2192 q \u2227 p\n\n-- commutativity of \u2227 and \u2228\ntheorem and_comm_ : p \u2227 q \u2194 q \u2227 p :=\niff.intro\n  (assume hpq : p \u2227 q,\n    show q \u2227 p, from \u27e8(and.right hpq), (and.left hpq)\u27e9)\n  (assume hqp : q \u2227 p,\n    show p \u2227 q, from \u27e8(and.right hqp), (and.left hqp)\u27e9)\n\ntheorem or_comm_ : p \u2228 q \u2194 q \u2228 p :=\niff.intro\n  (assume hpq: p \u2228 q,\n    hpq.elim\n      (assume hp:p, or.inr hp)\n      (assume hq:q, or.inl hq))\n  (assume hqp: q \u2228 p,\n    hqp.elim\n      (assume hq:q, or.inr hq)\n      (assume hp:p, or.inl hp))\n\n-- associativity of \u2227 and \u2228\ntheorem and_assoc_ : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\niff.intro\n  (assume h : (p \u2227 q) \u2227 r,\n    show p \u2227 (q \u2227 r), from \u27e8h.left.left, \u27e8h.left.right, h.right\u27e9\u27e9)\n  (assume h : p \u2227 (q \u2227 r),\n      show (p \u2227 q) \u2227 r, from \u27e8\u27e8h.left, h.right.left\u27e9,h.right.right\u27e9)\n\ntheorem or_assoc_ : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\niff.intro\n  (assume h: (p \u2228 q) \u2228 r,\n    or.elim h\n      (assume hpq : p \u2228 q,\n        show p \u2228 (q \u2228 r),\n        from hpq.elim\n          (assume hp : p, or.inl hp)\n          (assume hq : q, or.inr (or.inl hq)))\n      (assume hr : r,\n        show p \u2228 (q \u2228 r),\n        from or.inr (or.inr hr)))\n  (assume h: p \u2228 (q \u2228 r),\n    or.elim h\n    (assume hp : p,\n      show (p \u2228 q) \u2228 r,\n      from or.inl (or.inl hp))\n    (assume hqr : q \u2228 r,\n      or.elim hqr\n      (assume hq : q,\n        show (p \u2228 q) \u2228 r,\n        from or.inl (or.inr hq))\n      (assume hr : r,\n        show (p \u2228 q) \u2228 r,\n        from or.inr hr)))\n\n-- distributivity\ntheorem and_to_or_dist : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\niff.intro\n  (assume h : p \u2227 (q \u2228 r),\n    show (p \u2227 q) \u2228 (p \u2227 r),\n    from or.elim h.right\n      (assume hq : q, or.inl \u27e8h.left,hq\u27e9)\n      (assume hr : r, or.inr \u27e8h.left,hr\u27e9))\n  (assume h :(p \u2227 q) \u2228 (p \u2227 r),\n      show p \u2227 (q \u2228 r),\n      from or.elim h\n        (assume hpq : p \u2227 q, and.intro hpq.left (or.inl hpq.right))\n        (assume hpr : p \u2227 r, and.intro hpr.left (or.inr hpr.right)))\n\ntheorem or_to_and_dist : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\niff.intro\n  (assume h : p \u2228 (q \u2227 r),\n    show (p \u2228 q) \u2227 (p \u2228 r),\n    from h.elim\n      (assume hp : p, and.intro (or.inl hp) (or.inl hp))\n      (assume hqr : q \u2227 r, and.intro (or.inr hqr.left) (or.inr hqr.right)))\n  (assume h : (p \u2228 q) \u2227 (p \u2228 r),\n    show p \u2228 (q \u2227 r), from\n    have hpq : p \u2228 q, from h.left,\n    have hpr : p \u2228 r, from h.right,\n    hpq.elim\n      (assume hp : p, or.inl hp)\n      (assume hq : q,\n        hpr.elim\n          (assume hp : p, or.inl hp)\n          (assume hr : r, or.inr \u27e8hq, hr\u27e9)))\n\n-- other properties\n-- exportation name comes from book 'Modern Formal Logic', McKay\ntheorem exportation : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\niff.intro\n  (assume h : p \u2192 (q \u2192 r),\n    assume hpq : p \u2227 q,\n      h hpq.left hpq.right)\n  (assume h : p \u2227 q \u2192 r,\n    assume hp : p,\n      assume hq : q,\n        h \u27e8hp, hq\u27e9)\n\n\n-- resorting to numbering, who knows what these should be called\ntheorem t1 : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\niff.intro\n  (assume h : (p \u2228 q) \u2192 r,\n    show (p \u2192 r) \u2227 (q \u2192 r),\n    from and.intro\n      (assume hp : p,\n        h (or.inl hp))\n      (assume hq : q,\n        h (or.inr hq)))\n  (assume h : (p \u2192 r) \u2227 (q \u2192 r),\n    show (p \u2228 q) \u2192 r,\n    from assume hpq : p \u2228 q,\n      hpq.elim\n        (assume hp : p,\n          have hr : r, from h.left hp, hr)\n        (assume hq : q,\n          have hr : r, from h.right hq, hr))\n\n-- DeMorgan's laws\ntheorem dem1 : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\niff.intro\n  (assume h : \u00ac(p \u2228 q),\n    show \u00acp \u2227 \u00acq,\n    from and.intro\n      (show \u00acp, from assume hp : p, absurd (or.inl hp) h)\n      (show \u00acq, from assume hq : q, absurd (or.inr hq) h))\n  (assume h : \u00acp \u2227 \u00acq,\n    show \u00ac(p \u2228 q),\n    from assume hpq : p \u2228 q,\n    show false, from hpq.elim\n        (assume hp : p, absurd hp h.left)\n        (assume hq : q, absurd hq h.right))\n\ntheorem dem2 : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\nassume h : \u00acp \u2228 \u00acq,\n  assume hpq : p \u2227 q, h.elim\n    (assume hnp : \u00acp, absurd hpq.left hnp)\n    (assume hnq : \u00acq, absurd hpq.right hnq)\n\ntheorem paradox : \u00ac(p \u2227 \u00acp) :=\nassume h : p \u2227 \u00acp, absurd h.left h.right\n\ntheorem t2: p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\nassume h : p \u2227 \u00acq,\n  assume hptq : p \u2192 q,\n  have hq : q, from hptq h.left,\n  show false, from absurd hq h.right\n\ntheorem t3 : \u00acp \u2192 (p \u2192 q) :=\nassume h : \u00acp,\n  assume hp : p,\n    false.elim (h hp)\n\ntheorem t4 : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\nassume h : \u00acp \u2228 q,\n  assume hp : p, h.elim\n    (assume hnp : \u00acp, absurd hp hnp)\n    (assume hq : q, hq)\n\ntheorem t5 : p \u2228 false \u2194 p :=\niff.intro\n  (assume h : p \u2228 false,\n    h.elim (\u03bb hp, hp) (\u03bb false, false.elim))\n  (assume p,\n    or.inl p)\n\ntheorem t6 : p \u2227 false \u2194 false :=\niff.intro\n  (assume h : p \u2227 false, h.right)\n  (assume false, false.elim)\n\ntheorem t7 : \u00ac(p \u2194 \u00acp) :=\nassume h : p \u2194 \u00acp,\n  have hnp : p \u2192 false, from\n    assume hp : p, have hnp : \u00acp, from h.mp hp, absurd hp hnp,\n  absurd (h.mpr hnp) hnp\n\n-- helper function, modus tollens\ntheorem modus_tollens : (p \u2192 q) \u2192 \u00acq \u2192 \u00acp :=\nassume h : p \u2192 q,\n  assume hnq : \u00acq,\n    assume hp : p, absurd (h hp) hnq\n\ntheorem t8 : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\nassume h : p \u2192 q,\n  assume hnq : \u00acq, (modus_tollens p q) h hnq\n\n-- classical section:\nopen classical\n\n-- variables p q r s : Prop\n\ntheorem c1 : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\nassume h : p \u2192 r \u2228 s,\nor.elim (em p)\n  (assume hp : p,\n  show ((p \u2192 r) \u2228 (p \u2192 s)), from\n    have hrs : r \u2228 s, from h hp,\n      hrs.elim\n      (assume hr : r,\n        suffices hpr : p \u2192 r,\n        from or.inl hpr,\n        assume hp : p, hr)\n      (assume hs : s,\n        suffices hps : p \u2192 s,\n        from or.inr hps,\n        assume hp: p, hs))\n  (assume hnp : \u00acp,\n  show ((p \u2192 r) \u2228 (p \u2192 s)), from\n    suffices hpr : p \u2192 r, from or.inl hpr,\n      assume hp : p, absurd hp hnp)\n\ntheorem c2 : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\nassume h : \u00ac(p \u2227 q),\nshow \u00acp \u2228 \u00acq, from\nor.elim (em p)\n  (assume hp : p,\n    or.elim (em q)\n    (assume hq : q,\n      absurd (and.intro hp hq) h)\n    (assume hnq : \u00acq,\n      or.inr hnq))\n  (assume hnp : \u00acp,\n    or.inl hnp)\n\ntheorem c3 : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nassume h : \u00ac(p \u2192 q),\nshow p \u2227 \u00acq, from\nor.elim (em p)\n  (assume hp : p,\n    or.elim (em q)\n      (assume hq : q,\n        have hptq : p \u2192 q, from assume hp : p, hq,\n        absurd hptq h)\n      (assume hnq : \u00acq,\n        and.intro hp hnq))\n  (assume hnp : \u00acp,\n    or.elim (em q)\n      (assume hq : q,\n        have hptq : p \u2192 q, from assume hp : p, hq,\n        absurd hptq h)\n      (assume hnq : \u00acq,\n        suffices hptq : p \u2192 q, from false.elim (h hptq),\n        assume hp : p, absurd hp hnp))\n\ntheorem c4 : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\nassume h : p \u2192 q,\nshow (\u00acp \u2228 q), from\nor.elim (em p)\n  (assume hp : p,\n    or.elim (em q)\n      (assume hq : q,\n        or.inr hq)\n      (assume hnq : \u00acq,\n        have hq : q, from h hp,\n        absurd hq hnq))\n  (assume hnp : \u00acp,\n    or.elim (em q)\n      (assume hq : q,\n        or.inr hq)\n      (assume hnq : \u00acq,\n        or.inl hnp))\n\n\ntheorem c5 : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\nassume h : (\u00acq \u2192 \u00acp),\nshow p \u2192 q, from\nor.elim (em q)\n  (assume hq : q,\n    or.elim (em p)\n      (assume hp : p,\n        (assume hp : p, hq))\n      (assume hnp : \u00acp,\n        (assume hp : p, hq)))\n  (assume hnq : \u00acq,\n    or.elim (em p)\n      (assume hp : p,\n        have hnp : \u00acp, from h hnq,\n        absurd hp hnp)\n      (assume hnp : \u00acp,\n        (assume hp : p,\n        absurd hp hnp)))\n\ntheorem c6 : p \u2228 \u00acp :=\nor.elim (em p)\n  (assume hp : p,\n    or.inl hp)\n  (assume hnp : \u00acp,\n      or.inr hnp)\n\ntheorem c7 : (((p \u2192 q) \u2192 p) \u2192 p) :=\nassume h : ((p \u2192 q) \u2192 p),\nshow p, from\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : \u00acp,\n    have hptq : p \u2192 q, from assume hp : p, absurd hp hnp,\n  absurd (h hptq) hnp)\n", "meta": {"author": "solbloch", "repo": "theorem-proving-in-lean", "sha": "4b7b62f3ca82d4463f6e607e0ef974c9577a5b7e", "save_path": "github-repos/lean/solbloch-theorem-proving-in-lean", "path": "github-repos/lean/solbloch-theorem-proving-in-lean/theorem-proving-in-lean-4b7b62f3ca82d4463f6e607e0ef974c9577a5b7e/ch3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7390723565710561}}
{"text": "import field_theory.finite.basic\n\nnamespace int\n\nvariables {n a b : \u2124} {m : \u2115}\n\nnamespace modeq\n\ntheorem modeq_pow {m a b : \u2124} (h : a \u2261 b [ZMOD m]) :\n\t\u2200 k : \u2115, a ^ k \u2261 b ^ k [ZMOD m]\n| 0     := rfl\n| (n+1) := by rw [pow_succ, pow_succ]; apply modeq_mul h (modeq_pow n)\n\ntheorem pow_modeq_one {m a : \u2124} (ha : a \u2261 1 [ZMOD m]) (k : \u2115) :\n\ta ^ k \u2261 1 [ZMOD m] :=\nby rw [\u2190 one_pow k]; apply modeq_pow ha\n\ntheorem is_coprime_of_modeq (hcop : is_coprime a n) (hmodeq : a \u2261 b [ZMOD n]) :\n  is_coprime b n :=\nbegin\n  cases modeq_iff_dvd.mp hmodeq with x hx,\n  rw [sub_eq_iff_eq_add, add_comm] at hx,\n  rwa [hx, is_coprime.add_mul_left_left_iff],\nend\n\nlocal notation ` \u03d5 ` := nat.totient\n\nlemma pow_totient {x : \u2124} {n : \u2115} (h : is_coprime x n) :\n  x ^ \u03d5 n \u2261 1 [ZMOD n] :=\nbegin\n  cases n, { rw [nat.totient_zero, pow_zero] },\n  rcases @exists_unique_equiv_nat x \u2191(n.succ) _ with \u27e8y, hyn, hy\u27e9, swap,\n  { rw coe_nat_pos, apply nat.succ_pos },\n  apply modeq.trans (modeq_pow hy.symm _),\n  rw [\u2190 coe_nat_pow, \u2190 int.coe_nat_one, int.modeq.coe_nat_modeq_iff],\n  apply nat.modeq.pow_totient,\n  rw \u2190 nat.is_coprime_iff_coprime,\n  exact int.modeq.is_coprime_of_modeq h hy.symm,\nend\n\nend modeq\n\ntheorem is_coprime_of_prime_not_dvd {p : \u2115} (hp : p.prime) : is_coprime a p \u2194 \u00ac \u2191p \u2223 a :=\nbegin\n  rw \u2190 int.gcd_eq_one_iff_coprime,\n  split,\n  { intros hcop hdvd,\n    have := int.dvd_gcd hdvd (dvd_refl _),\n    rw hcop at this,\n    have peq1 := eq_one_of_dvd_one (coe_nat_nonneg p) this,\n    norm_cast at peq1,\n    rw peq1 at hp,\n    exact nat.not_prime_one hp },\n  intro hndvd,\n  cases (nat.dvd_prime hp).mp (coe_nat_dvd.mp $ gcd_dvd_right a p) with h1 heqp,\n  { assumption },\n  exfalso, apply hndvd, rw \u2190 heqp, apply gcd_dvd_left,\nend\n\nend int", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/imo/zmod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7390700920400017}}
{"text": "/-\nCopyright (c) 2018 Rohan Mitta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rohan Mitta\n-/\nimport analysis.metric_space\nimport analysis.topology.topological_space\nimport order.filter\nimport tactic.norm_num\n\nnoncomputable theory\nlocal attribute [instance] classical.prop_decidable \n\n--Patrick's Lemmas\nvariables {\u03b1 : Type*} {\u03b2 : Type*} \nopen filter\n\nlemma tendsto_nhds_iff [metric_space \u03b1] (u : \u03b2 \u2192 \u03b1) (f : filter \u03b2) (a : \u03b1) : tendsto u f (nhds a) \u2194\n  \u2200 \u03b5 > 0, \u2203 s \u2208 f.sets, \u2200 {n}, n \u2208 s \u2192 dist (u n) a < \u03b5 :=\n\u27e8\u03bb H \u03b5 \u03b5pos, \u27e8u \u207b\u00b9' ball a \u03b5, \u27e8H $ ball_mem_nhds a \u03b5pos, \u03bb n h, h\u27e9\u27e9,\n \u03bb H s s_nhd, let \u27e8\u03b5, \u03b5pos, sub\u27e9 := mem_nhds_iff_metric.1 s_nhd in\n   let \u27e8N, \u27e8N_in, H'\u27e9\u27e9 := H \u03b5 \u03b5pos in f.sets_of_superset N_in (\u03bb b b_in, sub $ H' b_in)\u27e9\n\n\nlemma seq_tendsto_iff [metric_space \u03b1] (u : \u2115 \u2192 \u03b1) (a : \u03b1) : tendsto u at_top (nhds a) \u2194\n  \u2200 \u03b5 > 0, \u2203 (N : \u2115), \u2200 {n}, n \u2265 N \u2192 dist (u n) a < \u03b5 :=\n\u27e8\u03bb H \u03b5 \u03b5pos, mem_at_top_sets.1 $ mem_map.2 $ H (ball_mem_nhds _ \u03b5pos),\n \u03bb H s s_nhd, let \u27e8\u03b5, \u03b5pos, sub\u27e9 := mem_nhds_iff_metric.1 s_nhd in\n   let \u27e8N, H'\u27e9 := H \u03b5 \u03b5pos in mem_at_top_sets.2 \u27e8N, \u03bb n nN,\n   sub $ mem_ball.2 $ H' nN\u27e9\u27e9\n\n--Sutherland Exercise 6.26 (as setup for prop 17.6)\n\ntheorem lim_sequence_of_mem_closure {\u03b1 : Type*} [metric_space \u03b1] {Y : set \u03b1} {a : \u03b1} (H : a \u2208 closure Y) :\n\u2203 (f : \u2115 \u2192 \u03b1) (H1 : \u2200 (n : \u2115), f n \u2208 Y), filter.tendsto f at_top (nhds a)  := \nbegin\n  let ball_n := \u03bb (n : \u2115), ball a ((1 : \u211d)/n),  \n  have H1 : \u2200 (n : \u2115), nonempty {x : \u03b1 | x \u2208 (ball_n (n+1)) \u2229 Y},\n  { intro n,\n    apply @nonempty_of_exists _ (\u03bb _,true),\n    have H3 := set.exists_mem_of_ne_empty ((mem_closure_iff_nhds.1 H) (ball_n (n+1)) (ball_mem_nhds _ _)),\n    { cases H3 with xn Hxn,\n      existsi (\u27e8xn, Hxn\u27e9 : \u21a5{x : \u03b1 | x \u2208 ball_n (n+1) \u2229 Y}),\n      trivial },\n    apply div_pos, exact zero_lt_one, rw \u2190 nat.cast_zero, apply nat.cast_lt.2,\n    apply zero_lt_iff_ne_zero.2, apply nat.succ_ne_zero },\n  \n  have sequence := \u03bb (n : \u2115), classical.choice (H1 n),\n  let sequencevals := \u03bb (n : \u2115), (sequence n).val,\n  existsi sequencevals,\n\n  have H1 : \u2200 (n : \u2115), sequencevals n \u2208 Y,\n  { show \u2200 (n : \u2115), (sequence n).val \u2208 Y,\n    let sequenceprops := \u03bb (n : \u2115), ((sequence n).property).2,\n    exact sequenceprops },\n  existsi H1,\n  rw tendsto_nhds_iff _ _ _,\n  intros ep Hep,\n  let nat_one_over_ep := int.nat_abs (ceil (1/ep)),\n  existsi [{n : \u2115 | nat_one_over_ep \u2264 n}, _], swap,\n  { rw filter.mem_at_top_sets,\n    existsi nat_one_over_ep,\n    exact \u03bb b Hb, Hb }, \n\n  intros n Hn,\n  show dist (sequence n).val a < ep,\n    \n  have : dist (sequence n).val a < (1 / \u2191(n+1)) := (sequence n).property.1,\n  apply lt.trans this,\n  rw one_div_eq_inv,\n  \n  have H3: 0 < (\u2191(n + 1) : \u211d), \n  { rw \u2190 nat.cast_zero,\n    rw (@nat.cast_lt \u211d _ 0 (n+1)),\n    exact zero_lt_iff_ne_zero.2 (nat.succ_ne_zero n) },\n  rw (@inv_lt \u211d _ \u2191(n + 1) ep) H3 Hep,\n  dsimp at Hn, rw \u2190 one_div_eq_inv,\n  have H4 := nat.lt_succ_of_le Hn,\n  rw [nat.succ_eq_add_one, \u2190 @nat.cast_lt \u211d _ nat_one_over_ep (n+1)] at H4,\n  exact lt_of_le_of_lt (le_trans (le_ceil (1 / ep)) ((@int.cast_le \u211d _ _ _).2 (@int.le_nat_abs \u23081 / ep\u2309))) H4,  \nend\n\n--We think here of sequences as functions (f : \u2115 \u2192 \u03b1)\ndef metric_space.seq_cauchy [metric_space \u03b1] (u : \u2115 \u2192 \u03b1) : Prop := cauchy (filter.map u at_top)\n\nlemma metric_space.seq_cauchy_of_mathematician [metric_space \u03b1] (u : \u2115 \u2192 \u03b1) : \nmetric_space.seq_cauchy u \u2194 \u2200 \u03b5 > 0, \u2203 (N : \u2115), \u2200 {n m}, n \u2265 N \u2192 m \u2265 N \u2192 dist (u n) (u m) < \u03b5 :=\nbegin\n  split, \n  { intros H \u03b5 H\u03b5,\n    unfold metric_space.seq_cauchy at H,\n    rw cauchy_of_metric at H,\n    rcases H.2 \u03b5 H\u03b5 with \u27e8t, Ht, Ht2\u27e9,\n    rw [mem_map, mem_at_top_sets] at Ht,\n    cases Ht with N HN,\n    existsi N,\n    intros n m Hn Hm,\n    exact Ht2 (u n) (u m) (HN n Hn) (HN m Hm) },\n  intro H,\n  unfold metric_space.seq_cauchy, rw cauchy_of_metric,\n  apply and.intro _,\n  { intros \u03b5 H\u03b5,\n    cases H \u03b5 H\u03b5 with N HN,\n    existsi u '' {x : \u2115 | N \u2264 x},\n    existsi _, swap, \n    { rw [mem_map, mem_at_top_sets], existsi N, intros b Hb, rw [set.mem_set_of_eq, set.mem_image], \n    existsi b, exact \u27e8Hb, rfl\u27e9 },\n    intros x y Hx Hy,\n    rw set.mem_image at Hx,\n    rw set.mem_image at Hy,\n    cases Hx with n Hn,\n    cases Hy with m Hm,\n    have := HN Hn.1 Hm.1, rw Hn.2 at this, rw Hm.2 at this,\n    assumption },\n  exact map_ne_bot at_top_ne_bot,\nend\n\ndef metric_space.seq_tendsto [metric_space \u03b1] (u : \u2115 \u2192 \u03b1) (a : \u03b1) : Prop :=\n\u2200 \u03b5 > 0, \u2203 (N : \u2115), \u2200 {n}, n \u2265 N \u2192 dist (u n) a < \u03b5\n\n\nlemma metric_space.unique_limit_seq [metric_space \u03b1] (u : \u2115 \u2192 \u03b1) (a b : \u03b1)  \n  (Ha : metric_space.seq_tendsto u a) (Hb : metric_space.seq_tendsto u b) : a = b := \nbegin\n  unfold metric_space.seq_tendsto at Ha,\n  unfold metric_space.seq_tendsto at Hb,\n  apply metric_space.eq_of_dist_eq_zero,\n  by_contradiction Hnab,\n  cases @dist_nonneg _ _ a b, swap, cc,\n  cases Ha ((dist a b)/2) (div_pos h (by norm_num)) with N Ha1,\n  cases Hb ((dist a b)/2) (div_pos h (by norm_num)) with M Hb1,\n  let k := max N M,\n  have Ha2 : dist (u k) a < dist a b / 2:= Ha1 (le_max_left N M), \n  have Hb2 : dist (u k) b < dist a b / 2:= Hb1 (le_max_right N M),\n  rw dist_comm at Ha2,\n  have := add_lt_add Ha2 Hb2,\n  have this2 := dist_triangle a (u k) b,\n  have this3 := lt_of_le_of_lt this2 this,\n  rw [\u2190 two_mul, mul_div_cancel' (dist a b) two_ne_zero] at this3,\n  exact lt_irrefl (dist a b) this3,\nend\n\nlemma metric_space.cauchy_of_convergent [metric_space \u03b1] (u : \u2115 \u2192 \u03b1) (H : \u2203 (a : \u03b1), metric_space.seq_tendsto u a) : \n  metric_space.seq_cauchy u := \nbegin\n  rw metric_space.seq_cauchy_of_mathematician,\n  cases H with a Ha,\n  intros \u03b5 H\u03b5,\n  unfold metric_space.seq_tendsto at Ha,\n  cases Ha (\u03b5 / 2) (div_pos H\u03b5 (by norm_num)) with N HN,\n  existsi N,\n  intros n m Hn Hm,\n  have dist_m := HN Hm, rw dist_comm at dist_m,\n  have := add_lt_add (HN Hn) (dist_m), rw [\u2190 two_mul (\u03b5 / 2), mul_div_cancel' \u03b5 two_ne_zero] at this, \n  exact lt_of_le_of_lt (dist_triangle (u n) a (u m)) this,\nend\n\n\nlemma subtype.seq_cauchy [metric_space \u03b1] {Y : set \u03b1} (u : \u2115 \u2192 \u03b1) (H1 : \u2200 (n : \u2115), u n \u2208 Y) :\n  metric_space.seq_cauchy u \u2194 metric_space.seq_cauchy (\u03bb (n : \u2115), (\u27e8u n, H1 n\u27e9 : Y)) := \nby rw metric_space.seq_cauchy_of_mathematician; rw metric_space.seq_cauchy_of_mathematician; refl\n\n\nlemma subtype.seq_tendsto [metric_space \u03b1] {Y : set \u03b1} (u : \u2115 \u2192 \u03b1) (H1 : \u2200 (n : \u2115), u n \u2208 Y) {a : \u03b1} (H2 : a \u2208 Y) :\n  metric_space.seq_tendsto u a \u2194 metric_space.seq_tendsto (\u03bb (n : \u2115), (\u27e8u n, H1 n\u27e9 : Y)) \u27e8a, H2\u27e9 := by refl\n\n\ntheorem metric_space.convergent_of_cauchy_of_complete [metric_space \u03b1] (u : \u2115 \u2192 \u03b1) [complete_space \u03b1] \n  (H : metric_space.seq_cauchy u) :\n  \u2203 (x : \u03b1), metric_space.seq_tendsto u x := let \u27e8a, Ha\u27e9 := (complete_space.complete H) in \n    \u27e8a, by change tendsto u at_top (nhds a) at Ha; exact (seq_tendsto_iff u a).1 Ha\u27e9\n\n\n--Proposition 17.6\ntheorem closed_of_complete_subspace_of_metric {\u03b1 : Type*} [metric_space \u03b1] (Y : set \u03b1) [complete_space Y] :\nis_closed Y := \nbegin\n  rw \u2190 closure_eq_iff_is_closed, \n  apply set.eq_of_subset_of_subset,\n  { intros x Hx,\n    rcases lim_sequence_of_mem_closure Hx with \u27e8sequence, Hxn, Hsequence\u27e9,\n    rw seq_tendsto_iff at Hsequence,\n    have Ha := metric_space.convergent_of_cauchy_of_complete (\u03bb (n : \u2115), (\u27e8sequence n, Hxn n\u27e9 : Y)) \n      ((subtype.seq_cauchy sequence Hxn).1 (metric_space.cauchy_of_convergent sequence \u27e8x, Hsequence\u27e9)), \n    cases Ha with a Ha,\n    change metric_space.seq_tendsto (\u03bb (n : \u2115), (\u27e8sequence n, Hxn n\u27e9 : Y)) a at Ha,\n    cases a with a ha,\n    rw \u2190 subtype.seq_tendsto at Ha,\n    change metric_space.seq_tendsto sequence x at Hsequence,\n    change metric_space.seq_tendsto sequence a at Ha,\n    have H4 := metric_space.unique_limit_seq sequence x a Hsequence Ha,\n    rw H4, exact ha },\n  exact subset_closure,\nend\n\n--Lemma for following lemma   \n--Showing the filter definition of complete is equivalent to the sequences defintion for a metric space\nlemma complete_iff_seq_complete {\u03b1 : Type*} [metric_space \u03b1] :\n  complete_space \u03b1 \u2194 ( \u2200 (f : \u2115 \u2192 \u03b1), cauchy (filter.map f at_top) \u2192 (\u2203 (a : \u03b1), tendsto f at_top (nhds a))) :=\nbegin \n  split, intros H f Hf,\n    exact (@complete_space.complete _ _ H _ Hf),\n  intro H,\n  split,\n  intros filt Hfilt,\n  rw cauchy_of_metric at Hfilt,\n\n  have this1 : \u2200 n, 0 < (\u2191(n + 1) : \u211d) := by intro n; rw \u2190 nat.cast_zero; rw (@nat.cast_lt \u211d _ 0 (n+1)); exact zero_lt_iff_ne_zero.2 (nat.succ_ne_zero n),\n\n  have this2 := \u03bb (n : \u2115), (@div_pos \u211d _ 1 (n+1) (nat.cast_lt.2 (@zero_lt_one \u2115 _)) (this1 n)),\n    have this3 := \u03bb n, (Hfilt.2 ((1 : \u211d)/(n+1 : \u2115))) (this2 n),\n    have this4 := classical.axiom_of_choice (this3),\n\n    cases this4 with f Hf, dsimp at f, dsimp at Hf,\n    cases (classical.axiom_of_choice Hf) with Hf1 Hf2,\n    dsimp at Hf1, dsimp at Hf2,\n    \n    have H3 : \u2200 n, (f n) \u2260 \u2205,\n      intro n,\n      by_contradiction,\n      rw not_not at a,\n      have H2 := Hf1 n,\n      rw a at H2,\n      have H1 := empty_in_sets_eq_bot.1 H2,\n      cc,\n\n    have H4 : \u2200 n, nonempty (f n),\n    intro n, \n    cases set.exists_mem_of_ne_empty (H3 n) with x Hx,\n    constructor,\n    exact \u27e8x, Hx\u27e9,  \n   \n \n    have seq_prop_better : \u2200 (n : \u2115), \u2203 (S : set \u03b1), (\u2200 (m : \u2115), m \u2264 n \u2192 (S \u2286 (f m))) \u2227 S \u2208 filt.sets,\n      intro n, induction n with N HN,\n      existsi (f 0),\n      exact \u27e8\u03bb n Hn, by rw (le_zero_iff_eq.1 Hn); exact (set.subset.refl (f 0)), Hf1 0\u27e9,\n      cases HN with S0 HS0,\n      existsi S0 \u2229 (f (N+1)),\n      refine \u27e8_,inter_mem_sets HS0.2 (Hf1 (N+1))\u27e9,\n      intro n,\n      by_cases (n \u2264 N),\n      exact \u03bb _ x Hx, (HS0.1 n h) Hx.1,\n      rw not_le at h,\n      intro Hn,\n\n      rw (le_antisymm Hn (nat.succ_le_of_lt h)),\n      intros x Hx, exact Hx.2,\n\n    have seq_prop2 := classical.axiom_of_choice seq_prop_better, dsimp at seq_prop2,\n    cases seq_prop2 with seqsets Hseqsets,\n    \n    have Hnonempty : \u2200 n, nonempty (seqsets n),\n      intro n,\n        have Hnotempty : seqsets n \u2260 \u2205,\n        by_contradiction,\n        rw not_not at a,\n        have := Hseqsets n,\n        rw a at this,\n        have := empty_in_sets_eq_bot.1 this.2,\n        cc,\n      cases set.exists_mem_of_ne_empty Hnotempty,  \n      constructor, exact \u27e8w,h\u27e9,\n    have seq := \u03bb (n : \u2115), classical.choice (Hnonempty n),\n\n    have FGI : cauchy (map (\u03bb (n : \u2115), (seq n).val) at_top),\n      rw cauchy_of_metric,\n      apply and.intro (map_ne_bot at_top_ne_bot),\n      intros \u03b5 H\u03b5,\n      existsi (f (int.nat_abs (ceil ((1:\u211d)/\u03b5)))),\n      have Hnext : f (int.nat_abs \u23081 / \u03b5\u2309) \u2208 (map (\u03bb (n : \u2115), (seq n).val) at_top).sets,\n        rw mem_map,\n        rw mem_at_top_sets,\n        existsi (int.nat_abs \u23081 / \u03b5\u2309),\n        intros m Hm,\n        exact (Hseqsets m).1 (int.nat_abs \u23081 / \u03b5\u2309) Hm (seq m).property,        \n      existsi Hnext,      \n      intros x y Hx Hy,\n      \n      have exciting := Hf2 (int.nat_abs \u23081 / \u03b5\u2309) x y Hx Hy,\n       have Hnext3 : 1/\u03b5 > 0,\n            apply (mul_lt_mul_right H\u03b5).1,\n            rw one_div_eq_inv, rw zero_mul,\n            rw inv_mul_cancel (ne.symm (ne_of_lt H\u03b5)),\n            exact zero_lt_one,\n      have Hnext2 : ceil (1/\u03b5) \u2265 0,\n          exact le_of_lt (ceil_pos.2 Hnext3),\n      have Hnext : 1 / (\u2191(int.nat_abs \u23081 / \u03b5\u2309) + 1) < \u03b5,\n        \n        rw [\u2190 int.cast_coe_nat (int.nat_abs _), int.nat_abs_of_nonneg Hnext2],\n        have Hfornext4 := lt_add_one (\u2191\u23081 / \u03b5\u2309 : \u211d),\n          \n        have Hnext4 : (1 : \u211d) / (\u2191\u23081 / \u03b5\u2309 + 1) < 1 / (\u2191\u23081 / \u03b5\u2309),\n          exact one_div_lt_one_div_of_lt (int.cast_lt.2 (ceil_pos.2 Hnext3)) Hfornext4,\n        apply lt_of_lt_of_le Hnext4,\n        have Hnext5 := le_ceil (1/\u03b5),\n        have Hnext6 := one_div_le_one_div_of_le Hnext3 Hnext5,\n        apply le_trans Hnext6,\n        simp,\n        exact lt_trans exciting Hnext,\n        exact \u27e80\u27e9, \n\n  have := H (\u03bb n, (seq n).1) FGI,\n  cases this with a Ha,\n  existsi a,\n  unfold tendsto at Ha,\n  intros S HS,\n\n  rcases mem_nhds_sets_iff.1 HS with \u27e8S1, HS1, H2S1\u27e9,\n  rcases is_open_metric.1 H2S1.1 a H2S1.2 with \u27e8\u03b5, H\u03b5, Hball\u03b5\u27e9,\n\n  have Hepover2 : \u03b5/2 > 0 := div_pos H\u03b5 (by norm_num),\n  cases (seq_tendsto_iff (\u03bb (n : \u2115), (seq n).val) a).1 Ha (\u03b5/2) Hepover2 with N1 HN1,\n  \n  let N := max N1 (int.nat_abs \u23082 / \u03b5\u2309),\n\n  have HS3 : f N \u2286 ball a \u03b5,\n    intros x Hx,\n    rw mem_ball,\n    dsimp at HN1,\n    have distance1 := Hf2 N x (seq N).val Hx ((Hseqsets N).1 N (le_refl N) (seq N).property),\n    have lt_\u03b5over2 : 1 / (\u2191N + 1) < \u03b5 / 2,\n      have le_somth := le_max_right N1 (int.nat_abs \u23082 / \u03b5\u2309),\n      have twoovereplt : 2 / \u03b5 < \u2191(nat.succ N),\n        apply lt_of_le_of_lt (le_ceil (2/\u03b5)),\n        have N_ge_ceil : int.nat_abs \u23082 / \u03b5\u2309 \u2264 N, \n        exact le_max_right _ _,\n        have N_ge_ceil2 : ((int.nat_abs \u23082 / \u03b5\u2309) : \u211d) \u2264 \u2191N := nat.cast_le.2 N_ge_ceil,\n        have zero_le_ceiltwooverep : (0 : \u2124) \u2264 \u23082 / \u03b5\u2309,\n        have zero_lt_twooverep : 0 < 2/\u03b5,\n        have := div_div_eq_mul_div 1 2 \u03b5,\n        simp at this,\n        rw \u2190 this at Hepover2,\n        exact inv_pos'.1 Hepover2,\n        apply int.cast_le.1,\n        refine le_of_lt (lt_of_lt_of_le zero_lt_twooverep _),\n        exact le_ceil _,\n\n        have := int.nat_abs_of_nonneg zero_le_ceiltwooverep,\n        change (((int.nat_abs \u23082 / \u03b5\u2309) : \u2124) : \u211d) \u2264 _ at N_ge_ceil2,\n        rw this at N_ge_ceil2,\n        refine lt_of_le_of_lt N_ge_ceil2 _,\n        simp [zero_lt_one],\n\n      have := (inv_lt_inv  (nat.cast_lt.2 (nat.zero_lt_succ N) : (0 : \u211d) < _) \n        (div_pos (by norm_num) H\u03b5 : (2 : \u211d)/\u03b5 > 0)).2 twoovereplt,\n      rw inv_eq_one_div at this, rw inv_eq_one_div at this,\n      rw div_div_eq_mul_div at this, rw one_mul at this,\n      exact this,\n\n    have distance2 := HN1 (le_max_left N1 (int.nat_abs \u23082 / \u03b5\u2309)),\n    have distance3 := dist_triangle x (seq N).val a,\n    have distance4 := add_lt_add (lt_trans distance1 lt_\u03b5over2) distance2,\n    have distance5 := lt_of_le_of_lt distance3 distance4,\n    rw add_halves at distance5, exact distance5,\n  \n  apply mem_sets_of_superset (Hf1 N),\n  exact set.subset.trans (set.subset.trans HS3 Hball\u03b5) HS1,\n\nend\n\n--Proposition 17.7\ntheorem complete_of_closed_subspace_of_complete {\u03b1 : Type*} [metric_space \u03b1] [complete_space \u03b1] \n(Y : set \u03b1) (HY : is_closed Y) : complete_space Y := \nbegin\n  rw complete_iff_seq_complete,\n  intros f Hf,\n  rw complete_iff_seq_complete at _inst_2,\n  have : metric_space.seq_cauchy f := Hf,\n  have this2 : f = (\u03bb (n : \u2115), (\u27e8(f n).val, (f n).property\u27e9 : Y)),\n  { simp },\n  rw this2 at this,\n  cases _inst_2 (\u03bb n, (f n).val) ((subtype.seq_cauchy _ _).2 this) with a Ha,\n  have H2 : a \u2208 Y,  \n  { apply mem_of_closed_of_tendsto at_top_ne_bot Ha HY,\n  rw mem_at_top_sets, existsi 0, exact \u03bb n _, (f n).property },\n  existsi (\u27e8a, H2\u27e9 : Y),\n  have H3 := subtype.seq_tendsto (\u03bb n, (f n).val) (\u03bb n, (f n).property) H2,\n  simp at H3,\n  rw seq_tendsto_iff,\n  apply H3.1,\n  exact (seq_tendsto_iff (\u03bb (n : \u2115), (f n).val) a).1 Ha\nend\n\ndef subseq {\u03b1 : Type*} (f : \u2115 \u2192 \u03b1) (u : \u2115 \u2192 \u03b1) := \u2203 (map : \u2115 \u2192 \u2115), u = f \u2218 map \u2227 tendsto map at_top at_top\n--tendsto map at_top at_top is the same as being a subsequence, but we don't require strict increasingness\n\n--Prop 17.10\ntheorem convergent_of_cauchy_of_subseq_convergent {\u03b1 : Type*} [metric_space \u03b1] {f : \u2115 \u2192 \u03b1} (H : cauchy (filter.map f at_top))\n {sub : \u2115 \u2192 \u03b1} (H1 : subseq sub f) {x : \u03b1} (H2 : metric_space.seq_tendsto sub x) : metric_space.seq_tendsto f x := \nbegin\n  unfold subseq at H1,\n  cases H1 with map Hmap,\n  rw Hmap.1,\n  unfold tendsto at Hmap,\n  unfold metric_space.seq_tendsto, rw \u2190 seq_tendsto_iff,\n  unfold metric_space.seq_tendsto at H2, rw \u2190 seq_tendsto_iff at H2,\n  apply tendsto.comp,\n  { exact tendsto_id },\n  apply tendsto.comp,\n  { exact Hmap.2 },\n  exact H2,\nend\n\ntheorem convergent_of_cauchy_of_subseq_convergent' {\u03b1 : Type*} [metric_space \u03b1] {f : \u2115 \u2192 \u03b1} (H : cauchy (filter.map f at_top))\n {sub : \u2115 \u2192 \u03b1} (H1 : subseq sub f) {x : \u03b1} (H2 : metric_space.seq_tendsto sub x) : metric_space.seq_tendsto f x :=\nbegin\n  cases H1 with map Hmap,\n  rw Hmap.1, unfold tendsto at Hmap, unfold metric_space.seq_tendsto, \n  rw \u2190 seq_tendsto_iff,\n  unfold metric_space.seq_tendsto at H2,\n  rw \u2190 seq_tendsto_iff at H2, exact tendsto.comp tendsto_id (tendsto.comp Hmap.2 H2),\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/Topology/Material/topological_sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7390700803696446}}
{"text": "/-\nCopyright (c) 2019 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou, Yury Kudryashov, S\u00e9bastien Gou\u00ebzel, R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module measure_theory.integral.bochner\n! leanprover-community/mathlib commit fbde2f60a46865c85f49b4193175c6e339ff9020\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Integral.SetToL1\n\n/-!\n# Bochner integral\n\nThe Bochner integral extends the definition of the Lebesgue integral to functions that map from a\nmeasure space into a Banach space (complete normed vector space). It is constructed here by\nextending the integral on simple functions.\n\n## Main definitions\n\nThe Bochner integral is defined through the extension process described in the file `set_to_L1`,\nwhich follows these steps:\n\n1. Define the integral of the indicator of a set. This is `weighted_smul \u03bc s x = (\u03bc s).to_real * x`.\n  `weighted_smul \u03bc` is shown to be linear in the value `x` and `dominated_fin_meas_additive`\n  (defined in the file `set_to_L1`) with respect to the set `s`.\n\n2. Define the integral on simple functions of the type `simple_func \u03b1 E` (notation : `\u03b1 \u2192\u209b E`)\n  where `E` is a real normed space. (See `simple_func.integral` for details.)\n\n3. Transfer this definition to define the integral on `L1.simple_func \u03b1 E` (notation :\n  `\u03b1 \u2192\u2081\u209b[\u03bc] E`), see `L1.simple_func.integral`. Show that this integral is a continuous linear\n  map from `\u03b1 \u2192\u2081\u209b[\u03bc] E` to `E`.\n\n4. Define the Bochner integral on L1 functions by extending the integral on integrable simple\n  functions `\u03b1 \u2192\u2081\u209b[\u03bc] E` using `continuous_linear_map.extend` and the fact that the embedding of\n  `\u03b1 \u2192\u2081\u209b[\u03bc] E` into `\u03b1 \u2192\u2081[\u03bc] E` is dense.\n\n5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1\n  space, if it is in L1, and 0 otherwise.\n\nThe result of that construction is `\u222b a, f a \u2202\u03bc`, which is definitionally equal to\n`set_to_fun (dominated_fin_meas_additive_weighted_smul \u03bc) f`. Some basic properties of the integral\n(like linearity) are particular cases of the properties of `set_to_fun` (which are described in the\nfile `set_to_L1`).\n\n## Main statements\n\n1. Basic properties of the Bochner integral on functions of type `\u03b1 \u2192 E`, where `\u03b1` is a measure\n   space and `E` is a real normed space.\n\n  * `integral_zero`                  : `\u222b 0 \u2202\u03bc = 0`\n  * `integral_add`                   : `\u222b x, f x + g x \u2202\u03bc = \u222b x, f \u2202\u03bc + \u222b x, g x \u2202\u03bc`\n  * `integral_neg`                   : `\u222b x, - f x \u2202\u03bc = - \u222b x, f x \u2202\u03bc`\n  * `integral_sub`                   : `\u222b x, f x - g x \u2202\u03bc = \u222b x, f x \u2202\u03bc - \u222b x, g x \u2202\u03bc`\n  * `integral_smul`                  : `\u222b x, r \u2022 f x \u2202\u03bc = r \u2022 \u222b x, f x \u2202\u03bc`\n  * `integral_congr_ae`              : `f =\u1d50[\u03bc] g \u2192 \u222b x, f x \u2202\u03bc = \u222b x, g x \u2202\u03bc`\n  * `norm_integral_le_integral_norm` : `\u2016\u222b x, f x \u2202\u03bc\u2016 \u2264 \u222b x, \u2016f x\u2016 \u2202\u03bc`\n\n2. Basic properties of the Bochner integral on functions of type `\u03b1 \u2192 \u211d`, where `\u03b1` is a measure\n  space.\n\n  * `integral_nonneg_of_ae` : `0 \u2264\u1d50[\u03bc] f \u2192 0 \u2264 \u222b x, f x \u2202\u03bc`\n  * `integral_nonpos_of_ae` : `f \u2264\u1d50[\u03bc] 0 \u2192 \u222b x, f x \u2202\u03bc \u2264 0`\n  * `integral_mono_ae`      : `f \u2264\u1d50[\u03bc] g \u2192 \u222b x, f x \u2202\u03bc \u2264 \u222b x, g x \u2202\u03bc`\n  * `integral_nonneg`       : `0 \u2264 f \u2192 0 \u2264 \u222b x, f x \u2202\u03bc`\n  * `integral_nonpos`       : `f \u2264 0 \u2192 \u222b x, f x \u2202\u03bc \u2264 0`\n  * `integral_mono`         : `f \u2264\u1d50[\u03bc] g \u2192 \u222b x, f x \u2202\u03bc \u2264 \u222b x, g x \u2202\u03bc`\n\n3. Propositions connecting the Bochner integral with the integral on `\u211d\u22650\u221e`-valued functions,\n   which is called `lintegral` and has the notation `\u222b\u207b`.\n\n  * `integral_eq_lintegral_max_sub_lintegral_min` : `\u222b x, f x \u2202\u03bc = \u222b\u207b x, f\u207a x \u2202\u03bc - \u222b\u207b x, f\u207b x \u2202\u03bc`,\n    where `f\u207a` is the positive part of `f` and `f\u207b` is the negative part of `f`.\n  * `integral_eq_lintegral_of_nonneg_ae`          : `0 \u2264\u1d50[\u03bc] f \u2192 \u222b x, f x \u2202\u03bc = \u222b\u207b x, f x \u2202\u03bc`\n\n4. `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem\n\n5. (In the file `set_integral`) integration commutes with continuous linear maps.\n\n  * `continuous_linear_map.integral_comp_comm`\n  * `linear_isometry.integral_comp_comm`\n\n\n## Notes\n\nSome tips on how to prove a proposition if the API for the Bochner integral is not enough so that\nyou need to unfold the definition of the Bochner integral and go back to simple functions.\n\nOne method is to use the theorem `integrable.induction` in the file `simple_func_dense_lp` (or one\nof the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove\nsomething for an arbitrary integrable function.\n\nAnother method is using the following steps.\nSee `integral_eq_lintegral_max_sub_lintegral_min` for a complicated example, which proves that\n`\u222b f = \u222b\u207b f\u207a - \u222b\u207b f\u207b`, with the first integral sign being the Bochner integral of a real-valued\nfunction `f : \u03b1 \u2192 \u211d`, and second and third integral sign being the integral on `\u211d\u22650\u221e`-valued\nfunctions (called `lintegral`). The proof of `integral_eq_lintegral_max_sub_lintegral_min` is\nscattered in sections with the name `pos_part`.\n\nHere are the usual steps of proving that a property `p`, say `\u222b f = \u222b\u207b f\u207a - \u222b\u207b f\u207b`, holds for all\nfunctions :\n\n1. First go to the `L\u00b9` space.\n\n   For example, if you see `ennreal.to_real (\u222b\u207b a, ennreal.of_real $ \u2016f a\u2016)`, that is the norm of\n   `f` in `L\u00b9` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.\n\n2. Show that the set `{f \u2208 L\u00b9 | \u222b f = \u222b\u207b f\u207a - \u222b\u207b f\u207b}` is closed in `L\u00b9` using `is_closed_eq`.\n\n3. Show that the property holds for all simple functions `s` in `L\u00b9` space.\n\n   Typically, you need to convert various notions to their `simple_func` counterpart, using lemmas\n   like `L1.integral_coe_eq_integral`.\n\n4. Since simple functions are dense in `L\u00b9`,\n```\nuniv = closure {s simple}\n     = closure {s simple | \u222b s = \u222b\u207b s\u207a - \u222b\u207b s\u207b} : the property holds for all simple functions\n     \u2286 closure {f | \u222b f = \u222b\u207b f\u207a - \u222b\u207b f\u207b}\n     = {f | \u222b f = \u222b\u207b f\u207a - \u222b\u207b f\u207b} : closure of a closed set is itself\n```\nUse `is_closed_property` or `dense_range.induction_on` for this argument.\n\n## Notations\n\n* `\u03b1 \u2192\u209b E`  : simple functions (defined in `measure_theory/integration`)\n* `\u03b1 \u2192\u2081[\u03bc] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in\n                `measure_theory/lp_space`)\n* `\u03b1 \u2192\u2081\u209b[\u03bc] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple\n                 functions (defined in `measure_theory/simple_func_dense`)\n* `\u222b a, f a \u2202\u03bc` : integral of `f` with respect to a measure `\u03bc`\n* `\u222b a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type\n\nWe also define notations for integral on a set, which are described in the file\n`measure_theory/set_integral`.\n\nNote : `\u209b` is typed using `\\_s`. Sometimes it shows as a box if the font is missing.\n\n## Tags\n\nBochner integral, simple function, function space, Lebesgue dominated convergence theorem\n\n-/\n\n\nnoncomputable section\n\nopen Topology BigOperators NNReal ENNReal MeasureTheory\n\nopen Set Filter TopologicalSpace ENNReal Emetric\n\nnamespace MeasureTheory\n\nvariable {\u03b1 E F \ud835\udd5c : Type _}\n\nsection WeightedSmul\n\nopen ContinuousLinearMap\n\nvariable [NormedAddCommGroup F] [NormedSpace \u211d F] {m : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n\n/-- Given a set `s`, return the continuous linear map `\u03bb x, (\u03bc s).to_real \u2022 x`. The extension of\nthat set function through `set_to_L1` gives the Bochner integral of L1 functions. -/\ndef weightedSmul {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (s : Set \u03b1) : F \u2192L[\u211d] F :=\n  (\u03bc s).toReal \u2022 ContinuousLinearMap.id \u211d F\n#align measure_theory.weighted_smul MeasureTheory.weightedSmul\n\ntheorem weightedSmul_apply {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (s : Set \u03b1) (x : F) :\n    weightedSmul \u03bc s x = (\u03bc s).toReal \u2022 x := by simp [weighted_smul]\n#align measure_theory.weighted_smul_apply MeasureTheory.weightedSmul_apply\n\n@[simp]\ntheorem weightedSmul_zero_measure {m : MeasurableSpace \u03b1} :\n    weightedSmul (0 : Measure \u03b1) = (0 : Set \u03b1 \u2192 F \u2192L[\u211d] F) :=\n  by\n  ext1\n  simp [weighted_smul]\n#align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSmul_zero_measure\n\n@[simp]\ntheorem weightedSmul_empty {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) :\n    weightedSmul \u03bc \u2205 = (0 : F \u2192L[\u211d] F) := by\n  ext1 x\n  rw [weighted_smul_apply]\n  simp\n#align measure_theory.weighted_smul_empty MeasureTheory.weightedSmul_empty\n\ntheorem weightedSmul_add_measure {m : MeasurableSpace \u03b1} (\u03bc \u03bd : Measure \u03b1) {s : Set \u03b1}\n    (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bds : \u03bd s \u2260 \u221e) :\n    (weightedSmul (\u03bc + \u03bd) s : F \u2192L[\u211d] F) = weightedSmul \u03bc s + weightedSmul \u03bd s :=\n  by\n  ext1 x\n  push_cast\n  simp_rw [Pi.add_apply, weighted_smul_apply]\n  push_cast\n  rw [Pi.add_apply, ENNReal.toReal_add h\u03bcs h\u03bds, add_smul]\n#align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSmul_add_measure\n\ntheorem weightedSmul_smul_measure {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (c : \u211d\u22650\u221e) {s : Set \u03b1} :\n    (weightedSmul (c \u2022 \u03bc) s : F \u2192L[\u211d] F) = c.toReal \u2022 weightedSmul \u03bc s :=\n  by\n  ext1 x\n  push_cast\n  simp_rw [Pi.smul_apply, weighted_smul_apply]\n  push_cast\n  simp_rw [Pi.smul_apply, smul_eq_mul, to_real_mul, smul_smul]\n#align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSmul_smul_measure\n\ntheorem weightedSmul_congr (s t : Set \u03b1) (hst : \u03bc s = \u03bc t) :\n    (weightedSmul \u03bc s : F \u2192L[\u211d] F) = weightedSmul \u03bc t :=\n  by\n  ext1 x\n  simp_rw [weighted_smul_apply]\n  congr 2\n#align measure_theory.weighted_smul_congr MeasureTheory.weightedSmul_congr\n\ntheorem weightedSmul_null {s : Set \u03b1} (h_zero : \u03bc s = 0) : (weightedSmul \u03bc s : F \u2192L[\u211d] F) = 0 :=\n  by\n  ext1 x\n  rw [weighted_smul_apply, h_zero]\n  simp\n#align measure_theory.weighted_smul_null MeasureTheory.weightedSmul_null\n\ntheorem weightedSmul_union' (s t : Set \u03b1) (ht : MeasurableSet t) (hs_finite : \u03bc s \u2260 \u221e)\n    (ht_finite : \u03bc t \u2260 \u221e) (h_inter : s \u2229 t = \u2205) :\n    (weightedSmul \u03bc (s \u222a t) : F \u2192L[\u211d] F) = weightedSmul \u03bc s + weightedSmul \u03bc t :=\n  by\n  ext1 x\n  simp_rw [add_apply, weighted_smul_apply,\n    measure_union (set.disjoint_iff_inter_eq_empty.mpr h_inter) ht,\n    ENNReal.toReal_add hs_finite ht_finite, add_smul]\n#align measure_theory.weighted_smul_union' MeasureTheory.weightedSmul_union'\n\n@[nolint unused_arguments]\ntheorem weightedSmul_union (s t : Set \u03b1) (hs : MeasurableSet s) (ht : MeasurableSet t)\n    (hs_finite : \u03bc s \u2260 \u221e) (ht_finite : \u03bc t \u2260 \u221e) (h_inter : s \u2229 t = \u2205) :\n    (weightedSmul \u03bc (s \u222a t) : F \u2192L[\u211d] F) = weightedSmul \u03bc s + weightedSmul \u03bc t :=\n  weightedSmul_union' s t ht hs_finite ht_finite h_inter\n#align measure_theory.weighted_smul_union MeasureTheory.weightedSmul_union\n\ntheorem weightedSmul_smul [NormedField \ud835\udd5c] [NormedSpace \ud835\udd5c F] [SMulCommClass \u211d \ud835\udd5c F] (c : \ud835\udd5c)\n    (s : Set \u03b1) (x : F) : weightedSmul \u03bc s (c \u2022 x) = c \u2022 weightedSmul \u03bc s x := by\n  simp_rw [weighted_smul_apply, smul_comm]\n#align measure_theory.weighted_smul_smul MeasureTheory.weightedSmul_smul\n\ntheorem norm_weightedSmul_le (s : Set \u03b1) : \u2016(weightedSmul \u03bc s : F \u2192L[\u211d] F)\u2016 \u2264 (\u03bc s).toReal :=\n  calc\n    \u2016(weightedSmul \u03bc s : F \u2192L[\u211d] F)\u2016 = \u2016(\u03bc s).toReal\u2016 * \u2016ContinuousLinearMap.id \u211d F\u2016 :=\n      norm_smul _ _\n    _ \u2264 \u2016(\u03bc s).toReal\u2016 :=\n      ((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le)\n    _ = abs (\u03bc s).toReal := (Real.norm_eq_abs _)\n    _ = (\u03bc s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg\n    \n#align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSmul_le\n\ntheorem dominatedFinMeasAdditiveWeightedSmul {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) :\n    DominatedFinMeasAdditive \u03bc (weightedSmul \u03bc : Set \u03b1 \u2192 F \u2192L[\u211d] F) 1 :=\n  \u27e8weightedSmul_union, fun s _ _ => (norm_weightedSmul_le s).trans (one_mul _).symm.le\u27e9\n#align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditiveWeightedSmul\n\ntheorem weightedSmul_nonneg (s : Set \u03b1) (x : \u211d) (hx : 0 \u2264 x) : 0 \u2264 weightedSmul \u03bc s x :=\n  by\n  simp only [weighted_smul, Algebra.id.smul_eq_mul, coe_smul', id.def, coe_id', Pi.smul_apply]\n  exact mul_nonneg to_real_nonneg hx\n#align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSmul_nonneg\n\nend WeightedSmul\n\n-- mathport name: \u00abexpr \u2192\u209b \u00bb\nlocal infixr:25 \" \u2192\u209b \" => SimpleFunc\n\nnamespace SimpleFunc\n\nsection PosPart\n\nvariable [LinearOrder E] [Zero E] [MeasurableSpace \u03b1]\n\n/-- Positive part of a simple function. -/\ndef posPart (f : \u03b1 \u2192\u209b E) : \u03b1 \u2192\u209b E :=\n  f.map fun b => max b 0\n#align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart\n\n/-- Negative part of a simple function. -/\ndef negPart [Neg E] (f : \u03b1 \u2192\u209b E) : \u03b1 \u2192\u209b E :=\n  posPart (-f)\n#align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart\n\ntheorem posPart_map_norm (f : \u03b1 \u2192\u209b \u211d) : (posPart f).map norm = posPart f :=\n  by\n  ext\n  rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]\n  exact le_max_right _ _\n#align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm\n\ntheorem negPart_map_norm (f : \u03b1 \u2192\u209b \u211d) : (negPart f).map norm = negPart f :=\n  by\n  rw [neg_part]\n  exact pos_part_map_norm _\n#align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm\n\ntheorem posPart_sub_negPart (f : \u03b1 \u2192\u209b \u211d) : f.posPart - f.negPart = f :=\n  by\n  simp only [pos_part, neg_part]\n  ext a\n  rw [coe_sub]\n  exact max_zero_sub_eq_self (f a)\n#align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart\n\nend PosPart\n\nsection Integral\n\n/-!\n### The Bochner integral of simple functions\n\nDefine the Bochner integral of simple functions of the type `\u03b1 \u2192\u209b \u03b2` where `\u03b2` is a normed group,\nand prove basic property of this integral.\n-/\n\n\nopen Finset\n\nvariable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace \u211d F] {p : \u211d\u22650\u221e} {G F' : Type _}\n  [NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace \u211d F'] {m : MeasurableSpace \u03b1}\n  {\u03bc : Measure \u03b1}\n\n/-- Bochner integral of simple functions whose codomain is a real `normed_space`.\nThis is equal to `\u2211 x in f.range, (\u03bc (f \u207b\u00b9' {x})).to_real \u2022 x` (see `integral_eq`). -/\ndef integral {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (f : \u03b1 \u2192\u209b F) : F :=\n  f.setToSimpleFunc (weightedSmul \u03bc)\n#align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral\n\ntheorem integral_def {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (f : \u03b1 \u2192\u209b F) :\n    f.integral \u03bc = f.setToSimpleFunc (weightedSmul \u03bc) :=\n  rfl\n#align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def\n\ntheorem integral_eq {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (f : \u03b1 \u2192\u209b F) :\n    f.integral \u03bc = \u2211 x in f.range, (\u03bc (f \u207b\u00b9' {x})).toReal \u2022 x := by\n  simp [integral, set_to_simple_func, weighted_smul_apply]\n#align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq\n\ntheorem integral_eq_sum_filter [DecidablePred fun x : F => x \u2260 0] {m : MeasurableSpace \u03b1}\n    (f : \u03b1 \u2192\u209b F) (\u03bc : Measure \u03b1) :\n    f.integral \u03bc = \u2211 x in f.range.filter\u2093 fun x => x \u2260 0, (\u03bc (f \u207b\u00b9' {x})).toReal \u2022 x :=\n  by\n  rw [integral_def, set_to_simple_func_eq_sum_filter]\n  simp_rw [weighted_smul_apply]\n  congr\n#align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter\n\n/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/\ntheorem integral_eq_sum_of_subset [DecidablePred fun x : F => x \u2260 0] {f : \u03b1 \u2192\u209b F} {s : Finset F}\n    (hs : (f.range.filter\u2093 fun x => x \u2260 0) \u2286 s) :\n    f.integral \u03bc = \u2211 x in s, (\u03bc (f \u207b\u00b9' {x})).toReal \u2022 x :=\n  by\n  rw [simple_func.integral_eq_sum_filter, Finset.sum_subset hs]\n  rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne.def, Classical.not_not] at hx\n  rcases hx with (hx | rfl) <;> [skip, simp]\n  rw [simple_func.mem_range] at hx;\n  rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx]\n#align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset\n\n@[simp]\ntheorem integral_const {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (y : F) :\n    (const \u03b1 y).integral \u03bc = (\u03bc univ).toReal \u2022 y := by\n  classical calc\n      (const \u03b1 y).integral \u03bc = \u2211 z in {y}, (\u03bc (const \u03b1 y \u207b\u00b9' {z})).toReal \u2022 z :=\n        integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _)\n      _ = (\u03bc univ).toReal \u2022 y := by simp\n      \n#align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const\n\n@[simp]\ntheorem integral_piecewise_zero {m : MeasurableSpace \u03b1} (f : \u03b1 \u2192\u209b F) (\u03bc : Measure \u03b1) {s : Set \u03b1}\n    (hs : MeasurableSet s) : (piecewise s hs f 0).integral \u03bc = f.integral (\u03bc.restrict s) := by\n  classical\n    refine'\n      (integral_eq_sum_of_subset _).trans\n        ((sum_congr rfl fun y hy => _).trans (integral_eq_sum_filter _ _).symm)\n    \u00b7 intro y hy\n      simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,\n        mem_range_indicator] at *\n      rcases hy with \u27e8\u27e8rfl, -\u27e9 | \u27e8x, hxs, rfl\u27e9, h\u2080\u27e9\n      exacts[(h\u2080 rfl).elim, \u27e8Set.mem_range_self _, h\u2080\u27e9]\n    \u00b7 dsimp\n      rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem,\n        measure.restrict_apply (f.measurable_set_preimage _)]\n      exact fun h\u2080 => (mem_filter.1 hy).2 (Eq.symm h\u2080)\n#align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero\n\n/-- Calculate the integral of `g \u2218 f : \u03b1 \u2192\u209b F`, where `f` is an integrable function from `\u03b1` to `E`\n    and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g \u2218 f` is integrable. -/\ntheorem map_integral (f : \u03b1 \u2192\u209b E) (g : E \u2192 F) (hf : Integrable f \u03bc) (hg : g 0 = 0) :\n    (f.map g).integral \u03bc = \u2211 x in f.range, ENNReal.toReal (\u03bc (f \u207b\u00b9' {x})) \u2022 g x :=\n  map_setToSimpleFunc _ weightedSmul_union hf hg\n#align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral\n\n/-- `simple_func.integral` and `simple_func.lintegral` agree when the integrand has type\n    `\u03b1 \u2192\u209b \u211d\u22650\u221e`. But since `\u211d\u22650\u221e` is not a `normed_space`, we need some form of coercion.\n    See `integral_eq_lintegral` for a simpler version. -/\ntheorem integral_eq_lintegral' {f : \u03b1 \u2192\u209b E} {g : E \u2192 \u211d\u22650\u221e} (hf : Integrable f \u03bc) (hg0 : g 0 = 0)\n    (ht : \u2200 b, g b \u2260 \u221e) :\n    (f.map (ENNReal.toReal \u2218 g)).integral \u03bc = ENNReal.toReal (\u222b\u207b a, g (f a) \u2202\u03bc) :=\n  by\n  have hf' : f.fin_meas_supp \u03bc := integrable_iff_fin_meas_supp.1 hf\n  simp only [\u2190 map_apply g f, lintegral_eq_lintegral]\n  rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum]\n  \u00b7 refine' Finset.sum_congr rfl fun b hb => _\n    rw [smul_eq_mul, to_real_mul, mul_comm]\n  \u00b7 intro a ha\n    by_cases a0 : a = 0\n    \u00b7 rw [a0, hg0, MulZeroClass.zero_mul]\n      exact WithTop.zero_ne_top\n    \u00b7 apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).Ne\n  \u00b7 simp [hg0]\n#align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral'\n\nvariable [NormedField \ud835\udd5c] [NormedSpace \ud835\udd5c E] [NormedSpace \u211d E] [SMulCommClass \u211d \ud835\udd5c E]\n\ntheorem integral_congr {f g : \u03b1 \u2192\u209b E} (hf : Integrable f \u03bc) (h : f =\u1d50[\u03bc] g) :\n    f.integral \u03bc = g.integral \u03bc :=\n  setToSimpleFunc_congr (weightedSmul \u03bc) (fun s hs => weightedSmul_null) weightedSmul_union hf h\n#align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr\n\n/-- `simple_func.bintegral` and `simple_func.integral` agree when the integrand has type\n    `\u03b1 \u2192\u209b \u211d\u22650\u221e`. But since `\u211d\u22650\u221e` is not a `normed_space`, we need some form of coercion. -/\ntheorem integral_eq_lintegral {f : \u03b1 \u2192\u209b \u211d} (hf : Integrable f \u03bc) (h_pos : 0 \u2264\u1d50[\u03bc] f) :\n    f.integral \u03bc = ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal (f a) \u2202\u03bc) :=\n  by\n  have : f =\u1d50[\u03bc] f.map (ENNReal.toReal \u2218 ENNReal.ofReal) :=\n    h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm\n  rw [\u2190 integral_eq_lintegral' hf]\n  exacts[integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top]\n#align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral\n\ntheorem integral_add {f g : \u03b1 \u2192\u209b E} (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    integral \u03bc (f + g) = integral \u03bc f + integral \u03bc g :=\n  setToSimpleFunc_add _ weightedSmul_union hf hg\n#align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add\n\ntheorem integral_neg {f : \u03b1 \u2192\u209b E} (hf : Integrable f \u03bc) : integral \u03bc (-f) = -integral \u03bc f :=\n  setToSimpleFunc_neg _ weightedSmul_union hf\n#align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg\n\ntheorem integral_sub {f g : \u03b1 \u2192\u209b E} (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    integral \u03bc (f - g) = integral \u03bc f - integral \u03bc g :=\n  setToSimpleFunc_sub _ weightedSmul_union hf hg\n#align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub\n\ntheorem integral_smul (c : \ud835\udd5c) {f : \u03b1 \u2192\u209b E} (hf : Integrable f \u03bc) :\n    integral \u03bc (c \u2022 f) = c \u2022 integral \u03bc f :=\n  setToSimpleFunc_smul _ weightedSmul_union weightedSmul_smul c hf\n#align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul\n\ntheorem norm_setToSimpleFunc_le_integral_norm (T : Set \u03b1 \u2192 E \u2192L[\u211d] F) {C : \u211d}\n    (hT_norm : \u2200 s, MeasurableSet s \u2192 \u03bc s < \u221e \u2192 \u2016T s\u2016 \u2264 C * (\u03bc s).toReal) {f : \u03b1 \u2192\u209b E}\n    (hf : Integrable f \u03bc) : \u2016f.setToSimpleFunc T\u2016 \u2264 C * (f.map norm).integral \u03bc :=\n  calc\n    \u2016f.setToSimpleFunc T\u2016 \u2264 C * \u2211 x in f.range, ENNReal.toReal (\u03bc (f \u207b\u00b9' {x})) * \u2016x\u2016 :=\n      norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf\n    _ = C * (f.map norm).integral \u03bc :=\n      by\n      rw [map_integral f norm hf norm_zero]\n      simp_rw [smul_eq_mul]\n    \n#align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm\n\ntheorem norm_integral_le_integral_norm (f : \u03b1 \u2192\u209b E) (hf : Integrable f \u03bc) :\n    \u2016f.integral \u03bc\u2016 \u2264 (f.map norm).integral \u03bc :=\n  by\n  refine' (norm_set_to_simple_func_le_integral_norm _ (fun s _ _ => _) hf).trans (one_mul _).le\n  exact (norm_weighted_smul_le s).trans (one_mul _).symm.le\n#align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm\n\ntheorem integral_add_measure {\u03bd} (f : \u03b1 \u2192\u209b E) (hf : Integrable f (\u03bc + \u03bd)) :\n    f.integral (\u03bc + \u03bd) = f.integral \u03bc + f.integral \u03bd :=\n  by\n  simp_rw [integral_def]\n  refine'\n    set_to_simple_func_add_left' (weighted_smul \u03bc) (weighted_smul \u03bd) (weighted_smul (\u03bc + \u03bd))\n      (fun s hs h\u03bc\u03bds => _) hf\n  rw [lt_top_iff_ne_top, measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at h\u03bc\u03bds\n  rw [weighted_smul_add_measure _ _ h\u03bc\u03bds.1 h\u03bc\u03bds.2]\n#align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure\n\nend Integral\n\nend SimpleFunc\n\nnamespace L1\n\nopen AeEqFun Lp.SimpleFunc Lp\n\nvariable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n\nvariable {\u03b1 E \u03bc}\n\nnamespace SimpleFunc\n\ntheorem norm_eq_integral (f : \u03b1 \u2192\u2081\u209b[\u03bc] E) : \u2016f\u2016 = ((toSimpleFunc f).map norm).integral \u03bc :=\n  by\n  rw [norm_eq_sum_mul f, (to_simple_func f).map_integral norm (simple_func.integrable f) norm_zero]\n  simp_rw [smul_eq_mul]\n#align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral\n\nsection PosPart\n\n/-- Positive part of a simple function in L1 space.  -/\ndef posPart (f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d) : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d :=\n  \u27e8lp.posPart (f : \u03b1 \u2192\u2081[\u03bc] \u211d), by\n    rcases f with \u27e8f, s, hsf\u27e9\n    use s.pos_part\n    simp only [Subtype.coe_mk, Lp.coe_pos_part, \u2190 hsf, ae_eq_fun.pos_part_mk, simple_func.pos_part,\n      simple_func.coe_map, mk_eq_mk]\u27e9\n#align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart\n\n/-- Negative part of a simple function in L1 space. -/\ndef negPart (f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d) : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d :=\n  posPart (-f)\n#align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart\n\n@[norm_cast]\ntheorem coe_posPart (f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d) : (posPart f : \u03b1 \u2192\u2081[\u03bc] \u211d) = lp.posPart (f : \u03b1 \u2192\u2081[\u03bc] \u211d) :=\n  rfl\n#align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart\n\n@[norm_cast]\ntheorem coe_negPart (f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d) : (negPart f : \u03b1 \u2192\u2081[\u03bc] \u211d) = lp.negPart (f : \u03b1 \u2192\u2081[\u03bc] \u211d) :=\n  rfl\n#align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart\n\nend PosPart\n\nsection SimpleFuncIntegral\n\n/-!\n### The Bochner integral of `L1`\n\nDefine the Bochner integral on `\u03b1 \u2192\u2081\u209b[\u03bc] E` by extension from the simple functions `\u03b1 \u2192\u2081\u209b[\u03bc] E`,\nand prove basic properties of this integral. -/\n\n\nvariable [NormedField \ud835\udd5c] [NormedSpace \ud835\udd5c E] [NormedSpace \u211d E] [SMulCommClass \u211d \ud835\udd5c E] {F' : Type _}\n  [NormedAddCommGroup F'] [NormedSpace \u211d F']\n\nattribute [local instance] simple_func.normed_space\n\n/-- The Bochner integral over simple functions in L1 space. -/\ndef integral (f : \u03b1 \u2192\u2081\u209b[\u03bc] E) : E :=\n  (toSimpleFunc f).integral \u03bc\n#align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral\n\ntheorem integral_eq_integral (f : \u03b1 \u2192\u2081\u209b[\u03bc] E) : integral f = (toSimpleFunc f).integral \u03bc :=\n  rfl\n#align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral\n\ntheorem integral_eq_lintegral {f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d} (h_pos : 0 \u2264\u1d50[\u03bc] toSimpleFunc f) :\n    integral f = ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal ((toSimpleFunc f) a) \u2202\u03bc) := by\n  rw [integral, simple_func.integral_eq_lintegral (simple_func.integrable f) h_pos]\n#align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral\n\ntheorem integral_eq_setToL1s (f : \u03b1 \u2192\u2081\u209b[\u03bc] E) : integral f = setToL1s (weightedSmul \u03bc) f :=\n  rfl\n#align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1s\n\ntheorem integral_congr {f g : \u03b1 \u2192\u2081\u209b[\u03bc] E} (h : toSimpleFunc f =\u1d50[\u03bc] toSimpleFunc g) :\n    integral f = integral g :=\n  SimpleFunc.integral_congr (SimpleFunc.integrable f) h\n#align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr\n\ntheorem integral_add (f g : \u03b1 \u2192\u2081\u209b[\u03bc] E) : integral (f + g) = integral f + integral g :=\n  setToL1s_add _ (fun _ _ => weightedSmul_null) weightedSmul_union _ _\n#align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add\n\ntheorem integral_smul (c : \ud835\udd5c) (f : \u03b1 \u2192\u2081\u209b[\u03bc] E) : integral (c \u2022 f) = c \u2022 integral f :=\n  setToL1s_smul _ (fun _ _ => weightedSmul_null) weightedSmul_union weightedSmul_smul c f\n#align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul\n\ntheorem norm_integral_le_norm (f : \u03b1 \u2192\u2081\u209b[\u03bc] E) : \u2016integral f\u2016 \u2264 \u2016f\u2016 :=\n  by\n  rw [integral, norm_eq_integral]\n  exact (to_simple_func f).norm_integral_le_integral_norm (simple_func.integrable f)\n#align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm\n\nvariable {E' : Type _} [NormedAddCommGroup E'] [NormedSpace \u211d E'] [NormedSpace \ud835\udd5c E']\n\nvariable (\u03b1 E \u03bc \ud835\udd5c)\n\n/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/\ndef integralClm' : (\u03b1 \u2192\u2081\u209b[\u03bc] E) \u2192L[\ud835\udd5c] E :=\n  LinearMap.mkContinuous \u27e8integral, integral_add, integral_smul\u27e9 1 fun f =>\n    le_trans (norm_integral_le_norm _) <| by rw [one_mul]\n#align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralClm'\n\n/-- The Bochner integral over simple functions in L1 space as a continuous linear map over \u211d. -/\ndef integralClm : (\u03b1 \u2192\u2081\u209b[\u03bc] E) \u2192L[\u211d] E :=\n  integralClm' \u03b1 E \u211d \u03bc\n#align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralClm\n\nvariable {\u03b1 E \u03bc \ud835\udd5c}\n\n-- mathport name: simple_func.integral_clm\nlocal notation \"Integral\" => integralClm \u03b1 E \u03bc\n\nopen ContinuousLinearMap\n\ntheorem norm_Integral_le_one : \u2016Integral\u2016 \u2264 1 :=\n  LinearMap.mkContinuous_norm_le _ zero_le_one _\n#align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one\n\nsection PosPart\n\ntheorem posPart_toSimpleFunc (f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d) :\n    toSimpleFunc (posPart f) =\u1d50[\u03bc] (toSimpleFunc f).posPart :=\n  by\n  have eq : \u2200 a, (to_simple_func f).posPart a = max ((to_simple_func f) a) 0 := fun a => rfl\n  have ae_eq : \u2200\u1d50 a \u2202\u03bc, to_simple_func (pos_part f) a = max ((to_simple_func f) a) 0 :=\n    by\n    filter_upwards [to_simple_func_eq_to_fun (pos_part f), Lp.coe_fn_pos_part (f : \u03b1 \u2192\u2081[\u03bc] \u211d),\n      to_simple_func_eq_to_fun f]with _ _ h\u2082 _\n    convert h\u2082\n  refine' ae_eq.mono fun a h => _\n  rw [h, Eq]\n#align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc\n\ntheorem negPart_toSimpleFunc (f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d) :\n    toSimpleFunc (negPart f) =\u1d50[\u03bc] (toSimpleFunc f).negPart :=\n  by\n  rw [simple_func.neg_part, MeasureTheory.SimpleFunc.negPart]\n  filter_upwards [pos_part_to_simple_func (-f), neg_to_simple_func f]\n  intro a h\u2081 h\u2082\n  rw [h\u2081]\n  show max _ _ = max _ _\n  rw [h\u2082]\n  rfl\n#align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc\n\ntheorem integral_eq_norm_posPart_sub (f : \u03b1 \u2192\u2081\u209b[\u03bc] \u211d) : integral f = \u2016posPart f\u2016 - \u2016negPart f\u2016 :=\n  by\n  -- Convert things in `L\u00b9` to their `simple_func` counterpart\n  have ae_eq\u2081 : (to_simple_func f).posPart =\u1d50[\u03bc] (to_simple_func (pos_part f)).map norm :=\n    by\n    filter_upwards [pos_part_to_simple_func f]with _ h\n    rw [simple_func.map_apply, h]\n    conv_lhs => rw [\u2190 simple_func.pos_part_map_norm, simple_func.map_apply]\n  -- Convert things in `L\u00b9` to their `simple_func` counterpart\n  have ae_eq\u2082 : (to_simple_func f).negPart =\u1d50[\u03bc] (to_simple_func (neg_part f)).map norm :=\n    by\n    filter_upwards [neg_part_to_simple_func f]with _ h\n    rw [simple_func.map_apply, h]\n    conv_lhs => rw [\u2190 simple_func.neg_part_map_norm, simple_func.map_apply]\n  -- Convert things in `L\u00b9` to their `simple_func` counterpart\n  have ae_eq :\n    \u2200\u1d50 a \u2202\u03bc,\n      (to_simple_func f).posPart a - (to_simple_func f).negPart a =\n        (to_simple_func (pos_part f)).map norm a - (to_simple_func (neg_part f)).map norm a :=\n    by\n    filter_upwards [ae_eq\u2081, ae_eq\u2082]with _ h\u2081 h\u2082\n    rw [h\u2081, h\u2082]\n  rw [integral, norm_eq_integral, norm_eq_integral, \u2190 simple_func.integral_sub]\n  \u00b7 show\n      (to_simple_func f).integral \u03bc =\n        ((to_simple_func (pos_part f)).map norm - (to_simple_func (neg_part f)).map norm).integral \u03bc\n    apply MeasureTheory.SimpleFunc.integral_congr (simple_func.integrable f)\n    filter_upwards [ae_eq\u2081, ae_eq\u2082]with _ h\u2081 h\u2082\n    show _ = _ - _\n    rw [\u2190 h\u2081, \u2190 h\u2082]\n    have := (to_simple_func f).posPart_sub_negPart\n    conv_lhs => rw [\u2190 this]\n    rfl\n  \u00b7 exact (simple_func.integrable f).posPart.congr ae_eq\u2081\n  \u00b7 exact (simple_func.integrable f).negPart.congr ae_eq\u2082\n#align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub\n\nend PosPart\n\nend SimpleFuncIntegral\n\nend SimpleFunc\n\nopen SimpleFunc\n\n-- mathport name: simple_func.integral_clm\nlocal notation \"Integral\" => @integralClm \u03b1 E _ _ _ _ _ \u03bc _\n\nvariable [NormedSpace \u211d E] [NontriviallyNormedField \ud835\udd5c] [NormedSpace \ud835\udd5c E] [SMulCommClass \u211d \ud835\udd5c E]\n  [NormedSpace \u211d F] [CompleteSpace E]\n\nsection IntegrationInL1\n\nattribute [local instance] simple_func.normed_space\n\nopen ContinuousLinearMap\n\nvariable (\ud835\udd5c)\n\n/-- The Bochner integral in L1 space as a continuous linear map. -/\ndef integralClm' : (\u03b1 \u2192\u2081[\u03bc] E) \u2192L[\ud835\udd5c] E :=\n  (integralClm' \u03b1 E \ud835\udd5c \u03bc).extend (coeToLp \u03b1 E \ud835\udd5c) (simpleFunc.denseRange one_ne_top)\n    simpleFunc.uniformInducing\n#align measure_theory.L1.integral_clm' MeasureTheory.L1.integralClm'\n\nvariable {\ud835\udd5c}\n\n/-- The Bochner integral in L1 space as a continuous linear map over \u211d. -/\ndef integralClm : (\u03b1 \u2192\u2081[\u03bc] E) \u2192L[\u211d] E :=\n  integralClm' \u211d\n#align measure_theory.L1.integral_clm MeasureTheory.L1.integralClm\n\n/-- The Bochner integral in L1 space -/\nirreducible_def integral (f : \u03b1 \u2192\u2081[\u03bc] E) : E :=\n  integralClm f\n#align measure_theory.L1.integral MeasureTheory.L1.integral\n\ntheorem integral_eq (f : \u03b1 \u2192\u2081[\u03bc] E) : integral f = integralClm f := by simp only [integral]\n#align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq\n\ntheorem integral_eq_setToL1 (f : \u03b1 \u2192\u2081[\u03bc] E) :\n    integral f = setToL1 (dominatedFinMeasAdditiveWeightedSmul \u03bc) f :=\n  by\n  simp only [integral]\n  rfl\n#align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1\n\n@[norm_cast]\ntheorem SimpleFunc.integral_L1_eq_integral (f : \u03b1 \u2192\u2081\u209b[\u03bc] E) :\n    integral (f : \u03b1 \u2192\u2081[\u03bc] E) = SimpleFunc.integral f :=\n  by\n  simp only [integral]\n  exact set_to_L1_eq_set_to_L1s_clm (dominated_fin_meas_additive_weighted_smul \u03bc) f\n#align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral\n\nvariable (\u03b1 E)\n\n@[simp]\ntheorem integral_zero : integral (0 : \u03b1 \u2192\u2081[\u03bc] E) = 0 :=\n  by\n  simp only [integral]\n  exact map_zero integral_clm\n#align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero\n\nvariable {\u03b1 E}\n\ntheorem integral_add (f g : \u03b1 \u2192\u2081[\u03bc] E) : integral (f + g) = integral f + integral g :=\n  by\n  simp only [integral]\n  exact map_add integral_clm f g\n#align measure_theory.L1.integral_add MeasureTheory.L1.integral_add\n\ntheorem integral_neg (f : \u03b1 \u2192\u2081[\u03bc] E) : integral (-f) = -integral f :=\n  by\n  simp only [integral]\n  exact map_neg integral_clm f\n#align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg\n\ntheorem integral_sub (f g : \u03b1 \u2192\u2081[\u03bc] E) : integral (f - g) = integral f - integral g :=\n  by\n  simp only [integral]\n  exact map_sub integral_clm f g\n#align measure_theory.L1.integral_sub MeasureTheory.L1.integral_sub\n\ntheorem integral_smul (c : \ud835\udd5c) (f : \u03b1 \u2192\u2081[\u03bc] E) : integral (c \u2022 f) = c \u2022 integral f :=\n  by\n  simp only [integral]\n  show (integral_clm' \ud835\udd5c) (c \u2022 f) = c \u2022 (integral_clm' \ud835\udd5c) f; exact map_smul (integral_clm' \ud835\udd5c) c f\n#align measure_theory.L1.integral_smul MeasureTheory.L1.integral_smul\n\n-- mathport name: integral_clm\nlocal notation \"Integral\" => @integralClm \u03b1 E _ _ \u03bc _ _\n\n-- mathport name: simple_func.integral_clm'\nlocal notation \"sIntegral\" => @SimpleFunc.integralClm \u03b1 E _ _ \u03bc _\n\ntheorem norm_Integral_le_one : \u2016Integral\u2016 \u2264 1 :=\n  norm_setToL1_le (dominatedFinMeasAdditiveWeightedSmul \u03bc) zero_le_one\n#align measure_theory.L1.norm_Integral_le_one MeasureTheory.L1.norm_Integral_le_one\n\ntheorem norm_integral_le (f : \u03b1 \u2192\u2081[\u03bc] E) : \u2016integral f\u2016 \u2264 \u2016f\u2016 :=\n  calc\n    \u2016integral f\u2016 = \u2016Integral f\u2016 := by simp only [integral]\n    _ \u2264 \u2016Integral\u2016 * \u2016f\u2016 := (le_op_norm _ _)\n    _ \u2264 1 * \u2016f\u2016 := (mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _)\n    _ = \u2016f\u2016 := one_mul _\n    \n#align measure_theory.L1.norm_integral_le MeasureTheory.L1.norm_integral_le\n\n@[continuity]\ntheorem continuous_integral : Continuous fun f : \u03b1 \u2192\u2081[\u03bc] E => integral f :=\n  by\n  simp only [integral]\n  exact L1.integral_clm.continuous\n#align measure_theory.L1.continuous_integral MeasureTheory.L1.continuous_integral\n\nsection PosPart\n\ntheorem integral_eq_norm_posPart_sub (f : \u03b1 \u2192\u2081[\u03bc] \u211d) :\n    integral f = \u2016lp.posPart f\u2016 - \u2016lp.negPart f\u2016 :=\n  by\n  -- Use `is_closed_property` and `is_closed_eq`\n  refine'\n    @isClosed_property _ _ _ (coe : (\u03b1 \u2192\u2081\u209b[\u03bc] \u211d) \u2192 \u03b1 \u2192\u2081[\u03bc] \u211d)\n      (fun f : \u03b1 \u2192\u2081[\u03bc] \u211d => integral f = \u2016Lp.pos_part f\u2016 - \u2016Lp.neg_part f\u2016)\n      (simple_func.dense_range one_ne_top) (isClosed_eq _ _) _ f\n  \u00b7 simp only [integral]\n    exact cont _\n  \u00b7\n    refine'\n      Continuous.sub (continuous_norm.comp Lp.continuous_pos_part)\n        (continuous_norm.comp Lp.continuous_neg_part)\n  -- Show that the property holds for all simple functions in the `L\u00b9` space.\n  \u00b7 intro s\n    norm_cast\n    exact simple_func.integral_eq_norm_pos_part_sub _\n#align measure_theory.L1.integral_eq_norm_pos_part_sub MeasureTheory.L1.integral_eq_norm_posPart_sub\n\nend PosPart\n\nend IntegrationInL1\n\nend L1\n\n/-!\n## The Bochner integral on functions\n\nDefine the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable\nfunctions, and 0 otherwise; prove its basic properties.\n\n-/\n\n\nvariable [NormedAddCommGroup E] [NormedSpace \u211d E] [CompleteSpace E] [NontriviallyNormedField \ud835\udd5c]\n  [NormedSpace \ud835\udd5c E] [SMulCommClass \u211d \ud835\udd5c E] [NormedAddCommGroup F] [NormedSpace \u211d F] [CompleteSpace F]\n\nsection\n\nopen Classical\n\n/-- The Bochner integral -/\nirreducible_def integral {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (f : \u03b1 \u2192 E) : E :=\n  if hf : Integrable f \u03bc then L1.integral (hf.toL1 f) else 0\n#align measure_theory.integral MeasureTheory.integral\n\nend\n\n/-! In the notation for integrals, an expression like `\u222b x, g \u2016x\u2016 \u2202\u03bc` will not be parsed correctly,\n  and needs parentheses. We do not set the binding power of `r` to `0`, because then\n  `\u222b x, f x = 0` will be parsed incorrectly. -/\n\n\n-- mathport name: \u00abexpr\u222b , \u2202 \u00bb\nnotation3\"\u222b \"(...)\", \"r:(scoped f => f)\" \u2202\"\u03bc => integral \u03bc r\n\n-- mathport name: \u00abexpr\u222b , \u00bb\nnotation3\"\u222b \"(...)\", \"r:(scoped f => integral volume f) => r\n\n-- mathport name: \u00abexpr\u222b in , \u2202 \u00bb\nnotation3\"\u222b \"(...)\" in \"s\", \"r:(scoped f => f)\" \u2202\"\u03bc => integral (Measure.restrict \u03bc s) r\n\n-- mathport name: \u00abexpr\u222b in , \u00bb\nnotation3\"\u222b \"(...)\" in \"s\", \"r:(scoped f => integral Measure.restrict volume s f) => r\n\nsection Properties\n\nopen ContinuousLinearMap MeasureTheory.SimpleFunc\n\nvariable {f g : \u03b1 \u2192 E} {m : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n\ntheorem integral_eq (f : \u03b1 \u2192 E) (hf : Integrable f \u03bc) : (\u222b a, f a \u2202\u03bc) = L1.integral (hf.toL1 f) :=\n  by\n  rw [integral]\n  exact @dif_pos _ (id _) hf _ _ _\n#align measure_theory.integral_eq MeasureTheory.integral_eq\n\ntheorem integral_eq_setToFun (f : \u03b1 \u2192 E) :\n    (\u222b a, f a \u2202\u03bc) = setToFun \u03bc (weightedSmul \u03bc) (dominatedFinMeasAdditiveWeightedSmul \u03bc) f :=\n  by\n  simp only [integral, L1.integral]\n  rfl\n#align measure_theory.integral_eq_set_to_fun MeasureTheory.integral_eq_setToFun\n\ntheorem L1.integral_eq_integral (f : \u03b1 \u2192\u2081[\u03bc] E) : L1.integral f = \u222b a, f a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact (L1.set_to_fun_eq_set_to_L1 (dominated_fin_meas_additive_weighted_smul \u03bc) f).symm\n#align measure_theory.L1.integral_eq_integral MeasureTheory.L1.integral_eq_integral\n\ntheorem integral_undef (h : \u00acIntegrable f \u03bc) : (\u222b a, f a \u2202\u03bc) = 0 :=\n  by\n  rw [integral]\n  exact @dif_neg _ (id _) h _ _ _\n#align measure_theory.integral_undef MeasureTheory.integral_undef\n\ntheorem integral_non_aeStronglyMeasurable (h : \u00acAeStronglyMeasurable f \u03bc) : (\u222b a, f a \u2202\u03bc) = 0 :=\n  integral_undef <| not_and_of_not_left _ h\n#align measure_theory.integral_non_ae_strongly_measurable MeasureTheory.integral_non_aeStronglyMeasurable\n\nvariable (\u03b1 E)\n\ntheorem integral_zero : (\u222b a : \u03b1, (0 : E) \u2202\u03bc) = 0 :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_zero (dominated_fin_meas_additive_weighted_smul \u03bc)\n#align measure_theory.integral_zero MeasureTheory.integral_zero\n\n@[simp]\ntheorem integral_zero' : integral \u03bc (0 : \u03b1 \u2192 E) = 0 :=\n  integral_zero \u03b1 E\n#align measure_theory.integral_zero' MeasureTheory.integral_zero'\n\nvariable {\u03b1 E}\n\ntheorem integrableOfIntegralEqOne {f : \u03b1 \u2192 \u211d} (h : (\u222b x, f x \u2202\u03bc) = 1) : Integrable f \u03bc :=\n  by\n  contrapose h\n  rw [integral_undef h]\n  exact zero_ne_one\n#align measure_theory.integrable_of_integral_eq_one MeasureTheory.integrableOfIntegralEqOne\n\ntheorem integral_add (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    (\u222b a, f a + g a \u2202\u03bc) = (\u222b a, f a \u2202\u03bc) + \u222b a, g a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_add (dominated_fin_meas_additive_weighted_smul \u03bc) hf hg\n#align measure_theory.integral_add MeasureTheory.integral_add\n\ntheorem integral_add' (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    (\u222b a, (f + g) a \u2202\u03bc) = (\u222b a, f a \u2202\u03bc) + \u222b a, g a \u2202\u03bc :=\n  integral_add hf hg\n#align measure_theory.integral_add' MeasureTheory.integral_add'\n\ntheorem integral_finset_sum {\u03b9} (s : Finset \u03b9) {f : \u03b9 \u2192 \u03b1 \u2192 E} (hf : \u2200 i \u2208 s, Integrable (f i) \u03bc) :\n    (\u222b a, \u2211 i in s, f i a \u2202\u03bc) = \u2211 i in s, \u222b a, f i a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_finset_sum (dominated_fin_meas_additive_weighted_smul _) s hf\n#align measure_theory.integral_finset_sum MeasureTheory.integral_finset_sum\n\ntheorem integral_neg (f : \u03b1 \u2192 E) : (\u222b a, -f a \u2202\u03bc) = -\u222b a, f a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_neg (dominated_fin_meas_additive_weighted_smul \u03bc) f\n#align measure_theory.integral_neg MeasureTheory.integral_neg\n\ntheorem integral_neg' (f : \u03b1 \u2192 E) : (\u222b a, (-f) a \u2202\u03bc) = -\u222b a, f a \u2202\u03bc :=\n  integral_neg f\n#align measure_theory.integral_neg' MeasureTheory.integral_neg'\n\ntheorem integral_sub (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    (\u222b a, f a - g a \u2202\u03bc) = (\u222b a, f a \u2202\u03bc) - \u222b a, g a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_sub (dominated_fin_meas_additive_weighted_smul \u03bc) hf hg\n#align measure_theory.integral_sub MeasureTheory.integral_sub\n\ntheorem integral_sub' (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    (\u222b a, (f - g) a \u2202\u03bc) = (\u222b a, f a \u2202\u03bc) - \u222b a, g a \u2202\u03bc :=\n  integral_sub hf hg\n#align measure_theory.integral_sub' MeasureTheory.integral_sub'\n\ntheorem integral_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 E) : (\u222b a, c \u2022 f a \u2202\u03bc) = c \u2022 \u222b a, f a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_smul (dominated_fin_meas_additive_weighted_smul \u03bc) weighted_smul_smul c f\n#align measure_theory.integral_smul MeasureTheory.integral_smul\n\ntheorem integral_mul_left {L : Type _} [IsROrC L] (r : L) (f : \u03b1 \u2192 L) :\n    (\u222b a, r * f a \u2202\u03bc) = r * \u222b a, f a \u2202\u03bc :=\n  integral_smul r f\n#align measure_theory.integral_mul_left MeasureTheory.integral_mul_left\n\ntheorem integral_mul_right {L : Type _} [IsROrC L] (r : L) (f : \u03b1 \u2192 L) :\n    (\u222b a, f a * r \u2202\u03bc) = (\u222b a, f a \u2202\u03bc) * r :=\n  by\n  simp only [mul_comm]\n  exact integral_mul_left r f\n#align measure_theory.integral_mul_right MeasureTheory.integral_mul_right\n\ntheorem integral_div {L : Type _} [IsROrC L] (r : L) (f : \u03b1 \u2192 L) :\n    (\u222b a, f a / r \u2202\u03bc) = (\u222b a, f a \u2202\u03bc) / r := by\n  simpa only [\u2190 div_eq_mul_inv] using integral_mul_right r\u207b\u00b9 f\n#align measure_theory.integral_div MeasureTheory.integral_div\n\ntheorem integral_congr_ae (h : f =\u1d50[\u03bc] g) : (\u222b a, f a \u2202\u03bc) = \u222b a, g a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_congr_ae (dominated_fin_meas_additive_weighted_smul \u03bc) h\n#align measure_theory.integral_congr_ae MeasureTheory.integral_congr_ae\n\n@[simp]\ntheorem L1.integral_of_fun_eq_integral {f : \u03b1 \u2192 E} (hf : Integrable f \u03bc) :\n    (\u222b a, (hf.toL1 f) a \u2202\u03bc) = \u222b a, f a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_to_L1 (dominated_fin_meas_additive_weighted_smul \u03bc) hf\n#align measure_theory.L1.integral_of_fun_eq_integral MeasureTheory.L1.integral_of_fun_eq_integral\n\n@[continuity]\ntheorem continuous_integral : Continuous fun f : \u03b1 \u2192\u2081[\u03bc] E => \u222b a, f a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact continuous_set_to_fun (dominated_fin_meas_additive_weighted_smul \u03bc)\n#align measure_theory.continuous_integral MeasureTheory.continuous_integral\n\ntheorem norm_integral_le_lintegral_norm (f : \u03b1 \u2192 E) :\n    \u2016\u222b a, f a \u2202\u03bc\u2016 \u2264 ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal \u2016f a\u2016 \u2202\u03bc) :=\n  by\n  by_cases hf : integrable f \u03bc\n  \u00b7 rw [integral_eq f hf, \u2190 integrable.norm_to_L1_eq_lintegral_norm f hf]\n    exact L1.norm_integral_le _\n  \u00b7 rw [integral_undef hf, norm_zero]\n    exact to_real_nonneg\n#align measure_theory.norm_integral_le_lintegral_norm MeasureTheory.norm_integral_le_lintegral_norm\n\ntheorem ennnorm_integral_le_lintegral_ennnorm (f : \u03b1 \u2192 E) :\n    (\u2016\u222b a, f a \u2202\u03bc\u2016\u208a : \u211d\u22650\u221e) \u2264 \u222b\u207b a, \u2016f a\u2016\u208a \u2202\u03bc :=\n  by\n  simp_rw [\u2190 ofReal_norm_eq_coe_nnnorm]\n  apply ENNReal.ofReal_le_of_le_toReal\n  exact norm_integral_le_lintegral_norm f\n#align measure_theory.ennnorm_integral_le_lintegral_ennnorm MeasureTheory.ennnorm_integral_le_lintegral_ennnorm\n\ntheorem integral_eq_zero_of_ae {f : \u03b1 \u2192 E} (hf : f =\u1d50[\u03bc] 0) : (\u222b a, f a \u2202\u03bc) = 0 := by\n  simp [integral_congr_ae hf, integral_zero]\n#align measure_theory.integral_eq_zero_of_ae MeasureTheory.integral_eq_zero_of_ae\n\n/-- If `f` has finite integral, then `\u222b x in s, f x \u2202\u03bc` is absolutely continuous in `s`: it tends\nto zero as `\u03bc s` tends to zero. -/\ntheorem HasFiniteIntegral.tendsto_set_integral_nhds_zero {\u03b9} {f : \u03b1 \u2192 E}\n    (hf : HasFiniteIntegral f \u03bc) {l : Filter \u03b9} {s : \u03b9 \u2192 Set \u03b1} (hs : Tendsto (\u03bc \u2218 s) l (\ud835\udcdd 0)) :\n    Tendsto (fun i => \u222b x in s i, f x \u2202\u03bc) l (\ud835\udcdd 0) :=\n  by\n  rw [tendsto_zero_iff_norm_tendsto_zero]\n  simp_rw [\u2190 coe_nnnorm, \u2190 NNReal.coe_zero, NNReal.tendsto_coe, \u2190 ENNReal.tendsto_coe,\n    ENNReal.coe_zero]\n  exact\n    tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds\n      (tendsto_set_lintegral_zero (ne_of_lt hf) hs) (fun i => zero_le _) fun i =>\n      ennnorm_integral_le_lintegral_ennnorm _\n#align measure_theory.has_finite_integral.tendsto_set_integral_nhds_zero MeasureTheory.HasFiniteIntegral.tendsto_set_integral_nhds_zero\n\n/-- If `f` is integrable, then `\u222b x in s, f x \u2202\u03bc` is absolutely continuous in `s`: it tends\nto zero as `\u03bc s` tends to zero. -/\ntheorem Integrable.tendsto_set_integral_nhds_zero {\u03b9} {f : \u03b1 \u2192 E} (hf : Integrable f \u03bc)\n    {l : Filter \u03b9} {s : \u03b9 \u2192 Set \u03b1} (hs : Tendsto (\u03bc \u2218 s) l (\ud835\udcdd 0)) :\n    Tendsto (fun i => \u222b x in s i, f x \u2202\u03bc) l (\ud835\udcdd 0) :=\n  hf.2.tendsto_set_integral_nhds_zero hs\n#align measure_theory.integrable.tendsto_set_integral_nhds_zero MeasureTheory.Integrable.tendsto_set_integral_nhds_zero\n\n/-- If `F i \u2192 f` in `L1`, then `\u222b x, F i x \u2202\u03bc \u2192 \u222b x, f x \u2202\u03bc`. -/\ntheorem tendsto_integral_of_L1 {\u03b9} (f : \u03b1 \u2192 E) (hfi : Integrable f \u03bc) {F : \u03b9 \u2192 \u03b1 \u2192 E} {l : Filter \u03b9}\n    (hFi : \u2200\u1da0 i in l, Integrable (F i) \u03bc)\n    (hF : Tendsto (fun i => \u222b\u207b x, \u2016F i x - f x\u2016\u208a \u2202\u03bc) l (\ud835\udcdd 0)) :\n    Tendsto (fun i => \u222b x, F i x \u2202\u03bc) l (\ud835\udcdd <| \u222b x, f x \u2202\u03bc) :=\n  by\n  simp only [integral, L1.integral]\n  exact tendsto_set_to_fun_of_L1 (dominated_fin_meas_additive_weighted_smul \u03bc) f hfi hFi hF\n#align measure_theory.tendsto_integral_of_L1 MeasureTheory.tendsto_integral_of_L1\n\n/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost\n  everywhere convergence of a sequence of functions implies the convergence of their integrals.\n  We could weaken the condition `bound_integrable` to require `has_finite_integral bound \u03bc` instead\n  (i.e. not requiring that `bound` is measurable), but in all applications proving integrability\n  is easier. -/\ntheorem tendsto_integral_of_dominated_convergence {F : \u2115 \u2192 \u03b1 \u2192 E} {f : \u03b1 \u2192 E} (bound : \u03b1 \u2192 \u211d)\n    (F_measurable : \u2200 n, AeStronglyMeasurable (F n) \u03bc) (bound_integrable : Integrable bound \u03bc)\n    (h_bound : \u2200 n, \u2200\u1d50 a \u2202\u03bc, \u2016F n a\u2016 \u2264 bound a)\n    (h_lim : \u2200\u1d50 a \u2202\u03bc, Tendsto (fun n => F n a) atTop (\ud835\udcdd (f a))) :\n    Tendsto (fun n => \u222b a, F n a \u2202\u03bc) atTop (\ud835\udcdd <| \u222b a, f a \u2202\u03bc) :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    tendsto_set_to_fun_of_dominated_convergence (dominated_fin_meas_additive_weighted_smul \u03bc) bound\n      F_measurable bound_integrable h_bound h_lim\n#align measure_theory.tendsto_integral_of_dominated_convergence MeasureTheory.tendsto_integral_of_dominated_convergence\n\n/-- Lebesgue dominated convergence theorem for filters with a countable basis -/\ntheorem tendsto_integral_filter_of_dominated_convergence {\u03b9} {l : Filter \u03b9} [l.IsCountablyGenerated]\n    {F : \u03b9 \u2192 \u03b1 \u2192 E} {f : \u03b1 \u2192 E} (bound : \u03b1 \u2192 \u211d) (hF_meas : \u2200\u1da0 n in l, AeStronglyMeasurable (F n) \u03bc)\n    (h_bound : \u2200\u1da0 n in l, \u2200\u1d50 a \u2202\u03bc, \u2016F n a\u2016 \u2264 bound a) (bound_integrable : Integrable bound \u03bc)\n    (h_lim : \u2200\u1d50 a \u2202\u03bc, Tendsto (fun n => F n a) l (\ud835\udcdd (f a))) :\n    Tendsto (fun n => \u222b a, F n a \u2202\u03bc) l (\ud835\udcdd <| \u222b a, f a \u2202\u03bc) :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    tendsto_set_to_fun_filter_of_dominated_convergence (dominated_fin_meas_additive_weighted_smul \u03bc)\n      bound hF_meas h_bound bound_integrable h_lim\n#align measure_theory.tendsto_integral_filter_of_dominated_convergence MeasureTheory.tendsto_integral_filter_of_dominated_convergence\n\n/-- Lebesgue dominated convergence theorem for series. -/\ntheorem hasSum_integral_of_dominated_convergence {\u03b9} [Countable \u03b9] {F : \u03b9 \u2192 \u03b1 \u2192 E} {f : \u03b1 \u2192 E}\n    (bound : \u03b9 \u2192 \u03b1 \u2192 \u211d) (hF_meas : \u2200 n, AeStronglyMeasurable (F n) \u03bc)\n    (h_bound : \u2200 n, \u2200\u1d50 a \u2202\u03bc, \u2016F n a\u2016 \u2264 bound n a)\n    (bound_summable : \u2200\u1d50 a \u2202\u03bc, Summable fun n => bound n a)\n    (bound_integrable : Integrable (fun a => \u2211' n, bound n a) \u03bc)\n    (h_lim : \u2200\u1d50 a \u2202\u03bc, HasSum (fun n => F n a) (f a)) :\n    HasSum (fun n => \u222b a, F n a \u2202\u03bc) (\u222b a, f a \u2202\u03bc) :=\n  by\n  have hb_nonneg : \u2200\u1d50 a \u2202\u03bc, \u2200 n, 0 \u2264 bound n a :=\n    eventually_countable_forall.2 fun n => (h_bound n).mono fun a => (norm_nonneg _).trans\n  have hb_le_tsum : \u2200 n, bound n \u2264\u1d50[\u03bc] fun a => \u2211' n, bound n a :=\n    by\n    intro n\n    filter_upwards [hb_nonneg,\n      bound_summable]with _ ha0 ha_sum using le_tsum ha_sum _ fun i _ => ha0 i\n  have hF_integrable : \u2200 n, integrable (F n) \u03bc :=\n    by\n    refine' fun n => bound_integrable.mono' (hF_meas n) _\n    exact eventually_le.trans (h_bound n) (hb_le_tsum n)\n  simp only [HasSum, \u2190 integral_finset_sum _ fun n _ => hF_integrable n]\n  refine'\n    tendsto_integral_filter_of_dominated_convergence (fun a => \u2211' n, bound n a) _ _ bound_integrable\n      h_lim\n  \u00b7 exact eventually_of_forall fun s => s.ae_strongly_measurable_sum fun n hn => hF_meas n\n  \u00b7 refine' eventually_of_forall fun s => _\n    filter_upwards [eventually_countable_forall.2 h_bound, hb_nonneg,\n      bound_summable]with a hFa ha0 has\n    calc\n      \u2016\u2211 n in s, F n a\u2016 \u2264 \u2211 n in s, bound n a := norm_sum_le_of_le _ fun n hn => hFa n\n      _ \u2264 \u2211' n, bound n a := sum_le_tsum _ (fun n hn => ha0 n) has\n      \n#align measure_theory.has_sum_integral_of_dominated_convergence MeasureTheory.hasSum_integral_of_dominated_convergence\n\nvariable {X : Type _} [TopologicalSpace X] [FirstCountableTopology X]\n\ntheorem continuousWithinAt_of_dominated {F : X \u2192 \u03b1 \u2192 E} {x\u2080 : X} {bound : \u03b1 \u2192 \u211d} {s : Set X}\n    (hF_meas : \u2200\u1da0 x in \ud835\udcdd[s] x\u2080, AeStronglyMeasurable (F x) \u03bc)\n    (h_bound : \u2200\u1da0 x in \ud835\udcdd[s] x\u2080, \u2200\u1d50 a \u2202\u03bc, \u2016F x a\u2016 \u2264 bound a) (bound_integrable : Integrable bound \u03bc)\n    (h_cont : \u2200\u1d50 a \u2202\u03bc, ContinuousWithinAt (fun x => F x a) s x\u2080) :\n    ContinuousWithinAt (fun x => \u222b a, F x a \u2202\u03bc) s x\u2080 :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    continuous_within_at_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul \u03bc)\n      hF_meas h_bound bound_integrable h_cont\n#align measure_theory.continuous_within_at_of_dominated MeasureTheory.continuousWithinAt_of_dominated\n\ntheorem continuousAt_of_dominated {F : X \u2192 \u03b1 \u2192 E} {x\u2080 : X} {bound : \u03b1 \u2192 \u211d}\n    (hF_meas : \u2200\u1da0 x in \ud835\udcdd x\u2080, AeStronglyMeasurable (F x) \u03bc)\n    (h_bound : \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200\u1d50 a \u2202\u03bc, \u2016F x a\u2016 \u2264 bound a) (bound_integrable : Integrable bound \u03bc)\n    (h_cont : \u2200\u1d50 a \u2202\u03bc, ContinuousAt (fun x => F x a) x\u2080) :\n    ContinuousAt (fun x => \u222b a, F x a \u2202\u03bc) x\u2080 :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    continuous_at_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul \u03bc) hF_meas\n      h_bound bound_integrable h_cont\n#align measure_theory.continuous_at_of_dominated MeasureTheory.continuousAt_of_dominated\n\ntheorem continuousOn_of_dominated {F : X \u2192 \u03b1 \u2192 E} {bound : \u03b1 \u2192 \u211d} {s : Set X}\n    (hF_meas : \u2200 x \u2208 s, AeStronglyMeasurable (F x) \u03bc)\n    (h_bound : \u2200 x \u2208 s, \u2200\u1d50 a \u2202\u03bc, \u2016F x a\u2016 \u2264 bound a) (bound_integrable : Integrable bound \u03bc)\n    (h_cont : \u2200\u1d50 a \u2202\u03bc, ContinuousOn (fun x => F x a) s) : ContinuousOn (fun x => \u222b a, F x a \u2202\u03bc) s :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    continuous_on_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul \u03bc) hF_meas\n      h_bound bound_integrable h_cont\n#align measure_theory.continuous_on_of_dominated MeasureTheory.continuousOn_of_dominated\n\ntheorem continuous_of_dominated {F : X \u2192 \u03b1 \u2192 E} {bound : \u03b1 \u2192 \u211d}\n    (hF_meas : \u2200 x, AeStronglyMeasurable (F x) \u03bc) (h_bound : \u2200 x, \u2200\u1d50 a \u2202\u03bc, \u2016F x a\u2016 \u2264 bound a)\n    (bound_integrable : Integrable bound \u03bc) (h_cont : \u2200\u1d50 a \u2202\u03bc, Continuous fun x => F x a) :\n    Continuous fun x => \u222b a, F x a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    continuous_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul \u03bc) hF_meas h_bound\n      bound_integrable h_cont\n#align measure_theory.continuous_of_dominated MeasureTheory.continuous_of_dominated\n\n/-- The Bochner integral of a real-valued function `f : \u03b1 \u2192 \u211d` is the difference between the\n  integral of the positive part of `f` and the integral of the negative part of `f`.  -/\ntheorem integral_eq_lintegral_pos_part_sub_lintegral_neg_part {f : \u03b1 \u2192 \u211d} (hf : Integrable f \u03bc) :\n    (\u222b a, f a \u2202\u03bc) =\n      ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal <| f a \u2202\u03bc) -\n        ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal <| -f a \u2202\u03bc) :=\n  by\n  let f\u2081 := hf.toL1 f\n  -- Go to the `L\u00b9` space\n  have eq\u2081 : ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal <| f a \u2202\u03bc) = \u2016lp.posPart f\u2081\u2016 :=\n    by\n    rw [L1.norm_def]\n    congr 1\n    apply lintegral_congr_ae\n    filter_upwards [Lp.coe_fn_pos_part f\u2081, hf.coe_fn_to_L1]with _ h\u2081 h\u2082\n    rw [h\u2081, h\u2082, ENNReal.ofReal]\n    congr 1\n    apply NNReal.eq\n    rw [Real.nnnorm_of_nonneg (le_max_right _ _)]\n    simp only [Real.coe_toNNReal', Subtype.coe_mk]\n  -- Go to the `L\u00b9` space\n  have eq\u2082 : ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal <| -f a \u2202\u03bc) = \u2016lp.negPart f\u2081\u2016 :=\n    by\n    rw [L1.norm_def]\n    congr 1\n    apply lintegral_congr_ae\n    filter_upwards [Lp.coe_fn_neg_part f\u2081, hf.coe_fn_to_L1]with _ h\u2081 h\u2082\n    rw [h\u2081, h\u2082, ENNReal.ofReal]\n    congr 1\n    apply NNReal.eq\n    simp only [Real.coe_toNNReal', coe_nnnorm, nnnorm_neg]\n    rw [Real.norm_of_nonpos (min_le_right _ _), \u2190 max_neg_neg, neg_zero]\n  rw [eq\u2081, eq\u2082, integral, dif_pos]\n  exact L1.integral_eq_norm_pos_part_sub _\n#align measure_theory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part MeasureTheory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part\n\ntheorem integral_eq_lintegral_of_nonneg_ae {f : \u03b1 \u2192 \u211d} (hf : 0 \u2264\u1d50[\u03bc] f)\n    (hfm : AeStronglyMeasurable f \u03bc) :\n    (\u222b a, f a \u2202\u03bc) = ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal <| f a \u2202\u03bc) :=\n  by\n  by_cases hfi : integrable f \u03bc\n  \u00b7 rw [integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi]\n    have h_min : (\u222b\u207b a, ENNReal.ofReal (-f a) \u2202\u03bc) = 0 :=\n      by\n      rw [lintegral_eq_zero_iff']\n      \u00b7 refine' hf.mono _\n        simp only [Pi.zero_apply]\n        intro a h\n        simp only [h, neg_nonpos, of_real_eq_zero]\n      \u00b7 exact measurable_of_real.comp_ae_measurable hfm.ae_measurable.neg\n    rw [h_min, zero_to_real, _root_.sub_zero]\n  \u00b7 rw [integral_undef hfi]\n    simp_rw [integrable, hfm, has_finite_integral_iff_norm, lt_top_iff_ne_top, Ne.def, true_and_iff,\n      Classical.not_not] at hfi\n    have : (\u222b\u207b a : \u03b1, ENNReal.ofReal (f a) \u2202\u03bc) = \u222b\u207b a, ENNReal.ofReal \u2016f a\u2016 \u2202\u03bc :=\n      by\n      refine' lintegral_congr_ae (hf.mono fun a h => _)\n      rw [Real.norm_eq_abs, abs_of_nonneg h]\n    rw [this, hfi]\n    rfl\n#align measure_theory.integral_eq_lintegral_of_nonneg_ae MeasureTheory.integral_eq_lintegral_of_nonneg_ae\n\ntheorem integral_norm_eq_lintegral_nnnorm {G} [NormedAddCommGroup G] {f : \u03b1 \u2192 G}\n    (hf : AeStronglyMeasurable f \u03bc) : (\u222b x, \u2016f x\u2016 \u2202\u03bc) = ENNReal.toReal (\u222b\u207b x, \u2016f x\u2016\u208a \u2202\u03bc) :=\n  by\n  rw [integral_eq_lintegral_of_nonneg_ae _ hf.norm]\n  \u00b7 simp_rw [ofReal_norm_eq_coe_nnnorm]\n  \u00b7 refine' ae_of_all _ _\n    simp_rw [Pi.zero_apply, norm_nonneg, imp_true_iff]\n#align measure_theory.integral_norm_eq_lintegral_nnnorm MeasureTheory.integral_norm_eq_lintegral_nnnorm\n\ntheorem ofReal_integral_norm_eq_lintegral_nnnorm {G} [NormedAddCommGroup G] {f : \u03b1 \u2192 G}\n    (hf : Integrable f \u03bc) : ENNReal.ofReal (\u222b x, \u2016f x\u2016 \u2202\u03bc) = \u222b\u207b x, \u2016f x\u2016\u208a \u2202\u03bc := by\n  rw [integral_norm_eq_lintegral_nnnorm hf.ae_strongly_measurable,\n    ENNReal.ofReal_toReal (lt_top_iff_ne_top.mp hf.2)]\n#align measure_theory.of_real_integral_norm_eq_lintegral_nnnorm MeasureTheory.ofReal_integral_norm_eq_lintegral_nnnorm\n\ntheorem integral_eq_integral_pos_part_sub_integral_neg_part {f : \u03b1 \u2192 \u211d} (hf : Integrable f \u03bc) :\n    (\u222b a, f a \u2202\u03bc) = (\u222b a, Real.toNNReal (f a) \u2202\u03bc) - \u222b a, Real.toNNReal (-f a) \u2202\u03bc :=\n  by\n  rw [\u2190 integral_sub hf.real_to_nnreal]\n  \u00b7 simp\n  \u00b7 exact hf.neg.real_to_nnreal\n#align measure_theory.integral_eq_integral_pos_part_sub_integral_neg_part MeasureTheory.integral_eq_integral_pos_part_sub_integral_neg_part\n\ntheorem integral_nonneg_of_ae {f : \u03b1 \u2192 \u211d} (hf : 0 \u2264\u1d50[\u03bc] f) : 0 \u2264 \u222b a, f a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    set_to_fun_nonneg (dominated_fin_meas_additive_weighted_smul \u03bc)\n      (fun s _ _ => weighted_smul_nonneg s) hf\n#align measure_theory.integral_nonneg_of_ae MeasureTheory.integral_nonneg_of_ae\n\ntheorem lintegral_coe_eq_integral (f : \u03b1 \u2192 \u211d\u22650) (hfi : Integrable (fun x => (f x : \u211d)) \u03bc) :\n    (\u222b\u207b a, f a \u2202\u03bc) = ENNReal.ofReal (\u222b a, f a \u2202\u03bc) :=\n  by\n  simp_rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall fun x => (f x).coe_nonneg)\n      hfi.ae_strongly_measurable,\n    \u2190 ENNReal.coe_nnreal_eq]\n  rw [ENNReal.ofReal_toReal]\n  rw [\u2190 lt_top_iff_ne_top]; convert hfi.has_finite_integral; ext1 x; rw [NNReal.nnnorm_eq]\n#align measure_theory.lintegral_coe_eq_integral MeasureTheory.lintegral_coe_eq_integral\n\ntheorem ofReal_integral_eq_lintegral_ofReal {f : \u03b1 \u2192 \u211d} (hfi : Integrable f \u03bc) (f_nn : 0 \u2264\u1d50[\u03bc] f) :\n    ENNReal.ofReal (\u222b x, f x \u2202\u03bc) = \u222b\u207b x, ENNReal.ofReal (f x) \u2202\u03bc :=\n  by\n  simp_rw [integral_congr_ae\n      (show f =\u1d50[\u03bc] fun x => \u2016f x\u2016 by\n        filter_upwards [f_nn]with x hx\n        rw [Real.norm_eq_abs, abs_eq_self.mpr hx]),\n    of_real_integral_norm_eq_lintegral_nnnorm hfi, \u2190 ofReal_norm_eq_coe_nnnorm]\n  apply lintegral_congr_ae\n  filter_upwards [f_nn]with x hx\n  exact congr_arg ENNReal.ofReal (by rw [Real.norm_eq_abs, abs_eq_self.mpr hx])\n#align measure_theory.of_real_integral_eq_lintegral_of_real MeasureTheory.ofReal_integral_eq_lintegral_ofReal\n\ntheorem integral_toReal {f : \u03b1 \u2192 \u211d\u22650\u221e} (hfm : AeMeasurable f \u03bc) (hf : \u2200\u1d50 x \u2202\u03bc, f x < \u221e) :\n    (\u222b a, (f a).toReal \u2202\u03bc) = (\u222b\u207b a, f a \u2202\u03bc).toReal :=\n  by\n  rw [integral_eq_lintegral_of_nonneg_ae _ hfm.ennreal_to_real.ae_strongly_measurable]\n  \u00b7 rw [lintegral_congr_ae]\n    refine' hf.mp (eventually_of_forall _)\n    intro x hx\n    rw [lt_top_iff_ne_top] at hx\n    simp [hx]\n  \u00b7 exact eventually_of_forall fun x => ENNReal.toReal_nonneg\n#align measure_theory.integral_to_real MeasureTheory.integral_toReal\n\ntheorem lintegral_coe_le_coe_iff_integral_le {f : \u03b1 \u2192 \u211d\u22650} (hfi : Integrable (fun x => (f x : \u211d)) \u03bc)\n    {b : \u211d\u22650} : (\u222b\u207b a, f a \u2202\u03bc) \u2264 b \u2194 (\u222b a, (f a : \u211d) \u2202\u03bc) \u2264 b := by\n  rw [lintegral_coe_eq_integral f hfi, ENNReal.ofReal, ENNReal.coe_le_coe,\n    Real.toNNReal_le_iff_le_coe]\n#align measure_theory.lintegral_coe_le_coe_iff_integral_le MeasureTheory.lintegral_coe_le_coe_iff_integral_le\n\ntheorem integral_coe_le_of_lintegral_coe_le {f : \u03b1 \u2192 \u211d\u22650} {b : \u211d\u22650} (h : (\u222b\u207b a, f a \u2202\u03bc) \u2264 b) :\n    (\u222b a, (f a : \u211d) \u2202\u03bc) \u2264 b :=\n  by\n  by_cases hf : integrable (fun a => (f a : \u211d)) \u03bc\n  \u00b7 exact (lintegral_coe_le_coe_iff_integral_le hf).1 h\n  \u00b7 rw [integral_undef hf]\n    exact b.2\n#align measure_theory.integral_coe_le_of_lintegral_coe_le MeasureTheory.integral_coe_le_of_lintegral_coe_le\n\ntheorem integral_nonneg {f : \u03b1 \u2192 \u211d} (hf : 0 \u2264 f) : 0 \u2264 \u222b a, f a \u2202\u03bc :=\n  integral_nonneg_of_ae <| eventually_of_forall hf\n#align measure_theory.integral_nonneg MeasureTheory.integral_nonneg\n\ntheorem integral_nonpos_of_ae {f : \u03b1 \u2192 \u211d} (hf : f \u2264\u1d50[\u03bc] 0) : (\u222b a, f a \u2202\u03bc) \u2264 0 :=\n  by\n  have hf : 0 \u2264\u1d50[\u03bc] -f := hf.mono fun a h => by rwa [Pi.neg_apply, Pi.zero_apply, neg_nonneg]\n  have : 0 \u2264 \u222b a, -f a \u2202\u03bc := integral_nonneg_of_ae hf\n  rwa [integral_neg, neg_nonneg] at this\n#align measure_theory.integral_nonpos_of_ae MeasureTheory.integral_nonpos_of_ae\n\ntheorem integral_nonpos {f : \u03b1 \u2192 \u211d} (hf : f \u2264 0) : (\u222b a, f a \u2202\u03bc) \u2264 0 :=\n  integral_nonpos_of_ae <| eventually_of_forall hf\n#align measure_theory.integral_nonpos MeasureTheory.integral_nonpos\n\ntheorem integral_eq_zero_iff_of_nonneg_ae {f : \u03b1 \u2192 \u211d} (hf : 0 \u2264\u1d50[\u03bc] f) (hfi : Integrable f \u03bc) :\n    (\u222b x, f x \u2202\u03bc) = 0 \u2194 f =\u1d50[\u03bc] 0 := by\n  simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ENNReal.toReal_eq_zero_iff,\n    lintegral_eq_zero_iff' (ennreal.measurable_of_real.comp_ae_measurable hfi.1.AeMeasurable), \u2190\n    ENNReal.not_lt_top, \u2190 has_finite_integral_iff_of_real hf, hfi.2, not_true, or_false_iff, \u2190\n    hf.le_iff_eq, Filter.EventuallyEq, Filter.EventuallyLE, (\u00b7 \u2218 \u00b7), Pi.zero_apply,\n    ENNReal.ofReal_eq_zero]\n#align measure_theory.integral_eq_zero_iff_of_nonneg_ae MeasureTheory.integral_eq_zero_iff_of_nonneg_ae\n\ntheorem integral_eq_zero_iff_of_nonneg {f : \u03b1 \u2192 \u211d} (hf : 0 \u2264 f) (hfi : Integrable f \u03bc) :\n    (\u222b x, f x \u2202\u03bc) = 0 \u2194 f =\u1d50[\u03bc] 0 :=\n  integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi\n#align measure_theory.integral_eq_zero_iff_of_nonneg MeasureTheory.integral_eq_zero_iff_of_nonneg\n\ntheorem integral_pos_iff_support_of_nonneg_ae {f : \u03b1 \u2192 \u211d} (hf : 0 \u2264\u1d50[\u03bc] f) (hfi : Integrable f \u03bc) :\n    (0 < \u222b x, f x \u2202\u03bc) \u2194 0 < \u03bc (Function.support f) := by\n  simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, pos_iff_ne_zero, Ne.def, @eq_comm \u211d 0,\n    integral_eq_zero_iff_of_nonneg_ae hf hfi, Filter.EventuallyEq, ae_iff, Pi.zero_apply,\n    Function.support]\n#align measure_theory.integral_pos_iff_support_of_nonneg_ae MeasureTheory.integral_pos_iff_support_of_nonneg_ae\n\ntheorem integral_pos_iff_support_of_nonneg {f : \u03b1 \u2192 \u211d} (hf : 0 \u2264 f) (hfi : Integrable f \u03bc) :\n    (0 < \u222b x, f x \u2202\u03bc) \u2194 0 < \u03bc (Function.support f) :=\n  integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi\n#align measure_theory.integral_pos_iff_support_of_nonneg MeasureTheory.integral_pos_iff_support_of_nonneg\n\nsection NormedAddCommGroup\n\nvariable {H : Type _} [NormedAddCommGroup H]\n\ntheorem L1.norm_eq_integral_norm (f : \u03b1 \u2192\u2081[\u03bc] H) : \u2016f\u2016 = \u222b a, \u2016f a\u2016 \u2202\u03bc :=\n  by\n  simp only [snorm, snorm', ENNReal.one_toReal, ENNReal.rpow_one, Lp.norm_def, if_false,\n    ENNReal.one_ne_top, one_ne_zero, _root_.div_one]\n  rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (by simp [norm_nonneg]))\n      (Lp.ae_strongly_measurable f).norm]\n  simp [ofReal_norm_eq_coe_nnnorm]\n#align measure_theory.L1.norm_eq_integral_norm MeasureTheory.L1.norm_eq_integral_norm\n\ntheorem L1.norm_of_fun_eq_integral_norm {f : \u03b1 \u2192 H} (hf : Integrable f \u03bc) :\n    \u2016hf.toL1 f\u2016 = \u222b a, \u2016f a\u2016 \u2202\u03bc := by\n  rw [L1.norm_eq_integral_norm]\n  refine' integral_congr_ae _\n  apply hf.coe_fn_to_L1.mono\n  intro a ha\n  simp [ha]\n#align measure_theory.L1.norm_of_fun_eq_integral_norm MeasureTheory.L1.norm_of_fun_eq_integral_norm\n\ntheorem Mem\u2112p.snorm_eq_integral_rpow_norm {f : \u03b1 \u2192 H} {p : \u211d\u22650\u221e} (hp1 : p \u2260 0) (hp2 : p \u2260 \u221e)\n    (hf : Mem\u2112p f p \u03bc) : snorm f p \u03bc = ENNReal.ofReal ((\u222b a, \u2016f a\u2016 ^ p.toReal \u2202\u03bc) ^ p.toReal\u207b\u00b9) :=\n  by\n  have A : (\u222b\u207b a : \u03b1, ENNReal.ofReal (\u2016f a\u2016 ^ p.to_real) \u2202\u03bc) = \u222b\u207b a : \u03b1, \u2016f a\u2016\u208a ^ p.to_real \u2202\u03bc :=\n    by\n    apply lintegral_congr fun x => _\n    rw [\u2190 of_real_rpow_of_nonneg (norm_nonneg _) to_real_nonneg, ofReal_norm_eq_coe_nnnorm]\n  simp only [snorm_eq_lintegral_rpow_nnnorm hp1 hp2, one_div]\n  rw [integral_eq_lintegral_of_nonneg_ae]\n  rotate_left\n  \u00b7 exact eventually_of_forall fun x => Real.rpow_nonneg_of_nonneg (norm_nonneg _) _\n  \u00b7 exact (hf.ae_strongly_measurable.norm.ae_measurable.pow_const _).AeStronglyMeasurable\n  rw [A, \u2190 of_real_rpow_of_nonneg to_real_nonneg (inv_nonneg.2 to_real_nonneg), of_real_to_real]\n  exact (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp1 hp2 hf.2).Ne\n#align measure_theory.mem_\u2112p.snorm_eq_integral_rpow_norm MeasureTheory.Mem\u2112p.snorm_eq_integral_rpow_norm\n\nend NormedAddCommGroup\n\ntheorem integral_mono_ae {f g : \u03b1 \u2192 \u211d} (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) (h : f \u2264\u1d50[\u03bc] g) :\n    (\u222b a, f a \u2202\u03bc) \u2264 \u222b a, g a \u2202\u03bc :=\n  by\n  simp only [integral, L1.integral]\n  exact\n    set_to_fun_mono (dominated_fin_meas_additive_weighted_smul \u03bc)\n      (fun s _ _ => weighted_smul_nonneg s) hf hg h\n#align measure_theory.integral_mono_ae MeasureTheory.integral_mono_ae\n\n@[mono]\ntheorem integral_mono {f g : \u03b1 \u2192 \u211d} (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) (h : f \u2264 g) :\n    (\u222b a, f a \u2202\u03bc) \u2264 \u222b a, g a \u2202\u03bc :=\n  integral_mono_ae hf hg <| eventually_of_forall h\n#align measure_theory.integral_mono MeasureTheory.integral_mono\n\ntheorem integral_mono_of_nonneg {f g : \u03b1 \u2192 \u211d} (hf : 0 \u2264\u1d50[\u03bc] f) (hgi : Integrable g \u03bc)\n    (h : f \u2264\u1d50[\u03bc] g) : (\u222b a, f a \u2202\u03bc) \u2264 \u222b a, g a \u2202\u03bc :=\n  by\n  by_cases hfm : ae_strongly_measurable f \u03bc\n  \u00b7 refine' integral_mono_ae \u27e8hfm, _\u27e9 hgi h\n    refine' hgi.has_finite_integral.mono <| h.mp <| hf.mono fun x hf hfg => _\n    simpa [abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)]\n  \u00b7 rw [integral_non_ae_strongly_measurable hfm]\n    exact integral_nonneg_of_ae (hf.trans h)\n#align measure_theory.integral_mono_of_nonneg MeasureTheory.integral_mono_of_nonneg\n\ntheorem integral_mono_measure {f : \u03b1 \u2192 \u211d} {\u03bd} (hle : \u03bc \u2264 \u03bd) (hf : 0 \u2264\u1d50[\u03bd] f)\n    (hfi : Integrable f \u03bd) : (\u222b a, f a \u2202\u03bc) \u2264 \u222b a, f a \u2202\u03bd :=\n  by\n  have hfi' : integrable f \u03bc := hfi.mono_measure hle\n  have hf' : 0 \u2264\u1d50[\u03bc] f := hle.absolutely_continuous hf\n  rw [integral_eq_lintegral_of_nonneg_ae hf' hfi'.1, integral_eq_lintegral_of_nonneg_ae hf hfi.1,\n    ENNReal.toReal_le_toReal]\n  exacts[lintegral_mono' hle le_rfl, ((has_finite_integral_iff_of_real hf').1 hfi'.2).Ne,\n    ((has_finite_integral_iff_of_real hf).1 hfi.2).Ne]\n#align measure_theory.integral_mono_measure MeasureTheory.integral_mono_measure\n\ntheorem norm_integral_le_integral_norm (f : \u03b1 \u2192 E) : \u2016\u222b a, f a \u2202\u03bc\u2016 \u2264 \u222b a, \u2016f a\u2016 \u2202\u03bc :=\n  have le_ae : \u2200\u1d50 a \u2202\u03bc, 0 \u2264 \u2016f a\u2016 := eventually_of_forall fun a => norm_nonneg _\n  by_cases\n    (fun h : AeStronglyMeasurable f \u03bc =>\n      calc\n        \u2016\u222b a, f a \u2202\u03bc\u2016 \u2264 ENNReal.toReal (\u222b\u207b a, ENNReal.ofReal \u2016f a\u2016 \u2202\u03bc) :=\n          norm_integral_le_lintegral_norm _\n        _ = \u222b a, \u2016f a\u2016 \u2202\u03bc := (integral_eq_lintegral_of_nonneg_ae le_ae <| h.norm).symm\n        )\n    fun h : \u00acAeStronglyMeasurable f \u03bc =>\n    by\n    rw [integral_non_ae_strongly_measurable h, norm_zero]\n    exact integral_nonneg_of_ae le_ae\n#align measure_theory.norm_integral_le_integral_norm MeasureTheory.norm_integral_le_integral_norm\n\ntheorem norm_integral_le_of_norm_le {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 \u211d} (hg : Integrable g \u03bc)\n    (h : \u2200\u1d50 x \u2202\u03bc, \u2016f x\u2016 \u2264 g x) : \u2016\u222b x, f x \u2202\u03bc\u2016 \u2264 \u222b x, g x \u2202\u03bc :=\n  calc\n    \u2016\u222b x, f x \u2202\u03bc\u2016 \u2264 \u222b x, \u2016f x\u2016 \u2202\u03bc := norm_integral_le_integral_norm f\n    _ \u2264 \u222b x, g x \u2202\u03bc := integral_mono_of_nonneg (eventually_of_forall fun x => norm_nonneg _) hg h\n    \n#align measure_theory.norm_integral_le_of_norm_le MeasureTheory.norm_integral_le_of_norm_le\n\ntheorem SimpleFunc.integral_eq_integral (f : \u03b1 \u2192\u209b E) (hfi : Integrable f \u03bc) :\n    f.integral \u03bc = \u222b x, f x \u2202\u03bc :=\n  by\n  rw [integral_eq f hfi, \u2190 L1.simple_func.to_Lp_one_eq_to_L1,\n    L1.simple_func.integral_L1_eq_integral, L1.simple_func.integral_eq_integral]\n  exact simple_func.integral_congr hfi (Lp.simple_func.to_simple_func_to_Lp _ _).symm\n#align measure_theory.simple_func.integral_eq_integral MeasureTheory.SimpleFunc.integral_eq_integral\n\ntheorem SimpleFunc.integral_eq_sum (f : \u03b1 \u2192\u209b E) (hfi : Integrable f \u03bc) :\n    (\u222b x, f x \u2202\u03bc) = \u2211 x in f.range, ENNReal.toReal (\u03bc (f \u207b\u00b9' {x})) \u2022 x :=\n  by\n  rw [\u2190 f.integral_eq_integral hfi, simple_func.integral, \u2190 simple_func.integral_eq]\n  rfl\n#align measure_theory.simple_func.integral_eq_sum MeasureTheory.SimpleFunc.integral_eq_sum\n\n@[simp]\ntheorem integral_const (c : E) : (\u222b x : \u03b1, c \u2202\u03bc) = (\u03bc univ).toReal \u2022 c :=\n  by\n  cases' (@le_top _ _ _ (\u03bc univ)).lt_or_eq with h\u03bc h\u03bc\n  \u00b7 haveI : is_finite_measure \u03bc := \u27e8h\u03bc\u27e9\n    simp only [integral, L1.integral]\n    exact set_to_fun_const (dominated_fin_meas_additive_weighted_smul _) _\n  \u00b7 by_cases hc : c = 0\n    \u00b7 simp [hc, integral_zero]\n    \u00b7 have : \u00acintegrable (fun x : \u03b1 => c) \u03bc :=\n        by\n        simp only [integrable_const_iff, not_or]\n        exact \u27e8hc, h\u03bc.not_lt\u27e9\n      simp [integral_undef, *]\n#align measure_theory.integral_const MeasureTheory.integral_const\n\ntheorem norm_integral_le_of_norm_le_const [IsFiniteMeasure \u03bc] {f : \u03b1 \u2192 E} {C : \u211d}\n    (h : \u2200\u1d50 x \u2202\u03bc, \u2016f x\u2016 \u2264 C) : \u2016\u222b x, f x \u2202\u03bc\u2016 \u2264 C * (\u03bc univ).toReal :=\n  calc\n    \u2016\u222b x, f x \u2202\u03bc\u2016 \u2264 \u222b x, C \u2202\u03bc := norm_integral_le_of_norm_le (integrableConst C) h\n    _ = C * (\u03bc univ).toReal := by rw [integral_const, smul_eq_mul, mul_comm]\n    \n#align measure_theory.norm_integral_le_of_norm_le_const MeasureTheory.norm_integral_le_of_norm_le_const\n\ntheorem tendsto_integral_approxOn_of_measurable [MeasurableSpace E] [BorelSpace E] {f : \u03b1 \u2192 E}\n    {s : Set E} [SeparableSpace s] (hfi : Integrable f \u03bc) (hfm : Measurable f)\n    (hs : \u2200\u1d50 x \u2202\u03bc, f x \u2208 closure s) {y\u2080 : E} (h\u2080 : y\u2080 \u2208 s) (h\u2080i : Integrable (fun x => y\u2080) \u03bc) :\n    Tendsto (fun n => (SimpleFunc.approxOn f hfm s y\u2080 h\u2080 n).integral \u03bc) atTop (\ud835\udcdd <| \u222b x, f x \u2202\u03bc) :=\n  by\n  have hfi' := simple_func.integrable_approx_on hfm hfi h\u2080 h\u2080i\n  simp only [simple_func.integral_eq_integral _ (hfi' _), integral, L1.integral]\n  exact\n    tendsto_set_to_fun_approx_on_of_measurable (dominated_fin_meas_additive_weighted_smul \u03bc) hfi hfm\n      hs h\u2080 h\u2080i\n#align measure_theory.tendsto_integral_approx_on_of_measurable MeasureTheory.tendsto_integral_approxOn_of_measurable\n\ntheorem tendsto_integral_approxOn_of_measurable_of_range_subset [MeasurableSpace E] [BorelSpace E]\n    {f : \u03b1 \u2192 E} (fmeas : Measurable f) (hf : Integrable f \u03bc) (s : Set E) [SeparableSpace s]\n    (hs : range f \u222a {0} \u2286 s) :\n    Tendsto (fun n => (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n).integral \u03bc) atTop\n      (\ud835\udcdd <| \u222b x, f x \u2202\u03bc) :=\n  by\n  apply tendsto_integral_approx_on_of_measurable hf fmeas _ _ (integrable_zero _ _ _)\n  exact eventually_of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _)))\n#align measure_theory.tendsto_integral_approx_on_of_measurable_of_range_subset MeasureTheory.tendsto_integral_approxOn_of_measurable_of_range_subset\n\nvariable {\u03bd : Measure \u03b1}\n\ntheorem integral_add_measure {f : \u03b1 \u2192 E} (h\u03bc : Integrable f \u03bc) (h\u03bd : Integrable f \u03bd) :\n    (\u222b x, f x \u2202\u03bc + \u03bd) = (\u222b x, f x \u2202\u03bc) + \u222b x, f x \u2202\u03bd :=\n  by\n  have hfi := h\u03bc.add_measure h\u03bd\n  simp_rw [integral_eq_set_to_fun]\n  have h\u03bc_dfma : dominated_fin_meas_additive (\u03bc + \u03bd) (weighted_smul \u03bc : Set \u03b1 \u2192 E \u2192L[\u211d] E) 1 :=\n    dominated_fin_meas_additive.add_measure_right \u03bc \u03bd (dominated_fin_meas_additive_weighted_smul \u03bc)\n      zero_le_one\n  have h\u03bd_dfma : dominated_fin_meas_additive (\u03bc + \u03bd) (weighted_smul \u03bd : Set \u03b1 \u2192 E \u2192L[\u211d] E) 1 :=\n    dominated_fin_meas_additive.add_measure_left \u03bc \u03bd (dominated_fin_meas_additive_weighted_smul \u03bd)\n      zero_le_one\n  rw [\u2190\n    set_to_fun_congr_measure_of_add_right h\u03bc_dfma (dominated_fin_meas_additive_weighted_smul \u03bc) f\n      hfi,\n    \u2190\n    set_to_fun_congr_measure_of_add_left h\u03bd_dfma (dominated_fin_meas_additive_weighted_smul \u03bd) f\n      hfi]\n  refine' set_to_fun_add_left' _ _ _ (fun s hs h\u03bc\u03bds => _) f\n  rw [measure.coe_add, Pi.add_apply, add_lt_top] at h\u03bc\u03bds\n  rw [weighted_smul, weighted_smul, weighted_smul, \u2190 add_smul, measure.coe_add, Pi.add_apply,\n    to_real_add h\u03bc\u03bds.1.Ne h\u03bc\u03bds.2.Ne]\n#align measure_theory.integral_add_measure MeasureTheory.integral_add_measure\n\n@[simp]\ntheorem integral_zero_measure {m : MeasurableSpace \u03b1} (f : \u03b1 \u2192 E) :\n    (\u222b x, f x \u2202(0 : Measure \u03b1)) = 0 :=\n  by\n  simp only [integral, L1.integral]\n  exact set_to_fun_measure_zero (dominated_fin_meas_additive_weighted_smul _) rfl\n#align measure_theory.integral_zero_measure MeasureTheory.integral_zero_measure\n\ntheorem integral_finset_sum_measure {\u03b9} {m : MeasurableSpace \u03b1} {f : \u03b1 \u2192 E} {\u03bc : \u03b9 \u2192 Measure \u03b1}\n    {s : Finset \u03b9} (hf : \u2200 i \u2208 s, Integrable f (\u03bc i)) :\n    (\u222b a, f a \u2202\u2211 i in s, \u03bc i) = \u2211 i in s, \u222b a, f a \u2202\u03bc i := by\n  classical\n    refine' Finset.induction_on' s _ _\n    -- `induction s using finset.induction_on'` fails\n    \u00b7 simp\n    \u00b7 intro i t hi ht hit iht\n      simp only [Finset.sum_insert hit, \u2190 iht]\n      exact\n        integral_add_measure (hf _ hi) (integrable_finset_sum_measure.2 fun j hj => hf j (ht hj))\n#align measure_theory.integral_finset_sum_measure MeasureTheory.integral_finset_sum_measure\n\ntheorem nndist_integral_add_measure_le_lintegral (h\u2081 : Integrable f \u03bc) (h\u2082 : Integrable f \u03bd) :\n    (nndist (\u222b x, f x \u2202\u03bc) (\u222b x, f x \u2202\u03bc + \u03bd) : \u211d\u22650\u221e) \u2264 \u222b\u207b x, \u2016f x\u2016\u208a \u2202\u03bd :=\n  by\n  rw [integral_add_measure h\u2081 h\u2082, nndist_comm, nndist_eq_nnnorm, add_sub_cancel']\n  exact ennnorm_integral_le_lintegral_ennnorm _\n#align measure_theory.nndist_integral_add_measure_le_lintegral MeasureTheory.nndist_integral_add_measure_le_lintegral\n\ntheorem hasSum_integral_measure {\u03b9} {m : MeasurableSpace \u03b1} {f : \u03b1 \u2192 E} {\u03bc : \u03b9 \u2192 Measure \u03b1}\n    (hf : Integrable f (Measure.sum \u03bc)) :\n    HasSum (fun i => \u222b a, f a \u2202\u03bc i) (\u222b a, f a \u2202Measure.sum \u03bc) :=\n  by\n  have hfi : \u2200 i, integrable f (\u03bc i) := fun i => hf.mono_measure (measure.le_sum _ _)\n  simp only [HasSum, \u2190 integral_finset_sum_measure fun i _ => hfi i]\n  refine' metric.nhds_basis_ball.tendsto_right_iff.mpr fun \u03b5 \u03b50 => _\n  lift \u03b5 to \u211d\u22650 using \u03b50.le\n  have hf_lt : (\u222b\u207b x, \u2016f x\u2016\u208a \u2202measure.sum \u03bc) < \u221e := hf.2\n  have hmem : \u2200\u1da0 y in \ud835\udcdd (\u222b\u207b x, \u2016f x\u2016\u208a \u2202measure.sum \u03bc), (\u222b\u207b x, \u2016f x\u2016\u208a \u2202measure.sum \u03bc) < y + \u03b5 :=\n    by\n    refine' tendsto_id.add tendsto_const_nhds (lt_mem_nhds <| ENNReal.lt_add_right _ _)\n    exacts[hf_lt.ne, ENNReal.coe_ne_zero.2 (NNReal.coe_ne_zero.1 \u03b50.ne')]\n  refine' ((has_sum_lintegral_measure (fun x => \u2016f x\u2016\u208a) \u03bc).Eventually hmem).mono fun s hs => _\n  obtain \u27e8\u03bd, h\u03bd\u27e9 : \u2203 \u03bd, (\u2211 i in s, \u03bc i) + \u03bd = measure.sum \u03bc :=\n    by\n    refine' \u27e8measure.sum fun i : \u21a5(s\u1d9c : Set \u03b9) => \u03bc i, _\u27e9\n    simpa only [\u2190 measure.sum_coe_finset] using measure.sum_add_sum_compl (s : Set \u03b9) \u03bc\n  rw [Metric.mem_ball, \u2190 coe_nndist, NNReal.coe_lt_coe, \u2190 ENNReal.coe_lt_coe, \u2190 h\u03bd]\n  rw [\u2190 h\u03bd, integrable_add_measure] at hf\n  refine' (nndist_integral_add_measure_le_lintegral hf.1 hf.2).trans_lt _\n  rw [\u2190 h\u03bd, lintegral_add_measure, lintegral_finset_sum_measure] at hs\n  exact lt_of_add_lt_add_left hs\n#align measure_theory.has_sum_integral_measure MeasureTheory.hasSum_integral_measure\n\ntheorem integral_sum_measure {\u03b9} {m : MeasurableSpace \u03b1} {f : \u03b1 \u2192 E} {\u03bc : \u03b9 \u2192 Measure \u03b1}\n    (hf : Integrable f (Measure.sum \u03bc)) : (\u222b a, f a \u2202Measure.sum \u03bc) = \u2211' i, \u222b a, f a \u2202\u03bc i :=\n  (hasSum_integral_measure hf).tsum_eq.symm\n#align measure_theory.integral_sum_measure MeasureTheory.integral_sum_measure\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:72:38: in filter_upwards #[[], [\"with\", ident x], []]: ./././Mathport/Syntax/Translate/Basic.lean:349:22: unsupported: parse error @ arg 0: next failed, no more args -/\ntheorem integral_tsum {\u03b9} [Countable \u03b9] {f : \u03b9 \u2192 \u03b1 \u2192 E} (hf : \u2200 i, AeStronglyMeasurable (f i) \u03bc)\n    (hf' : (\u2211' i, \u222b\u207b a : \u03b1, \u2016f i a\u2016\u208a \u2202\u03bc) \u2260 \u221e) :\n    (\u222b a : \u03b1, \u2211' i, f i a \u2202\u03bc) = \u2211' i, \u222b a : \u03b1, f i a \u2202\u03bc :=\n  by\n  have hf'' : \u2200 i, AeMeasurable (fun x => (\u2016f i x\u2016\u208a : \u211d\u22650\u221e)) \u03bc := fun i => (hf i).ennnorm\n  have hhh : \u2200\u1d50 a : \u03b1 \u2202\u03bc, Summable fun n => (\u2016f n a\u2016\u208a : \u211d) :=\n    by\n    rw [\u2190 lintegral_tsum hf''] at hf'\n    refine' (ae_lt_top' (AeMeasurable.ennrealTsum hf'') hf').mono _\n    intro x hx\n    rw [\u2190 ENNReal.tsum_coe_ne_top_iff_summable_coe]\n    exact hx.ne\n  convert(MeasureTheory.hasSum_integral_of_dominated_convergence (fun i a => \u2016f i a\u2016\u208a) hf _ hhh\n          \u27e8_, _\u27e9 _).tsum_eq.symm\n  \u00b7 intro n\n    trace\n      \"./././Mathport/Syntax/Translate/Tactic/Builtin.lean:72:38: in filter_upwards #[[], [\\\"with\\\", ident x], []]: ./././Mathport/Syntax/Translate/Basic.lean:349:22: unsupported: parse error @ arg 0: next failed, no more args\"\n    rfl\n  \u00b7 simp_rw [\u2190 coe_nnnorm, \u2190 NNReal.coe_tsum]\n    rw [aeStronglyMeasurable_iff_aeMeasurable]\n    apply AeMeasurable.coeNnrealReal\n    apply AeMeasurable.nnrealTsum\n    exact fun i => (hf i).nnnorm.AeMeasurable\n  \u00b7 dsimp [has_finite_integral]\n    have : (\u222b\u207b a, \u2211' n, \u2016f n a\u2016\u208a \u2202\u03bc) < \u22a4 := by rwa [lintegral_tsum hf'', lt_top_iff_ne_top]\n    convert this using 1\n    apply lintegral_congr_ae\n    simp_rw [\u2190 coe_nnnorm, \u2190 NNReal.coe_tsum, NNReal.nnnorm_eq]\n    filter_upwards [hhh]with a ha\n    exact ENNReal.coe_tsum (nnreal.summable_coe.mp ha)\n  \u00b7 filter_upwards [hhh]with x hx\n    exact (summable_of_summable_norm hx).HasSum\n#align measure_theory.integral_tsum MeasureTheory.integral_tsum\n\n@[simp]\ntheorem integral_smul_measure (f : \u03b1 \u2192 E) (c : \u211d\u22650\u221e) : (\u222b x, f x \u2202c \u2022 \u03bc) = c.toReal \u2022 \u222b x, f x \u2202\u03bc :=\n  by\n  -- First we consider the \u201cdegenerate\u201d case `c = \u221e`\n  rcases eq_or_ne c \u221e with (rfl | hc)\n  \u00b7 rw [ENNReal.top_toReal, zero_smul, integral_eq_set_to_fun, set_to_fun_top_smul_measure]\n  -- Main case: `c \u2260 \u221e`\n  simp_rw [integral_eq_set_to_fun, \u2190 set_to_fun_smul_left]\n  have hdfma :\n    dominated_fin_meas_additive \u03bc (weighted_smul (c \u2022 \u03bc) : Set \u03b1 \u2192 E \u2192L[\u211d] E) c.to_real :=\n    mul_one c.to_real \u25b8 (dominated_fin_meas_additive_weighted_smul (c \u2022 \u03bc)).ofSmulMeasure c hc\n  have hdfma_smul := dominated_fin_meas_additive_weighted_smul (c \u2022 \u03bc)\n  rw [\u2190 set_to_fun_congr_smul_measure c hc hdfma hdfma_smul f]\n  exact set_to_fun_congr_left' _ _ (fun s hs h\u03bcs => weighted_smul_smul_measure \u03bc c) f\n#align measure_theory.integral_smul_measure MeasureTheory.integral_smul_measure\n\ntheorem integral_map_of_stronglyMeasurable {\u03b2} [MeasurableSpace \u03b2] {\u03c6 : \u03b1 \u2192 \u03b2} (h\u03c6 : Measurable \u03c6)\n    {f : \u03b2 \u2192 E} (hfm : StronglyMeasurable f) : (\u222b y, f y \u2202Measure.map \u03c6 \u03bc) = \u222b x, f (\u03c6 x) \u2202\u03bc :=\n  by\n  by_cases hfi : integrable f (measure.map \u03c6 \u03bc); swap\n  \u00b7 rw [integral_undef hfi, integral_undef]\n    rwa [\u2190 integrable_map_measure hfm.ae_strongly_measurable h\u03c6.ae_measurable]\n  borelize E\n  haveI : separable_space (range f \u222a {0} : Set E) := hfm.separable_space_range_union_singleton\n  refine'\n    tendsto_nhds_unique\n      (tendsto_integral_approx_on_of_measurable_of_range_subset hfm.measurable hfi _ subset.rfl) _\n  convert tendsto_integral_approx_on_of_measurable_of_range_subset (hfm.measurable.comp h\u03c6)\n      ((integrable_map_measure hfm.ae_strongly_measurable h\u03c6.ae_measurable).1 hfi) (range f \u222a {0})\n      (by simp [insert_subset_insert, Set.range_comp_subset_range]) using\n    1\n  ext1 i\n  simp only [simple_func.approx_on_comp, simple_func.integral_eq, measure.map_apply, h\u03c6,\n    simple_func.measurable_set_preimage, \u2190 preimage_comp, simple_func.coe_comp]\n  refine' (Finset.sum_subset (simple_func.range_comp_subset_range _ h\u03c6) fun y _ hy => _).symm\n  rw [simple_func.mem_range, \u2190 Set.preimage_singleton_eq_empty, simple_func.coe_comp] at hy\n  rw [hy]\n  simp\n#align measure_theory.integral_map_of_strongly_measurable MeasureTheory.integral_map_of_stronglyMeasurable\n\ntheorem integral_map {\u03b2} [MeasurableSpace \u03b2] {\u03c6 : \u03b1 \u2192 \u03b2} (h\u03c6 : AeMeasurable \u03c6 \u03bc) {f : \u03b2 \u2192 E}\n    (hfm : AeStronglyMeasurable f (Measure.map \u03c6 \u03bc)) :\n    (\u222b y, f y \u2202Measure.map \u03c6 \u03bc) = \u222b x, f (\u03c6 x) \u2202\u03bc :=\n  let g := hfm.mk f\n  calc\n    (\u222b y, f y \u2202Measure.map \u03c6 \u03bc) = \u222b y, g y \u2202Measure.map \u03c6 \u03bc := integral_congr_ae hfm.ae_eq_mk\n    _ = \u222b y, g y \u2202Measure.map (h\u03c6.mk \u03c6) \u03bc := by\n      congr 1\n      exact measure.map_congr h\u03c6.ae_eq_mk\n    _ = \u222b x, g (h\u03c6.mk \u03c6 x) \u2202\u03bc :=\n      (integral_map_of_stronglyMeasurable h\u03c6.measurable_mk hfm.stronglyMeasurable_mk)\n    _ = \u222b x, g (\u03c6 x) \u2202\u03bc := (integral_congr_ae (h\u03c6.ae_eq_mk.symm.fun_comp _))\n    _ = \u222b x, f (\u03c6 x) \u2202\u03bc := integral_congr_ae <| ae_eq_comp h\u03c6 hfm.ae_eq_mk.symm\n    \n#align measure_theory.integral_map MeasureTheory.integral_map\n\ntheorem MeasurableEmbedding.integral_map {\u03b2} {_ : MeasurableSpace \u03b2} {f : \u03b1 \u2192 \u03b2}\n    (hf : MeasurableEmbedding f) (g : \u03b2 \u2192 E) : (\u222b y, g y \u2202Measure.map f \u03bc) = \u222b x, g (f x) \u2202\u03bc :=\n  by\n  by_cases hgm : ae_strongly_measurable g (measure.map f \u03bc)\n  \u00b7 exact integral_map hf.measurable.ae_measurable hgm\n  \u00b7 rw [integral_non_ae_strongly_measurable hgm, integral_non_ae_strongly_measurable]\n    rwa [\u2190 hf.ae_strongly_measurable_map_iff]\n#align measurable_embedding.integral_map MeasurableEmbedding.integral_map\n\ntheorem ClosedEmbedding.integral_map {\u03b2} [TopologicalSpace \u03b1] [BorelSpace \u03b1] [TopologicalSpace \u03b2]\n    [MeasurableSpace \u03b2] [BorelSpace \u03b2] {\u03c6 : \u03b1 \u2192 \u03b2} (h\u03c6 : ClosedEmbedding \u03c6) (f : \u03b2 \u2192 E) :\n    (\u222b y, f y \u2202Measure.map \u03c6 \u03bc) = \u222b x, f (\u03c6 x) \u2202\u03bc :=\n  h\u03c6.MeasurableEmbedding.integral_map _\n#align closed_embedding.integral_map ClosedEmbedding.integral_map\n\ntheorem integral_map_equiv {\u03b2} [MeasurableSpace \u03b2] (e : \u03b1 \u2243\u1d50 \u03b2) (f : \u03b2 \u2192 E) :\n    (\u222b y, f y \u2202Measure.map e \u03bc) = \u222b x, f (e x) \u2202\u03bc :=\n  e.MeasurableEmbedding.integral_map f\n#align measure_theory.integral_map_equiv MeasureTheory.integral_map_equiv\n\ntheorem MeasurePreserving.integral_comp {\u03b2} {_ : MeasurableSpace \u03b2} {f : \u03b1 \u2192 \u03b2} {\u03bd}\n    (h\u2081 : MeasurePreserving f \u03bc \u03bd) (h\u2082 : MeasurableEmbedding f) (g : \u03b2 \u2192 E) :\n    (\u222b x, g (f x) \u2202\u03bc) = \u222b y, g y \u2202\u03bd :=\n  h\u2081.map_eq \u25b8 (h\u2082.integral_map g).symm\n#align measure_theory.measure_preserving.integral_comp MeasureTheory.MeasurePreserving.integral_comp\n\ntheorem set_integral_eq_subtype {\u03b1} [MeasureSpace \u03b1] {s : Set \u03b1} (hs : MeasurableSet s)\n    (f : \u03b1 \u2192 E) : (\u222b x in s, f x) = \u222b x : s, f x :=\n  by\n  rw [\u2190 map_comap_subtype_coe hs]\n  exact (MeasurableEmbedding.subtype_coe hs).integral_map _\n#align measure_theory.set_integral_eq_subtype MeasureTheory.set_integral_eq_subtype\n\n@[simp]\ntheorem integral_dirac' [MeasurableSpace \u03b1] (f : \u03b1 \u2192 E) (a : \u03b1) (hfm : StronglyMeasurable f) :\n    (\u222b x, f x \u2202Measure.dirac a) = f a := by\n  borelize E\n  calc\n    (\u222b x, f x \u2202measure.dirac a) = \u222b x, f a \u2202measure.dirac a :=\n      integral_congr_ae <| ae_eq_dirac' hfm.measurable\n    _ = f a := by simp [measure.dirac_apply_of_mem]\n    \n#align measure_theory.integral_dirac' MeasureTheory.integral_dirac'\n\n@[simp]\ntheorem integral_dirac [MeasurableSpace \u03b1] [MeasurableSingletonClass \u03b1] (f : \u03b1 \u2192 E) (a : \u03b1) :\n    (\u222b x, f x \u2202Measure.dirac a) = f a :=\n  calc\n    (\u222b x, f x \u2202Measure.dirac a) = \u222b x, f a \u2202Measure.dirac a := integral_congr_ae <| ae_eq_dirac f\n    _ = f a := by simp [measure.dirac_apply_of_mem]\n    \n#align measure_theory.integral_dirac MeasureTheory.integral_dirac\n\ntheorem mul_meas_ge_le_integral_of_nonneg [IsFiniteMeasure \u03bc] {f : \u03b1 \u2192 \u211d} (hf_nonneg : 0 \u2264 f)\n    (hf_int : Integrable f \u03bc) (\u03b5 : \u211d) : \u03b5 * (\u03bc { x | \u03b5 \u2264 f x }).toReal \u2264 \u222b x, f x \u2202\u03bc :=\n  by\n  cases' lt_or_le \u03b5 0 with h\u03b5 h\u03b5\n  \u00b7\n    exact\n      (mul_nonpos_of_nonpos_of_nonneg h\u03b5.le ENNReal.toReal_nonneg).trans (integral_nonneg hf_nonneg)\n  rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall fun x => hf_nonneg x)\n      hf_int.ae_strongly_measurable,\n    \u2190 ENNReal.toReal_ofReal h\u03b5, \u2190 ENNReal.toReal_mul]\n  have :\n    { x : \u03b1 | (ENNReal.ofReal \u03b5).toReal \u2264 f x } =\n      { x : \u03b1 | ENNReal.ofReal \u03b5 \u2264 (fun x => ENNReal.ofReal (f x)) x } :=\n    by\n    ext1 x\n    rw [Set.mem_setOf_eq, Set.mem_setOf_eq, \u2190 ENNReal.toReal_ofReal (hf_nonneg x)]\n    exact ENNReal.toReal_le_toReal ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top\n  rw [this]\n  have h_meas : AeMeasurable (fun x => ENNReal.ofReal (f x)) \u03bc :=\n    measurable_id'.ennreal_of_real.comp_ae_measurable hf_int.ae_measurable\n  have h_mul_meas_le := @mul_meas_ge_le_lintegral\u2080 _ _ \u03bc _ h_meas (ENNReal.ofReal \u03b5)\n  rw [ENNReal.toReal_le_toReal _ _]\n  \u00b7 exact h_mul_meas_le\n  \u00b7 simp only [Ne.def, WithTop.mul_eq_top_iff, ENNReal.ofReal_eq_zero, not_le,\n      ENNReal.ofReal_ne_top, false_and_iff, or_false_iff, not_and]\n    exact fun _ => measure_ne_top _ _\n  \u00b7 have h_lt_top : (\u222b\u207b a, \u2016f a\u2016\u208a \u2202\u03bc) < \u221e := hf_int.has_finite_integral\n    simp_rw [\u2190 ofReal_norm_eq_coe_nnnorm, Real.norm_eq_abs] at h_lt_top\n    convert h_lt_top.ne\n    ext1 x\n    rw [abs_of_nonneg (hf_nonneg x)]\n#align measure_theory.mul_meas_ge_le_integral_of_nonneg MeasureTheory.mul_meas_ge_le_integral_of_nonneg\n\n/-- H\u00f6lder's inequality for the integral of a product of norms. The integral of the product of two\nnorms of functions is bounded by the product of their `\u2112p` and `\u2112q` seminorms when `p` and `q` are\nconjugate exponents. -/\ntheorem integral_mul_norm_le_Lp_mul_Lq {E} [NormedAddCommGroup E] {f g : \u03b1 \u2192 E} {p q : \u211d}\n    (hpq : p.IsConjugateExponent q) (hf : Mem\u2112p f (ENNReal.ofReal p) \u03bc)\n    (hg : Mem\u2112p g (ENNReal.ofReal q) \u03bc) :\n    (\u222b a, \u2016f a\u2016 * \u2016g a\u2016 \u2202\u03bc) \u2264 (\u222b a, \u2016f a\u2016 ^ p \u2202\u03bc) ^ (1 / p) * (\u222b a, \u2016g a\u2016 ^ q \u2202\u03bc) ^ (1 / q) :=\n  by\n  -- translate the Bochner integrals into Lebesgue integrals.\n  rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae,\n    integral_eq_lintegral_of_nonneg_ae]\n  rotate_left\n  \u00b7 exact eventually_of_forall fun x => Real.rpow_nonneg_of_nonneg (norm_nonneg _) _\n  \u00b7 exact (hg.1.norm.AeMeasurable.pow aeMeasurableConst).AeStronglyMeasurable\n  \u00b7 exact eventually_of_forall fun x => Real.rpow_nonneg_of_nonneg (norm_nonneg _) _\n  \u00b7 exact (hf.1.norm.AeMeasurable.pow aeMeasurableConst).AeStronglyMeasurable\n  \u00b7 exact eventually_of_forall fun x => mul_nonneg (norm_nonneg _) (norm_nonneg _)\n  \u00b7 exact hf.1.norm.mul hg.1.norm\n  rw [ENNReal.toReal_rpow, ENNReal.toReal_rpow, \u2190 ENNReal.toReal_mul]\n  -- replace norms by nnnorm\n  have h_left :\n    (\u222b\u207b a, ENNReal.ofReal (\u2016f a\u2016 * \u2016g a\u2016) \u2202\u03bc) =\n      \u222b\u207b a, ((fun x => (\u2016f x\u2016\u208a : \u211d\u22650\u221e)) * fun x => \u2016g x\u2016\u208a) a \u2202\u03bc :=\n    by simp_rw [Pi.mul_apply, \u2190 ofReal_norm_eq_coe_nnnorm, ENNReal.ofReal_mul (norm_nonneg _)]\n  have h_right_f : (\u222b\u207b a, ENNReal.ofReal (\u2016f a\u2016 ^ p) \u2202\u03bc) = \u222b\u207b a, \u2016f a\u2016\u208a ^ p \u2202\u03bc :=\n    by\n    refine' lintegral_congr fun x => _\n    rw [\u2190 ofReal_norm_eq_coe_nnnorm, ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) hpq.nonneg]\n  have h_right_g : (\u222b\u207b a, ENNReal.ofReal (\u2016g a\u2016 ^ q) \u2202\u03bc) = \u222b\u207b a, \u2016g a\u2016\u208a ^ q \u2202\u03bc :=\n    by\n    refine' lintegral_congr fun x => _\n    rw [\u2190 ofReal_norm_eq_coe_nnnorm, ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) hpq.symm.nonneg]\n  rw [h_left, h_right_f, h_right_g]\n  -- we can now apply `ennreal.lintegral_mul_le_Lp_mul_Lq` (up to the `to_real` application)\n  refine' ENNReal.toReal_mono _ _\n  \u00b7 refine' ENNReal.mul_ne_top _ _\n    \u00b7 convert hf.snorm_ne_top\n      rw [snorm_eq_lintegral_rpow_nnnorm]\n      \u00b7 rw [ENNReal.toReal_ofReal hpq.nonneg]\n      \u00b7 rw [Ne.def, ENNReal.ofReal_eq_zero, not_le]\n        exact hpq.pos\n      \u00b7 exact ENNReal.coe_ne_top\n    \u00b7 convert hg.snorm_ne_top\n      rw [snorm_eq_lintegral_rpow_nnnorm]\n      \u00b7 rw [ENNReal.toReal_ofReal hpq.symm.nonneg]\n      \u00b7 rw [Ne.def, ENNReal.ofReal_eq_zero, not_le]\n        exact hpq.symm.pos\n      \u00b7 exact ENNReal.coe_ne_top\n  \u00b7\n    exact\n      ENNReal.lintegral_mul_le_Lp_mul_Lq \u03bc hpq hf.1.nnnorm.AeMeasurable.coe_nNReal_eNNReal\n        hg.1.nnnorm.AeMeasurable.coe_nNReal_eNNReal\n#align measure_theory.integral_mul_norm_le_Lp_mul_Lq MeasureTheory.integral_mul_norm_le_Lp_mul_Lq\n\n/-- H\u00f6lder's inequality for functions `\u03b1 \u2192 \u211d`. The integral of the product of two nonnegative\nfunctions is bounded by the product of their `\u2112p` and `\u2112q` seminorms when `p` and `q` are conjugate\nexponents. -/\ntheorem integral_mul_le_Lp_mul_Lq_of_nonneg {p q : \u211d} (hpq : p.IsConjugateExponent q) {f g : \u03b1 \u2192 \u211d}\n    (hf_nonneg : 0 \u2264\u1d50[\u03bc] f) (hg_nonneg : 0 \u2264\u1d50[\u03bc] g) (hf : Mem\u2112p f (ENNReal.ofReal p) \u03bc)\n    (hg : Mem\u2112p g (ENNReal.ofReal q) \u03bc) :\n    (\u222b a, f a * g a \u2202\u03bc) \u2264 (\u222b a, f a ^ p \u2202\u03bc) ^ (1 / p) * (\u222b a, g a ^ q \u2202\u03bc) ^ (1 / q) :=\n  by\n  have h_left : (\u222b a, f a * g a \u2202\u03bc) = \u222b a, \u2016f a\u2016 * \u2016g a\u2016 \u2202\u03bc :=\n    by\n    refine' integral_congr_ae _\n    filter_upwards [hf_nonneg, hg_nonneg]with x hxf hxg\n    rw [Real.norm_of_nonneg hxf, Real.norm_of_nonneg hxg]\n  have h_right_f : (\u222b a, f a ^ p \u2202\u03bc) = \u222b a, \u2016f a\u2016 ^ p \u2202\u03bc :=\n    by\n    refine' integral_congr_ae _\n    filter_upwards [hf_nonneg]with x hxf\n    rw [Real.norm_of_nonneg hxf]\n  have h_right_g : (\u222b a, g a ^ q \u2202\u03bc) = \u222b a, \u2016g a\u2016 ^ q \u2202\u03bc :=\n    by\n    refine' integral_congr_ae _\n    filter_upwards [hg_nonneg]with x hxg\n    rw [Real.norm_of_nonneg hxg]\n  rw [h_left, h_right_f, h_right_g]\n  exact integral_mul_norm_le_Lp_mul_Lq hpq hf hg\n#align measure_theory.integral_mul_le_Lp_mul_Lq_of_nonneg MeasureTheory.integral_mul_le_Lp_mul_Lq_of_nonneg\n\nend Properties\n\n/- failed to parenthesize: unknown constant 'Lean.Meta._root_.Lean.Parser.Command.registerSimpAttr'\n[PrettyPrinter.parenthesize.input] (Lean.Meta._root_.Lean.Parser.Command.registerSimpAttr\n     [(Command.docComment \"/--\" \"Simp set for integral rules. -/\")]\n     \"register_simp_attr\"\n     `integral_simps)-/-- failed to format: unknown constant 'Lean.Meta._root_.Lean.Parser.Command.registerSimpAttr'\n/-- Simp set for integral rules. -/ register_simp_attr integral_simps\n\nattribute [integral_simps]\n  integral_neg integral_smul L1.integral_add L1.integral_sub L1.integral_smul L1.integral_neg\n\nsection IntegralTrim\n\nvariable {H \u03b2 \u03b3 : Type _} [NormedAddCommGroup H] {m m0 : MeasurableSpace \u03b2} {\u03bc : Measure \u03b2}\n\n/-- Simple function seen as simple function of a larger `measurable_space`. -/\ndef SimpleFunc.toLargerSpace (hm : m \u2264 m0) (f : @SimpleFunc \u03b2 m \u03b3) : SimpleFunc \u03b2 \u03b3 :=\n  \u27e8@SimpleFunc.toFun \u03b2 m \u03b3 f, fun x => hm _ (@SimpleFunc.measurableSet_fiber \u03b2 \u03b3 m f x),\n    @SimpleFunc.finite_range \u03b2 \u03b3 m f\u27e9\n#align measure_theory.simple_func.to_larger_space MeasureTheory.SimpleFunc.toLargerSpace\n\ntheorem SimpleFunc.coe_toLargerSpace_eq (hm : m \u2264 m0) (f : @SimpleFunc \u03b2 m \u03b3) :\n    \u21d1(f.toLargerSpace hm) = f :=\n  rfl\n#align measure_theory.simple_func.coe_to_larger_space_eq MeasureTheory.SimpleFunc.coe_toLargerSpace_eq\n\ntheorem integral_simpleFunc_larger_space (hm : m \u2264 m0) (f : @SimpleFunc \u03b2 m F)\n    (hf_int : Integrable f \u03bc) :\n    (\u222b x, f x \u2202\u03bc) = \u2211 x in @SimpleFunc.range \u03b2 F m f, ENNReal.toReal (\u03bc (f \u207b\u00b9' {x})) \u2022 x :=\n  by\n  simp_rw [\u2190 f.coe_to_larger_space_eq hm]\n  have hf_int : integrable (f.to_larger_space hm) \u03bc := by rwa [simple_func.coe_to_larger_space_eq]\n  rw [simple_func.integral_eq_sum _ hf_int]\n  congr\n#align measure_theory.integral_simple_func_larger_space MeasureTheory.integral_simpleFunc_larger_space\n\ntheorem integral_trim_simpleFunc (hm : m \u2264 m0) (f : @SimpleFunc \u03b2 m F) (hf_int : Integrable f \u03bc) :\n    (\u222b x, f x \u2202\u03bc) = \u222b x, f x \u2202\u03bc.trim hm :=\n  by\n  have hf : strongly_measurable[m] f := @simple_func.strongly_measurable \u03b2 F m _ f\n  have hf_int_m := hf_int.trim hm hf\n  rw [integral_simple_func_larger_space (le_refl m) f hf_int_m,\n    integral_simple_func_larger_space hm f hf_int]\n  congr with x\n  congr\n  exact (trim_measurable_set_eq hm (@simple_func.measurable_set_fiber \u03b2 F m f x)).symm\n#align measure_theory.integral_trim_simple_func MeasureTheory.integral_trim_simpleFunc\n\ntheorem integral_trim (hm : m \u2264 m0) {f : \u03b2 \u2192 F} (hf : strongly_measurable[m] f) :\n    (\u222b x, f x \u2202\u03bc) = \u222b x, f x \u2202\u03bc.trim hm := by\n  borelize F\n  by_cases hf_int : integrable f \u03bc\n  swap\n  \u00b7 have hf_int_m : \u00acintegrable f (\u03bc.trim hm) := fun hf_int_m =>\n      hf_int (integrable_of_integrable_trim hm hf_int_m)\n    rw [integral_undef hf_int, integral_undef hf_int_m]\n  haveI : separable_space (range f \u222a {0} : Set F) := hf.separable_space_range_union_singleton\n  let f_seq := @simple_func.approx_on F \u03b2 _ _ _ m _ hf.measurable (range f \u222a {0}) 0 (by simp) _\n  have hf_seq_meas : \u2200 n, strongly_measurable[m] (f_seq n) := fun n =>\n    @simple_func.strongly_measurable \u03b2 F m _ (f_seq n)\n  have hf_seq_int : \u2200 n, integrable (f_seq n) \u03bc :=\n    simple_func.integrable_approx_on_range (hf.mono hm).Measurable hf_int\n  have hf_seq_int_m : \u2200 n, integrable (f_seq n) (\u03bc.trim hm) := fun n =>\n    (hf_seq_int n).trim hm (hf_seq_meas n)\n  have hf_seq_eq : \u2200 n, (\u222b x, f_seq n x \u2202\u03bc) = \u222b x, f_seq n x \u2202\u03bc.trim hm := fun n =>\n    integral_trim_simple_func hm (f_seq n) (hf_seq_int n)\n  have h_lim_1 : at_top.tendsto (fun n => \u222b x, f_seq n x \u2202\u03bc) (\ud835\udcdd (\u222b x, f x \u2202\u03bc)) :=\n    by\n    refine' tendsto_integral_of_L1 f hf_int (eventually_of_forall hf_seq_int) _\n    exact simple_func.tendsto_approx_on_range_L1_nnnorm (hf.mono hm).Measurable hf_int\n  have h_lim_2 : at_top.tendsto (fun n => \u222b x, f_seq n x \u2202\u03bc) (\ud835\udcdd (\u222b x, f x \u2202\u03bc.trim hm)) :=\n    by\n    simp_rw [hf_seq_eq]\n    refine'\n      @tendsto_integral_of_L1 \u03b2 F _ _ _ m (\u03bc.trim hm) _ f (hf_int.trim hm hf) _ _\n        (eventually_of_forall hf_seq_int_m) _\n    exact\n      @simple_func.tendsto_approx_on_range_L1_nnnorm \u03b2 F m _ _ _ f _ _ hf.measurable\n        (hf_int.trim hm hf)\n  exact tendsto_nhds_unique h_lim_1 h_lim_2\n#align measure_theory.integral_trim MeasureTheory.integral_trim\n\ntheorem integral_trim_ae (hm : m \u2264 m0) {f : \u03b2 \u2192 F} (hf : AeStronglyMeasurable f (\u03bc.trim hm)) :\n    (\u222b x, f x \u2202\u03bc) = \u222b x, f x \u2202\u03bc.trim hm :=\n  by\n  rw [integral_congr_ae (ae_eq_of_ae_eq_trim hf.ae_eq_mk), integral_congr_ae hf.ae_eq_mk]\n  exact integral_trim hm hf.strongly_measurable_mk\n#align measure_theory.integral_trim_ae MeasureTheory.integral_trim_ae\n\ntheorem ae_eq_trim_of_stronglyMeasurable [TopologicalSpace \u03b3] [MetrizableSpace \u03b3] (hm : m \u2264 m0)\n    {f g : \u03b2 \u2192 \u03b3} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g)\n    (hfg : f =\u1d50[\u03bc] g) : f =\u1d50[\u03bc.trim hm] g :=\n  by\n  rwa [eventually_eq, ae_iff, trim_measurable_set_eq hm _]\n  exact (hf.measurable_set_eq_fun hg).compl\n#align measure_theory.ae_eq_trim_of_strongly_measurable MeasureTheory.ae_eq_trim_of_stronglyMeasurable\n\ntheorem ae_eq_trim_iff [TopologicalSpace \u03b3] [MetrizableSpace \u03b3] (hm : m \u2264 m0) {f g : \u03b2 \u2192 \u03b3}\n    (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) :\n    f =\u1d50[\u03bc.trim hm] g \u2194 f =\u1d50[\u03bc] g :=\n  \u27e8ae_eq_of_ae_eq_trim, ae_eq_trim_of_stronglyMeasurable hm hf hg\u27e9\n#align measure_theory.ae_eq_trim_iff MeasureTheory.ae_eq_trim_iff\n\ntheorem ae_le_trim_of_stronglyMeasurable [LinearOrder \u03b3] [TopologicalSpace \u03b3]\n    [OrderClosedTopology \u03b3] [PseudoMetrizableSpace \u03b3] (hm : m \u2264 m0) {f g : \u03b2 \u2192 \u03b3}\n    (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) (hfg : f \u2264\u1d50[\u03bc] g) :\n    f \u2264\u1d50[\u03bc.trim hm] g :=\n  by\n  rwa [eventually_le, ae_iff, trim_measurable_set_eq hm _]\n  exact (hf.measurable_set_le hg).compl\n#align measure_theory.ae_le_trim_of_strongly_measurable MeasureTheory.ae_le_trim_of_stronglyMeasurable\n\ntheorem ae_le_trim_iff [LinearOrder \u03b3] [TopologicalSpace \u03b3] [OrderClosedTopology \u03b3]\n    [PseudoMetrizableSpace \u03b3] (hm : m \u2264 m0) {f g : \u03b2 \u2192 \u03b3} (hf : strongly_measurable[m] f)\n    (hg : strongly_measurable[m] g) : f \u2264\u1d50[\u03bc.trim hm] g \u2194 f \u2264\u1d50[\u03bc] g :=\n  \u27e8ae_le_of_ae_le_trim, ae_le_trim_of_stronglyMeasurable hm hf hg\u27e9\n#align measure_theory.ae_le_trim_iff MeasureTheory.ae_le_trim_iff\n\nend IntegralTrim\n\nsection SnormBound\n\nvariable {m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n\ntheorem snorm_one_le_of_le {r : \u211d\u22650} {f : \u03b1 \u2192 \u211d} (hfint : Integrable f \u03bc) (hfint' : 0 \u2264 \u222b x, f x \u2202\u03bc)\n    (hf : \u2200\u1d50 \u03c9 \u2202\u03bc, f \u03c9 \u2264 r) : snorm f 1 \u03bc \u2264 2 * \u03bc Set.univ * r :=\n  by\n  by_cases hr : r = 0\n  \u00b7 suffices f =\u1d50[\u03bc] 0\n      by\n      rw [snorm_congr_ae this, snorm_zero, hr, ENNReal.coe_zero, MulZeroClass.mul_zero]\n      exact le_rfl\n    rw [hr, Nonneg.coe_zero] at hf\n    have hnegf : (\u222b x, -f x \u2202\u03bc) = 0 :=\n      by\n      rw [integral_neg, neg_eq_zero]\n      exact le_antisymm (integral_nonpos_of_ae hf) hfint'\n    have := (integral_eq_zero_iff_of_nonneg_ae _ hfint.neg).1 hnegf\n    \u00b7 filter_upwards [this]with \u03c9 h\u03c9\n      rwa [Pi.neg_apply, Pi.zero_apply, neg_eq_zero] at h\u03c9\n    \u00b7 filter_upwards [hf]with \u03c9 h\u03c9\n      rwa [Pi.zero_apply, Pi.neg_apply, Right.nonneg_neg_iff]\n  by_cases h\u03bc : is_finite_measure \u03bc\n  swap\n  \u00b7 have : \u03bc Set.univ = \u221e := by\n      by_contra h\u03bc'\n      exact h\u03bc (is_finite_measure.mk <| lt_top_iff_ne_top.2 h\u03bc')\n    rw [this, ENNReal.mul_top', if_neg, ENNReal.top_mul', if_neg]\n    \u00b7 exact le_top\n    \u00b7 simp [hr]\n    \u00b7 norm_num\n  haveI := h\u03bc\n  rw [integral_eq_integral_pos_part_sub_integral_neg_part hfint, sub_nonneg] at hfint'\n  have hposbdd : (\u222b \u03c9, max (f \u03c9) 0 \u2202\u03bc) \u2264 (\u03bc Set.univ).toReal \u2022 r :=\n    by\n    rw [\u2190 integral_const]\n    refine' integral_mono_ae hfint.real_to_nnreal (integrable_const r) _\n    filter_upwards [hf]with \u03c9 h\u03c9 using Real.toNNReal_le_iff_le_coe.2 h\u03c9\n  rw [mem_\u2112p.snorm_eq_integral_rpow_norm one_ne_zero ENNReal.one_ne_top\n      (mem_\u2112p_one_iff_integrable.2 hfint),\n    ENNReal.ofReal_le_iff_le_toReal\n      (ENNReal.mul_ne_top (ENNReal.mul_ne_top ENNReal.two_ne_top <| @measure_ne_top _ _ _ h\u03bc _)\n        ENNReal.coe_ne_top)]\n  simp_rw [ENNReal.one_toReal, _root_.inv_one, Real.rpow_one, Real.norm_eq_abs, \u2190\n    max_zero_add_max_neg_zero_eq_abs_self, \u2190 Real.coe_toNNReal']\n  rw [integral_add hfint.real_to_nnreal]\n  \u00b7 simp only [Real.coe_toNNReal', ENNReal.toReal_mul, [anonymous], ENNReal.one_toReal,\n      ENNReal.coe_toReal] at hfint'\u22a2\n    refine' (add_le_add_left hfint' _).trans _\n    rwa [\u2190 two_mul, mul_assoc, mul_le_mul_left (two_pos : (0 : \u211d) < 2)]\n  \u00b7 exact hfint.neg.sup (integrable_zero _ _ \u03bc)\n#align measure_theory.snorm_one_le_of_le MeasureTheory.snorm_one_le_of_le\n\ntheorem snorm_one_le_of_le' {r : \u211d} {f : \u03b1 \u2192 \u211d} (hfint : Integrable f \u03bc) (hfint' : 0 \u2264 \u222b x, f x \u2202\u03bc)\n    (hf : \u2200\u1d50 \u03c9 \u2202\u03bc, f \u03c9 \u2264 r) : snorm f 1 \u03bc \u2264 2 * \u03bc Set.univ * ENNReal.ofReal r :=\n  by\n  refine' snorm_one_le_of_le hfint hfint' _\n  simp only [Real.coe_toNNReal', le_max_iff]\n  filter_upwards [hf]with \u03c9 h\u03c9 using Or.inl h\u03c9\n#align measure_theory.snorm_one_le_of_le' MeasureTheory.snorm_one_le_of_le'\n\nend SnormBound\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Integral/Bochner.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7390085423150093}}
{"text": "/-\nCopyright (c) 2021 Chris Hughes, Junyan Xu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Junyan Xu\n\n! This file was ported from Lean 3 source module data.polynomial.cardinal\n! leanprover-community/mathlib commit 62c0a4ef1441edb463095ea02a06e87f3dfe135c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.Basic\nimport Mathlib.SetTheory.Cardinal.Ordinal\n\n/-!\n# Cardinality of Polynomial Ring\n\nThe result in this file is that the cardinality of `R[X]` is at most the maximum\nof `#R` and `\u2135\u2080`.\n-/\n\n\nuniverse u\n\nopen Cardinal Polynomial\n\nopen Cardinal\n\nnamespace Polynomial\n\n@[simp]\ntheorem cardinal_mk_eq_max {R : Type u} [Semiring R] [Nontrivial R] : (#R[X]) = max (#R) \u2135\u2080 :=\n  (toFinsuppIso R).toEquiv.cardinal_eq.trans <|\n    by\n    rw [AddMonoidAlgebra, mk_finsupp_lift_of_infinite, lift_uzero, max_comm]\n    rfl\n#align polynomial.cardinal_mk_eq_max Polynomial.cardinal_mk_eq_max\n\ntheorem cardinal_mk_le_max {R : Type u} [Semiring R] : (#R[X]) \u2264 max (#R) \u2135\u2080 := by\n  cases subsingleton_or_nontrivial R\n  \u00b7 exact (mk_eq_one _).trans_le (le_max_of_le_right one_le_aleph0)\n  \u00b7 exact cardinal_mk_eq_max.le\n#align polynomial.cardinal_mk_le_max Polynomial.cardinal_mk_le_max\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.739008537715165}}
{"text": "-- Conectivas_y_desigualdades.lean\n-- Conectivas y desigualdades.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 23 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- En esta relaci\u00f3n se formulan algunas de las anteriores propiedades de\n-- las desigualdades de los n\u00fameros reales usando conectivas.\n\nimport data.real.basic\n\nvariables (a b c : \u211d)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1. Demostrar que\n--    0 \u2264 a \u2192 b \u2264 a + b\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 b \u2264 a + b :=\nbegin\n  intro ha,\n  exact le_add_of_nonneg_left ha,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 b \u2264 a + b :=\nle_add_of_nonneg_left\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 b \u2264 a + b :=\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    0 \u2264 b \u2192 a \u2264 a + b\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample: 0 \u2264 b \u2192 a \u2264 a + b :=\nbegin\n  intro hb,\n  exact le_add_of_nonneg_right hb,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample: 0 \u2264 b \u2192 a \u2264 a + b :=\nle_add_of_nonneg_right\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample: 0 \u2264 b \u2192 a \u2264 a + b :=\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que\n--    (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b :=\nbegin\n  intros hab,\n  cases hab with ha hb,\n  exact add_nonneg ha hb,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b :=\nbegin\n  rintros \u27e8ha, hb\u27e9,\n  exact add_nonneg ha hb,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b :=\n\u03bb \u27e8ha, hb\u27e9, add_nonneg ha hb\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Demostrar que\n--    0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) := \nbegin\n  intro ha,\n  intro hb,\n  exact add_nonneg ha hb,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) := \nbegin\n  intros ha hb,\n  exact add_nonneg ha hb,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) := \n\u03bb ha hb, add_nonneg ha hb\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) := \nadd_nonneg\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) := \nby intros ; linarith \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que si\n--   (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b\n-- entonces \n--   0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) \n  : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\nbegin\n  intro ha,\n  intro hb,\n  apply H,\n  split,\n  { exact ha, },\n  { exact hb, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) \n  : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\nbegin\n  intros ha hb,\n  apply H,\n  split,\n  { exact ha, },\n  { exact hb, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) \n  : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\nbegin\n  intros ha hb,\n  exact H \u27e8ha, hb\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) \n  : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\n\u03bb ha hb, H \u27e8ha, hb\u27e9\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) \n  : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (H : (0 \u2264 a \u2227 0 \u2264 b) \u2192 0 \u2264 a + b) \n  : 0 \u2264 a \u2192 (0 \u2264 b \u2192 0 \u2264 a + b) :=\nby finish\n\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/2_Conectivas/Conectivas_y_desigualdades.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7390000112519425}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport order.bounds.basic\n\n/-!\n# Intervals in Lattices\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file, we provide instances of lattice structures on intervals within lattices.\nSome of them depend on the order of the endpoints of the interval, and thus are not made\nglobal instances. These are probably not all of the lattice instances that could be placed on these\nintervals, but more can be added easily along the same lines when needed.\n\n## Main definitions\nIn the following, `*` can represent either `c`, `o`, or `i`.\n  * `set.Ic*.order_bot`\n  * `set.Ii*.semillatice_inf`\n  * `set.I*c.order_top`\n  * `set.I*c.semillatice_inf`\n  * `set.I**.lattice`\n  * `set.Iic.bounded_order`, within an `order_bot`\n  * `set.Ici.bounded_order`, within an `order_top`\n\n-/\n\nvariable {\u03b1 : Type*}\n\nnamespace set\n\nnamespace Ico\n\ninstance [semilattice_inf \u03b1] {a b : \u03b1} : semilattice_inf (Ico a b) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, \u27e8le_inf hx.1 hy.1, lt_of_le_of_lt inf_le_left hx.2\u27e9)\n\n/-- `Ico a b` has a bottom element whenever `a < b`. -/\n@[reducible] protected def order_bot [partial_order \u03b1] {a b : \u03b1} (h : a < b) :\n  order_bot (Ico a b) :=\n(is_least_Ico h).order_bot\n\nend Ico\n\nnamespace Iio\n\ninstance [semilattice_inf \u03b1] {a : \u03b1} : semilattice_inf (Iio a) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, lt_of_le_of_lt inf_le_left hx)\n\nend Iio\n\nnamespace Ioc\n\ninstance [semilattice_sup \u03b1] {a b : \u03b1} : semilattice_sup (Ioc a b) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, \u27e8lt_of_lt_of_le hx.1 le_sup_left, sup_le hx.2 hy.2\u27e9)\n\n/-- `Ioc a b` has a top element whenever `a < b`. -/\n@[reducible] protected def order_top [partial_order \u03b1] {a b : \u03b1} (h : a < b) :\n  order_top (Ioc a b) :=\n(is_greatest_Ioc h).order_top\n\nend Ioc\n\nnamespace Ioi\n\ninstance [semilattice_sup \u03b1] {a : \u03b1} : semilattice_sup (Ioi a) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, lt_of_lt_of_le hx le_sup_left)\n\nend Ioi\n\nnamespace Iic\n\ninstance [semilattice_inf \u03b1] {a : \u03b1} : semilattice_inf (Iic a) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, le_trans inf_le_left hx)\n\ninstance [semilattice_sup \u03b1] {a : \u03b1} : semilattice_sup (Iic a) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, sup_le hx hy)\n\ninstance [lattice \u03b1] {a : \u03b1} : lattice (Iic a) :=\n{ .. Iic.semilattice_inf,\n  .. Iic.semilattice_sup }\n\ninstance [preorder \u03b1] {a : \u03b1} : order_top (Iic a) :=\n{ top := \u27e8a, le_refl a\u27e9,\n  le_top := \u03bb x, x.prop }\n\n@[simp] lemma coe_top [preorder \u03b1] {a : \u03b1} : \u2191(\u22a4 : Iic a) = a := rfl\n\ninstance [preorder \u03b1] [order_bot \u03b1] {a : \u03b1} : order_bot (Iic a) :=\n{ bot := \u27e8\u22a5, bot_le\u27e9,\n  bot_le := \u03bb \u27e8_,_\u27e9, subtype.mk_le_mk.2 bot_le }\n\n@[simp] lemma coe_bot [preorder \u03b1] [order_bot \u03b1] {a : \u03b1} : \u2191(\u22a5 : Iic a) = (\u22a5 : \u03b1) := rfl\n\ninstance [preorder \u03b1] [order_bot \u03b1] {a : \u03b1} : bounded_order (Iic a) :=\n{ .. Iic.order_top,\n  .. Iic.order_bot }\n\nend Iic\n\nnamespace Ici\n\ninstance [semilattice_inf \u03b1] {a : \u03b1}: semilattice_inf (Ici a) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, le_inf hx hy)\n\ninstance [semilattice_sup \u03b1] {a : \u03b1} : semilattice_sup (Ici a) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, le_trans hx le_sup_left)\n\ninstance [lattice \u03b1] {a : \u03b1} : lattice (Ici a) :=\n{ .. Ici.semilattice_inf,\n  .. Ici.semilattice_sup }\n\ninstance [distrib_lattice \u03b1] {a : \u03b1} : distrib_lattice (Ici a) :=\n{ le_sup_inf := \u03bb a b c, le_sup_inf,\n  .. Ici.lattice }\n\ninstance [preorder \u03b1] {a : \u03b1} : order_bot (Ici a) :=\n{ bot := \u27e8a, le_refl a\u27e9,\n  bot_le := \u03bb x, x.prop }\n\n@[simp] lemma coe_bot [preorder \u03b1] {a : \u03b1} : \u2191(\u22a5 : Ici a) = a := rfl\n\ninstance [preorder \u03b1] [order_top \u03b1] {a : \u03b1}: order_top (Ici a) :=\n{ top := \u27e8\u22a4, le_top\u27e9,\n  le_top := \u03bb \u27e8_,_\u27e9, subtype.mk_le_mk.2 le_top }\n\n@[simp] lemma coe_top [preorder \u03b1] [order_top \u03b1] {a : \u03b1} : \u2191(\u22a4 : Ici a) = (\u22a4 : \u03b1) := rfl\n\ninstance [preorder \u03b1] [order_top \u03b1] {a : \u03b1}: bounded_order (Ici a) :=\n{ .. Ici.order_top,\n  .. Ici.order_bot }\n\nend Ici\n\nnamespace Icc\n\ninstance [semilattice_inf \u03b1] {a b : \u03b1} : semilattice_inf (Icc a b) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, \u27e8le_inf hx.1 hy.1, le_trans inf_le_left hx.2\u27e9)\n\ninstance [semilattice_sup \u03b1] {a b : \u03b1} : semilattice_sup (Icc a b) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, \u27e8le_trans hx.1 le_sup_left, sup_le hx.2 hy.2\u27e9)\n\ninstance [lattice \u03b1] {a b : \u03b1} : lattice (Icc a b) :=\n{ .. Icc.semilattice_inf,\n  .. Icc.semilattice_sup }\n\n/-- `Icc a b` has a bottom element whenever `a \u2264 b`. -/\n@[reducible] protected def order_bot [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) : order_bot (Icc a b) :=\n(is_least_Icc h).order_bot\n\n/-- `Icc a b` has a top element whenever `a \u2264 b`. -/\n@[reducible] protected def order_top [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) : order_top (Icc a b) :=\n(is_greatest_Icc h).order_top\n\n/-- `Icc a b` is a `bounded_order` whenever `a \u2264 b`. -/\n@[reducible] protected def bounded_order [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) :\n  bounded_order (Icc a b) :=\n{ .. Icc.order_top h,\n  .. Icc.order_bot h }\n\nend Icc\n\nend set\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/lattice_intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7390000063456061}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport topology.algebra.affine\n/-!\n\n# `equiv` -- bijections the easy way\n\nHere's a theorem. Say `f : X \u2192 Y` is a function. Then\nthe following are equivalent:\n\n(1) `f` is a bijection (i.e., injective and surjective)\n(2) There exists a function `g : Y \u2192 X` which is a\ntwo-sided inverse of `f` (i.e. `f \u2218 g` and `g \u2218 f` are\nboth identity functions)\n\nHowever, trying to prove this in Lean, you run into a perhaps\nunexpected hitch. Let's consider following even simpler\ntheorem. Again say `f : X \u2192 Y` is a function. Then I claim\nthe following are equivalent:\n\n(1) `f` is a surjection;\n(2) There exists `g : Y \u2192 X` such that `f(g(y))=y` for all `y : Y`.\n\nIf you didn't know this already, then pause for a second and write down a proof\non paper before continuing. Consider drawing a picture if this helps.\n\nOK here's the proof. To do (1) implies (2) define `g` thus: if `y : Y` then\nby surjectivity of `f` there exists some `x : X` such that `f(x)=y`; define\n`g(y)` to be any such `x` and this works. To do (2) implies (1) just note\nthat if `y : Y` then certainly there exists `x : X` with `f(x)=y` because\nwe can just take `x=g(y)`.\n\nDid you notice where we used the axiom of choice? Do you know what the axiom of choice is?\n\nTo make that function `g : Y \u2192 X` in the proof of (1) \u2192 (2) we need to make *one object* `g`\nwhich involves making a \"random\" choice of element `g(y)` from the nonempty set `{x : X | f x = y}`,\nfor every `y : Y`, all at once. That's exactly what the axiom of choice says that you can do.\nIn fact the axiom of choice is *equivalent* to the claim that (1) and (2) are equivalent.\n\n-/\n\nexample (X Y : Type) (f : X \u2192 Y) : function.surjective f \u2194 \u2203 g : Y \u2192 X, \u2200 y, f(g y)=y :=\nbegin\n  split,\n  { intro hf,\n    -- `hf` has type `\u2200 y, \u2203 x, f x = y`.\n    choose g hg using hf,\n    -- now `g` is a function which, given `y`, chooses such an `x`,\n    -- and `hg` says that `f (g y) = y`,\n    use g,\n    exact hg },\n  { rintro \u27e8g, hg\u27e9 y,\n    exact \u27e8g y, hg y\u27e9 }\nend\n\n-- Now see if you can prove the `bijective` version.\n-- The `apply_fun` tactic might be useful. From the docstring:\n-- \"If we have `h : a = b`, then `apply_fun f at h` will replace this \n-- with `h : f a = f b`.\"\n\nexample (X Y : Type) (f : X \u2192 Y) :\n  function.bijective f \u2194 \u2203 g : Y \u2192 X, (\u2200 y, f(g y)=y) \u2227 (\u2200 x, g(f x) = x) :=\nbegin\n  sorry,\nend\n\n/-\n\n# The axiom of choice in Lean\n\nUnfortunately, *using* the above result is *really annoying*. The theorem\nsays that there *exists* a `g`, but this is a statement in the `Prop`\nuniverse. What we actually want is the inverse itself; this is data, so it\nlives in the `Type` universe. Here are the types of everything:\n\n-- this is on the `Prop` side of Lean\n`\u2203 g : Y \u2192 X, (\u2200 y, f(g y)=y) \u2227 (\u2200 x, g(f x) = x) : Prop`\n\n-- these are on the `Type` side of Lean\n`g : Y \u2192 X`\n`Y \u2192 X : Type`\n\nIn constructive mathematics, or computer science, or whatever you want to\ncall it, it's impossible to move from the `Prop` universe to the `Type`\nuniverse; we know `g` exists, but we don't have a *formula* for it. \nIn mathematics we don't care about this, and we can use what the\ncomputer scientists call \"classical axioms\" to get `g` from the `\u2203 g` statement.\nFor example, `classical.some` is a function which eats a proof of `\u2203 x : X, <something>`\nand returns a term of type `X` which satisfies the `<something>`. It's really inconvenient\nhaving to keep using `classical.some` though. What is done in Lean's maths library\nis something different. In Lean, a group isomorphism or a homeomorphism\nis defined not to be a bijective function `f : X \u2192 Y` with some properties,\nbut a *pair* of functions `f : X \u2192 Y` and `g : Y \u2192 X` with some properties\n(including the properties of being each other's inverse). In the next\nsheet we'll see the `equiv` structure, which packages up the common\ndata needed in all these definitions; `equiv` is \"constructive bijections\",\nor \"bijections with a given inverse\".\n\n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section09equiv/sheet1introduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541611, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7389999910982522}}
{"text": "theorem t (p q r:Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\niff.intro\n    (assume Hpqr : p \u2227 (q \u2228 r), \n        or.elim (and.elim_right Hpqr)\n            (assume Hq : q,\n                or.intro_left (p \u2227 r) (and.intro (and.elim_left Hpqr) Hq)\n            )\n            (assume Hr : r,\n                or.intro_right (p \u2227 q) (and.intro (and.elim_left Hpqr) Hr)\n            )\n    )\n    (assume Hpqr : (p \u2227 q) \u2228 (p \u2227 r),\n        or.elim Hpqr \n            (assume Hpq : (p \u2227 q),\n                and.intro (and.elim_left Hpq) (or.intro_left r (and.elim_right Hpq))\n            )\n            (assume Hpr : (p \u2227 r),\n                and.intro (and.elim_left Hpr) (or.intro_right q (and.elim_right Hpr))\n            )\n    )\ncheck t  -- t : \u2200 p q r, p \u2227 (q \u2228 r) \u2194 p \u2227 q \u2228 p \u2227 r\n", "meta": {"author": "gagansh7171", "repo": "Automated-Theorem-Proving-Codes", "sha": "88a12ff4fafc6b746412f1ee7086cbf471daae88", "save_path": "github-repos/lean/gagansh7171-Automated-Theorem-Proving-Codes", "path": "github-repos/lean/gagansh7171-Automated-Theorem-Proving-Codes/Automated-Theorem-Proving-Codes-88a12ff4fafc6b746412f1ee7086cbf471daae88/proof-2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809826, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7389504927515855}}
{"text": "/-\nThis file contains the definition of a Boolean literal.\nThe type of the underlying Boolean variable is polymorphic, such\nthat Boolean variables may be represented by nats, strings, etc.\n \nAuthors: Cayden Codel, Jeremy Avigad, Marijn Heule\nCarnegie Mellon University\n-/\n\nimport tactic\n\nuniverse u\n\n-- Represents the type of the variable stored in the literal\nvariable {V : Type*}\n\n/-\nAll propositional formulas are comprised of Boolean literals.\nLiterals are positive or negative forms of the underlying variable type.\n-/\n@[derive decidable_eq]\ninductive literal (V)\n| Pos (v : V) : literal\n| Neg (v : V) : literal\n\n/-\nPropositional formulas may be evaluated under truth assignments.\nAssignments give boolean values to the variables in the formula.\n-/\ndef assignment (V : Type*) := V \u2192 bool\n\nnamespace literal\n\nopen function\n\n/-! # Properties -/\n\ninstance [inhabited V] : inhabited (literal V) := \u27e8Pos (arbitrary V)\u27e9\n\nprotected def repr [has_repr V] : literal V \u2192 string\n| (Pos v) := \"Pos \" ++ (has_repr.repr v)\n| (Neg v) := \"Neg \" ++ (has_repr.repr v)\n\ninstance [has_repr V] : has_repr (literal V) := \u27e8literal.repr\u27e9\ninstance [has_repr V] : has_to_string (literal V) := \u27e8literal.repr\u27e9\n\n/-! # Var -/\n\n/- Extracts the underlying variable of the literal -/\ndef var : literal V \u2192 V\n| (Pos v) := v\n| (Neg v) := v\n\ntheorem var_surjective : surjective (var : literal V \u2192 V) :=\nassume v, exists.intro (Pos v) (by simp only [var])\n\ntheorem ne_of_ne_var {l\u2081 l\u2082 : literal V} : l\u2081.var \u2260 l\u2082.var \u2192 l\u2081 \u2260 l\u2082 :=\nassume h\u2081 h\u2082, h\u2081 (congr_arg var h\u2082)\n\n/-! # Evaluation -/\n\n/-\nWhen provided an assignment, literals may be evaluated against\nthat assignment. Negated literals flip the truth value of the\nunderlying variable when evaluated on the assignment.\n-/\nprotected def eval (\u03c4 : assignment V) : literal V \u2192 bool\n| (Pos v) := \u03c4 v\n| (Neg v) := bnot (\u03c4 v)\n\n/-! # Flip -/\n\n/- Flips the parity of the literal from positive to negative and vice versa -/\nprotected def flip : literal V \u2192 literal V\n| (Pos v) := Neg v\n| (Neg v) := Pos v\n\n@[simp] theorem flip_ne [decidable_eq V] : \u2200 (l : literal V), l.flip \u2260 l\n| (Pos v) := dec_trivial\n| (Neg v) := dec_trivial\n\ntheorem flip_flip : \u2200 (l : literal V), l.flip.flip = l\n| (Pos v) := rfl\n| (Neg v) := rfl\n\ntheorem flip_var_eq : \u2200 (l : literal V), l.flip.var = l.var\n| (Pos v) := rfl\n| (Neg v) := rfl\n\n@[simp] theorem flip_injective : injective (literal.flip : literal V \u2192 literal V) :=\nassume l\u2081 l\u2082 h, (flip_flip l\u2082) \u25b8 ((flip_flip l\u2081) \u25b8 (congr_arg literal.flip h))\n\ntheorem flip_inj {l\u2081 l\u2082 : literal V} : l\u2081.flip = l\u2082.flip \u2194 l\u2081 = l\u2082 :=\nflip_injective.eq_iff\n\n@[simp] theorem flip_surjective : surjective (literal.flip : literal V \u2192 literal V) :=\nassume l, exists.intro l.flip (flip_flip l)\n\n@[simp] theorem flip_bijective : bijective (literal.flip : literal V \u2192 literal V) :=\n\u27e8flip_injective, flip_surjective\u27e9\n\ntheorem exists_flip_eq (l\u2081 : literal V) : \u2203 (l\u2082 : literal V), l\u2082.flip = l\u2081 :=\n\u27e8l\u2081.flip, flip_flip l\u2081\u27e9\n\nsection -- Various lemmas on how var and flip interact\n\nvariables {l\u2081 l\u2082 : literal V}\n\ntheorem var_eq_iff_eq_or_flip_eq : l\u2081.var = l\u2082.var \u2194 l\u2081 = l\u2082 \u2228 l\u2081.flip = l\u2082 :=\nby cases l\u2081; cases l\u2082; simp [literal.flip, var]\n\ntheorem flip_eq_iff_eq_flip : l\u2081.flip = l\u2082 \u2194 l\u2081 = l\u2082.flip :=\n\u27e8\u03bb h, congr_arg literal.flip h \u25b8 (flip_flip l\u2081).symm, \n \u03bb h, (congr_arg literal.flip h).symm \u25b8 flip_flip l\u2082\u27e9\n\ntheorem flip_ne_iff_ne_flip : l\u2081.flip \u2260 l\u2082 \u2194 l\u2081 \u2260 l\u2082.flip :=\n\u27e8\u03bb h\u2081 h\u2082, absurd (flip_eq_iff_eq_flip.mpr h\u2082) h\u2081, \n \u03bb h\u2081 h\u2082, absurd (flip_eq_iff_eq_flip.mp h\u2082) h\u2081\u27e9\n\ntheorem flip_eq_of_ne_of_var_eq : l\u2081 \u2260 l\u2082 \u2192 l\u2081.var = l\u2082.var \u2192 l\u2081.flip = l\u2082 :=\n\u03bb h\u2081 h\u2082, or.elim (var_eq_iff_eq_or_flip_eq.mp h\u2082) (\u03bb h, absurd h h\u2081) id\n\ntheorem eq_of_flip_ne_of_var_eq : l\u2081.flip \u2260 l\u2082 \u2192 l\u2081.var = l\u2082.var \u2192 l\u2081 = l\u2082 :=\n\u03bb h\u2081 h\u2082, or.elim (var_eq_iff_eq_or_flip_eq.mp h\u2082) id (\u03bb h, absurd h h\u2081)\n\nend /- end section -/\n\n/-! # Flip evaluation -/\n\n-- When a literal is flipped, its truth assignment is negated\ntheorem eval_flip (\u03c4 : assignment V) (l : literal V) : \n  l.flip.eval \u03c4 = bnot (l.eval \u03c4) :=\nby cases l; simp only [literal.flip, literal.eval, bnot_bnot]\n\n-- A slight modification where the negation is the flipped literal\ntheorem eval_flip2 (\u03c4 : assignment V) (l : literal V) :\n  l.eval \u03c4 = bnot (l.flip.eval \u03c4) :=\nby cases l; simp only [literal.flip, literal.eval, bnot_bnot]\n\ntheorem eval_flip_of_eval {\u03c4 : assignment V} {l : literal V} {b : bool} :\n  l.eval \u03c4 = b \u2192 l.flip.eval \u03c4 = bnot b :=\nassume h, congr_arg bnot h \u25b8 eval_flip \u03c4 l\n\ntheorem eval_of_eval_flip {\u03c4 : assignment V} {l : literal V} {b : bool} :\n  literal.eval \u03c4 l.flip = b \u2192 literal.eval \u03c4 l = bnot b :=\nassume h, congr_arg bnot h \u25b8 eval_flip2 \u03c4 l\n\n/-! # Positives and negatives -/\n\nprotected def is_pos : literal V \u2192 Prop\n| (Pos _) := true\n| (Neg _) := false\n\nprotected def is_neg : literal V \u2192 Prop\n| (Pos _) := false\n| (Neg _) := true\n\n-- Must be protected because of decidable.is_true\nprotected def is_true (\u03c4 : assignment V) (l : literal V) : Prop := \nliteral.eval \u03c4 l = tt\n\nprotected def is_false (\u03c4 : assignment V) (l : literal V) : Prop :=\nliteral.eval \u03c4 l = ff\n\ninstance : decidable_pred (literal.is_pos : literal V \u2192 Prop)\n| (Pos v) := decidable.true\n| (Neg v) := decidable.false\n\ninstance : decidable_pred (literal.is_neg : literal V \u2192 Prop)\n| (Pos v) := decidable.false\n| (Neg v) := decidable.true\n\ninstance (\u03c4 : assignment V) : decidable_pred (literal.is_true \u03c4) :=\n\u03bb l, by cases h : l.eval \u03c4; { unfold literal.is_true, rw h, exact eq.decidable _ _ }\n\ninstance (\u03c4 : assignment V) : decidable_pred (literal.is_false \u03c4) :=\n\u03bb l, by cases h : l.eval \u03c4; { unfold literal.is_false, rw h, exact eq.decidable _ _ }\n\n-- A literal can never be both positive and negative\ntheorem is_pos_ne_is_neg (l : literal V) :\n  literal.is_pos l \u2260 literal.is_neg l :=\nby cases l; simp [literal.is_pos, literal.is_neg]\n\n-- A literal can never be both true and false under the same assignment\n-- NOTE: A strange proof, can probably be simplified\ntheorem is_true_ne_is_false [inhabited V] (\u03c4 : assignment V) :\n  (literal.is_true \u03c4) \u2260 (literal.is_false \u03c4) :=\nbegin\n  intro h,\n  have v := arbitrary (literal V),\n  have := congr_arg (\u03bb (f : literal V \u2192 Prop), f v) h,\n  cases he : literal.eval \u03c4 v;\n  { simp [literal.is_true, literal.is_false, he] at this, assumption }\nend\n\nend literal", "meta": {"author": "chasenorman", "repo": "verified-encodings-social-choice", "sha": "72f88c5a31ce30df5a04a99f726244c327b9a6f6", "save_path": "github-repos/lean/chasenorman-verified-encodings-social-choice", "path": "github-repos/lean/chasenorman-verified-encodings-social-choice/verified-encodings-social-choice-72f88c5a31ce30df5a04a99f726244c327b9a6f6/src/cnf/literal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7389347072819613}}
{"text": "/-\nCopyright (c) 2020 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n\n! This file was ported from Lean 3 source module group_theory.subgroup.zpowers\n! leanprover-community/mathlib commit f93c11933efbc3c2f0299e47b8ff83e9b539cbf6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.GroupTheory.Subgroup.Basic\n\n/-!\n# Subgroups generated by an element\n\n## Tags\nsubgroup, subgroups\n\n-/\n\n\nvariable {G : Type _} [Group G]\n\nvariable {A : Type _} [AddGroup A]\n\nvariable {N : Type _} [Group N]\n\nnamespace Subgroup\n\n/-- The subgroup generated by an element. -/\ndef zpowers (g : G) : Subgroup G :=\n  Subgroup.copy (zpowersHom G g).range (Set.range ((\u00b7 ^ \u00b7) g : \u2124 \u2192 G)) rfl\n#align subgroup.zpowers Subgroup.zpowers\n\ntheorem mem_zpowers (g : G) : g \u2208 zpowers g :=\n  \u27e81, zpow_one _\u27e9\n#align subgroup.mem_zpowers Subgroup.mem_zpowers\n\ntheorem zpowers_eq_closure (g : G) : zpowers g = closure {g} := by\n  ext\n  exact mem_closure_singleton.symm\n#align subgroup.zpowers_eq_closure Subgroup.zpowers_eq_closure\n\ntheorem range_zpowersHom (g : G) : (zpowersHom G g).range = zpowers g :=\n  rfl\n#align subgroup.range_zpowers_hom Subgroup.range_zpowersHom\n\ntheorem zpowers_subset {a : G} {K : Subgroup G} (h : a \u2208 K) : zpowers a \u2264 K := fun x hx =>\n  match x, hx with\n  | _, \u27e8i, rfl\u27e9 => K.zpow_mem h i\n#align subgroup.zpowers_subset Subgroup.zpowers_subset\n\ntheorem mem_zpowers_iff {g h : G} : h \u2208 zpowers g \u2194 \u2203 k : \u2124, g ^ k = h :=\n  Iff.rfl\n#align subgroup.mem_zpowers_iff Subgroup.mem_zpowers_iff\n\ntheorem zpow_mem_zpowers (g : G) (k : \u2124) : g ^ k \u2208 zpowers g :=\n  mem_zpowers_iff.mpr \u27e8k, rfl\u27e9\n#align subgroup.zpow_mem_zpowers Subgroup.zpow_mem_zpowers\n\ntheorem npow_mem_zpowers (g : G) (k : \u2115) : g ^ k \u2208 zpowers g :=\n  zpow_ofNat g k \u25b8 zpow_mem_zpowers g k\n#align subgroup.npow_mem_zpowers Subgroup.npow_mem_zpowers\n\ntheorem forall_zpowers {x : G} {p : zpowers x \u2192 Prop} : (\u2200 g, p g) \u2194 \u2200 m : \u2124, p \u27e8x ^ m, m, rfl\u27e9 :=\n  Set.forall_subtype_range_iff\n#align subgroup.forall_zpowers Subgroup.forall_zpowers\n\ntheorem exists_zpowers {x : G} {p : zpowers x \u2192 Prop} : (\u2203 g, p g) \u2194 \u2203 m : \u2124, p \u27e8x ^ m, m, rfl\u27e9 :=\n  Set.exists_subtype_range_iff\n#align subgroup.exists_zpowers Subgroup.exists_zpowers\n\ntheorem forall_mem_zpowers {x : G} {p : G \u2192 Prop} : (\u2200 g \u2208 zpowers x, p g) \u2194 \u2200 m : \u2124, p (x ^ m) :=\n  Set.forall_range_iff\n#align subgroup.forall_mem_zpowers Subgroup.forall_mem_zpowers\n\ntheorem exists_mem_zpowers {x : G} {p : G \u2192 Prop} : (\u2203 g \u2208 zpowers x, p g) \u2194 \u2203 m : \u2124, p (x ^ m) :=\n  Set.exists_range_iff\n#align subgroup.exists_mem_zpowers Subgroup.exists_mem_zpowers\n\ninstance (a : G) : Countable (zpowers a) :=\n  ((zpowersHom G a).rangeRestrict_surjective.comp Multiplicative.ofAdd.surjective).countable\n\nend Subgroup\n\nnamespace AddSubgroup\n\n/-- The subgroup generated by an element. -/\ndef zmultiples (a : A) : AddSubgroup A :=\n  AddSubgroup.copy (zmultiplesHom A a).range (Set.range ((\u00b7 \u2022 a) : \u2124 \u2192 A)) rfl\n#align add_subgroup.zmultiples AddSubgroup.zmultiples\n\n@[simp]\ntheorem range_zmultiplesHom (a : A) : (zmultiplesHom A a).range = zmultiples a :=\n  rfl\n#align add_subgroup.range_zmultiples_hom AddSubgroup.range_zmultiplesHom\n\nattribute [to_additive existing AddSubgroup.zmultiples] Subgroup.zpowers\n\nattribute [to_additive (attr := simp) AddSubgroup.mem_zmultiples] Subgroup.mem_zpowers\n#align add_subgroup.mem_zmultiples AddSubgroup.mem_zmultiples\n\nattribute [to_additive AddSubgroup.zmultiples_eq_closure] Subgroup.zpowers_eq_closure\n#align add_subgroup.zmultiples_eq_closure AddSubgroup.zmultiples_eq_closure\n\nattribute [to_additive existing (attr := simp) AddSubgroup.range_zmultiplesHom]\n  Subgroup.range_zpowersHom\n\nattribute [to_additive AddSubgroup.zmultiples_subset] Subgroup.zpowers_subset\n#align add_subgroup.zmultiples_subset AddSubgroup.zmultiples_subset\n\nattribute [to_additive AddSubgroup.mem_zmultiples_iff] Subgroup.mem_zpowers_iff\n#align add_subgroup.mem_zmultiples_iff AddSubgroup.mem_zmultiples_iff\n\nattribute [to_additive (attr := simp) AddSubgroup.zsmul_mem_zmultiples] Subgroup.zpow_mem_zpowers\n#align add_subgroup.zsmul_mem_zmultiples AddSubgroup.zsmul_mem_zmultiples\n\nattribute [to_additive (attr := simp) AddSubgroup.nsmul_mem_zmultiples] Subgroup.npow_mem_zpowers\n#align add_subgroup.nsmul_mem_zmultiples AddSubgroup.nsmul_mem_zmultiples\n\n--Porting note: increasing simp priority. Better lemma than `Subtype.forall`\nattribute [to_additive (attr := simp 1100) AddSubgroup.forall_zmultiples] Subgroup.forall_zpowers\n#align add_subgroup.forall_zmultiples AddSubgroup.forall_zmultiples\n\nattribute [to_additive AddSubgroup.forall_mem_zmultiples] Subgroup.forall_mem_zpowers\n#align add_subgroup.forall_mem_zmultiples AddSubgroup.forall_mem_zmultiples\n\n--Porting note: increasing simp priority. Better lemma than `Subtype.exists`\nattribute [to_additive (attr := simp 1100) AddSubgroup.exists_zmultiples] Subgroup.exists_zpowers\n#align add_subgroup.exists_zmultiples AddSubgroup.exists_zmultiples\n\nattribute [to_additive AddSubgroup.exists_mem_zmultiples] Subgroup.exists_mem_zpowers\n#align add_subgroup.exists_mem_zmultiples AddSubgroup.exists_mem_zmultiples\n\ninstance (a : A) : Countable (zmultiples a) :=\n  (zmultiplesHom A a).rangeRestrict_surjective.countable\n\nsection Ring\n\nvariable {R : Type _} [Ring R] (r : R) (k : \u2124)\n\n@[simp]\ntheorem int_cast_mul_mem_zmultiples : \u2191(k : \u2124) * r \u2208 zmultiples r := by\n  simpa only [\u2190 zsmul_eq_mul] using zsmul_mem_zmultiples r k\n#align add_subgroup.int_cast_mul_mem_zmultiples AddSubgroup.int_cast_mul_mem_zmultiples\n\n@[simp]\ntheorem int_cast_mem_zmultiples_one : \u2191(k : \u2124) \u2208 zmultiples (1 : R) :=\n  mem_zmultiples_iff.mp \u27e8k, by simp\u27e9\n#align add_subgroup.int_cast_mem_zmultiples_one AddSubgroup.int_cast_mem_zmultiples_one\n\nend Ring\n\nend AddSubgroup\n\n@[to_additive (attr := simp) map_zmultiples]\ntheorem MonoidHom.map_zpowers (f : G \u2192* N) (x : G) :\n    (Subgroup.zpowers x).map f = Subgroup.zpowers (f x) := by\n  rw [Subgroup.zpowers_eq_closure, Subgroup.zpowers_eq_closure, f.map_closure, Set.image_singleton]\n#align monoid_hom.map_zpowers MonoidHom.map_zpowers\n#align add_monoid_hom.map_zmultiples AddMonoidHom.map_zmultiples\n\ntheorem Int.mem_zmultiples_iff {a b : \u2124} : b \u2208 AddSubgroup.zmultiples a \u2194 a \u2223 b :=\n  exists_congr fun k => by rw [mul_comm, eq_comm, \u2190 smul_eq_mul]\n#align int.mem_zmultiples_iff Int.mem_zmultiples_iff\n\ntheorem ofMul_image_zpowers_eq_zmultiples_ofMul {x : G} :\n    Additive.ofMul '' (Subgroup.zpowers x : Set G) = AddSubgroup.zmultiples (Additive.ofMul x) := by\n  ext y\n  constructor\n  \u00b7 rintro \u27e8z, \u27e8m, hm\u27e9, hz2\u27e9\n    use m\n    simp only at *\n    rwa [\u2190 ofMul_zpow, hm]\n  \u00b7 rintro \u27e8n, hn\u27e9\n    refine' \u27e8x ^ n, \u27e8n, rfl\u27e9, _\u27e9\n    rwa [ofMul_zpow]\n#align of_mul_image_zpowers_eq_zmultiples_of_mul ofMul_image_zpowers_eq_zmultiples_ofMul\n\ntheorem ofAdd_image_zmultiples_eq_zpowers_ofAdd {x : A} :\n    Multiplicative.ofAdd '' (AddSubgroup.zmultiples x : Set A) =\n      Subgroup.zpowers (Multiplicative.ofAdd x) := by\n  symm\n  rw [Equiv.eq_image_iff_symm_image_eq]\n  exact ofMul_image_zpowers_eq_zmultiples_ofMul\n#align of_add_image_zmultiples_eq_zpowers_of_add ofAdd_image_zmultiples_eq_zpowers_ofAdd\n\nnamespace Subgroup\n\n@[to_additive zmultiples_isCommutative]\ninstance zpowers_isCommutative (g : G) : (zpowers g).IsCommutative :=\n  \u27e8\u27e8fun \u27e8_, _, h\u2081\u27e9 \u27e8_, _, h\u2082\u27e9 => by\n      rw [Subtype.ext_iff, coe_mul, coe_mul, Subtype.coe_mk, Subtype.coe_mk, \u2190 h\u2081, \u2190 h\u2082,\n        zpow_mul_comm]\u27e9\u27e9\n#align subgroup.zpowers_is_commutative Subgroup.zpowers_isCommutative\n#align add_subgroup.zmultiples_is_commutative AddSubgroup.zmultiples_isCommutative\n\n@[to_additive (attr := simp) zmultiples_le]\ntheorem zpowers_le {g : G} {H : Subgroup G} : zpowers g \u2264 H \u2194 g \u2208 H := by\n  rw [zpowers_eq_closure, closure_le, Set.singleton_subset_iff, SetLike.mem_coe]\n#align subgroup.zpowers_le Subgroup.zpowers_le\n#align add_subgroup.zmultiples_le AddSubgroup.zmultiples_le\n\n@[to_additive (attr := simp) zmultiples_eq_bot]\ntheorem zpowers_eq_bot {g : G} : zpowers g = \u22a5 \u2194 g = 1 := by rw [eq_bot_iff, zpowers_le, mem_bot]\n#align subgroup.zpowers_eq_bot Subgroup.zpowers_eq_bot\n#align add_subgroup.zmultiples_eq_bot AddSubgroup.zmultiples_eq_bot\n\n@[to_additive (attr := simp) zmultiples_zero_eq_bot]\ntheorem zpowers_one_eq_bot : Subgroup.zpowers (1 : G) = \u22a5 :=\n  Subgroup.zpowers_eq_bot.mpr rfl\n#align subgroup.zpowers_one_eq_bot Subgroup.zpowers_one_eq_bot\n#align add_subgroup.zmultiples_zero_eq_bot AddSubgroup.zmultiples_zero_eq_bot\n\n@[to_additive]\ntheorem centralizer_closure (S : Set G) :\n    (closure S).centralizer = \u2a05 g \u2208 S, (zpowers g).centralizer :=\n  le_antisymm\n      (le_inf\u1d62 fun _ => le_inf\u1d62 fun hg => centralizer_le <| zpowers_le.2 <| subset_closure hg) <|\n    le_centralizer_iff.1 <|\n      (closure_le _).2 fun g =>\n        SetLike.mem_coe.2 \u2218 zpowers_le.1 \u2218 le_centralizer_iff.1 \u2218 inf\u1d62_le_of_le g \u2218 inf\u1d62_le _\n#align subgroup.centralizer_closure Subgroup.centralizer_closure\n#align add_subgroup.centralizer_closure AddSubgroup.centralizer_closure\n\n@[to_additive]\ntheorem center_eq_inf\u1d62 (S : Set G) (hS : closure S = \u22a4) :\n    center G = \u2a05 g \u2208 S, centralizer (zpowers g) := by\n  rw [\u2190 centralizer_top, \u2190 hS, centralizer_closure]\n#align subgroup.center_eq_infi Subgroup.center_eq_inf\u1d62\n#align add_subgroup.center_eq_infi AddSubgroup.center_eq_inf\u1d62\n\n@[to_additive]\ntheorem center_eq_infi' (S : Set G) (hS : closure S = \u22a4) :\n    center G = \u2a05 g : S, centralizer (zpowers (g : G)) :=\n  by rw [center_eq_inf\u1d62 S hS, \u2190 inf\u1d62_subtype'']\n#align subgroup.center_eq_infi' Subgroup.center_eq_infi'\n#align add_subgroup.center_eq_infi' AddSubgroup.center_eq_infi'\n\nend Subgroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/Subgroup/Zpowers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064586998, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.7389346998440246}}
{"text": "/-\n  Package the definition of an open cover of an open set.\n\n  Author: Ramon Fernandez Mir\n-/\n\nimport topology.basic\nimport topology.opens\nimport sheaves.opens\n\nuniverses u\n\nopen topological_space lattice\n\nsection covering\n\nvariables {\u03b1 : Type u} [topological_space \u03b1]\n\n-- Open cover.\n\nstructure covering (U : opens \u03b1) :=\n{\u03b3    : Type u}\n(Uis  : \u03b3 \u2192 opens \u03b1)\n(Hcov : \u22c3 Uis = U)\n\nvariable (\u03b1)\n\ndef covering.univ := covering (@opens.univ \u03b1 _)\n\nvariable {\u03b1}\n\n-- If \u22c3 Ui = U then for all i, Ui \u2286 U.\n\nlemma subset_covering {U : opens \u03b1} {OC : covering U} :\n\u2200 i, OC.Uis i \u2286 U :=\n\u03bb i x Hx, OC.Hcov \u25b8 opens_supr_mem OC.Uis i x Hx\n\n-- Make covering from standard definition. Used for instance in compactness.\n\ndef opens.from_sets {A : Type*} [topological_space A]\n: set (set A) \u2192 set (opens A) := \u03bb C, { x | x.1 \u2208 C }\n\nlemma opens.from_sets.eq {A : Type*} [topological_space A]\n(S : set (set A)) (HS : \u2200 (t : set A), t \u2208 S \u2192 is_open t)\n: subtype.val '' (opens.from_sets S) = S :=\nset.ext $ \u03bb x, \u27e8\n  \u03bb \u27e8x', Hx', Hval\u27e9, Hval \u25b8 Hx',\n  \u03bb Hx, by simp [HS x Hx]; by exact Hx\u27e9\n\n@[reducible] def covering.from_cover {A : Type*} [topological_space A]\n(U     : opens A)\n(C     : set (set A))\n(HC    : \u2200 (t : set A), t \u2208 C \u2192 is_open t)\n(Hcov : U.1 = \u22c3\u2080 C)\n: covering U :=\n{ \u03b3 := opens.from_sets C,\n  Uis := \u03bb x, x,\n  Hcov :=\n    begin\n      apply subtype.ext.2,\n      rw Hcov,\n      apply set.ext,\n      intros x,\n      split,\n      { intros Hx,\n        rcases Hx with \u27e8U, HU, HxU\u27e9,\n        existsi U,\n        simp at HU,\n        rcases HU with \u27e8OU, HU\u27e9,\n        rw \u2190opens.from_sets.eq C HC,\n        split,\n        { simp [HU],\n          use OU, },\n        { exact HxU, } },\n      { intros Hx,\n        rcases Hx with \u27e8U, HU, HxU\u27e9,\n        use U,\n        simp,\n        use (HC U HU),\n        { simp [opens.from_sets],\n          exact HU, },\n        { exact HxU, }  }\n    end, }\n\nlemma covering.from_cover.Uis {A : Type*} [topological_space A]\n(U     : opens A)\n(C     : set (set A))\n(HC    : \u2200 (t : set A), t \u2208 C \u2192 is_open t)\n(Hcov : U.1 = \u22c3\u2080 C)\n: \u2200 i, ((covering.from_cover U C HC Hcov).Uis i).1 \u2208 C :=\nbegin\n  intros i,\n  simp [covering.from_cover] at *,\n  cases i with i Hi,\n  simp,\n  simp [opens.from_sets] at *,\n  exact Hi,\nend\n\nend covering\n", "meta": {"author": "leanprover-community", "repo": "lean-perfectoid-spaces", "sha": "95a6520ce578b30a80b4c36e36ab2d559a842690", "save_path": "github-repos/lean/leanprover-community-lean-perfectoid-spaces", "path": "github-repos/lean/leanprover-community-lean-perfectoid-spaces/lean-perfectoid-spaces-95a6520ce578b30a80b4c36e36ab2d559a842690/src/sheaves/covering.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7389346995119129}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Johannes H\u00f6lzl, Mario Carneiro\nPorted by: Kevin Buzzard, Johan Commelin, Siddhartha Gadgil, Anand Rao\n-/\n\nimport Mathlib.Data.Nat.Size\n\n/-!\n\nThese are lemmas that were proved in the process of porting `Data.Nat.Sqrt`.\n\n-/\n\nnamespace Nat\n\nsection Misc\n\n-- porting note: Miscellaneous lemmas that should be integrated with `Mathlib` in the future\n\nprotected lemma mul_le_of_le_div (k x y : \u2115) (h : x \u2264 y / k) : x * k \u2264 y := by\n  by_cases hk : k = 0\n  case pos => rw [hk, mul_zero]; exact zero_le _\n  case neg => rwa [\u2190 le_div_iff_mul_le (pos_iff_ne_zero.2 hk)]\n\nprotected lemma div_mul_div_le (a b c d : \u2115) :\n    (a / b) * (c / d) \u2264 (a * c) / (b * d) := by\n  by_cases hb : b = 0\n  case pos => simp [hb]\n  by_cases hd : d = 0\n  case pos => simp [hd]\n  have hbd : b * d \u2260 0 := mul_ne_zero hb hd\n  rw [le_div_iff_mul_le (Nat.pos_of_ne_zero hbd)]\n  transitivity ((a / b) * b) * ((c / d) * d)\n  \u00b7 apply le_of_eq; simp only [mul_assoc, mul_left_comm]\n  \u00b7 apply Nat.mul_le_mul <;> apply div_mul_le_self\n\nprivate lemma iter_fp_bound (n k : \u2115) :\n    let iter_next (n guess : \u2115) := (guess + n / guess) / 2;\n    sqrt.iter n k \u2264 iter_next n (sqrt.iter n k) := by\n  intro iter_next\n  unfold sqrt.iter\n  by_cases h : (k + n / k) / 2 < k\n  case pos => simp [if_pos h]; exact iter_fp_bound _ _\n  case neg => simp [if_neg h]; exact Nat.le_of_not_lt h\n\nprivate lemma AM_GM : {a b : \u2115} \u2192 (4 * a * b \u2264 (a + b) * (a + b))\n  | 0, _ => by rw [mul_zero, zero_mul]; exact zero_le _\n  | _, 0 => by rw [mul_zero]; exact zero_le _\n  | a + 1, b + 1 => by\n    have ih := add_le_add_right (@AM_GM a b) 4\n    simp only [mul_add, add_mul, show (4 : \u2115) = 1 + 1 + 1 + 1 from rfl, one_mul, mul_one] at ih \u22a2\n    simp only [add_assoc, add_left_comm, add_le_add_iff_left] at ih \u22a2\n    exact ih\n\nend Misc\n\nsection Std\n\n-- porting note: These two lemmas seem like they belong to `Std.Data.Nat.Basic`.\n\nlemma sqrt.iter_sq_le (n guess : \u2115) : sqrt.iter n guess * sqrt.iter n guess \u2264 n := by\n  unfold sqrt.iter\n  let next := (guess + n / guess) / 2\n  by_cases h : next < guess\n  case pos => simpa only [dif_pos h] using sqrt.iter_sq_le n next\n  case neg =>\n    simp only [dif_neg h]\n    apply Nat.mul_le_of_le_div\n    apply le_of_add_le_add_left (a := guess)\n    rw [\u2190 mul_two, \u2190 le_div_iff_mul_le]\n    \u00b7 exact le_of_not_lt h\n    \u00b7 exact zero_lt_two\n\nlemma sqrt.lt_iter_succ_sq (n guess : \u2115) (hn : n < (guess + 1) * (guess + 1)) :\n    n < (sqrt.iter n guess + 1) * (sqrt.iter n guess + 1) := by\n  unfold sqrt.iter\n  -- m was `next`\n  let m := (guess + n / guess) / 2\n  by_cases h : m < guess\n  case pos =>\n    suffices : n < (m + 1) * (m + 1)\n    \u00b7 simpa only [dif_pos h] using sqrt.lt_iter_succ_sq n m this\n    refine lt_of_mul_lt_mul_left ?_ (4 * (guess * guess)).zero_le\n    apply lt_of_le_of_lt AM_GM\n    rw [show (4 : \u2115) = 2 * 2 from rfl]\n    rw [mul_mul_mul_comm 2, mul_mul_mul_comm (2 * guess)]\n    refine mul_self_lt_mul_self (?_ : _ < _ * succ (_ / 2))\n    rw [\u2190 add_div_right _ (by decide), mul_comm 2, mul_assoc,\n      show guess + n / guess + 2 = (guess + n / guess + 1) + 1 from rfl]\n    have aux_lemma {a : \u2115} : a \u2264 2 * ((a + 1) / 2) := by\n      rw [mul_comm]\n      exact (add_le_add_iff_right 2).1 $ succ_le_of_lt $ @lt_div_mul_add (a + 1) 2 zero_lt_two\n    refine lt_of_lt_of_le ?_ (act_rel_act_of_rel _ aux_lemma)\n    rw [add_assoc, mul_add]\n    exact add_lt_add_left (lt_mul_div_succ _ (lt_of_le_of_lt (Nat.zero_le m) h)) _\n  case neg =>\n    simpa only [dif_neg h] using hn\n\nend Std\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/ForSqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7389251355442132}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n-/\nimport algebra.ordered_monoid\n\n/-!\n# Ordered groups\n\nThis file develops the basics of ordered groups.\n\n## Implementation details\n\nUnfortunately, the number of `'` appended to lemmas in this file\nmay differ between the multiplicative and the additive version of a lemma.\nThe reason is that we did not want to change existing names in the library.\n-/\n\nset_option old_structure_cmd true\n\nuniverse u\nvariable {\u03b1 : Type u}\n\n/-- An ordered additive commutative group is an additive commutative group\nwith a partial order in which addition is strictly monotone. -/\n@[protect_proj, ancestor add_comm_group partial_order]\nclass ordered_add_comm_group (\u03b1 : Type u) extends add_comm_group \u03b1, partial_order \u03b1 :=\n(add_le_add_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n\n/-- An ordered commutative group is an commutative group\nwith a partial order in which multiplication is strictly monotone. -/\n@[protect_proj, ancestor comm_group partial_order]\nclass ordered_comm_group (\u03b1 : Type u) extends comm_group \u03b1, partial_order \u03b1 :=\n(mul_le_mul_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\n\nattribute [to_additive] ordered_comm_group\n\n/--The units of an ordered commutative monoid form an ordered commutative group. -/\n@[to_additive]\ninstance units.ordered_comm_group [ordered_comm_monoid \u03b1] : ordered_comm_group (units \u03b1) :=\n{ mul_le_mul_left := \u03bb a b h c, mul_le_mul_left' h _,\n  .. units.partial_order,\n  .. (infer_instance : comm_group (units \u03b1)) }\n\nsection ordered_comm_group\nvariables [ordered_comm_group \u03b1] {a b c d : \u03b1}\n\n@[to_additive ordered_add_comm_group.add_lt_add_left]\nlemma ordered_comm_group.mul_lt_mul_left' (a b : \u03b1) (h : a < b) (c : \u03b1) : c * a < c * b :=\nbegin\n  rw lt_iff_le_not_le at h \u22a2,\n  split,\n  { apply ordered_comm_group.mul_le_mul_left _ _ h.1 },\n  { intro w,\n    replace w : c\u207b\u00b9 * (c * b) \u2264 c\u207b\u00b9 * (c * a) := ordered_comm_group.mul_le_mul_left _ _ w _,\n    simp only [mul_one, mul_comm, mul_left_inv, mul_left_comm] at w,\n    exact h.2 w },\nend\n\n@[to_additive ordered_add_comm_group.le_of_add_le_add_left]\nlemma ordered_comm_group.le_of_mul_le_mul_left (h : a * b \u2264 a * c) : b \u2264 c :=\nhave a\u207b\u00b9 * (a * b) \u2264 a\u207b\u00b9 * (a * c), from ordered_comm_group.mul_le_mul_left _ _ h _,\nbegin simp [inv_mul_cancel_left] at this, assumption end\n\n@[to_additive]\nlemma ordered_comm_group.lt_of_mul_lt_mul_left (h : a * b < a * c) : b < c :=\nhave a\u207b\u00b9 * (a * b) < a\u207b\u00b9 * (a * c), from ordered_comm_group.mul_lt_mul_left' _ _ h _,\nbegin simp [inv_mul_cancel_left] at this, assumption end\n\n@[priority 100, to_additive]    -- see Note [lower instance priority]\ninstance ordered_comm_group.to_ordered_cancel_comm_monoid (\u03b1 : Type u)\n  [s : ordered_comm_group \u03b1] :\n  ordered_cancel_comm_monoid \u03b1 :=\n{ mul_left_cancel       := @mul_left_cancel \u03b1 _,\n  le_of_mul_le_mul_left := @ordered_comm_group.le_of_mul_le_mul_left \u03b1 _,\n  ..s }\n\n@[priority 100, to_additive]\ninstance ordered_comm_group.has_exists_mul_of_le (\u03b1 : Type u)\n  [ordered_comm_group \u03b1] :\n  has_exists_mul_of_le \u03b1 :=\n\u27e8\u03bb a b hab, \u27e8b * a\u207b\u00b9, (mul_inv_cancel_comm_assoc a b).symm\u27e9\u27e9\n\n@[to_additive neg_le_neg]\nlemma inv_le_inv' (h : a \u2264 b) : b\u207b\u00b9 \u2264 a\u207b\u00b9 :=\nhave 1 \u2264 a\u207b\u00b9 * b,           from mul_left_inv a \u25b8 mul_le_mul_left' h _,\nhave 1 * b\u207b\u00b9 \u2264 a\u207b\u00b9 * b * b\u207b\u00b9, from mul_le_mul_right' this _,\nby rwa [mul_inv_cancel_right, one_mul] at this\n\n@[to_additive]\nlemma le_of_inv_le_inv (h : b\u207b\u00b9 \u2264 a\u207b\u00b9) : a \u2264 b :=\nsuffices (a\u207b\u00b9)\u207b\u00b9 \u2264 (b\u207b\u00b9)\u207b\u00b9, from\n  begin simp [inv_inv] at this, assumption end,\ninv_le_inv' h\n\n@[to_additive]\nlemma one_le_of_inv_le_one (h : a\u207b\u00b9 \u2264 1) : 1 \u2264 a :=\nhave a\u207b\u00b9 \u2264 1\u207b\u00b9, by rwa one_inv,\nle_of_inv_le_inv this\n\n@[to_additive]\nlemma inv_le_one_of_one_le (h : 1 \u2264 a) : a\u207b\u00b9 \u2264 1 :=\nhave a\u207b\u00b9 \u2264 1\u207b\u00b9, from inv_le_inv' h,\nby rwa one_inv at this\n\n@[to_additive nonpos_of_neg_nonneg]\nlemma le_one_of_one_le_inv (h : 1 \u2264 a\u207b\u00b9) : a \u2264 1 :=\nhave 1\u207b\u00b9 \u2264 a\u207b\u00b9, by rwa one_inv,\nle_of_inv_le_inv this\n\n@[to_additive neg_nonneg_of_nonpos]\nlemma one_le_inv_of_le_one (h : a \u2264 1) : 1 \u2264 a\u207b\u00b9 :=\nhave 1\u207b\u00b9 \u2264 a\u207b\u00b9, from inv_le_inv' h,\nby rwa one_inv at this\n\n@[to_additive neg_lt_neg]\nlemma inv_lt_inv' (h : a < b) : b\u207b\u00b9 < a\u207b\u00b9 :=\nhave 1 < a\u207b\u00b9 * b, from mul_left_inv a \u25b8 mul_lt_mul_left' h (a\u207b\u00b9),\nhave 1 * b\u207b\u00b9 < a\u207b\u00b9 * b * b\u207b\u00b9, from mul_lt_mul_right' this (b\u207b\u00b9),\nby rwa [mul_inv_cancel_right, one_mul] at this\n\n@[to_additive]\nlemma lt_of_inv_lt_inv (h : b\u207b\u00b9 < a\u207b\u00b9) : a < b :=\ninv_inv a \u25b8 inv_inv b \u25b8 inv_lt_inv' h\n\n@[to_additive]\nlemma one_lt_of_inv_inv (h : a\u207b\u00b9 < 1) : 1 < a :=\nhave a\u207b\u00b9 < 1\u207b\u00b9, by rwa one_inv,\nlt_of_inv_lt_inv this\n\n@[to_additive]\nlemma inv_inv_of_one_lt (h : 1 < a) : a\u207b\u00b9 < 1 :=\nhave a\u207b\u00b9 < 1\u207b\u00b9, from inv_lt_inv' h,\nby rwa one_inv at this\n\n@[to_additive neg_of_neg_pos]\nlemma inv_of_one_lt_inv (h : 1 < a\u207b\u00b9) : a < 1 :=\nhave 1\u207b\u00b9 < a\u207b\u00b9, by rwa one_inv,\nlt_of_inv_lt_inv this\n\n@[to_additive neg_pos_of_neg]\nlemma one_lt_inv_of_inv (h : a < 1) : 1 < a\u207b\u00b9 :=\nhave 1\u207b\u00b9 < a\u207b\u00b9, from inv_lt_inv' h,\nby rwa one_inv at this\n\n@[to_additive]\nlemma le_inv_of_le_inv (h : a \u2264 b\u207b\u00b9) : b \u2264 a\u207b\u00b9 :=\nbegin\n  have h := inv_le_inv' h,\n  rwa inv_inv at h\nend\n\n@[to_additive]\nlemma inv_le_of_inv_le (h : a\u207b\u00b9 \u2264 b) : b\u207b\u00b9 \u2264 a :=\nbegin\n  have h := inv_le_inv' h,\n  rwa inv_inv at h\nend\n\n@[to_additive]\nlemma lt_inv_of_lt_inv (h : a < b\u207b\u00b9) : b < a\u207b\u00b9 :=\nbegin\n  have h := inv_lt_inv' h,\n  rwa inv_inv at h\nend\n\n@[to_additive]\nlemma inv_lt_of_inv_lt (h : a\u207b\u00b9 < b) : b\u207b\u00b9 < a :=\nbegin\n  have h := inv_lt_inv' h,\n  rwa inv_inv at h\nend\n\n@[to_additive]\nlemma mul_le_of_le_inv_mul (h : b \u2264 a\u207b\u00b9 * c) : a * b \u2264 c :=\nbegin\n  have h := mul_le_mul_left' h a,\n  rwa mul_inv_cancel_left at h\nend\n\n@[to_additive]\nlemma le_inv_mul_of_mul_le (h : a * b \u2264 c) : b \u2264 a\u207b\u00b9 * c :=\nbegin\n  have h := mul_le_mul_left' h a\u207b\u00b9,\n  rwa inv_mul_cancel_left at h\nend\n\n@[to_additive]\nlemma le_mul_of_inv_mul_le (h : b\u207b\u00b9 * a \u2264 c) : a \u2264 b * c :=\nbegin\n  have h := mul_le_mul_left' h b,\n  rwa mul_inv_cancel_left at h\nend\n\n@[to_additive]\nlemma inv_mul_le_of_le_mul (h : a \u2264 b * c) : b\u207b\u00b9 * a \u2264 c :=\nbegin\n  have h := mul_le_mul_left' h b\u207b\u00b9,\n  rwa inv_mul_cancel_left at h\nend\n\n@[to_additive]\nlemma le_mul_of_inv_mul_le_left (h : b\u207b\u00b9 * a \u2264 c) : a \u2264 b * c :=\nle_mul_of_inv_mul_le h\n\n@[to_additive]\nlemma inv_mul_le_left_of_le_mul (h : a \u2264 b * c) : b\u207b\u00b9 * a \u2264 c :=\ninv_mul_le_of_le_mul h\n\n@[to_additive]\nlemma le_mul_of_inv_mul_le_right (h : c\u207b\u00b9 * a \u2264 b) : a \u2264 b * c :=\nby { rw mul_comm, exact le_mul_of_inv_mul_le h }\n\n@[to_additive]\nlemma inv_mul_le_right_of_le_mul (h : a \u2264 b * c) : c\u207b\u00b9 * a \u2264 b :=\nby { rw mul_comm at h, apply inv_mul_le_left_of_le_mul h }\n\n@[to_additive]\nlemma mul_lt_of_lt_inv_mul (h : b < a\u207b\u00b9 * c) : a * b < c :=\nbegin\n  have h := mul_lt_mul_left' h a,\n  rwa mul_inv_cancel_left at h\nend\n\n@[to_additive]\nlemma lt_inv_mul_of_mul_lt (h : a * b < c) : b < a\u207b\u00b9 * c :=\nbegin\n  have h := mul_lt_mul_left' h (a\u207b\u00b9),\n  rwa inv_mul_cancel_left at h\nend\n\n@[to_additive]\nlemma lt_mul_of_inv_mul_lt (h : b\u207b\u00b9 * a < c) : a < b * c :=\nbegin\n  have h := mul_lt_mul_left' h b,\n  rwa mul_inv_cancel_left at h\nend\n\n@[to_additive]\nlemma inv_mul_lt_of_lt_mul (h : a < b * c) : b\u207b\u00b9 * a < c :=\nbegin\n  have h := mul_lt_mul_left' h (b\u207b\u00b9),\n  rwa inv_mul_cancel_left at h\nend\n\n@[to_additive]\nlemma lt_mul_of_inv_mul_lt_left (h : b\u207b\u00b9 * a < c) : a < b * c :=\nlt_mul_of_inv_mul_lt h\n\n@[to_additive]\nlemma inv_mul_lt_left_of_lt_mul (h : a < b * c) : b\u207b\u00b9 * a < c :=\ninv_mul_lt_of_lt_mul h\n\n@[to_additive]\nlemma lt_mul_of_inv_mul_lt_right (h : c\u207b\u00b9 * a < b) : a < b * c :=\nby { rw mul_comm, exact lt_mul_of_inv_mul_lt h }\n\n@[to_additive]\nlemma inv_mul_lt_right_of_lt_mul (h : a < b * c) : c\u207b\u00b9 * a < b :=\nby { rw mul_comm at h, exact inv_mul_lt_of_lt_mul h }\n\n@[simp, to_additive]\nlemma inv_lt_one_iff_one_lt : a\u207b\u00b9 < 1 \u2194 1 < a :=\n\u27e8 one_lt_of_inv_inv, inv_inv_of_one_lt \u27e9\n\n@[simp, to_additive]\nlemma inv_le_inv_iff : a\u207b\u00b9 \u2264 b\u207b\u00b9 \u2194 b \u2264 a :=\nhave a * b * a\u207b\u00b9 \u2264 a * b * b\u207b\u00b9 \u2194 a\u207b\u00b9 \u2264 b\u207b\u00b9, from mul_le_mul_iff_left _,\nby { rw [mul_inv_cancel_right, mul_comm a, mul_inv_cancel_right] at this, rw [this] }\n\n@[to_additive neg_le]\nlemma inv_le' : a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a :=\nhave a\u207b\u00b9 \u2264 (b\u207b\u00b9)\u207b\u00b9 \u2194 b\u207b\u00b9 \u2264 a, from inv_le_inv_iff,\nby rwa inv_inv at this\n\n@[to_additive le_neg]\nlemma le_inv' : a \u2264 b\u207b\u00b9 \u2194 b \u2264 a\u207b\u00b9 :=\nhave (a\u207b\u00b9)\u207b\u00b9 \u2264 b\u207b\u00b9 \u2194 b \u2264 a\u207b\u00b9, from inv_le_inv_iff,\nby rwa inv_inv at this\n\n@[to_additive neg_le_iff_add_nonneg]\nlemma inv_le_iff_one_le_mul : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 b * a :=\n(mul_le_mul_iff_right a).symm.trans $ by rw inv_mul_self\n\n@[to_additive neg_le_iff_add_nonneg']\nlemma inv_le_iff_one_le_mul' : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 a * b :=\n(mul_le_mul_iff_left a).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma inv_lt_iff_one_lt_mul : a\u207b\u00b9 < b \u2194 1 < b * a :=\n(mul_lt_mul_iff_right a).symm.trans $ by rw inv_mul_self\n\n@[to_additive]\nlemma inv_lt_iff_one_lt_mul' : a\u207b\u00b9 < b \u2194 1 < a * b :=\n(mul_lt_mul_iff_left a).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma le_inv_iff_mul_le_one : a \u2264 b\u207b\u00b9 \u2194 a * b \u2264 1 :=\n(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_self\n\n@[to_additive]\nlemma le_inv_iff_mul_le_one' : a \u2264 b\u207b\u00b9 \u2194 b * a \u2264 1 :=\n(mul_le_mul_iff_left b).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma lt_inv_iff_mul_lt_one : a < b\u207b\u00b9 \u2194 a * b < 1 :=\n(mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_self\n\n@[to_additive]\nlemma lt_inv_iff_mul_lt_one' : a < b\u207b\u00b9 \u2194 b * a < 1 :=\n(mul_lt_mul_iff_left b).symm.trans $ by rw mul_inv_self\n\n@[simp, to_additive neg_nonpos]\nlemma inv_le_one' : a\u207b\u00b9 \u2264 1 \u2194 1 \u2264 a :=\nhave a\u207b\u00b9 \u2264 1\u207b\u00b9 \u2194 1 \u2264 a, from inv_le_inv_iff,\nby rwa one_inv at this\n\n@[simp, to_additive neg_nonneg]\nlemma one_le_inv' : 1 \u2264 a\u207b\u00b9 \u2194 a \u2264 1 :=\nhave 1\u207b\u00b9 \u2264 a\u207b\u00b9 \u2194 a \u2264 1, from inv_le_inv_iff,\nby rwa one_inv at this\n\n@[to_additive]\nlemma inv_le_self (h : 1 \u2264 a) : a\u207b\u00b9 \u2264 a :=\nle_trans (inv_le_one'.2 h) h\n\n@[to_additive]\nlemma self_le_inv (h : a \u2264 1) : a \u2264 a\u207b\u00b9 :=\nle_trans h (one_le_inv'.2 h)\n\n@[simp, to_additive]\nlemma inv_lt_inv_iff : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nhave a * b * a\u207b\u00b9 < a * b * b\u207b\u00b9 \u2194 a\u207b\u00b9 < b\u207b\u00b9, from mul_lt_mul_iff_left _,\nby { rw [mul_inv_cancel_right, mul_comm a, mul_inv_cancel_right] at this, rw [this] }\n\n@[to_additive neg_lt_zero]\nlemma inv_lt_one' : a\u207b\u00b9 < 1 \u2194 1 < a :=\nhave a\u207b\u00b9 < 1\u207b\u00b9 \u2194 1 < a, from inv_lt_inv_iff,\nby rwa one_inv at this\n\n@[to_additive neg_pos]\nlemma one_lt_inv' : 1 < a\u207b\u00b9 \u2194 a < 1 :=\nhave 1\u207b\u00b9 < a\u207b\u00b9 \u2194 a < 1, from inv_lt_inv_iff,\nby rwa one_inv at this\n\n@[to_additive neg_lt]\nlemma inv_lt' : a\u207b\u00b9 < b \u2194 b\u207b\u00b9 < a :=\nhave a\u207b\u00b9 < (b\u207b\u00b9)\u207b\u00b9 \u2194 b\u207b\u00b9 < a, from inv_lt_inv_iff,\nby rwa inv_inv at this\n\n@[to_additive lt_neg]\nlemma lt_inv' : a < b\u207b\u00b9 \u2194 b < a\u207b\u00b9 :=\nhave (a\u207b\u00b9)\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a\u207b\u00b9, from inv_lt_inv_iff,\nby rwa inv_inv at this\n\n@[to_additive]\nlemma inv_lt_self (h : 1 < a) : a\u207b\u00b9 < a :=\n(inv_lt_one'.2 h).trans h\n\n@[to_additive]\nlemma le_inv_mul_iff_mul_le : b \u2264 a\u207b\u00b9 * c \u2194 a * b \u2264 c :=\nhave a\u207b\u00b9 * (a * b) \u2264 a\u207b\u00b9 * c \u2194 a * b \u2264 c, from mul_le_mul_iff_left _,\nby rwa inv_mul_cancel_left at this\n\n@[simp, to_additive]\nlemma inv_mul_le_iff_le_mul : b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 b * c :=\nhave b\u207b\u00b9 * a \u2264 b\u207b\u00b9 * (b * c) \u2194 a \u2264 b * c, from mul_le_mul_iff_left _,\nby rwa inv_mul_cancel_left at this\n\n@[to_additive]\nlemma mul_inv_le_iff_le_mul : a * c\u207b\u00b9 \u2264 b \u2194 a \u2264 b * c :=\nby rw [mul_comm a, mul_comm b, inv_mul_le_iff_le_mul]\n\n@[simp, to_additive]\nlemma mul_inv_le_iff_le_mul' : a * b\u207b\u00b9 \u2264 c \u2194 a \u2264 b * c :=\nby rw [\u2190 inv_mul_le_iff_le_mul, mul_comm]\n\n@[to_additive]\nlemma inv_mul_le_iff_le_mul' : c\u207b\u00b9 * a \u2264 b \u2194 a \u2264 b * c :=\nby rw [inv_mul_le_iff_le_mul, mul_comm]\n\n@[simp, to_additive]\nlemma lt_inv_mul_iff_mul_lt : b < a\u207b\u00b9 * c \u2194 a * b < c :=\nhave a\u207b\u00b9 * (a * b) < a\u207b\u00b9 * c \u2194 a * b < c, from mul_lt_mul_iff_left _,\nby rwa inv_mul_cancel_left at this\n\n@[simp, to_additive]\nlemma inv_mul_lt_iff_lt_mul : b\u207b\u00b9 * a < c \u2194 a < b * c :=\nhave b\u207b\u00b9 * a < b\u207b\u00b9 * (b * c) \u2194 a < b * c, from mul_lt_mul_iff_left _,\nby rwa inv_mul_cancel_left at this\n\n@[to_additive]\nlemma inv_mul_lt_iff_lt_mul_right : c\u207b\u00b9 * a < b \u2194 a < b * c :=\nby rw [inv_mul_lt_iff_lt_mul, mul_comm]\n\n@[to_additive add_neg_le_add_neg_iff]\nlemma div_le_div_iff' : a * b\u207b\u00b9 \u2264 c * d\u207b\u00b9 \u2194 a * d \u2264 c * b :=\nbegin\n  split ; intro h,\n  have := mul_le_mul_right' (mul_le_mul_right' h b) d,\n  rwa [inv_mul_cancel_right, mul_assoc _ _ b, mul_comm _ b, \u2190 mul_assoc, inv_mul_cancel_right]\n    at this,\n  have := mul_le_mul_right' (mul_le_mul_right' h d\u207b\u00b9) b\u207b\u00b9,\n  rwa [mul_inv_cancel_right, _root_.mul_assoc, _root_.mul_comm d\u207b\u00b9 b\u207b\u00b9, \u2190 mul_assoc,\n    mul_inv_cancel_right] at this,\nend\n\n@[simp, to_additive] lemma div_le_self_iff (a : \u03b1) {b : \u03b1} : a / b \u2264 a \u2194 1 \u2264 b :=\nby simp [div_eq_mul_inv]\n\n@[simp, to_additive] lemma div_lt_self_iff (a : \u03b1) {b : \u03b1} : a / b < a \u2194 1 < b :=\nby simp [div_eq_mul_inv]\n\n/-- Pullback an `ordered_comm_group` under an injective map. -/\n@[to_additive function.injective.ordered_add_comm_group\n\"Pullback an `ordered_add_comm_group` under an injective map.\"]\ndef function.injective.ordered_comm_group {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2] [has_inv \u03b2] [has_div \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9)\n  (div : \u2200 x y, f (x / y) = f x / f y) :\n  ordered_comm_group \u03b2 :=\n{ ..partial_order.lift f hf,\n  ..hf.ordered_comm_monoid f one mul,\n  ..hf.comm_group f one mul inv div }\n\nend ordered_comm_group\n\nsection ordered_add_comm_group\nvariables [ordered_add_comm_group \u03b1] {a b c d : \u03b1}\n\nlemma sub_le_sub (hab : a \u2264 b) (hcd : c \u2264 d) : a - d \u2264 b - c :=\nby simpa only [sub_eq_add_neg] using add_le_add hab (neg_le_neg hcd)\n\nlemma sub_lt_sub (hab : a < b) (hcd : c < d) : a - d < b - c :=\nby simpa only [sub_eq_add_neg] using add_lt_add hab (neg_lt_neg hcd)\n\nalias sub_le_self_iff \u2194 _ sub_le_self\n\nalias sub_lt_self_iff \u2194 _ sub_lt_self\n\nlemma sub_le_sub_iff : a - b \u2264 c - d \u2194 a + d \u2264 c + b :=\nby simpa only [sub_eq_add_neg] using add_neg_le_add_neg_iff\n\n@[simp]\nlemma sub_le_sub_iff_left (a : \u03b1) {b c : \u03b1} : a - b \u2264 a - c \u2194 c \u2264 b :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, add_le_add_iff_left, neg_le_neg_iff]\n\nlemma sub_le_sub_left (h : a \u2264 b) (c : \u03b1) : c - b \u2264 c - a :=\n(sub_le_sub_iff_left c).2 h\n\n@[simp]\nlemma sub_le_sub_iff_right (c : \u03b1) : a - c \u2264 b - c \u2194 a \u2264 b :=\nby simpa only [sub_eq_add_neg] using add_le_add_iff_right _\n\nlemma sub_le_sub_right (h : a \u2264 b) (c : \u03b1) : a - c \u2264 b - c :=\n(sub_le_sub_iff_right c).2 h\n\n@[simp]\nlemma sub_lt_sub_iff_left (a : \u03b1) {b c : \u03b1} : a - b < a - c \u2194 c < b :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, add_lt_add_iff_left, neg_lt_neg_iff]\n\nlemma sub_lt_sub_left (h : a < b) (c : \u03b1) : c - b < c - a :=\n(sub_lt_sub_iff_left c).2 h\n\n@[simp]\nlemma sub_lt_sub_iff_right (c : \u03b1) : a - c < b - c \u2194 a < b :=\nby simpa only [sub_eq_add_neg] using add_lt_add_iff_right _\n\nlemma sub_lt_sub_right (h : a < b) (c : \u03b1) : a - c < b - c :=\n(sub_lt_sub_iff_right c).2 h\n\n@[simp] lemma sub_nonneg : 0 \u2264 a - b \u2194 b \u2264 a :=\nby rw [\u2190 sub_self a, sub_le_sub_iff_left]\n\nalias sub_nonneg \u2194 le_of_sub_nonneg sub_nonneg_of_le\n\n@[simp] lemma sub_nonpos : a - b \u2264 0 \u2194 a \u2264 b :=\nby rw [\u2190 sub_self b,  sub_le_sub_iff_right]\n\nalias sub_nonpos \u2194 le_of_sub_nonpos sub_nonpos_of_le\n\n@[simp] lemma sub_pos : 0 < a - b \u2194 b < a :=\nby rw [\u2190 sub_self a, sub_lt_sub_iff_left]\n\nalias sub_pos \u2194 lt_of_sub_pos sub_pos_of_lt\n\n@[simp] lemma sub_lt_zero : a - b < 0 \u2194 a < b :=\nby rw [\u2190 sub_self b, sub_lt_sub_iff_right]\n\nalias sub_lt_zero \u2194 lt_of_sub_neg sub_neg_of_lt\n\nlemma le_sub_iff_add_le' : b \u2264 c - a \u2194 a + b \u2264 c :=\nby rw [sub_eq_add_neg, add_comm, le_neg_add_iff_add_le]\n\nlemma le_sub_iff_add_le : a \u2264 c - b \u2194 a + b \u2264 c :=\nby rw [le_sub_iff_add_le', add_comm]\n\nalias le_sub_iff_add_le \u2194 add_le_of_le_sub_right le_sub_right_of_add_le\n\nlemma sub_le_iff_le_add' : a - b \u2264 c \u2194 a \u2264 b + c :=\nby rw [sub_eq_add_neg, add_comm, neg_add_le_iff_le_add]\n\nalias le_sub_iff_add_le' \u2194 add_le_of_le_sub_left le_sub_left_of_add_le\n\nlemma sub_le_iff_le_add : a - c \u2264 b \u2194 a \u2264 b + c :=\nby rw [sub_le_iff_le_add', add_comm]\n\n@[simp] lemma neg_le_sub_iff_le_add : -b \u2264 a - c \u2194 c \u2264 a + b :=\nle_sub_iff_add_le.trans neg_add_le_iff_le_add'\n\nlemma neg_le_sub_iff_le_add' : -a \u2264 b - c \u2194 c \u2264 a + b :=\nby rw [neg_le_sub_iff_le_add, add_comm]\n\nlemma sub_le : a - b \u2264 c \u2194 a - c \u2264 b :=\nsub_le_iff_le_add'.trans sub_le_iff_le_add.symm\n\ntheorem le_sub : a \u2264 b - c \u2194 c \u2264 b - a :=\nle_sub_iff_add_le'.trans le_sub_iff_add_le.symm\n\nlemma lt_sub_iff_add_lt' : b < c - a \u2194 a + b < c :=\nby rw [sub_eq_add_neg, add_comm, lt_neg_add_iff_add_lt]\n\nalias lt_sub_iff_add_lt' \u2194 add_lt_of_lt_sub_left lt_sub_left_of_add_lt\n\nlemma lt_sub_iff_add_lt : a < c - b \u2194 a + b < c :=\nby rw [lt_sub_iff_add_lt', add_comm]\n\nalias lt_sub_iff_add_lt \u2194 add_lt_of_lt_sub_right lt_sub_right_of_add_lt\n\nlemma sub_lt_iff_lt_add' : a - b < c \u2194 a < b + c :=\nby rw [sub_eq_add_neg, add_comm, neg_add_lt_iff_lt_add]\n\nalias sub_lt_iff_lt_add' \u2194 lt_add_of_sub_left_lt sub_left_lt_of_lt_add\n\nlemma sub_lt_iff_lt_add : a - c < b \u2194 a < b + c :=\nby rw [sub_lt_iff_lt_add', add_comm]\n\nalias sub_lt_iff_lt_add \u2194 lt_add_of_sub_right_lt sub_right_lt_of_lt_add\n\n@[simp] lemma neg_lt_sub_iff_lt_add : -b < a - c \u2194 c < a + b :=\nlt_sub_iff_add_lt.trans neg_add_lt_iff_lt_add_right\n\nlemma neg_lt_sub_iff_lt_add' : -a < b - c \u2194 c < a + b :=\nby rw [neg_lt_sub_iff_lt_add, add_comm]\n\nlemma sub_lt : a - b < c \u2194 a - c < b :=\nsub_lt_iff_lt_add'.trans sub_lt_iff_lt_add.symm\n\ntheorem lt_sub : a < b - c \u2194 c < b - a :=\nlt_sub_iff_add_lt'.trans lt_sub_iff_add_lt.symm\n\nend ordered_add_comm_group\n\n/-!\n\n### Linearly ordered commutative groups\n\n-/\n\n/-- A linearly ordered additive commutative group is an\nadditive commutative group with a linear order in which\naddition is monotone. -/\n@[protect_proj, ancestor add_comm_group linear_order]\nclass linear_ordered_add_comm_group (\u03b1 : Type u) extends add_comm_group \u03b1, linear_order \u03b1 :=\n(add_le_add_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n\n/-- A linearly ordered commutative group is a\ncommutative group with a linear order in which\nmultiplication is monotone. -/\n@[protect_proj, ancestor comm_group linear_order, to_additive]\nclass linear_ordered_comm_group (\u03b1 : Type u) extends comm_group \u03b1, linear_order \u03b1 :=\n(mul_le_mul_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\n\nsection linear_ordered_comm_group\nvariables [linear_ordered_comm_group \u03b1] {a b c : \u03b1}\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_ordered_comm_group : ordered_comm_group \u03b1 :=\n{ ..\u2039linear_ordered_comm_group \u03b1\u203a }\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_linear_ordered_cancel_comm_monoid :\n  linear_ordered_cancel_comm_monoid \u03b1 :=\n{ le_of_mul_le_mul_left := \u03bb x y z, le_of_mul_le_mul_left',\n  mul_left_cancel := \u03bb x y z, mul_left_cancel,\n  ..\u2039linear_ordered_comm_group \u03b1\u203a }\n\n/-- Pullback a `linear_ordered_comm_group` under an injective map. -/\n@[to_additive function.injective.linear_ordered_add_comm_group\n\"Pullback a `linear_ordered_add_comm_group` under an injective map.\"]\ndef function.injective.linear_ordered_comm_group {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2] [has_inv \u03b2] [has_div \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9)\n  (div : \u2200 x y, f (x / y) = f x / f y)  :\n  linear_ordered_comm_group \u03b2 :=\n{ ..linear_order.lift f hf,\n  ..hf.ordered_comm_group f one mul inv div }\n\n@[to_additive linear_ordered_add_comm_group.add_lt_add_left]\nlemma linear_ordered_comm_group.mul_lt_mul_left'\n  (a b : \u03b1) (h : a < b) (c : \u03b1) : c * a < c * b :=\nordered_comm_group.mul_lt_mul_left' a b h c\n\n@[to_additive min_neg_neg]\nlemma min_inv_inv' (a b : \u03b1) : min (a\u207b\u00b9) (b\u207b\u00b9) = (max a b)\u207b\u00b9 :=\neq.symm $ @monotone.map_max \u03b1 (order_dual \u03b1) _ _ has_inv.inv a b $ \u03bb a b, inv_le_inv'\n\n@[to_additive max_neg_neg]\nlemma max_inv_inv' (a b : \u03b1) : max (a\u207b\u00b9) (b\u207b\u00b9) = (min a b)\u207b\u00b9 :=\neq.symm $ @monotone.map_min \u03b1 (order_dual \u03b1) _ _ has_inv.inv a b $ \u03bb a b, inv_le_inv'\n\n@[to_additive min_sub_sub_right]\nlemma min_div_div_right' (a b c : \u03b1) : min (a / c) (b / c) = min a b / c :=\nby simpa only [div_eq_mul_inv] using min_mul_mul_right a b (c\u207b\u00b9)\n\n@[to_additive max_sub_sub_right]\nlemma max_div_div_right' (a b c : \u03b1) : max (a / c) (b / c) = max a b / c :=\nby simpa only [div_eq_mul_inv] using max_mul_mul_right a b (c\u207b\u00b9)\n\n@[to_additive min_sub_sub_left]\nlemma min_div_div_left' (a b c : \u03b1) : min (a / b) (a / c) = a / max b c :=\nby simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv']\n\n@[to_additive max_sub_sub_left]\nlemma max_div_div_left' (a b c : \u03b1) : max (a / b) (a / c) = a / min b c :=\nby simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']\n\n@[to_additive max_zero_sub_eq_self]\nlemma max_one_div_eq_self' (a : \u03b1) : max a 1 / max (a\u207b\u00b9) 1 = a :=\nbegin\n  rcases le_total a 1,\n  { rw [max_eq_right h, max_eq_left, one_div, inv_inv], { rwa [le_inv', one_inv] } },\n  { rw [max_eq_left, max_eq_right, div_eq_mul_inv, one_inv, mul_one],\n    { rwa [inv_le', one_inv] }, exact h }\nend\n\n@[to_additive eq_zero_of_neg_eq]\nlemma eq_one_of_inv_eq' (h : a\u207b\u00b9 = a) : a = 1 :=\nmatch lt_trichotomy a 1 with\n| or.inl h\u2081 :=\n  have 1 < a, from h \u25b8 one_lt_inv_of_inv h\u2081,\n  absurd h\u2081 this.asymm\n| or.inr (or.inl h\u2081) := h\u2081\n| or.inr (or.inr h\u2081) :=\n  have a < 1, from h \u25b8 inv_inv_of_one_lt h\u2081,\n  absurd h\u2081 this.asymm\nend\n\n@[to_additive exists_zero_lt]\nlemma exists_one_lt' [nontrivial \u03b1] : \u2203 (a:\u03b1), 1 < a :=\nbegin\n  obtain \u27e8y, hy\u27e9 := exists_ne (1 : \u03b1),\n  cases hy.lt_or_lt,\n  { exact \u27e8y\u207b\u00b9, one_lt_inv'.mpr h\u27e9 },\n  { exact \u27e8y, h\u27e9 }\nend\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_no_top_order [nontrivial \u03b1] :\n  no_top_order \u03b1 :=\n\u27e8 begin\n    obtain \u27e8y, hy\u27e9 : \u2203 (a:\u03b1), 1 < a := exists_one_lt',\n    exact \u03bb a, \u27e8a * y, lt_mul_of_one_lt_right' a hy\u27e9\n  end \u27e9\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_no_bot_order [nontrivial \u03b1] : no_bot_order \u03b1 :=\n\u27e8 begin\n    obtain \u27e8y, hy\u27e9 : \u2203 (a:\u03b1), 1 < a := exists_one_lt',\n    exact \u03bb a, \u27e8a / y, (div_lt_self_iff a).mpr hy\u27e9\n  end \u27e9\n\nend linear_ordered_comm_group\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1] {a b c : \u03b1}\n\n@[simp]\nlemma sub_le_sub_flip : a - b \u2264 b - a \u2194 a \u2264 b :=\nbegin\n  rw [sub_le_iff_le_add, sub_add_eq_add_sub, le_sub_iff_add_le],\n  split,\n  { intro h,\n    by_contra H,\n    rw not_le at H,\n    apply not_lt.2 h,\n    exact add_lt_add H H, },\n  { intro h,\n    exact add_le_add h h, }\nend\n\nlemma le_of_forall_pos_le_add [densely_ordered \u03b1] (h : \u2200 \u03b5 : \u03b1, 0 < \u03b5 \u2192 a \u2264 b + \u03b5) : a \u2264 b :=\nle_of_forall_le_of_dense $ \u03bb c hc,\ncalc a \u2264 b + (c - b) : h _ (sub_pos_of_lt hc)\n   ... = c           : add_sub_cancel'_right _ _\n\nlemma le_of_forall_pos_lt_add (h : \u2200 \u03b5 : \u03b1, 0 < \u03b5 \u2192 a < b + \u03b5) : a \u2264 b :=\nle_of_not_lt $ \u03bb h\u2081, by simpa using h _ (sub_pos_of_lt h\u2081)\n\n/-- `abs a` is the absolute value of `a`. -/\ndef abs (a : \u03b1) : \u03b1 := max a (-a)\n\nlemma abs_of_nonneg (h : 0 \u2264 a) : abs a = a :=\nmax_eq_left $ (neg_nonpos.2 h).trans h\n\nlemma abs_of_pos (h : 0 < a) : abs a = a :=\nabs_of_nonneg h.le\n\nlemma abs_of_nonpos (h : a \u2264 0) : abs a = -a :=\nmax_eq_right $ h.trans (neg_nonneg.2 h)\n\nlemma abs_of_neg (h : a < 0) : abs a = -a :=\nabs_of_nonpos h.le\n\n@[simp] lemma abs_zero : abs 0 = (0:\u03b1) :=\nabs_of_nonneg le_rfl\n\n@[simp] lemma abs_neg (a : \u03b1) : abs (-a) = abs a :=\nbegin unfold abs, rw [max_comm, neg_neg] end\n\n@[simp] lemma abs_pos : 0 < abs a \u2194 a \u2260 0 :=\nbegin\n  rcases lt_trichotomy a 0 with (ha|rfl|ha),\n  { simp [abs_of_neg ha, neg_pos, ha.ne, ha] },\n  { simp },\n  { simp [abs_of_pos ha, ha, ha.ne.symm] }\nend\n\nlemma abs_pos_of_pos (h : 0 < a) : 0 < abs a := abs_pos.2 h.ne.symm\n\nlemma abs_pos_of_neg (h : a < 0) : 0 < abs a := abs_pos.2 h.ne\n\nlemma abs_sub (a b : \u03b1) : abs (a - b) = abs (b - a) :=\nby rw [\u2190 neg_sub, abs_neg]\n\nlemma abs_le' : abs a \u2264 b \u2194 a \u2264 b \u2227 -a \u2264 b := max_le_iff\n\nlemma abs_le : abs a \u2264 b \u2194 - b \u2264 a \u2227 a \u2264 b :=\nby rw [abs_le', and.comm, neg_le]\n\nlemma neg_le_of_abs_le (h : abs a \u2264 b) : -b \u2264 a := (abs_le.mp h).1\n\nlemma le_of_abs_le (h : abs a \u2264 b) : a \u2264 b := (abs_le.mp h).2\n\nlemma le_abs : a \u2264 abs b \u2194 a \u2264 b \u2228 a \u2264 -b := le_max_iff\n\nlemma le_abs_self (a : \u03b1) : a \u2264 abs a := le_max_left _ _\n\nlemma neg_le_abs_self (a : \u03b1) : -a \u2264 abs a := le_max_right _ _\n\nlemma abs_nonneg (a : \u03b1) : 0 \u2264 abs a :=\n(le_total 0 a).elim (\u03bb h, h.trans (le_abs_self a)) (\u03bb h, (neg_nonneg.2 h).trans $ neg_le_abs_self a)\n\n@[simp] lemma abs_abs (a : \u03b1) : abs (abs a) = abs a :=\nabs_of_nonneg $ abs_nonneg a\n\n@[simp] lemma abs_eq_zero : abs a = 0 \u2194 a = 0 :=\nnot_iff_not.1 $ ne_comm.trans $ (abs_nonneg a).lt_iff_ne.symm.trans abs_pos\n\n@[simp] lemma abs_nonpos_iff {a : \u03b1} : abs a \u2264 0 \u2194 a = 0 :=\n(abs_nonneg a).le_iff_eq.trans abs_eq_zero\n\nlemma abs_lt : abs a < b \u2194 - b < a \u2227 a < b :=\nmax_lt_iff.trans $ and.comm.trans $ by rw [neg_lt]\n\nlemma neg_lt_of_abs_lt (h : abs a < b) : -b < a := (abs_lt.mp h).1\n\nlemma lt_of_abs_lt (h : abs a < b) : a < b := (abs_lt.mp h).2\n\nlemma lt_abs : a < abs b \u2194 a < b \u2228 a < -b := lt_max_iff\n\nlemma max_sub_min_eq_abs' (a b : \u03b1) : max a b - min a b = abs (a - b) :=\nbegin\n  cases le_total a b with ab ba,\n  { rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub], rwa sub_nonpos },\n  { rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg], rwa sub_nonneg }\nend\n\nlemma max_sub_min_eq_abs (a b : \u03b1) : max a b - min a b = abs (b - a) :=\nby { rw [abs_sub], exact max_sub_min_eq_abs' _ _ }\n\nlemma abs_add (a b : \u03b1) : abs (a + b) \u2264 abs a + abs b :=\nabs_le.2 \u27e8(neg_add (abs a) (abs b)).symm \u25b8\n  add_le_add (neg_le.2 $ neg_le_abs_self _) (neg_le.2 $ neg_le_abs_self _),\n  add_le_add (le_abs_self _) (le_abs_self _)\u27e9\n\nlemma abs_sub_le_iff : abs (a - b) \u2264 c \u2194 a - b \u2264 c \u2227 b - a \u2264 c :=\nby rw [abs_le, neg_le_sub_iff_le_add, @sub_le_iff_le_add' _ _ b, and_comm]\n\nlemma abs_sub_lt_iff : abs (a - b) < c \u2194 a - b < c \u2227 b - a < c :=\nby rw [abs_lt, neg_lt_sub_iff_lt_add, @sub_lt_iff_lt_add' _ _ b, and_comm]\n\nlemma sub_le_of_abs_sub_le_left (h : abs (a - b) \u2264 c) : b - c \u2264 a :=\nsub_le.1 $ (abs_sub_le_iff.1 h).2\n\nlemma sub_le_of_abs_sub_le_right (h : abs (a - b) \u2264 c) : a - c \u2264 b :=\nsub_le_of_abs_sub_le_left (abs_sub a b \u25b8 h)\n\nlemma sub_lt_of_abs_sub_lt_left (h : abs (a - b) < c) : b - c < a :=\nsub_lt.1 $ (abs_sub_lt_iff.1 h).2\n\nlemma sub_lt_of_abs_sub_lt_right (h : abs (a - b) < c) : a - c < b :=\nsub_lt_of_abs_sub_lt_left (abs_sub a b \u25b8 h)\n\nlemma abs_sub_abs_le_abs_sub (a b : \u03b1) : abs a - abs b \u2264 abs (a - b) :=\nsub_le_iff_le_add.2 $\ncalc abs a = abs (a - b + b)     : by rw [sub_add_cancel]\n       ... \u2264 abs (a - b) + abs b : abs_add _ _\n\nlemma abs_abs_sub_abs_le_abs_sub (a b : \u03b1) : abs (abs a - abs b) \u2264 abs (a - b) :=\nabs_sub_le_iff.2 \u27e8abs_sub_abs_le_abs_sub _ _, by rw abs_sub; apply abs_sub_abs_le_abs_sub\u27e9\n\nlemma abs_eq (hb : 0 \u2264 b) : abs a = b \u2194 a = b \u2228 a = -b :=\niff.intro\n  begin\n    cases le_total a 0 with a_nonpos a_nonneg,\n    { rw [abs_of_nonpos a_nonpos, neg_eq_iff_neg_eq, eq_comm], exact or.inr },\n    { rw [abs_of_nonneg a_nonneg, eq_comm], exact or.inl }\n  end\n  (by intro h; cases h; subst h; try { rw abs_neg }; exact abs_of_nonneg hb)\n\nlemma abs_le_max_abs_abs (hab : a \u2264 b)  (hbc : b \u2264 c) : abs b \u2264 max (abs a) (abs c) :=\nabs_le'.2\n  \u27e8by simp [hbc.trans (le_abs_self c)],\n   by simp [(neg_le_neg hab).trans (neg_le_abs_self a)]\u27e9\n\ntheorem abs_le_abs (h\u2080 : a \u2264 b) (h\u2081 : -a \u2264 b) : abs a \u2264 abs b :=\n(abs_le'.2 \u27e8h\u2080, h\u2081\u27e9).trans (le_abs_self b)\n\nlemma abs_max_sub_max_le_abs (a b c : \u03b1) : abs (max a c - max b c) \u2264 abs (a - b) :=\nbegin\n  simp_rw [abs_le, le_sub_iff_add_le, sub_le_iff_le_add, \u2190 max_add_add_left],\n  split; apply max_le_max; simp only [\u2190 le_sub_iff_add_le, \u2190 sub_le_iff_le_add, sub_self, neg_le,\n    neg_le_abs_self, neg_zero, abs_nonneg, le_abs_self]\nend\n\nlemma eq_of_abs_sub_eq_zero {a b : \u03b1} (h : abs (a - b) = 0) : a = b :=\nsub_eq_zero.1 $ abs_eq_zero.1 h\n\nlemma abs_by_cases (P : \u03b1 \u2192 Prop) {a : \u03b1} (h1 : P a) (h2 : P (-a)) : P (abs a) :=\nsup_ind _ _ h1 h2\n\nlemma abs_sub_le (a b c : \u03b1) : abs (a - c) \u2264 abs (a - b) + abs (b - c) :=\ncalc\n    abs (a - c) = abs (a - b + (b - c))     : by rw [sub_add_sub_cancel]\n            ... \u2264 abs (a - b) + abs (b - c) : abs_add _ _\n\nlemma abs_add_three (a b c : \u03b1) : abs (a + b + c) \u2264 abs a + abs b + abs c :=\n(abs_add _ _).trans (add_le_add_right (abs_add _ _) _)\n\nlemma dist_bdd_within_interval {a b lb ub : \u03b1} (hal : lb \u2264 a) (hau : a \u2264 ub)\n      (hbl : lb \u2264 b) (hbu : b \u2264 ub) : abs (a - b) \u2264 ub - lb :=\nabs_sub_le_iff.2 \u27e8sub_le_sub hau hbl, sub_le_sub hbu hal\u27e9\n\nlemma eq_of_abs_sub_nonpos (h : abs (a - b) \u2264 0) : a = b :=\neq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b)))\n\nend linear_ordered_add_comm_group\n\n/-- This is not so much a new structure as a construction mechanism\n  for ordered groups, by specifying only the \"positive cone\" of the group. -/\nclass nonneg_add_comm_group (\u03b1 : Type*) extends add_comm_group \u03b1 :=\n(nonneg : \u03b1 \u2192 Prop)\n(pos : \u03b1 \u2192 Prop := \u03bb a, nonneg a \u2227 \u00ac nonneg (neg a))\n(pos_iff : \u2200 a, pos a \u2194 nonneg a \u2227 \u00ac nonneg (-a) . order_laws_tac)\n(zero_nonneg : nonneg 0)\n(add_nonneg : \u2200 {a b}, nonneg a \u2192 nonneg b \u2192 nonneg (a + b))\n(nonneg_antisymm : \u2200 {a}, nonneg a \u2192 nonneg (-a) \u2192 a = 0)\n\nnamespace nonneg_add_comm_group\nvariable [s : nonneg_add_comm_group \u03b1]\ninclude s\n\n@[reducible, priority 100] -- see Note [lower instance priority]\ninstance to_ordered_add_comm_group : ordered_add_comm_group \u03b1 :=\n{ le := \u03bb a b, nonneg (b - a),\n  lt := \u03bb a b, pos (b - a),\n  lt_iff_le_not_le := \u03bb a b, by simp; rw [pos_iff]; simp,\n  le_refl := \u03bb a, by simp [zero_nonneg],\n  le_trans := \u03bb a b c nab nbc, by simp [-sub_eq_add_neg];\n    rw \u2190 sub_add_sub_cancel; exact add_nonneg nbc nab,\n  le_antisymm := \u03bb a b nab nba, eq_of_sub_eq_zero $\n    nonneg_antisymm nba (by rw neg_sub; exact nab),\n  add_le_add_left := \u03bb a b nab c, by simpa [(\u2264), preorder.le] using nab,\n  ..s }\n\ntheorem nonneg_def {a : \u03b1} : nonneg a \u2194 0 \u2264 a :=\nshow _ \u2194 nonneg _, by simp\n\ntheorem pos_def {a : \u03b1} : pos a \u2194 0 < a :=\nshow _ \u2194 pos _, by simp\n\ntheorem not_zero_pos : \u00ac pos (0 : \u03b1) :=\nmt pos_def.1 (lt_irrefl _)\n\ntheorem zero_lt_iff_nonneg_nonneg {a : \u03b1} :\n  0 < a \u2194 nonneg a \u2227 \u00ac nonneg (-a) :=\npos_def.symm.trans (pos_iff _)\n\ntheorem nonneg_total_iff :\n  (\u2200 a : \u03b1, nonneg a \u2228 nonneg (-a)) \u2194\n  (\u2200 a b : \u03b1, a \u2264 b \u2228 b \u2264 a) :=\n\u27e8\u03bb h a b, by have := h (b - a); rwa [neg_sub] at this,\n \u03bb h a, by rw [nonneg_def, nonneg_def, neg_nonneg]; apply h\u27e9\n\n/--\nA `nonneg_add_comm_group` is a `linear_ordered_add_comm_group`\nif `nonneg` is total and decidable.\n-/\ndef to_linear_ordered_add_comm_group\n  [decidable_pred (@nonneg \u03b1 _)]\n  (nonneg_total : \u2200 a : \u03b1, nonneg a \u2228 nonneg (-a))\n  : linear_ordered_add_comm_group \u03b1 :=\n{ le := (\u2264),\n  lt := (<),\n  le_total := nonneg_total_iff.1 nonneg_total,\n  decidable_le := by apply_instance,\n  decidable_lt := by apply_instance,\n  ..@nonneg_add_comm_group.to_ordered_add_comm_group _ s }\n\nend nonneg_add_comm_group\n\nnamespace order_dual\n\ninstance [ordered_add_comm_group \u03b1] : ordered_add_comm_group (order_dual \u03b1) :=\n{ add_left_neg := \u03bb a : \u03b1, add_left_neg a,\n  sub := \u03bb a b, (a - b : \u03b1),\n  ..order_dual.ordered_add_comm_monoid,\n  ..show add_comm_group \u03b1, by apply_instance }\n\ninstance [linear_ordered_add_comm_group \u03b1] :\n  linear_ordered_add_comm_group (order_dual \u03b1) :=\n{ add_le_add_left := \u03bb a b h c, @add_le_add_left \u03b1 _ b a h _,\n  ..order_dual.linear_order \u03b1,\n  ..show add_comm_group \u03b1, by apply_instance }\n\nend order_dual\n\nnamespace prod\n\nvariables {G H : Type*}\n\n@[to_additive]\ninstance [ordered_comm_group G] [ordered_comm_group H] :\n  ordered_comm_group (G \u00d7 H) :=\n{ .. prod.comm_group, .. prod.partial_order G H, .. prod.ordered_cancel_comm_monoid }\n\nend prod\n\nsection type_tags\n\ninstance [ordered_add_comm_group \u03b1] : ordered_comm_group (multiplicative \u03b1) :=\n{ ..multiplicative.comm_group,\n  ..multiplicative.ordered_comm_monoid }\n\ninstance [ordered_comm_group \u03b1] : ordered_add_comm_group (additive \u03b1) :=\n{ ..additive.add_comm_group,\n  ..additive.ordered_add_comm_monoid }\n\ninstance [linear_ordered_add_comm_group \u03b1] : linear_ordered_comm_group (multiplicative \u03b1) :=\n{ ..multiplicative.linear_order,\n  ..multiplicative.ordered_comm_group }\n\ninstance [linear_ordered_comm_group \u03b1] : linear_ordered_add_comm_group (additive \u03b1) :=\n{ ..additive.linear_order,\n  ..additive.ordered_add_comm_group }\n\nend type_tags\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/ordered_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7389251286900541}}
{"text": "import tactic\nimport data.set.finite\nimport data.real.basic -- for metrics\n\n/-\n# (Re)-Building topological spaces in Lean\nMathlib has a large library of results on topological spaces, including various\nconstructions, separation axioms, Tychonoff's theorem, sheaves, Stone-\u010cech\ncompactification, Heine-Cantor, to name but a few.\nSee https://leanprover-community.github.io/theories/topology.html which for a\n(subset) of what's in library.\nBut today we will ignore all that, and build our own version of topological\nspaces from scratch!\n(On Friday morning Patrick Massot will lead a session exploring the existing\nmathlib library in more detail)\nTo get this file run either `leanproject get lftcm2020`, if you didn't already or cd to\nthat folder and run `git pull; leanproject get-mathlib-cache`, this is\n`src/exercise_sources/wednesday/topological_spaces.lean`.\nThe exercises are spread throughout, you needn't do them in order! They are marked as\nshort, medium and long, so I suggest you try some short ones first.\nFirst a little setup, we will be making definitions involving the real numbers,\nthe theory of which is not computable, and we'll use sets.\n-/\nnoncomputable theory\nopen set\n\n/-!\n## What is a topological space:\nThere are many definitions: one from Wikipedia:\n  A topological space is an ordered pair (X, \u03c4), where X is a set and \u03c4 is a\n  collection of subsets of X, satisfying the following axioms:\n  - The empty set and X itself belong to \u03c4.\n  - Any arbitrary (finite or infinite) union of members of \u03c4 still belongs to \u03c4.\n  - The intersection of any finite number of members of \u03c4 still belongs to \u03c4.\nWe can formalize this as follows: -/\n\nclass topological_space_wiki :=\n  (X : Type)  -- the underlying Type that the topology will be on\n  (\u03c4 : set (set X))  -- the set of open subsets of X\n  (empty_mem : \u2205 \u2208 \u03c4)  -- empty set is open\n  (univ_mem : univ \u2208 \u03c4)  -- whole space is open\n  (union : \u2200 B \u2286 \u03c4, \u22c3\u2080 B \u2208 \u03c4)  -- arbitrary unions (sUnions) of members of \u03c4 are open\n  (inter : \u2200 (B \u2286 \u03c4) (h : set.finite B), \u22c2\u2080 B \u2208 \u03c4)  -- finite intersections of\n                                                -- members of \u03c4 are open\n\n/-\nBefore we go on we should be sure we want to use this as our definition.\n-/\n\n\n@[ext]\nclass topological_space (X : Type) :=\n  (is_open : set X \u2192 Prop) -- why set X \u2192 Prop not set (set X)? former plays\n                           -- nicer with typeclasses later\n  (univ_mem : is_open univ)\n  (union : \u2200 (B : set (set X)) (h : \u2200 b \u2208 B, is_open b), is_open (\u22c3\u2080 B))\n  (inter : \u2200 (A B : set X) (hA : is_open A) (hB : is_open B), is_open (A \u2229 B))\n\nnamespace topological_space\n\n/- We can now work with topological spaces like this. -/\nexample (X : Type) [topological_space X] (U V W : set X) (hU : is_open U) (hV : is_open V)\n  (hW : is_open W) : is_open (U \u2229 V \u2229 W) :=\nbegin\n  apply inter _ _ _ hW,\n  exact inter _ _ hU hV,\nend\n\n/- ## Exercise 0 [short]:\nOne of the axioms of a topological space we have here is unnecessary, it follows\nfrom the others. If we remove it we'll have less work to do each time we want to\ncreate a new topological space so:\n1. Identify and remove the unneeded axiom, make sure to remove it throughout the file.\n2. Add the axiom back as a lemma with the same name and prove it based on the\n   others, so that the _interface_ is the same. -/\n\nlemma empty_mem (X : Type) [topological_space X] : is_open (\u2205 : set X) := \nbegin \n  convert union (\u2205 : set (set X)) _; simp,\nend\n\n\n\n/- Defining a basic topology now works like so: -/\ndef discrete (X : Type) : topological_space X :=\n{ is_open := \u03bb U, true, -- everything is open\n  univ_mem := trivial,\n  union := begin intros B h, trivial, end,\n  inter := begin intros A hA B hB, trivial, end }\n\n/- ## Exercise 1 [medium]:\nOne way me might want to create topological spaces in practice is to take\nthe coarsest possible topological space containing a given set of is_open.\nTo define this we might say we want to define what `is_open` is given the set\nof generators.\nSo we want to define the predicate `is_open` by declaring that each generator\nwill be open, the intersection of two opens will be open, and each union of a\nset of opens will be open, and finally the empty and whole space (`univ`) must\nbe open. The cleanest way to do this is as an inductive definition.\nThe exercise is to make this definition of the topological space generated by a\ngiven set in Lean.\n### Hint:\nAs a hint for this exercise take a look at the following definition of a\nconstructible set of a topological space, defined by saying that an intersection\nof an open and a closed set is constructible and that the union of any pair of\nconstructible sets is constructible.\n(Bonus exercise: mathlib doesn't have any theory of constructible sets, make one and PR\nit! [arbitrarily long!], or just prove that open and closed sets are constructible for now) -/\n\ninductive is_constructible {X : Type} (T : topological_space X) : set X \u2192 Prop\n/- Given two open sets in `T`, the intersection of one with the complement of\n   the other open is locally closed, hence constructible: -/\n| locally_closed : \u2200 (A B : set X), is_open A \u2192 is_open B \u2192 is_constructible (A \u2229 B\u1d9c)\n-- Given two constructible sets their union is constructible:\n| union : \u2200 A B, is_constructible A \u2192 is_constructible B \u2192 is_constructible (A \u222a B)\n\n-- For example we can now use this definition to prove the empty set is constructible\nexample {X : Type} (T : topological_space X) : is_constructible T \u2205 :=\nbegin\n  -- The intersection of the whole space (open) with the empty set (closed) is\n  -- locally closed, hence constructible\n  have := is_constructible.locally_closed univ univ T.univ_mem T.univ_mem,\n  -- but simp knows that's just the empty set (`simp` uses `this` automatically)\n  simpa,\nend\n\n/-- The open sets of the least topology containing a collection of basic sets. -/\ninductive generated_open (X : Type) (g : set (set X)) : set X \u2192 Prop\n-- The exercise: Add a definition here defining which sets are generated by `g` like the\n-- `is_constructible` definition above.\n| basic : \u2200 s \u2208 g, generated_open s\n| univ : generated_open univ \n| inter : \u2200 s t, generated_open s \u2192 generated_open t \u2192 generated_open (s \u2229 t)\n| sUnion : \u2200 k, (\u2200 s \u2208 k, generated_open s) \u2192 generated_open (\u22c3\u2080 k)\n\n\n\n/-- The smallest topological space containing the collection `g` of basic sets -/\ndef generate_from (X : Type) (g : set (set X)) : topological_space X :=\n{ is_open   := generated_open X g,\n  univ_mem  := generated_open.univ,\n  inter     := generated_open.inter,\n  union     := generated_open.sUnion }\n\n/- ## Exercise 2 [short]:\nDefine the indiscrete topology on any type using this.\n(To do it without this it is surprisingly fiddly to prove that the set `{\u2205, univ}`\nactually forms a topology) -/\ndef indiscrete (X : Type) : topological_space X :=\n  generate_from X \u2205 \nend topological_space\n\nopen topological_space\n/- Now it is quite easy to give a topology on the product of a pair of\n   topological spaces. -/\ninstance prod.topological_space (X Y : Type) [topological_space X]\n  [topological_space Y] : topological_space (X \u00d7 Y) :=\ntopological_space.generate_from (X \u00d7 Y) {U | \u2203 (Ux : set X) (Uy : set Y)\n  (hx : is_open Ux) (hy : is_open Uy), U = Ux \u00d7\u02e2 Uy}\n\n-- the proof of this is bit long so I've left it out for the purpose of this file!\nlemma is_open_prod_iff (X Y : Type) [topological_space X] [topological_space Y]\n  {s : set (X \u00d7 Y)} :\nis_open s \u2194 (\u2200a b, (a, b) \u2208 s \u2192 \u2203 (u : set X) (v : set Y), is_open u \u2227 is_open v \u2227\n                                  a \u2208 u \u2227 b \u2208 v \u2227 u \u00d7\u02e2 v \u2286 s) := sorry\n\n/- # Metric spaces -/\n\nopen_locale big_operators\n\nclass metric_space_basic (X : Type) :=\n  (dist : X \u2192 X \u2192 \u211d)\n  (dist_eq_zero_iff : \u2200 x y, dist x y = 0 \u2194 x = y)\n  (dist_symm : \u2200 x y, dist x y = dist y x)\n  (triangle : \u2200 x y z, dist x z \u2264 dist x y + dist y z)\n\nnamespace metric_space_basic\nopen topological_space\n\n/- ## Exercise 3 [short]:\nWe have defined a metric space with a metric landing in \u211d, and made no mention of\nnonnegativity, (this is in line with the philosophy of using the easiest axioms for our\ndefinitions as possible, to make it easier to define individual metrics). Show that we\nreally did define the usual notion of metric space. -/\nlemma dist_nonneg {X : Type} [metric_space_basic X] (x y : X) : 0 \u2264 dist x y :=\nbegin \n  have : 0 \u2264 2 * dist x y,\n  calc \n    0 = dist x x : by symmetry; rw [dist_eq_zero_iff x x]\n    ... \u2264 dist x y + dist y x : by simp only [triangle]\n    ... = dist x y + dist x y : by rw [dist_symm]\n    ... = 2 * dist x y : by rw two_mul, \n  linarith [this],\nend\n\n/- From a metric space we get an induced topological space structure like so: -/\n\ninstance {X : Type} [metric_space_basic X] : topological_space X :=\ngenerate_from X { B | \u2203 (x : X) r, B = {y | dist x y < r} }\n\nend metric_space_basic\n\nopen metric_space_basic\n\n/- So far so good, now lets define the product of two metric spaces:\n## Exercise 4 [medium]:\nFill in the proofs here.\nHint: the computer can do boring casework you would never dream of in real life.\n`max` is defined as `if x < y then y else x` and the `split_ifs` tactic will\nbreak apart if statements. -/\ninstance prod.metric_space_basic (X Y : Type) [metric_space_basic X] [metric_space_basic Y] :\nmetric_space_basic (X \u00d7 Y) :=\n{ dist := \u03bb u v, max (dist u.fst v.fst) (dist u.snd v.snd),\n  dist_eq_zero_iff :=\n    begin\n      intros x y, split,\n      { intro h,\n        have hf := dist_nonneg x.1 y.1,\n        have hs := dist_nonneg x.2 y.2,\n        have := max_le_iff.mp (le_of_eq h),\n        ext; rw \u2190 dist_eq_zero_iff; linarith,},\n      { intro h, rw [h, (dist_eq_zero_iff _ _).mpr, (dist_eq_zero_iff _ _).mpr, max_self]; refl,}\n    end,\n  dist_symm := by { intros x y, simp [dist_symm]},\n  triangle :=\n    begin \n      intros x y z, \n      have hf := triangle x.fst y.fst z.fst,\n      have hs := triangle x.snd y.snd z.snd,\n      simp only [max, max_default],\n      split_ifs; linarith,\n    end\n  }\n\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/LftCM2020/exercises/03_Wednesday/03_Topological_Spaces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7389251255282053}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\nimport data.list.perm\n\n/-!\n# Sorting algorithms on lists\n\nIn this file we define `list.sorted r l` to be an alias for `pairwise r l`. This alias is preferred\nin the case that `r` is a `<` or `\u2264`-like relation. Then we define two sorting algorithms:\n`list.insertion_sort` and `list.merge_sort`, and prove their correctness.\n-/\n\nopen list.perm\n\nuniverse uu\n\nnamespace list\n\n/-!\n### The predicate `list.sorted`\n-/\n\nsection sorted\n\nvariables {\u03b1 : Type uu} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {a : \u03b1} {l : list \u03b1}\n\n/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`\n  is a `<` or `\u2264`-like relation (transitive and antisymmetric or asymmetric) -/\ndef sorted := @pairwise\n\ninstance decidable_sorted [decidable_rel r] (l : list \u03b1) : decidable (sorted r l) :=\nlist.decidable_pairwise _\n\n@[simp] theorem sorted_nil : sorted r [] := pairwise.nil\n\nlemma sorted.of_cons : sorted r (a :: l) \u2192 sorted r l := pairwise.of_cons\n\ntheorem sorted.tail {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {l : list \u03b1} (h : sorted r l) : sorted r l.tail :=\nh.tail\n\ntheorem rel_of_sorted_cons {a : \u03b1} {l : list \u03b1} : sorted r (a :: l) \u2192\n  \u2200 b \u2208 l, r a b :=\nrel_of_pairwise_cons\n\n@[simp] theorem sorted_cons {a : \u03b1} {l : list \u03b1} :\n  sorted r (a :: l) \u2194 (\u2200 b \u2208 l, r a b) \u2227 sorted r l :=\npairwise_cons\n\nprotected theorem sorted.nodup {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_irrefl \u03b1 r] {l : list \u03b1} (h : sorted r l) :\n  nodup l :=\nh.nodup\n\ntheorem eq_of_perm_of_sorted [is_antisymm \u03b1 r]\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) (s\u2081 : sorted r l\u2081) (s\u2082 : sorted r l\u2082) : l\u2081 = l\u2082 :=\nbegin\n  induction s\u2081 with a l\u2081 h\u2081 s\u2081 IH generalizing l\u2082,\n  { exact p.nil_eq },\n  { have : a \u2208 l\u2082 := p.subset (mem_cons_self _ _),\n    rcases mem_split this with \u27e8u\u2082, v\u2082, rfl\u27e9,\n    have p' := (perm_cons a).1 (p.trans perm_middle),\n    obtain rfl := IH p' (s\u2082.sublist $ by simp),\n    change a::u\u2082 ++ v\u2082 = u\u2082 ++ ([a] ++ v\u2082), rw \u2190 append_assoc, congr,\n    have : \u2200 (x : \u03b1) (h : x \u2208 u\u2082), x = a := \u03bb x m,\n      antisymm ((pairwise_append.1 s\u2082).2.2 _ m a (mem_cons_self _ _))\n        (h\u2081 _ (by simp [m])),\n    rw [(@eq_repeat _ a (length u\u2082 + 1) (a::u\u2082)).2,\n        (@eq_repeat _ a (length u\u2082 + 1) (u\u2082++[a])).2];\n    split; simp [iff_true_intro this, or_comm] }\nend\n\ntheorem sublist_of_subperm_of_sorted [is_antisymm \u03b1 r]\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 <+~ l\u2082) (s\u2081 : l\u2081.sorted r) (s\u2082 : l\u2082.sorted r) : l\u2081 <+ l\u2082 :=\nlet \u27e8_, h, h'\u27e9 := p in by rwa \u2190eq_of_perm_of_sorted h (s\u2082.sublist h') s\u2081\n\n@[simp] theorem sorted_singleton (a : \u03b1) : sorted r [a] := pairwise_singleton _ _\n\nlemma sorted.rel_nth_le_of_lt {l : list \u03b1}\n  (h : l.sorted r) {a b : \u2115} (ha : a < l.length) (hb : b < l.length) (hab : a < b) :\n  r (l.nth_le a ha) (l.nth_le b hb) :=\nlist.pairwise_iff_nth_le.1 h a b hb hab\n\nlemma sorted.rel_nth_le_of_le [is_refl \u03b1 r] {l : list \u03b1}\n  (h : l.sorted r) {a b : \u2115} (ha : a < l.length) (hb : b < l.length) (hab : a \u2264 b) :\n  r (l.nth_le a ha) (l.nth_le b hb) :=\nbegin\n  cases eq_or_lt_of_le hab with H H,\n  { subst H, exact refl _ },\n  { exact h.rel_nth_le_of_lt _ _ H }\nend\n\nlemma sorted.rel_of_mem_take_of_mem_drop {l : list \u03b1} (h : list.sorted r l)\n  {k : \u2115} {x y : \u03b1} (hx : x \u2208 list.take k l) (hy : y \u2208 list.drop k l) :\n  r x y :=\nbegin\n  obtain \u27e8iy, hiy, rfl\u27e9 := nth_le_of_mem hy,\n  obtain \u27e8ix, hix, rfl\u27e9 := nth_le_of_mem hx,\n  rw [nth_le_take', nth_le_drop'],\n  rw length_take at hix,\n  exact h.rel_nth_le_of_lt _ _ (ix.lt_add_right _ _ (lt_min_iff.mp hix).left)\nend\n\nend sorted\n\nsection sort\nvariables {\u03b1 : Type uu} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [decidable_rel r]\nlocal infix ` \u227c ` : 50 := r\n\n/-! ### Insertion sort -/\n\nsection insertion_sort\n\n/-- `ordered_insert a l` inserts `a` into `l` at such that\n  `ordered_insert a l` is sorted if `l` is. -/\n@[simp] def ordered_insert (a : \u03b1) : list \u03b1 \u2192 list \u03b1\n| []       := [a]\n| (b :: l) := if a \u227c b then a :: b :: l else b :: ordered_insert l\n\n/-- `insertion_sort l` returns `l` sorted using the insertion sort algorithm. -/\n@[simp] def insertion_sort : list \u03b1 \u2192 list \u03b1\n| []       := []\n| (b :: l) := ordered_insert r b (insertion_sort l)\n\n@[simp] lemma ordered_insert_nil (a : \u03b1) : [].ordered_insert r a = [a] := rfl\n\ntheorem ordered_insert_length : \u03a0 (L : list \u03b1) (a : \u03b1), (L.ordered_insert r a).length = L.length + 1\n| [] a := rfl\n| (hd :: tl) a := by { dsimp [ordered_insert], split_ifs; simp [ordered_insert_length], }\n\n/-- An alternative definition of `ordered_insert` using `take_while` and `drop_while`. -/\nlemma ordered_insert_eq_take_drop (a : \u03b1) : \u2200 l : list \u03b1,\n  l.ordered_insert r a = l.take_while (\u03bb b, \u00ac(a \u227c b)) ++ (a :: l.drop_while (\u03bb b, \u00ac(a \u227c b)))\n| [] := rfl\n| (b :: l) := by { dsimp only [ordered_insert], split_ifs; simp [take_while, drop_while, *] }\n\nlemma insertion_sort_cons_eq_take_drop (a : \u03b1) (l : list \u03b1) :\n  insertion_sort r (a :: l) = (insertion_sort r l).take_while (\u03bb b, \u00ac(a \u227c b)) ++\n    (a :: (insertion_sort r l).drop_while (\u03bb b, \u00ac(a \u227c b))) :=\nordered_insert_eq_take_drop r a _\n\nsection correctness\nopen perm\n\ntheorem perm_ordered_insert (a) : \u2200 l : list \u03b1, ordered_insert r a l ~ a :: l\n| []       := perm.refl _\n| (b :: l) := by by_cases a \u227c b; [simp [ordered_insert, h],\n  simpa [ordered_insert, h] using\n    ((perm_ordered_insert l).cons _).trans (perm.swap _ _ _)]\n\ntheorem ordered_insert_count [decidable_eq \u03b1] (L : list \u03b1) (a b : \u03b1) :\n  count a (L.ordered_insert r b) = count a L + if (a = b) then 1 else 0 :=\nbegin\n  rw [(L.perm_ordered_insert r b).count_eq, count_cons],\n  split_ifs; simp only [nat.succ_eq_add_one, add_zero],\nend\n\ntheorem perm_insertion_sort : \u2200 l : list \u03b1, insertion_sort r l ~ l\n| []       := perm.nil\n| (b :: l) := by simpa [insertion_sort] using\n  (perm_ordered_insert _ _ _).trans ((perm_insertion_sort l).cons b)\n\nvariable {r}\n\n/-- If `l` is already `list.sorted` with respect to `r`, then `insertion_sort` does not change\nit. -/\nlemma sorted.insertion_sort_eq : \u2200 {l : list \u03b1} (h : sorted r l), insertion_sort r l = l\n| [] _ := rfl\n| [a] _ := rfl\n| (a :: b :: l) h :=\n  begin\n    rw [insertion_sort, sorted.insertion_sort_eq, ordered_insert, if_pos],\n    exacts [rel_of_sorted_cons h _ (or.inl rfl), h.tail]\n  end\n\nsection total_and_transitive\nvariables [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted.ordered_insert (a : \u03b1) : \u2200 l, sorted r l \u2192 sorted r (ordered_insert r a l)\n| []       h := sorted_singleton a\n| (b :: l) h := begin\n  by_cases h' : a \u227c b,\n  { simpa [ordered_insert, h', h] using \u03bb b' bm, trans h' (rel_of_sorted_cons h _ bm) },\n  { suffices : \u2200 (b' : \u03b1), b' \u2208 ordered_insert r a l \u2192 r b b',\n    { simpa [ordered_insert, h', h.of_cons.ordered_insert l] },\n    intros b' bm,\n    cases (show b' = a \u2228 b' \u2208 l, by simpa using\n      (perm_ordered_insert _ _ _).subset bm) with be bm,\n    { subst b', exact (total_of r _ _).resolve_left h' },\n    { exact rel_of_sorted_cons h _ bm } }\nend\n\nvariable (r)\n\n/-- The list `list.insertion_sort r l` is `list.sorted` with respect to `r`. -/\ntheorem sorted_insertion_sort : \u2200 l, sorted r (insertion_sort r l)\n| []       := sorted_nil\n| (a :: l) := (sorted_insertion_sort l).ordered_insert a _\n\nend total_and_transitive\nend correctness\nend insertion_sort\n\n/-! ### Merge sort -/\n\nsection merge_sort\n\n-- TODO(Jeremy): observation: if instead we write (a :: (split l).1, b :: (split l).2), the\n-- equation compiler can't prove the third equation\n\n/-- Split `l` into two lists of approximately equal length.\n\n     split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) -/\n@[simp] def split : list \u03b1 \u2192 list \u03b1 \u00d7 list \u03b1\n| []       := ([], [])\n| (a :: l) := let (l\u2081, l\u2082) := split l in (a :: l\u2082, l\u2081)\n\ntheorem split_cons_of_eq (a : \u03b1) {l l\u2081 l\u2082 : list \u03b1} (h : split l = (l\u2081, l\u2082)) :\n  split (a :: l) = (a :: l\u2082, l\u2081) :=\nby rw [split, h]; refl\n\ntheorem length_split_le : \u2200 {l l\u2081 l\u2082 : list \u03b1},\n  split l = (l\u2081, l\u2082) \u2192 length l\u2081 \u2264 length l \u2227 length l\u2082 \u2264 length l\n| []     ._  ._  rfl := \u27e8nat.le_refl 0, nat.le_refl 0\u27e9\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ h\u2082, nat.le_succ_of_le h\u2081\u27e9\nend\n\ntheorem length_split_lt {a b} {l l\u2081 l\u2082 : list \u03b1} (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  length l\u2081 < length (a::b::l) \u2227 length l\u2082 < length (a::b::l) :=\nbegin\n  cases e : split l with l\u2081' l\u2082',\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l\u2081 l\u2082,\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ (nat.succ_le_succ h\u2081), nat.succ_le_succ (nat.succ_le_succ h\u2082)\u27e9\nend\n\ntheorem perm_split : \u2200 {l l\u2081 l\u2082 : list \u03b1}, split l = (l\u2081, l\u2082) \u2192 l ~ l\u2081 ++ l\u2082\n| []     ._  ._  rfl := perm.refl _\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  exact ((perm_split e).trans perm_append_comm).cons a,\nend\n\n/-- Merge two sorted lists into one in linear time.\n\n     merge [1, 2, 4, 5] [0, 1, 3, 4] = [0, 1, 1, 2, 3, 4, 4, 5] -/\ndef merge : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| []       l'        := l'\n| l        []        := l\n| (a :: l) (b :: l') := if a \u227c b then a :: merge l (b :: l') else b :: merge (a :: l) l'\n\ninclude r\n/-- Implementation of a merge sort algorithm to sort a list. -/\ndef merge_sort : list \u03b1 \u2192 list \u03b1\n| []        := []\n| [a]       := [a]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  exact merge r (merge_sort l\u2081) (merge_sort l\u2082)\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_cons_cons {a b} {l l\u2081 l\u2082 : list \u03b1}\n  (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  merge_sort r (a::b::l) = merge r (merge_sort r l\u2081) (merge_sort r l\u2082) :=\nbegin\n  suffices : \u2200 (L : list \u03b1) h1, @@and.rec\n    (\u03bb a a (_ : length l\u2081 < length l + 1 + 1 \u2227\n      length l\u2082 < length l + 1 + 1), L) h1 h1 = L,\n  { simp [merge_sort, h], apply this },\n  intros, cases h1, refl\nend\n\nsection correctness\n\ntheorem perm_merge : \u2200 (l l' : list \u03b1), merge r l l' ~ l ++ l'\n| []       []        := by simp [merge]\n| []       (b :: l') := by simp [merge]\n| (a :: l) []        := by simp [merge]\n| (a :: l) (b :: l') := begin\n  by_cases a \u227c b,\n  { simpa [merge, h] using perm_merge _ _ },\n  { suffices : b :: merge r (a :: l) l' ~ a :: (l ++ b :: l'), {simpa [merge, h]},\n    exact ((perm_merge _ _).cons _).trans ((swap _ _ _).trans (perm_middle.symm.cons _)) }\nend\n\ntheorem perm_merge_sort : \u2200 l : list \u03b1, merge_sort r l ~ l\n| []        := by simp [merge_sort]\n| [a]       := by simp [merge_sort]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  apply (perm_merge r _ _).trans,\n  exact ((perm_merge_sort l\u2081).append (perm_merge_sort l\u2082)).trans (perm_split e).symm\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\n@[simp] lemma length_merge_sort (l : list \u03b1) : (merge_sort r l).length = l.length :=\n(perm_merge_sort r _).length_eq\n\nsection total_and_transitive\nvariables {r} [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted.merge : \u2200 {l l' : list \u03b1}, sorted r l \u2192 sorted r l' \u2192 sorted r (merge r l l')\n| []       []        h\u2081 h\u2082 := by simp [merge]\n| []       (b :: l') h\u2081 h\u2082 := by simpa [merge] using h\u2082\n| (a :: l) []        h\u2081 h\u2082 := by simpa [merge] using h\u2081\n| (a :: l) (b :: l') h\u2081 h\u2082 := begin\n  by_cases a \u227c b,\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r l (b :: l')), r a b',\n    { simpa [merge, h, h\u2081.of_cons.merge h\u2082] },\n    intros b' bm,\n    rcases (show b' = b \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa [or.left_comm] using\n      (perm_merge _ _ _).subset bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact rel_of_sorted_cons h\u2081 _ bl },\n    { exact trans h (rel_of_sorted_cons h\u2082 _ bl') } },\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r (a :: l) l'), r b b',\n    { simpa [merge, h, h\u2081.merge h\u2082.of_cons] },\n    intros b' bm,\n    have ba : b \u227c a := (total_of r _ _).resolve_left h,\n    rcases (show b' = a \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa using\n      (perm_merge _ _ _).subset bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact trans ba (rel_of_sorted_cons h\u2081 _ bl) },\n    { exact rel_of_sorted_cons h\u2082 _ bl' } }\nend\n\nvariable (r)\n\ntheorem sorted_merge_sort : \u2200 l : list \u03b1, sorted r (merge_sort r l)\n| []        := by simp [merge_sort]\n| [a]       := by simp [merge_sort]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  exact (sorted_merge_sort l\u2081).merge (sorted_merge_sort l\u2082)\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_eq_self [is_antisymm \u03b1 r] {l : list \u03b1} : sorted r l \u2192 merge_sort r l = l :=\neq_of_perm_of_sorted (perm_merge_sort _ _) (sorted_merge_sort _ _)\n\ntheorem merge_sort_eq_insertion_sort [is_antisymm \u03b1 r] (l : list \u03b1) :\n  merge_sort r l = insertion_sort r l :=\neq_of_perm_of_sorted ((perm_merge_sort r l).trans (perm_insertion_sort r l).symm)\n  (sorted_merge_sort r l) (sorted_insertion_sort r l)\n\nend total_and_transitive\nend correctness\n\n@[simp] theorem merge_sort_nil : [].merge_sort r = [] :=\nby rw list.merge_sort\n\n@[simp] theorem merge_sort_singleton (a : \u03b1) : [a].merge_sort r = [a] :=\nby rw list.merge_sort\n\nend merge_sort\nend sort\n\n/- try them out! -/\n\n--#eval insertion_sort (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\n--#eval merge_sort     (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\nend list\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/list/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7388258894072381}}
{"text": "import ..lectures.love01_definitions_and_statements_demo\nimport ..lectures.love10_denotational_semantics_demo\n\n/-!\n# FPV Homework 6: Operational and denotational semantics\n\nThis homework corresponds to chapters 8 and 10 of the HHG.\n-/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (4 points): Operational Semantics of Regular Expressions\n\nRegular expression are a very popular tool for software development. Often,\nwhen textual input needs to be analyzed it is matched against a regular\nexpression. In this question, we define the syntax of regular expressions and\nwhat it means for a regular expression to match a string.\n\nWe define `regex` to represent the following grammar:\n\n    R ::= \u2205       \u2014 `nothing`: matches nothing\n        | \u03b5       \u2014 `empty`: matches the empty string\n        | a       \u2014 `atom`: matches the atom `a`\n        | R \u2b1d R    \u2014 `concat`: matches the concatenation of two regexes\n        | R + R   \u2014 `alt`: matches either of two regexes\n        | R*      \u2014 `star`: matches arbitrary many repetitions of a regex\n\nNotice the rough correspondence with a WHILE language:\n\n    `empty`  ~ `skip`\n    `atom`   ~ assignment\n    `concat` ~ sequential composition\n    `alt`    ~ conditional statement\n    `star`   ~ while loop -/\n\ninductive regex (\u03b1 : Type) : Type\n| nothing {} : regex\n| empty   {} : regex\n| atom       : \u03b1 \u2192 regex\n| concat     : regex \u2192 regex \u2192 regex\n| alt        : regex \u2192 regex \u2192 regex\n| star       : regex \u2192 regex\n\n/-! The `matches r s` predicate indicates that the regular expression `r` matches\nthe string `s`. -/\n\ninductive matches {\u03b1 : Type } : regex \u03b1 \u2192 list \u03b1 \u2192 Prop\n| empty :\n  matches regex.empty []\n| atom (a : \u03b1) :\n  matches (regex.atom a) [a]\n| concat {r\u2081 r\u2082 : regex \u03b1} (s\u2081 s\u2082 : list \u03b1) (h\u2081 : matches r\u2081 s\u2081)\n    (h\u2082 : matches r\u2082 s\u2082) :\n  matches (regex.concat r\u2081 r\u2082) (s\u2081 ++ s\u2082)\n| alt_left {r\u2081 r\u2082 : regex \u03b1} (s : list \u03b1) (h : matches r\u2081 s) :\n  matches (regex.alt r\u2081 r\u2082) s\n| alt_right {r\u2081 r\u2082 : regex \u03b1} (s : list \u03b1) (h : matches r\u2082 s) :\n  matches (regex.alt r\u2081 r\u2082) s\n| star_base {r : regex \u03b1} :\n  matches (regex.star r) []\n| star_step {r : regex \u03b1} (s s' : list \u03b1) (h\u2081 : matches r s)\n    (h\u2082 : matches (regex.star r) s') :\n  matches (regex.star r) (s ++ s')\n\n/-! The introduction rules correspond to the following cases:\n\n* match the empty string\n* match one atom (e.g., character)\n* match two concatenated regexes\n* match the left option\n* match the right option\n* match the empty string (the base case of `R*`)\n* match `R` followed again by `R*` (the induction step of `R*`)\n\n1.1 (1 point). Explain why there is no rule for `nothing`. -/\n\n-- enter your answer here\n\n/-! 1.2 (3 points). Prove the following inversion rules. -/\n\n@[simp] lemma matches_atom {\u03b1 : Type} {s : list \u03b1} {a : \u03b1} :\n  matches (regex.atom a) s \u2194 s = [a] :=\nsorry\n\n@[simp] lemma matches_nothing {\u03b1 : Type} {s : list \u03b1} :\n  \u00ac matches regex.nothing s :=\nsorry\n\n@[simp] lemma matches_empty {\u03b1 : Type} {s : list \u03b1} :\n  matches regex.empty s \u2194 s = [] :=\nsorry\n\n@[simp] lemma matches_concat {\u03b1 : Type} {s : list \u03b1} {r\u2081 r\u2082 : regex \u03b1} :\n  matches (regex.concat r\u2081 r\u2082) s\n  \u2194 (\u2203s\u2081 s\u2082, matches r\u2081 s\u2081 \u2227 matches r\u2082 s\u2082 \u2227 s = s\u2081 ++ s\u2082) :=\nsorry\n\n@[simp] lemma matches_alt {\u03b1 : Type} {s : list \u03b1} {r\u2081 r\u2082 : regex \u03b1} :\n  matches (regex.alt r\u2081 r\u2082) s \u2194 (matches r\u2081 s \u2228 matches r\u2082 s) :=\nsorry\n\n\n\n/-! ## Question 2: Monotonicity (4 points)\n\n2.1 (2 points). Prove the following lemma from the Ch. 10 lecture. -/\n\nlemma monotone_comp {\u03b1 \u03b2 : Type} [partial_order \u03b1] (f g : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (\u03bba, f a \u25ef g a) :=\nsorry\n\n/-! 2.2 (2 points). Prove its cousin. -/\n\nlemma monotone_restrict {\u03b1 \u03b2 : Type} [partial_order \u03b1] (f : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2))\n    (p : \u03b2 \u2192 Prop) (hf : monotone f) :\n  monotone (\u03bba, f a \u21c3 p) :=\nsorry\n\n\n/-! ## Question 3: Denotational Semantics of Regular Expressions (4 points)\n\nIn this exercise, we explore an alternative semantics of regular\nexpressions. Namely, we can imagine that the atoms represent binary relations,\ninstead of letters or symbols. Concatenation corresponds to composition of\nrelations, and alternation is union. Mathematically, regexes and binary\nrelations are both instances of Kleene algebras.\n\n3.1 (2 points). Complete the following translation of regular expressions to relations.\n\nHint: Exploit the correspondence with the WHILE language. -/\n\ndef rel_of_regex {\u03b1 : Type} : regex (set (\u03b1 \u00d7 \u03b1)) \u2192 set (\u03b1 \u00d7 \u03b1)\n| regex.nothing        := \u2205\n| regex.empty          := Id\n| (regex.atom s)       := s\n-- enter the missing cases here\n\n/-! 3.2 (2 points). Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {\u03b1 : Type} (r : regex (set (\u03b1 \u00d7 \u03b1))) :\n  rel_of_regex (regex.star r) =\n  rel_of_regex (regex.alt (regex.concat r (regex.star r)) regex.empty) :=\nsorry\n\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/homework/love06_operational_and_denotational_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.738825881490131}}
{"text": "import game.max.level10\n\nopen_locale classical\n\nnoncomputable theory\n\nnamespace test\n\nvariables {a b c : \u211d}\n\n-- What \u211d has that a general total order hasn't got, is - .\n\nexample : -a \u2264 -b \u2194 b \u2264 a := by split; intros; linarith\n\ndef abs (x : \u211d) := max x (-x)\n\n-- useful for rewriting\nlemma abs_def (x : \u211d) : abs x = max x (-x) := rfl\n\n-- needs congr'\nlemma abs_neg (x : \u211d) : abs (-x) = abs x :=\nbegin\n  rw abs_def,\n  rw abs_def,\n  rw max_comm,\n  congr',\n  ring,\nend\n\n-- order level 3\n-- Powerful. Teaches them the colon. \ntheorem abs_le : abs a \u2264 b \u2194 -b \u2264 a \u2227 a \u2264 b :=\nbegin\n  rw abs_def,\n  rw max_le_iff,\n  split;\n  intro h;\n  cases h;\n  split;\n  linarith,\nend\n\ntheorem abs_of_nonneg (h : 0 \u2264 a) : abs a = a :=\nbegin\n  rw abs_def,\n  apply max_eq_left,\n  linarith,\nend\n\ntheorem abs_of_nonpos (h : a \u2264 0) : abs a = -a :=\nbegin\n  rw abs_def,\n  apply max_eq_right,\n  linarith,\nend\n\nvariables (a b) -- want them explicit in the next few\n\ntheorem abs_add : abs (a + b) \u2264 abs a + abs b :=\nbegin\n  rw abs_le,\n  cases le_total 0 a with h0a ha0,\n  { -- 0 \u2264 a\n    rw abs_of_nonneg h0a,\n    cases le_total 0 b with h0b hb0,\n    { rw abs_of_nonneg h0b,\n      split; linarith\n    },\n    { rw abs_of_nonpos hb0,\n      split; linarith\n    },\n  },\n  { -- a \u2264 0\n    rw abs_of_nonpos ha0,\n    cases le_total 0 b with h0b hb0,\n    { rw abs_of_nonneg h0b,\n      split; linarith\n    },\n    { rw abs_of_nonpos hb0,\n      split; linarith\n    },\n  },\nend\n\n-- order level 4\n-- convert makes this simple\ntheorem abs_sub_le_add_abs : abs (a - b) \u2264 abs a + abs b :=\nbegin\n  rw \u2190abs_neg b,\n  convert abs_add a (-b),\nend\n\n-- order level 5\n-- combination of ring and linarith; always try and deduce from triangle ineq\ntheorem abs_abs_sub_le_abs_sub : abs (abs a - abs b) \u2264 abs (a - b) :=\nbegin\n  rw abs_le,\n  split,\n  { have h := abs_sub_le_add_abs a (a - b),\n    ring_nf at h,\n    linarith,\n  },\n  { have h := abs_sub_le_add_abs (a - b) (-b),\n    rw abs_neg at h,\n    ring_nf at h,\n    linarith,\n  }\nend\n\n-- order level 2\ntheorem abs_mul (a b : \u211d) : abs (a * b) = abs a * abs b :=\nbegin\n  cases le_total 0 a with h0a ha0;\n  cases le_total 0 b with h0b hb0,\n  { -- both nonnegative\n    rw abs_of_nonneg h0a,\n    rw abs_of_nonneg h0b,\n    rw abs_of_nonneg,\n    nlinarith,\n  },\n  { -- b <= 0 <= a\n    rw abs_of_nonneg h0a,\n    rw abs_of_nonpos hb0,\n    rw abs_of_nonpos,\n    { ring},\n    nlinarith,\n  },\n  { -- a \u2264 0 \u2264 b\n    rw abs_of_nonpos ha0,\n    rw abs_of_nonneg h0b,\n    rw abs_of_nonpos,\n    { ring},\n    nlinarith,\n  },\n  { -- both nonnegative\n    rw abs_of_nonpos ha0,\n    rw abs_of_nonpos hb0,\n    rw abs_of_nonneg,\n    { ring},\n    nlinarith,\n  },  \nend\n\n-- order level 6 (unfinished)\nlemma le_iff_square_le (ha : 0 \u2264 a) (hb : 0 \u2264 b): a \u2264 b \u2194 a^2 \u2264 b^2 :=\nbegin\n  rw (show a^2 \u2264 b^2 \u2194 0 \u2264 b^2 - a^2, by split; intros; linarith),\n  rw (show b^2 - a^2 = (b + a) * (b - a), by ring),\n  rw (show a \u2264 b \u2194 0 \u2264 b - a, by split; intros; linarith), -- should be a lemma\n  have hab : 0 \u2264 b + a, by linarith,\n  split,\n  { intros,\n    nlinarith},\n  { intros,\n    by_cases h : b + a = 0,\n    { linarith },\n    have ha2 : 0 < b + a,\n    { by_contradiction hab,\n      push_neg at hab,\n      apply h,\n      linarith\n    },\n    sorry,\n  } \nend\n\n\nend test\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/abs/abs_API_test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.7387484530543501}}
{"text": "import tactic\nopen nat\n\ninductive le : \u2115 \u2192 \u2115 \u2192 Prop\n| le0 {n : \u2115} : le 0 n\n| les {m n : \u2115} : le m n \u2192 le (succ m) (succ n)\n\nopen le\n\ninductive le' : \u2115 \u2192 \u2115 \u2192 Prop\n| reflle' {n : \u2115} : le' n n\n| le's {m n : \u2115} : le' m n \u2192 le' m (succ n)\n\nopen le'\n\nlemma l1 : \u2200 n : \u2115, le' zero n :=\nbegin \n  assume n,\n  induction n,\n  exact reflle',\n  apply le's,\n  exact n_ih,\nend\n\nlemma l2 : \u2200 m n : \u2115, le' m n \u2192 le' (succ m) (succ n) :=\nbegin\n  assume m n h,\n  induction h,\n  {\n    exact reflle',\n  },\n  {\n    apply le's,\n    exact h_ih,\n  }\nend\n\nlemma l3 : \u2200 n : \u2115, le n n :=\nbegin\n  assume n,\n  induction n,\n  exact le0,\n  apply les,\n  exact n_ih,\nend\n\nlemma l4 : \u2200 m n : \u2115, le m n \u2192 le m (succ n) :=\nbegin\n  assume m n h,\n  induction h,\n  {\n    exact le0,\n  },\n  {\n    apply les,\n    exact h_ih,\n  }\nend\n\ntheorem equ {m n : \u2115} : le m n \u2194 le' m n :=\nbegin\n  constructor,\n  {\n    assume h,\n    induction h,\n    {\n      exact l1 h,\n    },\n    {\n      apply l2,\n      exact h_ih,\n    }\n  },\n  {\n    assume h,\n    induction h,\n    {\n      exact l3 h,\n    },\n    {\n      apply l4,\n      exact h_ih,\n    }\n  }\nend\n", "meta": {"author": "Filikec", "repo": "automaton-in-lean", "sha": "4f94b969f7780964f705fde2aa11d4085736cd7c", "save_path": "github-repos/lean/Filikec-automaton-in-lean", "path": "github-repos/lean/Filikec-automaton-in-lean/automaton-in-lean-4f94b969f7780964f705fde2aa11d4085736cd7c/src/induction_example.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7387484507486015}}
{"text": "import tactic --hide\n\n-- Level name : absorption laws pt 1\n\n/-\nThis level proves the first *absorption* law.\n-/\n\n/-Lemma\nIf $P,Q$ are logical statements then $P \u2227 (P \u2228 Q)$ is true if and only if $P$ is true.\n-/\nlemma absorption_one (P Q : Prop) : P \u2227 (P \u2228 Q) \u2194 P :=\nbegin\n  split,\n  intro h,\n  cases h with hP hPQ,\n  exact hP,\n  intro h,\n  split,\n  exact h,\n  left,\n  exact h,  \n\n\n  \nend\n", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic2/logical_ands2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7386959823318592}}
{"text": "import .prop_logic\n\n/-\nA logic is a \"formal language\" with\na mathematically defined syntax and a\nmathematically defined semantics. The\nsyntax of a language defines the set\nof legal expressions in the language\n(sometimes called formula, well-formed\nformula, sentences, etc). The semantics\nthen explains how to give a meaning to\neach such expression.\nIn this unit, we formalize the syntax\nand semantics of our first example of\na complete logic: a simple logic called\npropositional logic.\nThe *syntactic* terms of propositional\nlogic again fall in three categories:\n- there are two literal terms, which we\nwill call pTrue and pFalse\n- there are variable terms\n- and there are application terms, in\nwhich propositional logic connectives\nare applied to smaller terms to create\nlarger ones. These connectives are the\nfamiliar connectives of Boolean algebra:\nand (\u2227), or (\u2228), not (\u00ac), and so forth.\nExamples of propositional logic terms\nthus include:\n- pTrue             -- literal\n- pFalse            -- literal\n- and pTrue pFalse  -- application\n- X                 -- variable\n- Y                 -- variable\n- Z                 -- variable\n- X \u2228 Y             -- application: or X Y\n- (X \u2228 Y) \u2227 (X \u2227 Z) -- etc.\n- (X \u2228 Y) \u2227 (X \u2227 pTrue)\n- etc\nThe semantic domain of discourse, in which\nsuch expressions are given meaning, is the \nset of Boolean truth values, {true, false}.\nThe semantics of propositional logic assigns\na simple Boolean truth value to each such\npropositional logic expression. \nIn this unit, we will define \"eval\" to be\na function that takes an expressions and\nreturns its meaning as a Boolean value.\n(As we'll see shortly, the eval function\nwill have to take one more argument in\norder to deal with variable expressions).\nHere are the rules for how eval works:\nLITERAL TERMS\nTo the literal, pTrue, the semantic\n\"evaluation\" function assigns the truth\nvalue, true. To pFalse, it assigns the\ntruth value false. In other words, we\ndefine eval(pFalse) to be the bool, ff,\nand eval (pTrue) to be the bool, tt.\nVARIABLE TERMS\nTo evaluate a variable expression, such\nas X, or to evaluate an expression with\nseveral variables, such as X \u2227 Y, we need\nan addition piece of data: what Boolean\ntruth value each such variable has. \nWe call this data an *interpretation*.\nWe will represent it as a function, interp,\nfrom variables to Boolean truth values. \nThe semantic meaning of the syntactic\nvariable term, X, is then interp(X).\nI.e., eval(X) is defined as interp(X).\nThere are many possible interpretations \nfor a given (non-empty) set of variables.\nSelf-test: How many interpretations are\nthere for a single variable, X? How many\ninterpretations are possible for a set\nof variables {X_i} of size n?\nAPPLICATION TERMS\nApplication terms are built inductively\nby applying proposition logic connectives\nto smaller terms. For example, if e1 and\ne2 are terms (whether literal, variable,\nor application), then so are (and e1 e2),\n(or e1 e2), (not e1), etc.\nOur intention is that the semantics of \nsuch syntactic terms should reflect the\nusual Boolean algebraic meaning of the\nconnectives. So, for example, if e1 and \ne2 are expressions, then so is (and e1 \ne2), and we wish to evaluate this as\ntrue if and only if both e1 and e2\nevaluate to true.\nWe thus define eval to work recursively\non such expressions. We evaluate the truth\nof e1 and of e2 and then apply the *bool*\nand operator (as distinct from the and\nlogical connective) to the results to\ndetermine the truth value of (and e1 e2).\n-/\n\nopen prop_logic\nopen prop_logic.var\nopen prop_logic.unOp\nopen prop_logic.binOp\nopen prop_logic.pExp\n\n\n/-\n    **************\n    *** SYNTAX ***\n    **************\n-/\n\n\n-- Variables\n\n#check mkVar\n#check mkVar 0\n#check mkVar 1\n#check mkVar 2\n#check mkVar 3\n\n\n-- names for a few\ndef varX := mkVar 0\ndef varY := mkVar 1\ndef varZ := mkVar 2\n\n\n-- Operators (connectives)\n#check pNot     -- unary\n#check pAnd     -- binary\n#check pOr      -- binary\n\n\n-- Expressions\n\n-- Literal\n#check litExp ff\n#check litExp tt\n#check pFalse\n#check pTrue\n\n-- Variable\n#check varExp varX\n#check varExp varY\ndef X : pExp:= varExp varX\ndef Y : pExp := varExp varY\ndef Z : pExp := varExp varZ\n#check X\n#check Y\n\n-- Operator/application\n#check unOpExp notOp pTrue\n#check unOpExp notOp\n\n-- with shorthands\n#check pNot pTrue\n#check pNot X\n#check binOpExp andOp X Y\n#check binOpExp andOp\n#check pAnd X Y\n#check pOr X Y\n\n-- finally, logical expressions!\n#check pTrue\n#check \u00ac pTrue\n#check \u00ac pFalse\n#check X\n#check \u00ac X\n#check Y\n#check X \u2227 Y\n#check X \u2228 Y\n#check \u00ac (X \u2227 Y)\n#check \u00ac (X \u2227 Y) \u2228 (\u00ac X \u2228 \u00ac Y) \n\n/-\nYou have now defined the syntax of the\nformal language, propositional logic!\nYou can now check syntactic correctness\nof expressions.\n-/\n\n#check \u00ac (X \u2227 Y) \u2228 (X \u2228 Z) -- correct\n#check \u00ac (X \u2227 Y) \u2228 (X \u2228 )  -- error\n#check \u00ac X \u00ac Y             -- error\n#check pTrue pFalse        -- error\n\n\n/-\n    *****************\n    *** SEMANTICS ***\n    *****************\n-/\n\n-- Interpretations\n\ndef allFalse : var \u2192 bool\n| _ := ff\n\ndef allTrue : var \u2192 bool\n| _ := tt\n\ndef anInterp: var \u2192 bool \n  | (mkVar 0) := tt\n  | (mkVar 1) := ff\n  | (mkVar 2) := tt\n  | (mkVar _) := ff\n\n-- interpretation\n\n#eval allFalse varX\n#eval allTrue varX\n#eval anInterp varX\n#eval anInterp varY\n\n\n-- Interpretation of operators\n\n#check interpUnOp notOp \n#eval (interpUnOp notOp) tt \n#eval interpBinOp andOp tt ff\n#eval interpBinOp andOp tt tt\n\n-- evaluation of expressions\n\n#eval pEval pTrue allTrue\n#eval pEval pTrue allFalse\n#eval pEval X allTrue\n#eval pEval Y allFalse\n#eval pEval X anInterp\n#eval pEval Y anInterp\n#eval pEval (X \u2227 Y) allTrue\n#eval pEval (X \u2227 Y) allFalse\n#eval pEval (X \u2227 Y) anInterp\n#eval pEval (X \u2228 Y) anInterp\n#eval pEval (X \u2227 Z) anInterp\n#eval pEval (\u00ac (X \u2227 Z)) anInterp\n#eval pEval (\u00ac (X \u2227 Y) \u2228 (\u00ac X \u2228 \u00ac Y)) anInterp\n#eval pEval (\u00ac (X \u2227 Y) \u2228 (\u00ac X \u2228 \u00ac Y)) allTrue\n\n/-\nTo formalize a semantics for our\nrealization of propositional logic,\nwe need to formally define what we\nmean by an interpretation.\nAn interpretation in propositional \nlogic is a function from propositional\nvariables to corresponding (Boolean)\ntruth values. An interpretation tells\nus what each variable \"means\" -- i.e.,\nwhether it means true, or false. \nWe now define a name for the type\nof an interpretation (pVar \u2192 bool).\nThen we present several examples of\ninterpretations.\n-/\n\n-- Semantics\n\n/-\nWe now define a semantics for our\nlanguage in the form of a function\nthat, when given any expression in\nour language *and* an interpretation\nfor the variables that might appear\nin it, evaluates its truth value and\nreturns it as a result.\nThe definition is by cases, i.e., \nwith one rule for each possible form\n(constructor) of expression.\nNote: Lean \"overloads\" logical\noperator notations, such as \u2227, \u2228, \nand \u00ac. Here they are applied not to\nvalues of type Prop, but to values \nof type bool, where they have their\nusual means from Boolean algebra.\n-/\n\n/-\nAnd now we have a formal language, with\na syntax, interpretations, and semantics.\nLet's evaluate some of our expressions\nunder varying interpretations.\n-/\n\n\n/-\nSo there you have it: a complete\nformal definition of the syntax,\ninterpretation, and semantics of\npropositional logic, in Lean, with\na nice \"surface syntax,\" to boot.\n(Ok, it's complete except for the\ndefinitions for the other logical\nconnectives. You will add some of\nthem in homework and on the exam.)\n-/\n\n/-\nFrom here, we can define richer\nfunctions, such as functions that\nanalyze expressions; and we can\neven state and prove theorems \nabout our language.\n-/\n\n/-\nLet's define a function that \nreturns the set of variables \nin a given pExp. This will be\nuseful in the future.\n-/\n\n/-\nWe start by defining a recursive \nhelper function that adds all the \nvariables in given expression to \nthe given, often already non-empty, \nset of variables.\nUnderstand the type and purpose of\nthis function, then go on to read \nthe following main function. Study\nits purpose, type, and implementation,\nthen come back for a deeper look at \nhow this function is implemented.\nLearn to use functions knowing only\ntheir type and purpose, ignoring, at\nleast at first, their implementation\ndetails. Pratice mental abstracting.\nWe implement (prove) this recursive \nfunction (type) by case analysis on \npossible forms of the given pExp.\n-/\n/-\nMain function: a non-recursive function\nthat passes an initially empty set of\nvariables to the helper function and \nthen gets back a set of all, and only,\nthe variables in the given expression.\n-/\n/-\nExamples of its use\n-/\n#reduce vars_in_exp (X \u2227 Y)\n-- A predicate for set {X,Y}\n\n/-\nAnother example\n-/\n#reduce vars_in_exp (X \u2227 Z)\n\n/-\nEXERCISE: Write a function that when\ngiven an expression, e, returns the \n\"nesting depth\" of the expression. The\nnesting depth of a literal or variable\nexpression is 1. The depth of a (not e) \nexpression is 1 + the depth of e. And\nthe depth of an (and e1 e2) expression\nis 1 + the max of the depths of e1 and\ne2. You can use the Lean-provided max \nfunction in your answer.\n-/\n\n#reduce max 5 7\n#reduce max 7 5\n\n/-\nWe can also prove theorems about\nour language in general. Here's a\nproof that evaluation under a given\ninterpretation is \"deterministic:: \nit always produces the same result.\nThis is really just a corollary of\nthe facts that (1) functions in Lean \nare single valued and (2) we defined \nthe semantics of expressions with a\nfunction. There's one and only one \nanswer for the value of any given\nexpression.\n-/\n\ntheorem pEval_deterministic :\n\u2200 e : pExp, \n\u2200 i : pInterp,\n\u2200 v1 v2 : bool,\nv1 = pEval e i \u2192 v2 = pEval e i \u2192 v1 = v2 :=\nbegin\nintros e i v1 v2 h_v1 h_v2,\nrw h_v1, \nrw h_v2,\nend\n\n\n/-\nWe can also prove theorems (\"reason\nabout\") particular expressions, or\ncertain classes of expressions, in \nour language. For example, if X_exp \nis any variable expression, then the \nexpression (X_exp \u2227 (\u00ac X_exp)) is \nfalse under any interpretation. We\ncan easily prove this proposition.\n-/\n\ntheorem contra :\n\u2200 V : pVar,\n\u2200 i : pInterp,\npEval \n    ((mk_var_pexp V) \u2227 \u00ac (mk_var_pexp V)) i = ff \n:=\nbegin\nintros X i,\nsimp [pEval],\n-- case analysis on result of function!\ncases (i X),\nleft, apply rfl,\nright, apply rfl,\nend\n\n/-\nNote that it is quantified over all\npossible interpretations: over all\npossible functions from pVar \u2192 bool.\nLean supports what is called higher\norder predicate logic. Quantifying\nover functions and relations is ok\nin a higher-order predicate logic. \nIt is not allowed in the first-order\npredicate logic of everyday math and\ncomputer science. Here you can see\nthat it gives you great expressive\npower to be able to quantify over\nfunctions. It gives us a way to say,\n\"under any possible interpretation\",\nwhich is exactly what we need to be\nable to say to define satisfiability,\nvalidity, unsatisfiability, etc.\n-/\n\n\n\n/-\nExercise: Prove that for any \nvariable, V, the logical expression\n(mk_var_exp V) \u2228 (\u00ac (mk_var_exp V))\nalways evaluates to true.\n-/\n\ndef valid (e : pExp) : Prop :=\n    \u2200 i : pInterp, pEval e i = tt\n\n/-\nAn expression in propositional logic\nis unsatisfiable if it does'ot evaluate \nto true under any interpretation.\n-/\n\ndef unsatisfiable (e : pExp) : Prop :=\n    \u2200 i, pEval e i = ff\n\n/-\nYou could also have said there does not\nexist an i that makes (pEval e i) = tt.\n-/\n\n/-\nAn interpretation that makes an\nexpression, e, evaluate to true,\nis said to be a \"model\" of that\nexpression. Here's a predicate\nasserting that i is a model of e.\n-/\n\ndef isModel (i: pInterp) (e : pExp) :=\n    pEval e i = tt\n\n/-\nAn expression is said to be satisfiable \nif there is at least one interpretation \nunder which it evaluates to true.\n-/\ndef satisfiable (e : pExp) : Prop :=\n    \u2203 i, isModel i e\n\n/-\nExample: X \u2227 \u00ac X is unsatisfiable.\n-/\n\nexample : unsatisfiable (X_exp \u2227 (\u00ac (X_exp))) :=\nbegin\nunfold unsatisfiable,\nintro i,\nrw pEval, -- you can do this\nrw pEval, -- and do it again\ncases (pEval X_exp i), -- cool!\ntrivial,\ntrivial,\nend\n\n/-\nEXERCISE: Once you've extended\nour logic with an or operator,\nformulize and prove the proposition\nthat (our rendering of) X \u2228 (\u00ac X)\nis valid.\nEXERCISE: Prove the proposition\nthat (X \u2228 Y) \u2227 Z is satisfiable.\nHint: You'll need a witness. There\nis an element of search involved\nin solving a problem like this.\n-/\n\n/-\nEXERCISE: Write a SAT solver based\non what we've done here.\n-/\n\n-- m'th bit from right in binary rep of n\ndef mrbn: \u2115 \u2192 \u2115 \u2192 bool \n| 0 n := n % 2 = 1\n| (nat.succ m') n := mrbn m' (n/2) \n\n/- smoke test\n#reduce mrbn 0 15\n#reduce mrbn 2 15\n#reduce mrbn 2 15\n#reduce mrbn 3 15\n#reduce mrbn 4 15\n#reduce mrbn 5 15\n-/\n\n/-\nThe mth canonical interpretation\namong the 2^n-1 interpretations\nfor a set of variables of size n.\nThe values of the first n-indexed\nvariables in the mth interpretation\nare determined by the bits in the \nbinary representation of m. The\nleftmost bit gives the value for \nthe variable with index 0. Each\nbit to the left gives the value of\nthe next indexed variable. All \nsubsequent values are ff. m thus \neffectively enumerates the 2^n \ninterpretations on the n first \nvariables in the index set of all\nvariables. \n-/\n\ndef mthInterpOf2toN (m n: \u2115) : pInterp :=\n    if (m >= 2^n)\n    then falseInterp \n    else\n    \u03bb v : pVar, \n        match v with\n        | (pVar.mk i) := \n        if i >= n then \n        ff \n        else \n        (mrbn i m)\n        end\n\n/-\nExamples:\n-/\n\n#reduce pEval and_X_Y_exp (mthInterpOf2toN 3 3)\n\n-- unincorporated\n\n#reduce mthInterpOf2toN 3 5\n\ndef first_n_true_inter (n : \u2115) : pInterp :=\n\u03bb v, \n    match v with\n    | (pVar.mk n') := if n' < n then tt else ff\n    end\n\ndef all_models (e : pExp) :=\n    { m | isModel m e}\n\n\ndef sat_solve (e : pExp) : option pInterp :=\nnone", "meta": {"author": "yl4df", "repo": "Discrete-Mathematics", "sha": "c93ce9f6a6e36d194e350d9fa0a0360191e97fa0", "save_path": "github-repos/lean/yl4df-Discrete-Mathematics", "path": "github-repos/lean/yl4df-Discrete-Mathematics/Discrete-Mathematics-c93ce9f6a6e36d194e350d9fa0a0360191e97fa0/notes/2019.10.14.prop_logic/prop_logic_test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7386959814289981}}
{"text": "import tactic.basic\n\n/-\nIt's time to learn about universes!\n\nThis assignment is hopefully fairly quick, but will walk you through the\nuniverse polymorphism issues involved in defining categories in Lean.\n-/\n\n-- Here's a simple attempt at defining a category.\n-- The parameter `C` describes the objects of the category.\nclass category (C : Type) :=\n(hom : C \u2192 C \u2192 Type)\n(id : \u03a0 X : C, hom X X)\n(comp : \u03a0 {X Y Z : C}, hom X Y \u2192 hom Y Z \u2192 hom X Z)\n(comp_id : \u03a0 {X Y : C} (f : hom X Y), comp f (id Y) = f)\n(id_comp : \u03a0 {X Y : C} (f : hom X Y), comp (id X) f = f)\n(assoc : \u03a0 {W X Y Z : C} (f : hom W X) (g : hom X Y) (h : hom Y Z), comp (comp f g) h = comp f (comp g h))\n\n-- However, this definition is no good: we can't define the category of types:\ninstance category_of_types_broken : category Type :=\n{ hom := \u03bb X Y, X \u2192 Y }\n\n-- To fix this, you're going to need to modify the definition above,\n-- to fix the universe levels.\n\n-- Question 0: Explain why the definition above wasn't useful, perhaps\n-- mentioning Russell's paradox.\n\n/- Answer: Because of the hierarchy of the universes, Type cannot be of type Type. \nInstead, it must be of Type 1 (otherwise, we would have an analogue of Russell's Paradox:\nthe set of all sets being an element of itself). In a dependent type theory context,\nthis means that nothing can be of Type itself, which is implemented by setting Type to be of\nType 1, Type 1 of Type 2 etc. This is not reflected in the definition,\nas the universe level of the category above is fixed. It should instead be polymorphic, so\nthat elements belonging to higher universe levels can be made into categories.\n\nOne possible solution to this would be to change Type to Type 1 (at the very least, this would\nallow the category of types to be defined. However, we would then have an identical problem to\nthe one above when we tried to create a category for a type in a universe level higher\nthan 1).\n-/\n\n-- Here's one attempt:\n\nclass category_1 (C : Type 1) :=\n(hom : C \u2192 C \u2192 Type)\n(id : \u03a0 X : C, hom X X)\n(comp : \u03a0 {X Y Z : C}, hom X Y \u2192 hom Y Z \u2192 hom X Z)\n(comp_id : \u03a0 {X Y : C} (f : hom X Y), comp f (id Y) = f)\n(id_comp : \u03a0 {X Y : C} (f : hom X Y), comp (id X) f = f)\n(assoc : \u03a0 {W X Y Z : C} (f : hom W X) (g : hom X Y) (h : hom Y Z), comp (comp f g) h = comp f (comp g h))\n\n-- Question 1: fill in the remaining fields of this definition.\ninstance category_of_types : category_1 Type :=\n{ hom := \u03bb X Y, X \u2192 Y,\n  id := \u03bb X, \u03bb x, x,\n  comp := \u03bb X Y Z, \u03bb f g, \u03bb x, g (f x),\n  comp_id := by {intros X Y f, simp},\n  id_comp := by {intros X Y f, simp},\n  assoc := by {intros W X Y Z f g h, simp}\n}\n\n-- However, this variant has its own problems. A standard solution to Russell's\n-- paradox about \"the set of all sets\" (resolved in Lean's dependent type theory\n-- by the typing judgement `Type : Type 1`) is to consider all subsets of some\n-- fixed 'big' set, rather than \"all sets\".\n\n-- Question 2: Decide whether `C` below should be `category` or `category_1`,\n-- and fill in the remaining fields.\ninstance category_of_subsets (X : Type) : category (set X) :=\n{ hom := \u03bb P Q, { x // P x } \u2192 { x // Q x },\n  id := \u03bb P, \u03bb x, x,\n  comp := \u03bb P Q R, \u03bb p q, \u03bb x, q (p x),\n  comp_id := by {intros P Q f, simp},\n  id_comp := by {intros P Q f, simp},\n  assoc := by {intros P Q R f g h, simp}\n}\n\n-- We've now got a conundrum: for some reasonable examples, we want the\n-- objects and morphisms to live in the same universe, while for other\n-- examples we want the objects to live one universe level higher than\n-- the morphisms.\n\n-- In ZFC based category theory, these two variants of the notion of a category\n-- are called \"small categories\" and \"large categories\".\n\n-- Rather than duplicate everything we want to prove about categories\n-- (or worse: we'll need to worry about four different sorts of functors,\n-- as the source and target categories could individually be small or large!)\n-- in the mathlib category theory library we've made a \"universe polymorphic\"\n-- definition, which is essentially this one:\n\nuniverses v u\n\nclass pcategory (C : Type u) :=\n(hom : C \u2192 C \u2192 Type v)\n(id : \u03a0 X : C, hom X X)\n(comp : \u03a0 {X Y Z : C}, hom X Y \u2192 hom Y Z \u2192 hom X Z)\n(comp_id : \u03a0 {X Y : C} (f : hom X Y), comp f (id Y) = f)\n(id_comp : \u03a0 {X Y : C} (f : hom X Y), comp (id X) f = f)\n(assoc : \u03a0 {W X Y Z : C} (f : hom W X) (g : hom X Y) (h : hom Y Z), comp (comp f g) h = comp f (comp g h))\n\n-- Question 3:\n-- Work out the appropriate values of the universe parameters `p`, `q`, `r`, `s`\n-- below, and then verify that the same fields you used above can be used to\n-- complete the following two definitions:\n-- (Hint: substitute fixed large values, like p=5, q=10, and read the error messages...)\ninstance category_of_types' : pcategory.{0 1} Type :=\n{ hom := \u03bb X Y, X \u2192 Y,\n  id := \u03bb X, \u03bb x, x,\n  comp := \u03bb X Y Z, \u03bb f g, \u03bb x, g (f x),\n  comp_id := by {intros X Y f, simp},\n  id_comp := by {intros X Y f, simp},\n  assoc := by {intros W X Y Z f g h, simp}\n}\n\ninstance category_of_subsets' (X : Type) : pcategory.{0 0} (set X) :=\n{ hom := \u03bb P Q, { x // P x } \u2192 { x // Q x },\n  id := \u03bb P, \u03bb x, x,\n  comp := \u03bb P Q R, \u03bb p q, \u03bb x, q (p x),\n  comp_id := by {intros P Q f, simp},\n  id_comp := by {intros P Q f, simp},\n  assoc := by {intros P Q R f g h, simp}\n}\n\n-- Question 4:\n-- Complete the following definitions:\nuniverses v\u2081 u\u2081 v\u2082 u\u2082\n\nstructure Functor (C : Type u\u2081) [pcategory.{v\u2081 u\u2081} C] (D : Type u\u2082) [pcategory.{v\u2082 u\u2082} D] :=\n(obj : C \u2192 D)\n(map : \u03a0 {X Y : C}, pcategory.hom X Y \u2192 pcategory.hom (obj X) (obj Y))\n(id_map : \u03a0 X : C, map (pcategory.id X) = pcategory.id (obj X))\n(map_comp : \u03a0 X Y Z : C, \u03a0 f : pcategory.hom X Y, \u03a0 g : pcategory.hom Y Z, map (pcategory.comp f g) = pcategory.comp (map f) (map g))\n-- Hint: there are two missing fields here, giving the axioms for functors.\n\ndef List : Functor Type Type :=\n{ obj := \u03bb \u03b1, list \u03b1,\n  map := \u03bb \u03b1 \u03b2 : Type, \u03bb f : pcategory.hom \u03b1 \u03b2, \u03bb L, list.map f L,\n  id_map := by {intros X, dsimp [pcategory.id], funext, induction x, simp, dsimp [list.map], rw [x_ih]},\n  map_comp := by {intros X Y Z f g, simp, funext, dsimp [pcategory.comp], induction x,\n                  simp, dsimp [list.map], rw [x_ih],}}\n\n-- Question 5:\n-- Complete the following definitions:\n\nstructure NaturalTransformation\n  {C : Type u\u2081} [pcategory.{v\u2081 u\u2081} C] {D : Type u\u2082} [pcategory.{v\u2082 u\u2082} D]\n  (F G : Functor C D) :=\n(app : \u03a0 X : C, pcategory.hom (F.obj X) (G.obj X))\n(naturality : \u03a0 X Y : C, \u03a0 f : pcategory.hom X Y, pcategory.comp (F.map f) (app Y) = pcategory.comp (app X) (G.map f))\n\nnamespace NaturalTransformation\ndef id\n  {C : Type u\u2081} [pcategory.{v\u2081 u\u2081} C] {D : Type u\u2082} [pcategory.{v\u2082 u\u2082} D]\n  (F : Functor C D) : NaturalTransformation F F :=\n{app := \u03bb X : C, pcategory.id (F.obj X), \n naturality := by {intros X Y f, rw [pcategory.comp_id, pcategory.id_comp]}}\n\ndef comp\n  {C : Type u\u2081} [pcategory.{v\u2081 u\u2081} C] {D : Type u\u2082} [pcategory.{v\u2082 u\u2082} D]\n  {F G H : Functor C D}\n  (\u03b1 : NaturalTransformation F G) (\u03b2 : NaturalTransformation G H) : NaturalTransformation F H :=\n{app := \u03bb X : C, pcategory.comp (\u03b1.app X) (\u03b2.app X), \n naturality := by {intros X Y f, rw [\u2190pcategory.assoc, \u03b1.naturality, pcategory.assoc, pcategory.assoc],\n apply congr_arg, rw [\u03b2.naturality]}}\n\n@[extensionality] lemma Natural_ext\n{C : Type u\u2081} [pcategory.{v\u2081 u\u2081} C] {D : Type u\u2082} [pcategory.{v\u2082 u\u2082} D] \n{F G : Functor C D} {N M : NaturalTransformation F G} :\n(\u03a0 X : C, N.app X = M.app X) \u2192 N = M :=\nbegin\n  intros h,\n  induction N,\n  induction M,\n  simp at h,\n  simp [h],\n  funext,\n  exact h x,\nend\n\n@[simp] lemma id_app\n{C : Type u\u2081} [pcategory.{v\u2081 u\u2081} C] {D : Type u\u2082} [pcategory.{v\u2082 u\u2082} D] {F : Functor C D} :\n(id F).app = \u03bb X : C, pcategory.id (F.obj X) := rfl\n\n-- Hint: you may find `conv` helpful.\nend NaturalTransformation\n\n-- Here's the crux of the whole assignment: understand what the correct values\n-- of `p` and `q` are in this definition, then complete the definition.\n-- Hint: you may like to prove an extensionality lemma for natural transformations,\n-- and appropriate simp lemmas.\ninstance {C : Type u\u2081} [pcategory.{v\u2081 u\u2081} C] {D : Type u\u2082} [pcategory.{v\u2082 u\u2082} D] :\n  pcategory.{(max u\u2081 v\u2082) (max u\u2081 u\u2082 v\u2081 v\u2082)} (Functor C D) :=\n{ hom := \u03bb F G, NaturalTransformation F G ,\n  id := NaturalTransformation.id, \n  comp := \u03bb F G H, NaturalTransformation.comp,\n  comp_id := by {intros F G N, ext X, dsimp [NaturalTransformation.comp], rw [pcategory.comp_id]},\n  id_comp := by {intros F G N, ext X, dsimp [NaturalTransformation.comp], rw [pcategory.id_comp]},\n  assoc := by {intros F G H I N M O, ext X, dsimp [NaturalTransformation.comp], rw [pcategory.assoc]}\n}\n\nconstant C : Type u\u2081\nconstant D : Type u\u2082\nvariables [C_cat : pcategory.{v\u2081 u\u2081} C] [D_cat : pcategory.{v\u2082 u\u2082} D]\nvariables F G : @Functor C C_cat D D_cat\nconstant N : NaturalTransformation F G\n\nset_option pp.universes true\n#check @Functor C C_cat D D_cat -- Type (max u\u2081 u\u2082 v\u2081 v\u2082)\n#check @NaturalTransformation C C_cat D D_cat F G -- Type (max u\u2081 v\u2082)\n\n-- Question 6:\n-- What universe does `NaturalTransformation F G` live in? Why?\n-- Hint: a really good answer will use the word 'impredicativity' somewhere\n-- along the way.\n\n/- Answer: NaturalTransformation F G lives in the universe 'max (u\u2081 v\u2082)'. \n  We begin by noting that Functor C D is of type Type max (u\u2081 u\u2082 v\u2081 v\u2082).\n  This is because the field obj has type Type (max u\u2081 u\u2082) (because C : Type u\u2081\n  and D : Type u\u2082 and so) and the field map has type Type (max v\u2081 v\u2082) (because \n  the morphisms in the category of C live in the universe v\u2081,  and the morphisms \n  in the category of D live in the universe v\u2082). \n  \n  The other fields are of type Prop = Sort 0 : Type 0, because they are functions from some type\n  into Prop. Impredicativity means that regardless of the universe level\n  of the domain, the type of this will always be Type 0. We want this feature\n  in our universe levels in Lean because we can interpret a function f : A \u2192 B for some\n  types A : Type u and B : Prop by the statement \"given some element of A, I can give you an\n  element of B\". In the case where B : Prop, an element of B is a proof of B and so f : A \u2192 Prop\n  represents the statement \"if A has an element then B\", so f is itself a proposition (and hence\n  of type Prop), even if this is a lower universe level than A.\n  \n  All of these facts together mean that Functor C D is of type\n  Type max (max u\u2081 u\u2082) (max v\u2081 v\u2082) = Type max (u\u2081 u\u2082 v\u2081 v\u2082). \n  [Note : I realised after I had written this that the universe level of Functor does not affect \n   the universe level of NaturalTransformation. However, the explanation about impredicativity above \n   is still used below when we discuss why the field naturality of NaturalTransformation does not \n   affect its universe level, so I left it in.]\n\n  We can now apply the same reasoning as above to determine the universe level of \n  NaturalTransformation. Because naturality is a Prop, it will not affect the universe level of \n  NaturalTransformation (once again by impredicativity), so it suffices to determine the universe \n  level of app. pcategory.hom (F.obj X) (G.obj X) is a morphism in the category D and so is of type \n  Type v\u2082. Because X : C, app is a function from something of type Type u\u2081 to something of type \n  Type v\u2082 and so its type is Type (max u\u2081 v\u2082) (meaning it lives in the universe level max (u\u2081 v\u2082)).\n  Then NaturalTransformation has the same universe level as app and so lives in the universe level\n  max (u\u2081 v\u2082).\n-/\n", "meta": {"author": "MartinSkilleter", "repo": "real_ip_spaces", "sha": "1ad1e0456602038711cbb0de7aa92b88d6eff06f", "save_path": "github-repos/lean/MartinSkilleter-real_ip_spaces", "path": "github-repos/lean/MartinSkilleter-real_ip_spaces/real_ip_spaces-1ad1e0456602038711cbb0de7aa92b88d6eff06f/src/Assignment 4/category.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.7386857134257516}}
{"text": "/-\nDefines a notion of getting two distinct indexes from a list.\n\nAuthors: Cayden Codel\nCarnegie Mellon University\n-/\n\nimport basic\n\nimport data.list.basic\nimport data.nat.basic\nimport tactic\n\nnamespace distinct\n\nopen list\nopen nat\n\ndef distinct {\u03b1 : Type*} (a\u2081 a\u2082 : \u03b1) (l : list \u03b1) :=\n  \u2203 (i j : nat) (Hi : i < l.length) (Hj : j < l.length), \n  i < j \u2227 l.nth_le i Hi = a\u2081 \u2227 l.nth_le j Hj = a\u2082\n\ntheorem not_distinct_nil {\u03b1 : Type*} (a\u2081 a\u2082 : \u03b1) : \u00acdistinct a\u2081 a\u2082 [] :=\nbegin\n  rintro \u27e8i, _, hi, _, _\u27e9,\n  rw length at hi,\n  linarith\nend\n\ntheorem not_distinct_singleton {\u03b1 : Type*} (a\u2081 a\u2082 a\u2083 : \u03b1) : \u00acdistinct a\u2081 a\u2082 [a\u2083] :=\nbegin\n  rintro \u27e8i, j, _, hj, hij, _\u27e9,\n  have := gt_of_gt_of_ge hij (zero_le i),\n  rw [length, length] at hj,\n  linarith\nend\n\ntheorem distinct_double {\u03b1 : Type*} (a\u2081 a\u2082 : \u03b1) : distinct a\u2081 a\u2082 [a\u2081, a\u2082] :=\nby { use [0, 1], simp }\n\ntheorem eq_of_distinct_double {\u03b1 : Type*} {a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1} :\n  distinct a\u2081 a\u2082 [b\u2081, b\u2082] \u2192 a\u2081 = b\u2081 \u2227 a\u2082 = b\u2082 :=\nbegin\n  rintros \u27e8i, j, hi, hj, hij, hil, hjl\u27e9,\n  cases i,\n  { rcases nth_le_of_ge hj (succ_le_iff.mpr hij) with \u27e8h\u2081, h\u2082\u27e9,\n    rw [hjl, nth_le, nth_le_singleton] at h\u2082,\n    rw nth_le at hil,\n    exact \u27e8hil.symm, h\u2082\u27e9 },\n  { simp [length] at hj,\n    have : 1 \u2264 i + 1, exact le_add_self,\n    have := gt_of_gt_of_ge hij this,\n    linarith }\nend\n\ntheorem length_ge_two_of_distinct {\u03b1 : Type*} {a\u2081 a\u2082 : \u03b1} {l : list \u03b1} :\n  distinct a\u2081 a\u2082 l \u2192 length l \u2265 2 :=\nbegin\n  rintros \u27e8i, j, _, Hj, hij, _, _\u27e9,\n  have : 1 \u2264 j, exact succ_le_iff.mpr (pos_of_gt hij),\n  have : 1 < length l, exact gt_of_gt_of_ge Hj this,\n  exact succ_le_iff.mpr this\nend\n\ntheorem exists_distinct_of_length_ge_two {\u03b1 : Type*} {l : list \u03b1} :\n  length l \u2265 2 \u2192 \u2203 {a\u2081 a\u2082 : \u03b1}, distinct a\u2081 a\u2082 l :=\nbegin\n  intro hl,\n  rcases exists_cons_cons_of_length_ge_two hl with \u27e8a\u2081, a\u2082, as, rfl\u27e9,\n  use [a\u2081, a\u2082, 0, 1], simp\nend\n\ntheorem distinct_cons_of_mem {\u03b1 : Type*} (a\u2081 : \u03b1) {a\u2082 : \u03b1} {l : list \u03b1} :\n  a\u2082 \u2208 l \u2192 distinct a\u2081 a\u2082 (a\u2081 :: l) :=\nbegin\n  intro h,\n  rcases mem_iff_nth_le.mp h with \u27e8n, hlen, hn\u27e9,\n  have hi : 0 < length (a\u2081 :: l), simp,\n  have hj : n + 1 < length (a\u2081 :: l), \n    by { rw [length, succ_lt_succ_iff], exact hlen },\n  use [0, n + 1, hi, hj],\n  simp [\u2190 hn],\n  refl\nend\n\ntheorem distinct_cons_of_distinct {\u03b1 : Type*} {a\u2081 a\u2082 : \u03b1} {l : list \u03b1} (a : \u03b1) :\n  distinct a\u2081 a\u2082 l \u2192 distinct a\u2081 a\u2082 (a :: l) :=\nbegin\n  rintros \u27e8i, j, hi, hj, hij, hil, hjl\u27e9,\n  have hi\u2082 : i + 1 < (a :: l).length,\n  { simp only [hi, length, add_lt_add_iff_right] },\n  have hj\u2082 : j + 1 < (a :: l).length,\n  { simp only [hj, length, add_lt_add_iff_right] },\n  use [i + 1, j + 1, hi\u2082, hj\u2082, succ_lt_succ hij],\n  rw [nth_le, nth_le],\n  exact \u27e8hil, hjl\u27e9\nend\n\ntheorem distinct_of_distinct_cons_of_ne {\u03b1 : Type*} {a\u2081 a\u2082 a : \u03b1} {l : list \u03b1} :\n  distinct a\u2081 a\u2082 (a :: l) \u2192 a\u2081 \u2260 a \u2192 distinct a\u2081 a\u2082 l :=\nbegin\n  rintros \u27e8i, j, hi, hj, hij, hil, hjl\u27e9 hne,\n  cases i,\n  { rw nth_le at hil, exact absurd hil.symm hne },\n  { rw length at hi,\n    have := succ_le_iff.mpr ((gt_of_gt_of_ge hij (zero_le i.succ))),\n    rcases nth_le_of_ge hj this with \u27e8hjm, hnth\u27e9,\n    rw [\u2190 nat.sub_add_cancel this, length] at hj,\n    rw \u2190 nat.sub_add_cancel this at hij,\n    use [i, j - 1, succ_lt_succ_iff.mp hi, succ_lt_succ_iff.mp hj,\n      succ_lt_succ_iff.mp hij],\n    rw [\u2190 hil, \u2190 hjl, hnth, nth_le, nth_le],\n    exact \u27e8rfl, rfl\u27e9 }\nend\n\ntheorem eq_or_distinct_of_distinct_cons {\u03b1 : Type*} {a\u2081 a\u2082 a : \u03b1} {l : list \u03b1} :\n  distinct a\u2081 a\u2082 (a :: l) \u2192 a\u2081 = a \u2228 distinct a\u2081 a\u2082 l :=\nbegin\n  intro hdis,\n  by_cases h : (a\u2081 = a),\n  { exact or.inl h },\n  { exact or.inr (distinct_of_distinct_cons_of_ne hdis h) }\nend\n\ntheorem mem_tail_of_distinct_cons {\u03b1 : Type*} {a\u2081 a\u2082 a : \u03b1} {as : list \u03b1} :\n  distinct a\u2081 a\u2082 (a :: as) \u2192 a\u2082 \u2208 as :=\nbegin\n  rintro \u27e8i, j, Hi, Hj, hij, hil, hjl\u27e9,\n  have := succ_le_iff.mpr ((gt_of_gt_of_ge hij (zero_le i))),\n  rcases (nth_le_of_ge Hj this) with \u27e8Hj\u2082, hnth\u27e9,\n  rw hjl at hnth,\n  rw [hnth, nth_le],\n  exact nth_le_mem as _ _\nend\n\ntheorem distinct_sublist {\u03b1 : Type*} {a\u2081 a\u2082 : \u03b1} {l\u2081 l\u2082 : list \u03b1} :\n  l\u2081 <+ l\u2082 \u2192 distinct a\u2081 a\u2082 l\u2081 \u2192 distinct a\u2081 a\u2082 l\u2082 :=\nbegin\n  induction l\u2082 with a as ih generalizing l\u2081,\n  { rw sublist_nil_iff_eq_nil, rintro rfl, exact id },\n  { intros hl\u2081 hdis,\n    cases hl\u2081,\n    { exact distinct_cons_of_distinct a (ih hl\u2081_\u1fb0 hdis) },\n    { by_cases ha : (a\u2081 = a),\n      { have := (sublist.subset hl\u2081_\u1fb0) (mem_tail_of_distinct_cons hdis),\n        rcases mem_iff_nth_le.mp this with \u27e8n, hn\u2081, hn\u2082\u27e9,\n        have Hi : 0 < (a :: as).length, by dec_trivial,\n        have Hj : n + 1 < (a :: as).length,\n        { rw length, exact succ_lt_succ_iff.mpr hn\u2081 },\n        use [0, n + 1, Hi, Hj],\n        simp [ha],\n        rw \u2190 hn\u2082,\n        refl },\n      { have := distinct_of_distinct_cons_of_ne hdis ha,\n        exact distinct_cons_of_distinct a (ih hl\u2081_\u1fb0 this) } } }\nend\n\n-- TODO way to do in a non-tactic way?\ntheorem mem_of_distinct_left {\u03b1 : Type*} {a\u2081 a\u2082 : \u03b1} {l : list \u03b1} :\n  distinct a\u2081 a\u2082 l \u2192 a\u2081 \u2208 l :=\nbegin\n  rintro \u27e8i, _, hi, _, _, hil, _\u27e9,\n  rw \u2190 hil, exact nth_le_mem l _ _\nend\n\n-- TODO this too\ntheorem mem_of_distinct_right {\u03b1 : Type*} {a\u2081 a\u2082 : \u03b1} {l : list \u03b1} :\n  distinct a\u2081 a\u2082 l \u2192 a\u2082 \u2208 l :=\nbegin\n  rintro \u27e8_, j, _, hj, _, _, hjl\u27e9,\n  rw \u2190 hjl, exact nth_le_mem l _ _\nend\n\ntheorem countp_ge_two_of_distinct_of_pos {\u03b1 : Type*} {a\u2081 a\u2082 : \u03b1}\n  {p : \u03b1 \u2192 Prop} [decidable_pred p] (h\u2081 : p a\u2081) (h\u2082 : p a\u2082) :\n  \u2200 {l : list \u03b1}, distinct a\u2081 a\u2082 l \u2192 countp p l \u2265 2\n| [] hdis := absurd hdis (not_distinct_nil _ _)\n| [a] hdis := absurd hdis (not_distinct_singleton _ _ _)\n| (a :: b :: bs) hdis := begin\n  have hmem := mem_tail_of_distinct_cons hdis,\n  rcases hdis with \u27e8i, j, hi, hj, hij, hil, hjl\u27e9,\n  cases i,\n  { rw nth_le at hil,\n    rw [hil, countp_cons_of_pos p (b :: bs) h\u2081],\n    apply succ_le_succ_iff.mpr,\n    apply succ_le_iff.mpr,\n    apply (countp_pos p).mpr,\n    use [a\u2082, hmem, h\u2082] },\n  { cases j,\n    { linarith },\n    { have : distinct a\u2081 a\u2082 (b :: bs),\n      { rw [length, succ_lt_succ_iff] at hi hj,\n        rw succ_lt_succ_iff at hij,\n        rw nth_le at hil hjl,\n        use [i, j, hi, hj, hij, hil, hjl] },\n      have ih := countp_ge_two_of_distinct_of_pos this,\n      exact le_trans ih (sublist.countp_le p (sublist_cons a (b :: bs))) } }\nend\n\nend distinct", "meta": {"author": "chasenorman", "repo": "verified-encodings-social-choice", "sha": "72f88c5a31ce30df5a04a99f726244c327b9a6f6", "save_path": "github-repos/lean/chasenorman-verified-encodings-social-choice", "path": "github-repos/lean/chasenorman-verified-encodings-social-choice/verified-encodings-social-choice-72f88c5a31ce30df5a04a99f726244c327b9a6f6/src/cardinality/distinct.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8311430478583169, "lm_q1q2_score": 0.7386856948831262}}
{"text": "/-\nCopyright (c) 2017 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Robert Y. Lewis\n-/\n\nimport mathematica\nimport data.real.basic\nopen expr tactic nat mmexpr\n\n/--\n`factor e nm` takes an expression representing a polynomial, like `` `(x^2-1)``.\nIt gets translated to Mathematica, factored, and reconstructed.\nThe `ring` tactic is called to prove that the input `e` is equal to the result,\nand this equality is added to the context as a hypothesis with name `nm`.\n-/\nmeta def factor (e : expr) (nm : option name) : tactic unit :=\ndo t \u2190 mathematica.run_command_on (\u03bb s, s ++\" // LeanForm // Activate // Factor\") e,\n   ts \u2190 to_expr t,\n   (_, pf) \u2190 to_expr ``(%%e = %%ts) >>= \u03bb tgt, solve_aux tgt `[ring, done],\n   match nm with\n   | some n := note n none pf >> skip\n   | none := do n \u2190 get_unused_name `h none, note n none pf, skip\n   end\n\nnamespace tactic\nnamespace interactive\n\nsetup_tactic_parser\n\nmeta def factor (e : parse texpr) (nm : parse using_ident) : tactic unit :=\ndo e' \u2190 i_to_expr e,\n   _root_.factor e' nm\n\nend interactive\nend tactic\n\n/-\nIn these first two examples we prove that polynomials are nonnegative\nby factoring them into squares.\n-/\nexample (x : \u211d) : 1 - 2*x + 3*x^2 - 2*x^3 + x^4 \u2265 0 :=\nbegin\n factor  1 - 2*x + 3*x^2 - 2*x^3 + x^4  using h,\n rewrite h,\n apply pow_two_nonneg\nend\n\nexample (x : \u211d) : x^2-2*x+1 \u2265 0 :=\nbegin\nfactor x^2-2*x+1 using q,\nrewrite q,\napply pow_two_nonneg\nend\n\n/-\nHere we factor a larger polynomial and trace the state afterward:\n\nx y : \u211d,\nh :\n  x ^ 10 - y ^ 10 =\n    (x + (-1) * y) * (x + y) * (x ^ 4 + (-1) * x ^ 3 * y + x ^ 2 * y ^ 2 + (-1) * x * y ^ 3 + y ^ 4) *\n      (x ^ 4 + x ^ 3 * y + x ^ 2 * y ^ 2 + x * y ^ 3 + y ^ 4)\n\u22a2 true\n-/\nexample (x y : \u211d) : true :=\nbegin\nfactor (x^10-y^10),\ntrace_state,\ntriv\nend\n", "meta": {"author": "robertylewis", "repo": "mathematica_examples", "sha": "e317381c49db032accef2a92e7650d029952ad76", "save_path": "github-repos/lean/robertylewis-mathematica_examples", "path": "github-repos/lean/robertylewis-mathematica_examples/mathematica_examples-e317381c49db032accef2a92e7650d029952ad76/src/factor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7386856838190412}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.calculus.mean_value\nimport analysis.special_functions.pow_deriv\n\n/-!\n# Collection of convex functions\n\nIn this file we prove that the following functions are convex:\n\n* `strict_convex_on_exp` : The exponential function is strictly convex.\n* `even.convex_on_pow`, `even.strict_convex_on_pow` : For an even `n : \u2115`, `\u03bb x, x ^ n` is convex\n  and strictly convex when `2 \u2264 n`.\n* `convex_on_pow`, `strict_convex_on_pow` : For `n : \u2115`, `\u03bb x, x ^ n` is convex on $[0, +\u221e)$ and\n  strictly convex when `2 \u2264 n`.\n* `convex_on_zpow`, `strict_convex_on_zpow` : For `m : \u2124`, `\u03bb x, x ^ m` is convex on $[0, +\u221e)$ and\n  strictly convex when `m \u2260 0, 1`.\n* `convex_on_rpow`, `strict_convex_on_rpow` : For `p : \u211d`, `\u03bb x, x ^ p` is convex on $[0, +\u221e)$ when\n  `1 \u2264 p` and strictly convex when `1 < p`.\n* `strict_concave_on_log_Ioi`, `strict_concave_on_log_Iio`: `real.log` is strictly concave on\n  $(0, +\u221e)$ and $(-\u221e, 0)$ respectively.\n\n## TODO\n\nFor `p : \u211d`, prove that `\u03bb x, x ^ p` is concave when `0 \u2264 p \u2264 1` and strictly concave when\n`0 < p < 1`.\n-/\n\nopen real set\nopen_locale big_operators\n\n/-- The norm of a real normed space is convex. Also see `seminorm.convex_on`. -/\nlemma convex_on_norm {E : Type*} [normed_group E] [normed_space \u211d E] :\n  convex_on \u211d univ (norm : E \u2192 \u211d) :=\n\u27e8convex_univ, \u03bb x y hx hy a b ha hb hab,\n  calc \u2225a \u2022 x + b \u2022 y\u2225 \u2264 \u2225a \u2022 x\u2225 + \u2225b \u2022 y\u2225 : norm_add_le _ _\n    ... = a * \u2225x\u2225 + b * \u2225y\u2225\n        : by rw [norm_smul, norm_smul, real.norm_of_nonneg ha, real.norm_of_nonneg hb]\u27e9\n\n/-- `exp` is strictly convex on the whole real line. -/\nlemma strict_convex_on_exp : strict_convex_on \u211d univ exp :=\nstrict_convex_on_univ_of_deriv2_pos differentiable_exp (\u03bb x, (iter_deriv_exp 2).symm \u25b8 exp_pos x)\n\n/-- `exp` is convex on the whole real line. -/\nlemma convex_on_exp : convex_on \u211d univ exp := strict_convex_on_exp.convex_on\n\n/-- `x^n`, `n : \u2115` is convex on the whole real line whenever `n` is even -/\nlemma even.convex_on_pow {n : \u2115} (hn : even n) : convex_on \u211d set.univ (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_univ_of_deriv2_nonneg differentiable_pow,\n  { simp only [deriv_pow', differentiable.mul, differentiable_const, differentiable_pow] },\n  { intro x,\n    rcases nat.even.sub_even hn (nat.even_bit0 1) with \u27e8k, hk\u27e9,\n    rw [iter_deriv_pow, finset.prod_range_cast_nat_sub, hk, pow_mul'],\n    exact mul_nonneg (nat.cast_nonneg _) (pow_two_nonneg _) }\nend\n\n/-- `x^n`, `n : \u2115` is strictly convex on the whole real line whenever `n \u2260 0` is even. -/\nlemma even.strict_convex_on_pow {n : \u2115} (hn : even n) (h : n \u2260 0) :\n  strict_convex_on \u211d set.univ (\u03bb x : \u211d, x^n) :=\nbegin\n  apply strict_mono.strict_convex_on_univ_of_deriv differentiable_pow,\n  rw deriv_pow',\n  replace h := nat.pos_of_ne_zero h,\n  exact strict_mono.const_mul (odd.strict_mono_pow $ nat.even.sub_odd h hn $ nat.odd_iff.2 rfl)\n    (nat.cast_pos.2 h),\nend\n\n/-- `x^n`, `n : \u2115` is convex on `[0, +\u221e)` for all `n` -/\nlemma convex_on_pow (n : \u2115) : convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_of_deriv2_nonneg (convex_Ici _) (continuous_pow n).continuous_on\n    differentiable_on_pow,\n  { simp only [deriv_pow'], exact (@differentiable_on_pow \u211d _ _ _).const_mul (n : \u211d) },\n  { intros x hx,\n    rw [iter_deriv_pow, finset.prod_range_cast_nat_sub],\n    exact mul_nonneg (nat.cast_nonneg _) (pow_nonneg (interior_subset hx) _) }\nend\n\n/-- `x^n`, `n : \u2115` is strictly convex on `[0, +\u221e)` for all `n` greater than `2`. -/\nlemma strict_convex_on_pow {n : \u2115} (hn : 2 \u2264 n) : strict_convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^n) :=\nbegin\n  apply strict_mono_on.strict_convex_on_of_deriv (convex_Ici _) (continuous_on_pow _)\n    differentiable_on_pow,\n  rw [deriv_pow', interior_Ici],\n  exact \u03bb x (hx : 0 < x) y hy hxy, mul_lt_mul_of_pos_left (pow_lt_pow_of_lt_left hxy hx.le $\n    nat.sub_pos_of_lt hn) (nat.cast_pos.2 $ zero_lt_two.trans_le hn),\nend\n\nlemma finset.prod_nonneg_of_card_nonpos_even\n  {\u03b1 \u03b2 : Type*} [linear_ordered_comm_ring \u03b2]\n  {f : \u03b1 \u2192 \u03b2} [decidable_pred (\u03bb x, f x \u2264 0)]\n  {s : finset \u03b1} (h0 : even (s.filter (\u03bb x, f x \u2264 0)).card) :\n  0 \u2264 \u220f x in s, f x :=\ncalc 0 \u2264 (\u220f x in s, ((if f x \u2264 0 then (-1:\u03b2) else 1) * f x)) :\n  finset.prod_nonneg (\u03bb x _, by\n    { split_ifs with hx hx, by simp [hx], simp at hx \u22a2, exact le_of_lt hx })\n... = _ : by rw [finset.prod_mul_distrib, finset.prod_ite, finset.prod_const_one,\n  mul_one, finset.prod_const, neg_one_pow_eq_pow_mod_two, nat.even_iff.1 h0, pow_zero, one_mul]\n\nlemma int_prod_range_nonneg (m : \u2124) (n : \u2115) (hn : even n) :\n  0 \u2264 \u220f k in finset.range n, (m - k) :=\nbegin\n  rcases hn with \u27e8n, rfl\u27e9,\n  induction n with n ihn, { simp },\n  rw [nat.succ_eq_add_one, mul_add, mul_one, bit0, \u2190 add_assoc, finset.prod_range_succ,\n    finset.prod_range_succ, mul_assoc],\n  refine mul_nonneg ihn _, generalize : (1 + 1) * n = k,\n  cases le_or_lt m k with hmk hmk,\n  { have : m \u2264 k + 1, from hmk.trans (lt_add_one \u2191k).le,\n    exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) (sub_nonpos_of_le this) },\n  { exact mul_nonneg (sub_nonneg_of_le hmk.le) (sub_nonneg_of_le hmk) }\nend\n\nlemma int_prod_range_pos {m : \u2124} {n : \u2115} (hn : even n) (hm : m \u2209 Ico (0 : \u2124) n) :\n  0 < \u220f k in finset.range n, (m - k) :=\nbegin\n  refine (int_prod_range_nonneg m n hn).lt_of_ne (\u03bb h, hm _),\n  rw [eq_comm, finset.prod_eq_zero_iff] at h,\n  obtain \u27e8a, ha, h\u27e9 := h,\n  rw sub_eq_zero.1 h,\n  exact \u27e8int.coe_zero_le _, int.coe_nat_lt.2 $ finset.mem_range.1 ha\u27e9,\nend\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` -/\nlemma convex_on_zpow (m : \u2124) : convex_on \u211d (Ioi 0) (\u03bb x : \u211d, x^m) :=\nbegin\n  have : \u2200 n : \u2124, differentiable_on \u211d (\u03bb x, x ^ n) (Ioi (0 : \u211d)),\n    from \u03bb n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),\n  apply convex_on_of_deriv2_nonneg (convex_Ioi 0);\n    try { simp only [interior_Ioi, deriv_zpow'] },\n  { exact (this _).continuous_on },\n  { exact this _ },\n  { exact (this _).const_mul _ },\n  { intros x hx,\n    simp only [iter_deriv_zpow, \u2190 int.cast_coe_nat, \u2190 int.cast_sub, \u2190 int.cast_prod],\n    refine mul_nonneg (int.cast_nonneg.2 _) (zpow_nonneg (le_of_lt hx) _),\n    exact int_prod_range_nonneg _ _ (nat.even_bit0 1) }\nend\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` except `0` and `1`. -/\nlemma strict_convex_on_zpow {m : \u2124} (hm\u2080 : m \u2260 0) (hm\u2081 : m \u2260 1) :\n  strict_convex_on \u211d (Ioi 0) (\u03bb x : \u211d, x^m) :=\nbegin\n  have : \u2200 n : \u2124, differentiable_on \u211d (\u03bb x, x ^ n) (Ioi (0 : \u211d)),\n    from \u03bb n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),\n  apply strict_convex_on_of_deriv2_pos (convex_Ioi 0),\n  { exact (this _).continuous_on },\n   all_goals { rw interior_Ioi },\n  { exact this _ },\n  intros x hx,\n  simp only [iter_deriv_zpow, \u2190 int.cast_coe_nat, \u2190 int.cast_sub, \u2190 int.cast_prod],\n  refine mul_pos (int.cast_pos.2 _) (zpow_pos_of_pos hx _),\n  refine int_prod_range_pos (nat.even_bit0 1) (\u03bb hm, _),\n  norm_cast at hm,\n  rw \u2190finset.coe_Ico at hm,\n  fin_cases hm,\n  { exact hm\u2080 rfl },\n  { exact hm\u2081 rfl }\nend\n\nlemma convex_on_rpow {p : \u211d} (hp : 1 \u2264 p) : convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  have A : deriv (\u03bb (x : \u211d), x ^ p) = \u03bb x, p * x^(p-1), by { ext x, simp [hp] },\n  apply convex_on_of_deriv2_nonneg (convex_Ici 0),\n  { exact continuous_on_id.rpow_const (\u03bb x _, or.inr (zero_le_one.trans hp)) },\n  { exact (differentiable_rpow_const hp).differentiable_on },\n  { rw A,\n    assume x hx,\n    replace hx : x \u2260 0, by { simp at hx, exact ne_of_gt hx },\n    simp [differentiable_at.differentiable_within_at, hx] },\n  { assume x hx,\n    replace hx : 0 < x, by simpa using hx,\n    suffices : 0 \u2264 p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],\n    apply mul_nonneg (le_trans zero_le_one hp),\n    exact mul_nonneg (sub_nonneg_of_le hp) (rpow_nonneg_of_nonneg hx.le _) }\nend\n\nlemma strict_convex_on_rpow {p : \u211d} (hp : 1 < p) : strict_convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  have A : deriv (\u03bb (x : \u211d), x ^ p) = \u03bb x, p * x^(p-1), by { ext x, simp [hp.le] },\n  apply strict_convex_on_of_deriv2_pos (convex_Ici 0),\n  { exact continuous_on_id.rpow_const (\u03bb x _, or.inr (zero_le_one.trans hp.le)) },\n  { exact (differentiable_rpow_const hp.le).differentiable_on },\n  rw interior_Ici,\n  rintro x (hx : 0 < x),\n  suffices : 0 < p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],\n  exact mul_pos (zero_lt_one.trans hp) (mul_pos (sub_pos_of_lt hp) (rpow_pos_of_pos hx _)),\nend\n\nlemma strict_concave_on_log_Ioi : strict_concave_on \u211d (Ioi 0) log :=\nbegin\n  have h\u2081 : Ioi 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { exact \u03bb x (hx : 0 < x) (hx' : x = 0), hx.ne' hx' },\n  refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 0) is_open_Ioi\n    (differentiable_on_log.mono h\u2081) (\u03bb x (hx : 0 < x), _),\n  rw [function.iterate_succ, function.iterate_one],\n  change (deriv (deriv log)) x < 0,\n  rw [deriv_log', deriv_inv],\n  exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne'),\nend\n\nlemma strict_concave_on_log_Iio : strict_concave_on \u211d (Iio 0) log :=\nbegin\n  have h\u2081 : Iio 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { exact \u03bb x (hx : x < 0) (hx' : x = 0), hx.ne hx' },\n  refine strict_concave_on_open_of_deriv2_neg (convex_Iio 0) is_open_Iio\n    (differentiable_on_log.mono h\u2081) (\u03bb x (hx : x < 0), _),\n  rw [function.iterate_succ, function.iterate_one],\n  change (deriv (deriv log)) x < 0,\n  rw [deriv_log', deriv_inv],\n  exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne),\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/convex/specific_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7386824717057513}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport data.fintype.basic\n\n/-!\n# Finite sets\n\nThis file defines predicates `finite : set \u03b1 \u2192 Prop` and `infinite : set \u03b1 \u2192 Prop` and proves some\nbasic facts about finite sets.\n-/\n\nopen set function\n\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b9 : Sort w} {\u03b3 : Type x}\n\nnamespace set\n\n/-- A set is finite if the subtype is a fintype, i.e. there is a\n  list that enumerates its members. -/\ndef finite (s : set \u03b1) : Prop := nonempty (fintype s)\n\n/-- A set is infinite if it is not finite. -/\ndef infinite (s : set \u03b1) : Prop := \u00ac finite s\n\n/-- The subtype corresponding to a finite set is a finite type. Note\nthat because `finite` isn't a typeclass, this will not fire if it\nis made into an instance -/\nnoncomputable def finite.fintype {s : set \u03b1} (h : finite s) : fintype s :=\nclassical.choice h\n\n/-- Get a finset from a finite set -/\nnoncomputable def finite.to_finset {s : set \u03b1} (h : finite s) : finset \u03b1 :=\n@set.to_finset _ _ h.fintype\n\n@[simp] theorem finite.mem_to_finset {s : set \u03b1} (h : finite s) {a : \u03b1} : a \u2208 h.to_finset \u2194 a \u2208 s :=\n@mem_to_finset _ _ h.fintype _\n\n@[simp] theorem finite.to_finset.nonempty {s : set \u03b1} (h : finite s) :\n  h.to_finset.nonempty \u2194 s.nonempty :=\nshow (\u2203 x, x \u2208 h.to_finset) \u2194 (\u2203 x, x \u2208 s),\nfrom exists_congr (\u03bb _, h.mem_to_finset)\n\n@[simp] lemma finite.coe_to_finset {s : set \u03b1} (h : finite s) : \u2191h.to_finset = s :=\n@set.coe_to_finset _ s h.fintype\n\n@[simp] lemma finite_empty_to_finset (h : finite (\u2205 : set \u03b1)) : h.to_finset = \u2205 :=\nby rw [\u2190 finset.coe_inj, h.coe_to_finset, finset.coe_empty]\n\n@[simp] lemma finite.to_finset_inj {s t : set \u03b1} {hs : finite s} {ht : finite t} :\n  hs.to_finset = ht.to_finset \u2194 s = t :=\nby simp [\u2190finset.coe_inj]\n\n@[simp] lemma finite_to_finset_eq_empty_iff {s : set \u03b1} {h : finite s} :\n  h.to_finset = \u2205 \u2194 s = \u2205 :=\nby simp [\u2190finset.coe_inj]\n\ntheorem finite.exists_finset {s : set \u03b1} : finite s \u2192\n  \u2203 s' : finset \u03b1, \u2200 a : \u03b1, a \u2208 s' \u2194 a \u2208 s\n| \u27e8h\u27e9 := by exactI \u27e8to_finset s, \u03bb _, mem_to_finset\u27e9\n\ntheorem finite.exists_finset_coe {s : set \u03b1} (hs : finite s) :\n  \u2203 s' : finset \u03b1, \u2191s' = s :=\n\u27e8hs.to_finset, hs.coe_to_finset\u27e9\n\n/-- Finite sets can be lifted to finsets. -/\ninstance : can_lift (set \u03b1) (finset \u03b1) :=\n{ coe := coe,\n  cond := finite,\n  prf := \u03bb s hs, hs.exists_finset_coe }\n\ntheorem finite_mem_finset (s : finset \u03b1) : finite {a | a \u2208 s} :=\n\u27e8fintype.of_finset s (\u03bb _, iff.rfl)\u27e9\n\ntheorem finite.of_fintype [fintype \u03b1] (s : set \u03b1) : finite s :=\nby classical; exact \u27e8set_fintype s\u27e9\n\ntheorem exists_finite_iff_finset {p : set \u03b1 \u2192 Prop} :\n  (\u2203 s, finite s \u2227 p s) \u2194 \u2203 s : finset \u03b1, p \u2191s :=\n\u27e8\u03bb \u27e8s, hs, hps\u27e9, \u27e8hs.to_finset, hs.coe_to_finset.symm \u25b8 hps\u27e9,\n  \u03bb \u27e8s, hs\u27e9, \u27e8\u2191s, finite_mem_finset s, hs\u27e9\u27e9\n\nlemma finite.fin_embedding {s : set \u03b1} (h : finite s) : \u2203 (n : \u2115) (f : fin n \u21aa \u03b1), range f = s :=\n\u27e8_, (fintype.equiv_fin (h.to_finset : set \u03b1)).symm.as_embedding, by simp\u27e9\n\nlemma finite.fin_param {s : set \u03b1} (h : finite s) :\n  \u2203 (n : \u2115) (f : fin n \u2192 \u03b1), injective f \u2227 range f = s :=\nlet \u27e8n, f, hf\u27e9 := h.fin_embedding in \u27e8n, f, f.injective, hf\u27e9\n\n/-- Membership of a subset of a finite type is decidable.\n\nUsing this as an instance leads to potential loops with `subtype.fintype` under certain decidability\nassumptions, so it should only be declared a local instance. -/\ndef decidable_mem_of_fintype [decidable_eq \u03b1] (s : set \u03b1) [fintype s] (a) : decidable (a \u2208 s) :=\ndecidable_of_iff _ mem_to_finset\n\ninstance fintype_empty : fintype (\u2205 : set \u03b1) :=\nfintype.of_finset \u2205 $ by simp\n\ntheorem empty_card : fintype.card (\u2205 : set \u03b1) = 0 := rfl\n\n@[simp] theorem empty_card' {h : fintype.{u} (\u2205 : set \u03b1)} :\n  @fintype.card (\u2205 : set \u03b1) h = 0 :=\neq.trans (by congr) empty_card\n\n@[simp] theorem finite_empty : @finite \u03b1 \u2205 := \u27e8set.fintype_empty\u27e9\n\ninstance finite.inhabited : inhabited {s : set \u03b1 // finite s} := \u27e8\u27e8\u2205, finite_empty\u27e9\u27e9\n\n/-- A `fintype` structure on `insert a s`. -/\ndef fintype_insert' {a : \u03b1} (s : set \u03b1) [fintype s] (h : a \u2209 s) : fintype (insert a s : set \u03b1) :=\nfintype.of_finset \u27e8a ::\u2098 s.to_finset.1,\n  multiset.nodup_cons_of_nodup (by simp [h]) s.to_finset.2\u27e9 $ by simp\n\ntheorem card_fintype_insert' {a : \u03b1} (s : set \u03b1) [fintype s] (h : a \u2209 s) :\n  @fintype.card _ (fintype_insert' s h) = fintype.card s + 1 :=\nby rw [fintype_insert', fintype.card_of_finset];\n   simp [finset.card, to_finset]; refl\n\n@[simp] theorem card_insert {a : \u03b1} (s : set \u03b1)\n  [fintype s] (h : a \u2209 s) {d : fintype.{u} (insert a s : set \u03b1)} :\n  @fintype.card _ d = fintype.card s + 1 :=\nby rw \u2190 card_fintype_insert' s h; congr\n\nlemma card_image_of_inj_on {s : set \u03b1} [fintype s]\n  {f : \u03b1 \u2192 \u03b2} [fintype (f '' s)] (H : \u2200x\u2208s, \u2200y\u2208s, f x = f y \u2192 x = y) :\n  fintype.card (f '' s) = fintype.card s :=\nby haveI := classical.prop_decidable; exact\ncalc fintype.card (f '' s) = (s.to_finset.image f).card : fintype.card_of_finset' _ (by simp)\n... = s.to_finset.card : finset.card_image_of_inj_on\n    (\u03bb x hx y hy hxy, H x (mem_to_finset.1 hx) y (mem_to_finset.1 hy) hxy)\n... = fintype.card s : (fintype.card_of_finset' _ (\u03bb a, mem_to_finset)).symm\n\nlemma card_image_of_injective (s : set \u03b1) [fintype s]\n  {f : \u03b1 \u2192 \u03b2} [fintype (f '' s)] (H : function.injective f) :\n  fintype.card (f '' s) = fintype.card s :=\ncard_image_of_inj_on $ \u03bb _ _ _ _ h, H h\n\nsection\n\nlocal attribute [instance] decidable_mem_of_fintype\n\ninstance fintype_insert [decidable_eq \u03b1] (a : \u03b1) (s : set \u03b1) [fintype s] :\n  fintype (insert a s : set \u03b1) :=\nif h : a \u2208 s then by rwa [insert_eq, union_eq_self_of_subset_left (singleton_subset_iff.2 h)]\nelse fintype_insert' _ h\n\nend\n\n@[simp] theorem finite.insert (a : \u03b1) {s : set \u03b1} : finite s \u2192 finite (insert a s)\n| \u27e8h\u27e9 := \u27e8@set.fintype_insert _ (classical.dec_eq \u03b1) _ _ h\u27e9\n\nlemma to_finset_insert [decidable_eq \u03b1] {a : \u03b1} {s : set \u03b1} (hs : finite s) :\n  (hs.insert a).to_finset = insert a hs.to_finset :=\nfinset.ext $ by simp\n\n@[simp] lemma insert_to_finset [decidable_eq \u03b1] {a : \u03b1} {s : set \u03b1} [fintype s] :\n  (insert a s).to_finset = insert a s.to_finset :=\nby simp [finset.ext_iff, mem_insert_iff]\n\n@[elab_as_eliminator]\ntheorem finite.induction_on {C : set \u03b1 \u2192 Prop} {s : set \u03b1} (h : finite s)\n  (H0 : C \u2205) (H1 : \u2200 {a s}, a \u2209 s \u2192 finite s \u2192 C s \u2192 C (insert a s)) : C s :=\nlet \u27e8t\u27e9 := h in by exactI\nmatch s.to_finset, @mem_to_finset _ s _ with\n| \u27e8l, nd\u27e9, al := begin\n    change \u2200 a, a \u2208 l \u2194 a \u2208 s at al,\n    clear _let_match _match t h, revert s nd al,\n    refine multiset.induction_on l _ (\u03bb a l IH, _); intros s nd al,\n    { rw show s = \u2205, from eq_empty_iff_forall_not_mem.2 (by simpa using al),\n      exact H0 },\n    { rw \u2190 show insert a {x | x \u2208 l} = s, from set.ext (by simpa using al),\n      cases multiset.nodup_cons.1 nd with m nd',\n      refine H1 _ \u27e8finset.subtype.fintype \u27e8l, nd'\u27e9\u27e9 (IH nd' (\u03bb _, iff.rfl)),\n      exact m }\n  end\nend\n\n@[elab_as_eliminator]\ntheorem finite.dinduction_on {C : \u2200s:set \u03b1, finite s \u2192 Prop} {s : set \u03b1} (h : finite s)\n  (H0 : C \u2205 finite_empty)\n  (H1 : \u2200 {a s}, a \u2209 s \u2192 \u2200h:finite s, C s h \u2192 C (insert a s) (h.insert a)) :\n  C s h :=\nhave \u2200h:finite s, C s h,\n  from finite.induction_on h (assume h, H0) (assume a s has hs ih h, H1 has hs (ih _)),\nthis h\n\ninstance fintype_singleton (a : \u03b1) : fintype ({a} : set \u03b1) :=\nunique.fintype\n\n@[simp] theorem card_singleton (a : \u03b1) :\n  fintype.card ({a} : set \u03b1) = 1 :=\nfintype.card_of_subsingleton _\n\n@[simp] theorem finite_singleton (a : \u03b1) : finite ({a} : set \u03b1) :=\n\u27e8set.fintype_singleton _\u27e9\n\nlemma subsingleton.finite {s : set \u03b1} (h : s.subsingleton) : finite s :=\nh.induction_on finite_empty finite_singleton\n\ninstance fintype_pure : \u2200 a : \u03b1, fintype (pure a : set \u03b1) :=\nset.fintype_singleton\n\ntheorem finite_pure (a : \u03b1) : finite (pure a : set \u03b1) :=\n\u27e8set.fintype_pure a\u27e9\n\ninstance fintype_univ [fintype \u03b1] : fintype (@univ \u03b1) :=\nfintype.of_equiv \u03b1 $ (equiv.set.univ \u03b1).symm\n\ntheorem finite_univ [fintype \u03b1] : finite (@univ \u03b1) := \u27e8set.fintype_univ\u27e9\n\n/-- If `(set.univ : set \u03b1)` is finite then `\u03b1` is a finite type. -/\nnoncomputable def fintype_of_univ_finite (H : (univ : set \u03b1).finite ) :\n  fintype \u03b1 :=\n@fintype.of_equiv _ (univ : set \u03b1) H.fintype (equiv.set.univ _)\n\nlemma univ_finite_iff_nonempty_fintype :\n  (univ : set \u03b1).finite \u2194 nonempty (fintype \u03b1) :=\nbegin\n  split,\n  { intro h, exact \u27e8fintype_of_univ_finite h\u27e9 },\n  { rintro \u27e8_i\u27e9, exactI finite_univ }\nend\n\ntheorem infinite_univ_iff : (@univ \u03b1).infinite \u2194 _root_.infinite \u03b1 :=\n\u27e8\u03bb h\u2081, \u27e8\u03bb h\u2082, h\u2081 $ @finite_univ \u03b1 h\u2082\u27e9, \u03bb \u27e8h\u2081\u27e9 h\u2082, h\u2081 (fintype_of_univ_finite h\u2082)\u27e9\n\ntheorem infinite_univ [h : _root_.infinite \u03b1] : infinite (@univ \u03b1) :=\ninfinite_univ_iff.2 h\n\ntheorem infinite_coe_iff {s : set \u03b1} : _root_.infinite s \u2194 infinite s :=\n\u27e8\u03bb \u27e8h\u2081\u27e9 h\u2082, h\u2081 h\u2082.some, \u03bb h\u2081, \u27e8\u03bb h\u2082, h\u2081 \u27e8h\u2082\u27e9\u27e9\u27e9\n\ntheorem infinite.to_subtype {s : set \u03b1} (h : infinite s) : _root_.infinite s :=\ninfinite_coe_iff.2 h\n\n/-- Embedding of `\u2115` into an infinite set. -/\nnoncomputable def infinite.nat_embedding (s : set \u03b1) (h : infinite s) : \u2115 \u21aa s :=\nby { haveI := h.to_subtype, exact infinite.nat_embedding s }\n\nlemma infinite.exists_subset_card_eq {s : set \u03b1} (hs : infinite s) (n : \u2115) :\n  \u2203 t : finset \u03b1, \u2191t \u2286 s \u2227 t.card = n :=\n\u27e8((finset.range n).map (hs.nat_embedding _)).map (embedding.subtype _), by simp\u27e9\n\nlemma infinite.nonempty {s : set \u03b1} (h : s.infinite) : s.nonempty :=\nlet a := infinite.nat_embedding s h 37 in \u27e8a.1, a.2\u27e9\n\ninstance fintype_union [decidable_eq \u03b1] (s t : set \u03b1) [fintype s] [fintype t] :\n  fintype (s \u222a t : set \u03b1) :=\nfintype.of_finset (s.to_finset \u222a t.to_finset) $ by simp\n\ntheorem finite.union {s t : set \u03b1} : finite s \u2192 finite t \u2192 finite (s \u222a t)\n| \u27e8hs\u27e9 \u27e8ht\u27e9 := \u27e8@set.fintype_union _ (classical.dec_eq \u03b1) _ _ hs ht\u27e9\n\nlemma finite.sup {s t : set \u03b1} : finite s \u2192 finite t \u2192 finite (s \u2294 t) := finite.union\n\nlemma infinite_of_finite_compl {\u03b1 : Type} [_root_.infinite \u03b1] {s : set \u03b1}\n  (hs : s\u1d9c.finite) : s.infinite :=\n\u03bb h, set.infinite_univ (by simpa using hs.union h)\n\nlemma finite.infinite_compl {\u03b1 : Type} [_root_.infinite \u03b1] {s : set \u03b1}\n  (hs : s.finite) : s\u1d9c.infinite :=\n\u03bb h, set.infinite_univ (by simpa using hs.union h)\n\ninstance fintype_sep (s : set \u03b1) (p : \u03b1 \u2192 Prop) [fintype s] [decidable_pred p] :\n  fintype ({a \u2208 s | p a} : set \u03b1) :=\nfintype.of_finset (s.to_finset.filter p) $ by simp\n\ninstance fintype_inter (s t : set \u03b1) [fintype s] [decidable_pred t] : fintype (s \u2229 t : set \u03b1) :=\nset.fintype_sep s t\n\n/-- A `fintype` structure on a set defines a `fintype` structure on its subset. -/\ndef fintype_subset (s : set \u03b1) {t : set \u03b1} [fintype s] [decidable_pred t] (h : t \u2286 s) : fintype t :=\nby rw \u2190 inter_eq_self_of_subset_right h; apply_instance\n\ntheorem finite.subset {s : set \u03b1} : finite s \u2192 \u2200 {t : set \u03b1}, t \u2286 s \u2192 finite t\n| \u27e8hs\u27e9 t h := \u27e8@set.fintype_subset _ _ _ hs (classical.dec_pred t) h\u27e9\n\nlemma finite.union_iff {s t : set \u03b1} : finite (s \u222a t) \u2194 finite s \u2227 finite t :=\n\u27e8\u03bb h, \u27e8h.subset (subset_union_left _ _), h.subset (subset_union_right _ _)\u27e9,\n \u03bb \u27e8hs, ht\u27e9, hs.union ht\u27e9\n\nlemma finite.diff {s t u : set \u03b1} (hs : s.finite) (ht : t.finite) (h : u \\ t \u2264 s) : u.finite :=\nbegin\n  refine finite.subset (ht.union hs) _,\n  exact diff_subset_iff.mp h\nend\n\ntheorem finite.inter_of_left {s : set \u03b1} (h : finite s) (t : set \u03b1) : finite (s \u2229 t) :=\nh.subset (inter_subset_left _ _)\n\ntheorem finite.inter_of_right {s : set \u03b1} (h : finite s) (t : set \u03b1) : finite (t \u2229 s) :=\nh.subset (inter_subset_right _ _)\n\ntheorem finite.inf_of_left {s : set \u03b1} (h : finite s) (t : set \u03b1) : finite (s \u2293 t) :=\nh.inter_of_left t\n\ntheorem finite.inf_of_right {s : set \u03b1} (h : finite s) (t : set \u03b1) : finite (t \u2293 s) :=\nh.inter_of_right t\n\ntheorem infinite_mono {s t : set \u03b1} (h : s \u2286 t) : infinite s \u2192 infinite t :=\nmt (\u03bb ht, ht.subset h)\n\ninstance fintype_image [decidable_eq \u03b2] (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) [fintype s] : fintype (f '' s) :=\nfintype.of_finset (s.to_finset.image f) $ by simp\n\ninstance fintype_range [decidable_eq \u03b2] (f : \u03b1 \u2192 \u03b2) [fintype \u03b1] : fintype (range f) :=\nfintype.of_finset (finset.univ.image f) $ by simp [range]\n\ntheorem finite_range (f : \u03b1 \u2192 \u03b2) [fintype \u03b1] : finite (range f) :=\nby haveI := classical.dec_eq \u03b2; exact \u27e8by apply_instance\u27e9\n\ntheorem finite.image {s : set \u03b1} (f : \u03b1 \u2192 \u03b2) : finite s \u2192 finite (f '' s)\n| \u27e8h\u27e9 := \u27e8@set.fintype_image _ _ (classical.dec_eq \u03b2) _ _ h\u27e9\n\ntheorem infinite_of_infinite_image (f : \u03b1 \u2192 \u03b2) {s : set \u03b1} (hs : (f '' s).infinite) :\n  s.infinite :=\nmt (finite.image f) hs\n\nlemma finite.dependent_image {s : set \u03b1} (hs : finite s) (F : \u03a0 i \u2208 s, \u03b2) :\n  finite {y : \u03b2 | \u2203 x (hx : x \u2208 s), y = F x hx} :=\nbegin\n  letI : fintype s := hs.fintype,\n  convert finite_range (\u03bb x : s, F x x.2),\n  simp only [set_coe.exists, subtype.coe_mk, eq_comm],\nend\n\ntheorem finite.of_preimage {f : \u03b1 \u2192 \u03b2} {s : set \u03b2} (h : finite (f \u207b\u00b9' s)) (hf : surjective f) :\n  finite s :=\nhf.image_preimage s \u25b8 h.image _\n\ninstance fintype_map {\u03b1 \u03b2} [decidable_eq \u03b2] :\n  \u2200 (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) [fintype s], fintype (f <$> s) := set.fintype_image\n\ntheorem finite.map {\u03b1 \u03b2} {s : set \u03b1} :\n  \u2200 (f : \u03b1 \u2192 \u03b2), finite s \u2192 finite (f <$> s) := finite.image\n\n/-- If a function `f` has a partial inverse and sends a set `s` to a set with `[fintype]` instance,\nthen `s` has a `fintype` structure as well. -/\ndef fintype_of_fintype_image (s : set \u03b1)\n  {f : \u03b1 \u2192 \u03b2} {g} (I : is_partial_inv f g) [fintype (f '' s)] : fintype s :=\nfintype.of_finset \u27e8_, @multiset.nodup_filter_map \u03b2 \u03b1 g _\n  (@injective_of_partial_inv_right _ _ f g I) (f '' s).to_finset.2\u27e9 $ \u03bb a,\nbegin\n  suffices : (\u2203 b x, f x = b \u2227 g b = some a \u2227 x \u2208 s) \u2194 a \u2208 s,\n  by simpa [exists_and_distrib_left.symm, and.comm, and.left_comm, and.assoc],\n  rw exists_swap,\n  suffices : (\u2203 x, x \u2208 s \u2227 g (f x) = some a) \u2194 a \u2208 s, {simpa [and.comm, and.left_comm, and.assoc]},\n  simp [I _, (injective_of_partial_inv I).eq_iff]\nend\n\ntheorem finite_of_finite_image {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} (hi : set.inj_on f s) :\n  finite (f '' s) \u2192 finite s | \u27e8h\u27e9 :=\n\u27e8@fintype.of_injective _ _ h (\u03bba:s, \u27e8f a.1, mem_image_of_mem f a.2\u27e9) $\n  assume a b eq, subtype.eq $ hi a.2 b.2 $ subtype.ext_iff_val.1 eq\u27e9\n\ntheorem finite_image_iff {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} (hi : inj_on f s) :\n  finite (f '' s) \u2194 finite s :=\n\u27e8finite_of_finite_image hi, finite.image _\u27e9\n\ntheorem infinite_image_iff {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} (hi : inj_on f s) :\n  infinite (f '' s) \u2194 infinite s :=\nnot_congr $ finite_image_iff hi\n\ntheorem infinite_of_inj_on_maps_to {s : set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (hi : inj_on f s) (hm : maps_to f s t) (hs : infinite s) : infinite t :=\ninfinite_mono (maps_to'.mp hm) $ (infinite_image_iff hi).2 hs\n\ntheorem infinite.exists_ne_map_eq_of_maps_to {s : set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (hs : infinite s) (hf : maps_to f s t) (ht : finite t) :\n  \u2203 (x \u2208 s) (y \u2208 s), x \u2260 y \u2227 f x = f y :=\nbegin\n  unfreezingI { contrapose! ht },\n  exact infinite_of_inj_on_maps_to (\u03bb x hx y hy, not_imp_not.1 (ht x hx y hy)) hf hs\nend\n\ntheorem infinite.exists_lt_map_eq_of_maps_to [linear_order \u03b1] {s : set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (hs : infinite s) (hf : maps_to f s t) (ht : finite t) :\n  \u2203 (x \u2208 s) (y \u2208 s), x < y \u2227 f x = f y :=\nlet \u27e8x, hx, y, hy, hxy, hf\u27e9 := hs.exists_ne_map_eq_of_maps_to hf ht\nin hxy.lt_or_lt.elim (\u03bb hxy, \u27e8x, hx, y, hy, hxy, hf\u27e9) (\u03bb hyx, \u27e8y, hy, x, hx, hyx, hf.symm\u27e9)\n\ntheorem infinite_range_of_injective [_root_.infinite \u03b1] {f : \u03b1 \u2192 \u03b2} (hi : injective f) :\n  infinite (range f) :=\nby { rw [\u2190image_univ, infinite_image_iff (inj_on_of_injective hi _)], exact infinite_univ }\n\ntheorem infinite_of_injective_forall_mem [_root_.infinite \u03b1] {s : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (hi : injective f) (hf : \u2200 x : \u03b1, f x \u2208 s) : infinite s :=\nby { rw \u2190range_subset_iff at hf, exact infinite_mono hf (infinite_range_of_injective hi) }\n\ntheorem finite.preimage {s : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (I : set.inj_on f (f\u207b\u00b9' s)) (h : finite s) : finite (f \u207b\u00b9' s) :=\nfinite_of_finite_image I (h.subset (image_preimage_subset f s))\n\ntheorem finite.preimage_embedding {s : set \u03b2} (f : \u03b1 \u21aa \u03b2) (h : s.finite) : (f \u207b\u00b9' s).finite :=\nfinite.preimage (\u03bb _ _ _ _ h', f.injective h') h\n\nlemma finite_option {s : set (option \u03b1)} : finite s \u2194 finite {x : \u03b1 | some x \u2208 s} :=\n\u27e8\u03bb h, h.preimage_embedding embedding.some,\n  \u03bb h, ((h.image some).insert none).subset $\n    \u03bb x, option.cases_on x (\u03bb _, or.inl rfl) (\u03bb x hx, or.inr $ mem_image_of_mem _ hx)\u27e9\n\ninstance fintype_Union [decidable_eq \u03b1] {\u03b9 : Type*} [fintype \u03b9]\n  (f : \u03b9 \u2192 set \u03b1) [\u2200 i, fintype (f i)] : fintype (\u22c3 i, f i) :=\nfintype.of_finset (finset.univ.bUnion (\u03bb i, (f i).to_finset)) $ by simp\n\ntheorem finite_Union {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 set \u03b1} (H : \u2200i, finite (f i)) :\n  finite (\u22c3 i, f i) :=\n\u27e8@set.fintype_Union _ (classical.dec_eq \u03b1) _ _ _ (\u03bb i, finite.fintype (H i))\u27e9\n\n/-- A union of sets with `fintype` structure over a set with `fintype` structure has a `fintype`\nstructure. -/\ndef fintype_bUnion [decidable_eq \u03b1] {\u03b9 : Type*} {s : set \u03b9} [fintype s]\n  (f : \u03b9 \u2192 set \u03b1) (H : \u2200 i \u2208 s, fintype (f i)) : fintype (\u22c3 i \u2208 s, f i) :=\nby rw bUnion_eq_Union; exact\n@set.fintype_Union _ _ _ _ _ (by rintro \u27e8i, hi\u27e9; exact H i hi)\n\ninstance fintype_bUnion' [decidable_eq \u03b1] {\u03b9 : Type*} {s : set \u03b9} [fintype s]\n  (f : \u03b9 \u2192 set \u03b1) [H : \u2200 i, fintype (f i)] : fintype (\u22c3 i \u2208 s, f i) :=\nfintype_bUnion _ (\u03bb i _, H i)\n\ntheorem finite.sUnion {s : set (set \u03b1)} (h : finite s) (H : \u2200t\u2208s, finite t) : finite (\u22c3\u2080 s) :=\nby rw sUnion_eq_Union; haveI := finite.fintype h;\n   apply finite_Union; simpa using H\n\ntheorem finite.bUnion {\u03b1} {\u03b9 : Type*} {s : set \u03b9} {f : \u03a0 i \u2208 s, set \u03b1} :\n  finite s \u2192 (\u2200 i \u2208 s, finite (f i \u2039_\u203a)) \u2192 finite (\u22c3 i\u2208s, f i \u2039_\u203a)\n| \u27e8hs\u27e9 h := by rw [bUnion_eq_Union]; exactI finite_Union (\u03bb i, h _ _)\n\ntheorem finite_Union_Prop {p : Prop} {f : p \u2192 set \u03b1} (hf : \u2200 h, finite (f h)) :\n  finite (\u22c3 h : p, f h) :=\nby by_cases p; simp *\n\ninstance fintype_lt_nat (n : \u2115) : fintype {i | i < n} :=\nfintype.of_finset (finset.range n) $ by simp\n\ninstance fintype_le_nat (n : \u2115) : fintype {i | i \u2264 n} :=\nby simpa [nat.lt_succ_iff] using set.fintype_lt_nat (n+1)\n\nlemma finite_le_nat (n : \u2115) : finite {i | i \u2264 n} := \u27e8set.fintype_le_nat _\u27e9\n\nlemma finite_lt_nat (n : \u2115) : finite {i | i < n} := \u27e8set.fintype_lt_nat _\u27e9\n\ninstance fintype_prod (s : set \u03b1) (t : set \u03b2) [fintype s] [fintype t] : fintype (set.prod s t) :=\nfintype.of_finset (s.to_finset.product t.to_finset) $ by simp\n\nlemma finite.prod {s : set \u03b1} {t : set \u03b2} : finite s \u2192 finite t \u2192 finite (set.prod s t)\n| \u27e8hs\u27e9 \u27e8ht\u27e9 := by exactI \u27e8set.fintype_prod s t\u27e9\n\n/-- `image2 f s t` is finitype if `s` and `t` are. -/\ninstance fintype_image2 [decidable_eq \u03b3] (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (s : set \u03b1) (t : set \u03b2)\n  [hs : fintype s] [ht : fintype t] : fintype (image2 f s t : set \u03b3) :=\nby { rw \u2190 image_prod, apply set.fintype_image }\n\nlemma finite.image2 (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) {s : set \u03b1} {t : set \u03b2} (hs : finite s) (ht : finite t) :\n  finite (image2 f s t) :=\nby { rw \u2190 image_prod, exact (hs.prod ht).image _ }\n\n/-- If `s : set \u03b1` is a set with `fintype` instance and `f : \u03b1 \u2192 set \u03b2` is a function such that\neach `f a`, `a \u2208 s`, has a `fintype` structure, then `s >>= f` has a `fintype` structure. -/\ndef fintype_bind {\u03b1 \u03b2} [decidable_eq \u03b2] (s : set \u03b1) [fintype s]\n  (f : \u03b1 \u2192 set \u03b2) (H : \u2200 a \u2208 s, fintype (f a)) : fintype (s >>= f) :=\nset.fintype_bUnion _ H\n\ninstance fintype_bind' {\u03b1 \u03b2} [decidable_eq \u03b2] (s : set \u03b1) [fintype s]\n  (f : \u03b1 \u2192 set \u03b2) [H : \u2200 a, fintype (f a)] : fintype (s >>= f) :=\nfintype_bind _ _ (\u03bb i _, H i)\n\ntheorem finite.bind {\u03b1 \u03b2} {s : set \u03b1} {f : \u03b1 \u2192 set \u03b2} (h : finite s) (hf : \u2200 a \u2208 s, finite (f a)) :\n  finite (s >>= f) :=\nh.bUnion hf\n\ninstance fintype_seq [decidable_eq \u03b2] (f : set (\u03b1 \u2192 \u03b2)) (s : set \u03b1) [fintype f] [fintype s] :\n  fintype (f.seq s) :=\nby { rw seq_def, apply set.fintype_bUnion' }\n\ninstance fintype_seq' {\u03b1 \u03b2 : Type u} [decidable_eq \u03b2]\n  (f : set (\u03b1 \u2192 \u03b2)) (s : set \u03b1) [fintype f] [fintype s] :\n  fintype (f <*> s) :=\nset.fintype_seq f s\n\ntheorem finite.seq {f : set (\u03b1 \u2192 \u03b2)} {s : set \u03b1} (hf : finite f) (hs : finite s) :\n  finite (f.seq s) :=\nby { rw seq_def, exact hf.bUnion (\u03bb f _, hs.image _) }\n\ntheorem finite.seq' {\u03b1 \u03b2 : Type u} {f : set (\u03b1 \u2192 \u03b2)} {s : set \u03b1} (hf : finite f) (hs : finite s) :\n  finite (f <*> s) :=\nhf.seq hs\n\n/-- There are finitely many subsets of a given finite set -/\nlemma finite.finite_subsets {\u03b1 : Type u} {a : set \u03b1} (h : finite a) : finite {b | b \u2286 a} :=\nbegin\n  -- we just need to translate the result, already known for finsets,\n  -- to the language of finite sets\n  let s : set (set \u03b1) := coe '' (\u2191(finset.powerset (finite.to_finset h)) : set (finset \u03b1)),\n  have : finite s := (finite_mem_finset _).image _,\n  apply this.subset,\n  refine \u03bb b hb, \u27e8(h.subset hb).to_finset, _, finite.coe_to_finset _\u27e9,\n  simpa [finset.subset_iff]\nend\n\nlemma exists_min_image [linear_order \u03b2] (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) (h1 : finite s) :\n  s.nonempty \u2192 \u2203 a \u2208 s, \u2200 b \u2208 s, f a \u2264 f b\n| \u27e8x, hx\u27e9 := by simpa only [exists_prop, finite.mem_to_finset]\n  using h1.to_finset.exists_min_image f \u27e8x, h1.mem_to_finset.2 hx\u27e9\n\nlemma exists_max_image [linear_order \u03b2] (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) (h1 : finite s) :\n  s.nonempty \u2192 \u2203 a \u2208 s, \u2200 b \u2208 s, f b \u2264 f a\n| \u27e8x, hx\u27e9 := by simpa only [exists_prop, finite.mem_to_finset]\n  using h1.to_finset.exists_max_image f \u27e8x, h1.mem_to_finset.2 hx\u27e9\n\ntheorem exists_lower_bound_image [h\u03b1 : nonempty \u03b1] [linear_order \u03b2] (s : set \u03b1) (f : \u03b1 \u2192 \u03b2)\n  (h : s.finite) : \u2203 (a : \u03b1), \u2200 b \u2208 s, f a \u2264 f b :=\nbegin\n  by_cases hs : set.nonempty s,\n  { exact let \u27e8x\u2080, H, hx\u2080\u27e9 := set.exists_min_image s f h hs in \u27e8x\u2080, \u03bb x hx, hx\u2080 x hx\u27e9 },\n  { exact nonempty.elim h\u03b1 (\u03bb a, \u27e8a, \u03bb x hx, absurd (set.nonempty_of_mem hx) hs\u27e9) }\nend\n\ntheorem exists_upper_bound_image [h\u03b1 : nonempty \u03b1] [linear_order \u03b2] (s : set \u03b1) (f : \u03b1 \u2192 \u03b2)\n  (h : s.finite) : \u2203 (a : \u03b1), \u2200 b \u2208 s, f b \u2264 f a :=\nbegin\n  by_cases hs : set.nonempty s,\n  { exact let \u27e8x\u2080, H, hx\u2080\u27e9 := set.exists_max_image s f h hs in \u27e8x\u2080, \u03bb x hx, hx\u2080 x hx\u27e9 },\n  { exact nonempty.elim h\u03b1 (\u03bb a, \u27e8a, \u03bb x hx, absurd (set.nonempty_of_mem hx) hs\u27e9) }\nend\n\nend set\n\nnamespace finset\nvariables [decidable_eq \u03b2]\nvariables {s : finset \u03b1}\n\nlemma finite_to_set (s : finset \u03b1) : set.finite (\u2191s : set \u03b1) :=\nset.finite_mem_finset s\n\n@[simp] lemma coe_bUnion {f : \u03b1 \u2192 finset \u03b2} : \u2191(s.bUnion f) = (\u22c3x \u2208 (\u2191s : set \u03b1), \u2191(f x) : set \u03b2) :=\nby simp [set.ext_iff]\n\n@[simp] lemma finite_to_set_to_finset {\u03b1 : Type*} (s : finset \u03b1) :\n  (finite_to_set s).to_finset = s :=\nby { ext, rw [set.finite.mem_to_finset, mem_coe] }\n\nend finset\n\nnamespace set\n\n/-- Finite product of finite sets is finite -/\nlemma finite.pi {\u03b4 : Type*} [fintype \u03b4] {\u03ba : \u03b4 \u2192 Type*} {t : \u03a0 d, set (\u03ba d)}\n  (ht : \u2200 d, (t d).finite) :\n  (pi univ t).finite :=\nbegin\n  classical,\n  convert (fintype.pi_finset (\u03bb d, (ht d).to_finset)).finite_to_set,\n  ext,\n  simp,\nend\n\n\n\nlemma eq_finite_Union_of_finite_subset_Union  {\u03b9} {s : \u03b9 \u2192 set \u03b1} {t : set \u03b1} (tfin : finite t)\n  (h : t \u2286 \u22c3 i, s i) :\n  \u2203 I : set \u03b9, (finite I) \u2227 \u2203 \u03c3 : {i | i \u2208 I} \u2192 set \u03b1,\n     (\u2200 i, finite (\u03c3 i)) \u2227 (\u2200 i, \u03c3 i \u2286 s i) \u2227 t = \u22c3 i, \u03c3 i :=\nlet \u27e8I, Ifin, hI\u27e9 := finite_subset_Union tfin h in\n\u27e8I, Ifin, \u03bb x, s x \u2229 t,\n    \u03bb i, tfin.subset (inter_subset_right _ _),\n    \u03bb i, inter_subset_left _ _,\n    begin\n      ext x,\n      rw mem_Union,\n      split,\n      { intro x_in,\n        rcases mem_Union.mp (hI x_in) with \u27e8i, _, \u27e8hi, rfl\u27e9, H\u27e9,\n        use [i, hi, H, x_in] },\n      { rintros \u27e8i, hi, H\u27e9,\n        exact H }\n    end\u27e9\n\n/-- An increasing union distributes over finite intersection. -/\nlemma Union_Inter_of_monotone {\u03b9 \u03b9' \u03b1 : Type*} [fintype \u03b9] [linear_order \u03b9']\n  [nonempty \u03b9'] {s : \u03b9 \u2192 \u03b9' \u2192 set \u03b1} (hs : \u2200 i, monotone (s i)) :\n  (\u22c3 j : \u03b9', \u22c2 i : \u03b9, s i j) = \u22c2 i : \u03b9, \u22c3 j : \u03b9', s i j :=\nbegin\n  ext x, refine \u27e8\u03bb hx, Union_Inter_subset hx, \u03bb hx, _\u27e9,\n  simp only [mem_Inter, mem_Union, mem_Inter] at hx \u22a2, choose j hj using hx,\n  obtain \u27e8j\u2080\u27e9 := show nonempty \u03b9', by apply_instance,\n  refine \u27e8finset.univ.fold max j\u2080 j, \u03bb i, hs i _ (hj i)\u27e9,\n  rw [finset.fold_op_rel_iff_or (@le_max_iff _ _)],\n  exact or.inr \u27e8i, finset.mem_univ i, le_rfl\u27e9\nend\n\ninstance nat.fintype_Iio (n : \u2115) : fintype (Iio n) :=\nfintype.of_finset (finset.range n) $ by simp\n\n/--\nIf `P` is some relation between terms of `\u03b3` and sets in `\u03b3`,\nsuch that every finite set `t : set \u03b3` has some `c : \u03b3` related to it,\nthen there is a recursively defined sequence `u` in `\u03b3`\nso `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.\n\n(We use this later to show sequentially compact sets\nare totally bounded.)\n-/\nlemma seq_of_forall_finite_exists  {\u03b3 : Type*}\n  {P : \u03b3 \u2192 set \u03b3 \u2192 Prop} (h : \u2200 t,  finite t \u2192 \u2203 c, P c t) :\n  \u2203 u : \u2115 \u2192 \u03b3, \u2200 n, P (u n) (u '' Iio n) :=\n\u27e8\u03bb n, @nat.strong_rec_on' (\u03bb _, \u03b3) n $ \u03bb n ih, classical.some $ h\n    (range $ \u03bb m : Iio n, ih m.1 m.2)\n    (finite_range _),\n\u03bb n, begin\n  classical,\n  refine nat.strong_rec_on' n (\u03bb n ih, _),\n  rw nat.strong_rec_on_beta', convert classical.some_spec (h _ _),\n  ext x, split,\n  { rintros \u27e8m, hmn, rfl\u27e9, exact \u27e8\u27e8m, hmn\u27e9, rfl\u27e9 },\n  { rintros \u27e8\u27e8m, hmn\u27e9, rfl\u27e9, exact \u27e8m, hmn, rfl\u27e9 }\nend\u27e9\n\nlemma finite_range_ite {p : \u03b1 \u2192 Prop} [decidable_pred p] {f g : \u03b1 \u2192 \u03b2} (hf : finite (range f))\n  (hg : finite (range g)) : finite (range (\u03bb x, if p x then f x else g x)) :=\n(hf.union hg).subset range_ite_subset\n\nlemma finite_range_const {c : \u03b2} : finite (range (\u03bb x : \u03b1, c)) :=\n(finite_singleton c).subset range_const_subset\n\nlemma range_find_greatest_subset {P : \u03b1 \u2192 \u2115 \u2192 Prop} [\u2200 x, decidable_pred (P x)] {b : \u2115}:\n  range (\u03bb x, nat.find_greatest (P x) b) \u2286 \u2191(finset.range (b + 1)) :=\nby { rw range_subset_iff, assume x, simp [nat.lt_succ_iff, nat.find_greatest_le] }\n\nlemma finite_range_find_greatest {P : \u03b1 \u2192 \u2115 \u2192 Prop} [\u2200 x, decidable_pred (P x)] {b : \u2115} :\n  finite (range (\u03bb x, nat.find_greatest (P x) b)) :=\n(finset.range (b + 1)).finite_to_set.subset range_find_greatest_subset\n\nlemma card_lt_card {s t : set \u03b1} [fintype s] [fintype t] (h : s \u2282 t) :\n  fintype.card s < fintype.card t :=\nfintype.card_lt_of_injective_not_surjective (set.inclusion h.1) (set.inclusion_injective h.1) $\n  \u03bb hst, (ssubset_iff_subset_ne.1 h).2 (eq_of_inclusion_surjective hst)\n\nlemma card_le_of_subset {s t : set \u03b1} [fintype s] [fintype t] (hsub : s \u2286 t) :\n  fintype.card s \u2264 fintype.card t :=\nfintype.card_le_of_injective (set.inclusion hsub) (set.inclusion_injective hsub)\n\nlemma eq_of_subset_of_card_le {s t : set \u03b1} [fintype s] [fintype t]\n   (hsub : s \u2286 t) (hcard : fintype.card t \u2264 fintype.card s) : s = t :=\n(eq_or_ssubset_of_subset hsub).elim id\n  (\u03bb h, absurd hcard $ not_le_of_lt $ card_lt_card h)\n\nlemma subset_iff_to_finset_subset (s t : set \u03b1) [fintype s] [fintype t] :\n  s \u2286 t \u2194 s.to_finset \u2286 t.to_finset :=\nby simp\n\n@[simp, mono] lemma finite.to_finset_mono {s t : set \u03b1} {hs : finite s} {ht : finite t} :\n  hs.to_finset \u2286 ht.to_finset \u2194 s \u2286 t :=\nbegin\n  split,\n  { intros h x,\n    rw [\u2190finite.mem_to_finset hs, \u2190finite.mem_to_finset ht],\n    exact \u03bb hx, h hx },\n  { intros h x,\n    rw [finite.mem_to_finset hs, finite.mem_to_finset ht],\n    exact \u03bb hx, h hx }\nend\n\n@[simp, mono] lemma finite.to_finset_strict_mono {s t : set \u03b1} {hs : finite s} {ht : finite t} :\n  hs.to_finset \u2282 ht.to_finset \u2194 s \u2282 t :=\nbegin\n  rw [\u2190lt_eq_ssubset, \u2190finset.lt_iff_ssubset, lt_iff_le_and_ne, lt_iff_le_and_ne],\n  simp\nend\n\nlemma card_range_of_injective [fintype \u03b1] {f : \u03b1 \u2192 \u03b2} (hf : injective f)\n  [fintype (range f)] : fintype.card (range f) = fintype.card \u03b1 :=\neq.symm $ fintype.card_congr $ equiv.of_injective f hf\n\nlemma finite.exists_maximal_wrt [partial_order \u03b2] (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (h : set.finite s) :\n  s.nonempty \u2192 \u2203a\u2208s, \u2200a'\u2208s, f a \u2264 f a' \u2192 f a = f a' :=\nbegin\n  classical,\n  refine h.induction_on _ _,\n  { assume h, exact absurd h empty_not_nonempty },\n  assume a s his _ ih _,\n  cases s.eq_empty_or_nonempty with h h,\n  { use a, simp [h] },\n  rcases ih h with \u27e8b, hb, ih\u27e9,\n  by_cases f b \u2264 f a,\n  { refine \u27e8a, set.mem_insert _ _, assume c hc hac, le_antisymm hac _\u27e9,\n    rcases set.mem_insert_iff.1 hc with rfl | hcs,\n    { refl },\n    { rwa [\u2190 ih c hcs (le_trans h hac)] } },\n  { refine \u27e8b, set.mem_insert_of_mem _ hb, assume c hc hbc, _\u27e9,\n    rcases set.mem_insert_iff.1 hc with rfl | hcs,\n    { exact (h hbc).elim },\n    { exact ih c hcs hbc } }\nend\n\nlemma finite.card_to_finset {s : set \u03b1} [fintype s] (h : s.finite) :\n  h.to_finset.card = fintype.card s :=\nby { rw [\u2190 finset.card_attach, finset.attach_eq_univ, \u2190 fintype.card], congr' 2, funext,\n     rw set.finite.mem_to_finset }\n\nsection decidable_eq\n\nlemma to_finset_compl {\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1]\n  (s : set \u03b1) [fintype (s\u1d9c : set \u03b1)] [fintype s] : s\u1d9c.to_finset = (s.to_finset)\u1d9c :=\nby ext; simp\n\nlemma to_finset_inter {\u03b1 : Type*} [decidable_eq \u03b1] (s t : set \u03b1) [fintype (s \u2229 t : set \u03b1)]\n  [fintype s] [fintype t] : (s \u2229 t).to_finset = s.to_finset \u2229 t.to_finset :=\nby ext; simp\n\nlemma to_finset_union {\u03b1 : Type*} [decidable_eq \u03b1] (s t : set \u03b1) [fintype (s \u222a t : set \u03b1)]\n  [fintype s] [fintype t] : (s \u222a t).to_finset = s.to_finset \u222a t.to_finset :=\nby ext; simp\n\nlemma to_finset_ne_eq_erase {\u03b1 : Type*} [decidable_eq \u03b1] [fintype \u03b1] (a : \u03b1)\n  [fintype {x : \u03b1 | x \u2260 a}] : {x : \u03b1 | x \u2260 a}.to_finset = finset.univ.erase a :=\nby ext; simp\n\nlemma card_ne_eq [fintype \u03b1] (a : \u03b1) [fintype {x : \u03b1 | x \u2260 a}] :\n  fintype.card {x : \u03b1 | x \u2260 a} = fintype.card \u03b1 - 1 :=\nbegin\n  haveI := classical.dec_eq \u03b1,\n  rw [\u2190to_finset_card, to_finset_ne_eq_erase, finset.card_erase_of_mem (finset.mem_univ _),\n      finset.card_univ, nat.pred_eq_sub_one],\nend\n\nend decidable_eq\n\nsection\n\nvariables [semilattice_sup \u03b1] [nonempty \u03b1] {s : set \u03b1}\n\n/--A finite set is bounded above.-/\nprotected lemma finite.bdd_above (hs : finite s) : bdd_above s :=\nfinite.induction_on hs bdd_above_empty $ \u03bb a s _ _ h, h.insert a\n\n/--A finite union of sets which are all bounded above is still bounded above.-/\nlemma finite.bdd_above_bUnion {I : set \u03b2} {S : \u03b2 \u2192 set \u03b1} (H : finite I) :\n  (bdd_above (\u22c3i\u2208I, S i)) \u2194 (\u2200i \u2208 I, bdd_above (S i)) :=\nfinite.induction_on H\n  (by simp only [bUnion_empty, bdd_above_empty, ball_empty_iff])\n  (\u03bb a s ha _ hs, by simp only [bUnion_insert, ball_insert_iff, bdd_above_union, hs])\n\nend\n\nsection\n\nvariables [semilattice_inf \u03b1] [nonempty \u03b1] {s : set \u03b1}\n\n/--A finite set is bounded below.-/\nprotected lemma finite.bdd_below (hs : finite s) : bdd_below s :=\n@finite.bdd_above (order_dual \u03b1) _ _ _ hs\n\n/--A finite union of sets which are all bounded below is still bounded below.-/\nlemma finite.bdd_below_bUnion {I : set \u03b2} {S : \u03b2 \u2192 set \u03b1} (H : finite I) :\n  (bdd_below (\u22c3i\u2208I, S i)) \u2194 (\u2200i \u2208 I, bdd_below (S i)) :=\n@finite.bdd_above_bUnion (order_dual \u03b1) _ _ _ _ _ H\n\nend\n\nend set\n\nnamespace finset\n\n/-- A finset is bounded above. -/\nprotected lemma bdd_above [semilattice_sup \u03b1] [nonempty \u03b1] (s : finset \u03b1) :\n  bdd_above (\u2191s : set \u03b1) :=\ns.finite_to_set.bdd_above\n\n/-- A finset is bounded below. -/\nprotected lemma bdd_below [semilattice_inf \u03b1] [nonempty \u03b1] (s : finset \u03b1) :\n  bdd_below (\u2191s : set \u03b1) :=\ns.finite_to_set.bdd_below\n\nend finset\n\nnamespace fintype\nvariables [fintype \u03b1] {p q : \u03b1 \u2192 Prop} [decidable_pred p] [decidable_pred q]\n\n@[simp]\nlemma card_subtype_compl : fintype.card {x // \u00ac p x} = fintype.card \u03b1 - fintype.card {x // p x} :=\nbegin\n  classical,\n  rw [fintype.card_of_subtype (set.to_finset p\u1d9c), set.to_finset_compl p, finset.card_compl,\n      fintype.card_of_subtype (set.to_finset p)];\n    intros; simp; refl\nend\n\n/-- If two subtypes of a fintype have equal cardinality, so do their complements. -/\nlemma card_compl_eq_card_compl (h : fintype.card {x // p x} = fintype.card {x // q x}) :\n  fintype.card {x // \u00ac p x} = fintype.card {x // \u00ac q x} :=\nby simp only [card_subtype_compl, h]\n\nend fintype\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/set/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7386735498588906}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.prime\n! leanprover-community/mathlib commit 8631e2d5ea77f6c13054d9151d82b83069680cb1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Associated\nimport Mathlib.Algebra.Parity\nimport Mathlib.Data.Int.Dvd.Basic\nimport Mathlib.Data.Int.Units\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Data.Nat.GCD.Basic\nimport Mathlib.Data.Nat.Sqrt\nimport Mathlib.Order.Bounds.Basic\nimport Mathlib.Tactic.ByContra\n\n/-!\n# Prime numbers\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\n- `Nat.Prime`: the predicate that expresses that a natural number `p` is prime\n- `Nat.Primes`: the subtype of natural numbers that are prime\n- `Nat.minFac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `Nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers.\n  This also appears as `Nat.not_bddAbove_setOf_prime` and `Nat.infinite_setOf_prime` (the latter\n  in `Data.Nat.PrimeFin`).\n- `Nat.prime_iff`: `Nat.Prime` coincides with the general definition of `Prime`\n- `Nat.irreducible_iff_nat_prime`: a non-unit natural number is\n                                  only divisible by `1` iff it is prime\n\n-/\n\n\nopen Bool Subtype\n\nopen Nat\n\nnamespace Nat\n\n/-- `Nat.Prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\n-- Porting note: removed @[pp_nodot]\ndef Prime (p : \u2115) :=\n  Irreducible p\n#align nat.prime Nat.Prime\n\ntheorem irreducible_iff_nat_prime (a : \u2115) : Irreducible a \u2194 Nat.Prime a :=\n  Iff.rfl\n#align irreducible_iff_nat_prime Nat.irreducible_iff_nat_prime\n\ntheorem not_prime_zero : \u00acPrime 0\n  | h => h.ne_zero rfl\n#align nat.not_prime_zero Nat.not_prime_zero\n\ntheorem not_prime_one : \u00acPrime 1\n  | h => h.ne_one rfl\n#align nat.not_prime_one Nat.not_prime_one\n\ntheorem Prime.ne_zero {n : \u2115} (h : Prime n) : n \u2260 0 :=\n  Irreducible.ne_zero h\n#align nat.prime.ne_zero Nat.Prime.ne_zero\n\ntheorem Prime.pos {p : \u2115} (pp : Prime p) : 0 < p :=\n  Nat.pos_of_ne_zero pp.ne_zero\n#align nat.prime.pos Nat.Prime.pos\n\ntheorem Prime.two_le : \u2200 {p : \u2115}, Prime p \u2192 2 \u2264 p\n  | 0, h => (not_prime_zero h).elim\n  | 1, h => (not_prime_one h).elim\n  | _ + 2, _ => le_add_self\n#align nat.prime.two_le Nat.Prime.two_le\n\ntheorem Prime.one_lt {p : \u2115} : Prime p \u2192 1 < p :=\n  Prime.two_le\n#align nat.prime.one_lt Nat.Prime.one_lt\n\ninstance Prime.one_lt' (p : \u2115) [hp : Fact p.Prime] : Fact (1 < p) :=\n  \u27e8hp.1.one_lt\u27e9\n#align nat.prime.one_lt' Nat.Prime.one_lt'\n\ntheorem Prime.ne_one {p : \u2115} (hp : p.Prime) : p \u2260 1 :=\n  hp.one_lt.ne'\n#align nat.prime.ne_one Nat.Prime.ne_one\n\ntheorem Prime.eq_one_or_self_of_dvd {p : \u2115} (pp : p.Prime) (m : \u2115) (hm : m \u2223 p) :\n    m = 1 \u2228 m = p := by\n  obtain \u27e8n, hn\u27e9 := hm\n  have := pp.isUnit_or_isUnit hn\n  rw [Nat.isUnit_iff, Nat.isUnit_iff] at this\n  apply Or.imp_right _ this\n  rintro rfl\n  rw [hn, mul_one]\n#align nat.prime.eq_one_or_self_of_dvd Nat.Prime.eq_one_or_self_of_dvd\n\ntheorem prime_def_lt'' {p : \u2115} : Prime p \u2194 2 \u2264 p \u2227 \u2200 (m) (_ : m \u2223 p), m = 1 \u2228 m = p := by\n  refine' \u27e8fun h => \u27e8h.two_le, h.eq_one_or_self_of_dvd\u27e9, fun h => _\u27e9\n  -- Porting note: needed to make \u2115 explicit\n  have h1 := (@one_lt_two \u2115 ..).trans_le h.1\n  refine' \u27e8mt Nat.isUnit_iff.mp h1.ne', fun a b hab => _\u27e9\n  simp only [Nat.isUnit_iff]\n  apply Or.imp_right _ (h.2 a _)\n  \u00b7 rintro rfl\n    rw [\u2190 mul_right_inj' (pos_of_gt h1).ne', \u2190 hab, mul_one]\n  \u00b7 rw [hab]\n    exact dvd_mul_right _ _\n#align nat.prime_def_lt'' Nat.prime_def_lt''\n\ntheorem prime_def_lt {p : \u2115} : Prime p \u2194 2 \u2264 p \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\n  prime_def_lt''.trans <|\n    and_congr_right fun p2 =>\n      forall_congr' fun _ =>\n        \u27e8fun h l d => (h d).resolve_right (ne_of_lt l), fun h d =>\n          (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left fun l => h l d\u27e9\n#align nat.prime_def_lt Nat.prime_def_lt\n\ntheorem prime_def_lt' {p : \u2115} : Prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00acm \u2223 p :=\n  prime_def_lt.trans <|\n    and_congr_right fun p2 =>\n      forall_congr' fun m =>\n        \u27e8fun h m2 l d => not_lt_of_ge m2 ((h l d).symm \u25b8 by decide), fun h l d => by\n          rcases m with (_ | _ | m)\n          \u00b7 rw [eq_zero_of_zero_dvd d] at p2\n            revert p2\n            decide\n          \u00b7 rfl\n          \u00b7 exact (h le_add_self l).elim d\u27e9\n#align nat.prime_def_lt' Nat.prime_def_lt'\n\ntheorem prime_def_le_sqrt {p : \u2115} : Prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00acm \u2223 p :=\n  prime_def_lt'.trans <|\n    and_congr_right fun p2 =>\n      \u27e8fun a m m2 l => a m m2 <| lt_of_le_of_lt l <| sqrt_lt_self p2, fun a =>\n        have : \u2200 {m k : \u2115}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k := fun {m k} mk m1 e =>\n          a m m1 (le_sqrt.2 (e.symm \u25b8 Nat.mul_le_mul_left m mk)) \u27e8k, e\u27e9\n        fun m m2 l \u27e8k, e\u27e9 => by\n        cases' le_total m k with mk km\n        \u00b7 exact this mk m2 e\n        \u00b7 rw [mul_comm] at e\n          refine' this km (lt_of_mul_lt_mul_right _ (zero_le m)) e\n          rwa [one_mul, \u2190 e]\u27e9\n#align nat.prime_def_le_sqrt Nat.prime_def_le_sqrt\n\ntheorem prime_of_coprime (n : \u2115) (h1 : 1 < n) (h : \u2200 m < n, m \u2260 0 \u2192 n.coprime m) : Prime n := by\n  refine' prime_def_lt.mpr \u27e8h1, fun m mlt mdvd => _\u27e9\n  have hm : m \u2260 0 := by\n    rintro rfl\n    rw [zero_dvd_iff] at mdvd\n    exact mlt.ne' mdvd\n  exact (h m mlt hm).symm.eq_one_of_dvd mdvd\n#align nat.prime_of_coprime Nat.prime_of_coprime\n\nsection\n\n/-- This instance is slower than the instance `decidablePrime` defined below,\n  but has the advantage that it works in the kernel for small values.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `by decide`, but rather `by norm_num`, which is\n  much faster.\n  -/\n@[local instance]\ndef decidablePrime1 (p : \u2115) : Decidable (Prime p) :=\n  decidable_of_iff' _ prime_def_lt'\n#align nat.decidable_prime_1 Nat.decidablePrime1\n\ntheorem prime_two : Prime 2 := by decide\n#align nat.prime_two Nat.prime_two\n\ntheorem prime_three : Prime 3 := by decide\n#align nat.prime_three Nat.prime_three\n\ntheorem Prime.five_le_of_ne_two_of_ne_three {p : \u2115} (hp : p.Prime) (h_two : p \u2260 2)\n    (h_three : p \u2260 3) : 5 \u2264 p := by\n  by_contra' h\n  revert h_two h_three hp\n  -- Porting note: was `decide!`\n  match p with\n  | 0 => decide\n  | 1 => decide\n  | 2 => decide\n  | 3 => decide\n  | 4 => decide\n  | n + 5 => exact (h.not_le le_add_self).elim\n#align nat.prime.five_le_of_ne_two_of_ne_three Nat.Prime.five_le_of_ne_two_of_ne_three\n\nend\n\ntheorem Prime.pred_pos {p : \u2115} (pp : Prime p) : 0 < pred p :=\n  lt_pred_iff.2 pp.one_lt\n#align nat.prime.pred_pos Nat.Prime.pred_pos\n\ntheorem succ_pred_prime {p : \u2115} (pp : Prime p) : succ (pred p) = p :=\n  succ_pred_eq_of_pos pp.pos\n#align nat.succ_pred_prime Nat.succ_pred_prime\n\ntheorem dvd_prime {p m : \u2115} (pp : Prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n  \u27e8fun d => pp.eq_one_or_self_of_dvd m d, fun h =>\n    h.elim (fun e => e.symm \u25b8 one_dvd _) fun e => e.symm \u25b8 dvd_rfl\u27e9\n#align nat.dvd_prime Nat.dvd_prime\n\ntheorem dvd_prime_two_le {p m : \u2115} (pp : Prime p) (H : 2 \u2264 m) : m \u2223 p \u2194 m = p :=\n  (dvd_prime pp).trans <| or_iff_right_of_imp <| Not.elim <| ne_of_gt H\n#align nat.dvd_prime_two_le Nat.dvd_prime_two_le\n\ntheorem prime_dvd_prime_iff_eq {p q : \u2115} (pp : p.Prime) (qp : q.Prime) : p \u2223 q \u2194 p = q :=\n  dvd_prime_two_le qp (Prime.two_le pp)\n#align nat.prime_dvd_prime_iff_eq Nat.prime_dvd_prime_iff_eq\n\ntheorem Prime.not_dvd_one {p : \u2115} (pp : Prime p) : \u00acp \u2223 1 :=\n  Irreducible.not_dvd_one pp\n#align nat.prime.not_dvd_one Nat.Prime.not_dvd_one\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00acPrime (a * b) := fun h =>\n  ne_of_lt (Nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) <| by\n    simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)\n#align nat.not_prime_mul Nat.not_prime_mul\n\ntheorem not_prime_mul' {a b n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) : \u00acPrime n := by\n  rw [\u2190 h]\n  exact not_prime_mul h\u2081 h\u2082\n#align nat.not_prime_mul' Nat.not_prime_mul'\n\ntheorem prime_mul_iff {a b : \u2115} : Nat.Prime (a * b) \u2194 a.Prime \u2227 b = 1 \u2228 b.Prime \u2227 a = 1 := by\n  simp only [iff_self_iff, irreducible_mul_iff, \u2190 irreducible_iff_nat_prime, Nat.isUnit_iff]\n#align nat.prime_mul_iff Nat.prime_mul_iff\n\ntheorem Prime.dvd_iff_eq {p a : \u2115} (hp : p.Prime) (a1 : a \u2260 1) : a \u2223 p \u2194 p = a := by\n  refine'\n    \u27e8_, by\n      rintro rfl\n      rfl\u27e9\n  rintro \u27e8j, rfl\u27e9\n  rcases prime_mul_iff.mp hp with (\u27e8_, rfl\u27e9 | \u27e8_, rfl\u27e9)\n  \u00b7 exact mul_one _\n  \u00b7 exact (a1 rfl).elim\n#align nat.prime.dvd_iff_eq Nat.Prime.dvd_iff_eq\n\nsection MinFac\n\ntheorem minFac_lemma (n k : \u2115) (h : \u00acn < k * k) : sqrt n - k < sqrt n + 2 - k :=\n  (tsub_lt_tsub_iff_right <| le_sqrt.2 <| le_of_not_gt h).2 <| Nat.lt_add_of_pos_right (by decide)\n#align nat.min_fac_lemma Nat.minFac_lemma\n\n/-- If `n < k * k`, then `minFacAux n k = n`, if `k | n`, then `minFacAux n k = k`.\n  Otherwise, `minFacAux n k = minFacAux n (k+2)` using well-founded recursion.\n  If `n` is odd and `1 < n`, then then `minFacAux n 3` is the smallest prime factor of `n`. -/\ndef minFacAux (n : \u2115) : \u2115 \u2192 \u2115\n  | k =>\n    if h : n < k * k then n\n    else\n      if k \u2223 n then k\n      else\n        have := minFac_lemma n k h\n        minFacAux n (k + 2)\ntermination_by _ n k => sqrt n + 2 - k\n#align nat.min_fac_aux Nat.minFacAux\n\n/-- Returns the smallest prime factor of `n \u2260 1`. -/\ndef minFac : \u2115 \u2192 \u2115\n  | 0 => 2\n  | 1 => 1\n  | n + 2 => if 2 \u2223 n then 2 else minFacAux (n + 2) 3\n#align nat.min_fac Nat.minFac\n\n@[simp]\ntheorem minFac_zero : minFac 0 = 2 :=\n  rfl\n#align nat.min_fac_zero Nat.minFac_zero\n\n@[simp]\ntheorem minFac_one : minFac 1 = 1 :=\n  rfl\n#align nat.min_fac_one Nat.minFac_one\n\ntheorem minFac_eq : \u2200 n, minFac n = if 2 \u2223 n then 2 else minFacAux n 3\n  | 0 => by simp\n  | 1 => by simp [show 2 \u2260 1 by decide]\n  | n + 2 => by\n    simp [minFac]\n#align nat.min_fac_eq Nat.minFac_eq\n\nprivate def minFacProp (n k : \u2115) :=\n  2 \u2264 k \u2227 k \u2223 n \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m\n\ntheorem minFacAux_has_prop {n : \u2115} (n2 : 2 \u2264 n) :\n    \u2200 k i, k = 2 * i + 3 \u2192 (\u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 minFacProp n (minFacAux n k)\n  | k => fun i e a => by\n    rw [minFacAux]\n    by_cases h : n < k * k <;> simp [h]\n    \u00b7 have pp : Prime n :=\n        prime_def_le_sqrt.2\n          \u27e8n2, fun m m2 l d => not_lt_of_ge l <| lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9\n      exact \u27e8n2, dvd_rfl, fun m m2 d => le_of_eq ((dvd_prime_two_le pp m2).1 d).symm\u27e9\n    have k2 : 2 \u2264 k := by\n      subst e\n      apply Nat.le_add_left\n    by_cases dk : k \u2223 n <;> simp [dk]\n    \u00b7 exact \u27e8k2, dk, a\u27e9\n    \u00b7 refine'\n        have := minFac_lemma n k h\n        minFacAux_has_prop n2 (k + 2) (i + 1) (by simp [e, left_distrib]) fun m m2 d => _\n      cases' Nat.eq_or_lt_of_le (a m m2 d) with me ml\n      \u00b7 subst me\n        contradiction\n      apply (Nat.eq_or_lt_of_le ml).resolve_left\n      intro me\n      rw [\u2190 me, e] at d\n      have d' : 2 * (i + 2) \u2223 n := d\n      have := a _ le_rfl (dvd_of_mul_right_dvd d')\n      rw [e] at this\n      exact absurd this (by contradiction)\n  termination_by _ n _ k => sqrt n + 2 - k\n#align nat.min_fac_aux_has_prop Nat.minFacAux_has_prop\n\ntheorem minFac_has_prop {n : \u2115} (n1 : n \u2260 1) : minFacProp n (minFac n) := by\n  by_cases n0 : n = 0\n  \u00b7 simp [n0, minFacProp, GE.ge]\n  have n2 : 2 \u2264 n := by\n    revert n0 n1\n    rcases n with (_ | _ | _) <;> simp [succ_le_succ]\n  simp [minFac_eq]\n  by_cases d2 : 2 \u2223 n <;> simp [d2]\n  \u00b7 exact \u27e8le_rfl, d2, fun k k2 _ => k2\u27e9\n  \u00b7 refine'\n      minFacAux_has_prop n2 3 0 rfl fun m m2 d => (Nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)\n    exact fun e => e.symm \u25b8 d\n#align nat.min_fac_has_prop Nat.minFac_has_prop\n\ntheorem minFac_dvd (n : \u2115) : minFac n \u2223 n :=\n  if n1 : n = 1 then by simp [n1] else (minFac_has_prop n1).2.1\n#align nat.min_fac_dvd Nat.minFac_dvd\n\ntheorem minFac_prime {n : \u2115} (n1 : n \u2260 1) : Prime (minFac n) :=\n  let \u27e8f2, fd, a\u27e9 := minFac_has_prop n1\n  prime_def_lt'.2 \u27e8f2, fun m m2 l d => not_le_of_gt l (a m m2 (d.trans fd))\u27e9\n#align nat.min_fac_prime Nat.minFac_prime\n\ntheorem minFac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, 2 \u2264 m \u2192 m \u2223 n \u2192 minFac n \u2264 m := by\n  by_cases n1 : n = 1 <;> [exact fun m2 _ => n1.symm \u25b8 le_trans (by decide) m2,\n    apply (minFac_has_prop n1).2.2]\n#align nat.min_fac_le_of_dvd Nat.minFac_le_of_dvd\n\ntheorem minFac_pos (n : \u2115) : 0 < minFac n := by\n  by_cases n1 : n = 1 <;> [exact n1.symm \u25b8 by decide, exact (minFac_prime n1).pos]\n#align nat.min_fac_pos Nat.minFac_pos\n\ntheorem minFac_le {n : \u2115} (H : 0 < n) : minFac n \u2264 n :=\n  le_of_dvd H (minFac_dvd n)\n#align nat.min_fac_le Nat.minFac_le\n\ntheorem le_minFac {m n : \u2115} : n = 1 \u2228 m \u2264 minFac n \u2194 \u2200 p, Prime p \u2192 p \u2223 n \u2192 m \u2264 p :=\n  \u27e8fun h p pp d =>\n    h.elim (by rintro rfl; cases pp.not_dvd_one d) fun h =>\n      le_trans h <| minFac_le_of_dvd pp.two_le d,\n    fun H => or_iff_not_imp_left.2 fun n1 => H _ (minFac_prime n1) (minFac_dvd _)\u27e9\n#align nat.le_min_fac Nat.le_minFac\n\ntheorem le_minFac' {m n : \u2115} : n = 1 \u2228 m \u2264 minFac n \u2194 \u2200 p, 2 \u2264 p \u2192 p \u2223 n \u2192 m \u2264 p :=\n  \u27e8fun h p (pp : 1 < p) d =>\n    h.elim (by rintro rfl ; cases not_le_of_lt pp (le_of_dvd (by decide) d)) fun h =>\n      le_trans h <| minFac_le_of_dvd pp d,\n    fun H => le_minFac.2 fun p pp d => H p pp.two_le d\u27e9\n#align nat.le_min_fac' Nat.le_minFac'\n\ntheorem prime_def_minFac {p : \u2115} : Prime p \u2194 2 \u2264 p \u2227 minFac p = p :=\n  \u27e8fun pp =>\n    \u27e8pp.two_le,\n      let \u27e8f2, fd, _\u27e9 := minFac_has_prop <| ne_of_gt pp.one_lt\n      ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n    fun \u27e8p2, e\u27e9 => e \u25b8 minFac_prime (ne_of_gt p2)\u27e9\n#align nat.prime_def_min_fac Nat.prime_def_minFac\n\n@[simp]\ntheorem Prime.minFac_eq {p : \u2115} (hp : Prime p) : minFac p = p :=\n  (prime_def_minFac.1 hp).2\n#align nat.prime.min_fac_eq Nat.Prime.minFac_eq\n\n/-- This instance is faster in the virtual machine than `decidablePrime1`,\nbut slower in the kernel.\n\nIf you need to prove that a particular number is prime, in any case\nyou should not use `by decide`, but rather `by norm_num`, which is\nmuch faster.\n-/\ninstance decidablePrime (p : \u2115) : Decidable (Prime p) :=\n  decidable_of_iff' _ prime_def_minFac\n#align nat.decidable_prime Nat.decidablePrime\n\ntheorem not_prime_iff_minFac_lt {n : \u2115} (n2 : 2 \u2264 n) : \u00acPrime n \u2194 minFac n < n :=\n  (not_congr <| prime_def_minFac.trans <| and_iff_right n2).trans <|\n    (lt_iff_le_and_ne.trans <| and_iff_right <| minFac_le <| le_of_succ_le n2).symm\n#align nat.not_prime_iff_min_fac_lt Nat.not_prime_iff_minFac_lt\n\ntheorem minFac_le_div {n : \u2115} (pos : 0 < n) (np : \u00acPrime n) : minFac n \u2264 n / minFac n :=\n  match minFac_dvd n with\n  | \u27e80, h0\u27e9 => absurd pos <| by rw [h0, mul_zero]; exact by decide\n  | \u27e81, h1\u27e9 => by\n    rw [mul_one] at h1\n    rw [prime_def_minFac, not_and_or, \u2190 h1, eq_self_iff_true, _root_.not_true, or_false_iff,\n      not_le] at np\n    rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), minFac_one, Nat.div_one]\n  | \u27e8x + 2, hx\u27e9 => by\n    conv_rhs =>\n      congr\n      rw [hx]\n    rw [Nat.mul_div_cancel_left _ (minFac_pos _)]\n    exact minFac_le_of_dvd (le_add_left 2 x) \u27e8minFac n, by rwa [mul_comm]\u27e9\n#align nat.min_fac_le_div Nat.minFac_le_div\n\n/-- The square of the smallest prime factor of a composite number `n` is at most `n`.\n-/\ntheorem minFac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00acPrime n) : minFac n ^ 2 \u2264 n :=\n  have t : minFac n \u2264 n / minFac n := minFac_le_div w h\n  calc\n    minFac n ^ 2 = minFac n * minFac n := sq (minFac n)\n    _ \u2264 n / minFac n * minFac n := Nat.mul_le_mul_right (minFac n) t\n    _ \u2264 n := div_mul_le_self n (minFac n)\n\n#align nat.min_fac_sq_le_self Nat.minFac_sq_le_self\n\n@[simp]\ntheorem minFac_eq_one_iff {n : \u2115} : minFac n = 1 \u2194 n = 1 := by\n  constructor\n  \u00b7 intro h\n    by_contra hn\n    have := minFac_prime hn\n    rw [h] at this\n    exact not_prime_one this\n  \u00b7 rintro rfl\n    rfl\n#align nat.min_fac_eq_one_iff Nat.minFac_eq_one_iff\n\n@[simp]\ntheorem minFac_eq_two_iff (n : \u2115) : minFac n = 2 \u2194 2 \u2223 n := by\n  constructor\n  \u00b7 intro h\n    rw [\u2190h]\n    exact minFac_dvd n\n  \u00b7 intro h\n    have ub := minFac_le_of_dvd (le_refl 2) h\n    have lb := minFac_pos n\n    refine ub.eq_or_lt.resolve_right fun h' => ?_\n    have := le_antisymm (Nat.succ_le_of_lt lb) (lt_succ_iff.mp h')\n    rw [eq_comm, Nat.minFac_eq_one_iff] at this\n    subst this\n    exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two\n#align nat.min_fac_eq_two_iff Nat.minFac_eq_two_iff\n\nend MinFac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : 2 \u2264 n) (np : \u00acPrime n) : \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n  \u27e8minFac n, minFac_dvd _, ne_of_gt (minFac_prime (ne_of_gt n2)).one_lt,\n    ne_of_lt <| (not_prime_iff_minFac_lt n2).1 np\u27e9\n#align nat.exists_dvd_of_not_prime Nat.exists_dvd_of_not_prime\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : 2 \u2264 n) (np : \u00acPrime n) :\n    \u2203 m, m \u2223 n \u2227 2 \u2264 m \u2227 m < n :=\n  \u27e8minFac n, minFac_dvd _, (minFac_prime (ne_of_gt n2)).two_le,\n    (not_prime_iff_minFac_lt n2).1 np\u27e9\n#align nat.exists_dvd_of_not_prime2 Nat.exists_dvd_of_not_prime2\n\ntheorem exists_prime_and_dvd {n : \u2115} (hn : n \u2260 1) : \u2203 p, Prime p \u2227 p \u2223 n :=\n  \u27e8minFac n, minFac_prime hn, minFac_dvd _\u27e9\n#align nat.exists_prime_and_dvd Nat.exists_prime_and_dvd\n\ntheorem dvd_of_forall_prime_mul_dvd {a b : \u2115}\n    (hdvd : \u2200 p : \u2115, p.Prime \u2192 p \u2223 a \u2192 p * a \u2223 b) : a \u2223 b := by\n  obtain rfl | ha := eq_or_ne a 1\n  \u00b7 apply one_dvd\n  obtain \u27e8p, hp\u27e9 := exists_prime_and_dvd ha\n  exact _root_.trans (dvd_mul_left a p) (hdvd p hp.1 hp.2)\n#align nat.dvd_of_forall_prime_mul_dvd Nat.dvd_of_forall_prime_mul_dvd\n\n/-- Euclid's theorem on the **infinitude of primes**.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, n \u2264 p \u2227 Prime p :=\n  let p := minFac (n ! + 1)\n  have f1 : n ! + 1 \u2260 1 := ne_of_gt <| succ_lt_succ <| factorial_pos _\n  have pp : Prime p := minFac_prime f1\n  have np : n \u2264 p :=\n    le_of_not_ge fun h =>\n      have h\u2081 : p \u2223 n ! := dvd_factorial (minFac_pos _) h\n      have h\u2082 : p \u2223 1 := (Nat.dvd_add_iff_right h\u2081).2 (minFac_dvd _)\n      pp.not_dvd_one h\u2082\n  \u27e8p, np, pp\u27e9\n#align nat.exists_infinite_primes Nat.exists_infinite_primes\n\n/-- A version of `Nat.exists_infinite_primes` using the `BddAbove` predicate. -/\ntheorem not_bddAbove_setOf_prime : \u00acBddAbove { p | Prime p } := by\n  rw [not_bddAbove_iff]\n  intro n\n  obtain \u27e8p, hi, hp\u27e9 := exists_infinite_primes n.succ\n  exact \u27e8p, hp, hi\u27e9\n#align nat.not_bdd_above_set_of_prime Nat.not_bddAbove_setOf_prime\n\ntheorem Prime.eq_two_or_odd {p : \u2115} (hp : Prime p) : p = 2 \u2228 p % 2 = 1 :=\n  p.mod_two_eq_zero_or_one.imp_left fun h =>\n    ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left (by decide)).symm\n#align nat.prime.eq_two_or_odd Nat.Prime.eq_two_or_odd\n\ntheorem Prime.eq_two_or_odd' {p : \u2115} (hp : Prime p) : p = 2 \u2228 Odd p :=\n  Or.imp_right (fun h => \u27e8p / 2, (div_add_mod p 2).symm.trans (congr_arg _ h)\u27e9) hp.eq_two_or_odd\n#align nat.prime.eq_two_or_odd' Nat.Prime.eq_two_or_odd'\n\ntheorem Prime.even_iff {p : \u2115} (hp : Prime p) : Even p \u2194 p = 2 := by\n  rw [even_iff_two_dvd, prime_dvd_prime_iff_eq prime_two hp, eq_comm]\n#align nat.prime.even_iff Nat.Prime.even_iff\n\ntheorem Prime.odd_of_ne_two {p : \u2115} (hp : p.Prime) (h_two : p \u2260 2) : Odd p :=\n  hp.eq_two_or_odd'.resolve_left h_two\n#align nat.prime.odd_of_ne_two Nat.Prime.odd_of_ne_two\n\n\n\n/-- A prime `p` satisfies `p % 2 = 1` if and only if `p \u2260 2`. -/\ntheorem Prime.mod_two_eq_one_iff_ne_two {p : \u2115} [Fact p.Prime] : p % 2 = 1 \u2194 p \u2260 2 := by\n  refine' \u27e8fun h hf => _, (Nat.Prime.eq_two_or_odd <| @Fact.out p.Prime _).resolve_left\u27e9\n  rw [hf] at h\n  simp at h\n#align nat.prime.mod_two_eq_one_iff_ne_two Nat.Prime.mod_two_eq_one_iff_ne_two\n\ntheorem coprime_of_dvd {m n : \u2115} (H : \u2200 k, Prime k \u2192 k \u2223 m \u2192 \u00ack \u2223 n) : coprime m n := by\n  rw [coprime_iff_gcd_eq_one]\n  by_contra g2\n  obtain \u27e8p, hp, hpdvd\u27e9 := exists_prime_and_dvd g2\n  apply H p hp <;> apply dvd_trans hpdvd\n  \u00b7 exact gcd_dvd_left _ _\n  \u00b7 exact gcd_dvd_right _ _\n#align nat.coprime_of_dvd Nat.coprime_of_dvd\n\ntheorem coprime_of_dvd' {m n : \u2115} (H : \u2200 k, Prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) : coprime m n :=\n  coprime_of_dvd fun k kp km kn => not_le_of_gt kp.one_lt <| le_of_dvd zero_lt_one <| H k kp km kn\n#align nat.coprime_of_dvd' Nat.coprime_of_dvd'\n\ntheorem factors_lemma {k} : (k + 2) / minFac (k + 2) < k + 2 :=\n  div_lt_self (Nat.zero_lt_succ _) (minFac_prime (by\n      apply Nat.ne_of_gt\n      apply Nat.succ_lt_succ\n      apply Nat.zero_lt_succ\n      )).one_lt\n#align nat.factors_lemma Nat.factors_lemma\n\ntheorem Prime.coprime_iff_not_dvd {p n : \u2115} (pp : Prime p) : coprime p n \u2194 \u00acp \u2223 n :=\n  \u27e8fun co d => pp.not_dvd_one <| co.dvd_of_dvd_mul_left (by simp [d]), fun nd =>\n    coprime_of_dvd fun m m2 mp => ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm \u25b8 nd\u27e9\n#align nat.prime.coprime_iff_not_dvd Nat.Prime.coprime_iff_not_dvd\n\ntheorem Prime.dvd_iff_not_coprime {p n : \u2115} (pp : Prime p) : p \u2223 n \u2194 \u00accoprime p n :=\n  iff_not_comm.2 pp.coprime_iff_not_dvd\n#align nat.prime.dvd_iff_not_coprime Nat.Prime.dvd_iff_not_coprime\n\ntheorem Prime.not_coprime_iff_dvd {m n : \u2115} : \u00accoprime m n \u2194 \u2203 p, Prime p \u2227 p \u2223 m \u2227 p \u2223 n := by\n  apply Iff.intro\n  \u00b7 intro h\n    exact\n      \u27e8minFac (gcd m n), minFac_prime h, (minFac_dvd (gcd m n)).trans (gcd_dvd_left m n),\n        (minFac_dvd (gcd m n)).trans (gcd_dvd_right m n)\u27e9\n  \u00b7 intro h\n    cases' h with p hp\n    apply Nat.not_coprime_of_dvd_of_dvd (Prime.one_lt hp.1) hp.2.1 hp.2.2\n#align nat.prime.not_coprime_iff_dvd Nat.Prime.not_coprime_iff_dvd\n\ntheorem Prime.dvd_mul {p m n : \u2115} (pp : Prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n  \u27e8fun H => or_iff_not_imp_left.2 fun h => (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n    Or.rec (fun h : p \u2223 m => h.mul_right _) fun h : p \u2223 n => h.mul_left _\u27e9\n#align nat.prime.dvd_mul Nat.Prime.dvd_mul\n\ntheorem Prime.not_dvd_mul {p m n : \u2115} (pp : Prime p) (Hm : \u00acp \u2223 m) (Hn : \u00acp \u2223 n) : \u00acp \u2223 m * n :=\n  mt pp.dvd_mul.1 <| by simp [Hm, Hn]\n#align nat.prime.not_dvd_mul Nat.Prime.not_dvd_mul\n\ntheorem prime_iff {p : \u2115} : p.Prime \u2194 _root_.Prime p :=\n  \u27e8fun h => \u27e8h.ne_zero, h.not_unit, fun _ _ => h.dvd_mul.mp\u27e9, Prime.irreducible\u27e9\n#align nat.prime_iff Nat.prime_iff\n\nalias prime_iff \u2194 Prime.prime _root_.Prime.nat_prime\n#align nat.prime.prime Nat.Prime.prime\n#align prime.nat_prime Prime.nat_prime\n\n-- Porting note: attributes `protected`, `nolint dup_namespace` removed\n\ntheorem irreducible_iff_prime {p : \u2115} : Irreducible p \u2194 _root_.Prime p :=\n  prime_iff\n#align nat.irreducible_iff_prime Nat.irreducible_iff_prime\n\ntheorem Prime.dvd_of_dvd_pow {p m n : \u2115} (pp : Prime p) (h : p \u2223 m ^ n) : p \u2223 m := by\n  induction' n with n IH\n  \u00b7 exact pp.not_dvd_one.elim h\n  \u00b7 rw [pow_succ] at h\n    exact (pp.dvd_mul.1 h).elim IH id\n#align nat.prime.dvd_of_dvd_pow Nat.Prime.dvd_of_dvd_pow\n\ntheorem Prime.pow_not_prime {x n : \u2115} (hn : 2 \u2264 n) : \u00ac(x ^ n).Prime := fun hp =>\n  (hp.eq_one_or_self_of_dvd x <| dvd_trans \u27e8x, sq _\u27e9 (pow_dvd_pow _ hn)).elim\n    (fun hx1 => hp.ne_one <| hx1.symm \u25b8 one_pow _) fun hxn =>\n    lt_irrefl x <|\n      calc\n        x = x ^ 1 := (pow_one _).symm\n        _ < x ^ n := Nat.pow_right_strictMono (hxn.symm \u25b8 hp.two_le) hn\n        _ = x := hxn.symm\n\n#align nat.prime.pow_not_prime Nat.Prime.pow_not_prime\n\ntheorem Prime.pow_not_prime' {x : \u2115} : \u2200 {n : \u2115}, n \u2260 1 \u2192 \u00ac(x ^ n).Prime\n  | 0 => fun _ => not_prime_one\n  | 1 => fun h => (h rfl).elim\n  | _ + 2 => fun _ => Prime.pow_not_prime le_add_self\n#align nat.prime.pow_not_prime' Nat.Prime.pow_not_prime'\n\ntheorem Prime.eq_one_of_pow {x n : \u2115} (h : (x ^ n).Prime) : n = 1 :=\n  not_imp_not.mp Prime.pow_not_prime' h\n#align nat.prime.eq_one_of_pow Nat.Prime.eq_one_of_pow\n\ntheorem Prime.pow_eq_iff {p a k : \u2115} (hp : p.Prime) : a ^ k = p \u2194 a = p \u2227 k = 1 := by\n  refine' \u27e8fun h => _, fun h => by rw [h.1, h.2, pow_one]\u27e9\n  rw [\u2190 h] at hp\n  rw [\u2190 h, hp.eq_one_of_pow, eq_self_iff_true, and_true_iff, pow_one]\n#align nat.prime.pow_eq_iff Nat.Prime.pow_eq_iff\n\ntheorem pow_minFac {n k : \u2115} (hk : k \u2260 0) : (n ^ k).minFac = n.minFac := by\n  rcases eq_or_ne n 1 with (rfl | hn)\n  \u00b7 simp\n  have hnk : n ^ k \u2260 1 := fun hk' => hn ((pow_eq_one_iff hk).1 hk')\n  apply (minFac_le_of_dvd (minFac_prime hn).two_le ((minFac_dvd n).pow hk)).antisymm\n  apply\n    minFac_le_of_dvd (minFac_prime hnk).two_le\n      ((minFac_prime hnk).dvd_of_dvd_pow (minFac_dvd _))\n#align nat.pow_min_fac Nat.pow_minFac\n\ntheorem Prime.pow_minFac {p k : \u2115} (hp : p.Prime) (hk : k \u2260 0) : (p ^ k).minFac = p := by\n  rw [Nat.pow_minFac hk, hp.minFac_eq]\n#align nat.prime.pow_min_fac Nat.Prime.pow_minFac\n\ntheorem Prime.mul_eq_prime_sq_iff {x y p : \u2115} (hp : p.Prime) (hx : x \u2260 1) (hy : y \u2260 1) :\n    x * y = p ^ 2 \u2194 x = p \u2227 y = p := by\n    refine' \u27e8fun h => _, fun \u27e8h\u2081, h\u2082\u27e9 => h\u2081.symm \u25b8 h\u2082.symm \u25b8 (sq _).symm\u27e9\n    have pdvdxy : p \u2223 x * y := by rw [h]; simp [sq]\n    -- Could be `wlog := hp.dvd_mul.1 pdvdxy using x y`, but that imports more than we want.\n    suffices \u2200 x' y' : \u2115, x' \u2260 1 \u2192 y' \u2260 1 \u2192 x' * y' = p ^ 2 \u2192 p \u2223 x' \u2192 x' = p \u2227 y' = p by\n      obtain hx | hy := hp.dvd_mul.1 pdvdxy <;>\n        [skip, rw [And.comm]] <;>\n        [skip, rw [mul_comm] at h pdvdxy] <;>\n        apply this <;>\n        assumption\n    rintro x y hx hy h \u27e8a, ha\u27e9\n    have : a \u2223 p := \u27e8y, by rwa [ha, sq, mul_assoc, mul_right_inj' hp.ne_zero, eq_comm] at h\u27e9\n    obtain ha1 | hap := (Nat.dvd_prime hp).mp \u2039a \u2223 p\u203a\n    \u00b7 subst ha1\n      rw [mul_one] at ha\n      subst ha\n      simp only [sq, mul_right_inj' hp.ne_zero] at h\n      subst h\n      exact \u27e8rfl, rfl\u27e9\n    \u00b7 refine' (hy ?_).elim\n      subst hap\n      subst ha\n      rw [sq, Nat.mul_right_eq_self_iff (Nat.mul_pos hp.pos hp.pos : 0 < a * a)] at h\n      exact h\n\n#align nat.prime.mul_eq_prime_sq_iff Nat.Prime.mul_eq_prime_sq_iff\n\ntheorem Prime.dvd_factorial : \u2200 {n p : \u2115} (_ : Prime p), p \u2223 n ! \u2194 p \u2264 n\n  | 0, p, hp => iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)\n  | n + 1, p, hp => by\n    rw [factorial_succ, hp.dvd_mul, Prime.dvd_factorial hp]\n    exact\n      \u27e8fun h => h.elim (le_of_dvd (succ_pos _)) le_succ_of_le, fun h =>\n        (_root_.lt_or_eq_of_le h).elim (Or.inr \u2218 le_of_lt_succ) fun h => Or.inl <| by rw [h]\u27e9\n#align nat.prime.dvd_factorial Nat.Prime.dvd_factorial\n\ntheorem Prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : Prime p) (h : \u00acp \u2223 a) : coprime a (p ^ m) :=\n  (pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n#align nat.prime.coprime_pow_of_not_dvd Nat.Prime.coprime_pow_of_not_dvd\n\ntheorem coprime_primes {p q : \u2115} (pp : Prime p) (pq : Prime q) : coprime p q \u2194 p \u2260 q :=\n  pp.coprime_iff_not_dvd.trans <| not_congr <| dvd_prime_two_le pq pp.two_le\n#align nat.coprime_primes Nat.coprime_primes\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : Prime p) (pq : Prime q) (h : p \u2260 q) :\n    coprime (p ^ n) (q ^ m) :=\n  ((coprime_primes pp pq).2 h).pow _ _\n#align nat.coprime_pow_primes Nat.coprime_pow_primes\n\ntheorem coprime_or_dvd_of_prime {p} (pp : Prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i := by\n  rw [pp.dvd_iff_not_coprime] ; apply em\n#align nat.coprime_or_dvd_of_prime Nat.coprime_or_dvd_of_prime\n\ntheorem coprime_of_lt_prime {n p} (n_pos : 0 < n) (hlt : n < p) (pp : Prime p) : coprime p n :=\n  (coprime_or_dvd_of_prime pp n).resolve_right fun h => lt_le_antisymm hlt (le_of_dvd n_pos h)\n#align nat.coprime_of_lt_prime Nat.coprime_of_lt_prime\n\ntheorem eq_or_coprime_of_le_prime {n p} (n_pos : 0 < n) (hle : n \u2264 p) (pp : Prime p) :\n    p = n \u2228 coprime p n :=\n  hle.eq_or_lt.imp Eq.symm fun h => coprime_of_lt_prime n_pos h pp\n#align nat.eq_or_coprime_of_le_prime Nat.eq_or_coprime_of_le_prime\n\ntheorem dvd_prime_pow {p : \u2115} (pp : Prime p) {m i : \u2115} : i \u2223 p ^ m \u2194 \u2203 k \u2264 m, i = p ^ k := by\n  simp_rw [_root_.dvd_prime_pow  (prime_iff.mp pp)  m, associated_eq_eq]\n#align nat.dvd_prime_pow Nat.dvd_prime_pow\n\ntheorem Prime.dvd_mul_of_dvd_ne {p1 p2 n : \u2115} (h_neq : p1 \u2260 p2) (pp1 : Prime p1) (pp2 : Prime p2)\n    (h1 : p1 \u2223 n) (h2 : p2 \u2223 n) : p1 * p2 \u2223 n :=\n  coprime.mul_dvd_of_dvd_of_dvd ((coprime_primes pp1 pp2).mpr h_neq) h1 h2\n#align nat.prime.dvd_mul_of_dvd_ne Nat.Prime.dvd_mul_of_dvd_ne\n\n/-- If `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\ntheorem eq_prime_pow_of_dvd_least_prime_pow {a p k : \u2115} (pp : Prime p) (h\u2081 : \u00aca \u2223 p ^ k)\n    (h\u2082 : a \u2223 p ^ (k + 1)) : a = p ^ (k + 1) := by\n  obtain \u27e8l, \u27e8h, rfl\u27e9\u27e9 := (dvd_prime_pow pp).1 h\u2082\n  congr\n  exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (Prime.one_lt pp))).1 h\u2081))\n#align nat.eq_prime_pow_of_dvd_least_prime_pow Nat.eq_prime_pow_of_dvd_least_prime_pow\n\ntheorem ne_one_iff_exists_prime_dvd : \u2200 {n}, n \u2260 1 \u2194 \u2203 p : \u2115, p.Prime \u2227 p \u2223 n\n  | 0 => by simpa using Exists.intro 2 Nat.prime_two\n  | 1 => by simp [Nat.not_prime_one]\n  | n + 2 => by\n    let a := n + 2\n    let ha : a \u2260 1 := Nat.succ_succ_ne_one n\n    simp only [true_iff_iff, Ne.def, not_false_iff, ha]\n    exact \u27e8a.minFac, Nat.minFac_prime ha, a.minFac_dvd\u27e9\n#align nat.ne_one_iff_exists_prime_dvd Nat.ne_one_iff_exists_prime_dvd\n\ntheorem eq_one_iff_not_exists_prime_dvd {n : \u2115} : n = 1 \u2194 \u2200 p : \u2115, p.Prime \u2192 \u00acp \u2223 n := by\n  simpa using not_iff_not.mpr ne_one_iff_exists_prime_dvd\n#align nat.eq_one_iff_not_exists_prime_dvd Nat.eq_one_iff_not_exists_prime_dvd\n\ntheorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : Prime p) {m n k l : \u2115}\n    (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k + l + 1) \u2223 m * n) :\n    p ^ (k + 1) \u2223 m \u2228 p ^ (l + 1) \u2223 n := by\n  have hpd : p ^ (k + l) * p \u2223 m * n := by\n      let hpmn' : p ^ (succ (k + l)) \u2223 m * n := hpmn\n      rwa [pow_succ'] at hpmn'\n  have hpd2 : p \u2223 m * n / p ^ (k + l) := dvd_div_of_mul_dvd hpd\n  have hpd3 : p \u2223 m * n / (p ^ k * p ^ l) := by simpa [pow_add] using hpd2\n  have hpd4 : p \u2223 m / p ^ k * (n / p ^ l) := by simpa [Nat.div_mul_div_comm hpm hpn] using hpd3\n  have hpd5 : p \u2223 m / p ^ k \u2228 p \u2223 n / p ^ l :=\n    (Prime.dvd_mul p_prime).1 hpd4\n  suffices p ^ k * p \u2223 m \u2228 p ^ l * p \u2223 n by rwa [_root_.pow_succ', _root_.pow_succ']\n  exact hpd5.elim (fun h : p \u2223 m / p ^ k => Or.inl <| mul_dvd_of_dvd_div hpm h)\n    fun h : p \u2223 n / p ^ l => Or.inr <| mul_dvd_of_dvd_div hpn h\n#align nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul Nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul\n\ntheorem prime_iff_prime_int {p : \u2115} : p.Prime \u2194 _root_.Prime (p : \u2124) :=\n  \u27e8fun hp =>\n    \u27e8Int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt Int.isUnit_iff_natAbs_eq.1 hp.ne_one, fun a b h => by\n      rw [\u2190 Int.dvd_natAbs, Int.coe_nat_dvd, Int.natAbs_mul, hp.dvd_mul] at h ;\n        rwa [\u2190 Int.dvd_natAbs, Int.coe_nat_dvd, \u2190 Int.dvd_natAbs, Int.coe_nat_dvd]\u27e9,\n    fun hp =>\n    Nat.prime_iff.2\n      \u27e8Int.coe_nat_ne_zero.1 hp.1,\n        (mt Nat.isUnit_iff.1) fun h => by simp [h, not_prime_one] at hp, fun a b => by\n        simpa only [Int.coe_nat_dvd, (Int.ofNat_mul _ _).symm] using hp.2.2 a b\u27e9\u27e9\n#align nat.prime_iff_prime_int Nat.prime_iff_prime_int\n\n/-- The type of prime numbers -/\ndef Primes :=\n  { p : \u2115 // p.Prime }\n  deriving DecidableEq\n#align nat.primes Nat.Primes\n\nnamespace Primes\n\ninstance : Repr Nat.Primes :=\n  \u27e8fun p _ => repr p.val\u27e9\n\ninstance inhabitedPrimes : Inhabited Primes :=\n  \u27e8\u27e82, prime_two\u27e9\u27e9\n#align nat.primes.inhabited_primes Nat.Primes.inhabitedPrimes\n\ninstance coeNat : Coe Nat.Primes \u2115 :=\n  \u27e8Subtype.val\u27e9\n#align nat.primes.coe_nat Nat.Primes.coeNat\n\n-- Porting note: change in signature to match change in coercion\ntheorem coe_nat_injective : Function.Injective (fun (a : Nat.Primes) \u21a6 (a : \u2115)) :=\n  Subtype.coe_injective\n#align nat.primes.coe_nat_injective Nat.Primes.coe_nat_injective\n\ntheorem coe_nat_inj (p q : Nat.Primes) : (p : \u2115) = (q : \u2115) \u2194 p = q :=\n  Subtype.ext_iff.symm\n#align nat.primes.coe_nat_inj Nat.Primes.coe_nat_inj\n\nend Primes\n\ninstance monoid.primePow {\u03b1 : Type _} [Monoid \u03b1] : Pow \u03b1 Primes :=\n  \u27e8fun x p => x ^ (p : \u2115)\u27e9\n#align nat.monoid.prime_pow Nat.monoid.primePow\n\nend Nat\n\nnamespace Nat\n\ninstance fact_prime_two : Fact (Prime 2) :=\n  \u27e8prime_two\u27e9\n#align nat.fact_prime_two Nat.fact_prime_two\n\ninstance fact_prime_three : Fact (Prime 3) :=\n  \u27e8prime_three\u27e9\n#align nat.fact_prime_three Nat.fact_prime_three\n\nend Nat\n\nnamespace Int\n\ntheorem prime_two : Prime (2 : \u2124) :=\n  Nat.prime_iff_prime_int.mp Nat.prime_two\n#align int.prime_two Int.prime_two\n\ntheorem prime_three : Prime (3 : \u2124) :=\n  Nat.prime_iff_prime_int.mp Nat.prime_three\n#align int.prime_three Int.prime_three\n\nend Int\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.738667705024067}}
{"text": "import group_theory.group_action\nimport algebra.group\nimport category_theory.category.Groupoid\n/--\n## Let G be a group and X a G-set (i.e a set with an G action), we make the so called 'action groupoid' \n## This is a category with obj  : X and for x y \u2208 X, hom(x,y) = Transporteur (x,y)  := { g \u2208 G | g \u2022 x = y} \n##  The composition is given by the group law.    \n-/\n\ndef Transporteur (G : Type )[group G](X : Type )[mul_action  G X] (x y : X) : set G  := { g : G | g \u2022 x = y}\nlemma mem_transporteur (G : Type )[group G](X : Type )[mul_action  G X] (x y : X)(g : G) : \n        (g \u2208 Transporteur G X x y) \u2194 g \u2022 x = y :=\n        begin \n            split,\n            intro,\n            cases a, \n            exact rfl, ---------- Grrrrouhhhhhhhhh :  how to simplify \n            intro,\n            cases a,\n            exact rfl,\n        end\nsection Transposteur \nparameters (G : Type )[group G](X : Type )[mul_action  G X]\ndef one_in_transporteur : \u2200 x y : X, (1 : G) \u2208 (Transporteur G X x y) \u2194 (x = y) := \n    begin \n        intros x y,\n        rw mem_transporteur  (G) (X) (x) (y) (1),\n        split,\n        intro,\n        cases a,\n        exact eq.symm (one_smul G x ),\n        intro,\n        cases a,\n        exact one_smul G x,\n    end \nlemma transporteur_comp (x y z : X) : (Transporteur G X  x y) \u2192 (Transporteur G X y z ) \u2192 (Transporteur G X x z) := \n    \u03bb \u27e8g,proof_g\u27e9 \u27e8h, proof_h\u27e9,  begin  \n        have H : (h * g) \u2022 x = z,\n            rw mul_smul,\n            rw mem_transporteur at proof_g,\n            rw proof_g,\n            rw mem_transporteur at proof_h,\n            rw proof_h,\n        use (h * g),\n        exact H,\n    end\nlemma transporteur_inv (x y : X) : (Transporteur G X x y) \u2192 (Transporteur G X y x) := \n\u03bb \u27e8g,proof_g\u27e9, begin \n    rw mem_transporteur at proof_g, \n    have H : x = g\u207b\u00b9 \u2022 y,\n        rw \u2190 proof_g,\n        rw \u2190  mul_smul,\n        rw  inv_mul_self,\n        rw one_smul,\n    use g\u207b\u00b9,\n    exact eq.symm H,\nend \nend Transposteur\nopen category_theory\nsection\nvariables (G : Type )[group G](X : Type)[mul_action  G X]\n\nend\n", "meta": {"author": "Or7ando", "repo": "lean", "sha": "d41169cf4e416a0d42092fb6bdc14131cee9dd15", "save_path": "github-repos/lean/Or7ando-lean", "path": "github-repos/lean/Or7ando-lean/lean-d41169cf4e416a0d42092fb6bdc14131cee9dd15/.github/workflows/project_1_a_decrire/group_action/action_groupe_to_groupoid.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395157060208, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7386676920516704}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.box_integral.partition.basic\n\n/-!\n# Split a box along one or more hyperplanes\n\n## Main definitions\n\nA hyperplane `{x : \u03b9 \u2192 \u211d | x i = a}` splits a rectangular box `I : box_integral.box \u03b9` into two\nsmaller boxes. If `a \u2209 Ioo (I.lower i, I.upper i)`, then one of these boxes is empty, so it is not a\nbox in the sense of `box_integral.box`.\n\nWe introduce the following definitions.\n\n* `box_integral.box.split_lower I i a` and `box_integral.box.split_upper I i a` are these boxes (as\n  `with_bot (box_integral.box \u03b9)`);\n* `box_integral.prepartition.split I i a` is the partition of `I` made of these two boxes (or of one\n   box `I` if one of these boxes is empty);\n* `box_integral.prepartition.split_many I s`, where `s : finset (\u03b9 \u00d7 \u211d)` is a finite set of\n  hyperplanes `{x : \u03b9 \u2192 \u211d | x i = a}` encoded as pairs `(i, a)`, is the partition of `I` made by\n  cutting it along all the hyperplanes in `s`.\n\n## Main results\n\nThe main result `box_integral.prepartition.exists_Union_eq_diff` says that any prepartition `\u03c0` of\n`I` admits a prepartition `\u03c0'` of `I` that covers exactly `I \\ \u03c0.Union`. One of these prepartitions\nis available as `box_integral.prepartition.compl`.\n\n## Tags\n\nrectangular box, partition, hyperplane\n-/\n\nnoncomputable theory\nopen_locale classical big_operators filter\nopen function set filter\n\nnamespace box_integral\n\nvariables {\u03b9 M : Type*} {n : \u2115}\n\nnamespace box\n\nvariables {I : box \u03b9} {i : \u03b9} {x : \u211d} {y : \u03b9 \u2192 \u211d}\n\n/-- Given a box `I` and `x \u2208 (I.lower i, I.upper i)`, the hyperplane `{y : \u03b9 \u2192 \u211d | y i = x}` splits\n`I` into two boxes. `box_integral.box.split_lower I i x` is the box `I \u2229 {y | y i \u2264 x}`\n(if it is nonempty). As usual, we represent a box that may be empty as\n`with_bot (box_integral.box \u03b9)`. -/\ndef split_lower (I : box \u03b9) (i : \u03b9) (x : \u211d) : with_bot (box \u03b9) :=\nmk' I.lower (update I.upper i (min x (I.upper i)))\n\n@[simp] lemma coe_split_lower : (split_lower I i x : set (\u03b9 \u2192 \u211d)) = I \u2229 {y | y i \u2264 x} :=\nbegin\n  rw [split_lower, coe_mk'],\n  ext y,\n  simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_set_of_eq, forall_and_distrib,\n    \u2190 pi.le_def, le_update_iff, le_min_iff, and_assoc, and_forall_ne i, mem_def],\n  rw [and_comm (y i \u2264 x), pi.le_def]\nend\n\nlemma split_lower_le : I.split_lower i x \u2264 I := with_bot_coe_subset_iff.1 $ by simp\n\n@[simp] lemma split_lower_eq_bot {i x} : I.split_lower i x = \u22a5 \u2194 x \u2264 I.lower i :=\nbegin\n  rw [split_lower, mk'_eq_bot, exists_update_iff I.upper (\u03bb j y, y \u2264 I.lower j)],\n  simp [(I.lower_lt_upper _).not_le]\nend\n\n@[simp] lemma split_lower_eq_self : I.split_lower i x = I \u2194 I.upper i \u2264 x :=\nby simp [split_lower, update_eq_iff]\n\nlemma split_lower_def [decidable_eq \u03b9] {i x} (h : x \u2208 Ioo (I.lower i) (I.upper i))\n  (h' : \u2200 j, I.lower j < update I.upper i x j :=\n    (forall_update_iff I.upper (\u03bb j y, I.lower j < y)).2 \u27e8h.1, \u03bb j hne, I.lower_lt_upper _\u27e9) :\n  I.split_lower i x = (\u27e8I.lower, update I.upper i x, h'\u27e9 : box \u03b9) :=\nby { simp only [split_lower, mk'_eq_coe, min_eq_left h.2.le], use rfl, congr }\n\n/-- Given a box `I` and `x \u2208 (I.lower i, I.upper i)`, the hyperplane `{y : \u03b9 \u2192 \u211d | y i = x}` splits\n`I` into two boxes. `box_integral.box.split_upper I i x` is the box `I \u2229 {y | x < y i}`\n(if it is nonempty). As usual, we represent a box that may be empty as\n`with_bot (box_integral.box \u03b9)`. -/\ndef split_upper (I : box \u03b9) (i : \u03b9) (x : \u211d) : with_bot (box \u03b9) :=\nmk' (update I.lower i (max x (I.lower i))) I.upper\n\n@[simp] lemma coe_split_upper : (split_upper I i x : set (\u03b9 \u2192 \u211d)) = I \u2229 {y | x < y i} :=\nbegin\n  rw [split_upper, coe_mk'],\n  ext y,\n  simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_set_of_eq, forall_and_distrib,\n    forall_update_iff I.lower (\u03bb j z, z < y j), max_lt_iff, and_assoc (x < y i),\n    and_forall_ne i, mem_def],\n  exact and_comm _ _\nend\n\nlemma split_upper_le : I.split_upper i x \u2264 I := with_bot_coe_subset_iff.1 $ by simp\n\n@[simp] lemma split_upper_eq_bot {i x} : I.split_upper i x = \u22a5 \u2194 I.upper i \u2264 x :=\nbegin\n  rw [split_upper, mk'_eq_bot, exists_update_iff I.lower (\u03bb j y, I.upper j \u2264 y)],\n  simp [(I.lower_lt_upper _).not_le]\nend\n\n@[simp] lemma split_upper_eq_self : I.split_upper i x = I \u2194 x \u2264 I.lower i :=\nby simp [split_upper, update_eq_iff]\n\nlemma split_upper_def [decidable_eq \u03b9] {i x} (h : x \u2208 Ioo (I.lower i) (I.upper i))\n  (h' : \u2200 j, update I.lower i x j < I.upper j :=\n    (forall_update_iff I.lower (\u03bb j y, y < I.upper j)).2 \u27e8h.2, \u03bb j hne, I.lower_lt_upper _\u27e9) :\n  I.split_upper i x = (\u27e8update I.lower i x, I.upper, h'\u27e9 : box \u03b9) :=\nby { simp only [split_upper, mk'_eq_coe, max_eq_left h.1.le], refine \u27e8_, rfl\u27e9, congr }\n\nlemma disjoint_split_lower_split_upper (I : box \u03b9) (i : \u03b9) (x : \u211d) :\n  disjoint (I.split_lower i x) (I.split_upper i x) :=\nbegin\n  rw [\u2190 disjoint_with_bot_coe, coe_split_lower, coe_split_upper],\n  refine (disjoint.inf_left' _ _).inf_right' _,\n  rw set.disjoint_left,\n  exact \u03bb y (hle : y i \u2264 x) hlt, not_lt_of_le hle hlt\nend\n\nlemma split_lower_ne_split_upper (I : box \u03b9) (i : \u03b9) (x : \u211d) :\n  I.split_lower i x \u2260 I.split_upper i x :=\nbegin\n  cases le_or_lt x (I.lower i),\n  { rw [split_upper_eq_self.2 h, split_lower_eq_bot.2 h], exact with_bot.bot_ne_coe },\n  { refine (disjoint_split_lower_split_upper I i x).ne _,\n    rwa [ne.def, split_lower_eq_bot, not_le] }\nend\nend box\n\nnamespace prepartition\n\nvariables {I J : box \u03b9} {i : \u03b9} {x : \u211d}\n\n/-- The partition of `I : box \u03b9` into the boxes `I \u2229 {y | y \u2264 x i}` and `I \u2229 {y | x i < y}`.\nOne of these boxes can be empty, then this partition is just the single-box partition `\u22a4`. -/\ndef split (I : box \u03b9) (i : \u03b9) (x : \u211d) : prepartition I :=\nof_with_bot {I.split_lower i x, I.split_upper i x}\n  begin\n    simp only [finset.mem_insert, finset.mem_singleton],\n    rintro J (rfl|rfl),\n    exacts [box.split_lower_le, box.split_upper_le]\n  end\n  begin\n    simp only [finset.coe_insert, finset.coe_singleton, true_and, set.mem_singleton_iff,\n      pairwise_insert_of_symmetric symmetric_disjoint, pairwise_singleton],\n    rintro J rfl -,\n    exact I.disjoint_split_lower_split_upper i x\n  end\n\n@[simp] lemma mem_split_iff : J \u2208 split I i x \u2194 \u2191J = I.split_lower i x \u2228 \u2191J = I.split_upper i x :=\nby simp [split]\n\nlemma mem_split_iff' : J \u2208 split I i x \u2194\n  (J : set (\u03b9 \u2192 \u211d)) = I \u2229 {y | y i \u2264 x} \u2228 (J : set (\u03b9 \u2192 \u211d)) = I \u2229 {y | x < y i} :=\nby simp [mem_split_iff, \u2190 box.with_bot_coe_inj]\n\n@[simp] lemma Union_split (I : box \u03b9) (i : \u03b9) (x : \u211d) : (split I i x).Union = I :=\nby simp [split, \u2190 inter_union_distrib_left, \u2190 set_of_or, le_or_lt]\n\nlemma is_partition_split (I : box \u03b9) (i : \u03b9) (x : \u211d) : is_partition (split I i x) :=\nis_partition_iff_Union_eq.2 $ Union_split I i x\n\nlemma sum_split_boxes {M : Type*} [add_comm_monoid M] (I : box \u03b9) (i : \u03b9) (x : \u211d) (f : box \u03b9 \u2192 M) :\n  \u2211 J in (split I i x).boxes, f J = (I.split_lower i x).elim 0 f + (I.split_upper i x).elim 0 f :=\nby rw [split, sum_of_with_bot, finset.sum_pair (I.split_lower_ne_split_upper i x)]\n\n/-- If `x \u2209 (I.lower i, I.upper i)`, then the hyperplane `{y | y i = x}` does not split `I`. -/\nlemma split_of_not_mem_Ioo (h : x \u2209 Ioo (I.lower i) (I.upper i)) : split I i x = \u22a4 :=\nbegin\n  refine ((is_partition_top I).eq_of_boxes_subset (\u03bb J hJ, _)).symm,\n  rcases mem_top.1 hJ with rfl, clear hJ,\n  rw [mem_boxes, mem_split_iff],\n  rw [mem_Ioo, not_and_distrib, not_lt, not_lt] at h,\n  cases h; [right, left],\n  { rwa [eq_comm, box.split_upper_eq_self] },\n  { rwa [eq_comm, box.split_lower_eq_self] }\nend\n\nlemma coe_eq_of_mem_split_of_mem_le {y : \u03b9 \u2192 \u211d} (h\u2081 : J \u2208 split I i x) (h\u2082 : y \u2208 J) (h\u2083 : y i \u2264 x) :\n  (J : set (\u03b9 \u2192 \u211d)) = I \u2229 {y | y i \u2264 x} :=\n(mem_split_iff'.1 h\u2081).resolve_right $ \u03bb H,\n  by { rw [\u2190 box.mem_coe, H] at h\u2082, exact h\u2083.not_lt h\u2082.2 }\n\nlemma coe_eq_of_mem_split_of_lt_mem {y : \u03b9 \u2192 \u211d} (h\u2081 : J \u2208 split I i x) (h\u2082 : y \u2208 J) (h\u2083 : x < y i) :\n  (J : set (\u03b9 \u2192 \u211d)) = I \u2229 {y | x < y i} :=\n(mem_split_iff'.1 h\u2081).resolve_left $ \u03bb H,\n  by { rw [\u2190 box.mem_coe, H] at h\u2082, exact h\u2083.not_le h\u2082.2 }\n\n@[simp] lemma restrict_split (h : I \u2264 J) (i : \u03b9) (x : \u211d) : (split J i x).restrict I = split I i x :=\nbegin\n  refine ((is_partition_split J i x).restrict h).eq_of_boxes_subset _,\n  simp only [finset.subset_iff, mem_boxes, mem_restrict', exists_prop, mem_split_iff'],\n  have : \u2200 s, (I \u2229 s : set (\u03b9 \u2192 \u211d)) \u2286 J, from \u03bb s, (inter_subset_left _ _).trans h,\n  rintro J\u2081 \u27e8J\u2082, (H\u2082|H\u2082), H\u2081\u27e9; [left, right]; simp [H\u2081, H\u2082, inter_left_comm \u2191I, this],\nend\n\nlemma inf_split (\u03c0 : prepartition I) (i : \u03b9) (x : \u211d) :\n  \u03c0 \u2293 split I i x = \u03c0.bUnion (\u03bb J, split J i x) :=\nbUnion_congr_of_le rfl $ \u03bb J hJ, restrict_split hJ i x\n\n/-- Split a box along many hyperplanes `{y | y i = x}`; each hyperplane is given by the pair\n`(i x)`. -/\ndef split_many (I : box \u03b9) (s : finset (\u03b9 \u00d7 \u211d)) : prepartition I :=\ns.inf (\u03bb p, split I p.1 p.2)\n\n@[simp] \n\n@[simp] lemma split_many_insert (I : box \u03b9) (s : finset (\u03b9 \u00d7 \u211d)) (p : \u03b9 \u00d7 \u211d) :\n  split_many I (insert p s) = split_many I s \u2293 split I p.1 p.2 :=\nby rw [split_many, finset.inf_insert, inf_comm, split_many]\n\nlemma split_many_le_split (I : box \u03b9) {s : finset (\u03b9 \u00d7 \u211d)} {p : \u03b9 \u00d7 \u211d} (hp : p \u2208 s) :\n  split_many I s \u2264 split I p.1 p.2 :=\nfinset.inf_le hp\n\nlemma is_partition_split_many (I : box \u03b9) (s : finset (\u03b9 \u00d7 \u211d)) :\n  is_partition (split_many I s) :=\nfinset.induction_on s (by simp only [split_many_empty, is_partition_top]) $\n  \u03bb a s ha hs, by simpa only [split_many_insert, inf_split]\n    using hs.bUnion (\u03bb J hJ, is_partition_split _ _ _)\n\n@[simp] lemma Union_split_many (I : box \u03b9) (s : finset (\u03b9 \u00d7 \u211d)) : (split_many I s).Union = I :=\n(is_partition_split_many I s).Union_eq\n\nlemma inf_split_many {I : box \u03b9} (\u03c0 : prepartition I) (s : finset (\u03b9 \u00d7 \u211d)) :\n  \u03c0 \u2293 split_many I s = \u03c0.bUnion (\u03bb J, split_many J s) :=\nbegin\n  induction s using finset.induction_on with p s hp ihp,\n  { simp },\n  { simp_rw [split_many_insert, \u2190 inf_assoc, ihp, inf_split, bUnion_assoc] }\nend\n\n/-- Let `s : finset (\u03b9 \u00d7 \u211d)` be a set of hyperplanes `{x : \u03b9 \u2192 \u211d | x i = r}` in `\u03b9 \u2192 \u211d` encoded as\npairs `(i, r)`. Suppose that this set contains all faces of a box `J`. The hyperplanes of `s` split\na box `I` into subboxes. Let `Js` be one of them. If `J` and `Js` have nonempty intersection, then\n`Js` is a subbox of `J`.  -/\nlemma not_disjoint_imp_le_of_subset_of_mem_split_many {I J Js : box \u03b9} {s : finset (\u03b9 \u00d7 \u211d)}\n  (H : \u2200 i, {(i, J.lower i), (i, J.upper i)} \u2286 s) (HJs : Js \u2208 split_many I s)\n  (Hn : \u00acdisjoint (J : with_bot (box \u03b9)) Js) : Js \u2264 J :=\nbegin\n  simp only [finset.insert_subset, finset.singleton_subset_iff] at H,\n  rcases box.not_disjoint_coe_iff_nonempty_inter.mp Hn with \u27e8x, hx, hxs\u27e9,\n  refine \u03bb y hy i, \u27e8_, _\u27e9,\n  { rcases split_many_le_split I (H i).1 HJs with \u27e8Jl, Hmem : Jl \u2208 split I i (J.lower i), Hle\u27e9,\n    have := Hle hxs,\n    rw [\u2190 box.coe_subset_coe, coe_eq_of_mem_split_of_lt_mem Hmem this (hx i).1] at Hle,\n    exact (Hle hy).2 },\n  { rcases split_many_le_split I (H i).2 HJs with \u27e8Jl, Hmem : Jl \u2208 split I i (J.upper i), Hle\u27e9,\n    have := Hle hxs,\n    rw [\u2190 box.coe_subset_coe, coe_eq_of_mem_split_of_mem_le Hmem this (hx i).2] at Hle,\n    exact (Hle hy).2 }\nend\n\nsection fintype\n\nvariable [finite \u03b9]\n\n/-- Let `s` be a finite set of boxes in `\u211d\u207f = \u03b9 \u2192 \u211d`. Then there exists a finite set `t\u2080` of\nhyperplanes (namely, the set of all hyperfaces of boxes in `s`) such that for any `t \u2287 t\u2080`\nand any box `I` in `\u211d\u207f` the following holds. The hyperplanes from `t` split `I` into subboxes.\nLet `J'` be one of them, and let `J` be one of the boxes in `s`. If these boxes have a nonempty\nintersection, then `J' \u2264 J`. -/\nlemma eventually_not_disjoint_imp_le_of_mem_split_many (s : finset (box \u03b9)) :\n  \u2200\u1da0 t : finset (\u03b9 \u00d7 \u211d) in at_top, \u2200 (I : box \u03b9) (J \u2208 s) (J' \u2208 split_many I t),\n    \u00acdisjoint (J : with_bot (box \u03b9)) J' \u2192 J' \u2264 J :=\nbegin\n  casesI nonempty_fintype \u03b9,\n  refine eventually_at_top.2\n    \u27e8s.bUnion (\u03bb J, finset.univ.bUnion (\u03bb i, {(i, J.lower i), (i, J.upper i)})),\n      \u03bb t ht I J hJ J' hJ', not_disjoint_imp_le_of_subset_of_mem_split_many (\u03bb i, _) hJ'\u27e9,\n  exact \u03bb p hp, ht (finset.mem_bUnion.2 \u27e8J, hJ, finset.mem_bUnion.2 \u27e8i, finset.mem_univ _, hp\u27e9\u27e9)\nend\n\nlemma eventually_split_many_inf_eq_filter (\u03c0 : prepartition I) :\n  \u2200\u1da0 t : finset (\u03b9 \u00d7 \u211d) in at_top,\n    \u03c0 \u2293 (split_many I t) = (split_many I t).filter (\u03bb J, \u2191J \u2286 \u03c0.Union) :=\nbegin\n  refine (eventually_not_disjoint_imp_le_of_mem_split_many \u03c0.boxes).mono (\u03bb t ht, _),\n  refine le_antisymm ((bUnion_le_iff _).2 $ \u03bb J hJ, _) (le_inf (\u03bb J hJ, _) (filter_le _ _)),\n  { refine of_with_bot_mono _,\n    simp only [finset.mem_image, exists_prop, mem_boxes, mem_filter],\n    rintro _ \u27e8J\u2081, h\u2081, rfl\u27e9 hne,\n    refine \u27e8_, \u27e8J\u2081, \u27e8h\u2081, subset.trans _ (\u03c0.subset_Union hJ)\u27e9, rfl\u27e9, le_rfl\u27e9,\n    exact ht I J hJ J\u2081 h\u2081 (mt disjoint_iff.1 hne) },\n  { rw mem_filter at hJ,\n    rcases set.mem_Union\u2082.1 (hJ.2 J.upper_mem) with \u27e8J', hJ', hmem\u27e9,\n    refine \u27e8J', hJ', ht I _ hJ' _ hJ.1 $ box.not_disjoint_coe_iff_nonempty_inter.2 _\u27e9,\n    exact \u27e8J.upper, hmem, J.upper_mem\u27e9  }\nend\n\nlemma exists_split_many_inf_eq_filter_of_finite (s : set (prepartition I)) (hs : s.finite) :\n  \u2203 t : finset (\u03b9 \u00d7 \u211d), \u2200 \u03c0 \u2208 s,\n    \u03c0 \u2293 (split_many I t) = (split_many I t).filter (\u03bb J, \u2191J \u2286 \u03c0.Union) :=\nbegin\n  have := \u03bb \u03c0 (h\u03c0 : \u03c0 \u2208 s), eventually_split_many_inf_eq_filter \u03c0,\n  exact (hs.eventually_all.2 this).exists\nend\n\n/-- If `\u03c0` is a partition of `I`, then there exists a finite set `s` of hyperplanes such that\n`split_many I s \u2264 \u03c0`. -/\nlemma is_partition.exists_split_many_le {I : box \u03b9} {\u03c0 : prepartition I}\n  (h : is_partition \u03c0) : \u2203 s, split_many I s \u2264 \u03c0 :=\n(eventually_split_many_inf_eq_filter \u03c0).exists.imp $ \u03bb s hs,\n  by { rwa [h.Union_eq, filter_of_true, inf_eq_right] at hs, exact \u03bb J hJ, le_of_mem _ hJ }\n\n/-- For every prepartition `\u03c0` of `I` there exists a prepartition that covers exactly\n`I \\ \u03c0.Union`. -/\nlemma exists_Union_eq_diff (\u03c0 : prepartition I) :\n  \u2203 \u03c0' : prepartition I, \u03c0'.Union = I \\ \u03c0.Union :=\nbegin\n  rcases \u03c0.eventually_split_many_inf_eq_filter.exists with \u27e8s, hs\u27e9,\n  use (split_many I s).filter (\u03bb J, \u00ac(J : set (\u03b9 \u2192 \u211d)) \u2286 \u03c0.Union),\n  simp [\u2190 hs]\nend\n\n/-- If `\u03c0` is a prepartition of `I`, then `\u03c0.compl` is a prepartition of `I`\nsuch that `\u03c0.compl.Union = I \\ \u03c0.Union`. -/\ndef compl (\u03c0 : prepartition I) : prepartition I := \u03c0.exists_Union_eq_diff.some\n\n@[simp] lemma Union_compl (\u03c0 : prepartition I) : \u03c0.compl.Union = I \\ \u03c0.Union :=\n\u03c0.exists_Union_eq_diff.some_spec\n\n/-- Since the definition of `box_integral.prepartition.compl` uses `Exists.some`,\nthe result depends only on `\u03c0.Union`. -/\nlemma compl_congr {\u03c0\u2081 \u03c0\u2082 : prepartition I} (h : \u03c0\u2081.Union = \u03c0\u2082.Union) :\n  \u03c0\u2081.compl = \u03c0\u2082.compl :=\nby { dunfold compl, congr' 1, rw h }\n\nlemma is_partition.compl_eq_bot {\u03c0 : prepartition I} (h : is_partition \u03c0) : \u03c0.compl = \u22a5 :=\nby rw [\u2190 Union_eq_empty, Union_compl, h.Union_eq, diff_self]\n\n@[simp] lemma compl_top : (\u22a4 : prepartition I).compl = \u22a5 := (is_partition_top I).compl_eq_bot\n\nend fintype\n\nend prepartition\n\nend box_integral\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/box_integral/partition/split.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7386327834547962}}
{"text": "import separation_world.level3 -- hide\n\n/-\n# Level 4: Characterisation of Frechet spaces\n-/\n\nvariables {X : Type} -- hide\nvariables [topological_space X] -- hide\n\nnamespace topological_space -- hide\nopen set -- hide\n\n/- Lemma\nLet \u03c4 be a topological space. \u03c4 is a frechet space if only if for all the points in the topology, their singletons are closed sets.\n-/\nlemma T1_characterisation : T1_space X \u2194 (\u2200 (x : X), is_closed ({x} : set X)) :=\nbegin\n  split,\n  { introsI t1 x,\n    rw [is_closed, \u2190 union_disjont_open_sets],\n    exact topological_space.union {U : set X | (x \u2209 U) \u2227 (is_open U)} (\u03bb B hB, hB.2)},\n  { intro h, \n    exact \u27e8\u03bb x y hxy, \u27e8{y}\u1d9c,h y, mem_compl_singleton_iff.mpr (ne.symm hxy), not_not.mpr rfl\u27e9\u27e9}\nend\n\nend topological_space -- hide\n", "meta": {"author": "joan-ferrer", "repo": "topologygameprova", "sha": "b0c0a320d52b77abeed145052bac15fa710b94be", "save_path": "github-repos/lean/joan-ferrer-topologygameprova", "path": "github-repos/lean/joan-ferrer-topologygameprova/topologygameprova-b0c0a320d52b77abeed145052bac15fa710b94be/src/separation_world/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7386327830573381}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.finset.sort\nimport data.fintype.basic\n\n/-!\n# Sorting a finite type\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides two equivalences for linearly ordered fintypes:\n* `mono_equiv_of_fin`: Order isomorphism between `\u03b1` and `fin (card \u03b1)`.\n* `fin_sum_equiv_of_finset`: Equivalence between `\u03b1` and `fin m \u2295 fin n` where `m` and `n` are\n  respectively the cardinalities of some `finset \u03b1` and its complement.\n-/\n\nopen finset\n\n/-- Given a linearly ordered fintype `\u03b1` of cardinal `k`, the order isomorphism\n`mono_equiv_of_fin \u03b1 h` is the increasing bijection between `fin k` and `\u03b1`. Here, `h` is a proof\nthat the cardinality of `\u03b1` is `k`. We use this instead of an isomorphism `fin (card \u03b1) \u2243o \u03b1` to\navoid casting issues in further uses of this function. -/\ndef mono_equiv_of_fin (\u03b1 : Type*) [fintype \u03b1] [linear_order \u03b1] {k : \u2115} (h : fintype.card \u03b1 = k) :\n  fin k \u2243o \u03b1 :=\n(univ.order_iso_of_fin h).trans $ (order_iso.set_congr _ _ coe_univ).trans order_iso.set.univ\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] [fintype \u03b1] [linear_order \u03b1] {m n : \u2115} {s : finset \u03b1}\n\n/-- If `\u03b1` is a linearly ordered fintype, `s : finset \u03b1` has cardinality `m` and its complement has\ncardinality `n`, then `fin m \u2295 fin n \u2243 \u03b1`. The equivalence sends elements of `fin m` to\nelements of `s` and elements of `fin n` to elements of `s\u1d9c` while preserving order on each\n\"half\" of `fin m \u2295 fin n` (using `set.order_iso_of_fin`). -/\ndef fin_sum_equiv_of_finset (hm : s.card = m) (hn : s\u1d9c.card = n) : fin m \u2295 fin n \u2243 \u03b1 :=\ncalc fin m \u2295 fin n \u2243 (s : set \u03b1) \u2295 (s\u1d9c : set \u03b1) :\n  equiv.sum_congr (s.order_iso_of_fin hm).to_equiv $\n    (s\u1d9c.order_iso_of_fin hn).to_equiv.trans $ equiv.set.of_eq s.coe_compl\n... \u2243 \u03b1 : equiv.set.sum_compl _\n\n@[simp] lemma fin_sum_equiv_of_finset_inl (hm : s.card = m) (hn : s\u1d9c.card = n) (i : fin m) :\n  fin_sum_equiv_of_finset hm hn (sum.inl i) = s.order_emb_of_fin hm i :=\nrfl\n\n@[simp] lemma fin_sum_equiv_of_finset_inr (hm : s.card = m) (hn : s\u1d9c.card = n) (i : fin n) :\n  fin_sum_equiv_of_finset hm hn (sum.inr i) = s\u1d9c.order_emb_of_fin hn i :=\nrfl\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/fintype/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642526773001, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7386327816858894}}
{"text": "import ..library.src_ordered_field\n\nnamespace mth1001\n\nnamespace myreal\n\nsection ordered\n\nvariables {R : Type} [myordered_field R]\n\nopen_locale classical\n\nopen myordered_field\n\n/-\nThe three basic axiom of an orderd field are:\n\n1. `trichotomy`,\n2. `pos_add_of_pos_of_pos`, and\n3. `pos_mul_of_pos_of_pos`,\n\nas exemplified below\n-/\n\nexample (x : R) : pos x \u2227 \u00acx = 0 \u2227 \u00acpos (-x)\n               \u2228 \u00acpos x \u2227 x = 0  \u2227 \u00acpos (-x)\n               \u2228 \u00acpos x \u2227 x \u2260 0 \u2227 pos (-x) := trichotomy x\n\nexample (x y : R) : pos x \u2192 pos y \u2192 pos (x + y) := pos_add_of_pos_of_pos x y\n\nexample (x y : R) : pos x \u2192 pos y \u2192 pos (x * y) := pos_mul_of_pos_of_pos x y\n\n-- In the example below, we see that the square of non-zero positive number is positive.\nexample (x : R) (h : x \u2260 (0 : R)) : pos (x ^ 2) :=\nbegin\n  rw pow_two,\n  rcases trichotomy x with \u27e8hpx, _, _\u27e9 | \u27e8_, rfl, _\u27e9 | \u27e8_, _, hpnx\u27e9,\n  { exact pos_mul_of_pos_of_pos _ _ hpx hpx, },\n  { rw mul_zero, contradiction, },\n  { rw [\u2190neg_mul_neg_self],\n    exact pos_mul_of_pos_of_pos _ _ hpnx hpnx,},\nend\n\n-- Exercise 033:\n-- Use trichotomy on `(1 : R)`, as in the example above.\nlemma pos_one : pos (1 : R) :=\nbegin\n  sorry  \nend\n\n-- Below, we see that every non-zero natural number (seen as a term of type `R`) is positive.\nlemma pos_nat (n : \u2115) : n \u2260 0 \u2192 pos (n : R) :=\nbegin\n  induction n with k hk,\n  { intro _, contradiction, },\n  { intro _,\n    rw coe_nat_succ,\n    by_cases h\u2081 : k = 0,\n    { rw h\u2081,\n      change pos((0 : R) + (1 : R)),\n      rw zero_add,\n      exact pos_one, },\n    { exact pos_add_of_pos_of_pos _ _ (hk h\u2081) pos_one }, },\nend\n\n-- The lemmas below are used to work with the definition of `<`.\n\nlemma lt_iff_pos_sub (x y : R) : x < y \u2194 pos (y -x) := by refl\n\nlemma lt_iff_pos_neg (x y : R) : x < y \u2194 pos (y + -x) := by refl\n\nlemma pos_iff_gt_zero (x : R) : pos x \u2194 0 < x := \nby rw [lt_iff_pos_sub, sub_zero]\n\nlemma gt_zero_of_ne_zero_nat (n : \u2115) (h : n \u2260 0) : (0 : R) < n :=\nbegin\n  rw [\u2190pos_iff_gt_zero],\n  exact pos_nat n h,\nend\n\n-- Exercise 034:\nlemma mul_pos {a b : R} (h\u2081 : 0 < a) (h\u2082 : 0 < b) : 0 < a * b :=\nbegin\n  sorry  \nend\n\n-- Exercise 035:\nlemma neg_pos {x : R} : 0 < -x \u2194 x < 0:=\nbegin\n  repeat {rw lt_iff_pos_neg},\n  sorry  end\n\n-- Exercise 036:\nlemma trichotomy' (x y: R) : x < y \u2227 \u00acx = y \u2227 \u00acy < x \u2228\n                               \u00acx < y \u2227 x = y \u2227 \u00acy < x \u2228\n                               \u00acx < y \u2227 \u00acx = y \u2227 y < x :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  have : x - y = -(y - x),\n  { sorry, }, \n  sorry  \nend\n\n-- Exercise 037:\nlemma lt_trans {x y z : R} : x < y \u2192 y < z \u2192 x < z :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  sorry  \nend\n\n-- Exercise 038:\nlemma add_lt_add_iff_right_mpr {x y : R} (z : R) : x < y \u2192 x + z < y + z :=\nbegin\n  sorry  \nend\n\n-- Exercise 039:\nlemma add_lt_add_iff_right_mp {x y : R} (z : R) : x + z < y + z \u2192 x < y :=\nbegin\n  sorry  \nend\n\n-- Exercise 040:\nlemma add_lt_add_iff_right {x y : R} (z : R) : x + z < y + z \u2194 x < y :=\nbegin\n  sorry  \nend\n\n-- Exercise 041:\ntheorem neg_lt_neg_iff  {a b : R} : -a < -b \u2194 b < a :=\nbegin\n  sorry  \nend\n\n-- Exercise 042:\nlemma mul_lt_mul_left_mpr {x y z : R} : 0 < z \u2192 x < y \u2192 z * x < z * y :=\nbegin\n  sorry  \nend\n\n-- Exercise 043:\ntheorem add_lt_add {a b c d : R} : a < b \u2192 c < d \u2192 a + c < b + d :=\nbegin\n  sorry  \nend\n\n-- Exercise 044:\nlemma lt_irrefl {x : R} : \u00acx < x :=\nbegin\n  sorry  \nend\n\n-- Exercise 045:\nlemma non_zero_of_pos {x : R} (h : 0 < x) : x \u2260 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 046:\n-- Use `lt_irrefl` to prove the following.\ntheorem ne_of_gt {a b : R} (h : a > b) : a \u2260 b :=\nbegin\n  sorry  end\n\n-- The following lemma is used to work with the definition of `\u2264`.\n\nlemma le_iff_lt_or_eq {x y : R} : x \u2264 y \u2194 ((x < y) \u2228 x = y) := by refl\n\n-- Exercise 047:\nlemma le_refl (x : R) : x \u2264 x :=\nsorry \n\n-- Exercise 048:\n-- Though it looks complicated, you can fill in the `sorry` below using only the\n-- `split`, `intro`, and `exact` tactics (with and introduction and hypotheses).\nlemma not_le_iff_lt (x y : R) : \u00ac(x \u2264 y) \u2194 (y < x) :=\nbegin\n  rw le_iff_lt_or_eq,\n  push_neg,\n  rcases trichotomy' x y with \u27e8hxlty, _, _\u27e9 | \u27e8_, hxy, hnyltx \u27e9  | \u27e8hnxlty, hnxy, hxlty \u27e9 ,\n  { split,\n    { rintro \u27e8hnxy, _\u27e9,\n      contradiction, },\n    { intros hyltx, exfalso,\n      exact lt_irrefl (lt_trans hxlty hyltx), }, },\n  { split,\n    { rintro \u27e8_, hnxy\u27e9,\n      contradiction, },\n    { intro hyltx, contradiction, }, },\n  { sorry, }, \nend\n\n-- Exercise 049:\n-- Use `neg_le_iff_lt` to prove the result below.\nlemma not_lt_iff_le (x y : R) : \u00ac(x < y) \u2194 (y \u2264 x) :=\nsorry \n\n-- Exercise 050:\nlemma neg_nonneg {x : R} : 0 \u2264 -x \u2194 x \u2264 0 :=\nbegin\n  repeat {rw le_iff_lt_or_eq},\n  have k : 0 < -x \u2194 x < 0, from neg_pos,\n  sorry  \nend\n\n\n-- Exercise 051:\nlemma le_trans (x y z : R) : x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z :=\nbegin\n  rintro (h\u2081 | rfl) (h\u2082 | rfl),\n  { sorry, }, \n  { sorry, }, \n  { sorry, }, \n  { sorry, }, \nend\n\n-- Exercise 052:\nlemma lt_of_le_of_lt {a b c : R} (h\u2081 : a \u2264 b) (h\u2082 : b < c) : a < c :=\nbegin\n  sorry    \nend\n\n-- Exercise 053:\n-- Use `rcases trichotomy' x y` (see examples above) to prove the following.\nlemma le_total (x y : R) : x \u2264 y \u2228 y \u2264 x :=\nbegin\n  sorry  \nend\n\n\n-- Exercise 054:\nlemma anti_symm {x y : R} : x \u2264 y \u2192 y \u2264 x \u2192 x = y :=\nbegin\n  sorry  \nend\n\n-- Exercise 055:\ntheorem neg_le_neg_iff {a b : R} : -a \u2264 -b \u2194 b \u2264 a :=\nbegin\n  repeat {rw le_iff_lt_or_eq},\n  split,\n  { rintro (hlt | heq),\n    { left, rwa \u2190neg_lt_neg_iff, },\n    { right, rw [\u2190neg_neg a, heq, neg_neg], }, },\n  { sorry, }, \nend\n\n-- Exercise 056:\ntheorem add_le_add {a b c d : R} : a \u2264 b \u2192 c \u2264 d \u2192 a + c \u2264 b + d :=\nbegin\n  sorry  \nend\n\n-- Exercise 057:\ntheorem mul_self_non_neg (a : R) : 0 \u2264 a * a:=\nbegin\n  rcases trichotomy' 0 a with \u27e8posa, _\u27e9 | \u27e8_, eq0, _\u27e9 | \u27e8_, _, nega\u27e9,\n  { sorry, }, \n  { sorry, }, \n  { sorry, }, \nend\n\n-- Exercise 058:\nlemma non_neg_mul_of_non_neg_of_non_neg {a b : R} (h\u2081 : 0 \u2264 a) (h\u2082 : 0 \u2264 b) : 0 \u2264 a * b :=\nbegin\n  cases h\u2081 with apos aeq0,\n  { cases h\u2082 with bpos beq0,\n    { sorry, },  \n    { right, rw [\u2190beq0, mul_zero], }, },\n  { sorry, }, \nend\n\n-- Exercise 059:\nlemma non_neg_of_non_neg_mul_of_pos {x y : R} (h\u2081 : 0 \u2264 x * y) (h\u2082 : 0 < x) : 0 \u2264 y :=\nbegin\n  sorry  \nend\n\nlemma non_neg_mul_iff_non_neg_and_non_neg_or_non_pos_and_non_pos (a b : R)\n  : 0 \u2264 a * b \u2194 (0 \u2264 a \u2227 0 \u2264 b) \u2228 (a \u2264 0 \u2227 b \u2264 0) :=\nbegin\n  split,\n  { intro h\u2081,\n    by_cases h\u2082 : 0 \u2264 a,\n    { by_cases h\u2083 : a = 0,\n      { rw h\u2083,\n        exact or.elim (le_total b 0) (\u03bb h\u2084, or.inr \u27e8le_refl 0, h\u2084\u27e9) (\u03bb h\u2084, or.inl \u27e8le_refl 0, h\u2084\u27e9), },\n      { have h\u2084 : 0 < a, from or.elim h\u2082 id (\u03bb aeq0, absurd aeq0.symm h\u2083), \n        have h\u2085 : 0 \u2264 b, from non_neg_of_non_neg_mul_of_pos h\u2081 h\u2084,\n        exact or.inl \u27e8or.inl h\u2084, h\u2085\u27e9, }, },\n    { rw not_le_iff_lt at h\u2082,\n      right,\n      have k : b \u2264 0,\n      { by_contra h\u2083,\n        rw not_le_iff_lt at h\u2083,\n        rw \u2190neg_pos at h\u2082,\n        have h\u2084 : 0 < b * -a, from mul_pos h\u2083 h\u2082,\n        rw [\u2190neg_mul_eq_mul_neg, mul_comm, neg_pos] at h\u2084,\n        exact lt_irrefl (lt_of_le_of_lt h\u2081 h\u2084), },\n      exact \u27e8or.inl h\u2082, k\u27e9, }, },\n  { rintro (\u27e8h\u2081, h\u2082\u27e9 | \u27e8h\u2081, h\u2082\u27e9),\n    { exact non_neg_mul_of_non_neg_of_non_neg h\u2081 h\u2082, },\n    { rw \u2190neg_mul_neg a b,\n      rw \u2190neg_nonneg at h\u2081 h\u2082,\n      exact non_neg_mul_of_non_neg_of_non_neg h\u2081 h\u2082, }, },\nend\n\n-- Exercise 060:\n-- Modify the proof of the second case to prove the first case.\ntheorem inv_pos {a : R}  (h : a \u2260 0) : 0 < a\u207b\u00b9 \u2194 0 < a :=\nbegin\n  split,\n  { sorry, }, \n  { intro k,\n    have h\u2082 : 0 \u2264 (a\u207b\u00b9 * a\u207b\u00b9), from mul_self_non_neg a\u207b\u00b9,\n    rw le_iff_lt_or_eq at h\u2082,\n    cases h\u2082 with posainvsq eq0,\n    { convert mul_lt_mul_left_mpr k posainvsq,\n      { rw mul_zero, },\n      { rw [\u2190mul_assoc, mul_inv a h, one_mul], }, },\n    { have h\u2083 : a\u207b\u00b9 = 0,\n      { cases eq_zero_or_eq_zero_of_mul_eq_zero _ _ eq0.symm;\n        assumption, },\n      exact absurd h\u2083 (inv_ne_zero h), }, },\nend\n\n-- Exercise 061:\ntheorem inv_lt_inv {a b : R} (h\u2081 : 0  < a) (h\u2082 : 0 < b) : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nbegin\n  split,\n  { sorry, }, \n  { intro h\u2083,\n    have h\u2085 : a \u2260 0, from ne_of_gt h\u2081,\n    have k\u2081 : a\u207b\u00b9 > 0, from (inv_pos h\u2085).mpr h\u2081,\n    have h\u2084 : a\u207b\u00b9 * b < a\u207b\u00b9 * a, from mul_lt_mul_left_mpr k\u2081 h\u2083, \n    rw inv_mul a h\u2085 at h\u2084,\n    have h\u2087 : b \u2260 0, from ne_of_gt h\u2082,\n    have k\u2082 : b\u207b\u00b9 > 0, from (inv_pos h\u2087).mpr h\u2082,\n    have h\u2086 :  b\u207b\u00b9 * (a\u207b\u00b9 * b) < b\u207b\u00b9 * 1, from mul_lt_mul_left_mpr k\u2082 h\u2084,\n    rw [mul_comm, mul_assoc, mul_inv b h\u2087, mul_one, mul_one] at h\u2086,\n    exact h\u2086, },\nend\n\nend ordered\n\nsection max_abs\n\nvariables {R : Type} [myordered_field R]\n\nopen_locale classical\n\nopen myordered_field\n\n/-\nThe absolute value `abs a` of `a : R` is defined to be by maximum of\n`a` and `-a`.\n-/\n\nexample (a : R) : abs a = max a (-a) := rfl\n\n/-\nBy definition, `max a b` is `a` if `b \u2264 a`, otherwise it is `b`.\n\nNote the use of `if_pos` and `if_neg` below to distiguish between the cases where\n`b \u2264 a` and `\u00ac(b \u2264 a)` in the definition of `max`.\n-/\n\nlemma le_max_left (a b : R) : a \u2264 max a b :=\nbegin\n  unfold max,\n  by_cases h : b \u2264 a,\n  { rw (if_pos h),\n    exact le_refl a, },\n  { rw (if_neg h),\n    rw not_le_iff_lt at h,\n    left, exact h, },\nend\n\n-- Exercise 062:\nlemma le_max_right (a b : R) : b \u2264 max a b :=\nbegin\n  unfold max,\n  by_cases h : b \u2264 a,\n  { rw (if_pos h),\n    sorry, }, \n  { rw (if_neg h),\n    sorry, }, \nend\n\n-- Exercise 063:\n-- Prove this using the template of the above two results.\nlemma max_choice (a b : R) : max a b = a \u2228 max a b = b :=\nbegin\n  sorry  \nend\n\nlemma neg_le_abs (a : R) : -a \u2264 abs a :=\nbegin\n  unfold abs max,\n  by_cases h : -a \u2264 a,\n  { rw (if_pos h), exact h, },\n  { rw (if_neg h), exact le_refl (-a), },\nend\n\n-- Exercise 064:\nlemma le_abs_self (a : R) : a \u2264 abs a :=\nbegin\n  sorry  \nend\n\n-- Exercise 065:\ntheorem triangle_inequality (x y : R) : abs (x + y) \u2264 abs x + abs y :=\nbegin\n  by_cases h : -(x+y) \u2264 x+y,\n  { have : abs (x+y) = x + y,\n    { unfold abs max,\n      rw (if_pos h), },\n    rw this,\n    have h\u2081 : x \u2264 abs x, from le_abs_self x,\n    have h\u2082 : y \u2264 abs y, from le_abs_self y,\n    exact add_le_add h\u2081 h\u2082, },\n  { sorry, }, \nend\n\nend max_abs\n\nsection upper_bounds_lower_bounds_sup\n\nopen myordered_field\n\nvariables {R : Type} [myordered_field R]\n\n/-\nHere are archetypal applications of the definitions of `upper_bound`, `lower_bound`,\n`bounded_above`, `bounded_below`, `bounded`, and `is_sup`.\n-/\n\nexample (u : R) (S : set R) (h : \u2200 s \u2208 S, s \u2264 u) : upper_bound u S := h\nexample (v : R) (S : set R) (h : \u2200 s \u2208 S, v \u2264 s) : lower_bound v S := h\nexample (S : set R) (h : \u2203 u : R, upper_bound u S) : bounded_above S := h\nexample (S : set R) (h : \u2203 v : R, lower_bound v S) : bounded_below S := h\nexample (S : set R) (h\u2081 : bounded_above S) (h\u2082 : bounded_below S) : bounded S := and.intro h\u2081 h\u2082\nexample (u : R) (S : set R) (h\u2081 : upper_bound u S) (h\u2082 : \u2200 v : R, upper_bound v S \u2192 u \u2264 v)\n: is_sup u S := and.intro h\u2081 h\u2082\n\n-- Exercise 066:\ntheorem sup_uniqueness (S : set R) (a b : R) (h\u2081 : is_sup a S) (h\u2082 : is_sup b S) : a = b :=\nbegin\n  cases h\u2081 with h\u2083 h\u2084,\n  cases h\u2082 with h\u2085 h\u2086,\n  apply anti_symm,\n  { sorry, }, \n  { sorry, }, \nend\n\n-- Exercise 067:\n-- In this example, we show _every_ real number `u` is an upper bound of the empty set.\ntheorem empty_set_upper_bound (u : R) : upper_bound u \u2205 :=\nbegin\n  sorry    \nend\n\n-- Exercise 068:\ntheorem empty_set_lower_bound (v : R) : lower_bound v \u2205 :=\nbegin\n  sorry  \nend\n\n-- Exercise 069:\n-- Given `S` a set of real numbers, given `s \u2208 S`, given `u` and `v` are upper and lower bounds\n-- of `S`, respectively, then `v \u2264 u`.\nexample (S : set R) (u v : R) (h\u2081 : upper_bound u S) (h\u2082 : lower_bound v S) (s : R) (h\u2083 : s \u2208 S)\n  : v \u2264 u :=\nbegin\n  sorry  \nend\n\n-- Exercise 070:\n-- However, it's *not true* that for every set `S` of real numbers, for all real numbers `u` and `v`,\n-- if `u` and `v` are upper and lower bounds of `S`, respectively, then `v \u2264 u`.\n-- Hint: start with `push_neg` and think of the results above.\nexample : \u00ac(\u2200 (S : set R), \u2200 u v : R, upper_bound u S \u2192 lower_bound v S \u2192 v \u2264 u) :=\nbegin\n  sorry  \nend\n\nend upper_bounds_lower_bounds_sup\n\nsection boo\n\nopen myordered_field\n\nvariables {R : Type} [myordered_field R]\n\nlemma zero_of_non_neg_of_lt_pos (a : R) (h : 0 \u2264 a) (h\u2082 : \u2200 \u03b5 > 0, a < \u03b5) : a = 0 :=\nbegin\n  rw le_iff_lt_or_eq at h,\n  cases h with hpos heq0,\n  { exfalso,\n    specialize h\u2082 (a * (\u21912)\u207b\u00b9),\n    have h\u2083 : (0 : R) < \u21912, from gt_zero_of_ne_zero_nat 2 (by norm_num),\n    have k\u2081 : \u21912 \u2260 (0 : R), from non_zero_of_pos h\u2083,\n    have h\u2084 : (0 : R) < (\u21912)\u207b\u00b9, { rwa inv_pos k\u2081, },\n    have h\u2085 : 0 < a * (\u21912)\u207b\u00b9, from mul_pos hpos h\u2084,\n    have h\u2086 : a < a * (\u21912)\u207b\u00b9, from h\u2082 h\u2085,\n    have h\u2087 : \u21912 * a < a,\n    calc \u21912 * a < \u21912 * (a * (\u21912)\u207b\u00b9) : mul_lt_mul_left_mpr h\u2083 h\u2086\n           ...  = a                 : by {rw [mul_comm, mul_assoc, inv_mul _ k\u2081, mul_one] },\n    have k\u2082 : \u21912 = (1 : R) + (1 : R), \n    { rw [coe_nat_succ, coe_nat_succ, (show \u21910 = (0 : R), by refl), zero_add], },\n    have k\u2083 : a + a < a, { rwa [k\u2082, add_mul, one_mul] at h\u2087, },\n    have k\u2084 : a < (0 : R),\n    { rwa [\u2190add_lt_add_iff_right a, zero_add], },\n    exact lt_irrefl (lt_trans hpos k\u2084), },\n  { exact heq0.symm, }\nend\n\nend boo\n\nend myreal\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "ems_reals", "sha": "9df527742db69d0a389add44b506538fdb4d0800", "save_path": "github-repos/lean/gihanmarasingha-ems_reals", "path": "github-repos/lean/gihanmarasingha-ems_reals/ems_reals-9df527742db69d0a389add44b506538fdb4d0800/src/exercises/src_36_order_axioms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7386327747893365}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.modeq\n! leanprover-community/mathlib commit 2ed7e4aec72395b6a7c3ac4ac7873a7a43ead17c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Int.GCD\nimport Mathlib.Data.Int.Order.Lemmas\n\n/-!\n# Congruences modulo a natural number\n\nThis file defines the equivalence relation `a \u2261 b [MOD n]` on the natural numbers,\nand proves basic properties about it such as the Chinese Remainder Theorem\n`modEq_and_modEq_iff_modEq_mul`.\n\n## Notations\n\n`a \u2261 b [MOD n]` is notation for `nat.ModEq n a b`, which is defined to mean `a % n = b % n`.\n\n## Tags\n\nModEq, congruence, mod, MOD, modulo\n-/\n\n\nnamespace Nat\n\n/-- Modular equality. `n.ModEq a b`, or `a \u2261 b [MOD n]`, means that `a - b` is a multiple of `n`. -/\ndef ModEq (n a b : \u2115) :=\n  a % n = b % n\n#align nat.modeq Nat.ModEq\n\n@[inherit_doc]\nnotation:50 a \" \u2261 \" b \" [MOD \" n \"]\" => ModEq n a b\n\nvariable {m n a b c d : \u2115}\n\n-- Porting note: This instance should be derivable automatically\ninstance : Decidable (ModEq n a b) := decEq (a % n) (b % n)\n\nnamespace ModEq\n\n@[refl]\nprotected theorem refl (a : \u2115) : a \u2261 a [MOD n] := rfl\n#align nat.modeq.refl Nat.ModEq.refl\n\nprotected theorem rfl : a \u2261 a [MOD n] :=\n  ModEq.refl _\n#align nat.modeq.rfl Nat.ModEq.rfl\n\ninstance : IsRefl _ (ModEq n) :=\n  \u27e8ModEq.refl\u27e9\n\n@[symm]\nprotected theorem symm : a \u2261 b [MOD n] \u2192 b \u2261 a [MOD n] :=\n  Eq.symm\n#align nat.modeq.symm Nat.ModEq.symm\n\n@[trans]\nprotected theorem trans : a \u2261 b [MOD n] \u2192 b \u2261 c [MOD n] \u2192 a \u2261 c [MOD n] :=\n  Eq.trans\n#align nat.modeq.trans Nat.ModEq.trans\n\ninstance : Trans (ModEq n) (ModEq n) (ModEq n) where\n  trans := Nat.ModEq.trans\n\nprotected theorem comm : a \u2261 b [MOD n] \u2194 b \u2261 a [MOD n] :=\n  \u27e8ModEq.symm, ModEq.symm\u27e9\n#align nat.modeq.comm Nat.ModEq.comm\n\nend ModEq\n\ntheorem modEq_zero_iff_dvd : a \u2261 0 [MOD n] \u2194 n \u2223 a := by rw [ModEq, zero_mod, dvd_iff_mod_eq_zero]\n#align nat.modeq_zero_iff_dvd Nat.modEq_zero_iff_dvd\n\ntheorem _root_.Dvd.dvd.modEq_zero_nat (h : n \u2223 a) : a \u2261 0 [MOD n] :=\n  modEq_zero_iff_dvd.2 h\n#align has_dvd.dvd.modeq_zero_nat Dvd.dvd.modEq_zero_nat\n\ntheorem _root_.Dvd.dvd.zero_modEq_nat (h : n \u2223 a) : 0 \u2261 a [MOD n] :=\n  h.modEq_zero_nat.symm\n#align has_dvd.dvd.zero_modeq_nat Dvd.dvd.zero_modEq_nat\n\ntheorem modEq_iff_dvd : a \u2261 b [MOD n] \u2194 (n : \u2124) \u2223 b - a := by\n  rw [ModEq, eq_comm, \u2190 Int.coe_nat_inj', Int.coe_nat_mod, Int.coe_nat_mod,\n    Int.emod_eq_emod_iff_emod_sub_eq_zero, Int.dvd_iff_emod_eq_zero]\n#align nat.modeq_iff_dvd Nat.modEq_iff_dvd\n\nalias modEq_iff_dvd \u2194 ModEq.dvd modEq_of_dvd\n#align nat.modeq.dvd Nat.ModEq.dvd\n#align nat.modeq_of_dvd Nat.modEq_of_dvd\n\n/-- A variant of `modEq_iff_dvd` with `nat` divisibility -/\ntheorem modEq_iff_dvd' (h : a \u2264 b) : a \u2261 b [MOD n] \u2194 n \u2223 b - a := by\n  rw [modEq_iff_dvd, \u2190 Int.coe_nat_dvd, Int.ofNat_sub h]\n#align nat.modeq_iff_dvd' Nat.modEq_iff_dvd'\n\ntheorem mod_modEq (a n) : a % n \u2261 a [MOD n] :=\n  mod_mod _ _\n#align nat.mod_modeq Nat.mod_modEq\n\nnamespace ModEq\n\nlemma of_dvd (d : m \u2223 n) (h : a \u2261 b [MOD n]) : a \u2261 b [MOD m] := modEq_of_dvd $ d.natCast.trans h.dvd\n#align nat.modeq.of_dvd Nat.ModEq.of_dvd\n\nprotected theorem mul_left' (c : \u2115) (h : a \u2261 b [MOD n]) : c * a \u2261 c * b [MOD c * n] := by\n  unfold ModEq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h]\n#align nat.modeq.mul_left' Nat.ModEq.mul_left'\n\nprotected theorem mul_left (c : \u2115) (h : a \u2261 b [MOD n]) : c * a \u2261 c * b [MOD n] :=\n  (h.mul_left' _).of_dvd (dvd_mul_left _ _)\n#align nat.modeq.mul_left Nat.ModEq.mul_left\n\nprotected theorem mul_right' (c : \u2115) (h : a \u2261 b [MOD n]) : a * c \u2261 b * c [MOD n * c] := by\n  rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c\n#align nat.modeq.mul_right' Nat.ModEq.mul_right'\n\nprotected theorem mul_right (c : \u2115) (h : a \u2261 b [MOD n]) : a * c \u2261 b * c [MOD n] := by\n  rw [mul_comm a, mul_comm b]; exact h.mul_left c\n#align nat.modeq.mul_right Nat.ModEq.mul_right\n\nprotected theorem mul (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : c \u2261 d [MOD n]) : a * c \u2261 b * d [MOD n] :=\n  (h\u2082.mul_left _).trans (h\u2081.mul_right _)\n#align nat.modeq.mul Nat.ModEq.mul\n\nprotected theorem pow (m : \u2115) (h : a \u2261 b [MOD n]) : a ^ m \u2261 b ^ m [MOD n] := by\n  induction m with\n  | zero => rfl\n  | succ d hd =>\n    rw[pow_succ, pow_succ]\n    exact hd.mul h\n#align nat.modeq.pow Nat.ModEq.pow\n\nprotected \n\nprotected theorem add_left (c : \u2115) (h : a \u2261 b [MOD n]) : c + a \u2261 c + b [MOD n] :=\n  ModEq.rfl.add h\n#align nat.modeq.add_left Nat.ModEq.add_left\n\nprotected theorem add_right (c : \u2115) (h : a \u2261 b [MOD n]) : a + c \u2261 b + c [MOD n] :=\n  h.add ModEq.rfl\n#align nat.modeq.add_right Nat.ModEq.add_right\n\nprotected theorem add_left_cancel (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : a + c \u2261 b + d [MOD n]) :\n    c \u2261 d [MOD n] := by\n  simp only [modEq_iff_dvd, Int.ofNat_add] at *\n  rw [add_sub_add_comm] at h\u2082\n  convert _root_.dvd_sub h\u2082 h\u2081 using 1\n  rw [add_sub_cancel']\n#align nat.modeq.add_left_cancel Nat.ModEq.add_left_cancel\n\nprotected theorem add_left_cancel' (c : \u2115) (h : c + a \u2261 c + b [MOD n]) : a \u2261 b [MOD n] :=\n  ModEq.rfl.add_left_cancel h\n#align nat.modeq.add_left_cancel' Nat.ModEq.add_left_cancel'\n\nprotected theorem add_right_cancel (h\u2081 : c \u2261 d [MOD n]) (h\u2082 : a + c \u2261 b + d [MOD n]) :\n    a \u2261 b [MOD n] := by\n  rw [add_comm a, add_comm b] at h\u2082\n  exact h\u2081.add_left_cancel h\u2082\n#align nat.modeq.add_right_cancel Nat.ModEq.add_right_cancel\n\nprotected theorem add_right_cancel' (c : \u2115) (h : a + c \u2261 b + c [MOD n]) : a \u2261 b [MOD n] :=\n  ModEq.rfl.add_right_cancel h\n#align nat.modeq.add_right_cancel' Nat.ModEq.add_right_cancel'\n\n/-- Cancel left multiplication on both sides of the `\u2261` and in the modulus.\n\nFor cancelling left multiplication in the modulus, see `Nat.ModEq.of_mul_left`. -/\nprotected theorem mul_left_cancel' {a b c m : \u2115} (hc : c \u2260 0) :\n    c * a \u2261 c * b [MOD c * m] \u2192 a \u2261 b [MOD m] := by\n  simp [modEq_iff_dvd, \u2190 mul_sub, mul_dvd_mul_iff_left (by simp [hc] : (c : \u2124) \u2260 0)]\n#align nat.modeq.mul_left_cancel' Nat.ModEq.mul_left_cancel'\n\nprotected theorem mul_left_cancel_iff' {a b c m : \u2115} (hc : c \u2260 0) :\n    c * a \u2261 c * b [MOD c * m] \u2194 a \u2261 b [MOD m] :=\n  \u27e8ModEq.mul_left_cancel' hc, ModEq.mul_left' _\u27e9\n#align nat.modeq.mul_left_cancel_iff' Nat.ModEq.mul_left_cancel_iff'\n\n/-- Cancel right multiplication on both sides of the `\u2261` and in the modulus.\n\nFor cancelling right multiplication in the modulus, see `Nat.ModEq.of_mul_right`. -/\nprotected theorem mul_right_cancel' {a b c m : \u2115} (hc : c \u2260 0) :\n    a * c \u2261 b * c [MOD m * c] \u2192 a \u2261 b [MOD m] := by\n  simp [modEq_iff_dvd, \u2190 sub_mul, mul_dvd_mul_iff_right (by simp [hc] : (c : \u2124) \u2260 0)]\n#align nat.modeq.mul_right_cancel' Nat.ModEq.mul_right_cancel'\n\nprotected theorem mul_right_cancel_iff' {a b c m : \u2115} (hc : c \u2260 0) :\n    a * c \u2261 b * c [MOD m * c] \u2194 a \u2261 b [MOD m] :=\n  \u27e8ModEq.mul_right_cancel' hc, ModEq.mul_right' _\u27e9\n#align nat.modeq.mul_right_cancel_iff' Nat.ModEq.mul_right_cancel_iff'\n\n/-- Cancel left multiplication in the modulus.\n\nFor cancelling left multiplication on both sides of the `\u2261`, see `nat.modeq.mul_left_cancel'`. -/\nlemma of_mul_left (m : \u2115) (h : a \u2261 b [MOD m * n]) : a \u2261 b [MOD n] := by\n  rw [modEq_iff_dvd] at *\n  exact (dvd_mul_left (n : \u2124) (m : \u2124)).trans h\n#align nat.modeq.of_mul_left Nat.ModEq.of_mul_left\n\n/-- Cancel right multiplication in the modulus.\n\nFor cancelling right multiplication on both sides of the `\u2261`, see `nat.modeq.mul_right_cancel'`. -/\nlemma of_mul_right (m : \u2115) : a \u2261 b [MOD n * m] \u2192 a \u2261 b [MOD n] := mul_comm m n \u25b8 of_mul_left _\n#align nat.modeq.of_mul_right Nat.ModEq.of_mul_right\n\nend ModEq\n\nlemma modEq_sub (h : b \u2264 a) : a \u2261 b [MOD a - b] := (modEq_of_dvd $ by rw [Int.ofNat_sub h]).symm\n#align nat.modeq_sub Nat.modEq_sub\n\nlemma modEq_one : a \u2261 b [MOD 1] := modEq_of_dvd $ one_dvd _\n#align nat.modeq_one Nat.modEq_one\n\n@[simp] lemma modEq_zero_iff : a \u2261 b [MOD 0] \u2194 a = b := by rw [ModEq, mod_zero, mod_zero]\n#align nat.modeq_zero_iff Nat.modEq_zero_iff\n\n@[simp] lemma add_modEq_left : n + a \u2261 a [MOD n] := by rw [ModEq, add_mod_left]\n#align nat.add_modeq_left Nat.add_modEq_left\n\n@[simp] lemma add_modEq_right : a + n \u2261 a [MOD n] := by rw [ModEq, add_mod_right]\n#align nat.add_modeq_right Nat.add_modEq_right\n\nnamespace ModEq\n\ntheorem le_of_lt_add (h1 : a \u2261 b [MOD m]) (h2 : a < b + m) : a \u2264 b :=\n  (le_total a b).elim id fun h3 =>\n    Nat.le_of_sub_eq_zero\n      (eq_zero_of_dvd_of_lt ((modEq_iff_dvd' h3).mp h1.symm) ((tsub_lt_iff_left h3).mpr h2))\n#align nat.modeq.le_of_lt_add Nat.ModEq.le_of_lt_add\n\ntheorem add_le_of_lt (h1 : a \u2261 b [MOD m]) (h2 : a < b) : a + m \u2264 b :=\n  le_of_lt_add (add_modEq_right.trans h1) (add_lt_add_right h2 m)\n#align nat.modeq.add_le_of_lt Nat.ModEq.add_le_of_lt\n\ntheorem dvd_iff (h : a \u2261 b [MOD m]) (hdm : d \u2223 m) : d \u2223 a \u2194 d \u2223 b := by\n  simp only [\u2190 modEq_zero_iff_dvd]\n  replace h := h.of_dvd hdm\n  exact \u27e8h.symm.trans, h.trans\u27e9\n#align nat.modeq.dvd_iff Nat.ModEq.dvd_iff\n\ntheorem gcd_eq (h : a \u2261 b [MOD m]) : gcd a m = gcd b m := by\n  have h1 := gcd_dvd_right a m\n  have h2 := gcd_dvd_right b m\n  exact\n    dvd_antisymm (dvd_gcd ((h.dvd_iff h1).mp (gcd_dvd_left a m)) h1)\n      (dvd_gcd ((h.dvd_iff h2).mpr (gcd_dvd_left b m)) h2)\n#align nat.modeq.gcd_eq Nat.ModEq.gcd_eq\n\nlemma eq_of_abs_lt (h : a \u2261 b [MOD m]) (h2 : |(b : \u2124) - a| < m) : a = b := by\n  apply Int.ofNat.inj\n  rw [eq_comm, \u2190 sub_eq_zero]\n  exact Int.eq_zero_of_abs_lt_dvd h.dvd h2\n#align nat.modeq.eq_of_abs_lt Nat.ModEq.eq_of_abs_lt\n\nlemma eq_of_lt_of_lt (h : a \u2261 b [MOD m]) (ha : a < m) (hb : b < m) : a = b :=\nh.eq_of_abs_lt $ abs_sub_lt_iff.2\n  \u27e8(sub_le_self _ $ Int.coe_nat_nonneg _).trans_lt $ Int.ofNat_lt.2 hb,\n   (sub_le_self _ $ Int.coe_nat_nonneg _).trans_lt $ Int.ofNat_lt.2 ha\u27e9\n#align nat.modeq.eq_of_lt_of_lt Nat.ModEq.eq_of_lt_of_lt\n\n/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/\nlemma cancel_left_div_gcd (hm : 0 < m) (h : c * a \u2261 c * b [MOD m]) :  a \u2261 b [MOD m / gcd m c] := by\n  let d := gcd m c\n  have hmd := gcd_dvd_left m c\n  have hcd := gcd_dvd_right m c\n  rw [modEq_iff_dvd]\n  refine' @Int.dvd_of_dvd_mul_right_of_gcd_one (m / d) (c / d) (b - a) _ _\n  show (m / d : \u2124) \u2223 c / d * (b - a)\n  \u00b7 rw [mul_comm, \u2190 Int.mul_ediv_assoc (b - a) (Int.coe_nat_dvd.mpr hcd), mul_comm]\n    apply Int.ediv_dvd_ediv (Int.coe_nat_dvd.mpr hmd)\n    rw [mul_sub]\n    exact modEq_iff_dvd.mp h\n  show Int.gcd (m / d) (c / d) = 1\n  \u00b7\n    simp only [\u2190 Int.coe_nat_div, Int.coe_nat_gcd (m / d) (c / d), gcd_div hmd hcd,\n      Nat.div_self (gcd_pos_of_pos_left c hm)]\n#align nat.modeq.cancel_left_div_gcd Nat.ModEq.cancel_left_div_gcd\n\n/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/\nlemma cancel_right_div_gcd (hm : 0 < m) (h : a * c \u2261 b * c [MOD m]) : a \u2261 b [MOD m / gcd m c] := by\n  apply cancel_left_div_gcd hm\n  simpa [mul_comm] using h\n#align nat.modeq.cancel_right_div_gcd Nat.ModEq.cancel_right_div_gcd\n\nlemma cancel_left_div_gcd' (hm : 0 < m) (hcd : c \u2261 d [MOD m]) (h : c * a \u2261 d * b [MOD m]) :\n  a \u2261 b [MOD m / gcd m c] :=\n(h.trans $ hcd.symm.mul_right b).cancel_left_div_gcd hm\n#align nat.modeq.cancel_left_div_gcd' Nat.ModEq.cancel_left_div_gcd'\n\nlemma cancel_right_div_gcd' (hm : 0 < m) (hcd : c \u2261 d [MOD m]) (h : a * c \u2261 b * d [MOD m]) :\n  a \u2261 b [MOD m / gcd m c] :=\n(h.trans $ hcd.symm.mul_left b).cancel_right_div_gcd hm\n#align nat.modeq.cancel_right_div_gcd' Nat.ModEq.cancel_right_div_gcd'\n\n/-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/\nlemma cancel_left_of_coprime (hmc : gcd m c = 1) (h : c * a \u2261 c * b [MOD m]) : a \u2261 b [MOD m] := by\n  rcases m.eq_zero_or_pos with (rfl | hm)\n  \u00b7 simp only [gcd_zero_left] at hmc\n    simp only [gcd_zero_left, hmc, one_mul, modEq_zero_iff] at h\n    subst h\n    rfl\n  simpa [hmc] using h.cancel_left_div_gcd hm\n#align nat.modeq.cancel_left_of_coprime Nat.ModEq.cancel_left_of_coprime\n\n/-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/\nlemma cancel_right_of_coprime (hmc : gcd m c = 1) (h : a * c \u2261 b * c [MOD m]) : a \u2261 b [MOD m] :=\ncancel_left_of_coprime hmc $ by simpa [mul_comm] using h\n#align nat.modeq.cancel_right_of_coprime Nat.ModEq.cancel_right_of_coprime\n\nend ModEq\n\n/-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/\ndef chineseRemainder' (h : a \u2261 b [MOD gcd n m]) : { k // k \u2261 a [MOD n] \u2227 k \u2261 b [MOD m] } :=\n  if hn : n = 0 then \u27e8a, by rw [hn, gcd_zero_left] at h; constructor; rfl; exact h\u27e9\n  else\n    if hm : m = 0 then \u27e8b, by rw [hm, gcd_zero_right] at h; constructor; exact h.symm; rfl\u27e9\n    else\n      \u27e8let (c, d) := xgcd n m\n       Int.toNat ((n * c * b + m * d * a) / gcd n m % lcm n m),\n       by\n        rw [xgcd_val]\n        dsimp\n        rw [modEq_iff_dvd, modEq_iff_dvd,\n          Int.toNat_of_nonneg (Int.emod_nonneg _ (Int.coe_nat_ne_zero.2 (lcm_ne_zero hn hm)))]\n        have hnonzero : (gcd n m : \u2124) \u2260 0 := by\n          norm_cast\n          rw [Nat.gcd_eq_zero_iff, not_and]\n          exact fun _ => hm\n        have hcoedvd : \u2200 t, (gcd n m : \u2124) \u2223 t * (b - a) := fun t => h.dvd.mul_left _\n        have := gcd_eq_gcd_ab n m\n\n        constructor <;> rw [Int.emod_def, \u2190 sub_add] <;>\n            refine' dvd_add _ (dvd_mul_of_dvd_left _ _) <;>\n          try norm_cast\n        \u00b7 rw [\u2190 sub_eq_iff_eq_add'] at this\n          rw [\u2190 this, sub_mul, \u2190 add_sub_assoc, add_comm, add_sub_assoc, \u2190 mul_sub,\n            Int.add_ediv_of_dvd_left, Int.mul_ediv_cancel_left _ hnonzero,\n            Int.mul_ediv_assoc _ h.dvd, \u2190 sub_sub, sub_self, zero_sub, dvd_neg, mul_assoc]\n          exact dvd_mul_right _ _\n          norm_cast\n          exact dvd_mul_right _ _\n        \u00b7 exact dvd_lcm_left n m\n        \u00b7 rw [\u2190 sub_eq_iff_eq_add] at this\n          rw [\u2190 this, sub_mul, sub_add, \u2190 mul_sub, Int.sub_ediv_of_dvd,\n            Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, \u2190 sub_add, sub_self,\n            zero_add, mul_assoc]\n          exact dvd_mul_right _ _\n          exact hcoedvd _\n        \u00b7 exact dvd_lcm_right n m\u27e9\n#align nat.chinese_remainder' Nat.chineseRemainder'\n\n/-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/\ndef chineseRemainder (co : n.coprime m) (a b : \u2115) : { k // k \u2261 a [MOD n] \u2227 k \u2261 b [MOD m] } :=\n  chineseRemainder' (by convert @modEq_one a b)\n#align nat.chinese_remainder Nat.chineseRemainder\n\ntheorem chineseRemainder'_lt_lcm (h : a \u2261 b [MOD gcd n m]) (hn : n \u2260 0) (hm : m \u2260 0) :\n    \u2191(chineseRemainder' h) < lcm n m := by\n  dsimp only [chineseRemainder']\n  rw [dif_neg hn, dif_neg hm, Subtype.coe_mk, xgcd_val, \u2190 Int.toNat_coe_nat (lcm n m)]\n  have lcm_pos := Int.coe_nat_pos.mpr (Nat.pos_of_ne_zero (lcm_ne_zero hn hm))\n  exact (Int.toNat_lt_toNat lcm_pos).mpr (Int.emod_lt_of_pos _ lcm_pos)\n#align nat.chinese_remainder'_lt_lcm Nat.chineseRemainder'_lt_lcm\n\ntheorem chineseRemainder_lt_mul (co : n.coprime m) (a b : \u2115) (hn : n \u2260 0) (hm : m \u2260 0) :\n    \u2191(chineseRemainder co a b) < n * m :=\n  lt_of_lt_of_le (chineseRemainder'_lt_lcm _ hn hm) (le_of_eq co.lcm_eq_mul)\n#align nat.chinese_remainder_lt_mul Nat.chineseRemainder_lt_mul\n\ntheorem modEq_and_modEq_iff_modEq_mul {a b m n : \u2115} (hmn : m.coprime n) :\n    a \u2261 b [MOD m] \u2227 a \u2261 b [MOD n] \u2194 a \u2261 b [MOD m * n] :=\n  \u27e8fun h => by\n    rw [Nat.modEq_iff_dvd, Nat.modEq_iff_dvd, \u2190 Int.dvd_natAbs, Int.coe_nat_dvd, \u2190 Int.dvd_natAbs,\n      Int.coe_nat_dvd] at h\n    rw [Nat.modEq_iff_dvd, \u2190 Int.dvd_natAbs, Int.coe_nat_dvd]\n    exact hmn.mul_dvd_of_dvd_of_dvd h.1 h.2, fun h =>\n    \u27e8h.of_mul_right _, h.of_mul_left _\u27e9\u27e9\n#align nat.modeq_and_modeq_iff_modeq_mul Nat.modEq_and_modEq_iff_modEq_mul\n\ntheorem coprime_of_mul_modEq_one (b : \u2115) {a n : \u2115} (h : a * b \u2261 1 [MOD n]) : a.coprime n := by\n  obtain \u27e8g, hh\u27e9 := Nat.gcd_dvd_right a n\n  rw [Nat.coprime_iff_gcd_eq_one, \u2190 Nat.dvd_one, \u2190 Nat.modEq_zero_iff_dvd]\n  calc\n    1 \u2261 a * b [MOD a.gcd n] := (hh \u25b8 h).symm.of_mul_right g\n    _ \u2261 0 * b [MOD a.gcd n] := (Nat.modEq_zero_iff_dvd.mpr (Nat.gcd_dvd_left _ _)).mul_right b\n    _ = 0 := by rw [zero_mul]\n\n#align nat.coprime_of_mul_modeq_one Nat.coprime_of_mul_modEq_one\n\n@[simp 1100]\ntheorem mod_mul_right_mod (a b c : \u2115) : a % (b * c) % b = a % b :=\n  (mod_modEq _ _).of_mul_right _\n#align nat.mod_mul_right_mod Nat.mod_mul_right_mod\n\n@[simp 1100]\ntheorem mod_mul_left_mod (a b c : \u2115) : a % (b * c) % c = a % c :=\n  (mod_modEq _ _).of_mul_left _\n#align nat.mod_mul_left_mod Nat.mod_mul_left_mod\n\ntheorem div_mod_eq_mod_mul_div (a b c : \u2115) : a / b % c = a % (b * c) / b :=\n  if hb0 : b = 0 then by simp [hb0]\n  else by\n    rw [\u2190 @add_right_cancel_iff _ _ _ (c * (a / b / c)), mod_add_div, Nat.div_div_eq_div_mul, \u2190\n      mul_right_inj' hb0, \u2190 @add_left_cancel_iff _ _ _ (a % b), mod_add_div, mul_add, \u2190\n      @add_left_cancel_iff _ _ _ (a % (b * c) % b), add_left_comm, \u2190 add_assoc (a % (b * c) % b),\n      mod_add_div, \u2190 mul_assoc, mod_add_div, mod_mul_right_mod]\n#align nat.div_mod_eq_mod_mul_div Nat.div_mod_eq_mod_mul_div\n\ntheorem add_mod_add_ite (a b c : \u2115) :\n    ((a + b) % c + if c \u2264 a % c + b % c then c else 0) = a % c + b % c :=\n  have : (a + b) % c = (a % c + b % c) % c := ((mod_modEq _ _).add <| mod_modEq _ _).symm\n  if hc0 : c = 0 then by simp [hc0, Nat.mod_zero]\n  else by\n    rw [this]\n    split_ifs with h\n    \u00b7 have h2 : (a % c + b % c) / c < 2 :=\n        Nat.div_lt_of_lt_mul\n          (by\n            rw [mul_two]\n            exact\n              add_lt_add (Nat.mod_lt _ (Nat.pos_of_ne_zero hc0))\n                (Nat.mod_lt _ (Nat.pos_of_ne_zero hc0)))\n      have h0 : 0 < (a % c + b % c) / c := Nat.div_pos h (Nat.pos_of_ne_zero hc0)\n      rw [\u2190 @add_right_cancel_iff _ _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc,\n        mod_add_div, le_antisymm (le_of_lt_succ h2) h0, mul_one, add_comm]\n    \u00b7 rw [Nat.mod_eq_of_lt (lt_of_not_ge h), add_zero]\n#align nat.add_mod_add_ite Nat.add_mod_add_ite\n\ntheorem add_mod_of_add_mod_lt {a b c : \u2115} (hc : a % c + b % c < c) : (a + b) % c = a % c + b % c :=\n  by rw [\u2190 add_mod_add_ite, if_neg (not_le_of_lt hc), add_zero]\n#align nat.add_mod_of_add_mod_lt Nat.add_mod_of_add_mod_lt\n\ntheorem add_mod_add_of_le_add_mod {a b c : \u2115} (hc : c \u2264 a % c + b % c) :\n    (a + b) % c + c = a % c + b % c := by rw [\u2190 add_mod_add_ite, if_pos hc]\n#align nat.add_mod_add_of_le_add_mod Nat.add_mod_add_of_le_add_mod\n\ntheorem add_div {a b c : \u2115} (hc0 : 0 < c) :\n    (a + b) / c = a / c + b / c + if c \u2264 a % c + b % c then 1 else 0 := by\n  rw [\u2190 mul_right_inj' hc0.ne', \u2190 @add_left_cancel_iff _ _ _ ((a + b) % c + a % c + b % c)]\n  suffices\n    (a + b) % c + c * ((a + b) / c) + a % c + b % c =\n      (a % c + c * (a / c) + (b % c + c * (b / c)) + c * if c \u2264 a % c + b % c then 1 else 0) +\n        (a + b) % c\n    by simpa only [mul_add, add_comm, add_left_comm, add_assoc]\n  rw [mod_add_div, mod_add_div, mod_add_div, mul_ite, add_assoc, add_assoc]\n  conv_lhs => rw [\u2190 add_mod_add_ite]\n  simp\n  ac_rfl\n#align nat.add_div Nat.add_div\n\ntheorem add_div_eq_of_add_mod_lt {a b c : \u2115} (hc : a % c + b % c < c) :\n    (a + b) / c = a / c + b / c :=\n  if hc0 : c = 0 then by simp [hc0]\n  else by rw [add_div (Nat.pos_of_ne_zero hc0), if_neg (not_le_of_lt hc), add_zero]\n#align nat.add_div_eq_of_add_mod_lt Nat.add_div_eq_of_add_mod_lt\n\nprotected theorem add_div_of_dvd_right {a b c : \u2115} (hca : c \u2223 a) : (a + b) / c = a / c + b / c :=\n  if h : c = 0 then by simp [h]\n  else\n    add_div_eq_of_add_mod_lt\n      (by\n        rw [Nat.mod_eq_zero_of_dvd hca, zero_add]\n        exact Nat.mod_lt _ (pos_iff_ne_zero.mpr h))\n#align nat.add_div_of_dvd_right Nat.add_div_of_dvd_right\n\nprotected theorem add_div_of_dvd_left {a b c : \u2115} (hca : c \u2223 b) : (a + b) / c = a / c + b / c := by\n  rwa [add_comm, Nat.add_div_of_dvd_right, add_comm]\n#align nat.add_div_of_dvd_left Nat.add_div_of_dvd_left\n\ntheorem add_div_eq_of_le_mod_add_mod {a b c : \u2115} (hc : c \u2264 a % c + b % c) (hc0 : 0 < c) :\n    (a + b) / c = a / c + b / c + 1 := by rw [add_div hc0, if_pos hc]\n#align nat.add_div_eq_of_le_mod_add_mod Nat.add_div_eq_of_le_mod_add_mod\n\ntheorem add_div_le_add_div (a b c : \u2115) : a / c + b / c \u2264 (a + b) / c :=\n  if hc0 : c = 0 then by simp [hc0]\n  else by rw [Nat.add_div (Nat.pos_of_ne_zero hc0)]; exact Nat.le_add_right _ _\n#align nat.add_div_le_add_div Nat.add_div_le_add_div\n\ntheorem le_mod_add_mod_of_dvd_add_of_not_dvd {a b c : \u2115} (h : c \u2223 a + b) (ha : \u00acc \u2223 a) :\n    c \u2264 a % c + b % c :=\n  by_contradiction fun hc => by\n    have : (a + b) % c = a % c + b % c := add_mod_of_add_mod_lt (lt_of_not_ge hc)\n    simp_all [dvd_iff_mod_eq_zero]\n#align nat.le_mod_add_mod_of_dvd_add_of_not_dvd Nat.le_mod_add_mod_of_dvd_add_of_not_dvd\n\ntheorem odd_mul_odd {n m : \u2115} : n % 2 = 1 \u2192 m % 2 = 1 \u2192 n * m % 2 = 1 := by\n  simpa [Nat.ModEq] using @ModEq.mul 2 n 1 m 1\n#align nat.odd_mul_odd Nat.odd_mul_odd\n\ntheorem odd_mul_odd_div_two {m n : \u2115} (hm1 : m % 2 = 1) (hn1 : n % 2 = 1) :\n    m * n / 2 = m * (n / 2) + m / 2 :=\n  have hm0 : 0 < m := Nat.pos_of_ne_zero fun h => by simp_all\n  have hn0 : 0 < n := Nat.pos_of_ne_zero fun h => by simp_all\n  mul_right_injective\u2080 two_ne_zero <| by\n    dsimp\n    rw [mul_add, two_mul_odd_div_two hm1, mul_left_comm, two_mul_odd_div_two hn1,\n      two_mul_odd_div_two (Nat.odd_mul_odd hm1 hn1), mul_tsub, mul_one, \u2190\n      add_tsub_assoc_of_le (succ_le_of_lt hm0),\n      tsub_add_cancel_of_le (le_mul_of_one_le_right (Nat.zero_le _) hn0)]\n#align nat.odd_mul_odd_div_two Nat.odd_mul_odd_div_two\n\ntheorem odd_of_mod_four_eq_one {n : \u2115} : n % 4 = 1 \u2192 n % 2 = 1 := by\n  simpa [ModEq, show 2 * 2 = 4 by norm_num] using @ModEq.of_mul_left 2 n 1 2\n#align nat.odd_of_mod_four_eq_one Nat.odd_of_mod_four_eq_one\n\ntheorem odd_of_mod_four_eq_three {n : \u2115} : n % 4 = 3 \u2192 n % 2 = 1 := by\n  simpa [ModEq, show 2 * 2 = 4 by norm_num, show 3 % 4 = 3 by norm_num] using\n    @ModEq.of_mul_left 2 n 3 2\n#align nat.odd_of_mod_four_eq_three Nat.odd_of_mod_four_eq_three\n\n/-- A natural number is odd iff it has residue `1` or `3` mod `4`-/\ntheorem odd_mod_four_iff {n : \u2115} : n % 2 = 1 \u2194 n % 4 = 1 \u2228 n % 4 = 3 :=\n  have help : \u2200 m : \u2115, m < 4 \u2192 m % 2 = 1 \u2192 m = 1 \u2228 m = 3 := by decide\n  \u27e8fun hn =>\n    help (n % 4) (mod_lt n (by norm_num)) <| (mod_mod_of_dvd n (by norm_num : 2 \u2223 4)).trans hn,\n    fun h => Or.elim h odd_of_mod_four_eq_one odd_of_mod_four_eq_three\u27e9\n#align nat.odd_mod_four_iff Nat.odd_mod_four_iff\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/ModEq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.7386327734178878}}
{"text": "/-\n5. Use the Pigeonhole Principle to prove the following statements involv-\ning a positive integer n:\n(a) In any set of 6 integers, there must be two whose difference is divisible by 5.\n(b) In any set of n + 1 integers, there must be two whose difference is\ndivisible by n.\n(c) Given any n integers a\u2081, a\u2082,..., a\u2099, there is a non-empty subset of\nthese whose sum is divisible by n. (Hint: Consider the integers 0,a\u2081 ,\na\u2081 + a\u2082 ,..., a\u2081 +...+a\u2099 and use (b).)\n(d) Given any set S consisting of ten distinct integers between 1 and 50,\nthere are two different 5-element subsets of S with the same sum.\n(e) Given any set T consisting of nine distinct integers between 1 and\n50, there are two disjoint subsets of T with the same sum.\n(f) In any set of 101 integers chosen from the set {1, 2, . . . , 200}, there\nmust be two integers such that one divides the other.\n-/\nimport tactic\nimport combinatorics.pigeonhole\nimport algebra.big_operators.fin\nimport data.int.succ_pred\nimport data.int.parity\nimport data.nat.factorization.basic\n\nopen function \n\nlemma parta (S : finset \u2124) (hS : S.card = 6) : \u2203 a b \u2208 S, a \u2260 b \u2227 (5 : \u2124) \u2223 a - b :=\nbegin\n  let f : \u2124 \u2192 \u2124 := \u03bb z, z % 5, \n  let T : finset \u2124 := finset.Ico 0 5,\n  have hfT : \u2200 z : \u2124, z \u2208 S \u2192 (f z) \u2208 T,\n  { intros z hz,\n    simp only [f, finset.mem_Ico],\n    split,\n    apply int.mod_nonneg,\n    norm_num,\n    apply int.mod_lt,\n    norm_num, },\n  have hST : T.card * 1 < S.card,\n  { simp only [hS, int.card_Ico, tsub_zero, mul_one],\n    norm_num, },\n  have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hfT hST,\n  dsimp at this,\n  rcases this with \u27e8y, Hy, H\u27e9,\n  rw finset.one_lt_card at H,\n  rcases H with \u27e8a, ha, b, hb, H\u27e9,\n  simp only [finset.mem_filter] at ha hb,\n  use [a, ha.1, b, hb.1, H],\n  apply int.modeq.dvd,\n  change f b = f a,\n  rw [hb.2, ha.2],\nend\n\nlemma partb (n : \u2115) (hn : 0 < n) (S : finset \u2124) (hS : S.card = n + 1) : \u2203 a b \u2208 S, a \u2260 b \u2227 (n : \u2124) \u2223 a - b :=\nbegin\n  let f : \u2124 \u2192 \u2124 := \u03bb z, z % n, \n  let T : finset \u2124 := finset.Ico 0 n,\n  have hfT : \u2200 z : \u2124, z \u2208 S \u2192 (f z) \u2208 T,\n  { intros z hz,\n    simp only [f, finset.mem_Ico],\n    split,\n    apply int.mod_nonneg,\n    linarith,\n    convert int.mod_lt _ _,\n    simp only [nat.abs_cast],\n    linarith, },\n  have hST : T.card * 1 < S.card,\n  { simp only [hS, int.card_Ico, tsub_zero, int.to_nat_coe_nat, mul_one, lt_add_iff_pos_right, nat.lt_one_iff], },\n  have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hfT hST,\n  dsimp at this,\n  rcases this with \u27e8y, Hy, H\u27e9,\n  rw finset.one_lt_card at H,\n  rcases H with \u27e8a, ha, b, hb, H\u27e9,\n  simp at ha hb,\n  use [a, ha.1, b, hb.1, H],\n  apply int.modeq.dvd,\n  change f b = f a,\n  rw [hb.2, ha.2],\nend\n\n-- A stronger of part b which should be easier to use\n-- (the point is that f might not be injective on s)\nlemma partb' {\u03b9 : Type*} {s : finset \u03b9} (f : \u03b9 \u2192 \u2124) (hs : s.nonempty) {n : \u2115} (hn : 0 < n)\n  (hs' : n < s.card): \u2203 a b \u2208 s, a \u2260 b \u2227 (n : \u2124) \u2223 f a - f b :=\nbegin\n  let f' : \u03b9 \u2192 \u2124 := \u03bb z, (f z) % n, \n  let T : finset \u2124 := finset.Ico 0 n,\n  have hfT : \u2200 z : \u03b9, z \u2208 s \u2192 (f' z) \u2208 T,\n  { intros z hz,\n    simp only [f', finset.mem_Ico],\n    have hn' : (n : \u2124) \u2260 0, \n    { norm_cast, exact hn.ne', },\n    split,\n    { exact int.mod_nonneg _ hn', },\n    { convert int.mod_lt _ hn',\n      simp only [nat.abs_cast], }, },\n  have hST : T.card * 1 < s.card,\n  { simp [hs'], },\n  obtain \u27e8y, hyT, hcard\u27e9 := \n    finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hfT hST,\n  rw finset.one_lt_card_iff at hcard,\n  rcases hcard with \u27e8a, b, ha, hb, hab\u27e9,\n  rw finset.mem_filter at ha hb,\n  refine \u27e8a, ha.1, b, hb.1, hab, _\u27e9,\n  dsimp at ha hb,\n  apply int.modeq.dvd,\n  change f' b = f' a,\n  rw [hb.2, ha.2],\nend\n\nopen_locale big_operators\n\nlemma finset.sum_Ico {M : Type*} [add_comm_group M]\n  {a b : \u2115} (h : a \u2264 b) (f : \u2115 \u2192 M) : \n  \u2211 i in finset.Ico a b, f i = \u2211 j in finset.range b, f j - \u2211 j in finset.range a, f j :=\nbegin\n  rw eq_sub_iff_add_eq,\n  rw \u2190 finset.sum_union,\n  { apply finset.sum_congr _ (\u03bb x _, rfl),\n    rw [finset.range_eq_Ico, finset.union_comm, finset.Ico_union_Ico_eq_Ico (nat.zero_le a) h], },\n  { rintros x (hx : x \u2208 _ \u2229 _),\n    rw [finset.mem_inter, finset.mem_Ico, finset.mem_range] at hx,\n    rcases hx with \u27e8\u27e8h1, _\u27e9, h2\u27e9,\n    exact false.elim (h1.not_lt h2), },\nend\n\nlemma partc (n : \u2115) (hn : 0 < n) (f : \u2115 \u2192 \u2124) : \u2203 S : finset \u2115, \n  S \u2286 finset.range n \u2227 S.nonempty \u2227 (n : \u2124) \u2223 \u2211 i in S, f i :=\nbegin\n  --  {\u03b9 : Type*} {s : finset \u03b9} (f : \u03b9 \u2192 \u2124) (hs : s.nonempty) {n : \u2115} (hn : 0 < n)\n  -- (hs' : n < s.card): \u2203 a b \u2208 s, a \u2260 b \u2227 (n : \u2124) \u2223 f a - f b := sorry\n  rcases partb' (\u03bb t, \u2211 i in finset.range t, f i) \n    (@finset.nonempty_range_succ n) hn (by simp) with \u27e8a, ha, b, hb, hab, hn\u27e9,\n  rw finset.mem_range_succ_iff at ha hb,\n  rw ne_iff_lt_or_gt at hab,\n  rcases hab with hab | (hab : b < a),\n  { use finset.Ico a b,\n    refine \u27e8_, _, _\u27e9,\n    { rw [finset.range_eq_Ico, finset.Ico_subset_Ico_iff hab],\n      exact \u27e8zero_le a, hb\u27e9, },\n    { rwa finset.nonempty_Ico, },\n    { rwa [finset.sum_Ico hab.le, \u2190 dvd_neg, neg_sub], }, },\n  { -- b < a case\n    use finset.Ico b a,\n    refine \u27e8_, _, _\u27e9,\n    { rw [finset.range_eq_Ico, finset.Ico_subset_Ico_iff hab],\n      exact \u27e8zero_le b, ha\u27e9, },\n    { rwa finset.nonempty_Ico, },\n    { rwa finset.sum_Ico hab.le, }, },\nend\n\n-- should be in mathlib maybe? (thanks Eric Rodriguez)\ndef sum_le_max (S : finset \u2124) (x : \u2124) (hS' : \u2200 s \u2208 S, s \u2264 x) :\n  \u2211 i in S, i \u2264 \u2211 i in finset.Ioc (x - finset.card S) x, i :=\nbegin\n  induction h : finset.card S with k ih generalizing S x,\n  { obtain rfl := finset.card_eq_zero.mp h, simp},\n  have hSn : 0 < S.card := h.symm \u25b8 k.succ_pos,\n  replace hSn : S.nonempty := finset.card_pos.mp hSn,\n  specialize ih (S.erase (S.max' hSn)) (x - 1) (\u03bb s hs, _) _,\n  { rw [\u2190int.pred, \u2190int.pred_eq_pred, order.le_pred_iff],\n    obtain \u27e8hs\u2081, hs\u2082\u27e9 := finset.mem_erase.1 hs,\n    exact (S.lt_max'_of_mem_erase_max' hSn hs).trans_le (hS' _ $ S.max'_mem hSn) },\n  { simpa [h] using finset.card_erase_of_mem (S.max'_mem hSn) },\n  have : x - 1 - k = x - k.succ,\n  { rw [sub_sub, sub_right_inj],\n    simp only [add_comm, nat.cast_succ]},\n  rw this at ih,\n  have hSm : S.max' hSn \u2264 x := hS' _ (S.max'_mem hSn),\n  replace ih := add_le_add ih hSm,\n  suffices : finset.Ioc (x - k.succ) (x - 1) = (finset.Ioc (x - k.succ) x).erase x,\n  { rwa [finset.sum_erase_add _ _ $ S.max'_mem hSn, this, finset.sum_erase_add] at ih,\n    simp only [finset.right_mem_Ioc, sub_lt_self_iff],\n    exact nat.cast_pos.mpr (k.succ_pos) },\n  ext,\n  simp only [nat.cast_succ, finset.mem_Ioc, finset.Ioc_erase_right, finset.mem_Ioo,\n             and.congr_right_iff],\n  rintro -,\n  rw [\u2190int.pred, \u2190int.pred_eq_pred, order.le_pred_iff]\nend\n\n-- should also be in mathlib maybe?\ndef min_le_sum (S : finset \u2124) (x : \u2124) (hS' : \u2200 s \u2208 S, x \u2264 s) :\n \u2211 i in finset.Ico x (x + finset.card S), i \u2264 \u2211 i in S, i :=\nbegin\n  have := sum_le_max (finset.image (\u03bb i, -i) S) (-x) _, swap,\n  { intros s hs,\n    rw finset.mem_image at hs,\n    rcases hs with \u27e8t, ht, rfl\u27e9,\n    exact neg_le_neg (hS' t ht), },\n  rw \u2190 neg_le_neg_iff,\n  have Scard : (finset.image has_neg.neg S).card = S.card,\n  { rw finset.card_image_iff,\n    intros x hx y hy,\n    exact neg_inj.1, },\n  convert this,\n  { rw finset.sum_image,\n    symmetry,\n    apply finset.sum_neg_distrib,\n    intros x hx y hy h,\n    rwa neg_inj at h, },\n  { rw \u2190 finset.sum_neg_distrib,\n    apply finset.sum_bij (\u03bb (a : \u2124) ha, -a),\n    { intros a ha,\n      simp only [finset.mem_Ioc, neg_le_neg_iff],\n      rw finset.mem_Ico at ha,\n      rw Scard,\n      cases ha,\n      split; linarith, },\n    { simp only [eq_self_iff_true, implies_true_iff], },\n    { simp only [neg_inj, imp_self, implies_true_iff, forall_const], },\n    { rw Scard,\n      intros b hb,\n      refine \u27e8-b, _, _\u27e9,\n      { simp only [finset.mem_Ico, finset.mem_Ioc] at hb \u22a2, \n        cases hb, split; linarith, },\n      { simp only [neg_neg], }, }, },\nend\n\nlemma partd (S : finset \u2124) (hS : \u2200 s \u2208 S, (1 : \u2124) \u2264 s \u2227 s \u2264 50) (hScard : S.card = 10) : \u2203 A B : finset \u2124,\n  A.card = 5 \u2227 B.card = 5 \u2227 A \u2260 B \u2227 A \u2264 S \u2227 B \u2264 S \u2227 \u2211 i in A, i = \u2211 j in B, j :=\nbegin\n  -- consider possibilities for subset of S with card 5\n  let P := finset.powerset_len 5 S,\n  -- consider possibilities for sum\n  let F := finset.Icc (15 : \u2124) 240,\n  have hFP : F.card * 1 < P.card,\n  { simp only [finset.card_powerset_len 5 S, hScard, int.card_Icc, mul_one],\n    have h : (10 : \u2115).choose 5 = 252,\n    {refl},\n    simp only [h],\n    norm_num, },\n  let g : finset \u2124 \u2192 \u2124 := \u03bb x, \u2211 i in x, i,\n  have hg : \u2200 p : finset \u2124, p \u2208 P \u2192 (g p) \u2208 F,\n  { intros p hp,\n    simp only [g, finset.mem_Icc],\n    rw finset.mem_powerset_len at hp,\n    split,\n    { convert min_le_sum p 1 (\u03bb s hs, (hS s (hp.1 hs)).1),\n      rw hp.2,\n      refl, },\n    { convert sum_le_max p 50 (\u03bb s hs, (hS s (hp.1 hs)).2),\n      rw hp.2,\n      refl, }, },\n  have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hg hFP,\n  dsimp at this,\n  rcases this with \u27e8y, hy1, hy2\u27e9,\n  rw finset.one_lt_card at hy2,\n  rcases hy2 with \u27e8A, hA, B, hB, hAB\u27e9,\n  rw finset.mem_filter at hA hB,\n  refine \u27e8A, B, _\u27e9,\n  rw [finset.mem_powerset_len] at hA hB,\n  simp [hAB, hA.1, hB.1],\n  change g A = g B,\n  rw [hA.2, hB.2],\nend\n\nlemma parte (T : finset \u2124) (hT : \u2200 t \u2208 T, (1 : \u2124) \u2264 t \u2227 t \u2264 50) (hTcard : T.card = 9) : \u2203 A B : finset \u2124,\n  A \u2264 T \u2227 B \u2264 T \u2227 disjoint A B \u2227 \u2211 i in A, i = \u2211 j in B, j :=\nbegin\n  -- as long as we can find two non-empty sets A, B of the same sum, we can find two disjoint set by A\\B and B\\A\n  suffices h : \u2203 C D : finset \u2124, C \u2264 T \u2227 D \u2264 T \u2227 C \u2260 D \u2227 \u2211 i in C, i = \u2211 j in D, j,\n  { -- let A = C - (C \u2229 D), B = D - (C \u2229 D),\n    rcases h with \u27e8C, D, hC, hD, hCD, h\u27e9,\n    let A : finset \u2124 := C \\ D,\n    let B : finset \u2124 := D \\ C,\n    refine \u27e8A, B, _\u27e9,\n    have hAC : A \u2264 C, apply finset.sdiff_subset,\n    have hBD : B \u2264 D, apply finset.sdiff_subset,\n    have hA : A \u2264 T := le_trans hAC hC,\n    have hB : B \u2264 T := le_trans hBD hD,\n    refine \u27e8hA, hB, disjoint_sdiff_sdiff, _\u27e9, \n    let X := C \u2229 D,\n    suffices : \u2211 (i : \u2124) in A, i + \u2211 (x : \u2124) in X, x = \u2211 (j : \u2124) in B, j + \u2211 (x : \u2124) in X, x,\n    exact (add_left_inj (\u2211 (x : \u2124) in X, x)).mp this,\n    convert h,\n    { suffices : C = A \u222a X, \n      { rw [this, \u2190 finset.sum_union],\n        exact finset.disjoint_sdiff_inter C D, },\n      ext x,\n      simp only [finset.mem_union, finset.mem_sdiff, finset.mem_inter, \u2190 and_or_distrib_left],\n      tauto, },\n    { suffices : D = B \u222a X,\n      { rw [this, \u2190 finset.sum_union],\n        change disjoint B (C \u2229 D),\n        rw finset.inter_comm C D,\n        exact finset.disjoint_sdiff_inter D C, },\n      { ext x,\n        simp only [finset.mem_union, finset.mem_sdiff, finset.mem_inter, \u2190 and_or_distrib_left],\n        tauto, }, }, },\n  { -- consider powerset of T\n    let P := finset.powerset T,\n    let F := finset.Icc (0:\u2124) 414,\n    have hPF : F.card * 1 < P.card,\n    { simp [nat.card_Icc, finset.card_powerset, hTcard],\n      norm_num, },\n    -- find a map from P to F by summing elements in P\n    let g : finset \u2124 \u2192 \u2124 := \u03bb x, \u2211 i in x, i,\n    have hg : \u2200 p : finset \u2124, p \u2208 P \u2192 (g p) \u2208 F,\n    { intros p hp,\n      simp [g],\n      rw finset.mem_powerset at hp,\n      split,\n      { apply finset.sum_nonneg,\n        intros i hi,\n        exact le_trans zero_le_one (hT i (hp hi)).1, },\n      { transitivity (\u2211 i in T, i),\n        { apply finset.sum_le_sum_of_subset_of_nonneg hp,\n          intros i hi _,\n          exact le_trans zero_le_one (hT i hi).1, },\n        { convert sum_le_max T 50 _, \n          { rw hTcard, refl, },\n          { intros i hi, exact (hT i hi).2, }, } }, },\n    have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hg hPF,\n    dsimp at this,\n    rcases this with \u27e8y, hy1, hy2\u27e9,\n    rw finset.one_lt_card at hy2,\n    rcases hy2 with \u27e8C, hC, D, hD, hCD\u27e9,\n    rw [finset.mem_filter, finset.mem_powerset] at hC hD,\n    refine \u27e8C, D, hC.1, hD.1, hCD, _\u27e9,\n    change g C = g D,\n    rw [hC.2, hD.2], },\nend\n\nlemma nat.ord_compl_eq_dvd (a b : \u2115) (h : ord_compl[2] a = ord_compl[2] b) (ha : 0 < a) (hab : a < b) :\n  a \u2223 b :=\nbegin\n  -- if a = 2^k1 * p, b = 2^k2 * p\n  set k1 : \u2115 := a.factorization 2,\n  set k2 : \u2115 := b.factorization 2,\n  rw dvd_iff_exists_eq_mul_left,\n  -- c = 2^ (k2 - k1)\n  use (2 ^ (k2 - k1)),\n  have h02 : 0 < 2 := by norm_num,\n  -- because of natural division is involved, we need divisibility\n  have had := nat.ord_proj_dvd a 2,\n  have hbd := nat.ord_proj_dvd b 2,\n  have haf := pow_pos h02 k1,\n  have hbf := pow_pos h02 k2,\n  have hab : k1 \u2264 k2,\n  { by_contra hc,\n    push_neg at hc,\n    have hc' : 2 ^ k2 < 2 ^ k1,\n    { rw pow_lt_pow_iff,\n      exact hc,\n      norm_num, },\n    have hak : 0 < a / 2 ^ k1,\n    { apply nat.div_pos,\n      apply nat.ord_proj_le,\n      exact ne_of_gt ha,\n      exact haf, },\n    suffices : b < a,\n    { linarith, },\n    { have hc'' :  2 ^ k2 * (b / 2 ^ k2) < 2 ^ k1 * (a / 2 ^ k1),\n      { rw \u2190 h, apply mul_lt_mul_of_pos_right hc' hak, },\n    rw [mul_comm (2 ^ k2) (b / 2 ^ k2), nat.div_mul_cancel] at hc'',\n    swap, exact hbd,\n    rw [mul_comm (2 ^ k1) (a / 2 ^ k1), nat.div_mul_cancel] at hc'',\n    exact hc'',\n    exact had, }, },\n  have := nat.pow_div hab h02,\n  rw \u2190 this,\n  -- again we need divisibility to proceed\n  have hkd := pow_dvd_pow 2 hab,\n  rw [mul_comm, \u2190 nat.mul_div_assoc _ hkd, mul_comm a (2^k2), nat.mul_div_assoc],\n  swap, exact had,\n  rw [h, mul_comm, nat.div_mul_cancel hbd],\nend\n\nlemma partf (T : finset \u2115) (hT : \u2200 t \u2208 T, (1 : \u2124) \u2264 t \u2227 t \u2264 200) (hTcard : T.card = 101) : \u2203 a b : \u2115,\n  a \u2208 T \u2227 b \u2208 T \u2227 a \u2260 b \u2227 a \u2223 b :=\nbegin\n  -- claim : every t can be written as 2^k * q for which q is odd, using ord_compl[2] t\n  let Q : finset \u2115 := (finset.Icc 1 200).filter odd,\n  have hQcard : Q.card = 100,\n  { -- Show that it equals (finset.Iio 100).map \\<\\la n, 2 * n + 1, proof_of_injectivity_here\\> \n    have hQ : Q = (finset.Iio 100).map \u27e8\u03bb n, 2 * n + 1 , \n                                        begin intros a b hab, \n                                        simpa [add_left_inj, mul_eq_mul_left_iff, bit0_eq_zero, nat.one_ne_zero, or_false] using hab, \n                                        end \u27e9,\n    { dsimp [Q],\n      rw le_antisymm_iff,\n      split,\n      { intros x hx,\n        simp only [finset.mem_map, finset.mem_Iio, function.embedding.coe_fn_mk, exists_prop, nat.one_le_cast, finset.mem_filter,\n          finset.mem_Icc, nat.odd_iff_not_even] at hx \u22a2,\n        refine \u27e8((x-1)/2), _, _\u27e9,\n        { rcases hx with \u27e8\u27e8h1, h2\u27e9, h3\u27e9,\n          zify at h2 \u22a2,\n          rw int.div_lt_iff_lt_mul,\n          linarith,\n          norm_num, },\n        { rcases hx with \u27e8\u27e8h1, h2\u27e9, h3\u27e9,\n          rw \u2190 nat.odd_iff_not_even at h3,\n          unfold odd at h3,\n          cases h3 with k h3,\n          rw h3,\n          simp only [nat.add_succ_sub_one, add_zero, nat.mul_div_right, nat.succ_pos'], }, },\n      { intros x hx,\n        simp only [finset.mem_map, finset.mem_Iio, function.embedding.coe_fn_mk, exists_prop, nat.one_le_cast, finset.mem_filter,\n          finset.mem_Icc, nat.odd_iff_not_even] at hx \u22a2,\n        rcases hx with \u27e8a, \u27e8h1, h2\u27e9\u27e9,\n        refine \u27e8\u27e8_, _\u27e9, _\u27e9,\n        { rw \u2190 h2,\n          linarith, },\n        { rw \u2190 h2,\n          linarith, },\n        { intro h,\n          rw [nat.even_iff, \u2190 h2, nat.mul_comm, nat.mul_add_mod a 2 1] at h,\n          simpa [nat.one_mod, nat.one_ne_zero] using h, }, }, },\n    rw hQ,\n    simp only [nat.card_Iio, finset.card_map], },\n  have hTO : Q.card * 1 < T.card,\n  { rw [hQcard, hTcard], norm_num, },\n  -- find a map from T to Q, by considering corresponding 'q'\n  let f : \u2115 \u2192 \u2115 := \u03bb z, ord_compl[2] z,\n  have hf : \u2200 t \u2208 T, (f t) \u2208 Q,\n  { intros t ht,\n    simp only [f, finset.mem_filter, finset.mem_Icc, nat.odd_iff_not_even],\n    have ht0 : t \u2260 0,\n    { specialize hT t ht, \n    cases hT with hT1 hT2, \n    linarith, }, \n    refine \u27e8\u27e8_,_\u27e9,_\u27e9,\n    { rw nat.one_le_div_iff,\n      {apply nat.ord_proj_le 2 ht0, },\n      {exact nat.ord_proj_pos t 2, }, },\n    { apply nat.div_le_of_le_mul,\n      have h1 := nat.ord_proj_pos t 2,\n      rw \u2190 nat.succ_le_iff at h1,\n      exact le_mul_of_one_le_of_le h1 (hT t ht).2, },\n    { simp only [even_iff_two_dvd, nat.not_dvd_ord_compl nat.prime_two ht0, not_false_iff], }, },\n  have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hf hTO,\n  dsimp at this,\n  rcases this with \u27e8y, hy1, hy2\u27e9,\n  rw finset.one_lt_card at hy2,\n  rcases hy2 with \u27e8a, ha, b, hb, hab\u27e9,\n  by_cases a < b,\n  { refine \u27e8a, b, _\u27e9,\n    simp only [hab, ne.def, not_false_iff, true_and],\n    rw finset.mem_filter at ha hb,\n    simp only [ha.1, hb.1, true_and],\n    have ha0 : 0 < a,\n    { specialize hT a ha.1,\n      cases hT with h1 h2,\n      linarith, },\n    suffices : f a = f b,\n    { apply nat.ord_compl_eq_dvd, \n      exact this,\n      exact ha0,\n      exact h, },\n    { rw [ha.2, hb.2], }, },\n  { have h : b < a,\n    { omega, },\n    refine \u27e8b, a, _\u27e9,\n    simp only [ne.symm hab, ne.def, not_false_iff, true_and],\n    rw finset.mem_filter at ha hb,\n    simp only [ha.1, hb.1, true_and],\n    have hb0 : 0 < b,\n    { specialize hT b hb.1,\n      cases hT with h1 h2,\n      linarith, },\n    suffices : f b = f a,\n    { apply nat.ord_compl_eq_dvd, \n      exact this,\n      exact hb0,\n      exact h, },\n    { rw [ha.2, hb.2], }, },\nend\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "m1fexplained_lean3", "sha": "570c9a3ff8cfc3805047f2796864516a49f51510", "save_path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3", "path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3/m1fexplained_lean3-570c9a3ff8cfc3805047f2796864516a49f51510/src/chapter19/exercises/exercise05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.8840392741081574, "lm_q1q2_score": 0.7386002705342484}}
{"text": "import algebra.field data.set\n\nuniverse u\n\nclass is_subring {R : Type u} [ring R] (s : set R) : Prop :=\n(one_mem : (1 : R) \u2208 s) \n(sub_mem : \u2200 {x y : R}, x \u2208 s \u2192 y \u2208 s \u2192 x - y \u2208 s)\n(mul_mem : \u2200 {x y : R}, x \u2208 s \u2192 y \u2208 s \u2192 x * y \u2208 s)\n\nopen is_subring set\n\nnamespace is_subring\n\nlemma zero_mem {R : Type u} [ring R] {s : set R} [is_subring s] :\n(0 : R) \u2208 s := eq.subst (sub_self (1 : R)) (sub_mem (one_mem s) (one_mem s))\n\nlemma neg_mem {R : Type u} [ring R] {s : set R} [is_subring s] {x : R}:\nx \u2208 s \u2192 -x \u2208 s :=\nbegin\nintros hx,\nhave H : 0 - x \u2208 s,\n    exact sub_mem zero_mem hx,\nrw zero_sub at H,\nexact H,\nend\n\nlemma add_mem  {R : Type u} [ring R] {s : set R} [is_subring s] {x y : R} :\nx \u2208 s \u2192 y \u2208 s \u2192 x + y \u2208 s := \u03bb hx hy, eq.subst (sub_neg_eq_add x y) (sub_mem hx (neg_mem hy))\n\ninstance subring_to_ring {R : Type u} [ring R] (s : set R) [is_subring s] : ring s :=\n{\nadd := \u03bb (a b : s), \u27e8a.val + b.val, add_mem a.property b.property\u27e9, \nadd_assoc := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (add_assoc a b c),\nzero := \u27e80, zero_mem\u27e9, \nzero_add := assume \u27e8a, _\u27e9, subtype.eq (zero_add a), \nadd_zero := assume \u27e8a, _\u27e9, subtype.eq (add_zero a),\nneg := \u03bb (a : s), \u27e8 -a.val, neg_mem a.property\u27e9 ,\nadd_left_neg := assume \u27e8a, _\u27e9, subtype.eq (add_left_neg a),\nadd_comm := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9, subtype.eq (add_comm a b),\nmul := \u03bb (a b : s), \u27e8a.val * b.val, mul_mem a.property b.property\u27e9,\nmul_assoc := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (mul_assoc a b c),   \none := \u27e81, one_mem s\u27e9,\none_mul := assume \u27e8a, _\u27e9, subtype.eq (one_mul a), \nmul_one := assume \u27e8a, _\u27e9, subtype.eq (mul_one a),\nleft_distrib := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (left_distrib a b c),\nright_distrib := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (right_distrib a b c),\n} \n\nend is_subring\n\nclass is_subfield {F : Type u} [field F] (s : set F) : Prop :=\n(one_mem : (1 : F) \u2208 s)\n(sub_mem : \u2200 {x y : F}, x \u2208 s \u2192 y \u2208 s \u2192 x - y \u2208 s)\n(mul_mem : \u2200 {x y : F}, x \u2208 s \u2192 y \u2208 s \u2192 x * y \u2208 s)\n(inv_mem : \u2200 {x : F}, x \u2208 s \u2192 x\u207b\u00b9 \u2208 s)\n\nopen is_subfield\n\nnamespace is_subfield\n\nlemma zero_mem {F : Type u} [field F] {s : set F} [is_subfield s] :\n(0 : F) \u2208 s := eq.subst (sub_self (1 : F)) (sub_mem (one_mem s) (one_mem s))\n\nlemma neg_mem {R : Type u} [field R] {s : set R} [is_subfield s] {x : R}:\nx \u2208 s \u2192 -x \u2208 s :=\nbegin\nintros hx,\nhave H : 0 - x \u2208 s,\n    exact sub_mem zero_mem hx,\nrw zero_sub at H,\nexact H,\nend\n\nlemma add_mem {F : Type u} [field F] {s : set F} [is_subfield s] {x y : F} :\nx \u2208 s \u2192 y \u2208 s \u2192 x + y \u2208 s := \u03bb hx hy, eq.subst (sub_neg_eq_add x y) (sub_mem hx (neg_mem hy))\n\ninstance subfield_to_field {F : Type u} [field F] (s : set F) [is_subfield s] : field s :=\n{\nadd := \u03bb (a b : s), \u27e8a.val + b.val, add_mem a.property b.property\u27e9, \nadd_assoc := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (add_assoc a b c),\nzero := \u27e80, zero_mem\u27e9, \nzero_add := assume \u27e8a, _\u27e9, subtype.eq (zero_add a), \nadd_zero := assume \u27e8a, _\u27e9, subtype.eq (add_zero a),\nneg := \u03bb (a : s), \u27e8 -a.val, neg_mem a.property\u27e9 ,\nadd_left_neg := assume \u27e8a, _\u27e9, subtype.eq (add_left_neg a),\nadd_comm := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9, subtype.eq (add_comm a b),\nmul := \u03bb (a b : s), \u27e8a.val * b.val, mul_mem a.property b.property\u27e9,\nmul_assoc := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (mul_assoc a b c),   \none := \u27e81, one_mem s\u27e9,\none_mul := assume \u27e8a, _\u27e9, subtype.eq (one_mul a), \nmul_one := assume \u27e8a, _\u27e9, subtype.eq (mul_one a),\nleft_distrib := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (left_distrib a b c),\nright_distrib := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9 \u27e8c, _\u27e9, subtype.eq (right_distrib a b c),\ninv := \u03bb (a : s), \u27e8a.val\u207b\u00b9, inv_mem a.property\u27e9,   \nzero_ne_one := begin apply (iff_false_left zero_ne_one).mp, simp, exact F, apply_instance, end,\nmul_inv_cancel := assume \u27e8a, _\u27e9, \u03bb h, subtype.eq (mul_inv_cancel ((iff_false_left (not_not_intro h)).mp (begin dunfold ne, rw auto.not_not_eq, apply subtype.ext, end))),\ninv_mul_cancel := assume \u27e8a, _\u27e9, \u03bb h, subtype.eq (inv_mul_cancel ((iff_false_left (not_not_intro h)).mp (begin dunfold ne, rw auto.not_not_eq, apply subtype.ext, end))),\nmul_comm := assume \u27e8a, _\u27e9 \u27e8b, _\u27e9, subtype.eq (mul_comm a b),\n}\n\nend is_subfield\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/inner_product_spaces/subrings_subfields.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7385923407732137}}
{"text": "import tuto_lib\nimport data.int.parity\n/-\nNegations, proof by contradiction and contraposition.\n\nThis file introduces the logical rules and tactics related to negation:\nexfalso, by_contradiction, contrapose, by_cases and push_neg.\n\nThere is a special statement denoted by `false` which, by definition,\nhas no proof.\n\nSo `false` implies everything. Indeed `false \u2192 P` means any proof of \n`false` could be turned into a proof of P.\nThis fact is known by its latin name\n\"ex falso quod libet\" (from false follows whatever you want).\nHence Lean's tactic to invoke this is called `exfalso`.\n-/\n\nexample : false \u2192 0 = 1 :=\nbegin\n  intro h,\n  exfalso,\n  exact h,\nend\n\n/-\nThe preceding example suggests that this definition of `false` isn't very useful.\nBut actually it allows us to define the negation of a statement P as\n\"P implies false\" that we can read as \"if P were true, we would get \na contradiction\". Lean denotes this by `\u00ac P`.\n\nOne can prove that (\u00ac P) \u2194 (P \u2194 false). But in practice we directly\nuse the definition of `\u00ac P`.\n-/\n\nexample {x : \u211d} : \u00ac x < x :=\nby { rw lt_iff_le_and_ne, cc }\n\nexample {x : \u211d} : \u00ac x < x :=\nbegin\n  intro hyp,\n  rw lt_iff_le_and_ne at hyp,\n  cases hyp with hyp_inf hyp_non,\n  clear hyp_inf, -- we won't use that one, so let's discard it\n  change x = x \u2192 false at hyp_non, -- Lean doesn't need this psychological line\n  apply hyp_non,\n  refl,\nend\n\nopen int\n\n-- 0045\nexample (n : \u2124) (h_pair : even n) (h_non_pair : \u00ac even n) : 0 = 1 := by cc\n\n-- 0046\nexample (P Q : Prop) (h\u2081 : P \u2228 Q) (h\u2082 : \u00ac (P \u2227 Q)) : \u00ac P \u2194 Q :=\nbegin\n  split,\n  { intro h\u2083,\n    cases h\u2081 with p q,\n    { exfalso,\n      apply h\u2083,\n      assumption },\n    { assumption } },\n  { intro h\u2083,\n    cases h\u2081 with p q,\n    { exfalso,\n      apply h\u2082,\n      split; assumption },\n    { intro q,\n      apply h\u2082,\n      split; assumption } }\nend\n\n/-\nThe definition of negation easily implies that, for every statement P,\nP \u2192 \u00ac \u00ac P\n\nThe excluded middle axiom, which asserts P \u2228 \u00ac P allows us to\nprove the converse implication.\n\nTogether those two implications form the principle of double negation elimination.\n  not_not {P : Prop} : (\u00ac \u00ac P) \u2194 P\n\nThe implication `\u00ac \u00ac P \u2192 P` is the basis for proofs by contradiction:\nin order to prove P, it suffices to prove \u00ac\u00ac P, ie `\u00ac P \u2192 false`.\n\nOf course there is no need to keep explaining all this. The tactic\n`by_contradiction Hyp` will transform any goal P into `false` and \nadd Hyp : \u00ac P to the local context.\n\nLet's return to a proof from the 5th file: uniqueness of limits for a sequence.\nThis cannot be proved without using some version of the excluded middle\naxiom. We used it secretely in\n\neq_of_abs_sub_le_all (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y\n\n(we'll prove a variation on this lemma below).\n-/\nexample (u : \u2115 \u2192 \u211d) (l l' : \u211d) : seq_limit u l \u2192 seq_limit u l' \u2192 l = l' :=\nbegin\n  intros hl hl',\n  by_contra h,\n  change l \u2260 l' at h,\n  have h\u2081 : |l - l'| > 0,\n  { apply abs_pos_of_ne_zero,\n    apply sub_ne_zero_of_ne,\n    assumption },\n  set \u03b5 := |l - l'| / 4 with h\u03b5,\n  cases hl \u03b5 (by linarith) with N hN,\n  cases hl' \u03b5 (by linarith) with N' hN',\n  let N := max N N',  \n  specialize hN N le_sup_left,\n  specialize hN' N le_sup_right,\n  have h\u2082 : |l - l'| < |l - l'|,\n  calc |l - l'| = |(l - u N) + (u N - l')| : by ring\n  ...           \u2264 |l - u N| + |u N - l'|   : by apply abs_add\n  ...           \u2264 |u N - l| + |u N - l'|   : by rw abs_sub\n  ...           < |l - l'|                 : by linarith,\n  linarith\nend\n\nexample (u : \u2115 \u2192 \u211d) (l l' : \u211d) : seq_limit u l \u2192 seq_limit u l' \u2192 l = l' :=\nbegin\n  intros hl hl',\n  by_contradiction H,\n  change l \u2260 l' at H, -- Lean does not need this line\n  have ineg : |l-l'| > 0,\n    exact abs_pos_of_ne_zero (sub_ne_zero_of_ne H),\n  cases hl ( |l-l'|/4 ) (by linarith) with N hN,\n  cases hl' ( |l-l'|/4 ) (by linarith) with N' hN',\n  let N\u2080 := max N N', -- this is a new tactic, whose effect should be clear\n  specialize hN N\u2080 (le_max_left _ _),\n  specialize hN' N\u2080 (le_max_right _ _),\n  have clef : |l-l'| < |l-l'|,\n    calc\n    |l - l'| = |(l-u N\u2080) + (u N\u2080 -l')|   : by ring\n         ... \u2264 |l - u N\u2080| + |u N\u2080 - l'|  : by apply abs_add\n         ... = |u N\u2080 - l| + |u N\u2080 - l'|  : by rw abs_sub\n         ... < |l-l'|                    : by linarith,\n  linarith, -- linarith can also find simple numerical contradictions\nend\n\n/-\nAnother incarnation of the excluded middle axiom is the principle of\ncontraposition: in order to prove P \u21d2 Q, it suffices to prove\nnon Q \u21d2 non P.\n-/\n\n-- Using a proof by contradiction, let's prove the contraposition principle\n-- 0047\nexample (P Q : Prop) (h : \u00ac Q \u2192 \u00ac P) : P \u2192 Q :=\nbegin\n  intro p,\n  by_contra hq,\n  apply h; assumption\nend\n\n/-\nAgain Lean doesn't need to be explain this principle. We can use the\n`contrapose` tactic.\n-/\n\nexample (P Q : Prop) (h : \u00ac Q \u2192 \u00ac P) : P \u2192 Q :=\nbegin\n  contrapose,\n  exact h,\nend\n\n/-\nIn the next exercise, we'll use\n odd n : \u2203 k, n = 2*k + 1\n not_even_iff_odd : \u00ac even n \u2194 odd n,\n-/\n-- 0048\nexample (n : \u2124) : even (n^2) \u2194 even n :=\nbegin\n  rw pow_two,\n  split,\n  { contrapose,\n    repeat { rw not_even_iff_odd },\n    rintros \u27e8k, rfl\u27e9,\n    set a := 2 * k with ha,\n    use k * (a + 2),\n    rw ha,\n    ring },\n  { rintros \u27e8k, rfl\u27e9,\n    use 2 * k * k,\n    ring }\nend\n/-\nAs a last step on our law of the excluded middle tour, let's notice that, especially\nin pure logic exercises, it can sometimes be useful to use the\nexcluded middle axiom in its original form:\n  classical.em : \u2200 P, P \u2228 \u00ac P\n\nInstead of applying this lemma and then using the `cases` tactic, we\nhave the shortcut\n by_cases h : P,\n\ncombining both steps to create two proof branches: one assuming\nh : P, and the other assuming h : \u00ac P\n\nFor instance, let's prove a reformulation of this implication relation,\nwhich is sometimes used as a definition in other logical foundations,\nespecially those based on truth tables (hence very strongly using\nexcluded middle from the very beginning).\n-/\n\nvariables (P Q : Prop)\n\nexample : (P \u2192 Q) \u2194 (\u00ac P \u2228 Q) :=\nbegin\n  split; intros h,\n  { by_cases hq : Q,\n    { right, assumption },\n    { left, exact \u03bb p, hq (h p) } },\n  { intro p,\n    cases h with hp q,\n    { exfalso, apply hp, assumption },\n    { assumption } }\nend\n\nexample : (P \u2192 Q) \u2194 (\u00ac P \u2228 Q) :=\nbegin\n  split,\n  { intro h,\n    by_cases hP : P,\n    { right,\n      exact h hP },\n    { left,\n      exact hP } },\n  { intros h hP,\n    cases h with hnP hQ,\n    { exfalso,\n      exact hnP hP },\n    { exact hQ } },\nend\n\n-- 0049\nexample : \u00ac (P \u2227 Q) \u2194 \u00ac P \u2228 \u00ac Q :=\nbegin\n  split,\n  { intro h,\n    by_cases hp : P,\n    { right,\n      intro q,\n      apply h,\n      split; assumption },\n    { left; assumption } },\n  { rintros h \u27e8p, q\u27e9,\n    cases h; cc }\nend\n\n/-\nIt is crucial to understand negation of quantifiers. \nLet's do it by hand for a little while.\nIn the first exercise, only the definition of negation is needed.\n-/\n\n-- 0050\nexample (n : \u2124) : \u00ac (\u2203 k, n = 2*k) \u2194 \u2200 k, n \u2260 2*k :=\nbegin\n  split; intro h,\n  { intros k hk,\n    exact h \u27e8k, hk\u27e9 },\n  { rintro \u27e8k, hk\u27e9,\n    exact h k hk }\nend\n\n/-\nContrary to negation of the existential quantifier, negation of the\nuniversal quantifier requires excluded middle for the first implication.\nIn order to prove this, we can use either\n* a double proof by contradiction\n* a contraposition, not_not : (\u00ac \u00ac P) \u2194 P) and a proof by contradiction.\n-/\n\ndef even_fun (f : \u211d \u2192 \u211d) := \u2200 x, f (-x) = f x\n\n-- 0051\nexample (f : \u211d \u2192 \u211d) : \u00ac even_fun f \u2194 \u2203 x, f (-x) \u2260 f x :=\nbegin\n  split,\n  { intro h\u2081,\n    by_contra h\u2082,\n    apply h\u2081,\n    intro x,\n    by_contra h\u2083,\n    apply h\u2082,\n    use x; assumption },\n  { rintros \u27e8x, hx\u27e9 hf,\n    apply hx,\n    apply hf }\nend\n\nexample (f : \u211d \u2192 \u211d) : \u00ac even_fun f \u2194 \u2203 x, f (-x) \u2260 f x :=\nbegin\n  split,\n  { contrapose,\n    intro h,\n    rw not_not,\n    intro x,\n    by_contra,\n    apply h,\n    use x; assumption },\n  { contrapose,\n    rw not_not,\n    intro h,\n    -- It sucks that the anonymous contructor syntax isn't \"builtin enough\" in\n    -- Lean, so I can't write `by_contra \u27e8x, hx\u27e9`.\n    by_contra this,\n    cases this with x hx,\n    apply hx,\n    apply h }\nend\n\n/-\nOf course we can't keep repeating the above proofs, especially the second one.\nSo we use the `push_neg` tactic.\n-/\n\nexample : \u00ac even_fun (\u03bb x, 2*x) :=\nbegin\n  unfold even_fun, -- Here unfolding is important because push_neg won't do it.\n  push_neg,\n  use 42,\n  linarith,\nend\n\n-- 0052\nexample (f : \u211d \u2192 \u211d) : \u00ac even_fun f \u2194 \u2203 x, f (-x) \u2260 f x :=\nbegin\n  unfold even_fun,\n  push_neg\nend\n\ndef bounded_above (f : \u211d \u2192 \u211d) := \u2203 M, \u2200 x, f x \u2264 M\n\nexample : \u00ac bounded_above (\u03bb x, x) :=\nbegin\n  unfold bounded_above,\n  push_neg,\n  intro M,\n  use M + 1,\n  linarith,\nend\n\n-- Let's contrapose\n-- 0053\nexample (x : \u211d) : (\u2200 \u03b5 > 0, x \u2264 \u03b5) \u2192 x \u2264 0 :=\nbegin\n  contrapose,\n  push_neg,\n  intro h,\n  use x/2,\n  split; linarith\nend\n\n/-\nThe \"contrapose, push_neg\" combo is so common that we can abreviate it to\n`contrapose!`\n\nLet's use this trick, together with:\n  eq_or_lt_of_le : a \u2264 b \u2192 a = b \u2228 a < b\n-/\n\n-- 0054\nexample (f : \u211d \u2192 \u211d) : (\u2200 x y, x < y \u2192 f x < f y) \u2194 (\u2200 x y, (x \u2264 y \u2194 f x \u2264 f y)) :=\nbegin\n  split,\n  { intros hf x y,\n    split,\n    { intro h,\n      cases eq_or_lt_of_le h with h h,\n      { rw h },\n      { linarith [hf x y h] } },\n    { contrapose!,\n      apply hf } },\n  { intros hf x y,\n    contrapose!,\n    intro h,\n    rwa hf }\nend\n\n", "meta": {"author": "pedrominicz", "repo": "learn", "sha": "b79b802a9846c86c21d4b6f3e17af36e7382f0ef", "save_path": "github-repos/lean/pedrominicz-learn", "path": "github-repos/lean/pedrominicz-learn/learn-b79b802a9846c86c21d4b6f3e17af36e7382f0ef/src/tutorials/07_first_negations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.738592340701613}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland, Yury Kudryashov\n-/\nimport algebra.group.semiconj\n\n/-!\n# Commuting pairs of elements in monoids\n\nWe define the predicate `commute a b := a * b = b * a` and provide some operations on terms `(h :\ncommute a b)`. E.g., if `a`, `b`, and c are elements of a semiring, and that `hb : commute a b` and\n`hc : commute a c`.  Then `hb.pow_left 5` proves `commute (a ^ 5) b` and `(hb.pow_right 2).add_right\n(hb.mul_right hc)` proves `commute a (b ^ 2 + b * c)`.\n\nLean does not immediately recognise these terms as equations, so for rewriting we need syntax like\n`rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`.\n\nThis file defines only a few operations (`mul_left`, `inv_right`, etc).  Other operations\n(`pow_right`, field inverse etc) are in the files that define corresponding notions.\n\n## Implementation details\n\nMost of the proofs come from the properties of `semiconj_by`.\n-/\n\n/-- Two elements commute if `a * b = b * a`. -/\n@[to_additive add_commute \"Two elements additively commute if `a + b = b + a`\"]\ndef commute {S : Type*} [has_mul S] (a b : S) : Prop := semiconj_by a b b\n\nnamespace commute\n\nsection has_mul\n\nvariables {S : Type*} [has_mul S]\n\n/-- Equality behind `commute a b`; useful for rewriting. -/\n@[to_additive] protected theorem eq {a b : S} (h : commute a b) : a * b = b * a := h\n\n/-- Any element commutes with itself. -/\n@[refl, simp, to_additive] protected theorem refl (a : S) : commute a a := eq.refl (a * a)\n\n/-- If `a` commutes with `b`, then `b` commutes with `a`. -/\n@[symm, to_additive] protected theorem symm {a b : S} (h : commute a b) : commute b a :=\neq.symm h\n\n@[to_additive]\nprotected theorem symm_iff {a b : S} : commute a b \u2194 commute b a :=\n\u27e8commute.symm, commute.symm\u27e9\n\nend has_mul\n\nsection semigroup\n\nvariables {S : Type*} [semigroup S] {a b c : S}\n\n/-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/\n@[simp, to_additive] theorem mul_right (hab : commute a b) (hac : commute a c) :\n  commute a (b * c) :=\nhab.mul_right hac\n\n/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/\n@[simp, to_additive] theorem mul_left (hac : commute a c) (hbc : commute b c) :\n  commute (a * b) c :=\nhac.mul_left hbc\n\n@[to_additive] protected lemma right_comm (h : commute b c) (a : S) :\n  a * b * c = a * c * b :=\nby simp only [mul_assoc, h.eq]\n\n@[to_additive] protected lemma left_comm (h : commute a b) (c) :\n  a * (b * c) = b * (a * c) :=\nby simp only [\u2190 mul_assoc, h.eq]\n\nend semigroup\n\n@[to_additive]\nprotected \n\nsection mul_one_class\n\nvariables {M : Type*} [mul_one_class M]\n\n@[simp, to_additive] theorem one_right (a : M) : commute a 1 := semiconj_by.one_right a\n@[simp, to_additive] theorem one_left (a : M) : commute 1 a := semiconj_by.one_left a\n\nend mul_one_class\n\nsection monoid\n\nvariables {M : Type*} [monoid M]\n\n@[to_additive] theorem units_inv_right {a : M} {u : units M} : commute a u \u2192 commute a \u2191u\u207b\u00b9 :=\nsemiconj_by.units_inv_right\n\n@[simp, to_additive] theorem units_inv_right_iff {a : M} {u : units M} :\n  commute a \u2191u\u207b\u00b9 \u2194 commute a u :=\nsemiconj_by.units_inv_right_iff\n\n@[to_additive] theorem units_inv_left {u : units M} {a : M} : commute \u2191u a \u2192 commute \u2191u\u207b\u00b9 a :=\nsemiconj_by.units_inv_symm_left\n\n@[simp, to_additive]\ntheorem units_inv_left_iff {u : units M} {a : M}: commute \u2191u\u207b\u00b9 a \u2194 commute \u2191u a :=\nsemiconj_by.units_inv_symm_left_iff\n\nvariables {u\u2081 u\u2082 : units M}\n\n@[to_additive]\ntheorem units_coe : commute u\u2081 u\u2082 \u2192 commute (u\u2081 : M) u\u2082 := semiconj_by.units_coe\n@[to_additive]\ntheorem units_of_coe : commute (u\u2081 : M) u\u2082 \u2192 commute u\u2081 u\u2082 := semiconj_by.units_of_coe\n@[simp, to_additive]\ntheorem units_coe_iff : commute (u\u2081 : M) u\u2082 \u2194 commute u\u2081 u\u2082 := semiconj_by.units_coe_iff\n\nend monoid\n\nsection group\n\nvariables {G : Type*} [group G] {a b : G}\n\n@[to_additive]\ntheorem inv_right : commute a b \u2192 commute a b\u207b\u00b9 := semiconj_by.inv_right\n@[simp, to_additive]\ntheorem inv_right_iff : commute a b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_right_iff\n\n@[to_additive] theorem inv_left :  commute a b \u2192 commute a\u207b\u00b9 b := semiconj_by.inv_symm_left\n@[simp, to_additive]\ntheorem inv_left_iff : commute a\u207b\u00b9 b \u2194 commute a b := semiconj_by.inv_symm_left_iff\n\n@[to_additive]\ntheorem inv_inv : commute a b \u2192 commute a\u207b\u00b9 b\u207b\u00b9 := semiconj_by.inv_inv_symm\n@[simp, to_additive]\ntheorem inv_inv_iff : commute a\u207b\u00b9 b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_inv_symm_iff\n\n@[to_additive]\nprotected theorem inv_mul_cancel (h : commute a b) : a\u207b\u00b9 * b * a = b :=\nby rw [h.inv_left.eq, inv_mul_cancel_right]\n\n@[to_additive]\ntheorem inv_mul_cancel_assoc (h : commute a b) : a\u207b\u00b9 * (b * a) = b :=\nby rw [\u2190 mul_assoc, h.inv_mul_cancel]\n\n@[to_additive]\nprotected theorem mul_inv_cancel (h : commute a b) : a * b * a\u207b\u00b9 = b :=\nby rw [h.eq, mul_inv_cancel_right]\n\n@[to_additive]\ntheorem mul_inv_cancel_assoc (h : commute a b) : a * (b * a\u207b\u00b9) = b :=\nby rw [\u2190 mul_assoc, h.mul_inv_cancel]\n\nend group\n\nend commute\n\nsection comm_group\n\nvariables {G : Type*} [comm_group G] (a b : G)\n\n@[simp, to_additive] lemma mul_inv_cancel_comm : a * b * a\u207b\u00b9 = b :=\n(commute.all a b).mul_inv_cancel\n\n@[simp, to_additive] lemma mul_inv_cancel_comm_assoc : a * (b * a\u207b\u00b9) = b :=\n(commute.all a b).mul_inv_cancel_assoc\n\n@[simp, to_additive] lemma inv_mul_cancel_comm : a\u207b\u00b9 * b * a = b :=\n(commute.all a b).inv_mul_cancel\n\n@[simp, to_additive] lemma inv_mul_cancel_comm_assoc : a\u207b\u00b9 * (b * a) = b :=\n(commute.all a b).inv_mul_cancel_assoc\n\nend comm_group\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/group/commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7385923385964823}}
{"text": "import Mathlib.Init.Set\nimport Mathlib.Data.List.Basic\n\nnamespace List\n\n/-- `Perm l\u2081 l\u2082` or `l\u2081 ~ l\u2082` asserts that `l\u2081` and `l\u2082` are Permutations\n  of each other. This is defined by induction using pairwise swaps. -/\ninductive Perm {\u03b1} : List \u03b1 \u2192 List \u03b1 \u2192 Prop\n| nil   : Perm [] []\n| cons  : \u2200 (x : \u03b1) {l\u2081 l\u2082 : List \u03b1}, Perm l\u2081 l\u2082 \u2192 Perm (x::l\u2081) (x::l\u2082)\n| swap  : \u2200 (x y : \u03b1) (l : List \u03b1), Perm (y::x::l) (x::y::l)\n| trans : \u2200 {l\u2081 l\u2082 l\u2083 : List \u03b1}, Perm l\u2081 l\u2082 \u2192 Perm l\u2082 l\u2083 \u2192 Perm l\u2081 l\u2083\n\nopen Perm\n\ninfixl:50 \" ~ \" => Perm\n\nprotected theorem Perm.refl : \u2200 (l : List \u03b1), l ~ l\n| []      => Perm.nil\n| (x::xs) => (Perm.refl xs).cons x\n\nprotected theorem Perm.symm {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2082 ~ l\u2081 := by\ninduction p with\n| nil => exact Perm.nil\n| cons x _ ih => exact Perm.cons x ih\n| swap x y l => exact Perm.swap y x l\n| trans _ _ ih\u2081 ih\u2082 => exact Perm.trans ih\u2082 ih\u2081\n\ntheorem Perm_comm {l\u2081 l\u2082 : List \u03b1} : l\u2081 ~ l\u2082 \u2194 l\u2082 ~ l\u2081 := \u27e8Perm.symm, Perm.symm\u27e9\n\ntheorem Perm.swap'\n  (x y : \u03b1)\n  {l\u2081 l\u2082 : List \u03b1}\n  (p : l\u2081 ~ l\u2082) :\n  y::x::l\u2081 ~ x::y::l\u2082 :=\n  have h1 : y :: l\u2081 ~ y :: l\u2082 := Perm.cons y p\n  have h2 : x :: y :: l\u2081 ~ x :: y :: l\u2082 := Perm.cons x h1\n  have h3 : y :: x :: l\u2081 ~ x :: y :: l\u2081 := Perm.swap x y l\u2081\n  Perm.trans h3 h2\n\ntheorem Perm.Equivalence : Equivalence (@Perm \u03b1) := \u27e8Perm.refl, Perm.symm, Perm.trans\u27e9\n\ninstance (\u03b1 : Type u) : Setoid (List \u03b1) := \u27e8Perm, Perm.Equivalence\u27e9\n\ntheorem Perm.subset {\u03b1 : Type u} {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 \u2286 l\u2082 := by\ninduction p with\n| nil => exact nil_subset _\n| cons _ _ ih => exact cons_subset_cons _ ih\n| swap x y l =>\n  intro a\n  rw [mem_cons]\n  exact fun\n  | Or.inl rfl => Mem.tail _ (Mem.head ..)\n  | Or.inr (Mem.head ..) => Mem.head ..\n  | Or.inr (Mem.tail _ a_mem_l) => Mem.tail _ (Mem.tail _ a_mem_l)\n| trans h1 h2 ih\u2081 ih\u2082 => exact subset.trans ih\u2081 ih\u2082\n\ntheorem perm_middle {a : \u03b1} : \u2200 {l\u2081 l\u2082 : List \u03b1}, l\u2081++a::l\u2082 ~ a::(l\u2081++l\u2082)\n| [], l\u2082 => Perm.refl _\n| (b::l\u2081), l\u2082 =>\n  let h2 := @perm_middle \u03b1 a l\u2081 l\u2082\n  (h2.cons _).trans (swap a b _)\n", "meta": {"author": "JOSHCLUNE", "repo": "Keller_reduction", "sha": "dc392b3da352fc1ffcfbecb1d4717d05f5faed4a", "save_path": "github-repos/lean/JOSHCLUNE-Keller_reduction", "path": "github-repos/lean/JOSHCLUNE-Keller_reduction/Keller_reduction-dc392b3da352fc1ffcfbecb1d4717d05f5faed4a/Lean4_Clique/Mathlib/Mathlib/Data/List/Perm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.738592338524881}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module measure_theory.function.conditional_expectation.basic\n! leanprover-community/mathlib commit 46b633fd842bef9469441c0209906f6dddd2b4f5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.InnerProductSpace.Projection\nimport Mathbin.MeasureTheory.Function.L2Space\nimport Mathbin.MeasureTheory.Function.AeEqOfIntegral\n\n/-! # Conditional expectation\n\nWe build the conditional expectation of an integrable function `f` with value in a Banach space\nwith respect to a measure `\u03bc` (defined on a measurable space structure `m0`) and a measurable space\nstructure `m` with `hm : m \u2264 m0` (a sub-sigma-algebra). This is an `m`-strongly measurable\nfunction `\u03bc[f|hm]` which is integrable and verifies `\u222b x in s, \u03bc[f|hm] x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc`\nfor all `m`-measurable sets `s`. It is unique as an element of `L\u00b9`.\n\nThe construction is done in four steps:\n* Define the conditional expectation of an `L\u00b2` function, as an element of `L\u00b2`. This is the\n  orthogonal projection on the subspace of almost everywhere `m`-measurable functions.\n* Show that the conditional expectation of the indicator of a measurable set with finite measure\n  is integrable and define a map `set \u03b1 \u2192 (E \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E))` which to a set associates a linear\n  map. That linear map sends `x \u2208 E` to the conditional expectation of the indicator of the set\n  with value `x`.\n* Extend that map to `condexp_L1_clm : (\u03b1 \u2192\u2081[\u03bc] E) \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E)`. This is done using the same\n  construction as the Bochner integral (see the file `measure_theory/integral/set_to_L1`).\n* Define the conditional expectation of a function `f : \u03b1 \u2192 E`, which is an integrable function\n  `\u03b1 \u2192 E` equal to 0 if `f` is not integrable, and equal to an `m`-measurable representative of\n  `condexp_L1_clm` applied to `[f]`, the equivalence class of `f` in `L\u00b9`.\n\n## Main results\n\nThe conditional expectation and its properties\n\n* `condexp (m : measurable_space \u03b1) (\u03bc : measure \u03b1) (f : \u03b1 \u2192 E)`: conditional expectation of `f`\n  with respect to `m`.\n* `integrable_condexp` : `condexp` is integrable.\n* `strongly_measurable_condexp` : `condexp` is `m`-strongly-measurable.\n* `set_integral_condexp (hf : integrable f \u03bc) (hs : measurable_set[m] s)` : if `m \u2264 m0` (the\n  \u03c3-algebra over which the measure is defined), then the conditional expectation verifies\n  `\u222b x in s, condexp m \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc` for any `m`-measurable set `s`.\n\nWhile `condexp` is function-valued, we also define `condexp_L1` with value in `L1` and a continuous\nlinear map `condexp_L1_clm` from `L1` to `L1`. `condexp` should be used in most cases.\n\nUniqueness of the conditional expectation\n\n* `Lp.ae_eq_of_forall_set_integral_eq'`: two `Lp` functions verifying the equality of integrals\n  defining the conditional expectation are equal.\n* `ae_eq_of_forall_set_integral_eq_of_sigma_finite'`: two functions verifying the equality of\n  integrals defining the conditional expectation are equal almost everywhere.\n  Requires `[sigma_finite (\u03bc.trim hm)]`.\n* `ae_eq_condexp_of_forall_set_integral_eq`: an a.e. `m`-measurable function which verifies the\n  equality of integrals is a.e. equal to `condexp`.\n\n## Notations\n\nFor a measure `\u03bc` defined on a measurable space structure `m0`, another measurable space structure\n`m` with `hm : m \u2264 m0` (a sub-\u03c3-algebra) and a function `f`, we define the notation\n* `\u03bc[f|m] = condexp m \u03bc f`.\n\n## Implementation notes\n\nMost of the results in this file are valid for a complete real normed space `F`.\nHowever, some lemmas also use `\ud835\udd5c : is_R_or_C`:\n* `condexp_L2` is defined only for an `inner_product_space` for now, and we use `\ud835\udd5c` for its field.\n* results about scalar multiplication are stated not only for `\u211d` but also for `\ud835\udd5c` if we happen to\n  have `normed_space \ud835\udd5c F`.\n\n## Tags\n\nconditional expectation, conditional expected value\n\n-/\n\n\nnoncomputable section\n\nopen TopologicalSpace MeasureTheory.lp Filter ContinuousLinearMap\n\nopen NNReal ENNReal Topology BigOperators MeasureTheory\n\nnamespace MeasureTheory\n\n/-- A function `f` verifies `ae_strongly_measurable' m f \u03bc` if it is `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. This is similar to `ae_strongly_measurable`, but the\n`measurable_space` structures used for the measurability statement and for the measure are\ndifferent. -/\ndef AeStronglyMeasurable' {\u03b1 \u03b2} [TopologicalSpace \u03b2] (m : MeasurableSpace \u03b1)\n    {m0 : MeasurableSpace \u03b1} (f : \u03b1 \u2192 \u03b2) (\u03bc : Measure \u03b1) : Prop :=\n  \u2203 g : \u03b1 \u2192 \u03b2, strongly_measurable[m] g \u2227 f =\u1d50[\u03bc] g\n#align measure_theory.ae_strongly_measurable' MeasureTheory.AeStronglyMeasurable'\n\nnamespace AeStronglyMeasurable'\n\nvariable {\u03b1 \u03b2 \ud835\udd5c : Type _} {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} [TopologicalSpace \u03b2]\n  {f g : \u03b1 \u2192 \u03b2}\n\ntheorem congr (hf : AeStronglyMeasurable' m f \u03bc) (hfg : f =\u1d50[\u03bc] g) : AeStronglyMeasurable' m g \u03bc :=\n  by\n  obtain \u27e8f', hf'_meas, hff'\u27e9 := hf\n  exact \u27e8f', hf'_meas, hfg.symm.trans hff'\u27e9\n#align measure_theory.ae_strongly_measurable'.congr MeasureTheory.AeStronglyMeasurable'.congr\n\ntheorem add [Add \u03b2] [ContinuousAdd \u03b2] (hf : AeStronglyMeasurable' m f \u03bc)\n    (hg : AeStronglyMeasurable' m g \u03bc) : AeStronglyMeasurable' m (f + g) \u03bc :=\n  by\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9\n  rcases hg with \u27e8g', h_g'_meas, hgg'\u27e9\n  exact \u27e8f' + g', h_f'_meas.add h_g'_meas, hff'.add hgg'\u27e9\n#align measure_theory.ae_strongly_measurable'.add MeasureTheory.AeStronglyMeasurable'.add\n\ntheorem neg [AddGroup \u03b2] [TopologicalAddGroup \u03b2] {f : \u03b1 \u2192 \u03b2} (hfm : AeStronglyMeasurable' m f \u03bc) :\n    AeStronglyMeasurable' m (-f) \u03bc :=\n  by\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9\n  refine' \u27e8-f', hf'_meas.neg, hf_ae.mono fun x hx => _\u27e9\n  simp_rw [Pi.neg_apply]\n  rw [hx]\n#align measure_theory.ae_strongly_measurable'.neg MeasureTheory.AeStronglyMeasurable'.neg\n\ntheorem sub [AddGroup \u03b2] [TopologicalAddGroup \u03b2] {f g : \u03b1 \u2192 \u03b2} (hfm : AeStronglyMeasurable' m f \u03bc)\n    (hgm : AeStronglyMeasurable' m g \u03bc) : AeStronglyMeasurable' m (f - g) \u03bc :=\n  by\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9\n  rcases hgm with \u27e8g', hg'_meas, hg_ae\u27e9\n  refine' \u27e8f' - g', hf'_meas.sub hg'_meas, hf_ae.mp (hg_ae.mono fun x hx1 hx2 => _)\u27e9\n  simp_rw [Pi.sub_apply]\n  rw [hx1, hx2]\n#align measure_theory.ae_strongly_measurable'.sub MeasureTheory.AeStronglyMeasurable'.sub\n\ntheorem constSmul [SMul \ud835\udd5c \u03b2] [ContinuousConstSMul \ud835\udd5c \u03b2] (c : \ud835\udd5c) (hf : AeStronglyMeasurable' m f \u03bc) :\n    AeStronglyMeasurable' m (c \u2022 f) \u03bc :=\n  by\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9\n  refine' \u27e8c \u2022 f', h_f'_meas.const_smul c, _\u27e9\n  exact eventually_eq.fun_comp hff' fun x => c \u2022 x\n#align measure_theory.ae_strongly_measurable'.const_smul MeasureTheory.AeStronglyMeasurable'.constSmul\n\ntheorem constInner {\ud835\udd5c \u03b2} [IsROrC \ud835\udd5c] [NormedAddCommGroup \u03b2] [InnerProductSpace \ud835\udd5c \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (hfm : AeStronglyMeasurable' m f \u03bc) (c : \u03b2) :\n    AeStronglyMeasurable' m (fun x => (inner c (f x) : \ud835\udd5c)) \u03bc :=\n  by\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9\n  refine'\n    \u27e8fun x => (inner c (f' x) : \ud835\udd5c), (@strongly_measurable_const _ _ m _ _).inner hf'_meas,\n      hf_ae.mono fun x hx => _\u27e9\n  dsimp only\n  rw [hx]\n#align measure_theory.ae_strongly_measurable'.const_inner MeasureTheory.AeStronglyMeasurable'.constInner\n\n/-- An `m`-strongly measurable function almost everywhere equal to `f`. -/\ndef mk (f : \u03b1 \u2192 \u03b2) (hfm : AeStronglyMeasurable' m f \u03bc) : \u03b1 \u2192 \u03b2 :=\n  hfm.some\n#align measure_theory.ae_strongly_measurable'.mk MeasureTheory.AeStronglyMeasurable'.mk\n\ntheorem stronglyMeasurable_mk {f : \u03b1 \u2192 \u03b2} (hfm : AeStronglyMeasurable' m f \u03bc) :\n    strongly_measurable[m] (hfm.mk f) :=\n  hfm.choose_spec.1\n#align measure_theory.ae_strongly_measurable'.strongly_measurable_mk MeasureTheory.AeStronglyMeasurable'.stronglyMeasurable_mk\n\ntheorem ae_eq_mk {f : \u03b1 \u2192 \u03b2} (hfm : AeStronglyMeasurable' m f \u03bc) : f =\u1d50[\u03bc] hfm.mk f :=\n  hfm.choose_spec.2\n#align measure_theory.ae_strongly_measurable'.ae_eq_mk MeasureTheory.AeStronglyMeasurable'.ae_eq_mk\n\ntheorem continuousComp {\u03b3} [TopologicalSpace \u03b3] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (hg : Continuous g)\n    (hf : AeStronglyMeasurable' m f \u03bc) : AeStronglyMeasurable' m (g \u2218 f) \u03bc :=\n  \u27e8fun x => g (hf.mk _ x),\n    @Continuous.comp_stronglyMeasurable _ _ _ m _ _ _ _ hg hf.stronglyMeasurable_mk,\n    hf.ae_eq_mk.mono fun x hx => by rw [Function.comp_apply, hx]\u27e9\n#align measure_theory.ae_strongly_measurable'.continuous_comp MeasureTheory.AeStronglyMeasurable'.continuousComp\n\nend AeStronglyMeasurable'\n\ntheorem aeStronglyMeasurable'OfAeStronglyMeasurable'Trim {\u03b1 \u03b2} {m m0 m0' : MeasurableSpace \u03b1}\n    [TopologicalSpace \u03b2] (hm0 : m0 \u2264 m0') {\u03bc : Measure \u03b1} {f : \u03b1 \u2192 \u03b2}\n    (hf : AeStronglyMeasurable' m f (\u03bc.trim hm0)) : AeStronglyMeasurable' m f \u03bc :=\n  by\n  obtain \u27e8g, hg_meas, hfg\u27e9 := hf\n  exact \u27e8g, hg_meas, ae_eq_of_ae_eq_trim hfg\u27e9\n#align measure_theory.ae_strongly_measurable'_of_ae_strongly_measurable'_trim MeasureTheory.aeStronglyMeasurable'OfAeStronglyMeasurable'Trim\n\ntheorem StronglyMeasurable.aeStronglyMeasurable' {\u03b1 \u03b2} {m m0 : MeasurableSpace \u03b1}\n    [TopologicalSpace \u03b2] {\u03bc : Measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : strongly_measurable[m] f) :\n    AeStronglyMeasurable' m f \u03bc :=\n  \u27e8f, hf, ae_eq_refl _\u27e9\n#align measure_theory.strongly_measurable.ae_strongly_measurable' MeasureTheory.StronglyMeasurable.aeStronglyMeasurable'\n\ntheorem ae_eq_trim_iff_of_aeStronglyMeasurable' {\u03b1 \u03b2} [TopologicalSpace \u03b2] [MetrizableSpace \u03b2]\n    {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {f g : \u03b1 \u2192 \u03b2} (hm : m \u2264 m0)\n    (hfm : AeStronglyMeasurable' m f \u03bc) (hgm : AeStronglyMeasurable' m g \u03bc) :\n    hfm.mk f =\u1d50[\u03bc.trim hm] hgm.mk g \u2194 f =\u1d50[\u03bc] g :=\n  (ae_eq_trim_iff hm hfm.stronglyMeasurable_mk hgm.stronglyMeasurable_mk).trans\n    \u27e8fun h => hfm.ae_eq_mk.trans (h.trans hgm.ae_eq_mk.symm), fun h =>\n      hfm.ae_eq_mk.symm.trans (h.trans hgm.ae_eq_mk)\u27e9\n#align measure_theory.ae_eq_trim_iff_of_ae_strongly_measurable' MeasureTheory.ae_eq_trim_iff_of_aeStronglyMeasurable'\n\n/-- If the restriction to a set `s` of a \u03c3-algebra `m` is included in the restriction to `s` of\nanother \u03c3-algebra `m\u2082` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` almost\neverywhere supported on `s` is `m`-ae-strongly-measurable, then `f` is also\n`m\u2082`-ae-strongly-measurable. -/\ntheorem AeStronglyMeasurable'.aeStronglyMeasurable'OfMeasurableSpaceLeOn {\u03b1 E}\n    {m m\u2082 m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} [TopologicalSpace E] [Zero E] (hm : m \u2264 m0)\n    {s : Set \u03b1} {f : \u03b1 \u2192 E} (hs_m : measurable_set[m] s)\n    (hs : \u2200 t, measurable_set[m] (s \u2229 t) \u2192 measurable_set[m\u2082] (s \u2229 t))\n    (hf : AeStronglyMeasurable' m f \u03bc) (hf_zero : f =\u1d50[\u03bc.restrict (s\u1d9c)] 0) :\n    AeStronglyMeasurable' m\u2082 f \u03bc := by\n  let f' := hf.mk f\n  have h_ind_eq : s.indicator (hf.mk f) =\u1d50[\u03bc] f :=\n    by\n    refine'\n      Filter.EventuallyEq.trans _ (indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs_m) hf_zero)\n    filter_upwards [hf.ae_eq_mk]with x hx\n    by_cases hxs : x \u2208 s\n    \u00b7 simp [hxs, hx]\n    \u00b7 simp [hxs]\n  suffices : strongly_measurable[m\u2082] (s.indicator (hf.mk f))\n  exact ae_strongly_measurable'.congr this.ae_strongly_measurable' h_ind_eq\n  have hf_ind : strongly_measurable[m] (s.indicator (hf.mk f)) :=\n    hf.strongly_measurable_mk.indicator hs_m\n  exact\n    hf_ind.strongly_measurable_of_measurable_space_le_on hs_m hs fun x hxs =>\n      Set.indicator_of_not_mem hxs _\n#align measure_theory.ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on MeasureTheory.AeStronglyMeasurable'.aeStronglyMeasurable'OfMeasurableSpaceLeOn\n\nvariable {\u03b1 \u03b2 \u03b3 E E' F F' G G' H \ud835\udd5c : Type _} {p : \u211d\u22650\u221e} [IsROrC \ud835\udd5c]\n  -- \ud835\udd5c for \u211d or \u2102\n  [TopologicalSpace \u03b2]\n  -- \u03b2 for a generic topological space\n  -- E for an inner product space\n  [NormedAddCommGroup E]\n  [InnerProductSpace \ud835\udd5c E]\n  -- E' for an inner product space on which we compute integrals\n  [NormedAddCommGroup E']\n  [InnerProductSpace \ud835\udd5c E'] [CompleteSpace E'] [NormedSpace \u211d E']\n  -- F for a Lp submodule\n  [NormedAddCommGroup F]\n  [NormedSpace \ud835\udd5c F]\n  -- F' for integrals on a Lp submodule\n  [NormedAddCommGroup F']\n  [NormedSpace \ud835\udd5c F'] [NormedSpace \u211d F'] [CompleteSpace F']\n  -- G for a Lp add_subgroup\n  [NormedAddCommGroup G]\n  -- G' for integrals on a Lp add_subgroup\n  [NormedAddCommGroup G']\n  [NormedSpace \u211d G'] [CompleteSpace G']\n  -- H for a normed group (hypotheses of mem_\u2112p)\n  [NormedAddCommGroup H]\n\nsection LpMeas\n\n/-! ## The subset `Lp_meas` of `Lp` functions a.e. measurable with respect to a sub-sigma-algebra -/\n\n\nvariable (F)\n\n/-- `Lp_meas_subgroup F m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef lpMeasSubgroup (m : MeasurableSpace \u03b1) [MeasurableSpace \u03b1] (p : \u211d\u22650\u221e) (\u03bc : Measure \u03b1) :\n    AddSubgroup (lp F p \u03bc)\n    where\n  carrier := { f : lp F p \u03bc | AeStronglyMeasurable' m f \u03bc }\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @stronglyMeasurable_zero _ _ m _ _, lp.coeFn_zero _ _ _\u27e9\n  add_mem' f g hf hg := (hf.add hg).congr (lp.coeFn_add f g).symm\n  neg_mem' f hf := AeStronglyMeasurable'.congr hf.neg (lp.coeFn_neg f).symm\n#align measure_theory.Lp_meas_subgroup MeasureTheory.lpMeasSubgroup\n\nvariable (\ud835\udd5c)\n\n/-- `Lp_meas F \ud835\udd5c m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef lpMeas (m : MeasurableSpace \u03b1) [MeasurableSpace \u03b1] (p : \u211d\u22650\u221e) (\u03bc : Measure \u03b1) :\n    Submodule \ud835\udd5c (lp F p \u03bc)\n    where\n  carrier := { f : lp F p \u03bc | AeStronglyMeasurable' m f \u03bc }\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @stronglyMeasurable_zero _ _ m _ _, lp.coeFn_zero _ _ _\u27e9\n  add_mem' f g hf hg := (hf.add hg).congr (lp.coeFn_add f g).symm\n  smul_mem' c f hf := (hf.const_smul c).congr (lp.coeFn_smul c f).symm\n#align measure_theory.Lp_meas MeasureTheory.lpMeas\n\nvariable {F \ud835\udd5c}\n\nvariable ()\n\ntheorem mem_lpMeasSubgroup_iff_aeStronglyMeasurable' {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n    {f : lp F p \u03bc} : f \u2208 lpMeasSubgroup F m p \u03bc \u2194 AeStronglyMeasurable' m f \u03bc := by\n  rw [\u2190 AddSubgroup.mem_carrier, Lp_meas_subgroup, Set.mem_setOf_eq]\n#align measure_theory.mem_Lp_meas_subgroup_iff_ae_strongly_measurable' MeasureTheory.mem_lpMeasSubgroup_iff_aeStronglyMeasurable'\n\ntheorem mem_lpMeas_iff_aeStronglyMeasurable' {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n    {f : lp F p \u03bc} : f \u2208 lpMeas F \ud835\udd5c m p \u03bc \u2194 AeStronglyMeasurable' m f \u03bc := by\n  rw [\u2190 SetLike.mem_coe, \u2190 Submodule.mem_carrier, Lp_meas, Set.mem_setOf_eq]\n#align measure_theory.mem_Lp_meas_iff_ae_strongly_measurable' MeasureTheory.mem_lpMeas_iff_aeStronglyMeasurable'\n\ntheorem lpMeas.aeStronglyMeasurable' {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n    (f : lpMeas F \ud835\udd5c m p \u03bc) : AeStronglyMeasurable' m f \u03bc :=\n  mem_lpMeas_iff_aeStronglyMeasurable'.mp f.Mem\n#align measure_theory.Lp_meas.ae_strongly_measurable' MeasureTheory.lpMeas.aeStronglyMeasurable'\n\ntheorem mem_lpMeas_self {m0 : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (f : lp F p \u03bc) :\n    f \u2208 lpMeas F \ud835\udd5c m0 p \u03bc :=\n  mem_lpMeas_iff_aeStronglyMeasurable'.mpr (lp.aeStronglyMeasurable f)\n#align measure_theory.mem_Lp_meas_self MeasureTheory.mem_lpMeas_self\n\ntheorem lpMeasSubgroup_coe {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {f : lpMeasSubgroup F m p \u03bc} :\n    \u21d1f = (f : lp F p \u03bc) :=\n  coeFn_coeBase f\n#align measure_theory.Lp_meas_subgroup_coe MeasureTheory.lpMeasSubgroup_coe\n\ntheorem lpMeas_coe {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {f : lpMeas F \ud835\udd5c m p \u03bc} :\n    \u21d1f = (f : lp F p \u03bc) :=\n  coeFn_coeBase f\n#align measure_theory.Lp_meas_coe MeasureTheory.lpMeas_coe\n\ntheorem mem_lpMeas_indicatorConstLp {m m0 : MeasurableSpace \u03b1} (hm : m \u2264 m0) {\u03bc : Measure \u03b1}\n    {s : Set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) {c : F} :\n    indicatorConstLp p (hm s hs) h\u03bcs c \u2208 lpMeas F \ud835\udd5c m p \u03bc :=\n  \u27e8s.indicator fun x : \u03b1 => c, (@stronglyMeasurable_const _ _ m _ _).indicator hs,\n    indicatorConstLp_coeFn\u27e9\n#align measure_theory.mem_Lp_meas_indicator_const_Lp MeasureTheory.mem_lpMeas_indicatorConstLp\n\nsection CompleteSubspace\n\n/-! ## The subspace `Lp_meas` is complete.\n\nWe define an `isometry_equiv` between `Lp_meas_subgroup` and the `Lp` space corresponding to the\nmeasure `\u03bc.trim hm`. As a consequence, the completeness of `Lp` implies completeness of\n`Lp_meas_subgroup` (and `Lp_meas`). -/\n\n\nvariable {\u03b9 : Type _} {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n\n/-- If `f` belongs to `Lp_meas_subgroup F m p \u03bc`, then the measurable function it is almost\neverywhere equal to (given by `ae_measurable.mk`) belongs to `\u2112p` for the measure `\u03bc.trim hm`. -/\ntheorem mem\u2112pTrimOfMemLpMeasSubgroup (hm : m \u2264 m0) (f : lp F p \u03bc)\n    (hf_meas : f \u2208 lpMeasSubgroup F m p \u03bc) :\n    Mem\u2112p (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp hf_meas).some p (\u03bc.trim hm) :=\n  by\n  have hf : ae_strongly_measurable' m f \u03bc :=\n    mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas\n  let g := hf.some\n  obtain \u27e8hg, hfg\u27e9 := hf.some_spec\n  change mem_\u2112p g p (\u03bc.trim hm)\n  refine' \u27e8hg.ae_strongly_measurable, _\u27e9\n  have h_snorm_fg : snorm g p (\u03bc.trim hm) = snorm f p \u03bc :=\n    by\n    rw [snorm_trim hm hg]\n    exact snorm_congr_ae hfg.symm\n  rw [h_snorm_fg]\n  exact Lp.snorm_lt_top f\n#align measure_theory.mem_\u2112p_trim_of_mem_Lp_meas_subgroup MeasureTheory.mem\u2112pTrimOfMemLpMeasSubgroup\n\n/-- If `f` belongs to `Lp` for the measure `\u03bc.trim hm`, then it belongs to the subgroup\n`Lp_meas_subgroup F m p \u03bc`. -/\ntheorem mem_lpMeasSubgroup_toLp_of_trim (hm : m \u2264 m0) (f : lp F p (\u03bc.trim hm)) :\n    (mem\u2112pOfMem\u2112pTrim hm (lp.mem\u2112p f)).toLp f \u2208 lpMeasSubgroup F m p \u03bc :=\n  by\n  let hf_mem_\u2112p := mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)\n  rw [mem_Lp_meas_subgroup_iff_ae_strongly_measurable']\n  refine' ae_strongly_measurable'.congr _ (mem_\u2112p.coe_fn_to_Lp hf_mem_\u2112p).symm\n  refine' ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm _\n  exact Lp.ae_strongly_measurable f\n#align measure_theory.mem_Lp_meas_subgroup_to_Lp_of_trim MeasureTheory.mem_lpMeasSubgroup_toLp_of_trim\n\nvariable (F p \u03bc)\n\n/-- Map from `Lp_meas_subgroup` to `Lp F p (\u03bc.trim hm)`. -/\ndef lpMeasSubgroupToLpTrim (hm : m \u2264 m0) (f : lpMeasSubgroup F m p \u03bc) : lp F p (\u03bc.trim hm) :=\n  Mem\u2112p.toLp (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp f.Mem).some\n    (mem\u2112pTrimOfMemLpMeasSubgroup hm f f.Mem)\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim MeasureTheory.lpMeasSubgroupToLpTrim\n\nvariable (\ud835\udd5c)\n\n/-- Map from `Lp_meas` to `Lp F p (\u03bc.trim hm)`. -/\ndef lpMeasToLpTrim (hm : m \u2264 m0) (f : lpMeas F \ud835\udd5c m p \u03bc) : lp F p (\u03bc.trim hm) :=\n  Mem\u2112p.toLp (mem_lpMeas_iff_aeStronglyMeasurable'.mp f.Mem).some\n    (mem\u2112pTrimOfMemLpMeasSubgroup hm f f.Mem)\n#align measure_theory.Lp_meas_to_Lp_trim MeasureTheory.lpMeasToLpTrim\n\nvariable {\ud835\udd5c}\n\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas_subgroup`, inverse of\n`Lp_meas_subgroup_to_Lp_trim`. -/\ndef lpTrimToLpMeasSubgroup (hm : m \u2264 m0) (f : lp F p (\u03bc.trim hm)) : lpMeasSubgroup F m p \u03bc :=\n  \u27e8(mem\u2112pOfMem\u2112pTrim hm (lp.mem\u2112p f)).toLp f, mem_lpMeasSubgroup_toLp_of_trim hm f\u27e9\n#align measure_theory.Lp_trim_to_Lp_meas_subgroup MeasureTheory.lpTrimToLpMeasSubgroup\n\nvariable (\ud835\udd5c)\n\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas`, inverse of `Lp_meas_to_Lp_trim`. -/\ndef lpTrimToLpMeas (hm : m \u2264 m0) (f : lp F p (\u03bc.trim hm)) : lpMeas F \ud835\udd5c m p \u03bc :=\n  \u27e8(mem\u2112pOfMem\u2112pTrim hm (lp.mem\u2112p f)).toLp f, mem_lpMeasSubgroup_toLp_of_trim hm f\u27e9\n#align measure_theory.Lp_trim_to_Lp_meas MeasureTheory.lpTrimToLpMeas\n\nvariable {F \ud835\udd5c p \u03bc}\n\ntheorem lpMeasSubgroupToLpTrim_ae_eq (hm : m \u2264 m0) (f : lpMeasSubgroup F m p \u03bc) :\n    lpMeasSubgroupToLpTrim F p \u03bc hm f =\u1d50[\u03bc] f :=\n  (ae_eq_of_ae_eq_trim (Mem\u2112p.coeFn_toLp (mem\u2112pTrimOfMemLpMeasSubgroup hm (\u2191f) f.Mem))).trans\n    (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp f.Mem).choose_spec.2.symm\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_ae_eq MeasureTheory.lpMeasSubgroupToLpTrim_ae_eq\n\ntheorem lpTrimToLpMeasSubgroup_ae_eq (hm : m \u2264 m0) (f : lp F p (\u03bc.trim hm)) :\n    lpTrimToLpMeasSubgroup F p \u03bc hm f =\u1d50[\u03bc] f :=\n  Mem\u2112p.coeFn_toLp _\n#align measure_theory.Lp_trim_to_Lp_meas_subgroup_ae_eq MeasureTheory.lpTrimToLpMeasSubgroup_ae_eq\n\ntheorem lpMeasToLpTrim_ae_eq (hm : m \u2264 m0) (f : lpMeas F \ud835\udd5c m p \u03bc) :\n    lpMeasToLpTrim F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\n  (ae_eq_of_ae_eq_trim (Mem\u2112p.coeFn_toLp (mem\u2112pTrimOfMemLpMeasSubgroup hm (\u2191f) f.Mem))).trans\n    (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp f.Mem).choose_spec.2.symm\n#align measure_theory.Lp_meas_to_Lp_trim_ae_eq MeasureTheory.lpMeasToLpTrim_ae_eq\n\ntheorem lpTrimToLpMeas_ae_eq (hm : m \u2264 m0) (f : lp F p (\u03bc.trim hm)) :\n    lpTrimToLpMeas F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\n  Mem\u2112p.coeFn_toLp _\n#align measure_theory.Lp_trim_to_Lp_meas_ae_eq MeasureTheory.lpTrimToLpMeas_ae_eq\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a right inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\ntheorem lpMeasSubgroupToLpTrim_right_inv (hm : m \u2264 m0) :\n    Function.RightInverse (lpTrimToLpMeasSubgroup F p \u03bc hm) (lpMeasSubgroupToLpTrim F p \u03bc hm) :=\n  by\n  intro f\n  ext1\n  refine'\n    ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) (Lp.strongly_measurable _) _\n  exact (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _)\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_right_inv MeasureTheory.lpMeasSubgroupToLpTrim_right_inv\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a left inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\ntheorem lpMeasSubgroupToLpTrim_left_inv (hm : m \u2264 m0) :\n    Function.LeftInverse (lpTrimToLpMeasSubgroup F p \u03bc hm) (lpMeasSubgroupToLpTrim F p \u03bc hm) :=\n  by\n  intro f\n  ext1\n  ext1\n  rw [\u2190 Lp_meas_subgroup_coe]\n  exact (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _).trans (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _)\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_left_inv MeasureTheory.lpMeasSubgroupToLpTrim_left_inv\n\ntheorem lpMeasSubgroupToLpTrim_add (hm : m \u2264 m0) (f g : lpMeasSubgroup F m p \u03bc) :\n    lpMeasSubgroupToLpTrim F p \u03bc hm (f + g) =\n      lpMeasSubgroupToLpTrim F p \u03bc hm f + lpMeasSubgroupToLpTrim F p \u03bc hm g :=\n  by\n  ext1\n  refine' eventually_eq.trans _ (Lp.coe_fn_add _ _).symm\n  refine' ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _\n  \u00b7 exact (Lp.strongly_measurable _).add (Lp.strongly_measurable _)\n  refine' (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _\n  refine'\n    eventually_eq.trans _\n      (eventually_eq.add (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm\n        (Lp_meas_subgroup_to_Lp_trim_ae_eq hm g).symm)\n  refine' (Lp.coe_fn_add _ _).trans _\n  simp_rw [Lp_meas_subgroup_coe]\n  exact eventually_of_forall fun x => by rfl\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_add MeasureTheory.lpMeasSubgroupToLpTrim_add\n\ntheorem lpMeasSubgroupToLpTrim_neg (hm : m \u2264 m0) (f : lpMeasSubgroup F m p \u03bc) :\n    lpMeasSubgroupToLpTrim F p \u03bc hm (-f) = -lpMeasSubgroupToLpTrim F p \u03bc hm f :=\n  by\n  ext1\n  refine' eventually_eq.trans _ (Lp.coe_fn_neg _).symm\n  refine' ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _\n  \u00b7 exact @strongly_measurable.neg _ _ _ m _ _ _ (Lp.strongly_measurable _)\n  refine' (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _\n  refine' eventually_eq.trans _ (eventually_eq.neg (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm)\n  refine' (Lp.coe_fn_neg _).trans _\n  simp_rw [Lp_meas_subgroup_coe]\n  exact eventually_of_forall fun x => by rfl\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_neg MeasureTheory.lpMeasSubgroupToLpTrim_neg\n\ntheorem lpMeasSubgroupToLpTrim_sub (hm : m \u2264 m0) (f g : lpMeasSubgroup F m p \u03bc) :\n    lpMeasSubgroupToLpTrim F p \u03bc hm (f - g) =\n      lpMeasSubgroupToLpTrim F p \u03bc hm f - lpMeasSubgroupToLpTrim F p \u03bc hm g :=\n  by\n  rw [sub_eq_add_neg, sub_eq_add_neg, Lp_meas_subgroup_to_Lp_trim_add,\n    Lp_meas_subgroup_to_Lp_trim_neg]\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_sub MeasureTheory.lpMeasSubgroupToLpTrim_sub\n\ntheorem lpMeasToLpTrim_smul (hm : m \u2264 m0) (c : \ud835\udd5c) (f : lpMeas F \ud835\udd5c m p \u03bc) :\n    lpMeasToLpTrim F \ud835\udd5c p \u03bc hm (c \u2022 f) = c \u2022 lpMeasToLpTrim F \ud835\udd5c p \u03bc hm f :=\n  by\n  ext1\n  refine' eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm\n  refine' ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _\n  \u00b7 exact (Lp.strongly_measurable _).const_smul c\n  refine' (Lp_meas_to_Lp_trim_ae_eq hm _).trans _\n  refine' (Lp.coe_fn_smul _ _).trans _\n  refine' (Lp_meas_to_Lp_trim_ae_eq hm f).mono fun x hx => _\n  rw [Pi.smul_apply, Pi.smul_apply, hx]\n  rfl\n#align measure_theory.Lp_meas_to_Lp_trim_smul MeasureTheory.lpMeasToLpTrim_smul\n\n/-- `Lp_meas_subgroup_to_Lp_trim` preserves the norm. -/\ntheorem lpMeasSubgroupToLpTrim_norm_map [hp : Fact (1 \u2264 p)] (hm : m \u2264 m0)\n    (f : lpMeasSubgroup F m p \u03bc) : \u2016lpMeasSubgroupToLpTrim F p \u03bc hm f\u2016 = \u2016f\u2016 :=\n  by\n  rw [Lp.norm_def, snorm_trim hm (Lp.strongly_measurable _),\n    snorm_congr_ae (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _), Lp_meas_subgroup_coe, \u2190 Lp.norm_def]\n  congr\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_norm_map MeasureTheory.lpMeasSubgroupToLpTrim_norm_map\n\ntheorem isometry_lpMeasSubgroupToLpTrim [hp : Fact (1 \u2264 p)] (hm : m \u2264 m0) :\n    Isometry (lpMeasSubgroupToLpTrim F p \u03bc hm) :=\n  Isometry.of_dist_eq fun f g => by\n    rw [dist_eq_norm, \u2190 Lp_meas_subgroup_to_Lp_trim_sub, Lp_meas_subgroup_to_Lp_trim_norm_map,\n      dist_eq_norm]\n#align measure_theory.isometry_Lp_meas_subgroup_to_Lp_trim MeasureTheory.isometry_lpMeasSubgroupToLpTrim\n\nvariable (F p \u03bc)\n\n/-- `Lp_meas_subgroup` and `Lp F p (\u03bc.trim hm)` are isometric. -/\ndef lpMeasSubgroupToLpTrimIso [hp : Fact (1 \u2264 p)] (hm : m \u2264 m0) :\n    lpMeasSubgroup F m p \u03bc \u2243\u1d62 lp F p (\u03bc.trim hm)\n    where\n  toFun := lpMeasSubgroupToLpTrim F p \u03bc hm\n  invFun := lpTrimToLpMeasSubgroup F p \u03bc hm\n  left_inv := lpMeasSubgroupToLpTrim_left_inv hm\n  right_inv := lpMeasSubgroupToLpTrim_right_inv hm\n  isometry_toFun := isometry_lpMeasSubgroupToLpTrim hm\n#align measure_theory.Lp_meas_subgroup_to_Lp_trim_iso MeasureTheory.lpMeasSubgroupToLpTrimIso\n\nvariable (\ud835\udd5c)\n\n/-- `Lp_meas_subgroup` and `Lp_meas` are isometric. -/\ndef lpMeasSubgroupToLpMeasIso [hp : Fact (1 \u2264 p)] : lpMeasSubgroup F m p \u03bc \u2243\u1d62 lpMeas F \ud835\udd5c m p \u03bc :=\n  IsometryEquiv.refl (lpMeasSubgroup F m p \u03bc)\n#align measure_theory.Lp_meas_subgroup_to_Lp_meas_iso MeasureTheory.lpMeasSubgroupToLpMeasIso\n\n/-- `Lp_meas` and `Lp F p (\u03bc.trim hm)` are isometric, with a linear equivalence. -/\ndef lpMeasToLpTrimLie [hp : Fact (1 \u2264 p)] (hm : m \u2264 m0) : lpMeas F \ud835\udd5c m p \u03bc \u2243\u2097\u1d62[\ud835\udd5c] lp F p (\u03bc.trim hm)\n    where\n  toFun := lpMeasToLpTrim F \ud835\udd5c p \u03bc hm\n  invFun := lpTrimToLpMeas F \ud835\udd5c p \u03bc hm\n  left_inv := lpMeasSubgroupToLpTrim_left_inv hm\n  right_inv := lpMeasSubgroupToLpTrim_right_inv hm\n  map_add' := lpMeasSubgroupToLpTrim_add hm\n  map_smul' := lpMeasToLpTrim_smul hm\n  norm_map' := lpMeasSubgroupToLpTrim_norm_map hm\n#align measure_theory.Lp_meas_to_Lp_trim_lie MeasureTheory.lpMeasToLpTrimLie\n\nvariable {F \ud835\udd5c p \u03bc}\n\ninstance [hm : Fact (m \u2264 m0)] [CompleteSpace F] [hp : Fact (1 \u2264 p)] :\n    CompleteSpace (lpMeasSubgroup F m p \u03bc) :=\n  by\n  rw [(Lp_meas_subgroup_to_Lp_trim_iso F p \u03bc hm.elim).completeSpace_iff]\n  infer_instance\n\ninstance [hm : Fact (m \u2264 m0)] [CompleteSpace F] [hp : Fact (1 \u2264 p)] :\n    CompleteSpace (lpMeas F \ud835\udd5c m p \u03bc) :=\n  by\n  rw [(Lp_meas_subgroup_to_Lp_meas_iso F \ud835\udd5c p \u03bc).symm.completeSpace_iff]\n  infer_instance\n\ntheorem isComplete_aeStronglyMeasurable' [hp : Fact (1 \u2264 p)] [CompleteSpace F] (hm : m \u2264 m0) :\n    IsComplete { f : lp F p \u03bc | AeStronglyMeasurable' m f \u03bc } :=\n  by\n  rw [\u2190 completeSpace_coe_iff_isComplete]\n  haveI : Fact (m \u2264 m0) := \u27e8hm\u27e9\n  change CompleteSpace (Lp_meas_subgroup F m p \u03bc)\n  infer_instance\n#align measure_theory.is_complete_ae_strongly_measurable' MeasureTheory.isComplete_aeStronglyMeasurable'\n\ntheorem isClosed_aeStronglyMeasurable' [hp : Fact (1 \u2264 p)] [CompleteSpace F] (hm : m \u2264 m0) :\n    IsClosed { f : lp F p \u03bc | AeStronglyMeasurable' m f \u03bc } :=\n  IsComplete.isClosed (isComplete_aeStronglyMeasurable' hm)\n#align measure_theory.is_closed_ae_strongly_measurable' MeasureTheory.isClosed_aeStronglyMeasurable'\n\nend CompleteSubspace\n\nsection StronglyMeasurable\n\nvariable {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n\n/-- We do not get `ae_fin_strongly_measurable f (\u03bc.trim hm)`, since we don't have\n`f =\u1d50[\u03bc.trim hm] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f` but only the weaker\n`f =\u1d50[\u03bc] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f`. -/\ntheorem lpMeas.ae_fin_strongly_measurable' (hm : m \u2264 m0) (f : lpMeas F \ud835\udd5c m p \u03bc) (hp_ne_zero : p \u2260 0)\n    (hp_ne_top : p \u2260 \u221e) : \u2203 g, FinStronglyMeasurable g (\u03bc.trim hm) \u2227 f =\u1d50[\u03bc] g :=\n  \u27e8lpMeasSubgroupToLpTrim F p \u03bc hm f, lp.finStronglyMeasurable _ hp_ne_zero hp_ne_top,\n    (lpMeasSubgroupToLpTrim_ae_eq hm f).symm\u27e9\n#align measure_theory.Lp_meas.ae_fin_strongly_measurable' MeasureTheory.lpMeas.ae_fin_strongly_measurable'\n\n/-- When applying the inverse of `Lp_meas_to_Lp_trim_lie` (which takes a function in the Lp space of\nthe sub-sigma algebra and returns its version in the larger Lp space) to an indicator of the\nsub-sigma-algebra, we obtain an indicator in the Lp space of the larger sigma-algebra. -/\ntheorem lpMeasToLpTrimLie_symm_indicator [one_le_p : Fact (1 \u2264 p)] [NormedSpace \u211d F] {hm : m \u2264 m0}\n    {s : Set \u03b1} {\u03bc : Measure \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc.trim hm s \u2260 \u221e) (c : F) :\n    ((lpMeasToLpTrimLie F \u211d p \u03bc hm).symm (indicatorConstLp p hs h\u03bcs c) : lp F p \u03bc) =\n      indicatorConstLp p (hm s hs) ((le_trim hm).trans_lt h\u03bcs.lt_top).Ne c :=\n  by\n  ext1\n  rw [\u2190 Lp_meas_coe]\n  change\n    Lp_trim_to_Lp_meas F \u211d p \u03bc hm (indicator_const_Lp p hs h\u03bcs c) =\u1d50[\u03bc]\n      (indicator_const_Lp p _ _ c : \u03b1 \u2192 F)\n  refine' (Lp_trim_to_Lp_meas_ae_eq hm _).trans _\n  exact (ae_eq_of_ae_eq_trim indicator_const_Lp_coe_fn).trans indicator_const_Lp_coe_fn.symm\n#align measure_theory.Lp_meas_to_Lp_trim_lie_symm_indicator MeasureTheory.lpMeasToLpTrimLie_symm_indicator\n\ntheorem lpMeasToLpTrimLie_symm_toLp [one_le_p : Fact (1 \u2264 p)] [NormedSpace \u211d F] (hm : m \u2264 m0)\n    (f : \u03b1 \u2192 F) (hf : Mem\u2112p f p (\u03bc.trim hm)) :\n    ((lpMeasToLpTrimLie F \u211d p \u03bc hm).symm (hf.toLp f) : lp F p \u03bc) =\n      (mem\u2112pOfMem\u2112pTrim hm hf).toLp f :=\n  by\n  ext1\n  rw [\u2190 Lp_meas_coe]\n  refine' (Lp_trim_to_Lp_meas_ae_eq hm _).trans _\n  exact (ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp hf)).trans (mem_\u2112p.coe_fn_to_Lp _).symm\n#align measure_theory.Lp_meas_to_Lp_trim_lie_symm_to_Lp MeasureTheory.lpMeasToLpTrimLie_symm_toLp\n\nend StronglyMeasurable\n\nend LpMeas\n\nsection Induction\n\nvariable {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} [Fact (1 \u2264 p)] [NormedSpace \u211d F]\n\n/-- Auxiliary lemma for `Lp.induction_strongly_measurable`. -/\n@[elab_as_elim]\ntheorem lp.inductionStronglyMeasurableAux (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e) (P : lp F p \u03bc \u2192 Prop)\n    (h_ind :\n      \u2200 (c : F) {s : Set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s < \u221e),\n        P (lp.simpleFunc.indicatorConst p (hm s hs) h\u03bcs.Ne c))\n    (h_add :\n      \u2200 \u2983f g\u2984,\n        \u2200 hf : Mem\u2112p f p \u03bc,\n          \u2200 hg : Mem\u2112p g p \u03bc,\n            \u2200 hfm : AeStronglyMeasurable' m f \u03bc,\n              \u2200 hgm : AeStronglyMeasurable' m g \u03bc,\n                Disjoint (Function.support f) (Function.support g) \u2192\n                  P (hf.toLp f) \u2192 P (hg.toLp g) \u2192 P (hf.toLp f + hg.toLp g))\n    (h_closed : IsClosed { f : lpMeas F \u211d m p \u03bc | P f }) :\n    \u2200 f : lp F p \u03bc, AeStronglyMeasurable' m f \u03bc \u2192 P f :=\n  by\n  intro f hf\n  let f' := (\u27e8f, hf\u27e9 : Lp_meas F \u211d m p \u03bc)\n  let g := Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm f'\n  have hfg : f' = (Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm g := by\n    simp only [LinearIsometryEquiv.symm_apply_apply]\n  change P \u2191f'\n  rw [hfg]\n  refine'\n    @Lp.induction \u03b1 F m _ p (\u03bc.trim hm) _ hp_ne_top\n      (fun g => P ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm g)) _ _ _ g\n  \u00b7 intro b t ht h\u03bct\n    rw [Lp.simple_func.coe_indicator_const, Lp_meas_to_Lp_trim_lie_symm_indicator ht h\u03bct.ne b]\n    have h\u03bct' : \u03bc t < \u221e := (le_trim hm).trans_lt h\u03bct\n    specialize h_ind b ht h\u03bct'\n    rwa [Lp.simple_func.coe_indicator_const] at h_ind\n  \u00b7 intro f g hf hg h_disj hfP hgP\n    rw [LinearIsometryEquiv.map_add]\n    push_cast\n    have h_eq :\n      \u2200 (f : \u03b1 \u2192 F) (hf : mem_\u2112p f p (\u03bc.trim hm)),\n        ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm (mem_\u2112p.to_Lp f hf) : Lp F p \u03bc) =\n          (mem_\u2112p_of_mem_\u2112p_trim hm hf).toLp f :=\n      Lp_meas_to_Lp_trim_lie_symm_to_Lp hm\n    rw [h_eq f hf] at hfP\u22a2\n    rw [h_eq g hg] at hgP\u22a2\n    exact\n      h_add (mem_\u2112p_of_mem_\u2112p_trim hm hf) (mem_\u2112p_of_mem_\u2112p_trim hm hg)\n        (ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hf.ae_strongly_measurable)\n        (ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hg.ae_strongly_measurable)\n        h_disj hfP hgP\n  \u00b7 change IsClosed ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm \u207b\u00b9' { g : Lp_meas F \u211d m p \u03bc | P \u2191g })\n    exact IsClosed.preimage (LinearIsometryEquiv.continuous _) h_closed\n#align measure_theory.Lp.induction_strongly_measurable_aux MeasureTheory.lp.inductionStronglyMeasurableAux\n\n/-- To prove something for an `Lp` function a.e. strongly measurable with respect to a\nsub-\u03c3-algebra `m` in a normed space, it suffices to show that\n* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;\n* is closed under addition;\n* the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is\n  closed.\n-/\n@[elab_as_elim]\ntheorem lp.inductionStronglyMeasurable (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e) (P : lp F p \u03bc \u2192 Prop)\n    (h_ind :\n      \u2200 (c : F) {s : Set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s < \u221e),\n        P (lp.simpleFunc.indicatorConst p (hm s hs) h\u03bcs.Ne c))\n    (h_add :\n      \u2200 \u2983f g\u2984,\n        \u2200 hf : Mem\u2112p f p \u03bc,\n          \u2200 hg : Mem\u2112p g p \u03bc,\n            \u2200 hfm : strongly_measurable[m] f,\n              \u2200 hgm : strongly_measurable[m] g,\n                Disjoint (Function.support f) (Function.support g) \u2192\n                  P (hf.toLp f) \u2192 P (hg.toLp g) \u2192 P (hf.toLp f + hg.toLp g))\n    (h_closed : IsClosed { f : lpMeas F \u211d m p \u03bc | P f }) :\n    \u2200 f : lp F p \u03bc, AeStronglyMeasurable' m f \u03bc \u2192 P f :=\n  by\n  intro f hf\n  suffices h_add_ae :\n    \u2200 \u2983f g\u2984,\n      \u2200 hf : mem_\u2112p f p \u03bc,\n        \u2200 hg : mem_\u2112p g p \u03bc,\n          \u2200 hfm : ae_strongly_measurable' m f \u03bc,\n            \u2200 hgm : ae_strongly_measurable' m g \u03bc,\n              Disjoint (Function.support f) (Function.support g) \u2192\n                P (hf.toLp f) \u2192 P (hg.toLp g) \u2192 P (hf.toLp f + hg.toLp g)\n  exact Lp.induction_strongly_measurable_aux hm hp_ne_top P h_ind h_add_ae h_closed f hf\n  intro f g hf hg hfm hgm h_disj hPf hPg\n  let s_f : Set \u03b1 := Function.support (hfm.mk f)\n  have hs_f : measurable_set[m] s_f := hfm.strongly_measurable_mk.measurable_set_support\n  have hs_f_eq : s_f =\u1d50[\u03bc] Function.support f := hfm.ae_eq_mk.symm.support\n  let s_g : Set \u03b1 := Function.support (hgm.mk g)\n  have hs_g : measurable_set[m] s_g := hgm.strongly_measurable_mk.measurable_set_support\n  have hs_g_eq : s_g =\u1d50[\u03bc] Function.support g := hgm.ae_eq_mk.symm.support\n  have h_inter_empty : (s_f \u2229 s_g : Set \u03b1) =\u1d50[\u03bc] (\u2205 : Set \u03b1) :=\n    by\n    refine' (hs_f_eq.inter hs_g_eq).trans _\n    suffices Function.support f \u2229 Function.support g = \u2205 by rw [this]\n    exact set.disjoint_iff_inter_eq_empty.mp h_disj\n  let f' := (s_f \\ s_g).indicator (hfm.mk f)\n  have hff' : f =\u1d50[\u03bc] f' :=\n    by\n    have : s_f \\ s_g =\u1d50[\u03bc] s_f :=\n      by\n      rw [\u2190 Set.diff_inter_self_eq_diff, Set.inter_comm]\n      refine' ((ae_eq_refl s_f).diff\u2093 h_inter_empty).trans _\n      rw [Set.diff_empty]\n    refine' ((indicator_ae_eq_of_ae_eq_set this).trans _).symm\n    rw [Set.indicator_support]\n    exact hfm.ae_eq_mk.symm\n  have hf'_meas : strongly_measurable[m] f' := hfm.strongly_measurable_mk.indicator (hs_f.diff hs_g)\n  have hf'_Lp : mem_\u2112p f' p \u03bc := hf.ae_eq hff'\n  let g' := (s_g \\ s_f).indicator (hgm.mk g)\n  have hgg' : g =\u1d50[\u03bc] g' :=\n    by\n    have : s_g \\ s_f =\u1d50[\u03bc] s_g := by\n      rw [\u2190 Set.diff_inter_self_eq_diff]\n      refine' ((ae_eq_refl s_g).diff\u2093 h_inter_empty).trans _\n      rw [Set.diff_empty]\n    refine' ((indicator_ae_eq_of_ae_eq_set this).trans _).symm\n    rw [Set.indicator_support]\n    exact hgm.ae_eq_mk.symm\n  have hg'_meas : strongly_measurable[m] g' := hgm.strongly_measurable_mk.indicator (hs_g.diff hs_f)\n  have hg'_Lp : mem_\u2112p g' p \u03bc := hg.ae_eq hgg'\n  have h_disj : Disjoint (Function.support f') (Function.support g') :=\n    haveI : Disjoint (s_f \\ s_g) (s_g \\ s_f) := disjoint_sdiff_sdiff\n    this.mono Set.support_indicator_subset Set.support_indicator_subset\n  rw [\u2190 mem_\u2112p.to_Lp_congr hf'_Lp hf hff'.symm] at hPf\u22a2\n  rw [\u2190 mem_\u2112p.to_Lp_congr hg'_Lp hg hgg'.symm] at hPg\u22a2\n  exact h_add hf'_Lp hg'_Lp hf'_meas hg'_meas h_disj hPf hPg\n#align measure_theory.Lp.induction_strongly_measurable MeasureTheory.lp.inductionStronglyMeasurable\n\n/-- To prove something for an arbitrary `mem_\u2112p` function a.e. strongly measurable with respect\nto a sub-\u03c3-algebra `m` in a normed space, it suffices to show that\n* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;\n* is closed under addition;\n* the set of functions in the `L\u1d56` space strongly measurable w.r.t. `m` for which the property\n  holds is closed.\n* the property is closed under the almost-everywhere equal relation.\n-/\n@[elab_as_elim]\ntheorem Mem\u2112p.inductionStronglyMeasurable (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e) (P : (\u03b1 \u2192 F) \u2192 Prop)\n    (h_ind : \u2200 (c : F) \u2983s\u2984, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 P (s.indicator fun _ => c))\n    (h_add :\n      \u2200 \u2983f g : \u03b1 \u2192 F\u2984,\n        Disjoint (Function.support f) (Function.support g) \u2192\n          Mem\u2112p f p \u03bc \u2192\n            Mem\u2112p g p \u03bc \u2192\n              strongly_measurable[m] f \u2192 strongly_measurable[m] g \u2192 P f \u2192 P g \u2192 P (f + g))\n    (h_closed : IsClosed { f : lpMeas F \u211d m p \u03bc | P f })\n    (h_ae : \u2200 \u2983f g\u2984, f =\u1d50[\u03bc] g \u2192 Mem\u2112p f p \u03bc \u2192 P f \u2192 P g) :\n    \u2200 \u2983f : \u03b1 \u2192 F\u2984 (hf : Mem\u2112p f p \u03bc) (hfm : AeStronglyMeasurable' m f \u03bc), P f :=\n  by\n  intro f hf hfm\n  let f_Lp := hf.to_Lp f\n  have hfm_Lp : ae_strongly_measurable' m f_Lp \u03bc := hfm.congr hf.coe_fn_to_Lp.symm\n  refine' h_ae hf.coe_fn_to_Lp (Lp.mem_\u2112p _) _\n  change P f_Lp\n  refine' Lp.induction_strongly_measurable hm hp_ne_top (fun f => P \u21d1f) _ _ h_closed f_Lp hfm_Lp\n  \u00b7 intro c s hs h\u03bcs\n    rw [Lp.simple_func.coe_indicator_const]\n    refine' h_ae indicator_const_Lp_coe_fn.symm _ (h_ind c hs h\u03bcs)\n    exact mem_\u2112p_indicator_const p (hm s hs) c (Or.inr h\u03bcs.ne)\n  \u00b7 intro f g hf_mem hg_mem hfm hgm h_disj hfP hgP\n    have hfP' : P f := h_ae hf_mem.coe_fn_to_Lp (Lp.mem_\u2112p _) hfP\n    have hgP' : P g := h_ae hg_mem.coe_fn_to_Lp (Lp.mem_\u2112p _) hgP\n    specialize h_add h_disj hf_mem hg_mem hfm hgm hfP' hgP'\n    refine' h_ae _ (hf_mem.add hg_mem) h_add\n    exact (hf_mem.coe_fn_to_Lp.symm.add hg_mem.coe_fn_to_Lp.symm).trans (Lp.coe_fn_add _ _).symm\n#align measure_theory.mem_\u2112p.induction_strongly_measurable MeasureTheory.Mem\u2112p.inductionStronglyMeasurable\n\nend Induction\n\nsection UniquenessOfConditionalExpectation\n\n/-! ## Uniqueness of the conditional expectation -/\n\n\nvariable {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n\ntheorem lpMeas.ae_eq_zero_of_forall_set_integral_eq_zero (hm : m \u2264 m0) (f : lpMeas E' \ud835\udd5c m p \u03bc)\n    (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n    (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 IntegrableOn f s \u03bc)\n    (hf_zero : \u2200 s : Set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 (\u222b x in s, f x \u2202\u03bc) = 0) : f =\u1d50[\u03bc] 0 :=\n  by\n  obtain \u27e8g, hg_sm, hfg\u27e9 := Lp_meas.ae_fin_strongly_measurable' hm f hp_ne_zero hp_ne_top\n  refine' hfg.trans _\n  refine' ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim hm _ _ hg_sm\n  \u00b7 intro s hs h\u03bcs\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g := ae_restrict_of_ae hfg\n    rw [integrable_on, integrable_congr hfg_restrict.symm]\n    exact hf_int_finite s hs h\u03bcs\n  \u00b7 intro s hs h\u03bcs\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g := ae_restrict_of_ae hfg\n    rw [integral_congr_ae hfg_restrict.symm]\n    exact hf_zero s hs h\u03bcs\n#align measure_theory.Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero MeasureTheory.lpMeas.ae_eq_zero_of_forall_set_integral_eq_zero\n\ninclude \ud835\udd5c\n\nvariable (\ud835\udd5c)\n\ntheorem lp.ae_eq_zero_of_forall_set_integral_eq_zero' (hm : m \u2264 m0) (f : lp E' p \u03bc)\n    (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n    (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 IntegrableOn f s \u03bc)\n    (hf_zero : \u2200 s : Set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 (\u222b x in s, f x \u2202\u03bc) = 0)\n    (hf_meas : AeStronglyMeasurable' m f \u03bc) : f =\u1d50[\u03bc] 0 :=\n  by\n  let f_meas : Lp_meas E' \ud835\udd5c m p \u03bc := \u27e8f, hf_meas\u27e9\n  have hf_f_meas : f =\u1d50[\u03bc] f_meas := by simp only [coeFn_coe_base', Subtype.coe_mk]\n  refine' hf_f_meas.trans _\n  refine' Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero hm f_meas hp_ne_zero hp_ne_top _ _\n  \u00b7 intro s hs h\u03bcs\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas := ae_restrict_of_ae hf_f_meas\n    rw [integrable_on, integrable_congr hfg_restrict.symm]\n    exact hf_int_finite s hs h\u03bcs\n  \u00b7 intro s hs h\u03bcs\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas := ae_restrict_of_ae hf_f_meas\n    rw [integral_congr_ae hfg_restrict.symm]\n    exact hf_zero s hs h\u03bcs\n#align measure_theory.Lp.ae_eq_zero_of_forall_set_integral_eq_zero' MeasureTheory.lp.ae_eq_zero_of_forall_set_integral_eq_zero'\n\n/-- **Uniqueness of the conditional expectation** -/\ntheorem lp.ae_eq_of_forall_set_integral_eq' (hm : m \u2264 m0) (f g : lp E' p \u03bc) (hp_ne_zero : p \u2260 0)\n    (hp_ne_top : p \u2260 \u221e) (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 IntegrableOn f s \u03bc)\n    (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 IntegrableOn g s \u03bc)\n    (hfg : \u2200 s : Set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 (\u222b x in s, f x \u2202\u03bc) = \u222b x in s, g x \u2202\u03bc)\n    (hf_meas : AeStronglyMeasurable' m f \u03bc) (hg_meas : AeStronglyMeasurable' m g \u03bc) : f =\u1d50[\u03bc] g :=\n  by\n  suffices h_sub : \u21d1(f - g) =\u1d50[\u03bc] 0\n  \u00b7 rw [\u2190 sub_ae_eq_zero]\n    exact (Lp.coe_fn_sub f g).symm.trans h_sub\n  have hfg' : \u2200 s : Set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 (\u222b x in s, (f - g) x \u2202\u03bc) = 0 :=\n    by\n    intro s hs h\u03bcs\n    rw [integral_congr_ae (ae_restrict_of_ae (Lp.coe_fn_sub f g))]\n    rw [integral_sub' (hf_int_finite s hs h\u03bcs) (hg_int_finite s hs h\u03bcs)]\n    exact sub_eq_zero.mpr (hfg s hs h\u03bcs)\n  have hfg_int : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on (\u21d1(f - g)) s \u03bc :=\n    by\n    intro s hs h\u03bcs\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub f g))]\n    exact (hf_int_finite s hs h\u03bcs).sub (hg_int_finite s hs h\u03bcs)\n  have hfg_meas : ae_strongly_measurable' m (\u21d1(f - g)) \u03bc :=\n    ae_strongly_measurable'.congr (hf_meas.sub hg_meas) (Lp.coe_fn_sub f g).symm\n  exact\n    Lp.ae_eq_zero_of_forall_set_integral_eq_zero' \ud835\udd5c hm (f - g) hp_ne_zero hp_ne_top hfg_int hfg'\n      hfg_meas\n#align measure_theory.Lp.ae_eq_of_forall_set_integral_eq' MeasureTheory.lp.ae_eq_of_forall_set_integral_eq'\n\nvariable {\ud835\udd5c}\n\nomit \ud835\udd5c\n\ntheorem ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)]\n    {f g : \u03b1 \u2192 F'} (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 IntegrableOn f s \u03bc)\n    (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 IntegrableOn g s \u03bc)\n    (hfg_eq : \u2200 s : Set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 (\u222b x in s, f x \u2202\u03bc) = \u222b x in s, g x \u2202\u03bc)\n    (hfm : AeStronglyMeasurable' m f \u03bc) (hgm : AeStronglyMeasurable' m g \u03bc) : f =\u1d50[\u03bc] g :=\n  by\n  rw [\u2190 ae_eq_trim_iff_of_ae_strongly_measurable' hm hfm hgm]\n  have hf_mk_int_finite :\n    \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192 @integrable_on _ _ m _ (hfm.mk f) s (\u03bc.trim hm) :=\n    by\n    intro s hs h\u03bcs\n    rw [trim_measurable_set_eq hm hs] at h\u03bcs\n    rw [integrable_on, restrict_trim hm _ hs]\n    refine' integrable.trim hm _ hfm.strongly_measurable_mk\n    exact integrable.congr (hf_int_finite s hs h\u03bcs) (ae_restrict_of_ae hfm.ae_eq_mk)\n  have hg_mk_int_finite :\n    \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192 @integrable_on _ _ m _ (hgm.mk g) s (\u03bc.trim hm) :=\n    by\n    intro s hs h\u03bcs\n    rw [trim_measurable_set_eq hm hs] at h\u03bcs\n    rw [integrable_on, restrict_trim hm _ hs]\n    refine' integrable.trim hm _ hgm.strongly_measurable_mk\n    exact integrable.congr (hg_int_finite s hs h\u03bcs) (ae_restrict_of_ae hgm.ae_eq_mk)\n  have hfg_mk_eq :\n    \u2200 s : Set \u03b1,\n      measurable_set[m] s \u2192\n        \u03bc.trim hm s < \u221e \u2192 (\u222b x in s, hfm.mk f x \u2202\u03bc.trim hm) = \u222b x in s, hgm.mk g x \u2202\u03bc.trim hm :=\n    by\n    intro s hs h\u03bcs\n    rw [trim_measurable_set_eq hm hs] at h\u03bcs\n    rw [restrict_trim hm _ hs, \u2190 integral_trim hm hfm.strongly_measurable_mk, \u2190\n      integral_trim hm hgm.strongly_measurable_mk,\n      integral_congr_ae (ae_restrict_of_ae hfm.ae_eq_mk.symm),\n      integral_congr_ae (ae_restrict_of_ae hgm.ae_eq_mk.symm)]\n    exact hfg_eq s hs h\u03bcs\n  exact ae_eq_of_forall_set_integral_eq_of_sigma_finite hf_mk_int_finite hg_mk_int_finite hfg_mk_eq\n#align measure_theory.ae_eq_of_forall_set_integral_eq_of_sigma_finite' MeasureTheory.ae_eq_of_forall_set_integral_eq_of_sigma_finite'\n\nend UniquenessOfConditionalExpectation\n\nsection IntegralNormLe\n\nvariable {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {s : Set \u03b1}\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b x in s, \u2016g x\u2016 \u2202\u03bc \u2264 \u222b x in s, \u2016f x\u2016 \u2202\u03bc` on all `m`-measurable sets with finite measure. -/\ntheorem integral_norm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n    (hf : StronglyMeasurable f) (hfi : IntegrableOn f s \u03bc) (hg : strongly_measurable[m] g)\n    (hgi : IntegrableOn g s \u03bc)\n    (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 (\u222b x in t, g x \u2202\u03bc) = \u222b x in t, f x \u2202\u03bc)\n    (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) : (\u222b x in s, \u2016g x\u2016 \u2202\u03bc) \u2264 \u222b x in s, \u2016f x\u2016 \u2202\u03bc :=\n  by\n  rw [integral_norm_eq_pos_sub_neg hgi, integral_norm_eq_pos_sub_neg hfi]\n  have h_meas_nonneg_g : measurable_set[m] { x | 0 \u2264 g x } :=\n    (@strongly_measurable_const _ _ m _ _).measurableSet_le hg\n  have h_meas_nonneg_f : MeasurableSet { x | 0 \u2264 f x } :=\n    strongly_measurable_const.measurable_set_le hf\n  have h_meas_nonpos_g : measurable_set[m] { x | g x \u2264 0 } :=\n    hg.measurable_set_le (@strongly_measurable_const _ _ m _ _)\n  have h_meas_nonpos_f : MeasurableSet { x | f x \u2264 0 } :=\n    hf.measurable_set_le strongly_measurable_const\n  refine' sub_le_sub _ _\n  \u00b7 rw [measure.restrict_restrict (hm _ h_meas_nonneg_g), measure.restrict_restrict h_meas_nonneg_f,\n      hgf _ (@MeasurableSet.inter \u03b1 m _ _ h_meas_nonneg_g hs)\n        ((measure_mono (Set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonneg_g), \u2190\n      measure.restrict_restrict h_meas_nonneg_f]\n    exact set_integral_le_nonneg (hm _ h_meas_nonneg_g) hf hfi\n  \u00b7 rw [measure.restrict_restrict (hm _ h_meas_nonpos_g), measure.restrict_restrict h_meas_nonpos_f,\n      hgf _ (@MeasurableSet.inter \u03b1 m _ _ h_meas_nonpos_g hs)\n        ((measure_mono (Set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonpos_g), \u2190\n      measure.restrict_restrict h_meas_nonpos_f]\n    exact set_integral_nonpos_le (hm _ h_meas_nonpos_g) hf hfi\n#align measure_theory.integral_norm_le_of_forall_fin_meas_integral_eq MeasureTheory.integral_norm_le_of_forall_fin_meas_integral_eq\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b\u207b x in s, \u2016g x\u2016\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2016f x\u2016\u208a \u2202\u03bc` on all `m`-measurable sets with finite\nmeasure. -/\ntheorem lintegral_nnnorm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n    (hf : StronglyMeasurable f) (hfi : IntegrableOn f s \u03bc) (hg : strongly_measurable[m] g)\n    (hgi : IntegrableOn g s \u03bc)\n    (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 (\u222b x in t, g x \u2202\u03bc) = \u222b x in t, f x \u2202\u03bc)\n    (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) : (\u222b\u207b x in s, \u2016g x\u2016\u208a \u2202\u03bc) \u2264 \u222b\u207b x in s, \u2016f x\u2016\u208a \u2202\u03bc :=\n  by\n  rw [\u2190 of_real_integral_norm_eq_lintegral_nnnorm hfi, \u2190\n    of_real_integral_norm_eq_lintegral_nnnorm hgi, ENNReal.ofReal_le_ofReal_iff]\n  \u00b7 exact integral_norm_le_of_forall_fin_meas_integral_eq hm hf hfi hg hgi hgf hs h\u03bcs\n  \u00b7 exact integral_nonneg fun x => norm_nonneg _\n#align measure_theory.lintegral_nnnorm_le_of_forall_fin_meas_integral_eq MeasureTheory.lintegral_nnnorm_le_of_forall_fin_meas_integral_eq\n\nend IntegralNormLe\n\n/-! ## Conditional expectation in L2\n\nWe define a conditional expectation in `L2`: it is the orthogonal projection on the subspace\n`Lp_meas`. -/\n\n\nsection CondexpL2\n\nvariable [CompleteSpace E] {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {s t : Set \u03b1}\n\n-- mathport name: \u00abexpr\u27ea , \u27eb\u00bb\nlocal notation \"\u27ea\" x \", \" y \"\u27eb\" => @inner \ud835\udd5c E _ x y\n\n-- mathport name: \u00abexpr\u27ea , \u27eb\u2082\u00bb\nlocal notation \"\u27ea\" x \", \" y \"\u27eb\u2082\" => @inner \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ x y\n\nvariable (\ud835\udd5c)\n\n/-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/\ndef condexpL2 (hm : m \u2264 m0) : (\u03b1 \u2192\u2082[\u03bc] E) \u2192L[\ud835\udd5c] lpMeas E \ud835\udd5c m 2 \u03bc :=\n  @orthogonalProjection \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ _ _ (lpMeas E \ud835\udd5c m 2 \u03bc)\n    haveI : Fact (m \u2264 m0) := \u27e8hm\u27e9\n    inferInstance\n#align measure_theory.condexp_L2 MeasureTheory.condexpL2\n\nvariable {\ud835\udd5c}\n\ntheorem aeStronglyMeasurable'CondexpL2 (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n    AeStronglyMeasurable' m (condexpL2 \ud835\udd5c hm f) \u03bc :=\n  lpMeas.aeStronglyMeasurable' _\n#align measure_theory.ae_strongly_measurable'_condexp_L2 MeasureTheory.aeStronglyMeasurable'CondexpL2\n\ntheorem integrableOnCondexpL2OfMeasureNeTop (hm : m \u2264 m0) (h\u03bcs : \u03bc s \u2260 \u221e) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n    IntegrableOn (condexpL2 \ud835\udd5c hm f) s \u03bc :=\n  integrableOnLpOfMeasureNeTop (condexpL2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E) fact_one_le_two_ennreal.elim h\u03bcs\n#align measure_theory.integrable_on_condexp_L2_of_measure_ne_top MeasureTheory.integrableOnCondexpL2OfMeasureNeTop\n\ntheorem integrableCondexpL2OfIsFiniteMeasure (hm : m \u2264 m0) [IsFiniteMeasure \u03bc] {f : \u03b1 \u2192\u2082[\u03bc] E} :\n    Integrable (condexpL2 \ud835\udd5c hm f) \u03bc :=\n  integrableOn_univ.mp <| integrableOnCondexpL2OfMeasureNeTop hm (measure_ne_top _ _) f\n#align measure_theory.integrable_condexp_L2_of_is_finite_measure MeasureTheory.integrableCondexpL2OfIsFiniteMeasure\n\ntheorem norm_condexpL2_le_one (hm : m \u2264 m0) : \u2016@condexpL2 \u03b1 E \ud835\udd5c _ _ _ _ _ _ \u03bc hm\u2016 \u2264 1 :=\n  haveI : Fact (m \u2264 m0) := \u27e8hm\u27e9\n  orthogonalProjection_norm_le _\n#align measure_theory.norm_condexp_L2_le_one MeasureTheory.norm_condexpL2_le_one\n\ntheorem norm_condexpL2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) : \u2016condexpL2 \ud835\udd5c hm f\u2016 \u2264 \u2016f\u2016 :=\n  ((@condexpL2 _ E \ud835\udd5c _ _ _ _ _ _ \u03bc hm).le_opNorm f).trans\n    (mul_le_of_le_one_left (norm_nonneg _) (norm_condexpL2_le_one hm))\n#align measure_theory.norm_condexp_L2_le MeasureTheory.norm_condexpL2_le\n\ntheorem snorm_condexpL2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n    snorm (condexpL2 \ud835\udd5c hm f) 2 \u03bc \u2264 snorm f 2 \u03bc :=\n  by\n  rw [Lp_meas_coe, \u2190 ENNReal.toReal_le_toReal (Lp.snorm_ne_top _) (Lp.snorm_ne_top _), \u2190\n    Lp.norm_def, \u2190 Lp.norm_def, Submodule.norm_coe]\n  exact norm_condexp_L2_le hm f\n#align measure_theory.snorm_condexp_L2_le MeasureTheory.snorm_condexpL2_le\n\ntheorem norm_condexpL2_coe_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n    \u2016(condexpL2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E)\u2016 \u2264 \u2016f\u2016 :=\n  by\n  rw [Lp.norm_def, Lp.norm_def, \u2190 Lp_meas_coe]\n  refine' (ENNReal.toReal_le_toReal _ (Lp.snorm_ne_top _)).mpr (snorm_condexp_L2_le hm f)\n  exact Lp.snorm_ne_top _\n#align measure_theory.norm_condexp_L2_coe_le MeasureTheory.norm_condexpL2_coe_le\n\ntheorem inner_condexpL2_left_eq_right (hm : m \u2264 m0) {f g : \u03b1 \u2192\u2082[\u03bc] E} :\n    \u27ea(condexpL2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, (condexpL2 \ud835\udd5c hm g : \u03b1 \u2192\u2082[\u03bc] E)\u27eb\u2082 :=\n  haveI : Fact (m \u2264 m0) := \u27e8hm\u27e9\n  inner_orthogonalProjection_left_eq_right _ f g\n#align measure_theory.inner_condexp_L2_left_eq_right MeasureTheory.inner_condexpL2_left_eq_right\n\ntheorem condexpL2_indicator_of_measurable (hm : m \u2264 m0) (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (c : E) :\n    (condexpL2 \ud835\udd5c hm (indicatorConstLp 2 (hm s hs) h\u03bcs c) : \u03b1 \u2192\u2082[\u03bc] E) =\n      indicatorConstLp 2 (hm s hs) h\u03bcs c :=\n  by\n  rw [condexp_L2]\n  haveI : Fact (m \u2264 m0) := \u27e8hm\u27e9\n  have h_mem : indicator_const_Lp 2 (hm s hs) h\u03bcs c \u2208 Lp_meas E \ud835\udd5c m 2 \u03bc :=\n    mem_Lp_meas_indicator_const_Lp hm hs h\u03bcs\n  let ind := (\u27e8indicator_const_Lp 2 (hm s hs) h\u03bcs c, h_mem\u27e9 : Lp_meas E \ud835\udd5c m 2 \u03bc)\n  have h_coe_ind : (ind : \u03b1 \u2192\u2082[\u03bc] E) = indicator_const_Lp 2 (hm s hs) h\u03bcs c := by rfl\n  have h_orth_mem := orthogonalProjection_mem_subspace_eq_self ind\n  rw [\u2190 h_coe_ind, h_orth_mem]\n#align measure_theory.condexp_L2_indicator_of_measurable MeasureTheory.condexpL2_indicator_of_measurable\n\ntheorem inner_condexpL2_eq_inner_fun (hm : m \u2264 m0) (f g : \u03b1 \u2192\u2082[\u03bc] E)\n    (hg : AeStronglyMeasurable' m g \u03bc) : \u27ea(condexpL2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, g\u27eb\u2082 :=\n  by\n  symm\n  rw [\u2190 sub_eq_zero, \u2190 inner_sub_left, condexp_L2]\n  simp only [mem_Lp_meas_iff_ae_strongly_measurable'.mpr hg, orthogonalProjection_inner_eq_zero]\n#align measure_theory.inner_condexp_L2_eq_inner_fun MeasureTheory.inner_condexpL2_eq_inner_fun\n\nsection Real\n\nvariable {hm : m \u2264 m0}\n\ntheorem integral_condexpL2_eq_of_fin_meas_real (f : lp \ud835\udd5c 2 \u03bc) (hs : measurable_set[m] s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) : (\u222b x in s, condexpL2 \ud835\udd5c hm f x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc :=\n  by\n  rw [\u2190 L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs]\n  have h_eq_inner :\n    (\u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc) =\n      inner (indicator_const_Lp 2 (hm s hs) h\u03bcs (1 : \ud835\udd5c)) (condexp_L2 \ud835\udd5c hm f) :=\n    by\n    rw [L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs]\n    congr\n  rw [h_eq_inner, \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable hm hs h\u03bcs]\n#align measure_theory.integral_condexp_L2_eq_of_fin_meas_real MeasureTheory.integral_condexpL2_eq_of_fin_meas_real\n\ntheorem lintegral_nnnorm_condexpL2_le (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (f : lp \u211d 2 \u03bc) :\n    (\u222b\u207b x in s, \u2016condexpL2 \u211d hm f x\u2016\u208a \u2202\u03bc) \u2264 \u222b\u207b x in s, \u2016f x\u2016\u208a \u2202\u03bc :=\n  by\n  let h_meas := Lp_meas.ae_strongly_measurable' (condexp_L2 \u211d hm f)\n  let g := h_meas.some\n  have hg_meas : strongly_measurable[m] g := h_meas.some_spec.1\n  have hg_eq : g =\u1d50[\u03bc] condexp_L2 \u211d hm f := h_meas.some_spec.2.symm\n  have hg_eq_restrict : g =\u1d50[\u03bc.restrict s] condexp_L2 \u211d hm f := ae_restrict_of_ae hg_eq\n  have hg_nnnorm_eq :\n    (fun x => (\u2016g x\u2016\u208a : \u211d\u22650\u221e)) =\u1d50[\u03bc.restrict s] fun x => (\u2016condexp_L2 \u211d hm f x\u2016\u208a : \u211d\u22650\u221e) :=\n    by\n    refine' hg_eq_restrict.mono fun x hx => _\n    dsimp only\n    rw [hx]\n  rw [lintegral_congr_ae hg_nnnorm_eq.symm]\n  refine'\n    lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm (Lp.strongly_measurable f) _ _ _ _ hs h\u03bcs\n  \u00b7 exact integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs\n  \u00b7 exact hg_meas\n  \u00b7 rw [integrable_on, integrable_congr hg_eq_restrict]\n    exact integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs f\n  \u00b7 intro t ht h\u03bct\n    rw [\u2190 integral_condexp_L2_eq_of_fin_meas_real f ht h\u03bct.ne]\n    exact set_integral_congr_ae (hm t ht) (hg_eq.mono fun x hx _ => hx)\n#align measure_theory.lintegral_nnnorm_condexp_L2_le MeasureTheory.lintegral_nnnorm_condexpL2_le\n\ntheorem condexpL2_ae_eq_zero_of_ae_eq_zero (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) {f : lp \u211d 2 \u03bc}\n    (hf : f =\u1d50[\u03bc.restrict s] 0) : condexpL2 \u211d hm f =\u1d50[\u03bc.restrict s] 0 :=\n  by\n  suffices h_nnnorm_eq_zero : (\u222b\u207b x in s, \u2016condexp_L2 \u211d hm f x\u2016\u208a \u2202\u03bc) = 0\n  \u00b7 rw [lintegral_eq_zero_iff] at h_nnnorm_eq_zero\n    refine' h_nnnorm_eq_zero.mono fun x hx => _\n    dsimp only at hx\n    rw [Pi.zero_apply] at hx\u22a2\n    \u00b7 rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] at hx\n    \u00b7 refine' Measurable.coe_nNReal_eNNReal (Measurable.nnnorm _)\n      rw [Lp_meas_coe]\n      exact (Lp.strongly_measurable _).Measurable\n  refine' le_antisymm _ (zero_le _)\n  refine' (lintegral_nnnorm_condexp_L2_le hs h\u03bcs f).trans (le_of_eq _)\n  rw [lintegral_eq_zero_iff]\n  \u00b7 refine' hf.mono fun x hx => _\n    dsimp only\n    rw [hx]\n    simp\n  \u00b7 exact (Lp.strongly_measurable _).ennnorm\n#align measure_theory.condexp_L2_ae_eq_zero_of_ae_eq_zero MeasureTheory.condexpL2_ae_eq_zero_of_ae_eq_zero\n\ntheorem lintegral_nnnorm_condexpL2_indicator_le_real (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n    (\u222b\u207b a in t, \u2016condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) a\u2016\u208a \u2202\u03bc) \u2264 \u03bc (s \u2229 t) :=\n  by\n  refine' (lintegral_nnnorm_condexp_L2_le ht h\u03bct _).trans (le_of_eq _)\n  have h_eq :\n    (\u222b\u207b x in t, \u2016(indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) x\u2016\u208a \u2202\u03bc) =\n      \u222b\u207b x in t, s.indicator (fun x => (1 : \u211d\u22650\u221e)) x \u2202\u03bc :=\n    by\n    refine' lintegral_congr_ae (ae_restrict_of_ae _)\n    refine' (@indicator_const_Lp_coe_fn _ _ _ 2 _ _ _ hs h\u03bcs (1 : \u211d)).mono fun x hx => _\n    rw [hx]\n    classical\n      simp_rw [Set.indicator_apply]\n      split_ifs <;> simp\n  rw [h_eq, lintegral_indicator _ hs, lintegral_const, measure.restrict_restrict hs]\n  simp only [one_mul, Set.univ_inter, MeasurableSet.univ, measure.restrict_apply]\n#align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le_real MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le_real\n\nend Real\n\n/-- `condexp_L2` commutes with taking inner products with constants. See the lemma\n`condexp_L2_comp_continuous_linear_map` for a more general result about commuting with continuous\nlinear maps. -/\ntheorem condexpL2_constInner (hm : m \u2264 m0) (f : lp E 2 \u03bc) (c : E) :\n    condexpL2 \ud835\udd5c hm (((lp.mem\u2112p f).constInner c).toLp fun a => \u27eac, f a\u27eb) =\u1d50[\u03bc] fun a =>\n      \u27eac, condexpL2 \ud835\udd5c hm f a\u27eb :=\n  by\n  rw [Lp_meas_coe]\n  have h_mem_Lp : mem_\u2112p (fun a => \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb) 2 \u03bc :=\n    by\n    refine' mem_\u2112p.const_inner _ _\n    rw [Lp_meas_coe]\n    exact Lp.mem_\u2112p _\n  have h_eq : h_mem_Lp.to_Lp _ =\u1d50[\u03bc] fun a => \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb := h_mem_Lp.coe_fn_to_Lp\n  refine' eventually_eq.trans _ h_eq\n  refine'\n    Lp.ae_eq_of_forall_set_integral_eq' \ud835\udd5c hm _ _ two_ne_zero ENNReal.coe_ne_top\n      (fun s hs h\u03bcs => integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.Ne _) _ _ _ _\n  \u00b7 intro s hs h\u03bcs\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae h_eq)]\n    exact (integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _).constInner _\n  \u00b7 intro s hs h\u03bcs\n    rw [\u2190 Lp_meas_coe, integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs.ne,\n      integral_congr_ae (ae_restrict_of_ae h_eq), Lp_meas_coe, \u2190\n      L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c (\u2191(condexp_L2 \ud835\udd5c hm f)) (hm s hs) c h\u03bcs.ne,\n      \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable,\n      L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c f (hm s hs) c h\u03bcs.ne,\n      set_integral_congr_ae (hm s hs)\n        ((mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).constInner c)).mono fun x hx hxs => hx)]\n  \u00b7 rw [\u2190 Lp_meas_coe]\n    exact Lp_meas.ae_strongly_measurable' _\n  \u00b7 refine' ae_strongly_measurable'.congr _ h_eq.symm\n    exact (Lp_meas.ae_strongly_measurable' _).constInner _\n#align measure_theory.condexp_L2_const_inner MeasureTheory.condexpL2_constInner\n\n/-- `condexp_L2` verifies the equality of integrals defining the conditional expectation. -/\ntheorem integral_condexpL2_eq (hm : m \u2264 m0) (f : lp E' 2 \u03bc) (hs : measurable_set[m] s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) : (\u222b x in s, condexpL2 \ud835\udd5c hm f x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc :=\n  by\n  rw [\u2190 sub_eq_zero, Lp_meas_coe, \u2190\n    integral_sub' (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)\n      (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)]\n  refine' integral_eq_zero_of_forall_integral_inner_eq_zero \ud835\udd5c _ _ _\n  \u00b7 rw [integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub (\u2191(condexp_L2 \ud835\udd5c hm f)) f).symm)]\n    exact integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs\n  intro c\n  simp_rw [Pi.sub_apply, inner_sub_right]\n  rw [integral_sub\n      ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).constInner c)\n      ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).constInner c)]\n  have h_ae_eq_f := mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).constInner c)\n  rw [\u2190 Lp_meas_coe, sub_eq_zero, \u2190\n    set_integral_congr_ae (hm s hs) ((condexp_L2_const_inner hm f c).mono fun x hx _ => hx), \u2190\n    set_integral_congr_ae (hm s hs) (h_ae_eq_f.mono fun x hx _ => hx)]\n  exact integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs\n#align measure_theory.integral_condexp_L2_eq MeasureTheory.integral_condexpL2_eq\n\nvariable {E'' \ud835\udd5c' : Type _} [IsROrC \ud835\udd5c'] [NormedAddCommGroup E''] [InnerProductSpace \ud835\udd5c' E'']\n  [CompleteSpace E''] [NormedSpace \u211d E'']\n\nvariable (\ud835\udd5c \ud835\udd5c')\n\ntheorem condexpL2_comp_continuousLinearMap (hm : m \u2264 m0) (T : E' \u2192L[\u211d] E'') (f : \u03b1 \u2192\u2082[\u03bc] E') :\n    (condexpL2 \ud835\udd5c' hm (T.compLp f) : \u03b1 \u2192\u2082[\u03bc] E'') =\u1d50[\u03bc] T.compLp (condexpL2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E') :=\n  by\n  refine'\n    Lp.ae_eq_of_forall_set_integral_eq' \ud835\udd5c' hm _ _ two_ne_zero ENNReal.coe_ne_top\n      (fun s hs h\u03bcs => integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.Ne _)\n      (fun s hs h\u03bcs => integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.Ne) _ _\n      _\n  \u00b7 intro s hs h\u03bcs\n    rw [T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.ne),\n      \u2190 Lp_meas_coe, \u2190 Lp_meas_coe, integral_condexp_L2_eq hm f hs h\u03bcs.ne,\n      integral_condexp_L2_eq hm (T.comp_Lp f) hs h\u03bcs.ne, T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs.ne)]\n  \u00b7 rw [\u2190 Lp_meas_coe]\n    exact Lp_meas.ae_strongly_measurable' _\n  \u00b7 have h_coe := T.coe_fn_comp_Lp (condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E')\n    rw [\u2190 eventually_eq] at h_coe\n    refine' ae_strongly_measurable'.congr _ h_coe.symm\n    exact (Lp_meas.ae_strongly_measurable' (condexp_L2 \ud835\udd5c hm f)).continuous_comp T.continuous\n#align measure_theory.condexp_L2_comp_continuous_linear_map MeasureTheory.condexpL2_comp_continuousLinearMap\n\nvariable {\ud835\udd5c \ud835\udd5c'}\n\nsection CondexpL2Indicator\n\nvariable (\ud835\udd5c)\n\ntheorem condexpL2_indicator_ae_eq_smul (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (x : E') :\n    condexpL2 \ud835\udd5c hm (indicatorConstLp 2 hs h\u03bcs x) =\u1d50[\u03bc] fun a =>\n      condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) a \u2022 x :=\n  by\n  rw [indicator_const_Lp_eq_to_span_singleton_comp_Lp hs h\u03bcs x]\n  have h_comp :=\n    condexp_L2_comp_continuous_linear_map \u211d \ud835\udd5c hm (to_span_singleton \u211d x)\n      (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))\n  rw [\u2190 Lp_meas_coe] at h_comp\n  refine' h_comp.trans _\n  exact (to_span_singleton \u211d x).coeFn_compLp _\n#align measure_theory.condexp_L2_indicator_ae_eq_smul MeasureTheory.condexpL2_indicator_ae_eq_smul\n\ntheorem condexpL2_indicator_eq_toSpanSingleton_comp (hm : m \u2264 m0) (hs : MeasurableSet s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') :\n    (condexpL2 \ud835\udd5c hm (indicatorConstLp 2 hs h\u03bcs x) : \u03b1 \u2192\u2082[\u03bc] E') =\n      (toSpanSingleton \u211d x).compLp (condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d))) :=\n  by\n  ext1\n  rw [\u2190 Lp_meas_coe]\n  refine' (condexp_L2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).trans _\n  have h_comp :=\n    (to_span_singleton \u211d x).coeFn_compLp\n      (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) : \u03b1 \u2192\u2082[\u03bc] \u211d)\n  rw [\u2190 eventually_eq] at h_comp\n  refine' eventually_eq.trans _ h_comp.symm\n  refine' eventually_of_forall fun y => _\n  rfl\n#align measure_theory.condexp_L2_indicator_eq_to_span_singleton_comp MeasureTheory.condexpL2_indicator_eq_toSpanSingleton_comp\n\nvariable {\ud835\udd5c}\n\ntheorem set_lintegral_nnnorm_condexpL2_indicator_le (hm : m \u2264 m0) (hs : MeasurableSet s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') {t : Set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n    (\u222b\u207b a in t, \u2016condexpL2 \ud835\udd5c hm (indicatorConstLp 2 hs h\u03bcs x) a\u2016\u208a \u2202\u03bc) \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :=\n  calc\n    (\u222b\u207b a in t, \u2016condexpL2 \ud835\udd5c hm (indicatorConstLp 2 hs h\u03bcs x) a\u2016\u208a \u2202\u03bc) =\n        \u222b\u207b a in t, \u2016condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) a \u2022 x\u2016\u208a \u2202\u03bc :=\n      set_lintegral_congr_fun (hm t ht)\n        ((condexpL2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).mono fun a ha hat => by rw [ha])\n    _ = (\u222b\u207b a in t, \u2016condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) a\u2016\u208a \u2202\u03bc) * \u2016x\u2016\u208a :=\n      by\n      simp_rw [nnnorm_smul, ENNReal.coe_mul]\n      rw [lintegral_mul_const, Lp_meas_coe]\n      exact (Lp.strongly_measurable _).ennnorm\n    _ \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :=\n      mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs h\u03bcs ht h\u03bct) _\n    \n#align measure_theory.set_lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.set_lintegral_nnnorm_condexpL2_indicator_le\n\ntheorem lintegral_nnnorm_condexpL2_indicator_le (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (x : E') [SigmaFinite (\u03bc.trim hm)] :\n    (\u222b\u207b a, \u2016condexpL2 \ud835\udd5c hm (indicatorConstLp 2 hs h\u03bcs x) a\u2016\u208a \u2202\u03bc) \u2264 \u03bc s * \u2016x\u2016\u208a :=\n  by\n  refine' lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a) _ fun t ht h\u03bct => _\n  \u00b7 rw [Lp_meas_coe]\n    exact (Lp.ae_strongly_measurable _).ennnorm\n  refine' (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _\n  exact mul_le_mul_right' (measure_mono (Set.inter_subset_left _ _)) _\n#align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\ntheorem integrableCondexpL2Indicator (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)] (hs : MeasurableSet s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') : Integrable (condexpL2 \ud835\udd5c hm (indicatorConstLp 2 hs h\u03bcs x)) \u03bc :=\n  by\n  refine'\n    integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a) (ENNReal.mul_lt_top h\u03bcs ENNReal.coe_ne_top) _\n      _\n  \u00b7 rw [Lp_meas_coe]\n    exact Lp.ae_strongly_measurable _\n  \u00b7 refine' fun t ht h\u03bct =>\n      (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _\n    exact mul_le_mul_right' (measure_mono (Set.inter_subset_left _ _)) _\n#align measure_theory.integrable_condexp_L2_indicator MeasureTheory.integrableCondexpL2Indicator\n\nend CondexpL2Indicator\n\nsection CondexpIndSmul\n\nvariable [NormedSpace \u211d G] {hm : m \u2264 m0}\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/\ndef condexpIndSmul (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : lp G 2 \u03bc :=\n  (toSpanSingleton \u211d x).compLpL 2 \u03bc (condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)))\n#align measure_theory.condexp_ind_smul MeasureTheory.condexpIndSmul\n\ntheorem aeStronglyMeasurable'CondexpIndSmul (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (x : G) : AeStronglyMeasurable' m (condexpIndSmul hm hs h\u03bcs x) \u03bc :=\n  by\n  have h : ae_strongly_measurable' m (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) \u03bc :=\n    ae_strongly_measurable'_condexp_L2 _ _\n  rw [condexp_ind_smul]\n  suffices\n    ae_strongly_measurable' m\n      (to_span_singleton \u211d x \u2218 condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) \u03bc\n    by\n    refine' ae_strongly_measurable'.congr this _\n    refine' eventually_eq.trans _ (coe_fn_comp_LpL _ _).symm\n    rw [Lp_meas_coe]\n  exact ae_strongly_measurable'.continuous_comp (to_span_singleton \u211d x).Continuous h\n#align measure_theory.ae_strongly_measurable'_condexp_ind_smul MeasureTheory.aeStronglyMeasurable'CondexpIndSmul\n\ntheorem condexpIndSmul_add (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n    condexpIndSmul hm hs h\u03bcs (x + y) = condexpIndSmul hm hs h\u03bcs x + condexpIndSmul hm hs h\u03bcs y :=\n  by\n  simp_rw [condexp_ind_smul]\n  rw [to_span_singleton_add, add_comp_LpL, add_apply]\n#align measure_theory.condexp_ind_smul_add MeasureTheory.condexpIndSmul_add\n\ntheorem condexpIndSmul_smul (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n    condexpIndSmul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexpIndSmul hm hs h\u03bcs x :=\n  by\n  simp_rw [condexp_ind_smul]\n  rw [to_span_singleton_smul, smul_comp_LpL, smul_apply]\n#align measure_theory.condexp_ind_smul_smul MeasureTheory.condexpIndSmul_smul\n\ntheorem condexpIndSmul_smul' [NormedSpace \u211d F] [SMulCommClass \u211d \ud835\udd5c F] (hs : MeasurableSet s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n    condexpIndSmul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexpIndSmul hm hs h\u03bcs x := by\n  rw [condexp_ind_smul, condexp_ind_smul, to_span_singleton_smul',\n    (to_span_singleton \u211d x).smul_compLpL_apply c\n      \u2191(condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))]\n#align measure_theory.condexp_ind_smul_smul' MeasureTheory.condexpIndSmul_smul'\n\ntheorem condexpIndSmul_ae_eq_smul (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n    condexpIndSmul hm hs h\u03bcs x =\u1d50[\u03bc] fun a =>\n      condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) a \u2022 x :=\n  (toSpanSingleton \u211d x).coeFn_compLpL _\n#align measure_theory.condexp_ind_smul_ae_eq_smul MeasureTheory.condexpIndSmul_ae_eq_smul\n\ntheorem set_lintegral_nnnorm_condexpIndSmul_le (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (x : G) {t : Set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n    (\u222b\u207b a in t, \u2016condexpIndSmul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc) \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :=\n  calc\n    (\u222b\u207b a in t, \u2016condexpIndSmul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc) =\n        \u222b\u207b a in t, \u2016condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) a \u2022 x\u2016\u208a \u2202\u03bc :=\n      set_lintegral_congr_fun (hm t ht)\n        ((condexpIndSmul_ae_eq_smul hm hs h\u03bcs x).mono fun a ha hat => by rw [ha])\n    _ = (\u222b\u207b a in t, \u2016condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) a\u2016\u208a \u2202\u03bc) * \u2016x\u2016\u208a :=\n      by\n      simp_rw [nnnorm_smul, ENNReal.coe_mul]\n      rw [lintegral_mul_const, Lp_meas_coe]\n      exact (Lp.strongly_measurable _).ennnorm\n    _ \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :=\n      mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs h\u03bcs ht h\u03bct) _\n    \n#align measure_theory.set_lintegral_nnnorm_condexp_ind_smul_le MeasureTheory.set_lintegral_nnnorm_condexpIndSmul_le\n\ntheorem lintegral_nnnorm_condexpIndSmul_le (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (x : G) [SigmaFinite (\u03bc.trim hm)] : (\u222b\u207b a, \u2016condexpIndSmul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc) \u2264 \u03bc s * \u2016x\u2016\u208a :=\n  by\n  refine' lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a) _ fun t ht h\u03bct => _\n  \u00b7 exact (Lp.ae_strongly_measurable _).ennnorm\n  refine' (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _\n  exact mul_le_mul_right' (measure_mono (Set.inter_subset_left _ _)) _\n#align measure_theory.lintegral_nnnorm_condexp_ind_smul_le MeasureTheory.lintegral_nnnorm_condexpIndSmul_le\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\ntheorem integrableCondexpIndSmul (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)] (hs : MeasurableSet s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : Integrable (condexpIndSmul hm hs h\u03bcs x) \u03bc :=\n  by\n  refine'\n    integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a) (ENNReal.mul_lt_top h\u03bcs ENNReal.coe_ne_top) _\n      _\n  \u00b7 exact Lp.ae_strongly_measurable _\n  \u00b7 refine' fun t ht h\u03bct => (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _\n    exact mul_le_mul_right' (measure_mono (Set.inter_subset_left _ _)) _\n#align measure_theory.integrable_condexp_ind_smul MeasureTheory.integrableCondexpIndSmul\n\ntheorem condexpIndSmul_empty {x : G} :\n    condexpIndSmul hm MeasurableSet.empty ((@measure_empty _ _ \u03bc).le.trans_lt ENNReal.coe_lt_top).Ne\n        x =\n      0 :=\n  by\n  rw [condexp_ind_smul, indicator_const_empty]\n  simp only [coeFn_coeBase, Submodule.coe_zero, ContinuousLinearMap.map_zero]\n#align measure_theory.condexp_ind_smul_empty MeasureTheory.condexpIndSmul_empty\n\ntheorem set_integral_condexpL2_indicator (hs : measurable_set[m] s) (ht : MeasurableSet t)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) :\n    (\u222b x in s, (condexpL2 \u211d hm (indicatorConstLp 2 ht h\u03bct (1 : \u211d))) x \u2202\u03bc) = (\u03bc (t \u2229 s)).toReal :=\n  calc\n    (\u222b x in s, (condexpL2 \u211d hm (indicatorConstLp 2 ht h\u03bct (1 : \u211d))) x \u2202\u03bc) =\n        \u222b x in s, indicatorConstLp 2 ht h\u03bct (1 : \u211d) x \u2202\u03bc :=\n      @integral_condexpL2_eq \u03b1 _ \u211d _ _ _ _ _ _ _ _ _ hm (indicatorConstLp 2 ht h\u03bct (1 : \u211d)) hs h\u03bcs\n    _ = (\u03bc (t \u2229 s)).toReal \u2022 1 := (set_integral_indicatorConstLp (hm s hs) ht h\u03bct (1 : \u211d))\n    _ = (\u03bc (t \u2229 s)).toReal := by rw [smul_eq_mul, mul_one]\n    \n#align measure_theory.set_integral_condexp_L2_indicator MeasureTheory.set_integral_condexpL2_indicator\n\ntheorem set_integral_condexpIndSmul (hs : measurable_set[m] s) (ht : MeasurableSet t)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (x : G') :\n    (\u222b a in s, (condexpIndSmul hm ht h\u03bct x) a \u2202\u03bc) = (\u03bc (t \u2229 s)).toReal \u2022 x :=\n  calc\n    (\u222b a in s, (condexpIndSmul hm ht h\u03bct x) a \u2202\u03bc) =\n        \u222b a in s, condexpL2 \u211d hm (indicatorConstLp 2 ht h\u03bct (1 : \u211d)) a \u2022 x \u2202\u03bc :=\n      set_integral_congr_ae (hm s hs)\n        ((condexpIndSmul_ae_eq_smul hm ht h\u03bct x).mono fun x hx hxs => hx)\n    _ = (\u222b a in s, condexpL2 \u211d hm (indicatorConstLp 2 ht h\u03bct (1 : \u211d)) a \u2202\u03bc) \u2022 x :=\n      (integral_smul_const _ x)\n    _ = (\u03bc (t \u2229 s)).toReal \u2022 x := by rw [set_integral_condexp_L2_indicator hs ht h\u03bcs h\u03bct]\n    \n#align measure_theory.set_integral_condexp_ind_smul MeasureTheory.set_integral_condexpIndSmul\n\ntheorem condexpL2_indicator_nonneg (hm : m \u2264 m0) (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    [SigmaFinite (\u03bc.trim hm)] : 0 \u2264\u1d50[\u03bc] condexpL2 \u211d hm (indicatorConstLp 2 hs h\u03bcs (1 : \u211d)) :=\n  by\n  have h : ae_strongly_measurable' m (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) \u03bc :=\n    ae_strongly_measurable'_condexp_L2 _ _\n  refine' eventually_le.trans_eq _ h.ae_eq_mk.symm\n  refine' @ae_le_of_ae_le_trim _ _ _ _ _ _ hm _ _ _\n  refine' ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite _ _\n  \u00b7 intro t ht h\u03bct\n    refine' @integrable.integrable_on _ _ m _ _ _ _ _\n    refine' integrable.trim hm _ _\n    \u00b7 rw [integrable_congr h.ae_eq_mk.symm]\n      exact integrable_condexp_L2_indicator hm hs h\u03bcs _\n    \u00b7 exact h.strongly_measurable_mk\n  \u00b7 intro t ht h\u03bct\n    rw [\u2190 set_integral_trim hm h.strongly_measurable_mk ht]\n    have h_ae :\n      \u2200\u1d50 x \u2202\u03bc, x \u2208 t \u2192 h.mk _ x = condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) x :=\n      by\n      filter_upwards [h.ae_eq_mk]with x hx\n      exact fun _ => hx.symm\n    rw [set_integral_congr_ae (hm t ht) h_ae,\n      set_integral_condexp_L2_indicator ht hs ((le_trim hm).trans_lt h\u03bct).Ne h\u03bcs]\n    exact ENNReal.toReal_nonneg\n#align measure_theory.condexp_L2_indicator_nonneg MeasureTheory.condexpL2_indicator_nonneg\n\ntheorem condexpIndSmul_nonneg {E} [NormedLatticeAddCommGroup E] [NormedSpace \u211d E] [OrderedSMul \u211d E]\n    [SigmaFinite (\u03bc.trim hm)] (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : E) (hx : 0 \u2264 x) :\n    0 \u2264\u1d50[\u03bc] condexpIndSmul hm hs h\u03bcs x :=\n  by\n  refine' eventually_le.trans_eq _ (condexp_ind_smul_ae_eq_smul hm hs h\u03bcs x).symm\n  filter_upwards [condexp_L2_indicator_nonneg hm hs h\u03bcs]with a ha\n  exact smul_nonneg ha hx\n#align measure_theory.condexp_ind_smul_nonneg MeasureTheory.condexpIndSmul_nonneg\n\nend CondexpIndSmul\n\nend CondexpL2\n\nsection CondexpInd\n\n/-! ## Conditional expectation of an indicator as a continuous linear map.\n\nThe goal of this section is to build\n`condexp_ind (hm : m \u2264 m0) (\u03bc : measure \u03b1) (s : set s) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G`, which\ntakes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`,\nseen as an element of `\u03b1 \u2192\u2081[\u03bc] G`.\n-/\n\n\nvariable {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {s t : Set \u03b1} [NormedSpace \u211d G]\n\nsection CondexpIndL1Fin\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure,\nas a function in L1. -/\ndef condexpIndL1Fin (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)] (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (x : G) : \u03b1 \u2192\u2081[\u03bc] G :=\n  (integrableCondexpIndSmul hm hs h\u03bcs x).toL1 _\n#align measure_theory.condexp_ind_L1_fin MeasureTheory.condexpIndL1Fin\n\ntheorem condexpIndL1Fin_ae_eq_condexpIndSmul (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)]\n    (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n    condexpIndL1Fin hm hs h\u03bcs x =\u1d50[\u03bc] condexpIndSmul hm hs h\u03bcs x :=\n  (integrableCondexpIndSmul hm hs h\u03bcs x).coeFn_toL1\n#align measure_theory.condexp_ind_L1_fin_ae_eq_condexp_ind_smul MeasureTheory.condexpIndL1Fin_ae_eq_condexpIndSmul\n\nvariable {hm : m \u2264 m0} [SigmaFinite (\u03bc.trim hm)]\n\ntheorem condexpIndL1Fin_add (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n    condexpIndL1Fin hm hs h\u03bcs (x + y) = condexpIndL1Fin hm hs h\u03bcs x + condexpIndL1Fin hm hs h\u03bcs y :=\n  by\n  ext1\n  refine' (mem_\u2112p.coe_fn_to_Lp _).trans _\n  refine' eventually_eq.trans _ (Lp.coe_fn_add _ _).symm\n  refine'\n    eventually_eq.trans _\n      (eventually_eq.add (mem_\u2112p.coe_fn_to_Lp _).symm (mem_\u2112p.coe_fn_to_Lp _).symm)\n  rw [condexp_ind_smul_add]\n  refine' (Lp.coe_fn_add _ _).trans (eventually_of_forall fun a => _)\n  rfl\n#align measure_theory.condexp_ind_L1_fin_add MeasureTheory.condexpIndL1Fin_add\n\ntheorem condexpIndL1Fin_smul (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n    condexpIndL1Fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexpIndL1Fin hm hs h\u03bcs x :=\n  by\n  ext1\n  refine' (mem_\u2112p.coe_fn_to_Lp _).trans _\n  refine' eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm\n  rw [condexp_ind_smul_smul hs h\u03bcs c x]\n  refine' (Lp.coe_fn_smul _ _).trans _\n  refine' (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono fun y hy => _\n  rw [Pi.smul_apply, Pi.smul_apply, hy]\n#align measure_theory.condexp_ind_L1_fin_smul MeasureTheory.condexpIndL1Fin_smul\n\ntheorem condexpIndL1Fin_smul' [NormedSpace \u211d F] [SMulCommClass \u211d \ud835\udd5c F] (hs : MeasurableSet s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n    condexpIndL1Fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexpIndL1Fin hm hs h\u03bcs x :=\n  by\n  ext1\n  refine' (mem_\u2112p.coe_fn_to_Lp _).trans _\n  refine' eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm\n  rw [condexp_ind_smul_smul' hs h\u03bcs c x]\n  refine' (Lp.coe_fn_smul _ _).trans _\n  refine' (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono fun y hy => _\n  rw [Pi.smul_apply, Pi.smul_apply, hy]\n#align measure_theory.condexp_ind_L1_fin_smul' MeasureTheory.condexpIndL1Fin_smul'\n\ntheorem norm_condexpIndL1Fin_le (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n    \u2016condexpIndL1Fin hm hs h\u03bcs x\u2016 \u2264 (\u03bc s).toReal * \u2016x\u2016 :=\n  by\n  have : 0 \u2264 \u222b a : \u03b1, \u2016condexp_ind_L1_fin hm hs h\u03bcs x a\u2016 \u2202\u03bc :=\n    integral_nonneg fun a => norm_nonneg _\n  rw [L1.norm_eq_integral_norm, \u2190 ENNReal.toReal_ofReal (norm_nonneg x), \u2190 ENNReal.toReal_mul, \u2190\n    ENNReal.toReal_ofReal this,\n    ENNReal.toReal_le_toReal ENNReal.ofReal_ne_top (ENNReal.mul_ne_top h\u03bcs ENNReal.ofReal_ne_top),\n    of_real_integral_norm_eq_lintegral_nnnorm]\n  swap\n  \u00b7 rw [\u2190 mem_\u2112p_one_iff_integrable]\n    exact Lp.mem_\u2112p _\n  have h_eq :\n    (\u222b\u207b a, \u2016condexp_ind_L1_fin hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc) = \u222b\u207b a, \u2016condexp_ind_smul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc :=\n    by\n    refine' lintegral_congr_ae _\n    refine' (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono fun z hz => _\n    dsimp only\n    rw [hz]\n  rw [h_eq, ofReal_norm_eq_coe_nnnorm]\n  exact lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x\n#align measure_theory.norm_condexp_ind_L1_fin_le MeasureTheory.norm_condexpIndL1Fin_le\n\ntheorem condexpIndL1Fin_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n    condexpIndL1Fin hm (hs.union ht)\n        ((measure_union_le s t).trans_lt\n            (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).Ne\n        x =\n      condexpIndL1Fin hm hs h\u03bcs x + condexpIndL1Fin hm ht h\u03bct x :=\n  by\n  ext1\n  have h\u03bcst :=\n    ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).Ne\n  refine' (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm (hs.union ht) h\u03bcst x).trans _\n  refine' eventually_eq.trans _ (Lp.coe_fn_add _ _).symm\n  have hs_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x\n  have ht_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm ht h\u03bct x\n  refine' eventually_eq.trans _ (eventually_eq.add hs_eq.symm ht_eq.symm)\n  rw [condexp_ind_smul]\n  rw [indicator_const_Lp_disjoint_union hs ht h\u03bcs h\u03bct hst (1 : \u211d)]\n  rw [(condexp_L2 \u211d hm).map_add]\n  push_cast\n  rw [((to_span_singleton \u211d x).compLpL 2 \u03bc).map_add]\n  refine' (Lp.coe_fn_add _ _).trans _\n  refine' eventually_of_forall fun y => _\n  rfl\n#align measure_theory.condexp_ind_L1_fin_disjoint_union MeasureTheory.condexpIndL1Fin_disjoint_union\n\nend CondexpIndL1Fin\n\nopen Classical\n\nsection CondexpIndL1\n\n/-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets\nwhich are not both measurable and of finite measure is not used: we set it to 0. -/\ndef condexpIndL1 {m m0 : MeasurableSpace \u03b1} (hm : m \u2264 m0) (\u03bc : Measure \u03b1) (s : Set \u03b1)\n    [SigmaFinite (\u03bc.trim hm)] (x : G) : \u03b1 \u2192\u2081[\u03bc] G :=\n  if hs : MeasurableSet s \u2227 \u03bc s \u2260 \u221e then condexpIndL1Fin hm hs.1 hs.2 x else 0\n#align measure_theory.condexp_ind_L1 MeasureTheory.condexpIndL1\n\nvariable {hm : m \u2264 m0} [SigmaFinite (\u03bc.trim hm)]\n\ntheorem condexpIndL1_of_measurableSet_of_measure_ne_top (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (x : G) : condexpIndL1 hm \u03bc s x = condexpIndL1Fin hm hs h\u03bcs x := by\n  simp only [condexp_ind_L1, And.intro hs h\u03bcs, dif_pos, Ne.def, not_false_iff, and_self_iff]\n#align measure_theory.condexp_ind_L1_of_measurable_set_of_measure_ne_top MeasureTheory.condexpIndL1_of_measurableSet_of_measure_ne_top\n\ntheorem condexpIndL1_of_measure_eq_top (h\u03bcs : \u03bc s = \u221e) (x : G) : condexpIndL1 hm \u03bc s x = 0 := by\n  simp only [condexp_ind_L1, h\u03bcs, eq_self_iff_true, not_true, Ne.def, dif_neg, not_false_iff,\n    and_false_iff]\n#align measure_theory.condexp_ind_L1_of_measure_eq_top MeasureTheory.condexpIndL1_of_measure_eq_top\n\ntheorem condexpIndL1_of_not_measurableSet (hs : \u00acMeasurableSet s) (x : G) :\n    condexpIndL1 hm \u03bc s x = 0 := by\n  simp only [condexp_ind_L1, hs, dif_neg, not_false_iff, false_and_iff]\n#align measure_theory.condexp_ind_L1_of_not_measurable_set MeasureTheory.condexpIndL1_of_not_measurableSet\n\ntheorem condexpIndL1_add (x y : G) :\n    condexpIndL1 hm \u03bc s (x + y) = condexpIndL1 hm \u03bc s x + condexpIndL1 hm \u03bc s y :=\n  by\n  by_cases hs : MeasurableSet s\n  swap;\n  \u00b7 simp_rw [condexp_ind_L1_of_not_measurable_set hs]\n    rw [zero_add]\n  by_cases h\u03bcs : \u03bc s = \u221e\n  \u00b7 simp_rw [condexp_ind_L1_of_measure_eq_top h\u03bcs]\n    rw [zero_add]\n  \u00b7 simp_rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs]\n    exact condexp_ind_L1_fin_add hs h\u03bcs x y\n#align measure_theory.condexp_ind_L1_add MeasureTheory.condexpIndL1_add\n\ntheorem condexpIndL1_smul (c : \u211d) (x : G) :\n    condexpIndL1 hm \u03bc s (c \u2022 x) = c \u2022 condexpIndL1 hm \u03bc s x :=\n  by\n  by_cases hs : MeasurableSet s\n  swap;\n  \u00b7 simp_rw [condexp_ind_L1_of_not_measurable_set hs]\n    rw [smul_zero]\n  by_cases h\u03bcs : \u03bc s = \u221e\n  \u00b7 simp_rw [condexp_ind_L1_of_measure_eq_top h\u03bcs]\n    rw [smul_zero]\n  \u00b7 simp_rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs]\n    exact condexp_ind_L1_fin_smul hs h\u03bcs c x\n#align measure_theory.condexp_ind_L1_smul MeasureTheory.condexpIndL1_smul\n\ntheorem condexpIndL1_smul' [NormedSpace \u211d F] [SMulCommClass \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n    condexpIndL1 hm \u03bc s (c \u2022 x) = c \u2022 condexpIndL1 hm \u03bc s x :=\n  by\n  by_cases hs : MeasurableSet s\n  swap;\n  \u00b7 simp_rw [condexp_ind_L1_of_not_measurable_set hs]\n    rw [smul_zero]\n  by_cases h\u03bcs : \u03bc s = \u221e\n  \u00b7 simp_rw [condexp_ind_L1_of_measure_eq_top h\u03bcs]\n    rw [smul_zero]\n  \u00b7 simp_rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs]\n    exact condexp_ind_L1_fin_smul' hs h\u03bcs c x\n#align measure_theory.condexp_ind_L1_smul' MeasureTheory.condexpIndL1_smul'\n\ntheorem norm_condexpIndL1_le (x : G) : \u2016condexpIndL1 hm \u03bc s x\u2016 \u2264 (\u03bc s).toReal * \u2016x\u2016 :=\n  by\n  by_cases hs : MeasurableSet s\n  swap;\n  \u00b7 simp_rw [condexp_ind_L1_of_not_measurable_set hs]\n    rw [Lp.norm_zero]\n    exact mul_nonneg ENNReal.toReal_nonneg (norm_nonneg _)\n  by_cases h\u03bcs : \u03bc s = \u221e\n  \u00b7 rw [condexp_ind_L1_of_measure_eq_top h\u03bcs x, Lp.norm_zero]\n    exact mul_nonneg ENNReal.toReal_nonneg (norm_nonneg _)\n  \u00b7 rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x]\n    exact norm_condexp_ind_L1_fin_le hs h\u03bcs x\n#align measure_theory.norm_condexp_ind_L1_le MeasureTheory.norm_condexpIndL1_le\n\ntheorem continuous_condexpIndL1 : Continuous fun x : G => condexpIndL1 hm \u03bc s x :=\n  continuous_of_linear_of_bound condexpIndL1_add condexpIndL1_smul norm_condexpIndL1_le\n#align measure_theory.continuous_condexp_ind_L1 MeasureTheory.continuous_condexpIndL1\n\ntheorem condexpIndL1_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n    condexpIndL1 hm \u03bc (s \u222a t) x = condexpIndL1 hm \u03bc s x + condexpIndL1 hm \u03bc t x :=\n  by\n  have h\u03bcst : \u03bc (s \u222a t) \u2260 \u221e :=\n    ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).Ne\n  rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top ht h\u03bct x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs.union ht) h\u03bcst x]\n  exact condexp_ind_L1_fin_disjoint_union hs ht h\u03bcs h\u03bct hst x\n#align measure_theory.condexp_ind_L1_disjoint_union MeasureTheory.condexpIndL1_disjoint_union\n\nend CondexpIndL1\n\n/-- Conditional expectation of the indicator of a set, as a linear map from `G` to L1. -/\ndef condexpInd {m m0 : MeasurableSpace \u03b1} (hm : m \u2264 m0) (\u03bc : Measure \u03b1) [SigmaFinite (\u03bc.trim hm)]\n    (s : Set \u03b1) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G\n    where\n  toFun := condexpIndL1 hm \u03bc s\n  map_add' := condexpIndL1_add\n  map_smul' := condexpIndL1_smul\n  cont := continuous_condexpIndL1\n#align measure_theory.condexp_ind MeasureTheory.condexpInd\n\ntheorem condexpInd_ae_eq_condexpIndSmul (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)]\n    (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n    condexpInd hm \u03bc s x =\u1d50[\u03bc] condexpIndSmul hm hs h\u03bcs x :=\n  by\n  refine' eventually_eq.trans _ (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x)\n  simp [condexp_ind, condexp_ind_L1, hs, h\u03bcs]\n#align measure_theory.condexp_ind_ae_eq_condexp_ind_smul MeasureTheory.condexpInd_ae_eq_condexpIndSmul\n\nvariable {hm : m \u2264 m0} [SigmaFinite (\u03bc.trim hm)]\n\ntheorem aeStronglyMeasurable'CondexpInd (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n    AeStronglyMeasurable' m (condexpInd hm \u03bc s x) \u03bc :=\n  AeStronglyMeasurable'.congr (aeStronglyMeasurable'CondexpIndSmul hm hs h\u03bcs x)\n    (condexpInd_ae_eq_condexpIndSmul hm hs h\u03bcs x).symm\n#align measure_theory.ae_strongly_measurable'_condexp_ind MeasureTheory.aeStronglyMeasurable'CondexpInd\n\n@[simp]\ntheorem condexpInd_empty : condexpInd hm \u03bc \u2205 = (0 : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) :=\n  by\n  ext1\n  ext1\n  refine' (condexp_ind_ae_eq_condexp_ind_smul hm MeasurableSet.empty (by simp) x).trans _\n  rw [condexp_ind_smul_empty]\n  refine' (Lp.coe_fn_zero G 2 \u03bc).trans _\n  refine' eventually_eq.trans _ (Lp.coe_fn_zero G 1 \u03bc).symm\n  rfl\n#align measure_theory.condexp_ind_empty MeasureTheory.condexpInd_empty\n\ntheorem condexpInd_smul' [NormedSpace \u211d F] [SMulCommClass \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n    condexpInd hm \u03bc s (c \u2022 x) = c \u2022 condexpInd hm \u03bc s x :=\n  condexpIndL1_smul' c x\n#align measure_theory.condexp_ind_smul' MeasureTheory.condexpInd_smul'\n\ntheorem norm_condexpInd_apply_le (x : G) : \u2016condexpInd hm \u03bc s x\u2016 \u2264 (\u03bc s).toReal * \u2016x\u2016 :=\n  norm_condexpIndL1_le x\n#align measure_theory.norm_condexp_ind_apply_le MeasureTheory.norm_condexpInd_apply_le\n\ntheorem norm_condexpInd_le : \u2016(condexpInd hm \u03bc s : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G)\u2016 \u2264 (\u03bc s).toReal :=\n  ContinuousLinearMap.op_norm_le_bound _ ENNReal.toReal_nonneg norm_condexpInd_apply_le\n#align measure_theory.norm_condexp_ind_le MeasureTheory.norm_condexpInd_le\n\ntheorem condexpInd_disjoint_union_apply (hs : MeasurableSet s) (ht : MeasurableSet t)\n    (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n    condexpInd hm \u03bc (s \u222a t) x = condexpInd hm \u03bc s x + condexpInd hm \u03bc t x :=\n  condexpIndL1_disjoint_union hs ht h\u03bcs h\u03bct hst x\n#align measure_theory.condexp_ind_disjoint_union_apply MeasureTheory.condexpInd_disjoint_union_apply\n\ntheorem condexpInd_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) :\n    (condexpInd hm \u03bc (s \u222a t) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) = condexpInd hm \u03bc s + condexpInd hm \u03bc t :=\n  by\n  ext1\n  push_cast\n  exact condexp_ind_disjoint_union_apply hs ht h\u03bcs h\u03bct hst x\n#align measure_theory.condexp_ind_disjoint_union MeasureTheory.condexpInd_disjoint_union\n\nvariable (G)\n\ntheorem dominatedFinMeasAdditiveCondexpInd (hm : m \u2264 m0) (\u03bc : Measure \u03b1) [SigmaFinite (\u03bc.trim hm)] :\n    DominatedFinMeasAdditive \u03bc (condexpInd hm \u03bc : Set \u03b1 \u2192 G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) 1 :=\n  \u27e8fun s t => condexpInd_disjoint_union, fun s _ _ => norm_condexpInd_le.trans (one_mul _).symm.le\u27e9\n#align measure_theory.dominated_fin_meas_additive_condexp_ind MeasureTheory.dominatedFinMeasAdditiveCondexpInd\n\nvariable {G}\n\ntheorem set_integral_condexpInd (hs : measurable_set[m] s) (ht : MeasurableSet t) (h\u03bcs : \u03bc s \u2260 \u221e)\n    (h\u03bct : \u03bc t \u2260 \u221e) (x : G') : (\u222b a in s, condexpInd hm \u03bc t x a \u2202\u03bc) = (\u03bc (t \u2229 s)).toReal \u2022 x :=\n  calc\n    (\u222b a in s, condexpInd hm \u03bc t x a \u2202\u03bc) = \u222b a in s, condexpIndSmul hm ht h\u03bct x a \u2202\u03bc :=\n      set_integral_congr_ae (hm s hs)\n        ((condexpInd_ae_eq_condexpIndSmul hm ht h\u03bct x).mono fun x hx hxs => hx)\n    _ = (\u03bc (t \u2229 s)).toReal \u2022 x := set_integral_condexpIndSmul hs ht h\u03bcs h\u03bct x\n    \n#align measure_theory.set_integral_condexp_ind MeasureTheory.set_integral_condexpInd\n\ntheorem condexpInd_of_measurable (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : G) :\n    condexpInd hm \u03bc s c = indicatorConstLp 1 (hm s hs) h\u03bcs c :=\n  by\n  ext1\n  refine' eventually_eq.trans _ indicator_const_Lp_coe_fn.symm\n  refine' (condexp_ind_ae_eq_condexp_ind_smul hm (hm s hs) h\u03bcs c).trans _\n  refine' (condexp_ind_smul_ae_eq_smul hm (hm s hs) h\u03bcs c).trans _\n  rw [Lp_meas_coe, condexp_L2_indicator_of_measurable hm hs h\u03bcs (1 : \u211d)]\n  refine' (@indicator_const_Lp_coe_fn \u03b1 _ _ 2 \u03bc _ s (hm s hs) h\u03bcs (1 : \u211d)).mono fun x hx => _\n  dsimp only\n  rw [hx]\n  by_cases hx_mem : x \u2208 s <;> simp [hx_mem]\n#align measure_theory.condexp_ind_of_measurable MeasureTheory.condexpInd_of_measurable\n\ntheorem condexpInd_nonneg {E} [NormedLatticeAddCommGroup E] [NormedSpace \u211d E] [OrderedSMul \u211d E]\n    (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : E) (hx : 0 \u2264 x) : 0 \u2264 condexpInd hm \u03bc s x :=\n  by\n  rw [\u2190 coe_fn_le]\n  refine' eventually_le.trans_eq _ (condexp_ind_ae_eq_condexp_ind_smul hm hs h\u03bcs x).symm\n  exact (coe_fn_zero E 1 \u03bc).trans_le (condexp_ind_smul_nonneg hs h\u03bcs x hx)\n#align measure_theory.condexp_ind_nonneg MeasureTheory.condexpInd_nonneg\n\nend CondexpInd\n\nsection CondexpL1\n\nvariable {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {hm : m \u2264 m0} [SigmaFinite (\u03bc.trim hm)]\n  {f g : \u03b1 \u2192 F'} {s : Set \u03b1}\n\n/-- Conditional expectation of a function as a linear map from `\u03b1 \u2192\u2081[\u03bc] F'` to itself. -/\ndef condexpL1Clm (hm : m \u2264 m0) (\u03bc : Measure \u03b1) [SigmaFinite (\u03bc.trim hm)] :\n    (\u03b1 \u2192\u2081[\u03bc] F') \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] F' :=\n  L1.setToL1 (dominatedFinMeasAdditiveCondexpInd F' hm \u03bc)\n#align measure_theory.condexp_L1_clm MeasureTheory.condexpL1Clm\n\ntheorem condexpL1Clm_smul (c : \ud835\udd5c) (f : \u03b1 \u2192\u2081[\u03bc] F') :\n    condexpL1Clm hm \u03bc (c \u2022 f) = c \u2022 condexpL1Clm hm \u03bc f :=\n  L1.setToL1_smul (dominatedFinMeasAdditiveCondexpInd F' hm \u03bc) (fun c s x => condexpInd_smul' c x) c\n    f\n#align measure_theory.condexp_L1_clm_smul MeasureTheory.condexpL1Clm_smul\n\ntheorem condexpL1Clm_indicatorConstLp (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n    (condexpL1Clm hm \u03bc) (indicatorConstLp 1 hs h\u03bcs x) = condexpInd hm \u03bc s x :=\n  L1.setToL1_indicatorConstLp (dominatedFinMeasAdditiveCondexpInd F' hm \u03bc) hs h\u03bcs x\n#align measure_theory.condexp_L1_clm_indicator_const_Lp MeasureTheory.condexpL1Clm_indicatorConstLp\n\ntheorem condexpL1Clm_indicatorConst (hs : MeasurableSet s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n    (condexpL1Clm hm \u03bc) \u2191(simpleFunc.indicatorConst 1 hs h\u03bcs x) = condexpInd hm \u03bc s x :=\n  by\n  rw [Lp.simple_func.coe_indicator_const]\n  exact condexp_L1_clm_indicator_const_Lp hs h\u03bcs x\n#align measure_theory.condexp_L1_clm_indicator_const MeasureTheory.condexpL1Clm_indicatorConst\n\n/-- Auxiliary lemma used in the proof of `set_integral_condexp_L1_clm`. -/\ntheorem set_integral_condexpL1Clm_of_measure_ne_top (f : \u03b1 \u2192\u2081[\u03bc] F') (hs : measurable_set[m] s)\n    (h\u03bcs : \u03bc s \u2260 \u221e) : (\u222b x in s, condexpL1Clm hm \u03bc f x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc :=\n  by\n  refine'\n    Lp.induction ENNReal.one_ne_top\n      (fun f : \u03b1 \u2192\u2081[\u03bc] F' => (\u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc) _ _\n      (isClosed_eq _ _) f\n  \u00b7 intro x t ht h\u03bct\n    simp_rw [condexp_L1_clm_indicator_const ht h\u03bct.ne x]\n    rw [Lp.simple_func.coe_indicator_const, set_integral_indicator_const_Lp (hm _ hs)]\n    exact set_integral_condexp_ind hs ht h\u03bcs h\u03bct.ne x\n  \u00b7 intro f g hf_Lp hg_Lp hfg_disj hf hg\n    simp_rw [(condexp_L1_clm hm \u03bc).map_add]\n    rw [set_integral_congr_ae (hm s hs)\n        ((Lp.coe_fn_add (condexp_L1_clm hm \u03bc (hf_Lp.to_Lp f))\n              (condexp_L1_clm hm \u03bc (hg_Lp.to_Lp g))).mono\n          fun x hx hxs => hx)]\n    rw [set_integral_congr_ae (hm s hs)\n        ((Lp.coe_fn_add (hf_Lp.to_Lp f) (hg_Lp.to_Lp g)).mono fun x hx hxs => hx)]\n    simp_rw [Pi.add_apply]\n    rw [integral_add (L1.integrable_coe_fn _).IntegrableOn (L1.integrable_coe_fn _).IntegrableOn,\n      integral_add (L1.integrable_coe_fn _).IntegrableOn (L1.integrable_coe_fn _).IntegrableOn, hf,\n      hg]\n  \u00b7 exact (continuous_set_integral s).comp (condexp_L1_clm hm \u03bc).Continuous\n  \u00b7 exact continuous_set_integral s\n#align measure_theory.set_integral_condexp_L1_clm_of_measure_ne_top MeasureTheory.set_integral_condexpL1Clm_of_measure_ne_top\n\n/-- The integral of the conditional expectation `condexp_L1_clm` over an `m`-measurable set is equal\nto the integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\ntheorem set_integral_condexpL1Clm (f : \u03b1 \u2192\u2081[\u03bc] F') (hs : measurable_set[m] s) :\n    (\u222b x in s, condexpL1Clm hm \u03bc f x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc :=\n  by\n  let S := spanning_sets (\u03bc.trim hm)\n  have hS_meas : \u2200 i, measurable_set[m] (S i) := measurable_spanning_sets (\u03bc.trim hm)\n  have hS_meas0 : \u2200 i, MeasurableSet (S i) := fun i => hm _ (hS_meas i)\n  have hs_eq : s = \u22c3 i, S i \u2229 s := by\n    simp_rw [Set.inter_comm]\n    rw [\u2190 Set.inter_union\u1d62, Union_spanning_sets (\u03bc.trim hm), Set.inter_univ]\n  have hS_finite : \u2200 i, \u03bc (S i \u2229 s) < \u221e :=\n    by\n    refine' fun i => (measure_mono (Set.inter_subset_left _ _)).trans_lt _\n    have hS_finite_trim := measure_spanning_sets_lt_top (\u03bc.trim hm) i\n    rwa [trim_measurable_set_eq hm (hS_meas i)] at hS_finite_trim\n  have h_mono : Monotone fun i => S i \u2229 s :=\n    by\n    intro i j hij x\n    simp_rw [Set.mem_inter_iff]\n    exact fun h => \u27e8monotone_spanning_sets (\u03bc.trim hm) hij h.1, h.2\u27e9\n  have h_eq_forall :\n    (fun i => \u222b x in S i \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc) = fun i => \u222b x in S i \u2229 s, f x \u2202\u03bc :=\n    funext fun i =>\n      set_integral_condexp_L1_clm_of_measure_ne_top f (@MeasurableSet.inter \u03b1 m _ _ (hS_meas i) hs)\n        (hS_finite i).Ne\n  have h_right : tendsto (fun i => \u222b x in S i \u2229 s, f x \u2202\u03bc) at_top (\ud835\udcdd (\u222b x in s, f x \u2202\u03bc)) :=\n    by\n    have h :=\n      tendsto_set_integral_of_monotone (fun i => (hS_meas0 i).inter (hm s hs)) h_mono\n        (L1.integrable_coe_fn f).IntegrableOn\n    rwa [\u2190 hs_eq] at h\n  have h_left :\n    tendsto (fun i => \u222b x in S i \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc) at_top\n      (\ud835\udcdd (\u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc)) :=\n    by\n    have h :=\n      tendsto_set_integral_of_monotone (fun i => (hS_meas0 i).inter (hm s hs)) h_mono\n        (L1.integrable_coe_fn (condexp_L1_clm hm \u03bc f)).IntegrableOn\n    rwa [\u2190 hs_eq] at h\n  rw [h_eq_forall] at h_left\n  exact tendsto_nhds_unique h_left h_right\n#align measure_theory.set_integral_condexp_L1_clm MeasureTheory.set_integral_condexpL1Clm\n\ntheorem aeStronglyMeasurable'CondexpL1Clm (f : \u03b1 \u2192\u2081[\u03bc] F') :\n    AeStronglyMeasurable' m (condexpL1Clm hm \u03bc f) \u03bc :=\n  by\n  refine'\n    Lp.induction ENNReal.one_ne_top\n      (fun f : \u03b1 \u2192\u2081[\u03bc] F' => ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc) _ _ _ f\n  \u00b7 intro c s hs h\u03bcs\n    rw [condexp_L1_clm_indicator_const hs h\u03bcs.ne c]\n    exact ae_strongly_measurable'_condexp_ind hs h\u03bcs.ne c\n  \u00b7 intro f g hf hg h_disj hfm hgm\n    rw [(condexp_L1_clm hm \u03bc).map_add]\n    refine' ae_strongly_measurable'.congr _ (coe_fn_add _ _).symm\n    exact ae_strongly_measurable'.add hfm hgm\n  \u00b7 have :\n      { f : Lp F' 1 \u03bc | ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc } =\n        condexp_L1_clm hm \u03bc \u207b\u00b9' { f | ae_strongly_measurable' m f \u03bc } :=\n      by rfl\n    rw [this]\n    refine' IsClosed.preimage (condexp_L1_clm hm \u03bc).Continuous _\n    exact is_closed_ae_strongly_measurable' hm\n#align measure_theory.ae_strongly_measurable'_condexp_L1_clm MeasureTheory.aeStronglyMeasurable'CondexpL1Clm\n\ntheorem condexpL1Clm_lpMeas (f : lpMeas F' \u211d m 1 \u03bc) : condexpL1Clm hm \u03bc (f : \u03b1 \u2192\u2081[\u03bc] F') = \u2191f :=\n  by\n  let g := Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm f\n  have hfg : f = (Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g := by\n    simp only [LinearIsometryEquiv.symm_apply_apply]\n  rw [hfg]\n  refine'\n    @Lp.induction \u03b1 F' m _ 1 (\u03bc.trim hm) _ ENNReal.coe_ne_top\n      (fun g : \u03b1 \u2192\u2081[\u03bc.trim hm] F' =>\n        condexp_L1_clm hm \u03bc ((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g : \u03b1 \u2192\u2081[\u03bc] F') =\n          \u2191((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g))\n      _ _ _ g\n  \u00b7 intro c s hs h\u03bcs\n    rw [Lp.simple_func.coe_indicator_const, Lp_meas_to_Lp_trim_lie_symm_indicator hs h\u03bcs.ne c,\n      condexp_L1_clm_indicator_const_Lp]\n    exact condexp_ind_of_measurable hs ((le_trim hm).trans_lt h\u03bcs).Ne c\n  \u00b7 intro f g hf hg hfg_disj hf_eq hg_eq\n    rw [LinearIsometryEquiv.map_add]\n    push_cast\n    rw [map_add, hf_eq, hg_eq]\n  \u00b7 refine' isClosed_eq _ _\n    \u00b7 refine' (condexp_L1_clm hm \u03bc).Continuous.comp (continuous_induced_dom.comp _)\n      exact LinearIsometryEquiv.continuous _\n    \u00b7 refine' continuous_induced_dom.comp _\n      exact LinearIsometryEquiv.continuous _\n#align measure_theory.condexp_L1_clm_Lp_meas MeasureTheory.condexpL1Clm_lpMeas\n\ntheorem condexpL1Clm_of_aeStronglyMeasurable' (f : \u03b1 \u2192\u2081[\u03bc] F') (hfm : AeStronglyMeasurable' m f \u03bc) :\n    condexpL1Clm hm \u03bc f = f :=\n  condexpL1Clm_lpMeas (\u27e8f, hfm\u27e9 : lpMeas F' \u211d m 1 \u03bc)\n#align measure_theory.condexp_L1_clm_of_ae_strongly_measurable' MeasureTheory.condexpL1Clm_of_aeStronglyMeasurable'\n\n/-- Conditional expectation of a function, in L1. Its value is 0 if the function is not\nintegrable. The function-valued `condexp` should be used instead in most cases. -/\ndef condexpL1 (hm : m \u2264 m0) (\u03bc : Measure \u03b1) [SigmaFinite (\u03bc.trim hm)] (f : \u03b1 \u2192 F') : \u03b1 \u2192\u2081[\u03bc] F' :=\n  setToFun \u03bc (condexpInd hm \u03bc) (dominatedFinMeasAdditiveCondexpInd F' hm \u03bc) f\n#align measure_theory.condexp_L1 MeasureTheory.condexpL1\n\ntheorem condexpL1_undef (hf : \u00acIntegrable f \u03bc) : condexpL1 hm \u03bc f = 0 :=\n  setToFun_undef (dominatedFinMeasAdditiveCondexpInd F' hm \u03bc) hf\n#align measure_theory.condexp_L1_undef MeasureTheory.condexpL1_undef\n\ntheorem condexpL1_eq (hf : Integrable f \u03bc) : condexpL1 hm \u03bc f = condexpL1Clm hm \u03bc (hf.toL1 f) :=\n  setToFun_eq (dominatedFinMeasAdditiveCondexpInd F' hm \u03bc) hf\n#align measure_theory.condexp_L1_eq MeasureTheory.condexpL1_eq\n\n@[simp]\ntheorem condexpL1_zero : condexpL1 hm \u03bc (0 : \u03b1 \u2192 F') = 0 :=\n  setToFun_zero _\n#align measure_theory.condexp_L1_zero MeasureTheory.condexpL1_zero\n\n@[simp]\ntheorem condexpL1_measure_zero (hm : m \u2264 m0) : condexpL1 hm (0 : Measure \u03b1) f = 0 :=\n  setToFun_measure_zero _ rfl\n#align measure_theory.condexp_L1_measure_zero MeasureTheory.condexpL1_measure_zero\n\ntheorem aeStronglyMeasurable'CondexpL1 {f : \u03b1 \u2192 F'} :\n    AeStronglyMeasurable' m (condexpL1 hm \u03bc f) \u03bc :=\n  by\n  by_cases hf : integrable f \u03bc\n  \u00b7 rw [condexp_L1_eq hf]\n    exact ae_strongly_measurable'_condexp_L1_clm _\n  \u00b7 rw [condexp_L1_undef hf]\n    refine' ae_strongly_measurable'.congr _ (coe_fn_zero _ _ _).symm\n    exact strongly_measurable.ae_strongly_measurable' (@strongly_measurable_zero _ _ m _ _)\n#align measure_theory.ae_strongly_measurable'_condexp_L1 MeasureTheory.aeStronglyMeasurable'CondexpL1\n\ntheorem condexpL1_congr_ae (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)] (h : f =\u1d50[\u03bc] g) :\n    condexpL1 hm \u03bc f = condexpL1 hm \u03bc g :=\n  setToFun_congr_ae _ h\n#align measure_theory.condexp_L1_congr_ae MeasureTheory.condexpL1_congr_ae\n\ntheorem integrableCondexpL1 (f : \u03b1 \u2192 F') : Integrable (condexpL1 hm \u03bc f) \u03bc :=\n  L1.integrableCoeFn _\n#align measure_theory.integrable_condexp_L1 MeasureTheory.integrableCondexpL1\n\n/-- The integral of the conditional expectation `condexp_L1` over an `m`-measurable set is equal to\nthe integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\ntheorem set_integral_condexpL1 (hf : Integrable f \u03bc) (hs : measurable_set[m] s) :\n    (\u222b x in s, condexpL1 hm \u03bc f x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc :=\n  by\n  simp_rw [condexp_L1_eq hf]\n  rw [set_integral_condexp_L1_clm (hf.to_L1 f) hs]\n  exact set_integral_congr_ae (hm s hs) (hf.coe_fn_to_L1.mono fun x hx hxs => hx)\n#align measure_theory.set_integral_condexp_L1 MeasureTheory.set_integral_condexpL1\n\ntheorem condexpL1_add (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    condexpL1 hm \u03bc (f + g) = condexpL1 hm \u03bc f + condexpL1 hm \u03bc g :=\n  setToFun_add _ hf hg\n#align measure_theory.condexp_L1_add MeasureTheory.condexpL1_add\n\ntheorem condexpL1_neg (f : \u03b1 \u2192 F') : condexpL1 hm \u03bc (-f) = -condexpL1 hm \u03bc f :=\n  setToFun_neg _ f\n#align measure_theory.condexp_L1_neg MeasureTheory.condexpL1_neg\n\ntheorem condexpL1_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : condexpL1 hm \u03bc (c \u2022 f) = c \u2022 condexpL1 hm \u03bc f :=\n  setToFun_smul _ (fun c _ x => condexpInd_smul' c x) c f\n#align measure_theory.condexp_L1_smul MeasureTheory.condexpL1_smul\n\ntheorem condexpL1_sub (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    condexpL1 hm \u03bc (f - g) = condexpL1 hm \u03bc f - condexpL1 hm \u03bc g :=\n  setToFun_sub _ hf hg\n#align measure_theory.condexp_L1_sub MeasureTheory.condexpL1_sub\n\ntheorem condexpL1_of_aeStronglyMeasurable' (hfm : AeStronglyMeasurable' m f \u03bc)\n    (hfi : Integrable f \u03bc) : condexpL1 hm \u03bc f =\u1d50[\u03bc] f :=\n  by\n  rw [condexp_L1_eq hfi]\n  refine' eventually_eq.trans _ (integrable.coe_fn_to_L1 hfi)\n  rw [condexp_L1_clm_of_ae_strongly_measurable']\n  exact ae_strongly_measurable'.congr hfm (integrable.coe_fn_to_L1 hfi).symm\n#align measure_theory.condexp_L1_of_ae_strongly_measurable' MeasureTheory.condexpL1_of_aeStronglyMeasurable'\n\ntheorem condexpL1_mono {E} [NormedLatticeAddCommGroup E] [CompleteSpace E] [NormedSpace \u211d E]\n    [OrderedSMul \u211d E] {f g : \u03b1 \u2192 E} (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) (hfg : f \u2264\u1d50[\u03bc] g) :\n    condexpL1 hm \u03bc f \u2264\u1d50[\u03bc] condexpL1 hm \u03bc g :=\n  by\n  rw [coe_fn_le]\n  have h_nonneg : \u2200 s, MeasurableSet s \u2192 \u03bc s < \u221e \u2192 \u2200 x : E, 0 \u2264 x \u2192 0 \u2264 condexp_ind hm \u03bc s x :=\n    fun s hs h\u03bcs x hx => condexp_ind_nonneg hs h\u03bcs.Ne x hx\n  exact set_to_fun_mono (dominated_fin_meas_additive_condexp_ind E hm \u03bc) h_nonneg hf hg hfg\n#align measure_theory.condexp_L1_mono MeasureTheory.condexpL1_mono\n\nend CondexpL1\n\nsection Condexp\n\n/-! ### Conditional expectation of a function -/\n\n\nopen Classical\n\nvariable {\ud835\udd5c} {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} {f g : \u03b1 \u2192 F'} {s : Set \u03b1}\n\n/-- Conditional expectation of a function. It is defined as 0 if any one of the following conditions\nis true:\n- `m` is not a sub-\u03c3-algebra of `m0`,\n- `\u03bc` is not \u03c3-finite with respect to `m`,\n- `f` is not integrable. -/\nirreducible_def condexp (m : MeasurableSpace \u03b1) {m0 : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1)\n  (f : \u03b1 \u2192 F') : \u03b1 \u2192 F' :=\n  if hm : m \u2264 m0 then\n    if h : SigmaFinite (\u03bc.trim hm) \u2227 Integrable f \u03bc then\n      if strongly_measurable[m] f then f\n      else\n        (@aeStronglyMeasurable'CondexpL1 _ _ _ _ _ m m0 \u03bc hm h.1 _).mk\n          (@condexpL1 _ _ _ _ _ _ _ hm \u03bc h.1 f)\n    else 0\n  else 0\n#align measure_theory.condexp MeasureTheory.condexp\n\n-- mathport name: measure_theory.condexp\n-- We define notation `\u03bc[f|m]` for the conditional expectation of `f` with respect to `m`.\nscoped notation \u03bc \"[\" f \"|\" m \"]\" => MeasureTheory.condexp m \u03bc f\n\ntheorem condexp_of_not_le (hm_not : \u00acm \u2264 m0) : \u03bc[f|m] = 0 := by rw [condexp, dif_neg hm_not]\n#align measure_theory.condexp_of_not_le MeasureTheory.condexp_of_not_le\n\ntheorem condexp_of_not_sigmaFinite (hm : m \u2264 m0) (h\u03bcm_not : \u00acSigmaFinite (\u03bc.trim hm)) :\n    \u03bc[f|m] = 0 := by\n  rw [condexp, dif_pos hm, dif_neg]\n  push_neg\n  exact fun h => absurd h h\u03bcm_not\n#align measure_theory.condexp_of_not_sigma_finite MeasureTheory.condexp_of_not_sigmaFinite\n\ntheorem condexp_of_sigmaFinite (hm : m \u2264 m0) [h\u03bcm : SigmaFinite (\u03bc.trim hm)] :\n    \u03bc[f|m] =\n      if Integrable f \u03bc then\n        if strongly_measurable[m] f then f else aeStronglyMeasurable'CondexpL1.mk (condexpL1 hm \u03bc f)\n      else 0 :=\n  by\n  rw [condexp, dif_pos hm]\n  simp only [h\u03bcm, Ne.def, true_and_iff]\n  by_cases hf : integrable f \u03bc\n  \u00b7 rw [dif_pos hf, if_pos hf]\n  \u00b7 rw [dif_neg hf, if_neg hf]\n#align measure_theory.condexp_of_sigma_finite MeasureTheory.condexp_of_sigmaFinite\n\ntheorem condexp_of_stronglyMeasurable (hm : m \u2264 m0) [h\u03bcm : SigmaFinite (\u03bc.trim hm)] {f : \u03b1 \u2192 F'}\n    (hf : strongly_measurable[m] f) (hfi : Integrable f \u03bc) : \u03bc[f|m] = f :=\n  by\n  rw [condexp_of_sigma_finite hm, if_pos hfi, if_pos hf]\n  infer_instance\n#align measure_theory.condexp_of_strongly_measurable MeasureTheory.condexp_of_stronglyMeasurable\n\ntheorem condexp_const (hm : m \u2264 m0) (c : F') [IsFiniteMeasure \u03bc] :\n    \u03bc[fun x : \u03b1 => c|m] = fun _ => c :=\n  condexp_of_stronglyMeasurable hm (@stronglyMeasurable_const _ _ m _ _) (integrableConst c)\n#align measure_theory.condexp_const MeasureTheory.condexp_const\n\ntheorem condexp_ae_eq_condexpL1 (hm : m \u2264 m0) [h\u03bcm : SigmaFinite (\u03bc.trim hm)] (f : \u03b1 \u2192 F') :\n    \u03bc[f|m] =\u1d50[\u03bc] condexpL1 hm \u03bc f :=\n  by\n  rw [condexp_of_sigma_finite hm]\n  by_cases hfi : integrable f \u03bc\n  \u00b7 rw [if_pos hfi]\n    by_cases hfm : strongly_measurable[m] f\n    \u00b7 rw [if_pos hfm]\n      exact\n        (condexp_L1_of_ae_strongly_measurable' (strongly_measurable.ae_strongly_measurable' hfm)\n            hfi).symm\n    \u00b7 rw [if_neg hfm]\n      exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm\n  rw [if_neg hfi, condexp_L1_undef hfi]\n  exact (coe_fn_zero _ _ _).symm\n#align measure_theory.condexp_ae_eq_condexp_L1 MeasureTheory.condexp_ae_eq_condexpL1\n\ntheorem condexp_ae_eq_condexpL1Clm (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)] (hf : Integrable f \u03bc) :\n    \u03bc[f|m] =\u1d50[\u03bc] condexpL1Clm hm \u03bc (hf.toL1 f) :=\n  by\n  refine' (condexp_ae_eq_condexp_L1 hm f).trans (eventually_of_forall fun x => _)\n  rw [condexp_L1_eq hf]\n#align measure_theory.condexp_ae_eq_condexp_L1_clm MeasureTheory.condexp_ae_eq_condexpL1Clm\n\ntheorem condexp_undef (hf : \u00acIntegrable f \u03bc) : \u03bc[f|m] = 0 :=\n  by\n  by_cases hm : m \u2264 m0\n  swap; \u00b7 rw [condexp_of_not_le hm]\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap; \u00b7 rw [condexp_of_not_sigma_finite hm h\u03bcm]\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  rw [condexp_of_sigma_finite, if_neg hf]\n#align measure_theory.condexp_undef MeasureTheory.condexp_undef\n\n@[simp]\ntheorem condexp_zero : \u03bc[(0 : \u03b1 \u2192 F')|m] = 0 :=\n  by\n  by_cases hm : m \u2264 m0\n  swap; \u00b7 rw [condexp_of_not_le hm]\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap; \u00b7 rw [condexp_of_not_sigma_finite hm h\u03bcm]\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  exact\n    condexp_of_strongly_measurable hm (@strongly_measurable_zero _ _ m _ _) (integrable_zero _ _ _)\n#align measure_theory.condexp_zero MeasureTheory.condexp_zero\n\ntheorem stronglyMeasurable_condexp : strongly_measurable[m] (\u03bc[f|m]) :=\n  by\n  by_cases hm : m \u2264 m0\n  swap;\n  \u00b7 rw [condexp_of_not_le hm]\n    exact strongly_measurable_zero\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap;\n  \u00b7 rw [condexp_of_not_sigma_finite hm h\u03bcm]\n    exact strongly_measurable_zero\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  rw [condexp_of_sigma_finite hm]\n  swap; \u00b7 infer_instance\n  split_ifs with hfi hfm\n  \u00b7 exact hfm\n  \u00b7 exact ae_strongly_measurable'.strongly_measurable_mk _\n  \u00b7 exact strongly_measurable_zero\n#align measure_theory.strongly_measurable_condexp MeasureTheory.stronglyMeasurable_condexp\n\ntheorem condexp_congr_ae (h : f =\u1d50[\u03bc] g) : \u03bc[f|m] =\u1d50[\u03bc] \u03bc[g|m] :=\n  by\n  by_cases hm : m \u2264 m0\n  swap; \u00b7 simp_rw [condexp_of_not_le hm]\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap; \u00b7 simp_rw [condexp_of_not_sigma_finite hm h\u03bcm]\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  exact\n    (condexp_ae_eq_condexp_L1 hm f).trans\n      (Filter.EventuallyEq.trans (by rw [condexp_L1_congr_ae hm h])\n        (condexp_ae_eq_condexp_L1 hm g).symm)\n#align measure_theory.condexp_congr_ae MeasureTheory.condexp_congr_ae\n\ntheorem condexp_of_aeStronglyMeasurable' (hm : m \u2264 m0) [h\u03bcm : SigmaFinite (\u03bc.trim hm)] {f : \u03b1 \u2192 F'}\n    (hf : AeStronglyMeasurable' m f \u03bc) (hfi : Integrable f \u03bc) : \u03bc[f|m] =\u1d50[\u03bc] f :=\n  by\n  refine' ((condexp_congr_ae hf.ae_eq_mk).trans _).trans hf.ae_eq_mk.symm\n  rw [condexp_of_strongly_measurable hm hf.strongly_measurable_mk\n      ((integrable_congr hf.ae_eq_mk).mp hfi)]\n#align measure_theory.condexp_of_ae_strongly_measurable' MeasureTheory.condexp_of_aeStronglyMeasurable'\n\ntheorem integrableCondexp : Integrable (\u03bc[f|m]) \u03bc :=\n  by\n  by_cases hm : m \u2264 m0\n  swap;\n  \u00b7 rw [condexp_of_not_le hm]\n    exact integrable_zero _ _ _\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap;\n  \u00b7 rw [condexp_of_not_sigma_finite hm h\u03bcm]\n    exact integrable_zero _ _ _\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  exact (integrable_condexp_L1 f).congr (condexp_ae_eq_condexp_L1 hm f).symm\n#align measure_theory.integrable_condexp MeasureTheory.integrableCondexp\n\n/-- The integral of the conditional expectation `\u03bc[f|hm]` over an `m`-measurable set is equal to\nthe integral of `f` on that set. -/\ntheorem set_integral_condexp (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)] (hf : Integrable f \u03bc)\n    (hs : measurable_set[m] s) : (\u222b x in s, (\u03bc[f|m]) x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc :=\n  by\n  rw [set_integral_congr_ae (hm s hs) ((condexp_ae_eq_condexp_L1 hm f).mono fun x hx _ => hx)]\n  exact set_integral_condexp_L1 hf hs\n#align measure_theory.set_integral_condexp MeasureTheory.set_integral_condexp\n\ntheorem integral_condexp (hm : m \u2264 m0) [h\u03bcm : SigmaFinite (\u03bc.trim hm)] (hf : Integrable f \u03bc) :\n    (\u222b x, (\u03bc[f|m]) x \u2202\u03bc) = \u222b x, f x \u2202\u03bc :=\n  by\n  suffices (\u222b x in Set.univ, (\u03bc[f|m]) x \u2202\u03bc) = \u222b x in Set.univ, f x \u2202\u03bc\n    by\n    simp_rw [integral_univ] at this\n    exact this\n  exact set_integral_condexp hm hf (@MeasurableSet.univ _ m)\n#align measure_theory.integral_condexp MeasureTheory.integral_condexp\n\n/-- **Uniqueness of the conditional expectation**\nIf a function is a.e. `m`-measurable, verifies an integrability condition and has same integral\nas `f` on all `m`-measurable sets, then it is a.e. equal to `\u03bc[f|hm]`. -/\ntheorem ae_eq_condexp_of_forall_set_integral_eq (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)]\n    {f g : \u03b1 \u2192 F'} (hf : Integrable f \u03bc)\n    (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 IntegrableOn g s \u03bc)\n    (hg_eq : \u2200 s : Set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 (\u222b x in s, g x \u2202\u03bc) = \u222b x in s, f x \u2202\u03bc)\n    (hgm : AeStronglyMeasurable' m g \u03bc) : g =\u1d50[\u03bc] \u03bc[f|m] :=\n  by\n  refine'\n    ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm hg_int_finite\n      (fun s hs h\u03bcs => integrable_condexp.integrable_on) (fun s hs h\u03bcs => _) hgm\n      (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp)\n  rw [hg_eq s hs h\u03bcs, set_integral_condexp hm hf hs]\n#align measure_theory.ae_eq_condexp_of_forall_set_integral_eq MeasureTheory.ae_eq_condexp_of_forall_set_integral_eq\n\ntheorem condexp_bot' [h\u03bc : \u03bc.ae.ne_bot] (f : \u03b1 \u2192 F') :\n    \u03bc[f|\u22a5] = fun _ => (\u03bc Set.univ).toReal\u207b\u00b9 \u2022 \u222b x, f x \u2202\u03bc :=\n  by\n  by_cases h\u03bc_finite : is_finite_measure \u03bc\n  swap\n  \u00b7 have h : \u00acsigma_finite (\u03bc.trim bot_le) := by rwa [sigma_finite_trim_bot_iff]\n    rw [not_is_finite_measure_iff] at h\u03bc_finite\n    rw [condexp_of_not_sigma_finite bot_le h]\n    simp only [h\u03bc_finite, ENNReal.top_toReal, inv_zero, zero_smul]\n    rfl\n  haveI : is_finite_measure \u03bc := h\u03bc_finite\n  by_cases hf : integrable f \u03bc\n  swap;\n  \u00b7 rw [integral_undef hf, smul_zero, condexp_undef hf]\n    rfl\n  have h_meas : strongly_measurable[\u22a5] (\u03bc[f|\u22a5]) := strongly_measurable_condexp\n  obtain \u27e8c, h_eq\u27e9 := strongly_measurable_bot_iff.mp h_meas\n  rw [h_eq]\n  have h_integral : (\u222b x, (\u03bc[f|\u22a5]) x \u2202\u03bc) = \u222b x, f x \u2202\u03bc := integral_condexp bot_le hf\n  simp_rw [h_eq, integral_const] at h_integral\n  rw [\u2190 h_integral, \u2190 smul_assoc, smul_eq_mul, inv_mul_cancel, one_smul]\n  rw [Ne.def, ENNReal.toReal_eq_zero_iff, Auto.not_or_eq, measure.measure_univ_eq_zero, \u2190 ae_eq_bot,\n    \u2190 Ne.def, \u2190 ne_bot_iff]\n  exact \u27e8h\u03bc, measure_ne_top \u03bc Set.univ\u27e9\n#align measure_theory.condexp_bot' MeasureTheory.condexp_bot'\n\ntheorem condexp_bot_ae_eq (f : \u03b1 \u2192 F') :\n    \u03bc[f|\u22a5] =\u1d50[\u03bc] fun _ => (\u03bc Set.univ).toReal\u207b\u00b9 \u2022 \u222b x, f x \u2202\u03bc :=\n  by\n  by_cases \u03bc.ae.ne_bot\n  \u00b7 refine' eventually_of_forall fun x => _\n    rw [condexp_bot' f]\n    exact h\n  \u00b7 rw [ne_bot_iff, Classical.not_not, ae_eq_bot] at h\n    simp only [h, ae_zero]\n#align measure_theory.condexp_bot_ae_eq MeasureTheory.condexp_bot_ae_eq\n\ntheorem condexp_bot [IsProbabilityMeasure \u03bc] (f : \u03b1 \u2192 F') : \u03bc[f|\u22a5] = fun _ => \u222b x, f x \u2202\u03bc :=\n  by\n  refine' (condexp_bot' f).trans _\n  rw [measure_univ, ENNReal.one_toReal, inv_one, one_smul]\n#align measure_theory.condexp_bot MeasureTheory.condexp_bot\n\ntheorem condexp_add (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    \u03bc[f + g|m] =\u1d50[\u03bc] \u03bc[f|m] + \u03bc[g|m] :=\n  by\n  by_cases hm : m \u2264 m0\n  swap;\n  \u00b7 simp_rw [condexp_of_not_le hm]\n    simp\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap;\n  \u00b7 simp_rw [condexp_of_not_sigma_finite hm h\u03bcm]\n    simp\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  refine' (condexp_ae_eq_condexp_L1 hm _).trans _\n  rw [condexp_L1_add hf hg]\n  exact\n    (coe_fn_add _ _).trans\n      ((condexp_ae_eq_condexp_L1 hm _).symm.add (condexp_ae_eq_condexp_L1 hm _).symm)\n#align measure_theory.condexp_add MeasureTheory.condexp_add\n\ntheorem condexp_finset_sum {\u03b9 : Type _} {s : Finset \u03b9} {f : \u03b9 \u2192 \u03b1 \u2192 F'}\n    (hf : \u2200 i \u2208 s, Integrable (f i) \u03bc) : \u03bc[\u2211 i in s, f i|m] =\u1d50[\u03bc] \u2211 i in s, \u03bc[f i|m] :=\n  by\n  induction' s using Finset.induction_on with i s his heq hf\n  \u00b7 rw [Finset.sum_empty, Finset.sum_empty, condexp_zero]\n  \u00b7 rw [Finset.sum_insert his, Finset.sum_insert his]\n    exact\n      (condexp_add (hf i <| Finset.mem_insert_self i s) <|\n            integrable_finset_sum' _ fun j hmem => hf j <| Finset.mem_insert_of_mem hmem).trans\n        ((eventually_eq.refl _ _).add (HEq fun j hmem => hf j <| Finset.mem_insert_of_mem hmem))\n#align measure_theory.condexp_finset_sum MeasureTheory.condexp_finset_sum\n\ntheorem condexp_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : \u03bc[c \u2022 f|m] =\u1d50[\u03bc] c \u2022 \u03bc[f|m] :=\n  by\n  by_cases hm : m \u2264 m0\n  swap;\n  \u00b7 simp_rw [condexp_of_not_le hm]\n    simp\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap;\n  \u00b7 simp_rw [condexp_of_not_sigma_finite hm h\u03bcm]\n    simp\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  refine' (condexp_ae_eq_condexp_L1 hm _).trans _\n  rw [condexp_L1_smul c f]\n  refine' (@condexp_ae_eq_condexp_L1 _ _ _ _ _ m _ _ hm _ f).mp _\n  refine' (coe_fn_smul c (condexp_L1 hm \u03bc f)).mono fun x hx1 hx2 => _\n  rw [hx1, Pi.smul_apply, Pi.smul_apply, hx2]\n#align measure_theory.condexp_smul MeasureTheory.condexp_smul\n\ntheorem condexp_neg (f : \u03b1 \u2192 F') : \u03bc[-f|m] =\u1d50[\u03bc] -\u03bc[f|m] := by\n  letI : Module \u211d (\u03b1 \u2192 F') := @Pi.module \u03b1 (fun _ => F') \u211d _ _ fun _ => inferInstance <;>\n    calc\n      \u03bc[-f|m] = \u03bc[(-1 : \u211d) \u2022 f|m] := by rw [neg_one_smul \u211d f]\n      _ =\u1d50[\u03bc] (-1 : \u211d) \u2022 \u03bc[f|m] := (condexp_smul (-1) f)\n      _ = -\u03bc[f|m] := neg_one_smul \u211d (\u03bc[f|m])\n      \n#align measure_theory.condexp_neg MeasureTheory.condexp_neg\n\ntheorem condexp_sub (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    \u03bc[f - g|m] =\u1d50[\u03bc] \u03bc[f|m] - \u03bc[g|m] :=\n  by\n  simp_rw [sub_eq_add_neg]\n  exact (condexp_add hf hg.neg).trans (eventually_eq.rfl.add (condexp_neg g))\n#align measure_theory.condexp_sub MeasureTheory.condexp_sub\n\ntheorem condexp_condexp_of_le {m\u2081 m\u2082 m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} (hm\u2081\u2082 : m\u2081 \u2264 m\u2082)\n    (hm\u2082 : m\u2082 \u2264 m0) [SigmaFinite (\u03bc.trim hm\u2082)] : \u03bc[\u03bc[f|m\u2082]|m\u2081] =\u1d50[\u03bc] \u03bc[f|m\u2081] :=\n  by\n  by_cases h\u03bcm\u2081 : sigma_finite (\u03bc.trim (hm\u2081\u2082.trans hm\u2082))\n  swap; \u00b7 simp_rw [condexp_of_not_sigma_finite (hm\u2081\u2082.trans hm\u2082) h\u03bcm\u2081]\n  haveI : sigma_finite (\u03bc.trim (hm\u2081\u2082.trans hm\u2082)) := h\u03bcm\u2081\n  by_cases hf : integrable f \u03bc\n  swap; \u00b7 simp_rw [condexp_undef hf, condexp_zero]\n  refine'\n    ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm\u2081\u2082.trans hm\u2082)\n      (fun s hs h\u03bcs => integrable_condexp.integrable_on)\n      (fun s hs h\u03bcs => integrable_condexp.integrable_on) _\n      (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp)\n      (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp)\n  intro s hs h\u03bcs\n  rw [set_integral_condexp (hm\u2081\u2082.trans hm\u2082) integrable_condexp hs]\n  swap; \u00b7 infer_instance\n  rw [set_integral_condexp (hm\u2081\u2082.trans hm\u2082) hf hs, set_integral_condexp hm\u2082 hf (hm\u2081\u2082 s hs)]\n#align measure_theory.condexp_condexp_of_le MeasureTheory.condexp_condexp_of_le\n\ntheorem condexp_mono {E} [NormedLatticeAddCommGroup E] [CompleteSpace E] [NormedSpace \u211d E]\n    [OrderedSMul \u211d E] {f g : \u03b1 \u2192 E} (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) (hfg : f \u2264\u1d50[\u03bc] g) :\n    \u03bc[f|m] \u2264\u1d50[\u03bc] \u03bc[g|m] := by\n  by_cases hm : m \u2264 m0\n  swap; \u00b7 simp_rw [condexp_of_not_le hm]\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap; \u00b7 simp_rw [condexp_of_not_sigma_finite hm h\u03bcm]\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  exact\n    (condexp_ae_eq_condexp_L1 hm _).trans_le\n      ((condexp_L1_mono hf hg hfg).trans_eq (condexp_ae_eq_condexp_L1 hm _).symm)\n#align measure_theory.condexp_mono MeasureTheory.condexp_mono\n\ntheorem condexp_nonneg {E} [NormedLatticeAddCommGroup E] [CompleteSpace E] [NormedSpace \u211d E]\n    [OrderedSMul \u211d E] {f : \u03b1 \u2192 E} (hf : 0 \u2264\u1d50[\u03bc] f) : 0 \u2264\u1d50[\u03bc] \u03bc[f|m] :=\n  by\n  by_cases hfint : integrable f \u03bc\n  \u00b7 rw [(condexp_zero.symm : (0 : \u03b1 \u2192 E) = \u03bc[0|m])]\n    exact condexp_mono (integrable_zero _ _ _) hfint hf\n  \u00b7 rw [condexp_undef hfint]\n#align measure_theory.condexp_nonneg MeasureTheory.condexp_nonneg\n\ntheorem condexp_nonpos {E} [NormedLatticeAddCommGroup E] [CompleteSpace E] [NormedSpace \u211d E]\n    [OrderedSMul \u211d E] {f : \u03b1 \u2192 E} (hf : f \u2264\u1d50[\u03bc] 0) : \u03bc[f|m] \u2264\u1d50[\u03bc] 0 :=\n  by\n  by_cases hfint : integrable f \u03bc\n  \u00b7 rw [(condexp_zero.symm : (0 : \u03b1 \u2192 E) = \u03bc[0|m])]\n    exact condexp_mono hfint (integrable_zero _ _ _) hf\n  \u00b7 rw [condexp_undef hfint]\n#align measure_theory.condexp_nonpos MeasureTheory.condexp_nonpos\n\n/-- **Lebesgue dominated convergence theorem**: sufficient conditions under which almost\n  everywhere convergence of a sequence of functions implies the convergence of their image by\n  `condexp_L1`. -/\ntheorem tendsto_condexpL1_of_dominated_convergence (hm : m \u2264 m0) [SigmaFinite (\u03bc.trim hm)]\n    {fs : \u2115 \u2192 \u03b1 \u2192 F'} {f : \u03b1 \u2192 F'} (bound_fs : \u03b1 \u2192 \u211d)\n    (hfs_meas : \u2200 n, AeStronglyMeasurable (fs n) \u03bc) (h_int_bound_fs : Integrable bound_fs \u03bc)\n    (hfs_bound : \u2200 n, \u2200\u1d50 x \u2202\u03bc, \u2016fs n x\u2016 \u2264 bound_fs x)\n    (hfs : \u2200\u1d50 x \u2202\u03bc, Tendsto (fun n => fs n x) atTop (\ud835\udcdd (f x))) :\n    Tendsto (fun n => condexpL1 hm \u03bc (fs n)) atTop (\ud835\udcdd (condexpL1 hm \u03bc f)) :=\n  tendsto_setToFun_of_dominated_convergence _ bound_fs hfs_meas h_int_bound_fs hfs_bound hfs\n#align measure_theory.tendsto_condexp_L1_of_dominated_convergence MeasureTheory.tendsto_condexpL1_of_dominated_convergence\n\n/-- If two sequences of functions have a.e. equal conditional expectations at each step, converge\nand verify dominated convergence hypotheses, then the conditional expectations of their limits are\na.e. equal. -/\ntheorem tendsto_condexp_unique (fs gs : \u2115 \u2192 \u03b1 \u2192 F') (f g : \u03b1 \u2192 F')\n    (hfs_int : \u2200 n, Integrable (fs n) \u03bc) (hgs_int : \u2200 n, Integrable (gs n) \u03bc)\n    (hfs : \u2200\u1d50 x \u2202\u03bc, Tendsto (fun n => fs n x) atTop (\ud835\udcdd (f x)))\n    (hgs : \u2200\u1d50 x \u2202\u03bc, Tendsto (fun n => gs n x) atTop (\ud835\udcdd (g x))) (bound_fs : \u03b1 \u2192 \u211d)\n    (h_int_bound_fs : Integrable bound_fs \u03bc) (bound_gs : \u03b1 \u2192 \u211d)\n    (h_int_bound_gs : Integrable bound_gs \u03bc) (hfs_bound : \u2200 n, \u2200\u1d50 x \u2202\u03bc, \u2016fs n x\u2016 \u2264 bound_fs x)\n    (hgs_bound : \u2200 n, \u2200\u1d50 x \u2202\u03bc, \u2016gs n x\u2016 \u2264 bound_gs x) (hfg : \u2200 n, \u03bc[fs n|m] =\u1d50[\u03bc] \u03bc[gs n|m]) :\n    \u03bc[f|m] =\u1d50[\u03bc] \u03bc[g|m] := by\n  by_cases hm : m \u2264 m0\n  swap\n  \u00b7 simp_rw [condexp_of_not_le hm]\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm)\n  swap\n  \u00b7 simp_rw [condexp_of_not_sigma_finite hm h\u03bcm]\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm\n  refine' (condexp_ae_eq_condexp_L1 hm f).trans ((condexp_ae_eq_condexp_L1 hm g).trans _).symm\n  rw [\u2190 Lp.ext_iff]\n  have hn_eq : \u2200 n, condexp_L1 hm \u03bc (gs n) = condexp_L1 hm \u03bc (fs n) :=\n    by\n    intro n\n    ext1\n    refine' (condexp_ae_eq_condexp_L1 hm (gs n)).symm.trans ((hfg n).symm.trans _)\n    exact condexp_ae_eq_condexp_L1 hm (fs n)\n  have hcond_fs : tendsto (fun n => condexp_L1 hm \u03bc (fs n)) at_top (\ud835\udcdd (condexp_L1 hm \u03bc f)) :=\n    tendsto_condexp_L1_of_dominated_convergence hm _ (fun n => (hfs_int n).1) h_int_bound_fs\n      hfs_bound hfs\n  have hcond_gs : tendsto (fun n => condexp_L1 hm \u03bc (gs n)) at_top (\ud835\udcdd (condexp_L1 hm \u03bc g)) :=\n    tendsto_condexp_L1_of_dominated_convergence hm _ (fun n => (hgs_int n).1) h_int_bound_gs\n      hgs_bound hgs\n  exact tendsto_nhds_unique_of_eventuallyEq hcond_gs hcond_fs (eventually_of_forall hn_eq)\n#align measure_theory.tendsto_condexp_unique MeasureTheory.tendsto_condexp_unique\n\nend Condexp\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Function/ConditionalExpectation/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.738592330426563}}
{"text": "-- Imagen_de_la_union.lean\n-- Imagen de la uni\u00f3n.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 4 de mayo de 2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, la imagen de un conjunto s por una funci\u00f3n f se representa\n-- por `f '' s`; es decir,\n--    f '' s = {y | \u2203 x, x \u2208 s \u2227 f x = y}\n--\n-- Demostrar que\n--    f '' (s \u222a t) = f '' s \u222a f '' t\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables s t : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { intro h,\n    rw mem_image at h,\n    cases h with x hx,\n    cases hx with xst fxy,\n    rw \u2190 fxy, \n    rw mem_union at xst,\n    cases xst with xs xt, \n    { apply mem_union_left,\n      apply mem_image_of_mem,\n      exact xs, },\n    { apply mem_union_right,\n      apply mem_image_of_mem,\n      exact xt, }},\n  { intro h,\n    rw mem_union at h,\n    cases h with yfs yft,\n    { rw mem_image,\n      rw mem_image at yfs,\n      cases yfs with x hx,\n      cases hx with xs fxy,\n      use x,\n      split,\n      { apply mem_union_left,\n        exact xs, },\n      { exact fxy, }},\n    { rw mem_image,\n      rw mem_image at yft,\n      cases yft with x hx,\n      cases hx with xt fxy,\n      use x,\n      split,\n      { apply mem_union_right,\n        exact xt, },\n      { exact fxy, }}},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8x, xst, rfl\u27e9,\n    cases xst with xs xt, \n    { left,\n      exact mem_image_of_mem f xs, },\n    { right,\n      exact mem_image_of_mem f xt, }},\n  { rintro (yfs | yft),\n    { rcases yfs with \u27e8x, xs, rfl\u27e9,\n      apply mem_image_of_mem,\n      left,\n      exact xs, },\n    { rcases yft with \u27e8x, xt, rfl\u27e9,\n      apply mem_image_of_mem,\n      right,\n      exact xt, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8x, xst, rfl\u27e9,\n    cases xst with xs xt, \n    { left,\n      use [x, xs], },\n    { right,\n      use [x, xt], }},\n  { rintro (yfs | yft),\n    { rcases yfs with \u27e8x, xs, rfl\u27e9,\n      use [x, or.inl xs], },\n    { rcases yft with \u27e8x, xt, rfl\u27e9,\n      use [x, or.inr xt], }},\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8x, xs | xt, rfl\u27e9,\n    { left,\n      use [x, xs], },\n    { right,\n      use [x, xt], }},\n  { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9),\n    { use [x, or.inl xs], },\n    { use [x, or.inr xt], }},\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8x, xs | xt, rfl\u27e9 ; finish, },\n  { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9) ; finish, },\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { finish, },\n  { finish, },\nend\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  rw iff_def,\n  finish, \nend\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nby finish [ext_iff, iff_def]\n\n-- 9\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nimage_union f s t", "meta": {"author": "jaalonso", "repo": "Razonando-con-Lean", "sha": "d6e3fe9e384bdb6d8cc6ce4383d86c72bbcc154c", "save_path": "github-repos/lean/jaalonso-Razonando-con-Lean", "path": "github-repos/lean/jaalonso-Razonando-con-Lean/Razonando-con-Lean-d6e3fe9e384bdb6d8cc6ce4383d86c72bbcc154c/src/Imagen_de_la_union.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7385857886999206}}
{"text": "/-\nCopyright (c) 2016 Jacob Gross. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jacob Gross\n\nThe order topology.\n-/\nimport data.set theories.topology.basic algebra.interval\nopen algebra eq.ops set interval topology\n\nnamespace order_topology\n\nvariables {X : Type} [linear_strong_order_pair X]\n\ndefinition linorder_generators : set (set X) := {y | \u2203 a, y = '(a, \u221e) } \u222a {y | \u2203 a, y = '(-\u221e, a)}\n\ndefinition linorder_topology [instance] : topology X :=\n  topology.generated_by linorder_generators\n\ntheorem Open_Ioi {a : X} : Open '(a, \u221e) :=\n(generators_mem_topology_generated_by linorder_generators) (!mem_unionl (exists.intro a rfl))\n\ntheorem Open_Iio {a : X} : Open '(-\u221e, a) :=\n(generators_mem_topology_generated_by linorder_generators) (!mem_unionr (exists.intro a rfl))\n\ntheorem closed_Ici (a : X) : closed '[a,\u221e) :=\n!compl_Ici\u207b\u00b9 \u25b8 Open_Iio\n\ntheorem closed_Iic (a : X) : closed '(-\u221e,a] :=\nhave '(a, \u221e) = -'(-\u221e,a], from ext(take x, iff.intro\n  (assume H, not_le_of_gt H)\n  (assume H, lt_of_not_ge H)),\nthis \u25b8 Open_Ioi\n\ntheorem Open_Ioo (a b : X) : Open '(a, b) :=\nOpen_inter !Open_Ioi !Open_Iio\n\ntheorem closed_Icc (a b : X) : closed '[a, b] :=\nclosed_inter !closed_Ici !closed_Iic\n\nsection\n  open classical\n\n  theorem linorder_separation {x y : X} :\n    x < y \u2192 \u2203 a b, (x < a \u2227 b < y) \u2227 '(-\u221e, a) \u2229 '(b, \u221e) = \u2205 :=\n  suppose x < y,\n  if H1 : \u2203 z, x < z \u2227 z < y then\n    obtain z (Hz : x < z \u2227 z < y), from H1,\n    have '(-\u221e, z) \u2229 '(z, \u221e) = \u2205, from ext (take r, iff.intro\n      (assume H, absurd (!lt.trans (and.elim_left H) (and.elim_right H)) !lt.irrefl)\n      (assume H, !not.elim !not_mem_empty H)),\n    exists.intro z (exists.intro z (and.intro Hz this))\n  else\n    have '(-\u221e, y) \u2229 '(x, \u221e) = \u2205, from ext(take r, iff.intro\n      (assume H, absurd (exists.intro r (iff.elim_left and.comm H)) H1)\n      (assume H, !not.elim !not_mem_empty H)),\n    exists.intro y (exists.intro x (and.intro (and.intro `x < y` `x < y`) this))\nend\n\nprotected definition T2_space.of_linorder_topology [trans_instance] :\n  T2_space X :=\n\u2983 T2_space, linorder_topology,\n  T2 := abstract\n         take x y, assume H,\n         or.elim (lt_or_gt_of_ne H)\n           (assume H,\n            obtain a [b Hab], from linorder_separation H,\n            show _, from exists.intro '(-\u221e, a) (exists.intro '(b, \u221e)\n              (and.intro Open_Iio (and.intro Open_Ioi (iff.elim_left and.assoc Hab)))))\n           (assume H,\n            obtain a [b Hab], from linorder_separation H,\n            have Hx : x \u2208 '(b, \u221e), from and.elim_right (and.elim_left Hab),\n            have Hy : y \u2208 '(-\u221e, a), from and.elim_left (and.elim_left Hab),\n            have Hi : '(b, \u221e) \u2229 '(-\u221e, a) = \u2205, from !inter_comm \u25b8 (and.elim_right Hab),\n            have (Open '(b,\u221e)) \u2227 (Open '(-\u221e, a)) \u2227 x \u2208 '(b, \u221e) \u2227 y \u2208 '(-\u221e, a) \u2227\n                   '(b, \u221e) \u2229 '(-\u221e, a) = \u2205, from\n             and.intro Open_Ioi (and.intro Open_Iio (and.intro Hx (and.intro Hy Hi))),\n           show _, from exists.intro '(b,\u221e) (exists.intro '(-\u221e, a) this))\n        end \u2984\n\nend order_topology\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/theories/topology/order_topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7385102981741271}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport data.finset.fold\nimport algebra.gcd_monoid.multiset\n\n/-!\n# GCD and LCM operations on finsets\n\n## Main definitions\n\n- `finset.gcd` - the greatest common denominator of a `finset` of elements of a `gcd_monoid`\n- `finset.lcm` - the least common multiple of a `finset` of elements of a `gcd_monoid`\n\n## Implementation notes\n\nMany of the proofs use the lemmas `gcd.def` and `lcm.def`, which relate `finset.gcd`\nand `finset.lcm` to `multiset.gcd` and `multiset.lcm`.\n\nTODO: simplify with a tactic and `data.finset.lattice`\n\n## Tags\n\nfinset, gcd\n-/\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\nnamespace finset\nopen multiset\n\nvariables [comm_cancel_monoid_with_zero \u03b1] [normalized_gcd_monoid \u03b1]\n\n/-! ### lcm -/\nsection lcm\n\n/-- Least common multiple of a finite set -/\ndef lcm (s : finset \u03b2) (f : \u03b2 \u2192 \u03b1) : \u03b1 := s.fold gcd_monoid.lcm 1 f\n\nvariables {s s\u2081 s\u2082 : finset \u03b2} {f : \u03b2 \u2192 \u03b1}\n\nlemma lcm_def : s.lcm f = (s.1.map f).lcm := rfl\n\n@[simp] \n\n@[simp] lemma lcm_dvd_iff {a : \u03b1} : s.lcm f \u2223 a \u2194 (\u2200b \u2208 s, f b \u2223 a) :=\nbegin\n  apply iff.trans multiset.lcm_dvd,\n  simp only [multiset.mem_map, and_imp, exists_imp_distrib],\n  exact \u27e8\u03bb k b hb, k _ _ hb rfl, \u03bb k a' b hb h, h \u25b8 k _ hb\u27e9,\nend\n\nlemma lcm_dvd {a : \u03b1} : (\u2200b \u2208 s, f b \u2223 a) \u2192 s.lcm f \u2223 a :=\nlcm_dvd_iff.2\n\nlemma dvd_lcm {b : \u03b2} (hb : b \u2208 s) : f b \u2223 s.lcm f :=\nlcm_dvd_iff.1 dvd_rfl _ hb\n\n@[simp] lemma lcm_insert [decidable_eq \u03b2] {b : \u03b2} :\n  (insert b s : finset \u03b2).lcm f = gcd_monoid.lcm (f b) (s.lcm f) :=\nbegin\n  by_cases h : b \u2208 s,\n  { rw [insert_eq_of_mem h,\n        (lcm_eq_right_iff (f b) (s.lcm f) (multiset.normalize_lcm (s.1.map f))).2 (dvd_lcm h)] },\n  apply fold_insert h,\nend\n\n@[simp] lemma lcm_singleton {b : \u03b2} : ({b} : finset \u03b2).lcm f = normalize (f b) :=\nmultiset.lcm_singleton\n\n@[simp] lemma normalize_lcm : normalize (s.lcm f) = s.lcm f := by simp [lcm_def]\n\nlemma lcm_union [decidable_eq \u03b2] : (s\u2081 \u222a s\u2082).lcm f = gcd_monoid.lcm (s\u2081.lcm f) (s\u2082.lcm f) :=\nfinset.induction_on s\u2081 (by rw [empty_union, lcm_empty, lcm_one_left, normalize_lcm]) $ \u03bb a s has ih,\n  by rw [insert_union, lcm_insert, lcm_insert, ih, lcm_assoc]\n\ntheorem lcm_congr {f g : \u03b2 \u2192 \u03b1} (hs : s\u2081 = s\u2082) (hfg : \u2200a \u2208 s\u2082, f a = g a) :\n  s\u2081.lcm f = s\u2082.lcm g :=\nby { subst hs, exact finset.fold_congr hfg }\n\nlemma lcm_mono_fun {g : \u03b2 \u2192 \u03b1} (h : \u2200 b \u2208 s, f b \u2223 g b) : s.lcm f \u2223 s.lcm g :=\nlcm_dvd (\u03bb b hb, (h b hb).trans (dvd_lcm hb))\n\nlemma lcm_mono (h : s\u2081 \u2286 s\u2082) : s\u2081.lcm f \u2223 s\u2082.lcm f :=\nlcm_dvd $ assume b hb, dvd_lcm (h hb)\n\ntheorem lcm_eq_zero_iff [nontrivial \u03b1] : s.lcm f = 0 \u2194 0 \u2208 f '' s :=\nby simp only [multiset.mem_map, lcm_def, multiset.lcm_eq_zero_iff, set.mem_image, mem_coe,\n  \u2190 finset.mem_def]\n\nend lcm\n\n/-! ### gcd -/\nsection gcd\n\n/-- Greatest common divisor of a finite set -/\ndef gcd (s : finset \u03b2) (f : \u03b2 \u2192 \u03b1) : \u03b1 := s.fold gcd_monoid.gcd 0 f\n\nvariables {s s\u2081 s\u2082 : finset \u03b2} {f : \u03b2 \u2192 \u03b1}\n\nlemma gcd_def : s.gcd f = (s.1.map f).gcd := rfl\n\n@[simp] lemma gcd_empty : (\u2205 : finset \u03b2).gcd f = 0 :=\nfold_empty\n\nlemma dvd_gcd_iff {a : \u03b1} : a \u2223 s.gcd f \u2194 \u2200b \u2208 s, a \u2223 f b :=\nbegin\n  apply iff.trans multiset.dvd_gcd,\n  simp only [multiset.mem_map, and_imp, exists_imp_distrib],\n  exact \u27e8\u03bb k b hb, k _ _ hb rfl, \u03bb k a' b hb h, h \u25b8 k _ hb\u27e9,\nend\n\nlemma gcd_dvd {b : \u03b2} (hb : b \u2208 s) : s.gcd f \u2223 f b :=\ndvd_gcd_iff.1 dvd_rfl _ hb\n\nlemma dvd_gcd {a : \u03b1} : (\u2200b \u2208 s, a \u2223 f b) \u2192 a \u2223 s.gcd f :=\ndvd_gcd_iff.2\n\n@[simp] lemma gcd_insert [decidable_eq \u03b2] {b : \u03b2} :\n  (insert b s : finset \u03b2).gcd f = gcd_monoid.gcd (f b) (s.gcd f) :=\nbegin\n  by_cases h : b \u2208 s,\n  { rw [insert_eq_of_mem h,\n    (gcd_eq_right_iff (f b) (s.gcd f) (multiset.normalize_gcd (s.1.map f))).2 (gcd_dvd h)] ,},\n  apply fold_insert h,\nend\n\n@[simp] lemma gcd_singleton {b : \u03b2} : ({b} : finset \u03b2).gcd f = normalize (f b) :=\nmultiset.gcd_singleton\n\n@[simp] lemma normalize_gcd : normalize (s.gcd f) = s.gcd f := by simp [gcd_def]\n\nlemma gcd_union [decidable_eq \u03b2] : (s\u2081 \u222a s\u2082).gcd f = gcd_monoid.gcd (s\u2081.gcd f) (s\u2082.gcd f) :=\nfinset.induction_on s\u2081 (by rw [empty_union, gcd_empty, gcd_zero_left, normalize_gcd]) $\n  \u03bb a s has ih, by rw [insert_union, gcd_insert, gcd_insert, ih, gcd_assoc]\n\ntheorem gcd_congr {f g : \u03b2 \u2192 \u03b1} (hs : s\u2081 = s\u2082) (hfg : \u2200a \u2208 s\u2082, f a = g a) :\n  s\u2081.gcd f = s\u2082.gcd g :=\nby { subst hs, exact finset.fold_congr hfg }\n\nlemma gcd_mono_fun {g : \u03b2 \u2192 \u03b1} (h : \u2200 b \u2208 s, f b \u2223 g b) : s.gcd f \u2223 s.gcd g :=\ndvd_gcd (\u03bb b hb, (gcd_dvd hb).trans (h b hb))\n\nlemma gcd_mono (h : s\u2081 \u2286 s\u2082) : s\u2082.gcd f \u2223 s\u2081.gcd f :=\ndvd_gcd $ assume b hb, gcd_dvd (h hb)\n\ntheorem gcd_image {g : \u03b3 \u2192 \u03b2} (s: finset \u03b3) [decidable_eq \u03b2] [is_idempotent \u03b1 gcd_monoid.gcd] :\n  (s.image g).gcd f = s.gcd (f \u2218 g) := by simp [gcd, fold_image_idem]\n\ntheorem gcd_eq_gcd_image [decidable_eq \u03b1] [is_idempotent \u03b1 gcd_monoid.gcd] :\n  s.gcd f = (s.image f).gcd id := (@gcd_image _ _ _ _ _ id _ _ _ _).symm\n\ntheorem gcd_eq_zero_iff : s.gcd f = 0 \u2194 \u2200 (x : \u03b2), x \u2208 s \u2192 f x = 0 :=\nbegin\n  rw [gcd_def, multiset.gcd_eq_zero_iff],\n  split; intro h,\n  { intros b bs,\n    apply h (f b),\n    simp only [multiset.mem_map, mem_def.1 bs],\n    use b,\n    simp [mem_def.1 bs] },\n  { intros a as,\n    rw multiset.mem_map at as,\n    rcases as with \u27e8b, \u27e8bs, rfl\u27e9\u27e9,\n    apply h b (mem_def.1 bs) }\nend\n\nlemma gcd_eq_gcd_filter_ne_zero [decidable_pred (\u03bb (x : \u03b2), f x = 0)] :\n  s.gcd f = (s.filter (\u03bb x, f x \u2260 0)).gcd f :=\nbegin\n  classical,\n  transitivity ((s.filter (\u03bb x, f x = 0)) \u222a (s.filter (\u03bb x, f x \u2260 0))).gcd f,\n  { rw filter_union_filter_neg_eq },\n  rw gcd_union,\n  transitivity gcd_monoid.gcd (0 : \u03b1) _,\n  { refine congr (congr rfl _) rfl,\n    apply s.induction_on, { simp },\n    intros a s has h,\n    rw filter_insert,\n    split_ifs with h1; simp [h, h1], },\n  simp [gcd_zero_left, normalize_gcd],\nend\n\nlemma gcd_mul_left {a : \u03b1} : s.gcd (\u03bb x, a * f x) = normalize a * s.gcd f :=\nbegin\n  classical,\n  apply s.induction_on,\n  { simp },\n  intros b t hbt h,\n  rw [gcd_insert, gcd_insert, h, \u2190 gcd_mul_left],\n  apply ((normalize_associated a).mul_right _).gcd_eq_right\nend\n\nlemma gcd_mul_right {a : \u03b1} : s.gcd (\u03bb x, f x * a) = s.gcd f * normalize a :=\nbegin\n  classical,\n  apply s.induction_on,\n  { simp },\n  intros b t hbt h,\n  rw [gcd_insert, gcd_insert, h, \u2190 gcd_mul_right],\n  apply ((normalize_associated a).mul_left _).gcd_eq_right\nend\n\nend gcd\nend finset\n\nnamespace finset\nsection is_domain\n\nvariables [comm_ring \u03b1] [is_domain \u03b1] [normalized_gcd_monoid \u03b1]\n\nlemma gcd_eq_of_dvd_sub {s : finset \u03b2} {f g : \u03b2 \u2192 \u03b1} {a : \u03b1}\n  (h : \u2200 x : \u03b2, x \u2208 s \u2192 a \u2223 f x - g x) :\n  gcd_monoid.gcd a (s.gcd f) = gcd_monoid.gcd a (s.gcd g) :=\nbegin\n  classical,\n  revert h,\n  apply s.induction_on,\n  { simp },\n  intros b s bs hi h,\n  rw [gcd_insert, gcd_insert, gcd_comm (f b), \u2190 gcd_assoc, hi (\u03bb x hx, h _ (mem_insert_of_mem hx)),\n      gcd_comm a, gcd_assoc, gcd_comm a (gcd_monoid.gcd _ _),\n      gcd_comm (g b), gcd_assoc _ _ a, gcd_comm _ a],\n  exact congr_arg _ (gcd_eq_of_dvd_sub_right (h _ (mem_insert_self _ _)))\nend\n\nend is_domain\n\nend finset\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/gcd_monoid/finset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7385094345048797}}
{"text": "-- Imagen_inversa_de_la_union_general.lean\n-- Imagen inversa de la uni\u00f3n general\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 26 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {I : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables B : I \u2192 set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    rw mem_preimage at hx,\n    rw mem_Union at hx,\n    cases hx with i fxBi,\n    rw mem_Union,\n    use i,\n    apply mem_preimage.mpr,\n    exact fxBi, },\n  { intro hx,\n    rw mem_preimage,\n    rw mem_Union,\n    rw mem_Union at hx,\n    cases hx with i xBi,\n    use i,\n    rw mem_preimage at xBi,\n    exact xBi, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\npreimage_Union\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\nby  simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Imagen_inversa_de_la_union_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7385094340636706}}
{"text": "import ...inClassNotes.langs.arith_expr\n\nvariables (P Q R : Prop)\n\n/-\nExcluded middle [25 points]\n-/\n\n-- A. 5 points\n\nexample : (\u00acP \u2228 \u00acQ) \u2192 \u00ac(P \u2227 Q) :=\nbegin\nassume h,\ncases h,\nassume k,\nexact h k.left,\nassume k,\nexact h k.right,\nend\n\n\n-- B. 15 points\n\nexample : \u00ac(P \u2227 Q) \u2192 (\u00acP \u2228 \u00acQ) :=\nbegin\nassume h,\ncases (classical.em P),\ncases (classical.em Q),\nexact false.elim (h (and.intro h_1 h_2)),\nexact or.inr h_2,\nexact or.inl h_1,\nend\n\n\n-- C. 5 Points. What do these examples teach \n-- us about DeMorgan's Laws in constructive logic?\n\n/-\n-/\n\n/-\nRecursive definitions (practice) [20 points]\n-/\n\n\n/- 15 points\nA. Write a function, le : nat \u2192 nat \u2192 bool,\nthat returns true if the first argument is\n*less than or equal to* the second, and false\notherwise. Hints: case analysis, recursion.\n-/\n\ndef leq : nat \u2192 nat \u2192 bool\n| 0 n := tt\n| (n'+1) 0 := ff\n| (n'+1)(m'+1) := leq n' m'\n\n\n/- 10 points\nB. Write a function, eqn : nat \u2192 nat \u2192 bool,\nthat returns true if the first argument is\n*equal to* the second, and false otherwise.\nHints: case analysis, recursion.\n-/\n\ndef eql : nat \u2192 nat \u2192 bool\n| 0 0 := tt\n| _ 0 := ff\n| 0 _ := ff\n| (n'+1)(m'+1) := eql n' m'\n\n\n/-\nBetter Boolean expressions [25 points]\n\nConsolidate our definitions of the syntax and\nsemantics of Boolean and arithmetic expressions\ninto a system. Leave each algebra implemented\nin its own file. Now define two new forms of\nBoolean expression, as follows:\n\n(1) if N and M are arithmetic variable\nexpressions, tben leq_expr N M is a Boolean\nexpression. It should evaluate to Boolean\ntrue (tt) if and ony if N evaluates to a\nnumber that is less than or equal to M,\nusing your leq function from the previous\nproblem.\n\n(2) if N and M are arithmetic variable\nexpressions, then eql_expr N M is also\na Boolean expression: one that evaluates\nto tt if and only if N evaluates to a \nnatural number (nat) that is equal to \nthe number to which M evaluates, using\nyour eql function.\n\nSubmit your work as a pair of files,\nwith the bool file importing from the\narithmetic file to obtain support for\narithmetic expressions. Follow naming\nconventions established in the files\nwe developed in class. Submit the two\nfiles in addition to your completed\nversion of this file.\n-/\n\n\n\n/-\nMutable state and assignment [25 points]\n\nIn this problem, we will contine to represent \na state, as we have in our previous work, as \na function from variables (objects of a type,\nvar) to values (here of type nat). \n-/\n\nstructure Var : Type := (index : nat)\ndef State := Var \u2192 nat\ndef eqVar (v1 v2 : Var) : bool := v1.index = v2.index\n\n/-\nOne of the profound differences between\nimperative and functional programming is \nthat in the former--in languages such as\nPython and C--one assumes and is given a\n*mutable* global state. That is not the\ncase in functional programming. While we\ncan bind variable names to values once, we\ncannot update the values bound to variables\nas computations progress. \n\nWhen programming in an imperative language,\nby contrast, one has operations for free to\nobtain the value associated with (to read)\na variable, and to override the value that\nis associated with a variable (to write to\nit). We call the write operation assignment.\n\nTo confuse humans who already understand\narithmetic, the designers of languages such\nas Basic, C, Java, and Python use = as a \nconcrete notation to invoke the assignment\noperation. (It's only indirectly related to\nthe concept of equality from basic math.)\n\nThus in such languages we might write code\nlike this:\n\nX = 1\n\nIgnoring the terrible choice of notation\nfor what you can think of as a procedure\ninvocation (assign X 1), what this really \nmeans is *update the state so that the \nvalue of the variable X is now bound to 1.\n\nWhat's missing from our X = 1 diagram,\nthough, is a representation of the states!\nHere's a better picture, one that clearly\nillustrates the *effect* of an assignment\noperation on a state in one scenario. \n\n{ (X, 0), (Y, 1), (Z, 2) }\nX = 1\n{ (X, 1), (Y, 1), (Z, 2) }\n\nIn this case, the state before the assignment \nwas given by the function, \n  st = { (X, 0), (Y, 1), (Z, 2) }, while after\nthe assignment operation it was \n  st' = { (X, 1), (Y, 1), (Z, 2) }.\nNotice that st' differs from st only for X, and\nthe new value associated with X is the one that\nwe \"assigned\" to it.\n\nNow read this carefully. We can now represent\nan assignment operation in Lean as a function:\none that takes a state, st, a variable, v, and\na value, k, and that returns a state, st', that\ndiffers from st only to the extent that in st',\nv is bound to k, whereas every other variable \nremains bound to the value it had in st.\n-/\n\ndef assign (st : State) (v : Var) (k : nat) : State :=\n\u03bb v', if (v.index = v'.index) then k else st v'\n\n\n/-\nExamples\n-/\n\ndef allz : State := \u03bb v, 0\n\n#reduce allz\n\n\ndef X := Var.mk 0\ndef Y := Var.mk 1\ndef Z := Var.mk 2\n\n/-\n-- start in initial state\nX = 7;\nY = 8;\nZ = 9;\n-/\ndef st := \n  assign \n    (assign \n      (assign \n        allz \n        X \n        7\n      ) \n      Y \n      8\n    ) \n    Z \n    9\n\n#eval st X\n#eval st Y\n#eval st Z\n\n-- Exercise: assign 10 to X after all that, call new state st'\n\ndef st' : State := _\n\n#eval st' X\n#eval st' Y\n#eval st' Z\n\ninductive cmd : Type\n| assn (v : Var) (a : aexp)\n| seq (c1 c2 : cmd) \n\nopen cmd\n\nnotation v = aexp := assn v aexp \nnotation c1 ; c2 := seq c1 c2\n\ndef a1 : cmd := X = [7]\ndef a2 : cmd := Y = [8]\ndef a3 : cmd := Z = [9]\ndef a4 : cmd := X = [10]\n\n-- Need a way to compose these commands!\n\ndef c := a1; a2; a3; a4\n\n\n\n#reduce st \n/-\n-- a function that takes an argument, v', of type Var, and that returns its value\n\u03bb (v' : Var),\n  decidable.rec\n\n    -- case 1: if v' \u2260 Z the return result of applying the function before the override\n    (\u03bb (hnc : 2 = v'.index \u2192 false),\n       decidable.rec\n\n          -- case A: v' \u2260 Y\n         (\u03bb (hnc : 1 = v'.index \u2192 false),\n            decidable.rec \n              \n              -- case a: v' \u2260 X\n              (\u03bb (hnc : 0 = v'.index \u2192 false), 0) \n\n              -- case b: v' = X\n              (\u03bb (hc : 0 = v'.index), 7)\n\n              -- v' =? X decidable\n              (nat.decidable_eq 0 v'.index))\n\n          -- case B: v' = Y\n         (\u03bb (hc : 1 = v'.index), 8)\n         (nat.decidable_eq 1 v'.index))\n\n    -- case 2: if v' = Z then return the overriding value \n    (\u03bb (hc : 2 = v'.index), 9)\n    (nat.decidable_eq 2 v'.index)\n-/\n#check @decidable_eq\n#check @nat.decidable_eq\n\n/-\n In English, this is the state obtained by\n starting with an all-zeros state and then\n overriding X with 1, then overriding Y with\n 5 in that state, and then overriding the\n result of that with Z 4.\n -/\n /-\n How is that concept of state implemented \n using decidable.rec, answers, functions,\n or values? [?]\n -/\n/-\nHere's decidable.rec.\n-/\n#check @decidable\n/-\nclass inductive decidable (p : Prop)\n| is_false (h : \u00acp) : decidable\n| is_true  (h : p) : decidable\n-/\n#check @decidable.rec\n/-\n-- For any proposition, p, and a function \n-- from either a proof of p or a proof of\n-- not p to a type inhabiting Sort u_1,\n\u03a0 {p : Prop} {C : decidable p \u2192 Sort u_1},\n\n-- assume we have a function that takes a\n-- proof, h, that p is false, and returns\n-- C applied to the proof that p is false, \n    (\u03a0 (h : \u00acp), C (is_false h)) \u2192 \n-- assume we have a function that takes a\n-- proof, h, that p is true, and returns\n-- C applied to the proof that p is true, \n\n    (\u03a0 (h : p), C (is_true h)) \u2192 \n-- then for any (n : decidable p), or in\n-- other words for either an is_true proof\n-- or an is_false proof, there is a value\n-- of type C n\n\u03a0 (n : decidable p), C n\n\n-- In other words, if you've given a value\n-- for the true case and one for the false\n-- case then you've covered all the cases,\n-- and for each case you have a function to\n-- convert a proof for that case into a type.\n[SEEMS_WRONG]\n-/\n\n", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/assignments/assignment_9/assignment_9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7385094136702863}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.reverse\nimport algebra.associated\n\n/-!\n# Theory of monic polynomials\n\nWe give several tools for proving that polynomials are monic, e.g.\n`monic_mul`, `monic_map`.\n-/\n\nnoncomputable theory\nlocal attribute [instance, priority 100] classical.prop_decidable\n\nopen finset\nopen_locale big_operators\n\nnamespace polynomial\nuniverses u v y\nvariables {R : Type u} {S : Type v} {a b : R} {m n : \u2115} {\u03b9 : Type y}\n\nsection semiring\nvariables [semiring R] {p q r : polynomial R}\n\nlemma monic.as_sum {p : polynomial R} (hp : p.monic) :\n  p = X^(p.nat_degree) + (\u2211 i in range p.nat_degree, C (p.coeff i) * X^i) :=\nbegin\n  conv_lhs { rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] },\n  suffices : C (p.coeff p.nat_degree) = 1,\n  { rw [this, one_mul] },\n  exact congr_arg C hp\nend\n\nlemma ne_zero_of_monic_of_zero_ne_one (hp : monic p) (h : (0 : R) \u2260 1) :\n  p \u2260 0 := mt (congr_arg leading_coeff) $ by rw [monic.def.1 hp, leading_coeff_zero]; cc\n\nlemma ne_zero_of_ne_zero_of_monic (hp : p \u2260 0) (hq : monic q) : q \u2260 0 :=\nbegin\n  intro h, rw [h, monic.def, leading_coeff_zero] at hq,\n  rw [\u2190 mul_one p, \u2190 C_1, \u2190 hq, C_0, mul_zero] at hp,\n  exact hp rfl\nend\n\nlemma monic_map [semiring S] (f : R \u2192+* S) (hp : monic p) : monic (p.map f) :=\nif h : (0 : S) = 1 then\n  by haveI := subsingleton_of_zero_eq_one h;\n  exact subsingleton.elim _ _\nelse\nhave f (leading_coeff p) \u2260 0,\n  by rwa [show _ = _, from hp, is_semiring_hom.map_one f, ne.def, eq_comm],\nby\nbegin\n  rw [monic, leading_coeff, coeff_map],\n  suffices : p.coeff (map f p).nat_degree = 1, simp [this],\n  suffices : (map f p).nat_degree = p.nat_degree, rw this, exact hp,\n  rwa nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero _ _),\nend\n\nlemma monic_mul_C_of_leading_coeff_mul_eq_one [nontrivial R] {b : R}\n  (hp : p.leading_coeff * b = 1) : monic (p * C b) :=\nby rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp]\n\ntheorem monic_of_degree_le (n : \u2115) (H1 : degree p \u2264 n) (H2 : coeff p n = 1) : monic p :=\ndecidable.by_cases\n  (assume H : degree p < n, eq_of_zero_eq_one\n    (H2 \u25b8 (coeff_eq_zero_of_degree_lt H).symm) _ _)\n  (assume H : \u00acdegree p < n,\n    by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H])\n\ntheorem monic_X_pow_add {n : \u2115} (H : degree p \u2264 n) : monic (X ^ (n+1) + p) :=\nhave H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)),\nmonic_of_degree_le (n+1)\n  (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1)))\n  (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero])\n\ntheorem monic_X_add_C (x : R) : monic (X + C x) :=\npow_one (X : polynomial R) \u25b8 monic_X_pow_add degree_C_le\n\nlemma monic_mul (hp : monic p) (hq : monic q) : monic (p * q) :=\nif h0 : (0 : R) = 1 then by haveI := subsingleton_of_zero_eq_one h0;\n  exact subsingleton.elim _ _\nelse\n  have leading_coeff p * leading_coeff q \u2260 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0],\n  by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul]\n\nlemma monic_pow (hp : monic p) : \u2200 (n : \u2115), monic (p ^ n)\n| 0     := monic_one\n| (n+1) := by { rw pow_succ, exact monic_mul hp (monic_pow n) }\n\nlemma monic_add_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :\n  monic (p + q) :=\nby rwa [monic, add_comm, leading_coeff_add_of_degree_lt hpq]\n\nlemma monic_add_of_right {p q : polynomial R} (hq : monic q) (hpq : degree p < degree q) :\n  monic (p + q) :=\nby rwa [monic, leading_coeff_add_of_degree_lt hpq]\n\nnamespace monic\n\n@[simp]\nlemma degree_eq_zero_iff_eq_one {p : polynomial R} (hp : p.monic) :\n  p.nat_degree = 0 \u2194 p = 1 :=\nbegin\n  split; intro h,\n  swap, { rw h, exact nat_degree_one },\n  have : p = C (p.coeff 0),\n  { rw \u2190 polynomial.degree_le_zero_iff,\n    rwa polynomial.nat_degree_eq_zero_iff_degree_le_zero at h },\n  rw this, convert C_1, rw \u2190 h, apply hp,\nend\n\nlemma nat_degree_mul {p q : polynomial R} (hp : p.monic) (hq : q.monic) :\n  (p * q).nat_degree = p.nat_degree + q.nat_degree :=\nbegin\n  nontriviality R,\n  apply nat_degree_mul',\n  simp [hp.leading_coeff, hq.leading_coeff]\nend\n\nlemma next_coeff_mul {p q : polynomial R} (hp : monic p) (hq : monic q) :\n  next_coeff (p * q) = next_coeff p + next_coeff q :=\nbegin\n  nontriviality,\n  simp only [\u2190 coeff_one_reverse],\n  rw reverse_mul;\n    simp [coeff_mul, nat.antidiagonal, hp.leading_coeff, hq.leading_coeff, add_comm]\nend\n\nend monic\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R] {p : polynomial R}\n\nlemma monic_multiset_prod_of_monic (t : multiset \u03b9) (f : \u03b9 \u2192 polynomial R)\n  (ht : \u2200 i \u2208 t, monic (f i)) :\n  monic (t.map f).prod :=\nbegin\n  revert ht,\n  refine t.induction_on _ _, { simp },\n  intros a t ih ht,\n  rw [multiset.map_cons, multiset.prod_cons],\n  exact monic_mul\n    (ht _ (multiset.mem_cons_self _ _))\n    (ih (\u03bb _ hi, ht _ (multiset.mem_cons_of_mem hi)))\nend\n\nlemma monic_prod_of_monic (s : finset \u03b9) (f : \u03b9 \u2192 polynomial R) (hs : \u2200 i \u2208 s, monic (f i)) :\n  monic (\u220f i in s, f i) :=\nmonic_multiset_prod_of_monic s.1 f hs\n\nlemma is_unit_C {x : R} : is_unit (C x) \u2194 is_unit x :=\nbegin\n  rw [is_unit_iff_dvd_one, is_unit_iff_dvd_one],\n  split,\n  { rintros \u27e8g, hg\u27e9,\n    replace hg := congr_arg (eval 0) hg,\n    rw [eval_one, eval_mul, eval_C] at hg,\n    exact \u27e8g.eval 0, hg\u27e9 },\n  { rintros \u27e8y, hy\u27e9,\n    exact \u27e8C y, by rw [\u2190 C_mul, \u2190 hy, C_1]\u27e9 }\nend\n\nlemma eq_one_of_is_unit_of_monic (hm : monic p) (hpu : is_unit p) : p = 1 :=\nhave degree p \u2264 0,\n  from calc degree p \u2264 degree (1 : polynomial R) :\n    let \u27e8u, hu\u27e9 := is_unit_iff_dvd_one.1 hpu in\n    if hu0 : u = 0\n    then begin\n        rw [hu0, mul_zero] at hu,\n        rw [\u2190 mul_one p, hu, mul_zero],\n        simp\n      end\n    else have p.leading_coeff * u.leading_coeff \u2260 0,\n        by rw [hm.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero];\n          exact hu0,\n      by rw [hu, degree_mul' this];\n        exact le_add_of_nonneg_right (degree_nonneg_iff_ne_zero.2 hu0)\n  ... \u2264 0 : degree_one_le,\nby rw [eq_C_of_degree_le_zero this, \u2190 nat_degree_eq_zero_iff_degree_le_zero.2 this,\n    \u2190 leading_coeff, hm.leading_coeff, C_1]\n\nlemma monic.next_coeff_multiset_prod (t : multiset \u03b9) (f : \u03b9 \u2192 polynomial R)\n  (h : \u2200 i \u2208 t, monic (f i)) :\n  next_coeff (t.map f).prod = (t.map (\u03bb i, next_coeff (f i))).sum :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _),\n  { simp only [multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, multiset.map_zero,\n               multiset.prod_zero, multiset.sum_zero, not_false_iff, forall_true_iff],\n    rw \u2190 C_1, rw next_coeff_C_eq_zero },\n  { rw [multiset.map_cons, multiset.prod_cons, multiset.map_cons, multiset.sum_cons,\n        monic.next_coeff_mul, ih],\n    exacts [\u03bb i hi, ht i (multiset.mem_cons_of_mem hi), ht a (multiset.mem_cons_self _ _),\n            monic_multiset_prod_of_monic _ _ (\u03bb b bs, ht _ (multiset.mem_cons_of_mem bs))] }\nend\n\nlemma monic.next_coeff_prod (s : finset \u03b9) (f : \u03b9 \u2192 polynomial R) (h : \u2200 i \u2208 s, monic (f i)) :\n  next_coeff (\u220f i in s, f i) = \u2211 i in s, next_coeff (f i) :=\nmonic.next_coeff_multiset_prod s.1 f h\n\nend comm_semiring\n\nsection ring\nvariables [ring R] {p : polynomial R}\n\ntheorem monic_X_sub_C (x : R) : monic (X - C x) :=\nby simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)\n\ntheorem monic_X_pow_sub {n : \u2115} (H : degree p \u2264 n) : monic (X ^ (n+1) - p) :=\nby simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) \u2264 n, by rwa \u2190degree_neg p at H)\n\n/-- `X ^ n - a` is monic. -/\nlemma monic_X_pow_sub_C {R : Type u} [ring R] (a : R) {n : \u2115} (h : n \u2260 0) : (X ^ n - C a).monic :=\nbegin\n  obtain \u27e8k, hk\u27e9 := nat.exists_eq_succ_of_ne_zero h,\n  convert monic_X_pow_sub _,\n  exact le_trans degree_C_le nat.with_bot.coe_nonneg,\nend\n\nlemma monic_sub_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :\n  monic (p - q) :=\nby { rw sub_eq_add_neg, apply monic_add_of_left hp, rwa degree_neg }\n\nlemma monic_sub_of_right {p q : polynomial R}\n  (hq : q.leading_coeff = -1) (hpq : degree p < degree q) : monic (p - q) :=\nhave (-q).coeff (-q).nat_degree = 1 :=\nby rw [nat_degree_neg, coeff_neg, show q.coeff q.nat_degree = -1, from hq, neg_neg],\nby { rw sub_eq_add_neg, apply monic_add_of_right this, rwa degree_neg }\n\nsection injective\nopen function\nvariables [semiring S] {f : R \u2192+* S} (hf : injective f)\ninclude hf\n\n\nlemma leading_coeff_of_injective (p : polynomial R) :\n  leading_coeff (p.map f) = f (leading_coeff p) :=\nbegin\n  delta leading_coeff,\n  rw [coeff_map f, nat_degree_map' hf p]\nend\n\nlemma monic_of_injective {p : polynomial R} (hp : (p.map f).monic) : p.monic :=\nbegin\n  apply hf,\n  rw [\u2190 leading_coeff_of_injective hf, hp.leading_coeff, is_semiring_hom.map_one f]\nend\n\nend injective\nend ring\n\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : polynomial R}\n\n@[simp] lemma not_monic_zero : \u00acmonic (0 : polynomial R) :=\nby simpa only [monic, leading_coeff_zero] using (zero_ne_one : (0 : R) \u2260 1)\n\nlemma ne_zero_of_monic (h : monic p) : p \u2260 0 :=\n\u03bb h\u2081, @not_monic_zero R _ _ (h\u2081 \u25b8 h)\n\nend nonzero_semiring\n\n\nend polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/polynomial/monic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7385094108808922}}
{"text": "/-\nCopyright (c) 2022 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n-/\nimport algebra.is_prime_pow\nimport data.nat.factorization.basic\n\n/-!\n# Prime powers and factorizations\n\nThis file deals with factorizations of prime powers.\n-/\n\nvariables {R : Type*} [comm_monoid_with_zero R] (n p : R) (k : \u2115)\n\nlemma is_prime_pow.min_fac_pow_factorization_eq {n : \u2115} (hn : is_prime_pow n) :\n  n.min_fac ^ n.factorization n.min_fac = n :=\nbegin\n  obtain \u27e8p, k, hp, hk, rfl\u27e9 := hn,\n  rw \u2190nat.prime_iff at hp,\n  rw [hp.pow_min_fac hk.ne', hp.factorization_pow, finsupp.single_eq_same],\nend\n\nlemma is_prime_pow_of_min_fac_pow_factorization_eq {n : \u2115}\n  (h : n.min_fac ^ n.factorization n.min_fac = n) (hn : n \u2260 1) :\n  is_prime_pow n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn',\n  { simpa using h },\n  refine \u27e8_, _, nat.prime_iff.1 (nat.min_fac_prime hn), _, h\u27e9,\n  rw [pos_iff_ne_zero, \u2190finsupp.mem_support_iff, nat.factor_iff_mem_factorization,\n    nat.mem_factors_iff_dvd hn' (nat.min_fac_prime hn)],\n  apply nat.min_fac_dvd\nend\n\nlemma is_prime_pow_iff_min_fac_pow_factorization_eq {n : \u2115} (hn : n \u2260 1) :\n  is_prime_pow n \u2194 n.min_fac ^ n.factorization n.min_fac = n :=\n\u27e8\u03bb h, h.min_fac_pow_factorization_eq, \u03bb h, is_prime_pow_of_min_fac_pow_factorization_eq h hn\u27e9\n\nlemma is_prime_pow_iff_factorization_eq_single {n : \u2115} :\n  is_prime_pow n \u2194 \u2203 p k : \u2115, 0 < k \u2227 n.factorization = finsupp.single p k :=\nbegin\n  rw is_prime_pow_nat_iff,\n  refine exists\u2082_congr (\u03bb p k, _),\n  split,\n  { rintros \u27e8hp, hk, hn\u27e9,\n    exact \u27e8hk, by rw [\u2190hn, nat.prime.factorization_pow hp]\u27e9 },\n  { rintros \u27e8hk, hn\u27e9,\n    have hn0 : n \u2260 0,\n    { rintro rfl,\n      simpa only [finsupp.single_eq_zero, eq_comm, nat.factorization_zero, hk.ne'] using hn },\n    rw nat.eq_pow_of_factorization_eq_single hn0 hn,\n    exact \u27e8nat.prime_of_mem_factorization\n      (by simp [hn, hk.ne'] : p \u2208 n.factorization.support), hk, rfl\u27e9 }\nend\n\nlemma is_prime_pow_iff_card_support_factorization_eq_one {n : \u2115} :\n  is_prime_pow n \u2194 n.factorization.support.card = 1 :=\nby simp_rw [is_prime_pow_iff_factorization_eq_single, finsupp.card_support_eq_one', exists_prop,\n  pos_iff_ne_zero]\n\n/-- An equivalent definition for prime powers: `n` is a prime power iff there is a unique prime\ndividing it. -/\nlemma is_prime_pow_iff_unique_prime_dvd {n : \u2115} :\n  is_prime_pow n \u2194 \u2203! p : \u2115, p.prime \u2227 p \u2223 n :=\nbegin\n  rw is_prime_pow_nat_iff,\n  split,\n  { rintro \u27e8p, k, hp, hk, rfl\u27e9,\n    refine \u27e8p, \u27e8hp, dvd_pow_self _ hk.ne'\u27e9, _\u27e9,\n    rintro q \u27e8hq, hq'\u27e9,\n    exact (nat.prime_dvd_prime_iff_eq hq hp).1 (hq.dvd_of_dvd_pow hq') },\n  rintro \u27e8p, \u27e8hp, hn\u27e9, hq\u27e9,\n  -- Take care of the n = 0 case\n  rcases eq_or_ne n 0 with rfl | hn\u2080,\n  { obtain \u27e8q, hq', hq''\u27e9 := nat.exists_infinite_primes (p + 1),\n    cases hq q \u27e8hq'', by simp\u27e9,\n    simpa using hq' },\n  -- So assume 0 < n\n  refine \u27e8p, n.factorization p, hp, hp.factorization_pos_of_dvd hn\u2080 hn, _\u27e9,\n  simp only [and_imp] at hq,\n  apply nat.dvd_antisymm (nat.pow_factorization_dvd _ _),\n  -- We need to show n \u2223 p ^ n.factorization p\n  apply nat.dvd_of_factors_subperm hn\u2080,\n  rw [hp.factors_pow, list.subperm_ext_iff],\n  intros q hq',\n  rw nat.mem_factors hn\u2080 at hq',\n  cases hq _ hq'.1 hq'.2,\n  simp,\nend\n\nlemma is_prime_pow_pow_iff {n k : \u2115} (hk : k \u2260 0) :\n  is_prime_pow (n ^ k) \u2194 is_prime_pow n :=\nbegin\n  simp only [is_prime_pow_iff_unique_prime_dvd],\n  apply exists_unique_congr,\n  simp only [and.congr_right_iff],\n  intros p hp,\n  exact \u27e8hp.dvd_of_dvd_pow, \u03bb t, t.trans (dvd_pow_self _ hk)\u27e9,\nend\n\nlemma nat.coprime.is_prime_pow_dvd_mul {n a b : \u2115} (hab : nat.coprime a b) (hn : is_prime_pow n) :\n  n \u2223 a * b \u2194 n \u2223 a \u2228 n \u2223 b :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simp only [nat.coprime_zero_left] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  rcases eq_or_ne b 0 with rfl | hb,\n  { simp only [nat.coprime_zero_right] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  refine \u27e8_, \u03bb h, or.elim h (\u03bb i, i.trans (dvd_mul_right _ _)) (\u03bb i, i.trans (dvd_mul_left _ _))\u27e9,\n  obtain \u27e8p, k, hp, hk, rfl\u27e9 := (is_prime_pow_nat_iff _).1 hn,\n  simp only [hp.pow_dvd_iff_le_factorization (mul_ne_zero ha hb),\n    nat.factorization_mul ha hb, hp.pow_dvd_iff_le_factorization ha,\n    hp.pow_dvd_iff_le_factorization hb, pi.add_apply, finsupp.coe_add],\n  have : a.factorization p = 0 \u2228 b.factorization p = 0,\n  { rw [\u2190finsupp.not_mem_support_iff, \u2190finsupp.not_mem_support_iff, \u2190not_and_distrib,\n      \u2190finset.mem_inter],\n    exact \u03bb t, nat.factorization_disjoint_of_coprime hab t },\n  cases this;\n  simp [this, imp_or_distrib],\nend\n\nlemma nat.mul_divisors_filter_prime_pow {a b : \u2115} (hab : a.coprime b) :\n  (a * b).divisors.filter is_prime_pow = (a.divisors \u222a b.divisors).filter is_prime_pow :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simp only [nat.coprime_zero_left] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  rcases eq_or_ne b 0 with rfl | hb,\n  { simp only [nat.coprime_zero_right] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  ext n,\n  simp only [ha, hb, finset.mem_union, finset.mem_filter, nat.mul_eq_zero, and_true, ne.def,\n    and.congr_left_iff, not_false_iff, nat.mem_divisors, or_self],\n  apply hab.is_prime_pow_dvd_mul,\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/nat/factorization/prime_pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7384919374958722}}
{"text": "/-\nCopyright (c) 2014 Parikshit Khanna. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro\n-/\nimport data.list.big_operators\n\n/-!\n# Counting in lists\n\nThis file proves basic properties of `list.countp` and `list.count`, which count the number of\nelements of a list satisfying a predicate and equal to a given element respectively. Their\ndefinitions can be found in [`data.list.defs`](./defs).\n-/\n\nopen nat\n\nvariables {\u03b1 \u03b2 : Type*} {l l\u2081 l\u2082 : list \u03b1}\n\nnamespace list\n\nsection countp\nvariables (p : \u03b1 \u2192 Prop) [decidable_pred p]\n\n@[simp] lemma countp_nil : countp p [] = 0 := rfl\n\n@[simp] lemma countp_cons_of_pos {a : \u03b1} (l) (pa : p a) : countp p (a::l) = countp p l + 1 :=\nif_pos pa\n\n@[simp] lemma countp_cons_of_neg {a : \u03b1} (l) (pa : \u00ac p a) : countp p (a::l) = countp p l :=\nif_neg pa\n\nlemma countp_cons (a : \u03b1) (l) : countp p (a :: l) = countp p l + ite (p a) 1 0 :=\nby { by_cases h : p a; simp [h] }\n\nlemma length_eq_countp_add_countp (l) : length l = countp p l + countp (\u03bb a, \u00acp a) l :=\nby induction l with x h ih; [refl, by_cases p x];\n  [simp only [countp_cons_of_pos _ _ h, countp_cons_of_neg (\u03bb a, \u00acp a) _ (decidable.not_not.2 h),\n    ih, length],\n   simp only [countp_cons_of_pos (\u03bb a, \u00acp a) _ h, countp_cons_of_neg _ _ h, ih, length]]; ac_refl\n\nlemma countp_eq_length_filter (l) : countp p l = length (filter p l) :=\nby induction l with x l ih; [refl, by_cases (p x)];\n  [simp only [filter_cons_of_pos _ h, countp, ih, if_pos h],\n   simp only [countp_cons_of_neg _ _ h, ih, filter_cons_of_neg _ h]]; refl\n\nlemma countp_le_length : countp p l \u2264 l.length :=\nby simpa only [countp_eq_length_filter] using length_le_of_sublist (filter_sublist _)\n\n@[simp] lemma countp_append (l\u2081 l\u2082) : countp p (l\u2081 ++ l\u2082) = countp p l\u2081 + countp p l\u2082 :=\nby simp only [countp_eq_length_filter, filter_append, length_append]\n\nlemma countp_pos {l} : 0 < countp p l \u2194 \u2203 a \u2208 l, p a :=\nby simp only [countp_eq_length_filter, length_pos_iff_exists_mem, mem_filter, exists_prop]\n\ntheorem countp_eq_zero {l} : countp p l = 0 \u2194 \u2200 a \u2208 l, \u00ac p a :=\nby { rw [\u2190 not_iff_not, \u2190 ne.def, \u2190 pos_iff_ne_zero, countp_pos], simp }\n\nlemma countp_eq_length {l} : countp p l = l.length \u2194 \u2200 a \u2208 l, p a :=\nby rw [countp_eq_length_filter, filter_length_eq_length]\n\nlemma length_filter_lt_length_iff_exists (l) : length (filter p l) < length l \u2194 \u2203 x \u2208 l, \u00acp x :=\nby rw [length_eq_countp_add_countp p l, \u2190 countp_pos, countp_eq_length_filter, lt_add_iff_pos_right]\n\nlemma sublist.countp_le (s : l\u2081 <+ l\u2082) : countp p l\u2081 \u2264 countp p l\u2082 :=\nby simpa only [countp_eq_length_filter] using length_le_of_sublist (s.filter p)\n\n@[simp] lemma countp_filter {q} [decidable_pred q] (l : list \u03b1) :\n  countp p (filter q l) = countp (\u03bb a, p a \u2227 q a) l :=\nby simp only [countp_eq_length_filter, filter_filter]\n\n@[simp] lemma countp_true : l.countp (\u03bb _, true) = l.length :=\nby simp [countp_eq_length_filter]\n\n@[simp] lemma countp_false : l.countp (\u03bb _, false) = 0 :=\nby simp [countp_eq_length_filter]\n\nend countp\n\n/-! ### count -/\n\nsection count\nvariables [decidable_eq \u03b1]\n\n@[simp] lemma count_nil (a : \u03b1) : count a [] = 0 := rfl\n\nlemma count_cons (a b : \u03b1) (l : list \u03b1) :\n  count a (b :: l) = if a = b then succ (count a l) else count a l := rfl\n\nlemma count_cons' (a b : \u03b1) (l : list \u03b1) :\n  count a (b :: l) = count a l + (if a = b then 1 else 0) :=\nbegin rw count_cons, split_ifs; refl end\n\n@[simp] lemma count_cons_self (a : \u03b1) (l : list \u03b1) : count a (a::l) = succ (count a l) := if_pos rfl\n\n@[simp, priority 990]\nlemma count_cons_of_ne {a b : \u03b1} (h : a \u2260 b) (l : list \u03b1) : count a (b::l) = count a l := if_neg h\n\nlemma count_tail : \u03a0 (l : list \u03b1) (a : \u03b1) (h : 0 < l.length),\n  l.tail.count a = l.count a - ite (a = list.nth_le l 0 h) 1 0\n| (_ :: _) a h := by { rw [count_cons], split_ifs; simp }\n\nlemma count_le_length (a : \u03b1) (l : list \u03b1) : count a l \u2264 l.length :=\ncountp_le_length _\n\nlemma sublist.count_le (h : l\u2081 <+ l\u2082) (a : \u03b1) : count a l\u2081 \u2264 count a l\u2082 := h.countp_le _\n\nlemma count_le_count_cons (a b : \u03b1) (l : list \u03b1) : count a l \u2264 count a (b :: l) :=\n(sublist_cons _ _).count_le _\n\nlemma count_singleton (a : \u03b1) : count a [a] = 1 := if_pos rfl\n\nlemma count_singleton' (a b : \u03b1) : count a [b] = ite (a = b) 1 0 := rfl\n\n@[simp] lemma count_append (a : \u03b1) : \u2200 l\u2081 l\u2082, count a (l\u2081 ++ l\u2082) = count a l\u2081 + count a l\u2082 :=\ncountp_append _\n\nlemma count_concat (a : \u03b1) (l : list \u03b1) : count a (concat l a) = succ (count a l) :=\nby simp [-add_comm]\n\n@[simp] lemma count_pos {a : \u03b1} {l : list \u03b1} : 0 < count a l \u2194 a \u2208 l :=\nby simp only [count, countp_pos, exists_prop, exists_eq_right']\n\n@[simp] lemma one_le_count_iff_mem {a : \u03b1} {l : list \u03b1} : 1 \u2264 count a l \u2194 a \u2208 l :=\ncount_pos\n\n@[simp, priority 980]\nlemma count_eq_zero_of_not_mem {a : \u03b1} {l : list \u03b1} (h : a \u2209 l) : count a l = 0 :=\ndecidable.by_contradiction $ \u03bb h', h $ count_pos.1 (nat.pos_of_ne_zero h')\n\nlemma not_mem_of_count_eq_zero {a : \u03b1} {l : list \u03b1} (h : count a l = 0) : a \u2209 l :=\n\u03bb h', (count_pos.2 h').ne' h\n\nlemma count_eq_zero {a : \u03b1} {l} : count a l = 0 \u2194 a \u2209 l :=\n\u27e8not_mem_of_count_eq_zero, count_eq_zero_of_not_mem\u27e9\n\nlemma count_eq_length {a : \u03b1} {l} : count a l = l.length \u2194 \u2200 b \u2208 l, a = b :=\nby rw [count, countp_eq_length]\n\n@[simp] lemma count_repeat (a : \u03b1) (n : \u2115) : count a (repeat a n) = n :=\nby rw [count, countp_eq_length_filter, filter_eq_self.2, length_repeat];\n   exact \u03bb b m, (eq_of_mem_repeat m).symm\n\nlemma le_count_iff_repeat_sublist {a : \u03b1} {l : list \u03b1} {n : \u2115} :\n  n \u2264 count a l \u2194 repeat a n <+ l :=\n\u27e8\u03bb h, ((repeat_sublist_repeat a).2 h).trans $\n  have filter (eq a) l = repeat a (count a l), from eq_repeat.2\n    \u27e8by simp only [count, countp_eq_length_filter], \u03bb b m, (of_mem_filter m).symm\u27e9,\n  by rw \u2190 this; apply filter_sublist,\n \u03bb h, by simpa only [count_repeat] using h.count_le a\u27e9\n\nlemma repeat_count_eq_of_count_eq_length  {a : \u03b1} {l : list \u03b1} (h : count a l = length l)  :\n  repeat a (count a l) = l :=\neq_of_sublist_of_length_eq (le_count_iff_repeat_sublist.mp (le_refl (count a l)))\n    (eq.trans (length_repeat a (count a l)) h)\n\n@[simp] lemma count_filter {p} [decidable_pred p]\n  {a} {l : list \u03b1} (h : p a) : count a (filter p l) = count a l :=\nby simp only [count, countp_filter, show (\u03bb b, a = b \u2227 p b) = eq a, by { ext b, constructor; cc }]\n\nlemma count_bind {\u03b1 \u03b2} [decidable_eq \u03b2] (l : list \u03b1) (f : \u03b1 \u2192 list \u03b2) (x : \u03b2)  :\n  count x (l.bind f) = sum (map (count x \u2218 f) l) :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simpa }\nend\n\n@[simp] lemma count_map_of_injective {\u03b1 \u03b2} [decidable_eq \u03b1] [decidable_eq \u03b2]\n  (l : list \u03b1) (f : \u03b1 \u2192 \u03b2) (hf : function.injective f) (x : \u03b1) :\n  count (f x) (map f l) = count x l :=\nbegin\n  induction l with y l IH generalizing x,\n  { simp },\n  { simp [map_cons, count_cons', IH, hf.eq_iff] }\nend\n\nlemma count_le_count_map [decidable_eq \u03b2] (l : list \u03b1) (f : \u03b1 \u2192 \u03b2) (x : \u03b1) :\n  count x l \u2264 count (f x) (map f l) :=\nbegin\n  induction l with a as IH, { simp },\n  rcases eq_or_ne x a with rfl | hxa,\n  { simp [succ_le_succ IH] },\n  { simp [hxa, le_add_right IH, count_cons'] }\nend\n\n@[simp] lemma count_erase_self (a : \u03b1) :\n  \u2200 (s : list \u03b1), count a (list.erase s a) = pred (count a s)\n| [] := by simp\n| (h :: t) :=\nbegin\n  rw erase_cons,\n  by_cases p : h = a,\n  { rw [if_pos p, count_cons', if_pos p.symm], simp },\n  { rw [if_neg p, count_cons', count_cons', if_neg (\u03bb x : a = h, p x.symm), count_erase_self],\n    simp }\nend\n\n@[simp] lemma count_erase_of_ne {a b : \u03b1} (ab : a \u2260 b) :\n  \u2200 (s : list \u03b1), count a (list.erase s b) = count a s\n| [] := by simp\n| (x :: xs) :=\nbegin\n  rw erase_cons,\n  split_ifs with h,\n  { rw [count_cons', h, if_neg ab], simp },\n  { rw [count_cons', count_cons', count_erase_of_ne] }\nend\n\nend count\n\nend list\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/list/count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.7384777259326306}}
{"text": "/-\nCopyright (c) 2020 Ruben Van de Velde, Stanislas Polu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ruben Van de Velde, Stanislas Polu\n-/\n\nimport data.real.basic\nimport analysis.normed_space.basic\n\n/-- IMO 1972 B2\n\nProblem: `f` and `g` are real-valued functions defined on the real line. For all `x` and `y`,\n`f(x + y) + f(x - y) = 2f(x)g(y)`. `f` is not identically zero and `|f(x)| \u2264 1` for all `x`.\nProve that `|g(x)| \u2264 1` for all `x`.\n\nThis is a more concise version of the proof proposed by Ruben Van de Velde.\n-/\ntheorem imo1972_p5_alt1 (f g : \u211d \u2192 \u211d)\n  (hf1 : \u2200 x, \u2200 y, (f (x+y) + f(x-y)) = 2 * f(x) * g(y))\n  (hf2 : bdd_above (set.range (\u03bb x, \u2225f x\u2225)))\n  (hf3 : \u2203 x, f(x) \u2260 0)\n  (y : \u211d) :\n  \u2225g(y)\u2225 \u2264 1 :=\nbegin\n  obtain \u27e8x, hx\u27e9 := hf3,\n  set k := \u2a06 x, \u2225f x\u2225,\n  have h : \u2200 x, \u2225f x\u2225 \u2264 k := le_csupr hf2,\n  by_contra' H,\n  have hgy : 0 < \u2225g y\u2225,\n    by linarith,\n  have k_pos : 0 < k := lt_of_lt_of_le (norm_pos_iff.mpr hx) (h x),\n  have : k / \u2225g y\u2225 < k := (div_lt_iff hgy).mpr (lt_mul_of_one_lt_right k_pos H),\n  have : k \u2264 k / \u2225g y\u2225,\n  { suffices : \u2200 x, \u2225f x\u2225 \u2264 k / \u2225g y\u2225, from csupr_le this,\n    intro x,\n    suffices : 2 * (\u2225f x\u2225 * \u2225g y\u2225) \u2264 2 * k,\n      by { rwa [le_div_iff hgy, \u2190mul_le_mul_left zero_lt_two], apply_instance },\n    calc 2 * (\u2225f x\u2225 * \u2225g y\u2225)\n        = \u22252 * f x * g y\u2225           : by simp [abs_mul, mul_assoc]\n    ... = \u2225f (x + y) + f (x - y)\u2225   : by rw hf1\n    ... \u2264 \u2225f (x + y)\u2225 + \u2225f (x - y)\u2225 : abs_add _ _\n    ... \u2264 2 * k                     : by linarith [h (x+y), h (x -y)] },\n  linarith,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/imo/1972/p5_alt1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.73847772551765}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Importar las siguientes librer\u00edas\n-- + tactic (con las t\u00e1cticas)\n-- + data.set.basic (con la teor\u00eda b\u00e1sica de conjuntos)\n-- + data.set.lattice (con las uniones e intersecciones infinitas).\n-- ---------------------------------------------------------------------\n\nimport tactic\nimport data.set.basic\nimport data.set.lattice\n\n-- =====================================================================\n-- \u00a7 Introducci\u00f3n                                                     --\n-- =====================================================================\n\n-- Nota. Si `X` es un tipo, entonces `set X` es el tipo de los\n-- subconjuntos de `X`.\n\n-- Nota. Si `X` es un tipo, entonces\n-- + `a : X`  significa que `a` es un t\u00e9rmino de tipo `X`\n-- + `S : set X`  significa que `S` es un conjunto de t\u00e9rminos de tipo `X`.\n\n-- Nota: Si `S : set X` y `a : X`, entonces existe un predicado `a \u2208 S`\n-- que significa que `a` pertenece al subconjunto `S` de `X`.\n\n-- =====================================================================\n-- \u00a7 Implementaciones                                                 --\n-- =====================================================================\n\n-- Nota: Si `S : set X`, entonces `S` es una funci\u00f3n de `X` a `Prop`. La\n-- idea es que un subconjunto `S` de `X` se representa como una funci\u00f3n a\n-- `{true, false}` que aplica los elementos de `S` a `true` y los\n-- restantes a `false`.\n\n-- Nota: La definici\u00f3n del tipo de los subconjuntos es `set X := X \u2192 Prop`\n\n-- Nota: Si `S : set X`, entonces `a \u2208 S` significa `S a`.\n\n-- =====================================================================\n-- \u00a7 Notaci\u00f3n                                                         --\n-- =====================================================================\n\n-- Nota: En lo que sigue, `X` e `Y` son tipos.\n\n-- Nota: Cada tipo tiene un conjunto vac\u00edo denotado por `\u2205 : set X`\n\n-- Nota: Cada tipo tiene un conjunto universal denotado por\n-- `set.univ : set X` (o simplemente `univ : set X` si previamente se ha\n-- escrito `open set`).\n\n-- Nota: Si `S : set X` entonces su complementario es `S\u1d9c : set X`.\n\n-- Nota: En lo que sigue, `f : X \u2192 Y`.\n\n-- Nota: Si `S : set X`, entonces `f '' S : set Y` es la imagen de `S`\n-- por `f`.\n\n-- Nota: Si `T : set Y`, entonces `f \u207b\u00b9' T : set X` es la preimagen de\n-- `T` por `f`.\n\n-- Nota: El rango de f es `range f` (que es igual a `f '' univ`).\n\n-- Nota: La definici\u00f3n de subconjunto es:\n--    subset_def : S \u2286 T \u2194 \u2200 x, x \u2208 S \u2192 x \u2208 T\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar las siguientes variables:\n-- + X, Y, Z sobre tipos.\n-- + f sobre funciones de X en Y.\n-- + g sobre funciones de Y en Z.\n-- + S sobre el tipo de subconjuntos de X.\n-- + T sobre el tipo de subconjuntos de Z.\n-- + y sobre elementos de Y.\n-- ---------------------------------------------------------------------\n\nvariables (X Y Z : Type)\nvariable  (f : X \u2192 Y)\nvariable  (g : Y \u2192 Z)\nvariable  (S : set X)\nvariable  (T : set Z)\nvariable  (y : Y)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir el espacio de nombre set (de los conjuntos).\n-- ---------------------------------------------------------------------\n\nopen set\n\n-- =====================================================================\n-- \u00a7 Imagen                                                           --\n-- =====================================================================\n\n-- Nota. La imagen de un conjunto mediante una funci\u00f3n est\u00e1 definida en\n-- pfun.lean por\n--    image_def (s : set \u03b1) :\n--      image f s = {y | \u2203 x \u2208 s, y \u2208 f x}\n\n-- Nota. La imagen, mediante f, de S se representa por\n--    f '' S\n\n-- Nota. la pertenencia a la imagen est\u00e1 caracterizada en basic.lean por\n--    mem_image (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (y : \u03b2) :\n--      y \u2208 f '' s \u2194 \u2203 x, x \u2208 s \u2227 f x = y\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la imagen de cualquier conjunto S por la\n-- funci\u00f3n identidad es S.\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nlemma image_identity :\n  id '' S = S :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    rw mem_image at h,\n    cases h with y hy,\n    cases hy with hyS hid,\n    rw id.def at hid,\n    rw \u2190 hid,\n    exact hyS },\n  { intro hxS,\n    rw mem_image,\n    use x,\n    split,\n    { exact hxS, },\n    { rw id.def, } }\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  id '' S = S :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    rcases h with \u27e8y, hyS, hid\u27e9,\n    rw \u2190 hid,\n    exact hyS, },\n  { intro hxS,\n    use x,\n    use hxS,\n    refl, }\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  id '' S = S :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8y, hyS, hid\u27e9,\n    rw \u2190 hid,\n    exact hyS, },\n  { intro hxS,\n    use [x, hxS],\n    refl, }\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  id '' S = S :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8y, hyS, rfl\u27e9,\n    exact hyS, },\n  { intro hxS,\n    exact \u27e8x, hxS, rfl\u27e9 },\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  id '' S = S :=\n-- by library_search [- image_identity]\nimage_id S\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  id '' S = S :=\nby simp\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  id '' S = S :=\nby finish\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  id '' S = S :=\nby tidy\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (g \u2218 f) '' S = g '' (f '' S)\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z,\n  split,\n  { intro h,\n    rw mem_image at *,\n    cases h with x hx,\n    use f x,\n    split,\n    { rw mem_image,\n      use x,\n      split,\n      { exact hx.left, },\n      { refl, } },\n    { exact hx.right, }},\n  { intro h,\n    rw mem_image at *,\n    cases h with x hx,\n    rw mem_image at hx,\n    cases hx.left with a ha,\n    use a,\n    split,\n    { exact ha.left, },\n    { dsimp,\n      rw ha.2,\n      rw hx.2, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z,\n  split,\n  { intro h,\n    rw mem_image at *,\n    rcases h with \u27e8x, hxS, h_gfx\u27e9,\n    use f x,\n    split,\n    { rw mem_image,\n      use x,\n      use hxS,},\n    { exact h_gfx, }},\n  { intro h,\n    rw mem_image at *,\n    rcases h with \u27e8x, hxf, hxg\u27e9,\n    rw mem_image at hxf,\n    rcases hxf with \u27e8a, haS, haf\u27e9,\n    use a,\n    split,\n    { exact haS, },\n    { dsimp,\n      rw haf,\n      exact hxg, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z,\n  split,\n  { intro h,\n    rcases h with \u27e8x, hxS, h_gfx\u27e9,\n    use f x,\n    split,\n    { use x,\n      use hxS,},\n    { exact h_gfx, }},\n  { intro h,\n    rcases h with \u27e8x, hxf, hxg\u27e9,\n    rcases hxf with \u27e8a, haS, haf\u27e9,\n    use a,\n    split,\n    { exact haS, },\n    { dsimp,\n      rw haf,\n      exact hxg, }},\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z,\n  split,\n  { intro h,\n    rcases h with \u27e8x, hxS, h_gfx\u27e9,\n    use f x,\n    split,\n    { use [x, hxS],},\n    { exact h_gfx, }},\n  { intro h,\n    rcases h with \u27e8x, hxf, hxg\u27e9,\n    rcases hxf with \u27e8a, haS, haf\u27e9,\n    use a,\n    split,\n    { exact haS, },\n    { dsimp,\n      rw haf,\n      exact hxg, }},\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z,\n  split,\n  { intro h,\n    rcases h with \u27e8x, hxS, h_gfx\u27e9,\n    use f x,\n    { use [x, hxS, h_gfx], }},\n  { intro h,\n    rcases h with \u27e8x, hxf, hxg\u27e9,\n    rcases hxf with \u27e8a, haS, haf\u27e9,\n    use a,\n    split,\n    { exact haS, },\n    { dsimp,\n      rw haf,\n      exact hxg, }},\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z,\n  split,\n  { intro h,\n    rcases h with \u27e8x, hxS, h_gfx\u27e9,\n    use [f x, x, hxS, h_gfx], },\n  { intro h,\n    rcases h with \u27e8x, hxf, hxg\u27e9,\n    rcases hxf with \u27e8a, haS, haf\u27e9,\n    use a,\n    split,\n    { exact haS, },\n    { dsimp,\n      rw haf,\n      exact hxg, }},\nend\n\n-- 7\u00aa demostraci\u00f3n\nlemma image_comp :\n  (g \u2218 f) '' S = g '' (f '' S) :=\nbegin\n  ext z,\n  split,\n  { rintro \u27e8x, hxS, h_gfx\u27e9,\n    use [f x, x, hxS, h_gfx] },\n  { rintro \u27e8y, \u27e8x, hxS, rfl\u27e9, rfl\u27e9,\n    exact \u27e8x, hxS, rfl\u27e9 }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir el espacio de nombre function (de las funciones).\n-- ---------------------------------------------------------------------\n\nopen function\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es inyectiva, entonces la funci\u00f3n que\n-- le asigna a cada conjunto su imagen por f tambi\u00e9n es inyectiva.\n-- ---------------------------------------------------------------------\n\nlemma image_injective :\n  injective f \u2192 injective (\u03bb S, f '' S) :=\nbegin\n  intro hf,\n  intros S T h,\n  dsimp at h,\n  ext x,\n  suffices : \u2200 S T : set X, f '' S = f '' T \u2192 x \u2208 S \u2192 x \u2208 T,\n  { split,\n    { apply this _ _ h, },\n    { apply this _ _ h.symm, }},\n  { clear h S T,\n    intros S T h hxS,\n    have hfx : f x \u2208 f '' T,\n    { rw \u2190 h,\n      use [x, hxS] },\n    { rcases hfx with \u27e8y, hyT, hfy\u27e9,\n      convert hyT,\n      apply hf,\n      exact hfy.symm, }},\nend\n\n-- =====================================================================\n-- \u00a7 Imagen inversa                                                   --\n-- =====================================================================\n\n-- Nota. La imagen de un conjunto mediante una funci\u00f3n est\u00e1 definida en\n-- pfun.lean por\n--    preimage_def (s : set \u03b2) :\n--      preimage f s = {x | \u2203 y \u2208 s, y \u2208 f x}\n\n-- Nota. La imagen inversa, mediante f, de S se representa por\n--    f \u207b\u00b9' S\n\n-- Nota. La pertenencia a la imagen est\u00e1 caracterizada en basic.lean por\n--    mem_preimage {s : set \u03b2} {a : \u03b1} :\n--      (a \u2208 f \u207b\u00b9' s) \u2194 (f a \u2208 s)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la imagen inversa de cualquier conjunto por\n-- la identidad es \u00e9l mismo.\n-- ---------------------------------------------------------------------\n\nexample :\n  S = id \u207b\u00b9' S :=\nbegin\n  refl,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (g \u2218 f) \u207b\u00b9' T = f \u207b\u00b9' (g \u207b\u00b9' T)\n-- ---------------------------------------------------------------------\n\nexample :\n  (g \u2218 f) \u207b\u00b9' T = f \u207b\u00b9' (g \u207b\u00b9' T) :=\nbegin\n  refl,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es suprayectiva, entonces la funci\u00f3n\n-- que asigna a cada conjunto su imagen inversa por f es inyectiva.\n-- ---------------------------------------------------------------------\n\nlemma preimage_injective\n  (hf : surjective f)\n  : injective (\u03bb T, f \u207b\u00b9' T) :=\nbegin\n  intros T U h,\n  ext y,\n  suffices : \u2200 {T U}, f \u207b\u00b9' T = f \u207b\u00b9' U \u2192 y \u2208 T \u2192 y \u2208 U,\n  { exact \u27e8this h, this h.symm\u27e9 },\n  { intros T U h hyT,\n    rcases hf y with \u27e8x, rfl\u27e9,\n    rwa [\u2190 mem_preimage, \u2190 h], },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es suprayectiva, entonces la funci\u00f3n\n-- que le asigna a cada conjunto su imagen por f es suprayectiva.\n-- ---------------------------------------------------------------------\n\nlemma image_surjective\n  (hf : surjective f)\n  : surjective (\u03bb S, f '' S) :=\nbegin\n  intro T,\n  use f \u207b\u00b9' T,\n  dsimp only,\n  ext y,\n  split,\n  { rintro \u27e8x, hx, rfl\u27e9,\n    exact hx },\n  { intro hyT,\n    rcases hf y with \u27e8x, rfl\u27e9,\n    use [x, hyT] }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es inyectiva, entonces la funci\u00f3n que a\n-- cada conjunto le asigna su imagen inversa por S es suprayectiva.\n\n\nlemma preimage_surjective\n  (hf : injective f)\n  : surjective (\u03bb S, f \u207b\u00b9' S) :=\nbegin\n  intro S,\n  use f '' S,\n  ext x,\n  split,\n  { rintro \u27e8y, hyS, h\u27e9,\n    rwa \u2190 (hf h) },\n  { intro h,\n    use [x, h, rfl] }\nend\n\n-- =====================================================================\n-- \u00a7 Uni\u00f3n general                                                    --\n-- =====================================================================\n\n-- Nota. La uni\u00f3n de una familia de conjuntos est\u00e1 definida (en\n-- lattice.lean) como su supremo\n--    def Union (s : \u03b9 \u2192 set \u03b2) : set \u03b2 := supr s\n\n-- Nota. Sea `(\u03b9 : Type)` y `(F : \u03b9 \u2192 set X)`, la uni\u00f3n de la familia de\n-- conjuntos `F` se representa por `\u22c3 (i : \u03b9), F i`.\n\n-- Nota. La caracterizaci\u00f3n de la pertenencia a la uni\u00f3n de una familia\n-- es\n--    mem_Union {x : \u03b2} {s : \u03b9 \u2192 set \u03b2} :\n--       x \u2208 Union s \u2194 \u2203 i, x \u2208 s i\n-- o bien\n--    mem_Union {x : \u03b2} {F : \u03b9 \u2192 set \u03b2} :\n--       (x \u2208 \u22c3 (i : \u03b9), F i) \u2194 \u2203 j : \u03b9, x \u2208 F j\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar\n-- + \u03b9 una variable sobre tipos\n-- + F una variable para las familias de subconjuntos de X con \u00edndice \u03b9\n-- + x una varible sobre t\u00e9rminos de tipo X.\n-- ---------------------------------------------------------------------\n\nvariable (\u03b9 : Type)\nvariable (F : \u03b9 \u2192 set X)\nvariable (x : X)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la imagen de la uni\u00f3n de una familia es\n-- igual a la uni\u00f3n de las im\u00e1genes de cada elemento de la familia.\n-- ---------------------------------------------------------------------\n\nlemma image_Union  :\n  f '' (\u22c3 (i : \u03b9), F i) = \u22c3 (i : \u03b9), f '' (F i) :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8x, hxF, rfl\u27e9,\n    rw mem_Union at *,\n    cases hxF with i hi,\n    use [i, x, hi] },\n  { intro h,\n    rw mem_Union at h,\n    rcases h with \u27e8i, x, hxi, rfl\u27e9,\n    use x,\n    rw mem_Union,\n    use i,\n    assumption }\nend\n\n-- =====================================================================\n-- \u00a7 Uni\u00f3n general acotada                                            --\n-- =====================================================================\n\n-- Nota. Si `F : \u03b9 \u2192 set X` y `J : set \u03b9`, entonces `\u22c3 (i \u2208 J), F i` es\n-- la uni\u00f3n general acotada y sus elementos se caracterizan por\n--    mem_bUnion_iff : (x \u2208 \u22c3 (i \u2208 J), F i) \u2194 \u2203 (j \u2208 J), x \u2208 F j\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    f \u207b\u00b9' (\u22c3 (i \u2208 Z), F i) = \u22c3 (i \u2208 Z), f \u207b\u00b9' (F i)\n-- ---------------------------------------------------------------------\n\nlemma preimage_bUnion\n  (F : \u03b9 \u2192 set Y)\n  (Z : set \u03b9)\n  : f \u207b\u00b9' (\u22c3 (i \u2208 Z), F i) = \u22c3 (i \u2208 Z), f \u207b\u00b9' (F i) :=\nbegin\n  ext y,\n  rw [mem_preimage, mem_bUnion_iff, mem_bUnion_iff],\n  refl,\nend\n", "meta": {"author": "jaalonso", "repo": "Formalizacion_de_las_matematicas_en_Lean", "sha": "52bf9748d17a22d819cac19502fca9bc7340f7ae", "save_path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean/Formalizacion_de_las_matematicas_en_Lean-52bf9748d17a22d819cac19502fca9bc7340f7ae/src/4_Topologia/Conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7384777086022134}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.real.basic\nimport data.real.sqrt\nimport data.real.nnreal\nimport tactic.linear_combination\n\n/-!\n# IMO 2008 Q4\nFind all functions `f : (0,\u221e) \u2192 (0,\u221e)` (so, `f` is a function from the positive real\nnumbers to the positive real numbers) such that\n      ```\n      (f(w)^2 + f(x)^2)/(f(y^2) + f(z^2)) = (w^2 + x^2)/(y^2 + z^2)\n      ```\nfor all positive real numbers `w`, `x`, `y`, `z`, satisfying `wx = yz`.\n\n# Solution\nThe desired theorem is that either `f = \u03bb x, x` or `f = \u03bb x, 1/x`\n-/\n\nopen real\n\nlemma abs_eq_one_of_pow_eq_one (x : \u211d) (n : \u2115) (hn : n \u2260 0) (h : x ^ n = 1) : |x| = 1 :=\nby rw [\u2190 pow_left_inj (abs_nonneg x) zero_le_one (pos_iff_ne_zero.2 hn), one_pow, pow_abs, h,\n  abs_one]\n\ntheorem imo2008_q4\n  (f : \u211d \u2192 \u211d)\n  (H\u2081 : \u2200 x > 0, f(x) > 0) :\n  (\u2200 w x y z : \u211d, 0 < w \u2192 0 < x \u2192 0 < y \u2192 0 < z \u2192 w * x = y * z \u2192\n    (f(w) ^ 2 + f(x) ^ 2) / (f(y ^ 2) + f(z ^ 2)) = (w ^ 2 + x ^ 2) / (y ^ 2 + z ^ 2)) \u2194\n  ((\u2200 x > 0, f(x) = x) \u2228 (\u2200 x > 0, f(x) = 1 / x)) :=\nbegin\n  split, swap,\n  -- proof that f(x) = x and f(x) = 1/x satisfy the condition\n  { rintros (h | h),\n    { intros w x y z hw hx hy hz hprod,\n      rw [h w hw, h x hx, h (y ^ 2) (pow_pos hy 2), h (z ^ 2) (pow_pos hz 2)] },\n    { intros w x y z hw hx hy hz hprod,\n      rw [h w hw, h x hx, h (y ^ 2) (pow_pos hy 2), h (z ^ 2) (pow_pos hz 2)],\n      have hy2z2 : y ^ 2 + z ^ 2 \u2260 0 := ne_of_gt (add_pos (pow_pos hy 2) (pow_pos hz 2)),\n      have hz2y2 : z ^ 2 + y ^ 2 \u2260 0 := ne_of_gt (add_pos (pow_pos hz 2) (pow_pos hy 2)),\n      have hp2 : w ^ 2 * x ^ 2 = y ^ 2 * z ^ 2,\n      { linear_combination (hprod, w * x + y * z) },\n      field_simp [ne_of_gt hw, ne_of_gt hx, ne_of_gt hy, ne_of_gt hz, hy2z2, hz2y2, hp2],\n      ring } },\n\n  -- proof that the only solutions are f(x) = x or f(x) = 1/x\n  intro H\u2082,\n  have h\u2080 : f(1) \u2260 0, { specialize H\u2081 1 zero_lt_one, exact ne_of_gt H\u2081 },\n\n  have h\u2081 : f(1) = 1,\n  { specialize H\u2082 1 1 1 1 zero_lt_one zero_lt_one zero_lt_one zero_lt_one rfl,\n    norm_num [\u2190 two_mul] at H\u2082,\n    rw mul_div_mul_left (f(1) ^ 2) (f 1) two_ne_zero at H\u2082,\n    rwa \u2190 (div_eq_iff h\u2080).mpr (sq (f 1)) },\n\n  have h\u2082 : \u2200 x > 0, (f(x) - x) * (f(x) - 1 / x) = 0,\n  { intros x hx,\n    have h1xss : 1 * x = (sqrt x) * (sqrt x), { rw [one_mul, mul_self_sqrt (le_of_lt hx)] },\n    specialize H\u2082 1 x (sqrt x) (sqrt x) zero_lt_one hx (sqrt_pos.mpr hx) (sqrt_pos.mpr hx) h1xss,\n    rw [h\u2081, one_pow 2, sq_sqrt (le_of_lt hx), \u2190 two_mul (f(x)), \u2190 two_mul x] at H\u2082,\n    have hx_ne_0 : x \u2260 0 := ne_of_gt hx,\n    have hfx_ne_0 : f(x) \u2260 0, { specialize H\u2081 x hx, exact ne_of_gt H\u2081 },\n    field_simp at H\u2082 \u22a2,\n    linear_combination (H\u2082, 1/2) },\n\n  have h\u2083 : \u2200 x > 0, f(x) = x \u2228 f(x) = 1 / x, { simpa [sub_eq_zero] using h\u2082 },\n\n  by_contra' h,\n  rcases h with \u27e8\u27e8b, hb, hfb\u2081\u27e9, \u27e8a, ha, hfa\u2081\u27e9\u27e9,\n  obtain hfa\u2082 := or.resolve_right (h\u2083 a ha) hfa\u2081, -- f(a) \u2260 1/a, f(a) = a\n  obtain hfb\u2082 := or.resolve_left (h\u2083 b hb) hfb\u2081,  -- f(b) \u2260 b, f(b) = 1/b\n\n  have hab : a * b > 0 := mul_pos ha hb,\n  have habss : a * b = sqrt(a * b) * sqrt(a * b) := (mul_self_sqrt (le_of_lt hab)).symm,\n\n  specialize H\u2082 a b (sqrt (a * b)) (sqrt (a * b)) ha hb (sqrt_pos.mpr hab) (sqrt_pos.mpr hab) habss,\n  rw [sq_sqrt (le_of_lt hab), \u2190 two_mul (f(a * b)), \u2190 two_mul (a * b)] at H\u2082,\n  rw [hfa\u2082, hfb\u2082] at H\u2082,\n\n  have h2ab_ne_0 : 2 * (a * b) \u2260 0 := mul_ne_zero two_ne_zero (ne_of_gt hab),\n\n  specialize h\u2083 (a * b) hab,\n  cases h\u2083 with hab\u2081 hab\u2082,\n\n  -- f(ab) = ab \u2192 b^4 = 1 \u2192 b = 1 \u2192 f(b) = b \u2192 false\n  { field_simp [hab\u2081] at H\u2082,\n    field_simp [ne_of_gt hb] at H\u2082,\n    have hb\u2081 : b ^ 4 = 1 := by linear_combination (H\u2082, -1),\n    obtain hb\u2082 := abs_eq_one_of_pow_eq_one b 4 (show 4 \u2260 0, by norm_num) hb\u2081,\n    rw abs_of_pos hb at hb\u2082, rw hb\u2082 at hfb\u2081, exact hfb\u2081 h\u2081 },\n\n  -- f(ab) = 1/ab \u2192 a^4 = 1 \u2192 a = 1 \u2192 f(a) = 1/a \u2192 false\n  { have hb_ne_0 : b \u2260 0 := ne_of_gt hb,\n    field_simp [hab\u2082] at H\u2082,\n    have H\u2083 : 2 * b ^ 4 * (a ^ 4 - 1) = 0 := by linear_combination H\u2082,\n    have h2b4_ne_0 : 2 * (b ^ 4) \u2260 0 := mul_ne_zero two_ne_zero (pow_ne_zero 4 hb_ne_0),\n    have ha\u2081 : a ^ 4 = 1, { simpa [sub_eq_zero, h2b4_ne_0] using H\u2083 },\n    obtain ha\u2082 := abs_eq_one_of_pow_eq_one a 4 (show 4 \u2260 0, by norm_num) ha\u2081,\n    rw abs_of_pos ha at ha\u2082, rw ha\u2082 at hfa\u2081, norm_num at hfa\u2081 },\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/archive/imo/imo2008_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7383383783559077}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport data.polynomial.erase_lead\nimport data.polynomial.eval\n\n/-!\n# Denominators of evaluation of polynomials at ratios\n\nLet `i : R \u2192 K` be a homomorphism of semirings.  Assume that `K` is commutative.  If `a` and\n`b` are elements of `R` such that `i b \u2208 K` is invertible, then for any polynomial\n`f \u2208 polynomial R` the \"mathematical\" expression `b ^ f.nat_degree * f (a / b) \u2208 K` is in\nthe image of the homomorphism `i`.\n-/\n\nopen polynomial finset\n\nsection denoms_clearable\n\nvariables {R K : Type*} [semiring R] [comm_semiring K] {i : R \u2192+* K}\nvariables {a b : R} {bi : K}\n-- TODO: use hypothesis (ub : is_unit (i b)) to work with localizations.\n\n/-- `denoms_clearable` formalizes the property that `b ^ N * f (a / b)`\ndoes not have denominators, if the inequality `f.nat_degree \u2264 N` holds.\n\nThe definition asserts the existence of an element `D` of `R` and an\nelement `bi = 1 / i b` of `K` such that clearing the denominators of\nthe fraction equals `i D`.\n-/\ndef denoms_clearable (a b : R) (N : \u2115) (f : polynomial R) (i : R \u2192+* K) : Prop :=\n  \u2203 (D : R) (bi : K), bi * i b = 1 \u2227 i D = i b ^ N * eval (i a * bi) (f.map i)\n\nlemma denoms_clearable_zero (N : \u2115) (a : R) (bu : bi * i b = 1) :\n  denoms_clearable a b N 0 i :=\n\u27e80, bi, bu, by simp only [eval_zero, ring_hom.map_zero, mul_zero, polynomial.map_zero]\u27e9\n\nlemma denoms_clearable_C_mul_X_pow {N : \u2115} (a : R) (bu : bi * i b = 1) {n : \u2115} (r : R)\n  (nN : n \u2264 N) : denoms_clearable a b N (C r * X ^ n) i :=\nbegin\n  refine \u27e8r * a ^ n * b ^ (N - n), bi, bu, _\u27e9,\n  rw [C_mul_X_pow_eq_monomial, map_monomial, \u2190 C_mul_X_pow_eq_monomial, eval_mul, eval_pow, eval_C],\n  rw [ring_hom.map_mul, ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_pow, eval_X, mul_comm],\n  rw [\u2190 tsub_add_cancel_of_le nN] {occs := occurrences.pos [2]},\n  rw [pow_add, mul_assoc, mul_comm (i b ^ n), mul_pow, mul_assoc, mul_assoc (i a ^ n), \u2190 mul_pow],\n  rw [bu, one_pow, mul_one],\nend\n\nlemma denoms_clearable.add {N : \u2115} {f g : polynomial R} :\n  denoms_clearable a b N f i \u2192 denoms_clearable a b N g i \u2192 denoms_clearable a b N (f + g) i :=\n\u03bb \u27e8Df, bf, bfu, Hf\u27e9 \u27e8Dg, bg, bgu, Hg\u27e9, \u27e8Df + Dg, bf, bfu,\n  begin\n    rw [ring_hom.map_add, polynomial.map_add, eval_add, mul_add, Hf, Hg],\n    congr,\n    refine @inv_unique K _ (i b) bg bf _ _;\n    rwa mul_comm,\n  end \u27e9\n\nlemma denoms_clearable_of_nat_degree_le (N : \u2115) (a : R) (bu : bi * i b = 1) :\n  \u2200 (f : polynomial R), f.nat_degree \u2264 N \u2192 denoms_clearable a b N f i :=\ninduction_with_nat_degree_le N\n  (denoms_clearable_zero N a bu)\n  (\u03bb N_1 r r0, denoms_clearable_C_mul_X_pow a bu r)\n  (\u03bb f g fN gN df dg, df.add dg)\n\n/-- If `i : R \u2192 K` is a ring homomorphism, `f` is a polynomial with coefficients in `R`,\n`a, b` are elements of `R`, with `i b` invertible, then there is a `D \u2208 R` such that\n`b ^ f.nat_degree * f (a / b)` equals `i D`. -/\ntheorem denoms_clearable_nat_degree\n  (i : R \u2192+* K) (f : polynomial R) (a : R) (bu : bi * i b = 1) :\n  denoms_clearable a b f.nat_degree f i :=\ndenoms_clearable_of_nat_degree_le f.nat_degree a bu f le_rfl\n\nend denoms_clearable\n\nopen ring_hom\n\n/--  Evaluating a polynomial with integer coefficients at a rational number and clearing\ndenominators, yields a number greater than or equal to one.  The target can be any\n`linear_ordered_field K`.\nThe assumption on `K` could be weakened to `linear_ordered_comm_ring` assuming that the\nimage of the denominator is invertible in `K`. -/\nlemma one_le_pow_mul_abs_eval_div {K : Type*} [linear_ordered_field K] {f : polynomial \u2124}\n  {a b : \u2124} (b0 : 0 < b) (fab : eval ((a : K) / b) (f.map (algebra_map \u2124 K)) \u2260 0) :\n  (1 : K) \u2264 b ^ f.nat_degree * |eval ((a : K) / b) (f.map (algebra_map \u2124 K))| :=\nbegin\n  obtain \u27e8ev, bi, bu, hF\u27e9 := @denoms_clearable_nat_degree _ _ _ _ b _ (algebra_map \u2124 K)\n    f a (by { rw [eq_int_cast, one_div_mul_cancel], rw [int.cast_ne_zero], exact (b0.ne.symm) }),\n  obtain Fa := congr_arg abs hF,\n  rw [eq_one_div_of_mul_eq_one_left bu, eq_int_cast, eq_int_cast, abs_mul] at Fa,\n  rw [abs_of_pos (pow_pos (int.cast_pos.mpr b0) _ : 0 < (b : K) ^ _), one_div, eq_int_cast] at Fa,\n  rw [div_eq_mul_inv, \u2190 Fa, \u2190 int.cast_abs, \u2190 int.cast_one, int.cast_le],\n  refine int.le_of_lt_add_one ((lt_add_iff_pos_left 1).mpr (abs_pos.mpr (\u03bb F0, fab _))),\n  rw [eq_one_div_of_mul_eq_one_left bu, F0, one_div, eq_int_cast, int.cast_zero, zero_eq_mul] at hF,\n  cases hF with hF hF,\n  { exact (not_le.mpr b0 (le_of_eq (int.cast_eq_zero.mp (pow_eq_zero hF)))).elim },\n  { rwa div_eq_mul_inv }\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/denoms_clearable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7383383767887782}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module topology.locally_constant.algebra\n! leanprover-community/mathlib commit bcfa726826abd57587355b4b5b7e78ad6527b7e4\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Algebra.Pi\nimport Mathlib.Topology.LocallyConstant.Basic\n\n/-!\n# Algebraic structure on locally constant functions\n\nThis file puts algebraic structure (`Group`, `AddGroup`, etc)\non the type of locally constant functions.\n\n-/\n\nnamespace LocallyConstant\n\nvariable {X Y : Type _} [TopologicalSpace X]\n\n@[to_additive]\ninstance [One Y] : One (LocallyConstant X Y) where one := const X 1\n\n@[to_additive (attr := simp)]\ntheorem coe_one [One Y] : \u21d1(1 : LocallyConstant X Y) = (1 : X \u2192 Y) :=\n  rfl\n#align locally_constant.coe_one LocallyConstant.coe_one\n#align locally_constant.coe_zero LocallyConstant.coe_zero\n\n@[to_additive]\ntheorem one_apply [One Y] (x : X) : (1 : LocallyConstant X Y) x = 1 :=\n  rfl\n#align locally_constant.one_apply LocallyConstant.one_apply\n#align locally_constant.zero_apply LocallyConstant.zero_apply\n\n@[to_additive]\ninstance [Inv Y] : Inv (LocallyConstant X Y) where inv f := \u27e8f\u207b\u00b9, f.isLocallyConstant.inv\u27e9\n\n@[to_additive (attr := simp)]\ntheorem coe_inv [Inv Y] (f : LocallyConstant X Y) : \u21d1(f\u207b\u00b9 : LocallyConstant X Y) = (f : X \u2192 Y)\u207b\u00b9 :=\n  rfl\n#align locally_constant.coe_inv LocallyConstant.coe_inv\n#align locally_constant.coe_neg LocallyConstant.coe_neg\n\n@[to_additive]\ntheorem inv_apply [Inv Y] (f : LocallyConstant X Y) (x : X) : f\u207b\u00b9 x = (f x)\u207b\u00b9 :=\n  rfl\n#align locally_constant.inv_apply LocallyConstant.inv_apply\n#align locally_constant.neg_apply LocallyConstant.neg_apply\n\n@[to_additive]\ninstance [Mul Y] : Mul (LocallyConstant X Y) where\n  mul f g := \u27e8f * g, f.isLocallyConstant.mul g.isLocallyConstant\u27e9\n\n@[to_additive (attr := simp)]\ntheorem coe_mul [Mul Y] (f g : LocallyConstant X Y) : \u21d1(f * g) = f * g :=\n  rfl\n#align locally_constant.coe_mul LocallyConstant.coe_mul\n#align locally_constant.coe_add LocallyConstant.coe_add\n\n@[to_additive]\ntheorem mul_apply [Mul Y] (f g : LocallyConstant X Y) (x : X) : (f * g) x = f x * g x :=\n  rfl\n#align locally_constant.mul_apply LocallyConstant.mul_apply\n#align locally_constant.add_apply LocallyConstant.add_apply\n\n@[to_additive]\ninstance [MulOneClass Y] : MulOneClass (LocallyConstant X Y) :=\n  Function.Injective.mulOneClass FunLike.coe FunLike.coe_injective' rfl fun _ _ => rfl\n\n/-- `FunLike.coe` is a `MonoidHom`. -/\n@[to_additive (attr := simps) \"`FunLike.coe` is an `AddMonoidHom`.\"]\ndef coeFnMonoidHom [MulOneClass Y] : LocallyConstant X Y \u2192* X \u2192 Y where\n  toFun := FunLike.coe\n  map_one' := rfl\n  map_mul' _ _ := rfl\n#align locally_constant.coe_fn_monoid_hom LocallyConstant.coeFnMonoidHom\n#align locally_constant.coe_fn_add_monoid_hom LocallyConstant.coeFnAddMonoidHom\n\n/-- The constant-function embedding, as a multiplicative monoid hom. -/\n@[to_additive (attr := simps) \"The constant-function embedding, as an additive monoid hom.\"]\ndef constMonoidHom [MulOneClass Y] : Y \u2192* LocallyConstant X Y where\n  toFun := const X\n  map_one' := rfl\n  map_mul' _ _ := rfl\n#align locally_constant.const_monoid_hom LocallyConstant.constMonoidHom\n#align locally_constant.const_add_monoid_hom LocallyConstant.constAddMonoidHom\n\ninstance [MulZeroClass Y] : MulZeroClass (LocallyConstant X Y) :=\n  Function.Injective.mulZeroClass FunLike.coe FunLike.coe_injective' rfl fun _ _ => rfl\n\ninstance [MulZeroOneClass Y] : MulZeroOneClass (LocallyConstant X Y) :=\n  Function.Injective.mulZeroOneClass FunLike.coe FunLike.coe_injective' rfl rfl fun _ _ => rfl\n\nsection CharFn\n\nvariable (Y) [MulZeroOneClass Y] {U V : Set X}\n\n/-- Characteristic functions are locally constant functions taking `x : X` to `1` if `x \u2208 U`,\n  where `U` is a clopen set, and `0` otherwise. -/\nnoncomputable def charFn (hU : IsClopen U) : LocallyConstant X Y :=\n  indicator 1 hU\n#align locally_constant.char_fn LocallyConstant.charFn\n\ntheorem coe_charFn (hU : IsClopen U) : (charFn Y hU : X \u2192 Y) = Set.indicator U 1 :=\n  rfl\n#align locally_constant.coe_char_fn LocallyConstant.coe_charFn\n\ntheorem charFn_eq_one [Nontrivial Y] (x : X) (hU : IsClopen U) : charFn Y hU x = (1 : Y) \u2194 x \u2208 U :=\n  Set.indicator_eq_one_iff_mem _\n#align locally_constant.char_fn_eq_one LocallyConstant.charFn_eq_one\n\ntheorem charFn_eq_zero [Nontrivial Y] (x : X) (hU : IsClopen U) : charFn Y hU x = (0 : Y) \u2194 x \u2209 U :=\n  Set.indicator_eq_zero_iff_not_mem _\n#align locally_constant.char_fn_eq_zero LocallyConstant.charFn_eq_zero\n\ntheorem charFn_inj [Nontrivial Y] (hU : IsClopen U) (hV : IsClopen V)\n    (h : charFn Y hU = charFn Y hV) : U = V :=\n  Set.indicator_one_inj Y <| coe_inj.mpr h\n#align locally_constant.char_fn_inj LocallyConstant.charFn_inj\n\nend CharFn\n\n@[to_additive]\ninstance [Div Y] : Div (LocallyConstant X Y) where\n  div f g := \u27e8f / g, f.isLocallyConstant.div g.isLocallyConstant\u27e9\n\n@[to_additive]\ntheorem coe_div [Div Y] (f g : LocallyConstant X Y) : \u21d1(f / g) = f / g :=\n  rfl\n#align locally_constant.coe_div LocallyConstant.coe_div\n#align locally_constant.coe_sub LocallyConstant.coe_sub\n\n@[to_additive]\ntheorem div_apply [Div Y] (f g : LocallyConstant X Y) (x : X) : (f / g) x = f x / g x :=\n  rfl\n#align locally_constant.div_apply LocallyConstant.div_apply\n#align locally_constant.sub_apply LocallyConstant.sub_apply\n\n@[to_additive]\ninstance [Semigroup Y] : Semigroup (LocallyConstant X Y) :=\n  Function.Injective.semigroup FunLike.coe FunLike.coe_injective' fun _ _ => rfl\n\ninstance [SemigroupWithZero Y] : SemigroupWithZero (LocallyConstant X Y) :=\n  Function.Injective.semigroupWithZero FunLike.coe FunLike.coe_injective' rfl fun _ _ => rfl\n\n@[to_additive]\ninstance [CommSemigroup Y] : CommSemigroup (LocallyConstant X Y) :=\n  Function.Injective.commSemigroup FunLike.coe FunLike.coe_injective' fun _ _ => rfl\n\n@[to_additive]\ninstance smul [SMul \u03b1 Y] : SMul \u03b1 (LocallyConstant X Y) where\n  smul n f := f.map (n \u2022 \u00b7)\n\n@[to_additive (attr := simp)]\ntheorem coe_smul [SMul R Y] (r : R) (f : LocallyConstant X Y) : \u21d1(r \u2022 f) = r \u2022 (f : X \u2192 Y) :=\n  rfl\n#align locally_constant.coe_smul LocallyConstant.coe_smul\n\n@[to_additive]\ntheorem smul_apply [SMul R Y] (r : R) (f : LocallyConstant X Y) (x : X) : (r \u2022 f) x = r \u2022 f x :=\n  rfl\n#align locally_constant.smul_apply LocallyConstant.smul_apply\n\n@[to_additive existing LocallyConstant.smul]\ninstance [Pow Y \u03b1] : Pow (LocallyConstant X Y) \u03b1 where\n  pow f n := f.map (\u00b7 ^ n)\n\n@[to_additive]\ninstance [Monoid Y] : Monoid (LocallyConstant X Y) :=\n  Function.Injective.monoid FunLike.coe FunLike.coe_injective' rfl (fun _ _ => rfl) fun _ _ => rfl\n\ninstance [NatCast Y] : NatCast (LocallyConstant X Y) where\n  natCast n := const X n\n\ninstance [IntCast Y] : IntCast (LocallyConstant X Y) where\n  intCast n := const X n\n\ninstance [AddMonoidWithOne Y] : AddMonoidWithOne (LocallyConstant X Y) :=\n  Function.Injective.addMonoidWithOne FunLike.coe FunLike.coe_injective' rfl rfl (fun _ _ => rfl)\n    (fun _ _ => rfl) fun _ => rfl\n\n@[to_additive]\ninstance [CommMonoid Y] : CommMonoid (LocallyConstant X Y) :=\n  Function.Injective.commMonoid FunLike.coe FunLike.coe_injective' rfl (fun _ _ => rfl)\n    fun _ _ => rfl\n\n@[to_additive]\ninstance [Group Y] : Group (LocallyConstant X Y) :=\n  Function.Injective.group FunLike.coe FunLike.coe_injective' rfl (fun _ _ => rfl)\n    (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\n@[to_additive]\ninstance [CommGroup Y] : CommGroup (LocallyConstant X Y) :=\n  Function.Injective.commGroup FunLike.coe FunLike.coe_injective' rfl (fun _ _ => rfl)\n    (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\ninstance [Distrib Y] : Distrib (LocallyConstant X Y) :=\n  Function.Injective.distrib FunLike.coe FunLike.coe_injective' (fun _ _ => rfl) fun _ _ => rfl\n\ninstance [NonUnitalNonAssocSemiring Y] : NonUnitalNonAssocSemiring (LocallyConstant X Y) :=\n  Function.Injective.nonUnitalNonAssocSemiring FunLike.coe FunLike.coe_injective' rfl\n    (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\ninstance [NonUnitalSemiring Y] : NonUnitalSemiring (LocallyConstant X Y) :=\n  Function.Injective.nonUnitalSemiring FunLike.coe FunLike.coe_injective' rfl\n    (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\ninstance [NonAssocSemiring Y] : NonAssocSemiring (LocallyConstant X Y) :=\n  Function.Injective.nonAssocSemiring FunLike.coe FunLike.coe_injective' rfl rfl\n    (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl\n\n/-- The constant-function embedding, as a ring hom.  -/\n@[simps]\ndef constRingHom [NonAssocSemiring Y] : Y \u2192+* LocallyConstant X Y :=\n  { constMonoidHom, constAddMonoidHom with toFun := const X }\n#align locally_constant.const_ring_hom LocallyConstant.constRingHom\n\ninstance [Semiring Y] : Semiring (LocallyConstant X Y) :=\n  Function.Injective.semiring FunLike.coe FunLike.coe_injective' rfl rfl\n    (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl\n\ninstance [NonUnitalCommSemiring Y] : NonUnitalCommSemiring (LocallyConstant X Y) :=\n  Function.Injective.nonUnitalCommSemiring FunLike.coe FunLike.coe_injective' rfl\n    (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\ninstance [CommSemiring Y] : CommSemiring (LocallyConstant X Y) :=\n  Function.Injective.commSemiring FunLike.coe FunLike.coe_injective' rfl rfl\n    (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl\n\ninstance [NonUnitalNonAssocRing Y] : NonUnitalNonAssocRing (LocallyConstant X Y) :=\n  Function.Injective.nonUnitalNonAssocRing FunLike.coe FunLike.coe_injective' rfl (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\ninstance [NonUnitalRing Y] : NonUnitalRing (LocallyConstant X Y) :=\n  Function.Injective.nonUnitalRing FunLike.coe FunLike.coe_injective' rfl (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\ninstance [NonAssocRing Y] : NonAssocRing (LocallyConstant X Y) :=\n  Function.Injective.nonAssocRing FunLike.coe FunLike.coe_injective' rfl rfl (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n    (fun _ => rfl) (fun _ => rfl)\n\ninstance [Ring Y] : Ring (LocallyConstant X Y) :=\n  Function.Injective.ring FunLike.coe FunLike.coe_injective' rfl rfl (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl\n\ninstance [NonUnitalCommRing Y] : NonUnitalCommRing (LocallyConstant X Y) :=\n  Function.Injective.nonUnitalCommRing FunLike.coe FunLike.coe_injective' rfl (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n\ninstance [CommRing Y] : CommRing (LocallyConstant X Y) :=\n  Function.Injective.commRing FunLike.coe FunLike.coe_injective' rfl rfl (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl\n\nvariable {R : Type _}\n\ninstance [Monoid R] [MulAction R Y] : MulAction R (LocallyConstant X Y) :=\n  Function.Injective.mulAction _ coe_injective fun _ _ => rfl\n\ninstance [Monoid R] [AddMonoid Y] [DistribMulAction R Y] :\n    DistribMulAction R (LocallyConstant X Y) :=\n  Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective fun _ _ => rfl\n\ninstance [Semiring R] [AddCommMonoid Y] [Module R Y] : Module R (LocallyConstant X Y) :=\n  Function.Injective.module R coeFnAddMonoidHom coe_injective fun _ _ => rfl\n\nsection Algebra\n\nvariable [CommSemiring R] [Semiring Y] [Algebra R Y]\n\ninstance : Algebra R (LocallyConstant X Y) where\n  toRingHom := constRingHom.comp <| algebraMap R Y\n  commutes' := by\n    intros\n    ext\n    exact Algebra.commutes' _ _\n  smul_def' := by\n    intros\n    ext\n    exact Algebra.smul_def' _ _\n\n@[simp]\ntheorem coe_algebraMap (r : R) : \u21d1(algebraMap R (LocallyConstant X Y) r) = algebraMap R (X \u2192 Y) r :=\n  rfl\n#align locally_constant.coe_algebra_map LocallyConstant.coe_algebraMap\n\nend Algebra\n\nend LocallyConstant\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/LocallyConstant/Algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7383383730328862}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.degree.definitions\n! leanprover-community/mathlib commit 808ea4ebfabeb599f21ec4ae87d6dc969597887f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fintype.BigOperators\nimport Mathlib.Data.Nat.WithBot\nimport Mathlib.Data.Polynomial.Monomial\nimport Mathlib.Data.Polynomial.Coeff\nimport Mathlib.Data.Nat.Cast.WithTop\n\n\n/-!\n# Theory of univariate polynomials\n\nThe definitions include\n`degree`, `Monic`, `leadingCoeff`\n\nResults include\n- `degree_mul` : The degree of the product is the sum of degrees\n- `leadingCoeff_add_of_degree_eq` and `leadingCoeff_add_of_degree_lt` :\n    The leading_coefficient of a sum is determined by the leading coefficients and degrees\n-/\n\n-- Porting note: `Mathlib.Data.Nat.Cast.WithTop` should be imported for `Nat.cast_withBot`.\n\nset_option linter.uppercaseLean3 false\n\nnoncomputable section\n\nopen Finsupp Finset\n\nopen BigOperators Classical Polynomial\n\nnamespace Polynomial\n\nuniverse u v\n\nvariable {R : Type u} {S : Type v} {a b c d : R} {n m : \u2115}\n\nsection Semiring\n\nvariable [Semiring R] {p q r : R[X]}\n\n/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.\n`degree p = some n` when `p \u2260 0` and `n` is the highest power of `X` that appears in `p`, otherwise\n`degree 0 = \u22a5`. -/\ndef degree (p : R[X]) : WithBot \u2115 :=\n  p.support.max\n#align polynomial.degree Polynomial.degree\n\ntheorem degree_lt_wf : WellFounded fun p q : R[X] => degree p < degree q :=\n  InvImage.wf degree (WithBot.wellFounded_lt Nat.lt_wfRel.wf)\n#align polynomial.degree_lt_wf Polynomial.degree_lt_wf\n\ninstance : WellFoundedRelation R[X] :=\n  \u27e8_, degree_lt_wf\u27e9\n\n/-- `natDegree p` forces `degree p` to \u2115, by defining nat_degree 0 = 0. -/\ndef natDegree (p : R[X]) : \u2115 :=\n  (degree p).unbot' 0\n#align polynomial.nat_degree Polynomial.natDegree\n\n/-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`-/\ndef leadingCoeff (p : R[X]) : R :=\n  coeff p (natDegree p)\n#align polynomial.leading_coeff Polynomial.leadingCoeff\n\n/-- a polynomial is `Monic` if its leading coefficient is 1 -/\ndef Monic (p : R[X]) :=\n  leadingCoeff p = (1 : R)\n#align polynomial.monic Polynomial.Monic\n\n@[nontriviality]\ntheorem monic_of_subsingleton [Subsingleton R] (p : R[X]) : Monic p :=\n  Subsingleton.elim _ _\n#align polynomial.monic_of_subsingleton Polynomial.monic_of_subsingleton\n\ntheorem Monic.def : Monic p \u2194 leadingCoeff p = 1 :=\n  Iff.rfl\n#align polynomial.monic.def Polynomial.Monic.def\n\ninstance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance\n#align polynomial.monic.decidable Polynomial.Monic.decidable\n\n@[simp]\ntheorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 :=\n  hp\n#align polynomial.monic.leading_coeff Polynomial.Monic.leadingCoeff\n\ntheorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 :=\n  hp\n#align polynomial.monic.coeff_nat_degree Polynomial.Monic.coeff_natDegree\n\n@[simp]\ntheorem degree_zero : degree (0 : R[X]) = \u22a5 :=\n  rfl\n#align polynomial.degree_zero Polynomial.degree_zero\n\n@[simp]\ntheorem natDegree_zero : natDegree (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.nat_degree_zero Polynomial.natDegree_zero\n\n@[simp]\ntheorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p :=\n  rfl\n#align polynomial.coeff_nat_degree Polynomial.coeff_natDegree\n\ntheorem degree_eq_bot : degree p = \u22a5 \u2194 p = 0 :=\n  \u27e8fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm \u25b8 rfl\u27e9\n#align polynomial.degree_eq_bot Polynomial.degree_eq_bot\n\n@[nontriviality]\ntheorem degree_of_subsingleton [Subsingleton R] : degree p = \u22a5 := by\n  rw [Subsingleton.elim p 0, degree_zero]\n#align polynomial.degree_of_subsingleton Polynomial.degree_of_subsingleton\n\n@[nontriviality]\ntheorem natDegree_of_subsingleton [Subsingleton R] : natDegree p = 0 := by\n  rw [Subsingleton.elim p 0, natDegree_zero]\n#align polynomial.nat_degree_of_subsingleton Polynomial.natDegree_of_subsingleton\n\ntheorem degree_eq_natDegree (hp : p \u2260 0) : degree p = (natDegree p : WithBot \u2115) := by\n  let \u27e8n, hn\u27e9 := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp))\n  have hn : degree p = some n := Classical.not_not.1 hn\n  rw [natDegree, hn]; rfl\n#align polynomial.degree_eq_nat_degree Polynomial.degree_eq_natDegree\n\ntheorem degree_eq_iff_natDegree_eq {p : R[X]} {n : \u2115} (hp : p \u2260 0) :\n    p.degree = n \u2194 p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe\n#align polynomial.degree_eq_iff_nat_degree_eq Polynomial.degree_eq_iff_natDegree_eq\n\ntheorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : \u2115} (hn : 0 < n) :\n    p.degree = n \u2194 p.natDegree = n := by\n  constructor\n  \u00b7 intro H\n    rwa [\u2190 degree_eq_iff_natDegree_eq]\n    rintro rfl\n    rw [degree_zero] at H\n    exact Option.noConfusion H\n  \u00b7 intro H\n    rwa [degree_eq_iff_natDegree_eq]\n    rintro rfl\n    rw [natDegree_zero] at H\n    rw [H] at hn\n    exact lt_irrefl _ hn\n#align polynomial.degree_eq_iff_nat_degree_eq_of_pos Polynomial.degree_eq_iff_natDegree_eq_of_pos\n\ntheorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : \u2115} (h : degree p = n) : natDegree p = n :=\n  have hp0 : p \u2260 0 := fun hp0 => by rw [hp0] at h; exact Option.noConfusion h\n  Option.some_inj.1 <| show (natDegree p : WithBot \u2115) = n by rwa [\u2190 degree_eq_natDegree hp0]\n#align polynomial.nat_degree_eq_of_degree_eq_some Polynomial.natDegree_eq_of_degree_eq_some\n\n@[simp]\ntheorem degree_le_natDegree : degree p \u2264 natDegree p :=\n  WithBot.giUnbot'Bot.gc.le_u_l _\n#align polynomial.degree_le_nat_degree Polynomial.degree_le_natDegree\n\ntheorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) :\n    natDegree p = natDegree q := by unfold natDegree; rw [h]\n#align polynomial.nat_degree_eq_of_degree_eq Polynomial.natDegree_eq_of_degree_eq\n\ntheorem le_degree_of_ne_zero (h : coeff p n \u2260 0) : (n : WithBot \u2115) \u2264 degree p :=\n  show @LE.le (WithBot \u2115) _ (some n : WithBot \u2115) (p.support.sup some : WithBot \u2115) from\n    Finset.le_sup (mem_support_iff.2 h)\n#align polynomial.le_degree_of_ne_zero Polynomial.le_degree_of_ne_zero\n\ntheorem le_natDegree_of_ne_zero (h : coeff p n \u2260 0) : n \u2264 natDegree p := by\n  -- Porting note: `Nat.cast_withBot` is required.\n  rw [\u2190 WithBot.coe_le_coe, \u2190 Nat.cast_withBot,\n    \u2190 Nat.cast_withBot, \u2190 degree_eq_natDegree]\n  exact le_degree_of_ne_zero h\n  \u00b7 intro h\n    subst h\n    exact h rfl\n#align polynomial.le_nat_degree_of_ne_zero Polynomial.le_natDegree_of_ne_zero\n\ntheorem le_natDegree_of_mem_supp (a : \u2115) : a \u2208 p.support \u2192 a \u2264 natDegree p :=\n  le_natDegree_of_ne_zero \u2218 mem_support_iff.mp\n#align polynomial.le_nat_degree_of_mem_supp Polynomial.le_natDegree_of_mem_supp\n\ntheorem degree_eq_of_le_of_coeff_ne_zero (pn : p.degree \u2264 n) (p1 : p.coeff n \u2260 0) : p.degree = n :=\n  pn.antisymm (le_degree_of_ne_zero p1)\n#align polynomial.degree_eq_of_le_of_coeff_ne_zero Polynomial.degree_eq_of_le_of_coeff_ne_zero\n\ntheorem natDegree_eq_of_le_of_coeff_ne_zero (pn : p.natDegree \u2264 n) (p1 : p.coeff n \u2260 0) :\n    p.natDegree = n :=\n  pn.antisymm (le_natDegree_of_ne_zero p1)\n#align polynomial.nat_degree_eq_of_le_of_coeff_ne_zero Polynomial.natDegree_eq_of_le_of_coeff_ne_zero\n\ntheorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support \u2286 g.support) :\n    f.degree \u2264 g.degree :=\n  Finset.sup_mono h\n#align polynomial.degree_mono Polynomial.degree_mono\n\ntheorem supp_subset_range (h : natDegree p < m) : p.support \u2286 Finset.range m := fun _n hn =>\n  mem_range.2 <| (le_natDegree_of_mem_supp _ hn).trans_lt h\n#align polynomial.supp_subset_range Polynomial.supp_subset_range\n\ntheorem supp_subset_range_natDegree_succ : p.support \u2286 Finset.range (natDegree p + 1) :=\n  supp_subset_range (Nat.lt_succ_self _)\n#align polynomial.supp_subset_range_nat_degree_succ Polynomial.supp_subset_range_natDegree_succ\n\ntheorem degree_le_degree (h : coeff q (natDegree p) \u2260 0) : degree p \u2264 degree q := by\n  by_cases hp : p = 0\n  \u00b7 rw [hp]\n    exact bot_le\n  \u00b7 rw [degree_eq_natDegree hp]\n    exact le_degree_of_ne_zero h\n#align polynomial.degree_le_degree Polynomial.degree_le_degree\n\ntheorem degree_ne_of_natDegree_ne {n : \u2115} : p.natDegree \u2260 n \u2192 degree p \u2260 n :=\n  -- Porting note: `Nat.cast_withBot` is required.\n  mt fun h => by rw [natDegree, h, Nat.cast_withBot, WithBot.unbot'_coe]\n#align polynomial.degree_ne_of_nat_degree_ne Polynomial.degree_ne_of_natDegree_ne\n\ntheorem natDegree_le_iff_degree_le {n : \u2115} : natDegree p \u2264 n \u2194 degree p \u2264 n :=\n  WithBot.unbot'_bot_le_iff\n#align polynomial.nat_degree_le_iff_degree_le Polynomial.natDegree_le_iff_degree_le\n\ntheorem natDegree_lt_iff_degree_lt (hp : p \u2260 0) : p.natDegree < n \u2194 p.degree < \u2191n :=\n  WithBot.unbot'_lt_iff <| degree_eq_bot.not.mpr hp\n#align polynomial.nat_degree_lt_iff_degree_lt Polynomial.natDegree_lt_iff_degree_lt\n\nalias natDegree_le_iff_degree_le \u2194 ..\n#align polynomial.degree_le_of_nat_degree_le Polynomial.degree_le_of_natDegree_le\n#align polynomial.nat_degree_le_of_degree_le Polynomial.natDegree_le_of_degree_le\n\ntheorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree \u2264 q.degree) :\n    p.natDegree \u2264 q.natDegree :=\n  WithBot.giUnbot'Bot.gc.monotone_l hpq\n#align polynomial.nat_degree_le_nat_degree Polynomial.natDegree_le_natDegree\n\ntheorem natDegree_lt_natDegree {p q : R[X]} (hp : p \u2260 0) (hpq : p.degree < q.degree) :\n    p.natDegree < q.natDegree := by\n  by_cases hq : q = 0; \u00b7 exact (not_lt_bot <| hq \u25b8 hpq).elim\n  -- Porting note: `Nat.cast_withBot` is required.\n  rwa [degree_eq_natDegree hp, degree_eq_natDegree hq,\n    Nat.cast_withBot, Nat.cast_withBot, WithBot.coe_lt_coe] at hpq\n#align polynomial.nat_degree_lt_nat_degree Polynomial.natDegree_lt_natDegree\n\n@[simp]\ntheorem degree_C (ha : a \u2260 0) : degree (C a) = (0 : WithBot \u2115) := by\n  rw [degree, \u2190 monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton,\n    WithBot.coe_zero]\n#align polynomial.degree_C Polynomial.degree_C\n\ntheorem degree_C_le : degree (C a) \u2264 0 := by\n  by_cases h : a = 0\n  \u00b7 rw [h, C_0]\n    exact bot_le\n  \u00b7 rw [degree_C h]\n#align polynomial.degree_C_le Polynomial.degree_C_le\n\ntheorem degree_C_lt : degree (C a) < 1 :=\n  degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one\n#align polynomial.degree_C_lt Polynomial.degree_C_lt\n\ntheorem degree_one_le : degree (1 : R[X]) \u2264 (0 : WithBot \u2115) := by rw [\u2190 C_1]; exact degree_C_le\n#align polynomial.degree_one_le Polynomial.degree_one_le\n\n@[simp]\ntheorem natDegree_C (a : R) : natDegree (C a) = 0 := by\n  by_cases ha : a = 0\n  \u00b7 have : C a = 0 := by rw [ha, C_0]\n    rw [natDegree, degree_eq_bot.2 this]\n    rfl\n  \u00b7 rw [natDegree, degree_C ha]\n    rfl\n#align polynomial.nat_degree_C Polynomial.natDegree_C\n\n@[simp]\ntheorem natDegree_one : natDegree (1 : R[X]) = 0 :=\n  natDegree_C 1\n#align polynomial.nat_degree_one Polynomial.natDegree_one\n\n@[simp]\ntheorem natDegree_nat_cast (n : \u2115) : natDegree (n : R[X]) = 0 := by\n  simp only [\u2190 C_eq_nat_cast, natDegree_C]\n#align polynomial.nat_degree_nat_cast Polynomial.natDegree_nat_cast\n\n@[simp]\ntheorem degree_monomial (n : \u2115) (ha : a \u2260 0) : degree (monomial n a) = n := by\n  rw [degree, support_monomial n ha]; rfl\n#align polynomial.degree_monomial Polynomial.degree_monomial\n\n@[simp]\ntheorem degree_C_mul_X_pow (n : \u2115) (ha : a \u2260 0) : degree (C a * X ^ n) = n := by\n  rw [C_mul_X_pow_eq_monomial, degree_monomial n ha]\n#align polynomial.degree_C_mul_X_pow Polynomial.degree_C_mul_X_pow\n\ntheorem degree_C_mul_X (ha : a \u2260 0) : degree (C a * X) = 1 := by\n  simpa only [pow_one] using degree_C_mul_X_pow 1 ha\n#align polynomial.degree_C_mul_X Polynomial.degree_C_mul_X\n\ntheorem degree_monomial_le (n : \u2115) (a : R) : degree (monomial n a) \u2264 n :=\n  if h : a = 0 then by rw [h, (monomial n).map_zero]; exact bot_le\n  else le_of_eq (degree_monomial n h)\n#align polynomial.degree_monomial_le Polynomial.degree_monomial_le\n\ntheorem degree_C_mul_X_pow_le (n : \u2115) (a : R) : degree (C a * X ^ n) \u2264 n := by\n  rw [C_mul_X_pow_eq_monomial]\n  apply degree_monomial_le\n#align polynomial.degree_C_mul_X_pow_le Polynomial.degree_C_mul_X_pow_le\n\ntheorem degree_C_mul_X_le (a : R) : degree (C a * X) \u2264 1 := by\n  simpa only [pow_one] using degree_C_mul_X_pow_le 1 a\n#align polynomial.degree_C_mul_X_le Polynomial.degree_C_mul_X_le\n\n@[simp]\ntheorem natDegree_C_mul_X_pow (n : \u2115) (a : R) (ha : a \u2260 0) : natDegree (C a * X ^ n) = n :=\n  natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)\n#align polynomial.nat_degree_C_mul_X_pow Polynomial.natDegree_C_mul_X_pow\n\n@[simp]\ntheorem natDegree_C_mul_X (a : R) (ha : a \u2260 0) : natDegree (C a * X) = 1 := by\n  simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha\n#align polynomial.nat_degree_C_mul_X Polynomial.natDegree_C_mul_X\n\n@[simp]\ntheorem natDegree_monomial [DecidableEq R] (i : \u2115) (r : R) :\n    natDegree (monomial i r) = if r = 0 then 0 else i := by\n  split_ifs with hr\n  \u00b7 simp [hr]\n  \u00b7 rw [\u2190 C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr]\n#align polynomial.nat_degree_monomial Polynomial.natDegree_monomial\n\ntheorem natDegree_monomial_le (a : R) {m : \u2115} : (monomial m a).natDegree \u2264 m := by\n  rw [Polynomial.natDegree_monomial]\n  split_ifs\n  exacts[Nat.zero_le _, rfl.le]\n#align polynomial.nat_degree_monomial_le Polynomial.natDegree_monomial_le\n\ntheorem natDegree_monomial_eq (i : \u2115) {r : R} (r0 : r \u2260 0) : (monomial i r).natDegree = i :=\n  Eq.trans (natDegree_monomial _ _) (if_neg r0)\n#align polynomial.nat_degree_monomial_eq Polynomial.natDegree_monomial_eq\n\ntheorem coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=\n  Classical.not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))\n#align polynomial.coeff_eq_zero_of_degree_lt Polynomial.coeff_eq_zero_of_degree_lt\n\ntheorem coeff_eq_zero_of_natDegree_lt {p : R[X]} {n : \u2115} (h : p.natDegree < n) :\n    p.coeff n = 0 := by\n  apply coeff_eq_zero_of_degree_lt\n  by_cases hp : p = 0\n  \u00b7 subst hp\n    exact WithBot.bot_lt_coe n\n  -- Porting note: `Nat.cast_withBot` is required.\n  \u00b7 rwa [degree_eq_natDegree hp, Nat.cast_withBot, Nat.cast_withBot, WithBot.coe_lt_coe]\n#align polynomial.coeff_eq_zero_of_nat_degree_lt Polynomial.coeff_eq_zero_of_natDegree_lt\n\ntheorem ext_iff_natDegree_le {p q : R[X]} {n : \u2115} (hp : p.natDegree \u2264 n) (hq : q.natDegree \u2264 n) :\n    p = q \u2194 \u2200 i \u2264 n, p.coeff i = q.coeff i := by\n  refine' Iff.trans Polynomial.ext_iff _\n  refine' forall_congr' fun i => \u27e8fun h _ => h, fun h => _\u27e9\n  refine' (le_or_lt i n).elim h fun k => _\n  refine'\n    (coeff_eq_zero_of_natDegree_lt (hp.trans_lt k)).trans\n      (coeff_eq_zero_of_natDegree_lt (hq.trans_lt k)).symm\n#align polynomial.ext_iff_nat_degree_le Polynomial.ext_iff_natDegree_le\n\ntheorem ext_iff_degree_le {p q : R[X]} {n : \u2115} (hp : p.degree \u2264 n) (hq : q.degree \u2264 n) :\n    p = q \u2194 \u2200 i \u2264 n, p.coeff i = q.coeff i :=\n  ext_iff_natDegree_le (natDegree_le_of_degree_le hp) (natDegree_le_of_degree_le hq)\n#align polynomial.ext_iff_degree_le Polynomial.ext_iff_degree_le\n\n@[simp]\ntheorem coeff_natDegree_succ_eq_zero {p : R[X]} : p.coeff (p.natDegree + 1) = 0 :=\n  coeff_eq_zero_of_natDegree_lt (lt_add_one _)\n#align polynomial.coeff_nat_degree_succ_eq_zero Polynomial.coeff_natDegree_succ_eq_zero\n\n-- We need the explicit `Decidable` argument here because an exotic one shows up in a moment!\ntheorem ite_le_natDegree_coeff (p : R[X]) (n : \u2115) (I : Decidable (n < 1 + natDegree p)) :\n    @ite _ (n < 1 + natDegree p) I (coeff p n) 0 = coeff p n := by\n  split_ifs with h\n  \u00b7 rfl\n  \u00b7 exact (coeff_eq_zero_of_natDegree_lt (not_le.1 fun w => h (Nat.lt_one_add_iff.2 w))).symm\n#align polynomial.ite_le_nat_degree_coeff Polynomial.ite_le_natDegree_coeff\n\ntheorem as_sum_support (p : R[X]) : p = \u2211 i in p.support, monomial i (p.coeff i) :=\n  (sum_monomial_eq p).symm\n#align polynomial.as_sum_support Polynomial.as_sum_support\n\ntheorem as_sum_support_C_mul_X_pow (p : R[X]) : p = \u2211 i in p.support, C (p.coeff i) * X ^ i :=\n  _root_.trans p.as_sum_support <| by simp only [C_mul_X_pow_eq_monomial]\n#align polynomial.as_sum_support_C_mul_X_pow Polynomial.as_sum_support_C_mul_X_pow\n\n/-- We can reexpress a sum over `p.support` as a sum over `range n`,\nfor any `n` satisfying `p.natDegree < n`.\n-/\ntheorem sum_over_range' [AddCommMonoid S] (p : R[X]) {f : \u2115 \u2192 R \u2192 S} (h : \u2200 n, f n 0 = 0) (n : \u2115)\n    (w : p.natDegree < n) : p.sum f = \u2211 a : \u2115 in range n, f a (coeff p a) := by\n  rcases p with \u27e8\u27e9\n  have := supp_subset_range w\n  simp only [Polynomial.sum, support, coeff, natDegree, degree] at this\u22a2\n  exact Finsupp.sum_of_support_subset _ this _ fun n _hn => h n\n#align polynomial.sum_over_range' Polynomial.sum_over_range'\n\n/-- We can reexpress a sum over `p.support` as a sum over `range (p.natDegree + 1)`.\n-/\ntheorem sum_over_range [AddCommMonoid S] (p : R[X]) {f : \u2115 \u2192 R \u2192 S} (h : \u2200 n, f n 0 = 0) :\n    p.sum f = \u2211 a : \u2115 in range (p.natDegree + 1), f a (coeff p a) :=\n  sum_over_range' p h (p.natDegree + 1) (lt_add_one _)\n#align polynomial.sum_over_range Polynomial.sum_over_range\n\n-- TODO this is essentially a duplicate of `sum_over_range`, and should be removed.\ntheorem sum_fin [AddCommMonoid S] (f : \u2115 \u2192 R \u2192 S) (hf : \u2200 i, f i 0 = 0) {n : \u2115} {p : R[X]}\n    (hn : p.degree < n) : (\u2211 i : Fin n, f i (p.coeff i)) = p.sum f := by\n  by_cases hp : p = 0\n  \u00b7 rw [hp, sum_zero_index, Finset.sum_eq_zero]\n    intro i _\n    exact hf i\n  rw [sum_over_range' _ hf n ((natDegree_lt_iff_degree_lt hp).mpr hn),\n    Fin.sum_univ_eq_sum_range fun i => f i (p.coeff i)]\n#align polynomial.sum_fin Polynomial.sum_fin\n\ntheorem as_sum_range' (p : R[X]) (n : \u2115) (w : p.natDegree < n) :\n    p = \u2211 i in range n, monomial i (coeff p i) :=\n  p.sum_monomial_eq.symm.trans <| p.sum_over_range' monomial_zero_right _ w\n#align polynomial.as_sum_range' Polynomial.as_sum_range'\n\ntheorem as_sum_range (p : R[X]) : p = \u2211 i in range (p.natDegree + 1), monomial i (coeff p i) :=\n  p.sum_monomial_eq.symm.trans <| p.sum_over_range <| monomial_zero_right\n#align polynomial.as_sum_range Polynomial.as_sum_range\n\ntheorem as_sum_range_C_mul_X_pow (p : R[X]) :\n    p = \u2211 i in range (p.natDegree + 1), C (coeff p i) * X ^ i :=\n  p.as_sum_range.trans <| by simp only [C_mul_X_pow_eq_monomial]\n#align polynomial.as_sum_range_C_mul_X_pow Polynomial.as_sum_range_C_mul_X_pow\n\ntheorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n \u2260 0 := fun h =>\n  mem_support_iff.mp (mem_of_max hn) h\n#align polynomial.coeff_ne_zero_of_eq_degree Polynomial.coeff_ne_zero_of_eq_degree\n\ntheorem eq_X_add_C_of_degree_le_one (h : degree p \u2264 1) : p = C (p.coeff 1) * X + C (p.coeff 0) :=\n  ext fun n =>\n    Nat.casesOn n (by simp) fun n =>\n      Nat.casesOn n (by simp [coeff_C]) fun m => by\n        -- Porting note: `by decide` \u2192 `Iff.mpr ..`\n        have : degree p < m.succ.succ := lt_of_le_of_lt h\n          (Iff.mpr WithBot.coe_lt_coe <| Nat.succ_lt_succ <| Nat.zero_lt_succ m)\n        simp [coeff_eq_zero_of_degree_lt this, coeff_C, Nat.succ_ne_zero, coeff_X, Nat.succ_inj',\n          @eq_comm \u2115 0]\n#align polynomial.eq_X_add_C_of_degree_le_one Polynomial.eq_X_add_C_of_degree_le_one\n\ntheorem eq_X_add_C_of_degree_eq_one (h : degree p = 1) :\n    p = C p.leadingCoeff * X + C (p.coeff 0) :=\n  (eq_X_add_C_of_degree_le_one (show degree p \u2264 1 from h \u25b8 le_rfl)).trans\n    (by simp only [leadingCoeff, natDegree_eq_of_degree_eq_some h]; rfl)\n#align polynomial.eq_X_add_C_of_degree_eq_one Polynomial.eq_X_add_C_of_degree_eq_one\n\ntheorem eq_X_add_C_of_natDegree_le_one (h : natDegree p \u2264 1) :\n    p = C (p.coeff 1) * X + C (p.coeff 0) :=\n  eq_X_add_C_of_degree_le_one <| degree_le_of_natDegree_le h\n#align polynomial.eq_X_add_C_of_nat_degree_le_one Polynomial.eq_X_add_C_of_natDegree_le_one\n\ntheorem Monic.eq_X_add_C (hm : p.Monic) (hnd : p.natDegree = 1) : p = X + C (p.coeff 0) := by\n  rw [\u2190 one_mul X, \u2190 C_1, \u2190 hm.coeff_natDegree, hnd, \u2190 eq_X_add_C_of_natDegree_le_one hnd.le]\n#align polynomial.monic.eq_X_add_C Polynomial.Monic.eq_X_add_C\n\n\n\ntheorem degree_X_pow_le (n : \u2115) : degree (X ^ n : R[X]) \u2264 n := by\n  simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R)\n#align polynomial.degree_X_pow_le Polynomial.degree_X_pow_le\n\ntheorem degree_X_le : degree (X : R[X]) \u2264 1 :=\n  degree_monomial_le _ _\n#align polynomial.degree_X_le Polynomial.degree_X_le\n\ntheorem natDegree_X_le : (X : R[X]).natDegree \u2264 1 :=\n  natDegree_le_of_degree_le degree_X_le\n#align polynomial.nat_degree_X_le Polynomial.natDegree_X_le\n\ntheorem mem_support_C_mul_X_pow {n a : \u2115} {c : R} (h : a \u2208 support (C c * X ^ n)) : a = n :=\n  mem_singleton.1 <| support_C_mul_X_pow' n c h\n#align polynomial.mem_support_C_mul_X_pow Polynomial.mem_support_C_mul_X_pow\n\ntheorem card_support_C_mul_X_pow_le_one {c : R} {n : \u2115} : card (support (C c * X ^ n)) \u2264 1 := by\n  rw [\u2190 card_singleton n]\n  apply card_le_of_subset (support_C_mul_X_pow' n c)\n#align polynomial.card_support_C_mul_X_pow_le_one Polynomial.card_support_C_mul_X_pow_le_one\n\ntheorem card_supp_le_succ_natDegree (p : R[X]) : p.support.card \u2264 p.natDegree + 1 := by\n  rw [\u2190 Finset.card_range (p.natDegree + 1)]\n  exact Finset.card_le_of_subset supp_subset_range_natDegree_succ\n#align polynomial.card_supp_le_succ_nat_degree Polynomial.card_supp_le_succ_natDegree\n\ntheorem le_degree_of_mem_supp (a : \u2115) : a \u2208 p.support \u2192 \u2191a \u2264 degree p :=\n  le_degree_of_ne_zero \u2218 mem_support_iff.mp\n#align polynomial.le_degree_of_mem_supp Polynomial.le_degree_of_mem_supp\n\ntheorem nonempty_support_iff : p.support.Nonempty \u2194 p \u2260 0 := by\n  rw [Ne.def, nonempty_iff_ne_empty, Ne.def, \u2190 support_eq_empty]\n#align polynomial.nonempty_support_iff Polynomial.nonempty_support_iff\n\nend Semiring\n\nsection NonzeroSemiring\n\nvariable [Semiring R] [Nontrivial R] {p q : R[X]}\n\n@[simp]\ntheorem degree_one : degree (1 : R[X]) = (0 : WithBot \u2115) :=\n  degree_C (show (1 : R) \u2260 0 from zero_ne_one.symm)\n#align polynomial.degree_one Polynomial.degree_one\n\n@[simp]\ntheorem degree_X : degree (X : R[X]) = 1 :=\n  degree_monomial _ one_ne_zero\n#align polynomial.degree_X Polynomial.degree_X\n\n@[simp]\ntheorem natDegree_X : (X : R[X]).natDegree = 1 :=\n  natDegree_eq_of_degree_eq_some degree_X\n#align polynomial.nat_degree_X Polynomial.natDegree_X\n\nend NonzeroSemiring\n\nsection Ring\n\nvariable [Ring R]\n\ntheorem coeff_mul_X_sub_C {p : R[X]} {r : R} {a : \u2115} :\n    coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r := by simp [mul_sub]\n#align polynomial.coeff_mul_X_sub_C Polynomial.coeff_mul_X_sub_C\n\n@[simp]\ntheorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg]\n#align polynomial.degree_neg Polynomial.degree_neg\n\n@[simp]\ntheorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree]\n#align polynomial.nat_degree_neg Polynomial.natDegree_neg\n\n@[simp]\ntheorem natDegree_int_cast (n : \u2124) : natDegree (n : R[X]) = 0 := by\n  rw [\u2190 C_eq_int_cast, natDegree_C]\n#align polynomial.nat_degree_int_cast Polynomial.natDegree_int_cast\n\n@[simp]\ntheorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by\n  rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg]\n#align polynomial.leading_coeff_neg Polynomial.leadingCoeff_neg\n\nend Ring\n\nsection Semiring\n\nvariable [Semiring R]\n\n/-- The second-highest coefficient, or 0 for constants -/\ndef nextCoeff (p : R[X]) : R :=\n  if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1)\n#align polynomial.next_coeff Polynomial.nextCoeff\n\n@[simp]\ntheorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by\n  rw [nextCoeff]\n  simp\n#align polynomial.next_coeff_C_eq_zero Polynomial.nextCoeff_C_eq_zero\n\ntheorem nextCoeff_of_pos_natDegree (p : R[X]) (hp : 0 < p.natDegree) :\n    nextCoeff p = p.coeff (p.natDegree - 1) := by\n  rw [nextCoeff, if_neg]\n  contrapose! hp\n  simpa\n#align polynomial.next_coeff_of_pos_nat_degree Polynomial.nextCoeff_of_pos_natDegree\n\nvariable {p q : R[X]} {\u03b9 : Type _}\n\ntheorem coeff_natDegree_eq_zero_of_degree_lt (h : degree p < degree q) :\n    coeff p (natDegree q) = 0 :=\n  coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_natDegree)\n#align polynomial.coeff_nat_degree_eq_zero_of_degree_lt Polynomial.coeff_natDegree_eq_zero_of_degree_lt\n\ntheorem ne_zero_of_degree_gt {n : WithBot \u2115} (h : n < degree p) : p \u2260 0 :=\n  mt degree_eq_bot.2 (Ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))\n#align polynomial.ne_zero_of_degree_gt Polynomial.ne_zero_of_degree_gt\n\ntheorem ne_zero_of_degree_ge_degree (hpq : p.degree \u2264 q.degree) (hp : p \u2260 0) : q \u2260 0 :=\n  Polynomial.ne_zero_of_degree_gt\n    (lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr (by rwa [Ne.def, Polynomial.degree_eq_bot])) hpq :\n      q.degree > \u22a5)\n#align polynomial.ne_zero_of_degree_ge_degree Polynomial.ne_zero_of_degree_ge_degree\n\ntheorem ne_zero_of_natDegree_gt {n : \u2115} (h : n < natDegree p) : p \u2260 0 := fun H => by\n  simp [H, Nat.not_lt_zero] at h\n#align polynomial.ne_zero_of_nat_degree_gt Polynomial.ne_zero_of_natDegree_gt\n\ntheorem degree_lt_degree (h : natDegree p < natDegree q) : degree p < degree q := by\n  by_cases hp : p = 0\n  \u00b7 simp [hp]\n    rw [bot_lt_iff_ne_bot]\n    intro hq\n    simp [hp, degree_eq_bot.mp hq, lt_irrefl] at h\n    -- Porting note: `Nat.cast_withBot` is required.\n  \u00b7 rw [degree_eq_natDegree hp, degree_eq_natDegree <| ne_zero_of_natDegree_gt h,\n      Nat.cast_withBot, Nat.cast_withBot]\n    exact_mod_cast h\n#align polynomial.degree_lt_degree Polynomial.degree_lt_degree\n\ntheorem natDegree_lt_natDegree_iff (hp : p \u2260 0) : natDegree p < natDegree q \u2194 degree p < degree q :=\n  \u27e8degree_lt_degree, by\n    intro h\n    have hq : q \u2260 0 := ne_zero_of_degree_gt h\n    -- Porting note: `Nat.cast_withBot` is required.\n    rw [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_withBot, Nat.cast_withBot] at h\n    exact_mod_cast h\u27e9\n#align polynomial.nat_degree_lt_nat_degree_iff Polynomial.natDegree_lt_natDegree_iff\n\ntheorem eq_C_of_degree_le_zero (h : degree p \u2264 0) : p = C (coeff p 0) := by\n  ext (_ | n); \u00b7 simp\n  rw [coeff_C, if_neg (Nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt]\n  exact h.trans_lt (WithBot.some_lt_some.2 n.succ_pos)\n#align polynomial.eq_C_of_degree_le_zero Polynomial.eq_C_of_degree_le_zero\n\ntheorem eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=\n  eq_C_of_degree_le_zero (h \u25b8 le_rfl)\n#align polynomial.eq_C_of_degree_eq_zero Polynomial.eq_C_of_degree_eq_zero\n\ntheorem degree_le_zero_iff : degree p \u2264 0 \u2194 p = C (coeff p 0) :=\n  \u27e8eq_C_of_degree_le_zero, fun h => h.symm \u25b8 degree_C_le\u27e9\n#align polynomial.degree_le_zero_iff Polynomial.degree_le_zero_iff\n\ntheorem degree_add_le (p q : R[X]) : degree (p + q) \u2264 max (degree p) (degree q) :=\n  calc\n    degree (p + q) = (p + q).support.sup WithBot.some := rfl\n    _ \u2264 (p.support \u222a q.support).sup WithBot.some := (sup_mono support_add)\n    _ = p.support.sup WithBot.some \u2294 q.support.sup WithBot.some := sup_union\n\n#align polynomial.degree_add_le Polynomial.degree_add_le\n\ntheorem degree_add_le_of_degree_le {p q : R[X]} {n : \u2115} (hp : degree p \u2264 n) (hq : degree q \u2264 n) :\n    degree (p + q) \u2264 n :=\n  (degree_add_le p q).trans <| max_le hp hq\n#align polynomial.degree_add_le_of_degree_le Polynomial.degree_add_le_of_degree_le\n\ntheorem natDegree_add_le (p q : R[X]) : natDegree (p + q) \u2264 max (natDegree p) (natDegree q) := by\n  cases' le_max_iff.1 (degree_add_le p q) with h h <;> simp [natDegree_le_natDegree h]\n#align polynomial.nat_degree_add_le Polynomial.natDegree_add_le\n\ntheorem natDegree_add_le_of_degree_le {p q : R[X]} {n : \u2115} (hp : natDegree p \u2264 n)\n    (hq : natDegree q \u2264 n) : natDegree (p + q) \u2264 n :=\n  (natDegree_add_le p q).trans <| max_le hp hq\n#align polynomial.nat_degree_add_le_of_degree_le Polynomial.natDegree_add_le_of_degree_le\n\n@[simp]\ntheorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.leading_coeff_zero Polynomial.leadingCoeff_zero\n\n@[simp]\ntheorem leadingCoeff_eq_zero : leadingCoeff p = 0 \u2194 p = 0 :=\n  \u27e8fun h =>\n    Classical.by_contradiction fun hp =>\n      mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)),\n    fun h => h.symm \u25b8 leadingCoeff_zero\u27e9\n#align polynomial.leading_coeff_eq_zero Polynomial.leadingCoeff_eq_zero\n\ntheorem leadingCoeff_ne_zero : leadingCoeff p \u2260 0 \u2194 p \u2260 0 := by rw [Ne.def, leadingCoeff_eq_zero]\n#align polynomial.leading_coeff_ne_zero Polynomial.leadingCoeff_ne_zero\n\ntheorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 \u2194 degree p = \u22a5 := by\n  rw [leadingCoeff_eq_zero, degree_eq_bot]\n#align polynomial.leading_coeff_eq_zero_iff_deg_eq_bot Polynomial.leadingCoeff_eq_zero_iff_deg_eq_bot\n\ntheorem natDegree_mem_support_of_nonzero (H : p \u2260 0) : p.natDegree \u2208 p.support := by\n  rw [mem_support_iff]\n  exact (not_congr leadingCoeff_eq_zero).mpr H\n#align polynomial.nat_degree_mem_support_of_nonzero Polynomial.natDegree_mem_support_of_nonzero\n\ntheorem natDegree_eq_support_max' (h : p \u2260 0) :\n    p.natDegree = p.support.max' (nonempty_support_iff.mpr h) :=\n  (le_max' _ _ <| natDegree_mem_support_of_nonzero h).antisymm <|\n    max'_le _ _ _ le_natDegree_of_mem_supp\n#align polynomial.nat_degree_eq_support_max' Polynomial.natDegree_eq_support_max'\n\ntheorem natDegree_C_mul_X_pow_le (a : R) (n : \u2115) : natDegree (C a * X ^ n) \u2264 n :=\n  natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _\n#align polynomial.nat_degree_C_mul_X_pow_le Polynomial.natDegree_C_mul_X_pow_le\n\ntheorem degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p :=\n  le_antisymm (max_eq_left_of_lt h \u25b8 degree_add_le _ _) <|\n    degree_le_degree <|\n      by\n      rw [coeff_add, coeff_natDegree_eq_zero_of_degree_lt h, add_zero]\n      exact mt leadingCoeff_eq_zero.1 (ne_zero_of_degree_gt h)\n#align polynomial.degree_add_eq_left_of_degree_lt Polynomial.degree_add_eq_left_of_degree_lt\n\ntheorem degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q := by\n  rw [add_comm, degree_add_eq_left_of_degree_lt h]\n#align polynomial.degree_add_eq_right_of_degree_lt Polynomial.degree_add_eq_right_of_degree_lt\n\ntheorem natDegree_add_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) :\n    natDegree (p + q) = natDegree p :=\n  natDegree_eq_of_degree_eq (degree_add_eq_left_of_degree_lt (degree_lt_degree h))\n#align polynomial.nat_degree_add_eq_left_of_nat_degree_lt Polynomial.natDegree_add_eq_left_of_natDegree_lt\n\ntheorem natDegree_add_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) :\n    natDegree (p + q) = natDegree q :=\n  natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt (degree_lt_degree h))\n#align polynomial.nat_degree_add_eq_right_of_nat_degree_lt Polynomial.natDegree_add_eq_right_of_natDegree_lt\n\ntheorem degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p :=\n  add_comm (C a) p \u25b8 degree_add_eq_right_of_degree_lt <| lt_of_le_of_lt degree_C_le hp\n#align polynomial.degree_add_C Polynomial.degree_add_C\n\ntheorem degree_add_eq_of_leadingCoeff_add_ne_zero (h : leadingCoeff p + leadingCoeff q \u2260 0) :\n    degree (p + q) = max p.degree q.degree :=\n  le_antisymm (degree_add_le _ _) <|\n    match lt_trichotomy (degree p) (degree q) with\n    | Or.inl hlt => by\n      rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt]\n    | Or.inr (Or.inl HEq) =>\n      le_of_not_gt fun hlt : max (degree p) (degree q) > degree (p + q) =>\n        h <|\n          show leadingCoeff p + leadingCoeff q = 0\n            by\n            rw [HEq, max_self] at hlt\n            rw [leadingCoeff, leadingCoeff, natDegree_eq_of_degree_eq HEq, \u2190 coeff_add]\n            exact coeff_natDegree_eq_zero_of_degree_lt hlt\n    | Or.inr (Or.inr hlt) => by\n      rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt]\n#align polynomial.degree_add_eq_of_leading_coeff_add_ne_zero Polynomial.degree_add_eq_of_leadingCoeff_add_ne_zero\n\ntheorem degree_erase_le (p : R[X]) (n : \u2115) : degree (p.erase n) \u2264 degree p := by\n  rcases p with \u27e8p\u27e9\n  simp only [erase_def, degree, coeff, support]\n  -- Porting note: simpler convert-free proof to be explicit about definition unfolding\n  apply sup_mono\n  rw [Finsupp.support_erase]\n  apply Finset.erase_subset\n#align polynomial.degree_erase_le Polynomial.degree_erase_le\n\ntheorem degree_erase_lt (hp : p \u2260 0) : degree (p.erase (natDegree p)) < degree p := by\n  apply lt_of_le_of_ne (degree_erase_le _ _)\n  rw [degree_eq_natDegree hp, degree, support_erase]\n  exact fun h => not_mem_erase _ _ (mem_of_max h)\n#align polynomial.degree_erase_lt Polynomial.degree_erase_lt\n\ntheorem degree_update_le (p : R[X]) (n : \u2115) (a : R) : degree (p.update n a) \u2264 max (degree p) n := by\n  rw [degree, support_update]\n  split_ifs\n  \u00b7 exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _)\n  \u00b7 rw [max_insert, max_comm]\n    exact le_rfl\n#align polynomial.degree_update_le Polynomial.degree_update_le\n\ntheorem degree_sum_le (s : Finset \u03b9) (f : \u03b9 \u2192 R[X]) :\n    degree (\u2211 i in s, f i) \u2264 s.sup fun b => degree (f b) :=\n  Finset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl])\n    fun a s has ih =>\n    calc\n      degree (\u2211 i in insert a s, f i) \u2264 max (degree (f a)) (degree (\u2211 i in s, f i)) := by\n        rw [sum_insert has]; exact degree_add_le _ _\n      _ \u2264 _ := by rw [sup_insert, sup_eq_max]; exact max_le_max le_rfl ih\n\n#align polynomial.degree_sum_le Polynomial.degree_sum_le\n\ntheorem degree_mul_le (p q : R[X]) : degree (p * q) \u2264 degree p + degree q :=\n  calc\n    degree (p * q) \u2264\n        p.support.sup fun i => degree (sum q fun j a => C (coeff p i * a) * X ^ (i + j)) := by\n      -- Porting note: Was `simp only [..]; convert ..; exact mul_eq_sum_sum`.\n      simp only [\u2190 C_mul_X_pow_eq_monomial.symm, mul_eq_sum_sum (p := p) (q := q)]\n      exact degree_sum_le _ _\n    _ \u2264\n        p.support.sup fun i =>\n          q.support.sup fun j => degree (C (coeff p i * coeff q j) * X ^ (i + j)) :=\n      (Finset.sup_mono_fun fun i _hi => degree_sum_le _ _)\n    _ \u2264 degree p + degree q := by\n      refine'\n        Finset.sup_le fun a ha => Finset.sup_le fun b hb => le_trans (degree_C_mul_X_pow_le _ _) _\n      -- Porting note: `Nat.cast_withBot` is required.\n      rw [Nat.cast_withBot, WithBot.coe_add]\n      rw [mem_support_iff] at ha hb\n      exact add_le_add (le_degree_of_ne_zero ha) (le_degree_of_ne_zero hb)\n\n#align polynomial.degree_mul_le Polynomial.degree_mul_le\n\ntheorem degree_pow_le (p : R[X]) : \u2200 n : \u2115, degree (p ^ n) \u2264 n \u2022 degree p\n  | 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le\n  | n + 1 =>\n    calc\n      degree (p ^ (n + 1)) \u2264 degree p + degree (p ^ n) := by\n        rw [pow_succ]; exact degree_mul_le _ _\n      _ \u2264 _ := by rw [succ_nsmul]; exact add_le_add le_rfl (degree_pow_le _ _)\n\n#align polynomial.degree_pow_le Polynomial.degree_pow_le\n\n@[simp]\ntheorem leadingCoeff_monomial (a : R) (n : \u2115) : leadingCoeff (monomial n a) = a := by\n  by_cases ha : a = 0\n  \u00b7 simp only [ha, (monomial n).map_zero, leadingCoeff_zero]\n  \u00b7 rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial]\n    simp\n#align polynomial.leading_coeff_monomial Polynomial.leadingCoeff_monomial\n\ntheorem leadingCoeff_C_mul_X_pow (a : R) (n : \u2115) : leadingCoeff (C a * X ^ n) = a := by\n  rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial]\n#align polynomial.leading_coeff_C_mul_X_pow Polynomial.leadingCoeff_C_mul_X_pow\n\ntheorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by\n  simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1\n#align polynomial.leading_coeff_C_mul_X Polynomial.leadingCoeff_C_mul_X\n\n@[simp]\ntheorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a :=\n  leadingCoeff_monomial a 0\n#align polynomial.leading_coeff_C Polynomial.leadingCoeff_C\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem leadingCoeff_X_pow (n : \u2115) : leadingCoeff ((X : R[X]) ^ n) = 1 := by\n  simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n\n#align polynomial.leading_coeff_X_pow Polynomial.leadingCoeff_X_pow\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by\n  simpa only [pow_one] using @leadingCoeff_X_pow R _ 1\n#align polynomial.leading_coeff_X Polynomial.leadingCoeff_X\n\n@[simp]\ntheorem monic_X_pow (n : \u2115) : Monic (X ^ n : R[X]) :=\n  leadingCoeff_X_pow n\n#align polynomial.monic_X_pow Polynomial.monic_X_pow\n\n@[simp]\ntheorem monic_X : Monic (X : R[X]) :=\n  leadingCoeff_X\n#align polynomial.monic_X Polynomial.monic_X\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 :=\n  leadingCoeff_C 1\n#align polynomial.leading_coeff_one Polynomial.leadingCoeff_one\n\n@[simp]\ntheorem monic_one : Monic (1 : R[X]) :=\n  leadingCoeff_C _\n#align polynomial.monic_one Polynomial.monic_one\n\ntheorem Monic.ne_zero {R : Type _} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) :\n    p \u2260 0 := by\n  rintro rfl\n  simp [Monic] at hp\n#align polynomial.monic.ne_zero Polynomial.Monic.ne_zero\n\ntheorem Monic.ne_zero_of_ne (h : (0 : R) \u2260 1) {p : R[X]} (hp : p.Monic) : p \u2260 0 := by\n  nontriviality R\n  exact hp.ne_zero\n#align polynomial.monic.ne_zero_of_ne Polynomial.Monic.ne_zero_of_ne\n\ntheorem monic_of_natDegree_le_of_coeff_eq_one (n : \u2115) (pn : p.natDegree \u2264 n) (p1 : p.coeff n = 1) :\n    Monic p := by\n  unfold Monic\n  nontriviality\n  refine' (congr_arg _ <| natDegree_eq_of_le_of_coeff_ne_zero pn _).trans p1\n  exact ne_of_eq_of_ne p1 one_ne_zero\n#align polynomial.monic_of_nat_degree_le_of_coeff_eq_one Polynomial.monic_of_natDegree_le_of_coeff_eq_one\n\ntheorem monic_of_degree_le_of_coeff_eq_one (n : \u2115) (pn : p.degree \u2264 n) (p1 : p.coeff n = 1) :\n    Monic p :=\n  monic_of_natDegree_le_of_coeff_eq_one n (natDegree_le_of_degree_le pn) p1\n#align polynomial.monic_of_degree_le_of_coeff_eq_one Polynomial.monic_of_degree_le_of_coeff_eq_one\n\ntheorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q \u2260 r) : p \u2260 0 :=\n  haveI := Nontrivial.of_polynomial_ne hne\n  hp.ne_zero\n#align polynomial.monic.ne_zero_of_polynomial_ne Polynomial.Monic.ne_zero_of_polynomial_ne\n\ntheorem leadingCoeff_add_of_degree_lt (h : degree p < degree q) :\n    leadingCoeff (p + q) = leadingCoeff q := by\n  have : coeff p (natDegree q) = 0 := coeff_natDegree_eq_zero_of_degree_lt h\n  simp only [leadingCoeff, natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h), this,\n    coeff_add, zero_add]\n#align polynomial.leading_coeff_add_of_degree_lt Polynomial.leadingCoeff_add_of_degree_lt\n\ntheorem leadingCoeff_add_of_degree_eq (h : degree p = degree q)\n    (hlc : leadingCoeff p + leadingCoeff q \u2260 0) :\n    leadingCoeff (p + q) = leadingCoeff p + leadingCoeff q := by\n  have : natDegree (p + q) = natDegree p := by\n    apply natDegree_eq_of_degree_eq;\n      rw [degree_add_eq_of_leadingCoeff_add_ne_zero hlc, h, max_self]\n  simp only [leadingCoeff, this, natDegree_eq_of_degree_eq h, coeff_add]\n#align polynomial.leading_coeff_add_of_degree_eq Polynomial.leadingCoeff_add_of_degree_eq\n\n@[simp]\ntheorem coeff_mul_degree_add_degree (p q : R[X]) :\n    coeff (p * q) (natDegree p + natDegree q) = leadingCoeff p * leadingCoeff q :=\n  calc\n    coeff (p * q) (natDegree p + natDegree q) =\n        \u2211 x in Nat.antidiagonal (natDegree p + natDegree q), coeff p x.1 * coeff q x.2 :=\n      coeff_mul _ _ _\n    _ = coeff p (natDegree p) * coeff q (natDegree q) :=\n      by\n      refine' Finset.sum_eq_single (natDegree p, natDegree q) _ _\n      \u00b7 rintro \u27e8i, j\u27e9 h\u2081 h\u2082\n        rw [Nat.mem_antidiagonal] at h\u2081\n        by_cases H : natDegree p < i\n        \u00b7\n          rw [coeff_eq_zero_of_degree_lt\n              (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 H)),\n            zero_mul]\n        \u00b7 rw [not_lt_iff_eq_or_lt] at H\n          cases' H with H H\n          \u00b7 subst H\n            rw [add_left_cancel_iff] at h\u2081\n            dsimp at h\u2081\n            subst h\u2081\n            exfalso\n            exact h\u2082 rfl\n          \u00b7 suffices natDegree q < j by\n              rw [coeff_eq_zero_of_degree_lt\n                  (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 this)),\n                mul_zero]\n            \u00b7 by_contra H'\n              rw [not_lt] at H'\n              exact\n                ne_of_lt (Nat.lt_of_lt_of_le (Nat.add_lt_add_right H j) (Nat.add_le_add_left H' _))\n                  h\u2081\n      \u00b7 intro H\n        exfalso\n        apply H\n        rw [Nat.mem_antidiagonal]\n\n#align polynomial.coeff_mul_degree_add_degree Polynomial.coeff_mul_degree_add_degree\n\ntheorem degree_mul' (h : leadingCoeff p * leadingCoeff q \u2260 0) :\n    degree (p * q) = degree p + degree q :=\n  have hp : p \u2260 0 := by refine' mt _ h; exact fun hp => by rw [hp, leadingCoeff_zero, zero_mul]\n  have hq : q \u2260 0 := by refine' mt _ h; exact fun hq => by rw [hq, leadingCoeff_zero, mul_zero]\n  le_antisymm (degree_mul_le _ _)\n    (by\n      rw [degree_eq_natDegree hp, degree_eq_natDegree hq]\n      refine le_degree_of_ne_zero (n := natDegree p + natDegree q) ?_\n      rwa [coeff_mul_degree_add_degree])\n#align polynomial.degree_mul' Polynomial.degree_mul'\n\ntheorem Monic.degree_mul (hq : Monic q) : degree (p * q) = degree p + degree q :=\n  if hp : p = 0 then by simp [hp]\n  else degree_mul' <| by rwa [hq.leadingCoeff, mul_one, Ne.def, leadingCoeff_eq_zero]\n#align polynomial.monic.degree_mul Polynomial.Monic.degree_mul\n\ntheorem natDegree_mul' (h : leadingCoeff p * leadingCoeff q \u2260 0) :\n    natDegree (p * q) = natDegree p + natDegree q :=\n  have hp : p \u2260 0 := mt leadingCoeff_eq_zero.2 fun h\u2081 => h <| by rw [h\u2081, zero_mul]\n  have hq : q \u2260 0 := mt leadingCoeff_eq_zero.2 fun h\u2081 => h <| by rw [h\u2081, mul_zero]\n  natDegree_eq_of_degree_eq_some <| by\n    -- Porting note: `Nat.cast_withBot` is required.\n    rw [degree_mul' h, Nat.cast_withBot, WithBot.coe_add, degree_eq_natDegree hp,\n      degree_eq_natDegree hq, \u2190 Nat.cast_withBot, \u2190 Nat.cast_withBot]\n#align polynomial.nat_degree_mul' Polynomial.natDegree_mul'\n\ntheorem leadingCoeff_mul' (h : leadingCoeff p * leadingCoeff q \u2260 0) :\n    leadingCoeff (p * q) = leadingCoeff p * leadingCoeff q := by\n  unfold leadingCoeff\n  rw [natDegree_mul' h, coeff_mul_degree_add_degree]\n  rfl\n#align polynomial.leading_coeff_mul' Polynomial.leadingCoeff_mul'\n\ntheorem monomial_natDegree_leadingCoeff_eq_self (h : p.support.card \u2264 1) :\n    monomial p.natDegree p.leadingCoeff = p := by\n  rcases card_support_le_one_iff_monomial.1 h with \u27e8n, a, rfl\u27e9\n  by_cases ha : a = 0 <;> simp [ha]\n#align polynomial.monomial_nat_degree_leading_coeff_eq_self Polynomial.monomial_natDegree_leadingCoeff_eq_self\n\ntheorem C_mul_X_pow_eq_self (h : p.support.card \u2264 1) : C p.leadingCoeff * X ^ p.natDegree = p := by\n  rw [C_mul_X_pow_eq_monomial, monomial_natDegree_leadingCoeff_eq_self h]\n#align polynomial.C_mul_X_pow_eq_self Polynomial.C_mul_X_pow_eq_self\n\ntheorem leadingCoeff_pow' : leadingCoeff p ^ n \u2260 0 \u2192 leadingCoeff (p ^ n) = leadingCoeff p ^ n :=\n  Nat.recOn n (by simp) fun n ih h =>\n    by\n    have h\u2081 : leadingCoeff p ^ n \u2260 0 := fun h\u2081 => h <| by rw [pow_succ, h\u2081, mul_zero]\n    have h\u2082 : leadingCoeff p * leadingCoeff (p ^ n) \u2260 0 := by rwa [pow_succ, \u2190 ih h\u2081] at h\n    rw [pow_succ, pow_succ, leadingCoeff_mul' h\u2082, ih h\u2081]\n#align polynomial.leading_coeff_pow' Polynomial.leadingCoeff_pow'\n\ntheorem degree_pow' : \u2200 {n : \u2115}, leadingCoeff p ^ n \u2260 0 \u2192 degree (p ^ n) = n \u2022 degree p\n  | 0 => fun h => by rw [pow_zero, \u2190 C_1] at *; rw [degree_C h, zero_nsmul]\n  | n + 1 => fun h =>\n    by\n    have h\u2081 : leadingCoeff p ^ n \u2260 0 := fun h\u2081 => h <| by rw [pow_succ, h\u2081, mul_zero]\n    have h\u2082 : leadingCoeff p * leadingCoeff (p ^ n) \u2260 0 := by\n      rwa [pow_succ, \u2190 leadingCoeff_pow' h\u2081] at h\n    rw [pow_succ, degree_mul' h\u2082, succ_nsmul, degree_pow' h\u2081]\n#align polynomial.degree_pow' Polynomial.degree_pow'\n\ntheorem natDegree_pow' {n : \u2115} (h : leadingCoeff p ^ n \u2260 0) : natDegree (p ^ n) = n * natDegree p :=\n  if hp0 : p = 0 then\n    if hn0 : n = 0 then by simp [*] else by rw [hp0, zero_pow (Nat.pos_of_ne_zero hn0)]; simp\n  else\n    have hpn : p ^ n \u2260 0 := fun hpn0 => by\n      have h1 := h\n      rw [\u2190 leadingCoeff_pow' h1, hpn0, leadingCoeff_zero] at h; exact h rfl\n    Option.some_inj.1 <|\n      show (natDegree (p ^ n) : WithBot \u2115) = (n * natDegree p : \u2115) by\n        -- Porting note: `Nat.cast_withBot` is required.\n        rw [\u2190 degree_eq_natDegree hpn, degree_pow' h, degree_eq_natDegree hp0,\n            Nat.cast_withBot, \u2190 WithBot.coe_nsmul, \u2190 Nat.cast_withBot];\n          simp\n#align polynomial.nat_degree_pow' Polynomial.natDegree_pow'\n\ntheorem leadingCoeff_monic_mul {p q : R[X]} (hp : Monic p) :\n    leadingCoeff (p * q) = leadingCoeff q := by\n  rcases eq_or_ne q 0 with (rfl | H)\n  \u00b7 simp\n  \u00b7 rw [leadingCoeff_mul', hp.leadingCoeff, one_mul]\n    rwa [hp.leadingCoeff, one_mul, Ne.def, leadingCoeff_eq_zero]\n#align polynomial.leading_coeff_monic_mul Polynomial.leadingCoeff_monic_mul\n\ntheorem leadingCoeff_mul_monic {p q : R[X]} (hq : Monic q) :\n    leadingCoeff (p * q) = leadingCoeff p :=\n  Decidable.byCases\n    (fun H : leadingCoeff p = 0 => by\n      rw [H, leadingCoeff_eq_zero.1 H, zero_mul, leadingCoeff_zero])\n    fun H : leadingCoeff p \u2260 0 => by\n    rw [leadingCoeff_mul', hq.leadingCoeff, mul_one];rwa [hq.leadingCoeff, mul_one]\n#align polynomial.leading_coeff_mul_monic Polynomial.leadingCoeff_mul_monic\n\n@[simp]\ntheorem leadingCoeff_mul_X_pow {p : R[X]} {n : \u2115} : leadingCoeff (p * X ^ n) = leadingCoeff p :=\n  leadingCoeff_mul_monic (monic_X_pow n)\n#align polynomial.leading_coeff_mul_X_pow Polynomial.leadingCoeff_mul_X_pow\n\n@[simp]\ntheorem leadingCoeff_mul_X {p : R[X]} : leadingCoeff (p * X) = leadingCoeff p :=\n  leadingCoeff_mul_monic monic_X\n#align polynomial.leading_coeff_mul_X Polynomial.leadingCoeff_mul_X\n\ntheorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) \u2264 natDegree p + natDegree q := by\n  apply natDegree_le_of_degree_le\n  apply le_trans (degree_mul_le p q)\n  -- Porting note: `Nat.cast_withBot` is required.\n  rw [Nat.cast_withBot, WithBot.coe_add]\n  refine' add_le_add _ _ <;> apply degree_le_natDegree\n#align polynomial.nat_degree_mul_le Polynomial.natDegree_mul_le\n\ntheorem natDegree_pow_le {p : R[X]} {n : \u2115} : (p ^ n).natDegree \u2264 n * p.natDegree := by\n  induction' n with i hi\n  \u00b7 simp\n  \u00b7 rw [pow_succ, Nat.succ_mul, add_comm]\n    apply le_trans natDegree_mul_le\n    exact add_le_add_left hi _\n#align polynomial.nat_degree_pow_le Polynomial.natDegree_pow_le\n\n@[simp]\ntheorem coeff_pow_mul_natDegree (p : R[X]) (n : \u2115) :\n    (p ^ n).coeff (n * p.natDegree) = p.leadingCoeff ^ n := by\n  induction' n with i hi\n  \u00b7 simp\n  \u00b7 rw [pow_succ', pow_succ', Nat.succ_mul]\n    by_cases hp1 : p.leadingCoeff ^ i = 0\n    \u00b7 rw [hp1, zero_mul]\n      by_cases hp2 : p ^ i = 0\n      \u00b7 rw [hp2, zero_mul, coeff_zero]\n      \u00b7 apply coeff_eq_zero_of_natDegree_lt\n        have h1 : (p ^ i).natDegree < i * p.natDegree := by\n          refine lt_of_le_of_ne natDegree_pow_le fun h => hp2 ?_\n          rw [\u2190 h, hp1] at hi\n          exact leadingCoeff_eq_zero.mp hi\n        calc\n          (p ^ i * p).natDegree \u2264 (p ^ i).natDegree + p.natDegree := natDegree_mul_le\n          _ < i * p.natDegree + p.natDegree := add_lt_add_right h1 _\n\n    \u00b7 rw [\u2190 natDegree_pow' hp1, \u2190 leadingCoeff_pow' hp1]\n      exact coeff_mul_degree_add_degree _ _\n#align polynomial.coeff_pow_mul_nat_degree Polynomial.coeff_pow_mul_natDegree\n\ntheorem zero_le_degree_iff : 0 \u2264 degree p \u2194 p \u2260 0 := by\n  rw [\u2190 not_lt, Nat.WithBot.lt_zero_iff, degree_eq_bot]\n#align polynomial.zero_le_degree_iff Polynomial.zero_le_degree_iff\n\ntheorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 \u2194 p.degree \u2264 0 := by\n  -- Porting note: `Nat.cast_withBot` is required.\n  rw [\u2190 nonpos_iff_eq_zero, natDegree_le_iff_degree_le,\n    Nat.cast_withBot, WithBot.coe_zero]\n#align polynomial.nat_degree_eq_zero_iff_degree_le_zero Polynomial.natDegree_eq_zero_iff_degree_le_zero\n\ntheorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot \u2115) :\n    degree f \u2264 n \u2194 \u2200 m : \u2115, n < m \u2192 coeff f m = 0 := by\n  -- Porting note: `Nat.cast_withBot` is required.\n  simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne.def, \u2190 not_le,\n    not_imp_comm, Nat.cast_withBot]\n#align polynomial.degree_le_iff_coeff_zero Polynomial.degree_le_iff_coeff_zero\n\ntheorem degree_lt_iff_coeff_zero (f : R[X]) (n : \u2115) :\n    degree f < n \u2194 \u2200 m : \u2115, n \u2264 m \u2192 coeff f m = 0 := by\n  refine'\n    \u27e8fun hf m hm => coeff_eq_zero_of_degree_lt (lt_of_lt_of_le hf (WithBot.coe_le_coe.2 hm)), _\u27e9\n  -- Porting note: `Nat.cast_withBot` is required.\n  simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff, WithBot.some_eq_coe,\n    WithBot.coe_lt_coe, \u2190 @not_le \u2115, max_eq_sup_coe, Nat.cast_withBot]\n  exact fun h m => mt (h m)\n#align polynomial.degree_lt_iff_coeff_zero Polynomial.degree_lt_iff_coeff_zero\n\ntheorem degree_smul_le (a : R) (p : R[X]) : degree (a \u2022 p) \u2264 degree p := by\n  refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_\n  rw [degree_lt_iff_coeff_zero] at hm\n  simp [hm m le_rfl]\n#align polynomial.degree_smul_le Polynomial.degree_smul_le\n\ntheorem natDegree_smul_le (a : R) (p : R[X]) : natDegree (a \u2022 p) \u2264 natDegree p :=\n  natDegree_le_natDegree (degree_smul_le a p)\n#align polynomial.nat_degree_smul_le Polynomial.natDegree_smul_le\n\ntheorem degree_lt_degree_mul_X (hp : p \u2260 0) : p.degree < (p * X).degree := by\n  haveI := Nontrivial.of_polynomial_ne hp; exact\n    have : leadingCoeff p * leadingCoeff X \u2260 0 := by simpa\n    by\n      erw [degree_mul' this, degree_eq_natDegree hp, degree_X, \u2190 WithBot.coe_one,\n        \u2190 WithBot.coe_add, WithBot.coe_lt_coe];\n      exact Nat.lt_succ_self _\n#align polynomial.degree_lt_degree_mul_X Polynomial.degree_lt_degree_mul_X\n\ntheorem natDegree_pos_iff_degree_pos : 0 < natDegree p \u2194 0 < degree p :=\n  lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le\n#align polynomial.nat_degree_pos_iff_degree_pos Polynomial.natDegree_pos_iff_degree_pos\n\ntheorem eq_C_of_natDegree_le_zero (h : natDegree p \u2264 0) : p = C (coeff p 0) :=\n  eq_C_of_degree_le_zero <| degree_le_of_natDegree_le h\n#align polynomial.eq_C_of_nat_degree_le_zero Polynomial.eq_C_of_natDegree_le_zero\n\ntheorem eq_C_of_natDegree_eq_zero (h : natDegree p = 0) : p = C (coeff p 0) :=\n  eq_C_of_natDegree_le_zero h.le\n#align polynomial.eq_C_of_nat_degree_eq_zero Polynomial.eq_C_of_natDegree_eq_zero\n\ntheorem ne_zero_of_coe_le_degree (hdeg : \u2191n \u2264 p.degree) : p \u2260 0 :=\n  zero_le_degree_iff.mp <| (WithBot.coe_le_coe.mpr n.zero_le).trans hdeg\n#align polynomial.ne_zero_of_coe_le_degree Polynomial.ne_zero_of_coe_le_degree\n\ntheorem le_natDegree_of_coe_le_degree (hdeg : \u2191n \u2264 p.degree) : n \u2264 p.natDegree :=\n  -- Porting note: `.. \u25b8 ..` \u2192 `rwa [..] at ..`\n  WithBot.coe_le_coe.mp <| by\n    rwa [degree_eq_natDegree <| ne_zero_of_coe_le_degree hdeg] at hdeg\n#align polynomial.le_nat_degree_of_coe_le_degree Polynomial.le_natDegree_of_coe_le_degree\n\ntheorem degree_sum_fin_lt {n : \u2115} (f : Fin n \u2192 R) :\n    degree (\u2211 i : Fin n, C (f i) * X ^ (i : \u2115)) < n :=\n  (degree_sum_le _ _).trans_lt <|\n    (Finset.sup_lt_iff <| WithBot.bot_lt_coe n).2 fun k _hk =>\n      (degree_C_mul_X_pow_le _ _).trans_lt <| WithBot.coe_lt_coe.2 k.is_lt\n#align polynomial.degree_sum_fin_lt Polynomial.degree_sum_fin_lt\n\ntheorem degree_linear_le : degree (C a * X + C b) \u2264 1 :=\n  degree_add_le_of_degree_le (degree_C_mul_X_le _) <| le_trans degree_C_le Nat.WithBot.coe_nonneg\n#align polynomial.degree_linear_le Polynomial.degree_linear_le\n\ntheorem degree_linear_lt : degree (C a * X + C b) < 2 :=\n  degree_linear_le.trans_lt <| WithBot.coe_lt_coe.mpr one_lt_two\n#align polynomial.degree_linear_lt Polynomial.degree_linear_lt\n\ntheorem degree_C_lt_degree_C_mul_X (ha : a \u2260 0) : degree (C b) < degree (C a * X) := by\n  simpa only [degree_C_mul_X ha] using degree_C_lt\n#align polynomial.degree_C_lt_degree_C_mul_X Polynomial.degree_C_lt_degree_C_mul_X\n\n@[simp]\ntheorem degree_linear (ha : a \u2260 0) : degree (C a * X + C b) = 1 := by\n  rw [degree_add_eq_left_of_degree_lt <| degree_C_lt_degree_C_mul_X ha, degree_C_mul_X ha]\n#align polynomial.degree_linear Polynomial.degree_linear\n\ntheorem natDegree_linear_le : natDegree (C a * X + C b) \u2264 1 :=\n  natDegree_le_of_degree_le degree_linear_le\n#align polynomial.nat_degree_linear_le Polynomial.natDegree_linear_le\n\n@[simp]\ntheorem natDegree_linear (ha : a \u2260 0) : natDegree (C a * X + C b) = 1 :=\n  natDegree_eq_of_degree_eq_some <| degree_linear ha\n#align polynomial.nat_degree_linear Polynomial.natDegree_linear\n\n@[simp]\ntheorem leadingCoeff_linear (ha : a \u2260 0) : leadingCoeff (C a * X + C b) = a := by\n  rw [add_comm, leadingCoeff_add_of_degree_lt (degree_C_lt_degree_C_mul_X ha),\n    leadingCoeff_C_mul_X]\n#align polynomial.leading_coeff_linear Polynomial.leadingCoeff_linear\n\ntheorem degree_quadratic_le : degree (C a * X ^ 2 + C b * X + C c) \u2264 2 := by\n  simpa only [add_assoc] using\n    degree_add_le_of_degree_le (degree_C_mul_X_pow_le 2 a)\n      (le_trans degree_linear_le <| WithBot.coe_le_coe.mpr one_le_two)\n#align polynomial.degree_quadratic_le Polynomial.degree_quadratic_le\n\ntheorem degree_quadratic_lt : degree (C a * X ^ 2 + C b * X + C c) < 3 :=\n  degree_quadratic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 2\n#align polynomial.degree_quadratic_lt Polynomial.degree_quadratic_lt\n\ntheorem degree_linear_lt_degree_C_mul_X_sq (ha : a \u2260 0) :\n    degree (C b * X + C c) < degree (C a * X ^ 2) := by\n  simpa only [degree_C_mul_X_pow 2 ha] using degree_linear_lt\n#align polynomial.degree_linear_lt_degree_C_mul_X_sq Polynomial.degree_linear_lt_degree_C_mul_X_sq\n\n@[simp]\ntheorem degree_quadratic (ha : a \u2260 0) : degree (C a * X ^ 2 + C b * X + C c) = 2 := by\n  rw [add_assoc, degree_add_eq_left_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha,\n    degree_C_mul_X_pow 2 ha]\n  rfl\n#align polynomial.degree_quadratic Polynomial.degree_quadratic\n\ntheorem natDegree_quadratic_le : natDegree (C a * X ^ 2 + C b * X + C c) \u2264 2 :=\n  natDegree_le_of_degree_le degree_quadratic_le\n#align polynomial.nat_degree_quadratic_le Polynomial.natDegree_quadratic_le\n\n@[simp]\ntheorem natDegree_quadratic (ha : a \u2260 0) : natDegree (C a * X ^ 2 + C b * X + C c) = 2 :=\n  natDegree_eq_of_degree_eq_some <| degree_quadratic ha\n#align polynomial.nat_degree_quadratic Polynomial.natDegree_quadratic\n\n@[simp]\ntheorem leadingCoeff_quadratic (ha : a \u2260 0) : leadingCoeff (C a * X ^ 2 + C b * X + C c) = a := by\n  rw [add_assoc, add_comm, leadingCoeff_add_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha,\n    leadingCoeff_C_mul_X_pow]\n#align polynomial.leading_coeff_quadratic Polynomial.leadingCoeff_quadratic\n\ntheorem degree_cubic_le : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) \u2264 3 := by\n  simpa only [add_assoc] using\n    degree_add_le_of_degree_le (degree_C_mul_X_pow_le 3 a)\n      (le_trans degree_quadratic_le <| WithBot.coe_le_coe.mpr <| Nat.le_succ 2)\n#align polynomial.degree_cubic_le Polynomial.degree_cubic_le\n\ntheorem degree_cubic_lt : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) < 4 :=\n  degree_cubic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 3\n#align polynomial.degree_cubic_lt Polynomial.degree_cubic_lt\n\ntheorem degree_quadratic_lt_degree_C_mul_X_cb (ha : a \u2260 0) :\n    degree (C b * X ^ 2 + C c * X + C d) < degree (C a * X ^ 3) := by\n  simpa only [degree_C_mul_X_pow 3 ha] using degree_quadratic_lt\n#align polynomial.degree_quadratic_lt_degree_C_mul_X_cb Polynomial.degree_quadratic_lt_degree_C_mul_X_cb\n\n@[simp]\ntheorem degree_cubic (ha : a \u2260 0) : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 := by\n  rw [add_assoc, add_assoc, \u2190 add_assoc (C b * X ^ 2),\n    degree_add_eq_left_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha,\n    degree_C_mul_X_pow 3 ha]\n  rfl\n#align polynomial.degree_cubic Polynomial.degree_cubic\n\ntheorem natDegree_cubic_le : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) \u2264 3 :=\n  natDegree_le_of_degree_le degree_cubic_le\n#align polynomial.nat_degree_cubic_le Polynomial.natDegree_cubic_le\n\n@[simp]\ntheorem natDegree_cubic (ha : a \u2260 0) : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 :=\n  natDegree_eq_of_degree_eq_some <| degree_cubic ha\n#align polynomial.nat_degree_cubic Polynomial.natDegree_cubic\n\n@[simp]\ntheorem leadingCoeff_cubic (ha : a \u2260 0) :\n    leadingCoeff (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = a := by\n  rw [add_assoc, add_assoc, \u2190 add_assoc (C b * X ^ 2), add_comm,\n    leadingCoeff_add_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha,\n    leadingCoeff_C_mul_X_pow]\n#align polynomial.leading_coeff_cubic Polynomial.leadingCoeff_cubic\n\nend Semiring\n\nsection NontrivialSemiring\n\nvariable [Semiring R] [Nontrivial R] {p q : R[X]}\n\n@[simp]\ntheorem degree_X_pow (n : \u2115) : degree ((X : R[X]) ^ n) = n := by\n  rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)]\n#align polynomial.degree_X_pow Polynomial.degree_X_pow\n\n@[simp]\ntheorem natDegree_X_pow (n : \u2115) : natDegree ((X : R[X]) ^ n) = n :=\n  natDegree_eq_of_degree_eq_some (degree_X_pow n)\n#align polynomial.nat_degree_X_pow Polynomial.natDegree_X_pow\n\n--  This lemma explicitly does not require the `Nontrivial R` assumption.\ntheorem natDegree_X_pow_le {R : Type _} [Semiring R] (n : \u2115) : (X ^ n : R[X]).natDegree \u2264 n := by\n  nontriviality R\n  rw [Polynomial.natDegree_X_pow]\n#align polynomial.nat_degree_X_pow_le Polynomial.natDegree_X_pow_le\n\ntheorem not_isUnit_X : \u00acIsUnit (X : R[X]) := fun \u27e8\u27e8_, g, _hfg, hgf\u27e9, rfl\u27e9 =>\n  zero_ne_one' R <| by\n    conv at hgf => change g * monomial 1 1 = 1\n    rw [\u2190 coeff_one_zero, \u2190 hgf]\n    simp\n#align polynomial.not_is_unit_X Polynomial.not_isUnit_X\n\n@[simp]\ntheorem degree_mul_X : degree (p * X) = degree p + 1 := by simp [monic_X.degree_mul]\n#align polynomial.degree_mul_X Polynomial.degree_mul_X\n\n@[simp]\ntheorem degree_mul_X_pow : degree (p * X ^ n) = degree p + n := by simp [(monic_X_pow n).degree_mul]\n#align polynomial.degree_mul_X_pow Polynomial.degree_mul_X_pow\n\nend NontrivialSemiring\n\nsection Ring\n\nvariable [Ring R] {p q : R[X]}\n\ntheorem degree_sub_le (p q : R[X]) : degree (p - q) \u2264 max (degree p) (degree q) := by\n  simpa only [degree_neg q] using degree_add_le p (-q)\n#align polynomial.degree_sub_le Polynomial.degree_sub_le\n\ntheorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) \u2264 max (natDegree p) (natDegree q) := by\n  simpa only [\u2190 natDegree_neg q] using natDegree_add_le p (-q)\n#align polynomial.nat_degree_sub_le Polynomial.natDegree_sub_le\n\ntheorem degree_sub_lt (hd : degree p = degree q) (hp0 : p \u2260 0)\n    (hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p :=\n  have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p :=\n    monomial_add_erase _ _\n  have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q :=\n    monomial_add_erase _ _\n  have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd]\n  have hq0 : q \u2260 0 := mt degree_eq_bot.2 (hd \u25b8 mt degree_eq_bot.1 hp0)\n  calc\n    degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by\n      conv =>\n        lhs\n        rw [\u2190 hp, \u2190 hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]\n    _ \u2264 max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) :=\n      (degree_neg (erase (natDegree q) q) \u25b8 degree_add_le _ _)\n    _ < degree p := max_lt_iff.2 \u27e8hd' \u25b8 degree_erase_lt hp0, hd.symm \u25b8 degree_erase_lt hq0\u27e9\n\n#align polynomial.degree_sub_lt Polynomial.degree_sub_lt\n\ntheorem degree_X_sub_C_le (r : R) : (X - C r).degree \u2264 1 :=\n  (degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one))\n#align polynomial.degree_X_sub_C_le Polynomial.degree_X_sub_C_le\n\ntheorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree \u2264 1 :=\n  natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r\n#align polynomial.nat_degree_X_sub_C_le Polynomial.natDegree_X_sub_C_le\n\ntheorem degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p := by\n  rw [\u2190 degree_neg q] at h\n  rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h]\n#align polynomial.degree_sub_eq_left_of_degree_lt Polynomial.degree_sub_eq_left_of_degree_lt\n\ntheorem degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q := by\n  rw [\u2190 degree_neg q] at h\n  rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg]\n#align polynomial.degree_sub_eq_right_of_degree_lt Polynomial.degree_sub_eq_right_of_degree_lt\n\ntheorem natDegree_sub_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) :\n    natDegree (p - q) = natDegree p :=\n  natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt (degree_lt_degree h))\n#align polynomial.nat_degree_sub_eq_left_of_nat_degree_lt Polynomial.natDegree_sub_eq_left_of_natDegree_lt\n\ntheorem natDegree_sub_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) :\n    natDegree (p - q) = natDegree q :=\n  natDegree_eq_of_degree_eq (degree_sub_eq_right_of_degree_lt (degree_lt_degree h))\n#align polynomial.nat_degree_sub_eq_right_of_nat_degree_lt Polynomial.natDegree_sub_eq_right_of_natDegree_lt\n\nend Ring\n\nsection NonzeroRing\n\nvariable [Nontrivial R]\n\nsection Semiring\n\nvariable [Semiring R]\n\n@[simp]\ntheorem degree_X_add_C (a : R) : degree (X + C a) = 1 := by\n  have : degree (C a) < degree (X : R[X]) :=\n    calc\n      degree (C a) \u2264 0 := degree_C_le\n      _ < 1 := (WithBot.some_lt_some.mpr zero_lt_one)\n      _ = degree X := degree_X.symm\n  rw [degree_add_eq_left_of_degree_lt this, degree_X]\n#align polynomial.degree_X_add_C Polynomial.degree_X_add_C\n\n@[simp]\ntheorem natDegree_X_add_C (x : R) : (X + C x).natDegree = 1 :=\n  natDegree_eq_of_degree_eq_some <| degree_X_add_C x\n#align polynomial.nat_degree_X_add_C Polynomial.natDegree_X_add_C\n\n@[simp]\ntheorem nextCoeff_X_add_C [Semiring S] (c : S) : nextCoeff (X + C c) = c := by\n  nontriviality S\n  simp [nextCoeff_of_pos_natDegree]\n#align polynomial.next_coeff_X_add_C Polynomial.nextCoeff_X_add_C\n\ntheorem degree_X_pow_add_C {n : \u2115} (hn : 0 < n) (a : R) : degree ((X : R[X]) ^ n + C a) = n := by\n  have : degree (C a) < degree ((X : R[X]) ^ n) :=\n    -- Porting note: `Nat.cast_withBot` is required.\n    degree_C_le.trans_lt <| by rwa [degree_X_pow, Nat.cast_withBot, WithBot.coe_pos]\n  rw [degree_add_eq_left_of_degree_lt this, degree_X_pow]\n#align polynomial.degree_X_pow_add_C Polynomial.degree_X_pow_add_C\n\ntheorem X_pow_add_C_ne_zero {n : \u2115} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a \u2260 0 :=\n  mt degree_eq_bot.2\n    (show degree ((X : R[X]) ^ n + C a) \u2260 \u22a5 by\n      rw [degree_X_pow_add_C hn a]; exact WithBot.coe_ne_bot)\n#align polynomial.X_pow_add_C_ne_zero Polynomial.X_pow_add_C_ne_zero\n\ntheorem X_add_C_ne_zero (r : R) : X + C r \u2260 0 :=\n  pow_one (X : R[X]) \u25b8 X_pow_add_C_ne_zero zero_lt_one r\n#align polynomial.X_add_C_ne_zero Polynomial.X_add_C_ne_zero\n\ntheorem zero_nmem_multiset_map_X_add_C {\u03b1 : Type _} (m : Multiset \u03b1) (f : \u03b1 \u2192 R) :\n    (0 : R[X]) \u2209 m.map fun a => X + C (f a) := fun mem =>\n  let \u27e8_a, _, ha\u27e9 := Multiset.mem_map.mp mem\n  X_add_C_ne_zero _ ha\n#align polynomial.zero_nmem_multiset_map_X_add_C Polynomial.zero_nmem_multiset_map_X_add_C\n\ntheorem natDegree_X_pow_add_C {n : \u2115} {r : R} : (X ^ n + C r).natDegree = n := by\n  by_cases hn : n = 0\n  \u00b7 rw [hn, pow_zero, \u2190 C_1, \u2190 RingHom.map_add, natDegree_C]\n  \u00b7 exact natDegree_eq_of_degree_eq_some (degree_X_pow_add_C (pos_iff_ne_zero.mpr hn) r)\n#align polynomial.nat_degree_X_pow_add_C Polynomial.natDegree_X_pow_add_C\n\ntheorem X_pow_add_C_ne_one {n : \u2115} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a \u2260 1 := fun h =>\n  hn.ne' <| by simpa only [natDegree_X_pow_add_C, natDegree_one] using congr_arg natDegree h\n#align polynomial.X_pow_add_C_ne_one Polynomial.X_pow_add_C_ne_one\n\ntheorem X_add_C_ne_one (r : R) : X + C r \u2260 1 :=\n  pow_one (X : R[X]) \u25b8 X_pow_add_C_ne_one zero_lt_one r\n#align polynomial.X_add_C_ne_one Polynomial.X_add_C_ne_one\n\nend Semiring\n\nend NonzeroRing\n\nsection Semiring\n\nvariable [Semiring R]\n\n@[simp]\ntheorem leadingCoeff_X_pow_add_C {n : \u2115} (hn : 0 < n) {r : R} :\n    (X ^ n + C r).leadingCoeff = 1 := by\n  nontriviality R\n  rw [leadingCoeff, natDegree_X_pow_add_C, coeff_add, coeff_X_pow_self, coeff_C,\n    if_neg (pos_iff_ne_zero.mp hn), add_zero]\n#align polynomial.leading_coeff_X_pow_add_C Polynomial.leadingCoeff_X_pow_add_C\n\n@[simp]\ntheorem leadingCoeff_X_add_C [Semiring S] (r : S) : (X + C r).leadingCoeff = 1 := by\n  rw [\u2190 pow_one (X : S[X]), leadingCoeff_X_pow_add_C zero_lt_one]\n#align polynomial.leading_coeff_X_add_C Polynomial.leadingCoeff_X_add_C\n\n@[simp]\ntheorem leadingCoeff_X_pow_add_one {n : \u2115} (hn : 0 < n) : (X ^ n + 1 : R[X]).leadingCoeff = 1 :=\n  leadingCoeff_X_pow_add_C hn\n#align polynomial.leading_coeff_X_pow_add_one Polynomial.leadingCoeff_X_pow_add_one\n\n@[simp]\ntheorem leadingCoeff_pow_X_add_C (r : R) (i : \u2115) : leadingCoeff ((X + C r) ^ i) = 1 := by\n  nontriviality\n  rw [leadingCoeff_pow'] <;> simp\n#align polynomial.leading_coeff_pow_X_add_C Polynomial.leadingCoeff_pow_X_add_C\n\nend Semiring\n\nsection Ring\n\nvariable [Ring R]\n\n@[simp]\ntheorem leadingCoeff_X_pow_sub_C {n : \u2115} (hn : 0 < n) {r : R} :\n    (X ^ n - C r).leadingCoeff = 1 := by\n  rw [sub_eq_add_neg, \u2190 map_neg C r, leadingCoeff_X_pow_add_C hn]\n#align polynomial.leading_coeff_X_pow_sub_C Polynomial.leadingCoeff_X_pow_sub_C\n\n@[simp]\ntheorem leadingCoeff_X_pow_sub_one {n : \u2115} (hn : 0 < n) : (X ^ n - 1 : R[X]).leadingCoeff = 1 :=\n  leadingCoeff_X_pow_sub_C hn\n#align polynomial.leading_coeff_X_pow_sub_one Polynomial.leadingCoeff_X_pow_sub_one\n\nvariable [Nontrivial R]\n\n@[simp]\ntheorem degree_X_sub_C (a : R) : degree (X - C a) = 1 := by\n  rw [sub_eq_add_neg, \u2190 map_neg C a, degree_X_add_C]\n#align polynomial.degree_X_sub_C Polynomial.degree_X_sub_C\n\n@[simp]\ntheorem natDegree_X_sub_C (x : R) : (X - C x).natDegree = 1 :=\n  natDegree_eq_of_degree_eq_some <| degree_X_sub_C x\n#align polynomial.nat_degree_X_sub_C Polynomial.natDegree_X_sub_C\n\n@[simp]\ntheorem nextCoeff_X_sub_C [Ring S] (c : S) : nextCoeff (X - C c) = -c := by\n  rw [sub_eq_add_neg, \u2190 map_neg C c, nextCoeff_X_add_C]\n#align polynomial.next_coeff_X_sub_C Polynomial.nextCoeff_X_sub_C\n\ntheorem degree_X_pow_sub_C {n : \u2115} (hn : 0 < n) (a : R) : degree ((X : R[X]) ^ n - C a) = n := by\n  rw [sub_eq_add_neg, \u2190 map_neg C a, degree_X_pow_add_C hn]\n#align polynomial.degree_X_pow_sub_C Polynomial.degree_X_pow_sub_C\n\ntheorem X_pow_sub_C_ne_zero {n : \u2115} (hn : 0 < n) (a : R) : (X : R[X]) ^ n - C a \u2260 0 := by\n  rw [sub_eq_add_neg, \u2190 map_neg C a]\n  exact X_pow_add_C_ne_zero hn _\n#align polynomial.X_pow_sub_C_ne_zero Polynomial.X_pow_sub_C_ne_zero\n\ntheorem X_sub_C_ne_zero (r : R) : X - C r \u2260 0 :=\n  pow_one (X : R[X]) \u25b8 X_pow_sub_C_ne_zero zero_lt_one r\n#align polynomial.X_sub_C_ne_zero Polynomial.X_sub_C_ne_zero\n\ntheorem zero_nmem_multiset_map_X_sub_C {\u03b1 : Type _} (m : Multiset \u03b1) (f : \u03b1 \u2192 R) :\n    (0 : R[X]) \u2209 m.map fun a => X - C (f a) := fun mem =>\n  let \u27e8_a, _, ha\u27e9 := Multiset.mem_map.mp mem\n  X_sub_C_ne_zero _ ha\n#align polynomial.zero_nmem_multiset_map_X_sub_C Polynomial.zero_nmem_multiset_map_X_sub_C\n\ntheorem natDegree_X_pow_sub_C {n : \u2115} {r : R} : (X ^ n - C r).natDegree = n := by\n  rw [sub_eq_add_neg, \u2190 map_neg C r, natDegree_X_pow_add_C]\n#align polynomial.nat_degree_X_pow_sub_C Polynomial.natDegree_X_pow_sub_C\n\n@[simp]\ntheorem leadingCoeff_X_sub_C [Ring S] (r : S) : (X - C r).leadingCoeff = 1 := by\n  rw [sub_eq_add_neg, \u2190 map_neg C r, leadingCoeff_X_add_C]\n#align polynomial.leading_coeff_X_sub_C Polynomial.leadingCoeff_X_sub_C\n\nend Ring\n\nsection NoZeroDivisors\n\nvariable [Semiring R] [NoZeroDivisors R] {p q : R[X]}\n\n@[simp]\ntheorem degree_mul : degree (p * q) = degree p + degree q :=\n  if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, WithBot.bot_add]\n  else\n    if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, WithBot.add_bot]\n    else degree_mul' <| mul_ne_zero (mt leadingCoeff_eq_zero.1 hp0) (mt leadingCoeff_eq_zero.1 hq0)\n#align polynomial.degree_mul Polynomial.degree_mul\n\n/-- `degree` as a monoid homomorphism between `R[X]` and `Multiplicative (WithBot \u2115)`.\n  This is useful to prove results about multiplication and degree. -/\ndef degreeMonoidHom [Nontrivial R] : R[X] \u2192* Multiplicative (WithBot \u2115)\n    where\n  toFun := degree\n  map_one' := degree_one\n  map_mul' _ _ := degree_mul\n#align polynomial.degree_monoid_hom Polynomial.degreeMonoidHom\n\n@[simp]\ntheorem degree_pow [Nontrivial R] (p : R[X]) (n : \u2115) : degree (p ^ n) = n \u2022 degree p :=\n  map_pow (@degreeMonoidHom R _ _ _) _ _\n#align polynomial.degree_pow Polynomial.degree_pow\n\n@[simp]\ntheorem leadingCoeff_mul (p q : R[X]) : leadingCoeff (p * q) = leadingCoeff p * leadingCoeff q := by\n  by_cases hp : p = 0\n  \u00b7 simp only [hp, zero_mul, leadingCoeff_zero]\n  \u00b7 by_cases hq : q = 0\n    \u00b7 simp only [hq, mul_zero, leadingCoeff_zero]\n    \u00b7 rw [leadingCoeff_mul']\n      exact mul_ne_zero (mt leadingCoeff_eq_zero.1 hp) (mt leadingCoeff_eq_zero.1 hq)\n#align polynomial.leading_coeff_mul Polynomial.leadingCoeff_mul\n\n/-- `Polynomial.leadingCoeff` bundled as a `MonoidHom` when `R` has `NoZeroDivisors`, and thus\n  `leadingCoeff` is multiplicative -/\ndef leadingCoeffHom : R[X] \u2192* R where\n  toFun := leadingCoeff\n  map_one' := by simp\n  map_mul' := leadingCoeff_mul\n#align polynomial.leading_coeff_hom Polynomial.leadingCoeffHom\n\n@[simp]\ntheorem leadingCoeffHom_apply (p : R[X]) : leadingCoeffHom p = leadingCoeff p :=\n  rfl\n#align polynomial.leading_coeff_hom_apply Polynomial.leadingCoeffHom_apply\n\n@[simp]\ntheorem leadingCoeff_pow (p : R[X]) (n : \u2115) : leadingCoeff (p ^ n) = leadingCoeff p ^ n :=\n  (leadingCoeffHom : R[X] \u2192* R).map_pow p n\n#align polynomial.leading_coeff_pow Polynomial.leadingCoeff_pow\n\nend NoZeroDivisors\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Degree/Definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7383120442629197}}
{"text": "import analysis.convex.specific_functions\nimport analysis.convex.combination\n\nopen real set\nopen_locale big_operators\n\n/-\n\nvariables {E F : Type*}\nvariables [ordered_add_comm_group E] [module \u211d E]\nvariables [ordered_add_comm_group F] [module \u211d F]\nvariables {s : set E} {f : E \u2192 F} (t : set F) (g : F \u2192 E)\n\nlemma concave_on_of_convex_on_inverse (hs : convex \u211d s) (hg : convex_on t g)\n  (hfs : s \u2286 f \u207b\u00b9' t) (hgt : t \u2286 g \u207b\u00b9' s)\n  (hgf : \u2200 {x}, x \u2208 s \u2192 g (f x) = x) (hfg : \u2200 {y}, y \u2208 t \u2192 f (g y) = y)\n  (hf : \u2200 {x\u2081 x\u2082}, x\u2081 \u2208 s \u2192 x\u2082 \u2208 s \u2192 x\u2081 \u2264 x\u2082 \u2192 f x\u2081 \u2264 f x\u2082) :\n  concave_on s f :=\nbegin\n  refine \u27e8hs, _\u27e9,\n  intros x y xs ys a b ha hb hab,\n  have H : a \u2022 f x + b \u2022 f y \u2208 t := hg.1 (hfs xs) (hfs ys) ha hb hab,\n  have := hf (hgt H) _ (hg.2 (hfs xs) (hfs ys) ha hb hab),\n  { rwa [hgf xs, hgf ys, hfg H] at this },\n  { rw [hgf xs, hgf ys], exact hs xs ys ha hb hab, }\nend\n\nlemma concave_on_rpow {p : \u211d} (hp0 : 0 \u2264 p) (hp1 : p \u2264 1) : concave_on (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  by_cases hp : p = 0,\n  { simpa only [hp, rpow_zero] using concave_on_const (1:\u211d) (convex_Ici 0) },\n  have h0p : 0 < p := lt_of_le_of_ne hp0 (ne.symm hp),\n  have : \u2200 {s t : set \u211d}, s \u2286 t \u2194 (\u2200 x, x \u2208 s \u2192 x \u2208 t) := \u03bb s t, iff.rfl,\n  apply concave_on_of_convex_on_inverse (Ici 0) (\u03bb x:\u211d, x ^ (p\u207b\u00b9)) (convex_Ici 0)\n    (convex_on_rpow (one_le_inv h0p hp1)),\n  all_goals { simp only [this, mem_Ici, mem_preimage] },\n  { intros x hx, exact rpow_nonneg_of_nonneg hx _ },\n  { intros x hx, exact rpow_nonneg_of_nonneg hx _ },\n  { intros x hx, rw [\u2190 rpow_mul hx, mul_inv_cancel hp, rpow_one], },\n  { intros x hx, rw [\u2190 rpow_mul hx, inv_mul_cancel hp, rpow_one], },\n  { intros, apply rpow_le_rpow, assumption' },\nend\n\n-/\n", "meta": {"author": "leanprover-community", "repo": "lean-liquid", "sha": "92f188bd17f34dbfefc92a83069577f708851aec", "save_path": "github-repos/lean/leanprover-community-lean-liquid", "path": "github-repos/lean/leanprover-community-lean-liquid/lean-liquid-92f188bd17f34dbfefc92a83069577f708851aec/src/for_mathlib/real.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.808067208930584, "lm_q1q2_score": 0.7383120419391542}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de dupla nega\u00e7o:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P \u2192 \u00ac\u00acP  :=\nbegin\n  intro P,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  \u00ac\u00acP \u2192 P  :=\nbegin\n  intro H,\n  by_contradiction hboom,\n  contradiction,\n\nend\n\ntheorem doubleneg_law :\n  \u00ac\u00acP \u2194 P  :=\nbegin\n  split,\n  intro H,\n  by_contradiction hboom,\n  contradiction,\n  intro P,\n  contradiction,\nend\n\n------------------------------------------------\n-- Comutatividade dos \u2228,\u2227:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P \u2228 Q) \u2192 (Q \u2228 P)  :=\nbegin\n  intro H,\n  cases H with hp hq,\n  right,\n  exact hp,\n  left,\n  exact hq,\nend\n\ntheorem conj_comm :\n  (P \u2227 Q) \u2192 (Q \u2227 P)  :=\nbegin\n  intro H,\n  cases H with hp hq,\n  split,\n  exact hq,\n  exact hp,\nend\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de interdefinabilidade dos \u2192,\u2228:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (\u00acP \u2228 Q) \u2192 (P \u2192 Q)  :=\nbegin\n  intro H,\n  intro P,\n  cases H with hb hq,\n  contradiction,\n  exact hq,\nend\n\ntheorem disj_as_impl :\n  (P \u2228 Q) \u2192 (\u00acP \u2192 Q)  :=\nbegin\n  intro H,\n  intro I,\n  cases H with hp hq,\n  contradiction,\n  exact hq,\nend\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de contraposi\u00e7\u00e3o:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P \u2192 Q) \u2192 (\u00acQ \u2192 \u00acP)  :=\nbegin\n  intro H,\n  intro W,\n  intro G,\n  have J : Q := H G,\n  apply W,\n  exact J,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (\u00acQ \u2192 \u00acP) \u2192 (P \u2192 Q)  :=\nbegin\n  intro H,\n  intro P,\n  by_contra hboom,\n  apply H,\n  exact hboom,\n  exact P,\nend\n\ntheorem contrapositive_law :\n  (P \u2192 Q) \u2194 (\u00acQ \u2192 \u00acP)  :=\nbegin\n  split,\n  intro H,\n  intro W,\n  intro G,\n  have J : Q := H G,\n  apply W,\n  exact J,\n  intro H,\n  intro P,\n  by_contra hboom,\n  apply H,\n  exact hboom,\n  exact P,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  \u00ac\u00ac(P\u2228\u00acP)  :=\nbegin\n  intro H,\n  have h : P\u2228\u00acP,\n  right,\n  intro G,\n  have g : P\u2228\u00acP,\n  left,\n  exact G,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P \u2192 Q) \u2192 P) \u2192 \u00ac\u00acP  :=\nbegin\n  intro H,\n  intro G,\n  have g : (\u00acP \u2228 Q) \u2192 (P \u2192 Q),\n  intro J,\n  intro p,\n  cases J with hj hq,\n  contradiction,\n  exact hq,\n  have h : \u00acP \u2228 Q,\n  left,\n  exact G,\n  have hpq : P \u2192 Q := g h,\n  have p : P := H hpq,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de interdefinabilidade dos \u2228,\u2227:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P\u2228Q \u2192 \u00ac(\u00acP\u2227\u00acQ)  :=\nbegin\n  intro H,\n  intro G,\n  cases G with hp hq,\n  cases H with P Q,\n  apply hp,\n  exact P,\n  apply hq,\n  exact Q,\nend\n\ntheorem conj_as_negdisj :\n  P\u2227Q \u2192 \u00ac(\u00acP\u2228\u00acQ)  :=\nbegin\n  intro H,\n  intro G,\n  cases H with P Q,\n  cases G with hp hq,\n  apply hp,\n  exact P,\n  apply hq,\n  exact Q,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para \u2228,\u2227:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  \u00ac(P\u2228Q) \u2192 (\u00acP \u2227 \u00acQ)  :=\nbegin\n  intro H,\n  split,\n  intro hp,\n  have hpq : P\u2228Q,\n  left,\n  exact hp,\n  contradiction,\n  intro hq,\n  have hpq : P\u2228Q,\n  right,\n  exact hq,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (\u00acP \u2227 \u00acQ) \u2192 \u00ac(P\u2228Q)  :=\nbegin\n  intro H,\n  intro G,\n  cases H with ho hw,\n  cases G with hp hq,\n  apply ho,\n  exact hp,\n  apply hw,\n  exact hq,\nend\n\ntheorem demorgan_conj :\n  \u00ac(P\u2227Q) \u2192 (\u00acQ \u2228 \u00acP)  :=\nbegin\n  intro H,\n  by_cases h : P,\n  left,\n  intro G,\n  have j : P\u2227Q,\n  split,\n  exact h,\n  exact G,\n  apply H,\n  exact j,\n  right,\n  exact h,\n\nend\n\ntheorem demorgan_conj_converse :\n  (\u00acQ \u2228 \u00acP) \u2192 \u00ac(P\u2227Q)  :=\nbegin\n  intro H,\n  intro G,\n  cases G with hp hq,\n  cases H with hw ho,\n  apply hw,\n  exact hq,\n  apply ho,\n  exact hp,\nend\n\ntheorem demorgan_conj_law :\n  \u00ac(P\u2227Q) \u2194 (\u00acQ \u2228 \u00acP)  :=\nbegin\n  split,\n  intro H,\n  by_cases h : P,\n  left,\n  intro G,\n  have j : P\u2227Q,\n  split,\n  exact h,\n  exact G,\n  apply H,\n  exact j,\n  right,\n  exact h,\n  intro H,\n  intro G,\n  cases G with hp hq,\n  cases H with hw ho,\n  apply hw,\n  exact hq,\n  apply ho,\n  exact hp,\nend\n\ntheorem demorgan_disj_law :\n  \u00ac(P\u2228Q) \u2194 (\u00acP \u2227 \u00acQ)  :=\nbegin\n  split,\n  intro H,\n  split,\n  intro hp,\n  have hpq : P\u2228Q,\n  left,\n  exact hp,\n  contradiction,\n  intro hq,\n  have hpq : P\u2228Q,\n  right,\n  exact hq,\n  contradiction,\n  intro H,\n  intro G,\n  cases H with ho hw,\n  cases G with hp hq,\n  apply ho,\n  exact hp,\n  apply hw,\n  exact hq,\nend\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de distributividade dos \u2228,\u2227:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P\u2227(Q\u2228R) \u2192 (P\u2227Q)\u2228(P\u2227R)  :=\nbegin\n  intro H,\n  cases H with hp hqr,\n  cases hqr with hq hr,\n  left,\n  split,\n  exact hp,\n  exact hq,\n  right,\n  split,\n  exact hp,\n  exact hr,\nend\n\ntheorem distr_conj_disj_converse :\n  (P\u2227Q)\u2228(P\u2227R) \u2192 P\u2227(Q\u2228R)  :=\nbegin\n  intro H,\n  split,\n  cases H with hpq hpr,\n  cases hpq with hp hq,\n  exact hp,\n  cases hpr with hp hr,\n  exact hp,\n  cases H with hpq hpr,\n  left,\n  cases hpq with hp hq,\n  exact hq,\n  right,\n  cases hpr with hp hr,\n  exact hr,\nend\n\ntheorem distr_disj_conj :\n  P\u2228(Q\u2227R) \u2192 (P\u2228Q)\u2227(P\u2228R)  :=\nbegin\n  intro H,\n  split,\n  cases H with hp hqr,\n  left,\n  exact hp,\n  right,\n  cases hqr with hq hr,\n  exact hq,\n  cases H with hp hqr,\n  left,\n  exact hp,\n  right,\n  cases hqr with hq hr,\n  exact hr,\nend\n\ntheorem distr_disj_conj_converse :\n  (P\u2228Q)\u2227(P\u2228R) \u2192 P\u2228(Q\u2227R)  :=\nbegin\n  intro H,\n  cases H with hpq hpr,\n  cases hpq with hp hq,\n  left,\n  exact hp,\n  cases hpr with hp hr,\n  left,\n  exact hp,\n  right,\n  split,\n  exact hq,\n  exact hr,\nend\n\n\n------------------------------------------------\n-- Currifica\u00e7\u00e3o\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P\u2227Q)\u2192R) \u2192 (P\u2192(Q\u2192R))  :=\nbegin\n  intro H,\n  intro hp,\n  intro hq,\n  have h : P\u2227Q,\n  split,\n  exact hp,\n  exact hq,\n  apply H,\n  exact h,\nend\n\ntheorem uncurry_prop :\n  (P\u2192(Q\u2192R)) \u2192 ((P\u2227Q)\u2192R)  :=\nbegin\n  intro H,\n  intro G,\n  cases G with hp hq,\n  have hqr : Q\u2192R := H hp,\n  apply hqr,\n  exact hq,\nend\n\n\n------------------------------------------------\n-- Reflexividade da \u2192:\n------------------------------------------------\n\ntheorem impl_refl :\n  P \u2192 P  :=\nbegin\n  intro H,\n  exact H,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P \u2192 (P\u2228Q)  :=\nbegin\n  intro H,\n  left,\n  exact H,\nend\n\ntheorem weaken_disj_left :\n  Q \u2192 (P\u2228Q)  :=\nbegin\n  intro H,\n  right,\n  exact H,\nend\n\ntheorem weaken_conj_right :\n  (P\u2227Q) \u2192 P  :=\nbegin\n  intro H,\n  cases H with hp hq,\n  exact hp,\nend\n\ntheorem weaken_conj_left :\n  (P\u2227Q) \u2192 Q  :=\nbegin\n  intro H,\n  cases H with hp hq,\n  exact hq,\nend\n\ntheorem conj_idempot :\n  (P\u2227P) \u2194 P :=\nbegin\n  split,\n  intro H,\n  cases H with hp hq,\n  exact hp,\n  intro H,\n  split,\n  exact H, \n  exact H,\nend\n\ntheorem disj_idempot :\n  (P\u2228P) \u2194 P  :=\nbegin\n  split,\n  intro H,\n  cases H with hp1 hp2,\n  exact hp1,\n  exact hp2,\n  intro H,\n  left,\n  exact H,\nend\n\nend propositional\n\n\n----------------------------------------------------------------\n\n\nsection predicate\n\nvariable U : Type\nvariables P Q : U -> Prop\n\n\n------------------------------------------------\n-- As leis de De Morgan para \u2203,\u2200:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  \u00ac(\u2203x, P x) \u2192 (\u2200x, \u00acP x)  :=\nbegin\n  intro H,\n  intro a,\n  intro b,\n  apply H,\n  existsi a,\n  exact b,\nend\n\ntheorem demorgan_exists_converse :\n  (\u2200x, \u00acP x) \u2192 \u00ac(\u2203x, P x)  :=\nbegin\n  intro H,\n  intro G,\n  cases G with a G_h,\n  apply H,\n  exact G_h,\nend\n\ntheorem demorgan_forall :\n  \u00ac(\u2200x, P x) \u2192 (\u2203x, \u00acP x)  :=\nbegin\n  intro H,\n  by_contra hboom,\n  have h : \u2200x, P x,\n  intro a,\n  by_cases h : P a,\n  exact h,\n  have G : \u2203x, \u00acP x,\n  existsi a,\n  exact h,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_forall_converse :\n  (\u2203x, \u00acP x) \u2192 \u00ac(\u2200x, P x)  :=\nbegin\n  intro H,\n  intro G,\n  cases H with a H_g,\n  have hp : P a := G a,\n  apply H_g,\n  exact hp,\nend\n\ntheorem demorgan_forall_law :\n  \u00ac(\u2200x, P x) \u2194 (\u2203x, \u00acP x)  :=\nbegin\n  split,\n  intro H,\n  by_contra hboom,\n  have h : \u2200x, P x,\n  intro a,\n  by_cases h : P a,\n  exact h,\n  have G : \u2203x, \u00acP x,\n  existsi a,\n  exact h,\n  contradiction,\n  contradiction,\n  intro H,\n  intro G,\n  cases H with a H_g,\n  have hp : P a := G a,\n  apply H_g,\n  exact hp,\nend\n\ntheorem demorgan_exists_law :\n  \u00ac(\u2203x, P x) \u2194 (\u2200x, \u00acP x)  :=\nbegin\n  split,\n  intro H,\n  intro a,\n  intro b,\n  apply H,\n  existsi a,\n  exact b,\n  intro H,\n  intro G,\n  cases G with a G_h,\n  apply H,\n  exact G_h,\nend\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de interdefinabilidade dos \u2203,\u2200:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (\u2203x, P x) \u2192 \u00ac(\u2200x, \u00acP x)  :=\nbegin\n  intro H,\n  intro G,\n  cases H with a H_a,\n  apply G,\n  exact H_a,\nend\n\ntheorem forall_as_neg_exists :\n  (\u2200x, P x) \u2192 \u00ac(\u2203x, \u00acP x)  :=\nbegin\n  intro H,\n  intro G,\n  cases G with a G_a,\n  have H_a : P a := H a,\n  apply G_a,\n  exact H_a,\nend\n\ntheorem forall_as_neg_exists_converse :\n  \u00ac(\u2203x, \u00acP x) \u2192 (\u2200x, P x)  :=\nbegin\n  intro H,\n  intro a,\n  by_cases h : P a,\n  exact h,\n  have G : \u2203x, \u00acP x,\n  existsi a,\n  exact h,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_converse :\n  \u00ac(\u2200x, \u00acP x) \u2192 (\u2203x, P x)  :=\nbegin\n  intro H,\n  by_contra hboom,\n  have h : \u2200x, \u00acP x,\n  intro a,\n  intro G,\n  apply hboom,\n  existsi a,\n  exact G,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_law :\n  (\u2200x, P x) \u2194 \u00ac(\u2203x, \u00acP x)  :=\nbegin\n  split,\n  intro H,\n  intro G,\n  cases G with a G_a,\n  have H_a : P a := H a,\n  apply G_a,\n  exact H_a,\n  intro H,\n  intro a,\n  by_contra hboom,\n  apply H,\n  existsi a,\n  exact hboom,\nend\n\ntheorem exists_as_neg_forall_law :\n  (\u2203x, P x) \u2194 \u00ac(\u2200x, \u00acP x)  :=\nbegin\n  split,\n  intro H,\n  intro G,\n  cases H with a H_a,\n  apply G,\n  exact H_a,\n  intro H,\n  by_contra hboom,\n  have h : \u2200x, \u00acP x,\n  intro a,\n  intro G,\n  apply hboom,\n  existsi a,\n  exact G,\n  contradiction,\nend\n\n\n------------------------------------------------\n--  Proposi\u00e7\u00f5es de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (\u2203x, P x \u2227 Q x) \u2192 (\u2203x, P x) \u2227 (\u2203x, Q x)  :=\nbegin\n  intro H,\n  cases H with a hpq,\n  cases hpq with hp hq,\n  split,\n  existsi a,\n  exact hp,\n  existsi a,\n  exact hq,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (\u2203x, P x \u2228 Q x) \u2192 (\u2203x, P x) \u2228 (\u2203x, Q x)  :=\nbegin\n  intro H,\n  cases H with a hpq,\n  cases hpq with hp hq,\n  left,\n  existsi a,\n  exact hp,\n  right,\n  existsi a,\n  exact hq,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (\u2203x, P x) \u2228 (\u2203x, Q x) \u2192 (\u2203x, P x \u2228 Q x)  :=\nbegin\n  intro H,\n  cases H with hp hq,\n  cases hp with a hp_a,\n  existsi a,\n  left,\n  exact hp_a,\n  cases hq with a hq_a,\n   existsi a,\n  right,\n  exact hq_a,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (\u2200x, P x \u2227 Q x) \u2192 (\u2200x, P x) \u2227 (\u2200x, Q x)  :=\nbegin\n  intro H,\n  split,\n  intro a,\n  have hpq : P a \u2227 Q a := H a,\n  cases hpq with hp hq,\n  exact hp,\n  intro b,\n  have hpq : P b \u2227 Q b := H b,\n  cases hpq with hp hq,\n  exact hq,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (\u2200x, P x) \u2227 (\u2200x, Q x) \u2192 (\u2200x, P x \u2227 Q x)  :=\nbegin\n  intro H,\n  intro a,\n  cases H with hp hq,\n  split,\n  apply hp,\n  apply hq,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (\u2200x, P x) \u2228 (\u2200x, Q x) \u2192 (\u2200x, P x \u2228 Q x)  :=\nbegin\n  intro H,\n  intro a,\n  cases H with hp hq,\n  left,\n  apply hp,\n  right,\n  apply hq,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (\u2200x, P x \u2228 Q x) \u2192 (\u2200x, P x) \u2228 (\u2200x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (\u2203x, P x) \u2227 (\u2203x, Q x) \u2192 (\u2203x, P x \u2227 Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "CaioAzeved", "repo": "fmclean", "sha": "79d162a9563c97c46adad597eb452db50339a730", "save_path": "github-repos/lean/CaioAzeved-fmclean", "path": "github-repos/lean/CaioAzeved-fmclean/fmclean-79d162a9563c97c46adad597eb452db50339a730/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676514011486, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.738312028431099}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n-/\n\nimport Mathlib.Init.Logic\n\n/-! # Quotient types\n\nThese are ported from the Lean 3 standard library file `init/data/quot.lean`.\n-/\n\nsection\nvariable {\u03b1 : Type u}\nvariable (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n/-- `EqvGen r` is the equivalence relation generated by `r`. -/\ninductive EqvGen : \u03b1 \u2192 \u03b1 \u2192 Prop\n  | rel : \u2200 x y, r x y \u2192 EqvGen x y\n  | refl : \u2200 x, EqvGen x x\n  | symm : \u2200 x y, EqvGen x y \u2192 EqvGen y x\n  | trans : \u2200 x y z, EqvGen x y \u2192 EqvGen y z \u2192 EqvGen x z\n\n#align eqv_gen EqvGen\n\ntheorem EqvGen.is_equivalence : Equivalence (@EqvGen \u03b1 r) :=\n  Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _)\n\n/-- `EqvGen.Setoid r` is the setoid generated by a relation `r`.\n\nThe motivation for this definition is that `Quot r` behaves like `Quotient (EqvGen.Setoid r)`,\nsee for example `Quot.exact` and `Quot.EqvGen_sound`.\n-/\ndef EqvGen.Setoid : Setoid \u03b1 :=\n  Setoid.mk _ (EqvGen.is_equivalence r)\n#align eqv_gen.setoid EqvGen.Setoid\n\ntheorem Quot.exact {a b : \u03b1} (H : Quot.mk r a = Quot.mk r b) : EqvGen r a b :=\n  @Quotient.exact _ (EqvGen.Setoid r) a b (congr_arg\n    (Quot.lift (Quotient.mk (EqvGen.Setoid r)) (\u03bbx y h => Quot.sound (EqvGen.rel x y h))) H)\n#align quot.exact Quot.exact\n\ntheorem Quot.EqvGen_sound {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {a b : \u03b1} (H : EqvGen r a b) :\n    Quot.mk r a = Quot.mk r b :=\n  EqvGen.rec\n    (\u03bb _ _ h => Quot.sound h)\n    (\u03bb _ => rfl)\n    (\u03bb _ _ _ IH => Eq.symm IH)\n    (\u03bb _ _ _ _ _ IH\u2081 IH\u2082 => Eq.trans IH\u2081 IH\u2082)\n    H\n#align quot.eqv_gen_sound Quot.EqvGen_sound\n\nend\n\nopen Decidable\ninstance Quotient.decidableEq {\u03b1 : Sort u} {s : Setoid \u03b1} [d : \u2200 a b : \u03b1, Decidable (a \u2248 b)] :\n    DecidableEq (Quotient s) :=\n  \u03bb q\u2081 q\u2082 : Quotient s =>\n    Quotient.recOnSubsingleton\u2082 q\u2081 q\u2082\n      (\u03bb a\u2081 a\u2082 =>\n        match (d a\u2081 a\u2082) with\n        | (isTrue h\u2081)  => isTrue (Quotient.sound h\u2081)\n        | (isFalse h\u2082) => isFalse (\u03bb h => absurd (Quotient.exact h) h\u2082))\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Init/Data/Quot.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7382494191719833}}
{"text": "import filter_world.level3 --hide\nopen set --hide\nnamespace filters --hide\nlocalized \"notation `P` := principal\" in filters --hide\n\n/-\n# Level 4: The meet of a pair of filters\n-/\n\ndef meet_set' {X : Type*} (V F : filter X) := {t | \u2203 (v \u2208 V) (f \u2208 F), v \u2229 f \u2286 t}\n\n/- Lemma\nThe collection of subsets defined before is a filter.\n-/\nlemma is_filter_meet {X : Type} (V F : filter X): is_filter (meet_set' V F) :=\nbegin\n  fconstructor,\n  {\n    exact \u27e8univ, V.univ_sets, univ, F.univ_sets, (univ \u2229 univ).subset_univ\u27e9\n  },\n  {\n    rintros A B \u27e8v, hv, f, hf, H\u27e9 hAB,\n    exact \u27e8v, hv, f, hf, subset.trans H hAB\u27e9\n  },\n  {\n    rintros A B \u27e8v\u2081, hv\u2081, f\u2081, hf\u2081, H\u2081\u27e9 \u27e8v\u2082, hv\u2082, f\u2082, hf\u2082, H\u2082\u27e9,\n    have : v\u2081 \u2229 v\u2082 \u2229 (f\u2081 \u2229 f\u2082) = v\u2081 \u2229 f\u2081 \u2229 (v\u2082 \u2229 f\u2082),\n      by rwa [\u2190 inter_assoc, inter_assoc v\u2081, inter_comm v\u2082, \u2190 inter_assoc, \u2190 inter_assoc],\n    obtain hvf := inter_subset_inter H\u2081 H\u2082,\n    exact \u27e8v\u2081 \u2229 v\u2082, V.inter_sets hv\u2081 hv\u2082, f\u2081 \u2229 f\u2082, F.inter_sets hf\u2081 hf\u2082, by rwa this\u27e9,\n  }\n\n\n\n\n\n\n\n\nend\n\n\ndef meet {\u03b1 : Type*} (V F : filter \u03b1) : filter \u03b1 := --hide\n{ sets := {t | \u2203 (v f : set \u03b1), v \u2208 V \u2227 f \u2208 F \u2227 v \u2229 f \u2286 t }, --hide\n  univ_sets := \u27e8univ, univ, V.univ_sets, F.univ_sets, (univ \u2229 univ).subset_univ\u27e9, --hide\n  sets_of_superset := (\u03bb A B \u27e8v, f, hv, hf, H\u27e9 hAB, \u27e8v, f, hv, hf, subset.trans H hAB\u27e9), --hide\n  inter_sets := --hide\n  begin --hide\n    rintros A B \u27e8v\u2081, f\u2081, hv\u2081, hf\u2081, H\u2081\u27e9 \u27e8v\u2082, f\u2082, hv\u2082, hf\u2082, H\u2082\u27e9, --hide\n    have : v\u2081 \u2229 v\u2082 \u2229 (f\u2081 \u2229 f\u2082) = v\u2081 \u2229 f\u2081 \u2229 (v\u2082 \u2229 f\u2082), --hide\n      by rwa [\u2190 inter_assoc, inter_assoc v\u2081, inter_comm v\u2082, \u2190 inter_assoc, \u2190 inter_assoc], --hide\n    obtain hvf := inter_subset_inter H\u2081 H\u2082, --hide\n    exact \u27e8v\u2081 \u2229 v\u2082, f\u2081 \u2229 f\u2082, V.inter_sets hv\u2081 hv\u2082, F.inter_sets hf\u2081 hf\u2082, by rwa this\u27e9 --hide\n  end } --hide\n\nend filters --hide", "meta": {"author": "mmasdeu", "repo": "topologygame", "sha": "0a1b868031919a5555e7b99efca66ece2f546ec7", "save_path": "github-repos/lean/mmasdeu-topologygame", "path": "github-repos/lean/mmasdeu-topologygame/topologygame-0a1b868031919a5555e7b99efca66ece2f546ec7/src/filter_world/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7382494014839506}}
{"text": "/-\nCopyright (c) S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport data.complex.module\nimport data.complex.is_R_or_C\n\n/-!\n# Normed space structure on `\u2102`.\n\nThis file gathers basic facts on complex numbers of an analytic nature.\n\n## Main results\n\nThis file registers `\u2102` as a normed field, expresses basic properties of the norm, and gives\ntools on the real vector space structure of `\u2102`. Notably, in the namespace `complex`,\nit defines functions:\n\n* `re_clm`\n* `im_clm`\n* `of_real_clm`\n* `conj_clm`\n\nThey are bundled versions of the real part, the imaginary part, the embedding of `\u211d` in `\u2102`, and\nthe complex conjugate as continuous `\u211d`-linear maps. The last two are also bundled as linear\nisometries in `of_real_li` and `conj_li`.\n\nWe also register the fact that `\u2102` is an `is_R_or_C` field.\n-/\nnoncomputable theory\n\n\nnamespace complex\n\ninstance : has_norm \u2102 := \u27e8abs\u27e9\n\ninstance : normed_group \u2102 :=\nnormed_group.of_core \u2102\n{ norm_eq_zero_iff := \u03bb z, abs_eq_zero,\n  triangle := abs_add,\n  norm_neg := abs_neg }\n\ninstance : normed_field \u2102 :=\n{ norm := abs,\n  dist_eq := \u03bb _ _, rfl,\n  norm_mul' := abs_mul,\n  .. complex.field }\n\ninstance : nondiscrete_normed_field \u2102 :=\n{ non_trivial := \u27e82, by simp [norm]; norm_num\u27e9 }\n\ninstance {R : Type*} [normed_field R] [normed_algebra R \u211d] : normed_algebra R \u2102 :=\n{ norm_algebra_map_eq := \u03bb x, (abs_of_real $ algebra_map R \u211d x).trans (norm_algebra_map_eq \u211d x),\n  to_algebra := complex.algebra }\n\n@[simp] lemma norm_eq_abs (z : \u2102) : \u2225z\u2225 = abs z := rfl\n\nlemma dist_eq (z w : \u2102) : dist z w = abs (z - w) := rfl\n\n@[simp] lemma norm_real (r : \u211d) : \u2225(r : \u2102)\u2225 = \u2225r\u2225 := abs_of_real _\n\n@[simp] lemma norm_rat (r : \u211a) : \u2225(r : \u2102)\u2225 = _root_.abs (r : \u211d) :=\nsuffices \u2225((r : \u211d) : \u2102)\u2225 = _root_.abs r, by simpa,\nby rw [norm_real, real.norm_eq_abs]\n\n@[simp] lemma norm_nat (n : \u2115) : \u2225(n : \u2102)\u2225 = n := abs_of_nat _\n\n@[simp] lemma norm_int {n : \u2124} : \u2225(n : \u2102)\u2225 = _root_.abs n :=\nsuffices \u2225((n : \u211d) : \u2102)\u2225 = _root_.abs n, by simpa,\nby rw [norm_real, real.norm_eq_abs]\n\nlemma norm_int_of_nonneg {n : \u2124} (hn : 0 \u2264 n) : \u2225(n : \u2102)\u2225 = n :=\nby rw [norm_int, _root_.abs_of_nonneg]; exact int.cast_nonneg.2 hn\n\nopen continuous_linear_map\n\n/-- Continuous linear map version of the real part function, from `\u2102` to `\u211d`. -/\ndef re_clm : \u2102 \u2192L[\u211d] \u211d := re_lm.mk_continuous 1 (\u03bb x, by simp [real.norm_eq_abs, abs_re_le_abs])\n\n@[continuity] lemma continuous_re : continuous re := re_clm.continuous\n\n@[simp] lemma re_clm_coe : (coe (re_clm) : \u2102 \u2192\u2097[\u211d] \u211d) = re_lm := rfl\n\n@[simp] \n\n@[simp] lemma re_clm_norm : \u2225re_clm\u2225 = 1 :=\nle_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _) $\ncalc 1 = \u2225re_clm 1\u2225 : by simp\n   ... \u2264 \u2225re_clm\u2225 : unit_le_op_norm _ _ (by simp)\n\n/-- Continuous linear map version of the real part function, from `\u2102` to `\u211d`. -/\ndef im_clm : \u2102 \u2192L[\u211d] \u211d := im_lm.mk_continuous 1 (\u03bb x, by simp [real.norm_eq_abs, abs_im_le_abs])\n\n@[continuity] lemma continuous_im : continuous im := im_clm.continuous\n\n@[simp] lemma im_clm_coe : (coe (im_clm) : \u2102 \u2192\u2097[\u211d] \u211d) = im_lm := rfl\n\n@[simp] lemma im_clm_apply (z : \u2102) : (im_clm : \u2102 \u2192 \u211d) z = z.im := rfl\n\n@[simp] lemma im_clm_norm : \u2225im_clm\u2225 = 1 :=\nle_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _) $\ncalc 1 = \u2225im_clm I\u2225 : by simp\n   ... \u2264 \u2225im_clm\u2225 : unit_le_op_norm _ _ (by simp)\n\n/-- The complex-conjugation function from `\u2102` to itself is an isometric linear map. -/\ndef conj_li : \u2102 \u2192\u2097\u1d62[\u211d] \u2102 := \u27e8conj_lm, \u03bb x, by simp\u27e9\n\n/-- Continuous linear map version of the conj function, from `\u2102` to `\u2102`. -/\ndef conj_clm : \u2102 \u2192L[\u211d] \u2102 := conj_li.to_continuous_linear_map\n\nlemma isometry_conj : isometry (conj : \u2102 \u2192 \u2102) := conj_li.isometry\n\n@[continuity] lemma continuous_conj : continuous conj := conj_clm.continuous\n\n@[simp] lemma conj_clm_coe : (coe (conj_clm) : \u2102 \u2192\u2097[\u211d] \u2102) = conj_lm := rfl\n\n@[simp] lemma conj_clm_apply (z : \u2102) : (conj_clm : \u2102 \u2192 \u2102) z = z.conj := rfl\n\n@[simp] lemma conj_clm_norm : \u2225conj_clm\u2225 = 1 := conj_li.norm_to_continuous_linear_map\n\n/-- Linear isometry version of the canonical embedding of `\u211d` in `\u2102`. -/\ndef of_real_li : \u211d \u2192\u2097\u1d62[\u211d] \u2102 := \u27e8of_real_lm, \u03bb x, by simp\u27e9\n\n/-- Continuous linear map version of the canonical embedding of `\u211d` in `\u2102`. -/\ndef of_real_clm : \u211d \u2192L[\u211d] \u2102 := of_real_li.to_continuous_linear_map\n\nlemma isometry_of_real : isometry (coe : \u211d \u2192 \u2102) := of_real_li.isometry\n\n@[continuity] lemma continuous_of_real : continuous (coe : \u211d \u2192 \u2102) := isometry_of_real.continuous\n\n@[simp] lemma of_real_clm_coe : (coe (of_real_clm) : \u211d \u2192\u2097[\u211d] \u2102) = of_real_lm := rfl\n\n@[simp] lemma of_real_clm_apply (x : \u211d) : (of_real_clm : \u211d \u2192 \u2102) x = x := rfl\n\n@[simp] lemma of_real_clm_norm : \u2225of_real_clm\u2225 = 1 := of_real_li.norm_to_continuous_linear_map\n\nnoncomputable instance : is_R_or_C \u2102 :=\n{ re := \u27e8complex.re, complex.zero_re, complex.add_re\u27e9,\n  im := \u27e8complex.im, complex.zero_im, complex.add_im\u27e9,\n  conj := complex.conj,\n  I := complex.I,\n  I_re_ax := by simp only [add_monoid_hom.coe_mk, complex.I_re],\n  I_mul_I_ax := by simp only [complex.I_mul_I, eq_self_iff_true, or_true],\n  re_add_im_ax := \u03bb z, by simp only [add_monoid_hom.coe_mk, complex.re_add_im,\n                                     complex.coe_algebra_map, complex.of_real_eq_coe],\n  of_real_re_ax := \u03bb r, by simp only [add_monoid_hom.coe_mk, complex.of_real_re,\n                                      complex.coe_algebra_map, complex.of_real_eq_coe],\n  of_real_im_ax := \u03bb r, by simp only [add_monoid_hom.coe_mk, complex.of_real_im,\n                                      complex.coe_algebra_map, complex.of_real_eq_coe],\n  mul_re_ax := \u03bb z w, by simp only [complex.mul_re, add_monoid_hom.coe_mk],\n  mul_im_ax := \u03bb z w, by simp only [add_monoid_hom.coe_mk, complex.mul_im],\n  conj_re_ax := \u03bb z, by simp only [ring_hom.coe_mk, add_monoid_hom.coe_mk, complex.conj_re],\n  conj_im_ax := \u03bb z, by simp only [ring_hom.coe_mk, complex.conj_im, add_monoid_hom.coe_mk],\n  conj_I_ax := by simp only [complex.conj_I, ring_hom.coe_mk],\n  norm_sq_eq_def_ax := \u03bb z, by simp only [\u2190complex.norm_sq_eq_abs, \u2190complex.norm_sq_apply,\n    add_monoid_hom.coe_mk, complex.norm_eq_abs],\n  mul_im_I_ax := \u03bb z, by simp only [mul_one, add_monoid_hom.coe_mk, complex.I_im],\n  inv_def_ax := \u03bb z, by simp only [complex.inv_def, complex.norm_sq_eq_abs, complex.coe_algebra_map,\n    complex.of_real_eq_coe, complex.norm_eq_abs],\n  div_I_ax := complex.div_I }\n\nend complex\n\nnamespace is_R_or_C\n\nlocal notation `reC` := @is_R_or_C.re \u2102 _\nlocal notation `imC` := @is_R_or_C.im \u2102 _\nlocal notation `conjC` := @is_R_or_C.conj \u2102 _\nlocal notation `IC` := @is_R_or_C.I \u2102 _\nlocal notation `absC` := @is_R_or_C.abs \u2102 _\nlocal notation `norm_sqC` := @is_R_or_C.norm_sq \u2102 _\n\n@[simp] lemma re_to_complex {x : \u2102} : reC x = x.re := rfl\n@[simp] lemma im_to_complex {x : \u2102} : imC x = x.im := rfl\n@[simp] lemma conj_to_complex {x : \u2102} : conjC x = x.conj := rfl\n@[simp] lemma I_to_complex : IC = complex.I := rfl\n@[simp] lemma norm_sq_to_complex {x : \u2102} : norm_sqC x = complex.norm_sq x :=\nby simp [is_R_or_C.norm_sq, complex.norm_sq]\n@[simp] lemma abs_to_complex {x : \u2102} : absC x = complex.abs x :=\nby simp [is_R_or_C.abs, complex.abs]\n\nend is_R_or_C\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7382384272026145}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\n\nimport algebra.group.units\nimport algebra.ring.basic\n\n/-!\n# Invertible elements\n\nThis file defines a typeclass `invertible a` for elements `a` with a two-sided\nmultiplicative inverse.\n\nThe intent of the typeclass is to provide a way to write e.g. `\u215f2` in a ring\nlike `\u2124[1/2]` where some inverses exist but there is no general `\u207b\u00b9` operator;\nor to specify that a field has characteristic `\u2260 2`.\nIt is the `Type`-valued analogue to the `Prop`-valued `is_unit`.\n\nFor constructions of the invertible element given a characteristic, see\n`algebra/char_p/invertible` and other lemmas in that file.\n\n## Notation\n\n * `\u215fa` is `invertible.inv_of a`, the inverse of `a`\n\n## Implementation notes\n\nThe `invertible` class lives in `Type`, not `Prop`, to make computation easier.\nIf multiplication is associative, `invertible` is a subsingleton anyway.\n\nThe `simp` normal form tries to normalize `\u215fa` to `a \u207b\u00b9`. Otherwise, it pushes\n`\u215f` inside the expression as much as possible.\n\nSince `invertible a` is not a `Prop` (but it is a `subsingleton`), we have to be careful about\ncoherence issues: we should avoid having multiple non-defeq instances for `invertible a` in the\nsame context.  This file plays it safe and uses `def` rather than `instance` for most definitions,\nusers can choose which instances to use at the point of use.\n\nFor example, here's how you can use an `invertible 1` instance:\n```lean\nvariables {\u03b1 : Type*} [monoid \u03b1]\n\ndef something_that_needs_inverses (x : \u03b1) [invertible x] := sorry\n\nsection\nlocal attribute [instance] invertible_one\ndef something_one := something_that_needs_inverses 1\nend\n```\n\n## Tags\n\ninvertible, inverse element, inv_of, a half, one half, a third, one third, \u00bd, \u2153\n\n-/\n\nuniverses u\n\nvariables {\u03b1 : Type u}\n\n/-- `invertible a` gives a two-sided multiplicative inverse of `a`. -/\nclass invertible [has_mul \u03b1] [has_one \u03b1] (a : \u03b1) : Type u :=\n(inv_of : \u03b1) (inv_of_mul_self : inv_of * a = 1) (mul_inv_of_self : a * inv_of = 1)\n\n-- This notation has the same precedence as `has_inv.inv`.\nnotation `\u215f`:1034 := invertible.inv_of\n\n@[simp]\nlemma inv_of_mul_self [has_mul \u03b1] [has_one \u03b1] (a : \u03b1) [invertible a] : \u215fa * a = 1 :=\ninvertible.inv_of_mul_self\n\n@[simp]\nlemma mul_inv_of_self [has_mul \u03b1] [has_one \u03b1] (a : \u03b1) [invertible a] : a * \u215fa = 1 :=\ninvertible.mul_inv_of_self\n\n@[simp]\nlemma inv_of_mul_self_assoc [monoid \u03b1] (a b : \u03b1) [invertible a] : \u215fa * (a * b) = b :=\nby rw [\u2190mul_assoc, inv_of_mul_self, one_mul]\n\n@[simp]\nlemma mul_inv_of_self_assoc [monoid \u03b1] (a b : \u03b1) [invertible a] : a * (\u215fa * b) = b :=\nby rw [\u2190mul_assoc, mul_inv_of_self, one_mul]\n\n@[simp]\nlemma mul_inv_of_mul_self_cancel [monoid \u03b1] (a b : \u03b1) [invertible b] : a * \u215fb * b = a :=\nby simp [mul_assoc]\n\n@[simp]\nlemma mul_mul_inv_of_self_cancel [monoid \u03b1] (a b : \u03b1) [invertible b] : a * b * \u215fb = a :=\nby simp [mul_assoc]\n\nlemma inv_of_eq_right_inv [monoid \u03b1] {a b : \u03b1} [invertible a] (hac : a * b = 1) : \u215fa = b :=\nleft_inv_eq_right_inv (inv_of_mul_self _) hac\n\nlemma inv_of_eq_left_inv [monoid \u03b1] {a b : \u03b1} [invertible a] (hac : b * a = 1) : \u215fa = b :=\n(left_inv_eq_right_inv hac (mul_inv_of_self _)).symm\n\nlemma invertible_unique {\u03b1 : Type u} [monoid \u03b1] (a b : \u03b1) (h : a = b)\n  [invertible a] [invertible b] :\n  \u215fa = \u215fb :=\nby { apply inv_of_eq_right_inv, rw [h, mul_inv_of_self], }\n\ninstance [monoid \u03b1] (a : \u03b1) : subsingleton (invertible a) :=\n\u27e8 \u03bb \u27e8b, hba, hab\u27e9 \u27e8c, hca, hac\u27e9, by { congr, exact left_inv_eq_right_inv hba hac } \u27e9\n\n/-- If `r` is invertible and `s = r`, then `s` is invertible. -/\ndef invertible.copy [monoid \u03b1] {r : \u03b1} (hr : invertible r) (s : \u03b1) (hs : s = r) : invertible s :=\n{ inv_of := \u215fr,\n  inv_of_mul_self := by rw [hs, inv_of_mul_self],\n  mul_inv_of_self := by rw [hs, mul_inv_of_self] }\n\n/-- An `invertible` element is a unit. -/\n@[simps]\ndef unit_of_invertible [monoid \u03b1] (a : \u03b1) [invertible a] : units \u03b1 :=\n{ val     := a,\n  inv     := \u215fa,\n  val_inv := by simp,\n  inv_val := by simp, }\n\nlemma is_unit_of_invertible [monoid \u03b1] (a : \u03b1) [invertible a] : is_unit a :=\n\u27e8unit_of_invertible a, rfl\u27e9\n\n/-- Units are invertible in their associated monoid. -/\ndef units.invertible [monoid \u03b1] (u : units \u03b1) : invertible (u : \u03b1) :=\n{ inv_of := \u2191(u\u207b\u00b9), inv_of_mul_self := u.inv_mul, mul_inv_of_self := u.mul_inv }\n\n@[simp] lemma inv_of_units [monoid \u03b1] (u : units \u03b1) [invertible (u : \u03b1)] : \u215f(u : \u03b1) = \u2191(u\u207b\u00b9) :=\ninv_of_eq_right_inv u.mul_inv\n\nlemma is_unit.nonempty_invertible [monoid \u03b1] {a : \u03b1} (h : is_unit a) : nonempty (invertible a) :=\nlet \u27e8x, hx\u27e9 := h in \u27e8x.invertible.copy _ hx.symm\u27e9\n\n/-- Convert `is_unit` to `invertible` using `classical.choice`.\n\nPrefer `casesI h.nonempty_invertible` over `letI := h.invertible` if you want to avoid choice. -/\nnoncomputable def is_unit.invertible [monoid \u03b1] {a : \u03b1} (h : is_unit a) : invertible a :=\nclassical.choice h.nonempty_invertible\n\n@[simp]\nlemma nonempty_invertible_iff_is_unit [monoid \u03b1] (a : \u03b1) :\n  nonempty (invertible a) \u2194 is_unit a :=\n\u27e8nonempty.rec $ @is_unit_of_invertible _ _ _, is_unit.nonempty_invertible\u27e9\n\n/-- Each element of a group is invertible. -/\ndef invertible_of_group [group \u03b1] (a : \u03b1) : invertible a :=\n\u27e8a\u207b\u00b9, inv_mul_self a, mul_inv_self a\u27e9\n\n@[simp] lemma inv_of_eq_group_inv [group \u03b1] (a : \u03b1) [invertible a] : \u215fa = a\u207b\u00b9 :=\ninv_of_eq_right_inv (mul_inv_self a)\n\n/-- `1` is the inverse of itself -/\ndef invertible_one [monoid \u03b1] : invertible (1 : \u03b1) :=\n\u27e81, mul_one _, one_mul _\u27e9\n\n@[simp] lemma inv_of_one [monoid \u03b1] [invertible (1 : \u03b1)] : \u215f(1 : \u03b1) = 1 :=\ninv_of_eq_right_inv (mul_one _)\n\n/-- `-\u215fa` is the inverse of `-a` -/\ndef invertible_neg [ring \u03b1] (a : \u03b1) [invertible a] : invertible (-a) :=\n\u27e8 -\u215fa, by simp, by simp \u27e9\n\n@[simp] lemma inv_of_neg [ring \u03b1] (a : \u03b1) [invertible a] [invertible (-a)] : \u215f(-a) = -\u215fa :=\ninv_of_eq_right_inv (by simp)\n\n@[simp] lemma one_sub_inv_of_two [ring \u03b1] [invertible (2:\u03b1)] : 1 - (\u215f2:\u03b1) = \u215f2 :=\n(is_unit_of_invertible (2:\u03b1)).mul_right_inj.1 $\n  by rw [mul_sub, mul_inv_of_self, mul_one, bit0, add_sub_cancel]\n\n/-- `a` is the inverse of `\u215fa`. -/\ninstance invertible_inv_of [has_one \u03b1] [has_mul \u03b1] {a : \u03b1} [invertible a] : invertible (\u215fa) :=\n\u27e8 a, mul_inv_of_self a, inv_of_mul_self a \u27e9\n\n@[simp] lemma inv_of_inv_of [monoid \u03b1] {a : \u03b1} [invertible a] [invertible (\u215fa)] :\n  \u215f(\u215fa) = a :=\ninv_of_eq_right_inv (inv_of_mul_self _)\n\n/-- `\u215fb * \u215fa` is the inverse of `a * b` -/\ndef invertible_mul [monoid \u03b1] (a b : \u03b1) [invertible a] [invertible b] : invertible (a * b) :=\n\u27e8 \u215fb * \u215fa, by simp [\u2190mul_assoc], by simp [\u2190mul_assoc] \u27e9\n\n@[simp]\nlemma inv_of_mul [monoid \u03b1] (a b : \u03b1) [invertible a] [invertible b] [invertible (a * b)] :\n  \u215f(a * b) = \u215fb * \u215fa :=\ninv_of_eq_right_inv (by simp [\u2190mul_assoc])\n\ntheorem commute.inv_of_right [monoid \u03b1] {a b : \u03b1} [invertible b] (h : commute a b) :\n  commute a (\u215fb) :=\ncalc a * (\u215fb) = (\u215fb) * (b * a * (\u215fb)) : by simp [mul_assoc]\n... = (\u215fb) * (a * b * ((\u215fb))) : by rw h.eq\n... = (\u215fb) * a : by simp [mul_assoc]\n\ntheorem commute.inv_of_left [monoid \u03b1] {a b : \u03b1} [invertible b] (h : commute b a) :\n  commute (\u215fb) a :=\ncalc (\u215fb) * a = (\u215fb) * (a * b * (\u215fb)) : by simp [mul_assoc]\n... = (\u215fb) * (b * a * (\u215fb)) : by rw h.eq\n... = a * (\u215fb) : by simp [mul_assoc]\n\nlemma commute_inv_of {M : Type*} [has_one M] [has_mul M] (m : M) [invertible m] :\n  commute m (\u215fm) :=\ncalc m * \u215fm = 1       : mul_inv_of_self m\n        ... = \u215f m * m : (inv_of_mul_self m).symm\n\nsection monoid_with_zero\nvariable [monoid_with_zero \u03b1]\n\n/-- A variant of `ring.inverse_unit`. -/\n@[simp] lemma ring.inverse_invertible (x : \u03b1) [invertible x] : ring.inverse x = \u215fx :=\nring.inverse_unit (unit_of_invertible _)\n\nend monoid_with_zero\n\nsection group_with_zero\n\nvariable [group_with_zero \u03b1]\n\nlemma nonzero_of_invertible (a : \u03b1) [invertible a] : a \u2260 0 :=\n\u03bb ha, zero_ne_one $ calc   0 = \u215fa * a : by simp [ha]\n                         ... = 1 : inv_of_mul_self a\n\n/-- `a\u207b\u00b9` is an inverse of `a` if `a \u2260 0` -/\ndef invertible_of_nonzero {a : \u03b1} (h : a \u2260 0) : invertible a :=\n\u27e8 a\u207b\u00b9, inv_mul_cancel h, mul_inv_cancel h \u27e9\n\n@[simp] lemma inv_of_eq_inv (a : \u03b1) [invertible a] : \u215fa = a\u207b\u00b9 :=\ninv_of_eq_right_inv (mul_inv_cancel (nonzero_of_invertible a))\n\n@[simp] lemma inv_mul_cancel_of_invertible (a : \u03b1) [invertible a] : a\u207b\u00b9 * a = 1 :=\ninv_mul_cancel (nonzero_of_invertible a)\n\n@[simp] lemma mul_inv_cancel_of_invertible (a : \u03b1) [invertible a] : a * a\u207b\u00b9 = 1 :=\nmul_inv_cancel (nonzero_of_invertible a)\n\n@[simp] lemma div_mul_cancel_of_invertible (a b : \u03b1) [invertible b] : a / b * b = a :=\ndiv_mul_cancel a (nonzero_of_invertible b)\n\n@[simp] lemma mul_div_cancel_of_invertible (a b : \u03b1) [invertible b] : a * b / b = a :=\nmul_div_cancel a (nonzero_of_invertible b)\n\n@[simp] lemma div_self_of_invertible (a : \u03b1) [invertible a] : a / a = 1 :=\ndiv_self (nonzero_of_invertible a)\n\n/-- `b / a` is the inverse of `a / b` -/\ndef invertible_div (a b : \u03b1) [invertible a] [invertible b] : invertible (a / b) :=\n\u27e8b / a, by simp [\u2190mul_div_assoc], by simp [\u2190mul_div_assoc]\u27e9\n\n@[simp] lemma inv_of_div (a b : \u03b1) [invertible a] [invertible b] [invertible (a / b)] :\n  \u215f(a / b) = b / a :=\ninv_of_eq_right_inv (by simp [\u2190mul_div_assoc])\n\n/-- `a` is the inverse of `a\u207b\u00b9` -/\ndef invertible_inv {a : \u03b1} [invertible a] : invertible (a\u207b\u00b9) :=\n\u27e8 a, by simp, by simp \u27e9\n\nend group_with_zero\n\n/--\nMonoid homs preserve invertibility.\n-/\ndef invertible.map {R : Type*} {S : Type*} [monoid R] [monoid S] (f : R \u2192* S)\n  (r : R) [invertible r] :\n  invertible (f r) :=\n{ inv_of := f (\u215fr),\n  inv_of_mul_self := by rw [\u2190 f.map_mul, inv_of_mul_self, f.map_one],\n  mul_inv_of_self := by rw [\u2190 f.map_mul, mul_inv_of_self, f.map_one] }\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.7382384159933599}}
{"text": "-- ==================== Syntax ====================\n\ndef loc := string\n\n\ninductive aexp : Type\n| Lookup : loc -> aexp\n| Int : int -> aexp\n| Plus : aexp -> aexp -> aexp\n| Minus : aexp -> aexp -> aexp\n| Times : aexp -> aexp -> aexp\n\n\ninductive bexp : Type\n| Bool : bool -> bexp\n| Equal : aexp -> aexp -> bexp\n| Less : aexp -> aexp -> bexp\n| Greater : aexp -> aexp -> bexp\n\n\ninductive cmd : Type\n| Assign : loc -> aexp -> cmd\n| IfThenElse  : bexp -> cmd -> cmd -> cmd\n| Seq : cmd -> cmd -> cmd\n| Skip : cmd\n| WhileDo : bexp -> cmd -> cmd\n\n-- ================== Example 'fact.imp' in LEAN notation. ==================\n\ndef fact : cmd :=\n  cmd.Seq\n    (cmd.Seq\n      (cmd.Assign \"n\" (aexp.Int 10))\n      (cmd.Assign \"fact\" (aexp.Int 10)) )\n    (cmd.WhileDo\n      (bexp.Greater\n        (aexp.Lookup \"n\")\n        (aexp.Int 0) )\n      (cmd.Seq\n        (cmd.Assign \"fact\" \n          (aexp.Times (aexp.Lookup \"fact\") (aexp.Lookup \"n\")) )\n        (cmd.Assign \"n\"\n          (aexp.Minus (aexp.Lookup \"n\") (aexp.Int 1)) ) ) )\n\n-- ==================== Environment ====================\n\ninductive env : Type\n| Nil : env\n| Cons : loc -> int -> env -> env\n\n\ninductive lookup : loc -> env -> int -> Prop\n| Find {loc i E} : \n    lookup loc (env.Cons loc i E) i \n| Search {loc loc' i' E' i} : \n    loc\u2260loc' -> lookup loc E' i -> \n    lookup loc (env.Cons loc' i' E') i\n\n-- ==================== Operational Semantics ====================\n\ninductive aeval : env -> aexp -> int -> Prop\n| Lookup {E loc i} :\n    lookup loc E i -> \n    aeval E (aexp.Lookup loc) i\n| Int {E i} :\n    aeval E (aexp.Int i) i\n| Plus {E a1 a2 i1 i2} :\n    aeval E a1 i1 -> aeval E a2 i2 ->\n    aeval E (aexp.Plus a1 a2) (i1 + i2)\n| Minus {E a1 a2 i1 i2} :\n    aeval E a1 i1 -> aeval E a2 i2 ->\n    aeval E (aexp.Minus a1 a2) (i1 - i2)\n| Times {E a1 a2 i1 i2} :\n    aeval E a1 i1 -> aeval E a2 i2 ->\n    aeval E (aexp.Times a1 a2) (i1 * i2)\n\n\n-- Lean works best with '<' and '\u2264' so we use them to encode '>' and '\u2265'.\ninductive beval : env -> bexp -> bool -> Prop\n| Bool {E b} :\n    beval E (bexp.Bool b) b\n| Equal_t {E a1 a2 i1 i2}:\n    aeval E a1 i1 -> aeval E a2 i2 -> i1 = i2 ->\n    beval E (bexp.Equal a1 a2) true\n| Equal_f {E a1 a2 i1 i2}:\n    aeval E a1 i1 -> aeval E a2 i2 -> i1 \u2260 i2 ->\n    beval E (bexp.Equal a1 a2) false\n| Less_t {E a1 a2 i1 i2}:\n    aeval E a1 i1 -> aeval E a2 i2 -> i1 < i2 ->\n    beval E (bexp.Less a1 a2) true\n| Less_f {E a1 a2 i1 i2}:\n    aeval E a1 i1 -> aeval E a2 i2 -> \u00ac i1 < i2 ->\n    beval E (bexp.Less a1 a2) false\n| Greater_t {E a1 a2 i1 i2}:\n    aeval E a1 i1 -> aeval E a2 i2 -> \u00ac i1 \u2264 i2 ->\n    beval E (bexp.Greater a1 a2) true\n| Greater_f {E a1 a2 i1 i2}:\n    aeval E a1 i1 -> aeval E a2 i2 -> i1 \u2264 i2 ->\n    beval E (bexp.Greater a1 a2) false\n\n\ninductive ceval : env -> cmd -> env -> Prop\n| Assign {loc a i E} :\n    aeval E a i ->\n    ceval E (cmd.Assign loc a) (env.Cons loc i E)\n| IfThenElse_t {E b c1 c2 M'} :\n    beval E b true -> ceval E c1 M' ->\n    ceval E (cmd.IfThenElse b c1 c2) M'\n| IfThenElse_f {E b c1 c2 E'} :\n    beval E b false -> ceval E c2 E' ->\n    ceval E (cmd.IfThenElse b c1 c2) E'\n| Seq {E c1 E' c2 E''} :\n    ceval E c1 E' -> ceval E' c2 E'' ->\n    ceval E (cmd.Seq c1 c2) E''\n| Skip {E} :\n    ceval E cmd.Skip E\n| WhileDo_t {E b c E' E''} :\n    beval E b true -> ceval E c E' ->\n    ceval E' (cmd.WhileDo b c) E'' ->\n    ceval E (cmd.WhileDo b c) E''\n| WhileDo_f {E b c} :\n    beval E b false -> \n    ceval E (cmd.WhileDo b c) E\n\n-- ==================== Safety ====================\n\n-- Contains all the names of already assigned locations.\ninductive locs : Type\n| Nil : locs\n| Cons : loc -> locs -> locs\n\n\ninductive loc_safe : loc -> locs -> Prop\n| Find {loc L} : \n    loc_safe loc (locs.Cons loc L) \n| Search {loc loc' L} : \n    loc'\u2260loc -> loc_safe loc L -> \n    loc_safe loc (locs.Cons loc' L)\n\n\ninductive asafe : locs -> aexp -> Prop\n| Lookup {L loc}:\n    loc_safe loc L -> asafe L (aexp.Lookup loc)\n| Int {L i}:\n    asafe L (aexp.Int i)\n| Plus {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    asafe L (aexp.Plus a1 a2)\n| Minus {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    asafe L (aexp.Minus a1 a2)\n| Times {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    asafe L (aexp.Times a1 a2)\n\n\ninductive bsafe : locs -> bexp -> Prop\n| Bool {L b} :\n    bsafe L (bexp.Bool b)\n| Equal {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    bsafe L (bexp.Equal a1 a2)\n| Less {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    bsafe L (bexp.Less a1 a2)\n| Greater {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    bsafe L (bexp.Greater a1 a2)\n\n\ninductive csafe : locs -> cmd -> locs -> Prop\n| Assign {L loc a} :\n    asafe L a ->\n    csafe L (cmd.Assign loc a) (locs.Cons loc L)\n-- | IfThenElse {L b c1 c2} :\n--     bsafe L b -> csafe L c1 L' -> csafe L c2 L'' ->\n-- Note: This part requires a definition of locs intersection. \n| Seq {L c1 L' c2 L''} :\n    csafe L c1 L' -> csafe L' c2 L'' ->\n    csafe L (cmd.Seq c1 c2) L''\n| Skip {L} :\n    csafe L cmd.Skip L\n| WhileDo {L b c L'} :\n    bsafe L b -> csafe L c L' ->\n    csafe L (cmd.WhileDo b c) L'\n\n-- ==================== Auxiliary safety for lookup ====================\n\n-- Proves that the given environment maps all the required locations.\ninductive env_maps : env -> locs -> Prop\n| Nil {E} :\n    env_maps E locs.Nil\n| Cons {loc E L} :\n    env_maps E L -> (\u2203i, lookup loc E i) ->\n    env_maps E (locs.Cons loc L)\n\n\n-- Increasing the environment does not break its safety.\ntheorem env_maps_weaken {E L loc i}:\n  env_maps E L -> env_maps (env.Cons loc i E) L\n:=\nbegin\n  intro es, induction es with E' loc' E' L' maps finds ih,\n  apply env_maps.Nil,\n  apply env_maps.Cons, assumption,\n  -- we compare the the strings to know which lookup result is correct\n  cases string.has_decidable_eq loc' loc with neq eq,\n  { cases finds with i', existsi i',\n    apply lookup.Search, assumption, assumption, },\n  existsi i, subst eq, apply lookup.Find,\nend\n\n\n-- If the location is safe in the same specification as the environment\n-- then we are guaranteed to look up a value\ntheorem safe_lookup {L E loc}:\n  loc_safe loc L -> env_maps E L -> \u2203 (i:int), lookup loc E i\n:=\nbegin\n  intros sloc es, \n  induction es with E' loc' E' L' maps finds ih,\n  { cases sloc, },\n  cases sloc, assumption, apply ih, assumption,\nend\n\n-- ==================== Safety theorems ====================\n\ntheorem asafety {L E a}:\n  asafe L a -> env_maps E L -> \u2203 (i:int), aeval E a i\n:=\nbegin\n  intros s es,\n  induction s,\n  case asafe.Lookup\n    { cases safe_lookup s_a es,\n      existsi w, apply aeval.Lookup, assumption, },\n  case asafe.Int\n    { existsi s_i, apply aeval.Int, },\n  case asafe.Plus\n    { cases s_ih_a es with i1,\n      cases s_ih_a_1 es with i2,\n      existsi (i1+i2), apply aeval.Plus, \n      assumption, assumption },\n  case asafe.Minus\n    { cases s_ih_a es with i1,\n      cases s_ih_a_1 es with i2,\n      existsi (i1-i2), apply aeval.Minus, \n      assumption, assumption },\n  case asafe.Times\n    { cases s_ih_a es with i1,\n      cases s_ih_a_1 es with i2,\n      existsi (i1*i2), apply aeval.Times, \n      assumption, assumption },\nend\n\n\ntheorem bsafety {L E b}:\n  bsafe L b -> env_maps E L -> \u2203 (v:bool), beval E b v\n:=\nbegin\n  intros s es,\n  induction s,\n  case bsafe.Bool\n    { existsi s_b, apply beval.Bool, },\n  case bsafe.Equal\n    { cases asafety s_a es with i1,\n      cases asafety s_a_1 es with i2,\n      cases int.decidable_eq i1 i2 with neq eq,\n      -- i1 \u2260 i2\n      { existsi (false:bool), apply beval.Equal_f,\n        assumption, assumption, assumption,},\n      -- i1 = i2\n      { existsi (true:bool), apply beval.Equal_t,\n        assumption, assumption, assumption,}, },\n  case bsafe.Less\n    { cases asafety s_a es with i1,\n      cases asafety s_a_1 es with i2,\n      cases int.decidable_lt i1 i2 with neq eq,\n      -- i1 \u2270 i2\n      { existsi (false:bool), apply beval.Less_f,\n        assumption, assumption, assumption,},\n      -- i1 < i2\n      { existsi (true:bool), apply beval.Less_t,\n        assumption, assumption, assumption,}, },\n  case bsafe.Greater\n    { cases asafety s_a es with i1,\n      cases asafety s_a_1 es with i2,\n      cases int.decidable_le i1 i2 with neq eq,\n      -- i > i2\n      { existsi (true:bool), apply beval.Greater_t,\n        assumption, assumption, assumption,},\n      -- i \u2271 i2\n      { existsi (false:bool), apply beval.Greater_f,\n        assumption, assumption, assumption,}, },\nend\n\n\ntheorem csafety {L L' E c }:\n  csafe L c L' -> env_maps E L -> \u2203 (E':env), ceval E c E' \u2227 env_maps E' L'\n:=\nbegin\n  intros s, revert E,\n  induction s; intros E es,\n  case csafe.Assign\n    { cases asafety s_a_1 es with i,\n      existsi (env.Cons s_loc i E),\n      constructor,\n      { apply ceval.Assign, assumption, },\n      apply env_maps.Cons,\n      { apply env_maps_weaken, assumption, },\n      existsi i, apply lookup.Find, },\n  case csafe.Seq\n    { cases (s_ih_a es) with E',\n      destruct h, intros c1s es',\n      cases (s_ih_a_1 es') with E'',\n      destruct h_1, intros c2s es'',\n      existsi E'', constructor,\n      { apply ceval.Seq, assumption, assumption, },\n      assumption, },\n  case csafe.Skip\n    { existsi E, constructor, apply ceval.Skip, assumption, },\n  case csafe.WhileDo\n    { \n      -- this part can't really be done in big step semantics\n      cases (s_ih es) with E',\n      destruct h, intros csafe es',\n      cases bsafety s_a es,\n      cases w,\n      { existsi E, constructor,\n        apply ceval.WhileDo_f,\n        assumption, sorry, },\n      { existsi E', constructor,\n        apply ceval.WhileDo_t,\n        assumption, assumption, \n        sorry, sorry, } \n      },\nend", "meta": {"author": "tadejpetric", "repo": "tpj-coq", "sha": "dda9fb2e635f9a1302739e34d8692a4252066b76", "save_path": "github-repos/lean/tadejpetric-tpj-coq", "path": "github-repos/lean/tadejpetric-tpj-coq/tpj-coq-dda9fb2e635f9a1302739e34d8692a4252066b76/06-formalizacija-dokazov/vaje-imp-resene.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7381220162657667}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport measure_theory.function.continuous_map_dense\nimport measure_theory.function.l2_space\nimport measure_theory.measure.haar\nimport analysis.complex.circle\nimport topology.metric_space.emetric_paracompact\nimport topology.continuous_function.stone_weierstrass\n\n/-!\n\n# Fourier analysis on the circle\n\nThis file contains basic technical results for a development of Fourier series.\n\n## Main definitions\n\n* `haar_circle`, Haar measure on the circle, normalized to have total measure `1`\n* instances `measure_space`, `is_probability_measure` for the circle with respect to this measure\n* for `n : \u2124`, `fourier n` is the monomial `\u03bb z, z ^ n`, bundled as a continuous map from `circle`\n  to `\u2102`\n* for `n : \u2124` and `p : \u211d\u22650\u221e`, `fourier_Lp p n` is an abbreviation for the monomial `fourier n`\n  considered as an element of the L\u1d56-space `Lp \u2102 p haar_circle`, via the embedding\n  `continuous_map.to_Lp`\n\n## Main statements\n\nThe theorem `span_fourier_closure_eq_top` states that the span of the monomials `fourier n` is\ndense in `C(circle, \u2102)`, i.e. that its `submodule.topological_closure` is `\u22a4`.  This follows from\nthe Stone-Weierstrass theorem after checking that it is a subalgebra, closed under conjugation, and\nseparates points.\n\nThe theorem `span_fourier_Lp_closure_eq_top` states that for `1 \u2264 p < \u221e` the span of the monomials\n`fourier_Lp` is dense in `Lp \u2102 p haar_circle`, i.e. that its `submodule.topological_closure` is\n`\u22a4`.  This follows from the previous theorem using general theory on approximation of L\u1d56 functions\nby continuous functions.\n\nThe theorem `orthonormal_fourier` states that the monomials `fourier_Lp 2 n` form an orthonormal\nset (in the L\u00b2 space of the circle).\n\nBy definition, a Hilbert basis for an inner product space is an orthonormal set whose span is\ndense.  Thus, the last two results together establish that the functions `fourier_Lp 2 n` form a\nHilbert basis for L\u00b2.\n\n## TODO\n\nOnce mathlib has general theory showing that a Hilbert basis of an inner product space induces a\nunitary equivalence with L\u00b2, the results in this file will give Fourier series applications such\nas Parseval's formula.\n\n-/\n\nnoncomputable theory\nopen_locale ennreal complex_conjugate\nopen topological_space continuous_map measure_theory measure_theory.measure algebra submodule set\n\nlocal attribute [instance] fact_one_le_two_ennreal\n\n/-! ### Choice of measure on the circle -/\n\nsection haar_circle\n/-! We make the circle into a measure space, using the Haar measure normalized to have total\nmeasure 1. -/\n\ninstance : measurable_space circle := borel circle\ninstance : borel_space circle := \u27e8rfl\u27e9\n\n/-- Haar measure on the circle, normalized to have total measure 1. -/\ndef haar_circle : measure circle := haar_measure positive_compacts_univ\n\ninstance : is_probability_measure haar_circle := \u27e8haar_measure_self\u27e9\n\ninstance : measure_space circle :=\n{ volume := haar_circle,\n  .. circle.measurable_space }\n\nend haar_circle\n\n/-! ### Monomials on the circle -/\n\nsection fourier\n\n/-- The family of monomials `\u03bb z, z ^ n`, parametrized by `n : \u2124` and considered as bundled\ncontinuous maps from `circle` to `\u2102`. -/\n@[simps] def fourier (n : \u2124) : C(circle, \u2102) :=\n{ to_fun := \u03bb z, z ^ n,\n  continuous_to_fun := continuous_subtype_coe.zpow n $ \u03bb z, or.inl (nonzero_of_mem_circle z) }\n\n@[simp] lemma fourier_zero {z : circle} : fourier 0 z = 1 := rfl\n\n@[simp] lemma fourier_neg {n : \u2124} {z : circle} : fourier (-n) z = conj (fourier n z) :=\nby simp [\u2190 coe_inv_circle_eq_conj z]\n\n@[simp] lemma fourier_add {m n : \u2124} {z : circle} :\n  fourier (m + n) z = (fourier m z) * (fourier n z) :=\nby simp [zpow_add\u2080 (nonzero_of_mem_circle z)]\n\n/-- The subalgebra of `C(circle, \u2102)` generated by `z ^ n` for `n \u2208 \u2124`; equivalently, polynomials in\n`z` and `conj z`. -/\ndef fourier_subalgebra : subalgebra \u2102 C(circle, \u2102) := algebra.adjoin \u2102 (range fourier)\n\n/-- The subalgebra of `C(circle, \u2102)` generated by `z ^ n` for `n \u2208 \u2124` is in fact the linear span of\nthese functions. -/\nlemma fourier_subalgebra_coe : fourier_subalgebra.to_submodule = span \u2102 (range fourier) :=\nbegin\n  apply adjoin_eq_span_of_subset,\n  refine subset.trans _ submodule.subset_span,\n  intros x hx,\n  apply submonoid.closure_induction hx (\u03bb _, id) \u27e80, rfl\u27e9,\n  rintros _ _ \u27e8m, rfl\u27e9 \u27e8n, rfl\u27e9,\n  refine \u27e8m + n, _\u27e9,\n  ext1 z,\n  exact fourier_add,\nend\n\n/-- The subalgebra of `C(circle, \u2102)` generated by `z ^ n` for `n \u2208 \u2124` separates points. -/\nlemma fourier_subalgebra_separates_points : fourier_subalgebra.separates_points :=\nbegin\n  intros x y hxy,\n  refine \u27e8_, \u27e8fourier 1, _, rfl\u27e9, _\u27e9,\n  { exact subset_adjoin \u27e81, rfl\u27e9 },\n  { simp [hxy] }\nend\n\n/-- The subalgebra of `C(circle, \u2102)` generated by `z ^ n` for `n \u2208 \u2124` is invariant under complex\nconjugation. -/\nlemma fourier_subalgebra_conj_invariant :\n  conj_invariant_subalgebra (fourier_subalgebra.restrict_scalars \u211d) :=\nbegin\n  rintros _ \u27e8f, hf, rfl\u27e9,\n  change _ \u2208 fourier_subalgebra,\n  change _ \u2208 fourier_subalgebra at hf,\n  apply adjoin_induction hf,\n  { rintros _ \u27e8n, rfl\u27e9,\n    suffices : fourier (-n) \u2208 fourier_subalgebra,\n    { convert this,\n      ext1,\n      simp },\n    exact subset_adjoin \u27e8-n, rfl\u27e9 },\n  { intros c,\n    exact fourier_subalgebra.algebra_map_mem (conj c) },\n  { intros f g hf hg,\n    convert fourier_subalgebra.add_mem hf hg,\n    exact alg_hom.map_add _ f g, },\n  { intros f g hf hg,\n    convert fourier_subalgebra.mul_mem hf hg,\n    exact alg_hom.map_mul _ f g, }\nend\n\n/-- The subalgebra of `C(circle, \u2102)` generated by `z ^ n` for `n \u2208 \u2124` is dense. -/\nlemma fourier_subalgebra_closure_eq_top : fourier_subalgebra.topological_closure = \u22a4 :=\ncontinuous_map.subalgebra_complex_topological_closure_eq_top_of_separates_points\n  fourier_subalgebra\n  fourier_subalgebra_separates_points\n  fourier_subalgebra_conj_invariant\n\n/-- The linear span of the monomials `z ^ n` is dense in `C(circle, \u2102)`. -/\nlemma span_fourier_closure_eq_top : (span \u2102 (range fourier)).topological_closure = \u22a4 :=\nbegin\n  rw \u2190 fourier_subalgebra_coe,\n  exact congr_arg subalgebra.to_submodule fourier_subalgebra_closure_eq_top,\nend\n\n/-- The family of monomials `\u03bb z, z ^ n`, parametrized by `n : \u2124` and considered as elements of\nthe `Lp` space of functions on `circle` taking values in `\u2102`. -/\nabbreviation fourier_Lp (p : \u211d\u22650\u221e) [fact (1 \u2264 p)] (n : \u2124) : Lp \u2102 p haar_circle :=\nto_Lp p haar_circle \u2102 (fourier n)\n\n/-- For each `1 \u2264 p < \u221e`, the linear span of the monomials `z ^ n` is dense in\n`Lp \u2102 p haar_circle`. -/\nlemma span_fourier_Lp_closure_eq_top {p : \u211d\u22650\u221e} [fact (1 \u2264 p)] (hp : p \u2260 \u221e) :\n  (span \u2102 (range (fourier_Lp p))).topological_closure = \u22a4 :=\nbegin\n  convert (continuous_map.to_Lp_dense_range \u2102 hp haar_circle \u2102).topological_closure_map_submodule\n    span_fourier_closure_eq_top,\n  rw [map_span, range_comp],\n  simp\nend\n\n/-- For `n \u2260 0`, a rotation by `n\u207b\u00b9 * real.pi` negates the monomial `z ^ n`. -/\nlemma fourier_add_half_inv_index {n : \u2124} (hn : n \u2260 0) (z : circle) :\n  fourier n ((exp_map_circle (n\u207b\u00b9 * real.pi) * z)) = - fourier n z :=\nbegin\n  have : \u2191n * ((\u2191n)\u207b\u00b9 * \u2191real.pi * complex.I) = \u2191real.pi * complex.I,\n  { have : (n:\u2102) \u2260 0 := by exact_mod_cast hn,\n    field_simp,\n    ring },\n  simp [mul_zpow\u2080, \u2190 complex.exp_int_mul, complex.exp_pi_mul_I, this]\nend\n\n/-- The monomials `z ^ n` are an orthonormal set with respect to Haar measure on the circle. -/\nlemma orthonormal_fourier : orthonormal \u2102 (fourier_Lp 2) :=\nbegin\n  rw orthonormal_iff_ite,\n  intros i j,\n  rw continuous_map.inner_to_Lp haar_circle (fourier i) (fourier j),\n  split_ifs,\n  { simp [h, is_probability_measure.measure_univ, \u2190 fourier_neg, \u2190 fourier_add, -fourier_to_fun] },\n  simp only [\u2190 fourier_add, \u2190 fourier_neg],\n  have hij : -i + j \u2260 0,\n  { rw add_comm,\n    exact sub_ne_zero.mpr (ne.symm h) },\n  exact integral_zero_of_mul_left_eq_neg (is_mul_left_invariant_haar_measure _)\n    (fourier_add_half_inv_index hij)\nend\n\nend fourier\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/fourier.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133565584851, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7381220147509365}}
{"text": "import Aesop\n\nvariable [LE \u03b1] [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n\n@[aesop safe constructors]\ninductive Sorted : List \u03b1 \u2192 Prop where\n  | nil : Sorted []\n  | single : Sorted [x]\n  | cons_cons : x \u2264 x' \u2192 Sorted (x' :: xs) \u2192 Sorted (x :: x' :: xs)\n\n@[simp] def insertInOrder (a : \u03b1) : List \u03b1 \u2192 List \u03b1\n  | [] => [a]\n  | x :: xs =>\n    if a \u2264 x then\n      a :: x :: xs\n    else\n      x :: insertInOrder a xs\n\n@[simp] def insertionSort : List \u03b1 \u2192 List \u03b1\n  | []      => []\n  | x :: xs => insertInOrder x (insertionSort xs)\n\nvariable (antisymm : \u2200 {x y : \u03b1}, \u00ac (x \u2264 y) \u2192 y \u2264 x)\n\ntheorem sorted_insertInOrder {xs : List \u03b1} (h : Sorted xs) : Sorted (insertInOrder x xs) := by\n  induction h <;> aesop\n\ntheorem sorted_insertionSort {xs : List \u03b1} : Sorted (insertionSort xs) := by\n  induction xs <;> aesop (add safe sorted_insertInOrder)\n\ninductive Perm : List \u03b1 \u2192 List \u03b1 \u2192 Prop where\n  | nil : Perm [] []\n  | cons : Perm xs xs' \u2192 Perm (x :: xs) (x :: xs')\n  | swap : Perm (x :: y :: xs) (y :: x :: xs)\n  | trans : Perm xs ys \u2192 Perm ys zs \u2192 Perm xs zs\n\nattribute [aesop safe] Perm.nil\nattribute [aesop unsafe] Perm.cons\nattribute [aesop unsafe] Perm.swap\nattribute [aesop unsafe] Perm.trans\n\ntheorem Perm.symm : Perm xs ys \u2192 Perm ys xs := by\n  intro h\n  induction h <;> aesop\n\n@[aesop safe]\ntheorem perm_insertInOrder {xs : List \u03b1} : Perm (x :: xs) (insertInOrder x xs) := by\n  induction xs <;> aesop\n\ntheorem perm_insertionSort {xs : List \u03b1} : Perm xs (insertionSort xs) := by\n  induction xs with\n  | nil => aesop\n  | cons x xs =>\n    cases xs with\n    | nil => aesop\n    | cons x' xs =>\n      apply Perm.trans (ys := x :: insertInOrder x' xs)\n      \u00b7 exact Perm.cons perm_insertInOrder\n      \u00b7 apply Perm.trans (ys := x :: insertionSort (x' :: xs))\n        \u00b7 aesop (add safe Perm.cons, unsafe [cases List, Perm.symm])\n        \u00b7 aesop\n\ndef IsSortingAlgorithm (f : List \u03b1 \u2192 List \u03b1) := \u2200 xs, Perm xs (f xs) \u2227 Sorted (f xs)\n\ntheorem isSortingAlgorithm_insertionSort : IsSortingAlgorithm (insertionSort (\u03b1 := \u03b1)) :=\n  fun _xs => \u27e8perm_insertionSort, sorted_insertionSort @antisymm\u27e9\n", "meta": {"author": "IPDSnelting", "repo": "tba-2022", "sha": "1aa29ce5494c1287a282b88e798f8430f7e49af9", "save_path": "github-repos/lean/IPDSnelting-tba-2022", "path": "github-repos/lean/IPDSnelting-tba-2022/tba-2022-1aa29ce5494c1287a282b88e798f8430f7e49af9/TBA/AesopSort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7380753220588372}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.mv_polynomial\n! leanprover-community/mathlib commit bdcb7310db0fbc0e55dc1897bea76448733b7810\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Matrix.Determinant\nimport Mathbin.Data.MvPolynomial.Basic\nimport Mathbin.Data.MvPolynomial.CommRing\n\n/-!\n# Matrices of multivariate polynomials\n\nIn this file, we prove results about matrices over an mv_polynomial ring.\nIn particular, we provide `matrix.mv_polynomial_X` which associates every entry of a matrix with a\nunique variable.\n\n## Tags\n\nmatrix determinant, multivariate polynomial\n-/\n\n\nvariable {m n R S : Type _}\n\nnamespace Matrix\n\nvariable (m n R)\n\n/-- The matrix with variable `X (i,j)` at location `(i,j)`. -/\n@[simp]\nnoncomputable def mvPolynomialX [CommSemiring R] : Matrix m n (MvPolynomial (m \u00d7 n) R)\n  | i, j => MvPolynomial.X (i, j)\n#align matrix.mv_polynomial_X Matrix.mvPolynomialX\n\nvariable {m n R S}\n\n/-- Any matrix `A` can be expressed as the evaluation of `matrix.mv_polynomial_X`.\n\nThis is of particular use when `mv_polynomial (m \u00d7 n) R` is an integral domain but `S` is\nnot, as if the `mv_polynomial.eval\u2082` can be pulled to the outside of a goal, it can be solved in\nunder cancellative assumptions. -/\ntheorem mvPolynomialX_map_eval\u2082 [CommSemiring R] [CommSemiring S] (f : R \u2192+* S) (A : Matrix m n S) :\n    (mvPolynomialX m n R).map (MvPolynomial.eval\u2082 f fun p : m \u00d7 n => A p.1 p.2) = A :=\n  ext fun i j => MvPolynomial.eval\u2082_X _ (fun p : m \u00d7 n => A p.1 p.2) (i, j)\n#align matrix.mv_polynomial_X_map_eval\u2082 Matrix.mvPolynomialX_map_eval\u2082\n\n/-- A variant of `matrix.mv_polynomial_X_map_eval\u2082` with a bundled `ring_hom` on the LHS. -/\ntheorem mvPolynomialX_mapMatrix_eval [Fintype m] [DecidableEq m] [CommSemiring R]\n    (A : Matrix m m R) :\n    (MvPolynomial.eval fun p : m \u00d7 m => A p.1 p.2).mapMatrix (mvPolynomialX m m R) = A :=\n  mvPolynomialX_map_eval\u2082 _ A\n#align matrix.mv_polynomial_X_map_matrix_eval Matrix.mvPolynomialX_mapMatrix_eval\n\nvariable (R)\n\n/-- A variant of `matrix.mv_polynomial_X_map_eval\u2082` with a bundled `alg_hom` on the LHS. -/\ntheorem mvPolynomialX_mapMatrix_aeval [Fintype m] [DecidableEq m] [CommSemiring R] [CommSemiring S]\n    [Algebra R S] (A : Matrix m m S) :\n    (MvPolynomial.aeval fun p : m \u00d7 m => A p.1 p.2).mapMatrix (mvPolynomialX m m R) = A :=\n  mvPolynomialX_map_eval\u2082 _ A\n#align matrix.mv_polynomial_X_map_matrix_aeval Matrix.mvPolynomialX_mapMatrix_aeval\n\nvariable (m R)\n\n/-- In a nontrivial ring, `matrix.mv_polynomial_X m m R` has non-zero determinant. -/\ntheorem det_mvPolynomialX_ne_zero [DecidableEq m] [Fintype m] [CommRing R] [Nontrivial R] :\n    det (mvPolynomialX m m R) \u2260 0 := by\n  intro h_det\n  have := congr_arg Matrix.det (mv_polynomial_X_map_matrix_eval (1 : Matrix m m R))\n  rw [det_one, \u2190 RingHom.map_det, h_det, RingHom.map_zero] at this\n  exact zero_ne_one this\n#align matrix.det_mv_polynomial_X_ne_zero Matrix.det_mvPolynomialX_ne_zero\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/MvPolynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7380753038690046}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module data.bool.count\n! leanprover-community/mathlib commit a11f9106a169dd302a285019e5165f8ab32ff433\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Parity\nimport Mathbin.Data.List.Chain\n\n/-!\n# List of booleans\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove lemmas about the number of `ff`s and `tt`s in a list of booleans. First we\nprove that the number of `ff`s plus the number of `tt` equals the length of the list. Then we prove\nthat in a list with alternating `tt`s and `ff`s, the number of `tt`s differs from the number of\n`ff`s by at most one. We provide several versions of these statements.\n-/\n\n\nnamespace List\n\n#print List.count_not_add_count /-\n@[simp]\ntheorem count_not_add_count (l : List Bool) (b : Bool) : count (!b) l + count b l = length l := by\n  simp only [length_eq_countp_add_countp (Eq (!b)), Bool.not_not_eq, count]\n#align list.count_bnot_add_count List.count_not_add_count\n-/\n\n#print List.count_add_count_not /-\n@[simp]\ntheorem count_add_count_not (l : List Bool) (b : Bool) : count b l + count (!b) l = length l := by\n  rw [add_comm, count_bnot_add_count]\n#align list.count_add_count_bnot List.count_add_count_not\n-/\n\n#print List.count_false_add_count_true /-\n@[simp]\ntheorem count_false_add_count_true (l : List Bool) : count false l + count true l = length l :=\n  count_not_add_count l true\n#align list.count_ff_add_count_tt List.count_false_add_count_true\n-/\n\n#print List.count_true_add_count_false /-\n@[simp]\ntheorem count_true_add_count_false (l : List Bool) : count true l + count false l = length l :=\n  count_not_add_count l false\n#align list.count_tt_add_count_ff List.count_true_add_count_false\n-/\n\n#print List.Chain.count_not /-\ntheorem Chain.count_not :\n    \u2200 {b : Bool} {l : List Bool}, Chain (\u00b7 \u2260 \u00b7) b l \u2192 count (!b) l = count b l + length l % 2\n  | b, [], h => rfl\n  | b, x :: l, h =>\n    by\n    obtain rfl : b = !x := Bool.eq_not_iff.2 (rel_of_chain_cons h)\n    rw [Bool.not_not, count_cons_self, count_cons_of_ne x.bnot_ne_self,\n      chain.count_bnot (chain_of_chain_cons h), length, add_assoc, Nat.mod_two_add_succ_mod_two]\n#align list.chain.count_bnot List.Chain.count_not\n-/\n\nnamespace Chain'\n\nvariable {l : List Bool}\n\n#print List.Chain'.count_not_eq_count /-\ntheorem count_not_eq_count (hl : Chain' (\u00b7 \u2260 \u00b7) l) (h2 : Even (length l)) (b : Bool) :\n    count (!b) l = count b l := by\n  cases' l with x l\n  \u00b7 rfl\n  rw [length_cons, Nat.even_add_one, Nat.not_even_iff] at h2\n  suffices count (!x) (x :: l) = count x (x :: l) by\n    cases b <;> cases x <;> try exact this <;> exact this.symm\n  rw [count_cons_of_ne x.bnot_ne_self, hl.count_bnot, h2, count_cons_self]\n#align list.chain'.count_bnot_eq_count List.Chain'.count_not_eq_count\n-/\n\n#print List.Chain'.count_false_eq_count_true /-\ntheorem count_false_eq_count_true (hl : Chain' (\u00b7 \u2260 \u00b7) l) (h2 : Even (length l)) :\n    count false l = count true l :=\n  hl.count_not_eq_count h2 true\n#align list.chain'.count_ff_eq_count_tt List.Chain'.count_false_eq_count_true\n-/\n\n#print List.Chain'.count_not_le_count_add_one /-\ntheorem count_not_le_count_add_one (hl : Chain' (\u00b7 \u2260 \u00b7) l) (b : Bool) :\n    count (!b) l \u2264 count b l + 1 := by\n  cases' l with x l\n  \u00b7 exact zero_le _\n  obtain rfl | rfl : b = x \u2228 b = !x := by simp only [Bool.eq_not_iff, em]\n  \u00b7 rw [count_cons_of_ne b.bnot_ne_self, count_cons_self, hl.count_bnot, add_assoc]\n    exact add_le_add_left (Nat.mod_lt _ two_pos).le _\n  \u00b7 rw [Bool.not_not, count_cons_self, count_cons_of_ne x.bnot_ne_self, hl.count_bnot]\n    exact add_le_add_right (le_add_right le_rfl) _\n#align list.chain'.count_bnot_le_count_add_one List.Chain'.count_not_le_count_add_one\n-/\n\n#print List.Chain'.count_false_le_count_true_add_one /-\ntheorem count_false_le_count_true_add_one (hl : Chain' (\u00b7 \u2260 \u00b7) l) :\n    count false l \u2264 count true l + 1 :=\n  hl.count_not_le_count_add_one true\n#align list.chain'.count_ff_le_count_tt_add_one List.Chain'.count_false_le_count_true_add_one\n-/\n\n#print List.Chain'.count_true_le_count_false_add_one /-\ntheorem count_true_le_count_false_add_one (hl : Chain' (\u00b7 \u2260 \u00b7) l) :\n    count true l \u2264 count false l + 1 :=\n  hl.count_not_le_count_add_one false\n#align list.chain'.count_tt_le_count_ff_add_one List.Chain'.count_true_le_count_false_add_one\n-/\n\n#print List.Chain'.two_mul_count_bool_of_even /-\ntheorem two_mul_count_bool_of_even (hl : Chain' (\u00b7 \u2260 \u00b7) l) (h2 : Even (length l)) (b : Bool) :\n    2 * count b l = length l := by\n  rw [\u2190 count_bnot_add_count l b, hl.count_bnot_eq_count h2, two_mul]\n#align list.chain'.two_mul_count_bool_of_even List.Chain'.two_mul_count_bool_of_even\n-/\n\n#print List.Chain'.two_mul_count_bool_eq_ite /-\ntheorem two_mul_count_bool_eq_ite (hl : Chain' (\u00b7 \u2260 \u00b7) l) (b : Bool) :\n    2 * count b l =\n      if Even (length l) then length l else if b \u2208 l.head? then length l + 1 else length l - 1 :=\n  by\n  by_cases h2 : Even (length l)\n  \u00b7 rw [if_pos h2, hl.two_mul_count_bool_of_even h2]\n  \u00b7 cases' l with x l\n    \u00b7 exact (h2 even_zero).elim\n    simp only [if_neg h2, count_cons', mul_add, head', Option.mem_some_iff, @eq_comm _ x]\n    rw [length_cons, Nat.even_add_one, Classical.not_not] at h2\n    replace hl : l.chain' (\u00b7 \u2260 \u00b7) := hl.tail\n    rw [hl.two_mul_count_bool_of_even h2]\n    split_ifs <;> simp\n#align list.chain'.two_mul_count_bool_eq_ite List.Chain'.two_mul_count_bool_eq_ite\n-/\n\n#print List.Chain'.length_sub_one_le_two_mul_count_bool /-\ntheorem length_sub_one_le_two_mul_count_bool (hl : Chain' (\u00b7 \u2260 \u00b7) l) (b : Bool) :\n    length l - 1 \u2264 2 * count b l :=\n  by\n  rw [hl.two_mul_count_bool_eq_ite]\n  split_ifs <;> simp [le_tsub_add, Nat.le_succ_of_le]\n#align list.chain'.length_sub_one_le_two_mul_count_bool List.Chain'.length_sub_one_le_two_mul_count_bool\n-/\n\n#print List.Chain'.length_div_two_le_count_bool /-\ntheorem length_div_two_le_count_bool (hl : Chain' (\u00b7 \u2260 \u00b7) l) (b : Bool) :\n    length l / 2 \u2264 count b l :=\n  by\n  rw [Nat.div_le_iff_le_mul_add_pred two_pos, \u2190 tsub_le_iff_right]\n  exact length_sub_one_le_two_mul_count_bool hl b\n#align list.chain'.length_div_two_le_count_bool List.Chain'.length_div_two_le_count_bool\n-/\n\n#print List.Chain'.two_mul_count_bool_le_length_add_one /-\ntheorem two_mul_count_bool_le_length_add_one (hl : Chain' (\u00b7 \u2260 \u00b7) l) (b : Bool) :\n    2 * count b l \u2264 length l + 1 :=\n  by\n  rw [hl.two_mul_count_bool_eq_ite]\n  split_ifs <;> simp [Nat.le_succ_of_le]\n#align list.chain'.two_mul_count_bool_le_length_add_one List.Chain'.two_mul_count_bool_le_length_add_one\n-/\n\nend Chain'\n\nend List\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Bool/Count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703476, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7380753035742692}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n\n! This file was ported from Lean 3 source module analysis.special_functions.trigonometric.inverse\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.SpecialFunctions.Trigonometric.Basic\nimport Mathbin.Topology.Algebra.Order.ProjIcc\n\n/-!\n# Inverse trigonometric functions.\n\nSee also `analysis.special_functions.trigonometric.arctan` for the inverse tan function.\n(This is delayed as it is easier to set up after developing complex trigonometric functions.)\n\nBasic inequalities on trigonometric functions.\n-/\n\n\nnoncomputable section\n\nopen Classical Topology Filter\n\nopen Set Filter\n\nopen Real\n\nnamespace Real\n\n/-- Inverse of the `sin` function, returns values in the range `-\u03c0 / 2 \u2264 arcsin x \u2264 \u03c0 / 2`.\nIt defaults to `-\u03c0 / 2` on `(-\u221e, -1)` and to `\u03c0 / 2` to `(1, \u221e)`. -/\n@[pp_nodot]\nnoncomputable def arcsin : \u211d \u2192 \u211d :=\n  coe \u2218 IccExtend (neg_le_self zero_le_one) sinOrderIso.symm\n#align real.arcsin Real.arcsin\n\ntheorem arcsin_mem_Icc (x : \u211d) : arcsin x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2) :=\n  Subtype.coe_prop _\n#align real.arcsin_mem_Icc Real.arcsin_mem_Icc\n\n@[simp]\ntheorem range_arcsin : range arcsin = Icc (-(\u03c0 / 2)) (\u03c0 / 2) :=\n  by\n  rw [arcsin, range_comp coe]\n  simp [Icc]\n#align real.range_arcsin Real.range_arcsin\n\ntheorem arcsin_le_pi_div_two (x : \u211d) : arcsin x \u2264 \u03c0 / 2 :=\n  (arcsin_mem_Icc x).2\n#align real.arcsin_le_pi_div_two Real.arcsin_le_pi_div_two\n\ntheorem neg_pi_div_two_le_arcsin (x : \u211d) : -(\u03c0 / 2) \u2264 arcsin x :=\n  (arcsin_mem_Icc x).1\n#align real.neg_pi_div_two_le_arcsin Real.neg_pi_div_two_le_arcsin\n\ntheorem arcsin_projIcc (x : \u211d) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x :=\n  by rw [arcsin, Function.comp_apply, Icc_extend_coe, Function.comp_apply, Icc_extend]\n#align real.arcsin_proj_Icc Real.arcsin_projIcc\n\ntheorem sin_arcsin' {x : \u211d} (hx : x \u2208 Icc (-1 : \u211d) 1) : sin (arcsin x) = x := by\n  simpa [arcsin, Icc_extend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using\n    Subtype.ext_iff.1 (sin_order_iso.apply_symm_apply \u27e8x, hx\u27e9)\n#align real.sin_arcsin' Real.sin_arcsin'\n\ntheorem sin_arcsin {x : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) : sin (arcsin x) = x :=\n  sin_arcsin' \u27e8hx\u2081, hx\u2082\u27e9\n#align real.sin_arcsin Real.sin_arcsin\n\ntheorem arcsin_sin' {x : \u211d} (hx : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) : arcsin (sin x) = x :=\n  injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]\n#align real.arcsin_sin' Real.arcsin_sin'\n\ntheorem arcsin_sin {x : \u211d} (hx\u2081 : -(\u03c0 / 2) \u2264 x) (hx\u2082 : x \u2264 \u03c0 / 2) : arcsin (sin x) = x :=\n  arcsin_sin' \u27e8hx\u2081, hx\u2082\u27e9\n#align real.arcsin_sin Real.arcsin_sin\n\ntheorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) :=\n  (Subtype.strictMono_coe _).comp_strictMonoOn <|\n    sinOrderIso.symm.StrictMono.strictMonoOn_IccExtend _\n#align real.strict_mono_on_arcsin Real.strictMonoOn_arcsin\n\ntheorem monotone_arcsin : Monotone arcsin :=\n  (Subtype.mono_coe _).comp <| sinOrderIso.symm.Monotone.IccExtend _\n#align real.monotone_arcsin Real.monotone_arcsin\n\ntheorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) :=\n  strictMonoOn_arcsin.InjOn\n#align real.inj_on_arcsin Real.injOn_arcsin\n\ntheorem arcsin_inj {x y : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) (hy\u2081 : -1 \u2264 y) (hy\u2082 : y \u2264 1) :\n    arcsin x = arcsin y \u2194 x = y :=\n  injOn_arcsin.eq_iff \u27e8hx\u2081, hx\u2082\u27e9 \u27e8hy\u2081, hy\u2082\u27e9\n#align real.arcsin_inj Real.arcsin_inj\n\n@[continuity]\ntheorem continuous_arcsin : Continuous arcsin :=\n  continuous_subtype_val.comp sinOrderIso.symm.Continuous.Icc_extend'\n#align real.continuous_arcsin Real.continuous_arcsin\n\ntheorem continuousAt_arcsin {x : \u211d} : ContinuousAt arcsin x :=\n  continuous_arcsin.ContinuousAt\n#align real.continuous_at_arcsin Real.continuousAt_arcsin\n\ntheorem arcsin_eq_of_sin_eq {x y : \u211d} (h\u2081 : sin x = y) (h\u2082 : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    arcsin y = x := by\n  subst y\n  exact inj_on_sin (arcsin_mem_Icc _) h\u2082 (sin_arcsin' (sin_mem_Icc x))\n#align real.arcsin_eq_of_sin_eq Real.arcsin_eq_of_sin_eq\n\n@[simp]\ntheorem arcsin_zero : arcsin 0 = 0 :=\n  arcsin_eq_of_sin_eq sin_zero \u27e8neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le\u27e9\n#align real.arcsin_zero Real.arcsin_zero\n\n@[simp]\ntheorem arcsin_one : arcsin 1 = \u03c0 / 2 :=\n  arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)\n#align real.arcsin_one Real.arcsin_one\n\ntheorem arcsin_of_one_le {x : \u211d} (hx : 1 \u2264 x) : arcsin x = \u03c0 / 2 := by\n  rw [\u2190 arcsin_proj_Icc, proj_Icc_of_right_le _ hx, Subtype.coe_mk, arcsin_one]\n#align real.arcsin_of_one_le Real.arcsin_of_one_le\n\ntheorem arcsin_neg_one : arcsin (-1) = -(\u03c0 / 2) :=\n  arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <|\n    left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)\n#align real.arcsin_neg_one Real.arcsin_neg_one\n\ntheorem arcsin_of_le_neg_one {x : \u211d} (hx : x \u2264 -1) : arcsin x = -(\u03c0 / 2) := by\n  rw [\u2190 arcsin_proj_Icc, proj_Icc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one]\n#align real.arcsin_of_le_neg_one Real.arcsin_of_le_neg_one\n\n@[simp]\ntheorem arcsin_neg (x : \u211d) : arcsin (-x) = -arcsin x :=\n  by\n  cases' le_total x (-1) with hx\u2081 hx\u2081\n  \u00b7 rw [arcsin_of_le_neg_one hx\u2081, neg_neg, arcsin_of_one_le (le_neg.2 hx\u2081)]\n  cases' le_total 1 x with hx\u2082 hx\u2082\n  \u00b7 rw [arcsin_of_one_le hx\u2082, arcsin_of_le_neg_one (neg_le_neg hx\u2082)]\n  refine' arcsin_eq_of_sin_eq _ _\n  \u00b7 rw [sin_neg, sin_arcsin hx\u2081 hx\u2082]\n  \u00b7 exact \u27e8neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)\u27e9\n#align real.arcsin_neg Real.arcsin_neg\n\ntheorem arcsin_le_iff_le_sin {x y : \u211d} (hx : x \u2208 Icc (-1 : \u211d) 1) (hy : y \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    arcsin x \u2264 y \u2194 x \u2264 sin y := by\n  rw [\u2190 arcsin_sin' hy, strict_mono_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]\n#align real.arcsin_le_iff_le_sin Real.arcsin_le_iff_le_sin\n\ntheorem arcsin_le_iff_le_sin' {x y : \u211d} (hy : y \u2208 Ico (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    arcsin x \u2264 y \u2194 x \u2264 sin y := by\n  cases' le_total x (-1) with hx\u2081 hx\u2081\n  \u00b7 simp [arcsin_of_le_neg_one hx\u2081, hy.1, hx\u2081.trans (neg_one_le_sin _)]\n  cases' lt_or_le 1 x with hx\u2082 hx\u2082\n  \u00b7 simp [arcsin_of_one_le hx\u2082.le, hy.2.not_le, (sin_le_one y).trans_lt hx\u2082]\n  exact arcsin_le_iff_le_sin \u27e8hx\u2081, hx\u2082\u27e9 (mem_Icc_of_Ico hy)\n#align real.arcsin_le_iff_le_sin' Real.arcsin_le_iff_le_sin'\n\ntheorem le_arcsin_iff_sin_le {x y : \u211d} (hx : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) (hy : y \u2208 Icc (-1 : \u211d) 1) :\n    x \u2264 arcsin y \u2194 sin x \u2264 y := by\n  rw [\u2190 neg_le_neg_iff, \u2190 arcsin_neg,\n    arcsin_le_iff_le_sin \u27e8neg_le_neg hy.2, neg_le.2 hy.1\u27e9 \u27e8neg_le_neg hx.2, neg_le.2 hx.1\u27e9, sin_neg,\n    neg_le_neg_iff]\n#align real.le_arcsin_iff_sin_le Real.le_arcsin_iff_sin_le\n\ntheorem le_arcsin_iff_sin_le' {x y : \u211d} (hx : x \u2208 Ioc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    x \u2264 arcsin y \u2194 sin x \u2264 y := by\n  rw [\u2190 neg_le_neg_iff, \u2190 arcsin_neg, arcsin_le_iff_le_sin' \u27e8neg_le_neg hx.2, neg_lt.2 hx.1\u27e9,\n    sin_neg, neg_le_neg_iff]\n#align real.le_arcsin_iff_sin_le' Real.le_arcsin_iff_sin_le'\n\ntheorem arcsin_lt_iff_lt_sin {x y : \u211d} (hx : x \u2208 Icc (-1 : \u211d) 1) (hy : y \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    arcsin x < y \u2194 x < sin y :=\n  not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le\n#align real.arcsin_lt_iff_lt_sin Real.arcsin_lt_iff_lt_sin\n\ntheorem arcsin_lt_iff_lt_sin' {x y : \u211d} (hy : y \u2208 Ioc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    arcsin x < y \u2194 x < sin y :=\n  not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le\n#align real.arcsin_lt_iff_lt_sin' Real.arcsin_lt_iff_lt_sin'\n\ntheorem lt_arcsin_iff_sin_lt {x y : \u211d} (hx : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) (hy : y \u2208 Icc (-1 : \u211d) 1) :\n    x < arcsin y \u2194 sin x < y :=\n  not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le\n#align real.lt_arcsin_iff_sin_lt Real.lt_arcsin_iff_sin_lt\n\ntheorem lt_arcsin_iff_sin_lt' {x y : \u211d} (hx : x \u2208 Ico (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    x < arcsin y \u2194 sin x < y :=\n  not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le\n#align real.lt_arcsin_iff_sin_lt' Real.lt_arcsin_iff_sin_lt'\n\ntheorem arcsin_eq_iff_eq_sin {x y : \u211d} (hy : y \u2208 Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) :\n    arcsin x = y \u2194 x = sin y := by\n  simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),\n    le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]\n#align real.arcsin_eq_iff_eq_sin Real.arcsin_eq_iff_eq_sin\n\n@[simp]\ntheorem arcsin_nonneg {x : \u211d} : 0 \u2264 arcsin x \u2194 0 \u2264 x :=\n  (le_arcsin_iff_sin_le' \u27e8neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le\u27e9).trans <| by\n    rw [sin_zero]\n#align real.arcsin_nonneg Real.arcsin_nonneg\n\n@[simp]\ntheorem arcsin_nonpos {x : \u211d} : arcsin x \u2264 0 \u2194 x \u2264 0 :=\n  neg_nonneg.symm.trans <| arcsin_neg x \u25b8 arcsin_nonneg.trans neg_nonneg\n#align real.arcsin_nonpos Real.arcsin_nonpos\n\n@[simp]\ntheorem arcsin_eq_zero_iff {x : \u211d} : arcsin x = 0 \u2194 x = 0 := by simp [le_antisymm_iff]\n#align real.arcsin_eq_zero_iff Real.arcsin_eq_zero_iff\n\n@[simp]\ntheorem zero_eq_arcsin_iff {x} : 0 = arcsin x \u2194 x = 0 :=\n  eq_comm.trans arcsin_eq_zero_iff\n#align real.zero_eq_arcsin_iff Real.zero_eq_arcsin_iff\n\n@[simp]\ntheorem arcsin_pos {x : \u211d} : 0 < arcsin x \u2194 0 < x :=\n  lt_iff_lt_of_le_iff_le arcsin_nonpos\n#align real.arcsin_pos Real.arcsin_pos\n\n@[simp]\ntheorem arcsin_lt_zero {x : \u211d} : arcsin x < 0 \u2194 x < 0 :=\n  lt_iff_lt_of_le_iff_le arcsin_nonneg\n#align real.arcsin_lt_zero Real.arcsin_lt_zero\n\n@[simp]\ntheorem arcsin_lt_pi_div_two {x : \u211d} : arcsin x < \u03c0 / 2 \u2194 x < 1 :=\n  (arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by\n    rw [sin_pi_div_two]\n#align real.arcsin_lt_pi_div_two Real.arcsin_lt_pi_div_two\n\n@[simp]\ntheorem neg_pi_div_two_lt_arcsin {x : \u211d} : -(\u03c0 / 2) < arcsin x \u2194 -1 < x :=\n  (lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by\n    rw [sin_neg, sin_pi_div_two]\n#align real.neg_pi_div_two_lt_arcsin Real.neg_pi_div_two_lt_arcsin\n\n@[simp]\ntheorem arcsin_eq_pi_div_two {x : \u211d} : arcsin x = \u03c0 / 2 \u2194 1 \u2264 x :=\n  \u27e8fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').Ne h, arcsin_of_one_le\u27e9\n#align real.arcsin_eq_pi_div_two Real.arcsin_eq_pi_div_two\n\n@[simp]\ntheorem pi_div_two_eq_arcsin {x} : \u03c0 / 2 = arcsin x \u2194 1 \u2264 x :=\n  eq_comm.trans arcsin_eq_pi_div_two\n#align real.pi_div_two_eq_arcsin Real.pi_div_two_eq_arcsin\n\n@[simp]\ntheorem pi_div_two_le_arcsin {x} : \u03c0 / 2 \u2264 arcsin x \u2194 1 \u2264 x :=\n  (arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin\n#align real.pi_div_two_le_arcsin Real.pi_div_two_le_arcsin\n\n@[simp]\ntheorem arcsin_eq_neg_pi_div_two {x : \u211d} : arcsin x = -(\u03c0 / 2) \u2194 x \u2264 -1 :=\n  \u27e8fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one\u27e9\n#align real.arcsin_eq_neg_pi_div_two Real.arcsin_eq_neg_pi_div_two\n\n@[simp]\ntheorem neg_pi_div_two_eq_arcsin {x} : -(\u03c0 / 2) = arcsin x \u2194 x \u2264 -1 :=\n  eq_comm.trans arcsin_eq_neg_pi_div_two\n#align real.neg_pi_div_two_eq_arcsin Real.neg_pi_div_two_eq_arcsin\n\n@[simp]\ntheorem arcsin_le_neg_pi_div_two {x} : arcsin x \u2264 -(\u03c0 / 2) \u2194 x \u2264 -1 :=\n  (neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two\n#align real.arcsin_le_neg_pi_div_two Real.arcsin_le_neg_pi_div_two\n\n@[simp]\ntheorem pi_div_four_le_arcsin {x} : \u03c0 / 4 \u2264 arcsin x \u2194 sqrt 2 / 2 \u2264 x :=\n  by\n  rw [\u2190 sin_pi_div_four, le_arcsin_iff_sin_le']\n  have := pi_pos\n  constructor <;> linarith\n#align real.pi_div_four_le_arcsin Real.pi_div_four_le_arcsin\n\ntheorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) (Ioo (-1) 1) := fun x h => by\n  rwa [mem_Ioo, \u2190 arcsin_lt_pi_div_two, \u2190 neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le]\n#align real.maps_to_sin_Ioo Real.mapsTo_sin_Ioo\n\n/-- `real.sin` as a `local_homeomorph` between `(-\u03c0 / 2, \u03c0 / 2)` and `(-1, 1)`. -/\n@[simp]\ndef sinLocalHomeomorph : LocalHomeomorph \u211d \u211d\n    where\n  toFun := sin\n  invFun := arcsin\n  source := Ioo (-(\u03c0 / 2)) (\u03c0 / 2)\n  target := Ioo (-1) 1\n  map_source' := mapsTo_sin_Ioo\n  map_target' y hy := \u27e8neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2\u27e9\n  left_inv' x hx := arcsin_sin hx.1.le hx.2.le\n  right_inv' y hy := sin_arcsin hy.1.le hy.2.le\n  open_source := isOpen_Ioo\n  open_target := isOpen_Ioo\n  continuous_toFun := continuous_sin.ContinuousOn\n  continuous_invFun := continuous_arcsin.ContinuousOn\n#align real.sin_local_homeomorph Real.sinLocalHomeomorph\n\ntheorem cos_arcsin_nonneg (x : \u211d) : 0 \u2264 cos (arcsin x) :=\n  cos_nonneg_of_mem_Icc \u27e8neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _\u27e9\n#align real.cos_arcsin_nonneg Real.cos_arcsin_nonneg\n\n-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.\ntheorem cos_arcsin (x : \u211d) : cos (arcsin x) = sqrt (1 - x ^ 2) :=\n  by\n  by_cases hx\u2081 : -1 \u2264 x; swap\n  \u00b7 rw [not_le] at hx\u2081\n    rw [arcsin_of_le_neg_one hx\u2081.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos]\n    nlinarith\n  by_cases hx\u2082 : x \u2264 1; swap\n  \u00b7 rw [not_le] at hx\u2082\n    rw [arcsin_of_one_le hx\u2082.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos]\n    nlinarith\n  have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x)\n  rw [\u2190 eq_sub_iff_add_eq', \u2190 sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq,\n    sqrt_mul_self (cos_arcsin_nonneg _)] at this\n  rw [this, sin_arcsin hx\u2081 hx\u2082]\n#align real.cos_arcsin Real.cos_arcsin\n\n-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.\ntheorem tan_arcsin (x : \u211d) : tan (arcsin x) = x / sqrt (1 - x ^ 2) :=\n  by\n  rw [tan_eq_sin_div_cos, cos_arcsin]\n  by_cases hx\u2081 : -1 \u2264 x; swap\n  \u00b7 have h : sqrt (1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)\n    rw [h]\n    simp\n  by_cases hx\u2082 : x \u2264 1; swap\n  \u00b7 have h : sqrt (1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)\n    rw [h]\n    simp\n  rw [sin_arcsin hx\u2081 hx\u2082]\n#align real.tan_arcsin Real.tan_arcsin\n\n/-- Inverse of the `cos` function, returns values in the range `0 \u2264 arccos x` and `arccos x \u2264 \u03c0`.\n  It defaults to `\u03c0` on `(-\u221e, -1)` and to `0` to `(1, \u221e)`. -/\n@[pp_nodot]\nnoncomputable def arccos (x : \u211d) : \u211d :=\n  \u03c0 / 2 - arcsin x\n#align real.arccos Real.arccos\n\ntheorem arccos_eq_pi_div_two_sub_arcsin (x : \u211d) : arccos x = \u03c0 / 2 - arcsin x :=\n  rfl\n#align real.arccos_eq_pi_div_two_sub_arcsin Real.arccos_eq_pi_div_two_sub_arcsin\n\ntheorem arcsin_eq_pi_div_two_sub_arccos (x : \u211d) : arcsin x = \u03c0 / 2 - arccos x := by simp [arccos]\n#align real.arcsin_eq_pi_div_two_sub_arccos Real.arcsin_eq_pi_div_two_sub_arccos\n\ntheorem arccos_le_pi (x : \u211d) : arccos x \u2264 \u03c0 := by\n  unfold arccos <;> linarith [neg_pi_div_two_le_arcsin x]\n#align real.arccos_le_pi Real.arccos_le_pi\n\ntheorem arccos_nonneg (x : \u211d) : 0 \u2264 arccos x := by\n  unfold arccos <;> linarith [arcsin_le_pi_div_two x]\n#align real.arccos_nonneg Real.arccos_nonneg\n\n@[simp]\ntheorem arccos_pos {x : \u211d} : 0 < arccos x \u2194 x < 1 := by simp [arccos]\n#align real.arccos_pos Real.arccos_pos\n\ntheorem cos_arccos {x : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) : cos (arccos x) = x := by\n  rw [arccos, cos_pi_div_two_sub, sin_arcsin hx\u2081 hx\u2082]\n#align real.cos_arccos Real.cos_arccos\n\ntheorem arccos_cos {x : \u211d} (hx\u2081 : 0 \u2264 x) (hx\u2082 : x \u2264 \u03c0) : arccos (cos x) = x := by\n  rw [arccos, \u2190 sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith\n#align real.arccos_cos Real.arccos_cos\n\ntheorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun x hx y hy h =>\n  sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _\n#align real.strict_anti_on_arccos Real.strictAntiOn_arccos\n\ntheorem arccos_injOn : InjOn arccos (Icc (-1) 1) :=\n  strictAntiOn_arccos.InjOn\n#align real.arccos_inj_on Real.arccos_injOn\n\ntheorem arccos_inj {x y : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) (hy\u2081 : -1 \u2264 y) (hy\u2082 : y \u2264 1) :\n    arccos x = arccos y \u2194 x = y :=\n  arccos_injOn.eq_iff \u27e8hx\u2081, hx\u2082\u27e9 \u27e8hy\u2081, hy\u2082\u27e9\n#align real.arccos_inj Real.arccos_inj\n\n@[simp]\ntheorem arccos_zero : arccos 0 = \u03c0 / 2 := by simp [arccos]\n#align real.arccos_zero Real.arccos_zero\n\n@[simp]\ntheorem arccos_one : arccos 1 = 0 := by simp [arccos]\n#align real.arccos_one Real.arccos_one\n\n@[simp]\ntheorem arccos_neg_one : arccos (-1) = \u03c0 := by simp [arccos, add_halves]\n#align real.arccos_neg_one Real.arccos_neg_one\n\n@[simp]\ntheorem arccos_eq_zero {x} : arccos x = 0 \u2194 1 \u2264 x := by simp [arccos, sub_eq_zero]\n#align real.arccos_eq_zero Real.arccos_eq_zero\n\n@[simp]\ntheorem arccos_eq_pi_div_two {x} : arccos x = \u03c0 / 2 \u2194 x = 0 := by simp [arccos]\n#align real.arccos_eq_pi_div_two Real.arccos_eq_pi_div_two\n\n@[simp]\ntheorem arccos_eq_pi {x} : arccos x = \u03c0 \u2194 x \u2264 -1 := by\n  rw [arccos, sub_eq_iff_eq_add, \u2190 sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]\n#align real.arccos_eq_pi Real.arccos_eq_pi\n\ntheorem arccos_neg (x : \u211d) : arccos (-x) = \u03c0 - arccos x := by\n  rw [\u2190 add_halves \u03c0, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]\n#align real.arccos_neg Real.arccos_neg\n\ntheorem arccos_of_one_le {x : \u211d} (hx : 1 \u2264 x) : arccos x = 0 := by\n  rw [arccos, arcsin_of_one_le hx, sub_self]\n#align real.arccos_of_one_le Real.arccos_of_one_le\n\ntheorem arccos_of_le_neg_one {x : \u211d} (hx : x \u2264 -1) : arccos x = \u03c0 := by\n  rw [arccos, arcsin_of_le_neg_one hx, sub_neg_eq_add, add_halves']\n#align real.arccos_of_le_neg_one Real.arccos_of_le_neg_one\n\n-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.\ntheorem sin_arccos (x : \u211d) : sin (arccos x) = sqrt (1 - x ^ 2) :=\n  by\n  by_cases hx\u2081 : -1 \u2264 x; swap\n  \u00b7 rw [not_le] at hx\u2081\n    rw [arccos_of_le_neg_one hx\u2081.le, sin_pi, sqrt_eq_zero_of_nonpos]\n    nlinarith\n  by_cases hx\u2082 : x \u2264 1; swap\n  \u00b7 rw [not_le] at hx\u2082\n    rw [arccos_of_one_le hx\u2082.le, sin_zero, sqrt_eq_zero_of_nonpos]\n    nlinarith\n  rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin]\n#align real.sin_arccos Real.sin_arccos\n\n@[simp]\ntheorem arccos_le_pi_div_two {x} : arccos x \u2264 \u03c0 / 2 \u2194 0 \u2264 x := by simp [arccos]\n#align real.arccos_le_pi_div_two Real.arccos_le_pi_div_two\n\n@[simp]\ntheorem arccos_lt_pi_div_two {x : \u211d} : arccos x < \u03c0 / 2 \u2194 0 < x := by simp [arccos]\n#align real.arccos_lt_pi_div_two Real.arccos_lt_pi_div_two\n\n@[simp]\ntheorem arccos_le_pi_div_four {x} : arccos x \u2264 \u03c0 / 4 \u2194 sqrt 2 / 2 \u2264 x :=\n  by\n  rw [arccos, \u2190 pi_div_four_le_arcsin]\n  constructor <;>\n    \u00b7 intro\n      linarith\n#align real.arccos_le_pi_div_four Real.arccos_le_pi_div_four\n\n@[continuity]\ntheorem continuous_arccos : Continuous arccos :=\n  continuous_const.sub continuous_arcsin\n#align real.continuous_arccos Real.continuous_arccos\n\n-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.\ntheorem tan_arccos (x : \u211d) : tan (arccos x) = sqrt (1 - x ^ 2) / x := by\n  rw [arccos, tan_pi_div_two_sub, tan_arcsin, inv_div]\n#align real.tan_arccos Real.tan_arccos\n\n-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.\ntheorem arccos_eq_arcsin {x : \u211d} (h : 0 \u2264 x) : arccos x = arcsin (sqrt (1 - x ^ 2)) :=\n  (arcsin_eq_of_sin_eq (sin_arccos _)\n      \u27e8(Left.neg_nonpos_iff.2 (div_nonneg pi_pos.le (by norm_num))).trans (arccos_nonneg _),\n        arccos_le_pi_div_two.2 h\u27e9).symm\n#align real.arccos_eq_arcsin Real.arccos_eq_arcsin\n\n-- The junk values for `arcsin` and `sqrt` make this true even for `1 < x`.\ntheorem arcsin_eq_arccos {x : \u211d} (h : 0 \u2264 x) : arcsin x = arccos (sqrt (1 - x ^ 2)) :=\n  by\n  rw [eq_comm, \u2190 cos_arcsin]\n  exact\n    arccos_cos (arcsin_nonneg.2 h)\n      ((arcsin_le_pi_div_two _).trans (div_le_self pi_pos.le one_le_two))\n#align real.arcsin_eq_arccos Real.arcsin_eq_arccos\n\nend Real\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/SpecialFunctions/Trigonometric/Inverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7380474049988912}}
{"text": "import data.real.basic\n\ndef converges_to (s : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (s n - a) < \u03b5\n\nvariables {s : \u2115 \u2192 \u211d} {a : \u211d}\n\n-- BEGIN\ntheorem exists_abs_le_of_converges_to (cs : converges_to s a) :\n  \u2203 N b, \u2200 n, N \u2264 n \u2192 abs (s n) < b :=\nbegin\n  cases cs 1 zero_lt_one with N h,\n  use [N, abs a + 1],\n  intros n hn,\n  specialize h n hn,\n  have t := abs_sub_abs_le_abs_sub (s n) a,\n  have t' := lt_of_le_of_lt t h,\n  exact sub_lt_iff_lt_add'.mp t',\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.1_cases_exist/ex13_cases_converge_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7380474037384741}}
{"text": "import tactic\n\n/-- The equivalence relation on \u2115\u00b2 such that equivalence classes are \u2124 -/\ndef nat2.R (a b : \u2115 \u00d7 \u2115) : Prop :=\na.1 + b.2 = b.1 + a.2\n-- here a and b are pairs, so a = (a.1, a.2) etc.\n\n-- introduce \u2248 (type with `\\~~`) notation for this relation\ninstance : has_equiv (\u2115 \u00d7 \u2115) := \u27e8nat2.R\u27e9\n\n-- let's prove some lemmas about this binary relation\nnamespace nat2.R\n#check quotient.lift_on\n-- The following lemma is true by definition, but it's useful to\n-- have it around so you can rewrite with it\n@[simp] lemma equiv_def {i j k l : \u2115} : (i, j) \u2248 (k, l) \u2194 i + l = k + j :=\nbegin\n  refl\nend\n\n-- try rewriting `equiv_def`\nlemma practice : (3, 5) \u2248 (4, 6) :=\nbegin\n  change 3 + 6 = 4 + 5,\n  refl,\nend\n\n-- Now let's prove that this binary relation is an equivalence relation\nlemma reflexive : \u2200 x : \u2115 \u00d7 \u2115, x \u2248 x :=\nbegin\n  rintro \u27e8i, j\u27e9,\n  rw equiv_def,\nend\n\nlemma symmetric : \u2200 x y : \u2115 \u00d7 \u2115, (x \u2248 y) \u2192 (y \u2248 x) :=\nbegin\n  -- here are a couple of tricks\n  rintro \u27e8i, j\u27e9 \u27e8k, l\u27e9 h,\n  -- type `\u22a2` with `\\|-` \n  rw equiv_def at h \u22a2,\n  rw h,\nend\n\nlemma transitive : \u2200 x y z : \u2115 \u00d7 \u2115, (x \u2248 y) \u2192 (y \u2248 z) \u2192 (x \u2248 z) :=\nbegin\n  -- this is a little trickier\n  -- recall `add_right_inj` says `a + b = c + b \u2192 a = c`\n  rintro \u27e8i, j\u27e9 \u27e8k, l\u27e9 \u27e8m, n\u27e9 hxy hyz,\n  rw equiv_def at hxy hyz \u22a2,\n  rw \u2190 add_left_inj (k+l),\n  calc (i+n)+(k+l)=(i+l)+(k+n) : by ring\n  ... = (k+j)+(m+l) : by rw [hxy, hyz]\n  ... = (m+j)+(k+l) : by ring\nend\n\n-- This line tells Lean that the binary relation is an equivalence\n-- relation and hence we can take the \"quotient\", i.e. the\n-- type of equivalence classes\ninstance setoid : setoid (\u2115 \u00d7 \u2115) :=\n{ r := nat2.R,\n  iseqv := \u27e8reflexive, symmetric, transitive\u27e9 }\n\n-- end of lemmas about the binary relation\nend nat2.R\n\n-- ...but we're still going to be using them\nopen nat2.R\n\n/-- The integers are the equivalence classes of the equivalence relation\n we just defined on \u2115\u00b2  -/\ndef myint := quotient nat2.R.setoid\n\n-- let's make some definitions, and prove some theorems, about integers\nnamespace myint \n\n-- The first goal is to get a good interface for addition.\n-- To do this we need to define a+b, and -a, and 0. Let's do\n-- them in reverse order.\n\n/-! ## zero -/\n\ndef zero := \u27e6(0,0)\u27e7\n\ninstance : has_zero myint := \u27e8myint.zero\u27e9\n\nlemma zero_def : (0 : myint) = \u27e6(0, 0)\u27e7 :=\nbegin\n  refl\nend\n\n/-! ## negation (additive inverse) -/\n\n-- First we define an \"auxiliary\" map from \u2115\u00b2 to \u2124 \n-- sending (a,b) to the equivalence class of (b,a).\n\ndef neg_aux (x : \u2115 \u00d7 \u2115) : myint := \u27e6(x.2, x.1)\u27e7\n\n-- true by definition\nlemma neg_aux_def (i j : \u2115) : neg_aux (i, j) = \u27e6(j, i)\u27e7 := rfl\n\n/-! ### Well-definedness\n\nOK now here's the concrete problem. We would like to define\na negation map `\u2124 \u2192 \u2124` sending `z` to `-z`. We want to do this in\nthe following way: Say `z \u2208 \u2124`. Choose `a=(i,j) \u2208 \u2115\u00b2` representing `z`\n(i.e. such that `cl(i,j) = \u27e6(i,j)\u27e7 = z`)\nNow apply `neg_aux` to `a`, and define `-z` to be the result.\n\nThe problem with this is that what if `b` is a different\nelement of the equivalence class? Then we also want `-z` to be `neg_aux b`.\n\nIndeed, in Lean this construction is called `quotient.lift`, and\nif you uncomment the below code\n-/\n\n--def neg : myint \u2192 myint :=\n--quotient.lift neg_aux _\n\n/-\nyou'll see an error, and if you put your cursor on the error you'll\nsee that Lean wants a proof that if two elements `a` and `b` are in the\nsame equivalence class, then `neg_aux a = neg_aux b`. So let's prove this now.\n-/\n\n-- negation on the integers, defined via neg_aux, is well-defined.\nlemma neg_aux_lemma : \u2200 x y : \u2115 \u00d7 \u2115, x \u2248 y \u2192 neg_aux x = neg_aux y :=\nbegin\n  rintro \u27e8i,j\u27e9 \u27e8k,l\u27e9 h,\n  rw [neg_aux_def, neg_aux_def],\n  -- \u22a2 \u27e6(j, i)\u27e7 = \u27e6(l, k)\u27e7\n  -- next step: if \u27e6a\u27e7=\u27e6b\u27e7 then a \u2248 b\n  apply quotient.sound,\n  -- \u22a2 (j, i) \u2248 (l, k)\n  rw equiv_def at h \u22a2,\n  rw add_comm,\n  rw \u2190 h,\n  apply add_comm,\nend\n\n/-- Negation on on the integers. The function sending `z` to `-z`. -/\ndef neg : myint \u2192 myint :=\nquotient.lift neg_aux neg_aux_lemma\n\n-- notation for negation\ninstance : has_neg myint := \u27e8neg\u27e9\n\n-- this is true by definition\nlemma neg_def (i j : \u2115) : (-\u27e6(i, j)\u27e7 : myint) = \u27e6(j, i)\u27e7 :=\nbegin\n  refl\nend\n\n/-!  ## addition\n\nOur final construction: we want to define addition on `myint`. \nHere we have the same problem. Say z\u2081 and z\u2082 are integers.\nChoose elements a\u2081=(i,j) and a\u2082=(k,l) in \u2115\u00b2. We want to define\nz\u2081 + z\u2082 to be \u27e6(i+k,j+l)\u27e7, the equivalence class of a\u2081 + a\u2082.\nLet's make this definition now.\n\n-/\n\n/-- An auxiliary function taking two elements of \u2115\u00b2 and returning\nthe equivalence class of their sum. -/\ndef add_aux (x y : \u2115 \u00d7 \u2115) : myint := \u27e6(x.1 + y.1, x.2 + y.2)\u27e7\n\n-- true by definition, but useful for rewriting\nlemma add_aux_def (i j k l : \u2115) : add_aux (i, j) (k, l) = \u27e6(i + k, j + l)\u27e7 :=\nbegin\n  refl\nend\n\n/-\n\nWe want the definition of addition to look like the below.\nUncomment it to see the problem. \n\n-/\n\n--def add : myint \u2192 myint \u2192 myint :=\n--quotient.lift\u2082 add_aux _\n\n/-\nWe had better check that choosing different elements in the same\nequivalence class gives the same definition.\n\n-/\n\nlemma add_aux_lemma : \u2200 x\u2081 x\u2082 y\u2081 y\u2082 : \u2115 \u00d7 \u2115,\n(x\u2081 \u2248 y\u2081) \u2192 (x\u2082 \u2248 y\u2082) \u2192 add_aux x\u2081 x\u2082 = add_aux y\u2081 y\u2082 :=\nbegin\n  rintro \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9 \u27e8g, h\u27e9 h1 h2,\n  rw add_aux_def,\n  rw add_aux_def,\n  apply quotient.sound,\n  rw equiv_def at *,\n  rw (show (a+c)+(f+h) = (a+f)+(c+h), by ring),\n  rw [h1, h2],\n  ring,\nend\n\n-- Now this is checked, we can define addition.\n\n/-- Addition on the integers -/\ndef add : myint \u2192 myint \u2192 myint :=\nquotient.lift\u2082 add_aux add_aux_lemma\n\n-- notation for addition\ninstance : has_add myint := \u27e8add\u27e9\n\n-- true by definition\nlemma add_def (i j k l : \u2115) :\n  (\u27e6(i, j)\u27e7 + \u27e6(k, l)\u27e7 : myint) = \u27e6(i + k, j + l)\u27e7 :=\nbegin\n  refl\nend\n\n/-\nThe four fundamental facts about addition on the integes are:\n1) associativity\n2) commutativity\n3) zero is an additive identity\n4) negation is an additive inverse.\n\nLet's prove these now.\n\n-/\n\nlemma zero_add (x : myint) : 0 + x = x :=\nbegin\n  apply quotient.induction_on x,\n  rintro \u27e8a, b\u27e9,\n  rw zero_def,\n  rw add_def,\n  apply quotient.sound,\n  rw equiv_def,\n  ring,\nend\n\nlemma add_zero (x : myint) : x + 0 = x :=\nbegin\n  apply quotient.induction_on x,\n  rintro \u27e8a, b\u27e9,\n  rw zero_def,\n  rw add_def,\n  apply quotient.sound,\n  rw equiv_def,\n  ring,\nend\n\nlemma add_left_neg (x : myint) : -x + x = 0 :=\nbegin\n  apply quotient.induction_on x,\n  rintro \u27e8a, b\u27e9,\n  rw zero_def,\n  rw neg_def,\n  rw add_def,\n  apply quotient.sound,\n  rw equiv_def,\n  ring,\nend\n\nlemma add_comm (x y : myint) : x + y = y + x :=\nbegin\n  apply quotient.induction_on\u2082 x y,\n  rintro \u27e8a, b\u27e9 \u27e8c, d\u27e9,\n  rw [add_def, add_def],\n  apply quotient.sound,\n  rw equiv_def,\n  ring,\nend\n\nlemma add_assoc (x y z : myint) : (x + y) + z = x + (y + z) :=\nbegin\n  apply quotient.induction_on\u2083 x y z,\n  rintro \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9,\n  simp [add_def],\n  ring,\nend\n\n-- We just proved that the integers are a commutative group under addition!\n\ninstance : add_comm_group myint :=\n{ add := (+),\n  add_assoc := add_assoc,\n  zero := 0,\n  zero_add := zero_add,\n  add_zero := add_zero,\n  neg := has_neg.neg,\n  add_left_neg := add_left_neg,\n  add_comm := add_comm }\n\n-- woohoo!\n\n/-! ## multiplication\n\nWhat's left to define is 1 and multiplication (note that we don't need multiplicative\ninverses -- if a is a non-zero integer then a\u207b\u00b9 is typially not an integer)\n\n-/\n\ndef mul_aux (x y : \u2115 \u00d7 \u2115) : myint := \u27e6(x.1*y.1+x.2*y.2, x.1*y.2+x.2*y.1)\u27e7\n\nlemma mul_aux_def (i j k l : \u2115) : mul_aux (i, j) (k, l) = \u27e6(i*k+j*l, i*l+j*k)\u27e7 :=\nbegin\n  refl\nend\n\n-- Boss level. \n-- Dr. Lawn: \"We leave the similar verification for multiplication as an exercise.\"\n\n-- This is what we need to check for multiplication to \"descend\" (or \"lift\" as Lean\n-- calls it) to a well-defined function on the quotient. \nlemma mul_aux_lemma : \u2200 x\u2081 x\u2082 y\u2081 y\u2082 : \u2115 \u00d7 \u2115,\n(x\u2081 \u2248 y\u2081) \u2192 (x\u2082 \u2248 y\u2082) \u2192 mul_aux x\u2081 x\u2082 = mul_aux y\u2081 y\u2082 :=\nbegin\n  rintro \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9 \u27e8g, h\u27e9 h1 h2,\n  simp only [mul_aux_def],\n  apply quotient.sound,\n  rw equiv_def at *,\n  -- a calc proof would be nicer. Can I get away with rewriting h1 and h2\n  -- fewer times?\n  rw \u2190 add_left_inj (a * h),\n  have h3 : a * c + b * d + (e * h + f * g) + a * h = a * (c + h) + b*d+e*h+f*g,\n    ring,\n  rw h3,\n  rw h2,\n  have h4 : a * (g + d) + b * d + e * h + f * g = (a+f)*g+a*d+b*d+e*h,\n    ring,\n  rw h4,\n  rw h1,\n  clear h3, clear h4,\n  rw (show (e + b) * g + a * d + b * d + e * h = e*g+a*d+b*(g+d)+e*h, by ring),\n  rw \u2190 h2,\n  rw (show e * g + a * d + b * (c + h) + e * h = e * g + a * d + b * c + (e+b) * h, by ring),\n  rw \u2190 h1,\n  ring,\nend\n\n-- definition of multiplication\ndef mul : myint \u2192 myint \u2192 myint :=\nquotient.lift\u2082 mul_aux mul_aux_lemma\n\ninstance : has_mul myint := \u27e8mul\u27e9 \n\nlemma mul_def (i j k l : \u2115) : (\u27e6(i, j)\u27e7 * \u27e6(k, l)\u27e7 : myint) = \u27e6(i*k+j*l, i*l+j*k)\u27e7 :=\nbegin\n  refl\nend\n\nlemma mul_assoc (x y z : myint) : (x * y) * z = x * (y * z) :=\nbegin\n  apply quotient.induction_on\u2083 x y z,\n  rintro \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9,\n  simp [mul_def],\n  ring,\nend\n\ndef one : myint := \u27e6(37, 36)\u27e7\n\ninstance : has_one myint := \u27e8myint.one\u27e9\n\n-- true by definition\nlemma one_def : (1 : myint) = \u27e6(37, 36)\u27e7 :=\nbegin\n  refl\nend\n\nlemma one_mul (x : myint) : 1 * x = x :=\nbegin\n  apply quotient.induction_on x,\n  rintro \u27e8i, j\u27e9,\n  simp [one_def, mul_def],\n  ring,\nend\n\nlemma mul_one (x : myint) : x * 1 = x :=\nbegin\n  apply quotient.induction_on x,\n  rintro \u27e8i, j\u27e9,\n  simp [one_def, mul_def],\n  ring,\nend\n\nlemma mul_comm (x y : myint) : x * y = y * x :=\nbegin\n  apply quotient.induction_on\u2082 x y,\n  rintro \u27e8i, j\u27e9 \u27e8k, l\u27e9,\n  simp [mul_def],\n  ring,\nend\n\nlemma mul_add (x y z : myint) : x * (y + z) = x * y + x * z :=\nbegin\n  apply quotient.induction_on\u2083 x y z,\n  rintro \u27e8i, j\u27e9 \u27e8k, l\u27e9 \u27e8m, n\u27e9,\n  simp [add_def, mul_def],\n  ring,\nend\n\nlemma add_mul (x y z : myint) : (x + y) * z = x * z + y * z :=\nbegin\n  apply quotient.induction_on\u2083 x y z,\n  rintro \u27e8i, j\u27e9 \u27e8k, l\u27e9 \u27e8m, n\u27e9,\n  simp [add_def, mul_def],\n  ring,\nend\n\n-- The integers are a commutative ring\n-- (that is, they satisfy the axioms we just proved)\ninstance : comm_ring myint :=\n{ mul := (*),\n  mul_assoc := mul_assoc,\n  one := 1,\n  one_mul := one_mul,\n  mul_one := mul_one,\n  left_distrib := mul_add,\n  right_distrib := add_mul,\n  mul_comm := mul_comm,\n  ..myint.add_comm_group }\n\nend myint\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/integers/int_def_solns.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7380473917900011}}
{"text": "/-\nCopyright (c) 2021 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n\n! This file was ported from Lean 3 source module algebra.algebra.spectrum\n! leanprover-community/mathlib commit 11dcb6b59dc9cc74e053b7ca8569bf6df4ac0f1e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Star.Pointwise\nimport Mathbin.Algebra.Star.Subalgebra\nimport Mathbin.FieldTheory.IsAlgClosed.Basic\nimport Mathbin.Tactic.NoncommRing\n\n/-!\n# Spectrum of an element in an algebra\nThis file develops the basic theory of the spectrum of an element of an algebra.\nThis theory will serve as the foundation for spectral theory in Banach algebras.\n\n## Main definitions\n\n* `resolvent_set a : set R`: the resolvent set of an element `a : A` where\n  `A` is an  `R`-algebra.\n* `spectrum a : set R`: the spectrum of an element `a : A` where\n  `A` is an  `R`-algebra.\n* `resolvent : R \u2192 A`: the resolvent function is `\u03bb r, ring.inverse (\u2191\u2090r - a)`, and hence\n  when `r \u2208 resolvent R A`, it is actually the inverse of the unit `(\u2191\u2090r - a)`.\n\n## Main statements\n\n* `spectrum.unit_smul_eq_smul` and `spectrum.smul_eq_smul`: units in the scalar ring commute\n  (multiplication) with the spectrum, and over a field even `0` commutes with the spectrum.\n* `spectrum.left_add_coset_eq`: elements of the scalar ring commute (addition) with the spectrum.\n* `spectrum.unit_mem_mul_iff_mem_swap_mul` and `spectrum.preimage_units_mul_eq_swap_mul`: the\n  units (of `R`) in `\u03c3 (a*b)` coincide with those in `\u03c3 (b*a)`.\n* `spectrum.scalar_eq`: in a nontrivial algebra over a field, the spectrum of a scalar is\n  a singleton.\n* `spectrum.subset_polynomial_aeval`, `spectrum.map_polynomial_aeval_of_degree_pos`,\n  `spectrum.map_polynomial_aeval_of_nonempty`: variations on the spectral mapping theorem.\n\n## Notations\n\n* `\u03c3 a` : `spectrum R a` of `a : A`\n-/\n\n\nopen Set\n\nopen Pointwise\n\nuniverse u v\n\nsection Defs\n\nvariable (R : Type u) {A : Type v}\n\nvariable [CommSemiring R] [Ring A] [Algebra R A]\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap R A\n\n-- definition and basic properties\n/-- Given a commutative ring `R` and an `R`-algebra `A`, the *resolvent set* of `a : A`\nis the `set R` consisting of those `r : R` for which `r\u20221 - a` is a unit of the\nalgebra `A`.  -/\ndef resolventSet (a : A) : Set R :=\n  { r : R | IsUnit (\u2191\u2090 r - a) }\n#align resolvent_set resolventSet\n\n/-- Given a commutative ring `R` and an `R`-algebra `A`, the *spectrum* of `a : A`\nis the `set R` consisting of those `r : R` for which `r\u20221 - a` is not a unit of the\nalgebra `A`.\n\nThe spectrum is simply the complement of the resolvent set.  -/\ndef spectrum (a : A) : Set R :=\n  resolventSet R a\u1d9c\n#align spectrum spectrum\n\nvariable {R}\n\n/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is\n    a map `R \u2192 A` which sends `r : R` to `(algebra_map R A r - a)\u207b\u00b9` when\n    `r \u2208 resolvent R A` and `0` when `r \u2208 spectrum R A`. -/\nnoncomputable def resolvent (a : A) (r : R) : A :=\n  Ring.inverse (\u2191\u2090 r - a)\n#align resolvent resolvent\n\n/-- The unit `1 - r\u207b\u00b9 \u2022 a` constructed from `r \u2022 1 - a` when the latter is a unit. -/\n@[simps]\nnoncomputable def IsUnit.subInvSmul {r : R\u02e3} {s : R} {a : A} (h : IsUnit <| r \u2022 \u2191\u2090 s - a) : A\u02e3\n    where\n  val := \u2191\u2090 s - r\u207b\u00b9 \u2022 a\n  inv := r \u2022 \u2191h.Unit\u207b\u00b9\n  val_inv := by rw [mul_smul_comm, \u2190 smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_coe_inv]\n  inv_val := by rw [smul_mul_assoc, \u2190 mul_smul_comm, smul_sub, smul_inv_smul, h.coe_inv_mul]\n#align is_unit.sub_inv_smul IsUnit.subInvSmul\n\nend Defs\n\nnamespace spectrum\n\nopen Polynomial\n\nsection ScalarSemiring\n\nvariable {R : Type u} {A : Type v}\n\nvariable [CommSemiring R] [Ring A] [Algebra R A]\n\n-- mathport name: expr\u03c3\nlocal notation \"\u03c3\" => spectrum R\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap R A\n\ntheorem mem_iff {r : R} {a : A} : r \u2208 \u03c3 a \u2194 \u00acIsUnit (\u2191\u2090 r - a) :=\n  Iff.rfl\n#align spectrum.mem_iff spectrum.mem_iff\n\ntheorem not_mem_iff {r : R} {a : A} : r \u2209 \u03c3 a \u2194 IsUnit (\u2191\u2090 r - a) :=\n  by\n  apply not_iff_not.mp\n  simp [Set.not_not_mem, mem_iff]\n#align spectrum.not_mem_iff spectrum.not_mem_iff\n\nvariable (R)\n\ntheorem zero_mem_iff {a : A} : (0 : R) \u2208 \u03c3 a \u2194 \u00acIsUnit a := by\n  rw [mem_iff, map_zero, zero_sub, IsUnit.neg_iff]\n#align spectrum.zero_mem_iff spectrum.zero_mem_iff\n\ntheorem zero_not_mem_iff {a : A} : (0 : R) \u2209 \u03c3 a \u2194 IsUnit a := by\n  rw [zero_mem_iff, Classical.not_not]\n#align spectrum.zero_not_mem_iff spectrum.zero_not_mem_iff\n\nvariable {R}\n\ntheorem mem_resolventSet_of_left_right_inverse {r : R} {a b c : A} (h\u2081 : (\u2191\u2090 r - a) * b = 1)\n    (h\u2082 : c * (\u2191\u2090 r - a) = 1) : r \u2208 resolventSet R a :=\n  Units.isUnit \u27e8\u2191\u2090 r - a, b, h\u2081, by rwa [\u2190 left_inv_eq_right_inv h\u2082 h\u2081]\u27e9\n#align spectrum.mem_resolvent_set_of_left_right_inverse spectrum.mem_resolventSet_of_left_right_inverse\n\ntheorem mem_resolventSet_iff {r : R} {a : A} : r \u2208 resolventSet R a \u2194 IsUnit (\u2191\u2090 r - a) :=\n  Iff.rfl\n#align spectrum.mem_resolvent_set_iff spectrum.mem_resolventSet_iff\n\n@[simp]\ntheorem resolventSet_of_subsingleton [Subsingleton A] (a : A) : resolventSet R a = Set.univ := by\n  simp_rw [resolventSet, Subsingleton.elim (algebraMap R A _ - a) 1, isUnit_one, Set.setOf_true]\n#align spectrum.resolvent_set_of_subsingleton spectrum.resolventSet_of_subsingleton\n\n@[simp]\ntheorem of_subsingleton [Subsingleton A] (a : A) : spectrum R a = \u2205 := by\n  rw [spectrum, resolvent_set_of_subsingleton, Set.compl_univ]\n#align spectrum.of_subsingleton spectrum.of_subsingleton\n\ntheorem resolvent_eq {a : A} {r : R} (h : r \u2208 resolventSet R a) : resolvent a r = \u2191h.Unit\u207b\u00b9 :=\n  Ring.inverse_unit h.Unit\n#align spectrum.resolvent_eq spectrum.resolvent_eq\n\ntheorem units_smul_resolvent {r : R\u02e3} {s : R} {a : A} :\n    r \u2022 resolvent a (s : R) = resolvent (r\u207b\u00b9 \u2022 a) (r\u207b\u00b9 \u2022 s : R) :=\n  by\n  by_cases h : s \u2208 spectrum R a\n  \u00b7 rw [mem_iff] at h\n    simp only [resolvent, Algebra.algebraMap_eq_smul_one] at *\n    rw [smul_assoc, \u2190 smul_sub]\n    have h' : \u00acIsUnit (r\u207b\u00b9 \u2022 (s \u2022 1 - a)) := fun hu =>\n      h (by simpa only [smul_inv_smul] using IsUnit.smul r hu)\n    simp only [Ring.inverse_non_unit _ h, Ring.inverse_non_unit _ h', smul_zero]\n  \u00b7 simp only [resolvent]\n    have h' : IsUnit (r \u2022 algebraMap R A (r\u207b\u00b9 \u2022 s) - a) := by\n      simpa [Algebra.algebraMap_eq_smul_one, smul_assoc] using not_mem_iff.mp h\n    rw [\u2190 h'.coe_sub_inv_smul, \u2190 (not_mem_iff.mp h).unit_spec, Ring.inverse_unit, Ring.inverse_unit,\n      h'.coe_inv_sub_inv_smul]\n    simp only [Algebra.algebraMap_eq_smul_one, smul_assoc, smul_inv_smul]\n#align spectrum.units_smul_resolvent spectrum.units_smul_resolvent\n\ntheorem units_smul_resolvent_self {r : R\u02e3} {a : A} :\n    r \u2022 resolvent a (r : R) = resolvent (r\u207b\u00b9 \u2022 a) (1 : R) := by\n  simpa only [Units.smul_def, Algebra.id.smul_eq_mul, Units.inv_mul] using\n    @units_smul_resolvent _ _ _ _ _ r r a\n#align spectrum.units_smul_resolvent_self spectrum.units_smul_resolvent_self\n\n/-- The resolvent is a unit when the argument is in the resolvent set. -/\ntheorem isUnit_resolvent {r : R} {a : A} : r \u2208 resolventSet R a \u2194 IsUnit (resolvent a r) :=\n  isUnit_ring_inverse.symm\n#align spectrum.is_unit_resolvent spectrum.isUnit_resolvent\n\ntheorem inv_mem_resolventSet {r : R\u02e3} {a : A\u02e3} (h : (r : R) \u2208 resolventSet R (a : A)) :\n    (\u2191r\u207b\u00b9 : R) \u2208 resolventSet R (\u2191a\u207b\u00b9 : A) :=\n  by\n  rw [mem_resolvent_set_iff, Algebra.algebraMap_eq_smul_one, \u2190 Units.smul_def] at h\u22a2\n  rw [IsUnit.smul_sub_iff_sub_inv_smul, inv_inv, IsUnit.sub_iff]\n  have h\u2081 : (a : A) * (r \u2022 (\u2191a\u207b\u00b9 : A) - 1) = r \u2022 1 - a := by\n    rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one]\n  have h\u2082 : (r \u2022 (\u2191a\u207b\u00b9 : A) - 1) * a = r \u2022 1 - a := by\n    rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul]\n  have hcomm : Commute (a : A) (r \u2022 (\u2191a\u207b\u00b9 : A) - 1) := by rwa [\u2190 h\u2082] at h\u2081\n  exact (hcomm.is_unit_mul_iff.mp (h\u2081.symm \u25b8 h)).2\n#align spectrum.inv_mem_resolvent_set spectrum.inv_mem_resolventSet\n\ntheorem inv_mem_iff {r : R\u02e3} {a : A\u02e3} : (r : R) \u2208 \u03c3 (a : A) \u2194 (\u2191r\u207b\u00b9 : R) \u2208 \u03c3 (\u2191a\u207b\u00b9 : A) :=\n  not_iff_not.2 <| \u27e8inv_mem_resolventSet, inv_mem_resolventSet\u27e9\n#align spectrum.inv_mem_iff spectrum.inv_mem_iff\n\ntheorem zero_mem_resolventSet_of_unit (a : A\u02e3) : 0 \u2208 resolventSet R (a : A) := by\n  simpa only [mem_resolvent_set_iff, \u2190 not_mem_iff, zero_not_mem_iff] using a.is_unit\n#align spectrum.zero_mem_resolvent_set_of_unit spectrum.zero_mem_resolventSet_of_unit\n\ntheorem ne_zero_of_mem_of_unit {a : A\u02e3} {r : R} (hr : r \u2208 \u03c3 (a : A)) : r \u2260 0 := fun hn =>\n  (hn \u25b8 hr) (zero_mem_resolventSet_of_unit a)\n#align spectrum.ne_zero_of_mem_of_unit spectrum.ne_zero_of_mem_of_unit\n\ntheorem add_mem_iff {a : A} {r s : R} : r + s \u2208 \u03c3 a \u2194 r \u2208 \u03c3 (-\u2191\u2090 s + a) := by\n  simp only [mem_iff, sub_neg_eq_add, \u2190 sub_sub, map_add]\n#align spectrum.add_mem_iff spectrum.add_mem_iff\n\ntheorem add_mem_add_iff {a : A} {r s : R} : r + s \u2208 \u03c3 (\u2191\u2090 s + a) \u2194 r \u2208 \u03c3 a := by\n  rw [add_mem_iff, neg_add_cancel_left]\n#align spectrum.add_mem_add_iff spectrum.add_mem_add_iff\n\ntheorem smul_mem_smul_iff {a : A} {s : R} {r : R\u02e3} : r \u2022 s \u2208 \u03c3 (r \u2022 a) \u2194 s \u2208 \u03c3 a := by\n  simp only [mem_iff, not_iff_not, Algebra.algebraMap_eq_smul_one, smul_assoc, \u2190 smul_sub,\n    isUnit_smul_iff]\n#align spectrum.smul_mem_smul_iff spectrum.smul_mem_smul_iff\n\nopen Polynomial\n\ntheorem unit_smul_eq_smul (a : A) (r : R\u02e3) : \u03c3 (r \u2022 a) = r \u2022 \u03c3 a :=\n  by\n  ext\n  have x_eq : x = r \u2022 r\u207b\u00b9 \u2022 x := by simp\n  nth_rw 1 [x_eq]\n  rw [smul_mem_smul_iff]\n  constructor\n  \u00b7 exact fun h => \u27e8r\u207b\u00b9 \u2022 x, \u27e8h, by simp\u27e9\u27e9\n  \u00b7 rintro \u27e8_, _, x'_eq\u27e9\n    simpa [\u2190 x'_eq]\n#align spectrum.unit_smul_eq_smul spectrum.unit_smul_eq_smul\n\n-- `r \u2208 \u03c3(a*b) \u2194 r \u2208 \u03c3(b*a)` for any `r : R\u02e3`\ntheorem unit_mem_mul_iff_mem_swap_mul {a b : A} {r : R\u02e3} : \u2191r \u2208 \u03c3 (a * b) \u2194 \u2191r \u2208 \u03c3 (b * a) :=\n  by\n  have h\u2081 : \u2200 x y : A, IsUnit (1 - x * y) \u2192 IsUnit (1 - y * x) :=\n    by\n    refine' fun x y h => \u27e8\u27e81 - y * x, 1 + y * h.unit.inv * x, _, _\u27e9, rfl\u27e9\n    calc\n      (1 - y * x) * (1 + y * (IsUnit.unit h).inv * x) =\n          1 - y * x + y * ((1 - x * y) * h.unit.inv) * x :=\n        by noncomm_ring\n      _ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.mul_val_inv, mul_one, sub_add_cancel]\n      \n    calc\n      (1 + y * (IsUnit.unit h).inv * x) * (1 - y * x) =\n          1 - y * x + y * (h.unit.inv * (1 - x * y)) * x :=\n        by noncomm_ring\n      _ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.val_inv_mul, mul_one, sub_add_cancel]\n      \n  simpa only [mem_iff, not_iff_not, Algebra.algebraMap_eq_smul_one, \u2190 Units.smul_def,\n    IsUnit.smul_sub_iff_sub_inv_smul, \u2190 smul_mul_assoc, \u2190 mul_smul_comm r\u207b\u00b9 b a] using\n    Iff.intro (h\u2081 (r\u207b\u00b9 \u2022 a) b) (h\u2081 b (r\u207b\u00b9 \u2022 a))\n#align spectrum.unit_mem_mul_iff_mem_swap_mul spectrum.unit_mem_mul_iff_mem_swap_mul\n\ntheorem preimage_units_mul_eq_swap_mul {a b : A} :\n    (coe : R\u02e3 \u2192 R) \u207b\u00b9' \u03c3 (a * b) = coe \u207b\u00b9' \u03c3 (b * a) :=\n  Set.ext fun _ => unit_mem_mul_iff_mem_swap_mul\n#align spectrum.preimage_units_mul_eq_swap_mul spectrum.preimage_units_mul_eq_swap_mul\n\nsection Star\n\nvariable [InvolutiveStar R] [StarRing A] [StarModule R A]\n\ntheorem star_mem_resolventSet_iff {r : R} {a : A} :\n    star r \u2208 resolventSet R a \u2194 r \u2208 resolventSet R (star a) := by\n  refine' \u27e8fun h => _, fun h => _\u27e9 <;>\n    simpa only [mem_resolvent_set_iff, Algebra.algebraMap_eq_smul_one, star_sub, star_smul,\n      star_star, star_one] using IsUnit.star h\n#align spectrum.star_mem_resolvent_set_iff spectrum.star_mem_resolventSet_iff\n\nprotected theorem map_star (a : A) : \u03c3 (star a) = star (\u03c3 a) :=\n  by\n  ext\n  simpa only [Set.mem_star, mem_iff, not_iff_not] using star_mem_resolvent_set_iff.symm\n#align spectrum.map_star spectrum.map_star\n\nend Star\n\nend ScalarSemiring\n\nsection ScalarRing\n\nvariable {R : Type u} {A : Type v}\n\nvariable [CommRing R] [Ring A] [Algebra R A]\n\n-- mathport name: expr\u03c3\nlocal notation \"\u03c3\" => spectrum R\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap R A\n\n-- it would be nice to state this for `subalgebra_class`, but we don't have such a thing yet\ntheorem subset_subalgebra {S : Subalgebra R A} (a : S) : spectrum R (a : A) \u2286 spectrum R a :=\n  compl_subset_compl.2 fun _ => IsUnit.map S.val\n#align spectrum.subset_subalgebra spectrum.subset_subalgebra\n\n-- this is why it would be nice if `subset_subalgebra` was registered for `subalgebra_class`.\ntheorem subset_starSubalgebra [StarRing R] [StarRing A] [StarModule R A] {S : StarSubalgebra R A}\n    (a : S) : spectrum R (a : A) \u2286 spectrum R a :=\n  compl_subset_compl.2 fun _ => IsUnit.map S.Subtype\n#align spectrum.subset_star_subalgebra spectrum.subset_starSubalgebra\n\ntheorem singleton_add_eq (a : A) (r : R) : {r} + \u03c3 a = \u03c3 (\u2191\u2090 r + a) :=\n  ext fun x => by\n    rw [singleton_add, image_add_left, mem_preimage, add_comm, add_mem_iff, map_neg, neg_neg]\n#align spectrum.singleton_add_eq spectrum.singleton_add_eq\n\ntheorem add_singleton_eq (a : A) (r : R) : \u03c3 a + {r} = \u03c3 (a + \u2191\u2090 r) :=\n  add_comm {r} (\u03c3 a) \u25b8 add_comm (algebraMap R A r) a \u25b8 singleton_add_eq a r\n#align spectrum.add_singleton_eq spectrum.add_singleton_eq\n\ntheorem vadd_eq (a : A) (r : R) : r +\u1d65 \u03c3 a = \u03c3 (\u2191\u2090 r + a) :=\n  singleton_add.symm.trans <| singleton_add_eq a r\n#align spectrum.vadd_eq spectrum.vadd_eq\n\ntheorem neg_eq (a : A) : -\u03c3 a = \u03c3 (-a) :=\n  Set.ext fun x => by\n    simp only [mem_neg, mem_iff, map_neg, \u2190 neg_add', IsUnit.neg_iff, sub_neg_eq_add]\n#align spectrum.neg_eq spectrum.neg_eq\n\ntheorem singleton_sub_eq (a : A) (r : R) : {r} - \u03c3 a = \u03c3 (\u2191\u2090 r - a) := by\n  rw [sub_eq_add_neg, neg_eq, singleton_add_eq, sub_eq_add_neg]\n#align spectrum.singleton_sub_eq spectrum.singleton_sub_eq\n\ntheorem sub_singleton_eq (a : A) (r : R) : \u03c3 a - {r} = \u03c3 (a - \u2191\u2090 r) := by\n  simpa only [neg_sub, neg_eq] using congr_arg Neg.neg (singleton_sub_eq a r)\n#align spectrum.sub_singleton_eq spectrum.sub_singleton_eq\n\nopen Polynomial\n\ntheorem exists_mem_of_not_isUnit_aeval_prod [IsDomain R] {p : R[X]} {a : A} (hp : p \u2260 0)\n    (h : \u00acIsUnit (aeval a (Multiset.map (fun x : R => X - C x) p.roots).Prod)) :\n    \u2203 k : R, k \u2208 \u03c3 a \u2227 eval k p = 0 :=\n  by\n  rw [\u2190 Multiset.prod_toList, AlgHom.map_list_prod] at h\n  replace h := mt List.prod_isUnit h\n  simp only [not_forall, exists_prop, aeval_C, Multiset.mem_toList, List.mem_map, aeval_X,\n    exists_exists_and_eq_and, Multiset.mem_map, AlgHom.map_sub] at h\n  rcases h with \u27e8r, r_mem, r_nu\u27e9\n  exact \u27e8r, by rwa [mem_iff, \u2190 IsUnit.sub_iff], by rwa [\u2190 is_root.def, \u2190 mem_roots hp]\u27e9\n#align spectrum.exists_mem_of_not_is_unit_aeval_prod spectrum.exists_mem_of_not_isUnit_aeval_prod\n\nend ScalarRing\n\nsection ScalarField\n\nvariable {\ud835\udd5c : Type u} {A : Type v}\n\nvariable [Field \ud835\udd5c] [Ring A] [Algebra \ud835\udd5c A]\n\n-- mathport name: expr\u03c3\nlocal notation \"\u03c3\" => spectrum \ud835\udd5c\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap \ud835\udd5c A\n\n/-- Without the assumption `nontrivial A`, then `0 : A` would be invertible. -/\n@[simp]\ntheorem zero_eq [Nontrivial A] : \u03c3 (0 : A) = {0} :=\n  by\n  refine' Set.Subset.antisymm _ (by simp [Algebra.algebraMap_eq_smul_one, mem_iff])\n  rw [spectrum, Set.compl_subset_comm]\n  intro k hk\n  rw [Set.mem_compl_singleton_iff] at hk\n  have : IsUnit (Units.mk0 k hk \u2022 (1 : A)) := IsUnit.smul (Units.mk0 k hk) isUnit_one\n  simpa [mem_resolvent_set_iff, Algebra.algebraMap_eq_smul_one]\n#align spectrum.zero_eq spectrum.zero_eq\n\n@[simp]\ntheorem scalar_eq [Nontrivial A] (k : \ud835\udd5c) : \u03c3 (\u2191\u2090 k) = {k} := by\n  rw [\u2190 add_zero (\u2191\u2090 k), \u2190 singleton_add_eq, zero_eq, Set.singleton_add_singleton, add_zero]\n#align spectrum.scalar_eq spectrum.scalar_eq\n\n@[simp]\ntheorem one_eq [Nontrivial A] : \u03c3 (1 : A) = {1} :=\n  calc\n    \u03c3 (1 : A) = \u03c3 (\u2191\u2090 1) := by rw [Algebra.algebraMap_eq_smul_one, one_smul]\n    _ = {1} := scalar_eq 1\n    \n#align spectrum.one_eq spectrum.one_eq\n\n/-- the assumption `(\u03c3 a).nonempty` is necessary and cannot be removed without\n    further conditions on the algebra `A` and scalar field `\ud835\udd5c`. -/\ntheorem smul_eq_smul [Nontrivial A] (k : \ud835\udd5c) (a : A) (ha : (\u03c3 a).Nonempty) : \u03c3 (k \u2022 a) = k \u2022 \u03c3 a :=\n  by\n  rcases eq_or_ne k 0 with (rfl | h)\n  \u00b7 simpa [ha, zero_smul_set]\n  \u00b7 exact unit_smul_eq_smul a (Units.mk0 k h)\n#align spectrum.smul_eq_smul spectrum.smul_eq_smul\n\ntheorem nonzero_mul_eq_swap_mul (a b : A) : \u03c3 (a * b) \\ {0} = \u03c3 (b * a) \\ {0} :=\n  by\n  suffices h : \u2200 x y : A, \u03c3 (x * y) \\ {0} \u2286 \u03c3 (y * x) \\ {0}\n  \u00b7 exact Set.eq_of_subset_of_subset (h a b) (h b a)\n  \u00b7 rintro _ _ k \u27e8k_mem, k_neq\u27e9\n    change k with \u2191(Units.mk0 k k_neq) at k_mem\n    exact \u27e8unit_mem_mul_iff_mem_swap_mul.mp k_mem, k_neq\u27e9\n#align spectrum.nonzero_mul_eq_swap_mul spectrum.nonzero_mul_eq_swap_mul\n\nprotected theorem map_inv (a : A\u02e3) : (\u03c3 (a : A))\u207b\u00b9 = \u03c3 (\u2191a\u207b\u00b9 : A) :=\n  by\n  refine' Set.eq_of_subset_of_subset (fun k hk => _) fun k hk => _\n  \u00b7 rw [Set.mem_inv] at hk\n    have : k \u2260 0 := by simpa only [inv_inv] using inv_ne_zero (ne_zero_of_mem_of_unit hk)\n    lift k to \ud835\udd5c\u02e3 using is_unit_iff_ne_zero.mpr this\n    rw [\u2190 Units.val_inv_eq_inv_val k] at hk\n    exact inv_mem_iff.mp hk\n  \u00b7 lift k to \ud835\udd5c\u02e3 using is_unit_iff_ne_zero.mpr (ne_zero_of_mem_of_unit hk)\n    simpa only [Units.val_inv_eq_inv_val] using inv_mem_iff.mp hk\n#align spectrum.map_inv spectrum.map_inv\n\nopen Polynomial\n\n/-- Half of the spectral mapping theorem for polynomials. We prove it separately\nbecause it holds over any field, whereas `spectrum.map_polynomial_aeval_of_degree_pos` and\n`spectrum.map_polynomial_aeval_of_nonempty` need the field to be algebraically closed. -/\ntheorem subset_polynomial_aeval (a : A) (p : \ud835\udd5c[X]) : (fun k => eval k p) '' \u03c3 a \u2286 \u03c3 (aeval a p) :=\n  by\n  rintro _ \u27e8k, hk, rfl\u27e9\n  let q := C (eval k p) - p\n  have hroot : is_root q k := by simp only [eval_C, eval_sub, sub_self, is_root.def]\n  rw [\u2190 mul_div_eq_iff_is_root, \u2190 neg_mul_neg, neg_sub] at hroot\n  have aeval_q_eq : \u2191\u2090 (eval k p) - aeval a p = aeval a q := by\n    simp only [aeval_C, AlgHom.map_sub, sub_left_inj]\n  rw [mem_iff, aeval_q_eq, \u2190 hroot, aeval_mul]\n  have hcomm := (Commute.all (C k - X) (-(q / (X - C k)))).map (aeval a)\n  apply mt fun h => (hcomm.is_unit_mul_iff.mp h).1\n  simpa only [aeval_X, aeval_C, AlgHom.map_sub] using hk\n#align spectrum.subset_polynomial_aeval spectrum.subset_polynomial_aeval\n\n/-- The *spectral mapping theorem* for polynomials.  Note: the assumption `degree p > 0`\nis necessary in case `\u03c3 a = \u2205`, for then the left-hand side is `\u2205` and the right-hand side,\nassuming `[nontrivial A]`, is `{k}` where `p = polynomial.C k`. -/\ntheorem map_polynomial_aeval_of_degree_pos [IsAlgClosed \ud835\udd5c] (a : A) (p : \ud835\udd5c[X])\n    (hdeg : 0 < degree p) : \u03c3 (aeval a p) = (fun k => eval k p) '' \u03c3 a :=\n  by\n  -- handle the easy direction via `spectrum.subset_polynomial_aeval`\n  refine' Set.eq_of_subset_of_subset (fun k hk => _) (subset_polynomial_aeval a p)\n  -- write `C k - p` product of linear factors and a constant; show `C k - p \u2260 0`.\n  have hprod := eq_prod_roots_of_splits_id (IsAlgClosed.splits (C k - p))\n  have h_ne : C k - p \u2260 0 :=\n    ne_zero_of_degree_gt\n      (by rwa [degree_sub_eq_right_of_degree_lt (lt_of_le_of_lt degree_C_le hdeg)])\n  have lead_ne := leading_coeff_ne_zero.mpr h_ne\n  have lead_unit := (Units.map \u2191\u2090.toMonoidHom (Units.mk0 _ lead_ne)).IsUnit\n  /- leading coefficient is a unit so product of linear factors is not a unit;\n    apply `exists_mem_of_not_is_unit_aeval_prod`. -/\n  have p_a_eq : aeval a (C k - p) = \u2191\u2090 k - aeval a p := by\n    simp only [aeval_C, AlgHom.map_sub, sub_left_inj]\n  rw [mem_iff, \u2190 p_a_eq, hprod, aeval_mul, ((Commute.all _ _).map (aeval a)).isUnit_mul_iff,\n    aeval_C] at hk\n  replace hk := exists_mem_of_not_is_unit_aeval_prod h_ne (not_and.mp hk lead_unit)\n  rcases hk with \u27e8r, r_mem, r_ev\u27e9\n  exact \u27e8r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)\u27e9\n#align spectrum.map_polynomial_aeval_of_degree_pos spectrum.map_polynomial_aeval_of_degree_pos\n\n/-- In this version of the spectral mapping theorem, we assume the spectrum\nis nonempty instead of assuming the degree of the polynomial is positive. -/\ntheorem map_polynomial_aeval_of_nonempty [IsAlgClosed \ud835\udd5c] (a : A) (p : \ud835\udd5c[X])\n    (hnon : (\u03c3 a).Nonempty) : \u03c3 (aeval a p) = (fun k => eval k p) '' \u03c3 a :=\n  by\n  nontriviality A\n  refine' Or.elim (le_or_gt (degree p) 0) (fun h => _) (map_polynomial_aeval_of_degree_pos a p)\n  \u00b7 rw [eq_C_of_degree_le_zero h]\n    simp only [Set.image_congr, eval_C, aeval_C, scalar_eq, Set.Nonempty.image_const hnon]\n#align spectrum.map_polynomial_aeval_of_nonempty spectrum.map_polynomial_aeval_of_nonempty\n\n/-- A specialization of `spectrum.subset_polynomial_aeval` to monic monomials for convenience. -/\ntheorem pow_image_subset (a : A) (n : \u2115) : (fun x => x ^ n) '' \u03c3 a \u2286 \u03c3 (a ^ n) := by\n  simpa only [eval_pow, eval_X, aeval_X_pow] using subset_polynomial_aeval a (X ^ n : \ud835\udd5c[X])\n#align spectrum.pow_image_subset spectrum.pow_image_subset\n\n/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for\nconvenience. -/\ntheorem map_pow_of_pos [IsAlgClosed \ud835\udd5c] (a : A) {n : \u2115} (hn : 0 < n) :\n    \u03c3 (a ^ n) = (fun x => x ^ n) '' \u03c3 a := by\n  simpa only [aeval_X_pow, eval_pow, eval_X] using\n    map_polynomial_aeval_of_degree_pos a (X ^ n : \ud835\udd5c[X])\n      (by\n        rw_mod_cast [degree_X_pow]\n        exact hn)\n#align spectrum.map_pow_of_pos spectrum.map_pow_of_pos\n\n/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for\nconvenience. -/\ntheorem map_pow_of_nonempty [IsAlgClosed \ud835\udd5c] {a : A} (ha : (\u03c3 a).Nonempty) (n : \u2115) :\n    \u03c3 (a ^ n) = (fun x => x ^ n) '' \u03c3 a := by\n  simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval_of_nonempty a (X ^ n) ha\n#align spectrum.map_pow_of_nonempty spectrum.map_pow_of_nonempty\n\nvariable (\ud835\udd5c)\n\n-- We will use this both to show eigenvalues exist, and to prove Schur's lemma.\n/-- Every element `a` in a nontrivial finite-dimensional algebra `A`\nover an algebraically closed field `\ud835\udd5c` has non-empty spectrum. -/\ntheorem nonempty_of_isAlgClosed_of_finiteDimensional [IsAlgClosed \ud835\udd5c] [Nontrivial A]\n    [I : FiniteDimensional \ud835\udd5c A] (a : A) : \u2203 k : \ud835\udd5c, k \u2208 \u03c3 a :=\n  by\n  obtain \u27e8p, \u27e8h_mon, h_eval_p\u27e9\u27e9 := isIntegral_of_noetherian (IsNoetherian.iff_fg.2 I) a\n  have nu : \u00acIsUnit (aeval a p) := by\n    rw [\u2190 aeval_def] at h_eval_p\n    rw [h_eval_p]\n    simp\n  rw [eq_prod_roots_of_monic_of_splits_id h_mon (IsAlgClosed.splits p)] at nu\n  obtain \u27e8k, hk, _\u27e9 := exists_mem_of_not_is_unit_aeval_prod (monic.ne_zero h_mon) nu\n  exact \u27e8k, hk\u27e9\n#align spectrum.nonempty_of_is_alg_closed_of_finite_dimensional spectrum.nonempty_of_isAlgClosed_of_finiteDimensional\n\nend ScalarField\n\nend spectrum\n\nnamespace AlgHom\n\nsection CommSemiring\n\nvariable {F R A B : Type _} [CommRing R] [Ring A] [Algebra R A] [Ring B] [Algebra R B]\n\nvariable [AlgHomClass F R A B]\n\n-- mathport name: expr\u03c3\nlocal notation \"\u03c3\" => spectrum R\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap R A\n\ntheorem mem_resolventSet_apply (\u03c6 : F) {a : A} {r : R} (h : r \u2208 resolventSet R a) :\n    r \u2208 resolventSet R ((\u03c6 : A \u2192 B) a) := by\n  simpa only [map_sub, AlgHomClass.commutes] using h.map \u03c6\n#align alg_hom.mem_resolvent_set_apply AlgHom.mem_resolventSet_apply\n\ntheorem spectrum_apply_subset (\u03c6 : F) (a : A) : \u03c3 ((\u03c6 : A \u2192 B) a) \u2286 \u03c3 a := fun _ =>\n  mt (mem_resolventSet_apply \u03c6)\n#align alg_hom.spectrum_apply_subset AlgHom.spectrum_apply_subset\n\nend CommSemiring\n\nsection CommRing\n\nvariable {F R A B : Type _} [CommRing R] [Ring A] [Algebra R A] [Ring B] [Algebra R B]\n\nvariable [AlgHomClass F R A R]\n\n-- mathport name: expr\u03c3\nlocal notation \"\u03c3\" => spectrum R\n\n-- mathport name: \u00abexpr\u2191\u2090\u00bb\nlocal notation \"\u2191\u2090\" => algebraMap R A\n\ntheorem apply_mem_spectrum [Nontrivial R] (\u03c6 : F) (a : A) : \u03c6 a \u2208 \u03c3 a :=\n  by\n  have h : \u2191\u2090 (\u03c6 a) - a \u2208 (\u03c6 : A \u2192+* R).ker := by\n    simp only [RingHom.mem_ker, map_sub, RingHom.coe_coe, AlgHomClass.commutes,\n      Algebra.id.map_eq_id, RingHom.id_apply, sub_self]\n  simp only [spectrum.mem_iff, \u2190 mem_nonunits_iff, coe_subset_nonunits (\u03c6 : A \u2192+* R).ker_ne_top h]\n#align alg_hom.apply_mem_spectrum AlgHom.apply_mem_spectrum\n\nend CommRing\n\nend AlgHom\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Algebra/Spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.73804738965239}}
{"text": "/-  Math40001 : Introduction to university mathematics.\n\nProblem Sheet 2, October 2020.\n\nThis is a Lean file. It can be read with the Lean theorem prover.\n\nYou can work on this file online via the link at\nhttps://github.com/ImperialCollegeLondon/M40001_lean/blob/master/README.md\n\n\nor you can install Lean and its maths library following the\ninstructions at\nhttps://leanprover-community.github.io/get_started.html\n\nand then just clone the project onto your own computer\nwith `leanproject get ImperialCollegeLondon/M40001_lean`.\n\nThere are advantages to installing Lean on your own computer\n(for example it's faster), but it's more hassle than\njust using it online.\n\nIn the below, delete \"sorry\" and replace it with some\ntactics which prove the result.\n\n-/\n\nimport data.real.basic -- need real numbers for Q5\n\n-- Q1 prove that \u2229 is symmetric\nlemma question1 (\u03b1 : Type) (X Y : set \u03b1) : X \u2229 Y = Y \u2229 X :=\nbegin\n  sorry\nend\n\n-- question 2 defs\ndef A := {x : \u211d | x ^ 2 < 3}\ndef B := {x : \u211d | \u2203 n : \u2124, x = n \u2227 x ^ 2 < 3}\ndef C := {x : \u211d | x ^ 3 < 3}\n\n-- Change _true to _false and put a \u00ac in front\n-- of the goal if you think it's false.\n-- e.g. if you think 2c is false then don't\n-- try to prove it's true, try proving\n-- lemma question2c_false : \u00ac (A \u2286 C) := ...\n\n-- Some of these are tricky for Lean beginners.\n\nlemma question2a_true : (1 : \u211d)/2 \u2208 A \u2229 B :=\nbegin\n  sorry\nend\n\nlemma question2b_true : (1 : \u211d)/2 \u2208 A \u222a B :=\nbegin\n  sorry\nend\n\nlemma question2c_true : A \u2286 C :=\nbegin\n  sorry\nend\n\nlemma question2d_true : B \u2286 C :=\nbegin\n  sorry\nend\n\nlemma question2e_true : C \u2286 A \u222a B :=\nbegin\n  sorry\nend\n\nlemma question2f_true : (A \u2229 B) \u222a C = (A \u222a B) \u2229 C :=\nbegin\n  sorry\nend\n\n-- Q3 set-up\nvariables (X Y : Type)\nvariable (P : X \u2192 Prop)\nvariable (Q : X \u2192 Prop)\nvariable (R : X \u2192 Y \u2192 Prop)\n\n-- for Q3 you're going to have to change the right hand\n-- side of the \u2194 in the statement\n-- of the lemma to the answer you think is correct.\n\nlemma question3a : \u00ac (\u2200 x : X, P x \u2227 \u00ac Q x) \u2194 true := -- change `true`!\nbegin\n  sorry\nend\n\nlemma question3b : \u00ac (\u2203 x : X, (\u00ac P x) \u2227 Q x) \u2194 true := -- change `true`!\nbegin\n  sorry\nend\n\nlemma question3c : \u00ac (\u2200 x : X, \u2203 y : Y, R x y) \u2194 true := -- change `true`!\nbegin\n  sorry\nend\n\nexample (f : \u211d \u2192 \u211d) (x : \u211d) :\n  \u00ac (\u2200 \u03b5 : \u211d, \u03b5 > 0 \u2192 \u2203 \u03b4 : \u211d, \u03b4 > 0 \u2227 \u2200 y : \u211d, abs (y - x) < \u03b4 \u2192 abs (f y -f x) < \u03b5 )\n\u2194 -- change next line to what you think the answer is\ntrue :=\nbegin\n  sorry\nend\n\n-- change _true to _false in 4a, 4b if you think the opposite is true\n-- and stick a `\u00ac` in front of it\nlemma question4a_true : \u2200 x : \u211d, \u2203 y : \u211d, x + y = 2 :=\nbegin\n  sorry\nend\n\nlemma question4b_true : \u2203 y : \u211d, \u2200 x : \u211d, x + y = 2 :=\nbegin\n  sorry\nend \n\n-- similarly for Q5 -- change _true to _false and add in a negation if you \n-- want to prove that the proposition in the question is false.\nlemma question5a_true : \u2203 x \u2208 (\u2205 : set \u2115), 2 + 2 = 5 :=\nbegin\n  sorry\nend\n\nlemma question5b_true : \u2200 x \u2208 (\u2205 : set \u2115), 2 + 2 = 5 :=\nbegin\n  sorry\nend \n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/problem_sheets/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181874, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7380184931811015}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\nThe integers, with addition, multiplication, and subtraction.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.basic\nimport Mathlib.algebra.order_functions\nimport Mathlib.PostPort\n\nuniverses u_1 u \n\nnamespace Mathlib\n\nnamespace int\n\n\nprotected instance inhabited : Inhabited \u2124 := { default := int.zero }\n\nprotected instance nontrivial : nontrivial \u2124 :=\n  nontrivial.mk (Exists.intro 0 (Exists.intro 1 int.zero_ne_one))\n\nprotected instance comm_ring : comm_ring \u2124 :=\n  comm_ring.mk int.add int.add_assoc int.zero int.zero_add int.add_zero int.neg int.sub\n    int.add_left_neg int.add_comm int.mul int.mul_assoc int.one int.one_mul int.mul_one\n    int.distrib_left int.distrib_right int.mul_comm\n\n/-! ### Extra instances to short-circuit type class resolution -/\n\n-- instance : has_sub int            := by apply_instance -- This is in core\n\nprotected instance add_comm_monoid : add_comm_monoid \u2124 := add_comm_group.to_add_comm_monoid \u2124\n\nprotected instance add_monoid : add_monoid \u2124 := sub_neg_monoid.to_add_monoid \u2124\n\nprotected instance monoid : monoid \u2124 := ring.to_monoid \u2124\n\nprotected instance comm_monoid : comm_monoid \u2124 := comm_semiring.to_comm_monoid \u2124\n\nprotected instance comm_semigroup : comm_semigroup \u2124 := comm_ring.to_comm_semigroup \u2124\n\nprotected instance semigroup : semigroup \u2124 := monoid.to_semigroup \u2124\n\nprotected instance add_comm_semigroup : add_comm_semigroup \u2124 :=\n  add_comm_monoid.to_add_comm_semigroup \u2124\n\nprotected instance add_semigroup : add_semigroup \u2124 := add_monoid.to_add_semigroup \u2124\n\nprotected instance comm_semiring : comm_semiring \u2124 := comm_ring.to_comm_semiring\n\nprotected instance semiring : semiring \u2124 := ring.to_semiring\n\nprotected instance ring : ring \u2124 := comm_ring.to_ring \u2124\n\nprotected instance distrib : distrib \u2124 := ring.to_distrib \u2124\n\nprotected instance linear_ordered_comm_ring : linear_ordered_comm_ring \u2124 :=\n  linear_ordered_comm_ring.mk comm_ring.add comm_ring.add_assoc comm_ring.zero comm_ring.zero_add\n    comm_ring.add_zero comm_ring.neg comm_ring.sub comm_ring.add_left_neg comm_ring.add_comm\n    comm_ring.mul comm_ring.mul_assoc comm_ring.one comm_ring.one_mul comm_ring.mul_one\n    comm_ring.left_distrib comm_ring.right_distrib linear_order.le linear_order.lt\n    linear_order.le_refl linear_order.le_trans linear_order.le_antisymm int.add_le_add_left sorry\n    int.mul_pos linear_order.le_total linear_order.decidable_le linear_order.decidable_eq\n    linear_order.decidable_lt nontrivial.exists_pair_ne comm_ring.mul_comm\n\nprotected instance linear_ordered_add_comm_group : linear_ordered_add_comm_group \u2124 :=\n  linear_ordered_ring.to_linear_ordered_add_comm_group\n\ntheorem abs_eq_nat_abs (a : \u2124) : abs a = \u2191(nat_abs a) :=\n  int.cases_on a (fun (a : \u2115) => idRhs (abs \u2191a = \u2191a) (abs_of_nonneg (coe_zero_le a)))\n    fun (a : \u2115) =>\n      idRhs (abs (Int.negSucc a) = -Int.negSucc a) (abs_of_nonpos (le_of_lt (neg_succ_lt_zero a)))\n\ntheorem nat_abs_abs (a : \u2124) : nat_abs (abs a) = nat_abs a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs (abs a) = nat_abs a)) (abs_eq_nat_abs a)))\n    (Eq.refl (nat_abs \u2191(nat_abs a)))\n\ntheorem sign_mul_abs (a : \u2124) : sign a * abs a = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (sign a * abs a = a)) (abs_eq_nat_abs a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (sign a * \u2191(nat_abs a) = a)) (sign_mul_nat_abs a)))\n      (Eq.refl a))\n\n@[simp] theorem default_eq_zero : Inhabited.default = 0 := rfl\n\n@[simp] theorem add_def {a : \u2124} {b : \u2124} : int.add a b = a + b := rfl\n\n@[simp] theorem mul_def {a : \u2124} {b : \u2124} : int.mul a b = a * b := rfl\n\n@[simp] theorem coe_nat_mul_neg_succ (m : \u2115) (n : \u2115) : \u2191m * Int.negSucc n = -(\u2191m * \u2191(Nat.succ n)) :=\n  rfl\n\n@[simp] theorem neg_succ_mul_coe_nat (m : \u2115) (n : \u2115) : Int.negSucc m * \u2191n = -(\u2191(Nat.succ m) * \u2191n) :=\n  rfl\n\n@[simp] theorem neg_succ_mul_neg_succ (m : \u2115) (n : \u2115) :\n    Int.negSucc m * Int.negSucc n = \u2191(Nat.succ m) * \u2191(Nat.succ n) :=\n  rfl\n\n@[simp] theorem coe_nat_le {m : \u2115} {n : \u2115} : \u2191m \u2264 \u2191n \u2194 m \u2264 n := coe_nat_le_coe_nat_iff m n\n\n@[simp] theorem coe_nat_lt {m : \u2115} {n : \u2115} : \u2191m < \u2191n \u2194 m < n := coe_nat_lt_coe_nat_iff m n\n\n@[simp] theorem coe_nat_inj' {m : \u2115} {n : \u2115} : \u2191m = \u2191n \u2194 m = n := int.coe_nat_eq_coe_nat_iff m n\n\n@[simp] theorem coe_nat_pos {n : \u2115} : 0 < \u2191n \u2194 0 < n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 < \u2191n \u2194 0 < n)) (Eq.symm int.coe_nat_zero)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u21910 < \u2191n \u2194 0 < n)) (propext coe_nat_lt))) (iff.refl (0 < n)))\n\n@[simp] theorem coe_nat_eq_zero {n : \u2115} : \u2191n = 0 \u2194 n = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191n = 0 \u2194 n = 0)) (Eq.symm int.coe_nat_zero)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191n = \u21910 \u2194 n = 0)) (propext coe_nat_inj'))) (iff.refl (n = 0)))\n\ntheorem coe_nat_ne_zero {n : \u2115} : \u2191n \u2260 0 \u2194 n \u2260 0 := not_congr coe_nat_eq_zero\n\n@[simp] theorem coe_nat_nonneg (n : \u2115) : 0 \u2264 \u2191n := iff.mpr coe_nat_le (nat.zero_le n)\n\ntheorem coe_nat_ne_zero_iff_pos {n : \u2115} : \u2191n \u2260 0 \u2194 0 < n :=\n  { mp := fun (h : \u2191n \u2260 0) => nat.pos_of_ne_zero (iff.mp coe_nat_ne_zero h),\n    mpr := fun (h : 0 < n) => ne.symm (ne_of_lt (iff.mpr coe_nat_lt h)) }\n\ntheorem coe_nat_succ_pos (n : \u2115) : 0 < \u2191(Nat.succ n) := iff.mpr coe_nat_pos (nat.succ_pos n)\n\n@[simp] theorem coe_nat_abs (n : \u2115) : abs \u2191n = \u2191n := abs_of_nonneg (coe_nat_nonneg n)\n\n/-! ### succ and pred -/\n\n/-- Immediate successor of an integer: `succ n = n + 1` -/\ndef succ (a : \u2124) : \u2124 := a + 1\n\n/-- Immediate predecessor of an integer: `pred n = n - 1` -/\ndef pred (a : \u2124) : \u2124 := a - 1\n\ntheorem nat_succ_eq_int_succ (n : \u2115) : \u2191(Nat.succ n) = succ \u2191n := rfl\n\ntheorem pred_succ (a : \u2124) : pred (succ a) = a := add_sub_cancel a 1\n\ntheorem succ_pred (a : \u2124) : succ (pred a) = a := sub_add_cancel a 1\n\ntheorem neg_succ (a : \u2124) : -succ a = pred (-a) := neg_add a 1\n\ntheorem succ_neg_succ (a : \u2124) : succ (-succ a) = -a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (succ (-succ a) = -a)) (neg_succ a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (succ (pred (-a)) = -a)) (succ_pred (-a)))) (Eq.refl (-a)))\n\ntheorem neg_pred (a : \u2124) : -pred a = succ (-a) :=\n  eq.mpr\n    (id (Eq._oldrec (Eq.refl (-pred a = succ (-a))) (eq_neg_of_eq_neg (Eq.symm (neg_succ (-a))))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-pred a = -pred ( --a))) (neg_neg a))) (Eq.refl (-pred a)))\n\ntheorem pred_neg_pred (a : \u2124) : pred (-pred a) = -a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (pred (-pred a) = -a)) (neg_pred a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (pred (succ (-a)) = -a)) (pred_succ (-a)))) (Eq.refl (-a)))\n\ntheorem pred_nat_succ (n : \u2115) : pred \u2191(Nat.succ n) = \u2191n := pred_succ \u2191n\n\ntheorem neg_nat_succ (n : \u2115) : -\u2191(Nat.succ n) = pred (-\u2191n) := neg_succ \u2191n\n\ntheorem succ_neg_nat_succ (n : \u2115) : succ (-\u2191(Nat.succ n)) = -\u2191n := succ_neg_succ \u2191n\n\ntheorem lt_succ_self (a : \u2124) : a < succ a := lt_add_of_pos_right a zero_lt_one\n\ntheorem pred_self_lt (a : \u2124) : pred a < a := sub_lt_self a zero_lt_one\n\ntheorem add_one_le_iff {a : \u2124} {b : \u2124} : a + 1 \u2264 b \u2194 a < b := iff.rfl\n\ntheorem lt_add_one_iff {a : \u2124} {b : \u2124} : a < b + 1 \u2194 a \u2264 b := add_le_add_iff_right 1\n\ntheorem le_add_one {a : \u2124} {b : \u2124} (h : a \u2264 b) : a \u2264 b + 1 := le_of_lt (iff.mpr lt_add_one_iff h)\n\ntheorem sub_one_lt_iff {a : \u2124} {b : \u2124} : a - 1 < b \u2194 a \u2264 b :=\n  iff.trans sub_lt_iff_lt_add lt_add_one_iff\n\ntheorem le_sub_one_iff {a : \u2124} {b : \u2124} : a \u2264 b - 1 \u2194 a < b := le_sub_iff_add_le\n\nprotected theorem induction_on {p : \u2124 \u2192 Prop} (i : \u2124) (hz : p 0) (hp : \u2200 (i : \u2115), p \u2191i \u2192 p (\u2191i + 1))\n    (hn : \u2200 (i : \u2115), p (-\u2191i) \u2192 p (-\u2191i - 1)) : p i :=\n  sorry\n\n/-- Inductively define a function on `\u2124` by defining it at `b`, for the `succ` of a number greater\n  than `b`, and the `pred` of a number less than `b`. -/\nprotected def induction_on' {C : \u2124 \u2192 Sort u_1} (z : \u2124) (b : \u2124) :\n    C b \u2192 ((k : \u2124) \u2192 b \u2264 k \u2192 C k \u2192 C (k + 1)) \u2192 ((k : \u2124) \u2192 k \u2264 b \u2192 C k \u2192 C (k - 1)) \u2192 C z :=\n  fun (H0 : C b) (Hs : (k : \u2124) \u2192 b \u2264 k \u2192 C k \u2192 C (k + 1))\n    (Hp : (k : \u2124) \u2192 k \u2264 b \u2192 C k \u2192 C (k - 1)) =>\n    eq.mpr sorry\n      (Int.rec\n        (fun (n : \u2115) =>\n          Nat.rec (eq.mpr sorry (eq.mpr sorry H0))\n            (fun (n : \u2115) (ih : C (Int.ofNat n + b)) =>\n              eq.mpr sorry\n                (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (Hs (Int.ofNat n + b) sorry ih)))))\n            n)\n        (fun (n : \u2115) =>\n          Nat.rec\n            (eq.mpr sorry\n              (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (Hp b sorry H0))))))\n            (fun (n : \u2115) (ih : C (Int.negSucc n + b)) =>\n              eq.mpr sorry\n                (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (Hp (Int.negSucc n + b) sorry ih)))))\n            n)\n        (z - b))\n\n/-! ### nat abs -/\n\ntheorem nat_abs_add_le (a : \u2124) (b : \u2124) : nat_abs (a + b) \u2264 nat_abs a + nat_abs b := sorry\n\ntheorem nat_abs_neg_of_nat (n : \u2115) : nat_abs (neg_of_nat n) = n :=\n  nat.cases_on n (Eq.refl (nat_abs (neg_of_nat 0)))\n    fun (n : \u2115) => Eq.refl (nat_abs (neg_of_nat (Nat.succ n)))\n\ntheorem nat_abs_mul (a : \u2124) (b : \u2124) : nat_abs (a * b) = nat_abs a * nat_abs b := sorry\n\ntheorem nat_abs_mul_nat_abs_eq {a : \u2124} {b : \u2124} {c : \u2115} (h : a * b = \u2191c) :\n    nat_abs a * nat_abs b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a * nat_abs b = c)) (Eq.symm (nat_abs_mul a b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs (a * b) = c)) h))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs \u2191c = c)) (nat_abs_of_nat c))) (Eq.refl c)))\n\n@[simp] theorem nat_abs_mul_self' (a : \u2124) : \u2191(nat_abs a) * \u2191(nat_abs a) = a * a :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (\u2191(nat_abs a) * \u2191(nat_abs a) = a * a))\n        (Eq.symm (int.coe_nat_mul (nat_abs a) (nat_abs a)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(nat_abs a * nat_abs a) = a * a)) nat_abs_mul_self))\n      (Eq.refl (a * a)))\n\ntheorem neg_succ_of_nat_eq' (m : \u2115) : Int.negSucc m = -\u2191m - 1 := sorry\n\ntheorem nat_abs_ne_zero_of_ne_zero {z : \u2124} (hz : z \u2260 0) : nat_abs z \u2260 0 :=\n  fun (h : nat_abs z = 0) => hz (eq_zero_of_nat_abs_eq_zero h)\n\n@[simp] theorem nat_abs_eq_zero {a : \u2124} : nat_abs a = 0 \u2194 a = 0 :=\n  { mp := eq_zero_of_nat_abs_eq_zero, mpr := fun (h : a = 0) => Eq.symm h \u25b8 rfl }\n\ntheorem nat_abs_lt_nat_abs_of_nonneg_of_lt {a : \u2124} {b : \u2124} (w\u2081 : 0 \u2264 a) (w\u2082 : a < b) :\n    nat_abs a < nat_abs b :=\n  sorry\n\ntheorem nat_abs_eq_iff_mul_self_eq {a : \u2124} {b : \u2124} : nat_abs a = nat_abs b \u2194 a * a = b * b := sorry\n\ntheorem nat_abs_lt_iff_mul_self_lt {a : \u2124} {b : \u2124} : nat_abs a < nat_abs b \u2194 a * a < b * b := sorry\n\ntheorem nat_abs_le_iff_mul_self_le {a : \u2124} {b : \u2124} : nat_abs a \u2264 nat_abs b \u2194 a * a \u2264 b * b := sorry\n\ntheorem nat_abs_eq_iff_sq_eq {a : \u2124} {b : \u2124} : nat_abs a = nat_abs b \u2194 a ^ bit0 1 = b ^ bit0 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a = nat_abs b \u2194 a ^ bit0 1 = b ^ bit0 1)) (pow_two a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a = nat_abs b \u2194 a * a = b ^ bit0 1)) (pow_two b)))\n      nat_abs_eq_iff_mul_self_eq)\n\ntheorem nat_abs_lt_iff_sq_lt {a : \u2124} {b : \u2124} : nat_abs a < nat_abs b \u2194 a ^ bit0 1 < b ^ bit0 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a < nat_abs b \u2194 a ^ bit0 1 < b ^ bit0 1)) (pow_two a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a < nat_abs b \u2194 a * a < b ^ bit0 1)) (pow_two b)))\n      nat_abs_lt_iff_mul_self_lt)\n\ntheorem nat_abs_le_iff_sq_le {a : \u2124} {b : \u2124} : nat_abs a \u2264 nat_abs b \u2194 a ^ bit0 1 \u2264 b ^ bit0 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a \u2264 nat_abs b \u2194 a ^ bit0 1 \u2264 b ^ bit0 1)) (pow_two a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a \u2264 nat_abs b \u2194 a * a \u2264 b ^ bit0 1)) (pow_two b)))\n      nat_abs_le_iff_mul_self_le)\n\n/-! ### `/`  -/\n\n@[simp] theorem of_nat_div (m : \u2115) (n : \u2115) : Int.ofNat (m / n) = Int.ofNat m / Int.ofNat n := rfl\n\n@[simp] theorem coe_nat_div (m : \u2115) (n : \u2115) : \u2191(m / n) = \u2191m / \u2191n := rfl\n\ntheorem neg_succ_of_nat_div (m : \u2115) {b : \u2124} (H : 0 < b) : Int.negSucc m / b = -(\u2191m / b + 1) := sorry\n\n@[simp] protected theorem div_neg (a : \u2124) (b : \u2124) : a / -b = -(a / b) := sorry\n\ntheorem div_of_neg_of_pos {a : \u2124} {b : \u2124} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) :=\n  sorry\n\nprotected theorem div_nonneg {a : \u2124} {b : \u2124} (Ha : 0 \u2264 a) (Hb : 0 \u2264 b) : 0 \u2264 a / b := sorry\n\nprotected theorem div_nonpos {a : \u2124} {b : \u2124} (Ha : 0 \u2264 a) (Hb : b \u2264 0) : a / b \u2264 0 :=\n  nonpos_of_neg_nonneg\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 -(a / b))) (Eq.symm (int.div_neg a b))))\n      (int.div_nonneg Ha (neg_nonneg_of_nonpos Hb)))\n\ntheorem div_neg' {a : \u2124} {b : \u2124} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 := sorry\n\n-- Will be generalized to Euclidean domains.\n\nprotected theorem zero_div (b : \u2124) : 0 / b = 0 :=\n  int.cases_on b\n    (fun (b : \u2115) =>\n      nat.cases_on b (idRhs (0 / 0 = 0 / 0) rfl)\n        fun (b : \u2115) => idRhs (0 / \u2191(b + 1) = 0 / \u2191(b + 1)) rfl)\n    fun (b : \u2115) => idRhs (0 / Int.negSucc b = 0 / Int.negSucc b) rfl\n\nprotected theorem div_zero (a : \u2124) : a / 0 = 0 :=\n  int.cases_on a\n    (fun (a : \u2115) =>\n      nat.cases_on a (idRhs (0 / 0 = 0 / 0) rfl)\n        fun (a : \u2115) => idRhs (\u2191(a + 1) / 0 = \u2191(a + 1) / 0) rfl)\n    fun (a : \u2115) => idRhs (Int.negSucc a / 0 = Int.negSucc a / 0) rfl\n\n@[simp] protected theorem div_one (a : \u2124) : a / 1 = a := sorry\n\ntheorem div_eq_zero_of_lt {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : a < b) : a / b = 0 := sorry\n\ntheorem div_eq_zero_of_lt_abs {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : a < abs b) : a / b = 0 := sorry\n\nprotected theorem add_mul_div_right (a : \u2124) (b : \u2124) {c : \u2124} (H : c \u2260 0) :\n    (a + b * c) / c = a / c + b :=\n  sorry\n\nprotected theorem add_mul_div_left (a : \u2124) {b : \u2124} (c : \u2124) (H : b \u2260 0) :\n    (a + b * c) / b = a / b + c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b * c) / b = a / b + c)) (mul_comm b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a + c * b) / b = a / b + c)) (int.add_mul_div_right a c H)))\n      (Eq.refl (a / b + c)))\n\nprotected theorem add_div_of_dvd_right {a : \u2124} {b : \u2124} {c : \u2124} (H : c \u2223 b) :\n    (a + b) / c = a / c + b / c :=\n  sorry\n\nprotected theorem add_div_of_dvd_left {a : \u2124} {b : \u2124} {c : \u2124} (H : c \u2223 a) :\n    (a + b) / c = a / c + b / c :=\n  sorry\n\n@[simp] protected theorem mul_div_cancel (a : \u2124) {b : \u2124} (H : b \u2260 0) : a * b / b = a :=\n  eq.mp (Eq._oldrec (Eq.refl (a * b / b = 0 + a)) (zero_add a))\n    (eq.mp (Eq._oldrec (Eq.refl (a * b / b = 0 / b + a)) (int.zero_div b))\n      (eq.mp (Eq._oldrec (Eq.refl ((0 + a * b) / b = 0 / b + a)) (zero_add (a * b)))\n        (int.add_mul_div_right 0 a H)))\n\n@[simp] protected theorem mul_div_cancel_left {a : \u2124} (b : \u2124) (H : a \u2260 0) : a * b / a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b / a = b)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / a = b)) (int.mul_div_cancel b H))) (Eq.refl b))\n\n@[simp] protected theorem div_self {a : \u2124} (H : a \u2260 0) : a / a = 1 :=\n  eq.mp (Eq._oldrec (Eq.refl (1 * a / a = 1)) (one_mul a)) (int.mul_div_cancel 1 H)\n\n/-! ### mod -/\n\ntheorem of_nat_mod (m : \u2115) (n : \u2115) : \u2191m % \u2191n = Int.ofNat (m % n) := rfl\n\n@[simp] theorem coe_nat_mod (m : \u2115) (n : \u2115) : \u2191(m % n) = \u2191m % \u2191n := rfl\n\ntheorem neg_succ_of_nat_mod (m : \u2115) {b : \u2124} (bpos : 0 < b) : Int.negSucc m % b = b - 1 - \u2191m % b :=\n  sorry\n\n@[simp] theorem mod_neg (a : \u2124) (b : \u2124) : a % -b = a % b := sorry\n\n@[simp] theorem mod_abs (a : \u2124) (b : \u2124) : a % abs b = a % b :=\n  abs_by_cases (fun (i : \u2124) => a % i = a % b) rfl (mod_neg a b)\n\ntheorem zero_mod (b : \u2124) : 0 % b = 0 := congr_arg Int.ofNat (nat.zero_mod (nat_abs b))\n\ntheorem mod_zero (a : \u2124) : a % 0 = a :=\n  int.cases_on a\n    (fun (a : \u2115) => idRhs (Int.ofNat (a % 0) = Int.ofNat a) (congr_arg Int.ofNat (nat.mod_zero a)))\n    fun (a : \u2115) =>\n      idRhs (Int.negSucc (a % 0) = Int.negSucc a) (congr_arg Int.negSucc (nat.mod_zero a))\n\ntheorem mod_one (a : \u2124) : a % 1 = 0 := sorry\n\ntheorem mod_eq_of_lt {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : a < b) : a % b = a := sorry\n\ntheorem mod_nonneg (a : \u2124) {b : \u2124} : b \u2260 0 \u2192 0 \u2264 a % b := sorry\n\ntheorem mod_lt_of_pos (a : \u2124) {b : \u2124} (H : 0 < b) : a % b < b := sorry\n\ntheorem mod_lt (a : \u2124) {b : \u2124} (H : b \u2260 0) : a % b < abs b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a % b < abs b)) (Eq.symm (mod_abs a b))))\n    (mod_lt_of_pos a (iff.mpr abs_pos H))\n\ntheorem mod_add_div_aux (m : \u2115) (n : \u2115) :\n    \u2191n - (\u2191m % \u2191n + 1) - (\u2191n * (\u2191m / \u2191n) + \u2191n) = Int.negSucc m :=\n  sorry\n\ntheorem mod_add_div (a : \u2124) (b : \u2124) : a % b + b * (a / b) = a := sorry\n\ntheorem div_add_mod (a : \u2124) (b : \u2124) : b * (a / b) + a % b = a :=\n  Eq.trans (add_comm (b * (a / b)) (a % b)) (mod_add_div a b)\n\ntheorem mod_def (a : \u2124) (b : \u2124) : a % b = a - b * (a / b) := eq_sub_of_add_eq (mod_add_div a b)\n\n@[simp] theorem add_mul_mod_self {a : \u2124} {b : \u2124} {c : \u2124} : (a + b * c) % c = a % c := sorry\n\n@[simp] theorem add_mul_mod_self_left (a : \u2124) (b : \u2124) (c : \u2124) : (a + b * c) % b = a % b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b * c) % b = a % b)) (mul_comm b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a + c * b) % b = a % b)) add_mul_mod_self))\n      (Eq.refl (a % b)))\n\n@[simp] theorem add_mod_self {a : \u2124} {b : \u2124} : (a + b) % b = a % b :=\n  eq.mp (Eq._oldrec (Eq.refl ((a + b * 1) % b = a % b)) (mul_one b)) (add_mul_mod_self_left a b 1)\n\n@[simp] theorem add_mod_self_left {a : \u2124} {b : \u2124} : (a + b) % a = b % a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b) % a = b % a)) (add_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((b + a) % a = b % a)) add_mod_self)) (Eq.refl (b % a)))\n\n@[simp] theorem mod_add_mod (m : \u2124) (n : \u2124) (k : \u2124) : (m % n + k) % n = (m + k) % n := sorry\n\n@[simp] theorem add_mod_mod (m : \u2124) (n : \u2124) (k : \u2124) : (m + n % k) % k = (m + n) % k :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((m + n % k) % k = (m + n) % k)) (add_comm m (n % k))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((n % k + m) % k = (m + n) % k)) (mod_add_mod n k m)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((n + m) % k = (m + n) % k)) (add_comm n m)))\n        (Eq.refl ((m + n) % k))))\n\ntheorem add_mod (a : \u2124) (b : \u2124) (n : \u2124) : (a + b) % n = (a % n + b % n) % n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b) % n = (a % n + b % n) % n)) (add_mod_mod (a % n) b n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a + b) % n = (a % n + b) % n)) (mod_add_mod a n b)))\n      (Eq.refl ((a + b) % n)))\n\ntheorem add_mod_eq_add_mod_right {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) (H : m % n = k % n) :\n    (m + i) % n = (k + i) % n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((m + i) % n = (k + i) % n)) (Eq.symm (mod_add_mod m n i))))\n    (eq.mpr\n      (id (Eq._oldrec (Eq.refl ((m % n + i) % n = (k + i) % n)) (Eq.symm (mod_add_mod k n i))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((m % n + i) % n = (k % n + i) % n)) H))\n        (Eq.refl ((k % n + i) % n))))\n\ntheorem add_mod_eq_add_mod_left {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) (H : m % n = k % n) :\n    (i + m) % n = (i + k) % n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((i + m) % n = (i + k) % n)) (add_comm i m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((m + i) % n = (i + k) % n)) (add_mod_eq_add_mod_right i H)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((k + i) % n = (i + k) % n)) (add_comm k i)))\n        (Eq.refl ((i + k) % n))))\n\ntheorem mod_add_cancel_right {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) :\n    (m + i) % n = (k + i) % n \u2194 m % n = k % n :=\n  sorry\n\ntheorem mod_add_cancel_left {m : \u2124} {n : \u2124} {k : \u2124} {i : \u2124} :\n    (i + m) % n = (i + k) % n \u2194 m % n = k % n :=\n  sorry\n\ntheorem mod_sub_cancel_right {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) :\n    (m - i) % n = (k - i) % n \u2194 m % n = k % n :=\n  mod_add_cancel_right (-i)\n\ntheorem mod_eq_mod_iff_mod_sub_eq_zero {m : \u2124} {n : \u2124} {k : \u2124} : m % n = k % n \u2194 (m - k) % n = 0 :=\n  sorry\n\n@[simp] theorem mul_mod_left (a : \u2124) (b : \u2124) : a * b % b = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b % b = 0)) (Eq.symm (zero_add (a * b)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((0 + a * b) % b = 0)) add_mul_mod_self))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 % b = 0)) (zero_mod b))) (Eq.refl 0)))\n\n@[simp] theorem mul_mod_right (a : \u2124) (b : \u2124) : a * b % a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b % a = 0)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a % a = 0)) (mul_mod_left b a))) (Eq.refl 0))\n\ntheorem mul_mod (a : \u2124) (b : \u2124) (n : \u2124) : a * b % n = a % n * (b % n) % n := sorry\n\n@[simp] theorem neg_mod_two (i : \u2124) : -i % bit0 1 = i % bit0 1 := sorry\n\ntheorem mod_self {a : \u2124} : a % a = 0 :=\n  eq.mp (Eq._oldrec (Eq.refl (1 * a % a = 0)) (one_mul a)) (mul_mod_left 1 a)\n\n@[simp] theorem mod_mod_of_dvd (n : \u2124) {m : \u2124} {k : \u2124} (h : m \u2223 k) : n % k % m = n % m := sorry\n\n@[simp] theorem mod_mod (a : \u2124) (b : \u2124) : a % b % b = a % b := sorry\n\ntheorem sub_mod (a : \u2124) (b : \u2124) (n : \u2124) : (a - b) % n = (a % n - b % n) % n := sorry\n\n/-! ### properties of `/` and `%` -/\n\n@[simp] theorem mul_div_mul_of_pos {a : \u2124} (b : \u2124) (c : \u2124) (H : 0 < a) : a * b / (a * c) = b / c :=\n  sorry\n\n@[simp] theorem mul_div_mul_of_pos_left (a : \u2124) {b : \u2124} (c : \u2124) (H : 0 < b) :\n    a * b / (c * b) = a / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b / (c * b) = a / c)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / (c * b) = a / c)) (mul_comm c b)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / (b * c) = a / c)) (mul_div_mul_of_pos a c H)))\n        (Eq.refl (a / c))))\n\n@[simp] theorem mul_mod_mul_of_pos {a : \u2124} (b : \u2124) (c : \u2124) (H : 0 < a) :\n    a * b % (a * c) = a * (b % c) :=\n  sorry\n\ntheorem lt_div_add_one_mul_self (a : \u2124) {b : \u2124} (H : 0 < b) : a < (a / b + 1) * b := sorry\n\ntheorem abs_div_le_abs (a : \u2124) (b : \u2124) : abs (a / b) \u2264 abs a := sorry\n\ntheorem div_le_self {a : \u2124} (b : \u2124) (Ha : 0 \u2264 a) : a / b \u2264 a :=\n  eq.mp (Eq._oldrec (Eq.refl (a / b \u2264 abs a)) (abs_of_nonneg Ha))\n    (le_trans (le_abs_self (a / b)) (abs_div_le_abs a b))\n\ntheorem mul_div_cancel_of_mod_eq_zero {a : \u2124} {b : \u2124} (H : a % b = 0) : b * (a / b) = a :=\n  eq.mp (Eq._oldrec (Eq.refl (0 + b * (a / b) = a)) (zero_add (b * (a / b))))\n    (eq.mp (Eq._oldrec (Eq.refl (a % b + b * (a / b) = a)) H) (mod_add_div a b))\n\ntheorem div_mul_cancel_of_mod_eq_zero {a : \u2124} {b : \u2124} (H : a % b = 0) : a / b * b = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b * b = a)) (mul_comm (a / b) b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * (a / b) = a)) (mul_div_cancel_of_mod_eq_zero H)))\n      (Eq.refl a))\n\ntheorem mod_two_eq_zero_or_one (n : \u2124) : n % bit0 1 = 0 \u2228 n % bit0 1 = 1 := sorry\n\n/-! ### dvd -/\n\ntheorem coe_nat_dvd {m : \u2115} {n : \u2115} : \u2191m \u2223 \u2191n \u2194 m \u2223 n := sorry\n\ntheorem coe_nat_dvd_left {n : \u2115} {z : \u2124} : \u2191n \u2223 z \u2194 n \u2223 nat_abs z := sorry\n\ntheorem coe_nat_dvd_right {n : \u2115} {z : \u2124} : z \u2223 \u2191n \u2194 nat_abs z \u2223 n := sorry\n\ntheorem dvd_antisymm {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : 0 \u2264 b) : a \u2223 b \u2192 b \u2223 a \u2192 a = b := sorry\n\ntheorem dvd_of_mod_eq_zero {a : \u2124} {b : \u2124} (H : b % a = 0) : a \u2223 b :=\n  Exists.intro (b / a) (Eq.symm (mul_div_cancel_of_mod_eq_zero H))\n\ntheorem mod_eq_zero_of_dvd {a : \u2124} {b : \u2124} : a \u2223 b \u2192 b % a = 0 := sorry\n\ntheorem dvd_iff_mod_eq_zero (a : \u2124) (b : \u2124) : a \u2223 b \u2194 b % a = 0 :=\n  { mp := mod_eq_zero_of_dvd, mpr := dvd_of_mod_eq_zero }\n\n/-- If `a % b = c` then `b` divides `a - c`. -/\ntheorem dvd_sub_of_mod_eq {a : \u2124} {b : \u2124} {c : \u2124} (h : a % b = c) : b \u2223 a - c := sorry\n\ntheorem nat_abs_dvd {a : \u2124} {b : \u2124} : \u2191(nat_abs a) \u2223 b \u2194 a \u2223 b := sorry\n\ntheorem dvd_nat_abs {a : \u2124} {b : \u2124} : a \u2223 \u2191(nat_abs b) \u2194 a \u2223 b := sorry\n\nprotected instance decidable_dvd : DecidableRel has_dvd.dvd :=\n  fun (a n : \u2124) => decidable_of_decidable_of_iff (int.decidable_eq (n % a) 0) sorry\n\nprotected theorem div_mul_cancel {a : \u2124} {b : \u2124} (H : b \u2223 a) : a / b * b = a :=\n  div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H)\n\nprotected theorem mul_div_cancel' {a : \u2124} {b : \u2124} (H : a \u2223 b) : a * (b / a) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b / a) = b)) (mul_comm a (b / a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b / a * a = b)) (int.div_mul_cancel H))) (Eq.refl b))\n\nprotected theorem mul_div_assoc (a : \u2124) {b : \u2124} {c : \u2124} : c \u2223 b \u2192 a * b / c = a * (b / c) := sorry\n\nprotected theorem mul_div_assoc' (b : \u2124) {a : \u2124} {c : \u2124} (h : c \u2223 a) : a * b / c = a / c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b / c = a / c * b)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / c = a / c * b)) (int.mul_div_assoc b h)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b * (a / c) = a / c * b)) (mul_comm b (a / c))))\n        (Eq.refl (a / c * b))))\n\ntheorem div_dvd_div {a : \u2124} {b : \u2124} {c : \u2124} (H1 : a \u2223 b) (H2 : b \u2223 c) : b / a \u2223 c / a := sorry\n\nprotected theorem eq_mul_of_div_eq_right {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2223 a) (H2 : a / b = c) :\n    a = b * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b * c)) (Eq.symm H2)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * (a / b))) (int.mul_div_cancel' H1))) (Eq.refl a))\n\nprotected theorem div_eq_of_eq_mul_right {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2260 0) (H2 : a = b * c) :\n    a / b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b = c)) H2))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * c / b = c)) (int.mul_div_cancel_left c H1))) (Eq.refl c))\n\nprotected theorem eq_div_of_mul_eq_right {a : \u2124} {b : \u2124} {c : \u2124} (H1 : a \u2260 0) (H2 : a * b = c) :\n    b = c / a :=\n  Eq.symm (int.div_eq_of_eq_mul_right H1 (Eq.symm H2))\n\nprotected theorem div_eq_iff_eq_mul_right {a : \u2124} {b : \u2124} {c : \u2124} (H : b \u2260 0) (H' : b \u2223 a) :\n    a / b = c \u2194 a = b * c :=\n  { mp := int.eq_mul_of_div_eq_right H', mpr := int.div_eq_of_eq_mul_right H }\n\nprotected theorem div_eq_iff_eq_mul_left {a : \u2124} {b : \u2124} {c : \u2124} (H : b \u2260 0) (H' : b \u2223 a) :\n    a / b = c \u2194 a = c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b = c \u2194 a = c * b)) (mul_comm c b)))\n    (int.div_eq_iff_eq_mul_right H H')\n\nprotected theorem eq_mul_of_div_eq_left {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2223 a) (H2 : a / b = c) :\n    a = c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = c * b)) (mul_comm c b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * c)) (int.eq_mul_of_div_eq_right H1 H2)))\n      (Eq.refl (b * c)))\n\nprotected theorem div_eq_of_eq_mul_left {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2260 0) (H2 : a = c * b) :\n    a / b = c :=\n  int.div_eq_of_eq_mul_right H1\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * c)) (mul_comm b c)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a = c * b)) H2)) (Eq.refl (c * b))))\n\ntheorem neg_div_of_dvd {a : \u2124} {b : \u2124} (H : b \u2223 a) : -a / b = -(a / b) := sorry\n\ntheorem sub_div_of_dvd {a : \u2124} {b : \u2124} {c : \u2124} (hcb : c \u2223 b) : (a - b) / c = a / c - b / c := sorry\n\ntheorem sub_div_of_dvd_sub {a : \u2124} {b : \u2124} {c : \u2124} (hcab : c \u2223 a - b) :\n    (a - b) / c = a / c - b / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a - b) / c = a / c - b / c)) (propext eq_sub_iff_add_eq)))\n    (eq.mpr\n      (id\n        (Eq._oldrec (Eq.refl ((a - b) / c + b / c = a / c))\n          (Eq.symm (int.add_div_of_dvd_left hcab))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((a - b + b) / c = a / c)) (sub_add_cancel a b)))\n        (Eq.refl (a / c))))\n\ntheorem div_sign (a : \u2124) (b : \u2124) : a / sign b = a * sign b := sorry\n\n@[simp] theorem sign_mul (a : \u2124) (b : \u2124) : sign (a * b) = sign a * sign b := sorry\n\nprotected theorem sign_eq_div_abs (a : \u2124) : sign a = a / abs a := sorry\n\ntheorem mul_sign (i : \u2124) : i * sign i = \u2191(nat_abs i) := sorry\n\ntheorem le_of_dvd {a : \u2124} {b : \u2124} (bpos : 0 < b) (H : a \u2223 b) : a \u2264 b := sorry\n\ntheorem eq_one_of_dvd_one {a : \u2124} (H : 0 \u2264 a) (H' : a \u2223 1) : a = 1 := sorry\n\ntheorem eq_one_of_mul_eq_one_right {a : \u2124} {b : \u2124} (H : 0 \u2264 a) (H' : a * b = 1) : a = 1 :=\n  eq_one_of_dvd_one H (Exists.intro b (Eq.symm H'))\n\ntheorem eq_one_of_mul_eq_one_left {a : \u2124} {b : \u2124} (H : 0 \u2264 b) (H' : a * b = 1) : b = 1 :=\n  eq_one_of_mul_eq_one_right H\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a = 1)) (mul_comm b a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a * b = 1)) H')) (Eq.refl 1)))\n\ntheorem of_nat_dvd_of_dvd_nat_abs {a : \u2115} {z : \u2124} (haz : a \u2223 nat_abs z) : \u2191a \u2223 z := sorry\n\ntheorem dvd_nat_abs_of_of_nat_dvd {a : \u2115} {z : \u2124} (haz : \u2191a \u2223 z) : a \u2223 nat_abs z := sorry\n\ntheorem pow_dvd_of_le_of_pow_dvd {p : \u2115} {m : \u2115} {n : \u2115} {k : \u2124} (hmn : m \u2264 n)\n    (hdiv : \u2191(p ^ n) \u2223 k) : \u2191(p ^ m) \u2223 k :=\n  sorry\n\ntheorem dvd_of_pow_dvd {p : \u2115} {k : \u2115} {m : \u2124} (hk : 1 \u2264 k) (hpk : \u2191(p ^ k) \u2223 m) : \u2191p \u2223 m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191p \u2223 m)) (Eq.symm (pow_one p))))\n    (pow_dvd_of_le_of_pow_dvd hk hpk)\n\n/-- If `n > 0` then `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)`\n  for some `k`. -/\ntheorem exists_lt_and_lt_iff_not_dvd (m : \u2124) {n : \u2124} (hn : 0 < n) :\n    (\u2203 (k : \u2124), n * k < m \u2227 m < n * (k + 1)) \u2194 \u00acn \u2223 m :=\n  sorry\n\n/-! ### `/` and ordering -/\n\nprotected theorem div_mul_le (a : \u2124) {b : \u2124} (H : b \u2260 0) : a / b * b \u2264 a :=\n  le_of_sub_nonneg\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 a - a / b * b)) (mul_comm (a / b) b)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 a - b * (a / b))) (Eq.symm (mod_def a b))))\n        (mod_nonneg a H)))\n\nprotected theorem div_le_of_le_mul {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H' : a \u2264 b * c) :\n    a / c \u2264 b :=\n  le_of_mul_le_mul_right (le_trans (int.div_mul_le a (ne_of_gt H)) H') H\n\nprotected theorem mul_lt_of_lt_div {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H3 : a < b / c) :\n    a * c < b :=\n  lt_of_not_ge (mt (int.div_le_of_le_mul H) (not_le_of_gt H3))\n\nprotected theorem mul_le_of_le_div {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 < c) (H2 : a \u2264 b / c) :\n    a * c \u2264 b :=\n  le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le b (ne_of_gt H1))\n\nprotected theorem le_div_of_mul_le {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 < c) (H2 : a * c \u2264 b) :\n    a \u2264 b / c :=\n  le_of_lt_add_one\n    (lt_of_mul_lt_mul_right (lt_of_le_of_lt H2 (lt_div_add_one_mul_self b H1)) (le_of_lt H1))\n\nprotected theorem le_div_iff_mul_le {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) : a \u2264 b / c \u2194 a * c \u2264 b :=\n  { mp := int.mul_le_of_le_div H, mpr := int.le_div_of_mul_le H }\n\nprotected theorem div_le_div {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H' : a \u2264 b) : a / c \u2264 b / c :=\n  int.le_div_of_mul_le H (le_trans (int.div_mul_le a (ne_of_gt H)) H')\n\nprotected theorem div_lt_of_lt_mul {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H' : a < b * c) :\n    a / c < b :=\n  lt_of_not_ge (mt (int.mul_le_of_le_div H) (not_le_of_gt H'))\n\nprotected theorem lt_mul_of_div_lt {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 < c) (H2 : a / c < b) :\n    a < b * c :=\n  lt_of_not_ge (mt (int.le_div_of_mul_le H1) (not_le_of_gt H2))\n\nprotected theorem div_lt_iff_lt_mul {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) : a / c < b \u2194 a < b * c :=\n  { mp := int.lt_mul_of_div_lt H, mpr := int.div_lt_of_lt_mul H }\n\nprotected theorem le_mul_of_div_le {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 a)\n    (H3 : a / b \u2264 c) : a \u2264 c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 c * b)) (Eq.symm (int.div_mul_cancel H2))))\n    (mul_le_mul_of_nonneg_right H3 H1)\n\nprotected theorem lt_div_of_mul_lt {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 c)\n    (H3 : a * b < c) : a < c / b :=\n  lt_of_not_ge (mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3))\n\nprotected theorem lt_div_iff_mul_lt {a : \u2124} {b : \u2124} (c : \u2124) (H : 0 < c) (H' : c \u2223 b) :\n    a < b / c \u2194 a * c < b :=\n  { mp := int.mul_lt_of_lt_div H, mpr := int.lt_div_of_mul_lt (le_of_lt H) H' }\n\ntheorem div_pos_of_pos_of_dvd {a : \u2124} {b : \u2124} (H1 : 0 < a) (H2 : 0 \u2264 b) (H3 : b \u2223 a) : 0 < a / b :=\n  int.lt_div_of_mul_lt H2 H3 (eq.mpr (id (Eq._oldrec (Eq.refl (0 * b < a)) (zero_mul b))) H1)\n\ntheorem div_eq_div_of_mul_eq_mul {a : \u2124} {b : \u2124} {c : \u2124} {d : \u2124} (H2 : d \u2223 c) (H3 : b \u2260 0)\n    (H4 : d \u2260 0) (H5 : a * d = b * c) : a / b = c / d :=\n  int.div_eq_of_eq_mul_right H3\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * (c / d))) (Eq.symm (int.mul_div_assoc b H2))))\n      (Eq.symm (int.div_eq_of_eq_mul_left H4 (Eq.symm H5))))\n\ntheorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a : \u2124} {b : \u2124} {c : \u2124} {d : \u2124} (hb : b \u2260 0)\n    (hbc : b \u2223 c) (h : b * a = c * d) : a = c / b * d :=\n  sorry\n\n/-- If an integer with larger absolute value divides an integer, it is\nzero. -/\ntheorem eq_zero_of_dvd_of_nat_abs_lt_nat_abs {a : \u2124} {b : \u2124} (w : a \u2223 b)\n    (h : nat_abs b < nat_abs a) : b = 0 :=\n  sorry\n\ntheorem eq_zero_of_dvd_of_nonneg_of_lt {a : \u2124} {b : \u2124} (w\u2081 : 0 \u2264 a) (w\u2082 : a < b) (h : b \u2223 a) :\n    a = 0 :=\n  eq_zero_of_dvd_of_nat_abs_lt_nat_abs h (nat_abs_lt_nat_abs_of_nonneg_of_lt w\u2081 w\u2082)\n\n/-- If two integers are congruent to a sufficiently large modulus,\nthey are equal. -/\ntheorem eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs {a : \u2124} {b : \u2124} {c : \u2124} (h1 : a % b = c)\n    (h2 : nat_abs (a - c) < nat_abs b) : a = c :=\n  eq_of_sub_eq_zero (eq_zero_of_dvd_of_nat_abs_lt_nat_abs (dvd_sub_of_mod_eq h1) h2)\n\ntheorem of_nat_add_neg_succ_of_nat_of_lt {m : \u2115} {n : \u2115} (h : m < Nat.succ n) :\n    Int.ofNat m + Int.negSucc n = Int.negSucc (n - m) :=\n  sorry\n\ntheorem of_nat_add_neg_succ_of_nat_of_ge {m : \u2115} {n : \u2115} (h : Nat.succ n \u2264 m) :\n    Int.ofNat m + Int.negSucc n = Int.ofNat (m - Nat.succ n) :=\n  sorry\n\n@[simp] theorem neg_add_neg (m : \u2115) (n : \u2115) :\n    Int.negSucc m + Int.negSucc n = Int.negSucc (Nat.succ (m + n)) :=\n  rfl\n\n/-! ### to_nat -/\n\ntheorem to_nat_eq_max (a : \u2124) : \u2191(to_nat a) = max a 0 :=\n  int.cases_on a (fun (a : \u2115) => idRhs (\u2191a = max (\u2191a) 0) (Eq.symm (max_eq_left (coe_zero_le a))))\n    fun (a : \u2115) =>\n      idRhs (0 = max (Int.negSucc a) 0) (Eq.symm (max_eq_right (le_of_lt (neg_succ_lt_zero a))))\n\n@[simp] theorem to_nat_zero : to_nat 0 = 0 := rfl\n\n@[simp] theorem to_nat_one : to_nat 1 = 1 := rfl\n\n@[simp] theorem to_nat_of_nonneg {a : \u2124} (h : 0 \u2264 a) : \u2191(to_nat a) = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(to_nat a) = a)) (to_nat_eq_max a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (max a 0 = a)) (max_eq_left h))) (Eq.refl a))\n\n@[simp] theorem to_nat_sub_of_le (a : \u2124) (b : \u2124) (h : b \u2264 a) : \u2191(to_nat (a + -b)) = a + -b :=\n  to_nat_of_nonneg (sub_nonneg_of_le h)\n\n@[simp] theorem to_nat_coe_nat (n : \u2115) : to_nat \u2191n = n := rfl\n\n@[simp] theorem to_nat_coe_nat_add_one {n : \u2115} : to_nat (\u2191n + 1) = n + 1 := rfl\n\ntheorem le_to_nat (a : \u2124) : a \u2264 \u2191(to_nat a) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 \u2191(to_nat a))) (to_nat_eq_max a))) (le_max_left a 0)\n\n@[simp] theorem to_nat_le {a : \u2124} {n : \u2115} : to_nat a \u2264 n \u2194 a \u2264 \u2191n :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (to_nat a \u2264 n \u2194 a \u2264 \u2191n))\n        (propext (iff.symm (coe_nat_le_coe_nat_iff (to_nat a) n)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(to_nat a) \u2264 \u2191n \u2194 a \u2264 \u2191n)) (to_nat_eq_max a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (max a 0 \u2264 \u2191n \u2194 a \u2264 \u2191n)) (propext max_le_iff)))\n        (and_iff_left (coe_zero_le n))))\n\n@[simp] theorem lt_to_nat {n : \u2115} {a : \u2124} : n < to_nat a \u2194 \u2191n < a :=\n  iff.mp le_iff_le_iff_lt_iff_lt to_nat_le\n\ntheorem to_nat_le_to_nat {a : \u2124} {b : \u2124} (h : a \u2264 b) : to_nat a \u2264 to_nat b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (to_nat a \u2264 to_nat b)) (propext to_nat_le)))\n    (le_trans h (le_to_nat b))\n\ntheorem to_nat_lt_to_nat {a : \u2124} {b : \u2124} (hb : 0 < b) : to_nat a < to_nat b \u2194 a < b := sorry\n\ntheorem lt_of_to_nat_lt {a : \u2124} {b : \u2124} (h : to_nat a < to_nat b) : a < b :=\n  iff.mp (to_nat_lt_to_nat (iff.mp lt_to_nat (lt_of_le_of_lt (nat.zero_le (to_nat a)) h))) h\n\ntheorem to_nat_add {a : \u2124} {b : \u2124} (ha : 0 \u2264 a) (hb : 0 \u2264 b) :\n    to_nat (a + b) = to_nat a + to_nat b :=\n  sorry\n\ntheorem to_nat_add_one {a : \u2124} (h : 0 \u2264 a) : to_nat (a + 1) = to_nat a + 1 :=\n  to_nat_add h zero_le_one\n\n/-- If `n : \u2115`, then `int.to_nat' n = some n`, if `n : \u2124` is negative, then `int.to_nat' n = none`.\n-/\ndef to_nat' : \u2124 \u2192 Option \u2115 := sorry\n\ntheorem mem_to_nat' (a : \u2124) (n : \u2115) : n \u2208 to_nat' a \u2194 a = \u2191n := sorry\n\ntheorem to_nat_zero_of_neg {z : \u2124} : z < 0 \u2192 to_nat z = 0 := sorry\n\n/-! ### units -/\n\n@[simp] theorem units_nat_abs (u : units \u2124) : nat_abs \u2191u = 1 := sorry\n\ntheorem units_eq_one_or (u : units \u2124) : u = 1 \u2228 u = -1 := sorry\n\ntheorem units_inv_eq_self (u : units \u2124) : u\u207b\u00b9 = u :=\n  or.elim (units_eq_one_or u) (fun (h : u = 1) => Eq.symm h \u25b8 rfl)\n    fun (h : u = -1) => Eq.symm h \u25b8 rfl\n\n@[simp] theorem units_mul_self (u : units \u2124) : u * u = 1 :=\n  or.elim (units_eq_one_or u) (fun (h : u = 1) => Eq.symm h \u25b8 rfl)\n    fun (h : u = -1) => Eq.symm h \u25b8 rfl\n\n-- `units.coe_mul` is a \"wrong turn\" for the simplifier, this undoes it and simplifies further\n\n@[simp] theorem units_coe_mul_self (u : units \u2124) : \u2191u * \u2191u = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191u * \u2191u = 1)) (Eq.symm (units.coe_mul u u))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(u * u) = 1)) (units_mul_self u)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (\u21911 = 1)) units.coe_one)) (Eq.refl 1)))\n\n/-! ### bitwise ops -/\n\n@[simp] theorem bodd_zero : bodd 0 = false := rfl\n\n@[simp] theorem bodd_one : bodd 1 = tt := rfl\n\ntheorem bodd_two : bodd (bit0 1) = false := rfl\n\n@[simp] theorem bodd_coe (n : \u2115) : bodd \u2191n = nat.bodd n := rfl\n\n@[simp] theorem bodd_sub_nat_nat (m : \u2115) (n : \u2115) :\n    bodd (sub_nat_nat m n) = bxor (nat.bodd m) (nat.bodd n) :=\n  sorry\n\n@[simp] theorem bodd_neg_of_nat (n : \u2115) : bodd (neg_of_nat n) = nat.bodd n := sorry\n\n@[simp] theorem bodd_neg (n : \u2124) : bodd (-n) = bodd n := sorry\n\n@[simp] theorem bodd_add (m : \u2124) (n : \u2124) : bodd (m + n) = bxor (bodd m) (bodd n) := sorry\n\n@[simp] theorem bodd_mul (m : \u2124) (n : \u2124) : bodd (m * n) = bodd m && bodd n := sorry\n\ntheorem bodd_add_div2 (n : \u2124) : cond (bodd n) 1 0 + bit0 1 * div2 n = n := sorry\n\ntheorem div2_val (n : \u2124) : div2 n = n / bit0 1 :=\n  int.cases_on n\n    (fun (n : \u2115) =>\n      idRhs (Int.ofNat (nat.div2 n) = Int.ofNat (n / bit0 1))\n        (congr_arg Int.ofNat (nat.div2_val n)))\n    fun (n : \u2115) =>\n      idRhs (Int.negSucc (nat.div2 n) = Int.negSucc (n / bit0 1))\n        (congr_arg Int.negSucc (nat.div2_val n))\n\ntheorem bit0_val (n : \u2124) : bit0 n = bit0 1 * n := Eq.symm (two_mul n)\n\ntheorem bit1_val (n : \u2124) : bit1 n = bit0 1 * n + 1 :=\n  congr_arg (fun (_x : \u2124) => _x + 1) (bit0_val n)\n\ntheorem bit_val (b : Bool) (n : \u2124) : bit b n = bit0 1 * n + cond b 1 0 :=\n  bool.cases_on b (Eq.trans (bit0_val n) (Eq.symm (add_zero (bit0 1 * n)))) (bit1_val n)\n\ntheorem bit_decomp (n : \u2124) : bit (bodd n) (div2 n) = n :=\n  Eq.trans (bit_val (bodd n) (div2 n))\n    (Eq.trans (add_comm (bit0 1 * div2 n) (cond (bodd n) 1 0)) (bodd_add_div2 n))\n\n/-- Defines a function from `\u2124` conditionally, if it is defined for odd and even integers separately\n  using `bit`. -/\ndef bit_cases_on {C : \u2124 \u2192 Sort u} (n : \u2124) (h : (b : Bool) \u2192 (n : \u2124) \u2192 C (bit b n)) : C n :=\n  eq.mpr sorry (h (bodd n) (div2 n))\n\n@[simp] theorem bit_zero : bit false 0 = 0 := rfl\n\n@[simp] theorem bit_coe_nat (b : Bool) (n : \u2115) : bit b \u2191n = \u2191(nat.bit b n) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (bit b \u2191n = \u2191(nat.bit b n))) (bit_val b \u2191n)))\n    (eq.mpr\n      (id (Eq._oldrec (Eq.refl (bit0 1 * \u2191n + cond b 1 0 = \u2191(nat.bit b n))) (nat.bit_val b n)))\n      (bool.cases_on b (Eq.refl (bit0 1 * \u2191n + cond false 1 0))\n        (Eq.refl (bit0 1 * \u2191n + cond tt 1 0))))\n\n@[simp] theorem bit_neg_succ (b : Bool) (n : \u2115) :\n    bit b (Int.negSucc n) = Int.negSucc (nat.bit (!b) n) :=\n  sorry\n\n@[simp] theorem bodd_bit (b : Bool) (n : \u2124) : bodd (bit b n) = b := sorry\n\n@[simp] theorem bodd_bit0 (n : \u2124) : bodd (bit0 n) = false := bodd_bit false n\n\n@[simp] theorem bodd_bit1 (n : \u2124) : bodd (bit1 n) = tt := bodd_bit tt n\n\n@[simp] theorem div2_bit (b : Bool) (n : \u2124) : div2 (bit b n) = n := sorry\n\ntheorem bit0_ne_bit1 (m : \u2124) (n : \u2124) : bit0 m \u2260 bit1 n := sorry\n\ntheorem bit1_ne_bit0 (m : \u2124) (n : \u2124) : bit1 m \u2260 bit0 n := ne.symm (bit0_ne_bit1 n m)\n\ntheorem bit1_ne_zero (m : \u2124) : bit1 m \u2260 0 := sorry\n\n@[simp] theorem test_bit_zero (b : Bool) (n : \u2124) : test_bit (bit b n) 0 = b := sorry\n\n@[simp] theorem test_bit_succ (m : \u2115) (b : Bool) (n : \u2124) :\n    test_bit (bit b n) (Nat.succ m) = test_bit n m :=\n  sorry\n\ntheorem bitwise_or : bitwise bor = lor := sorry\n\ntheorem bitwise_and : bitwise band = land := sorry\n\ntheorem bitwise_diff : (bitwise fun (a b : Bool) => a && !b) = ldiff := sorry\n\ntheorem bitwise_xor : bitwise bxor = lxor := sorry\n\n@[simp] theorem bitwise_bit (f : Bool \u2192 Bool \u2192 Bool) (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) :\n    bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=\n  sorry\n\n@[simp] theorem lor_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) :\n    lor (bit a m) (bit b n) = bit (a || b) (lor m n) :=\n  sorry\n\n@[simp] theorem land_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) :\n    land (bit a m) (bit b n) = bit (a && b) (land m n) :=\n  sorry\n\n@[simp] theorem ldiff_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) :\n    ldiff (bit a m) (bit b n) = bit (a && !b) (ldiff m n) :=\n  sorry\n\n@[simp] theorem lxor_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) :\n    lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) :=\n  sorry\n\n@[simp] theorem lnot_bit (b : Bool) (n : \u2124) : lnot (bit b n) = bit (!b) (lnot n) := sorry\n\n@[simp] theorem test_bit_bitwise (f : Bool \u2192 Bool \u2192 Bool) (m : \u2124) (n : \u2124) (k : \u2115) :\n    test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=\n  sorry\n\n@[simp] theorem test_bit_lor (m : \u2124) (n : \u2124) (k : \u2115) :\n    test_bit (lor m n) k = test_bit m k || test_bit n k :=\n  sorry\n\n@[simp] theorem test_bit_land (m : \u2124) (n : \u2124) (k : \u2115) :\n    test_bit (land m n) k = test_bit m k && test_bit n k :=\n  sorry\n\n@[simp] theorem test_bit_ldiff (m : \u2124) (n : \u2124) (k : \u2115) :\n    test_bit (ldiff m n) k = test_bit m k && !test_bit n k :=\n  sorry\n\n@[simp] theorem test_bit_lxor (m : \u2124) (n : \u2124) (k : \u2115) :\n    test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) :=\n  sorry\n\n@[simp] theorem test_bit_lnot (n : \u2124) (k : \u2115) : test_bit (lnot n) k = !test_bit n k := sorry\n\ntheorem shiftl_add (m : \u2124) (n : \u2115) (k : \u2124) : shiftl m (\u2191n + k) = shiftl (shiftl m \u2191n) k := sorry\n\ntheorem shiftl_sub (m : \u2124) (n : \u2115) (k : \u2124) : shiftl m (\u2191n - k) = shiftr (shiftl m \u2191n) k :=\n  shiftl_add m n (-k)\n\n@[simp] theorem shiftl_neg (m : \u2124) (n : \u2124) : shiftl m (-n) = shiftr m n := rfl\n\n@[simp] theorem shiftr_neg (m : \u2124) (n : \u2124) : shiftr m (-n) = shiftl m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (shiftr m (-n) = shiftl m n)) (Eq.symm (shiftl_neg m (-n)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (shiftl m ( --n) = shiftl m n)) (neg_neg n)))\n      (Eq.refl (shiftl m n)))\n\n@[simp] theorem shiftl_coe_nat (m : \u2115) (n : \u2115) : shiftl \u2191m \u2191n = \u2191(nat.shiftl m n) := rfl\n\n@[simp] theorem shiftr_coe_nat (m : \u2115) (n : \u2115) : shiftr \u2191m \u2191n = \u2191(nat.shiftr m n) :=\n  nat.cases_on n (Eq.refl (shiftr \u2191m \u21910)) fun (n : \u2115) => Eq.refl (shiftr \u2191m \u2191(Nat.succ n))\n\n@[simp] theorem shiftl_neg_succ (m : \u2115) (n : \u2115) :\n    shiftl (Int.negSucc m) \u2191n = Int.negSucc (nat.shiftl' tt m n) :=\n  rfl\n\n@[simp] theorem shiftr_neg_succ (m : \u2115) (n : \u2115) :\n    shiftr (Int.negSucc m) \u2191n = Int.negSucc (nat.shiftr m n) :=\n  nat.cases_on n (Eq.refl (shiftr (Int.negSucc m) \u21910))\n    fun (n : \u2115) => Eq.refl (shiftr (Int.negSucc m) \u2191(Nat.succ n))\n\ntheorem shiftr_add (m : \u2124) (n : \u2115) (k : \u2115) : shiftr m (\u2191n + \u2191k) = shiftr (shiftr m \u2191n) \u2191k := sorry\n\ntheorem shiftl_eq_mul_pow (m : \u2124) (n : \u2115) : shiftl m \u2191n = m * \u2191(bit0 1 ^ n) := sorry\n\ntheorem shiftr_eq_div_pow (m : \u2124) (n : \u2115) : shiftr m \u2191n = m / \u2191(bit0 1 ^ n) := sorry\n\ntheorem one_shiftl (n : \u2115) : shiftl 1 \u2191n = \u2191(bit0 1 ^ n) := congr_arg coe (nat.one_shiftl n)\n\n@[simp] theorem zero_shiftl (n : \u2124) : shiftl 0 n = 0 :=\n  int.cases_on n (fun (n : \u2115) => idRhs (\u2191(nat.shiftl 0 n) = \u21910) (congr_arg coe (nat.zero_shiftl n)))\n    fun (n : \u2115) =>\n      idRhs (\u2191(nat.shiftr 0 (Nat.succ n)) = \u21910) (congr_arg coe (nat.zero_shiftr (Nat.succ n)))\n\n@[simp] theorem zero_shiftr (n : \u2124) : shiftr 0 n = 0 := zero_shiftl (-n)\n\n/-! ### Least upper bound property for integers -/\n\ntheorem exists_least_of_bdd {P : \u2124 \u2192 Prop} (Hbdd : \u2203 (b : \u2124), \u2200 (z : \u2124), P z \u2192 b \u2264 z)\n    (Hinh : \u2203 (z : \u2124), P z) : \u2203 (lb : \u2124), P lb \u2227 \u2200 (z : \u2124), P z \u2192 lb \u2264 z :=\n  sorry\n\ntheorem exists_greatest_of_bdd {P : \u2124 \u2192 Prop} (Hbdd : \u2203 (b : \u2124), \u2200 (z : \u2124), P z \u2192 z \u2264 b)\n    (Hinh : \u2203 (z : \u2124), P z) : \u2203 (ub : \u2124), P ub \u2227 \u2200 (z : \u2124), P z \u2192 z \u2264 ub :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/int/basic_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7380184906656041}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.homology.homotopy\nimport algebra.category.Module.abelian\nimport algebra.category.Module.subobject\nimport category_theory.limits.concrete_category\n\n/-!\n# Complexes of modules\n\nWe provide some additional API to work with homological complexes in `Module R`.\n-/\n\nuniverses v u\n\nopen_locale classical\nnoncomputable theory\n\nopen category_theory category_theory.limits homological_complex\n\nvariables {R : Type v} [ring R]\nvariables {\u03b9 : Type*} {c : complex_shape \u03b9} {C D : homological_complex (Module.{u} R) c}\n\nnamespace Module\n\n/--\nTo prove that two maps out of a homology group are equal,\nit suffices to check they are equal on the images of cycles.\n-/\nlemma homology_ext {L M N K : Module R} {f : L \u27f6 M} {g : M \u27f6 N} (w : f \u226b g = 0)\n  {h k : homology f g w \u27f6 K}\n  (w : \u2200 (x : linear_map.ker g),\n    h (cokernel.\u03c0 (image_to_kernel _ _ w) (to_kernel_subobject x)) =\n      k (cokernel.\u03c0 (image_to_kernel _ _ w) (to_kernel_subobject x))) : h = k :=\nbegin\n  refine cokernel_funext (\u03bb n, _),\n  -- Gosh it would be nice if `equiv_rw` could directly use an isomorphism, or an enriched `\u2243`.\n  equiv_rw (kernel_subobject_iso g \u226a\u226b Module.kernel_iso_ker g).to_linear_equiv.to_equiv at n,\n  convert w n; simp [to_kernel_subobject],\nend\n\n/-- Bundle an element `C.X i` such that `C.d_from i x = 0` as a term of `C.cycles i`. -/\nabbreviation to_cycles {C : homological_complex (Module.{u} R) c}\n  {i : \u03b9} (x : linear_map.ker (C.d_from i)) : C.cycles i :=\nto_kernel_subobject x\n\n@[ext]\nlemma cycles_ext {C : homological_complex (Module.{u} R) c} {i : \u03b9}\n  {x y : C.cycles i} (w : (C.cycles i).arrow x = (C.cycles i).arrow y) : x = y :=\nbegin\n  apply_fun (C.cycles i).arrow using (Module.mono_iff_injective _).mp (cycles C i).arrow_mono,\n  exact w,\nend\n\nlocal attribute [instance] concrete_category.has_coe_to_sort\n\n@[simp] lemma cycles_map_to_cycles (f : C \u27f6 D) {i : \u03b9} (x : linear_map.ker (C.d_from i)) :\n  (cycles_map f i) (to_cycles x) = to_cycles \u27e8f.f i x.1, by simp [x.2]\u27e9 :=\nby { ext, simp, }\n\n/-- Build a term of `C.homology i` from an element `C.X i` such that `C.d_from i x = 0`. -/\nabbreviation to_homology\n  {C : homological_complex (Module.{u} R) c} {i : \u03b9} (x : linear_map.ker (C.d_from i)) :\n  C.homology i :=\nhomology.\u03c0 (C.d_to i) (C.d_from i) _ (to_cycles x)\n\n@[ext]\nlemma homology_ext' {M : Module R} (i : \u03b9) {h k : C.homology i \u27f6 M}\n  (w : \u2200 (x : linear_map.ker (C.d_from i)), h (to_homology x) = k (to_homology x)) :\n  h = k :=\nhomology_ext _ w\n\n/-- We give an alternative proof of `homology_map_eq_of_homotopy`,\nspecialized to the setting of `V = Module R`,\nto demonstrate the use of extensionality lemmas for homology in `Module R`. -/\nexample (f g : C \u27f6 D) (h : homotopy f g) (i : \u03b9) :\n  (homology_functor (Module.{u} R) c i).map f = (homology_functor (Module.{u} R) c i).map g :=\nbegin\n  -- To check that two morphisms out of a homology group agree, it suffices to check on cycles:\n  ext,\n  simp only [homology_functor_map, homology.\u03c0_map_apply],\n  -- To check that two elements are equal mod boundaries, it suffices to exhibit a boundary:\n  ext1,\n  swap, exact (to_prev i h.hom) x.1,\n  -- Moreover, to check that two cycles are equal, it suffices to check their underlying elements:\n  ext1,\n  simp only [map_add, image_to_kernel_arrow_apply, homological_complex.hom.sq_from_left,\n      Module.to_kernel_subobject_arrow, category_theory.limits.kernel_subobject_map_arrow_apply,\n      d_next_eq_d_from_from_next, function.comp_app, zero_add, Module.coe_comp,\n      linear_map.add_apply, map_zero, subtype.val_eq_coe,\n      category_theory.limits.image_subobject_arrow_comp_apply, linear_map.map_coe_ker,\n      prev_d_eq_to_prev_d_to, h.comm i, x.2],\n  abel\nend\n\nend Module\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/homology/Module.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7380184890471719}}
{"text": "import solutions.world2_multiplication\n\nimport mynat.le\n/- Here's what you get from the import:\n\n1) The following data:\n  * a binary relation called mynat.le, and notation a \u2264 b for this relation.\n\n  The definition is: a \u2264 b \u2194 \u2203 c : mynat, b = a + c\n\n2) The following axiom:\n\n  * `le_def (a b : mynat) : a \u2264 b \u2194 \u2203 (c : mynat), b = a + c`\n\nYou can rewrite `le_def`.\n\nIf a goal is of the form `\u2203 c, ...` then to make progress you can use the `use` tactic.\nFor example `use 7` will replace all c's in the goal with 7's.\n-/\n\n\nnamespace mynat\n\n-- example\ntheorem le_refl (a : mynat) : a \u2264 a :=\nbegin\n  rw le_def,\n  use 0,\n  rw add_zero,  \nend\n\nexample : one \u2264 one := le_refl one\n\n-- ignore this; it's making the \"refl\" tactic work with goals of the form a \u2264 a\nattribute [_refl_lemma] le_refl\n\ntheorem le_succ {a b : mynat} (h : a \u2264 b) : a \u2264 (succ b) :=\nbegin\n  sorry\nend\n\n\nlemma zero_le (a : mynat) : 0 \u2264 a :=\nbegin\n  sorry\nend\n\nlemma le_zero {a : mynat} : a \u2264 0 \u2192 a = 0 :=\nbegin\n  sorry\nend\n\ntheorem le_trans \u2983a b c : mynat\u2984 (hab : a \u2264 b) (hbc : b \u2264 c) : a \u2264 c :=\nbegin\n  sorry\nend\n\ninstance : preorder mynat := by structure_helper\n\n-- ignore this, it's the definition.\ntheorem lt_iff_le_not_le {a b : mynat} : a < b \u2194 a \u2264 b \u2227 \u00ac b \u2264 a := iff.rfl\n\ntheorem le_antisymm : \u2200 {{a b : mynat}}, a \u2264 b \u2192 b \u2264 a \u2192 a = b :=\nbegin\n  sorry\nend\n\ninstance : partial_order mynat := by structure_helper\n\ntheorem lt_iff_le_and_ne \u2983a b : mynat\u2984 : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\nbegin\n  sorry\nend\n\n\nlemma succ_le_succ {a b : mynat} (h : a \u2264 b) : succ a \u2264 succ b :=\nbegin\n  sorry\nend\n\ntheorem le_total (a b : mynat) : a \u2264 b \u2228 b \u2264 a :=\nbegin\n  sorry\nend\n\ninstance : linear_order mynat := by structure_helper\n\n\ntheorem add_le_add_right (a b : mynat) : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) :=\nbegin\n  sorry\nend\n\ntheorem le_succ_self (a : mynat) : a \u2264 succ a :=\nbegin\n  sorry\nend\n\ntheorem le_of_succ_le_succ {a b : mynat} : succ a \u2264 succ b \u2192 a \u2264 b :=\nbegin\n  sorry\nend\n\ntheorem not_succ_le_self {{d : mynat}} (h : succ d \u2264 d) : false :=\nbegin\n  sorry\nend\n\ntheorem add_le_add_left : \u2200 (a b : mynat), a \u2264 b \u2192 \u2200 (c : mynat), c + a \u2264 c + b :=\nbegin\n  sorry\nend\n\ndef succ_le_succ_iff (a b : mynat) : succ a \u2264 succ b \u2194 a \u2264 b :=\nbegin\n  sorry\nend\n\ndef succ_lt_succ_iff (a b : mynat) : succ a < succ b \u2194 a < b :=\nbegin\n  sorry\nend\n\ntheorem lt_of_add_lt_add_left : \u2200 {{a b c : mynat}}, a + b < a + c \u2192 b < c :=\nbegin\n  sorry\nend\n\ntheorem le_iff_exists_add : \u2200 (a b : mynat), a \u2264 b \u2194 \u2203 (c : mynat), b = a + c :=\nbegin\n  sorry\nend\n\ntheorem zero_ne_one : (0 : mynat) \u2260 1 :=\nbegin\n  sorry\nend\n\ninstance : ordered_comm_monoid mynat := by structure_helper\n\ntheorem le_of_add_le_add_left \u2983 a b c : mynat\u2984 : a + b \u2264 a + c \u2192 b \u2264 c :=\nbegin\n  sorry\nend\n\ninstance : ordered_cancel_comm_monoid mynat := by structure_helper\n\ntheorem mul_le_mul_of_nonneg_left \u2983a b c : mynat\u2984 : a \u2264 b \u2192 0 \u2264 c \u2192 c * a \u2264 c * b :=\nbegin\n  sorry\nend\n\ntheorem mul_le_mul_of_nonneg_right \u2983a b c : mynat\u2984 : a \u2264 b \u2192 0 \u2264 c \u2192 a * c \u2264 b * c :=\nbegin\n  sorry\nend\n\ntheorem ne_zero_of_pos \u2983a : mynat\u2984 : 0 < a \u2192 a \u2260 0 :=\nbegin\n  sorry\nend\n\ntheorem mul_lt_mul_of_pos_left \u2983a b c : mynat\u2984 : a < b \u2192 0 < c \u2192 c * a < c * b :=\nbegin\n  sorry\nend\n\ntheorem mul_lt_mul_of_pos_right \u2983a b c : mynat\u2984 : a < b \u2192 0 < c \u2192 a * c < b * c :=\nbegin\n  sorry\nend\n\ninstance : ordered_semiring mynat := by structure_helper\n\nlemma lt_irrefl (a : mynat) : \u00ac (a < a) :=\nbegin\n  sorry\nend\n\nend mynat\n", "meta": {"author": "RaitoBezarius", "repo": "projet-maths-lean", "sha": "42356e980e021a20c3468f5ca1639fec01bb934f", "save_path": "github-repos/lean/RaitoBezarius-projet-maths-lean", "path": "github-repos/lean/RaitoBezarius-projet-maths-lean/projet-maths-lean-42356e980e021a20c3468f5ca1639fec01bb934f/Lean Game/world3_le.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7380184840161772}}
{"text": "import ..lectures.love03_forward_proofs_demo\n\n\n/-! # LoVe Exercise 4: Functional Programming -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Reverse of a List\n\nWe define a new accumulator-based version of `reverse`. The first argument,\n`as`, serves as the accumulator. This definition is __tail-recursive__, meaning\nthat compilers and interpreters can easily optimize the recursion away,\nresulting in more efficient code. -/\n\ndef accurev {\u03b1 : Type} : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| as []        := as\n| as (x :: xs) := accurev (x :: as) xs\n\n/-! 1.1. Our intention is that `accurev [] xs` should be equal to `reverse xs`.\nBut if we start an induction, we quickly see that the induction hypothesis is\nnot strong enough. Start by proving the following generalization (using the\n`induction'` tactic or pattern matching): -/\n\nlemma accurev_eq_reverse_append {\u03b1 : Type} :\n  \u2200as xs : list \u03b1, accurev as xs = reverse xs ++ as\n:= sorry\n\n/-! 1.2. Derive the desired equation. -/\n\nlemma accurev_eq_reverse {\u03b1 : Type} (xs : list \u03b1) :\n  accurev [] xs = reverse xs :=\nsorry\n\n/-! 1.3. Prove the following property.\n\nHint: A one-line inductionless proof is possible. -/\n\nlemma accurev_accurev {\u03b1 : Type} (xs : list \u03b1) :\n  accurev [] (accurev [] xs) = xs :=\nsorry\n\n/-! 1.4. Prove the following lemma by structural induction, as a \"paper\" proof.\nThis is a good exercise to develop a deeper understanding of how structural\ninduction works.\n\n    lemma accurev_eq_reverse_append {\u03b1 : Type} :\n      \u2200as xs : list \u03b1, accurev as xs = reverse xs ++ as\n\nGuidelines for paper proofs:\n\nWe expect detailed, rigorous, mathematical proofs. You are welcome to use\nstandard mathematical notation or Lean structured commands (e.g., `assume`,\n`have`, `show`, `calc`). You can also use tactical proofs (e.g., `intro`,\n`apply`), but then please indicate some of the intermediate goals, so that we\ncan follow the chain of reasoning.\n\nMajor proof steps, including applications of induction and invocation of the\ninduction hypothesis, must be stated explicitly. For each case of a proof by\ninduction, you must list the inductive hypotheses assumed (if any) and the goal\nto be proved. Minor proof steps corresponding to `refl`, `simp`, or `cc` need\nnot be justified if you think they are obvious (to humans), but you should say\nwhich key lemmas they depend on. You should be explicit whenever you use a\nfunction definition or an introduction rule for an inductive predicate. -/\n\n-- enter your paper proof here\n\n\n/-! ## Question 2: Drop and Take\n\nThe `drop` function removes the first `n` elements from the front of a list. -/\n\ndef drop {\u03b1 : Type} : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0       xs        := xs\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := drop m xs\n\n/-! 2.1. Define the `take` function, which returns a list consisting of the the\nfirst `n` elements at the front of a list.\n\nTo avoid unpleasant surprises in the proofs, we recommend that you follow the\nsame recursion pattern as for `drop` above. -/\n\ndef take {\u03b1 : Type} : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n:= sorry\n\n#eval take 0 [3, 7, 11]   -- expected: []\n#eval take 1 [3, 7, 11]   -- expected: [3]\n#eval take 2 [3, 7, 11]   -- expected: [3, 7]\n#eval take 3 [3, 7, 11]   -- expected: [3, 7, 11]\n#eval take 4 [3, 7, 11]   -- expected: [3, 7, 11]\n\n#eval take 2 [\"a\", \"b\", \"c\"]   -- expected: [\"a\", \"b\"]\n\n/-! 2.2. Prove the following lemmas, using `induction'` or pattern matching.\nNotice that they are registered as simplification rules thanks to the `@[simp]`\nattribute. -/\n\n@[simp] lemma drop_nil {\u03b1 : Type} :\n  \u2200n : \u2115, drop n ([] : list \u03b1) = []\n:= sorry\n\n@[simp] lemma take_nil {\u03b1 : Type} :\n  \u2200n : \u2115, take n ([] : list \u03b1) = []\n:= sorry\n\n/-! 2.3. Follow the recursion pattern of `drop` and `take` to prove the\nfollowing lemmas. In other words, for each lemma, there should be three cases,\nand the third case will need to invoke the induction hypothesis.\n\nHint: Note that there are three variables in the `drop_drop` lemma (but only two\narguments to `drop`). For the third case, `\u2190add_assoc` might be useful. -/\n\nlemma drop_drop {\u03b1 : Type} :\n  \u2200(m n : \u2115) (xs : list \u03b1), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n-- supply the two missing cases here\n\nlemma take_take {\u03b1 : Type} :\n  \u2200(m : \u2115) (xs : list \u03b1), take m (take m xs) = take m xs\n:= sorry\n\nlemma take_drop {\u03b1 : Type} :\n  \u2200(n : \u2115) (xs : list \u03b1), take n xs ++ drop n xs = xs\n:= sorry\n\n\n/-! ## Question 3: A Type of \u03bb-Terms\n\n3.1. Define an inductive type corresponding to the untyped \u03bb-terms, as given\nby the following context-free grammar:\n\n    term ::= 'var' string        -- variable (e.g., `x`)\n           | 'lam' string term   -- \u03bb-expression (e.g., `\u03bbx, t`)\n           | 'app' term term     -- application (e.g., `t u`) -/\n\n-- enter your definition here\n\n/-! 3.2. Register a textual representation of the type `term` as an instance of\nthe `has_repr` type class. Make sure to supply enough parentheses to guarantee\nthat the output is unambiguous. -/\n\ndef term.repr : term \u2192 string\n-- enter your answer here\n\n@[instance] def term.has_repr : has_repr term :=\n{ repr := term.repr }\n\n/-! 3.3. Test your textual representation. The following command should print\nsomething like `(\u03bbx, ((y x) x))`. -/\n\n#eval (term.lam \"x\" (term.app (term.app (term.var \"y\") (term.var \"x\"))\n    (term.var \"x\")))\n\n\n\n\n/-! ## Question 4: Vectors and Matrices\n\n(Note: this question is long, but good preparation for the last HW problem!)\n\nRecall the type constructor `vec : Type \u2192 nat \u2192 Type` that represents a sequence\nof values of a particular length. -/\n\ninductive vec (\u03b1 : Type) : \u2115 \u2192 Type\n| nil {}                           : vec 0\n| cons (a : \u03b1) {n : \u2115} (v : vec n) : vec (n + 1)\n\n-- We define convenience notation for writing vectors. Note that this notation\n-- cannot be used when pattern-matching.\nlocal notation `V[]` := vec.nil\nlocal notation `V[` l:(foldr `,` (h t, vec.cons h t) vec.nil) `]` := l\n\ndef sample_vector_1 : vec string 0 := V[]\ndef sample_vector_2 : vec \u2115 4 := V[1, 9, 5, 1]\n\nnamespace vec\n\n/-! We can define functions on vectors just as we do on lists and trees. For\ninstance, here's an `append` function on vectors analogous to its counterpart\nfor lists: -/\n\n-- NOTE: the length arguments `m` and `n` must go after the colon (i.e., they\n-- can't be parameters of `vec_map`). We can then simply ignore those arguments\n-- when pattern matching by using `_`, as shown.\ndef append {\u03b1 : Type} : \u2200 {m n : \u2115}, vec \u03b1 m \u2192 vec \u03b1 n \u2192 vec \u03b1 (n + m)\n| _ _ vec.nil ys := ys\n| _ _ (vec.cons x xs) ys := vec.cons x (append xs ys)\n\n/-! 4.1. Implement the function `dot_product` that computes the dot\nproduct of two equal-dimensional (i.e., equal-length in the programmatic sense)\nvectors with integer coordinates (i.e., elements). The dot product of two\nvectors `V[v\u2081, v\u2082, ..., v\u2099]` and `V[w\u2081, w\u2082, ..., w\u2099]` is the number\n`v\u2081 * w\u2081 + v\u2082 * w\u2082 + ... + v\u2099 * w\u2099`, or, more formally, `\u2211_{i=1}^n (v\u1d62 * w\u1d62)`. -/\n\ndef dot_product : \u2200 {n : \u2115}, vec \u2124 n \u2192 vec \u2124 n \u2192 \u2124\n:= sorry\n\n\n\n/-! 4.2. We define the *melding* (a coined term) of two equal-length\nvectors to be the vector formed by applying a combining function to each\ncorresponding pair of elements in the two vectors. For instance, the melding of\n`V[1, 2, 3]` and `V[4, 5, 6]` using the combining function `(+)` would be the\nvector `V[5, 7, 9]`.\n\nImplement a function `meld` that performs this operation. (You'll need to fill\nin both the type and body of the function.)\n-/\n\ndef meld : sorry := sorry\n\n/-! The *product* of two types `\u03b1` and `\u03b2`, denoted `\u03b1 \u00d7 \u03b2`, is the type of\npairs `(a, b)` such that `a : \u03b1` and `b : \u03b2`. (`(a, b)` is syntactic sugar for\n`prod.mk a b`, where `prod.mk : \u2200 {\u03b1 \u03b2 : Type}, \u03b1 \u2192 \u03b2 \u2192 \u03b1 \u00d7 \u03b2`.) -/\n\n#check (1, 2)\n#check prod.mk 1951 \"X\"\n\n/-! 4.3. The *zipping* of two vectors is the vector formed by pairing\ncorresponding elements. For instance, zipping `V[1, 2, 3] : vec \u2115 3` and\n`[\"a\", \"b\", \"c\"] : vec string 3` yields the vector\n`[(1, \"a\"), (2, \"b\"), (3, \"c\")] : vec (\u2115 \u00d7 string) 3`.\n\nUse `meld` to implement `zip`. The only modification you may make to the line\nbelow is to replace `sorry` with a *non-recursive* function. -/\n\n\ndef zip {\u03b1 \u03b2 : Type} {n : \u2115} : vec \u03b1 n \u2192 vec \u03b2 n \u2192 vec (\u03b1 \u00d7 \u03b2) n :=\nmeld sorry\n\n/-! 4.4. Prove the lemma below that says that appending and melding\ncan be done in either order -- that is, that melding the results of appending\ntwo pairs of vectors is the same as appending the result of melding two pairs of\nvectors.\n\nYou may prove your base case however you wish. However, for the inductive\ncase, you must use `calc` mode, and you may only use the following terms in your\nproof (i.e., as \"justifications\" after the `:` in `calc` mode):\n* `rfl`\n* `eq.symm rfl` (this is used for \"stepping backward\" through functions)\n* `by rw [ih]`\n\nYou should, of course, fill in the `ih` declaration with the appropriate\nvariables. -/\n\nlemma meld_append {\u03b1 \u03b2 \u03b3 : Type} : \u2200 {m n : \u2115}\n  (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (vs : vec \u03b1 n) (ws : vec \u03b2 n) (xs : vec \u03b1 m) (ys : vec \u03b2 m),\n    meld f (append vs xs) (append ws ys) =\n    append (meld f vs ws) (meld f xs ys)\n| _ _ f vec.nil vec.nil xs ys :=\n  sorry\n| _ _ f (vec.cons v vs) (vec.cons w ws) xs ys :=\n  have ih : _, from meld_append sorry sorry sorry sorry sorry,\n  sorry\n\n\nend vec\n\n/-! 4.5. Having defined vectors, we now turn our attention to matrices. An\n`r`-by-`c` matrix is a \"grid\" of numerical entries (we'll use the naturals to\nmake things simple) with `r` rows and `c` columns. We can think of them as\nvectors of vectors: either a length-`c` vector of `r`-element column vectors, or\na length-`r` vector of `c`-element row vectors.\n\nFor this problem, we'll use the *row-wise* representation: that is, we'll think\nof matrices as a vector containing row vectors.\n\nFill in the type-level function that defines this type below. That is, `mat r c`\nshould evaluate to the type whose values are row-wise representations of\nmatrices that store natural numbers as their entries. -/\n\ndef mat (r : \u2115) (c : \u2115) : Type :=\nsorry\n\n-- The errors below should disappear if you've defined the type correctly!\n#reduce (V[] : mat 0 0)\n#reduce (V[V[11, 12], V[21, 22], V[31, 32]] : mat 3 2)\n#reduce (V[V[1, 3, 4], V[2, 2, 5]] : mat 2 3)\n\n/-! 4.6. The first type of matrix operation we'll implement is extracting\nsubcomponents. Below, implement the functions `get_row` and `get_col` that,\nrespectively, extract a row or column at a specified index from a matrix.\n\nNotice an interesting feature of these functions: they each take as an argument\na *proof* that the requested row or column index is legal for the given matrix.\nThis allows us to enforce the legality of arguments at the type level.\n\nWe provide two helper functions below that you will likely find helpful. (Hint:\nnotice the second explicit argument to `vec.nth`!) -/\n\ndef vec.map {\u03b1 \u03b2 : Type} : \u2200 {n : \u2115}, (\u03b1 \u2192 \u03b2) \u2192 vec \u03b1 n \u2192 vec \u03b2 n\n| _ _ vec.nil         := vec.nil\n| _ f (vec.cons x xs) := vec.cons (f x) (vec.map f xs)\n\ndef vec.nth {\u03b1 : Type} : \u2200 {n : \u2115} (i : \u2115), i < n \u2192 vec \u03b1 n \u2192 \u03b1\n| _ 0       _ (vec.cons x _)  := x\n| _ (n + 1) h (vec.cons x xs) := vec.nth n (nat.succ_lt_succ_iff.mp h) xs\n| 0 _       h vec.nil         := absurd h dec_trivial\n\nnamespace mat\n\ndef get_row {r c : \u2115} (i : \u2115) (h : i < r) (m : mat r c) : vec \u2115 c :=\nsorry \n\ndef get_col {r c : \u2115} (i : \u2115) (h : i < c) (m : mat r c) : vec \u2115 r :=\nsorry \n\n\n/-! 4.7. Our second matrix operation is addition. Matrix addition proceeds\ncomponent-wise: e.g.,\n\u250c     \u2510    \u250c     \u2510     \u250c         \u2510\n| a b |  + | e f |  =  | a+e b+f |\n| c d |    | g h |     | c+g d+h |\n\u2514     \u2518    \u2514     \u2518     \u2514         \u2518\n\nBelow, implement a function `add` for adding two matrices.\n\nHint: you might find your `vec.zip` function from earlier useful. You also\nremain free to use any vector helper functions you might need. -/\n\ndef add : \u2200 {r c}, mat r c \u2192 mat r c \u2192 mat r c \n:= sorry\n\nend mat\n\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/exercises/love04_functional_programming_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8856314662716159, "lm_q1q2_score": 0.7380184832263882}}
{"text": "/-\nCopyright (c) 2020 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n\n! This file was ported from Lean 3 source module data.set.intervals.infinite\n! leanprover-community/mathlib commit 1f0096e6caa61e9c849ec2adbd227e960e9dff58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Finite\n\n/-!\n# Infinitude of intervals\n\nBounded intervals in dense orders are infinite, as are unbounded intervals\nin orders that are unbounded on the appropriate side. We also prove that an unbounded\npreorder is an infinite type.\n-/\n\n\nvariable {\u03b1 : Type _} [Preorder \u03b1]\n\n/-- A nonempty preorder with no maximal element is infinite. This is not an instance to avoid\na cycle with `Infinite \u03b1 \u2192 Nontrivial \u03b1 \u2192 Nonempty \u03b1`. -/\ntheorem NoMaxOrder.infinite [Nonempty \u03b1] [NoMaxOrder \u03b1] : Infinite \u03b1 :=\n  let \u27e8f, hf\u27e9 := Nat.exists_strictMono \u03b1\n  Infinite.of_injective f hf.injective\n#align no_max_order.infinite NoMaxOrder.infinite\n\n/-- A nonempty preorder with no minimal element is infinite. This is not an instance to avoid\na cycle with `Infinite \u03b1 \u2192 Nontrivial \u03b1 \u2192 Nonempty \u03b1`. -/\ntheorem NoMinOrder.infinite [Nonempty \u03b1] [NoMinOrder \u03b1] : Infinite \u03b1 :=\n  @NoMaxOrder.infinite \u03b1\u1d52\u1d48 _ _ _\n#align no_min_order.infinite NoMinOrder.infinite\n\nnamespace Set\n\nsection DenselyOrdered\n\nvariable [DenselyOrdered \u03b1] {a b : \u03b1} (h : a < b)\n\ntheorem Ioo.infinite : Infinite (Ioo a b) :=\n  @NoMaxOrder.infinite _ _ (nonempty_Ioo_subtype h) _\n#align set.Ioo.infinite Set.Ioo.infinite\n\ntheorem Ioo_infinite : (Ioo a b).Infinite :=\n  infinite_coe_iff.1 <| Ioo.infinite h\n#align set.Ioo_infinite Set.Ioo_infinite\n\ntheorem Ico_infinite : (Ico a b).Infinite :=\n  (Ioo_infinite h).mono Ioo_subset_Ico_self\n#align set.Ico_infinite Set.Ico_infinite\n\ntheorem Ico.infinite : Infinite (Ico a b) :=\n  infinite_coe_iff.2 <| Ico_infinite h\n#align set.Ico.infinite Set.Ico.infinite\n\ntheorem Ioc_infinite : (Ioc a b).Infinite :=\n  (Ioo_infinite h).mono Ioo_subset_Ioc_self\n#align set.Ioc_infinite Set.Ioc_infinite\n\ntheorem Ioc.infinite : Infinite (Ioc a b) :=\n  infinite_coe_iff.2 <| Ioc_infinite h\n#align set.Ioc.infinite Set.Ioc.infinite\n\ntheorem Icc_infinite : (Icc a b).Infinite :=\n  (Ioo_infinite h).mono Ioo_subset_Icc_self\n#align set.Icc_infinite Set.Icc_infinite\n\ntheorem Icc.infinite : Infinite (Icc a b) :=\n  infinite_coe_iff.2 <| Icc_infinite h\n#align set.Icc.infinite Set.Icc.infinite\n\nend DenselyOrdered\n\ninstance [NoMinOrder \u03b1] {a : \u03b1} : Infinite (Iio a) :=\n  NoMinOrder.infinite\n\ntheorem Iio_infinite [NoMinOrder \u03b1] (a : \u03b1) : (Iio a).Infinite :=\n  infinite_coe_iff.1 inferInstance\n#align set.Iio_infinite Set.Iio_infinite\n\ninstance [NoMinOrder \u03b1] {a : \u03b1} : Infinite (Iic a) :=\n  NoMinOrder.infinite\n\ntheorem Iic_infinite [NoMinOrder \u03b1] (a : \u03b1) : (Iic a).Infinite :=\n  infinite_coe_iff.1 inferInstance\n#align set.Iic_infinite Set.Iic_infinite\n\ninstance [NoMaxOrder \u03b1] {a : \u03b1} : Infinite (Ioi a) :=\n  NoMaxOrder.infinite\n\ntheorem Ioi_infinite [NoMaxOrder \u03b1] (a : \u03b1) : (Ioi a).Infinite :=\n  infinite_coe_iff.1 inferInstance\n#align set.Ioi_infinite Set.Ioi_infinite\n\ninstance [NoMaxOrder \u03b1] {a : \u03b1} : Infinite (Ici a) :=\n  NoMaxOrder.infinite\n\ntheorem Ici_infinite [NoMaxOrder \u03b1] (a : \u03b1) : (Ici a).Infinite :=\n  infinite_coe_iff.1 inferInstance\n#align set.Ici_infinite Set.Ici_infinite\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Intervals/Infinite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7380184746367}}
{"text": "import data.nat.basic\nimport data.set.basic\nimport data.real.basic\n\n\n-- ------------------ EXERCICE 1 ------------------\n\nnamespace ex1\n\ntheorem ex_1_1 : \u2200 P:Prop, P \u2192 P := assume P:Prop, assume h:P, show P, from h\n\ntheorem ex_1_2 : \u2200 P Q:Prop, P \u2227 Q \u2192 P \u2228 Q := assume P Q:Prop, assume h:P \u2227 Q, show P \u2228 Q, from or.inl h.left\n\nend ex1\n\n-- ------------------ EXERCICE 2 ------------------\n\nnamespace ex2\n\nvariables {E F G:Type}\n\ndefinition injective  (f: E \u2192 F) : Prop  := \u2200 (u:E), \u2200 (v:E), f u=f v \u2192 u=v\n\ntheorem ex_2_1 : \u2200 f:E\u2192 F, \u2200 g:F\u2192 G, (injective f) \u2227 (injective g) \u2192 (injective (g \u2218 f)) :=\n   assume f:E\u2192 F,\n     assume g:F\u2192 G,\n       assume h1:(injective f) \u2227 (injective g),\n         assume u v :E,\n           assume h2: (g \u2218 f) u =(g \u2218 f) v,\n             have h3 : f u=f v, from h1.right (f u) (f v) h2,\n             show u = v, from h1.left u v h3\n\n\ntheorem ex_2_2 : \u2200 f:E\u2192 F, \u2200 g:F\u2192 G,  injective (g \u2218 f) \u2192 injective f :=\n   assume f:E\u2192 F,\n     assume g:F\u2192 G,\n       assume h1:injective (g \u2218 f),\n         assume u v :E,\n           assume h2: f u =f v,\n             have h3:g (f u) =g (f v), from congr_arg g h2,\n             show u=v, from h1 u v h3\n\nend ex2\n-- ------------------ EXERCICE 3 ------------------\n\nnamespace ex3\n\ndefinition divisible (n p:\u2115) := \u2203k:\u2115 , n=k*p\n\ntheorem  ex_3_2 : \u2200 p m n :\u2115 , (divisible m p)\u2227 (divisible n p) \u2192 (divisible (m+n) p) :=\n   assume p m n : \u2115, \n      assume h: (divisible m p)\u2227 (divisible n p),\n        exists.elim h.left (\n          assume (j:\u2115 )  (h_m: m = j*p),\n          exists.elim h.right (\n            assume (k:\u2115 ) (h_n : n = k*p),\n              exists.intro (j+k) (\n                calc\n                  m+n = j*p+n      : h_m \u25b8 (eq.refl (m+n))      -- congr_arg (\u03bb z, z+n)   h_m  --\n                  ... = j*p+k*p    : h_n \u25b8 (eq.refl (j*p+n))    -- congr_arg (\u03bb z, j*p+z) h_n  --\n                  ... = (j+k)*p    : (right_distrib j k p).symm\n              )\n          )\n        )\n \nend ex3\n\n-- ------------------ EXERCICE 4 ------------------\n\nnamespace ex4\n\ndefinition est_majorant (A:set \u211d) (m:\u211d)  : Prop := \u2200 x:\u211d , x \u2208 A \u2192 x \u2264 m  \ndefinition est_majorant' (A:set \u211d) (m:\u211d) : Prop := \u2200 x\u2208 A, x \u2264 m  \n#print  est_majorant'\n\ndefinition est_pge  (A:set \u211d) (m:\u211d) : Prop := m\u2208A \u2227 (est_majorant A m)\n\ntheorem ex_4_3 : \u2200 (A:set \u211d) (m:\u211d ) (n:\u211d ), (est_pge A m) \u2227 (est_pge A n)\u2192 m=n :=\n  assume  (A:set \u211d) (m:\u211d ) (n:\u211d ),\n    assume (h1: (est_pge A m) \u2227 (est_pge A n)),\n      have h2 : m \u2264 n, from h1.right.right m h1.left.left,\n      have h3 : n \u2264 m, from h1.left.right n h1.right.left, \n      show m=n, from le_antisymm h2 h3\n\nend ex4\n\n-- ------------------ QCM Open ------------------\n \nnamespace qcm_open\n\n  variables {E F G:Type}\n\n  definition injective  (f: E \u2192 F) : Prop  := \u2200 (u:E), \u2200 (v:E), f u = f v  \u2192  u = v\n  definition surjective (f: E \u2192 F) : Prop  := \u2200 (y:F), \u2203 (x:E), y = f x\n\n  theorem interessant : \u2200  (u: E \u2192 F) (v: F \u2192 G), surjective (v \u2218 u) \u2192 (injective v) \u2192 (surjective u) := \n  assume  (u: E \u2192 F) (v: F \u2192 G),\n    assume h1 : surjective (v \u2218 u),\n      assume h2: injective v,\n        assume (y:F),\n          let z:= v y in\n           exists.elim (h1 (z:G))\n           (\n             assume (x:E) (h3: z = (v \u2218 u) x),\n             have h4: v y = v (u x), from h3,\n             exists.intro x (\n               show y = u x, from h2 y (u x) h4\n             )\n           )\n/-\n  Soient E, F, G trois ensembles.\n\n  D\u00e9finition :  Soit f une application de E dans F. On dit que f est injective si et seulement si pour tous u et v dans E, \n  tels que f(u) = f(v), on a u=v.\n\n  D\u00e9finition :  Soit f une application de E dans F. On dit que f est surjective si et seulement si pour tout y dans F, \n  il existe x dans E tel que y=f(x).\n\n  Th\u00e9or\u00e8me : Pour toutes applications u de E dans F et v de F dans F, \n  si v o u est surjective et v est injective alors u est surjective.\n\n  Preuve : Soient u une application de E dans F et v une application de F dans G. \n  On suppose que v o u est surjective, et que v est injective. \n  Soit y appartenant \u00e0 F. (pour satisfaire la d\u00e9finition de surjectivit\u00e9 de u, on cherche x dans E tel que y=u(x))\n  On pose z:= v(y). \n  En appliquant la surjectivit\u00e9 de v o u  \u00e0 z, qui est bien un \u00e9l\u00e9ment de G, on obtient l'existence\n  d'un \u00e9l\u00e9ment x de E tel que z = (v o u) (x).  Ainsi, on a v(y) = v(u(x)).\n  Mais alors ce x convient, puisque l'injectivit\u00e9 de v donne y=u(x).\n\n-/\nend qcm_open", "meta": {"author": "ftranminh", "repo": "Esisar_MA121_HA_lean_2023", "sha": "03020c52868086664944e046386c98f070a15ad2", "save_path": "github-repos/lean/ftranminh-Esisar_MA121_HA_lean_2023", "path": "github-repos/lean/ftranminh-Esisar_MA121_HA_lean_2023/Esisar_MA121_HA_lean_2023-03020c52868086664944e046386c98f070a15ad2/64_epreuve_machine_S1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7379994463897174}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\nimport number_theory.padics.padic_numbers\nimport ring_theory.valuation.integers\nimport topology.metric_space.cau_seq_filter\nimport topology.algebra.valued_field\nimport from_mathlib.spectral_norm_unique\nimport from_mathlib.normed_valued\n\n/-!\n# The `p`-adic complex numbers.\n\nIn this file we define the field `\u2102_[p]` of `p`-adic complex numbers and we give it both a normed \nfield and a valued field structure, induced by the unique extension of the `p`-adic norm to `\u2102_[p]`.\n\n## Main Definitions\n\n* `padic_complex` : the type of `p`-adic complex numbers.\n* `padic_complex_integers` : the ring of integers of `\u2102_[p]`.\n\n\n## Main Results\n\n* `padic_complex.norm_extends` : the norm on `\u2102_[p]` extends the norm on `Q_p_alg p`, and hence\n  the norm on `\u211a_[p]`.\n* `padic_complex.is_nonarchimedean` : The norm on `\u2102_[p]` is nonarchimedean.\n\n\n## Notation\n\nWe introduce the notation `\u2102_[p]` for the `p`-adic complex numbers, and `\ud835\udcde_\u2102_[p]` for its ring of\nintegers.\n\n## Tags\n\np-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion\n-/\n\n\nnoncomputable theory\n\nopen rank_one_valuation\n\nopen_locale nnreal\n\nvariables (p : \u2115) [fact (nat.prime p)]\n\n/-- `Q_p_alg p` is the algebraic closure of `\u211a_[p]`. -/\n@[reducible] def Q_p_alg : Type* := algebraic_closure \u211a_[p]\n\n/-- `Q_p_alg p` is an algebraic extension of `\u211a_[p]`. -/\nlemma Q_p_alg.is_algebraic : algebra.is_algebraic \u211a_[p] (Q_p_alg p) := \nalgebraic_closure.is_algebraic _\n\ninstance : has_coe \u211a_[p] (Q_p_alg p) := \u27e8algebra_map \u211a_[p] (Q_p_alg p)\u27e9\n\nprotected lemma coe_eq : (coe : \u211a_[p] \u2192 (Q_p_alg p)) = algebra_map \u211a_[p] (Q_p_alg p) := rfl\n\nnamespace Q_p_alg\n\n/-- `Q_p_alg p` is a normed field, where the norm is the `p`-adic norm, that is, the spectral norm\ninduced by the `p`-adic norm on `\u211a_[p]`. -/\ninstance normed_field : normed_field (Q_p_alg p) := \n@spectral_norm_to_normed_field \u211a_[p] _ _ _ _ padic.complete_space (Q_p_alg.is_algebraic p) \n  padic_norm_e.nonarchimedean\n\n/-- The norm on `Q_p_alg p` is nonarchimedean. -/\nlemma is_nonarchimedean : is_nonarchimedean (norm : (Q_p_alg p) \u2192 \u211d) :=\nspectral_norm_is_nonarchimedean (Q_p_alg.is_algebraic p) (padic_norm_e.nonarchimedean)\n\n/-- The norm on `Q_p_alg p` is the spectral norm induced by the `p`-adic norm on `\u211a_[p]`. -/\nlemma norm_def (x : Q_p_alg p) : \u2016 x \u2016 = spectral_norm \u211a_[p] (Q_p_alg p) x := rfl\n\n/-- The norm on `Q_p_alg p` extends the `p`-adic norm on `\u211a_[p]`. -/\nlemma Q_p.norm_extends (x : \u211a_[p]) : \u2016 (x : Q_p_alg p) \u2016 = \u2016 x \u2016 := \nspectral_alg_norm_extends (Q_p_alg.is_algebraic p) _ (padic_norm_e.nonarchimedean)\n\n/-- `Q_p_alg p` is a valued field, with the valuation corresponding to the `p`-adic norm. -/\ninstance valued_field : valued (Q_p_alg p) \u211d\u22650 :=\nnormed_field.to_valued (Q_p_alg.is_nonarchimedean p)\n\n/-- The valuation of `x : Q_p_alg p` agrees with its `\u211d\u22650`-valued norm. -/\nlemma v_def (x : Q_p_alg p) : valued.v x = \u2016 x \u2016\u208a := rfl\n\n/-- The coercion of the valuation of `x : Q_p_alg p` to `\u211d` agrees with its norm. -/\nlemma v_def_coe (x : Q_p_alg p) : \n  ((valued.v x : \u211d\u22650) : \u211d) = spectral_norm \u211a_[p] (Q_p_alg p) x := rfl\n\n/-- The valuation of `p : Q_p_alg p` is `1/p`. -/\nlemma valuation_p (p : \u2115) [fact p.prime] : valued.v (p : Q_p_alg p) = 1/(p : \u211d\u22650) :=\nbegin\n  rw [\u2190 map_nat_cast (algebra_map  \u211a_[p] (Q_p_alg p)), \u2190 coe_eq],\n  ext,\n  rw [v_def_coe, coe_eq, spectral_norm_extends,padic_norm_e.norm_p, one_div, nonneg.coe_inv,\n    nnreal.coe_nat_cast],\nend\n\nend Q_p_alg\n\n/-- `\u2102_[p]` is the field of `p`-adic complex numbers, that is, the completion of `Q_p_alg p` with\nrespect to the `p`-adic norm. -/\ndef padic_complex := uniform_space.completion (Q_p_alg p) \n\nnotation `\u2102_[`p`]` := padic_complex p\n\nnamespace padic_complex\n\n/-- The `p`-adic complex numbers have a field structure. -/\ninstance : field \u2102_[p] := uniform_space.completion.field\n\n/-- The `p`-adic complex numbers are inhabited. -/\ninstance : inhabited \u2102_[p] := \u27e80\u27e9\n\n/-- `\u2102_[p]` is a valued field, where the valuation is the one extending that on `Q_p_alg p`. -/\ninstance valued_field : valued (\u2102_[p]) \u211d\u22650 := valued.valued_completion \n\n/-- `\u2102_[p]` is a complete space. -/\ninstance complete_space : complete_space (\u2102_[p]) := uniform_space.completion.complete_space _\n\ninstance : has_coe_t (Q_p_alg p) \u2102_[p] := uniform_space.completion.has_coe_t _\n\n/-- The valuation on `\u2102_[p]` extends the valuation on `Q_p_alg p`. -/\nlemma valuation_extends (x : Q_p_alg p) : valued.v (x : \u2102_[p]) = valued.v x := \nvalued.extension_extends _\n\n/-- `\u2102_[p]` is an algebra over `Q_p_alg p`. -/\ninstance : algebra (Q_p_alg p) \u2102_[p] := uniform_space.completion.algebra' _\n\nlemma coe_eq : (coe : (Q_p_alg p) \u2192 \u2102_[p]) = algebra_map (Q_p_alg p) \u2102_[p] := rfl\n\nlemma coe_zero : ((0 : Q_p_alg p) : \u2102_[p]) = 0 := rfl\n\n/-- The valuation of `p : \u2102_[p]` is `1/p`. -/\nlemma valuation_p (p : \u2115) [fact p.prime] : valued.v (p : \u2102_[p]) = 1/(p : \u211d\u22650) :=\nby rw [\u2190 map_nat_cast (algebra_map _ _), \u2190 coe_eq, valuation_extends, Q_p_alg.valuation_p]\n\n/-- The valuation on `\u2102_[p]` has rank one. -/\ninstance : is_rank_one (padic_complex.valued_field p).v := \n{ hom := monoid_with_zero_hom.id \u211d\u22650,\n  strict_mono := strict_mono_id,\n  nontrivial  := \n  begin\n    use p,\n    haveI hp : nat.prime p := _inst_1.elim,\n    simp only [valuation_p, one_div, ne.def, inv_eq_zero, nat.cast_eq_zero, \n      inv_eq_one, nat.cast_eq_one],\n    exact \u27e8hp.ne_zero, hp.ne_one\u27e9,\n  end }\n\n/-- `\u2102_[p]` is a normed field, where the norm corresponds to the extension of the `p`-adic \n  valuation.-/\ninstance : normed_field \u2102_[p] := valued_field.to_normed_field\n\n/-- The norm on `\u2102_[p]` agrees with the valuation. -/\nlemma norm_def : (norm : \u2102_[p] \u2192 \u211d) = rank_one_valuation.norm_def := rfl\n\n/-- The norm on `\u2102_[p]` extends the norm on `Q_p_alg p`. -/\nlemma norm_extends (x : Q_p_alg p) : \u2016 (x : \u2102_[p]) \u2016 = \u2016 x \u2016 := \nbegin\n  by_cases hx : x = 0,\n  { rw [hx, coe_zero, norm_zero, norm_zero] },\n  { simp only [norm_def, rank_one_valuation.norm_def, valuation_extends, \n      monoid_with_zero_hom.coe_mk], \n    refl }\nend\n\n/-- The `\u211d\u22650`-valued norm on `\u2102_[p]` extends that on `Q_p_alg p`. -/\nlemma nnnorm_extends (x : Q_p_alg p) : \u2016 (x : \u2102_[p]) \u2016\u208a = \u2016 x \u2016\u208a := \nby { ext, exact norm_extends p x }\n\n/-- The norm on `\u2102_[p]` is nonarchimedean. -/\nlemma is_nonarchimedean : is_nonarchimedean (norm : \u2102_[p] \u2192 \u211d) :=\nbegin\n  intros x y,\n  apply uniform_space.completion.induction_on\u2082 x y,\n  { exact is_closed_le (continuous.comp continuous_norm continuous_add) (continuous.max\n      (continuous.comp (@continuous_norm \u2102_[p] _) (continuous.fst continuous_id))\n      (continuous.comp (@continuous_norm \u2102_[p] _) (continuous.snd continuous_id))) },\n  { intros a b,\n    simp only [\u2190 uniform_space.completion.coe_add, norm_extends],\n    exact Q_p_alg.is_nonarchimedean p a b }\nend\n\nend padic_complex\n\n/-- We define `\ud835\udcde_\u2102_[p]` as the subring elements of `\u2102_[p]` with valuation `\u2264 1`. -/\ndef padic_complex_integers : subring \u2102_[p] := (padic_complex.valued_field p).v.integer\n\nnotation `\ud835\udcde_\u2102_[`p`]` := padic_complex_integers p\n\n/-- `\ud835\udcde_\u2102_[p]` is the ring of integers of `\u2102_[p]`. -/\nlemma padic_complex.integers : valuation.integers (padic_complex.valued_field p).v  \ud835\udcde_\u2102_[p] := \nvaluation.integer.integers _", "meta": {"author": "mariainesdff", "repo": "local_class_field_theory", "sha": "ffa8bc00cd45f6bee74e3a5ef7def8678bcee0b0", "save_path": "github-repos/lean/mariainesdff-local_class_field_theory", "path": "github-repos/lean/mariainesdff-local_class_field_theory/local_class_field_theory-ffa8bc00cd45f6bee74e3a5ef7def8678bcee0b0/src/from_mathlib/Cp_def.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7379994439768381}}
{"text": "import monotone limits\n\ntheorem bdd_above_of_is_bounded (f : \u2115 \u2192 \u211d) (hfb : M1P1.is_bounded f) : bdd_above (set.range f) :=\nlet \u27e8M, hm\u27e9 := hfb in \u27e8M, \u03bb y \u27e8n, hn\u27e9, hn \u25b8 (abs_le.1 (hm n)).2\u27e9\n\ntheorem bdd_below_of_is_bounded (f : \u2115 \u2192 \u211d) (hfb : M1P1.is_bounded f) : bdd_below (set.range f) :=\nlet \u27e8M, hm\u27e9 := hfb in \u27e8-M, \u03bb y \u27e8n, hn\u27e9, hn \u25b8 (abs_le.1 (hm n)).1\u27e9\n\ntheorem M1P1.is_bounded.comp {f : \u2115 \u2192 \u211d} (hf : M1P1.is_bounded f) (s : \u2115 \u2192 \u2115) : M1P1.is_bounded (f \u2218 s) :=\nlet \u27e8M, hm\u27e9 := hf in \u27e8M, \u03bb y, hm (s y)\u27e9\n\ntheorem increasing_bounded (f : \u2115 \u2192 \u211d) (hfb : M1P1.is_bounded f) (hfi : increasing f) :\n  M1P1.is_limit f (real.Sup $ set.range f) :=\nbegin\n  intros \u03b5 H\u03b5,\n  have := mt (real.Sup_le_ub (set.range f) \u27e8f 0, 0, rfl\u27e9) (not_le_of_lt $ sub_lt_self _ H\u03b5),\n  classical, simp only [not_forall] at this, rcases this with \u27e8_, \u27e8n, rfl\u27e9, hn\u27e9, use n, intros m hnm,\n  rw abs_sub_lt_iff, split,\n  { rw sub_lt_iff_lt_add', refine lt_of_le_of_lt _ (lt_add_of_pos_right _ H\u03b5),\n    exact real.le_Sup _ (bdd_above_of_is_bounded _ hfb) \u27e8m, rfl\u27e9 },\n  { rw sub_lt, exact lt_of_lt_of_le (not_le.1 hn) (hfi _ _ hnm) }\nend\n\ntheorem decreasing_bounded (f : \u2115 \u2192 \u211d) (hfb : M1P1.is_bounded f) (hfd : decreasing f) :\n  M1P1.is_limit f (real.Inf $ set.range f) :=\nbegin\n  intros \u03b5 H\u03b5,\n  have := mt (real.lb_le_Inf (set.range f) \u27e8f 0, 0, rfl\u27e9) (not_le_of_lt $ lt_add_of_pos_right _ H\u03b5),\n  classical, simp only [not_forall] at this, rcases this with \u27e8_, \u27e8n, rfl\u27e9, hn\u27e9, use n, intros m hnm,\n  rw abs_sub_lt_iff, split,\n  { rw sub_lt_iff_lt_add', exact lt_of_le_of_lt (hfd _ _ hnm) (not_le.1 hn) },\n  { rw sub_lt, refine lt_of_lt_of_le (sub_lt_self _ H\u03b5) _,\n    exact real.Inf_le _ (bdd_below_of_is_bounded _ hfb) \u27e8m, rfl\u27e9 }\nend\n\ntheorem bolzano_weierstrass (f : \u2115 \u2192 \u211d) (hf : M1P1.is_bounded f) : \u2203 s : \u2115 \u2192 \u2115, strictly_increasing s \u2227 M1P1.has_limit (f \u2218 s) :=\nlet \u27e8s, hs1, hs2\u27e9 := exists_monotone f in or.cases_on hs2\n  (\u03bb hsi, \u27e8s, hs1, _, increasing_bounded _ (hf.comp s) (increasing_of_strictly_increasing _ hsi)\u27e9)\n  (\u03bb hsd, \u27e8s, hs1, _, decreasing_bounded _ (hf.comp s) hsd\u27e9)\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1P1-lean", "sha": "3723468cc50f8bebd00a9811caf25224a578de17", "save_path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean", "path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean/M1P1-lean-3723468cc50f8bebd00a9811caf25224a578de17/src/Bolzano_Weierstrass.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7379994367382}}
{"text": "import Mathlib.Tactic.Ring\n\n/- # Proving challenge -/\n\n/- My summing function -/\ndef sum : Nat \u2192 Nat\n  | 0     => 0\n  | n + 1 => n + 1 + sum n\n\n/- The actual proof -/\ntheorem twoTimesSumEqTimesSucc {n : Nat} : 2 * sum n = n * (n + 1) := by\n  induction n with\n    | zero => rfl\n    | succ n hi =>\n      simp only [sum, Nat.mul_add, Nat.add_succ, hi]\n      ring\n\n/-! # Programming challenge -/\n\n/-\nA helper function for the programming challenge.\n\nIt carries over two variables for the computation happening on the current streak:\n`currStreak` and `currSum`. `currStreak` is the length of the current consecutive\nascending sequence and `currSum` is the sum of that sequence.\n\nIt also carries over two variables for the best solution until this point:\n`currMaxStreak` and `currMaxSum`, whose names indicate analogous utilities to the\nother two.\n-/\ndef longestConsecutiveSumAux : List Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat\n  | a::b::t, currStreak, currSum, currMaxStreak, currMaxSum =>\n    if a + 1 \u2260 b then -- breaking the streak\n      longestConsecutiveSumAux (b::t) 0 0 currMaxStreak currMaxSum\n    else\n      if currMaxStreak < currStreak + 1 then -- update highest values\n        longestConsecutiveSumAux (b::t) (currStreak + 1) (a + currSum) \n          (currStreak + 1) (a + b + currSum)\n      else\n        longestConsecutiveSumAux (b::t) (currStreak + 1) (a + currSum)\n          currMaxStreak currMaxSum\n  | _, _, _, _, currMaxSum => currMaxSum\n\n/- Final function for the challenge -/\ndef longestConsecutiveSum (l : List Nat) : Nat := longestConsecutiveSumAux l 0 0 0 0\n\n#eval longestConsecutiveSum [1, 2, 3, 100, 7, 8, 9, 10] -- 34 = 7 + 8 + 9 + 10\n\n/- # Extra -/\n\n/- This function extracts the greatest sum instead of the sum of the longest sequence -/\ndef greatestConsecutiveSumAux : List Nat \u2192 Nat \u2192 Nat \u2192 Nat\n  | a::b::t, currSum, currMaxSum =>\n    if a + 1 \u2260 b then -- breaking the streak\n      greatestConsecutiveSumAux (b::t) 0 currMaxSum\n    else\n      greatestConsecutiveSumAux (b::t) (a + currSum)\n        (max (a + b + currSum) currMaxSum)\n  | _, _, currMax => currMax\n\ndef greatestConsecutiveSum (l : List Nat) : Nat := greatestConsecutiveSumAux l 0 0\n\n#eval greatestConsecutiveSum [1, 2, 3, 100, 7, 8] -- 15 = 7 + 8\n", "meta": {"author": "crabbo-rave", "repo": "leandiscord-weekly", "sha": "e66366d9d6e896d0e86607bd1de791811d1c0043", "save_path": "github-repos/lean/crabbo-rave-leandiscord-weekly", "path": "github-repos/lean/crabbo-rave-leandiscord-weekly/leandiscord-weekly-e66366d9d6e896d0e86607bd1de791811d1c0043/Week 1/arthur-paulino-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.737999431912441}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport group_theory.subgroup.basic\n/-!\n\n# Quotient groups\n\n-/\n\n/-\nsubgroup.normal : \u03a0 {G : Type u_1} [_inst_1 : group G], subgroup G \u2192 Prop\n-/\n\n-- let G be a group and let N be a normal subgroup\nvariables {G : Type} [group G] (N : subgroup G) [hN : subgroup.normal N]\n\ninclude hN\n\nexample (g h : G) (h1 : g \u2208 N) : h * g * h\u207b\u00b9 \u2208 N :=\nbegin\n  apply hN.conj_mem,\n  assumption,\nend\n\n-- The binary relation on G whose equivalence classes are the cosets of N\ndef R (a b : G) : Prop := a * b\u207b\u00b9 \u2208 N \n\nvariables (a b : G)\n\nlemma R_def (a b : G) : R N a b \u2194 a * b\u207b\u00b9 \u2208 N := iff.rfl\n\nlemma R_refl : reflexive (R N) :=\nbegin\n  intro x,\n  rw R_def,\n  simp [N.one_mem],\nend\n\nlemma R_symm : symmetric (R N) :=\nbegin\n  intros x y h,\n  rw R_def at *,\n  rw \u2190 N.inv_mem_iff,\n  simp [h],\nend\n\nlemma R_trans : transitive (R N) :=\nbegin\n  intros x y z h1 h2,\n  rw R_def at *,\n  have h := N.mul_mem h1 h2,\n  convert h using 1,\n  group,\nend\n\nlemma R_equiv : equivalence (R N) :=\n\u27e8R_refl N, R_symm N, R_trans N\u27e9\n\ndef s : setoid G :=\n{ r := R N,\n  iseqv := R_equiv N }\n\n-- Q is quotient of G by N\nnotation `Q`:10000 N := quotient (s N)\n\n-- things to do\n-- (1) make Q a group\n-- (2) Define group hom G -> Q\n-- (3) prove universal property : if \u03c6 : G -> H is a group hom and N is in ker(\u03c6)\n--     then we get an induced map Q -> H\n\nnamespace quotient_group\n\ndef equiv_def (a b : G) : @has_equiv.equiv G (@setoid_has_equiv G (s N)) a b \u2194 a * b\u207b\u00b9 \u2208 N := iff.rfl\n--  \u2194 a * b\u207b\u00b9 \u2208 N := sorry \ndef one : Q N := quotient.mk' 1\n\ndef setoid_r_def (a b : G) : @setoid.r G (s N) a b \u2194 a * b\u207b\u00b9 \u2208 N := iff.rfl\n\ninstance : has_one (Q N) := \u27e8one N\u27e9\n\ndef inv : (Q N) \u2192 Q N :=\nquotient.map' (\u03bb g, g\u207b\u00b9) begin\n  intros a b h,\n  dsimp, \n  rw equiv_def at *,\n  rw [hN.mem_comm_iff, \u2190 N.inv_mem_iff] at h,\n  convert h using 1,\n  group,\nend\n\ninstance : has_inv (Q N) := \u27e8inv N\u27e9\n\ndef mul : (Q N) \u2192 (Q N) \u2192 Q N :=\nquotient.map\u2082' (\u03bb g h, g * h) begin\n  intros a b h1 c d h2,\n  dsimp,\n  rw equiv_def at *,\n  rw (show (b * d)\u207b\u00b9 = d\u207b\u00b9 * b\u207b\u00b9, by group),\n  rw hN.mem_comm_iff at h1,\n  rw [mul_assoc, hN.mem_comm_iff],\n  convert N.mul_mem h2 h1 using 1,\n  group,\nend\n\ninstance : has_mul (Q N) :=\n\u27e8mul N\u27e9\n\ninstance group : group (Q N) :=\n{ mul := (*),\n  mul_assoc := begin\n    intros a b c,\n    apply quotient.induction_on\u2083' a b c, clear a b c,\n    intros a b c,\n    apply quotient.sound',\n    dsimp,\n    rw setoid_r_def,\n    convert N.one_mem,\n    group,\n  end,\n  one := 1,\n  one_mul := begin\n    intro a,\n    apply quotient.induction_on' a, clear a,\n    intro a,\n    apply quotient.sound',\n    dsimp,\n    rw setoid_r_def,\n    simp [N.one_mem],\n  end,\n  mul_one := begin\n    intro a,\n    apply quotient.induction_on' a, clear a,\n    intro a,\n    apply quotient.sound',\n    dsimp,\n    rw setoid_r_def,\n    simp [N.one_mem],\n  end,\n  inv := has_inv.inv,\n  mul_left_inv := begin\n    intro a,\n    apply quotient.induction_on' a, clear a,\n    intro a,\n    apply quotient.sound',\n    dsimp,\n    rw setoid_r_def,\n    simp [N.one_mem],\n  end, }\n\ndef canonical : G \u2192* (Q N) :=\n{ to_fun := quotient.mk',\n  map_one' := rfl,\n  map_mul' := \u03bb x y, rfl }\n\n-- (3) prove universal property : if \u03c6 : G -> H is a group hom and N is in ker(\u03c6)\n--     then we get an induced map Q -> H\n\nvariable {N}\n\ndef lift {H : Type} [group H] {\u03c6 : G \u2192* H} (h\u03c6 : N \u2264 \u03c6.ker) :\n(Q N) \u2192* H :=\n{ to_fun := \u03bb q, quotient.lift_on' q \u03c6 begin\n    clear q,\n    intros a b h,\n    rw setoid_r_def at h,\n    have h2 : \u03c6 (a * b\u207b\u00b9) = 1,\n    { rw \u2190 monoid_hom.mem_ker,\n      apply h\u03c6 h },\n    rw \u03c6.map_mul at h2,\n    rw \u03c6.map_inv at h2,\n    exact mul_inv_eq_one.mp h2,\n  end,\n  map_one' := begin\n     exact \u03c6.map_one,\n  end,\n  map_mul' := begin intros x y,\n    apply quotient.induction_on\u2082' x y, clear x y,\n    exact \u03c6.map_mul,\n  end }\n\n/-\n\nG ----\u03c6---> H\n|        /\n|mk    /\n|    / lift\n|   /\n\\//\nQ\n-/\nexample (H : Type) [group H] (g : G) (\u03c6 : G \u2192* H) (h\u03c6 : N \u2264 \u03c6.ker) :\n  \u03c6 g = lift h\u03c6 (quotient.mk' g) := rfl \n\nend quotient_group", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/outtakes/sheet5quotientgroups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220294, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7379994310946955}}
{"text": "/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport group_theory.subgroup.pointwise\nimport group_theory.quotient_group\nimport algebra.group.pi\n\n/-!\n# Divisible Group and rootable group\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file, we define a divisible add monoid and a rootable monoid with some basic properties.\n\n## Main definition\n\n* `divisible_by A \u03b1`: An additive monoid `A` is said to be divisible by `\u03b1` iff for all `n \u2260 0 \u2208 \u03b1`\n  and `y \u2208 A`, there is an `x \u2208 A` such that `n \u2022 x = y`. In this file, we adopt a constructive\n  approach, i.e. we ask for an explicit `div : A \u2192 \u03b1 \u2192 A` function such that `div a 0 = 0` and\n  `n \u2022 div a n = a` for all `n \u2260 0 \u2208 \u03b1`.\n* `rootable_by A \u03b1`: A monoid `A` is said to be rootable by `\u03b1` iff for all `n \u2260 0 \u2208 \u03b1` and `y \u2208 A`,\n  there is an `x \u2208 A` such that `x^n = y`. In this file, we adopt a constructive approach, i.e. we\n  ask for an explicit `root : A \u2192 \u03b1 \u2192 A` function such that `root a 0 = 1` and `(root a n)\u207f = a` for\n  all `n \u2260 0 \u2208 \u03b1`.\n\n## Main results\n\nFor additive monoids and groups:\n\n* `divisible_by_of_smul_right_surj` : the constructive definition of divisiblity is implied by\n  the condition that `n \u2022 x = a` has solutions for all `n \u2260 0` and `a \u2208 A`.\n* `smul_right_surj_of_divisible_by` : the constructive definition of divisiblity implies\n  the condition that `n \u2022 x = a` has solutions for all `n \u2260 0` and `a \u2208 A`.\n* `prod.divisible_by` : `A \u00d7 B` is divisible for any two divisible additive monoids.\n* `pi.divisible_by` : any product of divisble additive monoids is divisible.\n* `add_group.divisible_by_int_of_divisible_by_nat` : for additive groups, int divisiblity is implied\n  by nat divisiblity.\n* `add_group.divisible_by_nat_of_divisible_by_int` : for additive groups, nat divisiblity is implied\n  by int divisiblity.\n* `add_comm_group.divisible_by_int_of_smul_top_eq_top`: the constructive definition of divisiblity\n  is implied by the condition that `n \u2022 A = A` for all `n \u2260 0`.\n* `add_comm_group.smul_top_eq_top_of_divisible_by_int`: the constructive definition of divisiblity\n  implies the condition that `n \u2022 A = A` for all `n \u2260 0`.\n* `divisible_by_int_of_char_zero` : any field of characteristic zero is divisible.\n* `quotient_add_group.divisible_by` : quotient group of divisible group is divisible.\n* `function.surjective.divisible_by` : if `A` is divisible and `A \u2192+ B` is surjective, then `B`\n  is divisible.\n\nand their multiplicative counterparts:\n\n* `rootable_by_of_pow_left_surj` : the constructive definition of rootablity is implied by the\n  condition that `x\u207f = y` has solutions for all `n \u2260 0` and `a \u2208 A`.\n* `pow_left_surj_of_rootable_by` : the constructive definition of rootablity implies the\n  condition that `x\u207f = y` has solutions for all `n \u2260 0` and `a \u2208 A`.\n* `prod.rootable_by` : any product of two rootable monoids is rootable.\n* `pi.rootable_by` : any product of rootable monoids is rootable.\n* `group.rootable_by_int_of_rootable_by_nat` : in groups, int rootablity is implied by nat\n  rootablity.\n* `group.rootable_by_nat_of_rootable_by_int` : in groups, nat rootablity is implied by int\n  rootablity.\n* `quotient_group.rootable_by` : quotient group of rootable group is rootable.\n* `function.surjective.rootable_by` : if `A` is rootable and `A \u2192* B` is surjective, then `B` is\n  rootable.\n\nTODO: Show that divisibility implies injectivity in the category of `AddCommGroup`.\n-/\n\nopen_locale pointwise\n\nsection add_monoid\n\nvariables (A \u03b1 : Type*) [add_monoid A] [has_smul \u03b1 A] [has_zero \u03b1]\n\n/--\nAn `add_monoid A` is `\u03b1`-divisible iff `n \u2022 x = a` has a solution for all `n \u2260 0 \u2208 \u03b1` and `a \u2208 A`.\nHere we adopt a constructive approach where we ask an explicit `div : A \u2192 \u03b1 \u2192 A` function such that\n* `div a 0 = 0` for all `a \u2208 A`\n* `n \u2022 div a n = a` for all `n \u2260 0 \u2208 \u03b1` and `a \u2208 A`.\n-/\nclass divisible_by :=\n(div : A \u2192 \u03b1 \u2192 A)\n(div_zero : \u2200 a, div a 0 = 0)\n(div_cancel : \u2200 {n : \u03b1} (a : A), n \u2260 0 \u2192 n \u2022 (div a n) = a)\n\nend add_monoid\n\nsection monoid\n\nvariables (A \u03b1 : Type*) [monoid A] [has_pow A \u03b1] [has_zero \u03b1]\n\n/--\nA `monoid A` is `\u03b1`-rootable iff `x\u207f = a` has a solution for all `n \u2260 0 \u2208 \u03b1` and `a \u2208 A`.\nHere we adopt a constructive approach where we ask an explicit `root : A \u2192 \u03b1 \u2192 A` function such that\n* `root a 0 = 1` for all `a \u2208 A`\n* `(root a n)\u207f = a` for all `n \u2260 0 \u2208 \u03b1` and `a \u2208 A`.\n-/\n@[to_additive]\nclass rootable_by :=\n(root : A \u2192 \u03b1 \u2192 A)\n(root_zero : \u2200 a, root a 0 = 1)\n(root_cancel : \u2200 {n : \u03b1} (a : A), n \u2260 0 \u2192 (root a n)^n = a)\n\n@[to_additive smul_right_surj_of_divisible_by]\nlemma pow_left_surj_of_rootable_by [rootable_by A \u03b1] {n : \u03b1} (hn : n \u2260 0) :\n  function.surjective (\u03bb a, pow a n : A \u2192 A) :=\n\u03bb x, \u27e8rootable_by.root x n, rootable_by.root_cancel _ hn\u27e9\n\n/--\nA `monoid A` is `\u03b1`-rootable iff the `pow _ n` function is surjective, i.e. the constructive version\nimplies the textbook approach.\n-/\n@[to_additive divisible_by_of_smul_right_surj\n\"An `add_monoid A` is `\u03b1`-divisible iff `n \u2022 _` is a surjective function, i.e. the constructive\nversion implies the textbook approach.\"]\nnoncomputable def rootable_by_of_pow_left_surj\n  (H : \u2200 {n : \u03b1}, n \u2260 0 \u2192 function.surjective (\u03bb a, a^n : A \u2192 A)) :\nrootable_by A \u03b1 :=\n{ root := \u03bb a n, @dite _ (n = 0) (classical.dec _) (\u03bb _, (1 : A)) (\u03bb hn, (H hn a).some),\n  root_zero := \u03bb _, by classical; exact dif_pos rfl,\n  root_cancel := \u03bb n a hn, by { classical, rw dif_neg hn, exact (H hn a).some_spec } }\n\nsection pi\n\nvariables {\u03b9 \u03b2 : Type*} (B : \u03b9 \u2192 Type*) [\u03a0 (i : \u03b9), has_pow (B i) \u03b2]\nvariables [has_zero \u03b2] [\u03a0 (i : \u03b9), monoid (B i)] [\u03a0 i, rootable_by (B i) \u03b2]\n\n@[to_additive]\ninstance pi.rootable_by : rootable_by (\u03a0 i, B i) \u03b2 :=\n{ root := \u03bb x n i, rootable_by.root (x i) n,\n  root_zero := \u03bb x, funext $ \u03bb i, rootable_by.root_zero _,\n  root_cancel := \u03bb n x hn, funext $ \u03bb i, rootable_by.root_cancel _ hn }\n\nend pi\n\nsection prod\n\nvariables {\u03b2 B B' : Type*} [has_pow B \u03b2] [has_pow B' \u03b2]\nvariables [has_zero \u03b2] [monoid B] [monoid B'] [rootable_by B \u03b2] [rootable_by B' \u03b2]\n\n@[to_additive]\ninstance prod.rootable_by : rootable_by (B \u00d7 B') \u03b2 :=\n{ root := \u03bb p n, (rootable_by.root p.1 n, rootable_by.root p.2 n),\n  root_zero := \u03bb p, prod.ext (rootable_by.root_zero _) (rootable_by.root_zero _),\n  root_cancel := \u03bb n p hn, prod.ext (rootable_by.root_cancel _ hn) (rootable_by.root_cancel _ hn) }\n\nend prod\n\nend monoid\n\nnamespace add_comm_group\n\nvariables (A : Type*) [add_comm_group A]\n\nlemma smul_top_eq_top_of_divisible_by_int [divisible_by A \u2124] {n : \u2124} (hn : n \u2260 0) :\n  n \u2022 (\u22a4 : add_subgroup A) = \u22a4 :=\nadd_subgroup.map_top_of_surjective _ $ \u03bb a, \u27e8divisible_by.div a n, divisible_by.div_cancel _ hn\u27e9\n\n/--\nIf for all `n \u2260 0 \u2208 \u2124`, `n \u2022 A = A`, then `A` is divisible.\n-/\nnoncomputable def divisible_by_int_of_smul_top_eq_top\n  (H : \u2200 {n : \u2124} (hn : n \u2260 0), n \u2022 (\u22a4 : add_subgroup A) = \u22a4) :\n  divisible_by A \u2124 :=\n{ div := \u03bb a n, if hn : n = 0 then 0 else\n    (show a \u2208 n \u2022 (\u22a4 : add_subgroup A), by rw [H hn]; trivial).some,\n  div_zero := \u03bb a, dif_pos rfl,\n  div_cancel := \u03bb n a hn, begin\n    rw [dif_neg hn],\n    generalize_proofs h1,\n    exact h1.some_spec.2,\n  end }\n\nend add_comm_group\n\n@[priority 100]\ninstance divisible_by_int_of_char_zero {\ud835\udd5c} [division_ring \ud835\udd5c] [char_zero \ud835\udd5c] : divisible_by \ud835\udd5c \u2124 :=\n{ div := \u03bb q n, q / n,\n  div_zero := \u03bb q, by norm_num,\n  div_cancel := \u03bb n q hn,\n    by rw [zsmul_eq_mul, (int.cast_commute n _).eq, div_mul_cancel q (int.cast_ne_zero.mpr hn)] }\n\nnamespace group\n\nvariables (A : Type*) [group A]\n\n/--\nA group is `\u2124`-rootable if it is `\u2115`-rootable.\n-/\n@[to_additive add_group.divisible_by_int_of_divisible_by_nat\n\"An additive group is `\u2124`-divisible if it is `\u2115`-divisible.\"]\ndef rootable_by_int_of_rootable_by_nat [rootable_by A \u2115] : rootable_by A \u2124 :=\n{ root := \u03bb a z, match z with\n  | (n : \u2115) := rootable_by.root a n\n  | -[1+n] := (rootable_by.root a (n + 1))\u207b\u00b9\n  end,\n  root_zero := \u03bb a, rootable_by.root_zero a,\n  root_cancel := \u03bb n a hn, begin\n    induction n,\n    { change (rootable_by.root a _) ^ _ = a,\n      norm_num,\n      rw [rootable_by.root_cancel],\n      rw [int.of_nat_eq_coe] at hn,\n      exact_mod_cast hn, },\n    { change ((rootable_by.root a _) \u207b\u00b9)^_ = a,\n      norm_num,\n      rw [rootable_by.root_cancel],\n      norm_num, }\n  end}\n\n/--A group is `\u2115`-rootable if it is `\u2124`-rootable\n-/\n@[to_additive add_group.divisible_by_nat_of_divisible_by_int\n\"An additive group is `\u2115`-divisible if it `\u2124`-divisible.\"]\ndef rootable_by_nat_of_rootable_by_int [rootable_by A \u2124] : rootable_by A \u2115 :=\n{ root := \u03bb a n, rootable_by.root a (n : \u2124),\n  root_zero := \u03bb a, rootable_by.root_zero a,\n  root_cancel := \u03bb n a hn, begin\n    have := rootable_by.root_cancel a (show (n : \u2124) \u2260 0, by exact_mod_cast hn),\n    norm_num at this,\n    exact this,\n  end }\n\nend group\n\nsection hom\n\nvariables {\u03b1 A B : Type*}\nvariables [has_zero \u03b1] [monoid A] [monoid B] [has_pow A \u03b1] [has_pow B \u03b1] [rootable_by A \u03b1]\nvariables (f : A \u2192 B)\n\n/--\nIf `f : A \u2192 B` is a surjective homomorphism and `A` is `\u03b1`-rootable, then `B` is also `\u03b1`-rootable.\n-/\n@[to_additive \"If `f : A \u2192 B` is a surjective homomorphism and\n`A` is `\u03b1`-divisible, then `B` is also `\u03b1`-divisible.\"]\nnoncomputable def function.surjective.rootable_by (hf : function.surjective f)\n  (hpow : \u2200 (a : A) (n : \u03b1), f (a ^ n) = f a ^ n) : rootable_by B \u03b1 :=\nrootable_by_of_pow_left_surj _ _ $ \u03bb n hn x,\n  let \u27e8y, hy\u27e9 := hf x in \u27e8f $ rootable_by.root y n, (by rw [\u2190hpow (rootable_by.root y n) n,\n    rootable_by.root_cancel _ hn, hy] : _ ^ _ = x)\u27e9\n\n@[to_additive divisible_by.surjective_smul]\nlemma rootable_by.surjective_pow\n  (A \u03b1 : Type*) [monoid A] [has_pow A \u03b1] [has_zero \u03b1] [rootable_by A \u03b1] {n : \u03b1} (hn : n \u2260 0) :\n  function.surjective (\u03bb (a : A), a^n) :=\n\u03bb a, \u27e8rootable_by.root a n, rootable_by.root_cancel a hn\u27e9\n\nend hom\n\nsection quotient\n\nvariables (\u03b1 : Type*) {A : Type*} [comm_group A] (B : subgroup A)\n\n/-- Any quotient group of a rootable group is rootable. -/\n@[to_additive quotient_add_group.divisible_by\n\"Any quotient group of a divisible group is divisible\"]\nnoncomputable instance quotient_group.rootable_by [rootable_by A \u2115] : rootable_by (A \u29f8 B) \u2115 :=\nquotient_group.mk_surjective.rootable_by _ $ \u03bb _ _, rfl\n\nend quotient\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/divisible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7379994294995614}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.factors\n! leanprover-community/mathlib commit 327c3c0d9232d80e250dc8f65e7835b82b266ea5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Prime\nimport Mathbin.Data.List.Prime\nimport Mathbin.Data.List.Sort\nimport Mathbin.Tactic.NthRewrite.Default\n\n/-!\n# Prime numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file deals with the factors of natural numbers.\n\n## Important declarations\n\n- `nat.factors n`: the prime factorization of `n`\n- `nat.factors_unique`: uniqueness of the prime factorisation\n\n-/\n\n\nopen Bool Subtype\n\nopen Nat\n\nnamespace Nat\n\n#print Nat.factors /-\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 List \u2115\n  | 0 => []\n  | 1 => []\n  | n@(k + 2) =>\n    let m := minFac n\n    have : n / m < n := factors_lemma\n    m :: factors (n / m)\n#align nat.factors Nat.factors\n-/\n\n#print Nat.factors_zero /-\n@[simp]\ntheorem factors_zero : factors 0 = [] := by rw [factors]\n#align nat.factors_zero Nat.factors_zero\n-/\n\n#print Nat.factors_one /-\n@[simp]\ntheorem factors_one : factors 1 = [] := by rw [factors]\n#align nat.factors_one Nat.factors_one\n-/\n\n#print Nat.prime_of_mem_factors /-\ntheorem prime_of_mem_factors : \u2200 {n p}, p \u2208 factors n \u2192 Prime p\n  | 0 => by simp\n  | 1 => by simp\n  | n@(k + 2) => fun p h =>\n    let m := minFac n\n    have : n / m < n := factors_lemma\n    have h\u2081 : p = m \u2228 p \u2208 factors (n / m) := (List.mem_cons _ _ _).1 (by rwa [factors] at h)\n    Or.cases_on h\u2081 (fun h\u2082 => h\u2082.symm \u25b8 minFac_prime (by decide)) prime_of_mem_factors\n#align nat.prime_of_mem_factors Nat.prime_of_mem_factors\n-/\n\n#print Nat.pos_of_mem_factors /-\ntheorem pos_of_mem_factors {n p : \u2115} (h : p \u2208 factors n) : 0 < p :=\n  Prime.pos (prime_of_mem_factors h)\n#align nat.pos_of_mem_factors Nat.pos_of_mem_factors\n-/\n\n#print Nat.prod_factors /-\ntheorem prod_factors : \u2200 {n}, n \u2260 0 \u2192 List.prod (factors n) = n\n  | 0 => by simp\n  | 1 => by simp\n  | n@(k + 2) => fun h =>\n    let m := minFac n\n    have : n / m < n := factors_lemma\n    show (factors n).Prod = n\n      by\n      have h\u2081 : n / m \u2260 0 := fun h =>\n        by\n        have : n = 0 * m := (Nat.div_eq_iff_eq_mul_left (minFac_pos _) (minFac_dvd _)).1 h\n        rw [MulZeroClass.zero_mul] at this <;> exact (show k + 2 \u2260 0 by decide) this\n      rw [factors, List.prod_cons, prod_factors h\u2081, Nat.mul_div_cancel' (min_fac_dvd _)]\n#align nat.prod_factors Nat.prod_factors\n-/\n\n#print Nat.factors_prime /-\ntheorem factors_prime {p : \u2115} (hp : Nat.Prime p) : p.factors = [p] :=\n  by\n  have : p = p - 2 + 2 := (tsub_eq_iff_eq_add_of_le hp.two_le).mp rfl\n  rw [this, Nat.factors]\n  simp only [Eq.symm this]\n  have : Nat.minFac p = p := (nat.prime_def_min_fac.mp hp).2\n  constructor\n  \u00b7 exact this\n  \u00b7 simp only [this, Nat.factors, Nat.div_self (Nat.Prime.pos hp)]\n#align nat.factors_prime Nat.factors_prime\n-/\n\n#print Nat.factors_chain /-\ntheorem factors_chain : \u2200 {n a}, (\u2200 p, Prime p \u2192 p \u2223 n \u2192 a \u2264 p) \u2192 List.Chain (\u00b7 \u2264 \u00b7) a (factors n)\n  | 0 => fun a h => by simp\n  | 1 => fun a h => by simp\n  | n@(k + 2) => fun a h => by\n    let m := minFac n\n    have : n / m < n := factors_lemma\n    rw [factors]\n    refine' List.Chain.cons ((le_min_fac.2 h).resolve_left (by decide)) (factors_chain _)\n    exact fun p pp d => min_fac_le_of_dvd pp.two_le (d.trans <| div_dvd_of_dvd <| min_fac_dvd _)\n#align nat.factors_chain Nat.factors_chain\n-/\n\n#print Nat.factors_chain_2 /-\ntheorem factors_chain_2 (n) : List.Chain (\u00b7 \u2264 \u00b7) 2 (factors n) :=\n  factors_chain fun p pp _ => pp.two_le\n#align nat.factors_chain_2 Nat.factors_chain_2\n-/\n\n#print Nat.factors_chain' /-\ntheorem factors_chain' (n) : List.Chain' (\u00b7 \u2264 \u00b7) (factors n) :=\n  @List.Chain'.tail _ _ (_ :: _) (factors_chain_2 _)\n#align nat.factors_chain' Nat.factors_chain'\n-/\n\n#print Nat.factors_sorted /-\ntheorem factors_sorted (n : \u2115) : List.Sorted (\u00b7 \u2264 \u00b7) (factors n) :=\n  List.chain'_iff_pairwise.1 (factors_chain' _)\n#align nat.factors_sorted Nat.factors_sorted\n-/\n\n#print Nat.factors_add_two /-\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\ntheorem factors_add_two (n : \u2115) :\n    factors (n + 2) = minFac (n + 2) :: factors ((n + 2) / minFac (n + 2)) := by rw [factors]\n#align nat.factors_add_two Nat.factors_add_two\n-/\n\n#print Nat.factors_eq_nil /-\n@[simp]\ntheorem factors_eq_nil (n : \u2115) : n.factors = [] \u2194 n = 0 \u2228 n = 1 :=\n  by\n  constructor <;> intro h\n  \u00b7 rcases n with (_ | _ | n)\n    \u00b7 exact Or.inl rfl\n    \u00b7 exact Or.inr rfl\n    \u00b7 rw [factors] at h\n      injection h\n  \u00b7 rcases h with (rfl | rfl)\n    \u00b7 exact factors_zero\n    \u00b7 exact factors_one\n#align nat.factors_eq_nil Nat.factors_eq_nil\n-/\n\n#print Nat.eq_of_perm_factors /-\ntheorem eq_of_perm_factors {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) (h : a.factors ~ b.factors) :\n    a = b := by simpa [prod_factors ha, prod_factors hb] using List.Perm.prod_eq h\n#align nat.eq_of_perm_factors Nat.eq_of_perm_factors\n-/\n\nsection\n\nopen List\n\n#print Nat.mem_factors_iff_dvd /-\ntheorem mem_factors_iff_dvd {n p : \u2115} (hn : n \u2260 0) (hp : Prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n  \u27e8fun h => prod_factors hn \u25b8 List.dvd_prod h, fun h =>\n    mem_list_primes_of_dvd_prod (prime_iff.mp hp) (fun p h => prime_iff.mp (prime_of_mem_factors h))\n      ((prod_factors hn).symm \u25b8 h)\u27e9\n#align nat.mem_factors_iff_dvd Nat.mem_factors_iff_dvd\n-/\n\n#print Nat.dvd_of_mem_factors /-\ntheorem dvd_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2223 n :=\n  by\n  rcases n.eq_zero_or_pos with (rfl | hn)\n  \u00b7 exact dvd_zero p\n  \u00b7 rwa [\u2190 mem_factors_iff_dvd hn.ne' (prime_of_mem_factors h)]\n#align nat.dvd_of_mem_factors Nat.dvd_of_mem_factors\n-/\n\n#print Nat.mem_factors /-\ntheorem mem_factors {n p} (hn : n \u2260 0) : p \u2208 factors n \u2194 Prime p \u2227 p \u2223 n :=\n  \u27e8fun h => \u27e8prime_of_mem_factors h, dvd_of_mem_factors h\u27e9, fun \u27e8hprime, hdvd\u27e9 =>\n    (mem_factors_iff_dvd hn hprime).mpr hdvd\u27e9\n#align nat.mem_factors Nat.mem_factors\n-/\n\n#print Nat.le_of_mem_factors /-\ntheorem le_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2264 n :=\n  by\n  rcases n.eq_zero_or_pos with (rfl | hn)\n  \u00b7 rw [factors_zero] at h\n    cases h\n  \u00b7 exact le_of_dvd hn (dvd_of_mem_factors h)\n#align nat.le_of_mem_factors Nat.le_of_mem_factors\n-/\n\n#print Nat.factors_unique /-\n/-- **Fundamental theorem of arithmetic**-/\ntheorem factors_unique {n : \u2115} {l : List \u2115} (h\u2081 : Prod l = n) (h\u2082 : \u2200 p \u2208 l, Prime p) :\n    l ~ factors n := by\n  refine' perm_of_prod_eq_prod _ _ _\n  \u00b7 rw [h\u2081]\n    refine' (prod_factors _).symm\n    rintro rfl\n    rw [prod_eq_zero_iff] at h\u2081\n    exact Prime.ne_zero (h\u2082 0 h\u2081) rfl\n  \u00b7 simp_rw [\u2190 prime_iff]\n    exact h\u2082\n  \u00b7 simp_rw [\u2190 prime_iff]\n    exact fun p => prime_of_mem_factors\n#align nat.factors_unique Nat.factors_unique\n-/\n\n#print Nat.Prime.factors_pow /-\ntheorem Prime.factors_pow {p : \u2115} (hp : p.Prime) (n : \u2115) : (p ^ n).factors = List.replicate n p :=\n  by\n  symm\n  rw [\u2190 List.replicate_perm]\n  apply Nat.factors_unique (List.prod_replicate n p)\n  intro q hq\n  rwa [eq_of_mem_replicate hq]\n#align nat.prime.factors_pow Nat.Prime.factors_pow\n-/\n\n#print Nat.eq_prime_pow_of_unique_prime_dvd /-\ntheorem eq_prime_pow_of_unique_prime_dvd {n p : \u2115} (hpos : n \u2260 0)\n    (h : \u2200 {d}, Nat.Prime d \u2192 d \u2223 n \u2192 d = p) : n = p ^ n.factors.length :=\n  by\n  set k := n.factors.length\n  rw [\u2190 prod_factors hpos, \u2190 prod_replicate k p,\n    eq_replicate_of_mem fun d hd => h (prime_of_mem_factors hd) (dvd_of_mem_factors hd)]\n#align nat.eq_prime_pow_of_unique_prime_dvd Nat.eq_prime_pow_of_unique_prime_dvd\n-/\n\n#print Nat.perm_factors_mul /-\n/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\ntheorem perm_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n    (a * b).factors ~ a.factors ++ b.factors :=\n  by\n  refine' (factors_unique _ _).symm\n  \u00b7 rw [List.prod_append, prod_factors ha, prod_factors hb]\n  \u00b7 intro p hp\n    rw [List.mem_append] at hp\n    cases hp <;> exact prime_of_mem_factors hp\n#align nat.perm_factors_mul Nat.perm_factors_mul\n-/\n\n#print Nat.perm_factors_mul_of_coprime /-\n/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\ntheorem perm_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) :\n    (a * b).factors ~ a.factors ++ b.factors :=\n  by\n  rcases a.eq_zero_or_pos with (rfl | ha)\n  \u00b7 simp [(coprime_zero_left _).mp hab]\n  rcases b.eq_zero_or_pos with (rfl | hb)\n  \u00b7 simp [(coprime_zero_right _).mp hab]\n  exact perm_factors_mul ha.ne' hb.ne'\n#align nat.perm_factors_mul_of_coprime Nat.perm_factors_mul_of_coprime\n-/\n\n#print Nat.factors_sublist_right /-\ntheorem factors_sublist_right {n k : \u2115} (h : k \u2260 0) : n.factors <+ (n * k).factors :=\n  by\n  cases n\n  \u00b7 rw [MulZeroClass.zero_mul]\n  apply sublist_of_subperm_of_sorted _ (factors_sorted _) (factors_sorted _)\n  rw [(perm_factors_mul n.succ_ne_zero h).subperm_left]\n  exact (sublist_append_left _ _).Subperm\n#align nat.factors_sublist_right Nat.factors_sublist_right\n-/\n\n#print Nat.factors_sublist_of_dvd /-\ntheorem factors_sublist_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors <+ k.factors :=\n  by\n  obtain \u27e8a, rfl\u27e9 := h\n  exact factors_sublist_right (right_ne_zero_of_mul h')\n#align nat.factors_sublist_of_dvd Nat.factors_sublist_of_dvd\n-/\n\n#print Nat.factors_subset_right /-\ntheorem factors_subset_right {n k : \u2115} (h : k \u2260 0) : n.factors \u2286 (n * k).factors :=\n  (factors_sublist_right h).Subset\n#align nat.factors_subset_right Nat.factors_subset_right\n-/\n\n#print Nat.factors_subset_of_dvd /-\ntheorem factors_subset_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors \u2286 k.factors :=\n  (factors_sublist_of_dvd h h').Subset\n#align nat.factors_subset_of_dvd Nat.factors_subset_of_dvd\n-/\n\n#print Nat.dvd_of_factors_subperm /-\ntheorem dvd_of_factors_subperm {a b : \u2115} (ha : a \u2260 0) (h : a.factors <+~ b.factors) : a \u2223 b :=\n  by\n  rcases b.eq_zero_or_pos with (rfl | hb)\n  \u00b7 exact dvd_zero _\n  rcases a with (_ | _ | a)\n  \u00b7 exact (ha rfl).elim\n  \u00b7 exact one_dvd _\n  use (b.factors.diff a.succ.succ.factors).Prod\n  nth_rw 1 [\u2190 Nat.prod_factors ha]\n  rw [\u2190 List.prod_append,\n    List.Perm.prod_eq <| List.subperm_append_diff_self_of_count_le <| list.subperm_ext_iff.mp h,\n    Nat.prod_factors hb.ne']\n#align nat.dvd_of_factors_subperm Nat.dvd_of_factors_subperm\n-/\n\nend\n\n#print Nat.mem_factors_mul /-\ntheorem mem_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) {p : \u2115} :\n    p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u2228 p \u2208 b.factors :=\n  by\n  rw [mem_factors (mul_ne_zero ha hb), mem_factors ha, mem_factors hb, \u2190 and_or_left]\n  simpa only [and_congr_right_iff] using prime.dvd_mul\n#align nat.mem_factors_mul Nat.mem_factors_mul\n-/\n\n#print Nat.coprime_factors_disjoint /-\n/-- The sets of factors of coprime `a` and `b` are disjoint -/\ntheorem coprime_factors_disjoint {a b : \u2115} (hab : a.coprime b) :\n    List.Disjoint a.factors b.factors := by\n  intro q hqa hqb\n  apply not_prime_one\n  rw [\u2190 eq_one_of_dvd_coprimes hab (dvd_of_mem_factors hqa) (dvd_of_mem_factors hqb)]\n  exact prime_of_mem_factors hqa\n#align nat.coprime_factors_disjoint Nat.coprime_factors_disjoint\n-/\n\n/- warning: nat.mem_factors_mul_of_coprime -> Nat.mem_factors_mul_of_coprime is a dubious translation:\nlean 3 declaration is\n  forall {a : Nat} {b : Nat}, (Nat.coprime a b) -> (forall (p : Nat), Iff (Membership.Mem.{0, 0} Nat (List.{0} Nat) (List.hasMem.{0} Nat) p (Nat.factors (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) a b))) (Membership.Mem.{0, 0} Nat (List.{0} Nat) (List.hasMem.{0} Nat) p (Union.union.{0} (List.{0} Nat) (List.hasUnion.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b)) (Nat.factors a) (Nat.factors b))))\nbut is expected to have type\n  forall {a : Nat} {b : Nat}, (Nat.coprime a b) -> (forall (p : Nat), Iff (Membership.mem.{0, 0} Nat (List.{0} Nat) (List.instMembershipList.{0} Nat) p (Nat.factors (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) a b))) (Membership.mem.{0, 0} Nat (List.{0} Nat) (List.instMembershipList.{0} Nat) p (Union.union.{0} (List.{0} Nat) (List.instUnionList.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b)) (Nat.factors a) (Nat.factors b))))\nCase conversion may be inaccurate. Consider using '#align nat.mem_factors_mul_of_coprime Nat.mem_factors_mul_of_coprime\u2093'. -/\ntheorem mem_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) (p : \u2115) :\n    p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u222a b.factors :=\n  by\n  rcases a.eq_zero_or_pos with (rfl | ha)\n  \u00b7 simp [(coprime_zero_left _).mp hab]\n  rcases b.eq_zero_or_pos with (rfl | hb)\n  \u00b7 simp [(coprime_zero_right _).mp hab]\n  rw [mem_factors_mul ha.ne' hb.ne', List.mem_union]\n#align nat.mem_factors_mul_of_coprime Nat.mem_factors_mul_of_coprime\n\nopen List\n\n#print Nat.mem_factors_mul_left /-\n/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/\ntheorem mem_factors_mul_left {p a b : \u2115} (hpa : p \u2208 a.factors) (hb : b \u2260 0) : p \u2208 (a * b).factors :=\n  by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  \u00b7 simpa using hpa\n  apply (mem_factors_mul ha hb).2 (Or.inl hpa)\n#align nat.mem_factors_mul_left Nat.mem_factors_mul_left\n-/\n\n#print Nat.mem_factors_mul_right /-\n/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/\ntheorem mem_factors_mul_right {p a b : \u2115} (hpb : p \u2208 b.factors) (ha : a \u2260 0) :\n    p \u2208 (a * b).factors := by\n  rw [mul_comm]\n  exact mem_factors_mul_left hpb ha\n#align nat.mem_factors_mul_right Nat.mem_factors_mul_right\n-/\n\n#print Nat.eq_two_pow_or_exists_odd_prime_and_dvd /-\ntheorem eq_two_pow_or_exists_odd_prime_and_dvd (n : \u2115) :\n    (\u2203 k : \u2115, n = 2 ^ k) \u2228 \u2203 p, Nat.Prime p \u2227 p \u2223 n \u2227 Odd p :=\n  (eq_or_ne n 0).elim (fun hn => Or.inr \u27e83, prime_three, hn.symm \u25b8 dvd_zero 3, \u27e81, rfl\u27e9\u27e9) fun hn =>\n    or_iff_not_imp_right.mpr fun H =>\n      \u27e8n.factors.length,\n        eq_prime_pow_of_unique_prime_dvd hn fun p hprime hdvd =>\n          hprime.eq_two_or_odd'.resolve_right fun hodd => H \u27e8p, hprime, hdvd, hodd\u27e9\u27e9\n#align nat.eq_two_pow_or_exists_odd_prime_and_dvd Nat.eq_two_pow_or_exists_odd_prime_and_dvd\n-/\n\nend Nat\n\nassert_not_exists Multiset\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Factors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7379994281501047}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\nModular equality relation.\n-/\nimport data.int.gcd\n\nnamespace nat\n\n/-- Modular equality. `modeq n a b`, or `a \u2261 b [MOD n]`, means\n  that `a - b` is a multiple of `n`. -/\ndef modeq (n a b : \u2115) := a % n = b % n\n\nnotation a ` \u2261 `:50 b ` [MOD `:50 n `]`:0 := modeq n a b\n\nnamespace modeq\nvariables {n m a b c d : \u2115}\n\n@[refl] protected theorem refl (a : \u2115) : a \u2261 a [MOD n] := @rfl _ _\n\n@[symm] protected theorem symm : a \u2261 b [MOD n] \u2192 b \u2261 a [MOD n] := eq.symm\n\n@[trans] protected theorem trans : a \u2261 b [MOD n] \u2192 b \u2261 c [MOD n] \u2192 a \u2261 c [MOD n] := eq.trans\n\ninstance : decidable (a \u2261 b [MOD n]) := by unfold modeq; apply_instance\n\ntheorem modeq_zero_iff : a \u2261 0 [MOD n] \u2194 n \u2223 a :=\nby rw [modeq, zero_mod, dvd_iff_mod_eq_zero]\n\ntheorem modeq_iff_dvd : a \u2261 b [MOD n] \u2194 (n:\u2124) \u2223 b - a :=\nby rw [modeq, eq_comm, \u2190 int.coe_nat_inj'];\n   simp [int.mod_eq_mod_iff_mod_sub_eq_zero, int.dvd_iff_mod_eq_zero]\n\ntheorem modeq_of_dvd : (n:\u2124) \u2223 b - a \u2192 a \u2261 b [MOD n] := modeq_iff_dvd.2\ntheorem dvd_of_modeq : a \u2261 b [MOD n] \u2192 (n:\u2124) \u2223 b - a := modeq_iff_dvd.1\n\ntheorem mod_modeq (a n) : a % n \u2261 a [MOD n] := nat.mod_mod _ _\n\ntheorem modeq_of_dvd_of_modeq (d : m \u2223 n) (h : a \u2261 b [MOD n]) : a \u2261 b [MOD m] :=\nmodeq_of_dvd $ dvd_trans (int.coe_nat_dvd.2 d) (dvd_of_modeq h)\n\ntheorem modeq_mul_left' (c : \u2115) (h : a \u2261 b [MOD n]) : c * a \u2261 c * b [MOD (c * n)] :=\nby unfold modeq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h]\n\ntheorem modeq_mul_left (c : \u2115) (h : a \u2261 b [MOD n]) : c * a \u2261 c * b [MOD n] :=\nmodeq_of_dvd_of_modeq (dvd_mul_left _ _) $ modeq_mul_left' _ h\n\ntheorem modeq_mul_right' (c : \u2115) (h : a \u2261 b [MOD n]) : a * c \u2261 b * c [MOD (n * c)] :=\nby rw [mul_comm a, mul_comm b, mul_comm n]; exact modeq_mul_left' c h\n\ntheorem modeq_mul_right (c : \u2115) (h : a \u2261 b [MOD n]) : a * c \u2261 b * c [MOD n] :=\nby rw [mul_comm a, mul_comm b]; exact modeq_mul_left c h\n\ntheorem modeq_mul (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : c \u2261 d [MOD n]) : a * c \u2261 b * d [MOD n] :=\n(modeq_mul_left _ h\u2082).trans (modeq_mul_right _ h\u2081)\n\ntheorem modeq_add (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : c \u2261 d [MOD n]) : a + c \u2261 b + d [MOD n] :=\nmodeq_of_dvd $ by simpa using dvd_add (dvd_of_modeq h\u2081) (dvd_of_modeq h\u2082)\n\ntheorem modeq_add_cancel_left (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : a + c \u2261 b + d [MOD n]) : c \u2261 d [MOD n] :=\nhave (n:\u2124) \u2223 a + (-a + (d + -c)),\nby simpa using _root_.dvd_sub (dvd_of_modeq h\u2082) (dvd_of_modeq h\u2081),\nmodeq_of_dvd $ by rwa add_neg_cancel_left at this\n\ntheorem modeq_add_cancel_right (h\u2081 : c \u2261 d [MOD n]) (h\u2082 : a + c \u2261 b + d [MOD n]) : a \u2261 b [MOD n] :=\nby rw [add_comm a, add_comm b] at h\u2082; exact modeq_add_cancel_left h\u2081 h\u2082\n\ntheorem chinese_remainder (co : coprime n m) (a b : \u2115) : {k // k \u2261 a [MOD n] \u2227 k \u2261 b [MOD m]} :=\n\u27e8let (c, d) := xgcd n m in int.to_nat ((b * c * n + a * d * m) % (n * m)), begin\n  rw xgcd_val, dsimp,\n  rw [modeq_iff_dvd, modeq_iff_dvd],\n  rw [int.to_nat_of_nonneg], swap,\n  { by_cases h\u2081 : n = 0, {simp [coprime, h\u2081] at co, substs m n, simp},\n    by_cases h\u2082 : m = 0, {simp [coprime, h\u2082] at co, substs m n, simp},\n    exact int.mod_nonneg _\n      (mul_ne_zero (int.coe_nat_ne_zero.2 h\u2081) (int.coe_nat_ne_zero.2 h\u2082)) },\n  have := gcd_eq_gcd_ab n m, simp [co.gcd_eq_one, mul_comm] at this,\n  rw [int.mod_def, \u2190 sub_add, \u2190 sub_add]; split,\n  { refine dvd_add _ (dvd_trans (dvd_mul_right _ _) (dvd_mul_right _ _)),\n    rw [add_comm, \u2190 sub_sub], refine _root_.dvd_sub _ (dvd_mul_left _ _),\n    have := congr_arg ((*) \u2191a) this,\n    exact \u27e8_, by rwa [mul_add, \u2190 mul_assoc, \u2190 mul_assoc, mul_one, mul_comm,\n        \u2190 sub_eq_iff_eq_add] at this\u27e9 },\n  { refine dvd_add _ (dvd_trans (dvd_mul_left _ _) (dvd_mul_right _ _)),\n    rw [\u2190 sub_sub], refine _root_.dvd_sub _ (dvd_mul_left _ _),\n    have := congr_arg ((*) \u2191b) this,\n    exact \u27e8_, by rwa [mul_add, \u2190 mul_assoc, \u2190 mul_assoc, mul_one, mul_comm _ \u2191m,\n        \u2190 sub_eq_iff_eq_add'] at this\u27e9 }\nend\u27e9\n\nend modeq\nend nat\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/nat/modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7379994273323588}}
{"text": "/- ----------------------\n   BACKGROUND DEFINITIONS\n   ----------------------\n-/\n\n-- part 1\ninductive Rstar {T : Type} (P : T -> T -> Prop) : T -> T -> Prop :=\n| refl : forall a, Rstar P a a\n| step : forall a b c, P a b -> Rstar P b c -> Rstar P a c\n\ntheorem RTrans {T : Type} {P : T -> T -> Prop} {a b c : T} : \n        Rstar P a b -> Rstar P b c -> Rstar P a c :=\n  by intros H1\n     revert c\n     induction H1 <;> intros c H2 <;> simp <;> try assumption\n     constructor\n     assumption\n     rename_i H\n     apply H\n     assumption\n\n-- part 1\n/- ------------------------\n   SOURCE, TARGET, COMPILER\n   ------------------------\n-/\n-- part 2\n\ninductive Source :=\n| b : Bool -> Source\n| and : Source -> Source -> Source\n| var : String -> Source\n| lam : String -> Source -> Source\n| app : Source -> Source -> Source\n\ndef Source.sub (e : Source) (x : String) (body : Source) :=\n  match body with\n  | b _ => body\n  | and t1 t2 => and (e.sub x t1) (e.sub x t2)\n  | var x' => if x == x' then e else body\n  | app t1 t2 => app (e.sub x t1) (e.sub x t2)\n  | lam x' body' => if x == x' then body\n                    else lam x' (e.sub x body')\n\ninductive SStep : Source -> Source -> Prop :=\n| app : forall e e' a, SStep e e' ->\n                  SStep (Source.app e a) (Source.app e' a)\n| beta : forall x1 body e,\n    SStep (Source.app (Source.lam x1 body) e)\n        (e.sub x1 body)\n| and1 : forall e1 e1' e2, SStep e1 e1' ->\n                        SStep (Source.and e1 e2) (Source.and e1' e2)\n| and2 : forall b e2 e2', SStep e2 e2' ->\n                      SStep (Source.and (Source.b b) e2) (Source.and (Source.b b) e2')\n| and : forall b1 b2, SStep (Source.and (Source.b b1) (Source.b b2))\n                        (Source.b (b1 && b2))\n\ninductive Target :=\n| n : Nat -> Target\n| plus : Target -> Target -> Target\n| minus : Target -> Target -> Target\n| var : String -> Target\n| lam : String -> Target -> Target\n| app : Target -> Target -> Target\n\ndef Target.sub (e : Target) (x : String) (body : Target) :=\n  match body with\n  | n _ => body\n  | plus t1 t2 => plus (e.sub x t1) (e.sub x t2)\n  | minus t1 t2 => minus (e.sub x t1) (e.sub x t2)\n  | var x' => if x == x' then e else body\n  | app t1 t2 => app (e.sub x t1) (e.sub x t2)\n  | lam x' body' => if x == x' then body\n                      else lam x' (e.sub x body')\n\ninductive TStep : Target -> Target -> Prop :=\n| app : forall e e' a, TStep e e' ->\n                  TStep (Target.app e a) (Target.app e' a)\n| beta : forall x1 body e,\n    TStep (Target.app (Target.lam x1 body) e)\n          (e.sub x1 body)\n| plus1 : forall e1 e1' e2, TStep e1 e1' ->\n                        TStep (Target.plus e1 e2) (Target.plus e1' e2)\n| plus2 : forall e1 e2 e2', TStep e2 e2' ->\n                        TStep (Target.plus e1 e2) (Target.plus e1 e2')\n| plus : forall n1 n2, TStep (Target.plus (Target.n n1) (Target.n n2))\n                        (Target.n (n1 + n2))\n| minus1 : forall e1 e1' e2, TStep e1 e1' ->\n                      TStep (Target.minus e1 e2) (Target.minus e1' e2)\n| minus2 : forall e1 e2 e2', TStep e2 e2' ->\n                      TStep (Target.minus e1 e2) (Target.minus e1 e2')\n| minus : forall n1 n2, TStep (Target.minus (Target.n n1) (Target.n n2))\n                          (Target.n (n1 - n2))\n\n\n-- part 2\n\n-- part 3\ndef Source.compile : Source -> Target \n| b true    => Target.n 1\n| b false   => Target.n 0\n| and b1 b2 => Target.minus (Target.plus (compile b1) (compile b2)) (Target.n 1)\n| var x     => Target.var x\n| app t1 t2 => Target.app (compile t1) (compile t2)\n| lam x bdy => Target.lam x (compile bdy)\n\n-- part 3\n/- -------------------\n   SIMULATION RELATION\n   -------------------\n-/\n-- part 4\ninductive sim : Source -> Target -> Prop :=\n| comp : forall e, sim e e.compile\n-- part 4\n\n/- PROBLEM 1: Lifting steps to RStar\n\n  These theorems will be necessary when proving `sim_step`. They\n  show how even though TStep is not defined in terms of Rstar, \n  you can nonetheless lift many steps (using Rstar) into subterms.\n\n  Note that all of these proofs should be very similar! So while it\n  looks like a lot, once you do _one_, the rest should be quite easy.\n-/\n\n-- part 5\n-- 7 lines \ntheorem app_star : forall e1 e1' e2, Rstar TStep e1 e1' -> \n                  Rstar TStep (Target.app e1 e2) (Target.app e1' e2) :=\n by sorry\n\n-- 7 lines\ntheorem plus_star1 : forall e1 e1' e2, Rstar TStep e1 e1' -> \n                  Rstar TStep (Target.plus e1 e2) (Target.plus e1' e2) :=\n by sorry\n\n-- 7 lines\ntheorem plus_star2 : forall e1 e2 e2', Rstar TStep e2 e2' -> \n                  Rstar TStep (Target.plus e1 e2) (Target.plus e1 e2') :=\n by sorry\n\n-- 7 lines\ntheorem minus_star1 : forall e1 e1' e2, Rstar TStep e1 e1' -> \n                  Rstar TStep (Target.minus e1 e2) (Target.minus e1' e2) :=\n by sorry\n\n-- 7 lines\ntheorem minus_star2 : forall e1 e2 e2', Rstar TStep e2 e2' -> \n                  Rstar TStep (Target.minus e1 e2) (Target.minus e1 e2') :=\n by sorry\n\n-- part 5\n\n/- PROBLEM 2: Substitution commutes with compile.\n\n  In this problem, you will prove that substituting and then \n  compiling is the same as compiling and then substituting. \n  This will be a necessary result in the `beta` case of `sim_step`.\n\n  Think about whether the expression being substituted, or the \n  expression substituted into (e or body) make more sense to do\n  induction on. Also: in the cases where variable comparison is \n  used (var & lam), remember L23 (3/13).\n-/\n-- part 6\n\n-- 15 lines\ntheorem compile_sub : forall (e : Source) x (body : Source),\n  (e.sub x body).compile = Target.sub e.compile x body.compile :=\n by sorry\n\n-- part 6\n/- PROBLEM 3: Show that the simulation respects compiler.\n\n  In some relations, this is involved: in ours, this should be \n  trivial! But it is a necessary step, as logically, it is how we\n  start our argument: first, we show that the source & target term are\n  in the relation. Then we should that at each step, they remain; \n  finally, we should that when they terminate, they terminate at related\n  values.\n-/\n-- part 7\n\n-- 1 line\ntheorem compile_sim : forall t,\n  sim t t.compile := \n by sorry\n\n-- part 7\n/- PROBLEM 4: Simulation is preserved over reduction\n\n  This is the heart of the proof. It says that for a single\n  step of the source, after any number of steps of the target,\n  there is some target term that is related again. i.e., we can \n  always get back to a pair of related terms. We will use this \n  iteratively in the next proof. \n\n  Be sure to use the theorems you did in Problem 1 & Problem 2, \n  and as a hint: you will want to do induction on the SSTep relation.\n-/\n-- part 8\n\n-- 67 lines\ntheorem sim_step : forall t1 t1',\n  SStep t1 t1' ->\n  forall t2,\n  sim t1 t2 ->\n  exists t2', Rstar TStep t2 t2' /\\ sim t1' t2' := \n by intros t1 t1' stept1\n    induction stept1 <;> intros t2 sim1 <;> sorry\n\n-- part 8\n/- PROBLEM 5: sim_step lifts to many steps.\n\n  This problem shows that if we take many steps at the source, \n  the result from the previous theorem still holds. It is \n  much easier, since we can appeal to the single step result\n  (where most of the work is done). \n-/\n-- part 9\n\n-- 15 lines\ntheorem step_sim_star : forall t1 t1',\n  Rstar SStep t1 t1' ->\n  forall t2,\n  sim t1 t2 ->\n  exists t2', Rstar TStep t2 t2' /\\ sim t1' t2' := \n by intros t1 t1' rst1\n    induction rst1 <;> intros t2 sim1 <;> sorry\n\n\n\n-- part 9\n/- PROBLEM 6: The final result!\n\n  While this is the actual result that we care about: that if \n  a term runs to a boolean, then the term in compiles to runs to the compiled version of that boolean, it is actually one of the easier proofs, as most of the work is done by the theorems above. \n\n  If you are wondering, why running to a boolean? If our program \n  runs forever, there isn't much we can say about the target (we could \n  say we want it to run forever, but we often don't). The only other\n  value it could run to is a function (lam). But knowing how to equate \n  lambdas is tricky (as they contain code, and equivalence of code sort \n  of requires running, which is circular). Fortunately, it turns out \n  that by showing equivalence of booleans, we essentially get \n  equivalence of functions, as if we have a term `t` that should run to \n  a function (say, of a single boolean argument), then our theorem, \n  since it holds of @italic{all} expressions, will\n  tell us that both `t true` and `t false` will run to the same thing.\n-/\n-- part 10\n\n-- 7 lines\ntheorem correct : forall t b, Rstar SStep t (Source.b b) ->\n                              Rstar TStep t.compile ((Source.b b).compile) := \n by sorry\n\n-- part 10", "meta": {"author": "logiccomp", "repo": "s23-hw10", "sha": "43ac307c2ea8050610a5cbcab8ddaa2b563d497e", "save_path": "github-repos/lean/logiccomp-s23-hw10", "path": "github-repos/lean/logiccomp-s23-hw10/s23-hw10-43ac307c2ea8050610a5cbcab8ddaa2b563d497e/hw10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530492, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7379556823210308}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Kyle Miller\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.parity\nimport Mathlib.data.zmod.basic\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Relating parity to natural numbers mod 2\n\nThis module provides lemmas relating `zmod 2` to `even` and `odd`.\n\n## Tags\n\nparity, zmod, even, odd\n-/\n\nnamespace zmod\n\n\ntheorem eq_zero_iff_even {n : \u2115} : \u2191n = 0 \u2194 even n :=\n  iff.trans (char_p.cast_eq_zero_iff (zmod (bit0 1)) (bit0 1) n) (iff.symm even_iff_two_dvd)\n\ntheorem eq_one_iff_odd {n : \u2115} : \u2191n = 1 \u2194 odd n := sorry\n\ntheorem ne_zero_iff_odd {n : \u2115} : \u2191n \u2260 0 \u2194 odd n := sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/zmod/parity_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7379519858403792}}
{"text": "import data.real.basic\n\n/- Tactics you may consider\n-intro\n-rw\n-apply\n-exact\n-cal\n-dsimp: definition simplification\n-/\n\nvariables (f g : \u211d \u2192 \u211d)\n\n#check mul_assoc\n#check neg_mul_comm\n#check neg_mul_neg\n#check neg_eq_neg_one_mul \n\n-- BEGIN\ndef fn_even (f : \u211d \u2192 \u211d) : Prop := \u2200 x, f x = f (-x)\ndef fn_odd (f : \u211d \u2192 \u211d) : Prop := \u2200 x, f x = - f (-x)\n\nexample (ef : fn_even f) (og : fn_odd g) : fn_odd (\u03bb x, f x * g x) :=\nbegin \n  intro x, \n  dsimp,\n  rw [ef, og],\n  rw \u2190 neg_mul_comm,\n  rw neg_eq_neg_one_mul,\n  rw mul_assoc,\n  rw \u2190 neg_eq_neg_one_mul,\nend\n\nexample (ef : fn_even f) (eg : fn_even g) : fn_even (\u03bb x, f x + g x) :=\nbegin\n  intro x,\n  calc\n    (\u03bb x, f x + g x) x = f x + g x       : rfl\n                   ... = f (-x) + g (-x) : by rw [ef, eg]\nend\n\nexample (of : fn_odd f) (og : fn_odd g) : fn_even (\u03bb x, f x * g x) :=\nbegin\n  intro x,\n  calc\n    (\u03bb x, f x * g x) x = f x * g x      : rfl\n                   ... = - f (-x) * - g(-x) : by rw [of, og]\n                   ... = f (-x) * g(-x)     : by rw neg_mul_neg,\nend\n\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/2_intro(s)/ex5_intro_vari_even_odd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7379519843109698}}
{"text": "import data.polynomial.ring_division\nimport data.polynomial.field_division\nimport data.polynomial.inductions\nimport data.polynomial.coeff\nimport ring_theory.polynomial.basic\nimport data.real.sign\nimport data.quot\nimport order.hom.basic\nimport data.fin.tuple.basic\nimport tactic\n\n\nnoncomputable theory\nopen_locale classical big_operators\n\n\nopen multiset\n\nvariables {R : Type*} [linear_ordered_field R]\n\ndef polynomial.positive_roots (f : polynomial R) :=\nf.roots.filter (\u03bb x, 0 < x)\n\ndef polynomial.number_positive_roots (f : polynomial R) :=\nf.positive_roots.card\n\n\nvariables {p q f : polynomial R}\n\nopen polynomial\n\n@[simp] lemma smul_eq {a : R} : C a * p = a \u2022 p :=\nbegin\nrw smul_eq_C_mul,\nend\n\nlemma mem_positive_roots {x : R} :\nx \u2208 p.positive_roots \u2194 x \u2208 p.roots \u2227 0 < x :=\nby rw [positive_roots, mem_filter]\n\n/--\nThe set of positive roots of X-a is {a} when 0 < a\n-/\nlemma positive_roots_X_sub_C_of_zero_lt {a : R} (h : 0 < a) :\n(X - C a).positive_roots = {a} :=\nbegin\n  rw positive_roots,\n  rw roots_X_sub_C,\n  rw filter_eq_self,\n  simp [h],\nend\n\nlemma positive_roots_X : polynomial.positive_roots (@X R _) = \u2205 :=\nbegin\n  rw polynomial.positive_roots,\n  rw roots_X,\n  simp,\n  rw filter_eq_nil,\n  intros a ha,\n  simp at ha,\n  subst ha,\n  exact irrefl 0,\nend\n\n\n/--\nThe positive roots of the monic normalization of f\n-/\nlemma positive_roots_normalize_eq_positive_roots :\n  (normalize f).positive_roots = f.positive_roots :=\nbegin\n  rw [positive_roots, roots_normalize],\n  refl,\nend\n\n/--\nThe positive roots of the product of two polinomials\n-/\nlemma positive_roots_mul {p q : polynomial R}\n(hpq : p * q \u2260 0):\n  (p * q).positive_roots = p.positive_roots + q.positive_roots :=\nbegin\n  rw [positive_roots, roots_mul hpq, filter_add],\n  refl,\nend\n\nlemma positive_roots_X_pow (i : \u2115):\npolynomial.positive_roots ((@X R _)^i) = \u2205 :=\nbegin\n  rw positive_roots,\n  rw roots_pow,\n  simp [filter_eq_nil],\n  intros a ha,\n  replace ha := mem_of_mem_nsmul ha,\n  simp at ha,\n  linarith [ha],\nend\n/--\nThe positive roots don't change when multiplying by X\n-/\nlemma positive_roots_mul_X (hp : p \u2260 0) :\n  p.positive_roots = (p * X).positive_roots :=\nbegin\n  have hnz : p * X \u2260 0 := mul_ne_zero hp X_ne_zero,\n  rw [positive_roots_mul hnz, positive_roots_X],\n  simp only [empty_eq_zero, add_zero],\nend\n\n\nlemma X_pow_ne_zero {i : \u2115} : (X : polynomial R)^i \u2260 0 :=\nbegin\n  induction i with d hd,\n  { simp only [pow_zero, ne.def, one_ne_zero, not_false_iff] },\n  { apply mul_ne_zero X_ne_zero hd }\nend\n\nlemma positive_roots_mul_X_pow {i : \u2115} (hp : p \u2260 0) :\n  (p * X^i).positive_roots = p.positive_roots :=\nbegin\nrw positive_roots_mul (mul_ne_zero hp X_pow_ne_zero),\nrw positive_roots_X_pow,\nsimp only [empty_eq_zero, add_zero],\nend\n\n-- Proposition 1 of Levin\n/--\nIf all coefficients of p are non-negative, then p has no positive roots.\n-/\nlemma positive_roots_empty_of_positive_coeffs (h : \u2200 n \u2208 p.support, 0 < p.coeff n) :\n  p.positive_roots = \u2205 :=\nbegin\n  by_contra he,\n  have hp : p \u2260 0,\n  {\n    intro hp,\n    apply he,\n    rw [positive_roots, hp, roots_zero, empty_eq_zero, filter_zero]\n  },\n  --cases exists_mem_of_ne_zero he with x hx,\n  obtain \u27e8x, hx\u27e9 := exists_mem_of_ne_zero he,\n  cases mem_positive_roots.mp hx with hxr hxp,\n  rw [mem_roots hp, is_root.def, eval_eq_sum] at hxr,\n  apply lt_irrefl (0 : R),\n  nth_rewrite_rhs 0 \u2190 hxr,\n  convert finset.sum_lt_sum_of_nonempty _ _,\n  swap,\n  exact 0,\n  simp only [pi.zero_apply, finset.sum_const_zero],\n  exact nonempty_support_iff.mpr hp,\n  intros n hn,\n  specialize h n hn,\n  rw [pi.zero_apply],\n  exact mul_pos h (pow_pos hxp n),\nend\n\n\n\n/--\nThe list of nonzero coefficients of a polynomial\n-/\ndef polynomial.nonzero_coeff_list\n(f : polynomial R) := (f.support.sort (\u2264)).map f.coeff\n\nopen list\n\nlemma list.sorted_of_monotone (l : list R) (hl : sorted (\u2264) l)\n(g : R \u2192o R) : sorted (\u2264) (map g l) :=\nlist.pairwise.map g.1 g.2 hl\n\nlemma list.sort_commutes_monotone (S : list \u2115)\n(g : \u2115 \u2192o \u2115) : (S.merge_sort (\u2264)).map g = (S.map g).merge_sort (\u2264)\n:=\nbegin\n  apply @eq_of_perm_of_sorted \u2115 (\u2264),\n  {\n    calc\n    map \u21d1g (merge_sort has_le.le S) ~ map g.1 S : by {\n      apply list.perm.map,\n      apply perm_merge_sort,\n    }\n    ... ~ merge_sort has_le.le (map \u21d1g S) : by {\n      symmetry,\n      apply perm_merge_sort,\n    }\n  },\n  {\n    apply pairwise.map g.1 g.2,\n    apply sorted_merge_sort,\n  },\n  apply sorted_merge_sort,\nend\n\nlemma multiset.sort_commutes_monotone (S : multiset \u2115)\n(g : \u2115 \u21aao \u2115) : (sort (\u2264) S).map g = sort (\u2264)\n(multiset.map g S) :=\nbegin\n  set l : list \u2115 := S.to_list,\n  rw show S = (l : multiset \u2115), by simp only [coe_to_list],\n  rw (show (sort has_le.le \u2191l) = merge_sort (\u2264) l, by exact multiset.coe_sort (\u2264) l),\n  rw (show (sort has_le.le (map \u21d1g \u2191l)) = merge_sort (\u2264) (map g l), by exact multiset.coe_sort (\u2264) _),\n  apply list.sort_commutes_monotone l g,\nend\n\nlemma finset.sort_commutes_monotone (S : finset \u2115)\n(g : \u2115 \u21aao \u2115) : (finset.sort (\u2264) S).map g = finset.sort (\u2264) (finset.map g.1 S) :=\nbegin\n  repeat {rw finset.sort},\n  apply multiset.sort_commutes_monotone,\nend\n\n/--\nThe support doesn't change when scaling by a nonzero constant\n-/\nlemma polynomial.support_smul_of_ne_zero (f : polynomial R) {a : R} (h : a \u2260 0) : (a \u2022 f).support = f.support :=\nbegin\n  ext,\n  simp [h],\nend\n\nlemma polynomial.nonzero_coeff_list_smul (f : polynomial R) {a : R} (hc : a \u2260 0) :\n(a \u2022 f).nonzero_coeff_list = f.nonzero_coeff_list.map (\u03bb x, a * x) :=\nbegin\n  simp only [polynomial.nonzero_coeff_list],\n  rw polynomial.support_smul_of_ne_zero f hc,\n  have : (a\u2022 f).coeff = \u03bb n, a * (f.coeff n),\n  {\n    ext n,\n    simp [coeff_smul],\n  },\n  simp [this],\nend\n\n/--\nThe number of sign changes in a list\n-/\n@[simp]\nnoncomputable def list.num_sign_changes : list R \u2192 \u2115\n| [] := 0\n| [a] := 0\n| (a :: b :: tail) :=\nite (b = 0) (list.num_sign_changes (a :: tail))\n(bool.to_nat (a * b < 0) + list.num_sign_changes (b :: tail))\n\n@[simp]\nlemma list.num_sign_changes_zero {a : R} (ha : a = 0) (l : list R) :\nlist.num_sign_changes (a :: l) = list.num_sign_changes l :=\nbegin\n  rw ha,\n  induction l with b tail,\n  {\n    simp,\n  },\n  by_cases hb : b = 0;\n  {\n    simp [hb],\n    try {refl},\n  },\nend\n\n@[simp]\nlemma list.num_sign_changes_zero' {a b : R} (ha : b = 0) (l : list R) :\nlist.num_sign_changes (a :: b :: l) = list.num_sign_changes (a :: l) :=\nbegin\n  sorry\nend\n\n@[simp]\nlemma list.num_sign_changes_of_eq_signs {a b : R} (h : 0 < a * b) (l : list R) :\nlist.num_sign_changes (a :: b :: l) = list.num_sign_changes (b :: l) :=\nbegin\n  sorry\nend\n\n@[simp]\nlemma list.num_sign_changes_of_neq_signs {a b : R} (h : a * b < 0) (l : list R) :\nlist.num_sign_changes (a :: b :: l) = 1 + list.num_sign_changes (b :: l) :=\nbegin\n  sorry\nend\n\nnotation `V` := list.num_sign_changes\n\nlemma list.num_sign_changes_smul (l : list R) (c : R) (hc : c \u2260 0) :\nl.num_sign_changes = (l.map (\u03bb x, c * x)).num_sign_changes :=\nbegin\ninduction l with a tail HI,\n{\n  refl,\n},\n{\n  induction tail with b tail HI2,\n  {\n    simp,\n  },\n  {\n    have hc : (a * b < 0) = (c * a * (c * b) < 0), by\n    {\n      ext,\n      rw show (c * a * ( c * b) = c^2 * (a * b)), by ring,\n      have hc' : 0 < c^2 := pow_two_pos_of_ne_zero c hc,\n      split;\n      {\n        intro H,\n        nlinarith [H],\n      },\n    },\n    simp at *,\n    rw HI,\n    by_cases b = 0;\n      simp [*] at *,\n  }\n}\nend\n\n\n/--\nThe number of sign changes of a  polynomial\n-/\ndef polynomial.num_sign_changes (f : polynomial R) :=\nf.nonzero_coeff_list.num_sign_changes\n\n\nlemma polynomial.num_sign_changes_smul (f : polynomial R) {c : R} (hc : c \u2260 0) :\n(c \u2022 f).num_sign_changes = f.num_sign_changes :=\nbegin\n  rw [polynomial.num_sign_changes, polynomial.num_sign_changes,\n  f.nonzero_coeff_list_smul hc,\u2190list.num_sign_changes_smul _  _ hc],\nend\n\nlemma polynomial.support_mul_X (f : polynomial R) :\n(f * X).support = f.support.map \u27e8nat.succ, nat.succ_injective\u27e9 :=\nbegin\n  ext i,\n  cases i with i i,\n  {\n    simp only [mem_support_iff, mul_coeff_zero, coeff_X_zero, mul_zero,\n    ne.def, eq_self_iff_true, not_true, finset.mem_map,\n    function.embedding.coe_fn_mk, exists_false],\n  },\n  split;\n  {\n    intro hi,\n    simpa using hi,\n  },\nend\n\n\nlemma polynomial.support_mul_X_pow {i : \u2115} (f : polynomial R) :\n(f * X^i).support = f.support.map \u27e8nat.add i, add_right_injective i\u27e9 :=\nbegin\n  induction i with i hi,\n  {\n    ext,\n    simp,\n  },\n  {\n    rw pow_succ,\n    rw [show f * (X * X^i) = (f*X^i) * X, by ring],\n    rw [polynomial.support_mul_X, hi, finset.map_map],\n    ext r,\n    simp only [finset.mem_map, mem_support_iff,\n    ne.def, function.embedding.trans_apply, function.embedding.coe_fn_mk,\n    nat.add_def, exists_prop],\n    simp_rw show \u2200 (a : \u2115), (i+a).succ = i.succ + a,\n    by {intro a, rw nat.succ_eq_add_one, rw nat.succ_eq_add_one, ring_nf},\n  }\nend\n\nlemma polynomial.nonzero_coeff_list_mul_X_pow (f : polynomial R) (i : \u2115) :\n  (f * X^i).nonzero_coeff_list = f.nonzero_coeff_list :=\nbegin\n  repeat {rw polynomial.nonzero_coeff_list},\n  rw polynomial.support_mul_X_pow,\n  set addi : \u2115 \u21aao \u2115 := \u27e8\u27e8i.add, \u03bb a b hab, (add_right_inj i).mp hab\u27e9, \u03bb a b, by simp\u27e9 with haddi,\n  rw (show function.embedding.mk i.add (add_right_injective i)  = addi.to_embedding, by refl),\n  rw \u2190finset.sort_commutes_monotone f.support addi,\n  simp only [function.embedding.coe_fn_mk, rel_embedding.coe_fn_mk, list.map_map],\n  rw show (f * X^i).coeff \u2218 i.add = f.coeff, by {ext,\n  simp,\n  rw [add_comm , coeff_mul_X_pow],\n  },\nend\n\nlemma polynomial.nonzero_coeff_list_mul_X (f : polynomial R) :\n  (f * X).nonzero_coeff_list = f.nonzero_coeff_list :=\nbegin\n  rw [\u2190pow_one X, polynomial.nonzero_coeff_list_mul_X_pow f 1],\nend\n\nlemma polynomial.num_sign_changes_mul_X (f : polynomial R):\n(f * X).num_sign_changes = f.num_sign_changes :=\nbegin\n  rw polynomial.num_sign_changes,\n  rw polynomial.num_sign_changes,\n  congr' 1,\n  apply polynomial.nonzero_coeff_list_mul_X,\nend\n\nlemma polynomial.num_sign_changes_mul_X_pow (f : polynomial R) (i : \u2115):\n(f * X^i).num_sign_changes = f.num_sign_changes :=\nbegin\n  induction i with n hn,\n  {\n    simp only [pow_zero, mul_one],    \n  },\n  {\n    rw show f * X ^ n.succ = (f * X^n) * X, by ring_nf,\n    rw polynomial.num_sign_changes_mul_X,\n    exact hn,\n  }\nend\n\n/--\nThe number of sign changes can be computed on the monic normalization\n-/\nlemma num_sign_changes_normalize_eq_num_sign_changes :\n  (normalize p).num_sign_changes = p.num_sign_changes :=\nbegin\n  have hnz := (norm_unit (leading_coeff p)).ne_zero,\n  simp only [coe_norm_unit, coeff_mul_C, normalize_apply],\n  rw \u2190 p.num_sign_changes_smul  hnz,\n  congr' 1,\n  rw smul_eq_C_mul,\n  ring,\nend\n\nlemma coeff_mul_X_sub_C' {p : polynomial R} {r : R} {a : \u2115} :\n  coeff (p * (X - C r)) a = (if 0 < a then coeff p (a - 1) else 0) - coeff p a * r :=\nbegin\n  split_ifs,\n  { have : a = (a - 1) + 1 := by omega,\n    rw [this, coeff_mul_X_sub_C],\n    simp, },\n  { have : a = 0 := by omega, simp [this], },\nend\n\nlemma finset.range_succ_succ (i : \u2115) :\nfinset.range i.succ.succ = insert 0  (insert 1 (finset.filter (\u03bb j, 1 < j) (finset.range i.succ.succ))):=\nbegin\n  ext,\n  simp,\n  cases a,\n  {finish},\n  cases a,\n  {finish},\n  finish,\nend\n\nlemma aux_lemma (a : \u2115) (f : \u2115 \u2192 R): ite (1 < a)  ((ite (0 = a) (1 : R) 0 - ite (1 = a) 1 0) * f a) (0 : R) = 0 :=\nbegin\n  cases a with a a,\n  { simp },\n  cases a with a a,\n  { simp },\n  have h0 : \u00ac 0 = a.succ.succ,\n  { \n    exact ne_zero.ne' (nat.succ a).succ,\n  },\n  have h1 : \u00ac 1 = a.succ.succ,\n  { \n    intro hc,\n    have hh : 0 = a.succ := nat.succ.inj hc,\n    finish,   \n  },\n  simp [h0, h1],\nend\n\nlemma coeff_X_sub_C_mul (i : \u2115):\n  p.coeff i = \u2211 j in finset.range (i+1), ((C (1 : R) - X) * p).coeff j :=\nbegin\n  induction i with i hi,\n    { simp },\n  rw finset.range_succ,\n  rw finset.sum_insert finset.not_mem_range_self,\n  rw \u2190 hi,\n  rw coeff_mul,\n  rw finset.nat.sum_antidiagonal_eq_sum_range_succ (\u03bb x y, (C (1:R)- X).coeff x * p.coeff y) (i.succ),\n  simp,\n  rw finset.range_succ_succ,\n  rw finset.sum_insert,\n  {\n    rw finset.sum_insert,\n    {\n      repeat {simp_rw coeff_one},\n      repeat {simp_rw coeff_X},\n      simp_rw [finset.sum_filter, aux_lemma],\n      simp,\n    },\n    {\n      simp,\n    }\n  },\n  {\n    simp,\n  }\nend\n\n-- Arthan's version\nlemma arthan (hp : coeff p 0 \u2260 0) :\n \u2203 (m : \u2115), ((X - C 1 : polynomial R) * p).num_sign_changes  =\n p.num_sign_changes + 2*m + 1:=\nbegin\nsorry\nend\n\n@[simp]\nlemma num_sign_changes_cX {c : R} (hc : 0 < c) : (p.comp (c \u2022 X)).num_sign_changes = p.num_sign_changes :=\nbegin\nsorry\nend\n\nlemma num_sign_changes_X_sub_C_mul'' {a : R} (ha: 0 < a) (hp : coeff p 0 \u2260 0) :\n \u2203 (m : \u2115), ((X - C a : polynomial R) * p).num_sign_changes  = p.num_sign_changes + 2*m + 1:=\nbegin\nhave hp' : coeff (p.comp (a\u2022X)) 0 \u2260 0, by sorry,\nobtain \u27e8m, hm\u27e9 := arthan hp',\nhave ha' : a \u2260 0 := ne_of_gt ha,\nhave ha'' : a\u207b\u00b9 \u2260 0 := inv_ne_zero ha',\nuse m,\n-- reduce to Arthan's lemma by using that p(cx) has the same number of sign changes as p(x)\ncalc\n((X - C a) * p).num_sign_changes  = (C a\u207b\u00b9 * ((X - C a) * p)).num_sign_changes : by {\n  rw show C a\u207b\u00b9 * ((X - C a) * p) = C a\u207b\u00b9 \u2022 ((X - C a) * p), by simp,\n  rw \u2190 polynomial.num_sign_changes_smul _ ha'',\n  simp,\n}\n... = (C a\u207b\u00b9 * ((C a * X - C a) * p.comp(a\u2022X))).num_sign_changes : by {rw \u2190 num_sign_changes_cX ha, simp}\n... = ((C a\u207b\u00b9 * (C a * X - C a)) * p.comp(a\u2022X)).num_sign_changes : by {simp}\n... = ((X - C 1) * p.comp(a\u2022X)).num_sign_changes : by {\n  rw show C a * X - C a = C a * (X - C 1), by ring_nf,\n  simp [ha'],\n  }\n... = (p.comp (a\u2022X)).num_sign_changes + 2 * m + 1 : hm\n... = p.num_sign_changes + 2 * m + 1 : by {rw num_sign_changes_cX ha}\nend\n\n\n-- Lemma 2 of Levin\n/--\nFor all \u03b1 > 0, the polynomial (X-\u03b1) * p has at least one more sign change than p\n-/\nlemma num_sign_changes_X_sub_C_mul' {x : R} (hx : 0 < x) (hp : coeff p 0 \u2260 0) :\n  p.num_sign_changes + 1 \u2264 ((X - C x : polynomial R) * p).num_sign_changes :=\nbegin\n  obtain \u27e8m,hm\u27e9 := num_sign_changes_X_sub_C_mul'' hx hp,\n  rw hm,\n  linarith,\nend\n\nlemma polynomial.root_iff_divides_X_sub_C {p : polynomial R} (hp : p \u2260 0) (\u03b1 : R) :\n\u2203 (q : polynomial R), p = (X-C \u03b1)^(p.root_multiplicity \u03b1) * q \u2227 q.eval \u03b1 \u2260 0 :=\nbegin\nhave H1 := @le_root_multiplicity_iff  _ _ _ hp \u03b1 (p.root_multiplicity \u03b1),\nsimp at H1,\nhave H2 := @root_multiplicity_le_iff  _ _ _ hp \u03b1 (p.root_multiplicity \u03b1),\nsimp at H2,\nobtain \u27e8q, hq\u27e9 := H1,\nuse q,\nsplit,\n  { exact hq },\nintro hc,\nreplace hc : is_root q \u03b1 := is_root.def.mpr hc,\nobtain \u27e8r, hr\u27e9 := dvd_iff_is_root.mpr hc,\napply H2,\nrw hr at hq,\nuse r,\ngeneralize hj : root_multiplicity \u03b1 p = j,\nrw hj at hq,\nrw hq,\nring_exp,\nend\n\nlemma polynomial.root_zero_iff_divides_X  {p : polynomial R} (hp : p \u2260 0)  :\n\u2203 q,  p = X^(p.root_multiplicity 0)  * q \u2227 (q.coeff 0 \u2260 0) :=\nbegin\n  obtain \u27e8q, hq\u27e9 := polynomial.root_iff_divides_X_sub_C hp 0,\n  use q,\n  simp at hq,\n  have H : q.coeff 0 = q.eval 0,\n  { simp only [eval, eval\u2082_at_zero, ring_hom.id_apply] },\n  rw H,\n  exact hq,\nend\n\nlemma num_sign_changes_X_sub_C_mul (hp : p \u2260 0) {x : R} (hx : 0 < x) :\n  p.num_sign_changes + 1 \u2264 ((X - C x : polynomial R) * p).num_sign_changes :=\nbegin\n  obtain \u27e8q, \u27e8h, hnz\u27e9\u27e9 := polynomial.root_zero_iff_divides_X hp,\n  have h' : (X - C x) * (q * X^(p.root_multiplicity 0)) = ((X - C x) * q) * X^(p.root_multiplicity 0),\n  { ring },\n  rw [h, mul_comm, polynomial.num_sign_changes_mul_X_pow, h', polynomial.num_sign_changes_mul_X_pow],\n  exact num_sign_changes_X_sub_C_mul' hx hnz,\nend\n\ntheorem descartes_sign_rule_1'  (hp : p \u2260 0) : p.number_positive_roots \u2264 p.num_sign_changes :=\nbegin\n  rw number_positive_roots,\n  induction h : p.positive_roots.card generalizing p hp,\n  { exact zero_le (p.num_sign_changes), },\n  { obtain \u27e8x, hx\u27e9 := card_pos_iff_exists_mem.mp (by rw h; exact nat.succ_pos n),\n    rw mem_positive_roots at hx,\n    rw \u2190 h,\n    have := mul_div_eq_iff_is_root.mpr ((mem_roots hp).mp hx.1),\n    rw \u2190 this at hp,\n    have hkey : (p / (X - C x)).positive_roots.card = n,\n    {\n      rw [\u2190 this, positive_roots_mul hp] at h,\n      simp [card_add, positive_roots_X_sub_C_of_zero_lt hx.2] at h,\n      exact nat.succ.inj h\n    },\n    have hp' : p / (X - C x) \u2260 0,\n    {\n      intro hc,\n      apply hp,\n      rw hc,\n      ring,\n    },\n    rw [\u2190 this, positive_roots_mul, card_add],\n    {\n    calc (X - C x).positive_roots.card + (p / (X - C x)).positive_roots.card = 1 + (p / (X - C x)).positive_roots.card : by simp [positive_roots_X_sub_C_of_zero_lt hx.2]\n      ... \u2264 1 + (p / (X - C x)).num_sign_changes : nat.add_le_add_left _ 1\n      ... = (p / (X - C x)).num_sign_changes + 1 : add_comm _ _\n      ... \u2264 ((X - C x) * (p / (X - C x))).num_sign_changes : num_sign_changes_X_sub_C_mul hp' hx.2,\n      rw hkey,\n      apply ih (right_ne_zero_of_mul hp),\n      exact hkey,\n    },\n    exact hp,\n  },\nend\n\ntheorem descartes_sign_rule_1 (hp : p \u2260 0) : p.number_positive_roots \u2264 p.num_sign_changes :=\nbegin\n  by_cases hp0 :  p.coeff 0 = 0,\n  {\n    sorry\n  },\n  {\n    exact descartes_sign_rule_1' hp,\n  }\nend\n\nlemma list.parity_sign (S : list \u211d) (h: S \u2260 []) : even (S.num_sign_changes - bool.to_nat (S.head * (S.last h) < 0)) :=\nbegin\n  sorry\nend\n\ntheorem descartes_sign_rule_2' {f : polynomial R} (hf : f.monic) : even (f.num_sign_changes - f.number_positive_roots) :=\nbegin\n  sorry\nend\n\ntheorem descartes_sign_rule_2 {f : polynomial R} (hf : f \u2260 0) : even (f.num_sign_changes - f.number_positive_roots) :=\nbegin\n  rw \u2190 num_sign_changes_normalize_eq_num_sign_changes,\n  rw number_positive_roots,\n  rw \u2190positive_roots_normalize_eq_positive_roots,\n  exact descartes_sign_rule_2' (polynomial.monic_normalize hf),\nend", "meta": {"author": "mmasdeu", "repo": "ruleofsigns", "sha": "80f5c2de14f3db0bec7d0bb5d456669fb9077ede", "save_path": "github-repos/lean/mmasdeu-ruleofsigns", "path": "github-repos/lean/mmasdeu-ruleofsigns/ruleofsigns-80f5c2de14f3db0bec7d0bb5d456669fb9077ede/src/main.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7379519767019954}}
{"text": "import game.sets.sets_level01 -- hide\n\nnamespace xena -- hide\n\nopen_locale classical -- hide\n\nvariable X : Type -- hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 2 : union (\u222a)\n-/\n\n/- \nWorking with sets is very similar to working with propositions.\nLet's now prove that any set $A$ is included in its union with \nany other set $B$, or $A \u2286 A \u222a B$. To work with unions you will\nneed to know the property which classifies them:\n\n```\nmem_union_iff : x \u2208 A \u222a B \u2194 x \u2208 A \u2228 x \u2208 B\n```\n\nYou need to get yourself into a situation where the left hand side\nof `mem_union_iff` is in your goal; that way, you can `rw mem_union_iff`\nand make progress.\n-/\n\n/- Axiom : mem_union_iff :\nx \u2208 A \u222a B \u2194 x \u2208 A \u2228 x \u2208 B\n-/\n\n/- Hint : Tactic tip : intros\n`intros` is like `intro` but can be used to introduce more than one\nthing at once. For example if your goal is `\u22a2 \u2200 (x : X), x \u2208 A \u2192 x \u2208 A \u222a B`\nthen `intros x hx` will do the same as `intro x, intro hx`.\n-/\n\n/- Hint : Stuck?\nWe start with a rewrite (see level 1).\nThen, after introducing your terms, you'll be able to pull off\nthe second rewrite. Finally, you'll need to prove the `left`\nside of an `or` goal.\n-/\n\n\n/- Lemma\nIf $A$ and $B$ are sets of any type $X$, then\n$$ A \\subseteq A\\cup B.$$ \n-/\ntheorem subset_union_left (A B : set X) : A \u2286 A \u222a B :=\nbegin\n  rw subset_iff,\n  intro h,\n  intro f,\n  left,\n  exact f,\n  \nend\n\nend xena --hide\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/sets/sets_level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7379053596418089}}
{"text": "import limits Bolzano_Weierstrass\n\nnoncomputable theory\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n-- the maths starts here.\n\n-- We introduce the usual mathematical notation for absolute value\nlocal notation `|` x `|` := abs x\n\ndef is_cauchy (a : \u2115 \u2192 \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 m \u2265 N, \u2200 n \u2265 N, |a m - a n| < \u03b5 \n\n/- TODO: merge with monotone.lean\n-- is_subsequence b a means b is a subsequence of a\ndef is_subsequence (b : \u2115 \u2192 \u211d) (a : \u2115 \u2192 \u211d) : Prop :=\n\u2203 s : \u2115 \u2192 \u2115, b = a \u2218 s \u2227 \u2200 m : \u2115, s m < s (m + 1)\n\ndef is_monotone (b : \u2115 \u2192 \u211d) : Prop :=\n(\u2200 m, b m \u2264 b (m + 1)) \u2228 \u2200 m, b (m + 1) \u2264 b m \n\ntheorem exists_monotone (a : \u2115 \u2192 \u211d) :\n\u2203 b : \u2115 \u2192 \u211d, is_subsequence b a \u2227 is_monotone b := sorry -/\n\ntheorem bounded_of_bounded_shift (a : \u2115 \u2192 \u211d) (N : \u2115) :\n  M1P1.is_bounded (\u03bb k, a (N + k)) \u2192 M1P1.is_bounded a :=\nnat.rec_on N (by simp only [zero_add, imp_self]) $ \u03bb N ih ha, ih $\nlet \u27e8M, HM\u27e9 := ha in \u27e8max M ( |a N| ), \u03bb y,\nnat.cases_on y (le_max_right _ _) $ \u03bb y,\nle_trans (by convert HM y; simp only [nat.succ_add]) (le_max_left _ _)\u27e9\n\ntheorem bounded_of_cauchy (a : \u2115 \u2192 \u211d) : is_cauchy a \u2192 M1P1.is_bounded a :=\n\u03bb ha, let \u27e8N, hn\u27e9 := ha 1 zero_lt_one in bounded_of_bounded_shift a N \u27e8|a N| + 1, \u03bb k,\ncalc  |a (N + k)|\n    \u2264 |a N + (a (N + k) - a N)| : by rw add_sub_cancel'_right\n... \u2264 |a N| + |a (N + k) - a N| : abs_add_le_abs_add_abs _ _\n... \u2264 |a N| + 1 : add_le_add_left (le_of_lt $ hn _ (nat.le_add_right _ _) _ (le_refl _)) _\u27e9\n\ntheorem cauchy_implies_convergent (a : \u2115 \u2192 \u211d) : is_cauchy a \u2192 M1P1.has_limit a :=\n\u03bb ha, let \u27e8s, hsi, L, hsL\u27e9 := bolzano_weierstrass a (bounded_of_cauchy a ha) in \u27e8L, \u03bb \u03b5 H\u03b5,\nlet \u27e8N1, HN1\u27e9 := ha (\u03b5/2) (half_pos H\u03b5) in\nlet \u27e8N2, HN2\u27e9 := hsL (\u03b5/2) (half_pos H\u03b5) in\n\u27e8max N1 N2, \u03bb n hn,\nhave hn1 : N1 \u2264 n, from le_trans (le_max_left _ _) hn,\nhave hn2 : N2 \u2264 n, from le_trans (le_max_right _ _) hn,\ncalc  |a n - L|\n    \u2264 |a n - a (s n)| + |a (s n) - L| : abs_sub_le _ _ _\n... < \u03b5/2 + \u03b5/2 : add_lt_add (HN1 _ hn1 _ $ le_trans hn1 $ n.le_of_strictly_increasing s hsi) (HN2 _ hn2)\n... = \u03b5 : add_halves \u03b5\u27e9\u27e9\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1P1-lean", "sha": "3723468cc50f8bebd00a9811caf25224a578de17", "save_path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean", "path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean/M1P1-lean-3723468cc50f8bebd00a9811caf25224a578de17/src/cauchy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.737864107298302}}
{"text": "import data.set.basic -- hide\nimport set_theory_world.image_tutorial\nimport tactic -- hide\n\n/-\n\n## The image of a union\n\nIn this level we prove that the image of a union of two sets if the union of their images.\n\nIn Lean, `x \u2208 A \u222a B` is the same as `x \u2208 A \u2228 x \u2208 B`, so the `left/right` tactics work in the goal, as well\nas the `cases` one in a hypothesis.\n-/\n\nopen set -- hide\nvariables{X Y: Type} -- hide\n\n/- Lemma\n$ f(A \u222a B) = f(A) \u222a f(B) $\n-/\nlemma image_union (f : X \u2192 Y) (A B : set X) : f '' (A \u222a B) = f '' A \u222a f '' B :=\nbegin\n  ext y,\n  split,\n  {\n    intro h1,\n    cases h1,\n    cases h1_h,\n    cases h1_h_left,\n    {\n      left, \n      rw \u2190 h1_h_right,\n      use [h1_w, h1_h_left],\n    },\n    {\n      right,\n      rw  \u2190 h1_h_right,\n      use [h1_w, h1_h_left],\n    },\n  },\n  {\n    intro h1,\n    cases h1,\n    {\n      cases h1,\n      cases h1_h,\n      rw \u2190 h1_h_right,\n      use h1_w,\n      split,\n      {\n        left,\n        assumption,\n      },\n      refl,\n    },\n    {\n      cases h1,\n      cases h1_h,\n      rw \u2190 h1_h_right,\n      use h1_w,\n      split,\n      {\n        right,\n        assumption,\n      },\n      refl,\n    },\n  },\n\n\n\n\n\n\n\nend\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/set_theory_world/image_union.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.737864106999936}}
{"text": "import galois.tactic\n       galois.nat.simplify_le\n\ndef nat_to_fin_option (k n : \u2115) : option (fin k)\n  := if H : n < k then some \u27e8 _, H \u27e9 else none\n\nnamespace fin\n\nlemma fin_0_empty (x : fin 0) : false :=\nbegin\ninduction x,\napply nat.lt_irrefl,\napply lt_of_le_of_lt, tactic.swap,\nassumption, apply nat.zero_le,\nend\n\nlemma val_inj {n : \u2115} (i j : fin n)\n  (H : i.val = j.val) : i = j\n:= begin\ninduction i, induction j, dsimp at H, induction H,\nreflexivity,\nend\n\nlemma succ_pred_id {k : \u2115} (i : fin k.succ)\n  (H : i \u2260 0)\n  : fin.succ (fin.pred i H) = i\n:= begin\ninduction i,\ndsimp [fin.pred, fin.succ],\ncases val, exfalso, apply H, unfold has_zero.zero,\ndsimp [nat.pred], reflexivity,\nend\n\nlemma succ_pred_equiv {k : \u2115} (i : fin k.succ)\n  (H : i \u2260 0)\n  (n : \u2115)\n : (i.val = nat.succ n) \u2194 ((fin.pred i H).val = n)\n:= begin\ninduction i, dsimp [fin.pred],\ncases val, exfalso, apply H,\nunfold has_zero.zero,\ndsimp [nat.pred], split; intros H',\ninjection H', subst H',\nend\n\nend fin\n\nlemma nat_to_fin_option_pred_none {n i : \u2115}\n  : nat_to_fin_option n.succ i.succ = none\n  \u2192 nat_to_fin_option n i = none\n:= begin\nunfold nat_to_fin_option,\napply (if Hlt : i.succ < n.succ then _ else _),\n{ rw (dif_pos Hlt), intros H,\n  contradiction,\n},\n{ rw (dif_neg Hlt), intros H', clear H',\n  have H : \u00ac (i < n),\n  intros contra, apply Hlt,\n  apply nat.succ_lt_succ, assumption,\n  rw (dif_neg H),\n}\nend\n\nlemma nat_to_fin_option_succ_nz {n k : \u2115} {i : fin n.succ}\n  : nat_to_fin_option n.succ k.succ = some i\n  \u2192 i \u2260 0\n:= begin\ndsimp [nat_to_fin_option],\napply (if H : (nat.succ k < nat.succ n) then _ else _),\n{ rw (dif_pos H), intros H', injection H' with H'', clear H',\n  intros contra, subst i, injection contra,\n  injection h_1,\n},\n{ rw (dif_neg H), intros contra, contradiction, }\nend\n\nlemma nat_to_fin_option_pred_some {n k : \u2115} (i : fin n.succ)\n  : \u2200 H : nat_to_fin_option n.succ k.succ = some i\n  , nat_to_fin_option n k = some (i.pred (nat_to_fin_option_succ_nz H))\n:= begin\ndsimp [nat_to_fin_option],\nintros H,\napply (if H' : (nat.succ k < nat.succ n) then _ else _),\n{ rw (dif_pos H') at H, injection H with H2, clear H,\n  rw nat.succ_lt_succ_iff at H',\n  rename H' H'1,\n  rw (dif_pos H'1), f_equal, subst i,\n  dsimp [fin.pred], reflexivity,\n},\n{ rw (dif_neg H') at H, contradiction, }\nend\n\nlemma nat_to_fin_option_val {n k : \u2115} {i : fin n}\n  (H : nat_to_fin_option n k = some i)\n  : i.val = k\n:= begin\ndsimp [nat_to_fin_option] at H,\napply (if H' : k < n then _ else _),\n{ rw (dif_pos H') at H, injection H with H2,\n  clear H, subst i,\n},\n{ rw (dif_neg H') at H, contradiction }\nend", "meta": {"author": "GaloisInc", "repo": "lean-protocol-support", "sha": "cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda", "save_path": "github-repos/lean/GaloisInc-lean-protocol-support", "path": "github-repos/lean/GaloisInc-lean-protocol-support/lean-protocol-support-cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda/galois/fin/default.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488296, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7377732188944062}}
{"text": "notation \"\u2124\" => Int\n\nsection\n  variable (x y : Nat)\n\n  def double := x + x\n\n  #check double y\n  #check double (2 * x)\n\n  attribute [local simp] Nat.add_assoc Nat.add_comm Nat.add_left_comm\n\n  theorem t1 : double (x + y) = double x + double y := by\n    simp [double]\n\n  #check t1 y\n  #check t1 (2 * x)\n\n  theorem t2 : double (x * y) = double x * y := by\n    simp [double, Nat.add_mul]\nend\n\ntheorem eight_equals_twice_four : 8 = 2 * 4 := by\n  simp\n\ndef twice (f : Nat \u2192 Nat) (a : Nat) :=\n  f (f a)\n\ndef foo (x : Nat) := x + 2\ndef goo (x : Nat) : Nat := x + 2\n#check foo\n#check goo\n\n-- The `where` syntax.\n\nstructure IntWithParity where\n  value : \u2124\n  even  : Bool\n  deriving Repr\n\ndef increment_int_with_parity (x : IntWithParity) : IntWithParity where\n  value := x.value + 1\n  even  := \u00acx.even\n\n#eval increment_int_with_parity (IntWithParity.mk 0 true)\n#eval increment_int_with_parity <| increment_int_with_parity <| (IntWithParity.mk 0 true)\n\nuniverse u\n\n-- Playing with records.\nstructure Point (\u03b1 : Type u) where\n  x : \u03b1\n  y : \u03b1\n  deriving Repr\n\n#check Point.mk\n#check Point.mk 0 0\n\ndef eight := 8\n#eval s!\"The cube of two is {eight}\"\n\ndef p\u2081 : Point Int := Point.mk 0 0\n\n-- When can we use `let`?\ndef fn :=\n  let a := 2\n  a\n-- let a := 0 (This doesn't work, because `let` must be in a local scope?)\n\n#eval fn\n\n#check p\u2081\n#eval p\u2081\n\n-- Checking multiple things at the same time (you can't).\n#check 0 -- This works!\n-- #check 0 0 (This doesn't work.)\n\n-- Can we use string literals on the left-hand side of a lambda `=>` definition? No.\n#check_failure \u03bb \"a\" => \"a\"\n\n-- Pipelining.\ndef add1 x := x + 1\ndef times2 x := x * 2\n\n#eval times2 (add1 100)\n#eval 100 |> add1 |> times2\n#eval times2 <| add1 <| 100\n\n-- Two different ways of defining a function.\ndef identity : Nat \u2192 Nat := \u03bb x => x\ndef identity2 (x : Nat) : Nat := x\n\n#check identity\n\n#eval identity 5\n#eval identity2 6\n\n-- Multiple parameters of the same type declared within the same declaration.\n\ndef add_two_naturals (a b : Nat) : Nat := a + b\n\n#check add_two_naturals\n#eval add_two_naturals 4 5\n\ndef multiply (a b : Int) : Int := a * b\n#eval multiply 7 (-8)\n\n-- Array literal declaration and subscripts.\n#eval #['a', 'b', 'c'][4]\n#eval #['b', 'c', 'd'][4]\n#eval #[1, 2, 3][4]\n#eval #[\"a\", \"aa\", \"aaa\"][4]\n\ndef add_two_naturals_with_shorthand_notation_for_integers (a b : \u2124) : \u2124 := a + b\n#eval add_two_naturals_with_shorthand_notation_for_integers 8 9\n\ninductive Tree (\u03b2 : Type v) where\n | leaf : Tree \u03b2\n | node (left : Tree \u03b2) (key : Nat) (value : \u03b2) (right : Tree \u03b2) : Tree \u03b2\nderiving Repr\n\n def walk [ToString \u03b2] : Tree \u03b2 \u2192 String\n   | .leaf          => \"leaf\"\n   | .node l k v r  => s!\"node: {k} {v}\\n{walk l}\\n{walk r}\"\n\n/-\ndef construct_tree : IO Unit := do\n  let tree : Tree String \u2190 Tree.node (Tree.leaf) 0 \"value\" (Tree.leaf)\n-/\n\n\n\n-- Exploring `do` notation.\ndef main : IO UInt32 := do\n  IO.println \"hello\"\n  IO.println \"world\"\n  return 0\n\n-- What does the notation used above in `main` do?\n-- The below is the same function *without* `do` notation.\n-- Let's look at the type of `bind`, as in https://leanprover.github.io/lean4/doc/do.html\n#check bind\n\n-- It's `{m : Type u_1 \u2192 Type u_2} \u2192 [self : Bind m] \u2192 {\u03b1 \u03b2 : Type u_1} \u2192 m \u03b1 \u2192 (\u03b1 \u2192 m \u03b2) \u2192 m \u03b2`\n-- And ignoring all the implicit arguments, we have `m \u03b1 \u2192 (\u03b1 \u2192 m \u03b2) \u2192 m \u03b2`.\n-- Well, what are `m \u03b1` and `(\u03b1 \u2192 m \u03b2)` in the below?\ndef mainInt : IO UInt32 :=\n  bind (IO.println \"hello\") fun _ =>\n  bind (IO.println \"world\") fun _ =>\n  pure 0\n\n-- Let's rewrite `mainInt` to find out:\ndef mainIntExpanded : IO UInt32 :=\n  bind (IO.println \"hello\") (fun _ => bind (IO.println \"world\") (fun _ => pure 0))\n\n-- So we see the second argument to the first `bind` call is actually\n-- everything from `fun` (which you should recall defines an anonymous lambda\n-- function) in the first line, all the way to the end. This might be obvious\n-- to someone coming from e.g. Haskell, but it was not to me. The hanging\n-- lambda function definition looked like it might be a syntax error. But of\n-- course it isn't because it typechecks.\n\n-- Let's cut out the second bind call to make things easier to look at:\ndef mainIntSimplified : IO UInt32 :=\n  bind (IO.println \"hello world\") (\u03bb _ => pure 0)\n\n-- So   `(IO.println \"hello world\")`  is our `m \u03b1` ...\n-- And  `(\u03bb _ => pure 0)`             is our `(\u03b1 \u2192 m \u03b2)`.\n\n-- What are `\u03b1` and `\u03b2` in this example?\n-- Let's `#check` the arguments to find out.\ndef m_\u03b1 := IO.println \"hello world\"\n#check m_\u03b1\n\n-- We must explicitly set the type we expect below, or we get an `instance\n-- problem stuck` error.\ndef \u03b1_to_m_\u03b2 : Unit \u2192 IO UInt32 := (\u03bb _ => pure 0)\n#check \u03b1_to_m_\u03b2\n\n\n-- Investigating the `<|>` operator.\n#check true\n#check false\n#check true <|> false\n\nvariable (a b c d e : Nat)\nvariable (h1 : a = b)\nvariable (h2 : b = c + 1)\nvariable (h3 : c = d)\nvariable (h4 : e = 1 + d)\n\ntheorem T : a = e :=\n  calc\n    a = b      := h1\n    _ = c + 1  := h2\n    _ = d + 1  := congrArg Nat.succ h3\n    _ = 1 + d  := Nat.add_comm d 1\n    _ = e      := Eq.symm h4\n\n\ndef isEmpty {\u03b1 : Type u} : List \u03b1 \u2192 Bool\n  | [] => true\n  | _ :: _ => false\n", "meta": {"author": "langfield", "repo": "Cheat.lean", "sha": "8b6c4a6cdd3c083d93020651a4cbf6412c0e6f6a", "save_path": "github-repos/lean/langfield-Cheat.lean", "path": "github-repos/lean/langfield-Cheat.lean/Cheat.lean-8b6c4a6cdd3c083d93020651a4cbf6412c0e6f6a/Main.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.737773209019287}}
{"text": "import data.real.basic\n\nimport analysis.special_functions.pow\n\n/-- Let <math>\\mathbb{R}</math> be the set of real numbers. Determine all functions <math>f</math>:<math>\\mathbb{R}\\rightarrow\\mathbb{R}</math> satisfying the equation\n\n<math></math>\n\nfor all real numbers <math>x</math> and <math>y</math>.\n\n--/\n\ntheorem exo (f: real -> real):\n  (forall x y, f(x+f(x+y))+f(x*y) = x+f(x+y)+y*f(x))\n  -> ((forall x, f x = x) \\/ (forall x, f x = 2-x))\n:= sorry", "meta": {"author": "ahayat16", "repo": "lean_exos", "sha": "682f2552d5b04a8c8eb9e4ab15f875a91b03845c", "save_path": "github-repos/lean/ahayat16-lean_exos", "path": "github-repos/lean/ahayat16-lean_exos/lean_exos-682f2552d5b04a8c8eb9e4ab15f875a91b03845c/src_icannos_totilas/aops/2015-IMO-Problem_5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7377281579781774}}
{"text": "/-\nCopyright (c) 2022 Antoine Labelle. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Labelle\n-/\nimport representation_theory.basic\nimport representation_theory.Rep\n\n/-!\n# Subspace of invariants a group representation\n\nThis file introduces the subspace of invariants of a group representation\nand proves basic results about it.\nThe main tool used is the average of all elements of the group, seen as an element of\n`monoid_algebra k G`. The action of this special element gives a projection onto the\nsubspace of invariants.\nIn order for the definition of the average element to make sense, we need to assume for most of the\nresults that the order of `G` is invertible in `k` (e. g. `k` has characteristic `0`).\n-/\n\nopen_locale big_operators\nopen monoid_algebra\nopen representation\n\nnamespace group_algebra\n\nvariables (k G : Type*) [comm_semiring k] [group G]\nvariables [fintype G] [invertible (fintype.card G : k)]\n\n/--\nThe average of all elements of the group `G`, considered as an element of `monoid_algebra k G`.\n-/\nnoncomputable def average : monoid_algebra k G :=\n  \u215f(fintype.card G : k) \u2022 \u2211 g : G, of k G g\n\nlemma average_def : average k G = \u215f(fintype.card G : k) \u2022 \u2211 g : G, of k G g := rfl\n\n/--\n`average k G` is invariant under left multiplication by elements of `G`.\n-/\n@[simp]\ntheorem mul_average_left (g : G) :\n  (finsupp.single g 1 * average k G : monoid_algebra k G) = average k G :=\nbegin\n  simp only [mul_one, finset.mul_sum, algebra.mul_smul_comm, average_def, monoid_algebra.of_apply,\n    finset.sum_congr, monoid_algebra.single_mul_single],\n  set f : G \u2192 monoid_algebra k G := \u03bb x, finsupp.single x 1,\n  show \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f (g * x) = \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f x,\n  rw function.bijective.sum_comp (group.mul_left_bijective g) _,\nend\n\n/--\n`average k G` is invariant under right multiplication by elements of `G`.\n-/\n@[simp]\ntheorem mul_average_right (g : G) :\n  average k G * finsupp.single g 1 = average k G :=\nbegin\n  simp only [mul_one, finset.sum_mul, algebra.smul_mul_assoc, average_def, monoid_algebra.of_apply,\n    finset.sum_congr, monoid_algebra.single_mul_single],\n  set f : G \u2192 monoid_algebra k G := \u03bb x, finsupp.single x 1,\n  show \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f (x * g) = \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f x,\n  rw function.bijective.sum_comp (group.mul_right_bijective g) _,\nend\n\nend group_algebra\n\nnamespace representation\n\nsection invariants\n\nopen group_algebra\n\nvariables {k G V : Type*} [comm_semiring k] [group G] [add_comm_monoid V] [module k V]\nvariables (\u03c1 : representation k G V)\n\n/--\nThe subspace of invariants, consisting of the vectors fixed by all elements of `G`.\n-/\ndef invariants : submodule k V :=\n{ carrier := set_of (\u03bb v, \u2200 (g : G), \u03c1 g v = v),\n  zero_mem' := \u03bb g, by simp only [map_zero],\n  add_mem' := \u03bb v w hv hw g, by simp only [hv g, hw g, map_add],\n  smul_mem' := \u03bb r v hv g, by simp only [hv g, linear_map.map_smul\u209b\u2097, ring_hom.id_apply]}\n\n@[simp]\nlemma mem_invariants (v : V) : v \u2208 invariants \u03c1 \u2194 \u2200 (g: G), \u03c1 g v = v := by refl\n\nlemma invariants_eq_inter :\n  (invariants \u03c1).carrier = \u22c2 g : G, function.fixed_points (\u03c1 g) :=\nby {ext, simp [function.is_fixed_pt]}\n\nvariables [fintype G] [invertible (fintype.card G : k)]\n\n/--\nThe action of `average k G` gives a projection map onto the subspace of invariants.\n-/\n@[simp]\nnoncomputable def average_map : V \u2192\u2097[k] V := as_algebra_hom \u03c1 (average k G)\n\n/--\nThe `average_map` sends elements of `V` to the subspace of invariants.\n-/\ntheorem average_map_invariant (v : V) : average_map \u03c1 v \u2208 invariants \u03c1 :=\n\u03bb g, by rw [average_map, \u2190as_algebra_hom_single, \u2190linear_map.mul_apply, \u2190map_mul (as_algebra_hom \u03c1),\n            mul_average_left]\n\n/--\nThe `average_map` acts as the identity on the subspace of invariants.\n-/\ntheorem average_map_id (v : V) (hv : v \u2208 invariants \u03c1) : average_map \u03c1 v = v :=\nbegin\n  rw mem_invariants at hv,\n  simp [average_def, map_sum, hv, finset.card_univ, nsmul_eq_smul_cast k _ v, smul_smul],\nend\n\ntheorem is_proj_average_map : linear_map.is_proj \u03c1.invariants \u03c1.average_map :=\n\u27e8\u03c1.average_map_invariant, \u03c1.average_map_id\u27e9\n\nend invariants\n\nnamespace lin_hom\n\nuniverses u\n\nopen category_theory Action\n\nvariables {k : Type u} [comm_ring k] {G : Group.{u}}\n\nlemma mem_invariants_iff_comm {X Y : Rep k G} (f : X.V \u2192\u2097[k] Y.V) (g : G) :\n  (lin_hom X.\u03c1 Y.\u03c1) g f = f \u2194 X.\u03c1 g \u226b f = f \u226b Y.\u03c1 g :=\nbegin\n  rw [lin_hom_apply, \u2190\u03c1_Aut_apply_inv, \u2190linear_map.comp_assoc, \u2190Module.comp_def, \u2190Module.comp_def,\n  iso.inv_comp_eq, \u03c1_Aut_apply_hom], exact comm,\nend\n\n/-- The invariants of the representation `lin_hom X.\u03c1 Y.\u03c1` correspond to the the representation\nhomomorphisms from `X` to `Y` -/\n@[simps]\ndef invariants_equiv_Rep_hom (X Y : Rep k G) : (lin_hom X.\u03c1 Y.\u03c1).invariants \u2243\u2097[k] (X \u27f6 Y) :=\n{ to_fun := \u03bb f, \u27e8f.val, \u03bb g, (mem_invariants_iff_comm _ g).1 (f.property g)\u27e9,\n  map_add' := \u03bb _ _, rfl,\n  map_smul' := \u03bb _ _, rfl,\n  inv_fun := \u03bb f, \u27e8f.hom, \u03bb g, (mem_invariants_iff_comm _ g).2 (f.comm g)\u27e9,\n  left_inv := \u03bb _, by { ext, refl },\n  right_inv := \u03bb _, by { ext, refl } }\n\nend lin_hom\n\nend representation\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/representation_theory/invariants.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025423, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7377198430650264}}
{"text": "import linear_algebra.basic\nimport data.sum\nimport linear_algebra.finite_dimensional\nuniverses  u v w w' w''\nset_option pp.beta true\nnotation `\u03a3` := finset.sum finset.univ \n/-!\n    Goals : sudying familly of projector. \n    We start  by sudy i little projector. \n-/\nnamespace Projector \nopen linear_map\nvariables {R : Type u}[comm_ring R]{M : Type v}[add_comm_group M] [module R M] \n/-!\n    A linear map `p : M \u2192\u2097[R] M)` is a projector when `p * p = p`.\n-/\ndef  is_projector (p : M \u2192\u2097[R] M) := p * p = p\n\nlemma is_projector_ext {p : M \u2192\u2097[R]M} (hyp : is_projector p) : p * p = p := \nbegin unfold is_projector at hyp,exact hyp, end\n/--\n    if `p\u00b2 = p` then `(1-p)\u00b2 = 1 - p - p +p\u00b2 = ... = 1-p`\n-/\nlemma Complementary (p : M \u2192\u2097[R]M) (hyp : is_projector p) : is_projector (id - p) := begin\n    change linear_map.id - p with 1 -p,\n    have R : ( 1- p) * (1 -p) = 1 - p -(p - p * p),\n        exact mul_sub (1 - p) 1 p,\n    unfold is_projector,\n    rw R,\n    rw is_projector_ext hyp,\n    simp,\nend\nvariables (p : M\u2192\u2097[R]M)\n\nlemma Projector_apply (x : M) :  p \u2218 p =  \u21d1(p * p) := rfl   \n\nlemma image_in_range (x : M) : p x \u2208 range p := by apply mem_range.mpr; use x\n\n\nlemma ker_eq_im_comp (hyp : is_projector p) : range p = ker (id-p) := begin\n    apply submodule.ext,intros x,split,rintros \u27e8y,hyp  \u27e9, rw mem_ker, change x- p x = 0, rw \u2190 hyp.2, \n    change (p - p * p) y = 0, rw is_projector_ext, rw sub_self, exact rfl,assumption,\n    intros hyp, rw mem_ker at hyp, change x-p x = 0 at hyp, rw mem_range, use x,  \n    have R : x - p x + p x = p x,\n        rw hyp_1,\n        rw zero_add,\n    rw \u2190 R,simp,\n  end\n\n\ndef has_projector (P : submodule R M) := \n        \u2203 p : M \u2192\u2097[R]M, is_projector p \u2227 linear_map.range (p : M\u2192\u2097[R]M)  = P\n\n\nlemma proj_ker (p : M \u2192\u2097[R]M) (hyp : is_projector p) : \u2200 m : M, p m \u2208 ker (id - p) := \nbegin \n    rw \u2190 ker_eq_im_comp, exact image_in_range p,assumption,\nend \nlemma  calcul : linear_map.id - (id - p) = p := begin exact sub_sub_self id p, end\n\nlemma proj_im(p : M \u2192\u2097[R]M) (hyp : is_projector p) : \u2200 m : M, m - p m \u2208 ker (p) := \nbegin \n    let H := proj_ker (id-p) (Complementary p hyp),    \n    -- let H := specialize (proj_ker (id - p)) (Complementary p hyp)  -- unknown identifier 'specialize'\n    rw calcul at H,\n    exact H,\nend \nlemma projector_decomp (p : M \u2192\u2097[R]M) (hyp : is_projector p) : \n    \u2200 m : M,\u2203 m_im \u2208 range p, \u2203 m_ker \u2208 ker p, m = m_ker+ m_im  := begin \n        intros m,\n        use p m,\n        split, refine image_in_range _ m ,\n        use m - p m,\n        split,\n        apply proj_im,\n        assumption,simp,\n     end \nlemma Unicity (hyp : is_projector p) : (range p)  \u2293 (ker p)= \u22a5 :=  begin \n    rw eq_bot_iff,\n    rw submodule.le_def', intros x, rw submodule.mem_bot, intros, \n    rw submodule.mem_inf at H,\n    rcases H with \u27e8  IM, KER \u27e9 ,\n    rw mem_ker at KER, rw mem_range at IM, rcases IM with \u27e8 y,hyp_y\u27e9 ,\n    rw \u2190 hyp_y at KER, change (p * p) y = 0 at KER, rw is_projector_ext at KER, rw hyp_y at KER, \nassumption, assumption, \nend\nlemma projector.mem_range (x : M)(hyp : is_projector p) : x \u2208 range p \u2194  p x = x := begin \n    split, \n        intro hyp, rw mem_range at hyp, rcases hyp with \u27e8y,hyp_y \u27e9,\n        rw \u2190 hyp_y,\n        change p( p y) with (p *p) y,\n        rw (is_projector_ext hyp),\n        intro hyp,\n        rw \u2190 hyp,\n        apply image_in_range, \nend \n\n\nlemma projector_im_eq (p q : M\u2192\u2097[R] M) (hyp_p : is_projector p) (hyp_q : is_projector q) : \n            range  p =  range q \u2194  ( p * q = q) \u2227  (q * p = p) := begin  \n        split, \n        intro hyp,\n            split,\n                {ext,rw mul_app, rw \u2190 projector.mem_range, rw hyp,refine image_in_range q _, assumption},\n                {ext, rw mul_app,rw \u2190 projector.mem_range,rw \u2190 hyp,refine image_in_range p _, assumption},\n            intro, \n            apply submodule.ext,\n            intro x, split,\n                {intro,rw \u2190  a.2 at a_1,rw mem_range at *,rcases a_1,use p a_1_w, exact a_1_h,},\n                {intro,rw \u2190  a.1 at a_1,rw mem_range at *,rcases a_1,use q a_1_w, exact a_1_h,},\nend\n\ntheorem projector.caract_image (p : M\u2192\u2097[R]M) : (\u2200 x : range p, p x = x ) \u2192 is_projector p := begin \n    intro hyp, unfold is_projector,\n    ext,rw mul_app,\n    exact hyp \u27e8p x,image_in_range p x \u27e9, \nend\nlemma range_le_submodule (p : M\u2192\u2097[R]M) (W : submodule R M) : range p \u2264 W \u2194  \u2200 x : M,  p x \u2208 W := begin \n    split, intros hyp, intro x, let R := image_in_range p x,\n    rw submodule.le_def' at hyp,\n    exact hyp (p x) R,\n    intro,\n    rw submodule.le_def', intro x, intro hyp_range, rw mem_range at hyp_range, rcases hyp_range, \n    rw \u2190 hyp_range_h, exact a hyp_range_w,\nend\ntheorem projector.caract_image' (p : M\u2192\u2097[R]M) (W : submodule R M) : (range p \u2264 W \u2227 \u2200 w \u2208 W, p w = w) \u2192 (is_projector p\n\u2227 range p = W) := \nbegin \n    intros hyp,\n    split, \n        apply projector.caract_image,\n        intro y, \n        apply hyp.2 y,\n        rw submodule.le_def' at hyp,\n        apply hyp.1 y,\n        exact y.property,\n        apply le_antisymm , \n            exact hyp.1,\n            rintros w, \n            intro hyp_w,\n            change w \u2208 range p,\n            change w \u2208 W at hyp_w,\n            rw mem_range,\n            use w,\n            rw hyp.2,assumption,\nend\nlemma projector.right_mul (p f : M \u2192\u2097[R] M) [is_projector p] : \n    p * f = f  \u2194 \u2200 x : M, (x \u2208 range f \u2192  p x = x) := \nbegin \n    split, intro hyp, intro x, rw mem_range, rintros \u27e8a,b\u27e9, \n    rw \u2190 b, change (p * f) a = f a,\n    rw hyp,\n    intro hyp,\n    ext, exact hyp _  (image_in_range f x), \nend\n\nlemma range_bot_iff {R : Type u} [ comm_ring R]{M : Type v}[add_comm_group M][module R M] (f: M \u2192\u2097[R] M) \n: (f = 0) \u2194   linear_map.range f = \u22a5   := \nbegin  rw eq_bot_iff, rw linear_map.range_le_bot_iff f, \n end\nlemma linear_map.range_sub_ker (R : Type u) [ comm_ring R](M : Type v)[add_comm_group M][module R M] (f g : M \u2192\u2097[R] M) :\n                f * g = 0  \u2194 range g \u2264 ker f :=\nbegin\n    rw range_bot_iff (f * g),\n    rw linear_map.le_ker_iff_map, \n    erw \u2190 submodule.map_comp, exact iff.rfl,\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nlemma range_le_iff {p q : M \u2192\u2097[R] M} (hyp : is_projector p)(hypq : is_projector q) : p * q = q \u2194 range q \u2264 range p := \nbegin\n    split, \n    {intros hyp, rw \u2190 hyp, erw range_comp,apply submodule.map_mono, exact le_top,},\n    {intros hyp, ext x,\n        change p ( q x ) = q x,\n        have r : q x \u2208 range p, \n            apply hyp,\n            exact image_in_range q x ,\n        rw  (projector.mem_range p _ _).mp r, assumption,\n        },\nend \n\nlemma range_cap {p q : M \u2192\u2097[R] M} (hypp : is_projector p)(hypq : is_projector q) : p * q = 0 \u2192  range p \u2293 range q = \u22a5 := \nbegin\n     intros hyp,rw eq_bot_iff,rw submodule.le_def',\n    intros x, intro hyp, rw submodule.mem_bot,rcases hyp, erw projector.mem_range at hyp_left hyp_right,\n    rw \u2190 hyp_left, rw \u2190 hyp_right, change ( p * q ) x = 0, rw hyp,exact rfl, assumption, assumption,\nend\n\nend Projector \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nopen Projector\n\ndef \u03b4 {X : Type w''}[decidable_eq X] (x y : X) := if  x = y then 1 else 0\n\nstructure orthogonal_familly_of_projector \n(R : Type u)[comm_ring R](M : Type v)[add_comm_group M] [module R M] (X : Type w)[fintype X][decidable_eq X]  :=\n(\u03c0 :  X \u2192 M \u2192\u2097[R]M) \n(ortho : \u2200 x y : X, \u03c0 x * \u03c0 y = (\u03b4 x y) \u2022  \u03c0 x)\n\nnamespace orthogonal_familly_of_projector\nvariables {R : Type u}[comm_ring R]{M : Type v}[add_comm_group M] [module R M] \n          {X : Type w}[fintype X][decidable_eq X]\n          ( P : orthogonal_familly_of_projector R M X)\n--instance : has_coe_to_fun(orthogonal_familly_of_projector R M X) := \u27e8_, \u03bb P, P.\u03c0 \u27e9 \n@[simp]lemma ortho_ite (x y : X ) : P.\u03c0 x * P.\u03c0 y = if x = y then P.\u03c0 x else 0 := begin \n    rw P.ortho, \n    unfold \u03b4,\n    split_ifs,\n    rw one_smul,\n    rw zero_smul,\nend\nlemma single_is_projector (x : X) : is_projector (P.\u03c0 x) := begin \n    unfold is_projector, erw ortho_ite, simp, \nend\ndef Total : M\u2192\u2097[R]M := \u03a3 P.\u03c0    \n\n@[simp]lemma Fact : (\u03bb (x : X), \u03a3 P.\u03c0 * P.\u03c0 x)  = \u03bb x, P.\u03c0  x := begin \n    funext,erw finset.sum_mul,\n    simp,\nend\nlemma Fact1 (x : X) : P.\u03c0 x * Total P = P.\u03c0 x := begin \n    unfold Total,erw  finset.mul_sum, simp,\nend\n@[simp]theorem Total_is_projector : (Total P) * (Total P) = Total P := begin \n    unfold Total, erw finset.mul_sum, rw Fact, \nend\nlemma Fact2 (x : X) :  Total P * P.\u03c0 x = P.\u03c0 x := begin\n    unfold Total, erw finset.sum_mul,simp,\nend\n\ndef Range : submodule R M :=  linear_map.range (\u03a3  P.\u03c0) \n\n@[simp] lemma Total_range : linear_map.range (Total P) = Range P := rfl\n\nlemma single_range_sub_total_( x: X ) : linear_map.range (P.\u03c0 x) \u2264 Range P := begin \n    apply (range_le_iff (Total_is_projector P) (single_is_projector P x) ).mp, \n    unfold Total,erw finset.sum_mul,\n    simp,\nend\n\nend orthogonal_familly_of_projector\nnamespace Ortho_of_familly\nopen orthogonal_familly_of_projector\nvariables {R : Type u}[comm_ring R]{M : Type v}[add_comm_group M] [module R M] \n          {X : Type w}[fintype X][decidable_eq X]\n          ( P : orthogonal_familly_of_projector R M X)\nvariables  {Y : Type w'}[fintype Y][decidable_eq Y]  \n          (Q : orthogonal_familly_of_projector R M Y)\n\ndef ortho  := \u2200 x : X, \u2200 y : Y,  P.\u03c0 x  *  Q.\u03c0 y = 0 \n@[simp]lemma ortho_simp (x : X) (y : Y) : ortho P Q  \u2192 P.\u03c0  x * Q.\u03c0 y = 0 := \nbegin \n    intros hyp, exact hyp x y,\nend\n@[simp]lemma ortho_simp'  (y : Y) (hyp : ortho P Q) : (\u03bb x : X,  P.\u03c0  x * Q.\u03c0 y) = (\u03bb x, 0) := \nbegin \n    funext, exact hyp x y,\nend\n@[simp]lemma ortho_mul_right (hyp : ortho P Q) : (\u03bb y :Y, (Total P) * Q.\u03c0 y) = 0 := \nbegin funext,\n    erw finset.sum_mul,\n    erw ortho_simp',\n    simp, assumption,\nend \n@[simp]lemma ortho_mul_total_eq_zero  : ortho P Q \u2194  (Total P ) * (Total Q) = 0 := \nbegin split,\n    intros hyp, erw finset.mul_sum, erw (ortho_mul_right P Q hyp), simp,\n    intros,unfold ortho,\n    intros x y,erw \u2190 Fact1, erw \u2190 Fact2 Q y, rw  mul_assoc, rw \u2190  mul_assoc (Total P) _  _,rw a, \n    rw zero_mul, rw mul_zero,\nend\n/--\n    Faire attention ici \n    theoreme du rang ? n = range(p) + ker(p) ...   dim (range p + range q) = dim range p + dim range q\n-/\ntheorem ortho_iff : ortho P Q \u2192   Range P  \u2293 Range Q = \u22a5 := \nbegin\n    rw ortho_mul_total_eq_zero, apply range_cap, exact Total_is_projector P, \n    exact Total_is_projector Q,\n    \nend    \n#check X \u2295 Y\nnamespace Test\nvariables \n(P1 : orthogonal_familly_of_projector R  M X)  (P2 : orthogonal_familly_of_projector R  M Y)\n/--\n    Faire mieux avec les complementaires ! \n-/\ntheorem add :   ortho P1 P2 \u2227  ortho P2 P1 \u2192 orthogonal_familly_of_projector R M (X \u2295 Y) := \u03bb certif,\n { \u03c0 := sum.elim P1.\u03c0 P2.\u03c0,\n  ortho := \nbegin \n        intros, rcases x,rcases y,unfold \u03b4,simp,split_ifs,rw one_smul,rw zero_smul,unfold \u03b4,simp,\n        exact certif.1 x y,\n        rcases y,unfold \u03b4, simp, exact certif.2 x y,\n        unfold \u03b4, simp, -- ite smul ? \n        split_ifs,rw one_smul, rw zero_smul,\n  end }\nend Test \n\nend Ortho_of_familly\nstructure complete_orthogonal_familly_of_projector\n(R : Type u)[comm_ring R](M : Type v)[add_comm_group M] [module R M] (X : Type w)[fintype X][decidable_eq X]\nextends orthogonal_familly_of_projector R M X :=\n(complete : \u03a3 \u03c0 = 1)\n\n/-!\n    vector space of finite dimension\n-/\nnamespace vector_space\nvariables {K : Type u}[field K]{V : Type v}[add_comm_group V] [vector_space K V] {\u03b9 : Type w} \n[fintype \u03b9] {b : \u03b9 \u2192 V} (h : is_basis K b)[W : submodule K V ]\n#check exists_is_basis K W\n\n#check exists_subset_is_basis\n#check (@zero_ne_one K _)\n\n\nexample {K : Type u}[field K]{V : Type v}[add_comm_group V] [vector_space K V] {\u03b9 : Type w} \n[fintype \u03b9] {b : \u03b9 \u2192 V} (h : is_basis K b)[W : submodule K V ] : true := begin \n    let F := exists_is_basis K W,\n    rcases F with \u27e8B,hyp\u27e9,\n    have  f : linear_independent K (\u03bb (i : B), submodule.subtype W i.val ),\n    let f :=  linear_independent.image_subtype hyp.1,\n    \n    \n    \n    --- linear_independant image injective avec l'injection canonique !\n    \n            \n        \n    --let H := @exists_subset_is_basis K  V _ _ _  _, --- probleme de convertion de set\n\n\nend\nend vector_space", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep1/Projection/projector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7376992723843003}}
{"text": "variables A B P Q R S : Prop.\n\nlemma exL (H1 : P \u2192 Q)\n          (H2 :  R \u2192 S) : (P \u2228 R) \u2192 (Q \u2228 S) :=\n\n          assume H3 : (P \u2228 R),\n          \n          (or.elim H3\n                   (assume H : P, show Q \u2228 S, from (or.intro_left S (H1 (show P, from (H)))))\n                   (assume H : R, show Q \u2228 S, from (or.intro_right Q (H2 (show R, from (H)))))).\n\n\nlemma exM (H1 : Q \u2192 R) : (P \u2192 Q) \u2192 (P \u2192 R) :=\n\n          assume H2 : (P \u2192 Q),\n          assume H3 : P,\n          show R, from (H1 (show Q, from (H2 (show P, from (H3))))).\n\n\nlemma exA (H1 : \u00ac(A \u2228 B)) : \u00acA \u2227 \u00acB :=\n\n          and.intro (assume H2 : A, (show false, from (H1 (or.intro_left B H2))))\n\n                    (assume H3 : B, show false, from (H1(or.intro_right A H3))).\n                    \n\nlemma exB (H1 : (\u00acA) \u2227 (\u00acB)) : \u00ac (A \u2228 B) :=\n\nassume H2 : A \u2228 B,\n     show false, \n     from ( (and.elim_left H1)\n            \n            (or.elim H2\n                      (assume H3 : A, H3)\n                      (assume H4 : B, false.elim (and.elim_right H1 H4)))).\n", "meta": {"author": "AlessandroDangelo", "repo": "Matem-tica-Discreta-1", "sha": "b154612d20d88a9fb173a238aa2a9f8e5375d9f7", "save_path": "github-repos/lean/AlessandroDangelo-Matem-tica-Discreta-1", "path": "github-repos/lean/AlessandroDangelo-Matem-tica-Discreta-1/Matem-tica-Discreta-1-b154612d20d88a9fb173a238aa2a9f8e5375d9f7/Semana_2/Semana2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.737699263794582}}
{"text": "-- Suma_de_progresion_aritmetica.lean\n-- Suma de progresi\u00f3n aritm\u00e9tica\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 19 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que la suma de los t\u00e9rminos de la progresi\u00f3n aritm\u00e9tica\n--    a + (a + d) + (a + 2 \u00d7 d) + \u00b7\u00b7\u00b7 + (a + n \u00d7 d)\n-- es (n + 1) \u00d7 (2 \u00d7 a + n \u00d7 d) / 2.\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\nopen nat\n\nvariable  (n : \u2115)\nvariables (a d : \u211d)\n\nset_option pp.structure_projections false\n\n@[simp]\ndef sumaPA : \u211d \u2192 \u211d \u2192 \u2115 \u2192 \u211d\n| a d 0       := a\n| a d (n + 1) := sumaPA a d n + (a + (n + 1) * d)\n\nexample :\n  2 * sumaPA a d n = (n + 1) * (2 * a + n * d) :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { calc 2 * sumaPA a d (succ n)\n         = 2 * (sumaPA a d n + (a + (n + 1) * d))\n           : rfl\n     ... = 2 * sumaPA a d n + 2 * (a + (n + 1) * d)\n           : by ring_nf\n     ... = ((n + 1) * (2 * a + n * d)) + 2 * (a + (n + 1) * d)\n           : by {congr; rw HI}\n     ... = (n + 2) * (2 * a + (n + 1) * d)\n           : by ring_nf\n     ... = (succ n + 1) * (2 * a + succ n * d)\n           : by norm_cast, },\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Suma_de_progresion_aritmetica.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7376992619375685}}
{"text": "\nnotation:65 \"\u2115\" => Nat \nopen Nat\ndef fact : \u2115 \u2192 \u2115 \n| zero => 1\n| succ n' => fact n' * succ n'\n\ninductive fact_state :=\n| AnswerIs (answer : \u2115)\n| WithAccumulator (input accumulator : \u2115)\n\ninductive fact_init (original_input : \u2115) : fact_state \u2192 Prop :=\n| FactInit : fact_init original_input (fact_state.WithAccumulator original_input 1)\ninductive fact_final : fact_state \u2192 Prop :=\n| FactFinal : \u2200 ans, fact_final (fact_state.AnswerIs ans)\ninductive fact_step : fact_state \u2192 fact_state \u2192 Prop :=\n| FactDone : \u2200 acc,\n  fact_step (fact_state.WithAccumulator zero acc) (fact_state.AnswerIs acc)\n| FactStep : \u2200 n acc,\n  fact_step (fact_state.WithAccumulator (succ n) acc) (fact_state.WithAccumulator n (acc * succ n))\n\n\n-- -------------- Transition Relation ---------------------\ninductive trc {A} (R : A \u2192 A \u2192 Prop) : A \u2192 A \u2192 Prop :=\n| TrcRefl : \u2200 x, trc R x x\n| TrcFront : \u2200 x y z, R x y \u2192 trc R y z \u2192 trc R x z\n\n\ntheorem trc_transitive : \u2200 {A} (R : A \u2192 A \u2192 Prop) x y,\n  trc R x y \u2192 \u2200 z, trc R y z \u2192 trc R x z := by\n  intros A R x y TR\n  induction TR with\n  | TrcRefl a => \n    intros z TR\n    assumption\n  | TrcFront _ _ _ _ _ ih =>\n    intros\n    apply trc.TrcFront\n    assumption\n    apply ih\n    assumption\n\n  postfix:max \"^*\" => trc\n\n-- -------------- Transition Relation ---------------------\n\ntheorem succ12 : \u2200 n, succ n = n + 1 := by\n  intro \n  simp \n theorem x : (succ 2 * succ 1) = 6 := by\n    simp \n\nopen trc \nopen fact_step\nexample : fact_step^* (fact_state.WithAccumulator 3 1) (fact_state.AnswerIs 6) :=\n  by \n    apply TrcFront\n    apply FactStep\n    simp \n    apply TrcFront\n    apply FactStep\n    simp [x]\n    apply TrcFront\n    apply FactStep\n    simp\n    apply TrcFront\n    apply FactDone\n    apply TrcRefl\n\n    \nexample : fact_step^* (fact_state.WithAccumulator 3 1) (fact_state.AnswerIs 6) :=\n  by \n    repeat \n      apply TrcFront\n      apply FactStep\n      simp [x]\n    apply TrcFront\n    apply FactDone\n    apply TrcRefl\n    done\n    \nexample : fact_step^* (fact_state.WithAccumulator 3 1) (fact_state.AnswerIs 6) :=\n  by \n    repeat constructor\n    done\n\n  example : 2 + 3 = 5 := by simp\n    \n-- -------------- Transition Relation ---------------------\nstructure trsys (state) := \n    (initial : state \u2192 Prop)\n    (step : state \u2192 state \u2192 Prop)\n-- -------------- Transition Relation ---------------------\n\ndef factorial_sys (original_input : \u2115) : trsys fact_state := {\n    initial := fact_init original_input,\n    step := fact_step\n  }\n\n-- -------------- Transition Relation ---------------------\ninductive reachable {state} (sys : trsys state) (st : state) : Prop :=\n  | Reachable : \u2200 st0, sys.initial st0 -> sys.step^* st0 st -> reachable sys st\n\ndef invariantFor {state} (sys : trsys state) (invariant : state \u2192 Prop) :=\n  \u2200 s, sys.initial s \u2192 \u2200 s', sys.step^* s s' \u2192 invariant s'\n    \ntheorem use_invariant' : \u2200 {state} (sys : trsys state) \n  (invariant : state \u2192 Prop) s s',\n  invariantFor sys invariant \n  \u2192 sys.initial s \n  \u2192 sys.step^* s s'\n  \u2192 invariant s' := by\n  -- intros state trsys inv s s'\n  simp [invariantFor]\n  intros _ _ _ _ _ H _ _ \n  apply H\n  assumption\n  assumption\n\ntheorem use_invariant : \u2200 {state} (sys : trsys state)\n  (invariant : state \u2192 Prop) s,\n  invariantFor sys invariant \u2192 reachable sys s \u2192 invariant s := by\n  intros _ _ _ _ _ H0\n  cases H0 \n  apply use_invariant'\n  repeat assumption\n  \ntheorem invariant_induction' : \u2200 {state} (sys : trsys state)\n  (invariant : state \u2192 Prop),\n  (\u2200 s, invariant s \u2192 \u2200 s', sys.step s s' \u2192 invariant s')\n  \u2192 \u2200 s s', sys.step^* s s'\n    \u2192 invariant s\n    \u2192 invariant s' := by\n  intros _ _ _ H\u2080 _ _ H\u2081\n  induction H\u2081 with\n  | TrcRefl a => \n    intro\n    assumption\n  | TrcFront _ _ _ _ _ iH => \n    intros\n    apply iH\n    apply H\u2080\n    repeat assumption\n    done\n\ntheorem invariant_induction : \u2200 {state} (sys : trsys state) \n  (invariant : state \u2192 Prop),\n  (\u2200 s, sys.initial s \u2192 invariant s)\n  \u2192 (\u2200 s, invariant s \u2192 \u2200 s', sys.step s s' \u2192 invariant s')\n  \u2192 invariantFor sys invariant := by\n  simp [invariantFor]; intros _ _ _ H _ _ _ _ _ \n  apply invariant_induction'\n  assumption\n  assumption\n  apply H \n  assumption\n\n-- -------------- Transition Relation --------------------- \nopen fact_state\ndef fact_invariant (original_input : \u2115) (st : fact_state) : Prop :=\n  match st with\n  | AnswerIs ans => fact original_input = ans\n  | WithAccumulator n acc => fact original_input = fact n * acc\n  \ntheorem fact_invariant_ok : \u2200 original_input,\n  invariantFor (factorial_sys original_input) (fact_invariant original_input) := by\n  intros oi\n  apply invariant_induction\n  intros s \n  simp [factorial_sys]\n  intro H\n  cases H\n  simp [fact_invariant]\n  intros s\n  simp [factorial_sys]\n  intros H _ H0\n  cases H0\n  \n  simp [fact_invariant, fact] at *\n  assumption\n\n  simp [fact_invariant, fact] at *\n  rw [H, Nat.mul_assoc]\n  simp [Nat.mul_comm]\n  done \n\ntheorem fact_invariant_always : \u2200 original_input s,\n  reachable (factorial_sys original_input) s\n  \u2192 fact_invariant original_input s := by\n  intros \n  apply use_invariant\n  apply fact_invariant_ok\n  assumption\n\n--  Therefore, any final state has the right answer! \ntheorem fact_ok' : \u2200 original_input s,\n  fact_final s\n  -> fact_invariant original_input s\n  -> s = AnswerIs (fact original_input)\n:= by\n  intros oi s\n  simp [fact_invariant] at *\n  cases s with \n  | AnswerIs x => \n    simp\n    intros a b\n    rw [b]\n    done\n  | WithAccumulator => \n    simp \n    intros H \n    cases H\n    done\n  \ntheorem fact_ok : \u2200 original_input s,\n  reachable (factorial_sys original_input) s \n  \u2192 fact_final s\n  \u2192 s = AnswerIs (fact original_input) := by\n  intros\n  apply fact_ok'\n  assumption\n  apply fact_invariant_always\n  assumption\n  done\n\n\n  \n\n\n\n\n  \n\ndef main : IO Unit :=\n  IO.println  (fact 4)\n", "meta": {"author": "teodorov", "repo": "lean-transition-systems", "sha": "252ceb254d95ab167273049717609e2c2089688c", "save_path": "github-repos/lean/teodorov-lean-transition-systems", "path": "github-repos/lean/teodorov-lean-transition-systems/lean-transition-systems-252ceb254d95ab167273049717609e2c2089688c/Tr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7376992608881497}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nIn classical mathematics, if we prove that there is a unique element\nx with a certain property p x, then we can treat that as a valid \ndefinition of x and use x as a known entity in further developments.\nThis does not work in quite the same way in Lean (unless we import\nclassical logic.)  The point is basically that Lean implements proof\nirrelevance, and so erases all details of the proof of unique\nexistence of x, making the definition of x inaccessible to\ncomputation.  However, if we have strong enough assumptions about \nfiniteness and decidability, then these issues go away.  The point \nof this file is to set up a framework for dealing with this kind of \nthing.  \n \nIn more detail, at the bottom of this file we will define a function \nfintype.witness.  This accepts a decidable predicate p defined on a \nfinite type \u03b1 with decidable equality, together with a proof of \n(\u2203! x : \u03b1, p x), and it returns the relevant value of x, packaged\ntogether with a proof that it has the expected property.\n\nIn building up to the definition of fintype.witness, we will define\na number of other functions that play similar roles in various other\ncontexts.\n-/\n\nimport data.nat.basic\nimport data.list data.multiset data.finset data.fintype.basic logic.encodable.basic\n\nuniverse u\n\nvariables {\u03b1 : Type u}\n\nnamespace option \n\n/-\n Recall that a term xo of type (option \u03b1) is either (none), or\n (some x) for some x in \u03b1.  This function accepts xo together \n with a proof that xo \u2260 none.  It returns the value x such that \n xo = (some x), packaged together with a proof of that property.\n\n Note that we have defined this function in the option namespace,\n so its full global name is option.unique_element.  Later in this\n file we will define several other functions called unique_element,\n but they will all be in different namespaces, so their full global\n names will be list.unique_element, multiset.unique_element and so\n on.\n-/\ndef unique_element (xo : option \u03b1) (xo_some : xo \u2260 none) : \n { x : \u03b1 // xo = some x } := \nbegin \n rcases xo with _ | x,\n exact false.elim (xo_some rfl),\n exact \u27e8 x, rfl \u27e9 \nend\n\nend option\n\n/- -------------------------------------------------------- -/\n\nnamespace list\n\n/-\n This function accepts a list xs of elements of \u03b1.  If the list \n has length one, so it contains a unique element x, then this\n function returns the term (some x) of type (option \u03b1).  In all\n other cases, it returns the term (none) of type (option \u03b1).\n-/\ndef maybe_unique_element (xs : list \u03b1) : (option \u03b1) := \nbegin\n rcases xs with _ | \u27e8 x , _ | \u27e8 y, zs \u27e9\u27e9,\n exact none,\n exact some x,\n exact none\nend\n\n/-\n A basic lemma saying that maybe_unique_element behaves as expected.\n-/\nlemma maybe_unique_element_prop (xs : list \u03b1) (a : \u03b1)\n (e : maybe_unique_element xs = some a) : xs = [a] :=\nbegin\n rcases xs with _ | \u27e8 x , _ | \u27e8 y, zs \u27e9\u27e9;\n  try {dsimp[maybe_unique_element]}; \n  try {dsimp[maybe_unique_element] at e}; \n  injection e with e1; \n  simp[e1]\nend\n\n/-\n Given that a list has length one, return its unique element, \n packaged with a proof of a key property.\n-/\ndef unique_element (xs : list \u03b1) (xs_length : xs.length = 1) : \n { x : \u03b1 // xs = [x]} := \nbegin\n rcases xs with _ | \u27e8 x,ys \u27e9,\n {simp at xs_length,exact false.elim xs_length},\n { change ys.length.succ = 1 at xs_length,\n  have ys_length : ys.length = 0 := nat.succ_inj'.mp xs_length,\n  have ys_nil : ys = [] := list.length_eq_zero.mp ys_length,\n  simp[ys_nil],\n  exact \u27e8 x, rfl \u27e9\n }\nend\n\n/-\n Another basic lemma saying that maybe_unique_element behaves as expected.\n-/\nlemma some_unique_element (xs : list \u03b1) : \n maybe_unique_element xs = none \u2194 xs.length \u2260 1 :=\nbegin\n rcases xs with _ | \u27e8 x , _ | \u27e8 y, zs \u27e9\u27e9; simp; dsimp[maybe_unique_element],\n refl,\n {intro h,injection h}, refl\nend\n\n/-\n A list with no duplicates and a unique element has length one.\n-/\nlemma length_one_of_prop (xs : list \u03b1) (nd : nodup xs) (u : \u2203! a, a \u2208 xs) :\n xs.length = 1 := \nbegin\n rcases u with \u27e8 a , a_in_xs , a_unique \u27e9, \n rcases xs with _ | \u27e8 x , _ | \u27e8y , zs\u27e9\u27e9,\n {exact false.elim (list.ne_nil_of_mem a_in_xs rfl)},\n {simp},\n {\n   have x_mem : x \u2208 list.cons x (list.cons y zs) := or.inl rfl,\n   have y_mem : y \u2208 list.cons x (list.cons y zs) := or.inr (or.inl rfl),\n   have x_eq_a : x = a := a_unique x x_mem,\n   have y_eq_a : y = a := a_unique y y_mem,\n   have x_eq_y : x = y := x_eq_a.trans y_eq_a.symm,\n   have x_in_y_zs : x \u2208 list.cons y zs := eq.subst x_eq_y (or.inl rfl), \n   exact false.elim ((list.nodup_cons.mp nd).1 x_in_y_zs)\n }\nend\n \n/- \n Let as and bs be lists of elements of type \u03b1.  The proposition \n (perm as bs) is defined inductively in mathlib in data.list.perm.lean; \n it means that bs is a permutation of as.  If so, then \n maybe_unique_element takes the same values on as and bs, as we \n prove here.\n-/\nlemma maybe_unique_element_perm (as bs : list \u03b1) (p : perm as bs) :\n (maybe_unique_element as) = (maybe_unique_element bs) := \nbegin\n induction p,\n case list.perm.nil : {simp},\n case list.perm.cons : x as1 bs1 q ih {\n   rcases as1 with _ | \u27e8 a1, as2 \u27e9 ,\n   {have bs1_nil : bs1 = [] := q.nil_eq.symm,\n   rw[bs1_nil]},{\n    rcases bs1 with _ | \u27e8 b1, bs2 \u27e9 ,\n    rcases q.eq_nil.symm,\n    dsimp[maybe_unique_element],\n    refl\n   }\n  },\n case list.perm.swap : x y cs {\n  dsimp[maybe_unique_element],refl\n },\n case list.perm.trans : cs ds es p_cd p_de ih_cd ih_de {\n   exact eq.trans ih_cd ih_de\n }\nend\n\nend list\n\n/- -------------------------------------------------------- -/\n\nnamespace multiset \n\n/-\n A multiset is (by definition) a permutation-equivalence class of lists.\n Above we defined a function maybe_unique_element in the list namespace.\n We have now closed that namespace, so we need to use the name \n list.maybe_unique_element.  We proved that that function is permutation\n invariant, so now we can define an induced function on multisets.\n We call the new function maybe_unique_element again, but now we are \n in the multiset namespace, so the full global name will be\n multiset.maybe_unique_element.\n-/\ndef maybe_unique_element : (multiset \u03b1) \u2192 (option \u03b1) :=\n quotient.lift list.maybe_unique_element \n  (@list.maybe_unique_element_perm \u03b1)\n\n/-\n We now prove compatibility with list.maybe_unique_element\n-/\nlemma maybe_unique_element_of_list (l : list \u03b1) :\n maybe_unique_element \u2191l = list.maybe_unique_element l := \n @quotient.lift_mk (list \u03b1) _ _\n  list.maybe_unique_element\n   (@list.maybe_unique_element_perm \u03b1) l\n\n/-\n We now have two basic lemmas saying that the multiset version of \n maybe_unique_element behaves as expected.\n-/\nlemma maybe_unique_element_prop (m : multiset \u03b1) (a : \u03b1)\n (e : maybe_unique_element m = some a) : m = [a] := \nbegin\n rcases quotient.exists_rep m with \u27e8 xs, xs_eq_m \u27e9,\n have h : maybe_unique_element \u27e6xs\u27e7 = list.maybe_unique_element xs :=\n  maybe_unique_element_of_list xs,\n rw[xs_eq_m,e] at h,\n have xs_eq_a : xs = [a] := list.maybe_unique_element_prop xs a h.symm,\n simp[xs_eq_a.symm],\n exact xs_eq_m.symm\nend\n\nlemma some_unique_element (m : multiset \u03b1) : \n maybe_unique_element m = none \u2194 card m \u2260 1 := \nbegin\n rcases quotient.exists_rep m with \u27e8 as,e \u27e9,\n rw[\u2190 e],\n simp[maybe_unique_element_of_list as],\n exact as.some_unique_element\nend\n\n/-\n Recall that the cardinality of any multiset is by definition the length\n of any representing list.  Thus, we have the following obvious fact \n about multisets of cardinality one.\n-/\nlemma eq_singleton (m : multiset \u03b1) (x : \u03b1) :\n m = [x] \u2194 (m.card = 1 \u2227 x \u2208 m) := \nbegin\n split,\n {intro m_eq_x,simp[m_eq_x]},\n {intro e,\n  rcases (exists_cons_of_mem e.2) with \u27e8 t, m_eq_xt\u27e9 ,\n  have h : 1 = t.card + 1 := calc \n   1 = m.card : e.1.symm\n   ... = (x ::\u2098 t).card : by rw[m_eq_xt]\n   ... = t.card + 1 : by simp,\n  have t_eq_0 : t = 0 := card_eq_zero.mp (nat.succ_inj'.mp h).symm,\n  simp[t_eq_0] at m_eq_xt,\n  exact m_eq_xt\n }\nend\n\n/-\n This function extracts the unique element of any multiset of cardinality\n one, packaged together with a proof of its key property.\n-/\ndef unique_element (m : multiset \u03b1) (m_card : m.card = 1) : \n {x : \u03b1 // m = [x]} :=\nbegin\n let xo := maybe_unique_element m,\n have xo_some : xo \u2260 none := \n begin\n  intro xo_none,\n  exact (some_unique_element m).mp xo_none m_card\n end,\n rcases option.unique_element xo xo_some with \u27e8 x, xox \u27e9,\n have mx : m = [x] := \n  maybe_unique_element_prop m x xox,\n exact \u27e8 x , mx \u27e9 \nend\n\n/-\n A multiset has cardinality one iff it has no duplicates and a unique element.\n-/\nlemma card_one_of_prop (m : multiset \u03b1) (nd : nodup m) (u : \u2203! a, a \u2208 m) :\n m.card = 1 := \nbegin\n rcases u with \u27e8 a , a_in_m , a_unique_in_m \u27e9,\n rcases quotient.exists_rep m with \u27e8 xs, xs_eq_m \u27e9,\n rw[\u2190 xs_eq_m] at a_in_m a_unique_in_m nd \u22a2,\n simp,\n have xs_nd : list.nodup xs := coe_nodup.mp nd,\n have a_in_xs : a \u2208 xs := mem_coe.mpr a_in_m,\n have a_unique_in_xs :\n   \u2200 x : \u03b1, \u2200 (x_in_xs : x \u2208 xs), x = a := \n begin\n  intros,\n  exact a_unique_in_m x (mem_coe.mp x_in_xs)\n end,\n exact list.length_one_of_prop xs xs_nd \u27e8 a , a_in_xs , a_unique_in_xs \u27e9\nend\n\nend multiset\n\n/- -------------------------------------------------------- -/\n\nnamespace finset\n\n/-\n A finset is a multiset with no duplicates.  We can restrict all our definitions\n and results for multisets, to get versions for finsets.\n-/\ndef maybe_unique_element (s : finset \u03b1) : (option \u03b1) :=\n multiset.maybe_unique_element s.val\n\nlemma maybe_unique_element_prop (s : finset \u03b1) (a : \u03b1)\n (e : maybe_unique_element s = some a) : s = singleton a := \nbegin\n apply finset.eq_of_veq,\n simp,dsimp[maybe_unique_element] at e,\n exact multiset.maybe_unique_element_prop s.val a e\nend\n\nlemma some_unique_element (s : finset \u03b1) : \n maybe_unique_element s = none \u2194 s.card \u2260 1 := \nbegin\n dsimp[maybe_unique_element,card],\n apply multiset.some_unique_element\nend\n\nlemma eq_singleton (s : finset \u03b1) (a : \u03b1) :\n s = singleton a \u2194 (s.card = 1 \u2227 a \u2208 s) := \nbegin\n split;intro e,\n {dsimp[card],\n  let e1 := congr_arg finset.val e,\n  simp at e1,\n  simp[e1,e]\n },{\n  dsimp[card] at e,\n  apply eq_of_veq,\n  exact (multiset.eq_singleton s.val a).mpr \u27e8 e.1 , finset.mem_def.mp e.2\u27e9,\n }\nend\n\ndef unique_element (s : finset \u03b1) (s_card : s.card = 1) : \n {x : \u03b1 // s = singleton x} :=\nbegin\n dsimp[card] at s_card,\n rcases (multiset.unique_element s.val s_card) with \u27e8 x , e \u27e9,\n have e1 : s = singleton x := eq_of_veq e,\n exact \u27e8 x , e1 \u27e9   \nend\n\nlemma card_one_of_prop (s : finset \u03b1) (h : \u2203! x, x \u2208 s) : s.card = 1 := \nbegin\n dsimp[card],\n exact multiset.card_one_of_prop s.val s.nodup h\nend\n\n/-\n Suppose that we have a finset s and a decidable predicate p; we can then\n define a finset (s.filter p) consisting of elements of s where p is \n satisfied.  The following function just applies our previous constructions\n to a finset of the form (s.filter p) and does a little associated \n bookkeeping.\n-/\ndef witness (s : finset \u03b1) (p : \u03b1 \u2192 Prop) [decidable_pred p]\n (h : \u2203! x, x \u2208 s \u2227 p x) : \n  { a : \u03b1 // s.filter p = singleton a} :=\nbegin\n let s1 := s.filter p,\n have h1 : \u2203! x, x \u2208 s1 := \n begin\n  rcases h with \u27e8 x , \u27e8 x_in_s , p_x \u27e9 , x_unique\u27e9, \n  have x_in_s1 : x \u2208 s1 := \n   mem_filter.mpr \u27e8 x_in_s , p_x \u27e9, \n  have x_unique_alt : \u2200 y, y \u2208 s1 \u2192 y = x := \n  begin\n   intros y y_in_s1,\n   exact x_unique y (mem_filter.mp y_in_s1),\n  end,\n  exact \u27e8 x , x_in_s1, x_unique_alt\u27e9 \n end,\n have s1_card : s1.card = 1 := card_one_of_prop s1 h1,\n exact unique_element s1 s1_card\nend\n\nend finset\n\n/- -------------------------------------------------------- -/\n\nnamespace fintype \n/-\n Recall that a fintype structure on \u03b1 is a finset containing every element\n of \u03b1, and thus proving that \u03b1 is finite.  In this section we do some \n obvious adaptation of our results for general finsets, to put them in a\n more convenient form for use with fintypes.\n-/\nopen finset fintype \n\nvariables (\u03b1) [fintype \u03b1]\n\ndef maybe_unique_element : (option \u03b1) :=\n finset.maybe_unique_element univ\n\nlemma maybe_unique_element_prop (a : \u03b1)\n (e : maybe_unique_element \u03b1 = some a) :\n  univ = ({a} : finset \u03b1) := \n  maybe_unique_element_prop univ a e\n\nlemma some_unique_element : \n maybe_unique_element \u03b1 = none \u2194 card \u03b1 \u2260 1 := \nfinset.some_unique_element univ\n\nlemma eq_singleton (a : \u03b1) :\n univ = ({a} : finset \u03b1) \u2194 (card \u03b1 = 1) := \nbegin\n dsimp[card],\n let e := finset.eq_singleton univ a, \n split,\n {intro u,exact (e.mp u).1},\n {intro v,exact e.mpr \u27e8 v , mem_univ a \u27e9}\nend\n\nlemma card_one_of_prop (h : \u2203 x : \u03b1, \u2200 y : \u03b1, y = x) : card \u03b1 = 1 := \nbegin\n dsimp[card],\n have h1 : (\u2203! x : \u03b1 , x \u2208 (@univ \u03b1 _)) := begin\n  rcases h with \u27e8 x , x_unique \u27e9, \n  let x_in_univ := @mem_univ \u03b1 _ x,\n  have x_unique_alt : \u2200 y : \u03b1, y \u2208 (@univ \u03b1 _) \u2192 y = x := \n  begin\n   intros y y_in_univ,\n   exact x_unique y\n  end,\n  exact \u27e8 x , x_in_univ , x_unique_alt \u27e9 \n end,\n exact finset.card_one_of_prop univ h1\nend\n\ndef witness (p : \u03b1 \u2192 Prop) [decidable_pred p]\n (h : \u2203! x, p x) : \n  { a : \u03b1 // univ.filter p = singleton a} :=\nbegin\n have h1 : \u2203! x, x \u2208 (@univ \u03b1 _) \u2227 p x := \n begin\n  rcases h with \u27e8 x , p_x , x_unique\u27e9, \n  have x_prop : x \u2208 univ \u2227 p x := \u27e8 mem_univ x , p_x \u27e9, \n  have x_unique_alt : \u2200 y, y \u2208 univ \u2227 p y \u2192 y = x := \n   \u03bb y y_prop, x_unique y y_prop.2,\n  exact \u27e8 x , x_prop , x_unique_alt \u27e9  \n end,\n exact finset.witness univ p h1,\nend\n\nend fintype\n\n\n\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/data/unique_element.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.737637785899797}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem induction_seq_mul2pnp1\n  (n : \u2115)\n  (u : \u2115 \u2192 \u2115)\n  (h\u2080 : u 0 = 0)\n  (h\u2081 : \u2200 n, u (n + 1) = 2 * u n + (n + 1)) :\n  u n = 2^(n + 1) - (n + 2) :=\nbegin\n  apply eq_tsub_of_add_eq,\n  simp [pow_succ],\n  induction n with a ih,\n  { simp [h\u2080, h\u2081] },\n  norm_num [h\u2080, h\u2081],\n  simp [nat.succ_eq_add_one],\n  rw [add_left_comm, \u2190 add_assoc],\n  simp only [pow_succ'],\n  rw [mul_two],\n  linarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/misc/miniF2F/induction/seq_mul2pnp1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.737637778143715}}
{"text": "-- Distributiva_de_la_interseccion_respecto_de_la_union_general.lean\n-- Distributiva de la intersecci\u00f3n respecto de la uni\u00f3n general\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 28-abril-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport data.set.lattice\nimport tactic\n\nopen set\n\nvariable {\u03b1 : Type}\nvariable s : set \u03b1\nvariable A : \u2115 \u2192 set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    rw mem_Union,\n    cases h with xs xUAi,\n    rw mem_Union at xUAi,\n    cases xUAi with i xAi,\n    use i,\n    split,\n    { exact xAi, },\n    { exact xs, }},\n  { intro h,\n    rw mem_Union at h,\n    cases h with i hi,\n    cases hi with xAi xs,\n    split,\n    { exact xs, },\n    { rw mem_Union,\n      use i,\n      exact xAi, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  simp,\n  split,\n  { rintros \u27e8xs, \u27e8i, xAi\u27e9\u27e9,\n    exact \u27e8\u27e8i, xAi\u27e9, xs\u27e9, },\n  { rintros \u27e8\u27e8i, xAi\u27e9, xs\u27e9,\n    exact \u27e8xs, \u27e8i, xAi\u27e9\u27e9, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext,\n  finish,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nby ext; finish\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nby finish [ext_iff]\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nby tidy ", "meta": {"author": "jaalonso", "repo": "Razonando-con-Lean", "sha": "d6e3fe9e384bdb6d8cc6ce4383d86c72bbcc154c", "save_path": "github-repos/lean/jaalonso-Razonando-con-Lean", "path": "github-repos/lean/jaalonso-Razonando-con-Lean/Razonando-con-Lean-d6e3fe9e384bdb6d8cc6ce4383d86c72bbcc154c/src/Distributiva_de_la_interseccion_respecto_de_la_union_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7376295024940488}}
{"text": "import order.galois_connection\n\nuniverse u\nvariables X Y : Type u\n\ndef VR {X Y} (R: X \u2192 Y \u2192 Prop) (S : set X) : set Y := {y : Y | \u2200 (s \u2208 S), R s y}\ndef IR {X Y} (R: X \u2192 Y \u2192 Prop) (T : set Y) : set X := {x : X | \u2200 (t \u2208 T), R x t}\n\ndef subsetrel {X} : preorder (set X) := {\n  le := \u03bb A B, A \u2286 B,\n  le_refl := set.subset.refl,\n  le_trans := begin\n    intros A B C,\n      dsimp,\n      exact set.subset.trans,\n  end,\n}\ndef supsetrel {Y} : preorder (set Y) := {\n  le := \u03bb A B, A \u2287 B,\n  le_refl := set.subset.refl,\n  le_trans := begin\n    intros A B C,\n      dsimp,\n      intros hAB hBC,\n      apply set.subset.trans,\n      exact hBC,\n      exact hAB,\n  end,\n}\n\n-- exercise 1a\n-- use @galois_connection to be able to provide all arguments explicitly\n-- in particular we want to provide the preorders that way to be able to use different ones on P(X) and P(Y)\nlemma ex1a (R : X \u2192 Y \u2192 Prop): @galois_connection (set X) (set Y) subsetrel supsetrel (VR R) (IR R) := begin\n  intros S T,\n  split,\n  {\n    show VR R S \u2287 T \u2192 S \u2286 IR R T,\n    intro h,\n    intros s hs,\n    intros t ht,\n    specialize h ht,\n    specialize h s hs,\n    exact h,\n  },\n  {\n    show S \u2286 IR R T \u2192 VR R S \u2287 T,\n    intro h,\n    intros t ht,\n    intros s hs,\n    specialize h hs,\n    specialize h t ht,\n    exact h,\n  },  \nend", "meta": {"author": "GraffL", "repo": "algebraic-geometry-in-lean", "sha": "d21acba4590b88dbda6e7a03c69aa10625514694", "save_path": "github-repos/lean/GraffL-algebraic-geometry-in-lean", "path": "github-repos/lean/GraffL-algebraic-geometry-in-lean/algebraic-geometry-in-lean-d21acba4590b88dbda6e7a03c69aa10625514694/src/exercise1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857831, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7376295022193927}}
{"text": "/-\nCopyright (c) 2021 Nicol\u00f2 Cavalleri. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Nicol\u00f2 Cavalleri\n-/\nimport topology.homeomorph\n\n/-!\n# Topological space structure on the opposite monoid and on the units group\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define `topological_space` structure on `M\u1d50\u1d52\u1d56`, `M\u1d43\u1d52\u1d56`, `M\u02e3`, and `add_units M`.\nThis file does not import definitions of a topological monoid and/or a continuous multiplicative\naction, so we postpone the proofs of `has_continuous_mul M\u1d50\u1d52\u1d56` etc till we have these definitions.\n\n## Tags\n\ntopological space, opposite monoid, units\n-/\n\nvariables {M X : Type*}\n\nopen filter\nopen_locale topology\n\nnamespace mul_opposite\n\n/-- Put the same topological space structure on the opposite monoid as on the original space. -/\n@[to_additive \"Put the same topological space structure on the opposite monoid as on the original\nspace.\"]\ninstance [topological_space M] : topological_space M\u1d50\u1d52\u1d56 :=\ntopological_space.induced (unop : M\u1d50\u1d52\u1d56 \u2192 M) \u2039_\u203a\n\nvariables [topological_space M]\n\n@[continuity, to_additive] lemma continuous_unop : continuous (unop : M\u1d50\u1d52\u1d56 \u2192 M) :=\ncontinuous_induced_dom\n\n@[continuity, to_additive] lemma continuous_op : continuous (op : M \u2192 M\u1d50\u1d52\u1d56) :=\ncontinuous_induced_rng.2 continuous_id\n\n/-- `mul_opposite.op` as a homeomorphism. -/\n@[to_additive \"`add_opposite.op` as a homeomorphism.\", simps]\ndef op_homeomorph : M \u2243\u209c M\u1d50\u1d52\u1d56 :=\n{ to_equiv := op_equiv,\n  continuous_to_fun := continuous_op,\n  continuous_inv_fun := continuous_unop }\n\n@[to_additive] instance [t2_space M] : t2_space M\u1d50\u1d52\u1d56 :=\nop_homeomorph.symm.embedding.t2_space\n\n@[simp, to_additive] lemma map_op_nhds (x : M) : map (op : M \u2192 M\u1d50\u1d52\u1d56) (\ud835\udcdd x) = \ud835\udcdd (op x) :=\nop_homeomorph.map_nhds_eq x\n\n@[simp, to_additive] lemma map_unop_nhds (x : M\u1d50\u1d52\u1d56) : map (unop : M\u1d50\u1d52\u1d56 \u2192 M) (\ud835\udcdd x) = \ud835\udcdd (unop x) :=\nop_homeomorph.symm.map_nhds_eq x\n\n@[simp, to_additive] lemma comap_op_nhds (x : M\u1d50\u1d52\u1d56) : comap (op : M \u2192 M\u1d50\u1d52\u1d56) (\ud835\udcdd x) = \ud835\udcdd (unop x) :=\nop_homeomorph.comap_nhds_eq x\n\n@[simp, to_additive] \n\nend mul_opposite\n\nnamespace units\n\nopen mul_opposite\n\nvariables [topological_space M] [monoid M] [topological_space X]\n\n/-- The units of a monoid are equipped with a topology, via the embedding into `M \u00d7 M`. -/\n@[to_additive \"The additive units of a monoid are equipped with a topology, via the embedding into\n`M \u00d7 M`.\"]\ninstance : topological_space M\u02e3 := prod.topological_space.induced (embed_product M)\n\n@[to_additive] lemma inducing_embed_product : inducing (embed_product M) := \u27e8rfl\u27e9\n\n@[to_additive] lemma embedding_embed_product : embedding (embed_product M) :=\n\u27e8inducing_embed_product, embed_product_injective M\u27e9\n\n@[to_additive] lemma topology_eq_inf :\n  units.topological_space = topological_space.induced (coe : M\u02e3 \u2192 M) \u2039_\u203a \u2293\n    topological_space.induced (\u03bb u, \u2191u\u207b\u00b9 : M\u02e3 \u2192 M) \u2039_\u203a :=\nby simp only [inducing_embed_product.1, prod.topological_space, induced_inf,\n  mul_opposite.topological_space, induced_compose]; refl\n\n/-- An auxiliary lemma that can be used to prove that coercion `M\u02e3 \u2192 M` is a topological embedding.\nUse `units.coe_embedding\u2080`, `units.coe_embedding`, or `to_units_homeomorph` instead. -/\n@[to_additive \"An auxiliary lemma that can be used to prove that coercion `add_units M \u2192 M` is a\ntopological embedding. Use `add_units.coe_embedding` or `to_add_units_homeomorph` instead.\"]\nlemma embedding_coe_mk {M : Type*} [division_monoid M] [topological_space M]\n  (h : continuous_on has_inv.inv {x : M | is_unit x}) : embedding (coe : M\u02e3 \u2192 M) :=\nbegin\n  refine \u27e8\u27e8_\u27e9, ext\u27e9,\n  rw [topology_eq_inf, inf_eq_left, \u2190 continuous_iff_le_induced, continuous_iff_continuous_at],\n  intros u s hs,\n  simp only [coe_inv, nhds_induced, filter.mem_map] at hs \u22a2,\n  exact \u27e8_, mem_inf_principal.1 (h u u.is_unit hs), \u03bb u' hu', hu' u'.is_unit\u27e9\nend\n\n@[to_additive] lemma continuous_embed_product : continuous (embed_product M) :=\ncontinuous_induced_dom\n\n@[to_additive] lemma continuous_coe : continuous (coe : M\u02e3 \u2192 M) :=\n(@continuous_embed_product M _ _).fst\n\n@[to_additive] protected lemma continuous_iff {f : X \u2192 M\u02e3} :\n  continuous f \u2194 continuous (coe \u2218 f : X \u2192 M) \u2227 continuous (\u03bb x, \u2191(f x)\u207b\u00b9 : X \u2192 M) :=\nby simp only [inducing_embed_product.continuous_iff, embed_product_apply, (\u2218), continuous_prod_mk,\n  op_homeomorph.symm.inducing.continuous_iff, op_homeomorph_symm_apply, unop_op]\n\n@[to_additive] lemma continuous_coe_inv : continuous (\u03bb u, \u2191u\u207b\u00b9 : M\u02e3 \u2192 M) :=\n(units.continuous_iff.1 continuous_id).2\n\nend units\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/constructions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7376295011670565}}
{"text": "import xenalib.zmod algebra.group_power tactic.norm_num algebra.big_operators\n\nlocal infix ` ^ ` := monoid.pow\n\n-- sheet 5 solns\n\ndef Fib : \u2115 \u2192 \u2115\n| 0 := 0\n| 1 := 1\n| (n+2) := Fib n + Fib (n+1)\n\n--#eval Fib 10\n--#reduce Fib 10\n\ndef is_even (n : \u2115) : Prop := \u2203 k, n=2*k\ndef is_odd (n : \u2115) : Prop := \u2203 k, n=2*k+1\n\nlemma even_of_even_add_even (a b : \u2115) : is_even a \u2192 is_even b \u2192 is_even (a+b) :=\nbegin\nintros Ha Hb,\ncases Ha with k Hk,\ncases Hb with l Hl,\nexistsi k+l,\nsimp [Hk,Hl,add_mul],\nend\n\nlemma odd_of_odd_add_even {a b : \u2115} : is_odd a \u2192 is_even b \u2192 is_odd (a+b) :=\nbegin\nintros Ha Hb,\ncases Ha with k Hk,\ncases Hb with l Hl,\nexistsi k+l,\nsimp [Hk,Hl,add_mul],\nend\n\nlemma odd_of_even_add_odd {a b : \u2115} : is_even a \u2192 is_odd b \u2192 is_odd (a+b) :=\n\u03bb h1 h2, (add_comm b a) \u25b8 (odd_of_odd_add_even h2 h1)\n\n\nlemma even_of_odd_add_odd {a b : \u2115} : is_odd a \u2192 is_odd b \u2192 is_even (a+b) :=\nbegin\nintros Ha Hb,\ncases Ha with k Hk,\ncases Hb with l Hl,\nexistsi k+l+1,\n-- simp [mul_add,Hk,Hl,one_add_one_eq_two] -- fails!\nrw [Hk,Hl,mul_add,mul_add],\nchange 2 with 1+1,\nsimp [mul_add,add_mul],\nend\n\ntheorem Q1a : \u2200 n : \u2115, n \u2265 1 \u2192\n  is_odd (Fib (3*n-2)) \u2227 is_odd (Fib (3*n-1)) \u2227 is_even (Fib (3*n)) :=\nbegin\nintros n Hn,\ncases n with m,\nhave : \u00ac (0 \u2265 1) := dec_trivial,\nexfalso,\nexact (this Hn),\ninduction m with d Hd,\n  exact \u27e8\u27e80,rfl\u27e9,\u27e80,rfl\u27e9,\u27e81,rfl\u27e9\u27e9,\nchange 3*nat.succ d-2 with 3*d+1 at Hd,\nchange 3*nat.succ d -1 with 3*d+2 at Hd,\nchange 3*nat.succ d with 3*d+3 at Hd,\nchange 3*nat.succ (nat.succ d)-2 with 3*d+4,\nchange 3*nat.succ (nat.succ d)-1 with 3*d+5,\nchange 3*nat.succ (nat.succ d) with 3*d+6,\n\nlet Hyp := Hd (begin apply nat.succ_le_succ,exact nat.zero_le d,end),\nlet H1 := Hyp.left,\nlet H2 := Hyp.right.left,\nlet H3 := Hyp.right.right,\nhave H4 : is_odd (Fib (3*d+4)),\n  change Fib (3*d+4) with Fib (3*d+2)+Fib(3*d+3),\n  exact odd_of_odd_add_even H2 H3,\nhave H5 : is_odd (Fib (3*d+5)),\n  change Fib (3*d+5) with Fib (3*d+3)+Fib(3*d+4),\n  exact odd_of_even_add_odd H3 H4,\nhave H6 : is_even (Fib (3*d+6)),\n  change Fib (3*d+6) with Fib (3*d+4)+Fib(3*d+5),\n  exact even_of_odd_add_odd H4 H5,\nexact \u27e8H4,H5,H6\u27e9,\nend\n\ntheorem Q1b : is_odd (Fib (2017)) :=\nbegin\nhave H : 2017 = 3*673-2 := dec_trivial,\nrw [H],\nexact (Q1a 673 (dec_trivial)).left,\nend\n\ntheorem Q2 (n : \u2115) : n \u2265 2 \u2192 nat.pow 4 n > nat.pow 3 n + nat.pow 2 n :=\nbegin\nintro H_n_ge_2,\ncases n with n1,\n  exfalso,revert H_n_ge_2, exact dec_trivial,\ncases n1 with n2,\n  exfalso,revert H_n_ge_2, exact dec_trivial,\nclear H_n_ge_2,\ninduction n2 with d Hd,\n  exact dec_trivial,\nlet e := nat.succ (nat.succ d),\nshow nat.pow 4 e*4>nat.pow 3 e*3+nat.pow 2 e*2,\nchange nat.pow 4 (nat.succ (nat.succ d)) > nat.pow 3 (nat.succ (nat.succ d)) + nat.pow 2 (nat.succ (nat.succ d))\nwith nat.pow 4 e>nat.pow 3 e+nat.pow 2 e at Hd,\nexact calc\nnat.pow 4 e * 4 > (nat.pow 3 e + nat.pow 2 e) * 4 : mul_lt_mul_of_pos_right Hd (dec_trivial)\n... = nat.pow 3 e*4+nat.pow 2 e*4 : add_mul _ _ _\n... \u2265 nat.pow 3 e*3+nat.pow 2 e*4 : add_le_add_right (nat.mul_le_mul_left _ (dec_trivial)) _\n... \u2265 nat.pow 3 e*3+nat.pow 2 e*2 : add_le_add_left (nat.mul_le_mul_left _ (dec_trivial)) _,\nend\n\ntheorem Q3a (n : \u2115) : \u2203 k, (n+1)+(n+2)+(n+3)+(n+4) = 4*k+2 :=\nbegin\ninduction n with d Hd,\n  existsi 2,trivial,\ncases Hd with k Hk, -- why is this so horrible!\nexistsi k+1,\nrw [nat.succ_eq_add_one],\nhave : ((d + 1 + (d + 2) + (d + 3) + (d + 4))+4)=(4*k+2)+4\n        := Hk \u25b8 @eq.refl \u2115 ((d + 1 + (d + 2) + (d + 3) + (d + 4))+4),\nsimp, -- have given in -- anything will now do.\nsimp at this,\nrw this,\nsimp [add_mul],\nend\n--#check @eq_of_add_eq_add_right\n--#check @eq.refl\n\n--#check (by apply_instance : has_mul (fin 4))\nlemma of_nat_pow : \u2200 a b: \u2115, int.of_nat(a^b)=(int.of_nat a)^b :=\nbegin\nintros a b,\ninduction b with k Hk,\n  unfold monoid.pow,\n  simp [int.of_nat_one],\nunfold monoid.pow nat.pow, -- pow_nat nat.pow has_pow_nat.pow_nat monoid.pow,\n--show int.of_nat (a^k*a) = (int.of_nat a) * (int.of_nat a)^k,\nrw [int.of_nat_mul,mul_comm,Hk,mul_comm],\nend\n\ntheorem Q3helpful_lemma : \u2200 (e : \u2115), 11^e \u2265 3^e :=\nbegin\nintro e,\ninduction e with d Hd,\n  exact dec_trivial,\nexact calc 11^(nat.succ d) = 11*11^d : rfl\n... \u2265 3*11^d : nat.mul_le_mul_right (11^d) (dec_trivial)\n... \u2265 3*3^d : nat.mul_le_mul_left 3 Hd\n... = 3^(nat.succ d) : rfl\nend \n\ntheorem Q3helpful_lemma2 : \u2200 (e : \u2115 ), (((11^e-3^e):\u2115):\u2124) = (11:\u2124)^e-(3:\u2124)^e :=\nbegin\nintro e,\nshow int.of_nat (11^e - 3^e) = (11:\u2124)^e - (3:\u2124)^e,\nrw [int.of_nat_sub (Q3helpful_lemma e)],\nrw [of_nat_pow,of_nat_pow],\nrefl,\nend\n\ntheorem Q3b (n : \u2115) : 8 \u2223 11^n - 3^n :=\nbegin\nhave H : \u2200 (e : \u2115), 11^e \u2265 3^e := Q3helpful_lemma,\n\nhave H311 : @Zmod.of_int 8 3 = Zmod.of_int 11,\napply quot.sound,\nexistsi (1:\u2124),\nexact dec_trivial,\n\ninduction n with d Hd,\n  exact \u27e80,rfl\u27e9,\n\ncases Hd with k Hk,\nrw [\u2190int.of_nat_eq_of_nat_iff] at Hk,\nrw [int.of_nat_sub (H d),int.of_nat_mul] at Hk,\nrw [of_nat_pow,of_nat_pow] at Hk,\n--have : (int.of_nat 11)^d - (int.of_nat 3)^d = 8 * (int.of_nat k),\n--exact Hk,\nhave Heq : @Zmod.of_int 8 ((3:\u2124)^d) = Zmod.of_int ((11:\u2124)^d),\napply quot.sound,\nexistsi (k:\u2124),\nrw [mul_comm],\nexact eq.symm Hk,\nhave H1 : @Zmod.of_int 8 ((3:\u2124)^(nat.succ d)) = Zmod.of_int (11^(nat.succ d)) := calc\nZmod.of_int ((3:\u2124)^(nat.succ d)) = (Zmod.of_int 3)^(nat.succ d) : eq.symm Zmod.of_int_pow\n... = (Zmod.of_int 3)^(d+1) : rfl\n... = (Zmod.of_int 3) * (Zmod.of_int 3)^d : pow_succ (Zmod.of_int 3) d\n... = (Zmod.of_int 3) * (Zmod.of_int (3^d)) : by rw [@Zmod.of_int_pow 8]\n... = Zmod.of_int 3 * (Zmod.of_int (11^d)) : by rw [Heq]\n... = Zmod.of_int 11 * (Zmod.of_int (11^d)) : by rw [H311]\n... = Zmod.of_int (11^(nat.succ d)) : rfl,\n\nunfold Zmod.of_int at H1,\nhave H2 := @quotient.exact \u2124 (@Z_setoid 8) _ _ H1,\ncases H2 with k2 Hk2,\n--show (8:\u2124) \u2223 11^nat.succ d - 3^nat.succ d,\nhave H3 : k2 * \u21918 = (int.of_nat 11) ^ nat.succ d - (int.of_nat 3) ^ nat.succ d,\nexact Hk2,\nrw [\u2190of_nat_pow,\u2190of_nat_pow] at H3,\nrw [\u2190int.of_nat_sub (H (nat.succ d))] at H3,\nhave Hpos : k2 * \u21918 \u2265 0,\nrw [H3], exact int.of_nat_nonneg (11^nat.succ d - 3^nat.succ d),\nhave Hpos2 : k2 \u2265 0 := nonneg_of_mul_nonneg_right Hpos (dec_trivial),\nlet k3 : \u2115 := int.nat_abs k2,\nhave H4 : \u2191k3 = k2 := int.nat_abs_of_nonneg Hpos2,\nexistsi k3,\napply int.of_nat_inj,\nrw [eq.symm H3],\nrw [\u2190H4,int.of_nat_mul,mul_comm],\nrw int.of_nat_eq_coe,\nrw int.of_nat_eq_coe,\nend\n\ntheorem Q3ca (n : \u2115) : \u2203 k, (n+1)+(n+2)+(n+3)+(n+4) = 4*k+2 :=\nbegin\nexistsi (n+2),\nchange 4 with 1+1+1+1,\nrw [add_mul,add_mul,add_mul],\nsimp,\nend\n\ndef Q3sum (d : \u2115) (a b : \u2124) := finset.sum (finset.range (d+1)) (\u03bb n, a^n*b^(d-n))\n\n--finset.sum_image :\n--  \u2200 {\u03b1 : Type u_1} {\u03b2 : Type u_2} {\u03b3 : Type u_3} {f : \u03b1 \u2192 \u03b2} [_inst_1 : add_comm_monoid \u03b2]\n--  [_inst_2 : decidable_eq \u03b1] [_inst_3 : decidable_eq \u03b3] {s : finset \u03b3} {g : \u03b3 \u2192 \u03b1},\n--    (\u2200 (x : \u03b3), x \u2208 s \u2192 \u2200 (y : \u03b3), y \u2208 s \u2192 g x = g y \u2192 x = y) \u2192\n--    finset.sum (finset.image g s) f = finset.sum s (\u03bb (x : \u03b3), f (g x))\n\n\nlemma lt_of_in_finset {x y: \u2115} : x \u2208 finset.range y \u2192 x < y := by simp\n#print multiset.to_finset \n#print finset.range\n#check multiset.erase\n#check finset.eq_of_veq\n#print multiset.erase_dup \n#check multiset.nodup_range\n#check multiset.erase_dup_eq_self\n#print multiset.map \n#check multiset.coe_reverse\n#print multiset.range\n#check multiset.coe_map\n#print list.reverse\n#print list.iota._main\n#print list.range_core\n#check list.range_core_range'\n#print list.range'._main\n#eval list.range' 5 8 -- [5,6,7,8,9,10,11,12] \n#check list.range'\n--set_option pp.notation false\nlemma H8 (d : \u2115) : list.map (\u03bb (i : \u2115), d - i) (list.range (d + 1)) \n    = list.reverse (list.range (d + 1)) :=\nbegin\nadmit, -- and ask Mario\nend\n\nlemma H7 : \u2200 d : \u2115, (finset.range (d+1)).image (\u03bb i,d-i) = finset.range (d+1) :=\nbegin\n-- statement about finsets\nintro d,\nunfold finset.image,\nunfold finset.range,\nshow multiset.to_finset (multiset.map (\u03bb (i : \u2115), d - i) \n      (multiset.range (d + 1))) =\n    {val := multiset.range (d + 1), nodup := _},\nunfold multiset.to_finset,\napply finset.eq_of_veq,\nshow multiset.erase_dup (multiset.map (\u03bb (i : \u2115), d - i) (multiset.range (d + 1)))\n    = multiset.range (d + 1),\n-- now a statement about multisets\nhave this2 := multiset.nodup_range (d+1),\nsuffices : multiset.erase_dup (multiset.map (\u03bb (i : \u2115), d - i) (multiset.range (d + 1))) \n   = multiset.erase_dup (multiset.range (d + 1)),\n  rw [this],\n  exact multiset.erase_dup_eq_self.2 this2,\napply congr_arg,\nclear this2,\nshow multiset.map (\u03bb (i : \u2115), d - i) (multiset.range (d + 1)) \n    = \u2191(list.range (d + 1)),\nrw \u2190multiset.coe_reverse,\nunfold multiset.range,\nrw multiset.coe_map,\napply congr_arg,\n-- now a statement about lists\nexact H8 d,\nend \n\nlemma H0 (d : \u2115) (a b : \u2124) : Q3sum d a b = Q3sum d b a :=\nbegin\nunfold Q3sum,\nhave : (finset.range (d+1)).image (\u03bb i,d-i) = finset.range (d+1),\n  exact H7 d,\n/-\n  unfold finset.range,\n  unfold multiset.range,\n  rw \u2190multiset.coe_reverse,\n-/\nrw \u2190this, -- aargh, rewrites both!\nhave H53 : \u2200 (x : \u2115), \n    x \u2208 finset.range(d+1) \u2192 \u2200 (y : \u2115), y \u2208 finset.range (d+1) \u2192 d-x = d-y \u2192 x=y,\n  introv Hx Hy Hxy,\n  have : (d-x)+x=d,\n    exact nat.sub_add_cancel (nat.le_of_lt_succ (lt_of_in_finset Hx)),\n  rw Hxy at this,\n  rw \u2190nat.sub_add_comm (nat.le_of_lt_succ (lt_of_in_finset Hy)) at this,\n  have this2 : (d+x-y)+y=d+x,\n    exact nat.sub_add_cancel (le_trans (nat.le_of_lt_succ (lt_of_in_finset Hy)) (nat.le_add_right _ _)),\n  rw this at this2,\n  exact eq.symm (nat.add_left_cancel this2),\nrw [@finset.sum_image \u2115 \u2124 \u2115 (\u03bb (n : \u2115), a ^ n * b ^ (d - n)) _ _ _ \n     (finset.range (d+1)) (\u03bb i : \u2115, d-i) H53],\nrw [this],\napply finset.sum_congr,\nintrov H,\nhave := lt_of_in_finset H,\nshow a ^ (d - x) * b ^ (d - (d - x)) = b ^ x * a ^ (d - x),\nrw [nat.sub_sub_self (nat.le_of_lt_succ this)],\napply mul_comm,\nend\n\nlemma H5 (e : \u2115) : finset.range (nat.succ e) = insert e (finset.range e) :=\nbegin\nexact finset.range_succ,\nend\n\n\nlemma H1 (d : \u2115) (aa b : \u2124) : b * Q3sum d aa b = Q3sum (d+1) aa b - aa^(d+1) :=\nbegin\nunfold Q3sum,\nrw finset.mul_sum,\nchange d+1+1 with nat.succ(d+1),\nrw (@finset.range_succ (d+1)),\nrw finset.sum_insert,\n  tactic.swap,\n  intro H,\n  apply lt_irrefl (d+1),\n  exact lt_of_in_finset H,\nrw [nat.sub_self (d+1)],\nhave : \u2200 x : \u2115, x<(d+1) \u2192 b*(aa^x*b^(d-x))= aa^x*b^(d+1-x),\n  intros x Hx,\n  rw [mul_comm], \n  have : d+1-x = (d-x)+1,\n    rw [add_comm,nat.add_sub_assoc (nat.le_of_lt_succ Hx),add_comm],\n  rw [this],\n  rw [pow_succ],simp,\nrw [pow_zero,mul_one],\nrw [add_comm (aa^(d+1)),add_sub_cancel],\napply finset.sum_congr,\nintros,\napply this x,\nexact lt_of_in_finset H,\nend\n\nlemma H3 (d : \u2115) : 11 * Q3sum d 3 11 = Q3sum (d+1) 3 11 - 3^(d+1) := H1 d 3 11\nlemma H2 (d : \u2115) : 3 * Q3sum d 3 11 = Q3sum (d+1) 3 11 - 11^(d+1) :=\nbegin\nrw [H0],\nrw H1 d 11 3,\nrw [H0]\nend\n\nlemma Q3cb_helper : \u2200 d : \u2115, 8*Q3sum d 3 11 = 11^(d+1)-3^(d+1) :=\nbegin\nintro d,\nchange (8:\u2124) with (11:\u2124)-3,\nrw [sub_mul,H3,H2],\nsimp,\nend\n\ntheorem Q3cbint (n : \u2115) : 8 \u2223 (11:\u2124)^n - 3^n :=\nbegin\ncases n with d,\n  simp,\nshow 8 \u2223 (11:\u2124)^(d+1) - 3^(d+1),\nrw [\u2190Q3cb_helper d],\nexistsi Q3sum d 3 11,\nrefl,\nend\n\ntheorem Q3cb (n : \u2115) : 8 \u2223 11^n - 3^n := -- non-inductive proof\nbegin\nrw \u2190int.coe_nat_dvd,\nrw [Q3helpful_lemma2],\napply Q3cbint,\nend\n\n--#check @finset.prod_image\n/-\n\nWhat's a sensible way to do 1+x+x^2+...+x^n?\n\nI'm still working on the details, but big_operations.lean deals with this stuff\n\nfinset.sum is the one you want (or list.sum, but the finset version has more algebraic properties on it)\n\n-/\n\n\ndef factorial : \u2115 \u2192 \u2115\n| 0 := 1\n| (n+1) := (factorial n) * (n+1)\n\ntheorem Q4 (n : \u2115) (H : n > 0) : factorial n < 3^n \u2194 n \u2264 6 :=\nbegin\ncases n with m,\n  revert H,\n  exact dec_trivial,\nclear H,\n\ncases m with m,split;exact dec_trivial,\ncases m with m,split;exact dec_trivial,\ncases m with m,split;exact dec_trivial,\n\ncases m with m,split;intros,exact dec_trivial,\nrepeat {unfold factorial monoid.pow},{norm_num},\n\ncases m with m,split;intros,exact dec_trivial,\nrepeat {unfold factorial monoid.pow},{norm_num},\n\ncases m with m,split;exact dec_trivial,\n\nsplit,\n  tactic.swap,\n  intro H,\n  exfalso,\n  revert H,\n  exact dec_trivial,\n\nintro this,exfalso,revert this,\napply not_lt_of_ge,\ninduction m with d Hd,\nrepeat {unfold factorial monoid.pow},{norm_num},\n\nlet e := nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ d)))))),\nchange nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ d)))))) with e,\nchange nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ d)))))) with e at Hd,\n\nhave He_ge_3 : nat.succ e \u2265 3 := by exact dec_trivial,\nexact calc\nfactorial (nat.succ e) = factorial e * (nat.succ e) : by unfold factorial\n... \u2265 factorial e * 3 : nat.mul_le_mul_left _ He_ge_3\n... \u2265 3^e*3 : nat.mul_le_mul_right 3 Hd\n... = 3*3^e : by rw mul_comm\n... = 3^nat.succ e : rfl,\nend\n\ntheorem Q5 : (\u00ac (\u2203 a b c : \u2115, 6*a+9*b+20*c = 43))\n             \u2227 \u2200 m, m \u2265 44 \u2192 \u2203 a b c : \u2115, 6*a+9*b+20*c = m :=\nbegin\nsplit,\n  intro H,\n  cases H with a H,\n  cases H with b H,\n  cases H with c H,\n  revert H,\n  cases c with c,tactic.swap,\n    cases c with c,tactic.swap,\n      cases c with c,tactic.swap,\n        show 6*a+9*b+20*(c+3) = 43 \u2192 false,\n        rw [mul_add],\n        apply ne_of_gt,\n        exact calc 6 * a + 9 * b + (20 * c + 20 * 3)\n                = 6*a + (9*b+(20*c+20*3)) : by simp\n            ... \u2265 9 * b + (20 * c + 20 * 3) : nat.le_add_left (9 * b + (20 * c + 20 * 3)) (6*a)\n            ... \u2265  20 * c + 20 * 3 : nat.le_add_left _ _\n            ... \u2265 20*3 : nat.le_add_left _ _\n            ... > 43 : dec_trivial,\n      cases b with b,tactic.swap,\n        show (6*a+9*(b+1)+20*2=43 \u2192 false),\n        rw [mul_add],\n        apply ne_of_gt,\n        exact calc 6 * a + (9 * b + 9 * 1) + 20 * 2\n            = (6*a+9*b)+9*1+20*2 : by simp\n        ... \u2265 9*1+20*2 : nat.le_add_left _ _\n        ... > 43 : dec_trivial,\n      cases a with a,\n        exact dec_trivial,\n      show 6*(a+1) + 9 * 0 + 20 * 2 = 43 \u2192 false,\n      rw [mul_add],\n      apply ne_of_gt,\n      exact calc 6 * a + 6 * 1 + 9 * 0 + 20 * 2\n              \u2265  6 * 1 + 9 * 0 + 20 * 2 : nat.le_add_left _ _\n          ... > 43 : dec_trivial,\n\n    cases b with b,tactic.swap,\n      cases b with b,tactic.swap,\n        cases b with b,tactic.swap,\n          show (6*a+9*(b+3)+20*1=43 \u2192 false),\n          rw [mul_add],\n          apply ne_of_gt,\n          exact calc 6 * a + (9 * b + 9 * 3) + 20 * 1\n            = (6*a+9*b)+9*3+20*1 : by simp\n        ... \u2265 9*3+20*1 : nat.le_add_left _ _\n        ... > 43 : dec_trivial,\n      cases a with a,\n        exact dec_trivial,\n      show 6*(a+1) + 9 * 2 + 20 * 1 = 43 \u2192 false,\n      rw [mul_add],\n      apply ne_of_gt,\n      exact calc 6 * a + 6 * 1 + 9 * 2 + 20 * 1\n              \u2265  6 * 1 + 9 * 2 + 20 * 1 : nat.le_add_left _ _\n          ... > 43 : dec_trivial,\n      cases a with a,\n        exact dec_trivial,\n      cases a with a,\n        exact dec_trivial,\n      cases a with a,\n        exact dec_trivial,\n      show 6*(a+3) + 9 * 1 + 20 * 1 = 43 \u2192 false,\n      rw [mul_add],\n      apply ne_of_gt,\n      exact calc 6 * a + 6 * 3 + 9 * 1 + 20 * 1\n              \u2265  6 * 3 + 9 * 1 + 20 * 1 : nat.le_add_left _ _\n          ... > 43 : dec_trivial,\n    cases a with a,\n      exact dec_trivial,\n    cases a with a,\n      exact dec_trivial,\n    cases a with a,\n      exact dec_trivial,\n    cases a with a,\n      exact dec_trivial,\n    show 6*(a+4) + 9 * 0 + 20 * 1 = 43 \u2192 false,\n    rw [mul_add],\n    apply ne_of_gt,\n    exact calc 6 * a + 6 * 4 + 9 * 0 + 20 * 1\n            \u2265  6 * 4 + 9 * 0 + 20 * 1 : nat.le_add_left _ _\n        ... > 43 : dec_trivial,\n\n\n  cases b with b,tactic.swap,\n    cases b with b,tactic.swap,\n      cases b with b,tactic.swap,\n        cases b with b,tactic.swap,\n          cases b with b,tactic.swap,\n            show (6*a+9*(b+5)+20*0=43 \u2192 false),\n            rw [mul_add],\n            apply ne_of_gt,\n            exact calc 6 * a + (9 * b + 9 * 5) + 20 * 0\n              = (6*a+9*b)+9*5+20*0 : by simp\n          ... \u2265 9*5+20*0 : nat.le_add_left _ _\n          ... > 43 : dec_trivial,\n      cases a with a,\n        exact dec_trivial,\n      cases a with a,\n        exact dec_trivial,\n      show 6*(a+2) + 9 * 4 + 20 * 0 = 43 \u2192 false,\n      rw [mul_add],\n      apply ne_of_gt,\n      exact calc 6 * a + 6 * 2 + 9 * 4 + 20 * 0\n              \u2265  6 * 2 + 9 * 4 + 20 * 0 : nat.le_add_left _ _\n          ... > 43 : dec_trivial,\n        cases a with a,exact dec_trivial,\n        cases a with a,exact dec_trivial,\n        cases a with a,exact dec_trivial,\n        show 6*(a+3) + 9 * 3 + 20 * 0 = 43 \u2192 false,\n        rw [mul_add],\n        apply ne_of_gt,\n        exact calc 6 * a + 6 * 3 + 9 * 3 + 20 * 0\n              \u2265  6 * 3 + 9 * 3 + 20 * 0 : nat.le_add_left _ _\n          ... > 43 : dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    show 6*(a+5) + 9 * 2 + 20 * 0 = 43 \u2192 false,\n    rw [mul_add],\n    apply ne_of_gt,\n    exact calc 6 * a + 6 * 5 + 9 * 2 + 20 * 0\n            \u2265  6 * 5 + 9 * 2 + 20 * 0 : nat.le_add_left _ _\n        ... > 43 : dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    cases a with a,exact dec_trivial,\n    show 6*(a+6) + 9 * 1 + 20 * 0 = 43 \u2192 false,\n    rw [mul_add],\n    apply ne_of_gt,\n    exact calc 6 * a + 6 * 6 + 9 * 1 + 20 * 0\n            \u2265  6 * 6 + 9 * 1 + 20 * 0 : nat.le_add_left _ _\n        ... > 43 : dec_trivial,\n  cases a with a,exact dec_trivial,\n  cases a with a,exact dec_trivial,\n  cases a with a,exact dec_trivial,\n  cases a with a,exact dec_trivial,\n  cases a with a,exact dec_trivial,\n  cases a with a,exact dec_trivial,\n  cases a with a,exact dec_trivial,\n  cases a with a,exact dec_trivial,\n  show 6*(a+8) + 9 * 0 + 20 * 0 = 43 \u2192 false,\n  rw [mul_add],\n  apply ne_of_gt,\n  exact calc 6 * a + 6 * 8 + 9 * 0 + 20 * 0\n          \u2265  6 * 8 + 9 * 0 + 20 * 0 : nat.le_add_left _ _\n      ... > 43 : dec_trivial,\n\n-- now the opposite\n\n-- proof that if m>=44 then it's 44+n\n-- probably would have been easier to do by induction on 44\n\nintros m Hm,\nhave H44 : \u2203 n : \u2115, m=44+n,\n  let c:\u2124 := m-((44:\u2115):\u2124),\n  have Hc_nonneg : c \u2265 0 := calc\n  c = \u2191m - \u219144 : rfl\n  ... = \u2191m + -\u219144 : sub_eq_add_neg _ _\n  ... \u2265 \u219144 + -\u219144 : add_le_add_right ((int.coe_nat_le_coe_nat_iff _ _).2 Hm) _\n  ... = 0 : add_neg_self _,\n  have H := int.nat_abs_of_nonneg Hc_nonneg,\n  let n := int.nat_abs c,\n  existsi n,\n  apply (int.of_nat_eq_of_nat_iff _ _).1,\n  rw [\u2190int.coe_nat_eq,\u2190int.coe_nat_eq,int.coe_nat_add,H,add_comm,sub_add_cancel],\n\ncases H44 with n H,\nrw [H],\nclear Hm H m,\n\n/- State now\n\nn : \u2115\n\u22a2 \u2203 (a b c : \u2115), 6 * a + 9 * b + 20 * c = 44 + n\n\n-/\n\n-- Now need division with remainder\n\nhave H6 : \u2203 q r : \u2115, n=6*q+r \u2227 (r=0 \u2228 r=1 \u2228 r=2 \u2228 r=3 \u2228 r=4 \u2228 r=5),\n  induction n with d Hd,\n    existsi 0,\n    existsi 0,\n    split,\n      simp,\n    simp,\n  cases Hd with q Hd',\n  cases Hd' with r HI,\n  cases HI.right with H0 H15,\n    existsi q,\n    existsi 1,\n    split,\n      simp [HI.left,H0,nat.succ_eq_add_one],\n    simp,\n  cases H15 with H H25,\n    existsi q,\n    existsi 2,\n    split,\n--      simp [nat.succ_eq_add_one,HI.left,H1],\n      rw [nat.succ_eq_add_one,HI.left,H],\n    simp,\n  cases H25 with H H35,\n    existsi q,\n    existsi 3,\n    split,\n      rw [nat.succ_eq_add_one,HI.left,H],\n    simp,\n  cases H35 with H H45,\n    existsi q,\n    existsi 4,\n    split,\n      rw [nat.succ_eq_add_one,HI.left,H],\n    simp,\n  cases H45 with H H5,\n    existsi q,\n    existsi 5,\n    split,\n      rw [nat.succ_eq_add_one,HI.left,H],\n    simp,\n  existsi q+1,\n  existsi 0,\n  split,\n    rw [nat.succ_eq_add_one,HI.left,H5,mul_add,mul_one],\n  simp,\n\ncases H6 with q H6',\ncases H6' with r H,\nrw [H.left],\nhave Hrsmall := H.right,\nclear H n,\n\n/-\n\nState now\n\nq r : \u2115\nHrsmall : r = 0 \u2228 r = 1 \u2228 r = 2 \u2228 r = 3 \u2228 r = 4 \u2228 r = 5\n\u22a2 \u2203 (a b c : \u2115), 6 * a + 9 * b + 20 * c = 44 + (6 * q + r)\n\n-/\n\ninduction q with d Hd,\n  cases Hrsmall with H H15,\n    existsi 4,existsi 0,existsi 1,\n    rw [H],exact dec_trivial,\n cases H15 with H H25,\n    existsi 0,existsi 5,existsi 0,\n    rw [H],exact dec_trivial,\n cases H25 with H H35,\n    existsi 1,existsi 0,existsi 2,\n    rw [H],exact dec_trivial,\n cases H35 with H H45,\n    existsi 0,existsi 3,existsi 1,\n    rw [H],exact dec_trivial,\n cases H45 with H H5,\n    existsi 8,existsi 0,existsi 0,\n    rw [H],exact dec_trivial,\n  existsi 0,existsi 1,existsi 2,\n    rw [H5],exact dec_trivial,\n\nclear Hrsmall,\n\ncases Hd with a Hd',\ncases Hd' with b Hd'',\ncases Hd'' with c H,\nexistsi (a+1),\nexistsi b,\nexistsi c,\nrw [nat.succ_eq_add_one,mul_add,mul_add,mul_one],\nrw [add_comm (6*a) 6,add_assoc,add_assoc],\nrw add_assoc at H,\nrw H,\nsimp,\nend\n\n\ntheorem Q6 : 1=1 := sorry -- blue-eyed islanders\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/2017-18/Example_Sheet_05/solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7375244476861849}}
{"text": "/-\nCopyright (c) 2021 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gabriel Ebner\n-/\nprelude\nimport Init.NotationExtra\n\nnamespace Nat\n\nprivate theorem log2_terminates : \u2200 n, n \u2265 2 \u2192 n / 2 < n\n  | 2, _ => by decide\n  | 3, _ => by decide\n  | n+4, _ => by\n    rw [div_eq, if_pos]\n    refine succ_lt_succ (Nat.lt_trans ?_ (lt_succ_self _))\n    exact log2_terminates (n+2) (succ_lt_succ (zero_lt_succ _))\n    exact \u27e8by decide, succ_lt_succ (zero_lt_succ _)\u27e9\n\n/--\nComputes `\u230amax 0 (log\u2082 n)\u230b`.\n\n`log2 0 = log2 1 = 0`, `log2 2 = 1`, ..., `log2 (2^i) = i`, etc.\n-/\n@[extern \"lean_nat_log2\"]\ndef log2 (n : @& Nat) : Nat :=\n  if h : n \u2265 2 then log2 (n / 2) + 1 else 0\ntermination_by _ => n\ndecreasing_by exact log2_terminates _ h\n", "meta": {"author": "Kha", "repo": "lean4-nightly", "sha": "b4c92de57090e6c47b29d3575df53d86fce52752", "save_path": "github-repos/lean/Kha-lean4-nightly", "path": "github-repos/lean/Kha-lean4-nightly/lean4-nightly-b4c92de57090e6c47b29d3575df53d86fce52752/stage0/src/Init/Data/Nat/Log2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7375244457261555}}
{"text": "/-\nCopyright (c) 2022 Antoine Labelle. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Labelle\n-/\nimport representation_theory.basic\nimport representation_theory.fdRep\n\n/-!\n# Subspace of invariants a group representation\n\nThis file introduces the subspace of invariants of a group representation\nand proves basic results about it.\nThe main tool used is the average of all elements of the group, seen as an element of\n`monoid_algebra k G`. The action of this special element gives a projection onto the\nsubspace of invariants.\nIn order for the definition of the average element to make sense, we need to assume for most of the\nresults that the order of `G` is invertible in `k` (e. g. `k` has characteristic `0`).\n-/\n\nopen_locale big_operators\nopen monoid_algebra\nopen representation\n\nnamespace group_algebra\n\nvariables (k G : Type*) [comm_semiring k] [group G]\nvariables [fintype G] [invertible (fintype.card G : k)]\n\n/--\nThe average of all elements of the group `G`, considered as an element of `monoid_algebra k G`.\n-/\nnoncomputable def average : monoid_algebra k G :=\n  \u215f(fintype.card G : k) \u2022 \u2211 g : G, of k G g\n\n/--\n`average k G` is invariant under left multiplication by elements of `G`.\n-/\n@[simp]\ntheorem mul_average_left (g : G) :\n  (finsupp.single g 1 * average k G : monoid_algebra k G) = average k G :=\nbegin\n  simp only [mul_one, finset.mul_sum, algebra.mul_smul_comm, average, monoid_algebra.of_apply,\n    finset.sum_congr, monoid_algebra.single_mul_single],\n  set f : G \u2192 monoid_algebra k G := \u03bb x, finsupp.single x 1,\n  show \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f (g * x) = \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f x,\n  rw function.bijective.sum_comp (group.mul_left_bijective g) _,\nend\n\n/--\n`average k G` is invariant under right multiplication by elements of `G`.\n-/\n@[simp]\ntheorem mul_average_right (g : G) :\n  average k G * finsupp.single g 1 = average k G :=\nbegin\n  simp only [mul_one, finset.sum_mul, algebra.smul_mul_assoc, average, monoid_algebra.of_apply,\n    finset.sum_congr, monoid_algebra.single_mul_single],\n  set f : G \u2192 monoid_algebra k G := \u03bb x, finsupp.single x 1,\n  show \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f (x * g) = \u215f \u2191(fintype.card G) \u2022 \u2211 (x : G), f x,\n  rw function.bijective.sum_comp (group.mul_right_bijective g) _,\nend\n\nend group_algebra\n\nnamespace representation\n\nsection invariants\n\nopen group_algebra\n\nvariables {k G V : Type*} [comm_semiring k] [group G] [add_comm_monoid V] [module k V]\nvariables (\u03c1 : representation k G V)\n\n/--\nThe subspace of invariants, consisting of the vectors fixed by all elements of `G`.\n-/\ndef invariants : submodule k V :=\n{ carrier := set_of (\u03bb v, \u2200 (g : G), \u03c1 g v = v),\n  zero_mem' := \u03bb g, by simp only [map_zero],\n  add_mem' := \u03bb v w hv hw g, by simp only [hv g, hw g, map_add],\n  smul_mem' := \u03bb r v hv g, by simp only [hv g, linear_map.map_smul\u209b\u2097, ring_hom.id_apply]}\n\n@[simp]\nlemma mem_invariants (v : V) : v \u2208 invariants \u03c1 \u2194 \u2200 (g: G), \u03c1 g v = v := by refl\n\nlemma invariants_eq_inter :\n  (invariants \u03c1).carrier = \u22c2 g : G, function.fixed_points (\u03c1 g) :=\nby {ext, simp [function.is_fixed_pt]}\n\nvariables [fintype G] [invertible (fintype.card G : k)]\n\n/--\nThe action of `average k G` gives a projection map onto the subspace of invariants.\n-/\n@[simp]\nnoncomputable def average_map : V \u2192\u2097[k] V := as_algebra_hom \u03c1 (average k G)\n\n/--\nThe `average_map` sends elements of `V` to the subspace of invariants.\n-/\ntheorem average_map_invariant (v : V) : average_map \u03c1 v \u2208 invariants \u03c1 :=\n\u03bb g, by rw [average_map, \u2190as_algebra_hom_single_one, \u2190linear_map.mul_apply,\n  \u2190map_mul (as_algebra_hom \u03c1), mul_average_left]\n\n/--\nThe `average_map` acts as the identity on the subspace of invariants.\n-/\ntheorem average_map_id (v : V) (hv : v \u2208 invariants \u03c1) : average_map \u03c1 v = v :=\nbegin\n  rw mem_invariants at hv,\n  simp [average, map_sum, hv, finset.card_univ, nsmul_eq_smul_cast k _ v, smul_smul],\nend\n\ntheorem is_proj_average_map : linear_map.is_proj \u03c1.invariants \u03c1.average_map :=\n\u27e8\u03c1.average_map_invariant, \u03c1.average_map_id\u27e9\n\nend invariants\n\nnamespace lin_hom\n\nuniverses u\n\nopen category_theory Action\n\nsection Rep\n\nvariables {k : Type u} [comm_ring k] {G : Group.{u}}\n\nlemma mem_invariants_iff_comm {X Y : Rep k G} (f : X.V \u2192\u2097[k] Y.V) (g : G) :\n  (lin_hom X.\u03c1 Y.\u03c1) g f = f \u2194 f.comp (X.\u03c1 g) = (Y.\u03c1 g).comp f :=\nbegin\n  dsimp,\n  erw [\u2190\u03c1_Aut_apply_inv],\n  rw [\u2190linear_map.comp_assoc, \u2190Module.comp_def, \u2190Module.comp_def, iso.inv_comp_eq, \u03c1_Aut_apply_hom],\n  exact comm,\nend\n\n/-- The invariants of the representation `lin_hom X.\u03c1 Y.\u03c1` correspond to the the representation\nhomomorphisms from `X` to `Y` -/\n@[simps]\ndef invariants_equiv_Rep_hom (X Y : Rep k G) : (lin_hom X.\u03c1 Y.\u03c1).invariants \u2243\u2097[k] (X \u27f6 Y) :=\n{ to_fun := \u03bb f, \u27e8f.val, \u03bb g, (mem_invariants_iff_comm _ g).1 (f.property g)\u27e9,\n  map_add' := \u03bb _ _, rfl,\n  map_smul' := \u03bb _ _, rfl,\n  inv_fun := \u03bb f, \u27e8f.hom, \u03bb g, (mem_invariants_iff_comm _ g).2 (f.comm g)\u27e9,\n  left_inv := \u03bb _, by { ext, refl },\n  right_inv := \u03bb _, by { ext, refl } }\n\nend Rep\n\nsection fdRep\n\nvariables {k : Type u} [field k] {G : Group.{u}}\n\n/-- The invariants of the representation `lin_hom X.\u03c1 Y.\u03c1` correspond to the the representation\nhomomorphisms from `X` to `Y` -/\ndef invariants_equiv_fdRep_hom (X Y : fdRep k G) : (lin_hom X.\u03c1 Y.\u03c1).invariants \u2243\u2097[k] (X \u27f6 Y) :=\nbegin\n  rw [\u2190fdRep.forget\u2082_\u03c1, \u2190fdRep.forget\u2082_\u03c1],\n  exact (lin_hom.invariants_equiv_Rep_hom _ _) \u226a\u226b\u2097 (fdRep.forget\u2082_hom_linear_equiv X Y),\nend\n\nend fdRep\n\nend lin_hom\n\nend representation\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/representation_theory/invariants.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7375005037932383}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport number_theory.class_number.admissible_card_pow_degree\nimport number_theory.class_number.finite\nimport number_theory.function_field\n\n/-!\n# Class numbers of function fields\n\nThis file defines the class number of a function field as the (finite) cardinality of\nthe class group of its ring of integers. It also proves some elementary results\non the class number.\n\n## Main definitions\n- `function_field.class_number`: the class number of a function field is the (finite)\ncardinality of the class group of its ring of integers\n-/\n\nnamespace function_field\nopen_locale polynomial\n\nvariables (Fq F : Type) [field Fq] [fintype Fq] [field F]\nvariables [algebra Fq[X] F] [algebra (ratfunc Fq) F]\nvariables [is_scalar_tower Fq[X] (ratfunc Fq) F]\nvariables [function_field Fq F] [is_separable (ratfunc Fq) F]\n\nopen_locale classical\n\nnamespace ring_of_integers\n\nopen function_field\n\nnoncomputable instance  : fintype (class_group (ring_of_integers Fq F) F) :=\nclass_group.fintype_of_admissible_of_finite (ratfunc Fq) F\n  (polynomial.card_pow_degree_is_admissible : absolute_value.is_admissible\n    (polynomial.card_pow_degree : absolute_value Fq[X] \u2124))\n\nend ring_of_integers\n\n/-- The class number in a function field is the (finite) cardinality of the class group. -/\nnoncomputable def class_number : \u2115 := fintype.card (class_group (ring_of_integers Fq F) F)\n\n/-- The class number of a function field is `1` iff the ring of integers is a PID. -/\ntheorem class_number_eq_one_iff :\n  class_number Fq F = 1 \u2194 is_principal_ideal_ring (ring_of_integers Fq F) :=\ncard_class_group_eq_one_iff\n\nend function_field\n", "meta": {"author": "lean-forward", "repo": "class-number-journal", "sha": "34d5872618d289ca3982bd9bc0c6e06af678909a", "save_path": "github-repos/lean/lean-forward-class-number-journal", "path": "github-repos/lean/lean-forward-class-number-journal/class-number-journal-34d5872618d289ca3982bd9bc0c6e06af678909a/src/class_number/function_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181418, "lm_q2_score": 0.8152324915965391, "lm_q1q2_score": 0.7375005013716105}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n\n! This file was ported from Lean 3 source module data.polynomial.mirror\n! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.BigOperators.NatAntidiagonal\nimport Mathlib.Data.Polynomial.RingDivision\n\n/-!\n# \"Mirror\" of a univariate polynomial\n\nIn this file we define `Polynomial.mirror`, a variant of `Polynomial.reverse`. The difference\nbetween `reverse` and `mirror` is that `reverse` will decrease the degree if the polynomial is\ndivisible by `X`.\n\n## Main definitions\n\n- `Polynomial.mirror`\n\n## Main results\n\n- `Polynomial.mirror_mul_of_domain`: `mirror` preserves multiplication.\n- `Polynomial.irreducible_of_mirror`: an irreducibility criterion involving `mirror`\n\n-/\n\n\nnamespace Polynomial\n\nopen Polynomial\n\nsection Semiring\n\nvariable {R : Type _} [Semiring R] (p q : R[X])\n\n/-- mirror of a polynomial: reverses the coefficients while preserving `Polynomial.natDegree` -/\nnoncomputable def mirror :=\n  p.reverse * X ^ p.natTrailingDegree\n#align polynomial.mirror Polynomial.mirror\n\n@[simp]\ntheorem mirror_zero : (0 : R[X]).mirror = 0 := by simp [mirror]\n#align polynomial.mirror_zero Polynomial.mirror_zero\n\ntheorem mirror_monomial (n : \u2115) (a : R) : (monomial n a).mirror = monomial n a := by\n  classical\n    by_cases ha : a = 0\n    \u00b7 rw [ha, monomial_zero_right, mirror_zero]\n    \u00b7 rw [mirror, reverse, natDegree_monomial n a, if_neg ha, natTrailingDegree_monomial ha, \u2190\n        C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, revAt_le (le_refl n), tsub_self, pow_zero,\n        mul_one]\n#align polynomial.mirror_monomial Polynomial.mirror_monomial\n\ntheorem mirror_C (a : R) : (C a).mirror = C a :=\n  mirror_monomial 0 a\nset_option linter.uppercaseLean3 false in\n#align polynomial.mirror_C Polynomial.mirror_C\n\ntheorem mirror_X : X.mirror = (X : R[X]) :=\n  mirror_monomial 1 (1 : R)\nset_option linter.uppercaseLean3 false in\n#align polynomial.mirror_X Polynomial.mirror_X\n\ntheorem mirror_natDegree : p.mirror.natDegree = p.natDegree := by\n  by_cases hp : p = 0\n  \u00b7 rw [hp, mirror_zero]\n  --Porting note: below two lines were `nontriviality R` in Lean3\n  have : p.leadingCoeff \u2260 0 := by simpa\n  let _ : Nontrivial R := nontrivial_of_ne _ _ this\n  rw [mirror, natDegree_mul', reverse_natDegree, natDegree_X_pow,\n    tsub_add_cancel_of_le p.natTrailingDegree_le_natDegree]\n  rwa [leadingCoeff_X_pow, mul_one, reverse_leadingCoeff, Ne, trailingCoeff_eq_zero]\n#align polynomial.mirror_nat_degree Polynomial.mirror_natDegree\n\ntheorem mirror_natTrailingDegree : p.mirror.natTrailingDegree = p.natTrailingDegree := by\n  by_cases hp : p = 0\n  \u00b7 rw [hp, mirror_zero]\n  \u00b7\n    rw [mirror, natTrailingDegree_mul_X_pow ((mt reverse_eq_zero.mp) hp),\n      reverse_natTrailingDegree, zero_add]\n#align polynomial.mirror_nat_trailing_degree Polynomial.mirror_natTrailingDegree\n\ntheorem coeff_mirror (n : \u2115) :\n    p.mirror.coeff n = p.coeff (revAt (p.natDegree + p.natTrailingDegree) n) := by\n  by_cases h2 : p.natDegree < n\n  \u00b7 rw [coeff_eq_zero_of_natDegree_lt (by rwa [mirror_natDegree])]\n    by_cases h1 : n \u2264 p.natDegree + p.natTrailingDegree\n    \u00b7 rw [revAt_le h1, coeff_eq_zero_of_lt_natTrailingDegree]\n      exact (tsub_lt_iff_left h1).mpr (Nat.add_lt_add_right h2 _)\n    \u00b7 rw [\u2190 revAtFun_eq, revAtFun, if_neg h1, coeff_eq_zero_of_natDegree_lt h2]\n  rw [not_lt] at h2\n  rw [revAt_le (h2.trans (Nat.le_add_right _ _))]\n  by_cases h3 : p.natTrailingDegree \u2264 n\n  \u00b7 rw [\u2190 tsub_add_eq_add_tsub h2, \u2190 tsub_tsub_assoc h2 h3, mirror, coeff_mul_X_pow', if_pos h3,\n      coeff_reverse, revAt_le (tsub_le_self.trans h2)]\n  rw [not_le] at h3\n  rw [coeff_eq_zero_of_natDegree_lt (lt_tsub_iff_right.mpr (Nat.add_lt_add_left h3 _))]\n  exact coeff_eq_zero_of_lt_natTrailingDegree (by rwa [mirror_natTrailingDegree])\n#align polynomial.coeff_mirror Polynomial.coeff_mirror\n\n--TODO: Extract `finset.sum_range_rev_at` lemma.\ntheorem mirror_eval_one : p.mirror.eval 1 = p.eval 1 := by\n  simp_rw [eval_eq_sum_range, one_pow, mul_one, mirror_natDegree]\n  refine' Finset.sum_bij_ne_zero _ _ _ _ _\n  \u00b7 exact fun n _ _ => revAt (p.natDegree + p.natTrailingDegree) n\n  \u00b7 intro n hn hp\n    rw [Finset.mem_range_succ_iff] at *\n    rw [revAt_le (hn.trans (Nat.le_add_right _ _))]\n    rw [tsub_le_iff_tsub_le, add_comm, add_tsub_cancel_right, \u2190 mirror_natTrailingDegree]\n    exact natTrailingDegree_le_of_ne_zero hp\n  \u00b7 exact fun n\u2081 n\u2082 _ _ _ _ h => by rw [\u2190 @revAt_invol _ n\u2081, h, revAt_invol]\n  \u00b7 intro n hn hp\n    use revAt (p.natDegree + p.natTrailingDegree) n\n    refine' \u27e8_, _, revAt_invol.symm\u27e9\n    \u00b7 rw [Finset.mem_range_succ_iff] at *\n      rw [revAt_le (hn.trans (Nat.le_add_right _ _))]\n      rw [tsub_le_iff_tsub_le, add_comm, add_tsub_cancel_right]\n      exact natTrailingDegree_le_of_ne_zero hp\n    \u00b7 change p.mirror.coeff _ \u2260 0\n      rwa [coeff_mirror, revAt_invol]\n  \u00b7 exact fun n _ _ => p.coeff_mirror n\n#align polynomial.mirror_eval_one Polynomial.mirror_eval_one\n\ntheorem mirror_mirror : p.mirror.mirror = p :=\n  Polynomial.ext fun n => by\n    rw [coeff_mirror, coeff_mirror, mirror_natDegree, mirror_natTrailingDegree, revAt_invol]\n#align polynomial.mirror_mirror Polynomial.mirror_mirror\n\nvariable {p q}\n\ntheorem mirror_involutive : Function.Involutive (mirror : R[X] \u2192 R[X]) :=\n  mirror_mirror\n#align polynomial.mirror_involutive Polynomial.mirror_involutive\n\ntheorem mirror_eq_iff : p.mirror = q \u2194 p = q.mirror :=\n  mirror_involutive.eq_iff\n#align polynomial.mirror_eq_iff Polynomial.mirror_eq_iff\n\n@[simp]\ntheorem mirror_inj : p.mirror = q.mirror \u2194 p = q :=\n  mirror_involutive.injective.eq_iff\n#align polynomial.mirror_inj Polynomial.mirror_inj\n\n@[simp]\ntheorem mirror_eq_zero : p.mirror = 0 \u2194 p = 0 :=\n  \u27e8fun h => by rw [\u2190 p.mirror_mirror, h, mirror_zero], fun h => by rw [h, mirror_zero]\u27e9\n#align polynomial.mirror_eq_zero Polynomial.mirror_eq_zero\n\nvariable (p q)\n\n@[simp]\ntheorem mirror_trailingCoeff : p.mirror.trailingCoeff = p.leadingCoeff := by\n  rw [leadingCoeff, trailingCoeff, mirror_natTrailingDegree, coeff_mirror,\n    revAt_le (Nat.le_add_left _ _), add_tsub_cancel_right]\n#align polynomial.mirror_trailing_coeff Polynomial.mirror_trailingCoeff\n\n@[simp]\ntheorem mirror_leadingCoeff : p.mirror.leadingCoeff = p.trailingCoeff := by\n  rw [\u2190 p.mirror_mirror, mirror_trailingCoeff, p.mirror_mirror]\n#align polynomial.mirror_leading_coeff Polynomial.mirror_leadingCoeff\n\ntheorem coeff_mul_mirror :\n    (p * p.mirror).coeff (p.natDegree + p.natTrailingDegree) = p.sum fun n => (\u00b7 ^ 2) := by\n  rw [coeff_mul, Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk]\n  refine'\n    (Finset.sum_congr rfl fun n hn => _).trans\n      (p.sum_eq_of_subset (fun _ => (\u00b7 ^ 2)) (fun _ => zero_pow zero_lt_two) _ fun n hn =>\n          Finset.mem_range_succ_iff.mpr\n            ((le_natDegree_of_mem_supp n hn).trans (Nat.le_add_right _ _))).symm\n  rw [coeff_mirror, \u2190 revAt_le (Finset.mem_range_succ_iff.mp hn), revAt_invol, \u2190 sq]\n#align polynomial.coeff_mul_mirror Polynomial.coeff_mul_mirror\n\nvariable [NoZeroDivisors R]\n\ntheorem natDegree_mul_mirror : (p * p.mirror).natDegree = 2 * p.natDegree := by\n  by_cases hp : p = 0\n  \u00b7 rw [hp, MulZeroClass.zero_mul, natDegree_zero, MulZeroClass.mul_zero]\n  rw [natDegree_mul hp (mt mirror_eq_zero.mp hp), mirror_natDegree, two_mul]\n#align polynomial.nat_degree_mul_mirror Polynomial.natDegree_mul_mirror\n\ntheorem natTrailingDegree_mul_mirror : (p * p.mirror).natTrailingDegree = 2 * p.natTrailingDegree :=\n  by\n  by_cases hp : p = 0\n  \u00b7 rw [hp, MulZeroClass.zero_mul, natTrailingDegree_zero, MulZeroClass.mul_zero]\n  rw [natTrailingDegree_mul hp (mt mirror_eq_zero.mp hp), mirror_natTrailingDegree, two_mul]\n#align polynomial.nat_trailing_degree_mul_mirror Polynomial.natTrailingDegree_mul_mirror\n\nend Semiring\n\nsection Ring\n\nvariable {R : Type _} [Ring R] (p q : R[X])\n\ntheorem mirror_neg : (-p).mirror = -p.mirror := by\n  rw [mirror, mirror, reverse_neg, natTrailingDegree_neg, neg_mul_eq_neg_mul]\n#align polynomial.mirror_neg Polynomial.mirror_neg\n\nvariable [NoZeroDivisors R]\n\ntheorem mirror_mul_of_domain : (p * q).mirror = p.mirror * q.mirror := by\n  by_cases hp : p = 0\n  \u00b7 rw [hp, MulZeroClass.zero_mul, mirror_zero, MulZeroClass.zero_mul]\n  by_cases hq : q = 0\n  \u00b7 rw [hq, MulZeroClass.mul_zero, mirror_zero, MulZeroClass.mul_zero]\n  rw [mirror, mirror, mirror, reverse_mul_of_domain, natTrailingDegree_mul hp hq, pow_add]\n  rw [mul_assoc, \u2190 mul_assoc q.reverse, \u2190 X_pow_mul (p := reverse q)]\n  repeat' rw [mul_assoc]\n#align polynomial.mirror_mul_of_domain Polynomial.mirror_mul_of_domain\n\ntheorem mirror_smul (a : R) : (a \u2022 p).mirror = a \u2022 p.mirror := by\n  rw [\u2190 C_mul', \u2190 C_mul', mirror_mul_of_domain, mirror_C]\n#align polynomial.mirror_smul Polynomial.mirror_smul\n\nend Ring\n\nsection CommRing\n\nvariable {R : Type _} [CommRing R] [NoZeroDivisors R] {f : R[X]}\n\ntheorem irreducible_of_mirror (h1 : \u00acIsUnit f)\n    (h2 : \u2200 k, f * f.mirror = k * k.mirror \u2192 k = f \u2228 k = -f \u2228 k = f.mirror \u2228 k = -f.mirror)\n    (h3 : \u2200 g, g \u2223 f \u2192 g \u2223 f.mirror \u2192 IsUnit g) : Irreducible f := by\n  constructor\n  \u00b7 exact h1\n  \u00b7 intro g h fgh\n    let k := g * h.mirror\n    have key : f * f.mirror = k * k.mirror := by\n      rw [fgh, mirror_mul_of_domain, mirror_mul_of_domain, mirror_mirror, mul_assoc, mul_comm h,\n        mul_comm g.mirror, mul_assoc, \u2190 mul_assoc]\n    have g_dvd_f : g \u2223 f := by\n      rw [fgh]\n      exact dvd_mul_right g h\n    have h_dvd_f : h \u2223 f := by\n      rw [fgh]\n      exact dvd_mul_left h g\n    have g_dvd_k : g \u2223 k := dvd_mul_right g h.mirror\n    have h_dvd_k_rev : h \u2223 k.mirror := by\n      rw [mirror_mul_of_domain, mirror_mirror]\n      exact dvd_mul_left h g.mirror\n    have hk := h2 k key\n    rcases hk with (hk | hk | hk | hk)\n    \u00b7 exact Or.inr (h3 h h_dvd_f (by rwa [\u2190 hk]))\n    \u00b7 exact Or.inr (h3 h h_dvd_f (by rwa [\u2190 neg_eq_iff_eq_neg.mpr hk, mirror_neg, dvd_neg]))\n    \u00b7 exact Or.inl (h3 g g_dvd_f (by rwa [\u2190 hk]))\n    \u00b7 exact Or.inl (h3 g g_dvd_f (by rwa [\u2190 neg_eq_iff_eq_neg.mpr hk, dvd_neg]))\n#align polynomial.irreducible_of_mirror Polynomial.irreducible_of_mirror\n\nend CommRing\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Mirror.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7374604474532827}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n\n! This file was ported from Lean 3 source module algebra.tropical.big_operators\n! leanprover-community/mathlib commit d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.List.MinMax\nimport Mathlib.Algebra.Tropical.Basic\nimport Mathlib.Order.ConditionallyCompleteLattice.Finset\n\n/-!\n\n# Tropicalization of finitary operations\n\nThis file provides the \"big-op\" or notation-based finitary operations on tropicalized types.\nThis allows easy conversion between sums to Infs and prods to sums. Results here are important\nfor expressing that evaluation of tropical polynomials are the minimum over a finite piecewise\ncollection of linear functions.\n\n## Main declarations\n\n* `untrop_sum`\n\n## Implementation notes\n\nNo concrete (semi)ring is used here, only ones with inferrable order/lattice structure, to support\n`Real`, `Rat`, `EReal`, and others (`ERat` is not yet defined).\n\nMinima over `List \u03b1` are defined as producing a value in `WithTop \u03b1` so proofs about lists do not\ndirectly transfer to minima over multisets or finsets.\n\n-/\n\nopen BigOperators\n\nvariable {R S : Type _}\n\nopen Tropical Finset\n\ntheorem List.trop_sum [AddMonoid R] (l : List R) : trop l.sum = List.prod (l.map trop) := by\n  induction' l with hd tl IH\n  \u00b7 simp\n  \u00b7 simp [\u2190 IH]\n#align list.trop_sum List.trop_sum\n\ntheorem Multiset.trop_sum [AddCommMonoid R] (s : Multiset R) :\n    trop s.sum = Multiset.prod (s.map trop) :=\n  Quotient.inductionOn s (by simpa using List.trop_sum)\n#align multiset.trop_sum Multiset.trop_sum\n\ntheorem trop_sum [AddCommMonoid R] (s : Finset S) (f : S \u2192 R) :\n    trop (\u2211 i in s, f i) = \u220f i in s, trop (f i) := by\n  convert Multiset.trop_sum (s.val.map f)\n  simp only [Multiset.map_map, Function.comp_apply]\n  rfl\n#align trop_sum trop_sum\n\ntheorem List.untrop_prod [AddMonoid R] (l : List (Tropical R)) :\n    untrop l.prod = List.sum (l.map untrop) := by\n  induction' l with hd tl IH\n  \u00b7 simp\n  \u00b7 simp [\u2190 IH]\n#align list.untrop_prod List.untrop_prod\n\ntheorem Multiset.untrop_prod [AddCommMonoid R] (s : Multiset (Tropical R)) :\n    untrop s.prod = Multiset.sum (s.map untrop) :=\n  Quotient.inductionOn s (by simpa using List.untrop_prod)\n#align multiset.untrop_prod Multiset.untrop_prod\n\ntheorem untrop_prod [AddCommMonoid R] (s : Finset S) (f : S \u2192 Tropical R) :\n    untrop (\u220f i in s, f i) = \u2211 i in s, untrop (f i) := by\n  convert Multiset.untrop_prod (s.val.map f)\n  simp only [Multiset.map_map, Function.comp_apply]\n  rfl\n#align untrop_prod untrop_prod\n\n-- Porting note: replaced `coe` with `WithTop.some` in statement\ntheorem List.trop_minimum [LinearOrder R] (l : List R) :\n    trop l.minimum = List.sum (l.map (trop \u2218 WithTop.some)) := by\n  induction' l with hd tl IH\n  \u00b7 simp\n  \u00b7 simp [List.minimum_cons, \u2190 IH]\n#align list.trop_minimum List.trop_minimum\n\ntheorem Multiset.trop_inf [LinearOrder R] [OrderTop R] (s : Multiset R) :\n    trop s.inf = Multiset.sum (s.map trop) := by\n  induction' s using Multiset.induction with s x IH\n  \u00b7 simp\n  \u00b7 simp [\u2190 IH]\n#align multiset.trop_inf Multiset.trop_inf\n\ntheorem Finset.trop_inf [LinearOrder R] [OrderTop R] (s : Finset S) (f : S \u2192 R) :\n    trop (s.inf f) = \u2211 i in s, trop (f i) := by\n  convert Multiset.trop_inf (s.val.map f)\n  simp only [Multiset.map_map, Function.comp_apply]\n  rfl\n#align finset.trop_inf Finset.trop_inf\n\ntheorem trop_inf\u209b_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S \u2192 WithTop R) :\n    trop (inf\u209b (f '' s)) = \u2211 i in s, trop (f i) := by\n  rcases s.eq_empty_or_nonempty with (rfl | h)\n  \u00b7 simp only [Set.image_empty, coe_empty, sum_empty, WithTop.inf\u209b_empty, trop_top]\n  rw [\u2190 inf'_eq_cinf\u209b_image _ h, inf'_eq_inf, s.trop_inf]\n#align trop_Inf_image trop_inf\u209b_image\n\ntheorem trop_inf\u1d62 [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S \u2192 WithTop R) :\n    trop (\u2a05 i : S, f i) = \u2211 i : S, trop (f i) := by\n  rw [inf\u1d62, \u2190 Set.image_univ, \u2190 coe_univ, trop_inf\u209b_image]\n#align trop_infi trop_inf\u1d62\n\ntheorem Multiset.untrop_sum [LinearOrder R] [OrderTop R] (s : Multiset (Tropical R)) :\n    untrop s.sum = Multiset.inf (s.map untrop) := by\n  induction' s using Multiset.induction with s x IH\n  \u00b7 simp\n  \u00b7 simp only [sum_cons, ge_iff_le, untrop_add, untrop_le_iff, map_cons, inf_cons, \u2190 IH]\n    rfl\n#align multiset.untrop_sum Multiset.untrop_sum\n\ntheorem Finset.untrop_sum' [LinearOrder R] [OrderTop R] (s : Finset S) (f : S \u2192 Tropical R) :\n    untrop (\u2211 i in s, f i) = s.inf (untrop \u2218 f) := by\n  convert Multiset.untrop_sum (s.val.map f)\n  simp only [Multiset.map_map, Function.comp_apply]\n  rfl\n#align finset.untrop_sum' Finset.untrop_sum'\n\ntheorem untrop_sum_eq_inf\u209b_image [ConditionallyCompleteLinearOrder R] (s : Finset S)\n    (f : S \u2192 Tropical (WithTop R)) : untrop (\u2211 i in s, f i) = inf\u209b (untrop \u2218 f '' s) := by\n  rcases s.eq_empty_or_nonempty with (rfl | h)\n  \u00b7 simp only [Set.image_empty, coe_empty, sum_empty, WithTop.inf\u209b_empty, untrop_zero]\n  \u00b7 rw [\u2190 inf'_eq_cinf\u209b_image _ h, inf'_eq_inf, Finset.untrop_sum']\n#align untrop_sum_eq_Inf_image untrop_sum_eq_inf\u209b_image\n\ntheorem untrop_sum [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S \u2192 Tropical (WithTop R)) :\n    untrop (\u2211 i : S, f i) = \u2a05 i : S, untrop (f i) := by\n  rw [inf\u1d62,\u2190 Set.image_univ,\u2190 coe_univ, untrop_sum_eq_inf\u209b_image]\n  rfl\n#align untrop_sum untrop_sum\n\n/-- Note we cannot use `i \u2208 s` instead of `i : s` here\nas it is simply not true on conditionally complete lattices! -/\ntheorem Finset.untrop_sum [ConditionallyCompleteLinearOrder R] (s : Finset S)\n    (f : S \u2192 Tropical (WithTop R)) : untrop (\u2211 i in s, f i) = \u2a05 i : s, untrop (f i) := by\n  simpa [\u2190 _root_.untrop_sum] using sum_attach.symm\n#align finset.untrop_sum Finset.untrop_sum\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Tropical/BigOperators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7374604351625472}}
{"text": "/-\n3. Prove \u00ac(p \u2194 \u00acp) without using classical logic.\n-/\n\nvariables p : Prop\n\nexample : \u00ac(p \u2194 \u00acp) :=\n    assume hpiffnp : p \u2194 \u00acp,\n    have hpimplnp : p \u2192 \u00acp, from iff.elim_left hpiffnp,\n    have hnpimplp : \u00acp \u2192 p, from iff.elim_right hpiffnp,\n    have hnp : \u00acp, from\n        assume hp : p,\n        show false, from absurd hp (hpimplnp hp),\n    have hp : p, from hnpimplp hnp,\n    absurd hp hnp\n-- short version\nexample : \u00ac(p \u2194 \u00acp) :=\n    \u03bb h,\n    have hnp : \u00acp, from \u03bb hp, absurd hp (h.mp hp),\n    absurd (h.mpr hnp) hnp\n", "meta": {"author": "ishioka0222", "repo": "theorem-proving-in-lean", "sha": "78884884cbf5b94fe2afb818e948b8168a53ea3d", "save_path": "github-repos/lean/ishioka0222-theorem-proving-in-lean", "path": "github-repos/lean/ishioka0222-theorem-proving-in-lean/theorem-proving-in-lean-78884884cbf5b94fe2afb818e948b8168a53ea3d/src/ch03-ex03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7374242420750057}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jeremy Avigad\n\nExtensional equality for functions, and a proof of function extensionality from quotients.\n\n! This file was ported from Lean 3 source module init.funext\n! leanprover-community/mathlib commit 855e0efed3137762a7ba9aca242499b3cce59406\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nprelude\nimport Leanbin.Init.Data.Quot\nimport Leanbin.Init.Logic\n\nopen Quotient\n\nuniverse u v\n\nvariable {\u03b1 : Sort u} {\u03b2 : \u03b1 \u2192 Sort v}\n\nnamespace Function\n\n/-- The relation stating that two functions are pointwise equal. -/\nprotected def Equiv (f\u2081 f\u2082 : \u2200 x : \u03b1, \u03b2 x) : Prop :=\n  \u2200 x, f\u2081 x = f\u2082 x\n#align function.equiv Function.Equiv\n\n-- mathport name: \u00abexpr ~ \u00bb\nlocal infixl:50 \" ~ \" => Function.Equiv\n\nprotected theorem Equiv.refl (f : \u2200 x : \u03b1, \u03b2 x) : f ~ f := fun x => rfl\n#align function.equiv.refl Function.Equiv.refl\n\nprotected theorem Equiv.symm {f\u2081 f\u2082 : \u2200 x : \u03b1, \u03b2 x} : f\u2081 ~ f\u2082 \u2192 f\u2082 ~ f\u2081 := fun h x => Eq.symm (h x)\n#align function.equiv.symm Function.Equiv.symm\n\nprotected theorem Equiv.trans {f\u2081 f\u2082 f\u2083 : \u2200 x : \u03b1, \u03b2 x} : f\u2081 ~ f\u2082 \u2192 f\u2082 ~ f\u2083 \u2192 f\u2081 ~ f\u2083 :=\n  fun h\u2081 h\u2082 x => Eq.trans (h\u2081 x) (h\u2082 x)\n#align function.equiv.trans Function.Equiv.trans\n\nprotected theorem Equiv.is_equivalence (\u03b1 : Sort u) (\u03b2 : \u03b1 \u2192 Sort v) :\n    Equivalence (@Function.Equiv \u03b1 \u03b2) :=\n  Equivalence.mk (@Function.Equiv \u03b1 \u03b2) (@Equiv.refl \u03b1 \u03b2) (@Equiv.symm \u03b1 \u03b2) (@Equiv.trans \u03b1 \u03b2)\n#align function.equiv.is_equivalence Function.Equiv.is_equivalence\n\n/-- The setoid generated by pointwise equality. -/\n@[local instance]\ndef funSetoid (\u03b1 : Sort u) (\u03b2 : \u03b1 \u2192 Sort v) : Setoid (\u2200 x : \u03b1, \u03b2 x) :=\n  Setoid.mk (@Function.Equiv \u03b1 \u03b2) (Function.Equiv.is_equivalence \u03b1 \u03b2)\n#align function.fun_setoid Function.funSetoid\n\n/-- The quotient of the function type by pointwise equality. -/\ndef Extfun (\u03b1 : Sort u) (\u03b2 : \u03b1 \u2192 Sort v) : Sort imax u v :=\n  Quotient (funSetoid \u03b1 \u03b2)\n#align function.extfun Function.Extfun\n\n/-- The map from functions into the qquotient by pointwise equality. -/\ndef funToExtfun (f : \u2200 x : \u03b1, \u03b2 x) : Extfun \u03b1 \u03b2 :=\n  \u27e6f\u27e7\n#align function.fun_to_extfun Function.funToExtfun\n\n/-- From an element of `extfun` we can retrieve an actual function. -/\ndef extfunApp (f : Extfun \u03b1 \u03b2) : \u2200 x : \u03b1, \u03b2 x := fun x =>\n  Quot.liftOn f (fun f : \u2200 x : \u03b1, \u03b2 x => f x) fun f\u2081 f\u2082 h => h x\n#align function.extfun_app Function.extfunApp\n\nend Function\n\nopen Function\n\nattribute [local instance] fun_setoid\n\n#print funext /-\n/-- Function extensionality, proven using quotients. -/\ntheorem funext {f\u2081 f\u2082 : \u2200 x : \u03b1, \u03b2 x} (h : \u2200 x, f\u2081 x = f\u2082 x) : f\u2081 = f\u2082 :=\n  show extfunApp \u27e6f\u2081\u27e7 = extfunApp \u27e6f\u2082\u27e7 from congr_arg extfunApp (sound h)\n#align funext funext\n-/\n\nattribute [intro!] funext\n\n-- mathport name: \u00abexpr ~ \u00bb\nlocal infixl:50 \" ~ \" => Function.Equiv\n\ninstance Pi.subsingleton [\u2200 a, Subsingleton (\u03b2 a)] : Subsingleton (\u2200 a, \u03b2 a) :=\n  \u27e8fun f\u2081 f\u2082 => funext fun a => Subsingleton.elim (f\u2081 a) (f\u2082 a)\u27e9\n#align pi.subsingleton Pi.subsingleton\n\n", "meta": {"author": "leanprover-community", "repo": "lean3port", "sha": "9ed1898f23e4379865ee93d62cb6353e5ed6c270", "save_path": "github-repos/lean/leanprover-community-lean3port", "path": "github-repos/lean/leanprover-community-lean3port/lean3port-9ed1898f23e4379865ee93d62cb6353e5ed6c270/Leanbin/Init/Funext.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7373939307045538}}
{"text": "/-\nCopyright (c) 2021 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Devon Tuma\n-/\nimport analysis.asymptotics.asymptotics\nimport analysis.normed.order.basic\nimport data.polynomial.eval\nimport topology.algebra.order.liminf_limsup\n\n/-!\n# Super-Polynomial Function Decay\n\nThis file defines a predicate `asymptotics.superpolynomial_decay f` for a function satisfying\n  one of following equivalent definitions (The definition is in terms of the first condition):\n\n* `x ^ n * f` tends to `\ud835\udcdd 0` for all (or sufficiently large) naturals `n`\n* `|x ^ n * f|` tends to `\ud835\udcdd 0` for all naturals `n` (`superpolynomial_decay_iff_abs_tendsto_zero`)\n* `|x ^ n * f|` is bounded for all naturals `n` (`superpolynomial_decay_iff_abs_is_bounded_under`)\n* `f` is `o(x ^ c)` for all integers `c` (`superpolynomial_decay_iff_is_o`)\n* `f` is `O(x ^ c)` for all integers `c` (`superpolynomial_decay_iff_is_O`)\n\nThese conditions are all equivalent to conditions in terms of polynomials, replacing `x ^ c` with\n  `p(x)` or `p(x)\u207b\u00b9` as appropriate, since asymptotically `p(x)` behaves like `X ^ p.nat_degree`.\nThese further equivalences are not proven in mathlib but would be good future projects.\n\nThe definition of superpolynomial decay for `f : \u03b1 \u2192 \u03b2` is relative to a parameter `k : \u03b1 \u2192 \u03b2`.\nSuper-polynomial decay then means `f x` decays faster than `(k x) ^ c` for all integers `c`.\nEquivalently `f x` decays faster than `p.eval (k x)` for all polynomials `p : \u03b2[X]`.\nThe definition is also relative to a filter `l : filter \u03b1` where the decay rate is compared.\n\nWhen the map `k` is given by `n \u21a6 \u2191n : \u2115 \u2192 \u211d` this defines negligible functions:\nhttps://en.wikipedia.org/wiki/Negligible_function\n\nWhen the map `k` is given by `(r\u2081,...,r\u2099) \u21a6 r\u2081*...*r\u2099 : \u211d\u207f \u2192 \u211d` this is equivalent\n  to the definition of rapidly decreasing functions given here:\nhttps://ncatlab.org/nlab/show/rapidly+decreasing+function\n\n# Main Theorems\n\n* `superpolynomial_decay.polynomial_mul` says that if `f(x)` is negligible,\n    then so is `p(x) * f(x)` for any polynomial `p`.\n* `superpolynomial_decay_iff_zpow_tendsto_zero` gives an equivalence between definitions in terms\n    of decaying faster than `k(x) ^ n` for all naturals `n` or `k(x) ^ c` for all integer `c`.\n-/\n\nnamespace asymptotics\n\nopen_locale topology polynomial\nopen filter\n\n/-- `f` has superpolynomial decay in parameter `k` along filter `l` if\n  `k ^ n * f` tends to zero at `l` for all naturals `n` -/\ndef superpolynomial_decay {\u03b1 \u03b2 : Type*} [topological_space \u03b2] [comm_semiring \u03b2]\n  (l : filter \u03b1) (k : \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) :=\n\u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), (k a) ^ n * f a) l (\ud835\udcdd 0)\n\nvariables {\u03b1 \u03b2 : Type*} {l : filter \u03b1} {k : \u03b1 \u2192 \u03b2} {f g g' : \u03b1 \u2192 \u03b2}\n\nsection comm_semiring\n\nvariables [topological_space \u03b2] [comm_semiring \u03b2]\n\nlemma superpolynomial_decay.congr' (hf : superpolynomial_decay l k f)\n  (hfg : f =\u1da0[l] g) : superpolynomial_decay l k g :=\n\u03bb z, (hf z).congr' (eventually_eq.mul (eventually_eq.refl l _) hfg)\n\nlemma superpolynomial_decay.congr (hf : superpolynomial_decay l k f)\n  (hfg : \u2200 x, f x = g x) : superpolynomial_decay l k g :=\n\u03bb z, (hf z).congr (\u03bb x, congr_arg (\u03bb a, k x ^ z * a) $ hfg x)\n\n@[simp]\nlemma superpolynomial_decay_zero (l : filter \u03b1) (k : \u03b1 \u2192 \u03b2) :\n  superpolynomial_decay l k 0 :=\n\u03bb z, by simpa only [pi.zero_apply, mul_zero] using tendsto_const_nhds\n\nlemma superpolynomial_decay.add [has_continuous_add \u03b2] (hf : superpolynomial_decay l k f)\n  (hg : superpolynomial_decay l k g) : superpolynomial_decay l k (f + g) :=\n\u03bb z, by simpa only [mul_add, add_zero, pi.add_apply] using (hf z).add (hg z)\n\nlemma superpolynomial_decay.mul [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (hg : superpolynomial_decay l k g) : superpolynomial_decay l k (f * g) :=\n\u03bb z, by simpa only [mul_assoc, one_mul, mul_zero, pow_zero] using (hf z).mul (hg 0)\n\nlemma superpolynomial_decay.mul_const [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (c : \u03b2) : superpolynomial_decay l k (\u03bb n, f n * c) :=\n\u03bb z, by simpa only [\u2190mul_assoc, zero_mul] using tendsto.mul_const c (hf z)\n\nlemma superpolynomial_decay.const_mul [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (c : \u03b2) : superpolynomial_decay l k (\u03bb n, c * f n) :=\n(hf.mul_const c).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.param_mul (hf : superpolynomial_decay l k f) :\n  superpolynomial_decay l k (k * f) :=\n\u03bb z, tendsto_nhds.2 (\u03bb s hs hs0, l.sets_of_superset ((tendsto_nhds.1 (hf $ z + 1)) s hs hs0)\n  (\u03bb x hx, by simpa only [set.mem_preimage, pi.mul_apply, \u2190 mul_assoc, \u2190 pow_succ'] using hx))\n\nlemma superpolynomial_decay.mul_param (hf : superpolynomial_decay l k f) :\n  superpolynomial_decay l k (f * k) :=\n(hf.param_mul).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.param_pow_mul (hf : superpolynomial_decay l k f)\n  (n : \u2115) : superpolynomial_decay l k (k ^ n * f) :=\nbegin\n  induction n with n hn,\n  { simpa only [one_mul, pow_zero] using hf },\n  { simpa only [pow_succ, mul_assoc] using hn.param_mul }\nend\n\nlemma superpolynomial_decay.mul_param_pow (hf : superpolynomial_decay l k f)\n  (n : \u2115) : superpolynomial_decay l k (f * k ^ n) :=\n(hf.param_pow_mul n).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.polynomial_mul [has_continuous_add \u03b2] [has_continuous_mul \u03b2]\n  (hf : superpolynomial_decay l k f) (p : \u03b2[X]) :\n  superpolynomial_decay l k (\u03bb x, (p.eval $ k x) * f x) :=\npolynomial.induction_on' p (\u03bb p q hp hq, by simpa [add_mul] using hp.add hq)\n  (\u03bb n c, by simpa [mul_assoc] using (hf.param_pow_mul n).const_mul c)\n\nlemma superpolynomial_decay.mul_polynomial [has_continuous_add \u03b2] [has_continuous_mul \u03b2]\n  (hf : superpolynomial_decay l k f) (p : \u03b2[X]) :\n  superpolynomial_decay l k (\u03bb x, f x * (p.eval $ k x)) :=\n(hf.polynomial_mul p).congr (\u03bb _, mul_comm _ _)\n\nend comm_semiring\n\nsection ordered_comm_semiring\n\nvariables [topological_space \u03b2] [ordered_comm_semiring \u03b2] [order_topology \u03b2]\n\n\n\nend ordered_comm_semiring\n\nsection linear_ordered_comm_ring\n\nvariables [topological_space \u03b2] [linear_ordered_comm_ring \u03b2] [order_topology \u03b2]\n\nvariables (l k f)\n\nlemma superpolynomial_decay_iff_abs_tendsto_zero :\n  superpolynomial_decay l k f \u2194 \u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), |(k a) ^ n * f a|) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h z, (tendsto_zero_iff_abs_tendsto_zero _).1 (h z),\n  \u03bb h z, (tendsto_zero_iff_abs_tendsto_zero _).2 (h z)\u27e9\n\nlemma superpolynomial_decay_iff_superpolynomial_decay_abs :\n  superpolynomial_decay l k f \u2194 superpolynomial_decay l (\u03bb a, |k a|) (\u03bb a, |f a|) :=\n(superpolynomial_decay_iff_abs_tendsto_zero l k f).trans\n  (by simp_rw [superpolynomial_decay, abs_mul, abs_pow])\n\nvariables {l k f}\n\nlemma superpolynomial_decay.trans_eventually_abs_le (hf : superpolynomial_decay l k f)\n  (hfg : abs \u2218 g \u2264\u1da0[l] abs \u2218 f) : superpolynomial_decay l k g :=\nbegin\n  rw superpolynomial_decay_iff_abs_tendsto_zero at hf \u22a2,\n  refine \u03bb z, tendsto_of_tendsto_of_tendsto_of_le_of_le' (tendsto_const_nhds) (hf z)\n    (eventually_of_forall $ \u03bb x, abs_nonneg _) (hfg.mono $ \u03bb x hx, _),\n  calc |k x ^ z * g x| = |k x ^ z| * |g x| : abs_mul (k x ^ z) (g x)\n    ... \u2264 |k x ^ z| * |f x| : mul_le_mul le_rfl hx (abs_nonneg _) (abs_nonneg _)\n    ... = |k x ^ z * f x| : (abs_mul (k x ^ z) (f x)).symm,\nend\n\nlemma superpolynomial_decay.trans_abs_le (hf : superpolynomial_decay l k f)\n  (hfg : \u2200 x, |g x| \u2264 |f x|) : superpolynomial_decay l k g :=\nhf.trans_eventually_abs_le (eventually_of_forall hfg)\n\nend linear_ordered_comm_ring\n\nsection field\n\nvariables [topological_space \u03b2] [field \u03b2] (l k f)\n\nlemma superpolynomial_decay_mul_const_iff [has_continuous_mul \u03b2] {c : \u03b2} (hc0 : c \u2260 0) :\n  superpolynomial_decay l k (\u03bb n, f n * c) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.mul_const c\u207b\u00b9).congr (\u03bb x, by simp [mul_assoc, mul_inv_cancel hc0]), \u03bb h, h.mul_const c\u27e9\n\nlemma superpolynomial_decay_const_mul_iff [has_continuous_mul \u03b2] {c : \u03b2} (hc0 : c \u2260 0) :\n  superpolynomial_decay l k (\u03bb n, c * f n) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.const_mul c\u207b\u00b9).congr (\u03bb x, by simp [\u2190 mul_assoc, inv_mul_cancel hc0]), \u03bb h, h.const_mul c\u27e9\n\nvariables {l k f}\n\nend field\n\nsection linear_ordered_field\n\nvariables [topological_space \u03b2] [linear_ordered_field \u03b2] [order_topology \u03b2]\n\nvariable (f)\n\nlemma superpolynomial_decay_iff_abs_is_bounded_under (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2115), is_bounded_under (\u2264) l (\u03bb (a : \u03b1), |(k a) ^ z * f a|) :=\nbegin\n  refine \u27e8\u03bb h z, tendsto.is_bounded_under_le (tendsto.abs (h z)),\n    \u03bb h, (superpolynomial_decay_iff_abs_tendsto_zero l k f).2 (\u03bb z, _)\u27e9,\n  obtain \u27e8m, hm\u27e9 := h (z + 1),\n  have h1 : tendsto (\u03bb (a : \u03b1), (0 : \u03b2)) l (\ud835\udcdd 0) := tendsto_const_nhds,\n  have h2 : tendsto (\u03bb (a : \u03b1), |(k a)\u207b\u00b9| * m) l (\ud835\udcdd 0) := (zero_mul m) \u25b8 tendsto.mul_const m\n    ((tendsto_zero_iff_abs_tendsto_zero _).1 hk.inv_tendsto_at_top),\n  refine tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 h2\n    (eventually_of_forall (\u03bb x, abs_nonneg _)) ((eventually_map.1 hm).mp _),\n  refine ((hk.eventually_ne_at_top 0).mono $ \u03bb x hk0 hx, _),\n  refine eq.trans_le _ (mul_le_mul_of_nonneg_left hx $ abs_nonneg (k x)\u207b\u00b9),\n  rw [\u2190 abs_mul, \u2190 mul_assoc, pow_succ, \u2190 mul_assoc, inv_mul_cancel hk0, one_mul],\nend\n\nlemma superpolynomial_decay_iff_zpow_tendsto_zero (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), tendsto (\u03bb (a : \u03b1), (k a) ^ z * f a) l (\ud835\udcdd 0) :=\nbegin\n  refine \u27e8\u03bb h z, _, \u03bb h n, by simpa only [zpow_coe_nat] using h (n : \u2124)\u27e9,\n  by_cases hz : 0 \u2264 z,\n  { lift z to \u2115 using hz,\n    simpa using h z },\n  { have : tendsto (\u03bb a, (k a) ^ z) l (\ud835\udcdd 0) :=\n      tendsto.comp (tendsto_zpow_at_top_zero (not_le.1 hz)) hk,\n    have h : tendsto f l (\ud835\udcdd 0) := by simpa using h 0,\n    exact (zero_mul (0 : \u03b2)) \u25b8 this.mul h },\nend\n\nvariable {f}\n\nlemma superpolynomial_decay.param_zpow_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) (z : \u2124) : superpolynomial_decay l k (\u03bb a, k a ^ z * f a) :=\nbegin\n  rw superpolynomial_decay_iff_zpow_tendsto_zero _ hk at hf \u22a2,\n  refine \u03bb z', (hf $ z' + z).congr' ((hk.eventually_ne_at_top 0).mono (\u03bb x hx, _)),\n  simp [zpow_add\u2080 hx, mul_assoc, pi.mul_apply],\nend\n\nlemma superpolynomial_decay.mul_param_zpow (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) (z : \u2124) : superpolynomial_decay l k (\u03bb a, f a * k a ^ z) :=\n(hf.param_zpow_mul hk z).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.inv_param_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) : superpolynomial_decay l k (k\u207b\u00b9 * f) :=\nby simpa using (hf.param_zpow_mul hk (-1))\n\nlemma superpolynomial_decay.param_inv_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) : superpolynomial_decay l k (f * k\u207b\u00b9) :=\n(hf.inv_param_mul hk).congr (\u03bb _, mul_comm _ _)\n\nvariable (f)\n\nlemma superpolynomial_decay_param_mul_iff (hk : tendsto k l at_top) :\n  superpolynomial_decay l k (k * f) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.inv_param_mul hk).congr' ((hk.eventually_ne_at_top 0).mono\n  (\u03bb x hx, by simp [\u2190 mul_assoc, inv_mul_cancel hx])), \u03bb h, h.param_mul\u27e9\n\nlemma superpolynomial_decay_mul_param_iff (hk : tendsto k l at_top) :\n  superpolynomial_decay l k (f * k) \u2194 superpolynomial_decay l k f :=\nby simpa [mul_comm k] using superpolynomial_decay_param_mul_iff f hk\n\nlemma superpolynomial_decay_param_pow_mul_iff (hk : tendsto k l at_top) (n : \u2115) :\n  superpolynomial_decay l k (k ^ n * f) \u2194 superpolynomial_decay l k f :=\nbegin\n  induction n with n hn,\n  { simp },\n  { simpa [pow_succ, \u2190 mul_comm k, mul_assoc,\n      superpolynomial_decay_param_mul_iff (k ^ n * f) hk] using hn }\nend\n\nlemma superpolynomial_decay_mul_param_pow_iff (hk : tendsto k l at_top) (n : \u2115) :\n  superpolynomial_decay l k (f * k ^ n) \u2194 superpolynomial_decay l k f :=\nby simpa [mul_comm f] using superpolynomial_decay_param_pow_mul_iff f hk n\n\nvariable {f}\n\nend linear_ordered_field\n\nsection normed_linear_ordered_field\n\nvariable [normed_linear_ordered_field \u03b2]\n\nvariables (l k f)\n\nlemma superpolynomial_decay_iff_norm_tendsto_zero :\n  superpolynomial_decay l k f \u2194 \u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), \u2016(k a) ^ n * f a\u2016) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h z, tendsto_zero_iff_norm_tendsto_zero.1 (h z),\n  \u03bb h z, tendsto_zero_iff_norm_tendsto_zero.2 (h z)\u27e9\n\nlemma superpolynomial_decay_iff_superpolynomial_decay_norm :\n  superpolynomial_decay l k f \u2194 superpolynomial_decay l (\u03bb a, \u2016k a\u2016) (\u03bb a, \u2016f a\u2016) :=\n(superpolynomial_decay_iff_norm_tendsto_zero l k f).trans (by simp [superpolynomial_decay])\n\nvariables {l k}\n\nvariable [order_topology \u03b2]\n\nlemma superpolynomial_decay_iff_is_O (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), f =O[l] (\u03bb (a : \u03b1), (k a) ^ z) :=\nbegin\n  refine (superpolynomial_decay_iff_zpow_tendsto_zero f hk).trans _,\n  have hk0 : \u2200\u1da0 x in l, k x \u2260 0 := hk.eventually_ne_at_top 0,\n  refine \u27e8\u03bb h z, _, \u03bb h z, _\u27e9,\n  { refine is_O_of_div_tendsto_nhds (hk0.mono (\u03bb x hx hxz, absurd (zpow_eq_zero hxz) hx)) 0 _,\n    have : (\u03bb (a : \u03b1), k a ^ z)\u207b\u00b9 = (\u03bb (a : \u03b1), k a ^ (- z)) := funext (\u03bb x, by simp),\n    rw [div_eq_mul_inv, mul_comm f, this],\n    exact h (-z) },\n  { suffices : (\u03bb (a : \u03b1), k a ^ z * f a) =O[l] (\u03bb (a : \u03b1), (k a)\u207b\u00b9),\n      from is_O.trans_tendsto this hk.inv_tendsto_at_top,\n    refine ((is_O_refl (\u03bb a, (k a) ^ z) l).mul (h (- (z + 1)))).trans\n      (is_O.of_bound 1 $ hk0.mono (\u03bb a ha0, _)),\n    simp only [one_mul, neg_add z 1, zpow_add\u2080 ha0, \u2190 mul_assoc, zpow_neg,\n      mul_inv_cancel (zpow_ne_zero z ha0), zpow_one] }\nend\n\nlemma superpolynomial_decay_iff_is_o (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), f =o[l] (\u03bb (a : \u03b1), (k a) ^ z) :=\nbegin\n  refine \u27e8\u03bb h z, _, \u03bb h, (superpolynomial_decay_iff_is_O f hk).2 (\u03bb z, (h z).is_O)\u27e9,\n  have hk0 : \u2200\u1da0 x in l, k x \u2260 0 := hk.eventually_ne_at_top 0,\n  have : (\u03bb (x : \u03b1), (1 : \u03b2)) =o[l] k := is_o_of_tendsto'\n    (hk0.mono (\u03bb x hkx hkx', absurd hkx' hkx)) (by simpa using hk.inv_tendsto_at_top),\n  have : f =o[l] (\u03bb (x : \u03b1), k x * k x ^ (z - 1)),\n    by simpa using this.mul_is_O (((superpolynomial_decay_iff_is_O f hk).1 h) $ z - 1),\n  refine this.trans_is_O (is_O.of_bound 1 (hk0.mono $ \u03bb x hkx, le_of_eq _)),\n  rw [one_mul, zpow_sub_one\u2080 hkx, mul_comm (k x), mul_assoc, inv_mul_cancel hkx, mul_one],\nend\n\nend normed_linear_ordered_field\n\nend asymptotics\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/asymptotics/superpolynomial_decay.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.737393926993745}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.group.to_additive\nimport Mathlib.tactic.basic\nimport Mathlib.PostPort\n\nuniverses u l \n\nnamespace Mathlib\n\n/-!\n# Typeclasses for (semi)groups and monoid\n\nIn this file we define typeclasses for algebraic structures with one binary operation.\nThe classes are named `(add_)?(comm_)?(semigroup|monoid|group)`, where `add_` means that\nthe class uses additive notation and `comm_` means that the class assumes that the binary\noperation is commutative.\n\nThe file does not contain any lemmas except for\n\n* axioms of typeclasses restated in the root namespace;\n* lemmas required for instances.\n\nFor basic lemmas about these classes see `algebra.group.basic`.\n-/\n\n/- Additive \"sister\" structures.\n   Example, add_semigroup mirrors semigroup.\n   These structures exist just to help automation.\n   In an alternative design, we could have the binary operation as an\n   extra argument for semigroup, monoid, group, etc. However, the lemmas\n   would be hard to index since they would not contain any constant.\n   For example, mul_assoc would be\n\n   lemma mul_assoc {\u03b1 : Type u} {op : \u03b1 \u2192 \u03b1 \u2192 \u03b1} [semigroup \u03b1 op] :\n                   \u2200 a b c : \u03b1, op (op a b) c = op a (op b c) :=\n    semigroup.mul_assoc\n\n   The simplifier cannot effectively use this lemma since the pattern for\n   the left-hand-side would be\n\n        ?op (?op ?a ?b) ?c\n\n   Remark: we use a tactic for transporting theorems from the multiplicative fragment\n   to the additive one.\n-/\n\n/-- `left_mul g` denotes left multiplication by `g` -/\ndef left_add {G : Type u} [Add G] : G \u2192 G \u2192 G := fun (g x : G) => g + x\n\n/-- `right_mul g` denotes right multiplication by `g` -/\ndef right_mul {G : Type u} [Mul G] : G \u2192 G \u2192 G := fun (g x : G) => x * g\n\n/-- A semigroup is a type with an associative `(*)`. -/\nclass semigroup (G : Type u) extends Mul G where\n  mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c)\n\n/-- An additive semigroup is a type with an associative `(+)`. -/\nclass add_semigroup (G : Type u) extends Add G where\n  add_assoc : \u2200 (a b c : G), a + b + c = a + (b + c)\n\ntheorem mul_assoc {G : Type u} [semigroup G] (a : G) (b : G) (c : G) : a * b * c = a * (b * c) :=\n  semigroup.mul_assoc\n\nprotected instance add_semigroup.to_is_associative {G : Type u} [add_semigroup G] :\n    is_associative G Add.add :=\n  is_associative.mk add_assoc\n\n/-- A commutative semigroup is a type with an associative commutative `(*)`. -/\nclass comm_semigroup (G : Type u) extends semigroup G where\n  mul_comm : \u2200 (a b : G), a * b = b * a\n\n/-- A commutative additive semigroup is a type with an associative commutative `(+)`. -/\nclass add_comm_semigroup (G : Type u) extends add_semigroup G where\n  add_comm : \u2200 (a b : G), a + b = b + a\n\ntheorem mul_comm {G : Type u} [comm_semigroup G] (a : G) (b : G) : a * b = b * a :=\n  comm_semigroup.mul_comm\n\nprotected instance comm_semigroup.to_is_commutative {G : Type u} [comm_semigroup G] :\n    is_commutative G Mul.mul :=\n  is_commutative.mk mul_comm\n\n/-- A `left_cancel_semigroup` is a semigroup such that `a * b = a * c` implies `b = c`. -/\nclass left_cancel_semigroup (G : Type u) extends semigroup G where\n  mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c\n\n/-- An `add_left_cancel_semigroup` is an additive semigroup such that\n`a + b = a + c` implies `b = c`. -/\nclass add_left_cancel_semigroup (G : Type u) extends add_semigroup G where\n  add_left_cancel : \u2200 (a b c : G), a + b = a + c \u2192 b = c\n\ntheorem mul_left_cancel {G : Type u} [left_cancel_semigroup G] {a : G} {b : G} {c : G} :\n    a * b = a * c \u2192 b = c :=\n  left_cancel_semigroup.mul_left_cancel a b c\n\ntheorem mul_left_cancel_iff {G : Type u} [left_cancel_semigroup G] {a : G} {b : G} {c : G} :\n    a * b = a * c \u2194 b = c :=\n  { mp := mul_left_cancel, mpr := congr_arg fun {b : G} => a * b }\n\ntheorem mul_right_injective {G : Type u} [left_cancel_semigroup G] (a : G) :\n    function.injective (Mul.mul a) :=\n  fun (b c : G) => mul_left_cancel\n\n@[simp] theorem add_right_inj {G : Type u} [add_left_cancel_semigroup G] (a : G) {b : G} {c : G} :\n    a + b = a + c \u2194 b = c :=\n  function.injective.eq_iff (add_right_injective a)\n\n/-- A `right_cancel_semigroup` is a semigroup such that `a * b = c * b` implies `a = c`. -/\nclass right_cancel_semigroup (G : Type u) extends semigroup G where\n  mul_right_cancel : \u2200 (a b c : G), a * b = c * b \u2192 a = c\n\n/-- An `add_right_cancel_semigroup` is an additive semigroup such that\n`a + b = c + b` implies `a = c`. -/\nclass add_right_cancel_semigroup (G : Type u) extends add_semigroup G where\n  add_right_cancel : \u2200 (a b c : G), a + b = c + b \u2192 a = c\n\ntheorem mul_right_cancel {G : Type u} [right_cancel_semigroup G] {a : G} {b : G} {c : G} :\n    a * b = c * b \u2192 a = c :=\n  right_cancel_semigroup.mul_right_cancel a b c\n\ntheorem add_right_cancel_iff {G : Type u} [add_right_cancel_semigroup G] {a : G} {b : G} {c : G} :\n    b + a = c + a \u2194 b = c :=\n  { mp := add_right_cancel, mpr := congr_arg fun {b : G} => b + a }\n\ntheorem add_left_injective {G : Type u} [add_right_cancel_semigroup G] (a : G) :\n    function.injective fun (x : G) => x + a :=\n  fun (b c : G) => add_right_cancel\n\n@[simp] theorem add_left_inj {G : Type u} [add_right_cancel_semigroup G] (a : G) {b : G} {c : G} :\n    b + a = c + a \u2194 b = c :=\n  function.injective.eq_iff (add_left_injective a)\n\n/-- A `monoid` is a `semigroup` with an element `1` such that `1 * a = a * 1 = a`. -/\nclass monoid (M : Type u) extends semigroup M, HasOne M where\n  one_mul : \u2200 (a : M), 1 * a = a\n  mul_one : \u2200 (a : M), a * 1 = a\n\n/-- An `add_monoid` is an `add_semigroup` with an element `0` such that `0 + a = a + 0 = a`. -/\nclass add_monoid (M : Type u) extends HasZero M, add_semigroup M where\n  zero_add : \u2200 (a : M), 0 + a = a\n  add_zero : \u2200 (a : M), a + 0 = a\n\n@[simp] theorem one_mul {M : Type u} [monoid M] (a : M) : 1 * a = a := monoid.one_mul\n\n@[simp] theorem add_zero {M : Type u} [add_monoid M] (a : M) : a + 0 = a := add_monoid.add_zero\n\nprotected instance monoid_to_is_left_id {M : Type u} [monoid M] : is_left_id M Mul.mul 1 :=\n  is_left_id.mk monoid.one_mul\n\nprotected instance add_monoid_to_is_right_id {M : Type u} [add_monoid M] :\n    is_right_id M Add.add 0 :=\n  is_right_id.mk add_monoid.add_zero\n\ntheorem left_neg_eq_right_neg {M : Type u} [add_monoid M] {a : M} {b : M} {c : M} (hba : b + a = 0)\n    (hac : a + c = 0) : b = c :=\n  sorry\n\n/-- A commutative monoid is a monoid with commutative `(*)`. -/\nclass comm_monoid (M : Type u) extends comm_semigroup M, monoid M where\n\n/-- An additive commutative monoid is an additive monoid with commutative `(+)`. -/\nclass add_comm_monoid (M : Type u) extends add_comm_semigroup M, add_monoid M where\n\n/-- An additive monoid in which addition is left-cancellative.\nMain examples are `\u2115` and groups. This is the right typeclass for many sum lemmas, as having a zero\nis useful to define the sum over the empty set, so `add_left_cancel_semigroup` is not enough. -/\n-- TODO: I found 1 (one) lemma assuming `[add_left_cancel_monoid]`.\n\nclass add_left_cancel_monoid (M : Type u) extends add_left_cancel_semigroup M, add_monoid M where\n\n-- Should we port more lemmas to this typeclass?\n\n/-- A monoid in which multiplication is left-cancellative. -/\nclass left_cancel_monoid (M : Type u) extends left_cancel_semigroup M, monoid M where\n\n/-- Commutative version of add_left_cancel_monoid. -/\nclass add_left_cancel_comm_monoid (M : Type u) extends add_left_cancel_monoid M, add_comm_monoid M\n    where\n\n/-- Commutative version of left_cancel_monoid. -/\nclass left_cancel_comm_monoid (M : Type u) extends left_cancel_monoid M, comm_monoid M where\n\n/-- An additive monoid in which addition is right-cancellative.\nMain examples are `\u2115` and groups. This is the right typeclass for many sum lemmas, as having a zero\nis useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/\nclass add_right_cancel_monoid (M : Type u) extends add_monoid M, add_right_cancel_semigroup M where\n\n/-- A monoid in which multiplication is right-cancellative. -/\nclass right_cancel_monoid (M : Type u) extends right_cancel_semigroup M, monoid M where\n\n/-- Commutative version of add_right_cancel_monoid. -/\nclass add_right_cancel_comm_monoid (M : Type u) extends add_right_cancel_monoid M, add_comm_monoid M\n    where\n\n/-- Commutative version of right_cancel_monoid. -/\nclass right_cancel_comm_monoid (M : Type u) extends right_cancel_monoid M, comm_monoid M where\n\n/-- An additive monoid in which addition is cancellative on both sides.\nMain examples are `\u2115` and groups. This is the right typeclass for many sum lemmas, as having a zero\nis useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/\nclass add_cancel_monoid (M : Type u) extends add_left_cancel_monoid M, add_right_cancel_monoid M\n    where\n\n/-- A monoid in which multiplication is cancellative. -/\nclass cancel_monoid (M : Type u) extends left_cancel_monoid M, right_cancel_monoid M where\n\n/-- Commutative version of add_cancel_monoid. -/\nclass add_cancel_comm_monoid (M : Type u)\n    extends add_left_cancel_comm_monoid M, add_right_cancel_comm_monoid M where\n\n/-- Commutative version of cancel_monoid. -/\nclass cancel_comm_monoid (M : Type u) extends right_cancel_comm_monoid M, left_cancel_comm_monoid M\n    where\n\n/-- `try_refl_tac` solves goals of the form `\u2200 a b, f a b = g a b`,\nif they hold by definition. -/\n/-- A `div_inv_monoid` is a `monoid` with operations `/` and `\u207b\u00b9` satisfying\n`div_eq_mul_inv : \u2200 a b, a / b = a * b\u207b\u00b9`.\n\nThis is the immediate common ancestor of `group` and `group_with_zero`,\nin order to deduplicate the name `div_eq_mul_inv`.\nThe default for `div` is such that `a / b = a * b\u207b\u00b9` holds by definition.\n\nAdding `div` as a field rather than defining `a / b := a * b\u207b\u00b9` allows us to\navoid certain classes of unification failures, for example:\nLet `foo X` be a type with a `\u2200 X, has_div (foo X)` instance but no\n`\u2200 X, has_inv (foo X)`, e.g. when `foo X` is a `euclidean_domain`. Suppose we\nalso have an instance `\u2200 X [cromulent X], group_with_zero (foo X)`. Then the\n`(/)` coming from `group_with_zero_has_div` cannot be definitionally equal to\nthe `(/)` coming from `foo.has_div`.\n-/\nclass div_inv_monoid (G : Type u) extends Div G, monoid G, has_inv G where\n  div_eq_mul_inv :\n    autoParam (\u2200 (a b : G), a / b = a * (b\u207b\u00b9))\n      (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring \"Mathlib.try_refl_tac\")\n        (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous \"Mathlib\") \"try_refl_tac\") [])\n\n/-- A `sub_neg_monoid` is an `add_monoid` with unary `-` and binary `-` operations\nsatisfying `sub_eq_add_neg : \u2200 a b, a - b = a + -b`.\n\nThe default for `sub` is such that `a - b = a + -b` holds by definition.\n\nAdding `sub` as a field rather than defining `a - b := a + -b` allows us to\navoid certain classes of unification failures, for example:\nLet `foo X` be a type with a `\u2200 X, has_sub (foo X)` instance but no\n`\u2200 X, has_neg (foo X)`. Suppose we also have an instance\n`\u2200 X [cromulent X], add_group (foo X)`. Then the `(-)` coming from\n`add_group.has_sub` cannot be definitionally equal to the `(-)` coming from\n`foo.has_sub`.\n-/\nclass sub_neg_monoid (G : Type u) extends Sub G, Neg G, add_monoid G where\n  sub_eq_add_neg :\n    autoParam (\u2200 (a b : G), a - b = a + -b)\n      (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring \"Mathlib.try_refl_tac\")\n        (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous \"Mathlib\") \"try_refl_tac\") [])\n\ntheorem sub_eq_add_neg {G : Type u} [sub_neg_monoid G] (a : G) (b : G) : a - b = a + -b :=\n  sub_neg_monoid.sub_eq_add_neg\n\n/-- A `group` is a `monoid` with an operation `\u207b\u00b9` satisfying `a\u207b\u00b9 * a = 1`.\n\nThere is also a division operation `/` such that `a / b = a * b\u207b\u00b9`,\nwith a default so that `a / b = a * b\u207b\u00b9` holds by definition.\n-/\nclass group (G : Type u) extends div_inv_monoid G where\n  mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1\n\n/-- An `add_group` is an `add_monoid` with a unary `-` satisfying `-a + a = 0`.\n\nThere is also a binary operation `-` such that `a - b = a + -b`,\nwith a default so that `a - b = a + -b` holds by definition.\n-/\nclass add_group (A : Type u) extends sub_neg_monoid A where\n  add_left_neg : \u2200 (a : A), -a + a = 0\n\n/-- Abbreviation for `@div_inv_monoid.to_monoid _ (@group.to_div_inv_monoid _ _)`.\n\nUseful because it corresponds to the fact that `Grp` is a subcategory of `Mon`.\nNot an instance since it duplicates `@div_inv_monoid.to_monoid _ (@group.to_div_inv_monoid _ _)`.\n-/\ndef group.to_monoid (G : Type u) [group G] : monoid G := div_inv_monoid.to_monoid G\n\n@[simp] theorem mul_left_inv {G : Type u} [group G] (a : G) : a\u207b\u00b9 * a = 1 := group.mul_left_inv\n\ntheorem inv_mul_self {G : Type u} [group G] (a : G) : a\u207b\u00b9 * a = 1 := mul_left_inv a\n\n@[simp] theorem neg_add_cancel_left {G : Type u} [add_group G] (a : G) (b : G) : -a + (a + b) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-a + (a + b) = b)) (Eq.symm (add_assoc (-a) a b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a + a + b = b)) (add_left_neg a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 + b = b)) (zero_add b))) (Eq.refl b)))\n\n@[simp] theorem inv_eq_of_mul_eq_one {G : Type u} [group G] {a : G} {b : G} (h : a * b = 1) :\n    a\u207b\u00b9 = b :=\n  left_inv_eq_right_inv (inv_mul_self a) h\n\n@[simp] theorem inv_inv {G : Type u} [group G] (a : G) : a\u207b\u00b9\u207b\u00b9 = a :=\n  inv_eq_of_mul_eq_one (mul_left_inv a)\n\n@[simp] theorem add_right_neg {G : Type u} [add_group G] (a : G) : a + -a = 0 :=\n  (fun (this : --a + -a = 0) => eq.mp (Eq._oldrec (Eq.refl ( --a + -a = 0)) (neg_neg a)) this)\n    (add_left_neg (-a))\n\ntheorem add_neg_self {G : Type u} [add_group G] (a : G) : a + -a = 0 := add_right_neg a\n\n@[simp] theorem mul_inv_cancel_right {G : Type u} [group G] (a : G) (b : G) : a * b * (b\u207b\u00b9) = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b * (b\u207b\u00b9) = a)) (mul_assoc a b (b\u207b\u00b9))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (b * (b\u207b\u00b9)) = a)) (mul_right_inv b)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a * 1 = a)) (mul_one a))) (Eq.refl a)))\n\nprotected instance add_group.to_cancel_add_monoid {G : Type u} [add_group G] :\n    add_cancel_monoid G :=\n  add_cancel_monoid.mk add_group.add add_group.add_assoc sorry add_group.zero add_group.zero_add\n    add_group.add_zero sorry\n\n/-- A commutative group is a group with commutative `(*)`. -/\n/-- An additive commutative group is an additive group with commutative `(+)`. -/\nclass comm_group (G : Type u) extends group G, comm_monoid G where\n\nclass add_comm_group (G : Type u) extends add_group G, add_comm_monoid G where\n\nprotected instance comm_group.to_cancel_comm_monoid {G : Type u} [comm_group G] :\n    cancel_comm_monoid G :=\n  cancel_comm_monoid.mk comm_group.mul comm_group.mul_assoc sorry comm_group.one comm_group.one_mul\n    comm_group.mul_one comm_group.mul_comm sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/group/defs_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.737393923906329}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n\n! This file was ported from Lean 3 source module combinatorics.configuration\n! leanprover-community/mathlib commit d2d8742b0c21426362a9dacebc6005db895ca963\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.BigOperators.Order\nimport Mathbin.Combinatorics.Hall.Basic\nimport Mathbin.Data.Fintype.BigOperators\nimport Mathbin.SetTheory.Cardinal.Finite\n\n/-!\n# Configurations of Points and lines\nThis file introduces abstract configurations of points and lines, and proves some basic properties.\n\n## Main definitions\n* `configuration.nondegenerate`: Excludes certain degenerate configurations,\n  and imposes uniqueness of intersection points.\n* `configuration.has_points`: A nondegenerate configuration in which\n  every pair of lines has an intersection point.\n* `configuration.has_lines`:  A nondegenerate configuration in which\n  every pair of points has a line through them.\n* `configuration.line_count`: The number of lines through a given point.\n* `configuration.point_count`: The number of lines through a given line.\n\n## Main statements\n* `configuration.has_lines.card_le`: `has_lines` implies `|P| \u2264 |L|`.\n* `configuration.has_points.card_le`: `has_points` implies `|L| \u2264 |P|`.\n* `configuration.has_lines.has_points`: `has_lines` and `|P| = |L|` implies `has_points`.\n* `configuration.has_points.has_lines`: `has_points` and `|P| = |L|` implies `has_lines`.\nTogether, these four statements say that any two of the following properties imply the third:\n(a) `has_lines`, (b) `has_points`, (c) `|P| = |L|`.\n\n-/\n\n\nopen BigOperators\n\nnamespace Configuration\n\nvariable (P L : Type _) [Membership P L]\n\n/-- A type synonym. -/\ndef Dual :=\n  P\n#align configuration.dual Configuration.Dual\n\ninstance [this : Inhabited P] : Inhabited (Dual P) :=\n  this\n\ninstance [Finite P] : Finite (Dual P) :=\n  \u2039Finite P\u203a\n\ninstance [this : Fintype P] : Fintype (Dual P) :=\n  this\n\ninstance : Membership (Dual L) (Dual P) :=\n  \u27e8Function.swap (Membership.Mem : P \u2192 L \u2192 Prop)\u27e9\n\n/-- A configuration is nondegenerate if:\n  1) there does not exist a line that passes through all of the points,\n  2) there does not exist a point that is on all of the lines,\n  3) there is at most one line through any two points,\n  4) any two lines have at most one intersection point.\n  Conditions 3 and 4 are equivalent. -/\nclass Nondegenerate : Prop where\n  exists_point : \u2200 l : L, \u2203 p, p \u2209 l\n  exists_line : \u2200 p, \u2203 l : L, p \u2209 l\n  eq_or_eq : \u2200 {p\u2081 p\u2082 : P} {l\u2081 l\u2082 : L}, p\u2081 \u2208 l\u2081 \u2192 p\u2082 \u2208 l\u2081 \u2192 p\u2081 \u2208 l\u2082 \u2192 p\u2082 \u2208 l\u2082 \u2192 p\u2081 = p\u2082 \u2228 l\u2081 = l\u2082\n#align configuration.nondegenerate Configuration.Nondegenerate\n\n/-- A nondegenerate configuration in which every pair of lines has an intersection point. -/\nclass HasPoints extends Nondegenerate P L where\n  mkPoint : \u2200 {l\u2081 l\u2082 : L} (h : l\u2081 \u2260 l\u2082), P\n  mkPoint_ax : \u2200 {l\u2081 l\u2082 : L} (h : l\u2081 \u2260 l\u2082), mk_point h \u2208 l\u2081 \u2227 mk_point h \u2208 l\u2082\n#align configuration.has_points Configuration.HasPoints\n\n/-- A nondegenerate configuration in which every pair of points has a line through them. -/\nclass HasLines extends Nondegenerate P L where\n  mkLine : \u2200 {p\u2081 p\u2082 : P} (h : p\u2081 \u2260 p\u2082), L\n  mkLine_ax : \u2200 {p\u2081 p\u2082 : P} (h : p\u2081 \u2260 p\u2082), p\u2081 \u2208 mk_line h \u2227 p\u2082 \u2208 mk_line h\n#align configuration.has_lines Configuration.HasLines\n\nopen Nondegenerate\n\nopen HasPoints (mkPoint mkPoint_ax)\n\nopen HasLines (mkLine mkLine_ax)\n\ninstance [Nondegenerate P L] : Nondegenerate (Dual L) (Dual P)\n    where\n  exists_point := @exists_line P L _ _\n  exists_line := @exists_point P L _ _\n  eq_or_eq l\u2081 l\u2082 p\u2081 p\u2082 h\u2081 h\u2082 h\u2083 h\u2084 := (@eq_or_eq P L _ _ p\u2081 p\u2082 l\u2081 l\u2082 h\u2081 h\u2083 h\u2082 h\u2084).symm\n\ninstance [HasPoints P L] : HasLines (Dual L) (Dual P) :=\n  { Dual.nondegenerate _ _ with\n    mkLine := @mkPoint P L _ _\n    mkLine_ax := fun _ _ => mkPoint_ax }\n\ninstance [HasLines P L] : HasPoints (Dual L) (Dual P) :=\n  { Dual.nondegenerate _ _ with\n    mkPoint := @mkLine P L _ _\n    mkPoint_ax := fun _ _ => mkLine_ax }\n\ntheorem HasPoints.existsUnique_point [HasPoints P L] (l\u2081 l\u2082 : L) (hl : l\u2081 \u2260 l\u2082) :\n    \u2203! p, p \u2208 l\u2081 \u2227 p \u2208 l\u2082 :=\n  \u27e8mkPoint hl, mkPoint_ax hl, fun p hp =>\n    (eq_or_eq hp.1 (mkPoint_ax hl).1 hp.2 (mkPoint_ax hl).2).resolve_right hl\u27e9\n#align configuration.has_points.exists_unique_point Configuration.HasPoints.existsUnique_point\n\ntheorem HasLines.existsUnique_line [HasLines P L] (p\u2081 p\u2082 : P) (hp : p\u2081 \u2260 p\u2082) :\n    \u2203! l : L, p\u2081 \u2208 l \u2227 p\u2082 \u2208 l :=\n  HasPoints.existsUnique_point (Dual L) (Dual P) p\u2081 p\u2082 hp\n#align configuration.has_lines.exists_unique_line Configuration.HasLines.existsUnique_line\n\nvariable {P L}\n\n/-- If a nondegenerate configuration has at least as many points as lines, then there exists\n  an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/\ntheorem Nondegenerate.exists_injective_of_card_le [Nondegenerate P L] [Fintype P] [Fintype L]\n    (h : Fintype.card L \u2264 Fintype.card P) : \u2203 f : L \u2192 P, Function.Injective f \u2227 \u2200 l, f l \u2209 l := by\n  classical\n    let t : L \u2192 Finset P := fun l => Set.toFinset { p | p \u2209 l }\n    suffices \u2200 s : Finset L, s.card \u2264 (s.bunion\u1d62 t).card\n      by\n      -- Hall's marriage theorem\n      obtain \u27e8f, hf1, hf2\u27e9 := (Finset.all_card_le_bunion\u1d62_card_iff_exists_injective t).mp this\n      exact \u27e8f, hf1, fun l => set.mem_to_finset.mp (hf2 l)\u27e9\n    intro s\n    by_cases hs\u2080 : s.card = 0\n    -- If `s = \u2205`, then `s.card = 0 \u2264 (s.bUnion t).card`\n    \u00b7 simp_rw [hs\u2080, zero_le]\n    by_cases hs\u2081 : s.card = 1\n    -- If `s = {l}`, then pick a point `p \u2209 l`\n    \u00b7 obtain \u27e8l, rfl\u27e9 := finset.card_eq_one.mp hs\u2081\n      obtain \u27e8p, hl\u27e9 := exists_point l\n      rw [Finset.card_singleton, Finset.singleton_bunion\u1d62, Nat.one_le_iff_ne_zero]\n      exact Finset.card_ne_zero_of_mem (set.mem_to_finset.mpr hl)\n    suffices s.bUnion t\u1d9c.card \u2264 s\u1d9c.card\n      by\n      -- Rephrase in terms of complements (uses `h`)\n      rw [Finset.card_compl, Finset.card_compl, tsub_le_iff_left] at this\n      replace := h.trans this\n      rwa [\u2190 add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left (le_add_left s.card_le_univ),\n        add_le_add_iff_right] at this\n    have hs\u2082 : s.bUnion t\u1d9c.card \u2264 1 :=\n      by\n      -- At most one line through two points of `s`\n      refine' finset.card_le_one_iff.mpr fun p\u2081 p\u2082 hp\u2081 hp\u2082 => _\n      simp_rw [Finset.mem_compl, Finset.mem_bunion\u1d62, exists_prop, not_exists, not_and,\n        Set.mem_toFinset, Set.mem_setOf_eq, Classical.not_not] at hp\u2081 hp\u2082\n      obtain \u27e8l\u2081, l\u2082, hl\u2081, hl\u2082, hl\u2083\u27e9 :=\n        finset.one_lt_card_iff.mp (nat.one_lt_iff_ne_zero_and_ne_one.mpr \u27e8hs\u2080, hs\u2081\u27e9)\n      exact (eq_or_eq (hp\u2081 l\u2081 hl\u2081) (hp\u2082 l\u2081 hl\u2081) (hp\u2081 l\u2082 hl\u2082) (hp\u2082 l\u2082 hl\u2082)).resolve_right hl\u2083\n    by_cases hs\u2083 : s\u1d9c.card = 0\n    \u00b7 rw [hs\u2083, le_zero_iff]\n      rw [Finset.card_compl, tsub_eq_zero_iff_le, LE.le.le_iff_eq (Finset.card_le_univ _), eq_comm,\n        Finset.card_eq_iff_eq_univ] at hs\u2083\u22a2\n      rw [hs\u2083]\n      rw [Finset.eq_univ_iff_forall] at hs\u2083\u22a2\n      exact fun p =>\n        Exists.elim (exists_line p)-- If `s = univ`, then show `s.bUnion t = univ`\n        fun l hl => finset.mem_bUnion.mpr \u27e8l, Finset.mem_univ l, set.mem_to_finset.mpr hl\u27e9\n    \u00b7 exact hs\u2082.trans (nat.one_le_iff_ne_zero.mpr hs\u2083)\n#align configuration.nondegenerate.exists_injective_of_card_le Configuration.Nondegenerate.exists_injective_of_card_le\n\n-- If `s < univ`, then consequence of `hs\u2082`\nvariable {P} (L)\n\n/-- Number of points on a given line. -/\nnoncomputable def lineCount (p : P) : \u2115 :=\n  Nat.card { l : L // p \u2208 l }\n#align configuration.line_count Configuration.lineCount\n\nvariable (P) {L}\n\n/-- Number of lines through a given point. -/\nnoncomputable def pointCount (l : L) : \u2115 :=\n  Nat.card { p : P // p \u2208 l }\n#align configuration.point_count Configuration.pointCount\n\nvariable (P L)\n\ntheorem sum_lineCount_eq_sum_pointCount [Fintype P] [Fintype L] :\n    (\u2211 p : P, lineCount L p) = \u2211 l : L, pointCount P l := by\n  classical\n    simp only [line_count, point_count, Nat.card_eq_fintype_card, \u2190 Fintype.card_sigma]\n    apply Fintype.card_congr\n    calc\n      (\u03a3p, { l : L // p \u2208 l }) \u2243 { x : P \u00d7 L // x.1 \u2208 x.2 } :=\n        (Equiv.subtypeProdEquivSigmaSubtype (\u00b7 \u2208 \u00b7)).symm\n      _ \u2243 { x : L \u00d7 P // x.2 \u2208 x.1 } := ((Equiv.prodComm P L).subtypeEquiv fun x => Iff.rfl)\n      _ \u2243 \u03a3l, { p // p \u2208 l } := Equiv.subtypeProdEquivSigmaSubtype fun (l : L) (p : P) => p \u2208 l\n      \n#align configuration.sum_line_count_eq_sum_point_count Configuration.sum_lineCount_eq_sum_pointCount\n\nvariable {P L}\n\ntheorem HasLines.pointCount_le_lineCount [HasLines P L] {p : P} {l : L} (h : p \u2209 l)\n    [Finite { l : L // p \u2208 l }] : pointCount P l \u2264 lineCount L p :=\n  by\n  by_cases hf : Infinite { p : P // p \u2208 l }\n  \u00b7 exact (le_of_eq Nat.card_eq_zero_of_infinite).trans (zero_le (line_count L p))\n  haveI := fintypeOfNotInfinite hf\n  cases nonempty_fintype { l : L // p \u2208 l }\n  rw [line_count, point_count, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card]\n  have : \u2200 p' : { p // p \u2208 l }, p \u2260 p' := fun p' hp' => h ((congr_arg (\u00b7 \u2208 l) hp').mpr p'.2)\n  exact\n    Fintype.card_le_of_injective (fun p' => \u27e8mk_line (this p'), (mk_line_ax (this p')).1\u27e9)\n      fun p\u2081 p\u2082 hp =>\n      Subtype.ext\n        ((eq_or_eq p\u2081.2 p\u2082.2 (mk_line_ax (this p\u2081)).2\n              ((congr_arg _ (subtype.ext_iff.mp hp)).mpr (mk_line_ax (this p\u2082)).2)).resolve_right\n          fun h' => (congr_arg _ h').mp h (mk_line_ax (this p\u2081)).1)\n#align configuration.has_lines.point_count_le_line_count Configuration.HasLines.pointCount_le_lineCount\n\ntheorem HasPoints.lineCount_le_pointCount [HasPoints P L] {p : P} {l : L} (h : p \u2209 l)\n    [hf : Finite { p : P // p \u2208 l }] : lineCount L p \u2264 pointCount P l :=\n  @HasLines.pointCount_le_lineCount (Dual L) (Dual P) _ _ l p h hf\n#align configuration.has_points.line_count_le_point_count Configuration.HasPoints.lineCount_le_pointCount\n\nvariable (P L)\n\n/-- If a nondegenerate configuration has a unique line through any two points, then `|P| \u2264 |L|`. -/\ntheorem HasLines.card_le [HasLines P L] [Fintype P] [Fintype L] : Fintype.card P \u2264 Fintype.card L :=\n  by\n  classical\n    by_contra hc\u2082\n    obtain \u27e8f, hf\u2081, hf\u2082\u27e9 := nondegenerate.exists_injective_of_card_le (le_of_not_le hc\u2082)\n    have :=\n      calc\n        (\u2211 p, line_count L p) = \u2211 l, point_count P l := sum_line_count_eq_sum_point_count P L\n        _ \u2264 \u2211 l, line_count L (f l) :=\n          (Finset.sum_le_sum fun l hl => has_lines.point_count_le_line_count (hf\u2082 l))\n        _ = \u2211 p in finset.univ.image f, line_count L p :=\n          (Finset.sum_bij (fun l hl => f l) (fun l hl => Finset.mem_image_of_mem f hl)\n            (fun l hl => rfl) (fun l\u2081 l\u2082 hl\u2081 hl\u2082 hl\u2083 => hf\u2081 hl\u2083) fun p => by\n            simp_rw [Finset.mem_image, eq_comm, imp_self])\n        _ < \u2211 p, line_count L p := _\n        \n    \u00b7 exact lt_irrefl _ this\n    \u00b7 obtain \u27e8p, hp\u27e9 := not_forall.mp (mt (Fintype.card_le_of_surjective f) hc\u2082)\n      refine'\n        Finset.sum_lt_sum_of_subset (finset.univ.image f).subset_univ (Finset.mem_univ p) _ _\n          fun p hp\u2081 hp\u2082 => zero_le (line_count L p)\n      \u00b7 simpa only [Finset.mem_image, exists_prop, Finset.mem_univ, true_and_iff]\n      \u00b7 rw [line_count, Nat.card_eq_fintype_card, Fintype.card_pos_iff]\n        obtain \u27e8l, hl\u27e9 := @exists_line P L _ _ p\n        exact\n          let this := not_exists.mp hp l\n          \u27e8\u27e8mk_line this, (mk_line_ax this).2\u27e9\u27e9\n#align configuration.has_lines.card_le Configuration.HasLines.card_le\n\n/-- If a nondegenerate configuration has a unique point on any two lines, then `|L| \u2264 |P|`. -/\ntheorem HasPoints.card_le [HasPoints P L] [Fintype P] [Fintype L] :\n    Fintype.card L \u2264 Fintype.card P :=\n  @HasLines.card_le (Dual L) (Dual P) _ _ _ _\n#align configuration.has_points.card_le Configuration.HasPoints.card_le\n\nvariable {P L}\n\ntheorem HasLines.exists_bijective_of_card_eq [HasLines P L] [Fintype P] [Fintype L]\n    (h : Fintype.card P = Fintype.card L) :\n    \u2203 f : L \u2192 P, Function.Bijective f \u2227 \u2200 l, pointCount P l = lineCount L (f l) := by\n  classical\n    obtain \u27e8f, hf1, hf2\u27e9 := nondegenerate.exists_injective_of_card_le (ge_of_eq h)\n    have hf3 := (Fintype.bijective_iff_injective_and_card f).mpr \u27e8hf1, h.symm\u27e9\n    refine'\n      \u27e8f, hf3, fun l =>\n        (Finset.sum_eq_sum_iff_of_le fun l hl => has_lines.point_count_le_line_count (hf2 l)).mp\n          ((sum_line_count_eq_sum_point_count P L).symm.trans\n            (Finset.sum_bij (fun l hl => f l) (fun l hl => Finset.mem_univ (f l))\n                (fun l hl => refl (line_count L (f l))) (fun l\u2081 l\u2082 hl\u2081 hl\u2082 hl => hf1 hl) fun p hp =>\n                _).symm)\n          l (Finset.mem_univ l)\u27e9\n    obtain \u27e8l, rfl\u27e9 := hf3.2 p\n    exact \u27e8l, Finset.mem_univ l, rfl\u27e9\n#align configuration.has_lines.exists_bijective_of_card_eq Configuration.HasLines.exists_bijective_of_card_eq\n\ntheorem HasLines.lineCount_eq_pointCount [HasLines P L] [Fintype P] [Fintype L]\n    (hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p \u2209 l) :\n    lineCount L p = pointCount P l := by\n  classical\n    obtain \u27e8f, hf1, hf2\u27e9 := has_lines.exists_bijective_of_card_eq hPL\n    let s : Finset (P \u00d7 L) := Set.toFinset { i | i.1 \u2208 i.2 }\n    have step1 : (\u2211 i : P \u00d7 L, line_count L i.1) = \u2211 i : P \u00d7 L, point_count P i.2 :=\n      by\n      rw [\u2190 Finset.univ_product_univ, Finset.sum_product_right, Finset.sum_product]\n      simp_rw [Finset.sum_const, Finset.card_univ, hPL, sum_line_count_eq_sum_point_count]\n    have step2 : (\u2211 i in s, line_count L i.1) = \u2211 i in s, point_count P i.2 :=\n      by\n      rw [s.sum_finset_product Finset.univ fun p => Set.toFinset { l | p \u2208 l }]\n      rw [s.sum_finset_product_right Finset.univ fun l => Set.toFinset { p | p \u2208 l }]\n      refine'\n        (Finset.sum_bij (fun l hl => f l) (fun l hl => Finset.mem_univ (f l)) (fun l hl => _)\n            (fun _ _ _ _ h => hf1.1 h) fun p hp => _).symm\n      \u00b7 simp_rw [Finset.sum_const, Set.toFinset_card, \u2190 Nat.card_eq_fintype_card]\n        change point_count P l \u2022 point_count P l = line_count L (f l) \u2022 line_count L (f l)\n        rw [hf2]\n      \u00b7 obtain \u27e8l, hl\u27e9 := hf1.2 p\n        exact \u27e8l, Finset.mem_univ l, hl.symm\u27e9\n      all_goals simp_rw [Finset.mem_univ, true_and_iff, Set.mem_toFinset]; exact fun p => Iff.rfl\n    have step3 : (\u2211 i in s\u1d9c, line_count L i.1) = \u2211 i in s\u1d9c, point_count P i.2 := by\n      rwa [\u2190 s.sum_add_sum_compl, \u2190 s.sum_add_sum_compl, step2, add_left_cancel_iff] at step1\n    rw [\u2190 Set.toFinset_compl] at step3\n    exact\n      ((Finset.sum_eq_sum_iff_of_le fun i hi =>\n              has_lines.point_count_le_line_count (set.mem_to_finset.mp hi)).mp\n          step3.symm (p, l) (set.mem_to_finset.mpr hpl)).symm\n#align configuration.has_lines.line_count_eq_point_count Configuration.HasLines.lineCount_eq_pointCount\n\ntheorem HasPoints.lineCount_eq_pointCount [HasPoints P L] [Fintype P] [Fintype L]\n    (hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p \u2209 l) :\n    lineCount L p = pointCount P l :=\n  (@HasLines.lineCount_eq_pointCount (Dual L) (Dual P) _ _ _ _ hPL.symm l p hpl).symm\n#align configuration.has_points.line_count_eq_point_count Configuration.HasPoints.lineCount_eq_pointCount\n\n/-- If a nondegenerate configuration has a unique line through any two points, and if `|P| = |L|`,\n  then there is a unique point on any two lines. -/\nnoncomputable def HasLines.hasPoints [HasLines P L] [Fintype P] [Fintype L]\n    (h : Fintype.card P = Fintype.card L) : HasPoints P L :=\n  let this : \u2200 l\u2081 l\u2082 : L, l\u2081 \u2260 l\u2082 \u2192 \u2203 p : P, p \u2208 l\u2081 \u2227 p \u2208 l\u2082 := fun l\u2081 l\u2082 hl => by\n    classical\n      obtain \u27e8f, hf1, hf2\u27e9 := has_lines.exists_bijective_of_card_eq h\n      haveI : Nontrivial L := \u27e8\u27e8l\u2081, l\u2082, hl\u27e9\u27e9\n      haveI := fintype.one_lt_card_iff_nontrivial.mp ((congr_arg _ h).mpr Fintype.one_lt_card)\n      have h\u2081 : \u2200 p : P, 0 < line_count L p := fun p =>\n        Exists.elim (exists_ne p) fun q hq =>\n          (congr_arg _ Nat.card_eq_fintype_card).mpr\n            (fintype.card_pos_iff.mpr \u27e8\u27e8mk_line hq, (mk_line_ax hq).2\u27e9\u27e9)\n      have h\u2082 : \u2200 l : L, 0 < point_count P l := fun l => (congr_arg _ (hf2 l)).mpr (h\u2081 (f l))\n      obtain \u27e8p, hl\u2081\u27e9 := fintype.card_pos_iff.mp ((congr_arg _ Nat.card_eq_fintype_card).mp (h\u2082 l\u2081))\n      by_cases hl\u2082 : p \u2208 l\u2082\n      exact \u27e8p, hl\u2081, hl\u2082\u27e9\n      have key' : Fintype.card { q : P // q \u2208 l\u2082 } = Fintype.card { l : L // p \u2208 l } :=\n        ((has_lines.line_count_eq_point_count h hl\u2082).trans Nat.card_eq_fintype_card).symm.trans\n          Nat.card_eq_fintype_card\n      have : \u2200 q : { q // q \u2208 l\u2082 }, p \u2260 q := fun q hq => hl\u2082 ((congr_arg (\u00b7 \u2208 l\u2082) hq).mpr q.2)\n      let f : { q : P // q \u2208 l\u2082 } \u2192 { l : L // p \u2208 l } := fun q =>\n        \u27e8mk_line (this q), (mk_line_ax (this q)).1\u27e9\n      have hf : Function.Injective f := fun q\u2081 q\u2082 hq =>\n        Subtype.ext\n          ((eq_or_eq q\u2081.2 q\u2082.2 (mk_line_ax (this q\u2081)).2\n                ((congr_arg _ (subtype.ext_iff.mp hq)).mpr (mk_line_ax (this q\u2082)).2)).resolve_right\n            fun h => (congr_arg _ h).mp hl\u2082 (mk_line_ax (this q\u2081)).1)\n      have key' := ((Fintype.bijective_iff_injective_and_card f).mpr \u27e8hf, key'\u27e9).2\n      obtain \u27e8q, hq\u27e9 := key' \u27e8l\u2081, hl\u2081\u27e9\n      exact \u27e8q, (congr_arg _ (subtype.ext_iff.mp hq)).mp (mk_line_ax (this q)).2, q.2\u27e9\n  { \u2039HasLines P L\u203a with\n    mkPoint := fun l\u2081 l\u2082 hl => Classical.choose (this l\u2081 l\u2082 hl)\n    mkPoint_ax := fun l\u2081 l\u2082 hl => Classical.choose_spec (this l\u2081 l\u2082 hl) }\n#align configuration.has_lines.has_points Configuration.HasLines.hasPoints\n\n/-- If a nondegenerate configuration has a unique point on any two lines, and if `|P| = |L|`,\n  then there is a unique line through any two points. -/\nnoncomputable def HasPoints.hasLines [HasPoints P L] [Fintype P] [Fintype L]\n    (h : Fintype.card P = Fintype.card L) : HasLines P L :=\n  let this := @HasLines.hasPoints (Dual L) (Dual P) _ _ _ _ h.symm\n  { \u2039HasPoints P L\u203a with\n    mkLine := fun _ _ => this.mkPoint\n    mkLine_ax := fun _ _ => this.mkPoint_ax }\n#align configuration.has_points.has_lines Configuration.HasPoints.hasLines\n\nvariable (P L)\n\n/-- A projective plane is a nondegenerate configuration in which every pair of lines has\n  an intersection point, every pair of points has a line through them,\n  and which has three points in general position. -/\nclass ProjectivePlane extends HasPoints P L, HasLines P L where\n  exists_config :\n    \u2203 (p\u2081 p\u2082 p\u2083 : P)(l\u2081 l\u2082 l\u2083 : L),\n      p\u2081 \u2209 l\u2082 \u2227 p\u2081 \u2209 l\u2083 \u2227 p\u2082 \u2209 l\u2081 \u2227 p\u2082 \u2208 l\u2082 \u2227 p\u2082 \u2208 l\u2083 \u2227 p\u2083 \u2209 l\u2081 \u2227 p\u2083 \u2208 l\u2082 \u2227 p\u2083 \u2209 l\u2083\n#align configuration.projective_plane Configuration.ProjectivePlane\n\nnamespace ProjectivePlane\n\nvariable [ProjectivePlane P L]\n\ninstance : ProjectivePlane (Dual L) (Dual P) :=\n  { Dual.hasPoints _ _, Dual.hasLines _ _ with\n    exists_config :=\n      let \u27e8p\u2081, p\u2082, p\u2083, l\u2081, l\u2082, l\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2081, h\u2082\u2082, h\u2082\u2083, h\u2083\u2081, h\u2083\u2082, h\u2083\u2083\u27e9 := @exists_config P L _ _\n      \u27e8l\u2081, l\u2082, l\u2083, p\u2081, p\u2082, p\u2083, h\u2082\u2081, h\u2083\u2081, h\u2081\u2082, h\u2082\u2082, h\u2083\u2082, h\u2081\u2083, h\u2082\u2083, h\u2083\u2083\u27e9 }\n\n/-- The order of a projective plane is one less than the number of lines through an arbitrary point.\nEquivalently, it is one less than the number of points on an arbitrary line. -/\nnoncomputable def order : \u2115 :=\n  lineCount L (Classical.choose (@exists_config P L _ _)) - 1\n#align configuration.projective_plane.order Configuration.ProjectivePlane.order\n\ntheorem card_points_eq_card_lines [Fintype P] [Fintype L] : Fintype.card P = Fintype.card L :=\n  le_antisymm (HasLines.card_le P L) (HasPoints.card_le P L)\n#align configuration.projective_plane.card_points_eq_card_lines Configuration.ProjectivePlane.card_points_eq_card_lines\n\nvariable {P} (L)\n\ntheorem lineCount_eq_lineCount [Finite P] [Finite L] (p q : P) : lineCount L p = lineCount L q :=\n  by\n  cases nonempty_fintype P\n  cases nonempty_fintype L\n  obtain \u27e8p\u2081, p\u2082, p\u2083, l\u2081, l\u2082, l\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2081, h\u2082\u2082, h\u2082\u2083, h\u2083\u2081, h\u2083\u2082, h\u2083\u2083\u27e9 := exists_config\n  have h := card_points_eq_card_lines P L\n  let n := line_count L p\u2082\n  have hp\u2082 : line_count L p\u2082 = n := rfl\n  have hl\u2081 : point_count P l\u2081 = n := (has_lines.line_count_eq_point_count h h\u2082\u2081).symm.trans hp\u2082\n  have hp\u2083 : line_count L p\u2083 = n := (has_lines.line_count_eq_point_count h h\u2083\u2081).trans hl\u2081\n  have hl\u2083 : point_count P l\u2083 = n := (has_lines.line_count_eq_point_count h h\u2083\u2083).symm.trans hp\u2083\n  have hp\u2081 : line_count L p\u2081 = n := (has_lines.line_count_eq_point_count h h\u2081\u2083).trans hl\u2083\n  have hl\u2082 : point_count P l\u2082 = n := (has_lines.line_count_eq_point_count h h\u2081\u2082).symm.trans hp\u2081\n  suffices \u2200 p : P, line_count L p = n by exact (this p).trans (this q).symm\n  refine' fun p =>\n    or_not.elim (fun h\u2082 => _) fun h\u2082 => (has_lines.line_count_eq_point_count h h\u2082).trans hl\u2082\n  refine' or_not.elim (fun h\u2083 => _) fun h\u2083 => (has_lines.line_count_eq_point_count h h\u2083).trans hl\u2083\n  rwa [(eq_or_eq h\u2082 h\u2082\u2082 h\u2083 h\u2082\u2083).resolve_right fun h =>\n      h\u2083\u2083 ((congr_arg (Membership.Mem p\u2083) h).mp h\u2083\u2082)]\n#align configuration.projective_plane.line_count_eq_line_count Configuration.ProjectivePlane.lineCount_eq_lineCount\n\nvariable (P) {L}\n\ntheorem pointCount_eq_pointCount [Finite P] [Finite L] (l m : L) :\n    pointCount P l = pointCount P m :=\n  lineCount_eq_lineCount (Dual P) l m\n#align configuration.projective_plane.point_count_eq_point_count Configuration.ProjectivePlane.pointCount_eq_pointCount\n\nvariable {P L}\n\ntheorem lineCount_eq_pointCount [Finite P] [Finite L] (p : P) (l : L) :\n    lineCount L p = pointCount P l :=\n  Exists.elim (exists_point l) fun q hq =>\n    (lineCount_eq_lineCount L p q).trans <|\n      by\n      cases nonempty_fintype P\n      cases nonempty_fintype L\n      exact has_lines.line_count_eq_point_count (card_points_eq_card_lines P L) hq\n#align configuration.projective_plane.line_count_eq_point_count Configuration.ProjectivePlane.lineCount_eq_pointCount\n\nvariable (P L)\n\ntheorem Dual.order [Finite P] [Finite L] : order (Dual L) (Dual P) = order P L :=\n  congr_arg (fun n => n - 1) (lineCount_eq_pointCount _ _)\n#align configuration.projective_plane.dual.order Configuration.ProjectivePlane.Dual.order\n\nvariable {P} (L)\n\ntheorem lineCount_eq [Finite P] [Finite L] (p : P) : lineCount L p = order P L + 1 := by\n  classical\n    obtain \u27e8q, -, -, l, -, -, -, -, h, -\u27e9 := Classical.choose_spec (@exists_config P L _ _)\n    cases nonempty_fintype { l : L // q \u2208 l }\n    rw [order, line_count_eq_line_count L p q, line_count_eq_line_count L (Classical.choose _) q,\n      line_count, Nat.card_eq_fintype_card, Nat.sub_add_cancel]\n    exact fintype.card_pos_iff.mpr \u27e8\u27e8l, h\u27e9\u27e9\n#align configuration.projective_plane.line_count_eq Configuration.ProjectivePlane.lineCount_eq\n\nvariable (P) {L}\n\ntheorem pointCount_eq [Finite P] [Finite L] (l : L) : pointCount P l = order P L + 1 :=\n  (lineCount_eq (Dual P) l).trans (congr_arg (fun n => n + 1) (Dual.order P L))\n#align configuration.projective_plane.point_count_eq Configuration.ProjectivePlane.pointCount_eq\n\nvariable (P L)\n\ntheorem one_lt_order [Finite P] [Finite L] : 1 < order P L :=\n  by\n  obtain \u27e8p\u2081, p\u2082, p\u2083, l\u2081, l\u2082, l\u2083, -, -, h\u2082\u2081, h\u2082\u2082, h\u2082\u2083, h\u2083\u2081, h\u2083\u2082, h\u2083\u2083\u27e9 := @exists_config P L _ _\n  classical\n    cases nonempty_fintype { p : P // p \u2208 l\u2082 }\n    rw [\u2190 add_lt_add_iff_right, \u2190 point_count_eq _ l\u2082, point_count, Nat.card_eq_fintype_card]\n    simp_rw [Fintype.two_lt_card_iff, Ne, Subtype.ext_iff]\n    have h := mk_point_ax fun h => h\u2082\u2081 ((congr_arg _ h).mpr h\u2082\u2082)\n    exact\n      \u27e8\u27e8mk_point _, h.2\u27e9, \u27e8p\u2082, h\u2082\u2082\u27e9, \u27e8p\u2083, h\u2083\u2082\u27e9, ne_of_mem_of_not_mem h.1 h\u2082\u2081,\n        ne_of_mem_of_not_mem h.1 h\u2083\u2081, ne_of_mem_of_not_mem h\u2082\u2083 h\u2083\u2083\u27e9\n#align configuration.projective_plane.one_lt_order Configuration.ProjectivePlane.one_lt_order\n\nvariable {P} (L)\n\ntheorem two_lt_lineCount [Finite P] [Finite L] (p : P) : 2 < lineCount L p := by\n  simpa only [line_count_eq L p, Nat.succ_lt_succ_iff] using one_lt_order P L\n#align configuration.projective_plane.two_lt_line_count Configuration.ProjectivePlane.two_lt_lineCount\n\nvariable (P) {L}\n\ntheorem two_lt_pointCount [Finite P] [Finite L] (l : L) : 2 < pointCount P l := by\n  simpa only [point_count_eq P l, Nat.succ_lt_succ_iff] using one_lt_order P L\n#align configuration.projective_plane.two_lt_point_count Configuration.ProjectivePlane.two_lt_pointCount\n\nvariable (P) (L)\n\ntheorem card_points [Fintype P] [Finite L] : Fintype.card P = order P L ^ 2 + order P L + 1 :=\n  by\n  cases nonempty_fintype L\n  obtain \u27e8p, -\u27e9 := @exists_config P L _ _\n  let \u03d5 : { q // q \u2260 p } \u2243 \u03a3l : { l : L // p \u2208 l }, { q // q \u2208 l.1 \u2227 q \u2260 p } :=\n    { toFun := fun q => \u27e8\u27e8mk_line q.2, (mk_line_ax q.2).2\u27e9, q, (mk_line_ax q.2).1, q.2\u27e9\n      invFun := fun lq => \u27e8lq.2, lq.2.2.2\u27e9\n      left_inv := fun q => Subtype.ext rfl\n      right_inv := fun lq =>\n        Sigma.subtype_ext\n          (Subtype.ext\n            ((eq_or_eq (mk_line_ax lq.2.2.2).1 (mk_line_ax lq.2.2.2).2 lq.2.2.1 lq.1.2).resolve_left\n              lq.2.2.2))\n          rfl }\n  classical\n    have h1 : Fintype.card { q // q \u2260 p } + 1 = Fintype.card P :=\n      by\n      apply (eq_tsub_iff_add_eq_of_le (Nat.succ_le_of_lt (fintype.card_pos_iff.mpr \u27e8p\u27e9))).mp\n      convert(Fintype.card_subtype_compl _).trans (congr_arg _ (Fintype.card_subtype_eq p))\n    have h2 : \u2200 l : { l : L // p \u2208 l }, Fintype.card { q // q \u2208 l.1 \u2227 q \u2260 p } = order P L :=\n      by\n      intro l\n      rw [\u2190 Fintype.card_congr (Equiv.subtypeSubtypeEquivSubtypeInter (\u00b7 \u2208 l.val) (\u00b7 \u2260 p)),\n        Fintype.card_subtype_compl fun x : Subtype (\u00b7 \u2208 l.val) => x.val = p, \u2190\n        Nat.card_eq_fintype_card]\n      refine' tsub_eq_of_eq_add ((point_count_eq P l.1).trans _)\n      rw [\u2190 Fintype.card_subtype_eq (\u27e8p, l.2\u27e9 : { q : P // q \u2208 l.1 })]\n      simp_rw [Subtype.ext_iff_val]\n    simp_rw [\u2190 h1, Fintype.card_congr \u03d5, Fintype.card_sigma, h2, Finset.sum_const, Finset.card_univ]\n    rw [\u2190 Nat.card_eq_fintype_card, \u2190 line_count, line_count_eq, smul_eq_mul, Nat.succ_mul, sq]\n#align configuration.projective_plane.card_points Configuration.ProjectivePlane.card_points\n\ntheorem card_lines [Finite P] [Fintype L] : Fintype.card L = order P L ^ 2 + order P L + 1 :=\n  (card_points (Dual L) (Dual P)).trans (congr_arg (fun n => n ^ 2 + n + 1) (Dual.order P L))\n#align configuration.projective_plane.card_lines Configuration.ProjectivePlane.card_lines\n\nend ProjectivePlane\n\nend Configuration\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/Configuration.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7373921306167952}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson, Jalex Stark\n-/\n\nimport data.polynomial.expand\nimport linear_algebra.matrix.charpoly.basic\n\n/-!\n# Characteristic polynomials\n\nWe give methods for computing coefficients of the characteristic polynomial.\n\n## Main definitions\n\n- `matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial\n  over a nonzero ring is the dimension of the matrix\n- `matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the\n  characteristic polynomial, up to sign.\n- `matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th\n  coefficient of the characteristic polynomial, where d is the dimension of the matrix.\n  For a nonzero ring, this is the second-highest coefficient.\n\n-/\n\nnoncomputable theory\n\nuniverses u v w z\n\nopen polynomial matrix\nopen_locale big_operators polynomial\n\nvariables {R : Type u} [comm_ring R]\nvariables {n G : Type v} [decidable_eq n] [fintype n]\nvariables {\u03b1 \u03b2 : Type v} [decidable_eq \u03b1]\n\n\nopen finset\n\nvariable {M : matrix n n R}\n\nlemma charmatrix_apply_nat_degree [nontrivial R] (i j : n) :\n  (charmatrix M i j).nat_degree = ite (i = j) 1 0 :=\nby { by_cases i = j; simp [h, \u2190 degree_eq_iff_nat_degree_eq_of_pos (nat.succ_pos 0)], }\n\nlemma charmatrix_apply_nat_degree_le (i j : n) :\n  (charmatrix M i j).nat_degree \u2264 ite (i = j) 1 0 :=\nby split_ifs; simp [h, nat_degree_X_sub_C_le]\n\nnamespace matrix\n\nvariable (M)\nlemma charpoly_sub_diagonal_degree_lt :\n(M.charpoly - \u220f (i : n), (X - C (M i i))).degree < \u2191(fintype.card n - 1) :=\nbegin\n  rw [charpoly, det_apply', \u2190 insert_erase (mem_univ (equiv.refl n)),\n    sum_insert (not_mem_erase (equiv.refl n) univ), add_comm],\n  simp only [charmatrix_apply_eq, one_mul, equiv.perm.sign_refl, id.def, int.cast_one,\n    units.coe_one, add_sub_cancel, equiv.coe_refl],\n  rw \u2190 mem_degree_lt, apply submodule.sum_mem (degree_lt R (fintype.card n - 1)),\n  intros c hc, rw [\u2190 C_eq_int_cast, C_mul'],\n  apply submodule.smul_mem (degree_lt R (fintype.card n - 1)) \u2191\u2191(equiv.perm.sign c),\n  rw mem_degree_lt, apply lt_of_le_of_lt degree_le_nat_degree _, rw with_bot.coe_lt_coe,\n  apply lt_of_le_of_lt _ (equiv.perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc)),\n  apply le_trans (polynomial.nat_degree_prod_le univ (\u03bb i : n, (charmatrix M (c i) i))) _,\n  rw card_eq_sum_ones, rw sum_filter, apply sum_le_sum,\n  intros, apply charmatrix_apply_nat_degree_le,\nend\n\nlemma charpoly_coeff_eq_prod_coeff_of_le {k : \u2115} (h : fintype.card n - 1 \u2264 k) :\n  M.charpoly.coeff k = (\u220f i : n, (X - C (M i i))).coeff k :=\nbegin\n  apply eq_of_sub_eq_zero, rw \u2190 coeff_sub, apply polynomial.coeff_eq_zero_of_degree_lt,\n  apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) _, rw with_bot.coe_le_coe, apply h,\nend\n\nlemma det_of_card_zero (h : fintype.card n = 0) (M : matrix n n R) : M.det = 1 :=\nby { rw fintype.card_eq_zero_iff at h, suffices : M = 1, { simp [this] }, ext i, exact h.elim i }\n\ntheorem charpoly_degree_eq_dim [nontrivial R] (M : matrix n n R) :\nM.charpoly.degree = fintype.card n :=\nbegin\n  by_cases fintype.card n = 0,\n  { rw h, unfold charpoly, rw det_of_card_zero, {simp}, {assumption} },\n  rw \u2190 sub_add_cancel M.charpoly (\u220f (i : n), (X - C (M i i))),\n  have h1 : (\u220f (i : n), (X - C (M i i))).degree = fintype.card n,\n  { rw degree_eq_iff_nat_degree_eq_of_pos, swap, apply nat.pos_of_ne_zero h,\n    rw nat_degree_prod', simp_rw nat_degree_X_sub_C, unfold fintype.card, simp,\n    simp_rw (monic_X_sub_C _).leading_coeff, simp, },\n  rw degree_add_eq_right_of_degree_lt, exact h1, rw h1,\n  apply lt_trans (charpoly_sub_diagonal_degree_lt M), rw with_bot.coe_lt_coe,\n  rw \u2190 nat.pred_eq_sub_one, apply nat.pred_lt, apply h,\nend\n\ntheorem charpoly_nat_degree_eq_dim [nontrivial R] (M : matrix n n R) :\n  M.charpoly.nat_degree = fintype.card n :=\nnat_degree_eq_of_degree_eq_some (charpoly_degree_eq_dim M)\n\nlemma charpoly_monic (M : matrix n n R) : M.charpoly.monic :=\nbegin\n  nontriviality,\n  by_cases fintype.card n = 0, {rw [charpoly, det_of_card_zero h], apply monic_one},\n  have mon : (\u220f (i : n), (X - C (M i i))).monic,\n  { apply monic_prod_of_monic univ (\u03bb i : n, (X - C (M i i))), simp [monic_X_sub_C], },\n  rw \u2190 sub_add_cancel (\u220f (i : n), (X - C (M i i))) M.charpoly at mon,\n  rw monic at *, rw leading_coeff_add_of_degree_lt at mon, rw \u2190 mon,\n  rw charpoly_degree_eq_dim, rw \u2190 neg_sub, rw degree_neg,\n  apply lt_trans (charpoly_sub_diagonal_degree_lt M), rw with_bot.coe_lt_coe,\n  rw \u2190 nat.pred_eq_sub_one, apply nat.pred_lt, apply h,\nend\n\ntheorem trace_eq_neg_charpoly_coeff [nonempty n] (M : matrix n n R) :\n  trace M = -M.charpoly.coeff (fintype.card n - 1) :=\nbegin\n  rw charpoly_coeff_eq_prod_coeff_of_le, swap, refl,\n  rw [fintype.card, prod_X_sub_C_coeff_card_pred univ (\u03bb i : n, M i i) fintype.card_pos, neg_neg,\n    trace],\n  refl\nend\n\n-- I feel like this should use polynomial.alg_hom_eval\u2082_algebra_map\nlemma mat_poly_equiv_eval (M : matrix n n R[X]) (r : R) (i j : n) :\n  (mat_poly_equiv M).eval ((scalar n) r) i j = (M i j).eval r :=\nbegin\n  unfold polynomial.eval, unfold eval\u2082,\n  transitivity polynomial.sum (mat_poly_equiv M) (\u03bb (e : \u2115) (a : matrix n n R),\n    (a * (scalar n) r ^ e) i j),\n  { unfold polynomial.sum, rw sum_apply, dsimp, refl },\n  { simp_rw [\u2190ring_hom.map_pow, \u2190(scalar.commute _ _).eq],\n    simp only [coe_scalar, matrix.one_mul, ring_hom.id_apply,\n      pi.smul_apply, smul_eq_mul, mul_eq_mul, algebra.smul_mul_assoc],\n    have h : \u2200 x : \u2115, (\u03bb (e : \u2115) (a : R), r ^ e * a) x 0 = 0 := by simp,\n    simp only [polynomial.sum, mat_poly_equiv_coeff_apply, mul_comm],\n    apply (finset.sum_subset (support_subset_support_mat_poly_equiv _ _ _) _).symm,\n    assume n hn h'n,\n    rw not_mem_support_iff at h'n,\n    simp only [h'n, zero_mul] }\nend\n\nlemma eval_det (M : matrix n n R[X]) (r : R) :\n  polynomial.eval r M.det = (polynomial.eval (scalar n r) (mat_poly_equiv M)).det :=\nbegin\n  rw [polynomial.eval, \u2190 coe_eval\u2082_ring_hom, ring_hom.map_det],\n  apply congr_arg det, ext, symmetry, convert mat_poly_equiv_eval _ _ _ _,\nend\n\ntheorem det_eq_sign_charpoly_coeff (M : matrix n n R) :\n  M.det = (-1)^(fintype.card n) * M.charpoly.coeff 0:=\nbegin\n  rw [coeff_zero_eq_eval_zero, charpoly, eval_det, mat_poly_equiv_charmatrix, \u2190 det_smul],\n  simp\nend\n\nend matrix\n\nvariables {p : \u2115} [fact p.prime]\n\nlemma mat_poly_equiv_eq_X_pow_sub_C {K : Type*} (k : \u2115) [field K] (M : matrix n n K) :\n  mat_poly_equiv\n      ((expand K (k) : K[X] \u2192+* K[X]).map_matrix (charmatrix (M ^ k))) =\n    X ^ k - C (M ^ k) :=\nbegin\n  ext m,\n  rw [coeff_sub, coeff_C, mat_poly_equiv_coeff_apply, ring_hom.map_matrix_apply, matrix.map_apply,\n    alg_hom.coe_to_ring_hom, dmatrix.sub_apply, coeff_X_pow],\n  by_cases hij : i = j,\n  { rw [hij, charmatrix_apply_eq, alg_hom.map_sub, expand_C, expand_X, coeff_sub, coeff_X_pow,\n     coeff_C],\n    split_ifs with mp m0;\n    simp only [matrix.one_apply_eq, dmatrix.zero_apply] },\n  { rw [charmatrix_apply_ne _ _ _ hij, alg_hom.map_neg, expand_C, coeff_neg, coeff_C],\n    split_ifs with m0 mp;\n    simp only [hij, zero_sub, dmatrix.zero_apply, sub_zero, neg_zero, matrix.one_apply_ne, ne.def,\n      not_false_iff] }\nend\n\nnamespace matrix\n\n/-- Any matrix polynomial `p` is equivalent under evaluation to `p %\u2098 M.charpoly`; that is, `p`\nis equivalent to a polynomial with degree less than the dimension of the matrix. -/\nlemma aeval_eq_aeval_mod_charpoly (M : matrix n n R) (p : R[X]) :\n  aeval M p = aeval M (p %\u2098 M.charpoly) :=\n(aeval_mod_by_monic_eq_self_of_root M.charpoly_monic M.aeval_self_charpoly).symm\n\n/-- Any matrix power can be computed as the sum of matrix powers less than `fintype.card n`.\n\nTODO: add the statement for negative powers phrased with `zpow`. -/\nlemma pow_eq_aeval_mod_charpoly (M : matrix n n R) (k : \u2115) : M^k = aeval M (X^k %\u2098 M.charpoly) :=\nby rw [\u2190aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]\n\nend matrix\n\nsection ideal\n\nlemma coeff_charpoly_mem_ideal_pow {I : ideal R} (h : \u2200 i j, M i j \u2208 I) (k : \u2115) :\n  M.charpoly.coeff k \u2208 I ^ (fintype.card n - k) :=\nbegin\n  delta charpoly,\n  rw [matrix.det_apply, finset_sum_coeff],\n  apply sum_mem,\n  rintro c -,\n  rw [coeff_smul, submodule.smul_mem_iff'],\n  have : \u2211 (x : n), 1 = fintype.card n := by rw [finset.sum_const, card_univ, smul_eq_mul, mul_one],\n  rw \u2190 this,\n  apply coeff_prod_mem_ideal_pow_tsub,\n  rintro i - (_|k),\n  { rw [tsub_zero, pow_one, charmatrix_apply, coeff_sub, coeff_X_mul_zero, coeff_C_zero, zero_sub,\n      neg_mem_iff],\n    exact h (c i) i },\n  { rw [nat.succ_eq_one_add, tsub_self_add, pow_zero, ideal.one_eq_top],\n    exact submodule.mem_top }\nend\n\nend ideal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/charpoly/coeff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7373873288417107}}
{"text": "/-\nCopyright (c) 2022 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n-/\n\nimport number_theory.cyclotomic.primitive_roots\nimport field_theory.polynomial_galois_group\n\n/-!\n# Galois group of cyclotomic extensions\n\nIn this file, we show the relationship between the Galois group of `K(\u03b6\u2099)` and `(zmod n)\u02e3`;\nit is always a subgroup, and if the `n`th cyclotomic polynomial is irreducible, they are isomorphic.\n\n## Main results\n\n* `is_primitive_root.aut_to_pow_injective`: `is_primitive_root.aut_to_pow` is injective\n  in the case that it's considered over a cyclotomic field extension, where `n` does not divide\n  the characteristic of K.\n* `is_cyclotomic_extension.aut_equiv_pow`: If, additionally, the `n`th cyclotomic polynomial is\n  irreducible in K, then `aut_to_pow` is a `mul_equiv` (for example, in \u211a and certain \ud835\udd3d\u209a).\n* `gal_X_pow_equiv_units_zmod`, `gal_cyclotomic_equiv_units_zmod`: Repackage `aut_equiv_pow` in\n  terms of `polynomial.gal`.\n* `is_cyclotomic_extension.aut.comm_group`: Cyclotomic extensions are abelian.\n\n## References\n\n* https://kconrad.math.uconn.edu/blurbs/galoistheory/cyclotomic.pdf\n\n## TODO\n\n* We currently can get away with the fact that the power of a primitive root is a primitive root,\n  but the correct long-term solution for computing other explicit Galois groups is creating\n  `power_basis.map_conjugate`; but figuring out the exact correct assumptions + proof for this is\n  mathematically nontrivial. (Current thoughts: the correct condition is that the annihilating\n  ideal of both elements is equal. This may not hold in an ID, and definitely holds in an ICD.)\n\n-/\n\nlocal attribute [instance] pnat.fact_pos\n\nvariables {n : \u2115+} (K : Type*) [field K] {L : Type*} [field L] {\u03bc : L} (h\u03bc : is_primitive_root \u03bc n)\n          [algebra K L] [is_cyclotomic_extension {n} K L]\n\nopen polynomial ne_zero is_cyclotomic_extension\n\nopen_locale cyclotomic\n\nnamespace is_primitive_root\n\n/-- `is_primitive_root.aut_to_pow` is injective in the case that it's considered over a cyclotomic\nfield extension, where `n` does not divide the characteristic of K. -/\nlemma aut_to_pow_injective : function.injective $ h\u03bc.aut_to_pow K :=\nbegin\n  intros f g hfg,\n  apply_fun units.val at hfg,\n  simp only [is_primitive_root.coe_aut_to_pow_apply, units.val_eq_coe] at hfg,\n  generalize_proofs hf' hg' at hfg,\n  have hf := hf'.some_spec,\n  have hg := hg'.some_spec,\n  generalize_proofs h\u03b6 at hf hg,\n  suffices : f h\u03bc.to_roots_of_unity = g h\u03bc.to_roots_of_unity,\n  { apply alg_equiv.coe_alg_hom_injective,\n    apply (h\u03bc.power_basis K).alg_hom_ext,\n    exact this },\n  rw zmod.eq_iff_modeq_nat at hfg,\n  refine (hf.trans _).trans hg.symm,\n  rw [\u2190roots_of_unity.coe_pow _ hf'.some, \u2190roots_of_unity.coe_pow _ hg'.some],\n  congr' 1,\n  rw [pow_eq_pow_iff_modeq],\n  convert hfg,\n  rw [h\u03bc.eq_order_of],\n  rw [\u2190h\u03bc.coe_to_roots_of_unity_coe] {occs := occurrences.pos [2]},\n  rw [order_of_units, order_of_subgroup]\nend\n\nend is_primitive_root\n\nnamespace is_cyclotomic_extension\n\n/-- Cyclotomic extensions are abelian. -/\nnoncomputable def aut.comm_group [ne_zero ((n : \u2115) : K)] : comm_group (L \u2243\u2090[K] L) :=\nlet _ := of_no_zero_smul_divisors K L n in by exactI\n((zeta_primitive_root n K L).aut_to_pow_injective K).comm_group _\n  (map_one _) (map_mul _) (map_inv _) (map_div _) (map_pow _) (map_zpow _)\n\nvariables (h : irreducible (cyclotomic n K)) {K} (L)\n\ninclude h\n\n/-- The `mul_equiv` that takes an automorphism `f` to the element `k : (zmod n)\u02e3` such that\n  `f \u03bc = \u03bc ^ k`. A stronger version of `is_primitive_root.aut_to_pow`. -/\n@[simps] noncomputable def aut_equiv_pow [ne_zero ((n : \u2115) : K)] : (L \u2243\u2090[K] L) \u2243* (zmod n)\u02e3 :=\nlet hn := of_no_zero_smul_divisors K L n in\nby exactI\nlet h\u03b6 := zeta_primitive_root n K L,\n    h\u03bc := \u03bb t, h\u03b6.pow_of_coprime _ (zmod.val_coe_unit_coprime t) in\n{ inv_fun := \u03bb t, (h\u03b6.power_basis K).equiv_of_minpoly ((h\u03bc t).power_basis K)\n  begin\n    simp only [is_primitive_root.power_basis_gen],\n    have hr := is_primitive_root.minpoly_eq_cyclotomic_of_irreducible\n               ((zeta_primitive_root n K L).pow_of_coprime _ (zmod.val_coe_unit_coprime t)) h,\n    exact ((zeta_primitive_root n K L).minpoly_eq_cyclotomic_of_irreducible h).symm.trans hr\n  end,\n  left_inv := \u03bb f, begin\n    simp only [monoid_hom.to_fun_eq_coe],\n    apply alg_equiv.coe_alg_hom_injective,\n    apply (h\u03b6.power_basis K).alg_hom_ext,\n    simp only [alg_equiv.coe_alg_hom, alg_equiv.map_pow],\n    rw power_basis.equiv_of_minpoly_gen,\n    simp only [is_primitive_root.power_basis_gen, is_primitive_root.aut_to_pow_spec],\n  end,\n  right_inv := \u03bb x, begin\n    simp only [monoid_hom.to_fun_eq_coe],\n    generalize_proofs _ _ _ h,\n    have key := h\u03b6.aut_to_pow_spec K ((h\u03b6.power_basis K).equiv_of_minpoly\n                                      ((h\u03bc x).power_basis K) h),\n    have := (h\u03b6.power_basis K).equiv_of_minpoly_gen ((h\u03bc x).power_basis K) h,\n    rw h\u03b6.power_basis_gen K at this,\n    rw [this, is_primitive_root.power_basis_gen] at key,\n    rw \u2190 h\u03b6.coe_to_roots_of_unity_coe at key {occs := occurrences.pos [1, 5]},\n    simp only [\u2190coe_coe, \u2190roots_of_unity.coe_pow] at key,\n    replace key := roots_of_unity.coe_injective key,\n    rw [pow_eq_pow_iff_modeq, \u2190order_of_subgroup, \u2190order_of_units, h\u03b6.coe_to_roots_of_unity_coe,\n        \u2190(zeta_primitive_root n K L).eq_order_of, \u2190zmod.eq_iff_modeq_nat] at key,\n    simp only [zmod.nat_cast_val, zmod.cast_id', id.def] at key,\n    exact units.ext key\n  end,\n  .. (zeta_primitive_root n K L).aut_to_pow K }\n\ninclude h\u03bc\n\nvariables {L}\n\n/-- Maps `\u03bc` to the `alg_equiv` that sends `is_cyclotomic_extension.zeta` to `\u03bc`. -/\nnoncomputable def from_zeta_aut [ne_zero ((n : \u2115) : K)] : L \u2243\u2090[K] L :=\nhave _ := of_no_zero_smul_divisors K L n, by exactI\nlet h\u03b6 := (zeta_primitive_root n K L).eq_pow_of_pow_eq_one h\u03bc.pow_eq_one n.pos in\n(aut_equiv_pow L h).symm $ zmod.unit_of_coprime h\u03b6.some $\n((zeta_primitive_root n K L).pow_iff_coprime n.pos h\u03b6.some).mp $ h\u03b6.some_spec.some_spec.symm \u25b8 h\u03bc\n\nlemma from_zeta_aut_spec [ne_zero ((n : \u2115) : K)] : from_zeta_aut h\u03bc h (zeta n K L) = \u03bc :=\nbegin\n  simp_rw [from_zeta_aut, aut_equiv_pow_symm_apply],\n  generalize_proofs _ h\u03b6 h _ h\u03bc _,\n  rw [\u2190h\u03b6.power_basis_gen K] {occs := occurrences.pos [4]},\n  rw [power_basis.equiv_of_minpoly_gen, h\u03bc.power_basis_gen K],\n  convert h.some_spec.some_spec,\n  exact zmod.val_cast_of_lt h.some_spec.some\nend\n\nend is_cyclotomic_extension\n\nsection gal\n\nvariables (h : irreducible (cyclotomic n K)) {K}\n\n/-- `is_cyclotomic_extension.aut_equiv_pow` repackaged in terms of `gal`. Asserts that the\nGalois group of `cyclotomic n K` is equivalent to `(zmod n)\u02e3` if `n` does not divide the\ncharacteristic of `K`, and `cyclotomic n K` is irreducible in the base field. -/\nnoncomputable def gal_cyclotomic_equiv_units_zmod [ne_zero ((n : \u2115) : K)] :\n  (cyclotomic n K).gal \u2243* (zmod n)\u02e3 :=\n(alg_equiv.aut_congr (is_splitting_field.alg_equiv _ _)).symm.trans\n(is_cyclotomic_extension.aut_equiv_pow L h)\n\n/-- `is_cyclotomic_extension.aut_equiv_pow` repackaged in terms of `gal`. Asserts that the\nGalois group of `X ^ n - 1` is equivalent to `(zmod n)\u02e3` if `n` does not divide the characteristic\nof `K`, and `cyclotomic n K` is irreducible in the base field. -/\nnoncomputable def gal_X_pow_equiv_units_zmod [ne_zero ((n : \u2115) : K)] :\n  (X ^ (n : \u2115) - 1).gal \u2243* (zmod n)\u02e3 :=\n(alg_equiv.aut_congr (is_splitting_field.alg_equiv _ _)).symm.trans\n(is_cyclotomic_extension.aut_equiv_pow L h)\n\nend gal\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/number_theory/cyclotomic/gal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7373873202202026}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Damiano Testa, Jens Wagemaker\n-/\nimport algebra.monoid_algebra.division\nimport data.nat.interval\nimport data.polynomial.degree.definitions\nimport data.polynomial.induction\n\n/-!\n# Induction on polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains lemmas dealing with different flavours of induction on polynomials.\n-/\n\nnoncomputable theory\nopen_locale classical big_operators polynomial\n\nopen finset\n\nnamespace polynomial\nuniverses u v w z\nvariables {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : \u2115}\n\nsection semiring\nvariables [semiring R] {p q : R[X]}\n\n/-- `div_X p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`.\n  It can be used in a semiring where the usual division algorithm is not possible -/\ndef div_X (p : R[X]) : R[X] :=\n\u27e8add_monoid_algebra.div_of p.to_finsupp 1\u27e9\n\n@[simp] lemma coeff_div_X : (div_X p).coeff n = p.coeff (n+1) :=\nby { rw [add_comm], cases p, refl }\n\nlemma div_X_mul_X_add (p : R[X]) : div_X p * X + C (p.coeff 0) = p :=\next $ by rintro \u27e8_|_\u27e9; simp [coeff_C, nat.succ_ne_zero, coeff_mul_X]\n\n@[simp] lemma div_X_C (a : R) : div_X (C a) = 0 :=\next $ \u03bb n, by simp [coeff_div_X, coeff_C, finsupp.single_eq_of_ne _]\n\nlemma div_X_eq_zero_iff : div_X p = 0 \u2194 p = C (p.coeff 0) :=\n\u27e8\u03bb h, by simpa [eq_comm, h] using div_X_mul_X_add p,\n  \u03bb h, by rw [h, div_X_C]\u27e9\n\nlemma div_X_add : div_X (p + q) = div_X p + div_X q :=\next $ by simp\n\nlemma degree_div_X_lt (hp0 : p \u2260 0) : (div_X p).degree < p.degree :=\nby haveI := nontrivial.of_polynomial_ne hp0;\ncalc (div_X p).degree < (div_X p * X + C (p.coeff 0)).degree :\n  if h : degree p \u2264 0\n  then begin\n      have h' : C (p.coeff 0) \u2260 0, by rwa [\u2190 eq_C_of_degree_le_zero h],\n      rw [eq_C_of_degree_le_zero h, div_X_C, degree_zero, zero_mul, zero_add],\n      exact lt_of_le_of_ne bot_le (ne.symm (mt degree_eq_bot.1 $\n        by simp [h'])),\n    end\n  else\n    have hXp0 : div_X p \u2260 0,\n      by simpa [div_X_eq_zero_iff, -not_le, degree_le_zero_iff] using h,\n    have leading_coeff (div_X p) * leading_coeff X \u2260 0, by simpa,\n    have degree (C (p.coeff 0)) < degree (div_X p * X),\n      from calc degree (C (p.coeff 0)) \u2264 0 : degree_C_le\n         ... < 1 : dec_trivial\n         ... = degree (X : R[X]) : degree_X.symm\n         ... \u2264 degree (div_X p * X) :\n          by rw [\u2190 zero_add (degree X), degree_mul' this];\n            exact add_le_add\n              (by rw [zero_le_degree_iff, ne.def, div_X_eq_zero_iff];\n                exact \u03bb h0, h (h0.symm \u25b8 degree_C_le))\n              le_rfl,\n    by rw [degree_add_eq_left_of_degree_lt this];\n      exact degree_lt_degree_mul_X hXp0\n... = p.degree : congr_arg _ (div_X_mul_X_add _)\n\n/-- An induction principle for polynomials, valued in Sort* instead of Prop. -/\n@[elab_as_eliminator] noncomputable def rec_on_horner\n  {M : R[X] \u2192 Sort*} : \u03a0 (p : R[X]),\n  M 0 \u2192\n  (\u03a0 p a, coeff p 0 = 0 \u2192 a \u2260 0 \u2192 M p \u2192 M (p + C a)) \u2192\n  (\u03a0 p, p \u2260 0 \u2192 M p \u2192 M (p * X)) \u2192\n  M p\n| p := \u03bb M0 MC MX,\nif hp : p = 0 then eq.rec_on hp.symm M0\nelse\nhave wf : degree (div_X p) < degree p,\n  from degree_div_X_lt hp,\nby rw [\u2190 div_X_mul_X_add p] at *;\n  exact\n  if hcp0 : coeff p 0 = 0\n  then by rw [hcp0, C_0, add_zero];\n    exact MX _ (\u03bb h : div_X p = 0, by simpa [h, hcp0] using hp)\n      (rec_on_horner _ M0 MC MX)\n  else MC _ _ (coeff_mul_X_zero _) hcp0 (if hpX0 : div_X p = 0\n    then show M (div_X p * X), by rw [hpX0, zero_mul]; exact M0\n    else MX (div_X p) hpX0 (rec_on_horner _ M0 MC MX))\nusing_well_founded {dec_tac := tactic.assumption}\n\n/--  A property holds for all polynomials of positive `degree` with coefficients in a semiring `R`\nif it holds for\n* `a * X`, with `a \u2208 R`,\n* `p * X`, with `p \u2208 R[X]`,\n* `p + a`, with `a \u2208 R`, `p \u2208 R[X]`,\nwith appropriate restrictions on each term.\n\nSee `nat_degree_ne_zero_induction_on` for a similar statement involving no explicit multiplication.\n -/\n@[elab_as_eliminator] lemma degree_pos_induction_on\n  {P : R[X] \u2192 Prop} (p : R[X]) (h0 : 0 < degree p)\n  (hC : \u2200 {a}, a \u2260 0 \u2192 P (C a * X))\n  (hX : \u2200 {p}, 0 < degree p \u2192 P p \u2192 P (p * X))\n  (hadd : \u2200 {p} {a}, 0 < degree p \u2192 P p \u2192 P (p + C a)) : P p :=\nrec_on_horner p\n  (\u03bb h, by rw degree_zero at h; exact absurd h dec_trivial)\n  (\u03bb p a _ _ ih h0,\n    have 0 < degree p,\n      from lt_of_not_ge (\u03bb h, (not_lt_of_ge degree_C_le) $\n        by rwa [eq_C_of_degree_le_zero h, \u2190 C_add] at h0),\n    hadd this (ih this))\n  (\u03bb p _ ih h0',\n    if h0 : 0 < degree p\n    then hX h0 (ih h0)\n    else by rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at *;\n      exact hC (\u03bb h : coeff p 0 = 0,\n        by simpa [h, nat.not_lt_zero] using h0'))\n  h0\n\n/--  A property holds for all polynomials of non-zero `nat_degree` with coefficients in a\nsemiring `R` if it holds for\n* `p + a`, with `a \u2208 R`, `p \u2208 R[X]`,\n* `p + q`, with `p, q \u2208 R[X]`,\n* monomials with nonzero coefficient and non-zero exponent,\nwith appropriate restrictions on each term.\nNote that multiplication is \"hidden\" in the assumption on monomials, so there is no explicit\nmultiplication in the statement.\nSee `degree_pos_induction_on` for a similar statement involving more explicit multiplications.\n -/\n@[elab_as_eliminator] lemma nat_degree_ne_zero_induction_on {M : R[X] \u2192 Prop}\n  {f : R[X]} (f0 : f.nat_degree \u2260 0) (h_C_add : \u2200 {a p}, M p \u2192 M (C a + p))\n  (h_add : \u2200 {p q}, M p \u2192 M q \u2192 M (p + q))\n  (h_monomial : \u2200 {n : \u2115} {a : R}, a \u2260 0 \u2192 n \u2260 0 \u2192 M (monomial n a)) :\n  M f :=\nsuffices f.nat_degree = 0 \u2228 M f, from or.dcases_on this (\u03bb h, (f0 h).elim) id,\nbegin\n  apply f.induction_on,\n  { exact \u03bb a, or.inl (nat_degree_C _) },\n  { rintros p q (hp | hp) (hq | hq),\n    { refine or.inl _,\n      rw [eq_C_of_nat_degree_eq_zero hp, eq_C_of_nat_degree_eq_zero hq, \u2190 C_add, nat_degree_C] },\n    { refine or.inr _,\n      rw [eq_C_of_nat_degree_eq_zero hp],\n      exact h_C_add hq },\n    { refine or.inr _,\n      rw [eq_C_of_nat_degree_eq_zero hq, add_comm],\n      exact h_C_add hp },\n    { exact or.inr (h_add hp hq) } },\n  { intros n a hi,\n    by_cases a0 : a = 0,\n    { exact or.inl (by rw [a0, C_0, zero_mul, nat_degree_zero]) },\n    { refine or.inr _,\n      rw C_mul_X_pow_eq_monomial,\n      exact h_monomial a0 n.succ_ne_zero } }\nend\n\nend semiring\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/inductions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7373873166639416}}
{"text": "import tutorial_world.level08_use --hide\nopen IncidencePlane --hide\n/- Tactic : have\n\n## Summary\n`have h : P,` will create a new goal of creating a term of type `P`, and will add `h : P` to the hypotheses for the goal you were working on.\n\n## Details\nIf you want to name a term of some type (because you want it in your local context for some reason), and if you have the formula for the term, you can use have to give the term a name.\n\n## Example (have q := ... or have q : Q := ...)\nIf the local context contains\n\n```\nf : P \u2192 Q\np : P\n```\nthen the tactic `have q := f(p),` will add `q` to our local context, leaving it like this:\n\n```\nf : P \u2192 Q\np : P\nq : Q\n```\n\nIf you think about it, you don't ever really need `q`, because whenever you think you need it you coudl just use `f(p)` instead. But it's good that we can introduce convenient notation like this.\n\n## Example (have q : Q,)\nA variant of this tactic can be used where you just declare the type of the term you want to have, finish the tactic statement with a comma and no :=, and then Lean just adds it as a new goal. The number of goals goes up by one if you use `have` like this.\n\nFor example if the local context is\n\n```\nP Q R : Prop/Type,\nf : P \u2192 Q,\ng : Q \u2192 R,\np : P\n\u22a2 R\n```\nthen after `have q : Q,`, there will be the new goal\n\n```\nf : P \u2192 Q,\ng : Q \u2192 R,\np : P,\n\u22a2 Q\n```\nand your original goal will have `q : Q` added to the list of hypotheses.\n-/\n\n/-\n# Tutorial World \n\n## Level 9: the `have` tactic (boss level).\n\nCongratulations! You are half of the way to finish this world! In this level, we introduce the new tactic `have`. It is used to add a new hypothesis\nto the context (which, of course, you will have to prove!). This is sometimes useful to structure our proofs. In this particular level, it is convenient\nto prove first that `r = line_through B C`, and then that `s = line_through B C`. This strategy will allow us to finish the prove very easily!\n\nTo use the tactic `have`, we should follow the following structure: `have h : A = B,`. This line will add the hypothesis `h : A = B` to the local\ncontext and break the proof into two goals. First, Lean will ask us to prove `\u22a2 A = B` without the hypothesis `h : A = B`. Then, it will ask us to\nprove the goal that existed before with the support of the new hypothesis `h : A = B` that we have added to the local context.\n\n**Pro tip:** Because you're getting better at this, proofs are going to be more challenging as time goes by. Whenever you see that you have to prove two \nor more goals to finsih one level, you may want to use **curly braces**; that is to say, the **{** - **}** symbols. Inside each of them, you just have to\nprove one goal. Then, whenever you want to prove the following one, just open curly braces again. **Don't forget to close them with a comma at the end!**\n\nFor example, the first line of this proof will be `have hr : r = line_through B C,` (you can change `hr` into whatever name you are comfortable with to\nmake reference to the hypothesis `r = line_through B C`). Now, because two goals have appeared, you can type the following structure: \n\n{\n  \n(delete this parenthesis and hit the space bar twice)sorry,\n  \n}, \n\n{\n\n(delete this parenthesis and hit the space bar twice)sorry, \n  \n}, \n\nIn this way, by deleting the `sorry`'s, you will be able to prove the goals separately. Now, let's try solve this level together so that you can\neasily understand how the syntax of Lean works! \n\nFirst, we are going to prove the first goal, which is `\u22a2 r = line_through B C,`. To begin with, let's look at the \"theorem statements\" we have. \nCan you note that `incidence` finishes with the same structure as our goal? Then, we have to check if we have the previous implications of `incidence`\nin our local context. On the face of it, `h : B \u2260 C` and `h1 : B \u2208 r \u2227 C \u2208 r` are what we are looking for. However, `h1` should be divided into `B \u2208 r`\nand `C \u2208 r`, right? [**Rule of thumb:** whenever a hypothesis looks like `h1 : P \u2227 Q`, we can refer to `P` and `Q` as `h1.1` and `h1.2`, respectively.]\nThen, notice how `exact incidence h h1.1 h1.2,` closes the first goal! \n\nBefore jumping onto the second goal, we may want to rewrite something first. Can you see that we can `rw hr,` (where `hr : r = line_through B C`) to change \nthe goal `\u22a2 r = s` into `\u22a2 line_through B C = s`. Now, you will be wondering if `exact incidence h h2.1 h2.2,` finishes the proof, but it does not. Do you \nknow why? Because the theorem statement called `incidence` works with the goal `\u22a2 s = line_through B C`, but not with `\u22a2 line_through B C = s`. Because of \nthis reason, we should create another hypothesis by using the `have` tactic. That is to say, type `have hs : s = line_through B C,` right before the curly braces.\n\nNow, two final goals are waiting to be proved! I'm sure that you are able to complete the level by your own! Make an effort to apply the knowledge that\nwe have acquired so far! In case you get stuck, click right below for a hint. \n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nDo you see that `exact incidence h h2.1 h2.2,` closes the above goal? It is similar to the case that we have proved earlier. \nNow, try to finish the proof by rewriting one of the hypotheses. Still bewildered? Click on \"View source\" (located on the\ntop right corner of the game screen) to see the solution.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\n\n/- Lemma : no-side-bar\nIf two lines share two distinct points, then they are the same line.\n-/\nlemma equal_lines_example (B C : \u03a9) (h : B \u2260 C) (r s : Line \u03a9)\n(h1 :  B \u2208 r \u2227 C \u2208 r)\n(h2 : B \u2208 s \u2227 C \u2208 s)\n: r = s :=\nbegin\n  have hr : r = line_through B C,\n  {\n    exact incidence h h1.1 h1.2,\n  },\n  rw hr,\n  have hs : s = line_through B C,\n  {\n    exact incidence h h2.1 h2.2,\n  },\n  rw hs,\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/tutorial_world/level09_have.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7373484710329253}}
{"text": "import tactic\n/-\n\n# Quotients\n\nThe quotient of a type by an equivalence relation.\n\n## Overview\n\nA binary relation on a type `X` is just a function `r : X \u2192 X \u2192 Prop`,\nthat is, a true-false statement attached to each pair of elements of `X`.\n\nIf `r` is also reflexive, symmetric and transitive, we say it is an\nequivalence relation. We will use the standard notation `x \u2248 y`\nfor `r x y` below.\n\nGiven a type `X` and an equivalence relation `\u2248` on it, the type `clX` of\nequivalence classes for `\u2248` comes equipped with a canonical function\n`X \u2192 clX` (sending an element to its equivalence class), and it also satisfies\na universal property, namely that to give a map from `clX` to a type `T`\nis to give a map `X \u2192 T` which is constant on equivalence classes.\n\nNote however that other types other than the type of equivalence classes\nmay also satisfy this universal property. For example if we start with\na type `X` and a surjection `p : X \u2192 Y` and then define an equivalence\nrelation on `X` by `x\u2081 \u2248 x\u2082 \u2194 p x\u2081 = p x\u2082` then `Y` satisfies the same\nuniversal property. In general it is a fact in mathematics that things\nwhich define universal properties are unique up to unique isomorphism,\nand things like the type of equivalence classes are just a *model* for\nthis general concept of quotient.\n\nLean does not use the equivalence class model when doing quotients.\nHere's how it does it. The type `setoid X` is defined to be the type\nof equivalence relations on `X`. If `s : setoid X` is an equivalence relation\nthen Lean defines `quotient s` to be a new type which satisfies the\nuniversal property of quotients. Let us spell out what this means.\nFirstly, it means that there is a map `p : X \u2192 quotient s`, and\nsecondly it means that to give a map `f : quotient s \u2192 T` is to\ngive `f \u2218 p : X \u2192 T`, a map which is constant on equivalence classes.\n\nIn this file we will learn the various useful functions which Lean has\nfor dealing with quotients -- that is, the key definitions and theorems\nwhich mathematicians use, sometimes subconsciously, when dealing with\nquotients. We will learn them by explicitly working through an\nexample, namely the case where `X = \u2115\u00b2` and `(a,b) \u2248 (c,d) \u2194 a + d = c + b`. \nIn this case, the quotient is a model for the integers.\n\n## More on universal properties.\n\nRecall that if `X` and `T` are types, then `X \u2192 T` denotes the *type*\nof functions from `X` to `T`. A mathematician might call this\ntype `Hom(X,T)`. A term `f : X \u2192 T` of this type is just a function\nfrom `X` to `T`.\n\nLet us now spell out the universal property more carefully.\nGiven a type `X` and an equivalence relation `\u2248` on `X`, we say\nthat a function `f : X \u2192 T` is *constant on equivalence classes*,\n(or `\u2248`-equivariant for short), if `\u2200 x y : X, x \u2248 y \u2192 f x = f y`. \n\nWe say that a pair `(Q, p)` consisting of a type `Q` and a\nfunction `p : X \u2192 Q` are a *quotient* of `X` by `\u2248`\nif `p` is constant on equivalence classes, and furthermore `p`\nis *initial* with repect to this property. What does this mean?\nLet me spell this out. \n\nLet `(Q, p)` be a quotient of `X` by `\u2248`. Note first that if `T` is any\ntype and `g : Q \u2192 T` is any function, then `f := g \u2218 p : X \u2192 T` is\nconstant on equivalence classes (because `p` is). Being *initial* is the claim\nthat this construction, starting with a function `g : Q \u2192 T` and\ngiving us a function `f : X \u2192 T` which is `\u2248`-equivariant,\nis a *bijection* between `Q \u2192 T` and the subset of `X \u2192 T`\nconsisting of `\u2248`-equivariant functions. In diagrams, if `f` is\nconstant on equivalence classes, then there's a unique `g` which\nfills in the diagram.\n\n          f\n    X ---------> T\n    |          /\\\n    |        /\n    | p    / \u2203!g\n    |    /\n    |  /\n    \\/\n    Q\n\n\nOne can easily check that the type of equivalence classes for `\u2248` satisfies\nthis universal property, with `p` being the map sending a term of type `X`\nto its equivalence class. One can think of the type of equivalence classes\nas a \"model\" for the quotient, in the same way that you might have seen\na model for the tensor product `V \u2297 W` of two vector spaces given\nas a quotient of the vector space generated by pairs `(v,w)` by the subspace\ngenerated by an appropriate collection of relations, or a model for\nthe localisation `R[1/S]` of a commutative ring at a multiplicative\nsubset given by `R \u00d7 S` modulo a certain equivalence relation. Models\nare useful. A model of an `n`-dimensional real vector space is obtained\nby choosing a basis; then it can be identified with `\u211d\u207f` enabling explicit\ncomputations to be done. \n\nBut there are many other models for quotients. For example let's\nsay `X` and `Q` are any types, and `f : X \u2192 Q` is any surjection at all.\nDefine `\u2248` on `X` by `x \u2248 y \u2194 f x = f y`. It is easy to check that `Q` is a\nquotient of `X` by `\u2248` simply because `Q` naturally bijects with the\nequivalence classes of `\u2248`.\n\nLean does not use equivalence classes in its definition of the quotient\nof `X` by `\u2248`. It chooses a different model. It is an opaque model, meaning\nthat you cannot actually see what the terms are.\nBut Lean and mathlib give you a very solid API for the quotient.\nIn particular, the quotient satisfies the universal property, so one\ncan prove that it bijects with the type of equivalence classes on `X`.\nHowever, after a while one moves away from the \"equivalence class\"\nway of thinking, and starts thinking more abstractly about quotients,\nand so ultimately one does not really need this bijection at all.\n\nYou might wonder why Lean does not use the type of equivalence classes.\nThe reason is not a mathematical one -- it is simply to do with an\nimplementation issue which I will mention later.\n\nHere is a guided tour of the API for Lean's quotients, worked out for\na specific example -- the integers, as a quotient of \u2115\u00b2 by the\nequivalence relation `(a,b) \u2248 (c,d) \u2194 a + d = c + b.`\n\n-/\n\n-- N2 is much easier to type than `\u2115 \u00d7 \u2115` \nabbreviation N2 := \u2115 \u00d7 \u2115\n\nnamespace N2 -- all the functions below will be N2.something\n\n-- Hmm, I guess I should run you through the API for products `\u00d7`. \n\n/-\n\n### products\n\nThe product of two types `X` and `Y` is `prod X Y`, with notation `X \u00d7 Y`.\nHover over `\u00d7` to find out how to type it.\n\n-/\nsection product\n\n-- to make a term of a product, use round brackets.\ndef foo : N2 := (3,4)\n\n-- To extract the first term of a product, use `.1` or `.fst`\n\nexample : foo.1 = 3 := \nbegin\n  -- true by definition.\n  refl\nend\n\nexample : foo.fst = 3 :=\nbegin\n  refl\nend\n\n-- similarly use `.2` or `.snd` to get the second term\n\nexample : foo.snd = 4 := rfl -- term mode reflexivity of equality\n\n-- The extensionality tactic works for products: a product is determined\n-- by the two parts used to make it.\nexample (X Y : Type) (s t : X \u00d7 Y) (h1 : s.fst = t.fst) (h2 : s.snd = t.snd) :\n  s = t :=\nbegin\n  ext,\n  { exact h1 },\n  { exact h2 }\nend\n\n-- you can uses `cases x` on a product if you want to take it apart into\n-- its two pieces\nexample (A B : Type) (x : A \u00d7 B) : x = (x.1, x.2) :=\nbegin\n  -- note that this is not yet `refl` -- you have to take `x` apart. \n  cases x with a b,\n  -- \u22a2 (a, b) = ((a, b).fst, (a, b).snd)\n  dsimp only, -- to tidy up: this replaces `(a, b).fst` with `a`.\n  -- \u22a2 (a, b) = (a, b)\n  refl,\nend\n\nend product\n\n/-\n\n## Worked example: \u2124 as a quotient of \u2115\u00b2  \n\nThere's a surjection `\u2115 \u00d7 \u2115 \u2192 \u2124` sending `(a,b)` to `a - b` (where here\n`a` and `b` are regarded as integers). One checks easily that `(a,b)`\nand `(c,d)` are sent to the same integer if and only if `a + d = b + c`.\nConversely one could just define an equivalence relation on \u2115 \u00d7 \u2115\nby `ab \u2248 cd \u2194 ab.1 + cd.2 = cd.1 + ab.2` and then redefine \u2124 -- or more\nprecisely define a second \u2124 -- to be the quotient\nby this equivalence relation. Let's set up this equivalence relation\nand call the quotient `Z`. Recall we're using `N2` to mean `\u2115 \u00d7 \u2115`.\n\n-/\n\n\ndef r (ab cd : N2) : Prop :=\nab.1 + cd.2 = cd.1 + ab.2\n\n-- This is a definition so let's make a little API for it.\n-- It's nice to be able to `rw` to get rid of explicit occurrences of `r`.\n-- So let's make two lemmas suitable for rewriting.\n\nlemma r_def (ab cd : N2) : r ab cd \u2194 ab.1 + cd.2 = cd.1 + ab.2 :=\nbegin\n  refl\nend\n\n-- This one is more useful if you've already done `cases` on the pairs.\nlemma r_def' (a b c d : \u2115) : r (a,b) (c,d) \u2194 a + d = c + b :=\nbegin\n  refl\nend\n\ndef r_refl : reflexive r :=\nbegin\n  -- you can start with `unfold reflexive` if you want to see what\n  -- you're supposed to be proving here.\n  sorry,\nend\n\n-- hint: `linarith` is good at linear arithmetic. \ndef r_symm : symmetric r :=\nbegin\n  sorry\nend\n\ndef r_trans : transitive r :=\nbegin\n  sorry\nend\n\n-- now let's give N2 a setoid structure coming from `r`.\n-- In other words, we tell the type class inference system\n-- about `r`. Let's call it `setoid` and remember\n-- we're in the `N2` namespace, so its full name\n-- is N2.setoid\ninstance setoid : setoid N2 := \u27e8r, r_refl, r_symm, r_trans\u27e9\n\n-- Now we can use `\u2248` notation\n\nexample (x y : N2) : x \u2248 y \u2194 r x y :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- `r x y` and `x \u2248 y` are definitionally equal but not syntactically equal,\n-- rather annoyingly, so we need two more lemmas enabling us to rewrite.\n-- Let's teach them to `simp`, because they're the ones we'll be using\n-- in practice.\n\n@[simp] lemma equiv_def (ab cd : N2) : ab \u2248 cd \u2194 ab.1 + cd.2 = cd.1 + ab.2 :=\nbegin\n  refl\nend\n\n@[simp] lemma equiv_def' (a b c d : \u2115) : (a,b) \u2248 (c,d) \u2194 a + d = c + b :=\niff.rfl -- term mode variant\n\nend N2\n\nopen N2\n\n-- Now we can take the quotient!\ndef Z := quotient N2.setoid\n\nnamespace Z\n\n-- And now we can finally start.\n\n-- The map from N2 to Z is called `quotient.mk`\n-- Recall `foo` is `(3,4)`\n\ndef bar : Z := quotient.mk foo -- bar is the image of `foo` in the quotient.\n-- so it's morally -1.\n\n-- Notation for `quotient.mk x` is `\u27e6x\u27e7`\nexample : bar = \u27e6foo\u27e7 :=\nbegin\n  refl\nend\n\n/-\n\n## Z\n\nWe have a new type `Z` now, and a way of going from `N2`\nto `Z` (`quotient.mk`, with notation `\u27e6 \u27e7`). \n\nHere then are some things we can think about:\n\n(1) How to prove the universal property for `Z`?\n(2) How to put a ring structure on `Z`?\n(3) How to define a map from `Z` to Lean's `\u2124`, which\nis not defined as a quotient but also satisfies the\nuniversal property?\n\nWe will do (1) and (2) in this file. Let's start with (1).\nThe claim is that to give\na map `Z \u2192 T` is to give a map `N2 \u2192 T`\nwhich is constant on equivalence classes. The\nconstruction: given a map `Z \u2192 T`, just\ncompose with `quotient.mk : N2 \u2192 Z`.\nWhat do we need to prove here?\n\nFirst we need to prove that `quotient.mk` is `\u2248`-equivariant.\nIn other words, we need to prove `x \u2248 y \u2192 \u27e6x\u27e7 = \u27e6y\u27e7`.\n\n-/\n\nexample (x y : N2) : x \u2248 y \u2192 \u27e6x\u27e7 = \u27e6y\u27e7 :=\nquotient.sound\n\n-- Of course we know the other implication is also true.\n-- This is called `quotient.exact`.\n\nexample (x y : N2) : \u27e6x\u27e7 = \u27e6y\u27e7 \u2192 x \u2248 y :=\nquotient.exact\n\n-- The iff statement (useful for rewrites) is called `quotient.eq` :\n\nexample (x y : N2) : \u27e6x\u27e7 = \u27e6y\u27e7 \u2194 x \u2248 y :=\nquotient.eq\n\n-- So now we can define the map from `Z \u2192 T` to the subtype of `N2 \u2192 T`\n-- consisting of `\u2248`-equivariant functions.\n\nvariable {T : Type}\n\n/- Given a map `g : Z \u2192 T`, make a function `f : N2 \u2192 T` which is\n   constant on equivalence classes. -/\ndef universal1 (g : Z \u2192 T) :\n  {f : N2 \u2192 T // \u2200 x y : N2, x \u2248 y \u2192 f x = f y} :=\n\u27e8\u03bb n2, g \u27e6n2\u27e7, begin\n  sorry\nend\u27e9\n\n-- To go the other way, we use a new function called `quotient.lift`.\n-- Note that this is a weird name for the construction, at least if your\n-- mental picture has the quotient underneath the type with the relation.\n-- But we're stuck with it.\n\n/- Given a map `f : N2 \u2192 T` plus the assumption that it is constant on\n   equivalence classes, \"lift\" this map to a map `Z \u2192 T`. -/\ndef universal2 (f : N2 \u2192 T) (hf : \u2200 x y : N2, x \u2248 y \u2192 f x = f y) :\n  Z \u2192 T :=\nquotient.lift f hf\n\n-- So now the big question is: how do we prove that these two constructions\n-- are inverse to each other? In other words, what is the API for\n-- the definition `quotient.lift`?\n-- Let's start by showing that going from `N2 \u2192 T` to `Z \u2192 T` (via `quotient.lift`)\n-- and then back to `N2 \u2192 T` (via composing with `quotient.mk`) is the\n-- identity function. Recall `\u27e6\u27e7` is the notation for `quotient.mk`. \n-- Another way of writing the example below : universal2 \u2218 universal1 = id.\n\nexample (f : N2 \u2192 T) (hf : \u2200 x y : N2, x \u2248 y \u2192 f x = f y) :\n  f = \u03bb n2, quotient.lift f hf \u27e6n2\u27e7 :=\nbegin\n  -- true by definition!\n  refl\nend\n\n-- This is the reason quotients are defined as a black box; if we had\n-- defined them to be equivalence classes this would be true, but\n-- not by definition. To a mathematician this is not really a big deal,\n-- but it is what it is.\n\n-- To go the other way, proving universal1 \u2218 universal2 = id, the key thing\n-- to know is a function \n-- called `quotient.induction_on`:\n\nexample (g : Z \u2192 T) : g = quotient.lift (\u03bb n2, g \u27e6n2\u27e7) (universal1 g).2 :=\nbegin\n  -- two functions are equal if they agree on all inputs\n  ext z,\n  -- now use `quotient.induction_on` (this is the key move)\n  apply quotient.induction_on z,\n  -- and now we're in the situation of the above example again\n  intro ab,\n  -- so it's true by definition.\n  refl,\nend\n\n-- We have hence proved that `universal1` and `universal2` are inverse\n-- bijections, at least in this `N2 \u2192 Z` case. In `Part_C` we will do\n-- this in general, but there is a ton of material this week so\n-- don't worry if you don't get to it.\n\n/-\n\n## Giving Z a commutative ring structure\n\nLet's now show how to give this quotient object `Z` a commutative ring\nstructure, which it somehow wants to inherit from structures on `\u2115`. Recall\nthat a ring is a choice of `0`, `1`, and functions `+`, `-` and `*`\nsatisfying some axioms. After a while this all becomes straightforward\nand boring, so I will go through the proof that it's an abelian group\nunder addition carefully and then the multiplication part is just more\nof the same -- feel free to skip it.\n\n### zero and one\n\nWe start by giving `Z` a zero and a one.\n\n-/\n\ndef zero : Z := \u27e6(0, 0)\u27e7\n\ndef one : Z := \u27e6(1, 0)\u27e7\n\n-- We don't have the numeral notation yet though:\n\n-- #check (0 : Z) -- error about failing to find an instance of `has_zero Z`\n\n-- Let's use numeral notation `0` and `1` for `zero` and `one`.\n\ninstance : has_zero Z := \u27e8zero\u27e9\ninstance : has_one Z := \u27e8one\u27e9\n\n-- let's start to train the simplifier\n@[simp] lemma zero_def : (0 : Z) = \u27e6(0, 0)\u27e7 := rfl -- works \n@[simp] lemma one_def : (1 : Z) = \u27e6(1, 0)\u27e7 := rfl\n\n/-\n\n### negation\n\nLet's do negation next, by which I mean the function sending `z` to `-z`,\nbecause this is a function which only takes one input (addition takes two).\n\nHere is how a mathematician might describe defining negation on the\nequivalence classes of `\u2115 \u00d7 \u2115`. They might say this:\n\n1) choose an element `z` of the quotient `Z`.\n2) lift it randomly to a pair `(a, b)` of natural numbers.\n3) Define `-z` to be `\u27e6(b,a)\u27e7`\n4) Now let us check that this definition did not depend on the random lift in (2):\n   [and then they prove a lemma saying the construction is well-defined, i.e.\n    that if `(a, b) \u2248 (c,d)` then `\u27e6(b, a)\u27e7 = \u27e6(d, c)\u27e7` ]\n\nThis is the way mathematicians are taught. We will use *the same\nconstruction* in Lean but we will phrase it differently.\n\n1') Define an auxiliary map `N2 \u2192 Z` by sending `(a,b)` to `\u27e6(b,a)\u27e7`\n2') I claim that this function is constant on equivalence classes\n    [and then we prove a lemma saying `(a, b) \u2248 (c, d) \u2192 \u27e6(b, a)\u27e7 = \u27e6(d, c)\u27e7`\n3') Now use `quotient.lift` to descend this to a map from `Z` to `Z`.\n\nSo as you can see, the mathematics is the same, but the emphasis is slightly\ndifferent. \n-/\n\n-- Here's the auxiliary map.\ndef neg_aux (ab : N2) : Z := \u27e6(ab.2, ab.1)\u27e7\n\n-- useful for rewriting. Let's teach it to `simp`.\n@[simp] lemma neg_aux_def (ab : N2) : neg_aux ab = \u27e6(ab.2, ab.1)\u27e7 := rfl\n  -- true by def\n\n-- In the process of making this definition we need to prove a theorem\n-- saying neg_aux is constant on equivalence classes.\ndef neg : Z \u2192 Z := quotient.lift neg_aux\nbegin\n  -- \u22a2 \u2200 (a b : N2), a \u2248 b \u2192 neg_aux a = neg_aux b\n  sorry,\nend\n\n-- `-z` notation\ninstance : has_neg Z := \u27e8neg\u27e9\n\n-- Let's teach the definition of `neg` to the simplifier.\n@[simp] lemma neg_def (a b : \u2115) : (-\u27e6(a, b)\u27e7 : Z) = \u27e6(b, a)\u27e7 := rfl\n/-\n\n## Addition\n\nIf we use `quotient.lift` for defining addition, we'd have to use it twice.\nWe define `\u27e6(a, b)\u27e7 + \u27e6(c, d)\u27e7 = \u27e6(a + c, b + d)\u27e7` and would then have\nto check it was independent of the choice of lift `(a, b)` in one lemma,\nand then in a second proof check it was independent of the choice of `(c, d)`.\nThe variant `quotient.lift\u2082` enables us to prove both results in one go. \nIt says that if `f : A \u2192 B \u2192 C` is a function which and `A` and `B`\nhave equivalence relations on them, and `f` is constant on equivalence\nclasses in both the `A` and the `B` variable, then `f` descends (\"lifts\")\nto a function `A/~ \u2192 B/~ \u2192 C`.\n-/\n\n-- auxiliary definition of addition (note `(a-b)+(c-d)=(a+c)-(b+d)` )\ndef add_aux (ab cd : N2) : Z := \u27e6(ab.1 + cd.1, ab.2 + cd.2)\u27e7\n\n-- useful for rewriting\n@[simp] lemma add_aux_def (ab cd : N2) :\n  add_aux ab cd = \u27e6(ab.1 + cd.1, ab.2 + cd.2)\u27e7 :=\nrfl -- true by def\n\ndef add : Z \u2192 Z \u2192 Z := quotient.lift\u2082 add_aux \nbegin\n  sorry,\nend\n\n-- notation for addition\ninstance : has_add Z := \u27e8add\u27e9\n\n-- train the simplifier, because we have some axioms to prove about `+`\n@[simp] lemma add_def (a b c d : \u2115) :\n  (\u27e6(a, b)\u27e7 + \u27e6(c, d)\u27e7 : Z) = \u27e6(a+c, b+d)\u27e7 := \nrfl\n\n-- may as well get subtraction working\ndef sub (x y : Z) : Z := x + -y\n\ninstance : has_sub Z := \u27e8sub\u27e9\n\n/-\n\n## Z is a commutative group under addition\n\n-/\n\ndef add_comm_group : add_comm_group Z :=\n{ zero := 0,\n  add := (+),\n  neg := has_neg.neg, \n  sub := has_sub.sub,\n  -- The key is always `quotient.induction_on`\n  -- I'll do the first one for you.\n  zero_add := begin\n    intro x,\n    apply quotient.induction_on x, clear x,\n    rintro \u27e8a, b\u27e9,\n    simp,\n  end,\n  add_zero := begin\n    sorry\n  end,    \n  -- Here there are three variables so it's `quotient.induction_on\u2083`\n  -- Remember the `ring` tactic will prove identities in `\u2115`.\n  add_assoc := begin\n    sorry\n  end,\n  add_left_neg := begin\n    sorry\n  end,\n  add_comm := begin\n    sorry\n  end,\n}\n\n/-\n\n## More of the same : Z is a commutative ring.\n\nI would recommend skipping this and going onto Part B.\nThere are no more ideas here, this is just to prove that it can be done.\n\nA mild variant: let's do multiplication in a slightly different way.\nInstead of using `quotient.lift\u2082` (which descends a map `N2 \u2192 N2 \u2192 Z` to a\nmap `Z \u2192 Z \u2192 Z`) we'll use `quotient.map\u2082`, which descends a\nmap `N2 \u2192 N2 \u2192 N2` to a map `Z \u2192 Z \u2192 Z`.\n\n-/\n\n-- auxiliary definition of multiplication: `(a-b)*(c-d) = (a*c+b*d)-(a*d+b*c)`\ndef mul_aux (ab cd : N2) : N2 :=\n  (ab.1 * cd.1 + ab.2 * cd.2, ab.1 * cd.2 + ab.2 * cd.1)\n\n@[simp] lemma mul_aux_def (a b c d : \u2115) :\n  mul_aux (a,b) (c,d) = (a*c+b*d,a*d+b*c) := rfl\n\n-- The key result you have to prove here involves multiplication so is\n-- unfortunately non-linear. However `nlinarith` is OK at non-linear arithmetic...\ndef mul : Z \u2192 Z \u2192 Z := quotient.map\u2082 mul_aux \nbegin\n  sorry\nend\n\n-- notation for multiplication\ninstance : has_mul Z := \u27e8mul\u27e9\n\n@[simp] lemma mul_def (a b c d : \u2115) :\n  (\u27e6(a, b)\u27e7 * \u27e6(c, d)\u27e7 : Z) = \u27e6(a*c+b*d, a*d+b*c)\u27e7 := rfl\n\n-- now let's prove that Z is a commutative ring!\n\ndef comm_ring : comm_ring Z :=\n{ one := 1,\n  add := (+),\n  mul := (*),\n  mul_assoc := begin\n    intros x y z,\n    apply quotient.induction_on\u2083 x y z, clear x y z,\n    rintros \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9,\n    simp,\n    ring,\n  end,\n  -- etc etc\n  one_mul := begin\n    sorry\n  end,\n  mul_one := begin\n    sorry\n  end,\n  left_distrib := begin\n    sorry\n  end,\n  right_distrib := begin\n    sorry\n  end,\n  mul_comm := begin\n    sorry\n  end,\n  ..add_comm_group\n}\n\nend Z\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_7/Part_A_quotients.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.8558511396138366, "lm_q1q2_score": 0.7373484705330388}}
{"text": "import data.real.basic\n\nvariables a b c d : \u211d\n\n#check add_assoc\n#check add_mul\n#check mul_add\n\n-- BEGIN\n\n/- a tactic proof using rw -/\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nbegin\n  rw [add_mul, mul_add, mul_add],\n  rw \u2190 add_assoc,\nend \n\n/- a calc proof-/\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\ncalc\n  (a + b) * (c + d)\n      = a * c + a * d + (b * c + b * d) :\n      by rw [add_mul, mul_add, mul_add]\n  ... = a * c + a * d + b * c + b * d :\n      by rw \u2190 add_assoc\n-- END\n\n\n ", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/1_rw/ex10_rw_mul_add.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7373097459260177}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\n\nimport algebra.group_power.basic\nimport logic.function.iterate\nimport group_theory.perm.basic\n\n/-!\n# Iterates of monoid and ring homomorphisms\n\nIterate of a monoid/ring homomorphism is a monoid/ring homomorphism but it has a wrong type, so Lean\ncan't apply lemmas like `monoid_hom.map_one` to `f^[n] 1`. Though it is possible to define\na monoid structure on the endomorphisms, quite often we do not want to convert from\n`M \u2192* M` to `monoid.End M` and from `f^[n]` to `f^n` just to apply a simple lemma.\n\nSo, we restate standard `*_hom.map_*` lemmas under names `*_hom.iterate_map_*`.\n\nWe also prove formulas for iterates of add/mul left/right.\n\n## Tags\n\nhomomorphism, iterate\n-/\n\nopen function\n\nvariables {M : Type*} {N : Type*} {G : Type*} {H : Type*}\n\n/-- An auxiliary lemma that can be used to prove `\u21d1(f ^ n) = (\u21d1f^[n])`. -/\nlemma hom_coe_pow {F : Type*} [monoid F] (c : F \u2192 M \u2192 M) (h1 : c 1 = id)\n  (hmul : \u2200 f g, c (f * g) = c f \u2218 c g) (f : F) : \u2200 n, c (f ^ n) = (c f^[n])\n| 0 := by { rw [pow_zero, h1], refl }\n| (n + 1) := by rw [pow_succ, iterate_succ', hmul, hom_coe_pow]\n\nnamespace monoid_hom\n\nsection\n\nvariables [mul_one_class M] [mul_one_class N]\n\n@[simp, to_additive]\ntheorem iterate_map_one (f : M \u2192* M) (n : \u2115) : f^[n] 1 = 1 :=\niterate_fixed f.map_one n\n\n@[simp, to_additive]\ntheorem iterate_map_mul (f : M \u2192* M) (n : \u2115) (x y) :\n  f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nsemiconj\u2082.iterate f.map_mul n x y\n\nend\n\nvariables [monoid M] [monoid N] [group G] [group H]\n\n@[simp, to_additive]\ntheorem iterate_map_inv (f : G \u2192* G) (n : \u2115) (x) :\n  f^[n] (x\u207b\u00b9) = (f^[n] x)\u207b\u00b9 :=\ncommute.iterate_left f.map_inv n x\n\n@[simp, to_additive]\ntheorem iterate_map_div (f : G \u2192* G) (n : \u2115) (x y) :\n  f^[n] (x / y) = (f^[n] x) / (f^[n] y) :=\nsemiconj\u2082.iterate f.map_div n x y\n\ntheorem iterate_map_pow (f : M \u2192* M) (n : \u2115) (a) (m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_pow x m) n a\n\ntheorem iterate_map_zpow (f : G \u2192* G) (n : \u2115) (a) (m : \u2124) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_zpow x m) n a\n\nlemma coe_pow {M} [comm_monoid M] (f : monoid.End M) (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) _ _\n\nend monoid_hom\n\nlemma monoid.End.coe_pow {M} [monoid M] (f : monoid.End M) (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) _ _\n\n-- we define these manually so that we can pick a better argument order\nnamespace add_monoid_hom\nvariables [add_monoid M] [add_group G]\n\ntheorem iterate_map_smul (f : M \u2192+ M) (n m : \u2115) (x : M) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_pow n x m\n\nattribute [to_additive iterate_map_smul, to_additive_reorder 5] monoid_hom.iterate_map_pow\n\ntheorem iterate_map_zsmul (f : G \u2192+ G) (n : \u2115) (m : \u2124) (x : G) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_zpow n x m\n\nattribute [to_additive, to_additive_reorder 5] monoid_hom.iterate_map_zpow\n\nend add_monoid_hom\n\nlemma add_monoid.End.coe_pow {A} [add_monoid A] (f : add_monoid.End A) (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) _ _\n\nnamespace ring_hom\n\nsection semiring\n\nvariables {R : Type*} [semiring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\nlemma coe_pow (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) f n\n\ntheorem iterate_map_one : f^[n] 1 = 1 := f.to_monoid_hom.iterate_map_one n\n\ntheorem iterate_map_zero : f^[n] 0 = 0 := f.to_add_monoid_hom.iterate_map_zero n\n\ntheorem iterate_map_add : f^[n] (x + y) = (f^[n] x) + (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_add n x y\n\ntheorem iterate_map_mul : f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nf.to_monoid_hom.iterate_map_mul n x y\n\ntheorem iterate_map_pow (a) (n m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\nf.to_monoid_hom.iterate_map_pow n a m\n\ntheorem iterate_map_smul (n m : \u2115) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_smul n m x\n\nend semiring\n\nvariables {R : Type*} [ring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\ntheorem iterate_map_sub : f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_sub n x y\n\ntheorem iterate_map_neg : f^[n] (-x) = -(f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_neg n x\n\ntheorem iterate_map_zsmul (n : \u2115) (m : \u2124) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_zsmul n m x\n\nend ring_hom\n\nlemma equiv.perm.coe_pow {\u03b1 : Type*} (f : equiv.perm \u03b1) (n : \u2115) : \u21d1(f ^ n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb _ _, rfl) _ _\n\n--what should be the namespace for this section?\nsection monoid\n\nvariables [monoid G] (a : G) (n : \u2115)\n\n@[simp, to_additive] lemma mul_left_iterate : ((*) a)^[n] = (*) (a^n) :=\nnat.rec_on n (funext $ \u03bb x, by simp) $ \u03bb n ihn,\nfunext $ \u03bb x, by simp [iterate_succ, ihn, pow_succ', mul_assoc]\n\n@[simp, to_additive] lemma mul_right_iterate : (* a)^[n] = (* a ^ n) :=\nbegin\n  induction n with d hd,\n  { simpa },\n  { simp [\u2190 pow_succ, hd] }\nend\n\n@[to_additive]\nlemma mul_right_iterate_apply_one : (* a)^[n] 1 = a ^ n :=\nby simp [mul_right_iterate]\n\nend monoid\n\nsection semigroup\n\nvariables [semigroup G] {a b c : G}\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_left (h : semiconj_by a b c) :\n  function.semiconj ((*)a) ((*)b) ((*)c) :=\n\u03bb j, by rw [\u2190 mul_assoc, h.eq, mul_assoc]\n\n@[to_additive]\nlemma commute.function_commute_mul_left (h : commute a b) :\n  function.commute ((*)a) ((*)b) :=\nsemiconj_by.function_semiconj_mul_left h\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_right_swap (h : semiconj_by a b c) :\n  function.semiconj (*a) (*c) (*b) :=\n\u03bb j, by simp_rw [mul_assoc, \u2190 h.eq]\n\n@[to_additive]\nlemma commute.function_commute_mul_right (h : commute a b) :\n  function.commute (*a) (*b) :=\nsemiconj_by.function_semiconj_mul_right_swap h\n\nend semigroup\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/iterate_hom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7373097451874819}}
{"text": "/-\nCopyright (c) 2021 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Julian Kuelshammer\n-/\nimport data.zmod.quotient\nimport group_theory.noncomm_pi_coprod\nimport group_theory.order_of_element\nimport algebra.gcd_monoid.finset\nimport data.nat.factorization.basic\nimport tactic.by_contra\n\n/-!\n# Exponent of a group\n\nThis file defines the exponent of a group, or more generally a monoid. For a group `G` it is defined\nto be the minimal `n\u22651` such that `g ^ n = 1` for all `g \u2208 G`. For a finite group `G`,\nit is equal to the lowest common multiple of the order of all elements of the group `G`.\n\n## Main definitions\n\n* `monoid.exponent_exists` is a predicate on a monoid `G` saying that there is some positive `n`\n  such that `g ^ n = 1` for all `g \u2208 G`.\n* `monoid.exponent` defines the exponent of a monoid `G` as the minimal positive `n` such that\n  `g ^ n = 1` for all `g \u2208 G`, by convention it is `0` if no such `n` exists.\n* `add_monoid.exponent_exists` the additive version of `monoid.exponent_exists`.\n* `add_monoid.exponent` the additive version of `monoid.exponent`.\n\n## Main results\n\n* `monoid.lcm_order_eq_exponent`: For a finite left cancel monoid `G`, the exponent is equal to the\n  `finset.lcm` of the order of its elements.\n* `monoid.exponent_eq_supr_order_of(')`: For a commutative cancel monoid, the exponent is\n  equal to `\u2a06 g : G, order_of g` (or zero if it has any order-zero elements).\n\n## TODO\n* Refactor the characteristic of a ring to be the exponent of its underlying additive group.\n-/\n\nuniverse u\n\nvariable {G : Type u}\n\nopen_locale classical\n\nnamespace monoid\n\nsection monoid\n\nvariables (G) [monoid G]\n\n/--A predicate on a monoid saying that there is a positive integer `n` such that `g ^ n = 1`\n  for all `g`.-/\n@[to_additive \"A predicate on an additive monoid saying that there is a positive integer `n` such\n  that `n \u2022 g = 0` for all `g`.\"]\ndef exponent_exists  := \u2203 n, 0 < n \u2227 \u2200 g : G, g ^ n = 1\n\n/--The exponent of a group is the smallest positive integer `n` such that `g ^ n = 1` for all\n  `g \u2208 G` if it exists, otherwise it is zero by convention.-/\n@[to_additive \"The exponent of an additive group is the smallest positive integer `n` such that\n  `n \u2022 g = 0` for all `g \u2208 G` if it exists, otherwise it is zero by convention.\"]\nnoncomputable def exponent :=\nif h : exponent_exists G then nat.find h else 0\n\nvariable {G}\n\n@[to_additive]\nlemma exponent_exists_iff_ne_zero : exponent_exists G \u2194 exponent G \u2260 0 :=\nbegin\n  rw [exponent],\n  split_ifs,\n  { simp [h, @not_lt_zero' \u2115] }, --if this isn't done this way, `to_additive` freaks\n  { tauto },\nend\n\n@[to_additive]\nlemma exponent_eq_zero_iff : exponent G = 0 \u2194 \u00ac exponent_exists G :=\nby simp only [exponent_exists_iff_ne_zero, not_not]\n\n@[to_additive]\nlemma exponent_eq_zero_of_order_zero {g : G} (hg : order_of g = 0) : exponent G = 0 :=\nexponent_eq_zero_iff.mpr $ \u03bb \u27e8n, hn, hgn\u27e9, order_of_eq_zero_iff'.mp hg n hn $ hgn g\n\n@[to_additive exponent_nsmul_eq_zero]\nlemma pow_exponent_eq_one (g : G) : g ^ exponent G = 1 :=\nbegin\n  by_cases exponent_exists G,\n  { simp_rw [exponent, dif_pos h],\n    exact (nat.find_spec h).2 g },\n  { simp_rw [exponent, dif_neg h, pow_zero] }\nend\n\n@[to_additive]\nlemma pow_eq_mod_exponent {n : \u2115} (g : G): g ^ n = g ^ (n % exponent G) :=\ncalc g ^ n = g ^ (n % exponent G + exponent G * (n / exponent G)) : by rw [nat.mod_add_div]\n  ... = g ^ (n % exponent G) : by simp [pow_add, pow_mul, pow_exponent_eq_one]\n\n@[to_additive]\nlemma exponent_pos_of_exists (n : \u2115) (hpos : 0 < n) (hG : \u2200 g : G, g ^ n = 1) :\n  0 < exponent G :=\nbegin\n  have h : \u2203 n, 0 < n \u2227 \u2200 g : G, g ^ n = 1 := \u27e8n, hpos, hG\u27e9,\n  rw [exponent, dif_pos],\n  exact (nat.find_spec h).1,\nend\n\n@[to_additive]\n\n\n@[to_additive]\nlemma exponent_min (m : \u2115) (hpos : 0 < m) (hm : m < exponent G) : \u2203 g : G, g ^ m \u2260 1 :=\nbegin\n  by_contra' h,\n  have hcon : exponent G \u2264 m := exponent_min' m hpos h,\n  linarith,\nend\n\n@[simp, to_additive]\nlemma exp_eq_one_of_subsingleton [subsingleton G] : exponent G = 1 :=\nbegin\n  apply le_antisymm,\n  { apply exponent_min' _ nat.one_pos,\n    simp },\n  { apply nat.succ_le_of_lt,\n    apply exponent_pos_of_exists 1 (nat.one_pos),\n    simp },\nend\n\n@[to_additive add_order_dvd_exponent]\nlemma order_dvd_exponent (g : G) : (order_of g) \u2223 exponent G :=\norder_of_dvd_of_pow_eq_one $ pow_exponent_eq_one g\n\nvariable (G)\n\n@[to_additive]\nlemma exponent_dvd_of_forall_pow_eq_one (G) [monoid G] (n : \u2115) (hG : \u2200 g : G, g ^ n = 1) :\n  exponent G \u2223 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hpos,\n  { exact dvd_zero _ },\n  apply nat.dvd_of_mod_eq_zero,\n  by_contradiction h,\n  have h\u2081 := nat.pos_of_ne_zero h,\n  have h\u2082 : n % exponent G < exponent G := nat.mod_lt _ (exponent_pos_of_exists n hpos hG),\n  have h\u2083 : exponent G \u2264 n % exponent G,\n  { apply exponent_min' _ h\u2081,\n    simp_rw \u2190pow_eq_mod_exponent,\n    exact hG },\n  linarith,\nend\n\n@[to_additive lcm_add_order_of_dvd_exponent]\nlemma lcm_order_of_dvd_exponent [fintype G] : (finset.univ : finset G).lcm order_of \u2223 exponent G :=\nbegin\n  apply finset.lcm_dvd,\n  intros g hg,\n  exact order_dvd_exponent g\nend\n\n@[to_additive exists_order_of_eq_pow_padic_val_nat_add_exponent]\nlemma _root_.nat.prime.exists_order_of_eq_pow_factorization_exponent {p : \u2115} (hp : p.prime) :\n  \u2203 g : G, order_of g = p ^ (exponent G).factorization p :=\nbegin\n  haveI := fact.mk hp,\n  rcases eq_or_ne ((exponent G).factorization p) 0 with h | h,\n  { refine \u27e81, by rw [h, pow_zero, order_of_one]\u27e9 },\n  have he : 0 < exponent G := ne.bot_lt (\u03bb ht,\n    by {rw ht at h, apply h, rw [bot_eq_zero, nat.factorization_zero, finsupp.zero_apply] }),\n  rw \u2190 finsupp.mem_support_iff at h,\n  obtain \u27e8g, hg\u27e9 : \u2203 (g : G), g ^ (exponent G / p) \u2260 1,\n  { suffices key : \u00ac exponent G \u2223 exponent G / p,\n    { simpa using mt (exponent_dvd_of_forall_pow_eq_one G (exponent G / p)) key },\n    exact \u03bb hd, hp.one_lt.not_le ((mul_le_iff_le_one_left he).mp $\n                nat.le_of_dvd he $ nat.mul_dvd_of_dvd_div (nat.dvd_of_mem_factorization h) hd) },\n  obtain \u27e8k, hk : exponent G = p ^ _ * k\u27e9 := nat.ord_proj_dvd _ _,\n  obtain \u27e8t, ht\u27e9 := nat.exists_eq_succ_of_ne_zero (finsupp.mem_support_iff.mp h),\n  refine \u27e8g ^ k, _\u27e9,\n  rw ht,\n  apply order_of_eq_prime_pow,\n  { rwa [hk, mul_comm, ht, pow_succ', \u2190mul_assoc, nat.mul_div_cancel _ hp.pos, pow_mul] at hg },\n  { rw [\u2190nat.succ_eq_add_one, \u2190ht, \u2190pow_mul, mul_comm, \u2190hk],\n    exact pow_exponent_eq_one g },\nend\n\nvariable {G}\n\n@[to_additive] lemma exponent_ne_zero_iff_range_order_of_finite (h : \u2200 g : G, 0 < order_of g) :\n  exponent G \u2260 0 \u2194 (set.range (order_of : G \u2192 \u2115)).finite :=\nbegin\n  refine \u27e8\u03bb he, _, \u03bb he, _\u27e9,\n  { by_contra h,\n    obtain \u27e8m, \u27e8t, rfl\u27e9, het\u27e9 := set.infinite.exists_nat_lt h (exponent G),\n    exact pow_ne_one_of_lt_order_of' he het (pow_exponent_eq_one t) },\n  { lift (set.range order_of) to finset \u2115 using he with t ht,\n    have htpos : 0 < t.prod id,\n    { refine finset.prod_pos (\u03bb a ha, _),\n      rw [\u2190finset.mem_coe, ht] at ha,\n      obtain \u27e8k, rfl\u27e9 := ha,\n      exact h k },\n    suffices : exponent G \u2223 t.prod id,\n    { intro h,\n      rw [h, zero_dvd_iff] at this,\n      exact htpos.ne' this },\n    refine exponent_dvd_of_forall_pow_eq_one _ _ (\u03bb g, _),\n    rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd, pow_zero g],\n    apply finset.dvd_prod_of_mem,\n    rw [\u2190finset.mem_coe, ht],\n    exact set.mem_range_self g },\nend\n\n@[to_additive] lemma exponent_eq_zero_iff_range_order_of_infinite (h : \u2200 g : G, 0 < order_of g) :\n  exponent G = 0 \u2194 (set.range (order_of : G \u2192 \u2115)).infinite :=\nhave _ := exponent_ne_zero_iff_range_order_of_finite h,\nby rwa [ne.def, not_iff_comm, iff.comm] at this\n\n@[to_additive lcm_add_order_eq_exponent]\nlemma lcm_order_eq_exponent [fintype G] : (finset.univ : finset G).lcm order_of = exponent G :=\nbegin\n  apply nat.dvd_antisymm (lcm_order_of_dvd_exponent G),\n  refine exponent_dvd_of_forall_pow_eq_one G _ (\u03bb g, _),\n  obtain \u27e8m, hm\u27e9 : order_of g \u2223 finset.univ.lcm order_of := finset.dvd_lcm (finset.mem_univ g),\n  rw [hm, pow_mul, pow_order_of_eq_one, one_pow]\nend\n\nend monoid\n\nsection left_cancel_monoid\n\nvariable [left_cancel_monoid G]\n\n@[to_additive]\nlemma exponent_ne_zero_of_finite [finite G] : exponent G \u2260 0 :=\nby { casesI nonempty_fintype G,\n  simpa [\u2190lcm_order_eq_exponent, finset.lcm_eq_zero_iff] using \u03bb x, (order_of_pos x).ne' }\n\nend left_cancel_monoid\n\nsection comm_monoid\n\nvariable [comm_monoid G]\n\n@[to_additive] lemma exponent_eq_supr_order_of (h : \u2200 g : G, 0 < order_of g) :\n  exponent G = \u2a06 g : G, order_of g :=\nbegin\n  rw supr,\n  rcases eq_or_ne (exponent G) 0 with he | he,\n  { rw [he, set.infinite.nat.Sup_eq_zero $ (exponent_eq_zero_iff_range_order_of_infinite h).1 he] },\n  have hne : (set.range (order_of : G \u2192 \u2115)).nonempty := \u27e81, 1, order_of_one\u27e9,\n  have hfin : (set.range (order_of : G \u2192 \u2115)).finite,\n  { rwa [\u2190 exponent_ne_zero_iff_range_order_of_finite h] },\n  obtain \u27e8t, ht\u27e9 := hne.cSup_mem hfin,\n  apply nat.dvd_antisymm _,\n  { rw \u2190ht,\n    apply order_dvd_exponent },\n  refine nat.dvd_of_factors_subperm he _,\n  rw list.subperm_ext_iff,\n  by_contra' h,\n  obtain \u27e8p, hp, hpe\u27e9 := h,\n  replace hp := nat.prime_of_mem_factors hp,\n  simp only [nat.factors_count_eq] at hpe,\n  set k := (order_of t).factorization p with hk,\n  obtain \u27e8g, hg\u27e9 := hp.exists_order_of_eq_pow_factorization_exponent G,\n  suffices : order_of t < order_of (t ^ (p ^ k) * g),\n  { rw ht at this,\n    exact this.not_le (le_cSup hfin.bdd_above $ set.mem_range_self _) },\n  have hpk  : p ^ k \u2223 order_of t := nat.ord_proj_dvd _ _,\n  have hpk' : order_of (t ^ p ^ k) = order_of t / p ^ k,\n  { rw [order_of_pow' t (pow_ne_zero k hp.ne_zero), nat.gcd_eq_right hpk] },\n  obtain \u27e8a, ha\u27e9 := nat.exists_eq_add_of_lt hpe,\n  have hcoprime : (order_of (t ^ p ^ k)).coprime (order_of g),\n  { rw [hg, nat.coprime_pow_right_iff (pos_of_gt hpe), nat.coprime_comm],\n    apply or.resolve_right (nat.coprime_or_dvd_of_prime hp _),\n    nth_rewrite 0 \u2190pow_one p,\n    convert nat.pow_succ_factorization_not_dvd (h $ t ^ p ^ k).ne' hp,\n    rw [hpk', nat.factorization_div hpk],\n    simp [hp] },\n  rw [(commute.all _ g).order_of_mul_eq_mul_order_of_of_coprime hcoprime, hpk', hg, ha, \u2190ht, \u2190hk,\n      pow_add, pow_add, pow_one, \u2190mul_assoc, \u2190mul_assoc, nat.div_mul_cancel, mul_assoc,\n      lt_mul_iff_one_lt_right $ h t, \u2190pow_succ'],\n  exact one_lt_pow hp.one_lt a.succ_ne_zero,\n  exact hpk\nend\n\n@[to_additive] lemma exponent_eq_supr_order_of' :\n  exponent G = if \u2203 g : G, order_of g = 0 then 0 else \u2a06 g : G, order_of g :=\nbegin\n  split_ifs,\n  { obtain \u27e8g, hg\u27e9 := h,\n    exact exponent_eq_zero_of_order_zero hg },\n  { have := not_exists.mp h,\n    exact exponent_eq_supr_order_of (\u03bb g, ne.bot_lt $ this g) }\nend\n\nend comm_monoid\n\nsection cancel_comm_monoid\n\nvariables [cancel_comm_monoid G]\n\n@[to_additive] lemma exponent_eq_max'_order_of [fintype G] :\n  exponent G = ((@finset.univ G _).image order_of).max' \u27e81, by simp\u27e9 :=\nbegin\n  rw [\u2190finset.nonempty.cSup_eq_max', finset.coe_image, finset.coe_univ, set.image_univ, \u2190 supr],\n  exact exponent_eq_supr_order_of order_of_pos\nend\n\nend cancel_comm_monoid\n\nend monoid\n\nsection comm_group\n\nopen subgroup\nopen_locale big_operators\n\nvariables (G) [comm_group G] [group.fg G]\n\n@[to_additive] lemma card_dvd_exponent_pow_rank : nat.card G \u2223 monoid.exponent G ^ group.rank G :=\nbegin\n  obtain \u27e8S, hS1, hS2\u27e9 := group.rank_spec G,\n  rw [\u2190hS1, \u2190fintype.card_coe, \u2190finset.card_univ, \u2190finset.prod_const],\n  let f : (\u03a0 g : S, zpowers (g : G)) \u2192* G := noncomm_pi_coprod (\u03bb s t h x y hx hy, mul_comm x y),\n  have hf : function.surjective f,\n  { rw [\u2190monoid_hom.range_top_iff_surjective, eq_top_iff, \u2190hS2, closure_le],\n    exact \u03bb g hg, \u27e8pi.mul_single \u27e8g, hg\u27e9 \u27e8g, mem_zpowers g\u27e9, noncomm_pi_coprod_mul_single _ _\u27e9 },\n  replace hf := nat_card_dvd_of_surjective f hf,\n  rw nat.card_pi at hf,\n  refine hf.trans (finset.prod_dvd_prod_of_dvd _ _ (\u03bb g hg, _)),\n  rw \u2190 order_eq_card_zpowers',\n  exact monoid.order_dvd_exponent (g : G),\nend\n\n@[to_additive] lemma card_dvd_exponent_pow_rank' {n : \u2115} (hG : \u2200 g : G, g ^ n = 1) :\n  nat.card G \u2223 n ^ group.rank G :=\n(card_dvd_exponent_pow_rank G).trans\n    (pow_dvd_pow_of_dvd (monoid.exponent_dvd_of_forall_pow_eq_one G n hG) (group.rank G))\n\nend comm_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/exponent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115783, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7372707079258585}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar el l\u00edmite del producto de dos sucesiones\n-- convergentes es el producto de sus l\u00edmites.\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_convergencia\nimport .Convergencia_de_la_funcion_constante\nimport .Convergencia_de_la_suma\nimport .Convergencia_del_producto_por_una_constante\nimport .Acotacion_de_convergentes\nimport .Producto_por_sucesion_convergente_a_cero\nimport tactic\n\nvariables {s t : \u2115 \u2192 \u211d} {a b : \u211d}\n\ntheorem converges_to_mul\n  (cs : converges_to s a)\n  (ct : converges_to t b)\n  : converges_to (\u03bb n, s n * t n) (a * b) :=\nbegin\n  have h\u2081 : converges_to (\u03bb n, s n * (t n - b)) 0,\n  { apply aux cs,\n    convert converges_to_add ct (converges_to_const (-b)),\n    ring, },\n  convert (converges_to_add h\u2081 (@converges_to_mul_const s a b cs)),\n  { ext,\n    ring },\n  { ring },\nend\n\n-- Prueba\n-- ======\n\n/-\ns t : \u2115 \u2192 \u211d,\na b : \u211d,\ncs : converges_to s a,\nct : converges_to t b\n\u22a2 converges_to (\u03bb (n : \u2115), s n * t n) (a * b)\n  >> have h\u2081 : converges_to (\u03bb n, s n * (t n - b)) 0,\n| \u22a2 converges_to (\u03bb (n : \u2115), s n * (t n - b)) 0\n|   >> { apply aux cs,\n| \u22a2 converges_to (\u03bb (n : \u2115), t n - b) 0\n|   >>   convert converges_to_add ct (converges_to_const (-b)),\n| \u22a2 0 = b + -b\n|   >>   ring },\nh\u2081 : converges_to (\u03bb (n : \u2115), s n * (t n - b)) 0\n\u22a2 converges_to (\u03bb (n : \u2115), s n * t n) (a * b)\n  >> convert (converges_to_add h\u2081 (@converges_to_mul_const s a b cs)),\n| \u22a2 (\u03bb (n : \u2115), s n * t n) = \u03bb (n : \u2115), s n * (t n - b) + b * s n\n|   >> { ext,\n| x : \u2115\n| \u22a2 s x * t x = s x * (t x - b) + b * s x\n|   >>   ring },\n\u22a2 a * b = 0 + b * a\n  >> { ring },\nno goals\n-/\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Convergencia_del_producto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7372707079258582}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov, S\u00e9bastien Gou\u00ebzel\n-/\nimport measure_theory.constructions.borel_space\n\n/-!\n# Stieltjes measures on the real line\n\nConsider a function `f : \u211d \u2192 \u211d` which is monotone and right-continuous. Then one can define a\ncorrresponding measure, giving mass `f b - f a` to the interval `(a, b]`.\n\n## Main definitions\n\n* `stieltjes_function` is a structure containing a function from `\u211d \u2192 \u211d`, together with the\nassertions that it is monotone and right-continuous. To `f : stieltjes_function`, one associates\na Borel measure `f.measure`.\n* `f.left_lim x` is the limit of `f` to the left of `x`.\n* `f.measure_Ioc` asserts that `f.measure (Ioc a b) = of_real (f b - f a)`\n* `f.measure_Ioo` asserts that `f.measure (Ioo a b) = of_real (f.left_lim b - f a)`.\n* `f.measure_Icc` and `f.measure_Ico` are analogous.\n-/\n\nnoncomputable theory\nopen classical set filter\nopen ennreal (of_real)\nopen_locale big_operators ennreal nnreal topological_space measure_theory\n\n/-! ### Basic properties of Stieltjes functions -/\n\n/-- Bundled monotone right-continuous real functions, used to construct Stieltjes measures. -/\nstructure stieltjes_function :=\n(to_fun : \u211d \u2192 \u211d)\n(mono' : monotone to_fun)\n(right_continuous' : \u2200 x, continuous_within_at to_fun (Ici x) x)\n\nnamespace stieltjes_function\n\ninstance : has_coe_to_fun stieltjes_function (\u03bb _, \u211d \u2192 \u211d) := \u27e8to_fun\u27e9\n\ninitialize_simps_projections stieltjes_function (to_fun \u2192 apply)\n\nvariable (f : stieltjes_function)\n\nlemma mono : monotone f := f.mono'\n\nlemma right_continuous (x : \u211d) : continuous_within_at f (Ici x) x := f.right_continuous' x\n\n/-- The limit of a Stieltjes function to the left of `x` (it exists by monotonicity). The fact that\nit is indeed a left limit is asserted in `tendsto_left_lim` -/\n@[irreducible] def left_lim (x : \u211d) := Sup (f '' (Iio x))\n\nlemma tendsto_left_lim (x : \u211d) : tendsto f (\ud835\udcdd[<] x) (\ud835\udcdd (f.left_lim x)) :=\nby { rw left_lim, exact f.mono.tendsto_nhds_within_Iio x }\n\nlemma left_lim_le {x y : \u211d} (h : x \u2264 y) : f.left_lim x \u2264 f y :=\nbegin\n  apply le_of_tendsto (f.tendsto_left_lim x),\n  filter_upwards [self_mem_nhds_within] with _ hz using (f.mono (le_of_lt hz)).trans (f.mono h),\nend\n\nlemma le_left_lim {x y : \u211d} (h : x < y) : f x \u2264 f.left_lim y :=\nbegin\n  apply ge_of_tendsto (f.tendsto_left_lim y),\n  apply mem_nhds_within_Iio_iff_exists_Ioo_subset.2 \u27e8x, h, _\u27e9,\n  assume z hz,\n  exact f.mono hz.1.le,\nend\n\nlemma left_lim_le_left_lim {x y : \u211d} (h : x \u2264 y) : f.left_lim x \u2264 f.left_lim y :=\nbegin\n  rcases eq_or_lt_of_le h with rfl|hxy,\n  { exact le_rfl },\n  { exact (f.left_lim_le le_rfl).trans (f.le_left_lim hxy) }\nend\n\n/-- The identity of `\u211d` as a Stieltjes function, used to construct Lebesgue measure. -/\n@[simps] protected def id : stieltjes_function :=\n{ to_fun := id,\n  mono' := \u03bb x y, id,\n  right_continuous' := \u03bb x, continuous_within_at_id }\n\n@[simp] lemma id_left_lim (x : \u211d) : stieltjes_function.id.left_lim x = x :=\ntendsto_nhds_unique (stieltjes_function.id.tendsto_left_lim x) $\n  (continuous_at_id).tendsto.mono_left nhds_within_le_nhds\n\ninstance : inhabited stieltjes_function := \u27e8stieltjes_function.id\u27e9\n\n/-! ### The outer measure associated to a Stieltjes function -/\n\n/-- Length of an interval. This is the largest monotone function which correctly measures all\nintervals. -/\ndef length (s : set \u211d) : \u211d\u22650\u221e := \u2a05a b (h : s \u2286 Ioc a b), of_real (f b - f a)\n\n@[simp] lemma length_empty : f.length \u2205 = 0 :=\nnonpos_iff_eq_zero.1 $ infi_le_of_le 0 $ infi_le_of_le 0 $ by simp\n\n@[simp] lemma length_Ioc (a b : \u211d) :\n  f.length (Ioc a b) = of_real (f b - f a) :=\nbegin\n  refine le_antisymm (infi_le_of_le a $ infi\u2082_le b subset.rfl)\n    (le_infi $ \u03bb a', le_infi $ \u03bb b', le_infi $ \u03bb h, ennreal.coe_le_coe.2 _),\n  cases le_or_lt b a with ab ab,\n  { rw real.to_nnreal_of_nonpos (sub_nonpos.2 (f.mono ab)), apply zero_le, },\n  cases (Ioc_subset_Ioc_iff ab).1 h with h\u2081 h\u2082,\n  exact real.to_nnreal_le_to_nnreal (sub_le_sub (f.mono h\u2081) (f.mono h\u2082))\nend\n\nlemma length_mono {s\u2081 s\u2082 : set \u211d} (h : s\u2081 \u2286 s\u2082) : f.length s\u2081 \u2264 f.length s\u2082 :=\ninfi_mono $ \u03bb a, binfi_mono $ \u03bb b, h.trans\n\nopen measure_theory\n\n/-- The Stieltjes outer measure associated to a Stieltjes function. -/\nprotected def outer : outer_measure \u211d :=\nouter_measure.of_function f.length f.length_empty\n\nlemma outer_le_length (s : set \u211d) : f.outer s \u2264 f.length s :=\nouter_measure.of_function_le _\n\n/-- If a compact interval `[a, b]` is covered by a union of open interval `(c i, d i)`, then\n`f b - f a \u2264 \u2211 f (d i) - f (c i)`. This is an auxiliary technical statement to prove the same\nstatement for half-open intervals, the point of the current statement being that one can use\ncompactness to reduce it to a finite sum, and argue by induction on the size of the covering set. -/\nlemma length_subadditive_Icc_Ioo {a b : \u211d} {c d : \u2115 \u2192 \u211d}\n  (ss : Icc a b \u2286 \u22c3 i, Ioo (c i) (d i)) :\n  of_real (f b - f a) \u2264 \u2211' i, of_real (f (d i) - f (c i)) :=\nbegin\n  suffices : \u2200 (s:finset \u2115) b\n    (cv : Icc a b \u2286 \u22c3 i \u2208 (\u2191s:set \u2115), Ioo (c i) (d i)),\n    (of_real (f b - f a) : \u211d\u22650\u221e) \u2264 \u2211 i in s, of_real (f (d i) - f (c i)),\n  { rcases is_compact_Icc.elim_finite_subcover_image (\u03bb (i : \u2115) (_ : i \u2208 univ),\n      @is_open_Ioo _ _ _ _ (c i) (d i)) (by simpa using ss) with \u27e8s, su, hf, hs\u27e9,\n    have e : (\u22c3 i \u2208 (\u2191hf.to_finset:set \u2115), Ioo (c i) (d i)) = (\u22c3 i \u2208 s, Ioo (c i) (d i)),\n      by simp only [ext_iff, exists_prop, finset.set_bUnion_coe, mem_Union, forall_const, iff_self,\n                    finite.mem_to_finset],\n    rw ennreal.tsum_eq_supr_sum,\n    refine le_trans _ (le_supr _ hf.to_finset),\n    exact this hf.to_finset _ (by simpa only [e]) },\n  clear ss b,\n  refine \u03bb s, finset.strong_induction_on s (\u03bb s IH b cv, _),\n  cases le_total b a with ab ab,\n  { rw ennreal.of_real_eq_zero.2 (sub_nonpos.2 (f.mono ab)), exact zero_le _, },\n  have := cv \u27e8ab, le_rfl\u27e9, simp at this,\n  rcases this with \u27e8i, is, cb, bd\u27e9,\n  rw [\u2190 finset.insert_erase is] at cv \u22a2,\n  rw [finset.coe_insert, bUnion_insert] at cv,\n  rw [finset.sum_insert (finset.not_mem_erase _ _)],\n  refine le_trans _ (add_le_add_left (IH _ (finset.erase_ssubset is) (c i) _) _),\n  { refine le_trans (ennreal.of_real_le_of_real _) ennreal.of_real_add_le,\n    rw sub_add_sub_cancel,\n    exact sub_le_sub_right (f.mono bd.le) _ },\n  { rintro x \u27e8h\u2081, h\u2082\u27e9,\n    refine (cv \u27e8h\u2081, le_trans h\u2082 (le_of_lt cb)\u27e9).resolve_left\n      (mt and.left (not_lt_of_le h\u2082)) }\nend\n\n@[simp] lemma outer_Ioc (a b : \u211d) :\n  f.outer (Ioc a b) = of_real (f b - f a) :=\nbegin\n  /- It suffices to show that, if `(a, b]` is covered by sets `s i`, then `f b - f a` is bounded\n  by `\u2211 f.length (s i) + \u03b5`. The difficulty is that `f.length` is expressed in terms of half-open\n  intervals, while we would like to have a compact interval covered by open intervals to use\n  compactness and finite sums, as provided by `length_subadditive_Icc_Ioo`. The trick is to use the\n  right-continuity of `f`. If `a'` is close enough to `a` on its right, then `[a', b]` is still\n  covered by the sets `s i` and moreover `f b - f a'` is very close to `f b - f a` (up to `\u03b5/2`).\n  Also, by definition one can cover `s i` by a half-closed interval `(p i, q i]` with `f`-length\n  very close to  that of `s i` (within a suitably small `\u03b5' i`, say). If one moves `q i` very\n  slightly to the right, then the `f`-length will change very little by right continuity, and we\n  will get an open interval `(p i, q' i)` covering `s i` with `f (q' i) - f (p i)` within `\u03b5' i`\n  of the `f`-length of `s i`. -/\n  refine le_antisymm (by { rw \u2190 f.length_Ioc, apply outer_le_length })\n    (le_infi\u2082 $ \u03bb s hs, ennreal.le_of_forall_pos_le_add $ \u03bb \u03b5 \u03b5pos h, _),\n  let \u03b4 := \u03b5 / 2,\n  have \u03b4pos : 0 < (\u03b4 : \u211d\u22650\u221e), by simpa using \u03b5pos.ne',\n  rcases ennreal.exists_pos_sum_of_encodable \u03b4pos.ne' \u2115 with \u27e8\u03b5', \u03b5'0, h\u03b5\u27e9,\n  obtain \u27e8a', ha', aa'\u27e9 : \u2203 a', f a' - f a < \u03b4 \u2227 a < a',\n  { have A : continuous_within_at (\u03bb r, f r - f a) (Ioi a) a,\n    { refine continuous_within_at.sub _ continuous_within_at_const,\n      exact (f.right_continuous a).mono Ioi_subset_Ici_self },\n    have B : f a - f a < \u03b4, by rwa [sub_self, nnreal.coe_pos, \u2190 ennreal.coe_pos],\n    exact (((tendsto_order.1 A).2 _ B).and self_mem_nhds_within).exists },\n  have : \u2200 i, \u2203 p:\u211d\u00d7\u211d, s i \u2286 Ioo p.1 p.2 \u2227\n                        (of_real (f p.2 - f p.1) : \u211d\u22650\u221e) < f.length (s i) + \u03b5' i,\n  { intro i,\n    have := (ennreal.lt_add_right ((ennreal.le_tsum i).trans_lt h).ne\n        (ennreal.coe_ne_zero.2 (\u03b5'0 i).ne')),\n    conv at this { to_lhs, rw length },\n    simp only [infi_lt_iff, exists_prop] at this,\n    rcases this with \u27e8p, q', spq, hq'\u27e9,\n    have : continuous_within_at (\u03bb r, of_real (f r - f p)) (Ioi q') q',\n    { apply ennreal.continuous_of_real.continuous_at.comp_continuous_within_at,\n      refine continuous_within_at.sub _ continuous_within_at_const,\n      exact (f.right_continuous q').mono Ioi_subset_Ici_self },\n    rcases (((tendsto_order.1 this).2 _ hq').and self_mem_nhds_within).exists with \u27e8q, hq, q'q\u27e9,\n    exact \u27e8\u27e8p, q\u27e9, spq.trans (Ioc_subset_Ioo_right q'q), hq\u27e9 },\n  choose g hg using this,\n  have I_subset : Icc a' b \u2286 \u22c3 i, Ioo (g i).1 (g i).2 := calc\n    Icc a' b \u2286 Ioc a b : \u03bb x hx, \u27e8aa'.trans_le hx.1, hx.2\u27e9\n    ... \u2286 \u22c3 i, s i : hs\n    ... \u2286 \u22c3 i, Ioo (g i).1 (g i).2 : Union_mono (\u03bb i, (hg i).1),\n  calc of_real (f b - f a)\n      = of_real ((f b - f a') + (f a' - f a)) : by rw sub_add_sub_cancel\n  ... \u2264 of_real (f b - f a') + of_real (f a' - f a) : ennreal.of_real_add_le\n  ... \u2264 (\u2211' i, of_real (f (g i).2 - f (g i).1)) + of_real \u03b4 :\n    add_le_add (f.length_subadditive_Icc_Ioo I_subset) (ennreal.of_real_le_of_real ha'.le)\n  ... \u2264 (\u2211' i, (f.length (s i) + \u03b5' i)) + \u03b4 :\n    add_le_add (ennreal.tsum_le_tsum (\u03bb i, (hg i).2.le))\n      (by simp only [ennreal.of_real_coe_nnreal, le_rfl])\n  ... = (\u2211' i, f.length (s i)) + (\u2211' i, \u03b5' i) + \u03b4 : by rw [ennreal.tsum_add]\n  ... \u2264 (\u2211' i, f.length (s i)) + \u03b4 + \u03b4 : add_le_add (add_le_add le_rfl h\u03b5.le) le_rfl\n  ... = \u2211' (i : \u2115), f.length (s i) + \u03b5 : by simp [add_assoc, ennreal.add_halves]\nend\n\nlemma measurable_set_Ioi {c : \u211d} :\n  measurable_set[f.outer.caratheodory] (Ioi c) :=\nbegin\n  apply outer_measure.of_function_caratheodory (\u03bb t, _),\n  refine le_infi (\u03bb a, le_infi (\u03bb b, le_infi (\u03bb h, _))),\n  refine le_trans (add_le_add\n    (f.length_mono $ inter_subset_inter_left _ h)\n    (f.length_mono $ diff_subset_diff_left h)) _,\n  cases le_total a c with hac hac; cases le_total b c with hbc hbc,\n  { simp only [Ioc_inter_Ioi, f.length_Ioc, hac, sup_eq_max, hbc, le_refl, Ioc_eq_empty,\n      max_eq_right, min_eq_left, Ioc_diff_Ioi, f.length_empty, zero_add, not_lt] },\n  { simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right,\n      sup_eq_max, \u2190ennreal.of_real_add, f.mono hac, f.mono hbc, sub_nonneg, sub_add_sub_cancel,\n      le_refl, max_eq_right] },\n  { simp only [hbc, le_refl, Ioc_eq_empty, Ioc_inter_Ioi, min_eq_left, Ioc_diff_Ioi,\n      f.length_empty, zero_add, or_true, le_sup_iff, f.length_Ioc, not_lt] },\n  { simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right,\n      sup_eq_max, le_refl, Ioc_eq_empty, add_zero, max_eq_left, f.length_empty, not_lt] }\nend\n\ntheorem outer_trim : f.outer.trim = f.outer :=\nbegin\n  refine le_antisymm (\u03bb s, _) (outer_measure.le_trim _),\n  rw outer_measure.trim_eq_infi,\n  refine le_infi (\u03bb t, le_infi $ \u03bb ht,\n    ennreal.le_of_forall_pos_le_add $ \u03bb \u03b5 \u03b50 h, _),\n  rcases ennreal.exists_pos_sum_of_encodable\n    (ennreal.coe_pos.2 \u03b50).ne' \u2115 with \u27e8\u03b5', \u03b5'0, h\u03b5\u27e9,\n  refine le_trans _ (add_le_add_left (le_of_lt h\u03b5) _),\n  rw \u2190 ennreal.tsum_add,\n  choose g hg using show\n    \u2200 i, \u2203 s, t i \u2286 s \u2227 measurable_set s \u2227\n      f.outer s \u2264 f.length (t i) + of_real (\u03b5' i),\n  { intro i,\n    have := (ennreal.lt_add_right ((ennreal.le_tsum i).trans_lt h).ne\n        (ennreal.coe_pos.2 (\u03b5'0 i)).ne'),\n    conv at this {to_lhs, rw length},\n    simp only [infi_lt_iff] at this,\n    rcases this with \u27e8a, b, h\u2081, h\u2082\u27e9,\n    rw \u2190 f.outer_Ioc at h\u2082,\n    exact \u27e8_, h\u2081, measurable_set_Ioc, le_of_lt $ by simpa using h\u2082\u27e9 },\n  simp at hg,\n  apply infi_le_of_le (Union g) _,\n  apply infi_le_of_le (ht.trans $ Union_mono (\u03bb i, (hg i).1)) _,\n  apply infi_le_of_le (measurable_set.Union (\u03bb i, (hg i).2.1)) _,\n  exact le_trans (f.outer.Union _) (ennreal.tsum_le_tsum $ \u03bb i, (hg i).2.2)\nend\n\nlemma borel_le_measurable : borel \u211d \u2264 f.outer.caratheodory :=\nbegin\n  rw borel_eq_generate_from_Ioi,\n  refine measurable_space.generate_from_le _,\n  simp [f.measurable_set_Ioi] { contextual := tt }\nend\n\n/-! ### The measure associated to a Stieltjes function -/\n\n/-- The measure associated to a Stieltjes function, giving mass `f b - f a` to the\ninterval `(a, b]`. -/\n@[irreducible] protected def measure : measure \u211d :=\n{ to_outer_measure := f.outer,\n  m_Union := \u03bb s hs, f.outer.Union_eq_of_caratheodory $\n    \u03bb i, f.borel_le_measurable _ (hs i),\n  trimmed := f.outer_trim }\n\n@[simp] lemma measure_Ioc (a b : \u211d) : f.measure (Ioc a b) = of_real (f b - f a) :=\nby { rw stieltjes_function.measure, exact f.outer_Ioc a b }\n\n@[simp] lemma measure_singleton (a : \u211d) : f.measure {a} = of_real (f a - f.left_lim a) :=\nbegin\n  obtain \u27e8u, u_mono, u_lt_a, u_lim\u27e9 : \u2203 (u : \u2115 \u2192 \u211d), strict_mono u \u2227 (\u2200 (n : \u2115), u n < a)\n    \u2227 tendsto u at_top (\ud835\udcdd a) := exists_seq_strict_mono_tendsto a,\n  have A : {a} = \u22c2 n, Ioc (u n) a,\n  { refine subset.antisymm (\u03bb x hx, by simp [mem_singleton_iff.1 hx, u_lt_a]) (\u03bb x hx, _),\n    simp at hx,\n    have : a \u2264 x := le_of_tendsto' u_lim (\u03bb n, (hx n).1.le),\n    simp [le_antisymm this (hx 0).2] },\n  have L1 : tendsto (\u03bb n, f.measure (Ioc (u n) a)) at_top (\ud835\udcdd (f.measure {a})),\n  { rw A,\n    refine tendsto_measure_Inter (\u03bb n, measurable_set_Ioc) (\u03bb m n hmn, _) _,\n    { exact Ioc_subset_Ioc (u_mono.monotone hmn) le_rfl },\n    { exact \u27e80, by simpa only [measure_Ioc] using ennreal.of_real_ne_top\u27e9 } },\n  have L2 : tendsto (\u03bb n, f.measure (Ioc (u n) a)) at_top (\ud835\udcdd (of_real (f a - f.left_lim a))),\n  { simp only [measure_Ioc],\n    have : tendsto (\u03bb n, f (u n)) at_top (\ud835\udcdd (f.left_lim a)),\n    { apply (f.tendsto_left_lim a).comp,\n      exact tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ u_lim\n        (eventually_of_forall (\u03bb n, u_lt_a n)) },\n    exact ennreal.continuous_of_real.continuous_at.tendsto.comp (tendsto_const_nhds.sub this) },\n  exact tendsto_nhds_unique L1 L2\nend\n\n@[simp] lemma measure_Icc (a b : \u211d) : f.measure (Icc a b) = of_real (f b - f.left_lim a) :=\nbegin\n  rcases le_or_lt a b with hab|hab,\n  { have A : disjoint {a} (Ioc a b), by simp,\n    simp [\u2190 Icc_union_Ioc_eq_Icc le_rfl hab, -singleton_union, \u2190 ennreal.of_real_add, f.left_lim_le,\n      measure_union A measurable_set_Ioc, f.mono hab] },\n  { simp only [hab, measure_empty, Icc_eq_empty, not_le],\n    symmetry,\n    simp [ennreal.of_real_eq_zero, f.le_left_lim hab] }\nend\n\n@[simp] lemma measure_Ioo {a b : \u211d} : f.measure (Ioo a b) = of_real (f.left_lim b - f a) :=\nbegin\n  rcases le_or_lt b a with hab|hab,\n  { simp only [hab, measure_empty, Ioo_eq_empty, not_lt],\n    symmetry,\n    simp [ennreal.of_real_eq_zero, f.left_lim_le hab] },\n  { have A : disjoint (Ioo a b) {b}, by simp,\n    have D : f b - f a = (f b - f.left_lim b) + (f.left_lim b - f a), by abel,\n    have := f.measure_Ioc a b,\n    simp only [\u2190Ioo_union_Icc_eq_Ioc hab le_rfl, measure_singleton,\n      measure_union A (measurable_set_singleton b), Icc_self] at this,\n    rw [D, ennreal.of_real_add, add_comm] at this,\n    { simpa only [ennreal.add_right_inj ennreal.of_real_ne_top] },\n    { simp only [f.left_lim_le, sub_nonneg] },\n    { simp only [f.le_left_lim hab, sub_nonneg] } },\nend\n\n@[simp] \n\nend stieltjes_function\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/measure_theory/measure/stieltjes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7372707041183042}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.mean_inequalities\nimport analysis.mean_inequalities_pow\nimport analysis.normed.group.pointwise\nimport topology.algebra.order.liminf_limsup\n\n/-!\n# \u2113p space\n\nThis file describes properties of elements `f` of a pi-type `\u03a0 i, E i` with finite \"norm\",\ndefined for `p:\u211d\u22650\u221e` as the size of the support of `f` if `p=0`, `(\u2211' a, \u2225f a\u2225^p) ^ (1/p)` for\n`0 < p < \u221e` and `\u2a06 a, \u2225f a\u2225` for `p=\u221e`.\n\nThe Prop-valued `mem_\u2113p f p` states that a function `f : \u03a0 i, E i` has finite norm according\nto the above definition; that is, `f` has finite support if `p = 0`, `summable (\u03bb a, \u2225f a\u2225^p)` if\n`0 < p < \u221e`, and `bdd_above (norm '' (set.range f))` if `p = \u221e`.\n\nThe space `lp E p` is the subtype of elements of `\u03a0 i : \u03b1, E i` which satisfy `mem_\u2113p f p`. For\n`1 \u2264 p`, the \"norm\" is genuinely a norm and `lp` is a complete metric space.\n\n## Main definitions\n\n* `mem_\u2113p f p` : property that the function `f` satisfies, as appropriate, `f` finitely supported\n  if `p = 0`, `summable (\u03bb a, \u2225f a\u2225^p)` if `0 < p < \u221e`, and `bdd_above (norm '' (set.range f))` if\n  `p = \u221e`\n* `lp E p` : elements of `\u03a0 i : \u03b1, E i` such that `mem_\u2113p f p`. Defined as an `add_subgroup` of\n  a type synonym `pre_lp` for `\u03a0 i : \u03b1, E i`, and equipped with a `normed_group` structure; also\n  equipped with `normed_space \ud835\udd5c` and `complete_space` instances under appropriate conditions\n\n## Main results\n\n* `mem_\u2113p.of_exponent_ge`: For `q \u2264 p`, a function which is `mem_\u2113p` for `q` is also `mem_\u2113p` for\n  `p`\n* `lp.mem_\u2113p_of_tendsto`, `lp.norm_le_of_tendsto`: A pointwise limit of functions in `lp`, all with\n  `lp` norm `\u2264 C`, is itself in `lp` and has `lp` norm `\u2264 C`.\n* `lp.tsum_mul_le_mul_norm`: basic form of H\u00f6lder's inequality\n\n## Implementation\n\nSince `lp` is defined as an `add_subgroup`, dot notation does not work. Use `lp.norm_neg f` to\nsay that `\u2225-f\u2225 = \u2225f\u2225`, instead of the non-working `f.norm_neg`.\n\n## TODO\n\n* More versions of H\u00f6lder's inequality (for example: the case `p = 1`, `q = \u221e`; a version for normed\n  rings which has `\u2225\u2211' i, f i * g i\u2225` rather than `\u2211' i, \u2225f i\u2225 * g i\u2225` on the RHS; a version for\n  three exponents satisfying `1 / r = 1 / p + 1 / q`)\n* Equivalence with `pi_Lp`, for `\u03b1` finite\n* Equivalence with `measure_theory.Lp`, for `f : \u03b1 \u2192 E` (i.e., functions rather than pi-types) and\n  the counting measure on `\u03b1`\n* Equivalence with `bounded_continuous_function`, for `f : \u03b1 \u2192 E` (i.e., functions rather than\n  pi-types) and `p = \u221e`, and the discrete topology on `\u03b1`\n\n-/\n\nnoncomputable theory\nopen_locale nnreal ennreal big_operators\n\nvariables {\u03b1 : Type*} {E : \u03b1 \u2192 Type*} {p q : \u211d\u22650\u221e} [\u03a0 i, normed_group (E i)]\n\n/-!\n### `mem_\u2113p` predicate\n\n-/\n\n/-- The property that `f : \u03a0 i : \u03b1, E i`\n* is finitely supported, if `p = 0`, or\n* admits an upper bound for `set.range (\u03bb i, \u2225f i\u2225)`, if `p = \u221e`, or\n* has the series `\u2211' i, \u2225f i\u2225 ^ p` be summable, if `0 < p < \u221e`. -/\ndef mem_\u2113p (f : \u03a0 i, E i) (p : \u211d\u22650\u221e) : Prop :=\nif p = 0 then (set.finite {i | f i \u2260 0}) else\n  (if p = \u221e then bdd_above (set.range (\u03bb i, \u2225f i\u2225)) else summable (\u03bb i, \u2225f i\u2225 ^ p.to_real))\n\nlemma mem_\u2113p_zero_iff {f : \u03a0 i, E i} : mem_\u2113p f 0 \u2194 set.finite {i | f i \u2260 0} :=\nby dsimp [mem_\u2113p]; rw [if_pos rfl]\n\nlemma mem_\u2113p_zero {f : \u03a0 i, E i} (hf : set.finite {i | f i \u2260 0}) : mem_\u2113p f 0 :=\nmem_\u2113p_zero_iff.2 hf\n\nlemma mem_\u2113p_infty_iff {f : \u03a0 i, E i} : mem_\u2113p f \u221e \u2194 bdd_above (set.range (\u03bb i, \u2225f i\u2225)) :=\nby dsimp [mem_\u2113p]; rw [if_neg ennreal.top_ne_zero, if_pos rfl]\n\nlemma mem_\u2113p_infty {f : \u03a0 i, E i} (hf : bdd_above (set.range (\u03bb i, \u2225f i\u2225))) : mem_\u2113p f \u221e :=\nmem_\u2113p_infty_iff.2 hf\n\nlemma mem_\u2113p_gen_iff (hp : 0 < p.to_real) {f : \u03a0 i, E i} :\n  mem_\u2113p f p \u2194 summable (\u03bb i, \u2225f i\u2225 ^ p.to_real) :=\nbegin\n  rw ennreal.to_real_pos_iff at hp,\n  dsimp [mem_\u2113p],\n  rw [if_neg hp.1.ne', if_neg hp.2.ne],\nend\n\nlemma mem_\u2113p_gen {f : \u03a0 i, E i} (hf : summable (\u03bb i, \u2225f i\u2225 ^ p.to_real)) :\n  mem_\u2113p f p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    have H : summable (\u03bb i : \u03b1, (1:\u211d)) := by simpa using hf,\n    exact (finite_of_summable_const (by norm_num) H).subset (set.subset_univ _) },\n  { apply mem_\u2113p_infty,\n    have H : summable (\u03bb i : \u03b1, (1:\u211d)) := by simpa using hf,\n    simpa using ((finite_of_summable_const (by norm_num) H).image (\u03bb i, \u2225f i\u2225)).bdd_above },\n  exact (mem_\u2113p_gen_iff hp).2 hf\nend\n\nlemma mem_\u2113p_gen' {C : \u211d} {f : \u03a0 i, E i} (hf : \u2200 s : finset \u03b1, \u2211 i in s, \u2225f i\u2225 ^ p.to_real \u2264 C) :\n  mem_\u2113p f p :=\nbegin\n  apply mem_\u2113p_gen,\n  use \u2a06 s : finset \u03b1, \u2211 i in s, \u2225f i\u2225 ^ p.to_real,\n  apply has_sum_of_is_lub_of_nonneg,\n  { intros b,\n    exact real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  apply is_lub_csupr,\n  use C,\n  rintros - \u27e8s, rfl\u27e9,\n  exact hf s\nend\n\nlemma zero_mem_\u2113p : mem_\u2113p (0 : \u03a0 i, E i) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    simp },\n  { apply mem_\u2113p_infty,\n    simp only [norm_zero, pi.zero_apply],\n    exact bdd_above_singleton.mono set.range_const_subset, },\n  { apply mem_\u2113p_gen,\n    simp [real.zero_rpow hp.ne', summable_zero], }\nend\n\nlemma zero_mem_\u2113p' : mem_\u2113p (\u03bb i : \u03b1, (0 : E i)) p := zero_mem_\u2113p\n\nnamespace mem_\u2113p\n\nlemma finite_dsupport {f : \u03a0 i, E i} (hf : mem_\u2113p f 0) : set.finite {i | f i \u2260 0} :=\nmem_\u2113p_zero_iff.1 hf\n\nlemma bdd_above {f : \u03a0 i, E i} (hf : mem_\u2113p f \u221e) : bdd_above (set.range (\u03bb i, \u2225f i\u2225)) :=\nmem_\u2113p_infty_iff.1 hf\n\nlemma summable (hp : 0 < p.to_real) {f : \u03a0 i, E i} (hf : mem_\u2113p f p) :\n  summable (\u03bb i, \u2225f i\u2225 ^ p.to_real) :=\n(mem_\u2113p_gen_iff hp).1 hf\n\nlemma neg {f : \u03a0 i, E i} (hf : mem_\u2113p f p) : mem_\u2113p (-f) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    simp [hf.finite_dsupport] },\n  { apply mem_\u2113p_infty,\n    simpa using hf.bdd_above },\n  { apply mem_\u2113p_gen,\n    simpa using hf.summable hp },\nend\n\n@[simp] lemma neg_iff {f : \u03a0 i, E i} : mem_\u2113p (-f) p \u2194 mem_\u2113p f p :=\n\u27e8\u03bb h, neg_neg f \u25b8 h.neg, mem_\u2113p.neg\u27e9\n\nlemma of_exponent_ge {p q : \u211d\u22650\u221e} {f : \u03a0 i, E i}\n  (hfq : mem_\u2113p f q) (hpq : q \u2264 p) :\n  mem_\u2113p f p :=\nbegin\n  rcases ennreal.trichotomy\u2082 hpq with \u27e8rfl, rfl\u27e9 | \u27e8rfl, rfl\u27e9 | \u27e8rfl, hp\u27e9 | \u27e8rfl, rfl\u27e9 | \u27e8hq, rfl\u27e9\n    | \u27e8hq, hp, hpq'\u27e9,\n  { exact hfq },\n  { apply mem_\u2113p_infty,\n    obtain \u27e8C, hC\u27e9 := (hfq.finite_dsupport.image (\u03bb i, \u2225f i\u2225)).bdd_above,\n    use max 0 C,\n    rintros x \u27e8i, rfl\u27e9,\n    by_cases hi : f i = 0,\n    { simp [hi] },\n    { exact (hC \u27e8i, hi, rfl\u27e9).trans (le_max_right _ _) } },\n  { apply mem_\u2113p_gen,\n    have : \u2200 i \u2209 hfq.finite_dsupport.to_finset, \u2225f i\u2225 ^ p.to_real = 0,\n    { intros i hi,\n      have : f i = 0 := by simpa using hi,\n      simp [this, real.zero_rpow hp.ne'] },\n    exact summable_of_ne_finset_zero this },\n  { exact hfq },\n  { apply mem_\u2113p_infty,\n    obtain \u27e8A, hA\u27e9 := (hfq.summable hq).tendsto_cofinite_zero.bdd_above_range_of_cofinite,\n    use A ^ (q.to_real\u207b\u00b9),\n    rintros x \u27e8i, rfl\u27e9,\n    have : 0 \u2264 \u2225f i\u2225 ^ q.to_real := real.rpow_nonneg_of_nonneg (norm_nonneg _) _,\n    simpa [\u2190 real.rpow_mul, mul_inv_cancel hq.ne'] using\n      real.rpow_le_rpow this (hA \u27e8i, rfl\u27e9) (inv_nonneg.mpr hq.le) },\n  { apply mem_\u2113p_gen,\n    have hf' := hfq.summable hq,\n    refine summable_of_norm_bounded_eventually _ hf' (@set.finite.subset _ {i | 1 \u2264 \u2225f i\u2225} _ _ _),\n    { have H : {x : \u03b1 | 1 \u2264 \u2225f x\u2225 ^ q.to_real}.finite,\n      { simpa using eventually_lt_of_tendsto_lt (by norm_num : (0:\u211d) < 1)\n          hf'.tendsto_cofinite_zero },\n      exact H.subset (\u03bb i hi, real.one_le_rpow hi hq.le) },\n    { show \u2200 i, \u00ac (|\u2225f i\u2225 ^ p.to_real| \u2264 \u2225f i\u2225 ^ q.to_real) \u2192 1 \u2264 \u2225f i\u2225,\n      intros i hi,\n      have : 0 \u2264 \u2225f i\u2225 ^ p.to_real := real.rpow_nonneg_of_nonneg (norm_nonneg _) p.to_real,\n      simp only [abs_of_nonneg, this] at hi,\n      contrapose! hi,\n      exact real.rpow_le_rpow_of_exponent_ge' (norm_nonneg _) hi.le hq.le hpq' } }\nend\n\nlemma add {f g : \u03a0 i, E i} (hf : mem_\u2113p f p) (hg : mem_\u2113p g p) : mem_\u2113p (f + g) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    refine (hf.finite_dsupport.union hg.finite_dsupport).subset (\u03bb i, _),\n    simp only [pi.add_apply, ne.def, set.mem_union_eq, set.mem_set_of_eq],\n    contrapose!,\n    rintros \u27e8hf', hg'\u27e9,\n    simp [hf', hg'] },\n  { apply mem_\u2113p_infty,\n    obtain \u27e8A, hA\u27e9 := hf.bdd_above,\n    obtain \u27e8B, hB\u27e9 := hg.bdd_above,\n    refine \u27e8A + B, _\u27e9,\n    rintros a \u27e8i, rfl\u27e9,\n    exact le_trans (norm_add_le _ _) (add_le_add (hA \u27e8i, rfl\u27e9) (hB \u27e8i, rfl\u27e9)) },\n  apply mem_\u2113p_gen,\n  let C : \u211d := if p.to_real < 1 then 1 else 2 ^ (p.to_real - 1),\n  refine summable_of_nonneg_of_le _ (\u03bb i, _) (((hf.summable hp).add (hg.summable hp)).mul_left C),\n  { exact \u03bb b, real.rpow_nonneg_of_nonneg (norm_nonneg (f b + g b)) p.to_real },\n  { refine (real.rpow_le_rpow (norm_nonneg _) (norm_add_le _ _) hp.le).trans _,\n    dsimp [C],\n    split_ifs with h h,\n    { simpa using nnreal.coe_le_coe.2 (nnreal.rpow_add_le_add_rpow (\u2225f i\u2225\u208a) (\u2225g i\u2225\u208a) hp h.le) },\n    { let F : fin 2 \u2192 \u211d\u22650 := ![\u2225f i\u2225\u208a, \u2225g i\u2225\u208a],\n      have : \u2200 i, (0:\u211d) \u2264 F i := \u03bb i, (F i).coe_nonneg,\n      simp only [not_lt] at h,\n      simpa [F, fin.sum_univ_succ] using\n        real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (finset.univ : finset (fin 2)) h\n        (\u03bb i _, (F i).coe_nonneg) } }\nend\n\nlemma sub {f g : \u03a0 i, E i} (hf : mem_\u2113p f p) (hg : mem_\u2113p g p) : mem_\u2113p (f - g) p :=\nby { rw sub_eq_add_neg, exact hf.add hg.neg }\n\nlemma finset_sum {\u03b9} (s : finset \u03b9) {f : \u03b9 \u2192 \u03a0 i, E i} (hf : \u2200 i \u2208 s, mem_\u2113p (f i) p) :\n  mem_\u2113p (\u03bb a, \u2211 i in s, f i a) p :=\nbegin\n  haveI : decidable_eq \u03b9 := classical.dec_eq _,\n  revert hf,\n  refine finset.induction_on s _ _,\n  { simp only [zero_mem_\u2113p', finset.sum_empty, implies_true_iff], },\n  { intros i s his ih hf,\n    simp only [his, finset.sum_insert, not_false_iff],\n    exact (hf i (s.mem_insert_self i)).add (ih (\u03bb j hj, hf j (finset.mem_insert_of_mem hj))), },\nend\n\nsection normed_space\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [\u03a0 i, normed_space \ud835\udd5c (E i)]\n\nlemma const_smul {f : \u03a0 i, E i} (hf : mem_\u2113p f p) (c : \ud835\udd5c) : mem_\u2113p (c \u2022 f) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    refine hf.finite_dsupport.subset (\u03bb i, (_ : \u00acc \u2022 f i = 0 \u2192 \u00acf i = 0)),\n    exact not_imp_not.mpr (\u03bb hf', hf'.symm \u25b8 (smul_zero c)) },\n  { obtain \u27e8A, hA\u27e9 := hf.bdd_above,\n    refine mem_\u2113p_infty \u27e8\u2225c\u2225 * A, _\u27e9,\n    rintros a \u27e8i, rfl\u27e9,\n    simpa [norm_smul] using mul_le_mul_of_nonneg_left (hA \u27e8i, rfl\u27e9) (norm_nonneg c) },\n  { apply mem_\u2113p_gen,\n    convert (hf.summable hp).mul_left (\u2225c\u2225 ^ p.to_real),\n    ext i,\n    simp [norm_smul, real.mul_rpow (norm_nonneg c) (norm_nonneg (f i))] },\nend\n\nlemma const_mul {f : \u03b1 \u2192 \ud835\udd5c} (hf : mem_\u2113p f p) (c : \ud835\udd5c) : mem_\u2113p (\u03bb x, c * f x) p :=\n@mem_\u2113p.const_smul \u03b1 (\u03bb i, \ud835\udd5c) _ _ \ud835\udd5c _ _ _ hf c\n\nend normed_space\n\nend mem_\u2113p\n\n/-!\n### lp space\n\nThe space of elements of `\u03a0 i, E i` satisfying the predicate `mem_\u2113p`.\n-/\n\n/-- We define `pre_lp E` to be a type synonym for `\u03a0 i, E i` which, importantly, does not inherit\nthe `pi` topology on `\u03a0 i, E i` (otherwise this topology would descend to `lp E p` and conflict\nwith the normed group topology we will later equip it with.)\n\nWe choose to deal with this issue by making a type synonym for `\u03a0 i, E i` rather than for the `lp`\nsubgroup itself, because this allows all the spaces `lp E p` (for varying `p`) to be subgroups of\nthe same ambient group, which permits lemma statements like `lp.monotone` (below). -/\n@[derive add_comm_group, nolint unused_arguments]\ndef pre_lp (E : \u03b1 \u2192 Type*) [\u03a0 i, normed_group (E i)] : Type* := \u03a0 i, E i\n\ninstance pre_lp.unique [is_empty \u03b1] : unique (pre_lp E) := pi.unique_of_is_empty E\n\n/-- lp space -/\ndef lp (E : \u03b1 \u2192 Type*) [\u03a0 i, normed_group (E i)]\n  (p : \u211d\u22650\u221e) : add_subgroup (pre_lp E) :=\n{ carrier := {f | mem_\u2113p f p},\n  zero_mem' := zero_mem_\u2113p,\n  add_mem' := \u03bb f g, mem_\u2113p.add,\n  neg_mem' := \u03bb f, mem_\u2113p.neg }\n\nnamespace lp\n\ninstance : has_coe (lp E p) (\u03a0 i, E i) := coe_subtype\ninstance : has_coe_to_fun (lp E p) (\u03bb _, \u03a0 i, E i) := \u27e8\u03bb f, ((f : \u03a0 i, E i) : \u03a0 i, E i)\u27e9\n\n@[ext] lemma ext {f g : lp E p} (h : (f : \u03a0 i, E i) = g) : f = g :=\nsubtype.ext h\n\nprotected lemma ext_iff {f g : lp E p} : f = g \u2194 (f : \u03a0 i, E i) = g :=\nsubtype.ext_iff\n\nlemma eq_zero' [is_empty \u03b1] (f : lp E p) : f = 0 := subsingleton.elim f 0\n\nprotected lemma monotone {p q : \u211d\u22650\u221e} (hpq : q \u2264 p) : lp E q \u2264 lp E p :=\n\u03bb f hf, mem_\u2113p.of_exponent_ge hf hpq\n\nprotected lemma mem_\u2113p (f : lp E p) : mem_\u2113p f p := f.prop\n\nvariables (E p)\n@[simp] lemma coe_fn_zero : \u21d1(0 : lp E p) = 0 := rfl\nvariables {E p}\n\n@[simp] lemma coe_fn_neg (f : lp E p) : \u21d1(-f) = -f := rfl\n\n@[simp] lemma coe_fn_add (f g : lp E p) : \u21d1(f + g) = f + g := rfl\n\n@[simp] lemma coe_fn_sum {\u03b9 : Type*} (f : \u03b9 \u2192 lp E p) (s : finset \u03b9) :\n  \u21d1(\u2211 i in s, f i) = \u2211 i in s, \u21d1(f i) :=\nbegin\n  classical,\n  refine finset.induction _ _ s,\n  { simp },\n  intros i s his,\n  simp [finset.sum_insert his],\nend\n\n@[simp] lemma coe_fn_sub (f g : lp E p) : \u21d1(f - g) = f - g := rfl\n\ninstance : has_norm (lp E p) :=\n{ norm := \u03bb f, if hp : p = 0 then by subst hp; exact (lp.mem_\u2113p f).finite_dsupport.to_finset.card\n   else (if p = \u221e then \u2a06 i, \u2225f i\u2225 else (\u2211' i, \u2225f i\u2225 ^ p.to_real) ^ (1/p.to_real)) }\n\nlemma norm_eq_card_dsupport (f : lp E 0) : \u2225f\u2225 = (lp.mem_\u2113p f).finite_dsupport.to_finset.card :=\ndif_pos rfl\n\nlemma norm_eq_csupr (f : lp E \u221e) : \u2225f\u2225 = \u2a06 i, \u2225f i\u2225 :=\nbegin\n  dsimp [norm],\n  rw [dif_neg ennreal.top_ne_zero, if_pos rfl]\nend\n\nlemma is_lub_norm [nonempty \u03b1] (f : lp E \u221e) : is_lub (set.range (\u03bb i, \u2225f i\u2225)) \u2225f\u2225 :=\nbegin\n  rw lp.norm_eq_csupr,\n  exact is_lub_csupr (lp.mem_\u2113p f)\nend\n\nlemma norm_eq_tsum_rpow (hp : 0 < p.to_real) (f : lp E p) :\n  \u2225f\u2225 = (\u2211' i, \u2225f i\u2225 ^ p.to_real) ^ (1/p.to_real) :=\nbegin\n  dsimp [norm],\n  rw ennreal.to_real_pos_iff at hp,\n  rw [dif_neg hp.1.ne', if_neg hp.2.ne],\nend\n\nlemma norm_rpow_eq_tsum (hp : 0 < p.to_real) (f : lp E p) :\n  \u2225f\u2225 ^ p.to_real = \u2211' i, \u2225f i\u2225 ^ p.to_real :=\nbegin\n  rw [norm_eq_tsum_rpow hp, \u2190 real.rpow_mul],\n  { field_simp [hp.ne'] },\n  apply tsum_nonneg,\n  intros i,\n  calc (0:\u211d) = 0 ^ p.to_real : by rw real.zero_rpow hp.ne'\n  ... \u2264 _ : real.rpow_le_rpow rfl.le (norm_nonneg (f i)) hp.le\nend\n\nlemma has_sum_norm (hp : 0 < p.to_real) (f : lp E p) :\n  has_sum (\u03bb i, \u2225f i\u2225 ^ p.to_real) (\u2225f\u2225 ^ p.to_real) :=\nbegin\n  rw norm_rpow_eq_tsum hp,\n  exact ((lp.mem_\u2113p f).summable hp).has_sum\nend\n\nlemma norm_nonneg' (f : lp E p) : 0 \u2264 \u2225f\u2225 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport f] },\n  { cases is_empty_or_nonempty \u03b1 with _i _i; resetI,\n    { rw lp.norm_eq_csupr,\n      simp [real.csupr_empty] },\n    inhabit \u03b1,\n    exact (norm_nonneg (f default)).trans ((lp.is_lub_norm f).1 \u27e8default, rfl\u27e9) },\n  { rw lp.norm_eq_tsum_rpow hp f,\n    refine real.rpow_nonneg_of_nonneg (tsum_nonneg _) _,\n    exact \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\nend\n\n@[simp] lemma norm_zero : \u2225(0 : lp E p)\u2225 = 0 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport] },\n  { simp [lp.norm_eq_csupr] },\n  { rw lp.norm_eq_tsum_rpow hp,\n    have hp' : 1 / p.to_real \u2260 0 := one_div_ne_zero hp.ne',\n    simpa [real.zero_rpow hp.ne'] using real.zero_rpow hp' }\nend\n\nlemma norm_eq_zero_iff \u2983f : lp E p\u2984 : \u2225f\u2225 = 0 \u2194 f = 0 :=\nbegin\n  classical,\n  refine \u27e8\u03bb h, _, by { rintros rfl, exact norm_zero }\u27e9,\n  rcases p.trichotomy with rfl | rfl | hp,\n  { ext i,\n    have : {i : \u03b1 | \u00acf i = 0} = \u2205 := by simpa [lp.norm_eq_card_dsupport f] using h,\n    have : (\u00ac (f i = 0)) = false := congr_fun this i,\n    tauto },\n  { cases is_empty_or_nonempty \u03b1 with _i _i; resetI,\n    { simp },\n    have H : is_lub (set.range (\u03bb i, \u2225f i\u2225)) 0,\n    { simpa [h] using lp.is_lub_norm f },\n    ext i,\n    have : \u2225f i\u2225 = 0 := le_antisymm (H.1 \u27e8i, rfl\u27e9) (norm_nonneg _),\n    simpa using this },\n  { have hf : has_sum (\u03bb (i : \u03b1), \u2225f i\u2225 ^ p.to_real) 0,\n    { have := lp.has_sum_norm hp f,\n      rwa [h, real.zero_rpow hp.ne'] at this },\n    have : \u2200 i, 0 \u2264 \u2225f i\u2225 ^ p.to_real := \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _,\n    rw has_sum_zero_iff_of_nonneg this at hf,\n    ext i,\n    have : f i = 0 \u2227 p.to_real \u2260 0,\n    { simpa [real.rpow_eq_zero_iff_of_nonneg (norm_nonneg (f i))] using congr_fun hf i },\n    exact this.1 },\nend\n\nlemma eq_zero_iff_coe_fn_eq_zero {f : lp E p} : f = 0 \u2194 \u21d1f = 0 :=\nby rw [lp.ext_iff, coe_fn_zero]\n\n@[simp] lemma norm_neg \u2983f : lp E p\u2984 : \u2225-f\u2225 = \u2225f\u2225 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport] },\n  { cases is_empty_or_nonempty \u03b1; resetI,\n    { simp [lp.eq_zero' f], },\n    apply (lp.is_lub_norm (-f)).unique,\n    simpa using lp.is_lub_norm f },\n  { suffices : \u2225-f\u2225 ^ p.to_real = \u2225f\u2225 ^ p.to_real,\n    { exact real.rpow_left_inj_on hp.ne' (norm_nonneg' _) (norm_nonneg' _) this },\n    apply (lp.has_sum_norm hp (-f)).unique,\n    simpa using lp.has_sum_norm hp f }\nend\n\ninstance [hp : fact (1 \u2264 p)] : normed_group (lp E p) :=\nnormed_group.of_core _\n{ norm_eq_zero_iff := norm_eq_zero_iff,\n  triangle := \u03bb f g, begin\n    unfreezingI { rcases p.dichotomy with rfl | hp' },\n    { cases is_empty_or_nonempty \u03b1; resetI,\n      { simp [lp.eq_zero' f] },\n      refine (lp.is_lub_norm (f + g)).2 _,\n      rintros x \u27e8i, rfl\u27e9,\n      refine le_trans _ (add_mem_upper_bounds_add (lp.is_lub_norm f).1 (lp.is_lub_norm g).1\n        \u27e8_, _, \u27e8i, rfl\u27e9, \u27e8i, rfl\u27e9, rfl\u27e9),\n      exact norm_add_le (f i) (g i) },\n    { have hp'' : 0 < p.to_real := zero_lt_one.trans_le hp',\n      have hf\u2081 : \u2200 i, 0 \u2264 \u2225f i\u2225 := \u03bb i, norm_nonneg _,\n      have hg\u2081 : \u2200 i, 0 \u2264 \u2225g i\u2225 := \u03bb i, norm_nonneg _,\n      have hf\u2082 := lp.has_sum_norm hp'' f,\n      have hg\u2082 := lp.has_sum_norm hp'' g,\n      -- apply Minkowski's inequality\n      obtain \u27e8C, hC\u2081, hC\u2082, hCfg\u27e9 :=\n        real.Lp_add_le_has_sum_of_nonneg hp' hf\u2081 hg\u2081 (norm_nonneg' _) (norm_nonneg' _) hf\u2082 hg\u2082,\n      refine le_trans _ hC\u2082,\n      rw \u2190 real.rpow_le_rpow_iff (norm_nonneg' (f + g)) hC\u2081 hp'',\n      refine has_sum_le _ (lp.has_sum_norm hp'' (f + g)) hCfg,\n      intros i,\n      exact real.rpow_le_rpow (norm_nonneg _) (norm_add_le _ _) hp''.le },\n  end,\n  norm_neg := norm_neg }\n\n-- TODO: define an `ennreal` version of `is_conjugate_exponent`, and then express this inequality\n-- in a better version which also covers the case `p = 1, q = \u221e`.\n/-- H\u00f6lder inequality -/\nprotected \n\nprotected lemma summable_mul {p q : \u211d\u22650\u221e}\n  (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p) (g : lp E q) :\n  summable (\u03bb i, \u2225f i\u2225 * \u2225g i\u2225) :=\n(lp.tsum_mul_le_mul_norm hpq f g).1\n\nprotected lemma tsum_mul_le_mul_norm' {p q : \u211d\u22650\u221e}\n  (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p) (g : lp E q) :\n  \u2211' i, \u2225f i\u2225 * \u2225g i\u2225 \u2264 \u2225f\u2225 * \u2225g\u2225 :=\n(lp.tsum_mul_le_mul_norm hpq f g).2\n\nsection compare_pointwise\n\nlemma norm_apply_le_norm (hp : p \u2260 0) (f : lp E p) (i : \u03b1) : \u2225f i\u2225 \u2264 \u2225f\u2225 :=\nbegin\n  rcases eq_or_ne p \u221e with rfl | hp',\n  { haveI : nonempty \u03b1 := \u27e8i\u27e9,\n    exact (is_lub_norm f).1 \u27e8i, rfl\u27e9 },\n  have hp'' : 0 < p.to_real := ennreal.to_real_pos hp hp',\n  have : \u2200 i, 0 \u2264 \u2225f i\u2225 ^ p.to_real,\n  { exact \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  rw \u2190 real.rpow_le_rpow_iff (norm_nonneg _) (norm_nonneg' _) hp'',\n  convert le_has_sum (has_sum_norm hp'' f) i (\u03bb i hi, this i),\nend\n\nlemma sum_rpow_le_norm_rpow (hp : 0 < p.to_real) (f : lp E p) (s : finset \u03b1) :\n  \u2211 i in s, \u2225f i\u2225 ^ p.to_real \u2264 \u2225f\u2225 ^ p.to_real :=\nbegin\n  rw lp.norm_rpow_eq_tsum hp f,\n  have : \u2200 i, 0 \u2264 \u2225f i\u2225 ^ p.to_real,\n  { exact \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  refine sum_le_tsum _ (\u03bb i hi, this i) _,\n  exact (lp.mem_\u2113p f).summable hp\nend\n\nlemma norm_le_of_forall_le' [nonempty \u03b1] {f : lp E \u221e} (C : \u211d) (hCf : \u2200 i, \u2225f i\u2225 \u2264 C) : \u2225f\u2225 \u2264 C :=\nbegin\n  refine (is_lub_norm f).2 _,\n  rintros - \u27e8i, rfl\u27e9,\n  exact hCf i,\nend\n\nlemma norm_le_of_forall_le {f : lp E \u221e} {C : \u211d} (hC : 0 \u2264 C) (hCf : \u2200 i, \u2225f i\u2225 \u2264 C) : \u2225f\u2225 \u2264 C :=\nbegin\n  casesI is_empty_or_nonempty \u03b1,\n  { simpa [eq_zero' f] using hC, },\n  { exact norm_le_of_forall_le' C hCf },\nend\n\nlemma norm_le_of_tsum_le (hp : 0 < p.to_real) {C : \u211d} (hC : 0 \u2264 C) {f : lp E p}\n  (hf : \u2211' i, \u2225f i\u2225 ^ p.to_real \u2264 C ^ p.to_real) :\n  \u2225f\u2225 \u2264 C :=\nbegin\n  rw [\u2190 real.rpow_le_rpow_iff (norm_nonneg' _) hC hp, norm_rpow_eq_tsum hp],\n  exact hf,\nend\n\nlemma norm_le_of_forall_sum_le (hp : 0 < p.to_real) {C : \u211d} (hC : 0 \u2264 C) {f : lp E p}\n  (hf : \u2200 s : finset \u03b1, \u2211 i in s, \u2225f i\u2225 ^ p.to_real \u2264 C ^ p.to_real) :\n  \u2225f\u2225 \u2264 C :=\nnorm_le_of_tsum_le hp hC (tsum_le_of_sum_le ((lp.mem_\u2113p f).summable hp) hf)\n\nend compare_pointwise\n\nsection normed_space\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [\u03a0 i, normed_space \ud835\udd5c (E i)]\n\ninstance : module \ud835\udd5c (pre_lp E) := pi.module \u03b1 E \ud835\udd5c\n\nlemma mem_lp_const_smul (c : \ud835\udd5c) (f : lp E p) : c \u2022 (f : pre_lp E) \u2208 lp E p :=\n(lp.mem_\u2113p f).const_smul c\n\nvariables (E p \ud835\udd5c)\n\n/-- The `\ud835\udd5c`-submodule of elements of `\u03a0 i : \u03b1, E i` whose `lp` norm is finite.  This is `lp E p`,\nwith extra structure. -/\ndef lp_submodule : submodule \ud835\udd5c (pre_lp E) :=\n{ smul_mem' := \u03bb c f hf, by simpa using mem_lp_const_smul c \u27e8f, hf\u27e9,\n  .. lp E p }\n\nvariables {E p \ud835\udd5c}\n\nlemma coe_lp_submodule : (lp_submodule E p \ud835\udd5c).to_add_subgroup = lp E p := rfl\n\ninstance : module \ud835\udd5c (lp E p) :=\n{ .. (lp_submodule E p \ud835\udd5c).module }\n\n@[simp] lemma coe_fn_smul (c : \ud835\udd5c) (f : lp E p) : \u21d1(c \u2022 f) = c \u2022 f := rfl\n\nlemma norm_const_smul (hp : p \u2260 0) {c : \ud835\udd5c} (f : lp E p) : \u2225c \u2022 f\u2225 = \u2225c\u2225 * \u2225f\u2225 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { exact absurd rfl hp },\n  { cases is_empty_or_nonempty \u03b1; resetI,\n    { simp [lp.eq_zero' f], },\n    apply (lp.is_lub_norm (c \u2022 f)).unique,\n    convert (lp.is_lub_norm f).mul_left (norm_nonneg c),\n    ext a,\n    simp [coe_fn_smul, norm_smul] },\n  { suffices : \u2225c \u2022 f\u2225 ^ p.to_real = (\u2225c\u2225 * \u2225f\u2225) ^ p.to_real,\n    { refine real.rpow_left_inj_on hp.ne' _ _ this,\n      { exact norm_nonneg' _ },\n      { exact mul_nonneg (norm_nonneg _) (norm_nonneg' _) } },\n    apply (lp.has_sum_norm hp (c \u2022 f)).unique,\n    convert (lp.has_sum_norm hp f).mul_left (\u2225c\u2225 ^ p.to_real),\n    { simp [coe_fn_smul, norm_smul, real.mul_rpow (norm_nonneg c) (norm_nonneg _)] },\n    have hf : 0 \u2264 \u2225f\u2225 := lp.norm_nonneg' f,\n    simp [coe_fn_smul, norm_smul, real.mul_rpow (norm_nonneg c) hf] }\nend\n\ninstance [fact (1 \u2264 p)] : normed_space \ud835\udd5c (lp E p) :=\n{ norm_smul_le := \u03bb c f, begin\n    have hp : 0 < p := ennreal.zero_lt_one.trans_le (fact.out _),\n    simp [norm_const_smul hp.ne']\n  end }\n\nvariables {\ud835\udd5c' : Type*} [normed_field \ud835\udd5c']\n\ninstance [\u03a0 i, normed_space \ud835\udd5c' (E i)] [has_scalar \ud835\udd5c' \ud835\udd5c] [\u03a0 i, is_scalar_tower \ud835\udd5c' \ud835\udd5c (E i)] :\n  is_scalar_tower \ud835\udd5c' \ud835\udd5c (lp E p) :=\nbegin\n  refine \u27e8\u03bb r c f, _\u27e9,\n  ext1,\n  exact (lp.coe_fn_smul _ _).trans (smul_assoc _ _ _)\nend\n\nend normed_space\n\nsection single\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [\u03a0 i, normed_space \ud835\udd5c (E i)]\nvariables [decidable_eq \u03b1]\n\n/-- The element of `lp E p` which is `a : E i` at the index `i`, and zero elsewhere. -/\nprotected def single (p) (i : \u03b1) (a : E i) : lp E p :=\n\u27e8 \u03bb j, if h : j = i then eq.rec a h.symm else 0,\n  begin\n    refine (mem_\u2113p_zero _).of_exponent_ge (zero_le p),\n    refine (set.finite_singleton i).subset _,\n    intros j,\n    simp only [forall_exists_index, set.mem_singleton_iff, ne.def, dite_eq_right_iff,\n      set.mem_set_of_eq, not_forall],\n    rintros rfl,\n    simp,\n  end \u27e9\n\nprotected lemma single_apply (p) (i : \u03b1) (a : E i) (j : \u03b1) :\n  lp.single p i a j = if h : j = i then eq.rec a h.symm else 0 :=\nrfl\n\nprotected lemma single_apply_self (p) (i : \u03b1) (a : E i) :\n  lp.single p i a i = a :=\nby rw [lp.single_apply, dif_pos rfl]\n\nprotected lemma single_apply_ne (p) (i : \u03b1) (a : E i) {j : \u03b1} (hij : j \u2260 i) :\n  lp.single p i a j = 0 :=\nby rw [lp.single_apply, dif_neg hij]\n\n@[simp] protected lemma single_neg (p) (i : \u03b1) (a : E i) :\n  lp.single p i (- a) = - lp.single p i a :=\nbegin\n  ext j,\n  by_cases hi : j = i,\n  { subst hi,\n    simp [lp.single_apply_self] },\n  { simp [lp.single_apply_ne p i _ hi] }\nend\n\n@[simp] protected lemma single_smul (p) (i : \u03b1) (a : E i) (c : \ud835\udd5c) :\n  lp.single p i (c \u2022 a) = c \u2022 lp.single p i a :=\nbegin\n  ext j,\n  by_cases hi : j = i,\n  { subst hi,\n    simp [lp.single_apply_self] },\n  { simp [lp.single_apply_ne p i _ hi] }\nend\n\nprotected lemma norm_sum_single (hp : 0 < p.to_real) (f : \u03a0 i, E i) (s : finset \u03b1) :\n  \u2225\u2211 i in s, lp.single p i (f i)\u2225 ^ p.to_real = \u2211 i in s, \u2225f i\u2225 ^ p.to_real :=\nbegin\n  refine (has_sum_norm hp (\u2211 i in s, lp.single p i (f i))).unique _,\n  simp only [lp.single_apply, coe_fn_sum, finset.sum_apply, finset.sum_dite_eq],\n  have h : \u2200 i \u2209 s, \u2225ite (i \u2208 s) (f i) 0\u2225 ^ p.to_real = 0,\n  { intros i hi,\n    simp [if_neg hi, real.zero_rpow hp.ne'], },\n  have h' : \u2200 i \u2208 s, \u2225f i\u2225 ^ p.to_real = \u2225ite (i \u2208 s) (f i) 0\u2225 ^ p.to_real,\n  { intros i hi,\n    rw if_pos hi },\n  simpa [finset.sum_congr rfl h'] using has_sum_sum_of_ne_finset_zero h,\nend\n\nprotected lemma norm_single (hp : 0 < p.to_real) (f : \u03a0 i, E i) (i : \u03b1) :\n  \u2225lp.single p i (f i)\u2225 = \u2225f i\u2225 :=\nbegin\n  refine real.rpow_left_inj_on hp.ne' (norm_nonneg' _) (norm_nonneg _) _,\n  simpa using lp.norm_sum_single hp f {i},\nend\n\nprotected lemma norm_sub_norm_compl_sub_single (hp : 0 < p.to_real) (f : lp E p) (s : finset \u03b1) :\n  \u2225f\u2225 ^ p.to_real - \u2225f - \u2211 i in s, lp.single p i (f i)\u2225 ^ p.to_real = \u2211 i in s, \u2225f i\u2225 ^ p.to_real :=\nbegin\n  refine ((has_sum_norm hp f).sub (has_sum_norm hp (f - \u2211 i in s, lp.single p i (f i)))).unique _,\n  let F : \u03b1 \u2192 \u211d := \u03bb i, \u2225f i\u2225 ^ p.to_real - \u2225(f - \u2211 i in s, lp.single p i (f i)) i\u2225 ^ p.to_real,\n  have hF : \u2200 i \u2209 s, F i = 0,\n  { intros i hi,\n    suffices : \u2225f i\u2225 ^ p.to_real - \u2225f i - ite (i \u2208 s) (f i) 0\u2225 ^ p.to_real = 0,\n    { simpa [F, coe_fn_sum, lp.single_apply] using this, },\n    simp [if_neg hi] },\n  have hF' : \u2200 i \u2208 s, F i = \u2225f i\u2225 ^ p.to_real,\n  { intros i hi,\n    simp [F, coe_fn_sum, lp.single_apply, if_pos hi, real.zero_rpow hp.ne'] },\n  have : has_sum F (\u2211 i in s, F i) := has_sum_sum_of_ne_finset_zero hF,\n  rwa [finset.sum_congr rfl hF'] at this,\nend\n\nprotected lemma norm_compl_sum_single (hp : 0 < p.to_real) (f : lp E p) (s : finset \u03b1) :\n  \u2225f - \u2211 i in s, lp.single p i (f i)\u2225 ^ p.to_real = \u2225f\u2225 ^ p.to_real - \u2211 i in s, \u2225f i\u2225 ^ p.to_real :=\nby linarith [lp.norm_sub_norm_compl_sub_single hp f s]\n\n/-- The canonical finitely-supported approximations to an element `f` of `lp` converge to it, in the\n`lp` topology. -/\nprotected lemma has_sum_single [fact (1 \u2264 p)] (hp : p \u2260 \u22a4) (f : lp E p) :\n  has_sum (\u03bb i : \u03b1, lp.single p i (f i : E i)) f :=\nbegin\n  have hp\u2080 : 0 < p := ennreal.zero_lt_one.trans_le (fact.out _),\n  have hp' : 0 < p.to_real := ennreal.to_real_pos hp\u2080.ne' hp,\n  have := lp.has_sum_norm hp' f,\n  dsimp [has_sum] at this \u22a2,\n  rw metric.tendsto_nhds at this \u22a2,\n  intros \u03b5 h\u03b5,\n  refine (this _ (real.rpow_pos_of_pos h\u03b5 p.to_real)).mono _,\n  intros s hs,\n  rw \u2190 real.rpow_lt_rpow_iff dist_nonneg (le_of_lt h\u03b5) hp',\n  rw dist_comm at hs,\n  simp only [dist_eq_norm, real.norm_eq_abs] at hs \u22a2,\n  have H : \u2225\u2211 i in s, lp.single p i (f i : E i) - f\u2225 ^ p.to_real\n    = \u2225f\u2225 ^ p.to_real - \u2211 i in s, \u2225f i\u2225 ^ p.to_real,\n  { simpa using lp.norm_compl_sum_single hp' (-f) s },\n  rw \u2190 H at hs,\n  have : |\u2225\u2211 i in s, lp.single p i (f i : E i) - f\u2225 ^ p.to_real|\n    = \u2225\u2211 i in s, lp.single p i (f i : E i) - f\u2225 ^ p.to_real,\n  { simp [real.abs_rpow_of_nonneg (norm_nonneg _)] },\n  linarith\nend\n\nend single\n\nsection topology\n\nopen filter\nopen_locale topological_space uniformity\n\n/-- The coercion from `lp E p` to `\u03a0 i, E i` is uniformly continuous. -/\nlemma uniform_continuous_coe [_i : fact (1 \u2264 p)] : uniform_continuous (coe : lp E p \u2192 \u03a0 i, E i) :=\nbegin\n  have hp : p \u2260 0 := (ennreal.zero_lt_one.trans_le _i.elim).ne',\n  rw uniform_continuous_pi,\n  intros i,\n  rw normed_group.uniformity_basis_dist.uniform_continuous_iff normed_group.uniformity_basis_dist,\n  intros \u03b5 h\u03b5,\n  refine \u27e8\u03b5, h\u03b5, _\u27e9,\n  rintros f g (hfg : \u2225f - g\u2225 < \u03b5),\n  have : \u2225f i - g i\u2225 \u2264 \u2225f - g\u2225 := norm_apply_le_norm hp (f - g) i,\n  exact this.trans_lt hfg,\nend\n\nvariables {\u03b9 : Type*} {l : filter \u03b9} [filter.ne_bot l]\n\nlemma norm_apply_le_of_tendsto {C : \u211d} {F : \u03b9 \u2192 lp E \u221e} (hCF : \u2200\u1da0 k in l, \u2225F k\u2225 \u2264 C)\n  {f : \u03a0 a, E a} (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) (a : \u03b1) :\n  \u2225f a\u2225 \u2264 C :=\nbegin\n  have : tendsto (\u03bb k, \u2225F k a\u2225) l (\ud835\udcdd \u2225f a\u2225) :=\n    (tendsto.comp (continuous_apply a).continuous_at hf).norm,\n  refine le_of_tendsto this (hCF.mono _),\n  intros k hCFk,\n  exact (norm_apply_le_norm ennreal.top_ne_zero (F k) a).trans hCFk,\nend\n\nvariables [_i : fact (1 \u2264 p)]\n\ninclude _i\n\nlemma sum_rpow_le_of_tendsto (hp : p \u2260 \u221e) {C : \u211d} {F : \u03b9 \u2192 lp E p} (hCF : \u2200\u1da0 k in l, \u2225F k\u2225 \u2264 C)\n  {f : \u03a0 a, E a} (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) (s : finset \u03b1) :\n  \u2211 (i : \u03b1) in s, \u2225f i\u2225 ^ p.to_real \u2264 C ^ p.to_real :=\nbegin\n  have hp' : p \u2260 0 := (ennreal.zero_lt_one.trans_le _i.elim).ne',\n  have hp'' : 0 < p.to_real := ennreal.to_real_pos hp' hp,\n  let G : (\u03a0 a, E a) \u2192 \u211d := \u03bb f, \u2211 a in s, \u2225f a\u2225 ^ p.to_real,\n  have hG : continuous G,\n  { refine continuous_finset_sum s _,\n    intros a ha,\n    have : continuous (\u03bb f : \u03a0 a, E a, f a):= continuous_apply a,\n    exact this.norm.rpow_const (\u03bb _, or.inr hp''.le) },\n  refine le_of_tendsto (hG.continuous_at.tendsto.comp hf) _,\n  refine hCF.mono _,\n  intros k hCFk,\n  refine (lp.sum_rpow_le_norm_rpow hp'' (F k) s).trans _,\n  exact real.rpow_le_rpow (norm_nonneg _) hCFk hp''.le,\nend\n\n/-- \"Semicontinuity of the `lp` norm\": If all sufficiently large elements of a sequence in `lp E p`\n have `lp` norm `\u2264 C`, then the pointwise limit, if it exists, also has `lp` norm `\u2264 C`. -/\nlemma norm_le_of_tendsto {C : \u211d} {F : \u03b9 \u2192 lp E p} (hCF : \u2200\u1da0 k in l, \u2225F k\u2225 \u2264 C) {f : lp E p}\n  (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) :\n  \u2225f\u2225 \u2264 C :=\nbegin\n  obtain \u27e8i, hi\u27e9 := hCF.exists,\n  have hC : 0 \u2264 C := (norm_nonneg _).trans hi,\n  unfreezingI { rcases eq_top_or_lt_top p with rfl | hp },\n  { apply norm_le_of_forall_le hC,\n    exact norm_apply_le_of_tendsto hCF hf, },\n  { have : 0 < p := ennreal.zero_lt_one.trans_le _i.elim,\n    have hp' : 0 < p.to_real := ennreal.to_real_pos this.ne' hp.ne,\n    apply norm_le_of_forall_sum_le hp' hC,\n    exact sum_rpow_le_of_tendsto hp.ne hCF hf, }\nend\n\n/-- If `f` is the pointwise limit of a bounded sequence in `lp E p`, then `f` is in `lp E p`. -/\nlemma mem_\u2113p_of_tendsto {F : \u03b9 \u2192 lp E p} (hF : metric.bounded (set.range F)) {f : \u03a0 a, E a}\n  (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) :\n  mem_\u2113p f p :=\nbegin\n  obtain \u27e8C, hC, hCF'\u27e9 := hF.exists_pos_norm_le,\n  have hCF : \u2200 k, \u2225F k\u2225 \u2264 C := \u03bb k, hCF' _ \u27e8k, rfl\u27e9,\n  unfreezingI { rcases eq_top_or_lt_top p with rfl | hp },\n  { apply mem_\u2113p_infty,\n    use C,\n    rintros _ \u27e8a, rfl\u27e9,\n    refine norm_apply_le_of_tendsto (eventually_of_forall hCF) hf a, },\n  { apply mem_\u2113p_gen',\n    exact sum_rpow_le_of_tendsto hp.ne (eventually_of_forall hCF) hf },\nend\n\n/-- If a sequence is Cauchy in the `lp E p` topology and pointwise convergent to a element `f` of\n`lp E p`, then it converges to `f` in the `lp E p` topology. -/\nlemma tendsto_lp_of_tendsto_pi {F : \u2115 \u2192 lp E p} (hF : cauchy_seq F) {f : lp E p}\n  (hf : tendsto (id (\u03bb i, F i) : \u2115 \u2192 \u03a0 a, E a) at_top (\ud835\udcdd f)) :\n  tendsto F at_top (\ud835\udcdd f) :=\nbegin\n  rw metric.nhds_basis_closed_ball.tendsto_right_iff,\n  intros \u03b5 h\u03b5,\n  have h\u03b5' : {p : (lp E p) \u00d7 (lp E p) | \u2225p.1 - p.2\u2225 < \u03b5} \u2208 \ud835\udce4 (lp E p),\n  { exact normed_group.uniformity_basis_dist.mem_of_mem h\u03b5 },\n  refine (hF.eventually_eventually h\u03b5').mono _,\n  rintros n (hn : \u2200\u1da0 l in at_top, \u2225(\u03bb f, F n - f) (F l)\u2225 < \u03b5),\n  refine norm_le_of_tendsto (hn.mono (\u03bb k hk, hk.le)) _,\n  rw tendsto_pi_nhds,\n  intros a,\n  exact (hf.apply a).const_sub (F n a),\nend\n\nvariables [\u03a0 a, complete_space (E a)]\n\ninstance : complete_space (lp E p) :=\nmetric.complete_of_cauchy_seq_tendsto\nbegin\n  intros F hF,\n  -- A Cauchy sequence in `lp E p` is pointwise convergent; let `f` be the pointwise limit.\n  obtain \u27e8f, hf\u27e9 := cauchy_seq_tendsto_of_complete (uniform_continuous_coe.comp_cauchy_seq hF),\n  -- Since the Cauchy sequence is bounded, its pointwise limit `f` is in `lp E p`.\n  have hf' : mem_\u2113p f p := mem_\u2113p_of_tendsto hF.bounded_range hf,\n  -- And therefore `f` is its limit in the `lp E p` topology as well as pointwise.\n  exact \u27e8\u27e8f, hf'\u27e9, tendsto_lp_of_tendsto_pi hF hf\u27e9\nend\n\nend topology\n\nend lp\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/normed_space/lp_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856298, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7372689294912796}}
{"text": "/-\nCopyright (c) 2018 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nIsometries of emetric and metric spaces\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module topology.metric_space.isometry\n! leanprover-community/mathlib commit 69c6a5a12d8a2b159f20933e60115a4f2de62b58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.MetricSpace.Antilipschitz\n\n/-!\n# Isometries\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define isometries, i.e., maps between emetric spaces that preserve\nthe edistance (on metric spaces, these are exactly the maps that preserve distances),\nand prove their basic properties. We also introduce isometric bijections.\n\nSince a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the\ntheory for `pseudo_metric_space` and we specialize to `metric_space` when needed.\n-/\n\n\nnoncomputable section\n\nuniverse u v w\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nopen Function Set\n\nopen Topology ENNReal\n\n#print Isometry /-\n/-- An isometry (also known as isometric embedding) is a map preserving the edistance\nbetween pseudoemetric spaces, or equivalently the distance between pseudometric space.  -/\ndef Isometry [PseudoEMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n  \u2200 x1 x2 : \u03b1, edist (f x1) (f x2) = edist x1 x2\n#align isometry Isometry\n-/\n\n#print isometry_iff_nndist_eq /-\n/-- On pseudometric spaces, a map is an isometry if and only if it preserves nonnegative\ndistances. -/\ntheorem isometry_iff_nndist_eq [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2} :\n    Isometry f \u2194 \u2200 x y, nndist (f x) (f y) = nndist x y := by\n  simp only [Isometry, edist_nndist, ENNReal.coe_eq_coe]\n#align isometry_iff_nndist_eq isometry_iff_nndist_eq\n-/\n\n#print isometry_iff_dist_eq /-\n/-- On pseudometric spaces, a map is an isometry if and only if it preserves distances. -/\ntheorem isometry_iff_dist_eq [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2} :\n    Isometry f \u2194 \u2200 x y, dist (f x) (f y) = dist x y := by\n  simp only [isometry_iff_nndist_eq, \u2190 coe_nndist, NNReal.coe_eq]\n#align isometry_iff_dist_eq isometry_iff_dist_eq\n-/\n\n/-- An isometry preserves distances. -/\nalias isometry_iff_dist_eq \u2194 Isometry.dist_eq _\n#align isometry.dist_eq Isometry.dist_eq\n\n/-- A map that preserves distances is an isometry -/\nalias isometry_iff_dist_eq \u2194 _ Isometry.of_dist_eq\n#align isometry.of_dist_eq Isometry.of_dist_eq\n\n/-- An isometry preserves non-negative distances. -/\nalias isometry_iff_nndist_eq \u2194 Isometry.nndist_eq _\n#align isometry.nndist_eq Isometry.nndist_eq\n\n/-- A map that preserves non-negative distances is an isometry. -/\nalias isometry_iff_nndist_eq \u2194 _ Isometry.of_nndist_eq\n#align isometry.of_nndist_eq Isometry.of_nndist_eq\n\nnamespace Isometry\n\nsection PseudoEmetricIsometry\n\nvariable [PseudoEMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] [PseudoEMetricSpace \u03b3]\n\nvariable {f : \u03b1 \u2192 \u03b2} {x y z : \u03b1} {s : Set \u03b1}\n\n#print Isometry.edist_eq /-\n/-- An isometry preserves edistances. -/\ntheorem edist_eq (hf : Isometry f) (x y : \u03b1) : edist (f x) (f y) = edist x y :=\n  hf x y\n#align isometry.edist_eq Isometry.edist_eq\n-/\n\n#print Isometry.lipschitz /-\ntheorem lipschitz (h : Isometry f) : LipschitzWith 1 f :=\n  LipschitzWith.of_edist_le fun x y => (h x y).le\n#align isometry.lipschitz Isometry.lipschitz\n-/\n\n#print Isometry.antilipschitz /-\ntheorem antilipschitz (h : Isometry f) : AntilipschitzWith 1 f := fun x y => by\n  simp only [h x y, ENNReal.coe_one, one_mul, le_refl]\n#align isometry.antilipschitz Isometry.antilipschitz\n-/\n\n#print isometry_subsingleton /-\n/-- Any map on a subsingleton is an isometry -/\n@[nontriviality]\ntheorem isometry_subsingleton [Subsingleton \u03b1] : Isometry f := fun x y => by\n  rw [Subsingleton.elim x y] <;> simp\n#align isometry_subsingleton isometry_subsingleton\n-/\n\n#print isometry_id /-\n/-- The identity is an isometry -/\ntheorem isometry_id : Isometry (id : \u03b1 \u2192 \u03b1) := fun x y => rfl\n#align isometry_id isometry_id\n-/\n\n/- warning: isometry.prod_map -> Isometry.prod_map is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b3 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] [_inst_3 : PseudoEMetricSpace.{u3} \u03b3] {\u03b4 : Type.{u4}} [_inst_4 : PseudoEMetricSpace.{u4} \u03b4] {f : \u03b1 -> \u03b2} {g : \u03b3 -> \u03b4}, (Isometry.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (Isometry.{u3, u4} \u03b3 \u03b4 _inst_3 _inst_4 g) -> (Isometry.{max u1 u3, max u2 u4} (Prod.{u1, u3} \u03b1 \u03b3) (Prod.{u2, u4} \u03b2 \u03b4) (Prod.pseudoEMetricSpaceMax.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3) (Prod.pseudoEMetricSpaceMax.{u2, u4} \u03b2 \u03b4 _inst_2 _inst_4) (Prod.map.{u1, u2, u3, u4} \u03b1 \u03b2 \u03b3 \u03b4 f g))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {\u03b3 : Type.{u4}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] [_inst_3 : PseudoEMetricSpace.{u4} \u03b3] {\u03b4 : Type.{u1}} [_inst_4 : PseudoEMetricSpace.{u1} \u03b4] {f : \u03b1 -> \u03b2} {g : \u03b3 -> \u03b4}, (Isometry.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (Isometry.{u4, u1} \u03b3 \u03b4 _inst_3 _inst_4 g) -> (Isometry.{max u4 u2, max u1 u3} (Prod.{u2, u4} \u03b1 \u03b3) (Prod.{u3, u1} \u03b2 \u03b4) (Prod.pseudoEMetricSpaceMax.{u2, u4} \u03b1 \u03b3 _inst_1 _inst_3) (Prod.pseudoEMetricSpaceMax.{u3, u1} \u03b2 \u03b4 _inst_2 _inst_4) (Prod.map.{u2, u3, u4, u1} \u03b1 \u03b2 \u03b3 \u03b4 f g))\nCase conversion may be inaccurate. Consider using '#align isometry.prod_map Isometry.prod_map\u2093'. -/\ntheorem prod_map {\u03b4} [PseudoEMetricSpace \u03b4] {f : \u03b1 \u2192 \u03b2} {g : \u03b3 \u2192 \u03b4} (hf : Isometry f)\n    (hg : Isometry g) : Isometry (Prod.map f g) := fun x y => by\n  simp only [Prod.edist_eq, hf.edist_eq, hg.edist_eq, Prod_map]\n#align isometry.prod_map Isometry.prod_map\n\n/- warning: isometry_dcomp -> isometry_dcomp is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} [_inst_4 : Fintype.{u1} \u03b9] {\u03b1 : \u03b9 -> Type.{u2}} {\u03b2 : \u03b9 -> Type.{u3}} [_inst_5 : forall (i : \u03b9), PseudoEMetricSpace.{u2} (\u03b1 i)] [_inst_6 : forall (i : \u03b9), PseudoEMetricSpace.{u3} (\u03b2 i)] (f : forall (i : \u03b9), (\u03b1 i) -> (\u03b2 i)), (forall (i : \u03b9), Isometry.{u2, u3} (\u03b1 i) (\u03b2 i) (_inst_5 i) (_inst_6 i) (f i)) -> (Isometry.{max u1 u2, max u1 u3} (forall (x : \u03b9), \u03b1 x) (forall (x : \u03b9), \u03b2 x) (pseudoEMetricSpacePi.{u1, u2} \u03b9 (fun (x : \u03b9) => \u03b1 x) _inst_4 (fun (b : \u03b9) => _inst_5 b)) (pseudoEMetricSpacePi.{u1, u3} \u03b9 (fun (x : \u03b9) => \u03b2 x) _inst_4 (fun (b : \u03b9) => _inst_6 b)) (Function.dcomp.{succ u1, succ u2, succ u3} \u03b9 (fun (i : \u03b9) => \u03b1 i) (fun (i : \u03b9) (\u1fb0 : \u03b1 i) => \u03b2 i) f))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} [_inst_4 : Fintype.{u3} \u03b9] {\u03b1 : \u03b9 -> Type.{u2}} {\u03b2 : \u03b9 -> Type.{u1}} [_inst_5 : forall (i : \u03b9), PseudoEMetricSpace.{u2} (\u03b1 i)] [_inst_6 : forall (i : \u03b9), PseudoEMetricSpace.{u1} (\u03b2 i)] (f : forall (i : \u03b9), (\u03b1 i) -> (\u03b2 i)), (forall (i : \u03b9), Isometry.{u2, u1} (\u03b1 i) (\u03b2 i) (_inst_5 i) (_inst_6 i) (f i)) -> (Isometry.{max u3 u2, max u3 u1} (forall (x : \u03b9), \u03b1 x) (forall (x : \u03b9), \u03b2 x) (pseudoEMetricSpacePi.{u3, u2} \u03b9 (fun (x : \u03b9) => \u03b1 x) _inst_4 (fun (b : \u03b9) => _inst_5 b)) (pseudoEMetricSpacePi.{u3, u1} \u03b9 (fun (x : \u03b9) => \u03b2 x) _inst_4 (fun (b : \u03b9) => _inst_6 b)) (fun (g : forall (i : \u03b9), \u03b1 i) (i : \u03b9) => f i (g i)))\nCase conversion may be inaccurate. Consider using '#align isometry_dcomp isometry_dcomp\u2093'. -/\ntheorem isometry_dcomp {\u03b9} [Fintype \u03b9] {\u03b1 \u03b2 : \u03b9 \u2192 Type _} [\u2200 i, PseudoEMetricSpace (\u03b1 i)]\n    [\u2200 i, PseudoEMetricSpace (\u03b2 i)] (f : \u2200 i, \u03b1 i \u2192 \u03b2 i) (hf : \u2200 i, Isometry (f i)) :\n    Isometry (dcomp f) := fun x y => by simp only [edist_pi_def, (hf _).edist_eq]\n#align isometry_dcomp isometry_dcomp\n\n#print Isometry.comp /-\n/-- The composition of isometries is an isometry. -/\ntheorem comp {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} (hg : Isometry g) (hf : Isometry f) : Isometry (g \u2218 f) :=\n  fun x y => (hg _ _).trans (hf _ _)\n#align isometry.comp Isometry.comp\n-/\n\n#print Isometry.uniformContinuous /-\n/-- An isometry from a metric space is a uniform continuous map -/\nprotected theorem uniformContinuous (hf : Isometry f) : UniformContinuous f :=\n  hf.lipschitz.UniformContinuous\n#align isometry.uniform_continuous Isometry.uniformContinuous\n-/\n\n#print Isometry.uniformInducing /-\n/-- An isometry from a metric space is a uniform inducing map -/\nprotected theorem uniformInducing (hf : Isometry f) : UniformInducing f :=\n  hf.antilipschitz.UniformInducing hf.UniformContinuous\n#align isometry.uniform_inducing Isometry.uniformInducing\n-/\n\n/- warning: isometry.tendsto_nhds_iff -> Isometry.tendsto_nhds_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {\u03b9 : Type.{u3}} {f : \u03b1 -> \u03b2} {g : \u03b9 -> \u03b1} {a : Filter.{u3} \u03b9} {b : \u03b1}, (Isometry.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (Iff (Filter.Tendsto.{u3, u1} \u03b9 \u03b1 g a (nhds.{u1} \u03b1 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) b)) (Filter.Tendsto.{u3, u2} \u03b9 \u03b2 (Function.comp.{succ u3, succ u1, succ u2} \u03b9 \u03b1 \u03b2 f g) a (nhds.{u2} \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (f b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] {\u03b9 : Type.{u1}} {f : \u03b1 -> \u03b2} {g : \u03b9 -> \u03b1} {a : Filter.{u1} \u03b9} {b : \u03b1}, (Isometry.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (Iff (Filter.Tendsto.{u1, u2} \u03b9 \u03b1 g a (nhds.{u2} \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) b)) (Filter.Tendsto.{u1, u3} \u03b9 \u03b2 (Function.comp.{succ u1, succ u2, succ u3} \u03b9 \u03b1 \u03b2 f g) a (nhds.{u3} \u03b2 (UniformSpace.toTopologicalSpace.{u3} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u3} \u03b2 _inst_2)) (f b))))\nCase conversion may be inaccurate. Consider using '#align isometry.tendsto_nhds_iff Isometry.tendsto_nhds_iff\u2093'. -/\ntheorem tendsto_nhds_iff {\u03b9 : Type _} {f : \u03b1 \u2192 \u03b2} {g : \u03b9 \u2192 \u03b1} {a : Filter \u03b9} {b : \u03b1}\n    (hf : Isometry f) : Filter.Tendsto g a (\ud835\udcdd b) \u2194 Filter.Tendsto (f \u2218 g) a (\ud835\udcdd (f b)) :=\n  hf.UniformInducing.Inducing.tendsto_nhds_iff\n#align isometry.tendsto_nhds_iff Isometry.tendsto_nhds_iff\n\n#print Isometry.continuous /-\n/-- An isometry is continuous. -/\nprotected theorem continuous (hf : Isometry f) : Continuous f :=\n  hf.lipschitz.Continuous\n#align isometry.continuous Isometry.continuous\n-/\n\n#print Isometry.right_inv /-\n/-- The right inverse of an isometry is an isometry. -/\ntheorem right_inv {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1} (h : Isometry f) (hg : RightInverse g f) : Isometry g :=\n  fun x y => by rw [\u2190 h, hg _, hg _]\n#align isometry.right_inv Isometry.right_inv\n-/\n\n#print Isometry.preimage_emetric_closedBall /-\ntheorem preimage_emetric_closedBall (h : Isometry f) (x : \u03b1) (r : \u211d\u22650\u221e) :\n    f \u207b\u00b9' EMetric.closedBall (f x) r = EMetric.closedBall x r :=\n  by\n  ext y\n  simp [h.edist_eq]\n#align isometry.preimage_emetric_closed_ball Isometry.preimage_emetric_closedBall\n-/\n\n#print Isometry.preimage_emetric_ball /-\ntheorem preimage_emetric_ball (h : Isometry f) (x : \u03b1) (r : \u211d\u22650\u221e) :\n    f \u207b\u00b9' EMetric.ball (f x) r = EMetric.ball x r :=\n  by\n  ext y\n  simp [h.edist_eq]\n#align isometry.preimage_emetric_ball Isometry.preimage_emetric_ball\n-/\n\n#print Isometry.ediam_image /-\n/-- Isometries preserve the diameter in pseudoemetric spaces. -/\ntheorem ediam_image (hf : Isometry f) (s : Set \u03b1) : EMetric.diam (f '' s) = EMetric.diam s :=\n  eq_of_forall_ge_iff fun d => by simp only [EMetric.diam_le_iff, ball_image_iff, hf.edist_eq]\n#align isometry.ediam_image Isometry.ediam_image\n-/\n\n#print Isometry.ediam_range /-\ntheorem ediam_range (hf : Isometry f) : EMetric.diam (range f) = EMetric.diam (univ : Set \u03b1) :=\n  by\n  rw [\u2190 image_univ]\n  exact hf.ediam_image univ\n#align isometry.ediam_range Isometry.ediam_range\n-/\n\n#print Isometry.mapsTo_emetric_ball /-\ntheorem mapsTo_emetric_ball (hf : Isometry f) (x : \u03b1) (r : \u211d\u22650\u221e) :\n    MapsTo f (EMetric.ball x r) (EMetric.ball (f x) r) :=\n  (hf.preimage_emetric_ball x r).ge\n#align isometry.maps_to_emetric_ball Isometry.mapsTo_emetric_ball\n-/\n\n#print Isometry.mapsTo_emetric_closedBall /-\ntheorem mapsTo_emetric_closedBall (hf : Isometry f) (x : \u03b1) (r : \u211d\u22650\u221e) :\n    MapsTo f (EMetric.closedBall x r) (EMetric.closedBall (f x) r) :=\n  (hf.preimage_emetric_closedBall x r).ge\n#align isometry.maps_to_emetric_closed_ball Isometry.mapsTo_emetric_closedBall\n-/\n\n#print isometry_subtype_coe /-\n/-- The injection from a subtype is an isometry -/\ntheorem isometry_subtype_coe {s : Set \u03b1} : Isometry (coe : s \u2192 \u03b1) := fun x y => rfl\n#align isometry_subtype_coe isometry_subtype_coe\n-/\n\n/- warning: isometry.comp_continuous_on_iff -> Isometry.comp_continuousOn_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2} {\u03b3 : Type.{u3}} [_inst_4 : TopologicalSpace.{u3} \u03b3], (Isometry.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (forall {g : \u03b3 -> \u03b1} {s : Set.{u3} \u03b3}, Iff (ContinuousOn.{u3, u2} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (Function.comp.{succ u3, succ u1, succ u2} \u03b3 \u03b1 \u03b2 f g) s) (ContinuousOn.{u3, u1} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) g s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] {f : \u03b1 -> \u03b2} {\u03b3 : Type.{u1}} [_inst_4 : TopologicalSpace.{u1} \u03b3], (Isometry.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (forall {g : \u03b3 -> \u03b1} {s : Set.{u1} \u03b3}, Iff (ContinuousOn.{u1, u3} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u3} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u3} \u03b2 _inst_2)) (Function.comp.{succ u1, succ u2, succ u3} \u03b3 \u03b1 \u03b2 f g) s) (ContinuousOn.{u1, u2} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) g s))\nCase conversion may be inaccurate. Consider using '#align isometry.comp_continuous_on_iff Isometry.comp_continuousOn_iff\u2093'. -/\ntheorem comp_continuousOn_iff {\u03b3} [TopologicalSpace \u03b3] (hf : Isometry f) {g : \u03b3 \u2192 \u03b1} {s : Set \u03b3} :\n    ContinuousOn (f \u2218 g) s \u2194 ContinuousOn g s :=\n  hf.UniformInducing.Inducing.continuousOn_iff.symm\n#align isometry.comp_continuous_on_iff Isometry.comp_continuousOn_iff\n\n/- warning: isometry.comp_continuous_iff -> Isometry.comp_continuous_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2} {\u03b3 : Type.{u3}} [_inst_4 : TopologicalSpace.{u3} \u03b3], (Isometry.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (forall {g : \u03b3 -> \u03b1}, Iff (Continuous.{u3, u2} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (Function.comp.{succ u3, succ u1, succ u2} \u03b3 \u03b1 \u03b2 f g)) (Continuous.{u3, u1} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) g))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] {f : \u03b1 -> \u03b2} {\u03b3 : Type.{u1}} [_inst_4 : TopologicalSpace.{u1} \u03b3], (Isometry.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (forall {g : \u03b3 -> \u03b1}, Iff (Continuous.{u1, u3} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u3} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u3} \u03b2 _inst_2)) (Function.comp.{succ u1, succ u2, succ u3} \u03b3 \u03b1 \u03b2 f g)) (Continuous.{u1, u2} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) g))\nCase conversion may be inaccurate. Consider using '#align isometry.comp_continuous_iff Isometry.comp_continuous_iff\u2093'. -/\ntheorem comp_continuous_iff {\u03b3} [TopologicalSpace \u03b3] (hf : Isometry f) {g : \u03b3 \u2192 \u03b1} :\n    Continuous (f \u2218 g) \u2194 Continuous g :=\n  hf.UniformInducing.Inducing.continuous_iff.symm\n#align isometry.comp_continuous_iff Isometry.comp_continuous_iff\n\nend PseudoEmetricIsometry\n\n--section\nsection EmetricIsometry\n\nvariable [EMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2}\n\n#print Isometry.injective /-\n/-- An isometry from an emetric space is injective -/\nprotected theorem injective (h : Isometry f) : Injective f :=\n  h.antilipschitz.Injective\n#align isometry.injective Isometry.injective\n-/\n\n#print Isometry.uniformEmbedding /-\n/-- An isometry from an emetric space is a uniform embedding -/\nprotected theorem uniformEmbedding (hf : Isometry f) : UniformEmbedding f :=\n  hf.antilipschitz.UniformEmbedding hf.lipschitz.UniformContinuous\n#align isometry.uniform_embedding Isometry.uniformEmbedding\n-/\n\n#print Isometry.embedding /-\n/-- An isometry from an emetric space is an embedding -/\nprotected theorem embedding (hf : Isometry f) : Embedding f :=\n  hf.UniformEmbedding.Embedding\n#align isometry.embedding Isometry.embedding\n-/\n\n#print Isometry.closedEmbedding /-\n/-- An isometry from a complete emetric space is a closed embedding -/\ntheorem closedEmbedding [CompleteSpace \u03b1] [EMetricSpace \u03b3] {f : \u03b1 \u2192 \u03b3} (hf : Isometry f) :\n    ClosedEmbedding f :=\n  hf.antilipschitz.ClosedEmbedding hf.lipschitz.UniformContinuous\n#align isometry.closed_embedding Isometry.closedEmbedding\n-/\n\nend EmetricIsometry\n\n--section\nsection PseudoMetricIsometry\n\nvariable [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2}\n\n#print Isometry.diam_image /-\n/-- An isometry preserves the diameter in pseudometric spaces. -/\ntheorem diam_image (hf : Isometry f) (s : Set \u03b1) : Metric.diam (f '' s) = Metric.diam s := by\n  rw [Metric.diam, Metric.diam, hf.ediam_image]\n#align isometry.diam_image Isometry.diam_image\n-/\n\n#print Isometry.diam_range /-\ntheorem diam_range (hf : Isometry f) : Metric.diam (range f) = Metric.diam (univ : Set \u03b1) :=\n  by\n  rw [\u2190 image_univ]\n  exact hf.diam_image univ\n#align isometry.diam_range Isometry.diam_range\n-/\n\n#print Isometry.preimage_setOf_dist /-\ntheorem preimage_setOf_dist (hf : Isometry f) (x : \u03b1) (p : \u211d \u2192 Prop) :\n    f \u207b\u00b9' { y | p (dist y (f x)) } = { y | p (dist y x) } :=\n  by\n  ext y\n  simp [hf.dist_eq]\n#align isometry.preimage_set_of_dist Isometry.preimage_setOf_dist\n-/\n\n#print Isometry.preimage_closedBall /-\ntheorem preimage_closedBall (hf : Isometry f) (x : \u03b1) (r : \u211d) :\n    f \u207b\u00b9' Metric.closedBall (f x) r = Metric.closedBall x r :=\n  hf.preimage_setOf_dist x (\u00b7 \u2264 r)\n#align isometry.preimage_closed_ball Isometry.preimage_closedBall\n-/\n\n#print Isometry.preimage_ball /-\ntheorem preimage_ball (hf : Isometry f) (x : \u03b1) (r : \u211d) :\n    f \u207b\u00b9' Metric.ball (f x) r = Metric.ball x r :=\n  hf.preimage_setOf_dist x (\u00b7 < r)\n#align isometry.preimage_ball Isometry.preimage_ball\n-/\n\n#print Isometry.preimage_sphere /-\ntheorem preimage_sphere (hf : Isometry f) (x : \u03b1) (r : \u211d) :\n    f \u207b\u00b9' Metric.sphere (f x) r = Metric.sphere x r :=\n  hf.preimage_setOf_dist x (\u00b7 = r)\n#align isometry.preimage_sphere Isometry.preimage_sphere\n-/\n\n#print Isometry.mapsTo_ball /-\ntheorem mapsTo_ball (hf : Isometry f) (x : \u03b1) (r : \u211d) :\n    MapsTo f (Metric.ball x r) (Metric.ball (f x) r) :=\n  (hf.preimage_ball x r).ge\n#align isometry.maps_to_ball Isometry.mapsTo_ball\n-/\n\n#print Isometry.mapsTo_sphere /-\ntheorem mapsTo_sphere (hf : Isometry f) (x : \u03b1) (r : \u211d) :\n    MapsTo f (Metric.sphere x r) (Metric.sphere (f x) r) :=\n  (hf.preimage_sphere x r).ge\n#align isometry.maps_to_sphere Isometry.mapsTo_sphere\n-/\n\n#print Isometry.mapsTo_closedBall /-\ntheorem mapsTo_closedBall (hf : Isometry f) (x : \u03b1) (r : \u211d) :\n    MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) r) :=\n  (hf.preimage_closedBall x r).ge\n#align isometry.maps_to_closed_ball Isometry.mapsTo_closedBall\n-/\n\nend PseudoMetricIsometry\n\n-- section\nend Isometry\n\n/- warning: uniform_embedding.to_isometry -> UniformEmbedding.to_isometry is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : UniformSpace.{u1} \u03b1] [_inst_2 : MetricSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2} (h : UniformEmbedding.{u1, u2} \u03b1 \u03b2 _inst_1 (PseudoMetricSpace.toUniformSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)) f), Isometry.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 (MetricSpace.toPseudoMetricSpace.{u1} \u03b1 (UniformEmbedding.comapMetricSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f h))) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)) f\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : UniformSpace.{u2} \u03b1] [_inst_2 : MetricSpace.{u1} \u03b2] {f : \u03b1 -> \u03b2} (h : UniformEmbedding.{u2, u1} \u03b1 \u03b2 _inst_1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2)) f), Isometry.{u2, u1} \u03b1 \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 (MetricSpace.toEMetricSpace.{u2} \u03b1 (UniformEmbedding.comapMetricSpace.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f h))) (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 (MetricSpace.toEMetricSpace.{u1} \u03b2 _inst_2)) f\nCase conversion may be inaccurate. Consider using '#align uniform_embedding.to_isometry UniformEmbedding.to_isometry\u2093'. -/\n-- namespace\n/-- A uniform embedding from a uniform space to a metric space is an isometry with respect to the\ninduced metric space structure on the source space. -/\ntheorem UniformEmbedding.to_isometry {\u03b1 \u03b2} [UniformSpace \u03b1] [MetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (h : UniformEmbedding f) :\n    @Isometry \u03b1 \u03b2\n      (@PseudoMetricSpace.toPseudoEMetricSpace \u03b1\n        (@MetricSpace.toPseudoMetricSpace \u03b1 (h.comapMetricSpace f)))\n      (by infer_instance) f :=\n  by\n  apply Isometry.of_dist_eq\n  intro x y\n  rfl\n#align uniform_embedding.to_isometry UniformEmbedding.to_isometry\n\n/- warning: embedding.to_isometry -> Embedding.to_isometry is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : MetricSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2} (h : Embedding.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoMetricSpace.toUniformSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2))) f), Isometry.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 (MetricSpace.toPseudoMetricSpace.{u1} \u03b1 (Embedding.comapMetricSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f h))) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)) f\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : MetricSpace.{u1} \u03b2] {f : \u03b1 -> \u03b2} (h : Embedding.{u2, u1} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoMetricSpace.toUniformSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2))) f), Isometry.{u2, u1} \u03b1 \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 (MetricSpace.toEMetricSpace.{u2} \u03b1 (Embedding.comapMetricSpace.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f h))) (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 (MetricSpace.toEMetricSpace.{u1} \u03b2 _inst_2)) f\nCase conversion may be inaccurate. Consider using '#align embedding.to_isometry Embedding.to_isometry\u2093'. -/\n/-- An embedding from a topological space to a metric space is an isometry with respect to the\ninduced metric space structure on the source space. -/\ntheorem Embedding.to_isometry {\u03b1 \u03b2} [TopologicalSpace \u03b1] [MetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (h : Embedding f) :\n    @Isometry \u03b1 \u03b2\n      (@PseudoMetricSpace.toPseudoEMetricSpace \u03b1\n        (@MetricSpace.toPseudoMetricSpace \u03b1 (h.comapMetricSpace f)))\n      (by infer_instance) f :=\n  by\n  apply Isometry.of_dist_eq\n  intro x y\n  rfl\n#align embedding.to_isometry Embedding.to_isometry\n\n#print IsometryEquiv /-\n-- such a bijection need not exist\n/-- `\u03b1` and `\u03b2` are isometric if there is an isometric bijection between them. -/\n@[nolint has_nonempty_instance]\nstructure IsometryEquiv (\u03b1 \u03b2 : Type _) [PseudoEMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] extends\n  \u03b1 \u2243 \u03b2 where\n  isometry_toFun : Isometry to_fun\n#align isometry_equiv IsometryEquiv\n-/\n\n-- mathport name: \u00abexpr \u2243\u1d62 \u00bb\ninfixl:25 \" \u2243\u1d62 \" => IsometryEquiv\n\nnamespace IsometryEquiv\n\nsection PseudoEMetricSpace\n\nvariable [PseudoEMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] [PseudoEMetricSpace \u03b3]\n\ninstance : CoeFun (\u03b1 \u2243\u1d62 \u03b2) fun _ => \u03b1 \u2192 \u03b2 :=\n  \u27e8fun e => e.toEquiv\u27e9\n\n/- warning: isometry_equiv.coe_eq_to_equiv -> IsometryEquiv.coe_eq_toEquiv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (a : \u03b1), Eq.{succ u2} \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h a) (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} \u03b1 \u03b2) (fun (_x : Equiv.{succ u1, succ u2} \u03b1 \u03b2) => \u03b1 -> \u03b2) (Equiv.hasCoeToFun.{succ u1, succ u2} \u03b1 \u03b2) (IsometryEquiv.toEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (a : \u03b1), Eq.{succ u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (Equiv.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : \u03b1) => \u03b2) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u2} \u03b1 \u03b2) (IsometryEquiv.toEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) a)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.coe_eq_to_equiv IsometryEquiv.coe_eq_toEquiv\u2093'. -/\ntheorem coe_eq_toEquiv (h : \u03b1 \u2243\u1d62 \u03b2) (a : \u03b1) : h a = h.toEquiv a :=\n  rfl\n#align isometry_equiv.coe_eq_to_equiv IsometryEquiv.coe_eq_toEquiv\n\n#print IsometryEquiv.coe_toEquiv /-\n@[simp]\ntheorem coe_toEquiv (h : \u03b1 \u2243\u1d62 \u03b2) : \u21d1h.toEquiv = h :=\n  rfl\n#align isometry_equiv.coe_to_equiv IsometryEquiv.coe_toEquiv\n-/\n\n/- warning: isometry_equiv.isometry -> IsometryEquiv.isometry is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Isometry.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Isometry.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.isometry IsometryEquiv.isometry\u2093'. -/\nprotected theorem isometry (h : \u03b1 \u2243\u1d62 \u03b2) : Isometry h :=\n  h.isometry_toFun\n#align isometry_equiv.isometry IsometryEquiv.isometry\n\n/- warning: isometry_equiv.bijective -> IsometryEquiv.bijective is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Function.Bijective.{succ u1, succ u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Function.Bijective.{succ u1, succ u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.bijective IsometryEquiv.bijective\u2093'. -/\nprotected theorem bijective (h : \u03b1 \u2243\u1d62 \u03b2) : Bijective h :=\n  h.toEquiv.Bijective\n#align isometry_equiv.bijective IsometryEquiv.bijective\n\n/- warning: isometry_equiv.injective -> IsometryEquiv.injective is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.injective IsometryEquiv.injective\u2093'. -/\nprotected theorem injective (h : \u03b1 \u2243\u1d62 \u03b2) : Injective h :=\n  h.toEquiv.Injective\n#align isometry_equiv.injective IsometryEquiv.injective\n\n/- warning: isometry_equiv.surjective -> IsometryEquiv.surjective is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Function.Surjective.{succ u1, succ u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Function.Surjective.{succ u1, succ u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.surjective IsometryEquiv.surjective\u2093'. -/\nprotected theorem surjective (h : \u03b1 \u2243\u1d62 \u03b2) : Surjective h :=\n  h.toEquiv.Surjective\n#align isometry_equiv.surjective IsometryEquiv.surjective\n\n/- warning: isometry_equiv.edist_eq -> IsometryEquiv.edist_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1) (y : \u03b1), Eq.{1} ENNReal (EDist.edist.{u2} \u03b2 (PseudoEMetricSpace.toHasEdist.{u2} \u03b2 _inst_2) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h y)) (EDist.edist.{u1} \u03b1 (PseudoEMetricSpace.toHasEdist.{u1} \u03b1 _inst_1) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1) (y : \u03b1), Eq.{1} ENNReal (EDist.edist.{u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) (PseudoEMetricSpace.toEDist.{u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_2) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h y)) (EDist.edist.{u1} \u03b1 (PseudoEMetricSpace.toEDist.{u1} \u03b1 _inst_1) x y)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.edist_eq IsometryEquiv.edist_eq\u2093'. -/\nprotected theorem edist_eq (h : \u03b1 \u2243\u1d62 \u03b2) (x y : \u03b1) : edist (h x) (h y) = edist x y :=\n  h.Isometry.edist_eq x y\n#align isometry_equiv.edist_eq IsometryEquiv.edist_eq\n\n/- warning: isometry_equiv.dist_eq -> IsometryEquiv.dist_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : PseudoMetricSpace.{u1} \u03b1] [_inst_5 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) (x : \u03b1) (y : \u03b1), Eq.{1} Real (Dist.dist.{u2} \u03b2 (PseudoMetricSpace.toHasDist.{u2} \u03b2 _inst_5) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) h x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) h y)) (Dist.dist.{u1} \u03b1 (PseudoMetricSpace.toHasDist.{u1} \u03b1 _inst_4) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : PseudoMetricSpace.{u2} \u03b1] [_inst_5 : PseudoMetricSpace.{u1} \u03b2] (h : IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) (x : \u03b1) (y : \u03b1), Eq.{1} Real (Dist.dist.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) (PseudoMetricSpace.toDist.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_5) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)))) h x) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)))) h y)) (Dist.dist.{u2} \u03b1 (PseudoMetricSpace.toDist.{u2} \u03b1 _inst_4) x y)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.dist_eq IsometryEquiv.dist_eq\u2093'. -/\nprotected theorem dist_eq {\u03b1 \u03b2 : Type _} [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] (h : \u03b1 \u2243\u1d62 \u03b2)\n    (x y : \u03b1) : dist (h x) (h y) = dist x y :=\n  h.Isometry.dist_eq x y\n#align isometry_equiv.dist_eq IsometryEquiv.dist_eq\n\n/- warning: isometry_equiv.nndist_eq -> IsometryEquiv.nndist_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : PseudoMetricSpace.{u1} \u03b1] [_inst_5 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) (x : \u03b1) (y : \u03b1), Eq.{1} NNReal (NNDist.nndist.{u2} \u03b2 (PseudoMetricSpace.toNNDist.{u2} \u03b2 _inst_5) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) h x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_5)) h y)) (NNDist.nndist.{u1} \u03b1 (PseudoMetricSpace.toNNDist.{u1} \u03b1 _inst_4) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : PseudoMetricSpace.{u2} \u03b1] [_inst_5 : PseudoMetricSpace.{u1} \u03b2] (h : IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) (x : \u03b1) (y : \u03b1), Eq.{1} NNReal (NNDist.nndist.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) (PseudoMetricSpace.toNNDist.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_5) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)))) h x) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u1), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)))) h y)) (NNDist.nndist.{u2} \u03b1 (PseudoMetricSpace.toNNDist.{u2} \u03b1 _inst_4) x y)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.nndist_eq IsometryEquiv.nndist_eq\u2093'. -/\nprotected theorem nndist_eq {\u03b1 \u03b2 : Type _} [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] (h : \u03b1 \u2243\u1d62 \u03b2)\n    (x y : \u03b1) : nndist (h x) (h y) = nndist x y :=\n  h.Isometry.nndist_eq x y\n#align isometry_equiv.nndist_eq IsometryEquiv.nndist_eq\n\n/- warning: isometry_equiv.continuous -> IsometryEquiv.continuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Continuous.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Continuous.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.continuous IsometryEquiv.continuous\u2093'. -/\nprotected theorem continuous (h : \u03b1 \u2243\u1d62 \u03b2) : Continuous h :=\n  h.Isometry.Continuous\n#align isometry_equiv.continuous IsometryEquiv.continuous\n\n#print IsometryEquiv.ediam_image /-\n@[simp]\ntheorem ediam_image (h : \u03b1 \u2243\u1d62 \u03b2) (s : Set \u03b1) : EMetric.diam (h '' s) = EMetric.diam s :=\n  h.Isometry.ediam_image s\n#align isometry_equiv.ediam_image IsometryEquiv.ediam_image\n-/\n\n#print IsometryEquiv.toEquiv_injective /-\ntheorem toEquiv_injective : \u2200 \u2983h\u2081 h\u2082 : \u03b1 \u2243\u1d62 \u03b2\u2984, h\u2081.toEquiv = h\u2082.toEquiv \u2192 h\u2081 = h\u2082\n  | \u27e8e\u2081, h\u2081\u27e9, \u27e8e\u2082, h\u2082\u27e9, H => by\n    dsimp at H\n    subst e\u2081\n#align isometry_equiv.to_equiv_inj IsometryEquiv.toEquiv_injective\n-/\n\n/- warning: isometry_equiv.ext -> IsometryEquiv.ext is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {{h\u2081 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2}} {{h\u2082 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2}}, (forall (x : \u03b1), Eq.{succ u2} \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h\u2081 x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h\u2082 x)) -> (Eq.{max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h\u2081 h\u2082)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {{h\u2081 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2}} {{h\u2082 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2}}, (forall (x : \u03b1), Eq.{succ u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h\u2081 x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h\u2082 x)) -> (Eq.{max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h\u2081 h\u2082)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.ext IsometryEquiv.ext\u2093'. -/\n@[ext]\ntheorem ext \u2983h\u2081 h\u2082 : \u03b1 \u2243\u1d62 \u03b2\u2984 (H : \u2200 x, h\u2081 x = h\u2082 x) : h\u2081 = h\u2082 :=\n  toEquiv_injective <| Equiv.ext H\n#align isometry_equiv.ext IsometryEquiv.ext\n\n#print IsometryEquiv.mk' /-\n/-- Alternative constructor for isometric bijections,\ntaking as input an isometry, and a right inverse. -/\ndef mk' {\u03b1 : Type u} [EMetricSpace \u03b1] (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) (hfg : \u2200 x, f (g x) = x)\n    (hf : Isometry f) : \u03b1 \u2243\u1d62 \u03b2 where\n  toFun := f\n  invFun := g\n  left_inv x := hf.Injective <| hfg _\n  right_inv := hfg\n  isometry_toFun := hf\n#align isometry_equiv.mk' IsometryEquiv.mk'\n-/\n\n#print IsometryEquiv.refl /-\n/-- The identity isometry of a space. -/\nprotected def refl (\u03b1 : Type _) [PseudoEMetricSpace \u03b1] : \u03b1 \u2243\u1d62 \u03b1 :=\n  { Equiv.refl \u03b1 with isometry_toFun := isometry_id }\n#align isometry_equiv.refl IsometryEquiv.refl\n-/\n\n#print IsometryEquiv.trans /-\n/-- The composition of two isometric isomorphisms, as an isometric isomorphism. -/\nprotected def trans (h\u2081 : \u03b1 \u2243\u1d62 \u03b2) (h\u2082 : \u03b2 \u2243\u1d62 \u03b3) : \u03b1 \u2243\u1d62 \u03b3 :=\n  { Equiv.trans h\u2081.toEquiv h\u2082.toEquiv with\n    isometry_toFun := h\u2082.isometry_toFun.comp h\u2081.isometry_toFun }\n#align isometry_equiv.trans IsometryEquiv.trans\n-/\n\n/- warning: isometry_equiv.trans_apply -> IsometryEquiv.trans_apply is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b3 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] [_inst_3 : PseudoEMetricSpace.{u3} \u03b3] (h\u2081 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (h\u2082 : IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) (x : \u03b1), Eq.{succ u3} \u03b3 (coeFn.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (IsometryEquiv.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3) (fun (_x : IsometryEquiv.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3) => \u03b1 -> \u03b3) (IsometryEquiv.hasCoeToFun.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3) (IsometryEquiv.trans.{u1, u2, u3} \u03b1 \u03b2 \u03b3 _inst_1 _inst_2 _inst_3 h\u2081 h\u2082) x) (coeFn.{max (succ u2) (succ u3), max (succ u2) (succ u3)} (IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) (fun (_x : IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) => \u03b2 -> \u03b3) (IsometryEquiv.hasCoeToFun.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) h\u2082 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h\u2081 x))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b3 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] [_inst_3 : PseudoEMetricSpace.{u3} \u03b3] (h\u2081 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (h\u2082 : IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) (x : \u03b1), Eq.{succ u3} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b3) x) (FunLike.coe.{max (succ u1) (succ u3), succ u1, succ u3} (IsometryEquiv.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b3) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u3), succ u1, succ u3} (IsometryEquiv.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3) \u03b1 \u03b3 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u3), succ u1, succ u3} (IsometryEquiv.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3) \u03b1 \u03b3 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3))) (IsometryEquiv.trans.{u1, u2, u3} \u03b1 \u03b2 \u03b3 _inst_1 _inst_2 _inst_3 h\u2081 h\u2082) x) (FunLike.coe.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b3) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) \u03b2 \u03b3 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) \u03b2 \u03b3 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3))) h\u2082 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h\u2081 x))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.trans_apply IsometryEquiv.trans_apply\u2093'. -/\n@[simp]\ntheorem trans_apply (h\u2081 : \u03b1 \u2243\u1d62 \u03b2) (h\u2082 : \u03b2 \u2243\u1d62 \u03b3) (x : \u03b1) : h\u2081.trans h\u2082 x = h\u2082 (h\u2081 x) :=\n  rfl\n#align isometry_equiv.trans_apply IsometryEquiv.trans_apply\n\n#print IsometryEquiv.symm /-\n/-- The inverse of an isometric isomorphism, as an isometric isomorphism. -/\nprotected def symm (h : \u03b1 \u2243\u1d62 \u03b2) : \u03b2 \u2243\u1d62 \u03b1\n    where\n  isometry_toFun := h.Isometry.right_inv h.right_inv\n  toEquiv := h.toEquiv.symm\n#align isometry_equiv.symm IsometryEquiv.symm\n-/\n\n#print IsometryEquiv.Simps.apply /-\n/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,\n  because it is a composition of multiple projections. -/\ndef Simps.apply (h : \u03b1 \u2243\u1d62 \u03b2) : \u03b1 \u2192 \u03b2 :=\n  h\n#align isometry_equiv.simps.apply IsometryEquiv.Simps.apply\n-/\n\n#print IsometryEquiv.Simps.symm_apply /-\n/-- See Note [custom simps projection] -/\ndef Simps.symm_apply (h : \u03b1 \u2243\u1d62 \u03b2) : \u03b2 \u2192 \u03b1 :=\n  h.symm\n#align isometry_equiv.simps.symm_apply IsometryEquiv.Simps.symm_apply\n-/\n\ninitialize_simps_projections IsometryEquiv (to_equiv_to_fun \u2192 apply, to_equiv_inv_fun \u2192 symm_apply)\n\n#print IsometryEquiv.symm_symm /-\n@[simp]\ntheorem symm_symm (h : \u03b1 \u2243\u1d62 \u03b2) : h.symm.symm = h :=\n  toEquiv_injective h.toEquiv.symm_symm\n#align isometry_equiv.symm_symm IsometryEquiv.symm_symm\n-/\n\n/- warning: isometry_equiv.apply_symm_apply -> IsometryEquiv.apply_symm_apply is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (y : \u03b2), Eq.{succ u2} \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) y)) y\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (y : \u03b2), Eq.{succ u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (a : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) a) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) y)) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) y)) y\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.apply_symm_apply IsometryEquiv.apply_symm_apply\u2093'. -/\n@[simp]\ntheorem apply_symm_apply (h : \u03b1 \u2243\u1d62 \u03b2) (y : \u03b2) : h (h.symm y) = y :=\n  h.toEquiv.apply_symm_apply y\n#align isometry_equiv.apply_symm_apply IsometryEquiv.apply_symm_apply\n\n/- warning: isometry_equiv.symm_apply_apply -> IsometryEquiv.symm_apply_apply is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1), Eq.{succ u1} \u03b1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h x)) x\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1), Eq.{succ u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (a : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) a) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h x)) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h x)) x\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.symm_apply_apply IsometryEquiv.symm_apply_apply\u2093'. -/\n@[simp]\ntheorem symm_apply_apply (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b1) : h.symm (h x) = x :=\n  h.toEquiv.symm_apply_apply x\n#align isometry_equiv.symm_apply_apply IsometryEquiv.symm_apply_apply\n\n/- warning: isometry_equiv.symm_apply_eq -> IsometryEquiv.symm_apply_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) {x : \u03b1} {y : \u03b2}, Iff (Eq.{succ u1} \u03b1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) y) x) (Eq.{succ u2} \u03b2 y (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h x))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) {x : \u03b1} {y : \u03b2}, Iff (Eq.{succ u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) y) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) y) x) (Eq.{succ u2} \u03b2 y (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h x))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.symm_apply_eq IsometryEquiv.symm_apply_eq\u2093'. -/\ntheorem symm_apply_eq (h : \u03b1 \u2243\u1d62 \u03b2) {x : \u03b1} {y : \u03b2} : h.symm y = x \u2194 y = h x :=\n  h.toEquiv.symm_apply_eq\n#align isometry_equiv.symm_apply_eq IsometryEquiv.symm_apply_eq\n\n/- warning: isometry_equiv.eq_symm_apply -> IsometryEquiv.eq_symm_apply is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) {x : \u03b1} {y : \u03b2}, Iff (Eq.{succ u1} \u03b1 x (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) y)) (Eq.{succ u2} \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h x) y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) {x : \u03b1} {y : \u03b2}, Iff (Eq.{succ u1} \u03b1 x (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) y)) (Eq.{succ u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h x) y)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.eq_symm_apply IsometryEquiv.eq_symm_apply\u2093'. -/\ntheorem eq_symm_apply (h : \u03b1 \u2243\u1d62 \u03b2) {x : \u03b1} {y : \u03b2} : x = h.symm y \u2194 h x = y :=\n  h.toEquiv.eq_symm_apply\n#align isometry_equiv.eq_symm_apply IsometryEquiv.eq_symm_apply\n\n/- warning: isometry_equiv.symm_comp_self -> IsometryEquiv.symm_comp_self is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{succ u1} (\u03b1 -> \u03b1) (Function.comp.{succ u1, succ u2, succ u1} \u03b1 \u03b2 \u03b1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)) (id.{succ u1} \u03b1)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{succ u1} (\u03b1 -> \u03b1) (Function.comp.{succ u1, succ u2, succ u1} \u03b1 \u03b2 \u03b1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h)) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)) (id.{succ u1} \u03b1)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.symm_comp_self IsometryEquiv.symm_comp_self\u2093'. -/\ntheorem symm_comp_self (h : \u03b1 \u2243\u1d62 \u03b2) : \u21d1h.symm \u2218 \u21d1h = id :=\n  funext fun a => h.toEquiv.left_inv a\n#align isometry_equiv.symm_comp_self IsometryEquiv.symm_comp_self\n\n/- warning: isometry_equiv.self_comp_symm -> IsometryEquiv.self_comp_symm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{succ u2} (\u03b2 -> \u03b2) (Function.comp.{succ u2, succ u1, succ u2} \u03b2 \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h) (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (id.{succ u2} \u03b2)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{succ u2} (\u03b2 -> \u03b2) (Function.comp.{succ u2, succ u1, succ u2} \u03b2 \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (id.{succ u2} \u03b2)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.self_comp_symm IsometryEquiv.self_comp_symm\u2093'. -/\ntheorem self_comp_symm (h : \u03b1 \u2243\u1d62 \u03b2) : \u21d1h \u2218 \u21d1h.symm = id :=\n  funext fun a => h.toEquiv.right_inv a\n#align isometry_equiv.self_comp_symm IsometryEquiv.self_comp_symm\n\n/- warning: isometry_equiv.range_eq_univ -> IsometryEquiv.range_eq_univ is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{succ u2} (Set.{u2} \u03b2) (Set.range.{u2, succ u1} \u03b2 \u03b1 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)) (Set.univ.{u2} \u03b2)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{succ u2} (Set.{u2} \u03b2) (Set.range.{u2, succ u1} \u03b2 \u03b1 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)) (Set.univ.{u2} \u03b2)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.range_eq_univ IsometryEquiv.range_eq_univ\u2093'. -/\n@[simp]\ntheorem range_eq_univ (h : \u03b1 \u2243\u1d62 \u03b2) : range h = univ :=\n  h.toEquiv.range_eq_univ\n#align isometry_equiv.range_eq_univ IsometryEquiv.range_eq_univ\n\n/- warning: isometry_equiv.image_symm -> IsometryEquiv.image_symm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u2) (succ u1)} ((Set.{u2} \u03b2) -> (Set.{u1} \u03b1)) (Set.image.{u2, u1} \u03b2 \u03b1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (Set.preimage.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} ((Set.{u2} \u03b2) -> (Set.{u1} \u03b1)) (Set.image.{u2, u1} \u03b2 \u03b1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (Set.preimage.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.image_symm IsometryEquiv.image_symm\u2093'. -/\ntheorem image_symm (h : \u03b1 \u2243\u1d62 \u03b2) : image h.symm = preimage h :=\n  image_eq_preimage_of_inverse h.symm.toEquiv.left_inv h.symm.toEquiv.right_inv\n#align isometry_equiv.image_symm IsometryEquiv.image_symm\n\n/- warning: isometry_equiv.preimage_symm -> IsometryEquiv.preimage_symm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} ((Set.{u1} \u03b1) -> (Set.{u2} \u03b2)) (Set.preimage.{u2, u1} \u03b2 \u03b1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (Set.image.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} ((Set.{u1} \u03b1) -> (Set.{u2} \u03b2)) (Set.preimage.{u2, u1} \u03b2 \u03b1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (Set.image.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.preimage_symm IsometryEquiv.preimage_symm\u2093'. -/\ntheorem preimage_symm (h : \u03b1 \u2243\u1d62 \u03b2) : preimage h.symm = image h :=\n  (image_eq_preimage_of_inverse h.toEquiv.left_inv h.toEquiv.right_inv).symm\n#align isometry_equiv.preimage_symm IsometryEquiv.preimage_symm\n\n/- warning: isometry_equiv.symm_trans_apply -> IsometryEquiv.symm_trans_apply is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b3 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] [_inst_3 : PseudoEMetricSpace.{u3} \u03b3] (h\u2081 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (h\u2082 : IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) (x : \u03b3), Eq.{succ u1} \u03b1 (coeFn.{max (succ u3) (succ u1), max (succ u3) (succ u1)} (IsometryEquiv.{u3, u1} \u03b3 \u03b1 _inst_3 _inst_1) (fun (_x : IsometryEquiv.{u3, u1} \u03b3 \u03b1 _inst_3 _inst_1) => \u03b3 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u3, u1} \u03b3 \u03b1 _inst_3 _inst_1) (IsometryEquiv.symm.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3 (IsometryEquiv.trans.{u1, u2, u3} \u03b1 \u03b2 \u03b3 _inst_1 _inst_2 _inst_3 h\u2081 h\u2082)) x) (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h\u2081) (coeFn.{max (succ u3) (succ u2), max (succ u3) (succ u2)} (IsometryEquiv.{u3, u2} \u03b3 \u03b2 _inst_3 _inst_2) (fun (_x : IsometryEquiv.{u3, u2} \u03b3 \u03b2 _inst_3 _inst_2) => \u03b3 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u3, u2} \u03b3 \u03b2 _inst_3 _inst_2) (IsometryEquiv.symm.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3 h\u2082) x))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b3 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] [_inst_3 : PseudoEMetricSpace.{u3} \u03b3] (h\u2081 : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (h\u2082 : IsometryEquiv.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3) (x : \u03b3), Eq.{succ u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b3) => \u03b1) x) (FunLike.coe.{max (succ u1) (succ u3), succ u3, succ u1} (IsometryEquiv.{u3, u1} \u03b3 \u03b1 _inst_3 _inst_1) \u03b3 (fun (_x : \u03b3) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b3) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u3), succ u3, succ u1} (IsometryEquiv.{u3, u1} \u03b3 \u03b1 _inst_3 _inst_1) \u03b3 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u3), succ u3, succ u1} (IsometryEquiv.{u3, u1} \u03b3 \u03b1 _inst_3 _inst_1) \u03b3 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u3, u1} \u03b3 \u03b1 _inst_3 _inst_1))) (IsometryEquiv.symm.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3 (IsometryEquiv.trans.{u1, u2, u3} \u03b1 \u03b2 \u03b3 _inst_1 _inst_2 _inst_3 h\u2081 h\u2082)) x) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h\u2081) (FunLike.coe.{max (succ u2) (succ u3), succ u3, succ u2} (IsometryEquiv.{u3, u2} \u03b3 \u03b2 _inst_3 _inst_2) \u03b3 (fun (_x : \u03b3) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b3) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u3), succ u3, succ u2} (IsometryEquiv.{u3, u2} \u03b3 \u03b2 _inst_3 _inst_2) \u03b3 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u3), succ u3, succ u2} (IsometryEquiv.{u3, u2} \u03b3 \u03b2 _inst_3 _inst_2) \u03b3 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u3, u2} \u03b3 \u03b2 _inst_3 _inst_2))) (IsometryEquiv.symm.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3 h\u2082) x))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.symm_trans_apply IsometryEquiv.symm_trans_apply\u2093'. -/\n@[simp]\ntheorem symm_trans_apply (h\u2081 : \u03b1 \u2243\u1d62 \u03b2) (h\u2082 : \u03b2 \u2243\u1d62 \u03b3) (x : \u03b3) :\n    (h\u2081.trans h\u2082).symm x = h\u2081.symm (h\u2082.symm x) :=\n  rfl\n#align isometry_equiv.symm_trans_apply IsometryEquiv.symm_trans_apply\n\n#print IsometryEquiv.ediam_univ /-\ntheorem ediam_univ (h : \u03b1 \u2243\u1d62 \u03b2) : EMetric.diam (univ : Set \u03b1) = EMetric.diam (univ : Set \u03b2) := by\n  rw [\u2190 h.range_eq_univ, h.isometry.ediam_range]\n#align isometry_equiv.ediam_univ IsometryEquiv.ediam_univ\n-/\n\n#print IsometryEquiv.ediam_preimage /-\n@[simp]\ntheorem ediam_preimage (h : \u03b1 \u2243\u1d62 \u03b2) (s : Set \u03b2) : EMetric.diam (h \u207b\u00b9' s) = EMetric.diam s := by\n  rw [\u2190 image_symm, ediam_image]\n#align isometry_equiv.ediam_preimage IsometryEquiv.ediam_preimage\n-/\n\n/- warning: isometry_equiv.preimage_emetric_ball -> IsometryEquiv.preimage_emetric_ball is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b2) (r : ENNReal), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h) (EMetric.ball.{u2} \u03b2 _inst_2 x r)) (EMetric.ball.{u1} \u03b1 _inst_1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b2) (r : ENNReal), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h) (EMetric.ball.{u2} \u03b2 _inst_2 x r)) (EMetric.ball.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) x) _inst_1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.preimage_emetric_ball IsometryEquiv.preimage_emetric_ball\u2093'. -/\n@[simp]\ntheorem preimage_emetric_ball (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b2) (r : \u211d\u22650\u221e) :\n    h \u207b\u00b9' EMetric.ball x r = EMetric.ball (h.symm x) r := by\n  rw [\u2190 h.isometry.preimage_emetric_ball (h.symm x) r, h.apply_symm_apply]\n#align isometry_equiv.preimage_emetric_ball IsometryEquiv.preimage_emetric_ball\n\n/- warning: isometry_equiv.preimage_emetric_closed_ball -> IsometryEquiv.preimage_emetric_closedBall is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b2) (r : ENNReal), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h) (EMetric.closedBall.{u2} \u03b2 _inst_2 x r)) (EMetric.closedBall.{u1} \u03b1 _inst_1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b2) (r : ENNReal), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h) (EMetric.closedBall.{u2} \u03b2 _inst_2 x r)) (EMetric.closedBall.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) x) _inst_1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h) x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.preimage_emetric_closed_ball IsometryEquiv.preimage_emetric_closedBall\u2093'. -/\n@[simp]\ntheorem preimage_emetric_closedBall (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b2) (r : \u211d\u22650\u221e) :\n    h \u207b\u00b9' EMetric.closedBall x r = EMetric.closedBall (h.symm x) r := by\n  rw [\u2190 h.isometry.preimage_emetric_closed_ball (h.symm x) r, h.apply_symm_apply]\n#align isometry_equiv.preimage_emetric_closed_ball IsometryEquiv.preimage_emetric_closedBall\n\n/- warning: isometry_equiv.image_emetric_ball -> IsometryEquiv.image_emetric_ball is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1) (r : ENNReal), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h) (EMetric.ball.{u1} \u03b1 _inst_1 x r)) (EMetric.ball.{u2} \u03b2 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1) (r : ENNReal), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h) (EMetric.ball.{u1} \u03b1 _inst_1 x r)) (EMetric.ball.{u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.image_emetric_ball IsometryEquiv.image_emetric_ball\u2093'. -/\n@[simp]\ntheorem image_emetric_ball (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b1) (r : \u211d\u22650\u221e) :\n    h '' EMetric.ball x r = EMetric.ball (h x) r := by\n  rw [\u2190 h.preimage_symm, h.symm.preimage_emetric_ball, symm_symm]\n#align isometry_equiv.image_emetric_ball IsometryEquiv.image_emetric_ball\n\n/- warning: isometry_equiv.image_emetric_closed_ball -> IsometryEquiv.image_emetric_closedBall is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1) (r : ENNReal), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h) (EMetric.closedBall.{u1} \u03b1 _inst_1 x r)) (EMetric.closedBall.{u2} \u03b2 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (x : \u03b1) (r : ENNReal), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h) (EMetric.closedBall.{u1} \u03b1 _inst_1 x r)) (EMetric.closedBall.{u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.image_emetric_closed_ball IsometryEquiv.image_emetric_closedBall\u2093'. -/\n@[simp]\ntheorem image_emetric_closedBall (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b1) (r : \u211d\u22650\u221e) :\n    h '' EMetric.closedBall x r = EMetric.closedBall (h x) r := by\n  rw [\u2190 h.preimage_symm, h.symm.preimage_emetric_closed_ball, symm_symm]\n#align isometry_equiv.image_emetric_closed_ball IsometryEquiv.image_emetric_closedBall\n\n#print IsometryEquiv.toHomeomorph /-\n/-- The (bundled) homeomorphism associated to an isometric isomorphism. -/\n@[simps toEquiv]\nprotected def toHomeomorph (h : \u03b1 \u2243\u1d62 \u03b2) : \u03b1 \u2243\u209c \u03b2\n    where\n  continuous_toFun := h.Continuous\n  continuous_invFun := h.symm.Continuous\n  toEquiv := h.toEquiv\n#align isometry_equiv.to_homeomorph IsometryEquiv.toHomeomorph\n-/\n\n/- warning: isometry_equiv.coe_to_homeomorph -> IsometryEquiv.coe_toHomeomorph is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} (\u03b1 -> \u03b2) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))) (fun (_x : Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))) => \u03b1 -> \u03b2) (Homeomorph.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))) (IsometryEquiv.toHomeomorph.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} (\u03b1 -> \u03b2) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))) \u03b1 (fun (_x : \u03b1) => \u03b2) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))) \u03b1 \u03b2 (Homeomorph.instEquivLikeHomeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))))) (IsometryEquiv.toHomeomorph.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h)) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) h)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.coe_to_homeomorph IsometryEquiv.coe_toHomeomorph\u2093'. -/\n@[simp]\ntheorem coe_toHomeomorph (h : \u03b1 \u2243\u1d62 \u03b2) : \u21d1h.toHomeomorph = h :=\n  rfl\n#align isometry_equiv.coe_to_homeomorph IsometryEquiv.coe_toHomeomorph\n\n/- warning: isometry_equiv.coe_to_homeomorph_symm -> IsometryEquiv.coe_toHomeomorph_symm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u2) (succ u1)} (\u03b2 -> \u03b1) (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Homeomorph.{u2, u1} \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (fun (_x : Homeomorph.{u2, u1} \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) => \u03b2 -> \u03b1) (Homeomorph.hasCoeToFun.{u2, u1} \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (Homeomorph.symm.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (IsometryEquiv.toHomeomorph.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} (\u03b2 -> \u03b1) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (Homeomorph.{u2, u1} \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) \u03b2 (fun (_x : \u03b2) => \u03b1) (EmbeddingLike.toFunLike.{max (succ u2) (succ u1), succ u2, succ u1} (Homeomorph.{u2, u1} \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u1), succ u2, succ u1} (Homeomorph.{u2, u1} \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) \u03b2 \u03b1 (Homeomorph.instEquivLikeHomeomorph.{u2, u1} \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))))) (Homeomorph.symm.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (IsometryEquiv.toHomeomorph.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 h))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.coe_to_homeomorph_symm IsometryEquiv.coe_toHomeomorph_symm\u2093'. -/\n@[simp]\ntheorem coe_toHomeomorph_symm (h : \u03b1 \u2243\u1d62 \u03b2) : \u21d1h.toHomeomorph.symm = h.symm :=\n  rfl\n#align isometry_equiv.coe_to_homeomorph_symm IsometryEquiv.coe_toHomeomorph_symm\n\n/- warning: isometry_equiv.comp_continuous_on_iff -> IsometryEquiv.comp_continuousOn_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {\u03b3 : Type.{u3}} [_inst_4 : TopologicalSpace.{u3} \u03b3] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) {f : \u03b3 -> \u03b1} {s : Set.{u3} \u03b3}, Iff (ContinuousOn.{u3, u2} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (Function.comp.{succ u3, succ u1, succ u2} \u03b3 \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h) f) s) (ContinuousOn.{u3, u1} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) f s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] {\u03b3 : Type.{u1}} [_inst_4 : TopologicalSpace.{u1} \u03b3] (h : IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) {f : \u03b3 -> \u03b1} {s : Set.{u1} \u03b3}, Iff (ContinuousOn.{u1, u3} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u3} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u3} \u03b2 _inst_2)) (Function.comp.{succ u1, succ u2, succ u3} \u03b3 \u03b1 \u03b2 (FunLike.coe.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2))) h) f) s) (ContinuousOn.{u1, u2} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) f s)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.comp_continuous_on_iff IsometryEquiv.comp_continuousOn_iff\u2093'. -/\n@[simp]\ntheorem comp_continuousOn_iff {\u03b3} [TopologicalSpace \u03b3] (h : \u03b1 \u2243\u1d62 \u03b2) {f : \u03b3 \u2192 \u03b1} {s : Set \u03b3} :\n    ContinuousOn (h \u2218 f) s \u2194 ContinuousOn f s :=\n  h.toHomeomorph.comp_continuousOn_iff _ _\n#align isometry_equiv.comp_continuous_on_iff IsometryEquiv.comp_continuousOn_iff\n\n/- warning: isometry_equiv.comp_continuous_iff -> IsometryEquiv.comp_continuous_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {\u03b3 : Type.{u3}} [_inst_4 : TopologicalSpace.{u3} \u03b3] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) {f : \u03b3 -> \u03b1}, Iff (Continuous.{u3, u2} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) (Function.comp.{succ u3, succ u1, succ u2} \u03b3 \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h) f)) (Continuous.{u3, u1} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] {\u03b3 : Type.{u1}} [_inst_4 : TopologicalSpace.{u1} \u03b3] (h : IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) {f : \u03b3 -> \u03b1}, Iff (Continuous.{u1, u3} \u03b3 \u03b2 _inst_4 (UniformSpace.toTopologicalSpace.{u3} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u3} \u03b2 _inst_2)) (Function.comp.{succ u1, succ u2, succ u3} \u03b3 \u03b1 \u03b2 (FunLike.coe.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2))) h) f)) (Continuous.{u1, u2} \u03b3 \u03b1 _inst_4 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) f)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.comp_continuous_iff IsometryEquiv.comp_continuous_iff\u2093'. -/\n@[simp]\ntheorem comp_continuous_iff {\u03b3} [TopologicalSpace \u03b3] (h : \u03b1 \u2243\u1d62 \u03b2) {f : \u03b3 \u2192 \u03b1} :\n    Continuous (h \u2218 f) \u2194 Continuous f :=\n  h.toHomeomorph.comp_continuous_iff\n#align isometry_equiv.comp_continuous_iff IsometryEquiv.comp_continuous_iff\n\n/- warning: isometry_equiv.comp_continuous_iff' -> IsometryEquiv.comp_continuous_iff' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {\u03b3 : Type.{u3}} [_inst_4 : TopologicalSpace.{u3} \u03b3] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) {f : \u03b2 -> \u03b3}, Iff (Continuous.{u1, u3} \u03b1 \u03b3 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) _inst_4 (Function.comp.{succ u1, succ u2, succ u3} \u03b1 \u03b2 \u03b3 f (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) h))) (Continuous.{u2, u3} \u03b2 \u03b3 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2)) _inst_4 f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] {\u03b3 : Type.{u1}} [_inst_4 : TopologicalSpace.{u1} \u03b3] (h : IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) {f : \u03b2 -> \u03b3}, Iff (Continuous.{u2, u1} \u03b1 \u03b3 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) _inst_4 (Function.comp.{succ u2, succ u3, succ u1} \u03b1 \u03b2 \u03b3 f (FunLike.coe.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u3), succ u2, succ u3} (IsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2))) h))) (Continuous.{u3, u1} \u03b2 \u03b3 (UniformSpace.toTopologicalSpace.{u3} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u3} \u03b2 _inst_2)) _inst_4 f)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.comp_continuous_iff' IsometryEquiv.comp_continuous_iff'\u2093'. -/\n@[simp]\ntheorem comp_continuous_iff' {\u03b3} [TopologicalSpace \u03b3] (h : \u03b1 \u2243\u1d62 \u03b2) {f : \u03b2 \u2192 \u03b3} :\n    Continuous (f \u2218 h) \u2194 Continuous f :=\n  h.toHomeomorph.comp_continuous_iff'\n#align isometry_equiv.comp_continuous_iff' IsometryEquiv.comp_continuous_iff'\n\n/-- The group of isometries. -/\ninstance : Group (\u03b1 \u2243\u1d62 \u03b1) where\n  one := IsometryEquiv.refl _\n  mul e\u2081 e\u2082 := e\u2082.trans e\u2081\n  inv := IsometryEquiv.symm\n  mul_assoc e\u2081 e\u2082 e\u2083 := rfl\n  one_mul e := ext fun _ => rfl\n  mul_one e := ext fun _ => rfl\n  mul_left_inv e := ext e.symm_apply_apply\n\n/- warning: isometry_equiv.coe_one -> IsometryEquiv.coe_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1], Eq.{succ u1} (\u03b1 -> \u03b1) (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (OfNat.ofNat.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) 1 (OfNat.mk.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) 1 (One.one.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (MulOneClass.toHasOne.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Monoid.toMulOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvMonoid.toMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivInvMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.group.{u1} \u03b1 _inst_1))))))))) (id.{succ u1} \u03b1)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1], Eq.{succ u1} (forall (\u1fb0 : \u03b1), (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) \u1fb0) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) (OfNat.ofNat.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) 1 (One.toOfNat1.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (InvOneClass.toOne.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvOneMonoid.toInvOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivisionMonoid.toDivInvOneMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivisionMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.instGroupIsometryEquiv.{u1} \u03b1 _inst_1)))))))) (id.{succ u1} \u03b1)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.coe_one IsometryEquiv.coe_one\u2093'. -/\n@[simp]\ntheorem coe_one : \u21d1(1 : \u03b1 \u2243\u1d62 \u03b1) = id :=\n  rfl\n#align isometry_equiv.coe_one IsometryEquiv.coe_one\n\n/- warning: isometry_equiv.coe_mul -> IsometryEquiv.coe_mul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e\u2081 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (e\u2082 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1), Eq.{succ u1} (\u03b1 -> \u03b1) (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (HMul.hMul.{u1, u1, u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (instHMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (MulOneClass.toHasMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Monoid.toMulOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvMonoid.toMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivInvMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.group.{u1} \u03b1 _inst_1)))))) e\u2081 e\u2082)) (Function.comp.{succ u1, succ u1, succ u1} \u03b1 \u03b1 \u03b1 (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) e\u2081) (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) e\u2082))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e\u2081 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (e\u2082 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1), Eq.{succ u1} (forall (\u1fb0 : \u03b1), (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) \u1fb0) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) (HMul.hMul.{u1, u1, u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (instHMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (MulOneClass.toMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Monoid.toMulOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvMonoid.toMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivInvMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.instGroupIsometryEquiv.{u1} \u03b1 _inst_1)))))) e\u2081 e\u2082)) (Function.comp.{succ u1, succ u1, succ u1} \u03b1 \u03b1 \u03b1 (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) e\u2081) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) e\u2082))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.coe_mul IsometryEquiv.coe_mul\u2093'. -/\n@[simp]\ntheorem coe_mul (e\u2081 e\u2082 : \u03b1 \u2243\u1d62 \u03b1) : \u21d1(e\u2081 * e\u2082) = e\u2081 \u2218 e\u2082 :=\n  rfl\n#align isometry_equiv.coe_mul IsometryEquiv.coe_mul\n\n/- warning: isometry_equiv.mul_apply -> IsometryEquiv.mul_apply is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e\u2081 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (e\u2082 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (x : \u03b1), Eq.{succ u1} \u03b1 (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (HMul.hMul.{u1, u1, u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (instHMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (MulOneClass.toHasMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Monoid.toMulOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvMonoid.toMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivInvMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.group.{u1} \u03b1 _inst_1)))))) e\u2081 e\u2082) x) (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) e\u2081 (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) e\u2082 x))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e\u2081 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (e\u2082 : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (x : \u03b1), Eq.{succ u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) x) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) (HMul.hMul.{u1, u1, u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (instHMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (MulOneClass.toMul.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Monoid.toMulOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvMonoid.toMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivInvMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.instGroupIsometryEquiv.{u1} \u03b1 _inst_1)))))) e\u2081 e\u2082) x) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) e\u2081 (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) e\u2082 x))\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.mul_apply IsometryEquiv.mul_apply\u2093'. -/\ntheorem mul_apply (e\u2081 e\u2082 : \u03b1 \u2243\u1d62 \u03b1) (x : \u03b1) : (e\u2081 * e\u2082) x = e\u2081 (e\u2082 x) :=\n  rfl\n#align isometry_equiv.mul_apply IsometryEquiv.mul_apply\n\n/- warning: isometry_equiv.inv_apply_self -> IsometryEquiv.inv_apply_self is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (x : \u03b1), Eq.{succ u1} \u03b1 (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Inv.inv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvMonoid.toHasInv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivInvMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.group.{u1} \u03b1 _inst_1))) e) (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) e x)) x\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (x : \u03b1), Eq.{succ u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (a : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) a) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) e x)) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) (Inv.inv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (InvOneClass.toInv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvOneMonoid.toInvOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivisionMonoid.toDivInvOneMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivisionMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.instGroupIsometryEquiv.{u1} \u03b1 _inst_1))))) e) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) e x)) x\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.inv_apply_self IsometryEquiv.inv_apply_self\u2093'. -/\n@[simp]\ntheorem inv_apply_self (e : \u03b1 \u2243\u1d62 \u03b1) (x : \u03b1) : e\u207b\u00b9 (e x) = x :=\n  e.symm_apply_apply x\n#align isometry_equiv.inv_apply_self IsometryEquiv.inv_apply_self\n\n/- warning: isometry_equiv.apply_inv_self -> IsometryEquiv.apply_inv_self is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (x : \u03b1), Eq.{succ u1} \u03b1 (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) e (coeFn.{succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (fun (_x : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) => \u03b1 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Inv.inv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvMonoid.toHasInv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivInvMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.group.{u1} \u03b1 _inst_1))) e) x)) x\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] (e : IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (x : \u03b1), Eq.{succ u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (a : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) a) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) (Inv.inv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (InvOneClass.toInv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvOneMonoid.toInvOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivisionMonoid.toDivInvOneMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivisionMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.instGroupIsometryEquiv.{u1} \u03b1 _inst_1))))) e) x)) (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) e (FunLike.coe.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (EquivLike.toEmbeddingLike.{succ u1, succ u1, succ u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) \u03b1 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1))) (Inv.inv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (InvOneClass.toInv.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivInvOneMonoid.toInvOneClass.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (DivisionMonoid.toDivInvOneMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (Group.toDivisionMonoid.{u1} (IsometryEquiv.{u1, u1} \u03b1 \u03b1 _inst_1 _inst_1) (IsometryEquiv.instGroupIsometryEquiv.{u1} \u03b1 _inst_1))))) e) x)) x\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.apply_inv_self IsometryEquiv.apply_inv_self\u2093'. -/\n@[simp]\ntheorem apply_inv_self (e : \u03b1 \u2243\u1d62 \u03b1) (x : \u03b1) : e (e\u207b\u00b9 x) = x :=\n  e.apply_symm_apply x\n#align isometry_equiv.apply_inv_self IsometryEquiv.apply_inv_self\n\n#print IsometryEquiv.completeSpace /-\nprotected theorem completeSpace [CompleteSpace \u03b2] (e : \u03b1 \u2243\u1d62 \u03b2) : CompleteSpace \u03b1 :=\n  completeSpace_of_isComplete_univ <|\n    isComplete_of_complete_image e.Isometry.UniformInducing <| by\n      rwa [Set.image_univ, IsometryEquiv.range_eq_univ, \u2190 completeSpace_iff_isComplete_univ]\n#align isometry_equiv.complete_space IsometryEquiv.completeSpace\n-/\n\n#print IsometryEquiv.completeSpace_iff /-\ntheorem completeSpace_iff (e : \u03b1 \u2243\u1d62 \u03b2) : CompleteSpace \u03b1 \u2194 CompleteSpace \u03b2 :=\n  by\n  constructor <;> intro H\n  exacts[e.symm.complete_space, e.complete_space]\n#align isometry_equiv.complete_space_iff IsometryEquiv.completeSpace_iff\n-/\n\nend PseudoEMetricSpace\n\nsection PseudoMetricSpace\n\nvariable [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] (h : \u03b1 \u2243\u1d62 \u03b2)\n\n#print IsometryEquiv.diam_image /-\n@[simp]\ntheorem diam_image (s : Set \u03b1) : Metric.diam (h '' s) = Metric.diam s :=\n  h.Isometry.diam_image s\n#align isometry_equiv.diam_image IsometryEquiv.diam_image\n-/\n\n#print IsometryEquiv.diam_preimage /-\n@[simp]\ntheorem diam_preimage (s : Set \u03b2) : Metric.diam (h \u207b\u00b9' s) = Metric.diam s := by\n  rw [\u2190 image_symm, diam_image]\n#align isometry_equiv.diam_preimage IsometryEquiv.diam_preimage\n-/\n\n#print IsometryEquiv.diam_univ /-\ntheorem diam_univ : Metric.diam (univ : Set \u03b1) = Metric.diam (univ : Set \u03b2) :=\n  congr_arg ENNReal.toReal h.ediam_univ\n#align isometry_equiv.diam_univ IsometryEquiv.diam_univ\n-/\n\n/- warning: isometry_equiv.preimage_ball -> IsometryEquiv.preimage_ball is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b2) (r : Real), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h) (Metric.ball.{u2} \u03b2 _inst_2 x r)) (Metric.ball.{u1} \u03b1 _inst_1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) h) x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b2) (r : Real), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h) (Metric.ball.{u2} \u03b2 _inst_2 x r)) (Metric.ball.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) x) _inst_1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) h) x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.preimage_ball IsometryEquiv.preimage_ball\u2093'. -/\n@[simp]\ntheorem preimage_ball (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b2) (r : \u211d) :\n    h \u207b\u00b9' Metric.ball x r = Metric.ball (h.symm x) r := by\n  rw [\u2190 h.isometry.preimage_ball (h.symm x) r, h.apply_symm_apply]\n#align isometry_equiv.preimage_ball IsometryEquiv.preimage_ball\n\n/- warning: isometry_equiv.preimage_sphere -> IsometryEquiv.preimage_sphere is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b2) (r : Real), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h) (Metric.sphere.{u2} \u03b2 _inst_2 x r)) (Metric.sphere.{u1} \u03b1 _inst_1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) h) x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b2) (r : Real), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h) (Metric.sphere.{u2} \u03b2 _inst_2 x r)) (Metric.sphere.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) x) _inst_1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) h) x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.preimage_sphere IsometryEquiv.preimage_sphere\u2093'. -/\n@[simp]\ntheorem preimage_sphere (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b2) (r : \u211d) :\n    h \u207b\u00b9' Metric.sphere x r = Metric.sphere (h.symm x) r := by\n  rw [\u2190 h.isometry.preimage_sphere (h.symm x) r, h.apply_symm_apply]\n#align isometry_equiv.preimage_sphere IsometryEquiv.preimage_sphere\n\n/- warning: isometry_equiv.preimage_closed_ball -> IsometryEquiv.preimage_closedBall is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b2) (r : Real), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h) (Metric.closedBall.{u2} \u03b2 _inst_2 x r)) (Metric.closedBall.{u1} \u03b1 _inst_1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) (fun (_x : IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) => \u03b2 -> \u03b1) (IsometryEquiv.hasCoeToFun.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) h) x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b2) (r : Real), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h) (Metric.closedBall.{u2} \u03b2 _inst_2 x r)) (Metric.closedBall.{u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) x) _inst_1 (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 (fun (_x : \u03b2) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b2) => \u03b1) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u2, succ u1} (IsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) \u03b2 \u03b1 (IsometryEquiv.instEquivLikeIsometryEquiv.{u2, u1} \u03b2 \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)))) (IsometryEquiv.symm.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) h) x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.preimage_closed_ball IsometryEquiv.preimage_closedBall\u2093'. -/\n@[simp]\ntheorem preimage_closedBall (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b2) (r : \u211d) :\n    h \u207b\u00b9' Metric.closedBall x r = Metric.closedBall (h.symm x) r := by\n  rw [\u2190 h.isometry.preimage_closed_ball (h.symm x) r, h.apply_symm_apply]\n#align isometry_equiv.preimage_closed_ball IsometryEquiv.preimage_closedBall\n\n/- warning: isometry_equiv.image_ball -> IsometryEquiv.image_ball is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b1) (r : Real), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h) (Metric.ball.{u1} \u03b1 _inst_1 x r)) (Metric.ball.{u2} \u03b2 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b1) (r : Real), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h) (Metric.ball.{u1} \u03b1 _inst_1 x r)) (Metric.ball.{u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.image_ball IsometryEquiv.image_ball\u2093'. -/\n@[simp]\ntheorem image_ball (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b1) (r : \u211d) : h '' Metric.ball x r = Metric.ball (h x) r := by\n  rw [\u2190 h.preimage_symm, h.symm.preimage_ball, symm_symm]\n#align isometry_equiv.image_ball IsometryEquiv.image_ball\n\n/- warning: isometry_equiv.image_sphere -> IsometryEquiv.image_sphere is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b1) (r : Real), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h) (Metric.sphere.{u1} \u03b1 _inst_1 x r)) (Metric.sphere.{u2} \u03b2 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b1) (r : Real), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h) (Metric.sphere.{u1} \u03b1 _inst_1 x r)) (Metric.sphere.{u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.image_sphere IsometryEquiv.image_sphere\u2093'. -/\n@[simp]\ntheorem image_sphere (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b1) (r : \u211d) :\n    h '' Metric.sphere x r = Metric.sphere (h x) r := by\n  rw [\u2190 h.preimage_symm, h.symm.preimage_sphere, symm_symm]\n#align isometry_equiv.image_sphere IsometryEquiv.image_sphere\n\n/- warning: isometry_equiv.image_closed_ball -> IsometryEquiv.image_closedBall is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b1) (r : Real), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h) (Metric.closedBall.{u1} \u03b1 _inst_1 x r)) (Metric.closedBall.{u2} \u03b2 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (fun (_x : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (IsometryEquiv.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) h x) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] (h : IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) (x : \u03b1) (r : Real), Eq.{succ u2} (Set.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h) (Metric.closedBall.{u1} \u03b1 _inst_1 x r)) (Metric.closedBall.{u2} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) x) _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (IsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 (IsometryEquiv.instEquivLikeIsometryEquiv.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2)))) h x) r)\nCase conversion may be inaccurate. Consider using '#align isometry_equiv.image_closed_ball IsometryEquiv.image_closedBall\u2093'. -/\n@[simp]\ntheorem image_closedBall (h : \u03b1 \u2243\u1d62 \u03b2) (x : \u03b1) (r : \u211d) :\n    h '' Metric.closedBall x r = Metric.closedBall (h x) r := by\n  rw [\u2190 h.preimage_symm, h.symm.preimage_closed_ball, symm_symm]\n#align isometry_equiv.image_closed_ball IsometryEquiv.image_closedBall\n\nend PseudoMetricSpace\n\nend IsometryEquiv\n\n#print Isometry.isometryEquivOnRange /-\n/-- An isometry induces an isometric isomorphism between the source space and the\nrange of the isometry. -/\n@[simps (config := { simpRhs := true }) toEquiv apply]\ndef Isometry.isometryEquivOnRange [EMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (h : Isometry f) : \u03b1 \u2243\u1d62 range f\n    where\n  isometry_toFun x y := by simpa [Subtype.edist_eq] using h x y\n  toEquiv := Equiv.ofInjective f h.Injective\n#align isometry.isometry_equiv_on_range Isometry.isometryEquivOnRange\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/MetricSpace/Isometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.737261124974089}}
{"text": "/-\nCopyright (c) 2021 Henry Swanson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henry Swanson, Patrick Massot\n-/\nimport analysis.special_functions.exponential\nimport combinatorics.derangements.finite\nimport order.filter.basic\n\n/-!\n# Derangement exponential series\n\nThis file proves that the probability of a permutation on n elements being a derangement is 1/e.\nThe specific lemma is `num_derangements_tendsto_inv_e`.\n-/\nopen filter\n\nopen_locale big_operators\nopen_locale topological_space\n\ntheorem num_derangements_tendsto_inv_e :\n  tendsto (\u03bb n, (num_derangements n : \u211d) / n.factorial) at_top\n  (\ud835\udcdd (real.exp (-1))) :=\nbegin\n  -- we show that d(n)/n! is the partial sum of exp(-1), but offset by 1.\n  -- this isn't entirely obvious, since we have to ensure that asc_factorial and\n  -- factorial interact in the right way, e.g., that k \u2264 n always\n  let s : \u2115 \u2192 \u211d := \u03bb n, \u2211 k in finset.range n, (-1 : \u211d)^k / k.factorial,\n  suffices : \u2200 n : \u2115, (num_derangements n : \u211d) / n.factorial = s(n+1),\n  { simp_rw this,\n    -- shift the function by 1, and then use the fact that the partial sums\n    -- converge to the infinite sum\n    rw tendsto_add_at_top_iff_nat 1,\n    apply has_sum.tendsto_sum_nat,\n    -- there's no specific lemma for \u211d that \u2211 x^k/k! sums to exp(x), but it's\n    -- true in more general fields, so use that lemma\n    rw real.exp_eq_exp_\u211d_\u211d,\n    exact exp_series_field_has_sum_exp (-1 : \u211d) },\n  intro n,\n  rw [\u2190 int.cast_coe_nat, num_derangements_sum],\n  push_cast,\n  rw finset.sum_div,\n  -- get down to individual terms\n  refine finset.sum_congr (refl _) _,\n  intros k hk,\n  have h_le : k \u2264 n := finset.mem_range_succ_iff.mp hk,\n  rw [nat.asc_factorial_eq_div, add_tsub_cancel_of_le h_le],\n  push_cast [nat.factorial_dvd_factorial h_le],\n  field_simp [nat.factorial_ne_zero],\n  ring,\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/combinatorics/derangements/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888613, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.73726111275953}}
{"text": "import data.nat.digits\n\nopen nat\n\n-- Los d\u00edgitos de n en base b son menores que b.\nlemma digits_lt_base\n  (b : \u2115)\n  (hb : 2 \u2264 b)\n  (n : \u2115)\n  : \u2200 d \u2208 digits b n, d < b :=\nbegin\n  cases b with b,\n  { linarith },\n  { cases b with b,\n    { linarith },\n    { clear hb,\n      apply nat.strong_induction_on n,\n      clear n,\n      intro n,\n      intro IH,\n      intro d,\n      intro hd,\n      unfold digits at hd IH,\n      have h := digits_aux_def (b+2) (by linarith) n,\n      cases n with n,\n      { finish },\n      { replace h := h (nat.zero_lt_succ n),\n        rw h at hd,\n        cases hd,\n        { rw hd,\n          exact n.succ.mod_lt (by linarith) },\n        { apply IH _ _ d hd,\n          apply nat.div_lt_self (nat.succ_pos _),\n          linarith }}}},\nend\n\n-- Los d\u00edgitos de la expresi\u00f3n decimal de un n\u00famero son menores o\n-- iguales que 9.\nlemma digits_le_9\n  (n : \u2115)\n  : \u2200 (d \u2208 (digits 10 n)), d \u2264 9 :=\n\u03bb d hd, nat.le_of_lt_succ $ digits_lt_base 10 (by norm_num) n _ hd\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Los_digitos_son_menores_que_la_base.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7372599563116607}}
{"text": "import data.finset\nimport data.fintype\nimport data.fin\nimport data.rat\n\nopen function\nopen finset\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariables [fintype \u03b1] [fintype \u03b2] \n\nnamespace fintype\n\ntheorem card_image_of_injective [decidable_eq \u03b2] {f : \u03b1 \u2192 \u03b2}: injective f \u2192 finset.card ((elems \u03b1).image f) = card \u03b1 :=\n  finset.card_image_of_injective (elems \u03b1)\n\nend fintype\n\nsection surj\n\nopen fintype\n\n-- for fintypes (where we can define the image), surjection is equivalent to the image being everything\n\nlemma univ_eq_image_of_surj [decidable_eq \u03b2] (f : \u03b1 \u2192 \u03b2): surjective f \u2192 elems \u03b2 = image f (elems \u03b1) := \nbegin\n  intro,\n  ext b, rw mem_image, apply iff_of_true (complete _), \n  cases \u2039surjective f\u203a b with a ha,\n  exact \u27e8a, complete _, ha\u27e9, \nend\n\nlemma surj_of_univ_eq_image [decidable_eq \u03b2] (f : \u03b1 \u2192 \u03b2): elems \u03b2 = image f (elems \u03b1) \u2192 surjective f :=\nbegin\n  intros h b,\n  have q: b \u2208 elems \u03b2 := complete b,\n  rw h at q,\n  simp at q,\n  rcases q with \u27e8a, _, r\u27e9,\n  exact \u27e8a, r\u27e9\nend\n\nlemma univ_eq_image_iff_surj [decidable_eq \u03b2] (f : \u03b1 \u2192 \u03b2): elems \u03b2 = image f (elems \u03b1) \u2194 surjective f :=\n\u27e8surj_of_univ_eq_image _, univ_eq_image_of_surj _\u27e9\n\n-- ed's proof\n-- idea: show f is injective as well, so it's bijective, so \u03b1 and \u03b2 have the same cardinality: contradiction \nlemma fintype.not_surjective_of_card_lt {f : \u03b1 \u2192 \u03b2}\n  (hcard : fintype.card \u03b1 < fintype.card \u03b2) (h_surj : surjective f) : false :=\n  begin\n    have h_inj : injective f,\n      intros a1 a2 h,\n      refine @finset.inj_on_of_surj_on_of_card_le _ _ (fintype.elems \u03b1) (fintype.elems \u03b2) (\u03bb a ha, f a)\n        (\u03bb a ha, fintype.complete _) _ (le_of_lt hcard) _ _ (fintype.complete _) (fintype.complete _) h,\n      refine \u03bb b hb, let \u27e8a,ha\u27e9 := h_surj b in \u27e8a,fintype.complete _, eq.symm ha\u27e9,\n    apply ne_of_lt hcard,\n    apply fintype.card_congr,\n    apply equiv.of_bijective \u27e8h_inj, h_surj\u27e9,\n  end\n\n-- my proof 1\n-- idea: show f is injective as well, so its image is the same size as \u03b1, but it's surjective: contradiction\nlemma no_surj_to_smaller_set [decidable_eq \u03b2] (hst : card \u03b1 < card \u03b2) (f : \u03b1 \u2192 \u03b2) : \u00ac surjective f := \nbegin\n  intro,\n  have: injective f,\n    intros a1 a2 h,\n    refine inj_on_of_surj_on_of_card_le (\u03bb a _, f a) (\u03bb _ _, mem_univ _) (\u03bb b _, _) (le_of_lt hst) (complete _) (complete _) h,\n    cases \u2039surjective f\u203a b with a _,\n    exact \u27e8a, complete _, \u2039f a = b\u203a.symm\u27e9,\n  apply not_le_of_gt hst,\n  rw [\u2190 card_image_of_injective \u2039injective f\u203a, \u2190 univ_eq_image_of_surj f \u2039surjective f\u203a],\n  trivial\nend\n\n-- my proof 2\n-- idea: show f has an injective inverse, so the image of f\u207b\u00b9 is the same size as \u03b2, but the image is a subset of \u03b1, so card \u03b1 \u2265 card \u03b2\nlemma ge_card_of_surj [decidable_eq \u03b1] {f : \u03b1 \u2192 \u03b2} : surjective f \u2192 card \u03b2 \u2264 card \u03b1 :=\nbegin\n  intro,\n  let f_inv := surj_inv \u2039surjective f\u203a,\n  have: injective f_inv := injective_surj_inv _,\n  rw \u2190 card_image_of_injective \u2039injective f_inv\u203a,\n  apply card_le_of_subset,\n  apply subset_univ\nend\n\n-- apply my proof 1 to fins\nlemma no_surj_to_smaller_fin (n m : \u2115) (H : n < m) (f : fin n \u2192 fin m) : \u00ac surjective f :=\nbegin\n  apply no_surj_to_smaller_set,\n  repeat {rwa fintype.card_fin},\nend\n\n-- apply my proof 2 to fins\nlemma no_surj_to_smaller_fin' (n m : \u2115) (H : n < m) (f : fin n \u2192 fin m) : \u00ac surjective f :=\nbegin\n  intro f_surj,\n  apply not_le_of_gt H,\n  rw [\u2190 fintype.card_fin m, \u2190 fintype.card_fin n], \n  apply ge_card_of_surj f_surj,\nend\n\n-- a lemma which might want to belong somewhere (effectively used in my proof 2)\nlemma no_inj_to_smaller_set [decidable_eq \u03b2] (H : card \u03b2 < card \u03b1) (f : \u03b1 \u2192 \u03b2) : \u00ac injective f :=\nbegin\n  intro f_inj,\n  have := card_image_of_injective f_inj,\n  apply not_le_of_gt H,\n  rw \u2190 this,\n  apply card_le_of_subset,\n  apply subset_univ\nend\n\nend surj", "meta": {"author": "b-mehta", "repo": "lean-experiments", "sha": "5f0aed189f724ae6f739ec75dcdddcd2687614e1", "save_path": "github-repos/lean/b-mehta-lean-experiments", "path": "github-repos/lean/b-mehta-lean-experiments/lean-experiments-5f0aed189f724ae6f739ec75dcdddcd2687614e1/src/combinatorics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7372539613020542}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport order.succ_pred.basic\n\n/-!\n# Successor and predecessor limits\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define the predicate `order.is_succ_limit` for \"successor limits\", values that don't cover any\nothers. They are so named since they can't be the successors of anything smaller. We define\n`order.is_pred_limit` analogously, and prove basic results.\n\n## Todo\n\nThe plan is to eventually replace `ordinal.is_limit` and `cardinal.is_limit` with the common\npredicate `order.is_succ_limit`.\n-/\n\nvariables {\u03b1 : Type*}\n\nnamespace order\nopen function set order_dual\n\n/-! ### Successor limits -/\n\nsection has_lt\nvariables [has_lt \u03b1]\n\n/-- A successor limit is a value that doesn't cover any other.\n\nIt's so named because in a successor order, a successor limit can't be the successor of anything\nsmaller. -/\ndef is_succ_limit (a : \u03b1) : Prop := \u2200 b, \u00ac b \u22d6 a\n\nlemma not_is_succ_limit_iff_exists_covby (a : \u03b1) : \u00ac is_succ_limit a \u2194 \u2203 b, b \u22d6 a :=\nby simp [is_succ_limit]\n\n@[simp] lemma is_succ_limit_of_dense [densely_ordered \u03b1] (a : \u03b1) : is_succ_limit a := \u03bb b, not_covby\n\nend has_lt\n\nsection preorder\nvariables [preorder \u03b1] {a : \u03b1}\n\nprotected lemma _root_.is_min.is_succ_limit : is_min a \u2192 is_succ_limit a :=\n\u03bb h b hab, not_is_min_of_lt hab.lt h\n\nlemma is_succ_limit_bot [order_bot \u03b1] : is_succ_limit (\u22a5 : \u03b1) := is_min_bot.is_succ_limit\n\nvariables [succ_order \u03b1]\n\nprotected lemma is_succ_limit.is_max (h : is_succ_limit (succ a)) : is_max a :=\nby { by_contra H, exact h a (covby_succ_of_not_is_max H) }\n\nlemma not_is_succ_limit_succ_of_not_is_max (ha : \u00ac is_max a) : \u00ac is_succ_limit (succ a) :=\nby { contrapose! ha, exact ha.is_max }\n\nsection no_max_order\nvariables [no_max_order \u03b1]\n\nlemma is_succ_limit.succ_ne (h : is_succ_limit a) (b : \u03b1) : succ b \u2260 a :=\nby { rintro rfl, exact not_is_max _ h.is_max }\n\n@[simp] lemma not_is_succ_limit_succ (a : \u03b1) : \u00ac is_succ_limit (succ a) := \u03bb h, h.succ_ne _ rfl\n\nend no_max_order\n\nsection is_succ_archimedean\nvariable [is_succ_archimedean \u03b1]\n\nlemma is_succ_limit.is_min_of_no_max [no_max_order \u03b1] (h : is_succ_limit a) : is_min a :=\n\u03bb b hb, begin\n  rcases hb.exists_succ_iterate with \u27e8_ | n, rfl\u27e9,\n  { exact le_rfl },\n  { rw iterate_succ_apply' at h,\n    exact (not_is_succ_limit_succ _ h).elim }\nend\n\n@[simp] lemma is_succ_limit_iff_of_no_max [no_max_order \u03b1] : is_succ_limit a \u2194 is_min a :=\n\u27e8is_succ_limit.is_min_of_no_max, is_min.is_succ_limit\u27e9\n\nlemma not_is_succ_limit_of_no_max [no_min_order \u03b1] [no_max_order \u03b1] : \u00ac is_succ_limit a := by simp\n\nend is_succ_archimedean\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] [succ_order \u03b1] {a b : \u03b1} {C : \u03b1 \u2192 Sort*}\n\nlemma is_succ_limit_of_succ_ne (h : \u2200 b, succ b \u2260 a) : is_succ_limit a := \u03bb b hba, h b hba.succ_eq\n\nlemma not_is_succ_limit_iff : \u00ac is_succ_limit a \u2194 \u2203 b, \u00ac is_max b \u2227 succ b = a :=\nbegin\n  rw not_is_succ_limit_iff_exists_covby,\n  refine exists_congr (\u03bb b, \u27e8\u03bb hba, \u27e8hba.lt.not_is_max, hba.succ_eq\u27e9, _\u27e9),\n  rintro \u27e8h, rfl\u27e9,\n  exact covby_succ_of_not_is_max h\nend\n\n/-- See `not_is_succ_limit_iff` for a version that states that `a` is a successor of a value other\nthan itself. -/\nlemma mem_range_succ_of_not_is_succ_limit (h : \u00ac is_succ_limit a) : a \u2208 range (@succ \u03b1 _ _) :=\nby { cases not_is_succ_limit_iff.1 h with b hb, exact \u27e8b, hb.2\u27e9 }\n\nlemma is_succ_limit_of_succ_lt (H : \u2200 a < b, succ a < b) : is_succ_limit b :=\n\u03bb a hab, (H a hab.lt).ne hab.succ_eq\n\nlemma is_succ_limit.succ_lt (hb : is_succ_limit b) (ha : a < b) : succ a < b :=\nbegin\n  by_cases h : is_max a,\n  { rwa h.succ_eq },\n  { rw [lt_iff_le_and_ne, succ_le_iff_of_not_is_max h],\n    refine \u27e8ha, \u03bb hab, _\u27e9,\n    subst hab,\n    exact (h hb.is_max).elim }\nend\n\nlemma is_succ_limit.succ_lt_iff (hb : is_succ_limit b) : succ a < b \u2194 a < b :=\n\u27e8\u03bb h, (le_succ a).trans_lt h, hb.succ_lt\u27e9\n\nlemma is_succ_limit_iff_succ_lt : is_succ_limit b \u2194 \u2200 a < b, succ a < b :=\n\u27e8\u03bb hb a, hb.succ_lt, is_succ_limit_of_succ_lt\u27e9\n\n/-- A value can be built by building it on successors and successor limits. -/\n@[elab_as_eliminator] noncomputable def is_succ_limit_rec_on (b : \u03b1)\n  (hs : \u03a0 a, \u00ac is_max a \u2192 C (succ a)) (hl : \u03a0 a, is_succ_limit a \u2192 C a) : C b :=\nbegin\n  by_cases hb : is_succ_limit b,\n  { exact hl b hb },\n  { have H := classical.some_spec (not_is_succ_limit_iff.1 hb),\n    rw \u2190H.2,\n    exact hs _ H.1 }\nend\n\nlemma is_succ_limit_rec_on_limit (hs : \u03a0 a, \u00ac is_max a \u2192 C (succ a))\n  (hl : \u03a0 a, is_succ_limit a \u2192 C a) (hb : is_succ_limit b) :\n  @is_succ_limit_rec_on \u03b1 _ _ C b hs hl = hl b hb :=\nby { classical, exact dif_pos hb }\n\nlemma is_succ_limit_rec_on_succ' (hs : \u03a0 a, \u00ac is_max a \u2192 C (succ a))\n  (hl : \u03a0 a, is_succ_limit a \u2192 C a) {b : \u03b1} (hb : \u00ac is_max b) :\n  @is_succ_limit_rec_on \u03b1 _ _ C (succ b) hs hl = hs b hb :=\nbegin\n  have hb' := not_is_succ_limit_succ_of_not_is_max hb,\n  have H := classical.some_spec (not_is_succ_limit_iff.1 hb'),\n  rw is_succ_limit_rec_on,\n  simp only [cast_eq_iff_heq, hb', not_false_iff, eq_mpr_eq_cast, dif_neg],\n  congr,\n  { exact (succ_eq_succ_iff_of_not_is_max H.1 hb).1 H.2 },\n  { apply proof_irrel_heq }\nend\n\nsection no_max_order\nvariables [no_max_order \u03b1]\n\n@[simp] lemma is_succ_limit_rec_on_succ (hs : \u03a0 a, \u00ac is_max a \u2192 C (succ a))\n  (hl : \u03a0 a, is_succ_limit a \u2192 C a) (b : \u03b1) :\n  @is_succ_limit_rec_on \u03b1 _ _ C (succ b) hs hl = hs b (not_is_max b) :=\nis_succ_limit_rec_on_succ' _ _ _\n\nlemma is_succ_limit_iff_succ_ne : is_succ_limit a \u2194 \u2200 b, succ b \u2260 a :=\n\u27e8is_succ_limit.succ_ne, is_succ_limit_of_succ_ne\u27e9\n\nlemma not_is_succ_limit_iff' : \u00ac is_succ_limit a \u2194 a \u2208 range (@succ \u03b1 _ _) :=\nby { simp_rw [is_succ_limit_iff_succ_ne, not_forall, not_ne_iff], refl }\n\nend no_max_order\n\nsection is_succ_archimedean\nvariable [is_succ_archimedean \u03b1]\n\nprotected lemma is_succ_limit.is_min (h : is_succ_limit a) : is_min a :=\n\u03bb b hb, begin\n  revert h,\n  refine succ.rec (\u03bb _, le_rfl) (\u03bb c hbc H hc, _) hb,\n  have := hc.is_max.succ_eq,\n  rw this at hc \u22a2,\n  exact H hc\nend\n\n@[simp] lemma is_succ_limit_iff : is_succ_limit a \u2194 is_min a :=\n\u27e8is_succ_limit.is_min, is_min.is_succ_limit\u27e9\n\nlemma not_is_succ_limit [no_min_order \u03b1] : \u00ac is_succ_limit a := by simp\n\nend is_succ_archimedean\nend partial_order\n\n/-! ### Predecessor limits -/\n\nsection has_lt\nvariables [has_lt \u03b1] {a : \u03b1}\n\n/-- A predecessor limit is a value that isn't covered by any other.\n\nIt's so named because in a predecessor order, a predecessor limit can't be the predecessor of\nanything greater. -/\ndef is_pred_limit (a : \u03b1) : Prop := \u2200 b, \u00ac a \u22d6 b\n\nlemma not_is_pred_limit_iff_exists_covby (a : \u03b1) : \u00ac is_pred_limit a \u2194 \u2203 b, a \u22d6 b :=\nby simp [is_pred_limit]\n\nlemma is_pred_limit_of_dense [densely_ordered \u03b1] (a : \u03b1) : is_pred_limit a := \u03bb b, not_covby\n\n@[simp] lemma is_succ_limit_to_dual_iff : is_succ_limit (to_dual a) \u2194 is_pred_limit a :=\nby simp [is_succ_limit, is_pred_limit]\n\n@[simp] lemma is_pred_limit_to_dual_iff : is_pred_limit (to_dual a) \u2194 is_succ_limit a :=\nby simp [is_succ_limit, is_pred_limit]\n\nalias is_succ_limit_to_dual_iff \u2194 _ is_pred_limit.dual\nalias is_pred_limit_to_dual_iff \u2194 _ is_succ_limit.dual\n\nend has_lt\n\nsection preorder\nvariables [preorder \u03b1] {a : \u03b1}\n\nprotected lemma _root_.is_max.is_pred_limit : is_max a \u2192 is_pred_limit a :=\n\u03bb h b hab, not_is_max_of_lt hab.lt h\n\nlemma is_pred_limit_top [order_top \u03b1] : is_pred_limit (\u22a4 : \u03b1) := is_max_top.is_pred_limit\n\nvariables [pred_order \u03b1]\n\nprotected lemma is_pred_limit.is_min (h : is_pred_limit (pred a)) : is_min a :=\nby { by_contra H, exact h a (pred_covby_of_not_is_min H) }\n\n\n\nsection no_min_order\nvariables [no_min_order \u03b1]\n\nlemma is_pred_limit.pred_ne (h : is_pred_limit a) (b : \u03b1) : pred b \u2260 a :=\nby { rintro rfl, exact not_is_min _ h.is_min }\n\n@[simp] lemma not_is_pred_limit_pred (a : \u03b1) : \u00ac is_pred_limit (pred a) := \u03bb h, h.pred_ne _ rfl\n\nend no_min_order\n\nsection is_pred_archimedean\nvariables [is_pred_archimedean \u03b1]\n\nprotected lemma is_pred_limit.is_max_of_no_min [no_min_order \u03b1] (h : is_pred_limit a) : is_max a :=\nh.dual.is_min_of_no_max\n\n@[simp] lemma is_pred_limit_iff_of_no_min [no_min_order \u03b1] : is_pred_limit a \u2194 is_max a :=\nis_succ_limit_to_dual_iff.symm.trans is_succ_limit_iff_of_no_max\n\nlemma not_is_pred_limit_of_no_min [no_min_order \u03b1] [no_max_order \u03b1] : \u00ac is_pred_limit a :=\nby simp\n\nend is_pred_archimedean\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] [pred_order \u03b1] {a b : \u03b1} {C : \u03b1 \u2192 Sort*}\n\nlemma is_pred_limit_of_pred_ne (h : \u2200 b, pred b \u2260 a) : is_pred_limit a := \u03bb b hba, h b hba.pred_eq\n\nlemma not_is_pred_limit_iff : \u00ac is_pred_limit a \u2194 \u2203 b, \u00ac is_min b \u2227 pred b = a :=\nby { rw \u2190is_succ_limit_to_dual_iff, exact not_is_succ_limit_iff }\n\n/-- See `not_is_pred_limit_iff` for a version that states that `a` is a successor of a value other\nthan itself. -/\nlemma mem_range_pred_of_not_is_pred_limit (h : \u00ac is_pred_limit a) : a \u2208 range (@pred \u03b1 _ _) :=\nby { cases not_is_pred_limit_iff.1 h with b hb, exact \u27e8b, hb.2\u27e9 }\n\nlemma is_pred_limit_of_pred_lt (H : \u2200 a > b, pred a < b) : is_pred_limit b :=\n\u03bb a hab, (H a hab.lt).ne hab.pred_eq\n\nlemma is_pred_limit.lt_pred (h : is_pred_limit a) : a < b \u2192 a < pred b := h.dual.succ_lt\nlemma is_pred_limit.lt_pred_iff (h : is_pred_limit a) : a < pred b \u2194 a < b := h.dual.succ_lt_iff\n\nlemma is_pred_limit_iff_lt_pred : is_pred_limit a \u2194 \u2200 \u2983b\u2984, a < b \u2192 a < pred b :=\nis_succ_limit_to_dual_iff.symm.trans is_succ_limit_iff_succ_lt\n\n/-- A value can be built by building it on predecessors and predecessor limits. -/\n@[elab_as_eliminator] noncomputable def is_pred_limit_rec_on (b : \u03b1)\n  (hs : \u03a0 a, \u00ac is_min a \u2192 C (pred a)) (hl : \u03a0 a, is_pred_limit a \u2192 C a) : C b :=\n@is_succ_limit_rec_on \u03b1\u1d52\u1d48 _ _ _ _ hs (\u03bb a ha, hl _ ha.dual)\n\nlemma is_pred_limit_rec_on_limit (hs : \u03a0 a, \u00ac is_min a \u2192 C (pred a))\n  (hl : \u03a0 a, is_pred_limit a \u2192 C a) (hb : is_pred_limit b) :\n  @is_pred_limit_rec_on \u03b1 _ _ C b hs hl = hl b hb :=\nis_succ_limit_rec_on_limit _ _ hb.dual\n\nlemma is_pred_limit_rec_on_pred' (hs : \u03a0 a, \u00ac is_min a \u2192 C (pred a))\n  (hl : \u03a0 a, is_pred_limit a \u2192 C a) {b : \u03b1} (hb : \u00ac is_min b) :\n  @is_pred_limit_rec_on \u03b1 _ _ C (pred b) hs hl = hs b hb :=\nis_succ_limit_rec_on_succ' _ _ _\n\nsection no_min_order\nvariables [no_min_order \u03b1]\n\n@[simp] theorem is_pred_limit_rec_on_pred (hs : \u03a0 a, \u00ac is_min a \u2192 C (pred a))\n  (hl : \u03a0 a, is_pred_limit a \u2192 C a) (b : \u03b1) :\n  @is_pred_limit_rec_on \u03b1 _ _ C (pred b) hs hl = hs b (not_is_min b) :=\nis_succ_limit_rec_on_succ _ _ _\n\nend no_min_order\n\nsection is_pred_archimedean\nvariable [is_pred_archimedean \u03b1]\n\nprotected lemma is_pred_limit.is_max (h : is_pred_limit a) : is_max a := h.dual.is_min\n\n@[simp] lemma is_pred_limit_iff : is_pred_limit a \u2194 is_max a :=\nis_succ_limit_to_dual_iff.symm.trans is_succ_limit_iff\n\nlemma not_is_pred_limit [no_max_order \u03b1] : \u00ac is_pred_limit a := by simp\n\nend is_pred_archimedean\nend partial_order\nend order\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/succ_pred/limit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7372539592391436}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport number_theory.class_number.admissible_card_pow_degree\nimport number_theory.class_number.finite\nimport number_theory.function_field\n\n/-!\n# Class numbers of function fields\n\nThis file defines the class number of a function field as the (finite) cardinality of\nthe class group of its ring of integers. It also proves some elementary results\non the class number.\n\n## Main definitions\n- `function_field.class_number`: the class number of a function field is the (finite)\ncardinality of the class group of its ring of integers\n-/\n\nnamespace function_field\nopen_locale polynomial\n\nvariables (Fq F : Type) [field Fq] [fintype Fq] [field F]\nvariables [algebra Fq[X] F] [algebra (ratfunc Fq) F]\nvariables [is_scalar_tower Fq[X] (ratfunc Fq) F]\nvariables [function_field Fq F] [is_separable (ratfunc Fq) F]\n\nopen_locale classical\n\nnamespace ring_of_integers\n\nopen function_field\n\nnoncomputable instance  : fintype (class_group (ring_of_integers Fq F)) :=\nclass_group.fintype_of_admissible_of_finite (ratfunc Fq) F\n  (polynomial.card_pow_degree_is_admissible : absolute_value.is_admissible\n    (polynomial.card_pow_degree : absolute_value Fq[X] \u2124))\n\nend ring_of_integers\n\n/-- The class number in a function field is the (finite) cardinality of the class group. -/\nnoncomputable def class_number : \u2115 := fintype.card (class_group (ring_of_integers Fq F))\n\n/-- The class number of a function field is `1` iff the ring of integers is a PID. -/\ntheorem class_number_eq_one_iff :\n  class_number Fq F = 1 \u2194 is_principal_ideal_ring (ring_of_integers Fq F) :=\ncard_class_group_eq_one_iff\n\nend function_field\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/class_number/function_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7371836313363835}}
{"text": "-- begin header\n\nimport M40001.M40001_C2\n\nnamespace numbers\n\nvariables {X Y : Type}\n-- end header\n\n/- Section\nChapter 2. Numbers\n-/\n\n/- Sub-section\nCountability\n-/\n\n/-\nWe will be proving the Well-Ordered Principle (A non-empty set of natural numbers \nhas a least element) as it will be usful for proving theorems regarding countability.\n\nIn LEAN's maths library, there is a useful lemma that does the samething. \nSee nat.find\n-/\n\nopen function M40001\n\n/- Theorem\nThe Well-Ordered Principle. If $S$ is a set of natural numbers and is non-empty, then there exists an element $n \u2208 S, \u2200s \u2208 S, n \u2264 s$.\n-/\ntheorem well_ordered_principle (S : set \u2115) (h : S \u2260 \u2205) : \u2203 n \u2208 S, \u2200 s \u2208 S, n \u2264 s :=\nbegin\n-- We'll prove the Well-Ordered Principle by contradiction. Suppose there exist $\u2205 \u2260 S \u2282 \u2115$, $S$ does not have a least element.\n  apply classical.by_contradiction, push_neg, intro ha,\n-- Then let us create the set $B := {n \u2208 \u2115 | \u2200 x \u2264 n, x \u2209 S}$. (Notice that all elements of $S$ are bigger that all elements of $B$.)\n  let B := {n : \u2115 | \u2200 x \u2264 n, x \u2209 S},\n-- I claim that $B = \u2115$.\n  have : \u2200 x : \u2115, x \u2208 B,\n-- We will prove this by doing an induction on $x$.\n    by {intro x, induction x with k hk,\n-- We first need to prove that $0 \u2208 B$. As we have $\u2200 s \u2208 S, s \u2208 \u2115 \u21d2 s \u2265 0$, it suffices to prove that $0 \u2209 S$.\n      {rw set.mem_set_of_eq,\n      intros x hb hc,\n      replace hb : x = 0 :=\n        by {revert hb, simp},\n      rw hb at hc,\n-- But if $0 \u2208 S$ then $S$ has a minimum, $0$ can't be in $S$, implying $0 \u2208 B$.\n    have : \u2203 (s : \u2115), s \u2208 S \u2227 s < 0 := by {apply ha 0, assumption},\n    rcases this with \u27e8y, \u27e8_, he\u27e9\u27e9,\n    refine not_lt_of_ge _ he, norm_num,\n    },\n-- Now assume $k \u2208 B$ for some $k \u2208 \u2115$, then we need to prove $k + 1 \u2208 B$, i.e. we need to prove $\u2200 x \u2208 \u2115, x \u2264 k + 1 \u2192 x \u2209 S$.\n    {rw set.mem_set_of_eq at hk,\n    rw set.mem_set_of_eq, \n-- Let $x$ be an arbitary natural number thats less than $k + 1$. Suppose $x \u2208 S$, we will show a contradiction.\n    intros x hx hb,\n-- As $x \u2264 k \u21d4 x < k + 1$, we have $x < k + 1 \u2192 x \u2209 S$.\n    have hl : x < k + 1 \u2192 x \u2209 S := by {rwa nat.lt_succ_iff, from hk x},\n-- Then as we have assumed $x \u2208 S$, $x \u2265 k + 1$ since $x < k + 1 \u2192 x \u2209 S$.\n    have : x = k + 1 := \n      by {cases lt_trichotomy x (k + 1),\n        {exfalso, from (hl h_1) hb},\n        {cases h_1,\n          {assumption},\n-- But we have $x < k + 1$, thus, by the trichotomy axiom, $x = k + 1$.\n          {have : k + 1 < x \u2227 x \u2264 nat.succ k := \u27e8h_1, hx\u27e9, \n          revert this, simp\n          } } },\n-- Then, as $S$ has no least element, there is some $s \u2208 S, s < k + 1$.\n    rw this at hb,\n    have hc : \u2203 (s : \u2115), s \u2208 S \u2227 s < k + 1 := by {apply ha, assumption},\n    rcases hc with \u27e8y, \u27e8hd, he\u27e9\u27e9,\n-- But as $k \u2208 B$, $s < k + 1 \u21d2 s \u2209 S$, we have a contradiction! Therefore, by mathematical induction, we have $B = \u2115$\n    apply hk y,\n    rwa \u2190nat.lt_succ_iff, assumption\n    } },\n-- As, by construction, we have $S$ and $B$ are disjoint. Thus, since $S \u2286 \u2115, B = \u2115 \u21d2 S = \u2205$.\n  apply h,\n  have hSempty : \u2200 n \u2208 B, n \u2209 S := \n    by {intros n hn hs,\n    rw set.mem_set_of_eq at hn,\n    apply hn n, refl, assumption\n    },\n  ext, split,\n  all_goals {intro he},\n  {from hSempty x (this x) he},\n-- But $S = \u2205$ is a contradiction as we assumed its non-empty. Thus such an $S$ does not exist!\n  {simp at he, contradiction}\nend\n\n/- Definition\nA set $S$ is countable if and only if there exists a bijection $f : \u2115 \u2192 S$.\n-/\ndef countable (A : set(X)) := \u2203 f : \u2115 \u2192 A, bijective f\n\n/-\nIntuitively, we can think of this as putting the elements of $S$ into a list with no repeates.\n-/\n\nlemma inverse_refl (f : X \u2192 Y) (g : Y \u2192 X): two_sided_inverse f g \u2194 two_sided_inverse g f :=\nby {split,\n  all_goals {rintro \u27e8ha, hb\u27e9, from \u27e8hb, ha\u27e9},   \n}\n\n/- Theorem\n Given a set $A$, if there exists a function $f : A \u2192 \u2115$ where $f$ is bijective then $A$ is countable. \n-/\ntheorem countable_rev : \u2200 (S : set X), countable S \u2194 (\u2203 g : S \u2192 \u2115, bijective g) :=\nbegin\n  intro S,\n  split,\n    all_goals{rintro \u27e8f, hf\u27e9},\n    {suffices : \u2203 (g : S \u2192 \u2115), two_sided_inverse f g, \n      by {cases this with g hg, use g, \n      rw \u2190exist_two_sided_inverse, use f, rwa inverse_refl},\n    rwa exist_two_sided_inverse,\n    },\n\n    {have : \u2203 (g : \u2115 \u2192 S), two_sided_inverse f g,\n      by {rwa exist_two_sided_inverse},\n    cases this with g hg,\n    use g,\n    rwa \u2190exist_two_sided_inverse, \n    use f, rwa inverse_refl\n    }\nend\n\nend numbers", "meta": {"author": "JasonKYi", "repo": "M4000x_LEAN_formalisation", "sha": "6e99793f2fcbe88596e27644f430e46aa2a464df", "save_path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation", "path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation/M4000x_LEAN_formalisation-6e99793f2fcbe88596e27644f430e46aa2a464df/src/M40002/countability.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7371836194656701}}
{"text": "theorem add_comm : \u2200 (n m : Nat), n + m = m + n\n  | n, 0   => Eq.symm (Nat.zero_add n)\n  | n, m+1 => by\n    have : Nat.succ (n + m) = Nat.succ (m + n) :=\n      by apply congrArg; apply Nat.add_comm\n    rw [Nat.succ_add m n]\n    apply this\n", "meta": {"author": "lurk-lab", "repo": "yatima", "sha": "f33b0bf1052d95f9acbbe61681b1b58c0b97121e", "save_path": "github-repos/lean/lurk-lab-yatima", "path": "github-repos/lean/lurk-lab-yatima/yatima-f33b0bf1052d95f9acbbe61681b1b58c0b97121e/Fixtures/Debug/AddComm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.7371447147072162}}
{"text": "import data.nat.modeq\nimport recursions\n\nlemma div_algo (a b: \u2115 ): \u2203 (q : \u2115) , a=b*q+(a%b) :=\nbegin\n    have t1: b \u2223 a-(a%b), apply nat.dvd_sub_mod,\n    cases t1 with x y, use x, rw \u2190 y, \n    apply int.coe_nat_inj, push_cast, rw int.coe_nat_sub (nat.mod_le a b), ring,\nend\n\nlemma fib_pos : \u2200 m: \u2115, fib(m+1) >0:=\nbegin\n    apply nat.two_step_induction,\n    {simp},\n    {simp},\n    {intros, simp,linarith}\nend\n\nlemma luc_pos : \u2200 m: \u2115, luc(m) >0:=\nbegin\n    apply nat.two_step_induction,\n    {simp},\n    {simp},\n    {intros, rw luc_add, linarith}\nend\n\nlemma gcd_add (a b c: \u2115  ) (h: a = b +c): nat.gcd a b = nat.gcd b c:=\nbegin\n    cases nat.gcd_dvd b c,\n    have h1: nat.gcd b c \u2223 b + c, \n    {apply dvd_add, exact left, exact right}, \n    rw \u2190 h at h1,\n    have h2: nat.gcd b c \u2223 nat.gcd a b,\n    {rw nat.dvd_gcd_iff, split, exact h1, exact left},\n    clear left, clear right,\n    cases nat.gcd_dvd a b,\n    have h3: (nat.gcd a b :\u2124 ) \u2223  (a - b :\u2124) ,\n    {apply dvd_sub, norm_cast, exact left, norm_cast, exact right},\n    nth_rewrite 1 h at h3, \n    have h4: nat.gcd a b \u2223 nat.gcd b c,\n    {rw nat.dvd_gcd_iff, split,\n    {exact right},\n    {simp at h3, norm_cast at h3, assumption}},\n    apply nat.dvd_antisymm h4 h2,\nend\n\nlemma fib_coprime (m: \u2115 ) : nat.gcd (fib(m+1)) (fib(m+2)) = 1:=\nbegin\n    induction m with d hd,\n    {ring},\n    nth_rewrite 1 fib_add, rw  nat.gcd_comm, rw gcd_add, \n    {rw nat.gcd_comm, exact hd},\n    {simp}\nend\n\nlemma fib_even (m : \u2115) : fib (3*m) %2 =0 \u2227  fib (3*m +1) % 2 =1  \u2227 fib (3*m+2)%2=1 :=\nbegin\n    induction m with d hd,\n    {simp, ring},\n    {cases hd with h1 h2, cases h2 with h2 h3,\n    have g1:fib (3*d+3)%2=0,\n    {rw fib_add, rw nat.add_mod, simp * at *},\n    have g2: fib(3*d+4)%2=1,\n    {rw fib_add, rw nat.add_mod, rw g1, rw h3, ring},\n    have g3: fib(3*d+5)%2=1,\n    {rw fib_add, rw nat.add_mod, rw g2, rw g1, ring},\n    repeat{rw nat.succ_eq_add_one}, ring, cc}\nend \n\n\nlemma fib_luc_gcd_div_2 (m: \u2115 ) : nat.gcd (fib(m+2)) (luc(m+2)) =nat.gcd (fib(m+2)) 2:=\nbegin\n    have h1: nat.gcd (fib(m+2)) (luc(m+2)) =nat.gcd (fib(m+2)) (2 * fib(m+1)),\n    {rw  fib_luc_rec, rw fib_add, rw nat.gcd_comm, rw gcd_add, simp, ring},\n    rw h1, apply nat.coprime.gcd_mul_right_cancel_right, apply fib_coprime\nend\n\nlemma fib_luc_gcd (m: \u2115 ) : nat.gcd (fib(3*m)) (luc(3*m)) = 2  :=\nbegin\n    cases nat_case_bash m 0, interval_cases m, \n    {cases h with h h2, rw [show h+0+1 =h+1, from rfl] at h2, rw h2, rw mul_add, rw [show 3*1 = 1+2, by ring], rw fib_luc_gcd_div_2,\n    rw [show 3*h+1+2 = 3*(h+1), by ring], \n    rw \u2190 nat.gcd_eq_right_iff_dvd, rw nat.dvd_iff_mod_eq_zero,  simp[fib_even]},\n    {ring},\nend \n\nlemma fib_luc_gcd_2 (m : \u2115) (h: m%3 \u2260 0): nat.gcd (fib(m)) (luc(m))=1 :=\nbegin\n    cases nat_case_bash m 1, interval_cases m, \n    {cases h_1 with u h1, rw h1, rw fib_luc_gcd_div_2, rw nat.gcd_comm, rw \u2190 nat.coprime,  rw nat.prime.coprime_iff_not_dvd nat.prime_two,\n    by_contra, \n    have h2 := nat.mod_eq_zero_of_dvd a, have h3:= nat.mod_lt m (show 3>0, by linarith), \n    have h4:= div_algo m 3, cases h4 with d h4, have h5:=fib_even d, interval_cases m%3, \n    {rw h_1 at h4, rw \u2190 h1 at h2, rw h4 at h2, cc},\n    {rw h_1 at h4, rw \u2190 h1 at h2, rw h4 at h2, cc}},\n    {simp at h, exfalso, exact h},\n    {simp}\nend", "meta": {"author": "mhk119", "repo": "fibonacci_squares", "sha": "d3ca98693c352e192471268da584a4d73573b0be", "save_path": "github-repos/lean/mhk119-fibonacci_squares", "path": "github-repos/lean/mhk119-fibonacci_squares/fibonacci_squares-d3ca98693c352e192471268da584a4d73573b0be/src/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.737144705616861}}
{"text": "/-\nCopyright (c) 2023 Mark Andrew Gerads. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mark Andrew Gerads, Junyan Xu, Eric Wieser\n\n! This file was ported from Lean 3 source module data.nat.hyperoperation\n! leanprover-community/mathlib commit f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Tactic.Ring\nimport Mathlib.Data.Nat.Parity\n\n/-!\n# Hyperoperation sequence\n\nThis file defines the Hyperoperation sequence.\n`hyperoperation 0 m k = k + 1`\n`hyperoperation 1 m k = m + k`\n`hyperoperation 2 m k = m * k`\n`hyperoperation 3 m k = m ^ k`\n`hyperoperation (n + 3) m 0 = 1`\n`hyperoperation (n + 1) m (k + 1) = hyperoperation n m (hyperoperation (n + 1) m k)`\n\n## References\n\n* <https://en.wikipedia.org/wiki/Hyperoperation>\n\n## Tags\n\nhyperoperation\n-/\n\n\n/-- Implementation of the hyperoperation sequence\nwhere `hyperoperation n m k` is the `n`th hyperoperation between `m` and `k`.\n-/\n-- porting note: termination_by was not required before port\ndef hyperoperation : \u2115 \u2192 \u2115 \u2192 \u2115 \u2192 \u2115\n  | 0, _, k => k + 1\n  | 1, m, 0 => m\n  | 2, _, 0 => 0\n  | _ + 3, _, 0 => 1\n  | n + 1, m, k + 1 => hyperoperation n m (hyperoperation (n + 1) m k)\n  termination_by hyperoperation a b c => (a, b, c)\n#align hyperoperation hyperoperation\n\n-- Basic hyperoperation lemmas\n@[simp]\ntheorem hyperoperation_zero (m : \u2115) : hyperoperation 0 m = Nat.succ :=\n  funext fun k => by rw [hyperoperation, Nat.succ_eq_add_one]\n#align hyperoperation_zero hyperoperation_zero\n\ntheorem hyperoperation_ge_three_eq_one (n m : \u2115) : hyperoperation (n + 3) m 0 = 1 := by\n  rw [hyperoperation]\n#align hyperoperation_ge_three_eq_one hyperoperation_ge_three_eq_one\n\ntheorem hyperoperation_recursion (n m k : \u2115) :\n    hyperoperation (n + 1) m (k + 1) = hyperoperation n m (hyperoperation (n + 1) m k) := by\n  rw [hyperoperation]\n#align hyperoperation_recursion hyperoperation_recursion\n\n-- Interesting hyperoperation lemmas\n@[simp]\ntheorem hyperoperation_one : hyperoperation 1 = (\u00b7 + \u00b7) := by\n  ext (m k)\n  induction' k with bn bih\n  \u00b7 rw [Nat.add_zero m, hyperoperation]\n  \u00b7 rw [hyperoperation_recursion, bih, hyperoperation_zero]\n    exact Nat.add_assoc m bn 1\n#align hyperoperation_one hyperoperation_one\n\n@[simp]\ntheorem hyperoperation_two : hyperoperation 2 = (\u00b7 * \u00b7) := by\n  ext (m k)\n  induction' k with bn bih\n  \u00b7 rw [hyperoperation]\n    exact (Nat.mul_zero m).symm\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_one, bih]\n    -- porting note: was `ring`\n    dsimp only\n    nth_rewrite 1 [\u2190 mul_one m]\n    rw [\u2190 mul_add, add_comm, Nat.succ_eq_add_one]\n#align hyperoperation_two hyperoperation_two\n\n@[simp]\ntheorem hyperoperation_three : hyperoperation 3 = (\u00b7 ^ \u00b7) := by\n  ext (m k)\n  induction' k with bn bih\n  \u00b7 rw [hyperoperation_ge_three_eq_one]\n    exact (pow_zero m).symm\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_two, bih]\n    exact (pow_succ m bn).symm\n#align hyperoperation_three hyperoperation_three\n\ntheorem hyperoperation_ge_two_eq_self (n m : \u2115) : hyperoperation (n + 2) m 1 = m := by\n  induction' n with nn nih\n  \u00b7 rw [hyperoperation_two]\n    ring\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_ge_three_eq_one, nih]\n#align hyperoperation_ge_two_eq_self hyperoperation_ge_two_eq_self\n\ntheorem hyperoperation_two_two_eq_four (n : \u2115) : hyperoperation (n + 1) 2 2 = 4 := by\n  induction' n with nn nih\n  \u00b7 rw [hyperoperation_one]\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_ge_two_eq_self, nih]\n#align hyperoperation_two_two_eq_four hyperoperation_two_two_eq_four\n\ntheorem hyperoperation_ge_three_one (n : \u2115) : \u2200 k : \u2115, hyperoperation (n + 3) 1 k = 1 := by\n  induction' n with nn nih\n  \u00b7 intro k\n    rw [hyperoperation_three]\n    dsimp\n    rw [one_pow]\n  \u00b7 intro k\n    cases k\n    \u00b7 rw [hyperoperation_ge_three_eq_one]\n    \u00b7 rw [hyperoperation_recursion, nih]\n#align hyperoperation_ge_three_one hyperoperation_ge_three_one\n\ntheorem hyperoperation_ge_four_zero (n k : \u2115) :\n    hyperoperation (n + 4) 0 k = if Even k then 1 else 0 := by\n  induction' k with kk kih\n  \u00b7 rw [hyperoperation_ge_three_eq_one]\n    simp only [even_zero, if_true]\n  \u00b7 rw [hyperoperation_recursion]\n    rw [kih]\n    simp_rw [Nat.even_add_one]\n    split_ifs\n    \u00b7 exact hyperoperation_ge_two_eq_self (n + 1) 0\n    \u00b7 exact hyperoperation_ge_three_eq_one n 0\n#align hyperoperation_ge_four_zero hyperoperation_ge_four_zero\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Hyperoperation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.7371301001213069}}
{"text": "import basic\n\n/- \n\nIn this file, we formalize a proof of Arrow's Impossibility Theorem. \nWe closely follow the first proof in this 2005 paper by John Geankopolos: \n* https://link.springer.com/article/10.1007/s00199-004-0556-7\n\n\nArrow's Impossibility Theorem has been formalized in other languages before. \n\nFreek Wiedijk wrote a formalization in Mizar: \n* https://link.springer.com/article/10.1007/s12046-009-0005-1\n\nTobias Nipkow wrote a formalization in Isabelle/HOL: \n* https://link.springer.com/article/10.1007/s10817-009-9147-4\n\n\nAt times, our formalization is a close translation of Nipkow's proof in HOL. \nIn particular, our definition of functions `maketop`, `makebot`, and `makeabove` are \ninspired by his strategy for manipulating preferences. However, Nipkow defines preference orders \nin a completely different way from our `basic` file. \n-/\n\n\nopen relation vector finset\n\n-- We think of social states as type `\u03c3` and inidividuals as type `\u03b9`\nvariables {\u03c3 \u03b9 : Type} {x y x' y' a b : \u03c3} {r r' : \u03c3 \u2192 \u03c3 \u2192 Prop} {X : finset \u03c3}\n\n/-! ### Some basic definitions and lemmas -/\n\n/-- A social state `b` is *strictly worst* of a finite set of social states `X` with respect to \n  a ranking `p` if `b` is ranked strictly lower than every other `a \u2208 X`. -/\ndef is_strictly_worst (b : \u03c3) (r : \u03c3 \u2192 \u03c3 \u2192 Prop) (X : finset \u03c3) : Prop :=\n\u2200 a \u2208 X, a \u2260 b \u2192 P r a b\n\n/-- A social state `b` is *strictly best* of a finite set of social states `X` with respect to\n  a ranking `p` if `b` is ranked strictly higher than every other `a \u2208 X`. -/\ndef is_strictly_best (b : \u03c3) (r : \u03c3 \u2192 \u03c3 \u2192 Prop) (X : finset \u03c3) : Prop := \n\u2200 a \u2208 X, a \u2260 b \u2192 P r b a\n\n/-- A social state `b` is *extremal* with respect to a finite set of social states `X` \n  and a ranking `p` if `b` is either strictly worst or strictly best of `X`. -/\ndef is_extremal (b : \u03c3) (r : \u03c3 \u2192 \u03c3 \u2192 Prop) (X : finset \u03c3) : Prop := \nis_strictly_worst b r X \u2228 is_strictly_best b r X\n\nlemma not_strictly_worst : \u00acis_strictly_worst b r X \u2194 \u2203 a (h : a \u2208 X) (h : a \u2260 b), \u00acP r a b :=\nby simp only [is_strictly_worst, not_forall]\n\nlemma not_strictly_best : \u00acis_strictly_best b r X \u2194 \u2203 a (h : a \u2208 X) (h : a \u2260 b), \u00acP r b a :=\nby simp only [is_strictly_best, not_forall]\n\nlemma not_extremal : \u00acis_extremal b r X \u2194 \n  (\u2203 a (h : a \u2208 X) (h : a \u2260 b), \u00acP r a b) \u2227 (\u2203 c (h : c \u2208 X) (h : c \u2260 b), \u00acP r b c) := \nby simp only [is_extremal, not_or_distrib, not_strictly_worst, not_strictly_best]\n\nlemma not_extremal' (hr : total r) (h : \u00ac is_extremal b r X) : -- maybe make an `iff`? maybe combine with `exists_of_not_extremal`? -Ben\n  \u2203 a c \u2208 X, a \u2260 b \u2227 c \u2260 b \u2227 r a b \u2227 r b c := \nlet \u27e8\u27e8c, hc, hcb, hPc\u27e9, \u27e8a, ha, hab, hPa\u27e9\u27e9 := not_extremal.mp h in\n  \u27e8a, c, ha, hc, hab, hcb, R_of_nP_total hr hPa, R_of_nP_total hr hPc\u27e9\n\nlemma is_strictly_best.not_strictly_worst (htop : is_strictly_best b r X) (h : \u2203 a \u2208 X, a \u2260 b) : \n  \u00acis_strictly_worst b r X :=\nlet \u27e8a, a_in, hab\u27e9 := h in not_strictly_worst.mpr \u27e8a, a_in, hab, nP_of_reverseP (htop a a_in hab)\u27e9\n\nlemma is_strictly_best.not_strictly_worst' (htop : is_strictly_best b r X) (hX : 2 \u2264 X.card) (hb : b \u2208 X) :\n  \u00acis_strictly_worst b r X :=\nhtop.not_strictly_worst $ exists_second_distinct_mem hX hb\n\nlemma is_strictly_worst.not_strictly_best (hbot : is_strictly_worst b r X) (h : \u2203 a \u2208 X, a \u2260 b) :\n  \u00acis_strictly_best b r X :=\nlet \u27e8a, a_in, hab\u27e9 := h in not_strictly_best.mpr \u27e8a, a_in, hab, nP_of_reverseP (hbot a a_in hab)\u27e9\n\nlemma is_strictly_worst.not_strictly_best' (hbot : is_strictly_worst b r X) (hX : 2 \u2264 X.card) (hb : b \u2208 X) :\n \u00acis_strictly_best b r X :=\nhbot.not_strictly_best $ exists_second_distinct_mem hX hb\n\nlemma is_extremal.is_strictly_best (hextr : is_extremal b r X) (not_strictly_worst : \u00acis_strictly_worst b r X) :\n  is_strictly_best b r X := \nhextr.resolve_left not_strictly_worst \n\nlemma is_extremal.is_strictly_worst (hextr : is_extremal b r X) (not_strictly_best : \u00acis_strictly_best b r X) :\n  is_strictly_worst b r X := \nhextr.resolve_right not_strictly_best \n\nlemma is_strictly_worst.is_extremal (hbot : is_strictly_worst b r X) : is_extremal b r X := \nor.inl hbot\n\nlemma is_strictly_best.is_extremal (hbot : is_strictly_best b r X) : is_extremal b r X := \nor.inr hbot\n\n/-! ### \"Make\" functions -/\n\nlocal attribute [instance] classical.prop_decidable\n\n/-- Given an arbitary preference order `r` and a social state `b`,\n  `maketop r b` updates `r` so that `b` is now ranked strictly higher \n  than any other social state. \n  The definition also contains a proof that this new relation is a `pref_order \u03c3`. --/\ndef maketop (r : pref_order \u03c3) (b : \u03c3) : pref_order \u03c3 := \nbegin\n  use \u03bb x y, if x = b then true else if y = b then false else r x y,\n  { intro x,\n    split_ifs,\n    { trivial },\n    { exact r.refl x } },\n  { intros x y, simp only,\n    split_ifs with hx _ hy,\n    work_on_goal 3 { exact r.total x y },\n    all_goals { simp only [or_true, true_or] } },\n  { intros x y z, simp only,\n    split_ifs with hx _ _ hy _ hz; intros hxy hyz,\n    work_on_goal 6 { exact r.trans hxy hyz },\n    all_goals { trivial } },\nend  \n\n/-- Given an arbitary preference order `r` and a social state `b`,\n  `makebot r b` updates `r` so that every other social state is now ranked \n  strictly higher than `b`. \n  The definition also contains a proof that this new relation is a `pref_order \u03c3`. --/\ndef makebot (r : pref_order \u03c3) (b : \u03c3) : pref_order \u03c3 := \nbegin\n  use \u03bb x y, if y = b then true else if x = b then false else r x y,\n  { intro x,\n    split_ifs,\n    { trivial },\n    { exact r.refl x } },\n  { intros x y, simp only,\n    split_ifs with hx _ hy,\n    work_on_goal 3 { exact r.total x y },\n    all_goals { simp only [or_true, true_or] } },\n  { intros x y z, simp only,\n    split_ifs with hx _ _ hy _ hz; intros hxy hyz,\n    work_on_goal 6 { exact r.trans hxy hyz },\n    all_goals { trivial } },\nend\n\n/-- Given an arbitary preference order `r` and two social states `a` and `b`, \n  `makebot r a b` updates `r` so that: \n  (1) `b` is strictly higher than `a` and any other social state `y` where `r a y`\n  (2) any other social state that is strictly higher than `a` is strictly higher than `b`.\n  Intuitively, we have moved `b` just above `a` in the ordering. \n  The definition also contains a proof that this new relation is a `pref_order \u03c3`. --/\ndef makeabove (r : pref_order \u03c3) (a b : \u03c3) : pref_order \u03c3 := \nbegin\n  use \u03bb x y, if x = b then if y = b then true else if r a y then true else false \n             else if y = b then if r a x then false else true else r x y,\n  { intro x,\n    split_ifs,\n    { trivial },\n    { exact r.refl x } },\n  { intros x y, simp only,\n    split_ifs,\n    work_on_goal 5 { exact r.total x y }, \n    all_goals { simp only [or_true, true_or] } },\n  { intros x y z, simp only,\n    split_ifs with hx hy _ _ hay hz haz _ _ hy hax _ _ hz haz hz hay; intros hxy hyz,\n    any_goals { trivial },\n    { exact haz (r.trans hay hyz) },\n    { exact r.trans (pref_order.reverse hax) haz },\n    { exact hay (r.trans h hxy) },\n    { exact r.trans hxy hyz } },\nend \n\nlemma maketop_noteq (r : pref_order \u03c3) {a b c : \u03c3} (ha : a \u2260 b) (hc : c \u2260 b) :\n  (maketop r b a c \u2194 r a c) \u2227 (maketop r b c a \u2194 r c a) := \nbegin\n  simp only [maketop, if_false_left_eq_and, if_true_left_eq_or],\n  refine \u27e8\u27e8_, \u03bb h, or.inr \u27e8hc, h\u27e9\u27e9, \u27e8_, \u03bb h, or.inr \u27e8ha, h\u27e9\u27e9\u27e9; rintro (rfl | \u27e8-, h\u27e9),\n  exacts [absurd rfl ha, h, absurd rfl hc, h],\nend\n\nlemma maketop_noteq' (r : pref_order \u03c3) {a b c : \u03c3} (ha : a \u2260 b) (hc : c \u2260 b) :\n  (P (maketop r b) a c \u2194 P r a c) \u2227 (P (maketop r b) c a \u2194 P r c a) :=\nlet h := maketop_noteq r ha hc in P_iff_of_iff h.1 h.2\n\nlemma makebot_noteq (r : pref_order \u03c3) {a b c : \u03c3} (ha : a \u2260 b) (hc : c \u2260 b) :\n  (makebot r b a c \u2194 r a c) \u2227 (makebot r b c a \u2194 r c a) := \nbegin\n  simp only [makebot, if_false_left_eq_and, if_true_left_eq_or],\n  refine \u27e8\u27e8_, \u03bb h, or.inr \u27e8ha, h\u27e9\u27e9, \u27e8_, \u03bb h, or.inr \u27e8hc, h\u27e9\u27e9\u27e9; rintro (rfl | \u27e8-, h\u27e9),\n  exacts [absurd rfl hc, h, absurd rfl ha, h],\nend\n\nlemma makebot_noteq' (r : pref_order \u03c3) {a b c : \u03c3} (ha : a \u2260 b) (hc : c \u2260 b) :\n  (P (makebot r b) a c \u2194 P r a c) \u2227 (P (makebot r b) c a \u2194 P r c a) :=\nlet h := makebot_noteq r ha hc in P_iff_of_iff h.1 h.2\n\nlemma makeabove_noteq (r : pref_order \u03c3) (a : \u03c3) {b c d : \u03c3} (hc : c \u2260 b) (hd : d \u2260 b) :\n  (makeabove r a b c d \u2194 r c d) \u2227 (makeabove r a b d c \u2194 r d c) :=\nby simp [makeabove, \u2190 pref_order.eq_coe, hc, hd]\n\nlemma makeabove_noteq' (r : pref_order \u03c3) (a : \u03c3) {b c d : \u03c3} (hc : c \u2260 b) (hd : d \u2260 b) :\n  (P (makeabove r a b) c d \u2194 P r c d) \u2227 (P (makeabove r a b) d c \u2194 P r d c) :=\nby simp [makeabove, P, \u2190 pref_order.eq_coe, hc, hd]\n\nlemma is_strictly_best_maketop (b : \u03c3) (r : pref_order \u03c3) (X : finset \u03c3) :\n  is_strictly_best b (maketop r b) X :=\nby simp [maketop, is_strictly_best, P, \u2190 pref_order.eq_coe]\n\nlemma is_strictly_worst_makebot (b : \u03c3) (r : pref_order \u03c3) (X : finset \u03c3) :\n  is_strictly_worst b (makebot r b) X :=\nby simp [is_strictly_worst, makebot, P, \u2190 pref_order.eq_coe]\n\nlemma makeabove_above {a b : \u03c3} (r : pref_order \u03c3) (ha : a \u2260 b):\n  P (makeabove r a b) b a :=\nby simpa [P, makeabove, \u2190 pref_order.eq_coe, not_or_distrib, ha] using r.refl a\n\nlemma makeabove_above' {a b c : \u03c3} {r : pref_order \u03c3} (hc : c \u2260 b) (hr : r a c) :\n  P (makeabove r a b) b c :=\nby simpa [P, makeabove, \u2190 pref_order.eq_coe, hc]\n\nlemma makeabove_below {a b c : \u03c3} {r : pref_order \u03c3} (hc : c \u2260 b) (hr : \u00acr a c) :\n  P (makeabove r a b) c b :=\nby simpa [P, makeabove, \u2190 pref_order.eq_coe, not_or_distrib, hc]\n\n/-! ### Properties -/\n\n/-- A social welfare function satisfies the Weak Pareto criterion if, for any two social states \n  `x` and `y`, every individual ranking `x` higher than `y` implies that society ranks `x` higher \n  than `y`. -/\ndef weak_pareto (f : (\u03b9 \u2192 pref_order \u03c3) \u2192 pref_order \u03c3) (X : finset \u03c3) : Prop := \n\u2200 (x y \u2208 X) (R : \u03b9 \u2192 pref_order \u03c3), (\u2200 i : \u03b9, P (R i) x y) \u2192 P (f R) x y\n\n/-- Suppose that for any two social states `x` and `y`, every individual's ordering of `x` and `y`\n  remains unchanged between two orderings `P\u2081` and `P\u2082`. We say that a social welfare function is \n  *independent of irrelevant alternatives* if society's ordering of `x` and `y` also remains \n  unchanged between `P\u2081` and `P\u2082`. -/\ndef ind_of_irr_alts (f : (\u03b9 \u2192 pref_order \u03c3) \u2192 pref_order \u03c3) (X : finset \u03c3) : Prop :=\n\u2200 (R R' : \u03b9 \u2192 pref_order \u03c3) (x y \u2208 X), \n  (\u2200 i : \u03b9, same_order' (R i) (R' i) x y x y) \u2192 same_order' (f R) (f R') x y x y\n\n/-- A social welfare function is a *dictatorship* if there exists an individual who possesses the power\n   to determine society's order of any social states. -/\ndef is_dictatorship (f : (\u03b9 \u2192 pref_order \u03c3) \u2192 pref_order \u03c3) (X : finset \u03c3) : Prop :=\n\u2203 i : \u03b9, \u2200 (x y \u2208 X) (R : \u03b9 \u2192 pref_order \u03c3), P (R i) x y \u2192 P (f R) x y\n\n/-- An individual `i` is *pivotal* with respect to a social welfare function and a social state `b`\n  if there exist preference orderings `R` and `R'` such that: \n  (1) all individuals except for `i` rank all social states exactly the same in both orderings\n  (2) all individuals place `b` in an extremal position in both rankings\n  (3) `i` ranks `b` bottom of their rankings in `R`, but top of their rankings in `R'`\n  (4) society ranks `b` bottom of its rankings in `R`, but top of its rankings in `R'` -/\ndef is_pivotal (f : (\u03b9 \u2192 pref_order \u03c3) \u2192 pref_order \u03c3) (X : finset \u03c3) (i : \u03b9) (b : \u03c3) : Prop :=\n\u2203 (R R' : \u03b9 \u2192 pref_order \u03c3),\n  (\u2200 j : \u03b9, j \u2260 i \u2192 \u2200 x y \u2208 X, R j = R' j) \u2227 \n    (\u2200 i : \u03b9, is_extremal b (R i) X) \u2227 (\u2200 i : \u03b9, is_extremal b (R' i) X) \u2227\n      (is_strictly_worst b (R i) X) \u2227 (is_strictly_best b (R' i) X) \u2227 \n        (is_strictly_worst b (f R) X) \u2227 (is_strictly_best b (f R') X)\n\n/-- A social welfare function has a *pivot* with respect to a social state `b` if there exists an\n  individual who is pivotal with respect to that function and `b`. -/\ndef has_pivot (f : (\u03b9 \u2192 pref_order \u03c3) \u2192 pref_order \u03c3) (X : finset \u03c3) (b : \u03c3): Prop := \n\u2203 i, is_pivotal f X i b\n\n/-- An individual is a dictator over all social states in a given set *except* `b` \n  if they are a dictator over every pair of distinct alternatives not equal to `b`.  -/\ndef is_dictator_except (f : (\u03b9 \u2192 pref_order \u03c3) \u2192 pref_order \u03c3) \n  (X : finset \u03c3) (i : \u03b9) (b : \u03c3) : Prop := \n\u2200 a c \u2208 X, a \u2260 b \u2192 c \u2260 b \u2192 \u2200 R : \u03b9 \u2192 pref_order \u03c3, P (R i) c a \u2192 P (f R) c a \n\nvariables {R : \u03b9 \u2192 pref_order \u03c3} {f : (\u03b9 \u2192 pref_order \u03c3) \u2192 pref_order \u03c3} \n\n/-! ### Auxiliary lemmas -/\n\n/-- If every individual ranks a social state `b` at the top of its rankings, then society must also\n  rank `b` at the top of its rankings. -/\ntheorem is_strictly_best_of_forall_is_strictly_best (b_in : b \u2208 X) (hwp : weak_pareto f X)\n  (htop : \u2200 i, is_strictly_best b (R i) X) :\n  is_strictly_best b (f R) X := \n\u03bb a a_in hab, hwp b a b_in a_in R $ \u03bb i, htop i a a_in hab\n\n/-- If every individual ranks a social state `b` at the bottom of its rankings, then society must \n  also rank `b` at the bottom of its rankings. -/\ntheorem is_strictly_worst_of_forall_is_strictly_worst (b_in : b \u2208 X) (hwp : weak_pareto f X) \n  (hbot : \u2200 i, is_strictly_worst b (R i) X) :\n  is_strictly_worst b (f R) X :=\n\u03bb a a_in hab, hwp a b a_in b_in R $ \u03bb i, hbot i a a_in hab\n\nlemma exists_of_not_extremal (hX : 3 \u2264 X.card) (hb : b \u2208 X) (h : \u00ac is_extremal b (f R) X) : -- it may be worth generalizing this; see `not_extremal'` above - Ben\n  \u2203 a c \u2208 X, a \u2260 b \u2227 c \u2260 b \u2227 a \u2260 c \u2227 f R a b \u2227 f R b c := \nbegin\n  obtain \u27e8a, c, ha, hc, hab, hcb, hfa, hfc\u27e9 := not_extremal' (f R).total h,\n  obtain hac | rfl := ne_or_eq a c, { exact \u27e8a, c, ha, hc, hab, hcb, hac, hfa, hfc\u27e9 },\n  obtain \u27e8d, hd, hda, hdb\u27e9 := exists_third_distinct_mem hX ha hb hab,\n  obtain hfd | hfd := (f R).total d b,\n  { exact \u27e8d, a, hd, hc, hdb, hcb, hda, hfd, hfc\u27e9 },\n  { exact \u27e8a, d, ha, hd, hab, hdb, hda.symm, hfa, hfd\u27e9 },\nend\n\n/-! ### The Proof Begins -/\n\n/- Geankopolos (2005) calls this step the *Extremal Lemma*. If every individual\nplaces alternative `b` in an extremal position (at the very top or bottom of her rankings),\nthen society must also place alternative `b` in an extremal position. -/\nlemma first_step (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X)\n  (hX : 3 \u2264 X.card) (hb : b \u2208 X) (hextr : \u2200 i, is_extremal b (R i) X) :\n  is_extremal b (f R) X :=\nbegin\n  by_contra hnot,\n  obtain \u27e8a, c, ha, hc, hab, hcb, hac, hfa, hfb\u27e9 := exists_of_not_extremal hX hb hnot,\n  have H1 := \u03bb {j} h, makeabove_below hcb.symm ((hextr j).is_strictly_best h a ha hab).2,\n  have H2 := \u03bb {j} h, makeabove_above' hcb.symm ((hextr j).is_strictly_worst h a ha hab).1,\n  refine (hwp c a hc ha (\u03bb j, makeabove (R j) a c) (\u03bb j, makeabove_above (R j) hac)).2 \n    ((f _).trans (((same_order_iff_same_order' (f R).total (f _).total).2 -- wouldn't it be better just to do everything using `same_order'`? -Ben\n      (hind R _ a b ha hb (\u03bb j, _))).1.1.1 hfa)\n        (((same_order_iff_same_order' (f R).total (f _).total).2\n          (hind R _ b c hb hc (\u03bb j, \u27e8\u27e8\u03bb h, H1 (not_strictly_worst.mpr \u27e8c, hc, hcb, nP_of_reverseP h\u27e9), _\u27e9,\n            \u27e8\u03bb h, H2 (not_strictly_best.mpr \u27e8c, hc, hcb, nP_of_reverseP h\u27e9), _\u27e9\u27e9))).1.1.1 hfb)),\n  { simp only [same_order', makeabove_noteq' _ a hcb.symm hac, iff_self, and_self] },\n  all_goals { rintro \u27e8-, h\u27e9, contrapose! h },\n  { exact (H2 (not_strictly_best.mpr \u27e8c, hc, hcb, h\u27e9)).1 },\n  { exact (H1 (not_strictly_worst.mpr \u27e8c, hc, hcb, h\u27e9)).1 },\nend\n\n/-- We define relation `r\u2082`, a `pref_order` we will use in `second_step`. -/\ndef r\u2082 (b : \u03c3) : pref_order \u03c3 :=\nbegin\n  use \u03bb x y, if y = b then true else if x = b then false else true,\n  { intro x, split_ifs; trivial },\n  { intros x y, simp only, split_ifs; simp only [true_or, or_true] },\n  { intros x y z, simp only, split_ifs; simp only [forall_true_left, forall_false_left] },\nend\n\n/- This is an auxiliary lemma used in the `second_step`. -/\nlemma second_step_aux [fintype \u03b9] (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X)\n  (hX : 2 < X.card) (b_in : b \u2208 X) {D' : finset \u03b9} :\n  \u2200 {R : \u03b9 \u2192 pref_order \u03c3}, D' = {i \u2208 univ | is_strictly_worst b (R i) X} \u2192 \n    (\u2200 i, is_extremal b (R i) X) \u2192 is_strictly_worst b (f R) X \u2192 has_pivot f X b := \nbegin\n  refine finset.induction_on D'\n    (\u03bb R h hextr hbot, absurd (is_strictly_best_of_forall_is_strictly_best b_in hwp (\u03bb j, (hextr j).is_strictly_best _))\n                              (hbot.not_strictly_best (exists_second_distinct_mem hX.le b_in))) \n    (\u03bb i D hi IH R h_insert hextr hbot, _),\n  { simpa using eq_empty_iff_forall_not_mem.mp h.symm j },\n  { let R' := \u03bb j, (ite (j = i) (maketop (R j) b) (R j)),\n    have hextr' : \u2200 j, is_extremal b (R' j) X,\n    { intro j, simp only [R'], \n      split_ifs,\n      { exact (is_strictly_best_maketop b (R j) X).is_extremal },\n      { exact hextr j } },\n    by_cases hR' : is_strictly_best b (f R') X,\n    { refine \u27e8i, R, R', \u03bb j hj x y _ _, _, hextr, hextr', _, _, hbot, hR'\u27e9,\n      { simp only [R', if_neg hj] },\n      { have : i \u2208 {j \u2208 univ | is_strictly_worst b (R j) X}, { rw \u2190 h_insert, exact mem_insert_self i D },\n        simpa },\n      { simp only [R', is_strictly_best_maketop, if_pos] } },\n    { refine IH (ext (\u03bb j, _)) hextr' ((first_step hwp hind hX b_in hextr').is_strictly_worst hR'),\n      simp only [true_and, sep_def, mem_filter, mem_univ, R'],\n      split; intro hj,\n      { have hji : j \u2260 i, { rintro rfl, exact hi hj },\n        have : j \u2208 {i \u2208 univ | is_strictly_worst b \u21d1(R i) X}, { convert mem_insert_of_mem hj, rw h_insert },\n        simpa [hji] },\n      { have hji : j \u2260 i,\n        { rintro rfl,\n          obtain \u27e8a, a_in, hab\u27e9 := exists_second_distinct_mem hX.le b_in,\n          simp only [if_pos] at hj,\n          exact (is_strictly_best_maketop b (R j) X a a_in hab).2 (hj a a_in hab).1 },\n        rw [\u2190 erase_insert hi, h_insert],\n        simpa [hji] using hj } } },\nend\n\n/- In his second step, Geankopolos shows that for any social state `b`, \nthere exists an individual who is pivotal over that social state.  -/\nlemma second_step [fintype \u03b9] (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X)\n  (hX : 3 \u2264 X.card) (b) (b_in : b \u2208 X) :\n  has_pivot f X b := \nhave hbot : is_strictly_worst b (r\u2082 b) X, by simp [is_strictly_worst, r\u2082, P, \u2190 pref_order.eq_coe],\nsecond_step_aux hwp hind hX b_in rfl (\u03bb i, hbot.is_extremal) $\n  is_strictly_worst_of_forall_is_strictly_worst b_in hwp $ \u03bb i, hbot\n\n/- Step 3 states that if an individual `is_pivotal` over some alternative `b`, they \nare also a dictator over every pair of alternatives not equal to `b`. -/\nlemma third_step (hind : ind_of_irr_alts f X) \n  (b_in : b \u2208 X) {i : \u03b9} (i_piv : is_pivotal f X i b) :\n  is_dictator_except f X i b :=\nbegin\n  rintros a c a_in c_in hab hcb Q \u27e8-, h\u27e9,\n  obtain \u27e8R, R', i_piv\u27e9 := i_piv,\n  let Q' := \u03bb j, if j = i then makeabove (Q j) a b \n                 else if is_strictly_worst b (R j) X then makebot (Q j) b else maketop (Q j) b,\n  have Q'bot : \u2200 j \u2260 i, is_strictly_worst b (R j) X \u2192 Q' j = makebot (Q j) b :=\n    \u03bb j hj hbot, by simp only [Q', if_neg hj, if_pos hbot],\n  have Q'top : \u2200 j \u2260 i, \u00acis_strictly_worst b (R j) X \u2192 Q' j = maketop (Q j) b :=\n    \u03bb j hj hbot, by simp only [Q', if_neg hj, if_neg hbot],\n  have Q'above : Q' i = makeabove (Q i) a b := by simp [Q'],\n  have hQ' : \u2200 j, same_order' (Q j) (Q' j) c a c a,\n  { intro j,\n    suffices : \u2200 d \u2260 b, \u2200 e \u2260 b, same_order' (Q j) (Q' j) e d e d, from this a hab c hcb,\n    intros d hdb e heb, \n    simp only [Q', same_order'],\n    split_ifs; simp [makeabove_noteq', makebot_noteq', maketop_noteq', hdb, heb] },\n  rw (hind Q Q' c a c_in a_in hQ').1,\n  refine P_trans (f Q').trans ((hind R Q' c b c_in b_in _).1.1 (i_piv.2.2.2.2.2.1 c c_in hcb)) \n    ((hind R' Q' b a b_in a_in _).1.1 (i_piv.2.2.2.2.2.2 a a_in hab)); \n      intro j; split; split; intro H; rcases eq_or_ne j i with rfl | hj,\n  { convert makeabove_below hcb h },  \n  { convert is_strictly_worst_makebot b (Q j) X c c_in hcb,\n    apply Q'bot j hj,\n    unfold is_strictly_worst,\n    by_contra hbot, push_neg at hbot,\n    rcases hbot with \u27e8d, d_in, hdb, H'\u27e9,\n    cases i_piv.2.1 j with hbot htop,\n    { exact H' (hbot d d_in hdb) },\n    { exact H.2 (htop c c_in hcb).1 } },\n  { exact i_piv.2.2.2.1 c c_in hcb }, \n  { by_contra H',\n    apply nP_of_reverseP ((is_strictly_best_maketop b (Q j) X) c c_in hcb),\n    rwa \u2190 Q'top j hj,\n    exact not_strictly_worst.mpr \u27e8c, c_in, hcb, H'\u27e9 },\n  { exact absurd (i_piv.2.2.2.1 c c_in hcb).1 H.2 },\n  { convert is_strictly_best_maketop b (Q j) X c c_in hcb,\n    exact Q'top j hj (\u03bb hbot, H.2 (hbot c c_in hcb).1) },\n  { apply absurd (makeabove_below hcb h).1,\n    convert \u2190 H.2 },\n  { by_contra H',\n    apply absurd (is_strictly_worst_makebot b (Q j) X c c_in hcb).1,\n    convert \u2190 H.2,\n    exact Q'bot j hj ((i_piv.2.1 j).is_strictly_worst (not_strictly_best.mpr \u27e8c, c_in, hcb, H'\u27e9)) }, \n  { convert makeabove_above (Q j) hab },\n  { convert is_strictly_best_maketop b (Q j) X a a_in hab,\n    apply Q'top j hj,\n    rw i_piv.1 j hj a b a_in b_in,\n    exact not_strictly_worst.mpr \u27e8a, a_in, hab, nP_of_reverseP H\u27e9 },\n  { exact i_piv.2.2.2.2.1 a a_in hab },\n  { rw \u2190 i_piv.1 j hj a b a_in b_in,\n    refine ((i_piv.2.1 j).is_strictly_best (\u03bb hbot, nP_of_reverseP H _)) a a_in hab,\n    convert is_strictly_worst_makebot b (Q j) X a a_in hab,\n    exact Q'bot j hj hbot },\n  { exact absurd (i_piv.2.2.2.2.1 a a_in hab).1 H.2 },\n  { convert is_strictly_worst_makebot b (Q j) X a a_in hab,\n    apply Q'bot j hj,\n    rw i_piv.1 j hj a b a_in b_in,\n    exact (i_piv.2.2.1 j).is_strictly_worst (not_strictly_best.mpr \u27e8a, a_in, hab, nP_of_reverseP H\u27e9) },\n  { apply absurd (makeabove_above (Q j) hab).1,\n    convert \u2190 H.2 },\n  { rw \u2190 i_piv.1 j hj a b a_in b_in,\n    suffices : is_strictly_worst b (R j) X, from this a a_in hab,\n    by_contra hbot,\n    apply absurd (is_strictly_best_maketop b (Q j) X a a_in hab).1,\n    convert \u2190 H.2,\n    exact Q'top j hj hbot },\nend\n\n\n/- Step 4 states that if an individual is a dictator over every pair of social states \nexcept for `b`, they are also a dictator over all pairs (including `b`). -/\nlemma fourth_step (hind : ind_of_irr_alts f X) \n  (hX : 3 \u2264 X.card) (hpiv : \u2200 b \u2208 X, has_pivot f X b) : \n  is_dictatorship f X := \nbegin\n  obtain \u27e8b, hb\u27e9 := (card_pos.1 (zero_lt_two.trans hX)).bex,\n  obtain \u27e8i, i_piv\u27e9 := hpiv b hb,\n  have h : \u2200 a \u2208 X, a \u2260 b \u2192 \u2200 R\u1d62 : \u03b9 \u2192 pref_order \u03c3, \n          (P (R\u1d62 i) a b \u2192 P (f R\u1d62) a b) \u2227 (P (R\u1d62 i) b a \u2192 P (f R\u1d62) b a), -- is there perhaps a better way to state this? -Ben\n  { intros a ha hab R\u1d62,\n    obtain \u27e8c, hc, hca, hcb\u27e9 := exists_third_distinct_mem hX ha hb hab,\n    obtain \u27e8hac, hbc\u27e9 := \u27e8hca.symm, hcb.symm\u27e9,\n    obtain \u27e8j, j_piv\u27e9 := hpiv c hc,\n    obtain hdict := third_step hind hc j_piv, \n    obtain rfl : j = i,\n    { by_contra hji,\n      obtain \u27e8R, R', hso, hextr, -, -, -, hbot, htop\u27e9 := i_piv,\n      refine (htop a ha hab).2 (hdict b a hb ha hbc hac R' _).1,\n      rw \u2190 hso j hji a b ha hb,\n      by_contra hnot,\n      exact (hdict a b ha hb hac hbc R ((hextr j).is_strictly_best\n        (not_strictly_worst.mpr \u27e8a, ha, hab, hnot\u27e9) a ha hab)).2 (hbot a ha hab).1 }, \n    split; apply hdict; assumption },\n  refine \u27e8i, \u03bb x y hx hy R\u1d62 hR\u1d62, _\u27e9,\n  rcases eq_or_ne b x with rfl | hbx; rcases eq_or_ne b y with rfl | hby,\n  { exact (false_of_P_self hR\u1d62).elim },\n  { exact (h y hy hby.symm R\u1d62).2 hR\u1d62 },\n  { exact (h x hx hbx.symm R\u1d62).1 hR\u1d62 },\n  { exact third_step hind hb i_piv y x hy hx hby.symm hbx.symm R\u1d62 hR\u1d62 },\nend \n\n/-- Arrow's Impossibility Theorem: Any social welfare function involving at least three social\n  states that satisfies WP and IoIA is necessarily a dictatorship. --/\ntheorem arrow [fintype \u03b9] (hwp : weak_pareto f X) (hind : ind_of_irr_alts f X) (hX : 3 \u2264 X.card) :\n  is_dictatorship f X := \nfourth_step hind hX $ second_step hwp hind hX\n", "meta": {"author": "asouther4", "repo": "lean-social-choice", "sha": "9906ade382ace77af4fef1edb70364b84f7afd9c", "save_path": "github-repos/lean/asouther4-lean-social-choice", "path": "github-repos/lean/asouther4-lean-social-choice/lean-social-choice-9906ade382ace77af4fef1edb70364b84f7afd9c/src/arrows_theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7371300903643208}}
{"text": "/-\nCopyright (c) 2022 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\n\nimport data.finite.basic\nimport data.fintype.basic\nimport data.fun_like.basic\n\n/-!\n# Finiteness of `fun_like` types\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe show a type `F` with a `fun_like F \u03b1 \u03b2` is finite if both `\u03b1` and `\u03b2` are finite.\nThis corresponds to the following two pairs of declarations:\n\n * `fun_like.fintype` is a definition stating all `fun_like`s are finite if their domain and\n   codomain are.\n * `fun_like.finite` is a lemma stating all `fun_like`s are finite if their domain and\n   codomain are.\n * `fun_like.fintype'` is a non-dependent version of `fun_like.fintype` and\n * `fun_like.finite` is a non-dependent version of `fun_like.finite`, because dependent instances\n   are harder to infer.\n\nYou can use these to produce instances for specific `fun_like` types.\n(Although there might be options for `fintype` instances with better definitional behaviour.)\nThey can't be instances themselves since they can cause loops.\n-/\n\nsection type\n\nvariables (F G : Type*) {\u03b1 \u03b3 : Type*} {\u03b2 : \u03b1 \u2192 Type*} [fun_like F \u03b1 \u03b2] [fun_like G \u03b1 (\u03bb _, \u03b3)]\n\n/-- All `fun_like`s are finite if their domain and codomain are.\n\nThis is not an instance because specific `fun_like` types might have a better-suited definition.\n\nSee also `fun_like.finite`.\n-/\nnoncomputable def fun_like.fintype [decidable_eq \u03b1] [fintype \u03b1] [\u03a0 i, fintype (\u03b2 i)] : fintype F :=\nfintype.of_injective _ fun_like.coe_injective\n\n/-- All `fun_like`s are finite if their domain and codomain are.\n\nNon-dependent version of `fun_like.fintype` that might be easier to infer.\nThis is not an instance because specific `fun_like` types might have a better-suited definition.\n-/\nnoncomputable def fun_like.fintype' [decidable_eq \u03b1] [fintype \u03b1] [fintype \u03b3] : fintype G :=\nfun_like.fintype G\n\nend type\n\nsection sort\n\nvariables (F G : Sort*) {\u03b1 \u03b3 : Sort*} {\u03b2 : \u03b1 \u2192 Sort*} [fun_like F \u03b1 \u03b2] [fun_like G \u03b1 (\u03bb _, \u03b3)]\n\n/-- All `fun_like`s are finite if their domain and codomain are.\n\nCan't be an instance because it can cause infinite loops.\n-/\nlemma fun_like.finite [finite \u03b1] [\u2200 i, finite (\u03b2 i)] : finite F :=\nfinite.of_injective _ fun_like.coe_injective\n\n/-- All `fun_like`s are finite if their domain and codomain are.\n\nNon-dependent version of `fun_like.finite` that might be easier to infer.\nCan't be an instance because it can cause infinite loops.\n-/\nlemma fun_like.finite' [finite \u03b1] [finite \u03b3] : finite G :=\nfun_like.finite G\n\nend sort\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/fun_like/fintype.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7371300857773738}}
{"text": "/- Universal quantifier -/\n\nnamespace uni_q\n  example (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) : (\u2200 x : \u03b1, p x \u2227 q x) \u2192 (\u2200 y : \u03b1, q y) :=\n    fun h : \u2200 x : \u03b1, p x \u2227 q x =>\n      fun y : \u03b1 =>\n        show q y from (h y).right\n\n  variable (\u03b1 : Type) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n  variable (trans_r : \u2200 x y z, r x y \u2192 r y z \u2192 r x z)\n  variable (a b c : \u03b1)\n  variable (hab : r a b) (hbc : r b c)\n\n  #check trans_r\n  #check trans_r a -- (\u2200 y z : \u03b1), r a y \u2192 r y z \u2192 r a z\n  #check trans_r a b -- (\u2200 z : \u03b1), r a b \u2192 r b z \u2192 r a z\n  #check trans_r a b c -- r a b \u2192 r b c \u2192 r a c\n  #check trans_r a b c hab -- r b c \u2192 r a c\n  #check trans_r a b c hab hbc -- r a c\n\n  variable (trans_r : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z)\n  #check trans_r hab hbc -- r a c\n\n\n  /- Equivalence relation -/\n  variable (refl_r : \u2200 x, r x x)\n  variable (symm_r : \u2200 {x y}, r x y \u2192 r y x)\n  variable (trans_r : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z)\n  example (a b c d : \u03b1) (hab : r a b) (hcb : r c b) (hcd : r c d) : r a d :=\n    trans_r (trans_r hab (symm_r hcb)) hcd\nend uni_q\n\n\n/- Equality -/\n\nnamespace equality \n  universe u\n  #check @Eq.refl.{u} -- a = a\n  #check @Eq.symm.{u} -- a = b \u2192 b = a\n  #check @Eq.trans.{u} -- a = b \u2192 b = c \u2192 a = c\n\n  variable (\u03b1 : Type) (a b c d : \u03b1)\n  variable (hab : a = b) (hcb : c = b) (hcd : c = d)\n  example : a = d :=\n    Eq.trans (Eq.trans hab (Eq.symm hcb)) hcd\n  example : a = d := (hab.trans hcb.symm).trans hcd\n\n\n  variable (\u03b1 \u03b2 : Type) (a b c d : \u03b1)\n\n  example (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (fun x => f x) a = f a := Eq.refl (f a)\n  example (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (fun x => f x) a = f a := Eq.refl _\n  example : (a, b).1 = a := Eq.refl a\n  example : 2 + 3 = 5 := rfl\n\n\n  -- Substitution\n  example (a b : \u03b1) (p : \u03b1 \u2192 Prop) (h1 : a = b) (h2 : p a) : p b :=\n    Eq.subst h1 h2\n\n  example (a b : \u03b1) (p : \u03b1 \u2192 Prop) (h1 : a = b) (h2 : p a) : p b :=\n    h1 \u25b8 h2  -- \"\u25b8\" \"t\"\n  \n  variable (f g : \u03b1 \u2192 \u2115) \n  variable (h1 : f = g) (h2 : a = b)\n  example : f a = f b := congrArg f h2\n  example : f a = g a := congrFun h1 a\n  example : f a = g b := congr h1 h2\n\n  variable (a b c d : Nat) \n  example : a + 0 = a := a.add_zero\n  example : 0 + a = a := a.zero_add\n  example : a * 1 = a := a.mul_one\n  example : 1 * a = a := a.one_mul\n  example : a + b = b + a := a.add_comm b\n  example : a + b + c = a + (b + c) := a.add_assoc b c\n  example : a * b = b * a := a.mul_comm b \n  example : a * b * c = a * (b * c) := a.mul_assoc b c\n  example : a * (b + c) = a * b + a * c := a.mul_add b c\n  example : (a + b) * c = a * c + b * c := a.add_mul b c\n\n  example (x y : Nat) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n    have h1 : (x + y) * (x + y) = (x + y) * x + (x + y) * y :=\n      Nat.mul_add (x + y) x y\n    have h2 : (x + y) * (x + y) = (x * x + y * x) + (x * y + y * y) :=\n      (Nat.add_mul x y x) \u25b8 (Nat.add_mul x y y) \u25b8 h1\n    h2.trans (Nat.add_assoc (x * x + y * x) (x * y) (y * y)).symm\n\nend equality\n\n\n/- Calculation Proofs -/\n\nnamespace calc_p\n  variable (a b c d e : Nat)\n  variable (h1 : a = b) (h2 : b = c + 1) (h3 : c = d) (h4 : e = 1 + d)\n  theorem T : a = e :=\n    calc\n      a = b := h1\n      _ = c + 1 := h2\n      _ = d + 1 := congrArg Nat.succ h3\n      _ = 1 + d := Nat.add_comm d 1\n      _ = e := h4.symm\n\n  theorem T1 : a = e :=\n    calc \n      a = b := by rw [h1]\n      _ = c + 1 := by rw [h2]\n      _ = d + 1 := by rw [h3]\n      _ = 1 + d := by rw [Nat.add_comm]\n      _ = e := by rw [h4]\n\n  theorem T2 : a = e :=\n    calc\n      a = d + 1 := by rw [h1, h2, h3]\n      _ = 1 + d := by rw [Nat.add_comm]\n      _ = e := by rw [h4]\n\n  theorem T3 : a = e :=\n    by rw [h1, h2, h3, Nat.add_comm, h4]\n\n  example (a b c d : Nat) (h1 : a = b) (h2 : b \u2264 c) (h3 : c + 1 < d) : a < d :=\n    calc\n      a = b := h1\n      _ < b + 1 := Nat.lt_succ_self b\n      _ \u2264 c + 1 := Nat.succ_le_succ h2\n      _ < d := h3\n\n  example (x y : Nat) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n    calc\n      (x + y) * (x + y) = (x + y) * x + (x + y) * y := by rw [Nat.mul_add]\n      _ = x * x + y * x + (x + y) * y := by rw [Nat.add_mul]\n      _ = x * x + y * x + (x * y + y * y) := by rw [Nat.add_mul]\n      _ = x * x + y * x + x * y + y * y := by rw [\u2190Nat.add_assoc]\n\n  example (x y : Nat) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n    by simp [Nat.mul_add, Nat.add_mul, Nat.add_assoc]\n \nend calc_p\n\n\n/- Existencial Quantifier -/\n\nnamespace exist\n  #check @Exists.intro\n  example : \u2203 x : Nat, x > 0 :=\n    have h : 1 > 0 := Nat.zero_lt_succ 0\n    Exists.intro 1 h\n\n  example (x : Nat) (h : x > 0) : \u2203 y : Nat, y < x :=\n    Exists.intro 0 h\n\n  example (x y z : Nat) (h1 : x < y) (h2 : y < z) : \u2203 w, x < w \u2227 w < z :=\n    Exists.intro y (And.intro h1 h2)\n\n  variable (g : Nat \u2192 Nat \u2192 Nat)\n\n\n  variable (hg : g 0 0 = 0)\n\n  theorem gex1 : \u2203 x, g x x = x := \u27e80, hg\u27e9\n  theorem gex2 : \u2203 x, g x 0 = x := \u27e80, hg\u27e9\n  theorem gex3 : \u2203 x, g 0 0 = x := \u27e80, hg\u27e9\n  theorem gex4 : \u2203 x, g x x = 0 := \u27e80, hg\u27e9\n\n  set_option pp.explicit true  -- display implicit arguments\n  #print gex1\n  #print gex2\n  #print gex3\n  #print gex4\n\n\n  variable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n  example (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\n    Exists.elim h\n      (fun w =>\n        fun hw : p w \u2227 q w =>\n          show \u2203 w, q w \u2227 p w from Exists.intro w (And.intro hw.right hw.left))\n\n  example (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\n    match h with\n    | Exists.intro w hw => Exists.intro w (And.intro hw.right hw.left)\n\n  example (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\n    match h with\n    | Exists.intro w (And.intro hpw hqw) => Exists.intro w (And.intro hqw hpw)\n\n  example (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x :=\n    let (Exists.intro w (And.intro hpw hqw)) := h\n    Exists.intro w (And.intro hqw hpw)\n\n\n  def is_even (a : Nat) := \u2203 b : Nat, a = 2 * b\n\n  theorem even_plus_even (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\n    match h1, h2 with\n    | Exists.intro w1 hw1, Exists.intro w2 hw2 =>\n        Exists.intro (w1 + w2)\n          (calc\n            a + b = 2 * w1 + 2 * w2 := by rw [hw1, hw2]\n            _ = 2 * (w1 + w2) := by simp [Nat.mul_add])\n\n  \n  example (h : \u00ac \u2200 x, \u00acp x) : \u2203 x, p x :=\n    Classical.byContradiction\n      (fun h1 : \u00ac \u2203 x, p x =>\n        have h2 : \u2200 x, \u00acp x :=\n          fun x => \n            fun h3 : p x =>\n              have h4 : \u2203 x, p x := Exists.intro x h3\n              show False from h1 h4\n        show False from h h2)\n\nend exist\n\n\n/- More on Proof Language -/\n\nnamespace proof_lang\n  variable (f : Nat \u2192 Nat)\n  variable (h : \u2200 x, f x \u2264 f (x + 1))\n\n  example : (f 0 \u2264 f 3) :=\n    have : f 0 \u2264 f 1 := h 0\n    have : f 0 \u2264 f 2 := Nat.le_trans this (h 1)\n    show f 0 \u2264 f 3 from Nat.le_trans this (h 2)\n\n  example : f 0 \u2264 f 3 :=\n    have : f 0 \u2264 f 1 := h 0\n    have : f 0 \u2264 f 2 := Nat.le_trans (by assumption) (h 1)\n    show f 0 \u2264 f 3 from Nat.le_trans (by assumption) (h 2) \n\n  example : f 0 \u2265 f 1 \u2192 f 1 \u2265 f 2 \u2192 f 0 = f 2 :=\n    fun _ : f 0 \u2265 f 1 =>\n    fun _ : f 1 \u2265 f 2 =>\n    have : f 0 \u2265 f 2 := Nat.le_trans \u2039f 1 \u2265 f 2\u203a \u2039f 0 \u2265 f 1\u203a \n    have : f 0 \u2264 f 2 := Nat.le_trans (h 0) (h 1)\n    show f 0 = f 2 from Nat.le_antisymm this \u2039f 0 \u2265 f 2\u203a\nend proof_lang", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/TheoremProvingLean/quantifiers_equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7371300811904268}}
{"text": "import data.real.basic\nimport data.matrix.notation\nimport linear_algebra.matrix\nimport linear_algebra.determinant\nimport group_theory.perm.fin\nimport tactic.norm_swap\n\nopen_locale big_operators\n\nnamespace e222\n\nsection\n\n-- We specialize `matrix` for n \u00d7 n matrices\nnotation `Mn[` \u03b1 `]` n := matrix (fin n) (fin n) \u03b1\n\n-- and a shortcut for Mn(\u211d)\nnotation `MnR ` n := Mn[\u211d]n\n\nvariables {n : \u2115}\nvariables (A : MnR n) (B : MnR n) (C : MnR n)\n\n-- Call the collection of n \u00d7 n matrices as M\u2099(\u211d).\n-- That is a vector space over the real numbers, of dimension n\u00b2.\nexample : finite_dimensional.finrank \u211d (MnR n) = n ^ 2 :=\nby simp [pow_two]   -- rw [matrix.findim_matrix, fintype.card_fin, nat.pow_two]\n\n-- The addition law in the vector space of n \u00d7 n matrices\nexample : A + B = \u03bb i j, A i j + B i j :=\nby { funext i j, refl } -- matrix.add_val A B\n\n-- Multiplication of a matrix by a real scalar, doesn't work\nexample (\u03b1 : \u211d) : \u03b1 \u2022 A = \u03bb i j, \u03b1 * (A i j) :=\nby { funext i j, refl } -- matrix.smul_val \u03b1 A i j\n\n-- Matrix is a vector space, which only needs a `module`\nexample : module \u211d (MnR n) :=\nby apply_instance\n-- ... so we can use a finite dimensional vector space instance\nexample : finite_dimensional \u211d (MnR n) :=\nby apply_instance\n\n-- An n \u00d7 n matrix has some finite basis of cardinality n ^ 2\nexample : \u2203 (s : finset (MnR n)) (b : basis s \u211d (MnR n)),\n            (finset.card s = n ^ 2) :=\nbegin\n  letI : is_noetherian \u211d (MnR n) := is_noetherian.iff_fg.mpr (by apply_instance),\n  let s_basis := is_noetherian.finset_basis \u211d (MnR n),\n  refine \u27e8_, s_basis, _\u27e9,\n  rw [\u2190finite_dimensional.finrank_eq_card_finset_basis s_basis,\n      matrix.finrank_matrix, fintype.card, finset.card_fin, pow_two]\nend\n\nvariables {m : \u2115}\n\n-- An m \u00d7 n matrix has some finite basis of cardinality m * n\nexample : \u2203 (s : finset (matrix (fin m) (fin n) \u211d)) (b : basis s \u211d (matrix (fin m) (fin n) \u211d)),\n            (finset.card s = m * n) :=\nbegin\n  letI : is_noetherian \u211d (matrix (fin m) (fin n) \u211d) := is_noetherian.iff_fg.mpr (by apply_instance),\n  let s_basis := is_noetherian.finset_basis \u211d (matrix (fin m) (fin n) \u211d),\n  refine \u27e8_, s_basis, _\u27e9,\n  rw [\u2190finite_dimensional.finrank_eq_card_finset_basis s_basis,\n      matrix.finrank_matrix],\n  repeat { rw [fintype.card, finset.card_fin] }\nend\n\n-- Multiplication is defined on n x n matrices\nexample : has_mul (MnR n) := by apply_instance -- show_term gives matrix.has_mul\n\n-- Multiplication is defined by sum of row elements times column elements\nexample : A * B = \u03bb i j, \u2211 k , A i k * B k j := rfl\n\n-- An n x n matrix represents a linear operator T : \u211d\u207f \u2192 \u211d\u207f\n-- ... vectors in \u211d\u207f are represented by functions of (fin n) \u2192 \u211d\n-- ... linear maps are notated by \u2192\u2097 with an optional \u2192\u2097[field R] parameter\nexample : \u2203 (T : (fin n \u2192 \u211d) \u2192\u2097[\u211d] fin n \u2192 \u211d), T.to_matrix' = A :=\nby { use A.to_lin', exact linear_map.to_matrix'_to_lin' _ }\n\nexample : (MnR n) \u2243\u2097[\u211d] ((fin n \u2192 \u211d) \u2192\u2097[\u211d] fin n \u2192 \u211d) := matrix.to_lin'\n\n-- Multiplication of matrices is the composition of transformations\nexample : A * B = (A.to_lin'.comp B.to_lin').to_matrix' :=\nby rw [\u2190matrix.to_lin'_mul, linear_map.to_matrix'_to_lin', matrix.mul_eq_mul]\n\n-- Multiplication of 1 x 1 matrices is commutative\nexample (A : MnR 1) (B : MnR 1) : A * B = B * A :=\nbegin\n  ext i j,\n  rw [matrix.mul_eq_mul, matrix.mul_eq_mul, matrix.mul_apply, matrix.mul_apply,\n      finset.sum_congr rfl],\n  intros x _,\n  rw mul_comm,\n  congr\nend\n\n-- Multiplication of 2 x 2 matrices is not necessarily commutative\nexample : \u2203 (A : MnR 2) (B : MnR 2), A * B \u2260 B * A :=\nbegin\n  use ![![0, 1], ![0, 0]],\n  use ![![0, 0], ![0, 1]],\n  intros h,\n  replace h := congr_fun (congr_fun h 0) 1,\n  norm_num at h\nend\n\n-- Zero matrix is the zero element of the vector space,\n-- adding it to any element, you get the same\n-- ... following examples use the monoid and semiring instances of matrices\nexample (A : matrix (fin m) (fin n) \u211d) : A + 0 = A := add_zero _\nexample (A : matrix (fin m) (fin n) \u211d) : 0 + A = A := zero_add _\n\n-- The identity matrix\nexample {i j} : (1 : MnR n) i j = if i = j then 1 else 0 := matrix.one_apply\n\n-- Multiplication by the identity matrix gets anything back\nexample : A * 1 = A := mul_one _\nexample : 1 * A = A := one_mul _\n\n-- Matrix distributive law\nexample : A * (B + C) = A * B + A * C :=\nmul_add _ _ _\n\n-- Matrix associative law\nexample : A * (B * C) = A * B * C :=\n(mul_assoc _ _ _).symm\n\n-- Proving associativity by composition of transformation\nexample : (A * (B * C)) = ((A.to_lin'.comp B.to_lin').comp C.to_lin').to_matrix' :=\nby { rw [linear_map.comp_assoc, \u2190matrix.to_lin'_mul, \u2190matrix.to_lin'_mul,\n         linear_map.to_matrix'_to_lin'], refl }\n\n-- A 1 x 1 matrix is invertible iff the element is nonzero\nexample (A : MnR 1) : A \u2260 0 \u2194 is_unit A :=\nbegin\n  have nonzero : A \u2260 0 \u2192 A 0 0 \u2260 0,\n    { intros nonzeroA nz,\n      refine nonzeroA _,\n      ext i j,\n      convert nz },\n  split,\n  { intros hA,\n    refine \u27e8\u27e8A, ![![1 / (A 0 0)]], _, _\u27e9, rfl\u27e9;\n    { ext i j,\n      rw [matrix.mul_eq_mul, matrix.mul_apply, fin.sum_univ_succ, subsingleton.elim i 0,\n          subsingleton.elim j 0],\n      simp [nonzero hA] } },\n  { rintros \u27e8\u27e8A, B, h, h'\u27e9, rfl\u27e9 H,\n    have : A 0 0 * B 0 0 = 1,\n      { convert matrix.ext_iff.mpr h 0 0,\n        rw [matrix.mul_eq_mul, matrix.mul_apply, fin.sum_univ_succ, fin.sum_univ_zero, add_zero] },\n    have hz : A 0 0 = 0 := matrix.ext_iff.mpr H 0 0,\n    rw [hz, zero_mul] at this,\n    exact zero_ne_one this }\nend\n\n-- A 2 x 2 matrix is invertible if the \"determinant\" is nonzero, without definition of determinants\nexample (A : MnR 2) {a b c d} (hA : A = ![![a, b], ![c, d]]) :\n        a * d - b * c \u2260 0 \u2194 is_unit A :=\nbegin\n  split,\n  { intros h,\n    refine \u27e8\u27e8A, (1 / (a * d - b * c)) \u2022 ![![d, -b], ![-c, a]], _, _\u27e9, rfl\u27e9;\n    { ext i j,\n      fin_cases i;\n      fin_cases j;\n      field_simp [hA, h];\n      ring } },\n  { rintros \u27e8\u27e8A, B, hAB, hBA\u27e9, rfl\u27e9 H,\n    simp only [units.coe_mk] at hA,\n    rw [\u2190matrix.ext_iff, hA, matrix.mul_eq_mul] at hBA hAB,\n    classical,\n    by_cases hn : a \u2260 0 \u2227 b \u2260 0 \u2227 c \u2260 0 \u2227 d \u2260 0,\n    { have ha' : a = b * c / d,\n        { rwa [eq_div_iff, \u2190sub_eq_zero],\n          simp [hn] },\n      have hBA' : a * B 0 0 + c * B 0 1 = 1,\n        { convert hBA 0 0 using 2;\n          simp [mul_comm] },\n      have hBA'' : b * B 0 0 + d * B 0 1 = 0,\n        { convert hBA 0 1 using 2;\n          simp [mul_comm] },\n      have hBv : B 0 1 = - b / d * B 0 0,\n        { field_simp [hn],\n          rw \u2190eq_neg_iff_add_eq_zero at hBA'',\n          simp [hBA'', mul_comm] },\n      have hd' : d = 0,\n        { field_simp [ha', hn, hBv] at hBA',\n          rw \u2190hBA',\n          ring },\n      simpa [hd'] using hn },\n    { simp only [not_and_distrib, not_not, ne.def] at hn,\n      have v0 : \u2200 x, matrix.vec_cons 0 (\u03bb (i : fin 1), 0) x = 0,\n        { intros x,\n          fin_cases x;\n          refl },\n      have h00 := hAB 0 0,\n      have h01 := hAB 0 1,\n      have h11 := hAB 1 1,\n      have h10 := hAB 1 0,\n      have h00' := hBA 0 0,\n      have h01' := hBA 0 1,\n      have h11' := hBA 1 1,\n      have h10' := hBA 1 0,\n      rcases hn with (rfl | rfl | rfl | rfl);\n      { simp only [zero_sub, sub_zero, zero_mul, mul_zero, neg_eq_zero, mul_eq_zero] at H,\n        rcases H with (rfl | rfl);\n        simp [matrix.mul_apply, fin.sum_univ_succ] at h00 h01 h11 h10 h00' h01' h11' h10';\n        assumption } } }\nend\n\n-- determinant of a 2 x 2 matrix is a * d - b * c\nlemma det_2 (A : MnR 2) {a b c d : \u211d} (hA : A = ![![a, b], ![c, d]]) :\n        matrix.det A = a * d - b * c :=\nbegin\n  simp [hA, matrix.det_succ_row_zero, fin.sum_univ_succ],\n  ring\nend\n\n--  A matrix is invertible iff the determinant is nonzero\nlemma is_unit_iff_det_ne_zero  {n : \u2115} (A : MnR n) : is_unit A \u2194 A.det \u2260 0 :=\nbegin\n  rw matrix.is_unit_iff_is_unit_det,\n  exact is_unit_iff_ne_zero\nend\n\n-- The general linear group, as a subtype of matrices\nabbreviation GL\u2099 (n : \u2115) (\u03b1 : Type*) [comm_ring \u03b1] : Type* := units (matrix (fin n) (fin n) \u03b1)\n\nlemma GL\u2099.is_unit_det {n : \u2115} (A : GL\u2099 n \u211d) : is_unit (matrix.det (A : MnR n)) :=\nbegin\n  rw \u2190matrix.is_unit_iff_is_unit_det,\n  exact units.is_unit _\nend\n\nlemma GL\u2099.det_ne_zero {n : \u2115} (A : GL\u2099 n \u211d) : matrix.det (A : MnR n) \u2260 0 :=\nbegin\n  rw \u2190is_unit_iff_det_ne_zero,\n  exact units.is_unit _\nend\n\n-- For GL\u2081(\u211d) matrices, everything but 0\nexample (A : GL\u2099 1 \u211d) : (A : MnR 1) \u2260 0 :=\nbegin\n  intro H,\n  simpa [H] using A.det_ne_zero\nend\n\n-- For M\u2082(\u211d) matrices, there are nonzero examples that are not GL\u2082(\u211d)\nexample (A : GL\u2099 2 \u211d) : ![![(0 : \u211d), 1], ![0, 0]] \u2260 (A : MnR 2) :=\nbegin\n  intro H,\n  apply A.det_ne_zero,\n  rw [\u2190H, det_2 _ rfl],\n  simp\nend\n\n-- If the inverse exists, it is unique\nexample {n : \u2115} (A : MnR n) (h : \u2203 B, A * B = 1 \u2227 B * A = 1) : \u2203! B, (A * B = 1 \u2227 B * A = 1) :=\nbegin\n  refine exists_unique_of_exists_of_unique h _,\n  rintros B C \u27e8hAB, hBA\u27e9 \u27e8hAC, hCA\u27e9,\n  have : B * (A * B) = B * (A * C),\n    { rw [hAB, hAC] },\n  rwa [matrix.mul_eq_mul, matrix.mul_eq_mul, \u2190matrix.mul_assoc,\n      matrix.mul_eq_mul, matrix.mul_eq_mul, \u2190matrix.mul_assoc,\n      \u2190matrix.mul_eq_mul, \u2190matrix.mul_eq_mul, \u2190matrix.mul_eq_mul, hBA,\n      one_mul, one_mul] at this\nend\n\n-- GL\u2099(\u211d) is not closed under addition\nexample (n : \u2115) : \u00ac is_unit (((1 : GL\u2099 (n + 1) \u211d) : MnR (n + 1)) + (-1 : GL\u2099 (n + 1) \u211d)) :=\nbegin\n  rw [units.coe_one, units.coe_neg_one, add_right_neg],\n  exact not_is_unit_zero\nend\n\n-- GL\u2099(\u211d) is not closed under scalar multiplication by 0\nexample (k : \u211d) {n : \u2115} (A : GL\u2099 (n + 1) \u211d) : \u00ac is_unit (k \u2022 (A : MnR (n + 1))) \u2194 k = 0 :=\nbegin\n  rw not_iff_comm,\n  split,\n  { intro h,\n    refine \u27e8\u27e8k \u2022 (A : MnR (n + 1)), (k \u2022 A)\u207b\u00b9, _, _\u27e9, rfl\u27e9;\n    { rw matrix.mul_eq_mul,\n      rw matrix.mul_nonsing_inv <|> rw matrix.nonsing_inv_mul,\n      rw [matrix.det_smul, is_unit_iff_ne_zero, mul_ne_zero_iff],\n      exact \u27e8pow_ne_zero _ h, A.det_ne_zero\u27e9 } },\n  { rintro \u27e8\u27e8A', B, hAB, hBA\u27e9, h\u27e9 rfl,\n    rw [units.coe_mk, zero_smul] at h,\n    rw [h, zero_mul] at hAB,\n    exact zero_ne_one hAB }\nend\n\n-- GL\u2099(\u211d) is closed under multiplication, proof 1\nexample {n : \u2115} (A B : GL\u2099 n \u211d) : is_unit ((A : MnR n) * B) :=\nbegin\n  refine \u27e8\u27e8(A : MnR n) * B, B\u207b\u00b9 * A\u207b\u00b9, _, _\u27e9, rfl\u27e9;\n  simp_rw [matrix.mul_eq_mul],\n  { rw [matrix.mul_assoc, \u2190matrix.mul_assoc (B : MnR n), matrix.mul_nonsing_inv _ B.is_unit_det,\n      matrix.one_mul, matrix.mul_nonsing_inv _ A.is_unit_det] },\n  { rw [matrix.mul_assoc, \u2190matrix.mul_assoc _ (A : MnR n), matrix.nonsing_inv_mul _ A.is_unit_det,\n      matrix.one_mul, matrix.nonsing_inv_mul _ B.is_unit_det] }\nend\n\n-- GL\u2099(\u211d) is closed under multiplication, proof 2\nexample {n : \u2115} (A B : GL\u2099 n \u211d) : is_unit ((A : MnR n) * B) :=\nbegin\n  rw [matrix.is_unit_iff_is_unit_det, matrix.mul_eq_mul, matrix.det_mul],\n  exact A.is_unit_det.mul B.is_unit_det\nend\n\n-- GL\u2099(\u211d) contains 1\nexample {n : \u2115} : is_unit (1 : MnR n) := \u27e8\u27e81, 1, one_mul _, one_mul _\u27e9, rfl\u27e9\n\n-- GL\u2099(\u211d) contains inverses\nexample {n : \u2115} (A : GL\u2099 n \u211d) : is_unit ((A : MnR n)\u207b\u00b9) :=\nbegin\n  refine \u27e8\u27e8A\u207b\u00b9, A, _, _\u27e9, rfl\u27e9,\n  rw [matrix.mul_eq_mul, matrix.nonsing_inv_mul _ A.is_unit_det],\n  rw [matrix.mul_eq_mul, matrix.mul_nonsing_inv _ A.is_unit_det]\nend\n\n-- GL\u2099(\u211d) multiplication is associative\nexample {n : \u2115} (A B C : GL\u2099 n \u211d) : A * B * C = A * (B * C) :=\nbegin\n  rw mul_assoc -- inherited from group structure on `units`\nend\n\nclass group (\u03b1 : Type*) :=\n(op : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(infixl `\u1d4d*`:70 := op)\n(assoc' : \u2200 g h k : \u03b1, g \u1d4d* (h \u1d4d* k) = (g \u1d4d* h) \u1d4d* k)\n(e : \u03b1)\n(notation `\u1d4d1`:50 := e)\n(op_e' : \u2200 g, g \u1d4d* \u1d4d1 = g)\n(e_op' : \u2200 g, \u1d4d1 \u1d4d* g = g)\n(inv : \u03b1 \u2192 \u03b1)\n(postfix `\u1d4d\u207b\u00b9`:max := inv)\n(inv_op' : \u2200 g, g\u1d4d\u207b\u00b9 \u1d4d* g = e)\n(op_inv' : \u2200 g, g \u1d4d* g\u1d4d\u207b\u00b9 = e)\n\ninfixl ` \u1d4d* `:70 := group.op\nnotation `\u1d4d1` := group.e\npostfix `\u1d4d\u207b\u00b9`:std.prec.max_plus := group.inv\n\nvariables {\u03b1 : Type*} [group \u03b1]\n\nnamespace group\n\nlemma mul_assoc (g h k : \u03b1) : g \u1d4d* (h \u1d4d* k) = (g \u1d4d* h) \u1d4d* k := group.assoc' _ _ _\n@[simp] lemma mul_one (g : \u03b1) : g \u1d4d* \u1d4d1 = g := group.op_e' _\n@[simp] lemma one_mul (g : \u03b1) : \u1d4d1 \u1d4d* g = g := group.e_op' _\n@[simp] lemma inv_mul (g : \u03b1) : g\u1d4d\u207b\u00b9 \u1d4d* g = \u1d4d1 := inv_op' _\n@[simp] lemma mul_inv (g : \u03b1) : g \u1d4d* g\u1d4d\u207b\u00b9 = \u1d4d1 := op_inv' _\n\nend group\n\nclass abelian_group (\u03b1 : Type*) extends group \u03b1 :=\n(comm : \u2200 (g h : \u03b1), g \u1d4d* h = h \u1d4d* g)\n\n-- The integers are an abelian group\nexample : abelian_group \u2124 :=\n{ op := (+),\n  assoc' := \u03bb _ _ _, (int.add_assoc _ _ _).symm,\n  e := 0,\n  op_e' := int.add_zero,\n  e_op' := int.zero_add,\n  inv := \u03bb x, -x,\n  inv_op' := int.add_left_neg,\n  op_inv' := int.add_right_neg,\n  comm := int.add_comm }\n\n-- Any vector space is an abelian group. Uses the proofs for groups already in mathlib\nexample (K V : Type*) [field K] [add_comm_group V] [module K V] : abelian_group V :=\n{ op := (+),\n  assoc' := \u03bb _ _ _, (add_assoc _ _ _).symm,\n  e := 0,\n  op_e' := add_zero,\n  e_op' := zero_add,\n  inv := \u03bb x, -x,\n  inv_op' := add_left_neg,\n  op_inv' := add_right_neg,\n  comm := add_comm }\n\n-- The bijections (symmetries) of a type are a group\n-- this example has `(f * g)(x) = g(f(x))`\nexample (T : Type*) : group (T \u2243 T) :=\n{ op := equiv.trans,\n  assoc' := equiv.trans_assoc,\n  e := equiv.refl _,\n  op_e' := equiv.trans_refl,\n  e_op' := equiv.refl_trans,\n  inv := equiv.symm,\n  inv_op' := equiv.symm_trans_self,\n  op_inv' := equiv.self_trans_symm }\n\nend\n\nopen matrix set linear_map\nvariables {R n : Type*} [comm_ring R] [fintype n] [decidable_eq n]\n\n-- The definition of GL\u2099(\u211d) is group-equivalent to the mathlib definition\nexample {n : \u2115} : (GL\u2099 n \u211d) \u2243* linear_map.general_linear_group \u211d (fin n \u2192 \u211d) :=\nunits.map_equiv to_lin_alg_equiv'.to_mul_equiv\n\n-- The symmetric group, as permutations of `fin n`\nnotation `S\u2099 ` n := equiv.perm (fin n)\n\n-- S\u2099 is a finite group of order `n!`\nexample {n : \u2115} : fintype.card (S\u2099 n) = nat.factorial n :=\nby rw [fintype.card_perm, fintype.card_fin]\n\n-- S\u2099 is not abelian for n = 3\nexample : \u2203 g h : S\u2099 3, g * h \u2260 h * g :=\nbegin\n  use [equiv.swap 0 1, equiv.swap 0 2],\n  intro H,\n  -- evaluate the swaps at the first element, which will make 2 = 1\n  have := equiv.congr_fun H 0,\n  -- norm_num discharges the false goal with the false hypothesis\n  norm_num at this\nend\n\nend e222\n", "meta": {"author": "pechersky", "repo": "e222", "sha": "db470367381d65dfc1e4e8fc1dd805b038dbfa93", "save_path": "github-repos/lean/pechersky-e222", "path": "github-repos/lean/pechersky-e222/e222-db470367381d65dfc1e4e8fc1dd805b038dbfa93/src/lecture01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539553, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.737073668949603}}
{"text": "import standard\nimport data.nat\n\nstructure Category : Type :=\n  (Obj : Type)\n  (Hom : Obj \u2192 Obj \u2192 Type)\n  \n  (Id : \u03a0 A : Obj, Hom A A)\n  (compose : \u03a0 \u2983A B C : Obj\u2984, Hom B C \u2192 Hom A B \u2192 Hom A C)\n\n  (Id_left  : \u03a0 \u2983A B : Obj\u2984 (f : Hom A B), compose !Id f = f)\n  (Id_right : \u03a0 \u2983A B : Obj\u2984 (f : Hom A B), compose f !Id = f)\n  (assoc : \u03a0 \u2983A B C D : Obj\u2984 (f : Hom C D) (g : Hom B C) (h : Hom A B),\n    compose (compose f g) h = compose f (compose g h))\n\nnamespace Category\n  -- Can we put this before the definition?\n  notation f `\u2218` g := compose _ f g\n  infix `\u27f6` :25 := Hom _\n\n  definition Mor := Hom\n\n  -- Do these do anything?\n  attribute mk [constructor]\n  attribute Obj [unfold 1]\n  attribute Hom [unfold 1]\n  attribute Id [unfold 1]\n  attribute compose [unfold 1]\nend Category\n\nopen Category \nopen nat\n\ndefinition \u2115Category : Category :=\n  \u2983 Category,\n    Obj     := unit,\n    Hom     := \u03bb a b, \u2115,\n    Id      := \u03bb a, 0,\n    compose := \u03bb a b c, add,\n\n    Id_left  := by blast,\n    Id_right := by blast,\n    assoc    := by blast \u2984\n\n--definition \u2115Category' : Category :=\n--begin\n--  refine (Category.mk unit (\u03bb a b, \u2115) (\u03bb a, 0) (\u03bb a b c, add) _ _ _),\n--end\n\nstructure Functor (source target : Category) : Type :=\n  (onObj : Obj source \u2192 Obj target)\n  (onMor : \u03a0 \u2983a b : Obj source\u2984, !Hom a b \u2192 !Hom (onObj a) (onObj b))\n  \n  (respect_Id   : \u03a0 (a : Obj source), onMor (Id _ a) = Id _ (onObj a))\n  (respect_comp : \u03a0 \u2983a b c : Obj source\u2984 (f : !Hom b c) (g : !Hom a b),\n                    onMor (f \u2218 g) = onMor f \u2218 onMor g)\n\nnamespace Functor\n  infix `<$>`:50  := \u03bb {C D : Category} (F : Functor C D) (a : Obj C), onObj F a\n  infix `<$>m`:50 := \u03bb {C D : Category} (F : Functor C D) {a b : Obj C}\n                       (f : !Hom a b), onMor F f\nend Functor\n\ntheorem double_order (n m p q : \u2115) : n + m + (p + q) = n + p + (m + q) :=\n  by blast\n--calc\n--  n + m + (p + q) = n + (m + (p + q)) : add.assoc n m (p + q)\n--              ... = n + (m + p + q)   : congr_arg (add n) (add.assoc m p q)\n--              ... = n + (p + m + q)   : congr_arg (add n) (congr_arg (swap add q) (add.comm m p))\n--              ... = n + (p + (m + q)) : congr_arg (add n) (add.assoc p m q)\n--              ... = n + p + (m + q)   : add.assoc n p (m + q)\n\ndefinition DoublingAsFunctor : Functor \u2115Category \u2115Category :=\n  \u2983 Functor,\n    onObj := id,\n    onMor := \u03bb a b (x : \u2115), x + x,\n\n    respect_Id   := by intros; trivial,\n    respect_comp := \u03bb a b c f g, double_order f g f g\u2984\n    --respect_comp := begin\n    --                intros,\n    --                unfold [\u2115Category],\n    --                exact (double_order f g f g)\n    --                end \u2984\n\nopen prod\n\ndefinition ProductCategory (C D : Category) : Category :=\n  \u2983 Category,\n    Obj := Obj C \u00d7 Obj D,\n    Hom := \u03bb a b, Hom C (pr1 a) (pr1 b) \u00d7 Hom D (pr2 a) (pr2 b),\n    Id  := \u03bb a, (Id C (pr1 a), Id D (pr2 a)),\n    compose := \u03bb a b c f g, (pr1 f \u2218 pr1 g, pr2 f \u2218 pr2 g),\n\n    Id_left  := by intros; exact prod.eq !Id_left !Id_left,\n    Id_right := by intros; exact prod.eq !Id_right !Id_right,\n    assoc    := by intros; exact prod.eq !assoc !assoc \u2984\n\nnamespace ProductCategory\n  notation C `\u00d7c` D := ProductCategory C D\nend ProductCategory\n\nopen Functor\nopen ProductCategory\n\nstructure LaxMonoidalCategory extends cat : Category :=\n  (tensor : Functor (cat \u00d7c cat) cat)\n  (unit : Obj)\n  \n  (associator : \u03a0 (a b c : Obj)\n                  (infix `\u2297`:70 := \u03bb (a b : Obj), tensor <$> (a, b)),\n                    Hom ((a \u2297 b) \u2297 c) (a \u2297 (b \u2297 c)))\n  (pentagon : \u03a0 (a b c d : Obj)\n                (infix `\u2218`     := compose)\n                (infix `\u2297`:70  := \u03bb (x y : Obj), tensor <$> (x, y))\n                (infix `\u2297m`:70 := \u03bb {x y z w : Obj} (f : Hom x y) (g : Hom z w),\n                  tensor <$>m (f, g)),\n                let \u03b1 := associator in\n                  (Id a \u2297m \u03b1 b c d) \u2218 (\u03b1 a (b \u2297 c) d) \u2218 (\u03b1 a b c \u2297m Id d)\n                    = \u03b1 a b (c \u2297 d) \u2218 \u03b1 (a \u2297 b) c d)\n   \n  (unitor_left  : \u03a0 (a : Obj)\n                    (infix `\u2297`:70 := \u03bb (a b : Obj), tensor <$> (a, b)),\n                      Hom (unit \u2297 a) a)\n  (unitor_right : \u03a0 (a : Obj)\n                    (infix `\u2297`:70 := \u03bb (a b : Obj), tensor <$> (a, b)),\n                      Hom (a \u2297 unit) a)\n  (triangle : \u03a0 (a b : Obj)\n                (infix `\u2218`     := compose)\n                (infix `\u2297`:70  := \u03bb (x y : Obj), tensor <$> (x, y))\n                (infix `\u2297m`:70 := \u03bb {x y z w : Obj} (f : Hom x y) (g : Hom z w),\n                  tensor <$>m (f, g)),\n                let L := unitor_left, R := unitor_right, \u03b1 := associator in\n                  R a \u2297m Id b = (Id a \u2297m L b) \u2218 \u03b1 a unit b)\n\nnamespace LaxMonoidalCategory\n  infix `\u2297`:70  := \u03bb {C : LaxMonoidalCategory} (a b : Obj C), tensor C <$> (a,b)\n  infix `\u2297m`:70 := \u03bb {C : LaxMonoidalCategory} {a b c d : Obj C}\n                     (f : Hom a b) (g : Hom c d), tensor C <$> (f,g)\nend LaxMonoidalCategory\n\ndefinition \u2115TensorProduct : Functor (\u2115Category \u00d7c \u2115Category) \u2115Category :=\n  \u2983 Functor,\n    onObj := pr1,\n    onMor := \u03bb a b (f : \u2115 \u00d7 \u2115), pr1 f + pr2 f,\n\n    respect_Id   := by intros; trivial,\n    respect_comp := \u03bb a b c (f g : \u2115 \u00d7 \u2115), by krewrite double_order \u2984\n\n--definition \u2115TensorProduct' : Functor (\u2115Category \u00d7c \u2115Category) \u2115Category :=\n--  Functor.mk pr1 (\u03bb a b (f : \u2115 \u00d7 \u2115), pr1 f + pr2 f) _ _ _\n--begin\n--  refine Functor.mk (pr1) (\u03bb (a b : unit), \u03bb (f : \u2115 \u00d7 \u2115), pr1 f + pr2 f) _ _,\n--end\n\ndefinition \u2115LaxMonoidalCategory : LaxMonoidalCategory :=\n  \u2983 LaxMonoidalCategory,\n    \u2115Category,\n    tensor := \u2115TensorProduct,\n    unit   := unit.star,\n\n    associator := \u03bb a b c, Id _ _,\n    pentagon := sorry,\n\n    unitor_left  := Id _,\n    unitor_right := Id _,\n    triangle := sorry\n    \u2984\n\nopen LaxMonoidalCategory\n\n--check (2 : Hom \u2115LaxMonoidalCategory unit.star unit.star)\n", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/category-theory2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7369886980999864}}
{"text": "def even(n : \u2115) : Prop := \u2203 m, n = 2 * m\n\n#check even 10\n\nexample : even 10 := \u27e8 5, rfl \u27e9\n\n\ntheorem and_commutative (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\nassume hpq : p \u2227 q,\nhave hp : p, from and.left hpq,\nhave hq : q, from and.right hpq,\nshow q \u2227 p, from and.intro hq hp\n\n#check and_commutative\n#print and_commutative\n\n\ntheorem and_commutative' (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\nbegin\n  intro hp,\n  apply and.intro,\n  exact and.right hp,\n  exact and.left hp,\nend\n\n#check and_commutative'\n#print and_commutative'\n\n#check prod\n#print prod\n\n#check list\n\nuniverse u \nconstant \u03b1 : Type u \n#check \u03b1\n\n#check fun x : nat, x + 5\n#check \u03bb x : nat, x + 5\n\n\nconstants (a : \u03b1) (b : \u03b2)\n#reduce (\u03bb x : \u03b1, x) a\n\n#eval (\u03bb x : \u03b1, x) a\n\ndef foo : (\u2115 \u2192 \u2115) \u2192 \u2115 := \u03bb f, f 0\n\n#check foo\n\n#check (\u2115 \u2192 \u2115) \u2192 \u2115\n\n#print foo\n\ndef curry (\u03b1 \u03b2 \u03b3 : Type) (f : \u03b1 \u00d7 \u03b2 \u2192 \u03b3) : \u03b1 \u2192 \u03b2 \u2192 \u03b3 := \u03bb x y, f (x, y)\n\n#check curry\n#print curry\n\n#check let y := 2 + 2, z := y + y in z * z\n#reduce let y := 2 + 2, z := y + y in z * z\n\ndef foo1 := let a := nat in \u03bb x : a, x + 2\n#check foo1\n/-\ndef bar := (\u03bb a, \u03bb x : a, x + 2) nat\n#check bar\n-/\n\n\n\n\n#check curry\n#print curry\n\n#check 0 - 1\n#reduce 0 + 1\n#reduce 0 - 1\n\n\n\n\n", "meta": {"author": "FiveEyes", "repo": "SoftwareFoundationsSolution", "sha": "d66c636107ac6fd7276504324c6da28c4775dd75", "save_path": "github-repos/lean/FiveEyes-SoftwareFoundationsSolution", "path": "github-repos/lean/FiveEyes-SoftwareFoundationsSolution/SoftwareFoundationsSolution-d66c636107ac6fd7276504324c6da28c4775dd75/LEAN/demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7369554066417118}}
{"text": "/- Tactic : rw\n\n## Summary\n\nIf `h` is a proof of `X = Y`, then `rw h,` will change\nall `X`s in the goal to `Y`s. \n\n**Variants:** `rw \u2190 h` changes\n`Y` to `X` and\n`rw h at h2` changes `X` to `Y` in hypothesis `h2` instead\nof the goal.\n\n## Details\n\nThe `rw` tactic is a way to do \"substituting in\". There\nare two distinct situations where use this tactics.\n\n1) If `h : A = B` is a hypothesis (i.e., a proof of `A = B`)\nin your local context (the box in the top right)\nand if your goal contains one or more `A`s, then `rw h`\nwill change them all to `B`'s. \n\n2) The `rw` tactic will also work with proofs of theorems\nwhich are equalities (look for them in the drop down\nmenu on the left, within Theorem Statements).\n\n**Important note:** if `h` is not a proof of the form `A = B`\nor `A \u2194 B` (for example if `h` is a function, an implication,\nor perhaps even a proposition itself rather than its proof),\nthen `rw` is not the tactic you want to use. For example,\n`rw (P = Q)` is never correct: `P = Q` is the true-false\nstatement itself, not the proof.\nIf `h : P = Q` is its proof, then `rw h` will work.\n\n**Pro tip 1:** If `h : A = B` and you want to change\n`B`s to `A`s instead, try `rw \u2190h` (get the arrow with `\\l`,\nnote that this is a small letter L, not a number 1).\n\n### Example:\nIf it looks like this in the top right hand box:\n```\nA B C : Point\nh1 : A = B\nh2 : B = C\n\u22a2 A = C\n```\n\nthen\n\n`rw h1,`\n\nwill change the goal into `\u22a2 B = C`.\n\n### Example: \nYou can use `rw` to change a hypothesis as well. \nFor example, if your local context looks like this:\n```\nA B C : Point\nh1 : A = C\nh2 : A = B\n\u22a2 B = C\n```\nthen `rw h1 at h2` will turn `h2` into `h2 : C = B` (remember operator precedence).\n\n-/\n\n\n/-\nThe next tactic we will learn is `rw` (from rewrite). It rewrites equalities. That is,\nif we have a proof `h : A = B` and we want to prove `\u22a2 A = C`, then after `rw h` the goal\nwill become `\u22a2 B = C`.\n\nAfter many tactics (and `rw` is one of them) Lean tries to apply `refl`. This is why\nin the following proof you may get away with only two tactic applications.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nDelete `sorry` and type `rw h,` (don't forget the comma!). Lean tries `refl` afterwards,\nso you will see that this suffices.\n-/\n\nvariables {\u03a9 : Type} -- hide\n\n/- Lemma : no-side-bar\nIf A, B and C are points with A = B and B = C, then A = C.\n-/\nlemma example_rw (A B C: \u03a9) (h1 : A = B) (h2 : B = C) : A = C :=\nbegin\n  rw h1,\n  rw h2,\n  \nend\n", "meta": {"author": "mmasdeu", "repo": "hilbertgame", "sha": "0557019a1b7220bab7fe35729646c25bf73f0447", "save_path": "github-repos/lean/mmasdeu-hilbertgame", "path": "github-repos/lean/mmasdeu-hilbertgame/hilbertgame-0557019a1b7220bab7fe35729646c25bf73f0447/src/tutorial_world/level02_rw.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.7369553887451747}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n-/\nimport algebra.group.with_one\nimport algebra.group.type_tags\nimport algebra.group.prod\nimport algebra.order_functions\nimport order.bounded_lattice\n\n/-!\n# Ordered monoids\n\nThis file develops the basics of ordered monoids.\n\n## Implementation details\n\nUnfortunately, the number of `'` appended to lemmas in this file\nmay differ between the multiplicative and the additive version of a lemma.\nThe reason is that we did not want to change existing names in the library.\n-/\n\nset_option old_structure_cmd true\n\nuniverse u\nvariable {\u03b1 : Type u}\n\n/-- An ordered commutative monoid is a commutative monoid\nwith a partial order such that\n  * `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone)\n  * `a * b < a * c \u2192 b < c`.\n-/\n@[protect_proj, ancestor comm_monoid partial_order]\nclass ordered_comm_monoid (\u03b1 : Type*) extends comm_monoid \u03b1, partial_order \u03b1 :=\n(mul_le_mul_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\n(lt_of_mul_lt_mul_left : \u2200 a b c : \u03b1, a * b < a * c \u2192 b < c)\n\n/-- An ordered (additive) commutative monoid is a commutative monoid\n  with a partial order such that\n  * `a \u2264 b \u2192 c + a \u2264 c + b` (addition is monotone)\n  * `a + b < a + c \u2192 b < c`.\n-/\n\n@[protect_proj, ancestor add_comm_monoid partial_order]\nclass ordered_add_comm_monoid (\u03b1 : Type*) extends add_comm_monoid \u03b1, partial_order \u03b1 :=\n(add_le_add_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n(lt_of_add_lt_add_left : \u2200 a b c : \u03b1, a + b < a + c \u2192 b < c)\n\nattribute [to_additive] ordered_comm_monoid\n\n/-- An `ordered_comm_monoid` with one-sided 'division' in the sense that\nif `a \u2264 b`, there is some `c` for which `a * c = b`. This is a weaker version\nof the condition on canonical orderings defined by `canonically_ordered_monoid`. -/\nclass has_exists_mul_of_le (\u03b1 : Type u) [ordered_comm_monoid \u03b1] : Prop :=\n(exists_mul_of_le : \u2200 {a b : \u03b1}, a \u2264 b \u2192 \u2203 (c : \u03b1), b = a * c)\n\nexport has_exists_mul_of_le (exists_mul_of_le)\n\n/-- An `ordered_add_comm_monoid` with one-sided 'subtraction' in the sense that\nif `a \u2264 b`, then there is some `c` for which `a + c = b`. This is a weaker version\nof the condition on canonical orderings defined by `canonically_ordered_add_monoid`. -/\nclass has_exists_add_of_le (\u03b1 : Type u) [ordered_add_comm_monoid \u03b1] : Prop :=\n(exists_add_of_le : \u2200 {a b : \u03b1}, a \u2264 b \u2192 \u2203 (c : \u03b1), b = a + c)\n\nexport has_exists_add_of_le (exists_add_of_le)\n\nattribute [to_additive] has_exists_mul_of_le\n\n/-- A linearly ordered additive commutative monoid. -/\n@[protect_proj, ancestor linear_order ordered_add_comm_monoid]\nclass linear_ordered_add_comm_monoid (\u03b1 : Type*)\n  extends linear_order \u03b1, ordered_add_comm_monoid \u03b1 :=\n(lt_of_add_lt_add_left := \u03bb x y z, by {\n  apply imp_of_not_imp_not,\n  intro h,\n  apply not_lt_of_le,\n  apply add_le_add_left,\n  -- type-class inference uses `a : linear_order \u03b1` which it can't unfold, unless we provide this!\n  -- `lt_iff_le_not_le` gets filled incorrectly with `autoparam` if we don't provide that field.\n  letI : linear_order \u03b1 := by refine { le := le, lt := lt, lt_iff_le_not_le := _, .. }; assumption,\n  exact le_of_not_lt h })\n\n/-- A linearly ordered commutative monoid. -/\n@[protect_proj, ancestor linear_order ordered_comm_monoid, to_additive]\nclass linear_ordered_comm_monoid (\u03b1 : Type*)\n  extends linear_order \u03b1, ordered_comm_monoid \u03b1 :=\n(lt_of_mul_lt_mul_left := \u03bb x y z, by {\n  apply imp_of_not_imp_not,\n  intro h,\n  apply not_lt_of_le,\n  apply mul_le_mul_left,\n  -- type-class inference uses `a : linear_order \u03b1` which it can't unfold, unless we provide this!\n  -- `lt_iff_le_not_le` gets filled incorrectly with `autoparam` if we don't provide that field.\n  letI : linear_order \u03b1 := by refine { le := le, lt := lt, lt_iff_le_not_le := _, .. }; assumption,\n  exact le_of_not_lt h })\n\n/-- A linearly ordered commutative monoid with a zero element. -/\nclass linear_ordered_comm_monoid_with_zero (\u03b1 : Type*)\n  extends linear_ordered_comm_monoid \u03b1, comm_monoid_with_zero \u03b1 :=\n(zero_le_one : (0 : \u03b1) \u2264 1)\n\n/-- A linearly ordered commutative monoid with an additively absorbing `\u22a4` element.\n  Instances should include number systems with an infinite element adjoined.` -/\n@[protect_proj, ancestor linear_ordered_add_comm_monoid order_top]\nclass linear_ordered_add_comm_monoid_with_top (\u03b1 : Type*)\n  extends linear_ordered_add_comm_monoid \u03b1, order_top \u03b1 :=\n(top_add' : \u2200 x : \u03b1, \u22a4 + x = \u22a4)\n\nsection linear_ordered_add_comm_monoid_with_top\nvariables [linear_ordered_add_comm_monoid_with_top \u03b1] {a b : \u03b1}\n\n@[simp]\nlemma top_add (a : \u03b1) : \u22a4 + a = \u22a4 := linear_ordered_add_comm_monoid_with_top.top_add' a\n\n@[simp]\nlemma add_top (a : \u03b1) : a + \u22a4 = \u22a4 :=\nby rw [add_comm, top_add]\n\nend linear_ordered_add_comm_monoid_with_top\n\nsection ordered_comm_monoid\nvariables [ordered_comm_monoid \u03b1] {a b c d : \u03b1}\n\n@[to_additive add_le_add_left]\nlemma mul_le_mul_left' (h : a \u2264 b) (c) : c * a \u2264 c * b :=\nordered_comm_monoid.mul_le_mul_left a b h c\n\n@[to_additive add_le_add_right]\nlemma mul_le_mul_right' (h : a \u2264 b) (c) : a * c \u2264 b * c :=\nby { convert mul_le_mul_left' h c using 1; rw mul_comm }\n\n@[to_additive]\nlemma mul_lt_of_mul_lt_left (h : a * b < c) (hle : d \u2264 b) : a * d < c :=\n(mul_le_mul_left' hle a).trans_lt h\n\n@[to_additive]\nlemma mul_lt_of_mul_lt_right (h : a * b < c) (hle : d \u2264 a) : d * b < c :=\n(mul_le_mul_right' hle b).trans_lt h\n\n@[to_additive]\nlemma mul_le_of_mul_le_left (h : a * b \u2264 c) (hle : d \u2264 b) : a * d \u2264 c :=\n(mul_le_mul_left' hle a).trans h\n\n@[to_additive]\nlemma mul_le_of_mul_le_right (h : a * b \u2264 c) (hle : d \u2264 a) : d * b \u2264 c :=\n(mul_le_mul_right' hle b).trans h\n\n@[to_additive]\nlemma lt_mul_of_lt_mul_left (h : a < b * c) (hle : c \u2264 d) : a < b * d :=\nh.trans_le (mul_le_mul_left' hle b)\n\n@[to_additive]\nlemma lt_mul_of_lt_mul_right (h : a < b * c) (hle : b \u2264 d) : a < d * c :=\nh.trans_le (mul_le_mul_right' hle c)\n\n@[to_additive]\nlemma le_mul_of_le_mul_left (h : a \u2264 b * c) (hle : c \u2264 d) : a \u2264 b * d :=\nh.trans (mul_le_mul_left' hle b)\n\n@[to_additive]\nlemma le_mul_of_le_mul_right (h : a \u2264 b * c) (hle : b \u2264 d) : a \u2264 d * c :=\nh.trans (mul_le_mul_right' hle c)\n\n@[to_additive lt_of_add_lt_add_left]\nlemma lt_of_mul_lt_mul_left' : a * b < a * c \u2192 b < c :=\nordered_comm_monoid.lt_of_mul_lt_mul_left a b c\n\n@[to_additive lt_of_add_lt_add_right]\nlemma lt_of_mul_lt_mul_right' (h : a * b < c * b) : a < c :=\nlt_of_mul_lt_mul_left'\n  (show b * a < b * c, begin rw [mul_comm b a, mul_comm b c], assumption end)\n\n@[to_additive add_le_add]\nlemma mul_le_mul' (h\u2081 : a \u2264 b) (h\u2082 : c \u2264 d) : a * c \u2264 b * d :=\n(mul_le_mul_right' h\u2081 _).trans $ mul_le_mul_left' h\u2082 _\n\n@[to_additive]\nlemma mul_le_mul_three {e f : \u03b1} (h\u2081 : a \u2264 d) (h\u2082 : b \u2264 e) (h\u2083 : c \u2264 f) : a * b * c \u2264 d * e * f :=\nmul_le_mul' (mul_le_mul' h\u2081 h\u2082) h\u2083\n\n-- here we start using properties of one.\n@[to_additive le_add_of_nonneg_right]\nlemma le_mul_of_one_le_right' (h : 1 \u2264 b) : a \u2264 a * b :=\nby simpa only [mul_one] using mul_le_mul_left' h a\n\n@[to_additive le_add_of_nonneg_left]\nlemma le_mul_of_one_le_left' (h : 1 \u2264 b) : a \u2264 b * a :=\nby simpa only [one_mul] using mul_le_mul_right' h a\n\n@[to_additive add_le_of_nonpos_right]\nlemma mul_le_of_le_one_right' (h : b \u2264 1) : a * b \u2264 a :=\nby simpa only [mul_one] using mul_le_mul_left' h a\n\n@[to_additive add_le_of_nonpos_left]\nlemma mul_le_of_le_one_left' (h : b \u2264 1) : b * a \u2264 a :=\nby simpa only [one_mul] using mul_le_mul_right' h a\n\n@[to_additive]\nlemma lt_of_mul_lt_of_one_le_left (h : a * b < c) (hle : 1 \u2264 b) : a < c :=\n(le_mul_of_one_le_right' hle).trans_lt h\n\n@[to_additive]\nlemma lt_of_mul_lt_of_one_le_right (h : a * b < c) (hle : 1 \u2264 a) : b < c :=\n(le_mul_of_one_le_left' hle).trans_lt h\n\n@[to_additive]\nlemma le_of_mul_le_of_one_le_left (h : a * b \u2264 c) (hle : 1 \u2264 b) : a \u2264 c :=\n(le_mul_of_one_le_right' hle).trans h\n\n@[to_additive]\nlemma le_of_mul_le_of_one_le_right (h : a * b \u2264 c) (hle : 1 \u2264 a) : b \u2264 c :=\n(le_mul_of_one_le_left' hle).trans h\n\n@[to_additive]\nlemma lt_of_lt_mul_of_le_one_left (h : a < b * c) (hle : c \u2264 1) : a < b :=\nh.trans_le (mul_le_of_le_one_right' hle)\n\n@[to_additive]\nlemma lt_of_lt_mul_of_le_one_right (h : a < b * c) (hle : b \u2264 1) : a < c :=\nh.trans_le (mul_le_of_le_one_left' hle)\n\n@[to_additive]\nlemma le_of_le_mul_of_le_one_left (h : a \u2264 b * c) (hle : c \u2264 1) : a \u2264 b :=\nh.trans (mul_le_of_le_one_right' hle)\n\n@[to_additive]\nlemma le_of_le_mul_of_le_one_right (h : a \u2264 b * c) (hle : b \u2264 1) : a \u2264 c :=\nh.trans (mul_le_of_le_one_left' hle)\n\n@[to_additive]\nlemma le_mul_of_one_le_of_le (ha : 1 \u2264 a) (hbc : b \u2264 c) : b \u2264 a * c :=\none_mul b \u25b8 mul_le_mul' ha hbc\n\n@[to_additive]\nlemma le_mul_of_le_of_one_le (hbc : b \u2264 c) (ha : 1 \u2264 a) : b \u2264 c * a :=\nmul_one b \u25b8 mul_le_mul' hbc ha\n\n@[to_additive add_nonneg]\nlemma one_le_mul (ha : 1 \u2264 a) (hb : 1 \u2264 b) : 1 \u2264 a * b :=\nle_mul_of_one_le_of_le ha hb\n\n@[to_additive add_pos_of_pos_of_nonneg]\nlemma one_lt_mul_of_lt_of_le' (ha : 1 < a) (hb : 1 \u2264 b) : 1 < a * b :=\nlt_of_lt_of_le ha $ le_mul_of_one_le_right' hb\n\n@[to_additive add_pos_of_nonneg_of_pos]\nlemma one_lt_mul_of_le_of_lt' (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\nlt_of_lt_of_le hb $ le_mul_of_one_le_left' ha\n\n@[to_additive add_pos]\nlemma one_lt_mul' (ha : 1 < a) (hb : 1 < b) : 1 < a * b :=\none_lt_mul_of_lt_of_le' ha hb.le\n\n@[to_additive add_nonpos]\nlemma mul_le_one' (ha : a \u2264 1) (hb : b \u2264 1) : a * b \u2264 1 :=\none_mul (1:\u03b1) \u25b8 (mul_le_mul' ha hb)\n\n@[to_additive]\nlemma mul_le_of_le_one_of_le' (ha : a \u2264 1) (hbc : b \u2264 c) : a * b \u2264 c :=\none_mul c \u25b8 mul_le_mul' ha hbc\n\n@[to_additive]\nlemma mul_le_of_le_of_le_one' (hbc : b \u2264 c) (ha : a \u2264 1) : b * a \u2264 c :=\nmul_one c \u25b8 mul_le_mul' hbc ha\n\n@[to_additive]\nlemma mul_lt_one_of_lt_one_of_le_one' (ha : a < 1) (hb : b \u2264 1) : a * b < 1 :=\n(mul_le_of_le_of_le_one' le_rfl hb).trans_lt ha\n\n@[to_additive]\nlemma mul_lt_one_of_le_one_of_lt_one' (ha : a \u2264 1) (hb : b < 1) : a * b < 1 :=\n(mul_le_of_le_one_of_le' ha le_rfl).trans_lt hb\n\n@[to_additive]\nlemma mul_lt_one' (ha : a < 1) (hb : b < 1) : a * b < 1 :=\nmul_lt_one_of_le_one_of_lt_one' ha.le hb\n\n@[to_additive]\nlemma lt_mul_of_one_le_of_lt' (ha : 1 \u2264 a) (hbc : b < c) : b < a * c :=\nhbc.trans_le $ le_mul_of_one_le_left' ha\n\n@[to_additive]\nlemma lt_mul_of_lt_of_one_le' (hbc : b < c) (ha : 1 \u2264 a) : b < c * a :=\nhbc.trans_le $ le_mul_of_one_le_right' ha\n\n@[to_additive]\nlemma lt_mul_of_one_lt_of_lt' (ha : 1 < a) (hbc : b < c) : b < a * c :=\nlt_mul_of_one_le_of_lt' ha.le hbc\n\n@[to_additive]\nlemma lt_mul_of_lt_of_one_lt' (hbc : b < c) (ha : 1 < a) : b < c * a :=\nlt_mul_of_lt_of_one_le' hbc ha.le\n\n@[to_additive]\nlemma mul_lt_of_le_one_of_lt' (ha : a \u2264 1) (hbc : b < c) : a * b < c :=\nlt_of_le_of_lt (mul_le_of_le_one_of_le' ha le_rfl) hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_of_le_one' (hbc : b < c) (ha : a \u2264 1)  : b * a < c :=\nlt_of_le_of_lt (mul_le_of_le_of_le_one' le_rfl ha) hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_one_of_lt' (ha : a < 1) (hbc : b < c) : a * b < c :=\nmul_lt_of_le_one_of_lt' ha.le hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_of_lt_one' (hbc : b < c) (ha : a < 1) : b * a < c :=\nmul_lt_of_lt_of_le_one' hbc ha.le\n\n@[to_additive]\nlemma mul_eq_one_iff' (ha : 1 \u2264 a) (hb : 1 \u2264 b) : a * b = 1 \u2194 a = 1 \u2227 b = 1 :=\niff.intro\n  (assume hab : a * b = 1,\n   have a \u2264 1, from hab \u25b8 le_mul_of_le_of_one_le le_rfl hb,\n   have a = 1, from le_antisymm this ha,\n   have b \u2264 1, from hab \u25b8 le_mul_of_one_le_of_le ha le_rfl,\n   have b = 1, from le_antisymm this hb,\n   and.intro \u2039a = 1\u203a \u2039b = 1\u203a)\n  (assume \u27e8ha', hb'\u27e9, by rw [ha', hb', mul_one])\n\n/-- Pullback an `ordered_comm_monoid` under an injective map. -/\n@[to_additive function.injective.ordered_add_comm_monoid\n\"Pullback an `ordered_add_comm_monoid` under an injective map.\"]\ndef function.injective.ordered_comm_monoid {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_comm_monoid \u03b2 :=\n{ mul_le_mul_left := \u03bb a b ab c,\n    show f (c * a) \u2264 f (c * b), by simp [mul, mul_le_mul_left' ab],\n  lt_of_mul_lt_mul_left :=\n    \u03bb a b c bc, @lt_of_mul_lt_mul_left' _ _ (f a) _ _ (by rwa [\u2190 mul, \u2190 mul]),\n  ..partial_order.lift f hf,\n  ..hf.comm_monoid f one mul }\n\nsection mono\n\nvariables {\u03b2 : Type*} [preorder \u03b2] {f g : \u03b2 \u2192 \u03b1}\n\n@[to_additive monotone.add]\nlemma monotone.mul' (hf : monotone f) (hg : monotone g) : monotone (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_le_mul' (hf h) (hg h)\n\n@[to_additive monotone.add_const]\nlemma monotone.mul_const' (hf : monotone f) (a : \u03b1) : monotone (\u03bb x, f x * a) :=\nhf.mul' monotone_const\n\n@[to_additive monotone.const_add]\nlemma monotone.const_mul' (hf : monotone f) (a : \u03b1) : monotone (\u03bb x, a * f x) :=\nmonotone_const.mul' hf\n\nend mono\n\nend ordered_comm_monoid\n\n/-- Pullback a `linear_ordered_comm_monoid` under an injective map. -/\n@[to_additive function.injective.linear_ordered_add_comm_monoid\n\"Pullback an `ordered_add_comm_monoid` under an injective map.\"]\ndef function.injective.linear_ordered_comm_monoid [linear_ordered_comm_monoid \u03b1] {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  linear_ordered_comm_monoid \u03b2 :=\n{ .. hf.ordered_comm_monoid f one mul,\n  .. linear_order.lift f hf }\n\nlemma bit0_pos [ordered_add_comm_monoid \u03b1] {a : \u03b1} (h : 0 < a) : 0 < bit0 a :=\nadd_pos h h\n\nnamespace units\n\n@[to_additive]\ninstance [monoid \u03b1] [preorder \u03b1] : preorder (units \u03b1) :=\npreorder.lift (coe : units \u03b1 \u2192 \u03b1)\n\n@[simp, norm_cast, to_additive]\ntheorem coe_le_coe [monoid \u03b1] [preorder \u03b1] {a b : units \u03b1} :\n  (a : \u03b1) \u2264 b \u2194 a \u2264 b := iff.rfl\n\n-- should `to_additive` do this?\nattribute [norm_cast] add_units.coe_le_coe\n\n@[simp, norm_cast, to_additive]\ntheorem coe_lt_coe [monoid \u03b1] [preorder \u03b1] {a b : units \u03b1} :\n  (a : \u03b1) < b \u2194 a < b := iff.rfl\n\nattribute [norm_cast] add_units.coe_lt_coe\n\n@[to_additive]\ninstance [monoid \u03b1] [partial_order \u03b1] : partial_order (units \u03b1) :=\npartial_order.lift coe units.ext\n\n@[to_additive]\ninstance [monoid \u03b1] [linear_order \u03b1] : linear_order (units \u03b1) :=\nlinear_order.lift coe units.ext\n\n@[simp, norm_cast, to_additive]\ntheorem max_coe [monoid \u03b1] [linear_order \u03b1] {a b : units \u03b1} :\n  (\u2191(max a b) : \u03b1) = max a b :=\nby by_cases b \u2264 a; simp [max, h]\n\nattribute [norm_cast] add_units.max_coe\n\n@[simp, norm_cast, to_additive]\ntheorem min_coe [monoid \u03b1] [linear_order \u03b1] {a b : units \u03b1} :\n  (\u2191(min a b) : \u03b1) = min a b :=\nby by_cases a \u2264 b; simp [min, h]\n\nattribute [norm_cast] add_units.min_coe\n\nend units\n\nnamespace with_zero\n\nlocal attribute [semireducible] with_zero\n\ninstance [preorder \u03b1] : preorder (with_zero \u03b1) := with_bot.preorder\n\ninstance [partial_order \u03b1] : partial_order (with_zero \u03b1) := with_bot.partial_order\n\ninstance [partial_order \u03b1] : order_bot (with_zero \u03b1) := with_bot.order_bot\n\nlemma zero_le [partial_order \u03b1] (a : with_zero \u03b1) : 0 \u2264 a := order_bot.bot_le a\n\nlemma zero_lt_coe [partial_order \u03b1] (a : \u03b1) : (0 : with_zero \u03b1) < a := with_bot.bot_lt_coe a\n\n@[simp, norm_cast] lemma coe_lt_coe [partial_order \u03b1] {a b : \u03b1} : (a : with_zero \u03b1) < b \u2194 a < b :=\nwith_bot.coe_lt_coe\n\n@[simp, norm_cast] lemma coe_le_coe [partial_order \u03b1] {a b : \u03b1} : (a : with_zero \u03b1) \u2264 b \u2194 a \u2264 b :=\nwith_bot.coe_le_coe\n\ninstance [lattice \u03b1] : lattice (with_zero \u03b1) := with_bot.lattice\n\ninstance [linear_order \u03b1] : linear_order (with_zero \u03b1) := with_bot.linear_order\n\nlemma mul_le_mul_left {\u03b1 : Type u}\n  [ordered_comm_monoid \u03b1] :\n  \u2200 (a b : with_zero \u03b1),\n    a \u2264 b \u2192 \u2200 (c : with_zero \u03b1), c * a \u2264 c * b :=\nbegin\n  rintro (_ | a) (_ | b) h (_ | c),\n  { apply with_zero.zero_le },\n  { apply with_zero.zero_le },\n  { apply with_zero.zero_le },\n  { apply with_zero.zero_le },\n  { apply with_zero.zero_le },\n  { exact false.elim (not_lt_of_le h (with_zero.zero_lt_coe a))},\n  { apply with_zero.zero_le },\n  { simp_rw [some_eq_coe] at h \u22a2,\n    norm_cast at h \u22a2,\n    exact mul_le_mul_left' h c }\nend\n\nlemma lt_of_mul_lt_mul_left  {\u03b1 : Type u}\n  [ordered_comm_monoid \u03b1] :\n  \u2200 (a b c : with_zero \u03b1), a * b < a * c \u2192 b < c :=\nbegin\n  rintro (_ | a) (_ | b) (_ | c) h,\n  { exact false.elim (lt_irrefl none h) },\n  { exact false.elim (lt_irrefl none h) },\n  { exact false.elim (lt_irrefl none h) },\n  { exact false.elim (lt_irrefl none h) },\n  { exact false.elim (lt_irrefl none h) },\n  { exact with_zero.zero_lt_coe c },\n  { exact false.elim (not_le_of_lt h (with_zero.zero_le _)) },\n  { simp_rw [some_eq_coe] at h \u22a2,\n    norm_cast at h \u22a2,\n    apply lt_of_mul_lt_mul_left' h }\nend\n\ninstance [ordered_comm_monoid \u03b1] : ordered_comm_monoid (with_zero \u03b1) :=\n{ mul_le_mul_left := with_zero.mul_le_mul_left,\n  lt_of_mul_lt_mul_left := with_zero.lt_of_mul_lt_mul_left,\n  ..with_zero.comm_monoid_with_zero,\n  ..with_zero.partial_order\n}\n\n/-\nNote 1 : the below is not an instance because it requires `zero_le`. It seems\nlike a rather pathological definition because \u03b1 already has a zero.\n\nNote 2 : there is no multiplicative analogue because it does not seem necessary.\nMathematicians might be more likely to use the order-dual version, where all\nelements are \u2264 1 and then 1 is the top element.\n-/\n\n/--\nIf `0` is the least element in `\u03b1`, then `with_zero \u03b1` is an `ordered_add_comm_monoid`.\n-/\ndef ordered_add_comm_monoid [ordered_add_comm_monoid \u03b1]\n  (zero_le : \u2200 a : \u03b1, 0 \u2264 a) : ordered_add_comm_monoid (with_zero \u03b1) :=\nbegin\n  suffices, refine {\n    add_le_add_left := this,\n    ..with_zero.partial_order,\n    ..with_zero.add_comm_monoid, .. },\n  { intros a b c h,\n    have h' := lt_iff_le_not_le.1 h,\n    rw lt_iff_le_not_le at \u22a2,\n    refine \u27e8\u03bb b h\u2082, _, \u03bb h\u2082, h'.2 $ this _ _ h\u2082 _\u27e9,\n    cases h\u2082, cases c with c,\n    { cases h'.2 (this _ _ bot_le a) },\n    { refine \u27e8_, rfl, _\u27e9,\n      cases a with a,\n      { exact with_bot.some_le_some.1 h'.1 },\n      { exact le_of_lt (lt_of_add_lt_add_left $\n          with_bot.some_lt_some.1 h), } } },\n  { intros a b h c ca h\u2082,\n    cases b with b,\n    { rw le_antisymm h bot_le at h\u2082,\n      exact \u27e8_, h\u2082, le_refl _\u27e9 },\n    cases a with a,\n    { change c + 0 = some ca at h\u2082,\n      simp at h\u2082, simp [h\u2082],\n      exact \u27e8_, rfl, by simpa using add_le_add_left (zero_le b) _\u27e9 },\n    { simp at h,\n      cases c with c; change some _ = _ at h\u2082;\n        simp [-add_comm] at h\u2082; subst ca; refine \u27e8_, rfl, _\u27e9,\n      { exact h },\n      { exact add_le_add_left h _ } } }\nend\n\nend with_zero\n\nnamespace with_top\n\nsection has_one\n\nvariables [has_one \u03b1]\n\n@[to_additive] instance : has_one (with_top \u03b1) := \u27e8(1 : \u03b1)\u27e9\n\n@[simp, to_additive] lemma coe_one : ((1 : \u03b1) : with_top \u03b1) = 1 := rfl\n\n@[simp, to_additive] lemma coe_eq_one {a : \u03b1} : (a : with_top \u03b1) = 1 \u2194 a = 1 :=\ncoe_eq_coe\n\n@[simp, to_additive] theorem one_eq_coe {a : \u03b1} : 1 = (a : with_top \u03b1) \u2194 a = 1 :=\nby rw [eq_comm, coe_eq_one]\n\nattribute [norm_cast] coe_one coe_eq_one coe_zero coe_eq_zero one_eq_coe zero_eq_coe\n\n@[simp, to_additive] theorem top_ne_one : \u22a4 \u2260 (1 : with_top \u03b1) .\n@[simp, to_additive] theorem one_ne_top : (1 : with_top \u03b1) \u2260 \u22a4 .\n\nend has_one\n\ninstance [has_add \u03b1] : has_add (with_top \u03b1) :=\n\u27e8\u03bb o\u2081 o\u2082, o\u2081.bind (\u03bb a, o\u2082.map (\u03bb b, a + b))\u27e9\n\nlocal attribute [reducible] with_zero\n\ninstance [add_semigroup \u03b1] : add_semigroup (with_top \u03b1) :=\n{ add := (+),\n  ..(by apply_instance : add_semigroup (additive (with_zero (multiplicative \u03b1)))) }\n\n@[norm_cast] lemma coe_add [has_add \u03b1] {a b : \u03b1} : ((a + b : \u03b1) : with_top \u03b1) = a + b := rfl\n\n@[norm_cast] lemma coe_bit0 [has_add \u03b1] {a : \u03b1} : ((bit0 a : \u03b1) : with_top \u03b1) = bit0 a := rfl\n\n@[norm_cast]\nlemma coe_bit1 [has_add \u03b1] [has_one \u03b1] {a : \u03b1} : ((bit1 a : \u03b1) : with_top \u03b1) = bit1 a := rfl\n\n@[simp] lemma add_top [has_add \u03b1] : \u2200{a : with_top \u03b1}, a + \u22a4 = \u22a4\n| none := rfl\n| (some a) := rfl\n\n@[simp] lemma top_add [has_add \u03b1] {a : with_top \u03b1} : \u22a4 + a = \u22a4 := rfl\n\nlemma add_eq_top [has_add \u03b1] {a b : with_top \u03b1} : a + b = \u22a4 \u2194 a = \u22a4 \u2228 b = \u22a4 :=\nby {cases a; cases b; simp [none_eq_top, some_eq_coe, \u2190with_top.coe_add, \u2190with_zero.coe_add]}\n\nlemma add_lt_top [has_add \u03b1] [partial_order \u03b1] {a b : with_top \u03b1} : a + b < \u22a4 \u2194 a < \u22a4 \u2227 b < \u22a4 :=\nby simp [lt_top_iff_ne_top, add_eq_top, not_or_distrib]\n\nlemma add_eq_coe [has_add \u03b1] : \u2200 {a b : with_top \u03b1} {c : \u03b1},\n  a + b = c \u2194 \u2203 (a' b' : \u03b1), \u2191a' = a \u2227 \u2191b' = b \u2227 a' + b' = c\n| none b c := by simp [none_eq_top]\n| (some a) none c := by simp [none_eq_top]\n| (some a) (some b) c :=\n    by simp only [some_eq_coe, \u2190 coe_add, coe_eq_coe, exists_and_distrib_left, exists_eq_left]\n\ninstance [add_comm_semigroup \u03b1] : add_comm_semigroup (with_top \u03b1) :=\n{ ..@additive.add_comm_semigroup _ $\n    @with_zero.comm_semigroup (multiplicative \u03b1) _ }\n\ninstance [add_monoid \u03b1] : add_monoid (with_top \u03b1) :=\n{ zero := some 0,\n  add := (+),\n  ..@additive.add_monoid _ $ @monoid_with_zero.to_monoid _ $\n    @with_zero.monoid_with_zero (multiplicative \u03b1) _ }\n\ninstance [add_comm_monoid \u03b1] : add_comm_monoid (with_top \u03b1) :=\n{ zero := 0,\n  add := (+),\n  ..@additive.add_comm_monoid _ $ @comm_monoid_with_zero.to_comm_monoid _ $\n    @with_zero.comm_monoid_with_zero (multiplicative \u03b1) _ }\n\ninstance [ordered_add_comm_monoid \u03b1] : ordered_add_comm_monoid (with_top \u03b1) :=\n{ add_le_add_left :=\n    begin\n      rintros a b h (_|c), { simp [none_eq_top] },\n      rcases b with (_|b), { simp [none_eq_top] },\n      rcases le_coe_iff.1 h with \u27e8a, rfl, h\u27e9,\n      simp only [some_eq_coe, \u2190 coe_add, coe_le_coe] at h \u22a2,\n      exact add_le_add_left h c\n    end,\n  lt_of_add_lt_add_left :=\n    begin\n      intros a b c h,\n      rcases lt_iff_exists_coe.1 h with \u27e8ab, hab, hlt\u27e9,\n      rcases add_eq_coe.1 hab with \u27e8a, b, rfl, rfl, rfl\u27e9,\n      rw coe_lt_iff,\n      rintro c rfl,\n      exact lt_of_add_lt_add_left (coe_lt_coe.1 hlt)\n    end,\n  ..with_top.partial_order, ..with_top.add_comm_monoid }\n\ninstance [linear_ordered_add_comm_monoid \u03b1] :\n  linear_ordered_add_comm_monoid_with_top (with_top \u03b1) :=\n{ top_add' := \u03bb x, with_top.top_add,\n  ..with_top.order_top,\n  ..with_top.linear_order,\n  ..with_top.ordered_add_comm_monoid,\n  ..option.nontrivial }\n\n/-- Coercion from `\u03b1` to `with_top \u03b1` as an `add_monoid_hom`. -/\ndef coe_add_hom [add_monoid \u03b1] : \u03b1 \u2192+ with_top \u03b1 :=\n\u27e8coe, rfl, \u03bb _ _, rfl\u27e9\n\n@[simp] lemma coe_coe_add_hom [add_monoid \u03b1] : \u21d1(coe_add_hom : \u03b1 \u2192+ with_top \u03b1) = coe := rfl\n\n@[simp] lemma zero_lt_top [ordered_add_comm_monoid \u03b1] : (0 : with_top \u03b1) < \u22a4 :=\ncoe_lt_top 0\n\n@[simp, norm_cast] lemma zero_lt_coe [ordered_add_comm_monoid \u03b1] (a : \u03b1) :\n  (0 : with_top \u03b1) < a \u2194 0 < a :=\ncoe_lt_coe\n\nend with_top\n\nnamespace with_bot\n\ninstance [has_zero \u03b1] : has_zero (with_bot \u03b1) := with_top.has_zero\ninstance [has_one \u03b1] : has_one (with_bot \u03b1) := with_top.has_one\ninstance [add_semigroup \u03b1] : add_semigroup (with_bot \u03b1) := with_top.add_semigroup\ninstance [add_comm_semigroup \u03b1] : add_comm_semigroup (with_bot \u03b1) := with_top.add_comm_semigroup\ninstance [add_monoid \u03b1] : add_monoid (with_bot \u03b1) := with_top.add_monoid\ninstance [add_comm_monoid \u03b1] : add_comm_monoid (with_bot \u03b1) :=  with_top.add_comm_monoid\n\ninstance [ordered_add_comm_monoid \u03b1] : ordered_add_comm_monoid (with_bot \u03b1) :=\nbegin\n  suffices, refine {\n    add_le_add_left := this,\n    ..with_bot.partial_order,\n    ..with_bot.add_comm_monoid, ..},\n  { intros a b c h,\n    have h' := h,\n    rw lt_iff_le_not_le at h' \u22a2,\n    refine \u27e8\u03bb b h\u2082, _, \u03bb h\u2082, h'.2 $ this _ _ h\u2082 _\u27e9,\n    cases h\u2082, cases a with a,\n    { exact (not_le_of_lt h).elim bot_le },\n    cases c with c,\n    { exact (not_le_of_lt h).elim bot_le },\n    { exact \u27e8_, rfl, le_of_lt (lt_of_add_lt_add_left $\n        with_bot.some_lt_some.1 h)\u27e9 } },\n  { intros a b h c ca h\u2082,\n    cases c with c, {cases h\u2082},\n    cases a with a; cases h\u2082,\n    cases b with b, {cases le_antisymm h bot_le},\n    simp at h,\n    exact \u27e8_, rfl, add_le_add_left h _\u27e9, }\nend\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_zero [has_zero \u03b1] : ((0 : \u03b1) : with_bot \u03b1) = 0 := rfl\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_one [has_one \u03b1] : ((1 : \u03b1) : with_bot \u03b1) = 1 := rfl\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_eq_zero {\u03b1 : Type*}\n  [add_monoid \u03b1] {a : \u03b1} : (a : with_bot \u03b1) = 0 \u2194 a = 0 :=\nby norm_cast\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_add [add_semigroup \u03b1] (a b : \u03b1) : ((a + b : \u03b1) : with_bot \u03b1) = a + b := by norm_cast\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_bit0 [add_semigroup \u03b1] {a : \u03b1} : ((bit0 a : \u03b1) : with_bot \u03b1) = bit0 a :=\nby norm_cast\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_bit1 [add_semigroup \u03b1] [has_one \u03b1] {a : \u03b1} : ((bit1 a : \u03b1) : with_bot \u03b1) = bit1 a :=\nby norm_cast\n\n@[simp] lemma bot_add [ordered_add_comm_monoid \u03b1] (a : with_bot \u03b1) : \u22a5 + a = \u22a5 := rfl\n\n@[simp] lemma add_bot [ordered_add_comm_monoid \u03b1] (a : with_bot \u03b1) : a + \u22a5 = \u22a5 := by cases a; refl\n\nend with_bot\n\n/-- A canonically ordered additive monoid is an ordered commutative additive monoid\n  in which the ordering coincides with the subtractibility relation,\n  which is to say, `a \u2264 b` iff there exists `c` with `b = a + c`.\n  This is satisfied by the natural numbers, for example, but not\n  the integers or other nontrivial `ordered_add_comm_group`s. -/\n@[protect_proj, ancestor ordered_add_comm_monoid order_bot]\nclass canonically_ordered_add_monoid (\u03b1 : Type*) extends ordered_add_comm_monoid \u03b1, order_bot \u03b1 :=\n(le_iff_exists_add : \u2200 a b : \u03b1, a \u2264 b \u2194 \u2203 c, b = a + c)\n\n/-- A canonically ordered monoid is an ordered commutative monoid\n  in which the ordering coincides with the divisibility relation,\n  which is to say, `a \u2264 b` iff there exists `c` with `b = a * c`.\n  Example seem rare; it seems more likely that the `order_dual`\n  of a naturally-occurring lattice satisfies this than the lattice\n  itself (for example, dual of the lattice of ideals of a PID or\n  Dedekind domain satisfy this; collections of all things \u2264 1 seem to\n  be more natural that collections of all things \u2265 1).\n-/\n@[protect_proj, ancestor ordered_comm_monoid order_bot, to_additive]\nclass canonically_ordered_monoid (\u03b1 : Type*) extends ordered_comm_monoid \u03b1, order_bot \u03b1 :=\n(le_iff_exists_mul : \u2200 a b : \u03b1, a \u2264 b \u2194 \u2203 c, b = a * c)\n\nsection canonically_ordered_monoid\n\nvariables [canonically_ordered_monoid \u03b1] {a b c d : \u03b1}\n\n@[to_additive]\nlemma le_iff_exists_mul : a \u2264 b \u2194 \u2203c, b = a * c :=\ncanonically_ordered_monoid.le_iff_exists_mul a b\n\n@[to_additive]\nlemma self_le_mul_right (a b : \u03b1) : a \u2264 a * b :=\nle_iff_exists_mul.mpr \u27e8b, rfl\u27e9\n\n@[to_additive]\nlemma self_le_mul_left (a b : \u03b1) : a \u2264 b * a :=\nby { rw [mul_comm], exact self_le_mul_right a b }\n\n@[simp, to_additive zero_le] lemma one_le (a : \u03b1) : 1 \u2264 a := le_iff_exists_mul.mpr \u27e8a, by simp\u27e9\n\n@[simp, to_additive] lemma bot_eq_one : (\u22a5 : \u03b1) = 1 :=\nle_antisymm bot_le (one_le \u22a5)\n\n@[simp, to_additive] lemma mul_eq_one_iff : a * b = 1 \u2194 a = 1 \u2227 b = 1 :=\nmul_eq_one_iff' (one_le _) (one_le _)\n\n@[simp, to_additive] lemma le_one_iff_eq_one : a \u2264 1 \u2194 a = 1 :=\niff.intro\n  (assume h, le_antisymm h (one_le a))\n  (assume h, h \u25b8 le_refl a)\n\n@[to_additive] lemma one_lt_iff_ne_one : 1 < a \u2194 a \u2260 1 :=\niff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (one_le _) hne.symm\n\n@[to_additive] lemma exists_pos_mul_of_lt (h : a < b) : \u2203 c > 1, a * c = b :=\nbegin\n  obtain \u27e8c, hc\u27e9 := le_iff_exists_mul.1 h.le,\n  refine \u27e8c, one_lt_iff_ne_one.2 _, hc.symm\u27e9,\n  rintro rfl,\n  simpa [hc, lt_irrefl] using h\nend\n\n@[to_additive] lemma le_mul_left (h : a \u2264 c) : a \u2264 b * c :=\ncalc a = 1 * a : by simp\n  ... \u2264 b * c : mul_le_mul' (one_le _) h\n\n@[to_additive] lemma le_mul_right (h : a \u2264 b) : a \u2264 b * c :=\ncalc a = a * 1 : by simp\n  ... \u2264 b * c : mul_le_mul' h (one_le _)\n\nlocal attribute [semireducible] with_zero\n\n-- This instance looks absurd: a monoid already has a zero\n/-- Adding a new zero to a canonically ordered additive monoid produces another one. -/\ninstance with_zero.canonically_ordered_add_monoid {\u03b1 : Type u} [canonically_ordered_add_monoid \u03b1] :\n  canonically_ordered_add_monoid (with_zero \u03b1) :=\n{ le_iff_exists_add := \u03bb a b, begin\n    cases a with a,\n    { exact iff_of_true bot_le \u27e8b, (zero_add b).symm\u27e9 },\n    cases b with b,\n    { exact iff_of_false\n        (mt (le_antisymm bot_le) (by simp))\n        (\u03bb \u27e8c, h\u27e9, by cases c; cases h) },\n    { simp [le_iff_exists_add, -add_comm],\n      split; intro h; rcases h with \u27e8c, h\u27e9,\n      { exact \u27e8some c, congr_arg some h\u27e9 },\n      { cases c; cases h,\n        { exact \u27e8_, (add_zero _).symm\u27e9 },\n        { exact \u27e8_, rfl\u27e9 } } }\n  end,\n  bot    := 0,\n  bot_le := assume a a' h, option.no_confusion h,\n  .. with_zero.ordered_add_comm_monoid zero_le }\n\ninstance with_top.canonically_ordered_add_monoid {\u03b1 : Type u} [canonically_ordered_add_monoid \u03b1] :\n  canonically_ordered_add_monoid (with_top \u03b1) :=\n{ le_iff_exists_add := assume a b,\n  match a, b with\n  | a, none     := show a \u2264 \u22a4 \u2194 \u2203c, \u22a4 = a + c, by simp; refine \u27e8\u22a4, _\u27e9; cases a; refl\n  | (some a), (some b) := show (a:with_top \u03b1) \u2264 \u2191b \u2194 \u2203c:with_top \u03b1, \u2191b = \u2191a + c,\n    begin\n      simp [canonically_ordered_add_monoid.le_iff_exists_add, -add_comm],\n      split,\n      { rintro \u27e8c, rfl\u27e9, refine \u27e8c, _\u27e9, norm_cast },\n      { exact assume h, match b, h with _, \u27e8some c, rfl\u27e9 := \u27e8_, rfl\u27e9 end }\n    end\n  | none, some b := show (\u22a4 : with_top \u03b1) \u2264 b \u2194 \u2203c:with_top \u03b1, \u2191b = \u22a4 + c, by simp\n  end,\n  .. with_top.order_bot,\n  .. with_top.ordered_add_comm_monoid }\n\n@[priority 100, to_additive]\ninstance canonically_ordered_monoid.has_exists_mul_of_le (\u03b1 : Type u)\n  [canonically_ordered_monoid \u03b1] : has_exists_mul_of_le \u03b1 :=\n{ exists_mul_of_le := \u03bb a b hab, le_iff_exists_mul.mp hab }\n\nend canonically_ordered_monoid\n\nlemma pos_of_gt {M : Type*} [canonically_ordered_add_monoid M] {n m : M} (h : n < m) : 0 < m :=\nlt_of_le_of_lt (zero_le _) h\n\n/-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid\n    whose ordering is a linear order. -/\n@[protect_proj, ancestor canonically_ordered_add_monoid linear_order]\nclass canonically_linear_ordered_add_monoid (\u03b1 : Type*)\n      extends canonically_ordered_add_monoid \u03b1, linear_order \u03b1\n\n/-- A canonically linear-ordered monoid is a canonically ordered monoid\n    whose ordering is a linear order. -/\n@[protect_proj, ancestor canonically_ordered_monoid linear_order, to_additive]\nclass canonically_linear_ordered_monoid (\u03b1 : Type*)\n      extends canonically_ordered_monoid \u03b1, linear_order \u03b1\n\nsection canonically_linear_ordered_monoid\nvariables\n\n@[priority 100, to_additive]  -- see Note [lower instance priority]\ninstance canonically_linear_ordered_monoid.semilattice_sup_bot\n  [canonically_linear_ordered_monoid \u03b1] : semilattice_sup_bot \u03b1 :=\n{ ..lattice_of_linear_order, ..canonically_ordered_monoid.to_order_bot \u03b1 }\n\ninstance with_top.canonically_linear_ordered_add_monoid\n  (\u03b1 : Type*) [canonically_linear_ordered_add_monoid \u03b1] :\n    canonically_linear_ordered_add_monoid (with_top \u03b1) :=\n{ .. (infer_instance : canonically_ordered_add_monoid (with_top \u03b1)),\n  .. (infer_instance : linear_order (with_top \u03b1)) }\n\n@[to_additive] lemma min_mul_distrib [canonically_linear_ordered_monoid \u03b1] (a b c : \u03b1) :\n  min a (b * c) = min a (min a b * min a c) :=\nbegin\n  cases le_total a b with hb hb,\n  { simp [hb, le_mul_right] },\n  { cases le_total a c with hc hc,\n    { simp [hc, le_mul_left] },\n    { simp [hb, hc] } }\nend\n\n@[to_additive] lemma min_mul_distrib' [canonically_linear_ordered_monoid \u03b1] (a b c : \u03b1) :\n  min (a * b) c = min (min a c * min b c) c :=\nby simpa [min_comm _ c] using min_mul_distrib c a b\n\nend canonically_linear_ordered_monoid\n\n/-- An ordered cancellative additive commutative monoid\nis an additive commutative monoid with a partial order,\nin which addition is cancellative and monotone. -/\n@[protect_proj, ancestor add_cancel_comm_monoid partial_order]\nclass ordered_cancel_add_comm_monoid (\u03b1 : Type u)\n      extends add_cancel_comm_monoid \u03b1, partial_order \u03b1 :=\n(add_le_add_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n(le_of_add_le_add_left : \u2200 a b c : \u03b1, a + b \u2264 a + c \u2192 b \u2264 c)\n\n/-- An ordered cancellative commutative monoid\nis a commutative monoid with a partial order,\nin which multiplication is cancellative and monotone. -/\n@[protect_proj, ancestor cancel_comm_monoid partial_order, to_additive]\nclass ordered_cancel_comm_monoid (\u03b1 : Type u)\n      extends cancel_comm_monoid \u03b1, partial_order \u03b1 :=\n(mul_le_mul_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\n(le_of_mul_le_mul_left : \u2200 a b c : \u03b1, a * b \u2264 a * c \u2192 b \u2264 c)\n\nsection ordered_cancel_comm_monoid\nvariables [ordered_cancel_comm_monoid \u03b1] {a b c d : \u03b1}\n\n@[to_additive le_of_add_le_add_left]\nlemma le_of_mul_le_mul_left' : \u2200 {a b c : \u03b1}, a * b \u2264 a * c \u2192 b \u2264 c :=\nordered_cancel_comm_monoid.le_of_mul_le_mul_left\n\n@[priority 100, to_additive]    -- see Note [lower instance priority]\ninstance ordered_cancel_comm_monoid.to_ordered_comm_monoid : ordered_comm_monoid \u03b1 :=\n{ lt_of_mul_lt_mul_left := \u03bb a b c h, lt_of_le_not_le (le_of_mul_le_mul_left' h.le) $\n      mt (\u03bb h, ordered_cancel_comm_monoid.mul_le_mul_left _ _ h _) (not_le_of_gt h),\n  ..\u2039ordered_cancel_comm_monoid \u03b1\u203a }\n\n@[to_additive add_lt_add_left]\nlemma mul_lt_mul_left' (h : a < b) (c : \u03b1) : c * a < c * b :=\nlt_of_le_not_le (mul_le_mul_left' h.le _) $\n  mt le_of_mul_le_mul_left' (not_le_of_gt h)\n\n@[to_additive add_lt_add_right]\nlemma mul_lt_mul_right' (h : a < b) (c : \u03b1) : a * c < b * c :=\nbegin\n rw [mul_comm a c, mul_comm b c],\n exact (mul_lt_mul_left' h c)\nend\n\n@[to_additive add_lt_add]\nlemma mul_lt_mul''' (h\u2081 : a < b) (h\u2082 : c < d) : a * c < b * d :=\nlt_trans (mul_lt_mul_right' h\u2081 c) (mul_lt_mul_left' h\u2082 b)\n\n@[to_additive]\nlemma mul_lt_mul_of_le_of_lt (h\u2081 : a \u2264 b) (h\u2082 : c < d) : a * c < b * d :=\nlt_of_le_of_lt (mul_le_mul_right' h\u2081 _) (mul_lt_mul_left' h\u2082 b)\n\n@[to_additive]\nlemma mul_lt_mul_of_lt_of_le (h\u2081 : a < b) (h\u2082 : c \u2264 d) : a * c < b * d :=\nlt_of_lt_of_le (mul_lt_mul_right' h\u2081 c) (mul_le_mul_left' h\u2082 _)\n\n@[to_additive lt_add_of_pos_right]\nlemma lt_mul_of_one_lt_right' (a : \u03b1) {b : \u03b1} (h : 1 < b) : a < a * b :=\nhave a * 1 < a * b, from mul_lt_mul_left' h a,\nby rwa [mul_one] at this\n\n@[to_additive lt_add_of_pos_left]\nlemma lt_mul_of_one_lt_left' (a : \u03b1) {b : \u03b1} (h : 1 < b) : a < b * a :=\nhave 1 * a < b * a, from mul_lt_mul_right' h a,\nby rwa [one_mul] at this\n\n@[to_additive le_of_add_le_add_right]\nlemma le_of_mul_le_mul_right' (h : a * b \u2264 c * b) : a \u2264 c :=\nle_of_mul_le_mul_left'\n  (show b * a \u2264 b * c, begin rw [mul_comm b a, mul_comm b c], assumption end)\n\n@[to_additive]\nlemma mul_lt_one (ha : a < 1) (hb : b < 1) : a * b < 1 :=\none_mul (1:\u03b1) \u25b8 (mul_lt_mul''' ha hb)\n\n@[to_additive]\nlemma mul_lt_one_of_lt_one_of_le_one (ha : a < 1) (hb : b \u2264 1) : a * b < 1 :=\none_mul (1:\u03b1) \u25b8 (mul_lt_mul_of_lt_of_le ha hb)\n\n@[to_additive]\nlemma mul_lt_one_of_le_one_of_lt_one (ha : a \u2264 1) (hb : b < 1) : a * b < 1 :=\none_mul (1:\u03b1) \u25b8 (mul_lt_mul_of_le_of_lt ha hb)\n\n@[to_additive]\nlemma lt_mul_of_one_lt_of_le (ha : 1 < a) (hbc : b \u2264 c) : b < a * c :=\none_mul b \u25b8 mul_lt_mul_of_lt_of_le ha hbc\n\n@[to_additive]\nlemma lt_mul_of_le_of_one_lt (hbc : b \u2264 c) (ha : 1 < a) : b < c * a :=\nmul_one b \u25b8 mul_lt_mul_of_le_of_lt hbc ha\n\n@[to_additive]\nlemma mul_le_of_le_one_of_le (ha : a \u2264 1) (hbc : b \u2264 c) : a * b \u2264 c :=\none_mul c \u25b8 mul_le_mul' ha hbc\n\n@[to_additive]\nlemma mul_le_of_le_of_le_one (hbc : b \u2264 c) (ha : a \u2264 1) : b * a \u2264 c :=\nmul_one c \u25b8 mul_le_mul' hbc ha\n\n@[to_additive]\nlemma mul_lt_of_lt_one_of_le (ha : a < 1) (hbc : b \u2264 c) : a * b < c :=\none_mul c \u25b8 mul_lt_mul_of_lt_of_le ha hbc\n\n@[to_additive]\nlemma mul_lt_of_le_of_lt_one (hbc : b \u2264 c) (ha : a < 1) : b * a < c :=\nmul_one c \u25b8 mul_lt_mul_of_le_of_lt hbc ha\n\n@[to_additive]\nlemma lt_mul_of_one_le_of_lt (ha : 1 \u2264 a) (hbc : b < c) : b < a * c :=\none_mul b \u25b8 mul_lt_mul_of_le_of_lt ha hbc\n\n@[to_additive]\nlemma lt_mul_of_lt_of_one_le (hbc : b < c) (ha : 1 \u2264 a) : b < c * a :=\nmul_one b \u25b8 mul_lt_mul_of_lt_of_le hbc ha\n\n@[to_additive]\nlemma lt_mul_of_one_lt_of_lt (ha : 1 < a) (hbc : b < c) : b < a * c :=\none_mul b \u25b8 mul_lt_mul''' ha hbc\n\n@[to_additive]\nlemma lt_mul_of_lt_of_one_lt (hbc : b < c) (ha : 1 < a) : b < c * a :=\nmul_one b \u25b8 mul_lt_mul''' hbc ha\n\n@[to_additive]\nlemma mul_lt_of_le_one_of_lt (ha : a \u2264 1) (hbc : b < c) : a * b < c :=\none_mul c \u25b8 mul_lt_mul_of_le_of_lt ha hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_of_le_one (hbc : b < c) (ha : a \u2264 1)  : b * a < c :=\nmul_one c \u25b8 mul_lt_mul_of_lt_of_le hbc ha\n\n@[to_additive]\nlemma mul_lt_of_lt_one_of_lt (ha : a < 1) (hbc : b < c) : a * b < c :=\none_mul c \u25b8 mul_lt_mul''' ha hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_of_lt_one (hbc : b < c) (ha : a < 1) : b * a < c :=\nmul_one c \u25b8 mul_lt_mul''' hbc ha\n\n@[simp, to_additive]\nlemma mul_le_mul_iff_left (a : \u03b1) {b c : \u03b1} : a * b \u2264 a * c \u2194 b \u2264 c :=\n\u27e8le_of_mul_le_mul_left', \u03bb h, mul_le_mul_left' h _\u27e9\n\n@[simp, to_additive]\nlemma mul_le_mul_iff_right (c : \u03b1) : a * c \u2264 b * c \u2194 a \u2264 b :=\nmul_comm c a \u25b8 mul_comm c b \u25b8 mul_le_mul_iff_left c\n\n@[simp, to_additive]\nlemma mul_lt_mul_iff_left (a : \u03b1) {b c : \u03b1} : a * b < a * c \u2194 b < c :=\n\u27e8lt_of_mul_lt_mul_left', \u03bb h, mul_lt_mul_left' h _\u27e9\n\n@[simp, to_additive]\nlemma mul_lt_mul_iff_right (c : \u03b1) : a * c < b * c \u2194 a < b :=\nmul_comm c a \u25b8 mul_comm c b \u25b8 mul_lt_mul_iff_left c\n\n@[simp, to_additive le_add_iff_nonneg_right]\nlemma le_mul_iff_one_le_right' (a : \u03b1) {b : \u03b1} : a \u2264 a * b \u2194 1 \u2264 b :=\nhave a * 1 \u2264 a * b \u2194 1 \u2264 b, from mul_le_mul_iff_left a,\nby rwa mul_one at this\n\n@[simp, to_additive le_add_iff_nonneg_left]\nlemma le_mul_iff_one_le_left' (a : \u03b1) {b : \u03b1} : a \u2264 b * a \u2194 1 \u2264 b :=\nby rw [mul_comm, le_mul_iff_one_le_right']\n\n@[simp, to_additive lt_add_iff_pos_right]\nlemma lt_mul_iff_one_lt_right' (a : \u03b1) {b : \u03b1} : a < a * b \u2194 1 < b :=\nhave a * 1 < a * b \u2194 1 < b, from mul_lt_mul_iff_left a,\nby rwa mul_one at this\n\n@[simp, to_additive lt_add_iff_pos_left]\nlemma lt_mul_iff_one_lt_left' (a : \u03b1) {b : \u03b1} : a < b * a \u2194 1 < b :=\nby rw [mul_comm, lt_mul_iff_one_lt_right']\n\n@[simp, to_additive add_le_iff_nonpos_left]\nlemma mul_le_iff_le_one_left' : a * b \u2264 b \u2194 a \u2264 1 :=\nby { convert mul_le_mul_iff_right b, rw [one_mul] }\n\n@[simp, to_additive add_le_iff_nonpos_right]\nlemma mul_le_iff_le_one_right' : a * b \u2264 a \u2194 b \u2264 1 :=\nby { convert mul_le_mul_iff_left a, rw [mul_one] }\n\n@[simp, to_additive add_lt_iff_neg_right]\nlemma mul_lt_iff_lt_one_right' : a * b < b \u2194 a < 1 :=\nby { convert mul_lt_mul_iff_right b, rw [one_mul] }\n\n@[simp, to_additive add_lt_iff_neg_left]\nlemma mul_lt_iff_lt_one_left' : a * b < a \u2194 b < 1 :=\nby { convert mul_lt_mul_iff_left a, rw [mul_one] }\n\n@[to_additive]\nlemma mul_eq_one_iff_eq_one_of_one_le\n  (ha : 1 \u2264 a) (hb : 1 \u2264 b) : a * b = 1 \u2194 a = 1 \u2227 b = 1 :=\n\u27e8\u03bb hab : a * b = 1,\nby split; apply le_antisymm; try {assumption};\n   rw \u2190 hab; simp [ha, hb],\n\u03bb \u27e8ha', hb'\u27e9, by rw [ha', hb', mul_one]\u27e9\n\n/-- Pullback an `ordered_cancel_comm_monoid` under an injective map. -/\n@[to_additive function.injective.ordered_cancel_add_comm_monoid\n\"Pullback an `ordered_cancel_add_comm_monoid` under an injective map.\"]\ndef function.injective.ordered_cancel_comm_monoid {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_cancel_comm_monoid \u03b2 :=\n{ le_of_mul_le_mul_left := \u03bb a b c (ab : f (a * b) \u2264 f (a * c)),\n    (by { rw [mul, mul] at ab, exact le_of_mul_le_mul_left' ab }),\n  ..hf.left_cancel_semigroup f mul,\n  ..hf.ordered_comm_monoid f one mul }\n\nsection mono\n\nvariables {\u03b2 : Type*} [preorder \u03b2] {f g : \u03b2 \u2192 \u03b1}\n\n@[to_additive monotone.add_strict_mono]\nlemma monotone.mul_strict_mono' (hf : monotone f) (hg : strict_mono g) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul_of_le_of_lt (hf $ le_of_lt h) (hg h)\n\n@[to_additive strict_mono.add_monotone]\nlemma strict_mono.mul_monotone' (hf : strict_mono f) (hg : monotone g) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul_of_lt_of_le (hf h) (hg $ le_of_lt h)\n\n@[to_additive strict_mono.add_const]\nlemma strict_mono.mul_const' (hf : strict_mono f) (c : \u03b1) :\n  strict_mono (\u03bb x, f x * c) :=\nhf.mul_monotone' monotone_const\n\n@[to_additive strict_mono.const_add]\nlemma strict_mono.const_mul' (hf : strict_mono f) (c : \u03b1) :\n  strict_mono (\u03bb x, c * f x) :=\nmonotone_const.mul_strict_mono' hf\n\nend mono\n\nend ordered_cancel_comm_monoid\n\nsection ordered_cancel_add_comm_monoid\n\nvariable [ordered_cancel_add_comm_monoid \u03b1]\n\nlemma with_top.add_lt_add_iff_left :\n  \u2200{a b c : with_top \u03b1}, a < \u22a4 \u2192 (a + c < a + b \u2194 c < b)\n| none := assume b c h, (lt_irrefl \u22a4 h).elim\n| (some a) :=\n  begin\n    assume b c h,\n    cases b; cases c;\n      simp [with_top.none_eq_top, with_top.some_eq_coe, with_top.coe_lt_top, with_top.coe_lt_coe],\n    { norm_cast, exact with_top.coe_lt_top _ },\n    { norm_cast, exact add_lt_add_iff_left _ }\n  end\n\nlemma with_bot.add_lt_add_iff_left :\n  \u2200{a b c : with_bot \u03b1}, \u22a5 < a \u2192 (a + c < a + b \u2194 c < b)\n| none := assume b c h, (lt_irrefl \u22a5 h).elim\n| (some a) :=\n  begin\n    assume b c h,\n    cases b; cases c;\n      simp [with_bot.none_eq_bot, with_bot.some_eq_coe, with_bot.bot_lt_coe, with_bot.coe_lt_coe],\n    { norm_cast, exact with_bot.bot_lt_coe _ },\n    { norm_cast, exact add_lt_add_iff_left _ }\n  end\n\nlocal attribute [reducible] with_zero\n\nlemma with_top.add_lt_add_iff_right\n  {a b c : with_top \u03b1} : a < \u22a4 \u2192 (c + a < b + a \u2194 c < b) :=\nby simpa [add_comm] using @with_top.add_lt_add_iff_left _ _ a b c\n\nlemma with_bot.add_lt_add_iff_right\n  {a b c : with_bot \u03b1} : \u22a5 < a \u2192 (c + a < b + a \u2194 c < b) :=\nby simpa [add_comm] using @with_bot.add_lt_add_iff_left _ _ a b c\n\nend ordered_cancel_add_comm_monoid\n\n/-! Some lemmas about types that have an ordering and a binary operation, with no\n  rules relating them. -/\n@[to_additive]\nlemma fn_min_mul_fn_max {\u03b2} [linear_order \u03b1] [comm_semigroup \u03b2] (f : \u03b1 \u2192 \u03b2) (n m : \u03b1) :\n  f (min n m) * f (max n m) = f n * f m :=\nby { cases le_total n m with h h; simp [h, mul_comm] }\n\n@[to_additive]\nlemma min_mul_max [linear_order \u03b1] [comm_semigroup \u03b1] (n m : \u03b1) :\n  min n m * max n m = n * m :=\nfn_min_mul_fn_max id n m\n\n/-- A linearly ordered cancellative additive commutative monoid\nis an additive commutative monoid with a decidable linear order\nin which addition is cancellative and monotone. -/\n@[protect_proj, ancestor ordered_cancel_add_comm_monoid linear_ordered_add_comm_monoid]\nclass linear_ordered_cancel_add_comm_monoid (\u03b1 : Type u)\n  extends ordered_cancel_add_comm_monoid \u03b1, linear_ordered_add_comm_monoid \u03b1\n\n/-- A linearly ordered cancellative commutative monoid\nis a commutative monoid with a linear order\nin which multiplication is cancellative and monotone. -/\n@[protect_proj, ancestor ordered_cancel_comm_monoid linear_ordered_comm_monoid, to_additive]\nclass linear_ordered_cancel_comm_monoid (\u03b1 : Type u)\n  extends ordered_cancel_comm_monoid \u03b1, linear_ordered_comm_monoid \u03b1\n\nsection linear_ordered_cancel_comm_monoid\n\nvariables [linear_ordered_cancel_comm_monoid \u03b1]\n\n@[to_additive] lemma min_mul_mul_left (a b c : \u03b1) : min (a * b) (a * c) = a * min b c :=\n(monotone_id.const_mul' a).map_min.symm\n\n@[to_additive]\nlemma min_mul_mul_right (a b c : \u03b1) : min (a * c) (b * c) = min a b * c :=\n(monotone_id.mul_const' c).map_min.symm\n\n@[to_additive]\nlemma max_mul_mul_left (a b c : \u03b1) : max (a * b) (a * c) = a * max b c :=\n(monotone_id.const_mul' a).map_max.symm\n\n@[to_additive]\nlemma max_mul_mul_right (a b c : \u03b1) : max (a * c) (b * c) = max a b * c :=\n(monotone_id.mul_const' c).map_max.symm\n\n@[to_additive]\nlemma min_le_mul_of_one_le_right {a b : \u03b1} (hb : 1 \u2264 b) : min a b \u2264 a * b :=\nmin_le_iff.2 $ or.inl $ le_mul_of_one_le_right' hb\n\n@[to_additive]\nlemma min_le_mul_of_one_le_left {a b : \u03b1} (ha : 1 \u2264 a) : min a b \u2264 a * b :=\nmin_le_iff.2 $ or.inr $ le_mul_of_one_le_left' ha\n\n@[to_additive]\nlemma max_le_mul_of_one_le {a b : \u03b1} (ha : 1 \u2264 a) (hb : 1 \u2264 b) : max a b \u2264 a * b :=\nmax_le_iff.2 \u27e8le_mul_of_one_le_right' hb, le_mul_of_one_le_left' ha\u27e9\n\n/-- Pullback a `linear_ordered_cancel_comm_monoid` under an injective map. -/\n@[to_additive function.injective.linear_ordered_cancel_add_comm_monoid\n\"Pullback a `linear_ordered_cancel_add_comm_monoid` under an injective map.\"]\ndef function.injective.linear_ordered_cancel_comm_monoid {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  linear_ordered_cancel_comm_monoid \u03b2 :=\n{ ..hf.linear_ordered_comm_monoid f one mul,\n  ..hf.ordered_cancel_comm_monoid f one mul }\n\nend linear_ordered_cancel_comm_monoid\n\nnamespace order_dual\n\n@[to_additive]\ninstance [ordered_comm_monoid \u03b1] : ordered_comm_monoid (order_dual \u03b1) :=\n{ mul_le_mul_left := \u03bb a b h c, @mul_le_mul_left' \u03b1 _ b a h _,\n  lt_of_mul_lt_mul_left := \u03bb a b c h, @lt_of_mul_lt_mul_left' \u03b1 _ a c b h,\n  ..order_dual.partial_order \u03b1,\n  ..show comm_monoid \u03b1, by apply_instance }\n\n\n@[to_additive]\ninstance [ordered_cancel_comm_monoid \u03b1] : ordered_cancel_comm_monoid (order_dual \u03b1) :=\n{ le_of_mul_le_mul_left := \u03bb a b c : \u03b1, le_of_mul_le_mul_left',\n  mul_left_cancel := @mul_left_cancel \u03b1 _,\n  ..order_dual.ordered_comm_monoid }\n\n@[to_additive]\ninstance [linear_ordered_cancel_comm_monoid \u03b1] :\n  linear_ordered_cancel_comm_monoid (order_dual \u03b1) :=\n{ .. order_dual.linear_order \u03b1,\n  .. order_dual.ordered_cancel_comm_monoid }\n\nend order_dual\n\nnamespace prod\n\nvariables {M N : Type*}\n\n@[to_additive]\ninstance [ordered_cancel_comm_monoid M] [ordered_cancel_comm_monoid N] :\n  ordered_cancel_comm_monoid (M \u00d7 N) :=\n{ mul_le_mul_left := \u03bb a b h c, \u27e8mul_le_mul_left' h.1 _, mul_le_mul_left' h.2 _\u27e9,\n  le_of_mul_le_mul_left := \u03bb a b c h, \u27e8le_of_mul_le_mul_left' h.1, le_of_mul_le_mul_left' h.2\u27e9,\n .. prod.cancel_comm_monoid, .. prod.partial_order M N }\n\nend prod\n\nsection type_tags\n\ninstance : \u03a0 [preorder \u03b1], preorder (multiplicative \u03b1) := id\ninstance : \u03a0 [preorder \u03b1], preorder (additive \u03b1) := id\ninstance : \u03a0 [partial_order \u03b1], partial_order (multiplicative \u03b1) := id\ninstance : \u03a0 [partial_order \u03b1], partial_order (additive \u03b1) := id\ninstance : \u03a0 [linear_order \u03b1], linear_order (multiplicative \u03b1) := id\ninstance : \u03a0 [linear_order \u03b1], linear_order (additive \u03b1) := id\n\ninstance [ordered_add_comm_monoid \u03b1] : ordered_comm_monoid (multiplicative \u03b1) :=\n{ mul_le_mul_left := @ordered_add_comm_monoid.add_le_add_left \u03b1 _,\n  lt_of_mul_lt_mul_left := @ordered_add_comm_monoid.lt_of_add_lt_add_left \u03b1 _,\n  ..multiplicative.partial_order,\n  ..multiplicative.comm_monoid }\n\ninstance [ordered_comm_monoid \u03b1] : ordered_add_comm_monoid (additive \u03b1) :=\n{ add_le_add_left := @ordered_comm_monoid.mul_le_mul_left \u03b1 _,\n  lt_of_add_lt_add_left := @ordered_comm_monoid.lt_of_mul_lt_mul_left \u03b1 _,\n  ..additive.partial_order,\n  ..additive.add_comm_monoid }\n\ninstance [ordered_cancel_add_comm_monoid \u03b1] : ordered_cancel_comm_monoid (multiplicative \u03b1) :=\n{ le_of_mul_le_mul_left := @ordered_cancel_add_comm_monoid.le_of_add_le_add_left \u03b1 _,\n  ..multiplicative.left_cancel_semigroup,\n  ..multiplicative.ordered_comm_monoid }\n\ninstance [ordered_cancel_comm_monoid \u03b1] : ordered_cancel_add_comm_monoid (additive \u03b1) :=\n{ le_of_add_le_add_left := @ordered_cancel_comm_monoid.le_of_mul_le_mul_left \u03b1 _,\n  ..additive.add_left_cancel_semigroup,\n  ..additive.ordered_add_comm_monoid }\n\ninstance [linear_ordered_add_comm_monoid \u03b1] : linear_ordered_comm_monoid (multiplicative \u03b1) :=\n{ ..multiplicative.linear_order,\n  ..multiplicative.ordered_comm_monoid }\n\ninstance [linear_ordered_comm_monoid \u03b1] : linear_ordered_add_comm_monoid (additive \u03b1) :=\n{ ..additive.linear_order,\n  ..additive.ordered_add_comm_monoid }\n\nend type_tags\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/ordered_monoid.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7368881502244208}}
{"text": "-- 1\nsection\n\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := \n \u27e8fun h => \u27e8fun x => (h x).left, fun x => (h x).right\u27e9, \n  fun h => fun x => \u27e8h.left x, h.right x\u27e9\u27e9\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := \n fun h => fun h\u2081 => fun x => (h x) (h\u2081 x)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := \n fun h => fun x => h.elim (fun h\u2081 => Or.inl (h\u2081 x)) (fun h\u2081 => Or.inr (h\u2081 x))\n\nend\n\n-- 2\nsection\n\nopen Classical\n\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable (r : Prop)\n\nexample : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) := \n  fun x => \u27e8fun h => h x, fun h => fun y => h\u27e9\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r := \n  \u27e8fun h => ((em r).elim (fun h\u2081 => Or.inr h\u2081) (fun h\u2081 => \n    have h\u2082 : \u2200 x, p x := fun x => (h x).elim id (fun h\u2084 => absurd h\u2084 h\u2081) \n    Or.inl h\u2082)), \n   fun h => fun x => h.elim (fun h\u2081 => Or.inl (h\u2081 x)) (fun hr => Or.inr hr)\u27e9\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) := \n  \u27e8fun h => fun hr => fun x => h x hr, fun h => fun x => fun hr => h hr x\u27e9\n\nend\n\n-- 3\nsection\n\nvariable (men : Type) (barber : men)\nvariable  (shaves : men \u2192 men \u2192 Prop)\n\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : False := \n  have h\u2081 : shaves barber barber \u2194 \u00ac shaves barber barber := h barber\n  have h\u2082 : \u00ac shaves barber barber := fun h\u2083 => h\u2081.mp h\u2083 h\u2083\n  h\u2082 (h\u2081.mpr h\u2082)\n\nend\n\n-- 4\nsection\n\ndef even (n : Nat) : Prop := \u2203 m, n = 2 * m\n\ndef prime (n : Nat) : Prop := \u2200 m, (\u2203 x, n = m * x) \u2192 m = 1 \u2228 m = n\n\ndef infinitely_many_primes : Prop := \u2200 N, \u2203 p, p > N \u2227 prime p\n\ndef Fermat_prime (n : Nat) : Prop := prime n \u2227 \u2203 m : Nat, n = 2 ^ (2 ^ m) + 1\n\ndef infinitely_many_Fermat_primes : Prop := \u2200 N, \u2203 p, p > N \u2227 Fermat_prime p\n\ndef goldbach_conjecture : Prop := \n  \u2200 n, (n > 2) \u2192 (even n) \u2192 \u2203 x y, prime x \u2227 prime y \u2227 n = x + y \n\ndef Goldbach's_weak_conjecture : Prop := \n  \u2200 n, (n > 5) \u2192 (\u00aceven n) \u2192 \u2203 x y z, prime x \u2227 prime y \u2227 prime z \u2227 n = x + y + z\n\ndef Fermat's_last_theorem : Prop :=\n  \u2200 a b c n : Nat, n > 2 \u2192 \u00ac(a ^ n + b ^ n = c ^ n)\n\nend\n\n-- 5\nsection \n\nopen Classical\n\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable (r : Prop)\n\nexample : (\u2203 x : \u03b1, r) \u2192 r := \n  fun \u27e8x, hr\u27e9 => hr\n\nexample (a : \u03b1) : r \u2192 (\u2203 x : \u03b1, r) := \n  fun hr => \u27e8a, hr\u27e9\n\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := \n  \u27e8fun \u27e8x, hp, hr\u27e9 => \u27e8\u27e8x, hp\u27e9, hr\u27e9, fun \u27e8\u27e8x, hp\u27e9, hr\u27e9 => \u27e8x, hp, hr\u27e9\u27e9\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := \n  \u27e8fun \u27e8x, h\u27e9 => h.elim (fun hp => Or.inl \u27e8x, hp\u27e9) (fun hq => Or.inr \u27e8x, hq\u27e9), \n   fun h => h.elim (fun \u27e8x, hp\u27e9 => \u27e8x, Or.inl hp\u27e9) (fun \u27e8x, hq\u27e9 => \u27e8x, Or.inr hq\u27e9)\u27e9\n\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := \n  \u27e8fun h\u2081 => fun h\u2082 => let \u27e8x, hp\u27e9 := h\u2082; hp (h\u2081 x), \n   fun h\u2081 => fun x => byContradiction fun h\u2082 => h\u2081 \u27e8x, h\u2082\u27e9\u27e9\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := \n  \u27e8fun \u27e8x, h\u2081\u27e9 => fun h\u2082 => absurd h\u2081 (h\u2082 x), \n   fun h\u2081 => byContradiction fun h\u2082 => \n   have h\u2083 : \u2200 (x : \u03b1), \u00acp x := fun x => fun h\u2084 => h\u2082 \u27e8x, h\u2084\u27e9; h\u2081 h\u2083\u27e9\n\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) := \n  \u27e8fun h\u2081 => fun x => fun h\u2082 => h\u2081 \u27e8x, h\u2082\u27e9, fun h\u2081 => fun h\u2082 => \n    let \u27e8x, h\u2083\u27e9 := h\u2082; h\u2081 x h\u2083\u27e9\n\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := \n  \u27e8fun h\u2081 => byContradiction fun h\u2082 => \n    have h\u2083 : \u2200 x, p x := fun x => byContradiction fun h\u2084 => h\u2082 \u27e8x, h\u2084\u27e9; h\u2081 h\u2083, \n  fun h\u2081 => fun h\u2082 => let \u27e8x, h\u2083\u27e9 := h\u2081; h\u2083 (h\u2082 x)\u27e9\n\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := \n  \u27e8fun h\u2081 => fun \u27e8x, h\u2082\u27e9 => h\u2081 x h\u2082, fun h => fun x => fun h\u2082 => h \u27e8x, h\u2082\u27e9\u27e9\n\nexample (a : \u03b1) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := \n  \u27e8fun \u27e8x, h\u2081\u27e9 => fun h\u2082 => h\u2081 (h\u2082 x), fun h\u2081 => byContradiction fun h\u2082 => \n    have h\u2083 : \u2200 x, p x := fun x => byContradiction fun h\u2084 => h\u2082 \u27e8x, fun h\u2085 => absurd h\u2085 h\u2084\u27e9; \n    h\u2082 \u27e8a, fun h\u2084 => h\u2081 h\u2083\u27e9\u27e9\n\nexample (a : \u03b1) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := \n  \u27e8fun \u27e8x, h\u2081\u27e9 => fun h\u2082 => \u27e8x, h\u2081 h\u2082\u27e9, \n    fun h\u2081 => byContradiction fun h\u2082 => \n    have h\u2083 : \u2200 x : \u03b1 , r := fun x => byContradiction fun h\u2085 => h\u2082 \u27e8x, fun h\u2086 => absurd h\u2086 h\u2085\u27e9;\n    let \u27e8x, h\u2084\u27e9 := h\u2081 (h\u2083 a); h\u2082 \u27e8x, fun h\u2085 => h\u2084\u27e9\u27e9\n\nend\n", "meta": {"author": "hikarimusic", "repo": "MyLean", "sha": "e42dc138addf5ad80dc3e5dbdbc329b90d9531b0", "save_path": "github-repos/lean/hikarimusic-MyLean", "path": "github-repos/lean/hikarimusic-MyLean/MyLean-e42dc138addf5ad80dc3e5dbdbc329b90d9531b0/Ch4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7368881336269058}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport algebra.gcd_monoid.multiset\nimport combinatorics.partition\nimport group_theory.perm.cycles\nimport ring_theory.int.basic\nimport tactic.linarith\n\n/-!\n# Cycle Types\n\nIn this file we define the cycle type of a permutation.\n\n## Main definitions\n\n- `\u03c3.cycle_type` where `\u03c3` is a permutation of a `fintype`\n- `\u03c3.partition` where `\u03c3` is a permutation of a `fintype`\n\n## Main results\n\n- `sum_cycle_type` : The sum of `\u03c3.cycle_type` equals `\u03c3.support.card`\n- `lcm_cycle_type` : The lcm of `\u03c3.cycle_type` equals `order_of \u03c3`\n- `is_conj_iff_cycle_type_eq` : Two permutations are conjugate if and only if they have the same\n  cycle type.\n* `exists_prime_order_of_dvd_card`: For every prime `p` dividing the order of a finite group `G`\n  there exists an element of order `p` in `G`. This is known as Cauchy`s theorem.\n-/\n\nnamespace equiv.perm\nopen equiv list multiset\n\nvariables {\u03b1 : Type*} [fintype \u03b1]\n\nsection cycle_type\n\nvariables [decidable_eq \u03b1]\n\n/-- The cycle type of a permutation -/\ndef cycle_type (\u03c3 : perm \u03b1) : multiset \u2115 :=\n\u03c3.cycle_factors_finset.1.map (finset.card \u2218 support)\n\nlemma cycle_type_def (\u03c3 : perm \u03b1) :\n  \u03c3.cycle_type = \u03c3.cycle_factors_finset.1.map (finset.card \u2218 support) := rfl\n\nlemma cycle_type_eq' {\u03c3 : perm \u03b1} (s : finset (perm \u03b1))\n  (h1 : \u2200 f : perm \u03b1, f \u2208 s \u2192 f.is_cycle) (h2 : \u2200 (a \u2208 s) (b \u2208 s), a \u2260 b \u2192 disjoint a b)\n  (h0 : s.noncomm_prod id\n    (\u03bb a ha b hb, (em (a = b)).by_cases (\u03bb h, h \u25b8 commute.refl a)\n      (set.pairwise.mono' (\u03bb _ _, disjoint.commute) h2 ha hb)) = \u03c3) :\n  \u03c3.cycle_type = s.1.map (finset.card \u2218 support) :=\nbegin\n  rw cycle_type_def,\n  congr,\n  rw cycle_factors_finset_eq_finset,\n  exact \u27e8h1, h2, h0\u27e9\nend\n\nlemma cycle_type_eq {\u03c3 : perm \u03b1} (l : list (perm \u03b1)) (h0 : l.prod = \u03c3)\n  (h1 : \u2200 \u03c3 : perm \u03b1, \u03c3 \u2208 l \u2192 \u03c3.is_cycle) (h2 : l.pairwise disjoint) :\n  \u03c3.cycle_type = l.map (finset.card \u2218 support) :=\nbegin\n  have hl : l.nodup := nodup_of_pairwise_disjoint_cycles h1 h2,\n  rw cycle_type_eq' l.to_finset,\n  { simp [list.erase_dup_eq_self.mpr hl] },\n  { simpa using h1 },\n  { simpa [hl] using h0 },\n  { simpa [list.erase_dup_eq_self.mpr hl] using list.forall_of_pairwise disjoint.symmetric h2 }\nend\n\nlemma cycle_type_one : (1 : perm \u03b1).cycle_type = 0 :=\ncycle_type_eq [] rfl (\u03bb _, false.elim) pairwise.nil\n\nlemma cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type = 0 \u2194 \u03c3 = 1 :=\nby simp [cycle_type_def, cycle_factors_finset_eq_empty_iff]\n\nlemma card_cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 0 \u2194 \u03c3 = 1 :=\nby rw [card_eq_zero, cycle_type_eq_zero]\n\nlemma two_le_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 2 \u2264 n :=\nbegin\n  simp only [cycle_type_def, \u2190finset.mem_def, function.comp_app, multiset.mem_map,\n    mem_cycle_factors_finset_iff] at h,\n  obtain \u27e8_, \u27e8hc, -\u27e9, rfl\u27e9 := h,\n  exact hc.two_le_card_support\nend\n\nlemma one_lt_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 1 < n :=\ntwo_le_of_mem_cycle_type h\n\nlemma is_cycle.cycle_type {\u03c3 : perm \u03b1} (h\u03c3 : is_cycle \u03c3) : \u03c3.cycle_type = [\u03c3.support.card] :=\ncycle_type_eq [\u03c3] (mul_one \u03c3) (\u03bb \u03c4 h\u03c4, (congr_arg is_cycle (list.mem_singleton.mp h\u03c4)).mpr h\u03c3)\n  (pairwise_singleton disjoint \u03c3)\n\nlemma card_cycle_type_eq_one {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 1 \u2194 \u03c3.is_cycle :=\nbegin\n  rw card_eq_one,\n  simp_rw [cycle_type_def, multiset.map_eq_singleton, \u2190finset.singleton_val,\n           finset.val_inj, cycle_factors_finset_eq_singleton_iff],\n  split,\n  { rintro \u27e8_, _, \u27e8h, -\u27e9, -\u27e9,\n    exact h },\n  { intro h,\n    use [\u03c3.support.card, \u03c3],\n    simp [h] }\nend\n\nlemma disjoint.cycle_type {\u03c3 \u03c4 : perm \u03b1} (h : disjoint \u03c3 \u03c4) :\n  (\u03c3 * \u03c4).cycle_type = \u03c3.cycle_type + \u03c4.cycle_type :=\nbegin\n  rw [cycle_type_def, cycle_type_def, cycle_type_def, h.cycle_factors_finset_mul_eq_union,\n      \u2190multiset.map_add, finset.union_val, multiset.add_eq_union_iff_disjoint.mpr _],\n  rw [\u2190finset.disjoint_val],\n  exact h.disjoint_cycle_factors_finset\nend\n\nlemma cycle_type_inv (\u03c3 : perm \u03b1) : \u03c3\u207b\u00b9.cycle_type = \u03c3.cycle_type :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4\u207b\u00b9.cycle_type = \u03c4.cycle_type) \u03c3 rfl\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, h\u03c3.inv.cycle_type, support_inv])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [mul_inv_rev, h\u03c3\u03c4.cycle_type, \u2190h\u03c3, \u2190h\u03c4, add_comm,\n    disjoint.cycle_type (\u03bb x, or.imp (\u03bb h : \u03c4 x = x, inv_eq_iff_eq.mpr h.symm)\n    (\u03bb h : \u03c3 x = x, inv_eq_iff_eq.mpr h.symm) (h\u03c3\u03c4 x).symm)])\n\nlemma cycle_type_conj {\u03c3 \u03c4 : perm \u03b1} : (\u03c4 * \u03c3 * \u03c4\u207b\u00b9).cycle_type = \u03c3.cycle_type :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intro,\n    simp },\n  { intros \u03c3 h\u03c3 \u03c4,\n    rw [h\u03c3.cycle_type, h\u03c3.is_cycle_conj.cycle_type, card_support_conj] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4 \u03c0,\n    rw [\u2190 conj_mul, hd.cycle_type, disjoint.cycle_type, h\u03c3, h\u03c4],\n    intro a,\n    apply (hd (\u03c0\u207b\u00b9 a)).imp _ _;\n    { intro h, rw [perm.mul_apply, perm.mul_apply, h, apply_inv_self] } }\nend\n\nlemma sum_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.sum = \u03c3.support.card :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.sum = \u03c4.support.card) \u03c3\n  (by rw [cycle_type_one, sum_zero, support_one, finset.card_empty])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, coe_sum, list.sum_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, sum_add, h\u03c3, h\u03c4, h\u03c3\u03c4.card_support_mul])\n\nlemma sign_of_cycle_type (\u03c3 : perm \u03b1) :\n  sign \u03c3 = (\u03c3.cycle_type.map (\u03bb n, -(-1 : \u2124\u02e3) ^ n)).prod :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, sign \u03c4 = (\u03c4.cycle_type.map (\u03bb n, -(-1 : \u2124\u02e3) ^ n)).prod) \u03c3\n  (by rw [sign_one, cycle_type_one, multiset.map_zero, prod_zero])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.sign, h\u03c3.cycle_type, coe_map, coe_prod,\n    list.map_singleton, list.prod_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [sign_mul, h\u03c3, h\u03c4, h\u03c3\u03c4.cycle_type, multiset.map_add, prod_add])\n\nlemma lcm_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.lcm = order_of \u03c3 :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.lcm = order_of \u03c4) \u03c3\n  (by rw [cycle_type_one, lcm_zero, order_of_one])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, \u2190singleton_coe, \u2190singleton_eq_cons, lcm_singleton,\n    order_of_is_cycle h\u03c3, normalize_eq])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, lcm_add, lcm_eq_nat_lcm, h\u03c3\u03c4.order_of, h\u03c3, h\u03c4])\n\nlemma dvd_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : n \u2223 order_of \u03c3 :=\nbegin\n  rw \u2190 lcm_cycle_type,\n  exact dvd_lcm h,\nend\n\nlemma order_of_cycle_of_dvd_order_of (f : perm \u03b1) (x : \u03b1) :\n  order_of (cycle_of f x) \u2223 order_of f :=\nbegin\n  by_cases hx : f x = x,\n  { rw \u2190cycle_of_eq_one_iff at hx,\n    simp [hx] },\n  { refine dvd_of_mem_cycle_type _,\n    rw [cycle_type, multiset.mem_map],\n    refine \u27e8f.cycle_of x, _, _\u27e9,\n    { rwa [\u2190finset.mem_def, cycle_of_mem_cycle_factors_finset_iff, mem_support] },\n    { simp [order_of_is_cycle (is_cycle_cycle_of _ hx)] } }\nend\n\nlemma two_dvd_card_support {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ 2 = 1) : 2 \u2223 \u03c3.support.card :=\n(congr_arg (has_dvd.dvd 2) \u03c3.sum_cycle_type).mp\n  (multiset.dvd_sum (\u03bb n hn, by rw le_antisymm (nat.le_of_dvd zero_lt_two $\n  (dvd_of_mem_cycle_type hn).trans $ order_of_dvd_of_pow_eq_one h\u03c3) (two_le_of_mem_cycle_type hn)))\n\nlemma cycle_type_prime_order {\u03c3 : perm \u03b1} (h\u03c3 : (order_of \u03c3).prime) :\n  \u2203 n : \u2115, \u03c3.cycle_type = repeat (order_of \u03c3) (n + 1) :=\nbegin\n  rw eq_repeat_of_mem (\u03bb n hn, or_iff_not_imp_left.mp\n    (h\u03c3.eq_one_or_self_of_dvd n (dvd_of_mem_cycle_type hn)) (one_lt_of_mem_cycle_type hn).ne'),\n  use \u03c3.cycle_type.card - 1,\n  rw tsub_add_cancel_of_le,\n  rw [nat.succ_le_iff, pos_iff_ne_zero, ne, card_cycle_type_eq_zero],\n  intro H,\n  rw [H, order_of_one] at h\u03c3,\n  exact h\u03c3.ne_one rfl,\nend\n\nlemma is_cycle_of_prime_order {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : \u03c3.support.card < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  obtain \u27e8n, hn\u27e9 := cycle_type_prime_order h1,\n  rw [\u2190\u03c3.sum_cycle_type, hn, multiset.sum_repeat, nsmul_eq_mul, nat.cast_id, mul_lt_mul_right\n      (order_of_pos \u03c3), nat.succ_lt_succ_iff, nat.lt_succ_iff, nat.le_zero_iff] at h2,\n  rw [\u2190card_cycle_type_eq_one, hn, card_repeat, h2],\nend\n\nlemma cycle_type_le_of_mem_cycle_factors_finset {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  f.cycle_type \u2264 g.cycle_type :=\nbegin\n  rw mem_cycle_factors_finset_iff at hf,\n  rw [cycle_type_def, cycle_type_def, hf.left.cycle_factors_finset_eq_singleton],\n  refine map_le_map _,\n  simpa [\u2190finset.mem_def, mem_cycle_factors_finset_iff] using hf\nend\n\nlemma cycle_type_mul_mem_cycle_factors_finset_eq_sub {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  (g * f\u207b\u00b9).cycle_type = g.cycle_type - f.cycle_type :=\nbegin\n  suffices : (g * f\u207b\u00b9).cycle_type + f.cycle_type = g.cycle_type - f.cycle_type + f.cycle_type,\n  { rw tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf) at this,\n    simp [\u2190this] },\n  simp [\u2190(disjoint_mul_inv_of_mem_cycle_factors_finset hf).cycle_type,\n    tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf)]\nend\n\ntheorem is_conj_of_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} (h : cycle_type \u03c3 = cycle_type \u03c4) : is_conj \u03c3 \u03c4 :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intros \u03c4 h,\n    rw [cycle_type_one, eq_comm, cycle_type_eq_zero] at h,\n    rw h },\n  { intros \u03c3 h\u03c3 \u03c4 h\u03c3\u03c4,\n    have h\u03c4 := card_cycle_type_eq_one.2 h\u03c3,\n    rw [h\u03c3\u03c4, card_cycle_type_eq_one] at h\u03c4,\n    apply h\u03c3.is_conj h\u03c4,\n    rw [h\u03c3.cycle_type, h\u03c4.cycle_type, coe_eq_coe, singleton_perm] at h\u03c3\u03c4,\n    simp only [and_true, eq_self_iff_true] at h\u03c3\u03c4,\n    exact h\u03c3\u03c4 },\n  { intros \u03c3 \u03c4 h\u03c3\u03c4 h\u03c3 h1 h2 \u03c0 h\u03c0,\n    rw [h\u03c3\u03c4.cycle_type] at h\u03c0,\n    { have h : \u03c3.support.card \u2208 map (finset.card \u2218 perm.support) \u03c0.cycle_factors_finset.val,\n      { simp [\u2190cycle_type_def, \u2190h\u03c0, h\u03c3.cycle_type] },\n      obtain \u27e8\u03c3', h\u03c3'l, h\u03c3'\u27e9 := multiset.mem_map.mp h,\n      have key : is_conj (\u03c3' * (\u03c0 * \u03c3'\u207b\u00b9)) \u03c0,\n      { rw is_conj_iff,\n        use \u03c3'\u207b\u00b9,\n        simp [mul_assoc] },\n      refine is_conj.trans _ key,\n      have hs : \u03c3.cycle_type = \u03c3'.cycle_type,\n      { rw [\u2190finset.mem_def, mem_cycle_factors_finset_iff] at h\u03c3'l,\n        rw [h\u03c3.cycle_type, \u2190h\u03c3', h\u03c3'l.left.cycle_type] },\n      refine h\u03c3\u03c4.is_conj_mul (h1 hs) (h2 _) _,\n      { rw [cycle_type_mul_mem_cycle_factors_finset_eq_sub, \u2190h\u03c0, add_comm, hs,\n            add_tsub_cancel_right],\n        rwa finset.mem_def },\n      { exact (disjoint_mul_inv_of_mem_cycle_factors_finset h\u03c3'l).symm } } }\nend\n\ntheorem is_conj_iff_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.cycle_type = \u03c4.cycle_type :=\n\u27e8\u03bb h, begin\n  obtain \u27e8\u03c0, rfl\u27e9 := is_conj_iff.1 h,\n  rw cycle_type_conj,\nend, is_conj_of_cycle_type_eq\u27e9\n\n@[simp] lemma cycle_type_extend_domain {\u03b2 : Type*} [fintype \u03b2] [decidable_eq \u03b2]\n  {p : \u03b2 \u2192 Prop} [decidable_pred p] (f : \u03b1 \u2243 subtype p) {g : perm \u03b1} :\n  cycle_type (g.extend_domain f) = cycle_type g :=\nbegin\n  apply cycle_induction_on _ g,\n  { rw [extend_domain_one, cycle_type_one, cycle_type_one] },\n  { intros \u03c3 h\u03c3,\n    rw [(h\u03c3.extend_domain f).cycle_type, h\u03c3.cycle_type, card_support_extend_domain] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4,\n    rw [hd.cycle_type, \u2190 extend_domain_mul, (hd.extend_domain f).cycle_type, h\u03c3, h\u03c4] }\nend\n\nlemma mem_cycle_type_iff {n : \u2115} {\u03c3 : perm \u03b1} :\n  n \u2208 cycle_type \u03c3 \u2194 \u2203 c \u03c4 : perm \u03b1, \u03c3 = c * \u03c4 \u2227 disjoint c \u03c4 \u2227 is_cycle c \u2227 c.support.card = n :=\nbegin\n  split,\n  { intro h,\n    obtain \u27e8l, rfl, hlc, hld\u27e9 := trunc_cycle_factors \u03c3,\n    rw cycle_type_eq _ rfl hlc hld at h,\n    obtain \u27e8c, cl, rfl\u27e9 := list.exists_of_mem_map h,\n    rw (list.perm_cons_erase cl).pairwise_iff (\u03bb _ _ hd, _) at hld,\n    swap, { exact hd.symm },\n    refine \u27e8c, (l.erase c).prod, _, _, hlc _ cl, rfl\u27e9,\n    { rw [\u2190 list.prod_cons,\n        (list.perm_cons_erase cl).symm.prod_eq' (hld.imp (\u03bb _ _, disjoint.commute))] },\n    { exact disjoint_prod_right _ (\u03bb g, list.rel_of_pairwise_cons hld) } },\n  { rintros \u27e8c, t, rfl, hd, hc, rfl\u27e9,\n    simp [hd.cycle_type, hc.cycle_type] }\nend\n\nlemma le_card_support_of_mem_cycle_type {n : \u2115} {\u03c3 : perm \u03b1} (h : n \u2208 cycle_type \u03c3) :\n  n \u2264 \u03c3.support.card :=\n(le_sum_of_mem h).trans (le_of_eq \u03c3.sum_cycle_type)\n\nlemma cycle_type_of_card_le_mem_cycle_type_add_two {n : \u2115} {g : perm \u03b1}\n  (hn2 : fintype.card \u03b1 < n + 2) (hng : n \u2208 g.cycle_type) :\n  g.cycle_type = {n} :=\nbegin\n  obtain \u27e8c, g', rfl, hd, hc, rfl\u27e9 := mem_cycle_type_iff.1 hng,\n  by_cases g'1 : g' = 1,\n  { rw [hd.cycle_type, hc.cycle_type, multiset.singleton_eq_cons, multiset.singleton_coe,\n      g'1, cycle_type_one, add_zero] },\n  contrapose! hn2,\n  apply le_trans _ (c * g').support.card_le_univ,\n  rw [hd.card_support_mul],\n  exact add_le_add_left (two_le_card_support_of_ne_one g'1) _,\nend\n\nend cycle_type\n\nlemma card_compl_support_modeq [decidable_eq \u03b1] {p n : \u2115} [hp : fact p.prime] {\u03c3 : perm \u03b1}\n  (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u03c3.support\u1d9c.card \u2261 fintype.card \u03b1 [MOD p] :=\nbegin\n  rw [nat.modeq_iff_dvd' \u03c3.support\u1d9c.card_le_univ, \u2190finset.card_compl, compl_compl],\n  refine (congr_arg _ \u03c3.sum_cycle_type).mp (multiset.dvd_sum (\u03bb k hk, _)),\n  obtain \u27e8m, -, hm\u27e9 := (nat.dvd_prime_pow hp.out).mp (order_of_dvd_of_pow_eq_one h\u03c3),\n  obtain \u27e8l, -, rfl\u27e9 := (nat.dvd_prime_pow hp.out).mp\n    ((congr_arg _ hm).mp (dvd_of_mem_cycle_type hk)),\n  exact dvd_pow_self _ (\u03bb h, (one_lt_of_mem_cycle_type hk).ne $ by rw [h, pow_zero]),\nend\n\nlemma exists_fixed_point_of_prime {p n : \u2115} [hp : fact p.prime] (h\u03b1 : \u00ac p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u2203 a : \u03b1, \u03c3 a = a :=\nbegin\n  classical,\n  contrapose! h\u03b1,\n  simp_rw \u2190 mem_support at h\u03b1,\n  exact nat.modeq_zero_iff_dvd.mp ((congr_arg _ (finset.card_eq_zero.mpr (compl_eq_bot.mpr\n    (finset.eq_univ_iff_forall.mpr h\u03b1)))).mp (card_compl_support_modeq h\u03c3).symm),\nend\n\nlemma exists_fixed_point_of_prime' {p n : \u2115} [hp : fact p.prime] (h\u03b1 : p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) {a : \u03b1} (ha : \u03c3 a = a) : \u2203 b : \u03b1, \u03c3 b = b \u2227 b \u2260 a :=\nbegin\n  classical,\n  have h : \u2200 b : \u03b1, b \u2208 \u03c3.support\u1d9c \u2194 \u03c3 b = b :=\n  \u03bb b, by rw [finset.mem_compl, mem_support, not_not],\n  obtain \u27e8b, hb1, hb2\u27e9 := finset.exists_ne_of_one_lt_card (lt_of_lt_of_le hp.out.one_lt\n    (nat.le_of_dvd (finset.card_pos.mpr \u27e8a, (h a).mpr ha\u27e9) (nat.modeq_zero_iff_dvd.mp\n    ((card_compl_support_modeq h\u03c3).trans (nat.modeq_zero_iff_dvd.mpr h\u03b1))))) a,\n  exact \u27e8b, (h b).mp hb1, hb2\u27e9,\nend\n\nlemma is_cycle_of_prime_order' {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : fintype.card \u03b1 < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  classical,\n  exact is_cycle_of_prime_order h1 (lt_of_le_of_lt \u03c3.support.card_le_univ h2),\nend\n\nlemma is_cycle_of_prime_order'' {\u03c3 : perm \u03b1} (h1 : (fintype.card \u03b1).prime)\n  (h2 : order_of \u03c3 = fintype.card \u03b1) : \u03c3.is_cycle :=\nis_cycle_of_prime_order' ((congr_arg nat.prime h2).mpr h1)\nbegin\n  classical,\n  rw [\u2190one_mul (fintype.card \u03b1), \u2190h2, mul_lt_mul_right (order_of_pos \u03c3)],\n  exact one_lt_two,\nend\n\nsection cauchy\n\nvariables (G : Type*) [group G] (n : \u2115)\n\n/-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/\ndef vectors_prod_eq_one : set (vector G n) :=\n{v | v.to_list.prod = 1}\n\nnamespace vectors_prod_eq_one\n\nlemma mem_iff {n : \u2115} (v : vector G n) :\nv \u2208 vectors_prod_eq_one G n \u2194 v.to_list.prod = 1 := iff.rfl\n\nlemma zero_eq : vectors_prod_eq_one G 0 = {vector.nil} :=\nset.eq_singleton_iff_unique_mem.mpr \u27e8eq.refl (1 : G), \u03bb v hv, v.eq_nil\u27e9\n\nlemma one_eq : vectors_prod_eq_one G 1 = {vector.nil.cons 1} :=\nbegin\n  simp_rw [set.eq_singleton_iff_unique_mem, mem_iff,\n    vector.to_list_singleton, list.prod_singleton, vector.head_cons],\n  exact \u27e8rfl, \u03bb v hv, v.cons_head_tail.symm.trans (congr_arg2 vector.cons hv v.tail.eq_nil)\u27e9,\nend\n\ninstance zero_unique : unique (vectors_prod_eq_one G 0) :=\nby { rw zero_eq, exact set.unique_singleton vector.nil }\n\ninstance one_unique : unique (vectors_prod_eq_one G 1) :=\nby { rw one_eq, exact set.unique_singleton (vector.nil.cons 1) }\n\n/-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`,\nby appending the inverse of the product of `v`. -/\n@[simps] def vector_equiv : vector G n \u2243 vectors_prod_eq_one G (n + 1) :=\n{ to_fun := \u03bb v, \u27e8v.to_list.prod\u207b\u00b9 ::\u1d65 v,\n    by rw [mem_iff, vector.to_list_cons, list.prod_cons, inv_mul_self]\u27e9,\n  inv_fun := \u03bb v, v.1.tail,\n  left_inv := \u03bb v, v.tail_cons v.to_list.prod\u207b\u00b9,\n  right_inv := \u03bb v, subtype.ext ((congr_arg2 vector.cons (eq_inv_of_mul_eq_one (by\n  { rw [\u2190list.prod_cons, \u2190vector.to_list_cons, v.1.cons_head_tail],\n    exact v.2 })).symm rfl).trans v.1.cons_head_tail) }\n\n/-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`,\nby deleting the last entry of `v`. -/\ndef equiv_vector : vectors_prod_eq_one G n \u2243 vector G (n - 1) :=\n((vector_equiv G (n - 1)).trans (if hn : n = 0 then (show vectors_prod_eq_one G (n - 1 + 1) \u2243\n  vectors_prod_eq_one G n, by { rw hn, exact equiv_of_unique_of_unique })\n  else by rw tsub_add_cancel_of_le (nat.pos_of_ne_zero hn).nat_succ_le)).symm\n\ninstance [fintype G] : fintype (vectors_prod_eq_one G n) :=\nfintype.of_equiv (vector G (n - 1)) (equiv_vector G n).symm\n\nlemma card [fintype G] :\n  fintype.card (vectors_prod_eq_one G n) = fintype.card G ^ (n - 1) :=\n(fintype.card_congr (equiv_vector G n)).trans (card_vector (n - 1))\n\nvariables {G n} {g : G} (v : vectors_prod_eq_one G n) (j k : \u2115)\n\n/-- Rotate a vector whose product is 1. -/\ndef rotate : vectors_prod_eq_one G n :=\n\u27e8\u27e8_, (v.1.1.length_rotate k).trans v.1.2\u27e9, list.prod_rotate_eq_one_of_prod_eq_one v.2 k\u27e9\n\nlemma rotate_zero : rotate v 0 = v :=\nsubtype.ext (subtype.ext v.1.1.rotate_zero)\n\nlemma rotate_rotate : rotate (rotate v j) k = rotate v (j + k) :=\nsubtype.ext (subtype.ext (v.1.1.rotate_rotate j k))\n\nlemma rotate_length : rotate v n = v :=\nsubtype.ext (subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length))\n\nend vectors_prod_eq_one\n\nlemma exists_prime_order_of_dvd_card {G : Type*} [group G] [fintype G] (p : \u2115) [hp : fact p.prime]\n  (hdvd : p \u2223 fintype.card G) : \u2203 x : G, order_of x = p :=\nbegin\n  have hp' : p - 1 \u2260 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_lt hp.out.one_lt),\n  have Scard := calc p \u2223 fintype.card G ^ (p - 1) : hdvd.trans (dvd_pow (dvd_refl _) hp')\n  ... = fintype.card (vectors_prod_eq_one G p) : (vectors_prod_eq_one.card G p).symm,\n  let f : \u2115 \u2192 vectors_prod_eq_one G p \u2192 vectors_prod_eq_one G p :=\n  \u03bb k v, vectors_prod_eq_one.rotate v k,\n  have hf1 : \u2200 v, f 0 v = v := vectors_prod_eq_one.rotate_zero,\n  have hf2 : \u2200 j k v, f k (f j v) = f (j + k) v :=\n  \u03bb j k v, vectors_prod_eq_one.rotate_rotate v j k,\n  have hf3 : \u2200 v, f p v = v := vectors_prod_eq_one.rotate_length,\n  let \u03c3 := equiv.mk (f 1) (f (p - 1))\n    (\u03bb s, by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3])\n    (\u03bb s, by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3]),\n  have h\u03c3 : \u2200 k v, (\u03c3 ^ k) v = f k v :=\n  \u03bb k v, nat.rec (hf1 v).symm (\u03bb k hk, eq.trans (by exact congr_arg \u03c3 hk) (hf2 k 1 v)) k,\n  replace h\u03c3 : \u03c3 ^ (p ^ 1) = 1 := perm.ext (\u03bb v, by rw [pow_one, h\u03c3, hf3, one_apply]),\n  let v\u2080 : vectors_prod_eq_one G p := \u27e8vector.repeat 1 p, (list.prod_repeat 1 p).trans (one_pow p)\u27e9,\n  have hv\u2080 : \u03c3 v\u2080 = v\u2080 := subtype.ext (subtype.ext (list.rotate_repeat (1 : G) p 1)),\n  obtain \u27e8v, hv1, hv2\u27e9 := exists_fixed_point_of_prime' Scard h\u03c3 hv\u2080,\n  refine exists_imp_exists (\u03bb g hg, order_of_eq_prime _ (\u03bb hg', hv2 _))\n    (list.rotate_one_eq_self_iff_eq_repeat.mp (subtype.ext_iff.mp (subtype.ext_iff.mp hv1))),\n  { rw [\u2190list.prod_repeat, \u2190v.1.2, \u2190hg, (show v.val.val.prod = 1, from v.2)] },\n  { rw [subtype.ext_iff_val, subtype.ext_iff_val, hg, hg', v.1.2],\n    refl },\nend\n\nend cauchy\n\nlemma subgroup_eq_top_of_swap_mem [decidable_eq \u03b1] {H : subgroup (perm \u03b1)}\n  [d : decidable_pred (\u2208 H)] {\u03c4 : perm \u03b1} (h0 : (fintype.card \u03b1).prime)\n  (h1 : fintype.card \u03b1 \u2223 fintype.card H) (h2 : \u03c4 \u2208 H) (h3 : is_swap \u03c4) :\n  H = \u22a4 :=\nbegin\n  haveI : fact (fintype.card \u03b1).prime := \u27e8h0\u27e9,\n  obtain \u27e8\u03c3, h\u03c3\u27e9 := exists_prime_order_of_dvd_card (fintype.card \u03b1) h1,\n  have h\u03c31 : order_of (\u03c3 : perm \u03b1) = fintype.card \u03b1 := (order_of_subgroup \u03c3).trans h\u03c3,\n  have h\u03c32 : is_cycle \u2191\u03c3 := is_cycle_of_prime_order'' h0 h\u03c31,\n  have h\u03c33 : (\u03c3 : perm \u03b1).support = \u22a4 :=\n    finset.eq_univ_of_card (\u03c3 : perm \u03b1).support ((order_of_is_cycle h\u03c32).symm.trans h\u03c31),\n  have h\u03c34 : subgroup.closure {\u2191\u03c3, \u03c4} = \u22a4 := closure_prime_cycle_swap h0 h\u03c32 h\u03c33 h3,\n  rw [eq_top_iff, \u2190h\u03c34, subgroup.closure_le, set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8subtype.mem \u03c3, h2\u27e9,\nend\n\nsection partition\n\nvariables [decidable_eq \u03b1]\n\n/-- The partition corresponding to a permutation -/\ndef partition (\u03c3 : perm \u03b1) : (fintype.card \u03b1).partition :=\n{ parts := \u03c3.cycle_type + repeat 1 (fintype.card \u03b1 - \u03c3.support.card),\n  parts_pos := \u03bb n hn,\n  begin\n    cases mem_add.mp hn with hn hn,\n    { exact zero_lt_one.trans (one_lt_of_mem_cycle_type hn) },\n    { exact lt_of_lt_of_le zero_lt_one (ge_of_eq (multiset.eq_of_mem_repeat hn)) },\n  end,\n  parts_sum := by rw [sum_add, sum_cycle_type, multiset.sum_repeat, nsmul_eq_mul,\n    nat.cast_id, mul_one, add_tsub_cancel_of_le \u03c3.support.card_le_univ] }\n\nlemma parts_partition {\u03c3 : perm \u03b1} :\n  \u03c3.partition.parts = \u03c3.cycle_type + repeat 1 (fintype.card \u03b1 - \u03c3.support.card) := rfl\n\nlemma filter_parts_partition_eq_cycle_type {\u03c3 : perm \u03b1} :\n  (partition \u03c3).parts.filter (\u03bb n, 2 \u2264 n) = \u03c3.cycle_type :=\nbegin\n  rw [parts_partition, filter_add, multiset.filter_eq_self.2 (\u03bb _, two_le_of_mem_cycle_type),\n    multiset.filter_eq_nil.2 (\u03bb a h, _), add_zero],\n  rw multiset.eq_of_mem_repeat h,\n  dec_trivial\nend\n\nlemma partition_eq_of_is_conj {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.partition = \u03c4.partition :=\nbegin\n  rw [is_conj_iff_cycle_type_eq],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rw [nat.partition.ext_iff, parts_partition, parts_partition,\n      \u2190 sum_cycle_type, \u2190 sum_cycle_type, h] },\n  { rw [\u2190 filter_parts_partition_eq_cycle_type, \u2190 filter_parts_partition_eq_cycle_type, h] }\nend\n\nend partition\n\n/-!\n### 3-cycles\n-/\n\n/-- A three-cycle is a cycle of length 3. -/\ndef is_three_cycle [decidable_eq \u03b1] (\u03c3 : perm \u03b1) : Prop := \u03c3.cycle_type = {3}\n\nnamespace is_three_cycle\n\nvariables [decidable_eq \u03b1] {\u03c3 : perm \u03b1}\n\nlemma cycle_type (h : is_three_cycle \u03c3) : \u03c3.cycle_type = {3} := h\n\nlemma card_support (h : is_three_cycle \u03c3) : \u03c3.support.card = 3 :=\nby rw [\u2190sum_cycle_type, h.cycle_type, multiset.sum_singleton]\n\nlemma _root_.card_support_eq_three_iff : \u03c3.support.card = 3 \u2194 \u03c3.is_three_cycle :=\nbegin\n  refine \u27e8\u03bb h, _, is_three_cycle.card_support\u27e9,\n  by_cases h0 : \u03c3.cycle_type = 0,\n  { rw [\u2190sum_cycle_type, h0, sum_zero] at h,\n    exact (ne_of_lt zero_lt_three h).elim },\n  obtain \u27e8n, hn\u27e9 := exists_mem_of_ne_zero h0,\n  by_cases h1 : \u03c3.cycle_type.erase n = 0,\n  { rw [\u2190sum_cycle_type, \u2190cons_erase hn, h1, \u2190singleton_eq_cons, multiset.sum_singleton] at h,\n    rw [is_three_cycle, \u2190cons_erase hn, h1, h, singleton_eq_cons] },\n  obtain \u27e8m, hm\u27e9 := exists_mem_of_ne_zero h1,\n  rw [\u2190sum_cycle_type, \u2190cons_erase hn, \u2190cons_erase hm, multiset.sum_cons, multiset.sum_cons] at h,\n  linarith [two_le_of_mem_cycle_type hn, two_le_of_mem_cycle_type (mem_of_mem_erase hm)],\nend\n\nlemma is_cycle (h : is_three_cycle \u03c3) : is_cycle \u03c3 :=\nby rw [\u2190card_cycle_type_eq_one, h.cycle_type, card_singleton]\n\nlemma sign (h : is_three_cycle \u03c3) : sign \u03c3 = 1 :=\nbegin\n  rw [sign_of_cycle_type, h.cycle_type],\n  refl,\nend\n\nlemma inv {f : perm \u03b1} (h : is_three_cycle f) : is_three_cycle (f\u207b\u00b9) :=\nby rwa [is_three_cycle, cycle_type_inv]\n\n@[simp] lemma inv_iff {f : perm \u03b1} : is_three_cycle (f\u207b\u00b9) \u2194 is_three_cycle f :=\n\u27e8by { rw \u2190 inv_inv f, apply inv }, inv\u27e9\n\nlemma order_of {g : perm \u03b1} (ht : is_three_cycle g) :\n  order_of g = 3 :=\nby rw [\u2190lcm_cycle_type, ht.cycle_type, multiset.lcm_singleton, normalize_eq]\n\nlemma is_three_cycle_sq {g : perm \u03b1} (ht : is_three_cycle g) :\n  is_three_cycle (g * g) :=\nbegin\n  rw [\u2190pow_two, \u2190card_support_eq_three_iff, support_pow_coprime, ht.card_support],\n  rw [ht.order_of, nat.coprime_iff_gcd_eq_one],\n  norm_num,\nend\n\nend is_three_cycle\n\nsection\nvariable [decidable_eq \u03b1]\n\nlemma is_three_cycle_swap_mul_swap_same\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) (bc : b \u2260 c) :\n  is_three_cycle (swap a b * swap a c) :=\nbegin\n  suffices h : support (swap a b * swap a c) = {a, b, c},\n  { rw [\u2190card_support_eq_three_iff, h],\n    simp [ab, ac, bc] },\n  apply le_antisymm ((support_mul_le _ _).trans (\u03bb x, _)) (\u03bb x hx, _),\n  { simp [ab, ac, bc] },\n  { simp only [finset.mem_insert, finset.mem_singleton] at hx,\n    rw mem_support,\n    simp only [perm.coe_mul, function.comp_app, ne.def],\n    obtain rfl | rfl | rfl := hx,\n    { rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm],\n      exact ac.symm },\n    { rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right],\n      exact ab },\n    { rw [swap_apply_right, swap_apply_left],\n      exact bc } }\nend\n\nopen subgroup\n\nlemma swap_mul_swap_same_mem_closure_three_cycles\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) :\n  (swap a b * swap a c) \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  by_cases bc : b = c,\n  { subst bc,\n    simp [one_mem] },\n  exact subset_closure (is_three_cycle_swap_mul_swap_same ab ac bc)\nend\n\nlemma is_swap.mul_mem_closure_three_cycles {\u03c3 \u03c4 : perm \u03b1}\n  (h\u03c3 : is_swap \u03c3) (h\u03c4 : is_swap \u03c4) :\n  \u03c3 * \u03c4 \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  obtain \u27e8a, b, ab, rfl\u27e9 := h\u03c3,\n  obtain \u27e8c, d, cd, rfl\u27e9 := h\u03c4,\n  by_cases ac : a = c,\n  { subst ac,\n    exact swap_mul_swap_same_mem_closure_three_cycles ab cd },\n  have h' : swap a b * swap c d = swap a b * swap a c * (swap c a * swap c d),\n  { simp [swap_comm c a, mul_assoc] },\n  rw h',\n  exact mul_mem _ (swap_mul_swap_same_mem_closure_three_cycles ab ac)\n    (swap_mul_swap_same_mem_closure_three_cycles (ne.symm ac) cd),\nend\n\nend\n\nend equiv.perm\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/group_theory/perm/cycle_type.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7368470731929783}}
{"text": "/-\nCopyright (c) 2021 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn, Eric Wieser\n-/\nimport group_theory.free_group\n/-!\n# Free groups structures on arbitrary types\n\nThis file defines the universal property of free groups, and proves some things about\ngroups with this property. For an explicit construction of free groups, see\n`group_theory/free_group`.\n\n## Main definitions\n\n* `is_free_group G` - a typeclass to indicate that `G` is free over some generators\n* `is_free_group.lift` - the (noncomputable) universal property of the free group\n* `is_free_group.to_free_group` - any free group with generators `A` is equivalent to\n  `free_group A`.\n\n## Implementation notes\n\nWhile the typeclass only requires the universal property hold within a single universe `u`, our\nexplicit construction of `free_group` allows this to be extended universe polymorphically. The\nprimed definition names in this file refer to the non-polymorphic versions.\n\n-/\nnoncomputable theory\nuniverses u w\n\n/-- `is_free_group G` means that `G` has the universal property of a free group,\nThat is, it has a family `generators G` of elements, such that a group homomorphism\n`G \u2192* X` is uniquely determined by a function `generators G \u2192 X`. -/\nclass is_free_group (G : Type u) [group G] : Type (u+1) :=\n(generators : Type u)\n(of : generators \u2192 G)\n(unique_lift' : \u2200 {X : Type u} [group X] (f : generators \u2192 X),\n                \u2203! F : G \u2192* X, \u2200 a, F (of a) = f a)\n\ninstance free_group_is_free_group {A} : is_free_group (free_group A) :=\n{ generators := A,\n  of := free_group.of,\n  unique_lift' := begin\n    introsI X _ f,\n    have := free_group.lift.symm.bijective.exists_unique f,\n    simp_rw function.funext_iff at this,\n    exact this,\n  end }\n\nnamespace is_free_group\n\nvariables {G H : Type u} {X : Type w} [group G] [group H] [group X] [is_free_group G]\n\n/-- The equivalence between functions on the generators and group homomorphisms from a free group\ngiven by those generators. -/\n@[simps symm_apply]\ndef lift' : (generators G \u2192 H) \u2243 (G \u2192* H) :=\n{ to_fun := \u03bb f, classical.some (unique_lift' f),\n  inv_fun := \u03bb F, F \u2218 of,\n  left_inv := \u03bb f, funext (classical.some_spec (unique_lift' f)).left,\n  right_inv := \u03bb F, ((classical.some_spec (unique_lift' (F \u2218 of))).right F (\u03bb _, rfl)).symm }\n\n@[simp] lemma lift'_of (f : generators G \u2192 H) (a : generators G) : (lift' f) (of a) = f a :=\ncongr_fun (lift'.symm_apply_apply f) a\n\n@[simp] lemma lift'_eq_free_group_lift {A : Type u} :\n  (@lift' (free_group A) H _ _ _) = free_group.lift :=\nbegin\n  -- TODO: `apply equiv.symm_bijective.injective`,\n  rw [\u2190free_group.lift.symm_symm, \u2190(@lift' (free_group A) H _ _ _).symm_symm],\n  congr' 1,\n  ext,\n  refl,\nend\n\n@[simp] lemma of_eq_free_group_of {A : Type u} : (@of (free_group A) _ _) = free_group.of :=\nrfl\n\n@[ext]\nlemma ext_hom' \u2983f g : G \u2192* H\u2984 (h : \u2200 a, f (of a) = g (of a)) :\n  f = g :=\nlift'.symm.injective $ funext h\n\n/-- Being a free group transports across group isomorphisms within a universe. -/\ndef of_mul_equiv (h : G \u2243* H) : is_free_group H :=\n{ generators := generators G,\n  of := h \u2218 of,\n  unique_lift' := begin\n    introsI X _ f,\n    refine \u27e8(lift' f).comp h.symm.to_monoid_hom, _, _\u27e9,\n    { simp },\n    intros F' hF',\n    suffices : F'.comp h.to_monoid_hom = lift' f,\n    { rw \u2190this, ext, apply congr_arg, symmetry, apply mul_equiv.apply_symm_apply },\n    ext,\n    simp [hF'],\n  end }\n\n/-!\n### Universe-polymorphic definitions\n\n\nThe primed definitions and lemmas above require `G` and `H` to be in the same universe `u`.\nThe lemmas below use `X` in a different universe `w`\n-/\n\nvariable (G)\n\n/-- Any free group is isomorphic to \"the\" free group. -/\n@[simps] def to_free_group : G \u2243* free_group (generators G) :=\n{ to_fun := lift' free_group.of,\n  inv_fun := free_group.lift of,\n  left_inv :=\n    suffices (free_group.lift of).comp (lift' free_group.of) = monoid_hom.id G,\n    from monoid_hom.congr_fun this,\n    by { ext, simp },\n  right_inv :=\n    suffices\n      (lift' free_group.of).comp (free_group.lift of) = monoid_hom.id (free_group (generators G)),\n    from monoid_hom.congr_fun this,\n    by { ext, simp },\n  map_mul' := (lift' free_group.of).map_mul }\n\nvariable {G}\n\nprivate lemma lift_right_inv_aux (F : G \u2192* X) :\n  free_group.lift.symm (F.comp (to_free_group G).symm.to_monoid_hom) = F \u2218 of :=\nby { ext, simp }\n\n/-- A universe-polymorphic version of `is_free_group.lift'`. -/\n@[simps symm_apply]\ndef lift : (generators G \u2192 X) \u2243 (G \u2192* X) :=\n{ to_fun := \u03bb f, (free_group.lift f).comp (to_free_group G).to_monoid_hom,\n  inv_fun := \u03bb F, F \u2218 of,\n  left_inv := \u03bb f, free_group.lift.injective begin\n    ext x,\n    simp,\n  end,\n  right_inv := \u03bb F, begin\n    dsimp,\n    rw \u2190lift_right_inv_aux,\n    simp only [equiv.apply_symm_apply],\n    ext x,\n    dsimp only [monoid_hom.comp_apply, mul_equiv.coe_to_monoid_hom],\n    rw mul_equiv.symm_apply_apply,\n  end}\n\n@[ext]\nlemma ext_hom \u2983f g : G \u2192* X\u2984 (h : \u2200 a, f (of a) = g (of a)) :\n  f = g :=\nis_free_group.lift.symm.injective $ funext h\n\n@[simp] lemma lift_of (f : generators G \u2192 X) (a : generators G) : (lift f) (of a) = f a :=\ncongr_fun (lift.symm_apply_apply f) a\n\n@[simp] lemma lift_eq_free_group_lift {A : Type u} :\n  (@lift (free_group A) H _ _ _) = free_group.lift :=\nbegin\n  -- TODO: `apply equiv.symm_bijective.injective`,\n  rw [\u2190free_group.lift.symm_symm, \u2190(@lift (free_group A) H _ _ _).symm_symm],\n  congr' 1,\n  ext,\n  refl,\nend\n\n/-- A universe-polymorphic version of `unique_lift`. -/\nlemma unique_lift {X : Type w} [group X] (f : generators G \u2192 X) :\n  \u2203! F : G \u2192* X, \u2200 a, F (of a) = f a :=\nbegin\n  have := lift.symm.bijective.exists_unique f,\n  simp_rw function.funext_iff at this,\n  exact this,\nend\n\nend is_free_group\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/is_free_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7368470688447523}}
{"text": "import .lovelib\n\n\n/-! # LoVe Exercise 3: Forward Proofs -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Connectives and Quantifiers\n\n1.1. Supply structured proofs of the following lemmas. -/\n\nlemma I (a : Prop) :\n  a \u2192 a :=\nsorry\n\nlemma K (a b : Prop) :\n  a \u2192 b \u2192 b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 b \u2192 a \u2192 c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a \u2192 a \u2192 a :=\nsorry\n\n/-! Please give a different answer than for `proj_1st`. -/\n\nlemma proj_2nd (a : Prop) :\n  a \u2192 a \u2192 a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 a \u2192 (a \u2192 c) \u2192 b \u2192 c :=\nsorry\n\n/-! 1.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a \u2192 b) \u2192 \u00ac b \u2192 \u00ac a :=\nsorry\n\n/-! 1.3. Supply a structured proof of the distributivity of `\u2200` over `\u2227`. -/\n\nlemma forall_and {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2200x, p x \u2227 q x) \u2194 (\u2200x, p x) \u2227 (\u2200x, q x) :=\nsorry\n\n/-! 1.4 (**optional**). Reuse, if possible, the lemma `forall_and` from question\n1.3 to prove the following instance of the lemma. -/\n\nlemma forall_and_inst {\u03b1 : Type} (r s : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2200x, r x x \u2227 s x x) \u2194 (\u2200x, r x x) \u2227 (\u2200x, s x x) :=\nsorry\n\n/-! 1.5. Supply a structured proof of the following property, which can be used\nto pull a `\u2200`-quantifier past an `\u2203`-quantifier. -/\n\nlemma forall_exists_of_exists_forall {\u03b1 : Type} (p : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2203x, \u2200y, p x y) \u2192 (\u2200y, \u2203x, p x y) :=\nsorry\n\n\n/-! ## Question 2: Chain of Equalities\n\n2.1. Write the following proof using `calc`.\n\n      (a + b) * (a + b)\n    = a * (a + b) + b * (a + b)\n    = a * a + a * b + b * a + b * b\n    = a * a + a * b + a * b + b * b\n    = a * a + 2 * a * b + b * b\n\nHint: You might need the tactics `simp` and `cc` and the lemmas `mul_add`,\n`add_mul`, and `two_mul`. -/\n\nlemma binomial_square (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/-! 2.2 (**optional**). Prove the same argument again, this time as a structured\nproof, with `have` steps corresponding to the `calc` equations. Try to reuse as\nmuch of the above proof idea as possible, proceeding mechanically. -/\n\nlemma binomial_square\u2082 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/-! 2.3. Prove the same lemma again, this time using tactics. -/\n\nlemma binomial_square\u2083 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nbegin\n  sorry\nend\n\n\n/-! ## Question 3 (**optional**): One-Point Rules\n\n3.1 (**optional**). Prove that the following wrong formulation of the one-point\nrule for `\u2200` is inconsistent, using a structured proof. -/\n\naxiom forall.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2200x : \u03b1, x = t \u2227 p x) \u2194 p t\n\nlemma proof_of_false :\n  false :=\nsorry\n\n/-! 3.2 (**optional**). Prove that the following wrong formulation of the\none-point rule for `\u2203` is inconsistent, using a tactical or structured proof. -/\n\naxiom exists.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2203x : \u03b1, x = t \u2192 p x) \u2194 p t\n\nlemma proof_of_false\u2082 :\n  false :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2022", "sha": "5aee593fbef9b63d4338288b4789d85851d258aa", "save_path": "github-repos/lean/blanchette-logical_verification_2022", "path": "github-repos/lean/blanchette-logical_verification_2022/logical_verification_2022-5aee593fbef9b63d4338288b4789d85851d258aa/lean/love03_forward_proofs_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7368470633615383}}
{"text": "/-\nCopyright (c) 2020 Hanting Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hanting Zhang\n-/\nimport data.polynomial.splits\nimport ring_theory.mv_polynomial.symmetric\n\n/-!\n# Vieta's Formula\n\nThe main result is `multiset.prod_X_add_C_eq_sum_esymm`, which shows that the product of\nlinear terms `X + \u03bb` with `\u03bb` in a `multiset s` is equal to a linear combination of the\nsymmetric functions `esymm s`.\n\nFrom this, we deduce `mv_polynomial.prod_X_add_C_eq_sum_esymm` which is the equivalent formula\nfor the product of linear terms `X + X i` with `i` in a `fintype \u03c3` as a linear combination\nof the symmetric polynomials `esymm \u03c3 R j`.\n\nFor `R` be an integral domain (so that `p.roots` is defined for any `p : R[X]` as a multiset),\nwe derive `polynomial.coeff_eq_esymm_roots_of_card`, the relationship between the coefficients and\nthe roots of `p` for a polynomial `p` that splits (i.e. having as many roots as its degree).\n-/\n\nopen_locale big_operators polynomial\n\nnamespace multiset\n\nopen polynomial\n\nsection semiring\n\nvariables {R : Type*} [comm_semiring R]\n\n/-- A sum version of Vieta's formula for `multiset`: the product of the linear terms `X + \u03bb` where\n`\u03bb` runs through a multiset `s` is equal to a linear combination of the symmetric functions\n`esymm s` of the `\u03bb`'s .-/\nlemma prod_X_add_C_eq_sum_esymm (s : multiset R) :\n  (s.map (\u03bb r, X + C r)).prod =\n  \u2211 j in finset.range (s.card + 1), C (s.esymm j) * X ^ (s.card - j) :=\nbegin\n  classical,\n  rw [prod_map_add, antidiagonal_eq_map_powerset, map_map, \u2190bind_powerset_len, function.comp,\n    map_bind, sum_bind, finset.sum_eq_multiset_sum, finset.range_val, map_congr (eq.refl _)],\n  intros _ _,\n  rw [esymm, \u2190sum_hom', \u2190sum_map_mul_right, map_congr (eq.refl _)],\n  intros _ ht,\n  rw mem_powerset_len at ht,\n  simp [ht, map_const, prod_replicate, prod_hom', map_id', card_sub],\nend\n\n/-- Vieta's formula for the coefficients of the product of linear terms `X + \u03bb` where `\u03bb` runs\nthrough a multiset `s` : the `k`th coefficient is the symmetric function `esymm (card s - k) s`. -/\n\n\nlemma prod_X_add_C_coeff' {\u03c3} (s : multiset \u03c3) (r : \u03c3 \u2192 R) {k : \u2115} (h : k \u2264 s.card) :\n  (s.map (\u03bb i, X + C (r i))).prod.coeff k = (s.map r).esymm (s.card - k) :=\nby rw [\u2190 map_map (\u03bb r, X + C r) r, prod_X_add_C_coeff]; rwa s.card_map r\n\nlemma _root_.finset.prod_X_add_C_coeff {\u03c3} (s : finset \u03c3) (r : \u03c3 \u2192 R) {k : \u2115} (h : k \u2264 s.card) :\n  (\u220f i in s, (X + C (r i))).coeff k = \u2211 t in s.powerset_len (s.card - k), \u220f i in t, r i :=\nby { rw [finset.prod, prod_X_add_C_coeff' _ r h, finset.esymm_map_val], refl }\n\nend semiring\n\nsection ring\n\nvariables {R : Type*} [comm_ring R]\n\nlemma esymm_neg (s : multiset R) (k : \u2115) :\n  (map has_neg.neg s).esymm k = (-1) ^ k * esymm s k :=\nbegin\n  rw [esymm, esymm, \u2190multiset.sum_map_mul_left, multiset.powerset_len_map, multiset.map_map,\n    map_congr (eq.refl _)],\n  intros x hx,\n  rw [(by { exact (mem_powerset_len.mp hx).right.symm }), \u2190prod_replicate, \u2190multiset.map_const],\n  nth_rewrite 2 \u2190map_id' x,\n  rw [\u2190prod_map_mul, map_congr (eq.refl _)],\n  exact \u03bb z _, neg_one_mul z,\nend\n\nlemma prod_X_sub_C_eq_sum_esymm (s : multiset R) :\n  (s.map (\u03bb t, X - C t)).prod =\n  \u2211 j in finset.range (s.card + 1), (-1) ^ j * (C (s.esymm j) * X ^ (s.card - j)) :=\nbegin\n  conv_lhs { congr, congr, funext, rw sub_eq_add_neg, rw \u2190map_neg C _, },\n  convert prod_X_add_C_eq_sum_esymm (map (\u03bb t, -t) s) using 1,\n  { rwa map_map, },\n  { simp only [esymm_neg, card_map, mul_assoc, map_mul, map_pow, map_neg, map_one], },\nend\n\nlemma prod_X_sub_C_coeff (s : multiset R) {k : \u2115} (h : k \u2264 s.card) :\n  (s.map (\u03bb t, X - C t)).prod.coeff k = (-1) ^ (s.card - k) * s.esymm (s.card - k) :=\nbegin\n  conv_lhs { congr, congr, congr, funext, rw sub_eq_add_neg, rw \u2190map_neg C _, },\n  convert prod_X_add_C_coeff (map (\u03bb t, -t) s) _ using 1,\n  { rwa map_map, },\n  { rwa [esymm_neg, card_map] },\n  { rwa card_map },\nend\n\n/-- Vieta's formula for the coefficients and the roots of a polynomial over an integral domain\n  with as many roots as its degree. -/\ntheorem _root_.polynomial.coeff_eq_esymm_roots_of_card [is_domain R] {p : R[X]}\n  (hroots : p.roots.card = p.nat_degree) {k : \u2115} (h : k \u2264 p.nat_degree) :\n  p.coeff k = p.leading_coeff * (-1) ^ (p.nat_degree - k) * p.roots.esymm (p.nat_degree - k) :=\nbegin\n  conv_lhs { rw \u2190 C_leading_coeff_mul_prod_multiset_X_sub_C hroots },\n  rw [coeff_C_mul, mul_assoc], congr,\n  convert p.roots.prod_X_sub_C_coeff _ using 3; rw hroots, exact h,\nend\n\n/-- Vieta's formula for split polynomials over a field. -/\ntheorem _root_.polynomial.coeff_eq_esymm_roots_of_splits {F} [field F] {p : F[X]}\n  (hsplit : p.splits (ring_hom.id F)) {k : \u2115} (h : k \u2264 p.nat_degree) :\n  p.coeff k = p.leading_coeff * (-1) ^ (p.nat_degree - k) * p.roots.esymm (p.nat_degree - k) :=\npolynomial.coeff_eq_esymm_roots_of_card (splits_iff_card_roots.1 hsplit) h\n\nend ring\n\nend multiset\n\nsection mv_polynomial\n\nopen finset polynomial fintype\n\nvariables (R \u03c3 : Type*) [comm_semiring R] [fintype \u03c3]\n\n/-- A sum version of Vieta's formula for `mv_polynomial`: viewing `X i` as variables,\nthe product of linear terms `\u03bb + X i` is equal to a linear combination of\nthe symmetric polynomials `esymm \u03c3 R j`. -/\nlemma mv_polynomial.prod_C_add_X_eq_sum_esymm :\n  \u220f i : \u03c3, (X + C (mv_polynomial.X i)) =\n  \u2211 j in range (card \u03c3 + 1), (C (mv_polynomial.esymm \u03c3 R j) * X ^ (card \u03c3 - j)) :=\nbegin\n  let s := finset.univ.val.map (\u03bb i : \u03c3, mv_polynomial.X i),\n  rw (_ : card \u03c3 = s.card),\n  { simp_rw [mv_polynomial.esymm_eq_multiset_esymm \u03c3 R, finset.prod_eq_multiset_prod],\n    convert multiset.prod_X_add_C_eq_sum_esymm s,\n    rwa multiset.map_map, },\n  { rw multiset.card_map, refl, }\nend\n\nlemma mv_polynomial.prod_X_add_C_coeff (k : \u2115) (h : k \u2264 card \u03c3) :\n  (\u220f i : \u03c3, (X + C (mv_polynomial.X i))).coeff k = mv_polynomial.esymm \u03c3 R (card \u03c3 - k) :=\nbegin\n  let s := finset.univ.val.map (\u03bb i, (mv_polynomial.X i : mv_polynomial \u03c3 R)),\n  rw (_ : card \u03c3 = s.card) at \u22a2 h,\n  { rw [mv_polynomial.esymm_eq_multiset_esymm \u03c3 R, finset.prod_eq_multiset_prod],\n    convert multiset.prod_X_add_C_coeff s h,\n    rwa multiset.map_map },\n  repeat { rw multiset.card_map, refl, },\nend\n\nend mv_polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/polynomial/vieta.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.736757662930108}}
{"text": "/-\nCopyright (c) 2022 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport data.nat.log\nimport algebra.order.floor\nimport algebra.field_power\n\n/-!\n# Integer logarithms in a field with respect to a natural base\n\nThis file defines two `\u2124`-valued analogs of the logarithm of `r : R` with base `b : \u2115`:\n\n* `int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `\u2191b^k \u2264 r`.\n* `int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r \u2264 \u2191b^k`.\n\nNote that `int.log` gives the position of the left-most non-zero digit:\n```lean\n#eval (int.log 10 (0.09 : \u211a), int.log 10 (0.10 : \u211a), int.log 10 (0.11 : \u211a))\n--    (-2,                    -1,                    -1)\n#eval (int.log 10 (9 : \u211a),    int.log 10 (10 : \u211a),   int.log 10 (11 : \u211a))\n--    (0,                     1,                     1)\n```\nwhich means it can be used for computing digit expansions\n```lean\nimport data.fin.vec_notation\n\ndef digits (b : \u2115) (q : \u211a) (n : \u2115) : \u2115 :=\n\u230aq*b^(\u2191n - int.log b q)\u230b\u208a % b\n\n#eval digits 10 (1/7) \u2218 (coe : fin 8 \u2192 \u2115)\n-- ![1, 4, 2, 8, 5, 7, 1, 4]\n```\n\n## Main results\n\n* For `int.log`:\n  * `int.zpow_log_le_self`, `int.lt_zpow_succ_log_self`: the bounds formed by `int.log`,\n    `(b : R) ^ log b r \u2264 r < (b : R) ^ (log b r + 1)`.\n  * `int.zpow_log_gi`: the galois coinsertion between `zpow` and `int.log`.\n* For `int.clog`:\n  * `int.zpow_pred_clog_lt_self`, `int.self_le_zpow_clog`: the bounds formed by `int.clog`,\n    `(b : R) ^ (clog b r - 1) < r \u2264 (b : R) ^ clog b r`.\n  * `int.clog_zpow_gi`:  the galois insertion between `int.clog` and `zpow`.\n* `int.neg_log_inv_eq_clog`, `int.neg_clog_inv_eq_log`: the link between the two definitions.\n\n-/\nvariables {R : Type*} [linear_ordered_field R] [floor_ring R]\n\nnamespace int\n\n/-- The greatest power of `b` such that `b ^ log b r \u2264 r`. -/\ndef log (b : \u2115) (r : R) : \u2124 :=\nif 1 \u2264 r then\n  nat.log b \u230ar\u230b\u208a\nelse\n  -nat.clog b \u2308r\u207b\u00b9\u2309\u208a\n\nlemma log_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : log b r = nat.log b \u230ar\u230b\u208a :=\nif_pos hr\n\nlemma log_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : log b r = -nat.clog b \u2308r\u207b\u00b9\u2309\u208a :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [log, if_pos hr, inv_one, nat.ceil_one, nat.floor_one, nat.log_one_right, nat.clog_one_right,\n        int.coe_nat_zero, neg_zero], },\n  { exact if_neg hr.not_le }\nend\n\n@[simp, norm_cast] lemma log_nat_cast (b : \u2115) (n : \u2115) : log b (n : R) = nat.log b n :=\nbegin\n  cases n,\n  { simp [log_of_right_le_one _ _, nat.log_zero_right] },\n  { have : 1 \u2264 (n.succ : R) := by simp,\n    simp [log_of_one_le_right _ this, \u2190nat.cast_succ] }\nend\n\nlemma log_of_left_le_one {b : \u2115} (hb : b \u2264 1) (r : R) : log b r = 0 :=\nbegin\n  cases le_total 1 r,\n  { rw [log_of_one_le_right _ h, nat.log_of_left_le_one hb, int.coe_nat_zero] },\n  { rw [log_of_right_le_one _ h, nat.clog_of_left_le_one hb, int.coe_nat_zero, neg_zero] },\nend\n\nlemma log_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : log b r = 0 :=\nby rw [log_of_right_le_one _ (hr.trans zero_le_one),\n    nat.clog_of_right_le_one ((nat.ceil_eq_zero.mpr $ inv_nonpos.2 hr).trans_le zero_le_one),\n    int.coe_nat_zero, neg_zero]\n\nlemma zpow_log_le_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) :\n  (b : R) ^ log b r \u2264 r :=\nbegin\n  cases le_total 1 r with hr1 hr1,\n  { rw log_of_one_le_right _ hr1,\n    refine le_trans _ (nat.floor_le hr.le),\n    rw [zpow_coe_nat, \u2190nat.cast_pow, nat.cast_le],\n    exact nat.pow_log_le_self hb (nat.floor_pos.mpr hr1) },\n  { rw [log_of_right_le_one _ hr1, zpow_neg, zpow_coe_nat, \u2190 nat.cast_pow],\n    apply inv_le_of_inv_le hr,\n    refine (nat.le_ceil _).trans (nat.cast_le.2 _),\n    exact nat.le_pow_clog hb _ },\nend\n\nlemma lt_zpow_succ_log_self {b : \u2115} (hb : 1 < b) (r : R) :\n  r < (b : R) ^ (log b r + 1) :=\nbegin\n  cases le_or_lt r 0 with hr hr,\n  { rw [log_of_right_le_zero _ hr, zero_add, zpow_one],\n    exact hr.trans_lt (zero_lt_one.trans_le $ by exact_mod_cast hb.le) },\n  cases le_or_lt 1 r with hr1 hr1,\n  { rw log_of_one_le_right _ hr1,\n    rw [int.coe_nat_add_one_out, zpow_coe_nat, \u2190nat.cast_pow],\n    apply nat.lt_of_floor_lt,\n    exact nat.lt_pow_succ_log_self hb _, },\n  { rw log_of_right_le_one _ hr1.le,\n    have hcri : 1 < r\u207b\u00b9 := one_lt_inv hr hr1,\n    have : 1 \u2264 nat.clog b \u2308r\u207b\u00b9\u2309\u208a :=\n      nat.succ_le_of_lt (nat.clog_pos hb $ nat.one_lt_cast.1 $ hcri.trans_le (nat.le_ceil _)),\n    rw [neg_add_eq_sub, \u2190neg_sub, \u2190int.coe_nat_one, \u2190 int.coe_nat_sub this,\n      zpow_neg, zpow_coe_nat, lt_inv hr (pow_pos (nat.cast_pos.mpr $ zero_lt_one.trans hb) _),\n      \u2190nat.cast_pow],\n    refine nat.lt_ceil.1 _,\n    exact (nat.pow_pred_clog_lt_self hb $ nat.one_lt_cast.1 $ hcri.trans_le $ nat.le_ceil _), }\nend\n\n@[simp] lemma log_zero_right (b : \u2115) : log b (0 : R) = 0 :=\nlog_of_right_le_zero b le_rfl\n\n@[simp] lemma log_one_right (b : \u2115) : log b (1 : R) = 0 :=\nby rw [log_of_one_le_right _ le_rfl, nat.floor_one, nat.log_one_right, int.coe_nat_zero]\n\nlemma log_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : log b (b ^ z : R) = z :=\nbegin\n  obtain \u27e8n, rfl | rfl\u27e9 := z.eq_coe_or_neg,\n  { rw [log_of_one_le_right _ (one_le_zpow_of_nonneg _ $ int.coe_nat_nonneg _),\n      zpow_coe_nat, \u2190nat.cast_pow, nat.floor_coe, nat.log_pow hb],\n    exact_mod_cast hb.le, },\n  { rw [log_of_right_le_one _ (zpow_le_one_of_nonpos _ $ neg_nonpos.mpr (int.coe_nat_nonneg _)),\n      zpow_neg, inv_inv, zpow_coe_nat, \u2190nat.cast_pow, nat.ceil_coe, nat.clog_pow _ _ hb],\n    exact_mod_cast hb.le, },\nend\n\n@[mono] lemma log_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) :\n  log b r\u2081 \u2264 log b r\u2082 :=\nbegin\n  cases le_or_lt b 1 with hb hb,\n  { rw [log_of_left_le_one hb, log_of_left_le_one hb], },\n  cases le_total r\u2081 1 with h\u2081 h\u2081; cases le_total r\u2082 1 with h\u2082 h\u2082,\n  { rw [log_of_right_le_one _ h\u2081, log_of_right_le_one _ h\u2082, neg_le_neg_iff, int.coe_nat_le],\n    exact nat.clog_mono_right _ (nat.ceil_mono $ inv_le_inv_of_le h\u2080 h), },\n  { rw [log_of_right_le_one _ h\u2081, log_of_one_le_right _ h\u2082],\n    exact (neg_nonpos.mpr (int.coe_nat_nonneg _)).trans (int.coe_nat_nonneg _) },\n  { obtain rfl := le_antisymm h (h\u2082.trans h\u2081), refl, },\n  { rw [log_of_one_le_right _ h\u2081, log_of_one_le_right _ h\u2082, int.coe_nat_le],\n    exact nat.log_mono_right (nat.floor_mono h), },\nend\n\nvariables (R)\n\n/-- Over suitable subtypes, `zpow` and `int.log` form a galois coinsertion -/\ndef zpow_log_gi {b : \u2115} (hb : 1 < b) :\n  galois_coinsertion\n    (\u03bb z : \u2124, subtype.mk ((b : R) ^ z) $ zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z)\n    (\u03bb r : set.Ioi (0 : R), int.log b (r : R)) :=\ngalois_coinsertion.monotone_intro\n  (\u03bb r\u2081 r\u2082, log_mono_right r\u2081.prop)\n  (\u03bb z\u2081 z\u2082 hz, subtype.coe_le_coe.mp $ (zpow_strict_mono $ by exact_mod_cast hb).monotone hz)\n  (\u03bb r, subtype.coe_le_coe.mp $ zpow_log_le_self hb r.prop)\n  (\u03bb _, log_zpow hb _)\n\nvariables {R}\n\n/-- `zpow b` and `int.log b` (almost) form a Galois connection. -/\nlemma lt_zpow_iff_log_lt {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  r < (b : R) ^ x \u2194 log b r < x :=\n@galois_connection.lt_iff_lt _ _ _ _ _ _ (zpow_log_gi R hb).gc x \u27e8r, hr\u27e9\n\n/-- `zpow b` and `int.log b` (almost) form a Galois connection. -/\nlemma zpow_le_iff_le_log {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  (b : R) ^ x \u2264 r \u2194 x \u2264 log b r :=\n@galois_connection.le_iff_le _ _ _ _ _ _ (zpow_log_gi R hb).gc x \u27e8r, hr\u27e9\n\n/-- The least power of `b` such that `r \u2264 b ^ log b r`. -/\ndef clog (b : \u2115) (r : R) : \u2124 :=\nif 1 \u2264 r then\n  nat.clog b \u2308r\u2309\u208a\nelse\n  -nat.log b \u230ar\u207b\u00b9\u230b\u208a\n\nlemma clog_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : clog b r = nat.clog b \u2308r\u2309\u208a :=\nif_pos hr\n\nlemma clog_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : clog b r = -nat.log b \u230ar\u207b\u00b9\u230b\u208a :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [clog, if_pos hr, inv_one, nat.ceil_one, nat.floor_one, nat.log_one_right,\n        nat.clog_one_right, int.coe_nat_zero, neg_zero], },\n  { exact if_neg hr.not_le }\nend\n\nlemma clog_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : clog b r = 0 :=\nbegin\n  rw [clog, if_neg (hr.trans_lt zero_lt_one).not_le, neg_eq_zero, int.coe_nat_eq_zero,\n    nat.log_eq_zero_iff],\n  cases le_or_lt b 1 with hb hb,\n  { exact or.inr hb },\n  { refine or.inl (lt_of_le_of_lt _ hb),\n    exact nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one) },\nend\n\n@[simp] lemma clog_inv (b : \u2115) (r : R) : clog b r\u207b\u00b9 = -log b r :=\nbegin\n  cases lt_or_le 0 r with hrp hrp,\n  { obtain hr | hr := le_total 1 r,\n    { rw [clog_of_right_le_one _ (inv_le_one hr), log_of_one_le_right _ hr, inv_inv] },\n    { rw [clog_of_one_le_right _ (one_le_inv hrp hr),  log_of_right_le_one _ hr, neg_neg] }, },\n  { rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero], },\nend\n\n@[simp] lemma log_inv (b : \u2115) (r : R) : log b r\u207b\u00b9 = -clog b r :=\nby rw [\u2190inv_inv r, clog_inv, neg_neg, inv_inv]\n\n-- note this is useful for writing in reverse\nlemma neg_log_inv_eq_clog (b : \u2115) (r : R) : -log b r\u207b\u00b9 = clog b r :=\nby rw [log_inv, neg_neg]\n\nlemma neg_clog_inv_eq_log (b : \u2115) (r : R) : -clog b r\u207b\u00b9 = log b r :=\nby rw [clog_inv, neg_neg]\n\n@[simp, norm_cast] lemma clog_nat_cast (b : \u2115) (n : \u2115) : clog b (n : R) = nat.clog b n :=\nbegin\n  cases n,\n  { simp [clog_of_right_le_one _ _, nat.clog_zero_right] },\n  { have : 1 \u2264 (n.succ : R) := by simp,\n    simp [clog_of_one_le_right _ this, \u2190nat.cast_succ] }\nend\n\nlemma clog_of_left_le_one {b : \u2115} (hb : b \u2264 1) (r : R) : clog b r = 0 :=\nby rw [\u2190neg_log_inv_eq_clog, log_of_left_le_one hb, neg_zero]\n\nlemma self_le_zpow_clog {b : \u2115} (hb : 1 < b) (r : R) : r \u2264 (b : R) ^ clog b r :=\nbegin\n  cases le_or_lt r 0 with hr hr,\n  { rw [clog_of_right_le_zero _ hr, zpow_zero],\n    exact hr.trans zero_le_one },\n  rw [\u2190neg_log_inv_eq_clog, zpow_neg, le_inv hr (zpow_pos_of_pos _ _)],\n  { exact zpow_log_le_self hb (inv_pos.mpr hr), },\n  { exact nat.cast_pos.mpr (zero_le_one.trans_lt hb), },\nend\n\nlemma zpow_pred_clog_lt_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) :\n  (b : R) ^ (clog b r - 1) < r :=\nbegin\n  rw [\u2190neg_log_inv_eq_clog, \u2190neg_add', zpow_neg, inv_lt (zpow_pos_of_pos _ _) hr],\n  { exact lt_zpow_succ_log_self hb _, },\n  { exact nat.cast_pos.mpr (zero_le_one.trans_lt hb), },\nend\n\n@[simp] lemma clog_zero_right (b : \u2115) : clog b (0 : R) = 0 :=\nclog_of_right_le_zero _ le_rfl\n\n@[simp] lemma clog_one_right (b : \u2115) : clog b (1 : R) = 0 :=\nby rw [clog_of_one_le_right _ le_rfl, nat.ceil_one, nat.clog_one_right, int.coe_nat_zero]\n\nlemma clog_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : clog b (b ^ z : R) = z :=\nby rw [\u2190neg_log_inv_eq_clog, \u2190zpow_neg, log_zpow hb, neg_neg]\n\n@[mono] lemma clog_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) :\n  clog b r\u2081 \u2264 clog b r\u2082 :=\nbegin\n  rw [\u2190neg_log_inv_eq_clog, \u2190neg_log_inv_eq_clog, neg_le_neg_iff],\n  exact log_mono_right (inv_pos.mpr $ h\u2080.trans_le h) (inv_le_inv_of_le h\u2080 h),\nend\n\nvariables (R)\n/-- Over suitable subtypes, `int.clog` and `zpow` form a galois insertion -/\ndef clog_zpow_gi {b : \u2115} (hb : 1 < b) :\n  galois_insertion\n    (\u03bb r : set.Ioi (0 : R), int.clog b (r : R))\n    (\u03bb z : \u2124, \u27e8(b : R) ^ z, zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z\u27e9) :=\ngalois_insertion.monotone_intro\n  (\u03bb z\u2081 z\u2082 hz, subtype.coe_le_coe.mp $ (zpow_strict_mono $ by exact_mod_cast hb).monotone hz)\n  (\u03bb r\u2081 r\u2082, clog_mono_right r\u2081.prop)\n  (\u03bb r, subtype.coe_le_coe.mp $ self_le_zpow_clog hb _)\n  (\u03bb _, clog_zpow hb _)\nvariables {R}\n\n/-- `int.clog b` and `zpow b` (almost) form a Galois connection. -/\n\n\n/-- `int.clog b` and `zpow b` (almost) form a Galois connection. -/\nlemma le_zpow_iff_clog_le {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  r \u2264 (b : R) ^ x \u2194 clog b r \u2264 x :=\n(@galois_connection.le_iff_le _ _ _ _ _ _ (clog_zpow_gi R hb).gc \u27e8r, hr\u27e9 x).symm\n\nend int\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/int/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7367534678060867}}
{"text": "import tactic.basic\nimport .ch07_indprop\n\n/-\nCheck nat_ind.\n-/\n\n#check nat.rec_on\n\nopen nat\n\n/-\nTheorem mult_0_r' : \u2200n:nat,\n  n * 0 = 0.\nProof.\n  apply nat_ind.\n  - (* n = O *) reflexivity.\n  - (* n = S n' *) simpl. intros n' IHn'. rewrite \u2192 IHn'.\n    reflexivity. Qed.\n-/\n\ntheorem mult_0_r' (n) : n * 0 = 0 :=\nbegin\n  apply n.rec_on,\n    refl,\n  intros n' ih,\n  /- i tried to get the ih in -/\n  rw succ_mul,\n  rw ih,\nend\n\n/-\nTheorem plus_one_r' : \u2200n:nat,\n  n + 1 = S n.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem plus_on_r' (n) : n + 1 = succ n :=\nbegin\n  apply n.rec_on,\n    refl,\n  intros n' ih,\n  rw \u2190ih,\nend\n\n/-\nInductive yesno : Type :=\n  | yes\n  | no.\n\nCheck yesno_ind.\n(* ===> yesno_ind : forall P : yesno -> Prop,\n                      P yes  ->\n                      P no  ->\n                      forall y : yesno, P y *)\n-/\n\ninductive yesno\n| yes\n| no\n\n#check yesno.rec_on\n\n/-\nInductive rgb : Type :=\n  | red\n  | green\n  | blue.\n\nCheck rgb_ind.\n-/\n\ninductive rgb'\n| red\n| green\n| blue\n\n#check rgb.rec_on\n\n/-\nInductive natlist : Type :=\n  | nnil\n  | ncons (n : nat) (l : natlist).\n\nCheck natlist_ind.\n(* ===> (modulo a little variable renaming)\n   natlist_ind :\n      forall P : natlist -> Prop,\n         P nnil  ->\n         (forall (n : nat) (l : natlist),\n            P l -> P (ncons n l)) ->\n         forall n : natlist, P n *)\n-/\n\ninductive natlist\n| nnil\n| ncons (n : \u2115) (l : natlist)\n\n#check natlist.rec_on\n\n/-\nInductive natlist1 : Type :=\n  | nnil1\n  | nsnoc1 (l : natlist1) (n : nat).\n-/\n\ninductive natlist\u2081\n| nnil\u2081\n| nsnoc\u2081 (l : natlist\u2081) (n : \u2115)\n\n#check natlist\u2081.rec_on\n\n/-\nInductive byntree : Type :=\n | bempty\n | bleaf (yn : yesno)\n | nbranch (yn : yesno) (t1 t2 : byntree).\n-/\n\ninductive byntree\n| bempty\n| bleaf (yn : yesno)\n| nbranch (yn : yesno) (t\u2081 t\u2082 : byntree)\n\n#check byntree.rec_on\n\n/-\nInductive ExSet : Type :=\n  (* FILL IN HERE *)\n.\n-/\n\ninductive ExSet\n| con\u2081 (b : bool)\n| con\u2082 (n : \u2115) (e : ExSet)\n\n#check ExSet.rec_on\n\n/-\nInductive list (X:Type) : Type :=\n        | nil : list X\n        | cons : X \u2192 list X \u2192 list X.\n-/\n\ninductive list' (\u03b1 : Type)\n| nil : list'\n| cons : \u03b1 \u2192 list' \u2192 list'\n\n#check list'.rec_on\n\n/-\nInductive tree (X:Type) : Type :=\n  | leaf (x : X)\n  | node (t1 t2 : tree X).\n\nCheck tree_ind.\n-/\n\ninductive tree (\u03b1 : Type)\n| leaf (a : \u03b1) : tree\n| node (t\u2081 t\u2082 : tree) : tree\n\n#check tree.rec_on\n\ninductive mytype_ind (\u03b1 : Type)\n| constr\u2081 (a : \u03b1) : mytype_ind\n| constr\u2082 (n : \u2115) : mytype_ind\n| constr\u2083 (m : mytype_ind) (n : \u2115) : mytype_ind\n\n#check mytype_ind.rec_on\n\ninductive foo (\u03b1 \u03b2 : Type)\n| bar (a : \u03b1) : foo\n| baz (b : \u03b2) : foo\n| quux (f\u2081 : \u2115 \u2192 foo) : foo\n\n#check foo.rec_on\n\n/-\nInductive foo' (X:Type) : Type :=\n  | C1 (l : list X) (f : foo' X)\n  | C2.\n-/\n\ninductive foo' (\u03b1 : Type)\n| C\u2081 (l : list \u03b1) (f : foo') : foo'\n| C\u2082 : foo'\n\n#check foo'.rec_on\n\n/-\nDefinition P_m0r (n:nat) : Prop :=\n  n * 0 = 0.\n-/\n\ndef P_m0r (n) := n * 0 = 0\n\n/-\nDefinition P_m0r' : nat\u2192Prop :=\n  fun n \u21d2 n * 0 = 0.\n-/\n\ndef P_m0r' := \u03bbn, n * 0 = 0\n\n/-\nTheorem mult_0_r'' : \u2200n:nat,\n  P_m0r n.\nProof.\n  apply nat_ind.\n  - (* n = O *) reflexivity.\n  - (* n = S n' *)\n    (* Note the proof state at this point! *)\n    intros n IHn.\n    unfold P_m0r in IHn. unfold P_m0r. simpl. apply IHn. Qed.\n-/\n\ntheorem mult_0_r'' (n) : P_m0r n :=\nbegin\n  apply n.rec_on,\n    unfold P_m0r,\n    refl,\n  intros n ih,\n  unfold P_m0r at ih,\n  unfold P_m0r,\n  rw succ_mul,\n  apply ih,\nend\n\n/-\nTheorem plus_assoc' : \u2200n m p : nat,\n  n + (m + p) = (n + m) + p.\nProof.\n  (* ...we first introduce all 3 variables into the context,\n     which amounts to saying \"Consider an arbitrary n, m, and\n     p...\" *)\n  intros n m p.\n  (* ...We now use the induction tactic to prove P n (that\n     is, n + (m + p) = (n + m) + p) for _all_ n,\n     and hence also for the particular n that is in the context\n     at the moment. *)\n  induction n as [| n'].\n  - (* n = O *) reflexivity.\n  - (* n = S n' *)\n    (* In the second subgoal generated by induction -- the\n       \"inductive step\" -- we must prove that P n' implies\n       P (S n') for all n'.  The induction tactic\n       automatically introduces n' and P n' into the context\n       for us, leaving just P (S n') as the goal. *)\n    simpl. rewrite \u2192 IHn'. reflexivity. Qed.\n-/\n\ntheorem plus_assoc''' (n m p : \u2115)\n  : n + (m + p) = ((n + m) + p) :=\nbegin\n  induction n with n' ih,\n    repeat { rw zero_add, },\n  rw succ_add,\n  rw ih,\n  repeat { rw \u2190succ_add, },\nend\n\n/-\nTheorem plus_comm' : \u2200n m : nat,\n  n + m = m + n.\nProof.\n  induction n as [| n'].\n  - (* n = O *) intros m. rewrite <- plus_n_O. reflexivity.\n  - (* n = S n' *) intros m. simpl. rewrite \u2192 IHn'.\n    rewrite <- plus_n_Sm. reflexivity. Qed.\n-/\n\n/- does not work in lean -/\n-- theorem plus_comm'\n--   : \u2200n m : \u2115, n + m = m + n :=\n-- begin\n--   induction n with n' ih,\n-- end\n\n/-\nTheorem plus_comm'' : \u2200n m : nat,\n  n + m = m + n.\nProof.\n  (* Let's do induction on m this time, instead of n... *)\n  induction m as [| m'].\n  - (* m = O *) simpl. rewrite <- plus_n_O. reflexivity.\n  - (* m = S m' *) simpl. rewrite <- IHm'.\n    rewrite <- plus_n_Sm. reflexivity. Qed.\n-/\n\n/- does not work in lean -/\n\ndef p_assoc (n m p : \u2115)\n  := n + (m + p) = ((n + m) + p)\n\ntheorem plus_assoc'''' (n m p) : p_assoc n m p :=\nbegin\n  induction n with n' ih,\n    unfold p_assoc,\n    repeat { rw zero_add },\n  unfold p_assoc at *,\n  rw [succ_add, ih, \u2190succ_add, \u2190succ_add],\nend\n\ndef p_comm (n m : \u2115) := n + m = m + n\n\ntheorem plus_comm' (n m) : p_comm n m :=\nbegin\n  induction n with n' ih generalizing m,\n    unfold p_comm,\n    rw zero_add,\n    refl,\n  unfold p_comm at *,\n  rw [succ_add, ih],\nend\n\n/-\nInductive even : nat \u2192 Prop :=\n    | ev_0 : even 0\n    | ev_SS : \u2200n : nat, even n \u2192 even (S (S n)).\n-/\n\ninductive even''' : \u2115 \u2192 Prop\n| ev_0 : even''' 0\n| ev_SS : \u2200n, even''' n \u2192 even''' (succ (succ n))\n\n#check even.rec_on\n\ntheorem even'''_even'' {n} (h: even''' n) : even'' n :=\nbegin\n  apply h.rec_on,\n    exact even''.even''_0,\n  intros n hn ih,\n  exact even''.even''_sum n 2 ih (even''.even''_2),\nend\n\ninductive le' (n : \u2115) : \u2115 \u2192 Prop\n| le_n : le' n\n| le_S (m) (h : le' m) : le' (succ m)\n\n#check le.rec_on\n#check le'.rec_on\n", "meta": {"author": "michens", "repo": "learn-lean", "sha": "f38fc342780ddff5a164a18e5482163dea506ccd", "save_path": "github-repos/lean/michens-learn-lean", "path": "github-repos/lean/michens-learn-lean/learn-lean-f38fc342780ddff5a164a18e5482163dea506ccd/sf/v1/ch12_indprinciples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677699040321, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.7367371081997554}}
{"text": "/-\nCopyright (c) 2022. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Moritz Firsching, Fabian Kruse, Nikolas Kuhn\n-/\nimport analysis.p_series\nimport analysis.special_functions.log.deriv\n\n/-!\n# Stirling's formula\n\nThis file proves Theorem 90 from the [100 Theorem List] <https://www.cs.ru.nl/~freek/100/>.\nIt states that $n!$ grows asymptotically like $\\sqrt{2\\pi n}(\\frac{n}{e})^n$.\nTODO: Add Part 2 to complete the proof\n\n## Proof outline\n\nThe proof follows: <https://proofwiki.org/wiki/Stirling%27s_Formula>.\n\n### Part 1\nWe consider the fraction sequence $a_n$ of fractions $n!$ over $\\sqrt{2n}(\\frac{n}{e})^n$ and\nproves that this sequence converges against a real, positve number $a$. For this the two main\ningredients are\n - taking the logarithm of the sequence and\n - use the series expansion of $\\log(1 + x)$.\n-/\n\nopen_locale topological_space big_operators\nopen finset filter nat real\n\nnamespace stirling\n\n/-!\n ### Part 1\n https://proofwiki.org/wiki/Stirling%27s_Formula#Part_1\n-/\n\n/--\nDefine `stirling_seq n` as $\\frac{n!}{\\sqrt{2n}/(\\frac{n}{e})^n$.\nStirling's formula states that this sequence has limit $\\sqrt(\u03c0)$.\n-/\nnoncomputable def stirling_seq (n : \u2115) : \u211d :=\nn.factorial / (sqrt (2 * n) * (n / exp 1) ^ n)\n\n/-- Define `log_stirling_seq n` as the log of `stirling_seq n`. -/\nnoncomputable def log_stirling_seq (n : \u2115) : \u211d := log (stirling_seq n)\n\n/--\nWe have the expression\n`log_stirling_seq (n + 1) = log(n + 1)! - 1 / 2 * log(2 * n) - n * log ((n + 1) / e)`.\n-/\nlemma log_stirling_seq_formula (n : \u2115) : log_stirling_seq n.succ =\n  log n.succ.factorial - 1 / 2 * log (2 * n.succ) - n.succ * log (n.succ / exp 1) :=\nbegin\n  have h3, from sqrt_ne_zero'.mpr (mul_pos two_pos $ cast_pos.mpr (succ_pos n)),\n  have h4 : 0 \u2260 ((n.succ : \u211d) / exp 1) ^ n.succ, from\n    ne_of_lt (pow_pos (div_pos (cast_pos.mpr n.succ_pos ) (exp_pos 1)) n.succ),\n  rw [log_stirling_seq, stirling_seq, log_div, log_mul, sqrt_eq_rpow, log_rpow, log_pow],\n  { linarith },\n  { refine (zero_lt_mul_left two_pos).mpr _,\n    rw \u2190cast_zero,\n    exact cast_lt.mpr (succ_pos n), },\n  { exact h3, },\n  { exact h4.symm, },\n  { exact cast_ne_zero.mpr n.succ.factorial_ne_zero, },\n  { apply (mul_ne_zero h3 h4.symm), },\nend\n\n/--\nThe sequence `log_stirling_seq (m + 1) - log_stirling_seq (m + 2)` has the series expansion\n   `\u2211 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))`\n-/\nlemma log_stirling_seq_diff_has_sum (m : \u2115) :\n  has_sum (\u03bb k : \u2115, (1 : \u211d) / (2 * k.succ + 1) * ((1 / (2 * m.succ + 1)) ^ 2) ^ k.succ)\n  (log_stirling_seq m.succ - log_stirling_seq m.succ.succ) :=\nbegin\n  change\n    has_sum ((\u03bb b : \u2115, 1 / (2 * (b : \u211d) + 1) * ((1 / (2 * m.succ + 1)) ^ 2) ^ b) \u2218 succ) _,\n  rw has_sum_nat_add_iff 1,\n  convert (has_sum_log_one_add_inv $ cast_pos.mpr (succ_pos m)).mul_left ((m.succ : \u211d) + 1 / 2),\n  { ext k,\n    rw [\u2190 pow_mul, pow_add],\n    push_cast,\n    have : 2 * (k : \u211d) + 1 \u2260 0, {norm_cast, exact succ_ne_zero (2*k)},\n    have : 2 * ((m : \u211d) + 1) + 1 \u2260 0, {norm_cast, exact succ_ne_zero (2*m.succ)},\n    field_simp,\n    ring },\n  { have h : \u2200 (x : \u211d) (hx : x \u2260 0), 1 + x\u207b\u00b9 = (x + 1) / x,\n    { intros, rw [_root_.add_div, div_self hx, inv_eq_one_div], },\n    simp only [log_stirling_seq_formula, log_div, log_mul, log_exp, factorial_succ, cast_mul,\n      cast_succ, cast_zero, range_one, sum_singleton, h] { discharger :=\n      `[norm_cast, apply_rules [mul_ne_zero, succ_ne_zero, factorial_ne_zero, exp_ne_zero]] },\n    ring },\n  { apply_instance }\nend\n\n/-- The sequence `log_stirling_seq \u2218 succ` is monotone decreasing -/\nlemma log_stirling_seq'_antitone : antitone (log_stirling_seq \u2218 succ) :=\nbegin\n  apply antitone_nat_of_succ_le,\n  intro n,\n  rw [\u2190 sub_nonneg, \u2190 succ_eq_add_one],\n  refine (log_stirling_seq_diff_has_sum n).nonneg _,\n  norm_num,\n  simp only [one_div],\n  intro m,\n  refine mul_nonneg _ _,\n  all_goals {refine inv_nonneg.mpr _, norm_cast, exact (zero_le _)},\nend\n\n/--\nWe have the bound  `log_stirling_seq n - log_stirling_seq (n+1) \u2264 1/(2n+1)^2* 1/(1-(1/2n+1)^2)`.\n-/\nlemma log_stirling_seq_diff_le_geo_sum (n : \u2115) :\n  log_stirling_seq n.succ - log_stirling_seq n.succ.succ \u2264\n  (1 / (2 * n.succ + 1)) ^ 2 / (1 - (1 / (2 * n.succ + 1)) ^ 2) :=\nbegin\n  have h_nonneg : 0 \u2264 ((1 / (2 * (n.succ : \u211d) + 1)) ^ 2),\n  { rw [cast_succ, one_div, inv_pow, inv_nonneg], norm_cast, exact zero_le', },\n  have g : has_sum (\u03bb k : \u2115, ((1 / (2 * (n.succ : \u211d) + 1)) ^ 2) ^ k.succ)\n    ((1 / (2 * n.succ + 1)) ^ 2 / (1 - (1 / (2 * n.succ + 1)) ^ 2)),\n  { have h_pow_succ := \u03bb k : \u2115,\n      symm (pow_succ ((1 / (2 * ((n : \u211d) + 1) + 1)) ^ 2) k),\n    have hlt : (1 / (2 * (n.succ : \u211d) + 1)) ^ 2 < 1,\n    { simp only [cast_succ, one_div, inv_pow],\n      refine inv_lt_one _,\n      norm_cast,\n      simp only [nat.one_lt_pow_iff, ne.def, zero_eq_bit0, nat.one_ne_zero, not_false_iff,\n        lt_add_iff_pos_left, canonically_ordered_comm_semiring.mul_pos, succ_pos', and_self], },\n    exact (has_sum_geometric_of_lt_1 h_nonneg hlt).mul_left ((1 / (2 * (n.succ : \u211d) + 1)) ^ 2) },\n  have hab : \u2200 (k : \u2115), (1 / (2 * (k.succ : \u211d) + 1)) * ((1 / (2 * n.succ + 1)) ^ 2) ^ k.succ \u2264\n    ((1 / (2 * n.succ + 1)) ^ 2) ^ k.succ,\n  { intro k,\n    have h_zero_le : 0 \u2264 ((1 / (2 * (n.succ : \u211d) + 1)) ^ 2) ^ k.succ := pow_nonneg h_nonneg _,\n    have h_left : 1 / (2 * (k.succ : \u211d) + 1) \u2264 1,\n    { rw [cast_succ, one_div],\n      refine inv_le_one _,\n      norm_cast,\n      exact (le_add_iff_nonneg_left 1).mpr zero_le', },\n    exact mul_le_of_le_one_left h_zero_le h_left, },\n  exact has_sum_le hab (log_stirling_seq_diff_has_sum n) g,\nend\n\n/--\nWe have the bound  `log_stirling_seq n - log_stirling_seq (n+1)` \u2264 1/(4 n^2)\n-/\nlemma log_stirling_seq_sub_log_stirling_seq_succ (n : \u2115) :\n  log_stirling_seq n.succ - log_stirling_seq n.succ.succ \u2264 1 / (4 * n.succ ^ 2) :=\nbegin\n  have h\u2081 : 0 < 4 * ((n : \u211d) + 1) ^ 2 := by nlinarith [@cast_nonneg \u211d _ n],\n  have h\u2083 : 0 < (2 * ((n : \u211d) + 1) + 1) ^ 2 := by nlinarith [@cast_nonneg \u211d _ n],\n  have h\u2082 : 0 < 1 - (1 / (2 * ((n : \u211d) + 1) + 1)) ^ 2,\n  { rw \u2190 mul_lt_mul_right h\u2083,\n    have H : 0 < (2 * ((n : \u211d) + 1) + 1) ^ 2 - 1 := by nlinarith [@cast_nonneg \u211d _ n],\n    convert H using 1; field_simp [h\u2083.ne'] },\n  refine (log_stirling_seq_diff_le_geo_sum n).trans _,\n  push_cast at *,\n  rw div_le_div_iff h\u2082 h\u2081,\n  field_simp [h\u2083.ne'],\n  rw div_le_div_right h\u2083,\n  ring_nf,\n  norm_cast,\n  linarith,\nend\n\n/-- For any `n`, we have `log_stirling_seq 1 - log_stirling_seq n \u2264 1/4 * \u2211' 1/k^2`  -/\nlemma log_stirling_seq_bounded_aux :\n  \u2203 (c : \u211d), \u2200 (n : \u2115), log_stirling_seq 1 - log_stirling_seq n.succ \u2264 c :=\nbegin\n  let d := \u2211' k : \u2115, (1 : \u211d) / k.succ ^ 2,\n  use (1 / 4 * d : \u211d),\n  let log_stirling_seq' : \u2115 \u2192 \u211d := \u03bb k : \u2115, log_stirling_seq k.succ,\n  intro n,\n  calc\n  log_stirling_seq 1 - log_stirling_seq n.succ = log_stirling_seq' 0 - log_stirling_seq' n : rfl\n  ... = \u2211 k in range n, (log_stirling_seq' k - log_stirling_seq' (k + 1)) : by\n    rw \u2190 sum_range_sub' log_stirling_seq' n\n  ... \u2264 \u2211 k in range n, (1/4) * (1 / k.succ^2) : by\n  { apply sum_le_sum,\n    intros k hk,\n    convert log_stirling_seq_sub_log_stirling_seq_succ k using 1,\n    field_simp, }\n  ... = 1 / 4 * \u2211 k in range n, 1 / k.succ ^ 2 : by rw mul_sum\n  ... \u2264 1 / 4 * d : by\n  { refine (mul_le_mul_left _).mpr _, { exact one_div_pos.mpr four_pos, },\n    refine sum_le_tsum (range n) (\u03bb k _, _)\n      ((summable_nat_add_iff 1).mpr (real.summable_one_div_nat_pow.mpr one_lt_two)),\n    apply le_of_lt,\n    rw one_div_pos,\n    rw sq_pos_iff,\n    exact nonzero_of_invertible \u2191(succ k), },\nend\n\n/-- The sequence `log_stirling_seq` is bounded below for `n \u2265 1`. -/\nlemma log_stirling_seq_bounded_by_constant : \u2203 c, \u2200 (n : \u2115), c \u2264 log_stirling_seq n.succ :=\nbegin\n  obtain \u27e8d, h\u27e9 := log_stirling_seq_bounded_aux,\n  use log_stirling_seq 1 - d,\n  intro n,\n  exact sub_le.mp (h n),\nend\n\n/-- The sequence `stirling_seq` is positive for `n > 0`  -/\nlemma stirling_seq'_pos (n : \u2115) : 0 < stirling_seq n.succ :=\nbegin\n  dsimp only [stirling_seq],\n  apply_rules [div_pos, cast_pos.mpr, mul_pos, factorial_pos, exp_pos, pow_pos, real.sqrt_pos.mpr,\n    two_pos, succ_pos] 7 {md := reducible}; apply_instance,\nend\n\n/--\nThe sequence `stirling_seq` has a positive lower bound.\n-/\nlemma stirling_seq'_bounded_by_pos_constant : \u2203 a, 0 < a \u2227 \u2200 n : \u2115, a \u2264 stirling_seq n.succ :=\nbegin\n  cases log_stirling_seq_bounded_by_constant with c h,\n  refine \u27e8exp c, exp_pos _, \u03bb n, _\u27e9,\n  rw \u2190 le_log_iff_exp_le (stirling_seq'_pos n),\n  exact h n,\nend\n\n/-- The sequence `stirling_seq \u2218 succ` is monotone decreasing -/\nlemma stirling_seq'_antitone : antitone (stirling_seq \u2218 succ) :=\n\u03bb n m h, (log_le_log (stirling_seq'_pos m) (stirling_seq'_pos n)).mp (log_stirling_seq'_antitone h)\n\n/-- The limit `a` of the sequence `stirling_seq` satisfies `0 < a` -/\nlemma stirling_seq_has_pos_limit_a :\n  \u2203 (a : \u211d), 0 < a \u2227 tendsto stirling_seq at_top (\ud835\udcdd a) :=\nbegin\n  obtain \u27e8x, x_pos, hx\u27e9 := stirling_seq'_bounded_by_pos_constant,\n  have hx' : x \u2208 lower_bounds (set.range (stirling_seq \u2218 succ)) := by simpa [lower_bounds] using hx,\n  refine \u27e8_, lt_of_lt_of_le x_pos (le_cInf (set.range_nonempty _) hx'), _\u27e9,\n  rw \u2190filter.tendsto_add_at_top_iff_nat 1,\n  exact tendsto_at_top_cinfi stirling_seq'_antitone \u27e8x, hx'\u27e9,\nend\n\nend stirling\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/special_functions/stirling.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276107, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7367371025056311}}
{"text": "/-\nCopyright (c) 2014 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthors: Floris van Doorn, Jeremy Avigad\nDistance function on the natural numbers.\n-/\nimport data.nat.basic\n\nnamespace nat\n\n/- distance -/\n\n/-- Distance (absolute value of difference) between natural numbers. -/\ndef dist (n m : \u2115) := (n - m) + (m - n)\n\ntheorem dist.def (n m : \u2115) : dist n m = (n - m) + (m - n) := rfl\n\n@[simp] theorem dist_comm (n m : \u2115) : dist n m = dist m n :=\nby simp [dist.def]\n\n@[simp] theorem dist_self (n : \u2115) : dist n n = 0 :=\nby simp [dist.def, nat.sub_self]\n\ntheorem eq_of_dist_eq_zero {n m : \u2115} (h : dist n m = 0) : n = m :=\nhave n - m = 0, from eq_zero_of_add_eq_zero_right h,\nhave n \u2264 m, from nat.le_of_sub_eq_zero this,\nhave m - n = 0, from eq_zero_of_add_eq_zero_left h,\nhave m \u2264 n, from nat.le_of_sub_eq_zero this,\nle_antisymm \u2039n \u2264 m\u203a \u2039m \u2264 n\u203a\n\ntheorem dist_eq_zero {n m : \u2115} (h : n = m) : dist n m = 0 :=\nbegin rw [h, dist_self] end\n\ntheorem dist_eq_sub_of_le {n m : \u2115} (h : n \u2264 m) : dist n m = m - n :=\nbegin rw [dist.def, sub_eq_zero_of_le h, zero_add] end\n\ntheorem dist_eq_sub_of_ge {n m : \u2115} (h : n \u2265 m) : dist n m = n - m :=\nbegin rw [dist_comm], apply dist_eq_sub_of_le h end\n\ntheorem dist_zero_right (n : \u2115) : dist n 0 = n :=\neq.trans (dist_eq_sub_of_ge (zero_le n)) (nat.sub_zero n)\n\ntheorem dist_zero_left (n : \u2115) : dist 0 n = n :=\neq.trans (dist_eq_sub_of_le (zero_le n)) (nat.sub_zero n)\n\ntheorem dist_add_add_right (n k m : \u2115) : dist (n + k) (m + k) = dist n m :=\ncalc\n  dist (n + k) (m + k) = ((n + k) - (m + k)) + ((m + k)-(n + k)) : rfl\n                   ... = (n - m) + ((m + k) - (n + k))   : by rw nat.add_sub_add_right\n                   ... = (n - m) + (m - n)               : by rw nat.add_sub_add_right\n\ntheorem dist_add_add_left (k n m : \u2115) : dist (k + n) (k + m) = dist n m :=\nbegin rw [add_comm k n, add_comm k m], apply dist_add_add_right end\n\ntheorem dist_eq_intro {n m k l : \u2115} (h : n + m = k + l) : dist n k = dist l m :=\ncalc\n  dist n k = dist (n + m) (k + m) : by rw dist_add_add_right\n       ... = dist (k + l) (k + m) : by rw h\n       ... = dist l m             : by rw dist_add_add_left\n\nprotected theorem sub_lt_sub_add_sub (n m k : \u2115) : n - k \u2264 (n - m) + (m - k) :=\nor.elim (le_total k m)\n  (assume : k \u2264 m,\n    begin rw \u2190nat.add_sub_assoc this, apply nat.sub_le_sub_right, apply nat.le_sub_add end)\n  (assume : k \u2265 m,\n    begin rw [sub_eq_zero_of_le this, add_zero], apply nat.sub_le_sub_left, exact this end)\n\ntheorem dist.triangle_inequality (n m k : \u2115) : dist n k \u2264 dist n m + dist m k :=\nhave dist n m + dist m k = (n - m) + (m - k) + ((k - m) + (m - n)), by simp [dist.def],\nbegin\n  rw [this, dist.def], apply add_le_add, repeat { apply nat.sub_lt_sub_add_sub }\nend\n\ntheorem dist_mul_right (n k m : \u2115) : dist (n * k) (m * k) = dist n m * k :=\nby rw [dist.def, dist.def, right_distrib, nat.mul_sub_right_distrib, nat.mul_sub_right_distrib]\n\ntheorem dist_mul_left (k n m : \u2115) : dist (k * n) (k * m) = k * dist n m :=\nby rw [mul_comm k n, mul_comm k m, dist_mul_right, mul_comm]\n\n-- TODO(Jeremy): do when we have max and minx\n--theorem dist_eq_max_sub_min {i j : nat} : dist i j = (max i j) - min i j :=\n--sorry\n/-\nor.elim (lt_or_ge i j)\n  (assume : i < j,\n    by rw [max_eq_right_of_lt this, min_eq_left_of_lt this, dist_eq_sub_of_lt this])\n  (assume : i \u2265 j,\n    by rw [max_eq_left this , min_eq_right this, dist_eq_sub_of_ge this])\n-/\n\ntheorem dist_succ_succ {i j : nat} : dist (succ i) (succ j) = dist i j :=\nby simp [dist.def, succ_sub_succ]\n\ntheorem dist_pos_of_ne {i j : nat} : i \u2260 j \u2192 dist i j > 0 :=\nassume hne, nat.lt_by_cases\n  (assume : i < j,\n     begin rw [dist_eq_sub_of_le (le_of_lt this)], apply nat.sub_pos_of_lt this end)\n  (assume : i = j, by contradiction)\n  (assume : i > j,\n     begin rw [dist_eq_sub_of_ge (le_of_lt this)], apply nat.sub_pos_of_lt this end)\n\nend nat\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/nat/dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.736737096287437}}
{"text": "/-\nFormalising Mathematics - Project 3\nBased on Number Theory module taken in term 1 of MSc in Pure Mathematics 2021-22\nSubmitted by: Additi Pandey \nCID: 02119403\n-/\n\n--We will first import the necessary mathlib libraries needed to proceed with the definitions and proofs. \nimport tactic \nimport data.int.modeq \nimport data.zmod.basic \nimport data.int.gcd \nimport init.data.int.basic\nimport data.nat.prime \nimport algebra.big_operators.finprod \nimport number_theory.divisors \n\n/-!\n## Number Theory Problem - Reflexive and Corpulent Integers\nThis file is based on a problem in the Number Theory past paper for Year 3/4. The question\ndeals with a integer `n` which is said to be:\n* Reflexive - If two conditions are equivalent, that is, if `\u2200 a,b \u2208 \u2124` with `(a,b) = 1` then,\n `a \u2261 b (mod n)` and `a*b \u2261 1 (mod n)`.\n* Corpulent - If `\u2200 a \u2208 \u2124` with `(a,n)=1`, `a^2 \u2261 1 (mod n)`. \nThe aim is to first show that `n` is reflexive \u2194 `n` is corpulent and then show that if `n` is \ncorpulent then all prime divisors of `n` are also corpulent. -/\n\n/-- Definition of Reflexive Number: An integer `1 \u2264 n` is reflexive if for all integers `a b` with \n`a.gcd b = 1`, the following two conditions are equivalent:\n(i) `a \u2261 b (mod n)`. \n(ii) `a * b \u2261 1 (mod n)`.-/\ndef reflexiv {n : \u2115} (hn : 1 \u2264 n) :=\n(\u2200 {a b : \u2124} (h : a.gcd b = 1),  a \u2261 b [ZMOD n] \u2194 a * b \u2261 1 [ZMOD n])\n\n/-\nHence, `reflexiv` defines a integer `n` which is `1 \u2264 n` as reflexive. To define a natural \nnumber `n` as corpulent, a `def` called `corpulent` is defined as :\n-/\n\n/--Definition of Corpulent Number: An integer `1 \u2264 n` is corpulent if for all integers `a` with \n`a.gcd n = 1`, we have `a^2 \u2261 1 (mod n)`.-/\ndef corpulent {n : \u2115} (hn : 1 \u2264 n) :=\n( \u2200 {a : \u2124} (han : a.gcd n = 1), a^2  \u2261 1 [ZMOD n])\n\n/-\nWe now declare the global variables `n` and `m` so that if they are used anywhere in the file,\nLean knows that they are in `\u2115` and `1 \u2264 n`.\n-/\nvariables  {n : \u2115} (hn : 1 \u2264 n) {m : \u2115}\n\n/- \nTo proceed with the proof of \"`n` is reflexive \u2194 `n` is corpulent\", there was a requirement of a\nlemma called  `int.gcd_add_self_left (m n : \u2124) : m.gcd (m + n) = m.gcd n` which says that:\nif `m` and `n` are two integers then `gcd(m,m+n)` is same as the `gcd(m,n)`. So to show this,\nProfessor Kevin Buzzard defined `int.nat_abs_def` which says that if an integer `a \u2265 0` then it \nis defined as `a` or else it is less than `0` and is defined as `-a`. He proceeded to further \ndefine `int.add_nat_abs` which defines `(a+b).nat_abs`, `a.nat_abs` and `b.nat_abs` and defined \n`int.gcd_add_self_right` which helped in defining `int.nat_add_self_left` by applying `add_comm`\nand `gcd_comm` on the already proven `int.gcd_add_self_left` theorem. \n-/\n\n/-- This theorem applies cases on `a` to show that if `a \u2265 0` then it is either `a` or `-a`. -/\ntheorem int.nat_abs_def (a : \u2124) : (a.nat_abs : \u2124) = if 0 \u2264 a then a else -a :=\nbegin\n  cases a,\n  { simp,},\n  { ring,},\nend\n\n/-- Defining integers and their sum in `nat_abs`, i.e. coercing from `\u2124` to `\u2115`. -/\ntheorem int.add_nat_abs (a b : \u2124) : \n  (a + b).nat_abs = a.nat_abs + b.nat_abs \u2228 \n  a.nat_abs = (a + b).nat_abs + b.nat_abs \u2228\n  b.nat_abs = (a + b).nat_abs + a.nat_abs :=\nbegin\n  zify,\n  simp [int.nat_abs_def],\n  split_ifs,\n  { left, ring, },\n  { right, left, ring, },\n  { right, right, ring, },\n  { linarith, },\n  { linarith, },\n  { right, right, ring, },\n  { right, left, ring, },\n  { left, ring },\nend\n\n/-- Given two integers `m` and `n`, show that `gcd(m,n+m) = gcd(m,n)`. -/\ntheorem int.gcd_add_self_right  (m n : \u2124) :\nm.gcd (n + m) = m.gcd n :=\nbegin\n  change (m.nat_abs).gcd (n + m).nat_abs = (m.nat_abs).gcd n.nat_abs,\n  rcases int.add_nat_abs n m with (h | h | h);\n  rw h,\n  { exact (int.nat_abs m).gcd_add_self_right (int.nat_abs n) },\n  { exact ((int.nat_abs m).gcd_add_self_right (n + m).nat_abs).symm },\n  { rw nat.gcd_add_self_left,\n    rw add_comm,\n    rw nat.gcd_add_self_left,\n    rw nat.gcd_comm },\nend\n\n/-- Using the above three theorems, I created a lemma that given integers `m` and `n`,\nthe  `gcd(m,m_n) = gcd(m,n)`. -/\n@[simp]lemma int.gcd_add_self_left (m n : \u2124) : m.gcd (m + n) = m.gcd n := \nbegin\n  change (m.nat_abs).gcd (m + n).nat_abs = (m.nat_abs).gcd n.nat_abs,\n  rcases int.add_nat_abs m n with (h | h | h);\n  rw h,\n  { exact (int.nat_abs m).gcd_self_add_right (int.nat_abs n),},\n  { rw nat.gcd_add_self_left,\n    rw add_comm,\n    rw nat.gcd_add_self_left,\n    rw nat.gcd_comm,},\n  { rw add_comm,\n    exact ((int.nat_abs m).gcd_add_self_right (n + m).nat_abs).symm,},\nend\n\n/-\nHaving defined `int.gcd_add_self_left`, there are two other lemmas needed that will help in \nproving that an integer  `1 \u2264 n` is reflexive \u2194 `1 \u2264 n` is corpulent. The first lemma is called\n`gcd_sn_given_t_s` which gives the gcd of two numbers `s` and `n` (where `s` is an integer and since,\n`n` is such that `1 \u2264 n`, the number `n` is defined as `n : \u2115`), when `t \u2261 s [ZMOD n]` and `gcd(s,t) = 1`.\nThis lemma has been proven by contradiction as it did not involve dealing with integer divisions, which \nis a harder and lesser efficient approach.\nAfter this, there is a lemma  `gcd_sn_given_st` defined, which by its name tells that given `gcd(s,t) = 1`\nand `s*t \u2261 1 [ZMOD n]`, the `gcd(s,n) = 1`. Again, I proved this by contradiction, as it was easier\nto avoid integer division in this method, which tends to be more pathological. \n-/\n\n/-- Given `gcd(s,t) = 1` and `t \u2261 s [ZMOD n]`, show that `gcd(s,n) = 1`. -/\nlemma gcd_sn_given_t_s {s t : \u2124} {n : \u2115} (hp : t \u2261 s [ZMOD n]): (s.gcd t) = 1 \u2192 (s.gcd n) = 1 := \nbegin\n  intro hst,\n  --We will now proceed by contradiction. \n  apply of_not_not, \n  intro hk,\n  set d :=  (s.gcd n) with hd, -- Letting `d` to be the `gcd (s, n)`.\n  -- Since `d` is the `gcd (s,n) \u2192 d \u2223 s \u2227 d \u2223 n`.\n  have h1: (d : \u2124) \u2223 s, \n  { apply int.gcd_dvd_left s n,},\n  have h2: (d : \u2124) \u2223 n,\n  { apply int.gcd_dvd_right s n,},\n  -- Since `d \u2223 s \u2192 s = d * p`, for some `(p : \u2124)` and similarly, `\u2191n = \u2191d * q`, for some `(q : \u2124)`.\n  have h12: \u2203 (p : \u2124), s = d * p,\n  { assumption,},\n  have h22 :  \u2203 (q : \u2124), \u2191n = \u2191d * q,\n  { assumption, },\n  -- We have `t \u2261 s [ZMOD n]`, so `\u2191n \u2223 (t - s)` and since, `d \u2223 n`, we have `d \u2223 (t - s)`.\n  have h4 : \u2191 n \u2223 (t - s),\n  { apply int.modeq.dvd,\n    exact hp.symm,},\n  have h5' : (d : \u2124) \u2223 (t - s),\n  { cases h22 with c hc,\n    exact dvd_trans h2 h4,},\n  -- The previous hypothesis imply that `d \u2223 s` and `d \u2223 t` but we already have `h1` for former. \n  have h5: (d : \u2124) \u2223 t,\n  { exact (dvd_iff_dvd_of_dvd_sub h5').mpr h1,},\n  have h6: \u2191 d \u2223 \u2191 (s.gcd t), -- Since `d` divides both `s` and `t`, it should divide their gcd.\n  { apply int.dvd_gcd h1 h5,},\n  rw hst at h6, -- The `gcd (s,t) = 1` \n  norm_cast at *, \n  -- `d \u2223 1` so `d = 1` but we assumed it is `\u2260 1`, hence, a contradiction!\n  finish,\nend\n\n/-- Given `gcd(s,t) = 1` and `s * t \u2261 1 [ZMOD n]`, show that `gcd(s,n) = 1`. -/\n@[simp]lemma gcd_sn_given_st {s t : \u2124}{n : \u2115} (hp : s * t \u2261 1 [ZMOD n]) : s.gcd n = 1 := \nbegin\n  -- As there was no use of `gcd(s,t) = 1` in the proof, I omitted it from the definition of lemma. \n  -- We will proceed by contradiction. \n  apply of_not_not, -- Assume that the `gcd(s,n) \u2260 1`.\n  intro hk,\n  set d :=  (s.gcd n) with hd, -- Let `d` be the `gcd (s,n)`.\n  -- Clearly `d \u2223 s` and `d \u2223 n`.\n  have h1: (d : \u2124) \u2223 s, \n  { apply int.gcd_dvd_left s n,},\n  have h2: (d : \u2124) \u2223 n,\n  { apply int.gcd_dvd_right s n,},\n  -- Given `s * t \u2261 1 [ZMOD n] \u2192 \u2191n \u2223 (s*t -1)`.\n  have h3: \u2191 n \u2223 (s * t - 1) ,\n  { apply int.modeq.dvd,\n    apply hp.symm,},\n  rw dvd_iff_exists_eq_mul_left at h3,\n  -- With `h3` now, we can express `s * t - 1` in terms of `n`.\n  have h3' : \u2203 (c : \u2124), s * t - n * c = 1,\n  { cases h3 with k hk,\n    use k,\n    rw mul_comm \u2191 n k,\n    linarith,},\n  -- Since `d \u2223 s` and `d \u2223 n`, `d` should divide their linear combination. \n  have h4: \u2203 (c : \u2124), \u2191 d \u2223 (s * t - n * c),\n  { cases h1 with x hx,\n    cases h2 with y hy,\n    cases h3 with k hk,\n    rw hx,\n    rw hy,\n    use k,\n    rw [mul_assoc, mul_assoc],\n    rw \u2190 mul_sub (\u2191d) (x*t) (y * k),\n    simp,},\n  have hs : \u2200 (c : \u2124), \u2191 d \u2223 s * c,\n  { apply dvd_mul_of_dvd_left h1,},\n  have hn : \u2200 (c : \u2124), \u2191 d \u2223 \u2191 n * c,\n  { apply dvd_mul_of_dvd_left h2,},\n  -- Since `\u2200 c` in \u2124,  `d \u2223 s * c` , `d` will divide `s * t` where `t` is an integer. \n  have hs_ : \u2191 d \u2223 s * t,\n  { apply hs,},\n  have hn_ : \u2203 (c : \u2124), \u2191d \u2223 \u2191n * c,\n  { tauto,},\n  -- Since `d` divides `s * t - \u2191n * c` so it will divide `1` as well by `h3`.\n  have h5: \u2191 d \u2223 (1 : \u2124),\n  { cases h3' with k hk,\n    rw \u2190 hk,\n    specialize hn k,\n    apply dvd_sub hs_ hn, },\n  norm_cast at *,\n  finish, -- `d \u2223 1` \u2192 `d = 1` and this imply that our claim that `d \u2260 1` is false.  \nend\n\n/-- Show that `n` is reflexive if and only if `n` is corpulent.-/\ntheorem reflexive_iff_corpulent : reflexiv hn \u2194 corpulent hn := \nbegin\n  split,\n  -- We will first prove the forward direction, i.e., `n` is reflexive \u2192 `n` is corpulent. \n    { unfold reflexiv, \n      unfold corpulent, \n      intros hp q hqn, \n      -- The goal now is to show that `q ^ 2 \u2261 1 [ZMOD \u2191n]`, given `n`, `hn`, `hp`, `q`, `hqn`.\n      have hp1 : q.gcd (q+n) = 1 \u2192 (q \u2261 (q+n) [ZMOD \u2191n] \u2194 q * (q+n) \u2261 1 [ZMOD \u2191n]),\n        { exact hp},\n      have hp2 : (q \u2261 q + \u2191n [ZMOD \u2191n] \u2194 q * (q + \u2191n) \u2261 1 [ZMOD \u2191n]),\n        { rw hp1, \n          simp,\n          rw hqn },\n      have hp3 : q * (q + \u2191n) \u2261 1 [ZMOD \u2191n],\n        { rw \u2190 hp2,\n          apply int.modeq.symm,\n          have h1 : q \u2261 q [ZMOD \u2191n] := int.modeq.rfl, \n          have h2 : \u2191n \u2261 0 [ZMOD \u2191n],\n          { rw int.modeq_zero_iff_dvd,},\n          conv\n            begin\n              to_rhs,\n              congr,\n              skip,\n              skip,\n              rw \u2190 add_zero q,\n            end,\n          apply int.modeq.add,\n          exact h1,\n          exact h2, },\n      have hp4: (q * \u2191n) \u2261 0 [ZMOD \u2191n],\n      { rw int.modeq,\n        simp only [int.mul_mod_left, euclidean_domain.zero_mod],},\n      have hp5 : q ^ 2 + (q * \u2191n) \u2261 1 [ZMOD \u2191n],\n      { have h: q * q = q ^ 2,\n        { ring,},\n        rw \u2190 h,\n        rw \u2190 mul_add,\n        exact hp3,},\n      set x := q + \u2191n with hx,\n      set y := q * \u2191n with hy,\n      have hp6: q ^ 2 + y - y \u2261 1 - 0 [ZMOD \u2191n],\n      { apply int.modeq.sub hp5 hp4,},\n      simp at hp6,\n      exact hp6,},\n  -- We will now prove the converse, i.e. `n` is corpulent \u2192 `n` is reflexive. \n    { unfold corpulent,\n      unfold reflexiv,\n      intros hp s t hst,\n      -- After unfolding the definitions of reflexive and corpulent, we observe that given\n      -- `n`, `hn`, `hp`, integers `s` and `t`, and a hypothesis `hst`, we need to show two \n      -- things to prove that `n` is reflexive. So, the goal now is `s \u2261 t [ZMOD \u2191n] \u2194 s * t \u2261 1 [ZMOD \u2191n]`.\n      split,\n      -- We will first show that given `s \u2261 t [ZMOD \u2191n] \u2192  s * t \u2261 1 [ZMOD \u2191n]`.\n      { intro hst_mod,\n        have h : t * t = t ^ 2,\n        { ring,},\n        have hts : t \u2261 s [ZMOD \u2191n],\n        { apply int.modeq.symm,\n          exact hst_mod,},\n        have htn : t.gcd n = 1,\n        { rwa gcd_sn_given_t_s hst_mod,\n          rwa int.gcd_comm,},\n        have ht: t * t \u2261 1 [ZMOD \u2191n],\n        { rw h,\n          apply hp,\n          exact htn,},\n        have hst : s * t \u2261 t * t [ZMOD \u2191n],\n        { apply int.modeq.mul_right t hst_mod,},\n        apply int.modeq.trans hst ht,},\n      -- We will now show that `s * t \u2261 1 [ZMOD \u2191n] \u2192 s \u2261 t [ZMOD \u2191n]`.\n      { intro h_st,\n        have hsn : s.gcd n = 1,\n        { rwa gcd_sn_given_st h_st,},\n        have hss : s^2 \u2261 1 [ZMOD \u2191n],\n        { apply hp,\n          exact hsn,},\n        have hs2 : s^2 = s * s,\n        { ring,},\n        have hs_modn : s * s \u2261 1 [ZMOD \u2191n],\n        { rw \u2190 hs2,\n          exact hss,},\n        have hst2 : s * s - s * t \u2261 1 - 1 [ZMOD \u2191n],\n        { apply int.modeq.sub hs_modn h_st,},\n        simp at hst2,\n        have hst_sub : s * (s - t) = s * s - s * t ,\n        { rw mul_sub,},\n        have hp_st_sub: s * (s-t) \u2261 0 [ZMOD \u2191n],\n        { rw hst_sub,\n          exact hst2,},\n        have hn_dvd_st: \u2191n \u2223 s * (s - t),\n        { set x := s * (s - t) with hx,\n          rwa \u2190 int.modeq_zero_iff_dvd,},\n        have hns_gcd : (n : \u2124).gcd s = 1,\n        { rw hsn.symm,\n          exact int.gcd_comm n s,},\n        have hn_dvd_st : \u2191n \u2223 (s - t),\n        { apply int.dvd_of_dvd_mul_right_of_gcd_one hn_dvd_st hns_gcd,},\n        have hts_modn: t \u2261 s [ZMOD \u2191n],\n        { apply int.modeq_of_dvd,\n          exact hn_dvd_st,},\n        apply int.modeq.symm ,\n        exact hts_modn,},},\n  -- Hence, we proved that `n` is reflexive \u2194 `n` is corpulent. \nend\n\n/-\nTo proceed with the next part of the project which is to prove that `n` is corpulent \u2194\n`m` is corpulent for every prime power `m` dividing `n`, I constructed a helper lemma called\n`na.coprime_lift`, which shows that units in `[ZMOD n]` are the units in `[ZMOD m]`. To do so,\nI constructed a `findprod f` called `x` to denote the product of all primes dividing `n` which \ndo not divide `b`, and `f` is a map from `nat.coprime_alpha` (which gives a condition on primes)\nto the set of integers, such that `b` is some integer such that \u2203 an `a\u2080 : \u2124` is coprime to `n` \nand `a\u2080 \u2261 b [ZMOD d]` where `d \u2223 n` and `gcd(b,d) = 1`.\n-/\n\n/-- Defining a subtype `nat.coprime_alpha` such that `\u2200 n,d \u2208 \u2115` and `b \u2208 \u2124`, there is a set of \nprimes `p` which divide `n` but do not divide `b`. -/\n@[nolint has_inhabited_instance] def nat.coprime_alpha (n : \u2115) (b : \u2124):\n  Type := { p : \u2115 // p\u2223n \u2227 \u00ac \u2191p\u2223b \u2227 p.prime}\n\n/-\nTo proceed with the proof, there are lemmas that need to be defined as below:\nThe lemmas `dvd_mem_gcd` and `dvd_mem_gcd` state that if there are integers `a` and `b` such that \nfor all primes that divide `a`, do not divide `b` or primes that do not divide `b` and divide `a`, \nthe `gcd(a,b) = 1`. The lemma `dvd_mem_dvd_sum` is a basic lemma stating that if a number does not \ndivide one or all of the members, then it does not divide their sum. The proof of the same is by \ncontradiction. \n-/\n\n/-- For some integers `a` and `b`, and `\u2200 (p : \u2115)` where `p` is prime and divides `a`, then `p` do \nnot divide `b \u2194 gcd (a,b) = 1`. -/\nlemma dvd_mem_gcd (a b : \u2124) : (\u2200 p : \u2115, p.prime \u2192 \u2191p \u2223 a \u2192 \u00ac \u2191p \u2223 b) \u2194 a.gcd b = 1 := \nbegin\n  split,\n  -- To show that: `a.gcd b = 1`\n  { intro hp,\n    -- We proceed by contradiction. \n    apply of_not_not,\n    set d:= a.gcd b with hd,\n    intro hpd,\n    have d_ne1 : d \u2260 1,\n    { exact hpd, },\n    -- If `a.gcd b` is not equal to `1` then there is a prime such that it divides the gcd. \n    have hprime_d : \u2203 (p : \u2115) , p.prime \u2227 p \u2223 d,\n    { rwa nat.ne_one_iff_exists_prime_dvd at d_ne1,},\n    -- Since the prime divides the `a.gcd b` \u2192 it divides `a` and `b`.\n    have hprime_a_b :\u2203 (p : \u2115) , p.prime \u2227 \u2191p \u2223 a \u2227 \u2191p \u2223 b,\n    {\n      cases hprime_d with p hprime,\n      use p,\n      have hd_a : (d : \u2124) \u2223 a,\n      {\n        exact int.gcd_dvd_left a b,\n      },\n      have hd_b : (d : \u2124) \u2223 b,\n      {\n        exact int.gcd_dvd_right a b,\n      },\n      split,\n      {exact hprime.1,},\n      { split,\n        { exact dvd_trans (int.coe_nat_dvd.mpr hprime.2) hd_a,},\n        {exact dvd_trans (int.coe_nat_dvd.mpr hprime.2) hd_b,},},},\n    finish,},\n    -- To show : `a.gcd b = 1 \u2192 \u2200 (p : \u2115), nat.prime p \u2192 \u2191p \u2223 a \u2192 \u00ac\u2191p \u2223 b`\n    { intros hp p hprime hp_a hp_b,\n      have hp_gcd : \u2191p \u2223 \u2191 (a.gcd b),\n      { apply int.dvd_gcd hp_a hp_b,},\n      rw hp at hp_gcd,\n      -- Since `p` divides `a` and `b` and also their gcd \u2192 `p \u2223 1` but a prime does \n      -- not divide `1`, hence, proved `a.gcd b = 1 \u2192 \u2200 (p : \u2115), nat.prime p \u2192 \u2191p \u2223 a \u2192 \u00ac\u2191p \u2223 b`\n      apply nat.prime.not_dvd_one hprime (int.coe_nat_dvd.mp hp_gcd),\n    },\nend\n\n/-- If `c` divides `a` and `c` does not divide `b`, then it does not divide their sum. -/\nlemma dvd_mem_dvd_sum (a b c: \u2124) : (c \u2223 a \u2227 \u00ac c \u2223 b) \u2192  \u00ac c \u2223 (a + b) := \nbegin\n  intros h_ab hp,\n  set d:= a.gcd b with hd,\n  have hc_a : c \u2223 a ,\n  { finish,},\n  have hc_b : c \u2223 ((a+b)-a),\n  { apply dvd_sub hp hc_a,},\n  simp at hc_b,\n  finish,\nend\n\n/-- Define a map from `nat.coprime_alpha` to the set of natural numbers. -/\ndef nat.coprime_alpha_id (n : \u2115) (b : \u2124) : nat.coprime_alpha n b \u2192 \u2115 := \u03bb p, p.1\n\n/-- To show that `f` is finite, where `f` is the map `nat.coprime_alpha_id`.-/\nlemma nat.coprime_alpha_finite (n : \u2115) (b : \u2124) (hn : 0 < n) : \n(function.mul_support (nat.coprime_alpha_id n b)).finite :=\nbegin\nshow set.finite {x : nat.coprime_alpha n b | nat.coprime_alpha_id n b x \u2260 1},\nunfold nat.coprime_alpha_id,\nhave t : {a : \u2115 | a \u2223 n} \u2286 {a : \u2115 | a \u2264 n},\n{ intro a, \n  apply nat.le_of_dvd hn,},\nhave k : fintype (n.coprime_alpha b),\n{ unfold nat.coprime_alpha,\n  show fintype \u21a5{p | p \u2223 n \u2227 \u00ac\u2191p \u2223 b \u2227 nat.prime p}, \n  apply set.finite.fintype,\n  rw [set.set_of_and, set.set_of_and],\n  apply set.finite.inter_of_left,\n  apply set.finite.subset (set.finite_le_nat _) t,},\napply @set.finite.of_fintype _ k _,\nend\n\n/-- Helper lemma to show that if `p \u2223 finprod f` then there is a `t` in `\u03b1` such that \n`p` divides that `t` in the product of `f t`-/\nlemma prime_dvd_finprod {\u03b1 : Type} (f : \u03b1 \u2192 \u2115) (hf : (function.mul_support f).finite) \n{p : \u2115} (hp : p.prime) : p \u2223 finprod f \u2194 \u2203 t : \u03b1, p \u2223 f t := sorry\n\n/-- This is a pre-existing mathlib lemma that says that if a prime number is divisible by a \nnatural number which is not `1`, then the number is the prime number itself. -/\nlemma nat.prime.dvd_iff_eq {p a : \u2115} (hp : p.prime) (a1 : a \u2260 1) : a \u2223 p \u2194 p = a := sorry\n\n/- Please note: The above stated lemma is already there in mathlib but since the addition was\nrecent (in the month of March itself), I am unable to use it in my file. Hence, I mentioned it\nhere. -/\n\n/-- Defining `nat.coprime_lift` which says that units in `[ZMOD n]` are units in `[ZMOD d]` where\n`d\u2223n` and here, the goal is to show that this map is surjective. Reference for the proof can be found\non the link : https://math.stackexchange.com/q/487022 -/\nlemma nat.coprime_lift {n d : \u2115} {b : \u2124}\n  (hn : 1 \u2264 n)\n  (hs : d \u2223 n)\n  (hyp : b.gcd \u2191d = 1) :\n  \u2203 a\u2080 : \u2124, a\u2080.gcd n = 1 \u2227 a\u2080 \u2261 b [ZMOD d] :=\nbegin\n  set f:= nat.coprime_alpha_id n b,\n  set x:= finprod f,\n  use (b + d * x),\n  have hyp' : (d : \u2124).gcd b = 1,\n  { rwa int.gcd_comm \u2191d b,},\n  split,\n  -- To first show that : `(b + \u2191d * \u2191x).gcd \u2191n = 1`\n  { set g:= (b + \u2191d * x).gcd \u2191n with hg,\n    have h1: \u2191g \u2223 \u2191n,\n    { apply int.gcd_dvd_right (b + \u2191d * x) \u2191n,},\n    have h2: \u2191g \u2223 (b + \u2191d * x),\n    { apply int.gcd_dvd_left (b + \u2191d * x) \u2191n,},\n    -- To show that: All primes that divide `n`, do not divide `(b + \u2191d * x)`:\n    have h3: \u2200 (p : \u2115), p.prime \u2227 p \u2223 n \u2192 \u00ac \u2191p \u2223 (b + \u2191d * x),\n      { intros p hp1 hp2,\n      by_cases (\u2191p \u2223 b),\n      -- To show if `p` divides `b` then it does not divide `(\u2191d * x)` hence, \n      -- does not divide `(b + \u2191d * x)`\n      { have h3_pd : \u00ac \u2191p \u2223 \u2191d,\n        { apply (dvd_mem_gcd b \u2191d).mpr hyp p hp1.1 h,}, \n        have h3_pd_nat : \u00ac p \u2223 d,\n        { intro ht, \n        have hkt: \u2191p \u2223 \u2191d,\n        {exact int.coe_nat_dvd.mpr ht,}, finish, },\n        have h3_px : \u00ac p \u2223 x,\n        { intro hpx,\n          change p \u2223 finprod f at hpx,\n          rw prime_dvd_finprod f (nat.coprime_alpha_finite n b hn) hp1.1 at hpx,\n          cases hpx with t ht,\n          change p \u2223 t.1 at ht,\n          set t_val2 := t.2,\n          have h3_t_ne1 : t.val \u2260 1,\n          { apply nat.prime.ne_one t_val2.2.2,},\n          have h_p_ne1 : p \u2260 1,\n          {apply nat.prime.ne_one hp1.1,},\n          have h3_tp : p = t.val,\n          { rw (nat.prime.dvd_iff_eq hp1.1 h3_t_ne1).mp,\n            rwa (nat.prime.dvd_iff_eq t_val2.2.2 h_p_ne1).mp,},\n          finish,},\n        have h3'_p : \u00ac p \u2223 (d * x),\n        { apply nat.prime.not_dvd_mul hp1.1 h3_pd_nat h3_px,},\n        have h3''_p :  \u00ac \u2191p \u2223 (d : \u2124) * x,\n        { norm_cast,\n          exact h3'_p,},\n        have h3_p : \u00ac \u2191p \u2223 (b + \u2191d * x) ,\n        { apply dvd_mem_dvd_sum b (\u2191d * x) \u2191p,\n          change \u00ac (p : \u2124) \u2223 \u2191d * \u2191x at h3''_p,\n          refine \u27e8h, h3''_p\u27e9,},\n        finish,},\n      -- To show if `p` does not divide `b` then it does not divide `(b + \u2191d * x)`.\n      { have h3' : p \u2223 x,\n        { show p \u2223 finprod f, \n         rw prime_dvd_finprod f (nat.coprime_alpha_finite n b hn) hp1.1,\n         use p,\n         finish,\n         finish,}, \n         have h3'' : \u2191 p \u2223 \u2191x,\n         {  exact int.coe_nat_dvd.mpr h3'},\n        have h3_p : \u00ac \u2191p \u2223 (\u2191d * \u2191x + b) ,\n        { apply dvd_mem_dvd_sum (\u2191d * x) b \u2191p, \n        split,\n        -- To show that `p` divides `(\u2191d * x)`.\n        { apply dvd_mul_of_dvd_right h3'' \u2191d,},\n        -- To show that `p` does not divide `b`.\n        {exact h,},},\n        have h3_p : \u00ac \u2191p \u2223 (b + \u2191d * x ),\n        { rwa add_comm at h3_p,},\n        -- Hence, we have a contradiction at `hp2` and `h3_p`. \n        finish,},},\n        -- We have shown that all primes `p` that divide `n`, do not divide `(b + \u2191d * x)`.\n        -- To show: (b + \u2191d * x).gcd n = 1\n        show (b + d * x).gcd n = 1,\n        have h3': \u2200 (p : \u2115), p.prime \u2192 (p : \u2124) \u2223 (n : \u2124) \u2192 \u00ac \u2191p \u2223 (b + \u2191d * x), \n        {intros p hp hs ht, rw int.coe_nat_dvd at hs, finish, },\n        rw \u2190 (dvd_mem_gcd n (b + d*x)).mp h3',\n        rw int.gcd_comm,},\n  -- To show that: `b + \u2191d * \u2191x \u2261 b [ZMOD \u2191d]`.\n  { rw int.modeq_iff_dvd,\n    simp only [dvd_neg, sub_add_cancel', dvd_mul_right],},\nend\n\n/- \nWe now have all the lemmas needed to prove the second theorem of the project, so we define the theorem\nas below and prove it by first unfolding our definitions and then using `nat.coprime_lift` and \n`int.modeq.modeq_of_dvd`, we get `a\u2080 ^ 2 \u2261 1 [ZMOD \u2191(p ^ e)]`. We will use this and `a\u2080 \u2261 b [ZMOD \u2191t]`\nto show that `b ^ 2 \u2261 1 [ZMOD \u2191(p ^ e)]` as follows:\n-/\n\n/--Show that `n` is corpulent if `m` is corpulent for every prime power `m|n` \n(i.e. for every divisor of `n` of the form `p^e` with `1 \u2264 e`).-/\ntheorem corpulent_two_int: corpulent hn \u2192  \u2200 {p e : \u2115} {hp : nat.prime p} {hm : (pow p e) \u2223 n} ,\n corpulent (pow_pos (nat.pos_of_ne_zero (nat.prime.ne_zero hp)) e) :=\nbegin\n  { unfold corpulent, \n    intros hp p e s hs,\n    unfold corpulent,\n    intros b hyp,\n    -- To show: `b ^ 2 \u2261 1 [ZMOD \u2191(p ^ e)]`, we can use `nat.coprime_lift` and draw a\n    -- connection between the units in `[ZMOD \u2191n]` and `[ZMOD \u2191(p ^ e)]`. \n    obtain \u27e8a\u2080, ha\u2080n, ha\u2080b\u27e9 := nat.coprime_lift hn hs hyp,\n    specialize @hp a\u2080 ha\u2080n,\n    set t:= (p ^ e) with ht,\n    -- Since we have that `t \u2223 n`, we can say that if `a\u2080 ^ 2 \u2261 1 [ZMOD \u2191n]` then \n    --`a\u2080 ^ 2 \u2261 1 [ZMOD \u2191(p ^ e)]`.\n    have ht: \u2191t \u2223 \u2191n,\n    { exact int.coe_nat_dvd.mpr hs, },\n    have hp' : a\u2080 ^ 2 \u2261 1 [ZMOD \u2191(p^e)],\n    { apply int.modeq.modeq_of_dvd ht hp, },\n    have hab : \u2191t \u2223 (a\u2080 - b),\n    { apply int.modeq.dvd ,\n      exact ha\u2080b.symm,},\n    rw dvd_iff_exists_eq_mul_left at hab,\n    -- Expressing `a\u2080` in terms of `\u2191t` and `b`, so that we can get an expression for `b` and `\u2191t`: \n    have h_ab: \u2203 (c : \u2124), a\u2080 = c * \u2191t + b,\n    { cases hab with k hk,\n      use k,\n      rw \u2190 mul_comm \u2191t k,\n      linarith, },\n    have h_ap : \u2191t \u2223 (a\u2080 ^ 2 - 1),\n    { apply int.modeq.dvd ,\n    exact hp'.symm, },\n    rw dvd_iff_exists_eq_mul_left at h_ap,\n    have h_bp : \u2203 (c k : \u2124), (c * \u2191t + b)^2 - 1 = k * \u2191t,\n    { cases h_ap with l hl,\n      cases h_ab with s hs,\n      use s,\n      use l,\n      rwa \u2190 hs, },\n      -- To show that in the expansion of `(c * \u2191t + b)^2` , all terms with `\u2191t` can be grouped together\n      -- and be expressed just as `g * \u2191t` for some integer `g`. \n    have helper : \u2203 (c k : \u2124), b ^ 2 - 1 = k * \u2191t - c ^ 2 * \u2191t ^ 2 - 2 * c * \u2191t * b,\n    { cases h_bp with x hx,\n      cases hx with y hy,\n      rw add_pow_two (x * \u2191t) (b) at hy,\n      use x, \n      use y,\n      apply eq_sub_of_add_eq',\n      apply eq_sub_of_add_eq',\n      rw (mul_pow x \u2191t 2).symm,\n      rw \u2190 add_assoc,\n      rw add_sub,\n      nth_rewrite 1 (mul_assoc),\n      exact hy,},\n    have h_bp' : \u2203 (g : \u2124), b^2 - 1 = g * \u2191t,\n    { cases helper with c hc,\n      cases hc with k hk,\n      use (k - c ^ 2 * \u2191t - 2 * c  * b),\n      rw mul_sub_right_distrib,\n      rw mul_sub_right_distrib,\n      rw hk,\n      ring, },\n    -- Since `\u2191t` divides `b^2 - 1`, we can say that `b^2 \u2261 1 [ZMOD \u2191t]`.\n    rw \u2190 dvd_iff_exists_eq_mul_left at h_bp',\n    have h_bp_mod : 1 \u2261 b^2 [ZMOD \u2191t],\n    { apply int.modeq_of_dvd, \n      exact h_bp',},\n    exact h_bp_mod.symm,},\nend\n\n\n#lint\n/-While there are the `unused_arguments` linter reports but I feel that they are really\nimportant to be a part of definition to maintain coherency, hence I did not remove them. -/\n\n", "meta": {"author": "cyclotomicextension", "repo": "Formalising-Mathematics-Project-3", "sha": "b05cf9ee5d3837918fea7758aee5409d0e4d3760", "save_path": "github-repos/lean/cyclotomicextension-Formalising-Mathematics-Project-3", "path": "github-repos/lean/cyclotomicextension-Formalising-Mathematics-Project-3/Formalising-Mathematics-Project-3-b05cf9ee5d3837918fea7758aee5409d0e4d3760/finalproject.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7367370909852242}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.pairing\n! leanprover-community/mathlib commit 207cfac9fcd06138865b5d04f7091e46d9320432\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Sqrt\nimport Mathlib.Data.Set.Lattice\nimport Mathlib.Algebra.Group.Prod\nimport Mathlib.Algebra.Order.Monoid.MinMax\n\n/-!\n#  Naturals pairing function\n\nThis file defines a pairing function for the naturals as follows:\n```text\n 0  1  4  9 16\n 2  3  5 10 17\n 6  7  8 11 18\n12 13 14 15 19\n20 21 22 23 24\n```\n\nIt has the advantage of being monotone in both directions and sending `\u27e60, n^2 - 1\u27e7` to\n`\u27e60, n - 1\u27e7\u00b2`.\n-/\n\n\nopen Prod Decidable Function\n\nnamespace Nat\n\n/-- Pairing function for the natural numbers. -/\n-- porting notes: no pp_nodot\n--@[pp_nodot]\ndef pair (a b : \u2115) : \u2115 :=\n  if a < b then b * b + a else a * a + a + b\n#align nat.mkpair Nat.pair\n\n/-- Unpairing function for the natural numbers. -/\n-- porting notes: no pp_nodot\n--@[pp_nodot]\ndef unpair (n : \u2115) : \u2115 \u00d7 \u2115 :=\n  let s := sqrt n\n  if n - s * s < s then (n - s * s, s) else (s, n - s * s - s)\n#align nat.unpair Nat.unpair\n\n@[simp]\ntheorem pair_unpair (n : \u2115) : pair (unpair n).1 (unpair n).2 = n := by\n  dsimp only [unpair]; let s := sqrt n\n  have sm : s * s + (n - s * s) = n := add_tsub_cancel_of_le (sqrt_le _)\n  split_ifs with h\n  \u00b7 simp [pair, h, sm]\n  \u00b7 have hl : n - s * s - s \u2264 s :=\n      tsub_le_iff_left.mpr (tsub_le_iff_left.mpr <| by rw [\u2190 add_assoc] ; apply sqrt_le_add)\n    simp [pair, hl.not_lt, add_assoc, add_tsub_cancel_of_le (le_of_not_gt h), sm]\n#align nat.mkpair_unpair Nat.pair_unpair\n\ntheorem pair_unpair' {n a b} (H : unpair n = (a, b)) : pair a b = n := by\n  simpa [H] using pair_unpair n\n#align nat.mkpair_unpair' Nat.pair_unpair'\n\n@[simp]\n\n\n/-- An equivalence between `\u2115 \u00d7 \u2115` and `\u2115`. -/\n@[simps (config := { fullyApplied := false })]\ndef pairEquiv : \u2115 \u00d7 \u2115 \u2243 \u2115 :=\n  \u27e8uncurry pair, unpair, fun \u27e8a, b\u27e9 => unpair_pair a b, pair_unpair\u27e9\n#align nat.mkpair_equiv Nat.pairEquiv\n#align nat.mkpair_equiv_apply Nat.pairEquiv_apply\n#align nat.mkpair_equiv_symm_apply Nat.pairEquiv_symm_apply\n\ntheorem surjective_unpair : Surjective unpair :=\n  pairEquiv.symm.surjective\n#align nat.surjective_unpair Nat.surjective_unpair\n\n@[simp]\ntheorem pair_eq_pair {a b c d : \u2115} : pair a b = pair c d \u2194 a = c \u2227 b = d :=\n  pairEquiv.injective.eq_iff.trans (@Prod.ext_iff \u2115 \u2115 (a, b) (c, d))\n#align nat.mkpair_eq_mkpair Nat.pair_eq_pair\n\ntheorem unpair_lt {n : \u2115} (n1 : 1 \u2264 n) : (unpair n).1 < n := by\n  let s := sqrt n\n  simp [unpair];\n  by_cases h : n - s * s < s <;> simp [h]\n  \u00b7 exact lt_of_lt_of_le h (sqrt_le_self _)\n  \u00b7 simp at h\n    have s0 : 0 < s := sqrt_pos.2 n1\n    exact lt_of_le_of_lt h (tsub_lt_self n1 (mul_pos s0 s0))\n#align nat.unpair_lt Nat.unpair_lt\n\n@[simp]\ntheorem unpair_zero : unpair 0 = 0 := by\n  rw [unpair]\n  simp\n#align nat.unpair_zero Nat.unpair_zero\n\ntheorem unpair_left_le : \u2200 n : \u2115, (unpair n).1 \u2264 n\n  | 0 => by simp\n  | n + 1 => le_of_lt (unpair_lt (Nat.succ_pos _))\n#align nat.unpair_left_le Nat.unpair_left_le\n\ntheorem left_le_pair (a b : \u2115) : a \u2264 pair a b := by simpa using unpair_left_le (pair a b)\n#align nat.left_le_mkpair Nat.left_le_pair\n\ntheorem right_le_pair (a b : \u2115) : b \u2264 pair a b := by\n  by_cases h : a < b <;> simp [pair, h]\n  exact le_trans (le_mul_self _) (Nat.le_add_right _ _)\n#align nat.right_le_mkpair Nat.right_le_pair\n\ntheorem unpair_right_le (n : \u2115) : (unpair n).2 \u2264 n := by\n  simpa using right_le_pair n.unpair.1 n.unpair.2\n#align nat.unpair_right_le Nat.unpair_right_le\n\ntheorem pair_lt_pair_left {a\u2081 a\u2082} (b) (h : a\u2081 < a\u2082) : pair a\u2081 b < pair a\u2082 b := by\n  by_cases h\u2081 : a\u2081 < b <;> simp [pair, h\u2081, add_assoc]\n  \u00b7 by_cases h\u2082 : a\u2082 < b <;> simp [pair, h\u2082, h]\n    simp at h\u2082\n    apply add_lt_add_of_le_of_lt\n    exact mul_self_le_mul_self h\u2082\n    exact Nat.lt_add_right _ _ _ h\n  \u00b7 simp at h\u2081\n    simp [not_lt_of_gt (lt_of_le_of_lt h\u2081 h)]\n    apply add_lt_add\n    exact mul_self_lt_mul_self h\n    apply add_lt_add_right ; assumption\n#align nat.mkpair_lt_mkpair_left Nat.pair_lt_pair_left\n\ntheorem pair_lt_pair_right (a) {b\u2081 b\u2082} (h : b\u2081 < b\u2082) : pair a b\u2081 < pair a b\u2082 := by\n  by_cases h\u2081 : a < b\u2081 <;> simp [pair, h\u2081, add_assoc]\n  \u00b7 simp [pair, lt_trans h\u2081 h, h]\n    exact mul_self_lt_mul_self h\n  \u00b7 by_cases h\u2082 : a < b\u2082 <;> simp [pair, h\u2082, h]\n    simp at h\u2081\n    rw [add_comm, add_comm _ a, add_assoc, add_lt_add_iff_left]\n    rwa [add_comm, \u2190 sqrt_lt, sqrt_add_eq]\n    exact le_trans h\u2081 (Nat.le_add_left _ _)\n#align nat.mkpair_lt_mkpair_right Nat.pair_lt_pair_right\n\ntheorem pair_lt_max_add_one_sq (m n : \u2115) : pair m n < (max m n + 1) ^ 2 := by\n  rw [pair, add_sq, mul_one, two_mul, sq, add_assoc, add_assoc]\n  cases' (lt_or_le m n) with h h\n  rw [if_pos h, max_eq_right h.le, add_lt_add_iff_left, add_assoc]\n  exact h.trans_le (self_le_add_right n _)\n  rw [if_neg h.not_lt, max_eq_left h, add_lt_add_iff_left, add_assoc, add_lt_add_iff_left]\n  exact lt_succ_of_le h\n#align nat.mkpair_lt_max_add_one_sq Nat.pair_lt_max_add_one_sq\n\ntheorem max_sq_add_min_le_pair (m n : \u2115) : max m n ^ 2 + min m n \u2264 pair m n := by\n  rw [pair]\n  cases' lt_or_le m n with h h\n  rw [if_pos h, max_eq_right h.le, min_eq_left h.le, sq]\n  rw [if_neg h.not_lt, max_eq_left h, min_eq_right h, sq, add_assoc, add_le_add_iff_left]\n  exact le_add_self\n#align nat.max_sq_add_min_le_mkpair Nat.max_sq_add_min_le_pair\n\ntheorem add_le_pair (m n : \u2115) : m + n \u2264 pair m n :=\n  (max_sq_add_min_le_pair _ _).trans' <| by\n    rw [sq, \u2190 min_add_max, add_comm, add_le_add_iff_right]\n    exact le_mul_self _\n#align nat.add_le_mkpair Nat.add_le_pair\n\ntheorem unpair_add_le (n : \u2115) : (unpair n).1 + (unpair n).2 \u2264 n :=\n  (add_le_pair _ _).trans_eq (pair_unpair _)\n#align nat.unpair_add_le Nat.unpair_add_le\n\nend Nat\n\nopen Nat\n\nsection CompleteLattice\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\ntheorem sup\u1d62_unpair {\u03b1} [CompleteLattice \u03b1] (f : \u2115 \u2192 \u2115 \u2192 \u03b1) :\n    (\u2a06 n : \u2115, f n.unpair.1 n.unpair.2) = \u2a06 (i : \u2115) (j : \u2115), f i j := by\n  rw [\u2190 (sup\u1d62_prod : (\u2a06 i : \u2115 \u00d7 \u2115, f i.1 i.2) = _), \u2190 Nat.surjective_unpair.sup\u1d62_comp]\n#align supr_unpair sup\u1d62_unpair\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\ntheorem inf\u1d62_unpair {\u03b1} [CompleteLattice \u03b1] (f : \u2115 \u2192 \u2115 \u2192 \u03b1) :\n    (\u2a05 n : \u2115, f n.unpair.1 n.unpair.2) = \u2a05 (i : \u2115) (j : \u2115), f i j :=\n  sup\u1d62_unpair (show \u2115 \u2192 \u2115 \u2192 \u03b1\u1d52\u1d48 from f)\n#align infi_unpair inf\u1d62_unpair\n\nend CompleteLattice\n\nnamespace Set\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem union\u1d62_unpair_prod {\u03b1 \u03b2} {s : \u2115 \u2192 Set \u03b1} {t : \u2115 \u2192 Set \u03b2} :\n    (\u22c3 n : \u2115, s n.unpair.fst \u00d7\u02e2 t n.unpair.snd) = (\u22c3 n, s n) \u00d7\u02e2 \u22c3 n, t n := by\n  rw [\u2190 Set.union\u1d62_prod]\n  exact surjective_unpair.union\u1d62_comp (fun x => s x.fst \u00d7\u02e2 t x.snd)\n#align set.Union_unpair_prod Set.union\u1d62_unpair_prod\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\ntheorem union\u1d62_unpair {\u03b1} (f : \u2115 \u2192 \u2115 \u2192 Set \u03b1) :\n    (\u22c3 n : \u2115, f n.unpair.1 n.unpair.2) = \u22c3 (i : \u2115) (j : \u2115), f i j :=\n  sup\u1d62_unpair f\n#align set.Union_unpair Set.union\u1d62_unpair\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\ntheorem inter\u1d62_unpair {\u03b1} (f : \u2115 \u2192 \u2115 \u2192 Set \u03b1) :\n    (\u22c2 n : \u2115, f n.unpair.1 n.unpair.2) = \u22c2 (i : \u2115) (j : \u2115), f i j :=\n  inf\u1d62_unpair f\n#align set.Inter_unpair Set.inter\u1d62_unpair\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Pairing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7367266564762338}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Callum Sutton, Yury Kudryashov\n-/\nimport algebra.hom.equiv.basic\nimport algebra.hom.units\n\n/-!\n# Multiplicative and additive equivalence acting on units.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {F \u03b1 \u03b2 A B M N P Q G H : Type*}\n\n/-- A group is isomorphic to its group of units. -/\n@[to_additive \"An additive group is isomorphic to its group of additive units\"]\ndef to_units [group G] : G \u2243* G\u02e3 :=\n{ to_fun := \u03bb x, \u27e8x, x\u207b\u00b9, mul_inv_self _, inv_mul_self _\u27e9,\n  inv_fun := coe,\n  left_inv := \u03bb x, rfl,\n  right_inv := \u03bb u, units.ext rfl,\n  map_mul' := \u03bb x y, units.ext rfl }\n\n@[simp, to_additive] lemma coe_to_units [group G] (g : G) :\n  (to_units g : G) = g := rfl\n\nnamespace units\n\nvariables [monoid M] [monoid N] [monoid P]\n\n/-- A multiplicative equivalence of monoids defines a multiplicative equivalence\nof their groups of units. -/\ndef map_equiv (h : M \u2243* N) : M\u02e3 \u2243* N\u02e3 :=\n{ inv_fun := map h.symm.to_monoid_hom,\n  left_inv := \u03bb u, ext $ h.left_inv u,\n  right_inv := \u03bb u, ext $ h.right_inv u,\n  .. map h.to_monoid_hom }\n\n@[simp]\nlemma map_equiv_symm (h : M \u2243* N) : (map_equiv h).symm = map_equiv h.symm :=\nrfl\n\n@[simp]\nlemma coe_map_equiv (h : M \u2243* N) (x : M\u02e3) : (map_equiv h x : N) = h x :=\nrfl\n\n/-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -/\n@[to_additive \"Left addition of an additive unit is a permutation of the underlying type.\",\n  simps apply {fully_applied := ff}]\ndef mul_left (u : M\u02e3) : equiv.perm M :=\n{ to_fun    := \u03bbx, u * x,\n  inv_fun   := \u03bbx, \u2191u\u207b\u00b9 * x,\n  left_inv  := u.inv_mul_cancel_left,\n  right_inv := u.mul_inv_cancel_left }\n\n@[simp, to_additive]\nlemma mul_left_symm (u : M\u02e3) : u.mul_left.symm = u\u207b\u00b9.mul_left :=\nequiv.ext $ \u03bb x, rfl\n\n@[to_additive]\nlemma mul_left_bijective (a : M\u02e3) : function.bijective ((*) a : M \u2192 M) :=\n(mul_left a).bijective\n\n/-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -/\n@[to_additive \"Right addition of an additive unit is a permutation of the underlying type.\",\n  simps apply {fully_applied := ff}]\ndef mul_right (u : M\u02e3) : equiv.perm M :=\n{ to_fun    := \u03bbx, x * u,\n  inv_fun   := \u03bbx, x * \u2191u\u207b\u00b9,\n  left_inv  := \u03bb x, mul_inv_cancel_right x u,\n  right_inv := \u03bb x, inv_mul_cancel_right x u }\n\n@[simp, to_additive]\nlemma mul_right_symm (u : M\u02e3) : u.mul_right.symm = u\u207b\u00b9.mul_right :=\nequiv.ext $ \u03bb x, rfl\n\n@[to_additive]\nlemma mul_right_bijective (a : M\u02e3) : function.bijective ((* a) : M \u2192 M) :=\n(mul_right a).bijective\n\nend units\n\nnamespace equiv\n\nsection group\nvariables [group G]\n\n/-- Left multiplication in a `group` is a permutation of the underlying type. -/\n@[to_additive \"Left addition in an `add_group` is a permutation of the underlying type.\"]\nprotected def mul_left (a : G) : perm G := (to_units a).mul_left\n\n@[simp, to_additive]\nlemma coe_mul_left (a : G) : \u21d1(equiv.mul_left a) = (*) a := rfl\n\n/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/\n@[simp, nolint simp_nf,\n  to_additive \"Extra simp lemma that `dsimp` can use. `simp` will never use this.\"]\nlemma mul_left_symm_apply (a : G) : ((equiv.mul_left a).symm : G \u2192 G) = (*) a\u207b\u00b9 := rfl\n\n@[simp, to_additive]\nlemma mul_left_symm (a : G) : (equiv.mul_left a).symm = equiv.mul_left a\u207b\u00b9 :=\next $ \u03bb x, rfl\n\n@[to_additive]\nlemma _root_.group.mul_left_bijective (a : G) : function.bijective ((*) a) :=\n(equiv.mul_left a).bijective\n\n/-- Right multiplication in a `group` is a permutation of the underlying type. -/\n@[to_additive \"Right addition in an `add_group` is a permutation of the underlying type.\"]\nprotected def mul_right (a : G) : perm G := (to_units a).mul_right\n\n@[simp, to_additive]\nlemma coe_mul_right (a : G) : \u21d1(equiv.mul_right a) = \u03bb x, x * a := rfl\n\n@[simp, to_additive]\nlemma mul_right_symm (a : G) : (equiv.mul_right a).symm = equiv.mul_right a\u207b\u00b9 :=\next $ \u03bb x, rfl\n\n/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/\n@[simp, nolint simp_nf,\n  to_additive \"Extra simp lemma that `dsimp` can use. `simp` will never use this.\"]\nlemma mul_right_symm_apply (a : G) : ((equiv.mul_right a).symm : G \u2192 G) = \u03bb x, x * a\u207b\u00b9 := rfl\n\n@[to_additive]\nlemma _root_.group.mul_right_bijective (a : G) : function.bijective (* a) :=\n(equiv.mul_right a).bijective\n\n/-- A version of `equiv.mul_left a b\u207b\u00b9` that is defeq to `a / b`. -/\n@[to_additive /-\" A version of `equiv.add_left a (-b)` that is defeq to `a - b`. \"-/, simps]\nprotected def div_left (a : G) : G \u2243 G :=\n{ to_fun := \u03bb b, a / b,\n  inv_fun := \u03bb b, b\u207b\u00b9 * a,\n  left_inv := \u03bb b, by simp [div_eq_mul_inv],\n  right_inv := \u03bb b, by simp [div_eq_mul_inv] }\n\n@[to_additive]\nlemma div_left_eq_inv_trans_mul_left (a : G) :\n  equiv.div_left a = (equiv.inv G).trans (equiv.mul_left a) :=\next $ \u03bb _, div_eq_mul_inv _ _\n\n/-- A version of `equiv.mul_right a\u207b\u00b9 b` that is defeq to `b / a`. -/\n@[to_additive /-\" A version of `equiv.add_right (-a) b` that is defeq to `b - a`. \"-/, simps]\nprotected def div_right (a : G) : G \u2243 G :=\n{ to_fun := \u03bb b, b / a,\n  inv_fun := \u03bb b, b * a,\n  left_inv := \u03bb b, by simp [div_eq_mul_inv],\n  right_inv := \u03bb b, by simp [div_eq_mul_inv] }\n\n@[to_additive]\nlemma div_right_eq_mul_right_inv (a : G) : equiv.div_right a = equiv.mul_right a\u207b\u00b9 :=\next $ \u03bb _, div_eq_mul_inv _ _\n\nend group\n\nend equiv\n\n/-- In a `division_comm_monoid`, `equiv.inv` is a `mul_equiv`. There is a variant of this\n`mul_equiv.inv' G : G \u2243* G\u1d50\u1d52\u1d56` for the non-commutative case. -/\n@[to_additive \"When the `add_group` is commutative, `equiv.neg` is an `add_equiv`.\", simps apply]\ndef mul_equiv.inv (G : Type*) [division_comm_monoid G] : G \u2243* G :=\n{ to_fun   := has_inv.inv,\n  inv_fun  := has_inv.inv,\n  map_mul' := mul_inv,\n  ..equiv.inv G }\n\n@[simp] lemma mul_equiv.inv_symm (G : Type*) [division_comm_monoid G] :\n  (mul_equiv.inv G).symm = mul_equiv.inv G := rfl\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/hom/equiv/units/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7367266515913728}}
{"text": "-- The first part can be done using only \"constructive logic\"\n\ntheorem contrapositive (P Q : Prop) (HPQ : P \u2192 Q) : \u00ac Q \u2192 \u00ac P :=\nbegin\n  /-\n    P Q : Prop,\n    HPQ : P \u2192 Q\n    \u22a2 \u00acQ \u2192 \u00acP\n  -/\n  intro HnQ,\n  intro HP,\n  /-\n    P Q : Prop,\n    HPQ : P \u2192 Q,\n    HnQ : \u00acQ,\n    HP : P\n    \u22a2 false\n  -/\n  apply HnQ, -- !\n  apply HPQ,\n  assumption\nend\n\n-- The other way needs normal logic (i.e. you can use the law of the excluded middle)\n-- The Lean term `classical.em Q` is a proof of `Q \u2228 \u00ac Q` , if `Q` is a proposition\n-- (that is, if `Q` has type `Prop`).\n\ntheorem other_way (P Q : Prop) (HnQnP : \u00ac Q \u2192 \u00ac P) : P \u2192 Q :=\nbegin\n  intro HP,\n  have HQnQ := classical.em Q,\n  cases HQnQ, -- Q is either true or false\n    assumption,\n  have HnP := HnQnP HQnQ,\n  have Hfalse := HnP HP,\n  cases Hfalse,\nend\n\ntheorem both_ways (P Q : Prop) : (P \u2192 Q) \u2194 (\u00ac Q \u2192 \u00ac P) := by ??", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/lean_together/contrapos_final.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7366916810765662}}
{"text": "import algebra.char_p.basic\nimport ring_theory.localization\nimport algebra.free_algebra\n\nnamespace ring_char\n\nlemma of_prime_eq_zero\n  {A : Type*} [non_assoc_semiring A] [nontrivial A]\n  {p : \u2115} (hprime : nat.prime p) (hp0 : (p : A) = 0) :\n  ring_char A = p :=\nbegin\n  have hchar : ring_char A \u2223 p := ring_char.dvd hp0,\n  unfold nat.prime at hprime,\n  have heq := hprime.2 (ring_char A) hchar,\n  cases heq,\n  { exfalso,\n    exact char_p.ring_char_ne_one heq },\n  { exact heq },\nend\n\nlemma lt_char {A : Type*} [non_assoc_semiring A]\n  {n : \u2115} : (n : A) = 0 \u2192 n < ring_char A \u2192 n = 0 :=\nbegin\n  rw spec A n,\n  exact nat.eq_zero_of_dvd_of_lt,\nend\n\nlemma lt_char_field {A : Type*} [field A]\n  {n : \u2115} : (n : A) = 0 \u2192 n < ring_char A \u2192 n = 0 :=\nbegin\n  rw spec A n,\n  exact nat.eq_zero_of_dvd_of_lt,\nend\n\n\nend ring_char\n\n/-- If the algebra map `R \u2192+* A` is injective then `A` has the same characteristic as `R`. -/\nlemma char_p_of_injective_algebra_map {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]\n  (h : function.injective (algebra_map R A)) (p : \u2115) [char_p R p] : char_p A p :=\n{ cast_eq_zero_iff := \u03bbx,\n  begin\n    rw \u2190char_p.cast_eq_zero_iff R p x,\n    change algebra_map \u2115 A x = 0 \u2194 algebra_map \u2115 R x = 0,\n    rw is_scalar_tower.algebra_map_apply \u2115 R A x,\n    refine iff.trans _ h.eq_iff,\n    rw ring_hom.map_zero,\n  end }\n", "meta": {"author": "Jlh18", "repo": "ModelTheoryInLean8", "sha": "fbda7d869d4169b6e739bb74165e99ee03ca63d6", "save_path": "github-repos/lean/Jlh18-ModelTheoryInLean8", "path": "github-repos/lean/Jlh18-ModelTheoryInLean8/ModelTheoryInLean8-fbda7d869d4169b6e739bb74165e99ee03ca63d6/Trash/Rings/ToMathlib/char_p.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7366916763037398}}
{"text": "/-\nCopyright (c) 2022 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport analysis.inner_product_space.basic\n\n/-!\n# Inversion in an affine space\n\nIn this file we define inversion in a sphere in an affine space. This map sends each point `x` to\nthe point `y` such that `y -\u1d65 c = (R / dist x c) ^ 2 \u2022 (x -\u1d65 c)`, where `c` and `R` are the center\nand the radius the sphere.\n\nIn many applications, it is convenient to assume that the inversions swaps the center and the point\nat infinity. In order to stay in the original affine space, we define the map so that it sends\ncenter to itself.\n\nCurrently, we prove only a few basic lemmas needed to prove Ptolemy's inequality, see\n`euclidean_geometry.mul_dist_le_mul_dist_add_mul_dist`.\n-/\n\nnoncomputable theory\nopen metric real function\n\nnamespace euclidean_geometry\n\nvariables {V P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\n  {a b c d x y z : P} {R : \u211d}\n\ninclude V\n\n/-- Inversion in a sphere in an affine space. This map sends each point `x` to the point `y` such\nthat `y -\u1d65 c = (R / dist x c) ^ 2 \u2022 (x -\u1d65 c)`, where `c` and `R` are the center and the radius the\nsphere. -/\ndef inversion (c : P) (R : \u211d) (x : P) : P := (R / dist x c) ^ 2 \u2022 (x -\u1d65 c) +\u1d65 c\n\nlemma inversion_vsub_center (c : P) (R : \u211d) (x : P) :\n  inversion c R x -\u1d65 c = (R / dist x c) ^ 2 \u2022 (x -\u1d65 c) :=\nvadd_vsub _ _\n\n@[simp] lemma inversion_self (c : P) (R : \u211d) : inversion c R c = c := by simp [inversion]\n\n@[simp] lemma inversion_dist_center (c x : P) : inversion c (dist x c) x = x :=\nbegin\n  rcases eq_or_ne x c with rfl|hne,\n  { apply inversion_self },\n  { rw [inversion, div_self, one_pow, one_smul, vsub_vadd],\n    rwa [dist_ne_zero] }\nend\n\nlemma inversion_of_mem_sphere (h : x \u2208 metric.sphere c R) : inversion c R x = x :=\nh.out \u25b8 inversion_dist_center c x\n\n/-- Distance from the image of a point under inversion to the center. This formula accidentally\nworks for `x = c`. -/\nlemma dist_inversion_center (c x : P) (R : \u211d) : dist (inversion c R x) c = R ^ 2 / dist x c :=\nbegin\n  rcases eq_or_ne x c with (rfl|hx), { simp },\n  have : dist x c \u2260 0, from dist_ne_zero.2 hx,\n  field_simp [inversion, norm_smul, abs_div, \u2190 dist_eq_norm_vsub, sq, mul_assoc]\nend\n\n/-- Distance from the center of an inversion to the image of a point under the inversion. This\nformula accidentally works for `x = c`. -/\nlemma dist_center_inversion (c x : P) (R : \u211d) : dist c (inversion c R x) = R ^ 2 / dist c x :=\nby rw [dist_comm c, dist_comm c, dist_inversion_center]\n\n@[simp] lemma inversion_inversion (c : P) {R : \u211d} (hR : R \u2260 0) (x : P) :\n  inversion c R (inversion c R x) = x :=\nbegin\n  rcases eq_or_ne x c with rfl|hne,\n  { rw [inversion_self, inversion_self] },\n  { rw [inversion, dist_inversion_center, inversion_vsub_center, smul_smul, \u2190 mul_pow,\n      div_mul_div_comm, div_mul_cancel _ (dist_ne_zero.2 hne), \u2190 sq, div_self, one_pow, one_smul,\n      vsub_vadd],\n    exact pow_ne_zero _ hR }\nend\n\nlemma inversion_involutive (c : P) {R : \u211d} (hR : R \u2260 0) : involutive (inversion c R) :=\ninversion_inversion c hR\n\nlemma inversion_surjective (c : P) {R : \u211d} (hR : R \u2260 0) : surjective (inversion c R) :=\n(inversion_involutive c hR).surjective\n\nlemma inversion_injective (c : P) {R : \u211d} (hR : R \u2260 0) : injective (inversion c R) :=\n(inversion_involutive c hR).injective\n\nlemma inversion_bijective (c : P) {R : \u211d} (hR : R \u2260 0) : bijective (inversion c R) :=\n(inversion_involutive c hR).bijective\n\n/-- Distance between the images of two points under an inversion. -/\nlemma dist_inversion_inversion (hx : x \u2260 c) (hy : y \u2260 c) (R : \u211d) :\n  dist (inversion c R x) (inversion c R y) = (R ^ 2 / (dist x c * dist y c)) * dist x y :=\nbegin\n  dunfold inversion,\n  simp_rw [dist_vadd_cancel_right, dist_eq_norm_vsub V _ c],\n  simpa only [dist_vsub_cancel_right]\n    using dist_div_norm_sq_smul (vsub_ne_zero.2 hx) (vsub_ne_zero.2 hy) R\nend\n\n/-- **Ptolemy's inequality**: in a quadrangle `ABCD`, `|AC| * |BD| \u2264 |AB| * |CD| + |BC| * |AD|`. If\n`ABCD` is a convex cyclic polygon, then this inequality becomes an equality, see\n`euclidean_geometry.mul_dist_add_mul_dist_eq_mul_dist_of_cospherical`.  -/\nlemma mul_dist_le_mul_dist_add_mul_dist (a b c d : P) :\n  dist a c * dist b d \u2264 dist a b * dist c d + dist b c * dist a d :=\nbegin\n  -- If one of the points `b`, `c`, `d` is equal to `a`, then the inequality is trivial.\n  rcases eq_or_ne b a with rfl|hb,\n  { rw [dist_self, zero_mul, zero_add] },\n  rcases eq_or_ne c a with rfl|hc,\n  { rw [dist_self, zero_mul],\n    apply_rules [add_nonneg, mul_nonneg, dist_nonneg] },\n  rcases eq_or_ne d a with rfl|hd,\n  { rw [dist_self, mul_zero, add_zero, dist_comm d, dist_comm d, mul_comm] },\n  /- Otherwise, we apply the triangle inequality to `euclidean_geometry.inversion a 1 b`,\n  `euclidean_geometry.inversion a 1 c`, and `euclidean_geometry.inversion a 1 d`. -/\n  have H := dist_triangle (inversion a 1 b) (inversion a 1 c) (inversion a 1 d),\n  rw [dist_inversion_inversion hb hd, dist_inversion_inversion hb hc,\n    dist_inversion_inversion hc hd, one_pow] at H,\n  rw [\u2190 dist_pos] at hb hc hd,\n  rw [\u2190 div_le_div_right (mul_pos hb (mul_pos hc hd))],\n  convert H; { field_simp [hb.ne', hc.ne', hd.ne', dist_comm a], ring }\nend\n\nend euclidean_geometry\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/inversion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7366916759847026}}
{"text": "/-\n\n# Chapter 12: complex numbers playground \n\nThis file contains some scattered code from the Ch 12 lectures,\nwhere we attempted to build a bit of API around the complex numbers.\n\n-/\n\nimport algebra.group.basic \nimport data.real.basic\nimport analysis.special_functions.trigonometric\n\nsection\nvariables {\u03b1 \u03b2 : Type} [group \u03b1] [group \u03b2]\n  (f : \u03b1 \u2192 \u03b2)\n  (hf : \u2200 a b : \u03b1, f (a*b) = f a * f b)\n\ninclude hf\n\nlemma f_one_eq_one :\n  f 1 = 1 := \nbegin \n  have h1 : f (1 * 1) = f 1 * f 1 := hf 1 1,\n  rw one_mul at h1,\n  rw self_eq_mul_left at h1,\n  -- simp at h1,\n  assumption\nend \n#check @f_one_eq_one\nlemma f_inv_eq_inv  :\n  \u2200 a, f (a\u207b\u00b9) = (f a)\u207b\u00b9 :=\nbegin\n  intro a,\n  have h1 : f a * f (a\u207b\u00b9)  = 1 := begin \n    rw [\u2190 hf, mul_right_inv],\n    apply f_one_eq_one,\n    apply hf\n  end,\n  exact (inv_eq_of_mul_eq_one h1).symm\nend\nend \n\nnamespace new \n\nstructure complex : Type :=\n(r im : \u211d)\n\ndef add (c1 c2 : complex) : complex :=\n{ r := c1.r + c2.r, im := c1.im + c2.im }\n\ndef neg (c : complex) : complex :=\n{ r := -c.r, im := -c.im }\n\ndef mul (c1 c2 : complex) : complex :=\n{ r := c1.r*c2.r - c1.im*c2.im, im := c1.r*c2.im + c1.im*c2.r  }\n\ninstance : comm_ring complex :=\n{ add := add,\n  mul := mul,\n  zero := {r := 0, im := 0},\n  one := {r := 1, im := 0},\n  neg := neg, \n  add_comm := sorry,\n  add_assoc := sorry,\n  zero_add := sorry,\n  add_zero := sorry,\n  add_left_neg := sorry,\n  mul_assoc := sorry,\n  one_mul := sorry,\n  mul_one := sorry,\n  left_distrib := sorry,\n  right_distrib := sorry,\n  mul_comm := sorry }\n\nlemma mul_eq (c1 c2 : complex) : \n  c1 * c2 = { r := c1.r*c2.r - c1.im*c2.im, im := c1.r*c2.im + c1.im*c2.r } :=\nby refl\n\ndef conjugate (a : complex) : complex :=\n{ r := a.r, im := - a.im }\n\ntheorem mul_conjugate (a : complex) : (a * conjugate a).im = 0 :=\nbegin\n  cases a,\n  simp [conjugate, mul_eq],\n  ring\nend\n\n-- returns (angle, radius)\nnoncomputable def to_polar (c : complex) : \u211d \u00d7 \u211d :=\n(real.arctan (c.im / c.r), real.sqrt (c.r^2 + c.im^2))\n\nnoncomputable def from_polar (angle radius : \u211d) : complex :=\n{ r := radius * real.cos angle, im := radius * real.sin angle }\n\nexample (angle radius : \u211d) (h_rad : radius > 0) (h_angle1 : -(real.pi / 2) < angle)\n  (h_angle2 : angle < real.pi / 2): \n  to_polar (from_polar angle radius) = (angle, radius) :=\nbegin \n  simp [to_polar, from_polar],\n  split,\n  { calc \n    real.arctan (radius * real.sin angle / (radius * real.cos angle)) = \n      real.arctan (real.sin angle / real.cos angle): _\n    ... = real.arctan (real.tan angle) : _\n    ... = angle : _,\n    \n    { rw mul_div_mul_left,\n      linarith },\n    { rw real.tan_eq_sin_div_cos },\n    { rw real.arctan_tan, assumption, assumption }\n     },\n  { rw [\u2190 eq_of_sq_eq_sq, real.sq_sqrt]\n    -- we should be able to finish the remaining stuff \n  }\nend\n\ndef of_real (r : \u211d) : complex :=\n{ r := r, im := 0 }\n\ninstance : has_coe \u211d complex :=\n{ coe := of_real }\n\nexample (r : \u211d) (c : complex) : c + r = c + r :=\nby refl\n\nend new \n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/lectures/love12_playground.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7364996089124881}}
{"text": "import data.real.basic\nimport tactic\n\nset_option pp.implicit true\n-- Make simp display the steps used.  \nset_option trace.simplify.rewrite true\n-- # 1\nnamespace problem1\n\n-- let X, Y, Z be sets.\nvariables {X Y Z : Type} \n\n-- a function f : X \u2192 Y is *injective* if f(a) = f(b) \u2192 a = b for all a,b in X.\ndef injective (f : X \u2192 Y)  : Prop :=\n\u2200 a b : X, f(a) = f(b) \u2192 a = b\n\n-- challenge: the composite of two injective functions is injective\ntheorem challenge1\n  (f : X \u2192 Y) (hf : injective f)\n  (g : Y \u2192 Z) (hg : injective g) :\ninjective (g \u2218 f) :=\nbegin\n    intros a b,\n    intro h\u2081, --: g \u2218 f a  = g \u2218 f b, How to specify the type of h\u2081?\n    have h\u2082 : f a = f b, from hg (f a) (f b) h\u2081,\n    have h\u2083 : a = b, from hf a b h\u2082,\n    exact h\u2083\nend\n\ntheorem challenge1_solution\n  (f : X \u2192 Y) (hf : injective f)\n  (g : Y \u2192 Z) (hg : injective g) :\ninjective (g \u2218 f) :=\nbegin\n  -- the *definition* of \"injective\" is \"for all a and b...\", so let\n  -- a and b be arbitrary elements of X.\n  intros a b,\n  -- Assume (g \u2218 f) a = (g \u2218 f) b\n  intro hab,\n  -- The goal is now \u22a2 a = b .\n  -- By injectivity of f, it suffices to prove f(a)=f(b)\n  apply hf,\n  -- By injectivity of g, it suffices to prove g(f(a))=g(f(b))\n  apply hg,\n  -- but this is precisely our assumption.\n  exact hab,\n  -- \"no goals\" means we're done.\nend\n\nend problem1\n\nnamespace problem2\n\n-- basic definitions\ndef upper_bounds (S : set \u211d) : set \u211d := { b | \u2200s \u2208 S, s \u2264 b }\ndef lower_bounds (S : set \u211d) : set \u211d := { b | \u2200s \u2208 S, b \u2264 s }\ndef is_least (S : set \u211d) (l : \u211d) : Prop := l \u2208 S \u2227 l \u2208 lower_bounds S\ndef is_lub (S : set \u211d) (l : \u211d) : Prop := is_least (upper_bounds S) l\n\n/-- A set has at most one least upper bound -/\ntheorem challenge2 \n  (S : set \u211d) \n  (a b : \u211d) \n  (ha : is_lub S a) \n  (hb : is_lub S b) : \na = b :=\nbegin\n  have h\u2081 : a \u2208 upper_bounds S, from ha.left,\n  have h\u2082 : b \u2208 upper_bounds S, from hb.left,\n  have h\u2083 : a \u2264 b, from ha.right b h\u2082, \n  have h\u2084 : b \u2264 a, from hb.right a h\u2081,\n  linarith,\n  -- or\n  --exact @le_antisymm \u211d real.partial_order a b h\u2083 h\u2084\nend \n\ntheorem challenge2_solution\n  (S : set \u211d) \n  (a b : \u211d) \n  (ha : is_lub S a) \n  (hb : is_lub S b) : \na = b :=\nbegin\n  -- if you unfold some definitions\n   unfold is_lub at ha,\n   unfold is_least at ha,\n  -- then you discover that by definition ha is a proof of\n  -- a \u2208 upper_bounds S \u2227 a \u2208 lower_bounds (upper_bounds S)\n  -- so it's a proof of P \u2227 Q, so you can use `cases` to recover the proofs of P and Q.\n  cases ha with ha1 ha2,\n  -- you don't have to do the unfolding though.\n  cases hb with hb1 hb2,\n  -- we prove a = b by showing a \u2264 b and b \u2264 a\n  apply le_antisymm,\n  { -- to prove a \u2264 b we want to argue that b is an upper bound and a is the least upper bound.\n    -- First let's use the fact that a is at most all upper bounds\n    apply ha2,\n    -- and now we just need that b is an upper bound\n    exact hb1},\n  { -- The other way is similar.\n    apply hb2,\n    exact ha1}\nend\n\nend problem2\n\n\nnamespace ploblem3\n\ntheorem challenge3 :\n(2 : \u211d) + 2 \u2260 5 :=\nbegin\n  linarith,\nend\n\ntheorem challenge3_solution :\n(2 : \u211d) + 2 \u2260 5 :=\nbegin\n  norm_num\nend\n\n/-\nNotes:\nAfter checking the docs, norm_num is more lightweight, covering arithmetic\nevaluations of *,+,-,^,\u2264, whereas linarith has norm_num as a subset. It\nhandles 'linear' arithmetic (not exactly sure what is included here), but it\nit is far more comprehensive.\n-/\n\nend ploblem3\n\n\nnamespace problem4\n\nopen function\n\ntheorem challenge4 \n  (X Y Z : Type) \n  (f : X \u2192 Y) \n  (g : Y \u2192 Z) : \nsurjective (g \u2218 f) \u2192 surjective g :=\nassume h\u2081,\nassume z,\n  have h\u2082 : \u2203y : Y, g y = z, from exists.elim (h\u2081 z) \n  (assume (x : X) (hh\u2081 : (g \u2218 f) x = z),\n    have hh\u2082 : g (f x) = z, from hh\u2081,\n    let y := f x in exists.intro y hh\u2082),\n  h\u2082\n\n\ntheorem challenge4_solution \n  (X Y Z : Type) \n  (f : X \u2192 Y) \n  (g : Y \u2192 Z) : \nsurjective (g \u2218 f) \u2192 surjective g :=\nbegin\n  intro h,\n  intro z,\n  cases h z with a ha,\n  use f a,\n  assumption,\nend\n\nend problem4", "meta": {"author": "kevindoran", "repo": "lean", "sha": "77e755095a31e3a214010eb48a61e48d65dfdec9", "save_path": "github-repos/lean/kevindoran-lean", "path": "github-repos/lean/kevindoran-lean/lean-77e755095a31e3a214010eb48a61e48d65dfdec9/lean_root/src/math_challenges.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7364996046442165}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\n\nimport algebra.triv_sq_zero_ext\n\n/-!\n# Dual numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe dual numbers over `R` are of the form `a + b\u03b5`, where `a` and `b` are typically elements of a\ncommutative ring `R`, and `\u03b5` is a symbol satisfying `\u03b5^2 = 0`. They are a special case of\n`triv_sq_zero_ext R M` with `M = R`.\n\n## Notation\n\nIn the `dual_number` locale:\n\n* `R[\u03b5]` is a shorthand for `dual_number R`\n* `\u03b5` is a shorthand for `dual_number.eps`\n\n## Main definitions\n\n* `dual_number`\n* `dual_number.eps`\n* `dual_number.lift`\n\n## Implementation notes\n\nRather than duplicating the API of `triv_sq_zero_ext`, this file reuses the functions there.\n\n## References\n\n* https://en.wikipedia.org/wiki/Dual_number\n-/\n\nvariables {R : Type*}\n\n/-- The type of dual numbers, numbers of the form $a + b\u03b5$ where $\u03b5^2 = 0$.-/\nabbreviation dual_number (R : Type*) : Type* := triv_sq_zero_ext R R\n\n/-- The unit element $\u03b5$ that squares to zero. -/\ndef dual_number.eps [has_zero R] [has_one R] : dual_number R := triv_sq_zero_ext.inr 1\n\nlocalized \"notation (name := dual_number.eps) `\u03b5` := dual_number.eps\" in dual_number\nlocalized \"postfix (name := dual_number) `[\u03b5]`:1025 := dual_number\" in dual_number\n\nopen_locale dual_number\n\nnamespace dual_number\n\nopen triv_sq_zero_ext\n\n@[simp] \n\n/-- A version of `triv_sq_zero_ext.snd_mul` with `*` instead of `\u2022`. -/\n@[simp] lemma snd_mul [semiring R] (x y : R[\u03b5]) : snd (x * y) = fst x * snd y + snd x * fst y :=\nsnd_mul _ _\n\n@[simp] lemma eps_mul_eps [semiring R] : (\u03b5 * \u03b5 : R[\u03b5]) = 0 := inr_mul_inr _ _ _\n\n@[simp] lemma inr_eq_smul_eps [mul_zero_one_class R] (r : R) : inr r = (r \u2022 \u03b5 : R[\u03b5]) :=\next (mul_zero r).symm (mul_one r).symm\n\n/-- For two algebra morphisms out of `R[\u03b5]` to agree, it suffices for them to agree on `\u03b5`. -/\n@[ext] lemma alg_hom_ext {A} [comm_semiring R] [semiring A] [algebra R A]\n  \u2983f g : R[\u03b5] \u2192\u2090[R] A\u2984 (h : f \u03b5 = g \u03b5) : f = g :=\nalg_hom_ext' $ linear_map.ext_ring $ h\n\nvariables {A : Type*} [comm_semiring R] [semiring A] [algebra R A]\n\n/-- A universal property of the dual numbers, providing a unique `R[\u03b5] \u2192\u2090[R] A` for every element\nof `A` which squares to `0`.\n\nThis isomorphism is named to match the very similar `complex.lift`. -/\n@[simps {attrs := []}]\ndef lift : {e : A // e * e = 0} \u2243 (R[\u03b5] \u2192\u2090[R] A) :=\nequiv.trans\n  (show {e : A // e * e = 0} \u2243 {f : R \u2192\u2097[R] A // \u2200 x y, f x * f y = 0}, from\n    (linear_map.ring_lmap_equiv_self R \u2115 A).symm.to_equiv.subtype_equiv $ \u03bb a, begin\n      dsimp,\n      simp_rw smul_mul_smul,\n      refine \u27e8\u03bb h x y, h.symm \u25b8 smul_zero _, \u03bb h, by simpa using h 1 1\u27e9,\n    end)\n  triv_sq_zero_ext.lift\n\n/- When applied to `\u03b5`, `dual_number.lift` produces the element of `A` that squares to 0. -/\n@[simp]\nlemma lift_apply_eps (e : {e : A // e * e = 0}) : lift e (\u03b5 : R[\u03b5]) = e :=\n(triv_sq_zero_ext.lift_aux_apply_inr _ _ _).trans $ one_smul _ _\n\n/- Lifting `dual_number.eps` itself gives the identity. -/\n@[simp]\nlemma lift_eps : lift \u27e8\u03b5, by exact eps_mul_eps\u27e9 = alg_hom.id R R[\u03b5] :=\nalg_hom_ext $ lift_apply_eps _\n\nend dual_number\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/dual_number.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7364996007912613}}
{"text": "import GMLInit.Data.Set.Basic\nimport GMLInit.Logic.Relation\n\nnamespace Set\nopen Set.Notation\nvariable {s t u : Set \u03b1}\n\ndef Subset (s t : Set \u03b1) : Prop := \u2200 x, x \u2208 s \u2192 x \u2208 t\n\ntheorem subset_refl (s : Set \u03b1) : s \u2286 s := by\n  intro x hs\n  exact hs\ninstance (\u03b1) : Relation.Reflexive (\u03b1:=Set \u03b1) (.\u2286.) := \u27e8subset_refl\u27e9\n\ntheorem subset_trans : s \u2286 t \u2192 t \u2286 u \u2192 s \u2286 u := by\n  intro hst htu x hs\n  apply htu\n  apply hst\n  exact hs\ninstance (\u03b1) : Relation.Transitive (\u03b1:=Set \u03b1) (.\u2286.) := \u27e8subset_trans\u27e9\n\ntheorem subset_antisymm : s \u2286 t \u2192 t \u2286 s \u2192 s = t := by\n  intro hst hts\n  apply Set.ext\n  intro x\n  constr\n  \u00b7 exact hst x\n  \u00b7 exact hts x\ninstance (\u03b1) : Relation.Antisymmetric (\u03b1:=Set \u03b1) (.\u2286.) := \u27e8subset_antisymm\u27e9\n\ntheorem empty_subset (s : Set \u03b1) : Set.empty \u2286 s := by\n  intro x h\n  contradiction\n\ntheorem eq_empty_of_subset_empty : s \u2286 Set.empty \u2192 s = Set.empty := by\n  intro hs\n  antisymmetry using (.\u2286.)\n  \u00b7 exact hs\n  \u00b7 exact empty_subset s\n\ntheorem subset_univ (s : Set \u03b1) : s \u2286 Set.univ := by\n  intro _ _\n  trivial\n\ntheorem eq_univ_of_univ_subset : Set.univ \u2286 s \u2192 s = Set.univ := by\n  intro hs\n  antisymmetry using (.\u2286.)\n  \u00b7 exact subset_univ s\n  \u00b7 exact hs\n\ntheorem pure_subset_of_mem {x : \u03b1} : x \u2208 s \u2192 pure x \u2286 s := by\n  intro | hs, _, rfl => exact hs\n\ntheorem subset_union_left (s t : Set \u03b1) : s \u2286 s \u222a t := by\n  intro x hs\n  left\n  exact hs\n\ntheorem subset_union_right (s t : Set \u03b1) : t \u2286 s \u222a t := by\n  intro x ht\n  right\n  exact ht\n\ntheorem union_subset_of_subset_of_subset : s \u2286 u \u2192 t \u2286 u \u2192 s \u222a t \u2286 u := by\n  intro hsu htu x\n  intro\n  | Or.inl hxs =>\n    exact hsu x hxs\n  | Or.inr hxt =>\n    exact htu x hxt\n\ntheorem union_subset_union_left : s \u2286 t \u2192 (\u2200 u, u \u222a s \u2286 u \u222a t) := by\n  intro hst u x\n  intro\n  | Or.inl hu =>\n    left\n    exact hu\n  | Or.inr hs =>\n    right\n    exact hst x hs\n\ntheorem union_subset_union_right : s \u2286 t \u2192 (\u2200 u, s \u222a u \u2286 t \u222a u) := by\n  intro hst u x\n  intro\n  | Or.inl hs =>\n    left\n    exact hst x hs\n  | Or.inr hu =>\n    right\n    exact hu\n\ntheorem union_subset_union {s\u2081 s\u2082 t\u2081 t\u2082 : Set \u03b1} : s\u2081 \u2286 s\u2082 \u2192 t\u2081 \u2286 t\u2082 \u2192 s\u2081 \u222a t\u2081 \u2286 s\u2082 \u222a t\u2082 := by\n  intro hs ht x\n  intro\n  | Or.inl hs\u2081 =>\n    left\n    exact hs x hs\u2081\n  | Or.inr ht\u2081 =>\n    right\n    exact ht x ht\u2081\n\ntheorem inter_subset_left (s t : Set \u03b1) : s \u2229 t \u2286 s := by\n  intro x \u27e8hs,_\u27e9\n  exact hs\n\ntheorem inter_subset_right (s t : Set \u03b1) : s \u2229 t \u2286 t := by\n  intro x \u27e8_,ht\u27e9\n  exact ht\n\ntheorem subset_inter_of_subset_of_subset : u \u2286 s \u2192 u \u2286 t \u2192 u \u2286 s \u2229 t := by\n  intro hus hut x hxu\n  constr\n  \u00b7 exact hus x hxu\n  \u00b7 exact hut x hxu\n\ntheorem inter_subset_inter_left : s \u2286 t \u2192 (\u2200 u, u \u2229 s \u2286 u \u2229 t) := by\n  intro hst u x \u27e8hu, hs\u27e9\n  constr\n  \u00b7 exact hu\n  \u00b7 exact hst x hs\n\ntheorem inter_subset_inter_right : s \u2286 t \u2192 (\u2200 u, s \u2229 u \u2286 t \u2229 u) := by\n  intro hst u x \u27e8hs, hu\u27e9\n  constr\n  \u00b7 exact hst x hs\n  \u00b7 exact hu\n\ntheorem inter_subset_inter {s\u2081 s\u2082 t\u2081 t\u2082 : Set \u03b1} : s\u2081 \u2286 s\u2082 \u2192 t\u2081 \u2286 t\u2082 \u2192 s\u2081 \u2229 t\u2081 \u2286 s\u2082 \u2229 t\u2082 := by\n  intro hs ht x \u27e8hs\u2081,ht\u2081\u27e9\n  constr\n  \u00b7 exact hs x hs\u2081\n  \u00b7 exact ht x ht\u2081\n\ntheorem map_subset_map (f : \u03b1 \u2192 \u03b2) : s \u2286 t \u2192 f <$> s \u2286 f <$> t := by\n  intro hst y \u27e8x,hx,h\u27e9\n  cases h\n  exists x\n  constr\n  \u00b7 exact hst x hx\n  \u00b7 rfl\n\ntheorem bind_subset_bind (f : \u03b1 \u2192 Set \u03b2) : s \u2286 t \u2192 s >>= f \u2286 t >>= f := by\n  intro hst y \u27e8x,hx,h\u27e9\n  exists x\n  constr\n  \u00b7 exact hst x hx\n  \u00b7 exact h\n\ntheorem val_subset_bind (f : \u03b1 \u2192 Set \u03b2) {x : \u03b1} : x \u2208 s \u2192 f x \u2286 s >>= f := by\n  intro hxs y hfxy\n  exists x\n\ntheorem bind_subset_of_val_subset {t : Set \u03b2} {f : \u03b1 \u2192 Set \u03b2} : (\u2200 x, x \u2208 s \u2192 f x \u2286 t) \u2192 s >>= f \u2286 t := by\n  intro h y \u27e8x, hxs, hfxy\u27e9\n  exact h x hxs y hfxy\n\nend Set\n", "meta": {"author": "fgdorais", "repo": "GMLInit", "sha": "a295111627ac907ebc6a86f906dd9b4d69b338d8", "save_path": "github-repos/lean/fgdorais-GMLInit", "path": "github-repos/lean/fgdorais-GMLInit/GMLInit-a295111627ac907ebc6a86f906dd9b4d69b338d8/GMLInit/Data/Set/Subset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7364751887441955}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.special_functions.exp_deriv\n\n/-!\n# Gr\u00f6nwall's inequality\n\nThe main technical result of this file is the Gr\u00f6nwall-like inequality\n`norm_le_gronwall_bound_of_norm_deriv_right_le`. It states that if `f : \u211d \u2192 E` satisfies `\u2016f a\u2016 \u2264 \u03b4`\nand `\u2200 x \u2208 [a, b), \u2016f' x\u2016 \u2264 K * \u2016f x\u2016 + \u03b5`, then for all `x \u2208 [a, b]` we have `\u2016f x\u2016 \u2264 \u03b4 * exp (K *\nx) + (\u03b5 / K) * (exp (K * x) - 1)`.\n\nThen we use this inequality to prove some estimates on the possible rate of growth of the distance\nbetween two approximate or exact solutions of an ordinary differential equation.\n\nThe proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*,\nSec. 4.5][HubbardWest-ode], where `norm_le_gronwall_bound_of_norm_deriv_right_le` is called\n\u201cFundamental Inequality\u201d.\n\n## TODO\n\n- Once we have FTC, prove an inequality for a function satisfying `\u2016f' x\u2016 \u2264 K x * \u2016f x\u2016 + \u03b5`,\n  or more generally `liminf_{y\u2192x+0} (f y - f x)/(y - x) \u2264 K x * f x + \u03b5` with any sign\n  of `K x` and `f x`.\n-/\n\nvariables {E : Type*} [normed_add_comm_group E] [normed_space \u211d E]\n          {F : Type*} [normed_add_comm_group F] [normed_space \u211d F]\n\nopen metric set asymptotics filter real\nopen_locale classical topology nnreal\n\n/-! ### Technical lemmas about `gronwall_bound` -/\n\n/-- Upper bound used in several Gr\u00f6nwall-like inequalities. -/\nnoncomputable def gronwall_bound (\u03b4 K \u03b5 x : \u211d) : \u211d :=\nif K = 0 then \u03b4 + \u03b5 * x else \u03b4 * exp (K * x) + (\u03b5 / K) * (exp (K * x) - 1)\n\nlemma gronwall_bound_K0 (\u03b4 \u03b5 : \u211d) : gronwall_bound \u03b4 0 \u03b5 = \u03bb x, \u03b4 + \u03b5 * x :=\nfunext $ \u03bb x, if_pos rfl\n\nlemma gronwall_bound_of_K_ne_0 {\u03b4 K \u03b5 : \u211d} (hK : K \u2260 0) :\n  gronwall_bound \u03b4 K \u03b5 = \u03bb x, \u03b4 * exp (K * x) + (\u03b5 / K) * (exp (K * x) - 1) :=\nfunext $ \u03bb x, if_neg hK\n\nlemma has_deriv_at_gronwall_bound (\u03b4 K \u03b5 x : \u211d) :\n  has_deriv_at (gronwall_bound \u03b4 K \u03b5) (K * (gronwall_bound \u03b4 K \u03b5 x) + \u03b5) x :=\nbegin\n  by_cases hK : K = 0,\n  { subst K,\n    simp only [gronwall_bound_K0, zero_mul, zero_add],\n    convert ((has_deriv_at_id x).const_mul \u03b5).const_add \u03b4,\n    rw [mul_one] },\n  { simp only [gronwall_bound_of_K_ne_0 hK],\n    convert (((has_deriv_at_id x).const_mul K).exp.const_mul \u03b4).add\n      ((((has_deriv_at_id x).const_mul K).exp.sub_const 1).const_mul (\u03b5 / K)) using 1,\n    simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel' _ hK],\n    ring }\nend\n\nlemma has_deriv_at_gronwall_bound_shift (\u03b4 K \u03b5 x a : \u211d) :\n  has_deriv_at (\u03bb y, gronwall_bound \u03b4 K \u03b5 (y - a)) (K * (gronwall_bound \u03b4 K \u03b5 (x - a)) + \u03b5) x :=\nbegin\n  convert (has_deriv_at_gronwall_bound \u03b4 K \u03b5 _).comp x ((has_deriv_at_id x).sub_const a),\n  rw [id, mul_one]\nend\n\nlemma gronwall_bound_x0 (\u03b4 K \u03b5 : \u211d) : gronwall_bound \u03b4 K \u03b5 0 = \u03b4 :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound, if_pos hK, mul_zero, add_zero] },\n  { simp only [gronwall_bound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] }\nend\n\nlemma gronwall_bound_\u03b50 (\u03b4 K x : \u211d) : gronwall_bound \u03b4 K 0 x = \u03b4 * exp (K * x) :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] },\n  { simp only [gronwall_bound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] }\nend\n\nlemma gronwall_bound_\u03b50_\u03b40 (K x : \u211d) : gronwall_bound 0 K 0 x = 0 :=\nby simp only [gronwall_bound_\u03b50, zero_mul]\n\nlemma gronwall_bound_continuous_\u03b5 (\u03b4 K x : \u211d) : continuous (\u03bb \u03b5, gronwall_bound \u03b4 K \u03b5 x) :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound_K0, hK],\n    exact continuous_const.add (continuous_id.mul continuous_const) },\n  { simp only [gronwall_bound_of_K_ne_0 hK],\n    exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) }\nend\n\n/-! ### Inequality and corollaries -/\n\n/-- A Gr\u00f6nwall-like inequality: if `f : \u211d \u2192 \u211d` is continuous on `[a, b]` and satisfies\nthe inequalities `f a \u2264 \u03b4` and\n`\u2200 x \u2208 [a, b), liminf_{z\u2192x+0} (f z - f x)/(z - x) \u2264 K * (f x) + \u03b5`, then `f x`\nis bounded by `gronwall_bound \u03b4 K \u03b5 (x - a)` on `[a, b]`.\n\nSee also `norm_le_gronwall_bound_of_norm_deriv_right_le` for a version bounding `\u2016f x\u2016`,\n`f : \u211d \u2192 E`. -/\ntheorem le_gronwall_bound_of_liminf_deriv_right_le {f f' : \u211d \u2192 \u211d} {\u03b4 K \u03b5 : \u211d} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 x \u2208 Ico a b, \u2200 r, f' x < r \u2192\n    \u2203\u1da0 z in \ud835\udcdd[>] x, (z - x)\u207b\u00b9 * (f z - f x) < r)\n  (ha : f a \u2264 \u03b4) (bound : \u2200 x \u2208 Ico a b, f' x \u2264 K * f x + \u03b5) :\n  \u2200 x \u2208 Icc a b, f x \u2264 gronwall_bound \u03b4 K \u03b5 (x - a) :=\nbegin\n  have H : \u2200 x \u2208 Icc a b, \u2200 \u03b5' \u2208 Ioi \u03b5, f x \u2264 gronwall_bound \u03b4 K \u03b5' (x - a),\n  { assume x hx \u03b5' h\u03b5',\n    apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf',\n    { rwa [sub_self, gronwall_bound_x0] },\n    { exact \u03bb x, has_deriv_at_gronwall_bound_shift \u03b4 K \u03b5' x a },\n    { assume x hx hfB,\n      rw [\u2190 hfB],\n      apply lt_of_le_of_lt (bound x hx),\n      exact add_lt_add_left h\u03b5' _ },\n    { exact hx } },\n  assume x hx,\n  change f x \u2264 (\u03bb \u03b5', gronwall_bound \u03b4 K \u03b5' (x - a)) \u03b5,\n  convert continuous_within_at_const.closure_le _ _ (H x hx),\n  { simp only [closure_Ioi, left_mem_Ici] },\n  exact (gronwall_bound_continuous_\u03b5 \u03b4 K (x - a)).continuous_within_at\nend\n\n/-- A Gr\u00f6nwall-like inequality: if `f : \u211d \u2192 E` is continuous on `[a, b]`, has right derivative\n`f' x` at every point `x \u2208 [a, b)`, and satisfies the inequalities `\u2016f a\u2016 \u2264 \u03b4`,\n`\u2200 x \u2208 [a, b), \u2016f' x\u2016 \u2264 K * \u2016f x\u2016 + \u03b5`, then `\u2016f x\u2016` is bounded by `gronwall_bound \u03b4 K \u03b5 (x - a)`\non `[a, b]`. -/\ntheorem norm_le_gronwall_bound_of_norm_deriv_right_le {f f' : \u211d \u2192 E} {\u03b4 K \u03b5 : \u211d} {a b : \u211d}\n  (hf : continuous_on f (Icc a b)) (hf' : \u2200 x \u2208 Ico a b, has_deriv_within_at f (f' x) (Ici x) x)\n  (ha : \u2016f a\u2016 \u2264 \u03b4) (bound : \u2200 x \u2208 Ico a b, \u2016f' x\u2016 \u2264 K * \u2016f x\u2016 + \u03b5) :\n  \u2200 x \u2208 Icc a b, \u2016f x\u2016 \u2264 gronwall_bound \u03b4 K \u03b5 (x - a) :=\nle_gronwall_bound_of_liminf_deriv_right_le (continuous_norm.comp_continuous_on hf)\n  (\u03bb x hx r hr, (hf' x hx).liminf_right_slope_norm_le hr) ha bound\n\n/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in some time-dependent set `s t`,\nand assumes that the solutions never leave this set. -/\ntheorem dist_le_of_approx_trajectories_ODE_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g f' g' : \u211d \u2192 E} {a b : \u211d} {\u03b5f \u03b5g \u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (f' t) (Ici t) t)\n  (f_bound : \u2200 t \u2208 Ico a b, dist (f' t) (v t (f t)) \u2264 \u03b5f)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (g' t) (Ici t) t)\n  (g_bound : \u2200 t \u2208 Ico a b, dist (g' t) (v t (g t)) \u2264 \u03b5g)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 gronwall_bound \u03b4 K (\u03b5f + \u03b5g) (t - a) :=\nbegin\n  simp only [dist_eq_norm] at ha \u22a2,\n  have h_deriv : \u2200 t \u2208 Ico a b, has_deriv_within_at (\u03bb t, f t - g t) (f' t - g' t) (Ici t) t,\n    from \u03bb t ht, (hf' t ht).sub (hg' t ht),\n  apply norm_le_gronwall_bound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha,\n  assume t ht,\n  have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)),\n  rw [dist_eq_norm] at this,\n  refine this.trans ((add_le_add (add_le_add (f_bound t ht) (g_bound t ht))\n    (hv t (f t) (hfs t ht) (g t) (hgs t ht))).trans _),\n  rw [dist_eq_norm, add_comm]\nend\n\n/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in the whole space. -/\ntheorem dist_le_of_approx_trajectories_ODE {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g f' g' : \u211d \u2192 E} {a b : \u211d} {\u03b5f \u03b5g \u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (f' t) (Ici t) t)\n  (f_bound : \u2200 t \u2208 Ico a b, dist (f' t) (v t (f t)) \u2264 \u03b5f)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (g' t) (Ici t) t)\n  (g_bound : \u2200 t \u2208 Ico a b, dist (g' t) (v t (g t)) \u2264 \u03b5g)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 gronwall_bound \u03b4 K (\u03b5f + \u03b5g) (t - a) :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\ndist_le_of_approx_trajectories_ODE_of_mem_set (\u03bb t x hx y hy, (hv t).dist_le_mul x y)\n  hf hf' f_bound hfs hg hg' g_bound (\u03bb t ht, trivial) ha\n\n/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in some time-dependent set `s t`,\nand assumes that the solutions never leave this set. -/\ntheorem dist_le_of_trajectories_ODE_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g : \u211d \u2192 E} {a b : \u211d} {\u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 \u03b4 * exp (K * (t - a)) :=\nbegin\n  have f_bound : \u2200 t \u2208 Ico a b, dist (v t (f t)) (v t (f t)) \u2264 0,\n    by { intros, rw [dist_self] },\n  have g_bound : \u2200 t \u2208 Ico a b, dist (v t (g t)) (v t (g t)) \u2264 0,\n    by { intros, rw [dist_self] },\n  assume t ht,\n  have := dist_le_of_approx_trajectories_ODE_of_mem_set hv hf hf' f_bound hfs hg hg' g_bound\n    hgs ha t ht,\n  rwa [zero_add, gronwall_bound_\u03b50] at this,\nend\n\n/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in the whole space. -/\ntheorem dist_le_of_trajectories_ODE {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g : \u211d \u2192 E} {a b : \u211d} {\u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 \u03b4 * exp (K * (t - a)) :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\ndist_le_of_trajectories_ODE_of_mem_set (\u03bb t x hx y hy, (hv t).dist_le_mul x y)\n  hf hf' hfs hg hg' (\u03bb t ht, trivial) ha\n\n/-- There exists only one solution of an ODE \\(\\dot x=v(t, x)\\) in a set `s \u2286 \u211d \u00d7 E` with\na given initial value provided that RHS is Lipschitz continuous in `x` within `s`,\nand we consider only solutions included in `s`. -/\ntheorem ODE_solution_unique_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g : \u211d \u2192 E} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : f a = g a) :\n  \u2200 t \u2208 Icc a b, f t = g t :=\nbegin\n  assume t ht,\n  have := dist_le_of_trajectories_ODE_of_mem_set hv hf hf' hfs hg hg' hgs\n    (dist_le_zero.2 ha) t ht,\n  rwa [zero_mul, dist_le_zero] at this\nend\n\n/-- There exists only one solution of an ODE \\(\\dot x=v(t, x)\\) with\na given initial value provided that RHS is Lipschitz continuous in `x`. -/\ntheorem ODE_solution_unique {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g : \u211d \u2192 E} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (ha : f a = g a) :\n  \u2200 t \u2208 Icc a b, f t = g t :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\nODE_solution_unique_of_mem_set (\u03bb t x hx y hy, (hv t).dist_le_mul x y)\n  hf hf' hfs hg hg' (\u03bb t ht, trivial) ha\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/ODE/gronwall.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7364751791412603}}
{"text": "import algebra.order data.fintype group_theory.subgroup data.set.basic data.rat\n\nvariables {G : Type*} [group G]\nvariables (H K : set G)\nvariables [is_subgroup H] [is_subgroup K]\n\ndefinition is_cyclic (G : Type*) [group G] := \u2203 x : G, gpowers x = set.univ\n-- 1. Let G be a group. For each of the following statements, say whether or not it is true in general, and give a proof or a counterexample.\n\n-- (a) If G is not cyclic then G is not abelian.\n    -- False (e.g : (\u211d,+))\n\n-- (b) For every element g of G there is an abelian subgroup of G which contains g.\n--theorem sheet06_q1b (G : Type*) (g : G) (H : Type*) [comm_group H]: \u2203 H \u2227 g \u2208 H := sorry\n--theorem sheet06_q1b (G : Type*) : exists H : set G, [is_subgroup H] \u2227 (\u2200 a b \u2208 H, a * b = b * a) := sorry \n\n\n-- (c) If G = \u27e8g\u27e9 is an infinite cyclic group, then the only generators for G are g and g\u207b\u00b9.\n--theorem sheet06_q1c (G : Type*) : is_cyclic G \u2192 (gpowers g = G) \u2227 (gpowers g\u207b\u00b9 = G) := sorry \n\n-- (d) If G is infinite then G has an element of infinite order.\n    -- False (e.g: set of all complex roots of unity)\n\n-- (e) If the order of every non-identity element of G is a prime number, then G is cyclic.\n--theorem sheet06_q1e (G : Type*) (g : G) (g \u2260 1) (order_of g : prime) : is_cyclic G := sorry\n\n-- (f) If G has order 4, then G is abelian.\n    --False. (e.g: Klein Four Group)\n\n-- (g) If G is abelian then every subgroup of G is abelian.\n--theorem sheet06_q1g (G : Type*) [comm_group G] (H : set G) [is_subgroup H] : comm_group H := sorry  \n\n-- (h) If G is cyclic then every subgroup of G is cyclic.\n--theorem sheet06_q1h (G : Type*) : is_cyclic G \u2192 is_cyclic H := sorry\n\n-- (i) If x, y \u2208 G, then x and y\u207b\u00b9xy have the same order.\n-- theorem sheet06_q1i (G : Type*) (x y : G): order_of x = order_of (y\u207b\u00b9 * x * y) := sorry\n\n-- (j) If x,y \u2208 G have order 2, then xy has order 2.\n    -- False. (e.g:(1,2),(2,3)\u2208 S\u2083)\n\ndefinition gsymmetric (n : \u2115) := equiv.perm (fin n)\n\n-- *2. (a) Write down all of the cycle shapes of the elements of S\u2085. For each cycle shape, calculate how many elements there are with that shape. (Check that your answers add up to |S\u2085| = 120.)\n-- theorem sheet06_q2a:\n\n-- (b) How many elements of S\u2085 have order 2?\n-- theorem sheet06_q2b:\n\n-- (c) How many subgroups of size 3 are there in the group S\u2085?\n-- theorem sheet06_q2c:\n\n-- 3. (a) Let H\u2081 be the cyclic subgroup \u27e8(1234)\u27e9 of S\u2084 . Write down the right cosets of H in S\u2084.\n-- theorem sheet06_q2d:\n\n-- (b) Find a subgroup H\u2082 of S\u2084 of order 4, in which all of the non-identity elements have the same cycle shape. Write down its right cosets in S\u2084.\n-- theorem sheet06_q2e:\n\n-- (c) Which of the right cosets you have found for H\u2081 and H\u2082 are also left cosets?\n-- theorem sheet06_q2f:\n\n-- 4. Let G be a finite group of order n, and H a subgroup of G of order m.\n\n-- (a) For x,y \u2208 G, show that Hx = Hy \u21d0\u21d2 xy\u207b\u00b9 \u2208 H.\n-- theorem sheet06_q4a (x y : G) : x * l  = x * l \u2194 x * y\u207b\u00b9 \u2208 H := sorry \n\n-- (c) Give an example to show that in (b), the integer k need not divide r.\n-- theorem sheet06_q4c:\n\n-- 5. Let G be a group,and let S be a subset of G.We say that S generates G if every element in G can be written as a product of elements of S and their inverses. (For example, if G is the cyclic group \u27e8g\u27e9, then {g} generates G.)\n-- theorem sheet06_q4d:\n\n-- (a) Let 2\u2264k\u2264n. Show that a k-cycle (a1 ...,ak)in Sn can be written as a product of k\u22121 distinct cycles of length 2. Deduce that the set of 2-cycles in Sn generates Sn.\n-- theorem sheet06_q4e:\n\n-- (b) Show that the group (Q, +) is not generated by any finite subset.\n--theorem sheet06_q4f (:\n\n-- bit0 stands for the binary representation of 2*n. n in binary -> 2*n appends a zero\n#print bit0", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1P2/sheet_6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7364751773833239}}
{"text": "/-\nCopyright (c) 2022 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Devon Tuma\n-/\nimport probability.probability_mass_function.constructions\n\n/-!\n# Uniform Probability Mass Functions\n\nThis file defines a number of uniform `pmf` distributions from various inputs,\n  uniformly drawing from the corresponding object.\n\n`pmf.uniform_of_finset` gives each element in the set equal probability,\n  with `0` probability for elements not in the set.\n\n`pmf.uniform_of_fintype` gives all elements equal probability,\n  equal to the inverse of the size of the `fintype`.\n\n`pmf.of_multiset` draws randomly from the given `multiset`, treating duplicate values as distinct.\n  Each probability is given by the count of the element divided by the size of the `multiset`\n\n-/\n\nnamespace pmf\n\nnoncomputable theory\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\nopen_locale classical big_operators nnreal ennreal\n\nsection uniform_of_finset\n\n/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/\ndef uniform_of_finset (s : finset \u03b1) (hs : s.nonempty) : pmf \u03b1 :=\nof_finset (\u03bb a, if a \u2208 s then s.card\u207b\u00b9 else 0) s (Exists.rec_on hs (\u03bb x hx,\n  calc \u2211 (a : \u03b1) in s, ite (a \u2208 s) (s.card : \u211d\u22650\u221e)\u207b\u00b9 0\n    = \u2211 (a : \u03b1) in s, (s.card : \u211d\u22650\u221e)\u207b\u00b9 : finset.sum_congr rfl (\u03bb x hx, by simp [hx])\n    ... = (s.card : \u211d\u22650\u221e) * (s.card : \u211d\u22650\u221e)\u207b\u00b9 : by rw [finset.sum_const, nsmul_eq_mul]\n    ... = 1 : ennreal.mul_inv_cancel (by simpa only [ne.def, nat.cast_eq_zero, finset.card_eq_zero]\n      using (finset.nonempty_iff_ne_empty.1 hs)) (ennreal.nat_ne_top s.card)))\n        (\u03bb x hx, by simp only [hx, if_false])\n\nvariables {s : finset \u03b1} (hs : s.nonempty) {a : \u03b1}\n\n@[simp] lemma uniform_of_finset_apply (a : \u03b1) :\n  uniform_of_finset s hs a = if a \u2208 s then s.card\u207b\u00b9 else 0 := rfl\n\nlemma uniform_of_finset_apply_of_mem (ha : a \u2208 s) : uniform_of_finset s hs a = (s.card)\u207b\u00b9 :=\nby simp [ha]\n\nlemma uniform_of_finset_apply_of_not_mem (ha : a \u2209 s) : uniform_of_finset s hs a = 0 :=\nby simp [ha]\n\n@[simp] lemma support_uniform_of_finset : (uniform_of_finset s hs).support = s :=\nset.ext (let \u27e8a, ha\u27e9 := hs in by simp [mem_support_iff, finset.ne_empty_of_mem ha])\n\nlemma mem_support_uniform_of_finset_iff (a : \u03b1) : a \u2208 (uniform_of_finset s hs).support \u2194 a \u2208 s :=\nby simp\n\nsection measure\n\nvariable (t : set \u03b1)\n\n@[simp] lemma to_outer_measure_uniform_of_finset_apply :\n  (uniform_of_finset s hs).to_outer_measure t = (s.filter (\u2208 t)).card / s.card :=\ncalc (uniform_of_finset s hs).to_outer_measure t\n  = \u2211' x, if x \u2208 t then (uniform_of_finset s hs x) else 0 :\n    to_outer_measure_apply (uniform_of_finset s hs) t\n  ... = \u2211' x, if x \u2208 s \u2227 x \u2208 t then (s.card : \u211d\u22650\u221e)\u207b\u00b9 else 0 :\n    (tsum_congr (\u03bb x, by simp only [uniform_of_finset_apply,\n      and_comm (x \u2208 s), ite_and, ennreal.coe_nat]))\n  ... = (\u2211 x in (s.filter (\u2208 t)), if x \u2208 s \u2227 x \u2208 t then (s.card : \u211d\u22650\u221e)\u207b\u00b9 else 0) :\n    (tsum_eq_sum (\u03bb x hx, if_neg (\u03bb h, hx (finset.mem_filter.2 h))))\n  ... = (\u2211 x in (s.filter (\u2208 t)), (s.card : \u211d\u22650\u221e)\u207b\u00b9) :\n    (finset.sum_congr rfl $ \u03bb x hx, let this : x \u2208 s \u2227 x \u2208 t := by simpa using hx in\n      by simp only [this, and_self, if_true])\n  ... = (s.filter (\u2208 t)).card / s.card :\n    have (s.card : \u211d\u22650\u221e) \u2260 0 := nat.cast_ne_zero.2 (hs.rec_on $ \u03bb _, finset.card_ne_zero_of_mem),\n    by simp only [div_eq_mul_inv, finset.sum_const, nsmul_eq_mul]\n\n@[simp] lemma to_measure_uniform_of_finset_apply [measurable_space \u03b1] (ht : measurable_set t) :\n  (uniform_of_finset s hs).to_measure t = (s.filter (\u2208 t)).card / s.card :=\n(to_measure_apply_eq_to_outer_measure_apply _ t ht).trans\n  (to_outer_measure_uniform_of_finset_apply hs t)\n\nend measure\n\nend uniform_of_finset\n\nsection uniform_of_fintype\n\n/-- The uniform pmf taking the same uniform value on all of the fintype `\u03b1` -/\ndef uniform_of_fintype (\u03b1 : Type*) [fintype \u03b1] [nonempty \u03b1] : pmf \u03b1 :=\n  uniform_of_finset (finset.univ) (finset.univ_nonempty)\n\nvariables [fintype \u03b1] [nonempty \u03b1]\n\n@[simp] lemma uniform_of_fintype_apply (a : \u03b1) : uniform_of_fintype \u03b1 a = (fintype.card \u03b1)\u207b\u00b9 :=\nby simpa only [uniform_of_fintype, finset.mem_univ, if_true, uniform_of_finset_apply]\n\n@[simp] lemma support_uniform_of_fintype (\u03b1 : Type*) [fintype \u03b1] [nonempty \u03b1] :\n  (uniform_of_fintype \u03b1).support = \u22a4 :=\nset.ext (\u03bb x, by simp [mem_support_iff])\n\nlemma mem_support_uniform_of_fintype (a : \u03b1) : a \u2208 (uniform_of_fintype \u03b1).support := by simp\n\nsection measure\n\nvariable (s : set \u03b1)\n\nlemma to_outer_measure_uniform_of_fintype_apply :\n  (uniform_of_fintype \u03b1).to_outer_measure s = fintype.card s / fintype.card \u03b1 :=\nby simpa [uniform_of_fintype]\n\nlemma to_measure_uniform_of_fintype_apply [measurable_space \u03b1] (hs : measurable_set s) :\n  (uniform_of_fintype \u03b1).to_measure s = fintype.card s / fintype.card \u03b1 :=\nby simpa [uniform_of_fintype, hs]\n\nend measure\n\nend uniform_of_fintype\n\nsection of_multiset\n\n/-- Given a non-empty multiset `s` we construct the `pmf` which sends `a` to the fraction of\n  elements in `s` that are `a`. -/\ndef of_multiset (s : multiset \u03b1) (hs : s \u2260 0) : pmf \u03b1 :=\n\u27e8\u03bb a, s.count a / s.card, ennreal.summable.has_sum_iff.2\n  (calc \u2211' (b : \u03b1), (s.count b : \u211d\u22650\u221e) / s.card = s.card\u207b\u00b9 * \u2211' b, s.count b :\n      by simp_rw [ennreal.div_eq_inv_mul, ennreal.tsum_mul_left]\n    ... = s.card\u207b\u00b9 * \u2211 b in s.to_finset, (s.count b : \u211d\u22650\u221e) :\n      congr_arg (\u03bb x, s.card\u207b\u00b9 * x) (tsum_eq_sum $ \u03bb a ha, (nat.cast_eq_zero.2 $\n        by rwa [multiset.count_eq_zero, \u2190 multiset.mem_to_finset]))\n    ... = 1 : by rw [\u2190 nat.cast_sum, multiset.to_finset_sum_count_eq s, ennreal.inv_mul_cancel\n      (nat.cast_ne_zero.2 (hs \u2218 multiset.card_eq_zero.1)) (ennreal.nat_ne_top _)] ) \u27e9\n\nvariables {s : multiset \u03b1} (hs : s \u2260 0)\n\n@[simp] lemma of_multiset_apply (a : \u03b1) : of_multiset s hs a = s.count a / s.card := rfl\n\n@[simp] lemma support_of_multiset : (of_multiset s hs).support = s.to_finset :=\nset.ext (by simp [mem_support_iff, hs])\n\n\n\nlemma of_multiset_apply_of_not_mem {a : \u03b1} (ha : a \u2209 s) : of_multiset s hs a = 0 :=\nby simpa only [of_multiset_apply, ennreal.div_zero_iff, nat.cast_eq_zero,\n  multiset.count_eq_zero, ennreal.nat_ne_top, or_false] using ha\n\nsection measure\n\nvariable (t : set \u03b1)\n\n@[simp] lemma to_outer_measure_of_multiset_apply :\n  (of_multiset s hs).to_outer_measure t = (\u2211' x, (s.filter (\u2208 t)).count x) / s.card :=\nbegin\n  rw [div_eq_mul_inv, \u2190 ennreal.tsum_mul_right, to_outer_measure_apply],\n  refine tsum_congr (\u03bb x, _),\n  by_cases hx : x \u2208 t;\n  simp [set.indicator, hx, div_eq_mul_inv],\nend\n\n@[simp] lemma to_measure_of_multiset_apply [measurable_space \u03b1] (ht : measurable_set t) :\n  (of_multiset s hs).to_measure t = (\u2211' x, (s.filter (\u2208 t)).count x) / s.card :=\n(to_measure_apply_eq_to_outer_measure_apply _ t ht).trans\n  (to_outer_measure_of_multiset_apply hs t)\n\nend measure\n\nend of_multiset\n\nend pmf\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/probability/probability_mass_function/uniform.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7364751757599015}}
{"text": "/-\nPorted by Deniz Aydin from the lean3 prelude:\nhttps://github.com/leanprover-community/lean/blob/master/library/init/algebra/order.lean\n\nOriginal file's license:\n  Copyright (c) 2016 Microsoft Corporation. All rights reserved.\n  Released under Apache 2.0 license as described in the file LICENSE.\n  Authors: Leonardo de Moura\n-/\nimport Mathlib.Init.Logic\n\n/-!\n# Orders\n\nDefines classes for preorders, partial orders, and linear orders\nand proves some basic lemmas about them.\n-/\n\n/-\nTODO: Does Lean4 have an equivalent for this:\n  Make sure instances defined in this file have lower priority than the ones\n  defined for concrete structures\nset_option default_priority 100\n-/\n\nuniverse u\nvariable {\u03b1 : Type u}\n\n-- set_option auto_param.check_exists false\n\nsection Preorder\n\n/-!\n### Definition of `Preorder` and lemmas about types with a `Preorder`\n-/\n\n/-- A preorder is a reflexive, transitive relation `\u2264` with `a < b` defined in the obvious way. -/\nclass Preorder (\u03b1 : Type u) extends LE \u03b1, LT \u03b1 :=\n(le_refl : \u2200 a : \u03b1, a \u2264 a)\n(le_trans : \u2200 a b c : \u03b1, a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c)\n(lt := \u03bb a b => a \u2264 b \u2227 \u00ac b \u2264 a)\n(lt_iff_le_not_le : \u2200 a b : \u03b1, a < b \u2194 (a \u2264 b \u2227 \u00ac b \u2264 a)) -- . order_laws_tac)\n\nvariable [Preorder \u03b1]\n\n/-- The relation `\u2264` on a preorder is reflexive. -/\n@[simp] theorem le_refl : \u2200 (a : \u03b1), a \u2264 a :=\nPreorder.le_refl\n\n/-- The relation `\u2264` on a preorder is transitive. -/\ntheorem le_trans : \u2200 {a b c : \u03b1}, a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c :=\nPreorder.le_trans _ _ _\n\ntheorem lt_iff_le_not_le : \u2200 {a b : \u03b1}, a < b \u2194 (a \u2264 b \u2227 \u00ac b \u2264 a) :=\nPreorder.lt_iff_le_not_le _ _\n\ntheorem lt_of_le_not_le : \u2200 {a b : \u03b1}, a \u2264 b \u2192 \u00ac b \u2264 a \u2192 a < b\n| a, b, hab, hba => lt_iff_le_not_le.mpr \u27e8hab, hba\u27e9\n\ntheorem le_not_le_of_lt : \u2200 {a b : \u03b1}, a < b \u2192 a \u2264 b \u2227 \u00ac b \u2264 a\n| a, b, hab => lt_iff_le_not_le.mp hab\n\ntheorem le_of_eq {a b : \u03b1} : a = b \u2192 a \u2264 b :=\n\u03bb h => h \u25b8 le_refl a\n\ntheorem ge_trans : \u2200 {a b c : \u03b1}, a \u2265 b \u2192 b \u2265 c \u2192 a \u2265 c :=\n\u03bb h\u2081 h\u2082 => le_trans h\u2082 h\u2081\n\ntheorem lt_irrefl : \u2200 a : \u03b1, \u00ac a < a\n| a, haa => match le_not_le_of_lt haa with\n  | \u27e8h1, h2\u27e9 => h2 h1\n\ntheorem gt_irrefl : \u2200 a : \u03b1, \u00ac a > a :=\nlt_irrefl\n\ntheorem lt_trans : \u2200 {a b c : \u03b1}, a < b \u2192 b < c \u2192 a < c\n| a, b, c, hab, hbc =>\n  match le_not_le_of_lt hab, le_not_le_of_lt hbc with\n  | \u27e8hab, hba\u27e9, \u27e8hbc, hcb\u27e9 => lt_of_le_not_le (le_trans hab hbc) (\u03bb hca => hcb (le_trans hca hab))\n\ntheorem gt_trans : \u2200 {a b c : \u03b1}, a > b \u2192 b > c \u2192 a > c :=\n\u03bb h\u2081 h\u2082 => lt_trans h\u2082 h\u2081\n\ntheorem ne_of_lt {a b : \u03b1} (h : a < b) : a \u2260 b :=\n\u03bb he => absurd h (he \u25b8 lt_irrefl a)\n\ntheorem ne_of_gt {a b : \u03b1} (h : b < a) : a \u2260 b :=\n\u03bb he => absurd h (he \u25b8 lt_irrefl a)\n\ntheorem lt_asymm {a b : \u03b1} (h : a < b) : \u00ac b < a :=\n\u03bb h1 : b < a => lt_irrefl a (lt_trans h h1)\n\ntheorem le_of_lt : \u2200 {a b : \u03b1}, a < b \u2192 a \u2264 b\n| a, b, hab => (le_not_le_of_lt hab).left\n\ntheorem lt_of_lt_of_le : \u2200 {a b c : \u03b1}, a < b \u2192 b \u2264 c \u2192 a < c\n| a, b, c, hab, hbc =>\n  let \u27e8hab, hba\u27e9 := le_not_le_of_lt hab\n  lt_of_le_not_le (le_trans hab hbc) $ \u03bb hca => hba (le_trans hbc hca)\n\ntheorem lt_of_le_of_lt : \u2200 {a b c : \u03b1}, a \u2264 b \u2192 b < c \u2192 a < c\n| a, b, c, hab, hbc =>\n  let \u27e8hbc, hcb\u27e9 := le_not_le_of_lt hbc\n  lt_of_le_not_le (le_trans hab hbc) $ \u03bb hca => hcb (le_trans hca hab)\n\ntheorem gt_of_gt_of_ge {a b c : \u03b1} (h\u2081 : a > b) (h\u2082 : b \u2265 c) : a > c :=\nlt_of_le_of_lt h\u2082 h\u2081\n\ntheorem gt_of_ge_of_gt {a b c : \u03b1} (h\u2081 : a \u2265 b) (h\u2082 : b > c) : a > c :=\nlt_of_lt_of_le h\u2082 h\u2081\n\ninstance : @Trans \u03b1 \u03b1 \u03b1 LE.le LE.le LE.le := \u27e8le_trans\u27e9\ninstance : @Trans \u03b1 \u03b1 \u03b1 LT.lt LE.le LT.lt := \u27e8lt_of_lt_of_le\u27e9\ninstance : @Trans \u03b1 \u03b1 \u03b1 LE.le LT.lt LT.lt := \u27e8lt_of_le_of_lt\u27e9\ninstance : @Trans \u03b1 \u03b1 \u03b1 GE.ge GE.ge GE.ge := \u27e8ge_trans\u27e9\ninstance : @Trans \u03b1 \u03b1 \u03b1 GT.gt GE.ge GT.gt := \u27e8gt_of_gt_of_ge\u27e9\ninstance : @Trans \u03b1 \u03b1 \u03b1 GE.ge GT.gt GT.gt := \u27e8gt_of_ge_of_gt\u27e9\n\ntheorem not_le_of_gt {a b : \u03b1} (h : a > b) : \u00ac a \u2264 b :=\n(le_not_le_of_lt h).right\n\ntheorem not_lt_of_ge {a b : \u03b1} (h : a \u2265 b) : \u00ac a < b :=\n\u03bb hab => not_le_of_gt hab h\n\ntheorem le_of_lt_or_eq : \u2200 {a b : \u03b1}, (a < b \u2228 a = b) \u2192 a \u2264 b\n| a, b, (Or.inl hab) => le_of_lt hab\n| a, b, (Or.inr hab) => hab \u25b8 le_refl _\n\ntheorem le_of_eq_or_lt {a b : \u03b1} (h : a = b \u2228 a < b) : a \u2264 b := match h with\n| (Or.inl h) => le_of_eq h\n| (Or.inr h) => le_of_lt h\n\ninstance decidableLt_of_decidableLe [DecidableRel (. \u2264 . : \u03b1 \u2192 \u03b1 \u2192 Prop)] :\n  DecidableRel (. < . : \u03b1 \u2192 \u03b1 \u2192 Prop)\n| a, b =>\n  if hab : a \u2264 b then\n    if hba : b \u2264 a then\n      isFalse $ \u03bb hab' => not_le_of_gt hab' hba\n    else\n      isTrue $ lt_of_le_not_le hab hba\n  else\n    isFalse $ \u03bb hab' => hab (le_of_lt hab')\n\nend Preorder\n\nsection PartialOrder\n\n/-!\n### Definition of `PartialOrder` and lemmas about types with a partial order\n-/\n\n/-- A partial order is a reflexive, transitive, antisymmetric relation `\u2264`. -/\nclass PartialOrder (\u03b1 : Type u) extends Preorder \u03b1 :=\n(le_antisymm : \u2200 a b : \u03b1, a \u2264 b \u2192 b \u2264 a \u2192 a = b)\n\nvariable [PartialOrder \u03b1]\n\ntheorem le_antisymm : \u2200 {a b : \u03b1}, a \u2264 b \u2192 b \u2264 a \u2192 a = b :=\nPartialOrder.le_antisymm _ _\n\ntheorem le_antisymm_iff {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 b \u2264 a :=\n\u27e8\u03bb e => \u27e8le_of_eq e, le_of_eq e.symm\u27e9, \u03bb \u27e8h1, h2\u27e9 => le_antisymm h1 h2\u27e9\n\ntheorem lt_of_le_of_ne {a b : \u03b1} : a \u2264 b \u2192 a \u2260 b \u2192 a < b :=\n\u03bb h\u2081 h\u2082 => lt_of_le_not_le h\u2081 $ mt (le_antisymm h\u2081) h\u2082\n\ninstance decidableEq_of_decidableLe [DecidableRel (. \u2264 . : \u03b1 \u2192 \u03b1 \u2192 Prop)] :\n  DecidableEq \u03b1\n| a, b =>\n  if hab : a \u2264 b then\n    if hba : b \u2264 a then\n      isTrue (le_antisymm hab hba)\n    else\n      isFalse (\u03bb heq => hba (heq \u25b8 le_refl _))\n  else\n    isFalse (\u03bb heq => hab (heq \u25b8 le_refl _))\n\nnamespace Decidable\n\nvariable [@DecidableRel \u03b1 (. \u2264 .)]\n\ntheorem lt_or_eq_of_le {a b : \u03b1} (hab : a \u2264 b) : a < b \u2228 a = b :=\nif hba : b \u2264 a then Or.inr (le_antisymm hab hba)\nelse Or.inl (lt_of_le_not_le hab hba)\n\ntheorem eq_or_lt_of_le {a b : \u03b1} (hab : a \u2264 b) : a = b \u2228 a < b :=\n(lt_or_eq_of_le hab).symm\n\ntheorem le_iff_lt_or_eq {a b : \u03b1} : a \u2264 b \u2194 a < b \u2228 a = b :=\n\u27e8lt_or_eq_of_le, le_of_lt_or_eq\u27e9\n\nend Decidable\n\nattribute [local instance] Classical.propDecidable\n\ntheorem lt_or_eq_of_le {a b : \u03b1} : a \u2264 b \u2192 a < b \u2228 a = b := Decidable.lt_or_eq_of_le\n\ntheorem le_iff_lt_or_eq {a b : \u03b1} : a \u2264 b \u2194 a < b \u2228 a = b := Decidable.le_iff_lt_or_eq\n\nend PartialOrder\n\nsection LinearOrder\n\n/-!\n### Definition of `LinearOrder` and lemmas about types with a linear order\n-/\n\n/-- A linear order is reflexive, transitive, antisymmetric and total relation `\u2264`.\nWe assume that every linear ordered type has decidable `(\u2264)`, `(<)`, and `(=)`. -/\nclass LinearOrder (\u03b1 : Type u) extends PartialOrder \u03b1 :=\n(le_total : \u2200 a b : \u03b1, a \u2264 b \u2228 b \u2264 a)\n(decidable_le : DecidableRel (. \u2264 . : \u03b1 \u2192 \u03b1 \u2192 Prop))\n(decidable_eq : DecidableEq \u03b1 := @decidableEq_of_decidableLe _ _ decidable_le)\n(decidable_lt : DecidableRel (. < . : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n    @decidableLt_of_decidableLe _ _ decidable_le)\n\nvariable [LinearOrder \u03b1]\n\nattribute [local instance] LinearOrder.decidable_le\n\ntheorem le_total : \u2200 a b : \u03b1, a \u2264 b \u2228 b \u2264 a :=\nLinearOrder.le_total\n\ntheorem le_of_not_ge {a b : \u03b1} : \u00ac a \u2265 b \u2192 a \u2264 b :=\nOr.resolve_left (le_total b a)\n\ntheorem le_of_not_le {a b : \u03b1} : \u00ac a \u2264 b \u2192 b \u2264 a :=\nOr.resolve_left (le_total a b)\n\ntheorem not_lt_of_gt {a b : \u03b1} (h : a > b) : \u00ac a < b :=\nlt_asymm h\n\ntheorem lt_trichotomy (a b : \u03b1) : a < b \u2228 a = b \u2228 b < a :=\nOr.elim\n  (le_total a b)\n  (\u03bb h : a \u2264 b   => Or.elim\n    (Decidable.lt_or_eq_of_le h)\n    (\u03bb h : a < b => Or.inl h)\n    (\u03bb h : a = b => Or.inr (Or.inl h)))\n  (\u03bb h : b \u2264 a   => Or.elim\n    (Decidable.lt_or_eq_of_le h)\n    (\u03bb h : b < a => Or.inr (Or.inr h))\n    (\u03bb h : b = a => Or.inr (Or.inl h.symm)))\n\ntheorem le_of_not_lt {a b : \u03b1} (h : \u00ac b < a) : a \u2264 b :=\nmatch lt_trichotomy a b with\n| Or.inl hlt          => le_of_lt hlt\n| Or.inr (Or.inl heq) => heq \u25b8 le_refl a\n| Or.inr (Or.inr hgt) => absurd hgt h\n\n\ntheorem le_of_not_gt {a b : \u03b1} : \u00ac a > b \u2192 a \u2264 b := le_of_not_lt\n\ntheorem lt_of_not_ge {a b : \u03b1} (h : \u00ac a \u2265 b) : a < b :=\nlt_of_le_not_le ((le_total _ _).resolve_right h) h\n\ntheorem lt_or_le (a b : \u03b1) : a < b \u2228 b \u2264 a :=\nif hba : b \u2264 a then Or.inr hba else Or.inl $ lt_of_not_ge hba\n\ntheorem le_or_lt (a b : \u03b1) : a \u2264 b \u2228 b < a :=\n(lt_or_le b a).symm\n\ntheorem lt_or_ge : \u2200 (a b : \u03b1), a < b \u2228 a \u2265 b := lt_or_le\ntheorem le_or_gt : \u2200 (a b : \u03b1), a \u2264 b \u2228 a > b := le_or_lt\n\ntheorem lt_or_gt_of_ne {a b : \u03b1} (h : a \u2260 b) : a < b \u2228 a > b :=\nmatch lt_trichotomy a b with\n| Or.inl hlt          => Or.inl hlt\n| Or.inr (Or.inl heq) => absurd heq h\n| Or.inr (Or.inr hgt) => Or.inr hgt\n\ntheorem ne_iff_lt_or_gt {a b : \u03b1} : a \u2260 b \u2194 a < b \u2228 a > b :=\n\u27e8lt_or_gt_of_ne, \u03bb o => match o with\n  | Or.inl ol => ne_of_lt ol\n  | Or.inr or => ne_of_gt or\n\u27e9\n\ntheorem lt_iff_not_ge (x y : \u03b1) : x < y \u2194 \u00ac x \u2265 y :=\n\u27e8not_le_of_gt, lt_of_not_ge\u27e9\n\n@[simp] theorem not_lt {a b : \u03b1} : \u00ac a < b \u2194 b \u2264 a := \u27e8le_of_not_gt, not_lt_of_ge\u27e9\n\n@[simp] theorem not_le {a b : \u03b1} : \u00ac a \u2264 b \u2194 b < a := (lt_iff_not_ge _ _).symm\n\ninstance (a b : \u03b1) : Decidable (a < b) :=\nLinearOrder.decidable_lt a b\n\ninstance (a b : \u03b1) : Decidable (a \u2264 b) :=\nLinearOrder.decidable_le a b\n\ninstance (a b : \u03b1) : Decidable (a = b) :=\nLinearOrder.decidable_eq a b\n\ntheorem eq_or_lt_of_not_lt {a b : \u03b1} (h : \u00ac a < b) : a = b \u2228 b < a :=\nif h\u2081 : a = b then Or.inl h\u2081\nelse Or.inr (lt_of_not_ge (\u03bb hge => h (lt_of_le_of_ne hge h\u2081)))\n\n/- TODO: instances of classes that haven't been defined.\n\ninstance : is_total_preorder \u03b1 (\u2264) :=\n{trans := @le_trans _ _, total := le_total}\n\ninstance is_strict_weak_order_of_linear_order : is_strict_weak_order \u03b1 (<) :=\nis_strict_weak_order_of_is_total_preorder lt_iff_not_ge\n\ninstance is_strict_total_order_of_linear_order : is_strict_total_order \u03b1 (<) :=\n{ trichotomous := lt_trichotomy }\n-/\n\n/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order. -/\ndef lt_by_cases (x y : \u03b1) {P : Sort _}\n (h\u2081 : x < y \u2192 P) (h\u2082 : x = y \u2192 P) (h\u2083 : y < x \u2192 P) : P :=\nif h : x < y then h\u2081 h else\nif h' : y < x then h\u2083 h' else\nh\u2082 (le_antisymm (le_of_not_gt h') (le_of_not_gt h))\n\ntheorem le_imp_le_of_lt_imp_lt {\u03b2} [Preorder \u03b1] [LinearOrder \u03b2]\n  {a b : \u03b1} {c d : \u03b2} (H : d < c \u2192 b < a) (h : a \u2264 b) : c \u2264 d :=\nle_of_not_lt $ \u03bb h' => not_le_of_gt (H h') h\n\nend LinearOrder\n", "meta": {"author": "JOSHCLUNE", "repo": "Keller_reduction", "sha": "dc392b3da352fc1ffcfbecb1d4717d05f5faed4a", "save_path": "github-repos/lean/JOSHCLUNE-Keller_reduction", "path": "github-repos/lean/JOSHCLUNE-Keller_reduction/Keller_reduction-dc392b3da352fc1ffcfbecb1d4717d05f5faed4a/Lean4_Clique/Mathlib/Mathlib/Init/Algebra/Order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.7364751701467219}}
{"text": "import tactic\nimport data.int.basic\nimport data.nat.prime\nimport number_theory.divisors\nimport algebra.big_operators.basic\nimport number_theory.arithmetic_function\n--import geom_sum\n\nopen nat.arithmetic_function\n\n\ndef divisor_sum : \u2115 \u2192 \u2115 := (\u03bb n : \u2115, n.divisors.sum id)\n\n\nlemma perfect_iff_sum_divisors_eq_two_mul' (n : \u2115) (hpos : n > 0) : nat.perfect n \u2194 divisor_sum n = 2*n :=\nbegin\n  split, {\n    intro hn,\n    rwa nat.perfect_iff_sum_divisors_eq_two_mul at hn,\n    assumption,\n  }, {\n    intro hn,\n    rwa nat.perfect_iff_sum_divisors_eq_two_mul,\n    assumption,\n  }\nend\n\n\nlemma divisor_sum_is_multiplicative (m n : \u2115) (h_coprime : m.coprime n) \n      : (sigma 1 (m*n) = sigma 1 (m) * sigma 1 (n)) :=\nbegin\n  have h := is_multiplicative_sigma,\n  have l := is_multiplicative.map_mul_of_coprime \n  \nend\n\nlemma finite_power_series (a k : \u2115) : (finset.range k).sum (\u03bb (x : \u2115), (a ^ x)) = (a^k - 1)/(a-1) :=\nbegin\n  set S := (finset.range k).sum (\u03bb (x : \u2115), a ^ x),\n  suffices hS : S = 1 + a * (S - a^(k-1)),\n  sorry,\n  sorry,\nend\n\n-- lemma divisor_sum_of_prime_pow {p k : \u2115 } (hk : k \u2265 1) (hp : nat.prime p) : ((nat.divisors (p^(k-1))).sum id = (p^k - 1)/(p-1)) :=\n-- begin\n--   rw nat.sum_divisors_prime_pow hp,\n--   -- power series\n--   have hs1 : k - 1 + 1 = k := by linarith,\n--   rw hs1,\n--   rw finite_power_series p k,\n-- end\n\n-- lemma obvious_lemma (a : \u2115) (k \u2265 1) : (2 * 2 ^ (k - 1) = 2^k) :=\n-- begin\n--   set n := k + 1,\n--   induction n with d hd,\n-- end\n\n-- \u2203 k, 2^k - 1 prime \u2192 2^(k-1) * 2^k - 1 is perfect\n\nlemma mersenne_to_perfect (k : \u2115) (hk : k > 0) (hp : nat.prime (2^k - 1)) : (nat.perfect ( 2^(k-1) * (2^k - 1))) :=\nbegin\n  rw perfect_iff_sum_divisors_eq_two_mul',\n  { \n    rw divisor_sum_is_multiplicative,\n    {\n      unfold divisor_sum,\n      rw nat.prime.sum_divisors hp,\n      have h2 : nat.prime 2 := nat.prime_two,\n      rw nat.divisors_prime_pow h2,\n      simp,\n      have hs : k - 1 + 1 = k := by linarith,\n      rw hs,\n      rw finite_power_series 2 k,\n\n\n      rw \u2190 mul_assoc,\n      have hpow : 2^k \u2265 1 := nat.one_le_pow' k 1,\n      have hs1: 2^k - 1 + 1 = 2^k := by linarith,\n      have hs2 : 2 * 2 ^ (k - 1) = 2^k,\n      {\n        zify,\n        sorry,\n      },\n      rw [hs1, hs2, mul_comm],\n    },\n\n    {\n      set d : \u2115 := nat.gcd (2 ^ (k - 1)) (2 ^ k - 1),\n      \n      \n      \n    },\n\n  },\n\n  { simpa using nat.one_lt_two_pow k hk, },\n\n\nend\n\n\n-- n is an even perfect number \u2192 n = 2^(k-1) * (2^k - 1) for some mersenne prime 2^k - 1", "meta": {"author": "Vilin97", "repo": "LLL", "sha": "ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9", "save_path": "github-repos/lean/Vilin97-LLL", "path": "github-repos/lean/Vilin97-LLL/LLL-ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9/Zachary/perfect_mersenne.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768525822309, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.7364512512558213}}
{"text": "import Mathlib.Algebra.Ring.Basic\nimport Mathlib.Algebra.Group.Defs\n\n/-!\n# Free modules \n\nWe construct the free module over a ring `R` generated by a set `X`. It is assumed that both `R` and `X` have decidable equality. \nThis is to obtain decidable equality for the elements of the module, which we do (`FreeModule.decEq`).\nWe choose our definition to allow both such computations and to prove results.\n\nThe definition is as a quotient of *Formal Sums* (`FormalSum`), \nwhich are simply lists of pairs `(a,x)` where `a` is a coefficient in `R` and `x` is a term in `X`. \nWe associate to such a formal sum a coordinate function `X \u2192 R` (`FormalSum.coords`). \nWe see that having the same coordinate functions gives an equivalence relation on the formal sums. \nThe free module (`FreeModule`) is then defined as the corresponding quotient of such formal sums.\n\nWe also give an alternative description via moves, which is more convenient for universal properties.\n-/\n\nvariable {R : Type _} [Ring R] [DecidableEq R]\n\nvariable {X : Type _} [DecidableEq X]\n\nsection FormalSumCoords\n\n/-! \n\n## Formal sums\n-/\n\n\n\n/-- A *formal sum* represents an `R`-linear combination of finitely many elements of `X`.\n  This is implemented as a list `R \u00d7 X`, which associates to each element `X` of the list a coefficient from `R`. -/\nabbrev FormalSum (R X : Type _) [Ring R] :=\n  List (R \u00d7 X)\n\n/-!\n## Coordinate functions and Supports\n\n* We define coordinate functions X \u2192 R for formal sums.\n* We define (weak) support, relate non-zero coordinates.\n* We prove decidable equality on a list (easy fact).\n\n-/\n\n/-!\n### Coordinate functions\n\nThe definition of coordinate functions is in two steps. We first define the coordinate for a pair `(a,x)`, and then define the coordinate function for a formal sum by summing over such terms.\n\n-/\n\n/-- Coordinates for a formal sum with one term. -/\ndef monomCoeff (R X : Type _) [Ring R] [DecidableEq X](x\u2080 : X) (nx : R \u00d7 X) : R :=\n  match (nx.2 == x\u2080) with\n  | true => nx.1\n  | false => 0\n\n/-- Homomorphism property for coordinates for a formal sum with one term. -/\ntheorem monom_coords_hom  (x\u2080 x : X) (a b : R) : monomCoeff R X x\u2080 (a + b, x) = monomCoeff R X x\u2080 (a, x) + monomCoeff R X x\u2080 (b, x) := by\n  repeat\n    (\n      rw [monomCoeff])\n  cases x == x\u2080 <;> simp\n\n/-- Associativity of scalar multiplication coordinates for a formal sum with one term. -/\ntheorem monom_coords_mul (x\u2080 : X) (a b : R) : monomCoeff R X x\u2080 (a * b, x) = a * monomCoeff R X x\u2080 (b, x) := by\n  repeat\n    (\n      rw [monomCoeff])\n  cases x == x\u2080 <;> simp\n\n/-- Coordinates for a formal sum with one term with scalar `0`.\n-/\ntheorem monom_coords_at_zero (x\u2080 x : X) : monomCoeff R X x\u2080 (0, x) = 0 := by\n  rw [monomCoeff]\n  cases x == x\u2080 <;> rfl\n\n/-- The coordinates for a formal sum. -/\ndef FormalSum.coords  : FormalSum R X \u2192 X \u2192 R\n  | [], _ => 0\n  | h :: t, x\u2080 => monomCoeff R X x\u2080 h + coords t x\u2080\n\n/-!\n\n### Support of a formal sum\n\nWe next define the support of a formal sum and prove the property that coordinates vanish outside the support.\n-/\n\n/-- Support for a formal sum in a weak sense (coordinates may vanish on this). -/\ndef FormalSum.support  (s : FormalSum R X) : List X :=\n  s.map <| fun (_, x) => x\n\nopen FormalSum\n\n/-- Support contains elements `x : X` where the coordinate is not `0`. -/\ntheorem nonzero_coord_in_support  (s : FormalSum R X) : \u2200 x : X, 0 \u2260 s.coords x \u2192 x \u2208 s.support :=\n  match s with\n  | [] => fun x hyp => by\n    have d : coords [] x = (0 : R) := by\n      rfl\n    rw [d] at hyp\n    contradiction\n  | h :: t => by\n    intro x hyp\n    let (a\u2080, x\u2080) := h\n    have d : support ((a\u2080, x\u2080) :: t) = x\u2080 :: (support t) := by\n      rfl\n    rw [d]\n    match p : x\u2080 == x with\n    | true =>\n      have eqn : x\u2080 = x := of_decide_eq_true p\n      rw [eqn]\n      apply List.mem_of_elem_eq_true\n      simp [List.elem]\n    | false =>\n      rw [coords, monomCoeff, p, zero_add] at hyp\n      let step := nonzero_coord_in_support t x hyp\n      apply List.mem_of_elem_eq_true\n      simp [List.elem]\n      have p' : (x == x\u2080) = false := by\n        have eqn := of_decide_eq_false p\n        have eqn' : \u00ac(x = x\u2080) := by\n          intro contra\n          let contra' := Eq.symm contra\n          contradiction\n        exact decide_eq_false eqn'\n      rw [p']\n      apply List.elem_eq_true_of_mem\n      exact step\n\n/-!\n### Equality of coordinates on a list\n\nWe define equality of coordinates on a list and prove that it is decidable and implied by equality of formal sums.\n-/\n\n/-- The condition of being equal on all elements is a given list -/\ndef equalOnList  (l : List X) (f g : X \u2192 R) : Prop :=\n  match l with\n  | [] => true\n  | h :: t => (f h = g h) \u2227 (equalOnList t f g)\n\n/-- Equal functions are equal on arbitrary supports. -/\ntheorem equalOnList_of_equal  (l : List X) (f g : X \u2192 R) :\n    f = g \u2192 equalOnList l f g := by\n  intro hyp\n  induction l with\n  | nil =>\n    rw [equalOnList]\n  | cons h t step =>\n    rw [equalOnList]\n    apply And.intro\n    rw [hyp]\n    exact step\n\n/-- Functions equal on support `l` are equal on each `x \u2208 l`. -/\ntheorem eq_mem_of_equalOnList  (l : List X) (f g : X \u2192 R) (x : X)(mhyp : x \u2208 l) : equalOnList l f g \u2192 f x = g x :=\n  match l with\n  | [] => by\n    contradiction\n  | h :: t => by\n    intro hyp\n    simp [equalOnList] at hyp\n    cases mhyp\n    exact hyp.left\n    have inTail : x \u2208 t := by\n      assumption\n    have step := eq_mem_of_equalOnList t f g x inTail hyp.right\n    exact step\n\n/-- Decidability of equality on list. -/\n@[instance] def decidableEqualOnList  (l : List X) (f g : X \u2192 R) : Decidable (equalOnList l f g) :=\n  match l with\n  | [] =>\n    Decidable.isTrue\n      (by\n        simp [equalOnList])\n  | h :: t => by\n    simp [equalOnList]\n    cases (decidableEqualOnList t f g)with\n    | isTrue hs =>\n      exact\n        (if c : f h = g h then (Decidable.isTrue \u27e8c, hs\u27e9)\n        else by\n          apply Decidable.isFalse\n          intro contra\n          have contra' := contra.left\n          contradiction)\n    | isFalse hs =>\n      apply Decidable.isFalse\n      intro contra\n      have contra' := contra.right\n      contradiction\n\n\nend FormalSumCoords\n\n/-! \n## Quotient Free Module \n\n\n* We define relation by having equal coordinates\n* We show this is an equivalence relation and define the quotient \n-/\nsection QuotientFreeModule\n\n\n/-- Relation by equal coordinates. -/\ndef eqlCoords (R X : Type) [Ring R] [DecidableEq X](s\u2081 s\u2082 : FormalSum R X) : Prop :=\n  s\u2081.coords = s\u2082.coords\n\nnamespace eqlCoords\n\n/-- Relation by equal coordinates is reflexive. -/\ntheorem refl  (s : FormalSum R X) : eqlCoords R X s s :=\n  by\n  rfl\n\n/-- Relation by equal coordinates is  symmetric. -/\ntheorem symm  {s\u2081 s\u2082 : FormalSum R X} : eqlCoords R X s\u2081 s\u2082 \u2192 eqlCoords R X s\u2082 s\u2081 := by\n  intro hyp\n  apply funext\n  intro x\n  apply Eq.symm\n  exact congrFun hyp x\n\n/-- Relation by equal coordinates is transitive. -/\ntheorem trans  {s\u2081 s\u2082 s\u2083 : FormalSum R X} : eqlCoords R X s\u2081 s\u2082 \u2192 eqlCoords R X s\u2082 s\u2083 \u2192 eqlCoords R X s\u2081 s\u2083 := by\n  intro hyp\u2081 hyp\u2082\n  apply funext\n  intro x\n  have l\u2081 := congrFun hyp\u2081 x\n  have l\u2082 := congrFun hyp\u2082 x\n  exact Eq.trans l\u2081 l\u2082\n\n/-- Relation by equal coordinates is an equivalence relation. -/\ntheorem is_equivalence  : Equivalence (eqlCoords R X) :=\n  { refl := refl, symm := symm, trans := trans }\n\nend eqlCoords\n\n/-- Setoid based on equal coordinates. -/\ninstance formalSumSetoid (R X : Type) [Ring R] [DecidableEq X] : Setoid (FormalSum R X) :=\n  \u27e8eqlCoords R X, eqlCoords.is_equivalence\u27e9\n\n/-- Quotient free module. -/\nabbrev FreeModule (R X : Type) [Ring R] [DecidableEq X] :=\n  Quotient (formalSumSetoid R X)\n\nnotation R\"[\"G\"]\" => FreeModule R G\n\nend QuotientFreeModule\n\nsection DecidableEqQuotFreeModule\n\n/-! \n## Decidable equality on quotient free modules\n  \nWe show that the free module `F[X]` has decidable equality. This has two steps:\n  \n* show decidable equality for images of formal sums.\n* lift to quotient (by relating to formal sums).\n\nWe also show that the coordinate functions are defined on the quotient. -/\n  \n\n\nnamespace FreeModule\n\n/-- Decidable equality for quotient elements in the free module -/\n@[instance]\ndef decideEqualQuotient  (s\u2081 s\u2082 : FormalSum R X) : Decidable (@Eq (R[X]) \u27e6s\u2081\u27e7 \u27e6s\u2082\u27e7) :=\n  if ch\u2081 : equalOnList s\u2081.support s\u2081.coords s\u2082.coords then\n    if ch\u2082 : equalOnList s\u2082.support s\u2081.coords s\u2082.coords then\n      Decidable.isTrue\n        (by\n          apply Quotient.sound\n          apply funext\n          intro x\n          exact\n            if h\u2081 : (0 = s\u2081.coords x) then\n              if h\u2082 : (0 = s\u2082.coords x) then by\n                rw [\u2190 h\u2081, h\u2082]\n              else by\n                have lem : x \u2208 s\u2082.support := by\n                  apply nonzero_coord_in_support\n                  assumption\n                let lem' := eq_mem_of_equalOnList s\u2082.support s\u2081.coords s\u2082.coords x lem ch\u2082\n                exact lem'\n            else by\n              have lem : x \u2208 s\u2081.support := by\n                apply nonzero_coord_in_support\n                assumption\n              let lem' := eq_mem_of_equalOnList s\u2081.support s\u2081.coords s\u2082.coords x lem ch\u2081\n              exact lem')\n    else\n      Decidable.isFalse\n        (by\n          intro contra\n          let lem := equalOnList_of_equal s\u2082.support s\u2081.coords s\u2082.coords (Quotient.exact contra)\n          contradiction)\n  else\n    Decidable.isFalse\n      (by\n        intro contra\n        let lem := equalOnList_of_equal s\u2081.support s\u2081.coords s\u2082.coords (Quotient.exact contra)\n        contradiction)\n\n/-! \n### Lift to quotient \n-/\n\n/-- Boolean equality on support. -/\ndef beqOnSupport  (l : List X) (f g : X \u2192 R) :Bool :=\n  l.all <| fun x => decide (f x = g x)\n\n/-- Equality on support from boolean equality. -/\ntheorem eql_on_support_of_true {l : List X} {f g : X \u2192 R} : beqOnSupport l f g = true \u2192 equalOnList l f g := by\n  intro hyp\n  induction l with\n  | nil =>\n    simp [equalOnList]\n  | cons h t step =>\n    simp [equalOnList]\n    simp [beqOnSupport, List.all] at hyp\n    let p\u2082 := step hyp.right\n    exact And.intro hyp.left p\u2082\n\n/-- Boolean equality on support gives equal quotients. -/\ntheorem eqlquot_of_beq_support (s\u2081 s\u2082 : FormalSum R X)\n  (c\u2081 : beqOnSupport s\u2081.support s\u2081.coords s\u2082.coords)\n  (c\u2082 : beqOnSupport s\u2082.support s\u2081.coords s\u2082.coords) : @Eq (R[X]) \u27e6s\u2081\u27e7 \u27e6s\u2082\u27e7 := \n        by\n        let ch\u2081 := eql_on_support_of_true c\u2081\n        let ch\u2082 := eql_on_support_of_true c\u2082\n        apply Quotient.sound\n        apply funext\n        intro x\n        exact\n          if h\u2081 : (0 = s\u2081.coords x) then\n            if h\u2082 : (0 = s\u2082.coords x) then by\n              rw [\u2190 h\u2081, h\u2082]\n            else by\n              have lem : x \u2208 s\u2082.support := by\n                apply nonzero_coord_in_support\n                assumption\n              let lem' := eq_mem_of_equalOnList s\u2082.support s\u2081.coords s\u2082.coords x lem ch\u2082\n              exact lem'\n          else by\n            have lem : x \u2208 s\u2081.support := by\n              apply nonzero_coord_in_support\n              assumption\n            let lem' := eq_mem_of_equalOnList s\u2081.support s\u2081.coords s\u2082.coords x lem ch\u2081\n            exact lem'\n\n\n/--\nBoolean equality for the quotient via lifting\n-/\ndef beq_quot : (x\u2081 x\u2082 : R[X]) \u2192 Bool := by\n  apply Quotient.lift\u2082 (fun (s\u2081 s\u2082 : FormalSum R X) => decide (@Eq (R[X]) \u27e6s\u2081\u27e7 \u27e6s\u2082\u27e7))\n  intro a\u2081 b\u2081 a\u2082 b\u2082 eqv\u2081 eqv\u2082\n  let eq\u2081 : Eq (\u03b1 := R[X]) \u27e6a\u2081\u27e7 \u27e6a\u2082\u27e7 := Quot.sound eqv\u2081\n  let eq\u2082 : Eq (\u03b1 := R[X]) \u27e6b\u2081\u27e7 \u27e6b\u2082\u27e7 := Quot.sound eqv\u2082\n  conv => lhs; congr; rw [eq\u2081, eq\u2082]\n\n/--\nBoolean equality for the quotient is equality.\n-/\nlemma eq_of_beq_true  : \u2200 x\u2081 x\u2082 : R[X], x\u2081.beq_quot x\u2082 = true \u2192 x\u2081 = x\u2082 := by\n  apply Quotient.ind\u2082 (motive := fun (x\u2081 x\u2082 : R[X]) => x\u2081.beq_quot x\u2082 = true \u2192 x\u2081 = x\u2082)\n  intro s\u2081 s\u2082 eqv\n  let eql := of_decide_eq_true eqv\n  assumption\n\n/--\nBoolean inequality for the quotient is inequality.\n-/\nlemma neq_of_beq_false  : \u2200 x\u2081 x\u2082 : R[X], x\u2081.beq_quot x\u2082 = false \u2192 Not (x\u2081 = x\u2082) := by\n  apply Quotient.ind\u2082 (motive := fun (x\u2081 x\u2082 : R[X]) => x\u2081.beq_quot x\u2082 = false \u2192 Not (x\u2081 = x\u2082))\n  intro s\u2081 s\u2082 neqv\n  let neql := of_decide_eq_false neqv\n  assumption\n\n/--\nDecidable equality for the free module.\n-/\n@[instance] def decEq  (x\u2081 x\u2082 : R[X]) : Decidable (x\u2081 = x\u2082) := by\n  match p : x\u2081.beq_quot x\u2082 with\n  | true =>\n    apply Decidable.isTrue\n    apply FreeModule.eq_of_beq_true\n    assumption\n  | false =>\n    apply Decidable.isFalse\n    apply FreeModule.neq_of_beq_false\n    assumption\n\n/-!\n### Induced coordinates on the quotient.\n-/\n\n/-- Coordinates are well defined on the quotient. -/\ntheorem equal_coords_of_approx (s\u2081 s\u2082 : FormalSum R X): s\u2081 \u2248 s\u2082 \u2192 s\u2081.coords = s\u2082.coords := by\n    intro hyp\n    apply funext; intro x\u2080\n    exact congrFun hyp x\u2080\n\n/-- coordinates for the quotient -/\ndef coordinates (x\u2080 : X) : R[X] \u2192  R := by\n  apply Quotient.lift (fun s : FormalSum R X => s.coords x\u2080)\n  intro a b\n  intro hyp\n  let l :=  equal_coords_of_approx _ _ hyp\n  exact congrFun l x\u2080 \n\nend FreeModule\nend DecidableEqQuotFreeModule\n\n/-! \n## Module structure  \n\nWe define the module structure on the quotient of the free module by the equivalence relation.\n\n* We define scalar multiplication and addition on formal sums.\n* We show that we have induced operations on the quotient.\n* We show that the induced operations give a module structure on the quotient.\n-/\nsection ModuleStruture\n\n\nopen FormalSum\nnamespace FormalSum\n/-!\n### Scalar multiplication: on formal sums and on the quotient.\n-/\n\n/-- Scalar multiplication on formal sums. -/\ndef scmul  : R \u2192 FormalSum R X \u2192 FormalSum R X\n  | _, [] => []\n  | r, (h :: t) =>\n    let (a\u2080, x\u2080) := h\n    (r * a\u2080, x\u2080) :: (scmul r t)\n\n/-- Coordinates after scalar multiplication. -/\ntheorem scmul_coords  (r : R) (s : FormalSum R X) (x\u2080 : X) : (r * s.coords x\u2080) = (s.scmul r).coords x\u2080 := by\n  induction s with\n  | nil =>\n    simp [coords]\n  | cons h t ih =>\n    simp [scmul, coords, monom_coords_mul, left_distrib, ih]\n\n/-- Scalar multiplication on the Free Module. -/\ndef FreeModule.scmul  : R \u2192 R[X] \u2192 R[X] := by\n  intro r\n  let f : FormalSum R X \u2192 R[X] := fun s => \u27e6s.scmul r\u27e7\n  apply Quotient.lift f\n  intro s\u2081 s\u2082\n  simp\n  intro hypeq\n  apply funext\n  intro x\u2080\n  have l\u2081 := scmul_coords r s\u2081 x\u2080\n  have l\u2082 := scmul_coords r s\u2082 x\u2080\n  rw [\u2190 l\u2081, \u2190 l\u2082]\n  rw [hypeq]\n\n/-!\n### Addition: on formal sums and on the quotient.\n-/\n\n/-- Coordinates add when appending. -/\ntheorem append_coords  (s\u2081 s\u2082 : FormalSum R X) (x\u2080 : X) : (s\u2081.coords x\u2080) + (s\u2082.coords x\u2080) = (s\u2081 ++ s\u2082).coords x\u2080 := by\n  induction s\u2081 with\n  | nil =>\n    simp [coords]\n  | cons h t ih =>\n    simp [coords, \u2190 ih, add_assoc]\n\n/-- Coordinates well-defined up to equivalence. -/\ntheorem append_equiv  (s\u2081 s\u2082 t\u2081 t\u2082 : FormalSum R X) :(s\u2081 \u2248 s\u2082) \u2192 (t\u2081 \u2248 t\u2082) \u2192 s\u2081 ++ t\u2081 \u2248 s\u2082 ++ t\u2082 := by\n    intro eqv\u2081 eqv\u2082\n    apply funext\n    intro x\u2080\n    rw [\u2190 append_coords]\n    rw [\u2190 append_coords]\n    have ls : coords s\u2081 x\u2080 = coords s\u2082 x\u2080 := by \n      apply congrFun eqv\u2081\n    have lt : coords t\u2081 x\u2080 = coords t\u2082 x\u2080 := by \n      apply congrFun eqv\u2082\n    rw [\u2190 ls, \u2190 lt]\n\nend FormalSum\n\n/-- Addition of elements in the free module. -/\ndef FreeModule.add  : R[X] \u2192 R[X] \u2192 R[X] := by\n  let f : FormalSum R X \u2192 FormalSum R X \u2192 R[X] := fun s\u2081 s\u2082 => \u27e6s\u2081 ++ s\u2082\u27e7\n  apply Quotient.lift\u2082 f\n  intro a\u2081 b\u2081 a\u2082 b\u2082\n  simp\n  intro eq\u2081 eq\u2082\n  apply funext\n  intro x\u2080\n  have l\u2081 := append_coords a\u2081 b\u2081 x\u2080\n  have l\u2082 := append_coords a\u2082 b\u2082 x\u2080\n  rw [\u2190 l\u2081, \u2190 l\u2082]\n  rw [eq\u2081, eq\u2082]\n\ninstance  : Add (R[X]) :=\n  \u27e8FreeModule.add\u27e9\n\ninstance  : HSMul R (R[X]) (R[X]) :=\n  \u27e8FreeModule.scmul\u27e9\nnamespace FormalSum\n\n/-!\n### Properties of operations on formal sums.\n-/\n\n/-- Associativity for scalar multiplication for formal sums. -/\ntheorem action  (a b : R) (s : FormalSum R X) : (s.scmul b).scmul a = s.scmul (a * b) := by\n  induction s with\n  | nil =>\n    simp [scmul]\n  | cons h t ih =>\n    simp [scmul, ih, mul_assoc]\n\n/-- Distributivity for the module operations. -/\ntheorem act_sum (a b : R) (s : FormalSum R X) : (s.scmul a) ++ (s.scmul b) \u2248  s.scmul (a + b) := by\n  induction s with\n  | nil =>\n    simp [scmul]\n    apply eqlCoords.refl\n  | cons h t ih =>\n    apply funext; intro x\u2080\n    let il\u2081 := congrFun ih x\u2080    \n    rw [\u2190 append_coords]\n    simp [scmul, coords, right_distrib, monom_coords_hom]\n    rw [\u2190 append_coords] at il\u2081 \n    rw [\u2190 il\u2081]\n    simp\n    conv =>\n      lhs\n      rw [add_assoc]\n      arg 2\n      rw [\u2190 add_assoc]\n      arg 1\n      rw [add_comm]\n    conv =>\n      lhs\n      rw [add_assoc]\n      rw [\u2190 add_assoc]\n    \n\nend FormalSum\n\nnamespace FreeModule\n\n/-!\n### Module properties for the free module.\n-/\n\n/-- Associativity for scalar and ring products. -/\ntheorem module_action  (a b : R) (x : R[X]) : a \u2022 (b \u2022 x) = (a * b) \u2022 x := by\n  apply @Quotient.ind (motive := fun x : R[X] => a \u2022 (b \u2022 x) = (a * b) \u2022 x)\n  intro s\n  apply Quotient.sound\n  rw [FormalSum.action]\n  apply eqlCoords.refl\n\n/-- Commutativity of addition. -/\ntheorem addn_comm  (x\u2081 x\u2082 : R[X]) : x\u2081 + x\u2082 = x\u2082 + x\u2081 := by\n  apply @Quotient.ind\u2082 (motive := fun x\u2081 x\u2082 : R[X] => x\u2081 + x\u2082 = x\u2082 + x\u2081)\n  intro s\u2081 s\u2082\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  let lm\u2081 := append_coords s\u2081 s\u2082 x\u2080\n  let lm\u2082 := append_coords s\u2082 s\u2081 x\u2080\n  rw [\u2190 lm\u2081, \u2190 lm\u2082]\n  simp [add_comm]\n\ntheorem add_assoc_aux  (s\u2081 : FormalSum R X) (x\u2082 x\u2083 : R[X]) : (\u27e6s\u2081\u27e7 + x\u2082) + x\u2083 = \u27e6s\u2081\u27e7 + (x\u2082 + x\u2083) := by\n  apply @Quotient.ind\u2082 (motive := fun x\u2082 x\u2083 : R[X] => (\u27e6s\u2081\u27e7 + x\u2082) + x\u2083 = \u27e6s\u2081\u27e7 + (x\u2082 + x\u2083))\n  intro x\u2082 x\u2083\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  rw [\u2190 append_coords]\n  rw [\u2190 append_coords]\n  rw [\u2190 append_coords]\n  rw [\u2190 append_coords]\n  simp [add_assoc]\n\n/-- Associativity of addition. -/\ntheorem addn_assoc  (x\u2081 x\u2082 x\u2083 : R[X]) : (x\u2081 + x\u2082) + x\u2083 = x\u2081 + (x\u2082 + x\u2083) := by\n  apply @Quotient.ind (motive := fun x\u2081 : R[X] => (x\u2081 + x\u2082) + x\u2083 = x\u2081 + (x\u2082 + x\u2083))\n  intro x\u2081\n  apply add_assoc_aux\n\n/-- The zero element of the free module. -/\ndef zero : R[X] := \u27e6[]\u27e7\n\n/-- adding zero-/\ntheorem addn_zero (x: R[X]) : x + zero = x := by\n  apply @Quotient.ind (motive := fun x : R[X] => x + zero = x)\n  intro x\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  rw [\u2190 append_coords]\n  simp [add_zero, coords]\n\n/-- adding zero-/\ntheorem zero_addn (x: R[X]) : zero + x = x := by\n  apply @Quotient.ind (motive := fun x : R[X] => zero + x = x)\n  intro x\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  rw [\u2190 append_coords]\n  simp [add_zero, coords]\n\n/-- Distributivity for addition of module elements. -/\ntheorem elem_distrib  (a : R) (x\u2081 x\u2082 : R[X]) : a \u2022 (x\u2081 + x\u2082) = a \u2022 x\u2081 + a \u2022 x\u2082 := by\n  apply @Quotient.ind\u2082 (motive := fun x\u2081 x\u2082 : R[X] => a \u2022 (x\u2081 + x\u2082) = a \u2022 x\u2081 + a \u2022 x\u2082)\n  intro s\u2081 s\u2082\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  rw [\u2190 scmul_coords]\n  rw [\u2190 append_coords]\n  rw [\u2190 append_coords]\n  rw [\u2190 scmul_coords]\n  rw [\u2190 scmul_coords]\n  simp [left_distrib]\n\n/-- Distributivity with respect to scalars. -/\ntheorem coeffs_distrib (a b: R)(x: R[X]) : a \u2022 x + b \u2022 x = (a + b) \u2022 x:= by\n  apply @Quotient.ind (motive := fun x : R[X] => \n    a \u2022 x + b \u2022 x = (a + b) \u2022 x)\n  intro s\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  let l := act_sum a b s\n  let l'' := congrFun l x\u2080\n  exact l''\n\n/-- Multiplication by `1 : R`. -/\ntheorem unit_coeffs (x: R[X]) : (1 : R) \u2022 x =  x:= by\n  apply @Quotient.ind (motive := fun x : R[X] => \n    (1 : R) \u2022 x =  x)\n  intro s\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  let l := scmul_coords 1 s x\u2080\n  rw [\u2190 l]\n  simp\n\n/-- Multiplication by `0 : R`. -/\ntheorem zero_coeffs (x: R[X]) : (0 : R) \u2022 x =  \u27e6 [] \u27e7:= by\n  apply @Quotient.ind (motive := fun x : R[X] => \n    (0 : R) \u2022 x =  \u27e6 [] \u27e7)\n  intro s\n  apply Quotient.sound\n  apply funext\n  intro x\u2080\n  let l := scmul_coords 0 s x\u2080\n  rw [\u2190 l]\n  simp [coords]\n\n/-- The module is an additive commutative group, mainly proved as a check -/\ninstance : AddCommGroup (R[X]) :=\n  {\n    zero := \u27e6 []\u27e7\n    add := FreeModule.add\n    add_assoc := FreeModule.addn_assoc\n    add_zero := FreeModule.addn_zero\n    zero_add := FreeModule.zero_addn\n    neg := fun x => (-1 : R) \u2022 x\n\n    sub_eq_add_neg := by intros; rfl\n\n    add_left_neg := by \n        intro x\n        let l := FreeModule.coeffs_distrib (-1 : R) (1 : R) x\n        simp at l\n        rw [FreeModule.unit_coeffs] at l\n        rw [FreeModule.zero_coeffs] at l\n        exact l\n\n    add_comm := FreeModule.addn_comm\n  }\n\nend FreeModule\n\nend ModuleStruture\n\n/-! \n## Equivalent definition of the relation via moves \n\nFor conceptual results such as the universal property (needed for the group ring structure) it is useful to define the relation on the free module in terms of moves. We do this, and show that this is the same as the relation defined by equality of coordinates.\n\n* We define elementary moves on formal sums \n* We show coordinates equal if and only if related by elementary moves\n* Hence can define map on Free Module when invariant under elementary moves \n  -/\n\nsection ElementaryMoves\n\nopen FormalSum\n/-- Elementary moves for formal sums. -/\ninductive ElementaryMove (R X : Type) [Ring R] [DecidableEq R][DecidableEq X] : FormalSum R X \u2192 FormalSum R X \u2192 Prop where\n  | zeroCoeff (tail : FormalSum R X) (x : X) (a : R) (h : a = 0) : ElementaryMove R X ((a, x) :: tail) tail\n  | addCoeffs (a b : R) (x : X) (tail : FormalSum R X) : \n    ElementaryMove R X ((a, x) :: (b, x) :: tail) ((a + b, x) :: tail)\n  | cons (a : R) (x : X) (s\u2081 s\u2082 : FormalSum R X) : ElementaryMove R X s\u2081 s\u2082 \u2192 ElementaryMove R X ((a, x) :: s\u2081) ((a, x) :: s\u2082)\n  | swap (a\u2081 a\u2082 : R) (x\u2081 x\u2082 : X) (tail : FormalSum R X) :\n    ElementaryMove R X ((a\u2081, x\u2081) :: (a\u2082, x\u2082) :: tail) ((a\u2082, x\u2082) :: (a\u2081, x\u2081) :: tail)\n\ndef FreeModuleAux (R X : Type) [Ring R] [DecidableEq R][DecidableEq X] :=\n  Quot (ElementaryMove R X)\n\nnamespace FormalSum\n\n/-- Image in the quotient (i.e., actual, not formal, sum). -/\ndef sum  (s : FormalSum R X) : FreeModuleAux R X :=\n  Quot.mk (ElementaryMove R X) s\n\n/-- Equivalence by having the same image. -/\ndef equiv  (s\u2081 s\u2082 : FormalSum R X) : Prop :=\n  s\u2081.sum = s\u2082.sum\n\ninfix:65 \" \u2243 \" => FormalSum.equiv\n\n/-!\n### Invariance of coordinates under elementary moves\n-/\n\n/-- Coordinates are invariant under moves. -/\ntheorem coords_move_invariant (x\u2080 : X) (s\u2081 s\u2082 : FormalSum R X) (h : ElementaryMove R X s\u2081 s\u2082) : coords s\u2081 x\u2080 = coords s\u2082 x\u2080 := by\n  induction h with\n  | zeroCoeff tail x a hyp =>\n    simp [coords, hyp, monom_coords_at_zero]\n  | addCoeffs a b x tail =>\n    simp [coords, monom_coords_at_zero, \u2190 add_assoc, monom_coords_hom]\n  | cons a x s\u2081 s\u2082 _ step =>\n    simp [coords, step]\n  | swap a\u2081 a\u2082 x\u2081 x\u2082 tail =>\n    simp [coords, \u2190 add_assoc, add_comm]\n\nend FormalSum\n\n/-- Coordinates on the quotients. -/\ndef FreeModuleAux.coeff (x\u2080 : X) : FreeModuleAux R X \u2192 R :=\n  Quot.lift (fun s => s.coords x\u2080) (coords_move_invariant x\u2080)\n\nnamespace FormalSum\n\n/-- Commutative diagram for coordinates. -/\ntheorem coeff_factors (x : X) (s : FormalSum R X) : FreeModuleAux.coeff  x (sum s) = s.coords x := by\n  simp [FreeModuleAux.coeff]\n  apply @Quot.liftBeta (r := ElementaryMove R X) (f := fun s => s.coords x)\n  apply coords_move_invariant\n\n/-- Coordinates well-defined under the equivalence generated by moves. -/\ntheorem coords_well_defined  (x : X) (s\u2081 s\u2082 : FormalSum R X) : s\u2081 \u2243 s\u2082 \u2192 s\u2081.coords x = s\u2082.coords x := by\n  intro hyp\n  have l : FreeModuleAux.coeff x (sum s\u2082) = s\u2082.coords x := by\n    simp [coeff_factors, hyp]\n  rw [\u2190 l]\n  rw [\u2190 coeff_factors]\n  rw [hyp]\n\n/-!\n### Equal coordinates implies related by elementary moves.\n-/\n\n/-- Cons respects equivalence. -/\ntheorem cons_equiv_of_equiv  (s\u2081 s\u2082 : FormalSum R X) (a : R) (x : X) : s\u2081 \u2243 s\u2082 \u2192 (a, x) :: s\u2081 \u2243 (a, x) :: s\u2082 := by\n  intro h\n  let f : FormalSum R X \u2192 FreeModuleAux R X := fun s => sum <| (a, x) :: s\n  let wit : (s\u2081 s\u2082 : FormalSum R X) \u2192 (ElementaryMove R X s\u2081 s\u2082) \u2192 f s\u2081 = f s\u2082 := by\n    intro s\u2081 s\u2082 hyp\n    apply Quot.sound\n    apply ElementaryMove.cons\n    assumption\n  let g := Quot.lift f wit\n  let factorizes : (s : FormalSum R X) \u2192 g (s.sum) = sum ((a, x) :: s) := Quot.liftBeta f wit\n  rw [equiv]\n  rw [\u2190 factorizes]\n  rw [\u2190 factorizes]\n  rw [h]\n\n/-- If a coordinate `x` for a formal sum `s` is non-zero, `s` is related by moves to a formal sum with first term `x` with coefficient its coordinates, and the rest shorter than `s`. -/\ntheorem nonzero_coeff_has_complement  (x\u2080 : X)(s : FormalSum R X) : 0 \u2260 s.coords x\u2080 \u2192 (\u2203 ys : FormalSum R X, (((s.coords x\u2080, x\u2080) :: ys) \u2243 s) \u2227 (List.length ys < s.length)) := by\n  induction s with\n  | nil =>\n    intro contra\n    contradiction\n  | cons head tail hyp =>\n    let (a, x) := head\n    intro pos\n    cases c : x == x\u2080 with\n    | true =>\n      let k := FormalSum.coords tail x\u2080\n      have lem : a + k = coords ((a, x) :: tail) x\u2080 := by\n        rw [coords, monomCoeff, c]\n      have c'' : x = x\u2080 := of_decide_eq_true c\n      rw [c'']\n      rw [c''] at lem\n      exact\n        if c' : (0 = k) then by\n          have lIneq : tail.length < List.length ((a, x) :: tail) := by\n            simp [List.length_cons]\n          rw [\u2190 c', add_zero] at lem\n          rw [\u2190 lem]\n          exact \u27e8tail, rfl, lIneq\u27e9\n        else by\n          let \u27e8ys, eqnStep, lIneqStep\u27e9 := hyp c'\n          have eqn\u2081 : (a, x\u2080) :: (k, x\u2080) :: ys \u2243 (a + k, x\u2080) :: ys := by\n            apply Quot.sound\n            apply ElementaryMove.addCoeffs\n          have eqn\u2082 : (a, x\u2080) :: (k, x\u2080) :: ys \u2243 (a, x\u2080) :: tail := by\n            apply cons_equiv_of_equiv\n            assumption\n          have eqn : (a + k, x\u2080) :: ys \u2243 (a, x\u2080) :: tail := Eq.trans (Eq.symm eqn\u2081) eqn\u2082\n          rw [\u2190 lem]\n          have lIneq : ys.length < List.length ((a, x\u2080) :: tail) := by\n            apply Nat.le_trans lIneqStep\n            simp [List.length_cons, Nat.le_succ]\n          exact \u27e8ys, eqn, lIneq\u27e9\n    | false =>\n      let k := coords tail x\u2080\n      have lem : k = coords ((a, x) :: tail) x\u2080 := by\n        simp [coords, monomCoeff, c, zero_add]\n      rw [\u2190 lem] at pos\n      let \u27e8ys', eqnStep, lIneqStep\u27e9 := hyp pos\n      rw [\u2190 lem]\n      let ys := (a, x) :: ys'\n      have lIneq : ys.length < ((a, x) :: tail).length := by\n        simp [List.length_cons]\n        apply Nat.succ_lt_succ\n        exact lIneqStep\n      have eqn\u2081 : (k, x\u2080) :: ys \u2243 (a, x) :: (k, x\u2080) :: ys' := by\n        apply Quot.sound\n        apply ElementaryMove.swap\n      have eqn\u2082 : (a, x) :: (k, x\u2080) :: ys' \u2243 (a, x) :: tail := by\n        apply cons_equiv_of_equiv\n        assumption\n      have eqn : (k, x\u2080) :: ys \u2243 (a, x) :: tail := by\n        exact Eq.trans eqn\u2081 eqn\u2082\n      exact \u27e8ys, eqn, lIneq\u27e9\n\n/-- If all coordinates are zero, then moves relate to the empty sum. -/\ntheorem equiv_e_of_zero_coeffs  (s : FormalSum R X) (hyp : \u2200 x : X, s.coords x = 0) : s \u2243 [] :=\n  -- let canc : IsAddLeftCancel R :=\n  --   \u27e8fun a b c h => by\n  --     rw [\u2190 neg_add_cancel_left a b, h, neg_add_cancel_left]\u27e9\n  match mt : s with\n  | [] => rfl\n  | h :: t => by\n    let (a\u2080, x\u2080) := h\n    let hyp\u2080 := hyp x\u2080\n    rw [coords] at hyp\u2080\n    have c\u2080 : monomCoeff R X x\u2080 (a\u2080, x\u2080) = a\u2080 := by\n      simp [monomCoeff]\n    rw [c\u2080] at hyp\u2080\n    exact\n      if hz : a\u2080 = 0 then by\n        rw [hz] at hyp\u2080\n        rw [zero_add] at hyp\u2080\n        have tail_coeffs : \u2200 x : X, coords t x = 0 := by\n          intro x\n          simp [coords]\n          exact\n            if c : (x\u2080 = x) then by\n              rw [\u2190 c]\n              assumption\n            else by\n              let hx := hyp x\n              simp [coords, monomCoeff] at hx\n              have lf : (x\u2080 == x) = false := decide_eq_false c\n              rw [lf] at hx\n              simp [zero_add] at hx\n              assumption\n        have _ : t.length < (h :: t).length := by\n          simp [List.length_cons]\n        let step : t \u2243 [] := by\n          apply equiv_e_of_zero_coeffs\n          exact tail_coeffs\n        rw [hz]\n        have ls : (0, x\u2080) :: t \u2243 t := by\n          apply Quot.sound\n          apply ElementaryMove.zeroCoeff\n          rfl\n        exact Eq.trans ls step\n      else by\n        have non_zero : 0 \u2260 coords t x\u2080 := by\n          intro contra'\n          let contra := Eq.symm contra'\n          rw [contra, add_zero] at hyp\u2080\n          contradiction\n        let \u27e8ys, eqnStep, lIneqStep\u27e9 := nonzero_coeff_has_complement x\u2080 t non_zero\n        have tail_coeffs : \u2200 x : X, coords ys x = 0 := by\n          intro x\n          simp [coords]\n          exact\n            if c : (x\u2080 = x) then by\n              rw [\u2190 c]\n              let ceq := coords_well_defined x\u2080 _ _ eqnStep\n              simp [coords, monomCoeff] at ceq\n              assumption\n            else by\n              let hx := hyp x\n              simp [coords, monomCoeff] at hx\n              have lf : (x\u2080 == x) = false := decide_eq_false c\n              rw [lf] at hx\n              simp [zero_add] at hx\n              let ceq := coords_well_defined x _ _ eqnStep\n              simp [coords, monomCoeff, lf] at ceq\n              rw [hx] at ceq\n              exact ceq\n        have _ : ys.length < (h :: t).length := by\n          simp [List.length_cons]\n          apply Nat.le_trans lIneqStep\n          apply Nat.le_succ\n        let step : ys \u2243 [] := by\n          apply equiv_e_of_zero_coeffs\n          exact tail_coeffs\n        let eqn\u2081 := cons_equiv_of_equiv _ _ (coords t x\u2080) x\u2080 step\n        let eqn\u2082 : t \u2243 (coords t x\u2080, x\u2080) :: [] := Eq.trans (Eq.symm eqnStep) eqn\u2081\n        let eqn\u2083 := cons_equiv_of_equiv _ _ a\u2080 x\u2080 eqn\u2082\n        apply Eq.trans eqn\u2083\n        have eqn\u2084 : sum [(a\u2080, x\u2080), (coords t x\u2080, x\u2080)] = sum [(a\u2080 + coords t x\u2080, x\u2080)] := by\n          apply Quot.sound\n          apply ElementaryMove.addCoeffs\n        apply Eq.trans eqn\u2084\n        rw [hyp\u2080]\n        apply Quot.sound\n        apply ElementaryMove.zeroCoeff\n        rfl\n  termination_by\n  _ R X s h => s.length decreasing_by\n  assumption\n\n/-- If coordinates are equal, the sums are related by moves. -/\ntheorem equiv_of_equal_coeffs  (s\u2081 s\u2082 : FormalSum R X) (hyp : \u2200 x : X, s\u2081.coords x = s\u2082.coords x) : s\u2081 \u2243 s\u2082 :=\n  match s\u2081 with\n  | [] =>\n    have coeffs : \u2200 x : X, s\u2082.coords x = 0 := by\n      intro x\n      let h := hyp x\n      rw [\u2190 h]\n      rfl\n    let zl := equiv_e_of_zero_coeffs s\u2082 coeffs\n    Eq.symm zl\n  | h :: t =>\n    let (a\u2080, x\u2080) := h\n    by\n    exact\n      if p : 0 = a\u2080 then by\n        have eq\u2081 : (a\u2080, x\u2080) :: t \u2243 t := by\n          apply Quot.sound\n          apply ElementaryMove.zeroCoeff\n          apply Eq.symm\n          assumption\n        have _ : t.length < (h :: t).length := by\n          simp [List.length_cons]\n        have eq\u2082 : t \u2243 s\u2082 := by\n          apply equiv_of_equal_coeffs t s\u2082\n          intro x\n          let ceq := coords_well_defined x ((a\u2080, x\u2080) :: t) t eq\u2081\n          simp [\u2190 ceq, hyp]\n        exact Eq.trans eq\u2081 eq\u2082\n      else by\n        let a\u2081 := coords t x\u2080\n        exact\n          if p\u2081 : 0 = a\u2081 then by\n            have cf\u2082 : s\u2082.coords x\u2080 = a\u2080 := by\n              rw [\u2190 hyp]\n              simp [coords, \u2190 p\u2081, Nat.add_zero, monomCoeff]\n            let \u27e8ys, eqn, _\u27e9 :=\n              nonzero_coeff_has_complement x\u2080 s\u2082\n                (by\n                  rw [cf\u2082]\n                  assumption)\n            let cfs := fun x => coords_well_defined x _ _ eqn\n            rw [cf\u2082] at cfs\n            let cfs' := fun (x : X) => Eq.trans (hyp x) (Eq.symm (cfs x))\n            simp [coords] at cfs'\n            have _ : t.length < (h :: t).length := by\n              simp [List.length_cons]\n            let step := equiv_of_equal_coeffs t ys cfs'\n            let _step' := cons_equiv_of_equiv t ys a\u2080 x\u2080 step\n            rw [cf\u2082] at eqn\n            exact Eq.trans _step' eqn\n          else by\n            let \u27e8ys, eqn, ineqn\u27e9 := nonzero_coeff_has_complement x\u2080 t p\u2081\n            let s\u2083 := (a\u2080 + a\u2081, x\u2080) :: ys\n            have eq\u2081 : (a\u2080, x\u2080) :: (a\u2081, x\u2080) :: ys \u2243 s\u2083 := by\n              apply Quot.sound\n              let lem := ElementaryMove.addCoeffs a\u2080 a\u2081 x\u2080 ys\n              exact lem\n            have eq\u2082 : (a\u2080, x\u2080) :: (a\u2081, x\u2080) :: ys \u2243 (a\u2080, x\u2080) :: t := by\n              apply cons_equiv_of_equiv\n              assumption\n            have eq\u2083 : s\u2083 \u2243 s\u2082 := by\n              have _ : ys.length + 1 < t.length + 1 := by\n                apply Nat.succ_lt_succ\n                exact ineqn\n              apply equiv_of_equal_coeffs\n              intro x\n              rw [\u2190 hyp x]\n              simp [coords]\n              let d := coords_well_defined x _ _ eqn\n              rw [coords] at d\n              rw [\u2190 d]\n              simp [monom_coords_hom, coords, add_assoc]\n            apply Eq.trans (Eq.trans (Eq.symm eq\u2082) eq\u2081) eq\u2083\n  termination_by\n  _ R X s _ _ => s.length decreasing_by\n  assumption\n\n/-!\n## Functions invariant under moves pass to the quotient.\n-/\n/-- Lifting functions to the move induced quotient. -/\ntheorem func_eql_of_move_equiv  {\u03b2 : Sort u} (f : FormalSum R X \u2192 \u03b2) : (\u2200 s\u2081 s\u2082 : FormalSum R X, ElementaryMove R X s\u2081 s\u2082 \u2192 f s\u2081 = f s\u2082) \u2192 (\u2200 s\u2081 s\u2082 : FormalSum R X, s\u2081 \u2248 s\u2082 \u2192 f s\u2081 = f s\u2082) :=\n  by\n  intro hyp\n  let fbar : FreeModuleAux R X \u2192 \u03b2 := Quot.lift f hyp\n  let fct : \u2200 s : FormalSum R X, f s = fbar (sum s) := by\n    apply Quot.liftBeta\n    apply hyp\n  intro s\u2081 s\u2082 sim\n  have ec : eqlCoords R X s\u2081 s\u2082 := sim\n  rw [eqlCoords] at ec\n  have pullback : sum s\u2081 = sum s\u2082 := by\n    apply equiv_of_equal_coeffs\n    intro x\n    exact congrFun ec x\n  simp [fct, pullback]\n\nend FormalSum\nend ElementaryMoves\n\nsection Injectivity\n/-!\n## Injectivity of inclusions\n\nWe show that, under appropriate hypotheses, two inclusions into Free Modules are injective. \n\n* If `a : R` is nonzero, then `x : X \u21a6 \u27e6[(a, x)]\u27e7` is injective.\n* If `x: X`, then `a : R \u21a6 \u27e6[(a, x)]\u27e7` is injective.\n\nThese are used in proving injectivity results for related functions on group rings, which act as a check on the correctness of the definitions.\n-/\nopen FormalSum\n\n/-- For `a: R` and `a \u2260 0`,  injectivity of the the function `x: X \u21a6 [(a, x)]` up to equivalence  -/\ntheorem monom_elem_eq_of_coord_eq_nonzero (a : R)(non_zero: a \u2260 0) (x\u2080 x\u2081 : X) : coords [(a, x\u2080)] = coords [(a, x\u2081)] \u2192 x\u2080 = x\u2081 := by\n  intro hyp\n  have sup\u2080 : support [(a, x\u2080)] = [x\u2080] := by\n    rfl\n  have c\u2081 : coords [(a, x\u2081)] x\u2081 = a := by\n    simp [coords, monomCoeff]\n  rw [\u2190 c\u2081] at non_zero\n  symm at non_zero\n  rw [\u2190 hyp] at non_zero\n  let lem := nonzero_coord_in_support [(a, x\u2080)] x\u2081 non_zero\n  simp [support] at lem\n  apply Eq.symm\n  assumption\n\n/-- For `x : X`, injectivity of the the function `a: R \u21a6 [(a, x)]` up to equivalence  -/\ntheorem monom_coeff_eq_of_coord_eq (x : X) (a\u2080 a\u2081 : R) : coords [(a\u2080, x)] = coords [(a\u2081, x)] \u2192 a\u2080 = a\u2081 := by\n  intro hyp\n  let h\u2081 := congrFun hyp x\n  simp [coords, monomCoeff] at h\u2081\n  assumption\n\n\n/-- For `x: X`, the functions `a : R \u21a6 \u27e6[(a, x)]\u27e7`-/\ndef coeffInclusion (x\u2080 : X) : R \u2192 R[X] := \n  fun a\u2080 => \u27e6[(a\u2080, x\u2080)]\u27e7\n\n/-- Injectivity of `coeffInclusion` -/\ntheorem coeffInclusion_injective (x\u2080 : X)\n (a\u2080 a\u2081 : R) : coeffInclusion x\u2080 a\u2080 =\n                coeffInclusion x\u2080 a\u2081  \u2192  a\u2080 = a\u2081 := by\n  intro hyp\n  simp [coeffInclusion] at hyp\n  exact monom_coeff_eq_of_coord_eq x\u2080 a\u2080 a\u2081 hyp\n\n/-- For `a: A`, the function `x: X \u21a6 \u27e6[(a, x)]\u27e7`-/\ndef baseInclusion (a\u2080 : R) : X \u2192 R[X] := \n  fun x\u2080 => \u27e6[(a\u2080, x\u2080)]\u27e7\n\n/-- Injectivity of `baseInclusion a` give `a \u22600`   -/\ntheorem baseInclusion_injective (a\u2080 : R) (non_zero : a\u2080 \u2260 0)\n (x\u2080 x\u2081 : X) : baseInclusion  a\u2080 x\u2080 =\n                baseInclusion a\u2080 x\u2081  \u2192  x\u2080 = x\u2081 := by\n  intro hyp\n  simp [baseInclusion] at hyp\n  exact monom_elem_eq_of_coord_eq_nonzero a\u2080 non_zero x\u2080 x\u2081 hyp\n\n\n\nend Injectivity\nsection NormRepr\n\n/-! \n## Basic `Repr`\n\nAn instance of `Repr` on Free Modules, mainly for debugging (fairly crude). This is implemented by constructing a norm ball containing all the non-zero coordinates, and then making a list of non-zero coordinates\n-/\n\ntheorem fst_le_max (a b : Nat): a \u2264 max a b  := by\n    simp [max]\n    exact if c:a \u2264 b \n          then by\n              unfold max\n              unfold Nat.instMaxNat\n              unfold maxOfLe\n              simp [if_pos c]\n              assumption\n          else by\n              unfold max\n              unfold Nat.instMaxNat\n              unfold maxOfLe\n              simp [if_neg c]\n\n            \ntheorem snd_le_max (a b : Nat): b \u2264 max a b  := by\n    simp [max]\n    exact if c: a \u2264 b\n    then by\n      unfold max\n      unfold Nat.instMaxNat\n      unfold maxOfLe \n      simp [if_pos c]\n    else by \n      unfold max\n      unfold Nat.instMaxNat\n      unfold maxOfLe\n      simp [if_neg c]\n      apply Nat.le_of_lt\n      let c' := Nat.gt_of_not_le c\n      assumption\n      \n\ntheorem eq_fst_or_snd_of_max (a b : Nat) : (max a b = a) \u2228 (max a b = b) := by\n      simp [max]\n      exact if c: a \u2264 b \n        then by\n          unfold max\n          unfold Nat.instMaxNat\n          unfold maxOfLe\n          simp [if_pos c]\n        else by\n          unfold max\n          unfold Nat.instMaxNat\n          unfold maxOfLe\n          simp [if_neg c]\n\ndef maxNormSuccOnSupp (norm: X \u2192 Nat)(crds : X \u2192 R)(s: List X) : Nat :=\n  match s with\n  | [] => 0\n  | head :: tail =>\n      if crds head \u2260 0 then \n        max (norm head + 1) (maxNormSuccOnSupp norm crds tail)\n      else\n        maxNormSuccOnSupp norm crds tail        \n    \ntheorem max_in_support (norm: X \u2192 Nat)(crds : X \u2192 R)(s: List X) : maxNormSuccOnSupp norm crds s > 0 \u2192 \n  \u2203 x : X, crds x \u2260 0 \u2227 maxNormSuccOnSupp norm crds s = norm x + 1 := by\n  intro h\n  induction s with\n  | nil => \n    simp [maxNormSuccOnSupp] at h\n  | cons head tail ih => \n    exact if c : crds head =0 then\n      by \n        simp [maxNormSuccOnSupp, c]\n        simp [maxNormSuccOnSupp, c] at h\n        exact  ih h\n        \n    else by    \n        simp [maxNormSuccOnSupp, c]\n        simp [maxNormSuccOnSupp, c] at h\n        let sl := eq_fst_or_snd_of_max (norm head + 1) (maxNormSuccOnSupp norm crds tail)\n        cases sl\n        case inr p =>\n            rw [p]\n            rw [p] at h\n            exact  ih h \n        case inl p =>\n            rw [p]\n            rw [p] at h\n            exact \u27e8head, And.intro c rfl\u27e9\n\ntheorem supp_below_max(norm: X \u2192 Nat)(crds : X \u2192 R)(s: List X) : (x: X) \u2192 x \u2208 s \u2192  crds x \u2260 0 \u2192 norm x + 1 \u2264 maxNormSuccOnSupp norm crds s := by\n    intro x h\u2081 h\u2082\n    cases h\u2081\n    case head as => \n      rw [maxNormSuccOnSupp]\n      simp [h\u2082]\n      apply fst_le_max  \n    case tail a as th =>\n      rw [maxNormSuccOnSupp]\n      let l := supp_below_max norm crds as  x  th h\u2082 \n      exact if c:crds a \u2260 0 then\n        by\n        simp [c]\n        apply Nat.le_trans l \n        apply snd_le_max\n      else\n        by \n        simp [c]\n        exact l\n\ntheorem supp_zero_of_max_zero(norm: X \u2192 Nat)(crds : X \u2192 R)(s: List X) : maxNormSuccOnSupp norm crds s = 0 \u2192 \n    (x: X) \u2192 x \u2208 s \u2192  crds x = 0 := fun hyp x hm =>\n      if c:crds x = 0 then c \n      else by \n        simp\n        let l := supp_below_max norm crds s x hm c \n        rw [hyp] at l\n        contradiction\n\ndef FormalSum.normSucc (norm : X \u2192 Nat)(s: FormalSum R X) : Nat :=\n      maxNormSuccOnSupp norm s.coords (s.support)\n\nopen FormalSum\ntheorem normsucc_le(norm : X \u2192 Nat)(s\u2081 s\u2082: FormalSum R X)(eql : s\u2081 \u2248 s\u2082): s\u2081.normSucc norm \u2264 s\u2082.normSucc norm := \n      if c:s\u2081.normSucc norm = 0 then \n      by\n        rw [c]\n        apply Nat.zero_le \n      else by\n        simp [FormalSum.normSucc]\n        simp [FormalSum.normSucc] at c\n        let c' : maxNormSuccOnSupp norm (coords s\u2081) (support s\u2081) > 0 :=\n            by\n            cases Nat.eq_zero_or_pos (maxNormSuccOnSupp norm (coords s\u2081) (support s\u2081))\n            contradiction\n            assumption\n        let l := max_in_support norm s\u2081.coords s\u2081.support c'\n        let \u27e8x\u2080, p\u27e9:= l\n        let nonzr' := p.left\n        let l := congrFun eql x\u2080\n        rw [l] at nonzr'\n        let nonzr : 0 \u2260 s\u2082.coords x\u2080 := by\n          intro hyp\n          let l' := Eq.symm hyp\n          contradiction\n        let in_supp := nonzero_coord_in_support s\u2082 x\u2080 nonzr\n        rw [p.right]\n        simp\n        apply supp_below_max norm s\u2082.coords s\u2082.support x\u2080 in_supp nonzr'\n\ntheorem norm_succ_eq(norm : X \u2192 Nat)(s\u2081 s\u2082: FormalSum R X)(eql : s\u2081 \u2248 s\u2082):\n    s\u2081.normSucc norm = s\u2082.normSucc norm := by\n      apply Nat.le_antisymm <;> apply normsucc_le\n      assumption\n      apply eqlCoords.symm\n      assumption\n\nclass NormCube (\u03b1 : Type) where\n  norm : \u03b1 \u2192 Nat\n  cube : Nat \u2192 List \u03b1\n\ndef normCube (\u03b1 : Type) [nc : NormCube \u03b1](k: Nat)  := nc.cube k\n\ninstance natCube : NormCube Nat := \u27e8id, fun n => (List.range n).reverse\u27e9\n\ninstance finCube {k: Nat} : NormCube (Fin (Nat.succ k)) := \n    let i : Nat \u2192 Fin (Nat.succ k) := fun n => \u27e8n % (Nat.succ k), by \n          apply Nat.mod_lt\n          apply Nat.zero_lt_succ\n          \u27e9\n    \u27e8fun j => j.val, fun n => (List.range (min (k + 1) n)).reverse.map i\u27e9\n\n\ninstance intCube : NormCube \u2124 where\n  norm := Int.natAbs\n  cube : Nat \u2192 List \u2124 := fun n => \n      (List.range (n)).reverse.map (Int.ofNat) ++\n      (List.range (n - 1)).map (Int.negSucc)\n\ninstance prodCube {\u03b1 \u03b2 : Type} [na: NormCube \u03b1] [nb :NormCube \u03b2] :  NormCube (\u03b1 \u00d7 \u03b2) where\n  norm : (\u03b1 \u00d7 \u03b2) \u2192 Nat := \n    fun \u27e8a, b\u27e9 => max (na.norm a) (nb.norm b) \n  cube : Nat \u2192 List (\u03b1 \u00d7 \u03b2) :=\n    fun n => \n      (na.cube n).bind (fun a => \n        (nb.cube n).map  (fun b => \n          (a, b)))\n\ndef FreeModule.normBound (x: R[X])[nx : NormCube X] : Nat := by\n  let f : FormalSum R X \u2192 Nat := fun s => s.normSucc (nx.norm)\n  apply Quotient.lift f\n  apply norm_succ_eq\n  exact x\n\n-- this should be viewable directly if `R` and `X` are, as in our case\ndef FreeModule.coeffList (x: R[X])[nx : NormCube X] : List (R \u00d7 X) := \n   (nx.cube (x.normBound)).filterMap fun x\u2080 => \n      let a := x.coordinates x\u2080\n      if a =0 then none else some (a, x\u2080)\n\n-- basic repr \ninstance basicRepr [NormCube X][Repr X][Repr R]: Repr (R[X]) := \n  \u27e8fun x _ => reprStr (x.coeffList)\u27e9\n\nend NormRepr", "meta": {"author": "siddhartha-gadgil", "repo": "Polylean", "sha": "3b411dc1dca8c84ab221cc544d1ae3bd4f83de5a", "save_path": "github-repos/lean/siddhartha-gadgil-Polylean", "path": "github-repos/lean/siddhartha-gadgil-Polylean/Polylean-3b411dc1dca8c84ab221cc544d1ae3bd4f83de5a/UnitConjecture/FreeModule.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8104788995148792, "lm_q1q2_score": 0.7364156351911963}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport algebra.order.ring\nimport algebra.invertible\n\n/-!\n# Lemmas about `inv_of` in ordered (semi)rings.\n-/\n\nvariables {\u03b1 : Type*} [linear_ordered_semiring \u03b1] {a : \u03b1}\n\n@[simp] lemma inv_of_pos [invertible a] : 0 < \u215fa \u2194 0 < a :=\nbegin\n  have : 0 < a * \u215fa, by simp only [mul_inv_of_self, zero_lt_one],\n  exact \u27e8\u03bb h, pos_of_mul_pos_right this h.le, \u03bb h, pos_of_mul_pos_left this h.le\u27e9\nend\n\n@[simp] lemma inv_of_nonpos [invertible a] : \u215fa \u2264 0 \u2194 a \u2264 0 :=\nby simp only [\u2190 not_lt, inv_of_pos]\n\n@[simp] lemma inv_of_nonneg [invertible a] : 0 \u2264 \u215fa \u2194 0 \u2264 a :=\nbegin\n  have : 0 < a * \u215fa, by simp only [mul_inv_of_self, zero_lt_one],\n  exact \u27e8\u03bb h, (pos_of_mul_pos_right this h).le, \u03bb h, (pos_of_mul_pos_left this h).le\u27e9\nend\n\n@[simp] lemma inv_of_lt_zero [invertible a] : \u215fa < 0 \u2194 a < 0 :=\nby simp only [\u2190 not_le, inv_of_nonneg]\n\n@[simp] lemma inv_of_le_one [invertible a] (h : 1 \u2264 a) : \u215fa \u2264 1 :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nmul_inv_of_self a \u25b8 decidable.le_mul_of_one_le_left (inv_of_nonneg.2 $ zero_le_one.trans h) h\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/order/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7363947889931065}}
{"text": "-- Let us copy Lean's definition of `eq` to our own version of equality\ninductive myeq {\u03b1 : Sort u} (a : \u03b1) : \u03b1 \u2192 Prop\n| refl : myeq a a\n\n-- Our goal is to show that `myeq` is an equivalence relation. That is,\n-- (1) Reflexivity: for all `x : \u03b1`, we have `x \u223c x`\n-- (2) Symmetry: for all `x y : \u03b1`, if `x \u223c y` then `y \u223c x`\n-- (3) Transitivity: for all `x y z : \u03b1`, if `x \u223c y` and `y \u223c z` then `x \u223c z`\n\n-- For convenience, we define an infix notation `\\sim` so that we can write `x \u223c y` instead of `myeq x y`\ninfix:50 \" \u223c \" => myeq\n\n-- We create a namespace `myeq`, so that all theorems `T` we prove will be called `myeq.T`\nnamespace myeq\n\n-- Also, we define some variables, so that we don't have to write them again for each theorem\nvariable {X : Sort u} {x y z : X}\n\n-- (1) Reflexivity follows by definition: it is the constructor! (That is why it is called `refl`)\nexample : x \u223c x := refl\n\n-- We can use the recursor `myeq.rec` to prove that `myeq` is the smallest reflexive relation, that is,\n-- for any other relation `R` on `X` such that `R x x` holds for all `x : X`, if `x \u223c y`, then also `R x y`\ntheorem min_refl (R : X \u2192 X \u2192 Prop) (h : \u2200 x, R x x) (hxy : x \u223c y) : R x y :=\n  myeq.rec (h x) hxy\n\n/-\n  # Exercises\n   Replace each of the sorry's below by proofs, using only things defined in this file\n   That means, using no other tactics than `exact`\n-/\n\n-- (2) Symmetry: for all `x y : \u03b1`, if `x \u223c y` then `y \u223c x`\ntheorem symm (hxy : x \u223c y) : y \u223c x :=\n  min_refl (\u03bb u v => v \u223c u) (\u03bb _ => myeq.refl) hxy\n\n-- It might be useful to prove the following lemma\ntheorem subst (P : X \u2192 Prop) (hxy : x \u223c y) : P x \u2192 P y :=\n  min_refl (\u03bb a b => P a \u2192 P b) (\u03bb _ p => p) hxy\n\n-- (3) Transitivity: for all `x y z : \u03b1`, if `x \u223c y` and `y \u223c z` then `x \u223c z`\ntheorem trans (hxy : x \u223c y) (hyz : y \u223c z) : x \u223c z :=\n  subst (\u03bb a => x \u223c a) hyz hxy\n\n-- Some additional exercises:\ntheorem function_invariant (f : X \u2192 Sort _) (hxy : x \u223c y) : f x \u223c f y :=\n  min_refl (\u03bb a b => f a \u223c f b) (\u03bb _ => refl) hxy\n\n-- Why is the following theorem ill-formed?\n--theorem product_invariant (hxy : x \u223c y) (t : X \u2192 Sort*) (ht : t x \u223c t y) (f : \u03a0 z : X, t z) : f x \u223c f y := sorry\n\ndef rewrite (f : X \u2192 Sort u) : x \u223c y \u2192 f x \u2192 f y := \u03bb h\u2081 h\u2082 =>\nmatch h\u2081 with\n  | refl => h\u2082\n\n-- Application of `rewrite`:\nexample (x y z : Prop) (hxy : x \u223c y) (u : x \u2227 z) : (y \u2227 z) := rewrite (\u03bb a => a \u2227 z) hxy u\n\nend myeq\n", "meta": {"author": "jessetvogel", "repo": "Math4", "sha": "1d6a30589c7b3b3c70e968985d0c1f6f9f242938", "save_path": "github-repos/lean/jessetvogel-Math4", "path": "github-repos/lean/jessetvogel-Math4/Math4-1d6a30589c7b3b3c70e968985d0c1f6f9f242938/Math/Test/Equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.7363947887085488}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module ring_theory.polynomial.opposites\n! leanprover-community/mathlib commit 63417e01fbc711beaf25fa73b6edb395c0cfddd0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.Degree.Definitions\n\n/-!  #  Interactions between `R[X]` and `R\u1d50\u1d52\u1d56[X]`\n\nThis file contains the basic API for \"pushing through\" the isomorphism\n`opRingEquiv : R[X]\u1d50\u1d52\u1d56 \u2243+* R\u1d50\u1d52\u1d56[X]`.  It allows going back and forth between a polynomial ring\nover a semiring and the polynomial ring over the opposite semiring. -/\n\n\nopen Polynomial\n\nopen Polynomial MulOpposite\n\nvariable {R : Type _} [Semiring R]\n\nnoncomputable section\n\nnamespace Polynomial\n\n/-- Ring isomorphism between `R[X]\u1d50\u1d52\u1d56` and `R\u1d50\u1d52\u1d56[X]` sending each coefficient of a polynomial\nto the corresponding element of the opposite ring. -/\ndef opRingEquiv (R : Type _) [Semiring R] : R[X]\u1d50\u1d52\u1d56 \u2243+* R\u1d50\u1d52\u1d56[X] :=\n  ((toFinsuppIso R).op.trans AddMonoidAlgebra.opRingEquiv).trans (toFinsuppIso _).symm\n#align polynomial.op_ring_equiv Polynomial.opRingEquiv\n\n/-!  Lemmas to get started, using `opRingEquiv R` on the various expressions of\n`Finsupp.single`: `monomial`, `C a`, `X`, `C a * X ^ n`. -/\n\n\n@[simp]\ntheorem opRingEquiv_op_monomial (n : \u2115) (r : R) :\n    opRingEquiv R (op (monomial n r : R[X])) = monomial n (op r) := by\n  simp only [opRingEquiv, RingEquiv.coe_trans, Function.comp_apply,\n    AddMonoidAlgebra.opRingEquiv_apply, RingEquiv.op_apply_apply_unop, toFinsuppIso_apply,\n    toFinsupp_monomial, Finsupp.mapRange_single, toFinsuppIso_symm_apply, ofFinsupp_single]\n#align polynomial.op_ring_equiv_op_monomial Polynomial.opRingEquiv_op_monomial\n\n@[simp]\ntheorem opRingEquiv_op_C (a : R) : opRingEquiv R (op (C a)) = C (op a) :=\n  opRingEquiv_op_monomial 0 a\nset_option linter.uppercaseLean3 false in\n#align polynomial.op_ring_equiv_op_C Polynomial.opRingEquiv_op_C\n\n@[simp]\ntheorem opRingEquiv_op_X : opRingEquiv R (op (X : R[X])) = X :=\n  opRingEquiv_op_monomial 1 1\nset_option linter.uppercaseLean3 false in\n#align polynomial.op_ring_equiv_op_X Polynomial.opRingEquiv_op_X\n\ntheorem opRingEquiv_op_C_mul_X_pow (r : R) (n : \u2115) :\n    opRingEquiv R (op (C r * X ^ n : R[X])) = C (op r) * X ^ n := by\n  simp only [X_pow_mul, op_mul, op_pow, map_mul, map_pow, opRingEquiv_op_X, opRingEquiv_op_C]\nset_option linter.uppercaseLean3 false in\n#align polynomial.op_ring_equiv_op_C_mul_X_pow Polynomial.opRingEquiv_op_C_mul_X_pow\n\n/-!  Lemmas to get started, using `(opRingEquiv R).symm` on the various expressions of\n`Finsupp.single`: `monomial`, `C a`, `X`, `C a * X ^ n`. -/\n\n\n@[simp]\ntheorem opRingEquiv_symm_monomial (n : \u2115) (r : R\u1d50\u1d52\u1d56) :\n    (opRingEquiv R).symm (monomial n r) = op (monomial n (unop r)) :=\n  (opRingEquiv R).injective (by simp)\n#align polynomial.op_ring_equiv_symm_monomial Polynomial.opRingEquiv_symm_monomial\n\n@[simp]\ntheorem opRingEquiv_symm_C (a : R\u1d50\u1d52\u1d56) : (opRingEquiv R).symm (C a) = op (C (unop a)) :=\n  opRingEquiv_symm_monomial 0 a\nset_option linter.uppercaseLean3 false in\n#align polynomial.op_ring_equiv_symm_C Polynomial.opRingEquiv_symm_C\n\n@[simp]\ntheorem opRingEquiv_symm_X : (opRingEquiv R).symm (X : R\u1d50\u1d52\u1d56[X]) = op X :=\n  opRingEquiv_symm_monomial 1 1\nset_option linter.uppercaseLean3 false in\n#align polynomial.op_ring_equiv_symm_X Polynomial.opRingEquiv_symm_X\n\ntheorem opRingEquiv_symm_C_mul_X_pow (r : R\u1d50\u1d52\u1d56) (n : \u2115) :\n    (opRingEquiv R).symm (C r * X ^ n : R\u1d50\u1d52\u1d56[X]) = op (C (unop r) * X ^ n) := by\n  rw [C_mul_X_pow_eq_monomial, opRingEquiv_symm_monomial, C_mul_X_pow_eq_monomial]\nset_option linter.uppercaseLean3 false in\n#align polynomial.op_ring_equiv_symm_C_mul_X_pow Polynomial.opRingEquiv_symm_C_mul_X_pow\n\n/-!  Lemmas about more global properties of polynomials and opposites. -/\n\n\n@[simp]\ntheorem coeff_opRingEquiv (p : R[X]\u1d50\u1d52\u1d56) (n : \u2115) :\n    (opRingEquiv R p).coeff n = op ((unop p).coeff n) := by\n  induction' p using MulOpposite.rec' with p\n  cases p\n  rfl\n#align polynomial.coeff_op_ring_equiv Polynomial.coeff_opRingEquiv\n\n@[simp]\ntheorem support_opRingEquiv (p : R[X]\u1d50\u1d52\u1d56) : (opRingEquiv R p).support = (unop p).support := by\n  induction' p using MulOpposite.rec' with p\n  cases p\n  exact Finsupp.support_mapRange_of_injective (map_zero _) _ op_injective\n#align polynomial.support_op_ring_equiv Polynomial.support_opRingEquiv\n\n@[simp]\ntheorem natDegree_opRingEquiv (p : R[X]\u1d50\u1d52\u1d56) : (opRingEquiv R p).natDegree = (unop p).natDegree := by\n  by_cases p0 : p = 0\n  \u00b7 simp only [p0, _root_.map_zero, natDegree_zero, unop_zero]\n  \u00b7 simp only [p0, natDegree_eq_support_max', Ne.def, AddEquivClass.map_eq_zero_iff, not_false_iff,\n      support_opRingEquiv, unop_eq_zero_iff]\n#align polynomial.nat_degree_op_ring_equiv Polynomial.natDegree_opRingEquiv\n\n@[simp]\ntheorem leadingCoeff_opRingEquiv (p : R[X]\u1d50\u1d52\u1d56) :\n    (opRingEquiv R p).leadingCoeff = op (unop p).leadingCoeff := by\n  rw [leadingCoeff, coeff_opRingEquiv, natDegree_opRingEquiv, leadingCoeff]\n#align polynomial.leading_coeff_op_ring_equiv Polynomial.leadingCoeff_opRingEquiv\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/Polynomial/Opposites.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.736394784938148}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module analysis.complex.cauchy_integral\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.ComplexLebesgue\nimport Mathbin.MeasureTheory.Integral.DivergenceTheorem\nimport Mathbin.MeasureTheory.Integral.CircleIntegral\nimport Mathbin.Analysis.Calculus.Dslope\nimport Mathbin.Analysis.Analytic.Basic\nimport Mathbin.Analysis.Complex.ReImTopology\nimport Mathbin.Analysis.Calculus.DiffContOnCl\nimport Mathbin.Data.Real.Cardinality\n\n/-!\n# Cauchy integral formula\n\nIn this file we prove the Cauchy-Goursat theorem and the Cauchy integral formula for integrals over\ncircles. Most results are formulated for a function `f : \u2102 \u2192 E` that takes values in a complex\nBanach space with second countable topology.\n\n## Main statements\n\nIn the following theorems, if the name ends with `off_countable`, then the actual theorem assumes\ndifferentiability at all but countably many points of the set mentioned below.\n\n* `complex.integral_boundary_rect_of_has_fderiv_within_at_real_off_countable`: If a function\n  `f : \u2102 \u2192 E` is continuous on a closed rectangle and *real* differentiable on its interior, then\n  its integral over the boundary of this rectangle is equal to the integral of\n  `I \u2022 f' (x + y * I) 1 - f' (x + y * I) I` over the rectangle, where `f' z w : E` is the derivative\n  of `f` at `z` in the direction `w` and `I = complex.I` is the imaginary unit.\n\n* `complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable`: If a function\n  `f : \u2102 \u2192 E` is continuous on a closed rectangle and is *complex* differentiable on its interior,\n  then its integral over the boundary of this rectangle is equal to zero.\n\n* `complex.circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable`: If a\n  function `f : \u2102 \u2192 E` is continuous on a closed annulus `{z | r \u2264 |z - c| \u2264 R}` and is complex\n  differentiable on its interior `{z | r < |z - c| < R}`, then the integrals of `(z - c)\u207b\u00b9 \u2022 f z`\n  over the outer boundary and over the inner boundary are equal.\n\n* `complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto`,\n  `complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable`:\n  If a function `f : \u2102 \u2192 E` is continuous on a punctured closed disc `{z | |z - c| \u2264 R \u2227 z \u2260 c}`, is\n  complex differentiable on the corresponding punctured open disc, and tends to `y` as `z \u2192 c`,\n  `z \u2260 c`, then the integral of `(z - c)\u207b\u00b9 \u2022 f z` over the circle `|z - c| = R` is equal to\n  `2\u03c0iy`. In particular, if `f` is continuous on the whole closed disc and is complex differentiable\n  on the corresponding open disc, then this integral is equal to `2\u03c0if(c)`.\n\n* `complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable`,\n  `complex.two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable`\n  **Cauchy integral formula**: if `f : \u2102 \u2192 E` is continuous on a closed disc of radius `R` and is\n  complex differentiable on the corresponding open disc, then for any `w` in the corresponding open\n  disc the integral of `(z - w)\u207b\u00b9 \u2022 f z` over the boundary of the disc is equal to `2\u03c0if(w)`.\n  Two versions of the lemma put the multiplier `2\u03c0i` at the different sides of the equality.\n\n* `complex.has_fpower_series_on_ball_of_differentiable_off_countable`: If `f : \u2102 \u2192 E` is continuous\n  on a closed disc of positive radius and is complex differentiable on the corresponding open disc,\n  then it is analytic on the corresponding open disc, and the coefficients of the power series are\n  given by Cauchy integral formulas.\n\n* `differentiable_on.has_fpower_series_on_ball`: If `f : \u2102 \u2192 E` is complex differentiable on a\n  closed disc of positive radius, then it is analytic on the corresponding open disc, and the\n  coefficients of the power series are given by Cauchy integral formulas.\n\n* `differentiable_on.analytic_at`, `differentiable.analytic_at`: If `f : \u2102 \u2192 E` is differentiable\n  on a neighborhood of a point, then it is analytic at this point. In particular, if `f : \u2102 \u2192 E`\n  is differentiable on the whole `\u2102`, then it is analytic at every point `z : \u2102`.\n\n* `differentiable.has_power_series_on_ball`: If `f : \u2102 \u2192 E` is differentiable everywhere then the\n  `cauchy_power_series f z R` is a formal power series representing `f` at `z` with infinite\n  radius of convergence (this holds for any choice of `0 < R`).\n\n## Implementation details\n\nThe proof of the Cauchy integral formula in this file is based on a very general version of the\ndivergence theorem, see `measure_theory.integral_divergence_of_has_fderiv_within_at_off_countable`\n(a version for functions defined on `fin (n + 1) \u2192 \u211d`),\n`measure_theory.integral_divergence_prod_Icc_of_has_fderiv_within_at_off_countable_of_le`, and\n`measure_theory.integral2_divergence_prod_of_has_fderiv_within_at_off_countable` (versions for\nfunctions defined on `\u211d \u00d7 \u211d`).\n\nUsually, the divergence theorem is formulated for a $C^1$ smooth function. The theorems formulated\nabove deal with a function that is\n\n* continuous on a closed box/rectangle;\n* differentiable at all but countably many points of its interior;\n* have divergence integrable over the closed box/rectangle.\n\nFirst, we reformulate the theorem for a *real*-differentiable map `\u2102 \u2192 E`, and relate the integral\nof `f` over the boundary of a rectangle in `\u2102` to the integral of the derivative\n$\\frac{\\partial f}{\\partial \\bar z}$ over the interior of this box. In particular, for a *complex*\ndifferentiable function, the latter derivative is zero, hence the integral over the boundary of a\nrectangle is zero. Thus we get the Cauchy-Goursat theorem for a rectangle in `\u2102`.\n\nNext, we apply the this theorem to the function $F(z)=f(c+e^{z})$ on the rectangle\n$[\\ln r, \\ln R]\\times [0, 2\\pi]$ to prove that\n$$\n  \\oint_{|z-c|=r}\\frac{f(z)\\,dz}{z-c}=\\oint_{|z-c|=R}\\frac{f(z)\\,dz}{z-c}\n$$\nprovided that `f` is continuous on the closed annulus `r \u2264 |z - c| \u2264 R` and is complex\ndifferentiable on its interior `r < |z - c| < R` (possibly, at all but countably many points).\n\nHere and below, we write $\\frac{f(z)}{z-c}$ in the documentation while the actual lemmas use\n`(z - c)\u207b\u00b9 \u2022 f z` because `f z` belongs to some Banach space over `\u2102` and `f z / (z - c)` is\nundefined.\n\nTaking the limit of this equality as `r` tends to `\ud835\udcdd[>] 0`, we prove\n$$\n  \\oint_{|z-c|=R}\\frac{f(z)\\,dz}{z-c}=2\\pi if(c)\n$$\nprovided that `f` is continuous on the closed disc `|z - c| \u2264 R` and is differentiable at all but\ncountably many points of its interior. This is the Cauchy integral formula for the center of a\ncircle. In particular, if we apply this function to `F z = (z - c) \u2022 f z`, then we get\n$$\n  \\oint_{|z-c|=R} f(z)\\,dz=0.\n$$\n\nIn order to deduce the Cauchy integral formula for any point `w`, `|w - c| < R`, we consider the\nslope function `g : \u2102 \u2192 E` given by `g z = (z - w)\u207b\u00b9 \u2022 (f z - f w)` if `z \u2260 w` and `g w = f' w`.\nThis function satisfies assumptions of the previous theorem, so we have\n$$\n  \\oint_{|z-c|=R} \\frac{f(z)\\,dz}{z-w}=\\oint_{|z-c|=R} \\frac{f(w)\\,dz}{z-w}=\n  \\left(\\oint_{|z-c|=R} \\frac{dz}{z-w}\\right)f(w).\n$$\nThe latter integral was computed in `circle_integral.integral_sub_inv_of_mem_ball` and is equal to\n`2 * \u03c0 * complex.I`.\n\nThere is one more step in the actual proof. Since we allow `f` to be non-differentiable on a\ncountable set `s`, we cannot immediately claim that `g` is continuous at `w` if `w \u2208 s`. So, we use\nthe proof outlined in the previous paragraph for `w \u2209 s` (see\n`complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable_aux`), then use continuity\nof both sides of the formula and density of `s\u1d9c` to prove the formula for all points of the open\nball, see `complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable`.\n\nFinally, we use the properties of the Cauchy integrals established elsewhere (see\n`has_fpower_series_on_cauchy_integral`) and Cauchy integral formula to prove that the original\nfunction is analytic on the open ball.\n\n## Tags\n\nCauchy-Goursat theorem, Cauchy integral formula\n-/\n\n\nopen TopologicalSpace Set MeasureTheory intervalIntegral Metric Filter Function\n\nopen Interval Real NNReal ENNReal Topology BigOperators\n\nnoncomputable section\n\nuniverse u\n\nvariable {E : Type u} [NormedAddCommGroup E] [NormedSpace \u2102 E] [CompleteSpace E]\n\nnamespace Complex\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/-- Suppose that a function `f : \u2102 \u2192 E` is continuous on a closed rectangle with opposite corners at\n`z w : \u2102`, is *real* differentiable at all but countably many points of the corresponding open\nrectangle, and $\\frac{\\partial f}{\\partial \\bar z}$ is integrable on this rectangle. Then the\nintegral of `f` over the boundary of the rectangle is equal to the integral of\n$2i\\frac{\\partial f}{\\partial \\bar z}=i\\frac{\\partial f}{\\partial x}-\\frac{\\partial f}{\\partial y}$\nover the rectangle. -/\ntheorem integral_boundary_rect_of_hasFderivAt_real_off_countable (f : \u2102 \u2192 E) (f' : \u2102 \u2192 \u2102 \u2192L[\u211d] E)\n    (z w : \u2102) (s : Set \u2102) (hs : s.Countable) (Hc : ContinuousOn f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n    (Hd :\n      \u2200 x \u2208 Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im) \\ s,\n        HasFderivAt f (f' x) x)\n    (Hi : IntegrableOn (fun z => I \u2022 f' z 1 - f' z I) ([z.re, w.re] \u00d7\u2102 [z.im, w.im])) :\n    ((((\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - \u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n          I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n        I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I)) =\n      \u222b x : \u211d in z.re..w.re, \u222b y : \u211d in z.im..w.im, I \u2022 f' (x + y * I) 1 - f' (x + y * I) I :=\n  by\n  set e : (\u211d \u00d7 \u211d) \u2243L[\u211d] \u2102 := equiv_real_prod_clm.symm\n  have he : \u2200 x y : \u211d, \u2191x + \u2191y * I = e (x, y) := fun x y => (mk_eq_add_mul_I x y).symm\n  have he\u2081 : e (1, 0) = 1 := rfl\n  have he\u2082 : e (0, 1) = I := rfl\n  simp only [he] at *\n  set F : \u211d \u00d7 \u211d \u2192 E := f \u2218 e\n  set F' : \u211d \u00d7 \u211d \u2192 \u211d \u00d7 \u211d \u2192L[\u211d] E := fun p => (f' (e p)).comp (e : \u211d \u00d7 \u211d \u2192L[\u211d] \u2102)\n  have hF' : \u2200 p : \u211d \u00d7 \u211d, (-(I \u2022 F' p)) (1, 0) + F' p (0, 1) = -(I \u2022 f' (e p) 1 - f' (e p) I) :=\n    by\n    rintro \u27e8x, y\u27e9\n    simp only [ContinuousLinearMap.neg_apply, ContinuousLinearMap.smul_apply, F',\n      ContinuousLinearMap.comp_apply, ContinuousLinearEquiv.coe_coe, he\u2081, he\u2082, neg_add_eq_sub,\n      neg_sub]\n  set R : Set (\u211d \u00d7 \u211d) := [z.re, w.re] \u00d7\u02e2 [w.im, z.im]\n  set t : Set (\u211d \u00d7 \u211d) := e \u207b\u00b9' s\n  rw [uIcc_comm z.im] at Hc Hi\n  rw [min_comm z.im, max_comm z.im] at Hd\n  have hR : e \u207b\u00b9' ([z.re, w.re] \u00d7\u2102 [w.im, z.im]) = R := rfl\n  have htc : ContinuousOn F R := Hc.comp e.continuous_on hR.ge\n  have htd :\n    \u2200 p \u2208 Ioo (min z.re w.re) (max z.re w.re) \u00d7\u02e2 Ioo (min w.im z.im) (max w.im z.im) \\ t,\n      HasFderivAt F (F' p) p :=\n    fun p hp => (Hd (e p) hp).comp p e.has_fderiv_at\n  simp_rw [\u2190 intervalIntegral.integral_smul, intervalIntegral.integral_symm w.im z.im, \u2190\n    intervalIntegral.integral_neg, \u2190 hF']\n  refine'\n    (integral2_divergence_prod_of_has_fderiv_within_at_off_countable (fun p => -(I \u2022 F p)) F\n        (fun p => -(I \u2022 F' p)) F' z.re w.im w.re z.im t (hs.preimage e.injective)\n        (htc.const_smul _).neg htc (fun p hp => ((htd p hp).const_smul I).neg) htd _).symm\n  rw [\u2190\n    (volume_preserving_equiv_real_prod.symm _).integrableOn_comp_preimage\n      (MeasurableEquiv.measurableEmbedding _)] at\n    Hi\n  simpa only [hF'] using Hi.neg\n#align complex.integral_boundary_rect_of_has_fderiv_at_real_off_countable Complex.integral_boundary_rect_of_hasFderivAt_real_off_countable\n\n/-- Suppose that a function `f : \u2102 \u2192 E` is continuous on a closed rectangle with opposite corners at\n`z w : \u2102`, is *real* differentiable on the corresponding open rectangle, and\n$\\frac{\\partial f}{\\partial \\bar z}$ is integrable on this rectangle. Then the integral of `f` over\nthe boundary of the rectangle is equal to the integral of\n$2i\\frac{\\partial f}{\\partial \\bar z}=i\\frac{\\partial f}{\\partial x}-\\frac{\\partial f}{\\partial y}$\nover the rectangle. -/\ntheorem integral_boundary_rect_of_continuousOn_of_hasFderivAt_real (f : \u2102 \u2192 E) (f' : \u2102 \u2192 \u2102 \u2192L[\u211d] E)\n    (z w : \u2102) (Hc : ContinuousOn f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n    (Hd :\n      \u2200 x \u2208 Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im),\n        HasFderivAt f (f' x) x)\n    (Hi : IntegrableOn (fun z => I \u2022 f' z 1 - f' z I) ([z.re, w.re] \u00d7\u2102 [z.im, w.im])) :\n    ((((\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - \u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n          I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n        I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I)) =\n      \u222b x : \u211d in z.re..w.re, \u222b y : \u211d in z.im..w.im, I \u2022 f' (x + y * I) 1 - f' (x + y * I) I :=\n  integral_boundary_rect_of_hasFderivAt_real_off_countable f f' z w \u2205 countable_empty Hc\n    (fun x hx => Hd x hx.1) Hi\n#align complex.integral_boundary_rect_of_continuous_on_of_has_fderiv_at_real Complex.integral_boundary_rect_of_continuousOn_of_hasFderivAt_real\n\n/-- Suppose that a function `f : \u2102 \u2192 E` is *real* differentiable on a closed rectangle with opposite\ncorners at `z w : \u2102` and $\\frac{\\partial f}{\\partial \\bar z}$ is integrable on this rectangle. Then\nthe integral of `f` over the boundary of the rectangle is equal to the integral of\n$2i\\frac{\\partial f}{\\partial \\bar z}=i\\frac{\\partial f}{\\partial x}-\\frac{\\partial f}{\\partial y}$\nover the rectangle. -/\ntheorem integral_boundary_rect_of_differentiableOn_real (f : \u2102 \u2192 E) (z w : \u2102)\n    (Hd : DifferentiableOn \u211d f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n    (Hi :\n      IntegrableOn (fun z => I \u2022 fderiv \u211d f z 1 - fderiv \u211d f z I) ([z.re, w.re] \u00d7\u2102 [z.im, w.im])) :\n    ((((\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - \u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n          I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n        I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I)) =\n      \u222b x : \u211d in z.re..w.re,\n        \u222b y : \u211d in z.im..w.im, I \u2022 fderiv \u211d f (x + y * I) 1 - fderiv \u211d f (x + y * I) I :=\n  integral_boundary_rect_of_hasFderivAt_real_off_countable f (fderiv \u211d f) z w \u2205 countable_empty\n    Hd.ContinuousOn\n    (fun x hx =>\n      Hd.HasFderivAt <| by\n        simpa only [\u2190 mem_interior_iff_mem_nhds, interior_re_prod_im, uIcc, interior_Icc] using\n          hx.1)\n    Hi\n#align complex.integral_boundary_rect_of_differentiable_on_real Complex.integral_boundary_rect_of_differentiableOn_real\n\n/-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function\nover the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed\nrectangle and is complex differentiable at all but countably many points of the corresponding open\nrectangle, then its integral over the boundary of the rectangle equals zero. -/\ntheorem integral_boundary_rect_eq_zero_of_differentiable_on_off_countable (f : \u2102 \u2192 E) (z w : \u2102)\n    (s : Set \u2102) (hs : s.Countable) (Hc : ContinuousOn f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n    (Hd :\n      \u2200 x \u2208 Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im) \\ s,\n        DifferentiableAt \u2102 f x) :\n    ((((\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - \u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n          I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n        I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I)) =\n      0 :=\n  by\n  refine'\n      (integral_boundary_rect_of_has_fderiv_at_real_off_countable f\n            (fun z => (fderiv \u2102 f z).restrictScalars \u211d) z w s hs Hc\n            (fun x hx => (Hd x hx).HasFderivAt.restrictScalars \u211d) _).trans\n        _ <;>\n    simp [\u2190 ContinuousLinearMap.map_smul]\n#align complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable Complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable\n\n/-- **Cauchy-Goursat theorem for a rectangle**: the integral of a complex differentiable function\nover the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed\nrectangle and is complex differentiable on the corresponding open rectangle, then its integral over\nthe boundary of the rectangle equals zero. -/\ntheorem integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn (f : \u2102 \u2192 E) (z w : \u2102)\n    (Hc : ContinuousOn f ([z.re, w.re] \u00d7\u2102 [z.im, w.im]))\n    (Hd :\n      DifferentiableOn \u2102 f\n        (Ioo (min z.re w.re) (max z.re w.re) \u00d7\u2102 Ioo (min z.im w.im) (max z.im w.im))) :\n    ((((\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - \u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n          I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n        I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I)) =\n      0 :=\n  integral_boundary_rect_eq_zero_of_differentiable_on_off_countable f z w \u2205 countable_empty Hc\n    fun x hx => Hd.DifferentiableAt <| (isOpen_Ioo.reProdIm isOpen_Ioo).mem_nhds hx.1\n#align complex.integral_boundary_rect_eq_zero_of_continuous_on_of_differentiable_on Complex.integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn\n\n/-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function\nover the boundary of a rectangle equals zero. More precisely, if `f` is complex differentiable on a\nclosed rectangle, then its integral over the boundary of the rectangle equals zero. -/\ntheorem integral_boundary_rect_eq_zero_of_differentiableOn (f : \u2102 \u2192 E) (z w : \u2102)\n    (H : DifferentiableOn \u2102 f ([z.re, w.re] \u00d7\u2102 [z.im, w.im])) :\n    ((((\u222b x : \u211d in z.re..w.re, f (x + z.im * I)) - \u222b x : \u211d in z.re..w.re, f (x + w.im * I)) +\n          I \u2022 \u222b y : \u211d in z.im..w.im, f (re w + y * I)) -\n        I \u2022 \u222b y : \u211d in z.im..w.im, f (re z + y * I)) =\n      0 :=\n  integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn f z w H.ContinuousOn <|\n    H.mono <|\n      inter_subset_inter (preimage_mono Ioo_subset_Icc_self) (preimage_mono Ioo_subset_Icc_self)\n#align complex.integral_boundary_rect_eq_zero_of_differentiable_on Complex.integral_boundary_rect_eq_zero_of_differentiableOn\n\n/-- If `f : \u2102 \u2192 E` is continuous the closed annulus `r \u2264 \u2016z - c\u2016 \u2264 R`, `0 < r \u2264 R`, and is complex\ndifferentiable at all but countably many points of its interior, then the integrals of\n`f z / (z - c)` (formally, `(z - c)\u207b\u00b9 \u2022 f z`) over the circles `\u2016z - c\u2016 = r` and `\u2016z - c\u2016 = R` are\nequal to each other. -/\ntheorem circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable {c : \u2102}\n    {r R : \u211d} (h0 : 0 < r) (hle : r \u2264 R) {f : \u2102 \u2192 E} {s : Set \u2102} (hs : s.Countable)\n    (hc : ContinuousOn f (closedBall c R \\ ball c r))\n    (hd : \u2200 z \u2208 (ball c R \\ closedBall c r) \\ s, DifferentiableAt \u2102 f z) :\n    (\u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z) = \u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 f z :=\n  by\n  /- We apply the previous lemma to `\u03bb z, f (c + exp z)` on the rectangle\n    `[log r, log R] \u00d7 [0, 2 * \u03c0]`. -/\n  set A := closed_ball c R \\ ball c r\n  obtain \u27e8a, rfl\u27e9 : \u2203 a, Real.exp a = r\n  exact \u27e8Real.log r, Real.exp_log h0\u27e9\n  obtain \u27e8b, rfl\u27e9 : \u2203 b, Real.exp b = R\n  exact \u27e8Real.log R, Real.exp_log (h0.trans_le hle)\u27e9\n  rw [Real.exp_le_exp] at hle\n  -- Unfold definition of `circle_integral` and cancel some terms.\n  suffices\n    (\u222b \u03b8 in 0 ..2 * \u03c0, I \u2022 f (circleMap c (Real.exp b) \u03b8)) =\n      \u222b \u03b8 in 0 ..2 * \u03c0, I \u2022 f (circleMap c (Real.exp a) \u03b8)\n    by\n    simpa only [circleIntegral, add_sub_cancel', of_real_exp, \u2190 exp_add, smul_smul, \u2190\n      div_eq_mul_inv, mul_div_cancel_left _ (circleMap_ne_center (Real.exp_pos _).ne'),\n      circleMap_sub_center, deriv_circleMap]\n  set R := [a, b] \u00d7\u2102 [0, 2 * \u03c0]\n  set g : \u2102 \u2192 \u2102 := (\u00b7 + \u00b7) c \u2218 exp\n  have hdg : Differentiable \u2102 g := differentiable_exp.const_add _\n  replace hs : (g \u207b\u00b9' s).Countable := (hs.preimage (add_right_injective c)).preimage_cexp\n  have h_maps : maps_to g R A := by\n    rintro z \u27e8h, -\u27e9\n    simpa [dist_eq, g, abs_exp, hle] using h.symm\n  replace hc : ContinuousOn (f \u2218 g) R\n  exact hc.comp hdg.continuous.continuous_on h_maps\n  replace hd :\n    \u2200 z \u2208 Ioo (min a b) (max a b) \u00d7\u2102 Ioo (min 0 (2 * \u03c0)) (max 0 (2 * \u03c0)) \\ g \u207b\u00b9' s,\n      DifferentiableAt \u2102 (f \u2218 g) z\n  \u00b7 refine' fun z hz => (hd (g z) \u27e8_, hz.2\u27e9).comp z (hdg _)\n    simpa [g, dist_eq, abs_exp, hle, and_comm] using hz.1.1\n  simpa [g, circleMap, exp_periodic _, sub_eq_zero, \u2190 exp_add] using\n    integral_boundary_rect_eq_zero_of_differentiable_on_off_countable _ \u27e8a, 0\u27e9 \u27e8b, 2 * \u03c0\u27e9 _ hs hc hd\n#align complex.circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable Complex.circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable\n\n/-- **Cauchy-Goursat theorem** for an annulus. If `f : \u2102 \u2192 E` is continuous on the closed annulus\n`r \u2264 \u2016z - c\u2016 \u2264 R`, `0 < r \u2264 R`, and is complex differentiable at all but countably many points of\nits interior, then the integrals of `f` over the circles `\u2016z - c\u2016 = r` and `\u2016z - c\u2016 = R` are equal\nto each other. -/\ntheorem circleIntegral_eq_of_differentiable_on_annulus_off_countable {c : \u2102} {r R : \u211d} (h0 : 0 < r)\n    (hle : r \u2264 R) {f : \u2102 \u2192 E} {s : Set \u2102} (hs : s.Countable)\n    (hc : ContinuousOn f (closedBall c R \\ ball c r))\n    (hd : \u2200 z \u2208 (ball c R \\ closedBall c r) \\ s, DifferentiableAt \u2102 f z) :\n    (\u222e z in C(c, R), f z) = \u222e z in C(c, r), f z :=\n  calc\n    (\u222e z in C(c, R), f z) = \u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 (z - c) \u2022 f z :=\n      (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm\n    _ = \u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 (z - c) \u2022 f z :=\n      (circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable h0 hle hs\n        ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz =>\n        (differentiableAt_id.sub_const _).smul (hd z hz))\n    _ = \u222e z in C(c, r), f z := circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _\n    \n#align complex.circle_integral_eq_of_differentiable_on_annulus_off_countable Complex.circleIntegral_eq_of_differentiable_on_annulus_off_countable\n\n/-- **Cauchy integral formula** for the value at the center of a disc. If `f` is continuous on a\npunctured closed disc of radius `R`, is differentiable at all but countably many points of the\ninterior of this disc, and has a limit `y` at the center of the disc, then the integral\n$\\oint_{\u2016z-c\u2016=R} \\frac{f(z)}{z-c}\\,dz$ is equal to $2\u03c0iy`. -/\ntheorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto {c : \u2102}\n    {R : \u211d} (h0 : 0 < R) {f : \u2102 \u2192 E} {y : E} {s : Set \u2102} (hs : s.Countable)\n    (hc : ContinuousOn f (closedBall c R \\ {c}))\n    (hd : \u2200 z \u2208 (ball c R \\ {c}) \\ s, DifferentiableAt \u2102 f z) (hy : Tendsto f (\ud835\udcdd[{c}\u1d9c] c) (\ud835\udcdd y)) :\n    (\u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z) = (2 * \u03c0 * I : \u2102) \u2022 y :=\n  by\n  rw [\u2190 sub_eq_zero, \u2190 norm_le_zero_iff]\n  refine' le_of_forall_le_of_dense fun \u03b5 \u03b50 => _\n  obtain \u27e8\u03b4, \u03b40, h\u03b4\u27e9 : \u2203 \u03b4 > (0 : \u211d), \u2200 z \u2208 closed_ball c \u03b4 \\ {c}, dist (f z) y < \u03b5 / (2 * \u03c0)\n  exact\n    ((nhdsWithin_hasBasis nhds_basis_closed_ball _).tendsto_iff\u2093 nhds_basis_ball).1 hy _\n      (div_pos \u03b50 Real.two_pi_pos)\n  obtain \u27e8r, hr0, hr\u03b4, hrR\u27e9 : \u2203 r, 0 < r \u2227 r \u2264 \u03b4 \u2227 r \u2264 R :=\n    \u27e8min \u03b4 R, lt_min \u03b40 h0, min_le_left _ _, min_le_right _ _\u27e9\n  have hsub : closed_ball c R \\ ball c r \u2286 closed_ball c R \\ {c} :=\n    diff_subset_diff_right (singleton_subset_iff.2 <| mem_ball_self hr0)\n  have hsub' : ball c R \\ closed_ball c r \u2286 ball c R \\ {c} :=\n    diff_subset_diff_right (singleton_subset_iff.2 <| mem_closed_ball_self hr0.le)\n  have hzne : \u2200 z \u2208 sphere c r, z \u2260 c := fun z hz =>\n    ne_of_mem_of_not_mem hz fun h => hr0.ne' <| dist_self c \u25b8 Eq.symm h\n  /- The integral `\u222e z in C(c, r), f z / (z - c)` does not depend on `0 < r \u2264 R` and tends to\n    `2\u03c0Iy` as `r \u2192 0`. -/\n  calc\n    \u2016(\u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z) - (2 * \u2191\u03c0 * I) \u2022 y\u2016 =\n        \u2016(\u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 f z) - \u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 y\u2016 :=\n      by\n      congr 2\n      \u00b7\n        exact\n          circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable hr0 hrR\n            hs (hc.mono hsub) fun z hz => hd z \u27e8hsub' hz.1, hz.2\u27e9\n      \u00b7 simp [hr0.ne']\n    _ = \u2016\u222e z in C(c, r), (z - c)\u207b\u00b9 \u2022 (f z - y)\u2016 :=\n      by\n      simp only [smul_sub]\n      have hc' : ContinuousOn (fun z => (z - c)\u207b\u00b9) (sphere c r) :=\n        (continuous_on_id.sub continuousOn_const).inv\u2080 fun z hz => sub_ne_zero.2 <| hzne _ hz\n      rw [circleIntegral.integral_sub] <;> refine' (hc'.smul _).CircleIntegrable hr0.le\n      \u00b7\n        exact\n          hc.mono\n            (subset_inter (sphere_subset_closed_ball.trans <| closed_ball_subset_closed_ball hrR)\n              hzne)\n      \u00b7 exact continuousOn_const\n    _ \u2264 2 * \u03c0 * r * (r\u207b\u00b9 * (\u03b5 / (2 * \u03c0))) :=\n      by\n      refine' circleIntegral.norm_integral_le_of_norm_le_const hr0.le fun z hz => _\n      specialize hzne z hz\n      rw [mem_sphere, dist_eq_norm] at hz\n      rw [norm_smul, norm_inv, hz, \u2190 dist_eq_norm]\n      refine' mul_le_mul_of_nonneg_left (h\u03b4 _ \u27e8_, hzne\u27e9).le (inv_nonneg.2 hr0.le)\n      rwa [mem_closedBall_iff_norm, hz]\n    _ = \u03b5 := by\n      field_simp [hr0.ne', real.two_pi_pos.ne']\n      ac_rfl\n    \n#align complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto\n\n/-- **Cauchy integral formula** for the value at the center of a disc. If `f : \u2102 \u2192 E` is continuous\non a closed disc of radius `R` and is complex differentiable at all but countably many points of its\ninterior, then the integral $\\oint_{|z-c|=R} \\frac{f(z)}{z-c}\\,dz$ is equal to $2\u03c0iy`. -/\ntheorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable {R : \u211d} (h0 : 0 < R)\n    {f : \u2102 \u2192 E} {c : \u2102} {s : Set \u2102} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R))\n    (hd : \u2200 z \u2208 ball c R \\ s, DifferentiableAt \u2102 f z) :\n    (\u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 f z) = (2 * \u03c0 * I : \u2102) \u2022 f c :=\n  circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto h0 hs\n    (hc.mono <| diff_subset _ _) (fun z hz => hd z \u27e8hz.1.1, hz.2\u27e9)\n    (hc.ContinuousAt <| closedBall_mem_nhds _ h0).ContinuousWithinAt\n#align complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable\n\n/-- **Cauchy-Goursat theorem** for a disk: if `f : \u2102 \u2192 E` is continuous on a closed disk\n`{z | \u2016z - c\u2016 \u2264 R}` and is complex differentiable at all but countably many points of its interior,\nthen the integral $\\oint_{|z-c|=R}f(z)\\,dz$ equals zero. -/\ntheorem circleIntegral_eq_zero_of_differentiable_on_off_countable {R : \u211d} (h0 : 0 \u2264 R) {f : \u2102 \u2192 E}\n    {c : \u2102} {s : Set \u2102} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R))\n    (hd : \u2200 z \u2208 ball c R \\ s, DifferentiableAt \u2102 f z) : (\u222e z in C(c, R), f z) = 0 :=\n  by\n  rcases h0.eq_or_lt with (rfl | h0); \u00b7 apply circleIntegral.integral_radius_zero\n  calc\n    (\u222e z in C(c, R), f z) = \u222e z in C(c, R), (z - c)\u207b\u00b9 \u2022 (z - c) \u2022 f z :=\n      (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm\n    _ = (2 * \u2191\u03c0 * I : \u2102) \u2022 (c - c) \u2022 f c :=\n      (circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable h0 hs\n        ((continuous_on_id.sub continuousOn_const).smul hc) fun z hz =>\n        (differentiable_at_id.sub_const _).smul (hd z hz))\n    _ = 0 := by rw [sub_self, zero_smul, smul_zero]\n    \n#align complex.circle_integral_eq_zero_of_differentiable_on_off_countable Complex.circleIntegral_eq_zero_of_differentiable_on_off_countable\n\n/-- An auxiliary lemma for\n`complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable`. This lemma assumes\n`w \u2209 s` while the main lemma drops this assumption. -/\ntheorem circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux {R : \u211d} {c w : \u2102}\n    {f : \u2102 \u2192 E} {s : Set \u2102} (hs : s.Countable) (hw : w \u2208 ball c R \\ s)\n    (hc : ContinuousOn f (closedBall c R)) (hd : \u2200 x \u2208 ball c R \\ s, DifferentiableAt \u2102 f x) :\n    (\u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) = (2 * \u03c0 * I : \u2102) \u2022 f w :=\n  by\n  have hR : 0 < R := dist_nonneg.trans_lt hw.1\n  set F : \u2102 \u2192 E := dslope f w\n  have hws : (insert w s).Countable := hs.insert w\n  have hnhds : closed_ball c R \u2208 \ud835\udcdd w := closed_ball_mem_nhds_of_mem hw.1\n  have hcF : ContinuousOn F (closed_ball c R) :=\n    (continuousOn_dslope <| closed_ball_mem_nhds_of_mem hw.1).2 \u27e8hc, hd _ hw\u27e9\n  have hdF : \u2200 z \u2208 ball (c : \u2102) R \\ insert w s, DifferentiableAt \u2102 F z := fun z hz =>\n    (differentiableAt_dslope_of_ne (ne_of_mem_of_not_mem (mem_insert _ _) hz.2).symm).2\n      (hd _ (diff_subset_diff_right (subset_insert _ _) hz))\n  have HI := circle_integral_eq_zero_of_differentiable_on_off_countable hR.le hws hcF hdF\n  have hne : \u2200 z \u2208 sphere c R, z \u2260 w := fun z hz => ne_of_mem_of_not_mem hz (ne_of_lt hw.1)\n  have hFeq : eq_on F (fun z => (z - w)\u207b\u00b9 \u2022 f z - (z - w)\u207b\u00b9 \u2022 f w) (sphere c R) :=\n    by\n    intro z hz\n    calc\n      F z = (z - w)\u207b\u00b9 \u2022 (f z - f w) := update_noteq (hne z hz) _ _\n      _ = (z - w)\u207b\u00b9 \u2022 f z - (z - w)\u207b\u00b9 \u2022 f w := smul_sub _ _ _\n      \n  have hc' : ContinuousOn (fun z => (z - w)\u207b\u00b9) (sphere c R) :=\n    (continuous_on_id.sub continuousOn_const).inv\u2080 fun z hz => sub_ne_zero.2 <| hne z hz\n  rw [\u2190 circleIntegral.integral_sub_inv_of_mem_ball hw.1, \u2190 circleIntegral.integral_smul_const, \u2190\n    sub_eq_zero, \u2190 circleIntegral.integral_sub, \u2190 circleIntegral.integral_congr hR.le hFeq, HI]\n  exacts[(hc'.smul (hc.mono sphere_subset_closed_ball)).CircleIntegrable hR.le,\n    (hc'.smul continuousOn_const).CircleIntegrable hR.le]\n#align complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable_aux Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is continuous on a closed disc of radius `R` and is\ncomplex differentiable at all but countably many points of its interior, then for any `w` in this\ninterior we have $\\frac{1}{2\u03c0i}\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=f(w)$.\n-/\ntheorem two_pi_i_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable {R : \u211d}\n    {c w : \u2102} {f : \u2102 \u2192 E} {s : Set \u2102} (hs : s.Countable) (hw : w \u2208 ball c R)\n    (hc : ContinuousOn f (closedBall c R)) (hd : \u2200 x \u2208 ball c R \\ s, DifferentiableAt \u2102 f x) :\n    ((2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) = f w :=\n  by\n  have hR : 0 < R := dist_nonneg.trans_lt hw\n  suffices w \u2208 closure (ball c R \\ s) by\n    lift R to \u211d\u22650 using hR.le\n    have A : ContinuousAt (fun w => (2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) w :=\n      by\n      have :=\n        hasFpowerSeriesOnCauchyIntegral\n          ((hc.mono sphere_subset_closed_ball).CircleIntegrable R.coe_nonneg) hR\n      refine' this.continuous_on.continuous_at (emetric.is_open_ball.mem_nhds _)\n      rwa [Metric.emetric_ball_nnreal]\n    have B : ContinuousAt f w := hc.continuous_at (closed_ball_mem_nhds_of_mem hw)\n    refine' tendsto_nhds_unique_of_frequently_eq A B ((mem_closure_iff_frequently.1 this).mono _)\n    intro z hz\n    rw [circle_integral_sub_inv_smul_of_differentiable_on_off_countable_aux hs hz hc hd,\n      inv_smul_smul\u2080]\n    simp [Real.pi_ne_zero, I_ne_zero]\n  refine' mem_closure_iff_nhds.2 fun t ht => _\n  -- TODO: generalize to any vector space over `\u211d`\n  set g : \u211d \u2192 \u2102 := fun x => w + x\n  have : tendsto g (\ud835\udcdd 0) (\ud835\udcdd w) :=\n    (continuous_const.add continuous_of_real).tendsto' 0 w (add_zero _)\n  rcases mem_nhds_iff_exists_Ioo_subset.1 (this <| inter_mem ht <| is_open_ball.mem_nhds hw) with\n    \u27e8l, u, hlu\u2080, hlu_sub\u27e9\n  obtain \u27e8x, hx\u27e9 : (Ioo l u \\ g \u207b\u00b9' s).Nonempty :=\n    by\n    refine' nonempty_diff.2 fun hsub => _\n    have : (Ioo l u).Countable :=\n      (hs.preimage ((add_right_injective w).comp of_real_injective)).mono hsub\n    rw [\u2190 Cardinal.le_aleph0_iff_set_countable, Cardinal.mk_Ioo_real (hlu\u2080.1.trans hlu\u2080.2)] at this\n    exact this.not_lt Cardinal.aleph0_lt_continuum\n  exact \u27e8g x, (hlu_sub hx.1).1, (hlu_sub hx.1).2, hx.2\u27e9\n#align complex.two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable Complex.two_pi_i_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is continuous on a closed disc of radius `R` and is\ncomplex differentiable at all but countably many points of its interior, then for any `w` in this\ninterior we have $\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=2\u03c0if(w)$.\n-/\ntheorem circleIntegral_sub_inv_smul_of_differentiable_on_off_countable {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E}\n    {s : Set \u2102} (hs : s.Countable) (hw : w \u2208 ball c R) (hc : ContinuousOn f (closedBall c R))\n    (hd : \u2200 x \u2208 ball c R \\ s, DifferentiableAt \u2102 f x) :\n    (\u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) = (2 * \u03c0 * I : \u2102) \u2022 f w :=\n  by\n  rw [\u2190\n    two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable hs hw hc hd,\n    smul_inv_smul\u2080]\n  simp [Real.pi_ne_zero, I_ne_zero]\n#align complex.circle_integral_sub_inv_smul_of_differentiable_on_off_countable Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is complex differentiable on an open disc and is\ncontinuous on its closure, then for any `w` in this open ball we have\n$\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=2\u03c0if(w)$. -/\ntheorem DiffContOnCl.circleIntegral_sub_inv_smul {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E}\n    (h : DiffContOnCl \u2102 f (ball c R)) (hw : w \u2208 ball c R) :\n    (\u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) = (2 * \u03c0 * I : \u2102) \u2022 f w :=\n  circleIntegral_sub_inv_smul_of_differentiable_on_off_countable countable_empty hw\n    h.continuousOn_ball fun x hx => h.DifferentiableAt isOpen_ball hx.1\n#align diff_cont_on_cl.circle_integral_sub_inv_smul DiffContOnCl.circleIntegral_sub_inv_smul\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is complex differentiable on an open disc and is\ncontinuous on its closure, then for any `w` in this open ball we have\n$\\frac{1}{2\u03c0i}\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=f(w)$. -/\ntheorem DiffContOnCl.two_pi_i_inv_smul_circleIntegral_sub_inv_smul {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E}\n    (hf : DiffContOnCl \u2102 f (ball c R)) (hw : w \u2208 ball c R) :\n    ((2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) = f w :=\n  by\n  have hR : 0 < R := not_le.mp (ball_eq_empty.not.mp (nonempty_of_mem hw).ne_empty)\n  refine'\n    two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable\n      countable_empty hw _ _\n  \u00b7 simpa only [closure_ball c hR.ne.symm] using hf.continuous_on\n  \u00b7 simpa only [diff_empty] using fun z hz => hf.differentiable_at is_open_ball hz\n#align diff_cont_on_cl.two_pi_I_inv_smul_circle_integral_sub_inv_smul DiffContOnCl.two_pi_i_inv_smul_circleIntegral_sub_inv_smul\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 E` is complex differentiable on a closed disc of radius\n`R`, then for any `w` in its interior we have $\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=2\u03c0if(w)$. -/\ntheorem DifferentiableOn.circleIntegral_sub_inv_smul {R : \u211d} {c w : \u2102} {f : \u2102 \u2192 E}\n    (hd : DifferentiableOn \u2102 f (closedBall c R)) (hw : w \u2208 ball c R) :\n    (\u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z) = (2 * \u03c0 * I : \u2102) \u2022 f w :=\n  (hd.mono closure_ball_subset_closedBall).DiffContOnCl.circleIntegral_sub_inv_smul hw\n#align differentiable_on.circle_integral_sub_inv_smul DifferentiableOn.circleIntegral_sub_inv_smul\n\n/-- **Cauchy integral formula**: if `f : \u2102 \u2192 \u2102` is continuous on a closed disc of radius `R` and is\ncomplex differentiable at all but countably many points of its interior, then for any `w` in this\ninterior we have $\\oint_{|z-c|=R}\\frac{f(z)}{z-w}dz=2\\pi i\\,f(w)$.\n-/\ntheorem circleIntegral_div_sub_of_differentiable_on_off_countable {R : \u211d} {c w : \u2102} {s : Set \u2102}\n    (hs : s.Countable) (hw : w \u2208 ball c R) {f : \u2102 \u2192 \u2102} (hc : ContinuousOn f (closedBall c R))\n    (hd : \u2200 z \u2208 ball c R \\ s, DifferentiableAt \u2102 f z) :\n    (\u222e z in C(c, R), f z / (z - w)) = 2 * \u03c0 * I * f w := by\n  simpa only [smul_eq_mul, div_eq_inv_mul] using\n    circle_integral_sub_inv_smul_of_differentiable_on_off_countable hs hw hc hd\n#align complex.circle_integral_div_sub_of_differentiable_on_off_countable Complex.circleIntegral_div_sub_of_differentiable_on_off_countable\n\n/-- If `f : \u2102 \u2192 E` is continuous on a closed ball of positive radius and is differentiable at all\nbut countably many points of the corresponding open ball, then it is analytic on the open ball with\ncoefficients of the power series given by Cauchy integral formulas. -/\ntheorem hasFpowerSeriesOnBallOfDifferentiableOffCountable {R : \u211d\u22650} {c : \u2102} {f : \u2102 \u2192 E} {s : Set \u2102}\n    (hs : s.Countable) (hc : ContinuousOn f (closedBall c R))\n    (hd : \u2200 z \u2208 ball c R \\ s, DifferentiableAt \u2102 f z) (hR : 0 < R) :\n    HasFpowerSeriesOnBall f (cauchyPowerSeries f c R) c R :=\n  { r_le := le_radius_cauchyPowerSeries _ _ _\n    r_pos := ENNReal.coe_pos.2 hR\n    HasSum := fun w hw =>\n      by\n      have hw' : c + w \u2208 ball c R := by\n        simpa only [add_mem_ball_iff_norm, \u2190 coe_nnnorm, mem_emetric_ball_zero_iff,\n          NNReal.coe_lt_coe, ENNReal.coe_lt_coe] using hw\n      rw [\u2190\n        two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable hs hw' hc\n          hd]\n      exact\n        (hasFpowerSeriesOnCauchyIntegral ((hc.mono sphere_subset_closed_ball).CircleIntegrable R.2)\n              hR).HasSum\n          hw }\n#align complex.has_fpower_series_on_ball_of_differentiable_off_countable Complex.hasFpowerSeriesOnBallOfDifferentiableOffCountable\n\n/-- If `f : \u2102 \u2192 E` is complex differentiable on an open disc of positive radius and is continuous\non its closure, then it is analytic on the open disc with coefficients of the power series given by\nCauchy integral formulas. -/\ntheorem DiffContOnCl.hasFpowerSeriesOnBall {R : \u211d\u22650} {c : \u2102} {f : \u2102 \u2192 E}\n    (hf : DiffContOnCl \u2102 f (ball c R)) (hR : 0 < R) :\n    HasFpowerSeriesOnBall f (cauchyPowerSeries f c R) c R :=\n  hasFpowerSeriesOnBallOfDifferentiableOffCountable countable_empty hf.continuousOn_ball\n    (fun z hz => hf.DifferentiableAt isOpen_ball hz.1) hR\n#align diff_cont_on_cl.has_fpower_series_on_ball DiffContOnCl.hasFpowerSeriesOnBall\n\n/-- If `f : \u2102 \u2192 E` is complex differentiable on a closed disc of positive radius, then it is\nanalytic on the corresponding open disc, and the coefficients of the power series are given by\nCauchy integral formulas. See also\n`complex.has_fpower_series_on_ball_of_differentiable_off_countable` for a version of this lemma with\nweaker assumptions. -/\nprotected theorem DifferentiableOn.hasFpowerSeriesOnBall {R : \u211d\u22650} {c : \u2102} {f : \u2102 \u2192 E}\n    (hd : DifferentiableOn \u2102 f (closedBall c R)) (hR : 0 < R) :\n    HasFpowerSeriesOnBall f (cauchyPowerSeries f c R) c R :=\n  (hd.mono closure_ball_subset_closedBall).DiffContOnCl.HasFpowerSeriesOnBall hR\n#align differentiable_on.has_fpower_series_on_ball DifferentiableOn.hasFpowerSeriesOnBall\n\n/-- If `f : \u2102 \u2192 E` is complex differentiable on some set `s`, then it is analytic at any point `z`\nsuch that `s \u2208 \ud835\udcdd z` (equivalently, `z \u2208 interior s`). -/\nprotected theorem DifferentiableOn.analyticAt {s : Set \u2102} {f : \u2102 \u2192 E} {z : \u2102}\n    (hd : DifferentiableOn \u2102 f s) (hz : s \u2208 \ud835\udcdd z) : AnalyticAt \u2102 f z :=\n  by\n  rcases nhds_basis_closed_ball.mem_iff.1 hz with \u27e8R, hR0, hRs\u27e9\n  lift R to \u211d\u22650 using hR0.le\n  exact ((hd.mono hRs).HasFpowerSeriesOnBall hR0).AnalyticAt\n#align differentiable_on.analytic_at DifferentiableOn.analyticAt\n\ntheorem DifferentiableOn.analyticOn {s : Set \u2102} {f : \u2102 \u2192 E} (hd : DifferentiableOn \u2102 f s)\n    (hs : IsOpen s) : AnalyticOn \u2102 f s := fun z hz => hd.AnalyticAt (hs.mem_nhds hz)\n#align differentiable_on.analytic_on DifferentiableOn.analyticOn\n\n/-- A complex differentiable function `f : \u2102 \u2192 E` is analytic at every point. -/\nprotected theorem Differentiable.analyticAt {f : \u2102 \u2192 E} (hf : Differentiable \u2102 f) (z : \u2102) :\n    AnalyticAt \u2102 f z :=\n  hf.DifferentiableOn.AnalyticAt univ_mem\n#align differentiable.analytic_at Differentiable.analyticAt\n\n/-- When `f : \u2102 \u2192 E` is differentiable, the `cauchy_power_series f z R` represents `f` as a power\nseries centered at `z` in the entirety of `\u2102`, regardless of `R : \u211d\u22650`, with  `0 < R`. -/\nprotected theorem Differentiable.hasFpowerSeriesOnBall {f : \u2102 \u2192 E} (h : Differentiable \u2102 f) (z : \u2102)\n    {R : \u211d\u22650} (hR : 0 < R) : HasFpowerSeriesOnBall f (cauchyPowerSeries f z R) z \u221e :=\n  (h.DifferentiableOn.HasFpowerSeriesOnBall hR).rEqTopOfExists fun r hr =>\n    \u27e8_, h.DifferentiableOn.HasFpowerSeriesOnBall hr\u27e9\n#align differentiable.has_fpower_series_on_ball Differentiable.hasFpowerSeriesOnBall\n\nend Complex\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/Complex/CauchyIntegral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7363947824364054}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\n\nimport data.polynomial.splits\nimport ring_theory.adjoin.basic\nimport ring_theory.adjoin_root\n\n/-!\n# Adjoining elements to a field\n\nSome lemmas on the ring generating by adjoining an element to a field.\n\n## Main statements\n\n* `lift_of_splits`: If `K` and `L` are field extensions of `F` and we have `s : finset K` such that\nthe minimal polynomial of each `x \u2208 s` splits in `L` then `algebra.adjoin F s` embeds in `L`.\n\n-/\n\nnoncomputable theory\nopen_locale big_operators polynomial\n\nsection embeddings\n\nvariables (F : Type*) [field F]\n\n/-- If `p` is the minimal polynomial of `a` over `F` then `F[a] \u2243\u2090[F] F[x]/(p)` -/\ndef alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly\n  {R : Type*} [comm_ring R] [algebra F R] (x : R) :\n  algebra.adjoin F ({x} : set R) \u2243\u2090[F] adjoin_root (minpoly F x) :=\nalg_equiv.symm $ alg_equiv.of_bijective\n  (alg_hom.cod_restrict\n    (adjoin_root.lift_hom _ x $ minpoly.aeval F x) _\n    (\u03bb p, adjoin_root.induction_on _ p $ \u03bb p,\n      (algebra.adjoin_singleton_eq_range_aeval F x).symm \u25b8\n        (polynomial.aeval _).mem_range.mpr \u27e8p, rfl\u27e9))\n  \u27e8(alg_hom.injective_cod_restrict _ _ _).2 $ (injective_iff_map_eq_zero _).2 $ \u03bb p,\n    adjoin_root.induction_on _ p $ \u03bb p hp, ideal.quotient.eq_zero_iff_mem.2 $\n    ideal.mem_span_singleton.2 $ minpoly.dvd F x hp,\n  \u03bb y,\n    let \u27e8p, hp\u27e9 := (set_like.ext_iff.1\n      (algebra.adjoin_singleton_eq_range_aeval F x) (y : R)).1 y.2 in\n    \u27e8adjoin_root.mk _ p, subtype.eq hp\u27e9\u27e9\n\nopen finset\n\n/-- If `K` and `L` are field extensions of `F` and we have `s : finset K` such that\nthe minimal polynomial of each `x \u2208 s` splits in `L` then `algebra.adjoin F s` embeds in `L`. -/\ntheorem lift_of_splits {F K L : Type*} [field F] [field K] [field L]\n  [algebra F K] [algebra F L] (s : finset K) :\n  (\u2200 x \u2208 s, is_integral F x \u2227 polynomial.splits (algebra_map F L) (minpoly F x)) \u2192\n  nonempty (algebra.adjoin F (\u2191s : set K) \u2192\u2090[F] L) :=\nbegin\n  classical,\n  refine finset.induction_on s (\u03bb H, _) (\u03bb a s has ih H, _),\n  { rw [coe_empty, algebra.adjoin_empty],\n    exact \u27e8(algebra.of_id F L).comp (algebra.bot_equiv F K)\u27e9 },\n  rw forall_mem_insert at H, rcases H with \u27e8\u27e8H1, H2\u27e9, H3\u27e9, cases ih H3 with f,\n  choose H3 H4 using H3,\n  rw [coe_insert, set.insert_eq, set.union_comm, algebra.adjoin_union_eq_adjoin_adjoin],\n  letI := (f : algebra.adjoin F (\u2191s : set K) \u2192+* L).to_algebra,\n  haveI : finite_dimensional F (algebra.adjoin F (\u2191s : set K)) := (\n    (submodule.fg_iff_finite_dimensional _).1\n      (fg_adjoin_of_finite s.finite_to_set H3)).of_subalgebra_to_submodule,\n  letI := field_of_finite_dimensional F (algebra.adjoin F (\u2191s : set K)),\n  have H5 : is_integral (algebra.adjoin F (\u2191s : set K)) a := is_integral_of_is_scalar_tower H1,\n  have H6 : (minpoly (algebra.adjoin F (\u2191s : set K)) a).splits\n    (algebra_map (algebra.adjoin F (\u2191s : set K)) L),\n  { refine polynomial.splits_of_splits_of_dvd _\n      (polynomial.map_ne_zero $ minpoly.ne_zero H1 :\n        polynomial.map (algebra_map _ _) _ \u2260 0)\n      ((polynomial.splits_map_iff _ _).2 _)\n      (minpoly.dvd _ _ _),\n    { rw \u2190 is_scalar_tower.algebra_map_eq, exact H2 },\n    { rw [polynomial.aeval_map_algebra_map, minpoly.aeval] } },\n  obtain \u27e8y, hy\u27e9 := polynomial.exists_root_of_splits _ H6 (ne_of_lt (minpoly.degree_pos H5)).symm,\n  refine \u27e8subalgebra.of_restrict_scalars _ _ _\u27e9,\n  refine (adjoin_root.lift_hom (minpoly (algebra.adjoin F (\u2191s : set K)) a) y hy).comp _,\n  exact alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly (algebra.adjoin F (\u2191s : set K)) a\nend\n\nend embeddings\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/adjoin/field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7363947783814468}}
{"text": "/-\nCopyright (c) 2022 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\n\nimport data.finsupp.defs\nimport data.finset.pairwise\n\n/-!\n\n# Sums of collections of finsupp, and their support\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\nThis file provides results about the `finsupp.support` of sums of collections of `finsupp`,\nincluding sums of `list`, `multiset`, and `finset`.\n\nThe support of the sum is a subset of the union of the supports:\n* `list.support_sum_subset`\n* `multiset.support_sum_subset`\n* `finset.support_sum_subset`\n\nThe support of the sum of pairwise disjoint finsupps is equal to the union of the supports\n* `list.support_sum_eq`\n* `multiset.support_sum_eq`\n* `finset.support_sum_eq`\n\nMember in the support of the indexed union over a collection iff\nit is a member of the support of a member of the collection:\n* `list.mem_foldr_sup_support_iff`\n* `multiset.mem_sup_map_support_iff`\n* `finset.mem_sup_support_iff`\n\n-/\n\nvariables {\u03b9 M : Type*} [decidable_eq \u03b9]\n\nlemma list.support_sum_subset [add_monoid M] (l : list (\u03b9 \u2192\u2080 M)) :\n  l.sum.support \u2286 l.foldr ((\u2294) \u2218 finsupp.support) \u2205 :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simp only [list.sum_cons, finset.union_comm],\n    refine finsupp.support_add.trans (finset.union_subset_union _ IH),\n    refl }\nend\n\nlemma multiset.support_sum_subset [add_comm_monoid M] (s : multiset (\u03b9 \u2192\u2080 M)) :\n  s.sum.support \u2286 (s.map (finsupp.support)).sup :=\nbegin\n  induction s using quot.induction_on,\n  simpa using list.support_sum_subset _\nend\n\nlemma finset.support_sum_subset [add_comm_monoid M] (s : finset (\u03b9 \u2192\u2080 M)) :\n  (s.sum id).support \u2286 finset.sup s finsupp.support :=\nby { classical, convert multiset.support_sum_subset s.1; simp }\n\nlemma list.mem_foldr_sup_support_iff [has_zero M] {l : list (\u03b9 \u2192\u2080 M)} {x : \u03b9} :\n  x \u2208 l.foldr ((\u2294) \u2218 finsupp.support) \u2205 \u2194 \u2203 (f : \u03b9 \u2192\u2080 M) (hf : f \u2208 l), x \u2208 f.support :=\nbegin\n  simp only [finset.sup_eq_union, list.foldr_map, finsupp.mem_support_iff, exists_prop],\n  induction l with hd tl IH,\n  { simp },\n  { simp only [IH, list.foldr_cons, finset.mem_union, finsupp.mem_support_iff, list.mem_cons_iff],\n    split,\n    { rintro (h|h),\n      { exact \u27e8hd, or.inl rfl, h\u27e9 },\n      { exact h.imp (\u03bb f hf, hf.imp_left or.inr) } },\n    { rintro \u27e8f, rfl|hf, h\u27e9,\n      { exact or.inl h },\n      { exact or.inr \u27e8f, hf, h\u27e9 } } }\nend\n\nlemma multiset.mem_sup_map_support_iff [has_zero M] {s : multiset (\u03b9 \u2192\u2080 M)} {x : \u03b9} :\n  x \u2208 (s.map (finsupp.support)).sup \u2194 \u2203 (f : \u03b9 \u2192\u2080 M) (hf : f \u2208 s), x \u2208 f.support :=\nquot.induction_on s $ \u03bb _, by simpa using list.mem_foldr_sup_support_iff\n\nlemma finset.mem_sup_support_iff [has_zero M] {s : finset (\u03b9 \u2192\u2080 M)} {x : \u03b9} :\n  x \u2208 s.sup finsupp.support \u2194 \u2203 (f : \u03b9 \u2192\u2080 M) (hf : f \u2208 s), x \u2208 f.support :=\nmultiset.mem_sup_map_support_iff\n\nlemma list.support_sum_eq [add_monoid M] (l : list (\u03b9 \u2192\u2080 M))\n  (hl : l.pairwise (disjoint on finsupp.support)) :\n  l.sum.support = l.foldr ((\u2294) \u2218 finsupp.support) \u2205 :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simp only [list.pairwise_cons] at hl,\n    simp only [list.sum_cons, list.foldr_cons, function.comp_app],\n    rw [finsupp.support_add_eq, IH hl.right, finset.sup_eq_union],\n    suffices : disjoint hd.support (tl.foldr ((\u2294) \u2218 finsupp.support) \u2205),\n    { exact finset.disjoint_of_subset_right (list.support_sum_subset _) this },\n    { rw [\u2190list.foldr_map, \u2190finset.bot_eq_empty, list.foldr_sup_eq_sup_to_finset],\n      rw finset.disjoint_sup_right,\n      intros f hf,\n      simp only [list.mem_to_finset, list.mem_map] at hf,\n      obtain \u27e8f, hf, rfl\u27e9 := hf,\n      exact hl.left _ hf } }\nend\n\nlemma multiset.support_sum_eq [add_comm_monoid M] (s : multiset (\u03b9 \u2192\u2080 M))\n  (hs : s.pairwise (disjoint on finsupp.support)) :\n  s.sum.support = (s.map finsupp.support).sup :=\nbegin\n  induction s using quot.induction_on,\n  obtain \u27e8l, hl, hd\u27e9 := hs,\n  convert list.support_sum_eq _ _,\n  { simp },\n  { simp },\n  { simp only [multiset.quot_mk_to_coe'', multiset.coe_map, multiset.coe_eq_coe] at hl,\n    exact hl.symm.pairwise hd (\u03bb _ _ h, disjoint.symm h) }\nend\n\nlemma finset.support_sum_eq [add_comm_monoid M] (s : finset (\u03b9 \u2192\u2080 M))\n  (hs : (s : set (\u03b9 \u2192\u2080 M)).pairwise_disjoint finsupp.support) :\n  (s.sum id).support = finset.sup s finsupp.support :=\nbegin\n  classical,\n  convert multiset.support_sum_eq s.1 _,\n  { exact (finset.sum_val _).symm },\n  { obtain \u27e8l, hl, hn\u27e9 : \u2203 (l : list (\u03b9 \u2192\u2080 M)), l.to_finset = s \u2227 l.nodup,\n    { refine \u27e8s.to_list, _, finset.nodup_to_list _\u27e9,\n      simp },\n    subst hl,\n    rwa [list.to_finset_val, list.dedup_eq_self.mpr hn,\n        multiset.pairwise_coe_iff_pairwise,\n        \u2190list.pairwise_disjoint_iff_coe_to_finset_pairwise_disjoint hn],\n    intros x y hxy,\n    exact symmetric_disjoint hxy }\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/finsupp/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.736390886688631}}
{"text": "/-\n\nEXAM 2 ANSWER KEY AND GRADING RUBRIC\n\nThis is the answer key and grading\nrubric for CS2102 Fall 2018 Exam 2.\nThere are acceptable ways to have\nanswered some of the questions on \nthe exam, so correct answers need\nnot literally match those provided\nhere.\n\n#1. 5 points each, no partial credit\n\n#2. 10 points for the proposition and\n10 points for the proof, with partial\ncredit of 5 points for a proof that is\ncorrect but for minor issues, e.g., a\nmisplaced comma.\n\n#3. 20 points, no partial credit\n\n#4. 10 points for a right proposition,\n10 points for the proof, with 5 points\nfor a proof that's substantially right\nand suffering only from minor issues,\ne.g., a misplaced colon or something.\n\n#5. 10 free points plus 10 points for \nthe proof, with 3 points for using exists \nelim correctly, 3 for using exists intro \ncorrectly, 3 for using forall elimination \ncorrectly (applying the proof of the \u2200 \nto w), and 1 more for getting it all \nright.\n-/\n\n\n/- ******************************* -/\n\n/-\nThis exam focuses on assessing your \nability to write and prove propositions \nin predicate logic, with an emphasis on\npredicates, disjunctions, and existentially \nquantified propositions. There are three \nparts: \n\nA: Predicates [20 points in 4 parts]\nB: Disjuctions [40 points in 2 parts]\nC. Existentials [40 point in 2 parts]\n-/\n\n\n/- ******************************** -/\n/- *** A. PREDICATES [20 points] ***-/\n/- ******************************** -/\n\n/-\n1a. Define a function called isOdd that\ntakes an argument, n : \u2115, and returns a \nproposition that asserts that n is odd.\nThe function will thus be a predicate on \nvalues of type \u2115. Hint: a number is odd\nif it's one more than an even number.\n-/\n\ndef isOdd(n:\u2115) :=\n    \u2203 m, 2 * m + 1 = n\n\n-- We will accept an answer that uses mod\n\n/-\n1b. To test your predicate, use \"example\"\nto write and prove isOdd(15).\n-/\n\nexample : isOdd 15 :=\n    \u27e8 7, rfl \u27e9 \n\n-- an answer using mod will be just rfl\n\n/-\n1c. Define isSmall : \u2115 \u2192 Prop, to be a\npredicate that is true exactly when the\nargument, n, is such that n = 0 \u2228 n = 1\n\u2228 n = 2 \u2228 n = 3 \u2228 n = 4 \u2228 n = 5. (Don't\ntry to rewrite this proposition as an \ninequality; just use it as is.) \n-/\n\ndef isSmall (n: \u2115) : Prop :=\n    n = 0 \u2228 n = 1 \u2228 n = 2 \u2228 n = 3 \u2228 n = 4 \u2228 n = 5 \n\n/-\n1d. Define a predicate, isBoth(n:\u2115) that \nis true exacly when n satisfies both the\nisOdd and isSmall predicates. Use isOdd \nand isSmall in your answer.\n-/\n\ndef isBoth (n: \u2115 ): Prop :=\n    isOdd n \u2227 isSmall n\n\n\n/- ******************* -/\n/- *** DISJUNCTIONS ***-/\n/- ******************* -/\n\n/-\n2. [20 Points]\n\nJane walks to school or she carries \nher lunch. In either case, she uses\na bag. If she walks, she uses a bag for\nher books. If she carries her lunch, she\nuses a bag to carry her food. So if she\nwalks, she uses a bag, and if she carries\nher lunch, she uses a bag. From the fact\nthat she walks or carries her lunch, and\nfrom the added facts that in either case \nshe uses a bag, we can conclude that she \nuses a bag.\n\nUsing Walks, Carries, and Bag as names\nof propositions, write a Lean example \nthat asserts the following proposition; \nthen prove it. \n\nIf Walks, Carries, and Bag are \npropositions, then if (Walks \u2228 Carries) \nis true, and then if (Walks implies Bag)\nis true, and then if (Carries implies Bag)\nis true, then Bag is true.\n\nHere's a start.\n\nexample : \u2200 (Walks Carries Bag : Prop), ...\n-/\n\nexample: \u2200 Walks Carries Bag : Prop, \n    Walks \u2228 Carries \u2192 \n    (Walks \u2192 Bag) \u2192 \n    (Carries \u2192 Bag) \u2192 \n    Bag :=\nbegin\nintros Walks Carries Bag,\nintros wc wb cb,\napply or.elim wc wb cb\nend\n\n-- It's ok with shorter names (W, C, B)\n\n\n/-\n3. [20 Points]\n\nProve the following proposition.\n-/\n\nexample : \n    \u2200 (P Q R : Prop), \n    (P \u2227 Q) \u2192 (Q \u2228 R) \u2192 (P \u2228 R) :=\nbegin\nintros P Q R pq qr,\napply or.inl pq.left\nend\n\n/- *********************** -/\n/- *** C. EXISTENTIALS  ***-/\n/- *********************** -/\n\n/-\n4. [20 points]\n\nReferring to the isBoth predicate you\ndefined in question #1, state and prove \nthe proposition that there *exists* a \nnumber, n, that satisfies isBoth. Remember that you can use the unfold \ntactic to expand the name of a predicate \nin a goal. Use \"example\" to state the \nproposition.\n-/\n\nexample : \u2203 n : \u2115, isBoth n :=\nbegin\napply exists.intro 3,\nunfold isBoth,\napply and.intro,\napply exists.intro 1, apply rfl,\nunfold isSmall,\nright, right, right, left, apply rfl, \nend\n\n\n/-\n5. [20 points]\n\nSuppose that Heavy and Round are\npredicates on values of any type, T.\nProve the proposition that if every \nt : T is Heavy (satisfies the Heavy \npredicate) and if there exists some \nt : T that is Round (satisfies the\nRound predicate) then there exists \nsome t : T is both Heavy and Round\n(satisfies the conjunction of the\ntwo properties). \n-/\n\nexample : \n\u2200 T : Type, \u2200 (Heavy Round : T \u2192 Prop),\n(\u2200 t, Heavy t) \u2192 (\u2203 t, Round t) \u2192\n(\u2203 t, Heavy t \u2227 Round t) :=\nbegin\nintros T H R,\nassume all_h exists_r,\napply exists.elim exists_r, \nintros w rw,\napply exists.intro w,\napply and.intro (all_h w) rw,\nend\n\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm-lean", "sha": "a06a94e98be77170ca1df486c8189338b16cf6c6", "save_path": "github-repos/lean/kevinsullivan-cs-dm-lean", "path": "github-repos/lean/kevinsullivan-cs-dm-lean/cs-dm-lean-a06a94e98be77170ca1df486c8189338b16cf6c6/EXAMS/exam2-key.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.7363908786909396}}
{"text": "class One (M : Type u) where one : M\ninstance {M} [One M] : OfNat M (nat_lit 1) := \u27e8One.one\u27e9\n\nclass Zero (A : Type u) where zero : A\ninstance {A} [Zero A] : OfNat A (nat_lit 0) := \u27e8Zero.zero\u27e9\n\nclass Monoid (M : Type u) extends Mul M, One M where\n  mul_one (m : M) : m * 1 = m\n\nclass AddCommMonoid (A : Type u) extends Add A, Zero A\n\nclass MonoidWithZero (M\u2080 : Type u) extends Monoid M\u2080, Zero M\u2080\n\nclass Semiring (R : Type u) extends AddCommMonoid R, MonoidWithZero R, One R\n\n#print Semiring -- only toMonoid field, no duplicate toOne\n\ndef oneViaMonoid {M} [Monoid M] : M := 1\nexample {R} [Semiring R] : (1 : R) = oneViaMonoid := rfl\n\nexample : Semiring Nat where\n  mul_one := by simp\n  zero := 0\n  one := 1\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/diamond8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.736350433115808}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module data.polynomial.degree.trailing_degree\n! leanprover-community/mathlib commit 69c6a5a12d8a2b159f20933e60115a4f2de62b58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Enat.Basic\nimport Mathbin.Data.Polynomial.Degree.Definitions\n\n/-!\n# Trailing degree of univariate polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\n* `trailing_degree p`: the multiplicity of `X` in the polynomial `p`\n* `nat_trailing_degree`: a variant of `trailing_degree` that takes values in the natural numbers\n* `trailing_coeff`: the coefficient at index `nat_trailing_degree p`\n\nConverts most results about `degree`, `nat_degree` and `leading_coeff` to results about the bottom\nend of a polynomial\n-/\n\n\nnoncomputable section\n\nopen Function Polynomial Finsupp Finset\n\nopen BigOperators Classical Polynomial\n\nnamespace Polynomial\n\nuniverse u v\n\nvariable {R : Type u} {S : Type v} {a b : R} {n m : \u2115}\n\nsection Semiring\n\nvariable [Semiring R] {p q r : R[X]}\n\n#print Polynomial.trailingDegree /-\n/-- `trailing_degree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest\n`X`-exponent in `p`.\n`trailing_degree p = some n` when `p \u2260 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailing_degree 0 = \u22a4`. -/\ndef trailingDegree (p : R[X]) : \u2115\u221e :=\n  p.support.min\n#align polynomial.trailing_degree Polynomial.trailingDegree\n-/\n\n/- warning: polynomial.trailing_degree_lt_wf -> Polynomial.trailingDegree_lt_wf is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], WellFounded.{succ u1} (Polynomial.{u1} R _inst_1) (fun (p : Polynomial.{u1} R _inst_1) (q : Polynomial.{u1} R _inst_1) => LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], WellFounded.{succ u1} (Polynomial.{u1} R _inst_1) (fun (p : Polynomial.{u1} R _inst_1) (q : Polynomial.{u1} R _inst_1) => LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_degree_lt_wf Polynomial.trailingDegree_lt_wf\u2093'. -/\ntheorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q :=\n  InvImage.wf trailingDegree (WithTop.wellFounded_lt Nat.lt_wfRel)\n#align polynomial.trailing_degree_lt_wf Polynomial.trailingDegree_lt_wf\n\n#print Polynomial.natTrailingDegree /-\n/-- `nat_trailing_degree p` forces `trailing_degree p` to `\u2115`, by defining\n`nat_trailing_degree \u22a4 = 0`. -/\ndef natTrailingDegree (p : R[X]) : \u2115 :=\n  (trailingDegree p).getD 0\n#align polynomial.nat_trailing_degree Polynomial.natTrailingDegree\n-/\n\n#print Polynomial.trailingCoeff /-\n/-- `trailing_coeff p` gives the coefficient of the smallest power of `X` in `p`-/\ndef trailingCoeff (p : R[X]) : R :=\n  coeff p (natTrailingDegree p)\n#align polynomial.trailing_coeff Polynomial.trailingCoeff\n-/\n\n#print Polynomial.TrailingMonic /-\n/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/\ndef TrailingMonic (p : R[X]) :=\n  trailingCoeff p = (1 : R)\n#align polynomial.trailing_monic Polynomial.TrailingMonic\n-/\n\n#print Polynomial.TrailingMonic.def /-\ntheorem TrailingMonic.def : TrailingMonic p \u2194 trailingCoeff p = 1 :=\n  Iff.rfl\n#align polynomial.trailing_monic.def Polynomial.TrailingMonic.def\n-/\n\n/- warning: polynomial.trailing_monic.decidable -> Polynomial.TrailingMonic.decidable is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} [_inst_2 : DecidableEq.{succ u1} R], Decidable (Polynomial.TrailingMonic.{u1} R _inst_1 p)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, Decidable (Polynomial.TrailingMonic.{u1} R _inst_1 p)\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_monic.decidable Polynomial.TrailingMonic.decidable\u2093'. -/\ninstance TrailingMonic.decidable [DecidableEq R] : Decidable (TrailingMonic p) := by\n  unfold trailing_monic <;> infer_instance\n#align polynomial.trailing_monic.decidable Polynomial.TrailingMonic.decidable\n\n#print Polynomial.TrailingMonic.trailingCoeff /-\n@[simp]\ntheorem TrailingMonic.trailingCoeff {p : R[X]} (hp : p.TrailingMonic) : trailingCoeff p = 1 :=\n  hp\n#align polynomial.trailing_monic.trailing_coeff Polynomial.TrailingMonic.trailingCoeff\n-/\n\n#print Polynomial.trailingDegree_zero /-\n@[simp]\ntheorem trailingDegree_zero : trailingDegree (0 : R[X]) = \u22a4 :=\n  rfl\n#align polynomial.trailing_degree_zero Polynomial.trailingDegree_zero\n-/\n\n/- warning: polynomial.trailing_coeff_zero -> Polynomial.trailingCoeff_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], Eq.{succ u1} R (Polynomial.trailingCoeff.{u1} R _inst_1 (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], Eq.{succ u1} R (Polynomial.trailingCoeff.{u1} R _inst_1 (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_coeff_zero Polynomial.trailingCoeff_zero\u2093'. -/\n@[simp]\ntheorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.trailing_coeff_zero Polynomial.trailingCoeff_zero\n\n#print Polynomial.natTrailingDegree_zero /-\n@[simp]\ntheorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.nat_trailing_degree_zero Polynomial.natTrailingDegree_zero\n-/\n\n#print Polynomial.trailingDegree_eq_top /-\ntheorem trailingDegree_eq_top : trailingDegree p = \u22a4 \u2194 p = 0 :=\n  \u27e8fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]\u27e9\n#align polynomial.trailing_degree_eq_top Polynomial.trailingDegree_eq_top\n-/\n\n#print Polynomial.trailingDegree_eq_natTrailingDegree /-\ntheorem trailingDegree_eq_natTrailingDegree (hp : p \u2260 0) :\n    trailingDegree p = (natTrailingDegree p : \u2115\u221e) :=\n  by\n  let \u27e8n, hn\u27e9 :=\n    not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt trailingDegree_eq_top.1 hp))\n  have hn : trailingDegree p = n := Classical.not_not.1 hn\n  rw [nat_trailing_degree, hn] <;> rfl\n#align polynomial.trailing_degree_eq_nat_trailing_degree Polynomial.trailingDegree_eq_natTrailingDegree\n-/\n\n#print Polynomial.trailingDegree_eq_iff_natTrailingDegree_eq /-\ntheorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : \u2115} (hp : p \u2260 0) :\n    p.trailingDegree = n \u2194 p.natTrailingDegree = n := by\n  rw [trailing_degree_eq_nat_trailing_degree hp, WithTop.coe_eq_coe]\n#align polynomial.trailing_degree_eq_iff_nat_trailing_degree_eq Polynomial.trailingDegree_eq_iff_natTrailingDegree_eq\n-/\n\n#print Polynomial.trailingDegree_eq_iff_natTrailingDegree_eq_of_pos /-\ntheorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : \u2115} (hn : 0 < n) :\n    p.trailingDegree = n \u2194 p.natTrailingDegree = n :=\n  by\n  constructor\n  \u00b7 intro H\n    rwa [\u2190 trailing_degree_eq_iff_nat_trailing_degree_eq]\n    rintro rfl\n    rw [trailing_degree_zero] at H\n    exact Option.noConfusion H\n  \u00b7 intro H\n    rwa [trailing_degree_eq_iff_nat_trailing_degree_eq]\n    rintro rfl\n    rw [nat_trailing_degree_zero] at H\n    rw [H] at hn\n    exact lt_irrefl _ hn\n#align polynomial.trailing_degree_eq_iff_nat_trailing_degree_eq_of_pos Polynomial.trailingDegree_eq_iff_natTrailingDegree_eq_of_pos\n-/\n\n#print Polynomial.natTrailingDegree_eq_of_trailingDegree_eq_some /-\ntheorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : \u2115}\n    (h : trailingDegree p = n) : natTrailingDegree p = n :=\n  have hp0 : p \u2260 0 := fun hp0 => by rw [hp0] at h <;> exact Option.noConfusion h\n  Option.some_inj.1 <|\n    show (natTrailingDegree p : \u2115\u221e) = n by rwa [\u2190 trailing_degree_eq_nat_trailing_degree hp0]\n#align polynomial.nat_trailing_degree_eq_of_trailing_degree_eq_some Polynomial.natTrailingDegree_eq_of_trailingDegree_eq_some\n-/\n\n/- warning: polynomial.nat_trailing_degree_le_trailing_degree -> Polynomial.natTrailingDegree_le_trailingDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) (Polynomial.trailingDegree.{u1} R _inst_1 p)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) (Polynomial.trailingDegree.{u1} R _inst_1 p)\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_le_trailing_degree Polynomial.natTrailingDegree_le_trailingDegree\u2093'. -/\n@[simp]\ntheorem natTrailingDegree_le_trailingDegree : \u2191(natTrailingDegree p) \u2264 trailingDegree p :=\n  by\n  by_cases hp : p = 0;\n  \u00b7 rw [hp, trailing_degree_zero]\n    exact le_top\n  rw [trailing_degree_eq_nat_trailing_degree hp]\n  exact le_rfl\n#align polynomial.nat_trailing_degree_le_trailing_degree Polynomial.natTrailingDegree_le_trailingDegree\n\n#print Polynomial.natTrailingDegree_eq_of_trailingDegree_eq /-\ntheorem natTrailingDegree_eq_of_trailingDegree_eq [Semiring S] {q : S[X]}\n    (h : trailingDegree p = trailingDegree q) : natTrailingDegree p = natTrailingDegree q := by\n  unfold nat_trailing_degree <;> rw [h]\n#align polynomial.nat_trailing_degree_eq_of_trailing_degree_eq Polynomial.natTrailingDegree_eq_of_trailingDegree_eq\n-/\n\n/- warning: polynomial.le_trailing_degree_of_ne_zero -> Polynomial.le_trailingDegree_of_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n))\nbut is expected to have type\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_trailing_degree_of_ne_zero Polynomial.le_trailingDegree_of_ne_zero\u2093'. -/\ntheorem le_trailingDegree_of_ne_zero (h : coeff p n \u2260 0) : trailingDegree p \u2264 n :=\n  show @LE.le \u2115\u221e _ p.support.min n from min_le (mem_support_iff.2 h)\n#align polynomial.le_trailing_degree_of_ne_zero Polynomial.le_trailingDegree_of_ne_zero\n\n/- warning: polynomial.nat_trailing_degree_le_of_ne_zero -> Polynomial.natTrailingDegree_le_of_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (LE.le.{0} Nat Nat.hasLe (Polynomial.natTrailingDegree.{u1} R _inst_1 p) n)\nbut is expected to have type\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (LE.le.{0} Nat instLENat (Polynomial.natTrailingDegree.{u1} R _inst_1 p) n)\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_le_of_ne_zero Polynomial.natTrailingDegree_le_of_ne_zero\u2093'. -/\ntheorem natTrailingDegree_le_of_ne_zero (h : coeff p n \u2260 0) : natTrailingDegree p \u2264 n :=\n  by\n  rw [\u2190 WithTop.coe_le_coe, \u2190 trailing_degree_eq_nat_trailing_degree]\n  \u00b7 exact le_trailing_degree_of_ne_zero h\n  \u00b7 intro h\n    subst h\n    exact h rfl\n#align polynomial.nat_trailing_degree_le_of_ne_zero Polynomial.natTrailingDegree_le_of_ne_zero\n\n/- warning: polynomial.trailing_degree_le_trailing_degree -> Polynomial.trailingDegree_le_trailingDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 q (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (Polynomial.trailingDegree.{u1} R _inst_1 q) (Polynomial.trailingDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 q (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Polynomial.trailingDegree.{u1} R _inst_1 q) (Polynomial.trailingDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_degree_le_trailing_degree Polynomial.trailingDegree_le_trailingDegree\u2093'. -/\ntheorem trailingDegree_le_trailingDegree (h : coeff q (natTrailingDegree p) \u2260 0) :\n    trailingDegree q \u2264 trailingDegree p :=\n  by\n  by_cases hp : p = 0\n  \u00b7 rw [hp]\n    exact le_top\n  \u00b7 rw [trailing_degree_eq_nat_trailing_degree hp]\n    exact le_trailing_degree_of_ne_zero h\n#align polynomial.trailing_degree_le_trailing_degree Polynomial.trailingDegree_le_trailingDegree\n\n#print Polynomial.trailingDegree_ne_of_natTrailingDegree_ne /-\ntheorem trailingDegree_ne_of_natTrailingDegree_ne {n : \u2115} :\n    p.natTrailingDegree \u2260 n \u2192 trailingDegree p \u2260 n :=\n  mt fun h => by rw [nat_trailing_degree, h, Option.getD_coe]\n#align polynomial.trailing_degree_ne_of_nat_trailing_degree_ne Polynomial.trailingDegree_ne_of_natTrailingDegree_ne\n-/\n\n/- warning: polynomial.nat_trailing_degree_le_of_trailing_degree_le -> Polynomial.natTrailingDegree_le_of_trailingDegree_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {n : Nat} {hp : Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))}, (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n) (Polynomial.trailingDegree.{u1} R _inst_1 p)) -> (LE.le.{0} Nat Nat.hasLe n (Polynomial.natTrailingDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {n : Nat} {hp : Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))}, (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n) (Polynomial.trailingDegree.{u1} R _inst_1 p)) -> (LE.le.{0} Nat instLENat n (Polynomial.natTrailingDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_le_of_trailing_degree_le Polynomial.natTrailingDegree_le_of_trailingDegree_le\u2093'. -/\ntheorem natTrailingDegree_le_of_trailingDegree_le {n : \u2115} {hp : p \u2260 0}\n    (H : (n : \u2115\u221e) \u2264 trailingDegree p) : n \u2264 natTrailingDegree p :=\n  by\n  rw [trailing_degree_eq_nat_trailing_degree hp] at H\n  exact with_top.coe_le_coe.mp H\n#align polynomial.nat_trailing_degree_le_of_trailing_degree_le Polynomial.natTrailingDegree_le_of_trailingDegree_le\n\n/- warning: polynomial.nat_trailing_degree_le_nat_trailing_degree -> Polynomial.natTrailingDegree_le_natTrailingDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1} {hq : Ne.{succ u1} (Polynomial.{u1} R _inst_1) q (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))}, (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)) -> (LE.le.{0} Nat Nat.hasLe (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1} {hq : Ne.{succ u1} (Polynomial.{u1} R _inst_1) q (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))}, (LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)) -> (LE.le.{0} Nat instLENat (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_le_nat_trailing_degree Polynomial.natTrailingDegree_le_natTrailingDegree\u2093'. -/\ntheorem natTrailingDegree_le_natTrailingDegree {hq : q \u2260 0}\n    (hpq : p.trailingDegree \u2264 q.trailingDegree) : p.natTrailingDegree \u2264 q.natTrailingDegree :=\n  by\n  by_cases hp : p = 0;\n  \u00b7 rw [hp, nat_trailing_degree_zero]\n    exact zero_le _\n  rwa [trailing_degree_eq_nat_trailing_degree hp, trailing_degree_eq_nat_trailing_degree hq,\n    WithTop.coe_le_coe] at hpq\n#align polynomial.nat_trailing_degree_le_nat_trailing_degree Polynomial.natTrailingDegree_le_natTrailingDegree\n\n/- warning: polynomial.trailing_degree_monomial -> Polynomial.trailingDegree_monomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a)) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_degree_monomial Polynomial.trailingDegree_monomial\u2093'. -/\n@[simp]\ntheorem trailingDegree_monomial (ha : a \u2260 0) : trailingDegree (monomial n a) = n := by\n  rw [trailing_degree, support_monomial n ha, min_singleton]\n#align polynomial.trailing_degree_monomial Polynomial.trailingDegree_monomial\n\n/- warning: polynomial.nat_trailing_degree_monomial -> Polynomial.natTrailingDegree_monomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a)) n)\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a)) n)\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_monomial Polynomial.natTrailingDegree_monomial\u2093'. -/\ntheorem natTrailingDegree_monomial (ha : a \u2260 0) : natTrailingDegree (monomial n a) = n := by\n  rw [nat_trailing_degree, trailing_degree_monomial ha] <;> rfl\n#align polynomial.nat_trailing_degree_monomial Polynomial.natTrailingDegree_monomial\n\n/- warning: polynomial.nat_trailing_degree_monomial_le -> Polynomial.natTrailingDegree_monomial_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], LE.le.{0} Nat Nat.hasLe (Polynomial.natTrailingDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a)) n\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], LE.le.{0} Nat instLENat (Polynomial.natTrailingDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a)) n\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_monomial_le Polynomial.natTrailingDegree_monomial_le\u2093'. -/\ntheorem natTrailingDegree_monomial_le : natTrailingDegree (monomial n a) \u2264 n :=\n  if ha : a = 0 then by simp [ha] else (natTrailingDegree_monomial ha).le\n#align polynomial.nat_trailing_degree_monomial_le Polynomial.natTrailingDegree_monomial_le\n\n/- warning: polynomial.le_trailing_degree_monomial -> Polynomial.le_trailingDegree_monomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n) (Polynomial.trailingDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} {n : Nat} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n) (Polynomial.trailingDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) a))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_trailing_degree_monomial Polynomial.le_trailingDegree_monomial\u2093'. -/\ntheorem le_trailingDegree_monomial : \u2191n \u2264 trailingDegree (monomial n a) :=\n  if ha : a = 0 then by simp [ha] else (trailingDegree_monomial ha).ge\n#align polynomial.le_trailing_degree_monomial Polynomial.le_trailingDegree_monomial\n\n/- warning: polynomial.trailing_degree_C -> Polynomial.trailingDegree_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R], (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a)) (OfNat.ofNat.{0} ENat 0 (OfNat.mk.{0} ENat 0 (Zero.zero.{0} ENat ENat.hasZero))))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R], (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a)) (OfNat.ofNat.{0} ENat 0 (Zero.toOfNat0.{0} ENat instENatZero)))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_degree_C Polynomial.trailingDegree_C\u2093'. -/\n@[simp]\ntheorem trailingDegree_C (ha : a \u2260 0) : trailingDegree (C a) = (0 : \u2115\u221e) :=\n  trailingDegree_monomial ha\n#align polynomial.trailing_degree_C Polynomial.trailingDegree_C\n\n/- warning: polynomial.le_trailing_degree_C -> Polynomial.le_trailingDegree_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (OfNat.ofNat.{0} ENat 0 (OfNat.mk.{0} ENat 0 (Zero.zero.{0} ENat ENat.hasZero))) (Polynomial.trailingDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (OfNat.ofNat.{0} ENat 0 (Zero.toOfNat0.{0} ENat instENatZero)) (Polynomial.trailingDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_trailing_degree_C Polynomial.le_trailingDegree_C\u2093'. -/\ntheorem le_trailingDegree_C : (0 : \u2115\u221e) \u2264 trailingDegree (C a) :=\n  le_trailingDegree_monomial\n#align polynomial.le_trailing_degree_C Polynomial.le_trailingDegree_C\n\n/- warning: polynomial.trailing_degree_one_le -> Polynomial.trailingDegree_one_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (OfNat.ofNat.{0} ENat 0 (OfNat.mk.{0} ENat 0 (Zero.zero.{0} ENat ENat.hasZero))) (Polynomial.trailingDegree.{u1} R _inst_1 (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 1 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 1 (One.one.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.hasOne.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (OfNat.ofNat.{0} ENat 0 (Zero.toOfNat0.{0} ENat instENatZero)) (Polynomial.trailingDegree.{u1} R _inst_1 (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 1 (One.toOfNat1.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.one.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_degree_one_le Polynomial.trailingDegree_one_le\u2093'. -/\ntheorem trailingDegree_one_le : (0 : \u2115\u221e) \u2264 trailingDegree (1 : R[X]) := by\n  rw [\u2190 C_1] <;> exact le_trailing_degree_C\n#align polynomial.trailing_degree_one_le Polynomial.trailingDegree_one_le\n\n/- warning: polynomial.nat_trailing_degree_C -> Polynomial.natTrailingDegree_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (a : R), Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (a : R), Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a)) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_C Polynomial.natTrailingDegree_C\u2093'. -/\n@[simp]\ntheorem natTrailingDegree_C (a : R) : natTrailingDegree (C a) = 0 :=\n  nonpos_iff_eq_zero.1 natTrailingDegree_monomial_le\n#align polynomial.nat_trailing_degree_C Polynomial.natTrailingDegree_C\n\n#print Polynomial.natTrailingDegree_one /-\n@[simp]\ntheorem natTrailingDegree_one : natTrailingDegree (1 : R[X]) = 0 :=\n  natTrailingDegree_C 1\n#align polynomial.nat_trailing_degree_one Polynomial.natTrailingDegree_one\n-/\n\n#print Polynomial.natTrailingDegree_nat_cast /-\n@[simp]\ntheorem natTrailingDegree_nat_cast (n : \u2115) : natTrailingDegree (n : R[X]) = 0 := by\n  simp only [\u2190 C_eq_nat_cast, nat_trailing_degree_C]\n#align polynomial.nat_trailing_degree_nat_cast Polynomial.natTrailingDegree_nat_cast\n-/\n\n/- warning: polynomial.trailing_degree_C_mul_X_pow -> Polynomial.trailingDegree_C_mul_X_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] (n : Nat), (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] (n : Nat), (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n))) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_degree_C_mul_X_pow Polynomial.trailingDegree_C_mul_X_pow\u2093'. -/\n@[simp]\ntheorem trailingDegree_C_mul_X_pow (n : \u2115) (ha : a \u2260 0) : trailingDegree (C a * X ^ n) = n := by\n  rw [C_mul_X_pow_eq_monomial, trailing_degree_monomial ha]\n#align polynomial.trailing_degree_C_mul_X_pow Polynomial.trailingDegree_C_mul_X_pow\n\n/- warning: polynomial.le_trailing_degree_C_mul_X_pow -> Polynomial.le_trailingDegree_C_mul_X_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (n : Nat) (a : R), LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n) (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (n : Nat) (a : R), LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n) (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n)))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_trailing_degree_C_mul_X_pow Polynomial.le_trailingDegree_C_mul_X_pow\u2093'. -/\ntheorem le_trailingDegree_C_mul_X_pow (n : \u2115) (a : R) : (n : \u2115\u221e) \u2264 trailingDegree (C a * X ^ n) :=\n  by\n  rw [C_mul_X_pow_eq_monomial]\n  exact le_trailing_degree_monomial\n#align polynomial.le_trailing_degree_C_mul_X_pow Polynomial.le_trailingDegree_C_mul_X_pow\n\n/- warning: polynomial.coeff_eq_zero_of_trailing_degree_lt -> Polynomial.coeff_eq_zero_of_trailingDegree_lt is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n) (Polynomial.trailingDegree.{u1} R _inst_1 p)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n) (Polynomial.trailingDegree.{u1} R _inst_1 p)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.coeff_eq_zero_of_trailing_degree_lt Polynomial.coeff_eq_zero_of_trailingDegree_lt\u2093'. -/\ntheorem coeff_eq_zero_of_trailingDegree_lt (h : (n : \u2115\u221e) < trailingDegree p) : coeff p n = 0 :=\n  Classical.not_not.1 (mt le_trailingDegree_of_ne_zero (not_le_of_gt h))\n#align polynomial.coeff_eq_zero_of_trailing_degree_lt Polynomial.coeff_eq_zero_of_trailingDegree_lt\n\n/- warning: polynomial.coeff_eq_zero_of_lt_nat_trailing_degree -> Polynomial.coeff_eq_zero_of_lt_natTrailingDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {n : Nat}, (LT.lt.{0} Nat Nat.hasLt n (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {n : Nat}, (LT.lt.{0} Nat instLTNat n (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.coeff_eq_zero_of_lt_nat_trailing_degree Polynomial.coeff_eq_zero_of_lt_natTrailingDegree\u2093'. -/\ntheorem coeff_eq_zero_of_lt_natTrailingDegree {p : R[X]} {n : \u2115} (h : n < p.natTrailingDegree) :\n    p.coeff n = 0 := by\n  apply coeff_eq_zero_of_trailing_degree_lt\n  by_cases hp : p = 0\n  \u00b7 rw [hp, trailing_degree_zero]\n    exact WithTop.coe_lt_top n\n  \u00b7 rwa [trailing_degree_eq_nat_trailing_degree hp, WithTop.coe_lt_coe]\n#align polynomial.coeff_eq_zero_of_lt_nat_trailing_degree Polynomial.coeff_eq_zero_of_lt_natTrailingDegree\n\n/- warning: polynomial.coeff_nat_trailing_degree_pred_eq_zero -> Polynomial.coeff_natTrailingDegree_pred_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {hp : LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (OfNat.ofNat.{0} ENat 0 (OfNat.mk.{0} ENat 0 (Zero.zero.{0} ENat ENat.hasZero))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) (Polynomial.natTrailingDegree.{u1} R _inst_1 p))}, Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {hp : LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (OfNat.ofNat.{0} ENat 0 (Zero.toOfNat0.{0} ENat instENatZero)) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) (Polynomial.natTrailingDegree.{u1} R _inst_1 p))}, Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.coeff_nat_trailing_degree_pred_eq_zero Polynomial.coeff_natTrailingDegree_pred_eq_zero\u2093'. -/\n@[simp]\ntheorem coeff_natTrailingDegree_pred_eq_zero {p : R[X]} {hp : (0 : \u2115\u221e) < natTrailingDegree p} :\n    p.coeff (p.natTrailingDegree - 1) = 0 :=\n  coeff_eq_zero_of_lt_natTrailingDegree <|\n    Nat.sub_lt ((WithTop.zero_lt_coe (natTrailingDegree p)).mp hp) Nat.one_pos\n#align polynomial.coeff_nat_trailing_degree_pred_eq_zero Polynomial.coeff_natTrailingDegree_pred_eq_zero\n\n/- warning: polynomial.le_trailing_degree_X_pow -> Polynomial.le_trailingDegree_X_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (n : Nat), LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat ENat (HasLiftT.mk.{1, 1} Nat ENat (CoeTC\u2093.coe.{1, 1} Nat ENat ENat.hasCoeT)) n) (Polynomial.trailingDegree.{u1} R _inst_1 (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (n : Nat), LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Nat.cast.{0} ENat (CanonicallyOrderedCommSemiring.toNatCast.{0} ENat instENatCanonicallyOrderedCommSemiring) n) (Polynomial.trailingDegree.{u1} R _inst_1 (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_trailing_degree_X_pow Polynomial.le_trailingDegree_X_pow\u2093'. -/\ntheorem le_trailingDegree_X_pow (n : \u2115) : (n : \u2115\u221e) \u2264 trailingDegree (X ^ n : R[X]) := by\n  simpa only [C_1, one_mul] using le_trailing_degree_C_mul_X_pow n (1 : R)\n#align polynomial.le_trailing_degree_X_pow Polynomial.le_trailingDegree_X_pow\n\n/- warning: polynomial.le_trailing_degree_X -> Polynomial.le_trailingDegree_X is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (OfNat.ofNat.{0} ENat 1 (OfNat.mk.{0} ENat 1 (One.one.{0} ENat (AddMonoidWithOne.toOne.{0} ENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} ENat ENat.addCommMonoidWithOne))))) (Polynomial.trailingDegree.{u1} R _inst_1 (Polynomial.X.{u1} R _inst_1))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R], LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (OfNat.ofNat.{0} ENat 1 (One.toOfNat1.{0} ENat (CanonicallyOrderedCommSemiring.toOne.{0} ENat instENatCanonicallyOrderedCommSemiring))) (Polynomial.trailingDegree.{u1} R _inst_1 (Polynomial.X.{u1} R _inst_1))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_trailing_degree_X Polynomial.le_trailingDegree_X\u2093'. -/\ntheorem le_trailingDegree_X : (1 : \u2115\u221e) \u2264 trailingDegree (X : R[X]) :=\n  le_trailingDegree_monomial\n#align polynomial.le_trailing_degree_X Polynomial.le_trailingDegree_X\n\n#print Polynomial.natTrailingDegree_X_le /-\ntheorem natTrailingDegree_X_le : (X : R[X]).natTrailingDegree \u2264 1 :=\n  natTrailingDegree_monomial_le\n#align polynomial.nat_trailing_degree_X_le Polynomial.natTrailingDegree_X_le\n-/\n\n/- warning: polynomial.trailing_coeff_eq_zero -> Polynomial.trailingCoeff_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, Iff (Eq.{succ u1} R (Polynomial.trailingCoeff.{u1} R _inst_1 p) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (Eq.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, Iff (Eq.{succ u1} R (Polynomial.trailingCoeff.{u1} R _inst_1 p) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (Eq.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_coeff_eq_zero Polynomial.trailingCoeff_eq_zero\u2093'. -/\n@[simp]\ntheorem trailingCoeff_eq_zero : trailingCoeff p = 0 \u2194 p = 0 :=\n  \u27e8fun h =>\n    by_contradiction fun hp =>\n      mt mem_support_iff.1 (Classical.not_not.2 h)\n        (mem_of_min (trailingDegree_eq_natTrailingDegree hp)),\n    fun h => h.symm \u25b8 leadingCoeff_zero\u27e9\n#align polynomial.trailing_coeff_eq_zero Polynomial.trailingCoeff_eq_zero\n\n/- warning: polynomial.trailing_coeff_nonzero_iff_nonzero -> Polynomial.trailingCoeff_nonzero_iff_nonzero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, Iff (Ne.{succ u1} R (Polynomial.trailingCoeff.{u1} R _inst_1 p) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, Iff (Ne.{succ u1} R (Polynomial.trailingCoeff.{u1} R _inst_1 p) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_coeff_nonzero_iff_nonzero Polynomial.trailingCoeff_nonzero_iff_nonzero\u2093'. -/\ntheorem trailingCoeff_nonzero_iff_nonzero : trailingCoeff p \u2260 0 \u2194 p \u2260 0 :=\n  not_congr trailingCoeff_eq_zero\n#align polynomial.trailing_coeff_nonzero_iff_nonzero Polynomial.trailingCoeff_nonzero_iff_nonzero\n\n#print Polynomial.natTrailingDegree_mem_support_of_nonzero /-\ntheorem natTrailingDegree_mem_support_of_nonzero : p \u2260 0 \u2192 natTrailingDegree p \u2208 p.support :=\n  mem_support_iff.mpr \u2218 trailingCoeff_nonzero_iff_nonzero.mpr\n#align polynomial.nat_trailing_degree_mem_support_of_nonzero Polynomial.natTrailingDegree_mem_support_of_nonzero\n-/\n\n#print Polynomial.natTrailingDegree_le_of_mem_supp /-\ntheorem natTrailingDegree_le_of_mem_supp (a : \u2115) : a \u2208 p.support \u2192 natTrailingDegree p \u2264 a :=\n  natTrailingDegree_le_of_ne_zero \u2218 mem_support_iff.mp\n#align polynomial.nat_trailing_degree_le_of_mem_supp Polynomial.natTrailingDegree_le_of_mem_supp\n-/\n\n#print Polynomial.natTrailingDegree_eq_support_min' /-\ntheorem natTrailingDegree_eq_support_min' (h : p \u2260 0) :\n    natTrailingDegree p = p.support.min' (nonempty_support_iff.mpr h) :=\n  by\n  apply le_antisymm\n  \u00b7 apply le_min'\n    intro y hy\n    exact nat_trailing_degree_le_of_mem_supp y hy\n  \u00b7 apply Finset.min'_le\n    exact mem_support_iff.mpr (trailing_coeff_nonzero_iff_nonzero.mpr h)\n#align polynomial.nat_trailing_degree_eq_support_min' Polynomial.natTrailingDegree_eq_support_min'\n-/\n\n/- warning: polynomial.le_nat_trailing_degree -> Polynomial.le_natTrailingDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))) -> (forall (m : Nat), (LT.lt.{0} Nat Nat.hasLt m n) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p m) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))))) -> (LE.le.{0} Nat Nat.hasLe n (Polynomial.natTrailingDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))) -> (forall (m : Nat), (LT.lt.{0} Nat instLTNat m n) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p m) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))))) -> (LE.le.{0} Nat instLENat n (Polynomial.natTrailingDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_nat_trailing_degree Polynomial.le_natTrailingDegree\u2093'. -/\ntheorem le_natTrailingDegree (hp : p \u2260 0) (hn : \u2200 m < n, p.coeff m = 0) : n \u2264 p.natTrailingDegree :=\n  by\n  rw [nat_trailing_degree_eq_support_min' hp]\n  exact Finset.le_min' _ _ _ fun m hm => not_lt.1 fun hmn => mem_support_iff.1 hm <| hn _ hmn\n#align polynomial.le_nat_trailing_degree Polynomial.le_natTrailingDegree\n\n#print Polynomial.natTrailingDegree_le_natDegree /-\ntheorem natTrailingDegree_le_natDegree (p : R[X]) : p.natTrailingDegree \u2264 p.natDegree :=\n  by\n  by_cases hp : p = 0\n  \u00b7 rw [hp, nat_degree_zero, nat_trailing_degree_zero]\n  \u00b7 exact le_nat_degree_of_ne_zero (mt trailing_coeff_eq_zero.mp hp)\n#align polynomial.nat_trailing_degree_le_nat_degree Polynomial.natTrailingDegree_le_natDegree\n-/\n\n#print Polynomial.natTrailingDegree_mul_X_pow /-\ntheorem natTrailingDegree_mul_X_pow {p : R[X]} (hp : p \u2260 0) (n : \u2115) :\n    (p * X ^ n).natTrailingDegree = p.natTrailingDegree + n :=\n  by\n  apply le_antisymm\n  \u00b7 refine' nat_trailing_degree_le_of_ne_zero fun h => mt trailing_coeff_eq_zero.mp hp _\n    rwa [trailing_coeff, \u2190 coeff_mul_X_pow]\n  \u00b7 rw [nat_trailing_degree_eq_support_min' fun h => hp (mul_X_pow_eq_zero h), Finset.le_min'_iff]\n    intro y hy\n    have key : n \u2264 y := by\n      rw [mem_support_iff, coeff_mul_X_pow'] at hy\n      exact by_contra fun h => hy (if_neg h)\n    rw [mem_support_iff, coeff_mul_X_pow', if_pos key] at hy\n    exact (le_tsub_iff_right key).mp (nat_trailing_degree_le_of_ne_zero hy)\n#align polynomial.nat_trailing_degree_mul_X_pow Polynomial.natTrailingDegree_mul_X_pow\n-/\n\n/- warning: polynomial.le_trailing_degree_mul -> Polynomial.le_trailingDegree_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (HAdd.hAdd.{0, 0, 0} ENat ENat ENat (instHAdd.{0} ENat (Distrib.toHasAdd.{0} ENat (NonUnitalNonAssocSemiring.toDistrib.{0} ENat (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENat (Semiring.toNonAssocSemiring.{0} ENat (OrderedSemiring.toSemiring.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)) (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, LE.le.{0} ENat (Preorder.toLE.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (HAdd.hAdd.{0, 0, 0} ENat ENat ENat (instHAdd.{0} ENat (Distrib.toAdd.{0} ENat (NonUnitalNonAssocSemiring.toDistrib.{0} ENat (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENat (Semiring.toNonAssocSemiring.{0} ENat (OrderedSemiring.toSemiring.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring)))))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)) (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q))\nCase conversion may be inaccurate. Consider using '#align polynomial.le_trailing_degree_mul Polynomial.le_trailingDegree_mul\u2093'. -/\ntheorem le_trailingDegree_mul : p.trailingDegree + q.trailingDegree \u2264 (p * q).trailingDegree :=\n  by\n  refine' Finset.le_min fun n hn => _\n  rw [mem_support_iff, coeff_mul] at hn\n  obtain \u27e8\u27e8i, j\u27e9, hij, hpq\u27e9 := exists_ne_zero_of_sum_ne_zero hn\n  refine'\n    (add_le_add (min_le (mem_support_iff.mpr (left_ne_zero_of_mul hpq)))\n          (min_le (mem_support_iff.mpr (right_ne_zero_of_mul hpq)))).trans\n      (le_of_eq _)\n  rwa [\u2190 WithTop.coe_add, WithTop.coe_eq_coe, \u2190 nat.mem_antidiagonal]\n#align polynomial.le_trailing_degree_mul Polynomial.le_trailingDegree_mul\n\n#print Polynomial.le_natTrailingDegree_mul /-\ntheorem le_natTrailingDegree_mul (h : p * q \u2260 0) :\n    p.natTrailingDegree + q.natTrailingDegree \u2264 (p * q).natTrailingDegree :=\n  by\n  have hp : p \u2260 0 := fun hp => h (by rw [hp, MulZeroClass.zero_mul])\n  have hq : q \u2260 0 := fun hq => h (by rw [hq, MulZeroClass.mul_zero])\n  rw [\u2190 WithTop.coe_le_coe, WithTop.coe_add, \u2190 trailing_degree_eq_nat_trailing_degree hp, \u2190\n    trailing_degree_eq_nat_trailing_degree hq, \u2190 trailing_degree_eq_nat_trailing_degree h]\n  exact le_trailing_degree_mul\n#align polynomial.le_nat_trailing_degree_mul Polynomial.le_natTrailingDegree_mul\n-/\n\n/- warning: polynomial.coeff_mul_nat_trailing_degree_add_nat_trailing_degree -> Polynomial.coeff_mul_natTrailingDegree_add_natTrailingDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q))) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (Polynomial.trailingCoeff.{u1} R _inst_1 p) (Polynomial.trailingCoeff.{u1} R _inst_1 q))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q))) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Polynomial.trailingCoeff.{u1} R _inst_1 p) (Polynomial.trailingCoeff.{u1} R _inst_1 q))\nCase conversion may be inaccurate. Consider using '#align polynomial.coeff_mul_nat_trailing_degree_add_nat_trailing_degree Polynomial.coeff_mul_natTrailingDegree_add_natTrailingDegree\u2093'. -/\ntheorem coeff_mul_natTrailingDegree_add_natTrailingDegree :\n    (p * q).coeff (p.natTrailingDegree + q.natTrailingDegree) = p.trailingCoeff * q.trailingCoeff :=\n  by\n  rw [coeff_mul]\n  refine'\n    Finset.sum_eq_single (p.nat_trailing_degree, q.nat_trailing_degree) _ fun h =>\n      (h (nat.mem_antidiagonal.mpr rfl)).elim\n  rintro \u27e8i, j\u27e9 h\u2081 h\u2082\n  rw [nat.mem_antidiagonal] at h\u2081\n  by_cases hi : i < p.nat_trailing_degree\n  \u00b7 rw [coeff_eq_zero_of_lt_nat_trailing_degree hi, MulZeroClass.zero_mul]\n  by_cases hj : j < q.nat_trailing_degree\n  \u00b7 rw [coeff_eq_zero_of_lt_nat_trailing_degree hj, MulZeroClass.mul_zero]\n  rw [not_lt] at hi hj\n  refine' (h\u2082 (prod.ext_iff.mpr _).symm).elim\n  exact (add_eq_add_iff_eq_and_eq hi hj).mp h\u2081.symm\n#align polynomial.coeff_mul_nat_trailing_degree_add_nat_trailing_degree Polynomial.coeff_mul_natTrailingDegree_add_natTrailingDegree\n\n/- warning: polynomial.trailing_degree_mul' -> Polynomial.trailingDegree_mul' is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (Polynomial.trailingCoeff.{u1} R _inst_1 p) (Polynomial.trailingCoeff.{u1} R _inst_1 q)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q)) (HAdd.hAdd.{0, 0, 0} ENat ENat ENat (instHAdd.{0} ENat (Distrib.toHasAdd.{0} ENat (NonUnitalNonAssocSemiring.toDistrib.{0} ENat (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENat (Semiring.toNonAssocSemiring.{0} ENat (OrderedSemiring.toSemiring.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Polynomial.trailingCoeff.{u1} R _inst_1 p) (Polynomial.trailingCoeff.{u1} R _inst_1 q)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} ENat (Polynomial.trailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q)) (HAdd.hAdd.{0, 0, 0} ENat ENat ENat (instHAdd.{0} ENat (Distrib.toAdd.{0} ENat (NonUnitalNonAssocSemiring.toDistrib.{0} ENat (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENat (Semiring.toNonAssocSemiring.{0} ENat (OrderedSemiring.toSemiring.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring)))))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)))\nCase conversion may be inaccurate. Consider using '#align polynomial.trailing_degree_mul' Polynomial.trailingDegree_mul'\u2093'. -/\ntheorem trailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff \u2260 0) :\n    (p * q).trailingDegree = p.trailingDegree + q.trailingDegree :=\n  by\n  have hp : p \u2260 0 := fun hp => h (by rw [hp, trailing_coeff_zero, MulZeroClass.zero_mul])\n  have hq : q \u2260 0 := fun hq => h (by rw [hq, trailing_coeff_zero, MulZeroClass.mul_zero])\n  refine' le_antisymm _ le_trailing_degree_mul\n  rw [trailing_degree_eq_nat_trailing_degree hp, trailing_degree_eq_nat_trailing_degree hq, \u2190\n    ENat.coe_add]\n  apply le_trailing_degree_of_ne_zero\n  rwa [coeff_mul_nat_trailing_degree_add_nat_trailing_degree]\n#align polynomial.trailing_degree_mul' Polynomial.trailingDegree_mul'\n\n/- warning: polynomial.nat_trailing_degree_mul' -> Polynomial.natTrailingDegree_mul' is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (Polynomial.trailingCoeff.{u1} R _inst_1 p) (Polynomial.trailingCoeff.{u1} R _inst_1 q)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Polynomial.trailingCoeff.{u1} R _inst_1 p) (Polynomial.trailingCoeff.{u1} R _inst_1 q)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q)))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_mul' Polynomial.natTrailingDegree_mul'\u2093'. -/\ntheorem natTrailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff \u2260 0) :\n    (p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree :=\n  by\n  have hp : p \u2260 0 := fun hp => h (by rw [hp, trailing_coeff_zero, MulZeroClass.zero_mul])\n  have hq : q \u2260 0 := fun hq => h (by rw [hq, trailing_coeff_zero, MulZeroClass.mul_zero])\n  apply nat_trailing_degree_eq_of_trailing_degree_eq_some\n  rw [trailing_degree_mul' h, WithTop.coe_add, \u2190 trailing_degree_eq_nat_trailing_degree hp, \u2190\n    trailing_degree_eq_nat_trailing_degree hq]\n#align polynomial.nat_trailing_degree_mul' Polynomial.natTrailingDegree_mul'\n\n/- warning: polynomial.nat_trailing_degree_mul -> Polynomial.natTrailingDegree_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1} [_inst_2 : NoZeroDivisors.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))], (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))) -> (Ne.{succ u1} (Polynomial.{u1} R _inst_1) q (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1} [_inst_2 : NoZeroDivisors.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))], (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))) -> (Ne.{succ u1} (Polynomial.{u1} R _inst_1) q (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))) -> (Eq.{1} Nat (Polynomial.natTrailingDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Polynomial.natTrailingDegree.{u1} R _inst_1 p) (Polynomial.natTrailingDegree.{u1} R _inst_1 q)))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_trailing_degree_mul Polynomial.natTrailingDegree_mul\u2093'. -/\ntheorem natTrailingDegree_mul [NoZeroDivisors R] (hp : p \u2260 0) (hq : q \u2260 0) :\n    (p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree :=\n  natTrailingDegree_mul'\n    (mul_ne_zero (mt trailingCoeff_eq_zero.mp hp) (mt trailingCoeff_eq_zero.mp hq))\n#align polynomial.nat_trailing_degree_mul Polynomial.natTrailingDegree_mul\n\nend Semiring\n\nsection NonzeroSemiring\n\nvariable [Semiring R] [Nontrivial R] {p q : R[X]}\n\n#print Polynomial.trailingDegree_one /-\n@[simp]\ntheorem trailingDegree_one : trailingDegree (1 : R[X]) = (0 : \u2115\u221e) :=\n  trailingDegree_C one_ne_zero\n#align polynomial.trailing_degree_one Polynomial.trailingDegree_one\n-/\n\n#print Polynomial.trailingDegree_X /-\n@[simp]\ntheorem trailingDegree_X : trailingDegree (X : R[X]) = 1 :=\n  trailingDegree_monomial one_ne_zero\n#align polynomial.trailing_degree_X Polynomial.trailingDegree_X\n-/\n\n#print Polynomial.natTrailingDegree_X /-\n@[simp]\ntheorem natTrailingDegree_X : (X : R[X]).natTrailingDegree = 1 :=\n  natTrailingDegree_monomial one_ne_zero\n#align polynomial.nat_trailing_degree_X Polynomial.natTrailingDegree_X\n-/\n\nend NonzeroSemiring\n\nsection Ring\n\nvariable [Ring R]\n\n#print Polynomial.trailingDegree_neg /-\n@[simp]\ntheorem trailingDegree_neg (p : R[X]) : trailingDegree (-p) = trailingDegree p := by\n  unfold trailing_degree <;> rw [support_neg]\n#align polynomial.trailing_degree_neg Polynomial.trailingDegree_neg\n-/\n\n#print Polynomial.natTrailingDegree_neg /-\n@[simp]\ntheorem natTrailingDegree_neg (p : R[X]) : natTrailingDegree (-p) = natTrailingDegree p := by\n  simp [nat_trailing_degree]\n#align polynomial.nat_trailing_degree_neg Polynomial.natTrailingDegree_neg\n-/\n\n#print Polynomial.natTrailingDegree_int_cast /-\n@[simp]\ntheorem natTrailingDegree_int_cast (n : \u2124) : natTrailingDegree (n : R[X]) = 0 := by\n  simp only [\u2190 C_eq_int_cast, nat_trailing_degree_C]\n#align polynomial.nat_trailing_degree_int_cast Polynomial.natTrailingDegree_int_cast\n-/\n\nend Ring\n\nsection Semiring\n\nvariable [Semiring R]\n\n#print Polynomial.nextCoeffUp /-\n/-- The second-lowest coefficient, or 0 for constants -/\ndef nextCoeffUp (p : R[X]) : R :=\n  if p.natTrailingDegree = 0 then 0 else p.coeff (p.natTrailingDegree + 1)\n#align polynomial.next_coeff_up Polynomial.nextCoeffUp\n-/\n\n/- warning: polynomial.next_coeff_up_C_eq_zero -> Polynomial.nextCoeffUp_C_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (c : R), Eq.{succ u1} R (Polynomial.nextCoeffUp.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) c)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (c : R), Eq.{succ u1} R (Polynomial.nextCoeffUp.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) c)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.next_coeff_up_C_eq_zero Polynomial.nextCoeffUp_C_eq_zero\u2093'. -/\n@[simp]\ntheorem nextCoeffUp_C_eq_zero (c : R) : nextCoeffUp (C c) = 0 :=\n  by\n  rw [next_coeff_up]\n  simp\n#align polynomial.next_coeff_up_C_eq_zero Polynomial.nextCoeffUp_C_eq_zero\n\n#print Polynomial.nextCoeffUp_of_pos_natTrailingDegree /-\ntheorem nextCoeffUp_of_pos_natTrailingDegree (p : R[X]) (hp : 0 < p.natTrailingDegree) :\n    nextCoeffUp p = p.coeff (p.natTrailingDegree + 1) :=\n  by\n  rw [next_coeff_up, if_neg]\n  contrapose! hp\n  simpa\n#align polynomial.next_coeff_up_of_pos_nat_trailing_degree Polynomial.nextCoeffUp_of_pos_natTrailingDegree\n-/\n\nend Semiring\n\nsection Semiring\n\nvariable [Semiring R] {p q : R[X]} {\u03b9 : Type _}\n\n/- warning: polynomial.coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt -> Polynomial.coeff_natTrailingDegree_eq_zero_of_trailingDegree_lt is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 q (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) (Polynomial.trailingDegree.{u1} R _inst_1 q)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 q (Polynomial.natTrailingDegree.{u1} R _inst_1 p)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt Polynomial.coeff_natTrailingDegree_eq_zero_of_trailingDegree_lt\u2093'. -/\ntheorem coeff_natTrailingDegree_eq_zero_of_trailingDegree_lt\n    (h : trailingDegree p < trailingDegree q) : coeff q (natTrailingDegree p) = 0 :=\n  coeff_eq_zero_of_trailingDegree_lt <| natTrailingDegree_le_trailingDegree.trans_lt h\n#align polynomial.coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt Polynomial.coeff_natTrailingDegree_eq_zero_of_trailingDegree_lt\n\n/- warning: polynomial.ne_zero_of_trailing_degree_lt -> Polynomial.ne_zero_of_trailingDegree_lt is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {n : ENat}, (LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedAddCommMonoid.toPartialOrder.{0} ENat (OrderedSemiring.toOrderedAddCommMonoid.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat ENat.canonicallyOrderedCommSemiring)))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) n) -> (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {n : ENat}, (LT.lt.{0} ENat (Preorder.toLT.{0} ENat (PartialOrder.toPreorder.{0} ENat (OrderedSemiring.toPartialOrder.{0} ENat (OrderedCommSemiring.toOrderedSemiring.{0} ENat (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENat instENatCanonicallyOrderedCommSemiring))))) (Polynomial.trailingDegree.{u1} R _inst_1 p) n) -> (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.ne_zero_of_trailing_degree_lt Polynomial.ne_zero_of_trailingDegree_lt\u2093'. -/\ntheorem ne_zero_of_trailingDegree_lt {n : \u2115\u221e} (h : trailingDegree p < n) : p \u2260 0 := fun h\u2080 =>\n  h.not_le (by simp [h\u2080])\n#align polynomial.ne_zero_of_trailing_degree_lt Polynomial.ne_zero_of_trailingDegree_lt\n\nend Semiring\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Polynomial/Degree/TrailingDegree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642533380189, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.736350414704072}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport data.int.basic\nimport tactic.linear_combination\nimport tactic.linarith\n\n/- \n# Quotients in Lean \n\nUpon request, let's try to see how to construct number systems like the integers or the \nrational numbers in Lean. Note that this is again some mathematical way to do this, not the \nactual way, e.g. integers are defined as the disjoint union of \u2115 with itself, where the first \ncopy is interpreted as the usual natural numbers while the second copy is interpreted as the \nnumbers `1-n` where `n : \u2115`. Similarly, \u211a is contructed as pairs of coprime integers (p,q). \nThis makes them computationally a bit better behaved than our quotient way. \n\n## Equivalence relations in Lean\n\nLean knows what an equivalence relation is. It is a reflexive, symmetric and transitive relation. \nA relation on a set `X` is a function `X \u2192 X \u2192 Prop`, i.e. a function that takes two elements \nof a set `X` and outputs a truth value depending whether they are related or not. \n\n```\ndef reflexive := \u2200 x, x \u223c x\n\ndef symmetric := \u2200 \u2983x y\u2984, x \u223c y \u2192 y \u223c x\n\ndef transitive := \u2200 \u2983x y z\u2984, x \u223c y \u2192 y \u223c m z \u2192 x \u223c z\n\ndef equivalence := reflexive r \u2227 symmetric r \u2227 transitive r\n```\n\n-/\n\ndef R (r s : \u2115 \u00d7 \u2115) : Prop := \nr.1+s.2=s.1+r.2\n\nlemma R_def (r s : \u2115 \u00d7 \u2115) :\nR r s \u2194 r.1 + s.2 = s.1 + r.2 := \nbegin\n  sorry\nend\n\nlemma R_refl : reflexive R :=\nbegin\n  sorry\nend\n\nlemma R_symm : symmetric R :=\nbegin\n  sorry\nend \n\nlemma R_trans : transitive R :=\nbegin\n  /- The lemma add_right_inj could be helpful at some point. -/\n  sorry\nend \n\nlemma R_equiv : equivalence R :=\nbegin \n  sorry\nend\n\n\n/- A setoid on a Type is a relation together with the fact that \n  this relation is an equivalence relation. -/\ninstance s : setoid (\u2115 \u00d7 \u2115) :=\n_\n\nstructure int_plane_non_zero :=\n(fst : \u2124) (snd : \u2124) (non_zero : snd \u2260 0)\n\ndef S (r s : int_plane_non_zero) : Prop :=\nr.1 * s.2 = s.1 * r.2\n\nlemma S_def (r s : int_plane_non_zero) : \nS r s \u2194 r.1 * s.2 = s.1 * r.2 :=\nbegin\n  sorry\nend\n\nlemma S_refl : reflexive S :=\nbegin\n  sorry\nend\n\nlemma S_symm : symmetric S :=\nbegin\n  sorry\nend\n\nlemma S_trans : transitive S :=\nbegin\n  /- The following lemma would be helpful at some point: mul_right_inj' -/\n  sorry\nend \n\nlemma S_equiv : equivalence S := \nbegin \n  sorry\nend\n\ninstance t : setoid (int_plane_non_zero) :=\n_", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/easy_mode/sheet07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7363504116006517}}
{"text": "universe u\n\nopen classical\n\ntheorem not_or_and_not : \u2200 { p q : Prop}, \u00ac (p \u2228 q) \u2192 \u00ac p \u2227 \u00ac q :=\nbegin\n  intros p q h,\n  split,\n  intro hp,\n  apply h,\n  left,\n  exact hp,\n  intro hq,\n  apply h,\n  right,\n  exact hq,\nend \n\ntheorem not_not : \u2200 {p : Prop} , \u00ac\u00acp \u2192 p :=\nbegin\n  intros p nnp,\n  by_contradiction,\n  exact nnp h,\nend\n\ntheorem exists_not_of_not_exists {\u03b1 :Sort u} {p : \u03b1 \u2192 Prop} : (\u00ac(\u2200 x : \u03b1 , p x)) \u2192 \u2203 x : \u03b1 , \u00ac(p x) :=\nbegin\n  intro h\u2081,\n  by_contradiction,\n  have h\u2082 := forall_not_of_not_exists h,\n  simp at h\u2082,\n  apply h\u2081,\n  intro x,\n  apply not_not,\n  apply h\u2082,\nend\n\ntheorem not_or_and_not_eqv (p q : Prop) : \u00ac (p \u2228 q) \u2194 (\u00acp) \u2227 (\u00acq) :=\nbegin\n  split,\n  intro h,\n  split,\n  intro hp,\n  apply h,\n  left,\n  exact hp,\n  intro hq,\n  apply h,\n  right,\n  exact hq,\n  intros h h\u2081,\n  cases h with np nq,\n  cases h\u2081,\n  exact np h\u2081,\n  exact nq h\u2081,\nend\n\ntheorem not_and_or_not : \u2200 {p q : Prop}, \u00ac (p \u2227 q) \u2192 \u00ac p \u2228 \u00acq :=\nbegin\n  intros p q h\u2081,\n  by_contradiction h\u2082,\n  rw not_or_and_not_eqv at h\u2082,\n  apply h\u2081,\n  cases h\u2082 with nnp nnq,\n  split,\n  apply not_not,\n  assumption,\n  apply not_not,\n  assumption,\nend\n\ntheorem implies_or_not (p q : Prop) : p \u2192 q \u2194 (\u00acp) \u2228 q :=\nbegin\n  split,\n  intro hpq,\n  by_cases p,\n  right,\n  exact hpq h,\n  left,\n  exact h,\n  intro h,\n  intro hp,\n  cases h,\n  apply false.elim,\n  apply h,\n  apply hp,\n  exact h,\nend\n\ntheorem not_not_eqv (p : Prop) : \u00ac\u00ac p \u2194 p :=\nbegin\n  split,\n  apply not_not,\n  apply not_not_intro,\nend \n\ntheorem not_implies (p q : Prop) : \u00ac (p \u2192 q) \u2194 p \u2227 \u00acq :=\nbegin\n  rw implies_or_not,\n  rw not_or_and_not_eqv,\n  rw not_not_eqv,\nend\n\ntheorem contrapostive (p q : Prop) : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := \nbegin\n  intros hnqnp hp,\n  cases (em q),\n  exact h,\n  apply false.elim,\n  apply hnqnp h,\n  exact hp, \nend", "meta": {"author": "CameronTorrance", "repo": "Schemes", "sha": "f407ce80b8407101231170680b03b55984c42496", "save_path": "github-repos/lean/CameronTorrance-Schemes", "path": "github-repos/lean/CameronTorrance-Schemes/Schemes-f407ce80b8407101231170680b03b55984c42496/src/misc/prop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7363504098372108}}
{"text": "variables p q r s: Prop\n\n-- commutativity of \u2227 and \u2228\n\ntheorem and_switch (h: p \u2227 q): q \u2227 p :=\n  and.intro h.right h.left\n\nexample: p \u2227 q \u2194 q \u2227 p :=\n  iff.intro\n    (and_switch p q)\n    (and_switch q p)\n\ntheorem or_switch (h: p \u2228 q): q \u2228 p :=\n  or.elim h\n    (assume p, or.inr p)\n    (assume q, or.inl q)\n\nexample: p \u2228 q \u2194 q \u2228 p :=\n  iff.intro\n    (or_switch p q)\n    (or_switch q p)\n\n-- associativity of \u2227 and \u2228\n\nexample: p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  iff.intro\n    (assume h: p \u2227 (q \u2228 r),\n      have hp: p, from h.left,\n      or.elim h.right\n        (assume hq: q,\n          have hpq: p \u2227 q, from and.intro hp hq,\n            or.inl hpq)\n        (assume hr: r,\n          have hpr: p \u2227 r, from and.intro hp hr,\n            or.inr hpr))\n    (assume h: (p \u2227 q) \u2228 (p \u2227 r),\n      or.elim h\n        (assume hpq: p \u2227 q,\n          have hp: p, from hpq.left,\n          have hqr: q \u2228 r, from or.inl hpq.right,\n          and.intro hp hqr)\n        (assume hpr: p \u2227 r,\n          have hp: p, from hpr.left,\n          have hqr: q \u2228 r, from or.inr hpr.right,\n          and.intro hp hqr))\n\nexample: (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n  iff.intro\n    (assume h: (p \u2227 q) \u2227 r,\n      have hpq: p \u2227 q, from h.left,\n      have hp: p, from hpq.left,\n      have hq: q, from hpq.right,\n      have hr: r, from h.right,\n      \u27e8hp, \u27e8hq, hr\u27e9\u27e9)\n    (assume h: p \u2227 (q \u2227 r),\n      have hp: p, from h.left,\n      have hqr: q \u2227 r, from h.right,\n      have hq: q, from hqr.left,\n      have hr: r, from hqr.right,\n      \u27e8\u27e8hp, hq\u27e9, hr\u27e9)\n\n", "meta": {"author": "agro1986", "repo": "lean-proofs", "sha": "a11b42ec47dbb347b66547d7e72e5154e13b6e85", "save_path": "github-repos/lean/agro1986-lean-proofs", "path": "github-repos/lean/agro1986-lean-proofs/lean-proofs-a11b42ec47dbb347b66547d7e72e5154e13b6e85/propositional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7363493531719767}}
{"text": "import algebra.group_power\nimport data.real.basic\nimport tactic.norm_num \n\n-- The integers, rationals and reals are all different types in Lean\n-- and the obvious inclusions between them are all denoted by \u2191 . \nlemma rational_half_not_an_integer : \u00ac \u2203 n : \u2124, (1/2 : \u211a) = \u2191n :=\nbegin\n  -- proof by contradiction\n  rintros \u27e8n,Hn\u27e9, -- n is an integer, Hn the proof that 1/2 = n\n  -- goal is \"false\"\n  have H := rat.coe_int_denom n, -- H says denominator of n is 1\n  rw \u2190Hn at H, -- H now says denominator of 1/2 is 1...\n  exact absurd H dec_trivial -- ...but denominator of 1/2 isn't 1.\nend \n\nlemma real_half_not_an_integer : \u00ac (\u2203 n : \u2124, (1/2 : \u211d) = (n : \u211d) ) :=\nbegin\n  rintro \u27e8n,Hn\u27e9, -- n is an integer, Hn the proof that it's 1/2\n  apply rational_half_not_an_integer,\n  existsi n,\n  -- now our hypothesis is that 1/2 = n as reals, and we want to\n  -- deduce 1/2 = n as rationals!\n  -- This is possible by some messing around with coercions\n  -- from integers to rationals to reals. I wish this were easier\n  -- for beginners in Lean...\n  rw \u2190@rat.cast_inj \u211d _ _,\n  rw rat.cast_coe_int,\n  rw \u2190Hn, --goal now is to prove that real 1/2 = rational 1/2\n  simp -- simplifier is good at that sort of thing\nend \n\n-- proof that the real numbers which are integers and whose squares are less than three\n-- are precisely -1, 0 and 1\n\n\nlemma square_lt_three_of_ge_two (n : \u2115) : \u00ac (n + 2) * (n + 2) < 3 :=\nbegin\n  intro H,\n  suffices Hab : 4 < 3,\n    exact absurd Hab dec_trivial,\n  exact calc\n    4 = 2 * 2             : rfl\n...   \u2264 (n + 2) * 2       : nat.mul_le_mul_right 2 (show 2 \u2264 n+2, from dec_trivial)\n...   \u2264 (n + 2) * (n + 2) : nat.mul_le_mul_left (n+2) (show 2 \u2264 n+2, from dec_trivial)\n...   < 3                 : H\nend \n\nlemma int_squared_lt_three {z : \u2124} : z ^ 2 < 3 \u2192 z = -1 \u2228 z = 0 \u2228 z = 1 :=\nbegin\n  cases z with n n,\n  { rw pow_two,\n    show \u2191n * \u2191n < \u21913 \u2192 _,\n    rw [\u2190int.coe_nat_mul,int.coe_nat_lt],\n    intro Hn,\n    cases n,\n      right,left,refl,\n    cases n,\n      right,right,refl,\n    cases square_lt_three_of_ge_two n Hn,\n  },\n  { rw [pow_two,\u2190int.nat_abs_mul_self],\n    show \u2191((n+1)*(n+1)) < \u21913 \u2192 _,\n    rw int.coe_nat_lt,\n    intro Hn,\n    cases n,\n      left,trivial,\n    cases square_lt_three_of_ge_two n Hn,\n  }\nend\n\ntheorem B_is_minus_one_zero_one (x : \u211d) : x \u2208 { x : \u211d | x^2 < 3 \u2227 \u2203 y : \u2124, x = \u2191y} \u2194 x = -1 \u2228 x = 0 \u2228 x = 1 :=\nbegin\n  split,\n  { intro H,\n    cases H.right with y Hy,\n    have Hleft := H.left,\n    rw [Hy,pow_two,\u2190int.cast_mul] at Hleft,\n    have Htemp : (3 : \u211d) = (3 : \u2124),\n      refl,\n    rw Htemp at Hleft,\n    rw [int.cast_lt,\u2190pow_two] at Hleft,\n    rw Hy,\n    cases int_squared_lt_three Hleft with h h,\n      left,rw h,refl,\n    cases h with h h,\n      right,left,rw h,refl,\n      right,right,rw h,refl\n  },\n  { intro H,\n    cases H,\n      rw H,\n      split,norm_num,existsi (-1 : \u2124),refl,\n    cases H,\n      rw H,\n      split,norm_num,existsi (0 : \u2124),refl,\n    rw H,\n    split,norm_num,existsi (1 : \u2124),refl\n  }\nend\n\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/src/xenalib/M1F/Q0107.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7363493516679269}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si c es un n\u00famero real no nulo, entonces la\n-- funci\u00f3n \n--    f(x) = c * x\n-- es suprayectiva. \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nopen function\n\nexample \n  {c : \u211d} \n  (h : c \u2260 0) \n  : surjective (\u03bb x, c * x) :=\nbegin\n  intro x,\n  use (x / c),\n  change c * (x / c) = x,\n  rw mul_comm,\n  apply div_mul_cancel,\n  exact h,\nend\n\n-- Su prueba es\n-- \n-- c : \u211d,\n-- h : c \u2260 0\n-- \u22a2 surjective (\u03bb (x : \u211d), c * x)\n--    >> intro x,\n-- x : \u211d\n-- \u22a2 \u2203 (a : \u211d), (\u03bb (x : \u211d), c * x) a = x\n--    >> use (x / c),\n-- \u22a2 (\u03bb (x : \u211d), c * x) (x / c) = x\n--    >> change c * (x / c) = x,\n-- \u22a2 c * (x / c) = x\n--    >> rw mul_comm,\n-- \u22a2 x / c * c = x\n--    >> apply div_mul_cancel,\n-- \u22a2 c \u2260 0\n--    >> exact h,\n-- no goals\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Producto_por_no_nula_es_suprayectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.7931059438487662, "lm_q1q2_score": 0.7363265349000001}}
{"text": "import .love01_definitions_and_statements_demo\n\n\n/-! # LoVe Exercise 1: Definitions and Statements\n\nReplace the placeholders (e.g., `:= sorry`) with your solutions. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Truncated Subtraction\n\n1.1. Define the function `sub` that implements truncated subtraction on natural\nnumbers by recursion. \"Truncated\" means that results that mathematically would\nbe negative are represented by 0. For example:\n\n    `sub 7 2 = 5`\n    `sub 2 7 = 0` -/\n\ndef sub : \u2115 \u2192 \u2115 \u2192 \u2115\n| m            0            := m\n| 0            _            := 0\n| (nat.succ m) (nat.succ n) := sub m n\n\n/-! 1.2. Check that your function works as expected. -/\n\n#eval sub 0 0   -- expected: 0\n#eval sub 0 1   -- expected: 0\n#eval sub 0 7   -- expected: 0\n#eval sub 1 0   -- expected: 1\n#eval sub 1 1   -- expected: 0\n#eval sub 3 0   -- expected: 3\n#eval sub 2 7   -- expected: 0\n#eval sub 3 1   -- expected: 2\n#eval sub 3 3   -- expected: 0\n#eval sub 3 7   -- expected: 0\n#eval sub 7 2   -- expected: 5\n\n\n/-! ## Question 2: Arithmetic Expressions\n\nConsider the type `aexp` from the lecture and the function `eval` that\ncomputes the value of an expression. You will find the definitions in the file\n`love01_definitions_and_statements_demo.lean`. One way to find them quickly is\nto\n\n1. hold the Control (on Linux and Windows) or Command (on macOS) key pressed;\n2. move the cursor to the identifier `aexp` or `eval`;\n3. click the identifier. -/\n\n#check aexp\n#check eval\n\n/-! 2.1. Test that `eval` behaves as expected. Make sure to exercise each\nconstructor at least once. You can use the following environment in your tests.\nWhat happens if you divide by zero?\n\nMake sure to use `#eval`. For technical reasons, `#reduce` does not work well\nhere. Note that `#eval` (Lean's evaluation command) and `eval` (our evaluation\nfunction on `aexp`) are unrelated. -/\n\ndef some_env : string \u2192 \u2124\n| \"x\" := 3\n| \"y\" := 17\n| _   := 201\n\n#eval eval some_env (aexp.var \"x\")   -- expected: 3\n#eval eval some_env (aexp.num 12)                              -- expected: 12\n#eval eval some_env (aexp.add (aexp.var \"x\") (aexp.var \"y\"))   -- expected: 20\n#eval eval some_env (aexp.sub (aexp.num 5) (aexp.var \"y\"))     -- expected: -12\n#eval eval some_env (aexp.mul (aexp.num 11) (aexp.var \"z\"))    -- expected: 2211\n#eval eval some_env (aexp.div (aexp.num 2) (aexp.num 0))       -- expected: 0\n\n/-! 2.2. The following function simplifies arithmetic expressions involving\naddition. It simplifies `0 + e` and `e + 0` to `e`. Complete the definition so\nthat it also simplifies expressions involving the other three binary\noperators. -/\n\ndef simplify : aexp \u2192 aexp\n| (aexp.add (aexp.num 0) e\u2082) := simplify e\u2082\n| (aexp.add e\u2081 (aexp.num 0)) := simplify e\u2081\n| (aexp.sub e\u2081 (aexp.num 0)) := simplify e\u2081\n| (aexp.mul (aexp.num 0) e\u2082) := aexp.num 0\n| (aexp.mul e\u2081 (aexp.num 0)) := aexp.num 0\n| (aexp.mul (aexp.num 1) e\u2082) := simplify e\u2082\n| (aexp.mul e\u2081 (aexp.num 1)) := simplify e\u2081\n| (aexp.div (aexp.num 0) e\u2082) := aexp.num 0\n| (aexp.div e\u2081 (aexp.num 0)) := aexp.num 0\n| (aexp.div e\u2081 (aexp.num 1)) := simplify e\u2081\n-- catch-all cases below\n| (aexp.num i)               := aexp.num i\n| (aexp.var x)               := aexp.var x\n| (aexp.add e\u2081 e\u2082)           := aexp.add (simplify e\u2081) (simplify e\u2082)\n| (aexp.sub e\u2081 e\u2082)           := aexp.sub (simplify e\u2081) (simplify e\u2082)\n| (aexp.mul e\u2081 e\u2082)           := aexp.mul (simplify e\u2081) (simplify e\u2082)\n| (aexp.div e\u2081 e\u2082)           := aexp.div (simplify e\u2081) (simplify e\u2082)\n\n/-! 2.3. Is the `simplify` function correct? In fact, what would it mean for it\nto be correct or not? Intuitively, for `simplify` to be correct, it must\nreturn an arithmetic expression that yields the same numeric value when\nevaluated as the original expression.\n\nGiven an environment `env` and an expression `e`, state (without proving it)\nthe property that the value of `e` after simplification is the same as the\nvalue of `e` before. -/\n\nlemma simplify_correct (env : string \u2192 \u2124) (e : aexp) :\n  eval env (simplify e) = eval env e :=\nsorry\n\n\n/-! ## Question 3: \u03bb-Terms\n\n3.1. Complete the following definitions, by replacing the `sorry` markers by\nterms of the expected type.\n\nHint: A procedure for doing so systematically is described in Section 1.1.4 of\nthe Hitchhiker's Guide. As explained there, you can use `_` as a placeholder\nwhile constructing a term. By hovering over `_`, you will see the current\nlogical context. -/\n\ndef I : \u03b1 \u2192 \u03b1 :=\n\u03bba, a\n\ndef K : \u03b1 \u2192 \u03b2 \u2192 \u03b1 :=\n\u03bba b, a\n\ndef C : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 \u03b2 \u2192 \u03b1 \u2192 \u03b3 :=\n\u03bbg b a, g a b\n\ndef proj_1st : \u03b1 \u2192 \u03b1 \u2192 \u03b1 :=\n\u03bbx y, x\n\n/-! Please give a different answer than for `proj_1st`. -/\n\ndef proj_2nd : \u03b1 \u2192 \u03b1 \u2192 \u03b1 :=\n\u03bbx y, y\n\ndef some_nonsense : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 \u03b1 \u2192 (\u03b1 \u2192 \u03b3) \u2192 \u03b2 \u2192 \u03b3 :=\n\u03bbg a f b, g a b\n\n/-! 3.2. Show the typing derivation for your definition of `C` above, on paper\nor using ASCII or Unicode art. You might find the characters `\u2013` (to draw\nhorizontal bars) and `\u22a2` useful. -/\n\n/-! Let `D` := `g : \u03b1 \u2192 \u03b2 \u2192 \u03b3, b : \u03b2, a : \u03b1`. We have\n\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Var    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Var\n    D \u22a2 g : \u03b1 \u2192 \u03b2 \u2192 \u03b3         D \u22a2 a : \u03b1\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 App    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 Var\n    D \u22a2 g a : \u03b2 \u2192 \u03b3                             D \u22a2 b : \u03b2\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013 App\n    D \u22a2 g a b : \u03b3\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013--- Lam\n    g : \u03b1 \u2192 \u03b2 \u2192 \u03b3, b : \u03b2 \u22a2 (\u03bba : \u03b1, g a b) : \u03b1 \u2192 \u03b3\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013------- Lam\n    g : \u03b1 \u2192 \u03b2 \u2192 \u03b3 \u22a2 (\u03bb(b : \u03b2) (a : \u03b1), g a b) : \u03b2 \u2192 \u03b1 \u2192 \u03b3\n    \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013---------------------- Lam\n    \u22a2 (\u03bb(g : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (b : \u03b2) (a : \u03b1), g a b) : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 \u03b2 \u2192 \u03b1 \u2192 \u03b3 -/\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2021", "sha": "23b469c79afd482fa66da82e4726a317e3a7b5d5", "save_path": "github-repos/lean/blanchette-logical_verification_2021", "path": "github-repos/lean/blanchette-logical_verification_2021/logical_verification_2021-23b469c79afd482fa66da82e4726a317e3a7b5d5/lean/love01_definitions_and_statements_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8080672204860317, "lm_q1q2_score": 0.7362944556325209}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.game.basic\nimport set_theory.ordinal.natural_ops\n\n/-!\n# Ordinals as games\n\nWe define the canonical map `ordinal \u2192 pgame`, where every ordinal is mapped to the game whose left\nset consists of all previous ordinals.\n\nThe map to surreals is defined in `ordinal.to_surreal`.\n\n# Main declarations\n\n- `ordinal.to_pgame`: The canonical map between ordinals and pre-games.\n- `ordinal.to_pgame_embedding`: The order embedding version of the previous map.\n-/\n\nuniverse u\n\nopen pgame\n\nopen_locale natural_ops pgame\n\nnamespace ordinal\n\n/-- Converts an ordinal into the corresponding pre-game. -/\nnoncomputable! def to_pgame : ordinal.{u} \u2192 pgame.{u}\n| o := \u27e8o.out.\u03b1, pempty, \u03bb x, let hwf := ordinal.typein_lt_self x in\n        (typein (<) x).to_pgame, pempty.elim\u27e9\nusing_well_founded { dec_tac := tactic.assumption }\n\ntheorem to_pgame_def (o : ordinal) :\n  o.to_pgame = \u27e8o.out.\u03b1, pempty, \u03bb x, (typein (<) x).to_pgame, pempty.elim\u27e9 :=\nby rw to_pgame\n\n@[simp] theorem to_pgame_left_moves (o : ordinal) : o.to_pgame.left_moves = o.out.\u03b1 :=\nby rw [to_pgame, left_moves]\n\n@[simp] theorem to_pgame_right_moves (o : ordinal) : o.to_pgame.right_moves = pempty :=\nby rw [to_pgame, right_moves]\n\ninstance is_empty_zero_to_pgame_left_moves : is_empty (to_pgame 0).left_moves :=\nby { rw to_pgame_left_moves, apply_instance }\n\ninstance is_empty_to_pgame_right_moves (o : ordinal) : is_empty o.to_pgame.right_moves :=\nby { rw to_pgame_right_moves, apply_instance }\n\n/-- Converts an ordinal less than `o` into a move for the `pgame` corresponding to `o`, and vice\nversa. -/\nnoncomputable def to_left_moves_to_pgame {o : ordinal} : set.Iio o \u2243 o.to_pgame.left_moves :=\n(enum_iso_out o).to_equiv.trans (equiv.cast (to_pgame_left_moves o).symm)\n\n@[simp] theorem to_left_moves_to_pgame_symm_lt {o : ordinal} (i : o.to_pgame.left_moves) :\n  \u2191(to_left_moves_to_pgame.symm i) < o :=\n(to_left_moves_to_pgame.symm i).prop\n\ntheorem to_pgame_move_left_heq {o : ordinal} :\n  o.to_pgame.move_left == \u03bb x : o.out.\u03b1, (typein (<) x).to_pgame :=\nby { rw to_pgame, refl }\n\n@[simp] theorem to_pgame_move_left' {o : ordinal} (i) :\n  o.to_pgame.move_left i = (to_left_moves_to_pgame.symm i).val.to_pgame :=\n(congr_heq to_pgame_move_left_heq.symm (cast_heq _ i)).symm\n\ntheorem to_pgame_move_left {o : ordinal} (i) :\n  o.to_pgame.move_left (to_left_moves_to_pgame i) = i.val.to_pgame :=\nby simp\n\n/-- `0.to_pgame` has the same moves as `0`. -/\nnoncomputable def zero_to_pgame_relabelling : to_pgame 0 \u2261r 0 :=\nrelabelling.is_empty _\n\nnoncomputable instance unique_one_to_pgame_left_moves : unique (to_pgame 1).left_moves :=\n(equiv.cast $ to_pgame_left_moves 1).unique\n\n@[simp] theorem one_to_pgame_left_moves_default_eq :\n  (default : (to_pgame 1).left_moves) = @to_left_moves_to_pgame 1 \u27e80, zero_lt_one\u27e9 :=\nrfl\n\n@[simp] theorem to_left_moves_one_to_pgame_symm (i) :\n  (@to_left_moves_to_pgame 1).symm i = \u27e80, zero_lt_one\u27e9 :=\nby simp\n\ntheorem one_to_pgame_move_left (x) : (to_pgame 1).move_left x = to_pgame 0 :=\nby simp\n\n/-- `1.to_pgame` has the same moves as `1`. -/\nnoncomputable def one_to_pgame_relabelling : to_pgame 1 \u2261r 1 :=\n\u27e8equiv.equiv_of_unique _ _, equiv.equiv_of_is_empty _ _,\n  \u03bb i, by simpa using zero_to_pgame_relabelling, is_empty_elim\u27e9\n\ntheorem to_pgame_lf {a b : ordinal} (h : a < b) : a.to_pgame \u29cf b.to_pgame :=\nby { convert move_left_lf (to_left_moves_to_pgame \u27e8a, h\u27e9), rw to_pgame_move_left }\n\ntheorem to_pgame_le {a b : ordinal} (h : a \u2264 b) : a.to_pgame \u2264 b.to_pgame :=\nbegin\n  refine le_iff_forall_lf.2 \u27e8\u03bb i, _, is_empty_elim\u27e9,\n  rw to_pgame_move_left',\n  exact to_pgame_lf ((to_left_moves_to_pgame_symm_lt i).trans_le h)\nend\n\ntheorem to_pgame_lt {a b : ordinal} (h : a < b) : a.to_pgame < b.to_pgame :=\n\u27e8to_pgame_le h.le, to_pgame_lf h\u27e9\n\ntheorem to_pgame_nonneg (a : ordinal) : 0 \u2264 a.to_pgame :=\nzero_to_pgame_relabelling.ge.trans $ to_pgame_le $ ordinal.zero_le a\n\n@[simp] theorem to_pgame_lf_iff {a b : ordinal} : a.to_pgame \u29cf b.to_pgame \u2194 a < b :=\n\u27e8by { contrapose, rw [not_lt, not_lf], exact to_pgame_le }, to_pgame_lf\u27e9\n\n@[simp] theorem to_pgame_le_iff {a b : ordinal} : a.to_pgame \u2264 b.to_pgame \u2194 a \u2264 b :=\n\u27e8by { contrapose, rw [not_le, pgame.not_le], exact to_pgame_lf }, to_pgame_le\u27e9\n\n@[simp] theorem to_pgame_lt_iff {a b : ordinal} : a.to_pgame < b.to_pgame \u2194 a < b :=\n\u27e8by { contrapose, rw not_lt, exact \u03bb h, not_lt_of_le (to_pgame_le h) }, to_pgame_lt\u27e9\n\n@[simp] theorem to_pgame_equiv_iff {a b : ordinal} : a.to_pgame \u2248 b.to_pgame \u2194 a = b :=\nby rw [pgame.equiv, le_antisymm_iff, to_pgame_le_iff, to_pgame_le_iff]\n\ntheorem to_pgame_injective : function.injective ordinal.to_pgame :=\n\u03bb a b h, to_pgame_equiv_iff.1 $ equiv_of_eq h\n\n@[simp] theorem to_pgame_eq_iff {a b : ordinal} : a.to_pgame = b.to_pgame \u2194 a = b :=\nto_pgame_injective.eq_iff\n\n/-- The order embedding version of `to_pgame`. -/\n@[simps] noncomputable def to_pgame_embedding : ordinal.{u} \u21aao pgame.{u} :=\n{ to_fun := ordinal.to_pgame,\n  inj' := to_pgame_injective,\n  map_rel_iff' := @to_pgame_le_iff }\n\n/-- The sum of ordinals as games corresponds to natural addition of ordinals. -/\ntheorem to_pgame_add : \u2200 a b : ordinal.{u}, a.to_pgame + b.to_pgame \u2248 (a \u266f b).to_pgame\n| a b := begin\n  refine \u27e8le_of_forall_lf (\u03bb i, _) is_empty_elim, le_of_forall_lf (\u03bb i, _) is_empty_elim\u27e9,\n  { apply left_moves_add_cases i;\n    intro i;\n    let wf := to_left_moves_to_pgame_symm_lt i;\n    try { rw add_move_left_inl }; try { rw add_move_left_inr };\n    rw [to_pgame_move_left', lf_congr_left (to_pgame_add _ _), to_pgame_lf_iff],\n    { exact nadd_lt_nadd_right wf _ },\n    { exact nadd_lt_nadd_left wf _ } },\n  { rw to_pgame_move_left',\n    rcases lt_nadd_iff.1 (to_left_moves_to_pgame_symm_lt i) with \u27e8c, hc, hc'\u27e9 | \u27e8c, hc, hc'\u27e9;\n    rw [\u2190to_pgame_le_iff, \u2190le_congr_right (to_pgame_add _ _)] at hc';\n    apply lf_of_le_of_lf hc',\n    { apply add_lf_add_right,\n      rwa to_pgame_lf_iff },\n    { apply add_lf_add_left,\n      rwa to_pgame_lf_iff } }\nend\nusing_well_founded { dec_tac := `[solve_by_elim [psigma.lex.left, psigma.lex.right]] }\n\n@[simp] theorem to_pgame_add_mk (a b : ordinal) :\n  \u27e6a.to_pgame\u27e7 + \u27e6b.to_pgame\u27e7 = \u27e6(a \u266f b).to_pgame\u27e7 :=\nquot.sound (to_pgame_add a b)\n\nend ordinal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/set_theory/game/ordinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.736294445730667}}
{"text": "/-\nCopyright (c) 2019 Gabriel Ebner. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gabriel Ebner, S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.calculus.fderiv\nimport data.polynomial.derivative\nimport linear_algebra.affine_space.slope\n\n/-!\n\n# One-dimensional derivatives\n\nThis file defines the derivative of a function `f : \ud835\udd5c \u2192 F` where `\ud835\udd5c` is a\nnormed field and `F` is a normed space over this field. The derivative of\nsuch a function `f` at a point `x` is given by an element `f' : F`.\n\nThe theory is developed analogously to the [Fr\u00e9chet\nderivatives](./fderiv.html). We first introduce predicates defined in terms\nof the corresponding predicates for Fr\u00e9chet derivatives:\n\n - `has_deriv_at_filter f f' x L` states that the function `f` has the\n    derivative `f'` at the point `x` as `x` goes along the filter `L`.\n\n - `has_deriv_within_at f f' s x` states that the function `f` has the\n    derivative `f'` at the point `x` within the subset `s`.\n\n - `has_deriv_at f f' x` states that the function `f` has the derivative `f'`\n    at the point `x`.\n\n - `has_strict_deriv_at f f' x` states that the function `f` has the derivative `f'`\n    at the point `x` in the sense of strict differentiability, i.e.,\n   `f y - f z = (y - z) \u2022 f' + o (y - z)` as `y, z \u2192 x`.\n\nFor the last two notions we also define a functional version:\n\n  - `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the\n    derivative does not exist, then `deriv_within f s x` equals zero.\n\n  - `deriv f x` is a derivative of `f` at `x`. If the derivative does not\n    exist, then `deriv f x` equals zero.\n\nThe theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the\none-dimensional derivatives coincide with the general Fr\u00e9chet derivatives.\n\nWe also show the existence and compute the derivatives of:\n  - constants\n  - the identity function\n  - linear maps\n  - addition\n  - sum of finitely many functions\n  - negation\n  - subtraction\n  - multiplication\n  - inverse `x \u2192 x\u207b\u00b9`\n  - multiplication of two functions in `\ud835\udd5c \u2192 \ud835\udd5c`\n  - multiplication of a function in `\ud835\udd5c \u2192 \ud835\udd5c` and of a function in `\ud835\udd5c \u2192 E`\n  - composition of a function in `\ud835\udd5c \u2192 F` with a function in `\ud835\udd5c \u2192 \ud835\udd5c`\n  - composition of a function in `F \u2192 E` with a function in `\ud835\udd5c \u2192 F`\n  - inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)\n  - division\n  - polynomials\n\nFor most binary operations we also define `const_op` and `op_const` theorems for the cases when\nthe first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,\nand they more frequently lead to the desired result.\n\nWe set up the simplifier so that it can compute the derivative of simple functions. For instance,\n```lean\nexample (x : \u211d) : deriv (\u03bb x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=\nby { simp, ring }\n```\n\n## Implementation notes\n\nMost of the theorems are direct restatements of the corresponding theorems\nfor Fr\u00e9chet derivatives.\n\nThe strategy to construct simp lemmas that give the simplifier the possibility to compute\nderivatives is the same as the one for differentiability statements, as explained in `fderiv.lean`.\nSee the explanations there.\n-/\n\nuniverses u v w\nnoncomputable theory\nopen_locale classical topology big_operators filter ennreal polynomial\nopen filter asymptotics set\nopen continuous_linear_map (smul_right smul_right_one_eq_iff)\n\n\nvariables {\ud835\udd5c : Type u} [nontrivially_normed_field \ud835\udd5c]\n\nsection\nvariables {F : Type v} [normed_add_comm_group F] [normed_space \ud835\udd5c F]\nvariables {E : Type w} [normed_add_comm_group E] [normed_space \ud835\udd5c E]\n\n/--\n`f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges along the filter `L`.\n-/\ndef has_deriv_at_filter (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) (L : filter \ud835\udd5c) :=\nhas_fderiv_at_filter f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x L\n\n/--\n`f` has the derivative `f'` at the point `x` within the subset `s`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef has_deriv_within_at (f : \ud835\udd5c \u2192 F) (f' : F) (s : set \ud835\udd5c) (x : \ud835\udd5c) :=\nhas_deriv_at_filter f f' x (\ud835\udcdd[s] x)\n\n/--\n`f` has the derivative `f'` at the point `x`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges to `x`.\n-/\ndef has_deriv_at (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) :=\nhas_deriv_at_filter f f' x (\ud835\udcdd x)\n\n/-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability.\n\nThat is, `f y - f z = (y - z) \u2022 f' + o(y - z)` as `y, z \u2192 x`. -/\ndef has_strict_deriv_at (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) :=\nhas_strict_fderiv_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x\n\n/--\nDerivative of `f` at the point `x` within the set `s`, if it exists.  Zero otherwise.\n\nIf the derivative exists (i.e., `\u2203 f', has_deriv_within_at f f' s x`), then\n`f x' = f x + (x' - x) \u2022 deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef deriv_within (f : \ud835\udd5c \u2192 F) (s : set \ud835\udd5c) (x : \ud835\udd5c) :=\nfderiv_within \ud835\udd5c f s x 1\n\n/--\nDerivative of `f` at the point `x`, if it exists.  Zero otherwise.\n\nIf the derivative exists (i.e., `\u2203 f', has_deriv_at f f' x`), then\n`f x' = f x + (x' - x) \u2022 deriv f x + o(x' - x)` where `x'` converges to `x`.\n-/\ndef deriv (f : \ud835\udd5c \u2192 F) (x : \ud835\udd5c) :=\nfderiv \ud835\udd5c f x 1\n\nvariables {f f\u2080 f\u2081 g : \ud835\udd5c \u2192 F}\nvariables {f' f\u2080' f\u2081' g' : F}\nvariables {x : \ud835\udd5c}\nvariables {s t : set \ud835\udd5c}\nvariables {L L\u2081 L\u2082 : filter \ud835\udd5c}\n\n/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/\nlemma has_fderiv_at_filter_iff_has_deriv_at_filter {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at_filter f f' x L \u2194 has_deriv_at_filter f (f' 1) x L :=\nby simp [has_deriv_at_filter]\n\nlemma has_fderiv_at_filter.has_deriv_at_filter {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at_filter f f' x L \u2192 has_deriv_at_filter f (f' 1) x L :=\nhas_fderiv_at_filter_iff_has_deriv_at_filter.mp\n\n/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/\nlemma has_fderiv_within_at_iff_has_deriv_within_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_within_at f f' s x \u2194 has_deriv_within_at f (f' 1) s x :=\nhas_fderiv_at_filter_iff_has_deriv_at_filter\n\n/-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/\nlemma has_deriv_within_at_iff_has_fderiv_within_at {f' : F} :\n  has_deriv_within_at f f' s x \u2194\n  has_fderiv_within_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') s x :=\niff.rfl\n\nlemma has_fderiv_within_at.has_deriv_within_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_within_at f f' s x \u2192 has_deriv_within_at f (f' 1) s x :=\nhas_fderiv_within_at_iff_has_deriv_within_at.mp\n\nlemma has_deriv_within_at.has_fderiv_within_at {f' : F} :\n  has_deriv_within_at f f' s x \u2192 has_fderiv_within_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') s x :=\nhas_deriv_within_at_iff_has_fderiv_within_at.mp\n\n/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/\nlemma has_fderiv_at_iff_has_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at f f' x \u2194 has_deriv_at f (f' 1) x :=\nhas_fderiv_at_filter_iff_has_deriv_at_filter\n\nlemma has_fderiv_at.has_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at f f' x \u2192 has_deriv_at f (f' 1) x :=\nhas_fderiv_at_iff_has_deriv_at.mp\n\nlemma has_strict_fderiv_at_iff_has_strict_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_strict_fderiv_at f f' x \u2194 has_strict_deriv_at f (f' 1) x :=\nby simp [has_strict_deriv_at, has_strict_fderiv_at]\n\nprotected lemma has_strict_fderiv_at.has_strict_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_strict_fderiv_at f f' x \u2192 has_strict_deriv_at f (f' 1) x :=\nhas_strict_fderiv_at_iff_has_strict_deriv_at.mp\n\nlemma has_strict_deriv_at_iff_has_strict_fderiv_at :\n  has_strict_deriv_at f f' x \u2194 has_strict_fderiv_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x :=\niff.rfl\n\nalias has_strict_deriv_at_iff_has_strict_fderiv_at \u2194 has_strict_deriv_at.has_strict_fderiv_at _\n\n/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/\nlemma has_deriv_at_iff_has_fderiv_at {f' : F} :\n  has_deriv_at f f' x \u2194\n  has_fderiv_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x :=\niff.rfl\n\nalias has_deriv_at_iff_has_fderiv_at \u2194 has_deriv_at.has_fderiv_at _\n\nlemma deriv_within_zero_of_not_differentiable_within_at\n  (h : \u00ac differentiable_within_at \ud835\udd5c f s x) : deriv_within f s x = 0 :=\nby { unfold deriv_within, rw fderiv_within_zero_of_not_differentiable_within_at, simp, assumption }\n\nlemma differentiable_within_at_of_deriv_within_ne_zero (h : deriv_within f s x \u2260 0) :\n  differentiable_within_at \ud835\udd5c f s x :=\nnot_imp_comm.1 deriv_within_zero_of_not_differentiable_within_at h\n\nlemma deriv_zero_of_not_differentiable_at (h : \u00ac differentiable_at \ud835\udd5c f x) : deriv f x = 0 :=\nby { unfold deriv, rw fderiv_zero_of_not_differentiable_at, simp, assumption }\n\nlemma differentiable_at_of_deriv_ne_zero (h : deriv f x \u2260 0) : differentiable_at \ud835\udd5c f x :=\nnot_imp_comm.1 deriv_zero_of_not_differentiable_at h\n\ntheorem unique_diff_within_at.eq_deriv (s : set \ud835\udd5c) (H : unique_diff_within_at \ud835\udd5c s x)\n  (h : has_deriv_within_at f f' s x) (h\u2081 : has_deriv_within_at f f\u2081' s x) : f' = f\u2081' :=\nsmul_right_one_eq_iff.mp $ unique_diff_within_at.eq H h h\u2081\n\ntheorem has_deriv_at_filter_iff_is_o :\n  has_deriv_at_filter f f' x L \u2194 (\u03bb x' : \ud835\udd5c, f x' - f x - (x' - x) \u2022 f') =o[L] (\u03bb x', x' - x) :=\niff.rfl\n\ntheorem has_deriv_at_filter_iff_tendsto :\n  has_deriv_at_filter f f' x L \u2194\n  tendsto (\u03bb x' : \ud835\udd5c, \u2016x' - x\u2016\u207b\u00b9 * \u2016f x' - f x - (x' - x) \u2022 f'\u2016) L (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_deriv_within_at_iff_is_o :\n  has_deriv_within_at f f' s x\n    \u2194 (\u03bb x' : \ud835\udd5c, f x' - f x - (x' - x) \u2022 f') =o[\ud835\udcdd[s] x] (\u03bb x', x' - x) :=\niff.rfl\n\ntheorem has_deriv_within_at_iff_tendsto : has_deriv_within_at f f' s x \u2194\n  tendsto (\u03bb x', \u2016x' - x\u2016\u207b\u00b9 * \u2016f x' - f x - (x' - x) \u2022 f'\u2016) (\ud835\udcdd[s] x) (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_deriv_at_iff_is_o :\n  has_deriv_at f f' x \u2194 (\u03bb x' : \ud835\udd5c, f x' - f x - (x' - x) \u2022 f') =o[\ud835\udcdd x] (\u03bb x', x' - x) :=\niff.rfl\n\ntheorem has_deriv_at_iff_tendsto : has_deriv_at f f' x \u2194\n  tendsto (\u03bb x', \u2016x' - x\u2016\u207b\u00b9 * \u2016f x' - f x - (x' - x) \u2022 f'\u2016) (\ud835\udcdd x) (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_strict_deriv_at.has_deriv_at (h : has_strict_deriv_at f f' x) :\n  has_deriv_at f f' x :=\nh.has_fderiv_at\n\n/-- If the domain has dimension one, then Fr\u00e9chet derivative is equivalent to the classical\ndefinition with a limit. In this version we have to take the limit along the subset `-{x}`,\nbecause for `y=x` the slope equals zero due to the convention `0\u207b\u00b9=0`. -/\nlemma has_deriv_at_filter_iff_tendsto_slope {x : \ud835\udd5c} {L : filter \ud835\udd5c} :\n  has_deriv_at_filter f f' x L \u2194 tendsto (slope f x) (L \u2293 \ud835\udcdf {x}\u1d9c) (\ud835\udcdd f') :=\nbegin\n  conv_lhs { simp only [has_deriv_at_filter_iff_tendsto, (norm_inv _).symm,\n    (norm_smul _ _).symm, tendsto_zero_iff_norm_tendsto_zero.symm] },\n  conv_rhs { rw [\u2190 nhds_translation_sub f', tendsto_comap_iff] },\n  refine (tendsto_inf_principal_nhds_iff_of_forall_eq $ by simp).symm.trans (tendsto_congr' _),\n  refine (eventually_principal.2 $ \u03bb z hz, _).filter_mono inf_le_right,\n  simp only [(\u2218)],\n  rw [smul_sub, \u2190 mul_smul, inv_mul_cancel (sub_ne_zero.2 hz), one_smul, slope_def_module]\nend\n\nlemma has_deriv_within_at_iff_tendsto_slope :\n  has_deriv_within_at f f' s x \u2194 tendsto (slope f x) (\ud835\udcdd[s \\ {x}] x) (\ud835\udcdd f') :=\nbegin\n  simp only [has_deriv_within_at, nhds_within, diff_eq, inf_assoc.symm, inf_principal.symm],\n  exact has_deriv_at_filter_iff_tendsto_slope\nend\n\nlemma has_deriv_within_at_iff_tendsto_slope' (hs : x \u2209 s) :\n  has_deriv_within_at f f' s x \u2194 tendsto (slope f x) (\ud835\udcdd[s] x) (\ud835\udcdd f') :=\nbegin\n  convert \u2190 has_deriv_within_at_iff_tendsto_slope,\n  exact diff_singleton_eq_self hs\nend\n\nlemma has_deriv_at_iff_tendsto_slope :\n  has_deriv_at f f' x \u2194 tendsto (slope f x) (\ud835\udcdd[\u2260] x) (\ud835\udcdd f') :=\nhas_deriv_at_filter_iff_tendsto_slope\n\ntheorem has_deriv_within_at_congr_set {s t u : set \ud835\udd5c}\n  (hu : u \u2208 \ud835\udcdd x) (h : s \u2229 u = t \u2229 u) :\n    has_deriv_within_at f f' s x \u2194 has_deriv_within_at f f' t x :=\nby simp_rw [has_deriv_within_at, nhds_within_eq_nhds_within' hu h]\n\nalias has_deriv_within_at_congr_set \u2194 has_deriv_within_at.congr_set _\n\n@[simp] lemma has_deriv_within_at_diff_singleton :\n  has_deriv_within_at f f' (s \\ {x}) x \u2194 has_deriv_within_at f f' s x :=\nby simp only [has_deriv_within_at_iff_tendsto_slope, sdiff_idem]\n\n@[simp] lemma has_deriv_within_at_Ioi_iff_Ici [partial_order \ud835\udd5c] :\n  has_deriv_within_at f f' (Ioi x) x \u2194 has_deriv_within_at f f' (Ici x) x :=\nby rw [\u2190 Ici_diff_left, has_deriv_within_at_diff_singleton]\n\nalias has_deriv_within_at_Ioi_iff_Ici \u2194\n  has_deriv_within_at.Ici_of_Ioi has_deriv_within_at.Ioi_of_Ici\n\n@[simp] lemma has_deriv_within_at_Iio_iff_Iic [partial_order \ud835\udd5c] :\n  has_deriv_within_at f f' (Iio x) x \u2194 has_deriv_within_at f f' (Iic x) x :=\nby rw [\u2190 Iic_diff_right, has_deriv_within_at_diff_singleton]\n\nalias has_deriv_within_at_Iio_iff_Iic \u2194\n  has_deriv_within_at.Iic_of_Iio has_deriv_within_at.Iio_of_Iic\n\ntheorem has_deriv_within_at.Ioi_iff_Ioo [linear_order \ud835\udd5c] [order_closed_topology \ud835\udd5c] {x y : \ud835\udd5c}\n  (h : x < y) :\n  has_deriv_within_at f f' (Ioo x y) x \u2194 has_deriv_within_at f f' (Ioi x) x :=\nhas_deriv_within_at_congr_set (is_open_Iio.mem_nhds h) $\n  by { rw [Ioi_inter_Iio, inter_eq_left_iff_subset], exact Ioo_subset_Iio_self }\n\nalias has_deriv_within_at.Ioi_iff_Ioo \u2194\n  has_deriv_within_at.Ioi_of_Ioo has_deriv_within_at.Ioo_of_Ioi\n\ntheorem has_deriv_at_iff_is_o_nhds_zero : has_deriv_at f f' x \u2194\n  (\u03bbh, f (x + h) - f x - h \u2022 f') =o[\ud835\udcdd 0] (\u03bbh, h) :=\nhas_fderiv_at_iff_is_o_nhds_zero\n\ntheorem has_deriv_at_filter.mono (h : has_deriv_at_filter f f' x L\u2082) (hst : L\u2081 \u2264 L\u2082) :\n  has_deriv_at_filter f f' x L\u2081 :=\nhas_fderiv_at_filter.mono h hst\n\ntheorem has_deriv_within_at.mono (h : has_deriv_within_at f f' t x) (hst : s \u2286 t) :\n  has_deriv_within_at f f' s x :=\nhas_fderiv_within_at.mono h hst\n\ntheorem has_deriv_at.has_deriv_at_filter (h : has_deriv_at f f' x) (hL : L \u2264 \ud835\udcdd x) :\n  has_deriv_at_filter f f' x L :=\nhas_fderiv_at.has_fderiv_at_filter h hL\n\ntheorem has_deriv_at.has_deriv_within_at\n  (h : has_deriv_at f f' x) : has_deriv_within_at f f' s x :=\nhas_fderiv_at.has_fderiv_within_at h\n\nlemma has_deriv_within_at.differentiable_within_at (h : has_deriv_within_at f f' s x) :\n  differentiable_within_at \ud835\udd5c f s x :=\nhas_fderiv_within_at.differentiable_within_at h\n\nlemma has_deriv_at.differentiable_at (h : has_deriv_at f f' x) : differentiable_at \ud835\udd5c f x :=\nhas_fderiv_at.differentiable_at h\n\n@[simp] lemma has_deriv_within_at_univ : has_deriv_within_at f f' univ x \u2194 has_deriv_at f f' x :=\nhas_fderiv_within_at_univ\n\ntheorem has_deriv_at.unique\n  (h\u2080 : has_deriv_at f f\u2080' x) (h\u2081 : has_deriv_at f f\u2081' x) : f\u2080' = f\u2081' :=\nsmul_right_one_eq_iff.mp $ h\u2080.has_fderiv_at.unique h\u2081\n\nlemma has_deriv_within_at_inter' (h : t \u2208 \ud835\udcdd[s] x) :\n  has_deriv_within_at f f' (s \u2229 t) x \u2194 has_deriv_within_at f f' s x :=\nhas_fderiv_within_at_inter' h\n\nlemma has_deriv_within_at_inter (h : t \u2208 \ud835\udcdd x) :\n  has_deriv_within_at f f' (s \u2229 t) x \u2194 has_deriv_within_at f f' s x :=\nhas_fderiv_within_at_inter h\n\nlemma has_deriv_within_at.union (hs : has_deriv_within_at f f' s x)\n  (ht : has_deriv_within_at f f' t x) :\n  has_deriv_within_at f f' (s \u222a t) x :=\nhs.has_fderiv_within_at.union ht.has_fderiv_within_at\n\nlemma has_deriv_within_at.nhds_within (h : has_deriv_within_at f f' s x)\n  (ht : s \u2208 \ud835\udcdd[t] x) : has_deriv_within_at f f' t x :=\n(has_deriv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))\n\nlemma has_deriv_within_at.has_deriv_at (h : has_deriv_within_at f f' s x) (hs : s \u2208 \ud835\udcdd x) :\n  has_deriv_at f f' x :=\nhas_fderiv_within_at.has_fderiv_at h hs\n\nlemma differentiable_within_at.has_deriv_within_at (h : differentiable_within_at \ud835\udd5c f s x) :\n  has_deriv_within_at f (deriv_within f s x) s x :=\nh.has_fderiv_within_at.has_deriv_within_at\n\nlemma differentiable_at.has_deriv_at (h : differentiable_at \ud835\udd5c f x) : has_deriv_at f (deriv f x) x :=\nh.has_fderiv_at.has_deriv_at\n\n@[simp] lemma has_deriv_at_deriv_iff : has_deriv_at f (deriv f x) x \u2194 differentiable_at \ud835\udd5c f x :=\n\u27e8\u03bb h, h.differentiable_at, \u03bb h, h.has_deriv_at\u27e9\n\n@[simp] lemma has_deriv_within_at_deriv_within_iff :\n  has_deriv_within_at f (deriv_within f s x) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\n\u27e8\u03bb h, h.differentiable_within_at, \u03bb h, h.has_deriv_within_at\u27e9\n\nlemma differentiable_on.has_deriv_at (h : differentiable_on \ud835\udd5c f s) (hs : s \u2208 \ud835\udcdd x) :\n  has_deriv_at f (deriv f x) x :=\n(h.has_fderiv_at hs).has_deriv_at\n\nlemma has_deriv_at.deriv (h : has_deriv_at f f' x) : deriv f x = f' :=\nh.differentiable_at.has_deriv_at.unique h\n\nlemma deriv_eq {f' : \ud835\udd5c \u2192 F} (h : \u2200 x, has_deriv_at f (f' x) x) : deriv f = f' :=\nfunext $ \u03bb x, (h x).deriv\n\nlemma has_deriv_within_at.deriv_within\n  (h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within f s x = f' :=\nhxs.eq_deriv _ h.differentiable_within_at.has_deriv_within_at h\n\nlemma fderiv_within_deriv_within : (fderiv_within \ud835\udd5c f s x : \ud835\udd5c \u2192 F) 1 = deriv_within f s x :=\nrfl\n\nlemma deriv_within_fderiv_within :\n  smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (deriv_within f s x) = fderiv_within \ud835\udd5c f s x :=\nby simp [deriv_within]\n\nlemma fderiv_deriv : (fderiv \ud835\udd5c f x : \ud835\udd5c \u2192 F) 1 = deriv f x :=\nrfl\n\nlemma deriv_fderiv :\n  smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (deriv f x) = fderiv \ud835\udd5c f x :=\nby simp [deriv]\n\nlemma differentiable_at.deriv_within (h : differentiable_at \ud835\udd5c f x)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within f s x = deriv f x :=\nby { unfold deriv_within deriv, rw h.fderiv_within hxs }\n\ntheorem has_deriv_within_at.deriv_eq_zero (hd : has_deriv_within_at f 0 s x)\n  (H : unique_diff_within_at \ud835\udd5c s x) : deriv f x = 0 :=\n(em' (differentiable_at \ud835\udd5c f x)).elim deriv_zero_of_not_differentiable_at $\n  \u03bb h, H.eq_deriv _ h.has_deriv_at.has_deriv_within_at hd\n\nlemma deriv_within_subset (st : s \u2286 t) (ht : unique_diff_within_at \ud835\udd5c s x)\n  (h : differentiable_within_at \ud835\udd5c f t x) :\n  deriv_within f s x = deriv_within f t x :=\n((differentiable_within_at.has_deriv_within_at h).mono st).deriv_within ht\n\n@[simp] lemma deriv_within_univ : deriv_within f univ = deriv f :=\nby { ext, unfold deriv_within deriv, rw fderiv_within_univ }\n\nlemma deriv_within_inter (ht : t \u2208 \ud835\udcdd x) (hs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within f (s \u2229 t) x = deriv_within f s x :=\nby { unfold deriv_within, rw fderiv_within_inter ht hs }\n\nlemma deriv_within_of_open (hs : is_open s) (hx : x \u2208 s) :\n  deriv_within f s x = deriv f x :=\nby { unfold deriv_within, rw fderiv_within_of_open hs hx, refl }\n\nlemma deriv_mem_iff {f : \ud835\udd5c \u2192 F} {s : set F} {x : \ud835\udd5c} :\n  deriv f x \u2208 s \u2194 (differentiable_at \ud835\udd5c f x \u2227 deriv f x \u2208 s) \u2228\n    (\u00acdifferentiable_at \ud835\udd5c f x \u2227 (0 : F) \u2208 s) :=\nby by_cases hx : differentiable_at \ud835\udd5c f x; simp [deriv_zero_of_not_differentiable_at, *]\n\nlemma deriv_within_mem_iff {f : \ud835\udd5c \u2192 F} {t : set \ud835\udd5c} {s : set F} {x : \ud835\udd5c} :\n  deriv_within f t x \u2208 s \u2194 (differentiable_within_at \ud835\udd5c f t x \u2227 deriv_within f t x \u2208 s) \u2228\n    (\u00acdifferentiable_within_at \ud835\udd5c f t x \u2227 (0 : F) \u2208 s) :=\nby by_cases hx : differentiable_within_at \ud835\udd5c f t x;\n  simp [deriv_within_zero_of_not_differentiable_within_at, *]\n\nlemma differentiable_within_at_Ioi_iff_Ici [partial_order \ud835\udd5c] :\n  differentiable_within_at \ud835\udd5c f (Ioi x) x \u2194 differentiable_within_at \ud835\udd5c f (Ici x) x :=\n\u27e8\u03bb h, h.has_deriv_within_at.Ici_of_Ioi.differentiable_within_at,\n\u03bb h, h.has_deriv_within_at.Ioi_of_Ici.differentiable_within_at\u27e9\n\nlemma deriv_within_Ioi_eq_Ici {E : Type*} [normed_add_comm_group E] [normed_space \u211d E] (f : \u211d \u2192 E)\n  (x : \u211d) :\n  deriv_within f (Ioi x) x = deriv_within f (Ici x) x :=\nbegin\n  by_cases H : differentiable_within_at \u211d f (Ioi x) x,\n  { have A := H.has_deriv_within_at.Ici_of_Ioi,\n    have B := (differentiable_within_at_Ioi_iff_Ici.1 H).has_deriv_within_at,\n    simpa using (unique_diff_on_Ici x).eq le_rfl A B },\n  { rw [deriv_within_zero_of_not_differentiable_within_at H,\n      deriv_within_zero_of_not_differentiable_within_at],\n    rwa differentiable_within_at_Ioi_iff_Ici at H }\nend\n\nsection congr\n/-! ### Congruence properties of derivatives -/\n\ntheorem filter.eventually_eq.has_deriv_at_filter_iff\n  (h\u2080 : f\u2080 =\u1da0[L] f\u2081) (hx : f\u2080 x = f\u2081 x) (h\u2081 : f\u2080' = f\u2081') :\n  has_deriv_at_filter f\u2080 f\u2080' x L \u2194 has_deriv_at_filter f\u2081 f\u2081' x L :=\nh\u2080.has_fderiv_at_filter_iff hx (by simp [h\u2081])\n\nlemma has_deriv_at_filter.congr_of_eventually_eq (h : has_deriv_at_filter f f' x L)\n  (hL : f\u2081 =\u1da0[L] f) (hx : f\u2081 x = f x) : has_deriv_at_filter f\u2081 f' x L :=\nby rwa hL.has_deriv_at_filter_iff hx rfl\n\nlemma has_deriv_within_at.congr_mono (h : has_deriv_within_at f f' s x) (ht : \u2200x \u2208 t, f\u2081 x = f x)\n  (hx : f\u2081 x = f x) (h\u2081 : t \u2286 s) : has_deriv_within_at f\u2081 f' t x :=\nhas_fderiv_within_at.congr_mono h ht hx h\u2081\n\nlemma has_deriv_within_at.congr (h : has_deriv_within_at f f' s x) (hs : \u2200x \u2208 s, f\u2081 x = f x)\n  (hx : f\u2081 x = f x) : has_deriv_within_at f\u2081 f' s x :=\nh.congr_mono hs hx (subset.refl _)\n\nlemma has_deriv_within_at.congr_of_mem (h : has_deriv_within_at f f' s x) (hs : \u2200x \u2208 s, f\u2081 x = f x)\n  (hx : x \u2208 s) : has_deriv_within_at f\u2081 f' s x :=\nh.congr hs (hs _ hx)\n\nlemma has_deriv_within_at.congr_of_eventually_eq (h : has_deriv_within_at f f' s x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : f\u2081 x = f x) : has_deriv_within_at f\u2081 f' s x :=\nhas_deriv_at_filter.congr_of_eventually_eq h h\u2081 hx\n\nlemma has_deriv_within_at.congr_of_eventually_eq_of_mem (h : has_deriv_within_at f f' s x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : x \u2208 s) : has_deriv_within_at f\u2081 f' s x :=\nh.congr_of_eventually_eq h\u2081 (h\u2081.eq_of_nhds_within hx)\n\nlemma has_deriv_at.congr_of_eventually_eq (h : has_deriv_at f f' x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd x] f) : has_deriv_at f\u2081 f' x :=\nhas_deriv_at_filter.congr_of_eventually_eq h h\u2081 (mem_of_mem_nhds h\u2081 : _)\n\nlemma filter.eventually_eq.deriv_within_eq (hs : unique_diff_within_at \ud835\udd5c s x)\n  (hL : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : f\u2081 x = f x) :\n  deriv_within f\u2081 s x = deriv_within f s x :=\nby { unfold deriv_within, rw hL.fderiv_within_eq hs hx }\n\nlemma deriv_within_congr (hs : unique_diff_within_at \ud835\udd5c s x)\n  (hL : \u2200y\u2208s, f\u2081 y = f y) (hx : f\u2081 x = f x) :\n  deriv_within f\u2081 s x = deriv_within f s x :=\nby { unfold deriv_within, rw fderiv_within_congr hs hL hx }\n\nlemma filter.eventually_eq.deriv_eq (hL : f\u2081 =\u1da0[\ud835\udcdd x] f) : deriv f\u2081 x = deriv f x :=\nby { unfold deriv, rwa filter.eventually_eq.fderiv_eq }\n\nprotected lemma filter.eventually_eq.deriv (h : f\u2081 =\u1da0[\ud835\udcdd x] f) : deriv f\u2081 =\u1da0[\ud835\udcdd x] deriv f :=\nh.eventually_eq_nhds.mono $ \u03bb x h, h.deriv_eq\n\nend congr\n\nsection id\n/-! ### Derivative of the identity -/\nvariables (s x L)\n\ntheorem has_deriv_at_filter_id : has_deriv_at_filter id 1 x L :=\n(has_fderiv_at_filter_id x L).has_deriv_at_filter\n\ntheorem has_deriv_within_at_id : has_deriv_within_at id 1 s x :=\nhas_deriv_at_filter_id _ _\n\ntheorem has_deriv_at_id : has_deriv_at id 1 x :=\nhas_deriv_at_filter_id _ _\n\ntheorem has_deriv_at_id' : has_deriv_at (\u03bb (x : \ud835\udd5c), x) 1 x :=\nhas_deriv_at_filter_id _ _\n\ntheorem has_strict_deriv_at_id : has_strict_deriv_at id 1 x :=\n(has_strict_fderiv_at_id x).has_strict_deriv_at\n\nlemma deriv_id : deriv id x = 1 :=\nhas_deriv_at.deriv (has_deriv_at_id x)\n\n@[simp] lemma deriv_id' : deriv (@id \ud835\udd5c) = \u03bb _, 1 := funext deriv_id\n\n@[simp] lemma deriv_id'' : deriv (\u03bb x : \ud835\udd5c, x) = \u03bb _, 1 := deriv_id'\n\nlemma deriv_within_id (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within id s x = 1 :=\n(has_deriv_within_at_id x s).deriv_within hxs\n\nend id\n\nsection const\n/-! ### Derivative of constant functions -/\nvariables (c : F) (s x L)\n\ntheorem has_deriv_at_filter_const : has_deriv_at_filter (\u03bb x, c) 0 x L :=\n(has_fderiv_at_filter_const c x L).has_deriv_at_filter\n\ntheorem has_strict_deriv_at_const : has_strict_deriv_at (\u03bb x, c) 0 x :=\n(has_strict_fderiv_at_const c x).has_strict_deriv_at\n\ntheorem has_deriv_within_at_const : has_deriv_within_at (\u03bb x, c) 0 s x :=\nhas_deriv_at_filter_const _ _ _\n\ntheorem has_deriv_at_const : has_deriv_at (\u03bb x, c) 0 x :=\nhas_deriv_at_filter_const _ _ _\n\nlemma deriv_const : deriv (\u03bb x, c) x = 0 :=\nhas_deriv_at.deriv (has_deriv_at_const x c)\n\n@[simp] lemma deriv_const' : deriv (\u03bb x:\ud835\udd5c, c) = \u03bb x, 0 :=\nfunext (\u03bb x, deriv_const x c)\n\nlemma deriv_within_const (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within (\u03bb x, c) s x = 0 :=\n(has_deriv_within_at_const _ _ _).deriv_within hxs\n\nend const\n\nsection continuous_linear_map\n/-! ### Derivative of continuous linear maps -/\nvariables (e : \ud835\udd5c \u2192L[\ud835\udd5c] F)\n\nprotected lemma continuous_linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=\ne.has_fderiv_at_filter.has_deriv_at_filter\n\nprotected lemma continuous_linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=\ne.has_strict_fderiv_at.has_strict_deriv_at\n\nprotected lemma continuous_linear_map.has_deriv_at : has_deriv_at e (e 1) x :=\ne.has_deriv_at_filter\n\nprotected lemma continuous_linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=\ne.has_deriv_at_filter\n\n@[simp] protected lemma continuous_linear_map.deriv : deriv e x = e 1 :=\ne.has_deriv_at.deriv\n\nprotected lemma continuous_linear_map.deriv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within e s x = e 1 :=\ne.has_deriv_within_at.deriv_within hxs\n\nend continuous_linear_map\n\nsection linear_map\n/-! ### Derivative of bundled linear maps -/\nvariables (e : \ud835\udd5c \u2192\u2097[\ud835\udd5c] F)\n\nprotected lemma linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=\ne.to_continuous_linear_map\u2081.has_deriv_at_filter\n\nprotected lemma linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=\ne.to_continuous_linear_map\u2081.has_strict_deriv_at\n\nprotected lemma linear_map.has_deriv_at : has_deriv_at e (e 1) x :=\ne.has_deriv_at_filter\n\nprotected lemma linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=\ne.has_deriv_at_filter\n\n@[simp] protected lemma linear_map.deriv : deriv e x = e 1 :=\ne.has_deriv_at.deriv\n\nprotected lemma linear_map.deriv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within e s x = e 1 :=\ne.has_deriv_within_at.deriv_within hxs\n\nend linear_map\n\nsection add\n/-! ### Derivative of the sum of two functions -/\n\ntheorem has_deriv_at_filter.add\n  (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :\n  has_deriv_at_filter (\u03bb y, f y + g y) (f' + g') x L :=\nby simpa using (hf.add hg).has_deriv_at_filter\n\ntheorem has_strict_deriv_at.add\n  (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :\n  has_strict_deriv_at (\u03bb y, f y + g y) (f' + g') x :=\nby simpa using (hf.add hg).has_strict_deriv_at\n\ntheorem has_deriv_within_at.add\n  (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :\n  has_deriv_within_at (\u03bb y, f y + g y) (f' + g') s x :=\nhf.add hg\n\ntheorem has_deriv_at.add\n  (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :\n  has_deriv_at (\u03bb x, f x + g x) (f' + g') x :=\nhf.add hg\n\nlemma deriv_within_add (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  deriv_within (\u03bby, f y + g y) s x = deriv_within f s x + deriv_within g s x :=\n(hf.has_deriv_within_at.add hg.has_deriv_within_at).deriv_within hxs\n\n@[simp] lemma deriv_add\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  deriv (\u03bby, f y + g y) x = deriv f x + deriv g x :=\n(hf.has_deriv_at.add hg.has_deriv_at).deriv\n\ntheorem has_deriv_at_filter.add_const\n  (hf : has_deriv_at_filter f f' x L) (c : F) :\n  has_deriv_at_filter (\u03bb y, f y + c) f' x L :=\nadd_zero f' \u25b8 hf.add (has_deriv_at_filter_const x L c)\n\ntheorem has_deriv_within_at.add_const\n  (hf : has_deriv_within_at f f' s x) (c : F) :\n  has_deriv_within_at (\u03bb y, f y + c) f' s x :=\nhf.add_const c\n\ntheorem has_deriv_at.add_const\n  (hf : has_deriv_at f f' x) (c : F) :\n  has_deriv_at (\u03bb x, f x + c) f' x :=\nhf.add_const c\n\nlemma deriv_within_add_const (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, f y + c) s x = deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_add_const hxs]\n\nlemma deriv_add_const (c : F) : deriv (\u03bby, f y + c) x = deriv f x :=\nby simp only [deriv, fderiv_add_const]\n\n@[simp] lemma deriv_add_const' (c : F) : deriv (\u03bb y, f y + c) = deriv f :=\nfunext $ \u03bb x, deriv_add_const c\n\ntheorem has_deriv_at_filter.const_add (c : F) (hf : has_deriv_at_filter f f' x L) :\n  has_deriv_at_filter (\u03bb y, c + f y) f' x L :=\nzero_add f' \u25b8 (has_deriv_at_filter_const x L c).add hf\n\ntheorem has_deriv_within_at.const_add (c : F) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb y, c + f y) f' s x :=\nhf.const_add c\n\ntheorem has_deriv_at.const_add (c : F) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, c + f x) f' x :=\nhf.const_add c\n\nlemma deriv_within_const_add (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, c + f y) s x = deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_const_add hxs]\n\nlemma deriv_const_add (c : F)  : deriv (\u03bby, c + f y) x = deriv f x :=\nby simp only [deriv, fderiv_const_add]\n\n@[simp] lemma deriv_const_add' (c : F) : deriv (\u03bb y, c + f y) = deriv f :=\nfunext $ \u03bb x, deriv_const_add c\n\nend add\n\nsection sum\n/-! ### Derivative of a finite sum of functions -/\n\nopen_locale big_operators\n\nvariables {\u03b9 : Type*} {u : finset \u03b9} {A : \u03b9 \u2192 (\ud835\udd5c \u2192 F)} {A' : \u03b9 \u2192 F}\n\ntheorem has_deriv_at_filter.sum (h : \u2200 i \u2208 u, has_deriv_at_filter (A i) (A' i) x L) :\n  has_deriv_at_filter (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x L :=\nby simpa [continuous_linear_map.sum_apply] using (has_fderiv_at_filter.sum h).has_deriv_at_filter\n\ntheorem has_strict_deriv_at.sum (h : \u2200 i \u2208 u, has_strict_deriv_at (A i) (A' i) x) :\n  has_strict_deriv_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x :=\nby simpa [continuous_linear_map.sum_apply] using (has_strict_fderiv_at.sum h).has_strict_deriv_at\n\ntheorem has_deriv_within_at.sum (h : \u2200 i \u2208 u, has_deriv_within_at (A i) (A' i) s x) :\n  has_deriv_within_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) s x :=\nhas_deriv_at_filter.sum h\n\ntheorem has_deriv_at.sum (h : \u2200 i \u2208 u, has_deriv_at (A i) (A' i) x) :\n  has_deriv_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x :=\nhas_deriv_at_filter.sum h\n\nlemma deriv_within_sum (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (h : \u2200 i \u2208 u, differentiable_within_at \ud835\udd5c (A i) s x) :\n  deriv_within (\u03bb y, \u2211 i in u, A i y) s x = \u2211 i in u, deriv_within (A i) s x :=\n(has_deriv_within_at.sum (\u03bb i hi, (h i hi).has_deriv_within_at)).deriv_within hxs\n\n@[simp] lemma deriv_sum (h : \u2200 i \u2208 u, differentiable_at \ud835\udd5c (A i) x) :\n  deriv (\u03bb y, \u2211 i in u, A i y) x = \u2211 i in u, deriv (A i) x :=\n(has_deriv_at.sum (\u03bb i hi, (h i hi).has_deriv_at)).deriv\n\nend sum\n\nsection pi\n\n/-! ### Derivatives of functions `f : \ud835\udd5c \u2192 \u03a0 i, E i` -/\n\nvariables {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_add_comm_group (E' i)]\n  [\u03a0 i, normed_space \ud835\udd5c (E' i)] {\u03c6 : \ud835\udd5c \u2192 \u03a0 i, E' i} {\u03c6' : \u03a0 i, E' i}\n\n@[simp] lemma has_strict_deriv_at_pi :\n  has_strict_deriv_at \u03c6 \u03c6' x \u2194 \u2200 i, has_strict_deriv_at (\u03bb x, \u03c6 x i) (\u03c6' i) x :=\nhas_strict_fderiv_at_pi'\n\n@[simp] lemma has_deriv_at_filter_pi :\n  has_deriv_at_filter \u03c6 \u03c6' x L \u2194\n    \u2200 i, has_deriv_at_filter (\u03bb x, \u03c6 x i) (\u03c6' i) x L :=\nhas_fderiv_at_filter_pi'\n\nlemma has_deriv_at_pi :\n  has_deriv_at \u03c6 \u03c6' x \u2194 \u2200 i, has_deriv_at (\u03bb x, \u03c6 x i) (\u03c6' i) x:=\nhas_deriv_at_filter_pi\n\nlemma has_deriv_within_at_pi :\n  has_deriv_within_at \u03c6 \u03c6' s x \u2194 \u2200 i, has_deriv_within_at (\u03bb x, \u03c6 x i) (\u03c6' i) s x:=\nhas_deriv_at_filter_pi\n\nlemma deriv_within_pi (h : \u2200 i, differentiable_within_at \ud835\udd5c (\u03bb x, \u03c6 x i) s x)\n  (hs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within \u03c6 s x = \u03bb i, deriv_within (\u03bb x, \u03c6 x i) s x :=\n(has_deriv_within_at_pi.2 (\u03bb i, (h i).has_deriv_within_at)).deriv_within hs\n\nlemma deriv_pi (h : \u2200 i, differentiable_at \ud835\udd5c (\u03bb x, \u03c6 x i) x) :\n  deriv \u03c6 x = \u03bb i, deriv (\u03bb x, \u03c6 x i) x :=\n(has_deriv_at_pi.2 (\u03bb i, (h i).has_deriv_at)).deriv\n\nend pi\n\nsection smul\n\n/-! ### Derivative of the multiplication of a scalar function and a vector function -/\n\nvariables {\ud835\udd5c' : Type*} [nontrivially_normed_field \ud835\udd5c'] [normed_algebra \ud835\udd5c \ud835\udd5c']\n  [normed_space \ud835\udd5c' F] [is_scalar_tower \ud835\udd5c \ud835\udd5c' F] {c : \ud835\udd5c \u2192 \ud835\udd5c'} {c' : \ud835\udd5c'}\n\ntheorem has_deriv_within_at.smul\n  (hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) s x :=\nby simpa using (has_fderiv_within_at.smul hc hf).has_deriv_within_at\n\ntheorem has_deriv_at.smul\n  (hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.smul hf\nend\n\ntheorem has_strict_deriv_at.smul\n  (hc : has_strict_deriv_at c c' x) (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) x :=\nby simpa using (hc.smul hf).has_strict_deriv_at\n\nlemma deriv_within_smul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  deriv_within (\u03bb y, c y \u2022 f y) s x = c x \u2022 deriv_within f s x + (deriv_within c s x) \u2022 f x :=\n(hc.has_deriv_within_at.smul hf.has_deriv_within_at).deriv_within hxs\n\nlemma deriv_smul (hc : differentiable_at \ud835\udd5c c x) (hf : differentiable_at \ud835\udd5c f x) :\n  deriv (\u03bb y, c y \u2022 f y) x = c x \u2022 deriv f x + (deriv c x) \u2022 f x :=\n(hc.has_deriv_at.smul hf.has_deriv_at).deriv\n\ntheorem has_strict_deriv_at.smul_const\n  (hc : has_strict_deriv_at c c' x) (f : F) :\n  has_strict_deriv_at (\u03bb y, c y \u2022 f) (c' \u2022 f) x :=\nbegin\n  have := hc.smul (has_strict_deriv_at_const x f),\n  rwa [smul_zero, zero_add] at this,\nend\n\ntheorem has_deriv_within_at.smul_const\n  (hc : has_deriv_within_at c c' s x) (f : F) :\n  has_deriv_within_at (\u03bb y, c y \u2022 f) (c' \u2022 f) s x :=\nbegin\n  have := hc.smul (has_deriv_within_at_const x s f),\n  rwa [smul_zero, zero_add] at this\nend\n\ntheorem has_deriv_at.smul_const\n  (hc : has_deriv_at c c' x) (f : F) :\n  has_deriv_at (\u03bb y, c y \u2022 f) (c' \u2022 f) x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.smul_const f\nend\n\nlemma deriv_within_smul_const (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (f : F) :\n  deriv_within (\u03bb y, c y \u2022 f) s x = (deriv_within c s x) \u2022 f :=\n(hc.has_deriv_within_at.smul_const f).deriv_within hxs\n\nlemma deriv_smul_const (hc : differentiable_at \ud835\udd5c c x) (f : F) :\n  deriv (\u03bb y, c y \u2022 f) x = (deriv c x) \u2022 f :=\n(hc.has_deriv_at.smul_const f).deriv\n\nend smul\n\nsection const_smul\n\nvariables {R : Type*} [semiring R] [module R F] [smul_comm_class \ud835\udd5c R F]\n  [has_continuous_const_smul R F]\n\ntheorem has_strict_deriv_at.const_smul\n  (c : R) (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb y, c \u2022 f y) (c \u2022 f') x :=\nby simpa using (hf.const_smul c).has_strict_deriv_at\n\ntheorem has_deriv_at_filter.const_smul\n  (c : R) (hf : has_deriv_at_filter f f' x L) :\n  has_deriv_at_filter (\u03bb y, c \u2022 f y) (c \u2022 f') x L :=\nby simpa using (hf.const_smul c).has_deriv_at_filter\n\ntheorem has_deriv_within_at.const_smul\n  (c : R) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb y, c \u2022 f y) (c \u2022 f') s x :=\nhf.const_smul c\n\ntheorem has_deriv_at.const_smul (c : R) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb y, c \u2022 f y) (c \u2022 f') x :=\nhf.const_smul c\n\nlemma deriv_within_const_smul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (c : R) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  deriv_within (\u03bb y, c \u2022 f y) s x = c \u2022 deriv_within f s x :=\n(hf.has_deriv_within_at.const_smul c).deriv_within hxs\n\nlemma deriv_const_smul (c : R) (hf : differentiable_at \ud835\udd5c f x) :\n  deriv (\u03bb y, c \u2022 f y) x = c \u2022 deriv f x :=\n(hf.has_deriv_at.const_smul c).deriv\n\nend const_smul\n\nsection neg\n/-! ### Derivative of the negative of a function -/\n\ntheorem has_deriv_at_filter.neg (h : has_deriv_at_filter f f' x L) :\n  has_deriv_at_filter (\u03bb x, -f x) (-f') x L :=\nby simpa using h.neg.has_deriv_at_filter\n\ntheorem has_deriv_within_at.neg (h : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, -f x) (-f') s x :=\nh.neg\n\ntheorem has_deriv_at.neg (h : has_deriv_at f f' x) : has_deriv_at (\u03bb x, -f x) (-f') x :=\nh.neg\n\ntheorem has_strict_deriv_at.neg (h : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, -f x) (-f') x :=\nby simpa using h.neg.has_strict_deriv_at\n\nlemma deriv_within.neg (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bby, -f y) s x = - deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_neg hxs, continuous_linear_map.neg_apply]\n\nlemma deriv.neg : deriv (\u03bby, -f y) x = - deriv f x :=\nby simp only [deriv, fderiv_neg, continuous_linear_map.neg_apply]\n\n@[simp] lemma deriv.neg' : deriv (\u03bby, -f y) = (\u03bb x, - deriv f x) :=\nfunext $ \u03bb x, deriv.neg\n\nend neg\n\nsection neg2\n/-! ### Derivative of the negation function (i.e `has_neg.neg`) -/\n\nvariables (s x L)\n\ntheorem has_deriv_at_filter_neg : has_deriv_at_filter has_neg.neg (-1) x L :=\nhas_deriv_at_filter.neg $ has_deriv_at_filter_id _ _\n\ntheorem has_deriv_within_at_neg : has_deriv_within_at has_neg.neg (-1) s x :=\nhas_deriv_at_filter_neg _ _\n\ntheorem has_deriv_at_neg : has_deriv_at has_neg.neg (-1) x :=\nhas_deriv_at_filter_neg _ _\n\ntheorem has_deriv_at_neg' : has_deriv_at (\u03bb x, -x) (-1) x :=\nhas_deriv_at_filter_neg _ _\n\ntheorem has_strict_deriv_at_neg : has_strict_deriv_at has_neg.neg (-1) x :=\nhas_strict_deriv_at.neg $ has_strict_deriv_at_id _\n\nlemma deriv_neg : deriv has_neg.neg x = -1 :=\nhas_deriv_at.deriv (has_deriv_at_neg x)\n\n@[simp] lemma deriv_neg' : deriv (has_neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) = \u03bb _, -1 :=\nfunext deriv_neg\n\n@[simp] lemma deriv_neg'' : deriv (\u03bb x : \ud835\udd5c, -x) x = -1 :=\nderiv_neg x\n\nlemma deriv_within_neg (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within has_neg.neg s x = -1 :=\n(has_deriv_within_at_neg x s).deriv_within hxs\n\nlemma differentiable_neg : differentiable \ud835\udd5c (has_neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) :=\ndifferentiable.neg differentiable_id\n\nlemma differentiable_on_neg : differentiable_on \ud835\udd5c (has_neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) s :=\ndifferentiable_on.neg differentiable_on_id\n\nend neg2\n\nsection sub\n/-! ### Derivative of the difference of two functions -/\n\ntheorem has_deriv_at_filter.sub\n  (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :\n  has_deriv_at_filter (\u03bb x, f x - g x) (f' - g') x L :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\ntheorem has_deriv_within_at.sub\n  (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :\n  has_deriv_within_at (\u03bb x, f x - g x) (f' - g') s x :=\nhf.sub hg\n\ntheorem has_deriv_at.sub\n  (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :\n  has_deriv_at (\u03bb x, f x - g x) (f' - g') x :=\nhf.sub hg\n\ntheorem has_strict_deriv_at.sub\n  (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :\n  has_strict_deriv_at (\u03bb x, f x - g x) (f' - g') x :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\nlemma deriv_within_sub (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  deriv_within (\u03bby, f y - g y) s x = deriv_within f s x - deriv_within g s x :=\n(hf.has_deriv_within_at.sub hg.has_deriv_within_at).deriv_within hxs\n\n@[simp] lemma deriv_sub\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  deriv (\u03bb y, f y - g y) x = deriv f x - deriv g x :=\n(hf.has_deriv_at.sub hg.has_deriv_at).deriv\n\ntheorem has_deriv_at_filter.is_O_sub (h : has_deriv_at_filter f f' x L) :\n  (\u03bb x', f x' - f x) =O[L] (\u03bb x', x' - x) :=\nhas_fderiv_at_filter.is_O_sub h\n\ntheorem has_deriv_at_filter.is_O_sub_rev (hf : has_deriv_at_filter f f' x L) (hf' : f' \u2260 0) :\n  (\u03bb x', x' - x) =O[L] (\u03bb x', f x' - f x) :=\nsuffices antilipschitz_with \u2016f'\u2016\u208a\u207b\u00b9 (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f'), from hf.is_O_sub_rev this,\nadd_monoid_hom_class.antilipschitz_of_bound (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') $\n  \u03bb x, by simp [norm_smul, \u2190 div_eq_inv_mul, mul_div_cancel _ (mt norm_eq_zero.1 hf')]\n\ntheorem has_deriv_at_filter.sub_const\n  (hf : has_deriv_at_filter f f' x L) (c : F) :\n  has_deriv_at_filter (\u03bb x, f x - c) f' x L :=\nby simpa only [sub_eq_add_neg] using hf.add_const (-c)\n\ntheorem has_deriv_within_at.sub_const\n  (hf : has_deriv_within_at f f' s x) (c : F) :\n  has_deriv_within_at (\u03bb x, f x - c) f' s x :=\nhf.sub_const c\n\ntheorem has_deriv_at.sub_const\n  (hf : has_deriv_at f f' x) (c : F) :\n  has_deriv_at (\u03bb x, f x - c) f' x :=\nhf.sub_const c\n\nlemma deriv_within_sub_const (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, f y - c) s x = deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_sub_const hxs]\n\nlemma deriv_sub_const (c : F) : deriv (\u03bb y, f y - c) x = deriv f x :=\nby simp only [deriv, fderiv_sub_const]\n\ntheorem has_deriv_at_filter.const_sub (c : F) (hf : has_deriv_at_filter f f' x L) :\n  has_deriv_at_filter (\u03bb x, c - f x) (-f') x L :=\nby simpa only [sub_eq_add_neg] using hf.neg.const_add c\n\ntheorem has_deriv_within_at.const_sub (c : F) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, c - f x) (-f') s x :=\nhf.const_sub c\n\ntheorem has_strict_deriv_at.const_sub (c : F) (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, c - f x) (-f') x :=\nby simpa only [sub_eq_add_neg] using hf.neg.const_add c\n\ntheorem has_deriv_at.const_sub (c : F) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, c - f x) (-f') x :=\nhf.const_sub c\n\nlemma deriv_within_const_sub (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, c - f y) s x = -deriv_within f s x :=\nby simp [deriv_within, fderiv_within_const_sub hxs]\n\nlemma deriv_const_sub (c : F) : deriv (\u03bb y, c - f y) x = -deriv f x :=\nby simp only [\u2190 deriv_within_univ,\n  deriv_within_const_sub (unique_diff_within_at_univ : unique_diff_within_at \ud835\udd5c _ _)]\n\nend sub\n\nsection continuous\n/-! ### Continuity of a function admitting a derivative -/\n\ntheorem has_deriv_at_filter.tendsto_nhds\n  (hL : L \u2264 \ud835\udcdd x) (h : has_deriv_at_filter f f' x L) :\n  tendsto f L (\ud835\udcdd (f x)) :=\nh.tendsto_nhds hL\n\ntheorem has_deriv_within_at.continuous_within_at\n  (h : has_deriv_within_at f f' s x) : continuous_within_at f s x :=\nhas_deriv_at_filter.tendsto_nhds inf_le_left h\n\ntheorem has_deriv_at.continuous_at (h : has_deriv_at f f' x) : continuous_at f x :=\nhas_deriv_at_filter.tendsto_nhds le_rfl h\n\nprotected theorem has_deriv_at.continuous_on {f f' : \ud835\udd5c \u2192 F}\n  (hderiv : \u2200 x \u2208 s, has_deriv_at f (f' x) x) : continuous_on f s :=\n\u03bb x hx, (hderiv x hx).continuous_at.continuous_within_at\n\nend continuous\n\nsection cartesian_product\n/-! ### Derivative of the cartesian product of two functions -/\n\nvariables {G : Type w} [normed_add_comm_group G] [normed_space \ud835\udd5c G]\nvariables {f\u2082 : \ud835\udd5c \u2192 G} {f\u2082' : G}\n\nlemma has_deriv_at_filter.prod\n  (hf\u2081 : has_deriv_at_filter f\u2081 f\u2081' x L) (hf\u2082 : has_deriv_at_filter f\u2082 f\u2082' x L) :\n  has_deriv_at_filter (\u03bb x, (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x L :=\nhf\u2081.prod hf\u2082\n\nlemma has_deriv_within_at.prod\n  (hf\u2081 : has_deriv_within_at f\u2081 f\u2081' s x) (hf\u2082 : has_deriv_within_at f\u2082 f\u2082' s x) :\n  has_deriv_within_at (\u03bb x, (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') s x :=\nhf\u2081.prod hf\u2082\n\nlemma has_deriv_at.prod (hf\u2081 : has_deriv_at f\u2081 f\u2081' x) (hf\u2082 : has_deriv_at f\u2082 f\u2082' x) :\n  has_deriv_at (\u03bb x, (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x :=\nhf\u2081.prod hf\u2082\n\nlemma has_strict_deriv_at.prod (hf\u2081 : has_strict_deriv_at f\u2081 f\u2081' x)\n  (hf\u2082 : has_strict_deriv_at f\u2082 f\u2082' x) :\n  has_strict_deriv_at (\u03bb x, (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x :=\nhf\u2081.prod hf\u2082\n\nend cartesian_product\n\nsection composition\n/-!\n### Derivative of the composition of a vector function and a scalar function\n\nWe use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`\nin lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also\nbecause the `comp` version with the shorter name will show up much more often in applications).\nThe formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to\nusual multiplication in `comp` lemmas.\n-/\n\n/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to\nget confused since there are too many possibilities for composition -/\nvariables {\ud835\udd5c' : Type*} [nontrivially_normed_field \ud835\udd5c'] [normed_algebra \ud835\udd5c \ud835\udd5c']\n  [normed_space \ud835\udd5c' F] [is_scalar_tower \ud835\udd5c \ud835\udd5c' F] {s' t' : set \ud835\udd5c'}\n  {h : \ud835\udd5c \u2192 \ud835\udd5c'} {h\u2081 : \ud835\udd5c \u2192 \ud835\udd5c} {h\u2082 : \ud835\udd5c' \u2192 \ud835\udd5c'} {h' h\u2082' : \ud835\udd5c'} {h\u2081' : \ud835\udd5c}\n  {g\u2081 : \ud835\udd5c' \u2192 F} {g\u2081' : F} {L' : filter \ud835\udd5c'} (x)\n\ntheorem has_deriv_at_filter.scomp\n  (hg : has_deriv_at_filter g\u2081 g\u2081' (h x) L')\n  (hh : has_deriv_at_filter h h' x L) (hL : tendsto h L L'):\n  has_deriv_at_filter (g\u2081 \u2218 h) (h' \u2022 g\u2081') x L :=\nby simpa using ((hg.restrict_scalars \ud835\udd5c).comp x hh hL).has_deriv_at_filter\n\ntheorem has_deriv_within_at.scomp_has_deriv_at\n  (hg : has_deriv_within_at g\u2081 g\u2081' s' (h x))\n  (hh : has_deriv_at h h' x) (hs : \u2200 x, h x \u2208 s') :\n  has_deriv_at (g\u2081 \u2218 h) (h' \u2022 g\u2081') x :=\nhg.scomp x hh $ tendsto_inf.2 \u27e8hh.continuous_at, tendsto_principal.2 $ eventually_of_forall hs\u27e9\n\ntheorem has_deriv_within_at.scomp\n  (hg : has_deriv_within_at g\u2081 g\u2081' t' (h x))\n  (hh : has_deriv_within_at h h' s x) (hst : maps_to h s t') :\n  has_deriv_within_at (g\u2081 \u2218 h) (h' \u2022 g\u2081') s x :=\nhg.scomp x hh $ hh.continuous_within_at.tendsto_nhds_within hst\n\n/-- The chain rule. -/\ntheorem has_deriv_at.scomp\n  (hg : has_deriv_at g\u2081 g\u2081' (h x)) (hh : has_deriv_at h h' x) :\n  has_deriv_at (g\u2081 \u2218 h) (h' \u2022 g\u2081') x :=\nhg.scomp x hh hh.continuous_at\n\ntheorem has_strict_deriv_at.scomp\n  (hg : has_strict_deriv_at g\u2081 g\u2081' (h x)) (hh : has_strict_deriv_at h h' x) :\n  has_strict_deriv_at (g\u2081 \u2218 h) (h' \u2022 g\u2081') x :=\nby simpa using ((hg.restrict_scalars \ud835\udd5c).comp x hh).has_strict_deriv_at\n\ntheorem has_deriv_at.scomp_has_deriv_within_at\n  (hg : has_deriv_at g\u2081 g\u2081' (h x)) (hh : has_deriv_within_at h h' s x) :\n  has_deriv_within_at (g\u2081 \u2218 h) (h' \u2022 g\u2081') s x :=\nhas_deriv_within_at.scomp x hg.has_deriv_within_at hh (maps_to_univ _ _)\n\nlemma deriv_within.scomp\n  (hg : differentiable_within_at \ud835\udd5c' g\u2081 t' (h x)) (hh : differentiable_within_at \ud835\udd5c h s x)\n  (hs : maps_to h s t') (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (g\u2081 \u2218 h) s x = deriv_within h s x \u2022 deriv_within g\u2081 t' (h x) :=\n(has_deriv_within_at.scomp x hg.has_deriv_within_at hh.has_deriv_within_at hs).deriv_within hxs\n\nlemma deriv.scomp\n  (hg : differentiable_at \ud835\udd5c' g\u2081 (h x)) (hh : differentiable_at \ud835\udd5c h x) :\n  deriv (g\u2081 \u2218 h) x = deriv h x \u2022 deriv g\u2081 (h x) :=\n(has_deriv_at.scomp x hg.has_deriv_at hh.has_deriv_at).deriv\n\n/-! ### Derivative of the composition of a scalar and vector functions -/\n\ntheorem has_deriv_at_filter.comp_has_fderiv_at_filter {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} (x)\n  {L'' : filter E} (hh\u2082 : has_deriv_at_filter h\u2082 h\u2082' (f x) L')\n  (hf : has_fderiv_at_filter f f' x L'') (hL : tendsto f L'' L') :\n  has_fderiv_at_filter (h\u2082 \u2218 f) (h\u2082' \u2022 f') x L'' :=\nby { convert (hh\u2082.restrict_scalars \ud835\udd5c).comp x hf hL, ext x, simp [mul_comm] }\n\ntheorem has_strict_deriv_at.comp_has_strict_fderiv_at {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} (x)\n  (hh : has_strict_deriv_at h\u2082 h\u2082' (f x)) (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (h\u2082 \u2218 f) (h\u2082' \u2022 f') x :=\nbegin\n  rw has_strict_deriv_at at hh,\n  convert (hh.restrict_scalars \ud835\udd5c).comp x hf,\n  ext x,\n  simp [mul_comm]\nend\n\ntheorem has_deriv_at.comp_has_fderiv_at {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} (x)\n  (hh : has_deriv_at h\u2082 h\u2082' (f x)) (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (h\u2082 \u2218 f) (h\u2082' \u2022 f') x :=\nhh.comp_has_fderiv_at_filter x hf hf.continuous_at\n\ntheorem has_deriv_at.comp_has_fderiv_within_at {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} {s} (x)\n  (hh : has_deriv_at h\u2082 h\u2082' (f x)) (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (h\u2082 \u2218 f) (h\u2082' \u2022 f') s x :=\nhh.comp_has_fderiv_at_filter x hf hf.continuous_within_at\n\ntheorem has_deriv_within_at.comp_has_fderiv_within_at {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} {s t} (x)\n  (hh : has_deriv_within_at h\u2082 h\u2082' t (f x)) (hf : has_fderiv_within_at f f' s x)\n  (hst : maps_to f s t) :\n  has_fderiv_within_at (h\u2082 \u2218 f) (h\u2082' \u2022 f') s x :=\nhh.comp_has_fderiv_at_filter x hf $ hf.continuous_within_at.tendsto_nhds_within hst\n\n/-! ### Derivative of the composition of two scalar functions -/\n\ntheorem has_deriv_at_filter.comp\n  (hh\u2082 : has_deriv_at_filter h\u2082 h\u2082' (h x) L')\n  (hh : has_deriv_at_filter h h' x L) (hL : tendsto h L L') :\n  has_deriv_at_filter (h\u2082 \u2218 h) (h\u2082' * h') x L :=\nby { rw mul_comm, exact hh\u2082.scomp x hh hL }\n\ntheorem has_deriv_within_at.comp\n  (hh\u2082 : has_deriv_within_at h\u2082 h\u2082' s' (h x))\n  (hh : has_deriv_within_at h h' s x) (hst : maps_to h s s') :\n  has_deriv_within_at (h\u2082 \u2218 h) (h\u2082' * h') s x :=\nby { rw mul_comm, exact hh\u2082.scomp x hh hst, }\n\n/-- The chain rule. -/\ntheorem has_deriv_at.comp\n  (hh\u2082 : has_deriv_at h\u2082 h\u2082' (h x)) (hh : has_deriv_at h h' x) :\n  has_deriv_at (h\u2082 \u2218 h) (h\u2082' * h') x :=\nhh\u2082.comp x hh hh.continuous_at\n\ntheorem has_strict_deriv_at.comp\n  (hh\u2082 : has_strict_deriv_at h\u2082 h\u2082' (h x)) (hh : has_strict_deriv_at h h' x) :\n  has_strict_deriv_at (h\u2082 \u2218 h) (h\u2082' * h') x :=\nby { rw mul_comm, exact hh\u2082.scomp x hh }\n\ntheorem has_deriv_at.comp_has_deriv_within_at\n  (hh\u2082 : has_deriv_at h\u2082 h\u2082' (h x)) (hh : has_deriv_within_at h h' s x) :\n  has_deriv_within_at (h\u2082 \u2218 h) (h\u2082' * h') s x :=\nhh\u2082.has_deriv_within_at.comp x hh (maps_to_univ _ _)\n\nlemma deriv_within.comp\n  (hh\u2082 : differentiable_within_at \ud835\udd5c' h\u2082 s' (h x)) (hh : differentiable_within_at \ud835\udd5c h s x)\n  (hs : maps_to h s s') (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (h\u2082 \u2218 h) s x = deriv_within h\u2082 s' (h x) * deriv_within h s x :=\n(hh\u2082.has_deriv_within_at.comp x hh.has_deriv_within_at hs).deriv_within hxs\n\nlemma deriv.comp\n  (hh\u2082 : differentiable_at \ud835\udd5c' h\u2082 (h x)) (hh : differentiable_at \ud835\udd5c h x) :\n  deriv (h\u2082 \u2218 h) x = deriv h\u2082 (h x) * deriv h x :=\n(hh\u2082.has_deriv_at.comp x hh.has_deriv_at).deriv\n\nprotected lemma has_deriv_at_filter.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_deriv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : \u2115) :\n  has_deriv_at_filter (f^[n]) (f'^n) x L :=\nbegin\n  have := hf.iterate hL hx n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nprotected lemma has_deriv_at.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_deriv_at f f' x) (hx : f x = x) (n : \u2115) :\n  has_deriv_at (f^[n]) (f'^n) x :=\nbegin\n  have := has_fderiv_at.iterate hf hx n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nprotected lemma has_deriv_within_at.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_deriv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : \u2115) :\n  has_deriv_within_at (f^[n]) (f'^n) s x :=\nbegin\n  have := has_fderiv_within_at.iterate hf hx hs n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nprotected lemma has_strict_deriv_at.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_strict_deriv_at f f' x) (hx : f x = x) (n : \u2115) :\n  has_strict_deriv_at (f^[n]) (f'^n) x :=\nbegin\n  have := hf.iterate hx n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nend composition\n\nsection composition_vector\n/-! ### Derivative of the composition of a function between vector spaces and a function on `\ud835\udd5c` -/\n\nopen continuous_linear_map\n\nvariables {l : F \u2192 E} {l' : F \u2192L[\ud835\udd5c] E}\nvariable (x)\n\n/-- The composition `l \u2218 f` where `l : F \u2192 E` and `f : \ud835\udd5c \u2192 F`, has a derivative within a set\nequal to the Fr\u00e9chet derivative of `l` applied to the derivative of `f`. -/\ntheorem has_fderiv_within_at.comp_has_deriv_within_at {t : set F}\n  (hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x)\n  (hst : maps_to f s t) :\n  has_deriv_within_at (l \u2218 f) (l' f') s x :=\nby simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (\u2218)]\n  using (hl.comp x hf.has_fderiv_within_at hst).has_deriv_within_at\n\ntheorem has_fderiv_at.comp_has_deriv_within_at\n  (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (l \u2218 f) (l' f') s x :=\nhl.has_fderiv_within_at.comp_has_deriv_within_at x hf (maps_to_univ _ _)\n\n/-- The composition `l \u2218 f` where `l : F \u2192 E` and `f : \ud835\udd5c \u2192 F`, has a derivative equal to the\nFr\u00e9chet derivative of `l` applied to the derivative of `f`. -/\ntheorem has_fderiv_at.comp_has_deriv_at (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) :\n  has_deriv_at (l \u2218 f) (l' f') x :=\nhas_deriv_within_at_univ.mp $ hl.comp_has_deriv_within_at x hf.has_deriv_within_at\n\ntheorem has_strict_fderiv_at.comp_has_strict_deriv_at\n  (hl : has_strict_fderiv_at l l' (f x)) (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (l \u2218 f) (l' f') x :=\nby simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (\u2218)]\n  using (hl.comp x hf.has_strict_fderiv_at).has_strict_deriv_at\n\nlemma fderiv_within.comp_deriv_within {t : set F}\n  (hl : differentiable_within_at \ud835\udd5c l t (f x)) (hf : differentiable_within_at \ud835\udd5c f s x)\n  (hs : maps_to f s t) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (l \u2218 f) s x = (fderiv_within \ud835\udd5c l t (f x) : F \u2192 E) (deriv_within f s x) :=\n(hl.has_fderiv_within_at.comp_has_deriv_within_at x hf.has_deriv_within_at hs).deriv_within hxs\n\nlemma fderiv.comp_deriv\n  (hl : differentiable_at \ud835\udd5c l (f x)) (hf : differentiable_at \ud835\udd5c f x) :\n  deriv (l \u2218 f) x = (fderiv \ud835\udd5c l (f x) : F \u2192 E) (deriv f x) :=\n(hl.has_fderiv_at.comp_has_deriv_at x hf.has_deriv_at).deriv\n\nend composition_vector\n\nsection mul\n/-! ### Derivative of the multiplication of two functions -/\nvariables {\ud835\udd5c' \ud835\udd38 : Type*} [normed_field \ud835\udd5c'] [normed_ring \ud835\udd38] [normed_algebra \ud835\udd5c \ud835\udd5c']\n  [normed_algebra \ud835\udd5c \ud835\udd38] {c d : \ud835\udd5c \u2192 \ud835\udd38} {c' d' : \ud835\udd38} {u v : \ud835\udd5c \u2192 \ud835\udd5c'}\n\ntheorem has_deriv_within_at.mul\n  (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) :\n  has_deriv_within_at (\u03bb y, c y * d y) (c' * d x + c x * d') s x :=\nbegin\n  have := (has_fderiv_within_at.mul' hc hd).has_deriv_within_at,\n  rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply,\n      continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply,\n      continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply,\n      one_smul, one_smul, add_comm] at this,\nend\n\ntheorem has_deriv_at.mul (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :\n  has_deriv_at (\u03bb y, c y * d y) (c' * d x + c x * d') x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.mul hd\nend\n\ntheorem has_strict_deriv_at.mul\n  (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) :\n  has_strict_deriv_at (\u03bb y, c y * d y) (c' * d x + c x * d') x :=\nbegin\n  have := (has_strict_fderiv_at.mul' hc hd).has_strict_deriv_at,\n  rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply,\n      continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply,\n      continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply,\n      one_smul, one_smul, add_comm] at this,\nend\n\nlemma deriv_within_mul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) :\n  deriv_within (\u03bb y, c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x :=\n(hc.has_deriv_within_at.mul hd.has_deriv_within_at).deriv_within hxs\n\n@[simp] lemma deriv_mul (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) :\n  deriv (\u03bb y, c y * d y) x = deriv c x * d x + c x * deriv d x :=\n(hc.has_deriv_at.mul hd.has_deriv_at).deriv\n\ntheorem has_deriv_within_at.mul_const (hc : has_deriv_within_at c c' s x) (d : \ud835\udd38) :\n  has_deriv_within_at (\u03bb y, c y * d) (c' * d) s x :=\nbegin\n  convert hc.mul (has_deriv_within_at_const x s d),\n  rw [mul_zero, add_zero]\nend\n\ntheorem has_deriv_at.mul_const (hc : has_deriv_at c c' x) (d : \ud835\udd38) :\n  has_deriv_at (\u03bb y, c y * d) (c' * d) x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.mul_const d\nend\n\ntheorem has_deriv_at_mul_const (c : \ud835\udd5c) : has_deriv_at (\u03bb x, x * c) c x :=\nby simpa only [one_mul] using (has_deriv_at_id' x).mul_const c\n\ntheorem has_strict_deriv_at.mul_const (hc : has_strict_deriv_at c c' x) (d : \ud835\udd38) :\n  has_strict_deriv_at (\u03bb y, c y * d) (c' * d) x :=\nbegin\n  convert hc.mul (has_strict_deriv_at_const x d),\n  rw [mul_zero, add_zero]\nend\n\nlemma deriv_within_mul_const (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd38) :\n  deriv_within (\u03bb y, c y * d) s x = deriv_within c s x * d :=\n(hc.has_deriv_within_at.mul_const d).deriv_within hxs\n\nlemma deriv_mul_const (hc : differentiable_at \ud835\udd5c c x) (d : \ud835\udd38) :\n  deriv (\u03bb y, c y * d) x = deriv c x * d :=\n(hc.has_deriv_at.mul_const d).deriv\n\nlemma deriv_mul_const_field (v : \ud835\udd5c') :\n  deriv (\u03bb y, u y * v) x = deriv u x * v :=\nbegin\n  by_cases hu : differentiable_at \ud835\udd5c u x,\n  { exact deriv_mul_const hu v },\n  { rw [deriv_zero_of_not_differentiable_at hu, zero_mul],\n    rcases eq_or_ne v 0 with rfl|hd,\n    { simp only [mul_zero, deriv_const] },\n    { refine deriv_zero_of_not_differentiable_at (mt (\u03bb H, _) hu),\n      simpa only [mul_inv_cancel_right\u2080 hd] using H.mul_const v\u207b\u00b9 } }\nend\n\n@[simp] lemma deriv_mul_const_field' (v : \ud835\udd5c') : deriv (\u03bb x, u x * v) = \u03bb x, deriv u x * v :=\nfunext $ \u03bb _, deriv_mul_const_field v\n\ntheorem has_deriv_within_at.const_mul (c : \ud835\udd38) (hd : has_deriv_within_at d d' s x) :\n  has_deriv_within_at (\u03bb y, c * d y) (c * d') s x :=\nbegin\n  convert (has_deriv_within_at_const x s c).mul hd,\n  rw [zero_mul, zero_add]\nend\n\ntheorem has_deriv_at.const_mul (c : \ud835\udd38) (hd : has_deriv_at d d' x) :\n  has_deriv_at (\u03bb y, c * d y) (c * d') x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hd.const_mul c\nend\n\ntheorem has_strict_deriv_at.const_mul (c : \ud835\udd38) (hd : has_strict_deriv_at d d' x) :\n  has_strict_deriv_at (\u03bb y, c * d y) (c * d') x :=\nbegin\n  convert (has_strict_deriv_at_const _ _).mul hd,\n  rw [zero_mul, zero_add]\nend\n\nlemma deriv_within_const_mul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (c : \ud835\udd38) (hd : differentiable_within_at \ud835\udd5c d s x) :\n  deriv_within (\u03bb y, c * d y) s x = c * deriv_within d s x :=\n(hd.has_deriv_within_at.const_mul c).deriv_within hxs\n\nlemma deriv_const_mul (c : \ud835\udd38) (hd : differentiable_at \ud835\udd5c d x) :\n  deriv (\u03bb y, c * d y) x = c * deriv d x :=\n(hd.has_deriv_at.const_mul c).deriv\n\nlemma deriv_const_mul_field (u : \ud835\udd5c') : deriv (\u03bb y, u * v y) x = u * deriv v x :=\nby simp only [mul_comm u, deriv_mul_const_field]\n\n@[simp] lemma deriv_const_mul_field' (u : \ud835\udd5c') : deriv (\u03bb x, u * v x) = \u03bb x, u * deriv v x :=\nfunext (\u03bb x, deriv_const_mul_field u)\n\nend mul\n\nsection inverse\n/-! ### Derivative of `x \u21a6 x\u207b\u00b9` -/\n\ntheorem has_strict_deriv_at_inv (hx : x \u2260 0) : has_strict_deriv_at has_inv.inv (-(x^2)\u207b\u00b9) x :=\nbegin\n  suffices : (\u03bb p : \ud835\udd5c \u00d7 \ud835\udd5c, (p.1 - p.2) * ((x * x)\u207b\u00b9 - (p.1 * p.2)\u207b\u00b9)) =o[\ud835\udcdd (x, x)]\n    (\u03bb p, (p.1 - p.2) * 1),\n  { refine this.congr' _ (eventually_of_forall $ \u03bb _, mul_one _),\n    refine eventually.mono (is_open.mem_nhds (is_open_ne.prod is_open_ne) \u27e8hx, hx\u27e9) _,\n    rintro \u27e8y, z\u27e9 \u27e8hy, hz\u27e9,\n    simp only [mem_set_of_eq] at hy hz, -- hy : y \u2260 0, hz : z \u2260 0\n    field_simp [hx, hy, hz], ring, },\n  refine (is_O_refl (\u03bb p : \ud835\udd5c \u00d7 \ud835\udd5c, p.1 - p.2) _).mul_is_o ((is_o_one_iff _).2 _),\n  rw [\u2190 sub_self (x * x)\u207b\u00b9],\n  exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv\u2080 $ mul_ne_zero hx hx)\nend\n\ntheorem has_deriv_at_inv (x_ne_zero : x \u2260 0) :\n  has_deriv_at (\u03bby, y\u207b\u00b9) (-(x^2)\u207b\u00b9) x :=\n(has_strict_deriv_at_inv x_ne_zero).has_deriv_at\n\ntheorem has_deriv_within_at_inv (x_ne_zero : x \u2260 0) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, x\u207b\u00b9) (-(x^2)\u207b\u00b9) s x :=\n(has_deriv_at_inv x_ne_zero).has_deriv_within_at\n\nlemma differentiable_at_inv :\n  differentiable_at \ud835\udd5c (\u03bbx, x\u207b\u00b9) x \u2194 x \u2260 0:=\n\u27e8\u03bb H, normed_field.continuous_at_inv.1 H.continuous_at,\n  \u03bb H, (has_deriv_at_inv H).differentiable_at\u27e9\n\nlemma differentiable_within_at_inv (x_ne_zero : x \u2260 0) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, x\u207b\u00b9) s x :=\n(differentiable_at_inv.2 x_ne_zero).differentiable_within_at\n\nlemma differentiable_on_inv : differentiable_on \ud835\udd5c (\u03bbx:\ud835\udd5c, x\u207b\u00b9) {x | x \u2260 0} :=\n\u03bbx hx, differentiable_within_at_inv hx\n\nlemma deriv_inv : deriv (\u03bbx, x\u207b\u00b9) x = -(x^2)\u207b\u00b9 :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hne,\n  { simp [deriv_zero_of_not_differentiable_at (mt differentiable_at_inv.1 (not_not.2 rfl))] },\n  { exact (has_deriv_at_inv hne).deriv  }\nend\n\n@[simp] lemma deriv_inv' : deriv (\u03bb x : \ud835\udd5c, x\u207b\u00b9) = \u03bb x, -(x ^ 2)\u207b\u00b9 := funext (\u03bb x, deriv_inv)\n\nlemma deriv_within_inv (x_ne_zero : x \u2260 0) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, x\u207b\u00b9) s x = -(x^2)\u207b\u00b9 :=\nbegin\n  rw differentiable_at.deriv_within (differentiable_at_inv.2 x_ne_zero) hxs,\n  exact deriv_inv\nend\n\nlemma has_fderiv_at_inv (x_ne_zero : x \u2260 0) :\n  has_fderiv_at (\u03bbx, x\u207b\u00b9) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\nhas_deriv_at_inv x_ne_zero\n\nlemma has_fderiv_within_at_inv (x_ne_zero : x \u2260 0) :\n  has_fderiv_within_at (\u03bbx, x\u207b\u00b9) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) s x :=\n(has_fderiv_at_inv x_ne_zero).has_fderiv_within_at\n\nlemma fderiv_inv :\n  fderiv \ud835\udd5c (\u03bbx, x\u207b\u00b9) x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) :=\nby rw [\u2190 deriv_fderiv, deriv_inv]\n\nlemma fderiv_within_inv (x_ne_zero : x \u2260 0) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bbx, x\u207b\u00b9) s x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) :=\nbegin\n  rw differentiable_at.fderiv_within (differentiable_at_inv.2 x_ne_zero) hxs,\n  exact fderiv_inv\nend\n\nvariables {c : \ud835\udd5c \u2192 \ud835\udd5c} {h : E \u2192 \ud835\udd5c} {c' : \ud835\udd5c} {z : E} {S : set E}\n\nlemma has_deriv_within_at.inv\n  (hc : has_deriv_within_at c c' s x) (hx : c x \u2260 0) :\n  has_deriv_within_at (\u03bb y, (c y)\u207b\u00b9) (- c' / (c x)^2) s x :=\nbegin\n  convert (has_deriv_at_inv hx).comp_has_deriv_within_at x hc,\n  field_simp\nend\n\nlemma has_deriv_at.inv (hc : has_deriv_at c c' x) (hx : c x \u2260 0) :\n  has_deriv_at (\u03bb y, (c y)\u207b\u00b9) (- c' / (c x)^2) x :=\nbegin\n  rw \u2190 has_deriv_within_at_univ at *,\n  exact hc.inv hx\nend\n\nlemma differentiable_within_at.inv (hf : differentiable_within_at \ud835\udd5c h S z) (hz : h z \u2260 0) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, (h x)\u207b\u00b9) S z :=\n(differentiable_at_inv.mpr hz).comp_differentiable_within_at z hf\n\n@[simp] lemma differentiable_at.inv (hf : differentiable_at \ud835\udd5c h z) (hz : h z \u2260 0) :\n  differentiable_at \ud835\udd5c (\u03bbx, (h x)\u207b\u00b9) z :=\n(differentiable_at_inv.mpr hz).comp z hf\n\nlemma differentiable_on.inv (hf : differentiable_on \ud835\udd5c h S) (hz : \u2200 x \u2208 S, h x \u2260 0) :\n  differentiable_on \ud835\udd5c (\u03bbx, (h x)\u207b\u00b9) S :=\n\u03bbx h, (hf x h).inv (hz x h)\n\n@[simp] lemma differentiable.inv (hf : differentiable \ud835\udd5c h) (hz : \u2200 x, h x \u2260 0) :\n  differentiable \ud835\udd5c (\u03bbx, (h x)\u207b\u00b9) :=\n\u03bbx, (hf x).inv (hz x)\n\nlemma deriv_within_inv' (hc : differentiable_within_at \ud835\udd5c c s x) (hx : c x \u2260 0)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, (c x)\u207b\u00b9) s x = - (deriv_within c s x) / (c x)^2 :=\n(hc.has_deriv_within_at.inv hx).deriv_within hxs\n\n@[simp] lemma deriv_inv'' (hc : differentiable_at \ud835\udd5c c x) (hx : c x \u2260 0) :\n  deriv (\u03bbx, (c x)\u207b\u00b9) x = - (deriv c x) / (c x)^2 :=\n(hc.has_deriv_at.inv hx).deriv\n\nend inverse\n\nsection division\n/-! ### Derivative of `x \u21a6 c x / d x` -/\n\nvariables {\ud835\udd5c' : Type*} [nontrivially_normed_field \ud835\udd5c'] [normed_algebra \ud835\udd5c \ud835\udd5c']\n  {c d : \ud835\udd5c \u2192 \ud835\udd5c'} {c' d' : \ud835\udd5c'}\n\nlemma has_deriv_within_at.div\n  (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x \u2260 0) :\n  has_deriv_within_at (\u03bb y, c y / d y) ((c' * d x - c x * d') / (d x)^2) s x :=\nbegin\n  convert hc.mul ((has_deriv_at_inv hx).comp_has_deriv_within_at x hd),\n  { simp only [div_eq_mul_inv] },\n  { field_simp, ring }\nend\n\nlemma has_strict_deriv_at.div (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x)\n  (hx : d x \u2260 0) :\n  has_strict_deriv_at (\u03bb y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=\nbegin\n  convert hc.mul ((has_strict_deriv_at_inv hx).comp x hd),\n  { simp only [div_eq_mul_inv] },\n  { field_simp, ring }\nend\n\nlemma has_deriv_at.div (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x \u2260 0) :\n  has_deriv_at (\u03bb y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=\nbegin\n  rw \u2190 has_deriv_within_at_univ at *,\n  exact hc.div hd hx\nend\n\nlemma differentiable_within_at.div\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) (hx : d x \u2260 0) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, c x / d x) s x :=\n((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).differentiable_within_at\n\n@[simp] lemma differentiable_at.div\n  (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) (hx : d x \u2260 0) :\n  differentiable_at \ud835\udd5c (\u03bbx, c x / d x) x :=\n((hc.has_deriv_at).div (hd.has_deriv_at) hx).differentiable_at\n\nlemma differentiable_on.div\n  (hc : differentiable_on \ud835\udd5c c s) (hd : differentiable_on \ud835\udd5c d s) (hx : \u2200 x \u2208 s, d x \u2260 0) :\n  differentiable_on \ud835\udd5c (\u03bbx, c x / d x) s :=\n\u03bbx h, (hc x h).div (hd x h) (hx x h)\n\n@[simp] lemma differentiable.div\n  (hc : differentiable \ud835\udd5c c) (hd : differentiable \ud835\udd5c d) (hx : \u2200 x, d x \u2260 0) :\ndifferentiable \ud835\udd5c (\u03bbx, c x / d x) :=\n\u03bbx, (hc x).div (hd x) (hx x)\n\nlemma deriv_within_div\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) (hx : d x \u2260 0)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, c x / d x) s x\n    = ((deriv_within c s x) * d x - c x * (deriv_within d s x)) / (d x)^2 :=\n((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).deriv_within hxs\n\n@[simp] lemma deriv_div\n  (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) (hx : d x \u2260 0) :\n  deriv (\u03bbx, c x / d x) x = ((deriv c x) * d x - c x * (deriv d x)) / (d x)^2 :=\n((hc.has_deriv_at).div (hd.has_deriv_at) hx).deriv\n\nlemma has_deriv_at.div_const (hc : has_deriv_at c c' x) (d : \ud835\udd5c') :\n  has_deriv_at (\u03bb x, c x / d) (c' / d) x :=\nby simpa only [div_eq_mul_inv] using hc.mul_const d\u207b\u00b9\n\nlemma has_deriv_within_at.div_const (hc : has_deriv_within_at c c' s x) (d : \ud835\udd5c') :\n  has_deriv_within_at (\u03bb x, c x / d) (c' / d) s x :=\nby simpa only [div_eq_mul_inv] using hc.mul_const d\u207b\u00b9\n\nlemma has_strict_deriv_at.div_const (hc : has_strict_deriv_at c c' x) (d : \ud835\udd5c') :\n  has_strict_deriv_at (\u03bb x, c x / d) (c' / d) x :=\nby simpa only [div_eq_mul_inv] using hc.mul_const d\u207b\u00b9\n\nlemma differentiable_within_at.div_const (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd5c') :\n  differentiable_within_at \ud835\udd5c (\u03bbx, c x / d) s x :=\n(hc.has_deriv_within_at.div_const _).differentiable_within_at\n\n@[simp] lemma differentiable_at.div_const (hc : differentiable_at \ud835\udd5c c x) (d : \ud835\udd5c') :\n  differentiable_at \ud835\udd5c (\u03bb x, c x / d) x :=\n(hc.has_deriv_at.div_const _).differentiable_at\n\nlemma differentiable_on.div_const (hc : differentiable_on \ud835\udd5c c s) (d : \ud835\udd5c') :\n  differentiable_on \ud835\udd5c (\u03bbx, c x / d) s :=\n\u03bb x hx, (hc x hx).div_const d\n\n@[simp] lemma differentiable.div_const (hc : differentiable \ud835\udd5c c) (d : \ud835\udd5c') :\n  differentiable \ud835\udd5c (\u03bbx, c x / d) :=\n\u03bb x, (hc x).div_const d\n\nlemma deriv_within_div_const (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd5c')\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, c x / d) s x = (deriv_within c s x) / d :=\nby simp [div_eq_inv_mul, deriv_within_const_mul, hc, hxs]\n\n@[simp] lemma deriv_div_const (d : \ud835\udd5c') :\n  deriv (\u03bbx, c x / d) x = (deriv c x) / d :=\nby simp only [div_eq_mul_inv, deriv_mul_const_field]\n\nend division\n\nsection clm_comp_apply\n/-! ### Derivative of the pointwise composition/application of continuous linear maps -/\n\nopen continuous_linear_map\n\nvariables {G : Type*} [normed_add_comm_group G] [normed_space \ud835\udd5c G] {c : \ud835\udd5c \u2192 F \u2192L[\ud835\udd5c] G}\n  {c' : F \u2192L[\ud835\udd5c] G} {d : \ud835\udd5c \u2192 E \u2192L[\ud835\udd5c] F} {d' : E \u2192L[\ud835\udd5c] F} {u : \ud835\udd5c \u2192 F} {u' : F}\n\nlemma has_strict_deriv_at.clm_comp (hc : has_strict_deriv_at c c' x)\n  (hd : has_strict_deriv_at d d' x) :\n  has_strict_deriv_at (\u03bb y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x :=\nbegin\n  have := (hc.has_strict_fderiv_at.clm_comp hd.has_strict_fderiv_at).has_strict_deriv_at,\n  rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n      one_smul, add_comm] at this,\nend\n\nlemma has_deriv_within_at.clm_comp (hc : has_deriv_within_at c c' s x)\n  (hd : has_deriv_within_at d d' s x) :\n  has_deriv_within_at (\u03bb y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') s x :=\nbegin\n  have := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).has_deriv_within_at,\n  rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n      one_smul, add_comm] at this,\nend\n\nlemma has_deriv_at.clm_comp (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :\n  has_deriv_at (\u03bb y, (c y).comp (d y))\n  (c'.comp (d x) + (c x).comp d') x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.clm_comp hd\nend\n\nlemma deriv_within_clm_comp (hc : differentiable_within_at \ud835\udd5c c s x)\n  (hd : differentiable_within_at \ud835\udd5c d s x) (hxs : unique_diff_within_at \ud835\udd5c s x):\n  deriv_within (\u03bb y, (c y).comp (d y)) s x =\n    ((deriv_within c s x).comp (d x) + (c x).comp (deriv_within d s x)) :=\n(hc.has_deriv_within_at.clm_comp hd.has_deriv_within_at).deriv_within hxs\n\nlemma deriv_clm_comp (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) :\n  deriv (\u03bb y, (c y).comp (d y)) x =\n    ((deriv c x).comp (d x) + (c x).comp (deriv d x)) :=\n(hc.has_deriv_at.clm_comp hd.has_deriv_at).deriv\n\nlemma has_strict_deriv_at.clm_apply (hc : has_strict_deriv_at c c' x)\n  (hu : has_strict_deriv_at u u' x) :\n  has_strict_deriv_at (\u03bb y, (c y) (u y)) (c' (u x) + c x u') x :=\nbegin\n  have := (hc.has_strict_fderiv_at.clm_apply hu.has_strict_fderiv_at).has_strict_deriv_at,\n  rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n      one_smul, add_comm] at this,\nend\n\nlemma has_deriv_within_at.clm_apply (hc : has_deriv_within_at c c' s x)\n  (hu : has_deriv_within_at u u' s x) :\n  has_deriv_within_at (\u03bb y, (c y) (u y)) (c' (u x) + c x u') s x :=\nbegin\n  have := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).has_deriv_within_at,\n  rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n      one_smul, add_comm] at this,\nend\n\nlemma has_deriv_at.clm_apply (hc : has_deriv_at c c' x) (hu : has_deriv_at u u' x) :\n  has_deriv_at (\u03bb y, (c y) (u y)) (c' (u x) + c x u') x :=\nbegin\n  have := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).has_deriv_at,\n  rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n      one_smul, add_comm] at this,\nend\n\nlemma deriv_within_clm_apply (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hu : differentiable_within_at \ud835\udd5c u s x) :\n  deriv_within (\u03bb y, (c y) (u y)) s x = (deriv_within c s x (u x) + c x (deriv_within u s x)) :=\n(hc.has_deriv_within_at.clm_apply hu.has_deriv_within_at).deriv_within hxs\n\nlemma deriv_clm_apply (hc : differentiable_at \ud835\udd5c c x) (hu : differentiable_at \ud835\udd5c u x) :\n  deriv (\u03bb y, (c y) (u y)) x = (deriv c x (u x) + c x (deriv u x)) :=\n(hc.has_deriv_at.clm_apply hu.has_deriv_at).deriv\n\nend clm_comp_apply\n\ntheorem has_strict_deriv_at.has_strict_fderiv_at_equiv {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' x : \ud835\udd5c}\n  (hf : has_strict_deriv_at f f' x) (hf' : f' \u2260 0) :\n  has_strict_fderiv_at f\n    (continuous_linear_equiv.units_equiv_aut \ud835\udd5c (units.mk0 f' hf') : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\nhf\n\ntheorem has_deriv_at.has_fderiv_at_equiv {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' x : \ud835\udd5c} (hf : has_deriv_at f f' x)\n  (hf' : f' \u2260 0) :\n  has_fderiv_at f (continuous_linear_equiv.units_equiv_aut \ud835\udd5c (units.mk0 f' hf') : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\nhf\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'\u207b\u00b9` at `a`\nin the strict sense.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have an\ninverse function. -/\ntheorem has_strict_deriv_at.of_local_left_inverse {f g : \ud835\udd5c \u2192 \ud835\udd5c} {f' a : \ud835\udd5c}\n  (hg : continuous_at g a) (hf : has_strict_deriv_at f f' (g a)) (hf' : f' \u2260 0)\n  (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n  has_strict_deriv_at g f'\u207b\u00b9 a :=\n(hf.has_strict_fderiv_at_equiv hf').of_local_left_inverse hg hfg\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a\nnonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` has the derivative `f'\u207b\u00b9`\nat `a` in the strict sense.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\nlemma local_homeomorph.has_strict_deriv_at_symm (f : local_homeomorph \ud835\udd5c \ud835\udd5c) {a f' : \ud835\udd5c}\n  (ha : a \u2208 f.target) (hf' : f' \u2260 0) (htff' : has_strict_deriv_at f f' (f.symm a)) :\n  has_strict_deriv_at f.symm f'\u207b\u00b9 a :=\nhtff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a`, then `g` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\ntheorem has_deriv_at.of_local_left_inverse {f g : \ud835\udd5c \u2192 \ud835\udd5c} {f' a : \ud835\udd5c}\n  (hg : continuous_at g a) (hf : has_deriv_at f f' (g a)) (hf' : f' \u2260 0)\n  (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n  has_deriv_at g f'\u207b\u00b9 a :=\n(hf.has_fderiv_at_equiv hf').of_local_left_inverse hg hfg\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an\nnonzero derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\nlemma local_homeomorph.has_deriv_at_symm (f : local_homeomorph \ud835\udd5c \ud835\udd5c) {a f' : \ud835\udd5c}\n  (ha : a \u2208 f.target) (hf' : f' \u2260 0) (htff' : has_deriv_at f f' (f.symm a)) :\n  has_deriv_at f.symm f'\u207b\u00b9 a :=\nhtff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)\n\nlemma has_deriv_at.eventually_ne (h : has_deriv_at f f' x) (hf' : f' \u2260 0) :\n  \u2200\u1da0 z in \ud835\udcdd[\u2260] x, f z \u2260 f x :=\n(has_deriv_at_iff_has_fderiv_at.1 h).eventually_ne\n  \u27e8\u2016f'\u2016\u207b\u00b9, \u03bb z, by field_simp [norm_smul, mt norm_eq_zero.1 hf']\u27e9\n\nlemma has_deriv_at.tendsto_punctured_nhds (h : has_deriv_at f f' x) (hf' : f' \u2260 0) :\n  tendsto f (\ud835\udcdd[\u2260] x) (\ud835\udcdd[\u2260] (f x)) :=\ntendsto_nhds_within_of_tendsto_nhds_of_eventually_within _\n  h.continuous_at.continuous_within_at (h.eventually_ne hf')\n\ntheorem not_differentiable_within_at_of_local_left_inverse_has_deriv_within_at_zero\n  {f g : \ud835\udd5c \u2192 \ud835\udd5c} {a : \ud835\udd5c} {s t : set \ud835\udd5c} (ha : a \u2208 s) (hsu : unique_diff_within_at \ud835\udd5c s a)\n  (hf : has_deriv_within_at f 0 t (g a)) (hst : maps_to g s t) (hfg : f \u2218 g =\u1da0[\ud835\udcdd[s] a] id) :\n  \u00acdifferentiable_within_at \ud835\udd5c g s a :=\nbegin\n  intro hg,\n  have := (hf.comp a hg.has_deriv_within_at hst).congr_of_eventually_eq_of_mem hfg.symm ha,\n  simpa using hsu.eq_deriv _ this (has_deriv_within_at_id _ _)\nend\n\ntheorem not_differentiable_at_of_local_left_inverse_has_deriv_at_zero\n  {f g : \ud835\udd5c \u2192 \ud835\udd5c} {a : \ud835\udd5c} (hf : has_deriv_at f 0 (g a)) (hfg : f \u2218 g =\u1da0[\ud835\udcdd a] id) :\n  \u00acdifferentiable_at \ud835\udd5c g a :=\nbegin\n  intro hg,\n  have := (hf.comp a hg.has_deriv_at).congr_of_eventually_eq hfg.symm,\n  simpa using this.unique (has_deriv_at_id a)\nend\n\nend\n\nnamespace polynomial\n/-! ### Derivative of a polynomial -/\n\nvariables {x : \ud835\udd5c} {s : set \ud835\udd5c}\nvariable (p : \ud835\udd5c[X])\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected lemma has_strict_deriv_at (x : \ud835\udd5c) :\n  has_strict_deriv_at (\u03bbx, p.eval x) (p.derivative.eval x) x :=\nbegin\n  apply p.induction_on,\n  { simp [has_strict_deriv_at_const] },\n  { assume p q hp hq,\n    convert hp.add hq;\n    simp },\n  { assume n a h,\n    convert h.mul (has_strict_deriv_at_id x),\n    { ext y, simp [pow_add, mul_assoc] },\n    { simp only [pow_add, pow_one, derivative_mul, derivative_C, zero_mul, derivative_X_pow,\n      derivative_X, mul_one, zero_add, eval_mul, eval_C, eval_add, eval_nat_cast, eval_pow, eval_X,\n      id.def], ring } }\nend\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected lemma has_deriv_at (x : \ud835\udd5c) : has_deriv_at (\u03bbx, p.eval x) (p.derivative.eval x) x :=\n(p.has_strict_deriv_at x).has_deriv_at\n\nprotected theorem has_deriv_within_at (x : \ud835\udd5c) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, p.eval x) (p.derivative.eval x) s x :=\n(p.has_deriv_at x).has_deriv_within_at\n\nprotected lemma differentiable_at : differentiable_at \ud835\udd5c (\u03bbx, p.eval x) x :=\n(p.has_deriv_at x).differentiable_at\n\nprotected lemma differentiable_within_at : differentiable_within_at \ud835\udd5c (\u03bbx, p.eval x) s x :=\np.differentiable_at.differentiable_within_at\n\nprotected lemma differentiable : differentiable \ud835\udd5c (\u03bbx, p.eval x) :=\n\u03bbx, p.differentiable_at\n\nprotected lemma differentiable_on : differentiable_on \ud835\udd5c (\u03bbx, p.eval x) s :=\np.differentiable.differentiable_on\n\n@[simp] protected lemma deriv : deriv (\u03bbx, p.eval x) x = p.derivative.eval x :=\n(p.has_deriv_at x).deriv\n\nprotected lemma deriv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, p.eval x) s x = p.derivative.eval x :=\nbegin\n  rw differentiable_at.deriv_within p.differentiable_at hxs,\n  exact p.deriv\nend\n\nprotected lemma has_fderiv_at (x : \ud835\udd5c) :\n  has_fderiv_at (\u03bbx, p.eval x) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x)) x :=\np.has_deriv_at x\n\nprotected lemma has_fderiv_within_at (x : \ud835\udd5c) :\n  has_fderiv_within_at (\u03bbx, p.eval x) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x)) s x :=\n(p.has_fderiv_at x).has_fderiv_within_at\n\n@[simp] protected lemma fderiv :\n  fderiv \ud835\udd5c (\u03bbx, p.eval x) x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x) :=\n(p.has_fderiv_at x).fderiv\n\nprotected lemma fderiv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bbx, p.eval x) s x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x) :=\n(p.has_fderiv_within_at x).fderiv_within hxs\n\nend polynomial\n\nsection pow\n/-! ### Derivative of `x \u21a6 x^n` for `n : \u2115` -/\nvariables {x : \ud835\udd5c} {s : set \ud835\udd5c} {c : \ud835\udd5c \u2192 \ud835\udd5c} {c' : \ud835\udd5c}\nvariable (n : \u2115)\n\nlemma has_strict_deriv_at_pow (n : \u2115) (x : \ud835\udd5c) :\n  has_strict_deriv_at (\u03bbx, x^n) ((n : \ud835\udd5c) * x^(n-1)) x :=\nbegin\n  convert (polynomial.C (1 : \ud835\udd5c) * (polynomial.X)^n).has_strict_deriv_at x,\n  { simp },\n  { rw [polynomial.derivative_C_mul_X_pow], simp }\nend\n\nlemma has_deriv_at_pow (n : \u2115) (x : \ud835\udd5c) : has_deriv_at (\u03bbx, x^n) ((n : \ud835\udd5c) * x^(n-1)) x :=\n(has_strict_deriv_at_pow n x).has_deriv_at\n\ntheorem has_deriv_within_at_pow (n : \u2115) (x : \ud835\udd5c) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, x^n) ((n : \ud835\udd5c) * x^(n-1)) s x :=\n(has_deriv_at_pow n x).has_deriv_within_at\n\nlemma differentiable_at_pow : differentiable_at \ud835\udd5c (\u03bbx, x^n) x :=\n(has_deriv_at_pow n x).differentiable_at\n\nlemma differentiable_within_at_pow : differentiable_within_at \ud835\udd5c (\u03bbx, x^n) s x :=\n(differentiable_at_pow n).differentiable_within_at\n\nlemma differentiable_pow : differentiable \ud835\udd5c (\u03bbx:\ud835\udd5c, x^n) :=\n\u03bb x, differentiable_at_pow n\n\nlemma differentiable_on_pow : differentiable_on \ud835\udd5c (\u03bbx, x^n) s :=\n(differentiable_pow n).differentiable_on\n\nlemma deriv_pow : deriv (\u03bb x, x^n) x = (n : \ud835\udd5c) * x^(n-1) :=\n(has_deriv_at_pow n x).deriv\n\n@[simp] lemma deriv_pow' : deriv (\u03bb x, x^n) = \u03bb x, (n : \ud835\udd5c) * x^(n-1) :=\nfunext $ \u03bb x, deriv_pow n\n\nlemma deriv_within_pow (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, x^n) s x = (n : \ud835\udd5c) * x^(n-1) :=\n(has_deriv_within_at_pow n x s).deriv_within hxs\n\nlemma has_deriv_within_at.pow (hc : has_deriv_within_at c c' s x) :\n  has_deriv_within_at (\u03bb y, (c y)^n) ((n : \ud835\udd5c) * (c x)^(n-1) * c') s x :=\n(has_deriv_at_pow n (c x)).comp_has_deriv_within_at x hc\n\nlemma has_deriv_at.pow (hc : has_deriv_at c c' x) :\n  has_deriv_at (\u03bb y, (c y)^n) ((n : \ud835\udd5c) * (c x)^(n-1) * c') x :=\nby { rw \u2190 has_deriv_within_at_univ at *, exact hc.pow n }\n\nlemma deriv_within_pow' (hc : differentiable_within_at \ud835\udd5c c s x)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, (c x)^n) s x = (n : \ud835\udd5c) * (c x)^(n-1) * (deriv_within c s x) :=\n(hc.has_deriv_within_at.pow n).deriv_within hxs\n\n@[simp] lemma deriv_pow'' (hc : differentiable_at \ud835\udd5c c x) :\n  deriv (\u03bbx, (c x)^n) x = (n : \ud835\udd5c) * (c x)^(n-1) * (deriv c x) :=\n(hc.has_deriv_at.pow n).deriv\n\nend pow\n\nsection zpow\n/-! ### Derivative of `x \u21a6 x^m` for `m : \u2124` -/\nvariables {E : Type*} [normed_add_comm_group E] [normed_space \ud835\udd5c E] {x : \ud835\udd5c} {s : set \ud835\udd5c} {m : \u2124}\n\nlemma has_strict_deriv_at_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) :\n  has_strict_deriv_at (\u03bbx, x^m) ((m : \ud835\udd5c) * x^(m-1)) x :=\nbegin\n  have : \u2200 m : \u2124, 0 < m \u2192 has_strict_deriv_at (\u03bbx, x^m) ((m:\ud835\udd5c) * x^(m-1)) x,\n  { assume m hm,\n    lift m to \u2115 using (le_of_lt hm),\n    simp only [zpow_coe_nat, int.cast_coe_nat],\n    convert has_strict_deriv_at_pow _ _ using 2,\n    rw [\u2190 int.coe_nat_one, \u2190 int.coe_nat_sub, zpow_coe_nat],\n    norm_cast at hm,\n    exact nat.succ_le_of_lt hm },\n  rcases lt_trichotomy m 0 with hm|hm|hm,\n  { have hx : x \u2260 0, from h.resolve_right hm.not_le,\n    have := (has_strict_deriv_at_inv _).scomp _ (this (-m) (neg_pos.2 hm));\n      [skip, exact zpow_ne_zero_of_ne_zero hx _],\n    simp only [(\u2218), zpow_neg, one_div, inv_inv, smul_eq_mul] at this,\n    convert this using 1,\n    rw [sq, mul_inv, inv_inv, int.cast_neg, neg_mul, neg_mul_neg,\n      \u2190 zpow_add\u2080 hx, mul_assoc, \u2190 zpow_add\u2080 hx], congr, abel },\n  { simp only [hm, zpow_zero, int.cast_zero, zero_mul, has_strict_deriv_at_const] },\n  { exact this m hm }\nend\n\nlemma has_deriv_at_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) :\n  has_deriv_at (\u03bbx, x^m) ((m : \ud835\udd5c) * x^(m-1)) x :=\n(has_strict_deriv_at_zpow m x h).has_deriv_at\n\ntheorem has_deriv_within_at_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, x^m) ((m : \ud835\udd5c) * x^(m-1)) s x :=\n(has_deriv_at_zpow m x h).has_deriv_within_at\n\nlemma differentiable_at_zpow : differentiable_at \ud835\udd5c (\u03bbx, x^m) x \u2194 x \u2260 0 \u2228 0 \u2264 m :=\n\u27e8\u03bb H, normed_field.continuous_at_zpow.1 H.continuous_at,\n  \u03bb H, (has_deriv_at_zpow m x H).differentiable_at\u27e9\n\nlemma differentiable_within_at_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, x^m) s x :=\n(differentiable_at_zpow.mpr h).differentiable_within_at\n\nlemma differentiable_on_zpow (m : \u2124) (s : set \ud835\udd5c) (h : (0 : \ud835\udd5c) \u2209 s \u2228 0 \u2264 m) :\n  differentiable_on \ud835\udd5c (\u03bbx, x^m) s :=\n\u03bb x hxs, differentiable_within_at_zpow m x $ h.imp_left $ ne_of_mem_of_not_mem hxs\n\nlemma deriv_zpow (m : \u2124) (x : \ud835\udd5c) : deriv (\u03bb x, x ^ m) x = m * x ^ (m - 1) :=\nbegin\n  by_cases H : x \u2260 0 \u2228 0 \u2264 m,\n  { exact (has_deriv_at_zpow m x H).deriv },\n  { rw deriv_zero_of_not_differentiable_at (mt differentiable_at_zpow.1 H),\n    push_neg at H, rcases H with \u27e8rfl, hm\u27e9,\n    rw [zero_zpow _ ((sub_one_lt _).trans hm).ne, mul_zero] }\nend\n\n@[simp] lemma deriv_zpow' (m : \u2124) : deriv (\u03bb x : \ud835\udd5c, x ^ m) = \u03bb x, m * x ^ (m - 1) :=\nfunext $ deriv_zpow m\n\nlemma deriv_within_zpow (hxs : unique_diff_within_at \ud835\udd5c s x) (h : x \u2260 0 \u2228 0 \u2264 m) :\n  deriv_within (\u03bbx, x^m) s x = (m : \ud835\udd5c) * x^(m-1) :=\n(has_deriv_within_at_zpow m x h s).deriv_within hxs\n\n@[simp] lemma iter_deriv_zpow' (m : \u2124) (k : \u2115) :\n  deriv^[k] (\u03bb x : \ud835\udd5c, x ^ m) = \u03bb x, (\u220f i in finset.range k, (m - i)) * x ^ (m - k) :=\nbegin\n  induction k with k ihk,\n  { simp only [one_mul, int.coe_nat_zero, id, sub_zero, finset.prod_range_zero,\n      function.iterate_zero] },\n  { simp only [function.iterate_succ_apply', ihk, deriv_const_mul_field', deriv_zpow',\n      finset.prod_range_succ, int.coe_nat_succ, \u2190 sub_sub, int.cast_sub, int.cast_coe_nat,\n      mul_assoc], }\nend\n\nlemma iter_deriv_zpow (m : \u2124) (x : \ud835\udd5c) (k : \u2115) :\n  deriv^[k] (\u03bb y, y ^ m) x = (\u220f i in finset.range k, (m - i)) * x ^ (m - k) :=\ncongr_fun (iter_deriv_zpow' m k) x\n\nlemma iter_deriv_pow (n : \u2115) (x : \ud835\udd5c) (k : \u2115) :\n  deriv^[k] (\u03bbx:\ud835\udd5c, x^n) x = (\u220f i in finset.range k, (n - i)) * x^(n-k) :=\nbegin\n  simp only [\u2190 zpow_coe_nat, iter_deriv_zpow, int.cast_coe_nat],\n  cases le_or_lt k n with hkn hnk,\n  { rw int.coe_nat_sub hkn },\n  { have : \u220f i in finset.range k, (n - i : \ud835\udd5c) = 0,\n      from finset.prod_eq_zero (finset.mem_range.2 hnk) (sub_self _),\n    simp only [this, zero_mul] }\nend\n\n@[simp] lemma iter_deriv_pow' (n k : \u2115) :\n  deriv^[k] (\u03bb x : \ud835\udd5c, x ^ n) = \u03bb x, (\u220f i in finset.range k, (n - i)) * x ^ (n - k) :=\nfunext $ \u03bb x, iter_deriv_pow n x k\n\nlemma iter_deriv_inv (k : \u2115) (x : \ud835\udd5c) :\n  deriv^[k] has_inv.inv x = (\u220f i in finset.range k, (-1 - i)) * x ^ (-1 - k : \u2124) :=\nby simpa only [zpow_neg_one, int.cast_neg, int.cast_one] using iter_deriv_zpow (-1) x k\n\n@[simp] lemma iter_deriv_inv' (k : \u2115) :\n  deriv^[k] has_inv.inv = \u03bb x : \ud835\udd5c, (\u220f i in finset.range k, (-1 - i)) * x ^ (-1 - k : \u2124) :=\nfunext (iter_deriv_inv k)\n\nvariables {f : E \u2192 \ud835\udd5c} {t : set E} {a : E}\n\nlemma differentiable_within_at.zpow (hf : differentiable_within_at \ud835\udd5c f t a) (h : f a \u2260 0 \u2228 0 \u2264 m) :\n  differentiable_within_at \ud835\udd5c (\u03bb x, f x ^ m) t a :=\n(differentiable_at_zpow.2 h).comp_differentiable_within_at a hf\n\nlemma differentiable_at.zpow (hf : differentiable_at \ud835\udd5c f a) (h : f a \u2260 0 \u2228 0 \u2264 m) :\n  differentiable_at \ud835\udd5c (\u03bb x, f x ^ m) a :=\n(differentiable_at_zpow.2 h).comp a hf\n\nlemma differentiable_on.zpow (hf : differentiable_on \ud835\udd5c f t) (h : (\u2200 x \u2208 t, f x \u2260 0) \u2228 0 \u2264 m) :\n  differentiable_on \ud835\udd5c (\u03bb x, f x ^ m) t :=\n\u03bb x hx, (hf x hx).zpow $ h.imp_left (\u03bb h, h x hx)\n\nlemma differentiable.zpow (hf : differentiable \ud835\udd5c f) (h : (\u2200 x, f x \u2260 0) \u2228 0 \u2264 m) :\n  differentiable \ud835\udd5c (\u03bb x, f x ^ m) :=\n\u03bb x, (hf x).zpow $ h.imp_left (\u03bb h, h x)\n\nend zpow\n\n/-! ### Support of derivatives -/\n\nsection support\n\nopen function\nvariables {F : Type*} [normed_add_comm_group F] [normed_space \ud835\udd5c F] {f : \ud835\udd5c \u2192 F}\n\nlemma support_deriv_subset : support (deriv f) \u2286 tsupport f :=\nbegin\n  intros x,\n  rw [\u2190 not_imp_not],\n  intro h2x,\n  rw [not_mem_tsupport_iff_eventually_eq] at h2x,\n  exact nmem_support.mpr (h2x.deriv_eq.trans (deriv_const x 0))\nend\n\nlemma has_compact_support.deriv (hf : has_compact_support f) : has_compact_support (deriv f) :=\nhf.mono' support_deriv_subset\n\nend support\n\n/-! ### Upper estimates on liminf and limsup -/\n\nsection real\n\nvariables {f : \u211d \u2192 \u211d} {f' : \u211d} {s : set \u211d} {x : \u211d} {r : \u211d}\n\nlemma has_deriv_within_at.limsup_slope_le (hf : has_deriv_within_at f f' s x) (hr : f' < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s \\ {x}] x, slope f x z < r :=\nhas_deriv_within_at_iff_tendsto_slope.1 hf (is_open.mem_nhds is_open_Iio hr)\n\nlemma has_deriv_within_at.limsup_slope_le' (hf : has_deriv_within_at f f' s x)\n  (hs : x \u2209 s) (hr : f' < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s] x, slope f x z < r :=\n(has_deriv_within_at_iff_tendsto_slope' hs).1 hf (is_open.mem_nhds is_open_Iio hr)\n\nlemma has_deriv_within_at.liminf_right_slope_le\n  (hf : has_deriv_within_at f f' (Ici x) x) (hr : f' < r) :\n  \u2203\u1da0 z in \ud835\udcdd[>] x, slope f x z < r :=\n(hf.Ioi_of_Ici.limsup_slope_le' (lt_irrefl x) hr).frequently\n\nend real\n\nsection real_space\n\nopen metric\n\nvariables {E : Type u} [normed_add_comm_group E] [normed_space \u211d E] {f : \u211d \u2192 E} {f' : E} {s : set \u211d}\n  {x r : \u211d}\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`\u2016f z - f x\u2016 / \u2016z - x\u2016` is less than `r` in some neighborhood of `x` within `s`.\nIn other words, the limit superior of this ratio as `z` tends to `x` along `s`\nis less than or equal to `\u2016f'\u2016`. -/\nlemma has_deriv_within_at.limsup_norm_slope_le\n  (hf : has_deriv_within_at f f' s x) (hr : \u2016f'\u2016 < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s] x, \u2016z - x\u2016\u207b\u00b9 * \u2016f z - f x\u2016 < r :=\nbegin\n  have hr\u2080 : 0 < r, from lt_of_le_of_lt (norm_nonneg f') hr,\n  have A : \u2200\u1da0 z in \ud835\udcdd[s \\ {x}] x, \u2016(z - x)\u207b\u00b9 \u2022 (f z - f x)\u2016 \u2208 Iio r,\n    from (has_deriv_within_at_iff_tendsto_slope.1 hf).norm (is_open.mem_nhds is_open_Iio hr),\n  have B : \u2200\u1da0 z in \ud835\udcdd[{x}] x, \u2016(z - x)\u207b\u00b9 \u2022 (f z - f x)\u2016 \u2208 Iio r,\n    from mem_of_superset self_mem_nhds_within\n      (singleton_subset_iff.2 $ by simp [hr\u2080]),\n  have C := mem_sup.2 \u27e8A, B\u27e9,\n  rw [\u2190 nhds_within_union, diff_union_self, nhds_within_union, mem_sup] at C,\n  filter_upwards [C.1],\n  simp only [norm_smul, mem_Iio, norm_inv],\n  exact \u03bb _, id\nend\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`(\u2016f z\u2016 - \u2016f x\u2016) / \u2016z - x\u2016` is less than `r` in some neighborhood of `x` within `s`.\nIn other words, the limit superior of this ratio as `z` tends to `x` along `s`\nis less than or equal to `\u2016f'\u2016`.\n\nThis lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`\nwhere `\u2016f z\u2016 - \u2016f x\u2016` is replaced by `\u2016f z - f x\u2016`. -/\nlemma has_deriv_within_at.limsup_slope_norm_le\n  (hf : has_deriv_within_at f f' s x) (hr : \u2016f'\u2016 < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s] x, \u2016z - x\u2016\u207b\u00b9 * (\u2016f z\u2016 - \u2016f x\u2016) < r :=\nbegin\n  apply (hf.limsup_norm_slope_le hr).mono,\n  assume z hz,\n  refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz,\n  exact inv_nonneg.2 (norm_nonneg _)\nend\n\n/-- If `f` has derivative `f'` within `(x, +\u221e)` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`\u2016f z - f x\u2016 / \u2016z - x\u2016` is frequently less than `r` as `z \u2192 x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `\u2016f'\u2016`. See also `has_deriv_within_at.limsup_norm_slope_le`\nfor a stronger version using limit superior and any set `s`. -/\nlemma has_deriv_within_at.liminf_right_norm_slope_le\n  (hf : has_deriv_within_at f f' (Ici x) x) (hr : \u2016f'\u2016 < r) :\n  \u2203\u1da0 z in \ud835\udcdd[>] x, \u2016z - x\u2016\u207b\u00b9 * \u2016f z - f x\u2016 < r :=\n(hf.Ioi_of_Ici.limsup_norm_slope_le hr).frequently\n\n/-- If `f` has derivative `f'` within `(x, +\u221e)` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`(\u2016f z\u2016 - \u2016f x\u2016) / (z - x)` is frequently less than `r` as `z \u2192 x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `\u2016f'\u2016`.\n\nSee also\n\n* `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using\n  limit superior and any set `s`;\n* `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using\n  `\u2016f z - f x\u2016` instead of `\u2016f z\u2016 - \u2016f x\u2016`. -/\nlemma has_deriv_within_at.liminf_right_slope_norm_le\n  (hf : has_deriv_within_at f f' (Ici x) x) (hr : \u2016f'\u2016 < r) :\n  \u2203\u1da0 z in \ud835\udcdd[>] x, (z - x)\u207b\u00b9 * (\u2016f z\u2016 - \u2016f x\u2016) < r :=\nbegin\n  have := (hf.Ioi_of_Ici.limsup_slope_norm_le hr).frequently,\n  refine this.mp (eventually.mono self_mem_nhds_within _),\n  assume z hxz hz,\n  rwa [real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz\nend\n\nend real_space\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/calculus/deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7362944436248493}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johan Commelin\n\n! This file was ported from Lean 3 source module field_theory.minpoly.basic\n! leanprover-community/mathlib commit 0a6c26ee8a47bd28d7b0bf45ad459eb266e3da48\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Polynomial.FieldDivision\nimport Mathbin.RingTheory.IntegralClosure\n\n/-!\n# Minimal polynomials\n\nThis file defines the minimal polynomial of an element `x` of an `A`-algebra `B`,\nunder the assumption that x is integral over `A`, and derives some basic properties\nsuch as ireducibility under the assumption `B` is a domain.\n\n-/\n\n\nopen Classical Polynomial\n\nopen Polynomial Set Function\n\nvariable {A B : Type _}\n\nsection MinPolyDef\n\nvariable (A) [CommRing A] [Ring B] [Algebra A B]\n\n/-- Suppose `x : B`, where `B` is an `A`-algebra.\n\nThe minimal polynomial `minpoly A x` of `x`\nis a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root,\nif such exists (`is_integral A x`) or zero otherwise.\n\nFor example, if `V` is a `\ud835\udd5c`-vector space for some field `\ud835\udd5c` and `f : V \u2192\u2097[\ud835\udd5c] V` then\nthe minimal polynomial of `f` is `minpoly \ud835\udd5c f`.\n-/\nnoncomputable def minpoly (x : B) : A[X] :=\n  if hx : IsIntegral A x then degree_lt_wf.min _ hx else 0\n#align minpoly minpoly\n\nend MinPolyDef\n\nnamespace minpoly\n\nsection Ring\n\nvariable [CommRing A] [Ring B] [Algebra A B]\n\nvariable {x : B}\n\n/-- A minimal polynomial is monic. -/\ntheorem monic (hx : IsIntegral A x) : Monic (minpoly A x) :=\n  by\n  delta minpoly\n  rw [dif_pos hx]\n  exact (degree_lt_wf.min_mem _ hx).1\n#align minpoly.monic minpoly.monic\n\n/-- A minimal polynomial is nonzero. -/\ntheorem ne_zero [Nontrivial A] (hx : IsIntegral A x) : minpoly A x \u2260 0 :=\n  (monic hx).NeZero\n#align minpoly.ne_zero minpoly.ne_zero\n\ntheorem eq_zero (hx : \u00acIsIntegral A x) : minpoly A x = 0 :=\n  dif_neg hx\n#align minpoly.eq_zero minpoly.eq_zero\n\nvariable (A x)\n\n/-- An element is a root of its minimal polynomial. -/\n@[simp]\ntheorem aeval : aeval x (minpoly A x) = 0 :=\n  by\n  delta minpoly; split_ifs with hx\n  \u00b7 exact (degree_lt_wf.min_mem _ hx).2\n  \u00b7 exact aeval_zero _\n#align minpoly.aeval minpoly.aeval\n\n/-- A minimal polynomial is not `1`. -/\ntheorem ne_one [Nontrivial B] : minpoly A x \u2260 1 :=\n  by\n  intro h\n  refine' (one_ne_zero : (1 : B) \u2260 0) _\n  simpa using congr_arg (Polynomial.aeval x) h\n#align minpoly.ne_one minpoly.ne_one\n\ntheorem map_ne_one [Nontrivial B] {R : Type _} [Semiring R] [Nontrivial R] (f : A \u2192+* R) :\n    (minpoly A x).map f \u2260 1 := by\n  by_cases hx : IsIntegral A x\n  \u00b7 exact mt ((monic hx).eq_one_of_map_eq_one f) (ne_one A x)\n  \u00b7 rw [eq_zero hx, Polynomial.map_zero]\n    exact zero_ne_one\n#align minpoly.map_ne_one minpoly.map_ne_one\n\n/-- A minimal polynomial is not a unit. -/\ntheorem not_isUnit [Nontrivial B] : \u00acIsUnit (minpoly A x) :=\n  by\n  haveI : Nontrivial A := (algebraMap A B).domain_nontrivial\n  by_cases hx : IsIntegral A x\n  \u00b7 exact mt (monic hx).eq_one_of_isUnit (ne_one A x)\n  \u00b7 rw [eq_zero hx]\n    exact not_isUnit_zero\n#align minpoly.not_is_unit minpoly.not_isUnit\n\ntheorem mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) : x \u2208 (algebraMap A B).range :=\n  by\n  have h : IsIntegral A x := by\n    by_contra h\n    rw [eq_zero h, degree_zero, \u2190 WithBot.coe_one] at hx\n    exact ne_of_lt (show \u22a5 < \u21911 from WithBot.bot_lt_coe 1) hx\n  have key := minpoly.aeval A x\n  rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leadingCoeff, C_1, one_mul, aeval_add,\n    aeval_C, aeval_X, \u2190 eq_neg_iff_add_eq_zero, \u2190 RingHom.map_neg] at key\n  exact \u27e8-(minpoly A x).coeff 0, key.symm\u27e9\n#align minpoly.mem_range_of_degree_eq_one minpoly.mem_range_of_degree_eq_one\n\n/-- The defining property of the minimal polynomial of an element `x`:\nit is the monic polynomial with smallest degree that has `x` as its root. -/\ntheorem min {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0) :\n    degree (minpoly A x) \u2264 degree p := by\n  delta minpoly; split_ifs with hx\n  \u00b7 exact le_of_not_lt (degree_lt_wf.not_lt_min _ hx \u27e8pmonic, hp\u27e9)\n  \u00b7 simp only [degree_zero, bot_le]\n#align minpoly.min minpoly.min\n\ntheorem unique' {p : A[X]} (hm : p.Monic) (hp : Polynomial.aeval x p = 0)\n    (hl : \u2200 q : A[X], degree q < degree p \u2192 q = 0 \u2228 Polynomial.aeval x q \u2260 0) : p = minpoly A x :=\n  by\n  nontriviality A\n  have hx : IsIntegral A x := \u27e8p, hm, hp\u27e9\n  obtain h | h := hl _ ((minpoly A x).degree_modByMonic_lt hm)\n  swap\n  \u00b7 exact (h <| (aeval_mod_by_monic_eq_self_of_root hm hp).trans <| aeval A x).elim\n  obtain \u27e8r, hr\u27e9 := (dvd_iff_mod_by_monic_eq_zero hm).1 h\n  rw [hr]\n  have hlead := congr_arg leading_coeff hr\n  rw [mul_comm, leading_coeff_mul_monic hm, (monic hx).leadingCoeff] at hlead\n  have : nat_degree r \u2264 0 :=\n    by\n    have hr0 : r \u2260 0 := by\n      rintro rfl\n      exact NeZero hx (MulZeroClass.mul_zero p \u25b8 hr)\n    apply_fun nat_degree  at hr\n    rw [hm.nat_degree_mul' hr0] at hr\n    apply Nat.le_of_add_le_add_left\n    rw [add_zero]\n    exact hr.symm.trans_le (nat_degree_le_nat_degree <| min A x hm hp)\n  rw [eq_C_of_nat_degree_le_zero this, \u2190 Nat.eq_zero_of_le_zero this, \u2190 leading_coeff, \u2190 hlead, C_1,\n    mul_one]\n#align minpoly.unique' minpoly.unique'\n\n@[nontriviality]\ntheorem subsingleton [Subsingleton B] : minpoly A x = 1 :=\n  by\n  nontriviality A\n  have := minpoly.min A x monic_one (Subsingleton.elim _ _)\n  rw [degree_one] at this\n  cases' le_or_lt (minpoly A x).degree 0 with h h\n  \u00b7 rwa [(monic \u27e81, monic_one, by simp\u27e9 : (minpoly A x).Monic).degree_le_zero_iff_eq_one] at h\n  \u00b7 exact (this.not_lt h).elim\n#align minpoly.subsingleton minpoly.subsingleton\n\nend Ring\n\nsection CommRing\n\nvariable [CommRing A]\n\nsection Ring\n\nvariable [Ring B] [Algebra A B]\n\nvariable {x : B}\n\n/-- The degree of a minimal polynomial, as a natural number, is positive. -/\ntheorem natDegree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < natDegree (minpoly A x) :=\n  by\n  rw [pos_iff_ne_zero]\n  intro ndeg_eq_zero\n  have eq_one : minpoly A x = 1 :=\n    by\n    rw [eq_C_of_nat_degree_eq_zero ndeg_eq_zero]\n    convert C_1\n    simpa only [ndeg_eq_zero.symm] using (monic hx).leadingCoeff\n  simpa only [eq_one, AlgHom.map_one, one_ne_zero] using aeval A x\n#align minpoly.nat_degree_pos minpoly.natDegree_pos\n\n/-- The degree of a minimal polynomial is positive. -/\ntheorem degree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < degree (minpoly A x) :=\n  natDegree_pos_iff_degree_pos.mp (natDegree_pos hx)\n#align minpoly.degree_pos minpoly.degree_pos\n\n/-- If `B/A` is an injective ring extension, and `a` is an element of `A`,\nthen the minimal polynomial of `algebra_map A B a` is `X - C a`. -/\ntheorem eq_x_sub_c_of_algebraMap_inj (a : A) (hf : Function.Injective (algebraMap A B)) :\n    minpoly A (algebraMap A B a) = X - C a :=\n  by\n  nontriviality A\n  refine' (unique' A _ (monic_X_sub_C a) _ _).symm\n  \u00b7 rw [map_sub, aeval_C, aeval_X, sub_self]\n  simp_rw [or_iff_not_imp_left]\n  intro q hl h0\n  rw [\u2190 nat_degree_lt_nat_degree_iff h0, nat_degree_X_sub_C, Nat.lt_one_iff] at hl\n  rw [eq_C_of_nat_degree_eq_zero hl] at h0\u22a2\n  rwa [aeval_C, map_ne_zero_iff _ hf, \u2190 C_ne_zero]\n#align minpoly.eq_X_sub_C_of_algebra_map_inj minpoly.eq_x_sub_c_of_algebraMap_inj\n\nend Ring\n\nsection IsDomain\n\nvariable [Ring B] [Algebra A B]\n\nvariable {x : B}\n\n/-- If `a` strictly divides the minimal polynomial of `x`, then `x` cannot be a root for `a`. -/\ntheorem aeval_ne_zero_of_dvdNotUnit_minpoly {a : A[X]} (hx : IsIntegral A x) (hamonic : a.Monic)\n    (hdvd : DvdNotUnit a (minpoly A x)) : Polynomial.aeval x a \u2260 0 :=\n  by\n  refine' fun ha => (min A x hamonic ha).not_lt (degree_lt_degree _)\n  obtain \u27e8b, c, hu, he\u27e9 := hdvd\n  have hcm := hamonic.of_mul_monic_left (he.subst <| monic hx)\n  rw [he, hamonic.nat_degree_mul hcm]\n  apply Nat.lt_add_of_zero_lt_left _ _ (lt_of_not_le fun h => hu _)\n  rw [eq_C_of_nat_degree_le_zero h, \u2190 Nat.eq_zero_of_le_zero h, \u2190 leading_coeff, hcm.leading_coeff,\n    C_1]\n  exact isUnit_one\n#align minpoly.aeval_ne_zero_of_dvd_not_unit_minpoly minpoly.aeval_ne_zero_of_dvdNotUnit_minpoly\n\nvariable [IsDomain A] [IsDomain B]\n\n/-- A minimal polynomial is irreducible. -/\ntheorem irreducible (hx : IsIntegral A x) : Irreducible (minpoly A x) :=\n  by\n  refine' (irreducible_of_monic (monic hx) <| ne_one A x).2 fun f g hf hg he => _\n  rw [\u2190 hf.is_unit_iff, \u2190 hg.is_unit_iff]\n  by_contra' h\n  have heval := congr_arg (Polynomial.aeval x) he\n  rw [aeval A x, aeval_mul, mul_eq_zero] at heval\n  cases heval\n  \u00b7 exact aeval_ne_zero_of_dvd_not_unit_minpoly hx hf \u27e8hf.ne_zero, g, h.2, he.symm\u27e9 heval\n  \u00b7 refine' aeval_ne_zero_of_dvd_not_unit_minpoly hx hg \u27e8hg.ne_zero, f, h.1, _\u27e9 heval\n    rw [mul_comm, he]\n#align minpoly.irreducible minpoly.irreducible\n\nend IsDomain\n\nend CommRing\n\nend minpoly\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/FieldTheory/Minpoly/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7362944390995957}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module data.polynomial.erase_lead\n! leanprover-community/mathlib commit 69c6a5a12d8a2b159f20933e60115a4f2de62b58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.BigOperators.Fin\nimport Mathbin.Data.Polynomial.Degree.Definitions\n\n/-!\n# Erase the leading term of a univariate polynomial\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Definition\n\n* `erase_lead f`: the polynomial `f - leading term of f`\n\n`erase_lead` serves as reduction step in an induction, shaving off one monomial from a polynomial.\nThe definition is set up so that it does not mention subtraction in the definition,\nand thus works for polynomials over semirings as well as rings.\n-/\n\n\nnoncomputable section\n\nopen Classical Polynomial\n\nopen Polynomial Finset\n\nnamespace Polynomial\n\nvariable {R : Type _} [Semiring R] {f : R[X]}\n\n#print Polynomial.eraseLead /-\n/-- `erase_lead f` for a polynomial `f` is the polynomial obtained by\nsubtracting from `f` the leading term of `f`. -/\ndef eraseLead (f : R[X]) : R[X] :=\n  Polynomial.erase f.natDegree f\n#align polynomial.erase_lead Polynomial.eraseLead\n-/\n\nsection EraseLead\n\n/- warning: polynomial.erase_lead_support -> Polynomial.eraseLead_support is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{1} (Finset.{0} Nat) (Polynomial.support.{u1} R _inst_1 (Polynomial.eraseLead.{u1} R _inst_1 f)) (Finset.erase.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (Polynomial.support.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 f))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{1} (Finset.{0} Nat) (Polynomial.support.{u1} R _inst_1 (Polynomial.eraseLead.{u1} R _inst_1 f)) (Finset.erase.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (Polynomial.support.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 f))\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_support Polynomial.eraseLead_support\u2093'. -/\ntheorem eraseLead_support (f : R[X]) : f.eraseLead.support = f.support.erase\u2093 f.natDegree := by\n  simp only [erase_lead, support_erase]\n#align polynomial.erase_lead_support Polynomial.eraseLead_support\n\n/- warning: polynomial.erase_lead_coeff -> Polynomial.eraseLead_coeff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1} (i : Nat), Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (Polynomial.eraseLead.{u1} R _inst_1 f) i) (ite.{succ u1} R (Eq.{1} Nat i (Polynomial.natDegree.{u1} R _inst_1 f)) (Nat.decidableEq i (Polynomial.natDegree.{u1} R _inst_1 f)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))) (Polynomial.coeff.{u1} R _inst_1 f i))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1} (i : Nat), Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (Polynomial.eraseLead.{u1} R _inst_1 f) i) (ite.{succ u1} R (Eq.{1} Nat i (Polynomial.natDegree.{u1} R _inst_1 f)) (instDecidableEqNat i (Polynomial.natDegree.{u1} R _inst_1 f)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (Polynomial.coeff.{u1} R _inst_1 f i))\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_coeff Polynomial.eraseLead_coeff\u2093'. -/\ntheorem eraseLead_coeff (i : \u2115) : f.eraseLead.coeff i = if i = f.natDegree then 0 else f.coeff i :=\n  by simp only [erase_lead, coeff_erase]\n#align polynomial.erase_lead_coeff Polynomial.eraseLead_coeff\n\n/- warning: polynomial.erase_lead_coeff_nat_degree -> Polynomial.eraseLead_coeff_natDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (Polynomial.eraseLead.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 f)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (Polynomial.eraseLead.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 f)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_coeff_nat_degree Polynomial.eraseLead_coeff_natDegree\u2093'. -/\n@[simp]\ntheorem eraseLead_coeff_natDegree : f.eraseLead.coeff f.natDegree = 0 := by simp [erase_lead_coeff]\n#align polynomial.erase_lead_coeff_nat_degree Polynomial.eraseLead_coeff_natDegree\n\n#print Polynomial.eraseLead_coeff_of_ne /-\ntheorem eraseLead_coeff_of_ne (i : \u2115) (hi : i \u2260 f.natDegree) : f.eraseLead.coeff i = f.coeff i := by\n  simp [erase_lead_coeff, hi]\n#align polynomial.erase_lead_coeff_of_ne Polynomial.eraseLead_coeff_of_ne\n-/\n\n#print Polynomial.eraseLead_zero /-\n@[simp]\ntheorem eraseLead_zero : eraseLead (0 : R[X]) = 0 := by simp only [erase_lead, erase_zero]\n#align polynomial.erase_lead_zero Polynomial.eraseLead_zero\n-/\n\n/- warning: polynomial.erase_lead_add_monomial_nat_degree_leading_coeff -> Polynomial.eraseLead_add_monomial_natDegree_leadingCoeff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) (Polynomial.eraseLead.{u1} R _inst_1 f) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 (Polynomial.natDegree.{u1} R _inst_1 f)) (Polynomial.leadingCoeff.{u1} R _inst_1 f))) f\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) (Polynomial.leadingCoeff.{u1} R _inst_1 f)) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) (Polynomial.eraseLead.{u1} R _inst_1 f) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 (Polynomial.natDegree.{u1} R _inst_1 f)) (Polynomial.leadingCoeff.{u1} R _inst_1 f))) f\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_add_monomial_nat_degree_leading_coeff Polynomial.eraseLead_add_monomial_natDegree_leadingCoeff\u2093'. -/\n@[simp]\ntheorem eraseLead_add_monomial_natDegree_leadingCoeff (f : R[X]) :\n    f.eraseLead + monomial f.natDegree f.leadingCoeff = f :=\n  (add_comm _ _).trans (f.monomial_add_erase _)\n#align polynomial.erase_lead_add_monomial_nat_degree_leading_coeff Polynomial.eraseLead_add_monomial_natDegree_leadingCoeff\n\n/- warning: polynomial.erase_lead_add_C_mul_X_pow -> Polynomial.eraseLead_add_C_mul_X_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) (Polynomial.eraseLead.{u1} R _inst_1 f) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) (Polynomial.leadingCoeff.{u1} R _inst_1 f)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) (Polynomial.natDegree.{u1} R _inst_1 f)))) f\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (Polynomial.leadingCoeff.{u1} R _inst_1 f)) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) (Polynomial.eraseLead.{u1} R _inst_1 f) (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (Polynomial.leadingCoeff.{u1} R _inst_1 f)) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (Polynomial.leadingCoeff.{u1} R _inst_1 f)) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (Polynomial.leadingCoeff.{u1} R _inst_1 f)) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) (Polynomial.leadingCoeff.{u1} R _inst_1 f)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) (Polynomial.natDegree.{u1} R _inst_1 f)))) f\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_add_C_mul_X_pow Polynomial.eraseLead_add_C_mul_X_pow\u2093'. -/\n@[simp]\ntheorem eraseLead_add_C_mul_X_pow (f : R[X]) :\n    f.eraseLead + C f.leadingCoeff * X ^ f.natDegree = f := by\n  rw [C_mul_X_pow_eq_monomial, erase_lead_add_monomial_nat_degree_leading_coeff]\n#align polynomial.erase_lead_add_C_mul_X_pow Polynomial.eraseLead_add_C_mul_X_pow\n\n/- warning: polynomial.self_sub_monomial_nat_degree_leading_coeff -> Polynomial.self_sub_monomial_natDegree_leadingCoeff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_2 : Ring.{u1} R] (f : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)), Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.sub.{u1} R _inst_2)) f (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R (Ring.toSemiring.{u1} R _inst_2) (Ring.toSemiring.{u1} R _inst_2) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R _inst_2) R (Ring.toSemiring.{u1} R _inst_2) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R (Ring.toSemiring.{u1} R _inst_2) (Ring.toSemiring.{u1} R _inst_2) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R _inst_2) R (Ring.toSemiring.{u1} R _inst_2) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Ring.toSemiring.{u1} R _inst_2) (Ring.toSemiring.{u1} R _inst_2) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R _inst_2) R (Ring.toSemiring.{u1} R _inst_2) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (Polynomial.monomial.{u1} R (Ring.toSemiring.{u1} R _inst_2) (Polynomial.natDegree.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f))) (Polynomial.eraseLead.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_2 : Ring.{u1} R] (f : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)), Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.sub.{u1} R _inst_2)) f (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R (Ring.toSemiring.{u1} R _inst_2) (Ring.toSemiring.{u1} R _inst_2) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R _inst_2) R (Ring.toSemiring.{u1} R _inst_2) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Ring.toSemiring.{u1} R _inst_2) (Ring.toSemiring.{u1} R _inst_2) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R _inst_2) R (Ring.toSemiring.{u1} R _inst_2) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (Polynomial.monomial.{u1} R (Ring.toSemiring.{u1} R _inst_2) (Polynomial.natDegree.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f))) (Polynomial.eraseLead.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)\nCase conversion may be inaccurate. Consider using '#align polynomial.self_sub_monomial_nat_degree_leading_coeff Polynomial.self_sub_monomial_natDegree_leadingCoeff\u2093'. -/\n@[simp]\ntheorem self_sub_monomial_natDegree_leadingCoeff {R : Type _} [Ring R] (f : R[X]) :\n    f - monomial f.natDegree f.leadingCoeff = f.eraseLead :=\n  (eq_sub_iff_add_eq.mpr (eraseLead_add_monomial_natDegree_leadingCoeff f)).symm\n#align polynomial.self_sub_monomial_nat_degree_leading_coeff Polynomial.self_sub_monomial_natDegree_leadingCoeff\n\n/- warning: polynomial.self_sub_C_mul_X_pow -> Polynomial.self_sub_C_mul_X_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_2 : Ring.{u1} R] (f : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)), Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.sub.{u1} R _inst_2)) f (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (instHMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) Nat (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (instHPow.{u1, 0} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Ring.toMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.ring.{u1} R _inst_2)))) (Polynomial.X.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.natDegree.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)))) (Polynomial.eraseLead.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_2 : Ring.{u1} R] (f : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)), Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.sub.{u1} R _inst_2)) f (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.leadingCoeff.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) Nat (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (instHPow.{u1, 0} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R _inst_2)))))) (Polynomial.X.{u1} R (Ring.toSemiring.{u1} R _inst_2)) (Polynomial.natDegree.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)))) (Polynomial.eraseLead.{u1} R (Ring.toSemiring.{u1} R _inst_2) f)\nCase conversion may be inaccurate. Consider using '#align polynomial.self_sub_C_mul_X_pow Polynomial.self_sub_C_mul_X_pow\u2093'. -/\n@[simp]\ntheorem self_sub_C_mul_X_pow {R : Type _} [Ring R] (f : R[X]) :\n    f - C f.leadingCoeff * X ^ f.natDegree = f.eraseLead := by\n  rw [C_mul_X_pow_eq_monomial, self_sub_monomial_nat_degree_leading_coeff]\n#align polynomial.self_sub_C_mul_X_pow Polynomial.self_sub_C_mul_X_pow\n\n#print Polynomial.eraseLead_ne_zero /-\ntheorem eraseLead_ne_zero (f0 : 2 \u2264 f.support.card) : eraseLead f \u2260 0 :=\n  by\n  rw [Ne, \u2190 card_support_eq_zero, erase_lead_support]\n  exact\n    (zero_lt_one.trans_le <| (tsub_le_tsub_right f0 1).trans Finset.pred_card_le_card_erase).Ne.symm\n#align polynomial.erase_lead_ne_zero Polynomial.eraseLead_ne_zero\n-/\n\n#print Polynomial.lt_natDegree_of_mem_eraseLead_support /-\ntheorem lt_natDegree_of_mem_eraseLead_support {a : \u2115} (h : a \u2208 (eraseLead f).support) :\n    a < f.natDegree := by\n  rw [erase_lead_support, mem_erase] at h\n  exact (le_nat_degree_of_mem_supp a h.2).lt_of_ne h.1\n#align polynomial.lt_nat_degree_of_mem_erase_lead_support Polynomial.lt_natDegree_of_mem_eraseLead_support\n-/\n\n#print Polynomial.ne_natDegree_of_mem_eraseLead_support /-\ntheorem ne_natDegree_of_mem_eraseLead_support {a : \u2115} (h : a \u2208 (eraseLead f).support) :\n    a \u2260 f.natDegree :=\n  (lt_natDegree_of_mem_eraseLead_support h).Ne\n#align polynomial.ne_nat_degree_of_mem_erase_lead_support Polynomial.ne_natDegree_of_mem_eraseLead_support\n-/\n\n#print Polynomial.natDegree_not_mem_eraseLead_support /-\ntheorem natDegree_not_mem_eraseLead_support : f.natDegree \u2209 (eraseLead f).support := fun h =>\n  ne_natDegree_of_mem_eraseLead_support h rfl\n#align polynomial.nat_degree_not_mem_erase_lead_support Polynomial.natDegree_not_mem_eraseLead_support\n-/\n\n#print Polynomial.eraseLead_support_card_lt /-\ntheorem eraseLead_support_card_lt (h : f \u2260 0) : (eraseLead f).support.card < f.support.card :=\n  by\n  rw [erase_lead_support]\n  exact card_lt_card (erase_ssubset <| nat_degree_mem_support_of_nonzero h)\n#align polynomial.erase_lead_support_card_lt Polynomial.eraseLead_support_card_lt\n-/\n\n#print Polynomial.eraseLead_card_support /-\ntheorem eraseLead_card_support {c : \u2115} (fc : f.support.card = c) :\n    f.eraseLead.support.card = c - 1 := by\n  by_cases f0 : f = 0\n  \u00b7 rw [\u2190 fc, f0, erase_lead_zero, support_zero, card_empty]\n  \u00b7 rw [erase_lead_support, card_erase_of_mem (nat_degree_mem_support_of_nonzero f0), fc]\n#align polynomial.erase_lead_card_support Polynomial.eraseLead_card_support\n-/\n\n#print Polynomial.eraseLead_card_support' /-\ntheorem eraseLead_card_support' {c : \u2115} (fc : f.support.card = c + 1) :\n    f.eraseLead.support.card = c :=\n  eraseLead_card_support fc\n#align polynomial.erase_lead_card_support' Polynomial.eraseLead_card_support'\n-/\n\n/- warning: polynomial.erase_lead_monomial -> Polynomial.eraseLead_monomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (i : Nat) (r : R), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.eraseLead.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 i) r)) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (i : Nat) (r : R), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.eraseLead.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 i) r)) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_monomial Polynomial.eraseLead_monomial\u2093'. -/\n@[simp]\ntheorem eraseLead_monomial (i : \u2115) (r : R) : eraseLead (monomial i r) = 0 :=\n  by\n  by_cases hr : r = 0\n  \u00b7 subst r\n    simp only [monomial_zero_right, erase_lead_zero]\n  \u00b7 rw [erase_lead, nat_degree_monomial, if_neg hr, erase_monomial]\n#align polynomial.erase_lead_monomial Polynomial.eraseLead_monomial\n\n/- warning: polynomial.erase_lead_C -> Polynomial.eraseLead_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (r : R), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.eraseLead.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) r)) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (r : R), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.eraseLead.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) r)) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_C Polynomial.eraseLead_C\u2093'. -/\n@[simp]\ntheorem eraseLead_C (r : R) : eraseLead (C r) = 0 :=\n  eraseLead_monomial _ _\n#align polynomial.erase_lead_C Polynomial.eraseLead_C\n\n#print Polynomial.eraseLead_X /-\n@[simp]\ntheorem eraseLead_X : eraseLead (X : R[X]) = 0 :=\n  eraseLead_monomial _ _\n#align polynomial.erase_lead_X Polynomial.eraseLead_X\n-/\n\n#print Polynomial.eraseLead_X_pow /-\n@[simp]\ntheorem eraseLead_X_pow (n : \u2115) : eraseLead (X ^ n : R[X]) = 0 := by\n  rw [X_pow_eq_monomial, erase_lead_monomial]\n#align polynomial.erase_lead_X_pow Polynomial.eraseLead_X_pow\n-/\n\n/- warning: polynomial.erase_lead_C_mul_X_pow -> Polynomial.eraseLead_C_mul_X_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (r : R) (n : Nat), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.eraseLead.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) r) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n))) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (r : R) (n : Nat), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.eraseLead.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) r) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) r) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) r) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n))) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))\nCase conversion may be inaccurate. Consider using '#align polynomial.erase_lead_C_mul_X_pow Polynomial.eraseLead_C_mul_X_pow\u2093'. -/\n@[simp]\ntheorem eraseLead_C_mul_X_pow (r : R) (n : \u2115) : eraseLead (C r * X ^ n) = 0 := by\n  rw [C_mul_X_pow_eq_monomial, erase_lead_monomial]\n#align polynomial.erase_lead_C_mul_X_pow Polynomial.eraseLead_C_mul_X_pow\n\n#print Polynomial.eraseLead_add_of_natDegree_lt_left /-\ntheorem eraseLead_add_of_natDegree_lt_left {p q : R[X]} (pq : q.natDegree < p.natDegree) :\n    (p + q).eraseLead = p.eraseLead + q := by\n  ext n\n  by_cases nd : n = p.nat_degree\n  \u00b7 rw [nd, erase_lead_coeff, if_pos (nat_degree_add_eq_left_of_nat_degree_lt pq).symm]\n    simpa using (coeff_eq_zero_of_nat_degree_lt pq).symm\n  \u00b7 rw [erase_lead_coeff, coeff_add, coeff_add, erase_lead_coeff, if_neg, if_neg nd]\n    rintro rfl\n    exact nd (nat_degree_add_eq_left_of_nat_degree_lt pq)\n#align polynomial.erase_lead_add_of_nat_degree_lt_left Polynomial.eraseLead_add_of_natDegree_lt_left\n-/\n\n#print Polynomial.eraseLead_add_of_natDegree_lt_right /-\ntheorem eraseLead_add_of_natDegree_lt_right {p q : R[X]} (pq : p.natDegree < q.natDegree) :\n    (p + q).eraseLead = p + q.eraseLead := by\n  ext n\n  by_cases nd : n = q.nat_degree\n  \u00b7 rw [nd, erase_lead_coeff, if_pos (nat_degree_add_eq_right_of_nat_degree_lt pq).symm]\n    simpa using (coeff_eq_zero_of_nat_degree_lt pq).symm\n  \u00b7 rw [erase_lead_coeff, coeff_add, coeff_add, erase_lead_coeff, if_neg, if_neg nd]\n    rintro rfl\n    exact nd (nat_degree_add_eq_right_of_nat_degree_lt pq)\n#align polynomial.erase_lead_add_of_nat_degree_lt_right Polynomial.eraseLead_add_of_natDegree_lt_right\n-/\n\n#print Polynomial.eraseLead_degree_le /-\ntheorem eraseLead_degree_le : (eraseLead f).degree \u2264 f.degree :=\n  f.degree_erase_le _\n#align polynomial.erase_lead_degree_le Polynomial.eraseLead_degree_le\n-/\n\n#print Polynomial.eraseLead_natDegree_le_aux /-\ntheorem eraseLead_natDegree_le_aux : (eraseLead f).natDegree \u2264 f.natDegree :=\n  natDegree_le_natDegree eraseLead_degree_le\n#align polynomial.erase_lead_nat_degree_le_aux Polynomial.eraseLead_natDegree_le_aux\n-/\n\n#print Polynomial.eraseLead_natDegree_lt /-\ntheorem eraseLead_natDegree_lt (f0 : 2 \u2264 f.support.card) : (eraseLead f).natDegree < f.natDegree :=\n  lt_of_le_of_ne eraseLead_natDegree_le_aux <|\n    ne_natDegree_of_mem_eraseLead_support <|\n      natDegree_mem_support_of_nonzero <| eraseLead_ne_zero f0\n#align polynomial.erase_lead_nat_degree_lt Polynomial.eraseLead_natDegree_lt\n-/\n\n#print Polynomial.eraseLead_natDegree_lt_or_eraseLead_eq_zero /-\ntheorem eraseLead_natDegree_lt_or_eraseLead_eq_zero (f : R[X]) :\n    (eraseLead f).natDegree < f.natDegree \u2228 f.eraseLead = 0 :=\n  by\n  by_cases h : f.support.card \u2264 1\n  \u00b7 right\n    rw [\u2190 C_mul_X_pow_eq_self h]\n    simp\n  \u00b7 left\n    apply erase_lead_nat_degree_lt (lt_of_not_ge h)\n#align polynomial.erase_lead_nat_degree_lt_or_erase_lead_eq_zero Polynomial.eraseLead_natDegree_lt_or_eraseLead_eq_zero\n-/\n\n#print Polynomial.eraseLead_natDegree_le /-\ntheorem eraseLead_natDegree_le (f : R[X]) : (eraseLead f).natDegree \u2264 f.natDegree - 1 :=\n  by\n  rcases f.erase_lead_nat_degree_lt_or_erase_lead_eq_zero with (h | h)\n  \u00b7 exact Nat.le_pred_of_lt h\n  \u00b7 simp only [h, nat_degree_zero, zero_le]\n#align polynomial.erase_lead_nat_degree_le Polynomial.eraseLead_natDegree_le\n-/\n\nend EraseLead\n\n/- warning: polynomial.induction_with_nat_degree_le -> Polynomial.induction_with_natDegree_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (P : (Polynomial.{u1} R _inst_1) -> Prop) (N : Nat), (P (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))) -> (forall (n : Nat) (r : R), (Ne.{succ u1} R r (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (LE.le.{0} Nat Nat.hasLe n N) -> (P (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) r) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n)))) -> (forall (f : Polynomial.{u1} R _inst_1) (g : Polynomial.{u1} R _inst_1), (LT.lt.{0} Nat Nat.hasLt (Polynomial.natDegree.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 g)) -> (LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 g) N) -> (P f) -> (P g) -> (P (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) f g))) -> (forall (f : Polynomial.{u1} R _inst_1), (LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 f) N) -> (P f))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (P : (Polynomial.{u1} R _inst_1) -> Prop) (N : Nat), (P (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))) -> (forall (n : Nat) (r : R), (Ne.{succ u1} R r (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (LE.le.{0} Nat instLENat n N) -> (P (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) r) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) r) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) r) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n)))) -> (forall (f : Polynomial.{u1} R _inst_1) (g : Polynomial.{u1} R _inst_1), (LT.lt.{0} Nat instLTNat (Polynomial.natDegree.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 g)) -> (LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 g) N) -> (P f) -> (P g) -> (P (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) f g))) -> (forall (f : Polynomial.{u1} R _inst_1), (LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 f) N) -> (P f))\nCase conversion may be inaccurate. Consider using '#align polynomial.induction_with_nat_degree_le Polynomial.induction_with_natDegree_le\u2093'. -/\n/-- An induction lemma for polynomials. It takes a natural number `N` as a parameter, that is\nrequired to be at least as big as the `nat_degree` of the polynomial.  This is useful to prove\nresults where you want to change each term in a polynomial to something else depending on the\n`nat_degree` of the polynomial itself and not on the specific `nat_degree` of each term. -/\ntheorem induction_with_natDegree_le (P : R[X] \u2192 Prop) (N : \u2115) (P_0 : P 0)\n    (P_C_mul_pow : \u2200 n : \u2115, \u2200 r : R, r \u2260 0 \u2192 n \u2264 N \u2192 P (C r * X ^ n))\n    (P_C_add : \u2200 f g : R[X], f.natDegree < g.natDegree \u2192 g.natDegree \u2264 N \u2192 P f \u2192 P g \u2192 P (f + g)) :\n    \u2200 f : R[X], f.natDegree \u2264 N \u2192 P f := by\n  intro f df\n  generalize hd : card f.support = c\n  revert f\n  induction' c with c hc\n  \u00b7 intro f df f0\n    convert P_0\n    simpa only [support_eq_empty, card_eq_zero] using f0\n  \u00b7 intro f df f0\n    rw [\u2190 erase_lead_add_C_mul_X_pow f]\n    cases c\n    \u00b7 convert P_C_mul_pow f.nat_degree f.leading_coeff _ df\n      \u00b7 convert zero_add _\n        rw [\u2190 card_support_eq_zero, erase_lead_card_support f0]\n      \u00b7 rw [leading_coeff_ne_zero, Ne.def, \u2190 card_support_eq_zero, f0]\n        exact zero_ne_one.symm\n    refine' P_C_add f.erase_lead _ _ _ _ _\n    \u00b7 refine' (erase_lead_nat_degree_lt _).trans_le (le_of_eq _)\n      \u00b7 exact (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))).trans f0.ge\n      \u00b7 rw [nat_degree_C_mul_X_pow _ _ (leading_coeff_ne_zero.mpr _)]\n        rintro rfl\n        simpa using f0\n    \u00b7 exact (nat_degree_C_mul_X_pow_le f.leading_coeff f.nat_degree).trans df\n    \u00b7 exact hc _ (erase_lead_nat_degree_le_aux.trans df) (erase_lead_card_support f0)\n    \u00b7 refine' P_C_mul_pow _ _ _ df\n      rw [Ne.def, leading_coeff_eq_zero, \u2190 card_support_eq_zero, f0]\n      exact Nat.succ_ne_zero _\n#align polynomial.induction_with_nat_degree_le Polynomial.induction_with_natDegree_le\n\n/- warning: polynomial.mono_map_nat_degree_eq -> Polynomial.mono_map_natDegree_eq is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {S : Type.{u2}} {F : Type.{u3}} [_inst_2 : Semiring.{u2} S] [_inst_3 : AddMonoidHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))] {\u03c6 : F} {p : Polynomial.{u1} R _inst_1} (k : Nat) (fu : Nat -> Nat), (forall {n : Nat}, (LE.le.{0} Nat Nat.hasLe n k) -> (Eq.{1} Nat (fu n) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))))) -> (forall {n : Nat} {m : Nat}, (LE.le.{0} Nat Nat.hasLe k n) -> (LT.lt.{0} Nat Nat.hasLt n m) -> (LT.lt.{0} Nat Nat.hasLt (fu n) (fu m))) -> (forall {f : Polynomial.{u1} R _inst_1}, (LT.lt.{0} Nat Nat.hasLt (Polynomial.natDegree.{u1} R _inst_1 f) k) -> (Eq.{succ u2} (Polynomial.{u2} S _inst_2) (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 f) (OfNat.ofNat.{u2} (Polynomial.{u2} S _inst_2) 0 (OfNat.mk.{u2} (Polynomial.{u2} S _inst_2) 0 (Zero.zero.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.zero.{u2} S _inst_2)))))) -> (forall (n : Nat) (c : R), (Ne.{succ u1} R c (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u2} S _inst_2 (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) c))) (fu n))) -> (Eq.{1} Nat (Polynomial.natDegree.{u2} S _inst_2 (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 p)) (fu (Polynomial.natDegree.{u1} R _inst_1 p)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {S : Type.{u3}} {F : Type.{u2}} [_inst_2 : Semiring.{u3} S] [_inst_3 : AddMonoidHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))] {\u03c6 : F} {p : Polynomial.{u1} R _inst_1} (k : Nat) (fu : Nat -> Nat), (forall {n : Nat}, (LE.le.{0} Nat instLENat n k) -> (Eq.{1} Nat (fu n) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))) -> (forall {n : Nat} {m : Nat}, (LE.le.{0} Nat instLENat k n) -> (LT.lt.{0} Nat instLTNat n m) -> (LT.lt.{0} Nat instLTNat (fu n) (fu m))) -> (forall {f : Polynomial.{u1} R _inst_1}, (LT.lt.{0} Nat instLTNat (Polynomial.natDegree.{u1} R _inst_1 f) k) -> (Eq.{succ u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) f) (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 f) (OfNat.ofNat.{u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) f) 0 (Zero.toOfNat0.{u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) f) (Polynomial.zero.{u3} S _inst_2))))) -> (forall (n : Nat) (c : R), (Ne.{succ u1} R c (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u3} S _inst_2 (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) c))) (fu n))) -> (Eq.{1} Nat (Polynomial.natDegree.{u3} S _inst_2 (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 p)) (fu (Polynomial.natDegree.{u1} R _inst_1 p)))\nCase conversion may be inaccurate. Consider using '#align polynomial.mono_map_nat_degree_eq Polynomial.mono_map_natDegree_eq\u2093'. -/\n/-- Let `\u03c6 : R[x] \u2192 S[x]` be an additive map, `k : \u2115` a bound, and `fu : \u2115 \u2192 \u2115` a\n\"sufficiently monotone\" map.  Assume also that\n* `\u03c6` maps to `0` all monomials of degree less than `k`,\n* `\u03c6` maps each monomial `m` in `R[x]` to a polynomial `\u03c6 m` of degree `fu (deg m)`.\nThen, `\u03c6` maps each polynomial `p` in `R[x]` to a polynomial of degree `fu (deg p)`. -/\ntheorem mono_map_natDegree_eq {S F : Type _} [Semiring S] [AddMonoidHomClass F R[X] S[X]] {\u03c6 : F}\n    {p : R[X]} (k : \u2115) (fu : \u2115 \u2192 \u2115) (fu0 : \u2200 {n}, n \u2264 k \u2192 fu n = 0)\n    (fc : \u2200 {n m}, k \u2264 n \u2192 n < m \u2192 fu n < fu m) (\u03c6_k : \u2200 {f : R[X]}, f.natDegree < k \u2192 \u03c6 f = 0)\n    (\u03c6_mon_nat : \u2200 n c, c \u2260 0 \u2192 (\u03c6 (monomial n c)).natDegree = fu n) :\n    (\u03c6 p).natDegree = fu p.natDegree :=\n  by\n  refine' induction_with_nat_degree_le (fun p => _ = fu _) p.nat_degree (by simp [fu0]) _ _ _ rfl.le\n  \u00b7 intro n r r0 np\n    rw [nat_degree_C_mul_X_pow _ _ r0, C_mul_X_pow_eq_monomial, \u03c6_mon_nat _ _ r0]\n  \u00b7 intro f g fg gp fk gk\n    rw [nat_degree_add_eq_right_of_nat_degree_lt fg, _root_.map_add]\n    by_cases FG : k \u2264 f.nat_degree\n    \u00b7 rw [nat_degree_add_eq_right_of_nat_degree_lt, gk]\n      rw [fk, gk]\n      exact fc FG fg\n    \u00b7 cases k\n      \u00b7 exact (FG (Nat.zero_le _)).elim\n      \u00b7 rwa [\u03c6_k (not_le.mp FG), zero_add]\n#align polynomial.mono_map_nat_degree_eq Polynomial.mono_map_natDegree_eq\n\n/- warning: polynomial.map_nat_degree_eq_sub -> Polynomial.map_natDegree_eq_sub is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {S : Type.{u2}} {F : Type.{u3}} [_inst_2 : Semiring.{u2} S] [_inst_3 : AddMonoidHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))] {\u03c6 : F} {p : Polynomial.{u1} R _inst_1} {k : Nat}, (forall (f : Polynomial.{u1} R _inst_1), (LT.lt.{0} Nat Nat.hasLt (Polynomial.natDegree.{u1} R _inst_1 f) k) -> (Eq.{succ u2} (Polynomial.{u2} S _inst_2) (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 f) (OfNat.ofNat.{u2} (Polynomial.{u2} S _inst_2) 0 (OfNat.mk.{u2} (Polynomial.{u2} S _inst_2) 0 (Zero.zero.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.zero.{u2} S _inst_2)))))) -> (forall (n : Nat) (c : R), (Ne.{succ u1} R c (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u2} S _inst_2 (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) c))) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n k))) -> (Eq.{1} Nat (Polynomial.natDegree.{u2} S _inst_2 (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 p)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (Polynomial.natDegree.{u1} R _inst_1 p) k))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {S : Type.{u3}} {F : Type.{u2}} [_inst_2 : Semiring.{u3} S] [_inst_3 : AddMonoidHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))] {\u03c6 : F} {p : Polynomial.{u1} R _inst_1} {k : Nat}, (forall (f : Polynomial.{u1} R _inst_1), (LT.lt.{0} Nat instLTNat (Polynomial.natDegree.{u1} R _inst_1 f) k) -> (Eq.{succ u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) f) (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 f) (OfNat.ofNat.{u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) f) 0 (Zero.toOfNat0.{u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) f) (Polynomial.zero.{u3} S _inst_2))))) -> (forall (n : Nat) (c : R), (Ne.{succ u1} R c (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u3} S _inst_2 (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) c))) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n k))) -> (Eq.{1} Nat (Polynomial.natDegree.{u3} S _inst_2 (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 p)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) (Polynomial.natDegree.{u1} R _inst_1 p) k))\nCase conversion may be inaccurate. Consider using '#align polynomial.map_nat_degree_eq_sub Polynomial.map_natDegree_eq_sub\u2093'. -/\ntheorem map_natDegree_eq_sub {S F : Type _} [Semiring S] [AddMonoidHomClass F R[X] S[X]] {\u03c6 : F}\n    {p : R[X]} {k : \u2115} (\u03c6_k : \u2200 f : R[X], f.natDegree < k \u2192 \u03c6 f = 0)\n    (\u03c6_mon : \u2200 n c, c \u2260 0 \u2192 (\u03c6 (monomial n c)).natDegree = n - k) :\n    (\u03c6 p).natDegree = p.natDegree - k :=\n  mono_map_natDegree_eq k (fun j => j - k) (by simp) (fun m n h => (tsub_lt_tsub_iff_right h).mpr)\n    \u03c6_k \u03c6_mon\n#align polynomial.map_nat_degree_eq_sub Polynomial.map_natDegree_eq_sub\n\n/- warning: polynomial.map_nat_degree_eq_nat_degree -> Polynomial.map_natDegree_eq_natDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {S : Type.{u2}} {F : Type.{u3}} [_inst_2 : Semiring.{u2} S] [_inst_3 : AddMonoidHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))] {\u03c6 : F} (p : Polynomial.{u1} R _inst_1), (forall (n : Nat) (c : R), (Ne.{succ u1} R c (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u2} S _inst_2 (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) c))) n)) -> (Eq.{1} Nat (Polynomial.natDegree.{u2} S _inst_2 (coeFn.{succ u3, max (succ u1) (succ u2)} F (fun (_x : F) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u2} S _inst_2)) (FunLike.hasCoeToFun.{succ u3, succ u1, succ u2} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => Polynomial.{u2} S _inst_2) (AddHomClass.toFunLike.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddZeroClass.toHasAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toHasAdd.{u2} (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u3, u1, u2} F (Polynomial.{u1} R _inst_1) (Polynomial.{u2} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u2} (Polynomial.{u2} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u2} (Polynomial.{u2} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u2} (Polynomial.{u2} S _inst_2) (Semiring.toNonAssocSemiring.{u2} (Polynomial.{u2} S _inst_2) (Polynomial.semiring.{u2} S _inst_2)))))) _inst_3))) \u03c6 p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {S : Type.{u3}} {F : Type.{u2}} [_inst_2 : Semiring.{u3} S] [_inst_3 : AddMonoidHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))] {\u03c6 : F} (p : Polynomial.{u1} R _inst_1), (forall (n : Nat) (c : R), (Ne.{succ u1} R c (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u3} S _inst_2 (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) c))) n)) -> (Eq.{1} Nat (Polynomial.natDegree.{u3} S _inst_2 (FunLike.coe.{succ u2, succ u1, succ u3} F (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Polynomial.{u1} R _inst_1) => Polynomial.{u3} S _inst_2) _x) (AddHomClass.toFunLike.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddZeroClass.toAdd.{u1} (Polynomial.{u1} R _inst_1) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))))) (AddZeroClass.toAdd.{u3} (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2))))))) (AddMonoidHomClass.toAddHomClass.{u2, u1, u3} F (Polynomial.{u1} R _inst_1) (Polynomial.{u3} S _inst_2) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R _inst_1) (AddMonoidWithOne.toAddMonoid.{u1} (Polynomial.{u1} R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (AddMonoid.toAddZeroClass.{u3} (Polynomial.{u3} S _inst_2) (AddMonoidWithOne.toAddMonoid.{u3} (Polynomial.{u3} S _inst_2) (AddCommMonoidWithOne.toAddMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (NonAssocSemiring.toAddCommMonoidWithOne.{u3} (Polynomial.{u3} S _inst_2) (Semiring.toNonAssocSemiring.{u3} (Polynomial.{u3} S _inst_2) (Polynomial.semiring.{u3} S _inst_2)))))) _inst_3)) \u03c6 p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.map_nat_degree_eq_nat_degree Polynomial.map_natDegree_eq_natDegree\u2093'. -/\ntheorem map_natDegree_eq_natDegree {S F : Type _} [Semiring S] [AddMonoidHomClass F R[X] S[X]]\n    {\u03c6 : F} (p) (\u03c6_mon_nat : \u2200 n c, c \u2260 0 \u2192 (\u03c6 (monomial n c)).natDegree = n) :\n    (\u03c6 p).natDegree = p.natDegree :=\n  (map_natDegree_eq_sub (fun f h => (Nat.not_lt_zero _ h).elim) (by simpa)).trans\n    p.natDegree.sub_zero\n#align polynomial.map_nat_degree_eq_nat_degree Polynomial.map_natDegree_eq_natDegree\n\nopen BigOperators\n\n/- warning: polynomial.card_support_eq' -> Polynomial.card_support_eq' is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {n : Nat} (k : (Fin n) -> Nat) (x : (Fin n) -> R), (Function.Injective.{1, 1} (Fin n) Nat k) -> (forall (i : Fin n), Ne.{succ u1} R (x i) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 (Finset.sum.{u1, 0} (Polynomial.{u1} R _inst_1) (Fin n) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Finset.univ.{0} (Fin n) (Fin.fintype n)) (fun (i : Fin n) => HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) (x i)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) (k i)))))) n)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {n : Nat} (k : (Fin n) -> Nat) (x : (Fin n) -> R), (Function.Injective.{1, 1} (Fin n) Nat k) -> (forall (i : Fin n), Ne.{succ u1} R (x i) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 (Finset.sum.{u1, 0} (Polynomial.{u1} R _inst_1) (Fin n) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Finset.univ.{0} (Fin n) (Fin.fintype n)) (fun (i : Fin n) => HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (x i)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (x i)) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) (x i)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) (k i)))))) n)\nCase conversion may be inaccurate. Consider using '#align polynomial.card_support_eq' Polynomial.card_support_eq'\u2093'. -/\ntheorem card_support_eq' {n : \u2115} (k : Fin n \u2192 \u2115) (x : Fin n \u2192 R) (hk : Function.Injective k)\n    (hx : \u2200 i, x i \u2260 0) : (\u2211 i, C (x i) * X ^ k i).support.card = n :=\n  by\n  suffices (\u2211 i, C (x i) * X ^ k i).support = image k univ by\n    rw [this, univ.card_image_of_injective hk, card_fin]\n  simp_rw [Finset.ext_iff, mem_support_iff, finset_sum_coeff, coeff_C_mul_X_pow, mem_image,\n    mem_univ, exists_true_left]\n  refine' fun i => \u27e8fun h => _, _\u27e9\n  \u00b7 obtain \u27e8j, hj, h\u27e9 := exists_ne_zero_of_sum_ne_zero h\n    exact \u27e8j, (ite_ne_right_iff.mp h).1.symm\u27e9\n  \u00b7 rintro \u27e8j, rfl\u27e9\n    rw [sum_eq_single_of_mem j (mem_univ j), if_pos rfl]\n    \u00b7 exact hx j\n    \u00b7 exact fun m hm hmj => if_neg fun h => hmj.symm (hk h)\n#align polynomial.card_support_eq' Polynomial.card_support_eq'\n\n/- warning: polynomial.card_support_eq -> Polynomial.card_support_eq is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1} {n : Nat}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) n) (Exists.{1} ((Fin n) -> Nat) (fun (k : (Fin n) -> Nat) => Exists.{succ u1} ((Fin n) -> R) (fun (x : (Fin n) -> R) => Exists.{0} (StrictMono.{0, 0} (Fin n) Nat (PartialOrder.toPreorder.{0} (Fin n) (Fin.partialOrder n)) (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) k) (fun (hk : StrictMono.{0, 0} (Fin n) Nat (PartialOrder.toPreorder.{0} (Fin n) (Fin.partialOrder n)) (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) k) => Exists.{0} (forall (i : Fin n), Ne.{succ u1} R (x i) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (fun (hx : forall (i : Fin n), Ne.{succ u1} R (x i) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (Finset.sum.{u1, 0} (Polynomial.{u1} R _inst_1) (Fin n) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Finset.univ.{0} (Fin n) (Fin.fintype n)) (fun (i : Fin n) => HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) (x i)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) (k i)))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1} {n : Nat}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) n) (Exists.{1} ((Fin n) -> Nat) (fun (k : (Fin n) -> Nat) => Exists.{succ u1} ((Fin n) -> R) (fun (x : (Fin n) -> R) => Exists.{0} (StrictMono.{0, 0} (Fin n) Nat (PartialOrder.toPreorder.{0} (Fin n) (Fin.instPartialOrderFin n)) (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) k) (fun (hk : StrictMono.{0, 0} (Fin n) Nat (PartialOrder.toPreorder.{0} (Fin n) (Fin.instPartialOrderFin n)) (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) k) => Exists.{0} (forall (i : Fin n), Ne.{succ u1} R (x i) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (fun (hx : forall (i : Fin n), Ne.{succ u1} R (x i) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (Finset.sum.{u1, 0} (Polynomial.{u1} R _inst_1) (Fin n) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Finset.univ.{0} (Fin n) (Fin.fintype n)) (fun (i : Fin n) => HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (x i)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) (x i)) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) (x i)) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) (k i)))))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.card_support_eq Polynomial.card_support_eq\u2093'. -/\ntheorem card_support_eq {n : \u2115} :\n    f.support.card = n \u2194\n      \u2203 (k : Fin n \u2192 \u2115)(x : Fin n \u2192 R)(hk : StrictMono k)(hx : \u2200 i, x i \u2260 0),\n        f = \u2211 i, C (x i) * X ^ k i :=\n  by\n  refine' \u27e8_, fun \u27e8k, x, hk, hx, hf\u27e9 => hf.symm \u25b8 card_support_eq' k x hk.Injective hx\u27e9\n  induction' n with n hn generalizing f\n  \u00b7 exact fun hf => \u27e80, 0, isEmptyElim, isEmptyElim, card_support_eq_zero.mp hf\u27e9\n  \u00b7 intro h\n    obtain \u27e8k, x, hk, hx, hf\u27e9 := hn (erase_lead_card_support' h)\n    have H : \u00ac\u2203 k : Fin n, k.cast_succ = Fin.last n :=\n      by\n      rintro \u27e8i, hi\u27e9\n      exact i.cast_succ_lt_last.Ne hi\n    refine'\n      \u27e8Function.extend Fin.castSucc k fun _ => f.nat_degree,\n        Function.extend Fin.castSucc x fun _ => f.leading_coeff, _, _, _\u27e9\n    \u00b7 intro i j hij\n      have hi : i \u2208 Set.range (Fin.castSucc : Fin n \u21aao Fin (n + 1)) :=\n        by\n        rw [Fin.range_castSucc, Set.mem_def]\n        exact lt_of_lt_of_le hij (nat.lt_succ_iff.mp j.2)\n      obtain \u27e8i, rfl\u27e9 := hi\n      rw [fin.cast_succ.injective.extend_apply]\n      by_cases hj : \u2203 j\u2080, Fin.castSucc j\u2080 = j\n      \u00b7 obtain \u27e8j, rfl\u27e9 := hj\n        rwa [fin.cast_succ.injective.extend_apply, hk.lt_iff_lt, \u2190 Fin.castSucc_lt_castSucc_iff]\n      \u00b7 rw [Function.extend_apply' _ _ _ hj]\n        apply lt_nat_degree_of_mem_erase_lead_support\n        rw [mem_support_iff, hf, finset_sum_coeff]\n        rw [sum_eq_single, coeff_C_mul, coeff_X_pow_self, mul_one]\n        \u00b7 exact hx i\n        \u00b7 intro j hj hji\n          rw [coeff_C_mul, coeff_X_pow, if_neg (hk.injective.ne hji.symm), MulZeroClass.mul_zero]\n        \u00b7 exact fun hi => (hi (mem_univ i)).elim\n    \u00b7 intro i\n      by_cases hi : \u2203 i\u2080, Fin.castSucc i\u2080 = i\n      \u00b7 obtain \u27e8i, rfl\u27e9 := hi\n        rw [fin.cast_succ.injective.extend_apply]\n        exact hx i\n      \u00b7 rw [Function.extend_apply' _ _ _ hi, Ne, leading_coeff_eq_zero, \u2190 card_support_eq_zero, h]\n        exact n.succ_ne_zero\n    \u00b7 rw [Fin.sum_univ_castSucc]\n      simp only [fin.cast_succ.injective.extend_apply]\n      rw [\u2190 hf, Function.extend_apply', Function.extend_apply', erase_lead_add_C_mul_X_pow]\n      all_goals exact H\n#align polynomial.card_support_eq Polynomial.card_support_eq\n\n/- warning: polynomial.card_support_eq_one -> Polynomial.card_support_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Exists.{1} Nat (fun (k : Nat) => Exists.{succ u1} R (fun (x : R) => Exists.{0} (Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (fun (hx : Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) x) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) k))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Exists.{1} Nat (fun (k : Nat) => Exists.{succ u1} R (fun (x : R) => Exists.{0} (Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (fun (hx : Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) x) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) k))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.card_support_eq_one Polynomial.card_support_eq_one\u2093'. -/\ntheorem card_support_eq_one : f.support.card = 1 \u2194 \u2203 (k : \u2115)(x : R)(hx : x \u2260 0), f = C x * X ^ k :=\n  by\n  refine' \u27e8fun h => _, _\u27e9\n  \u00b7 obtain \u27e8k, x, hk, hx, rfl\u27e9 := card_support_eq.mp h\n    exact \u27e8k 0, x 0, hx 0, Fin.sum_univ_one _\u27e9\n  \u00b7 rintro \u27e8k, x, hx, rfl\u27e9\n    rw [support_C_mul_X_pow k hx, card_singleton]\n#align polynomial.card_support_eq_one Polynomial.card_support_eq_one\n\n/- warning: polynomial.card_support_eq_two -> Polynomial.card_support_eq_two is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) (Exists.{1} Nat (fun (k : Nat) => Exists.{1} Nat (fun (m : Nat) => Exists.{0} (LT.lt.{0} Nat Nat.hasLt k m) (fun (hkm : LT.lt.{0} Nat Nat.hasLt k m) => Exists.{succ u1} R (fun (x : R) => Exists.{succ u1} R (fun (y : R) => Exists.{0} (Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (fun (hx : Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) => Exists.{0} (Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (fun (hy : Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) x) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) k)) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) y) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) m)))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) (Exists.{1} Nat (fun (k : Nat) => Exists.{1} Nat (fun (m : Nat) => Exists.{0} (LT.lt.{0} Nat instLTNat k m) (fun (hkm : LT.lt.{0} Nat instLTNat k m) => Exists.{succ u1} R (fun (x : R) => Exists.{succ u1} R (fun (y : R) => Exists.{0} (Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (fun (hx : Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) => Exists.{0} (Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (fun (hy : Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (HAdd.hAdd.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.add'.{u1} R _inst_1)) (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) x) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) k)) (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) y) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) m)))))))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.card_support_eq_two Polynomial.card_support_eq_two\u2093'. -/\ntheorem card_support_eq_two :\n    f.support.card = 2 \u2194\n      \u2203 (k m : \u2115)(hkm : k < m)(x y : R)(hx : x \u2260 0)(hy : y \u2260 0), f = C x * X ^ k + C y * X ^ m :=\n  by\n  refine' \u27e8fun h => _, _\u27e9\n  \u00b7 obtain \u27e8k, x, hk, hx, rfl\u27e9 := card_support_eq.mp h\n    refine' \u27e8k 0, k 1, hk Nat.zero_lt_one, x 0, x 1, hx 0, hx 1, _\u27e9\n    rw [Fin.sum_univ_castSucc, Fin.sum_univ_one]\n    rfl\n  \u00b7 rintro \u27e8k, m, hkm, x, y, hx, hy, rfl\u27e9\n    exact card_support_binomial hkm.ne hx hy\n#align polynomial.card_support_eq_two Polynomial.card_support_eq_two\n\n/- warning: polynomial.card_support_eq_three -> Polynomial.card_support_eq_three is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) (OfNat.ofNat.{0} Nat 3 (OfNat.mk.{0} Nat 3 (bit1.{0} Nat Nat.hasOne Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) (Exists.{1} Nat (fun (k : Nat) => Exists.{1} Nat (fun (m : Nat) => Exists.{1} Nat (fun (n : Nat) => Exists.{0} (LT.lt.{0} Nat Nat.hasLt k m) (fun (hkm : LT.lt.{0} Nat Nat.hasLt k m) => Exists.{0} (LT.lt.{0} Nat Nat.hasLt m n) (fun (hmn : LT.lt.{0} Nat Nat.hasLt m n) => Exists.{succ u1} R (fun (x : R) => Exists.{succ u1} R (fun (y : R) => Exists.{succ u1} R (fun (z : R) => Exists.{0} (Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (fun (hx : Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) => Exists.{0} (Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (fun (hy : Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) => Exists.{0} (Ne.{succ u1} R z (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) (fun (hz : Ne.{succ u1} R z (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) (HAdd.hAdd.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.add'.{u1} R _inst_1)) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) x) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) k)) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) y) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) m))) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) z) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n)))))))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] {f : Polynomial.{u1} R _inst_1}, Iff (Eq.{1} Nat (Finset.card.{0} Nat (Polynomial.support.{u1} R _inst_1 f)) (OfNat.ofNat.{0} Nat 3 (instOfNatNat 3))) (Exists.{1} Nat (fun (k : Nat) => Exists.{1} Nat (fun (m : Nat) => Exists.{1} Nat (fun (n : Nat) => Exists.{0} (LT.lt.{0} Nat instLTNat k m) (fun (hkm : LT.lt.{0} Nat instLTNat k m) => Exists.{0} (LT.lt.{0} Nat instLTNat m n) (fun (hmn : LT.lt.{0} Nat instLTNat m n) => Exists.{succ u1} R (fun (x : R) => Exists.{succ u1} R (fun (y : R) => Exists.{succ u1} R (fun (z : R) => Exists.{0} (Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (fun (hx : Ne.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) => Exists.{0} (Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (fun (hy : Ne.{succ u1} R y (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) => Exists.{0} (Ne.{succ u1} R z (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (fun (hz : Ne.{succ u1} R z (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) => Eq.{succ u1} (Polynomial.{u1} R _inst_1) f (HAdd.hAdd.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) z) (Polynomial.{u1} R _inst_1) (instHAdd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.add'.{u1} R _inst_1)) (HAdd.hAdd.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (instHAdd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.add'.{u1} R _inst_1)) (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) x) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) x) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) k)) (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) y) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) y) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) m))) (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) z) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) z) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) z) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) z) (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R _inst_1) Nat (Polynomial.{u1} R _inst_1) (instHPow.{u1, 0} (Polynomial.{u1} R _inst_1) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R _inst_1) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))))) (Polynomial.X.{u1} R _inst_1) n)))))))))))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.card_support_eq_three Polynomial.card_support_eq_three\u2093'. -/\ntheorem card_support_eq_three :\n    f.support.card = 3 \u2194\n      \u2203 (k m n : \u2115)(hkm : k < m)(hmn : m < n)(x y z : R)(hx : x \u2260 0)(hy : y \u2260 0)(hz : z \u2260 0),\n        f = C x * X ^ k + C y * X ^ m + C z * X ^ n :=\n  by\n  refine' \u27e8fun h => _, _\u27e9\n  \u00b7 obtain \u27e8k, x, hk, hx, rfl\u27e9 := card_support_eq.mp h\n    refine'\n      \u27e8k 0, k 1, k 2, hk Nat.zero_lt_one, hk (Nat.lt_succ_self 1), x 0, x 1, x 2, hx 0, hx 1, hx 2,\n        _\u27e9\n    rw [Fin.sum_univ_castSucc, Fin.sum_univ_castSucc, Fin.sum_univ_one]\n    rfl\n  \u00b7 rintro \u27e8k, m, n, hkm, hmn, x, y, z, hx, hy, hz, rfl\u27e9\n    exact card_support_trinomial hkm hmn hx hy hz\n#align polynomial.card_support_eq_three Polynomial.card_support_eq_three\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Polynomial/EraseLead.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7362501698211278}}
{"text": "-- Let's first prove some simple example lemmas with the logical connectives we learned in the lecture.\nsection\n-- Variables in sections determine the type of certain variables for the remainder of the section, saving us a bit of space.\nvariable (p q r : Prop)\n\nexample : p \u2192 p := \n  fun h => h\n\nexample : p \u2192 (q \u2192 p) := \n  fun hp => fun hq => hp -- similarly to the note below, we can elide parentheses around the inner `fun`\n\n-- Note: `\u2192` associates to the right, so the above proposition is equivalent to\n-- `p \u2192 q \u2192 p`\n\nexample : (p \u2192 False) \u2192 (p \u2192 q) := \n  fun hnp hp => nomatch hnp hp  -- we can also combine nested `fun`s\n\nexample : (p \u2228 p) \u2192 p := \n  fun hpp => match hpp with\n    | Or.inl hp => hp\n    | Or.inr hp => hp\n\nexample : (p \u2192 q \u2192 r) \u2192 (p \u2227 q \u2192 r) := \n  fun h hpq => match hpq with\n    | And.intro hp hq => h hp hq\n\nexample : (p \u2227 q \u2192 r) \u2192 (p \u2192 q \u2192 r) := \n  fun h hp hq => h (And.intro hp hq)\n\nexample : p \u2192 (p \u2192 q) \u2192 p \u2227 q := \n  -- For inductive types with a single constructor `I.c`, we can also use the\n  -- *anonymous constructor* notation `\u27e8e, ...\u27e9` instead of `I.c e...`.\n  -- Input `\u27e8` and `\u27e9` as `\\<` and `\\>`.\n  fun hp h => \u27e8hp, h hp\u27e9\n\ntheorem imp_and : (p \u2192 q \u2227 r) \u2192 (p \u2192 q) \u2227 (p \u2192 r) := \n  fun h => \u27e8fun hp => match h hp with | And.intro hq hr => hq,\n            fun hp => match h hp with | And.intro hq hr => hr\u27e9\n\n-- Matching on `And.intro` can quickly become tedious, so you can use the following helper functions from now on:\n#check And.left\n#check And.right\n\n/- BIIMPLICATION -/\n\n-- Biimplication (\"if and only if\") is written \\iff.\n-- It is defined as a data type on the constructor\n-- Iff.intro : (A \u2192 B) \u2192 (B \u2192 A) \u2192 (A \u2194 B)\n-- Can you recover the proof for A \u2192 B by a match expression?\n\nexample (hpq : p \u2194 q) : (p \u2192 q) := \n  match hpq with\n  | \u27e8hmp, _\u27e9 => hmp\n-- Note that we didn't have to give the second argument on the left side of `=>` since we do not use it.\n\n-- Like for `And`, we have names for both directions of the biimplication:\n#check Iff.mp\n#check Iff.mpr\n\n-- Prove the following biimplications using the threorem from above!\n-- Note: `\u2194` is defined to bind less tightly than other connectives such as `\u2227` or `\u2228`.\n\ntheorem iff_and : (p \u2192 q \u2227 r) \u2194 (p \u2192 q) \u2227 (p \u2192 r) := \n  -- If `h : p \u2227 q`, we can also write `h.left` as a shorthand for `And.left h`.\n  -- In general, if a term `e` has some type `A` and `A.f : A \u2192 ...` is a function,\n  -- then `e.f` is a shorthand for `A.f e`.\n  \u27e8fun hpqr => \u27e8fun hp => (hpqr hp).left, fun hp => (hpqr hp).right\u27e9,\n   -- We can use \"infallible\" patterns such as anonymous constructors directly in place of a `fun` binder name\n   -- This feature is a good way to make proofs shorter.\n   fun \u27e8hpq, hpr\u27e9 hp => \u27e8hpq hp, hpr hp\u27e9\u27e9\n\ntheorem or_and : (p \u2228 q \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := \n  \u27e8fun hpqr => \u27e8fun hp => hpqr (Or.inl hp), fun hq => hpqr (Or.inr hq)\u27e9,\n   fun hprqr =>\n     -- `fun | ...` is short for `fun x => match x with | ...`\n     fun\n     | Or.inl hp => hprqr.left hp\n     | Or.inr hq => hprqr.right hq\u27e9\n\ntheorem iff_and_false : False \u2194 p \u2227 False := \n  \u27e8fun fa => nomatch fa, fun h => h.right\u27e9\n\n/- NEGATION -/\n\n-- Negation is defined by \u00ac A := (A \u2192 False).\n-- How is that a good choice? Let us check some basic properties of negation:\ntheorem imp_not_not : p \u2192 \u00ac\u00acp := \n  fun hp hnp => hnp hp\n\nexample : \u00ac(p \u2227 \u00acp) := \n  fun h => h.right h.left\n\ntheorem not_or_not : (\u00acp \u2228 \u00acq) \u2192 \u00ac(p \u2227 q) := \n  fun hor \u27e8hp, hq\u27e9 =>\n    match hor with\n    | Or.inl hnp => hnp hp\n    | Or.inr hnq => hnq hq\n\n-- The following ones are a harder to prove. Don't hesitate to skip them or ask your\n-- tutors if you get stuck\n\nexample : \u00ac(p \u2194 \u00acp) := \n  fun h =>\n    -- We can use `have` for a sub-proof so we don't have to repeat ourselves.\n    -- `have` is generally nicer to use than `let` in the case of propositions.\n    -- We have updated the slides to reflect this.\n    have hp : p := h.2 (fun hp => h.1 hp hp)\n    h.1 hp hp\n-- Did you see that we used `.1` and `.2` instead of `.mp` and `.mpr`?\n-- For single-constructor inductive types we can also use numbers to refer to their \"fields\", i.e. to\n-- the arguments of the constructor.\n\nexample : \u00ac\u00ac(\u00ac\u00acp \u2192 p) := \n  fun nnnpp => nnnpp fun nnp => False.elim (nnp (fun hp => nnnpp fun _ => hp))\n-- Using `False.elim` instead of `nomatch` makes for better output during the construction of the proof.\n-- We have updated the slides to reflect this.\n\n\n/- CLASSICAL AXIOMS -/\n\n-- Some tautologies about negation cannot be proven by just assuming the logical\n-- connectives as algebraic propositions. Instead, we need to assume these facts\n-- as axioms. To have access to these, we need to open a namespace called \"Classical\".\n-- We will learn more about constructive versus classical logic in week 5.\nopen Classical\n\n-- The following statement is called the _law of excluded middle_.\n-- It is assumed as an axiom, which means that it doesn't have to be proved.\n\n#check em p\n\n-- Now use the law of excluded middle to show that the theorem not_or_not is reversible:\n\ntheorem not_and : \u00ac(p \u2227 q) \u2192 (\u00ac p \u2228 \u00ac q) := \n  fun hn =>\n  match em p with\n  | Or.inl hp  =>\n    match em q with\n    | Or.inl hq  => False.elim (hn \u27e8hp, hq\u27e9)\n    | Or.inr hnq => Or.inr hnq\n  | Or.inr hnp => Or.inl hnp\n-- You can see in the structure of this proof that what we are doing is just making\n-- iterated case distinctions on the truth value of propositions.\n-- As such, the above proof is the equivalent of a proof \"by truth\" table, where we are listing all the possible\n-- combinations.\n\n-- Also, we can now deal better with double negations:\n\nexample : \u00ac\u00acp \u2194 p := \n  \u27e8fun hnnp =>\n   match em p with\n   | Or.inl hp => hp\n   | Or.inr hnp => False.elim (hnnp hnp),\n   imp_not_not p\u27e9\n-- The proof of the first direction is what you know as \"proof by contradiction\":\n-- To prove a proposition `p`, we match on `em p`. Then, the first case is always trivial,\n-- and in the second case we will have to use `False.elim` to show that now we have contradicting\n-- premises.\n-- You will need this principle in the second exercise sheet as well.\n\nend\n", "meta": {"author": "IPDSnelting", "repo": "tba-2021", "sha": "b6390e55b768423d3266969e81d19290129c5914", "save_path": "github-repos/lean/IPDSnelting-tba-2021", "path": "github-repos/lean/IPDSnelting-tba-2021/tba-2021-b6390e55b768423d3266969e81d19290129c5914/TBA/Solutions/Exercise1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.736250168725664}}
{"text": "import data.set\nimport data.int.basic\nimport data.nat.basic\nopen function int set nat\n\nsection\n  def f (x : \u2124) : \u2124 := x + 3\n  def g (x : \u2124) : \u2124 := -x\n  def h (x : \u2124) : \u2124 := 2 * x + 3\n\n  -- 1\n  example : injective h :=\n\n  assume x,\n  assume y,\n\n  assume h1: 2 * x + 3 = 2 * y + 3,\n  \n  have h2: 2 * x = 2 * y, from add_right_cancel h1,\n\n  show x = y, from mul_left_cancel\u2080 dec_trivial h2\n\n\n  -- 2\n  example : surjective g :=\n  \n  assume f,\n\n  have h1: g (-f) = -(-f), from rfl,\n  have h2: g (-f) = f, from neg_neg f,\n  show \u2203 (a : \u2124), g a = f, from exists.intro (-f) h2\n\n\n  -- 3\n  example (A B : Type) (u : A \u2192 B) (v1 : B \u2192 A) (v2 : B \u2192 A)\n    (h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=\n  funext\n    (assume x,\n      calc\n        v1 x = v1 (u (v2 x)) : by rw h2\n         ... = v2 x          : by rw h1)\nend\n\n-- 4\nsection\n  variables {X Y : Type}\n  variable f : X \u2192 Y\n  variables A B : set X\n\n  example : f '' (A \u2229 B) \u2286 f '' A \u2229 f '' B :=\n  assume y,\n  assume h1 : y \u2208 f '' (A \u2229 B),\n  show y \u2208 f '' A \u2229 f '' B, from exists.elim h1\n  (\n    assume a,\n    assume b,\n\n    have e1: f a = y, from and.right b,\n\n    have e2: a \u2208 A, from and.left (and.left b),\n    have e3: a \u2208 A \u2227 f a = y, from and.intro e2 e1,\n    have e4: y \u2208 f '' A, from exists.intro a e3,\n\n    have e5: a \u2208 B, from and.right (and.left b),\n    have e6: a \u2208 B \u2227 f a = y, from and.intro e5 e1,\n    have e7: y \u2208 f '' B, from exists.intro a e6,\n\n    show y \u2208 f '' A \u2229 f '' B, from and.intro e4 e7\n  )\nend\n\n\n-- 5\nexample : \u2200 m n k : nat, m * (n + k) = m * n + m * k :=\n  begin\n    intros m n k,\n    induction m,\n\n    rw zero_mul,\n    rw zero_mul,\n    rw zero_mul,\n\n    rw succ_mul,\n    rw succ_mul,\n    rw succ_mul,\n\n    rw \u2190 add_assoc,\n    rw \u2190 add_assoc,\n\n    rw add_right_comm,\n\n    rw m_ih,\n\n    rw add_comm,\n\n    rw add_assoc,\n    rw add_assoc,\n    rw add_assoc,\n\n    rw add_left_comm\n  end\n\n-- 6\nexample : \u2200 n : nat, 0 * n = 0 :=\n  begin\n    intro n,\n    induction n,\n    \n    refl,\n\n    rw mul_succ,\n\n    rw n_ih\n  end\n\n-- 7\nexample : \u2200 n : nat, 1 * n = n :=\n  begin\n    intro n,\n    induction n,\n\n    rw mul_zero,\n\n    rw mul_succ,\n\n    rw n_ih\n  end\n\n-- 8\nexample : \u2200 m n k : nat, (m * n) * k = m * (n * k) :=\n  begin\n    intros m n k,\n    induction k,\n\n    rw mul_zero,\n    rw mul_zero,\n    rw mul_zero,\n\n    rw mul_succ,\n    rw mul_succ,\n\n    rw left_distrib,\n\n    rw k_ih\n  end\n\n-- 9\nexample : \u2200 m n : nat, m * n = n * m :=\n  begin\n  intros m n,\n  induction m,\n\n  rw mul_zero,\n\n  rw zero_mul,\n\n  rw mul_succ,\n\n  rw succ_mul,\n\n  rw m_ih\n  end\n", "meta": {"author": "ju211256", "repo": "CS205", "sha": "3bf7e3f8d51dff3f51fac07eb0dba377703ee587", "save_path": "github-repos/lean/ju211256-CS205", "path": "github-repos/lean/ju211256-CS205/CS205-3bf7e3f8d51dff3f51fac07eb0dba377703ee587/LEAN/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7362501656371687}}
{"text": "variable (\u03b1 : Type)\nvariable (f : \u03b1 \u2192 \u03b1) \nvariable (A B C : \u03b1 \u2192 Prop)\nvariable (D : Prop) \n\ntheorem problem1 (h\u2081 : \u2200 x, A x \u2192 B x) (h\u2082 : \u2203 y, A y) : \u2203 z, B z := sorry\n\ntheorem problem2 (h : \u2203 x, A x) : \u2203 y, A y \u2228 B y := sorry \n\ntheorem problem3 (h : \u2200 x, A x \u2192 A (f x)) : \u2200 y, A y \u2192 A (f (f y)) := sorry\n\ntheorem problem4 (h\u2081 : \u2200 x, A x \u2228 B x) (h\u2082 : \u2200 x, A x \u2192 C x) (h\u2083 : \u2200 x, B x \u2192 C x) : \u2200 x, C x := sorry\n\ntheorem problem5 (a : \u03b1) : (\u2200 (x:\u03b1), D) \u2194 D := sorry \n", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "homework7", "sha": "4873226c2ce223b0f592894b99ced612f0f2712d", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework7", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework7/homework7-4873226c2ce223b0f592894b99ced612f0f2712d/Hw7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7362391019422445}}
{"text": "/-\nCopyright (c) 2020 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport ring_theory.polynomial.cyclotomic\nimport topology.algebra.polynomial\nimport field_theory.finite.basic\n\n/-!\n# Primes congruent to one\n\nWe prove that, for any positive `k : \u2115`, there are infinitely many primes `p` such that\n`p \u2261 1 [MOD k]`.\n-/\n\nnamespace nat\n\nopen polynomial nat filter\n\n/-- For any positive `k : \u2115` there are infinitely many primes `p` such that `p \u2261 1 [MOD k]`. -/\nlemma exists_prime_ge_modeq_one (k n : \u2115) (hpos : 0 < k) :\n  \u2203 (p : \u2115), nat.prime p \u2227 n \u2264 p \u2227 p \u2261 1 [MOD k] :=\nbegin\n  have hli : tendsto (abs \u2218 (\u03bb (a : \u2115), abs(a : \u211a))) at_top at_top,\n  { simp only [(\u2218), abs_cast],\n    exact nat.strict_mono_cast.monotone.tendsto_at_top_at_top exists_nat_ge },\n  have hcff : int.cast_ring_hom \u211a (cyclotomic k \u2124).leading_coeff \u2260 0,\n  { simp only [cyclotomic.monic, ring_hom.eq_int_cast, monic.leading_coeff, int.cast_one, ne.def,\n     not_false_iff, one_ne_zero] },\n  obtain \u27e8a, ha\u27e9 := tendsto_at_top_at_top.1 (tendsto_abv_eval\u2082_at_top (int.cast_ring_hom \u211a) abs\n    (cyclotomic k \u2124) (degree_cyclotomic_pos k \u2124 hpos) hcff hli) 2,\n  let b := a * (k * n.factorial),\n  have hgt : 1 < (eval \u2191(a * (k * n.factorial)) (cyclotomic k \u2124)).nat_abs,\n  { suffices hgtabs : 1 < abs (eval \u2191b (cyclotomic k \u2124)),\n    { rw [int.abs_eq_nat_abs] at hgtabs,\n      exact_mod_cast hgtabs },\n    suffices hgtrat : 1 < abs (eval \u2191b (cyclotomic k \u211a)),\n    { rw [\u2190 map_cyclotomic_int k \u211a, \u2190 int.cast_coe_nat, \u2190 int.coe_cast_ring_hom, eval_map,\n        eval\u2082_hom, int.coe_cast_ring_hom] at hgtrat,\n      assumption_mod_cast },\n    suffices hleab : a \u2264 b,\n    { replace ha := lt_of_lt_of_le one_lt_two (ha b hleab),\n      rwa [\u2190 eval_map, map_cyclotomic_int k \u211a, abs_cast] at ha },\n    exact le_mul_of_pos_right (mul_pos hpos (factorial_pos n)) },\n  let p := min_fac (eval \u2191b (cyclotomic k \u2124)).nat_abs,\n  haveI hprime : fact p.prime := \u27e8min_fac_prime (ne_of_lt hgt).symm\u27e9,\n  have hroot : is_root (cyclotomic k (zmod p)) (cast_ring_hom (zmod p) b),\n  { rw [is_root.def, \u2190 map_cyclotomic_int k (zmod p), eval_map, coe_cast_ring_hom,\n    \u2190 int.cast_coe_nat, \u2190 int.coe_cast_ring_hom, eval\u2082_hom, int.coe_cast_ring_hom,\n      zmod.int_coe_zmod_eq_zero_iff_dvd _ _],\n    apply int.dvd_nat_abs.1,\n    exact_mod_cast min_fac_dvd (eval \u2191b (cyclotomic k \u2124)).nat_abs },\n  refine \u27e8p, hprime.1, _, _\u27e9,\n  { by_contra habs,\n    exact (prime.dvd_iff_not_coprime hprime.1).1\n      (dvd_factorial (min_fac_pos _) (le_of_not_ge habs))\n      (coprime_of_root_cyclotomic hpos hroot).symm.coprime_mul_left_right.coprime_mul_left_right },\n  { have hdiv := order_of_dvd_of_pow_eq_one (zmod.units_pow_card_sub_one_eq_one p\n      (zmod.unit_of_coprime b (coprime_of_root_cyclotomic hpos hroot))),\n    have : \u00acp \u2223 k := hprime.1.coprime_iff_not_dvd.1\n      (coprime_of_root_cyclotomic hpos hroot).symm.coprime_mul_left_right.coprime_mul_right_right,\n    rw [order_of_root_cyclotomic hpos this hroot] at hdiv,\n    exact ((modeq.modeq_iff_dvd' hprime.1.pos).2 hdiv).symm }\nend\n\nlemma frequently_at_top_modeq_one (k : \u2115) (hpos : 0 < k) :\n  \u2203\u1da0 p in at_top, nat.prime p \u2227 p \u2261 1 [MOD k] :=\nbegin\n  refine frequently_at_top.2 (\u03bb n, _),\n  obtain \u27e8p, hp\u27e9 := exists_prime_ge_modeq_one k n hpos,\n  exact \u27e8p, \u27e8hp.2.1, hp.1, hp.2.2\u27e9\u27e9\nend\n\nlemma infinite_set_of_prime_modeq_one (k : \u2115) (hpos : 0 < k) :\n  set.infinite {p : \u2115 | nat.prime p \u2227 p \u2261 1 [MOD k]} :=\nfrequently_at_top_iff_infinite.1 (frequently_at_top_modeq_one k hpos)\n\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/number_theory/primes_congruent_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8438951025545425, "lm_q1q2_score": 0.7361696772172533}}
{"text": "/-\nCopyright (c) 2022 Justin Thomas. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Justin Thomas\n-/\nimport field_theory.minpoly.field\nimport ring_theory.principal_ideal_domain\n\n/-!\n# Annihilating Ideal\n\nGiven a commutative ring `R` and an `R`-algebra `A`\nEvery element `a : A` defines\nan ideal `polynomial.ann_ideal a \u2286 R[X]`.\nSimply put, this is the set of polynomials `p` where\nthe polynomial evaluation `p(a)` is 0.\n\n## Special case where the ground ring is a field\n\nIn the special case that `R` is a field, we use the notation `R = \ud835\udd5c`.\nHere `\ud835\udd5c[X]` is a PID, so there is a polynomial `g \u2208 polynomial.ann_ideal a`\nwhich generates the ideal. We show that if this generator is\nchosen to be monic, then it is the minimal polynomial of `a`,\nas defined in `field_theory.minpoly`.\n\n## Special case: endomorphism algebra\n\nGiven an `R`-module `M` (`[add_comm_group M] [module R M]`)\nthere are some common specializations which may be more familiar.\n* Example 1: `A = M \u2192\u2097[R] M`, the endomorphism algebra of an `R`-module M.\n* Example 2: `A = n \u00d7 n` matrices with entries in `R`.\n-/\n\nopen_locale polynomial\n\nnamespace polynomial\n\nsection semiring\n\nvariables {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]\n\nvariables (R)\n\n/-- `ann_ideal R a` is the *annihilating ideal* of all `p : R[X]` such that `p(a) = 0`.\n\nThe informal notation `p(a)` stand for `polynomial.aeval a p`.\nAgain informally, the annihilating ideal of `a` is\n`{ p \u2208 R[X] | p(a) = 0 }`. This is an ideal in `R[X]`.\nThe formal definition uses the kernel of the aeval map. -/\nnoncomputable def ann_ideal (a : A) : ideal R[X] :=\n((aeval a).to_ring_hom : R[X] \u2192+* A).ker\n\nvariables {R}\n\n/-- It is useful to refer to ideal membership sometimes\n and the annihilation condition other times. -/\nlemma mem_ann_ideal_iff_aeval_eq_zero {a : A} {p : R[X]} :\n  p \u2208 ann_ideal R a \u2194 aeval a p = 0 :=\niff.rfl\n\nend semiring\n\nsection field\n\nvariables {\ud835\udd5c A : Type*} [field \ud835\udd5c] [ring A] [algebra \ud835\udd5c A]\nvariable (\ud835\udd5c)\n\nopen submodule\n\n/-- `ann_ideal_generator \ud835\udd5c a` is the monic generator of `ann_ideal \ud835\udd5c a`\nif one exists, otherwise `0`.\n\nSince `\ud835\udd5c[X]` is a principal ideal domain there is a polynomial `g` such that\n `span \ud835\udd5c {g} = ann_ideal a`. This picks some generator.\n We prefer the monic generator of the ideal. -/\nnoncomputable def ann_ideal_generator (a : A) : \ud835\udd5c[X] :=\nlet g := is_principal.generator $ ann_ideal \ud835\udd5c a\n  in g * (C g.leading_coeff\u207b\u00b9)\n\nsection\n\nvariables {\ud835\udd5c}\n\n@[simp] lemma ann_ideal_generator_eq_zero_iff {a : A} :\n  ann_ideal_generator \ud835\udd5c a = 0 \u2194 ann_ideal \ud835\udd5c a = \u22a5 :=\nby simp only [ann_ideal_generator, mul_eq_zero, is_principal.eq_bot_iff_generator_eq_zero,\n  polynomial.C_eq_zero, inv_eq_zero, polynomial.leading_coeff_eq_zero, or_self]\nend\n\n/-- `ann_ideal_generator \ud835\udd5c a` is indeed a generator. -/\n@[simp] lemma span_singleton_ann_ideal_generator (a : A) :\n  ideal.span {ann_ideal_generator \ud835\udd5c a} = ann_ideal \ud835\udd5c a :=\nbegin\n  by_cases h : ann_ideal_generator \ud835\udd5c a = 0,\n  { rw [h, ann_ideal_generator_eq_zero_iff.mp h, set.singleton_zero, ideal.span_zero] },\n  { rw [ann_ideal_generator, ideal.span_singleton_mul_right_unit, ideal.span_singleton_generator],\n    apply polynomial.is_unit_C.mpr,\n    apply is_unit.mk0,\n    apply inv_eq_zero.not.mpr,\n    apply polynomial.leading_coeff_eq_zero.not.mpr,\n    apply (mul_ne_zero_iff.mp h).1 }\nend\n\n/-- The annihilating ideal generator is a member of the annihilating ideal. -/\nlemma ann_ideal_generator_mem (a : A) : ann_ideal_generator \ud835\udd5c a \u2208 ann_ideal \ud835\udd5c a :=\nideal.mul_mem_right _ _ (submodule.is_principal.generator_mem _)\n\nlemma mem_iff_eq_smul_ann_ideal_generator {p : \ud835\udd5c[X]} (a : A) :\n  p \u2208 ann_ideal \ud835\udd5c a \u2194 \u2203 s : \ud835\udd5c[X], p = s \u2022 ann_ideal_generator \ud835\udd5c a :=\nby simp_rw [@eq_comm _ p, \u2190 mem_span_singleton, \u2190 span_singleton_ann_ideal_generator \ud835\udd5c a,\n ideal.span]\n\n/-- The generator we chose for the annihilating ideal is monic when the ideal is non-zero. -/\nlemma monic_ann_ideal_generator (a : A) (hg : ann_ideal_generator \ud835\udd5c a \u2260 0) :\n  monic (ann_ideal_generator \ud835\udd5c a) :=\nmonic_mul_leading_coeff_inv (mul_ne_zero_iff.mp hg).1\n\n/-! We are working toward showing the generator of the annihilating ideal\nin the field case is the minimal polynomial. We are going to use a uniqueness\ntheorem of the minimal polynomial.\n\nThis is the first condition: it must annihilate the original element `a : A`. -/\nlemma ann_ideal_generator_aeval_eq_zero (a : A) :\n  aeval a (ann_ideal_generator \ud835\udd5c a) = 0 :=\nmem_ann_ideal_iff_aeval_eq_zero.mp (ann_ideal_generator_mem \ud835\udd5c a)\n\nvariables {\ud835\udd5c}\n\nlemma mem_iff_ann_ideal_generator_dvd {p : \ud835\udd5c[X]} {a : A} :\n  p \u2208 ann_ideal \ud835\udd5c a \u2194 ann_ideal_generator \ud835\udd5c a \u2223 p :=\nby rw [\u2190 ideal.mem_span_singleton, span_singleton_ann_ideal_generator]\n\n/-- The generator of the annihilating ideal has minimal degree among\n the non-zero members of the annihilating ideal -/\nlemma degree_ann_ideal_generator_le_of_mem (a : A) (p : \ud835\udd5c[X])\n  (hp : p \u2208 ann_ideal \ud835\udd5c a) (hpn0 : p \u2260 0) :\n  degree (ann_ideal_generator \ud835\udd5c a) \u2264 degree p :=\ndegree_le_of_dvd (mem_iff_ann_ideal_generator_dvd.1 hp) hpn0\n\nvariables (\ud835\udd5c)\n\n/-- The generator of the annihilating ideal is the minimal polynomial. -/\nlemma ann_ideal_generator_eq_minpoly (a : A) :\n  ann_ideal_generator \ud835\udd5c a = minpoly \ud835\udd5c a :=\nbegin\n  by_cases h : ann_ideal_generator \ud835\udd5c a = 0,\n  { rw [h, minpoly.eq_zero],\n    rintro \u27e8p, p_monic, (hp : aeval a p = 0)\u27e9,\n    refine p_monic.ne_zero (ideal.mem_bot.mp _),\n    simpa only [ann_ideal_generator_eq_zero_iff.mp h]\n      using mem_ann_ideal_iff_aeval_eq_zero.mpr hp },\n  { exact minpoly.unique _ _\n      (monic_ann_ideal_generator _ _ h)\n      (ann_ideal_generator_aeval_eq_zero _ _)\n      (\u03bb q q_monic hq, (degree_ann_ideal_generator_le_of_mem a q\n        (mem_ann_ideal_iff_aeval_eq_zero.mpr hq)\n        q_monic.ne_zero)) }\nend\n\n/-- If a monic generates the annihilating ideal, it must match our choice\n of the annihilating ideal generator. -/\nlemma monic_generator_eq_minpoly (a : A) (p : \ud835\udd5c[X])\n  (p_monic : p.monic) (p_gen : ideal.span {p} = ann_ideal \ud835\udd5c a) :\n  ann_ideal_generator \ud835\udd5c a = p :=\nbegin\n  by_cases h : p = 0,\n  { rwa [h, ann_ideal_generator_eq_zero_iff, \u2190 p_gen, ideal.span_singleton_eq_bot.mpr], },\n  { rw [\u2190 span_singleton_ann_ideal_generator, ideal.span_singleton_eq_span_singleton] at p_gen,\n    rw eq_comm,\n    apply eq_of_monic_of_associated p_monic _ p_gen,\n    { apply monic_ann_ideal_generator _ _ ((associated.ne_zero_iff p_gen).mp h), }, },\nend\n\nend field\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/annihilating_polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7361696703675059}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis file formalises the fact that any finite, linearly ordered\nset of size n has a unique order-isomorphism with the set \nfin n =  {0,...,n-1}.\n-/\n\nimport data.finset data.fintype\nimport fin_extra\nopen list \n\nvariables {\u03b1 : Type*} \n\nnamespace list\n\n/-\n If we have a list l (of length n) and a natural number i, we might \n want to refer to the i'th entry in the list, but then we have to \n decide what to do about the possibility that i is too large so that \n there is no i'th entry.  We always use 0-based indexing so the \n i'th entry is defined for i < n but not for i \u2265 n.  \n\n The standard library defines (l.nth i) to be of type (option \u03b1),\n and to have value (some x) if i < n and x is the i'th entry, but to\n have value (none) if i \u2265 n.  The standard library also defines \n (l.nth_le i h) to be x if h is a proof of i < n.  Here we just \n repackage this slightly: the pair \u27e8i,h\u27e9 gives a term of type\n (fin n), and we define l.fin_nth \u27e8i,h\u27e9 to be x again. \n-/\ndef fin_nth (l : list \u03b1) (i : fin l.length) : \u03b1 := \n l.nth_le i.val i.is_lt\n\n/- An obvious lemma about the behaviour of fin_nth. -/\nlemma fin_nth_cons (a : \u03b1) (l : list \u03b1) (i : fin l.length) :\n (list.cons a l).fin_nth i.succ = l.fin_nth i := \nbegin\n cases i,dsimp[fin.succ,fin_nth],refl,\nend\n\n/-\n If R is a relation on \u03b1 and l is a list, we define \n (pairwise_nth R l) to be true if all entries in l are R-related\n to all strictly later entries.  For example, if R is an order\n relation then this just means that the list is sorted, and if \n R is the relation x \u2260 y then this just means that l has no\n duplicates.  Here we define pairwise_nth in the obvious way\n using indices.  We then prove that our pairwise_nth is \n equivalent to the definition of pairwise in the standard \n library, which is formulated by structural induction rather\n than using indices.\n-/\n\ndef pairwise_nth\u2080 (R : \u03b1 \u2192 \u03b1 \u2192 Prop) (l : list \u03b1) := \n \u2200 (i j : fin l.length), i < j \u2192 R (l.fin_nth i) (l.fin_nth j)\n\ndef pairwise_nth (R : \u03b1 \u2192 \u03b1 \u2192 Prop) (l : list \u03b1) := \n \u2200 {i j : \u2115} (hi : i < j) (hj : j < l.length), \n   R (l.nth_le i (lt_trans hi hj)) (l.nth_le j hj)\n\nlemma pairwise_nth_mp {R : \u03b1 \u2192 \u03b1 \u2192 Prop} {l : list \u03b1} \n (p : pairwise R l) : pairwise_nth R l :=\nbegin\n  induction p with a l0 R_a_l0 p0 ih,\n  { intros i j hi hj, cases hj },\n  { intros i j hi hj,\n    rcases j with j, { cases hi },\n    have hj0 : j < l0.length := nat.lt_of_succ_lt_succ hj,\n    cases i with i,\n    { exact R_a_l0 _ (l0.nth_le_mem j hj0) },\n    { exact ih (nat.lt_of_succ_lt_succ hi) hj0 } }\nend\n\nlemma pairwise_nth_mpr {R : \u03b1 \u2192 \u03b1 \u2192 Prop} {l : list \u03b1} \n (hl : pairwise_nth R l) : (pairwise R l) := \nbegin\n  induction l with a l ih,\n  { exact @pairwise.nil _ R },\n  { have R_a_l : \u2200 (b \u2208 l), (R a b) :=\n    begin\n      intros b b_in_l,\n      rcases nth_le_of_mem b_in_l with \u27e8j,\u27e8hj,eq_b\u27e9\u27e9,\n      rw [\u2190 eq_b],\n      exact hl (nat.zero_lt_succ j) (nat.succ_lt_succ hj)\n    end,\n    have : l.pairwise R := \n    begin\n      apply ih,\n      intros i j hi hj,\n      exact hl (nat.succ_lt_succ hi) (nat.succ_lt_succ hj),\n    end,\n    exact pairwise.cons R_a_l this }\nend\n\nlemma pairwise_nth_iff {R : \u03b1 \u2192 \u03b1 \u2192 Prop} {l : list \u03b1} :\n (pairwise R l) \u2194 (pairwise_nth R l) :=\n  iff.intro (@pairwise_nth_mp _ R l) (@pairwise_nth_mpr _ R l)\n\n/-\n The standard library defines a list to be sorted if all entries are\n less than or equal to all strictly later entries.  Here we define \n a list to be strongly sorted if the relevant inequalities hold \n strictly.  This is clearly equivalent to saying that the list is\n sorted and has distinct entries; we also formalise this equivalence.\n-/\n\nvariables [linear_order \u03b1] [decidable_rel (@has_le.le \u03b1 _)]\n\ndef strongly_sorted (l : list \u03b1) : Prop := \n list.pairwise has_lt.lt l\n\nlemma strongly_sorted_of_sorted_nodup (l : list \u03b1) :\n l.sorted has_le.le \u2192 l.nodup \u2192 l.strongly_sorted := \nbegin\n intro l_sorted,\n induction l_sorted with a l0 a_le_l0 l0_sorted ih,\n {intro,exact pairwise.nil},\n {intro l_nodup,\n  cases l_nodup with _ _ a_ne_l0 l0_nodup,\n  have l0_strongly_sorted := ih l0_nodup,\n  have a_lt_l0 : \u2200 (x : \u03b1) (x_in_l0 : x \u2208 l0), (a < x) := \n  begin\n   intros x x_in_l0,\n   exact lt_of_le_of_ne (a_le_l0 x x_in_l0) (a_ne_l0 x x_in_l0),\n  end,\n  exact pairwise.cons a_lt_l0 l0_strongly_sorted,\n }\nend\n\nlemma sorted_of_strongly_sorted (l : list \u03b1) : \n l.strongly_sorted \u2192 l.sorted has_le.le := \nbegin\n intro l_strongly_sorted,\n induction l_strongly_sorted with a l0 a_lt_l0 l0_strongly_sorted ih,\n {exact pairwise.nil},\n {have a_le_l0 : \u2200 x \u2208 l0, a \u2264 x := \n   \u03bb x x_in_l0,le_of_lt (a_lt_l0 x x_in_l0),\n  have l0_sorted := ih,\n  exact pairwise.cons a_le_l0 l0_sorted\n }\nend\n\nlemma nodup_of_strongly_sorted (l : list \u03b1) : \n l.strongly_sorted \u2192 l.nodup := \nbegin\n intro l_strongly_sorted,\n induction l_strongly_sorted with a l0 a_ne_l0 l0_strongly_sorted ih,\n {exact pairwise.nil},\n {have a_ne_l0 : \u2200 x \u2208 l0, a \u2260 x := \n   \u03bb x x_in_l0,ne_of_lt (a_ne_l0 x x_in_l0),\n  have l0_nodup := ih,\n  exact pairwise.cons a_ne_l0 l0_nodup\n }\nend\n\n/-\n Sortedness is defined in the standard library by structural\n induction. Here we reformulate it in terms of indices.\n-/\n\nlemma sorted_nth_lt_mp {l : list \u03b1} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l)\n {i j : \u2115} (hi : i < j) (hj : j < l.length) :\n (l.nth_le i (lt_trans hi hj) < l.nth_le j hj) := \nbegin\n  let x := l.nth_le i (lt_trans hi hj),\n  let y := l.nth_le j hj,\n  have x_ne_y : x \u2260 y := pairwise_nth_mp l_nodup hi hj,\n  have x_le_y : x \u2264 y := pairwise_nth_mp l_sorted hi hj,\n  exact lt_of_le_of_ne x_le_y x_ne_y,\nend\n\nlemma sorted_nth_le_mp {l : list \u03b1} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l)\n {i j : \u2115} (hi : i \u2264 j) (hj : j < l.length) :\n (l.nth_le i (lt_of_le_of_lt hi hj) \u2264 l.nth_le j hj) := \nbegin\n by_cases h : i = j,\n { cases h, refl },\n { have hi' : i < j := lt_of_le_of_ne hi h,\n   exact (le_of_lt $ sorted_nth_lt_mp l_nodup l_sorted hi' hj) }\nend\n\nlemma sorted_nth_lt {l : list \u03b1} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l) \n { i j : \u2115 } (hi : i < l.length) (hj : j < l.length) :\n  (i < j) \u2194 (l.nth_le i hi < l.nth_le j hj) := \nbegin\n split,\n { intro hi', \n   exact sorted_nth_lt_mp l_nodup l_sorted hi' hj },\n { intro x_lt_y,\n   rcases lt_or_ge i j with i_lt_j | j_le_i,\n   { assumption },\n   { exfalso,\n     let y_le_x := sorted_nth_le_mp l_nodup l_sorted j_le_i hi,\n     exact not_lt_of_ge y_le_x x_lt_y } }\nend\n\nlemma sorted_nth_le {l : list \u03b1} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l) \n { i j : \u2115 } (hi : i < l.length) (hj : j < l.length) :\n  (i \u2264 j) \u2194 (l.nth_le i hi \u2264 l.nth_le j hj) := \nbegin\n split,\n { intro hi', \n   exact sorted_nth_le_mp l_nodup l_sorted hi' hj },\n { intro x_le_y,\n   rcases le_or_gt i j with i_le_j | j_lt_i,\n   { assumption },\n   { exfalso,\n     let y_lt_x := sorted_nth_lt_mp l_nodup l_sorted j_lt_i hi,\n     exact not_le_of_gt y_lt_x x_le_y } }\nend\n\nend list \n\nnamespace finset \n\nvariables [linear_order \u03b1] [decidable_rel (@has_le.le \u03b1 _)]\n\n/-\n The standard library defines a function that accepts a finite set s\n and returns the list of elements in sorted order.  The next lemma \n tells us how we can recognise that list if we have obtained it by\n other means.\n-/\n\ntheorem list.perm.eqv' (\u03b1 : Type*) : equivalence (@perm \u03b1) :=\nmk_equivalence (@perm \u03b1) (@perm.refl \u03b1) (@perm.symm \u03b1) (@perm.trans \u03b1)\n\ninstance list.is_setoid' (\u03b1 : Type*) : setoid (list \u03b1) :=\nsetoid.mk (@perm \u03b1) (list.perm.eqv' \u03b1)\n\nlemma sort_spec (s : finset \u03b1) (l : list \u03b1) \n (l_nodup : l.nodup) (l_sorted : l.sorted has_le.le) \n  (s_eq_l : s = l.to_finset) : s.sort has_le.le = l := \nbegin\n let h0 := (congr_arg val\n            (eq.trans (eq.trans (to_finset_eq (sort_nodup has_le.le s)) (eq.trans (sort_to_finset has_le.le s) s_eq_l)) \n                      (eq.symm (to_finset_eq l_nodup)))),\n let h1 := list.eq_of_sorted_of_perm (@quotient.exact (list \u03b1) (list.is_setoid' \u03b1) _ _ h0) (sort_sorted has_le.le s) l_sorted,\n let ll : multiset \u03b1 := quot.mk _ l,\n have ll_nodup : ll.nodup := multiset.coe_nodup.mpr l_nodup,\n have ll_eq : (\u27e8ll,ll_nodup\u27e9 : finset \u03b1) = l.to_finset := list.to_finset_eq l_nodup,\n let m := s.sort has_le.le,\n have m_nodup : m.nodup := s.sort_nodup has_le.le,\n have m_sorted : m.sorted has_le.le := s.sort_sorted has_le.le,\n let mm : multiset \u03b1 := quot.mk _ m,\n have mm_nodup : mm.nodup := multiset.coe_nodup.mpr m_nodup,\n have mm_eq : (\u27e8mm,mm_nodup\u27e9 : finset \u03b1) = m.to_finset := list.to_finset_eq m_nodup,\n have m_to_finset : m.to_finset = s :=\n  s.sort_to_finset has_le.le,\n let mm_eq_ll :=\n  congr_arg finset.val ((mm_eq.trans (m_to_finset.trans s_eq_l)).trans ll_eq.symm),\n dsimp[finset.val] at mm_eq_ll,\n have perm_m_l : perm m l := quotient.exact mm_eq_ll,\n exact list.eq_of_sorted_of_perm perm_m_l m_sorted l_sorted,\nend\n\n/-\n The next lemma is equivalent to the previous one.  However, as an \n experiment we have written it as a single term rather than using \n tactics.  We used the command \"#print sort_spec\" to print the \n proof term generated automatically be Lean from the tactic proof, \n and then reorganised it a bit to eliminate some inefficiencies.\n-/\n\nlemma sort_spec_alt (s : finset \u03b1) (l : list \u03b1) \n (l_nodup : l.nodup) (l_sorted : l.sorted has_le.le) \n  (s_eq_l : s = l.to_finset) : s.sort has_le.le = l := \n    list.eq_of_sorted_of_perm \n     (@quotient.exact \n      (list \u03b1)\n      (list.is_setoid' \u03b1) \n      _ \n      _ \n      (@congr_arg \n       (finset \u03b1)\n       (multiset \u03b1) \n       _ \n       _ \n       finset.val \n       (eq.trans\n        (eq.trans (to_finset_eq (sort_nodup has_le.le s)) (eq.trans (sort_to_finset has_le.le s) s_eq_l))\n        (eq.symm (to_finset_eq l_nodup))\n       )\n      )\n     )\n     (sort_sorted has_le.le s) \n     l_sorted\n\nsection rank_equiv \n\n/-\n We now give our first version of the fact that any finite, linearly ordered \n set of size n is order-isomorphic to (fin n). In this version, the type \u03b1 has\n a decidable linear order and s is a finite subset of \u03b1 that need not contain \n all elements of \u03b1.  In order to talk about an order-equivalence we need to \n convert s into a separate type by considering {a // a \u2208 s}. The definition \n (rank_equiv s) gives an equivalence from this type to (fin n), but it is not \n initially packaged with any information about order-preserving properties.  \n Instead, we prove those properties as four separate lemmas after the \n definition of rank_equiv.\n\n Note that we have arguments n and s_card : s.card = n, and we produce an\n equivalence with (fin n).  One might think that it would be more natural to\n just produce an equivalence with (fin s.card), and then use eq.mp to convert\n this to (fin n) if necessary.  Unfortunately, this leads to a lot of tedious \n troubles with heterogenous equality.  As far as I can tell, the present \n approach is the simplest way to avoid that.\n-/\n\nvariables {s : finset \u03b1} {n : \u2115} (s_card : s.card = n)\ninclude s_card\n\ndef rank_equiv : { a // a \u2208 s } \u2243 fin n := \nbegin\n let l := s.sort has_le.le,\n have l_nodup : list.nodup l := finset.sort_nodup has_le.le s,\n have l_eq_s : l.to_finset = s := by simp[finset.sort_eq],\n have l_len : l.length = n := \n  ((@eq.subst (finset \u03b1) (\u03bb t, t.card = l.length) _ _ l_eq_s\n             (list.to_finset_card_of_nodup l_nodup)).symm).trans s_card,\n let mem_equiv : \u2200 a : \u03b1, a \u2208 s \u2194 a \u2208 l :=\n  \u03bb a, @eq.subst (finset \u03b1) (\u03bb t, a \u2208 t \u2194 a \u2208 l) _ _ l_eq_s\n         (@list.mem_to_finset \u03b1 _ a l),\n let to_fun : { a // a \u2208 s } \u2192 fin n := \n begin\n  intro a,\n  have a_in_l : a.val \u2208 l := (mem_equiv a.val).mp a.property,\n  let i : \u2115 := list.index_of a.val l,\n  have i_lt_n : i < n :=\n   l_len.subst (list.index_of_lt_length.mpr a_in_l),\n  exact \u27e8i,i_lt_n\u27e9 \n end,\n let inv_fun : fin n \u2192 { a // a \u2208 s } := \n begin\n  intro i,\n  have i_is_lt : i.val < l.length := @eq.subst \u2115 (\u03bb m, i.val < m) _ _ l_len.symm i.is_lt,\n  let a := l.nth_le i.val i_is_lt,\n  have a_in_s : a \u2208 s := (mem_equiv a).mpr (l.nth_le_mem i.val i_is_lt),\n  exact \u27e8a,a_in_s\u27e9 \n end,\n have left_inv : \u2200 a, inv_fun (to_fun a) = a := \n begin\n  intro a,\n  rcases a with \u27e8a_val,a_in_s\u27e9,\n  have a_in_l : a_val \u2208 l := (mem_equiv a_val).mp a_in_s, \n  let i := list.index_of a_val l,\n  have i_lt_len : i < l.length := list.index_of_lt_length.mpr a_in_l,\n  have i_lt_n : i < n := l_len.subst i_lt_len,\n  dsimp[inv_fun,to_fun],\n  apply subtype.eq,dsimp[subtype.val],\n  exact list.index_of_nth_le i_lt_len,\n end,\n have right_inv : \u2200 i, to_fun (inv_fun i) = i := \n begin\n  intro i,\n  rcases i with \u27e8i_val,i_lt_n\u27e9,\n  have i_lt_len : i_val < l.length := l_len.symm.subst i_lt_n,\n  dsimp[inv_fun,to_fun],\n  apply fin.eq_of_veq,dsimp[fin.val],\n  exact list.nth_le_index_of l_nodup i_val i_lt_len,\n end,\n exact \u27e8to_fun,inv_fun,left_inv,right_inv\u27e9, \nend\n\nlemma seq_le (i1 i2 : fin n) :\n i1 \u2264 i2 \u2194 (((rank_equiv s_card).inv_fun i1).val \u2264 ((rank_equiv s_card).inv_fun i2).val) := \nbegin\n dsimp [rank_equiv, nth_le, has_le.le, fin.le],\n let l := s.sort has_le.le,\n have l_nodup : list.nodup l := finset.sort_nodup has_le.le s,\n have l_sorted : l.sorted has_le.le := sort_sorted has_le.le s,\n have l_eq_s : l.to_finset = s := by simp[finset.sort_eq],\n have l_len : l.length = n := \n  ((@eq.subst (finset \u03b1) (\u03bb t, t.card = l.length) _ _ l_eq_s\n             (list.to_finset_card_of_nodup l_nodup)).symm).trans s_card,\n have i1p : i1.val < l.length := by { rw[l_len], exact i1.is_lt },\n have i2p : i2.val < l.length := by { rw[l_len], exact i2.is_lt },\n exact list.sorted_nth_le l_nodup l_sorted i1p i2p\nend\n\nlemma seq_lt (i1 i2 : fin n) :\n i1 < i2 \u2194 (((rank_equiv s_card).inv_fun i1).val < ((rank_equiv s_card).inv_fun i2).val) := \nbegin\n dsimp [rank_equiv, nth_le, has_le.le, fin.le],\n let l := s.sort has_le.le,\n have l_nodup : list.nodup l := finset.sort_nodup has_le.le s,\n have l_sorted : l.sorted has_le.le := sort_sorted has_le.le s,\n have l_eq_s : l.to_finset = s := by simp[finset.sort_eq],\n have l_len : l.length = n := \n  ((@eq.subst (finset \u03b1) (\u03bb t, t.card = l.length) _ _ l_eq_s\n             (list.to_finset_card_of_nodup l_nodup)).symm).trans s_card,\n have i1p : i1.val < l.length := by { rw[l_len], exact i1.is_lt },\n have i2p : i2.val < l.length := by { rw[l_len], exact i2.is_lt },\n exact list.sorted_nth_lt l_nodup l_sorted i1p i2p\nend\n\nlemma rank_le (a1 a2 : {a // a \u2208 s }) :\n a1.val \u2264 a2.val \u2194 (rank_equiv s_card).to_fun a1 \u2264 (rank_equiv s_card).to_fun a2 := \nbegin\n let f := rank_equiv s_card,\n let i1 := f.to_fun a1,\n let i2 := f.to_fun a2,\n let a1a := f.inv_fun i1,\n let a2a := f.inv_fun i2,\n let h := ((seq_le s_card) (f.to_fun a1) (f.to_fun a2)).symm,\n let e1 : (f.inv_fun i1).val = a1.val := congr_arg subtype.val (f.left_inv a1),\n let e2 : (f.inv_fun i2).val = a2.val := congr_arg subtype.val (f.left_inv a2),\n split,\n {intro h1,rw[\u2190 e1,\u2190 e2] at h1,exact h.mp h1,},\n {intro h2,let h3 := h.mpr h2,rw[e1,e2] at h3,exact h3}\nend\n\nlemma rank_lt (a1 a2 : {a // a \u2208 s }) :\n a1.val < a2.val \u2194 ((rank_equiv s_card).to_fun a1) < ((rank_equiv s_card).to_fun a2) := \nbegin\n let f := rank_equiv s_card,\n let i1 := f.to_fun a1,\n let i2 := f.to_fun a2,\n let a1a := f.inv_fun i1,\n let a2a := f.inv_fun i2,\n let h := ((seq_lt s_card) (f.to_fun a1) (f.to_fun a2)).symm,\n let e1 : (f.inv_fun i1).val = a1.val := congr_arg subtype.val (f.left_inv a1),\n let e2 : (f.inv_fun i2).val = a2.val := congr_arg subtype.val (f.left_inv a2),\n split,\n {intro h1,rw[\u2190 e1,\u2190 e2] at h1,exact h.mp h1,},\n {intro h2,let h3 := h.mpr h2,rw[e1,e2] at h3,exact h3}\nend\n\nlemma rank_as_card (a : { x // x \u2208 s}) :\n ((rank_equiv s_card).to_fun a).val = card (s.filter (\u03bb x, x < a.val)) := \nbegin\n let f := rank_equiv s_card,\n let u := s.filter (\u03bb x, x < a.val),\n let ut := {x // x \u2208 u},\n let k := f.to_fun a,\n have fi_k : f.inv_fun k = a := f.left_inv a,\n let g_to_fun : ut \u2192 fin k.val := \n begin\n  intro x,\n  let x0 : { x // x \u2208 s } := \u27e8x.val,(mem_filter.mp x.property).left\u27e9,\n  let x_lt_a : x0.val < a.val := (mem_filter.mp x.property).right,\n  let i := f.to_fun x0,\n  let i_lt_k : i < k := ((rank_lt s_card) x0 a).mp x_lt_a,\n  let i_lt_k_val : i.val < k.val := \n  begin\n   let h := i_lt_k,\n   dsimp[has_lt.lt,fin.lt] at h,\n   exact h,\n  end,\n  exact \u27e8i.val,i_lt_k_val\u27e9,\n end,\n let g_inv_fun : fin k.val \u2192 ut := \n begin\n  intro i,\n  let i0 : fin n := \u27e8i.val,lt_trans i.is_lt k.is_lt\u27e9,\n  have i0_lt_k : i0 < k := by { simp[has_lt.lt,fin.lt], exact i.is_lt,},\n  let x0 := f.inv_fun i0,\n  let x_lt_a := ((seq_lt s_card) i0 k).mp i0_lt_k,\n  rw[fi_k] at x_lt_a,\n  have x_in_u : x0.val \u2208 u := \n  begin\n   apply mem_filter.mpr,\n   exact \u27e8x0.property,x_lt_a\u27e9,\n  end,\n  exact \u27e8x0.val,x_in_u\u27e9, \n end,\n have g_left_inv : \u2200 x, g_inv_fun (g_to_fun x) = x := \n begin\n  intro x,\n  dsimp[g_to_fun,g_inv_fun],\n  apply subtype.eq; simp[subtype.val],\n  exact congr_arg subtype.val (f.left_inv _),\n end,\n have g_right_inv : \u2200 i, g_to_fun (g_inv_fun i) = i := \n begin\n  intro i,\n  dsimp[g_to_fun,g_inv_fun],\n  apply fin.eq_of_veq; simp[fin.val],\n  exact congr_arg fin.val (f.right_inv _),\n end,\n let g : ut \u2243 fin k.val := \u27e8g_to_fun,g_inv_fun,g_left_inv,g_right_inv\u27e9,\n let h0 := fintype.card_congr g, \n let h1 := @finset.card_attach \u03b1 u,\n let h2 := fintype.card_fin k.val,\n exact (h1.symm.trans (h0.trans h2)).symm,\nend\n\nend rank_equiv\n\nend finset\n\nnamespace fintype\nopen finset fintype \n\nvariables [linear_order \u03b1] [decidable_rel (@has_le.le \u03b1 _)]\nvariables [fintype \u03b1] {n : \u2115} (\u03b1_card : card \u03b1 = n)\ninclude \u03b1_card\n\n/-\n We now give our second version of the fact that any finite, linearly ordered \n set of size n is order-isomorphic to (fin n). In this version we assume given\n an instance of (fintype \u03b1), which is essentially a proof that the whole type \n \u03b1 is finite. From this we build an equivalence from \u03b1 to (fin n), and again \n we prove the order properties as separate lemmas.\n-/\n\ndef rank_equiv : \u03b1 \u2243 fin n := \nbegin\n have h0 : finset.card (@elems \u03b1 _) = n := \u03b1_card,\n let f := finset.rank_equiv h0,\n let to_fun : \u03b1 \u2192 fin n := \u03bb a, f.to_fun \u27e8a,mem_univ a\u27e9,\n let inv_fun : fin n \u2192 \u03b1 := \u03bb i, (f.inv_fun i).val,\n have left_inv : \u2200 a : \u03b1, inv_fun (to_fun a) = a := \n  \u03bb a, congr_arg subtype.val (f.left_inv \u27e8a,mem_univ a\u27e9),\n have right_inv : \u2200 i : fin n, to_fun (inv_fun i) = i := \n begin\n  intro i,\n  have e : f.inv_fun i = \u27e8inv_fun i,mem_univ _\u27e9 := \n   by {apply subtype.eq,simp[inv_fun]},\n  dsimp[inv_fun,to_fun],rw[\u2190 e],exact f.right_inv i,\n end,\n exact \u27e8to_fun,inv_fun,left_inv,right_inv\u27e9,\nend\n\nlemma seq_le (i1 i2 : fin n) : \n i1 \u2264 i2 \u2194 (rank_equiv \u03b1_card).inv_fun i1 \u2264 (rank_equiv \u03b1_card).inv_fun i2 := \n  (seq_le \u03b1_card) i1 i2\n\nlemma seq_lt (i1 i2 : fin n) : \n i1 < i2 \u2194 (rank_equiv \u03b1_card).inv_fun i1 < (rank_equiv \u03b1_card).inv_fun i2 := \n  (seq_lt \u03b1_card) i1 i2\n\nlemma rank_le (a1 a2 : \u03b1) : \n a1 \u2264 a2 \u2194 (rank_equiv \u03b1_card).to_fun a1 \u2264 (rank_equiv \u03b1_card).to_fun a2 := \n  (rank_le \u03b1_card) \u27e8a1,mem_univ a1\u27e9 \u27e8a2,mem_univ a2\u27e9\n\nlemma rank_lt (a1 a2 : \u03b1) : \n a1 < a2 \u2194 (rank_equiv \u03b1_card).to_fun a1 < (rank_equiv \u03b1_card).to_fun a2 := \n  (rank_lt \u03b1_card) \u27e8a1,mem_univ a1\u27e9 \u27e8a2,mem_univ a2\u27e9\n\nend fintype\n\nnamespace fin \n/-\n The only strictly increasing self-map of (fin n) is the identity\n-/\nlemma rigid {n : \u2115} {f : fin n \u2192 fin n} \n (f_mono : \u2200 {i1 i2 : fin n}, i1 < i2 \u2192 (f i1) < (f i2)) :\n  \u2200 (i : fin n), f i = i := \nbegin\n induction n with n0 ih,\n {intro i,exact fin.elim0 i},\n {\n  let f0 : fin n0 \u2192 fin n0 := \n  begin\n   intro i0,\n   let h0 := ne_of_lt (lt_of_le_of_lt (fin.zero_le (f 0)) (f_mono (@fin.zero_lt_succ n0 i0))), \n   exact fin.pred (f i0.succ) h0.symm,\n  end,\n  have succ_f0 : \u2200 (i0 : fin n0), (f0 i0).succ = f i0.succ := \n  begin\n   intro i0,\n   let h0 := ne_of_lt (lt_of_le_of_lt (fin.zero_le (f 0)) (f_mono (@fin.zero_lt_succ n0 i0))), \n   exact fin.succ_pred (f i0.succ) h0.symm,\n  end,\n  have f0_mono : \u2200 {i1 i2 : fin n0}, i1 < i2 \u2192 (f0 i1) < (f0 i2) :=\n  begin\n   intros i1 i2 i1_lt_i2,\n   let h0 := f_mono (fin.succ_lt_succ i1_lt_i2),\n   rw[\u2190 (succ_f0 i1)] at h0,\n   rw[\u2190 (succ_f0 i2)] at h0,\n   exact fin.lt_of_succ_lt_succ h0,\n  end,\n  let f0_id := ih @f0_mono,\n  have f_zero_a : \u2200 (j : fin n0.succ), f 0 = j \u2192 j = 0 := \n  begin\n   intros j e, cases j, cases j_val with j0_val,\n   {refl},\n   {\n     exfalso,\n     have j0_is_lt : j0_val < n0 := nat.lt_of_succ_lt_succ j_is_lt,\n     let j0 : fin n0 := \u27e8j0_val,j0_is_lt\u27e9,\n     let j := j0.succ,\n     have h0 : f j = j := (succ_f0 j0).symm.trans (congr_arg fin.succ (f0_id j0)), \n     have h1 : f 0 < f j := f_mono (@fin.zero_lt_succ n0 j0),\n     have h2 : j < f j := @eq.subst (fin n0.succ) (\u03bb k, k < f j) _ _ e h1,\n     exact (ne_of_lt h2) h0.symm,\n   }\n  end,\n  have f_zero : f 0 = 0 := f_zero_a (f 0) rfl,\n  intro i, cases i, cases i_val with i0_val,\n  {exact f_zero,},\n  {\n   have i0_is_lt : i0_val < n0 := nat.lt_of_succ_lt_succ i_is_lt,\n   let h0 := congr_arg fin.succ (f0_id \u27e8i0_val,i0_is_lt\u27e9),\n   let h1 := succ_f0 \u27e8i0_val,i0_is_lt\u27e9,\n   let h2 := h1.symm.trans h0,\n   exact h2,\n  }\n }\nend\n\nend fin", "meta": {"author": "NeilStrickland", "repo": "itloc", "sha": "5b13b5b418766d10926b983eb3dd2ac42abf63d8", "save_path": "github-repos/lean/NeilStrickland-itloc", "path": "github-repos/lean/NeilStrickland-itloc/itloc-5b13b5b418766d10926b983eb3dd2ac42abf63d8/src/sort_rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7361696625898064}}
{"text": "\n-- Level 1\nexample (P Q : Type) (p : P) (h : P \u2192 Q) : Q :=\n\nbegin\n\nexact h p\n\nend\n-- * Level 2\n\nimport mynat.add -- + on mynat\nimport mynat.mul -- * on mynat\n\n\nexample : mynat \u2192 mynat :=\n\nbegin\n\nintro n,\nexact 3*n+2\n\nend\n\n-- *  Level 3\n\nexample (P Q R S T U: Type)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U :=\n\nbegin\n\nhave q : Q := h(p),\nhave t : T := j(q),\nhave u : U := l(t),\nexact u\n\nend\n-- Level 4\nexample (P Q R S T U: Type)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U :=\n\nbegin\nhave q : Q := h(p),\nhave t : T := j(q),\nhave u : U := l(t),\nexact u\n\nend\n\n-- Level 5\n\nexample (P Q : Type) : P \u2192 (Q \u2192 P) :=\n\nbegin\n\nintro p,\nintro q,\nexact p\n\nend\n\n-- Level 6\nexample (P Q R : Type) : (P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R)) :=\n\nbegin\n\nintro f,\nintro g,\nintro h,\n\nhave j := f h,\n\napply j,\napply g,\nexact h\n\nend\n-- Level 7\nexample (P Q F : Type) : (P \u2192 Q) \u2192 ((Q \u2192 F) \u2192 (P \u2192 F)) :=\n\nbegin\nintros f h p,\nexact h(f(p))\nend\n-- Level 8\n\nexample (P Q : Type) : (P \u2192 Q) \u2192 ((Q \u2192 empty) \u2192 (P \u2192 empty)) :=\n\nbegin\n\nintros f h p,\napply h,\napply f,\nexact p\n\nend\n", "meta": {"author": "marcelovmaciel", "repo": "learning_lean", "sha": "0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4", "save_path": "github-repos/lean/marcelovmaciel-learning_lean", "path": "github-repos/lean/marcelovmaciel-learning_lean/learning_lean-0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4/nngame/function_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7361667063374644}}
{"text": "-- propositions\n-- proofs\n-- predicates\n    -- sets\n    -- relations\n    -- equality\n-- connectives\n    -- not\n    -- and\n    -- or\n\n-- proposition\ninductive nifty_was_a_cat : Prop\n-- proof\n| there_are_pictures_of_nifty\n| we_remember_nifty_fondly\n\ninductive pet : Type \n| nifty\n| tom\n| cheese\n| kevin\n\nopen pet\n\ninductive was_a_cat : pet \u2192 Prop\n| nifty_proof : was_a_cat nifty\n| tom_proof : was_a_cat tom\n\nopen was_a_cat\n\ntheorem nifty_cat : was_a_cat nifty := nifty_proof\n\n-- Predicates with single arguments, in essence, define a *set*\n-- The elements of this set all satisfy the predicate\n-- (elements that do not satisfy the predicate are not members)\n-- A kind of \"membership test\" for being in a set\n\ninductive and'' (\u03b1 \u03b2 : Prop) : Prop\n| intro : \u03b1 \u2192 \u03b2 \u2192 and''\n\ndef nwac_and_cwac : Prop := and'' (was_a_cat nifty) (was_a_cat cheese)\n\ntheorem pf : (and'' (was_a_cat nifty) (was_a_cat tom)) := and''.intro (nifty_proof) (tom_proof)\n\ndef and''_intro (\u03b1 \u03b2 : Prop) : \u03b1 \u2192 \u03b2 \u2192 (and'' \u03b1 \u03b2) := and''.intro\n\ndef and''_elim_left {\u03b1 \u03b2 : Prop} : (and'' \u03b1 \u03b2) \u2192 \u03b1\n| (and''.intro a b) := a\n\ndef and''_elim_right {\u03b1 \u03b2 : Prop} : (and'' \u03b1 \u03b2) \u2192 \u03b2 \n| (and''.intro a b) := b\n\ntheorem twac : (was_a_cat tom) := (and''_elim_right pf)\n\n-- if you have a data type of one constructor, you can use the \"structure\" keyword to declare it\n\ninductive and''' (\u03b1 \u03b2 : Prop) : Prop \n| intro (left : \u03b1) (right : \u03b2) : and'''\n\nstructure and' (a b : Prop) : Prop := intro :: (left : a) (right : b)", "meta": {"author": "joek13", "repo": "cs2102-notes", "sha": "25bb18788641b20af9cf3c429afe1da9b2f5eafb", "save_path": "github-repos/lean/joek13-cs2102-notes", "path": "github-repos/lean/joek13-cs2102-notes/cs2102-notes-25bb18788641b20af9cf3c429afe1da9b2f5eafb/11-05-2019.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7361667042589564}}
{"text": "import data.nat.prime\nimport tactic.norm_num\nimport data.list.basic\nopen nat\nopen list\n\ntheorem exists_prime_prod: \u2200x:\u2115,1\u2264x\u2192\u2203L:list \u2115,(\u2200p:\u2115,p \u2208 L\u2192prime p)\u2227prod L=x:=begin\n    have Hstrong:\u2200 y x:\u2115,x\u2264y\u21921\u2264x\u2192\u2203L:list \u2115,(\u2200p:\u2115,p \u2208 L\u2192prime p)\u2227prod L=x:=begin\n        intro,induction y with y1 Hiy,\n        intros,rw eq_zero_of_le_zero a at a_1,revert a_1,norm_num,intros,\n        cases x with x1,revert a_1,norm_num,\n        cases x1 with x2,existsi nil,norm_num,\n        cases classical.em (prime (succ(succ x2))) with A A,\n        existsi ([succ (succ x2)]),norm_num,exact A,\n        have H:=exists_dvd_of_not_prime2 (dec_trivial:2\u2264succ(succ x2)) A,\n        cases H with b Hb,cases Hb with Hbd Hb,cases Hb with Hb2 Hbx,\n        have H:=exists_eq_mul_right_of_dvd Hbd,cases H with c Hbc,rw eq_comm at Hbc,\n        have H3:=succ_ne_zero (succ x2),rw \u2190Hbc at H3,\n        have H2:= iff.elim_right pos_iff_ne_zero (ne_zero_of_mul_ne_zero_left H3),\n        have H1:=iff.elim_right (lt_mul_iff_one_lt_left (iff.elim_right pos_iff_ne_zero (ne_zero_of_mul_ne_zero_left H3))) (lt_of_lt_of_le (dec_trivial:1<2) Hb2),rw Hbc at H1,\n        cases Hiy b (le_of_succ_le_succ (le_trans (succ_le_of_lt Hbx) a)) (le_trans (dec_trivial:1\u22642) Hb2) with B HB,\n        cases Hiy c (le_of_succ_le_succ (le_trans (succ_le_of_lt H1) a)) (succ_le_of_lt H2) with C HC,existsi B++C,norm_num,intros,apply and.intro,\n        rwa [and.right HB,and.right HC],intros,cases a_2,exact and.left HB p a_2,exact and.left HC p a_2,\n    end,exact \u03bb x,Hstrong x x (le_refl x),\nend \ntheorem bezout: \u2200 b c:\u2115,\u2203x y:\u2124, \u2191b*x+\u2191c*y = \u2191(gcd b c):=begin\n    assume b c,apply gcd.induction b c,\n    simp [gcd],intro,existsi (1:\u2124),simp,\n    assume m n Hm,assume Hmn,cases Hmn with x1 Hx,cases Hx with y1 Hxy,\n    cases m with m,simp [lt_irrefl] at Hm,revert Hm,trivial,\n    unfold gcd,rw \u2190Hxy,existsi -\u2191(n/succ m)*x1+y1,existsi x1,\n    have H: n%succ m=n-(succ m)*(n/(succ m)):=begin rw [eq_comm,nat.sub_eq_iff_eq_add,mod_add_div n (succ m)],rw mul_comm,exact div_mul_le_self n (succ m) end,rw H,\n    rw [int.coe_nat_sub,mul_add,add_assoc,add_comm (\u2191(succ m) * y1) (\u2191n * x1),\u2190add_assoc,add_right_cancel_iff,mul_sub_right_distrib,int.coe_nat_mul],norm_num,\n    rw mul_comm,exact div_mul_le_self n (succ m),\nend\ntheorem euclid: \u2200b c p:\u2115, prime p \u2192 p \u2223 (b*c) \u2192 p \u2223 b \u2228 p \u2223 c:=begin\n    assume b c p Hp Hpbc,unfold prime at Hp,\n    cases(and.right Hp (gcd c p) (and.right (gcd_dvd c p))) with A A,\n    cases (bezout c p)with x H,cases H with y H,rw A at H,\n    have H1:\u2191(b*c)*x+\u2191(p*b)*y=\u2191b:=by{have H:\u2191b*\u2191c*x+\u2191b*\u2191p*y=\u2191b*\u21911:=by{rw[\u2190H,mul_add],norm_num},simp at H,rw\u2190H,norm_num},left,\n    have H2:=dvd_mul_of_dvd_left (iff.elim_right int.coe_nat_dvd Hpbc) x,\n    have H3:=dvd_mul_of_dvd_left (iff.elim_right int.coe_nat_dvd (dvd_mul_of_dvd_left (dvd_refl p) b)) y,\n    have H4:=dvd_add H2 H3,rw H1 at H4,rwa \u2190int.coe_nat_dvd,right,rw \u2190A,\n    exact and.left (gcd_dvd c p),\nend\ntheorem dvd_prod_of_mem: \u2200 (p:\u2115) (L:list \u2115),p\u2208L\u2192 p \u2223 prod L:=begin\n    assume p L,revert p,\n    induction L with p1 L1 HiL,\n        norm_num,\n        exact \u03bb p2 Hp, dvd_mul_of_dvd_right (HiL p2 Hp) p1,\nend\ntheorem mem_of_prime_dvd_prod: \u2200 (B:list \u2115)(p:\u2115),prime p\u2192(\u2200pB, pB \u2208 B \u2192 prime pB)\u2192p \u2223 prod B \u2192 p \u2208 B:=begin\n    assume B,\n    induction B with p1 B1 Hi,\n    rw prod_nil,assume p Hp H H2,exfalso,revert H2,\n    exact prime.not_dvd_one Hp,\n    assume p2 Hp2 H H1,\n    norm_num,rw prod_cons at H1,\n    have H2:=euclid p1 (prod B1) p2 Hp2 H1,\n    cases H2 with A A,left,\n    have H3:=H p1,\n    revert H3,norm_num,assume H4,\n    unfold prime at H4,\n    have H5:=and.right H4 p2 A,\n    have H6:\u00acp2=1:=begin unfold prime at Hp2,intro,rw a at Hp2,simp at Hp2,revert Hp2,exact dec_trivial,end,\n    simp [H6] at H5,assumption,right,\n    have H3:(\u2200 (pB : \u2115), pB \u2208 B1 \u2192 prime pB):=begin revert H, norm_num,end,have H2:= Hi p2 Hp2 H3 A,assumption,\nend\ntheorem  unique_prime_factorization: \u2200 A B:list \u2115,prod A=prod B\u2192(\u2200p:\u2115, p\u2208A\u2192prime p)\u2192(\u2200 p:\u2115,p\u2208 B\u2192 prime p)\u2192A~B:=begin\n    assume A,\n    induction A with pA A Hi,\n    rw prod_nil,norm_num,\n    assume B HP HA,\n    have H:\u2200 p,p\u2208 B\u2192 \u00acp\u2208 B:=begin intros p HpB,\n        have H1:=dvd_prod_of_mem p B HpB,\n        rw \u2190HP at H1,exfalso,\n        exact prime.not_dvd_one (HA p HpB) H1,\n    end,apply perm.symm,rw perm_nil, cases B,trivial,exfalso,\n    exact H a (mem_cons_self a a_1) (mem_cons_self a a_1),\n    assume B HP HA HB,\n    rw prod_cons at HP,\n    have H8:pA \u2223 prod B:=begin\n        have H1:=dvd_mul_of_dvd_left (dvd_refl pA) (prod A),\n        rwa HP at H1,\n    end,\n    have HppA: prime pA:=begin apply HA,norm_num,  end,\n    have H9:=mem_of_prime_dvd_prod B pA HppA HB H8,\n    have H11:=prod_eq_of_perm (perm_erase H9),rw [H11,prod_cons] at HP,\n    rw nat.mul_left_inj (gt_of_ge_of_gt (and.left HppA) (dec_trivial:2>0)) at HP,\n    have HA1:\u2200 (p : \u2115), p \u2208 A \u2192 prime p:=begin revert HA,norm_num,end,\n    have HB1:\u2200 (p : \u2115), p \u2208(list.erase B pA) \u2192 prime p:=\u03bb p Hp,HB p (mem_of_mem_erase Hp),\n    have Hi2:= iff.elim_right (perm_cons pA) (Hi (list.erase B pA) HP HA1 HB1),\n    exact perm.trans Hi2 (perm.symm (perm_erase H9)),\nend\ntheorem fundamental_theorem_of_arithmetic: \u2200n:\u2115,1\u2264n\u2192\u2203L:list \u2115,(\u2200p:\u2115,p\u2208L\u2192prime p)\u2227prod L=n\u2227\u2200M:list \u2115,((\u2200p:\u2115,p\u2208M\u2192prime p)\u2192prod M=n\u2192L~M):=begin\n    assume n Hn,\n    cases (exists_prime_prod n Hn) with L HL, existsi L,\n    apply and.intro (and.left HL),\n    apply and.intro (and.right HL),\n    intros M H1 H2,\n    rw[eq_comm,\u2190and.right HL] at H2,\n    exact (unique_prime_factorization L) M H2 (and.left HL) H1,\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/student_contributions/Chris_Hughes_FTA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7361666991746403}}
{"text": "/-\nCopyright (c) 2020 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n-/\nimport analysis.convex.function\nimport topology.algebra.affine\nimport topology.local_extr\nimport topology.metric_space.basic\n\n/-!\n# Minima and maxima of convex functions\n\nWe show that if a function `f : E \u2192 \u03b2` is convex, then a local minimum is also\na global minimum, and likewise for concave functions.\n-/\n\nvariables {E \u03b2 : Type*} [add_comm_group E] [topological_space E]\n  [module \u211d E] [topological_add_group E] [has_continuous_smul \u211d E]\n  [ordered_add_comm_group \u03b2] [module \u211d \u03b2] [ordered_smul \u211d \u03b2]\n  {s : set E}\n\nopen set filter function\nopen_locale classical topology\n\n/--\nHelper lemma for the more general case: `is_min_on.of_is_local_min_on_of_convex_on`.\n-/\nlemma is_min_on.of_is_local_min_on_of_convex_on_Icc {f : \u211d \u2192 \u03b2} {a b : \u211d} (a_lt_b : a < b)\n  (h_local_min : is_local_min_on f (Icc a b) a) (h_conv : convex_on \u211d (Icc a b) f) :\n  is_min_on f (Icc a b) a :=\nbegin\n  rintro c hc, dsimp only [mem_set_of_eq],\n  rw [is_local_min_on, nhds_within_Icc_eq_nhds_within_Ici a_lt_b] at h_local_min,\n  rcases hc.1.eq_or_lt with rfl|a_lt_c, { exact le_rfl },\n  have H\u2081 : \u2200\u1da0 y in \ud835\udcdd[>] a, f a \u2264 f y,\n    from h_local_min.filter_mono (nhds_within_mono _ Ioi_subset_Ici_self),\n  have H\u2082 : \u2200\u1da0 y in \ud835\udcdd[>] a, y \u2208 Ioc a c,\n    from Ioc_mem_nhds_within_Ioi (left_mem_Ico.2 a_lt_c),\n  rcases (H\u2081.and H\u2082).exists with \u27e8y, hfy, hy_ac\u27e9,\n  rcases (convex.mem_Ioc a_lt_c).mp hy_ac with \u27e8ya, yc, ya\u2080, yc\u2080, yac, rfl\u27e9,\n  suffices : ya \u2022 f a + yc \u2022 f a \u2264 ya \u2022 f a + yc \u2022 f c,\n    from (smul_le_smul_iff_of_pos yc\u2080).1 (le_of_add_le_add_left this),\n  calc ya \u2022 f a + yc \u2022 f a = f a : by rw [\u2190 add_smul, yac, one_smul]\n  ... \u2264 f (ya * a + yc * c)      : hfy\n  ... \u2264 ya \u2022 f a + yc \u2022 f c      : h_conv.2 (left_mem_Icc.2 a_lt_b.le) hc ya\u2080 yc\u2080.le yac\nend\n\n/--\nA local minimum of a convex function is a global minimum, restricted to a set `s`.\n-/\nlemma is_min_on.of_is_local_min_on_of_convex_on {f : E \u2192 \u03b2} {a : E}\n  (a_in_s : a \u2208 s) (h_localmin : is_local_min_on f s a) (h_conv : convex_on \u211d s f) :\n  is_min_on f s a :=\nbegin\n  intros x x_in_s,\n  let g : \u211d \u2192\u1d43[\u211d] E := affine_map.line_map a x,\n  have hg0 : g 0 = a := affine_map.line_map_apply_zero a x,\n  have hg1 : g 1 = x := affine_map.line_map_apply_one a x,\n  have hgc : continuous g, from affine_map.line_map_continuous,\n  have h_maps : maps_to g (Icc 0 1) s,\n  { simpa only [maps_to', \u2190 segment_eq_image_line_map]\n      using h_conv.1.segment_subset a_in_s x_in_s },\n  have fg_local_min_on : is_local_min_on (f \u2218 g) (Icc 0 1) 0,\n  { rw \u2190 hg0 at h_localmin,\n    exact h_localmin.comp_continuous_on h_maps hgc.continuous_on (left_mem_Icc.2 zero_le_one) },\n  have fg_min_on : is_min_on (f \u2218 g) (Icc 0 1 : set \u211d) 0,\n  { refine is_min_on.of_is_local_min_on_of_convex_on_Icc one_pos fg_local_min_on _,\n    exact (h_conv.comp_affine_map g).subset h_maps (convex_Icc 0 1) },\n  simpa only [hg0, hg1, comp_app, mem_set_of_eq] using fg_min_on (right_mem_Icc.2 zero_le_one)\nend\n\n/-- A local maximum of a concave function is a global maximum, restricted to a set `s`. -/\nlemma is_max_on.of_is_local_max_on_of_concave_on {f : E \u2192 \u03b2} {a : E}\n  (a_in_s : a \u2208 s) (h_localmax: is_local_max_on f s a) (h_conc : concave_on \u211d s f) :\n  is_max_on f s a :=\n@is_min_on.of_is_local_min_on_of_convex_on _ \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ s f a a_in_s h_localmax h_conc\n\n/-- A local minimum of a convex function is a global minimum. -/\nlemma is_min_on.of_is_local_min_of_convex_univ {f : E \u2192 \u03b2} {a : E}\n  (h_local_min : is_local_min f a) (h_conv : convex_on \u211d univ f) : \u2200 x, f a \u2264 f x :=\n\u03bb x, (is_min_on.of_is_local_min_on_of_convex_on (mem_univ a)\n        (h_local_min.on univ) h_conv) (mem_univ x)\n\n/-- A local maximum of a concave function is a global maximum. -/\nlemma is_max_on.of_is_local_max_of_convex_univ {f : E \u2192 \u03b2} {a : E}\n  (h_local_max : is_local_max f a) (h_conc : concave_on \u211d univ f) : \u2200 x, f x \u2264 f a :=\n@is_min_on.of_is_local_min_of_convex_univ _ \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ f a h_local_max h_conc\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/convex/extrema.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7360864448191357}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.star.basic\nimport analysis.normed_space.spectrum\nimport algebra.star.module\nimport analysis.normed_space.star.exponential\n\n/-! # Spectral properties in C\u22c6-algebras\nIn this file, we establish various propreties related to the spectrum of elements in C\u22c6-algebras.\n-/\n\nlocal postfix `\u22c6`:std.prec.max_plus := star\n\nopen_locale topological_space ennreal\nopen filter ennreal spectrum cstar_ring\n\nsection unitary_spectrum\n\nvariables\n{\ud835\udd5c : Type*} [normed_field \ud835\udd5c]\n{E : Type*} [normed_ring E] [star_ring E] [cstar_ring E]\n[normed_algebra \ud835\udd5c E] [complete_space E] [nontrivial E]\n\nlemma unitary.spectrum_subset_circle (u : unitary E) :\n  spectrum \ud835\udd5c (u : E) \u2286 metric.sphere 0 1 :=\nbegin\n  refine \u03bb k hk, mem_sphere_zero_iff_norm.mpr (le_antisymm _ _),\n  { simpa only [cstar_ring.norm_coe_unitary u] using norm_le_norm_of_mem hk },\n  { rw \u2190unitary.coe_to_units_apply u at hk,\n    have hnk := ne_zero_of_mem_of_unit hk,\n    rw [\u2190inv_inv (unitary.to_units u), \u2190spectrum.map_inv, set.mem_inv] at hk,\n    have : \u2225k\u2225\u207b\u00b9 \u2264 \u2225\u2191((unitary.to_units u)\u207b\u00b9)\u2225, simpa only [norm_inv] using norm_le_norm_of_mem hk,\n    simpa using inv_le_of_inv_le (norm_pos_iff.mpr hnk) this }\nend\n\nlemma spectrum.subset_circle_of_unitary {u : E} (h : u \u2208 unitary E) :\n  spectrum \ud835\udd5c u \u2286 metric.sphere 0 1 :=\nunitary.spectrum_subset_circle \u27e8u, h\u27e9\n\nend unitary_spectrum\n\nsection complex_scalars\n\nopen complex\n\nvariables {A : Type*}\n[normed_ring A] [normed_algebra \u2102 A] [complete_space A] [star_ring A] [cstar_ring A]\n\nlocal notation `\u2191\u2090` := algebra_map \u2102 A\n\nlemma spectral_radius_eq_nnnorm_of_self_adjoint [norm_one_class A] {a : A}\n  (ha : a \u2208 self_adjoint A) :\n  spectral_radius \u2102 a = \u2225a\u2225\u208a :=\nbegin\n  have hconst : tendsto (\u03bb n : \u2115, (\u2225a\u2225\u208a : \u211d\u22650\u221e)) at_top _ := tendsto_const_nhds,\n  refine tendsto_nhds_unique _ hconst,\n  convert (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a : A)).comp\n      (nat.tendsto_pow_at_top_at_top_of_one_lt (by linarith : 1 < 2)),\n  refine funext (\u03bb n, _),\n  rw [function.comp_app, nnnorm_pow_two_pow_of_self_adjoint ha, ennreal.coe_pow, \u2190rpow_nat_cast,\n    \u2190rpow_mul],\n  simp,\nend\n\nlemma spectral_radius_eq_nnnorm_of_star_normal [norm_one_class A] (a : A) [is_star_normal a] :\n  spectral_radius \u2102 a = \u2225a\u2225\u208a :=\nbegin\n  refine (ennreal.pow_strict_mono two_ne_zero).injective _,\n  have ha : a\u22c6 * a \u2208 self_adjoint A,\n    from self_adjoint.mem_iff.mpr (by simpa only [star_star] using (star_mul a\u22c6 a)),\n  have heq : (\u03bb n : \u2115, ((\u2225(a\u22c6 * a) ^ n\u2225\u208a ^ (1 / n : \u211d)) : \u211d\u22650\u221e))\n    = (\u03bb x, x ^ 2) \u2218 (\u03bb n : \u2115, ((\u2225a ^ n\u2225\u208a ^ (1 / n : \u211d)) : \u211d\u22650\u221e)),\n  { funext,\n    rw [function.comp_apply, \u2190rpow_nat_cast, \u2190rpow_mul, mul_comm, rpow_mul, rpow_nat_cast,\n      \u2190coe_pow, sq, \u2190nnnorm_star_mul_self, commute.mul_pow (star_comm_self' a), star_pow], },\n  have h\u2082 := ((ennreal.continuous_pow 2).tendsto (spectral_radius \u2102 a)).comp\n    (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius a),\n  rw \u2190heq at h\u2082,\n  convert tendsto_nhds_unique h\u2082 (pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a\u22c6 * a)),\n  rw [spectral_radius_eq_nnnorm_of_self_adjoint ha, sq, nnnorm_star_mul_self, coe_mul],\nend\n\n/-- Any element of the spectrum of a selfadjoint is real. -/\ntheorem self_adjoint.mem_spectrum_eq_re [star_module \u2102 A] [nontrivial A] {a : A}\n  (ha : a \u2208 self_adjoint A) {z : \u2102} (hz : z \u2208 spectrum \u2102 a) : z = z.re :=\nbegin\n  let Iu := units.mk0 I I_ne_zero,\n  have : exp \u2102 (I \u2022 z) \u2208 spectrum \u2102 (exp \u2102 (I \u2022 a)),\n    by simpa only [units.smul_def, units.coe_mk0]\n      using spectrum.exp_mem_exp (Iu \u2022 a) (smul_mem_smul_iff.mpr hz),\n  exact complex.ext (of_real_re _)\n    (by simpa only [\u2190complex.exp_eq_exp_\u2102, mem_sphere_zero_iff_norm, norm_eq_abs, abs_exp,\n      real.exp_eq_one_iff, smul_eq_mul, I_mul, neg_eq_zero]\n      using spectrum.subset_circle_of_unitary (self_adjoint.exp_i_smul_unitary ha) this),\nend\n\n/-- Any element of the spectrum of a selfadjoint is real. -/\ntheorem self_adjoint.mem_spectrum_eq_re' [star_module \u2102 A] [nontrivial A]\n  (a : self_adjoint A) {z : \u2102} (hz : z \u2208 spectrum \u2102 (a : A)) : z = z.re :=\nself_adjoint.mem_spectrum_eq_re a.property hz\n\n/-- The spectrum of a selfadjoint is real -/\ntheorem self_adjoint.coe_re_map_spectrum [star_module \u2102 A] [nontrivial A] {a : A}\n  (ha : a \u2208 self_adjoint A) : spectrum \u2102 a = (coe \u2218 re '' (spectrum \u2102 a) : set \u2102) :=\nle_antisymm (\u03bb z hz, \u27e8z, hz, (self_adjoint.mem_spectrum_eq_re ha hz).symm\u27e9) (\u03bb z, by\n  { rintros \u27e8z, hz, rfl\u27e9,\n    simpa only [(self_adjoint.mem_spectrum_eq_re ha hz).symm, function.comp_app] using hz })\n\n/-- The spectrum of a selfadjoint is real -/\ntheorem self_adjoint.coe_re_map_spectrum' [star_module \u2102 A] [nontrivial A] (a : self_adjoint A) :\n  spectrum \u2102 (a : A) = (coe \u2218 re '' (spectrum \u2102 (a : A)) : set \u2102) :=\nself_adjoint.coe_re_map_spectrum a.property\n\nend complex_scalars\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/normed_space/star/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7360167460478345}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\nimport order.lattice\nimport data.set.basic\n\nuniverses u v w\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b9 : Sort w} (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\nlocal infix ` \u227c ` : 50 := r\n\n/-- A family of elements of \u03b1 is directed (with respect to a relation `\u227c` on \u03b1)\n  if there is a member of the family `\u227c`-above any pair in the family.  -/\ndef directed (f : \u03b9 \u2192 \u03b1) := \u2200x y, \u2203z, f x \u227c f z \u2227 f y \u227c f z\n\n/-- A subset of \u03b1 is directed if there is an element of the set `\u227c`-above any\n  pair of elements in the set. -/\ndef directed_on (s : set \u03b1) := \u2200 (x \u2208 s) (y \u2208 s), \u2203z \u2208 s, x \u227c z \u2227 y \u227c z\n\nvariables {r}\n\ntheorem directed_on_iff_directed {s} : @directed_on \u03b1 r s \u2194 directed r (coe : s \u2192 \u03b1) :=\nby simp [directed, directed_on]; refine ball_congr (\u03bb x hx, by simp; refl)\n\nalias directed_on_iff_directed \u2194 directed_on.directed_coe _\n\ntheorem directed_on_image {s} {f : \u03b2 \u2192 \u03b1} :\n  directed_on r (f '' s) \u2194 directed_on (f \u207b\u00b9'o r) s :=\nby simp only [directed_on, set.ball_image_iff, set.bex_image_iff, order.preimage]\n\ntheorem directed_on.mono {s : set \u03b1} (h : directed_on r s)\n  {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (H : \u2200 {a b}, r a b \u2192 r' a b) :\n  directed_on r' s :=\n\u03bb x hx y hy, let \u27e8z, zs, xz, yz\u27e9 := h x hx y hy in \u27e8z, zs, H xz, H yz\u27e9\n\ntheorem directed_comp {\u03b9} {f : \u03b9 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1} :\n  directed r (g \u2218 f) \u2194 directed (g \u207b\u00b9'o r) f := iff.rfl\n\ntheorem directed.mono {s : \u03b1 \u2192 \u03b1 \u2192 Prop} {\u03b9} {f : \u03b9 \u2192 \u03b1}\n  (H : \u2200 a b, r a b \u2192 s a b) (h : directed r f) : directed s f :=\n\u03bb a b, let \u27e8c, h\u2081, h\u2082\u27e9 := h a b in \u27e8c, H _ _ h\u2081, H _ _ h\u2082\u27e9\n\ntheorem directed.mono_comp {\u03b9} {rb : \u03b2 \u2192 \u03b2 \u2192 Prop} {g : \u03b1 \u2192 \u03b2} {f : \u03b9 \u2192 \u03b1}\n  (hg : \u2200 \u2983x y\u2984, x \u227c y \u2192 rb (g x) (g y)) (hf : directed r f) :\n  directed rb (g \u2218 f) :=\ndirected_comp.2 $ hf.mono hg\n\n/-- A monotone function on a sup-semilattice is directed. -/\nlemma directed_of_sup [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} {r : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  (H : \u2200 \u2983i j\u2984, i \u2264 j \u2192 r (f i) (f j)) : directed r f :=\n\u03bb a b, \u27e8a \u2294 b, H le_sup_left, H le_sup_right\u27e9\n\nlemma monotone.directed_le [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  monotone f \u2192 directed (\u2264) f :=\ndirected_of_sup\n\n/-- An antimonotone function on an inf-semilattice is directed. -/\nlemma directed_of_inf [semilattice_inf \u03b1] {r : \u03b2 \u2192 \u03b2 \u2192 Prop} {f : \u03b1 \u2192 \u03b2}\n  (hf : \u2200a\u2081 a\u2082, a\u2081 \u2264 a\u2082 \u2192 r (f a\u2082) (f a\u2081)) : directed r f :=\nassume x y, \u27e8x \u2293 y, hf _ _ inf_le_left, hf _ _ inf_le_right\u27e9\n\n/-- A `preorder` is a `directed_order` if for any two elements `i`, `j`\nthere is an element `k` such that `i \u2264 k` and `j \u2264 k`. -/\nclass directed_order (\u03b1 : Type u) extends preorder \u03b1 :=\n(directed : \u2200 i j : \u03b1, \u2203 k, i \u2264 k \u2227 j \u2264 k)\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance linear_order.to_directed_order (\u03b1) [linear_order \u03b1] : directed_order \u03b1 :=\n\u27e8\u03bb i j, or.cases_on (le_total i j) (\u03bb hij, \u27e8j, hij, le_refl j\u27e9) (\u03bb hji, \u27e8i, le_refl i, hji\u27e9)\u27e9\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/directed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7360167403462171}}
{"text": "/-\nCopyright (c) 2020 Markus Himmel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Markus Himmel\n-/\nimport algebra.category.Module.epi_mono\n\n/-!\n# The concrete (co)kernels in the category of modules are (co)kernels in the categorical sense.\n-/\n\nopen category_theory\nopen category_theory.limits\nopen category_theory.limits.walking_parallel_pair\n\nuniverses u v\n\nnamespace Module\nvariables {R : Type u} [ring R]\n\nsection\nvariables {M N : Module.{v} R} (f : M \u27f6 N)\n\n/-- The kernel cone induced by the concrete kernel. -/\ndef kernel_cone : kernel_fork f :=\nkernel_fork.of_\u03b9 (as_hom f.ker.subtype) $ by tidy\n\n/-- The kernel of a linear map is a kernel in the categorical sense. -/\ndef kernel_is_limit : is_limit (kernel_cone f) :=\nfork.is_limit.mk _\n  (\u03bb s, linear_map.cod_restrict f.ker (fork.\u03b9 s) (\u03bb c, linear_map.mem_ker.2 $\n    by { rw [\u2190@function.comp_apply _ _ _ f (fork.\u03b9 s) c, \u2190coe_comp, fork.condition,\n      has_zero_morphisms.comp_zero (fork.\u03b9 s) N], refl }))\n  (\u03bb s, linear_map.subtype_comp_cod_restrict _ _ _)\n  (\u03bb s m h, linear_map.ext $ \u03bb x, subtype.ext_iff_val.2 $\n    have h\u2081 : (m \u226b (kernel_cone f).\u03c0.app zero).to_fun = (s.\u03c0.app zero).to_fun,\n      by { congr, exact h zero },\n    by convert @congr_fun _ _ _ _ h\u2081 x )\n\n/-- The cokernel cocone induced by the projection onto the quotient. -/\ndef cokernel_cocone : cokernel_cofork f :=\ncokernel_cofork.of_\u03c0 (as_hom f.range.mkq) $ linear_map.range_mkq_comp _\n\n/-- The projection onto the quotient is a cokernel in the categorical sense. -/\ndef cokernel_is_colimit : is_colimit (cokernel_cocone f) :=\ncofork.is_colimit.mk _\n  (\u03bb s, f.range.liftq (cofork.\u03c0 s) $ linear_map.range_le_ker_iff.2 $ cokernel_cofork.condition s)\n  (\u03bb s, f.range.liftq_mkq (cofork.\u03c0 s) _)\n  (\u03bb s m h,\n  begin\n    haveI : epi (as_hom f.range.mkq) := (epi_iff_range_eq_top _).mpr (submodule.range_mkq _),\n    apply (cancel_epi (as_hom f.range.mkq)).1,\n    convert h walking_parallel_pair.one,\n    exact submodule.liftq_mkq _ _ _\n  end)\nend\n\n/-- The category of R-modules has kernels, given by the inclusion of the kernel submodule. -/\nlemma has_kernels_Module : has_kernels (Module R) :=\n\u27e8\u03bb X Y f, has_limit.mk \u27e8_, kernel_is_limit f\u27e9\u27e9\n\n/-- The category or R-modules has cokernels, given by the projection onto the quotient. -/\nlemma has_cokernels_Module : has_cokernels (Module R) :=\n\u27e8\u03bb X Y f, has_colimit.mk \u27e8_, cokernel_is_colimit f\u27e9\u27e9\n\nopen_locale Module\n\nlocal attribute [instance] has_kernels_Module\nlocal attribute [instance] has_cokernels_Module\n\nvariables {G H : Module.{v} R} (f : G \u27f6 H)\n\n/--\nThe categorical kernel of a morphism in `Module`\nagrees with the usual module-theoretical kernel.\n-/\nnoncomputable def kernel_iso_ker {G H : Module.{v} R} (f : G \u27f6 H) :\n  kernel f \u2245 Module.of R (f.ker) :=\nlimit.iso_limit_cone \u27e8_, kernel_is_limit f\u27e9\n\n-- We now show this isomorphism commutes with the inclusion of the kernel into the source.\n\n@[simp, elementwise] lemma kernel_iso_ker_inv_kernel_\u03b9 :\n  (kernel_iso_ker f).inv \u226b kernel.\u03b9 f = f.ker.subtype :=\nlimit.iso_limit_cone_inv_\u03c0 _ _\n\n@[simp, elementwise] lemma kernel_iso_ker_hom_ker_subtype :\n  (kernel_iso_ker f).hom \u226b f.ker.subtype = kernel.\u03b9 f :=\nis_limit.cone_point_unique_up_to_iso_inv_comp _ (limit.is_limit _) zero\n\n/--\nThe categorical cokernel of a morphism in `Module`\nagrees with the usual module-theoretical quotient.\n-/\nnoncomputable def cokernel_iso_range_quotient {G H : Module.{v} R} (f : G \u27f6 H) :\n  cokernel f \u2245 Module.of R (f.range.quotient) :=\ncolimit.iso_colimit_cocone \u27e8_, cokernel_is_colimit f\u27e9\n\n-- We now show this isomorphism commutes with the projection of target to the cokernel.\n\n@[simp, elementwise] lemma cokernel_\u03c0_cokernel_iso_range_quotient_hom :\n  cokernel.\u03c0 f \u226b (cokernel_iso_range_quotient f).hom = f.range.mkq :=\nby { convert colimit.iso_colimit_cocone_\u03b9_hom _ _; refl, }\n\n@[simp, elementwise] lemma range_mkq_cokernel_iso_range_quotient_inv :\n  \u21bff.range.mkq \u226b (cokernel_iso_range_quotient f).inv = cokernel.\u03c0 f :=\nby { convert colimit.iso_colimit_cocone_\u03b9_inv \u27e8_, cokernel_is_colimit f\u27e9 _; refl, }\n\nend Module\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/category/Module/kernels.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7360167393345015}}
{"text": "import Lean4Axiomatic.AbstractAlgebra.Substitutive\n\nnamespace Lean4Axiomatic.AA\n\nopen Relation.Equivalence (EqvOp)\n\n/--\nClass for types and operations that satisfy the associative property.\n\nFor more information see `Associative.assoc` or\n[consult Wikipedia](https://en.wikipedia.org/wiki/Associative_property).\n\n**Named parameters**\n- `\u03b1`: the type that the binary operation `f` is defined over.\n- `f`: the binary operation that obeys the associative property.\n\n**Class parameters**\n- `EqvOp \u03b1`: necessary because the property expresses an equality on `\u03b1`.\n-/\nclass Associative {\u03b1 : Sort u} [EqvOp \u03b1] (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) where\n  /--\n  The associative property of a binary operation `f` defined over a type `\u03b1`.\n\n  Some well-known examples from arithmetic are that addition and multiplication\n  are associative; we have `(a + b) + c \u2243 a + (b + c)` and\n  `(a * b) * c \u2243 a * (b * c)` for all natural numbers `a`, `b`, and `c`.\n\n  **Named parameters**\n  - see `Associative` for the class parameters.\n  - `x`: the first operand (when reading from left to right).\n  - `y`: the second operand.\n  - `z`: the third operand.\n  -/\n  assoc {x y z : \u03b1} : f (f x y) z \u2243 f x (f y z)\n\nexport Associative (assoc)\n\n/--\nClass for types and operations that have either a left or right absorbing\nelement.\n\nFor more information see `AbsorbingOn.absorb` or\n[consult Wikipedia](https://en.wikipedia.org/wiki/Absorbing_element).\n\n**Named parameters**\n- `hand`:\n  Indicates whether the absorbing element is the left or right argument to the\n  binary operation `f`.\n- `\u03b1`:\n  The `Sort` of the absorbing element and the parameters of the operation `f`.\n- `z`:\n  The absorbing element, named `z` to suggest zero (the canonical example).\n- `f`:\n  The binary operation that has `z` as absorbing element.\n\n**Class parameters**\n- `EqvOp \u03b1`: Necessary because the property expresses an equivalence on `\u03b1`.\n-/\nclass AbsorbingOn\n    (hand : Hand) {\u03b1 : Sort u} [EqvOp \u03b1] (z : \u03b1) (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n    :=\n  /--\n  The left- or right-handed absorption property of a distinguished element `z`\n  and a binary operation `f` defined over a sort `\u03b1`.\n\n  The most well-known example of an absorbing element is zero, when paired with\n  multiplication. In all standard number systems, `0 * x \u2243 0 \u2243 x * 0` for all\n  numbers `x`.\n\n  **Named parameters**\n  - See `AbsorbingOn` for the class parameters.\n  - `x`:\n    The argument to `f` that is not the absorbing element; it will be in the\n    position that is the opposite of `hand`.\n  -/\n  absorb {x : \u03b1} : hand.align f z x \u2243 z\n\nexport AbsorbingOn (absorb)\n\n/--\nConvenience function for the left-handed absorption property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `AbsorbingOn.absorb` function; see its documentation for details.\n-/\nabbrev absorbL := @absorb Hand.L\n\n/--\nConvenience function for the right-handed absorption property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `AbsorbingOn.absorb` function; see its documentation for details.\n-/\nabbrev absorbR := @absorb Hand.R\n\n/--\nConvenience class for types and operations that have left **and** right\nabsorbing element.\n\nSee `AbsorbingOn` for detailed documentation.\n-/\nclass Absorbing {\u03b1 : Sort u} [EqvOp \u03b1] (z : \u03b1) (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\n  absorbingL : AbsorbingOn Hand.L z f\n  absorbingR : AbsorbingOn Hand.R z f\n\nattribute [instance] Absorbing.absorbingL\nattribute [instance] Absorbing.absorbingR\n\n/--\nDerive right-handed absorption from left-handed absorption for operations `f`\nmeeting certain conditions.\n\n**Intuition**: Both left and right absorbing elements produce the same result\n(themselves) from their associated binary operation. Thus, if the arguments to\n`f` can be swapped, one hand can be shown to imply the other.\n\n**Named parameters**\n- `\u03b1`: The `Sort` of the absorbing element `z`, and `f`'s parameters.\n- `z`: The absorbing element.\n- `f`: The binary operation that has `z` as absorbing element.\n\n**Class parameters**\n- `EqvOp \u03b1`: Necessary because `AbsorbingOn.absorb` requires it.\n- `Commutative f`: Restriction on `f` that's required for the derivation.\n-/\ndef absorbingR_from_absorbingL\n    {\u03b1 : Sort u} {z : \u03b1} {f : \u03b1 \u2192 \u03b1 \u2192 \u03b1} [EqvOp \u03b1] [Commutative f]\n    : AbsorbingOn Hand.L z f \u2192 AbsorbingOn Hand.R z f\n    := by\n  intro _ -- Make left absorbing available to instance search\n  apply AbsorbingOn.mk\n  intro (x : \u03b1)\n  show f x z \u2243 z\n  exact Rel.trans AA.comm AA.absorbL\n\n/--\nClass for types, values, and operations that satisfy either the left- or\nright-handed identity property.\n\nFor more information see `IdentityOn.ident` or\n[consult Wikipedia](https://en.wikipedia.org/wiki/Identity_element).\n\n**Named parameters**\n- `hand`:\n  Indicates whether the property is left- or right-handed.\n- `\u03b1`:\n  The `Sort` of the identity element and the parameters of the operation.\n- `e`:\n  The identity element. It's labeled as an `outParam` because it's useful to\n  have it be inferred in some contexts; see `InverseOn` for an example.\n- `f`:\n  The binary operation that obeys the identity property with `e`.\n\n**Class parameters**\n- `EqvOp \u03b1`: Necessary because the property expresses an equality on `\u03b1`.\n-/\nclass IdentityOn\n    (hand : Hand) {\u03b1 : Sort u} [EqvOp \u03b1] (e : outParam \u03b1) (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n    :=\n  /--\n  The left- or right-handed identity property of a distinguished element `e`\n  and a binary operation `f` defined over a sort `\u03b1`.\n\n  The most well-known examples are the additive and multiplicative identities\n  from arithmetic. Zero is the identity element for addition (because\n  `0 + n \u2243 n + 0 \u2243 n` for all `n`), while one is the identity for\n  multiplication (because `1 * m \u2243 m * 1 \u2243 m` for all `m`).\n\n  **Named parameters**\n  - See `IdentityOn` for the class parameters.\n  - `x`:\n    The argument to `f` that is not the identity element; it will be in the\n    position that is the opposite of `hand`.\n  -/\n  ident {x : \u03b1} : hand.align f e x \u2243 x\n\nexport IdentityOn (ident)\n\n/--\nConvenience function for the left-handed identity property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `ident` function.\n\nSee `IdentityOn.ident` for detailed documentation.\n-/\nabbrev identL := @ident Hand.L\n\n/--\nConvenience function for the right-handed identity property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `ident` function.\n\nSee `IdentityOn.ident` for detailed documentation.\n-/\nabbrev identR := @ident Hand.R\n\n/--\nConvenience class for types, values, and operations that satisfy the full\n(left- **and** right-handed) identity property.\n\nSee `IdentityOn` for detailed documentation.\n-/\nclass Identity {\u03b1 : Sort u} [EqvOp \u03b1] (e : outParam \u03b1) (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\n  identityL : IdentityOn Hand.L e f\n  identityR : IdentityOn Hand.R e f\n\nattribute [instance] Identity.identityL\nattribute [instance] Identity.identityR\n\n/--\nDerive the right-identity property from left-identity for operations `f`\nmeeting certain conditions.\n\n**Intuition**: Both the left-handed and right-handed versions of the property\nequate an application of `f` to the same value. Thus if `f` is commutative, one\nversion implies the other.\n\n**Named parameters**\n- `\u03b1`: The `Sort` of the identity element and the parameters of the operation.\n- `e`: The identity element.\n- `f`: The binary operation that obeys the identity property with `e`.\n\n**Class parameters**\n- `EqvOp \u03b1`: Necessary because `IdentityOn.ident` expresses an equality on `\u03b1`.\n- `Commutative f`: Restriction on `f` that's required for the derivation.\n-/\ndef identityR_from_identityL\n    {\u03b1 : Sort u} [EqvOp \u03b1] {e : \u03b1} {f : \u03b1 \u2192 \u03b1 \u2192 \u03b1} [Commutative f]\n    : IdentityOn Hand.L e f \u2192 IdentityOn Hand.R e f\n    := by\n  intro _ -- Make left identity available to instance search\n  apply IdentityOn.mk\n  intro (x : \u03b1)\n  show f x e \u2243 x\n  exact Rel.trans AA.comm AA.identL\n\n/--\nClass for types and operations that satisfy either the left- or right-handed\ninverse property.\n\nFor more information see `InverseOn.inverse` or\n[consult Wikipedia](https://en.wikipedia.org/wiki/Inverse_element).\n\n**Named parameters**\n- `hand`: Indicates whether the property is left- or right-handed.\n- `\u03b1`: The `Sort` of the operations' parameters.\n- `e`: An identity element under the operation `f`.\n- `inv`: An operation that turns any `\u03b1` value into its inverse.\n- `f`: The binary operation that, with `inv`, obeys the inverse property.\n\n**Class parameters**\n- `EqvOp \u03b1`: Necessary because the property expresses an equality on `\u03b1`.\n- `IdentityOn hand e f`: Evidence that `e` is an identity element.\n-/\nclass InverseOn\n    (hand : Hand) {\u03b1 : Sort u} {e : \u03b1} (inv : outParam (\u03b1 \u2192 \u03b1)) (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n    [EqvOp \u03b1] [IdentityOn hand e f]\n    :=\n  /--\n  The left- or right-handed inverse property of an inverse operation `inv` and\n  a binary operation `f` defined over a sort `\u03b1`.\n\n  The most well-known examples are additive and multiplicative inverses from\n  arithmetic. Integers are the simplest numbers to have additive inverses, via\n  negation; `a + (-a) \u2243 (-a) + a \u2243 0` for all `a`. Similarly, rational numbers\n  are the simplest ones with multiplicative inverses, via reciprocation;\n  `q * q\u207b\u00b9 \u2243 q\u207b\u00b9 * q \u2243 1` for all nonzero `q`.\n\n  **Named parameters**\n  - See `InverseOn` for the class parameters.\n  - `x`: The value that is combined (via `f`) with its own inverse.\n  -/\n  inverse {x : \u03b1} : hand.align f (inv x) x \u2243 e\n\nexport InverseOn (inverse)\n\n/--\nConvenience function for the left-handed inverse property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `inverse` function.\n\nSee `InverseOn.inverse` for detailed documentation.\n-/\nabbrev inverseL := @inverse Hand.L\n\n/--\nConvenience function for the right-handed inverse property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `inverse` function.\n\nSee `InverseOn.inverse` for detailed documentation.\n-/\nabbrev inverseR := @inverse Hand.R\n\n/--\nConvenience class for types and operations that satisfy the full (left- **and**\nright-handed) inverse property.\n\nSee `InverseOn` for detailed documentation.\n-/\nclass Inverse\n    {\u03b1 : Sort u} {e : \u03b1} (inv : outParam (\u03b1 \u2192 \u03b1)) (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n    [EqvOp \u03b1] [Identity e f] :=\n  inverseL : InverseOn Hand.L inv f\n  inverseR : InverseOn Hand.R inv f\n\nattribute [instance] Inverse.inverseL\nattribute [instance] Inverse.inverseR\n\n/--\nDerive the right-inverse property from left-inverse for operations `f`\nmeeting certain conditions.\n\n**Intuition**: Both the left-handed and right-handed versions of the property\nequate an application of `f` to the same value. Thus if `f` is commutative, one\nversion implies the other.\n\n**Named parameters**\n- `\u03b1`: The `Sort` of the operations' parameters.\n- `e`: An identity element under the operation `f`.\n- `inv`: An operation that turns any `\u03b1` value into its inverse.\n- `f`: The binary operation that, with `inv`, obeys the inverse property.\n\n**Class parameters**\n- `EqvOp \u03b1`: Necessary because the property expresses an equality on `\u03b1`.\n- `IdentityOn hand e f`: Evidence that `e` is an identity element.\n- `Commutative f`: Restriction on `f` that's required for the derivation.\n-/\ndef inverseR_from_inverseL\n    {\u03b1 : Sort u} {e : \u03b1} {inv : \u03b1 \u2192 \u03b1} {f : \u03b1 \u2192 \u03b1 \u2192 \u03b1}\n    [EqvOp \u03b1] [Identity e f] [Commutative f]\n    : InverseOn Hand.L inv f \u2192 InverseOn Hand.R inv f\n    := by\n  intro _ -- Make left inverse available to instance search\n  apply InverseOn.mk\n  intro (x : \u03b1)\n  show f x (inv x) \u2243 e\n  exact Rel.trans AA.comm AA.inverseL\n\n/--\nClass for types and operations that satisfy either the left- or right-handed\nsemicompatibility property.\n\nThis property doesn't seem to have a standard name. For more information see\n`SemicompatibleOn.scompat`\n\n**Named parameters**\n- `hand`: Indicates whether the property is left- or right-handed.\n- `\u03b1`: The `Sort` that the operations `f` and `g` are defined over.\n- `f`: An unary operation on `\u03b1`.\n- `g`: A binary operation on `\u03b1`.\n\n**Class parameters**\n- `EqvOp \u03b1`: Necessary because the property expresses an equivalence on `\u03b1`.\n-/\nclass SemicompatibleOn\n    (hand : Hand) {\u03b1 : Sort u} [EqvOp \u03b1] (f : \u03b1 \u2192 \u03b1) (g : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n    :=\n  /--\n  The left- or right-handed semicompatibility property of two operations `f`\n  and `g` defined over a sort `\u03b1`.\n\n  The property is called _semi_-compatible because when `f` is exchanged with\n  `g`, it only operates on one of `g`'s arguments, rather than both. An example\n  of operations that are semicompatible are _successor_ (i.e., `step`) and\n  _addition_ on natural numbers: `step n + m \u2243 step (n + m) \u2243 n + step m`.\n  Another example is negation and multiplication on integers:\n  `(-a) * b \u2243 -(a * b) \u2243 a * (-b)`.\n\n  **Named parameters**\n  - See `SemicompatibleOn` for the class parameters.\n  - `x`: The left-hand argument to `g`.\n  - `y`: The right-hand argument to `g`.\n  -/\n  scompat {x y : \u03b1} : f (g x y) \u2243 hand.pick (g (f x) y) (g x (f y))\n\nexport SemicompatibleOn (scompat)\n\n/--\nConvenience function for the left-handed semicompatibility property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `scompat` function.\n\nSee `SemicompatibleOn.scompat` for detailed documentation.\n-/\nabbrev scompatL := @scompat Hand.L\n\n/--\nConvenience function for the right-handed semicompatibility property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `scompat` function.\n\nSee `SemicompatibleOn.scompat` for detailed documentation.\n-/\nabbrev scompatR := @scompat Hand.R\n\n/--\nConvenience class for types and operations that satisfy the full (left- **and**\nright-handed) semicompatibility property.\n\nSee `SemicompatibleOn` for detailed documentation.\n-/\nclass Semicompatible {\u03b1 : Sort u} [EqvOp \u03b1] (f : \u03b1 \u2192 \u03b1) (g : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\n  semicompatibleL : SemicompatibleOn Hand.L f g\n  semicompatibleR : SemicompatibleOn Hand.R f g\n\nattribute [instance] Semicompatible.semicompatibleL\nattribute [instance] Semicompatible.semicompatibleR\n\n/--\nDerive the right-semicompatibility property from left-semicompatibility for\noperations `f` and `g` meeting certain conditions.\n\n**Intuition**: Both the left-handed and right-handed versions of the property\nhave one side of their equivalences in common. Thus if `g` is commutative, one\nversion implies the other.\n\n**Named parameters**\n- `\u03b1`: The `Sort` of the operations' parameters.\n- `f`: An unary operation on `\u03b1`.\n- `g`: A binary operation on `\u03b1`.\n\n**Class parameters**\n- `EqvOp \u03b1`:\n    Necessary because the property expresses an equivalence on `\u03b1`.\n- `Substitutive\u2081 f (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)`:\n    Needed to transform an expression passed to `f`. Nearly every useful `f`\n    will satisfy this property.\n- `Commutative g`:\n    Restriction on `g` that's required for the derivation.\n-/\ndef semicompatibleR_from_semicompatibleL\n    {\u03b1 : Sort u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1 \u2192 \u03b1}\n    [EqvOp \u03b1] [Substitutive\u2081 f (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)] [Commutative g]\n    : SemicompatibleOn Hand.L f g \u2192 SemicompatibleOn Hand.R f g\n    := by\n  intro _ -- Make the left-hand property available to instance search\n  apply SemicompatibleOn.mk\n  intro x y\n  show f (g x y) \u2243 g x (f y)\n  calc\n    f (g x y) \u2243 _ := AA.subst\u2081 AA.comm\n    f (g y x) \u2243 _ := AA.scompatL\n    g (f y) x \u2243 _ := AA.comm\n    g x (f y) \u2243 _ := Rel.refl\n\n/--\nClass for types and operations that satisfy the binary compatibility property.\n\nThis property does not have a standard name in abstract algebra. However, it is\na key part of what it means to have a\n[homomorphism](https://en.wikipedia.org/wiki/Homomorphism) between algebraic\nstructures.\n\n**Named parameters**\n- `\u03b1`:\n    The `Sort` that is the input of `f` and that the operation `g` is defined\n    over.\n- `\u03b2`:\n    The `Sort` that is the output of `f` and that the operation `h` is defined\n    over.\n- `f`:\n    An unary operation mapping `\u03b1` to `\u03b2`, that is \"compatible\" with operations\n    `g` and `h`.\n- `g`:\n    A binary operation on `\u03b1`.\n- `h`:\n    A binary operation on `\u03b2`.\n\n**Class parameters**\n- `EqvOp \u03b2`: Necessary because the property expresses an equivalence on `\u03b2`.\n-/\nclass Compatible\u2082\n    {\u03b1 \u03b2 : Sort u} [EqvOp \u03b2]\n    (f : \u03b1 \u2192 \u03b2) (g : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (h : outParam (\u03b2 \u2192 \u03b2 \u2192 \u03b2))\n    :=\n  /--\n  The compatibility property of an unary operation `f` with two binary\n  operations `g` and `h` that are defined over sorts `\u03b1` and `\u03b2`, respectively.\n\n  Typically, `g` and `h` represent a similar operation on each of their sorts,\n  and we say that `f` _is compatible with_ that operation, or that `f`\n  _preserves_ the operation. In particular, `\u03b1` and `\u03b2` are often the same\n  sort, and `g` and `h` are often the same operation.\n\n  An example instance of the property is that negation is compatible with\n  addition on the integers: `-(a + b) \u2243 (-a) + (-b)` for all integers `a` and\n  `b`.\n\n  **Named parameters**\n  - See `Compatible` for the class parameters.\n  - `x`: The left-hand argument to `g`.\n  - `y`: The right-hand argument to `g`.\n  -/\n  compat\u2082 {x y : \u03b1} : f (g x y) \u2243 h (f x) (f y)\n\nexport Compatible\u2082 (compat\u2082)\n\n/--\nClass for types and operations that satisfy either the left- or right-handed\ndistributive property.\n\nFor more information see `DistributiveOn.distrib` or\n[consult Wikipedia](https://en.wikipedia.org/wiki/Distributive_property).\n\n**Named parameters**\n- `hand`: indicates whether the property is left- or right-handed.\n- `\u03b1`: the type that the binary operations `f` and `g` are defined over.\n- `f`: the binary operation that distributes over `g`.\n- `g`: the binary operation that `f` distributes over.\n\n**Class parameters**\n- `EqvOp \u03b1`: necessary because the property expresses an equality on `\u03b1`.\n-/\nclass DistributiveOn\n    (hand : Hand) {\u03b1 : Sort u} [EqvOp \u03b1] (f g : \u03b1 \u2192 \u03b1 \u2192 \u03b1) where\n  /--\n  The left- or right-handed distributive property of two binary operations `f`\n  and `g` defined over a type `\u03b1`.\n\n  If this property is satisfied, one says that `f` _distributes_ over `g`. A\n  well-known example from arithmetic is that multiplication distributes over\n  addition; `a * (b + c) \u2243 a * b + a * c` for the left-handed case and\n  `(b + c) * a \u2243 b * a + c * a` for the right-handed case.\n\n  **Named parameters**\n  - see `DistributiveOn` for the class parameters.\n  - `x`: the argument to `f` that gets distributed; the `hand` parameter\n    indicates which side of `f` it is on.\n  - `y`: the left argument to `g`.\n  - `z`: the right argument to `g`.\n  -/\n  distrib {x y z : \u03b1} :\n    hand.align f x (g y z) \u2243 g (hand.align f x y) (hand.align f x z)\n\nexport DistributiveOn (distrib)\n\n/--\nConvenience function for the left-handed distributive property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `distrib` function.\n\nSee `DistributiveOn.distrib` for detailed documentation.\n-/\nabbrev distribL := @distrib Hand.L\n\n/--\nConvenience function for the right-handed distributive property.\n\nCan often resolve cases where type inference gets stuck when using the more\ngeneral `distrib` function.\n\nSee `DistributiveOn.distrib` for detailed documentation.\n-/\nabbrev distribR := @distrib Hand.R\n\n/--\nConvenience class for types and operations that satisfy the full (left- **and**\nright-handed) distributive property.\n\nSee `DistributiveOn` for detailed documentation.\n-/\nclass Distributive {\u03b1 : Sort u} [EqvOp \u03b1] (f g : \u03b1 \u2192 \u03b1 \u2192 \u03b1) where\n  distributiveL : DistributiveOn Hand.L f g\n  distributiveR : DistributiveOn Hand.R f g\n\nattribute [instance] Distributive.distributiveL\nattribute [instance] Distributive.distributiveR\n\n/--\nDerive right-distributivity from left-distributivity for operations `f` and `g`\nmeeting certain conditions.\n-/\ndef distributiveR_from_distributiveL\n    {\u03b1 : Sort u} {f g : \u03b1 \u2192 \u03b1 \u2192 \u03b1}\n    [EqvOp \u03b1] [Commutative f] [Substitutive\u2082 g AA.tc (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)]\n    : DistributiveOn Hand.L f g \u2192 DistributiveOn Hand.R f g := by\n  intro\n  constructor\n  intro x y z\n  show f (g y z) x \u2243 g (f y x) (f z x)\n  calc\n    f (g y z) x       \u2243 _ := AA.comm\n    f x (g y z)       \u2243 _ := AA.distribL\n    g (f x y) (f x z) \u2243 _ := AA.substL AA.comm\n    g (f y x) (f x z) \u2243 _ := AA.substR AA.comm\n    g (f y x) (f z x) \u2243 _ := Rel.refl\n\n/-- Expresses that one of two propositions is true, but not both. -/\ndef ExactlyOneOfTwo (\u03b1 \u03b2 : Prop) : Prop := (\u03b1 \u2228 \u03b2) \u2227 \u00ac (\u03b1 \u2227 \u03b2)\n\n/--\nInhabited when at least one of its three propositions is true; a three-way\nlogical OR.\n-/\ninductive OneOfThree (\u03b1 \u03b2 \u03b3 : Prop) : Prop\n| first  (a : \u03b1)\n| second (b : \u03b2)\n| third  (c : \u03b3)\n\n/--\nConverts each proposition in `OneOfThree` to a different one while preserving\nwhich one is inhabited.\n\nIntended to be used in contexts where the mapping functions are previously\ndefined, to keep the code compact.\n-/\ndef OneOfThree.map\n    {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 \u03b3\u2081 \u03b3\u2082 : Prop}\n    : OneOfThree \u03b1\u2081 \u03b2\u2081 \u03b3\u2081 \u2192 (\u03b1\u2081 \u2192 \u03b1\u2082) \u2192 (\u03b2\u2081 \u2192 \u03b2\u2082) \u2192 (\u03b3\u2081 \u2192 \u03b3\u2082)\n    \u2192 OneOfThree \u03b1\u2082 \u03b2\u2082 \u03b3\u2082\n| first a, f, _, _ => first (f a)\n| second b, _, g, _ => second (g b)\n| third c, _, _, h => third (h c)\n\n/--\n\"Rotates\" `OneOfThree`'s propositions one place to the left: the leftmost one\nbecomes the rightmost.\n\nThis merely changes how the type is written; the value is preserved. Useful\nin conjunction with `OneOfThree.map` to translate between arbitrary\n`OneOfThree` types.\n-/\ndef OneOfThree.rotL {\u03b1 \u03b2 \u03b3 : Prop} : OneOfThree \u03b1 \u03b2 \u03b3 \u2192 OneOfThree \u03b2 \u03b3 \u03b1\n| first a => third a\n| second b => first b\n| third c => second c\n\n/--\n\"Rotates\" `OneOfThree`'s propositions one place to the right: the rightmost one\nbecomes the leftmost.\n\nThis merely changes how the type is written; the value is preserved. Useful\nin conjunction with `OneOfThree.map` to translate between arbitrary\n`OneOfThree` types.\n-/\ndef OneOfThree.rotR {\u03b1 \u03b2 \u03b3 : Prop} : OneOfThree \u03b1 \u03b2 \u03b3 \u2192 OneOfThree \u03b3 \u03b1 \u03b2\n| first a => second a\n| second b => third b\n| third c => first c\n\n/-- Inhabited when at least two of its three propositions are true. -/\ninductive TwoOfThree (\u03b1 \u03b2 \u03b3 : Prop) : Prop\n| oneAndTwo   (a : \u03b1) (b : \u03b2)\n| oneAndThree (a : \u03b1) (c : \u03b3)\n| twoAndThree (b : \u03b2) (c : \u03b3)\n\n/--\nConverts each proposition in `TwoOfThree` to a different one while preserving\nwhich ones are inhabited.\n\nIntended to be used in contexts where the mapping functions are previously\ndefined, to keep the code compact.\n-/\ndef TwoOfThree.map\n    {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 \u03b3\u2081 \u03b3\u2082 : Prop} (f : \u03b1\u2081 \u2192 \u03b1\u2082) (g : \u03b2\u2081 \u2192 \u03b2\u2082) (h : \u03b3\u2081 \u2192 \u03b3\u2082)\n    : TwoOfThree \u03b1\u2081 \u03b2\u2081 \u03b3\u2081 \u2192 TwoOfThree \u03b1\u2082 \u03b2\u2082 \u03b3\u2082\n| oneAndTwo a b => oneAndTwo (f a) (g b)\n| oneAndThree a c => oneAndThree (f a) (h c)\n| twoAndThree b c => twoAndThree (g b) (h c)\n\n/--\n\"Rotates\" `TwoOfThree`'s propositions one place to the left: the leftmost one\nbecomes the rightmost.\n\nThis merely changes how the type is written; the value is preserved. Useful\nin conjunction with `TwoOfThree.map` to translate between arbitrary\n`TwoOfThree` types.\n-/\ndef TwoOfThree.rotL {\u03b1 \u03b2 \u03b3 : Prop} : TwoOfThree \u03b1 \u03b2 \u03b3 \u2192 TwoOfThree \u03b2 \u03b3 \u03b1\n| oneAndTwo a b => oneAndThree b a\n| oneAndThree a c => twoAndThree c a\n| twoAndThree b c => oneAndTwo b c\n\n/--\n\"Rotates\" `TwoOfThree`'s propositions one place to the right: the rightmost one\nbecomes the leftmost.\n\nThis merely changes how the type is written; the value is preserved. Useful\nin conjunction with `TwoOfThree.map` to translate between arbitrary\n`TwoOfThree` types.\n-/\ndef TwoOfThree.rotR {\u03b1 \u03b2 \u03b3 : Prop} : TwoOfThree \u03b1 \u03b2 \u03b3 \u2192 TwoOfThree \u03b3 \u03b1 \u03b2\n| oneAndTwo a b => twoAndThree a b\n| oneAndThree a c => oneAndTwo c a\n| twoAndThree b c => oneAndThree c b\n\n/--\nInhabited when exactly one of its three propositions is true.\n\nCan be used to express the various \"trichotomy\" properties in algebra.\n-/\nstructure ExactlyOneOfThree (\u03b1 \u03b2 \u03b3 : Prop) : Prop :=\n  atLeastOne :   OneOfThree \u03b1 \u03b2 \u03b3\n  atMostOne  : \u00ac TwoOfThree \u03b1 \u03b2 \u03b3\n\n/--\nConverts all propositions in `ExactlyOneOfThree` to equivalents while\npreserving the one that's inhabited.\n\nIntended to be used in contexts where the mapping functions are previously\ndefined, to keep the code compact.\n-/\ndef ExactlyOneOfThree.map\n    {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 \u03b3\u2081 \u03b3\u2082 : Prop}\n    : ExactlyOneOfThree \u03b1\u2081 \u03b2\u2081 \u03b3\u2081 \u2192 (\u03b1\u2081 \u2194 \u03b1\u2082) \u2192 (\u03b2\u2081 \u2194 \u03b2\u2082) \u2192 (\u03b3\u2081 \u2194 \u03b3\u2082)\n    \u2192 ExactlyOneOfThree \u03b1\u2082 \u03b2\u2082 \u03b3\u2082\n    := by\n  intro (x : ExactlyOneOfThree \u03b1\u2081 \u03b2\u2081 \u03b3\u2081)\n  intro (f : \u03b1\u2081 \u2194 \u03b1\u2082) (g : \u03b2\u2081 \u2194 \u03b2\u2082) (h : \u03b3\u2081 \u2194 \u03b3\u2082)\n  have atLeastOne : OneOfThree \u03b1\u2082 \u03b2\u2082 \u03b3\u2082 := x.atLeastOne.map f.mp g.mp h.mp\n  have atMostOne : \u00acTwoOfThree \u03b1\u2082 \u03b2\u2082 \u03b3\u2082 :=\n    mt (TwoOfThree.map f.mpr g.mpr h.mpr) x.atMostOne\n  exact ExactlyOneOfThree.mk atLeastOne atMostOne\n\n/--\n\"Rotates\" `ExactlyOneOfThree`'s propositions one place to the left: the\nleftmost one becomes the rightmost.\n\nThis merely changes how the type is written; the value is preserved. Useful\nin conjunction with `ExactlyOneOfThree.map` to translate between arbitrary\n`ExactlyOneOfThree` types.\n-/\ndef ExactlyOneOfThree.rotL\n    {\u03b1 \u03b2 \u03b3 : Prop} : ExactlyOneOfThree \u03b1 \u03b2 \u03b3 \u2192 ExactlyOneOfThree \u03b2 \u03b3 \u03b1\n    := by\n  intro (x : ExactlyOneOfThree \u03b1 \u03b2 \u03b3)\n  have atLeastOne : OneOfThree \u03b2 \u03b3 \u03b1 := x.atLeastOne.rotL\n  have atMostOne : \u00acTwoOfThree \u03b2 \u03b3 \u03b1 := mt TwoOfThree.rotR x.atMostOne\n  exact ExactlyOneOfThree.mk atLeastOne atMostOne\n\n/--\n\"Rotates\" `ExactlyOneOfThree`'s propositions one place to the right: the\nrightmost one becomes the leftmost.\n\nThis merely changes how the type is written; the value is preserved. Useful\nin conjunction with `ExactlyOneOfThree.map` to translate between arbitrary\n`ExactlyOneOfThree` types.\n-/\ndef ExactlyOneOfThree.rotR\n    {\u03b1 \u03b2 \u03b3 : Prop} : ExactlyOneOfThree \u03b1 \u03b2 \u03b3 \u2192 ExactlyOneOfThree \u03b3 \u03b1 \u03b2\n    := by\n  intro (x : ExactlyOneOfThree \u03b1 \u03b2 \u03b3)\n  have atLeastOne : OneOfThree \u03b3 \u03b1 \u03b2 := x.atLeastOne.rotR\n  have atMostOne : \u00acTwoOfThree \u03b3 \u03b1 \u03b2 := mt TwoOfThree.rotL x.atMostOne\n  exact ExactlyOneOfThree.mk atLeastOne atMostOne\n\n/--\nSwaps the middle two elements of a balanced four-element expression involving a\nsingle binary operation.\n\nThe sort `\u03b1` and its binary operation `f` must form a commutative semigroup.\n\n**Named parameters**\n- `\u03b1`: the sort over which `f` operates.\n- `f`: the binary operation used in the expression.\n- `a`, `b`, `c`, `d`: the operands to `f` in the expression.\n\n**Class parameters**\n- `EqvOp \u03b1`: needed to express the identity between expressions.\n- `Associative f`, `Commutative f`: needed to rearrange the operands freely.\n- `Substitutive\u2082 f tc (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)`: needed to rearrange subexpressions.\n-/\ntheorem expr_xxfxxff_lr_swap_rl\n    {\u03b1 : Sort u} {f : \u03b1 \u2192 \u03b1 \u2192 \u03b1} {a b c d : \u03b1} [EqvOp \u03b1]\n    [Associative f] [Commutative f] [Substitutive\u2082 f tc (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)]\n    : f (f a b) (f c d) \u2243 f (f a c) (f b d)\n    := calc\n  f (f a b) (f c d) \u2243 _ := AA.assoc\n  f a (f b (f c d)) \u2243 _ := AA.substR (Rel.symm AA.assoc)\n  f a (f (f b c) d) \u2243 _ := AA.substR (AA.substL AA.comm)\n  f a (f (f c b) d) \u2243 _ := AA.substR AA.assoc\n  f a (f c (f b d)) \u2243 _ := Rel.symm AA.assoc\n  f (f a c) (f b d) \u2243 _ := Rel.refl\n\n/--\nSwaps the second and fourth elements of a balanced four-element expression\ninvolving a single binary operation.\n\nThe sort `\u03b1` and its binary operation `f` must form a commutative semigroup.\n\n**Named parameters**\n- `\u03b1`: the sort over which `f` operates.\n- `f`: the binary operation used in the expression.\n- `a`, `b`, `c`, `d`: the operands to `f` in the expression.\n\n**Class parameters**\n- `EqvOp \u03b1`: needed to express the identity between expressions.\n- `Associative f`, `Commutative f`: needed to rearrange the operands freely.\n- `Substitutive\u2082 f tc (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)`: needed to rearrange subexpressions.\n-/\ntheorem expr_xxfxxff_lr_swap_rr\n    {\u03b1 : Sort u} {f : \u03b1 \u2192 \u03b1 \u2192 \u03b1} {a b c d : \u03b1} [EqvOp \u03b1]\n    [Associative f] [Commutative f] [Substitutive\u2082 f tc (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)]\n    : f (f a b) (f c d) \u2243 f (f a d) (f c b)\n    := calc\n  f (f a b) (f c d) \u2243 _ := AA.substR AA.comm\n  f (f a b) (f d c) \u2243 _ := expr_xxfxxff_lr_swap_rl\n  f (f a d) (f b c) \u2243 _ := AA.substR AA.comm\n  f (f a d) (f c b) \u2243 _ := Rel.refl\n\nend Lean4Axiomatic.AA\n", "meta": {"author": "cruhland", "repo": "lean4-axiomatic", "sha": "6384bd38b8ba104530247d25456858775fe3c442", "save_path": "github-repos/lean/cruhland-lean4-axiomatic", "path": "github-repos/lean/cruhland-lean4-axiomatic/lean4-axiomatic-6384bd38b8ba104530247d25456858775fe3c442/Lean4Axiomatic/AbstractAlgebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7360143944119111}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n\n! This file was ported from Lean 3 source module combinatorics.partition\n! leanprover-community/mathlib commit dc6c365e751e34d100e80fe6e314c3c3e0fd2988\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Combinatorics.Composition\nimport Mathlib.Data.Nat.Parity\nimport Mathlib.Tactic.ApplyFun\n\n/-!\n# Partitions\n\nA partition of a natural number `n` is a way of writing `n` as a sum of positive integers, where the\norder does not matter: two sums that differ only in the order of their summands are considered the\nsame partition. This notion is closely related to that of a composition of `n`, but in a composition\nof `n` the order does matter.\nA summand of the partition is called a part.\n\n## Main functions\n\n* `p : Partition n` is a structure, made of a multiset of integers which are all positive and\n  add up to `n`.\n\n## Implementation details\n\nThe main motivation for this structure and its API is to show Euler's partition theorem, and\nrelated results.\n\nThe representation of a partition as a multiset is very handy as multisets are very flexible and\nalready have a well-developed API.\n\n## Tags\n\nPartition\n\n## References\n\n<https://en.wikipedia.org/wiki/Partition_(number_theory)>\n-/\n\n\nvariable {\u03b1 : Type _}\n\nopen Multiset\n\nopen BigOperators\n\nnamespace Nat\n\n/-- A partition of `n` is a multiset of positive integers summing to `n`. -/\n@[ext]\nstructure Partition (n : \u2115) where\n  /-- positive integers summing to `n`-/\n  parts : Multiset \u2115\n  /-- proof that the `parts` are positive-/\n  parts_pos : \u2200 {i}, i \u2208 parts \u2192 0 < i\n  /-- proof that the `parts` sum to `n`-/\n  parts_sum : parts.sum = n\n  -- porting notes: chokes on `parts_pos`\n  --deriving DecidableEq\n#align nat.partition Nat.Partition\n\nnamespace Partition\n\ninstance decidableEqParition: DecidableEq (Partition n)\n  | p, q => by simp [Partition.ext_iff]; exact decidableEq p.parts q.parts\n\n/-- A composition induces a partition (just convert the list to a multiset). -/\ndef ofComposition (n : \u2115) (c : Composition n) : Partition n\n    where\n  parts := c.blocks\n  parts_pos {i} hi := c.blocks_pos hi\n  parts_sum := by rw [Multiset.coe_sum, c.blocks_sum]\n#align nat.partition.of_composition Nat.Partition.ofComposition\n\ntheorem ofComposition_surj {n : \u2115} : Function.Surjective (ofComposition n) := by\n  rintro \u27e8b, hb\u2081, hb\u2082\u27e9\n  rcases Quotient.exists_rep b with \u27e8b, rfl\u27e9\n  refine' \u27e8\u27e8b, fun {i} hi => hb\u2081 hi, _\u27e9, Partition.ext _ _ rfl\u27e9\n  simpa using hb\u2082\n#align nat.partition.of_composition_surj Nat.Partition.ofComposition_surj\n\n-- The argument `n` is kept explicit here since it is useful in tactic mode proofs to generate the\n-- proof obligation `l.sum = n`.\n/-- Given a multiset which sums to `n`, construct a partition of `n` with the same multiset, but\nwithout the zeros.\n-/\ndef ofSums (n : \u2115) (l : Multiset \u2115) (hl : l.sum = n) : Partition n\n    where\n  parts := l.filter (\u00b7 \u2260 0)\n  parts_pos {i} hi := Nat.pos_of_ne_zero <| by apply of_mem_filter hi\n  parts_sum := by\n    have lt : l.filter (\u00b7 = 0) + l.filter (\u00b7 \u2260 0) = l := filter_add_not _ l\n    apply_fun Multiset.sum  at lt\n    have lz : (l.filter (\u00b7 = 0)).sum = 0 :=\n      by\n      rw [Multiset.sum_eq_zero_iff]\n      simp\n    rwa [sum_add (filter (fun x => x = 0) l) (filter (fun x => \u00acx = 0) l),lz,hl, zero_add] at lt\n#align nat.partition.of_sums Nat.Partition.ofSums\n\n/-- A `Multiset \u2115` induces a partition on its sum. -/\ndef ofMultiset (l : Multiset \u2115) : Partition l.sum :=\n  ofSums _ l rfl\n#align nat.partition.of_multiset Nat.Partition.ofMultiset\n\n/-- The partition of exactly one part. -/\ndef indiscretePartition (n : \u2115) : Partition n :=\n  ofSums n {n} rfl\n#align nat.partition.indiscrete_partition Nat.Partition.indiscretePartition\n\ninstance {n : \u2115} : Inhabited (Partition n) :=\n  \u27e8indiscretePartition n\u27e9\n\n/-- The number of times a positive integer `i` appears in the partition `ofSums n l hl` is the same\nas the number of times it appears in the multiset `l`.\n(For `i = 0`, `Partition.non_zero` combined with `Multiset.count_eq_zero_of_not_mem` gives that\nthis is `0` instead.)\n-/\ntheorem count_ofSums_of_ne_zero {n : \u2115} {l : Multiset \u2115} (hl : l.sum = n) {i : \u2115} (hi : i \u2260 0) :\n    (ofSums n l hl).parts.count i = l.count i :=\n  count_filter_of_pos hi\n#align nat.partition.count_of_sums_of_ne_zero Nat.Partition.count_ofSums_of_ne_zero\n\ntheorem count_ofSums_zero {n : \u2115} {l : Multiset \u2115} (hl : l.sum = n) :\n    (ofSums n l hl).parts.count 0 = 0 :=\n  count_filter_of_neg fun h => h rfl\n#align nat.partition.count_of_sums_zero Nat.Partition.count_ofSums_zero\n\n/-- Show there are finitely many partitions by considering the surjection from compositions to\npartitions.\n-/\ninstance (n : \u2115) : Fintype (Partition n) :=\n  Fintype.ofSurjective (ofComposition n) ofComposition_surj\n\n/-- The finset of those partitions in which every part is odd. -/\ndef odds (n : \u2115) : Finset (Partition n) :=\n  Finset.univ.filter fun c => \u2200 i \u2208 c.parts, \u00acEven i\n#align nat.partition.odds Nat.Partition.odds\n\n/-- The finset of those partitions in which each part is used at most once. -/\ndef distincts (n : \u2115) : Finset (Partition n) :=\n  Finset.univ.filter fun c => c.parts.Nodup\n#align nat.partition.distincts Nat.Partition.distincts\n\n/-- The finset of those partitions in which every part is odd and used at most once. -/\ndef oddDistincts (n : \u2115) : Finset (Partition n) :=\n  odds n \u2229 distincts n\n#align nat.partition.odd_distincts Nat.Partition.oddDistincts\n\nend Partition\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/Partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7360143857044547}}
{"text": "/-\nCopyright (c) 2019 Yury Kudriashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudriashov\n-/\nimport algebra.big_operators.order\nimport analysis.convex.hull\nimport linear_algebra.affine_space.basis\n\n/-!\n# Convex combinations\n\nThis file defines convex combinations of points in a vector space.\n\n## Main declarations\n\n* `finset.center_mass`: Center of mass of a finite family of points.\n\n## Implementation notes\n\nWe divide by the sum of the weights in the definition of `finset.center_mass` because of the way\nmathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few\nlemmas unconditional on the sum of the weights being `1`.\n-/\n\nopen set function\nopen_locale big_operators classical pointwise\n\nuniverses u u'\nvariables {R E F \u03b9 \u03b9' \u03b1 : Type*} [linear_ordered_field R] [add_comm_group E] [add_comm_group F]\n  [linear_ordered_add_comm_group \u03b1] [module R E] [module R F] [module R \u03b1] [ordered_smul R \u03b1]\n  {s : set E}\n\n/-- Center of mass of a finite collection of points with prescribed weights.\nNote that we require neither `0 \u2264 w i` nor `\u2211 w = 1`. -/\ndef finset.center_mass (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E) : E :=\n(\u2211 i in t, w i)\u207b\u00b9 \u2022 (\u2211 i in t, w i \u2022 z i)\n\nvariables (i j : \u03b9) (c : R) (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n\nopen finset\n\nlemma finset.center_mass_empty : (\u2205 : finset \u03b9).center_mass w z = 0 :=\nby simp only [center_mass, sum_empty, smul_zero]\n\nlemma finset.center_mass_pair (hne : i \u2260 j) :\n  ({i, j} : finset \u03b9).center_mass w z = (w i / (w i + w j)) \u2022 z i + (w j / (w i + w j)) \u2022 z j :=\nby simp only [center_mass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul]\n\nvariable {w}\n\nlemma finset.center_mass_insert (ha : i \u2209 t) (hw : \u2211 j in t, w j \u2260 0) :\n  (insert i t).center_mass w z = (w i / (w i + \u2211 j in t, w j)) \u2022 z i +\n    ((\u2211 j in t, w j) / (w i + \u2211 j in t, w j)) \u2022 t.center_mass w z :=\nbegin\n  simp only [center_mass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, \u2190 div_eq_inv_mul],\n  congr' 2,\n  rw [div_mul_eq_mul_div, mul_inv_cancel hw, one_div]\nend\n\nlemma finset.center_mass_singleton (hw : w i \u2260 0) : ({i} : finset \u03b9).center_mass w z = z i :=\nby rw [center_mass, sum_singleton, sum_singleton, \u2190 mul_smul, inv_mul_cancel hw, one_smul]\n\nlemma finset.center_mass_eq_of_sum_1 (hw : \u2211 i in t, w i = 1) :\n  t.center_mass w z = \u2211 i in t, w i \u2022 z i :=\nby simp only [finset.center_mass, hw, inv_one, one_smul]\n\nlemma finset.center_mass_smul : t.center_mass w (\u03bb i, c \u2022 z i) = c \u2022 t.center_mass w z :=\nby simp only [finset.center_mass, finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc]\n\n/-- A convex combination of two centers of mass is a center of mass as well. This version\ndeals with two different index types. -/\nlemma finset.center_mass_segment'\n  (s : finset \u03b9) (t : finset \u03b9') (ws : \u03b9 \u2192 R) (zs : \u03b9 \u2192 E) (wt : \u03b9' \u2192 R) (zt : \u03b9' \u2192 E)\n  (hws : \u2211 i in s, ws i = 1) (hwt : \u2211 i in t, wt i = 1) (a b : R) (hab : a + b = 1) :\n  a \u2022 s.center_mass ws zs + b \u2022 t.center_mass wt zt =\n    (s.disj_sum t).center_mass (sum.elim (\u03bb i, a * ws i) (\u03bb j, b * wt j)) (sum.elim zs zt) :=\nbegin\n  rw [s.center_mass_eq_of_sum_1 _ hws, t.center_mass_eq_of_sum_1 _ hwt,\n    smul_sum, smul_sum, \u2190 finset.sum_sum_elim, finset.center_mass_eq_of_sum_1],\n  { congr' with \u27e8\u27e9; simp only [sum.elim_inl, sum.elim_inr, mul_smul] },\n  { rw [sum_sum_elim, \u2190 mul_sum, \u2190 mul_sum, hws, hwt, mul_one, mul_one, hab] }\nend\n\n/-- A convex combination of two centers of mass is a center of mass as well. This version\nworks if two centers of mass share the set of original points. -/\nlemma finset.center_mass_segment\n  (s : finset \u03b9) (w\u2081 w\u2082 : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n  (hw\u2081 : \u2211 i in s, w\u2081 i = 1) (hw\u2082 : \u2211 i in s, w\u2082 i = 1) (a b : R) (hab : a + b = 1) :\n  a \u2022 s.center_mass w\u2081 z + b \u2022 s.center_mass w\u2082 z =\n    s.center_mass (\u03bb i, a * w\u2081 i + b * w\u2082 i) z :=\nhave hw : \u2211 i in s, (a * w\u2081 i + b * w\u2082 i) = 1,\n  by simp only [mul_sum.symm, sum_add_distrib, mul_one, *],\nby simp only [finset.center_mass_eq_of_sum_1, smul_sum, sum_add_distrib, add_smul, mul_smul, *]\n\nlemma finset.center_mass_ite_eq (hi : i \u2208 t) :\n  t.center_mass (\u03bb j, if (i = j) then (1 : R) else 0) z = z i :=\nbegin\n  rw [finset.center_mass_eq_of_sum_1],\n  transitivity \u2211 j in t, if (i = j) then z i else 0,\n  { congr' with i, split_ifs, exacts [h \u25b8 one_smul _ _, zero_smul _ _] },\n  { rw [sum_ite_eq, if_pos hi] },\n  { rw [sum_ite_eq, if_pos hi] }\nend\n\nvariables {t w}\n\nlemma finset.center_mass_subset {t' : finset \u03b9} (ht : t \u2286 t')\n  (h : \u2200 i \u2208 t', i \u2209 t \u2192 w i = 0) :\n  t.center_mass w z = t'.center_mass w z :=\nbegin\n  rw [center_mass, sum_subset ht h, smul_sum, center_mass, smul_sum],\n  apply sum_subset ht,\n  assume i hit' hit,\n  rw [h i hit' hit, zero_smul, smul_zero]\nend\n\nlemma finset.center_mass_filter_ne_zero :\n  (t.filter (\u03bb i, w i \u2260 0)).center_mass w z = t.center_mass w z :=\nfinset.center_mass_subset z (filter_subset _ _) $ \u03bb i hit hit',\n  by simpa only [hit, mem_filter, true_and, ne.def, not_not] using hit'\n\nnamespace finset\n\nlemma center_mass_le_sup {s : finset \u03b9} {f : \u03b9 \u2192 \u03b1} {w : \u03b9 \u2192 R}\n  (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : 0 < \u2211 i in s, w i) :\n  s.center_mass w f \u2264 s.sup' (nonempty_of_ne_empty $ by { rintro rfl, simpa using hw\u2081 }) f :=\nbegin\n  rw [center_mass, inv_smul_le_iff hw\u2081, sum_smul],\n  exact sum_le_sum (\u03bb i hi, smul_le_smul_of_nonneg (le_sup' _ hi) $ hw\u2080 i hi),\n  apply_instance,\nend\n\nlemma inf_le_center_mass {s : finset \u03b9} {f : \u03b9 \u2192 \u03b1} {w : \u03b9 \u2192 R}\n  (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : 0 < \u2211 i in s, w i) :\n  s.inf' (nonempty_of_ne_empty $ by { rintro rfl, simpa using hw\u2081 }) f \u2264 s.center_mass w f :=\n@center_mass_le_sup R _ \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ hw\u2080 hw\u2081\n\nend finset\n\n\nvariable {z}\n\n/-- The center of mass of a finite subset of a convex set belongs to the set\nprovided that all weights are non-negative, and the total weight is positive. -/\nlemma convex.center_mass_mem (hs : convex R s) :\n  (\u2200 i \u2208 t, 0 \u2264 w i) \u2192 (0 < \u2211 i in t, w i) \u2192 (\u2200 i \u2208 t, z i \u2208 s) \u2192 t.center_mass w z \u2208 s :=\nbegin\n  induction t using finset.induction with i t hi ht, { simp [lt_irrefl] },\n  intros h\u2080 hpos hmem,\n  have zi : z i \u2208 s, from hmem _ (mem_insert_self _ _),\n  have hs\u2080 : \u2200 j \u2208 t, 0 \u2264 w j, from \u03bb j hj, h\u2080 j $ mem_insert_of_mem hj,\n  rw [sum_insert hi] at hpos,\n  by_cases hsum_t : \u2211 j in t, w j = 0,\n  { have ws : \u2200 j \u2208 t, w j = 0, from (sum_eq_zero_iff_of_nonneg hs\u2080).1 hsum_t,\n    have wz : \u2211 j in t, w j \u2022 z j = 0, from sum_eq_zero (\u03bb i hi, by simp [ws i hi]),\n    simp only [center_mass, sum_insert hi, wz, hsum_t, add_zero],\n    simp only [hsum_t, add_zero] at hpos,\n    rw [\u2190 mul_smul, inv_mul_cancel (ne_of_gt hpos), one_smul],\n    exact zi },\n  { rw [finset.center_mass_insert _ _ _ hi hsum_t],\n    refine convex_iff_div.1 hs zi (ht hs\u2080 _ _) _ (sum_nonneg hs\u2080) hpos,\n    { exact lt_of_le_of_ne (sum_nonneg hs\u2080) (ne.symm hsum_t) },\n    { intros j hj, exact hmem j (mem_insert_of_mem hj) },\n    { exact h\u2080 _ (mem_insert_self _ _) } }\nend\n\nlemma convex.sum_mem (hs : convex R s) (h\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (h\u2081 : \u2211 i in t, w i = 1)\n  (hz : \u2200 i \u2208 t, z i \u2208 s) :\n  \u2211 i in t, w i \u2022 z i \u2208 s :=\nby simpa only [h\u2081, center_mass, inv_one, one_smul] using\n  hs.center_mass_mem h\u2080 (h\u2081.symm \u25b8 zero_lt_one) hz\n\n/-- A version of `convex.sum_mem` for `finsum`s. If `s` is a convex set, `w : \u03b9 \u2192 R` is a family of\nnonnegative weights with sum one and `z : \u03b9 \u2192 E` is a family of elements of a module over `R` such\nthat `z i \u2208 s` whenever `w i \u2260 0``, then the sum `\u2211\u1da0 i, w i \u2022 z i` belongs to `s`. See also\n`partition_of_unity.finsum_smul_mem_convex`. -/\nlemma convex.finsum_mem {\u03b9 : Sort*} {w : \u03b9 \u2192 R} {z : \u03b9 \u2192 E} {s : set E}\n  (hs : convex R s) (h\u2080 : \u2200 i, 0 \u2264 w i) (h\u2081 : \u2211\u1da0 i, w i = 1) (hz : \u2200 i, w i \u2260 0 \u2192 z i \u2208 s) :\n  \u2211\u1da0 i, w i \u2022 z i \u2208 s :=\nbegin\n  have hfin_w : (support (w \u2218 plift.down)).finite,\n  { by_contra H,\n    rw [finsum, dif_neg H] at h\u2081,\n    exact zero_ne_one h\u2081 },\n  have hsub : support ((\u03bb i, w i \u2022 z i) \u2218 plift.down) \u2286 hfin_w.to_finset,\n    from (support_smul_subset_left _ _).trans hfin_w.coe_to_finset.ge,\n  rw [finsum_eq_sum_plift_of_support_subset hsub],\n  refine hs.sum_mem (\u03bb _ _, h\u2080 _) _ (\u03bb i hi, hz _ _),\n  { rwa [finsum, dif_pos hfin_w] at h\u2081 },\n  { rwa [hfin_w.mem_to_finset] at hi }\nend\n\nlemma convex_iff_sum_mem :\n  convex R s \u2194\n    (\u2200 (t : finset E) (w : E \u2192 R),\n      (\u2200 i \u2208 t, 0 \u2264 w i) \u2192 \u2211 i in t, w i = 1 \u2192 (\u2200 x \u2208 t, x \u2208 s) \u2192 \u2211 x in t, w x \u2022 x \u2208 s ) :=\nbegin\n  refine \u27e8\u03bb hs t w hw\u2080 hw\u2081 hts, hs.sum_mem hw\u2080 hw\u2081 hts, _\u27e9,\n  intros h x hx y hy a b ha hb hab,\n  by_cases h_cases: x = y,\n  { rw [h_cases, \u2190add_smul, hab, one_smul], exact hy },\n  { convert h {x, y} (\u03bb z, if z = y then b else a) _ _ _,\n    { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl] },\n    { simp_intros i hi,\n      cases hi; subst i; simp [ha, hb, if_neg h_cases] },\n    { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl, hab] },\n    { simp_intros i hi,\n      cases hi; subst i; simp [hx, hy, if_neg h_cases] } }\nend\n\nlemma finset.center_mass_mem_convex_hull (t : finset \u03b9) {w : \u03b9 \u2192 R} (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (hws : 0 < \u2211 i in t, w i) {z : \u03b9 \u2192 E} (hz : \u2200 i \u2208 t, z i \u2208 s) :\n  t.center_mass w z \u2208 convex_hull R s :=\n(convex_convex_hull R s).center_mass_mem hw\u2080 hws (\u03bb i hi, subset_convex_hull R s $ hz i hi)\n\n/-- A refinement of `finset.center_mass_mem_convex_hull` when the indexed family is a `finset` of\nthe space. -/\nlemma finset.center_mass_id_mem_convex_hull (t : finset E) {w : E \u2192 R} (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (hws : 0 < \u2211 i in t, w i) :\n  t.center_mass w id \u2208 convex_hull R (t : set E) :=\nt.center_mass_mem_convex_hull hw\u2080 hws (\u03bb i, mem_coe.2)\n\nlemma affine_combination_eq_center_mass {\u03b9 : Type*} {t : finset \u03b9} {p : \u03b9 \u2192 E} {w : \u03b9 \u2192 R}\n  (hw\u2082 : \u2211 i in t, w i = 1) :\n  t.affine_combination R p w = center_mass t w p :=\nbegin\n  rw [affine_combination_eq_weighted_vsub_of_point_vadd_of_sum_eq_one _ w _ hw\u2082 (0 : E),\n    finset.weighted_vsub_of_point_apply, vadd_eq_add, add_zero, t.center_mass_eq_of_sum_1 _ hw\u2082],\n  simp_rw [vsub_eq_sub, sub_zero],\nend\n\nlemma affine_combination_mem_convex_hull\n  {s : finset \u03b9} {v : \u03b9 \u2192 E} {w : \u03b9 \u2192 R} (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : s.sum w = 1) :\n  s.affine_combination R v w \u2208 convex_hull R (range v) :=\nbegin\n  rw affine_combination_eq_center_mass hw\u2081,\n  apply s.center_mass_mem_convex_hull hw\u2080,\n  { simp [hw\u2081], },\n  { simp, },\nend\n\n/-- The centroid can be regarded as a center of mass. -/\n@[simp] lemma finset.centroid_eq_center_mass (s : finset \u03b9) (hs : s.nonempty) (p : \u03b9 \u2192 E) :\n  s.centroid R p = s.center_mass (s.centroid_weights R) p :=\naffine_combination_eq_center_mass (s.sum_centroid_weights_eq_one_of_nonempty R hs)\n\nlemma finset.centroid_mem_convex_hull (s : finset E) (hs : s.nonempty) :\n  s.centroid R id \u2208 convex_hull R (s : set E) :=\nbegin\n  rw s.centroid_eq_center_mass hs,\n  apply s.center_mass_id_mem_convex_hull,\n  { simp only [inv_nonneg, implies_true_iff, nat.cast_nonneg, finset.centroid_weights_apply], },\n  { have hs_card : (s.card : R) \u2260 0, { simp [finset.nonempty_iff_ne_empty.mp hs] },\n    simp only [hs_card, finset.sum_const, nsmul_eq_mul, mul_inv_cancel, ne.def, not_false_iff,\n      finset.centroid_weights_apply, zero_lt_one] }\nend\n\nlemma convex_hull_range_eq_exists_affine_combination (v : \u03b9 \u2192 E) :\n  convex_hull R (range v) = { x | \u2203 (s : finset \u03b9) (w : \u03b9 \u2192 R)\n    (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : s.sum w = 1), s.affine_combination R v w = x } :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    obtain \u27e8i, hi\u27e9 := set.mem_range.mp hx,\n    refine \u27e8{i}, function.const \u03b9 (1 : R), by simp, by simp, by simp [hi]\u27e9, },\n  { rintro x \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9 y \u27e8s', w', hw\u2080', hw\u2081', rfl\u27e9 a b ha hb hab,\n    let W : \u03b9 \u2192 R := \u03bb i, (if i \u2208 s then a * w i else 0) + (if i \u2208 s' then b * w' i else 0),\n    have hW\u2081 : (s \u222a s').sum W = 1,\n    { rw [sum_add_distrib, \u2190 sum_subset (subset_union_left s s'),\n        \u2190 sum_subset (subset_union_right s s'), sum_ite_of_true _ _ (\u03bb i hi, hi),\n        sum_ite_of_true _ _ (\u03bb i hi, hi), \u2190 mul_sum, \u2190 mul_sum, hw\u2081, hw\u2081', \u2190 add_mul, hab, mul_one];\n      intros i hi hi';\n      simp [hi'], },\n    refine \u27e8s \u222a s', W, _, hW\u2081, _\u27e9,\n    { rintros i -,\n      by_cases hi : i \u2208 s;\n      by_cases hi' : i \u2208 s';\n      simp [hi, hi', add_nonneg, mul_nonneg ha (hw\u2080 i _), mul_nonneg hb (hw\u2080' i _)], },\n    { simp_rw [affine_combination_eq_linear_combination (s \u222a s') v _ hW\u2081,\n        affine_combination_eq_linear_combination s v w hw\u2081,\n        affine_combination_eq_linear_combination s' v w' hw\u2081', add_smul, sum_add_distrib],\n      rw [\u2190 sum_subset (subset_union_left s s'), \u2190 sum_subset (subset_union_right s s')],\n      { simp only [ite_smul, sum_ite_of_true _ _ (\u03bb i hi, hi), mul_smul, \u2190 smul_sum], },\n      { intros i hi hi', simp [hi'], },\n      { intros i hi hi', simp [hi'], }, }, },\n  { rintros x \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9,\n    exact affine_combination_mem_convex_hull hw\u2080 hw\u2081, },\nend\n\n/-- Convex hull of `s` is equal to the set of all centers of masses of `finset`s `t`, `z '' t \u2286 s`.\nThis version allows finsets in any type in any universe. -/\nlemma convex_hull_eq (s : set E) :\n  convex_hull R s = {x : E | \u2203 (\u03b9 : Type u') (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n    (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (hw\u2081 : \u2211 i in t, w i = 1) (hz : \u2200 i \u2208 t, z i \u2208 s),\n    t.center_mass w z = x} :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    use [punit, {punit.star}, \u03bb _, 1, \u03bb _, x, \u03bb _ _, zero_le_one,\n      finset.sum_singleton, \u03bb _ _, hx],\n    simp only [finset.center_mass, finset.sum_singleton, inv_one, one_smul] },\n  { rintros x \u27e8\u03b9, sx, wx, zx, hwx\u2080, hwx\u2081, hzx, rfl\u27e9 y \u27e8\u03b9', sy, wy, zy, hwy\u2080, hwy\u2081, hzy, rfl\u27e9\n      a b ha hb hab,\n    rw [finset.center_mass_segment' _ _ _ _ _ _ hwx\u2081 hwy\u2081 _ _ hab],\n    refine \u27e8_, _, _, _, _, _, _, rfl\u27e9,\n    { rintros i hi,\n      rw [finset.mem_disj_sum] at hi,\n      rcases hi with \u27e8j, hj, rfl\u27e9|\u27e8j, hj, rfl\u27e9;\n        simp only [sum.elim_inl, sum.elim_inr];\n        apply_rules [mul_nonneg, hwx\u2080, hwy\u2080] },\n    { simp [finset.sum_sum_elim, finset.mul_sum.symm, *], },\n    { intros i hi,\n      rw [finset.mem_disj_sum] at hi,\n      rcases hi with \u27e8j, hj, rfl\u27e9|\u27e8j, hj, rfl\u27e9; apply_rules [hzx, hzy] } },\n  { rintros _ \u27e8\u03b9, t, w, z, hw\u2080, hw\u2081, hz, rfl\u27e9,\n    exact t.center_mass_mem_convex_hull hw\u2080 (hw\u2081.symm \u25b8 zero_lt_one) hz }\nend\n\nlemma finset.convex_hull_eq (s : finset E) :\n  convex_hull R \u2191s = {x : E | \u2203 (w : E \u2192 R) (hw\u2080 : \u2200 y \u2208 s, 0 \u2264 w y) (hw\u2081 : \u2211 y in s, w y = 1),\n    s.center_mass w id = x} :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    rw [finset.mem_coe] at hx,\n    refine \u27e8_, _, _, finset.center_mass_ite_eq _ _ _ hx\u27e9,\n    { intros, split_ifs, exacts [zero_le_one, le_refl 0] },\n    { rw [finset.sum_ite_eq, if_pos hx] } },\n  { rintro x \u27e8wx, hwx\u2080, hwx\u2081, rfl\u27e9 y \u27e8wy, hwy\u2080, hwy\u2081, rfl\u27e9 a b ha hb hab,\n    rw [finset.center_mass_segment _ _ _ _ hwx\u2081 hwy\u2081 _ _ hab],\n    refine \u27e8_, _, _, rfl\u27e9,\n    { rintros i hi,\n      apply_rules [add_nonneg, mul_nonneg, hwx\u2080, hwy\u2080], },\n    { simp only [finset.sum_add_distrib, finset.mul_sum.symm, mul_one, *] } },\n  { rintros _ \u27e8w, hw\u2080, hw\u2081, rfl\u27e9,\n    exact s.center_mass_mem_convex_hull (\u03bb x hx, hw\u2080 _ hx)\n      (hw\u2081.symm \u25b8 zero_lt_one) (\u03bb x hx, hx) }\nend\n\nlemma finset.mem_convex_hull {s : finset E} {x : E} :\n  x \u2208 convex_hull R (s : set E) \u2194\n    \u2203 (w : E \u2192 R) (hw\u2080 : \u2200 y \u2208 s, 0 \u2264 w y) (hw\u2081 : \u2211 y in s, w y = 1), s.center_mass w id = x :=\nby rw [finset.convex_hull_eq, set.mem_set_of_eq]\n\nlemma set.finite.convex_hull_eq {s : set E} (hs : s.finite) :\n  convex_hull R s = {x : E | \u2203 (w : E \u2192 R) (hw\u2080 : \u2200 y \u2208 s, 0 \u2264 w y)\n    (hw\u2081 : \u2211 y in hs.to_finset, w y = 1), hs.to_finset.center_mass w id = x} :=\nby simpa only [set.finite.coe_to_finset, set.finite.mem_to_finset, exists_prop]\n  using hs.to_finset.convex_hull_eq\n\n/-- A weak version of Carath\u00e9odory's theorem. -/\nlemma convex_hull_eq_union_convex_hull_finite_subsets (s : set E) :\n  convex_hull R s = \u22c3 (t : finset E) (w : \u2191t \u2286 s), convex_hull R \u2191t :=\nbegin\n  refine subset.antisymm _ _,\n  { rw convex_hull_eq,\n    rintros x \u27e8\u03b9, t, w, z, hw\u2080, hw\u2081, hz, rfl\u27e9,\n    simp only [mem_Union],\n    refine \u27e8t.image z, _, _\u27e9,\n    { rw [coe_image, set.image_subset_iff],\n      exact hz },\n    { apply t.center_mass_mem_convex_hull hw\u2080,\n      { simp only [hw\u2081, zero_lt_one] },\n      { exact \u03bb i hi, finset.mem_coe.2 (finset.mem_image_of_mem _ hi) } } },\n  { exact Union_subset (\u03bb i, Union_subset convex_hull_mono), },\nend\n\nlemma mk_mem_convex_hull_prod {t : set F} {x : E} {y : F} (hx : x \u2208 convex_hull R s)\n  (hy : y \u2208 convex_hull R t) :\n  (x, y) \u2208 convex_hull R (s \u00d7\u02e2 t) :=\nbegin\n  rw convex_hull_eq at \u22a2 hx hy,\n  obtain \u27e8\u03b9, a, w, S, hw, hw', hS, hSp\u27e9 := hx,\n  obtain \u27e8\u03ba, b, v, T, hv, hv', hT, hTp\u27e9 := hy,\n  have h_sum : \u2211 (i : \u03b9 \u00d7 \u03ba) in a \u00d7\u02e2 b, w i.fst * v i.snd = 1,\n  { rw [finset.sum_product, \u2190 hw'],\n    congr,\n    ext i,\n    have : \u2211 (y : \u03ba) in b, w i * v y = \u2211 (y : \u03ba) in b, v y * w i,\n    { congr, ext, simp [mul_comm] },\n    rw [this, \u2190 finset.sum_mul, hv'],\n    simp },\n  refine \u27e8\u03b9 \u00d7 \u03ba, a \u00d7\u02e2 b, \u03bb p, (w p.1) * (v p.2), \u03bb p, (S p.1, T p.2),\n    \u03bb p hp, _, h_sum, \u03bb p hp, _, _\u27e9,\n  { rw mem_product at hp,\n    exact mul_nonneg (hw p.1 hp.1) (hv p.2 hp.2) },\n  { rw mem_product at hp,\n    exact \u27e8hS p.1 hp.1, hT p.2 hp.2\u27e9 },\n  ext,\n  { rw [\u2190hSp, finset.center_mass_eq_of_sum_1 _ _ hw', finset.center_mass_eq_of_sum_1 _ _ h_sum],\n    simp_rw [prod.fst_sum, prod.smul_mk],\n    rw finset.sum_product,\n    congr,\n    ext i,\n    have : \u2211 (j : \u03ba) in b, (w i * v j) \u2022 S i = \u2211 (j : \u03ba) in b, v j \u2022 w i \u2022 S i,\n    { congr, ext, rw [mul_smul, smul_comm] },\n    rw [this, \u2190finset.sum_smul, hv', one_smul] },\n  { rw [\u2190hTp, finset.center_mass_eq_of_sum_1 _ _ hv', finset.center_mass_eq_of_sum_1 _ _ h_sum],\n    simp_rw [prod.snd_sum, prod.smul_mk],\n    rw [finset.sum_product, finset.sum_comm],\n    congr,\n    ext j,\n    simp_rw mul_smul,\n    rw [\u2190finset.sum_smul, hw', one_smul] }\nend\n\n@[simp] lemma convex_hull_prod (s : set E) (t : set F) :\n  convex_hull R (s \u00d7\u02e2 t) = convex_hull R s \u00d7\u02e2 convex_hull R t :=\nsubset.antisymm (convex_hull_min (prod_mono (subset_convex_hull _ _) $ subset_convex_hull _ _) $\n  (convex_convex_hull _ _).prod $ convex_convex_hull _ _) $\n    prod_subset_iff.2 $ \u03bb x hx y, mk_mem_convex_hull_prod hx\n\nlemma convex_hull_add (s t : set E) : convex_hull R (s + t) = convex_hull R s + convex_hull R t :=\nby simp_rw [\u2190image2_add, \u2190image_prod, is_linear_map.is_linear_map_add.convex_hull_image,\n  convex_hull_prod]\n\nlemma convex_hull_sub (s t : set E) : convex_hull R (s - t) = convex_hull R s - convex_hull R t :=\nby simp_rw [sub_eq_add_neg, convex_hull_add, convex_hull_neg]\n\n/-! ### `std_simplex` -/\n\nvariables (\u03b9) [fintype \u03b9] {f : \u03b9 \u2192 R}\n\n/-- `std_simplex \ud835\udd5c \u03b9` is the convex hull of the canonical basis in `\u03b9 \u2192 \ud835\udd5c`. -/\nlemma convex_hull_basis_eq_std_simplex :\n  convex_hull R (range $ \u03bb(i j:\u03b9), if i = j then (1:R) else 0) = std_simplex R \u03b9 :=\nbegin\n  refine subset.antisymm (convex_hull_min _ (convex_std_simplex R \u03b9)) _,\n  { rintros _ \u27e8i, rfl\u27e9,\n    exact ite_eq_mem_std_simplex R i },\n  { rintros w \u27e8hw\u2080, hw\u2081\u27e9,\n    rw [pi_eq_sum_univ w, \u2190 finset.univ.center_mass_eq_of_sum_1 _ hw\u2081],\n    exact finset.univ.center_mass_mem_convex_hull (\u03bb i hi, hw\u2080 i)\n      (hw\u2081.symm \u25b8 zero_lt_one) (\u03bb i hi, mem_range_self i) }\nend\n\nvariable {\u03b9}\n\n/-- The convex hull of a finite set is the image of the standard simplex in `s \u2192 \u211d`\nunder the linear map sending each function `w` to `\u2211 x in s, w x \u2022 x`.\n\nSince we have no sums over finite sets, we use sum over `@finset.univ _ hs.fintype`.\nThe map is defined in terms of operations on `(s \u2192 \u211d) \u2192\u2097[\u211d] \u211d` so that later we will not need\nto prove that this map is linear. -/\nlemma set.finite.convex_hull_eq_image {s : set E} (hs : s.finite) :\n  convex_hull R s = by haveI := hs.fintype; exact\n    (\u21d1(\u2211 x : s, (@linear_map.proj R s _ (\u03bb i, R) _ _ x).smul_right x.1)) '' (std_simplex R s) :=\nbegin\n  rw [\u2190 convex_hull_basis_eq_std_simplex, \u2190 linear_map.convex_hull_image, \u2190 set.range_comp, (\u2218)],\n  apply congr_arg,\n  convert subtype.range_coe.symm,\n  ext x,\n  simp [linear_map.sum_apply, ite_smul, finset.filter_eq]\nend\n\n/-- All values of a function `f \u2208 std_simplex \ud835\udd5c \u03b9` belong to `[0, 1]`. -/\nlemma mem_Icc_of_mem_std_simplex (hf : f \u2208 std_simplex R \u03b9) (x) :\n  f x \u2208 Icc (0 : R) 1 :=\n\u27e8hf.1 x, hf.2 \u25b8 finset.single_le_sum (\u03bb y hy, hf.1 y) (finset.mem_univ x)\u27e9\n\n/-- The convex hull of an affine basis is the intersection of the half-spaces defined by the\ncorresponding barycentric coordinates. -/\nlemma affine_basis.convex_hull_eq_nonneg_coord {\u03b9 : Type*} (b : affine_basis \u03b9 R E) :\n  convex_hull R (range b) = {x | \u2200 i, 0 \u2264 b.coord i x} :=\nbegin\n  rw convex_hull_range_eq_exists_affine_combination,\n  ext x,\n  refine \u27e8_, \u03bb hx, _\u27e9,\n  { rintros \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9 i,\n    by_cases hi : i \u2208 s,\n    { rw b.coord_apply_combination_of_mem hi hw\u2081,\n      exact hw\u2080 i hi, },\n    { rw b.coord_apply_combination_of_not_mem hi hw\u2081, }, },\n  { have hx' : x \u2208 affine_span R (range b),\n    { rw b.tot, exact affine_subspace.mem_top R E x, },\n    obtain \u27e8s, w, hw\u2081, rfl\u27e9 := (mem_affine_span_iff_eq_affine_combination R E).mp hx',\n    refine \u27e8s, w, _, hw\u2081, rfl\u27e9,\n    intros i hi,\n    specialize hx i,\n    rw b.coord_apply_combination_of_mem hi hw\u2081 at hx,\n    exact hx, },\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/convex/combination.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7358914624140929}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-\n\n# More on functions\n\nAnother question on the Imperial introduction to proof problem sheet on functions\nis \"If `f : X \u2192 Y` and `g : Y \u2192 Z` and `g \u2218 f` is injective, is it true that `g` is injective?\"\nThis is not true. A counterexample could be made by letting `X` and `Z` have one element, \nand letting `Y` have two elements; `f` and `g` are then not hard to write down. Let's\nsee how to do this in Lean by making inductive types `X`, `Y` and `Z` and functions\n`f` and `g` which give an explicit counterexample.\n\n-/\n\n-- Let X be {a}\ninductive X : Type\n| a : X\n\n-- in fact the term of type X is called `X.a`.\n\n-- Let Y be {b,c}\ninductive Y : Type\n| b : Y\n| c : Y\n\ninductive Z : Type\n| d : Z\n\n-- Define f by f(X.a)=Y.b\ndef f : X \u2192 Y\n| X.a := Y.b\n\n-- define g by g(Y.b)=g(Y.c)=Z.d\ndef g : Y \u2192 Z\n| Y.b := Z.d\n| Y.c := Z.d\n\n-- Here `Z` only has one term, so if `z : Z` then `cases z` only produces one goal,\n-- namely \"what you get if you change `z` to `Z.d`\".\nexample (z : Z) : z = Z.d :=\nbegin\n  cases z,\n  refl,\nend\n\nlemma Yb_ne_Yc : Y.b \u2260 Y.c :=\nbegin\n  intro h, -- x \u2260 y is definitionally equal to (x = y) \u2192 false\n  cases h, -- no cases when they're equal!\nend\n\n-- The above and the below show that `g` is not injective\nlemma gYb_eq_gYc : g Y.b = g Y.c :=\nbegin\n  -- they're both definitionally `Z.d` so which tactic solves this goal?\n  sorry\nend\n\nopen function\n\nlemma gf_injective : injective (g \u2218 f) :=\nbegin\n  sorry,\nend\n\n-- This is a question on the IUM (Imperial introduction to proof course) function problem sheet.\n-- Recall that if you have a hypothesis of the form `h : \u2200 A, ...`, then `specialize h X`\n-- will specialize `h` to the specific case `A = X`.\nexample : \u00ac (\u2200 A B C : Type, \u2200 (\u03c6 : A \u2192 B) (\u03c8 : B \u2192 C), injective (\u03c8 \u2218 \u03c6) \u2192 injective \u03c8) :=\nbegin\n  sorry,\nend\n\n-- This is another one. You might want to make some sublemmas first.\nexample : \u00ac (\u2200 A B C : Type, \u2200 (\u03c6 : A \u2192 B) (\u03c8 : B \u2192 C), surjective (\u03c8 \u2218 \u03c6) \u2192 surjective \u03c6) :=\nbegin\n  sorry,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section03functions/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7358914617873885}}
{"text": "/-\nThis is a d\u2203\u2200duction file providing exercises for basic set theory. French version.\n-/\n\nimport data.set\nimport tactic\n\n-- dEAduction tactics\nimport structures2      -- hypo_analysis, targets_analysis\nimport utils            -- no_meta_vars\nimport user_notations   -- notations that can be used in deaduction UI for a new object\nimport push_neg_once\n\n-- dEAduction definitions\nimport set_definitions\n\n-- General principles :\n-- Type should be defined as parameters, in order to be implicit everywhere\n-- other parameters are implicit in definitions, i.e. defined using '{}' (e.g. {A : set X} )\n-- but explicit everywhere else, i.e. defined using '()' (e.g. (A : set X) )\n-- each definition must be an iff statement or an equality\n-- (since it will be called with 'rw' or 'symp_rw')\n\n-------------------------\n-- dEAduction METADATA --\n-------------------------\n-- logic names ['and', 'or', 'negate', 'implicate', 'iff', 'forall', 'exists']\n-- proofs names ['use_proof_methods', 'new_object', 'apply', 'assumption']\n-- magic names ['compute']\n-- proof methods names ['cbr', 'contrapose', 'absurdum', 'sorry']\n\n/- dEAduction\nTitle\n    Th\u00e9orie des ensembles\nAuthor\n    Fr\u00e9d\u00e9ric Le Roux\nInstitution\n    Universit\u00e9 de France\nDescription\n    Ce cours correspond \u00e0 un cours standard de th\u00e9orie \"\u00e9l\u00e9mentaire\" des ensembles.\n-/\n\nlocal attribute [instance] classical.prop_decidable\n\n---------------------------------------------\n-- global parameters = implicit variables --\n---------------------------------------------\nsection course\nparameters {X Y Z: Type}\n\n\nopen set\n\n------------------\n-- COURSE TITLE --\n------------------\nnamespace theorie_des_ensembles\n/- dEAduction\nPrettyName\n    Th\u00e9orie des ensembles\n-/\n\nnamespace generalites\n/- dEAduction\nPrettyName\n    G\u00e9n\u00e9ralit\u00e9s\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\nlemma definition.inclusion {A B : set X} : A \u2286 B \u2194 \u2200 {x:X}, x \u2208 A \u2192 x \u2208 B :=\n/- dEAduction\nImplicitUse\n    True\n-/\nbegin\n    exact iff.rfl,\nend\n\nlemma definition.egalite_deux_ensembles {A A' : set X} :\n(A = A') \u2194 ( \u2200 x, x \u2208 A \u2194 x \u2208 A' ) :=\n/- dEAduction\nPrettyName\n    Egalit\u00e9 de deux ensembles\nImplicitUse\n    True\n-/\nbegin\n     exact set.ext_iff\nend\n\nlemma definition.ensemble_vide\n(A: set X) :\n(A = \u2205) \u2194 \u2200 x : X, x \u2209 A\n:=\nbegin\n    exact eq_empty_iff_forall_not_mem,\nend\n\n-- lemma definition.ensemble_non_vide\n-- (A: set X) :\n-- (A \u2260 \u2205) \u2194 \u2203 x : X, x \u2208 A\n-- :=\n-- begin\n--     todo\n-- end\n\nlemma definition.ensemble_extension {X: Type}  {P : X \u2192 Prop} {x:X} :\n x \u2208 {x | P x} \u2194 P x\n:=\n/- dEAduction\nPrettyName\n    Ensemble en extension\n-/\nbegin\n    refl\nend\n\n\nlemma definition.double_inclusion (A A' : set X) :\nA = A' \u2194 (A \u2286 A' \u2227 A' \u2286 A) :=\n/- dEAduction\nPrettyName\n    Egalit\u00e9 de deux ensembles : double inclusion\nImplicitUse\n    True\n-/\nbegin\n    exact set.subset.antisymm_iff\nend\n\nlemma exercise.inclusion_transitive\n(A B C : set X) :\n(A \u2286 B \u2227 B \u2286 C) \u2192 A \u2286 C\n:=\n/- dEAduction\nPrettyName\n    Transitivit\u00e9 de l'inclusion\n-/\nbegin\n    todo\nend\n\n\nend generalites\n\n---------------\n-- SECTION 1 --\n---------------\nnamespace unions_et_intersections\n-- variables unions_et_intersections --\nvariables {A B C : set X}\n\n-----------------\n-- DEFINITIONS --\n-----------------\nnamespace definitions\n/- dEAduction\nPrettyName\n    D\u00e9finitions\n-/\n\nlemma definition.intersection_deux_ensembles {A B : set X} {x : X} :\nx \u2208 A \u2229 B \u2194 ( x \u2208 A \u2227 x \u2208 B) :=\n/- dEAduction\nPrettyName\n    Intersection de deux ensembles\nImplicitUse\n    True\n-/\nbegin\n    exact iff.rfl\nend\n\nlemma definition.intersection_quelconque_ensembles {I : index_set} {E : I \u2192 set X}  {x : X} :\n(x \u2208 set.Inter E) \u2194 (\u2200 i:I, x \u2208 E i) :=\n/- dEAduction\nPrettyName\n    Intersection d'une famille quelconque d'ensembles\nMatchPattern\n    IFF(\n    \u2208(?0, SET_INTER+(?1) )\n    \u2200(TYPE, ?2, \u2208(?0, APP(?1, ?2) ) ) \n    )\n-/\nbegin\n    exact set.mem_Inter\nend\n\nlemma definition.union_deux_ensembles  {A : set X} {B : set X} {x : X} :\nx \u2208 A \u222a B \u2194 ( x \u2208 A \u2228 x \u2208 B) :=\n/- dEAduction\nPrettyName\n    Union de deux ensembles\nImplicitUse\n    True\n-/\nbegin\n    exact iff.rfl\nend\n\nlemma definition.union_quelconque_ensembles {I : index_set} {E : I \u2192 set X}  {x : X} :\n(x \u2208 set.Union E) \u2194 (\u2203 i:I, x \u2208 E i) :=\n/- dEAduction\nPrettyName\n    Union d'une famille quelconque d'ensembles\n-/\nbegin\n    exact set.mem_Union\nend\n\nend definitions\n\n---------------\n-- EXERCICES --\n---------------\nnamespace exercices\n\nlemma exercise.intersection_inclus_ensemble :\nA \u2229 B \u2286 A\n:=\n/- dEAduction\nPrettyName\n    Un ensemble contient son intersection avec un autre\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.union_distributive_inter : A \u2229 (B \u222a C)  = (A \u2229 B) \u222a (A \u2229 C) :=\n/- dEAduction\nPrettyName\n    Intersection avec une union\nDescription\n    L'intersection est distributive par rapport \u00e0 l'union\nAvailableLogic\n    $ALL\nAvailableProofs\n    $ALL\nAvailableDefinitions\n    $UNTIL_NOW -union_quelconque_ensembles -intersection_quelconque_ensembles\nAvailableTheorems\n    double_inclusion\nExpectedVarsNumber\n    X=3, A=1, B=1\n-/\nbegin\n    rw generalites.definition.egalite_deux_ensembles,\n    intro x, split,\n    intro H,\n    cases H with H1 H2,\n    cases H2 with H2a H2b,\n    left,\n    split,\n    assumption, assumption,\n    right, split, assumption, assumption, todo\nend\n\n-- NB: 'ExpectedVarsNumber' is not implemented yet\n-- planned to be used for naming variables\n\n\nlemma exercise.inter_distributive_union : A \u222a (B \u2229 C)  = (A \u222a B) \u2229 (A \u222a C) :=\n/- dEAduction\nPrettyName\n    Union avec une intersection\nDescription\n    L'union est distributive par rapport \u00e0 l'intersection\nAvailableDefinitions\n    $UNTIL_NOW -union_quelconque_ensembles -intersection_quelconque_ensembles\n-/\nbegin\n    todo\nend\n\n\nend exercices\n\nend unions_et_intersections\n\n\n---------------\n-- SECTION 2 --\n---------------\nnamespace complementaire\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire\n-/\n\n\n-- variables complementaire --\nvariables  {A B : set X}\nvariables {I : index_set} {E F : I \u2192 set X}\n-- notation `\u2201`A := set.compl A\n\n-----------------\n-- DEFINITIONS --\n-----------------\nlemma definition.complement {A : set X} {x : X} : x \u2208 set.compl A \u2194 x \u2209 A :=\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire\n-/\nbegin\n    finish\nend\n\n---------------\n-- EXERCICES --\n---------------\nlemma exercise.complement_complement : (set.compl (set.compl A)) = A :=\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire du compl\u00e9mentaire\nDescription\n    Tout ensemble est \u00e9gal au compl\u00e9mentaire de son compl\u00e9mentaire\nAvailableDefinitions\n    $UNTIL_NOW -union_quelconque_ensembles -intersection_quelconque_ensembles\n-/\nbegin\n    todo\nend\n\nlemma exercise.complement_union_deux :\nset.compl (A \u222a B) = (set.compl A) \u2229 (set.compl B) :=\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire d'union I\nDescription\n    Le compl\u00e9mentaire de l'union de deux ensembles \u00e9gale l'intersection des compl\u00e9mentaires\nAvailableDefinitions\n    $UNTIL_NOW -union_quelconque_ensembles -intersection_quelconque_ensembles\n-/\nbegin\n    todo\nend\n\nlemma exercise.complement_union_quelconque :\nset.compl (set.Union (\u03bb i, E i)) = set.Inter (\u03bb i, set.compl (E i)) :=\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire d'union II\nDescription\n    Le compl\u00e9mentaire d'une r\u00e9union quelconque \u00e9gale l'intersection des compl\u00e9mentaires\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.inclusion_complement_I :\nA \u2286 B \u2192 set.compl B \u2286 set.compl A\n:=\n/- dEAduction\nPrettyName\n    Le passage au compl\u00e9mentaire renverse les inclusions, implication\nDescription\n    Si A est inclus dans B, alors le compl\u00e9mentaire de A contient le compl\u00e9mentaire de B\n-/\nbegin\n    todo\nend\n\nlemma exercise.inclusion_complement_II :\nA \u2286 B \u2194 set.compl B \u2286 set.compl A\n:=\n/- dEAduction\nPrettyName\n    Le passage au compl\u00e9mentaire renverse les inclusions, \u00e9quivalence\nDescription\n    Si A est inclus dans B, alors le compl\u00e9mentaire de A contient le compl\u00e9mentaire de B\n-/\nbegin\n    todo\nend\n\n/- Autres : diff\u00e9rence-/\n\nend complementaire\n\n\n\n-- Ajouter :  4. relations ?\n\nnamespace produits_cartesiens\n/- dEAduction\nPrettyName\n    Produits cart\u00e9siens\n-/\n\n\n-- Peut-on en faire une d\u00e9finition ?\nlemma theorem.type_produit :\n\u2200 z:X \u00d7 Y, \u2203 x:X, \u2203 y:Y, z = (x,y)\n:=\n/- dEAduction\nPrettyName\n    Element d'un produit cart\u00e9sien de deux ensembles\n-/\nbegin\n    todo\nend\n\n\nlemma definition.produit_de_parties {A : set X} {B : set Y}\n{x:X} {y:Y} :\n(x,y) \u2208 set.prod A B \u2194 x \u2208 A \u2227 y \u2208 B\n:=\n/- dEAduction\nPrettyName\n    Produit cart\u00e9sien de deux parties\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.produit_avec_intersection\n(A : set X) (B C : set Y) :\nset.prod A (B \u2229 C) = (set.prod A B) \u2229 (set.prod A C)\n:=\nbegin\n    todo,\nend\n\n\nend produits_cartesiens\n---------------\n-- SECTION 3 --\n---------------\nnamespace applications_I\n/- dEAduction\nPrettyName\n    Applications et op\u00e9rations ensemblistes\n-/\n\n\n-- variables applications --\n\nvariables  {A A': set X}\nvariables {f: X \u2192 Y} {B B': set Y}\n-- variables {I : Type} {E : I \u2192 set X} {F : I \u2192 set Y}\nvariables {I : index_set} {E : set_family I X} {F : set_family I Y}\nvariables (g : Y \u2192 Z) (h : X \u2192 Z)\n\n-- a-t-on besoin de ceci ?\n-- lemma theorem.egalite_fonctions : f = f' \u2194 \u2200 x : X, f(x) = f'(x) :=\n--  function.funext_iff\n\n\n-----------------\n-- DEFINITIONS --\n-----------------\nnamespace definitions\n/- dEAduction\nPrettyName\n    D\u00e9finitions\n-/\n\nlemma definition.image_directe (y : Y) : y \u2208 f '' A \u2194 \u2203 x : X, x \u2208 A \u2227  f x = y :=\nbegin\n    todo\nend\n\nlemma definition.image_reciproque (x:X) : x \u2208 f  \u207b\u00b9' B \u2194 f(x) \u2208 B :=\nbegin\n    todo\nend\n\nlemma definition.composition {x:X}:\ncomposition g f x = g (f x)\n:=\nbegin\n    todo,\nend\n\nlemma definition.egalite_fonctions (f' : X \u2192 Y) :\nf = f' \u2194 \u2200 x, f x = f' x :=\n/- dEAduction\nPrettyName\n    Egalit\u00e9 de deux fonctions\n-/\nbegin\n    exact function.funext_iff,\nend\n\n\nlemma definition.Identite (f\u2080: X \u2192 X) :\nf\u2080 = Identite \u2194 \u2200 x, f\u2080 x = x :=\n/- dEAduction\nPrettyName\n    Application identit\u00e9\n-/\nbegin\n    apply definition.egalite_fonctions,\nend\n\nend definitions\n\n---------------\n-- EXERCICES --\n---------------\nnamespace exercices\n/- dEAduction\nPrettyName\n    Exercices\n-/\nopen applications_I.definitions\n\nlemma exercise.image_de_reciproque : f '' (f \u207b\u00b9' B)  \u2286 B :=\n/- dEAduction\nPrettyName\n    Image de l'image r\u00e9ciproque\n-/\nbegin\n    todo\nend\n\nlemma exercise.reciproque_de_image : A \u2286 f \u207b\u00b9' (f '' A) :=\n/- dEAduction\nPrettyName\n    Image r\u00e9ciproque de l'image\n-/\nbegin\n    todo\nend\n\nlemma exercise.image_reciproque_inter :  f \u207b\u00b9'  (B\u2229B') = f \u207b\u00b9'  (B) \u2229 f \u207b\u00b9'  (B') :=\n/- dEAduction\nPrettyName\n    Image r\u00e9ciproque d'une intersection de deux ensembles\n-/\nbegin\n    todo\nend\n\nlemma  exercise.image_reciproque_union  : f \u207b\u00b9' (B \u222a B') = f \u207b\u00b9' B \u222a f \u207b\u00b9' B'\n:=\n/- dEAduction\nPrettyName\n    Image r\u00e9ciproque d'une union de deux ensembles\n-/\nbegin\n    todo\nend\n\n-- set_option pp.width 100\nlemma exercise.image_reciproque_inter_quelconque :\n(f \u207b\u00b9'  (set.Inter (F))) = set.Inter (\u03bb i, f \u207b\u00b9' (F i): set_family I X)\n-- (f \u207b\u00b9'  (set.Inter (\u03bb i, F i))) = set.Inter (\u03bb i, f \u207b\u00b9' (F i))\n:=\n/- dEAduction\nPrettyName\n    Image r\u00e9ciproque d'une intersection quelconque\n-/\nbegin\n    todo\nend\n\nlemma exercise.image_reciproque_union_quelconque :\n(f \u207b\u00b9'  (set.Union (\u03bb i, F i))) = set.Union (\u03bb i, f \u207b\u00b9' (F i))\n:=\n/- dEAduction\nPrettyName\n    Image r\u00e9ciproque d'une union quelconque\n-/\nbegin\n    todo\nend\n\nlemma exercise.image_inter_inclus_inter_images :\nf '' (A\u2229A') \u2286 f '' (A) \u2229 f '' (A')\n:=\n/- dEAduction\nPrettyName\n    Image d'une intersection\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.reciproque_complementaire_I :\nf \u207b\u00b9' (set.compl B) \u2286 set.compl (f \u207b\u00b9' B)\n:=\n/- dEAduction\nPrettyName\n    Image r\u00e9ciproque du compl\u00e9mentaire, inclusion\n-/\nbegin\n    todo\nend\n\nlemma exercise.reciproque_complementaire_II :\nf \u207b\u00b9' (set.compl B) = set.compl (f \u207b\u00b9' B)\n:=\n/- dEAduction\nPrettyName\n    Image r\u00e9ciproque du compl\u00e9mentaire, \u00e9galit\u00e9\n-/\nbegin\n    todo\nend\n\nlemma exercices.image_reciproque.composition\n(C: set Z)\n:\n((composition g f) )\u207b\u00b9' C = f \u207b\u00b9' (g \u207b\u00b9' C)\n:=\nbegin\n    todo\nend\n\nend exercices\nend applications_I\n\n----------------\n-- SUBSECTION --\n----------------\nnamespace applications_II\n/- dEAduction\nPrettyName\n    Injections et surjections\n-/\n\n-- variables injections_surjections --\nvariables (f: X \u2192 Y) (g : Y \u2192 Z) (h : X \u2192 Z)\n\n-----------------\n-- DEFINITIONS --\n-----------------\nnamespace definitions\n/- dEAduction\nPrettyName\n    D\u00e9finitions\n-/\n\nlemma definition.injectivite :\ninjective f \u2194 \u2200 x y : X, (f x = f y \u2192 x = y)\n:=\n/- dEAduction\nPrettyName\n    Application injective\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.surjectivite :\nsurjective f \u2194 \u2200 y : Y, \u2203 x : X, y = f x\n:=\n/- dEAduction\nPrettyName\n    Application surjective\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\n-- A bouger, mais \u00e0 enlever de tous les exos o\u00f9 \u00e7a ne sert pas !\nlemma definition.existe_un_unique\n(P : X \u2192 Prop) :\n(\u2203! (\u03bbx,  P x)) \u2194  (\u2203 x : X, (P x \u2227 (\u2200 x' : X, P x' \u2192 x' = x)))\n:=\n/- dEAduction\nPrettyName\n    \u2203! : existence et unicit\u00e9\n-/\nbegin\n    todo\nend\n\nlemma definition.bijectivite_1 :\nbijective f \u2194 (injective f \u2227 surjective f)\n:=\n/- dEAduction\nPrettyName\n    Application bijective (premi\u00e8re d\u00e9finition)\n-/\nbegin\n    todo\nend\n\nlemma definition.bijectivite_2 :\nbijective f \u2194 \u2200 y : Y, exists_unique (\u03bb x, y = f x)\n:=\n/- dEAduction\nPrettyName\n    Application bijective (seconde d\u00e9finition)\n-/\nbegin\n    refl,\nend\n\nend definitions\n\n\n\n---------------\n-- EXERCICES --\n---------------\nnamespace exercices\n/- dEAduction\nPrettyName\n    Exercices\n-/\n\nopen applications_II.definitions\n\nlemma exercise.composition_injections\n(H1 : injective f) (H2 : injective g)\n:\ninjective (composition g f)\n:=\n/- dEAduction\nPrettyName\n    Composition d'injections\n-/\nbegin\n    todo\nend\n\nlemma exercise.composition_surjections\n(H1 : surjective f) (H2 : surjective g) :\nsurjective (composition g f)\n:=\n/- dEAduction\nPrettyName\n    Composition de surjections\n-/\nbegin\n    todo\nend\n\nlemma exercise.injective_si_compo_injective\n(H1 : injective (composition g f)) :\ninjective f\n:=\n/- dEAduction\nPrettyName\n    Injective si composition injective\n-/\nbegin\n    todo\nend\n\nlemma exercise.surjective_si_compo_surjective\n(H1 : surjective (composition g f)) :\nsurjective g\n:=\n/- dEAduction\nPrettyName\n    Surjective si composition surjective\n-/\nbegin\n    todo\nend\n\nlemma exercise.injective_ssi_inverse_gauche : (injective f) \u2194\n\u2203 F: Y \u2192 X, (composition F f) = Identite :=\n/- dEAduction\nPrettyName\n    (x) Injectivit\u00e9 et inverse \u00e0 gauche\n-/\nbegin\n    todo\nend\n\nlemma exercise.surjective_ssi_inverse_droite : (surjective f) \u2194\n\u2203 F: Y \u2192 X, (composition f F) = Identite :=\n/- dEAduction\nPrettyName\n    (*) Surjectivit\u00e9 et inverse \u00e0 droite\n-/\nbegin\n    todo\nend\n\nlemma exercise.bijective_ssi_inverse :\n(bijective f) \u2194 \u2203 g : Y \u2192 X,\ncomposition g f = Identite \u2227 composition f g  = Identite\n:=\n/- dEAduction\nPrettyName\n    (**) Bijectivit\u00e9 et existence d'une application r\u00e9ciproque\n-/\nbegin\n    todo\nend\n\nlemma exercise.unicite_inverse :\n(bijective f) \u2192 exists_unique (\u03bb g : Y \u2192 X,\ncomposition g f = Identite)\n:=\n/- dEAduction\nPrettyName\n    (+) Unicit\u00e9 de la r\u00e9ciproque d'une application bijective\n-/\nbegin\n    todo\nend\n\n\n\nlemma exercise.Cantor (f : X \u2192 set X):\n \u00ac surjective f\n:=\n/- dEAduction\nPrettyName\n    (+) Th\u00e9or\u00e8me de Cantor : il n'y a pas de surjection d'un ensemble vers l'ensemble de ses parties\n-/\nbegin\n    by_contradiction H14,\n    let A := {x | x \u2209 f x}, have H15 : A = {x | x \u2209 f x}, refl,\n    rw theorie_des_ensembles.applications_II.definitions.definition.surjectivite at H14,\n    have H16 := H14 A,\n    cases H16 with x H17,\n    cases (classical.em (x dans A)) with H22 H23,\n    {\n        have H22b: x \u2209 A,\n        rw H15 at H22,\n        rw generalites.definition.ensemble_extension at H22,\n        rw H17, assumption,\n        contradiction,\n    },\n    {\n        have H22b: x \u2208 A,\n        rw H15 at H23,\n        -- simp only[ensemble_extension] at H23,\n        rw generalites.definition.ensemble_extension at H23,\n        push_neg at H23,\n        rw H17, assumption,\n        contradiction\n    }\nend\n\n\nend exercices\n\nend applications_II\n\n-----------------------------------\n-----------------------------------\nnamespace exercices_supplementaires\n\n\n-- relations : rel d'eq implique classes \u00e9gales ou disjointes\n-- les images r\u00e9ciproques des singletons forment une partition\n-- bijective ssi inversible \u00e0 g et d et inverses coincident\n\n\nlemma exercise.exercice_ensembles_1\n(A B : set X) :\nA \u2286 B \u2194 A \u2229 B = A\n:=\n/- dEAduction\nPrettyName\n    Caract\u00e9risation de l'inclusion par l'intersection\n-/\nbegin\n    todo\nend\n\nlemma exercise.complement_intersection_2\n(A B : set X):\nset.compl (A \u2229  B) = (set.compl A) \u222a (set.compl B)\n:=\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire d'une intersection\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.exercice_ensembles_3\n(A B : set X) :\nA \u2229 B = A \u222a B \u2192 A = B\n:=\n/- dEAduction\nPrettyName\n    Quand l'intersection \u00e9gale l'union\n-/\nbegin\n    todo\nend\n\nlemma exercise.exercice_ensembles_4a\n(A B C : set X) :\nA \u2229 B = A \u2229 C \u2227 (set.compl A) \u2229 B = (set.compl A) \u2229 C \u2192 B \u2286 C\n:=\n/- dEAduction\nPrettyName\n    Caract\u00e9risation par intersection avec A et son compl\u00e9mentaire, I\n-/\nbegin\n    todo\nend\n\nlemma exercise.exercice_ensembles_4b\n(A B C : set X) :\nA \u2229 B = A \u2229 C \u2227 (set.compl A) \u2229 B = (set.compl A) \u2229 C \u2192 B = C\n:=\n/- dEAduction\nPrettyName\n    Caract\u00e9risaton par intersection avec A et son compl\u00e9mentaire, II\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.exercice_ensembles_5\n(A B C : set X) :\nA \u2229 B = A \u2229 C \u2227 A \u222a B = A \u222a C \u2192 B = C\n:=\n/- dEAduction\nPrettyName\n    M\u00eame union et m\u00eame intersection\n-/\nbegin\n    todo\nend\n\n--def diff {X : Type} (A B : set X) := {x \u2208 A | \u00ac x \u2208 B}\n--notation A `\\\\` B := diff A B\n\n-- def symmetric_difference {X : Type} (A B : set X) := (A \u222a B) \\ (A \u2229 B)\n-- notation A `\u0394` B := symmetric_difference A B\n\nnamespace difference_et_difference_symetrique\n/- dEAduction\nPrettyName\n    Diff\u00e9rence et diff\u00e9rence sym\u00e9trique\n-/\n\nnamespace definitions\n/- dEAduction\nPrettyName\n    D\u00e9finitions\n-/\n\n\nlemma definition.difference\n(A B : set X) (x : X) :\nx \u2208 (A \\ B) \u2194 x \u2208 A \u2227 x \u2209 B\n:=\n/- dEAduction\nPrettyName\n    Diff\u00e9rence de deux ensembles\n-/\nbegin\n    refl,\nend\n\n\nlemma definition.difference_symetrique\n(A B : set X) :\n(A \u0394 B) =  (A \u222a B) \\ (A \u2229 B)\n:=\n/- dEAduction\nPrettyName\n    Diff\u00e9rence sym\u00e9trique de deux ensembles\n-/\nbegin\n    refl,\nend\n\nend definitions\n\n\nnamespace exercices\n/- dEAduction\nPrettyName\n    Exercices\n-/\n\nlemma exercise.difference_symetrique_1\n(A B : set X) :\n(A \u0394 B) = (A \\ B) \u222a (B \\ A)\n:=\n/- dEAduction\nPrettyName\n    Diff\u00e9rence sym\u00e9trique I\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_2\n(A B : set X) :\n(A \u0394 B) = (B \u0394 A)\n:=\n/- dEAduction\nPrettyName\n    (*) Diff\u00e9rence sym\u00e9trique II\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_3\n(A B C : set X) :\n((A \u0394 B) \u0394 C) = (A \u0394 (B \u0394 C))\n:=\n/- dEAduction\nPrettyName\n    (**) Diff\u00e9rence sym\u00e9trique III\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_4 :\n\u2203! (\u03bbE : set X, \u2200 A : set X, (A \u0394 E) = A) :=\n/- dEAduction\nPrettyName\n    (+) Diff\u00e9rence sym\u00e9trique VI\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_5 (A : set X) :\nexists_unique (\u03bbA' : set X, (A \u0394 A') = set.univ)\n:=\n/- dEAduction\nPrettyName\n    (+) Diff\u00e9rence sym\u00e9trique V\n-/\nbegin\n    todo\n    -- use complement A, \n    -- norm_num,\nend\n\nlemma exercise.difference_symetrique_6\n(A B : set X) :\n(A \u0394 B) = \u2205 \u2194 A = B\n:=\n/- dEAduction\nPrettyName\n    (+) Diff\u00e9rence sym\u00e9trique VI\n-/\nbegin\n    todo\nend\n\nend exercices\n\nend difference_et_difference_symetrique\n\n-- applications\nvariable (f: X \u2192 Y)\n\nnamespace applications\n\nlemma exercise.exercice_applications_1\n(A B : set X) :\nA \u2286 B \u2192 f '' A \u2286 f '' B\n:=\n/- dEAduction\nPrettyName\n    Image directe et inclusion\n-/\nbegin\n    todo\nend\n\nlemma exercise.exercice_applications_2\n(A B : set X) :\nf '' (A \u222a B)  = f '' A \u222a f '' B\n:=\n/- dEAduction\nPrettyName\n    Image d'une union\n-/\nbegin\n    todo\nend\n\nopen applications_II.definitions\nlemma exercise.exercice_factorisation_I\n(g : Y \u2192 Z) (h: X \u2192 Z) :\n(\u2203 f: X \u2192 Y, h = (composition g f)) \u2194 h '' set.univ \u2286 g '' set.univ\n:=\n/- dEAduction\nPrettyName\n    (+) Factorisation I\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.exercice_factorisation_II\n(f : X \u2192 Y) (h: X \u2192 Z) :\n(\u2203 g: Y \u2192 Z, h = (composition g f)) \u2194 (\u2200 x y, (f x = f y \u2192 h x = h y))\n:=\n/- dEAduction\nPrettyName\n    (+) Factorisation II\n-/\nbegin\n    todo\nend\n\n\n-- TODO: ajouter exoset ficall.pdf exos (140 bijections) 141 142 146\n\nlemma exercise.injectivite_surjecivite_1 (f: X \u2192 Y) (g: Y \u2192 Z)\n(H1 : injective (composition g f)) (H2 : surjective f)\n:\ninjective g\n:=\n/- dEAduction\nPrettyName\n    Injectivit\u00e9 et surjectivit\u00e9 I\n-/\nbegin\n    todo\nend\n\nlemma exercise.injectivite_surjecivite_2 (f: X \u2192 Y) (g: Y \u2192 Z)\n(H1 : surjective (composition g f)) (H2 : injective g)\n:\nsurjective f\n:=\n/- dEAduction\nPrettyName\n    Injectivit\u00e9 et surjectivit\u00e9 II\n-/\nbegin\n    todo\nend\n\n\n\nlemma exercise.injectivite_categorielle\n(f: Y \u2192 Z):\n(injective f) \u2192 (\u2200X: Type, \u2200 g h : X \u2192 Y, (composition f g) = (composition f h) \u2192 g = h)\n:=\n/- dEAduction\nPrettyName\n    Injectivit\u00e9 cat\u00e9gorielle\n-/\nbegin\n    todo\nend\n\nlemma exercise.surjectivite_categorielle\n(f: X \u2192 Y):\n(surjective f) \u2192  (\u2200Z: Type, \u2200 g h : Y \u2192 Z, (composition g f ) = (composition h f ) \u2192 g = h)\n:=\n/- dEAduction\nPrettyName\n    Surjectivit\u00e9 cat\u00e9gorielle\n-/\nbegin\n    todo\nend\n\nend applications\n\n\nend exercices_supplementaires\n\nend theorie_des_ensembles\n\nend course", "meta": {"author": "dEAduction", "repo": "dEAduction-lean", "sha": "4fe1d642078fc94f9081ccbed08e047e86a741fd", "save_path": "github-repos/lean/dEAduction-dEAduction-lean", "path": "github-repos/lean/dEAduction-dEAduction-lean/dEAduction-lean-4fe1d642078fc94f9081ccbed08e047e86a741fd/src/exercises_deaduction_synchro/experimental/exercices_theorie_des_ensembles.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7358914606100649}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport number_theory.zsqrtd.basic\nimport data.complex.basic\nimport ring_theory.principal_ideal_domain\nimport number_theory.quadratic_reciprocity\n/-!\n# Gaussian integers\n\nThe Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both\nintegers.\n\n## Main definitions\n\nThe Euclidean domain structure on `\u2124[i]` is defined in this file.\n\nThe homomorphism `to_complex` into the complex numbers is also defined in this file.\n\n## Main statements\n\n`prime_iff_mod_four_eq_three_of_nat_prime`\nA prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4`\n\n## Notations\n\nThis file uses the local notation `\u2124[i]` for `gaussian_int`\n\n## Implementation notes\n\nGaussian integers are implemented using the more general definition `zsqrtd`, the type of integers\nadjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties\nand definitions about `zsqrtd` can easily be used.\n-/\n\nopen zsqrtd complex\n\n@[reducible] def gaussian_int : Type := zsqrtd (-1)\n\nlocal notation `\u2124[i]` := gaussian_int\n\nnamespace gaussian_int\n\ninstance : has_repr \u2124[i] := \u27e8\u03bb x, \"\u27e8\" ++ repr x.re ++ \", \" ++ repr x.im ++ \"\u27e9\"\u27e9\n\ninstance : comm_ring \u2124[i] := zsqrtd.comm_ring\n\nsection\nlocal attribute [-instance] complex.field -- Avoid making things noncomputable unnecessarily.\n\n/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/\ndef to_complex : \u2124[i] \u2192+* \u2102 :=\nzsqrtd.lift \u27e8I, by simp\u27e9\nend\n\ninstance : has_coe (\u2124[i]) \u2102 := \u27e8to_complex\u27e9\n\nlemma to_complex_def (x : \u2124[i]) : (x : \u2102) = x.re + x.im * I := rfl\n\nlemma to_complex_def' (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102) = x + y * I := by simp [to_complex_def]\n\nlemma to_complex_def\u2082 (x : \u2124[i]) : (x : \u2102) = \u27e8x.re, x.im\u27e9 :=\nby apply complex.ext; simp [to_complex_def]\n\n@[simp] lemma to_real_re (x : \u2124[i]) : ((x.re : \u2124) : \u211d) = (x : \u2102).re := by simp [to_complex_def]\n@[simp] lemma to_real_im (x : \u2124[i]) : ((x.im : \u2124) : \u211d) = (x : \u2102).im := by simp [to_complex_def]\n@[simp] lemma to_complex_re (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).re = x := by simp [to_complex_def]\n@[simp] lemma to_complex_im (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).im = y := by simp [to_complex_def]\n@[simp] lemma to_complex_add (x y : \u2124[i]) : ((x + y : \u2124[i]) : \u2102) = x + y := to_complex.map_add _ _\n@[simp] lemma to_complex_mul (x y : \u2124[i]) : ((x * y : \u2124[i]) : \u2102) = x * y := to_complex.map_mul _ _\n@[simp] lemma to_complex_one : ((1 : \u2124[i]) : \u2102) = 1 := to_complex.map_one\n@[simp] lemma to_complex_zero : ((0 : \u2124[i]) : \u2102) = 0 := to_complex.map_zero\n@[simp] lemma to_complex_neg (x : \u2124[i]) : ((-x : \u2124[i]) : \u2102) = -x := to_complex.map_neg _\n@[simp] lemma to_complex_sub (x y : \u2124[i]) : ((x - y : \u2124[i]) : \u2102) = x - y := to_complex.map_sub _ _\n\n@[simp] lemma to_complex_inj {x y : \u2124[i]} : (x : \u2102) = y \u2194 x = y :=\nby cases x; cases y; simp [to_complex_def\u2082]\n\n@[simp] lemma to_complex_eq_zero {x : \u2124[i]} : (x : \u2102) = 0 \u2194 x = 0 :=\nby rw [\u2190 to_complex_zero, to_complex_inj]\n\n@[simp] lemma nat_cast_real_norm (x : \u2124[i]) : (x.norm : \u211d) = (x : \u2102).norm_sq :=\nby rw [norm, norm_sq]; simp\n\n@[simp] lemma nat_cast_complex_norm (x : \u2124[i]) : (x.norm : \u2102) = (x : \u2102).norm_sq :=\nby cases x; rw [norm, norm_sq]; simp\n\nlemma norm_nonneg (x : \u2124[i]) : 0 \u2264 norm x := norm_nonneg (by norm_num) _\n\n@[simp] lemma norm_eq_zero {x : \u2124[i]} : norm x = 0 \u2194 x = 0 :=\nby rw [\u2190 @int.cast_inj \u211d _ _ _]; simp\n\nlemma norm_pos {x : \u2124[i]} : 0 < norm x \u2194 x \u2260 0 :=\nby rw [lt_iff_le_and_ne, ne.def, eq_comm, norm_eq_zero]; simp [norm_nonneg]\n\n@[simp] lemma coe_nat_abs_norm (x : \u2124[i]) : (x.norm.nat_abs : \u2124) = x.norm :=\nint.nat_abs_of_nonneg (norm_nonneg _)\n\n@[simp] lemma nat_cast_nat_abs_norm {\u03b1 : Type*} [ring \u03b1]\n  (x : \u2124[i]) : (x.norm.nat_abs : \u03b1) = x.norm :=\nby rw [\u2190 int.cast_coe_nat, coe_nat_abs_norm]\n\nlemma nat_abs_norm_eq (x : \u2124[i]) : x.norm.nat_abs =\n  x.re.nat_abs * x.re.nat_abs + x.im.nat_abs * x.im.nat_abs :=\nint.coe_nat_inj $ begin simp, simp [norm] end\n\nprotected def div (x y : \u2124[i]) : \u2124[i] :=\nlet n := (rat.of_int (norm y))\u207b\u00b9 in let c := y.conj in\n\u27e8round (rat.of_int (x * c).re * n : \u211a),\n round (rat.of_int (x * c).im * n : \u211a)\u27e9\n\ninstance : has_div \u2124[i] := \u27e8gaussian_int.div\u27e9\n\nlemma div_def (x y : \u2124[i]) : x / y = \u27e8round ((x * conj y).re / norm y : \u211a),\n  round ((x * conj y).im / norm y : \u211a)\u27e9 :=\nshow zsqrtd.mk _ _ = _, by simp [rat.of_int_eq_mk, rat.mk_eq_div, div_eq_mul_inv]\n\nlemma to_complex_div_re (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).re = round ((x / y : \u2102).re) :=\nby rw [div_def, \u2190 @rat.round_cast \u211d _ _];\n  simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlemma to_complex_div_im (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).im = round ((x / y : \u2102).im) :=\nby rw [div_def, \u2190 @rat.round_cast \u211d _ _, \u2190 @rat.round_cast \u211d _ _];\n  simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlemma norm_sq_le_norm_sq_of_re_le_of_im_le {x y : \u2102} (hre : |x.re| \u2264 |y.re|)\n  (him : |x.im| \u2264 |y.im|) : x.norm_sq \u2264 y.norm_sq :=\nby rw [norm_sq_apply, norm_sq_apply, \u2190 _root_.abs_mul_self, _root_.abs_mul,\n  \u2190 _root_.abs_mul_self y.re, _root_.abs_mul y.re,\n  \u2190 _root_.abs_mul_self x.im, _root_.abs_mul x.im,\n  \u2190 _root_.abs_mul_self y.im, _root_.abs_mul y.im]; exact\n(add_le_add (mul_self_le_mul_self (abs_nonneg _) hre)\n  (mul_self_le_mul_self (abs_nonneg _) him))\n\nlemma norm_sq_div_sub_div_lt_one (x y : \u2124[i]) :\n  ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq < 1 :=\ncalc ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq =\n    ((x / y : \u2102).re - ((x / y : \u2124[i]) : \u2102).re +\n    ((x / y : \u2102).im - ((x / y : \u2124[i]) : \u2102).im) * I : \u2102).norm_sq :\n      congr_arg _ $ by apply complex.ext; simp\n  ... \u2264 (1 / 2 + 1 / 2 * I).norm_sq :\n  have |(2\u207b\u00b9 : \u211d)| = 2\u207b\u00b9, from _root_.abs_of_nonneg (by norm_num),\n  norm_sq_le_norm_sq_of_re_le_of_im_le\n    (by rw [to_complex_div_re]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).re)\n    (by rw [to_complex_div_im]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).im)\n  ... < 1 : by simp [norm_sq]; norm_num\n\nprotected def mod (x y : \u2124[i]) : \u2124[i] := x - y * (x / y)\n\ninstance : has_mod \u2124[i] := \u27e8gaussian_int.mod\u27e9\n\nlemma mod_def (x y : \u2124[i]) : x % y = x - y * (x / y) := rfl\n\nlemma norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) : (x % y).norm < y.norm :=\nhave (y : \u2102) \u2260 0, by rwa [ne.def, \u2190 to_complex_zero, to_complex_inj],\n(@int.cast_lt \u211d _ _ _ _).1 $\n  calc \u2191(norm (x % y)) = (x - y * (x / y : \u2124[i]) : \u2102).norm_sq : by simp [mod_def]\n  ... = (y : \u2102).norm_sq * (((x / y) - (x / y : \u2124[i])) : \u2102).norm_sq :\n    by rw [\u2190 norm_sq_mul, mul_sub, mul_div_cancel' _ this]\n  ... < (y : \u2102).norm_sq * 1 : mul_lt_mul_of_pos_left (norm_sq_div_sub_div_lt_one _ _)\n    (norm_sq_pos.2 this)\n  ... = norm y : by simp\n\nlemma nat_abs_norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (x % y).norm.nat_abs < y.norm.nat_abs :=\nint.coe_nat_lt.1 (by simp [-int.coe_nat_lt, norm_mod_lt x hy])\n\nlemma norm_le_norm_mul_left (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (norm x).nat_abs \u2264 (norm (x * y)).nat_abs :=\nby rw [norm_mul, int.nat_abs_mul];\n  exact le_mul_of_one_le_right (nat.zero_le _)\n    (int.coe_nat_le.1 (by rw [coe_nat_abs_norm]; exact int.add_one_le_of_lt (norm_pos.2 hy)))\n\ninstance : nontrivial \u2124[i] :=\n\u27e8\u27e80, 1, dec_trivial\u27e9\u27e9\n\ninstance : euclidean_domain \u2124[i] :=\n{ quotient := (/),\n  remainder := (%),\n  quotient_zero := by { simp [div_def], refl },\n  quotient_mul_add_remainder_eq := \u03bb _ _, by simp [mod_def],\n  r := _,\n  r_well_founded := measure_wf (int.nat_abs \u2218 norm),\n  remainder_lt := nat_abs_norm_mod_lt,\n  mul_left_not_lt := \u03bb a b hb0, not_lt_of_ge $ norm_le_norm_mul_left a hb0,\n  .. gaussian_int.comm_ring,\n  .. gaussian_int.nontrivial }\n\nopen principal_ideal_ring\n\nlemma mod_four_eq_three_of_nat_prime_of_prime (p : \u2115) [hp : fact p.prime] (hpi : prime (p : \u2124[i])) :\n  p % 4 = 3 :=\nhp.1.eq_two_or_odd.elim\n  (\u03bb hp2, absurd hpi (mt irreducible_iff_prime.2 $\n    \u03bb \u27e8hu, h\u27e9, begin\n      have := h \u27e81, 1\u27e9 \u27e81, -1\u27e9 (hp2.symm \u25b8 rfl),\n      rw [\u2190 norm_eq_one_iff, \u2190 norm_eq_one_iff] at this,\n      exact absurd this dec_trivial\n    end))\n  (\u03bb hp1, by_contradiction $ \u03bb hp3 : p % 4 \u2260 3,\n    have hp41 : p % 4 = 1,\n      begin\n        rw [\u2190 nat.mod_mul_left_mod p 2 2, show 2 * 2 = 4, from rfl] at hp1,\n        have := nat.mod_lt p (show 0 < 4, from dec_trivial),\n        revert this hp3 hp1,\n        generalize : p % 4 = m, dec_trivial!,\n      end,\n    let \u27e8k, hk\u27e9 := (zmod.exists_sq_eq_neg_one_iff_mod_four_ne_three p).2 $\n      by rw hp41; exact dec_trivial in\n    begin\n      obtain \u27e8k, k_lt_p, rfl\u27e9 : \u2203 (k' : \u2115) (h : k' < p), (k' : zmod p) = k,\n      { refine \u27e8k.val, k.val_lt, zmod.nat_cast_zmod_val k\u27e9 },\n      have hpk : p \u2223 k ^ 2 + 1,\n        by rw [\u2190 char_p.cast_eq_zero_iff (zmod p) p]; simp *,\n      have hkmul : (k ^ 2 + 1 : \u2124[i]) = \u27e8k, 1\u27e9 * \u27e8k, -1\u27e9 :=\n        by simp [sq, zsqrtd.ext],\n      have hpne1 : p \u2260 1 := ne_of_gt hp.1.one_lt,\n      have hkltp : 1 + k * k < p * p,\n        from calc 1 + k * k \u2264 k + k * k :\n          add_le_add_right (nat.pos_of_ne_zero\n            (\u03bb hk0, by clear_aux_decl; simp [*, pow_succ'] at *)) _\n        ... = k * (k + 1) : by simp [add_comm, mul_add]\n        ... < p * p : mul_lt_mul k_lt_p k_lt_p (nat.succ_pos _) (nat.zero_le _),\n      have hpk\u2081 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, -1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (norm \u27e8k, -1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (-1 : \u2124) \u2260 0, from dec_trivial) $\n              by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpk\u2082 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, 1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (norm \u27e8k, 1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (1 : \u2124) \u2260 0, from dec_trivial) $\n                by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2\n        (by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n        exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1),\n      obtain \u27e8y, hy\u27e9 := hpk,\n      have := hpi.2.2 \u27e8k, 1\u27e9 \u27e8k, -1\u27e9 \u27e8y, by rw [\u2190 hkmul, \u2190 nat.cast_mul p, \u2190 hy]; simp\u27e9,\n      clear_aux_decl, tauto\n    end)\n\nlemma sq_add_sq_of_nat_prime_of_not_irreducible (p : \u2115) [hp : fact p.prime]\n  (hpi : \u00acirreducible (p : \u2124[i])) : \u2203 a b, a^2 + b^2 = p :=\nhave hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2 $\n  by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n    exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1,\nhave hab : \u2203 a b, (p : \u2124[i]) = a * b \u2227 \u00ac is_unit a \u2227 \u00ac is_unit b,\n  by simpa [irreducible_iff, hpu, not_forall, not_or_distrib] using hpi,\nlet \u27e8a, b, hpab, hau, hbu\u27e9 := hab in\nhave hnap : (norm a).nat_abs = p, from ((hp.1.mul_eq_prime_sq_iff\n    (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 $\n  by rw [\u2190 int.coe_nat_inj', int.coe_nat_pow, sq,\n    \u2190 @norm_nat_cast (-1), hpab];\n    simp).1,\n\u27e8a.re.nat_abs, a.im.nat_abs, by simpa [nat_abs_norm_eq, sq] using hnap\u27e9\n\nlemma prime_of_nat_prime_of_mod_four_eq_three (p : \u2115) [hp : fact p.prime] (hp3 : p % 4 = 3) :\n  prime (p : \u2124[i]) :=\nirreducible_iff_prime.1 $ classical.by_contradiction $ \u03bb hpi,\n  let \u27e8a, b, hab\u27e9 := sq_add_sq_of_nat_prime_of_not_irreducible p hpi in\nhave \u2200 a b : zmod 4, a^2 + b^2 \u2260 p, by erw [\u2190 zmod.nat_cast_mod 4 p, hp3]; exact dec_trivial,\nthis a b (hab \u25b8 by simp)\n\n/-- A prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4` -/\nlemma prime_iff_mod_four_eq_three_of_nat_prime (p : \u2115) [hp : fact p.prime] :\n  prime (p : \u2124[i]) \u2194 p % 4 = 3 :=\n\u27e8mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p\u27e9\n\nend gaussian_int\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/zsqrtd/gaussian_int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.735891458806037}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.star.basic\nimport analysis.normed_space.operator_norm\n\n/-! # The left-regular representation is an isometry for C\u22c6-algebras -/\n\nopen continuous_linear_map\n\nlocal postfix `\u22c6`:std.prec.max_plus := star\n\nvariables (\ud835\udd5c : Type*) {E : Type*}\nvariables [densely_normed_field \ud835\udd5c] [non_unital_normed_ring E] [star_ring E] [cstar_ring E]\nvariables [normed_space \ud835\udd5c E] [is_scalar_tower \ud835\udd5c E E] [smul_comm_class \ud835\udd5c E E] (a : E)\n\n/-- In a C\u22c6-algebra `E`, either unital or non-unital, multiplication on the left by `a : E` has\nnorm equal to the norm of `a`. -/\n@[simp] lemma op_nnnorm_mul : \u2016mul \ud835\udd5c E a\u2016\u208a = \u2016a\u2016\u208a :=\nbegin\n  rw \u2190Sup_closed_unit_ball_eq_nnnorm,\n  refine cSup_eq_of_forall_le_of_forall_lt_exists_gt _ _ (\u03bb r hr, _),\n  { exact (metric.nonempty_closed_ball.mpr zero_le_one).image _ },\n  { rintro - \u27e8x, hx, rfl\u27e9,\n    exact ((mul \ud835\udd5c E a).unit_le_op_norm x $ mem_closed_ball_zero_iff.mp hx).trans\n      (op_norm_mul_apply_le \ud835\udd5c E a) },\n  { have ha : 0 < \u2016a\u2016\u208a := zero_le'.trans_lt hr,\n    rw [\u2190inv_inv (\u2016a\u2016\u208a), nnreal.lt_inv_iff_mul_lt (inv_ne_zero ha.ne')] at hr,\n    obtain \u27e8k, hk\u2081, hk\u2082\u27e9 := normed_field.exists_lt_nnnorm_lt \ud835\udd5c (mul_lt_mul_of_pos_right hr $\n      inv_pos.2 ha),\n    refine \u27e8_, \u27e8k \u2022 star a, _, rfl\u27e9, _\u27e9,\n    { simpa only [mem_closed_ball_zero_iff, norm_smul, one_mul, norm_star] using\n        (nnreal.le_inv_iff_mul_le ha.ne').1 (one_mul \u2016a\u2016\u208a\u207b\u00b9 \u25b8 hk\u2082.le : \u2016k\u2016\u208a \u2264 \u2016a\u2016\u208a\u207b\u00b9) },\n    { simp only [map_smul, nnnorm_smul, mul_apply', mul_smul_comm, cstar_ring.nnnorm_self_mul_star],\n      rwa [\u2190nnreal.div_lt_iff (mul_pos ha ha).ne', div_eq_mul_inv, mul_inv, \u2190mul_assoc] } },\nend\n\n/-- In a C\u22c6-algebra `E`, either unital or non-unital, multiplication on the right by `a : E` has\nnorm eqaul to the norm of `a`. -/\n@[simp] lemma op_nnnorm_mul_flip : \u2016(mul \ud835\udd5c E).flip a\u2016\u208a = \u2016a\u2016\u208a :=\nbegin\n  rw [\u2190Sup_unit_ball_eq_nnnorm, \u2190nnnorm_star, \u2190@op_nnnorm_mul \ud835\udd5c E, \u2190Sup_unit_ball_eq_nnnorm],\n  congr' 1,\n  simp only [mul_apply', flip_apply],\n  refine set.subset.antisymm _ _;\n  rintro - \u27e8b, hb, rfl\u27e9;\n  refine \u27e8star b, by simpa only [norm_star, mem_ball_zero_iff] using hb, _\u27e9,\n  { simp only [\u2190star_mul, nnnorm_star] },\n  { simpa using (nnnorm_star (star b * a)).symm }\nend\n\nvariables (E)\n\n/-- In a C\u22c6-algebra `E`, either unital or non-unital, the left regular representation is an\nisometry. -/\nlemma mul_isometry : isometry (mul \ud835\udd5c E) :=\nadd_monoid_hom_class.isometry_of_norm _ (\u03bb a, congr_arg coe $ op_nnnorm_mul \ud835\udd5c a)\n\n/-- In a C\u22c6-algebra `E`, either unital or non-unital, the right regular anti-representation is an\nisometry. -/\nlemma mul_flip_isometry : isometry (mul \ud835\udd5c E).flip :=\nadd_monoid_hom_class.isometry_of_norm _ (\u03bb a, congr_arg coe $ op_nnnorm_mul_flip \ud835\udd5c a)\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/star/mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7358914519570052}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\nimport data.set.basic\nimport order.lattice\nimport order.max\n\n/-!\n# Directed indexed families and sets\n\nThis file defines directed indexed families and directed sets. An indexed family/set is\ndirected iff each pair of elements has a shared upper bound.\n\n## Main declarations\n\n* `directed r f`: Predicate stating that the indexed family `f` is `r`-directed.\n* `directed_on r s`: Predicate stating that the set `s` is `r`-directed.\n* `is_directed \u03b1 r`: Prop-valued mixin stating that `\u03b1` is `r`-directed. Follows the style of the\n  unbundled relation classes such as `is_total`.\n-/\n\nopen function\n\nuniverses u v w\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b9 : Sort w} (r s : \u03b1 \u2192 \u03b1 \u2192 Prop)\nlocal infix ` \u227c ` : 50 := r\n\n/-- A family of elements of \u03b1 is directed (with respect to a relation `\u227c` on \u03b1)\n  if there is a member of the family `\u227c`-above any pair in the family.  -/\ndef directed (f : \u03b9 \u2192 \u03b1) := \u2200 x y, \u2203 z, f x \u227c f z \u2227 f y \u227c f z\n\n/-- A subset of \u03b1 is directed if there is an element of the set `\u227c`-above any\n  pair of elements in the set. -/\ndef directed_on (s : set \u03b1) := \u2200 (x \u2208 s) (y \u2208 s), \u2203 z \u2208 s, x \u227c z \u2227 y \u227c z\n\nvariables {r}\n\ntheorem directed_on_iff_directed {s} : @directed_on \u03b1 r s \u2194 directed r (coe : s \u2192 \u03b1) :=\nby simp [directed, directed_on]; refine ball_congr (\u03bb x hx, by simp; refl)\n\nalias directed_on_iff_directed \u2194 directed_on.directed_coe _\n\ntheorem directed_on_image {s} {f : \u03b2 \u2192 \u03b1} :\n  directed_on r (f '' s) \u2194 directed_on (f \u207b\u00b9'o r) s :=\nby simp only [directed_on, set.ball_image_iff, set.bex_image_iff, order.preimage]\n\ntheorem directed_on.mono {s : set \u03b1} (h : directed_on r s)\n  {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (H : \u2200 {a b}, r a b \u2192 r' a b) :\n  directed_on r' s :=\n\u03bb x hx y hy, let \u27e8z, zs, xz, yz\u27e9 := h x hx y hy in \u27e8z, zs, H xz, H yz\u27e9\n\ntheorem directed_comp {\u03b9} {f : \u03b9 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1} :\n  directed r (g \u2218 f) \u2194 directed (g \u207b\u00b9'o r) f := iff.rfl\n\ntheorem directed.mono {s : \u03b1 \u2192 \u03b1 \u2192 Prop} {\u03b9} {f : \u03b9 \u2192 \u03b1}\n  (H : \u2200 a b, r a b \u2192 s a b) (h : directed r f) : directed s f :=\n\u03bb a b, let \u27e8c, h\u2081, h\u2082\u27e9 := h a b in \u27e8c, H _ _ h\u2081, H _ _ h\u2082\u27e9\n\ntheorem directed.mono_comp {\u03b9} {rb : \u03b2 \u2192 \u03b2 \u2192 Prop} {g : \u03b1 \u2192 \u03b2} {f : \u03b9 \u2192 \u03b1}\n  (hg : \u2200 \u2983x y\u2984, x \u227c y \u2192 rb (g x) (g y)) (hf : directed r f) :\n  directed rb (g \u2218 f) :=\ndirected_comp.2 $ hf.mono hg\n\n/-- A monotone function on a sup-semilattice is directed. -/\nlemma directed_of_sup [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} {r : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  (H : \u2200 \u2983i j\u2984, i \u2264 j \u2192 r (f i) (f j)) : directed r f :=\n\u03bb a b, \u27e8a \u2294 b, H le_sup_left, H le_sup_right\u27e9\n\nlemma monotone.directed_le [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  monotone f \u2192 directed (\u2264) f :=\ndirected_of_sup\n\nlemma directed.extend_bot [preorder \u03b1] [order_bot \u03b1] {e : \u03b9 \u2192 \u03b2} {f : \u03b9 \u2192 \u03b1}\n  (hf : directed (\u2264) f) (he : function.injective e) :\n  directed (\u2264) (function.extend e f \u22a5) :=\nbegin\n  intros a b,\n  rcases (em (\u2203 i, e i = a)).symm with ha | \u27e8i, rfl\u27e9,\n  { use b, simp [function.extend_apply' _ _ _ ha] },\n  rcases (em (\u2203 i, e i = b)).symm with hb | \u27e8j, rfl\u27e9,\n  { use e i, simp [function.extend_apply' _ _ _ hb] },\n  rcases hf i j with \u27e8k, hi, hj\u27e9,\n  use (e k),\n  simp only [function.extend_apply he, *, true_and]\nend\n\n/-- An antitone function on an inf-semilattice is directed. -/\nlemma directed_of_inf [semilattice_inf \u03b1] {r : \u03b2 \u2192 \u03b2 \u2192 Prop} {f : \u03b1 \u2192 \u03b2}\n  (hf : \u2200 a\u2081 a\u2082, a\u2081 \u2264 a\u2082 \u2192 r (f a\u2082) (f a\u2081)) : directed r f :=\n\u03bb x y, \u27e8x \u2293 y, hf _ _ inf_le_left, hf _ _ inf_le_right\u27e9\n\n/-- `is_directed \u03b1 r` states that for any elements `a`, `b` there exists an element `c` such that\n`r a c` and `r b c`. -/\nclass is_directed (\u03b1 : Type*) (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop :=\n(directed (a b : \u03b1) : \u2203 c, r a c \u2227 r b c)\n\nlemma directed_of (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_directed \u03b1 r] (a b : \u03b1) : \u2203 c, r a c \u2227 r b c :=\nis_directed.directed _ _\n\nlemma directed_id [is_directed \u03b1 r] : directed r id := by convert directed_of r\nlemma directed_id_iff : directed r id \u2194 is_directed \u03b1 r := \u27e8\u03bb h, \u27e8h\u27e9, @directed_id _ _\u27e9\n\nlemma directed_on_univ [is_directed \u03b1 r] : directed_on r set.univ :=\n\u03bb a _ b _, let \u27e8c, hc\u27e9 := directed_of r a b in \u27e8c, trivial, hc\u27e9\n\nlemma directed_on_univ_iff : directed_on r set.univ \u2194 is_directed \u03b1 r :=\n\u27e8\u03bb h, \u27e8\u03bb a b, let \u27e8c, _, hc\u27e9 := h a trivial b trivial in \u27e8c, hc\u27e9\u27e9, @directed_on_univ _ _\u27e9\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance is_total.to_is_directed [is_total \u03b1 r] : is_directed \u03b1 r :=\n\u27e8\u03bb a b, or.cases_on (total_of r a b) (\u03bb h, \u27e8b, h, refl _\u27e9) (\u03bb h, \u27e8a, refl _, h\u27e9)\u27e9\n\nlemma is_directed_mono [is_directed \u03b1 r] (h : \u2200 \u2983a b\u2984, r a b \u2192 s a b) : is_directed \u03b1 s :=\n\u27e8\u03bb a b, let \u27e8c, ha, hb\u27e9 := is_directed.directed a b in \u27e8c, h ha, h hb\u27e9\u27e9\n\nlemma exists_ge_ge [has_le \u03b1] [is_directed \u03b1 (\u2264)] (a b : \u03b1) : \u2203 c, a \u2264 c \u2227 b \u2264 c :=\ndirected_of (\u2264) a b\n\nlemma exists_le_le [has_le \u03b1] [is_directed \u03b1 (swap (\u2264))] (a b : \u03b1) : \u2203 c, c \u2264 a \u2227 c \u2264 b :=\ndirected_of (swap (\u2264)) a b\n\ninstance order_dual.is_directed_ge [has_le \u03b1] [is_directed \u03b1 (\u2264)] :\n  is_directed (order_dual \u03b1) (swap (\u2264)) :=\nby assumption\n\ninstance order_dual.is_directed_le [has_le \u03b1] [is_directed \u03b1 (swap (\u2264))] :\n  is_directed (order_dual \u03b1) (\u2264) :=\nby assumption\n\nsection preorder\nvariables [preorder \u03b1] {a : \u03b1}\n\nprotected lemma is_min.is_bot [is_directed \u03b1 (swap (\u2264))] (h : is_min a) : is_bot a :=\n\u03bb b, let \u27e8c, hca, hcb\u27e9 := exists_le_le a b in (h hca).trans hcb\n\nprotected lemma is_max.is_top [is_directed \u03b1 (\u2264)] (h : is_max a) : is_top a :=\n\u03bb b, let \u27e8c, hac, hbc\u27e9 := exists_ge_ge a b in hbc.trans $ h hac\n\nlemma is_bot_iff_is_min [is_directed \u03b1 (swap (\u2264))] : is_bot a \u2194 is_min a :=\n\u27e8is_bot.is_min, is_min.is_bot\u27e9\n\nlemma is_top_iff_is_max [is_directed \u03b1 (\u2264)] : is_top a \u2194 is_max a := \u27e8is_top.is_max, is_max.is_top\u27e9\n\nend preorder\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance semilattice_sup.to_is_directed_le [semilattice_sup \u03b1] : is_directed \u03b1 (\u2264) :=\n\u27e8\u03bb a b, \u27e8a \u2294 b, le_sup_left, le_sup_right\u27e9\u27e9\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance semilattice_inf.to_is_directed_ge [semilattice_inf \u03b1] : is_directed \u03b1 (swap (\u2264)) :=\n\u27e8\u03bb a b, \u27e8a \u2293 b, inf_le_left, inf_le_right\u27e9\u27e9\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance order_top.to_is_directed_le [has_le \u03b1] [order_top \u03b1] : is_directed \u03b1 (\u2264) :=\n\u27e8\u03bb a b, \u27e8\u22a4, le_top, le_top\u27e9\u27e9\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance order_bot.to_is_directed_ge [has_le \u03b1] [order_bot \u03b1] : is_directed \u03b1 (swap (\u2264)) :=\n\u27e8\u03bb a b, \u27e8\u22a5, bot_le, bot_le\u27e9\u27e9\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/directed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7358914449244331}}
{"text": "import data.real.basic\nimport algebra.field.basic\nimport data.nat.parity\nimport algebra.big_operators.ring\n\nopen_locale big_operators\n\nopen division_ring\nopen finset\nopen nat\n\n-- supporting proofs\n\ntheorem alg_sup_proof_1 (n : \u2115) (h\u2080 : n > 1) :\n  (n-1)/2 < n :=\nbegin\n  rw nat.div_lt_iff_lt_mul,\n  {\n    induction n with n hn,\n    {linarith},\n    {rw succ_eq_add_one, simp, linarith}\n  },\n  {exact zero_lt_two}\nend\n\ntheorem alg_sup_proof_2 (n : \u2115) (h\u2080 : n > 1) :\n  n/2 < n :=\nbegin\n  rw nat.div_lt_iff_lt_mul,\n  {linarith},\n  {exact zero_lt_two}\nend\n\ntheorem alg_sup_proof_3 (n k : \u2115) :\n  2 * 2 ^ k * (n + 1) > 1 :=\nbegin\n  have hx : \u2203 x : \u2115, x = 2 ^ k, by use 2 ^ k,\n  cases hx with x hx,\n  have hx\u2082 : x > 0, by simp *,\n  have hy : \u2203 y : \u2115, y = n + 1, by use (n+1),\n  cases hy with y hy,\n  have hy\u2082 : y > 0, by simp *,\n  have hxy : \u2203 xy : \u2115, xy = x * y, by use x * y,\n  cases hxy with xy hxy,\n  have hxy\u2082 : xy > 0, by {rw hxy, exact mul_pos hx\u2082 hy\u2082},\n  rw [\u2190hx, \u2190hy, mul_assoc, \u2190hxy],\n  linarith\nend\n\n\ndef c : \u2115 \u2192 \u2124\n| n :=\n  if h\u2080 : n > 1 then\n    if h\u2081 : odd n then\n      have (n-1)/2 < n, by exact alg_sup_proof_1 n h\u2080,\n      (-1) ^ ((n-1)/2) * c ((n-1)/2)\n    else\n      have n/2 < n, by exact alg_sup_proof_2 n h\u2080,\n      c (n/2)\n  else\n    1\n\n-- lhs of core\n\ntheorem c_2n_eq_c_n (n : \u2115) :\n  c(2*n) = c(n) :=\nbegin\n  rw c,\n  cases n,\n  {simp, rw c, simp},\n  {\n    rw succ_eq_add_one,\n    have n_greater : 2 * (n + 1) > 1, by {\n      exact (cmp_eq_lt_iff 1 (2 * (n + 1))).mp rfl\n    },\n    have n_even : even (2 * (n + 1)), by {rw even, use n + 1},\n    simp *,\n  }\nend\n\ntheorem c_2n_add_2_eq_c_n_add_1 (n : \u2115) :\n  c(2*n+2) = c(n+1) :=\nbegin\n  have eq_ex : 2 * n + 2 = 2 * (n + 1), by linarith,\n  rw eq_ex,\n  exact c_2n_eq_c_n (n + 1)\nend\n\n-- rhs of core\n\ntheorem c_2n_add_1_eq_sign_c_n (n : \u2115) :\n  c(2*n+1) = (-1) ^ n * c(n) :=\nbegin\n  rw c,\n  cases n,\n  {simp, rw c, simp},\n  {\n    rw succ_eq_add_one,\n    have ex_greater : 2 * (n + 1) + 1 > 1, by linarith,\n    have ex_odd : odd (2*(n+1)+1), by {rw odd, use (n+1)},\n    simp *\n  }\nend\n\ntheorem c_2n_add_3_eq_sign_c_n_add_1 (n : \u2115) : \n  c(2*n+3) = (-1) ^ (n+1) * c(n+1) :=\nbegin\n  have eq_ex : 2 * n + 3 = 2 * (n + 1) + 1, by linarith,\n  rw eq_ex,\n  exact c_2n_add_1_eq_sign_c_n (n + 1)\nend\n\n-- main equality \ntheorem core_eq_putnam (n : \u2115) :\n  c(2*n) * c(2*n+2) = (-1) * c(2*n+1) * c(2*n+3) :=\nbegin\n  -- exploiting mini-proofs to simplify\n  rw c_2n_eq_c_n,\n  rw c_2n_add_2_eq_c_n_add_1,\n  rw c_2n_add_1_eq_sign_c_n,\n  rw c_2n_add_3_eq_sign_c_n_add_1,\n  -- deal with signs\n  -- get rid of (-1)^(2)\n  rw [\u2190mul_assoc, \u2190mul_assoc, \u2190pow_succ],\n  rw mul_assoc ((-1 : \u2124) ^ (n + 1)),\n  rw mul_comm (c(n)) ((-1)^(n+1)),\n  rw [\u2190mul_assoc, pow_succ, \u2190mul_assoc],\n  rw [mul_assoc (-1 : \u2124), mul_comm ((-1 : \u2124)^n)],\n  rw \u2190mul_assoc (-1 : \u2124) (-1) ((-1)^n),\n  rw [\u2190sq (-1 : \u2124), neg_one_sq, one_mul],\n  -- get rid of (-1)^n\n  rw [\u2190pow_add, \u2190two_mul, mul_comm 2 n],\n  rw [pow_mul', neg_one_sq, one_pow, one_mul]\nend\n\n\ntheorem putnam_2013_b1 : \n  \u2211 i in range 2014, c(i) * c(i+2) = 0 :=\nbegin\n  have eq : 2014 = 2 * 1007, by norm_num,\n  rw eq,\n  induction 1007,\n  {simp},\n  {\n    rw [succ_eq_add_one, mul_add, mul_one],\n    rw [sum_range_succ, sum_range_succ],\n    rw [ih, zero_add, core_eq_putnam],\n    linarith \n  }\nend", "meta": {"author": "Dmmc123", "repo": "lean_contest_tasks", "sha": "40f9912c22017c6c9799d9096fbba765bde76282", "save_path": "github-repos/lean/Dmmc123-lean_contest_tasks", "path": "github-repos/lean/Dmmc123-lean_contest_tasks/lean_contest_tasks-40f9912c22017c6c9799d9096fbba765bde76282/putnam_2013_b1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002789, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7358658159771778}}
{"text": "/-\nThis is a sorry-free file covering the material on Wednesday afternoon\nat LFTCM2020. It's how to build some algebraic structures in Lean\n-/\n\nimport data.rat.basic-- we'll need the rationals at the end of this file\n\n/-\nAs a mathematician I essentially always start my Lean files with the following line:\n-/\nimport tactic\n\n/- That gives me access to all Lean's tactics\n(see https://leanprover-community.github.io/mathlib_docs/tactics.html)\n-/\n\n/-\n## The point of this file\nThe idea of this file is to show how to build in Lean what the computer scientists call\n\"an algebraic heirarchy\", and what mathematicians call \"groups, rings, fields, modules etc\".\nFirstly, we will define groups, and develop a basic interface for groups.\nThen we will define rings, fields, modules, vector spaces, and just demonstrate\nthat they are usable, rather than making a complete interface for all of them.\nLet's start with the theory of groups. Unfortunately Lean has groups already,\nso we will have to do everything in a namespace\n-/\n\n\nnamespace lftcm\n\n/-\n... which means that now when we define `group`, it will actually be called `lftcm.group`.\n## Notation typeclasses\nTo make a term of type `has_mul G`, you need to give a map G^2 \u2192 G (or\nmore precisely, a map `has_mul.mul : G \u2192 G \u2192 G`. Lean's notation `g * h`\nis notation for `has_mul.mul g h`. Furthermore, `has_mul` is a class.\nIn short, this means that if you write `[has_mul G]` then `G` will\nmagically have a multiplication called `*` (satisfying no axioms).\nSimilarly `[has_one G]` gives you `has_one.one : G` with notation `1 : G`,\nand `[has_inv G]` gives you `has_inv.inv : G \u2192 G` with notation `g\u207b\u00b9 : G`\n## Definition of a group\nIf `G` is a type, equipped with `* : G^2 \u2192 G`, `1 : G` and `\u207b\u00b9 : G \u2192 G`\nthen it's a group if it satisfies the group axioms.\n-/\n\n-- `group G` is the type of group structures on a type `G`.\n-- first we ask for the structure\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n-- and then we ask for the axioms\n  (mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n  (one_mul : \u2200 (a : G), 1 * a = a)\n  (mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\n/-\nAdvantages of this approach: axioms look lovely.\nDisadvantage: what if I want the group law to be `+`?? I have embedded `has_mul`\nin the definition.\nLean's solution: develop a `to_additive` metaprogram which translates all theorems about\n`group`s (with group law `*`) to theorems about `add_group`s (with group law `+`). We will\nnot go into details here.\n-/\n\nnamespace group\n\n-- let G be a group\n\nvariables {G : Type} [group G]\n\n/-\nLemmas about groups are proved in this namespace. We already have some!\nAll the group axioms are theorems in this namespace. Indeed we have just defined\n`group.mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c)`\n`group.one_mul : \u2200 (a : G), 1 * a = a`\n`group.mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1`\nBecause we are in the `group` namespace, we don't need to write `group.`\neverywhere.\nLet's put some more theorems into the `group` namespace.\nWe definitely need `mul_one` and `mul_right_inv`, and it's a fun exercise to\nget them. Here is a route:\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n-/\n\nlemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c :=\n calc b = 1 * b         : by rw one_mul\n    ... = (a\u207b\u00b9 * a) * b : by rw mul_left_inv \n    ... = a\u207b\u00b9 * (a * b) : by rw mul_assoc\n    ... = a\u207b\u00b9 * (a * c) : by rw Habac\n    ... = (a\u207b\u00b9 * a) * c : by rw \u2190mul_assoc\n    ... = 1 * c         : by rw \u2190mul_left_inv\n    ... = c             : by rw one_mul \n\n-- more mathlib-ish proof:\nlemma mul_left_cancel' (a b c : G) (Habac : a * b = a * c) : b = c :=\nbegin\n  rw [\u2190one_mul b, \u2190mul_left_inv a, mul_assoc, Habac, \u2190mul_assoc, mul_left_inv, one_mul],\nend\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  -- \u22a2 a\u207b\u00b9 * (a * x) = a\u207b\u00b9 * y\n  rwa [\u2190mul_assoc, mul_left_inv, one_mul],\nend\n\n-- The same proof\nlemma mul_eq_of_eq_inv_mul' {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nmul_left_cancel a\u207b\u00b9 _ _ $ by rwa [\u2190mul_assoc, mul_left_inv, one_mul]\n\n/-\nSo now we can finally prove `mul_one` and `mul_right_inv`.\nBut before we start, let's learn a little bit about the simplifier.\n## The `simp` tactic -- Lean's simplifier\nWe have the theorems (axioms) `one_mul g : 1 * g = g` and\n`mul_left_inv g : g\u207b\u00b9 * g = 1`. Both of these theorems are of\nthe form `A = B`, with `A` more complicated than `B`. This means\nthat they are *perfect* theorems for the simplifier. Let's teach\nthose theorems to the simplifier, by adding the `@[simp]` attribute to them.\nAn \"attribute\" is just a tag which we attach to a theorem (or definition).\n-/\n\nattribute [simp] one_mul mul_left_inv\n\n/-\nNow let's prove `mul_one` using the simplifier. This also a perfect\n`simp` lemma, so let's also add the `simp` tag to it.\n-/\n\n@[simp] theorem mul_one (a : G) : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  -- \u22a2 1 = a\u207b\u00b9 * a\n  simp,\nend\n\n/-\nThe simplifier solved `1 = a\u207b\u00b9 * a` because it knew `mul_left_inv`.\nFeel free to comment out the `attribute [simp] one_mul mul_left_inv` line\nabove, and observe that the proof breaks.\n-/\n\n-- term mode proof\ntheorem mul_one' (a : G) : a * 1 = a :=\nmul_eq_of_eq_inv_mul $ by simp\n\n-- see if you can get the simplifier to do this one too\n@[simp] theorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1 :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rw [\u2190 mul_assoc, mul_left_inv, one_mul, mul_one],\nend\n\n-- Now here's a question. Can we train the simplifier to solve the following problem:\n\n-- example (a b c d : G) :\n--  ((a * b)\u207b\u00b9 * a * 1\u207b\u00b9\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * b * b * 1 * 1\u207b\u00b9)\u207b\u00b9 = (c\u207b\u00b9\u207b\u00b9 * d * d\u207b\u00b9 * 1\u207b\u00b9\u207b\u00b9 * c\u207b\u00b9\u207b\u00b9\u207b\u00b9)\u207b\u00b9\u207b\u00b9 :=\n-- by simp\n\n-- Remove the --'s and see that it fails. Let's see if we can get it to work.\n\n-- We start with two very natural `simp` lemmas.\n\n@[simp] lemma one_inv : (1 : G)\u207b\u00b9 = 1 :=\nbegin\n  apply mul_left_cancel (1 : G),\n  rw [mul_right_inv, mul_one],\nend\n\n@[simp] lemma inv_inv (a : G) : a\u207b\u00b9\u207b\u00b9 = a :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rw [mul_right_inv, mul_left_inv],\nend\n\n-- Here is a riskier looking `[simp]` lemma.\n\nattribute [simp] mul_assoc -- recall this says (a * b) * c = a * (b * c)\n\n-- The simplifier will now push all brackets to the right, which means\n-- that it's worth proving the following two lemmas and tagging\n-- them `[simp]`, so that we can still cancel a with a\u207b\u00b9 in these situations.\n\n@[simp] lemma inv_mul_cancel_left (a b : G) : a\u207b\u00b9 * (a * b) = b :=\nbegin\n  rw [\u2190 mul_assoc, mul_left_inv, one_mul],\nend\n\n@[simp] lemma mul_inv_cancel_left (a b : G) : a * (a\u207b\u00b9 * b) = b :=\nbegin\n  rw [\u2190 mul_assoc, mul_right_inv, one_mul],\nend\n\n-- Finally, let's make a `simp` lemma which enables us to\n-- reduce all inverses to inverses of variables\n@[simp] lemma mul_inv_rev (a b : G) : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel (a * b),\n  simp [mul_right_inv],\nend\n\n/-\nIf you solved them all -- congratulations!\nYou have just turned Lean's simplifier into a normalising confluent\nrewriting system for groups, following Knuth-Bendix.\nhttps://en.wikipedia.org/wiki/Confluence_(abstract_rewriting)#Motivating_examples\nIn other words, the simplifier will now put any element of a free group\ninto a canonical normal form, and can hence solve the word problem\nfor free groups.\n-/\nexample (a b c d : G) :\n  ((a * b)\u207b\u00b9 * a * 1\u207b\u00b9\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * b * b * 1 * 1\u207b\u00b9)\u207b\u00b9 = (c\u207b\u00b9\u207b\u00b9 * d * d\u207b\u00b9 * 1\u207b\u00b9\u207b\u00b9 * c\u207b\u00b9\u207b\u00b9\u207b\u00b9)\u207b\u00b9\u207b\u00b9 :=\nby simp\n\n-- Abstract example of the power of classes: we can define products of groups with instances\n\ninstance (G : Type) [group G] (H : Type) [group H] : group (G \u00d7 H) :=\n{ mul := \u03bb k l, (k.1*l.1, k.2*l.2),\n  one := (1,1),\n  inv := \u03bb k, (k.1\u207b\u00b9, k.2\u207b\u00b9),\n  mul_assoc := begin\n    intros a b c,\n    cases a, cases b, cases c,\n    ext;\n    simp,\n  end,\n  one_mul := begin\n    intro a, ext; simp,\n  end,\n  mul_left_inv := begin\n    intro a, ext; simp,\n  end }\n\n-- the type class inference system now knows that products of groups are groups\nexample (G H K : Type) [group G] [group H] [group K] : group (G \u00d7 H \u00d7 K) :=\nby apply_instance\n\nend group\n\n-- let's make a group of order two.\n\n-- First the elements {+1, -1}\ninductive mu2\n| p1 : mu2\n| m1 : mu2\n\nnamespace mu2\n\n-- Now let's do some CS stuff:\n\n-- 1) prove it has decidable equality\nattribute [derive decidable_eq] mu2\n\n-- 2) prove it is finite\ninstance : fintype mu2 := \u27e8\u27e8[mu2.p1, mu2.m1], by simp\u27e9, \u03bb x, by cases x; simp\u27e9\n\n-- now back to the maths.\n\n-- Define multiplication by doing all cases\ndef mul : mu2 \u2192 mu2 \u2192 mu2\n| p1 p1 := p1\n| p1 m1 := m1\n| m1 p1 := m1\n| m1 m1 := p1\n\ninstance : has_mul mu2 := \u27e8mul\u27e9\n\n-- identity\ndef one : mu2 := p1\n\n-- notation\ninstance : has_one mu2 := \u27e8one\u27e9\n\n-- inverse\ndef inv : mu2 \u2192 mu2 := id\n\n-- notation\ninstance : has_inv mu2 := \u27e8inv\u27e9\n\n-- currently we have notation but no axioms\n\nexample : p1 * m1 * m1 = p1\u207b\u00b9 * p1 := rfl -- all true by definition\n\n-- now let's make it a group\ninstance : group mu2 :=\nbegin\n  -- first define the structure\n  refine_struct { mul := mul, one := one, inv := inv },\n  -- now we have three goals (the axioms)\n  all_goals {exact dec_trivial}\nend\n\nend mu2\n\n\n-- Now let's build rings and modules and stuff (via monoids and add_comm_groups)\n\n-- a monoid is a group without inverses\nclass monoid (M : Type) extends has_mul M, has_one M :=\n(mul_assoc : \u2200 (a b c : M), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : M), 1 * a = a)\n(mul_one : \u2200 (a : M), a * 1 = a)\n\n-- additive commutative groups from first principles\nclass add_comm_group (A : Type) extends has_add A, has_zero A, has_neg A :=\n(add_assoc : \u2200 (a b c : A), a + b + c = a + (b + c))\n(zero_add : \u2200 (a : A), 0 + a = a)\n(add_left_neg : \u2200 (a : A), -a + a = 0)\n(add_comm : \u2200 a b : A, a + b = b + a)\n\n-- Notation for subtraction is handy to have; define a - b to be a + (-b)\ninstance (A : Type) [add_comm_group A] : has_sub A := \u27e8\u03bb a b, a + -b\u27e9\n\n-- rings are additive abelian groups and multiplicative monoids,\n-- with distributivity\nclass ring (R : Type) extends monoid R, add_comm_group R :=\n(mul_add : \u2200 (a b c : R), a * (b + c) = a * b + a * c)\n(add_mul : \u2200 (a b c : R), (a + b) * c = a * c + b * c)\n\n-- for commutative rings, add commutativity of multiplication\nclass comm_ring (R : Type) extends ring R :=\n(mul_comm : \u2200 a b : R, a * b = b * a)\n\n/-- Typeclass for types with a scalar multiplication operation, denoted `\u2022` (`\\bu`) -/\nclass has_scalar (R : Type) (M : Type) := (smul : R \u2192 M \u2192 M)\n\ninfixr ` \u2022 `:73 := has_scalar.smul\n\n-- modules for a ring\nclass module (R : Type) [ring R] (M : Type) [add_comm_group M]\nextends has_scalar R M :=\n(smul_add : \u2200(r : R) (x y : M), r \u2022 (x + y) = r \u2022 x + r \u2022 y)\n(add_smul : \u2200(r s : R) (x : M), (r + s) \u2022 x = r \u2022 x + s \u2022 x)\n(mul_smul : \u2200 (r s : R) (x : M), (r * s) \u2022 x = r \u2022 s \u2022 x)\n(one_smul : \u2200 x : M, (1 : R) \u2022 x = x)\n\n-- for fields we let \u207b\u00b9 be defined on the entire field, and demand 0\u207b\u00b9 = 0\n-- and that a\u207b\u00b9 * a = 1 for non-zero a. This is merely for convenience;\n-- one can easily check that it's mathematically equivalent to the usual\n-- definition of a field.\nclass field (K : Type) extends comm_ring K, has_inv K :=\n(zero_ne_one : (0 : K) \u2260 1)\n(mul_inv_cancel : \u2200 {a : K}, a \u2260 0 \u2192 a * a\u207b\u00b9 = 1)\n(inv_zero : (0 : K)\u207b\u00b9 = 0)\n\n-- the type of vector spaces\ndef vector_space (K : Type) [field K] (V : Type) [add_comm_group V] := module K V\n\n/-\nExercise for the reader: define manifolds, schemes, perfectoid spaces in Lean.\nAll have been done! As you can see, it is clearly *feasible*, although it does\nsometimes take time to get it right. It is all very much work in progress.\nThe extraordinary thing is that although these computer theorem\nprovers have been around for about 50 years, there has never been a serious\neffort to make the standard definitions used all over modern mathematics in\none of them, and this is why these systems are rarely used in mathematics departments.\nChanging this is one of the goals of the Leanprover community.\n-/\n\n/-\nLet's check that we can make the rational numbers into a field. Of course\nthey are already a field in Lean, but remember that when we say `field`\nbelow, we mean our just-defined structure `lftcm.field`.\n-/\n\n-- the rationals are a field (easy because all the work is done in the import)\ninstance : field \u211a :=\n{ mul := (*),\n  one := 1,\n  mul_assoc := rat.mul_assoc,\n  one_mul := rat.one_mul,\n  mul_one := rat.mul_one,\n  add := (+),\n  zero := 0,\n  neg := has_neg.neg, -- no () trickery for unary operators\n  add_assoc := rat.add_assoc,\n  zero_add := rat.zero_add,\n  add_left_neg := rat.add_left_neg,\n  add_comm := rat.add_comm,\n  mul_add := rat.mul_add,\n  add_mul := rat.add_mul,\n  mul_comm := rat.mul_comm,\n  inv := has_inv.inv, -- see neg\n  zero_ne_one := rat.zero_ne_one,\n  mul_inv_cancel := rat.mul_inv_cancel,\n  inv_zero := inv_zero -- I don't know why rat.inv_zero was never explicitly defined\n  }\n\n/-\nBelow is evidence that we can prove basic theorems about these structures.\nNote however that it is a *complete pain* because we are *re-implementing*\neverything; `add_comm` defaults to Lean's version for Lean's `add_comm_group`s, so we\nhave to explicitly write `add_comm_group.add_comm` to use our own version.\nThe mathlib versions of these proofs are less ugly.\n-/\n\nvariables {A : Type} [add_comm_group A]\n\nlemma add_comm_group.add_left_cancel (a b c : A) (Habac : a + b = a + c) : b = c :=\nbegin\n  rw \u2190add_comm_group.zero_add b,\n  rw \u2190add_comm_group.add_left_neg a,\n  rw add_comm_group.add_assoc,\n  rw Habac,\n  rw \u2190add_comm_group.add_assoc,\n  rw add_comm_group.add_left_neg,\n  rw add_comm_group.zero_add,\nend\n\nlemma add_comm_group.add_right_neg (a : A) : a + -a = 0 :=\nbegin\n  rw add_comm_group.add_comm,\n  rw add_comm_group.add_left_neg,\nend\n\nlemma add_comm_group.sub_eq_add_neg (a b : A) :\n  a - b = a + -b :=\nbegin\n  -- this is just our definition of subtraction\n  refl\nend\n\nlemma add_comm_group.sub_self (a : A) : a - a = 0 :=\nbegin\n  rw add_comm_group.sub_eq_add_neg,\n  rw add_comm_group.add_comm,\n  rw add_comm_group.add_left_neg,\nend\n\nlemma add_comm_group.neg_eq_of_add_eq_zero (a b : A) (h : a + b = 0) : -a = b :=\nbegin\n  apply add_comm_group.add_left_cancel a,\n  rw h,\n  rw add_comm_group.add_right_neg,\nend\n\nlemma add_comm_group.add_zero (a : A) : a + 0 = a :=\nbegin\n  rw add_comm_group.add_comm,\n  rw add_comm_group.zero_add,\nend\n\nvariables {R : Type} [ring R]\n\nlemma ring.mul_zero (r : R) : r * 0 = 0 :=\nbegin\n  apply add_comm_group.add_left_cancel (r * 0),\n  rw \u2190ring.mul_add,\n  rw add_comm_group.add_zero,\n  rw add_comm_group.add_zero,\nend\n\n\n\n\n-- etc etc, for thousands of lines of mathlib, which develop the interface\n-- abelian groups, rings, commutative rings, modules, fields, vector spaces etc.\n\nend lftcm\n\n/-\n## Advertisement\nFinished the natural number game? Have Lean installed? Want more games/exercises?\nTake a look at the following projects, many of which are ongoing but\nthe first three of which are pretty much ready:\n*) The complex number game (complete, needs to be played within VS Code)\nhttps://github.com/ImperialCollegeLondon/complex-number-game\nTo install, type\n`leanproject get ImperialCollegeLondon/complex-number-game`\nand then just open the levels in `src/complex`.\n*) Undergraduate level mathematics Lean puzzles (plenty of stuff here,\nand more appearing over the summer):\nhttps://github.com/ImperialCollegeLondon/Example-Lean-Projects\n`leanproject get ImperialCollegeLondon/Example-Lean-Projects`\n*) The max mini-game (a simple browser game like the natural number game)\nhttp://wwwf.imperial.ac.uk/~buzzard/xena/max_minigame/\n(this is part of what will become the real number game, a game to teach\nseries, sequences and limits etc like the natural number game):\n`leanproject get ImperialCollegeLondon/real-number-game`\n*) Some commutative algebra experiments (ongoing work to prove the Nullstellensatz,\ngoing slowly because I'm busy):\nhttps://github.com/ImperialCollegeLondon/M4P33/blob/1a179372db71ad6802d11eacbc1f02f327d55f8f/src/for_mathlib/commutative_algebra/Zariski_lemma.lean#L80-L81\n`leanproject get ImperialCollegeLondon/M4P33`\n*) The group theory game (work in progress, expect more progress over the summer,\nas a couple of undergraduates are working on it)\nhttps://github.com/ImperialCollegeLondon/group-theory-game\n`leanproject get ImperialCollegeLondon/group-theory-game`\n*) Galois theory experiments\nhttps://github.com/ImperialCollegeLondon/P11-Galois-Theory\n`leanproject get ImperialCollegeLondon/P11-Galois-Theory`\n*) Beginnings of the theory of condensed sets (currently on hold because\nwe need a good interface for abelian categories in mathlib)\nhttps://github.com/ImperialCollegeLondon/condensed-sets\n`leanproject get ImperialCollegeLondon/condensed-sets`\n## The Xena Project\nWhy do these projects exist? I (Kevin Buzzard) am interested in teaching\nundergraduates how to use Lean. I have been running a club at Imperial College London\ncalled the Xena Project for the last three years, I am proud that many Imperial\nmathematics undegraduates have contributed to Lean's maths library, and three of them\n(Chris Hughes, Kenny Lau, Amelia Livingston) have each contributed over 5,000 lines of\ncode. It is non-trivial to get your work into such a polished state that it\nis acceptable to the mathlib maintainers. It is also very good practice.\nI am running Lean summer projects this summer, on a Discord server. If you\nknow of any undergraduates who you think might be interested in Lean, please\ndirect them to the Xena Project Discord!\nhttps://discord.gg/BgyVYgJ\nUndergraduates use Discord for lots of things, and seem to be more likely\nto use a Discord server than the Zulip chat. The Discord server is chaotic and\nfull of off-topic material -- quite unlike the Lean Zulip server, which is\nprofessional and focussed. If you have a serious question about Lean,\nask it on the Zulip chat! But if you know an undergraduate who is interested\nin Lean, they might be interested in the Discord server. We have meetings\nevery Thursday evening (UK time), with live Lean coding and streaming, speedruns,\nthere is music, people posting pictures of cats, Haikus, and so on. To a large\nextent it is run by undergraduates and PhD students. Over the summer (July\nand August 2020) there are also live Twitch talks at https://www.twitch.tv/kbuzzard ,\non Tuesdays 10am and Thursdays 4pm UK time (UTC+1), aimed at mathematics\nundergraduates. It is an informal place for undergraduates to hang out and\nmeet other undergraduates who are interested in Lean.\nI believe that it is crucial to make undergraduates aware of computer proof\nverification systems, because one day (possibly a long time in the future,\nbut one day) these things will cause a paradigm shift in the way mathematics\nis done, and the sooner young mathematicians learn about them, the sooner it will happen.\nProve a theorem. Write a function. @XenaProject\nhttps://twitter.com/XenaProject\n-/", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/LftCM2020/exercises/03_Wednesday/02_Algebraic_Heriarchy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7358658130532292}}
{"text": "import MyNat.Power\nimport AdditionWorld.Level5 -- one_eq_succ_zero\nimport PowerWorld.Level3 -- pow_one\nimport AdditionWorld.Level6 -- simp additions\nimport MultiplicationWorld.Level7 -- add_mul\nimport MultiplicationWorld.Level9 -- simp additions\nnamespace MyNat\nopen MyNat\n\n/-!\n# Power World\n\n## Level 8: `add_squared`\n\n## Theorem\nFor all naturals `a` and `b`, we have `(a + b)^2 = a^2 + b^2 + 2ab.`\n\nThe first step in writing this proof is to convert `2` into something we\nhave theorems about, which is `1` and `0`.\n-/\ndef two : MyNat := 2\ndef two_eq_succ_one : two = succ 1 := by rfl\nlemma one_plus_one : (1 : MyNat) + (1 : MyNat) = (2 : MyNat) := by rfl\n-- and we already have one_eq_succ_zero.\n\n/-!\nNow we are ready to tackle the proof:\n-/\n\nlemma add_squared (a b : MyNat) :\n  (a + b) ^ two = a ^ two + b ^ two + 2 * a * b := by\n  rw [two_eq_succ_one]\n  rw [one_eq_succ_zero]\n  repeat rw [pow_succ]\n  repeat rw [pow_zero]\n  repeat rw [one_mul]\n  rw [mul_add]\n  repeat rw [add_mul]\n  rw [\u2190one_plus_one]\n  repeat rw [add_mul]\n  repeat rw [one_mul]\n  simp\n\n/-!\nIt is also helpful to teach `simp` our new tricks:\n-/\nattribute [simp] pow_succ pow_one pow_zero\n\n/-!\nThere is some fun discussion on [Lean3 Zulip](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/function.20with.20random.20definition/near/179723073)\nabout different ways to solve this one in fewer steps.\nFeel free to try some of those solutions here, just note that the Lean 4 syntax is a bit different,\nno commands between tactics, and square brackets are required on the `rw` tactic.\n\nDo you fancy doing `(a+b)^3` now? You might want to read\n[this Xena Project blog post](https://xenaproject.wordpress.com/2018/06/13/ab3/) before you start though.\n\nIf you got this far -- very well done! If you only learnt the three\ntactics `rw`, `induction` and `refl` then there are now more tactics to\nlearn; time to try  [Function World](../FunctionWorld.lean.md).\n\nThe main thing we really want to impress upon people is that we believe\nthat *all of pure mathematics* can be done in this new way.\n\nThe [Liquid Tensor Experiment](https://xenaproject.wordpress.com/2022/09/12/beyond-the-liquid-tensor-experiment/)\nshows that Lean3 could be used to prove very large math theorems.\n\nLean 3 also has a [definition of perfectoid spaces](https://leanprover-community.github.io/lean-perfectoid-spaces/)\n(a very complex modern mathematical structure). We believe that these systems will one day\ncause a paradigm shift in the way mathematics is done, but first we need\nto build what we know, or at least build enough to state what we\nmathematicians believe.\n\nIf you want to get involved, come and join\nus at the [Zulip Lean chat](https://leanprover.zulipchat.com\").\nThe #new members stream is a great place to start asking questions.\n\nNext up [Function World](../FunctionWorld.lean.md).\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/PowerWorld/Level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7358658098390167}}
{"text": "import .basic\n\nsection\nparameters {R : Type} [sia R]\nopen st_order\nopen st_ordered_field\nopen sia\n\n@[reducible] private def Delta := Delta R\n@[reducible] private def DeltaT := subtype Delta\n\n\nsection -- 1.1\n    variable (a: R)\n\n    example : 0 < a -> 0 != a :=\n        assume a_pos,\n        assume a_zero_bad: 0 = a,\n        lt_irrefl (0: R) (calc\n            0   < a : a_pos\n            ... = 0 : by rw a_zero_bad\n        )\n\n    example : 0 < a <-> -a < 0 :=\n        have forwards : 0 < a -> -a < 0, from (\n            assume a_pos,\n            calc\n                -a  < -0 : lt_neg_flip a_pos\n                ... = 0  : neg_zero\n        ),\n        have backwards : -a < 0 -> 0 < a, from (\n            assume neg_a_neg,\n            calc\n                0   = -0    : by rw neg_zero\n                ... < -(-a) : lt_neg_flip neg_a_neg\n                ... = a     : by rw neg_neg\n        ),\n        iff.intro forwards backwards\n\n    example : 0 < (1: R) + 1 := calc\n        0   < 1           : lt_zero_one R\n        ... = 1 + 0       : eq.symm (add_zero 1)\n        ... < (1 + 1 : R) : lt_add_left (lt_zero_one R) 1\n\n     example : a < 0 \\/ 0 < a -> 0 < a * a :=\n         assume either_lt_0_a,\n         have left: a < 0 -> 0 < a * a, from (\n            assume a_neg,\n            have neg_a_pos: 0 < -a, from (calc\n                0   = -0 : by rw neg_zero\n                ... < -a : lt_neg_flip a_neg\n            ), calc\n                0   = -a * 0     : by rw mul_zero\n                ... < -a * -a    : lt_mul_pos_left neg_a_pos neg_a_pos\n                ... = a * a      : by rw neg_mul_neg\n         ),\n         have right: 0 < a -> 0 < a * a, from (\n             assume a_pos,\n             calc\n                 0   = a * 0 : by rw (mul_zero a)\n                 ... < a * a : lt_mul_pos_left a_pos a_pos\n         ),\n         or.elim either_lt_0_a left right\nend\n\n-- 1.2 in basic.lean\n\nexample : forall {a b: R}, not (a < b) -> forall x: R, not (set.mem x [a ... b]) := -- 1.3; i.e. [a ... b] is empty\n    assume a b,\n    assume not_a_lt_b,\n    assume x,\n    assume bad_elem,\n    have bad: a < x /\\ x < b, from bad_elem,\n    not_a_lt_b (lt_trans (and.elim_left bad) (and.elim_right bad))\n\n-- 1.4 in basic.lean\n\nsection --1.5\n    @[reducible]\n    def convex_comb (x y : R) (t : subtype [[(0: R) ... 1]]) := t.val * y + (1 - t.val) * x\n\n    example : forall a b : R, forall x y : subtype [[a ... b]], forall t : subtype [[0 ... 1]],\n                a <= convex_comb x.val y.val t /\\ convex_comb x.val y.val t <= b :=\n        assume a b,\n        assume x y,\n        assume t,\n        have t_nonneg: 0 <= t.val, from and.elim_left t.property,\n\n        have t.val <= 1, from and.elim_right t.property,\n        have t_nonneg': 0 <= (1 - t.val), from (calc\n            0   = 1 + -1       : by rw add_neg_self\n            ... <= 1 + - t.val : le_add_left (le_neg_flip this)\n            ... = 1 - t.val    : by rw <-sub_eq_add_neg\n        ),\n\n        have left: a <= convex_comb x.val y.val t, from\n            have x_ineq: a <= x.val, from and.elim_left x.property,\n            have y_ineq: a <= y.val, from and.elim_left y.property,\n            (calc\n                a   = 1 * a + (- (t.val * a) + t.val * a)  : by rw [<-add_comm (t.val * a) _, <-sub_eq_add_neg, sub_self, add_zero, one_mul]\n                ... = 1 * a + -(t.val) * a + t.val * a     : by rw [add_assoc, neg_mul_eq_neg_mul]\n                ... = (1 - t.val) * a + t.val * a          : by rw [sub_eq_add_neg, <-right_distrib]\n                ... <= (1 - t.val) * a + t.val * y.val     : le_add_left (le_mul_pos_left y_ineq t_nonneg)\n                ... = t.val * y.val + (1 - t.val) * a      : by rw add_comm\n                ... <= t.val * y.val + (1 - t.val) * x.val : le_add_left (le_mul_pos_left x_ineq t_nonneg')\n            ),\n        have right: convex_comb x.val y.val t <= b, from\n            have x_ineq: x.val <= b, from and.elim_right x.property,\n            have y_ineq: y.val <= b, from and.elim_right y.property,\n            (calc\n                t.val * y.val + (1 - t.val) * x.val\n                    <= t.val * y.val + (1 - t.val) * b    : le_add_left (le_mul_pos_left x_ineq t_nonneg')\n                ... = (1 - t.val) * b + t.val * y.val     : by rw add_comm\n                ... <= (1 - t.val) * b + t.val * b        : le_add_left (le_mul_pos_left y_ineq t_nonneg)\n                ... = 1 * b + -(t.val) * b + t.val * b    : by rw [sub_eq_add_neg, right_distrib]\n                ... = 1 * b + (- (t.val * b) + t.val * b) : by rw [add_assoc, neg_mul_eq_neg_mul]\n                ... = b - (t.val * b) + t.val * b         : by rw [one_mul, sub_eq_add_neg, add_assoc]\n                ... = b                                   : by rw sub_add_cancel\n            ),\n        and.intro left right\nend\n\nsection -- 1.6\n    example : forall d: subtype Delta, not (d.val < (0: R) \\/ 0 < d.val) :=\n        assume d,\n        have 0 <= d.val /\\ d.val <= 0, from delta_near_zero d,\n        not_or this.left this.right\n\n    example : forall d: subtype Delta, forall a: R, 0 < a -> 0 < a + d.val :=\n        assume d,\n        assume a,\n        assume a_pos,\n        calc\n            0   <= d.val    : and.elim_left (delta_near_zero d)\n            ... = d.val + 0 : by rw add_zero\n            ... < d.val + a : lt_add_left a_pos _\n            ... = a + d.val : by rw add_comm\nend\n\nsection -- 1.7\n    example : forall a b : R, forall d e : subtype Delta, [[a ... b]] = [[a + d.val ... b + e.val]] :=\n        assume a b,\n        assume d e,\n        have set.eq [[a ... b]] [[a + d.val ... b + e.val]], from\n            assume x,\n            have forwards : set.mem x [[a ... b]] -> set.mem x [[a + d.val ... b + e.val]], from\n                assume x_mem,\n                have ge: a + d.val <= x, from\n                    have d.val <= 0, from and.elim_right (delta_near_zero d),\n                    calc a + d.val\n                        <= a + 0 : by {apply le_add_left this}\n                    ... <= x     : by {simp, apply and.elim_left x_mem},\n                have le: x <= b + e.val, from\n                    have 0 <= e.val, from and.elim_left (delta_near_zero e),\n                    calc\n                      x <= b + 0     : by {simp, apply and.elim_right x_mem}\n                    ... <= b + e.val : le_add_left this,\n                and.intro ge le,\n            have backwards : set.mem x [[a + d.val ... b + e.val]] -> set.mem x [[a ... b]], from\n                assume x_mem,\n                have ge: a <= x, from\n                    have 0 <= d.val, from and.elim_left (delta_near_zero d),\n                    calc\n                      a = a + 0      : by simp\n                    ... <= a + d.val : by {apply le_add_left this}\n                    ... <= x         : and.elim_left x_mem,\n                have le: x <= b, from\n                    have e.val <= 0, from and.elim_right (delta_near_zero e),\n                    calc\n                      x <= b + e.val : and.elim_right x_mem\n                    ... <= b + 0     : by {apply le_add_left this}\n                    ... = b          : by simp,\n                and.intro ge le,\n            iff.intro forwards backwards,\n        set.ext this\nend\n\nsection -- 1.8\n    @[reducible]\n    def rigid_rod : Type := DeltaT -> R\n\n    private meta def lift_funext : tactic unit := `[ intro f, intros, apply funext, intro d ]\n\n    instance rigid_rod_ring [sia R] : ring rigid_rod := {\n        add := fun f g, fun d, f d + g d,\n        zero := fun d, 0,\n        neg := fun f, fun d, -(f d),\n        mul := fun f g, fun d, f d * g d,\n        one := fun d, 1,\n\n        add_assoc := by {lift_funext, show _ + _ = _ + _, rw add_assoc},\n        add_comm := by {lift_funext, show _ + _ = _ + _, rw add_comm},\n        add_zero := by {lift_funext, show f d + 0 = f d, rw add_zero},\n        zero_add := by {lift_funext, show 0 + f d = f d, rw zero_add},\n        add_left_neg := by {lift_funext, show -(f d) + f d = 0, rw add_left_neg},\n        mul_assoc := by {lift_funext, show _ * _ = _ * _, rw mul_assoc},\n        one_mul := by {lift_funext, show 1 * f d = f d, rw one_mul},\n        mul_one := by {lift_funext, show f d * 1 = f d, rw mul_one},\n        left_distrib := by {lift_funext, show _ * _ = _ + _, rw left_distrib},\n        right_distrib := by {lift_funext, show _ * _ = _ + _, rw right_distrib},\n    }\n\n    instance prod_ring {T : Type} [ring T] : ring (T \u00d7 T) := {\n        add := fun x y, (x.fst + y.fst, x.snd + y.snd),\n        zero := (0, 0),\n        neg := fun x, (-x.fst, -x.snd),\n        mul := fun x y, (x.fst * y.fst, x.fst * y.snd + x.snd * y.fst),\n        one := (1, 0),\n\n        add_assoc := by {intros, simp},\n        add_comm := by {intros, show (_, _) = (_, _), simp},\n        add_zero := by {intro x, cases x, show (_, _) = (_, _), simp},\n        zero_add := by {intro x, cases x, show (_, _) = (_, _), simp},\n        add_left_neg := by {intro x, cases x, show (_, _) = (_, _), simp},\n        mul_assoc := by {intros, simp [left_distrib, right_distrib]},\n        one_mul := by {intro x, cases x, show (_, _) = (_, _), simp},\n        mul_one := by {intro x, cases x, show (_, _) = (_, _), simp},\n        left_distrib := by {intros, simp [left_distrib]},\n        right_distrib := by {intros, simp [right_distrib]},\n    }\n\n    @[reducible]\n    def iso : R \u00d7 R -> rigid_rod := fun ab, fun d, ab.fst + ab.snd * d.val\n\n    example : forall x y: R \u00d7 R, iso (x + y) = iso x + iso y := begin\n        intros,\n        apply funext,\n        intro,\n        show (_ + _) + (_ + _) * _ = (_ + _ * _) + (_ + _ * _), -- reduce iso\n        simp [left_distrib]\n    end\n\n    example : forall x y: R \u00d7 R, iso (x * y) = iso x * iso y := begin\n        intros,\n        apply funext,\n        intro d,\n        have sq_zero: d.val * d.val = 0, from d.property,\n        show (_ * _) + (_ + _) * _ = (_ + _ * _) * (_ + _ * _), -- reduce iso\n        simp [left_distrib, sq_zero],\n    end\n\n    example : iso 1 = (1: rigid_rod) := begin\n        apply funext,\n        intro,\n        show (_, _).fst + (_, _).snd * _ = (1 : R),\n        simp\n    end\nend\n\nsection -- 1.9\n    lemma microproduct_not_zero : not (forall e n : subtype Delta, e.val * n.val = 0) :=\n        assume bad,\n        have forall d e : subtype Delta, d.val = e.val, from\n            assume d e,\n            have forall n : subtype Delta, d.val * n.val = e.val * n.val, from \n                assume n,\n                (calc\n                    d.val * n.val = 0     : bad d n\n                    ...   = e.val * n.val : eq.symm (bad e n)\n                ),\n            sia.microcancellation this,\n        sia.delta_nondegenerate this\n\n    lemma Delta_not_microstable : not (sia.microstable Delta) :=\n        assume bad,\n        have forall a b : subtype Delta, a.val * b.val = 0, from\n            assume a b,\n            have a_nilpotent : a.val * a.val = 0, from a.property,\n            have b_nilpotent : b.val * b.val = 0, from b.property,\n            have sum_nilpotent : (a.val + b.val) * (a.val + b.val) = 0, from bad a b,\n            have (2 : R) != 0, from ne.symm (lt_ne (calc (0:R)\n                < 1     : lt_zero_one R\n            ... = 1 + 0 : by simp\n            ... < 1 + 1 : lt_add_left (lt_zero_one R) 1)),\n            (calc a.val * b.val\n                = (a.val * b.val) * 2 / 2 : by rw (mul_div_cancel _ this)\n            ... = (a.val * b.val) * (1 + 1) / 2 : by refl\n            ... = (a.val * b.val + a.val * b.val) / 2 : by rw [left_distrib, mul_one]\n            ... = ((0 + a.val * b.val) + (a.val * b.val + 0)) / 2 : by simp\n            ... = ((a.val * a.val + a.val * b.val) + (a.val * b.val + b.val * b.val)) / 2 : by rw [a_nilpotent, b_nilpotent]\n            ... = ((a.val + b.val) * (a.val + b.val)) / 2 : by simp [left_distrib, right_distrib]\n            ... = 0 / 2 : by rw [sum_nilpotent]\n            ... = 0 : by rw [zero_div]),\n        microproduct_not_zero this\n\n    example : not (forall x y : R, x * x + y * y = 0 -> x * x = 0) :=\n        assume bad,\n        have sia.microstable Delta, from\n            assume a_sub b_sub,\n            let a := a_sub.val in\n            let a_prop : a * a = 0 := a_sub.property in\n            let b := b_sub.val in\n            let b_prop : b * b = 0 := b_sub.property in\n            have (a + b) * (a + b) + (a - b) * (a - b) = 0, from (calc\n                (a + b) * (a + b) + (a - b) * (a - b)\n                    = (a * a + a * a + b * b + b * b) : by simp [left_distrib, right_distrib]\n                ... = 0 : by simp [a_prop, b_prop]\n            ),\n            bad (a + b) (a - b) this,\n        Delta_not_microstable this\nend\n\nsection -- 1.10\n    @[reducible] def neighbors (a b : R) := Delta (a - b)\n\n    example : forall a : R, neighbors a a :=\n        assume a,\n        show (a - a) * (a - a) = 0, by rw [sub_self, zero_mul]\n\n    example : forall {a b : R}, neighbors a b -> neighbors b a :=\n        assume a b,\n        assume pf_ab,\n        calc (b - a) * (b - a)\n            = -(b - a) * -(b - a) : by rw [neg_mul_neg]\n        ... = (a - b) * (a - b)   : by simp\n        ... = 0                   : pf_ab\n\n    example : not (forall {a b c : R}, neighbors a b -> neighbors b c -> neighbors a c) :=\n        assume bad,\n        have terrible : sia.microstable Delta, from\n            assume d e,\n            have n_ab : neighbors d.val 0, from\n                calc (d.val - 0) * (d.val - 0)\n                    = d.val * d.val : by simp\n                ... = 0 : d.property,\n            have n_bc : neighbors 0 (-e.val), from\n                calc (0 - -e.val) * (0 - -e.val)\n                    = e.val * e.val : by simp\n                ... = 0 : e.property,\n            calc (d.val + e.val) * (d.val + e.val)\n                = (d.val - -e.val) * (d.val - -e.val) : by rw [sub_neg_eq_add]\n            ... = 0 : bad n_ab n_bc,\n        Delta_not_microstable terrible\nend\n\nsection -- 1.11\n    @[reducible] def continuous (f : R -> R) : Prop := forall x y : R, neighbors x y -> neighbors (f x) (f y)\n\n    def univ (R : Type) : Type := subtype (@set.univ R)\n\n    example : forall (f : R -> R), continuous f :=\n        assume f,\n        show continuous f, from\n            assume x y : R,\n            let d_val := x - y in\n            assume d_Delta : d_val * d_val = 0,\n            let d : DeltaT := { val := d_val, property := d_Delta } in\n            have forall a: R, (forall d: DeltaT, f (y + d.val) = f y + a * d.val) -> neighbors (f x) (f y), from\n                assume a,\n                assume nice,\n                have x = y + d.val, by simp [d_val],\n                have f x = f y + a * d.val, by {rw this, apply nice d},\n                calc (f x - f y) * (f x - f y)\n                    = (a * a) * (d.val * d.val) : by simp [this]\n                ... = (a * a) * 0 : by rw d_Delta\n                ... = 0 : by rw mul_zero,\n            exists.elim (exists_of_exists_unique (microaffinity f y)) this\nend\n\nend\n", "meta": {"author": "metalogical", "repo": "sia-lean", "sha": "f8e354dd2ff6c09c4e001c1f80f6112c62da8592", "save_path": "github-repos/lean/metalogical-sia-lean", "path": "github-repos/lean/metalogical-sia-lean/sia-lean-f8e354dd2ff6c09c4e001c1f80f6112c62da8592/src/exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605945, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7357952482185434}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.ring_theory.roots_of_unity\nimport Mathlib.analysis.special_functions.trigonometric\nimport Mathlib.analysis.special_functions.pow\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Complex roots of unity\n\nIn this file we show that the `n`-th complex roots of unity\nare exactly the complex numbers `e ^ (2 * real.pi * complex.I * (i / n))` for `i \u2208 finset.range n`.\n\n## Main declarations\n\n* `complex.mem_roots_of_unity`: the complex `n`-th roots of unity are exactly the\n  complex numbers of the form `e ^ (2 * real.pi * complex.I * (i / n))` for some `i < n`.\n* `complex.card_roots_of_unity`: the number of `n`-th roots of unity is exactly `n`.\n\n-/\n\nnamespace complex\n\n\ntheorem is_primitive_root_exp_of_coprime (i : \u2115) (n : \u2115) (h0 : n \u2260 0) (hi : nat.coprime i n) : is_primitive_root (exp (bit0 1 * \u2191real.pi * I * (\u2191i / \u2191n))) n := sorry\n\ntheorem is_primitive_root_exp (n : \u2115) (h0 : n \u2260 0) : is_primitive_root (exp (bit0 1 * \u2191real.pi * I / \u2191n)) n := sorry\n\ntheorem is_primitive_root_iff (\u03b6 : \u2102) (n : \u2115) (hn : n \u2260 0) : is_primitive_root \u03b6 n \u2194 \u2203 (i : \u2115), \u2203 (H : i < n), \u2203 (hi : nat.coprime i n), exp (bit0 1 * \u2191real.pi * I * (\u2191i / \u2191n)) = \u03b6 := sorry\n\n/-- The complex `n`-th roots of unity are exactly the\ncomplex numbers of the form `e ^ (2 * real.pi * complex.I * (i / n))` for some `i < n`. -/\ntheorem mem_roots_of_unity (n : \u2115+) (x : units \u2102) : x \u2208 roots_of_unity n \u2102 \u2194 \u2203 (i : \u2115), \u2203 (H : i < \u2191n), exp (bit0 1 * \u2191real.pi * I * (\u2191i / \u2191n)) = \u2191x := sorry\n\ntheorem card_roots_of_unity (n : \u2115+) : fintype.card \u21a5(roots_of_unity n \u2102) = \u2191n :=\n  is_primitive_root.card_roots_of_unity (is_primitive_root_exp (\u2191n) (pnat.ne_zero n))\n\ntheorem card_primitive_roots (k : \u2115) (h : k \u2260 0) : finset.card (primitive_roots k \u2102) = nat.totient k :=\n  is_primitive_root.card_primitive_roots (is_primitive_root_exp k h) (nat.pos_of_ne_zero h)\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/analysis/complex/roots_of_unity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7357952402232937}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport linear_algebra.linear_pmap\nimport analysis.convex.basic\nimport order.zorn\n\n/-!\n# Convex cones\n\nIn a vector space `E` over `\u211d`, we define a convex cone as a subset `s` such that\n`a \u2022 x + b \u2022 y \u2208 s` whenever `x, y \u2208 s` and `a, b > 0`. We prove that convex cones form\na `complete_lattice`, and define their images (`convex_cone.map`) and preimages\n(`convex_cone.comap`) under linear maps.\n\nWe define pointed, blunt, flat and salient cones, and prove the correspondence between\nconvex cones and ordered modules.\n\nWe also define `convex.to_cone` to be the minimal cone that includes a given convex set.\n\n## Main statements\n\nWe prove two extension theorems:\n\n* `riesz_extension`:\n  [M. Riesz extension theorem](https://en.wikipedia.org/wiki/M._Riesz_extension_theorem) says that\n  if `s` is a convex cone in a real vector space `E`, `p` is a submodule of `E`\n  such that `p + s = E`, and `f` is a linear function `p \u2192 \u211d` which is\n  nonnegative on `p \u2229 s`, then there exists a globally defined linear function\n  `g : E \u2192 \u211d` that agrees with `f` on `p`, and is nonnegative on `s`.\n\n* `exists_extension_of_le_sublinear`:\n  Hahn-Banach theorem: if `N : E \u2192 \u211d` is a sublinear map, `f` is a linear map\n  defined on a subspace of `E`, and `f x \u2264 N x` for all `x` in the domain of `f`,\n  then `f` can be extended to the whole space to a linear map `g` such that `g x \u2264 N x`\n  for all `x`\n\n## Implementation notes\n\nWhile `convex` is a predicate on sets, `convex_cone` is a bundled convex cone.\n\n## References\n\n* https://en.wikipedia.org/wiki/Convex_cone\n\n## TODO\n\n* Define the dual cone.\n-/\n\nuniverses u v\n\nopen set linear_map\nopen_locale classical\n\nvariables (E : Type*) [add_comm_group E] [module \u211d E]\n  {F : Type*} [add_comm_group F] [module \u211d F]\n  {G : Type*} [add_comm_group G] [module \u211d G]\n\n/-!\n### Definition of `convex_cone` and basic properties\n-/\n\n/-- A convex cone is a subset `s` of a vector space over `\u211d` such that `a \u2022 x + b \u2022 y \u2208 s`\nwhenever `a, b > 0` and `x, y \u2208 s`. -/\nstructure convex_cone :=\n(carrier : set E)\n(smul_mem' : \u2200 \u2983c : \u211d\u2984, 0 < c \u2192 \u2200 \u2983x : E\u2984, x \u2208 carrier \u2192 c \u2022 x \u2208 carrier)\n(add_mem' : \u2200 \u2983x\u2984 (hx : x \u2208 carrier) \u2983y\u2984 (hy : y \u2208 carrier), x + y \u2208 carrier)\n\nvariable {E}\n\nnamespace convex_cone\n\nvariables (S T : convex_cone E)\n\ninstance : has_coe (convex_cone E) (set E) := \u27e8convex_cone.carrier\u27e9\n\ninstance : has_mem E (convex_cone E) := \u27e8\u03bb m S, m \u2208 S.carrier\u27e9\n\ninstance : has_le (convex_cone E) := \u27e8\u03bb S T, S.carrier \u2286 T.carrier\u27e9\n\ninstance : has_lt (convex_cone E) := \u27e8\u03bb S T, S.carrier \u2282 T.carrier\u27e9\n\n@[simp, norm_cast] lemma mem_coe {x : E} : x \u2208 (S : set E) \u2194 x \u2208 S := iff.rfl\n\n@[simp] lemma mem_mk {s : set E} {h\u2081 h\u2082 x} : x \u2208 mk s h\u2081 h\u2082 \u2194 x \u2208 s := iff.rfl\n\n/-- Two `convex_cone`s are equal if the underlying subsets are equal. -/\ntheorem ext' {S T : convex_cone E} (h : (S : set E) = T) : S = T :=\nby cases S; cases T; congr'\n\n/-- Two `convex_cone`s are equal if and only if the underlying subsets are equal. -/\nprotected theorem ext'_iff {S T : convex_cone E}  : (S : set E) = T \u2194 S = T :=\n\u27e8ext', \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Two `convex_cone`s are equal if they have the same elements. -/\n@[ext] theorem ext {S T : convex_cone E} (h : \u2200 x, x \u2208 S \u2194 x \u2208 T) : S = T := ext' $ set.ext h\n\nlemma smul_mem {c : \u211d} {x : E} (hc : 0 < c) (hx : x \u2208 S) : c \u2022 x \u2208 S := S.smul_mem' hc hx\n\nlemma add_mem \u2983x\u2984 (hx : x \u2208 S) \u2983y\u2984 (hy : y \u2208 S) : x + y \u2208 S := S.add_mem' hx hy\n\nlemma smul_mem_iff {c : \u211d} (hc : 0 < c) {x : E} :\n  c \u2022 x \u2208 S \u2194 x \u2208 S :=\n\u27e8\u03bb h, by simpa only [smul_smul, inv_mul_cancel (ne_of_gt hc), one_smul]\n  using S.smul_mem (inv_pos.2 hc) h, \u03bb h, S.smul_mem hc h\u27e9\n\nlemma convex : convex (S : set E) :=\nconvex_iff_forall_pos.2 $ \u03bb x y hx hy a b ha hb hab,\nS.add_mem (S.smul_mem ha hx) (S.smul_mem hb hy)\n\ninstance : has_inf (convex_cone E) :=\n\u27e8\u03bb S T, \u27e8S \u2229 T, \u03bb c hc x hx, \u27e8S.smul_mem hc hx.1, T.smul_mem hc hx.2\u27e9,\n  \u03bb x hx y hy, \u27e8S.add_mem hx.1 hy.1, T.add_mem hx.2 hy.2\u27e9\u27e9\u27e9\n\nlemma coe_inf : ((S \u2293 T : convex_cone E) : set E) = \u2191S \u2229 \u2191T := rfl\n\nlemma mem_inf {x} : x \u2208 S \u2293 T \u2194 x \u2208 S \u2227 x \u2208 T := iff.rfl\n\ninstance : has_Inf (convex_cone E) :=\n\u27e8\u03bb S, \u27e8\u22c2 s \u2208 S, \u2191s,\n  \u03bb c hc x hx, mem_bInter $ \u03bb s hs, s.smul_mem hc $ by apply mem_bInter_iff.1 hx s hs,\n  \u03bb x hx y hy, mem_bInter $ \u03bb s hs, s.add_mem (by apply mem_bInter_iff.1 hx s hs)\n    (by apply mem_bInter_iff.1 hy s hs)\u27e9\u27e9\n\nlemma mem_Inf {x : E} {S : set (convex_cone E)} : x \u2208 Inf S \u2194 \u2200 s \u2208 S, x \u2208 s := mem_bInter_iff\n\ninstance : has_bot (convex_cone E) := \u27e8\u27e8\u2205, \u03bb c hc x, false.elim, \u03bb x, false.elim\u27e9\u27e9\n\nlemma mem_bot (x : E) : x \u2208 (\u22a5 : convex_cone E) = false := rfl\n\ninstance : has_top (convex_cone E) := \u27e8\u27e8univ, \u03bb c hc x hx, mem_univ _, \u03bb x hx y hy, mem_univ _\u27e9\u27e9\n\nlemma mem_top (x : E) : x \u2208 (\u22a4 : convex_cone E) := mem_univ x\n\ninstance : complete_lattice (convex_cone E) :=\n{ le           := (\u2264),\n  lt           := (<),\n  bot          := (\u22a5),\n  bot_le       := \u03bb S x, false.elim,\n  top          := (\u22a4),\n  le_top       := \u03bb S x hx, mem_top x,\n  inf          := (\u2293),\n  Inf          := has_Inf.Inf,\n  sup          := \u03bb a b, Inf {x | a \u2264 x \u2227 b \u2264 x},\n  Sup          := \u03bb s, Inf {T | \u2200 S \u2208 s, S \u2264 T},\n  le_sup_left  := \u03bb a b, \u03bb x hx, mem_Inf.2 $ \u03bb s hs, hs.1 hx,\n  le_sup_right := \u03bb a b, \u03bb x hx, mem_Inf.2 $ \u03bb s hs, hs.2 hx,\n  sup_le       := \u03bb a b c ha hb x hx, mem_Inf.1 hx c \u27e8ha, hb\u27e9,\n  le_inf       := \u03bb a b c ha hb x hx, \u27e8ha hx, hb hx\u27e9,\n  inf_le_left  := \u03bb a b x, and.left,\n  inf_le_right := \u03bb a b x, and.right,\n  le_Sup       := \u03bb s p hs x hx, mem_Inf.2 $ \u03bb t ht, ht p hs hx,\n  Sup_le       := \u03bb s p hs x hx, mem_Inf.1 hx p hs,\n  le_Inf       := \u03bb s a ha x hx, mem_Inf.2 $ \u03bb t ht, ha t ht hx,\n  Inf_le       := \u03bb s a ha x hx, mem_Inf.1 hx _ ha,\n  .. partial_order.lift (coe : convex_cone E \u2192 set E) (\u03bb a b, ext') }\n\ninstance : inhabited (convex_cone E) := \u27e8\u22a5\u27e9\n\n/-- The image of a convex cone under an `\u211d`-linear map is a convex cone. -/\ndef map (f : E \u2192\u2097[\u211d] F) (S : convex_cone E) : convex_cone F :=\n{ carrier := f '' S,\n  smul_mem' := \u03bb c hc y \u27e8x, hx, hy\u27e9, hy \u25b8 f.map_smul c x \u25b8 mem_image_of_mem f (S.smul_mem hc hx),\n  add_mem' := \u03bb y\u2081 \u27e8x\u2081, hx\u2081, hy\u2081\u27e9 y\u2082 \u27e8x\u2082, hx\u2082, hy\u2082\u27e9, hy\u2081 \u25b8 hy\u2082 \u25b8 f.map_add x\u2081 x\u2082 \u25b8\n    mem_image_of_mem f (S.add_mem hx\u2081 hx\u2082) }\n\nlemma map_map (g : F \u2192\u2097[\u211d] G) (f : E \u2192\u2097[\u211d] F) (S : convex_cone E) :\n  (S.map f).map g = S.map (g.comp f) :=\next' $ image_image g f S\n\n@[simp] lemma map_id : S.map linear_map.id = S := ext' $ image_id _\n\n/-- The preimage of a convex cone under an `\u211d`-linear map is a convex cone. -/\ndef comap (f : E \u2192\u2097[\u211d] F) (S : convex_cone F) : convex_cone E :=\n{ carrier := f \u207b\u00b9' S,\n  smul_mem' := \u03bb c hc x hx, by { rw [mem_preimage, f.map_smul c], exact S.smul_mem hc hx },\n  add_mem' := \u03bb x hx y hy, by { rw [mem_preimage, f.map_add], exact S.add_mem hx hy } }\n\n@[simp] lemma comap_id : S.comap linear_map.id = S := ext' preimage_id\n\nlemma comap_comap (g : F \u2192\u2097[\u211d] G) (f : E \u2192\u2097[\u211d] F) (S : convex_cone G) :\n  (S.comap g).comap f = S.comap (g.comp f) :=\next' $ preimage_comp.symm\n\n@[simp] lemma mem_comap {f : E \u2192\u2097[\u211d] F} {S : convex_cone F} {x : E} :\n  x \u2208 S.comap f \u2194 f x \u2208 S := iff.rfl\n\n/--\nConstructs an ordered module given an `ordered_add_comm_group`, a cone, and a proof that\nthe order relation is the one defined by the cone.\n-/\nlemma to_ordered_module {M : Type*} [ordered_add_comm_group M] [module \u211d M]\n  (S : convex_cone M) (h : \u2200 x y : M, x \u2264 y \u2194 y - x \u2208 S) : ordered_module \u211d M :=\nordered_module.mk'\nbegin\n  intros x y z xy hz,\n  rw [h (z \u2022 x) (z \u2022 y), \u2190smul_sub z y x],\n  exact smul_mem S hz ((h x y).mp (le_of_lt xy))\nend\n\n/-! ### Convex cones with extra properties -/\n\n/-- A convex cone is pointed if it includes 0. -/\ndef pointed (S : convex_cone E) : Prop := (0 : E) \u2208 S\n\n/-- A convex cone is blunt if it doesn't include 0. -/\ndef blunt (S : convex_cone E) : Prop := (0 : E) \u2209 S\n\n/-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/\ndef flat (S : convex_cone E) : Prop := \u2203 x \u2208 S, x \u2260 (0 : E) \u2227 -x \u2208 S\n\n/-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/\ndef salient (S : convex_cone E) : Prop := \u2200 x \u2208 S, x \u2260 (0 : E) \u2192 -x \u2209 S\n\nlemma pointed_iff_not_blunt (S : convex_cone E) : pointed S \u2194 \u00acblunt S :=\n\u27e8\u03bb h\u2081 h\u2082, h\u2082 h\u2081, \u03bb h, not_not.mp h\u27e9\n\nlemma salient_iff_not_flat (S : convex_cone E) : salient S \u2194 \u00acflat S :=\nbegin\n  split,\n  { rintros h\u2081 \u27e8x, xs, H\u2081, H\u2082\u27e9,\n    exact h\u2081 x xs H\u2081 H\u2082 },\n  { intro h,\n    unfold flat at h,\n    push_neg at h,\n    exact h }\nend\n\n/-- A blunt cone (one not containing 0) is always salient. -/\nlemma salient_of_blunt (S : convex_cone E) : blunt S \u2192 salient S :=\nbegin\n  intro h\u2081,\n  rw [salient_iff_not_flat],\n  intro h\u2082,\n  obtain \u27e8x, xs, H\u2081, H\u2082\u27e9 := h\u2082,\n  have hkey : (0 : E) \u2208 S := by rw [(show 0 = x + (-x), by simp)]; exact add_mem S xs H\u2082,\n  exact h\u2081 hkey,\nend\n\n/-- A pointed convex cone defines a preorder. -/\ndef to_preorder (S : convex_cone E) (h\u2081 : pointed S) : preorder E :=\n{ le := \u03bb x y, y - x \u2208 S,\n  le_refl := \u03bb x, by change x - x \u2208 S; rw [sub_self x]; exact h\u2081,\n  le_trans := \u03bb x y z xy zy, by simp [(show z - x = z - y + (y - x), by abel), add_mem S zy xy] }\n\n/-- A pointed and salient cone defines a partial order. -/\ndef to_partial_order (S : convex_cone E) (h\u2081 : pointed S) (h\u2082 : salient S) : partial_order E :=\n{ le_antisymm :=\n    begin\n      intros a b ab ba,\n      by_contradiction h,\n      have h' : b - a \u2260 0 := \u03bb h'', h (eq_of_sub_eq_zero h'').symm,\n      have H := h\u2082 (b-a) ab h',\n      rw [neg_sub b a] at H,\n      exact H ba,\n    end,\n  ..to_preorder S h\u2081 }\n\n/-- A pointed and salient cone defines an `ordered_add_comm_group`. -/\ndef to_ordered_add_comm_group (S : convex_cone E) (h\u2081 : pointed S) (h\u2082 : salient S) :\n  ordered_add_comm_group E :=\n{ add_le_add_left :=\n    begin\n      intros a b hab c,\n      change c + b - (c + a) \u2208 S,\n      rw [add_sub_add_left_eq_sub],\n      exact hab,\n    end,\n  ..to_partial_order S h\u2081 h\u2082,\n  ..show add_comm_group E, by apply_instance }\n\n/-! ### Positive cone of an ordered module -/\nsection positive_cone\n\nvariables (M : Type*) [ordered_add_comm_group M] [module \u211d M] [ordered_module \u211d M]\n\n/--\nThe positive cone is the convex cone formed by the set of nonnegative elements in an ordered\nmodule.\n-/\ndef positive_cone : convex_cone M :=\n{ carrier := {x | 0 \u2264 x},\n  smul_mem' :=\n    begin\n      intros c hc x hx,\n      have := smul_le_smul_of_nonneg (show 0 \u2264 x, by exact hx) (le_of_lt hc),\n      have h' : c \u2022 (0 : M) = 0,\n      { simp only [smul_zero] },\n      rwa [h'] at this\n    end,\n  add_mem' := \u03bb x hx y hy, add_nonneg (show 0 \u2264 x, by exact hx) (show 0 \u2264 y, by exact hy) }\n\n/-- The positive cone of an ordered module is always salient. -/\nlemma salient_of_positive_cone : salient (positive_cone M) :=\nbegin\n  intros x xs hx hx',\n  have := calc\n    0   < x         : lt_of_le_of_ne xs hx.symm\n    ... \u2264 x + (-x)  : (le_add_iff_nonneg_right x).mpr hx'\n    ... = 0         : by rw [tactic.ring.add_neg_eq_sub x x]; exact sub_self x,\n  exact lt_irrefl 0 this,\nend\n\n/-- The positive cone of an ordered module is always pointed. -/\nlemma pointed_of_positive_cone : pointed (positive_cone M) := le_refl 0\n\nend positive_cone\n\nend convex_cone\n\n/-!\n### Cone over a convex set\n-/\n\nnamespace convex\n\n/-- The set of vectors proportional to those in a convex set forms a convex cone. -/\ndef to_cone (s : set E) (hs : convex s) : convex_cone E :=\nbegin\n  apply convex_cone.mk (\u22c3 c > 0, (c : \u211d) \u2022 s);\n    simp only [mem_Union, mem_smul_set],\n  { rintros c c_pos _ \u27e8c', c'_pos, x, hx, rfl\u27e9,\n    exact \u27e8c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm\u27e9 },\n  { rintros _ \u27e8cx, cx_pos, x, hx, rfl\u27e9 _ \u27e8cy, cy_pos, y, hy, rfl\u27e9,\n    have : 0 < cx + cy, from add_pos cx_pos cy_pos,\n    refine \u27e8_, this, _, convex_iff_div.1 hs hx hy (le_of_lt cx_pos) (le_of_lt cy_pos) this, _\u27e9,\n    simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left _ (ne_of_gt this)] }\nend\n\nvariables {s : set E} (hs : convex s) {x : E}\n\nlemma mem_to_cone : x \u2208 hs.to_cone s \u2194 \u2203 (c > 0) (y \u2208 s), (c : \u211d) \u2022 y = x :=\nby simp only [to_cone, convex_cone.mem_mk, mem_Union, mem_smul_set, eq_comm, exists_prop]\n\nlemma mem_to_cone' : x \u2208 hs.to_cone s \u2194 \u2203 c > 0, (c : \u211d) \u2022 x \u2208 s :=\nbegin\n  refine hs.mem_to_cone.trans \u27e8_, _\u27e9,\n  { rintros \u27e8c, hc, y, hy, rfl\u27e9,\n    exact \u27e8c\u207b\u00b9, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel (ne_of_gt hc), one_smul]\u27e9 },\n  { rintros \u27e8c, hc, hcx\u27e9,\n    exact \u27e8c\u207b\u00b9, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel (ne_of_gt hc), one_smul]\u27e9 }\nend\n\nlemma subset_to_cone : s \u2286 hs.to_cone s :=\n\u03bb x hx, hs.mem_to_cone'.2 \u27e81, zero_lt_one, by rwa one_smul\u27e9\n\n/-- `hs.to_cone s` is the least cone that includes `s`. -/\nlemma to_cone_is_least : is_least { t : convex_cone E | s \u2286 t } (hs.to_cone s) :=\nbegin\n  refine \u27e8hs.subset_to_cone, \u03bb t ht x hx, _\u27e9,\n  rcases hs.mem_to_cone.1 hx with \u27e8c, hc, y, hy, rfl\u27e9,\n  exact t.smul_mem hc (ht hy)\nend\n\nlemma to_cone_eq_Inf : hs.to_cone s = Inf { t : convex_cone E | s \u2286 t } :=\nhs.to_cone_is_least.is_glb.Inf_eq.symm\n\nend convex\n\nlemma convex_hull_to_cone_is_least (s : set E) :\n  is_least {t : convex_cone E | s \u2286 t} ((convex_convex_hull s).to_cone _) :=\nbegin\n  convert (convex_convex_hull s).to_cone_is_least,\n  ext t,\n  exact \u27e8\u03bb h, convex_hull_min h t.convex, \u03bb h, subset.trans (subset_convex_hull s) h\u27e9\nend\n\nlemma convex_hull_to_cone_eq_Inf (s : set E) :\n  (convex_convex_hull s).to_cone _ = Inf {t : convex_cone E | s \u2286 t} :=\n(convex_hull_to_cone_is_least s).is_glb.Inf_eq.symm\n\n/-!\n### M. Riesz extension theorem\n\nGiven a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p \u2192 \u211d`, assume\nthat `f` is nonnegative on `p \u2229 s` and `p + s = E`. Then there exists a globally defined linear\nfunction `g : E \u2192 \u211d` that agrees with `f` on `p`, and is nonnegative on `s`.\n\nWe prove this theorem using Zorn's lemma. `riesz_extension.step` is the main part of the proof.\nIt says that if the domain `p` of `f` is not the whole space, then `f` can be extended to a larger\nsubspace `p \u2294 span \u211d {y}` without breaking the non-negativity condition.\n\nIn `riesz_extension.exists_top` we use Zorn's lemma to prove that we can extend `f`\nto a linear map `g` on `\u22a4 : submodule E`. Mathematically this is the same as a linear map on `E`\nbut in Lean `\u22a4 : submodule E` is isomorphic but is not equal to `E`. In `riesz_extension`\nwe use this isomorphism to prove the theorem.\n-/\n\nnamespace riesz_extension\n\nopen submodule\n\nvariables (s : convex_cone E) (f : linear_pmap \u211d E \u211d)\n\n/-- Induction step in M. Riesz extension theorem. Given a convex cone `s` in a vector space `E`,\na partially defined linear map `f : f.domain \u2192 \u211d`, assume that `f` is nonnegative on `f.domain \u2229 p`\nand `p + s = E`. If `f` is not defined on the whole `E`, then we can extend it to a larger\nsubmodule without breaking the non-negativity condition. -/\nlemma step (nonneg : \u2200 x : f.domain, (x : E) \u2208 s \u2192 0 \u2264 f x)\n  (dense : \u2200 y, \u2203 x : f.domain, (x : E) + y \u2208 s) (hdom : f.domain \u2260 \u22a4) :\n  \u2203 g, f < g \u2227 \u2200 x : g.domain, (x : E) \u2208 s \u2192 0 \u2264 g x :=\nbegin\n  rcases set_like.exists_of_lt (lt_top_iff_ne_top.2 hdom) with \u27e8y, hy', hy\u27e9, clear hy',\n  obtain \u27e8c, le_c, c_le\u27e9 :\n    \u2203 c, (\u2200 x : f.domain, -(x:E) - y \u2208 s \u2192 f x \u2264 c) \u2227 (\u2200 x : f.domain, (x:E) + y \u2208 s \u2192 c \u2264 f x),\n  { set Sp := f '' {x : f.domain | (x:E) + y \u2208 s},\n    set Sn := f '' {x : f.domain | -(x:E) - y \u2208 s},\n    suffices : (upper_bounds Sn \u2229 lower_bounds Sp).nonempty,\n      by simpa only [set.nonempty, upper_bounds, lower_bounds, ball_image_iff] using this,\n    refine exists_between_of_forall_le (nonempty.image f _) (nonempty.image f (dense y)) _,\n    { rcases (dense (-y)) with \u27e8x, hx\u27e9,\n      rw [\u2190 neg_neg x, coe_neg, \u2190 sub_eq_add_neg] at hx,\n      exact \u27e8_, hx\u27e9 },\n    rintros a \u27e8xn, hxn, rfl\u27e9 b \u27e8xp, hxp, rfl\u27e9,\n    have := s.add_mem hxp hxn,\n    rw [add_assoc, add_sub_cancel'_right, \u2190 sub_eq_add_neg, \u2190 coe_sub] at this,\n    replace := nonneg _ this,\n    rwa [f.map_sub, sub_nonneg] at this },\n  have hy' : y \u2260 0, from \u03bb hy\u2080, hy (hy\u2080.symm \u25b8 zero_mem _),\n  refine \u27e8f.sup_span_singleton y (-c) hy, _, _\u27e9,\n  { refine lt_iff_le_not_le.2 \u27e8f.left_le_sup _ _, \u03bb H, _\u27e9,\n    replace H := linear_pmap.domain_mono.monotone H,\n    rw [linear_pmap.domain_sup_span_singleton, sup_le_iff, span_le, singleton_subset_iff] at H,\n    exact hy H.2 },\n  { rintros \u27e8z, hz\u27e9 hzs,\n    rcases mem_sup.1 hz with \u27e8x, hx, y', hy', rfl\u27e9,\n    rcases mem_span_singleton.1 hy' with \u27e8r, rfl\u27e9,\n    simp only [subtype.coe_mk] at hzs,\n    erw [linear_pmap.sup_span_singleton_apply_mk _ _ _ _ _ hx, smul_neg,\n      \u2190 sub_eq_add_neg, sub_nonneg],\n    rcases lt_trichotomy r 0 with hr|hr|hr,\n    { have : -(r\u207b\u00b9 \u2022 x) - y \u2208 s,\n        by rwa [\u2190 s.smul_mem_iff (neg_pos.2 hr), smul_sub, smul_neg, neg_smul, neg_neg, smul_smul,\n          mul_inv_cancel (ne_of_lt hr), one_smul, sub_eq_add_neg, neg_smul, neg_neg],\n      replace := le_c (r\u207b\u00b9 \u2022 \u27e8x, hx\u27e9) this,\n      rwa [\u2190 mul_le_mul_left (neg_pos.2 hr), \u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul,\n        neg_le_neg_iff, f.map_smul, smul_eq_mul, \u2190 mul_assoc, mul_inv_cancel (ne_of_lt hr),\n        one_mul] at this },\n    { subst r,\n      simp only [zero_smul, add_zero] at hzs \u22a2,\n      apply nonneg,\n      exact hzs },\n    { have : r\u207b\u00b9 \u2022 x + y \u2208 s,\n        by rwa [\u2190 s.smul_mem_iff hr, smul_add, smul_smul, mul_inv_cancel (ne_of_gt hr), one_smul],\n      replace := c_le (r\u207b\u00b9 \u2022 \u27e8x, hx\u27e9) this,\n      rwa [\u2190 mul_le_mul_left hr, f.map_smul, smul_eq_mul, \u2190 mul_assoc,\n        mul_inv_cancel (ne_of_gt hr), one_mul] at this } }\nend\n\ntheorem exists_top (p : linear_pmap \u211d E \u211d)\n  (hp_nonneg : \u2200 x : p.domain, (x : E) \u2208 s \u2192 0 \u2264 p x)\n  (hp_dense : \u2200 y, \u2203 x : p.domain, (x : E) + y \u2208 s) :\n  \u2203 q \u2265 p, q.domain = \u22a4 \u2227 \u2200 x : q.domain, (x : E) \u2208 s \u2192 0 \u2264 q x :=\nbegin\n  replace hp_nonneg : p \u2208 { p | _ }, by { rw mem_set_of_eq, exact hp_nonneg },\n  obtain \u27e8q, hqs, hpq, hq\u27e9 := zorn.zorn_nonempty_partial_order\u2080 _ _ _ hp_nonneg,\n  { refine \u27e8q, hpq, _, hqs\u27e9,\n    contrapose! hq,\n    rcases step s q hqs _ hq with \u27e8r, hqr, hr\u27e9,\n    { exact \u27e8r, hr, le_of_lt hqr, ne_of_gt hqr\u27e9 },\n    { exact \u03bb y, let \u27e8x, hx\u27e9 := hp_dense y in \u27e8of_le hpq.left x, hx\u27e9 } },\n  { intros c hcs c_chain y hy,\n    clear hp_nonneg hp_dense p,\n    have cne : c.nonempty := \u27e8y, hy\u27e9,\n    refine \u27e8linear_pmap.Sup c c_chain.directed_on, _, \u03bb _, linear_pmap.le_Sup c_chain.directed_on\u27e9,\n    rintros \u27e8x, hx\u27e9 hxs,\n    have hdir : directed_on (\u2264) (linear_pmap.domain '' c),\n      from directed_on_image.2 (c_chain.directed_on.mono linear_pmap.domain_mono.monotone),\n    rcases (mem_Sup_of_directed (cne.image _) hdir).1 hx with \u27e8_, \u27e8f, hfc, rfl\u27e9, hfx\u27e9,\n    have : f \u2264 linear_pmap.Sup c c_chain.directed_on, from linear_pmap.le_Sup _ hfc,\n    convert \u2190 hcs hfc \u27e8x, hfx\u27e9 hxs,\n    apply this.2, refl }\nend\n\nend riesz_extension\n\n/-- M. Riesz extension theorem: given a convex cone `s` in a vector space `E`, a submodule `p`,\nand a linear `f : p \u2192 \u211d`, assume that `f` is nonnegative on `p \u2229 s` and `p + s = E`. Then\nthere exists a globally defined linear function `g : E \u2192 \u211d` that agrees with `f` on `p`,\nand is nonnegative on `s`. -/\ntheorem riesz_extension (s : convex_cone E) (f : linear_pmap \u211d E \u211d)\n  (nonneg : \u2200 x : f.domain, (x : E) \u2208 s \u2192 0 \u2264 f x) (dense : \u2200 y, \u2203 x : f.domain, (x : E) + y \u2208 s) :\n  \u2203 g : E \u2192\u2097[\u211d] \u211d, (\u2200 x : f.domain, g x = f x) \u2227 (\u2200 x \u2208 s, 0 \u2264 g x) :=\nbegin\n  rcases riesz_extension.exists_top s f nonneg dense with \u27e8\u27e8g_dom, g\u27e9, \u27e8hpg, hfg\u27e9, htop, hgs\u27e9,\n  clear hpg,\n  refine \u27e8g.comp (linear_equiv.of_top _ htop).symm, _, _\u27e9;\n    simp only [comp_apply, linear_equiv.coe_coe, linear_equiv.of_top_symm_apply],\n  { exact \u03bb x, (hfg (submodule.coe_mk _ _).symm).symm },\n  { exact \u03bb x hx, hgs \u27e8x, _\u27e9 hx }\nend\n\n/-- Hahn-Banach theorem: if `N : E \u2192 \u211d` is a sublinear map, `f` is a linear map\ndefined on a subspace of `E`, and `f x \u2264 N x` for all `x` in the domain of `f`,\nthen `f` can be extended to the whole space to a linear map `g` such that `g x \u2264 N x`\nfor all `x`. -/\ntheorem exists_extension_of_le_sublinear (f : linear_pmap \u211d E \u211d) (N : E \u2192 \u211d)\n  (N_hom : \u2200 (c : \u211d), 0 < c \u2192 \u2200 x, N (c \u2022 x) = c * N x)\n  (N_add : \u2200 x y, N (x + y) \u2264 N x + N y)\n  (hf : \u2200 x : f.domain, f x \u2264 N x) :\n  \u2203 g : E \u2192\u2097[\u211d] \u211d, (\u2200 x : f.domain, g x = f x) \u2227 (\u2200 x, g x \u2264 N x) :=\nbegin\n  let s : convex_cone (E \u00d7 \u211d) :=\n  { carrier := {p : E \u00d7 \u211d | N p.1 \u2264 p.2 },\n    smul_mem' := \u03bb c hc p hp,\n      calc N (c \u2022 p.1) = c * N p.1 : N_hom c hc p.1\n      ... \u2264 c * p.2 : mul_le_mul_of_nonneg_left hp (le_of_lt hc),\n    add_mem' := \u03bb x hx y hy, le_trans (N_add _ _) (add_le_add hx hy) },\n  obtain \u27e8g, g_eq, g_nonneg\u27e9 :=\n    riesz_extension s ((-f).coprod (linear_map.id.to_pmap \u22a4)) _ _;\n    try { simp only [linear_pmap.coprod_apply, to_pmap_apply, id_apply,\n            linear_pmap.neg_apply, \u2190 sub_eq_neg_add, sub_nonneg, subtype.coe_mk] at * },\n  replace g_eq : \u2200 (x : f.domain) (y : \u211d), g (x, y) = y - f x,\n  { intros x y,\n    simpa only [subtype.coe_mk, subtype.coe_eta] using g_eq \u27e8(x, y), \u27e8x.2, trivial\u27e9\u27e9 },\n  { refine \u27e8-g.comp (inl \u211d E \u211d), _, _\u27e9; simp only [neg_apply, inl_apply, comp_apply],\n    { intro x, simp  [g_eq x 0] },\n    { intro x,\n      have A : (x, N x) = (x, 0) + (0, N x), by simp,\n      have B := g_nonneg \u27e8x, N x\u27e9 (le_refl (N x)),\n      rw [A, map_add, \u2190 neg_le_iff_add_nonneg'] at B,\n      have C := g_eq 0 (N x),\n      simp only [submodule.coe_zero, f.map_zero, sub_zero] at C,\n      rwa \u2190 C } },\n  { exact \u03bb x hx, le_trans (hf _) hx },\n  { rintros \u27e8x, y\u27e9,\n    refine \u27e8\u27e8(0, N x - y), \u27e8f.domain.zero_mem, trivial\u27e9\u27e9, _\u27e9,\n    simp only [convex_cone.mem_mk, mem_set_of_eq, subtype.coe_mk, prod.fst_add, prod.snd_add,\n      zero_add, sub_add_cancel] }\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/convex/cone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798115, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7357952359072085}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.complex\nimport analysis.special_functions.trigonometric.deriv\n\n/-!\n# Complex trigonometric functions\n\nBasic facts and derivatives for the complex trigonometric functions.\n-/\n\nnoncomputable theory\n\nnamespace complex\n\nopen set filter\nopen_locale real\n\nlemma has_strict_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_strict_deriv_at tan (1 / (cos x)^2) x :=\nbegin\n  convert (has_strict_deriv_at_sin x).div (has_strict_deriv_at_cos x) h,\n  rw \u2190 sin_sq_add_cos_sq x,\n  ring,\nend\n\nlemma has_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_deriv_at tan (1 / (cos x)^2) x :=\n(has_strict_deriv_at_tan h).has_deriv_at\n\nopen_locale topological_space\n\nlemma tendsto_abs_tan_of_cos_eq_zero {x : \u2102} (hx : cos x = 0) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[\u2260] x) at_top :=\nbegin\n  simp only [tan_eq_sin_div_cos, \u2190 norm_eq_abs, normed_field.norm_div],\n  have A : sin x \u2260 0 := \u03bb h, by simpa [*, sq] using sin_sq_add_cos_sq x,\n  have B : tendsto cos (\ud835\udcdd[\u2260] (x)) (\ud835\udcdd[\u2260] 0),\n    from hx \u25b8 (has_deriv_at_cos x).tendsto_punctured_nhds (neg_ne_zero.2 A),\n  exact continuous_sin.continuous_within_at.norm.mul_at_top (norm_pos_iff.2 A)\n    (tendsto_norm_nhds_within_zero.comp B).inv_tendsto_zero,\nend\n\nlemma tendsto_abs_tan_at_top (k : \u2124) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[\u2260] ((2 * k + 1) * \u03c0 / 2)) at_top :=\ntendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 \u27e8k, rfl\u27e9\n\n@[simp] lemma continuous_at_tan {x : \u2102} : continuous_at tan x \u2194 cos x \u2260 0 :=\nbegin\n  refine \u27e8\u03bb hc h\u2080, _, \u03bb h, (has_deriv_at_tan h).continuous_at\u27e9,\n  exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h\u2080) _\n    (hc.norm.tendsto.mono_left inf_le_left)\nend\n\n@[simp] lemma differentiable_at_tan {x : \u2102} : differentiable_at \u2102 tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at, \u03bb h, (has_deriv_at_tan h).differentiable_at\u27e9\n\n@[simp] lemma deriv_tan (x : \u2102) : deriv tan x = 1 / (cos x)^2 :=\nif h : cos x = 0 then\n  have \u00acdifferentiable_at \u2102 tan x := mt differentiable_at_tan.1 (not_not.2 h),\n  by simp [deriv_zero_of_not_differentiable_at this, h, sq]\nelse (has_deriv_at_tan h).deriv\n\n@[simp] lemma times_cont_diff_at_tan {x : \u2102} {n : with_top \u2115} :\n  times_cont_diff_at \u2102 n tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at,\n  times_cont_diff_sin.times_cont_diff_at.div times_cont_diff_cos.times_cont_diff_at\u27e9\n\nend complex\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/special_functions/trigonometric/complex_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.735795233749166}}
{"text": "-- vim: ts=2 sw=0 sts=-1 et ai tw=70\n\nimport .basic\nimport .dvd\nimport .induction\n\nnamespace hidden\n\nopen mynat\n\ndef fib: mynat \u2192 mynat\n| 0               := 0\n| 1               := 1\n| (succ (succ n)) := fib n + fib (succ n)\n\nvariables {m n k p: mynat}\n\n@[simp] theorem fib_zero: fib 0 = 0 := rfl\n@[simp] theorem fib_one: fib 1 = 1 := rfl\n\n@[simp]\ntheorem fib_succsucc:\nfib (succ (succ n)) = fib n + fib (succ n) := rfl\n\ntheorem fib_k_formula (k: mynat):\nfib (m + (k + 1)) = fib k * fib m + fib (k + 1) * fib (m + 1) :=\nbegin\n  -- this is here because I retroactively changed the theorem\n  -- statement and I'm lazy\n  rw \u2190add_assoc,\n  revert k,\n  apply duo_induction, {\n    simp,\n  }, {\n    simp,\n    rw \u2190one_eq_succ_zero,\n    rw fib_succsucc,\n    simp,\n  }, {\n    intro k,\n    assume h_ih1 h_ih2,\n    -- yucky algebra\n    have: (2: mynat) = 1 + 1 := rfl,\n    rw this,\n    repeat {rw \u2190add_assoc},\n    rw [add_one_succ, add_one_succ],\n    rw fib_succsucc,\n    rw \u2190add_one_succ,\n    rw \u2190add_assoc at h_ih2,\n    rw [h_ih1, h_ih2],\n    -- now we have to collect the terms in F_m and F_{m + 1}\n    conv {\n      to_lhs,\n      rw add_assoc,\n      rw add_comm,\n      congr, congr, skip,\n      rw add_comm,\n    },\n    rw \u2190add_assoc,\n    rw \u2190add_mul,\n    conv {\n      to_lhs,\n      congr, congr, congr, congr, skip,\n      rw add_one_succ,\n    },\n    rw \u2190fib_succsucc,\n    rw add_assoc,\n    rw \u2190add_mul,\n    conv {\n      to_lhs,\n      congr, skip, congr,\n      rw add_comm,\n      rw add_one_succ,\n    },\n    rw \u2190fib_succsucc,\n    rw add_comm,\n    refl,\n  },\nend\n\n-- this is a consequence of the big one we want to prove, which is\n-- F_gcd(m, n) = gcd(F_m, F_n), which actually needs only fairly basic\n-- properties of gcd - but it does require that you've defined gcd,\n-- sadly.\ntheorem f_preserves_multiples\n(k: mynat):\nn \u2223 m \u2192 fib n \u2223 fib m :=\nbegin\n  assume hnm,\n  cases hnm with k hk,\n  cases n, {\n    rw hk,\n    simp,\n  }, {\n    rw [hk, mul_comm],\n    clear hk,\n    induction k with k_n k_ih, {\n      from dvd_zero,\n    }, {\n      rw [mul_succ, add_comm],\n      conv {\n        congr, skip, congr, congr, skip,\n        rw \u2190add_one_succ,\n      },\n      rw [fib_k_formula n, add_one_succ],\n      apply dvd_sum, {\n        rw mul_comm,\n        from dvd_mul _ k_ih,\n      }, {\n        rw mul_comm,\n        from dvd_multiple,\n      },\n    },\n  },\nend\n\n-- TODO: adjacent are coprime,\n--       https://en.wikipedia.org/wiki/Fibonacci_number#Other_identities\n--       the squares one from\n--          https://en.wikipedia.org/wiki/Fibonacci_number#Combinatorial_identities\n\n-- induction, just to see if I could, really.\n-- the nice high-level way to prove this is using determinants\ntheorem cassini_odd:\nfib (2 * n) * fib (2 * n + 2) + 1\n  = fib (2 * n + 1) * fib (2 * n + 1) :=\nbegin\n  have cancel2: \u2200 a b c: mynat, a = b \u2192 c + a = c + b, {\n    intros, rw a_1,\n  },\n  induction n with n hn, {\n    refl,\n  }, {\n    repeat {rw mul_succ},\n    have h2k: \u2200 k: mynat, 2 + k = succ (succ k), {\n      intro k,\n      rw add_comm,\n      refl,\n    },\n    repeat {rw h2k},\n    have hk2: \u2200 k: mynat, k + 2 = succ (succ k), {\n      intro k, refl,\n    },\n    repeat {rw hk2},\n    repeat {rw add_one_succ},\n    repeat {rw fib_succsucc},\n    repeat {rw \u2190add_one_succ}, -- legibility\n    repeat {rw mul_add},\n    repeat {rw add_mul},\n    -- laboriously cancel terms. This is likely very inefficient\n    -- algebra, but it's hard for me to keep track of things\n    -- otherwise. Lots of conv, for similar reasons\n    conv {\n      to_lhs,\n      congr,\n      rw [\u2190add_assoc, \u2190add_assoc, \u2190add_assoc, \u2190add_assoc, \u2190add_assoc,\n          \u2190add_assoc],\n      rw add_comm,\n    },\n    repeat {rw add_assoc},\n    apply cancel2,\n    repeat {rw \u2190add_assoc},\n    rw add_comm (fib (2 * n) * fib (2 * n)),\n    repeat {rw add_assoc},\n    rw mul_comm,\n    apply cancel2,\n    repeat {rw \u2190add_assoc},\n    rw add_comm (fib (2 * n) * fib (2 * n)),\n    repeat {rw add_assoc},\n    conv {\n      to_rhs,\n      rw add_comm,\n    },\n    repeat {rw add_assoc},\n    apply cancel2,\n    apply cancel2,\n    repeat {rw \u2190add_assoc},\n    rw add_comm (fib (2 * n + 1) * fib (2 * n + 1)),\n    repeat {rw add_assoc},\n    apply cancel2,\n    apply cancel2,\n    conv {\n      to_rhs,\n      rw add_comm,\n      rw add_assoc,\n    },\n    apply cancel2,\n    conv {\n      congr,\n      rw add_comm,\n      rw add_assoc,\n      skip,\n      rw add_comm,\n    },\n    apply cancel2,\n    conv {\n      to_lhs,\n      rw add_comm,\n      rw \u2190add_assoc,\n      rw \u2190mul_add,\n      congr,\n      rw add_one_succ,\n      rw \u2190fib_succsucc,\n    },\n    from hn,\n  },\nend\n\ntheorem cassini_even:\nfib (2 * n + 1) * fib (2 * n + 3)\n  = fib (2 * n + 2) * fib (2 * n + 2) + 1 :=\nbegin\n  have cancel2: \u2200 a b c: mynat, a = b \u2192 c + a = c + b, {\n    intros, rw a_1,\n  },\n  repeat {rw mul_succ},\n  have h2k: \u2200 k: mynat, 2 + k = succ (succ k), {\n    intro k,\n    rw add_comm,\n    refl,\n  },\n  repeat {rw h2k},\n  have hk2: \u2200 k: mynat, k + 2 = succ (succ k), {\n    intro k, refl,\n  },\n  repeat {rw hk2},\n  have hk3: \u2200 k: mynat, k + 3 = succ (succ (succ k)), {\n    intro k, refl,\n  },\n  repeat {rw hk3},\n  repeat {rw add_one_succ},\n  repeat {rw fib_succsucc},\n  repeat {rw \u2190add_one_succ}, -- legibility\n  repeat {rw mul_add},\n  repeat {rw add_mul},\n\n  repeat {rw add_assoc},\n  conv {\n    congr,\n    rw add_comm,\n    skip,\n    rw add_comm,\n  },\n  repeat {rw add_assoc},\n  apply cancel2,\n  conv {\n    to_rhs,\n    rw add_comm,\n  },\n  repeat {rw add_assoc},\n  apply cancel2,\n  conv {\n    to_rhs,\n    rw add_comm,\n    congr,\n    rw \u2190mul_add,\n    rw add_one_succ,\n    rw \u2190fib_succsucc,\n  },\n  from cassini_odd.symm,\nend\n\nend hidden\n", "meta": {"author": "Sterrs", "repo": "leaning", "sha": "3901cc953694b33adda86cb88ca30ba99594db31", "save_path": "github-repos/lean/Sterrs-leaning", "path": "github-repos/lean/Sterrs-leaning/leaning-3901cc953694b33adda86cb88ca30ba99594db31/src/principia/mynat/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7357952322280435}}
{"text": "import algebra.big_operators.basic\nimport data.rat.defs\n\n\n/-!\nGiven a natural number n > 1, add up all the fractions 1 / (p \u2b1d q), where\np and q are relatively prime, 0 < p < q \u2264 n, and p + q > n. Prove that\nthe result is always 1/2.\n-/\n\nopen_locale big_operators\n\ntheorem summing_fractions (n : \u2115) (hn : 1 < n) :\n   (\u2211(p : \u2115) in finset.range n.succ, \u2211(q : \u2115) in finset.range n.succ,\n     if p < q \u2227 n < p + q \u2227 nat.coprime p q\n     then rat.inv (p * q)\n     else 0) = 1/2 :=\nbegin\n  sorry\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/summing_fractions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966656805269, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7357894519384782}}
{"text": "import data.set\nopen set\n\n\nuniverses u\u2081 u\u2082 u\u2083 \n\ninductive word (Sigma : Type u\u2082)\n        | \u03b5  {}         : word\n        | nonempty      : Sigma \u2192 word \u2192 word \n\n\n\n\nnotation e ` \u2022 ` v := word.nonempty e v\n\nnotation `[[` l:(foldr `.` (e v, word.nonempty e v) word.\u03b5) `]]` := l\n\n\n\nsection Automata_DFA \n    parameter {Sigma : Type u\u2082}             -- The alphabet\n    open word\n\n\n    structure DFA    :=         \n            (State : Type u\u2081)                    -- Set of States\n            (\u03b4 : State \u2192 Sigma \u2192 State)             -- \u03b4: S \u00d7 \u03a3 \u2192 S\n            (terminal: set State)               -- T \u2286 S\n            (s\u2080 : State)                        -- S\u2080 the starting state\n\n    /--\n    Given a morphism \u03c4 between two Automates A and B\n    determines if \u03c4 is a homomorphism\n    -/\n    def is_homomorphism                \n        (A B : DFA) (\u03c4 : A.State \u2192 B.State) : Prop :=   \n            \u2200 a : A.State ,                                 -- \u2200 states (a) in A\n                a \u2208 A.terminal \u2194 \u03c4 a \u2208 B.terminal \u2227     -- a \u2208 T_A iff \u03c4(a) \u2208 T_B\n                    \u2200 e : Sigma ,                       -- and \u2200 e \u2208 \u03a3\n                        \u03c4 (A.\u03b4 a e) = (B.\u03b4 (\u03c4 a) e)     -- \u03c4(\u03b4_A(a , e)) = \u03b4_B(\u03c4(a) , e)\n\n\n    def deltaStarDFA {A : DFA} (s : A.State): word Sigma \u2192 A.State \n        | \u03b5           :=  s \n        | (e\u2022v)       :=  A.\u03b4 (deltaStarDFA v) e\n\n\n    def acceptedDFA (A : DFA) (w : word Sigma) : Prop :=\n        @deltaStarDFA A A.s\u2080 w \u2208 A.terminal\n\nend Automata_DFA\n\n\n\n\nsection Automata_NFA\n    parameter {Sigma : Type}\n    open word\n\n    structure NFA := mk::\n            (State : Type)\n            (\u03b4 : State \u2192 Sigma \u2192 set State)\n            (terminal: set State)\n            (s\u2080 : State) \n\n\n    variable N : NFA\n\n    def deltaStarNFA {N :NFA} (s :N.State) : word Sigma\u2192 set N.State \n        |\u03b5         :=  {s}\n        |(e\u2022v)     :=  \u22c3 s \u2208 (deltaStarNFA v) ,\n                                (N.\u03b4 s e)\n\n    def acceptedNFA {N:NFA} (w : word Sigma) : Prop :=\n        deltaStarNFA N.s\u2080 w \u2229 N.terminal \u2260 \u2205\n\nend Automata_NFA\n    \n    \n    \n\n\n\n\n\nsection NFA_to_DFA\n    parameters {Sigma:Type} (N : @NFA Sigma)\n\n    open word\n\n    open DFA\n    open NFA\n\n    def NFA_to_DFA: DFA := \n        {   \n            State       :=  set N.State,\n            \u03b4       :=  \u03bb(S : set N.State) (a : Sigma), \n                        \u22c3 s \u2208 S, (N.\u03b4 s a),\n            terminal:=  {T: set N.State | T \u2229 N.terminal \u2260 \u2205},\n            s\u2080      :=  {N.s\u2080}\n        }\n\n    \n\n\n\n    theorem same_language: \n        \u2200 (word: word Sigma) ,\n            deltaStarNFA N.s\u2080 word \n            = \n            deltaStarDFA \n                        NFA_to_DFA.s\u2080  \n                        word \n        :=\n        begin\n            intro word,\n            induction word,\n            case word.\u03b5 : \n                {exact rfl},\n            case word.nonempty  : \n                {   \n                let e  := word_a,       --first letter\n                let v  := word_a_1,     --rest of the word\n                \n                let NFA_reachable_with_v : set N.State := \n                        deltaStarNFA N.s\u2080 v,\n\n                let DFA_reachable_with_v : set N.State := \n                        deltaStarDFA \n                            NFA_to_DFA.s\u2080\n                            v,\n\n                let NFA_reachable_with_word := deltaStarNFA N.s\u2080 \n                                    (e\u2022v) ,\n\n                let DFA_reachable_with_word := \n                    NFA_to_DFA.\u03b4\n                        DFA_reachable_with_v\n                        e,\n\n                have ih : NFA_reachable_with_v = DFA_reachable_with_v \n                                := word_ih,\n\n                have h1 : NFA_reachable_with_word = \n                            \u22c3 s \u2208 NFA_reachable_with_v ,\n                            (N.\u03b4 s e) := rfl,\n\n                have h2 : DFA_reachable_with_word =\n                            \u22c3 s \u2208 DFA_reachable_with_v, \n                            (N.\u03b4 s e) := rfl ,\n\n                show \n                    NFA_reachable_with_word = DFA_reachable_with_word\n                        , \n                from \n                    by {\n                        rw [h1, ih] ,\n                        apply rfl\n                    }\n\n                }\n        end\n\n\n\n\nend NFA_to_DFA\n\n\n\n\ndef D : DFA := \n{\n    State           := \u2115,\n    \u03b4           := \u03bb n (c : char) , n+1,\n    terminal    := {2,3},\n    s\u2080          := 0 \n}\n\ndef w1 : word char := [['a' . 'b' . 'c']]\n\n#reduce @deltaStarDFA char D (0:nat) w1\n\n#reduce acceptedDFA D w1\n\n\n", "meta": {"author": "QaisHamarneh", "repo": "Coalgebra-in-Lean", "sha": "bd0452df98bc64b608e5dfd7babc42c301bb6a46", "save_path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean", "path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean/Coalgebra-in-Lean-bd0452df98bc64b608e5dfd7babc42c301bb6a46/src/examples/automata/automata.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739075, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7357791323307269}}
{"text": "import tactic\nimport lectures.lec13_structures_on_gaussian_int\n\n\n/- A __set__ `S` in `U` is just a predicate `S : U \u2192 Prop`  -/\n\n\n\n\n/- If `U` is any type, the type `set U` consists of sets of elements of `U`.-/ \n\n\n/- `set U := U \u2192 Prop` -/\n\n/-the set `univ`, which consists of all the elements of type `U`, and the empty set, `\u2205`, which can be typed as \\empty.-/\n\n\n/- For a set `S : set U` and `x : U` we write `x \u2208 S` for the proposition `S x`. -/\n\n\n\n\nvariable {U : Type*}\nvariables (A B C D E : set U)\n\nopen set\n\n\n#check ( { 0 } : set \u2115) \n\n-- The subset relation can be typed with \\sub\n\n#check A \u2286 B \n-- `A \u2286 B` is defined by the logical statement  `\u2200  x : U , (x \u2208 A \u2192 x \u2208 B)`\n\n\n\n-- intersection can be typed with \\i or \\cap.\n#check A \u2229 B \n\n--Union can be typed with \\un or \\cup.\n#check A \u222a B \n\n\n#check @mem_inter\n#check @mem_of_mem_inter_left\n#check @mem_of_mem_inter_right\n#check @mem_union_left\n#check @mem_union_right\n#check @mem_or_mem_of_mem_union\n#check @not_mem_empty\n\n\n/-\nRecall that `rw` is rewrite tactic which corresponds to the substitution.\n-/\n\nlemma subset_reflexivity : A \u2286 A := \nbegin \nrw subset_def, \nintro x, \nintro h,\nexact h, \nend   \n\nlemma subset_transitivity {h\u2081 : A \u2286 B} {h\u2082 : B \u2286 C} : A \u2286 C \n:=\nbegin\nintros x h\u2083,\nrw subset_def at h\u2081, \nrw subset_def at h\u2082,\nhave h\u2084, from h\u2081 x, \nhave h\u2085, from h\u2084 h\u2083,\nexact h\u2082 x h\u2085,\nend    \n\n-- we can combine all intros into one step using `intros` instead of multiple instances of `intro`.\n\n-- we can also combine `rw subset_def at h\u2081` and   `rw subset_def at h\u2082` together. \n\nexample (h\u2081 : A \u2286 B) (h\u2082 : B \u2286 C) : A \u2286 C \n:=\nbegin\nrw subset_def, \nintros x h\u2083,\nrw subset_def at h\u2081 h\u2082,  \nhave h\u2084, from h\u2081 x, \nhave h\u2085, from h\u2084 h\u2083,\nexact h\u2082 x h\u2085,\nend \n\n/- \nLean is smart and it lets us further simplify the proof above by deleting the calls to `rw` entirely. \nTo do this, under the hood, Lean uses something called **definitional reduction**: to make sense of the `intros` command and the anonymous constructors Lean is forced to expand the definitions automatically so that we don't have to.\n-/\n\n-- We rewrite the proof above using definitional reduction: \n\nexample (h\u2081 : A \u2286 B) (h\u2082 : B \u2286 C) : A \u2286 C \n:=\nbegin\nintros x h\u2083, \nhave h\u2084, from h\u2081 h\u2083, \nshow x \u2208 C, from h\u2082 h\u2084,\nend \n\n\n\n---------------------\n--**Intersection**--\n---------------------\n\n/-\nWe can use the more concise notation `hx.1` and `hx.2` for `and.left hx` and `and.right hx`, respectively. Below is a proof with `hx.1` and `hx.2` instead of `and.left hx` and `and.right hx`.\n-/\n\nexample (h : A \u2286 B) : A \u2229 C \u2286 B \u2229 C :=\nbegin\n  -- tactics are applied to goals\n  rw subset_def, \n  -- \u22a2 \u2200 (x : U), x \u2208 A \u2229 C \u2192 x \u2208 B \u2229 C\n  rw inter_def,\n  -- \u22a2 \u2200 (x : U), x \u2208 {a : U | a \u2208 A \u2227 a \u2208 C} \u2192 x \u2208 B \u2229 C\n  rw inter_def, \n  rw subset_def at h,\n  dsimp,\n  -- try to understand what `dsimp` does here for us\n  intros x hx, \n  have hx_B, from h x hx.1, \n  show x \u2208 B \u2227 x \u2208 C, from \u27e8hx_B, hx.2\u27e9,  \nend\n\n/-\nThe `simp` tactic uses lemmas and hypotheses to simplify the main goal target or some (non-dependent) hypotheses. It has many variants. A variant is called `dsimp` (definitional simp) and is similar to simp, except that it only uses definitional equalities.\n-/\n\n/- \n Unlike `rw`, `simp` can perform simplifications inside a universal or existential quantifier. As usual, if you step through the proof, you can see the effects of these commands.\n-/ \n\n/-\nLet's reflect on what happened in the last three steps of the proof above: we introduced `hx: x \u2208 A \u2227 x \u2208 C` then we destrctured it into `hx.1 :  x \u2208 A` and `hx.2 : x \u2208 C ` which then were used to construct a proof of `x \u2208 B \u2227 x \u2208 C`.\nThe `rintro` combines the introducing and destrcturing in one tactic. `rintros` is an alias for rintro. Look at the penultimate line of the proof below to see a working example of `rintros`.\n-/\n\nexample (h : A \u2286 B) : A \u2229 C \u2286 B \u2229 C :=\nbegin\n  -- tactics are applied to goals\n  rw subset_def, \n  -- \u22a2 \u2200 (x : U), x \u2208 A \u2229 C \u2192 x \u2208 B \u2229 C\n  rw inter_def,\n  -- \u22a2 \u2200 (x : U), x \u2208 {a : U | a \u2208 A \u2227 a \u2208 C} \u2192 x \u2208 B \u2229 C\n  rw inter_def, \n  rw subset_def at h,\n  dsimp,\n  rintros x \u27e8xa, xc\u27e9,\n  exact \u27e8h x xa, xc\u27e9,\nend\n\n\n/-\n For brevity, we could package all `rw` tactics together as follows \n-/\n\nexample (h : A \u2286 B) : A \u2229 C \u2286 B \u2229 C :=\nbegin\n  rw [subset_def, inter_def, inter_def ],   \n  rw subset_def at h,\n  dsimp,\n  -- what is dsimp doing here?\n  rintros x \u27e8xa, xc\u27e9,\n  exact \u27e8h _ xa, xc\u27e9,\nend\n\n/-\n`simp only [h\u2081 h\u2082 ... h\u2099]` is like `simp [h\u2081 h\u2082 ... h\u2099]` but does not use `[simp]` lemmas\n-/\n\n-- Yet another shorter proof\nexample (h : A \u2286 B) : A \u2229 C \u2286 B \u2229 C :=\nbegin\nsimp only [subset_def, mem_inter_eq] at * ,\nrintros x \u27e8h\u2081,h\u2082\u27e9,\nexact \u27e8h x h\u2081, h\u2082\u27e9,\nend\n\n\n---------------------\n--**Union**---------\n---------------------\n\n/-\nTo deal with unions, we can use `set.union_def` and `set.mem_union`. Since `x \u2208 s \u222a t` unfolds to `x \u2208 s \u2228 x \u2208 t`, we can also use the cases tactic to force a definitional reduction.\n-/\n\n-- fill in `sorry` below. \nexample : A \u2229 (B \u222a C) \u2286 (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\n  intros x hx,\n  cases hx.2 with hx\u2083 hx\u2084,\n  { left,\n    show x \u2208 A \u2229 B,\n    exact \u27e8hx.1, hx\u2083\u27e9 },\n  right,\n  show x \u2208 A \u2229 C,\n  exact sorry,\nend\n\n\nexample : A \u2229 (B \u222a C) \u2286 (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\nrw subset_def, \nintros x hx, \nrw union_def, \ndsimp, \nrw inter_def at hx, \ndsimp at hx, \ncases hx.2 with hx_3 hx_4, \n{ exact or.inl \u27e8hx.1, hx_3\u27e9,   },\n{exact or.inr \u27e8hx.1, hx_4\u27e9},\nend \n\n\n-- fill in `sorry` below.\nexample : A \u2229 (B \u222a C) \u2286 (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\n  rintros x \u27e8hx_A, hx_B | hx_C\u27e9,\n  { left, exact \u27e8hx_A, hx_B\u27e9 },\n  { sorry },\nend\n\n\n-- Let's prove the converse inclusion of sets: \n-- fill in `sorry` below.\nexample : (A \u2229 B) \u222a (A \u2229 C) \u2286 A \u2229 (B \u222a C):=\nsorry\n\n\n\n/- \nTo prove that two sets are equal, it suffices to show that every element of one is an element of the other. This principle is known as \u201cextensionality\u201d and, unsurprisingly, the `ext` tactic is equipped to handle it.\n-/\n\n-- To prove the operation of intersection is commutative we use the facts that the intersection is defined in term of conjunction and that conjunction is commutative. The latter was proved in the Lean Lab on propositional logic.\n\n\n\nlemma conj_comm {P Q : Prop} : P \u2227 Q \u2194 Q \u2227 P :=\nbegin\n  split, \n  { intro h,\n    cases h with hp hq,\n    show Q \u2227 P, from \u27e8hq , hp\u27e9 \n  },\n  {\n    intro h,\n    cases h with hq hp,\n    show P \u2227 Q, from \u27e8hp , hq\u27e9 \n  }, \nend\n\n-- we use the lemma above in the proof of commutativity of intersection.\n\nexample : A \u2229 B = B \u2229 A :=\nbegin\n  ext x,\n  simp only [mem_inter_eq],\n  apply conj_comm,\nend\n\n-- The commutativity of conjunction is part of the Lean library where it is called `and.comm`; we invoke it in the short proof in below:\n\nexample : A \u2229 B = B \u2229 A :=\nby ext x; simp [and.comm]\n\n\n-- challenge: fill in the `sorry` below.\nexample : A \u222a B = B \u222a A :=\nby ext x; simp sorry\n\n\n-- We showed in the lecture on sets that if we prove A \u2286 B and B \u2286 A then it follows that A = B. This idea is implemented in Lean by the the theorem `subset.antisymm`. Here is a use of it:\n\nexample (h : A \u2286 B) : A \u222a B = B\n:= \nbegin\n  apply subset.antisymm, \n  -- now we have 2 goals  A \u222a B \u2286 B and B \u2286 A \u222a B\n  {\n    rintros x (hx_A | hx_B), \n      {exact h hx_A},\n      {exact hx_B},\n  },\n  {\n    intros x hx_B,\n    dsimp, \n    exact (or.inr hx_B),\n  }, \nend \n\n-- when using `rintros`, sometimes we need to use parentheses around a disjunctive pattern `h\u2081 | h\u2082` to get Lean to parse it correctly.\n\n\nexample (h : A \u2286 B) : A \u2229 B = A\n:= \nbegin\n  sorry \nend \n\n\nexample : A \u2229 (A \u222a B) = A :=\nsorry\n\nexample : A \u222a (A \u2229 B) = A :=\nsorry\n\n\n------------------------\n--**Relative Complement**\n------------------------\n\n\n/- \nThe library also defines set difference `A \\ B` (i.e. the complement of `B` relative to `A`), where the backslash is a special unicode character entered as `\\\\`. Recall that the expression `x \u2208 A \\ B` is by definition the same as `x \u2208 A \u2227 x \u2209 B`. (The `\u2209` can be entered as `\\notin`.) \nThe operation of set difference is left-associative, that is  A \\ B \\ C reads as \n(A \\ B) \\ C. Therefore, \nx \u2208 A \\ B \\ C \u2194 (x \u2208 A \u2227 x \u2209 B) \u2227 x \u2209 C  \n-/\n\n-- fill in the sorry below:\nexample : A \\ B \\ C \u2286 A \\ (B \u222a C) :=\nbegin\n  intros x h,\n  have h\u2081 : x \u2208 A := h.1.1,\n  have h\u2082 : x \u2209 B := h.1.2,\n  have h\u2083 : x \u2209 C := h.2,\n  split,\n  -- we now have two goals: x \u2208 A and (\u03bb (a : U), a \u2209 B \u222a C) x. The latter is equivalent to x \u2209 B \u222a C. \n  { exact h\u2081 }, \n  { dsimp,\n  -- current goal: \u00ac(x \u2208 B \u2228 x \u2208 C)\n    intro h, -- x \u2208 B \u2228 x \u2208 C\n  cases h with h_B h_C,\n  { show false, from h\u2082 h_B },\n  show false, from sorry\n  },\nend\n\nexample : A \\ B \\ C \u2286 A \\ (B \u222a C) :=\nbegin\n  rintros x \u27e8\u27e8h_A, hn_B\u27e9, hn_C\u27e9,\n  use h_A,\n  -- the tactic `use` instantiate the first term in a conjunctive goal. Since we want to prove x \u2208 A \\ (B \u222a C), `use h_A` will reduce the goal to x \u2209 B \u222a C. \n  dsimp, \n  rintros (h_B | h_C); contradiction,\n  --Here we sue the `contradiction` tactic to shorten the proof by letting Lean find in the current local context two contradictory hypotheses, for instance, h_B and hn_B.\nend\n\n-- Two sets A and B are called **disjoint** if A \u2229 B = \u2205. Theorem: We can write any union of two sets as a union of two disjoint sets. First we prove two lemmas: \n\nlemma disjoint_union_of_union_1 {A B : set U } : A \u222a (B \\ A) \u2286 A \u222a B \n:= \nbegin\n  rw subset_def,  \n  dsimp,  \n  rintros x (h_A | h_B), \n  apply or.inl; exact h_A, \n  apply or.inr; exact h_B.1,\nend \n\n-- fill in the sorry below\n\nlemma disjoint_union_of_union_2 {A B : set U } :  A \u222a B \u2286 A \u222a (B \\ A)\n:= \nbegin\n  rw subset_def, \n  dsimp, \n  intros x hx, \n  cases hx, \n  { \n    exact or.inl hx\n  },\n  {\n    cases em (x \u2208 A),\n    -- the use of LEM in here makes the proof non-constructive.\n    exact or.inl h, \n    exact or.inr sorry,\n  },\nend \n\n\n\n\n/-\nThe theorem `subset.antisymm` is an alternative to using `ext`. It allows us to prove an equation A = B between sets by proving A \u2286 B and B \u2286 A.\n-/\ntheorem disjoint_union_of_union {A B : set U } : A \u222a B = A \u222a (B \\ A) \n:= \nbegin\n  apply subset.antisymm,\n  apply disjoint_union_of_union_2, \n  apply disjoint_union_of_union_1,\nend \n\n\n---------------------\n--**Disjoint unions**\n---------------------\n\n/-\nIn below we define the sets of even and odd numbers and prove that they cover all natural numbers, i.e. their union is exactly the entire set of natural numbers. The proof below used LEM but there is a better constructive proof which uses division by 2 algorithm. \n-/\n\ndef evens : set \u2115 := {n | even n}\ndef odds :  set \u2115 := {n | \u00ac even n}\n\nexample : evens \u222a odds = univ :=\nbegin\n  rw [evens, odds],\n  ext n,\n  simp,\n  apply classical.em,\nend\n\n\n/-\nThe union evens \u222a odds is indeed a disjoint union since evens \u2229 odds = \u2205. We want to prove a stronger theorem that the disjoint union of evens and odds is the whole of \u2115. \n-/\n\n\n---------------------------------------\n--**The empty set and the universal set**\n---------------------------------------\n\n/- \nThe sets `\u2205` and `univ` are defined relative to the domain of discourse. For instance if the domain of discourse is natural numbers then `\u2205 : set \u2115` but if the domain of discourse is integers then `\u2205 : set \u2124`. \n-/\n\n/-\nWe often need to indicate the type of `\u2205` and `univ` explicitly, because Lean cannot infer which ones we mean. The following examples show how Lean unfolds the last two definitions when needed. In the second one, `trivial` is the canonical proof of `true` in the library.\n-/\n\n\nexample (x : \u2115) (h : x \u2208 (\u2205 : set \u2115)) : false :=\nh\n\nexample (x : \u2115) : x \u2208 (univ : set \u2115) :=\ntrivial\n\n\n\n\n-----------------------------------\n--**Power set**\n-----------------------------------\n\ndef power_set (A : set U) : set (set U) := {B : set U | B \u2286 A}\n\nexample (A B : set U) (h : B \u2208 power_set A) : B \u2286 A :=\nh\n\n-- As the example shows, B \u2208 powerset A is then definitionally the same as B \u2286 A.\n\nexample : A \u2208 powerset (A \u222a B) :=\nbegin \nintros x _,\nshow x \u2208 A \u222a B, from or.inl \u2039x \u2208 A\u203a,\nend   \n\n\n-- powersets are part of the Lean core library. They are defined as above. Type \"\\power\" to get \ud835\udcab. \n\n#check \ud835\udcab A\n\n#check A \u2286 B\n#check \ud835\udcab A \u2286 \ud835\udcab B\n\n\n\n-- we use the lemma subset_transitivity at the beginning of the file to prove the theorem belo\ntheorem subset_relation_lifts_to_power_sets {A B : set U} : (A \u2286 B) \u2192 (\ud835\udcab A \u2286 \ud835\udcab B)  \n:= \nbegin\n intros h S hS,  \n apply subset_transitivity S A B,\n exact hS,\n exact h, \nend \n\n\n\nlemma singelton_of_element {A : set U} {x : U} : x \u2208 A \u2194  {x} \u2286 A := \nbegin\n  split, \n  { intro h,\n    intros y hy, \n    simp at hy, \n    -- what is going on here? what does simp do?\n    rw hy,\n    exact h, \n    },\n  {\n    sorry,\n  },  \nend  \n\n\ntheorem subset_transport {A B : set U} {x : U} (A \u2286 B): \n(x \u2208 A) \u2192 (x \u2208 B)\n:= \nbegin \n  intro h, \n  exact H h, \nend \n\n\n\n\n-----------------------------------\n--**Cartesian binrary product of sets**--\n-----------------------------------\n\n\n/- \nThe ordered pair of two objects a and b is denoted (a, b). We say that a is the first component and b is the second component of the pair. \n-/\n\n/-\nWe proved in class that two pairs are only equal if the first component are equal and the second components are equal. In symbols, (a, b) = (c, d) if and only if a = c and b = d.\n-/\n\n/-\nWe also defined for any given sets A and B, the cartesian product A \u00d7 B of these two sets as the set of all pairs where the first component is an element in A and the second component is an element in B. In set-builder notation this means\n`A \u00d7 B = { (a, b) | a \u2208 A \u2227 b \u2208 B }`.\n-/\n\n/- \nNote that, in contrast to intersections, unions, and (relative) complements, if `A B : set U` the set A \u00d7 B need not be of the type `set U`. However, `A \u00d7 B : set (U \u00d7 U)`. \n-/\n\n#check A \u00d7 B \n#check set A \u00d7 B\n\n#check {p : A \u00d7 B | (p.1 \u2208 A) \u2227 (p.2 \u2208 B)} \n\nexample {A B : set U} {a \u2208 A} {b \u2208 B} : \n(a,b) \u2208 A \u00d7\u02e2 B :=\nbegin\nsorry, \nend \n\n-- this is not what we are looking! Instead we use the operation `\u00d7\u02e2` to form the Cartesian binrary product of sets. Write \u00d7\u02e2 by typing \"\\times\u02e2\" and then hit tab/space.\n\n-- infix ` \u00d7\u02e2 `:72 := has_set_prod.prod\n\nnamespace set\n\n/-! ### Cartesian binary product of sets -/\n\nsection prod\nvariables {\u03b1 \u03b2 \u03b3 \u03b4 : Type*} {s s\u2081 s\u2082 : set \u03b1} {t t\u2081 t\u2082 : set \u03b2} {a : \u03b1} {b : \u03b2}\n\n/- \nThe cartesian product `A \u00d7\u02e2 B` is the set of `(a, b)`\n  such that `a \u2208 A` and `b \u2208 B`.\nIn the Lean core library this is defined as in below:\n`instance : has_set_prod (set \u03b1) (set \u03b2) (set (\u03b1 \u00d7 \u03b2)) := \u27e8\u03bb s t, {p | p.1 \u2208 s \u2227 p.2 \u2208 t}\u27e9`\n-/\n\n\n-- some useful theorems about cartesian product of sets\n#check mem_prod_eq \n#check mem_prod \n#check prod_mk_mem_set_prod_eq \n\n\n-- Let's prove that the product of any set with the empty set is empty again. \n\ntheorem product_with_empty_right {A : set U} : A \u00d7\u02e2 (\u2205 : set U)=  \u2205 \n:=\nbegin\next, \nrw mem_prod_eq,\nexact and_false _, \nend \n\n#check and_false\n#check false_and\n\n-- fill in the sorry below\ntheorem product_with_empty_left {A : set U} :  (\u2205 : set U) \u00d7\u02e2 A =  \u2205 \n:=\nbegin\next, \nrw mem_prod_eq,\nsorry, \nend \n\n\n\n\n\n\n\n#check subgroup\n\n\n\n\n\n\n\n\n", "meta": {"author": "sinhp", "repo": "ProofLab", "sha": "f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2", "save_path": "github-repos/lean/sinhp-ProofLab", "path": "github-repos/lean/sinhp-ProofLab/ProofLab-f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2/src/lectures/sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7357661312946991}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro\n-/\nimport algebra.associated linear_algebra.basic order.zorn\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [comm_ring \u03b1] {a b : \u03b1}\nopen set function lattice\n\nlocal attribute [instance] classical.prop_decidable\n\nnamespace ideal\nvariable (I : ideal \u03b1)\n\n@[extensionality] lemma ext {I J : ideal \u03b1} (h : \u2200 x, x \u2208 I \u2194 x \u2208 J) : I = J :=\nsubmodule.ext h\n\ntheorem eq_top_of_unit_mem\n  (x y : \u03b1) (hx : x \u2208 I) (h : y * x = 1) : I = \u22a4 :=\neq_top_iff.2 $ \u03bb z _, calc\n    z = z * (y * x) : by simp [h]\n  ... = (z * y) * x : eq.symm $ mul_assoc z y x\n  ... \u2208 I : I.mul_mem_left hx\n\ntheorem eq_top_of_is_unit_mem {x} (hx : x \u2208 I) (h : is_unit x) : I = \u22a4 :=\nlet \u27e8y, hy\u27e9 := is_unit_iff_exists_inv'.1 h in eq_top_of_unit_mem I x y hx hy\n\ntheorem eq_top_iff_one : I = \u22a4 \u2194 (1:\u03b1) \u2208 I :=\n\u27e8by rintro rfl; trivial,\n \u03bb h, eq_top_of_unit_mem _ _ 1 h (by simp)\u27e9\n\ntheorem ne_top_iff_one : I \u2260 \u22a4 \u2194 (1:\u03b1) \u2209 I :=\nnot_congr I.eq_top_iff_one\n\ndef span (s : set \u03b1) : ideal \u03b1 := submodule.span \u03b1 s\n\nlemma subset_span {s : set \u03b1} : s \u2286 span s := submodule.subset_span\n\nlemma span_le {s : set \u03b1} {I} : span s \u2264 I \u2194 s \u2286 I := submodule.span_le\n\nlemma span_mono {s t : set \u03b1} : s \u2286 t \u2192 span s \u2264 span t := submodule.span_mono\n\n@[simp] lemma span_eq : span (I : set \u03b1) = I := submodule.span_eq _\n\n@[simp] lemma span_singleton_one : span ({1} : set \u03b1) = \u22a4 :=\n(eq_top_iff_one _).2 $ subset_span $ mem_singleton _\n\nlemma mem_span_insert {s : set \u03b1} {x y} :\n  x \u2208 span (insert y s) \u2194 \u2203 a (z \u2208 span s), x = a * y + z := submodule.mem_span_insert\n\nlemma mem_span_insert' {s : set \u03b1} {x y} :\n  x \u2208 span (insert y s) \u2194 \u2203a, x + a * y \u2208 span s := submodule.mem_span_insert'\n\nlemma mem_span_singleton' {x y : \u03b1} :\n  x \u2208 span ({y} : set \u03b1) \u2194 \u2203 a, a * y = x := submodule.mem_span_singleton\n\nlemma mem_span_singleton {x y : \u03b1} :\n  x \u2208 span ({y} : set \u03b1) \u2194 y \u2223 x :=\nmem_span_singleton'.trans $ exists_congr $ \u03bb _, by rw [eq_comm, mul_comm]; refl\n\nlemma span_singleton_le_span_singleton {x y : \u03b1} :\n  span ({x} : set \u03b1) \u2264 span ({y} : set \u03b1) \u2194 y \u2223 x :=\nspan_le.trans $ singleton_subset_iff.trans mem_span_singleton\n\nlemma span_eq_bot {s : set \u03b1} : span s = \u22a5 \u2194 \u2200 x \u2208 s, (x:\u03b1) = 0 := submodule.span_eq_bot\n\nlemma span_singleton_eq_bot {x} : span ({x} : set \u03b1) = \u22a5 \u2194 x = 0 := submodule.span_singleton_eq_bot\n\nlemma span_singleton_eq_top {x} : span ({x} : set \u03b1) = \u22a4 \u2194 is_unit x :=\nby rw [is_unit_iff_dvd_one, \u2190 span_singleton_le_span_singleton, span_singleton_one, eq_top_iff]\n\n@[class] def is_prime (I : ideal \u03b1) : Prop :=\nI \u2260 \u22a4 \u2227 \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I\n\ntheorem is_prime.mem_or_mem {I : ideal \u03b1} (hI : I.is_prime) :\n  \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I := hI.2\n\ntheorem is_prime.mem_or_mem_of_mul_eq_zero {I : ideal \u03b1} (hI : I.is_prime)\n  {x y : \u03b1} (h : x * y = 0) : x \u2208 I \u2228 y \u2208 I :=\nhI.2 (h.symm \u25b8 I.zero_mem)\n\ntheorem is_prime.mem_of_pow_mem {I : ideal \u03b1} (hI : I.is_prime)\n  {r : \u03b1} (n : \u2115) (H : r^n \u2208 I) : r \u2208 I :=\nbegin\n  induction n with n ih,\n  { exact (mt (eq_top_iff_one _).2 hI.1).elim H },\n  exact or.cases_on (hI.mem_or_mem H) id ih\nend\n\n@[class] def zero_ne_one_of_proper {I : ideal \u03b1} (h : I \u2260 \u22a4) : (0:\u03b1) \u2260 1 :=\n\u03bb hz, I.ne_top_iff_one.1 h $ hz \u25b8 I.zero_mem\n\ntheorem span_singleton_prime {p : \u03b1} (hp : p \u2260 0) :\n  is_prime (span ({p} : set \u03b1)) \u2194 prime p :=\nby simp [is_prime, prime, span_singleton_eq_top, hp, mem_span_singleton]\n\n@[class] def is_maximal (I : ideal \u03b1) : Prop :=\nI \u2260 \u22a4 \u2227 \u2200 J, I < J \u2192 J = \u22a4\n\ntheorem is_maximal_iff {I : ideal \u03b1} : I.is_maximal \u2194\n  (1:\u03b1) \u2209 I \u2227 \u2200 (J : ideal \u03b1) x, I \u2264 J \u2192 x \u2209 I \u2192 x \u2208 J \u2192 (1:\u03b1) \u2208 J :=\nand_congr I.ne_top_iff_one $ forall_congr $ \u03bb J,\nby rw [lt_iff_le_not_le]; exact\n \u27e8\u03bb H x h hx\u2081 hx\u2082, J.eq_top_iff_one.1 $\n    H \u27e8h, not_subset.2 \u27e8_, hx\u2082, hx\u2081\u27e9\u27e9,\n  \u03bb H \u27e8h\u2081, h\u2082\u27e9, let \u27e8x, xJ, xI\u27e9 := not_subset.1 h\u2082 in\n   J.eq_top_iff_one.2 $ H x h\u2081 xI xJ\u27e9\n\ntheorem is_maximal.eq_of_le {I J : ideal \u03b1}\n  (hI : I.is_maximal) (hJ : J \u2260 \u22a4) (IJ : I \u2264 J) : I = J :=\neq_iff_le_not_lt.2 \u27e8IJ, \u03bb h, hJ (hI.2 _ h)\u27e9\n\ntheorem is_maximal.exists_inv {I : ideal \u03b1}\n  (hI : I.is_maximal) {x} (hx : x \u2209 I) : \u2203 y, y * x - 1 \u2208 I :=\nbegin\n  cases is_maximal_iff.1 hI with H\u2081 H\u2082,\n  rcases mem_span_insert'.1 (H\u2082 (span (insert x I)) x\n    (set.subset.trans (subset_insert _ _) subset_span)\n    hx (subset_span (mem_insert _ _))) with \u27e8y, hy\u27e9,\n  rw [span_eq, \u2190 neg_mem_iff, add_comm, neg_add', neg_mul_eq_neg_mul] at hy,\n  exact \u27e8-y, hy\u27e9\nend\n\ntheorem is_maximal.is_prime {I : ideal \u03b1} (H : I.is_maximal) : I.is_prime :=\n\u27e8H.1, \u03bb x y hxy, or_iff_not_imp_left.2 $ \u03bb hx, begin\n  cases H.exists_inv hx with z hz,\n  have := I.mul_mem_left hz,\n  rw [mul_sub, mul_one, mul_comm, mul_assoc] at this,\n  exact I.neg_mem_iff.1 ((I.add_mem_iff_right $ I.mul_mem_left hxy).1 this)\nend\u27e9\n\ninstance is_maximal.is_prime' (I : ideal \u03b1) : \u2200 [H : I.is_maximal], I.is_prime := is_maximal.is_prime\n\ntheorem exists_le_maximal (I : ideal \u03b1) (hI : I \u2260 \u22a4) :\n  \u2203 M : ideal \u03b1, M.is_maximal \u2227 I \u2264 M :=\nbegin\n  rcases zorn.zorn_partial_order\u2080 { J : ideal \u03b1 | J \u2260 \u22a4 } _ I hI with \u27e8M, M0, IM, h\u27e9,\n  { refine \u27e8M, \u27e8M0, \u03bb J hJ, by_contradiction $ \u03bb J0, _\u27e9, IM\u27e9,\n    cases h J J0 (le_of_lt hJ), exact lt_irrefl _ hJ },\n  { intros S SC cC I IS,\n    refine \u27e8Sup S, \u03bb H, _, \u03bb _, le_Sup\u27e9,\n    rcases submodule.mem_Sup_of_directed ((eq_top_iff_one _).1 H) I IS cC.directed_on with \u27e8J, JS, J0\u27e9,\n    exact SC JS ((eq_top_iff_one _).2 J0) }\nend\n\ndef is_coprime (x y : \u03b1) : Prop :=\nspan ({x, y} : set \u03b1) = \u22a4\n\ntheorem mem_span_pair {\u03b1} [comm_ring \u03b1] {x y z : \u03b1} :\n  z \u2208 span (insert y {x} : set \u03b1) \u2194 \u2203 a b, a * x + b * y = z :=\nbegin\n  simp only [mem_span_insert, mem_span_singleton', exists_prop],\n  split,\n  { rintros \u27e8a, b, \u27e8c, hc\u27e9, h\u27e9,\n    exact \u27e8c, a, by simp [h, hc]\u27e9 },\n  { rintro \u27e8b, c, e\u27e9, exact \u27e8c, b * x, \u27e8b, rfl\u27e9, by simp [e.symm]\u27e9 }\nend\n\ntheorem is_coprime_def {\u03b1} [comm_ring \u03b1] {x y : \u03b1} :\n  is_coprime x y \u2194 \u2200 z, \u2203 a b, a * x + b * y = z :=\nby simp [is_coprime, submodule.eq_top_iff', mem_span_pair]\n\ntheorem is_coprime_self {\u03b1} [comm_ring \u03b1] (x y : \u03b1) :\n  is_coprime x x \u2194 is_unit x :=\nby rw [\u2190 span_singleton_eq_top]; simp [is_coprime]\n\nlemma span_singleton_lt_span_singleton [integral_domain \u03b2] {x y : \u03b2} :\n  span ({x} : set \u03b2) < span ({y} : set \u03b2) \u2194 y \u2260 0 \u2227 \u2203 d : \u03b2, \u00ac is_unit d \u2227 x = y * d :=\nby rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton,\n  dvd_and_not_dvd_iff]\n\nend ideal\n\ndef nonunits (\u03b1 : Type u) [monoid \u03b1] : set \u03b1 := { x | \u00acis_unit x }\n\n@[simp] theorem mem_nonunits_iff {\u03b1} [comm_monoid \u03b1] {x} : x \u2208 nonunits \u03b1 \u2194 \u00ac is_unit x := iff.rfl\n\ntheorem mul_mem_nonunits_right {\u03b1} [comm_monoid \u03b1]\n  {x y : \u03b1} : y \u2208 nonunits \u03b1 \u2192 x * y \u2208 nonunits \u03b1 :=\nmt is_unit_of_mul_is_unit_right\n\ntheorem mul_mem_nonunits_left {\u03b1} [comm_monoid \u03b1]\n  {x y : \u03b1} : x \u2208 nonunits \u03b1 \u2192 x * y \u2208 nonunits \u03b1 :=\nmt is_unit_of_mul_is_unit_left\n\ntheorem zero_mem_nonunits {\u03b1} [semiring \u03b1] : 0 \u2208 nonunits \u03b1 \u2194 (0:\u03b1) \u2260 1 :=\nnot_congr is_unit_zero_iff\n\ntheorem one_not_mem_nonunits {\u03b1} [monoid \u03b1] : (1:\u03b1) \u2209 nonunits \u03b1 :=\nnot_not_intro is_unit_one\n\ntheorem coe_subset_nonunits {I : ideal \u03b1} (h : I \u2260 \u22a4) :\n  (I : set \u03b1) \u2286 nonunits \u03b1 :=\n\u03bb x hx hu, h $ I.eq_top_of_is_unit_mem hx hu\n\n@[class] def is_local_ring (\u03b1 : Type u) [comm_ring \u03b1] : Prop :=\n\u2203! I : ideal \u03b1, I.is_maximal\n\n@[class] def is_local_ring.zero_ne_one (h : is_local_ring \u03b1) : (0:\u03b1) \u2260 1 :=\nlet \u27e8I, \u27e8hI, _\u27e9, _\u27e9 := h in ideal.zero_ne_one_of_proper hI\n\ndef nonunits_ideal (h : is_local_ring \u03b1) : ideal \u03b1 :=\n{ carrier := nonunits \u03b1,\n  zero := zero_mem_nonunits.2 h.zero_ne_one,\n  add := begin\n    rcases id h with \u27e8M, mM, hM\u27e9,\n    have : \u2200 x \u2208 nonunits \u03b1, x \u2208 M,\n    { intros x hx,\n      rcases (ideal.span {x} : ideal \u03b1).exists_le_maximal _ with \u27e8N, mN, hN\u27e9,\n      { cases hM N mN,\n        rwa [ideal.span_le, singleton_subset_iff] at hN },\n      { exact mt ideal.span_singleton_eq_top.1 hx } },\n    intros x y hx hy,\n    exact coe_subset_nonunits mM.1 (M.add_mem (this _ hx) (this _ hy))\n  end,\n  smul := \u03bb a x, mul_mem_nonunits_right }\n\n@[simp] theorem mem_nonunits_ideal (h : is_local_ring \u03b1) {x} :\n  x \u2208 nonunits_ideal h \u2194 x \u2208 nonunits \u03b1 := iff.rfl\n\ntheorem local_of_nonunits_ideal (hnze : (0:\u03b1) \u2260 1)\n  (h : \u2200 x y \u2208 nonunits \u03b1, x + y \u2208 nonunits \u03b1) : is_local_ring \u03b1 :=\nbegin\n  letI NU : ideal \u03b1 := \u27e8nonunits \u03b1,\n    zero_mem_nonunits.2 hnze, h, \u03bb a x, mul_mem_nonunits_right\u27e9,\n  have NU1 := NU.ne_top_iff_one.2 one_not_mem_nonunits,\n  exact \u27e8NU, \u27e8NU1,\n    \u03bb J hJ, not_not.1 $ \u03bb J0, not_le_of_gt hJ (coe_subset_nonunits J0)\u27e9,\n    \u03bb J mJ, mJ.eq_of_le NU1 (coe_subset_nonunits mJ.1)\u27e9,\nend\n\nnamespace ideal\nopen ideal\n\ndef quotient (I : ideal \u03b1) := I.quotient\n\nnamespace quotient\nvariables {I : ideal \u03b1} {x y : \u03b1}\ndef mk (I : ideal \u03b1) (a : \u03b1) : I.quotient := submodule.quotient.mk a\n\nprotected theorem eq : mk I x = mk I y \u2194 x - y \u2208 I := submodule.quotient.eq I\n\ninstance (I : ideal \u03b1) : has_one I.quotient := \u27e8mk I 1\u27e9\n\n@[simp] lemma mk_one (I : ideal \u03b1) : mk I 1 = 1 := rfl\n\ninstance (I : ideal \u03b1) : has_mul I.quotient :=\n\u27e8\u03bb a b, quotient.lift_on\u2082' a b (\u03bb a b, mk I (a * b)) $\n \u03bb a\u2081 a\u2082 b\u2081 b\u2082 h\u2081 h\u2082, quot.sound $ begin\n  refine calc a\u2081 * a\u2082 - b\u2081 * b\u2082 = a\u2082 * (a\u2081 - b\u2081) + (a\u2082 - b\u2082) * b\u2081 : _\n  ... \u2208 I : I.add_mem (I.mul_mem_left h\u2081) (I.mul_mem_right h\u2082),\n  rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b\u2081]\n end\u27e9\n\n@[simp] theorem mk_mul : mk I (x * y) = mk I x * mk I y := rfl\n\ninstance (I : ideal \u03b1) : comm_ring I.quotient :=\n{ mul := (*),\n  one := 1,\n  mul_assoc := \u03bb a b c, quotient.induction_on\u2083' a b c $\n    \u03bb a b c, congr_arg (mk _) (mul_assoc a b c),\n  mul_comm := \u03bb a b, quotient.induction_on\u2082' a b $\n    \u03bb a b, congr_arg (mk _) (mul_comm a b),\n  one_mul := \u03bb a, quotient.induction_on' a $\n    \u03bb a, congr_arg (mk _) (one_mul a),\n  mul_one := \u03bb a, quotient.induction_on' a $\n    \u03bb a, congr_arg (mk _) (mul_one a),\n  left_distrib := \u03bb a b c, quotient.induction_on\u2083' a b c $\n    \u03bb a b c, congr_arg (mk _) (left_distrib a b c),\n  right_distrib := \u03bb a b c, quotient.induction_on\u2083' a b c $\n    \u03bb a b c, congr_arg (mk _) (right_distrib a b c),\n  ..submodule.quotient.add_comm_group I }\n\ninstance is_ring_hom_mk (I : ideal \u03b1) : is_ring_hom (mk I) :=\n\u27e8rfl, \u03bb _ _, rfl, \u03bb _ _, rfl\u27e9\n\ndef map_mk (I J : ideal \u03b1) : ideal I.quotient :=\n{ carrier := mk I '' J,\n  zero := \u27e80, J.zero_mem, rfl\u27e9,\n  add := by rintro _ _ \u27e8x, hx, rfl\u27e9 \u27e8y, hy, rfl\u27e9;\n    exact \u27e8x + y, J.add_mem hx hy, rfl\u27e9,\n  smul := by rintro \u27e8c\u27e9 _ \u27e8x, hx, rfl\u27e9;\n    exact \u27e8c * x, J.mul_mem_left hx, rfl\u27e9 }\n\n@[simp] lemma mk_zero (I : ideal \u03b1) : mk I 0 = 0 := rfl\n@[simp] lemma mk_add (I : ideal \u03b1) (a b : \u03b1) : mk I (a + b) = mk I a + mk I b := rfl\n@[simp] lemma mk_neg (I : ideal \u03b1) (a : \u03b1) : mk I (-a : \u03b1) = -mk I a := rfl\n@[simp] lemma mk_sub (I : ideal \u03b1) (a b : \u03b1) : mk I (a - b : \u03b1) = mk I a - mk I b := rfl\n@[simp] lemma mk_pow (I : ideal \u03b1) (a : \u03b1) (n : \u2115) : mk I (a ^ n : \u03b1) = mk I a ^ n :=\nby induction n; simp [*, pow_succ]\n\nlemma eq_zero_iff_mem {I : ideal \u03b1} : mk I a = 0 \u2194 a \u2208 I :=\nby conv {to_rhs, rw \u2190 sub_zero a }; exact quotient.eq'\n\ntheorem zero_eq_one_iff {I : ideal \u03b1} : (0 : I.quotient) = 1 \u2194 I = \u22a4 :=\neq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm\n\ntheorem zero_ne_one_iff {I : ideal \u03b1} : (0 : I.quotient) \u2260 1 \u2194 I \u2260 \u22a4 :=\nnot_congr zero_eq_one_iff\n\nprotected def nonzero_comm_ring {I : ideal \u03b1} (hI : I \u2260 \u22a4) : nonzero_comm_ring I.quotient :=\n{ zero_ne_one := zero_ne_one_iff.2 hI, ..quotient.comm_ring I }\n\ninstance (I : ideal \u03b1) [hI : I.is_prime] : integral_domain I.quotient :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero := \u03bb a b,\n    quotient.induction_on\u2082' a b $ \u03bb a b hab,\n      (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim\n        (or.inl \u2218 eq_zero_iff_mem.2)\n        (or.inr \u2218 eq_zero_iff_mem.2),\n  ..quotient.nonzero_comm_ring hI.1 }\n\nlemma exists_inv {I : ideal \u03b1} [hI : I.is_maximal] :\n \u2200 {a : I.quotient}, a \u2260 0 \u2192 \u2203 b : I.quotient, a * b = 1 :=\nbegin\n  rintro \u27e8a\u27e9 h,\n  cases hI.exists_inv (mt eq_zero_iff_mem.2 h) with b hb,\n  rw [mul_comm] at hb,\n  exact \u27e8mk _ b, quot.sound hb\u27e9\nend\n\n/-- quotient by maximal ideal is a field. def rather than instance, since users will have\ncomputable inverses in some applications -/\nprotected noncomputable def field (I : ideal \u03b1) [hI : I.is_maximal] : discrete_field I.quotient :=\n{ inv := \u03bb a, if ha : a = 0 then 0 else classical.some (exists_inv ha),\n  mul_inv_cancel := \u03bb a (ha : a \u2260 0), show a * dite _ _ _ = _,\n    by rw dif_neg ha;\n    exact classical.some_spec (exists_inv ha),\n  inv_mul_cancel := \u03bb a (ha : a \u2260 0), show dite _ _ _ * a = _,\n    by rw [mul_comm, dif_neg ha];\n    exact classical.some_spec (exists_inv ha),\n  inv_zero := dif_pos rfl,\n  has_decidable_eq := classical.dec_eq _,\n  ..quotient.integral_domain I }\n\nvariable [comm_ring \u03b2]\n\ndef lift (S : ideal \u03b1) (f : \u03b1 \u2192 \u03b2) [is_ring_hom f] (H : \u2200 (a : \u03b1), a \u2208 S \u2192 f a = 0) :\n  quotient S \u2192 \u03b2 :=\n\u03bb x, quotient.lift_on' x f $ \u03bb (a b) (h : _ \u2208 _),\neq_of_sub_eq_zero (by simpa only [is_ring_hom.map_sub f] using H _ h)\n\nvariables {S : ideal \u03b1} {f : \u03b1 \u2192 \u03b2} [is_ring_hom f] {H : \u2200 (a : \u03b1), a \u2208 S \u2192 f a = 0}\n\n@[simp] lemma lift_mk : lift S f H (mk S a) = f a := rfl\n\ninstance : is_ring_hom (lift S f H) :=\n{ map_one := by show lift S f H (mk S 1) = 1; simp [is_ring_hom.map_one f, - mk_one],\n  map_add := \u03bb a\u2081 a\u2082, quotient.induction_on\u2082' a\u2081 a\u2082 $ \u03bb a\u2081 a\u2082, begin\n    show lift S f H (mk S a\u2081 + mk S a\u2082) = lift S f H (mk S a\u2081) + lift S f H (mk S a\u2082),\n    have := ideal.quotient.is_ring_hom_mk S,\n    rw \u2190 this.map_add,\n    show lift S f H (mk S (a\u2081 + a\u2082)) = lift S f H (mk S a\u2081) + lift S f H (mk S a\u2082),\n    simp only [lift_mk, is_ring_hom.map_add f],\n  end,\n  map_mul := \u03bb a\u2081 a\u2082, quotient.induction_on\u2082' a\u2081 a\u2082 $ \u03bb a\u2081 a\u2082, begin\n    show lift S f H (mk S a\u2081 * mk S a\u2082) = lift S f H (mk S a\u2081) * lift S f H (mk S a\u2082),\n    have := ideal.quotient.is_ring_hom_mk S,\n    rw \u2190 this.map_mul,\n    show lift S f H (mk S (a\u2081 * a\u2082)) = lift S f H (mk S a\u2081) * lift S f H (mk S a\u2082),\n    simp only [lift_mk, is_ring_hom.map_mul f],\n  end }\n\nend quotient\nend ideal\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/ring_theory/ideals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7357661125819269}}
{"text": "open Std\nopen Lean\n\ninductive BoolExpr where\n  | var (name : String)\n  | val (b : Bool)\n  | or  (p q : BoolExpr)\n  | not (p : BoolExpr)\n  deriving Repr, BEq, DecidableEq\n\ndef BoolExpr.isValue : BoolExpr \u2192 Bool\n  | val _ => true\n  | _     => false\n\ninstance : Inhabited BoolExpr where\n  default := BoolExpr.val false\n\nnamespace BoolExpr\n\nderiving instance DecidableEq for BoolExpr\n\n#eval decide (BoolExpr.val true = BoolExpr.val false)\n\n#check (a b : BoolExpr) \u2192 Decidable (a = b)\n\nabbrev Context := AssocList String Bool\n\ndef denote (ctx : Context) : BoolExpr \u2192 Bool\n  | BoolExpr.or p q => denote ctx p || denote ctx q\n  | BoolExpr.not p  => !denote ctx p\n  | BoolExpr.val b => b\n  | BoolExpr.var x => if let some b := ctx.find? x then b else false\n\ndef simplify : BoolExpr \u2192 BoolExpr\n  | or p q => mkOr (simplify p) (simplify q)\n  | not p  => mkNot (simplify p)\n  | e      => e\nwhere\n  mkOr : BoolExpr \u2192 BoolExpr \u2192 BoolExpr\n    | p, val true   => val true\n    | p, val false  => p\n    | val true, p   => val true\n    | val false, p  => p\n    | p, q          => or p q\n\n  mkNot : BoolExpr \u2192 BoolExpr\n    | val b => val (!b)\n    | p     => not p\n\n@[simp] theorem denote_not_Eq (ctx : Context) (p : BoolExpr) : denote ctx (not p) = !denote ctx p := rfl\n@[simp] theorem denote_or_Eq (ctx : Context) (p q : BoolExpr) : denote ctx (or p q) = (denote ctx p || denote ctx q) := rfl\n@[simp] theorem denote_val_Eq (ctx : Context) (b : Bool) : denote ctx (val b) = b := rfl\n\n@[simp] theorem denote_mkNot_Eq (ctx : Context) (p : BoolExpr) : denote ctx (simplify.mkNot p) = denote ctx (not p) := by\n  cases p <;> rfl\n@[simp] theorem mkOr_p_true (p : BoolExpr) : simplify.mkOr p (val true) = val true := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n@[simp] theorem mkOr_p_false (p : BoolExpr) : simplify.mkOr p (val false) = p := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n@[simp] theorem mkOr_true_p (p : BoolExpr) : simplify.mkOr (val true) p = val true := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n@[simp] theorem mkOr_false_p (p : BoolExpr) : simplify.mkOr (val false) p = p := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n\n@[simp] theorem denote_mkOr (ctx : Context) (p q : BoolExpr) : denote ctx (simplify.mkOr p q) = denote ctx (or p q) := by\n  cases p with\n  | val x => cases q with\n    | val y => cases x <;> cases y <;> simp\n    | _     => cases x <;> simp\n  | _ => cases q with\n    | val y => cases y <;> simp\n    | _     => rfl\n\n@[simp] theorem simplify_not (p : BoolExpr) : simplify (not p) = simplify.mkNot (simplify p) := rfl\n@[simp] theorem simplify_or (p q : BoolExpr) : simplify (or p q) = simplify.mkOr (simplify p) (simplify q) := rfl\n\ndef denote_simplify_eq (ctx : Context) (b : BoolExpr) : denote ctx (simplify b) = denote ctx b :=\n  by induction b with\n  | or p q ih\u2081 ih\u2082 => simp [ih\u2081, ih\u2082]\n  | not p ih       => simp [ih]\n  | _              => rfl\n\nsyntax \"`[BExpr|\" term \"]\" : term\n\nmacro_rules\n | `(`[BExpr| true])     => `(val true)\n | `(`[BExpr| false])    => `(val false)\n | `(`[BExpr| $x:ident]) => `(var $(quote x.getId.toString))\n | `(`[BExpr| $p \u2228 $q])  => `(or `[BExpr| $p] `[BExpr| $q])\n | `(`[BExpr| \u00ac $p])     => `(not `[BExpr| $p])\n\n#check `[BExpr| \u00ac p \u2228 q]\n\nsyntax entry := ident \" \u21a6 \" term:max\nsyntax entry,* \"\u22a2\" term : term\n\nmacro_rules\n  | `( $[$xs \u21a6 $vs],* \u22a2 $p) =>\n    let xs := xs.map fun x => quote x.getId.toString\n    `(denote (List.toAssocList [$[($xs, $vs)],*]) `[BExpr| $p])\n\n#check b \u21a6 true \u22a2 b \u2228 b\n#eval  a \u21a6 false, b \u21a6 false \u22a2 b \u2228 a\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/doc/BoolExpr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7357661079037336}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth, Yury Kudryashov\n-/\nimport topology.algebra.order.basic\n\n/-!\n# Bounded monotone sequences converge\n\nIn this file we prove a few theorems of the form \u201cif the range of a monotone function `f : \u03b9 \u2192 \u03b1`\nadmits a least upper bound `a`, then `f x` tends to `a` as `x \u2192 \u221e`\u201d, as well as version of this\nstatement for (conditionally) complete lattices that use `\u2a06 x, f x` instead of `is_lub`.\n\nThese theorems work for linear orders with order topologies as well as their products (both in terms\nof `prod` and in terms of function types). In order to reduce code duplication, we introduce two\ntypeclasses (one for the property formulated above and one for the dual property), prove theorems\nassuming one of these typeclasses, and provide instances for linear orders and their products.\n\nWe also prove some \"inverse\" results: if `f n` is a monotone sequence and `a` is its limit,\nthen `f n \u2264 a` for all `n`.\n\n## Tags\n\nmonotone convergence\n-/\n\nopen filter set function\nopen_locale filter topological_space classical\n\nvariables {\u03b1 \u03b2 : Type*}\n\n/-- We say that `\u03b1` is a `Sup_convergence_class` if the following holds. Let `f : \u03b9 \u2192 \u03b1` be a\nmonotone function, let `a : \u03b1` be a least upper bound of `set.range f`. Then `f x` tends to `\ud835\udcdd a` as\n`x \u2192 \u221e` (formally, at the filter `filter.at_top`). We require this for `\u03b9 = (s : set \u03b1)`, `f = coe`\nin the definition, then prove it for any `f` in `tendsto_at_top_is_lub`.\n\nThis property holds for linear orders with order topology as well as their products. -/\nclass Sup_convergence_class (\u03b1 : Type*) [preorder \u03b1] [topological_space \u03b1] : Prop :=\n(tendsto_coe_at_top_is_lub : \u2200 (a : \u03b1) (s : set \u03b1), is_lub s a \u2192 tendsto (coe : s \u2192 \u03b1) at_top (\ud835\udcdd a))\n\n/-- We say that `\u03b1` is an `Inf_convergence_class` if the following holds. Let `f : \u03b9 \u2192 \u03b1` be a\nmonotone function, let `a : \u03b1` be a greatest lower bound of `set.range f`. Then `f x` tends to `\ud835\udcdd a`\nas `x \u2192 -\u221e` (formally, at the filter `filter.at_bot`). We require this for `\u03b9 = (s : set \u03b1)`,\n`f = coe` in the definition, then prove it for any `f` in `tendsto_at_bot_is_glb`.\n\nThis property holds for linear orders with order topology as well as their products. -/\nclass Inf_convergence_class (\u03b1 : Type*) [preorder \u03b1] [topological_space \u03b1] : Prop :=\n(tendsto_coe_at_bot_is_glb : \u2200 (a : \u03b1) (s : set \u03b1), is_glb s a \u2192 tendsto (coe : s \u2192 \u03b1) at_bot (\ud835\udcdd a))\n\ninstance order_dual.Sup_convergence_class [preorder \u03b1] [topological_space \u03b1]\n  [Inf_convergence_class \u03b1] : Sup_convergence_class (order_dual \u03b1) :=\n\u27e8\u2039Inf_convergence_class \u03b1\u203a.1\u27e9\n\ninstance order_dual.Inf_convergence_class [preorder \u03b1] [topological_space \u03b1]\n  [Sup_convergence_class \u03b1] : Inf_convergence_class (order_dual \u03b1) :=\n\u27e8\u2039Sup_convergence_class \u03b1\u203a.1\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_order.Sup_convergence_class [topological_space \u03b1] [linear_order \u03b1]\n  [order_topology \u03b1] : Sup_convergence_class \u03b1 :=\nbegin\n  refine \u27e8\u03bb a s ha, tendsto_order.2 \u27e8\u03bb b hb, _, \u03bb b hb, _\u27e9\u27e9,\n  { rcases ha.exists_between hb with \u27e8c, hcs, bc, bca\u27e9,\n    lift c to s using hcs,\n    refine (eventually_ge_at_top c).mono (\u03bb x hx, bc.trans_le hx) },\n  { exact eventually_of_forall (\u03bb x, (ha.1 x.2).trans_lt hb) }\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_order.Inf_convergence_class [topological_space \u03b1] [linear_order \u03b1]\n  [order_topology \u03b1] : Inf_convergence_class \u03b1 :=\nshow Inf_convergence_class (order_dual $ order_dual \u03b1), from order_dual.Inf_convergence_class\n\nsection\n\nvariables {\u03b9 : Type*} [preorder \u03b9] [topological_space \u03b1]\n\nsection is_lub\n\nvariables [preorder \u03b1] [Sup_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_top_is_lub (h_mono : monotone f) (ha : is_lub (set.range f) a) :\n  tendsto f at_top (\ud835\udcdd a) :=\nbegin\n  suffices : tendsto (range_factorization f) at_top at_top,\n    from (Sup_convergence_class.tendsto_coe_at_top_is_lub _ _ ha).comp this,\n  exact h_mono.range_factorization.tendsto_at_top_at_top (\u03bb b, b.2.imp $ \u03bb a ha, ha.ge)\nend\n\nlemma tendsto_at_bot_is_lub (h_anti : antitone f)\n  (ha : is_lub (set.range f) a) : tendsto f at_bot (\ud835\udcdd a) :=\n@tendsto_at_top_is_lub \u03b1 (order_dual \u03b9) _ _ _ _ f a h_anti.dual ha\n\nend is_lub\n\nsection is_glb\n\nvariables [preorder \u03b1] [Inf_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_bot_is_glb (h_mono : monotone f) (ha : is_glb (set.range f) a) :\n  tendsto f at_bot (\ud835\udcdd a) :=\n@tendsto_at_top_is_lub (order_dual \u03b1) (order_dual \u03b9) _ _ _ _ f a h_mono.dual ha\n\nlemma tendsto_at_top_is_glb (h_anti : antitone f)\n  (ha : is_glb (set.range f) a) :\n  tendsto f at_top (\ud835\udcdd a) :=\n@tendsto_at_top_is_lub (order_dual \u03b1) \u03b9 _ _ _ _ f a h_anti ha\n\nend is_glb\n\nsection csupr\n\nvariables [conditionally_complete_lattice \u03b1] [Sup_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_top_csupr (h_mono : monotone f) (hbdd : bdd_above $ range f) :\n  tendsto f at_top (\ud835\udcdd (\u2a06i, f i)) :=\nbegin\n  casesI is_empty_or_nonempty \u03b9,\n  exacts [tendsto_of_is_empty, tendsto_at_top_is_lub h_mono (is_lub_csupr hbdd)]\nend\n\nlemma tendsto_at_bot_csupr (h_anti : antitone f)\n  (hbdd : bdd_above $ range f) :\n  tendsto f at_bot (\ud835\udcdd (\u2a06i, f i)) :=\n@tendsto_at_top_csupr \u03b1 (order_dual \u03b9) _ _ _ _ _ h_anti.dual hbdd\n\nend csupr\n\nsection cinfi\n\nvariables [conditionally_complete_lattice \u03b1] [Inf_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_bot_cinfi (h_mono : monotone f) (hbdd : bdd_below $ range f) :\n  tendsto f at_bot (\ud835\udcdd (\u2a05i, f i)) :=\n@tendsto_at_top_csupr (order_dual \u03b1) (order_dual \u03b9) _ _ _ _ _ h_mono.dual hbdd\n\nlemma tendsto_at_top_cinfi (h_anti : antitone f)\n  (hbdd : bdd_below $ range f) :\n  tendsto f at_top (\ud835\udcdd (\u2a05i, f i)) :=\n@tendsto_at_top_csupr (order_dual \u03b1) \u03b9 _ _ _ _ _ h_anti hbdd\n\nend cinfi\n\nsection supr\n\nvariables [complete_lattice \u03b1] [Sup_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_top_supr (h_mono : monotone f) : tendsto f at_top (\ud835\udcdd (\u2a06i, f i)) :=\ntendsto_at_top_csupr h_mono (order_top.bdd_above _)\n\nlemma tendsto_at_bot_supr (h_anti : antitone f) :\n  tendsto f at_bot (\ud835\udcdd (\u2a06i, f i)) :=\ntendsto_at_bot_csupr h_anti (order_top.bdd_above _)\n\nend supr\n\nsection infi\n\nvariables [complete_lattice \u03b1] [Inf_convergence_class \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\nlemma tendsto_at_bot_infi (h_mono : monotone f) : tendsto f at_bot (\ud835\udcdd (\u2a05i, f i)) :=\ntendsto_at_bot_cinfi h_mono (order_bot.bdd_below _)\n\nlemma tendsto_at_top_infi (h_anti : antitone f) :\n  tendsto f at_top (\ud835\udcdd (\u2a05i, f i)) :=\ntendsto_at_top_cinfi h_anti (order_bot.bdd_below _)\n\nend infi\n\nend\n\ninstance [preorder \u03b1] [preorder \u03b2] [topological_space \u03b1] [topological_space \u03b2]\n  [Sup_convergence_class \u03b1] [Sup_convergence_class \u03b2] : Sup_convergence_class (\u03b1 \u00d7 \u03b2) :=\nbegin\n  constructor,\n  rintro \u27e8a, b\u27e9 s h,\n  rw [is_lub_prod, \u2190 range_restrict, \u2190 range_restrict] at h,\n  have A : tendsto (\u03bb x : s, (x : \u03b1 \u00d7 \u03b2).1) at_top (\ud835\udcdd a),\n    from tendsto_at_top_is_lub (monotone_fst.restrict s) h.1,\n  have B : tendsto (\u03bb x : s, (x : \u03b1 \u00d7 \u03b2).2) at_top (\ud835\udcdd b),\n    from tendsto_at_top_is_lub (monotone_snd.restrict s) h.2,\n  convert A.prod_mk_nhds B,\n  ext1 \u27e8\u27e8x, y\u27e9, h\u27e9, refl\nend\n\ninstance [preorder \u03b1] [preorder \u03b2] [topological_space \u03b1] [topological_space \u03b2]\n  [Inf_convergence_class \u03b1] [Inf_convergence_class \u03b2] : Inf_convergence_class (\u03b1 \u00d7 \u03b2) :=\nshow Inf_convergence_class (order_dual $ (order_dual \u03b1 \u00d7 order_dual \u03b2)),\n  from order_dual.Inf_convergence_class\n\ninstance {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, topological_space (\u03b1 i)]\n  [\u03a0 i, Sup_convergence_class (\u03b1 i)] : Sup_convergence_class (\u03a0 i, \u03b1 i) :=\nbegin\n  refine \u27e8\u03bb f s h, _\u27e9,\n  simp only [is_lub_pi, \u2190 range_restrict] at h,\n  exact tendsto_pi_nhds.2 (\u03bb i, tendsto_at_top_is_lub ((monotone_eval _).restrict _) (h i))\nend\n\ninstance {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, topological_space (\u03b1 i)]\n  [\u03a0 i, Inf_convergence_class (\u03b1 i)] : Inf_convergence_class (\u03a0 i, \u03b1 i) :=\nshow Inf_convergence_class (order_dual $ \u03a0 i, order_dual (\u03b1 i)),\n  from order_dual.Inf_convergence_class\n\ninstance pi.Sup_convergence_class' {\u03b9 : Type*} [preorder \u03b1] [topological_space \u03b1]\n  [Sup_convergence_class \u03b1] : Sup_convergence_class (\u03b9 \u2192 \u03b1) :=\npi.Sup_convergence_class\n\ninstance pi.Inf_convergence_class' {\u03b9 : Type*} [preorder \u03b1] [topological_space \u03b1]\n  [Inf_convergence_class \u03b1] : Inf_convergence_class (\u03b9 \u2192 \u03b1) :=\npi.Inf_convergence_class\n\nlemma tendsto_of_monotone {\u03b9 \u03b1 : Type*} [preorder \u03b9] [topological_space \u03b1]\n  [conditionally_complete_linear_order \u03b1] [order_topology \u03b1] {f : \u03b9 \u2192 \u03b1} (h_mono : monotone f) :\n  tendsto f at_top at_top \u2228 (\u2203 l, tendsto f at_top (\ud835\udcdd l)) :=\nif H : bdd_above (range f) then or.inr \u27e8_, tendsto_at_top_csupr h_mono H\u27e9\nelse or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H\n\nlemma tendsto_iff_tendsto_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type*} [semilattice_sup \u03b9\u2081] [preorder \u03b9\u2082]\n  [nonempty \u03b9\u2081] [topological_space \u03b1] [conditionally_complete_linear_order \u03b1] [order_topology \u03b1]\n  [no_max_order \u03b1] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} {l : \u03b1} (hf : monotone f)\n  (hg : tendsto \u03c6 at_top at_top) :\n  tendsto f at_top (\ud835\udcdd l) \u2194 tendsto (f \u2218 \u03c6) at_top (\ud835\udcdd l) :=\nbegin\n  split; intro h,\n  { exact h.comp hg },\n  { rcases tendsto_of_monotone hf with h' | \u27e8l', hl'\u27e9,\n    { exact (not_tendsto_at_top_of_tendsto_nhds h (h'.comp hg)).elim },\n    { rwa tendsto_nhds_unique h (hl'.comp hg) } }\nend\n\n/-! The next family of results, such as `is_lub_of_tendsto_at_top` and `supr_eq_of_tendsto`, are\nconverses to the standard fact that bounded monotone functions converge. They state, that if a\nmonotone function `f` tends to `a` along `filter.at_top`, then that value `a` is a least upper bound\nfor the range of `f`.\n\nRelated theorems above (`is_lub.is_lub_of_tendsto`, `is_glb.is_glb_of_tendsto` etc) cover the case\nwhen `f x` tends to `a` as `x` tends to some point `b` in the domain. -/\n\nlemma monotone.ge_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) (b : \u03b2) :\n  f b \u2264 a :=\nbegin\n  haveI : nonempty \u03b2 := nonempty.intro b,\n  exact ge_of_tendsto ha ((eventually_ge_at_top b).mono (\u03bb _ hxy, hf hxy))\nend\n\nlemma monotone.le_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) (b : \u03b2) :\n  a \u2264 f b :=\nhf.dual.ge_of_tendsto ha b\n\nlemma antitone.le_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) (b : \u03b2) :\n  a \u2264 f b :=\nhf.dual_right.ge_of_tendsto ha b\n\nlemma antitone.ge_of_tendsto [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) (b : \u03b2) :\n  f b \u2264 a :=\nhf.dual_right.le_of_tendsto ha b\n\nlemma is_lub_of_tendsto_at_top [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) :\n  is_lub (set.range f) a :=\nbegin\n  split,\n  { rintros _ \u27e8b, rfl\u27e9,\n    exact hf.ge_of_tendsto ha b },\n  { exact \u03bb _ hb, le_of_tendsto' ha (\u03bb x, hb (set.mem_range_self x)) }\nend\n\nlemma is_glb_of_tendsto_at_bot [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) :\n  is_glb (set.range f) a :=\n@is_lub_of_tendsto_at_top (order_dual \u03b1) (order_dual \u03b2) _ _ _ _ _ _ _ hf.dual ha\n\nlemma is_lub_of_tendsto_at_bot [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_bot (\ud835\udcdd a)) :\n  is_lub (set.range f) a :=\n@is_lub_of_tendsto_at_top \u03b1 (order_dual \u03b2)  _ _ _ _ _ _ _ hf.dual_left ha\n\nlemma is_glb_of_tendsto_at_top [topological_space \u03b1] [preorder \u03b1] [order_closed_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f)\n  (ha : tendsto f at_top (\ud835\udcdd a)) :\n  is_glb (set.range f) a :=\n@is_glb_of_tendsto_at_bot \u03b1 (order_dual \u03b2)  _ _ _ _ _ _ _ hf.dual_left ha\n\nlemma supr_eq_of_tendsto {\u03b1 \u03b2} [topological_space \u03b1] [complete_linear_order \u03b1] [order_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f) :\n  tendsto f at_top (\ud835\udcdd a) \u2192 supr f = a :=\ntendsto_nhds_unique (tendsto_at_top_supr hf)\n\nlemma infi_eq_of_tendsto {\u03b1} [topological_space \u03b1] [complete_linear_order \u03b1] [order_topology \u03b1]\n  [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : antitone f) :\n  tendsto f at_top (\ud835\udcdd a) \u2192 infi f = a :=\ntendsto_nhds_unique (tendsto_at_top_infi hf)\n\nlemma supr_eq_supr_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type*} [preorder \u03b9\u2082] [complete_lattice \u03b1]\n  {l : filter \u03b9\u2081} [l.ne_bot] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} (hf : monotone f)\n  (h\u03c6 : tendsto \u03c6 l at_top) :\n  (\u2a06 i, f i) = (\u2a06 i, f (\u03c6 i)) :=\nle_antisymm\n  (supr_mono' $ \u03bb i, exists_imp_exists (\u03bb j (hj : i \u2264 \u03c6 j), hf hj)\n    (h\u03c6.eventually $ eventually_ge_at_top i).exists)\n  (supr_mono' $ \u03bb i, \u27e8\u03c6 i, le_rfl\u27e9)\n\nlemma infi_eq_infi_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type*} [preorder \u03b9\u2082] [complete_lattice \u03b1]\n  {l : filter \u03b9\u2081} [l.ne_bot] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} (hf : monotone f)\n  (h\u03c6 : tendsto \u03c6 l at_bot) :\n  (\u2a05 i, f i) = (\u2a05 i, f (\u03c6 i)) :=\nsupr_eq_supr_subseq_of_monotone hf.dual h\u03c6\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/topology/algebra/order/monotone_convergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7357442039701477}}
{"text": "/-\nCopyright (c) 2017 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis, Keeley Hoek\n-/\nimport tactic.apply_fun\nimport data.nat.cast\nimport order.rel_iso\nimport tactic.localized\n\n/-!\n# The finite type with `n` elements\n\n`fin n` is the type whose elements are natural numbers smaller than `n`.\nThis file expands on the development in the core library.\n\n## Main definitions\n\n### Induction principles\n\n* `fin_zero_elim` : Elimination principle for the empty set `fin 0`, generalizes `fin.elim0`.\n* `fin.succ_rec` : Define `C n i` by induction on  `i : fin n` interpreted\n  as `(0 : fin (n - i)).succ.succ\u2026`. This function has two arguments: `H0 n` defines\n  `0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element\n  of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple.\n* `fin.succ_rec_on` : same as `fin.succ_rec` but `i : fin n` is the first argument;\n* `fin.induction` : Define `C i` by induction on `i : fin (n + 1)`, separating into the\n  `nat`-like base cases of `C 0` and `C (i.succ)`.\n* `fin.induction_on` : same as `fin.induction` but with `i : fin (n + 1)` as the first argument.\n* `fin.cases` : define `f : \u03a0 i : fin n.succ, C i` by separately handling the cases `i = 0` and\n  `i = fin.succ j`, `j : fin n`, defined using `fin.induction`.\n* `fin.reverse_induction`: reverse induction on `i : fin (n + 1)`; given `C (fin.last n)` and\n  `\u2200 i : fin n, C (fin.succ i) \u2192 C (fin.cast_succ i)`, constructs all values `C i` by going down;\n* `fin.last_cases`: define `f : \u03a0 i, fin (n + 1), C i` by separately handling the cases\n  `i = fin.last n` and `i = fin.cast_succ j`, a special case of `fin.reverse_induction`;\n* `fin.add_cases`: define a function on `fin (m + n)` by separately handling the cases\n  `fin.cast_add n i` and `fin.nat_add m i`;\n* `fin.succ_above_cases`: given `i : fin (n + 1)`, define a function on `fin (n + 1)` by separately\n  handling the cases `j = i` and `j = fin.succ_above i k`, same as `fin.insert_nth` but marked\n  as eliminator and works for `Sort*`.\n\n### Order embeddings and an order isomorphism\n\n* `fin.coe_embedding` : coercion to natural numbers as an `order_embedding`;\n* `fin.succ_embedding` : `fin.succ` as an `order_embedding`;\n* `fin.cast_le h` : embed `fin n` into `fin m`, `h : n \u2264 m`;\n* `fin.cast eq` : order isomorphism between `fin n` and fin m` provided that `n = m`,\n  see also `equiv.fin_congr`;\n* `fin.cast_add m` : embed `fin n` into `fin (n+m)`;\n* `fin.cast_succ` : embed `fin n` into `fin (n+1)`;\n* `fin.succ_above p` : embed `fin n` into `fin (n + 1)` with a hole around `p`;\n* `fin.add_nat m i` : add `m` on `i` on the right, generalizes `fin.succ`;\n* `fin.nat_add n i` adds `n` on `i` on the left;\n\n### Other casts\n\n* `fin.of_nat'`: given a positive number `n` (deduced from `[fact (0 < n)]`), `fin.of_nat' i` is\n  `i % n` interpreted as an element of `fin n`;\n* `fin.cast_lt i h` : embed `i` into a `fin` where `h` proves it belongs into;\n* `fin.pred_above (p : fin n) i` : embed `i : fin (n+1)` into `fin n` by subtracting one if `p < i`;\n* `fin.cast_pred` : embed `fin (n + 2)` into `fin (n + 1)` by mapping `fin.last (n + 1)` to\n  `fin.last n`;\n* `fin.sub_nat i h` : subtract `m` from `i \u2265 m`, generalizes `fin.pred`;\n* `fin.clamp n m` : `min n m` as an element of `fin (m + 1)`;\n* `fin.div_nat i` : divides `i : fin (m * n)` by `n`;\n* `fin.mod_nat i` : takes the mod of `i : fin (m * n)` by `n`;\n\n### Misc definitions\n\n* `fin.last n` : The greatest value of `fin (n+1)`.\n\n-/\n\nuniverses u v\nopen fin nat function\n\n/-- Elimination principle for the empty set `fin 0`, dependent version. -/\ndef fin_zero_elim {\u03b1 : fin 0 \u2192 Sort u} (x : fin 0) : \u03b1 x := x.elim0\n\nlemma fact.succ.pos {n} : fact (0 < succ n) := \u27e8zero_lt_succ _\u27e9\n\nlemma fact.bit0.pos {n} [h : fact (0 < n)] : fact (0 < bit0 n) :=\n\u27e8nat.zero_lt_bit0 $ ne_of_gt h.1\u27e9\n\nlemma fact.bit1.pos {n} : fact (0 < bit1 n) :=\n\u27e8nat.zero_lt_bit1 _\u27e9\n\nlemma fact.pow.pos {p n : \u2115} [h : fact $ 0 < p] : fact (0 < p ^ n) :=\n\u27e8pow_pos h.1 _\u27e9\n\nlocalized \"attribute [instance] fact.succ.pos\" in fin_fact\nlocalized \"attribute [instance] fact.bit0.pos\" in fin_fact\nlocalized \"attribute [instance] fact.bit1.pos\" in fin_fact\nlocalized \"attribute [instance] fact.pow.pos\" in fin_fact\n\nnamespace fin\nvariables {n m : \u2115} {a b : fin n}\n\ninstance fin_to_nat (n : \u2115) : has_coe (fin n) nat := \u27e8subtype.val\u27e9\n\nlemma pos_iff_nonempty {n : \u2115} : 0 < n \u2194 nonempty (fin n) :=\n\u27e8\u03bb h, \u27e8\u27e80, h\u27e9\u27e9, \u03bb \u27e8i\u27e9, lt_of_le_of_lt (nat.zero_le _) i.2\u27e9\n\nsection coe\n\n/-!\n### coercions and constructions\n-/\n\n@[simp] protected lemma eta (a : fin n) (h : (a : \u2115) < n) : (\u27e8(a : \u2115), h\u27e9 : fin n) = a :=\nby cases a; refl\n\n@[ext]\nlemma ext {a b : fin n} (h : (a : \u2115) = b) : a = b := eq_of_veq h\n\nlemma ext_iff (a b : fin n) : a = b \u2194 (a : \u2115) = b :=\niff.intro (congr_arg _) fin.eq_of_veq\n\nlemma coe_injective {n : \u2115} : injective (coe : fin n \u2192 \u2115) := subtype.coe_injective\n\nlemma eq_iff_veq (a b : fin n) : a = b \u2194 a.1 = b.1 :=\n\u27e8veq_of_eq, eq_of_veq\u27e9\n\nlemma ne_iff_vne (a b : fin n) : a \u2260 b \u2194 a.1 \u2260 b.1 :=\n\u27e8vne_of_ne, ne_of_vne\u27e9\n\n@[simp] lemma mk_eq_subtype_mk (a : \u2115) (h : a < n) : mk a h = \u27e8a, h\u27e9 := rfl\n\nprotected lemma mk.inj_iff {n a b : \u2115} {ha : a < n} {hb : b < n} :\n  (\u27e8a, ha\u27e9 : fin n) = \u27e8b, hb\u27e9 \u2194 a = b :=\nsubtype.mk_eq_mk\n\nlemma mk_val {m n : \u2115} (h : m < n) : (\u27e8m, h\u27e9 : fin n).val = m := rfl\n\nlemma eq_mk_iff_coe_eq {k : \u2115} {hk : k < n} : a = \u27e8k, hk\u27e9 \u2194 (a : \u2115) = k :=\nfin.eq_iff_veq a \u27e8k, hk\u27e9\n\n@[simp, norm_cast] lemma coe_mk {m n : \u2115} (h : m < n) : ((\u27e8m, h\u27e9 : fin n) : \u2115) = m := rfl\n\nlemma mk_coe (i : fin n) : (\u27e8i, i.property\u27e9 : fin n) = i :=\nfin.eta _ _\n\nlemma coe_eq_val (a : fin n) : (a : \u2115) = a.val := rfl\n\n@[simp] lemma val_eq_coe (a : fin n) : a.val = a := rfl\n\n/-- Assume `k = l`. If two functions defined on `fin k` and `fin l` are equal on each element,\nthen they coincide (in the heq sense). -/\nprotected lemma heq_fun_iff {\u03b1 : Sort*} {k l : \u2115} (h : k = l) {f : fin k \u2192 \u03b1} {g : fin l \u2192 \u03b1} :\n  f == g \u2194 (\u2200 (i : fin k), f i = g \u27e8(i : \u2115), h \u25b8 i.2\u27e9) :=\nby { induction h, simp [heq_iff_eq, function.funext_iff] }\n\nprotected lemma heq_ext_iff {k l : \u2115} (h : k = l) {i : fin k} {j : fin l} :\n  i == j \u2194 (i : \u2115) = (j : \u2115) :=\nby { induction h, simp [ext_iff] }\n\nlemma exists_iff {p : fin n \u2192 Prop} : (\u2203 i, p i) \u2194 \u2203 i h, p \u27e8i, h\u27e9 :=\n\u27e8\u03bb h, exists.elim h (\u03bb \u27e8i, hi\u27e9 hpi, \u27e8i, hi, hpi\u27e9),\n  \u03bb h, exists.elim h (\u03bb i hi, \u27e8\u27e8i, hi.fst\u27e9, hi.snd\u27e9)\u27e9\n\nlemma forall_iff {p : fin n \u2192 Prop} : (\u2200 i, p i) \u2194 \u2200 i h, p \u27e8i, h\u27e9 :=\n\u27e8\u03bb h i hi, h \u27e8i, hi\u27e9, \u03bb h \u27e8i, hi\u27e9, h i hi\u27e9\n\nend coe\n\nsection order\n\n/-!\n### order\n-/\n\nlemma is_lt (i : fin n) : (i : \u2115) < n := i.2\n\nlemma is_le (i : fin (n + 1)) : (i : \u2115) \u2264 n := le_of_lt_succ i.is_lt\n\nlemma lt_iff_coe_lt_coe : a < b \u2194 (a : \u2115) < b := iff.rfl\n\nlemma le_iff_coe_le_coe : a \u2264 b \u2194 (a : \u2115) \u2264 b := iff.rfl\n\nlemma mk_lt_of_lt_coe {a : \u2115} (h : a < b) : (\u27e8a, h.trans b.is_lt\u27e9 : fin n) < b := h\n\nlemma mk_le_of_le_coe {a : \u2115} (h : a \u2264 b) : (\u27e8a, h.trans_lt b.is_lt\u27e9 : fin n) \u2264 b := h\n\n/-- `a < b` as natural numbers if and only if `a < b` in `fin n`. -/\n@[norm_cast, simp] lemma coe_fin_lt {n : \u2115} {a b : fin n} : (a : \u2115) < (b : \u2115) \u2194 a < b :=\niff.rfl\n\n/-- `a \u2264 b` as natural numbers if and only if `a \u2264 b` in `fin n`. -/\n@[norm_cast, simp] lemma coe_fin_le {n : \u2115} {a b : fin n} : (a : \u2115) \u2264 (b : \u2115) \u2194 a \u2264 b :=\niff.rfl\n\ninstance {n : \u2115} : linear_order (fin n) :=\n{ le := (\u2264), lt := (<),\n  decidable_le := fin.decidable_le,\n  decidable_lt := fin.decidable_lt,\n  decidable_eq := fin.decidable_eq _,\n ..linear_order.lift (coe : fin n \u2192 \u2115) (@fin.eq_of_veq _) }\n\n/-- The inclusion map `fin n \u2192 \u2115` is a relation embedding. -/\ndef coe_embedding (n) : (fin n) \u21aao \u2115 :=\n\u27e8\u27e8coe, @fin.eq_of_veq _\u27e9, \u03bb a b, iff.rfl\u27e9\n\n/-- The ordering on `fin n` is a well order. -/\ninstance fin.lt.is_well_order (n) : is_well_order (fin n) (<) :=\n(coe_embedding n).is_well_order\n\n/-- Use the ordering on `fin n` for checking recursive definitions.\n\nFor example, the following definition is not accepted by the termination checker,\nunless we declare the `has_well_founded` instance:\n```lean\ndef factorial {n : \u2115} : fin n \u2192 \u2115\n| \u27e80, _\u27e9 := 1\n| \u27e8i + 1, hi\u27e9 := (i + 1) * factorial \u27e8i, i.lt_succ_self.trans hi\u27e9\n```\n-/\ninstance {n : \u2115} : has_well_founded (fin n) :=\n\u27e8_, measure_wf coe\u27e9\n\n@[simp] lemma coe_zero {n : \u2115} : ((0 : fin (n+1)) : \u2115) = 0 := rfl\nattribute [simp] val_zero\n@[simp] lemma val_zero' (n) : (0 : fin (n+1)).val = 0 := rfl\n@[simp] lemma mk_zero : (\u27e80, nat.succ_pos'\u27e9 : fin (n + 1)) = (0 : fin _) := rfl\n\nlemma zero_le (a : fin (n + 1)) : 0 \u2264 a := zero_le a.1\n\nlemma zero_lt_one : (0 : fin (n + 2)) < 1 := nat.zero_lt_one\n\nlemma pos_iff_ne_zero (a : fin (n+1)) : 0 < a \u2194 a \u2260 0 :=\nby rw [\u2190 coe_fin_lt, coe_zero, pos_iff_ne_zero, ne.def, ne.def, ext_iff, coe_zero]\n\nlemma eq_zero_or_eq_succ {n : \u2115} (i : fin (n+1)) : i = 0 \u2228 \u2203 j : fin n, i = j.succ :=\nbegin\n  rcases i with \u27e8_|j, h\u27e9,\n  { left, refl, },\n  { right, exact \u27e8\u27e8j, nat.lt_of_succ_lt_succ h\u27e9, rfl\u27e9, }\nend\n\n/-- The greatest value of `fin (n+1)` -/\ndef last (n : \u2115) : fin (n+1) := \u27e8_, n.lt_succ_self\u27e9\n\n@[simp, norm_cast] lemma coe_last (n : \u2115) : (last n : \u2115) = n := rfl\n\nlemma last_val (n : \u2115) : (last n).val = n := rfl\n\ntheorem le_last (i : fin (n+1)) : i \u2264 last n :=\nle_of_lt_succ i.is_lt\n\ninstance : bounded_order (fin (n + 1)) :=\n{ top := last n,\n  le_top := le_last,\n  bot := 0,\n  bot_le := zero_le }\n\ninstance : lattice (fin (n + 1)) := lattice_of_linear_order\n\nlemma last_pos : (0 : fin (n + 2)) < last (n + 1) :=\nby simp [lt_iff_coe_lt_coe]\n\nlemma eq_last_of_not_lt {i : fin (n+1)} (h : \u00ac (i : \u2115) < n) : i = last n :=\nle_antisymm (le_last i) (not_lt.1 h)\n\nsection\n\nvariables {\u03b1 : Type*} [preorder \u03b1]\nopen set\n\n/-- If `e` is an `order_iso` between `fin n` and `fin m`, then `n = m` and `e` is the identity\nmap. In this lemma we state that for each `i : fin n` we have `(e i : \u2115) = (i : \u2115)`. -/\n@[simp] lemma coe_order_iso_apply (e : fin n \u2243o fin m) (i : fin n) : (e i : \u2115) = i :=\nbegin\n  rcases i with \u27e8i, hi\u27e9,\n  rw [subtype.coe_mk],\n  induction i using nat.strong_induction_on with i h,\n  refine le_antisymm (forall_lt_iff_le.1 $ \u03bb j hj, _) (forall_lt_iff_le.1 $ \u03bb j hj, _),\n  { have := e.symm.lt_iff_lt.2 (mk_lt_of_lt_coe hj),\n    rw e.symm_apply_apply at this,\n    convert this,\n    simpa using h _ this (e.symm _).is_lt },\n  { rwa [\u2190 h j hj (hj.trans hi), \u2190 lt_iff_coe_lt_coe, e.lt_iff_lt] }\nend\n\ninstance order_iso_subsingleton : subsingleton (fin n \u2243o \u03b1) :=\n\u27e8\u03bb e e', by { ext i,\n  rw [\u2190 e.symm.apply_eq_iff_eq, e.symm_apply_apply, \u2190 e'.trans_apply, ext_iff,\n    coe_order_iso_apply] }\u27e9\n\ninstance order_iso_subsingleton' : subsingleton (\u03b1 \u2243o fin n) :=\norder_iso.symm_injective.subsingleton\n\ninstance order_iso_unique : unique (fin n \u2243o fin n) := unique.mk' _\n\n/-- Two strictly monotone functions from `fin n` are equal provided that their ranges\nare equal. -/\nlemma strict_mono_unique {f g : fin n \u2192 \u03b1} (hf : strict_mono f) (hg : strict_mono g)\n  (h : range f = range g) : f = g :=\nhave (hf.order_iso f).trans (order_iso.set_congr _ _ h) = hg.order_iso g,\n  from subsingleton.elim _ _,\ncongr_arg (function.comp (coe : range g \u2192 \u03b1)) (funext $ rel_iso.ext_iff.1 this)\n\n/-- Two order embeddings of `fin n` are equal provided that their ranges are equal. -/\nlemma order_embedding_eq {f g : fin n \u21aao \u03b1} (h : range f = range g) : f = g :=\nrel_embedding.ext $ funext_iff.1 $ strict_mono_unique f.strict_mono g.strict_mono h\n\nend\n\n/-- A function `f` on `fin n` is strictly monotone if and only if `f i < f (i+1)` for all `i`. -/\nlemma strict_mono_iff_lt_succ {\u03b1 : Type*} [preorder \u03b1] {f : fin n \u2192 \u03b1} :\n  strict_mono f \u2194 \u2200 i (h : i + 1 < n), f \u27e8i, lt_of_le_of_lt (nat.le_succ i) h\u27e9 < f \u27e8i+1, h\u27e9 :=\nbegin\n  split,\n  { assume H i hi,\n    apply H,\n    exact nat.lt_succ_self _ },\n  { assume H,\n    have A : \u2200 i j (h : i < j) (h' : j < n), f \u27e8i, lt_trans h h'\u27e9 < f \u27e8j, h'\u27e9,\n    { assume i j h h',\n      induction h with k h IH,\n      { exact H _ _ },\n      { exact lt_trans (IH (nat.lt_of_succ_lt h')) (H _ _) } },\n    assume i j hij,\n    convert A (i : \u2115) (j : \u2115) hij j.2; ext; simp only [subtype.coe_eta] }\nend\n\nend order\n\nsection add\n\n/-!\n### addition, numerals, and coercion from nat\n-/\n\n/-- Given a positive `n`, `fin.of_nat' i` is `i % n` as an element of `fin n`. -/\ndef of_nat' [h : fact (0 < n)] (i : \u2115) : fin n := \u27e8i%n, mod_lt _ h.1\u27e9\n\nlemma one_val {n : \u2115} : (1 : fin (n+1)).val = 1 % (n+1) := rfl\nlemma coe_one' {n : \u2115} : ((1 : fin (n+1)) : \u2115) = 1 % (n+1) := rfl\n@[simp] lemma val_one  {n : \u2115} : (1 : fin (n+2)).val = 1 := rfl\n@[simp] lemma coe_one  {n : \u2115} : ((1 : fin (n+2)) : \u2115) = 1 := rfl\n@[simp] lemma mk_one : (\u27e81, nat.succ_lt_succ (nat.succ_pos n)\u27e9 : fin (n + 2)) = (1 : fin _) := rfl\n\ninstance {n : \u2115} : nontrivial (fin (n + 2)) := \u27e8\u27e80, 1, dec_trivial\u27e9\u27e9\n\nsection monoid\n\n@[simp] protected lemma add_zero (k : fin (n + 1)) : k + 0 = k :=\nby simp [eq_iff_veq, add_def, mod_eq_of_lt (is_lt k)]\n\n@[simp] protected lemma zero_add (k : fin (n + 1)) : (0 : fin (n + 1)) + k = k :=\nby simp [eq_iff_veq, add_def, mod_eq_of_lt (is_lt k)]\n\ninstance add_comm_monoid (n : \u2115) : add_comm_monoid (fin (n + 1)) :=\n{ add := (+),\n  add_assoc := by simp [eq_iff_veq, add_def, add_assoc],\n  zero := 0,\n  zero_add := fin.zero_add,\n  add_zero := fin.add_zero,\n  add_comm := by simp [eq_iff_veq, add_def, add_comm] }\n\nend monoid\n\nlemma val_add {n : \u2115} : \u2200 a b : fin n, (a + b).val = (a.val + b.val) % n\n| \u27e8_, _\u27e9 \u27e8_, _\u27e9 := rfl\n\nlemma coe_add {n : \u2115} : \u2200 a b : fin n, ((a + b : fin n) : \u2115) = (a + b) % n\n| \u27e8_, _\u27e9 \u27e8_, _\u27e9 := rfl\n\nlemma coe_add_eq_ite {n : \u2115} (a b : fin n) :\n  (\u2191(a + b) : \u2115) = if n \u2264 a + b then a + b - n else a + b :=\nby rw [fin.coe_add, nat.add_mod_eq_ite,\n       nat.mod_eq_of_lt (show \u2191a < n, from a.2), nat.mod_eq_of_lt (show \u2191b < n, from b.2)]\n\nlemma coe_bit0 {n : \u2115} (k : fin n) : ((bit0 k : fin n) : \u2115) = bit0 (k : \u2115) % n :=\nby { cases k, refl }\n\nlemma coe_bit1 {n : \u2115} (k : fin (n + 1)) :\n  ((bit1 k : fin (n + 1)) : \u2115) = bit1 (k : \u2115) % (n + 1) :=\nbegin\n  cases n, { cases k with k h, cases k, {show _ % _ = _, simp}, cases h with _ h, cases h },\n  simp [bit1, fin.coe_bit0, fin.coe_add, fin.coe_one],\nend\n\nlemma coe_add_one_of_lt {n : \u2115} {i : fin n.succ} (h : i < last _) :\n  (\u2191(i + 1) : \u2115) = i + 1 :=\nbegin\n  -- First show that `((1 : fin n.succ) : \u2115) = 1`, because `n.succ` is at least 2.\n  cases n,\n  { cases h },\n  -- Then just unfold the definitions.\n  rw [fin.coe_add, fin.coe_one, nat.mod_eq_of_lt (nat.succ_lt_succ _)],\n  exact h\nend\n\n@[simp] lemma last_add_one : \u2200 n, last n + 1 = 0\n| 0 := subsingleton.elim _ _\n| (n + 1) := by { ext, rw [coe_add, coe_zero, coe_last, coe_one, nat.mod_self] }\n\nlemma coe_add_one {n : \u2115} (i : fin (n + 1)) :\n  ((i + 1 : fin (n + 1)) : \u2115) = if i = last _ then 0 else i + 1 :=\nbegin\n  rcases (le_last i).eq_or_lt with rfl|h,\n  { simp },\n  { simpa [h.ne] using coe_add_one_of_lt h }\nend\n\nsection bit\n\n@[simp] lemma mk_bit0 {m n : \u2115} (h : bit0 m < n) :\n  (\u27e8bit0 m, h\u27e9 : fin n) = (bit0 \u27e8m, (nat.le_add_right m m).trans_lt h\u27e9 : fin _) :=\neq_of_veq (nat.mod_eq_of_lt h).symm\n\n@[simp] lemma mk_bit1 {m n : \u2115} (h : bit1 m < n + 1) :\n  (\u27e8bit1 m, h\u27e9 : fin (n + 1)) = (bit1 \u27e8m, (nat.le_add_right m m).trans_lt\n    ((m + m).lt_succ_self.trans h)\u27e9 : fin _) :=\nbegin\n  ext,\n  simp only [bit1, bit0] at h,\n  simp only [bit1, bit0, coe_add, coe_one', coe_mk, \u2190nat.add_mod, nat.mod_eq_of_lt h],\nend\n\nend bit\n\n@[simp] lemma val_two  {n : \u2115} : (2 : fin (n+3)).val = 2 := rfl\n@[simp] lemma coe_two  {n : \u2115} : ((2 : fin (n+3)) : \u2115) = 2 := rfl\n\nsection of_nat_coe\n\n@[simp]\nlemma of_nat_eq_coe (n : \u2115) (a : \u2115) : (of_nat a : fin (n+1)) = a :=\nbegin\n  induction a with a ih, { refl },\n  ext, show (a+1) % (n+1) = subtype.val (a+1 : fin (n+1)),\n  { rw [val_add, \u2190 ih, of_nat],\n    exact add_mod _ _ _ }\nend\n\n/-- Converting an in-range number to `fin (n + 1)` produces a result\nwhose value is the original number.  -/\nlemma coe_val_of_lt {n : \u2115} {a : \u2115} (h : a < n + 1) :\n  ((a : fin (n + 1)).val) = a :=\nbegin\n  rw \u2190of_nat_eq_coe,\n  exact nat.mod_eq_of_lt h\nend\n\n/-- Converting the value of a `fin (n + 1)` to `fin (n + 1)` results\nin the same value.  -/\nlemma coe_val_eq_self {n : \u2115} (a : fin (n + 1)) : (a.val : fin (n + 1)) = a :=\nbegin\n  rw fin.eq_iff_veq,\n  exact coe_val_of_lt a.property\nend\n\n/-- Coercing an in-range number to `fin (n + 1)`, and converting back\nto `\u2115`, results in that number. -/\nlemma coe_coe_of_lt {n : \u2115} {a : \u2115} (h : a < n + 1) :\n  ((a : fin (n + 1)) : \u2115) = a :=\ncoe_val_of_lt h\n\n/-- Converting a `fin (n + 1)` to `\u2115` and back results in the same\nvalue. -/\n@[simp] lemma coe_coe_eq_self {n : \u2115} (a : fin (n + 1)) : ((a : \u2115) : fin (n + 1)) = a :=\ncoe_val_eq_self a\n\nlemma coe_nat_eq_last (n) : (n : fin (n + 1)) = fin.last n :=\nby { rw [\u2190fin.of_nat_eq_coe, fin.of_nat, fin.last], simp only [nat.mod_eq_of_lt n.lt_succ_self] }\n\nlemma le_coe_last (i : fin (n + 1)) : i \u2264 n :=\nby { rw fin.coe_nat_eq_last, exact fin.le_last i }\n\nend of_nat_coe\n\nlemma add_one_pos (i : fin (n + 1)) (h : i < fin.last n) : (0 : fin (n + 1)) < i + 1 :=\nbegin\n  cases n,\n  { exact absurd h (nat.not_lt_zero _) },\n  { rw [lt_iff_coe_lt_coe, coe_last, \u2190add_lt_add_iff_right 1] at h,\n    rw [lt_iff_coe_lt_coe, coe_add, coe_zero, coe_one, nat.mod_eq_of_lt h],\n    exact nat.zero_lt_succ _ }\nend\n\nlemma one_pos : (0 : fin (n + 2)) < 1 := succ_pos 0\n\nlemma zero_ne_one : (0 : fin (n + 2)) \u2260 1 := ne_of_lt one_pos\n\n@[simp] lemma zero_eq_one_iff : (0 : fin (n + 1)) = 1 \u2194 n = 0 :=\nbegin\n  split,\n  { cases n; intro h,\n    { refl },\n    { have := zero_ne_one, contradiction } },\n  { rintro rfl, refl }\nend\n\n@[simp] lemma one_eq_zero_iff : (1 : fin (n + 1)) = 0 \u2194 n = 0 :=\nby rw [eq_comm, zero_eq_one_iff]\n\nend add\n\nsection succ\n\n/-!\n### succ and casts into larger fin types\n-/\n\n@[simp] lemma coe_succ (j : fin n) : (j.succ : \u2115) = j + 1 :=\nby cases j; simp [fin.succ]\n\nlemma succ_pos (a : fin n) : (0 : fin (n + 1)) < a.succ := by simp [lt_iff_coe_lt_coe]\n\n/-- `fin.succ` as an `order_embedding` -/\ndef succ_embedding (n : \u2115) : fin n \u21aao fin (n + 1) :=\norder_embedding.of_strict_mono fin.succ $ \u03bb \u27e8i, hi\u27e9 \u27e8j, hj\u27e9 h, succ_lt_succ h\n\n@[simp] lemma coe_succ_embedding : \u21d1(succ_embedding n) = fin.succ := rfl\n\n@[simp] lemma succ_le_succ_iff : a.succ \u2264 b.succ \u2194 a \u2264 b :=\n(succ_embedding n).le_iff_le\n\n@[simp] lemma succ_lt_succ_iff : a.succ < b.succ \u2194 a < b :=\n(succ_embedding n).lt_iff_lt\n\nlemma succ_injective (n : \u2115) : injective (@fin.succ n) :=\n(succ_embedding n).injective\n\n@[simp] lemma succ_inj {a b : fin n} : a.succ = b.succ \u2194 a = b :=\n(succ_injective n).eq_iff\n\nlemma succ_ne_zero {n} : \u2200 k : fin n, fin.succ k \u2260 0\n| \u27e8k, hk\u27e9 heq := nat.succ_ne_zero k $ (ext_iff _ _).1 heq\n\n@[simp] lemma succ_zero_eq_one : fin.succ (0 : fin (n + 1)) = 1 := rfl\n\n@[simp] lemma succ_one_eq_two : fin.succ (1 : fin (n + 2)) = 2 := rfl\n\n@[simp] lemma succ_mk (n i : \u2115) (h : i < n) : fin.succ \u27e8i, h\u27e9 = \u27e8i + 1, nat.succ_lt_succ h\u27e9 :=\nrfl\n\nlemma mk_succ_pos (i : \u2115) (h : i < n) : (0 : fin (n + 1)) < \u27e8i.succ, add_lt_add_right h 1\u27e9 :=\nby { rw [lt_iff_coe_lt_coe, coe_zero], exact nat.succ_pos i }\n\nlemma one_lt_succ_succ (a : fin n) : (1 : fin (n + 2)) < a.succ.succ :=\nbegin\n  cases n,\n  { exact fin_zero_elim a },\n  { rw [\u2190succ_zero_eq_one, succ_lt_succ_iff], exact succ_pos a }\nend\n\nlemma succ_succ_ne_one (a : fin n) : fin.succ (fin.succ a) \u2260 1 := ne_of_gt (one_lt_succ_succ a)\n\n/-- `cast_lt i h` embeds `i` into a `fin` where `h` proves it belongs into.  -/\ndef cast_lt (i : fin m) (h : i.1 < n) : fin n := \u27e8i.1, h\u27e9\n\n@[simp] lemma coe_cast_lt (i : fin m) (h : i.1 < n) : (cast_lt i h : \u2115) = i := rfl\n\n@[simp] lemma cast_lt_mk (i n m : \u2115) (hn : i < n) (hm : i < m) : cast_lt \u27e8i, hn\u27e9 hm = \u27e8i, hm\u27e9 := rfl\n\n/-- `cast_le h i` embeds `i` into a larger `fin` type.  -/\ndef cast_le (h : n \u2264 m) : fin n \u21aao fin m :=\norder_embedding.of_strict_mono (\u03bb a, cast_lt a (lt_of_lt_of_le a.2 h)) $ \u03bb a b h, h\n\n@[simp] lemma coe_cast_le (h : n \u2264 m) (i : fin n) : (cast_le h i : \u2115) = i := rfl\n\n@[simp] lemma cast_le_mk (i n m : \u2115) (hn : i < n) (h : n \u2264 m) :\n  cast_le h \u27e8i, hn\u27e9 = \u27e8i, lt_of_lt_of_le hn h\u27e9 := rfl\n\n@[simp] lemma cast_le_zero {n m : \u2115} (h : n.succ \u2264 m.succ) :\n  cast_le h 0 = 0 :=\nby simp [eq_iff_veq]\n\n@[simp] lemma range_cast_le {n k : \u2115} (h : n \u2264 k) :\n  set.range (cast_le h) = {i | (i : \u2115) < n} :=\nset.ext (\u03bb x, \u27e8\u03bb \u27e8y, hy\u27e9, hy \u25b8 y.2, \u03bb hx, \u27e8\u27e8x, hx\u27e9, fin.ext rfl\u27e9\u27e9)\n\n@[simp] lemma coe_of_injective_cast_le_symm {n k : \u2115} (h : n \u2264 k) (i : fin k) (hi) :\n  ((equiv.of_injective _ (cast_le h).injective).symm \u27e8i, hi\u27e9 : \u2115) = i :=\nbegin\n  rw \u2190 coe_cast_le,\n  exact congr_arg coe (equiv.apply_of_injective_symm _ _ _)\nend\n\n@[simp] lemma cast_le_succ {m n : \u2115} (h : (m + 1) \u2264 (n + 1)) (i : fin m) :\n  cast_le h i.succ = (cast_le (nat.succ_le_succ_iff.mp h) i).succ :=\nby simp [fin.eq_iff_veq]\n\n/-- `cast eq i` embeds `i` into a equal `fin` type, see also `equiv.fin_congr`. -/\ndef cast (eq : n = m) : fin n \u2243o fin m :=\n{ to_equiv := \u27e8cast_le eq.le, cast_le eq.symm.le, \u03bb a, eq_of_veq rfl, \u03bb a, eq_of_veq rfl\u27e9,\n  map_rel_iff' := \u03bb a b, iff.rfl }\n\n@[simp] lemma symm_cast (h : n = m) : (cast h).symm = cast h.symm := rfl\n\n/-- While `fin.coe_order_iso_apply` is a more general case of this, we mark this `simp` anyway\nas it is eligible for `dsimp`. -/\n@[simp]\nlemma coe_cast (h : n = m) (i : fin n) : (cast h i : \u2115) = i := rfl\n\n@[simp] lemma cast_mk (h : n = m) (i : \u2115) (hn : i < n) :\n  cast h \u27e8i, hn\u27e9 = \u27e8i, lt_of_lt_of_le hn h.le\u27e9 := rfl\n\n@[simp] lemma cast_trans {k : \u2115} (h : n = m) (h' : m = k) {i : fin n} :\n  cast h' (cast h i) = cast (eq.trans h h') i := rfl\n\n@[simp] lemma cast_refl (h : n = n := rfl) : cast h = order_iso.refl (fin n) :=\nby { ext, refl }\n\n/-- While in many cases `fin.cast` is better than `equiv.cast`/`cast`, sometimes we want to apply\na generic theorem about `cast`. -/\nlemma cast_to_equiv (h : n = m) : (cast h).to_equiv = equiv.cast (h \u25b8 rfl) :=\nby { subst h, simp }\n\n/-- While in many cases `fin.cast` is better than `equiv.cast`/`cast`, sometimes we want to apply\na generic theorem about `cast`. -/\nlemma cast_eq_cast (h : n = m) : (cast h : fin n \u2192 fin m) = _root_.cast (h \u25b8 rfl) :=\nby { subst h, ext, simp }\n\n/-- `cast_add m i` embeds `i : fin n` in `fin (n+m)`. See also `fin.nat_add` and `fin.add_nat`. -/\ndef cast_add (m) : fin n \u21aao fin (n + m) := cast_le $ nat.le_add_right n m\n\n@[simp] lemma coe_cast_add (m : \u2115) (i : fin n) : (cast_add m i : \u2115) = i := rfl\n\nlemma cast_add_lt {m : \u2115} (n : \u2115) (i : fin m) : (cast_add n i : \u2115) < m := i.2\n\n@[simp] lemma cast_add_mk (m : \u2115) (i : \u2115) (h : i < n) :\n  cast_add m \u27e8i, h\u27e9 = \u27e8i, lt_add_right i n m h\u27e9 := rfl\n\n@[simp] lemma cast_add_cast_lt (m : \u2115) (i : fin (n + m)) (hi : i.val < n) :\n  cast_add m (cast_lt i hi) = i :=\next rfl\n\n@[simp] lemma cast_lt_cast_add (m : \u2115) (i : fin n) :\n  cast_lt (cast_add m i) (cast_add_lt m i) = i :=\next rfl\n\n/-- For rewriting in the reverse direction, see `fin.cast_cast_add_left`. -/\nlemma cast_add_cast {n n' : \u2115} (m : \u2115) (i : fin n') (h : n' = n) :\n  cast_add m (fin.cast h i) = fin.cast (congr_arg _ h) (cast_add m i) :=\next rfl\n\nlemma cast_cast_add_left {n n' m : \u2115} (i : fin n') (h : n' + m = n + m) :\n  cast h (cast_add m i) = cast_add m (cast (add_right_cancel h) i) :=\next rfl\n\n@[simp] lemma cast_cast_add_right {n m m' : \u2115} (i : fin n) (h : n + m' = n + m) :\n  cast h (cast_add m' i) = cast_add m i :=\next rfl\n\n/-- The cast of the successor is the succesor of the cast. See `fin.succ_cast_eq` for rewriting in\nthe reverse direction. -/\n@[simp] lemma cast_succ_eq {n' : \u2115} (i : fin n) (h : n.succ = n'.succ) :\n  cast h i.succ = (cast (nat.succ.inj h) i).succ :=\next $ by simp\n\nlemma succ_cast_eq {n' : \u2115} (i : fin n) (h : n = n') : (cast h i).succ = cast (by rw h) i.succ :=\next $ by simp\n\n/-- `cast_succ i` embeds `i : fin n` in `fin (n+1)`. -/\ndef cast_succ : fin n \u21aao fin (n + 1) := cast_add 1\n\n@[simp] \n\n@[simp] lemma cast_succ_mk (n i : \u2115) (h : i < n) : cast_succ \u27e8i, h\u27e9 = \u27e8i, nat.lt.step h\u27e9 := rfl\n\nlemma cast_succ_lt_succ (i : fin n) : i.cast_succ < i.succ :=\nlt_iff_coe_lt_coe.2 $ by simp only [coe_cast_succ, coe_succ, nat.lt_succ_self]\n\nlemma le_cast_succ_iff {i : fin (n + 1)} {j : fin n} : i \u2264 j.cast_succ \u2194 i < j.succ :=\nby simpa [lt_iff_coe_lt_coe, le_iff_coe_le_coe] using nat.succ_le_succ_iff.symm\n\n@[simp] lemma succ_last (n : \u2115) : (last n).succ = last (n.succ) := rfl\n\n@[simp] lemma succ_eq_last_succ {n : \u2115} (i : fin n.succ) :\n  i.succ = last (n + 1) \u2194 i = last n :=\nby rw [\u2190 succ_last, (succ_injective _).eq_iff]\n\n@[simp] lemma cast_succ_cast_lt (i : fin (n + 1)) (h : (i : \u2115) < n) : cast_succ (cast_lt i h) = i :=\nfin.eq_of_veq rfl\n\n@[simp] lemma cast_lt_cast_succ {n : \u2115} (a : fin n) (h : (a : \u2115) < n) :\n  cast_lt (cast_succ a) h = a :=\nby cases a; refl\n\n@[simp] lemma cast_succ_lt_cast_succ_iff : a.cast_succ < b.cast_succ \u2194 a < b :=\n(@cast_succ n).lt_iff_lt\n\nlemma cast_succ_injective (n : \u2115) : injective (@fin.cast_succ n) :=\n(cast_succ : fin n \u21aao _).injective\n\nlemma cast_succ_inj {a b : fin n} : a.cast_succ = b.cast_succ \u2194 a = b :=\n(cast_succ_injective n).eq_iff\n\nlemma cast_succ_lt_last (a : fin n) : cast_succ a < last n := lt_iff_coe_lt_coe.mpr a.is_lt\n\n@[simp] lemma cast_succ_zero : cast_succ (0 : fin (n + 1)) = 0 := rfl\n\n@[simp] lemma cast_succ_one {n : \u2115} : fin.cast_succ (1 : fin (n + 2)) = 1 := rfl\n\n/-- `cast_succ i` is positive when `i` is positive -/\nlemma cast_succ_pos {i : fin (n + 1)} (h : 0 < i) : 0 < cast_succ i :=\nby simpa [lt_iff_coe_lt_coe] using h\n\n@[simp] lemma cast_succ_eq_zero_iff (a : fin (n + 1)) : a.cast_succ = 0 \u2194 a = 0 :=\nsubtype.ext_iff.trans $ (subtype.ext_iff.trans $ by exact iff.rfl).symm\n\nlemma cast_succ_ne_zero_iff (a : fin (n + 1)) : a.cast_succ \u2260 0 \u2194 a \u2260 0 :=\nnot_iff_not.mpr $ cast_succ_eq_zero_iff a\n\nlemma cast_succ_fin_succ (n : \u2115) (j : fin n) :\n  cast_succ (fin.succ j) = fin.succ (cast_succ j) :=\nby simp [fin.ext_iff]\n\n@[norm_cast, simp] lemma coe_eq_cast_succ : (a : fin (n + 1)) = a.cast_succ :=\nbegin\n  ext,\n  exact coe_val_of_lt (nat.lt.step a.is_lt),\nend\n\n@[simp] lemma coe_succ_eq_succ : a.cast_succ + 1 = a.succ :=\nbegin\n  cases n,\n  { exact fin_zero_elim a },\n  { simp [a.is_lt, eq_iff_veq, add_def, nat.mod_eq_of_lt] }\nend\n\nlemma lt_succ : a.cast_succ < a.succ :=\nby { rw [cast_succ, lt_iff_coe_lt_coe, coe_cast_add, coe_succ], exact lt_add_one a.val }\n\n@[simp] lemma range_cast_succ {n : \u2115} :\n  set.range (cast_succ : fin n \u2192 fin n.succ) = {i | (i : \u2115) < n} :=\nrange_cast_le _\n\n@[simp] lemma coe_of_injective_cast_succ_symm {n : \u2115} (i : fin n.succ) (hi) :\n  ((equiv.of_injective cast_succ (cast_succ_injective _)).symm \u27e8i, hi\u27e9 : \u2115) = i :=\nbegin\n  rw \u2190 coe_cast_succ,\n  exact congr_arg coe (equiv.apply_of_injective_symm _ _ _)\nend\n\nlemma succ_cast_succ {n : \u2115} (i : fin n) :\n  i.cast_succ.succ = i.succ.cast_succ :=\nfin.ext (by simp)\n\n/-- `add_nat m i` adds `m` to `i`, generalizes `fin.succ`. -/\ndef add_nat (m) : fin n \u21aao fin (n + m) :=\norder_embedding.of_strict_mono (\u03bb i, \u27e8(i : \u2115) + m, add_lt_add_right i.2 _\u27e9) $\n  \u03bb i j h, lt_iff_coe_lt_coe.2 $ add_lt_add_right h _\n\n@[simp] lemma coe_add_nat (m : \u2115) (i : fin n) : (add_nat m i : \u2115) = i + m := rfl\n\nlemma le_coe_add_nat (m : \u2115) (i : fin n) : m \u2264 add_nat m i := nat.le_add_left _ _\n\n@[simp] lemma add_nat_mk (n i : \u2115) (hi : i < m) :\n  add_nat n \u27e8i, hi\u27e9 = \u27e8i + n, add_lt_add_right hi n\u27e9 := rfl\n\n@[simp] lemma cast_add_nat_zero {n n' : \u2115} (i : fin n) (h : n + 0 = n') :\n  cast h (add_nat 0 i) = cast ((add_zero _).symm.trans h) i :=\next $ add_zero _\n\n/-- For rewriting in the reverse direction, see `fin.cast_add_nat_left`. -/\nlemma add_nat_cast {n n' m : \u2115} (i : fin n') (h : n' = n) :\n  add_nat m (cast h i) = cast (congr_arg _ h) (add_nat m i) :=\next rfl\n\nlemma cast_add_nat_left {n n' m : \u2115} (i : fin n') (h : n' + m = n + m) :\n  cast h (add_nat m i) = add_nat m (cast (add_right_cancel h) i) :=\next rfl\n\n@[simp] lemma cast_add_nat_right {n m m' : \u2115} (i : fin n) (h : n + m' = n + m) :\n  cast h (add_nat m' i) = add_nat m i :=\next $ (congr_arg ((+) (i : \u2115)) (add_left_cancel h) : _)\n\n/-- `nat_add n i` adds `n` to `i` \"on the left\". -/\ndef nat_add (n) {m} : fin m \u21aao fin (n + m) :=\norder_embedding.of_strict_mono (\u03bb i, \u27e8n + (i : \u2115), add_lt_add_left i.2 _\u27e9) $\n  \u03bb i j h, lt_iff_coe_lt_coe.2 $ add_lt_add_left h _\n\n@[simp] lemma coe_nat_add (n : \u2115) {m : \u2115} (i : fin m) : (nat_add n i : \u2115) = n + i := rfl\n\n@[simp] lemma nat_add_mk (n i : \u2115) (hi : i < m) :\n  nat_add n \u27e8i, hi\u27e9 = \u27e8n + i, add_lt_add_left hi n\u27e9 := rfl\n\nlemma le_coe_nat_add (m : \u2115) (i : fin n) : m \u2264 nat_add m i := nat.le_add_right _ _\n\nlemma nat_add_zero {n : \u2115} : fin.nat_add 0 = (fin.cast (zero_add n).symm).to_rel_embedding :=\nby { ext, apply zero_add }\n\n/-- For rewriting in the reverse direction, see `fin.cast_nat_add_right`. -/\nlemma nat_add_cast {n n' : \u2115} (m : \u2115) (i : fin n') (h : n' = n) :\n  nat_add m (cast h i) = cast (congr_arg _ h) (nat_add m i) :=\next rfl\n\nlemma cast_nat_add_right {n n' m : \u2115} (i : fin n') (h : m + n' = m + n) :\n  cast h (nat_add m i) = nat_add m (cast (add_left_cancel h) i) :=\next rfl\n\n@[simp] lemma cast_nat_add_left {n m m' : \u2115} (i : fin n) (h : m' + n = m + n) :\n  cast h (nat_add m' i) = nat_add m i :=\next $ (congr_arg (+ (i : \u2115)) (add_right_cancel h) : _)\n\n@[simp] lemma cast_nat_add_zero {n n' : \u2115} (i : fin n) (h : 0 + n = n') :\n  cast h (nat_add 0 i) = cast ((zero_add _).symm.trans h) i :=\next $ zero_add _\n\n@[simp] lemma cast_nat_add (n : \u2115) {m : \u2115} (i : fin m) :\n  cast (add_comm _ _) (nat_add n i) = add_nat n i :=\next $ add_comm _ _\n\n@[simp] lemma cast_add_nat {n : \u2115} (m : \u2115) (i : fin n) :\n  cast (add_comm _ _) (add_nat m i) = nat_add m i :=\next $ add_comm _ _\n\nend succ\n\nsection pred\n\n/-!\n### pred\n-/\n\n@[simp] lemma coe_pred (j : fin (n+1)) (h : j \u2260 0) : (j.pred h : \u2115) = j - 1 :=\nby { cases j, refl }\n\n@[simp] lemma succ_pred : \u2200(i : fin (n+1)) (h : i \u2260 0), (i.pred h).succ = i\n| \u27e80,     h\u27e9 hi := by contradiction\n| \u27e8n + 1, h\u27e9 hi := rfl\n\n@[simp] lemma pred_succ (i : fin n) {h : i.succ \u2260 0} : i.succ.pred h = i :=\nby { cases i, refl }\n\n@[simp] lemma pred_mk_succ (i : \u2115) (h : i < n + 1) :\n  fin.pred \u27e8i + 1, add_lt_add_right h 1\u27e9 (ne_of_vne (ne_of_gt (mk_succ_pos i h))) = \u27e8i, h\u27e9 :=\nby simp only [ext_iff, coe_pred, coe_mk, add_tsub_cancel_right]\n\n-- This is not a simp lemma by default, because `pred_mk_succ` is nicer when it applies.\nlemma pred_mk {n : \u2115} (i : \u2115) (h : i < n + 1) (w) :\n  fin.pred \u27e8i, h\u27e9 w =\n  \u27e8i - 1, by rwa tsub_lt_iff_right (nat.succ_le_of_lt $ nat.pos_of_ne_zero (fin.vne_of_ne w))\u27e9 :=\nrfl\n\n@[simp] lemma pred_le_pred_iff {n : \u2115} {a b : fin n.succ} {ha : a \u2260 0} {hb : b \u2260 0} :\n  a.pred ha \u2264 b.pred hb \u2194 a \u2264 b :=\nby rw [\u2190succ_le_succ_iff, succ_pred, succ_pred]\n\n@[simp] lemma pred_lt_pred_iff {n : \u2115} {a b : fin n.succ} {ha : a \u2260 0} {hb : b \u2260 0} :\n  a.pred ha < b.pred hb \u2194 a < b :=\nby rw [\u2190succ_lt_succ_iff, succ_pred, succ_pred]\n\n@[simp] lemma pred_inj :\n  \u2200 {a b : fin (n + 1)} {ha : a \u2260 0} {hb : b \u2260 0}, a.pred ha = b.pred hb \u2194 a = b\n| \u27e80,   _\u27e9  b         ha hb := by contradiction\n| \u27e8i+1, _\u27e9  \u27e80,   _\u27e9  ha hb := by contradiction\n| \u27e8i+1, hi\u27e9 \u27e8j+1, hj\u27e9 ha hb := by simp [fin.eq_iff_veq]\n\n@[simp] lemma pred_one {n : \u2115} : fin.pred (1 : fin (n + 2)) (ne.symm (ne_of_lt one_pos)) = 0 := rfl\n\nlemma pred_add_one (i : fin (n + 2)) (h : (i : \u2115) < n + 1) :\n  pred (i + 1) (ne_of_gt (add_one_pos _ (lt_iff_coe_lt_coe.mpr h))) = cast_lt i h :=\nbegin\n  rw [ext_iff, coe_pred, coe_cast_lt, coe_add, coe_one, mod_eq_of_lt, add_tsub_cancel_right],\n  exact add_lt_add_right h 1,\nend\n\n/-- `sub_nat i h` subtracts `m` from `i`, generalizes `fin.pred`. -/\ndef sub_nat (m) (i : fin (n + m)) (h : m \u2264 (i : \u2115)) : fin n :=\n\u27e8(i : \u2115) - m, by { rw [tsub_lt_iff_right h], exact i.is_lt }\u27e9\n\n@[simp] lemma coe_sub_nat (i : fin (n + m)) (h : m \u2264 i) : (i.sub_nat m h : \u2115) = i - m :=\nrfl\n\n@[simp] lemma sub_nat_mk {i : \u2115} (h\u2081 : i < n + m) (h\u2082 : m \u2264 i) :\n  sub_nat m \u27e8i, h\u2081\u27e9 h\u2082 = \u27e8i - m, (tsub_lt_iff_right h\u2082).2 h\u2081\u27e9 :=\nrfl\n\n@[simp] lemma pred_cast_succ_succ (i : fin n) :\n  pred (cast_succ i.succ) (ne_of_gt (cast_succ_pos i.succ_pos)) = i.cast_succ :=\nby simp [eq_iff_veq]\n\n@[simp] lemma add_nat_sub_nat {i : fin (n + m)} (h : m \u2264 i) :\n  add_nat m (sub_nat m i h) = i :=\next $ tsub_add_cancel_of_le h\n\n@[simp] lemma sub_nat_add_nat (i : fin n) (m : \u2115) (h : m \u2264 add_nat m i := le_coe_add_nat m i) :\n  sub_nat m (add_nat m i) h = i :=\next $ add_tsub_cancel_right i m\n\n@[simp] lemma nat_add_sub_nat_cast {i : fin (n + m)} (h : n \u2264 i) :\n  nat_add n (sub_nat n (cast (add_comm _ _) i) h) = i :=\nby simp [\u2190 cast_add_nat]\n\nend pred\n\nsection div_mod\n\n/-- Compute `i / n`, where `n` is a `nat` and inferred the type of `i`. -/\ndef div_nat (i : fin (m * n)) : fin m :=\n\u27e8i / n, nat.div_lt_of_lt_mul $ mul_comm m n \u25b8 i.prop\u27e9\n\n@[simp] lemma coe_div_nat (i : fin (m * n)) : (i.div_nat : \u2115) = i / n := rfl\n\n/-- Compute `i % n`, where `n` is a `nat` and inferred the type of `i`. -/\ndef mod_nat (i : fin (m * n)) : fin n :=\n\u27e8i % n, nat.mod_lt _ $ pos_of_mul_pos_left ((nat.zero_le i).trans_lt i.is_lt) m.zero_le\u27e9\n\n@[simp] lemma coe_mod_nat (i : fin (m * n)) : (i.mod_nat : \u2115) = i % n := rfl\n\nend div_mod\n\nsection rec\n\n/-!\n### recursion and induction principles\n-/\n\n/-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ\u2026`.\nThis function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple,\nand `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element\nof `n`-tuple. -/\n@[elab_as_eliminator] def succ_rec\n  {C : \u03a0 n, fin n \u2192 Sort*}\n  (H0 : \u03a0 n, C (succ n) 0)\n  (Hs : \u03a0 n i, C n i \u2192 C (succ n) i.succ) : \u03a0 {n : \u2115} (i : fin n), C n i\n| 0        i           := i.elim0\n| (succ n) \u27e80, _\u27e9      := H0 _\n| (succ n) \u27e8succ i, h\u27e9 := Hs _ _ (succ_rec \u27e8i, lt_of_succ_lt_succ h\u27e9)\n\n/-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ\u2026`.\nThis function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple,\nand `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element\nof `n`-tuple.\n\nA version of `fin.succ_rec` taking `i : fin n` as the first argument. -/\n@[elab_as_eliminator] def succ_rec_on {n : \u2115} (i : fin n)\n  {C : \u03a0 n, fin n \u2192 Sort*}\n  (H0 : \u03a0 n, C (succ n) 0)\n  (Hs : \u03a0 n i, C n i \u2192 C (succ n) i.succ) : C n i :=\ni.succ_rec H0 Hs\n\n@[simp] theorem succ_rec_on_zero {C : \u2200 n, fin n \u2192 Sort*} {H0 Hs} (n) :\n  @fin.succ_rec_on (succ n) 0 C H0 Hs = H0 n :=\nrfl\n\n@[simp] theorem succ_rec_on_succ {C : \u2200 n, fin n \u2192 Sort*} {H0 Hs} {n} (i : fin n) :\n  @fin.succ_rec_on (succ n) i.succ C H0 Hs = Hs n i (fin.succ_rec_on i H0 Hs) :=\nby cases i; refl\n\n/--\nDefine `C i` by induction on `i : fin (n + 1)` via induction on the underlying `nat` value.\nThis function has two arguments: `h0` handles the base case on `C 0`,\nand `hs` defines the inductive step using `C i.cast_succ`.\n-/\n@[elab_as_eliminator] def induction\n  {C : fin (n + 1) \u2192 Sort*}\n  (h0 : C 0)\n  (hs : \u2200 i : fin n, C i.cast_succ \u2192 C i.succ) :\n  \u03a0 (i : fin (n + 1)), C i :=\nbegin\n  rintro \u27e8i, hi\u27e9,\n  induction i with i IH,\n  { rwa [fin.mk_zero] },\n  { refine hs \u27e8i, lt_of_succ_lt_succ hi\u27e9 _,\n    exact IH (lt_of_succ_lt hi) }\nend\n\n/--\nDefine `C i` by induction on `i : fin (n + 1)` via induction on the underlying `nat` value.\nThis function has two arguments: `h0` handles the base case on `C 0`,\nand `hs` defines the inductive step using `C i.cast_succ`.\n\nA version of `fin.induction` taking `i : fin (n + 1)` as the first argument.\n-/\n@[elab_as_eliminator] def induction_on (i : fin (n + 1))\n  {C : fin (n + 1) \u2192 Sort*}\n  (h0 : C 0)\n  (hs : \u2200 i : fin n, C i.cast_succ \u2192 C i.succ) : C i :=\ninduction h0 hs i\n\n/-- Define `f : \u03a0 i : fin n.succ, C i` by separately handling the cases `i = 0` and\n`i = j.succ`, `j : fin n`. -/\n@[elab_as_eliminator] def cases\n  {C : fin (succ n) \u2192 Sort*} (H0 : C 0) (Hs : \u03a0 i : fin n, C (i.succ)) :\n  \u03a0 (i : fin (succ n)), C i :=\ninduction H0 (\u03bb i _, Hs i)\n\n@[simp] theorem cases_zero {n} {C : fin (succ n) \u2192 Sort*} {H0 Hs} : @fin.cases n C H0 Hs 0 = H0 :=\nrfl\n\n@[simp] theorem cases_succ {n} {C : fin (succ n) \u2192 Sort*} {H0 Hs} (i : fin n) :\n  @fin.cases n C H0 Hs i.succ = Hs i :=\nby cases i; refl\n\n@[simp] theorem cases_succ' {n} {C : fin (succ n) \u2192 Sort*} {H0 Hs} {i : \u2115} (h : i + 1 < n + 1) :\n  @fin.cases n C H0 Hs \u27e8i.succ, h\u27e9 = Hs \u27e8i, lt_of_succ_lt_succ h\u27e9 :=\nby cases i; refl\n\nlemma forall_fin_succ {P : fin (n+1) \u2192 Prop} :\n  (\u2200 i, P i) \u2194 P 0 \u2227 (\u2200 i:fin n, P i.succ) :=\n\u27e8\u03bb H, \u27e8H 0, \u03bb i, H _\u27e9, \u03bb \u27e8H0, H1\u27e9 i, fin.cases H0 H1 i\u27e9\n\nlemma exists_fin_succ {P : fin (n+1) \u2192 Prop} :\n  (\u2203 i, P i) \u2194 P 0 \u2228 (\u2203i:fin n, P i.succ) :=\n\u27e8\u03bb \u27e8i, h\u27e9, fin.cases or.inl (\u03bb i hi, or.inr \u27e8i, hi\u27e9) i h,\n  \u03bb h, or.elim h (\u03bb h, \u27e80, h\u27e9) $ \u03bb\u27e8i, hi\u27e9, \u27e8i.succ, hi\u27e9\u27e9\n\nlemma forall_fin_one {p : fin 1 \u2192 Prop} : (\u2200 i, p i) \u2194 p 0 := @unique.forall_iff (fin 1) _ p\nlemma exists_fin_one {p : fin 1 \u2192 Prop} : (\u2203 i, p i) \u2194 p 0 := @unique.exists_iff (fin 1) _ p\n\nlemma forall_fin_two {p : fin 2 \u2192 Prop} : (\u2200 i, p i) \u2194 p 0 \u2227 p 1 :=\nforall_fin_succ.trans $ and_congr_right $ \u03bb _, forall_fin_one\n\nlemma exists_fin_two {p : fin 2 \u2192 Prop} : (\u2203 i, p i) \u2194 p 0 \u2228 p 1 :=\nexists_fin_succ.trans $ or_congr_right exists_fin_one\n\n/--\nDefine `C i` by reverse induction on `i : fin (n + 1)` via induction on the underlying `nat` value.\nThis function has two arguments: `hlast` handles the base case on `C (fin.last n)`,\nand `hs` defines the inductive step using `C i.succ`, inducting downwards.\n-/\n@[elab_as_eliminator]\ndef reverse_induction {n : \u2115}\n  {C : fin (n + 1) \u2192 Sort*}\n  (hlast : C (fin.last n))\n  (hs : \u2200 i : fin n, C i.succ \u2192 C i.cast_succ) :\n  \u03a0 (i : fin (n + 1)), C i\n| i :=\nif hi : i = fin.last n\nthen _root_.cast (by rw hi) hlast\nelse\n  let j : fin n := \u27e8i, lt_of_le_of_ne (nat.le_of_lt_succ i.2) (\u03bb h, hi (fin.ext h))\u27e9 in\n  have wf : n + 1 - j.succ < n + 1 - i, begin\n    cases i,\n    rw [tsub_lt_tsub_iff_left_of_le];\n    simp [*, nat.succ_le_iff],\n  end,\n  have hi : i = fin.cast_succ j, from fin.ext rfl,\n_root_.cast (by rw hi) (hs _ (reverse_induction j.succ))\nusing_well_founded { rel_tac := \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb i : fin (n+1), n + 1 - i)\u27e9],\n  dec_tac := `[assumption] }\n\n@[simp] lemma reverse_induction_last {n : \u2115}\n  {C : fin (n + 1) \u2192 Sort*}\n  (h0 : C (fin.last n))\n  (hs : \u2200 i : fin n, C i.succ \u2192 C i.cast_succ) :\n  (reverse_induction h0 hs (fin.last n) : C (fin.last n)) = h0 :=\nby rw [reverse_induction]; simp\n\n@[simp] lemma reverse_induction_cast_succ {n : \u2115}\n  {C : fin (n + 1) \u2192 Sort*}\n  (h0 : C (fin.last n))\n  (hs : \u2200 i : fin n, C i.succ \u2192 C i.cast_succ) (i : fin n):\n  (reverse_induction h0 hs i.cast_succ : C i.cast_succ) =\n    hs i (reverse_induction h0 hs i.succ) :=\nbegin\n  rw [reverse_induction, dif_neg (ne_of_lt (fin.cast_succ_lt_last i))],\n  cases i,\n  refl\nend\n\n/-- Define `f : \u03a0 i : fin n.succ, C i` by separately handling the cases `i = fin.last n` and\n`i = j.cast_succ`, `j : fin n`. -/\n@[elab_as_eliminator, elab_strategy]\ndef last_cases {n : \u2115} {C : fin (n + 1) \u2192 Sort*}\n  (hlast : C (fin.last n)) (hcast : (\u03a0 (i : fin n), C i.cast_succ)) (i : fin (n + 1)) : C i :=\nreverse_induction hlast (\u03bb i _, hcast i) i\n\n@[simp] lemma last_cases_last {n : \u2115} {C : fin (n + 1) \u2192 Sort*}\n  (hlast : C (fin.last n)) (hcast : (\u03a0 (i : fin n), C i.cast_succ)) :\n  (fin.last_cases hlast hcast (fin.last n): C (fin.last n)) = hlast :=\nreverse_induction_last _ _\n\n@[simp] lemma last_cases_cast_succ {n : \u2115} {C : fin (n + 1) \u2192 Sort*}\n  (hlast : C (fin.last n)) (hcast : (\u03a0 (i : fin n), C i.cast_succ)) (i : fin n) :\n  (fin.last_cases hlast hcast (fin.cast_succ i): C (fin.cast_succ i)) = hcast i :=\nreverse_induction_cast_succ _ _ _\n\n/-- Define `f : \u03a0 i : fin (m + n), C i` by separately handling the cases `i = cast_add n i`,\n`j : fin m` and `i = nat_add m j`, `j : fin n`. -/\n@[elab_as_eliminator, elab_strategy]\ndef add_cases {m n : \u2115} {C : fin (m + n) \u2192 Sort u}\n  (hleft : \u03a0 i, C (cast_add n i))\n  (hright : \u03a0 i, C (nat_add m i)) (i : fin (m + n)) : C i :=\nif hi : (i : \u2115) < m then eq.rec_on (cast_add_cast_lt n i hi) (hleft (cast_lt i hi))\nelse eq.rec_on (nat_add_sub_nat_cast (le_of_not_lt hi)) (hright _)\n\n@[simp] lemma add_cases_left {m n : \u2115} {C : fin (m + n) \u2192 Sort*}\n  (hleft : \u03a0 i, C (cast_add n i)) (hright : \u03a0 i, C (nat_add m i)) (i : fin m) :\n  add_cases hleft hright (fin.cast_add n i) = hleft i :=\nbegin\n  cases i with i hi,\n  rw [add_cases, dif_pos (cast_add_lt _ _)],\n  refl\nend\n\n@[simp] lemma add_cases_right {m n : \u2115} {C : fin (m + n) \u2192 Sort*}\n  (hleft : \u03a0 i, C (cast_add n i)) (hright : \u03a0 i, C (nat_add m i)) (i : fin n) :\n  add_cases hleft hright (nat_add m i) = hright i :=\nbegin\n  have : \u00ac (nat_add m i : \u2115) < m, from (le_coe_nat_add _ _).not_lt,\n  rw [add_cases, dif_neg this],\n  refine eq_of_heq ((eq_rec_heq _ _).trans _), congr' 1,\n  simp\nend\n\nend rec\n\nsection add_group\n\nopen nat int\n\n/-- Negation on `fin n` -/\ninstance (n : \u2115) : has_neg (fin n) :=\n\u27e8\u03bb a, \u27e8(n - a) % n, nat.mod_lt _ (lt_of_le_of_lt (nat.zero_le _) a.2)\u27e9\u27e9\n\n/-- Abelian group structure on `fin (n+1)`. -/\ninstance (n : \u2115) : add_comm_group (fin (n+1)) :=\n{ add_left_neg := \u03bb \u27e8a, ha\u27e9, fin.ext $ trans (nat.mod_add_mod _ _ _) $\n    by { rw [fin.coe_mk, fin.coe_zero, tsub_add_cancel_of_le, nat.mod_self], exact le_of_lt ha },\n  sub_eq_add_neg := \u03bb \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, fin.ext $\n    show (a + (n + 1 - b)) % (n + 1) = (a + (n + 1 - b) % (n + 1)) % (n + 1), by simp,\n  sub := fin.sub,\n  ..fin.add_comm_monoid n,\n  ..fin.has_neg n.succ }\n\nprotected lemma coe_neg (a : fin n) : ((-a : fin n) : \u2115) = (n - a) % n := rfl\n\nprotected lemma coe_sub (a b : fin n) : ((a - b : fin n) : \u2115) = (a + (n - b)) % n :=\nby cases a; cases b; refl\n\nend add_group\n\nsection succ_above\n\nlemma succ_above_aux (p : fin (n + 1)) :\n  strict_mono (\u03bb i : fin n, if i.cast_succ < p then i.cast_succ else i.succ) :=\n(cast_succ : fin n \u21aao _).strict_mono.ite (succ_embedding n).strict_mono\n  (\u03bb i j hij hj, lt_trans ((cast_succ : fin n \u21aao _).lt_iff_lt.2 hij) hj)\n  (\u03bb i, (cast_succ_lt_succ i).le)\n\n/-- `succ_above p i` embeds `fin n` into `fin (n + 1)` with a hole around `p`. -/\ndef succ_above (p : fin (n + 1)) : fin n \u21aao fin (n + 1) :=\norder_embedding.of_strict_mono _ p.succ_above_aux\n\n/-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)`\nembeds `i` by `cast_succ` when the resulting `i.cast_succ < p`. -/\nlemma succ_above_below (p : fin (n + 1)) (i : fin n) (h : i.cast_succ < p) :\n  p.succ_above i = i.cast_succ :=\nby { rw [succ_above], exact if_pos h }\n\n@[simp] lemma succ_above_ne_zero_zero {a : fin (n + 2)} (ha : a \u2260 0) : a.succ_above 0 = 0 :=\nbegin\n  rw fin.succ_above_below,\n  { refl },\n  { exact bot_lt_iff_ne_bot.mpr ha }\nend\n\nlemma succ_above_eq_zero_iff {a : fin (n + 2)} {b : fin (n + 1)} (ha : a \u2260 0) :\n  a.succ_above b = 0 \u2194 b = 0 :=\nby simp only [\u2190succ_above_ne_zero_zero ha, order_embedding.eq_iff_eq]\n\nlemma succ_above_ne_zero {a : fin (n + 2)} {b : fin (n + 1)} (ha : a \u2260 0) (hb : b \u2260 0) :\n  a.succ_above b \u2260 0 :=\nmt (succ_above_eq_zero_iff ha).mp hb\n\n/-- Embedding `fin n` into `fin (n + 1)` with a hole around zero embeds by `succ`. -/\n@[simp] lemma succ_above_zero : \u21d1(succ_above (0 : fin (n + 1))) = fin.succ := rfl\n\n/-- Embedding `fin n` into `fin (n + 1)` with a hole around `last n` embeds by `cast_succ`. -/\n@[simp] lemma succ_above_last : succ_above (fin.last n) = cast_succ :=\nby { ext, simp only [succ_above_below, cast_succ_lt_last] }\n\nlemma succ_above_last_apply (i : fin n) : succ_above (fin.last n) i = i.cast_succ :=\nby rw succ_above_last\n\n/-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)`\nembeds `i` by `succ` when the resulting `p < i.succ`. -/\nlemma succ_above_above (p : fin (n + 1)) (i : fin n) (h : p \u2264 i.cast_succ) :\n  p.succ_above i = i.succ :=\nby simp [succ_above, h.not_lt]\n\n/-- Embedding `i : fin n` into `fin (n + 1)` is always about some hole `p`. -/\nlemma succ_above_lt_ge (p : fin (n + 1)) (i : fin n) : i.cast_succ < p \u2228 p \u2264 i.cast_succ :=\nlt_or_ge (cast_succ i) p\n\n/-- Embedding `i : fin n` into `fin (n + 1)` is always about some hole `p`. -/\nlemma succ_above_lt_gt (p : fin (n + 1)) (i : fin n) : i.cast_succ < p \u2228 p < i.succ :=\nor.cases_on (succ_above_lt_ge p i)\n  (\u03bb h, or.inl h) (\u03bb h, or.inr (lt_of_le_of_lt h (cast_succ_lt_succ i)))\n\n/-- Embedding `i : fin n` into `fin (n + 1)` using a pivot `p` that is greater\nresults in a value that is less than `p`. -/\n@[simp] lemma succ_above_lt_iff (p : fin (n + 1)) (i : fin n) :\n  p.succ_above i < p \u2194 i.cast_succ < p :=\nbegin\n  refine iff.intro _ _,\n  { intro h,\n    cases succ_above_lt_ge p i with H H,\n    { exact H },\n    { rw succ_above_above _ _ H at h,\n      exact lt_trans (cast_succ_lt_succ i) h } },\n  { intro h,\n    rw succ_above_below _ _ h,\n    exact h }\nend\n\n/-- Embedding `i : fin n` into `fin (n + 1)` using a pivot `p` that is lesser\nresults in a value that is greater than `p`. -/\nlemma lt_succ_above_iff (p : fin (n + 1)) (i : fin n) : p < p.succ_above i \u2194 p \u2264 i.cast_succ :=\nbegin\n  refine iff.intro _ _,\n  { intro h,\n    cases succ_above_lt_ge p i with H H,\n    { rw succ_above_below _ _ H at h,\n      exact le_of_lt h },\n    { exact H } },\n  { intro h,\n    rw succ_above_above _ _ h,\n    exact lt_of_le_of_lt h (cast_succ_lt_succ i) },\nend\n\n/-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)`\nnever results in `p` itself -/\ntheorem succ_above_ne (p : fin (n + 1)) (i : fin n) : p.succ_above i \u2260 p :=\nbegin\n  intro eq,\n  by_cases H : i.cast_succ < p,\n  { simpa [lt_irrefl, \u2190succ_above_below _ _ H, eq] using H },\n  { simpa [\u2190succ_above_above _ _ (le_of_not_lt H), eq] using cast_succ_lt_succ i }\nend\n\n/-- Embedding a positive `fin n` results in a positive fin (n + 1)` -/\nlemma succ_above_pos (p : fin (n + 2)) (i : fin (n + 1)) (h : 0 < i) : 0 < p.succ_above i :=\nbegin\n  by_cases H : i.cast_succ < p,\n  { simpa [succ_above_below _ _ H] using cast_succ_pos h },\n  { simpa [succ_above_above _ _ (le_of_not_lt H)] using succ_pos _ },\nend\n\n@[simp] lemma succ_above_cast_lt {x y : fin (n + 1)} (h : x < y)\n  (hx : x.1 < n := lt_of_lt_of_le h y.le_last) :\n  y.succ_above (x.cast_lt hx) = x :=\nby { rw [succ_above_below, cast_succ_cast_lt], exact h }\n\n@[simp] lemma succ_above_pred {x y : fin (n + 1)} (h : x < y)\n  (hy : y \u2260 0 := (x.zero_le.trans_lt h).ne') :\n  x.succ_above (y.pred hy) = y :=\nby { rw [succ_above_above, succ_pred], simpa [le_iff_coe_le_coe] using nat.le_pred_of_lt h }\n\nlemma cast_lt_succ_above {x : fin n} {y : fin (n + 1)} (h : cast_succ x < y)\n  (h' : (y.succ_above x).1 < n := lt_of_lt_of_le ((succ_above_lt_iff _ _).2 h) (le_last y)) :\n  (y.succ_above x).cast_lt h' = x :=\nby simp only [succ_above_below _ _ h, cast_lt_cast_succ]\n\nlemma pred_succ_above {x : fin n} {y : fin (n + 1)} (h : y \u2264 cast_succ x)\n  (h' : y.succ_above x \u2260 0 := (y.zero_le.trans_lt $ (lt_succ_above_iff _ _).2 h).ne') :\n  (y.succ_above x).pred h' = x :=\nby simp only [succ_above_above _ _ h, pred_succ]\n\nlemma exists_succ_above_eq {x y : fin (n + 1)} (h : x \u2260 y) : \u2203 z, y.succ_above z = x :=\nbegin\n  cases h.lt_or_lt with hlt hlt,\n  exacts [\u27e8_, succ_above_cast_lt hlt\u27e9, \u27e8_, succ_above_pred hlt\u27e9],\nend\n\n@[simp] lemma exists_succ_above_eq_iff {x y : fin (n + 1)} : (\u2203 z, x.succ_above z = y) \u2194 y \u2260 x :=\nbegin\n  refine \u27e8_, exists_succ_above_eq\u27e9,\n  rintro \u27e8y, rfl\u27e9,\n  exact succ_above_ne _ _\nend\n\n/-- The range of `p.succ_above` is everything except `p`. -/\n@[simp] lemma range_succ_above (p : fin (n + 1)) : set.range (p.succ_above) = {p}\u1d9c :=\nset.ext $ \u03bb _, exists_succ_above_eq_iff\n\n/-- Given a fixed pivot `x : fin (n + 1)`, `x.succ_above` is injective -/\nlemma succ_above_right_injective {x : fin (n + 1)} : injective (succ_above x) :=\n(succ_above x).injective\n\n/-- Given a fixed pivot `x : fin (n + 1)`, `x.succ_above` is injective -/\nlemma succ_above_right_inj {x : fin (n + 1)} :\n  x.succ_above a = x.succ_above b \u2194 a = b :=\nsucc_above_right_injective.eq_iff\n\n/-- `succ_above` is injective at the pivot -/\nlemma succ_above_left_injective : injective (@succ_above n) :=\n\u03bb _ _ h, by simpa [range_succ_above] using congr_arg (\u03bb f : fin n \u21aao fin (n + 1), (set.range f)\u1d9c) h\n\n/-- `succ_above` is injective at the pivot -/\n@[simp] lemma succ_above_left_inj {x y : fin (n + 1)} :\n  x.succ_above = y.succ_above \u2194 x = y :=\nsucc_above_left_injective.eq_iff\n\n@[simp] lemma zero_succ_above {n : \u2115} (i : fin n) :\n  (0 : fin (n + 1)).succ_above i = i.succ :=\nrfl\n\n@[simp] lemma succ_succ_above_zero {n : \u2115} (i : fin (n + 1)) :\n  (i.succ).succ_above 0 = 0 :=\nsucc_above_below _ _ (succ_pos _)\n\n@[simp] lemma succ_succ_above_succ {n : \u2115} (i : fin (n + 1)) (j : fin n) :\n  (i.succ).succ_above j.succ = (i.succ_above j).succ :=\n(lt_or_ge j.cast_succ i).elim\n  (\u03bb h, have h' : j.succ.cast_succ < i.succ, by simpa [lt_iff_coe_lt_coe] using h,\n        by { ext, simp [succ_above_below _ _ h, succ_above_below _ _ h'] })\n  (\u03bb h, have h' : i.succ \u2264 j.succ.cast_succ, by simpa [le_iff_coe_le_coe] using h,\n        by { ext, simp [succ_above_above _ _ h, succ_above_above _ _ h'] })\n\n@[simp] lemma one_succ_above_zero {n : \u2115} :\n  (1 : fin (n + 2)).succ_above 0 = 0 :=\nsucc_succ_above_zero 0\n\n/-- By moving `succ` to the outside of this expression, we create opportunities for further\nsimplification using `succ_above_zero` or `succ_succ_above_zero`. -/\n@[simp] lemma succ_succ_above_one {n : \u2115} (i : fin (n + 2)) :\n  (i.succ).succ_above 1 = (i.succ_above 0).succ :=\nsucc_succ_above_succ i 0\n\n@[simp] lemma one_succ_above_succ {n : \u2115} (j : fin n) :\n  (1 : fin (n + 2)).succ_above j.succ = j.succ.succ :=\nsucc_succ_above_succ 0 j\n\n@[simp] lemma one_succ_above_one {n : \u2115} :\n  (1 : fin (n + 3)).succ_above 1 = 2 :=\nsucc_succ_above_succ 0 0\n\nend succ_above\n\nsection pred_above\n\n/-- `pred_above p i` embeds `i : fin (n+1)` into `fin n` by subtracting one if `p < i`. -/\ndef pred_above (p : fin n) (i : fin (n+1)) : fin n :=\nif h : p.cast_succ < i then\n  i.pred (ne_of_lt (lt_of_le_of_lt (zero_le p.cast_succ) h)).symm\nelse\n  i.cast_lt (lt_of_le_of_lt (le_of_not_lt h) p.2)\n\nlemma pred_above_right_monotone (p : fin n) : monotone p.pred_above :=\n\u03bb a b H,\nbegin\n  dsimp [pred_above],\n  split_ifs with ha hb hb,\n  all_goals { simp only [le_iff_coe_le_coe, coe_pred], },\n  { exact pred_le_pred H, },\n  { calc _ \u2264 _ : nat.pred_le _\n        ... \u2264 _ : H, },\n  { simp at ha, exact le_pred_of_lt (lt_of_le_of_lt ha hb), },\n  { exact H, },\nend\n\nlemma pred_above_left_monotone (i : fin (n + 1)) : monotone (\u03bb p, pred_above p i) :=\n\u03bb a b H,\nbegin\n  dsimp [pred_above],\n  split_ifs with ha hb hb,\n  all_goals { simp only [le_iff_coe_le_coe, coe_pred] },\n  { exact pred_le _, },\n  { have : b < a := cast_succ_lt_cast_succ_iff.mpr (hb.trans_le (le_of_not_gt ha)),\n    exact absurd H this.not_le }\nend\n\n/-- `cast_pred` embeds `i : fin (n + 2)` into `fin (n + 1)`\nby lowering just `last (n + 1)` to `last n`. -/\ndef cast_pred (i : fin (n + 2)) : fin (n + 1) :=\npred_above (last n) i\n\n@[simp] lemma cast_pred_zero : cast_pred (0 : fin (n + 2)) = 0 := rfl\n\n@[simp] lemma cast_pred_one : cast_pred (1 : fin (n + 2)) = 1 :=\nby { cases n, apply subsingleton.elim, refl }\n\n@[simp] theorem pred_above_zero {i : fin (n + 2)} (hi : i \u2260 0) :\n  pred_above 0 i = i.pred hi :=\nbegin\n  dsimp [pred_above],\n  rw dif_pos,\n  exact (pos_iff_ne_zero _).mpr hi,\nend\n\n@[simp] lemma cast_pred_last : cast_pred (last (n + 1)) = last n :=\nby simp [eq_iff_veq, cast_pred, pred_above, cast_succ_lt_last]\n\n@[simp] lemma cast_pred_mk (n i : \u2115) (h : i < n + 1) :\n  cast_pred \u27e8i, lt_succ_of_lt h\u27e9 = \u27e8i, h\u27e9 :=\nbegin\n  have : \u00accast_succ (last n) < \u27e8i, lt_succ_of_lt h\u27e9,\n  { simpa [lt_iff_coe_lt_coe] using le_of_lt_succ h },\n  simp [cast_pred, pred_above, this]\nend\n\nlemma pred_above_below (p : fin (n + 1)) (i : fin (n + 2)) (h : i \u2264 p.cast_succ) :\n  p.pred_above i = i.cast_pred :=\nbegin\n  have : i \u2264 (last n).cast_succ := h.trans p.le_last,\n  simp [pred_above, cast_pred, h.not_lt, this.not_lt]\nend\n\n@[simp] lemma pred_above_last : pred_above (fin.last n) = cast_pred := rfl\n\nlemma pred_above_last_apply (i : fin n) : pred_above (fin.last n) i = i.cast_pred :=\nby rw pred_above_last\n\nlemma pred_above_above (p : fin n) (i : fin (n + 1)) (h : p.cast_succ < i) :\n  p.pred_above i = i.pred (p.cast_succ.zero_le.trans_lt h).ne.symm :=\nby simp [pred_above, h]\n\nlemma cast_pred_monotone : monotone (@cast_pred n) :=\npred_above_right_monotone (last _)\n\n/-- Sending `fin (n+1)` to `fin n` by subtracting one from anything above `p`\nthen back to `fin (n+1)` with a gap around `p` is the identity away from `p`. -/\n@[simp] lemma succ_above_pred_above {p : fin n} {i : fin (n + 1)} (h : i \u2260 p.cast_succ) :\n  p.cast_succ.succ_above (p.pred_above i) = i :=\nbegin\n  dsimp [pred_above, succ_above],\n  rcases p with \u27e8p, _\u27e9,\n  rcases i with \u27e8i, _\u27e9,\n  cases lt_or_le i p with H H,\n  { rw dif_neg, rw if_pos, refl, exact H, simp, apply le_of_lt H, },\n  { rw dif_pos, rw if_neg,\n    swap 3, -- For some reason `simp` doesn't fire fully unless we discharge the third goal.\n    { exact lt_of_le_of_ne H (ne.symm h), },\n    { simp, },\n    { simp only [subtype.mk_eq_mk, ne.def, fin.cast_succ_mk] at h,\n      simp only [pred, subtype.mk_lt_mk, not_lt],\n      exact nat.le_pred_of_lt (nat.lt_of_le_and_ne H (ne.symm h)), }, },\nend\n\n/-- Sending `fin n` into `fin (n + 1)` with a gap at `p`\nthen back to `fin n` by subtracting one from anything above `p` is the identity. -/\n@[simp] lemma pred_above_succ_above (p : fin n) (i : fin n) :\n  p.pred_above (p.cast_succ.succ_above i) = i :=\nbegin\n  dsimp [pred_above, succ_above],\n  rcases p with \u27e8p, _\u27e9,\n  rcases i with \u27e8i, _\u27e9,\n  split_ifs,\n  { rw dif_neg,\n    { refl },\n    { simp_rw [if_pos h],\n      simp only [subtype.mk_lt_mk, not_lt],\n      exact le_of_lt h, }, },\n  { rw dif_pos,\n    { refl, },\n    { simp_rw [if_neg h],\n      exact lt_succ_iff.mpr (not_lt.mp h), }, },\nend\n\nlemma cast_succ_pred_eq_pred_cast_succ  {a : fin (n + 1)} (ha : a \u2260 0)\n  (ha' := a.cast_succ_ne_zero_iff.mpr ha) : (a.pred ha).cast_succ = a.cast_succ.pred ha' :=\nby { cases a, refl }\n\n/-- `pred` commutes with `succ_above`. -/\nlemma pred_succ_above_pred {a : fin (n + 2)} {b : fin (n + 1)} (ha : a \u2260 0) (hb : b \u2260 0)\n  (hk := succ_above_ne_zero ha hb) :\n  (a.pred ha).succ_above (b.pred hb) = (a.succ_above b).pred hk :=\nbegin\n  obtain hbelow | habove := lt_or_le b.cast_succ a, -- `rwa` uses them\n  { rw fin.succ_above_below,\n    { rwa [cast_succ_pred_eq_pred_cast_succ , fin.pred_inj, fin.succ_above_below] },\n    { rwa [cast_succ_pred_eq_pred_cast_succ , pred_lt_pred_iff] } },\n  { rw fin.succ_above_above,\n    have : (b.pred hb).succ = b.succ.pred (fin.succ_ne_zero _), by rw [succ_pred, pred_succ],\n    { rwa [this, fin.pred_inj, fin.succ_above_above] },\n    { rwa [cast_succ_pred_eq_pred_cast_succ , fin.pred_le_pred_iff] } }\nend\n\n@[simp] theorem cast_pred_cast_succ (i : fin (n + 1)) :\n  cast_pred i.cast_succ = i :=\nby simp [cast_pred, pred_above, le_last]\n\nlemma cast_succ_cast_pred {i : fin (n + 2)} (h : i < last _) : cast_succ i.cast_pred = i :=\nbegin\n  rw [cast_pred, pred_above, dif_neg],\n  { simp [fin.eq_iff_veq] },\n  { exact h.not_le }\nend\n\nlemma coe_cast_pred_le_self (i : fin (n + 2)) : (i.cast_pred : \u2115) \u2264 i :=\nbegin\n  rcases i.le_last.eq_or_lt with rfl|h,\n  { simp },\n  { rw [cast_pred, pred_above, dif_neg],\n    { simp },\n    { simpa [lt_iff_coe_lt_coe, le_iff_coe_le_coe, lt_succ_iff] using h } }\nend\n\nlemma coe_cast_pred_lt_iff {i : fin (n + 2)} : (i.cast_pred : \u2115) < i \u2194 i = fin.last _ :=\nbegin\n  rcases i.le_last.eq_or_lt with rfl|H,\n  { simp },\n  { simp only [ne_of_lt H],\n    rw \u2190cast_succ_cast_pred H,\n    simp }\nend\n\nlemma lt_last_iff_coe_cast_pred {i : fin (n + 2)} : i < fin.last _ \u2194 (i.cast_pred : \u2115) = i :=\nbegin\n  rcases i.le_last.eq_or_lt with rfl|H,\n  { simp },\n  { simp only [H],\n    rw \u2190cast_succ_cast_pred H,\n    simp }\nend\n\nend pred_above\n\n/-- `min n m` as an element of `fin (m + 1)` -/\ndef clamp (n m : \u2115) : fin (m + 1) := of_nat $ min n m\n\n@[simp] lemma coe_clamp (n m : \u2115) : (clamp n m : \u2115) = min n m :=\nnat.mod_eq_of_lt $ nat.lt_succ_iff.mpr $ min_le_right _ _\n\n@[simp]\nlemma coe_of_nat_eq_mod (m n : \u2115) :\n  ((n : fin (succ m)) : \u2115) = n % succ m :=\nby rw [\u2190 of_nat_eq_coe]; refl\n\n@[simp] lemma coe_of_nat_eq_mod' (m n : \u2115) [I : fact (0 < m)] :\n  (@fin.of_nat' _ I n : \u2115) = n % m :=\nrfl\n\nsection mul\n\n/-!\n### mul\n-/\n\nlemma val_mul {n : \u2115} :  \u2200 a b : fin n, (a * b).val = (a.val * b.val) % n\n| \u27e8_, _\u27e9 \u27e8_, _\u27e9 := rfl\n\nlemma coe_mul {n : \u2115} :  \u2200 a b : fin n, ((a * b : fin n) : \u2115) = (a * b) % n\n| \u27e8_, _\u27e9 \u27e8_, _\u27e9 := rfl\n\n@[simp] protected lemma mul_one (k : fin (n + 1)) : k * 1 = k :=\nby { cases n, simp, simp [eq_iff_veq, mul_def, mod_eq_of_lt (is_lt k)] }\n\n@[simp] protected lemma one_mul (k : fin (n + 1)) : (1 : fin (n + 1)) * k = k :=\nby { cases n, simp, simp [eq_iff_veq, mul_def, mod_eq_of_lt (is_lt k)] }\n\n@[simp] protected lemma mul_zero (k : fin (n + 1)) : k * 0 = 0 :=\nby simp [eq_iff_veq, mul_def]\n\n@[simp] protected lemma zero_mul (k : fin (n + 1)) : (0 : fin (n + 1)) * k = 0 :=\nby simp [eq_iff_veq, mul_def]\n\nend mul\n\nend fin\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/fin/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7357442023061819}}
{"text": "import BrownCs22.Library.Tactics\nimport BrownCs22.Library.Defs\n\n-- don't change these lines\nnamespace HW3\nopen Set BrownCs22.Set\nset_option linter.unusedVariables false\nvariable (U : Type)\nvariable (A B : Set U)\n\n/-\n\n# Welcome to the Lean section of HW3!\n\nIn these problems, we're going to get a little practice formally proving \nset equalities. We've seen two techniques for doing this on paper:\n\n* With the set-element method, we argue that `A = B` by showing that \n  `A \u2286 B` and `B \u2286 A`.\n* With the algebraic method, we can prove that sets are equal by rewriting\n  one or both sides with algebraic identities like `(A\u1d9c)\u1d9c = A`, until we \n  have identical expressions.\n\nWe can do both of these in Lean. In this assignment you'll prove two \nset equalities, one with each method.\n\n**Notes**: \n\n* Remember that in Lean, we write \"the complement of A\" as `A\u1d9c` instead \n  of using a bar over the letter. (Diacritics are hard in a text editor!)\n\n* You can type `\u2286` using `\\sub`.\n\n* You can type `\u1d9c` using `\\compl` or `\\^c`.\n\n-/\n\n\n/-\n\n## Problem 1: the set-element method\n\nWe saw two important tactics in lecture for set-element proofs in Lean:\n\n* `ext x`: given a goal `A = B` where `A` and `B` are sets, changes the goal\n  to showing `x \u2208 A \u2194 x \u2208 B` for an arbitrary element `x`. The name comes \n  from \"extensionality,\" the property that two sets are equal if they have\n  the same elements.\n\n* `set_simplify`: unfolds the \"logic\" of a set membership proposition. \n  For instance, `x \u2208 A \u2229 B` simplifies to `x \u2208 A \u2227 x \u2208 B`. \n  `x \u2208 A \\ C` simplifies to `x \u2208 A \u2227 \u00ac(x \u2208 C)`.\n  Calling `set_simplify` will simplify the goal and all hypotheses.\n\nUse these techniques to prove the following.\nStarting with `ext x` is probably a good move!\nThen think about the last few homeworks; how do you prove an `\u2194` goal?\n\n-/\n\n/- 4 points -/\ntheorem problem_1 : (A \u2229 B) \u222a A = A := by \n  sorry\n\n\n/-\n\n## Problem 2: the algebraic method\n\nWhat you just proved is sometimes called an \"absorption law,\" since the \nintersection `A \u2229 B` gets \"absorbed\" into the bigger set `A`.\nThis is an example of a useful rewrite rule: if we ever see the pattern \n`X \u222a (X \u2229 Y)` in a proposition, we can replace it with `X`, since we know\nthat these sets are the same. \n\nAs we saw in Lecture 8, the `rewrite` tactic lets us do this in Lean. \nHere's an example of using the above rule, and another useful rewrite rule:\n\n-/\n\n\nexample : A \u2229 ((A\u1d9c \u2229 B) \u222a A\u1d9c) = \u2205 := by \n  rewrite [inter_union_cancel_left]\n  rewrite [inter_compl_self]\n  reflexivity\n\n/-\n\nThe name Lean gives to our identity from problem 1 is \n`inter_union_cancel_left`. We also used `inter_compl_self`, which says \n`A \u2229 A\u1d9c = \u2205`. Hover over the name in the proof above to see this statement!\n\nThe final tactic, `reflexivity`, tells Lean that we are done: we can close\nany goal of the form `P \u2194 P`.\n\nThe `rewrite` tactic will use the identity \"left to right\":\nit will look for the pattern on the left hand side of the identity,\nand replace it with the right hand side. For example, `inter_compl_self`\nsays that `s \u2229 s\u1d9c = \u2205`, so it replaces `s \u2229 s\u1d9c` with `\u2205`.\nSometimes you can use a rule in reverse direction, right to left,\nusing the symbol `\u2190` (typed `\\l` or `\\<-`). For example:\n\n-/ \n\nexample : A\u1d9c \u2229 A\u1d9c = A\u1d9c := by \n  rewrite [\u2190 compl_union] -- we have used de morgan's law \"backward\",\n                          -- changing `A\u1d9c \u2229 A\u1d9c` to `(A \u222a A)\u1d9c`.\n  rewrite [union_self] \n  reflexivity\n\n/-\nBut this won't work for every identity! Think about `inter_compl_self`.\nBackward, this would say that if you see the pattern `\u2205`, you can replace \nit with `s \u2229 s\u1d9c`. But how would Lean know what set `s` you wanted to use?\nIt could be anything! If you see some funny symbols like `?m1000`,\nthis is probably what's going on.\n\nYou may or may not need to use rules backwards in the following problem.\n\n\nIn recitation, you saw (or will see) a list of set identities:\n<https://brown-cs22.github.io/resources/math-resources/sets.pdf>\nAll the identities on this list are available as rewrite rules in Lean,\nlisted in the file `BrownCs22/Demos/SetIdentities.lean`.\n\nUse these rewrite rules to complete the following proof. Your proof should\nhave the same structure as the example above: \na sequence of rewrites, followed by `reflexivity`.\n\nIt might help to plan out your steps on paper!\n\n-/\n\n/- 4 points -/\ntheorem problem_2 : (A\u1d9c \\ B)\u1d9c = A \u222a B := by \n  sorry\n\n\n\n\n\nend HW3", "meta": {"author": "brown-cs22", "repo": "CS22-Lean-2023", "sha": "ad33820fb600dadb2306dadfc74f44629397add2", "save_path": "github-repos/lean/brown-cs22-CS22-Lean-2023", "path": "github-repos/lean/brown-cs22-CS22-Lean-2023/CS22-Lean-2023-ad33820fb600dadb2306dadfc74f44629397add2/BrownCs22/Homework/Hw3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7357441991454464}}
{"text": "import incidence_world.level02 --hide\nopen IncidencePlane --hide\n\n/-\n# Incidence World\n\n## Level 3: proving useful lemmas (II).\n\nIf you look at the list of your theorem statements, you will note that the lemma of the previous level has been added. Despite not\nbeing useful now, it will come handy for next levels. Analogously, the lemma of this level will be added to the list of theorem \nstatements, so that the computer can remember it in case you need to use it again.\n\nTo solve this level, you just need three lines of code. Try to finish it by your own. Here you have a clue for each of the lines:\n\n**Line 1:** Remember that a goal of the form `\u22a2 P \u2260 Q` can be read as `\u22a2 (P = Q) \u2192 false` as well.\n\n**Line 2:** If you have the hypotheses `h : A = B` and `h2 : A \u2208 r`, then `rw h at h2,` will change `h2` into `h2 : B \u2208 r`.\n\n**Line 3:** If the current goal is `\u22a2 false` and you have the hypotheses `h : \u00ac P` and `h2 : P`, which contradict each other, then `tauto,`\nwill make progress.\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nRemember that `\u00ac P` is the same as `P \u2192 false`, so `intro` may get you going. \nStill bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution. \n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables  {P Q: \u03a9} {r : Line \u03a9}  -- hide\n\n/- Lemma :\nIf a point P is in a line and a point Q is not, then they are different.\n-/\nlemma point_in_line_not_point (hP : P \u2208 r) (hQ : Q \u2209 r): P \u2260 Q :=\nbegin\n\n  intro H,\n  rw H at hP,\n  tauto,\n\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/incidence_world/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7356861649804954}}
{"text": "/-\nCopyright (c) 2014 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Jeremy Avigad\n-/\nimport data.nat.basic\n\n/-!\n#  Distance function on \u2115\n\nThis file defines a simple distance function on naturals from truncated substraction.\n-/\n\nnamespace nat\n\n/-- Distance (absolute value of difference) between natural numbers. -/\ndef dist (n m : \u2115) := (n - m) + (m - n)\n\ntheorem dist.def (n m : \u2115) : dist n m = (n - m) + (m - n) := rfl\n\ntheorem dist_comm (n m : \u2115) : dist n m = dist m n :=\nby simp [dist.def, add_comm]\n\n@[simp] theorem dist_self (n : \u2115) : dist n n = 0 :=\nby simp [dist.def, tsub_self]\n\ntheorem eq_of_dist_eq_zero {n m : \u2115} (h : dist n m = 0) : n = m :=\nhave n - m = 0, from nat.eq_zero_of_add_eq_zero_right h,\nhave n \u2264 m, from tsub_eq_zero_iff_le.mp this,\nhave m - n = 0, from nat.eq_zero_of_add_eq_zero_left h,\nhave m \u2264 n, from tsub_eq_zero_iff_le.mp this,\nle_antisymm \u2039n \u2264 m\u203a \u2039m \u2264 n\u203a\n\ntheorem dist_eq_zero {n m : \u2115} (h : n = m) : dist n m = 0 :=\nbegin rw [h, dist_self] end\n\n\n\ntheorem dist_eq_sub_of_le_right {n m : \u2115} (h : m \u2264 n) : dist n m = n - m :=\nbegin rw [dist_comm], apply dist_eq_sub_of_le h end\n\ntheorem dist_tri_left (n m : \u2115) : m \u2264 dist n m + n :=\nle_trans le_tsub_add (add_le_add_right (nat.le_add_left _ _) _)\n\ntheorem dist_tri_right (n m : \u2115) : m \u2264 n + dist n m :=\nby rw add_comm; apply dist_tri_left\n\ntheorem dist_tri_left' (n m : \u2115) : n \u2264 dist n m + m :=\nby rw dist_comm; apply dist_tri_left\n\ntheorem dist_tri_right' (n m : \u2115) : n \u2264 m + dist n m :=\nby rw dist_comm; apply dist_tri_right\n\ntheorem dist_zero_right (n : \u2115) : dist n 0 = n :=\neq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n)\n\ntheorem dist_zero_left (n : \u2115) : dist 0 n = n :=\neq.trans (dist_eq_sub_of_le (zero_le n)) (tsub_zero n)\n\ntheorem dist_add_add_right (n k m : \u2115) : dist (n + k) (m + k) = dist n m :=\ncalc\n  dist (n + k) (m + k) = ((n + k) - (m + k)) + ((m + k)-(n + k)) : rfl\n                   ... = (n - m) + ((m + k) - (n + k))   : by rw add_tsub_add_eq_tsub_right\n                   ... = (n - m) + (m - n)               : by rw add_tsub_add_eq_tsub_right\n\ntheorem dist_add_add_left (k n m : \u2115) : dist (k + n) (k + m) = dist n m :=\nbegin rw [add_comm k n, add_comm k m], apply dist_add_add_right end\n\ntheorem dist_eq_intro {n m k l : \u2115} (h : n + m = k + l) : dist n k = dist l m :=\ncalc\n  dist n k = dist (n + m) (k + m) : by rw dist_add_add_right\n       ... = dist (k + l) (k + m) : by rw h\n       ... = dist l m             : by rw dist_add_add_left\n\ntheorem dist.triangle_inequality (n m k : \u2115) : dist n k \u2264 dist n m + dist m k :=\nhave dist n m + dist m k = (n - m) + (m - k) + ((k - m) + (m - n)),\n  by simp [dist.def, add_comm, add_left_comm],\nby { rw [this, dist.def], exact add_le_add tsub_le_tsub_add_tsub tsub_le_tsub_add_tsub }\n\ntheorem dist_mul_right (n k m : \u2115) : dist (n * k) (m * k) = dist n m * k :=\nby rw [dist.def, dist.def, right_distrib, tsub_mul, tsub_mul]\n\ntheorem dist_mul_left (k n m : \u2115) : dist (k * n) (k * m) = k * dist n m :=\nby rw [mul_comm k n, mul_comm k m, dist_mul_right, mul_comm]\n\n-- TODO(Jeremy): do when we have max and minx\n--theorem dist_eq_max_sub_min {i j : nat} : dist i j = (max i j) - min i j :=\n--sorry\n/-\nor.elim (lt_or_ge i j)\n  (assume : i < j,\n    by rw [max_eq_right_of_lt this, min_eq_left_of_lt this, dist_eq_sub_of_lt this])\n  (assume : i \u2265 j,\n    by rw [max_eq_left this , min_eq_right this, dist_eq_sub_of_le_right this])\n-/\n\ntheorem dist_succ_succ {i j : nat} : dist (succ i) (succ j) = dist i j :=\nby simp [dist.def, succ_sub_succ]\n\ntheorem dist_pos_of_ne {i j : nat} : i \u2260 j \u2192 0 < dist i j :=\nassume hne, nat.lt_by_cases\n  (assume : i < j,\n     begin rw [dist_eq_sub_of_le (le_of_lt this)], apply tsub_pos_of_lt this end)\n  (assume : i = j, by contradiction)\n  (assume : i > j,\n     begin rw [dist_eq_sub_of_le_right (le_of_lt this)], apply tsub_pos_of_lt this end)\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912849, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7356861626737379}}
{"text": "/-\nCopyright (c) 2021 Henry Swanson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henry Swanson, Patrick Massot\n-/\nimport analysis.special_functions.exponential\nimport combinatorics.derangements.finite\nimport order.filter.basic\n\n/-!\n# Derangement exponential series\n\nThis file proves that the probability of a permutation on n elements being a derangement is 1/e.\nThe specific lemma is `num_derangements_tendsto_inv_e`.\n-/\nopen filter\n\nopen_locale big_operators\nopen_locale topology\n\ntheorem num_derangements_tendsto_inv_e :\n  tendsto (\u03bb n, (num_derangements n : \u211d) / n.factorial) at_top\n  (\ud835\udcdd (real.exp (-1))) :=\nbegin\n  -- we show that d(n)/n! is the partial sum of exp(-1), but offset by 1.\n  -- this isn't entirely obvious, since we have to ensure that asc_factorial and\n  -- factorial interact in the right way, e.g., that k \u2264 n always\n  let s : \u2115 \u2192 \u211d := \u03bb n, \u2211 k in finset.range n, (-1 : \u211d)^k / k.factorial,\n  suffices : \u2200 n : \u2115, (num_derangements n : \u211d) / n.factorial = s(n+1),\n  { simp_rw this,\n    -- shift the function by 1, and then use the fact that the partial sums\n    -- converge to the infinite sum\n    rw tendsto_add_at_top_iff_nat 1,\n    apply has_sum.tendsto_sum_nat,\n    -- there's no specific lemma for \u211d that \u2211 x^k/k! sums to exp(x), but it's\n    -- true in more general fields, so use that lemma\n    rw real.exp_eq_exp_\u211d,\n    exact exp_series_div_has_sum_exp \u211d (-1 : \u211d) },\n  intro n,\n  rw [\u2190 int.cast_coe_nat, num_derangements_sum],\n  push_cast,\n  rw finset.sum_div,\n  -- get down to individual terms\n  refine finset.sum_congr (refl _) _,\n  intros k hk,\n  have h_le : k \u2264 n := finset.mem_range_succ_iff.mp hk,\n  rw [nat.asc_factorial_eq_div, add_tsub_cancel_of_le h_le],\n  push_cast [nat.factorial_dvd_factorial h_le],\n  field_simp [nat.factorial_ne_zero],\n  ring,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/derangements/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7356784641883376}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport data.fin\nimport data.equiv.basic\nimport tactic.norm_num\n\n/-!\n# Equivalences for `fin n`\n-/\n\nuniverse variables u\n\nvariables {m n : \u2115}\n\n/-- Equivalence between `fin 0` and `empty`. -/\ndef fin_zero_equiv : fin 0 \u2243 empty :=\n\u27e8fin_zero_elim, empty.elim, assume a, fin_zero_elim a, assume a, empty.elim a\u27e9\n\n/-- Equivalence between `fin 0` and `pempty`. -/\ndef fin_zero_equiv' : fin 0 \u2243 pempty.{u} :=\nequiv.equiv_pempty fin.elim0\n\n/-- Equivalence between `fin 1` and `punit`. -/\ndef fin_one_equiv : fin 1 \u2243 punit :=\n\u27e8\u03bb_, (), \u03bb_, 0, fin.cases rfl (\u03bba, fin_zero_elim a), assume \u27e8\u27e9, rfl\u27e9\n\n/-- Equivalence between `fin 2` and `bool`. -/\ndef fin_two_equiv : fin 2 \u2243 bool :=\n\u27e8@fin.cases 1 (\u03bb_, bool) ff (\u03bb_, tt),\n  \u03bbb, cond b 1 0,\n  begin\n    refine fin.cases _ _, by norm_num,\n    refine fin.cases _ _, by norm_num,\n    exact \u03bbi, fin_zero_elim i\n  end,\n  begin\n    rintro \u27e8_|_\u27e9,\n    { refl },\n    { rw \u2190 fin.succ_zero_eq_one, refl }\n  end\u27e9\n\n/-- The 'identity' equivalence between `fin n` and `fin m` when `n = m`. -/\ndef fin_congr {n m : \u2115} (h : n = m) : fin n \u2243 fin m :=\nequiv.subtype_equiv_right (\u03bb x, by subst h)\n\n@[simp] lemma fin_congr_apply_mk {n m : \u2115} (h : n = m) (k : \u2115) (w : k < n) :\n  fin_congr h \u27e8k, w\u27e9 = \u27e8k, by { subst h, exact w }\u27e9 :=\nrfl\n\n@[simp] lemma fin_congr_symm {n m : \u2115} (h : n = m) :\n  (fin_congr h).symm = fin_congr h.symm := rfl\n\n@[simp] lemma fin_congr_apply_coe {n m : \u2115} (h : n = m) (k : fin n) :\n  (fin_congr h k : \u2115) = k :=\nby { cases k, refl, }\n\nlemma fin_congr_symm_apply_coe {n m : \u2115} (h : n = m) (k : fin m) :\n  ((fin_congr h).symm k : \u2115) = k :=\nby { cases k, refl, }\n\n/-- An equivalence that removes `i` and maps it to `none`.\nThis is a version of `fin.pred_above` that produces `option (fin n)` instead of\nmapping both `i.cast_succ` and `i.succ` to `i`. -/\ndef fin_succ_equiv' {n : \u2115} (i : fin n) :\n  fin (n + 1) \u2243 option (fin n) :=\n{ to_fun := \u03bb x, if x = i.cast_succ then none else some (i.pred_above x),\n  inv_fun := \u03bb x, x.cases_on' i.cast_succ (fin.succ_above i.cast_succ),\n  left_inv := \u03bb x, if h : x = i.cast_succ then by simp [h]\n                   else by simp [h, fin.succ_above_ne],\n  right_inv := \u03bb x, by { cases x; simp [fin.succ_above_ne] }}\n\n@[simp] lemma fin_succ_equiv'_at {n : \u2115} (i : fin (n + 1)) :\n  (fin_succ_equiv' i) i.cast_succ = none := by simp [fin_succ_equiv']\n\nlemma fin_succ_equiv'_below {n : \u2115} {i m : fin (n + 1)} (h : m < i) :\n  (fin_succ_equiv' i) m.cast_succ = some m :=\nbegin\n  have : m.cast_succ \u2264 i.cast_succ := h.le,\n  simp [fin_succ_equiv', h.ne, fin.pred_above_below, this]\nend\n\nlemma fin_succ_equiv'_above {n : \u2115} {i m : fin (n + 1)} (h : i \u2264 m) :\n  (fin_succ_equiv' i) m.succ = some m :=\nbegin\n  have : i.cast_succ < m.succ,\n    { refine (lt_of_le_of_lt _ m.cast_succ_lt_succ), exact h },\n  simp [fin_succ_equiv', this, fin.pred_above_above, ne_of_gt]\nend\n\n@[simp] lemma fin_succ_equiv'_symm_none {n : \u2115} (i : fin (n + 1)) :\n  (fin_succ_equiv' i).symm none = i.cast_succ := rfl\n\nlemma fin_succ_equiv_symm'_some_below {n : \u2115} {i m : fin (n + 1)} (h : m < i) :\n  (fin_succ_equiv' i).symm (some m) = m.cast_succ :=\nby simp [fin_succ_equiv', ne_of_gt h, fin.succ_above, not_le_of_gt h]\n\nlemma fin_succ_equiv_symm'_some_above {n : \u2115} {i m : fin (n + 1)} (h : i \u2264 m) :\n  (fin_succ_equiv' i).symm (some m) = m.succ :=\nby simp [fin_succ_equiv', fin.succ_above, h.not_lt]\n\nlemma fin_succ_equiv_symm'_coe_below {n : \u2115} {i m : fin (n + 1)} (h : m < i) :\n  (fin_succ_equiv' i).symm m = m.cast_succ :=\nby { convert fin_succ_equiv_symm'_some_below h; simp }\n\nlemma fin_succ_equiv_symm'_coe_above {n : \u2115} {i m : fin (n + 1)} (h : i \u2264 m) :\n  (fin_succ_equiv' i).symm m = m.succ :=\nby { convert fin_succ_equiv_symm'_some_above h; simp }\n\n/-- Equivalence between `fin (n + 1)` and `option (fin n)`.\nThis is a version of `fin.pred` that produces `option (fin n)` instead of\nrequiring a proof that the input is not `0`. -/\n-- TODO: make the `n = 0` case neater\ndef fin_succ_equiv (n : \u2115) : fin (n + 1) \u2243 option (fin n) :=\nnat.cases_on n\n{ to_fun := \u03bb _, none,\n  inv_fun := \u03bb _, 0,\n  left_inv := \u03bb _, by simp,\n  right_inv := \u03bb x, by { cases x, simp, exact x.elim0 } }\n(\u03bb _, fin_succ_equiv' 0)\n\n@[simp] lemma fin_succ_equiv_zero {n : \u2115} :\n  (fin_succ_equiv n) 0 = none :=\nby cases n; refl\n\n@[simp] lemma fin_succ_equiv_succ {n : \u2115} (m : fin n):\n  (fin_succ_equiv n) m.succ = some m :=\nbegin\n  cases n, { exact m.elim0 },\n  convert fin_succ_equiv'_above m.zero_le\nend\n\n@[simp] lemma fin_succ_equiv_symm_none {n : \u2115} :\n  (fin_succ_equiv n).symm none = 0 :=\nby cases n; refl\n\n@[simp] lemma fin_succ_equiv_symm_some {n : \u2115} (m : fin n) :\n  (fin_succ_equiv n).symm (some m) = m.succ :=\nbegin\n  cases n, { exact m.elim0 },\n  convert fin_succ_equiv_symm'_some_above m.zero_le\nend\n\n@[simp] lemma fin_succ_equiv_symm_coe {n : \u2115} (m : fin n) :\n  (fin_succ_equiv n).symm m = m.succ :=\nfin_succ_equiv_symm_some m\n\n/-- The equiv version of `fin.pred_above_zero`. -/\nlemma fin_succ_equiv'_zero {n : \u2115} :\n  fin_succ_equiv' (0 : fin (n + 1)) = fin_succ_equiv (n + 1) := rfl\n\n/-- Equivalence between `fin m \u2295 fin n` and `fin (m + n)` -/\ndef fin_sum_fin_equiv : fin m \u2295 fin n \u2243 fin (m + n) :=\n{ to_fun := \u03bb x, sum.rec_on x\n    (\u03bb y, \u27e8y.1, nat.lt_of_lt_of_le y.2 $ nat.le_add_right m n\u27e9)\n    (\u03bb y, \u27e8m + y.1, nat.add_lt_add_left y.2 m\u27e9),\n  inv_fun := \u03bb x, if H : x.1 < m\n    then sum.inl \u27e8x.1, H\u27e9\n    else sum.inr \u27e8x.1 - m, nat.lt_of_add_lt_add_left $\n      show m + (x.1 - m) < m + n,\n      from (nat.add_sub_of_le $ le_of_not_gt H).symm \u25b8 x.2\u27e9,\n  left_inv := \u03bb x, begin\n    cases x with y y,\n    { simp [fin.ext_iff, y.is_lt], },\n    { have H : \u00acm + y.val < m := not_lt_of_ge (nat.le_add_right _ _),\n      simp [H, nat.add_sub_cancel_left, fin.ext_iff] }\n  end,\n  right_inv := \u03bb x, begin\n    by_cases H : (x:\u2115) < m,\n    { dsimp, rw [dif_pos H], simp },\n    { dsimp, rw [dif_neg H], simp [fin.ext_iff, nat.add_sub_of_le (le_of_not_gt H)] }\n  end }\n\n@[simp] lemma fin_sum_fin_equiv_apply_left (x : fin m) :\n  @fin_sum_fin_equiv m n (sum.inl x) = \u27e8x.1, nat.lt_of_lt_of_le x.2 $ nat.le_add_right m n\u27e9 :=\nrfl\n\n@[simp] lemma fin_sum_fin_equiv_apply_right (x : fin n) :\n  @fin_sum_fin_equiv m n (sum.inr x) = \u27e8m + x.1, nat.add_lt_add_left x.2 m\u27e9 :=\nrfl\n\n@[simp] lemma fin_sum_fin_equiv_symm_apply_left (x : fin (m + n)) (h : \u2191x < m) :\n  fin_sum_fin_equiv.symm x = sum.inl \u27e8x.1, h\u27e9 :=\nby simp [fin_sum_fin_equiv, dif_pos h]\n\n@[simp] lemma fin_sum_fin_equiv_symm_apply_right (x : fin (m + n)) (h : m \u2264 \u2191x) :\n  fin_sum_fin_equiv.symm x = sum.inr \u27e8x.1 - m, nat.lt_of_add_lt_add_left $\n      show m + (x.1 - m) < m + n, from (nat.add_sub_of_le $ h).symm \u25b8 x.2\u27e9 :=\nby simp [fin_sum_fin_equiv, dif_neg (not_lt.mpr h)]\n\n/-- The equivalence between `fin (m + n)` and `fin (n + m)` which rotates by `n`. -/\ndef fin_add_flip : fin (m + n) \u2243 fin (n + m) :=\n(fin_sum_fin_equiv.symm.trans (equiv.sum_comm _ _)).trans fin_sum_fin_equiv\n\n@[simp] lemma fin_add_flip_apply_left {k : \u2115} (h : k < m)\n  (hk : k < m + n := nat.lt_add_right k m n h)\n  (hnk : n + k < n + m := add_lt_add_left h n) :\n  fin_add_flip (\u27e8k, hk\u27e9 : fin (m + n)) = \u27e8n + k, hnk\u27e9 :=\nbegin\n  dsimp [fin_add_flip, fin_sum_fin_equiv],\n  rw [dif_pos h],\n  refl,\nend\n\n@[simp] lemma fin_add_flip_apply_right {k : \u2115} (h\u2081 : m \u2264 k) (h\u2082 : k < m + n) :\n  fin_add_flip (\u27e8k, h\u2082\u27e9 : fin (m + n)) =\n    \u27e8k - m, lt_of_le_of_lt (nat.sub_le _ _) (by { convert h\u2082 using 1, simp [add_comm] })\u27e9 :=\nbegin\n  dsimp [fin_add_flip, fin_sum_fin_equiv],\n  rw [dif_neg (not_lt.mpr h\u2081)],\n  refl,\nend\n\n/-- Rotate `fin n` one step to the right. -/\ndef fin_rotate : \u03a0 n, equiv.perm (fin n)\n| 0 := equiv.refl _\n| (n+1) := fin_add_flip.trans (fin_congr (add_comm _ _))\n\nlemma fin_rotate_of_lt {k : \u2115} (h : k < n) :\n  fin_rotate (n+1) \u27e8k, lt_of_lt_of_le h (nat.le_succ _)\u27e9 = \u27e8k + 1, nat.succ_lt_succ h\u27e9 :=\nbegin\n  dsimp [fin_rotate],\n  simp [h, add_comm],\nend\n\nlemma fin_rotate_last' : fin_rotate (n+1) \u27e8n, lt_add_one _\u27e9 = \u27e80, nat.zero_lt_succ _\u27e9 :=\nbegin\n  dsimp [fin_rotate],\n  rw fin_add_flip_apply_right,\n  simp,\nend\n\nlemma fin_rotate_last : fin_rotate (n+1) (fin.last _) = 0 :=\nfin_rotate_last'\n\nlemma fin.snoc_eq_cons_rotate {\u03b1 : Type*} (v : fin n \u2192 \u03b1) (a : \u03b1) :\n  @fin.snoc _ (\u03bb _, \u03b1) v a = (\u03bb i, @fin.cons _ (\u03bb _, \u03b1) a v (fin_rotate _ i)) :=\nbegin\n  ext \u27e8i, h\u27e9,\n  by_cases h' : i < n,\n  { rw [fin_rotate_of_lt h', fin.snoc, fin.cons, dif_pos h'],\n    refl, },\n  { have h'' : n = i,\n    { simp only [not_lt] at h', exact (nat.eq_of_le_of_lt_succ h' h).symm, },\n    subst h'',\n    rw [fin_rotate_last', fin.snoc, fin.cons, dif_neg (lt_irrefl _)],\n    refl, }\nend\n\n@[simp] lemma fin_rotate_zero : fin_rotate 0 = equiv.refl _ := rfl\n\n@[simp] lemma fin_rotate_one : fin_rotate 1 = equiv.refl _ :=\nsubsingleton.elim _ _\n\n@[simp] lemma fin_rotate_succ_apply {n : \u2115} (i : fin n.succ) :\n  fin_rotate n.succ i = i + 1 :=\nbegin\n  cases n,\n  { simp },\n  rcases i.le_last.eq_or_lt with rfl|h,\n  { simp [fin_rotate_last] },\n  { cases i,\n    simp only [fin.lt_iff_coe_lt_coe, fin.coe_last, fin.coe_mk] at h,\n    simp [fin_rotate_of_lt h, fin.eq_iff_veq, fin.add_def, nat.mod_eq_of_lt (nat.succ_lt_succ h)] },\nend\n\n@[simp] lemma fin_rotate_apply_zero {n : \u2115} : fin_rotate n.succ 0 = 1 :=\nby rw [fin_rotate_succ_apply, zero_add]\n\nlemma coe_fin_rotate_of_ne_last {n : \u2115} {i : fin n.succ} (h : i \u2260 fin.last n) :\n  (fin_rotate n.succ i : \u2115) = i + 1 :=\nbegin\n  rw fin_rotate_succ_apply,\n  have : (i : \u2115) < n := lt_of_le_of_ne (nat.succ_le_succ_iff.mp i.2) (fin.coe_injective.ne h),\n  exact fin.coe_add_one_of_lt this\nend\n\nlemma coe_fin_rotate {n : \u2115} (i : fin n.succ) :\n  (fin_rotate n.succ i : \u2115) = if i = fin.last n then 0 else i + 1 :=\nby rw [fin_rotate_succ_apply, fin.coe_add_one i]\n\n/-- Equivalence between `fin m \u00d7 fin n` and `fin (m * n)` -/\ndef fin_prod_fin_equiv : fin m \u00d7 fin n \u2243 fin (m * n) :=\n{ to_fun := \u03bb x, \u27e8x.2.1 + n * x.1.1,\n    calc x.2.1 + n * x.1.1 + 1\n        = x.1.1 * n + x.2.1 + 1 : by ac_refl\n    ... \u2264 x.1.1 * n + n : nat.add_le_add_left x.2.2 _\n    ... = (x.1.1 + 1) * n : eq.symm $ nat.succ_mul _ _\n    ... \u2264 m * n : nat.mul_le_mul_right _ x.1.2\u27e9,\n  inv_fun := \u03bb x,\n    have H : 0 < n, from nat.pos_of_ne_zero $ \u03bb H, nat.not_lt_zero x.1 $ by subst H; from x.2,\n    (\u27e8x.1 / n, (nat.div_lt_iff_lt_mul _ _ H).2 x.2\u27e9,\n     \u27e8x.1 % n, nat.mod_lt _ H\u27e9),\n  left_inv := \u03bb \u27e8x, y\u27e9,\n    have H : 0 < n, from nat.pos_of_ne_zero $ \u03bb H, nat.not_lt_zero y.1 $ H \u25b8 y.2,\n    prod.ext\n      (fin.eq_of_veq $ calc\n              (y.1 + n * x.1) / n\n            = y.1 / n + x.1 : nat.add_mul_div_left _ _ H\n        ... = 0 + x.1 : by rw nat.div_eq_of_lt y.2\n        ... = x.1 : nat.zero_add x.1)\n      (fin.eq_of_veq $ calc\n              (y.1 + n * x.1) % n\n            = y.1 % n : nat.add_mul_mod_self_left _ _ _\n        ... = y.1 : nat.mod_eq_of_lt y.2),\n  right_inv := \u03bb x, fin.eq_of_veq $ nat.mod_add_div _ _ }\n\n/-- `fin 0` is a subsingleton. -/\ninstance subsingleton_fin_zero : subsingleton (fin 0) :=\nfin_zero_equiv.subsingleton\n\n/-- `fin 1` is a subsingleton. -/\ninstance subsingleton_fin_one : subsingleton (fin 1) :=\nfin_one_equiv.subsingleton\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/equiv/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.7355689125467559}}
{"text": "import basic_defs_world.level2 --hide\nimport set_theory_world.level11 --hide\nopen set --hide\nnamespace topological_space --hide\n\n\n/-\n# Level 3: Intersection of a finite set of open sets is open.\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nThe `sInter_of_inter` lemma will be of great help here.\n-/\n\n/- Lemma\nThe intersection of a finite set of open sets is open.\n-/\nlemma is_open_sInter {X : Type} [topological_space X] {S : set (set X)}\n(hfin : finite S) (h : \u2200 s \u2208 S, is_open s): is_open (sInter S) :=\nbegin\n  apply sInter_of_inter,\n  {\n    exact hfin,\n  },\n  {\n    exact univ_mem,\n  },\n  {\n    intros A B hA hB,\n    exact inter hA hB,\n  },\n  {\n    exact h,\n  }\n\n\n\n\n  \nend\n\nend topological_space --hide\n", "meta": {"author": "mmasdeu", "repo": "topologygame", "sha": "0a1b868031919a5555e7b99efca66ece2f546ec7", "save_path": "github-repos/lean/mmasdeu-topologygame", "path": "github-repos/lean/mmasdeu-topologygame/topologygame-0a1b868031919a5555e7b99efca66ece2f546ec7/src/basic_defs_world/level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7905303162021597, "lm_q1q2_score": 0.7355554589287177}}
{"text": "/-\nCopyright (c) 2020 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport data.set.intervals.basic\nimport data.set.function\n\n/-!\n# Monotone surjective functions are surjective on intervals\n\nA monotone surjective function sends any interval in the domain onto the interval with corresponding\nendpoints in the range.  This is expressed in this file using `set.surj_on`, and provided for all\npermutations of interval endpoints.\n-/\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [linear_order \u03b1] [partial_order \u03b2] {f : \u03b1 \u2192 \u03b2}\n\nopen set function order_dual (to_dual)\n\nlemma surj_on_Ioo_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a b : \u03b1) :\n  surj_on f (Ioo a b) (Ioo (f a) (f b)) :=\nbegin\n  intros p hp,\n  rcases h_surj p with \u27e8x, rfl\u27e9,\n  refine \u27e8x, mem_Ioo.2 _, rfl\u27e9,\n  contrapose! hp,\n  exact \u03bb h, h.2.not_le (h_mono $ hp $ h_mono.reflect_lt h.1)\nend\n\nlemma surj_on_Ico_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a b : \u03b1) :\n  surj_on f (Ico a b) (Ico (f a) (f b)) :=\nbegin\n  obtain hab | hab := lt_or_le a b,\n  { intros p hp,\n    rcases eq_left_or_mem_Ioo_of_mem_Ico hp with rfl|hp',\n    { exact mem_image_of_mem f (left_mem_Ico.mpr hab) },\n    { have := surj_on_Ioo_of_monotone_surjective h_mono h_surj a b hp',\n      exact image_subset f Ioo_subset_Ico_self this } },\n  { rw Ico_eq_empty (h_mono hab).not_lt,\n    exact surj_on_empty f _ }\nend\n\nlemma surj_on_Ioc_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a b : \u03b1) :\n  surj_on f (Ioc a b) (Ioc (f a) (f b)) :=\nby simpa using surj_on_Ico_of_monotone_surjective h_mono.dual h_surj (to_dual b) (to_dual a)\n\n-- to see that the hypothesis `a \u2264 b` is necessary, consider a constant function\nlemma surj_on_Icc_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) {a b : \u03b1} (hab : a \u2264 b) :\n  surj_on f (Icc a b) (Icc (f a) (f b)) :=\nbegin\n  intros p hp,\n  rcases eq_endpoints_or_mem_Ioo_of_mem_Icc hp with (rfl|rfl|hp'),\n  { exact \u27e8a, left_mem_Icc.mpr hab, rfl\u27e9 },\n  { exact \u27e8b, right_mem_Icc.mpr hab, rfl\u27e9 },\n  { have := surj_on_Ioo_of_monotone_surjective h_mono h_surj a b hp',\n    exact image_subset f Ioo_subset_Icc_self this }\nend\n\nlemma surj_on_Ioi_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Ioi a) (Ioi (f a)) :=\nbegin\n  rw [\u2190 compl_Iic, \u2190 compl_compl (Ioi (f a))],\n  refine maps_to.surj_on_compl _ h_surj,\n  exact \u03bb x hx, (h_mono hx).not_lt\nend\n\nlemma surj_on_Iio_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Iio a) (Iio (f a)) :=\n@surj_on_Ioi_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a\n\nlemma surj_on_Ici_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Ici a) (Ici (f a)) :=\nbegin\n  rw [\u2190 Ioi_union_left, \u2190 Ioi_union_left],\n  exact (surj_on_Ioi_of_monotone_surjective h_mono h_surj a).union_union\n    (@image_singleton _ _ f a \u25b8 surj_on_image _ _)\nend\n\nlemma surj_on_Iic_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Iic a) (Iic (f a)) :=\n@surj_on_Ici_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/set/intervals/surj_on.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7354792640101114}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n\n! This file was ported from Lean 3 source module algebra.order.euclidean_absolute_value\n! leanprover-community/mathlib commit 422e70f7ce183d2900c586a8cda8381e788a0c62\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.AbsoluteValue\nimport Mathlib.Algebra.EuclideanDomain.Instances\n\n/-!\n# Euclidean absolute values\n\nThis file defines a predicate `AbsoluteValue.IsEuclidean abv` stating the\nabsolute value is compatible with the Euclidean domain structure on its domain.\n\n## Main definitions\n\n * `AbsoluteValue.IsEuclidean abv` is a predicate on absolute values on `R` mapping to `S`\n    that preserve the order on `R` arising from the Euclidean domain structure.\n * `AbsoluteValue.abs_isEuclidean` shows the \"standard\" absolute value on `\u2124`,\n   mapping negative `x` to `-x`, is euclidean.\n-/\n\n\n@[inherit_doc]\nlocal infixl:50 \" \u227a \" => EuclideanDomain.r\n\nnamespace AbsoluteValue\n\nsection OrderedSemiring\n\nvariable {R S : Type _} [EuclideanDomain R] [OrderedSemiring S]\n\nvariable (abv : AbsoluteValue R S)\n\n/-- An absolute value `abv : R \u2192 S` is Euclidean if it is compatible with the\n`EuclideanDomain` structure on `R`, namely `abv` is strictly monotone with respect to the well\nfounded relation `\u227a` on `R`. -/\nstructure IsEuclidean : Prop where\n  /-- The requirement of a Euclidean absolute value\n  that `abv` is monotone with respect to `\u227a` -/\n  map_lt_map_iff' : \u2200 {x y}, abv x < abv y \u2194 x \u227a y\n#align absolute_value.is_euclidean AbsoluteValue.IsEuclidean\n\nnamespace IsEuclidean\n\nvariable {abv}\n\n-- Rearrange the parameters to `map_lt_map_iff'` so it elaborates better.\ntheorem map_lt_map_iff {x y : R} (h : abv.IsEuclidean) : abv x < abv y \u2194 x \u227a y :=\n  map_lt_map_iff' h\n#align absolute_value.is_euclidean.map_lt_map_iff AbsoluteValue.IsEuclidean.map_lt_map_iff\n\nattribute [simp] map_lt_map_iff\n\ntheorem sub_mod_lt (h : abv.IsEuclidean) (a : R) {b : R} (hb : b \u2260 0) : abv (a % b) < abv b :=\n  h.map_lt_map_iff.mpr (EuclideanDomain.mod_lt a hb)\n#align absolute_value.is_euclidean.sub_mod_lt AbsoluteValue.IsEuclidean.sub_mod_lt\n\nend IsEuclidean\n\nend OrderedSemiring\n\nsection Int\n\nopen Int\n\n-- TODO: generalize to `LinearOrderedEuclideanDomain`s if we ever get a definition of those\n/-- `abs : \u2124 \u2192 \u2124` is a Euclidean absolute value -/\nprotected theorem abs_isEuclidean : IsEuclidean (AbsoluteValue.abs : AbsoluteValue \u2124 \u2124) :=\n  {  map_lt_map_iff' := fun {x y} =>\n       show abs x < abs y \u2194 natAbs x < natAbs y by rw [abs_eq_natAbs, abs_eq_natAbs, ofNat_lt] }\n#align absolute_value.abs_is_euclidean AbsoluteValue.abs_isEuclidean\n\nend Int\n\nend AbsoluteValue\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/EuclideanAbsoluteValue.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7354383198483117}}
{"text": "-- always import the tactics, we are mathematicians\nimport tactic\n-- import the theory of G-module homomorphisms, for G a group\nimport algebra.group_action_hom\n-- for the theory of sub-G-modules\nimport group_theory.group_action.sub_mul_action\n\n/-\n\n# Introduction to G-modules in Lean\n\nLet `G` be a group (with group law `*`) and let `M` be an abelian\ngroup (with group law `+`). A `G`-action on `M` is just a group\nhomomorphism from `G` to the group automorphisms\nof `M`, or in other words an action `\u2022` of `G` on `M` (in the sense\nof groups acting on sets/types) satisfying\nthe axiom `smul_add g m n : g \u2022 (m + n) = g \u2022 m + g \u2022 n`.\n\nThe goal of this workshop will be to set up a cohomology theory\nfor G-modules. We will just do H\u2070 (G-invariant elements)\nand H\u00b9 (1-cocycles modulo coboundaries), but clearly one\ncould go on to 2-cocycles, n-cocycles etc.\n\n### typeclass comments (\"will it work for monoids/add_monoids?\")\n\nNote that the definition of G-module does not mention `g\u207b\u00b9` at all, so\nwe can even define it for monoids `G`, which we will. Loads\nof the theory works for `G` a monoid in fact (certainly everything\nwe do in this workshop). But we use subtraction on `M` quite a\nlot in practice when we get to `H\u00b9` (e.g. the coboundary `g b - b`\nneeds subtraction) so I've assumed that `M` is an abelian group throughout for\npedagogical reasons (and because it solved some typeclass issue at some point).\n\nThe `G`-module structure on `M` is called `distrib_mul_action G M` in Lean.\n-/\n\nsection distrib_mul_action_stuff\n\n/- \n\n## The interface for G-modules, i.e. the theory of `\u2022`\n\nIn Lean we learn about the typeclass `[distrib_mul_action G M]`, \nwhich gives us the notation `\u2022` for an action of `G` on `M`,\nand all the axioms.\n\nNotation for this section:\n\nLet `G` be a group. Let `M` be an abelian group and furthermore\nassume `M` is a `G`-module. We use the usual notation `(g\u2081 * g\u2082) \u2022 (m\u2081 + m\u2082)`\n\n-/\n\nvariables\n  {G : Type} [monoid G] --`*`\n  {M : Type} [add_comm_group M] --`+`\n  [distrib_mul_action G M] --`\u2022`\n\n-- Let `g`'ish variables be elements of `G`, and let `m`ish variables be\n-- elements of `M`.\nvariables (g g1 g2 g\u2081 g\u2082 : G) (m m1 m2 m\u2081 m\u2082 : M)\n\n/-\n\n### The interface for `\u2022`\n\nBelow are the names of the theorem proofs which you will need\nto know when manipulating an element of a fixed `G`-module,\nfor example the element `(g\u2081 * g\u2082) \u2022 (m\u2081 + m\u2082)`.\n\nI have explained the names of the proofs in the form\nof examples. The syntax for the examples is this:\n\n`example : <Theorem statement> := <name of proof function> input1 input2 ...`\n\nSo these examples tell you the names of the proofs of the theorems.\nThe proofs are functions which need inputs, and the inputs are\nthe variables used in the theorem statement. I also mention\nwhether Lean's \"rw-machine\" (the `simp` tactic) knows about these theorems.\n\n-/\n\n\n\nexample : g \u2022 (0 : M) = 0 := smul_zero g -- a simp lemma\nexample : g \u2022 (m\u2081 + m\u2082) = g \u2022 m\u2081 + g \u2022 m\u2082 := smul_add g m\u2081 m\u2082 -- a simp lemma \nexample : g \u2022 (-m) = -(g \u2022 m) := smul_neg g m -- a simp lemma\nexample : (1 : G) \u2022 m = m := one_smul G m -- a simp lemma\n-- at the time of writing, this is not a simp lemma.\nexample : g \u2022 (m\u2081 - m\u2082) = g \u2022 m\u2081 - g \u2022 m\u2082 := smul_sub g m\u2081 m\u2082\nexample : (g\u2081 * g\u2082) \u2022 m = g\u2081 \u2022 g\u2082 \u2022 m := mul_smul g\u2081 g\u2082 m -- not a simp lemma\n\nend distrib_mul_action_stuff\n/-\n\n### Entirely optional digression on `simp`\n\nSome of those lemmas above were \"simp lemmas\" (if you `#print one_smul`\nyou'll see it has a `@[simp]` tag). What makes a good simp lemma?\n\nThe most important rule is that, unless you really know what you're\ndoing, it should be of the form `A = B` or `A \u2194 B`.\n\nThe second rule is that the right hand side should in some sense\nbe \"simpler than\" the left hand side.\nso the lemma should say `A simplifies_to B`, indicating a flow towards\na solution.\n\nFor example `one_mul : 1 * a = a` is a `simp` lemma for groups (and\nfor monoids), because it is an equality, and the right hand side\nis unarguably simpler than the left hand side. \n\nLater on we'll be making some of our own structures, and\nwe will want to train Lean's simplifier to use those structures. The better\nyou understand how the simplifier works on your structures, the easier you\nwill find it to type \"mathematics as the mathematician thinks about it\"\ninto Lean.\n\n-/\n\n/-\n\nKB note to self: Some people think `smul_add`\n`g \u2022 (m\u2081 + m\u2082) = g \u2022 m\u2081 + g \u2022 m\u2082`\nis a good simp lemma. I should experiment with `simp` here perhaps\nor maybe just ask how to do it.\n\nshould mul_smul be a simp lemma?\n\n-/\n\n/-\n\n### The `simp` tactic\n\nA lemma is, by definition, a `simp` lemma, if its proof term is tagged\nwith the `@[simp]` attribute (you can check a term's attributes with `#print`)\n\n`simp` is an algorithm which will \"follow its nose\", doing\nstuff like expanding out brackets automatically and tidying up.\nIt would tidy up by simplifying `g \u2022 0` to `0` for example,\nand it would expand out by changing `g \u2022 (m\u2081 + m\u2082)` to `g \u2022 m\u2081 + g \u2022 m\u2082`.\nIn general `simp` tries to rewrite equivalences, e.g. things of the\nform `A = B` or `A \u2194 B`, with in each case `B` the \"simplified\" or\n\"expanded out\" version of `A`. The equivalences it rewrites\nwith are the ones in its database of a few thousand (*shrug?)\nso-called \"`simp` lemmas\" For example, if `\u21d10 : G \u2192 M` is the\nzero function then `zero_val g : \u21d10 g = 0` would be a good `simp`\nlemma, which is why it is tagged with the `@[simp]` attribute,\nmaking it part of the database.\n\nNote that `simp` does not have \"ideas\". It will never apply\ncommutativity or associativity, for example, for fear that\nit might be a waste of time which would have to be undone later.\n`simp` will solve `x + 0 = x` but it will not solve `m + n = n + m`,\nbecause it is not so clear that the right hand side is any simpler\nthan the left hand side. problems like that you need `abel`.\n\nTo learn more about `simp`, check out the simp docs on\nthe leanprover-community website.\n-- TODO when online -- add link to simp docs in API at leanprover-community website\n\n## A note on `abel`\n\n`abel` should be able to solve all problems in abelian groups\nof the form \u2200 a b c, a + (c + -b) = (a - b) + c etc.\nNote however that it *cannot use hypotheses*. It will only\nprove identities which are true in all abelian groups. \n\n-/\nexample (M : Type) [add_comm_group M] (a b c : M) :\n  a + (c + -b) = (a - b) + c := by abel\n\n\n/-\n\n## @JoBo's homework -- the interface for sub-G-modules\n\nLean also has G-invariant subsets (`sub_mul_action G A`)\nbut not G-invariant subgroups, rather annoyingly. Hopefully\n@jobo is going to make this stuff.\n\n-/\nsection Jobo_homework\n\nset_option old_structure_cmd true\n\nstructure sub_distrib_mul_action (G M : Type)\n  [monoid G] [add_comm_group M]\n  [distrib_mul_action G M]\nextends sub_mul_action G M, add_subgroup M\n\n/-\n\nSeems me to me that you either define `mem` or `coe`,\ndepending on whether you want to build your own `mem`\n(unwise?) or rely on `coe`'s `mem`. \n\n-- petition to abolish all `\u2208` other than `set.mem`\n\n-- mathematicians like reasoning with `\u2208`. By not defining\n-- `has_mem M` `sub_distrib_mul_action` we force set-theoretic\n-- arguments to happen within `set M`. \n\n-- We define a coercion \n-/\n-- **CLONE?**\n-- github search for formalizing mathematics does not give me\n-- this repo :-(\nnamespace sub_distrib_mul_action\nvariables {G : Type} [monoid G]\nvariables {M : Type} [add_comm_group M] [distrib_mul_action G M]\nvariables {N : Type} [add_comm_group N] [distrib_mul_action G N]\n\ninstance : has_coe (sub_distrib_mul_action G M) (set M) := \u27e8carrier\u27e9\n\nlemma ext {A B : sub_distrib_mul_action G M}\n  (h : \u2200 m : M, m \u2208 (A : set M) \u2194 m \u2208 (B : set M)) :\nA = B :=\nbegin\n  cases A; cases B; simp, ext m, exact h m\nend\n\ntheorem ext_iff {A B : sub_distrib_mul_action G M} :\n  A = B \u2194 \u2200 m : M, m \u2208 (A : set M) \u2194 m \u2208 (B : set M) :=\n\u27e8by {rintro rfl m, refl}, ext\u27e9 \n\nend sub_distrib_mul_action\n\nnamespace distrib_mul_action_hom\n\nvariables {G : Type} [monoid G]\nvariables {M : Type} [add_comm_group M] [distrib_mul_action G M]\nvariables {N : Type} [add_comm_group N] [distrib_mul_action G N]\n\ndef ker (\u03c6 : M \u2192+[G] N) :\n  sub_distrib_mul_action G M := \nby { refine_struct {carrier := {m : M | \u03c6 m = 0}},\n  try {repeat {sorry}} -- proofs missing\n}\n\nvariable (\u03c6 : M \u2192+[G] N)\n\nlemma mem_ker_set (m : M) : m \u2208 (\u03c6.ker : set M) \u2194 \u03c6 m = 0 :=\nbegin\n  refl\nend\n\n-- let's not make this. Let's force coercion to set. No point\n-- in reduplicating the theory of `\u2208` on `set`. \n-- kevin_thinks_this_is_a_bad_instance : has_mem M (sub_distrib_mul_action G M) := \u27e8\u03bb m S, m \u2208 (S : set M)\u27e9\n\n/-\nWill this work in Lean 4?\n\nlemma mem_ker (m : M) : m \u2208 \u03c6.ker \u2194 \u03c6 m = 0 :=\nbegin\n  refl\nend\n-/\nlemma mem_ker (m : M) : m \u2208 (\u03c6.ker : set M) \u2194 \u03c6 m = 0 :=\nbegin\n  refl\nend\n\ndef range (\u03c6 : M \u2192+[G] N) :\n  sub_distrib_mul_action G N :=\nby { refine_struct {carrier := set.range \u03c6},\n  try {repeat {sorry}} -- proofs missing\n}\n\nlemma coe_range (n : N) : n \u2208 (set.range (\u21d1\u03c6)) \u2194 n \u2208 (\u03c6.range : set N) := iff.rfl \nlemma mem_range (n : N) : n \u2208 (set.range (\u21d1\u03c6)) \u2194 \u2203 m : M, \u03c6 m = n := iff.rfl \n-- now copy theorems from sub_mul_action if you want\n\n--now port subgroup and sub_mul_action\n\nend distrib_mul_action_hom\n\n/-\nTODO\n\nG-invariant subgroups are a complete lattice.\n\nProof could perhaps go via a Galois correspondence with either\nG-invariant subsets or subgroups (or both?).\n\n-/\n\nend Jobo_homework\n\n/-\n## The interface for morphisms of G-modules, i.e. the theory of `\u2192+[_]`\n\nLean uses notation `M \u2192+[G] N` and name `distrib_mul_action_hom`,\nbut you don't need to remember the name, it should work in the \nbackground for you.\n\nThe type of G-module homs from `M` to `N`, i.e. the set\nthat a mathematician would call something like $$\\Hom_G(M,N)$$,\nis in Lean called `M \u2192+[G] N`. The non-notation name for this function\ntype is `distrib_mul_action_hom G M N`, which is why you see this word in\nnamespaces or mentioned in sections.\n\nTerms of this type are `G`-module morphisms from `M` to `N`.\nSo when we see `\u03c6 : M \u2192+[G] N` it means that `\u03c6` is a G-module hom\nfrom `M` to `N`. We will often only be using `\u03c6` only in terms of its\nassociated function `\u21d1\u03c6 : M \u2192 N`. `\u03c6` itself is a package, consisting\nof a function and a bunch of theorems about that function.\n\n-/\n\n-- let's make function composition notation\ninfixr ` \u2218\u1d4d `:90 := distrib_mul_action_hom.comp\n\nnamespace distrib_mul_action_hom\n\n-- let's do the variables\nvariables \n-- let `G` be a group (or a monoid)\n{G : Type} [monoid G]\n\n{M : Type}  [add_comm_group M] [distrib_mul_action G M] -- let `M` be a `G`-module\n{N : Type}  [add_comm_group N] [distrib_mul_action G N] -- let `N` be a `G`-module\n(\u03c6 : M \u2192+[G] N) -- let \u03c6 be a morphism of G-modules\n(g : G) (m m\u2081 m\u2082 m1 m2 : M) -- random useful variable names\n\n/-\n\n### API for `M \u2192+[G] N`\n\nHere are the names of the proofs of the basic axioms for G-module\nmorphisms. The proofs are in the `\u2192+[_]` namespace, so you can\nwrite things like `\u03c6.map_smul` to access them easily.\n\n-/\nexample : \u03c6 (g \u2022 m) = g \u2022 (\u03c6 m) := \u03c6.map_smul g m -- a simp lemma\nexample (m\u2081 m\u2082 : M) : \u03c6 (m\u2081 + m\u2082) = \u03c6 m\u2081 + \u03c6 m\u2082 := \u03c6.map_add m\u2081 m\u2082 -- a simp lemma\n\nexample : \u03c6 (g \u2022 (m1 + m2)) = g \u2022 \u03c6 m1 + g \u2022 \u03c6 m2 :=\nbegin\n  -- what will you rewrite? Will you rewrite at all?\n  rw \u03c6.map_smul,\n  rw \u03c6.map_add, \n  rw smul_add,\n  -- or just `simp` will do it\n  -- Moral : `simp` right now is being trained to \"push functions further in\"\n  -- and this must be the `simp` normal form.\nend\n/-\n\n\n## A G-module morphism is a pair of things\n\nA G-module morphism `\u03c6 : M \u2192+[G] N` is two things.\n1) a function `\u21d1\u03c6 : M \u2192 N`\n2) the dot notation system for `\u03c6`, a database where\nall the axioms and theorems for G-module homs as applied to `\u03c6` are stored.\n\nFor example, the type of \u03c6.map_smul is *actually* a theorem about `\u21d1\u03c6`.\n\n`\u03c6.map_smul g m : \u21d1\u03c6 (g \u2022 m) = g \u2022 \u21d1\u03c6 m`\n\n\n-/\n\nexample (\u03c6 : M \u2192+[G] N) : \u03c6 0 = 0 :=\nbegin\n  -- library_search will take some time (I don't know why)\n  -- but will eventually find the answer to this one. \n  -- But you can guess it quicker!\n  -- what will you rewrite? Remember rewrite tries \n  -- `refl` afterwards (unlike NNG)\n  rw \u03c6.map_zero,\nend\n\n-- Can you solve it in term mode?\nexample : \u03c6 0 = 0 := \u03c6.map_zero\n-- change `sorry` to the name of a tactic\nexample : \u03c6 0 = 0 := by simp\n\n\n/-\n\n### Composition of G-module morphisms\n\nYou know how to compose functions, you just write `\u03c8 (\u03c6 a)`\nor whatever. Composition in the category of G-modules is\ndone with the `comp` method for `G`-module morphisms.\n\n-/\n\n-- let P be another G-module\nvariables {P : Type} [add_comm_monoid P] [distrib_mul_action G P]\n\n-- Recall `\u03c6 : M \u2192+[G] N` from earlier.\n-- let \u03c8 : N \u2192 P be another G-module morphism\nvariable (\u03c8 : N \u2192+[G] P) -- his is notation for `\u03c8 : distrib_mul_action_hom G N P`\n\n-- how to compose G-module maps\nexample : M \u2192+[G] P := \u03c8 \u2218\u1d4d \u03c6\n\n-- You should think of \u03c6 and \u03c8 as morphisms in the category\n-- of `G`-modules. They are functions, but they also have\n-- some extra category-theoretic baggage (proofs that they\n-- are G-linear maps) which needs to be moved around.\n\n-- KB NOTE TO SELF do we ever actually compose morphisms?\n-- My definition of short exact sequence of G-modules\n-- is \"image = kernel\" , which is highly category-theoretic.\n-- and functional evaluation often takes place after that.\n\n-- The important fact is that `(\u03c8 \u2218\u1d4d \u03c6) m = \u03c8 (\u03c6 m)`, as\n-- terms of type `P`. Rather nicely, this theorem is called\n-- `\u03c8.comp_apply` but it is also a `simp` lemma, and \n-- furthermore true by definition\nexample (m : M) :\n  (\u03c8 \u2218\u1d4d \u03c6) m = \u03c8 (\u03c6 m) := \u03c8.comp_apply \u03c6 m -- and `rfl` works too and `by simp`\n\n-- all works with function.comp too\nexample (m : M) :\n  (\u03c8 \u2218 \u03c6) m = \u03c8 (\u03c6 m) := \u03c8.comp_apply \u03c6 m -- and `rfl` works too and `by simp`\n\n\n-- By the way, `squeeze_simp` is a version of `simp` which tells you \n-- which rewrites it did. Give it a try!\nexample :\n  \u03c8.comp \u03c6 (g \u2022 (m\u2081 + m\u2082)) = g \u2022 (\u03c8 (\u03c6 m\u2081) + \u03c8 (\u03c6 m\u2082)) :=\nbegin\n  simp,\nend\n\nend distrib_mul_action_hom\n\nsection exactness_stuff\n\n/-\n\n## Developing a basic API for exact sequences\n\nThis is relatively straightforward and a nice\nbeginner exercise.\n\n-/\n-- Let M, N and P be G-modules\nvariables {G M N P : Type}\n  [monoid G] [add_comm_group M] [add_comm_group N] [add_comm_group P]\n  [distrib_mul_action G M] [distrib_mul_action G N] [distrib_mul_action G P]\n\n-- I don't know which definition is best. This is the slickest for sure.\ndefinition is_exact (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) : Prop :=\n\u03c6.range = \u03c8.ker\n\nvariables (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) \n\n@[simp] lemma is_exact.def' : is_exact \u03c6 \u03c8 \u2194 \u03c6.range = \u03c8.ker := iff.rfl\n\n@[simp] lemma is_exact.def :\n  is_exact \u03c6 \u03c8 \u2194 \u2200 n : N, (\u2203 m : M, \u03c6 m = n) \u2194 \u03c8 n = 0 :=\nbegin\n  rw is_exact.def',\n  rw sub_distrib_mul_action.ext_iff, \n  refl,\nend\n\n/-\n\n## more than one \"definition\" of `is_exact`\n\nMathematicians have about three different ways of saying\na sequence is exact, and they're all \"the definition\".\nThat's why I proved the last few lemmas -- so we can use whichever\nof the definitions is most use to us at the time. \n\n-/\n\n/-\n\n## Making an API for short exact sequences.\n\nThis is really easy.\n\n-/\nopen function\n\n/-- Fundamental to cohomology theory is the concept of a short\nexact sequence. If `\u03c6 : M \u2192+[G] N` and\n`\u03c8 : N \u2192+[G] P` are G-module morphisms, `is_short_exact \u03c6 \u03c8` \nis the proposition stating that `0 \u2192 M -\u03c6\u2192 N -\u03c8\u2192 P \u2192 0` is short exact\nin the usual sense, that is:\n\n*) `\u03c6` is injective, \n*) the range of `\u03c6` equals the kernel of `\u03c8`,\n*) `\u03c8` is surjective. \n\nIf `h : is_short_exact \u03c6 \u03c8` then you can access various standard\nfacts about `\u03c6` and `\u03c8` using dot notation with `h`. For example\n`h.injective` is the proof that `\u03c6` is injective, and \n`h.exact_set` is the proof of some expanded-out version of the\nstatement that an element `n` is in the image\nof `\u03c6` if and only if it is in the kernel of `\u03c8`. A rather more\ncompact definition is `h.exact_cat`.\n-/\n-- This will do for an internal definition. The user should\n-- never have to think about that though.\ndef is_short_exact (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) : Prop :=\n  is_exact \u03c6 \u03c8 \u2227 injective \u03c6 \u2227 surjective \u03c8\n\n-- We need to make a nice API for this, it's easy and fun.\n\n-- useful for rewrites when we're making the API, but the user\n-- should never see this.\nprotected lemma is_short_exact_def :\n  is_short_exact \u03c6 \u03c8 \u2194 is_exact \u03c6 \u03c8 \u2227 injective \u03c6 \u2227 surjective \u03c8 :=\n-- true by definition\niff.rfl\n\n-- I marked it protected because the end user should never have\n-- to use this lemma in this repo, they should always use the `h.injective`\n-- dot notation.\n\n-- Now the proper API\nnamespace is_short_exact\n\n-- We are making the API so we are allowed to unfold stuff\n\nvariables {\u03c6} {\u03c8} (h : is_short_exact \u03c6 \u03c8)\n\ninclude h\ndef injective : injective \u03c6 := --h.2.1\nbegin\n  /- put your infoview filter onto only props.\n     You see\n\n     h: is_short_exact \u03c6 \u03c8\n     \u22a2 injective \u21d1\u03c6\n  \n     That's the question. You can take `h` apart\n     with `cases`, and even more effectively with\n     `rcases`.\n  -/\n  rcases h with \u27e8_, _, _\u27e9,\n  assumption\nend\n\n\ndef surjective : surjective \u03c8 := -- h.2.2\nbegin\n  exact h.2.2\nend\n\n-- again we don't really want the user messing\n-- with this internal function, it should be thought\n-- of as \"an abbreviation for several things\".\nprotected def exact : is_exact \u03c6 \u03c8 := h.1\n\n--@[simp] lemma is_exact_def0 (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) :\n--  is_exact \u03c6 \u03c8 \u2194 \u03c6.range = \u03c8.ker\n\n--@[simp] lemma is_exact_def (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) :\n--  is_exact \u03c6 \u03c8 \u2194 \u2200 n : N, (\u2203 m : M, \u03c6 m = n) \u2194 \u03c8 n = 0 :=\n\ntheorem exact_set : \u2200 n : N, (\u2203 m : M, \u03c6 m = n) \u2194 \u03c8 n = 0 :=\nbegin\n  rw \u2190 is_exact.def,\n  exact h.exact\nend\n\ntheorem exact_cat : \u03c6.range = \u03c8.ker :=\nbegin\n  rw \u2190 is_exact.def',\n  -- different uses of word!\n  exact h.exact,\nend\n\n@[simp] theorem comp_apply (m : M) : \u03c8 (\u03c6 m) = 0 :=\nbegin\n  rw \u2190 \u03c8.mem_ker,\n  rw \u2190 h.exact_cat,\n  rw \u2190 \u03c6.coe_range,\n  simp,\nend\n\n\n-- now a noncomputable function defined by the axiom of choice,\n-- a random splitting of the surjection \u03c8 : P \u2192 N and hence a one-sided\n-- inverse\nnoncomputable def inverse_\u03c8 : P \u2192 N := \u03bb p, classical.some (h.surjective p)\n\n@[simp] lemma inverse_\u03c8_spec (p : P) : \u03c8 (h.inverse_\u03c8 p) = p :=\nclassical.some_spec (h.surjective p)\n\n-- now the same sort of thing for the injection \u03c6 : M \u2192 N; this is\n-- the map from the image of \u03c6 back to M.\nnoncomputable def inverse_\u03c6 (h : is_short_exact \u03c6 \u03c8) (n : N)\n  (hn : \u2203 m : M, \u03c6 m = n) : M :=\nclassical.some hn\n\n@[simp]\nlemma inverse_\u03c6_def (h : is_short_exact \u03c6 \u03c8) {n : N} (hn : \u2203 m : M, \u03c6 m = n) :\n  \u03c6 (h.inverse_\u03c6 n hn) = n :=\nclassical.some_spec hn\n\n-- injectivity implies it's independent of choice, but we used choice anyway\n@[simp] lemma inverse_\u03c6_spec (h : is_short_exact \u03c6 \u03c8) {n : N} {m : M} (hm : \u03c6 m = n) :\n  h.inverse_\u03c6 _ \u27e8m, hm\u27e9 = m :=\nbegin\n  apply h.injective,\n  rw hm,\n  exact classical.some_spec \u27e8m, hm\u27e9,\nend\n\nend is_short_exact\n\nend exactness_stuff\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_8/ideas/Part_A_G_modules.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.7354383155014481}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.category.Module.abelian\nimport category_theory.limits.shapes.images\nimport category_theory.limits.types\n\n/-!\n# The category of R-modules has images.\n\nNote that we don't need to register any of the constructions here as instances, because we get them\nfrom the fact that `Module R` is an abelian category.\n-/\n\nopen category_theory\nopen category_theory.limits\n\nuniverses u v\n\nnamespace Module\n\nvariables {R : Type u} [comm_ring R]\n\nvariables {G H : Module.{v} R} (f : G \u27f6 H)\n\nlocal attribute [ext] subtype.ext_val\n\nsection -- implementation details of `has_image` for Module; use the API, not these\n/-- The image of a morphism in `Module R` is just the bundling of `linear_map.range f` -/\ndef image : Module R := Module.of R (linear_map.range f)\n\n/-- The inclusion of `image f` into the target -/\ndef image.\u03b9 : image f \u27f6 H := f.range.subtype\n\ninstance : mono (image.\u03b9 f) := concrete_category.mono_of_injective (image.\u03b9 f) subtype.val_injective\n\n/-- The corestriction map to the image -/\ndef factor_thru_image : G \u27f6 image f := f.range_restrict\n\nlemma image.fac : factor_thru_image f \u226b image.\u03b9 f = f :=\nby { ext, refl, }\n\nlocal attribute [simp] image.fac\n\nvariables {f}\n/-- The universal property for the image factorisation -/\nnoncomputable def image.lift (F' : mono_factorisation f) : image f \u27f6 F'.I :=\n{ to_fun :=\n  (\u03bb x, F'.e (classical.indefinite_description _ x.2).1 : image f \u2192 F'.I),\n  map_add' :=\n  begin\n    intros x y,\n    haveI := F'.m_mono,\n    apply (mono_iff_injective F'.m).1, apply_instance,\n    rw [linear_map.map_add],\n    change (F'.e \u226b F'.m) _ = (F'.e \u226b F'.m) _ + (F'.e \u226b F'.m) _,\n    rw [F'.fac],\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    refl,\n  end,\n  map_smul' := \u03bb c x,\n  begin\n    haveI := F'.m_mono,\n    apply (mono_iff_injective F'.m).1, apply_instance,\n    rw [linear_map.map_smul],\n    change (F'.e \u226b F'.m) _ = _ \u2022 (F'.e \u226b F'.m) _,\n    rw [F'.fac],\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    refl,\n  end }\n\nlemma image.lift_fac (F' : mono_factorisation f) : image.lift F' \u226b F'.m = image.\u03b9 f :=\nbegin\n  ext x,\n  change (F'.e \u226b F'.m) _ = _,\n  rw [F'.fac, (classical.indefinite_description _ x.2).2],\n  refl,\nend\nend\n\n/-- The factorisation of any morphism in `Module R` through a mono. -/\ndef mono_factorisation : mono_factorisation f :=\n{ I := image f,\n  m := image.\u03b9 f,\n  e := factor_thru_image f }\n\n/-- The factorisation of any morphism in `Module R` through a mono has the universal property of\nthe image. -/\nnoncomputable def is_image : is_image (mono_factorisation f) :=\n{ lift := image.lift,\n  lift_fac' := image.lift_fac }\n\n/--\nThe categorical image of a morphism in `Module R`\nagrees with the linear algebraic range.\n-/\nnoncomputable def image_iso_range {G H : Module.{v} R} (f : G \u27f6 H) :\n  limits.image f \u2245 Module.of R f.range :=\nis_image.iso_ext (image.is_image f) (is_image f)\n\n@[simp, reassoc, elementwise]\nlemma image_iso_range_inv_image_\u03b9 {G H : Module.{v} R} (f : G \u27f6 H) :\n  (image_iso_range f).inv \u226b limits.image.\u03b9 f = Module.of_hom f.range.subtype :=\nis_image.iso_ext_inv_m _ _\n\n@[simp, reassoc, elementwise]\nlemma image_iso_range_hom_subtype {G H : Module.{v} R} (f : G \u27f6 H) :\n  (image_iso_range f).hom \u226b Module.of_hom f.range.subtype = limits.image.\u03b9 f :=\nby erw [\u2190image_iso_range_inv_image_\u03b9 f, iso.hom_inv_id_assoc]\n\nend Module\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/category/Module/images.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7354383131111125}}
{"text": "/-\nCopyright (c) 2021 Vladimir Goryachev. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Vladimir Goryachev, Kyle Miller, Scott Morrison, Eric Rodriguez\n-/\nimport data.list.basic\nimport data.nat.prime\nimport set_theory.fincard\n\n/-!\n# Counting on \u2115\n\nThis file defines the `count` function, which gives, for any predicate on the natural numbers,\n\"how many numbers under `k` satisfy this predicate?\".\nWe then prove several expected lemmas about `count`, relating it to the cardinality of other\nobjects, and helping to evaluate it for specific `k`.\n\n-/\n\nopen finset\n\nnamespace nat\nvariable (p : \u2115 \u2192 Prop)\n\nsection count\nvariable [decidable_pred p]\n\n/-- Count the number of naturals `k < n` satisfying `p k`. -/\ndef count (n : \u2115) : \u2115 := (list.range n).countp p\n\n@[simp] lemma count_zero : count p 0 = 0 :=\nby rw [count, list.range_zero, list.countp]\n\n/-- A fintype instance for the set relevant to `nat.count`. Locally an instance in locale `count` -/\ndef count_set.fintype (n : \u2115) : fintype {i // i < n \u2227 p i} :=\nbegin\n  apply fintype.of_finset ((finset.range n).filter p),\n  intro x,\n  rw [mem_filter, mem_range],\n  refl,\nend\n\nlocalized \"attribute [instance] nat.count_set.fintype\" in count\n\nlemma count_eq_card_filter_range (n : \u2115) : count p n = ((range n).filter p).card :=\nby { rw [count, list.countp_eq_length_filter], refl, }\n\n/-- `count p n` can be expressed as the cardinality of `{k // k < n \u2227 p k}`. -/\nlemma count_eq_card_fintype (n : \u2115) : count p n = fintype.card {k : \u2115 // k < n \u2227 p k} :=\nby { rw [count_eq_card_filter_range, \u2190fintype.card_of_finset, \u2190count_set.fintype], refl, }\n\nlemma count_succ (n : \u2115) : count p (n + 1) = count p n + (if p n then 1 else 0) :=\nby split_ifs; simp [count, list.range_succ, h]\n\n@[mono] lemma count_monotone : monotone (count p) :=\nmonotone_nat_of_le_succ $ \u03bb n, by by_cases h : p n; simp [count_succ, h]\n\nlemma count_add (a b : \u2115) : count p (a + b) = count p a + count (\u03bb k, p (a + k)) b :=\nbegin\n  have : disjoint ((range a).filter p) (((range b).map $ add_left_embedding a).filter p),\n  { intros x hx,\n    simp_rw [inf_eq_inter, mem_inter, mem_filter, mem_map, mem_range] at hx,\n    obtain \u27e8\u27e8hx, _\u27e9, \u27e8c, _, rfl\u27e9, _\u27e9 := hx,\n    exact (self_le_add_right _ _).not_lt hx },\n  simp_rw [count_eq_card_filter_range, range_add, filter_union, card_disjoint_union this,\n    map_filter, add_left_embedding, card_map], refl,\nend\n\nlemma count_add' (a b : \u2115) : count p (a + b) = count (\u03bb k, p (k + b)) a + count p b :=\nby { rw [add_comm, count_add, add_comm], simp_rw [add_comm b] }\n\nlemma count_one : count p 1 = if p 0 then 1 else 0 := by simp [count_succ]\n\nlemma count_succ' (n : \u2115) : count p (n + 1) = count (\u03bb k, p (k + 1)) n + if p 0 then 1 else 0 :=\nby rw [count_add', count_one]\n\nvariables {p}\n\n@[simp] lemma count_lt_count_succ_iff {n : \u2115} : count p n < count p (n + 1) \u2194 p n :=\nby by_cases h : p n; simp [count_succ, h]\n\nlemma count_succ_eq_succ_count_iff {n : \u2115} : count p (n + 1) = count p n + 1 \u2194 p n :=\nby by_cases h : p n; simp [h, count_succ]\n\nlemma count_succ_eq_count_iff {n : \u2115} : count p (n + 1) = count p n \u2194 \u00acp n :=\nby by_cases h : p n; simp [h, count_succ]\n\nalias count_succ_eq_succ_count_iff \u2194 _ count_succ_eq_succ_count\nalias count_succ_eq_count_iff \u2194 _ count_succ_eq_count\n\nlemma count_le_cardinal (n : \u2115) : (count p n : cardinal) \u2264 cardinal.mk {k | p k} :=\nbegin\n  rw [count_eq_card_fintype, \u2190 cardinal.mk_fintype],\n  exact cardinal.mk_subtype_mono (\u03bb x hx, hx.2),\nend\n\nlemma lt_of_count_lt_count {a b : \u2115} (h : count p a < count p b) : a < b :=\n(count_monotone p).reflect_lt h\n\nlemma count_strict_mono {m n : \u2115} (hm : p m) (hmn : m < n) : count p m < count p n :=\n(count_lt_count_succ_iff.2 hm).trans_le $ count_monotone _ (nat.succ_le_iff.2 hmn)\n\nlemma count_injective {m n : \u2115} (hm : p m) (hn : p n) (heq : count p m = count p n) : m = n :=\nbegin\n  by_contra,\n  wlog hmn : m < n,\n  { exact ne.lt_or_lt h },\n  { simpa [heq] using count_strict_mono hm hmn }\nend\n\nlemma count_le_card (hp : (set_of p).finite) (n : \u2115) : count p n \u2264 hp.to_finset.card :=\nbegin\n  rw count_eq_card_filter_range,\n  exact finset.card_mono (\u03bb x hx, hp.mem_to_finset.2 (mem_filter.1 hx).2)\nend\n\nlemma count_lt_card {n : \u2115} (hp : (set_of p).finite) (hpn : p n) :\n  count p n < hp.to_finset.card :=\n(count_lt_count_succ_iff.2 hpn).trans_le (count_le_card hp _)\n\nvariable {q : \u2115 \u2192 Prop}\nvariable [decidable_pred q]\n\n\n\nend count\n\nend nat\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/nat/count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7354280878787679}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n\n! This file was ported from Lean 3 source module init.meta.well_founded_tactics\n! leanprover-community/lean commit 855e5b74e3a52a40552e8f067169d747d48743fd\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nprelude\nimport Mathlib.Init.Data.Nat.Lemmas\n\n-- Porting note: meta code used to implement well-founded recursion is not ported\n\ntheorem Nat.lt_add_of_zero_lt_left (a b : Nat) (h : 0 < b) : a < a + b :=\n  show a + 0 < a + b by\n    apply Nat.add_lt_add_left\n    assumption\n#align nat.lt_add_of_zero_lt_left Nat.lt_add_of_zero_lt_left\n\ntheorem Nat.zero_lt_one_add (a : Nat) : 0 < 1 + a :=\n  suffices 0 < a + 1 by\n    simp [Nat.add_comm]\n    assumption\n  Nat.zero_lt_succ _\n#align nat.zero_lt_one_add Nat.zero_lt_one_add\n\n#align nat.lt_add_right Nat.lt_add_right\n\ntheorem Nat.lt_add_left (a b c : Nat) : a < b \u2192 a < c + b := fun h =>\n  lt_of_lt_of_le h (Nat.le_add_left _ _)\n#align nat.lt_add_left Nat.lt_add_left\n\n/-\nThe remainder of the original Lean 3 source module is subsumed by Lean 4 core.\n-/\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Init/Meta/WellFoundedTactics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.735428085508195}}
{"text": "/-\nCopyright (c) 2021 Tian Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tian Chen\n-/\nimport data.pnat.basic\n\n/-!\n# IMO 1977 Q6\n\nSuppose `f : \u2115+ \u2192 \u2115+` satisfies `f(f(n)) < f(n + 1)` for all `n`.\nProve that `f(n) = n` for all `n`.\n\nWe first prove the problem statement for `f : \u2115 \u2192 \u2115`\nthen we use it to prove the statement for positive naturals.\n-/\n\ntheorem imo1977_q6_nat (f : \u2115 \u2192 \u2115) (h : \u2200 n, f (f n) < f (n + 1)) :\n  \u2200 n, f n = n :=\nbegin\n  have h' : \u2200 (k n : \u2115), k \u2264 n \u2192 k \u2264 f n,\n  { intro k,\n    induction k with k h_ind,\n    { intros, exact nat.zero_le _ },\n    { intros n hk,\n      apply nat.succ_le_of_lt,\n      calc k \u2264 f (f (n - 1)) : h_ind _ (h_ind (n - 1) (nat.le_sub_right_of_add_le hk))\n         ... < f n           : nat.sub_add_cancel\n        (le_trans (nat.succ_le_succ (nat.zero_le _)) hk) \u25b8 h _ } },\n  have hf : \u2200 n, n \u2264 f n := \u03bb n, h' n n rfl.le,\n  have hf_mono : strict_mono f := strict_mono.nat (\u03bb _, lt_of_le_of_lt (hf _) (h _)),\n  intro,\n  exact nat.eq_of_le_of_lt_succ (hf _) (hf_mono.lt_iff_lt.mp (h _))\nend\n\ntheorem imo1977_q6 (f : \u2115+ \u2192 \u2115+) (h : \u2200 n, f (f n) < f (n + 1)) :\n  \u2200 n, f n = n :=\nbegin\n  intro n,\n  simpa using imo1977_q6_nat (\u03bb m, if 0 < m then f m.to_pnat' else 0) _ n,\n  { intro x, cases x,\n    { simp },\n    { simpa using h _ } }\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/imo/imo1977_q6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7354280851563335}}
{"text": "-- Based on Kevin Buzzard's Zulip message \"Two hours of Lean\" - Nov 23rd 2021\n\nimport tactic\n\n-- Define a number as a zero, and a successor\ninductive number\n| zero           : number\n| S (n : number) : number\n\n-- start a namespace to work in (means we can type zero rather than number.zero)\nnamespace number\n\n-- Define some common numbers\ndef one   := S(zero)\ndef two   := S(one)\ndef three := S(two)\ndef four  := S(three)\n\n-- before we can prove two + two = four we have to define what + means\n\n-- add is a binary operator on two numbers that make another number\ndef add : number \u2192 number \u2192 number\n| n zero   := n            -- adding zero to a number just returns that number\n| n (S(d)) := S(add n d)   -- adding a non zero number to n is the successor of n and that non zero number\n\n-- Surprisingly refl will easily prove this\nexample : add two two = four := rfl\n\n-- We can't at this point write 2 + 2 because we haven't defined the infix notation of +\n\n-- In lean we define the infix notation + to be number.add\ninfix `+` := number.add\n\n-- and now we can write\nexample : two + two = four := rfl\n\n-- end our namespace\nend number\n", "meta": {"author": "andrewparr", "repo": "my_lean_project", "sha": "6c42f8a5d8b6548b5871d589054820b4bd8eedcc", "save_path": "github-repos/lean/andrewparr-my_lean_project", "path": "github-repos/lean/andrewparr-my_lean_project/my_lean_project-6c42f8a5d8b6548b5871d589054820b4bd8eedcc/src/notes/two_plus_two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7354197930183799}}
{"text": "import group_theory.subgroup\n\n/-!\nThis file supplements two instances relavant to monoid homomorphisms\n-/\n\nnamespace monoid_hom\nvariables {G N: Type*} [group G] [group N] \n\n/-- If the equality in `N` is decidable and `f : G \u2192* N` is a `monoid_hom`, \n    then the membership of `f.ker.carrier` is decidable. -/\ninstance [decidable_eq N] (f : G \u2192* N) (x : G) :\ndecidable (x \u2208 f.ker.carrier) := f.decidable_mem_ker x\n\n/-- If `G` is a finite type, and the equality in `N` is decidable, \n    and `f : G \u2192* N` is a `monoid_hom`, then `f.ker.carrier` is a finite type. -/\ninstance [fintype G] [decidable_eq N] (f : G \u2192* N) : \nfintype (f.ker.carrier) := set_fintype (f.ker.carrier)\n\n/-\nlemma fintype_card_ker_eq_card_ker_carrier [fintype G] [decidable_eq N] (f : G \u2192* N) : \nfintype.card f.ker = fintype.card f.ker.carrier := \nby refl\n-/\n\nend monoid_hom", "meta": {"author": "l534zhan", "repo": "my_project", "sha": "8949e149c242debd7cf932ba252cb67b10e78a43", "save_path": "github-repos/lean/l534zhan-my_project", "path": "github-repos/lean/l534zhan-my_project/my_project-8949e149c242debd7cf932ba252cb67b10e78a43/src/monoid_hom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7354197854741831}}
{"text": "/-\nCopyright (c) 2020 Hanting Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hanting Zhang, Johan Commelin\n-/\nimport data.fintype.card\nimport data.mv_polynomial.rename\nimport data.mv_polynomial.comm_ring\nimport algebra.algebra.subalgebra.basic\n\n/-!\n# Symmetric Polynomials and Elementary Symmetric Polynomials\n\nThis file defines symmetric `mv_polynomial`s and elementary symmetric `mv_polynomial`s.\nWe also prove some basic facts about them.\n\n## Main declarations\n\n* `mv_polynomial.is_symmetric`\n\n* `mv_polynomial.symmetric_subalgebra`\n\n* `mv_polynomial.esymm`\n\n## Notation\n\n+ `esymm \u03c3 R n`, is the `n`th elementary symmetric polynomial in `mv_polynomial \u03c3 R`.\n\nAs in other polynomial files, we typically use the notation:\n\n+ `\u03c3 \u03c4 : Type*` (indexing the variables)\n\n+ `R S : Type*` `[comm_semiring R]` `[comm_semiring S]` (the coefficients)\n\n+ `r : R` elements of the coefficient ring\n\n+ `i : \u03c3`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians\n\n+ `\u03c6 \u03c8 : mv_polynomial \u03c3 R`\n\n-/\n\nopen equiv (perm)\nopen_locale big_operators\nnoncomputable theory\n\nnamespace mv_polynomial\n\nvariables {\u03c3 : Type*} {R : Type*}\nvariables {\u03c4 : Type*} {S : Type*}\n\n/-- A `mv_polynomial \u03c6` is symmetric if it is invariant under\npermutations of its variables by the  `rename` operation -/\ndef is_symmetric [comm_semiring R] (\u03c6 : mv_polynomial \u03c3 R) : Prop :=\n\u2200 e : perm \u03c3, rename e \u03c6 = \u03c6\n\nvariables (\u03c3 R)\n\n/-- The subalgebra of symmetric `mv_polynomial`s. -/\ndef symmetric_subalgebra [comm_semiring R] : subalgebra R (mv_polynomial \u03c3 R) :=\n{ carrier := set_of is_symmetric,\n  algebra_map_mem' := \u03bb r e, rename_C e r,\n  mul_mem' := \u03bb a b ha hb e, by rw [alg_hom.map_mul, ha, hb],\n  add_mem' := \u03bb a b ha hb e, by rw [alg_hom.map_add, ha, hb] }\n\nvariables {\u03c3 R}\n\n@[simp] lemma mem_symmetric_subalgebra [comm_semiring R] (p : mv_polynomial \u03c3 R) :\n  p \u2208 symmetric_subalgebra \u03c3 R \u2194 p.is_symmetric := iff.rfl\n\nnamespace is_symmetric\n\nsection comm_semiring\nvariables [comm_semiring R] [comm_semiring S] {\u03c6 \u03c8 : mv_polynomial \u03c3 R}\n\n@[simp]\nlemma C (r : R) : is_symmetric (C r : mv_polynomial \u03c3 R) :=\n(symmetric_subalgebra \u03c3 R).algebra_map_mem r\n\n@[simp]\nlemma zero : is_symmetric (0 : mv_polynomial \u03c3 R) :=\n(symmetric_subalgebra \u03c3 R).zero_mem\n\n@[simp]\nlemma one : is_symmetric (1 : mv_polynomial \u03c3 R) :=\n(symmetric_subalgebra \u03c3 R).one_mem\n\nlemma add (h\u03c6 : is_symmetric \u03c6) (h\u03c8 : is_symmetric \u03c8) : is_symmetric (\u03c6 + \u03c8) :=\n(symmetric_subalgebra \u03c3 R).add_mem h\u03c6 h\u03c8\n\nlemma mul (h\u03c6 : is_symmetric \u03c6) (h\u03c8 : is_symmetric \u03c8) : is_symmetric (\u03c6 * \u03c8) :=\n(symmetric_subalgebra \u03c3 R).mul_mem h\u03c6 h\u03c8\n\nlemma smul (r : R) (h\u03c6 : is_symmetric \u03c6) : is_symmetric (r \u2022 \u03c6) :=\n(symmetric_subalgebra \u03c3 R).smul_mem h\u03c6 r\n\n@[simp]\nlemma map (h\u03c6 : is_symmetric \u03c6) (f : R \u2192+* S) : is_symmetric (map f \u03c6) :=\n\u03bb e, by rw [\u2190 map_rename, h\u03c6]\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R] {\u03c6 \u03c8 : mv_polynomial \u03c3 R}\n\nlemma neg (h\u03c6 : is_symmetric \u03c6) : is_symmetric (-\u03c6) :=\n(symmetric_subalgebra \u03c3 R).neg_mem h\u03c6\n\nlemma sub (h\u03c6 : is_symmetric \u03c6) (h\u03c8 : is_symmetric \u03c8) : is_symmetric (\u03c6 - \u03c8) :=\n(symmetric_subalgebra \u03c3 R).sub_mem h\u03c6 h\u03c8\n\nend comm_ring\n\nend is_symmetric\n\nsection elementary_symmetric\nopen finset\nvariables (\u03c3 R) [comm_semiring R] [comm_semiring S] [fintype \u03c3] [fintype \u03c4]\n\n/-- The `n`th elementary symmetric `mv_polynomial \u03c3 R`. -/\ndef esymm (n : \u2115) : mv_polynomial \u03c3 R :=\n\u2211 t in powerset_len n univ, \u220f i in t, X i\n\n/-- We can define `esymm \u03c3 R n` by summing over a subtype instead of over `powerset_len`. -/\nlemma esymm_eq_sum_subtype (n : \u2115) : esymm \u03c3 R n =\n  \u2211 t : {s : finset \u03c3 // s.card = n}, \u220f i in (t : finset \u03c3), X i :=\nbegin\n  rw esymm,\n  let i : \u03a0 (a : finset \u03c3), a \u2208 powerset_len n univ \u2192 {s : finset \u03c3 // s.card = n} :=\n    \u03bb a ha, \u27e8_, (mem_powerset_len.mp ha).2\u27e9,\n  refine sum_bij i (\u03bb a ha, mem_univ (i a ha)) _ (\u03bb _ _ _ _ hi, subtype.ext_iff_val.mp hi) _,\n  { intros,\n    apply prod_congr,\n    simp only [subtype.coe_mk],\n    intros, refl,},\n  { refine (\u03bb b H, \u27e8b.val, mem_powerset_len.mpr \u27e8subset_univ b.val, b.property\u27e9, _\u27e9),\n    simp [i] },\nend\n\n/-- We can define `esymm \u03c3 R n` as a sum over explicit monomials -/\nlemma esymm_eq_sum_monomial (n : \u2115) : esymm \u03c3 R n =\n  \u2211 t in powerset_len n univ, monomial (\u2211 i in t, finsupp.single i 1) 1 :=\nbegin\n  refine sum_congr rfl (\u03bb x hx, _),\n  rw monic_monomial_eq,\n  rw finsupp.prod_pow,\n  rw \u2190 prod_subset (\u03bb y _, finset.mem_univ y : x \u2286 univ) (\u03bb y _ hy, _),\n  { refine prod_congr rfl (\u03bb x' hx', _),\n    convert (pow_one _).symm,\n    convert (finsupp.apply_add_hom x' : (\u03c3 \u2192\u2080 \u2115) \u2192+ \u2115).map_sum _ x,\n    classical,\n    simp [finsupp.single_apply, finset.filter_eq', apply_ite, apply_ite finset.card],\n    rw if_pos, exact hx', },\n  { convert pow_zero _,\n    convert (finsupp.apply_add_hom y : (\u03c3 \u2192\u2080 \u2115) \u2192+ \u2115).map_sum _ x,\n    classical,\n    simp [finsupp.single_apply, finset.filter_eq', apply_ite, apply_ite finset.card],\n    rw if_neg, exact hy }\nend\n\n@[simp] lemma esymm_zero : esymm \u03c3 R 0 = 1 :=\nby simp only [esymm, powerset_len_zero, sum_singleton, prod_empty]\n\nlemma map_esymm (n : \u2115) (f : R \u2192+* S) : map f (esymm \u03c3 R n) = esymm \u03c3 S n :=\nbegin\n  rw [esymm, (map f).map_sum],\n  refine sum_congr rfl (\u03bb x hx, _),\n  rw (map f).map_prod,\n  simp,\nend\n\nlemma rename_esymm (n : \u2115) (e : \u03c3 \u2243 \u03c4) : rename e (esymm \u03c3 R n) = esymm \u03c4 R n :=\nbegin\n  rw [esymm_eq_sum_subtype, esymm_eq_sum_subtype, (rename \u21d1e).map_sum],\n  let e' : {s : finset \u03c3 // s.card = n} \u2243 {s : finset \u03c4 // s.card = n} :=\n    equiv.subtype_equiv (equiv.finset_congr e) (by simp),\n  rw \u2190 equiv.sum_comp e'.symm,\n  apply fintype.sum_congr,\n  intro,\n  calc _ = (\u220f i in (e'.symm a : finset \u03c3), (rename e) (X i)) : (rename e).map_prod _ _\n     ... = (\u220f i in (a : finset \u03c4), (rename e) (X (e.symm i))) : prod_map (a : finset \u03c4) _ _\n     ... = _ : _,\n  apply finset.prod_congr rfl,\n  intros,\n  simp,\nend\n\nlemma esymm_is_symmetric (n : \u2115) : is_symmetric (esymm \u03c3 R n) :=\nby { intro, rw rename_esymm }\n\nlemma support_esymm'' (n : \u2115) [decidable_eq \u03c3] [nontrivial R] :\n  (esymm \u03c3 R n).support = (powerset_len n (univ : finset \u03c3)).bUnion\n    (\u03bb t, (finsupp.single (\u2211 (i : \u03c3) in t, finsupp.single i 1) (1:R)).support) :=\nbegin\n  rw esymm_eq_sum_monomial,\n  simp only [\u2190 single_eq_monomial],\n  convert finsupp.support_sum_eq_bUnion (powerset_len n (univ : finset \u03c3)) _,\n  intros s t hst d,\n  simp only [finsupp.support_single_ne_zero one_ne_zero, and_imp, inf_eq_inter, mem_inter,\n             mem_singleton],\n  rintro h rfl,\n  have := congr_arg finsupp.support h,\n  rw [finsupp.support_sum_eq_bUnion, finsupp.support_sum_eq_bUnion] at this,\n  { simp only [finsupp.support_single_ne_zero one_ne_zero, bUnion_singleton_eq_self] at this,\n    exact absurd this hst.symm },\n  all_goals { intros x y, simp [finsupp.support_single_disjoint] }\nend\n\nlemma support_esymm' (n : \u2115) [decidable_eq \u03c3] [nontrivial R] :\n  (esymm \u03c3 R n).support =\n  (powerset_len n (univ : finset \u03c3)).bUnion (\u03bb t, {\u2211 (i : \u03c3) in t, finsupp.single i 1}) :=\nbegin\n  rw support_esymm'',\n  congr,\n  funext,\n  exact finsupp.support_single_ne_zero one_ne_zero\nend\n\nlemma support_esymm (n : \u2115) [decidable_eq \u03c3] [nontrivial R] :\n  (esymm \u03c3 R n).support =\n  (powerset_len n (univ : finset \u03c3)).image (\u03bb t, \u2211 (i : \u03c3) in t, finsupp.single i 1) :=\nby { rw support_esymm', exact bUnion_singleton }\n\nlemma degrees_esymm [nontrivial R]\n  (n : \u2115) (hpos : 0 < n) (hn : n \u2264 fintype.card \u03c3) :\n  (esymm \u03c3 R n).degrees = (univ : finset \u03c3).val :=\nbegin\n  classical,\n  have : (finsupp.to_multiset \u2218 \u03bb (t : finset \u03c3), \u2211 (i : \u03c3) in t, finsupp.single i 1) = finset.val,\n  { funext, simp [finsupp.to_multiset_sum_single] },\n  rw [degrees, support_esymm, sup_finset_image, this, \u2190comp_sup_eq_sup_comp],\n  { obtain \u27e8k, rfl\u27e9 := nat.exists_eq_succ_of_ne_zero hpos.ne',\n    simpa using powerset_len_sup _ _ (nat.lt_of_succ_le hn) },\n  { intros,\n    simp only [union_val, sup_eq_union],\n    congr },\n  { refl }\nend\n\nend elementary_symmetric\n\nend mv_polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/polynomial/symmetric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7354197713775705}}
{"text": "import categories.category\nimport categories.isomorphism\nimport categories.tactics\nimport categories.functor\nimport categories.ndefs\nopen categories\nopen categories.isomorphism\nopen categories.functor\nopen tactic\n\n--delaration of universes and variables\nuniverses u v u\u2081 v\u2081\nvariables (C : Type u\u2081) [\ud835\udc9e : category.{u\u2081 v\u2081} C]\ninclude \ud835\udc9e\n\n-- 1a Show that identities in a category are unique\ntheorem uniq_id (X : C) (id' : X \u27f6 X) : (\u2200 {A : C} (g : X \u27f6 A), id' \u226b g = g) \u2192 (\u2200 {A : C} (g : A \u27f6 X), g \u226b id' = g) \u2192 (id' = \ud835\udfd9X) :=\n    begin\n        intros hl hr,\n        transitivity,\n        symmetry,\n        exact category.right_identity_lemma C id',\n        exact hl(\ud835\udfd9X)\n    end\n\n-- 1b Show that a morphism with both a left inverse and right inverse is an isomorphism\ntheorem landr_id (X Y Z : C) (f : X \u27f6 Y) : (\u2203 gl : Y \u27f6 X, gl \u226b f = \ud835\udfd9Y) \u2192 (\u2203 gr : Y \u27f6 X, f \u226b gr = \ud835\udfd9X) \u2192 (is_Isomorphism' f) :=\n    begin\n    intros,\n    cases (classical.indefinite_description _ a) with gl hl,\n    cases (classical.indefinite_description _ a_1) with gr hr,\n    apply nonempty.intro \n        (\u27e8gr, hr,    \n            begin \n                simp,\n                symmetry,\n                exact calc\n                \ud835\udfd9Y     = gl \u226b f                : eq.symm hl\n                ...    = gl \u226b \ud835\udfd9X \u226b f           : by rw category.left_identity_lemma C f\n                ...    = (gl \u226b \ud835\udfd9X) \u226b f         : by rw category.associativity_lemma\n                ...    = (gl \u226b (f \u226b gr)) \u226b f  : by rw hr\n                ...    = ((gl \u226b f) \u226b gr) \u226b f  : by rw category.associativity_lemma C gl f gr \n                ...    = (\ud835\udfd9Y \u226b gr) \u226b f         : by rw hl\n                ...    = gr \u226b f                 : by rw category.left_identity_lemma C gr\n            end\u27e9 \n        : is_Isomorphism f)\n    end\n\n-- 1c Consider f : X \u27f6 Y and g : Y \u27f6 Z. Show that if two out of f, g and gf are isomorphisms,then so is the third.\nsection Two_Out_Of_Three\n    variables (X Y Z : C)\n    variables (f : X \u27f6 Y) (g : Y \u27f6 Z)\n    \n    theorem tootfirsec : is_Isomorphism' f \u2192 is_Isomorphism' g \u2192 is_Isomorphism' (f \u226b g) :=\n        begin\n            intros hf hg,\n            apply hf.elim,\n            apply hg.elim,\n            intros Ig If,\n            exact nonempty.intro \n                \u27e8Ig.1 \u226b If.1,\n                begin\n                    simp,\n                    exact calc\n                    f \u226b g \u226b Ig.1 \u226b If.1 = f \u226b (g \u226b Ig.1) \u226b If.1 : by rw category.associativity_lemma\n                    ...                   = f \u226b \ud835\udfd9Y \u226b If.1          : by rw is_Isomorphism.witness_1_lemma\n                    ...                   = f \u226b If.1               : by rw category.left_identity_lemma\n                    ...                   = \ud835\udfd9X                      : by rw is_Isomorphism.witness_1_lemma\n                end,    \n                begin \n                    simp,\n                    exact calc\n                        Ig.1 \u226b If.1 \u226b f \u226b g  = Ig.1 \u226b (If.1 \u226b f) \u226b g : by rw category.associativity_lemma\n                        ...                    = Ig.1 \u226b \ud835\udfd9Y \u226b g          : by rw is_Isomorphism.witness_2_lemma\n                        ...                    = Ig.1 \u226b g               : by rw category.left_identity_lemma\n                        ...                    = \ud835\udfd9Z                      : by rw is_Isomorphism.witness_2_lemma\n                end\u27e9\n        end\n\n    theorem tootsecthi : is_Isomorphism' g \u2192 is_Isomorphism' (f \u226b g) \u2192 is_Isomorphism' f :=\n        begin\n            intros hg hfg,\n            apply hg.elim,\n            apply hfg.elim,\n            intros Ifg Ig,\n            exact nonempty.intro\n                \u27e8g \u226b Ifg.1,\n                    begin\n                        simp,\n                        exact calc\n                            f \u226b g \u226b Ifg.1 = (f \u226b g) \u226b Ifg.1 : by rw category.associativity_lemma\n                            ... = \ud835\udfd9X : by rw is_Isomorphism.witness_1_lemma\n                    end,\n                    begin\n                        simp,\n                        exact calc\n                            g \u226b Ifg.1 \u226b f = (g \u226b Ifg.1 \u226b f) \u226b \ud835\udfd9Y : by rw category.right_identity_lemma\n                            ... = g \u226b (Ifg.1 \u226b f) \u226b \ud835\udfd9Y : by rw category.associativity_lemma\n                            ... = g \u226b Ifg.1 \u226b f \u226b \ud835\udfd9Y : by rw category.associativity_lemma\n                            ... = g \u226b Ifg.1 \u226b f \u226b g \u226b Ig.1 : by rw is_Isomorphism.witness_1_lemma\n                            ... = g \u226b (Ifg.1 \u226b ((f \u226b g) \u226b Ig.1)) : by rw category.associativity_lemma\n                            ... = g \u226b (Ifg.1 \u226b (f \u226b g)) \u226b Ig.1 : by rw (category.associativity_lemma C Ifg.1 (f \u226b g) Ig.1)\n                            ... = g \u226b \ud835\udfd9Z \u226b Ig.1 : by rw is_Isomorphism.witness_2_lemma\n                            ... = g \u226b Ig.1 : by rw category.left_identity_lemma\n                            ... = \ud835\udfd9Y : by rw is_Isomorphism.witness_1_lemma\n                    end\u27e9\n        end\n    theorem tootfirthi : is_Isomorphism' f \u2192 is_Isomorphism' (f \u226b g) \u2192 is_Isomorphism' g :=\n        begin\n            intros hf hfg,\n            apply hf.elim,\n            apply hfg.elim,\n            intros Ifg If,\n            exact nonempty.intro\n                \u27e8Ifg.1 \u226b f,\n                    begin\n                        simp,\n                        exact calc\n                            g \u226b Ifg.1 \u226b f = \ud835\udfd9Y \u226b g \u226b Ifg.1 \u226b f : by rw category.left_identity_lemma\n                            ... = (If.1 \u226b f) \u226b g \u226b Ifg.1 \u226b f : by rw is_Isomorphism.witness_2_lemma\n                            ... = ((If.1 \u226b f) \u226b g) \u226b Ifg.1 \u226b f : by rw (category.associativity_lemma C (If.1 \u226b f) g (Ifg.1 \u226b f))\n                            ... = (If.1 \u226b (f \u226b g)) \u226b Ifg.1 \u226b f : by rw (category.associativity_lemma C If.1 f g)\n                            ... = If.1 \u226b (f \u226b g) \u226b Ifg.1 \u226b f : by rw category.associativity_lemma\n                            ... = If.1 \u226b ((f \u226b g) \u226b Ifg.1) \u226b f : by rw (category.associativity_lemma C (f \u226b g) Ifg.1 f)\n                            ... = If.1 \u226b \ud835\udfd9X \u226b f : by rw is_Isomorphism.witness_1_lemma\n                            ... = If.1 \u226b f : by rw category.left_identity_lemma\n                            ... = \ud835\udfd9Y : by rw is_Isomorphism.witness_2_lemma\n                    end,\n                    begin\n                        simp\n                    end\u27e9\n        end\nend Two_Out_Of_Three\n\nvariables {D : Type u} [\ud835\udc9f : category.{u v} D]\ninclude \ud835\udc9f\n\n-- 1d Show functors preserve isomorphisms\ntheorem fun_id (F : C \u219d D) (X Y : C) (f : X \u27f6 Y) : (is_Isomorphism' f) \u2192 (is_Isomorphism' (F &> f)) :=\n    begin\n        intro hf,\n        apply hf.elim,\n        intro If,\n        exact nonempty.intro\n            /- \u27e8F &> If.1,\n            begin\n                simp,\n                exact calc\n                    (F &> f) \u226b (F &> If.1) = F &> (f \u226b If.1) : by rw Functor.functoriality_lemma\n                    ... = F &> \ud835\udfd9X : by rw is_Isomorphism.witness_1_lemma\n                    ... = \ud835\udfd9 (F +> X) : by rw Functor.identities\n            end,\n            begin\n                simp,\n                exact calc\n                    (F &> If.1) \u226b (F &> f) = F &> (If.1 \u226b f) : by rw Functor.functoriality_lemma\n                    ... = F &> \ud835\udfd9Y : by rw is_Isomorphism.witness_2_lemma\n                    ... = \ud835\udfd9 (F +> Y) : by rw Functor.identities\n            end\u27e9 -/\n            (isomorphism.is_Isomorphism_of_Isomorphism (F.onIsomorphisms \u27e8f , If.1, by simp, by simp\u27e9))\n    end\n\n-- 1e Show that if F : C \u219d D is full and faithful, and F &> f : F +> A \u27f6 F +> B is an isomorphism in \ud835\udc9f, then f : A \u27f6 B is an isomorphism in \ud835\udc9e\ntheorem reflecting_isomorphisms (F : C \u219d D) (X Y : C) (f : X \u27f6 Y) : is_Full_Functor F \u2192 is_Faithful_Functor F \u2192 is_Isomorphism' (F &> f) \u2192 is_Isomorphism' f :=\n    begin\n        intros hfu hfa hFf,\n        apply hFf.elim,\n        intro IFf,\n        cases (classical.indefinite_description _ (hfu IFf.1)) with g hg,\n        apply nonempty.intro\n            (\u27e8g,\n            begin\n                simp,\n                exact hfa\n                    (calc\n                        F &> (f \u226b g) = (F &> f) \u226b (F &> g) : by rw Functor.functoriality_lemma\n                        ... = \ud835\udfd9(F +> X) : by rw [hg, is_Isomorphism.witness_1_lemma]\n                        ... = F &> (\ud835\udfd9X) : by rw Functor.identities\n                    )\n            end,\n            begin\n                simp,\n                exact hfa\n                    (calc\n                        F &> (g \u226b f) = (F &> g) \u226b (F &> f) : by rw Functor.functoriality_lemma\n                        ... = \ud835\udfd9(F +> Y) : by rw [hg, is_Isomorphism.witness_2_lemma]\n                        ... = F &> (\ud835\udfd9Y) : by rw Functor.identities\n                    )\n            end\u27e9\n            : is_Isomorphism f)\n    end", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/category_theory/Problems/1_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7354197713775705}}
{"text": "-- Chapter 16\n\n-- Lucas Machado Moschen\n\n-- Exerc\u00edcio 1\nimport data.set \n\nopen function int algebra\n\nsection \n\n    def f (x : \u2124) : \u2124 := x + 3\n    def g (x : \u2124) : \u2124 := -x\n    def h (x : \u2124) : \u2124 := 2 * x + 3\n\n    example : injective f :=\n    assume x1 x2,\n    assume h1 : x1 + 3 = x2 + 3,   -- Lean knows this is the same as f x1 = f x2\n    show x1 = x2, from eq_of_add_eq_add_right h1\n\n    example : surjective f :=\n    assume y,\n    have h1 : f (y - 3) = y, from calc\n    f (y - 3) = (y - 3) + 3 : rfl\n            ... = y           : by rw sub_add_cancel,\n    show \u2203 x, f x = y, from exists.intro (y - 3) h1\n\n    example (x y : \u2124) (h : 2 * x = 2 * y) : x = y :=\n    have h1 : 2 \u2260 (0 : \u2124), from dec_trivial,  -- this tells Lean to figure it out itself\n    show x = y, from eq_of_mul_eq_mul_left h1 h\n\n    example (x : \u2124) : -(-x) = x := neg_neg x\n\n    example (A B : Type) (u : A \u2192 B) (v : B \u2192 A) (h : left_inverse u v) :\n    \u2200 x, u (v x) = x :=\n    h\n\n    example (A B : Type) (u : A \u2192 B) (v : B \u2192 A) (h : left_inverse u v) :\n    right_inverse v u :=\n    h\n\n    -- fill in the sorry's in the following proofs\n\n    example : injective h :=\n    begin \n        assume x1 x2, \n        assume h1, \n        have h2: 2 \u2260 (0 : \u2124), from dec_trivial, \n        apply eq_of_mul_eq_mul_left h2 (eq_of_add_eq_add_right h1),\n    end\n\n    example : surjective g :=\n    begin\n        assume y, \n        have h: g (-y) = y, from calc\n            g (-y) = -(-y) : rfl \n            ...    = y : by rw neg_neg, \n        apply exists.intro (-y),\n        exact h\n    end\n\n    example (A B : Type) (u : A \u2192 B) (v1 : B \u2192 A) (v2 : B \u2192 A)\n    (h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=\n    funext\n    (assume x,\n        calc\n        v1 x = v1 (u (v2 x)) : by rw h2\n        ... = v2 x          : by rw h1)\nend\n\n-- Exerc\u00edcio 2\n\nsection \n\n    open function set\n\n    variables {X Y : Type}\n    variable  f : X \u2192 Y\n    variables A B : set X\n\n    example : f '' (A \u222a B) = f '' A \u222a f '' B :=\n    eq_of_subset_of_subset\n    (assume y,\n        assume h1 : y \u2208 f '' (A \u222a B),\n        exists.elim h1 $\n        assume x h,\n        have h2 : x \u2208 A \u222a B, from h.left,\n        have h3 : f x = y, from h.right,\n        or.elim h2\n        (assume h4 : x \u2208 A,\n            have h5 : y \u2208 f '' A, from \u27e8x, h4, h3\u27e9,\n            show y \u2208 f '' A \u222a f '' B, from or.inl h5)\n        (assume h4 : x \u2208 B,\n            have h5 : y \u2208 f ''  B, from \u27e8x, h4, h3\u27e9,\n            show y \u2208 f '' A \u222a f '' B, from or.inr h5))\n    (assume y,\n        assume h2 : y \u2208 f '' A \u222a f '' B,\n        or.elim h2\n        (assume h3 : y \u2208 f '' A,\n            exists.elim h3 $\n            assume x h,\n            have h4 : x \u2208 A, from h.left,\n            have h5 : f x = y, from h.right,\n            have h6 : x \u2208 A \u222a B, from or.inl h4,\n            show y \u2208 f '' (A \u222a B), from \u27e8x, h6, h5\u27e9)\n        (assume h3 : y \u2208 f '' B,\n            exists.elim h3 $\n            assume x h,\n            have h4 : x \u2208 B, from h.left,\n            have h5 : f x = y, from h.right,\n            have h6 : x \u2208 A \u222a B, from or.inr h4,\n            show y \u2208 f '' (A \u222a B), from \u27e8x, h6, h5\u27e9))\n\n    -- remember, x \u2208 A \u2229 B is the same as x \u2208 A \u2227 x \u2208 B\n    example (x : X) (h1 : x \u2208 A) (h2 : x \u2208 B) : x \u2208 A \u2229 B :=\n    and.intro h1 h2\n\n    example (x : X) (h1 : x \u2208 A \u2229 B) : x \u2208 A :=\n    and.left h1\n\n    -- Fill in the proof below.\n    -- (It should take about 8 lines.)\n\n    example : f '' (A \u2229 B) \u2286 f '' A \u2229 f '' B :=\n    assume y,\n    assume h1 : y \u2208 f '' (A \u2229 B),\n    show y \u2208 f '' A \u2229 f '' B, from \n    begin\n        apply and.intro, \n        cases h1 with x h2,  \n            have h3: x \u2208 A \u2227 f x = y, \n                from and.intro (h2.left.left) h2.right,\n            apply exists.intro x, \n            exact h3,\n        cases h1 with x h2,\n            have h3: x \u2208 B \u2227 f x = y,\n                from and.intro (h2.left.right) h2.right,\n            apply exists.intro x,\n            exact h3 \n    end\n\nend", "meta": {"author": "lucasmoschen", "repo": "discrete-mathematics", "sha": "0f1945cc5eb094814c926cd6ae4a8b4c5c579a1e", "save_path": "github-repos/lean/lucasmoschen-discrete-mathematics", "path": "github-repos/lean/lucasmoschen-discrete-mathematics/discrete-mathematics-0f1945cc5eb094814c926cd6ae4a8b4c5c579a1e/Exercises/Lista 7/cap16-LucasMoschen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7354155395369437}}
{"text": "import inter.level3\nimport tactic\n\n/- Tactic : use\nWhen the goal is to prove an existential, `\u2203` we can\nsupply the witness (an example that has the desired property)\nusing the tactic `use`.\n\nFor example :\nIf the goal is\n```\n\u22a2 \u2203 n : \u2115, n + 1 = 1\n```\nthen we have to take `n` to be zero, so we type `use 0`.\nThe remaining goal will then be that\n`0 + 1 = 1`\nwhich is provable with `zero_add`.\n-/\n\n\n/- Lemma :\n-/\nlemma exists_betwn : \u2203 n : \u2115, 8 < n \u2227 n < 10 :=\nbegin\n  use 9,\n  split,\n  exact nat.lt_succ_self 8,\n  exact nat.lt_succ_self 9,\nend\n", "meta": {"author": "alexjbest", "repo": "CAP-game", "sha": "d823def7325d7142d61e766b2e027f936685a8ff", "save_path": "github-repos/lean/alexjbest-CAP-game", "path": "github-repos/lean/alexjbest-CAP-game/CAP-game-d823def7325d7142d61e766b2e027f936685a8ff/src/inter/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7353574271167478}}
{"text": "/-\nThe definition of a totally ordered set.\n-/\nclass TotalOrder (\u03b1 : Type _) [LE \u03b1] [DecidableRel $ @LE.le \u03b1 _] where\n  (reflLE : \u2200 a : \u03b1, a \u2264 a)\n  (antisymmLE : \u2200 {a b : \u03b1}, a \u2264 b \u2192 b \u2264 a \u2192 a = b)\n  (transLE : \u2200 {a b c : \u03b1}, a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c)\n  (totalLE : \u2200 a b : \u03b1, a \u2264 b \u2228 b \u2264 a)\n\nnamespace TotalOrder\n\ndef max {\u03b1 : Type _} [LE \u03b1] [DecidableRel $ @LE.le \u03b1 _] : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n  | a, b =>\n    if a \u2264 b then\n      b\n    else\n      a\n\ndef min {\u03b1 : Type _} [LE \u03b1] [DecidableRel $ @LE.le \u03b1 _] : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n  | a, b =>\n    if a \u2264 b then\n      a\n    else\n      b\n\nvariable {\u03b1 : Type} [LE \u03b1] [DecidableRel $ @LE.le \u03b1 _] [TotalOrder \u03b1]\nvariable {a b x : \u03b1}\n\ntheorem notLE : \u00ac(a \u2264 b) \u2192 b \u2264 a :=\n  \u03bb h : \u00ac(a \u2264 b) =>\n    match TotalOrder.totalLE a b with\n      | Or.inl h' => False.elim (h h')\n      | Or.inr h' => h'\n\ntheorem max_symm : max a b = max b a := by\n  byCases h:(a \u2264 b) <;> byCases h':(b \u2264 a) <;> simp [max, h, h']\n  \u00b7 apply TotalOrder.antisymmLE <;> assumption\n  \u00b7 apply TotalOrder.antisymmLE <;> (apply notLE ; assumption)\n\n@[simp] theorem max_left_le : TotalOrder.max a b \u2264 x \u2192 a \u2264 x :=\n  if h:(a \u2264 b) then by\n    simp [max, h]\n    intro h'\n    apply TotalOrder.transLE h h'\n  else by\n    simp [max, h]\n    exact id\n\n@[simp] theorem max_right_le : max a b \u2264 x \u2192 b \u2264 x := by\n  byCases h:(a \u2264 b) <;> simp [max, h]\n  \u00b7 exact id\n  \u00b7 intro h'\n    apply TotalOrder.transLE (notLE h) h'\n\ntheorem min_symm : min a b = min b a := by\n byCases h:(a \u2264 b) <;> byCases h':(b \u2264 a) <;> simp [min, h, h']\n  \u00b7 apply TotalOrder.antisymmLE <;> assumption\n  \u00b7 apply TotalOrder.antisymmLE <;> (apply notLE ; assumption)\n\n@[simp] theorem min_le_left : x \u2264 min a b \u2192 x \u2264 a := by\n  byCases h:(a \u2264 b) <;> simp [min, h]\n  \u00b7 exact id\n  \u00b7 intro h'\n    apply TotalOrder.transLE\n    \u00b7 assumption\n    \u00b7 apply notLE ; assumption\n\n@[simp] theorem min_le_right : x \u2264 min a b \u2192 x \u2264 b := by\n  byCases h:(a \u2264 b) <;> simp [min, h]\n  \u00b7 intro h'\n    exact TotalOrder.transLE h' h\n  \u00b7 exact id\n\ntheorem both_le_max_le : a \u2264 x \u2192 b \u2264 x \u2192 (max a b) \u2264 x := by\n  intro ; intro ; byCases h:(a \u2264 b) <;> simp [max, h] <;> assumption\n\ntheorem le_both_le_min : x \u2264 a \u2192 x \u2264 b \u2192 x \u2264 (min a b) := by\n  intro ; intro ; byCases h:(a \u2264 b) <;> simp [min, h] <;> assumption\n\nend TotalOrder\n", "meta": {"author": "crabbo-rave", "repo": "leandiscord-weekly", "sha": "e66366d9d6e896d0e86607bd1de791811d1c0043", "save_path": "github-repos/lean/crabbo-rave-leandiscord-weekly", "path": "github-repos/lean/crabbo-rave-leandiscord-weekly/leandiscord-weekly-e66366d9d6e896d0e86607bd1de791811d1c0043/Week 3/TotalOrder.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7353574086534729}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, S\u00e9bastien Gou\u00ebzel, Yury Kudryashov\n-/\nimport analysis.calculus.tangent_cone\nimport analysis.normed_space.units\nimport analysis.asymptotics.asymptotic_equivalent\nimport analysis.analytic.basic\n\n/-!\n# The Fr\u00e9chet derivative\n\nLet `E` and `F` be normed spaces, `f : E \u2192 F`, and `f' : E \u2192L[\ud835\udd5c] F` a\ncontinuous \ud835\udd5c-linear map, where `\ud835\udd5c` is a non-discrete normed field. Then\n\n  `has_fderiv_within_at f f' s x`\n\nsays that `f` has derivative `f'` at `x`, where the domain of interest\nis restricted to `s`. We also have\n\n  `has_fderiv_at f f' x := has_fderiv_within_at f f' x univ`\n\nFinally,\n\n  `has_strict_fderiv_at f f' x`\n\nmeans that `f : E \u2192 F` has derivative `f' : E \u2192L[\ud835\udd5c] F` in the sense of strict differentiability,\ni.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z \u2192 x`. This notion is used in the inverse\nfunction theorem, and is defined here only to avoid proving theorems like\n`is_bounded_bilinear_map.has_fderiv_at` twice: first for `has_fderiv_at`, then for\n`has_strict_fderiv_at`.\n\n## Main results\n\nIn addition to the definition and basic properties of the derivative, this file contains the\nusual formulas (and existence assertions) for the derivative of\n* constants\n* the identity\n* bounded linear maps\n* bounded bilinear maps\n* sum of two functions\n* sum of finitely many functions\n* multiplication of a function by a scalar constant\n* negative of a function\n* subtraction of two functions\n* multiplication of a function by a scalar function\n* multiplication of two scalar functions\n* composition of functions (the chain rule)\n* inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)\n\nFor most binary operations we also define `const_op` and `op_const` theorems for the cases when\nthe first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,\nand they more frequently lead to the desired result.\n\nOne can also interpret the derivative of a function `f : \ud835\udd5c \u2192 E` as an element of `E` (by identifying\na linear function from `\ud835\udd5c` to `E` with its value at `1`). Results on the Fr\u00e9chet derivative are\ntranslated to this more elementary point of view on the derivative in the file `deriv.lean`. The\nderivative of polynomials is handled there, as it is naturally one-dimensional.\n\nThe simplifier is set up to prove automatically that some functions are differentiable, or\ndifferentiable at a point (but not differentiable on a set or within a set at a point, as checking\nautomatically that the good domains are mapped one to the other when using composition is not\nsomething the simplifier can easily do). This means that one can write\n`example (x : \u211d) : differentiable \u211d (\u03bb x, sin (exp (3 + x^2)) - 5 * cos x) := by simp`.\nIf there are divisions, one needs to supply to the simplifier proofs that the denominators do\nnot vanish, as in\n```lean\nexample (x : \u211d) (h : 1 + sin x \u2260 0) : differentiable_at \u211d (\u03bb x, exp x / (1 + sin x)) x :=\nby simp [h]\n```\nOf course, these examples only work once `exp`, `cos` and `sin` have been shown to be\ndifferentiable, in `analysis.special_functions.trigonometric`.\n\nThe simplifier is not set up to compute the Fr\u00e9chet derivative of maps (as these are in general\ncomplicated multidimensional linear maps), but it will compute one-dimensional derivatives,\nsee `deriv.lean`.\n\n## Implementation details\n\nThe derivative is defined in terms of the `is_o` relation, but also\ncharacterized in terms of the `tendsto` relation.\n\nWe also introduce predicates `differentiable_within_at \ud835\udd5c f s x` (where `\ud835\udd5c` is the base field,\n`f` the function to be differentiated, `x` the point at which the derivative is asserted to exist,\nand `s` the set along which the derivative is defined), as well as `differentiable_at \ud835\udd5c f x`,\n`differentiable_on \ud835\udd5c f s` and `differentiable \ud835\udd5c f` to express the existence of a derivative.\n\nTo be able to compute with derivatives, we write `fderiv_within \ud835\udd5c f s x` and `fderiv \ud835\udd5c f x`\nfor some choice of a derivative if it exists, and the zero function otherwise. This choice only\nbehaves well along sets for which the derivative is unique, i.e., those for which the tangent\ndirections span a dense subset of the whole space. The predicates `unique_diff_within_at s x` and\n`unique_diff_on s`, defined in `tangent_cone.lean` express this property. We prove that indeed\nthey imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular\nfor `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very\nbeginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever.\n\nTo make sure that the simplifier can prove automatically that functions are differentiable, we tag\nmany lemmas with the `simp` attribute, for instance those saying that the sum of differentiable\nfunctions is differentiable, as well as their product, their cartesian product, and so on. A notable\nexception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are\ndifferentiable, then their composition also is: `simp` would always be able to match this lemma,\nby taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`),\nwe add a lemma that if `f` is differentiable then so is `(\u03bb x, exp (f x))`. This means adding\nsome boilerplate lemmas, but these can also be useful in their own right.\n\nTests for this ability of the simplifier (with more examples) are provided in\n`tests/differentiable.lean`.\n\n## Tags\n\nderivative, differentiable, Fr\u00e9chet, calculus\n\n-/\n\nopen filter asymptotics continuous_linear_map set metric\nopen_locale topological_space classical nnreal asymptotics filter ennreal\n\nnoncomputable theory\n\n\nsection\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\nvariables {E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\nvariables {F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\nvariables {G : Type*} [normed_group G] [normed_space \ud835\udd5c G]\nvariables {G' : Type*} [normed_group G'] [normed_space \ud835\udd5c G']\n\n/-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if\n`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition\nis designed to be specialized for `L = \ud835\udcdd x` (in `has_fderiv_at`), giving rise to the usual notion\nof Fr\u00e9chet derivative, and for `L = \ud835\udcdd[s] x` (in `has_fderiv_within_at`), giving rise to\nthe notion of Fr\u00e9chet derivative along the set `s`. -/\ndef has_fderiv_at_filter (f : E \u2192 F) (f' : E \u2192L[\ud835\udd5c] F) (x : E) (L : filter E) :=\nis_o (\u03bb x', f x' - f x - f' (x' - x)) (\u03bb x', x' - x) L\n\n/-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if\n`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/\ndef has_fderiv_within_at (f : E \u2192 F) (f' : E \u2192L[\ud835\udd5c] F) (s : set E) (x : E) :=\nhas_fderiv_at_filter f f' x (\ud835\udcdd[s] x)\n\n/-- A function `f` has the continuous linear map `f'` as derivative at `x` if\n`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/\ndef has_fderiv_at (f : E \u2192 F) (f' : E \u2192L[\ud835\udd5c] F) (x : E) :=\nhas_fderiv_at_filter f f' x (\ud835\udcdd x)\n\n/-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability*\nif `f x - f y - f' (x - y) = o(x - y)` as `x, y \u2192 a`. This form of differentiability is required,\ne.g., by the inverse function theorem. Any `C^1` function on a vector space over `\u211d` is strictly\ndifferentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/\ndef has_strict_fderiv_at (f : E \u2192 F) (f' : E \u2192L[\ud835\udd5c] F) (x : E) :=\nis_o (\u03bb p : E \u00d7 E, f p.1 - f p.2 - f' (p.1 - p.2)) (\u03bb p : E \u00d7 E, p.1 - p.2) (\ud835\udcdd (x, x))\n\nvariables (\ud835\udd5c)\n\n/-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative\nthere (possibly non-unique). -/\ndef differentiable_within_at (f : E \u2192 F) (s : set E) (x : E) :=\n\u2203f' : E \u2192L[\ud835\udd5c] F, has_fderiv_within_at f f' s x\n\n/-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly\nnon-unique). -/\ndef differentiable_at (f : E \u2192 F) (x : E) :=\n\u2203f' : E \u2192L[\ud835\udd5c] F, has_fderiv_at f f' x\n\n/-- If `f` has a derivative at `x` within `s`, then `fderiv_within \ud835\udd5c f s x` is such a derivative.\nOtherwise, it is set to `0`. -/\ndef fderiv_within (f : E \u2192 F) (s : set E) (x : E) : E \u2192L[\ud835\udd5c] F :=\nif h : \u2203f', has_fderiv_within_at f f' s x then classical.some h else 0\n\n/-- If `f` has a derivative at `x`, then `fderiv \ud835\udd5c f x` is such a derivative. Otherwise, it is\nset to `0`. -/\ndef fderiv (f : E \u2192 F) (x : E) : E \u2192L[\ud835\udd5c] F :=\nif h : \u2203f', has_fderiv_at f f' x then classical.some h else 0\n\n/-- `differentiable_on \ud835\udd5c f s` means that `f` is differentiable within `s` at any point of `s`. -/\ndef differentiable_on (f : E \u2192 F) (s : set E) :=\n\u2200x \u2208 s, differentiable_within_at \ud835\udd5c f s x\n\n/-- `differentiable \ud835\udd5c f` means that `f` is differentiable at any point. -/\ndef differentiable (f : E \u2192 F) :=\n\u2200x, differentiable_at \ud835\udd5c f x\n\nvariables {\ud835\udd5c}\nvariables {f f\u2080 f\u2081 g : E \u2192 F}\nvariables {f' f\u2080' f\u2081' g' : E \u2192L[\ud835\udd5c] F}\nvariables (e : E \u2192L[\ud835\udd5c] F)\nvariables {x : E}\nvariables {s t : set E}\nvariables {L L\u2081 L\u2082 : filter E}\n\nlemma fderiv_within_zero_of_not_differentiable_within_at\n  (h : \u00ac differentiable_within_at \ud835\udd5c f s x) : fderiv_within \ud835\udd5c f s x = 0 :=\nhave \u00ac \u2203 f', has_fderiv_within_at f f' s x, from h,\nby simp [fderiv_within, this]\n\nlemma fderiv_zero_of_not_differentiable_at (h : \u00ac differentiable_at \ud835\udd5c f x) : fderiv \ud835\udd5c f x = 0 :=\nhave \u00ac \u2203 f', has_fderiv_at f f' x, from h,\nby simp [fderiv, this]\n\nsection derivative_uniqueness\n/- In this section, we discuss the uniqueness of the derivative.\nWe prove that the definitions `unique_diff_within_at` and `unique_diff_on` indeed imply the\nuniqueness of the derivative. -/\n\n/-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f',\ni.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity\nand `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses\nthis fact, for functions having a derivative within a set. Its specific formulation is useful for\ntangent cone related discussions. -/\ntheorem has_fderiv_within_at.lim (h : has_fderiv_within_at f f' s x) {\u03b1 : Type*} (l : filter \u03b1)\n  {c : \u03b1 \u2192 \ud835\udd5c} {d : \u03b1 \u2192 E} {v : E} (dtop : \u2200\u1da0 n in l, x + d n \u2208 s)\n  (clim : tendsto (\u03bb n, \u2225c n\u2225) l at_top)\n  (cdlim : tendsto (\u03bb n, c n \u2022 d n) l (\ud835\udcdd v)) :\n  tendsto (\u03bbn, c n \u2022 (f (x + d n) - f x)) l (\ud835\udcdd (f' v)) :=\nbegin\n  have tendsto_arg : tendsto (\u03bb n, x + d n) l (\ud835\udcdd[s] x),\n  { conv in (\ud835\udcdd[s] x) { rw \u2190 add_zero x },\n    rw [nhds_within, tendsto_inf],\n    split,\n    { apply tendsto_const_nhds.add (tangent_cone_at.lim_zero l clim cdlim) },\n    { rwa tendsto_principal } },\n  have : is_o (\u03bb y, f y - f x - f' (y - x)) (\u03bb y, y - x) (\ud835\udcdd[s] x) := h,\n  have : is_o (\u03bb n, f (x + d n) - f x - f' ((x + d n) - x)) (\u03bb n, (x + d n)  - x) l :=\n    this.comp_tendsto tendsto_arg,\n  have : is_o (\u03bb n, f (x + d n) - f x - f' (d n)) d l := by simpa only [add_sub_cancel'],\n  have : is_o (\u03bbn, c n \u2022 (f (x + d n) - f x - f' (d n))) (\u03bbn, c n \u2022 d n) l :=\n    (is_O_refl c l).smul_is_o this,\n  have : is_o (\u03bbn, c n \u2022 (f (x + d n) - f x - f' (d n))) (\u03bbn, (1:\u211d)) l :=\n    this.trans_is_O (is_O_one_of_tendsto \u211d cdlim),\n  have L1 : tendsto (\u03bbn, c n \u2022 (f (x + d n) - f x - f' (d n))) l (\ud835\udcdd 0) :=\n    (is_o_one_iff \u211d).1 this,\n  have L2 : tendsto (\u03bbn, f' (c n \u2022 d n)) l (\ud835\udcdd (f' v)) :=\n    tendsto.comp f'.cont.continuous_at cdlim,\n  have L3 : tendsto (\u03bbn, (c n \u2022 (f (x + d n) - f x - f' (d n)) +  f' (c n \u2022 d n)))\n            l (\ud835\udcdd (0 + f' v)) :=\n    L1.add L2,\n  have : (\u03bbn, (c n \u2022 (f (x + d n) - f x - f' (d n)) +  f' (c n \u2022 d n)))\n          = (\u03bbn, c n \u2022 (f (x + d n) - f x)),\n    by { ext n, simp [smul_add, smul_sub] },\n  rwa [this, zero_add] at L3\nend\n\n/-- If `f'` and `f\u2081'` are two derivatives of `f` within `s` at `x`, then they are equal on the\ntangent cone to `s` at `x` -/\ntheorem has_fderiv_within_at.unique_on (hf : has_fderiv_within_at f f' s x)\n  (hg : has_fderiv_within_at f f\u2081' s x) :\n  eq_on f' f\u2081' (tangent_cone_at \ud835\udd5c s x) :=\n\u03bb y \u27e8c, d, dtop, clim, cdlim\u27e9,\n  tendsto_nhds_unique (hf.lim at_top dtop clim cdlim) (hg.lim at_top dtop clim cdlim)\n\n/-- `unique_diff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/\ntheorem unique_diff_within_at.eq (H : unique_diff_within_at \ud835\udd5c s x)\n  (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f\u2081' s x) : f' = f\u2081' :=\ncontinuous_linear_map.ext_on H.1 (hf.unique_on hg)\n\ntheorem unique_diff_on.eq (H : unique_diff_on \ud835\udd5c s) (hx : x \u2208 s)\n  (h : has_fderiv_within_at f f' s x) (h\u2081 : has_fderiv_within_at f f\u2081' s x) : f' = f\u2081' :=\n(H x hx).eq h h\u2081\n\nend derivative_uniqueness\n\nsection fderiv_properties\n/-! ### Basic properties of the derivative -/\n\ntheorem has_fderiv_at_filter_iff_tendsto :\n  has_fderiv_at_filter f f' x L \u2194\n  tendsto (\u03bb x', \u2225x' - x\u2225\u207b\u00b9 * \u2225f x' - f x - f' (x' - x)\u2225) L (\ud835\udcdd 0) :=\nhave h : \u2200 x', \u2225x' - x\u2225 = 0 \u2192 \u2225f x' - f x - f' (x' - x)\u2225 = 0, from \u03bb x' hx',\n  by { rw [sub_eq_zero.1 (norm_eq_zero.1 hx')], simp },\nbegin\n  unfold has_fderiv_at_filter,\n  rw [\u2190is_o_norm_left, \u2190is_o_norm_right, is_o_iff_tendsto h],\n  exact tendsto_congr (\u03bb _, div_eq_inv_mul),\nend\n\ntheorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x \u2194\n  tendsto (\u03bb x', \u2225x' - x\u2225\u207b\u00b9 * \u2225f x' - f x - f' (x' - x)\u2225) (\ud835\udcdd[s] x) (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x \u2194\n  tendsto (\u03bb x', \u2225x' - x\u2225\u207b\u00b9 * \u2225f x' - f x - f' (x' - x)\u2225) (\ud835\udcdd x) (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_fderiv_at_iff_is_o_nhds_zero : has_fderiv_at f f' x \u2194\n  is_o (\u03bbh, f (x + h) - f x - f' h) (\u03bbh, h) (\ud835\udcdd 0) :=\nbegin\n  rw [has_fderiv_at, has_fderiv_at_filter, \u2190 map_add_left_nhds_zero x, is_o_map],\n  simp [(\u2218)]\nend\n\n/-- Converse to the mean value inequality: if `f` is differentiable at `x\u2080` and `C`-lipschitz\non a neighborhood of `x\u2080` then it its derivative at `x\u2080` has norm bounded by `C`. -/\nlemma has_fderiv_at.le_of_lip {f : E \u2192 F} {f' : E \u2192L[\ud835\udd5c] F} {x\u2080 : E} (hf : has_fderiv_at f f' x\u2080)\n  {s : set E} (hs : s \u2208 \ud835\udcdd x\u2080) {C : \u211d\u22650} (hlip : lipschitz_on_with C f s) : \u2225f'\u2225 \u2264 C :=\nbegin\n  refine le_of_forall_pos_le_add (\u03bb \u03b5 \u03b50, op_norm_le_of_nhds_zero _ _),\n  exact add_nonneg C.coe_nonneg \u03b50.le,\n  have hs' := hs, rw [\u2190 map_add_left_nhds_zero x\u2080, mem_map] at hs',\n  filter_upwards [is_o_iff.1 (has_fderiv_at_iff_is_o_nhds_zero.1 hf) \u03b50, hs'], intros y hy hys,\n  have := hlip.norm_sub_le hys (mem_of_nhds hs), rw add_sub_cancel' at this,\n  calc \u2225f' y\u2225 \u2264 \u2225f (x\u2080 + y) - f x\u2080\u2225 + \u2225f (x\u2080 + y) - f x\u2080 - f' y\u2225 : norm_le_insert _ _\n          ... \u2264 C * \u2225y\u2225 + \u03b5 * \u2225y\u2225                                : add_le_add this hy\n          ... = (C + \u03b5) * \u2225y\u2225                                    : (add_mul _ _ _).symm\nend\n\ntheorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x L\u2082) (hst : L\u2081 \u2264 L\u2082) :\n  has_fderiv_at_filter f f' x L\u2081 :=\nh.mono hst\n\ntheorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s \u2286 t) :\n  has_fderiv_within_at f f' s x :=\nh.mono (nhds_within_mono _ hst)\n\ntheorem has_fderiv_at.has_fderiv_at_filter (h : has_fderiv_at f f' x) (hL : L \u2264 \ud835\udcdd x) :\n  has_fderiv_at_filter f f' x L :=\nh.mono hL\n\ntheorem has_fderiv_at.has_fderiv_within_at\n  (h : has_fderiv_at f f' x) : has_fderiv_within_at f f' s x :=\nh.has_fderiv_at_filter inf_le_left\n\nlemma has_fderiv_within_at.differentiable_within_at (h : has_fderiv_within_at f f' s x) :\n  differentiable_within_at \ud835\udd5c f s x :=\n\u27e8f', h\u27e9\n\nlemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at \ud835\udd5c f x :=\n\u27e8f', h\u27e9\n\n@[simp] lemma has_fderiv_within_at_univ :\n  has_fderiv_within_at f f' univ x \u2194 has_fderiv_at f f' x :=\nby { simp only [has_fderiv_within_at, nhds_within_univ], refl }\n\nlemma has_strict_fderiv_at.is_O_sub (hf : has_strict_fderiv_at f f' x) :\n  is_O (\u03bb p : E \u00d7 E, f p.1 - f p.2) (\u03bb p : E \u00d7 E, p.1 - p.2) (\ud835\udcdd (x, x)) :=\nhf.is_O.congr_of_sub.2 (f'.is_O_comp _ _)\n\nlemma has_fderiv_at_filter.is_O_sub (h : has_fderiv_at_filter f f' x L) :\n  is_O (\u03bb x', f x' - f x) (\u03bb x', x' - x) L :=\nh.is_O.congr_of_sub.2 (f'.is_O_sub _ _)\n\nprotected lemma has_strict_fderiv_at.has_fderiv_at (hf : has_strict_fderiv_at f f' x) :\n  has_fderiv_at f f' x :=\nbegin\n  rw [has_fderiv_at, has_fderiv_at_filter, is_o_iff],\n  exact (\u03bb c hc, tendsto_id.prod_mk_nhds tendsto_const_nhds (is_o_iff.1 hf hc))\nend\n\nprotected lemma has_strict_fderiv_at.differentiable_at (hf : has_strict_fderiv_at f f' x) :\n  differentiable_at \ud835\udd5c f x :=\nhf.has_fderiv_at.differentiable_at\n\n/-- Directional derivative agrees with `has_fderiv`. -/\nlemma has_fderiv_at.lim (hf : has_fderiv_at f f' x) (v : E) {\u03b1 : Type*} {c : \u03b1 \u2192 \ud835\udd5c}\n  {l : filter \u03b1} (hc : tendsto (\u03bb n, \u2225c n\u2225) l at_top) :\n  tendsto (\u03bb n, (c n) \u2022 (f (x + (c n)\u207b\u00b9 \u2022 v) - f x)) l (\ud835\udcdd (f' v)) :=\nbegin\n  refine (has_fderiv_within_at_univ.2 hf).lim _ (univ_mem_sets' (\u03bb _, trivial)) hc _,\n  assume U hU,\n  refine (eventually_ne_of_tendsto_norm_at_top hc (0:\ud835\udd5c)).mono (\u03bb y hy, _),\n  convert mem_of_nhds hU,\n  dsimp only,\n  rw [\u2190 mul_smul, mul_inv_cancel hy, one_smul]\nend\n\ntheorem has_fderiv_at.unique\n  (h\u2080 : has_fderiv_at f f\u2080' x) (h\u2081 : has_fderiv_at f f\u2081' x) : f\u2080' = f\u2081' :=\nbegin\n  rw \u2190 has_fderiv_within_at_univ at h\u2080 h\u2081,\n  exact unique_diff_within_at_univ.eq h\u2080 h\u2081\nend\n\nlemma has_fderiv_within_at_inter' (h : t \u2208 \ud835\udcdd[s] x) :\n  has_fderiv_within_at f f' (s \u2229 t) x \u2194 has_fderiv_within_at f f' s x :=\nby simp [has_fderiv_within_at, nhds_within_restrict'' s h]\n\nlemma has_fderiv_within_at_inter (h : t \u2208 \ud835\udcdd x) :\n  has_fderiv_within_at f f' (s \u2229 t) x \u2194 has_fderiv_within_at f f' s x :=\nby simp [has_fderiv_within_at, nhds_within_restrict' s h]\n\nlemma has_fderiv_within_at.union (hs : has_fderiv_within_at f f' s x)\n  (ht : has_fderiv_within_at f f' t x) :\n  has_fderiv_within_at f f' (s \u222a t) x :=\nbegin\n  simp only [has_fderiv_within_at, nhds_within_union],\n  exact hs.join ht,\nend\n\nlemma has_fderiv_within_at.nhds_within (h : has_fderiv_within_at f f' s x)\n  (ht : s \u2208 \ud835\udcdd[t] x) : has_fderiv_within_at f f' t x :=\n(has_fderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))\n\nlemma has_fderiv_within_at.has_fderiv_at (h : has_fderiv_within_at f f' s x) (hs : s \u2208 \ud835\udcdd x) :\n  has_fderiv_at f f' x :=\nby rwa [\u2190 univ_inter s, has_fderiv_within_at_inter hs, has_fderiv_within_at_univ] at h\n\nlemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at \ud835\udd5c f s x) :\n  has_fderiv_within_at f (fderiv_within \ud835\udd5c f s x) s x :=\nbegin\n  dunfold fderiv_within,\n  dunfold differentiable_within_at at h,\n  rw dif_pos h,\n  exact classical.some_spec h\nend\n\nlemma differentiable_at.has_fderiv_at (h : differentiable_at \ud835\udd5c f x) :\n  has_fderiv_at f (fderiv \ud835\udd5c f x) x :=\nbegin\n  dunfold fderiv,\n  dunfold differentiable_at at h,\n  rw dif_pos h,\n  exact classical.some_spec h\nend\n\nlemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv \ud835\udd5c f x = f' :=\nby { ext, rw h.unique h.differentiable_at.has_fderiv_at }\n\n/-- Converse to the mean value inequality: if `f` is differentiable at `x\u2080` and `C`-lipschitz\non a neighborhood of `x\u2080` then it its derivative at `x\u2080` has norm bounded by `C`.\nVersion using `fderiv`. -/\nlemma fderiv_at.le_of_lip {f : E \u2192 F} {x\u2080 : E} (hf : differentiable_at \ud835\udd5c f x\u2080)\n  {s : set E} (hs : s \u2208 \ud835\udcdd x\u2080) {C : \u211d\u22650} (hlip : lipschitz_on_with C f s) : \u2225fderiv \ud835\udd5c f x\u2080\u2225 \u2264 C :=\nhf.has_fderiv_at.le_of_lip hs hlip\n\nlemma has_fderiv_within_at.fderiv_within\n  (h : has_fderiv_within_at f f' s x) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c f s x = f' :=\n(hxs.eq h h.differentiable_within_at.has_fderiv_within_at).symm\n\n/-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`,\nas this statement is empty. -/\nlemma has_fderiv_within_at_of_not_mem_closure (h : x \u2209 closure s) :\n  has_fderiv_within_at f f' s x :=\nbegin\n  simp only [mem_closure_iff_nhds_within_ne_bot, ne_bot_iff, ne.def, not_not] at h,\n  simp [has_fderiv_within_at, has_fderiv_at_filter, h, is_o, is_O_with],\nend\n\nlemma differentiable_within_at.mono (h : differentiable_within_at \ud835\udd5c f t x) (st : s \u2286 t) :\n  differentiable_within_at \ud835\udd5c f s x :=\nbegin\n  rcases h with \u27e8f', hf'\u27e9,\n  exact \u27e8f', hf'.mono st\u27e9\nend\n\nlemma differentiable_within_at_univ :\n  differentiable_within_at \ud835\udd5c f univ x \u2194 differentiable_at \ud835\udd5c f x :=\nby simp only [differentiable_within_at, has_fderiv_within_at_univ, differentiable_at]\n\nlemma differentiable_within_at_inter (ht : t \u2208 \ud835\udcdd x) :\n  differentiable_within_at \ud835\udd5c f (s \u2229 t) x \u2194 differentiable_within_at \ud835\udd5c f s x :=\nby simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter,\n    nhds_within_restrict' s ht]\n\nlemma differentiable_within_at_inter' (ht : t \u2208 \ud835\udcdd[s] x) :\n  differentiable_within_at \ud835\udd5c f (s \u2229 t) x \u2194 differentiable_within_at \ud835\udd5c f s x :=\nby simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter,\n    nhds_within_restrict'' s ht]\n\nlemma differentiable_at.differentiable_within_at\n  (h : differentiable_at \ud835\udd5c f x) : differentiable_within_at \ud835\udd5c f s x :=\n(differentiable_within_at_univ.2 h).mono (subset_univ _)\n\nlemma differentiable.differentiable_at (h : differentiable \ud835\udd5c f) :\n  differentiable_at \ud835\udd5c f x :=\nh x\n\nlemma differentiable_within_at.differentiable_at\n  (h : differentiable_within_at \ud835\udd5c f s x) (hs : s \u2208 \ud835\udcdd x) : differentiable_at \ud835\udd5c f x :=\nh.imp (\u03bb f' hf', hf'.has_fderiv_at hs)\n\nlemma differentiable_at.fderiv_within\n  (h : differentiable_at \ud835\udd5c f x) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c f s x = fderiv \ud835\udd5c f x :=\nbegin\n  apply has_fderiv_within_at.fderiv_within _ hxs,\n  exact h.has_fderiv_at.has_fderiv_within_at\nend\n\nlemma differentiable_on.mono (h : differentiable_on \ud835\udd5c f t) (st : s \u2286 t) :\n  differentiable_on \ud835\udd5c f s :=\n\u03bbx hx, (h x (st hx)).mono st\n\nlemma differentiable_on_univ :\n  differentiable_on \ud835\udd5c f univ \u2194 differentiable \ud835\udd5c f :=\nby { simp [differentiable_on, differentiable_within_at_univ], refl }\n\nlemma differentiable.differentiable_on (h : differentiable \ud835\udd5c f) : differentiable_on \ud835\udd5c f s :=\n(differentiable_on_univ.2 h).mono (subset_univ _)\n\nlemma differentiable_on_of_locally_differentiable_on\n  (h : \u2200x\u2208s, \u2203u, is_open u \u2227 x \u2208 u \u2227 differentiable_on \ud835\udd5c f (s \u2229 u)) : differentiable_on \ud835\udd5c f s :=\nbegin\n  assume x xs,\n  rcases h x xs with \u27e8t, t_open, xt, ht\u27e9,\n  exact (differentiable_within_at_inter (mem_nhds_sets t_open xt)).1 (ht x \u27e8xs, xt\u27e9)\nend\n\nlemma fderiv_within_subset (st : s \u2286 t) (ht : unique_diff_within_at \ud835\udd5c s x)\n  (h : differentiable_within_at \ud835\udd5c f t x) :\n  fderiv_within \ud835\udd5c f s x = fderiv_within \ud835\udd5c f t x :=\n((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht\n\n@[simp] lemma fderiv_within_univ : fderiv_within \ud835\udd5c f univ = fderiv \ud835\udd5c f :=\nbegin\n  ext x : 1,\n  by_cases h : differentiable_at \ud835\udd5c f x,\n  { apply has_fderiv_within_at.fderiv_within _ unique_diff_within_at_univ,\n    rw has_fderiv_within_at_univ,\n    apply h.has_fderiv_at },\n  { have : \u00ac differentiable_within_at \ud835\udd5c f univ x,\n      by contrapose! h; rwa \u2190 differentiable_within_at_univ,\n    rw [fderiv_zero_of_not_differentiable_at h,\n        fderiv_within_zero_of_not_differentiable_within_at this] }\nend\n\nlemma fderiv_within_inter (ht : t \u2208 \ud835\udcdd x) (hs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c f (s \u2229 t) x = fderiv_within \ud835\udd5c f s x :=\nbegin\n  by_cases h : differentiable_within_at \ud835\udd5c f (s \u2229 t) x,\n  { apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h),\n    apply hs.inter ht },\n  { have : \u00ac differentiable_within_at \ud835\udd5c f s x,\n      by contrapose! h; rw differentiable_within_at_inter; assumption,\n    rw [fderiv_within_zero_of_not_differentiable_within_at h,\n        fderiv_within_zero_of_not_differentiable_within_at this] }\nend\n\nlemma fderiv_within_of_mem_nhds (h : s \u2208 \ud835\udcdd x) :\n  fderiv_within \ud835\udd5c f s x = fderiv \ud835\udd5c f x :=\nbegin\n  have : s = univ \u2229 s, by simp only [univ_inter],\n  rw [this, \u2190 fderiv_within_univ],\n  exact fderiv_within_inter h (unique_diff_on_univ _ (mem_univ _))\nend\n\nlemma fderiv_within_of_open (hs : is_open s) (hx : x \u2208 s) :\n  fderiv_within \ud835\udd5c f s x = fderiv \ud835\udd5c f x :=\nfderiv_within_of_mem_nhds (mem_nhds_sets hs hx)\n\nlemma fderiv_within_eq_fderiv (hs : unique_diff_within_at \ud835\udd5c s x) (h : differentiable_at \ud835\udd5c f x) :\n  fderiv_within \ud835\udd5c f s x = fderiv \ud835\udd5c f x :=\nbegin\n  rw \u2190 fderiv_within_univ,\n  exact fderiv_within_subset (subset_univ _) hs h.differentiable_within_at\nend\n\nlemma fderiv_mem_iff {f : E \u2192 F} {s : set (E \u2192L[\ud835\udd5c] F)} {x : E} :\n  fderiv \ud835\udd5c f x \u2208 s \u2194 (differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 s) \u2228\n    (0 : E \u2192L[\ud835\udd5c] F) \u2208 s \u2227 \u00acdifferentiable_at \ud835\udd5c f x :=\nbegin\n  split,\n  { intro hfx,\n    by_cases hx : differentiable_at \ud835\udd5c f x,\n    { exact or.inl \u27e8hx, hfx\u27e9 },\n    { rw [fderiv_zero_of_not_differentiable_at hx] at hfx,\n      exact or.inr \u27e8hfx, hx\u27e9 } },\n  { rintro (\u27e8hf, hf'\u27e9|\u27e8h\u2080, hx\u27e9),\n    { exact hf' },\n    { rwa [fderiv_zero_of_not_differentiable_at hx] } }\nend\n\nend fderiv_properties\n\nsection continuous\n/-! ### Deducing continuity from differentiability -/\n\ntheorem has_fderiv_at_filter.tendsto_nhds\n  (hL : L \u2264 \ud835\udcdd x) (h : has_fderiv_at_filter f f' x L) :\n  tendsto f L (\ud835\udcdd (f x)) :=\nbegin\n  have : tendsto (\u03bb x', f x' - f x) L (\ud835\udcdd 0),\n  { refine h.is_O_sub.trans_tendsto (tendsto.mono_left _ hL),\n    rw \u2190 sub_self x, exact tendsto_id.sub tendsto_const_nhds },\n  have := tendsto.add this tendsto_const_nhds,\n  rw zero_add (f x) at this,\n  exact this.congr (by simp)\nend\n\ntheorem has_fderiv_within_at.continuous_within_at\n  (h : has_fderiv_within_at f f' s x) : continuous_within_at f s x :=\nhas_fderiv_at_filter.tendsto_nhds inf_le_left h\n\ntheorem has_fderiv_at.continuous_at (h : has_fderiv_at f f' x) :\n  continuous_at f x :=\nhas_fderiv_at_filter.tendsto_nhds (le_refl _) h\n\nlemma differentiable_within_at.continuous_within_at (h : differentiable_within_at \ud835\udd5c f s x) :\n  continuous_within_at f s x :=\nlet \u27e8f', hf'\u27e9 := h in hf'.continuous_within_at\n\nlemma differentiable_at.continuous_at (h : differentiable_at \ud835\udd5c f x) : continuous_at f x :=\nlet \u27e8f', hf'\u27e9 := h in hf'.continuous_at\n\nlemma differentiable_on.continuous_on (h : differentiable_on \ud835\udd5c f s) : continuous_on f s :=\n\u03bbx hx, (h x hx).continuous_within_at\n\nlemma differentiable.continuous (h : differentiable \ud835\udd5c f) : continuous f :=\ncontinuous_iff_continuous_at.2 $ \u03bbx, (h x).continuous_at\n\nprotected lemma has_strict_fderiv_at.continuous_at (hf : has_strict_fderiv_at f f' x) :\n  continuous_at f x :=\nhf.has_fderiv_at.continuous_at\n\nlemma has_strict_fderiv_at.is_O_sub_rev {f' : E \u2243L[\ud835\udd5c] F}\n  (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) x) :\n  is_O (\u03bb p : E \u00d7 E, p.1 - p.2) (\u03bb p : E \u00d7 E, f p.1 - f p.2) (\ud835\udcdd (x, x)) :=\n((f'.is_O_comp_rev _ _).trans (hf.trans_is_O (f'.is_O_comp_rev _ _)).right_is_O_add).congr\n(\u03bb _, rfl) (\u03bb _, sub_add_cancel _ _)\n\nlemma has_fderiv_at_filter.is_O_sub_rev {f' : E \u2243L[\ud835\udd5c] F}\n  (hf : has_fderiv_at_filter f (f' : E \u2192L[\ud835\udd5c] F) x L) :\n  is_O (\u03bb x', x' - x) (\u03bb x', f x' - f x) L :=\n((f'.is_O_sub_rev _ _).trans (hf.trans_is_O (f'.is_O_sub_rev _ _)).right_is_O_add).congr\n(\u03bb _, rfl) (\u03bb _, sub_add_cancel _ _)\n\nend continuous\n\nsection congr\n/-! ### congr properties of the derivative -/\n\ntheorem filter.eventually_eq.has_strict_fderiv_at_iff\n  (h : f\u2080 =\u1da0[\ud835\udcdd x] f\u2081) (h' : \u2200 y, f\u2080' y = f\u2081' y) :\n  has_strict_fderiv_at f\u2080 f\u2080' x \u2194 has_strict_fderiv_at f\u2081 f\u2081' x :=\nbegin\n  refine is_o_congr ((h.prod_mk_nhds h).mono _) (eventually_of_forall $ \u03bb _, rfl),\n  rintros p \u27e8hp\u2081, hp\u2082\u27e9,\n  simp only [*]\nend\n\ntheorem has_strict_fderiv_at.congr_of_eventually_eq (h : has_strict_fderiv_at f f' x)\n  (h\u2081 : f =\u1da0[\ud835\udcdd x] f\u2081) : has_strict_fderiv_at f\u2081 f' x :=\n(h\u2081.has_strict_fderiv_at_iff (\u03bb _, rfl)).1 h\n\ntheorem filter.eventually_eq.has_fderiv_at_filter_iff\n  (h\u2080 : f\u2080 =\u1da0[L] f\u2081) (hx : f\u2080 x = f\u2081 x) (h\u2081 : \u2200 x, f\u2080' x = f\u2081' x) :\n  has_fderiv_at_filter f\u2080 f\u2080' x L \u2194 has_fderiv_at_filter f\u2081 f\u2081' x L :=\nis_o_congr (h\u2080.mono $ \u03bb y hy, by simp only [hy, h\u2081, hx]) (eventually_of_forall $ \u03bb _, rfl)\n\nlemma has_fderiv_at_filter.congr_of_eventually_eq (h : has_fderiv_at_filter f f' x L)\n  (hL : f\u2081 =\u1da0[L] f) (hx : f\u2081 x = f x) : has_fderiv_at_filter f\u2081 f' x L :=\n(hL.has_fderiv_at_filter_iff hx $ \u03bb _, rfl).2 h\n\nlemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : \u2200x \u2208 t, f\u2081 x = f x)\n  (hx : f\u2081 x = f x) (h\u2081 : t \u2286 s) : has_fderiv_within_at f\u2081 f' t x :=\nhas_fderiv_at_filter.congr_of_eventually_eq (h.mono h\u2081) (filter.mem_inf_sets_of_right ht) hx\n\nlemma has_fderiv_within_at.congr (h : has_fderiv_within_at f f' s x) (hs : \u2200x \u2208 s, f\u2081 x = f x)\n  (hx : f\u2081 x = f x) : has_fderiv_within_at f\u2081 f' s x :=\nh.congr_mono hs hx (subset.refl _)\n\nlemma has_fderiv_within_at.congr' (h : has_fderiv_within_at f f' s x) (hs : \u2200x \u2208 s, f\u2081 x = f x)\n  (hx : x \u2208 s) : has_fderiv_within_at f\u2081 f' s x :=\nh.congr hs (hs x hx)\n\nlemma has_fderiv_within_at.congr_of_eventually_eq (h : has_fderiv_within_at f f' s x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : f\u2081 x = f x) : has_fderiv_within_at f\u2081 f' s x :=\nhas_fderiv_at_filter.congr_of_eventually_eq h h\u2081 hx\n\nlemma has_fderiv_at.congr_of_eventually_eq (h : has_fderiv_at f f' x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd x] f) : has_fderiv_at f\u2081 f' x :=\nhas_fderiv_at_filter.congr_of_eventually_eq h h\u2081 (mem_of_nhds h\u2081 : _)\n\nlemma differentiable_within_at.congr_mono (h : differentiable_within_at \ud835\udd5c f s x)\n  (ht : \u2200x \u2208 t, f\u2081 x = f x) (hx : f\u2081 x = f x) (h\u2081 : t \u2286 s) : differentiable_within_at \ud835\udd5c f\u2081 t x :=\n(has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx h\u2081).differentiable_within_at\n\nlemma differentiable_within_at.congr (h : differentiable_within_at \ud835\udd5c f s x)\n  (ht : \u2200x \u2208 s, f\u2081 x = f x) (hx : f\u2081 x = f x) : differentiable_within_at \ud835\udd5c f\u2081 s x :=\ndifferentiable_within_at.congr_mono h ht hx (subset.refl _)\n\nlemma differentiable_within_at.congr_of_eventually_eq\n  (h : differentiable_within_at \ud835\udd5c f s x) (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f)\n  (hx : f\u2081 x = f x) : differentiable_within_at \ud835\udd5c f\u2081 s x :=\n(h.has_fderiv_within_at.congr_of_eventually_eq h\u2081 hx).differentiable_within_at\n\nlemma differentiable_on.congr_mono (h : differentiable_on \ud835\udd5c f s) (h' : \u2200x \u2208 t, f\u2081 x = f x)\n  (h\u2081 : t \u2286 s) : differentiable_on \ud835\udd5c f\u2081 t :=\n\u03bb x hx, (h x (h\u2081 hx)).congr_mono h' (h' x hx) h\u2081\n\nlemma differentiable_on.congr (h : differentiable_on \ud835\udd5c f s) (h' : \u2200x \u2208 s, f\u2081 x = f x) :\n  differentiable_on \ud835\udd5c f\u2081 s :=\n\u03bb x hx, (h x hx).congr h' (h' x hx)\n\nlemma differentiable_on_congr (h' : \u2200x \u2208 s, f\u2081 x = f x) :\n  differentiable_on \ud835\udd5c f\u2081 s \u2194 differentiable_on \ud835\udd5c f s :=\n\u27e8\u03bb h, differentiable_on.congr h (\u03bby hy, (h' y hy).symm),\n\u03bb h, differentiable_on.congr h h'\u27e9\n\nlemma differentiable_at.congr_of_eventually_eq (h : differentiable_at \ud835\udd5c f x) (hL : f\u2081 =\u1da0[\ud835\udcdd x] f) :\n  differentiable_at \ud835\udd5c f\u2081 x :=\nhas_fderiv_at.differentiable_at\n  (has_fderiv_at_filter.congr_of_eventually_eq h.has_fderiv_at hL (mem_of_nhds hL : _))\n\nlemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at \ud835\udd5c f s x)\n  (hs : \u2200x \u2208 t, f\u2081 x = f x) (hx : f\u2081 x = f x) (hxt : unique_diff_within_at \ud835\udd5c t x) (h\u2081 : t \u2286 s) :\n  fderiv_within \ud835\udd5c f\u2081 t x = fderiv_within \ud835\udd5c f s x :=\n(has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx h\u2081).fderiv_within hxt\n\nlemma filter.eventually_eq.fderiv_within_eq (hs : unique_diff_within_at \ud835\udd5c s x)\n  (hL : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : f\u2081 x = f x) :\n  fderiv_within \ud835\udd5c f\u2081 s x = fderiv_within \ud835\udd5c f s x :=\nif h : differentiable_within_at \ud835\udd5c f s x\nthen has_fderiv_within_at.fderiv_within (h.has_fderiv_within_at.congr_of_eventually_eq hL hx) hs\nelse\n  have h' : \u00ac differentiable_within_at \ud835\udd5c f\u2081 s x,\n  from mt (\u03bb h, h.congr_of_eventually_eq (hL.mono $ \u03bb x, eq.symm) hx.symm) h,\n  by rw [fderiv_within_zero_of_not_differentiable_within_at h,\n    fderiv_within_zero_of_not_differentiable_within_at h']\n\nlemma fderiv_within_congr (hs : unique_diff_within_at \ud835\udd5c s x)\n  (hL : \u2200y\u2208s, f\u2081 y = f y) (hx : f\u2081 x = f x) :\n  fderiv_within \ud835\udd5c f\u2081 s x = fderiv_within \ud835\udd5c f s x :=\nbegin\n  apply filter.eventually_eq.fderiv_within_eq hs _ hx,\n  apply mem_sets_of_superset self_mem_nhds_within,\n  exact hL\nend\n\nlemma filter.eventually_eq.fderiv_eq (hL : f\u2081 =\u1da0[\ud835\udcdd x] f) :\n  fderiv \ud835\udd5c f\u2081 x = fderiv \ud835\udd5c f x :=\nbegin\n  have A : f\u2081 x = f x := hL.eq_of_nhds,\n  rw [\u2190 fderiv_within_univ, \u2190 fderiv_within_univ],\n  rw \u2190 nhds_within_univ at hL,\n  exact hL.fderiv_within_eq unique_diff_within_at_univ A\nend\n\nend congr\n\nsection id\n/-! ### Derivative of the identity -/\n\ntheorem has_strict_fderiv_at_id (x : E) :\n  has_strict_fderiv_at id (id \ud835\udd5c E) x :=\n(is_o_zero _ _).congr_left $ by simp\n\ntheorem has_fderiv_at_filter_id (x : E) (L : filter E) :\n  has_fderiv_at_filter id (id \ud835\udd5c E) x L :=\n(is_o_zero _ _).congr_left $ by simp\n\ntheorem has_fderiv_within_at_id (x : E) (s : set E) :\n  has_fderiv_within_at id (id \ud835\udd5c E) s x :=\nhas_fderiv_at_filter_id _ _\n\ntheorem has_fderiv_at_id (x : E) : has_fderiv_at id (id \ud835\udd5c E) x :=\nhas_fderiv_at_filter_id _ _\n\n@[simp] lemma differentiable_at_id : differentiable_at \ud835\udd5c id x :=\n(has_fderiv_at_id x).differentiable_at\n\n@[simp] lemma differentiable_at_id' : differentiable_at \ud835\udd5c (\u03bb x, x) x :=\n(has_fderiv_at_id x).differentiable_at\n\nlemma differentiable_within_at_id : differentiable_within_at \ud835\udd5c id s x :=\ndifferentiable_at_id.differentiable_within_at\n\n@[simp] lemma differentiable_id : differentiable \ud835\udd5c (id : E \u2192 E) :=\n\u03bbx, differentiable_at_id\n\n@[simp] lemma differentiable_id' : differentiable \ud835\udd5c (\u03bb (x : E), x) :=\n\u03bbx, differentiable_at_id\n\nlemma differentiable_on_id : differentiable_on \ud835\udd5c id s :=\ndifferentiable_id.differentiable_on\n\nlemma fderiv_id : fderiv \ud835\udd5c id x = id \ud835\udd5c E :=\nhas_fderiv_at.fderiv (has_fderiv_at_id x)\n\n@[simp] lemma fderiv_id' : fderiv \ud835\udd5c (\u03bb (x : E), x) x = continuous_linear_map.id \ud835\udd5c E :=\nfderiv_id\n\nlemma fderiv_within_id (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c id s x = id \ud835\udd5c E :=\nbegin\n  rw differentiable_at.fderiv_within (differentiable_at_id) hxs,\n  exact fderiv_id\nend\n\nlemma fderiv_within_id' (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bb (x : E), x) s x = continuous_linear_map.id \ud835\udd5c E :=\nfderiv_within_id hxs\n\nend id\n\nsection const\n/-! ### derivative of a constant function -/\n\ntheorem has_strict_fderiv_at_const (c : F) (x : E) :\n  has_strict_fderiv_at (\u03bb _, c) (0 : E \u2192L[\ud835\udd5c] F) x :=\n(is_o_zero _ _).congr_left $ \u03bb _, by simp only [zero_apply, sub_self]\n\ntheorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) :\n  has_fderiv_at_filter (\u03bb x, c) (0 : E \u2192L[\ud835\udd5c] F) x L :=\n(is_o_zero _ _).congr_left $ \u03bb _, by simp only [zero_apply, sub_self]\n\ntheorem has_fderiv_within_at_const (c : F) (x : E) (s : set E) :\n  has_fderiv_within_at (\u03bb x, c) (0 : E \u2192L[\ud835\udd5c] F) s x :=\nhas_fderiv_at_filter_const _ _ _\n\ntheorem has_fderiv_at_const (c : F) (x : E) :\n  has_fderiv_at (\u03bb x, c) (0 : E \u2192L[\ud835\udd5c] F) x :=\nhas_fderiv_at_filter_const _ _ _\n\n@[simp] lemma differentiable_at_const (c : F) : differentiable_at \ud835\udd5c (\u03bbx, c) x :=\n\u27e80, has_fderiv_at_const c x\u27e9\n\nlemma differentiable_within_at_const (c : F) : differentiable_within_at \ud835\udd5c (\u03bbx, c) s x :=\ndifferentiable_at.differentiable_within_at (differentiable_at_const _)\n\nlemma fderiv_const_apply (c : F) : fderiv \ud835\udd5c (\u03bby, c) x = 0 :=\nhas_fderiv_at.fderiv (has_fderiv_at_const c x)\n\n@[simp] lemma fderiv_const (c : F) : fderiv \ud835\udd5c (\u03bb (y : E), c) = 0 :=\nby { ext m, rw fderiv_const_apply, refl }\n\nlemma fderiv_within_const_apply (c : F) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bby, c) s x = 0 :=\nbegin\n  rw differentiable_at.fderiv_within (differentiable_at_const _) hxs,\n  exact fderiv_const_apply _\nend\n\n@[simp] lemma differentiable_const (c : F) : differentiable \ud835\udd5c (\u03bbx : E, c) :=\n\u03bbx, differentiable_at_const _\n\nlemma differentiable_on_const (c : F) : differentiable_on \ud835\udd5c (\u03bbx, c) s :=\n(differentiable_const _).differentiable_on\n\nend const\n\nsection continuous_linear_map\n/-!\n### Continuous linear maps\n\nThere are currently two variants of these in mathlib, the bundled version\n(named `continuous_linear_map`, and denoted `E \u2192L[\ud835\udd5c] F`), and the unbundled version (with a\npredicate `is_bounded_linear_map`). We give statements for both versions. -/\n\nprotected theorem continuous_linear_map.has_strict_fderiv_at {x : E} :\n  has_strict_fderiv_at e e x :=\n(is_o_zero _ _).congr_left $ \u03bb x, by simp only [e.map_sub, sub_self]\n\nprotected lemma continuous_linear_map.has_fderiv_at_filter :\n  has_fderiv_at_filter e e x L :=\n(is_o_zero _ _).congr_left $ \u03bb x, by simp only [e.map_sub, sub_self]\n\nprotected lemma continuous_linear_map.has_fderiv_within_at : has_fderiv_within_at e e s x :=\ne.has_fderiv_at_filter\n\nprotected lemma continuous_linear_map.has_fderiv_at : has_fderiv_at e e x :=\ne.has_fderiv_at_filter\n\n@[simp] protected lemma continuous_linear_map.differentiable_at : differentiable_at \ud835\udd5c e x :=\ne.has_fderiv_at.differentiable_at\n\nprotected lemma continuous_linear_map.differentiable_within_at : differentiable_within_at \ud835\udd5c e s x :=\ne.differentiable_at.differentiable_within_at\n\n@[simp] protected lemma continuous_linear_map.fderiv : fderiv \ud835\udd5c e x = e :=\ne.has_fderiv_at.fderiv\n\nprotected lemma continuous_linear_map.fderiv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c e s x = e :=\nbegin\n  rw differentiable_at.fderiv_within e.differentiable_at hxs,\n  exact e.fderiv\nend\n\n@[simp] protected lemma continuous_linear_map.differentiable : differentiable \ud835\udd5c e :=\n\u03bbx, e.differentiable_at\n\nprotected lemma continuous_linear_map.differentiable_on : differentiable_on \ud835\udd5c e s :=\ne.differentiable.differentiable_on\n\nlemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map \ud835\udd5c f) :\n  has_fderiv_at_filter f h.to_continuous_linear_map x L :=\nh.to_continuous_linear_map.has_fderiv_at_filter\n\nlemma is_bounded_linear_map.has_fderiv_within_at (h : is_bounded_linear_map \ud835\udd5c f) :\n  has_fderiv_within_at f h.to_continuous_linear_map s x :=\nh.has_fderiv_at_filter\n\nlemma is_bounded_linear_map.has_fderiv_at (h : is_bounded_linear_map \ud835\udd5c f) :\n  has_fderiv_at f h.to_continuous_linear_map x  :=\nh.has_fderiv_at_filter\n\nlemma is_bounded_linear_map.differentiable_at (h : is_bounded_linear_map \ud835\udd5c f) :\n  differentiable_at \ud835\udd5c f x :=\nh.has_fderiv_at.differentiable_at\n\nlemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map \ud835\udd5c f) :\n  differentiable_within_at \ud835\udd5c f s x :=\nh.differentiable_at.differentiable_within_at\n\nlemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map \ud835\udd5c f) :\n  fderiv \ud835\udd5c f x = h.to_continuous_linear_map :=\nhas_fderiv_at.fderiv (h.has_fderiv_at)\n\nlemma is_bounded_linear_map.fderiv_within (h : is_bounded_linear_map \ud835\udd5c f)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) : fderiv_within \ud835\udd5c f s x = h.to_continuous_linear_map :=\nbegin\n  rw differentiable_at.fderiv_within h.differentiable_at hxs,\n  exact h.fderiv\nend\n\nlemma is_bounded_linear_map.differentiable (h : is_bounded_linear_map \ud835\udd5c f) :\n  differentiable \ud835\udd5c f :=\n\u03bbx, h.differentiable_at\n\nlemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map \ud835\udd5c f) :\n  differentiable_on \ud835\udd5c f s :=\nh.differentiable.differentiable_on\n\nend continuous_linear_map\n\nsection analytic\n\nvariables {p : formal_multilinear_series \ud835\udd5c E F} {r : \u211d\u22650\u221e}\n\nlemma has_fpower_series_at.has_strict_fderiv_at (h : has_fpower_series_at f p x) :\n  has_strict_fderiv_at f (continuous_multilinear_curry_fin1 \ud835\udd5c E F (p 1)) x :=\nbegin\n  refine h.is_O_image_sub_norm_mul_norm_sub.trans_is_o (is_o.of_norm_right _),\n  refine is_o_iff_exists_eq_mul.2 \u27e8\u03bb y, \u2225y - (x, x)\u2225, _, eventually_eq.rfl\u27e9,\n  refine (continuous_id.sub continuous_const).norm.tendsto' _ _ _,\n  rw [_root_.id, sub_self, norm_zero]\nend\n\nlemma has_fpower_series_at.has_fderiv_at (h : has_fpower_series_at f p x) :\n  has_fderiv_at f (continuous_multilinear_curry_fin1 \ud835\udd5c E F (p 1)) x :=\nh.has_strict_fderiv_at.has_fderiv_at\n\nlemma has_fpower_series_at.differentiable_at (h : has_fpower_series_at f p x) :\n  differentiable_at \ud835\udd5c f x :=\nh.has_fderiv_at.differentiable_at\n\nlemma analytic_at.differentiable_at : analytic_at \ud835\udd5c f x \u2192 differentiable_at \ud835\udd5c f x\n| \u27e8p, hp\u27e9 := hp.differentiable_at\n\nlemma analytic_at.differentiable_within_at (h : analytic_at \ud835\udd5c f x) :\n  differentiable_within_at \ud835\udd5c f s x :=\nh.differentiable_at.differentiable_within_at\n\nlemma has_fpower_series_at.fderiv (h : has_fpower_series_at f p x) :\n  fderiv \ud835\udd5c f x = continuous_multilinear_curry_fin1 \ud835\udd5c E F (p 1) :=\nh.has_fderiv_at.fderiv\n\nlemma has_fpower_series_on_ball.differentiable_on [complete_space F]\n  (h : has_fpower_series_on_ball f p x r) :\n  differentiable_on \ud835\udd5c f (emetric.ball x r) :=\n\u03bb y hy, (h.analytic_at_of_mem hy).differentiable_within_at\n\nend analytic\n\nsection composition\n/-!\n### Derivative of the composition of two functions\n\nFor composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to\nget confused since there are too many possibilities for composition -/\n\nvariable (x)\n\ntheorem has_fderiv_at_filter.comp {g : F \u2192 G} {g' : F \u2192L[\ud835\udd5c] G}\n  (hg : has_fderiv_at_filter g g' (f x) (L.map f))\n  (hf : has_fderiv_at_filter f f' x L) :\n  has_fderiv_at_filter (g \u2218 f) (g'.comp f') x L :=\nlet eq\u2081 := (g'.is_O_comp _ _).trans_is_o hf in\nlet eq\u2082 := (hg.comp_tendsto tendsto_map).trans_is_O hf.is_O_sub in\nby { refine eq\u2082.triangle (eq\u2081.congr_left (\u03bb x', _)), simp }\n\n/- A readable version of the previous theorem,\n   a general form of the chain rule. -/\n\nexample {g : F \u2192 G} {g' : F \u2192L[\ud835\udd5c] G}\n  (hg : has_fderiv_at_filter g g' (f x) (L.map f))\n  (hf : has_fderiv_at_filter f f' x L) :\n  has_fderiv_at_filter (g \u2218 f) (g'.comp f') x L :=\nbegin\n  unfold has_fderiv_at_filter at hg,\n  have : is_o (\u03bb x', g (f x') - g (f x) - g' (f x' - f x)) (\u03bb x', f x' - f x) L,\n    from hg.comp_tendsto (le_refl _),\n  have eq\u2081 : is_o (\u03bb x', g (f x') - g (f x) - g' (f x' - f x)) (\u03bb x', x' - x) L,\n    from this.trans_is_O hf.is_O_sub,\n  have eq\u2082 : is_o (\u03bb x', f x' - f x - f' (x' - x)) (\u03bb x', x' - x) L,\n    from hf,\n  have : is_O\n    (\u03bb x', g' (f x' - f x - f' (x' - x))) (\u03bb x', f x' - f x - f' (x' - x)) L,\n    from g'.is_O_comp _ _,\n  have : is_o (\u03bb x', g' (f x' - f x - f' (x' - x))) (\u03bb x', x' - x) L,\n    from this.trans_is_o eq\u2082,\n  have eq\u2083 : is_o (\u03bb x', g' (f x' - f x) - (g' (f' (x' - x)))) (\u03bb x', x' - x) L,\n    by { refine this.congr_left _, simp},\n  exact eq\u2081.triangle eq\u2083\nend\n\ntheorem has_fderiv_within_at.comp {g : F \u2192 G} {g' : F \u2192L[\ud835\udd5c] G} {t : set F}\n  (hg : has_fderiv_within_at g g' t (f x)) (hf : has_fderiv_within_at f f' s x)\n  (hst : s \u2286 f \u207b\u00b9' t) :\n  has_fderiv_within_at (g \u2218 f) (g'.comp f') s x :=\nbegin\n  apply has_fderiv_at_filter.comp _ (has_fderiv_at_filter.mono hg _) hf,\n  calc map f (\ud835\udcdd[s] x)\n      \u2264 \ud835\udcdd[f '' s] (f x) : hf.continuous_within_at.tendsto_nhds_within_image\n  ... \u2264 \ud835\udcdd[t] (f x)        : nhds_within_mono _ (image_subset_iff.mpr hst)\nend\n\n/-- The chain rule. -/\ntheorem has_fderiv_at.comp {g : F \u2192 G} {g' : F \u2192L[\ud835\udd5c] G}\n  (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (g \u2218 f) (g'.comp f') x :=\n(hg.mono hf.continuous_at).comp x hf\n\ntheorem has_fderiv_at.comp_has_fderiv_within_at {g : F \u2192 G} {g' : F \u2192L[\ud835\udd5c] G}\n  (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (g \u2218 f) (g'.comp f') s x :=\nbegin\n  rw \u2190 has_fderiv_within_at_univ at hg,\n  exact has_fderiv_within_at.comp x hg hf subset_preimage_univ\nend\n\nlemma differentiable_within_at.comp {g : F \u2192 G} {t : set F}\n  (hg : differentiable_within_at \ud835\udd5c g t (f x)) (hf : differentiable_within_at \ud835\udd5c f s x)\n  (h : s \u2286 f \u207b\u00b9' t) : differentiable_within_at \ud835\udd5c (g \u2218 f) s x :=\nbegin\n  rcases hf with \u27e8f', hf'\u27e9,\n  rcases hg with \u27e8g', hg'\u27e9,\n  exact \u27e8continuous_linear_map.comp g' f', hg'.comp x hf' h\u27e9\nend\n\nlemma differentiable_within_at.comp' {g : F \u2192 G} {t : set F}\n  (hg : differentiable_within_at \ud835\udd5c g t (f x)) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  differentiable_within_at \ud835\udd5c (g \u2218 f) (s \u2229 f\u207b\u00b9' t) x :=\nhg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)\n\nlemma differentiable_at.comp {g : F \u2192 G}\n  (hg : differentiable_at \ud835\udd5c g (f x)) (hf : differentiable_at \ud835\udd5c f x) :\n  differentiable_at \ud835\udd5c (g \u2218 f) x :=\n(hg.has_fderiv_at.comp x hf.has_fderiv_at).differentiable_at\n\nlemma differentiable_at.comp_differentiable_within_at {g : F \u2192 G}\n  (hg : differentiable_at \ud835\udd5c g (f x)) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  differentiable_within_at \ud835\udd5c (g \u2218 f) s x :=\n(differentiable_within_at_univ.2 hg).comp x hf (by simp)\n\nlemma fderiv_within.comp {g : F \u2192 G} {t : set F}\n  (hg : differentiable_within_at \ud835\udd5c g t (f x)) (hf : differentiable_within_at \ud835\udd5c f s x)\n  (h : maps_to f s t) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (g \u2218 f) s x = (fderiv_within \ud835\udd5c g t (f x)).comp (fderiv_within \ud835\udd5c f s x) :=\nbegin\n  apply has_fderiv_within_at.fderiv_within _ hxs,\n  exact has_fderiv_within_at.comp x (hg.has_fderiv_within_at) (hf.has_fderiv_within_at) h\nend\n\nlemma fderiv.comp {g : F \u2192 G}\n  (hg : differentiable_at \ud835\udd5c g (f x)) (hf : differentiable_at \ud835\udd5c f x) :\n  fderiv \ud835\udd5c (g \u2218 f) x = (fderiv \ud835\udd5c g (f x)).comp (fderiv \ud835\udd5c f x) :=\nbegin\n  apply has_fderiv_at.fderiv,\n  exact has_fderiv_at.comp x hg.has_fderiv_at hf.has_fderiv_at\nend\n\nlemma fderiv.comp_fderiv_within {g : F \u2192 G}\n  (hg : differentiable_at \ud835\udd5c g (f x)) (hf : differentiable_within_at \ud835\udd5c f s x)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (g \u2218 f) s x = (fderiv \ud835\udd5c g (f x)).comp (fderiv_within \ud835\udd5c f s x) :=\nbegin\n  apply has_fderiv_within_at.fderiv_within _ hxs,\n  exact has_fderiv_at.comp_has_fderiv_within_at x (hg.has_fderiv_at) (hf.has_fderiv_within_at)\nend\n\nlemma differentiable_on.comp {g : F \u2192 G} {t : set F}\n  (hg : differentiable_on \ud835\udd5c g t) (hf : differentiable_on \ud835\udd5c f s) (st : s \u2286 f \u207b\u00b9' t) :\n  differentiable_on \ud835\udd5c (g \u2218 f) s :=\n\u03bbx hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st\n\nlemma differentiable.comp {g : F \u2192 G} (hg : differentiable \ud835\udd5c g) (hf : differentiable \ud835\udd5c f) :\n  differentiable \ud835\udd5c (g \u2218 f) :=\n\u03bbx, differentiable_at.comp x (hg (f x)) (hf x)\n\nlemma differentiable.comp_differentiable_on {g : F \u2192 G} (hg : differentiable \ud835\udd5c g)\n  (hf : differentiable_on \ud835\udd5c f s) :\n  differentiable_on \ud835\udd5c (g \u2218 f) s :=\n(differentiable_on_univ.2 hg).comp hf (by simp)\n\n/-- The chain rule for derivatives in the sense of strict differentiability. -/\nprotected lemma has_strict_fderiv_at.comp {g : F \u2192 G} {g' : F \u2192L[\ud835\udd5c] G}\n  (hg : has_strict_fderiv_at g g' (f x)) (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, g (f x)) (g'.comp f') x :=\n((hg.comp_tendsto (hf.continuous_at.prod_map' hf.continuous_at)).trans_is_O hf.is_O_sub).triangle $\n  by simpa only [g'.map_sub, f'.coe_comp'] using (g'.is_O_comp _ _).trans_is_o hf\n\nprotected lemma differentiable.iterate {f : E \u2192 E} (hf : differentiable \ud835\udd5c f) (n : \u2115) :\n  differentiable \ud835\udd5c (f^[n]) :=\nnat.rec_on n differentiable_id (\u03bb n ihn, ihn.comp hf)\n\nprotected lemma differentiable_on.iterate {f : E \u2192 E} (hf : differentiable_on \ud835\udd5c f s)\n  (hs : maps_to f s s) (n : \u2115) :\n  differentiable_on \ud835\udd5c (f^[n]) s :=\nnat.rec_on n differentiable_on_id (\u03bb n ihn, ihn.comp hf hs)\n\nvariable {x}\n\nprotected lemma has_fderiv_at_filter.iterate {f : E \u2192 E} {f' : E \u2192L[\ud835\udd5c] E}\n  (hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : \u2115) :\n  has_fderiv_at_filter (f^[n]) (f'^n) x L :=\nbegin\n  induction n with n ihn,\n  { exact has_fderiv_at_filter_id x L },\n  { change has_fderiv_at_filter (f^[n] \u2218 f) (f'^(n+1)) x L,\n    rw [pow_succ'],\n    refine has_fderiv_at_filter.comp x _ hf,\n    rw hx,\n    exact ihn.mono hL }\nend\n\nprotected lemma has_fderiv_at.iterate {f : E \u2192 E} {f' : E \u2192L[\ud835\udd5c] E}\n  (hf : has_fderiv_at f f' x) (hx : f x = x) (n : \u2115) :\n  has_fderiv_at (f^[n]) (f'^n) x :=\nbegin\n  refine hf.iterate _ hx n,\n  convert hf.continuous_at,\n  exact hx.symm\nend\n\nprotected lemma has_fderiv_within_at.iterate {f : E \u2192 E} {f' : E \u2192L[\ud835\udd5c] E}\n  (hf : has_fderiv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : \u2115) :\n  has_fderiv_within_at (f^[n]) (f'^n) s x :=\nbegin\n  refine hf.iterate _ hx n,\n  convert tendsto_inf.2 \u27e8hf.continuous_within_at, _\u27e9,\n  exacts [hx.symm, (tendsto_principal_principal.2 hs).mono_left inf_le_right]\nend\n\nprotected lemma has_strict_fderiv_at.iterate {f : E \u2192 E} {f' : E \u2192L[\ud835\udd5c] E}\n  (hf : has_strict_fderiv_at f f' x) (hx : f x = x) (n : \u2115) :\n  has_strict_fderiv_at (f^[n]) (f'^n) x :=\nbegin\n  induction n with n ihn,\n  { exact has_strict_fderiv_at_id x },\n  { change has_strict_fderiv_at (f^[n] \u2218 f) (f'^(n+1)) x,\n    rw [pow_succ'],\n    refine has_strict_fderiv_at.comp x _ hf,\n    rwa hx }\nend\n\nprotected lemma differentiable_at.iterate {f : E \u2192 E} (hf : differentiable_at \ud835\udd5c f x)\n  (hx : f x = x) (n : \u2115) :\n  differentiable_at \ud835\udd5c (f^[n]) x :=\nexists.elim hf $ \u03bb f' hf, (hf.iterate hx n).differentiable_at\n\nprotected lemma differentiable_within_at.iterate {f : E \u2192 E} (hf : differentiable_within_at \ud835\udd5c f s x)\n  (hx : f x = x) (hs : maps_to f s s) (n : \u2115) :\n  differentiable_within_at \ud835\udd5c (f^[n]) s x :=\nexists.elim hf $ \u03bb f' hf, (hf.iterate hx hs n).differentiable_within_at\n\nend composition\n\nsection cartesian_product\n/-! ### Derivative of the cartesian product of two functions -/\n\nsection prod\nvariables {f\u2082 : E \u2192 G} {f\u2082' : E \u2192L[\ud835\udd5c] G}\n\nprotected lemma has_strict_fderiv_at.prod\n  (hf\u2081 : has_strict_fderiv_at f\u2081 f\u2081' x) (hf\u2082 : has_strict_fderiv_at f\u2082 f\u2082' x) :\n  has_strict_fderiv_at (\u03bbx, (f\u2081 x, f\u2082 x)) (f\u2081'.prod f\u2082') x :=\nhf\u2081.prod_left hf\u2082\n\nlemma has_fderiv_at_filter.prod\n  (hf\u2081 : has_fderiv_at_filter f\u2081 f\u2081' x L) (hf\u2082 : has_fderiv_at_filter f\u2082 f\u2082' x L) :\n  has_fderiv_at_filter (\u03bbx, (f\u2081 x, f\u2082 x)) (f\u2081'.prod f\u2082') x L :=\nhf\u2081.prod_left hf\u2082\n\nlemma has_fderiv_within_at.prod\n  (hf\u2081 : has_fderiv_within_at f\u2081 f\u2081' s x) (hf\u2082 : has_fderiv_within_at f\u2082 f\u2082' s x) :\n  has_fderiv_within_at (\u03bbx, (f\u2081 x, f\u2082 x)) (f\u2081'.prod f\u2082') s x :=\nhf\u2081.prod hf\u2082\n\nlemma has_fderiv_at.prod (hf\u2081 : has_fderiv_at f\u2081 f\u2081' x) (hf\u2082 : has_fderiv_at f\u2082 f\u2082' x) :\n  has_fderiv_at (\u03bbx, (f\u2081 x, f\u2082 x)) (continuous_linear_map.prod f\u2081' f\u2082') x :=\nhf\u2081.prod hf\u2082\n\nlemma differentiable_within_at.prod\n  (hf\u2081 : differentiable_within_at \ud835\udd5c f\u2081 s x) (hf\u2082 : differentiable_within_at \ud835\udd5c f\u2082 s x) :\n  differentiable_within_at \ud835\udd5c (\u03bbx:E, (f\u2081 x, f\u2082 x)) s x :=\n(hf\u2081.has_fderiv_within_at.prod hf\u2082.has_fderiv_within_at).differentiable_within_at\n\n@[simp]\nlemma differentiable_at.prod (hf\u2081 : differentiable_at \ud835\udd5c f\u2081 x) (hf\u2082 : differentiable_at \ud835\udd5c f\u2082 x) :\n  differentiable_at \ud835\udd5c (\u03bbx:E, (f\u2081 x, f\u2082 x)) x :=\n(hf\u2081.has_fderiv_at.prod hf\u2082.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.prod (hf\u2081 : differentiable_on \ud835\udd5c f\u2081 s) (hf\u2082 : differentiable_on \ud835\udd5c f\u2082 s) :\n  differentiable_on \ud835\udd5c (\u03bbx:E, (f\u2081 x, f\u2082 x)) s :=\n\u03bbx hx, differentiable_within_at.prod (hf\u2081 x hx) (hf\u2082 x hx)\n\n@[simp]\nlemma differentiable.prod (hf\u2081 : differentiable \ud835\udd5c f\u2081) (hf\u2082 : differentiable \ud835\udd5c f\u2082) :\n  differentiable \ud835\udd5c (\u03bbx:E, (f\u2081 x, f\u2082 x)) :=\n\u03bb x, differentiable_at.prod (hf\u2081 x) (hf\u2082 x)\n\nlemma differentiable_at.fderiv_prod\n  (hf\u2081 : differentiable_at \ud835\udd5c f\u2081 x) (hf\u2082 : differentiable_at \ud835\udd5c f\u2082 x) :\n  fderiv \ud835\udd5c (\u03bbx:E, (f\u2081 x, f\u2082 x)) x = (fderiv \ud835\udd5c f\u2081 x).prod (fderiv \ud835\udd5c f\u2082 x) :=\n(hf\u2081.has_fderiv_at.prod hf\u2082.has_fderiv_at).fderiv\n\nlemma differentiable_at.fderiv_within_prod\n  (hf\u2081 : differentiable_within_at \ud835\udd5c f\u2081 s x) (hf\u2082 : differentiable_within_at \ud835\udd5c f\u2082 s x)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bbx:E, (f\u2081 x, f\u2082 x)) s x =\n    (fderiv_within \ud835\udd5c f\u2081 s x).prod (fderiv_within \ud835\udd5c f\u2082 s x) :=\nbegin\n  apply has_fderiv_within_at.fderiv_within _ hxs,\n  exact has_fderiv_within_at.prod hf\u2081.has_fderiv_within_at hf\u2082.has_fderiv_within_at\nend\n\nend prod\n\nsection fst\n\nvariables {f\u2082 : E \u2192 F \u00d7 G} {f\u2082' : E \u2192L[\ud835\udd5c] F \u00d7 G} {p : E \u00d7 F}\n\nlemma has_strict_fderiv_at_fst : has_strict_fderiv_at (fst \ud835\udd5c E F) (fst \ud835\udd5c E F) p :=\n(fst \ud835\udd5c E F).has_strict_fderiv_at\n\nprotected lemma has_strict_fderiv_at.fst (h : has_strict_fderiv_at f\u2082 f\u2082' x) :\n  has_strict_fderiv_at (\u03bb x, (f\u2082 x).1) ((fst \ud835\udd5c F G).comp f\u2082') x :=\nhas_strict_fderiv_at_fst.comp x h\n\nlemma has_fderiv_at_filter_fst {L : filter (E \u00d7 F)} :\n  has_fderiv_at_filter (fst \ud835\udd5c E F) (fst \ud835\udd5c E F) p L :=\n(fst \ud835\udd5c E F).has_fderiv_at_filter\n\nprotected lemma has_fderiv_at_filter.fst (h : has_fderiv_at_filter f\u2082 f\u2082' x L) :\n  has_fderiv_at_filter (\u03bb x, (f\u2082 x).1) ((fst \ud835\udd5c F G).comp f\u2082') x L :=\nhas_fderiv_at_filter_fst.comp x h\n\nlemma has_fderiv_at_fst : has_fderiv_at (fst \ud835\udd5c E F) (fst \ud835\udd5c E F) p :=\nhas_fderiv_at_filter_fst\n\nprotected lemma has_fderiv_at.fst (h : has_fderiv_at f\u2082 f\u2082' x) :\n  has_fderiv_at (\u03bb x, (f\u2082 x).1) ((fst \ud835\udd5c F G).comp f\u2082') x :=\nh.fst\n\nlemma has_fderiv_within_at_fst {s : set (E \u00d7 F)} :\n  has_fderiv_within_at (fst \ud835\udd5c E F) (fst \ud835\udd5c E F) s p :=\nhas_fderiv_at_filter_fst\n\nprotected lemma has_fderiv_within_at.fst (h : has_fderiv_within_at f\u2082 f\u2082' s x) :\n  has_fderiv_within_at (\u03bb x, (f\u2082 x).1) ((fst \ud835\udd5c F G).comp f\u2082') s x :=\nh.fst\n\nlemma differentiable_at_fst : differentiable_at \ud835\udd5c prod.fst p :=\nhas_fderiv_at_fst.differentiable_at\n\n@[simp] protected lemma differentiable_at.fst (h : differentiable_at \ud835\udd5c f\u2082 x) :\n  differentiable_at \ud835\udd5c (\u03bb x, (f\u2082 x).1) x :=\ndifferentiable_at_fst.comp x h\n\nlemma differentiable_fst : differentiable \ud835\udd5c (prod.fst : E \u00d7 F \u2192 E) :=\n\u03bb x, differentiable_at_fst\n\n@[simp] protected lemma differentiable.fst (h : differentiable \ud835\udd5c f\u2082) :\n  differentiable \ud835\udd5c (\u03bb x, (f\u2082 x).1) :=\ndifferentiable_fst.comp h\n\nlemma differentiable_within_at_fst {s : set (E \u00d7 F)} : differentiable_within_at \ud835\udd5c prod.fst s p :=\ndifferentiable_at_fst.differentiable_within_at\n\nprotected lemma differentiable_within_at.fst (h : differentiable_within_at \ud835\udd5c f\u2082 s x) :\n  differentiable_within_at \ud835\udd5c (\u03bb x, (f\u2082 x).1) s x :=\ndifferentiable_at_fst.comp_differentiable_within_at x h\n\nlemma differentiable_on_fst {s : set (E \u00d7 F)} : differentiable_on \ud835\udd5c prod.fst s :=\ndifferentiable_fst.differentiable_on\n\nprotected lemma differentiable_on.fst (h : differentiable_on \ud835\udd5c f\u2082 s) :\n  differentiable_on \ud835\udd5c (\u03bb x, (f\u2082 x).1) s :=\ndifferentiable_fst.comp_differentiable_on h\n\nlemma fderiv_fst : fderiv \ud835\udd5c prod.fst p = fst \ud835\udd5c E F := has_fderiv_at_fst.fderiv\n\nlemma fderiv.fst (h : differentiable_at \ud835\udd5c f\u2082 x) :\n  fderiv \ud835\udd5c (\u03bb x, (f\u2082 x).1) x = (fst \ud835\udd5c F G).comp (fderiv \ud835\udd5c f\u2082 x) :=\nh.has_fderiv_at.fst.fderiv\n\nlemma fderiv_within_fst {s : set (E \u00d7 F)} (hs : unique_diff_within_at \ud835\udd5c s p) :\n  fderiv_within \ud835\udd5c prod.fst s p = fst \ud835\udd5c E F :=\nhas_fderiv_within_at_fst.fderiv_within hs\n\nlemma fderiv_within.fst (hs : unique_diff_within_at \ud835\udd5c s x) (h : differentiable_within_at \ud835\udd5c f\u2082 s x) :\n  fderiv_within \ud835\udd5c (\u03bb x, (f\u2082 x).1) s x = (fst \ud835\udd5c F G).comp (fderiv_within \ud835\udd5c f\u2082 s x) :=\nh.has_fderiv_within_at.fst.fderiv_within hs\n\nend fst\n\nsection snd\n\nvariables {f\u2082 : E \u2192 F \u00d7 G} {f\u2082' : E \u2192L[\ud835\udd5c] F \u00d7 G} {p : E \u00d7 F}\n\nlemma has_strict_fderiv_at_snd : has_strict_fderiv_at (snd \ud835\udd5c E F) (snd \ud835\udd5c E F) p :=\n(snd \ud835\udd5c E F).has_strict_fderiv_at\n\nprotected lemma has_strict_fderiv_at.snd (h : has_strict_fderiv_at f\u2082 f\u2082' x) :\n  has_strict_fderiv_at (\u03bb x, (f\u2082 x).2) ((snd \ud835\udd5c F G).comp f\u2082') x :=\nhas_strict_fderiv_at_snd.comp x h\n\nlemma has_fderiv_at_filter_snd {L : filter (E \u00d7 F)} :\n  has_fderiv_at_filter (snd \ud835\udd5c E F) (snd \ud835\udd5c E F) p L :=\n(snd \ud835\udd5c E F).has_fderiv_at_filter\n\nprotected lemma has_fderiv_at_filter.snd (h : has_fderiv_at_filter f\u2082 f\u2082' x L) :\n  has_fderiv_at_filter (\u03bb x, (f\u2082 x).2) ((snd \ud835\udd5c F G).comp f\u2082') x L :=\nhas_fderiv_at_filter_snd.comp x h\n\nlemma has_fderiv_at_snd : has_fderiv_at (snd \ud835\udd5c E F) (snd \ud835\udd5c E F) p :=\nhas_fderiv_at_filter_snd\n\nprotected lemma has_fderiv_at.snd (h : has_fderiv_at f\u2082 f\u2082' x) :\n  has_fderiv_at (\u03bb x, (f\u2082 x).2) ((snd \ud835\udd5c F G).comp f\u2082') x :=\nh.snd\n\nlemma has_fderiv_within_at_snd {s : set (E \u00d7 F)} :\n  has_fderiv_within_at (snd \ud835\udd5c E F) (snd \ud835\udd5c E F) s p :=\nhas_fderiv_at_filter_snd\n\nprotected lemma has_fderiv_within_at.snd (h : has_fderiv_within_at f\u2082 f\u2082' s x) :\n  has_fderiv_within_at (\u03bb x, (f\u2082 x).2) ((snd \ud835\udd5c F G).comp f\u2082') s x :=\nh.snd\n\nlemma differentiable_at_snd : differentiable_at \ud835\udd5c prod.snd p :=\nhas_fderiv_at_snd.differentiable_at\n\n@[simp] protected lemma differentiable_at.snd (h : differentiable_at \ud835\udd5c f\u2082 x) :\n  differentiable_at \ud835\udd5c (\u03bb x, (f\u2082 x).2) x :=\ndifferentiable_at_snd.comp x h\n\nlemma differentiable_snd : differentiable \ud835\udd5c (prod.snd : E \u00d7 F \u2192 F) :=\n\u03bb x, differentiable_at_snd\n\n@[simp] protected lemma differentiable.snd (h : differentiable \ud835\udd5c f\u2082) :\n  differentiable \ud835\udd5c (\u03bb x, (f\u2082 x).2) :=\ndifferentiable_snd.comp h\n\nlemma differentiable_within_at_snd {s : set (E \u00d7 F)} : differentiable_within_at \ud835\udd5c prod.snd s p :=\ndifferentiable_at_snd.differentiable_within_at\n\nprotected lemma differentiable_within_at.snd (h : differentiable_within_at \ud835\udd5c f\u2082 s x) :\n  differentiable_within_at \ud835\udd5c (\u03bb x, (f\u2082 x).2) s x :=\ndifferentiable_at_snd.comp_differentiable_within_at x h\n\nlemma differentiable_on_snd {s : set (E \u00d7 F)} : differentiable_on \ud835\udd5c prod.snd s :=\ndifferentiable_snd.differentiable_on\n\nprotected lemma differentiable_on.snd (h : differentiable_on \ud835\udd5c f\u2082 s) :\n  differentiable_on \ud835\udd5c (\u03bb x, (f\u2082 x).2) s :=\ndifferentiable_snd.comp_differentiable_on h\n\nlemma fderiv_snd : fderiv \ud835\udd5c prod.snd p = snd \ud835\udd5c E F := has_fderiv_at_snd.fderiv\n\nlemma fderiv.snd (h : differentiable_at \ud835\udd5c f\u2082 x) :\n  fderiv \ud835\udd5c (\u03bb x, (f\u2082 x).2) x = (snd \ud835\udd5c F G).comp (fderiv \ud835\udd5c f\u2082 x) :=\nh.has_fderiv_at.snd.fderiv\n\nlemma fderiv_within_snd {s : set (E \u00d7 F)} (hs : unique_diff_within_at \ud835\udd5c s p) :\n  fderiv_within \ud835\udd5c prod.snd s p = snd \ud835\udd5c E F :=\nhas_fderiv_within_at_snd.fderiv_within hs\n\nlemma fderiv_within.snd (hs : unique_diff_within_at \ud835\udd5c s x) (h : differentiable_within_at \ud835\udd5c f\u2082 s x) :\n  fderiv_within \ud835\udd5c (\u03bb x, (f\u2082 x).2) s x = (snd \ud835\udd5c F G).comp (fderiv_within \ud835\udd5c f\u2082 s x) :=\nh.has_fderiv_within_at.snd.fderiv_within hs\n\nend snd\n\nsection prod_map\n\nvariables {f\u2082 : G \u2192 G'} {f\u2082' : G \u2192L[\ud835\udd5c] G'} {y : G} (p : E \u00d7 G)\n\n-- TODO (Lean 3.8): use `prod.map f f\u2082``\n\nprotected theorem has_strict_fderiv_at.prod_map (hf : has_strict_fderiv_at f f' p.1)\n  (hf\u2082 : has_strict_fderiv_at f\u2082 f\u2082' p.2) :\n  has_strict_fderiv_at (\u03bb p : E \u00d7 G, (f p.1, f\u2082 p.2)) (f'.prod_map f\u2082') p :=\n(hf.comp p has_strict_fderiv_at_fst).prod (hf\u2082.comp p has_strict_fderiv_at_snd)\n\nprotected theorem has_fderiv_at.prod_map (hf : has_fderiv_at f f' p.1)\n  (hf\u2082 : has_fderiv_at f\u2082 f\u2082' p.2) :\n  has_fderiv_at (\u03bb p : E \u00d7 G, (f p.1, f\u2082 p.2)) (f'.prod_map f\u2082') p :=\n(hf.comp p has_fderiv_at_fst).prod (hf\u2082.comp p has_fderiv_at_snd)\n\n@[simp] protected theorem differentiable_at.prod_map (hf : differentiable_at \ud835\udd5c f p.1)\n  (hf\u2082 : differentiable_at \ud835\udd5c f\u2082 p.2) :\n  differentiable_at \ud835\udd5c (\u03bb p : E \u00d7 G, (f p.1, f\u2082 p.2)) p :=\n(hf.comp p differentiable_at_fst).prod (hf\u2082.comp p differentiable_at_snd)\n\nend prod_map\n\nend cartesian_product\n\nsection const_smul\n/-! ### Derivative of a function multiplied by a constant -/\n\ntheorem has_strict_fderiv_at.const_smul (h : has_strict_fderiv_at f f' x) (c : \ud835\udd5c) :\n  has_strict_fderiv_at (\u03bb x, c \u2022 f x) (c \u2022 f') x :=\n(c \u2022 (1 : F \u2192L[\ud835\udd5c] F)).has_strict_fderiv_at.comp x h\n\ntheorem has_fderiv_at_filter.const_smul (h : has_fderiv_at_filter f f' x L) (c : \ud835\udd5c) :\n  has_fderiv_at_filter (\u03bb x, c \u2022 f x) (c \u2022 f') x L :=\n(c \u2022 (1 : F \u2192L[\ud835\udd5c] F)).has_fderiv_at_filter.comp x h\n\ntheorem has_fderiv_within_at.const_smul (h : has_fderiv_within_at f f' s x) (c : \ud835\udd5c) :\n  has_fderiv_within_at (\u03bb x, c \u2022 f x) (c \u2022 f') s x :=\nh.const_smul c\n\ntheorem has_fderiv_at.const_smul (h : has_fderiv_at f f' x) (c : \ud835\udd5c) :\n  has_fderiv_at (\u03bb x, c \u2022 f x) (c \u2022 f') x :=\nh.const_smul c\n\nlemma differentiable_within_at.const_smul (h : differentiable_within_at \ud835\udd5c f s x) (c : \ud835\udd5c) :\n  differentiable_within_at \ud835\udd5c (\u03bby, c \u2022 f y) s x :=\n(h.has_fderiv_within_at.const_smul c).differentiable_within_at\n\nlemma differentiable_at.const_smul (h : differentiable_at \ud835\udd5c f x) (c : \ud835\udd5c) :\n  differentiable_at \ud835\udd5c (\u03bby, c \u2022 f y) x :=\n(h.has_fderiv_at.const_smul c).differentiable_at\n\nlemma differentiable_on.const_smul (h : differentiable_on \ud835\udd5c f s) (c : \ud835\udd5c) :\n  differentiable_on \ud835\udd5c (\u03bby, c \u2022 f y) s :=\n\u03bbx hx, (h x hx).const_smul c\n\nlemma differentiable.const_smul (h : differentiable \ud835\udd5c f) (c : \ud835\udd5c) :\n  differentiable \ud835\udd5c (\u03bby, c \u2022 f y) :=\n\u03bbx, (h x).const_smul c\n\nlemma fderiv_within_const_smul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (h : differentiable_within_at \ud835\udd5c f s x) (c : \ud835\udd5c) :\n  fderiv_within \ud835\udd5c (\u03bby, c \u2022 f y) s x = c \u2022 fderiv_within \ud835\udd5c f s x :=\n(h.has_fderiv_within_at.const_smul c).fderiv_within hxs\n\nlemma fderiv_const_smul (h : differentiable_at \ud835\udd5c f x) (c : \ud835\udd5c) :\n  fderiv \ud835\udd5c (\u03bby, c \u2022 f y) x = c \u2022 fderiv \ud835\udd5c f x :=\n(h.has_fderiv_at.const_smul c).fderiv\n\nend const_smul\n\nsection add\n/-! ### Derivative of the sum of two functions -/\n\ntheorem has_strict_fderiv_at.add (hf : has_strict_fderiv_at f f' x)\n  (hg : has_strict_fderiv_at g g' x) :\n  has_strict_fderiv_at (\u03bb y, f y + g y) (f' + g') x :=\n(hf.add hg).congr_left $ \u03bb y, by simp; abel\n\ntheorem has_fderiv_at_filter.add\n  (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) :\n  has_fderiv_at_filter (\u03bb y, f y + g y) (f' + g') x L :=\n(hf.add hg).congr_left $ \u03bb _, by simp; abel\n\ntheorem has_fderiv_within_at.add\n  (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) :\n  has_fderiv_within_at (\u03bb y, f y + g y) (f' + g') s x :=\nhf.add hg\n\ntheorem has_fderiv_at.add\n  (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :\n  has_fderiv_at (\u03bb x, f x + g x) (f' + g') x :=\nhf.add hg\n\nlemma differentiable_within_at.add\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, f y + g y) s x :=\n(hf.has_fderiv_within_at.add hg.has_fderiv_within_at).differentiable_within_at\n\n@[simp] lemma differentiable_at.add\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  differentiable_at \ud835\udd5c (\u03bb y, f y + g y) x :=\n(hf.has_fderiv_at.add hg.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.add\n  (hf : differentiable_on \ud835\udd5c f s) (hg : differentiable_on \ud835\udd5c g s) :\n  differentiable_on \ud835\udd5c (\u03bby, f y + g y) s :=\n\u03bbx hx, (hf x hx).add (hg x hx)\n\n@[simp] lemma differentiable.add\n  (hf : differentiable \ud835\udd5c f) (hg : differentiable \ud835\udd5c g) :\n  differentiable \ud835\udd5c (\u03bby, f y + g y) :=\n\u03bbx, (hf x).add (hg x)\n\nlemma fderiv_within_add (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  fderiv_within \ud835\udd5c (\u03bby, f y + g y) s x = fderiv_within \ud835\udd5c f s x + fderiv_within \ud835\udd5c g s x :=\n(hf.has_fderiv_within_at.add hg.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_add\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  fderiv \ud835\udd5c (\u03bby, f y + g y) x = fderiv \ud835\udd5c f x + fderiv \ud835\udd5c g x :=\n(hf.has_fderiv_at.add hg.has_fderiv_at).fderiv\n\ntheorem has_strict_fderiv_at.add_const (hf : has_strict_fderiv_at f f' x) (c : F) :\n  has_strict_fderiv_at (\u03bb y, f y + c) f' x :=\nadd_zero f' \u25b8 hf.add (has_strict_fderiv_at_const _ _)\n\ntheorem has_fderiv_at_filter.add_const\n  (hf : has_fderiv_at_filter f f' x L) (c : F) :\n  has_fderiv_at_filter (\u03bb y, f y + c) f' x L :=\nadd_zero f' \u25b8 hf.add (has_fderiv_at_filter_const _ _ _)\n\ntheorem has_fderiv_within_at.add_const\n  (hf : has_fderiv_within_at f f' s x) (c : F) :\n  has_fderiv_within_at (\u03bb y, f y + c) f' s x :=\nhf.add_const c\n\ntheorem has_fderiv_at.add_const (hf : has_fderiv_at f f' x) (c : F):\n  has_fderiv_at (\u03bb x, f x + c) f' x :=\nhf.add_const c\n\nlemma differentiable_within_at.add_const\n  (hf : differentiable_within_at \ud835\udd5c f s x) (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, f y + c) s x :=\n(hf.has_fderiv_within_at.add_const c).differentiable_within_at\n\n@[simp] lemma differentiable_within_at_add_const_iff (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, f y + c) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\n\u27e8\u03bb h, by simpa using h.add_const (-c), \u03bb h, h.add_const c\u27e9\n\nlemma differentiable_at.add_const\n  (hf : differentiable_at \ud835\udd5c f x) (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, f y + c) x :=\n(hf.has_fderiv_at.add_const c).differentiable_at\n\n@[simp] lemma differentiable_at_add_const_iff (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, f y + c) x \u2194 differentiable_at \ud835\udd5c f x :=\n\u27e8\u03bb h, by simpa using h.add_const (-c), \u03bb h, h.add_const c\u27e9\n\nlemma differentiable_on.add_const\n  (hf : differentiable_on \ud835\udd5c f s) (c : F) :\n  differentiable_on \ud835\udd5c (\u03bby, f y + c) s :=\n\u03bbx hx, (hf x hx).add_const c\n\n@[simp] lemma differentiable_on_add_const_iff (c : F) :\n  differentiable_on \ud835\udd5c (\u03bb y, f y + c) s \u2194 differentiable_on \ud835\udd5c f s :=\n\u27e8\u03bb h, by simpa using h.add_const (-c), \u03bb h, h.add_const c\u27e9\n\nlemma differentiable.add_const\n  (hf : differentiable \ud835\udd5c f) (c : F) :\n  differentiable \ud835\udd5c (\u03bby, f y + c) :=\n\u03bbx, (hf x).add_const c\n\n@[simp] lemma differentiable_add_const_iff (c : F) :\n  differentiable \ud835\udd5c (\u03bb y, f y + c) \u2194 differentiable \ud835\udd5c f :=\n\u27e8\u03bb h, by simpa using h.add_const (-c), \u03bb h, h.add_const c\u27e9\n\nlemma fderiv_within_add_const (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  fderiv_within \ud835\udd5c (\u03bby, f y + c) s x = fderiv_within \ud835\udd5c f s x :=\nif hf : differentiable_within_at \ud835\udd5c f s x\nthen (hf.has_fderiv_within_at.add_const c).fderiv_within hxs\nelse by { rw [fderiv_within_zero_of_not_differentiable_within_at hf,\n  fderiv_within_zero_of_not_differentiable_within_at], simpa }\n\nlemma fderiv_add_const (c : F) : fderiv \ud835\udd5c (\u03bby, f y + c) x = fderiv \ud835\udd5c f x :=\nby simp only [\u2190 fderiv_within_univ, fderiv_within_add_const unique_diff_within_at_univ]\n\ntheorem has_strict_fderiv_at.const_add (hf : has_strict_fderiv_at f f' x) (c : F) :\n  has_strict_fderiv_at (\u03bb y, c + f y) f' x :=\nzero_add f' \u25b8 (has_strict_fderiv_at_const _ _).add hf\n\ntheorem has_fderiv_at_filter.const_add\n  (hf : has_fderiv_at_filter f f' x L) (c : F) :\n  has_fderiv_at_filter (\u03bb y, c + f y) f' x L :=\nzero_add f' \u25b8 (has_fderiv_at_filter_const _ _ _).add hf\n\ntheorem has_fderiv_within_at.const_add\n  (hf : has_fderiv_within_at f f' s x) (c : F) :\n  has_fderiv_within_at (\u03bb y, c + f y) f' s x :=\nhf.const_add c\n\ntheorem has_fderiv_at.const_add\n  (hf : has_fderiv_at f f' x) (c : F):\n  has_fderiv_at (\u03bb x, c + f x) f' x :=\nhf.const_add c\n\nlemma differentiable_within_at.const_add\n  (hf : differentiable_within_at \ud835\udd5c f s x) (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c + f y) s x :=\n(hf.has_fderiv_within_at.const_add c).differentiable_within_at\n\n@[simp] lemma differentiable_within_at_const_add_iff (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c + f y) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\n\u27e8\u03bb h, by simpa using h.const_add (-c), \u03bb h, h.const_add c\u27e9\n\nlemma differentiable_at.const_add\n  (hf : differentiable_at \ud835\udd5c f x) (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, c + f y) x :=\n(hf.has_fderiv_at.const_add c).differentiable_at\n\n@[simp] lemma differentiable_at_const_add_iff (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, c + f y) x \u2194 differentiable_at \ud835\udd5c f x :=\n\u27e8\u03bb h, by simpa using h.const_add (-c), \u03bb h, h.const_add c\u27e9\n\nlemma differentiable_on.const_add (hf : differentiable_on \ud835\udd5c f s) (c : F) :\n  differentiable_on \ud835\udd5c (\u03bby, c + f y) s :=\n\u03bbx hx, (hf x hx).const_add c\n\n@[simp] lemma differentiable_on_const_add_iff (c : F) :\n  differentiable_on \ud835\udd5c (\u03bb y, c + f y) s \u2194 differentiable_on \ud835\udd5c f s :=\n\u27e8\u03bb h, by simpa using h.const_add (-c), \u03bb h, h.const_add c\u27e9\n\nlemma differentiable.const_add (hf : differentiable \ud835\udd5c f) (c : F) :\n  differentiable \ud835\udd5c (\u03bby, c + f y) :=\n\u03bbx, (hf x).const_add c\n\n@[simp] lemma differentiable_const_add_iff (c : F) :\n  differentiable \ud835\udd5c (\u03bb y, c + f y) \u2194 differentiable \ud835\udd5c f :=\n\u27e8\u03bb h, by simpa using h.const_add (-c), \u03bb h, h.const_add c\u27e9\n\nlemma fderiv_within_const_add (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  fderiv_within \ud835\udd5c (\u03bby, c + f y) s x = fderiv_within \ud835\udd5c f s x :=\nby simpa only [add_comm] using fderiv_within_add_const hxs c\n\nlemma fderiv_const_add (c : F) : fderiv \ud835\udd5c (\u03bby, c + f y) x = fderiv \ud835\udd5c f x :=\nby simp only [add_comm c, fderiv_add_const]\n\nend add\n\nsection sum\n/-! ### Derivative of a finite sum of functions -/\n\nopen_locale big_operators\n\nvariables {\u03b9 : Type*} {u : finset \u03b9} {A : \u03b9 \u2192 (E \u2192 F)} {A' : \u03b9 \u2192 (E \u2192L[\ud835\udd5c] F)}\n\ntheorem has_strict_fderiv_at.sum (h : \u2200 i \u2208 u, has_strict_fderiv_at (A i) (A' i) x) :\n  has_strict_fderiv_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x :=\nbegin\n  dsimp [has_strict_fderiv_at] at *,\n  convert is_o.sum h,\n  simp [finset.sum_sub_distrib, continuous_linear_map.sum_apply]\nend\n\ntheorem has_fderiv_at_filter.sum (h : \u2200 i \u2208 u, has_fderiv_at_filter (A i) (A' i) x L) :\n  has_fderiv_at_filter (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x L :=\nbegin\n  dsimp [has_fderiv_at_filter] at *,\n  convert is_o.sum h,\n  simp [continuous_linear_map.sum_apply]\nend\n\ntheorem has_fderiv_within_at.sum (h : \u2200 i \u2208 u, has_fderiv_within_at (A i) (A' i) s x) :\n  has_fderiv_within_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) s x :=\nhas_fderiv_at_filter.sum h\n\ntheorem has_fderiv_at.sum (h : \u2200 i \u2208 u, has_fderiv_at (A i) (A' i) x) :\n  has_fderiv_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x :=\nhas_fderiv_at_filter.sum h\n\ntheorem differentiable_within_at.sum (h : \u2200 i \u2208 u, differentiable_within_at \ud835\udd5c (A i) s x) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, \u2211 i in u, A i y) s x :=\nhas_fderiv_within_at.differentiable_within_at $ has_fderiv_within_at.sum $\n\u03bb i hi, (h i hi).has_fderiv_within_at\n\n@[simp] theorem differentiable_at.sum (h : \u2200 i \u2208 u, differentiable_at \ud835\udd5c (A i) x) :\n  differentiable_at \ud835\udd5c (\u03bb y, \u2211 i in u, A i y) x :=\nhas_fderiv_at.differentiable_at $ has_fderiv_at.sum $ \u03bb i hi, (h i hi).has_fderiv_at\n\ntheorem differentiable_on.sum (h : \u2200 i \u2208 u, differentiable_on \ud835\udd5c (A i) s) :\n  differentiable_on \ud835\udd5c (\u03bb y, \u2211 i in u, A i y) s :=\n\u03bb x hx, differentiable_within_at.sum $ \u03bb i hi, h i hi x hx\n\n@[simp] theorem differentiable.sum (h : \u2200 i \u2208 u, differentiable \ud835\udd5c (A i)) :\n  differentiable \ud835\udd5c (\u03bb y, \u2211 i in u, A i y) :=\n\u03bb x, differentiable_at.sum $ \u03bb i hi, h i hi x\n\ntheorem fderiv_within_sum (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (h : \u2200 i \u2208 u, differentiable_within_at \ud835\udd5c (A i) s x) :\n  fderiv_within \ud835\udd5c (\u03bb y, \u2211 i in u, A i y) s x = (\u2211 i in u, fderiv_within \ud835\udd5c (A i) s x) :=\n(has_fderiv_within_at.sum (\u03bb i hi, (h i hi).has_fderiv_within_at)).fderiv_within hxs\n\ntheorem fderiv_sum (h : \u2200 i \u2208 u, differentiable_at \ud835\udd5c (A i) x) :\n  fderiv \ud835\udd5c (\u03bb y, \u2211 i in u, A i y) x = (\u2211 i in u, fderiv \ud835\udd5c (A i) x) :=\n(has_fderiv_at.sum (\u03bb i hi, (h i hi).has_fderiv_at)).fderiv\n\nend sum\n\nsection pi\n\n/-!\n### Derivatives of functions `f : E \u2192 \u03a0 i, F' i`\n\nIn this section we formulate `has_*fderiv*_pi` theorems as `iff`s, and provide two versions of each\ntheorem:\n\n* the version without `'` deals with `\u03c6 : \u03a0 i, E \u2192 F' i` and `\u03c6' : \u03a0 i, E \u2192L[\ud835\udd5c] F' i`\n  and is designed to deduce differentiability of `\u03bb x i, \u03c6 i x` from differentiability\n  of each `\u03c6 i`;\n* the version with `'` deals with `\u03a6 : E \u2192 \u03a0 i, F' i` and `\u03a6' : E \u2192L[\ud835\udd5c] \u03a0 i, F' i`\n  and is designed to deduce differentiability of the components `\u03bb x, \u03a6 x i` from\n  differentiability of `\u03a6`.\n-/\n\nvariables {\u03b9 : Type*} [fintype \u03b9] {F' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (F' i)]\n  [\u03a0 i, normed_space \ud835\udd5c (F' i)] {\u03c6 : \u03a0 i, E \u2192 F' i} {\u03c6' : \u03a0 i, E \u2192L[\ud835\udd5c] F' i}\n  {\u03a6 : E \u2192 \u03a0 i, F' i} {\u03a6' : E \u2192L[\ud835\udd5c] \u03a0 i, F' i}\n\n@[simp] lemma has_strict_fderiv_at_pi' :\n  has_strict_fderiv_at \u03a6 \u03a6' x \u2194\n    \u2200 i, has_strict_fderiv_at (\u03bb x, \u03a6 x i) ((proj i).comp \u03a6') x :=\nbegin\n  simp only [has_strict_fderiv_at, continuous_linear_map.coe_pi],\n  exact is_o_pi\nend\n\n@[simp] lemma has_strict_fderiv_at_pi :\n  has_strict_fderiv_at (\u03bb x i, \u03c6 i x) (continuous_linear_map.pi \u03c6') x \u2194\n    \u2200 i, has_strict_fderiv_at (\u03c6 i) (\u03c6' i) x :=\nhas_strict_fderiv_at_pi'\n\n@[simp] lemma has_fderiv_at_filter_pi' :\n  has_fderiv_at_filter \u03a6 \u03a6' x L \u2194\n    \u2200 i, has_fderiv_at_filter (\u03bb x, \u03a6 x i) ((proj i).comp \u03a6') x L :=\nbegin\n  simp only [has_fderiv_at_filter, continuous_linear_map.coe_pi],\n  exact is_o_pi\nend\n\nlemma has_fderiv_at_filter_pi :\n  has_fderiv_at_filter (\u03bb x i, \u03c6 i x) (continuous_linear_map.pi \u03c6') x L \u2194\n    \u2200 i, has_fderiv_at_filter (\u03c6 i) (\u03c6' i) x L :=\nhas_fderiv_at_filter_pi'\n\n@[simp] lemma has_fderiv_at_pi' :\n  has_fderiv_at \u03a6 \u03a6' x \u2194\n    \u2200 i, has_fderiv_at (\u03bb x, \u03a6 x i) ((proj i).comp \u03a6') x :=\nhas_fderiv_at_filter_pi'\n\nlemma has_fderiv_at_pi :\n  has_fderiv_at (\u03bb x i, \u03c6 i x) (continuous_linear_map.pi \u03c6') x \u2194\n    \u2200 i, has_fderiv_at (\u03c6 i) (\u03c6' i) x :=\nhas_fderiv_at_filter_pi\n\n@[simp] lemma has_fderiv_within_at_pi' :\n  has_fderiv_within_at \u03a6 \u03a6' s x \u2194\n    \u2200 i, has_fderiv_within_at (\u03bb x, \u03a6 x i) ((proj i).comp \u03a6') s x :=\nhas_fderiv_at_filter_pi'\n\nlemma has_fderiv_within_at_pi :\n  has_fderiv_within_at (\u03bb x i, \u03c6 i x) (continuous_linear_map.pi \u03c6') s x \u2194\n    \u2200 i, has_fderiv_within_at (\u03c6 i) (\u03c6' i) s x :=\nhas_fderiv_at_filter_pi\n\n@[simp] lemma differentiable_within_at_pi :\n  differentiable_within_at \ud835\udd5c \u03a6 s x \u2194\n   \u2200 i, differentiable_within_at \ud835\udd5c (\u03bb x, \u03a6 x i) s x :=\n\u27e8\u03bb h i, (has_fderiv_within_at_pi'.1 h.has_fderiv_within_at i).differentiable_within_at,\n  \u03bb h, (has_fderiv_within_at_pi.2 (\u03bb i, (h i).has_fderiv_within_at)).differentiable_within_at\u27e9\n\n@[simp] lemma differentiable_at_pi :\n  differentiable_at \ud835\udd5c \u03a6 x \u2194 \u2200 i, differentiable_at \ud835\udd5c (\u03bb x, \u03a6 x i) x :=\n\u27e8\u03bb h i, (has_fderiv_at_pi'.1 h.has_fderiv_at i).differentiable_at,\n  \u03bb h, (has_fderiv_at_pi.2 (\u03bb i, (h i).has_fderiv_at)).differentiable_at\u27e9\n\nlemma differentiable_on_pi :\n  differentiable_on \ud835\udd5c \u03a6 s \u2194 \u2200 i, differentiable_on \ud835\udd5c (\u03bb x, \u03a6 x i) s :=\n\u27e8\u03bb h i x hx, differentiable_within_at_pi.1 (h x hx) i,\n  \u03bb h x hx, differentiable_within_at_pi.2 (\u03bb i, h i x hx)\u27e9\n\nlemma differentiable_pi :\n  differentiable \ud835\udd5c \u03a6 \u2194 \u2200 i, differentiable \ud835\udd5c (\u03bb x, \u03a6 x i) :=\n\u27e8\u03bb h i x, differentiable_at_pi.1 (h x) i, \u03bb h x, differentiable_at_pi.2 (\u03bb i, h i x)\u27e9\n\n-- TODO: find out which version (`\u03c6` or `\u03a6`) works better with `rw`/`simp`\nlemma fderiv_within_pi (h : \u2200 i, differentiable_within_at \ud835\udd5c (\u03c6 i) s x)\n  (hs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bb x i, \u03c6 i x) s x = pi (\u03bb i, fderiv_within \ud835\udd5c (\u03c6 i) s x) :=\n(has_fderiv_within_at_pi.2 (\u03bb i, (h i).has_fderiv_within_at)).fderiv_within hs\n\nlemma fderiv_pi (h : \u2200 i, differentiable_at \ud835\udd5c (\u03c6 i) x) :\n  fderiv \ud835\udd5c (\u03bb x i, \u03c6 i x) x = pi (\u03bb i, fderiv \ud835\udd5c (\u03c6 i) x) :=\n(has_fderiv_at_pi.2 (\u03bb i, (h i).has_fderiv_at)).fderiv\n\nend pi\n\nsection neg\n/-! ### Derivative of the negative of a function -/\n\ntheorem has_strict_fderiv_at.neg (h : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, -f x) (-f') x :=\n(-1 : F \u2192L[\ud835\udd5c] F).has_strict_fderiv_at.comp x h\n\ntheorem has_fderiv_at_filter.neg (h : has_fderiv_at_filter f f' x L) :\n  has_fderiv_at_filter (\u03bb x, -f x) (-f') x L :=\n(-1 : F \u2192L[\ud835\udd5c] F).has_fderiv_at_filter.comp x h\n\ntheorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, -f x) (-f') s x :=\nh.neg\n\ntheorem has_fderiv_at.neg (h : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, -f x) (-f') x :=\nh.neg\n\nlemma differentiable_within_at.neg (h : differentiable_within_at \ud835\udd5c f s x) :\n  differentiable_within_at \ud835\udd5c (\u03bby, -f y) s x :=\nh.has_fderiv_within_at.neg.differentiable_within_at\n\n@[simp] lemma differentiable_within_at_neg_iff :\n  differentiable_within_at \ud835\udd5c (\u03bby, -f y) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\n\u27e8\u03bb h, by simpa only [neg_neg] using h.neg, \u03bb h, h.neg\u27e9\n\nlemma differentiable_at.neg (h : differentiable_at \ud835\udd5c f x) :\n  differentiable_at \ud835\udd5c (\u03bby, -f y) x :=\nh.has_fderiv_at.neg.differentiable_at\n\n@[simp] lemma differentiable_at_neg_iff :\n  differentiable_at \ud835\udd5c (\u03bby, -f y) x \u2194 differentiable_at \ud835\udd5c f x :=\n\u27e8\u03bb h, by simpa only [neg_neg] using h.neg, \u03bb h, h.neg\u27e9\n\nlemma differentiable_on.neg (h : differentiable_on \ud835\udd5c f s) :\n  differentiable_on \ud835\udd5c (\u03bby, -f y) s :=\n\u03bbx hx, (h x hx).neg\n\n@[simp] lemma differentiable_on_neg_iff :\n  differentiable_on \ud835\udd5c (\u03bby, -f y) s \u2194 differentiable_on \ud835\udd5c f s :=\n\u27e8\u03bb h, by simpa only [neg_neg] using h.neg, \u03bb h, h.neg\u27e9\n\nlemma differentiable.neg (h : differentiable \ud835\udd5c f) :\n  differentiable \ud835\udd5c (\u03bby, -f y) :=\n\u03bbx, (h x).neg\n\n@[simp] lemma differentiable_neg_iff : differentiable \ud835\udd5c (\u03bby, -f y) \u2194 differentiable \ud835\udd5c f :=\n\u27e8\u03bb h, by simpa only [neg_neg] using h.neg, \u03bb h, h.neg\u27e9\n\nlemma fderiv_within_neg (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bby, -f y) s x = - fderiv_within \ud835\udd5c f s x :=\nif h : differentiable_within_at \ud835\udd5c f s x\nthen h.has_fderiv_within_at.neg.fderiv_within hxs\nelse by { rw [fderiv_within_zero_of_not_differentiable_within_at h,\n  fderiv_within_zero_of_not_differentiable_within_at, neg_zero], simpa }\n\n@[simp] lemma fderiv_neg : fderiv \ud835\udd5c (\u03bby, -f y) x = - fderiv \ud835\udd5c f x :=\nby simp only [\u2190 fderiv_within_univ, fderiv_within_neg unique_diff_within_at_univ]\n\nend neg\n\nsection sub\n/-! ### Derivative of the difference of two functions -/\n\ntheorem has_strict_fderiv_at.sub\n  (hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) :\n  has_strict_fderiv_at (\u03bb x, f x - g x) (f' - g') x :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\ntheorem has_fderiv_at_filter.sub\n  (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) :\n  has_fderiv_at_filter (\u03bb x, f x - g x) (f' - g') x L :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\ntheorem has_fderiv_within_at.sub\n  (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) :\n  has_fderiv_within_at (\u03bb x, f x - g x) (f' - g') s x :=\nhf.sub hg\n\ntheorem has_fderiv_at.sub\n  (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :\n  has_fderiv_at (\u03bb x, f x - g x) (f' - g') x :=\nhf.sub hg\n\nlemma differentiable_within_at.sub\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, f y - g y) s x :=\n(hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).differentiable_within_at\n\n@[simp] lemma differentiable_at.sub\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  differentiable_at \ud835\udd5c (\u03bb y, f y - g y) x :=\n(hf.has_fderiv_at.sub hg.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.sub\n  (hf : differentiable_on \ud835\udd5c f s) (hg : differentiable_on \ud835\udd5c g s) :\n  differentiable_on \ud835\udd5c (\u03bby, f y - g y) s :=\n\u03bbx hx, (hf x hx).sub (hg x hx)\n\n@[simp] lemma differentiable.sub\n  (hf : differentiable \ud835\udd5c f) (hg : differentiable \ud835\udd5c g) :\n  differentiable \ud835\udd5c (\u03bby, f y - g y) :=\n\u03bbx, (hf x).sub (hg x)\n\nlemma fderiv_within_sub (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  fderiv_within \ud835\udd5c (\u03bby, f y - g y) s x = fderiv_within \ud835\udd5c f s x - fderiv_within \ud835\udd5c g s x :=\n(hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_sub\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  fderiv \ud835\udd5c (\u03bby, f y - g y) x = fderiv \ud835\udd5c f x - fderiv \ud835\udd5c g x :=\n(hf.has_fderiv_at.sub hg.has_fderiv_at).fderiv\n\ntheorem has_strict_fderiv_at.sub_const\n  (hf : has_strict_fderiv_at f f' x) (c : F) :\n  has_strict_fderiv_at (\u03bb x, f x - c) f' x :=\nby simpa only [sub_eq_add_neg] using hf.add_const (-c)\n\ntheorem has_fderiv_at_filter.sub_const\n  (hf : has_fderiv_at_filter f f' x L) (c : F) :\n  has_fderiv_at_filter (\u03bb x, f x - c) f' x L :=\nby simpa only [sub_eq_add_neg] using hf.add_const (-c)\n\ntheorem has_fderiv_within_at.sub_const\n  (hf : has_fderiv_within_at f f' s x) (c : F) :\n  has_fderiv_within_at (\u03bb x, f x - c) f' s x :=\nhf.sub_const c\n\ntheorem has_fderiv_at.sub_const\n  (hf : has_fderiv_at f f' x) (c : F) :\n  has_fderiv_at (\u03bb x, f x - c) f' x :=\nhf.sub_const c\n\nlemma differentiable_within_at.sub_const\n  (hf : differentiable_within_at \ud835\udd5c f s x) (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, f y - c) s x :=\n(hf.has_fderiv_within_at.sub_const c).differentiable_within_at\n\n@[simp] lemma differentiable_within_at_sub_const_iff (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, f y - c) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\nby simp only [sub_eq_add_neg, differentiable_within_at_add_const_iff]\n\nlemma differentiable_at.sub_const (hf : differentiable_at \ud835\udd5c f x) (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, f y - c) x :=\n(hf.has_fderiv_at.sub_const c).differentiable_at\n\n@[simp] lemma differentiable_at_sub_const_iff (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, f y - c) x \u2194 differentiable_at \ud835\udd5c f x :=\nby simp only [sub_eq_add_neg, differentiable_at_add_const_iff]\n\nlemma differentiable_on.sub_const (hf : differentiable_on \ud835\udd5c f s) (c : F) :\n  differentiable_on \ud835\udd5c (\u03bby, f y - c) s :=\n\u03bbx hx, (hf x hx).sub_const c\n\n@[simp] lemma differentiable_on_sub_const_iff (c : F) :\n  differentiable_on \ud835\udd5c (\u03bb y, f y - c) s \u2194 differentiable_on \ud835\udd5c f s :=\nby simp only [sub_eq_add_neg, differentiable_on_add_const_iff]\n\nlemma differentiable.sub_const (hf : differentiable \ud835\udd5c f) (c : F) :\n  differentiable \ud835\udd5c (\u03bby, f y - c) :=\n\u03bbx, (hf x).sub_const c\n\n@[simp] lemma differentiable_sub_const_iff (c : F) :\n  differentiable \ud835\udd5c (\u03bb y, f y - c) \u2194 differentiable \ud835\udd5c f :=\nby simp only [sub_eq_add_neg, differentiable_add_const_iff]\n\nlemma fderiv_within_sub_const (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  fderiv_within \ud835\udd5c (\u03bby, f y - c) s x = fderiv_within \ud835\udd5c f s x :=\nby simp only [sub_eq_add_neg, fderiv_within_add_const hxs]\n\nlemma fderiv_sub_const (c : F) : fderiv \ud835\udd5c (\u03bby, f y - c) x = fderiv \ud835\udd5c f x :=\nby simp only [sub_eq_add_neg, fderiv_add_const]\n\ntheorem has_strict_fderiv_at.const_sub\n  (hf : has_strict_fderiv_at f f' x) (c : F) :\n  has_strict_fderiv_at (\u03bb x, c - f x) (-f') x :=\nby simpa only [sub_eq_add_neg] using hf.neg.const_add c\n\ntheorem has_fderiv_at_filter.const_sub\n  (hf : has_fderiv_at_filter f f' x L) (c : F) :\n  has_fderiv_at_filter (\u03bb x, c - f x) (-f') x L :=\nby simpa only [sub_eq_add_neg] using hf.neg.const_add c\n\ntheorem has_fderiv_within_at.const_sub\n  (hf : has_fderiv_within_at f f' s x) (c : F) :\n  has_fderiv_within_at (\u03bb x, c - f x) (-f') s x :=\nhf.const_sub c\n\ntheorem has_fderiv_at.const_sub\n  (hf : has_fderiv_at f f' x) (c : F) :\n  has_fderiv_at (\u03bb x, c - f x) (-f') x :=\nhf.const_sub c\n\nlemma differentiable_within_at.const_sub\n  (hf : differentiable_within_at \ud835\udd5c f s x) (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c - f y) s x :=\n(hf.has_fderiv_within_at.const_sub c).differentiable_within_at\n\n@[simp] lemma differentiable_within_at_const_sub_iff (c : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c - f y) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\nby simp [sub_eq_add_neg]\n\nlemma differentiable_at.const_sub\n  (hf : differentiable_at \ud835\udd5c f x) (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, c - f y) x :=\n(hf.has_fderiv_at.const_sub c).differentiable_at\n\n@[simp] lemma differentiable_at_const_sub_iff (c : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, c - f y) x \u2194 differentiable_at \ud835\udd5c f x :=\nby simp [sub_eq_add_neg]\n\nlemma differentiable_on.const_sub (hf : differentiable_on \ud835\udd5c f s) (c : F) :\n  differentiable_on \ud835\udd5c (\u03bby, c - f y) s :=\n\u03bbx hx, (hf x hx).const_sub c\n\n@[simp] lemma differentiable_on_const_sub_iff (c : F) :\n  differentiable_on \ud835\udd5c (\u03bb y, c - f y) s \u2194 differentiable_on \ud835\udd5c f s :=\nby simp [sub_eq_add_neg]\n\nlemma differentiable.const_sub (hf : differentiable \ud835\udd5c f) (c : F) :\n  differentiable \ud835\udd5c (\u03bby, c - f y) :=\n\u03bbx, (hf x).const_sub c\n\n@[simp] lemma differentiable_const_sub_iff (c : F) :\n  differentiable \ud835\udd5c (\u03bb y, c - f y) \u2194 differentiable \ud835\udd5c f :=\nby simp [sub_eq_add_neg]\n\nlemma fderiv_within_const_sub (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  fderiv_within \ud835\udd5c (\u03bby, c - f y) s x = -fderiv_within \ud835\udd5c f s x :=\nby simp only [sub_eq_add_neg, fderiv_within_const_add, fderiv_within_neg, hxs]\n\nlemma fderiv_const_sub (c : F) : fderiv \ud835\udd5c (\u03bby, c - f y) x = -fderiv \ud835\udd5c f x :=\nby simp only [\u2190 fderiv_within_univ, fderiv_within_const_sub unique_diff_within_at_univ]\n\nend sub\n\nsection bilinear_map\n/-! ### Derivative of a bounded bilinear map -/\n\nvariables {b : E \u00d7 F \u2192 G} {u : set (E \u00d7 F) }\n\nopen normed_field\n\nlemma is_bounded_bilinear_map.has_strict_fderiv_at (h : is_bounded_bilinear_map \ud835\udd5c b) (p : E \u00d7 F) :\n  has_strict_fderiv_at b (h.deriv p) p :=\nbegin\n  rw has_strict_fderiv_at,\n  set T := (E \u00d7 F) \u00d7 (E \u00d7 F),\n  have : is_o (\u03bb q : T, b (q.1 - q.2)) (\u03bb q : T, \u2225q.1 - q.2\u2225 * 1) (\ud835\udcdd (p, p)),\n  { refine (h.is_O'.comp_tendsto le_top).trans_is_o _,\n    simp only [(\u2218)],\n    refine (is_O_refl (\u03bb q : T, \u2225q.1 - q.2\u2225) _).mul_is_o (is_o.norm_left $ (is_o_one_iff _).2 _),\n    rw [\u2190 sub_self p],\n    exact continuous_at_fst.sub continuous_at_snd },\n  simp only [mul_one, is_o_norm_right] at this,\n  refine (is_o.congr_of_sub _).1 this, clear this,\n  convert_to is_o (\u03bb q : T, h.deriv (p - q.2) (q.1 - q.2)) (\u03bb q : T, q.1 - q.2) (\ud835\udcdd (p, p)),\n  { ext \u27e8\u27e8x\u2081, y\u2081\u27e9, \u27e8x\u2082, y\u2082\u27e9\u27e9, rcases p with \u27e8x, y\u27e9,\n    simp only [is_bounded_bilinear_map_deriv_coe, prod.mk_sub_mk, h.map_sub_left, h.map_sub_right],\n    abel },\n  have : is_o (\u03bb q : T, p - q.2) (\u03bb q, (1:\u211d)) (\ud835\udcdd (p, p)),\n    from (is_o_one_iff _).2 (sub_self p \u25b8 tendsto_const_nhds.sub continuous_at_snd),\n  apply is_bounded_bilinear_map_apply.is_O_comp.trans_is_o,\n  refine is_o.trans_is_O _ (is_O_const_mul_self 1 _ _).of_norm_right,\n  refine is_o.mul_is_O _ (is_O_refl _ _),\n  exact (((h.is_bounded_linear_map_deriv.is_O_id \u22a4).comp_tendsto le_top : _).trans_is_o\n    this).norm_left\nend\n\nlemma is_bounded_bilinear_map.has_fderiv_at (h : is_bounded_bilinear_map \ud835\udd5c b) (p : E \u00d7 F) :\n  has_fderiv_at b (h.deriv p) p :=\n(h.has_strict_fderiv_at p).has_fderiv_at\n\nlemma is_bounded_bilinear_map.has_fderiv_within_at (h : is_bounded_bilinear_map \ud835\udd5c b) (p : E \u00d7 F) :\n  has_fderiv_within_at b (h.deriv p) u p :=\n(h.has_fderiv_at p).has_fderiv_within_at\n\nlemma is_bounded_bilinear_map.differentiable_at (h : is_bounded_bilinear_map \ud835\udd5c b) (p : E \u00d7 F) :\n  differentiable_at \ud835\udd5c b p :=\n(h.has_fderiv_at p).differentiable_at\n\nlemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map \ud835\udd5c b)\n  (p : E \u00d7 F) :\n  differentiable_within_at \ud835\udd5c b u p :=\n(h.differentiable_at p).differentiable_within_at\n\nlemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map \ud835\udd5c b) (p : E \u00d7 F) :\n  fderiv \ud835\udd5c b p = h.deriv p :=\nhas_fderiv_at.fderiv (h.has_fderiv_at p)\n\nlemma is_bounded_bilinear_map.fderiv_within (h : is_bounded_bilinear_map \ud835\udd5c b) (p : E \u00d7 F)\n  (hxs : unique_diff_within_at \ud835\udd5c u p) : fderiv_within \ud835\udd5c b u p = h.deriv p :=\nbegin\n  rw differentiable_at.fderiv_within (h.differentiable_at p) hxs,\n  exact h.fderiv p\nend\n\nlemma is_bounded_bilinear_map.differentiable (h : is_bounded_bilinear_map \ud835\udd5c b) :\n  differentiable \ud835\udd5c b :=\n\u03bbx, h.differentiable_at x\n\nlemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map \ud835\udd5c b) :\n  differentiable_on \ud835\udd5c b u :=\nh.differentiable.differentiable_on\n\nlemma is_bounded_bilinear_map.continuous (h : is_bounded_bilinear_map \ud835\udd5c b) :\n  continuous b :=\nh.differentiable.continuous\n\nlemma is_bounded_bilinear_map.continuous_left (h : is_bounded_bilinear_map \ud835\udd5c b) {f : F} :\n  continuous (\u03bbe, b (e, f)) :=\nh.continuous.comp (continuous_id.prod_mk continuous_const)\n\nlemma is_bounded_bilinear_map.continuous_right (h : is_bounded_bilinear_map \ud835\udd5c b) {e : E} :\n  continuous (\u03bbf, b (e, f)) :=\nh.continuous.comp (continuous_const.prod_mk continuous_id)\n\nend bilinear_map\n\nnamespace continuous_linear_equiv\n\n/-!\n### The set of continuous linear equivalences between two Banach spaces is open\n\nIn this section we establish that the set of continuous linear equivalences between two Banach\nspaces is an open subset of the space of linear maps between them.  These facts are placed here\nbecause the proof uses `is_bounded_bilinear_map.continuous_left`, proved just above as a consequence\nof its differentiability.\n-/\n\nprotected lemma is_open [complete_space E] : is_open (range (coe : (E \u2243L[\ud835\udd5c] F) \u2192 (E \u2192L[\ud835\udd5c] F))) :=\nbegin\n  nontriviality E,\n  rw [is_open_iff_mem_nhds, forall_range_iff],\n  refine \u03bb e, mem_nhds_sets _ (mem_range_self _),\n  let O : (E \u2192L[\ud835\udd5c] F) \u2192 (E \u2192L[\ud835\udd5c] E) := \u03bb f, (e.symm : F \u2192L[\ud835\udd5c] E).comp f,\n  have h_O : continuous O := is_bounded_bilinear_map_comp.continuous_left,\n  convert units.is_open.preimage h_O using 1,\n  ext f',\n  split,\n  { rintros \u27e8e', rfl\u27e9,\n    exact \u27e8(e'.trans e.symm).to_unit, rfl\u27e9 },\n  { rintros \u27e8w, hw\u27e9,\n    use (units_equiv \ud835\udd5c E w).trans e,\n    ext x,\n    simp [hw] }\nend\n\nprotected lemma nhds [complete_space E] (e : E \u2243L[\ud835\udd5c] F) :\n  (range (coe : (E \u2243L[\ud835\udd5c] F) \u2192 (E \u2192L[\ud835\udd5c] F))) \u2208 \ud835\udcdd (e : E \u2192L[\ud835\udd5c] F) :=\nmem_nhds_sets continuous_linear_equiv.is_open (by simp)\n\nend continuous_linear_equiv\n\nsection smul\n/-! ### Derivative of the product of a scalar-valued function and a vector-valued function\n\nIf `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued\nfunction, then `\u03bb x, c x \u2022 f x` is differentiable as well. Lemmas in this section works for\nfunction `c` taking values in the base field, as well as in a normed algebra over the base\nfield: e.g., they work for `c : E \u2192 \u2102` and `f : E \u2192 F` provided that `F` is a complex\nnormed vector space.\n-/\n\nvariables {\ud835\udd5c' : Type*} [nondiscrete_normed_field \ud835\udd5c'] [normed_algebra \ud835\udd5c \ud835\udd5c']\n  [normed_space \ud835\udd5c' F] [is_scalar_tower \ud835\udd5c \ud835\udd5c' F]\nvariables {c : E \u2192 \ud835\udd5c'} {c' : E \u2192L[\ud835\udd5c] \ud835\udd5c'}\n\ntheorem has_strict_fderiv_at.smul (hc : has_strict_fderiv_at c c' x)\n  (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c'.smul_right (f x)) x :=\n(is_bounded_bilinear_map_smul.has_strict_fderiv_at (c x, f x)).comp x $\n  hc.prod hf\n\ntheorem has_fderiv_within_at.smul\n  (hc : has_fderiv_within_at c c' s x) (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c'.smul_right (f x)) s x :=\n(is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp_has_fderiv_within_at x $\n  hc.prod hf\n\ntheorem has_fderiv_at.smul (hc : has_fderiv_at c c' x) (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c'.smul_right (f x)) x :=\n(is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp x $\n  hc.prod hf\n\nlemma differentiable_within_at.smul\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c y \u2022 f y) s x :=\n(hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).differentiable_within_at\n\n@[simp] lemma differentiable_at.smul (hc : differentiable_at \ud835\udd5c c x) (hf : differentiable_at \ud835\udd5c f x) :\n  differentiable_at \ud835\udd5c (\u03bb y, c y \u2022 f y) x :=\n(hc.has_fderiv_at.smul hf.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.smul (hc : differentiable_on \ud835\udd5c c s) (hf : differentiable_on \ud835\udd5c f s) :\n  differentiable_on \ud835\udd5c (\u03bb y, c y \u2022 f y) s :=\n\u03bbx hx, (hc x hx).smul (hf x hx)\n\n@[simp] lemma differentiable.smul (hc : differentiable \ud835\udd5c c) (hf : differentiable \ud835\udd5c f) :\n  differentiable \ud835\udd5c (\u03bb y, c y \u2022 f y) :=\n\u03bbx, (hc x).smul (hf x)\n\nlemma fderiv_within_smul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  fderiv_within \ud835\udd5c (\u03bb y, c y \u2022 f y) s x =\n    c x \u2022 fderiv_within \ud835\udd5c f s x + (fderiv_within \ud835\udd5c c s x).smul_right (f x) :=\n(hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_smul (hc : differentiable_at \ud835\udd5c c x) (hf : differentiable_at \ud835\udd5c f x) :\n  fderiv \ud835\udd5c (\u03bb y, c y \u2022 f y) x =\n    c x \u2022 fderiv \ud835\udd5c f x + (fderiv \ud835\udd5c c x).smul_right (f x) :=\n(hc.has_fderiv_at.smul hf.has_fderiv_at).fderiv\n\ntheorem has_strict_fderiv_at.smul_const (hc : has_strict_fderiv_at c c' x) (f : F) :\n  has_strict_fderiv_at (\u03bb y, c y \u2022 f) (c'.smul_right f) x :=\nby simpa only [smul_zero, zero_add] using hc.smul (has_strict_fderiv_at_const f x)\n\ntheorem has_fderiv_within_at.smul_const (hc : has_fderiv_within_at c c' s x) (f : F) :\n  has_fderiv_within_at (\u03bb y, c y \u2022 f) (c'.smul_right f) s x :=\nby simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_within_at_const f x s)\n\ntheorem has_fderiv_at.smul_const (hc : has_fderiv_at c c' x) (f : F) :\n  has_fderiv_at (\u03bb y, c y \u2022 f) (c'.smul_right f) x :=\nby simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_at_const f x)\n\nlemma differentiable_within_at.smul_const\n  (hc : differentiable_within_at \ud835\udd5c c s x) (f : F) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c y \u2022 f) s x :=\n(hc.has_fderiv_within_at.smul_const f).differentiable_within_at\n\nlemma differentiable_at.smul_const (hc : differentiable_at \ud835\udd5c c x) (f : F) :\n  differentiable_at \ud835\udd5c (\u03bb y, c y \u2022 f) x :=\n(hc.has_fderiv_at.smul_const f).differentiable_at\n\nlemma differentiable_on.smul_const (hc : differentiable_on \ud835\udd5c c s) (f : F) :\n  differentiable_on \ud835\udd5c (\u03bb y, c y \u2022 f) s :=\n\u03bbx hx, (hc x hx).smul_const f\n\nlemma differentiable.smul_const (hc : differentiable \ud835\udd5c c) (f : F) :\n  differentiable \ud835\udd5c (\u03bb y, c y \u2022 f) :=\n\u03bbx, (hc x).smul_const f\n\nlemma fderiv_within_smul_const (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (f : F) :\n  fderiv_within \ud835\udd5c (\u03bb y, c y \u2022 f) s x =\n    (fderiv_within \ud835\udd5c c s x).smul_right f :=\n(hc.has_fderiv_within_at.smul_const f).fderiv_within hxs\n\nlemma fderiv_smul_const (hc : differentiable_at \ud835\udd5c c x) (f : F) :\n  fderiv \ud835\udd5c (\u03bb y, c y \u2022 f) x = (fderiv \ud835\udd5c c x).smul_right f :=\n(hc.has_fderiv_at.smul_const f).fderiv\n\nend smul\n\nsection mul\n/-! ### Derivative of the product of two scalar-valued functions -/\n\nvariables {c d : E \u2192 \ud835\udd5c} {c' d' : E \u2192L[\ud835\udd5c] \ud835\udd5c}\n\ntheorem has_strict_fderiv_at.mul\n  (hc : has_strict_fderiv_at c c' x) (hd : has_strict_fderiv_at d d' x) :\n  has_strict_fderiv_at (\u03bb y, c y * d y) (c x \u2022 d' + d x \u2022 c') x :=\nby { convert hc.smul hd, ext z, apply mul_comm }\n\ntheorem has_fderiv_within_at.mul\n  (hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) :\n  has_fderiv_within_at (\u03bb y, c y * d y) (c x \u2022 d' + d x \u2022 c') s x :=\nby { convert hc.smul hd, ext z, apply mul_comm }\n\ntheorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) :\n  has_fderiv_at (\u03bb y, c y * d y) (c x \u2022 d' + d x \u2022 c') x :=\nby { convert hc.smul hd, ext z, apply mul_comm }\n\nlemma differentiable_within_at.mul\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c y * d y) s x :=\n(hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).differentiable_within_at\n\n@[simp] lemma differentiable_at.mul (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) :\n  differentiable_at \ud835\udd5c (\u03bb y, c y * d y) x :=\n(hc.has_fderiv_at.mul hd.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.mul (hc : differentiable_on \ud835\udd5c c s) (hd : differentiable_on \ud835\udd5c d s) :\n  differentiable_on \ud835\udd5c (\u03bb y, c y * d y) s :=\n\u03bbx hx, (hc x hx).mul (hd x hx)\n\n@[simp] lemma differentiable.mul (hc : differentiable \ud835\udd5c c) (hd : differentiable \ud835\udd5c d) :\n  differentiable \ud835\udd5c (\u03bb y, c y * d y) :=\n\u03bbx, (hc x).mul (hd x)\n\nlemma fderiv_within_mul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) :\n  fderiv_within \ud835\udd5c (\u03bb y, c y * d y) s x =\n    c x \u2022 fderiv_within \ud835\udd5c d s x + d x \u2022 fderiv_within \ud835\udd5c c s x :=\n(hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_mul (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) :\n  fderiv \ud835\udd5c (\u03bb y, c y * d y) x =\n    c x \u2022 fderiv \ud835\udd5c d x + d x \u2022 fderiv \ud835\udd5c c x :=\n(hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv\n\ntheorem has_strict_fderiv_at.mul_const (hc : has_strict_fderiv_at c c' x) (d : \ud835\udd5c) :\n  has_strict_fderiv_at (\u03bb y, c y * d) (d \u2022 c') x :=\nby simpa only [smul_zero, zero_add] using hc.mul (has_strict_fderiv_at_const d x)\n\ntheorem has_fderiv_within_at.mul_const (hc : has_fderiv_within_at c c' s x) (d : \ud835\udd5c) :\n  has_fderiv_within_at (\u03bb y, c y * d) (d \u2022 c') s x :=\nby simpa only [smul_zero, zero_add] using hc.mul (has_fderiv_within_at_const d x s)\n\ntheorem has_fderiv_at.mul_const (hc : has_fderiv_at c c' x) (d : \ud835\udd5c) :\n  has_fderiv_at (\u03bb y, c y * d) (d \u2022 c') x :=\nbegin\n  rw [\u2190 has_fderiv_within_at_univ] at *,\n  exact hc.mul_const d\nend\n\nlemma differentiable_within_at.mul_const\n  (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd5c) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, c y * d) s x :=\n(hc.has_fderiv_within_at.mul_const d).differentiable_within_at\n\nlemma differentiable_at.mul_const (hc : differentiable_at \ud835\udd5c c x) (d : \ud835\udd5c) :\n  differentiable_at \ud835\udd5c (\u03bb y, c y * d) x :=\n(hc.has_fderiv_at.mul_const d).differentiable_at\n\nlemma differentiable_on.mul_const (hc : differentiable_on \ud835\udd5c c s) (d : \ud835\udd5c) :\n  differentiable_on \ud835\udd5c (\u03bb y, c y * d) s :=\n\u03bbx hx, (hc x hx).mul_const d\n\nlemma differentiable.mul_const (hc : differentiable \ud835\udd5c c) (d : \ud835\udd5c) :\n  differentiable \ud835\udd5c (\u03bb y, c y * d) :=\n\u03bbx, (hc x).mul_const d\n\nlemma fderiv_within_mul_const (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd5c) :\n  fderiv_within \ud835\udd5c (\u03bb y, c y * d) s x = d \u2022 fderiv_within \ud835\udd5c c s x :=\n(hc.has_fderiv_within_at.mul_const d).fderiv_within hxs\n\nlemma fderiv_mul_const (hc : differentiable_at \ud835\udd5c c x) (d : \ud835\udd5c) :\n  fderiv \ud835\udd5c (\u03bb y, c y * d) x = d \u2022 fderiv \ud835\udd5c c x :=\n(hc.has_fderiv_at.mul_const d).fderiv\n\ntheorem has_strict_fderiv_at.const_mul (hc : has_strict_fderiv_at c c' x) (d : \ud835\udd5c) :\n  has_strict_fderiv_at (\u03bb y, d * c y) (d \u2022 c') x :=\nbegin\n  simp only [mul_comm d],\n  exact hc.mul_const d,\nend\n\ntheorem has_fderiv_within_at.const_mul\n  (hc : has_fderiv_within_at c c' s x) (d : \ud835\udd5c) :\n  has_fderiv_within_at (\u03bb y, d * c y) (d \u2022 c') s x :=\nbegin\n  simp only [mul_comm d],\n  exact hc.mul_const d,\nend\n\ntheorem has_fderiv_at.const_mul (hc : has_fderiv_at c c' x) (d : \ud835\udd5c) :\n  has_fderiv_at (\u03bb y, d * c y) (d \u2022 c') x :=\nbegin\n  simp only [mul_comm d],\n  exact hc.mul_const d,\nend\n\nlemma differentiable_within_at.const_mul\n  (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd5c) :\n  differentiable_within_at \ud835\udd5c (\u03bb y, d * c y) s x :=\n(hc.has_fderiv_within_at.const_mul d).differentiable_within_at\n\nlemma differentiable_at.const_mul (hc : differentiable_at \ud835\udd5c c x) (d : \ud835\udd5c) :\n  differentiable_at \ud835\udd5c (\u03bb y, d * c y) x :=\n(hc.has_fderiv_at.const_mul d).differentiable_at\n\nlemma differentiable_on.const_mul (hc : differentiable_on \ud835\udd5c c s) (d : \ud835\udd5c) :\n  differentiable_on \ud835\udd5c (\u03bb y, d * c y) s :=\n\u03bbx hx, (hc x hx).const_mul d\n\nlemma differentiable.const_mul (hc : differentiable \ud835\udd5c c) (d : \ud835\udd5c) :\n  differentiable \ud835\udd5c (\u03bb y, d * c y) :=\n\u03bbx, (hc x).const_mul d\n\nlemma fderiv_within_const_mul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd5c) :\n  fderiv_within \ud835\udd5c (\u03bb y, d * c y) s x = d \u2022 fderiv_within \ud835\udd5c c s x :=\n(hc.has_fderiv_within_at.const_mul d).fderiv_within hxs\n\nlemma fderiv_const_mul (hc : differentiable_at \ud835\udd5c c x) (d : \ud835\udd5c) :\n  fderiv \ud835\udd5c (\u03bb y, d * c y) x = d \u2022 fderiv \ud835\udd5c c x :=\n(hc.has_fderiv_at.const_mul d).fderiv\n\nend mul\n\nsection algebra_inverse\nvariables {R : Type*} [normed_ring R] [normed_algebra \ud835\udd5c R] [complete_space R]\nopen normed_ring continuous_linear_map ring\n\n/-- At an invertible element `x` of a normed algebra `R`, the Fr\u00e9chet derivative of the inversion\noperation is the linear map `\u03bb t, - x\u207b\u00b9 * t * x\u207b\u00b9`. -/\nlemma has_fderiv_at_ring_inverse (x : units R) :\n  has_fderiv_at ring.inverse (-lmul_left_right \ud835\udd5c R \u2191x\u207b\u00b9 \u2191x\u207b\u00b9) x :=\nbegin\n  have h_is_o : is_o (\u03bb (t : R), inverse (\u2191x + t) - \u2191x\u207b\u00b9 + \u2191x\u207b\u00b9 * t * \u2191x\u207b\u00b9)\n    (\u03bb (t : R), t) (\ud835\udcdd 0),\n  { refine (inverse_add_norm_diff_second_order x).trans_is_o ((is_o_norm_norm).mp _),\n    simp only [normed_field.norm_pow, norm_norm],\n    have h12 : 1 < 2 := by norm_num,\n    convert (asymptotics.is_o_pow_pow h12).comp_tendsto tendsto_norm_zero,\n    ext, simp },\n  have h_lim : tendsto (\u03bb (y:R), y - x) (\ud835\udcdd x) (\ud835\udcdd 0),\n  { refine tendsto_zero_iff_norm_tendsto_zero.mpr _,\n    exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },\n  simp only [has_fderiv_at, has_fderiv_at_filter],\n  convert h_is_o.comp_tendsto h_lim,\n  ext y,\n  simp only [coe_comp', function.comp_app, lmul_left_right_apply, neg_apply, inverse_unit x,\n    units.inv_mul, add_sub_cancel'_right, mul_sub, sub_mul, one_mul, sub_neg_eq_add]\nend\n\nlemma differentiable_at_inverse (x : units R) : differentiable_at \ud835\udd5c (@ring.inverse R _) x :=\n(has_fderiv_at_ring_inverse x).differentiable_at\n\nlemma fderiv_inverse (x : units R) :\n  fderiv \ud835\udd5c (@ring.inverse R _) x = - lmul_left_right \ud835\udd5c R \u2191x\u207b\u00b9 \u2191x\u207b\u00b9 :=\n(has_fderiv_at_ring_inverse x).fderiv\n\nend algebra_inverse\n\nnamespace continuous_linear_equiv\n/-! ### Differentiability of linear equivs, and invariance of differentiability -/\n\nvariable (iso : E \u2243L[\ud835\udd5c] F)\n\nprotected lemma has_strict_fderiv_at :\n  has_strict_fderiv_at iso (iso : E \u2192L[\ud835\udd5c] F) x :=\niso.to_continuous_linear_map.has_strict_fderiv_at\n\nprotected lemma has_fderiv_within_at :\n  has_fderiv_within_at iso (iso : E \u2192L[\ud835\udd5c] F) s x :=\niso.to_continuous_linear_map.has_fderiv_within_at\n\nprotected lemma has_fderiv_at : has_fderiv_at iso (iso : E \u2192L[\ud835\udd5c] F) x :=\niso.to_continuous_linear_map.has_fderiv_at_filter\n\nprotected lemma differentiable_at : differentiable_at \ud835\udd5c iso x :=\niso.has_fderiv_at.differentiable_at\n\nprotected lemma differentiable_within_at :\n  differentiable_within_at \ud835\udd5c iso s x :=\niso.differentiable_at.differentiable_within_at\n\nprotected lemma fderiv : fderiv \ud835\udd5c iso x = iso :=\niso.has_fderiv_at.fderiv\n\nprotected lemma fderiv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c iso s x = iso :=\niso.to_continuous_linear_map.fderiv_within hxs\n\nprotected lemma differentiable : differentiable \ud835\udd5c iso :=\n\u03bbx, iso.differentiable_at\n\nprotected lemma differentiable_on : differentiable_on \ud835\udd5c iso s :=\niso.differentiable.differentiable_on\n\nlemma comp_differentiable_within_at_iff {f : G \u2192 E} {s : set G} {x : G} :\n  differentiable_within_at \ud835\udd5c (iso \u2218 f) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\nbegin\n  refine \u27e8\u03bb H, _, \u03bb H, iso.differentiable.differentiable_at.comp_differentiable_within_at x H\u27e9,\n  have : differentiable_within_at \ud835\udd5c (iso.symm \u2218 (iso \u2218 f)) s x :=\n    iso.symm.differentiable.differentiable_at.comp_differentiable_within_at x H,\n  rwa [\u2190 function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this,\nend\n\nlemma comp_differentiable_at_iff {f : G \u2192 E} {x : G} :\n  differentiable_at \ud835\udd5c (iso \u2218 f) x \u2194 differentiable_at \ud835\udd5c f x :=\nby rw [\u2190 differentiable_within_at_univ, \u2190 differentiable_within_at_univ,\n       iso.comp_differentiable_within_at_iff]\n\nlemma comp_differentiable_on_iff {f : G \u2192 E} {s : set G} :\n  differentiable_on \ud835\udd5c (iso \u2218 f) s \u2194 differentiable_on \ud835\udd5c f s :=\nbegin\n  rw [differentiable_on, differentiable_on],\n  simp only [iso.comp_differentiable_within_at_iff],\nend\n\nlemma comp_differentiable_iff {f : G \u2192 E} :\n  differentiable \ud835\udd5c (iso \u2218 f) \u2194 differentiable \ud835\udd5c f :=\nbegin\n  rw [\u2190 differentiable_on_univ, \u2190 differentiable_on_univ],\n  exact iso.comp_differentiable_on_iff\nend\n\nlemma comp_has_fderiv_within_at_iff\n  {f : G \u2192 E} {s : set G} {x : G} {f' : G \u2192L[\ud835\udd5c] E} :\n  has_fderiv_within_at (iso \u2218 f) ((iso : E \u2192L[\ud835\udd5c] F).comp f') s x \u2194 has_fderiv_within_at f f' s x :=\nbegin\n  refine \u27e8\u03bb H, _, \u03bb H, iso.has_fderiv_at.comp_has_fderiv_within_at x H\u27e9,\n  have A : f = iso.symm \u2218 (iso \u2218 f), by { rw [\u2190 function.comp.assoc, iso.symm_comp_self], refl },\n  have B : f' = (iso.symm : F \u2192L[\ud835\udd5c] E).comp ((iso : E \u2192L[\ud835\udd5c] F).comp f'),\n    by rw [\u2190 continuous_linear_map.comp_assoc, iso.coe_symm_comp_coe,\n             continuous_linear_map.id_comp],\n  rw [A, B],\n  exact iso.symm.has_fderiv_at.comp_has_fderiv_within_at x H\nend\n\nlemma comp_has_strict_fderiv_at_iff {f : G \u2192 E} {x : G} {f' : G \u2192L[\ud835\udd5c] E} :\n  has_strict_fderiv_at (iso \u2218 f) ((iso : E \u2192L[\ud835\udd5c] F).comp f') x \u2194 has_strict_fderiv_at f f' x :=\nbegin\n  refine \u27e8\u03bb H, _, \u03bb H, iso.has_strict_fderiv_at.comp x H\u27e9,\n  convert iso.symm.has_strict_fderiv_at.comp x H; ext z; apply (iso.symm_apply_apply _).symm\nend\n\nlemma comp_has_fderiv_at_iff {f : G \u2192 E} {x : G} {f' : G \u2192L[\ud835\udd5c] E} :\n  has_fderiv_at (iso \u2218 f) ((iso : E \u2192L[\ud835\udd5c] F).comp f') x \u2194 has_fderiv_at f f' x :=\nby rw [\u2190 has_fderiv_within_at_univ, \u2190 has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff]\n\nlemma comp_has_fderiv_within_at_iff'\n  {f : G \u2192 E} {s : set G} {x : G} {f' : G \u2192L[\ud835\udd5c] F} :\n  has_fderiv_within_at (iso \u2218 f) f' s x \u2194\n  has_fderiv_within_at f ((iso.symm : F \u2192L[\ud835\udd5c] E).comp f') s x :=\nby rw [\u2190 iso.comp_has_fderiv_within_at_iff, \u2190 continuous_linear_map.comp_assoc,\n  iso.coe_comp_coe_symm, continuous_linear_map.id_comp]\n\nlemma comp_has_fderiv_at_iff' {f : G \u2192 E} {x : G} {f' : G \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at (iso \u2218 f) f' x \u2194 has_fderiv_at f ((iso.symm : F \u2192L[\ud835\udd5c] E).comp f') x :=\nby rw [\u2190 has_fderiv_within_at_univ, \u2190 has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff']\n\nlemma comp_fderiv_within {f : G \u2192 E} {s : set G} {x : G}\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (iso \u2218 f) s x = (iso : E \u2192L[\ud835\udd5c] F).comp (fderiv_within \ud835\udd5c f s x) :=\nbegin\n  by_cases h : differentiable_within_at \ud835\udd5c f s x,\n  { rw [fderiv.comp_fderiv_within x iso.differentiable_at h hxs, iso.fderiv] },\n  { have : \u00acdifferentiable_within_at \ud835\udd5c (iso \u2218 f) s x,\n      from mt iso.comp_differentiable_within_at_iff.1 h,\n    rw [fderiv_within_zero_of_not_differentiable_within_at h,\n        fderiv_within_zero_of_not_differentiable_within_at this,\n        continuous_linear_map.comp_zero] }\nend\n\nlemma comp_fderiv {f : G \u2192 E} {x : G} :\n  fderiv \ud835\udd5c (iso \u2218 f) x = (iso : E \u2192L[\ud835\udd5c] F).comp (fderiv \ud835\udd5c f x) :=\nbegin\n  rw [\u2190 fderiv_within_univ, \u2190 fderiv_within_univ],\n  exact iso.comp_fderiv_within unique_diff_within_at_univ,\nend\n\nend continuous_linear_equiv\n\nnamespace linear_isometry_equiv\n/-! ### Differentiability of linear isometry equivs, and invariance of differentiability -/\n\nvariable (iso : E \u2243\u2097\u1d62[\ud835\udd5c] F)\n\nprotected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E \u2192L[\ud835\udd5c] F) x :=\n(iso : E \u2243L[\ud835\udd5c] F).has_strict_fderiv_at\n\nprotected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E \u2192L[\ud835\udd5c] F) s x :=\n(iso : E \u2243L[\ud835\udd5c] F).has_fderiv_within_at\n\nprotected lemma has_fderiv_at : has_fderiv_at iso (iso : E \u2192L[\ud835\udd5c] F) x :=\n(iso : E \u2243L[\ud835\udd5c] F).has_fderiv_at\n\nprotected lemma differentiable_at : differentiable_at \ud835\udd5c iso x :=\niso.has_fderiv_at.differentiable_at\n\nprotected lemma differentiable_within_at :\n  differentiable_within_at \ud835\udd5c iso s x :=\niso.differentiable_at.differentiable_within_at\n\nprotected lemma fderiv : fderiv \ud835\udd5c iso x = iso := iso.has_fderiv_at.fderiv\n\nprotected lemma fderiv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c iso s x = iso :=\n(iso : E \u2243L[\ud835\udd5c] F).fderiv_within hxs\n\nprotected lemma differentiable : differentiable \ud835\udd5c iso :=\n\u03bbx, iso.differentiable_at\n\nprotected lemma differentiable_on : differentiable_on \ud835\udd5c iso s :=\niso.differentiable.differentiable_on\n\nlemma comp_differentiable_within_at_iff {f : G \u2192 E} {s : set G} {x : G} :\n  differentiable_within_at \ud835\udd5c (iso \u2218 f) s x \u2194 differentiable_within_at \ud835\udd5c f s x :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_differentiable_within_at_iff\n\nlemma comp_differentiable_at_iff {f : G \u2192 E} {x : G} :\n  differentiable_at \ud835\udd5c (iso \u2218 f) x \u2194 differentiable_at \ud835\udd5c f x :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_differentiable_at_iff\n\nlemma comp_differentiable_on_iff {f : G \u2192 E} {s : set G} :\n  differentiable_on \ud835\udd5c (iso \u2218 f) s \u2194 differentiable_on \ud835\udd5c f s :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_differentiable_on_iff\n\nlemma comp_differentiable_iff {f : G \u2192 E} :\n  differentiable \ud835\udd5c (iso \u2218 f) \u2194 differentiable \ud835\udd5c f :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_differentiable_iff\n\nlemma comp_has_fderiv_within_at_iff\n  {f : G \u2192 E} {s : set G} {x : G} {f' : G \u2192L[\ud835\udd5c] E} :\n  has_fderiv_within_at (iso \u2218 f) ((iso : E \u2192L[\ud835\udd5c] F).comp f') s x \u2194 has_fderiv_within_at f f' s x :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_has_fderiv_within_at_iff\n\nlemma comp_has_strict_fderiv_at_iff {f : G \u2192 E} {x : G} {f' : G \u2192L[\ud835\udd5c] E} :\n  has_strict_fderiv_at (iso \u2218 f) ((iso : E \u2192L[\ud835\udd5c] F).comp f') x \u2194 has_strict_fderiv_at f f' x :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_has_strict_fderiv_at_iff\n\nlemma comp_has_fderiv_at_iff {f : G \u2192 E} {x : G} {f' : G \u2192L[\ud835\udd5c] E} :\n  has_fderiv_at (iso \u2218 f) ((iso : E \u2192L[\ud835\udd5c] F).comp f') x \u2194 has_fderiv_at f f' x :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_has_fderiv_at_iff\n\nlemma comp_has_fderiv_within_at_iff'\n  {f : G \u2192 E} {s : set G} {x : G} {f' : G \u2192L[\ud835\udd5c] F} :\n  has_fderiv_within_at (iso \u2218 f) f' s x \u2194\n  has_fderiv_within_at f ((iso.symm : F \u2192L[\ud835\udd5c] E).comp f') s x :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_has_fderiv_within_at_iff'\n\nlemma comp_has_fderiv_at_iff' {f : G \u2192 E} {x : G} {f' : G \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at (iso \u2218 f) f' x \u2194 has_fderiv_at f ((iso.symm : F \u2192L[\ud835\udd5c] E).comp f') x :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_has_fderiv_at_iff'\n\nlemma comp_fderiv_within {f : G \u2192 E} {s : set G} {x : G}\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (iso \u2218 f) s x = (iso : E \u2192L[\ud835\udd5c] F).comp (fderiv_within \ud835\udd5c f s x) :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_fderiv_within hxs\n\nlemma comp_fderiv {f : G \u2192 E} {x : G} :\n  fderiv \ud835\udd5c (iso \u2218 f) x = (iso : E \u2192L[\ud835\udd5c] F).comp (fderiv \ud835\udd5c f x) :=\n(iso : E \u2243L[\ud835\udd5c] F).comp_fderiv\n\nend linear_isometry_equiv\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'\u207b\u00b9` at `a`\nin the strict sense.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have an\ninverse function. -/\ntheorem has_strict_fderiv_at.of_local_left_inverse {f : E \u2192 F} {f' : E \u2243L[\ud835\udd5c] F} {g : F \u2192 E} {a : F}\n  (hg : continuous_at g a) (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) (g a))\n  (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n  has_strict_fderiv_at g (f'.symm : F \u2192L[\ud835\udd5c] E) a :=\nbegin\n  replace hg := hg.prod_map' hg,\n  replace hfg := hfg.prod_mk_nhds hfg,\n  have : is_O (\u03bb p : F \u00d7 F, g p.1 - g p.2 - f'.symm (p.1 - p.2))\n    (\u03bb p : F \u00d7 F, f' (g p.1 - g p.2) - (p.1 - p.2)) (\ud835\udcdd (a, a)),\n  { refine ((f'.symm : F \u2192L[\ud835\udd5c] E).is_O_comp _ _).congr (\u03bb x, _) (\u03bb _, rfl),\n    simp },\n  refine this.trans_is_o _, clear this,\n  refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _)\n    (eventually_of_forall $ \u03bb _, rfl)).trans_is_O _,\n  { rintros p \u27e8hp1, hp2\u27e9,\n    simp [hp1, hp2] },\n  { refine (hf.is_O_sub_rev.comp_tendsto hg).congr'\n      (eventually_of_forall $ \u03bb _, rfl) (hfg.mono _),\n    rintros p \u27e8hp1, hp2\u27e9,\n    simp only [(\u2218), hp1, hp2] }\nend\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a`, then `g` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\ntheorem has_fderiv_at.of_local_left_inverse {f : E \u2192 F} {f' : E \u2243L[\ud835\udd5c] F} {g : F \u2192 E} {a : F}\n  (hg : continuous_at g a) (hf : has_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) (g a))\n  (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n  has_fderiv_at g (f'.symm : F \u2192L[\ud835\udd5c] E) a :=\nbegin\n  have : is_O (\u03bb x : F, g x - g a - f'.symm (x - a)) (\u03bb x : F, f' (g x - g a) - (x - a)) (\ud835\udcdd a),\n  { refine ((f'.symm : F \u2192L[\ud835\udd5c] E).is_O_comp _ _).congr (\u03bb x, _) (\u03bb _, rfl),\n    simp },\n  refine this.trans_is_o _, clear this,\n  refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _)\n    (eventually_of_forall $ \u03bb _, rfl)).trans_is_O _,\n  { rintros p hp,\n    simp [hp, hfg.self_of_nhds] },\n  { refine (hf.is_O_sub_rev.comp_tendsto hg).congr'\n      (eventually_of_forall $ \u03bb _, rfl) (hfg.mono _),\n    rintros p hp,\n    simp only [(\u2218), hp, hfg.self_of_nhds] }\nend\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an\ninvertible derivative `f'` in the sense of strict differentiability at `f.symm a`, then `f.symm` has\nthe derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\nlemma local_homeomorph.has_strict_fderiv_at_symm (f : local_homeomorph E F) {f' : E \u2243L[\ud835\udd5c] F} {a : F}\n  (ha : a \u2208 f.target) (htff' : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) (f.symm a)) :\n  has_strict_fderiv_at f.symm (f'.symm : F \u2192L[\ud835\udd5c] E) a :=\nhtff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha)\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an\ninvertible derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\nlemma local_homeomorph.has_fderiv_at_symm (f : local_homeomorph E F) {f' : E \u2243L[\ud835\udd5c] F} {a : F}\n  (ha : a \u2208 f.target) (htff' : has_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) (f.symm a)) :\n  has_fderiv_at f.symm (f'.symm : F \u2192L[\ud835\udd5c] E) a :=\nhtff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha)\n\nlemma has_fderiv_within_at.eventually_ne (h : has_fderiv_within_at f f' s x)\n  (hf' : \u2203 C, \u2200 z, \u2225z\u2225 \u2264 C * \u2225f' z\u2225) :\n  \u2200\u1da0 z in \ud835\udcdd[s \\ {x}] x, f z \u2260 f x :=\nbegin\n  rw [nhds_within, diff_eq, \u2190 inf_principal, \u2190 inf_assoc, eventually_inf_principal],\n  have A : is_O (\u03bb z, z - x) (\u03bb z, f' (z - x)) (\ud835\udcdd[s] x) :=\n    (is_O_iff.2 $ hf'.imp $ \u03bb C hC, eventually_of_forall $ \u03bb z, hC _),\n  have : (\u03bb z, f z - f x) ~[\ud835\udcdd[s] x] (\u03bb z, f' (z - x)) := h.trans_is_O A,\n  simpa [not_imp_not, sub_eq_zero] using (A.trans this.is_O_symm).eq_zero_imp\nend\n\nlemma has_fderiv_at.eventually_ne (h : has_fderiv_at f f' x) (hf' : \u2203 C, \u2200 z, \u2225z\u2225 \u2264 C * \u2225f' z\u2225) :\n  \u2200\u1da0 z in \ud835\udcdd[{x}\u1d9c] x, f z \u2260 f x :=\nby simpa only [compl_eq_univ_diff] using (has_fderiv_within_at_univ.2 h).eventually_ne hf'\n\nend\n\nsection\n/-\n  In the special case of a normed space over the reals,\n  we can use  scalar multiplication in the `tendsto` characterization\n  of the Fr\u00e9chet derivative.\n-/\n\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E]\nvariables {F : Type*} [normed_group F] [normed_space \u211d F]\nvariables {f : E \u2192 F} {f' : E \u2192L[\u211d] F} {x : E}\n\ntheorem has_fderiv_at_filter_real_equiv {L : filter E} :\n  tendsto (\u03bb x' : E, \u2225x' - x\u2225\u207b\u00b9 * \u2225f x' - f x - f' (x' - x)\u2225) L (\ud835\udcdd 0) \u2194\n  tendsto (\u03bb x' : E, \u2225x' - x\u2225\u207b\u00b9 \u2022 (f x' - f x - f' (x' - x))) L (\ud835\udcdd 0) :=\nbegin\n  symmetry,\n  rw [tendsto_iff_norm_tendsto_zero], refine tendsto_congr (\u03bb x', _),\n  have : \u2225x' - x\u2225\u207b\u00b9 \u2265 0, from inv_nonneg.mpr (norm_nonneg _),\n  simp [norm_smul, real.norm_eq_abs, abs_of_nonneg this]\nend\n\nlemma has_fderiv_at.lim_real (hf : has_fderiv_at f f' x) (v : E) :\n  tendsto (\u03bb (c:\u211d), c \u2022 (f (x + c\u207b\u00b9 \u2022 v) - f x)) at_top (\ud835\udcdd (f' v)) :=\nbegin\n  apply hf.lim v,\n  rw tendsto_at_top_at_top,\n  exact \u03bb b, \u27e8b, \u03bb a ha, le_trans ha (le_abs_self _)\u27e9\nend\n\nend\n\nsection tangent_cone\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\n{f : E \u2192 F} {s : set E} {f' : E \u2192L[\ud835\udd5c] F}\n\n/-- The image of a tangent cone under the differential of a map is included in the tangent cone to\nthe image. -/\nlemma has_fderiv_within_at.maps_to_tangent_cone {x : E} (h : has_fderiv_within_at f f' s x) :\n  maps_to f' (tangent_cone_at \ud835\udd5c s x) (tangent_cone_at \ud835\udd5c (f '' s) (f x)) :=\nbegin\n  rintros v \u27e8c, d, dtop, clim, cdlim\u27e9,\n  refine \u27e8c, (\u03bbn, f (x + d n) - f x), mem_sets_of_superset dtop _, clim,\n    h.lim at_top dtop clim cdlim\u27e9,\n  simp [-mem_image, mem_image_of_mem] {contextual := tt}\nend\n\n/-- If a set has the unique differentiability property at a point x, then the image of this set\nunder a map with onto derivative has also the unique differentiability property at the image point.\n-/\nlemma has_fderiv_within_at.unique_diff_within_at {x : E} (h : has_fderiv_within_at f f' s x)\n  (hs : unique_diff_within_at \ud835\udd5c s x) (h' : dense_range f') :\n  unique_diff_within_at \ud835\udd5c (f '' s) (f x) :=\nbegin\n  refine \u27e8h'.dense_of_maps_to f'.continuous hs.1 _,\n    h.continuous_within_at.mem_closure_image hs.2\u27e9,\n  show submodule.span \ud835\udd5c (tangent_cone_at \ud835\udd5c s x) \u2264\n    (submodule.span \ud835\udd5c (tangent_cone_at \ud835\udd5c (f '' s) (f x))).comap f',\n  rw [submodule.span_le],\n  exact h.maps_to_tangent_cone.mono (subset.refl _) submodule.subset_span\nend\n\nlemma unique_diff_on.image {f' : E \u2192 E \u2192L[\ud835\udd5c] F} (hs : unique_diff_on \ud835\udd5c s)\n  (hf' : \u2200 x \u2208 s, has_fderiv_within_at f (f' x) s x) (hd : \u2200 x \u2208 s, dense_range (f' x)) :\n  unique_diff_on \ud835\udd5c (f '' s) :=\nball_image_iff.2 $ \u03bb x hx, (hf' x hx).unique_diff_within_at (hs x hx) (hd x hx)\n\nlemma has_fderiv_within_at.unique_diff_within_at_of_continuous_linear_equiv\n  {x : E} (e' : E \u2243L[\ud835\udd5c] F) (h : has_fderiv_within_at f (e' : E \u2192L[\ud835\udd5c] F) s x)\n  (hs : unique_diff_within_at \ud835\udd5c s x) :\n  unique_diff_within_at \ud835\udd5c (f '' s) (f x) :=\nh.unique_diff_within_at hs e'.surjective.dense_range\n\nlemma continuous_linear_equiv.unique_diff_on_image (e : E \u2243L[\ud835\udd5c] F) (h : unique_diff_on \ud835\udd5c s) :\n  unique_diff_on \ud835\udd5c (e '' s) :=\nh.image (\u03bb x _, e.has_fderiv_within_at) (\u03bb x hx, e.surjective.dense_range)\n\n@[simp] lemma continuous_linear_equiv.unique_diff_on_image_iff (e : E \u2243L[\ud835\udd5c] F) :\n  unique_diff_on \ud835\udd5c (e '' s) \u2194 unique_diff_on \ud835\udd5c s :=\n\u27e8\u03bb h, e.symm_image_image s \u25b8 e.symm.unique_diff_on_image h, e.unique_diff_on_image\u27e9\n\n@[simp] lemma continuous_linear_equiv.unique_diff_on_preimage_iff (e : F \u2243L[\ud835\udd5c] E) :\n  unique_diff_on \ud835\udd5c (e \u207b\u00b9' s) \u2194 unique_diff_on \ud835\udd5c s :=\nby rw [\u2190 e.image_symm_eq_preimage, e.symm.unique_diff_on_image_iff]\n\nend tangent_cone\n\nsection restrict_scalars\n/-!\n### Restricting from `\u2102` to `\u211d`, or generally from `\ud835\udd5c'` to `\ud835\udd5c`\n\nIf a function is differentiable over `\u2102`, then it is differentiable over `\u211d`. In this paragraph,\nwe give variants of this statement, in the general situation where `\u2102` and `\u211d` are replaced\nrespectively by `\ud835\udd5c'` and `\ud835\udd5c` where `\ud835\udd5c'` is a normed algebra over `\ud835\udd5c`.\n-/\n\nvariables (\ud835\udd5c : Type*) [nondiscrete_normed_field \ud835\udd5c]\nvariables {\ud835\udd5c' : Type*} [nondiscrete_normed_field \ud835\udd5c'] [normed_algebra \ud835\udd5c \ud835\udd5c']\nvariables {E : Type*} [normed_group E] [normed_space \ud835\udd5c E] [normed_space \ud835\udd5c' E]\nvariables [is_scalar_tower \ud835\udd5c \ud835\udd5c' E]\nvariables {F : Type*} [normed_group F] [normed_space \ud835\udd5c F] [normed_space \ud835\udd5c' F]\nvariables [is_scalar_tower \ud835\udd5c \ud835\udd5c' F]\nvariables {f : E \u2192 F} {f' : E \u2192L[\ud835\udd5c'] F} {s : set E} {x : E}\n\nlemma has_strict_fderiv_at.restrict_scalars (h : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at f (f'.restrict_scalars \ud835\udd5c) x := h\n\nlemma has_fderiv_at.restrict_scalars (h : has_fderiv_at f f' x) :\n  has_fderiv_at f (f'.restrict_scalars \ud835\udd5c) x := h\n\nlemma has_fderiv_within_at.restrict_scalars (h : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at f (f'.restrict_scalars \ud835\udd5c) s x := h\n\nlemma differentiable_at.restrict_scalars (h : differentiable_at \ud835\udd5c' f x) :\n  differentiable_at \ud835\udd5c f x :=\n(h.has_fderiv_at.restrict_scalars \ud835\udd5c).differentiable_at\n\nlemma differentiable_within_at.restrict_scalars (h : differentiable_within_at \ud835\udd5c' f s x) :\n  differentiable_within_at \ud835\udd5c f s x :=\n(h.has_fderiv_within_at.restrict_scalars \ud835\udd5c).differentiable_within_at\n\nlemma differentiable_on.restrict_scalars (h : differentiable_on \ud835\udd5c' f s) :\n  differentiable_on \ud835\udd5c f s :=\n\u03bbx hx, (h x hx).restrict_scalars \ud835\udd5c\n\nlemma differentiable.restrict_scalars (h : differentiable \ud835\udd5c' f) :\n  differentiable \ud835\udd5c f :=\n\u03bbx, (h x).restrict_scalars \ud835\udd5c\n\nend restrict_scalars\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/calculus/fderiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7353488535111605}}
{"text": "/-\n# Formalising *Principles of Mathematical Analysis* (Walter Rudin) in Lean\n\nI will be using the mathlib version of `nat`, `int`, `rat` and `real` here...\n\nNote that they are defined differently from those in IUM:\n\n* The integers are defined as an inductive type with two constructors (nonneg, neg);\n* The rationals are defined as an inductive type holding the numerator and denominator;\n* The reals are defined as equivalence classes of Cauchy sequences.\n-/\n\nimport data.nat.basic\nimport data.int.basic\nimport data.rat.basic\nimport data.real.basic\nimport data.complex.basic\nimport data.list\n\nimport tactic\nimport tactic.rewrite_search.frontend\n\nnoncomputable theory\n\n--------------------------------------------------------------------------------\n-- **The real field** in Lean\n\nsection\n  variables (x y z : \u211d)\n  variables (S : set \u211d)\n\n  #check real.field\n  #check real.linear_order\n  #check real.linear_ordered_field\n\n-- Field axioms\n  #check add_assoc x y z                --  x + y + z = x + (y + z)\n  #check add_zero x                     --/ x + 0 = x\n  #check zero_add x                     --\\ 0 + x = x\n  #check add_right_neg x                --/ x + -x = 0\n  #check add_left_neg x                 --\\ -x + x = 0\n  #check add_comm x y                   --  x + y = y + x\n\n  #check mul_assoc x y z                --  x * y * z = x * (y * z)\n  #check @zero_ne_one \u211d _ _             --/ 0 \u2260 1\n  #check @one_ne_zero \u211d _ _             --\\ 1 \u2260 0\n  #check mul_one x                      --/ x * 1 = x\n  #check one_mul x                      --\\ 1 * x = x\n  #check @mul_inv_cancel _ _ x          --/ x \u2260 0 \u2192 x * x\u207b\u00b9 = 1\n  #check @inv_mul_cancel _ _ x          --\\ x \u2260 0 \u2192 x\u207b\u00b9 * x = 1\n  #check mul_comm x y                   --  x * y = y * x\n\n  #check mul_add x y z                  --/ x * (y + z) = x * y + x * z\n  #check add_mul x y z                  --\\ (x + y) * z = x * z + y * z\n\n-- Conversion between lt and le\n  #check @le_iff_lt_or_eq _ _ x y       --/ x \u2264 y \u2194 x < y \u2228 x = y\n  #check @lt_iff_le_and_ne _ _ x y      --\\ x < y \u2194 x \u2264 y \u2227 x \u2260 y\n\n-- Total order axioms (lt)\n  #check lt_irrefl x                    --  \u00acx < x\n  #check @lt_trans _ _ x y z            --  x < y \u2192 y < z \u2192 x < z\n  #check lt_trichotomy x y              --  x < y \u2228 x = y \u2228 y < x\n-- Ordered field axioms (lt)\n  #check @add_lt_add_right _ _ _ _ x y  --/ x < y \u2192 \u2200 (z : \u211d), x + z < y + z\n  #check @add_lt_add_left _ _ _ _ y z   --\\ y < z \u2192 \u2200 (x : \u211d), x + y < x + z\n  #check @mul_pos _ _ x y               --  0 < x \u2192 0 < y \u2192 0 < x * y\n\n-- Total order axioms (le)\n  #check le_refl x                      --  x \u2264 x\n  #check @le_trans _ _ x y z            --  x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z\n  #check @le_antisymm _ _ x y           --  x \u2264 y \u2192 y \u2264 x \u2192 x = y\n  #check le_total x y                   --  x \u2264 y \u2228 y \u2264 x\n-- Ordered field axioms (le)\n  #check @add_le_add_right _ _ _ _ x y  --/ x \u2264 y \u2192 \u2200 (z : \u211d), x + z \u2264 y + z\n  #check @add_le_add_left _ _ _ _ y z   --\\ y \u2264 z \u2192 \u2200 (x : \u211d), x + y \u2264 x + z\n  #check @mul_nonneg _ _ x y            --  0 \u2264 x \u2192 0 \u2264 y \u2192 0 \u2264 x * y\n\n-- Completeness axiom (existence & uniqueness of supremum)\n  #check real.has_Sup\n  #check Sup (\u03bb x : \u211d, x < 1)           --  \u211d (noncomputable?)\n  #check real.is_lub_Sup S              --  S.nonempty \u2192 bdd_above S \u2192 is_lub S (Sup S)\n\n-- Miscellaneous\n-- Conversion between minus and negation\n  #check sub_eq_add_neg x y             --  x - y = x + -y  (also def eq)\n-- Conversion between division and inverse\n  #check div_eq_mul_inv x y             --  x / y = x * y\u207b\u00b9 (also def eq)\n-- \"smul by integer\" as repeated addition\n  #check nsmul 3 x                      --  \u211d (noncomputable?)\n  #check gsmul (-3) x                   --  \u211d (noncomputable?)\n-- \"pow by integer\" as repeated multiplication\n  #check npow 3 x                       --  \u211d (noncomputable?)\n  #check gpow (-3) x                    --  \u211d (noncomputable?)\n-- Maximum and minimum (?)\nend\n\n--------------------------------------------------------------------------------\n-- **The complex field** in Lean\n\nsection\n  variables (x y z : \u2102)\n  variables (a b c d : \u211d)\n\n  #check complex.field\n\n-- Definition as a structure with two \u211d's\n-- Constructor\n  #reduce complex.mk a b\n  #reduce (\u27e8a, b\u27e9 : \u2102)\n-- Projectors\n  #check x.re                           --  \u211d\n  #check x.im                           --  \u211d\n-- Operations and identity elements\n  example :  (\u27e8a, b\u27e9 : \u2102) + (\u27e8c, d\u27e9 : \u2102) = \u27e8a + c, b + d\u27e9 := rfl\n  example : -(\u27e8a, b\u27e9 : \u2102)                = \u27e8-a, -b\u27e9       := rfl\n  example :       (0 : \u2102)                = \u27e80, 0\u27e9         := rfl\n  example :  (\u27e8a, b\u27e9 : \u2102) * (\u27e8c, d\u27e9 : \u2102) = \u27e8a * c - b * d, a * d + b * c\u27e9 := rfl\n  example :  (\u27e8a, b\u27e9 : \u2102)\u207b\u00b9              = \u27e8a, -b\u27e9 * \u2191((a * a + b * b)\u207b\u00b9) := rfl\n  example :       (1 : \u2102)                = \u27e81, 0\u27e9         := rfl\n  example :  (\u27e8a, b\u27e9 : \u2102).conj           = \u27e8a, -b\u27e9        := rfl\n\n-- Field axioms\n  #check add_assoc x y z                --  x + y + z = x + (y + z)\n  #check add_zero x                     --/ x + 0 = x\n  #check zero_add x                     --\\ 0 + x = x\n  #check add_right_neg x                --/ x + -x = 0\n  #check add_left_neg x                 --\\ -x + x = 0\n  #check add_comm x y                   --  x + y = y + x\n\n  #check mul_assoc x y z                --  x * y * z = x * (y * z)\n  #check @zero_ne_one \u211d _ _             --/ 0 \u2260 1\n  #check @one_ne_zero \u211d _ _             --\\ 1 \u2260 0\n  #check mul_one x                      --/ x * 1 = x\n  #check one_mul x                      --\\ 1 * x = x\n  #check @mul_inv_cancel _ _ x          --/ x \u2260 0 \u2192 x * x\u207b\u00b9 = 1\n  #check @inv_mul_cancel _ _ x          --\\ x \u2260 0 \u2192 x\u207b\u00b9 * x = 1\n  #check mul_comm x y                   --  x * y = y * x\n\n  #check mul_add x y z                  --/ x * (y + z) = x * y + x * z\n  #check add_mul x y z                  --\\ (x + y) * z = x * z + y * z\n\n-- Miscellaneous\n-- Conversion between minus and negation\n  #check sub_eq_add_neg x y             --  x - y = x + -y  (also def eq)\n-- Conversion between division and inverse\n  #check div_eq_mul_inv x y             --  x / y = x * y\u207b\u00b9 (also def eq)\n-- \"smul by integer\" as repeated addition\n  #check nsmul 3 x                      --  \u211d (noncomputable?)\n  #check gsmul (-3) x                   --  \u211d (noncomputable?)\n-- \"pow by integer\" as repeated multiplication\n  #check npow 3 x                       --  \u211d (noncomputable?)\n  #check gpow (-3) x                    --  \u211d (noncomputable?)\n-- Imaginary unit\n  example : complex.I = \u27e80, 1\u27e9 := rfl\nend\n\nnamespace notes\n\n--------------------------------------------------------------------------------\n-- **Ordered sets**\n\nsection\n\n  def is_upper_bound {\u03b1 : Type} [linear_order \u03b1] (E : set \u03b1) (a : \u03b1) : Prop :=\n    \u2200 e, e \u2208 E \u2192 e \u2264 a\n  \n  def is_lower_bound {\u03b1 : Type} [linear_order \u03b1] (E : set \u03b1) (a : \u03b1) : Prop :=\n    \u2200 e, e \u2208 E \u2192 a \u2264 e\n\n  @[class]\n  structure bounded_above {\u03b1 : Type} [linear_order \u03b1] (E : set \u03b1) : Type :=\n    mk :: (a : \u03b1) (h : is_upper_bound E a)\n  \n  @[class]\n  structure bounded_below {\u03b1 : Type} [linear_order \u03b1] (E : set \u03b1) : Type :=\n    mk :: (a : \u03b1) (h : is_lower_bound E a)\n\n-- (TODO: complete)\n\nend\n\n--------------------------------------------------------------------------------\n-- **Fields**\n-- The following can be done using `simp` or `norm_num` (or even `library_search`!)\n-- I did most by hand just to gain familiarity with field axioms (and their Lean names...)\n\n-- (It would be better if we had an UI that completely avoids the use of \"names\" to refer to theorems...\n--  i.e. use type ascriptions only, relying more heavily on library_search and unification algorithms)\n\nsection\n\n  variables (\u03b1 : Type) [field \u03b1]\n  variables (x y z : \u03b1)\n\n  section propositions_1_14\n\n    #check @add_left_cancel _ _ x y z           -- x + y = x + z \u2192 y = z\n    #check @add_right_cancel _ _ x y z          -- x + y = z + y \u2192 x = z\n    example : x + y = x + z \u2192 y = z := by\n    { intros h,\n      calc  y\n          = -x + (x + y) : by rw [\u2190 add_assoc, add_left_neg, zero_add]\n      ... = -x + (x + z) : by rw h\n      ... = z            : by rw [\u2190 add_assoc, add_left_neg, zero_add] }\n\n    example : x + y = x \u2192 y = 0 := by\n    { intros h,\n      calc  y\n          = -x + (x + y) : by rw [\u2190 add_assoc, add_left_neg, zero_add]\n      ... = -x + x       : by rw h\n      ... = 0            : by rw add_left_neg }\n\n    example : x + y = 0 \u2192 y = -x := by\n    { intros h,\n      calc  y\n          = -x + (x + y) : by rw [\u2190 add_assoc, add_left_neg, zero_add]\n      ... = -x           : by rw [h, add_zero] }\n\n    #check neg_neg x                            -- -(-x) = x\n    example : -(-x) = x := by\n    { calc  -(-x)\n          = x + -x + -(-x) : by rw [add_right_neg, zero_add]\n      ... = x              : by rw [add_assoc, add_right_neg, add_zero] }\n\n  end propositions_1_14\n\n  section propositions_1_15\n\n    #check @mul_left_cancel\u2080 _ _ x y z          -- x \u2260 0 \u2192 x * y = x * z \u2192 y = z\n    #check @mul_right_cancel\u2080 _ _ x y z         -- y \u2260 0 \u2192 x * y = z * y \u2192 x = z\n    example : x \u2260 0 \u2192 x * y = x * z \u2192 y = z := by\n    { intros hx h,\n      calc  y\n          = x\u207b\u00b9 * (x * y) : by rw [\u2190 mul_assoc, inv_mul_cancel hx, one_mul]\n      ... = x\u207b\u00b9 * (x * z) : by rw h\n      ... = z             : by rw [\u2190 mul_assoc, inv_mul_cancel hx, one_mul] }\n\n    example : x \u2260 0 \u2192 x * y = x \u2192 y = 1 := by\n    { intros hx h,\n      calc  y\n          = x\u207b\u00b9 * (x * y) : by rw [\u2190 mul_assoc, inv_mul_cancel hx, one_mul]\n      ... = x\u207b\u00b9 * x       : by rw h\n      ... = 1             : by rw [inv_mul_cancel hx] }\n\n    example : x \u2260 0 \u2192 x * y = 1 \u2192 y = x\u207b\u00b9 := by\n    { intros hx h,\n      calc  y\n          = x\u207b\u00b9 * (x * y) : by rw [\u2190 mul_assoc, inv_mul_cancel hx, one_mul]\n      ... = x\u207b\u00b9           : by rw [h, mul_one] }\n\n    #check inv_inv\u2080 x                           -- x\u207b\u00b9\u207b\u00b9 = x\n    example : x \u2260 0 \u2192 x\u207b\u00b9\u207b\u00b9 = x := by\n    { intros hx,\n      calc  x\u207b\u00b9\u207b\u00b9\n          = x * x\u207b\u00b9 * x\u207b\u00b9\u207b\u00b9 : by rw [mul_inv_cancel hx, one_mul]\n      ... = x               : by simp [hx] }    -- tql (alternatively, prove x\u207b\u00b9 = 0 \u2192 false by x * x\u207b\u00b9 = 0 = 1)\n\n  end propositions_1_15\n\n  section propositions_1_16\n\n    #check zero_mul x                           -- 0 * x = 0\n    #check mul_zero x                           -- x * 0 = 0\n    example : 0 * x = 0 := by\n    { calc  0 * x\n          = 0 * x + 1 * x + -(1 * x) : by rw [add_assoc, add_right_neg, add_zero]\n      ... = (0 + 1) * x + -(1 * x)   : by rw add_mul\n      ... = 0                        : by rw [zero_add, add_right_neg] }\n\n    #check @mul_ne_zero _ _ _ x y               -- x \u2260 0 \u2192 y \u2260 0 \u2192 x * y \u2260 0\n    example : x \u2260 0 \u2192 y \u2260 0 \u2192 x * y \u2260 0 := by\n    { intros hx hy h,\n      have : (1 : \u03b1) = 0,\n      { calc  1\n            = x\u207b\u00b9 * x * (y\u207b\u00b9 * y) : by rw [inv_mul_cancel hx, inv_mul_cancel hy, mul_one]\n        ... = x\u207b\u00b9 * y\u207b\u00b9 * (x * y) : by rw [mul_assoc, \u2190 mul_assoc x, mul_comm x, mul_assoc y\u207b\u00b9, \u2190 mul_assoc]\n        ... = 0                   : by rw [h, mul_zero] },\n      exact one_ne_zero this }\n\n    #check neg_eq_neg_one_mul x                 -- -x = -1 * x\n    example : -x = -1 * x := by\n    { calc  -x\n          = -x + (1 + -1) * x : by rw [add_right_neg, zero_mul, add_zero]\n      ... = -x + x + -1 * x   : by rw [add_mul, one_mul, \u2190 add_assoc]\n      ... = -1 * x            : by rw [add_left_neg, zero_add] }\n\n    example : -x * y = -(x * y) := by\n    { calc  -x * y\n          = -1 * x * y : by simp\n      ... = -(x * y)   : by simp }\n\n    example : x * -y = -(x * y) := by\n    { calc  x * -y\n          = x * -1 * y : by simp\n      ... = -1 * x * y : by simp\n      ... = -(x * y)   : by simp }\n\n    example : -x * -y = x * y := by\n    { calc  -x * -y\n          = -1 * x * -1 * y : by simp\n      ... = -(-1) * x * y   : by simp\n      ... = x * y           : by simp }\n\n  end propositions_1_16\n\nend\n\nsection\n\n  variables (\u03b1 : Type) [linear_ordered_field \u03b1]\n  variables (x y z : \u03b1)\n\n  section propositions_1_18\n\n    #check @neg_lt_zero _ _ _ _ x               -- -x < 0 \u2194 0 < x\n    example : 0 < x \u2194 -x < 0 := by\n    { split,\n      { intros h,\n        calc  -x\n            = -x + 0 : by rw add_zero\n        ... < -x + x : add_lt_add_left h (-x)\n        ... = 0      : by rw add_left_neg },\n      { intros h,\n        calc  0\n            = x + -x : by rw add_right_neg\n        ... < x + 0  : add_lt_add_left h x\n        ... = x      : by rw add_zero }}\n\n    #check @mul_lt_mul_left _ _ y z x           -- 0 < x \u2192 (x * y < x * z \u2194 y < z)\n    #check @mul_lt_mul_right _ _ y z x          -- 0 < x \u2192 (y * x < z * x \u2194 y < z)\n    example : 0 < x \u2192 y < z \u2192 x * y < x * z := by\n    { intros hx h,\n      let a := z + -y,\n      have ha : 0 < a,\n      { have := add_lt_add_right h (-y),\n        rw add_right_neg at this,\n        exact this },\n      have h\u2081 : x * y < x * y + x * a,\n      { have : 0 < x * a := mul_pos hx ha,\n        replace this := add_lt_add_left this (x * y),\n        rw add_zero at this,\n        exact this },\n      calc  x * y\n          < x * (y + a)        : by { rw mul_add, exact h\u2081 }\n      ... = x * (y + (z + -y)) : rfl\n      ... = x * z              : by { rw [add_comm z, \u2190 add_assoc, add_right_neg, zero_add] }}\n\n    #check @mul_lt_mul_left_of_neg _ _ y z x    -- x < 0 \u2192 (x * y < x * z \u2194 z < y)\n    #check @mul_lt_mul_right_of_neg _ _ y z x   -- x < 0 \u2192 (y * x < z * x \u2194 z < y)\n    example : x < 0 \u2192 y < z \u2192 x * z < x * y := by\n    { intros hx h,\n      let a := z + -y,\n      have ha : 0 < a,\n      { have := add_lt_add_right h (-y),\n        rw add_right_neg at this,\n        exact this },\n      have h\u2081 : x * y + x * a < x * y,\n      { have : 0 < -x * a,\n        { have hnx : 0 < -x,\n          { calc  0\n                = -x + x : by rw add_left_neg\n            ... < -x + 0 : add_lt_add_left hx (-x)\n            ... = -x     : by rw add_zero },\n          exact mul_pos hnx ha },\n        replace this := add_lt_add_left this (x * y),\n        rw add_zero at this,\n        replace this := add_lt_add_right this (x * a),\n        rw [add_assoc, \u2190 add_mul, add_left_neg, zero_mul, add_zero] at this,\n        exact this },\n      calc  x * z\n          = x * (y + (z + -y)) : by { rw [add_comm z, \u2190 add_assoc, add_right_neg, zero_add] }\n      ... = x * (y + a)        : rfl\n      ... < x * y              : by { rw mul_add, exact h\u2081 }}\n\n    #check @mul_self_pos _ _ x                  -- x \u2260 0 \u2192 0 < x * x\n    example : x \u2260 0 \u2192 0 < x * x := by\n    { intros hx',\n      rcases lt_trichotomy x 0 with (hx|hx|hx),\n      { have : x * 0 < x * x := (mul_lt_mul_left_of_neg hx).mpr hx,\n        rw mul_zero at this,\n        exact this },\n      { exfalso, exact hx' hx },\n      { have : x * 0 < x * x := (mul_lt_mul_left hx).mpr hx,\n        rw mul_zero at this,\n        exact this }}\n\n    #check zero_lt_one                          -- 0 < 1\n    #check neg_one_lt_zero                      -- -1 < 0\n    example : (0 : \u03b1) < 1 := by\n    { have : (0 : \u03b1) < 1 * 1 := mul_self_pos one_ne_zero,\n      rw mul_one at this,\n      exact this }\n\n    #check @inv_pos _ _ x                       -- 0 < x\u207b\u00b9 \u2194 0 < x\n    example : 0 < x \u2192 0 < x\u207b\u00b9 := by\n    { intros hx,\n      have hx\u2080 : x \u2260 0, { intros hx', rw hx' at hx, exact lt_irrefl 0 hx },\n      rcases lt_trichotomy x\u207b\u00b9 0 with (h|h|h),\n      { exfalso,\n        have := (mul_lt_mul_left hx).mpr h,\n        rw [mul_inv_cancel hx\u2080, mul_zero] at this,\n        exact lt_irrefl _ (lt_trans zero_lt_one this) },\n      { exfalso,\n        have : x * x\u207b\u00b9 = 0, { rw [h, mul_zero] },\n        rw mul_inv_cancel hx\u2080 at this,\n        exact one_ne_zero this },\n      { exact h }}\n\n-- example (hx : 0 < x) (h : x < y) : y\u207b\u00b9 < x\u207b\u00b9 := by library_search!\n    example : 0 < x \u2192 x < y \u2192 y\u207b\u00b9 < x\u207b\u00b9 := by\n    { intros hx h,\n      have hy := lt_trans hx h,\n      have := (mul_lt_mul_left (inv_pos.mpr hx)).mpr h,\n      rw inv_mul_cancel (\u03bb hx' : x = 0, by { rw hx' at hx, exact lt_irrefl _ hx }) at this,\n      replace this := (mul_lt_mul_right (inv_pos.mpr hy)).mpr this,\n      rw mul_assoc at this,\n      rw mul_inv_cancel (\u03bb hy' : y = 0, by { rw hy' at hy, exact lt_irrefl _ hy }) at this,\n      rw [one_mul, mul_one] at this,\n      exact this }\n\n  end propositions_1_18\n\n-- Some other useful lemmas\n  lemma le_iff_not_gt : x \u2264 y \u2194 \u00ac y < x := by\n  { split,\n    { intros h h',\n      rcases le_iff_lt_or_eq.mp h with (h\u2081|h\u2081),\n      { exact lt_irrefl _ (lt_trans h' h\u2081) }, { rw h\u2081 at h', exact lt_irrefl _ h' }},\n    { intros h,\n      apply le_iff_lt_or_eq.mpr,\n      rcases lt_trichotomy x y with (h\u2081|h\u2081|h\u2081),\n      { exact or.inl h\u2081 }, { exact or.inr h\u2081 }, { exfalso, exact h h\u2081 }}}\n  #check @lt_iff_not_ge _ _ x y                 -- x < y \u2194 \u00acy \u2264 x (def eq)\n  #check @le_iff_not_gt _ _ x y                 -- x \u2264 y \u2194 \u00acy < x\n\nend\n\n--------------------------------------------------------------------------------\n-- **The real field**\n\nsection\n-- (TODO: `has_coe \u211a \u211d`)\n\n  variables (x y z : \u211d)\n\n  #check real.archimedean.arch\n  theorem real.archimedean' : 0 < x \u2192 \u2203 n : \u2115, y < n \u2022 x := by\n-- Proof using the least-upper-bound property\n  { intros hx,\n    -- Assume otherwise...\n    by_contra,\n    -- Let A be the set of all nx's...\n    let A : set \u211d := (\u03bb z : \u211d, \u2203 n : \u2115, z = n \u2022 x),\n    -- Clearly A is nonempty, and bounded above by y...\n    have hne  : A.nonempty := \u27e81 \u2022 x, \u27e81, rfl\u27e9\u27e9,\n    have hbdd : bdd_above A,\n    { use y,\n      rintros z \u27e8n, hn\u27e9,\n      apply (le_iff_not_gt _ _ _).mpr,\n      intros hyz,\n      apply h, use n,\n      rw \u2190 hn, exact hyz },\n    -- So we let a := sup A...\n    let a := Sup A,\n    rcases (real.is_lub_Sup A hne hbdd) with \u27e8ha\u2081, ha\u2082\u27e9,\n    unfold lower_bounds at ha\u2082,\n    -- And let b := a - x...\n    let b := a + -x,\n    -- Then b < mx for some m : \u2115 (since a is least)...\n    have hb : \u2203 m : \u2115, b < m \u2022 x,\n    { by_contra,\n      have hb' : b \u2208 upper_bounds A,\n      { rintros z \u27e8mz, hz\u27e9,\n        apply (le_iff_not_gt _ _ _).mpr,\n        intros hbz,\n        apply h, use mz, rw \u2190 hz, exact hbz },\n      replace hb' := ha\u2082 hb',\n      change Sup A \u2264 Sup A - x at hb',\n      linarith only [hb', hx] },\n    rcases hb with \u27e8m, hb\u27e9,\n    -- Then a < (m + 1) x, contradiction (since a is upper bound)...\n    have h\u2081 : a < (m + 1) \u2022 x,\n    { rw [add_smul, one_smul],\n      have : a + -x < m \u2022 x + x + -x,\n      { rw [add_assoc, add_right_neg, add_zero], exact hb },\n      replace this := add_lt_add_right this x,\n      simp only [add_assoc, add_left_neg, add_zero] at this,\n      exact this },\n    have : (m + 1) \u2022 x \u2208 A := \u27e8m + 1, rfl\u27e9,\n    specialize ha\u2081 this,\n    change Sup A < (m + 1) \u2022 x at h\u2081,\n    linarith only [h\u2081, ha\u2081] }\n\n  theorem real.rat_dense' : x < y \u2192 \u2203 p : \u211a, x < \u2191p \u2227 \u2191p < y := by\n-- Proof using the Archimedean property\n  { intros h,\n    -- Since y - x > 0, we have an n : \u2115 such that n (y - x) > 1...\n    -- (1 / n < y - x will be our \"unit\")\n    have hyx : 0 < y + -x,\n    { have := add_lt_add_right h (-x),\n      rw add_right_neg at this,\n      exact this },\n    rcases real.archimedean' _ 1 hyx with \u27e8n, hn\u27e9,\n    -- Also, there are (m\u2081 m\u2082 : \u2115) such that -m\u2081 < nx < m\u2082...\n    rcases real.archimedean' 1 (-(n \u2022 x)) zero_lt_one with \u27e8m\u2081, hm\u2081\u27e9,\n    rw [nat.smul_one_eq_coe] at hm\u2081,\n    replace hm\u2081 : - \u2191m\u2081 < n \u2022 x,\n    { replace hm\u2081 := (mul_lt_mul_left_of_neg neg_one_lt_zero).mpr hm\u2081,\n      simp only [\u2190 neg_eq_neg_one_mul, neg_neg] at hm\u2081,\n      exact hm\u2081 },\n    rcases real.archimedean' 1 (n \u2022 x) zero_lt_one with \u27e8m\u2082, hm\u2082\u27e9,\n    rw [nat.smul_one_eq_coe] at hm\u2082,\n    -- So, there is an m : \u2124 such that m - 1 \u2264 nx < m...\n    let m : \u2124 := sorry,\n    have hml : \u2191(m + -1) \u2264 n \u2022 x := sorry,\n    have hmr : n \u2022 x < \u2191m        := sorry,\n    -- Then m \u2264 nx + 1 < ny...\n    replace hml : \u2191m \u2264 n \u2022 x + 1,\n    { sorry },\n    -- So x < m / n < y...\n    use (\u2191m : \u211a) / (\u2191n : \u211a), split,\n    { sorry },\n    { sorry }}\n\n  theorem real.exists_nth_root' : 0 \u2264 x \u2192 \u2200 n : \u2115, n \u2260 0 \u2192 \u2203! y : \u211d, npow n y = x := by\n  { intros hx n hn,\n    -- Let E be the set consisting of all t : \u211d such that t > 0 and t^n < x...\n    let E : set \u211d := (\u03bb t, 0 < t \u2227 npow n t < x),\n    -- E is nonempty, since x / (x + 1) is in E...\n    -- E is bounded above by x + 1...\n    -- So we let y := sup E...\n    -- Lemma: b^n - a^n < (b - a) n b^(n - 1)...\n    -- * If y^n < x, choose h such that 0 < h < 1 and h < (x - y^n) / (n (y + 1)^(n - 1))...\n    --   Then (y + h)^n - y^n < h n (y + h)^(n - 1) < h n (y + 1)^(n - 1) < x - y^n...\n    --   So (y + h)^n < x, contradiction...\n    -- * If y^n = x, all good...\n    -- * If x < y^n, choose k := (y^n - x) / (n y^(n - 1)), then 0 < k < y...\n    --   * For all t such that y - k \u2264 t, y^n - t^n \u2264 y^n - (y - k)^n < k n y^(n - 1) = y^n - x...\n    --     So t^n > x, so t is not in E...\n    --   So y - k is an upper bound of E, contradiction...\n    sorry  }\n\n  -- lemma...\n  -- (I might be giving up on this...)\n\nend\n\n--------------------------------------------------------------------------------\n-- **The extended real number system**\n-- (Nothing to do here...?)\n\n--------------------------------------------------------------------------------\n-- **The complex field**\n\nsection\n\n  variables (a b : \u211d)\n  variables (z w : \u2102)\n\n  example : (\u27e8a, 0\u27e9 : \u2102) + \u27e8b, 0\u27e9 = \u27e8a + b, 0\u27e9 := by\n  { have : (\u27e8a, 0\u27e9 : \u2102) + \u27e8b, 0\u27e9 = \u27e8a + b, 0 + 0\u27e9 := rfl,\n    rw add_zero at this,\n    exact this }\n\n  example : (\u27e8a, 0\u27e9 : \u2102) * \u27e8b, 0\u27e9 = \u27e8a * b, 0\u27e9 := by\n  { have : (\u27e8a, 0\u27e9 : \u2102) * \u27e8b, 0\u27e9 = \u27e8a * b - 0 * 0, a * 0 + 0 * b\u27e9 := rfl,\n    simp at this,\n    exact this }\n\n  example : complex.I = (\u27e80, 1\u27e9 : \u2102)           := rfl\n  example : complex.I * complex.I = -1         := by simp\n  example : (\u27e8a, b\u27e9 : \u2102) = \u2191a + \u2191b * complex.I := by\n  { unfold complex.I,\n    change (\u27e8a, b\u27e9 : \u2102) = \u27e8a + (b * 0 - 0 * 1), 0 + (b * 1 + 0 * 0)\u27e9,\n    simp }\n\n  section theorems_1_31\n\n    example : (z + w).conj = z.conj + w.conj := by\n    { unfold complex.conj, -- what? sorry.\n      sorry }\n\n    example : (z * w).conj = z.conj * w.conj := by\n    { sorry }\n\n    example : z + z.conj = 2 * z.re := by\n    { sorry }\n\n    example : z - z.conj = 2 * complex.I * z.im := by\n    { sorry }\n\n    -- (TODO: How to express \"a complex number is real\" in Lean?)\n    -- (d)\n\n  end theorems_1_31\n\n  #print complex.abs                            --  real.sqrt (\u21d1complex.norm_sq z)\n\nend\n\n--------------------------------------------------------------------------------\n-- **Euclidean spaces**\n\n\n\n\nend notes\n", "meta": {"author": "bridgekat", "repo": "lean-notes", "sha": "18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d", "save_path": "github-repos/lean/bridgekat-lean-notes", "path": "github-repos/lean/bridgekat-lean-notes/lean-notes-18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d/src/2_analysis/1_the_real_and_complex_number_systems.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7353488527609094}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module data.set.countable\n! leanprover-community/mathlib commit 1f0096e6caa61e9c849ec2adbd227e960e9dff58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Finite\nimport Mathlib.Data.Countable.Basic\nimport Mathlib.Logic.Equiv.List\n\n/-!\n# Countable sets\n-/\n\nnoncomputable section\n\nopen Function Set Encodable Classical\n\nuniverse u v w x\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x}\n\nnamespace Set\n\n/-- A set is countable if there exists an encoding of the set into the natural numbers.\nAn encoding is an injection with a partial inverse, which can be viewed as a\nconstructive analogue of countability. (For the most part, theorems about\n`Countable` will be classical and `Encodable` will be constructive.)\n-/\nprotected def Countable (s : Set \u03b1) : Prop :=\n  Nonempty (Encodable s)\n#align set.countable Set.Countable\n\n@[simp]\ntheorem countable_coe_iff {s : Set \u03b1} : Countable s \u2194 s.Countable :=\n  Encodable.nonempty_encodable.symm\n#align set.countable_coe_iff Set.countable_coe_iff\n\n/-- Prove `Set.Countable` from a `Countable` instance on the subtype. -/\ntheorem to_countable (s : Set \u03b1) [Countable s] : s.Countable :=\n  countable_coe_iff.mp \u2039_\u203a\n#align set.to_countable Set.to_countable\n\n/-- Restate `Set.Countable` as a `Countable` instance. -/\nalias countable_coe_iff \u2194 _root_.Countable.to_set Countable.to_subtype\n#align countable.to_set Countable.to_set\n#align set.countable.to_subtype Set.Countable.to_subtype\n\nprotected theorem countable_iff_exists_injective {s : Set \u03b1} :\n    s.Countable \u2194 \u2203 f : s \u2192 \u2115, Injective f :=\n  countable_coe_iff.symm.trans (countable_iff_exists_injective s)\n#align set.countable_iff_exists_injective Set.countable_iff_exists_injective\n\n/-- A set `s : Set \u03b1` is countable if and only if there exists a function `\u03b1 \u2192 \u2115` injective\non `s`. -/\ntheorem countable_iff_exists_injOn {s : Set \u03b1} : s.Countable \u2194 \u2203 f : \u03b1 \u2192 \u2115, InjOn f s :=\n  Set.countable_iff_exists_injective.trans exists_injOn_iff_injective.symm\n#align set.countable_iff_exists_inj_on Set.countable_iff_exists_injOn\n\n/-- Convert `Set.Countable s` to `Encodable s` (noncomputable). -/\nprotected def Countable.toEncodable {s : Set \u03b1} : s.Countable \u2192 Encodable s :=\n  Classical.choice\n#align set.countable.to_encodable Set.Countable.toEncodable\n\nsection Enumerate\n\n/-- Noncomputably enumerate elements in a set. The `default` value is used to extend the domain to\nall of `\u2115`. -/\ndef enumerateCountable {s : Set \u03b1} (h : s.Countable) (default : \u03b1) : \u2115 \u2192 \u03b1 := fun n =>\n  match @Encodable.decode s h.toEncodable n with\n  | some y => y\n  | none => default\n#align set.enumerate_countable Set.enumerateCountable\n\ntheorem subset_range_enumerate {s : Set \u03b1} (h : s.Countable) (default : \u03b1) :\n    s \u2286 range (enumerateCountable h default) := fun x hx =>\n  \u27e8@Encodable.encode s h.toEncodable \u27e8x, hx\u27e9, by\n    letI := h.toEncodable\n    simp [enumerateCountable, Encodable.encodek]\u27e9\n#align set.subset_range_enumerate Set.subset_range_enumerate\n\nend Enumerate\n\ntheorem Countable.mono {s\u2081 s\u2082 : Set \u03b1} (h : s\u2081 \u2286 s\u2082) : s\u2082.Countable \u2192 s\u2081.Countable\n  | \u27e8H\u27e9 => \u27e8@ofInj _ _ H _ (embeddingOfSubset _ _ h).2\u27e9\n#align set.countable.mono Set.Countable.mono\n\ntheorem countable_range [Countable \u03b9] (f : \u03b9 \u2192 \u03b2) : (range f).Countable :=\n  surjective_onto_range.countable.to_set\n#align set.countable_range Set.countable_range\n\ntheorem countable_iff_exists_subset_range [Nonempty \u03b1] {s : Set \u03b1} :\n    s.Countable \u2194 \u2203 f : \u2115 \u2192 \u03b1, s \u2286 range f :=\n  \u27e8fun h => by\n    inhabit \u03b1\n    exact \u27e8enumerateCountable h default, subset_range_enumerate _ _\u27e9, fun \u27e8f, hsf\u27e9 =>\n    (countable_range f).mono hsf\u27e9\n#align set.countable_iff_exists_subset_range Set.countable_iff_exists_subset_range\n\n/-- A non-empty set is countable iff there exists a surjection from the\nnatural numbers onto the subtype induced by the set.\n-/\nprotected theorem countable_iff_exists_surjective {s : Set \u03b1} (hs : s.Nonempty) :\n    s.Countable \u2194 \u2203 f : \u2115 \u2192 s, Surjective f :=\n  countable_coe_iff.symm.trans <| @countable_iff_exists_surjective s hs.to_subtype\n#align set.countable_iff_exists_surjective Set.countable_iff_exists_surjective\n\nalias Set.countable_iff_exists_surjective \u2194 Countable.exists_surjective _\n#align set.countable.exists_surjective Set.Countable.exists_surjective\n\ntheorem countable_univ [Countable \u03b1] : (univ : Set \u03b1).Countable :=\n  to_countable univ\n#align set.countable_univ Set.countable_univ\n\n/-- If `s : Set \u03b1` is a nonempty countable set, then there exists a map\n`f : \u2115 \u2192 \u03b1` such that `s = range f`. -/\ntheorem Countable.exists_eq_range {s : Set \u03b1} (hc : s.Countable) (hs : s.Nonempty) :\n    \u2203 f : \u2115 \u2192 \u03b1, s = range f := by\n  rcases hc.exists_surjective hs with \u27e8f, hf\u27e9\n  refine' \u27e8(\u2191) \u2218 f, _\u27e9\n  rw [hf.range_comp, Subtype.range_coe]\n#align set.countable.exists_eq_range Set.Countable.exists_eq_range\n\n@[simp] theorem countable_empty : (\u2205 : Set \u03b1).Countable := to_countable _\n#align set.countable_empty Set.countable_empty\n\n@[simp] theorem countable_singleton (a : \u03b1) : ({a} : Set \u03b1).Countable := to_countable _\n#align set.countable_singleton Set.countable_singleton\n\ntheorem Countable.image {s : Set \u03b1} (hs : s.Countable) (f : \u03b1 \u2192 \u03b2) : (f '' s).Countable := by\n  rw [image_eq_range]\n  haveI := hs.to_subtype\n  apply countable_range\n#align set.countable.image Set.Countable.image\n\ntheorem MapsTo.countable_of_injOn {s : Set \u03b1} {t : Set \u03b2} {f : \u03b1 \u2192 \u03b2} (hf : MapsTo f s t)\n    (hf' : InjOn f s) (ht : t.Countable) : s.Countable :=\n  have : Injective (hf.restrict f s t) := (injOn_iff_injective.1 hf').codRestrict _\n  \u27e8@Encodable.ofInj _ _ ht.toEncodable _ this\u27e9\n#align set.maps_to.countable_of_inj_on Set.MapsTo.countable_of_injOn\n\ntheorem Countable.preimage_of_injOn {s : Set \u03b2} (hs : s.Countable) {f : \u03b1 \u2192 \u03b2}\n    (hf : InjOn f (f \u207b\u00b9' s)) : (f \u207b\u00b9' s).Countable :=\n  (mapsTo_preimage f s).countable_of_injOn hf hs\n#align set.countable.preimage_of_inj_on Set.Countable.preimage_of_injOn\n\nprotected theorem Countable.preimage {s : Set \u03b2} (hs : s.Countable) {f : \u03b1 \u2192 \u03b2} (hf : Injective f) :\n    (f \u207b\u00b9' s).Countable :=\n  hs.preimage_of_injOn (hf.injOn _)\n#align set.countable.preimage Set.Countable.preimage\n\ntheorem exists_seq_sup\u1d62_eq_top_iff_countable [CompleteLattice \u03b1] {p : \u03b1 \u2192 Prop} (h : \u2203 x, p x) :\n    (\u2203 s : \u2115 \u2192 \u03b1, (\u2200 n, p (s n)) \u2227 (\u2a06 n, s n) = \u22a4) \u2194\n      \u2203 S : Set \u03b1, S.Countable \u2227 (\u2200 s \u2208 S, p s) \u2227 sup\u209b S = \u22a4 := by\n  constructor\n  \u00b7 rintro \u27e8s, hps, hs\u27e9\n    refine' \u27e8range s, countable_range s, forall_range_iff.2 hps, _\u27e9\n    rwa [sup\u209b_range]\n  \u00b7 rintro \u27e8S, hSc, hps, hS\u27e9\n    rcases eq_empty_or_nonempty S with (rfl | hne)\n    \u00b7 rw [sup\u209b_empty] at hS\n      haveI := subsingleton_of_bot_eq_top hS\n      rcases h with \u27e8x, hx\u27e9\n      exact \u27e8fun _ => x, fun _ => hx, Subsingleton.elim _ _\u27e9\n    \u00b7 rcases(Set.countable_iff_exists_surjective hne).1 hSc with \u27e8s, hs\u27e9\n      refine' \u27e8fun n => s n, fun n => hps _ (s n).coe_prop, _\u27e9\n      rwa [hs.sup\u1d62_comp, \u2190 sup\u209b_eq_sup\u1d62']\n#align set.exists_seq_supr_eq_top_iff_countable Set.exists_seq_sup\u1d62_eq_top_iff_countable\n\ntheorem exists_seq_cover_iff_countable {p : Set \u03b1 \u2192 Prop} (h : \u2203 s, p s) :\n    (\u2203 s : \u2115 \u2192 Set \u03b1, (\u2200 n, p (s n)) \u2227 (\u22c3 n, s n) = univ) \u2194\n      \u2203 S : Set (Set \u03b1), S.Countable \u2227 (\u2200 s \u2208 S, p s) \u2227 \u22c3\u2080 S = univ :=\n  exists_seq_sup\u1d62_eq_top_iff_countable h\n#align set.exists_seq_cover_iff_countable Set.exists_seq_cover_iff_countable\n\ntheorem countable_of_injective_of_countable_image {s : Set \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : InjOn f s)\n    (hs : (f '' s).Countable) : s.Countable :=\n  (mapsTo_image _ _).countable_of_injOn hf hs\n#align set.countable_of_injective_of_countable_image Set.countable_of_injective_of_countable_image\n\ntheorem countable_union\u1d62 {t : \u03b9 \u2192 Set \u03b1} [Countable \u03b9] (ht : \u2200 i, (t i).Countable) :\n    (\u22c3 i, t i).Countable := by\n  haveI := fun a => (ht a).to_subtype\n  rw [union\u1d62_eq_range_psigma]\n  apply countable_range\n#align set.countable_Union Set.countable_union\u1d62\n\n@[simp]\ntheorem countable_union\u1d62_iff [Countable \u03b9] {t : \u03b9 \u2192 Set \u03b1} :\n    (\u22c3 i, t i).Countable \u2194 \u2200 i, (t i).Countable :=\n  \u27e8fun h _ => h.mono <| subset_union\u1d62 _ _, countable_union\u1d62\u27e9\n#align set.countable_Union_iff Set.countable_union\u1d62_iff\n\ntheorem Countable.bunion\u1d62_iff {s : Set \u03b1} {t : \u2200 a \u2208 s, Set \u03b2} (hs : s.Countable) :\n    (\u22c3 a \u2208 s, t a \u2039_\u203a).Countable \u2194 \u2200 a (ha : a \u2208 s), (t a ha).Countable := by\n  haveI := hs.to_subtype\n  rw [bunion\u1d62_eq_union\u1d62, countable_union\u1d62_iff, SetCoe.forall']\n#align set.countable.bUnion_iff Set.Countable.bunion\u1d62_iff\n\ntheorem Countable.union\u209b_iff {s : Set (Set \u03b1)} (hs : s.Countable) :\n    (\u22c3\u2080 s).Countable \u2194 \u2200 a \u2208 s, (a : _).Countable := by rw [union\u209b_eq_bunion\u1d62, hs.bunion\u1d62_iff]\n#align set.countable.sUnion_iff Set.Countable.union\u209b_iff\n\nalias Countable.bunion\u1d62_iff \u2194 _ Countable.bunion\u1d62\n#align set.countable.bUnion Set.Countable.bunion\u1d62\n\nalias Countable.union\u209b_iff \u2194 _ Countable.union\u209b\n#align set.countable.sUnion Set.Countable.union\u209b\n\n@[simp]\ntheorem countable_union {s t : Set \u03b1} : (s \u222a t).Countable \u2194 s.Countable \u2227 t.Countable := by\n  simp [union_eq_union\u1d62, and_comm]\n#align set.countable_union Set.countable_union\n\ntheorem Countable.union {s t : Set \u03b1} (hs : s.Countable) (ht : t.Countable) : (s \u222a t).Countable :=\n  countable_union.2 \u27e8hs, ht\u27e9\n#align set.countable.union Set.Countable.union\n\ntheorem Countable.of_diff {s t : Set \u03b1} (h : (s \\ t).Countable) (ht : t.Countable) : s.Countable :=\n  (h.union ht).mono (subset_diff_union _ _)\n\n@[simp]\n\n\ntheorem Countable.insert {s : Set \u03b1} (a : \u03b1) (h : s.Countable) : (insert a s).Countable :=\n  countable_insert.2 h\n#align set.countable.insert Set.Countable.insert\n\ntheorem Finite.countable {s : Set \u03b1} : s.Finite \u2192 s.Countable\n  | \u27e8_\u27e9 => Trunc.nonempty (Fintype.truncEncodable s)\n#align set.finite.countable Set.Finite.countable\n\n@[nontriviality]\ntheorem Countable.of_subsingleton [Subsingleton \u03b1] (s : Set \u03b1) : s.Countable :=\n  (Finite.of_subsingleton s).countable\n#align set.countable.of_subsingleton Set.Countable.of_subsingleton\n\ntheorem Subsingleton.countable {s : Set \u03b1} (hs : s.Subsingleton) : s.Countable :=\n  hs.finite.countable\n#align set.subsingleton.countable Set.Subsingleton.countable\n\ntheorem countable_isTop (\u03b1 : Type _) [PartialOrder \u03b1] : { x : \u03b1 | IsTop x }.Countable :=\n  (finite_isTop \u03b1).countable\n#align set.countable_is_top Set.countable_isTop\n\ntheorem countable_isBot (\u03b1 : Type _) [PartialOrder \u03b1] : { x : \u03b1 | IsBot x }.Countable :=\n  (finite_isBot \u03b1).countable\n#align set.countable_is_bot Set.countable_isBot\n\n/-- The set of finite subsets of a countable set is countable. -/\ntheorem countable_setOf_finite_subset {s : Set \u03b1} (hs : s.Countable) :\n    { t | Set.Finite t \u2227 t \u2286 s }.Countable := by\n  haveI := hs.to_subtype\n  refine' Countable.mono _ (countable_range fun t : Finset s => Subtype.val '' (t : Set s))\n  rintro t \u27e8ht, hts\u27e9\n  lift t to Set s using hts\n  lift t to Finset s using ht.of_finite_image (Subtype.val_injective.injOn _)\n  exact mem_range_self _\n#align set.countable_set_of_finite_subset Set.countable_setOf_finite_subset\n\ntheorem countable_univ_pi {\u03c0 : \u03b1 \u2192 Type _} [Finite \u03b1] {s : \u2200 a, Set (\u03c0 a)}\n    (hs : \u2200 a, (s a).Countable) : (pi univ s).Countable :=\n  haveI := fun a => (hs a).to_subtype\n  (Countable.of_equiv _ (Equiv.Set.univPi s).symm).to_set\n#align set.countable_univ_pi Set.countable_univ_pi\n\ntheorem countable_pi {\u03c0 : \u03b1 \u2192 Type _} [Finite \u03b1] {s : \u2200 a, Set (\u03c0 a)} (hs : \u2200 a, (s a).Countable) :\n    { f : \u2200 a, \u03c0 a | \u2200 a, f a \u2208 s a }.Countable := by\n  simpa only [\u2190 mem_univ_pi] using countable_univ_pi hs\n#align set.countable_pi Set.countable_pi\n\nprotected theorem Countable.prod {s : Set \u03b1} {t : Set \u03b2} (hs : s.Countable) (ht : t.Countable) :\n    Set.Countable (s \u00d7\u02e2 t) := by\n  haveI : Countable s := hs.to_subtype\n  haveI : Countable t := ht.to_subtype\n  exact (Countable.of_equiv _ <| (Equiv.Set.prod _ _).symm).to_set\n#align set.countable.prod Set.Countable.prod\n\ntheorem Countable.image2 {s : Set \u03b1} {t : Set \u03b2} (hs : s.Countable) (ht : t.Countable)\n    (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) : (image2 f s t).Countable := by\n  rw [\u2190 image_prod]\n  exact (hs.prod ht).image _\n#align set.countable.image2 Set.Countable.image2\n\nend Set\n\ntheorem Finset.countable_toSet (s : Finset \u03b1) : Set.Countable (\u2191s : Set \u03b1) :=\n  s.finite_toSet.countable\n#align finset.countable_to_set Finset.countable_toSet\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Countable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7353488483579497}}
{"text": "/-\nCopyright (c) 2019 Amelia Livingston. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Amelia Livingston, Bryan Gin-ge Chen, Patrick Massot\n-/\n\nimport data.fintype.basic\nimport data.set.finite\nimport data.setoid.basic\n\n/-!\n# Equivalence relations: partitions\n\nThis file comprises properties of equivalence relations viewed as partitions.\nThere are two implementations of partitions here:\n* A collection `c : set (set \u03b1)` of sets is a partition of `\u03b1` if `\u2205 \u2209 c` and each element `a : \u03b1`\n  belongs to a unique set `b \u2208 c`. This is expressed as `is_partition c`\n* An indexed partition is a map `s : \u03b9 \u2192 \u03b1` whose image is a partition. This is\n  expressed as `indexed_partition s`.\n\nOf course both implementations are related to `quotient` and `setoid`.\n\n## Tags\n\nsetoid, equivalence, iseqv, relation, equivalence relation, partition, equivalence class\n-/\n\nnamespace setoid\n\nvariables {\u03b1 : Type*}\n\n/-- If x \u2208 \u03b1 is in 2 elements of a set of sets partitioning \u03b1, those 2 sets are equal. -/\nlemma eq_of_mem_eqv_class {c : set (set \u03b1)} (H : \u2200 a, \u2203! b \u2208 c, a \u2208 b)\n  {x b b'} (hc : b \u2208 c) (hb : x \u2208 b) (hc' : b' \u2208 c) (hb' : x \u2208 b') :\n  b = b' :=\n(H x).unique2 hc hb hc' hb'\n\n/-- Makes an equivalence relation from a set of sets partitioning \u03b1. -/\ndef mk_classes (c : set (set \u03b1)) (H : \u2200 a, \u2203! b \u2208 c, a \u2208 b) :\n  setoid \u03b1 :=\n\u27e8\u03bb x y, \u2200 s \u2208 c, x \u2208 s \u2192 y \u2208 s, \u27e8\u03bb _ _ _ hx, hx,\n \u03bb x y h s hs hy, (H x).elim2 $ \u03bb t ht hx _,\n   have s = t, from eq_of_mem_eqv_class H hs hy ht (h t ht hx),\n   this.symm \u25b8 hx,\n \u03bb x y z h1 h2 s hs hx, (H y).elim2 $ \u03bb t ht hy _, (H z).elim2 $ \u03bb t' ht' hz _,\n   have hst : s = t, from eq_of_mem_eqv_class H hs (h1 _ hs hx) ht hy,\n   have htt' : t = t', from eq_of_mem_eqv_class H ht (h2 _ ht hy) ht' hz,\n   (hst.trans htt').symm \u25b8 hz\u27e9\u27e9\n\n/-- Makes the equivalence classes of an equivalence relation. -/\ndef classes (r : setoid \u03b1) : set (set \u03b1) :=\n{s | \u2203 y, s = {x | r.rel x y}}\n\nlemma mem_classes (r : setoid \u03b1) (y) : {x | r.rel x y} \u2208 r.classes := \u27e8y, rfl\u27e9\n\nlemma classes_ker_subset_fiber_set {\u03b2 : Type*} (f : \u03b1 \u2192 \u03b2) :\n  (setoid.ker f).classes \u2286 set.range (\u03bb y, {x | f x = y}) :=\nby { rintro s \u27e8x, rfl\u27e9, rw set.mem_range, exact \u27e8f x, rfl\u27e9 }\n\nlemma nonempty_fintype_classes_ker {\u03b1 \u03b2 : Type*} [fintype \u03b2] (f : \u03b1 \u2192 \u03b2) :\n  nonempty (fintype (setoid.ker f).classes) :=\nby { classical, exact \u27e8set.fintype_subset _ (classes_ker_subset_fiber_set f)\u27e9 }\n\nlemma card_classes_ker_le {\u03b1 \u03b2 : Type*} [fintype \u03b2]\n  (f : \u03b1 \u2192 \u03b2) [fintype (setoid.ker f).classes] :\n  fintype.card (setoid.ker f).classes \u2264 fintype.card \u03b2 :=\nbegin\n  classical,\n  exact le_trans (set.card_le_of_subset (classes_ker_subset_fiber_set f)) (fintype.card_range_le _)\nend\n\n/-- Two equivalence relations are equal iff all their equivalence classes are equal. -/\nlemma eq_iff_classes_eq {r\u2081 r\u2082 : setoid \u03b1} :\n  r\u2081 = r\u2082 \u2194 \u2200 x, {y | r\u2081.rel x y} = {y | r\u2082.rel x y} :=\n\u27e8\u03bb h x, h \u25b8 rfl, \u03bb h, ext' $ \u03bb x, set.ext_iff.1 $ h x\u27e9\n\nlemma rel_iff_exists_classes (r : setoid \u03b1) {x y} :\n  r.rel x y \u2194 \u2203 c \u2208 r.classes, x \u2208 c \u2227 y \u2208 c :=\n\u27e8\u03bb h, \u27e8_, r.mem_classes y, h, r.refl' y\u27e9,\n  \u03bb \u27e8c, \u27e8z, hz\u27e9, hx, hy\u27e9, by { subst c, exact r.trans' hx (r.symm' hy) }\u27e9\n\n/-- Two equivalence relations are equal iff their equivalence classes are equal. -/\nlemma classes_inj {r\u2081 r\u2082 : setoid \u03b1} :\n  r\u2081 = r\u2082 \u2194 r\u2081.classes = r\u2082.classes :=\n\u27e8\u03bb h, h \u25b8 rfl, \u03bb h, ext' $ \u03bb a b, by simp only [rel_iff_exists_classes, exists_prop, h] \u27e9\n\n/-- The empty set is not an equivalence class. -/\nlemma empty_not_mem_classes {r : setoid \u03b1} : \u2205 \u2209 r.classes :=\n\u03bb \u27e8y, hy\u27e9, set.not_mem_empty y $ hy.symm \u25b8 r.refl' y\n\n/-- Equivalence classes partition the type. -/\nlemma classes_eqv_classes {r : setoid \u03b1} (a) : \u2203! b \u2208 r.classes, a \u2208 b :=\nexists_unique.intro2 {x | r.rel x a} (r.mem_classes a) (r.refl' _) $\nbegin\n  rintros _ \u27e8y, rfl\u27e9 ha,\n  ext x,\n  exact \u27e8\u03bb hx, r.trans' hx (r.symm' ha), \u03bb hx, r.trans' hx ha\u27e9\nend\n\n/-- If x \u2208 \u03b1 is in 2 equivalence classes, the equivalence classes are equal. -/\nlemma eq_of_mem_classes {r : setoid \u03b1} {x b} (hc : b \u2208 r.classes)\n  (hb : x \u2208 b) {b'} (hc' : b' \u2208 r.classes) (hb' : x \u2208 b') : b = b' :=\neq_of_mem_eqv_class classes_eqv_classes hc hb hc' hb'\n\n/-- The elements of a set of sets partitioning \u03b1 are the equivalence classes of the\n    equivalence relation defined by the set of sets. -/\nlemma eq_eqv_class_of_mem {c : set (set \u03b1)}\n  (H : \u2200 a, \u2203! b \u2208 c, a \u2208 b) {s y} (hs : s \u2208 c) (hy : y \u2208 s) :\n  s = {x | (mk_classes c H).rel x y} :=\nset.ext $ \u03bb x,\n  \u27e8\u03bb hs', symm' (mk_classes c H) $ \u03bb b' hb' h', eq_of_mem_eqv_class H hs hy hb' h' \u25b8 hs',\n   \u03bb hx, (H x).elim2 $ \u03bb b' hc' hb' h',\n     (eq_of_mem_eqv_class H hs hy hc' $ hx b' hc' hb').symm \u25b8 hb'\u27e9\n\n/-- The equivalence classes of the equivalence relation defined by a set of sets\n    partitioning \u03b1 are elements of the set of sets. -/\nlemma eqv_class_mem {c : set (set \u03b1)} (H : \u2200 a, \u2203! b \u2208 c, a \u2208 b) {y} :\n  {x | (mk_classes c H).rel x y} \u2208 c :=\n(H y).elim2 $ \u03bb b hc hy hb, eq_eqv_class_of_mem H hc hy \u25b8 hc\n\nlemma eqv_class_mem' {c : set (set \u03b1)} (H : \u2200 a, \u2203! b \u2208 c, a \u2208 b) {x} :\n  {y : \u03b1 | (mk_classes c H).rel x y} \u2208 c :=\nby { convert setoid.eqv_class_mem H, ext, rw setoid.comm' }\n\n/-- Distinct elements of a set of sets partitioning \u03b1 are disjoint. -/\nlemma eqv_classes_disjoint {c : set (set \u03b1)} (H : \u2200 a, \u2203! b \u2208 c, a \u2208 b) :\n  c.pairwise_disjoint id :=\n\u03bb b\u2081 h\u2081 b\u2082 h\u2082 h, set.disjoint_left.2 $\n  \u03bb x hx1 hx2, (H x).elim2 $ \u03bb b hc hx hb, h $ eq_of_mem_eqv_class H h\u2081 hx1 h\u2082 hx2\n\n/-- A set of disjoint sets covering \u03b1 partition \u03b1 (classical). -/\nlemma eqv_classes_of_disjoint_union {c : set (set \u03b1)}\n  (hu : set.sUnion c = @set.univ \u03b1) (H : c.pairwise_disjoint id) (a) :\n  \u2203! b \u2208 c, a \u2208 b :=\nlet \u27e8b, hc, ha\u27e9 := set.mem_sUnion.1 $ show a \u2208 _, by rw hu; exact set.mem_univ a in\n  exists_unique.intro2 b hc ha $ \u03bb b' hc' ha', H.elim_set hc' hc a ha' ha\n\n/-- Makes an equivalence relation from a set of disjoints sets covering \u03b1. -/\ndef setoid_of_disjoint_union {c : set (set \u03b1)} (hu : set.sUnion c = @set.univ \u03b1)\n  (H : c.pairwise_disjoint id) : setoid \u03b1 :=\nsetoid.mk_classes c $ eqv_classes_of_disjoint_union hu H\n\n/-- The equivalence relation made from the equivalence classes of an equivalence\n    relation r equals r. -/\ntheorem mk_classes_classes (r : setoid \u03b1) :\n  mk_classes r.classes classes_eqv_classes = r :=\next' $ \u03bb x y, \u27e8\u03bb h, r.symm' (h {z | r.rel z x} (r.mem_classes x) $ r.refl' x),\n  \u03bb h b hb hx, eq_of_mem_classes (r.mem_classes x) (r.refl' x) hb hx \u25b8 r.symm' h\u27e9\n\n@[simp] theorem sUnion_classes (r : setoid \u03b1) : \u22c3\u2080 r.classes = set.univ :=\nset.eq_univ_of_forall $ \u03bb x, set.mem_sUnion.2 \u27e8{ y | r.rel y x }, \u27e8x, rfl\u27e9, setoid.refl _\u27e9\n\nsection partition\n\n/-- A collection `c : set (set \u03b1)` of sets is a partition of `\u03b1` into pairwise\ndisjoint sets if `\u2205 \u2209 c` and each element `a : \u03b1` belongs to a unique set `b \u2208 c`. -/\ndef is_partition (c : set (set \u03b1)) :=\n\u2205 \u2209 c \u2227 \u2200 a, \u2203! b \u2208 c, a \u2208 b\n\n/-- A partition of `\u03b1` does not contain the empty set. -/\nlemma nonempty_of_mem_partition {c : set (set \u03b1)} (hc : is_partition c) {s} (h : s \u2208 c) :\n  s.nonempty :=\nset.ne_empty_iff_nonempty.1 $ \u03bb hs0, hc.1 $ hs0 \u25b8 h\n\nlemma is_partition_classes (r : setoid \u03b1) : is_partition r.classes :=\n\u27e8empty_not_mem_classes, classes_eqv_classes\u27e9\n\nlemma is_partition.pairwise_disjoint {c : set (set \u03b1)} (hc : is_partition c) :\n  c.pairwise_disjoint id :=\neqv_classes_disjoint hc.2\n\nlemma is_partition.sUnion_eq_univ {c : set (set \u03b1)} (hc : is_partition c) :\n  \u22c3\u2080 c = set.univ :=\nset.eq_univ_of_forall $ \u03bb x, set.mem_sUnion.2 $\n  let \u27e8t, ht\u27e9 := hc.2 x in \u27e8t, by clear_aux_decl; finish\u27e9\n\n/-- All elements of a partition of \u03b1 are the equivalence class of some y \u2208 \u03b1. -/\nlemma exists_of_mem_partition {c : set (set \u03b1)} (hc : is_partition c) {s} (hs : s \u2208 c) :\n  \u2203 y, s = {x | (mk_classes c hc.2).rel x y} :=\nlet \u27e8y, hy\u27e9 := nonempty_of_mem_partition hc hs in\n  \u27e8y, eq_eqv_class_of_mem hc.2 hs hy\u27e9\n\n/-- The equivalence classes of the equivalence relation defined by a partition of \u03b1 equal\n    the original partition. -/\ntheorem classes_mk_classes (c : set (set \u03b1)) (hc : is_partition c) :\n  (mk_classes c hc.2).classes = c :=\nset.ext $ \u03bb s,\n  \u27e8\u03bb \u27e8y, hs\u27e9, (hc.2 y).elim2 $ \u03bb b hm hb hy,\n    by rwa (show s = b, from hs.symm \u25b8 set.ext\n      (\u03bb x, \u27e8\u03bb hx, symm' (mk_classes c hc.2) hx b hm hb,\n             \u03bb hx b' hc' hx', eq_of_mem_eqv_class hc.2 hm hx hc' hx' \u25b8 hb\u27e9)),\n   exists_of_mem_partition hc\u27e9\n\n/-- Defining `\u2264` on partitions as the `\u2264` defined on their induced equivalence relations. -/\ninstance partition.le : has_le (subtype (@is_partition \u03b1)) :=\n\u27e8\u03bb x y, mk_classes x.1 x.2.2 \u2264 mk_classes y.1 y.2.2\u27e9\n\n/-- Defining a partial order on partitions as the partial order on their induced\n    equivalence relations. -/\ninstance partition.partial_order : partial_order (subtype (@is_partition \u03b1)) :=\n{ le := (\u2264),\n  lt := \u03bb x y, x \u2264 y \u2227 \u00acy \u2264 x,\n  le_refl := \u03bb _, @le_refl (setoid \u03b1) _ _,\n  le_trans := \u03bb _ _ _, @le_trans (setoid \u03b1) _ _ _ _,\n  lt_iff_le_not_le := \u03bb _ _, iff.rfl,\n  le_antisymm := \u03bb x y hx hy, let h := @le_antisymm (setoid \u03b1) _ _ _ hx hy in by\n    rw [subtype.ext_iff_val, \u2190classes_mk_classes x.1 x.2, \u2190classes_mk_classes y.1 y.2, h] }\n\nvariables (\u03b1)\n\n/-- The order-preserving bijection between equivalence relations on a type `\u03b1`, and\n  partitions of `\u03b1` into subsets. -/\nprotected def partition.order_iso :\n  setoid \u03b1 \u2243o {C : set (set \u03b1) // is_partition C} :=\n{ to_fun := \u03bb r, \u27e8r.classes, empty_not_mem_classes, classes_eqv_classes\u27e9,\n  inv_fun := \u03bb C, mk_classes C.1 C.2.2,\n  left_inv := mk_classes_classes,\n  right_inv := \u03bb C, by rw [subtype.ext_iff_val, \u2190classes_mk_classes C.1 C.2],\n  map_rel_iff' := \u03bb r s,\n    by { conv_rhs { rw [\u2190mk_classes_classes r, \u2190mk_classes_classes s] }, refl } }\n\nvariables {\u03b1}\n\n/-- A complete lattice instance for partitions; there is more infrastructure for the\n    equivalent complete lattice on equivalence relations. -/\ninstance partition.complete_lattice : complete_lattice (subtype (@is_partition \u03b1)) :=\ngalois_insertion.lift_complete_lattice $ @order_iso.to_galois_insertion\n_ (subtype (@is_partition \u03b1)) _ (partial_order.to_preorder _) $ partition.order_iso \u03b1\n\nend partition\n\nend setoid\n\n/-- Constructive information associated with a partition of a type `\u03b1` indexed by another type `\u03b9`,\n`s : \u03b9 \u2192 set \u03b1`.\n\n`indexed_partition.index` sends an element to its index, while `indexed_partition.some` sends\nan index to an element of the corresponding set.\n\nThis type is primarily useful for definitional control of `s` - if this is not needed, then\n`setoid.ker index` by itself may be sufficient. -/\nstructure indexed_partition {\u03b9 \u03b1 : Type*} (s : \u03b9 \u2192 set \u03b1) :=\n(eq_of_mem : \u2200 {x i j}, x \u2208 s i \u2192 x \u2208 s j \u2192 i = j)\n(some : \u03b9 \u2192 \u03b1)\n(some_mem : \u2200 i, some i \u2208 s i)\n(index : \u03b1 \u2192 \u03b9)\n(mem_index : \u2200 x, x \u2208 s (index x))\n\n/-- The non-constructive constructor for `indexed_partition`. -/\nnoncomputable\ndef indexed_partition.mk' {\u03b9 \u03b1 : Type*} (s : \u03b9 \u2192 set \u03b1) (dis : \u2200 i j, i \u2260 j \u2192 disjoint (s i) (s j))\n  (nonempty : \u2200 i, (s i).nonempty) (ex : \u2200 x, \u2203 i, x \u2208 s i) : indexed_partition s :=\n{ eq_of_mem := \u03bb x i j hxi hxj, classical.by_contradiction $ \u03bb h, dis _ _ h \u27e8hxi, hxj\u27e9,\n  some := \u03bb i, (nonempty i).some,\n  some_mem := \u03bb i, (nonempty i).some_spec,\n  index := \u03bb x, (ex x).some,\n  mem_index := \u03bb x, (ex x).some_spec }\n\nnamespace indexed_partition\n\nopen set\n\nvariables {\u03b9 \u03b1 : Type*} {s : \u03b9 \u2192 set \u03b1} (hs : indexed_partition s)\n\n/-- On a unique index set there is the obvious trivial partition -/\ninstance [unique \u03b9] [inhabited \u03b1] :\n  inhabited (indexed_partition (\u03bb i : \u03b9, (set.univ : set \u03b1))) :=\n\u27e8{ eq_of_mem := \u03bb x i j hi hj, subsingleton.elim _ _,\n   some := \u03bb i, default \u03b1,\n   some_mem := set.mem_univ,\n   index := \u03bb a, default \u03b9,\n   mem_index := set.mem_univ }\u27e9\n\nattribute [simp] some_mem mem_index\n\ninclude hs\n\nlemma exists_mem (x : \u03b1) : \u2203 i, x \u2208 s i := \u27e8hs.index x, hs.mem_index x\u27e9\n\nlemma Union : (\u22c3 i, s i) = univ :=\nby { ext x, simp [hs.exists_mem x] }\n\nlemma disjoint : \u2200 {i j}, i \u2260 j \u2192 disjoint (s i) (s j) :=\n\u03bb i j h x \u27e8hxi, hxj\u27e9, h (hs.eq_of_mem hxi hxj)\n\nlemma mem_iff_index_eq {x i} : x \u2208 s i \u2194 hs.index x = i :=\n\u27e8\u03bb hxi, (hs.eq_of_mem hxi (hs.mem_index x)).symm, \u03bb h, h \u25b8 hs.mem_index _\u27e9\n\nlemma eq (i) : s i = {x | hs.index x = i} :=\nset.ext $ \u03bb _, hs.mem_iff_index_eq\n\n/-- The equivalence relation associated to an indexed partition. Two\nelements are equivalent if they belong to the same set of the partition. -/\nprotected abbreviation setoid (hs : indexed_partition s) : setoid \u03b1 :=\nsetoid.ker hs.index\n\n@[simp] \n\nlemma some_index (x : \u03b1) : hs.setoid.rel (hs.some (hs.index x)) x :=\nhs.index_some (hs.index x)\n\n/-- The quotient associated to an indexed partition. -/\nprotected def quotient := quotient hs.setoid\n\n/-- The projection onto the quotient associated to an indexed partition. -/\ndef proj : \u03b1 \u2192 hs.quotient := quotient.mk'\n\ninstance [inhabited \u03b1] : inhabited (hs.quotient) := \u27e8hs.proj (default \u03b1)\u27e9\n\nlemma proj_eq_iff {x y : \u03b1} : hs.proj x = hs.proj y \u2194 hs.index x = hs.index y :=\nquotient.eq_rel\n\n@[simp] lemma proj_some_index (x : \u03b1) : hs.proj (hs.some (hs.index x)) = hs.proj x :=\nquotient.eq'.2 (hs.some_index x)\n\n/-- The obvious equivalence between the quotient associated to an indexed partition and\nthe indexing type. -/\ndef equiv_quotient : \u03b9 \u2243 hs.quotient :=\n(setoid.quotient_ker_equiv_of_right_inverse hs.index hs.some $ hs.index_some).symm\n\n@[simp] lemma equiv_quotient_index_apply (x : \u03b1) : hs.equiv_quotient (hs.index x) = hs.proj x :=\nhs.proj_eq_iff.mpr (some_index hs x)\n\n@[simp] lemma equiv_quotient_symm_proj_apply (x : \u03b1) :\n  hs.equiv_quotient.symm (hs.proj x) = hs.index x :=\nrfl\n\nlemma equiv_quotient_index : hs.equiv_quotient \u2218 hs.index = hs.proj :=\nfunext hs.equiv_quotient_index_apply\n\n/-- A map choosing a representative for each element of the quotient associated to an indexed\npartition. This is a computable version of `quotient.out'` using `indexed_partition.some`. -/\ndef out : hs.quotient \u21aa \u03b1 :=\nhs.equiv_quotient.symm.to_embedding.trans \u27e8hs.some, function.left_inverse.injective hs.index_some\u27e9\n\n/-- This lemma is analogous to `quotient.mk_out'`. -/\n@[simp]\nlemma out_proj (x : \u03b1) : hs.out (hs.proj x) = hs.some (hs.index x) :=\nrfl\n\n/-- The indices of `quotient.out'` and `indexed_partition.out` are equal. -/\nlemma index_out' (x : hs.quotient) : hs.index (x.out') = hs.index (hs.out x) :=\nquotient.induction_on' x $ \u03bb x, (setoid.ker_apply_mk_out' x).trans (hs.index_some _).symm\n\n/-- This lemma is analogous to `quotient.out_eq'`. -/\n@[simp] lemma proj_out (x : hs.quotient) : hs.proj (hs.out x) = x :=\nquotient.induction_on' x $ \u03bb x, quotient.sound' $ hs.some_index x\n\nlemma class_of {x : \u03b1} : set_of (hs.setoid.rel x) = s (hs.index x) :=\nset.ext $ \u03bb y, eq_comm.trans hs.mem_iff_index_eq.symm\n\nlemma proj_fiber (x : hs.quotient) : hs.proj \u207b\u00b9' {x} = s (hs.equiv_quotient.symm x) :=\nquotient.induction_on' x $ \u03bb x, begin\n  ext y,\n  simp only [set.mem_preimage, set.mem_singleton_iff, hs.mem_iff_index_eq],\n  exact quotient.eq',\nend\n\nend indexed_partition\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/setoid/partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7353488469559938}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport algebra.big_operators.basic\nimport data.nat.prime\nimport data.zmod.basic\nimport ring_theory.multiplicity\nimport data.nat.periodic\nimport algebra.char_p.two\n\n/-!\n# Euler's totient function\n\nThis file defines [Euler's totient function](https://en.wikipedia.org/wiki/Euler's_totient_function)\n`nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`.\nWe prove the divisor sum formula, namely that `n` equals `\u03c6` summed over the divisors of `n`. See\n`sum_totient`. We also prove two lemmas to help compute totients, namely `totient_mul` and\n`totient_prime_pow`.\n-/\n\nopen finset\nopen_locale big_operators\n\nnamespace nat\n\n/-- Euler's totient function. This counts the number of naturals strictly less than `n` which are\ncoprime with `n`. -/\ndef totient (n : \u2115) : \u2115 := ((range n).filter n.coprime).card\n\nlocalized \"notation `\u03c6` := nat.totient\" in nat\n\n@[simp] theorem totient_zero : \u03c6 0 = 0 := rfl\n\n@[simp] theorem totient_one : \u03c6 1 = 1 :=\nby simp [totient]\n\nlemma totient_eq_card_coprime (n : \u2115) : \u03c6 n = ((range n).filter n.coprime).card := rfl\n\nlemma totient_le (n : \u2115) : \u03c6 n \u2264 n :=\ncalc totient n \u2264 (range n).card : card_filter_le _ _\n           ... = n              : card_range _\n\nlemma totient_lt (n : \u2115) (hn : 1 < n) : \u03c6 n < n :=\ncalc totient n \u2264 ((range n).filter (\u2260 0)).card :\n  begin\n    apply card_le_of_subset (monotone_filter_right _ _),\n    intros n1 hn1 hn1',\n    simpa only [hn1', coprime_zero_right, hn.ne'] using hn1,\n  end\n... = n - 1 : by simp only [filter_ne' (range n) 0, card_erase_of_mem, n.pred_eq_sub_one,\n                card_range, pos_of_gt hn, mem_range]\n... < n : nat.sub_lt (pos_of_gt hn) zero_lt_one\n\nlemma totient_pos : \u2200 {n : \u2115}, 0 < n \u2192 0 < \u03c6 n\n| 0 := dec_trivial\n| 1 := by simp [totient]\n| (n+2) := \u03bb h, card_pos.2 \u27e81, mem_filter.2 \u27e8mem_range.2 dec_trivial, coprime_one_right _\u27e9\u27e9\n\nlemma filter_coprime_Ico_eq_totient (a n : \u2115) :\n  ((Ico n (n+a)).filter (coprime a)).card = totient a :=\nbegin\n  rw [totient, filter_Ico_card_eq_of_periodic, count_eq_card_filter_range],\n  exact periodic_coprime a,\nend\n\nlemma Ico_filter_coprime_le {a : \u2115} (k n : \u2115) (a_pos : 0 < a) :\n  ((Ico k (k + n)).filter (coprime a)).card \u2264 totient a * (n / a + 1) :=\nbegin\n  conv_lhs { rw \u2190nat.mod_add_div n a },\n  induction n / a with i ih,\n  { rw \u2190filter_coprime_Ico_eq_totient a k,\n    simp only [add_zero, mul_one, mul_zero, le_of_lt (mod_lt n a_pos)],\n    mono,\n    refine monotone_filter_left a.coprime _,\n    simp only [finset.le_eq_subset],\n    exact Ico_subset_Ico rfl.le (add_le_add_left (le_of_lt (mod_lt n a_pos)) k), },\n  simp only [mul_succ],\n  simp_rw \u2190add_assoc at ih \u22a2,\n  calc (filter a.coprime (Ico k (k + n % a + a * i + a))).card\n      = (filter a.coprime (Ico k (k + n % a + a * i)\n                            \u222a Ico (k + n % a + a * i) (k + n % a + a * i + a))).card :\n        begin\n          congr,\n          rw Ico_union_Ico_eq_Ico,\n          rw add_assoc,\n          exact le_self_add,\n          exact le_self_add,\n        end\n  ... \u2264 (filter a.coprime (Ico k (k + n % a + a * i))).card + a.totient :\n        begin\n          rw [filter_union, \u2190filter_coprime_Ico_eq_totient a (k + n % a + a * i)],\n          apply card_union_le,\n        end\n  ... \u2264 a.totient * i + a.totient + a.totient : add_le_add_right ih (totient a),\nend\n\nopen zmod\n\n/-- Note this takes an explicit `fintype ((zmod n)\u02e3)` argument to avoid trouble with instance\ndiamonds. -/\n@[simp] lemma _root_.zmod.card_units_eq_totient (n : \u2115) [fact (0 < n)] [fintype ((zmod n)\u02e3)] :\n  fintype.card ((zmod n)\u02e3) = \u03c6 n :=\ncalc fintype.card ((zmod n)\u02e3) = fintype.card {x : zmod n // x.val.coprime n} :\n  fintype.card_congr zmod.units_equiv_coprime\n... = \u03c6 n :\nbegin\n  apply finset.card_congr (\u03bb (a : {x : zmod n // x.val.coprime n}) _, a.1.val),\n  { intro a, simp [(a : zmod n).val_lt, a.prop.symm] {contextual := tt} },\n  { intros _ _ _ _ h, rw subtype.ext_iff_val, apply val_injective, exact h, },\n  { intros b hb,\n    rw [finset.mem_filter, finset.mem_range] at hb,\n    refine \u27e8\u27e8b, _\u27e9, finset.mem_univ _, _\u27e9,\n    { let u := unit_of_coprime b hb.2.symm,\n      exact val_coe_unit_coprime u },\n    { show zmod.val (b : zmod n) = b,\n      rw [val_nat_cast, nat.mod_eq_of_lt hb.1], } }\nend\n\nlemma totient_even {n : \u2115} (hn : 2 < n) : even n.totient :=\nbegin\n  haveI : fact (1 < n) := \u27e8one_lt_two.trans hn\u27e9,\n  suffices : 2 = order_of (-1 : (zmod n)\u02e3),\n  { rw [\u2190 zmod.card_units_eq_totient, even_iff_two_dvd, this], exact order_of_dvd_card_univ },\n  rw [\u2190order_of_units, units.coe_neg_one, order_of_neg_one, ring_char.eq (zmod n) n, if_neg hn.ne'],\nend\n\nlemma totient_mul {m n : \u2115} (h : m.coprime n) : \u03c6 (m * n) = \u03c6 m * \u03c6 n :=\nif hmn0 : m * n = 0\n  then by cases nat.mul_eq_zero.1 hmn0 with h h;\n    simp only [totient_zero, mul_zero, zero_mul, h]\n  else\n  begin\n    haveI : fact (0 < (m * n)) := \u27e8nat.pos_of_ne_zero hmn0\u27e9,\n    haveI : fact (0 < m) := \u27e8nat.pos_of_ne_zero $ left_ne_zero_of_mul hmn0\u27e9,\n    haveI : fact (0 < n) := \u27e8nat.pos_of_ne_zero $ right_ne_zero_of_mul hmn0\u27e9,\n    rw [\u2190 zmod.card_units_eq_totient, \u2190 zmod.card_units_eq_totient,\n      \u2190 zmod.card_units_eq_totient, fintype.card_congr\n      (units.map_equiv (zmod.chinese_remainder h).to_mul_equiv).to_equiv,\n      fintype.card_congr (@mul_equiv.prod_units (zmod m) (zmod n) _ _).to_equiv,\n      fintype.card_prod]\n  end\n\n\n\n/-- When `p` is prime, then the totient of `p ^ (n + 1)` is `p ^ n * (p - 1)` -/\nlemma totient_prime_pow_succ {p : \u2115} (hp : p.prime) (n : \u2115) :\n  \u03c6 (p ^ (n + 1)) = p ^ n * (p - 1) :=\ncalc \u03c6 (p ^ (n + 1))\n    = ((range (p ^ (n + 1))).filter (coprime (p ^ (n + 1)))).card :\n  totient_eq_card_coprime _\n... = (range (p ^ (n + 1)) \\ ((range (p ^ n)).image (* p))).card :\n  congr_arg card begin\n    rw [sdiff_eq_filter],\n    apply filter_congr,\n    simp only [mem_range, mem_filter, coprime_pow_left_iff n.succ_pos,\n      mem_image, not_exists, hp.coprime_iff_not_dvd],\n    intros a ha,\n    split,\n    { rintros hap b _ rfl,\n      exact hap (dvd_mul_left _ _) },\n    { rintros h \u27e8b, rfl\u27e9,\n      rw [pow_succ] at ha,\n      exact h b (lt_of_mul_lt_mul_left ha (zero_le _)) (mul_comm _ _) }\n  end\n... = _ :\nhave h1 : set.inj_on (* p) (range (p ^ n)),\n  from \u03bb x _ y _, (nat.mul_left_inj hp.pos).1,\nhave h2 : (range (p ^ n)).image (* p) \u2286 range (p ^ (n + 1)),\n  from \u03bb a, begin\n    simp only [mem_image, mem_range, exists_imp_distrib],\n    rintros b h rfl,\n    rw [pow_succ'],\n    exact (mul_lt_mul_right hp.pos).2 h\n  end,\nbegin\n  rw [card_sdiff h2, card_image_of_inj_on h1, card_range,\n    card_range, \u2190 one_mul (p ^ n), pow_succ, \u2190 tsub_mul,\n    one_mul, mul_comm]\nend\n\n/-- When `p` is prime, then the totient of `p ^ n` is `p ^ (n - 1) * (p - 1)` -/\nlemma totient_prime_pow {p : \u2115} (hp : p.prime) {n : \u2115} (hn : 0 < n) :\n  \u03c6 (p ^ n) = p ^ (n - 1) * (p - 1) :=\nby rcases exists_eq_succ_of_ne_zero (pos_iff_ne_zero.1 hn) with \u27e8m, rfl\u27e9;\n  exact totient_prime_pow_succ hp _\n\nlemma totient_prime {p : \u2115} (hp : p.prime) : \u03c6 p = p - 1 :=\nby rw [\u2190 pow_one p, totient_prime_pow hp]; simp\n\nlemma totient_mul_of_prime_of_dvd {p n : \u2115} (hp : p.prime) (h : p \u2223 n) :\n  (p * n).totient = p * n.totient :=\nbegin\n  by_cases hzero : n = 0,\n  { simp [hzero] },\n  { have hfin := (multiplicity.finite_nat_iff.2 \u27e8hp.ne_one, zero_lt_iff.2 hzero\u27e9),\n    have h0 : 0 < (multiplicity p n).get hfin := multiplicity.pos_of_dvd hfin h,\n    obtain \u27e8m, hm, hndiv\u27e9 := multiplicity.exists_eq_pow_mul_and_not_dvd hfin,\n    rw [hm, \u2190 mul_assoc, \u2190 pow_succ, nat.totient_mul (coprime_comm.mp (hp.coprime_pow_of_not_dvd\n      hndiv)), nat.totient_mul (coprime_comm.mp (hp.coprime_pow_of_not_dvd hndiv)), \u2190 mul_assoc],\n    congr,\n    rw [ \u2190 succ_pred_eq_of_pos h0, totient_prime_pow_succ hp, totient_prime_pow_succ hp,\n      succ_pred_eq_of_pos h0, \u2190 mul_assoc p, \u2190 pow_succ, \u2190 succ_pred_eq_of_pos h0, nat.pred_succ] }\nend\n\nlemma totient_eq_iff_prime {p : \u2115} (hp : 0 < p) : p.totient = p - 1 \u2194 p.prime :=\nbegin\n  refine \u27e8\u03bb h, _, totient_prime\u27e9,\n  replace hp : 1 < p,\n  { apply lt_of_le_of_ne,\n    { rwa succ_le_iff },\n    { rintro rfl,\n      rw [totient_one, tsub_self] at h,\n      exact one_ne_zero h } },\n  rw [totient_eq_card_coprime, range_eq_Ico, \u2190Ico_insert_succ_left hp.le, finset.filter_insert,\n      if_neg (not_coprime_of_dvd_of_dvd hp (dvd_refl p) (dvd_zero p)), \u2190nat.card_Ico 1 p] at h,\n  refine p.prime_of_coprime hp (\u03bb n hn hnz, finset.filter_card_eq h n $ finset.mem_Ico.mpr \u27e8_, hn\u27e9),\n  rwa [succ_le_iff, pos_iff_ne_zero],\nend\n\nlemma card_units_zmod_lt_sub_one {p : \u2115} (hp : 1 < p) [fintype ((zmod p)\u02e3)] :\n  fintype.card ((zmod p)\u02e3) \u2264 p - 1 :=\nbegin\n  haveI : fact (0 < p) := \u27e8zero_lt_one.trans hp\u27e9,\n  rw zmod.card_units_eq_totient p,\n  exact nat.le_pred_of_lt (nat.totient_lt p hp),\nend\n\nlemma prime_iff_card_units (p : \u2115) [fintype ((zmod p)\u02e3)] :\n  p.prime \u2194 fintype.card ((zmod p)\u02e3) = p - 1 :=\nbegin\n  by_cases hp : p = 0,\n  { substI hp,\n    simp only [zmod, not_prime_zero, false_iff, zero_tsub],\n    -- the substI created an non-defeq but subsingleton instance diamond; resolve it\n    suffices : fintype.card \u2124\u02e3 \u2260 0, { convert this },\n    simp },\n  haveI : fact (0 < p) := \u27e8nat.pos_of_ne_zero hp\u27e9,\n  rw [zmod.card_units_eq_totient, nat.totient_eq_iff_prime (fact.out (0 < p))],\nend\n\n@[simp] lemma totient_two : \u03c6 2 = 1 :=\n(totient_prime prime_two).trans (by norm_num)\n\nend nat\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/nat/totient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7353488410525322}}
{"text": "import algebra.big_operators.basic data.nat.digits\n\n/-! # IMO 2010 A4 -/\n\nnamespace IMOSL\nnamespace IMO2010A4\n\nopen finset\n\ndef x : \u2115 \u2192 bool := nat.binary_rec ff (\u03bb odd k, bxor (bor odd k.bodd))\ndef S (n : \u2115) : \u2124 := (range n).sum (\u03bb k, cond (x k) (-1) 1)\n\n\n\nsection x_prop\n\nprivate lemma x_zero : x 0 = ff := nat.binary_rec_zero ff _\n\nprivate lemma x_mul2 (k : \u2115) : x (2 * k) = bxor k.bodd (x k) :=\nbegin\n  rw [x, \u2190 nat.bit0_val],\n  refine nat.binary_rec_eq _ ff k,\n  rw [ff_bor, bxor_ff, nat.bodd_zero]\nend\n\nprivate lemma x_mul2_add1 (k : \u2115) : x (2 * k + 1) = !(x k) :=\nbegin\n  rw [x, \u2190 nat.bit1_val, \u2190 tt_bxor],\n  refine nat.binary_rec_eq _ tt k,\n  rw [ff_bor, bxor_ff, nat.bodd_zero]\nend\n\nprivate lemma x_mul4_lem1 (k : \u2115) : x (4 * k + 1) = !(x (4 * k)) :=\n  by rw [bit0, \u2190 two_mul, mul_assoc, x_mul2, x_mul2_add1, \u2190 nat.bit0_val, nat.bodd_bit0, ff_bxor]\n\nprivate lemma x_mul4_lem2 (k : \u2115) : x (4 * k + 2) = x k :=\n  by rw [bit0, \u2190 two_mul, mul_assoc, \u2190 mul_add_one, x_mul2,\n    x_mul2_add1, \u2190 nat.bit1_val, nat.bodd_bit1, tt_bxor, bnot_bnot]\n\nprivate lemma x_mul4_lem3 (k : \u2115) : x (4 * k + 3) = x k :=\n  by rw [bit0, \u2190 two_mul, bit1, \u2190 add_assoc, mul_assoc,\n    \u2190 mul_add_one, x_mul2_add1, x_mul2_add1, bnot_bnot]\n\nend x_prop\n\n\n\nsection S_prop\n\nprivate lemma S_zero : S 0 = 0 := rfl\n\nprivate lemma S_succ (a : \u2115) : S a.succ = S a + cond (x a) (-1) 1 :=\n  sum_range_succ _ a\n\nprivate lemma S_mul4_add2 (k : \u2115) : S (4 * k + 2) = S (4 * k) :=\nbegin\n  rw [S_succ, S_succ, add_assoc, add_right_eq_self, x_mul4_lem1],\n  generalize : x (4 * k) = b,\n  cases b; refl\nend\n\nprivate lemma S_mul4 : \u2200 k : \u2115, S (4 * k) = 2 * S k\n| 0 := rfl\n| (k+1) := by rw [nat.mul_succ, bit0, S_succ, x_mul4_lem3, S_succ, x_mul4_lem2,\n  S_mul4_add2, S_mul4, add_assoc, \u2190 two_mul, \u2190 mul_add, \u2190 S_succ]\n\nprivate lemma S_parity : \u2200 k : \u2115, (S k).bodd = k.bodd\n| 0 := rfl\n| (k+1) := begin\n  rw [nat.bodd_succ, S_succ, int.bodd_add, S_parity, \u2190 bxor_tt],\n  generalize : x k = b,\n  cases b; refl\nend\n\nprivate lemma S_four_mul_add_eq_zero_iff (q : \u2115) {r : \u2115} (h : r < 4) :\n  S (4 * q + r) = 0 \u2194 S q = 0 \u2227 (r = 0 \u2228 r = 2) :=\nbegin\n  ---- If `S_q = 0` and `r \u2208 {0, 2}`, then `S_{4q + r} = 0`\n  symmetry; refine \u27e8\u03bb h0, _, \u03bb h0, (and_iff_right_of_imp _).mpr _\u27e9,\n  rcases h0 with \u27e8h0, rfl | rfl\u27e9,\n  rw [add_zero, S_mul4, h0, mul_zero],\n  rw [S_mul4_add2, S_mul4, h0, mul_zero],\n\n  ---- If `S_{4q + r} = 0` and `r \u2208 {0, 2}`, then `S_q = 0`\n  replace h : (2 : \u2124) \u2260 0 := two_ne_zero,\n  rintros (rfl | rfl),\n  rwa [add_zero, S_mul4, mul_eq_zero, or_iff_right h] at h0,\n  rwa [S_mul4_add2, S_mul4, mul_eq_zero, or_iff_right h] at h0,\n\n  ---- If `S_{4q + r} = 0`, then `r \u2208 {0, 2}`\n  apply_fun int.bodd at h0,\n  rw [int.bodd_zero, S_parity, nat.bodd_add, nat.bodd_mul, nat.bodd_bit0, ff_band, ff_bxor] at h0,\n  iterate 3 { rw nat.lt_succ_iff_lt_or_eq at h },\n  rw [nat.lt_one_iff, or_assoc, or_or_or_comm] at h,\n  revert h; refine (or_iff_left _).mp,\n  rintros (rfl | rfl); exact tt_eq_ff_eq_false h0\nend\n\nend S_prop\n\n\n\n\n\n/-- Final solution -/\ntheorem final_solution : \u2200 k : \u2115, 0 \u2264 S k :=\nbegin\n  ---- Reduce to showing that `x_k = ff` whenever `S_k = 0`\n  suffices : \u2200 k : \u2115, S k = 0 \u2192 x k = ff,\n  { intros k; induction k with k k_ih,\n    rw S_zero,\n    rw [le_iff_lt_or_eq, int.lt_iff_add_one_le, zero_add, or_comm] at k_ih,\n    rw S_succ; cases k_ih with h h,\n    rw [\u2190 h, zero_add, this k h.symm, bool.cond_ff]; exact zero_le_one,\n    rw \u2190 add_neg_self (1 : \u2124); refine add_le_add h _,\n    generalize : x k = b,\n    clear this h k; cases b,\n    rw [bool.cond_ff, neg_le_self_iff]; exact zero_le_one,\n    rw bool.cond_tt },\n  \n  ---- Now show that `x_k = ff` whenever `S_k = 0`, using strong induction\n  intros k h; induction k using nat.strong_induction_on with k k_ih,\n  obtain \u27e8q, r, h0, rfl\u27e9 : \u2203 q r : \u2115, r < 4 \u2227 4 * q + r = k :=\n    \u27e8k / 4, k % 4, nat.mod_lt k four_pos, nat.div_add_mod k 4\u27e9,\n  rw [S_four_mul_add_eq_zero_iff q h0, or_comm] at h,\n  clear h0; rcases h with \u27e8h, rfl | rfl\u27e9,\n  rw x_mul4_lem2; exact k_ih q (lt_add_of_le_of_pos (nat.le_mul_of_pos_left four_pos) two_pos) h,\n  rcases q.eq_zero_or_pos with rfl | h0,\n  rw [add_zero, mul_zero, x_zero],\n  replace k_ih := k_ih q (lt_mul_left h0 $ nat.succ_lt_succ $ nat.succ_pos 2) h,\n  apply_fun int.bodd at h; rw [int.bodd_zero, S_parity] at h,\n  rw [add_zero, bit0, \u2190 two_mul, mul_assoc, x_mul2, nat.bodd_mul,\n      nat.bodd_bit0, ff_band, ff_bxor, x_mul2, h, k_ih, ff_bxor]\nend\n\n\n\n/-- Extra part -/\ntheorem final_solution_extra (k : \u2115) :\n  S k = 0 \u2194 \u2200 c : \u2115, c \u2208 nat.digits 4 k \u2192 c = 0 \u2228 c = 2 :=\nbegin\n  induction k using nat.strong_induction_on with k k_ih,\n  obtain \u27e8q, r, h, rfl\u27e9 : \u2203 q r : \u2115, r < 4 \u2227 4 * q + r = k :=\n    \u27e8k / 4, k % 4, nat.mod_lt k four_pos, nat.div_add_mod k 4\u27e9,\n  rw S_four_mul_add_eq_zero_iff q h,\n  rcases q.eq_zero_or_pos with rfl | h0,\n\n  ---- Case 1: `q = 0`\n  rw [S_zero, eq_self_iff_true, true_and, mul_zero, zero_add],\n  rcases r.eq_zero_or_pos with rfl | h0,\n  rw [eq_self_iff_true, true_or, true_iff, nat.digits_zero],\n  intros c h0; exfalso; exact h0,\n  rw [nat.digits_def' (le_add_self : 2 \u2264 2 + 2) h0,\n      nat.mod_eq_of_lt h, nat.div_eq_zero h, nat.digits_zero],\n  simp_rw list.mem_singleton; rw forall_eq,\n\n  ---- Case 2: `0 < q`\n  replace k_ih := k_ih q (nat.lt_add_right q (4 * q) r (lt_mul_left h0 (by norm_num : 1 < 4))),\n  rw [k_ih, add_comm, nat.digits_add 4 le_add_self r q h (or.inr h0)]; clear k_ih h h0,\n  simp_rw list.mem_cons_iff; rw [forall_eq_or_imp, and_comm]\nend\n\nend IMO2010A4\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2010/A4/A4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7352750404744196}}
{"text": "-- Theorems/Exercises from \"Logical Investigations, with the Nuprl Proof Assistant\"\n-- by Robert L. Constable and Anne Trostle\n-- http://www.nuprl.org/MathLibrary/LogicalInvestigations/\nimport logic\n\n-- 2. The Minimal Implicational Calculus\ntheorem thm1 {A B : Prop} : A \u2192 B \u2192 A :=\nassume Ha Hb, Ha\n\ntheorem thm2 {A B C : Prop} : (A \u2192 B) \u2192 (A \u2192 B \u2192 C) \u2192 (A \u2192 C) :=\nassume Hab Habc Ha,\n  Habc Ha (Hab Ha)\n\ntheorem thm3 {A B C : Prop} : (A \u2192 B) \u2192 (B \u2192 C) \u2192 (A \u2192 C) :=\nassume Hab Hbc Ha,\n  Hbc (Hab Ha)\n\n-- 3. False Propositions and Negation\ntheorem thm4 {P Q : Prop} : \u00acP \u2192 P \u2192 Q :=\nassume Hnp Hp,\n  absurd Hp Hnp\n\ntheorem thm5 {P : Prop} : P \u2192 \u00ac\u00acP :=\nassume (Hp : P) (HnP : \u00acP),\n  absurd Hp HnP\n\ntheorem thm6 {P Q : Prop} : (P \u2192 Q) \u2192 (\u00acQ \u2192 \u00acP) :=\nassume (Hpq : P \u2192 Q) (Hnq : \u00acQ) (Hp : P),\n  have Hq : Q, from Hpq Hp,\n  show false, from absurd Hq Hnq\n\ntheorem thm7 {P Q : Prop} : (P \u2192 \u00acP) \u2192 (P \u2192 Q) :=\nassume Hpnp Hp,\n  absurd Hp (Hpnp Hp)\n\ntheorem thm8 {P Q : Prop} : \u00ac(P \u2192 Q) \u2192 (P \u2192 \u00acQ) :=\nassume (Hn : \u00ac(P \u2192 Q)) (Hp : P) (Hq : Q),\n  -- Rermak we don't even need the hypothesis Hp\n  have H : P \u2192 Q, from assume H', Hq,\n  absurd H Hn\n\n-- 4. Conjunction and Disjunction\ntheorem thm9 {P : Prop} : (P \u2228 \u00acP) \u2192 (\u00ac\u00acP \u2192 P) :=\nassume (em : P \u2228 \u00acP) (Hnn : \u00ac\u00acP),\n  or.elim em\n    (assume Hp, Hp)\n    (assume Hn, absurd Hn Hnn)\n\ntheorem thm10 {P : Prop} : \u00ac\u00ac(P \u2228 \u00acP) :=\nassume Hnem : \u00ac(P \u2228 \u00acP),\n  have Hnp : \u00acP, from\n    assume Hp : P,\n      have Hem : P \u2228 \u00acP, from or.inl Hp,\n      absurd Hem Hnem,\n  have Hem : P \u2228 \u00acP, from or.inr Hnp,\n  absurd Hem Hnem\n\ntheorem thm11 {P Q : Prop} : \u00acP \u2228 \u00acQ \u2192 \u00ac(P \u2227 Q) :=\nassume (H : \u00acP \u2228 \u00acQ) (Hn : P \u2227 Q),\n  or.elim H\n    (assume Hnp : \u00acP, absurd (and.elim_left Hn) Hnp)\n    (assume Hnq : \u00acQ, absurd (and.elim_right Hn) Hnq)\n\ntheorem thm12 {P Q : Prop} : \u00ac(P \u2228 Q) \u2192 \u00acP \u2227 \u00acQ :=\nassume H : \u00ac(P \u2228 Q),\n  have Hnp : \u00acP, from assume Hp : P, absurd (or.inl Hp) H,\n  have Hnq : \u00acQ, from assume Hq : Q, absurd (or.inr Hq) H,\n  and.intro Hnp Hnq\n\ntheorem thm13 {P Q : Prop} : \u00acP \u2227 \u00acQ \u2192 \u00ac(P \u2228 Q) :=\nassume (H : \u00acP \u2227 \u00acQ) (Hn : P \u2228 Q),\n  or.elim Hn\n    (assume Hp : P, absurd Hp (and.elim_left H))\n    (assume Hq : Q, absurd Hq (and.elim_right H))\n\ntheorem thm14 {P Q : Prop} : \u00acP \u2228 Q \u2192 P \u2192 Q :=\nassume (Hor : \u00acP \u2228 Q) (Hp : P),\n  or.elim Hor\n    (assume Hnp : \u00acP, absurd Hp Hnp)\n    (assume Hq : Q, Hq)\n\ntheorem thm15 {P Q : Prop} : (P \u2192 Q) \u2192 \u00ac\u00ac(\u00acP \u2228 Q) :=\nassume (Hpq : P \u2192 Q) (Hn : \u00ac(\u00acP \u2228 Q)),\n  have H1 : \u00ac\u00acP \u2227 \u00acQ, from thm12 Hn,\n  have Hnp : \u00acP, from mt Hpq (and.elim_right H1),\n  absurd Hnp (and.elim_left H1)\n\ntheorem thm16 {P Q : Prop} : (P \u2192 Q) \u2227 ((P \u2228 \u00acP) \u2228 (Q \u2228 \u00acQ)) \u2192 \u00acP \u2228 Q :=\nassume H : (P \u2192 Q) \u2227 ((P \u2228 \u00acP) \u2228 (Q \u2228 \u00acQ)),\n  have Hpq : P \u2192 Q, from and.elim_left H,\n  or.elim (and.elim_right H)\n    (assume Hem1 : P \u2228 \u00acP, or.elim Hem1\n      (assume Hp : P, or.inr (Hpq Hp))\n      (assume Hnp : \u00acP, or.inl Hnp))\n    (assume Hem2 : Q \u2228 \u00acQ, or.elim Hem2\n      (assume Hq : Q, or.inr Hq)\n      (assume Hnq : \u00acQ, or.inl (mt Hpq Hnq)))\n\n-- 5. First-Order Logic: All and Exists\nsection\nvariables {T : Type} {C : Prop} {P : T \u2192 Prop}\ntheorem thm17a : (C \u2192 \u2200x, P x) \u2192 (\u2200x, C \u2192 P x) :=\nassume H : C \u2192 \u2200x, P x,\n  take x : T, assume Hc : C,\n  H Hc x\n\ntheorem thm17b : (\u2200x, C \u2192 P x) \u2192 (C \u2192 \u2200x, P x) :=\nassume (H : \u2200x, C \u2192 P x) (Hc : C),\n  take x : T,\n  H x Hc\n\ntheorem thm18a : ((\u2203x, P x) \u2192 C) \u2192 (\u2200x, P x \u2192 C) :=\nassume H : (\u2203x, P x) \u2192 C,\n  take x, assume Hp : P x,\n  have Hex : \u2203x, P x, from exists.intro x Hp,\n  H Hex\n\ntheorem thm18b : (\u2200x, P x \u2192 C) \u2192 (\u2203x, P x) \u2192 C :=\nassume (H1 : \u2200x, P x \u2192 C) (H2 : \u2203x, P x),\n  obtain (w : T) (Hw : P w), from H2,\n  H1 w Hw\n\ntheorem thm19a : (C \u2228 \u00acC) \u2192 (\u2203x : T, true) \u2192 (C \u2192 (\u2203x, P x)) \u2192 (\u2203x, C \u2192 P x) :=\nassume (Hem : C \u2228 \u00acC) (Hin : \u2203x : T, true) (H1 : C \u2192 \u2203x, P x),\n  or.elim Hem\n    (assume Hc : C,\n      obtain (w : T) (Hw : P w), from H1 Hc,\n      have Hr : C \u2192 P w, from assume Hc, Hw,\n      exists.intro w Hr)\n    (assume Hnc : \u00acC,\n      obtain (w : T) (Hw : true), from Hin,\n      have Hr : C \u2192 P w, from assume Hc, absurd Hc Hnc,\n      exists.intro w Hr)\n\ntheorem thm19b : (\u2203x, C \u2192 P x) \u2192 C \u2192 (\u2203x, P x) :=\nassume (H : \u2203x, C \u2192 P x) (Hc : C),\n  obtain (w : T) (Hw : C \u2192 P w), from H,\n  exists.intro w (Hw Hc)\n\ntheorem thm20a : (C \u2228 \u00acC) \u2192 (\u2203x : T, true) \u2192 ((\u00ac\u2200x, P x) \u2192 \u2203x, \u00acP x) \u2192 ((\u2200x, P x) \u2192 C) \u2192 (\u2203x, P x \u2192 C) :=\nassume Hem Hin Hnf H,\n  or.elim Hem\n    (assume Hc : C,\n      obtain (w : T) (Hw : true), from Hin,\n      exists.intro w (assume H : P w, Hc))\n    (assume Hnc : \u00acC,\n      have H1 : \u00ac(\u2200x, P x), from mt H Hnc,\n      have H2 : \u2203x, \u00acP x, from Hnf H1,\n      obtain (w : T) (Hw : \u00acP w), from H2,\n      exists.intro w (assume H : P w, absurd H Hw))\n\ntheorem thm20b : (\u2203x, P x \u2192 C) \u2192 (\u2200 x, P x) \u2192 C :=\nassume Hex Hall,\n  obtain (w : T) (Hw : P w \u2192 C), from Hex,\n  Hw (Hall w)\n\ntheorem thm21a : (\u2203x : T, true) \u2192 ((\u2203x, P x) \u2228 C) \u2192 (\u2203x, P x \u2228 C) :=\nassume Hin H,\n  or.elim H\n    (assume Hex : \u2203x, P x,\n      obtain (w : T) (Hw : P w), from Hex,\n      exists.intro w (or.inl Hw))\n    (assume Hc  : C,\n      obtain (w : T) (Hw : true), from Hin,\n      exists.intro w (or.inr Hc))\n\ntheorem thm21b : (\u2203x, P x \u2228 C) \u2192 ((\u2203x, P x) \u2228 C) :=\nassume H,\n  obtain (w : T) (Hw : P w \u2228 C), from H,\n  or.elim Hw\n    (assume H : P w, or.inl (exists.intro w H))\n    (assume Hc : C, or.inr Hc)\n\ntheorem thm22a : (\u2200x, P x) \u2228 C \u2192 \u2200x, P x \u2228 C :=\nassume H, take x,\n  or.elim H\n    (assume Hl, or.inl (Hl x))\n    (assume Hr, or.inr Hr)\n\ntheorem thm22b : (C \u2228 \u00acC) \u2192 (\u2200x, P x \u2228 C) \u2192 ((\u2200x, P x) \u2228 C) :=\nassume Hem H1,\n  or.elim Hem\n    (assume Hc : C,   or.inr Hc)\n    (assume Hnc : \u00acC,\n      have Hx : \u2200x, P x, from\n        take x,\n        have H1 : P x \u2228 C, from H1 x,\n        or_resolve_left H1 Hnc,\n      or.inl Hx)\n\ntheorem thm23a : (\u2203x, P x) \u2227 C \u2192 (\u2203x, P x \u2227 C) :=\nassume H,\n  have Hex : \u2203x, P x, from and.elim_left H,\n  have Hc : C, from and.elim_right H,\n  obtain (w : T) (Hw : P w), from Hex,\n  exists.intro w (and.intro Hw Hc)\n\ntheorem thm23b : (\u2203x, P x \u2227 C) \u2192 (\u2203x, P x) \u2227 C :=\nassume H,\n  obtain (w : T) (Hw : P w \u2227 C), from H,\n  have Hex : \u2203x, P x, from exists.intro w (and.elim_left Hw),\n  and.intro Hex (and.elim_right Hw)\n\ntheorem thm24a : (\u2200x, P x) \u2227 C \u2192 (\u2200x, P x \u2227 C) :=\nassume H, take x,\n  and.intro (and.elim_left H x) (and.elim_right H)\n\ntheorem thm24b : (\u2203x : T, true) \u2192 (\u2200x, P x \u2227 C) \u2192 (\u2200x, P x) \u2227 C :=\nassume Hin H,\n  obtain (w : T) (Hw : true), from Hin,\n  have Hc : C, from and.elim_right (H w),\n  have Hx : \u2200x, P x, from take x, and.elim_left (H x),\n  and.intro Hx Hc\n\nend -- of section\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/examples/ex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7352750401}}
{"text": "import .nat ...mathlib.data.int.basic\n\nnamespace int\n\nlemma le_iff_zero_le_sub (a b) : a \u2264 b \u2194 (0 : int) \u2264 b - a := \nbegin\n  rewrite le_sub, simp\nend\n\nlemma abs_dvd (x y : int) : has_dvd.dvd (abs x) y \u2194 has_dvd.dvd x y :=\nbegin rewrite abs_eq_nat_abs, apply nat_abs_dvd end\n\nlemma mul_nonzero {z y : int} : z \u2260 0 \u2192 y \u2260 0 \u2192 z * y \u2260 0 := \nbegin\n  intros hm hn hc, apply hm,\n  apply eq.trans, apply eq.symm, \n  apply int.mul_div_cancel,\n  apply hn, rewrite hc, apply int.zero_div\nend \n\nlemma div_nonzero (z y : int) : z \u2260 0 \u2192 has_dvd.dvd y z \u2192 (z / y) \u2260 0 := \nbegin\n  intros hz hy hc, apply hz,\n  apply eq.trans, apply eq.symm, \n  apply int.div_mul_cancel, apply hy,\n  rewrite hc, apply zero_mul,\nend\n\nlemma nat_abs_nonzero (z : int) : z \u2260 0 \u2192 int.nat_abs z \u2260 0 := \nbegin\n  intro hz, cases z with n n, simp,\n  apply nat.neq_zero_of_of_nat_neq_zero hz,\n  simp, intro hc, cases hc\nend\n\nlemma dvd_iff_nat_abs_dvd_nat_abs {x y : int} : \n  (has_dvd.dvd x y)\n  \u2194 (has_dvd.dvd (int.nat_abs x) (int.nat_abs y)) :=\nbegin\n  rewrite iff.symm int.coe_nat_dvd,\n  rewrite int.nat_abs_dvd, rewrite int.dvd_nat_abs\nend\n\ndef lcm (x y : int) : int :=\n  (nat.lcm (nat_abs x) (nat_abs y))\n\nlemma lcm_dvd {x y z : int} (hx : has_dvd.dvd x z) (hy : y \u2223 z) : lcm x y \u2223 z :=\nbegin\n  rewrite dvd_iff_nat_abs_dvd_nat_abs, \n  rewrite dvd_iff_nat_abs_dvd_nat_abs at hx, \n  rewrite dvd_iff_nat_abs_dvd_nat_abs at hy,\n  unfold lcm, rewrite nat_abs_of_nat,\n  apply nat.lcm_dvd; assumption\nend\n\nlemma lcm_one_right (z : int) :\n  lcm z 1 = abs z :=\nbegin\n  unfold lcm, simp, rewrite nat.lcm_one_right, \n  cases (classical.em (0 \u2264 z)) with hz hz,\n  rewrite abs_eq_nat_abs, \n  rewrite not_le at hz, \n  apply @eq.trans _ _ (\u2191(nat_abs z)), refl,\n  rewrite (@of_nat_nat_abs_of_nonpos z _),\n  rewrite abs_of_neg, apply hz,\n  apply le_of_lt hz\nend\n\ndef lcms : list int \u2192 int\n| [] := 1 \n| (z::zs) := lcm z (lcms zs)\n\nlemma dvd_lcm_left : \u2200 (x y : int), has_dvd.dvd x (lcm x y) := \nbegin\n  intros x y, unfold lcm, rewrite iff.symm (abs_dvd _ _),\n  rewrite abs_eq_nat_abs, rewrite coe_nat_dvd,\n  apply nat.dvd_lcm_left\nend\n\nlemma dvd_lcm_right : \u2200 (x y : int), has_dvd.dvd y (lcm x y) :=\nbegin\n  intros x y, unfold lcm, rewrite iff.symm (abs_dvd _ _),\n  rewrite abs_eq_nat_abs, rewrite coe_nat_dvd,\n  apply nat.dvd_lcm_right\nend\nlemma dvd_lcms {x : int} : \u2200 {zs : list int}, x \u2208 zs \u2192 has_dvd.dvd x (lcms zs) \n| [] hm := by cases hm\n| (z::zs) hm := \n  begin\n    unfold lcms, rewrite list.mem_cons_iff at hm,\n    cases hm with hm hm, subst hm,\n    apply dvd_lcm_left, \n    apply dvd_trans, apply @dvd_lcms zs hm,\n    apply dvd_lcm_right, \n  end\n\nlemma nonzero_of_pos {z : int} : z > 0 \u2192 z \u2260 0 := \nbegin intros hgt heq, subst heq, cases hgt end\n\nlemma lcm_nonneg (x y : int) : lcm x y \u2265 0 := \nby unfold lcm\n\nlemma lcms_nonneg : \u2200 (zs : list int), lcms zs \u2265 0 \n| [] := by unfold lcms \n| (z::zs) := by unfold lcms\n\nlemma lcm_pos (x y : int) : x \u2260 0 \u2192 y \u2260 0 \u2192 lcm x y > 0 := \nbegin\n  intros hx hy, unfold lcm, unfold gt,\n  rewrite coe_nat_pos, \n  let h := @nat.pos_iff_ne_zero, unfold gt at h,\n  rewrite h, apply nat.lcm_nonzero;\n  apply nat_abs_nonzero; assumption\nend\n\nlemma lcms_pos : \u2200 {zs : list int}, (\u2200 z : int, z \u2208 zs \u2192 z \u2260 0) \u2192 lcms zs > 0\n| [] _ := coe_succ_pos _\n| (z::zs) hnzs :=\n  begin\n    unfold lcms, apply lcm_pos, \n    apply hnzs _ (or.inl rfl),\n    apply nonzero_of_pos, apply lcms_pos,\n    apply list.forall_mem_of_forall_mem_cons hnzs \n  end\n\nlemma lcms_dvd {k : int} : \n  \u2200 {zs : list int}, (\u2200 z \u2208 zs, has_dvd.dvd z k) \u2192 (has_dvd.dvd (lcms zs) k) \n| [] hk := one_dvd _\n| (z::zs) hk :=\n  begin\n    unfold lcms, apply lcm_dvd,\n    apply hk _ (or.inl rfl),\n    apply lcms_dvd, \n    apply list.forall_mem_of_forall_mem_cons hk\n  end\n\nlemma lcms_distrib (xs ys zs : list int) : \n  list.equiv zs (xs \u222a ys) \n  \u2192 lcms zs = lcm (lcms xs) (lcms ys) :=\nbegin\n  intro heqv, apply dvd_antisymm,\n  apply lcms_nonneg, apply lcm_nonneg,\n  apply lcms_dvd, intros z hz,\n  rewrite (list.mem_iff_mem_of_equiv heqv) at hz,\n  rewrite list.mem_union at hz, cases hz with hz hz,\n  apply dvd_trans (dvd_lcms _) (dvd_lcm_left _ _);\n  assumption,\n  apply dvd_trans (dvd_lcms _) (dvd_lcm_right _ _);\n  assumption,\n  apply lcm_dvd; apply lcms_dvd; intros z hz;\n  apply dvd_lcms; rewrite (list.mem_iff_mem_of_equiv heqv),\n  apply list.mem_union_left hz,\n  apply list.mem_union_right _ hz\nend\n\n-- lemma dvd_of_mul_dvd_mul_left : \u2200 {x y z : int}, \n--   z \u2260 0 \u2192 has_dvd.dvd (z * x) (z * y) \u2192 has_dvd.dvd x y := sorry\n\nlemma eq_zero_of_nonpos_of_nonzero (z : int) :\n(\u00ac z < 0) \u2192 (\u00ac z > 0) \u2192 z = 0 := \nbegin\n  cases (lt_trichotomy z 0) with h h,\n  intro hc, cases (hc h),\n  cases h with h h, intros _ _, apply h,\n  intros _ hc, cases (hc h)\nend\n\nlemma sign_split (z) : \n  sign z = -1 \u2228 sign z = 0 \u2228 sign z = 1 :=\nbegin\n  cases z with n n, cases n,\n  apply or.inr (or.inl rfl),\n  apply or.inr (or.inr rfl),\n  apply or.inl rfl\nend\n\n-- lemma abs_neq_zero_of_neq_zero {z : int} (h : z \u2260 0) : abs z \u2260 0 :=\n-- begin\n--   intro hc, apply h, apply eq_zero_of_abs_eq_zero, apply hc\n-- end\n\nlemma mul_le_mul_iff_le_of_pos_left (x y z : int) :\n  z > 0 \u2192 (z * x \u2264 z * y \u2194 x \u2264 y) := \nbegin\n  intro hz, apply iff.intro; intro h,\n  let h' := @int.div_le_div _ _ z hz h,\n  repeat {rewrite mul_comm z at h',\n  rewrite int.mul_div_cancel _ (nonzero_of_pos hz) at h'},\n  apply h', repeat {rewrite mul_comm z},\n  apply int.mul_le_of_le_div hz, \n  rewrite int.mul_div_cancel _ (nonzero_of_pos hz),\n  apply h \nend\n\nlemma mul_le_mul_iff_le_of_neg_left (x y z : int) :\n  z < 0 \u2192 (z * x \u2264 z * y \u2194 y \u2264 x) := \nbegin\n  intros hz,\n  rewrite eq.symm (neg_neg z),\n  repeat {rewrite eq.symm (neg_mul_eq_neg_mul (-z) _)},\n  rewrite neg_le_neg_iff,\n  apply mul_le_mul_iff_le_of_pos_left,\n  unfold gt, rewrite lt_neg, apply hz\nend\n\nlemma dvd_iff_exists (x y) :\n  has_dvd.dvd x y \u2194 \u2203 (z : int), z * x = y := \nbegin\n  apply iff.intro; intro h, \n  existsi (y / x), apply int.div_mul_cancel h,\n  cases h with z hz, subst hz, \n  apply dvd_mul_left\nend\n\nlemma div_mul_comm (x y z : int) : has_dvd.dvd y x \u2192 (x / y) * z = x * z / y := \nbegin\n  intro h, rewrite mul_comm x, \n  rewrite int.mul_div_assoc _ h, rewrite mul_comm,\nend\n\nlemma nonneg_iff_exists (z : int) :\n  0 \u2264 z \u2194 \u2203 (n : nat), z = \u2191n :=\nbegin\n  cases z with m m, apply true_iff_true, constructor,\n  existsi m, refl, apply false_iff_false; intro hc,\n  cases hc, cases hc with m hm, cases hm\nend\n\nlemma exists_nat_diff (x y : int) (n : nat) :\n  x \u2264 y \u2192 y < x + \u2191n \u2192 \u2203 (m : nat), m < n \u2227 y = x + \u2191m := \nbegin\n  intros hxy hyx, \n  rewrite iff.symm (sub_nonneg) at hxy,\n  rewrite nonneg_iff_exists at hxy, \n  cases hxy with m hm, existsi m,\n  rewrite iff.symm sub_lt_iff_lt_add' at hyx,\n  apply and.intro, rewrite iff.symm coe_nat_lt,\n  rewrite eq.symm hm, apply hyx,\n  rewrite eq.symm hm, rewrite add_sub, simp,\nend\n\nlemma exists_lt_and_lt (x y : int) :\n  \u2203 z, z < x \u2227 z < y := \nbegin\n  cases (lt_trichotomy x y),\n  existsi (pred x), \n  apply and.intro (pred_self_lt _) (lt_trans (pred_self_lt _) h),\n  cases h with h h, subst h, \n  existsi (pred x), apply and.intro (pred_self_lt _) (pred_self_lt _),\n  existsi (pred y),\n  apply and.intro (lt_trans (pred_self_lt _) h) (pred_self_lt _)\nend\n\nlemma le_mul_of_pos_left : \u2200 {x y : int}, y \u2265 0 \u2192 x > 0 \u2192 y \u2264 x * y :=\nbegin\n  intros x y hy hx,\n  have hx' : x \u2265 1 := add_one_le_of_lt hx,\n  let h := mul_le_mul hx' (le_refl y) hy _,\n  rewrite one_mul at h, apply h, \n  apply le_of_lt hx\nend\n\nlemma lt_mul_of_nonneg_right : \u2200 {x y z : int}, x < y \u2192 y \u2265 0 \u2192 z > 0 \u2192 x < y * z :=\nbegin\n  intros x y z hxy hy hz,\n  have h := @mul_lt_mul _ _ x 1 y z hxy,\n  rewrite mul_one at h, apply h,\n  apply add_one_le_of_lt hz, \n  apply int.zero_lt_one, apply hy\nend\n\nlemma zero_mul (z : int) : \n  int.of_nat 0 * z = 0 := \neq.trans (refl _) (zero_mul _)\n\nlemma mul_zero (z : int) : \n  z * int.of_nat 0 = 0 := \neq.trans (refl _) (mul_zero _)\n\nlemma one_mul (z : int) : \n  int.of_nat 1 * z = z := \neq.trans (refl _) (one_mul _)\n\nlemma neg_one_mul (z : int) : \n  (int.neg_succ_of_nat 0) * z = -z := \neq.trans (refl _) (neg_one_mul _)\n\nlemma zero_add (z : int) : \n  int.of_nat 0 + z = z := \neq.trans (refl _) (zero_add _)\n\nlemma coe_eq_of_nat {n : nat} :\n  \u2191n = int.of_nat n := refl _\n\nlemma coe_neg_succ_eq_neg_succ_of_nat {n : nat} :\n  -\u2191(nat.succ n) = int.neg_succ_of_nat n := refl _\n\n\nend int\n", "meta": {"author": "avigad", "repo": "qelim", "sha": "b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60", "save_path": "github-repos/lean/avigad-qelim", "path": "github-repos/lean/avigad-qelim/qelim-b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60/common/int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7352750342764239}}
{"text": "-- Coprimo con potencia de primo\n-- =============================\n\nimport data.nat.prime\nopen nat.prime\n\nlemma not_dvd_of_coprime\n  {p : \u2115}\n  (h : p.prime)\n  {n k : \u2115}\n  (hc : n.coprime (p^(k + 1)))\n  : \u00ac(p \u2223 n) :=\n\u03bb hn, not_dvd_one h\nbegin\n  unfold nat.coprime at hc,\n  rw \u2190 hc,\n  exact nat.dvd_gcd hn \u27e8p^k, rfl\u27e9,\nend\n\nlemma coprime_iff_not_div\n  {p : \u2115}\n  (h : p.prime)\n  (n k : \u2115)\n  : n.coprime (p^(k + 1)) \u2194 \u00ac (p \u2223 n) :=\n\u27e8not_dvd_of_coprime h, coprime_pow_of_not_dvd h\u27e9\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Coprimo_con_potencia_de_primo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.7352726510067548}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport measure_theory.measurable_space\n\n/-\n\n# The extended nonnegative reals [0,\u221e]\n\nThe big dilemma when a designer is faced with \"minor modifications\"\nof a standard type, is whether to just stick with the standard type\nand make do, or whether to make a new type and then be faced with the\nproblem of having to make all the API for that type. Example: in measure\ntheory a key role is played by the \"extended non-negative reals\",\nnamely {x : \u211d | 0 \u2264 x} \u222a {\u221e}. In Lean these are their own type,\ncalled `ennreal`. There is a \"locale\" containing standard notation\nassociated for this type. Let's open it.\n\n\nlocalized \"notation (name := ennreal) `\u211d\u22650\u221e` := ennreal\" in ennreal\nlocalized \"notation (name := ennreal.top) `\u221e` := (\u22a4 : ennreal)\" in ennreal\n-/\n\nopen_locale ennreal\n\n#print notation \u211d\u22650\u221e\n#check ennreal\n\n\n#check \u211d\u22650\u221e -- [0,\u221e]\n\n#check \u221e -- it's the \u221e in \u211d\u22650\u221e\n\n-- What can we do with extended non-negative reals?\n\nvariables (a b : \u211d\u22650\u221e)\n\n#check a + b\n#check a - b -- surprising?\n#check a * b -- what is 0 * \u221e then?\n#check a / b -- is 1 / 0 = 0 or \u221e? In \u211d it's 0 but here there's another possibility\n\n-- See if you can find tactics (or theorems) which prove these.\nexample : (0 : \u211d\u22650\u221e) * \u221e = 0 :=\nbegin\n  sorry,\nend\n\nexample : (1 : \u211d\u22650\u221e) / 0 = \u221e :=\nbegin\n  sorry,\nend\n\nexample (a b c : \u211d\u22650\u221e) : (a + b) * c = a * c + b * c :=\nbegin\n  sorry,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section12measure_theory/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7352660272441073}}
{"text": "/-\nCopyright (c) 2019 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann, Kyle Miller, Mario Carneiro\n-/\nimport data.nat.gcd.basic\nimport logic.function.iterate\nimport data.finset.nat_antidiagonal\nimport algebra.big_operators.basic\nimport tactic.ring\nimport tactic.zify\nimport tactic.wlog\n\n/-!\n# The Fibonacci Sequence\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Summary\n\nDefinition of the Fibonacci sequence `F\u2080 = 0, F\u2081 = 1, F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081`.\n\n## Main Definitions\n\n- `nat.fib` returns the stream of Fibonacci numbers.\n\n## Main Statements\n\n- `nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.`.\n- `nat.fib_gcd`: `fib n` is a strong divisibility sequence.\n- `nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `nat.choose` along an antidiagonal.\n- `nat.fib_succ_eq_succ_sum`: shows that `F\u2080 + F\u2081 + \u22ef + F\u2099 = F\u2099\u208a\u2082 - 1`.\n- `nat.fib_two_mul` and `nat.fib_two_mul_add_one` are the basis for an efficient algorithm to\n  compute `fib` (see `nat.fast_fib`). There are `bit0`/`bit1` variants of these can be used to\n  simplify `fib` expressions: `simp only [nat.fib_bit0, nat.fib_bit1, nat.fib_bit0_succ,\n  nat.fib_bit1_succ, nat.fib_one, nat.fib_two]`.\n\n## Implementation Notes\n\nFor efficiency purposes, the sequence is defined using `stream.iterate`.\n\n## Tags\n\nfib, fibonacci\n-/\n\nopen_locale big_operators\n\nnamespace nat\n\n/--\nImplementation of the fibonacci sequence satisfying\n`fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`.\n\n*Note:* We use a stream iterator for better performance when compared to the naive recursive\nimplementation.\n-/\n@[pp_nodot]\ndef fib (n : \u2115) : \u2115 := ((\u03bb p : \u2115 \u00d7 \u2115, (p.snd, p.fst + p.snd))^[n] (0, 1)).fst\n\n@[simp] lemma fib_zero : fib 0 = 0 := rfl\n@[simp] lemma fib_one : fib 1 = 1 := rfl\n@[simp] lemma fib_two : fib 2 = 1 := rfl\n\n/-- Shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.` -/\nlemma fib_add_two {n : \u2115} : fib (n + 2) = fib n + fib (n + 1) :=\nby simp only [fib, function.iterate_succ']\n\nlemma fib_le_fib_succ {n : \u2115} : fib n \u2264 fib (n + 1) := by { cases n; simp [fib_add_two] }\n\n@[mono] lemma fib_mono : monotone fib :=\nmonotone_nat_of_le_succ $ \u03bb _, fib_le_fib_succ\n\nlemma fib_pos {n : \u2115} (n_pos : 0 < n) : 0 < fib n :=\ncalc 0 < fib 1 : dec_trivial\n   ... \u2264 fib n : fib_mono n_pos\n\nlemma fib_add_two_sub_fib_add_one {n : \u2115} : fib (n + 2) - fib (n + 1) = fib n :=\nby rw [fib_add_two, add_tsub_cancel_right]\n\nlemma fib_lt_fib_succ {n : \u2115} (hn : 2 \u2264 n) : fib n < fib (n + 1) :=\nbegin\n  rcases exists_add_of_le hn with \u27e8n, rfl\u27e9,\n  rw [\u2190 tsub_pos_iff_lt, add_comm 2, fib_add_two_sub_fib_add_one],\n  apply fib_pos (succ_pos n),\nend\n\n/-- `fib (n + 2)` is strictly monotone. -/\nlemma fib_add_two_strict_mono : strict_mono (\u03bb n, fib (n + 2)) :=\nbegin\n  refine strict_mono_nat_of_lt_succ (\u03bb n, _),\n  rw add_right_comm,\n  exact fib_lt_fib_succ (self_le_add_left _ _)\nend\n\nlemma le_fib_self {n : \u2115} (five_le_n : 5 \u2264 n) : n \u2264 fib n :=\nbegin\n  induction five_le_n with n five_le_n IH,\n  { -- 5 \u2264 fib 5\n    refl },\n  { -- n + 1 \u2264 fib (n + 1) for 5 \u2264 n\n    rw succ_le_iff,\n    calc n \u2264 fib n       : IH\n       ... < fib (n + 1) : fib_lt_fib_succ (le_trans dec_trivial five_le_n) }\nend\n\n/-- Subsequent Fibonacci numbers are coprime,\n  see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/\nlemma fib_coprime_fib_succ (n : \u2115) : nat.coprime (fib n) (fib (n + 1)) :=\nbegin\n  induction n with n ih,\n  { simp },\n  { rw [fib_add_two, coprime_add_self_right],\n    exact ih.symm }\nend\n\n/-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/\nlemma fib_add (m n : \u2115) :\n  fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) :=\nbegin\n  induction n with n ih generalizing m,\n  { simp },\n  { intros,\n    specialize ih (m + 1),\n    rw [add_assoc m 1 n, add_comm 1 n] at ih,\n    simp only [fib_add_two, ih],\n    ring, }\nend\n\nlemma fib_two_mul (n : \u2115) : fib (2 * n) = fib n * (2 * fib (n + 1) - fib n) :=\nbegin\n  cases n,\n  { simp },\n  { rw [nat.succ_eq_add_one, two_mul, \u2190add_assoc, fib_add, fib_add_two, two_mul],\n    simp only [\u2190 add_assoc, add_tsub_cancel_right],\n    ring, },\nend\n\nlemma fib_two_mul_add_one (n : \u2115) : fib (2 * n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 :=\nby { rw [two_mul, fib_add], ring }\n\nlemma fib_bit0 (n : \u2115) : fib (bit0 n) = fib n * (2 * fib (n + 1) - fib n) :=\nby rw [bit0_eq_two_mul, fib_two_mul]\n\nlemma fib_bit1 (n : \u2115) : fib (bit1 n) = fib (n + 1) ^ 2 + fib n ^ 2 :=\nby rw [nat.bit1_eq_succ_bit0, bit0_eq_two_mul, fib_two_mul_add_one]\n\nlemma fib_bit0_succ (n : \u2115) : fib (bit0 n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 := fib_bit1 n\n\nlemma fib_bit1_succ (n : \u2115) : fib (bit1 n + 1) = fib (n + 1) * (2 * fib n + fib (n + 1)) :=\nbegin\n  rw [nat.bit1_eq_succ_bit0, fib_add_two, fib_bit0, fib_bit0_succ],\n  have : fib n \u2264 2 * fib (n + 1),\n  { rw two_mul,\n    exact le_add_left fib_le_fib_succ, },\n  zify,\n  ring,\nend\n\n/-- Computes `(nat.fib n, nat.fib (n + 1))` using the binary representation of `n`.\nSupports `nat.fast_fib`. -/\ndef fast_fib_aux : \u2115 \u2192 \u2115 \u00d7 \u2115 :=\nnat.binary_rec (fib 0, fib 1) (\u03bb b n p,\n  if b\n  then (p.2^2 + p.1^2, p.2 * (2 * p.1 + p.2))\n  else (p.1 * (2 * p.2 - p.1), p.2^2 + p.1^2))\n\n/-- Computes `nat.fib n` using the binary representation of `n`.\nProved to be equal to `nat.fib` in `nat.fast_fib_eq`. -/\ndef fast_fib (n : \u2115) : \u2115 := (fast_fib_aux n).1\n\nlemma fast_fib_aux_bit_ff (n : \u2115) :\n  fast_fib_aux (bit ff n) = let p := fast_fib_aux n in (p.1 * (2 * p.2 - p.1), p.2^2 + p.1^2) :=\nbegin\n  rw [fast_fib_aux, binary_rec_eq],\n  { refl },\n  { simp },\nend\n\nlemma fast_fib_aux_bit_tt (n : \u2115) :\n  fast_fib_aux (bit tt n) = let p := fast_fib_aux n in (p.2^2 + p.1^2, p.2 * (2 * p.1 + p.2)) :=\nbegin\n  rw [fast_fib_aux, binary_rec_eq],\n  { refl },\n  { simp },\nend\n\nlemma fast_fib_aux_eq (n : \u2115) :\n  fast_fib_aux n = (fib n, fib (n + 1)) :=\nbegin\n  apply nat.binary_rec _ (\u03bb b n' ih, _) n,\n  { simp [fast_fib_aux] },\n  { cases b; simp only [fast_fib_aux_bit_ff, fast_fib_aux_bit_tt,\n      congr_arg prod.fst ih, congr_arg prod.snd ih, prod.mk.inj_iff]; split;\n    simp [bit, fib_bit0, fib_bit1, fib_bit0_succ, fib_bit1_succ], },\nend\n\nlemma fast_fib_eq (n : \u2115) : fast_fib n = fib n :=\nby rw [fast_fib, fast_fib_aux_eq]\n\nlemma gcd_fib_add_self (m n : \u2115) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) :=\nbegin\n  cases nat.eq_zero_or_pos n,\n  { rw h, simp },\n  replace h := nat.succ_pred_eq_of_pos h, rw [\u2190 h, succ_eq_add_one],\n  calc gcd (fib m) (fib (n.pred + 1 + m))\n        = gcd (fib m) (fib (n.pred) * (fib m) + fib (n.pred + 1) * fib (m + 1)) :\n    by { rw \u2190 fib_add n.pred _, ring_nf }\n    ... = gcd (fib m) (fib (n.pred + 1) * fib (m + 1)) :\n    by rw [add_comm, gcd_add_mul_right_right (fib m) _ (fib (n.pred))]\n    ... = gcd (fib m) (fib (n.pred + 1)) :\n    coprime.gcd_mul_right_cancel_right\n      (fib (n.pred + 1)) (coprime.symm (fib_coprime_fib_succ m))\nend\n\nlemma gcd_fib_add_mul_self (m n : \u2115) : \u2200 k, gcd (fib m) (fib (n + k * m)) = gcd (fib m) (fib n)\n| 0     := by simp\n| (k+1) := by rw [\u2190 gcd_fib_add_mul_self k, add_mul, \u2190 add_assoc, one_mul, gcd_fib_add_self _ _]\n\n/-- `fib n` is a strong divisibility sequence,\n  see https://proofwiki.org/wiki/GCD_of_Fibonacci_Numbers -/\n\n\nlemma fib_dvd (m n : \u2115) (h : m \u2223 n) : fib m \u2223 fib n :=\nby rwa [gcd_eq_left_iff_dvd, \u2190 fib_gcd, gcd_eq_left_iff_dvd.mp]\n\nlemma fib_succ_eq_sum_choose :\n  \u2200 (n : \u2115), fib (n + 1) = \u2211 p in finset.nat.antidiagonal n, choose p.1 p.2 :=\ntwo_step_induction rfl rfl (\u03bb n h1 h2, by\n{ rw [fib_add_two, h1, h2, finset.nat.antidiagonal_succ_succ', finset.nat.antidiagonal_succ'],\n  simp [choose_succ_succ, finset.sum_add_distrib, add_left_comm] })\n\nlemma fib_succ_eq_succ_sum (n : \u2115):\n  fib (n + 1) = (\u2211 k in finset.range n, fib k) + 1 :=\nbegin\n  induction n with n ih,\n  { simp },\n  { calc fib (n + 2) = fib n + fib (n + 1)                        : fib_add_two\n                 ... = fib n + (\u2211 k in finset.range n, fib k) + 1 : by rw [ih, add_assoc]\n                 ... = (\u2211 k in finset.range (n + 1), fib k) + 1   : by simp [finset.range_add_one] }\nend\nend nat\n\nnamespace norm_num\nopen tactic nat\n\n/-! ### `norm_num` plugin for `fib`\n\nThe `norm_num` plugin uses a strategy parallel to that of `nat.fast_fib`, but it instead\nproduces proofs of what `nat.fib` evaluates to.\n-/\n\n/-- Auxiliary definition for `prove_fib` plugin. -/\ndef is_fib_aux (n a b : \u2115) := fib n = a \u2227 fib (n + 1) = b\n\nlemma is_fib_aux_one : is_fib_aux 1 1 1 := \u27e8fib_one, fib_two\u27e9\n\nlemma is_fib_aux_bit0 {n a b c a2 b2 a' b' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a + c = bit0 b) (h2 : a * c = a')\n  (h3 : a * a = a2) (h4 : b * b = b2) (h5 : a2 + b2 = b') :\n  is_fib_aux (bit0 n) a' b' :=\n\u27e8by rw [fib_bit0, H.1, H.2, \u2190 bit0_eq_two_mul,\n  show bit0 b-a=c, by rw [\u2190 h1, nat.add_sub_cancel_left], h2],\n by rw [fib_bit0_succ, H.1, H.2, pow_two, pow_two, h3, h4, add_comm, h5]\u27e9\n\nlemma is_fib_aux_bit1 {n a b c a2 b2 a' b' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a * a = a2) (h2 : b * b = b2) (h3 : a2 + b2 = a')\n  (h4 : bit0 a + b = c) (h5 : b * c = b') :\n  is_fib_aux (bit1 n) a' b' :=\n\u27e8by rw [fib_bit1, H.1, H.2, pow_two, pow_two, h1, h2, add_comm, h3],\n by rw [fib_bit1_succ, H.1, H.2, \u2190 bit0_eq_two_mul, h4, h5]\u27e9\n\nlemma is_fib_aux_bit0_done {n a b c a' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a + c = bit0 b) (h2 : a * c = a') : fib (bit0 n) = a' :=\n(is_fib_aux_bit0 H h1 h2 rfl rfl rfl).1\n\nlemma is_fib_aux_bit1_done {n a b a2 b2 a' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a * a = a2) (h2 : b * b = b2) (h3 : a2 + b2 = a') : fib (bit1 n) = a' :=\n(is_fib_aux_bit1 H h1 h2 h3 rfl rfl).1\n\n/-- `prove_fib_aux ic n` returns `(ic', a, b, \u22a2 is_fib_aux n a b)`, where `n` is a numeral. -/\nmeta def prove_fib_aux (ic : instance_cache) :\n  expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr \u00d7 expr)\n| e :=\n  match match_numeral e with\n  | match_numeral_result.one := pure (ic, `(1:\u2115), `(1:\u2115), `(is_fib_aux_one))\n  | match_numeral_result.bit0 e := do\n    (ic, a, b, H) \u2190 prove_fib_aux e,\n    na \u2190 a.to_nat, nb \u2190 b.to_nat,\n    (ic, c) \u2190 ic.of_nat (2*nb - na),\n    (ic, h1) \u2190 prove_add_nat ic a c (`(bit0:\u2115\u2192\u2115).mk_app [b]),\n    (ic, a', h2) \u2190 prove_mul_nat ic a c,\n    (ic, a2, h3) \u2190 prove_mul_nat ic a a,\n    (ic, b2, h4) \u2190 prove_mul_nat ic b b,\n    (ic, b', h5) \u2190 prove_add_nat' ic a2 b2,\n    pure (ic, a', b', `(@is_fib_aux_bit0).mk_app\n      [e, a, b, c, a2, b2, a', b', H, h1, h2, h3, h4, h5])\n  | match_numeral_result.bit1 e := do\n    (ic, a, b, H) \u2190 prove_fib_aux e,\n    na \u2190 a.to_nat, nb \u2190 b.to_nat,\n    (ic, c) \u2190 ic.of_nat (2*na + nb),\n    (ic, a2, h1) \u2190 prove_mul_nat ic a a,\n    (ic, b2, h2) \u2190 prove_mul_nat ic b b,\n    (ic, a', h3) \u2190 prove_add_nat' ic a2 b2,\n    (ic, h4) \u2190 prove_add_nat ic (`(bit0:\u2115\u2192\u2115).mk_app [a]) b c,\n    (ic, b', h5) \u2190 prove_mul_nat ic b c,\n    pure (ic, a', b', `(@is_fib_aux_bit1).mk_app\n      [e, a, b, c, a2, b2, a', b', H, h1, h2, h3, h4, h5])\n  | _ := failed\n  end\n\n/-- A `norm_num` plugin for `fib n` when `n` is a numeral.\nUses the binary representation of `n` like `nat.fast_fib`. -/\nmeta def prove_fib (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\nmatch match_numeral e with\n| match_numeral_result.zero := pure (ic, `(0:\u2115), `(fib_zero))\n| match_numeral_result.one := pure (ic, `(1:\u2115), `(fib_one))\n| match_numeral_result.bit0 e := do\n  (ic, a, b, H) \u2190 prove_fib_aux ic e,\n  na \u2190 a.to_nat, nb \u2190 b.to_nat,\n  (ic, c) \u2190 ic.of_nat (2*nb - na),\n  (ic, h1) \u2190 prove_add_nat ic a c (`(bit0:\u2115\u2192\u2115).mk_app [b]),\n  (ic, a', h2) \u2190 prove_mul_nat ic a c,\n  pure (ic, a', `(@is_fib_aux_bit0_done).mk_app [e, a, b, c, a', H, h1, h2])\n| match_numeral_result.bit1 e := do\n  (ic, a, b, H) \u2190 prove_fib_aux ic e,\n  (ic, a2, h1) \u2190 prove_mul_nat ic a a,\n  (ic, b2, h2) \u2190 prove_mul_nat ic b b,\n  (ic, a', h3) \u2190 prove_add_nat' ic a2 b2,\n  pure (ic, a', `(@is_fib_aux_bit1_done).mk_app [e, a, b, a2, b2, a', H, h1, h2, h3])\n| _ := failed\nend\n\n/-- A `norm_num` plugin for `fib n` when `n` is a numeral.\nUses the binary representation of `n` like `nat.fast_fib`. -/\n@[norm_num] meta def eval_fib : expr \u2192 tactic (expr \u00d7 expr)\n| `(fib %%en) := do\n    n \u2190 en.to_nat,\n    match n with\n    | 0 := pure (`(0:\u2115), `(fib_zero))\n    | 1 := pure (`(1:\u2115), `(fib_one))\n    | 2 := pure (`(1:\u2115), `(fib_two))\n    | _ := do\n      c \u2190 mk_instance_cache `(\u2115),\n      prod.snd <$> prove_fib c en\n    end\n| _ := failed\n\nend norm_num\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7352660087043232}}
{"text": "import ..fglib\nimport ..basic\n\nnamespace FG\n\n/- ## 3-Dimensional Vector\n\n  `vec3` is defined with the values on the three dimensions.\n  Only the ring of real numbers (`R`) are studied here. -/\n\nstructure vec3 :=\n(x : \u211d)\n(y : \u211d)\n(z : \u211d)\n\nnamespace vec3\n\n@[ext] theorem ext (a b : vec3) :\n  a.x = b.x \u2227 a.y = b.y \u2227 a.z = b.z \u2192 a = b :=\nbegin\n  intro h,\n  cases' a,\n  cases' b,\n  simp at *,\n  assumption\nend\n\n/- `vec3` is equivalent to mathlib's `vector \u211d 3`. -/\ndef vector3 : Type := vector \u211d 3\n\n@[simp] def to_vector (v : vec3) : vector3 :=\n  \u27e8 [v.x, v.y, v.z], by refl \u27e9\n\n@[simp] def from_vector (v : vector3) : vec3 :=\n  \u27e8 v.nth 0, v.nth 1, v.nth 2 \u27e9\n\nlemma from_vector_eq (v\u2081 v\u2082 : vector3) (h : from_vector v\u2081 = from_vector v\u2082) :\n  v\u2081 = v\u2082 :=\nbegin\n  ext,\n  simp only [from_vector, vector.nth] at h,\n  cases' h with h\u2081 h,\n  cases' h with h\u2082 h\u2083,\n  fin_cases m,\n  repeat { assumption }\nend\n\ndef equiv_vector : vec3 \u2243 vector \u211d 3 :=\n{ to_fun := to_vector,\n  inv_fun := from_vector,\n  left_inv := by intro v; ext; simp [vector.nth],\n  right_inv :=\n  begin\n    intro v,\n    apply from_vector_eq,\n    simp [vector.nth]\n  end }\n\n@[simp] def zero : vec3 := \u27e80, 0, 0\u27e9\n\n@[simp] def add (a b : vec3) : vec3 :=\n  \u27e8 a.x + b.x, a.y + b.y, a.z + b.z \u27e9\n\n@[simp] def neg (a : vec3) : vec3 :=\n  \u27e8 -a.x, -a.y, -a.z \u27e9\n\n/- `vec3` is an `add_comm_group` -/\n@[simps] instance add_comm_group : add_comm_group vec3 :=\n{ zero := zero,\n  add  := add,\n  add_assoc :=\n  begin\n    intros a b c,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring }\n  end,\n  zero_add := by intro a; ext; simp,\n  add_zero := by intro a; ext; simp,\n  add_comm :=\n  begin\n    intros a b,\n    /- `simp` could not directly work on `a + b = b + a`,\n      but it could simplify `a.add b = b.add a` here,\n      Similar case in some functions below such as `add_left_neg` -/\n    have h : a.add b = b.add a := by simp; repeat { apply and.intro }; repeat { ring },\n    exact h\n  end,\n  neg := neg,\n  add_left_neg := begin\n    intro a,\n    have h : (a.neg).add a = zero := by simp; refl,\n    exact h\n  end }\n\n@[simp] def dot (a b : vec3) : \u211d :=\n  a.x * b.x + a.y * b.y + a.z * b.z\n\n/- Note that \\cdot `\u2b1d` is different from \\smul `\u2022` -/\ninfixr ` \u22c5 `:100 := dot\n\n@[simp] def smul (c : \u211d) (v : vec3) : vec3 :=\n  \u27e8 c * v.x, c * v.y, c * v.z \u27e9\n\n/- The vector space is defined as a module of `\u211d` over `vec3`-/\n@[simps] instance vector_space : module \u211d vec3 :=\n{ smul := smul,\n  one_smul := by intro b; ext; simp,\n  mul_smul :=\n  begin\n    intros x y b,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring }\n  end,\n  smul_zero :=\n  begin\n    intro r,\n    have h : smul r zero = 0 := by simp; refl,\n    exact h\n  end,\n  zero_smul :=\n  begin\n    intro r,\n    have h : smul 0 r = 0 := by simp; refl,\n    exact h\n  end,\n  smul_add :=\n  begin\n    intros r x y,\n    have h : smul r (x.add y) = (smul r x).add (smul r y) :=\n    begin\n      simp,\n      repeat { apply and.intro },\n      repeat { ring },\n    end,\n    exact h\n  end,\n  add_smul :=\n  begin\n    intros r s x,\n    have h : smul (r + s) x = smul r x + smul s x :=\n    begin\n      ext,\n      simp,\n      repeat { apply and.intro },\n      repeat { ring }\n    end,\n    exact h\n  end }\n\nend vec3\n\n/- ## 3-Demensional Matrix\n\n  It's defined with the three rows that are represented by `vec3`. -/\nstructure mat3 :=\n(x : vec3)\n(y : vec3)\n(z : vec3)\n\n/- Another way could be like this -/\n-- structure mat3 :=\n-- (xx : \u211d) (xy : \u211d) (xz : \u211d)\n-- (yx : \u211d) (yy : \u211d) (yz : \u211d)\n-- (zx : \u211d) (zy : \u211d) (zz : \u211d)\n\nnamespace mat3\n\n@[ext] theorem ext {a b : mat3} :\n  a.x = b.x \u2227 a.y = b.y \u2227 a.z = b.z \u2192 a = b :=\nbegin\n  intro h,\n  cases' a,\n  cases' b,\n  simp at *,\n  assumption\nend\n\n/- `mat3` is equivalent to mathlib's `matrix (fin 3) (fin 3) \u211d`. -/\ndef matrix3 : Type := matrix (fin 3) (fin 3) \u211d\n\n@[simp] def to_matrix (A : mat3) : matrix3 :=\n![![A.x.x, A.x.y, A.x.z],\n  ![A.y.x, A.y.y, A.y.z],\n  ![A.z.x, A.z.y, A.z.z]]\n\n@[simp] def from_matrix (A : matrix3) : mat3 :=\n\u27e8 \u27e8 A 0 0, A 0 1, A 0 2 \u27e9,\n  \u27e8 A 1 0, A 1 1, A 1 2 \u27e9,\n  \u27e8 A 2 0, A 2 1, A 2 2 \u27e9 \u27e9\n\nlemma from_matrix_eq (A\u2081 A\u2082 : matrix3) (h : from_matrix A\u2081 = from_matrix A\u2082) :\n  A\u2081 = A\u2082 :=\nbegin\n  ext,\n  simp only [from_matrix] at h,\n  rcases h with \u27e8h\u2081, h\u2082, h\u2083\u27e9,\n  fin_cases i,\n  repeat { fin_cases j,\n    repeat { simp [h\u2081, h\u2082, h\u2083] } }\nend\n\ndef equiv_matrix : mat3 \u2243 matrix3 :=\n{ to_fun := to_matrix,\n  inv_fun := from_matrix,\n  left_inv :=\n  begin\n    intro A,\n    ext,\n    simp,\n    repeat { apply and.intro },\n    { cases' A.x, refl },\n    { cases' A.y, refl },\n    { cases' A.z, refl }\n  end,\n  right_inv :=\n  begin\n    intro v,\n    apply from_matrix_eq,\n    simp\n  end }\n\n@[simp] def zero : mat3 := \u27e8 0, 0, 0 \u27e9\n\n@[simp] def I : mat3 :=\n\u27e8 \u27e8 1, 0, 0 \u27e9,\n  \u27e8 0, 1, 0 \u27e9,\n  \u27e8 0, 0, 1 \u27e9 \u27e9\n\n@[simp] def add (A B : mat3) : mat3 :=\n  \u27e8 A.x + B.x, A.y + B.y, A.z + B.z \u27e9\n\n@[simp] def neg (A : mat3) : mat3 :=\n  \u27e8 -A.x, -A.y, -A.z \u27e9\n\n@[simp] def col_x (A : mat3) : vec3 :=\n  \u27e8 A.x.x, A.y.x, A.z.x \u27e9\n@[simp] def col_y (A : mat3) : vec3 :=\n  \u27e8 A.x.y, A.y.y, A.z.y \u27e9\n@[simp] def col_z (A : mat3) : vec3 :=\n  \u27e8 A.x.z, A.y.z, A.z.z \u27e9\n\n\n@[simp] def mul (A B : mat3) : mat3 :=\n\u27e8 \u27e8 A.x.dot B.col_x, A.x.dot B.col_y, A.x.dot B.col_z \u27e9,\n  \u27e8 A.y.dot B.col_x, A.y.dot B.col_y, A.y.dot B.col_z \u27e9,\n  \u27e8 A.z.dot B.col_x, A.z.dot B.col_y, A.z.dot B.col_z \u27e9 \u27e9\n\n/- `mat3` is a `ring`. -/\n@[simps] instance ring : ring mat3 :=\n{ zero := zero,\n  add  := add,\n  add_assoc :=\n  begin\n    intros a b c,\n    simp,\n    repeat { apply and.intro },\n    repeat { cc }\n  end,\n  zero_add :=\n  begin\n    intro a,\n    cases' a,\n    simp,\n    repeat { apply and.intro },\n    /-\n      Why `refl` cannot be directly used here?\n      ```\n      invalid apply tactic, failed to unify\n        {x := x.x, y := x.y, z := x.z} = x\n      with\n        ?m_2 = ?m_2\n      ```\n    -/\n    { cases' x, refl },\n    { cases' y, refl },\n    { cases' z, refl }\n  end,\n  add_zero :=\n  begin\n    intro a,\n    cases' a,\n    simp,\n    repeat { apply and.intro },\n    { cases' x, refl },\n    { cases' y, refl },\n    { cases' z, refl }\n  end,\n  add_comm :=\n  begin\n    intros a b,\n    have h : a.add b = b.add a := by simp; repeat { apply and.intro }; repeat { cc },\n    exact h\n  end,\n  neg := neg,\n  add_left_neg :=\n  begin\n    intro a,\n    have h : (a.neg).add a = zero := by simp; refl,\n    exact h\n  end,\n  one := I,\n  mul := mul,\n  mul_assoc :=\n  begin\n    intros a b c,\n    simp,\n    repeat { apply and.intro },\n    /- This is the most time consuming step... -/\n    repeat { ring }\n  end,\n  one_mul :=\n  begin\n    intro a,\n    cases' a,\n    simp,\n    repeat { apply and.intro },\n    { cases' x, refl },\n    { cases' y, refl },\n    { cases' z, refl }\n  end,\n  mul_one :=\n  begin\n    intro a,\n    cases' a,\n    simp,\n    repeat { apply and.intro },\n    { cases' x, refl },\n    { cases' y, refl },\n    { cases' z, refl }\n  end,\n  left_distrib :=\n  begin\n    intros a b c,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring }\n  end,\n  right_distrib :=\n  begin\n    intros a b c,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring }\n  end }\n\n@[simp] def mat_dot_vec (A : mat3) (x : vec3) : vec3 :=\n  \u27e8 A.x.dot x, A.y.dot x, A.z.dot x \u27e9\n\nlemma mat_dot_vec_assoc (A B : mat3) (v : vec3) :\n  (A * B).mat_dot_vec v = A.mat_dot_vec (B.mat_dot_vec v) :=\nbegin\n  simp,\n  repeat { apply and.intro },\n  repeat { ring }\nend\n\n/- `mat3` is also a `module` over `vec3` -/\n@[simps] instance module_vec3 : module mat3 vec3 :=\n{ smul := mat_dot_vec,\n  one_smul :=\n  begin\n    intros b,\n    simp,\n    cases' b,\n    refl,\n  end,\n  mul_smul := mat_dot_vec_assoc,\n  smul_add :=\n  begin\n    intros r x y,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring }\n  end,\n  add_smul :=\n  begin\n    intros r s x,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring },\n  end,\n  smul_zero := by intro r; simp,\n  zero_smul := by intro r; simp }\n\n/- `mat_mul_vec` is a linear operator on `vec3`. -/\n@[simp] def to_linear_operator (A : mat3) : linear_operator \u211d vec3 :=\n{ to_fun := \u03bbx, A \u2022 x,\n  map_add' :=\n  begin\n    intros x y,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring }\n  end,\n  map_smul' :=\n  begin\n    intros B x,\n    simp,\n    repeat { apply and.intro },\n    repeat { ring },\n  end }\n\n/- Some lemmas about `linear_operator`s of `mat3` -/\n@[simp] lemma linear_operator_eq (A B : mat3) :\n  A = B \u2192 A.to_linear_operator = B.to_linear_operator :=\nbegin\n  intro h,\n  apply linear_map.ext,\n  intro x,\n  simp [h]\nend\n\n@[simp] lemma I_eq_id :\n  to_linear_operator I = linear_map.id :=\nbegin\n  apply linear_map.ext,\n  intro x,\n  cases' x,\n  simp\nend\n\n@[simp] lemma linear_operator_mul_linear_operator (A B : mat3) :\n  A.to_linear_operator * B.to_linear_operator = to_linear_operator (A * B) :=\nbegin\n  apply linear_map.ext,\n  intro v,\n  cases' v,\n  simp,\n  repeat { apply and.intro },\n  repeat { ring }\nend\n\n@[simp] def transpose (A : mat3) : mat3 :=\n\u27e8 \u27e8 A.x.x, A.y.x, A.z.x \u27e9,\n  \u27e8 A.x.y, A.y.y, A.z.y \u27e9,\n  \u27e8 A.x.z, A.y.z, A.z.z \u27e9 \u27e9\n\n/- **Determinant** and its lemmas -/\n@[simp] def det (A : mat3) : \u211d :=\n  A.x.x * (A.y.y * A.z.z - A.y.z * A.z.y) -\n  A.x.y * (A.y.x * A.z.z - A.y.z * A.z.x) +\n  A.x.z * (A.y.x * A.z.y - A.y.y * A.z.x)\n\n@[simp] lemma det_mul_det (A B : mat3) :\n  det (A * B) = det A * det B :=\nby simp; ring\n\n@[simp] lemma det_one :\n  det 1 = 1 :=\nby simp\n\n@[simp] lemma det_zero :\n  det 0 = 0 :=\nby simp\n\n@[simp] lemma transpose_det (A : mat3) :\n  det (transpose A) = det A :=\nby simp; ring\n\nend mat3\n\nend FG\n", "meta": {"author": "sunoru", "repo": "finite-groups", "sha": "5095d557eb2d923627ba10169ad5e1e68c25cb30", "save_path": "github-repos/lean/sunoru-finite-groups", "path": "github-repos/lean/sunoru-finite-groups/finite-groups-5095d557eb2d923627ba10169ad5e1e68c25cb30/src/linear_space3/data.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.735264262549343}}
{"text": "import data.equiv.basic -- bijections with inverses\nimport tactic -- we want to use tactics\n\nopen set\n\n/-- Definition of a partition as a collection of disjoint nonempty\n  subsets of X whose union is X-/\n@[ext] structure partition (X : Type) :=\n(C : set (set X))\n(Hnonempty : \u2200 c \u2208 C, c \u2260 \u2205)\n(Hcover : \u2200 x, \u2203 c \u2208 C, x \u2208 c)\n(Hunique : \u2200 c d \u2208 C, c \u2229 d \u2260 \u2205 \u2192 c = d)\n\nnamespace partition\n\nvariables (X : Type) (P : partition X) (x : X)\n\nlemma block_eq (B : set X) (hB : B \u2208 P.C) (hx : x \u2208 B) :\nB = {y : X | \u2203 (c : set X), c \u2208 P.C \u2227 x \u2208 c \u2227 y \u2208 c} :=\nbegin\n      ext y,\n      dsimp,\n      split,\n      { intro hy,\n        use B,\n        use hB,\n        use hx,\n        use hy},\n      { rintro \u27e8C, hC, hCx, hCy\u27e9,\n        convert hCy,\n        apply P.Hunique B C hB hC,\n        rw ne_empty_iff_nonempty,\n        use x,\n        exact \u27e8hx, hCx\u27e9,\n      },\nend\n\nend partition\n\n\n/-- Equivalence class for a binary relation -/\ndef equivalence_class {X : Type} (R : X \u2192 X \u2192 Prop) (x : X) := {y : X | R x y}\n\nvariables {X : Type} (R : X \u2192 X \u2192 Prop)\n\n/-- x is in the equivalence class of x -/\nlemma mem_class (HR : equivalence R) (x : X) :\n  x \u2208 equivalence_class R x := HR.1 x\n\nlemma subset_of_rel (HR : equivalence R) (x y : X) (hxy : R x y) :\n  equivalence_class R y \u2286 equivalence_class R x :=\nbegin\n  intro z,\n  intro hz,\n  change R y z at hz,\n  change R x z,\n  exact HR.2.2 hxy hz,\nend\n\n/-- There is a bijection between equivalence relations on X and partitions of X -/\nexample (X : Type) : {R : X \u2192 X \u2192 Prop // equivalence R} \u2243 partition X :=\n-- The map in one direction: given a relation, use the set of equivalence classes.\n{ to_fun := \u03bb R,\n-- R is an equivalence relation\n-- and we need to make a partition\n{\n    C := { S : set X | \u2203 x : X, S = equivalence_class R.1 x},\n-- I claim that this is a partition.\n    Hnonempty := begin -- equiv classes are nonempty\n      rintro _ \u27e8x, rfl\u27e9,\n      rw ne_empty_iff_nonempty,\n      use x,\n      exact mem_class R.1 R.2 x,\n    end,\n    Hcover := begin -- they cover\n      intro x,\n      use equivalence_class R x,\n      dsimp,\n      split,\n        use x,\n      exact mem_class R.1 R.2 x,\n    end,\n    Hunique := begin -- and distinct equiv classes are disjoint\n      intros b1 b2,\n      rintro \u27e8x, rfl\u27e9,\n      rintro \u27e8y, rfl\u27e9,\n      intro h,\n      rw ne_empty_iff_nonempty at h,\n      cases h with z hz,\n      cases hz with hxz hyz,\n      change R.1 x z at hxz,\n      change R.1 y z at hyz,\n      apply set.subset.antisymm;\n      apply subset_of_rel R.1 R.2;\n      rcases R.2 with \u27e8ref, sym, tra\u27e9,\n      apply tra hyz,\n      exact sym hxz,\n      apply tra hxz,\n      exact sym hyz\n    end\n},\n-- The map the other way: given a partition, say two elements are related\n-- if there's a set in the partition that they both lie in.\n  inv_fun := \u03bb P, \u27e8\u03bb x y, \u2203 c \u2208 P.C, x \u2208 c \u2227 y \u2208 c, \u27e8\n    -- Claim this is an equivalence relation.\n    begin -- reflexive\n      change \u2200 (x : X), \u2203 (c : set X) (H : c \u2208 P.C), x \u2208 c \u2227 x \u2208 c,\n      intro x,\n      rcases P.Hcover x with \u27e8B, hB, hx\u27e9,\n      use B,\n      use hB,\n      cc,\n    end,\n    begin -- symmetric\n      change \u2200 (x y : X), (\u2203 (c : set X) (H : c \u2208 P.C), x \u2208 c \u2227 y \u2208 c) \u2192\n        (\u2203 (d : set X) (H : d \u2208 P.C), y \u2208 d \u2227 x \u2208 d),\n      intros x y,\n      rintro \u27e8B, hB, hx, hy\u27e9,\n      use [B, hB, hy, hx],\n      -- tidy bug\n    end,\n    begin -- transitive\n      change \u2200 (x y z : X),\n        (\u2203 (c : set X) (H : c \u2208 P.C), x \u2208 c \u2227 y \u2208 c) \u2192\n        (\u2203 (d : set X) (H : d \u2208 P.C), y \u2208 d \u2227 z \u2208 d) \u2192\n        (\u2203 (e : set X) (H : e \u2208 P.C), x \u2208 e \u2227 z \u2208 e),\n      intros x y z,\n      rintro \u27e8B, hB, hBx, hBy\u27e9, \n      rintro \u27e8C, hC, hCy, hCz\u27e9,\n      use [B, hB],\n      use hBx,\n      convert hCz,\n      apply P.Hunique B C hB hC,\n      rw ne_empty_iff_nonempty,\n      use y,\n      split; assumption\n    end\n  \u27e9\u27e9,\n  -- Furthermore, I claim that these two constructions are inverse to each other.\n  left_inv := begin\n    rintro \u27e8R, ref, sym, tra\u27e9,\n    ext x y,\n    dsimp,\n    split,\n    { rintro \u27e8_, \u27e8z, rfl\u27e9, hzx, hzy\u27e9,\n      unfold equivalence_class at *,\n      apply tra,\n      apply sym,\n      exact hzx,\n      exact hzy},\n    { intro hxy,\n      use equivalence_class R x,\n      use x,\n      use ref x,\n      exact hxy},\n  end,\n  -- (in both directions)\n  right_inv := begin\n    intro P,\n    ext B,\n    simp only [exists_prop, mem_set_of_eq],\n    split,\n    { rintro \u27e8x, rfl\u27e9,\n      dsimp [equivalence_class],\n      rcases P.Hcover x with \u27e8B, hB, hx\u27e9,\n      suffices : {y : X | \u2203 (c : set X), c \u2208 P.C \u2227 x \u2208 c \u2227 y \u2208 c} = B,\n        rw this,\n        assumption,\n      rw partition.block_eq X P x B hB hx\n    },\n    { intro hB,\n      let h := P.Hnonempty B hB,\n      rw ne_empty_iff_nonempty at h,\n      cases h with x hx,\n      use x,\n      rw partition.block_eq X P x B hB hx,\n      refl}\n  end }\n", "meta": {"author": "ImperialCollegeLondon", "repo": "Example-Lean-Projects", "sha": "87b27ba616eaf03f3642000829a481a1932dd08e", "save_path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects", "path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects/Example-Lean-Projects-87b27ba616eaf03f3642000829a481a1932dd08e/src/equivalence_relations/partitions_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.8244619177503206, "lm_q1q2_score": 0.7352642495340723}}
{"text": "import tactic\n\nimport data.real.basic\n\nexample : \u2200 x : \u211d, \u2203 y : \u211d, x + y > 0 :=\nbegin\n  intro x,\n  use 37 - x,\n  simp,\n  norm_num,\nend\n\n-- example : \u2203 y : \u211d, \u2200 x : \u211d, x + y > 0 :=\n-- begin\n--   use 10000000000,\n--   intro x,\n--   -- stuck!\n--   sorry\n-- end\n\nexample : \u00ac (\u2203 y : \u211d, \u2200 x : \u211d, x + y > 0) :=\nbegin\n  push_neg,\n  intro y,\n  use -37 - y,\n  simp,\n  norm_num,\nend\n\nvariable (\u03b1 : Type)\n\nexample : (\u03b1 \u2192 Prop) \u2243 set \u03b1 := \n{ to_fun := \u03bb P, {x : \u03b1 | P x},\n  inv_fun := \u03bb X, \u03bb a, a \u2208 X,\n  left_inv := begin\n    intro P,\n    dsimp,\n    refl,\n  end\n  ,\n  right_inv := begin\n    intro X,\n    dsimp,\n    refl,\n  end }\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/sets/lean_lecture.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813463747181, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.7352263554452746}}
{"text": "-- Chapter 3. Propositions and Proofs\n\n/- This chapter explains how to write mathematical assertions and proofs in the language\nof dependent type theory. -/\n\n#print \"==================================\"\n#print \"Section 3.1 Propositions as Types\"\n#print \" \"\n\nnamespace Sec_3_1\n  /- We introduce a new type, `Prop`, to represent propositions, and introduce \n     constructors to build new propositions from others.\n  -/\n  constant and : Prop \u2192 Prop \u2192 Prop\n  constant or : Prop \u2192 Prop \u2192 Prop\n  constant not : Prop \u2192 Prop\n  constant implies : Prop \u2192 Prop \u2192 Prop\n\n  variables p q r : Prop\n  #check and p q                      -- Prop\n  #check or (and p q) r               -- Prop\n  #check implies (and p q) (and q p)  -- Prop\n\n\n  /- We then introduce, for each `p : Prop`, another type `Proof p`, for the type \n     of proofs of `p`. An \"axiom\" would be constant of such a type. -/\n  constant Proof : Prop \u2192 Type\n\n  -- example of an axiom:\n  constant and_comm : \u03a0 (p q : Prop), Proof (implies (and p q) (and q p))\n\n  #check and_comm p q      -- Proof (implies (and p q) (and q p))\n  \n  /- In addition to axioms, however, we would also need rules to build new proofs from \n     old ones. For example, in many proof systems for propositional logic, we have the \n     rule of modus ponens. -/\n  constant modus_ponens (p q : Prop) : Proof (implies p q) \u2192  Proof p \u2192 Proof q\n  constant modus_ponens' : \u03a0 (p q : Prop), Proof (implies p q) \u2192  Proof p \u2192 Proof q\n  #check modus_ponens p q\n  #check modus_ponens' p q\n \n  /- Systems of natural deduction for propositional logic also typically rely on \n     the following rule: -/\n\n  constant implies_intro (p q : Prop) : (Proof p \u2192 Proof q) \u2192 Proof (implies p q).\n\n  /- This approach would provide us with a reasonable way of building assertions and proofs. \n     Determining that an expression =t= is a correct proof of assertion =p= would then \n     simply be a matter of checking that =t= has type =Proof p=. -/\n\n  /- Some simplifications are possible. We can avoid writing the term =Proof= repeatedly \n     by conflating =Proof p= with =p= itself. Whenever we have =p : Prop=, we can interpret\n     =p= as a type, namely, the type of its proofs. -/\n\n  /- We read =t : p= as the assertion that =t= is a proof of =p=. -/\n\n  /- The rules for implication then show that we can identify =implies p q= and =p \u2192 q=.  -/\n\n  /- In other words, implication =p \u2192 q= corresponds to existence of a function taking \n     elements of =p= to elements of =q=. Thus the introduction of the connective =implies= \n     is redundant: we can use the usual function space constructor =p \u2192 q= from dependent \n     type theory as our notion of implication. -/\n\n  /- The rules for implication in a system of natural deduction correspond to the rules \n     governing abstraction and application for functions. This is an instance of the \n     /Curry-Howard correspondence/, or /propositions-as-types/ paradigm. -/\n\n  /- In fact, the type =Prop= is syntactic sugar for =Sort 0=, the very bottom of the type \n     hierarchy.  Moreover, =Type u= is also just syntactic sugar for =Sort (u+1)=. -/\n\n  /- =Prop= has some special features, but like the other type universes, it is closed \n     under the arrow constructor: if =p q : Prop=, then =p \u2192 q : Prop=. -/\n\n  /- There are at least two ways of thinking about propositions-as-types (pat).  \n\n     Constructive view: pat is a faithful rendering of what it means to be a proposition: \n     a proposition `p` is a data type that represents a specification of the type of \n     data that constitutes a proof.  A proof `t` of `p` is simply an object of type `p`,\n     denoted `t : p`. \n\n     Non-constructive view: pat is a simple coding trick. To each proposition `p` we \n     associate a type, which is empty if `p` is false and has a *single* element, \n     say `*`, if `p` is true. In the latter case, we say (the type associated with)\n     `p` is *inhabited*. It just so happens that the rules for function application and \n     abstraction can conveniently help us keep track of which elements of `Prop` are \n     inhabited. So constructing an element =t : p= tells us that =p= is indeed true. \n     You can think of the inhabitant of =p= as being \"the fact that `p` has a proof.\" \n     (Lean document says, \"the fact that `p` is true\" but they're conflating \"truth\" \n     with \"has a proof\".)  -/\n\n  /- PROOF IRRELEVANCE: \n\n     If `p : Prop` is any proposition, Lean's kernel treats any two elements `t1 t2 : p` \n     as being definitionally equal.  This is known as \"proof irrelevance,\" and is \n     consistent with the non-constructive interpretation above. It means that even \n     though we can treat proofs =t : p= as ordinary objects in the language of dependent\n     type theory, they carry no information beyond the fact that =p= is true. -/\n\n  /- IMPORTANT DISTINCTION: \n\n     \"proofs as if people matter\" or \"proof relevance\"\n     From the constructive point of view, proofs are *abstract mathematical objects* that \n     may be denoted (in various ways) by suitable expressions in dependent type theory. \n\n     \"proofs as if people don't matter\" or \"proof irrelevance\"\n     From the non-constructive point of view, proofs are not abstract entities. \n     A syntactic expression---that we formulate using type theory in order to prove \n     a proposition---doesn't denote some abstract proof.  Rather, the expression itself\n     /is/ the proof. And such an expression does not denote anything beyond the fact that \n     (assuming it type-checks) the proposition in question is \"true\" (i.e., has a proof). -/\n\n  /- We may slip back and forth between these two ways of talking, at times saying that \n     an expression \"constructs\" or \"represents\" a proof of a proposition, and at other times\n     simply saying that it \"is\" such a proof. \n\n     This is similar to the way that computer scientists occasionally blur the distinction \n     between syntax and semantics by saying, at times, that a program \"computes\" a certain \n     function, and at other times speaking as though the program \"is\" the function in question.\n  -/\n\n  /- In any case, all that really matters is that the bottom line is clear. To formally express\n     a mathematical assertion in the language of dependent type theory, we need to exhibit a \n     term =p : Prop=. To /prove/ that assertion, we need to exhibit a term =t : p=. Lean's\n     task, as a proof assistant, is to help us to construct such a term, =t=, and to verify \n     that it is well-formed and has the correct type.\n  -/\n\n\n  #print \" \"\nend Sec_3_1\n\n/- Section 3.1 output:\n                and p q : Prop\n                or (and p q) r : Prop\n                implies (and p q) (and q p) : Prop\n                and_comm p q : Proof (implies (and p q) (and q p))\n-/\n\n#print \"================================================\"\n#print \"Section 3.2 Working with Propositions as Types\"\n#print \" \"\n\nnamespace page34\n  #print \"-------------- page 34 ----------------\"\n\n  constants p q : Prop\n\n  theorem t1 : p \u2192 q \u2192 p := \u03bb hp : p, \u03bb hq : q, hp\n\n  theorem t1' : p \u2192 q \u2192 p :=\n  assume hp : p,\n  assume hq : q,\n  hp\n  #print t1'   -- page34.t1' : p \u2192 q \u2192 p := \u03bb (hp : p) (hq : q), hp\n\n  lemma t1'' : p \u2192 q \u2192 p := assume hp : p, assume hq : q, show p, \n    from hp\n\n  #print \" \"\nend page34\n\n\n\nnamespace page35\n  #print \"-------------- page 35 ----------------\"\n\n  constants p q : Prop\n\n  /- As with ordinary defs, we can move lambda-abstracted variables to the left of colon. -/\n  theorem t1 (hp : p) (hq : q) : p := hp\n  #check t1   -- p \u2192 q \u2192 p\n\n  /- Now we can apply the theorem t1 just as a function application. -/\n\n  axiom hp : p     -- alternative syntax for `constant hp : p`\n  theorem t2 : q \u2192 p := t1 hp\n\n  theorem gen_t1 (p q : Prop) (Hp : p) (hp : q) : p := Hp\n  #check gen_t1                                             -- (p q : Prop), p \u2192 q \u2192 p\n\n  -- or we can move some parameters to the right of the colon\n  theorem gen_t1' (p q : Prop) : p \u2192 q \u2192 p := \u03bb (Hp : p) (hp : q), Hp\n  #check gen_t1'\n\n  -- or we can move all parameters to the right of the colon\n  theorem gen_t1'' : \u03a0 (p q : Prop), p \u2192 q \u2192 p := \u03bb (p q : Prop) (Hp : p) (hp : q), Hp\n  #check gen_t1''\n\n  -- but gen_t1, gen_t1', gen_t1'' all have same type, namely, `(p q : Prop), p \u2192 q \u2192 p`\n\n  /- The symbol \u2200 is alternate syntax for \u03a0.  Later we see how Pi types model universal \n     quantifiers more generally.  For the moment, however, we focus on theorems in logic, \n     generalized over propositions. We will tend to work in sections with variables over \n     propositions, so that they are generalized for us automatically. \n     When we generalize t1 in that way, we can then apply it to different pairs of \n     propositionshe to obtain different instances of the general theorem. -/\n  #print \" \"\nend page35\n\nnamespace page36 -- (page 26 of new edition)\n\n  #print \"-------------- page 36 ----------------\"\n\n  variables p q r s : Prop\n  variable h : r \u2192 s\n  #check h\n  #check r \u2192 s\n\n  theorem t1 : \u03a0 (p q : Prop), p \u2192 q \u2192 p := \u03bb (p q : Prop) (Hp : p) (hp : q), Hp\n\n  #check t1 p q\n  #check t1 r s\n  #check t1 (r \u2192 s) (s \u2192 r)\n  #check t1 (r \u2192 s) (s \u2192 r) h\n\n  theorem t2 (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q) : p \u2192 r := \u03bb (x : p), h\u2081 (h\u2082 x)\n\n  theorem t2' : \u03a0 (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q), p \u2192 r := \n    \u03bb (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q) (x : p), h\u2081 (h\u2082 x)\n\n  theorem t2'' (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q): p \u2192 r := \n  assume h\u2083 : p,                                          -- like Coq's `intro` tactic\n  show r, from h\u2081 (h\u2082 h\u2083)\n\n  /- As a theorem of propositional logic, what does thm2 say? \n     (given `p implies q` and `q implies r`, we can derive `p implies r`) -/\n  #print \" \"\n\nend page36\n\n/- Section 3.2 output:\n                theorem page34.t1' : p \u2192 q \u2192 p :=\n                \u03bb (hp : p) (hq : q), hp\n                t1 : p \u2192 q \u2192 p\n                gen_t1 : \u2200 (p q : Prop), p \u2192 q \u2192 p\n                gen_t1' : \u2200 (p q : Prop), p \u2192 q \u2192 p\n                gen_t1'' : \u2200 (p q : Prop), p \u2192 q \u2192 p\n                h : r \u2192 s\n                r \u2192 s : Prop\n                t1 p q : p \u2192 q \u2192 p\n                t1 r s : r \u2192 s \u2192 r\n                t1 (r \u2192 s) (s \u2192 r) : (r \u2192 s) \u2192 (s \u2192 r) \u2192 r \u2192 s\n                t1 (r \u2192 s) (s \u2192 r) h : (s \u2192 r) \u2192 r \u2192 s\n-/\n\n\n\n#print \"=================================\"\n#print \"Section 3.3 Propositional Logic\"\n  #print \" \"\n/- Propositional connectives are operators on the space Prop \n   For example, if we have p q r : Prop, then the expression\n   p \u2192 q  read \"if p then q\" and this is a Prop, so we see\n   that \u2192 is a binary operation on Prop; thus we could write\n   \u2192 : Prop \u00d7 Prop \u2192 Prop\n\n   the expression p \u2192 q \u2192 r reads \n   \"if p, then if q, then r.\" NB this is the \"curried\" form of p \u2227 q \u2192 r. -/\n\n/- Lambda abstraction can be viewed as an \"introduction rule\" for \u2192. \n   It \"introduces\" (or establishes) an implication.  \n\n   Application, on the other hand, is an \"elimination rule\" for \u2192.\n   It shows how to \"eliminate\" or /use/ an implication in a proof. -/ \n\n\n-- ____CONJUNCTION____\n\nnamespace page37\n  #print \"-------------- page 37 ----------------\"\n\n  /- The expression and.intro h1 h2 builds a proof of p \u2227 q using proofs h1 : p and h2 : q. \n     `and.intro` is known as the \"and-introduction rule.\" -/\n\n  -- __AND_INTRO__\n\n  -- Let's use `and.intro` to create a proof of `p \u2192 q \u2192 p \u2227 q`.\n  variables p q : Prop\n  theorem t3 (hp : p) (hq : q) :  p \u2227 q := and.intro hp hq\n  #check t3\n\n  -- Alternatively, \n  theorem t3' : \u03a0 (hp : p) (hq : q),  p \u2227 q := \u03bb (h\u2081 : p) (h\u2082 :q), and.intro h\u2081 h\u2082\n  #check t3'\n\n\n  -- __AND_ELIM__\n\n  /- `and.elim_left` gives a proof of `p` from a proof of `p \u2227 q`.   \n     Similarly for `and.elim_right` and `q`, resp. \n     These are known as the right and left /and-elimination/ rules. -/\n  example (h : p \u2227 q) : p := and.elim_left h   -- std lib abbreviation: `and.left`\n  example (h : p \u2227 q) : q := and.elim_right h  -- std lib abbreviation: `and.right`\n\n  /- The `example` command states a theorem without naming it or storing it in the \n     permanent context. It just checks that the given term has the indicated type. -/\n\n  -- Let's prove `p \u2227 q \u2192 q \u2227 p`\n  theorem and_comm (h : p \u2227 q) : q \u2227 p := and.intro (and.right h) (and.left h)\n  #check and_comm\n\n  theorem and_comm' : \u03a0 (\u03b1 : Prop) (\u03b2 : Prop), (\u03b1 \u2227 \u03b2) \u2192 (\u03b2 \u2227 \u03b1) := \n          \u03bb (\u03b1 \u03b2 : Prop), \u03bb (h : \u03b1 \u2227 \u03b2), and.intro (and.right h) (and.left h)\n  #check and_comm'\n\n  #print \" \"\nend page37\n\n/- `and-introduction` and `and-elimination` are similar to the pairing and projection \n   operations for the cartesian product. The difference is that given `hp : p` and `hq : q`, \n   `and.intro hp hq` has type `p \u2227 q : Prop`, while `pair hp hq` has type `p \u00d7 q : Type`.\n\n   The similarity between \u2227 and \u00d7 is another instance of the Curry-Howard isomorphism, but\n   in contrast to implication and the function space constructor, \u2227 and \u00d7 are treated sepa-\n   rately in Lean.\n-/\n\n\nnamespace page38\n  #print \"-------------- page 38 ----------------\"\n\n  -- __ANONYMOUS_CONSTRUCTORS__\n\n  /- Certain types in Lean are structures, which is to say, the type is defined with a \n     single canonical constructor which builds an element of the type from a sequence of \n     suitable arguments. The expression `p \u2227 q` is an example. -/\n\n  /- Lean allows us to use *anonymous constructor* notation \u27e8arg1, arg2, ...\u27e9 in situations \n     like these, when the relevant type is an inductive type and can be inferred from the \n     context. In particular, we can often write \u27e8hp, hq\u27e9 instead of and.intro hp hq. -/\n\n  variables p q : Prop\n  variables (hp : p) (hq : q)\n\n  #check (\u27e8hp, hq\u27e9 : p \u2227 q)        -- and.intro hp hq : p \u2227 q\n\n  /- Here's another useful syntactic gadget. Given an expression `e` of an inductive \n     type `fu`, the notation e.bar is shorthand for `fu.bar e`. Thus we can access \n     functions without opening a namespace. For example, these mean the same thing. -/\n  variable l : list \u2115\n  #check list.head l               -- list.head l : \u2115\n  #check l.head                    -- list.head l : \u2115\n\n  /- Another example: given `h : p \u2227 q`, we can write `h.left` for `and.left h` and \n     `h.right` for `and.right h`.  Thus the sample proof above can be given as follows: -/\n  example (h : p \u2227 q) : q \u2227 p := \u27e8h.right, h.left\u27e9\n\n  #print \" \"\nend page38\n\n/-  ____DISJUNCTION____\n\n   `or.intro_left q hp` creates a proof of `p \u2228 q` from a proof `hp : p`.\n   `or.intro_right p hq` creates a proof of `p \u2228 q` from a proof `hq : q`. \n   These are called the left and right \"or-introduction\" rules. \n-/\n\nnamespace page39a\n  #print \"-------------- page 39 ----------------\"\n\n  -- __OR_INTRO__\n\n  variables p q : Prop\n  example (h\u2081 : p) : p \u2228 q := or.intro_left q h\u2081\n  example (h\u2082 : q) : p \u2228 q := or.intro_right p h\u2082\n\n  -- __OR_ELIM__\n\n  /- The `or-elimination` rule is slightly more complicated. The idea is that we can prove\n     `r` from `p \u2228 q`, by showing that `r` follows from `p` and that `r` follows from `q`.  -/\n\n  /- In the expression `or.elim hpq hpr hqr`, the function `or.elim` takes three arguments:\n            hpq : p \u2228 q,     hpr : p \u2192 r,     hqr : q \u2192 r\n     and produces a proof of `r`. \n  -/\n\nend page39a\n\nnamespace page39b\n  -- Let's use `or.elim` to prove `p \u2228 q \u2192 q \u2228 p`.\n  theorem or_comm\u2081 : \u03a0 (p q : Prop), p \u2228 q \u2192 q \u2228 p := \u03bb (p q : Prop) (h : p \u2228 q), \n      or.elim h (\u03bb (h\u2081 : p), or.intro_right q h\u2081) (\u03bb (h\u2082 : q), or.intro_left p h\u2082)\n  -- note that using a \u03a0 type, we don't need to introduce variables p and q in advance\n\n  -- Here's the tutorial's version \n  -- (note we need to introduce p and q as variables)\n\n  variables p q : Prop\n  example (h : p \u2228 q) : q \u2228 p :=\n    or.elim h\n      (assume h\u2081 : p,\n        show q \u2228 p, from or.intro_right q h\u2081)\n      (assume h\u2082 : q,\n        show q \u2228 p, from or.intro_left p h\u2082)\n\n  -- Here's an alternative version from the tutorial.\n  theorem or_comm\u2082 (h : p \u2228 q) : q \u2228 p := \n    or.elim h (\u03bb (h\u2081 : p), or.inr h\u2081) (\u03bb (h\u2082 : q), or.inl h\u2082)\n\n  #check or_comm\u2081\n  #check or_comm\u2082\n  #print \" \"\nend page39b\n\n/-In most cases, the first argument of or.intro_right and or.intro_left can be in-\nferred automatically by Lean. Lean therefore provides or.inr and or.inl as shorthands\nfor or.intro_right _ and or.intro_left _. Thus the proof term above could be written\nmore concisely: -/\n\nnamespace page40\n  #print \"-------------- page 40 ----------------\"\n\n  variables p q r : Prop\n  -- variables (h\u2081 : p) (h\u2082 : q)\n\n  /- Because or has two constructors, we cannot use anonymous constructor notation. \n     But we can still write h.elim instead of or.elim h. -/\n  theorem or_comm (h : p \u2228 q) : q \u2228 p := \n    h.elim (\u03bb (h\u2081 : p), or.inr h\u2081) (\u03bb (h\u2082 : q), or.inl h\u2082)\n  \n  #check or_comm\n\n  -- Negation and Falsity\n  /- Negation, `\u00acp`, is defined to be p \u2192 false, so we obtain \u00acp by assuming\n     p and then deriving a contradiction. \n\n     Similarly, the expression `hnp hp` produces a proof of false from `hp : p`\n     and `hnp : \u00acp`. The next example uses both these rules to produce a proof of \n     `(p \u2192 q) \u2192 \u00acq \u2192 \u00acp`.\n  -/\n  theorem mt (hpq : p \u2192 q) (hnq : \u00acq) : \u00acp :=\n    assume hp : p,\n    show false, from hnq (hpq hp)\n\n  #check mt\n\n  -- Alternatively, without predeclared variables,\n  theorem mt\u2081 : \u03a0 (p q : Prop),  (p \u2192 q) \u2192 \u00acq \u2192 \u00acp := \n    \u03bb (p q : Prop) (h\u2081: p \u2192 q) (h\u2082 : \u00acq) (h\u2083 : p), h\u2082 (h\u2081 h\u2083) \n  #print mt\u2081\n  /- The connective false has a single elimination rule, false.elim, which \n     expresses the fact that anything follows from a contradiction. This \n     rule is sometimes called ex falso, or the principle of explosion. -/\n\n  example (h\u2081 : p) (h\u2082 : \u00acp) : q := false.elim (h\u2082 h\u2081)\n  example (h\u2081 : p) (h\u2082 : \u00acp) : q := absurd h\u2081 h\u2082 -- notice reversal of order of hypoths\n  example (h\u2081 : \u00acp) (h\u2082 : q) (h\u2083 : q \u2192 p) : r := absurd (h\u2083 h\u2082) h\u2081\n\n  /- Alternatively, without predeclared variables, the last three examples could \n     be implemented using \u03a0 types and \u03bb terms.   -/\n  theorem ex_falso\u2081 : \u03a0 (p q : Prop), p \u2192 \u00acp \u2192 q := \n    \u03bb (p q : Prop) (h\u2081 : p) (h\u2082 : \u00acp), false.elim (h\u2082 h\u2081)\n\n  theorem ex_falso\u2082 : \u03a0 (p q : Prop), p \u2192 \u00acp \u2192 q := \n    \u03bb (p q : Prop) (h\u2081 : p) (h\u2082 : \u00acp), absurd h\u2081 h\u2082\n\n  theorem absurd_example : \u03a0 (p q r : Prop), \u00acp \u2192 q \u2192 (q \u2192 p) \u2192 r :=\n    \u03bb (p q r : Prop) (h\u2081 : \u00acp) (h\u2082 : q) (h\u2083 : q \u2192 p), absurd (h\u2083 h\u2082) h\u2081\n\n  #print \" \"\nend page40\n\n\nnamespace page41\n  #print \"-------------- page 41 ----------------\"\n\n  /- __Logical Equivalence__\n    The expression `iff.intro h1 h2` produces a proof of `p \u2194 q` from `h1 : p \u2192 q` and \n    `h2 : q \u2192 p`. The expression `iff.elim_left h` produces a proof of `p \u2192 q` from \n    `h : p \u2194 q`. Similarly, `iff.elim_right h` produces a proof of `q \u2192 p` from \n    `h : p \u2194 q`. -/\n  variables p q r : Prop\n  variables (hp : p) (hq : q)\n\n  theorem and_swap : p \u2227 q \u2194 q \u2227 p :=\n    iff.intro\n      (assume h: p \u2227 q,\n        show q \u2227 p, from and.intro (and.elim_right h) (and.elim_left h))\n      (assume h: q \u2227 p,\n        show p \u2227 q, from and.intro (and.elim_right h) (and.elim_left h))\n\n  theorem and_swap\u2081 : p \u2227 q \u2194 q \u2227 p :=\n    iff.intro\n      (assume h: p \u2227 q, show q \u2227 p, from and.intro h.right h.left)\n      (assume h: q \u2227 p, show p \u2227 q, from and.intro h.right h.left)\n\n  theorem and_swap\u2082 : p \u2227 q \u2194 q \u2227 p :=\n    iff.intro  (\u03bb (h: p \u2227 q), and.intro h.right h.left)\n      (\u03bb (h: q \u2227 p), and.intro h.right h.left)\n\n  theorem and_swap\u2083 : \u03a0 (p q : Prop), p \u2227 q \u2194 q \u2227 p := \u03bb (p q : Prop), \n    \u27e8(\u03bb (h\u2081: p \u2227 q), \u27e8h\u2081.right, h\u2081.left\u27e9), (\u03bb (h\u2082: q \u2227 p), \u27e8h\u2082.right, h\u2082.left\u27e9)\u27e9\n\n\n  theorem and_swap\u2084 : \u03a0 (p q : Prop), p \u2227 q \u2194 q \u2227 p := \u03bb (p q : Prop), \n    iff.intro \n      (\u03bb (h\u2081: p \u2227 q), \u27e8h\u2081.right, h\u2081.left\u27e9) \n      (\u03bb (h\u2082: q \u2227 p), \u27e8h\u2082.right, h\u2082.left\u27e9)\n\n\n  #check and_swap                        -- \u2200 (p q : Prop), p \u2227 q \u2194 q \u2227 p\n  #check and_swap\u2081                        -- \u2200 (p q : Prop), p \u2227 q \u2194 q \u2227 p\n  #print \"--\"\n  #check and_swap p                      --   \u2200 (q : Prop), p \u2227 q \u2194 q \u2227 p\n  #check and_swap\u2082 p                      --   \u2200 (q : Prop), p \u2227 q \u2194 q \u2227 p\n  #print \"--\"\n  #check and_swap p q                    --                 p \u2227 q \u2194 q \u2227 p\n  #check and_swap\u2083 p q                    --                 p \u2227 q \u2194 q \u2227 p\n\n  /- iff.elim_left and iff.elim_right represent a form of modus ponens,\n     so they can be abbreviated iff.mp and iff.mpr, respectively. -/\n\n  /- We can use the anonymous constructor notation to construct a proof of p \u2194 q from \n     proofs of the forward and backward directions, and we can also use . notation with \n     mp and mpr. -/\n\n  theorem and_swap\u2085 : p \u2227 q \u2194 q \u2227 p :=\n    \u27e8\u03bb (h : p \u2227 q), \u27e8h.right, h.left\u27e9, \u03bb (h : q \u2227 p), \u27e8h.right, h.left\u27e9\u27e9\n\n  example (h : p \u2227 q) : q \u2227 p := (and_swap\u2085 p q).elim_left h\n\n  example (h : p \u2227 q) : q \u2227 p := (and_swap\u2085 p q).mp h\n\n  #print \" \"\nend page41\n\n\n#print \"  \"\n#print \"===========================================\"\n#print \"Section 3.4 Introducing Auxiliary Subgoals\"\n#print \"  \"\n  /- This is a good place to introduce another device Lean offers to help \n     structure long proofs, namely, the `have` construct, which introduces \n     an auxiliary subgoal in a proof. -/\n\nnamespace Sec_3_4\n  variables p q : Prop\n  \n  theorem and_swap (h : p \u2227 q) : q \u2227 p :=\n    have h\u2081 : p, from and.elim_left h,\n    have h\u2082 : q, from and.elim_right h,\n    show q \u2227 p, from  and.intro h\u2082 h\u2081\n\n  -- `show` is just for clarity; it's not required, as we see here.\n  theorem and_swap\u2081 (h : p \u2227 q) : q \u2227 p :=\n    have h\u2081 : p, from and.elim_left h,\n    have h\u2082 : q, from and.elim_right h, and.intro h\u2082 h\u2081\n\n  /- Under the hood, the expression \n         have h : p, from s, t\n     produces the term \n         (\u03bb (h : p), t) s\n\n     In other words, `s` is a proof of `p`, `t` is a proof of the desired \n     conclusion assuming `h : p`, and the two are combined by lambda \n     astraction and application. -/\n\n  /- Lean also supports a structured way of reasoning backwards from a goal,\n     which models the \"suffices to show\" construction in ordinary mathematics. -/\n\n  theorem and_swap\u2082 (h : p \u2227 q) : q \u2227 p :=\n    have h\u2081 : p, from and.elim_left h,\n    suffices h\u2082 : q, from and.intro h\u2082 h\u2081,\n    show q, from and.elim_right h\n\n  #check and_swap\u2081\n  #check and_swap\u2082\n\nend Sec_3_4\n\n\n#print \"  \"\n#print \"=====================================\"\n#print \"Section 3.5 Classical Logic\"\n#print \"  \"\n\nnamespace page43\n\n  /- The constructive \"or\" is very strong: asserting p \u2228 q amounts to knowing\n     which is the case. If RH represents the Riemann hypothesis, a classical \n     mathematician is willing to assert RH \u2228 \u00acRH, even though we cannot yet \n     assert either disjunct. -/\n\n  open classical \n\n  #check \u03bb (p : Prop), em p            -- p \u2228 \u00acp\n\n  /- One consequence of the law of the excluded middle is the principle of double-negation\n     elimination: -/\n  theorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\n    or.elim (em p)\n      (assume h\u2081 : p, h\u2081)\n      (assume h\u2082 : \u00acp, false.elim (h h\u2082))  -- alternatively,  (assume h\u2082 : \u00acp, absurd h\u2082 h)\n\n  #check @dne\n  /- double-negation elimination allows one to carry out a proof by contradiction, \n     something which is not always possible in constructive logic. -/\n\nend page43\n\n/- Exercise: prove the converse of dne, showing that em can be proved from dne. -/\nnamespace exer\n\n  variables p q : Prop\n\n/- first try (didn't get this to work)\n  theorem em (h : \u00ac\u00acp \u2192 p) : p \u2228 \u00acp :=  \n    (\u03bb (h\u2082 : \u00acp), or.inr h\u2082)\n    (\u03bb (h\u2083 : \u00ac\u00acp), or.inl (h h\u2083))\n-/\n/- second try (still didn't get it done...but getting closer) -/\n  theorem em (h : \u00ac\u00acp \u2192 p) : p \u2228 \u00acp :=  \n    show p \u2228 \u00acp, from  \n      suffices h\u2081 : \u00acp \u2228 \u00ac\u00acp, from or.elim h\u2081 \n        (assume h\u2082 : \u00acp, or.inr h\u2082)\n        (assume h\u2083 : \u00ac\u00acp, or.inl (h h\u2083)),\n      show \u00acp \u2228 \u00ac\u00acp, from sorry\n\n\n\n\nend exer\n\n#print \"  \"\n#print \"================================================\"\n#print \"Section 3.6 Examples of Propositional Validities\"\n#print \"  \"\n/- Lean's standard library contains proofs of many valid statements of propositional \n   logic, all of which you are free to use in proofs of your own. The following list \n   includes a number of common identities. The ones that require classical reasoning \n   are grouped together at the end, while the rest are constructively valid. -/\n\nnamespace Section_3_6\nvariables p q r s : Prop\n\n  -- commutativity of \u2227\n  theorem and_comm : p \u2227 q \u2194 q \u2227 p := iff.intro\n    (assume h: p \u2227 q,\n      show q \u2227 p, from and.intro (and.elim_right h) (and.elim_left h))\n    (assume h: q \u2227 p,\n      show p \u2227 q, from and.intro (and.elim_right h) (and.elim_left h))\n\n  -- commutativity of \u2228\n  theorem or_comm : p \u2228 q \u2194 q \u2228 p := iff.intro\n    (assume h\u2081: p \u2228 q,\n      show q \u2228 p, from or.elim h\u2081 (assume h\u2082 : p, or.inr h\u2082) (assume h\u2083 : q, or.inl h\u2083))\n    (assume h\u2081: q \u2228 p,\n      show p \u2228 q, from or.elim h\u2081 (assume h\u2081 : q, or.inr h\u2081) (assume h\u2082 : p, or.inl h\u2082))\n\n  -- associativity of \u2227\n  theorem and_assoc : p \u2227 (q \u2227 r) \u2194 (p \u2227 q) \u2227 r := iff.intro\n    (assume h : p \u2227 (q \u2227 r),\n      show (p \u2227 q) \u2227 r, from and.intro (and.intro h.left h.right.left) h.right.right) \n    (assume h : (p \u2227 q) \u2227 r,\n      show p \u2227 (q \u2227 r), from and.intro h.left.left (and.intro h.left.right h.right))\n\n  -- associativity of \u2228\n  theorem or_assoc : p \u2228 (q \u2228 r) \u2194 (p \u2228 q) \u2228 r := iff.intro\n    (assume h : p \u2228 (q \u2228 r),\n      show (p \u2228 q) \u2228 r, from or.elim h \n        (assume h\u2081 : p, or.inl (or.inl h\u2081)) \n        (assume h\u2082 : q \u2228 r, or.elim h\u2082\n          (assume h\u2083 : q, or.inl (or.inr h\u2083))\n          (assume h\u2084 : r, or.inr h\u2084)))\n    (assume h : (p \u2228 q) \u2228 r,\n      show p \u2228 (q \u2228 r), from or.elim h \n        (assume h\u2081 : (p \u2228 q), or.elim h\u2081\n          (assume h\u2082 : p, or.inl h\u2082)\n          (assume h\u2082 : q, or.inr (or.inl h\u2082)))\n        (assume h\u2083 : r, or.inr (or.inr h\u2083)))\n\n  -- distributivity of \u2227 over \u2228\n  theorem and_dist : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := iff.intro\n\n    (assume h : p \u2227 (q \u2228 r),\n      have h\u2080 : q \u2228 r, from h.right,\n      show (p \u2227 q) \u2228 (p \u2227 r), from or.elim h\u2080\n          (assume h\u2081: q, or.inl (and.intro h.left h\u2081))\n          (assume h\u2082: r, or.inr (and.intro h.left h\u2082))\n    )\n    \n    (assume h : (p \u2227 q) \u2228 (p \u2227 r),\n      show p \u2227 (q \u2228 r), from or.elim h\n        (assume h\u2081 : p \u2227 q, and.intro h\u2081.left (or.inl h\u2081.right))\n        (assume h\u2082 : p \u2227 r, and.intro h\u2082.left (or.inr h\u2082.right))\n    )\n          \n\n  -- distributivity of \u2228 over \u2227\n\n  theorem or_distr : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := iff.intro\n\n    (assume h : p \u2228 (q \u2227 r),\n      show (p \u2228 q) \u2227 (p \u2228 r), from or.elim h\n        (assume h\u2081 : p, and.intro (or.inl h\u2081) (or.inl h\u2081))\n        (assume h\u2082 : (q \u2227 r), and.intro (or.inr h\u2082.left) (or.inr h\u2082.right))\n    )\n\n    (assume h: (p \u2228 q) \u2227 (p \u2228 r),\n      show p \u2228 (q \u2227 r), from \n        have h\u2081 : p \u2228 q, from h.left,\n        have h\u2082 : p \u2228 r, from h.right,\n          or.elim h\u2081\n            (assume h\u2083 : p, or.inl h\u2083)\n            (assume h\u2084 : q, \n              or.elim h\u2082 \n                (assume h\u2085 : p, or.inl h\u2085)\n                (assume h\u2086 : r, or.inr (and.intro h\u2084 h\u2086))\n            )\n    )\n\n\n  -- other properties\n  example : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := sorry\n  example : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := sorry\n  example : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := sorry\n  example : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := sorry\n  example : \u00ac(p \u2227 \u00ac p) := sorry\n  example : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := sorry\n  example : \u00acp \u2192 (p \u2192 q) := sorry\n  example : (\u00acp \u2228 q) \u2192 (p \u2192 q) := sorry\n  example : p \u2228 false \u2194 p := sorry\n  example : p \u2227 false \u2194 false := sorry\n  example : \u00ac(p \u2194 \u00acp) := sorry\n  example : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := sorry\n\n  -- these require classical reasoning\n  open classical\n  example : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := sorry\n  example : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := sorry\n  example : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := sorry\n  example : (p \u2192 q) \u2192 (\u00acp \u2228 q) := sorry\n  example : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := sorry\n  example : p \u2228 \u00acp := sorry\n  example : (((p \u2192 q) \u2192 p) \u2192 p) := sorry\n\nend Section_3_6\n\n#print \"  \"\n#print \"===============================\"\n#print \"Section 3.7 Exercises\"\n#print \"  \"\nnamespace Section_3_7\n\nend Section_3_7\n\n\n", "meta": {"author": "williamdemeo", "repo": "LEAN_wjd", "sha": "13826c75c06ef435166a26a72e76fe984c15bad7", "save_path": "github-repos/lean/williamdemeo-LEAN_wjd", "path": "github-repos/lean/williamdemeo-LEAN_wjd/LEAN_wjd-13826c75c06ef435166a26a72e76fe984c15bad7/theorem_proving/03-propositions_and_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7352183804964942}}
{"text": "import ..lectures.love10_denotational_semantics_demo\n\n\n/-! # LoVe Exercise 10: Denotational Semantics -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Monotonicity\n\n1.1. Prove the following lemma from the lecture. -/\n\nlemma monotone_comp {\u03b1 \u03b2 : Type} [partial_order \u03b1] (f g : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (\u03bba, f a \u25ef g a) :=\nbegin\n  intros a\u2081 a\u2082 ha b hb,\n  cases' hb with m hm,\n  cases' hm,\n  apply exists.intro m,\n  apply and.intro,\n  { exact hf _ _ ha left },\n  { exact hg _ _ ha right }\nend\n\n/-! 1.2. Prove its cousin. -/\n\nlemma monotone_restrict {\u03b1 \u03b2 : Type} [partial_order \u03b1] (f : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2))\n    (p : \u03b2 \u2192 Prop) (hf : monotone f) :\n  monotone (\u03bba, f a \u21c3 p) :=\nbegin\n  intros a\u2081 a\u2082 ha b hb,\n  cases' hb,\n  apply and.intro,\n  { apply hf _ _ ha,\n    exact left },\n  { exact right }\nend\n\n\n/-! ## Question 2: Regular Expressions\n\n__Regular expressions__, or __regexes__, are a highly popular tool for software\ndevelopment, to analyze textual inputs. Regexes are generated by the following\ngrammar:\n\n    R ::= \u2205\n        | \u03b5\n        | a\n        | R \u2b1d R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `\u2205` accepts nothing;\n* `\u03b5` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R \u2b1d R` accepts the concatenation of two regexes;\n* `R + R` accepts either of two regexes;\n* `R*` accepts arbitrary many repetitions of a regex.\n\nNotice the rough correspondence with a WHILE language:\n\n    `\u2205` ~ diverging statement (e.g., `while true do skip`)\n    `\u03b5` ~ `skip`\n    `a` ~ `:=`\n    `\u2b1d` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (\u03b1 : Type) : Type\n| nothing : regex\n| empty   : regex\n| atom    : \u03b1 \u2192 regex\n| concat  : regex \u2192 regex \u2192 regex\n| alt     : regex \u2192 regex \u2192 regex\n| star    : regex \u2192 regex\n\n/-! In this exercise, we explore an alternative semantics of regular\nexpressions. Namely, we can imagine that the atoms represent binary relations,\ninstead of letters or symbols. Concatenation corresponds to composition of\nrelations, and alternation is union. Mathematically, regexes and binary\nrelations are both instances of Kleene algebras.\n\n2.1. Complete the following translation of regular expressions to relations.\n\nHint: Exploit the correspondence with the WHILE language. -/\n\ndef rel_of_regex {\u03b1 : Type} : regex (set (\u03b1 \u00d7 \u03b1)) \u2192 set (\u03b1 \u00d7 \u03b1)\n| regex.nothing        := \u2205\n| regex.empty          := Id\n| (regex.atom s)       := s\n| (regex.concat r\u2081 r\u2082) := rel_of_regex r\u2081 \u25ef rel_of_regex r\u2082\n| (regex.alt r\u2081 r\u2082)    := rel_of_regex r\u2081 \u222a rel_of_regex r\u2082\n| (regex.star r)       := lfp (\u03bbX, (rel_of_regex r \u25ef X) \u222a Id)\n\n/-! 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {\u03b1 : Type} (r : regex (set (\u03b1 \u00d7 \u03b1))) :\n  rel_of_regex (regex.star r) =\n  rel_of_regex (regex.alt (regex.concat r (regex.star r)) regex.empty) :=\nbegin\n  apply lfp_eq,\n  apply monotone_union,\n  { apply monotone_comp,\n    { exact monotone_const _ },\n    { exact monotone_id } },\n  { exact monotone_const _ }\nend\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/exercises/love10_denotational_semantics_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7350986888442252}}
{"text": "import group.basic\nimport int.iterate\n\nnamespace mygroup\n\nnamespace group\n\nvariables {G : Type} [group G]\n\nopen int \n\n/-- left multiplication is a bijection-/\ndef lmul (g : G) : G \u2243 G :=\n{ to_fun := (*) g, inv_fun := (*) g\u207b\u00b9,\n  left_inv := begin intro x, rw [\u2190 mul_assoc, mul_left_inv, one_mul], end,\n  right_inv := begin intro x, rw [\u2190 mul_assoc, mul_right_inv, one_mul] end }\n\ndef pow : G \u2192 \u2124 \u2192 G :=\n  \u03bb g n, (iterate n (lmul g)) 1\n\ninstance : has_pow G \u2124 := \u27e8pow\u27e9\n\nvariables (n m : \u2124) (g h k : G)\n\nlemma lmul_one : (lmul g) 1 = g := mul_one g\n\nlemma lmul_symm  : (lmul g).symm = lmul g\u207b\u00b9 := by ext; refl\nlemma lmul_symm' : (lmul g)\u207b\u00b9 = (lmul g).symm := rfl\n\nlemma pow_def     : g ^ n = iterate n (lmul g) 1 := rfl \nlemma pow_one_mul : iterate 1 (lmul g) h = g * h := rfl\n\n@[simp] lemma pow_zero : g ^ (0 : \u2124) = 1 := rfl\n@[simp] lemma pow_one  : g ^ (1 : \u2124) = g := \nbegin\n  rw [pow_def, iterate.one],\n  exact mul_one g, \nend\n\ntheorem pow_neg : g ^ -n = g\u207b\u00b9 ^ n :=\nby rw [pow_def, pow_def, \u2190 lmul_symm, \u2190 iterate.neg]\n\n-- A direct corollary\n@[simp] theorem pow_neg_one_inv (g : G) : g ^ (-1 : \u2124) = g\u207b\u00b9 := by simp [pow_neg 1 g]\n\nlemma iterate_succ : iterate (n + 1) (lmul g) h = g * iterate n (lmul g) h := \nby rw [add_comm, \u2190 iterate.comp, pow_one_mul]\n\nlemma iterate_mul_assoc : (iterate n (lmul g) h) * k = iterate n (lmul g) (h * k) :=\nbegin\n  apply int.induction_on' n 0,\n    { refl },\n    { intros _ _ h,\n      rw [iterate_succ, mul_assoc, h, \u2190 iterate_succ] },\n    { intros m _ h,\n      rw [show m - 1 = -(-m + 1), by ring],\n      rw [iterate.neg, lmul_symm, iterate_succ, mul_assoc,\n          \u2190 lmul_symm, \u2190 iterate.neg, neg_neg, h, lmul_symm, \n          iterate_succ, \u2190 lmul_symm, \u2190 iterate.neg, neg_neg] }\nend\n\nlemma pow_mul_eq_iterate (n : \u2124) : g ^ n * k = iterate n (lmul g) k :=\nby convert iterate_mul_assoc n g 1 k; exact (one_mul _).symm\n\ntheorem pow_add : g ^ (m + n) = g ^ m * g ^ n :=\nbegin\n  iterate 3 { rw pow_def },\n  rw [\u2190 iterate.comp, iterate_mul_assoc, one_mul]\nend\n\ntheorem pow_sub : g ^ (m - n) = g ^ m * g ^ (-n) :=\nby rw [sub_eq_add_neg, pow_add]\n\ntheorem pow_mul : g ^ (m  * n) = (g ^ n) ^ m :=\nbegin\n  simp [pow_def],\n  rw [\u2190 iterate.mul _ _ _ g], \n  congr, ext,\n  show _ = (n.iterate (lmul g)) 1 * x,\n  rw [iterate_mul_assoc, one_mul],\nend\n\ntheorem pow_inv : (g ^ n)\u207b\u00b9 = g\u207b\u00b9 ^ n :=\nbegin\n  apply int.induction_on n,\n  { simp },\n  { intros i hi,\n    rw [pow_add, pow_one, inv_mul, hi, add_comm, pow_add, pow_one] },\n  { intros i hi,\n    rw [pow_sub, sub_eq_add_neg, add_comm, pow_add, pow_neg, pow_neg, pow_one,\n      inv_mul, inv_inv, \u2190 pow_neg i, hi, pow_neg 1, inv_inv, pow_one] },  \nend\n\n@[simp] lemma one_pow : (1 : G) ^ n = 1 := \nbegin\n  apply int.induction_on n,\n    { exact pow_zero 1 },\n    { intros i hi, rw [pow_add, hi, pow_one, one_mul] },\n    { intros i hi, rw [sub_eq_add_neg, pow_add, hi, one_mul, pow_neg, pow_one, one_inv] }\nend\n\ntheorem mul_pow {H : Type} [hH :comm_group H] {g h : H} : \n  g ^ n * h ^ n = (g * h) ^ n := \nbegin\n  rw [pow_def, pow_def, pow_def, iterate_mul_assoc, one_mul],\n  apply int.induction_on' n 0,\n    { simp },\n    { intros k hk _ ,\n      repeat { rw iterate_succ },\n      rw [\u2190 a, \u2190 iterate_mul_assoc],\n      simp [\u2190 pow_mul_eq_iterate, mul_assoc, hH.mul_comm, hH.mul_comm, mul_assoc] },\n    { intros k hk _,\n      cases (show \u2203 m : \u2124, m + 1 = k, by exact \u27e8k - 1, by norm_num\u27e9) with m hm,    \n      rw \u2190 hm at *,\n      repeat { rw iterate_succ at a },\n      rw [\u2190 add_sub, sub_self, add_zero],       \n      simp [\u2190 pow_mul_eq_iterate, mul_assoc, hH.mul_comm] at *,\n      apply mul_left_cancel'' h,\n      rw [\u2190 a, hH.mul_comm],\n      simp [hH.mul_comm, mul_assoc] }\nend  \n\nend group\n\nend mygroup", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/src/group/powers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7350986806394405}}
{"text": "import mini_crush\n\nnamespace hide\n-- *Inductive Predicates\n\n#print unit\n#print true\n\n-- term T : Type is a type of programs\n-- it is inhabited by programs\n-- term T : Prop is a logical proposition\n-- it is inhabited by proofs\n\n-- there *is* a difference between programming and proving in practice\n\n-- proof irrelevance\n-- to an engineer: not all functions of type A \u2192 B are created equal but all proofs P \u2192 Q are\n-- ofc this is not true for mathematicians, but they have different criterion for good proofs than programmers have for good programs (right?)\n\n-- **Propositional Logic\nsection Propositional\nvariables P Q R : Prop\n\ntheorem obvious : true :=\nby apply true.intro\n\ntheorem obvious' : true :=\nby constructor\n\n#print false\n\ntheorem false_imp : false \u2192 2 + 2 = 5 :=\nby intro f; destruct f\n\ntheorem false_imp_lean : false \u2192 2 + 2 = 5 :=\nby contradiction\n\n-- TODO: not sure how to prove this in lean. Is there an elimtype analogue?\ntheorem arith_neq : 2 + 2 = 5 \u2192 9 + 9 = 835 :=\nbegin\nintro,\nexfalso,\nadmit\nend\n\n#print not\n\ntheorem arith_neq' : \u00ac(2 + 2 = 5) :=\nbegin\nunfold not,\n-- what to use next?\nadmit\nend\n\n#print and\n\ntheorem and_comm : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\nintro p,\ndestruct p,\nintros h1 h2,\nsplit; assumption\nend\n\ntheorem and_comm_idiomatic : P \u2227 Q \u2192 Q \u2227 P := by intros; simp; assumption\n\ntheorem and_comm_lean (h:P \u2227 Q):Q \u2227 P:=\nand.intro (and.right h) (and.left h)\n\ntheorem and_comm_lean_short (h:P \u2227 Q):Q \u2227 P:=\n\u27e8h.right, h.left\u27e9\n\n#print or\n\ntheorem or_comm (h:P \u2228 Q) : Q \u2228 P :=\nbegin\nexact h.elim\n    (assume hp : P, or.inr hp)\n    (assume hq : Q, or.inl hq)\nend\n\nuniverse variable u\n\ndef length {\u03b1 : Type u} : list \u03b1 \u2192 nat\n| list.nil        := nat.zero\n| (list.cons _ l) := nat.succ (length l)\n\n-- TODO:\ntheorem arith_comm : \u2200 ls1 ls2 : list nat,\n    length ls1 = length ls2 \u2228 length ls1 + length ls2 = 6\n    \u2192 length (ls1 ++ ls2) = 6 \u2228 length ls1 = length ls2 :=\nbegin\nadmit\nend\n\nend Propositional\n\n-- **What Does It Mean to Be Constructive?\n-- **First-Order Logic\n#print Exists\n\ntheorem exist1 : \u2203 x : \u2115, x + 1 = 2 :=\n\u27e81, by simp\u27e9\n\n-- TODO: simpler way?\ntheorem exist2 : \u2200 n m : \u2115, (\u2203 x : \u2115, n + x = m) \u2192 n \u2264 m :=\nbegin\nintros,\ndestruct a,\nintros,\nsubst a_2,\napply nat.le_add_right\nend\n\n-- **Predicates with Implicit Equality\ninductive isZero : \u2115 \u2192 Prop\n| IsZero : isZero 0\n\ntheorem isZero_zero : isZero 0 := by constructor\n\n#print eq\n\n-- Notice destruct does not work here, must use induction instead\n-- TODO: is this the \"correct\" tactic?\ntheorem isZero_plus : \u2200 n m : \u2115, isZero m \u2192 n + m = n :=\nbegin\nintros,\ninduction a,\nsimp\nend\n\ntheorem isZero_contra : isZero 1 \u2192 false :=\nbegin\nintros,\ncases a\nend\n\n#check @isZero.rec\n\n-- **Recursive Predicates\ninductive even : \u2115 \u2192 Prop\n| EvenO  : even nat.zero\n| EvenSS : \u2200 n, even n \u2192 even (nat.succ (nat.succ n))\n\ntheorem even_0 : even 0 := by constructor\n\ntheorem even_4 : even 4 := by repeat {constructor}\n\n-- TODO: hints?\n\ntheorem even_1_contra : even 1 \u2192 false :=\nbegin\nintros,\ncases a\nend\n\ntheorem even_3_contra : even 3 \u2192 false :=\nbegin\nintros,\ncases a,\ncases a_2\nend\n\ntheorem even_plus_on_n : \u2200 n m, even n \u2192 even m \u2192 even (n + m) :=\nbegin\nintro n,\ninduction n,\ncase nat.zero {mini_crush},\ncase nat.succ {\n    intros,\n    note h : \u2200 x y, nat.succ x + y = nat.succ (x + y) := by apply nat.succ_add,\n    rw h,\n    cases a_1,\n    rw h,\n    constructor,\n    admit\n}\nend\n\ntheorem even_plus_on_a : \u2200 n m, even n \u2192 even m \u2192 even (n + m) :=\nbegin\nintros,\ninduction a,\n{mini_crush},\n{\n    simp,\n    constructor,\n    rw nat.add_comm,\n    assumption\n}\nend\n\n-- Note: mini_crush doesn't work for even_plus\n\n-- TODO: finish this\nlemma even_contra' : \u2200 n', even n' \u2192 \u2200 n, n' = nat.succ (n + n) \u2192 false :=\nbegin\nintros n a,\ninduction a,\n{mini_crush},\n{\n    intros,\n    apply (ih_1 n_2),\n    symmetry,\n    admit\n}\nend\n\n-- TODO\ntheorem even_contra : \u2200 n, even (nat.succ (n + n)) \u2192 false :=\nbegin\nintros,\nadmit\nend\n\nend hide", "meta": {"author": "joshpoll", "repo": "CPDT-examples-in-Lean", "sha": "287aebec9a4a9dc4a07b8e4cc885c81afe400f1a", "save_path": "github-repos/lean/joshpoll-CPDT-examples-in-Lean", "path": "github-repos/lean/joshpoll-CPDT-examples-in-Lean/CPDT-examples-in-Lean-287aebec9a4a9dc4a07b8e4cc885c81afe400f1a/4_Predicates.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.735098678429427}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport ring_theory.noetherian -- theory of Noetherian rings\nimport ring_theory.polynomial\n\n/-\n\n# Commutative algebra\n\nMore Conrad, again from \n\nhttps://kconrad.math.uconn.edu/blurbs/ringtheory/noetherian-ring.pdf\n\nBut this time it's nasty.\n\nLet's *start* to prove Theorem 3.6 following Conrad: if R is Noetherian then R[X] is\nNoetherian.\n\nIt's not impossible, but it's messy, to make a complex recursive\ndefinition in the middle of a proof, so we factor it out and do it first.\nThe set-up is: R is a commutative ring and I \u2286 R[X] is an ideal which\nis *not* finitely-generated. We then define a sequence f\u2099 of elements of R[X]\nby strong recursion: f\u2099 is an element of smallest degree in `I - (f\u2080,f\u2081,\u2026f\u2099\u208b\u2081)`;\nnote that such an element must exist as `I` is not finitely-generated (and \u2115 is\nwell-ordered).\n\n-/\n\nopen_locale polynomial -- for R[X] notation\n\n-- Here's how Conrad's proof starts \nexample (R : Type) [comm_ring R] [is_noetherian_ring R] : \n  is_noetherian_ring R[X] :=\nbegin\n  -- Suffices to prove all ideals are finitely generated\n  rw is_noetherian_ring_iff_ideal_fg,\n  -- By contradiction. Assume `I` isn't.\n  by_contra h, push_neg at h, rcases h with \u27e8I, hInotfg\u27e9,\n  -- Define a sequence f\u2099 of elements of `I` by strong recursion: \n  -- f\u2099 is an element of smallest degree in I - (f\u2080,f\u2081,\u2026,f\u2099\u208b\u2081)\n  sorry, -- we won't fill this in, let's just discuss how to define `f\u2099`\n  -- (the proof is quite long even after this construction)\nend\n\n-- If I is a non-finitely-generated ideal of a commutative ring A,\n-- and f\u2080,f\u2081,...,f\u2099\u208b\u2081 are elements of I, then I - (f\u2080,f\u2081,\u2026,f\u2099\u208b\u2081) is nonempty\nlemma lemma1 {A : Type} [comm_ring A] [decidable_eq A] (I : ideal A) (hInonfg : \u00ac I.fg) (n : \u2115)\n  (g : \u03a0 m, m < n \u2192 I) : \n  set.nonempty ((I : set A) \\ (ideal.span (finset.image (\u03bb m : fin n, (g m.1 m.2).1) finset.univ : set A))) :=\nbegin\n  sorry,\nend\n\n-- If a subset of a set with a \"\u2115-valued height function\" (e.g. R[X] with `polynomial.nat_degree)\n-- is nonempty, then this is a function which returns an element with smallest height.\ndef smallest_height {A : Type} (h : A \u2192 \u2115) {S : set A} (hs : set.nonempty S) : S :=\nsorry\n\n-- The function Conrad wants:\ndef f {R : Type} [comm_ring R] {I : ideal R[X]} (hInonfg : \u00ac I.fg) \n  : \u2115 \u2192 I := \nsorry\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section16commutative_algebra/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7350986744329128}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module geometry.manifold.metrizable\n! leanprover-community/mathlib commit d1bd9c5df2867c1cb463bc6364446d57bdd9f7f1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Geometry.Manifold.SmoothManifoldWithCorners\nimport Mathbin.Topology.Paracompact\nimport Mathbin.Topology.MetricSpace.Metrizable\n\n/-!\n# Metrizability of a \u03c3-compact manifold\n\nIn this file we show that a \u03c3-compact Hausdorff topological manifold over a finite dimensional real\nvector space is metrizable.\n-/\n\n\nopen TopologicalSpace\n\n/-- A \u03c3-compact Hausdorff topological manifold over a finite dimensional real vector space is\nmetrizable. -/\ntheorem ManifoldWithCorners.metrizableSpace {E : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E]\n    [FiniteDimensional \u211d E] {H : Type _} [TopologicalSpace H] (I : ModelWithCorners \u211d E H)\n    (M : Type _) [TopologicalSpace M] [ChartedSpace H M] [SigmaCompactSpace M] [T2Space M] :\n    MetrizableSpace M := by\n  haveI := I.locally_compact; haveI := ChartedSpace.locally_compact H M\n  haveI : NormalSpace M := normal_of_paracompact_t2\n  haveI := I.second_countable_topology\n  haveI := ChartedSpace.second_countable_of_sigma_compact H M\n  exact metrizable_space_of_t3_second_countable M\n#align manifold_with_corners.metrizable_space ManifoldWithCorners.metrizableSpace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Geometry/Manifold/Metrizable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7350879468148092}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport linear_algebra.matrix.adjugate\nimport ring_theory.polynomial_algebra\nimport tactic.apply_fun\nimport tactic.squeeze\n\n/-!\n# Characteristic polynomials and the Cayley-Hamilton theorem\n\nWe define characteristic polynomials of matrices and\nprove the Cayley\u2013Hamilton theorem over arbitrary commutative rings.\n\nSee the file `matrix/charpoly/coeff` for corollaries of this theorem.\n\n## Main definitions\n\n* `matrix.charpoly` is the characteristic polynomial of a matrix.\n\n## Implementation details\n\nWe follow a nice proof from http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\n-/\n\nnoncomputable theory\n\nuniverses u v w\n\nopen polynomial matrix\nopen_locale big_operators polynomial\n\nvariables {R : Type u} [comm_ring R]\nvariables {n : Type w} [decidable_eq n] [fintype n]\n\nopen finset\n\n\n/--\nThe \"characteristic matrix\" of `M : matrix n n R` is the matrix of polynomials $t I - M$.\nThe determinant of this matrix is the characteristic polynomial.\n-/\ndef charmatrix (M : matrix n n R) : matrix n n R[X] :=\nmatrix.scalar n (X : R[X]) - (C : R \u2192+* R[X]).map_matrix M\n\nlemma charmatrix_apply (M : matrix n n R) (i j : n) :\n  charmatrix M i j = X * (1 : matrix n n R[X]) i j - C (M i j) := rfl\n\n@[simp] lemma charmatrix_apply_eq (M : matrix n n R) (i : n) :\n  charmatrix M i i = (X : R[X]) - C (M i i) :=\nby simp only [charmatrix, sub_left_inj, pi.sub_apply, scalar_apply_eq,\n  ring_hom.map_matrix_apply, map_apply, dmatrix.sub_apply]\n\n@[simp] lemma charmatrix_apply_ne (M : matrix n n R) (i j : n) (h : i \u2260 j) :\n  charmatrix M i j = - C (M i j) :=\nby simp only [charmatrix, pi.sub_apply, scalar_apply_ne _ _ _ h, zero_sub,\n  ring_hom.map_matrix_apply, map_apply, dmatrix.sub_apply]\n\nlemma mat_poly_equiv_charmatrix (M : matrix n n R) :\n  mat_poly_equiv (charmatrix M) = X - C M :=\nbegin\n  ext k i j,\n  simp only [mat_poly_equiv_coeff_apply, coeff_sub, pi.sub_apply],\n  by_cases h : i = j,\n  { subst h, rw [charmatrix_apply_eq, coeff_sub],\n    simp only [coeff_X, coeff_C],\n    split_ifs; simp, },\n  { rw [charmatrix_apply_ne _ _ _ h, coeff_X, coeff_neg, coeff_C, coeff_C],\n    split_ifs; simp [h], }\nend\n\nlemma charmatrix_reindex {m : Type v} [decidable_eq m] [fintype m] (e : n \u2243 m)\n  (M : matrix n n R) : charmatrix (reindex e e M) = reindex e e (charmatrix M) :=\nbegin\n  ext i j x,\n  by_cases h : i = j,\n  all_goals { simp [h] }\nend\n\n/--\nThe characteristic polynomial of a matrix `M` is given by $\\det (t I - M)$.\n-/\ndef matrix.charpoly (M : matrix n n R) : R[X] :=\n(charmatrix M).det\n\nlemma matrix.charpoly_reindex {m : Type v} [decidable_eq m] [fintype m] (e : n \u2243 m)\n  (M : matrix n n R) : (reindex e e M).charpoly = M.charpoly :=\nbegin\n  unfold matrix.charpoly,\n  rw [charmatrix_reindex, matrix.det_reindex_self]\nend\n\n/--\nThe **Cayley-Hamilton Theorem**, that the characteristic polynomial of a matrix,\napplied to the matrix itself, is zero.\n\nThis holds over any commutative ring.\n\nSee `linear_map.aeval_self_charpoly` for the equivalent statement about endomorphisms.\n-/\n-- This proof follows http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\ntheorem matrix.aeval_self_charpoly (M : matrix n n R) :\n  aeval M M.charpoly = 0 :=\nbegin\n  -- We begin with the fact $\u03c7_M(t) I = adjugate (t I - M) * (t I - M)$,\n  -- as an identity in `matrix n n R[X]`.\n  have h : M.charpoly \u2022 (1 : matrix n n R[X]) =\n    adjugate (charmatrix M) * (charmatrix M) :=\n    (adjugate_mul _).symm,\n  -- Using the algebra isomorphism `matrix n n R[X] \u2243\u2090[R] polynomial (matrix n n R)`,\n  -- we have the same identity in `polynomial (matrix n n R)`.\n  apply_fun mat_poly_equiv at h,\n  simp only [mat_poly_equiv.map_mul,\n    mat_poly_equiv_charmatrix] at h,\n  -- Because the coefficient ring `matrix n n R` is non-commutative,\n  -- evaluation at `M` is not multiplicative.\n  -- However, any polynomial which is a product of the form $N * (t I - M)$\n  -- is sent to zero, because the evaluation function puts the polynomial variable\n  -- to the right of any coefficients, so everything telescopes.\n  apply_fun (\u03bb p, p.eval M) at h,\n  rw eval_mul_X_sub_C at h,\n  -- Now $\u03c7_M (t) I$, when thought of as a polynomial of matrices\n  -- and evaluated at some `N` is exactly $\u03c7_M (N)$.\n  rw [mat_poly_equiv_smul_one, eval_map] at h,\n  -- Thus we have $\u03c7_M(M) = 0$, which is the desired result.\n  exact h,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7350879327545314}}
{"text": "/-\nCopyright (c) 2019 Alexander Bentkamp. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp\n\nConvex sets and functions on real vector spaces\n-/\n\nimport analysis.normed_space.basic\nimport data.complex.basic\nimport data.set.intervals\nimport tactic.interactive\nimport tactic.linarith\nimport linear_algebra.basic\nimport ring_theory.algebra\n\nlocal attribute [instance] classical.prop_decidable\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b9 : Sort _}\n  [add_comm_group \u03b1] [vector_space \u211d \u03b1] [add_comm_group \u03b2] [vector_space \u211d \u03b2]\n  (A : set \u03b1) (B : set \u03b1) (x : \u03b1)\n\n/-- Convexity of sets -/\ndef convex (A : set \u03b1) :=\n\u2200 (x y : \u03b1) (a b : \u211d), x \u2208 A \u2192 y \u2208 A \u2192 0 \u2264 a \u2192 0 \u2264 b \u2192 a + b = 1 \u2192\n  a \u2022 x + b \u2022 y \u2208 A\n\n/-- Alternative definition of set convexity -/\nlemma convex_iff:\n  convex A \u2194 \u2200 {x y : \u03b1} {\u03b8 : \u211d},\n    x \u2208 A \u2192 y \u2208 A \u2192 0 \u2264 \u03b8 \u2192 \u03b8 \u2264 1 \u2192 \u03b8 \u2022 x + (1 - \u03b8) \u2022 y \u2208 A :=\n\u27e8begin\n  assume h x y \u03b8 hx hy h\u03b8\u2081 h\u03b8\u2082,\n  have h\u03b8\u2082 : 0 \u2264 1 - \u03b8, by linarith,\n  exact (h _ _ _ _ hx hy h\u03b8\u2081 h\u03b8\u2082 (by linarith))\nend,\nbegin\n  assume h x y a b hx hy ha hb hab,\n  have ha' : a \u2264 1, by linarith,\n  have hb' : b = 1 - a, by linarith,\n  rw hb',\n  exact h hx hy ha ha'\nend\u27e9\n\n/-- Another alternative definition of set convexity -/\nlemma convex_iff_div:\n  convex A \u2194 \u2200 {x y : \u03b1} {a : \u211d} {b : \u211d},\n    x \u2208 A \u2192 y \u2208 A \u2192 0 \u2264 a \u2192 0 \u2264 b \u2192 0 < a + b \u2192 (a/(a+b)) \u2022 x + (b/(a+b)) \u2022 y \u2208 A :=\n\u27e8begin\n  assume h x y a b hx hy ha hb hab,\n  apply h _ _ _ _ hx hy,\n  have ha', from mul_le_mul_of_nonneg_left ha (le_of_lt (inv_pos hab)),\n  rwa [mul_zero, \u2190div_eq_inv_mul] at ha',\n  have hb', from mul_le_mul_of_nonneg_left hb (le_of_lt (inv_pos hab)),\n  rwa [mul_zero, \u2190div_eq_inv_mul] at hb',\n  rw [\u2190add_div],\n  exact div_self (ne_of_lt hab).symm\nend,\nbegin\n  assume h x y a b hx hy ha hb hab,\n  have h', from h hx hy ha hb,\n  rw [hab, div_one, div_one] at h',\n  exact h' zero_lt_one\nend\u27e9\n\nlocal notation `I` := (Icc 0 1 : set \u211d)\n\n/-- Segments in a vector space -/\ndef segment (x y : \u03b1) := {z : \u03b1 | \u2203 l : \u211d, l \u2208 I \u2227 z - x = l\u2022(y-x)}\nlocal notation `[`x `, ` y `]` := segment x y\n\nlemma left_mem_segment (x y : \u03b1) : x \u2208 [x, y] := \u27e80, \u27e8\u27e8le_refl _, zero_le_one\u27e9, by simp\u27e9\u27e9\n\nlemma right_mem_segment (x y : \u03b1) : y \u2208 [x, y] := \u27e81, \u27e8\u27e8zero_le_one, le_refl _\u27e9, by simp\u27e9\u27e9\n\nlemma mem_segment_iff {x y z : \u03b1} : z \u2208 [x, y] \u2194 \u2203 l \u2208 I, z = x + l\u2022(y - x) :=\nby split; rintro \u27e8l, l_in, H\u27e9; use [l, l_in]; try { rw sub_eq_iff_eq_add at H }; rw H; abel\n\nlemma mem_segment_iff' {x y z : \u03b1} : z \u2208 [x, y] \u2194 \u2203 l \u2208 I, z = ((1:\u211d)-l)\u2022x + l\u2022y :=\nbegin\n  split; rintro \u27e8l, l_in, H\u27e9; use [l, l_in]; try { rw sub_eq_iff_eq_add at H }; rw H;\n  simp only [smul_sub, sub_smul, one_smul]; abel,\nend\n\nlemma segment_symm (x y : \u03b1) : [x, y] = [y, x] :=\nbegin\n  ext z,\n  rw [mem_segment_iff', mem_segment_iff'],\n  split,\n  all_goals {\n    rintro \u27e8l, \u27e8hl\u2080, hl\u2081\u27e9, h\u27e9,\n    use (1-l),\n    split,\n    split; linarith,\n    rw [h]; simp },\nend\n\nlemma segment_eq_Icc {a b : \u211d} (h : a \u2264 b) : [a, b] = Icc a b :=\nbegin\n  ext z,\n  rw mem_segment_iff,\n  split,\n  { rintro \u27e8l, \u27e8hl\u2080, hl\u2081\u27e9, H\u27e9,\n    rw smul_eq_mul at H,\n    have hba : 0 \u2264 b - a, by linarith,\n    split ; rw H,\n    { have := mul_le_mul (le_refl l) hba (le_refl _) hl\u2080,\n      simpa using this, },\n    { have := mul_le_mul hl\u2081 (le_refl (b-a)) hba zero_le_one,\n      rw one_mul at this,\n      apply le_trans (add_le_add (le_refl a) this),\n      convert le_refl _,\n      show b = a + (b-a), by ring } },\n  { rintro \u27e8hza, hzb\u27e9,\n    by_cases hba : b-a = 0,\n    { use [(0:\u211d), \u27e8le_refl 0, zero_le_one\u27e9],\n      rw zero_smul, linarith },\n    { have : (z-a)/(b-a) \u2208 I,\n      { change b -a \u2260 0 at hba,\n        have : 0 < b - a, from lt_of_le_of_ne (by linarith) hba.symm,\n        split,\n        apply div_nonneg ; linarith,\n        apply (div_le_iff this).2,\n        simp, convert hzb, ring},\n      use [(z-a)/(b-a), this],\n      rw [smul_eq_mul, div_mul_cancel],\n      ring,\n      exact hba } }\nend\n\nlemma segment_translate (a b c x : \u03b1) (hx : x \u2208 [b, c]) : a + x \u2208 [a + b, a + c] :=\nbegin\n  refine exists.elim hx (\u03bb\u03b8 h\u03b8, \u27e8\u03b8, \u27e8h\u03b8.1, _\u27e9\u27e9),\n  simp only [smul_sub, smul_add] at *,\n  simp [smul_add, (add_eq_of_eq_sub h\u03b8.2.symm).symm]\nend\n\nlemma segment_translate_image (a b c: \u03b1) : (\u03bbx, a + x) '' [b, c] = [a + b, a + c] :=\nbegin\n  apply subset.antisymm,\n  { intros z hz,\n    apply exists.elim hz,\n    intros x hx,\n    convert segment_translate a b c x _,\n    { exact hx.2.symm },\n    { exact hx.1 } },\n  { intros z hz,\n    apply exists.elim hz,\n    intros \u03b8 h\u03b8,\n    use z - a,\n    apply and.intro,\n    { convert segment_translate (-a) (a + b) (a + c) z hz; simp },\n    { simp only [add_sub_cancel'_right] } }\nend\n\n/-- Alternative defintion of set convexity using segments -/\nlemma convex_segment_iff : convex A \u2194 \u2200 x y \u2208 A, [x, y] \u2286 A :=\nbegin\n  apply iff.intro,\n  { intros hA x y hx hy z hseg,\n    apply exists.elim hseg,\n    intros l hl,\n    have hz : z = l \u2022 y + (1-l) \u2022 x,\n    { rw sub_eq_iff_eq_add.1 hl.2,\n      rw [smul_sub, sub_smul, one_smul],\n      simp },\n    rw hz,\n    apply (convex_iff A).1 hA hy hx hl.1.1 hl.1.2 },\n  { intros hA,\n    rw convex_iff,\n    intros x y \u03b8 hx hy h\u03b8\u2080 h\u03b8\u2081,\n    apply hA y x hy hx,\n    use \u03b8,\n    apply and.intro,\n    { exact and.intro h\u03b8\u2080 h\u03b8\u2081 },\n    { simp only [smul_sub, sub_smul, one_smul],\n      simp } }\nend\n\n\n/- Examples of convex sets -/\n\nlemma convex_empty : convex (\u2205 : set \u03b1) :=  by finish\n\nlemma convex_singleton (a : \u03b1) : convex ({a} : set \u03b1) :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  rw [set.eq_of_mem_singleton hx, set.eq_of_mem_singleton hy, \u2190add_smul, hab],\n  simp\nend\n\nlemma convex_univ : convex (set.univ : set \u03b1) := by finish\n\nlemma convex_inter (hA: convex A) (hB: convex B) : convex (A \u2229 B) :=\n\u03bb x y a b (hx : x \u2208 A \u2229 B) (hy : y \u2208 A \u2229 B) (ha : 0 \u2264 a) (hb : 0 \u2264 b) (hab : a + b = 1),\n  \u27e8hA _ _ _ _ hx.left hy.left ha hb hab, hB _ _ _ _ hx.right hy.right ha hb hab\u27e9\n\nlemma convex_Inter {s: \u03b9 \u2192 set \u03b1} (h: \u2200 i : \u03b9, convex (s i)) : convex (Inter s) :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  apply mem_Inter.2,\n  exact \u03bbi, h i _ _ _ _ (mem_Inter.1 hx i) (mem_Inter.1 hy i) ha hb hab\nend\n\nlemma convex_prod {A : set \u03b1} {B : set \u03b2} (hA : convex A) (hB : convex B) :\n  convex (set.prod A B) :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  apply mem_prod.2,\n  exact \u27e8hA _ _ _ _ (mem_prod.1 hx).1 (mem_prod.1 hy).1 ha hb hab,\n        hB _ _ _ _ (mem_prod.1 hx).2 (mem_prod.1 hy).2 ha hb hab\u27e9\nend\n\nlemma convex_linear_image (f : \u03b1 \u2192 \u03b2) (hf : is_linear_map \u211d f) (hA : convex A) : convex (image f A) :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  apply exists.elim hx,\n  intros x' hx',\n  apply exists.elim hy,\n  intros y' hy',\n  use a \u2022 x' + b \u2022 y',\n  split,\n  { apply hA _ _ _ _ hx'.1 hy'.1 ha hb hab },\n  { simp [hx',hy',hf.add,hf.smul] }\nend\n\nlemma convex_linear_image' (f : \u03b1 \u2192\u2097[\u211d] \u03b2) (hA : convex A) : convex (image f A) :=\nconvex_linear_image A f.to_fun (linear_map.is_linear f) hA\n\nlemma convex_linear_preimage (A : set \u03b2) (f : \u03b1 \u2192 \u03b2) (hf : is_linear_map \u211d f) (hA : convex A) :\n  convex (preimage f A) :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  simp [hf.add, hf.smul],\n  exact hA (f x) (f y) a b hx hy ha hb hab\nend\n\nlemma convex_linear_preimage' (A : set \u03b2) (f : \u03b1 \u2192\u2097[\u211d] \u03b2) (hA : convex A) :\n  convex (preimage f A) :=\nconvex_linear_preimage A f.to_fun (linear_map.is_linear f) hA\n\nlemma convex_neg : convex A \u2192 convex ((\u03bb z, -z) '' A) :=\nconvex_linear_image _ _ is_linear_map.is_linear_map_neg\n\nlemma convex_neg_preimage : convex A \u2192 convex ((\u03bb z, -z) \u207b\u00b9' A) :=\nconvex_linear_preimage _ _ is_linear_map.is_linear_map_neg\n\nlemma convex_smul (c : \u211d) : convex A \u2192 convex ((\u03bb z, c \u2022 z) '' A) :=\nconvex_linear_image _ _ (is_linear_map.is_linear_map_smul c)\n\nlemma convex_smul_preimage (c : \u211d) : convex A \u2192 convex ((\u03bb z, c \u2022 z) \u207b\u00b9' A) :=\nconvex_linear_preimage _ _ (is_linear_map.is_linear_map_smul _)\n\nlemma convex_add (hA : convex A) (hB : convex B) :\n  convex ((\u03bbx : \u03b1 \u00d7 \u03b1, x.1 + x.2) '' (set.prod A B)) :=\nbegin\n  apply convex_linear_image (set.prod A B) (\u03bbx : \u03b1 \u00d7 \u03b1, x.1 + x.2) is_linear_map.is_linear_map_add,\n  exact convex_prod hA hB\nend\n\nlemma convex_sub (hA : convex A) (hB : convex B) :\n  convex ((\u03bbx : \u03b1 \u00d7 \u03b1, x.1 - x.2) '' (set.prod A B)) :=\nbegin\n  apply convex_linear_image (set.prod A B) (\u03bbx : \u03b1 \u00d7 \u03b1, x.1 - x.2) is_linear_map.is_linear_map_sub,\n  exact convex_prod hA hB\nend\n\nlemma convex_translation (z : \u03b1) (hA : convex A) : convex ((\u03bbx, z + x) '' A) :=\nbegin\n  have h : convex ((\u03bb (x : \u03b1 \u00d7 \u03b1), x.fst + x.snd) '' set.prod (insert z \u2205) A),\n    from convex_add {z} A (convex_singleton z) hA,\n  show convex ((\u03bbx, z + x) '' A),\n  { rw [@insert_prod _ _ z \u2205 A, set.empty_prod, set.union_empty, \u2190image_comp] at h,\n    simp at h,\n    exact h }\nend\n\nlemma convex_affinity (z : \u03b1) (c : \u211d) (hA : convex A) : convex ((\u03bbx, z + c \u2022 x) '' A) :=\nbegin\n  have h : convex ((\u03bb (x : \u03b1), z + x) '' ((\u03bb (z : \u03b1), c \u2022 z) '' A)),\n    from convex_translation _ z (convex_smul A c hA),\n  show convex ((\u03bbx, z + c \u2022 x) '' A),\n  { rw [\u2190image_comp] at h,\n    simp at h,\n    exact h }\nend\n\nlemma convex_Iio (r : \u211d) : convex (Iio r) :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  wlog h : x \u2264 y using [x y a b, y x b a],\n  exact le_total _ _,\n  calc\n    a * x + b * y \u2264 a * y + b * y : add_le_add_right (mul_le_mul_of_nonneg_left h ha) _\n    ...           = y             : by rw [\u2190add_mul a b y, hab, one_mul]\n    ... < r                       : hy\nend\n\nlemma convex_Iic (r : \u211d) : convex (Iic r) :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  wlog h : x \u2264 y using [x y a b, y x b a],\n  exact le_total _ _,\n  calc\n    a * x + b * y \u2264 a * y + b * y : add_le_add_right (mul_le_mul_of_nonneg_left h ha) _\n    ...           = y             : by rw [\u2190add_mul a b y, hab, one_mul]\n    ... \u2264 r                       : hy\nend\n\nlemma convex_Ioi (r : \u211d) : convex (Ioi r) :=\nbegin\n  rw [\u2190 neg_neg r],\n  rw (image_neg_Iio (-r)).symm,\n  unfold convex,\n  intros x y a b hx hy ha hb hab,\n  exact convex_linear_image _ _ is_linear_map.is_linear_map_neg (convex_Iio (-r)) _ _ _ _ hx hy ha hb hab\nend\n\nlemma convex_Ici (r : \u211d) : convex (Ici r) :=\nbegin\n  rw [\u2190 neg_neg r],\n  rw (image_neg_Iic (-r)).symm,\n  unfold convex,\n  intros x y a b hx hy ha hb hab,\n  exact convex_linear_image _ _ is_linear_map.is_linear_map_neg (convex_Iic (-r)) _ _ _ _ hx hy ha hb hab\nend\n\nlemma convex_Ioo (r : \u211d) (s : \u211d) : convex (Ioo r s) :=\nconvex_inter _ _ (convex_Ioi _) (convex_Iio _)\n\nlemma convex_Ico (r : \u211d) (s : \u211d) : convex (Ico r s) :=\nconvex_inter _ _ (convex_Ici _) (convex_Iio _)\n\nlemma convex_Ioc (r : \u211d) (s : \u211d) : convex (Ioc r s) :=\nconvex_inter _ _ (convex_Ioi _) (convex_Iic _)\n\nlemma convex_Icc (r : \u211d) (s : \u211d) : convex (Icc r s) :=\nconvex_inter _ _ (convex_Ici _) (convex_Iic _)\n\nprivate lemma convex_segment0 (b : \u03b1) : convex [0, b] :=\nbegin\n  let f := (\u03bb x : \u211d, x \u2022 b),\n  have h_image : f '' (Icc 0 1) = [0, b],\n  { apply subset.antisymm,\n    { intros z hz,\n      apply exists.elim hz,\n      intros x hx,\n      use x,\n      simp [hx.2.symm, hx.1] },\n    { intros z hz,\n      apply exists.elim hz,\n      intros x hx,\n      use x,\n      simp at hx,\n      exact and.intro hx.1 hx.2.symm } },\n  have h_lin : is_linear_map \u211d f,\n    from is_linear_map.is_linear_map_smul' _,\n  show convex [0, b],\n  { rw [\u2190h_image],\n    exact convex_linear_image _ f h_lin (convex_Icc _ _) }\nend\n\nlemma convex_segment (a b : \u03b1) : convex [a, b] :=\nbegin\n  have h: (\u03bbx, a + x) '' [0, b-a] = [a, b],\n  { convert segment_translate_image _ _ _,\n    { simp },\n    { simp only [add_sub_cancel'_right] } },\n  show convex [a, b],\n  { rw [\u2190 h],\n    apply convex_translation,\n    apply convex_segment0 }\nend\n\nlemma convex_halfspace_lt (f : \u03b1 \u2192 \u211d) (h : is_linear_map \u211d f) (r : \u211d) :\n  convex {w | f w < r} :=\nbegin\n  assume x y a b hx hy ha hb hab,\n  simp,\n  rw [is_linear_map.add \u211d f,  is_linear_map.smul f a,  is_linear_map.smul f b],\n  apply convex_Iio _ _ _ _ _ hx hy ha hb hab\nend\n\nlemma convex_halfspace_le (f : \u03b1 \u2192 \u211d) (h : is_linear_map \u211d f) (r : \u211d) :\n  convex {w | f w \u2264 r} :=\nbegin\n  assume x y a b hx hy ha hb hab,\n  simp,\n  rw [is_linear_map.add \u211d f,  is_linear_map.smul f a,  is_linear_map.smul f b],\n  apply convex_Iic _ _ _ _ _ hx hy ha hb hab\nend\n\nlemma convex_halfspace_gt (f : \u03b1 \u2192 \u211d) (h : is_linear_map \u211d f) (r : \u211d) :\n  convex {w | r < f w} :=\nbegin\n  assume x y a b hx hy ha hb hab,\n  simp,\n  rw [is_linear_map.add \u211d f,  is_linear_map.smul f a,  is_linear_map.smul f b],\n  apply convex_Ioi _ _ _ _ _ hx hy ha hb hab\nend\n\nlemma convex_halfspace_ge (f : \u03b1 \u2192 \u211d) (h : is_linear_map \u211d f) (r : \u211d) :\n  convex {w | r \u2264 f w} :=\nbegin\n  assume x y a b hx hy ha hb hab,\n  simp,\n  rw [is_linear_map.add \u211d f,  is_linear_map.smul f a,  is_linear_map.smul f b],\n  apply convex_Ici _ _ _ _ _ hx hy ha hb hab\nend\n\nlemma convex_halfplane (f : \u03b1 \u2192 \u211d) (h : is_linear_map \u211d f) (r : \u211d) :\n  convex {w | f w = r} :=\nbegin\n  assume x y a b hx hy ha hb hab,\n  simp at *,\n  rw [is_linear_map.add \u211d f,  is_linear_map.smul f a,  is_linear_map.smul f b],\n  rw [hx, hy, (add_smul a b r).symm, hab, one_smul]\nend\n\nlemma convex_halfspace_re_lt (r : \u211d) : convex {c : \u2102 | c.re < r} :=\nconvex_halfspace_lt _ (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_re_le (r : \u211d) : convex {c : \u2102 | c.re \u2264 r} :=\nconvex_halfspace_le _ (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_re_gt (r : \u211d) : convex {c : \u2102 | r < c.re } :=\nconvex_halfspace_gt _ (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_re_lge (r : \u211d) : convex {c : \u2102 | r \u2264 c.re} :=\nconvex_halfspace_ge _ (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_im_lt (r : \u211d) : convex {c : \u2102 | c.im < r} :=\nconvex_halfspace_lt _ (is_linear_map.mk complex.add_im complex.smul_im) _\n\nlemma convex_halfspace_im_le (r : \u211d) : convex {c : \u2102 | c.im \u2264 r} :=\nconvex_halfspace_le _ (is_linear_map.mk complex.add_im complex.smul_im) _\n\nlemma convex_halfspace_im_gt (r : \u211d) : convex {c : \u2102 | r < c.im } :=\nconvex_halfspace_gt _ (is_linear_map.mk complex.add_im complex.smul_im) _\n\nlemma convex_halfspace_im_lge (r : \u211d) : convex {c : \u2102 | r \u2264 c.im} :=\nconvex_halfspace_ge _ (is_linear_map.mk complex.add_im complex.smul_im) _\n\nlemma convex_sum {\u03b3 : Type*} (hA : convex A) (z : \u03b3 \u2192 \u03b1) (s : finset \u03b3) :\n  \u2200 a : \u03b3 \u2192 \u211d, s.sum a = 1 \u2192 (\u2200 i \u2208 s, 0 \u2264 a i) \u2192 (\u2200 i \u2208 s, z i \u2208 A) \u2192 s.sum (\u03bbi, a i \u2022 z i) \u2208 A :=\nbegin\n  refine finset.induction _ _ s,\n  { intros _ h_sum,\n    simp at h_sum,\n    exact false.elim h_sum },\n  { intros k s hks ih a h_sum ha hz,\n    by_cases h_cases : s.sum a = 0,\n    { have hak : a k = 1,\n        by rwa [finset.sum_insert hks, h_cases, add_zero] at h_sum,\n      have ha': \u2200 i \u2208 s, 0 \u2264 a i,\n        from \u03bb i hi, ha i (finset.mem_insert_of_mem hi),\n      have h_a0: \u2200 i \u2208 s, a i = 0,\n        from (finset.sum_eq_zero_iff_of_nonneg ha').1 h_cases,\n      have h_az0: \u2200 i \u2208 s, a i \u2022 z i = 0,\n      { intros i hi,\n        rw h_a0 i hi,\n        exact zero_smul _ (z i) },\n      show finset.sum (insert k s) (\u03bb (i : \u03b3), a i \u2022 z i) \u2208 A,\n      { rw [finset.sum_insert hks, hak, finset.sum_eq_zero h_az0],\n        simp,\n        exact hz k (finset.mem_insert_self k s) } },\n    { have h_sum_nonneg : 0 \u2264 s.sum a,\n      { apply finset.zero_le_sum',\n        intros i hi,\n        apply ha _ (finset.mem_insert_of_mem hi) },\n      have h_div_in_A: s.sum (\u03bb (i : \u03b3), ((s.sum a)\u207b\u00b9 * a i) \u2022 z i) \u2208 A,\n      { apply ih,\n        { rw finset.mul_sum.symm,\n          exact division_ring.inv_mul_cancel h_cases },\n        { intros i hi,\n          exact zero_le_mul (inv_nonneg.2 h_sum_nonneg) (ha i (finset.mem_insert_of_mem hi))},\n        { intros i hi,\n          exact hz i (finset.mem_insert_of_mem hi) } },\n      have h_sum_in_A: a k \u2022 z k\n        + finset.sum s a \u2022 finset.sum s (\u03bb (i : \u03b3), ((finset.sum s a)\u207b\u00b9 * a i) \u2022 z i) \u2208 A,\n      { apply hA,\n        exact hz k (finset.mem_insert_self k s),\n        exact h_div_in_A,\n        exact ha k (finset.mem_insert_self k s),\n        exact h_sum_nonneg,\n        rw (finset.sum_insert hks).symm,\n        exact h_sum },\n      show finset.sum (insert k s) (\u03bb (i : \u03b3), a i \u2022 z i) \u2208 A,\n      { rw finset.sum_insert hks,\n        rw finset.smul_sum at h_sum_in_A,\n        simp [smul_smul, (mul_assoc (s.sum a) _ _).symm] at h_sum_in_A,\n        conv\n        begin\n          congr,\n          congr,\n          skip,\n          congr, skip, funext,\n          rw (one_mul (a _)).symm,\n          rw (field.mul_inv_cancel h_cases).symm,\n        end,\n        exact h_sum_in_A } } }\nend\n\nlemma convex_sum_iff :\n  convex A \u2194\n    (\u2200 (s : finset \u03b1) (as : \u03b1 \u2192 \u211d),\n      s.sum as = 1 \u2192 (\u2200 i \u2208 s, 0 \u2264 as i) \u2192 (\u2200 x \u2208 s, x \u2208 A) \u2192 s.sum (\u03bbx, as x \u2022 x) \u2208 A ) :=\nbegin\n  apply iff.intro,\n  { intros hA s as h_sum has hs,\n    exact convex_sum A hA id s _ h_sum has hs },\n  { intros h,\n    intros x y a b hx hy ha hb hab,\n    by_cases h_cases: x = y,\n    { rw [h_cases, \u2190add_smul, hab, one_smul], exact hy },\n    { let s := insert x (finset.singleton y),\n      have h_sum_eq_add : finset.sum s (\u03bb z, ite (x = z) a b \u2022 z) = a \u2022 x + b \u2022 y,\n      { rw [finset.sum_insert (finset.not_mem_singleton.2 h_cases),\n        finset.sum_singleton],\n        simp [h_cases] },\n      rw h_sum_eq_add.symm,\n      apply h s,\n      { rw [finset.sum_insert (finset.not_mem_singleton.2 h_cases),\n        finset.sum_singleton],\n        simp [h_cases],\n        exact hab },\n      { intros k hk,\n        by_cases h_cases : x = k,\n        { simp [h_cases], exact ha },\n        { simp [h_cases], exact hb } },\n      { intros z hz,\n        apply or.elim (finset.mem_insert.1 hz),\n        { intros h_eq, rw h_eq, exact hx },\n        { intros h_eq, rw finset.mem_singleton at h_eq, rw h_eq, exact hy } } } }\nend\n\nvariables (D: set \u03b1) (D': set \u03b1) (f : \u03b1 \u2192 \u211d) (g : \u03b1 \u2192 \u211d)\n\n/-- Convexity of functions -/\ndef convex_on (f : \u03b1 \u2192 \u211d) : Prop :=\n  convex D \u2227\n  \u2200 (x y : \u03b1) (a b : \u211d), x \u2208 D \u2192 y \u2208 D \u2192 0 \u2264 a \u2192 0 \u2264 b \u2192 a + b = 1 \u2192\n    f (a \u2022 x + b \u2022 y) \u2264 a * f x + b * f y\n\nlemma convex_on_iff :\n  convex_on D f \u2194 convex D \u2227 \u2200 {x y : \u03b1} {\u03b8 : \u211d},\n    x \u2208 D \u2192 y \u2208 D \u2192 0 \u2264 \u03b8 \u2192 \u03b8 \u2264 1 \u2192 f (\u03b8 \u2022 x + (1 - \u03b8) \u2022 y) \u2264 \u03b8 * f x + (1 - \u03b8) * f y :=\n\u27e8begin\n  intro h,\n  apply and.intro h.1,\n  intros x y \u03b8 hx hy h\u03b8\u2081 h\u03b8\u2082,\n  have h\u03b8\u2082: 0 \u2264 1 - \u03b8, by linarith,\n  exact (h.2 _ _ _ _ hx hy h\u03b8\u2081 h\u03b8\u2082 (by linarith))\nend,\nbegin\n  intro h,\n  apply and.intro h.1,\n  assume x y a b hx hy ha hb hab,\n  have ha': a \u2264 1, by linarith,\n  have hb': b = 1 - a, by linarith,\n  rw hb',\n  exact (h.2 hx hy ha ha')\nend\u27e9\n\nlemma convex_on_iff_div:\n  convex_on D f \u2194 convex D \u2227 \u2200 {x y : \u03b1} {a : \u211d} {b : \u211d},\n    x \u2208 D \u2192 y \u2208 D \u2192 0 \u2264 a \u2192 0 \u2264 b \u2192 0 < a + b \u2192\n    f ((a/(a+b)) \u2022 x + (b/(a+b)) \u2022 y) \u2264 (a/(a+b)) * f x + (b/(a+b)) * f y :=\n\u27e8begin\n  intro h,\n  apply and.intro h.1,\n  intros x y a b hx hy ha hb hab,\n  apply h.2 _ _ _ _ hx hy,\n  have ha', from mul_le_mul_of_nonneg_left ha (le_of_lt (inv_pos hab)),\n  rwa [mul_zero, \u2190div_eq_inv_mul] at ha',\n  have hb', from mul_le_mul_of_nonneg_left hb (le_of_lt (inv_pos hab)),\n  rwa [mul_zero, \u2190div_eq_inv_mul] at hb',\n  rw [\u2190add_div],\n  exact div_self (ne_of_lt hab).symm\nend,\nbegin\n  intro h,\n  apply and.intro h.1,\n  intros x y a b hx hy ha hb hab,\n  have h', from h.2 hx hy ha hb,\n  rw [hab, div_one, div_one] at h',\n  exact h' zero_lt_one\nend\u27e9\n\nlemma convex_on_sum {\u03b3 : Type} (s : finset \u03b3) (z : \u03b3 \u2192 \u03b1) (hs : s \u2260 \u2205) :\n  \u2200 (a : \u03b3 \u2192 \u211d), convex_on D f \u2192 (\u2200 i \u2208 s, 0 \u2264 a i) \u2192 (\u2200 i \u2208 s, z i \u2208 D) \u2192 s.sum a = 1 \u2192\n  f (s.sum (\u03bbi, a i \u2022 z i)) \u2264 s.sum (\u03bbi, a i \u2022 f (z i)) :=\nbegin\n  refine finset.induction (by simp) _ s,\n  intros k s hks ih a hf ha hz h_sum,\n  by_cases h_cases : s.sum a = 0,\n  { have hak : a k = 1,\n      by rwa [finset.sum_insert hks, h_cases, add_zero] at h_sum,\n    have ha': \u2200 i \u2208 s, 0 \u2264 a i,\n      from \u03bb i hi, ha i (finset.mem_insert_of_mem hi),\n    have h_a0: \u2200 i \u2208 s, a i = 0,\n      from (finset.sum_eq_zero_iff_of_nonneg ha').1 h_cases,\n    have h_az0: \u2200 i \u2208 s, a i \u2022 z i = 0,\n    { intros i hi,\n      rw h_a0 i hi,\n      exact zero_smul _ _ },\n    have h_afz0: \u2200 i \u2208 s, a i \u2022 f (z i) = 0,\n    { intros i hi,\n      rw h_a0 i hi,\n      exact zero_smul _ _ },\n    show f (finset.sum (insert k s) (\u03bbi, a i \u2022 z i)) \u2264 finset.sum (insert k s) (\u03bbi, a i \u2022 f (z i)),\n    { rw [finset.sum_insert hks, hak, finset.sum_eq_zero h_az0],\n      rw [finset.sum_insert hks, hak, finset.sum_eq_zero h_afz0],\n      simp } },\n  { have h_sum_nonneg : 0 \u2264 s.sum a ,\n    { apply finset.zero_le_sum',\n      intros i hi,\n      apply ha _ (finset.mem_insert_of_mem hi) },\n    have ih_div: f (s.sum (\u03bb (i : \u03b3), ((s.sum a)\u207b\u00b9 * a i) \u2022 z i))\n                  \u2264 s.sum (\u03bb (i : \u03b3), ((s.sum a)\u207b\u00b9 * a i) \u2022 f (z i)),\n    { apply ih _ hf,\n      { intros i hi,\n        exact zero_le_mul (inv_nonneg.2 h_sum_nonneg) (ha i (finset.mem_insert_of_mem hi))},\n      { intros i hi,\n        exact hz i (finset.mem_insert_of_mem hi) },\n      { rw finset.mul_sum.symm,\n        exact division_ring.inv_mul_cancel h_cases } },\n    have h_div_in_D: s.sum (\u03bb (i : \u03b3), ((s.sum a)\u207b\u00b9 * a i) \u2022 z i) \u2208 D,\n    { apply convex_sum _ hf.1,\n      { rw finset.mul_sum.symm,\n        exact division_ring.inv_mul_cancel h_cases },\n      { intros i hi,\n        exact zero_le_mul (inv_nonneg.2 h_sum_nonneg) (ha i (finset.mem_insert_of_mem hi))},\n      { intros i hi,\n        exact hz i (finset.mem_insert_of_mem hi) } },\n    have hf': f (a k \u2022 z k     + s.sum a \u2022    s.sum (\u03bb (i : \u03b3), ((finset.sum s a)\u207b\u00b9 * a i) \u2022 z i))\n               \u2264 a k \u2022 f (z k) + s.sum a \u2022 f (s.sum (\u03bb (i : \u03b3), ((finset.sum s a)\u207b\u00b9 * a i) \u2022 z i)),\n    { apply hf.2,\n      exact hz k (finset.mem_insert_self k s),\n      exact h_div_in_D,\n      exact ha k (finset.mem_insert_self k s),\n      exact h_sum_nonneg,\n      rw (finset.sum_insert hks).symm,\n      exact h_sum },\n    have ih_div': f (a k \u2022 z k     + s.sum a \u2022 s.sum (\u03bb (i : \u03b3), ((finset.sum s a)\u207b\u00b9 * a i) \u2022 z i))\n                   \u2264 a k \u2022 f (z k) + s.sum a \u2022 s.sum (\u03bb (i : \u03b3), ((finset.sum s a)\u207b\u00b9 * a i) \u2022 f (z i)),\n      from trans hf' (add_le_add_left (mul_le_mul_of_nonneg_left ih_div h_sum_nonneg) _),\n    show f (finset.sum (insert k s) (\u03bb (i : \u03b3), a i \u2022 z i))\n          \u2264 finset.sum (insert k s) (\u03bb (i : \u03b3), a i \u2022 f (z i)),\n    { simp [finset.sum_insert hks],\n      simp [finset.smul_sum] at ih_div',\n      simp [smul_smul, (mul_assoc (s.sum a) _ _).symm] at ih_div',\n      convert ih_div',\n      repeat { apply funext,\n        intro i,\n        rw [field.mul_inv_cancel, one_mul],\n        exact h_cases } } }\nend\n\nlemma convex_on_linorder [h\u03b1 : linear_order \u03b1] (f : \u03b1 \u2192 \u211d) : convex_on D f \u2194\n  convex D \u2227 \u2200 (x y : \u03b1) (a b : \u211d), x \u2208 D \u2192 y \u2208 D \u2192 x < y \u2192 a \u2265 0 \u2192 b \u2265 0 \u2192 a + b = 1 \u2192\n    f (a \u2022 x + b \u2022 y) \u2264 a * f x + b * f y :=\nbegin\n  apply iff.intro,\n  { intro h,\n    apply and.intro h.1,\n    intros x y a b hx hy hxy ha hb hab,\n    exact h.2 x y a b hx hy ha hb hab },\n  { intro h,\n    apply and.intro h.1,\n    intros x y a b hx hy ha hb hab,\n    wlog hxy : x<=y using [x y a b, y x b a],\n    exact le_total _ _,\n    apply or.elim (lt_or_eq_of_le hxy),\n    { intros hxy, exact h.2 x y a b hx hy hxy ha hb hab },\n    { intros hxy, rw [hxy,\u2190add_smul, hab, one_smul,\u2190add_mul,hab,one_mul] } }\nend\n\nlemma convex_on_subset (h_convex_on : convex_on D f) (h_subset : A \u2286 D) (h_convex : convex A) :\n  convex_on A f :=\nbegin\n  apply and.intro h_convex,\n  intros x y a b hx hy,\n  exact h_convex_on.2 x y a b (h_subset hx) (h_subset hy),\nend\n\nlemma convex_on_add (hf : convex_on D f) (hg : convex_on D g) : convex_on D (\u03bbx, f x + g x) :=\nbegin\n  apply and.intro hf.1,\n  intros x y a b hx hy ha hb hab,\n  calc\n    f (a \u2022 x + b \u2022 y) + g (a \u2022 x + b \u2022 y) \u2264 (a * f x + b * f y) + (a * g x + b * g y)\n      : add_le_add (hf.2 x y a b hx hy ha hb hab) (hg.2 x y a b hx hy ha hb hab)\n    ... = a * f x + a * g x + b * f y + b * g y : by linarith\n    ... = a * (f x + g x) + b * (f y + g y) : by simp [mul_add]\nend\n\nlemma convex_on_smul (c : \u211d) (hc : 0 \u2264 c) (hf : convex_on D f) : convex_on D (\u03bbx, c * f x) :=\nbegin\n  apply and.intro hf.1,\n  intros x y a b hx hy ha hb hab,\n  calc\n    c * f (a \u2022 x + b \u2022 y) \u2264 c * (a * f x + b * f y)\n      : mul_le_mul_of_nonneg_left (hf.2 x y a b hx hy ha hb hab) hc\n    ... = a * (c * f x) + b * (c * f y) : by rw mul_add; ac_refl\nend\n\nlemma convex_le_of_convex_on (hf : convex_on D f) (r : \u211d) : convex {x \u2208 D | f x \u2264 r} :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  simp at *,\n  apply and.intro,\n  { exact hf.1 x y a b hx.1 hy.1 ha hb hab },\n  { apply le_trans (hf.2 x y a b hx.1 hy.1 ha hb hab),\n    wlog h_wlog : f x \u2264 f y using [x y a b, y x b a],\n    apply le_total,\n    calc\n      a * f x + b * f y \u2264 a * f y + b * f y :\n        add_le_add (mul_le_mul_of_nonneg_left h_wlog ha) (le_refl _)\n      ... = (a + b) * f y : (add_mul _ _ _).symm\n      ... \u2264 r             : by rw [hab, one_mul]; exact hy.2 }\nend\n\nlemma convex_lt_of_convex_on (hf : convex_on D f) (r : \u211d) : convex {x \u2208 D | f x < r} :=\nbegin\n  intros x y a b hx hy ha hb hab,\n  simp at *,\n  apply and.intro,\n  { exact hf.1 x y a b hx.1 hy.1 ha hb hab },\n  { apply lt_of_le_of_lt (hf.2 x y a b hx.1 hy.1 ha hb hab),\n    wlog h_wlog : f x \u2264 f y using [x y a b, y x b a],\n    apply le_total,\n    calc\n      a * f x + b * f y \u2264 a * f y + b * f y :\n        add_le_add (mul_le_mul_of_nonneg_left h_wlog ha) (le_refl _)\n      ... = (a + b) * f y     : (add_mul _ _ _).symm\n      ... < r                 : by rw [hab, one_mul]; exact hy.2 }\nend\n\nlemma le_on_interval_of_convex_on (x y : \u03b1) (a b : \u211d)\n  (hf : convex_on D f) (hx : x \u2208 D) (hy : y \u2208 D) (ha : 0 \u2264 a) (hb : 0 \u2264 b) (hab : a + b = 1) :\n  f (a \u2022 x + b \u2022 y) \u2264 max (f x) (f y) :=\ncalc\n  f (a \u2022 x + b \u2022 y) \u2264 a * f x + b * f y : hf.2 x y a b hx hy ha hb hab\n  ... \u2264 a * max (f x) (f y) + b * max (f x) (f y) :\n    add_le_add (mul_le_mul_of_nonneg_left (le_max_left _ _) ha) (mul_le_mul_of_nonneg_left (le_max_right _ _) hb)\n  ... \u2264 max (f x) (f y) : by rw [\u2190add_mul, hab, one_mul]\n\n/- This instance is necessary to guide class instance search in the lemma below. -/\nnoncomputable instance real_normed_space.to_has_scalar (\u03b1 : Type) [normed_space \u211d \u03b1] : has_scalar \u211d \u03b1 :=\nmul_action.to_has_scalar \u211d \u03b1\n\nlemma convex_on_dist {\u03b1 : Type} [normed_space \u211d \u03b1] (z : \u03b1) (D : set \u03b1) (hD : convex D) :\n  convex_on D (\u03bbz', dist z' z) :=\nbegin\n  apply and.intro hD,\n  intros x y a b hx hy ha hb hab,\n  calc\n    dist (a \u2022 x + b \u2022 y) z = \u2225 (a \u2022 x + b \u2022 y) - (a + b) \u2022 z \u2225 :\n      by rw [hab, one_smul, normed_group.dist_eq]\n    ... = \u2225a \u2022 (x - z) + b \u2022 (y - z)\u2225 :\n      by rw [add_smul, smul_sub, smul_sub]; simp\n    ... \u2264 \u2225a \u2022 (x - z)\u2225 + \u2225b \u2022 (y - z)\u2225 :\n      norm_triangle (a \u2022 (x - z)) (b \u2022 (y - z))\n    ... = a * dist x z + b * dist y z :\n      by simp [norm_smul, normed_group.dist_eq, real.norm_eq_abs, abs_of_nonneg ha, abs_of_nonneg hb]\nend\n\nlemma convex_ball {\u03b1 : Type} [normed_space \u211d \u03b1] (a : \u03b1) (r : \u211d) : convex (metric.ball a r) :=\nby simpa using convex_lt_of_convex_on univ (\u03bbb, dist b a) (convex_on_dist _  _ convex_univ) r\n\nlemma convex_closed_ball {\u03b1 : Type} [normed_space \u211d \u03b1] (a : \u03b1) (r : \u211d) : convex (metric.closed_ball a r) :=\nby simpa using convex_le_of_convex_on univ (\u03bbb, dist b a) (convex_on_dist _  _ convex_univ) r\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/analysis/convex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7349920763347763}}
{"text": "/-\nCopyright (c) 2022 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n\n! This file was ported from Lean 3 source module number_theory.cyclotomic.gal\n! leanprover-community/mathlib commit 861a26926586cd46ff80264d121cdb6fa0e35cc1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.NumberTheory.Cyclotomic.PrimitiveRoots\nimport Mathbin.FieldTheory.PolynomialGaloisGroup\n\n/-!\n# Galois group of cyclotomic extensions\n\nIn this file, we show the relationship between the Galois group of `K(\u03b6\u2099)` and `(zmod n)\u02e3`;\nit is always a subgroup, and if the `n`th cyclotomic polynomial is irreducible, they are isomorphic.\n\n## Main results\n\n* `is_primitive_root.aut_to_pow_injective`: `is_primitive_root.aut_to_pow` is injective\n  in the case that it's considered over a cyclotomic field extension.\n* `is_cyclotomic_extension.aut_equiv_pow`: If the `n`th cyclotomic polynomial is irreducible in `K`,\n  then `is_primitive_root.aut_to_pow` is a `mul_equiv` (for example, in `\u211a` and certain `\ud835\udd3d\u209a`).\n* `gal_X_pow_equiv_units_zmod`, `gal_cyclotomic_equiv_units_zmod`: Repackage\n  `is_cyclotomic_extension.aut_equiv_pow` in terms of `polynomial.gal`.\n* `is_cyclotomic_extension.aut.comm_group`: Cyclotomic extensions are abelian.\n\n## References\n\n* https://kconrad.math.uconn.edu/blurbs/galoistheory/cyclotomic.pdf\n\n## TODO\n\n* We currently can get away with the fact that the power of a primitive root is a primitive root,\n  but the correct long-term solution for computing other explicit Galois groups is creating\n  `power_basis.map_conjugate`; but figuring out the exact correct assumptions + proof for this is\n  mathematically nontrivial. (Current thoughts: the correct condition is that the annihilating\n  ideal of both elements is equal. This may not hold in an ID, and definitely holds in an ICD.)\n\n-/\n\n\nvariable {n : \u2115+} (K : Type _) [Field K] {L : Type _} {\u03bc : L}\n\nopen Polynomial IsCyclotomicExtension\n\nopen Cyclotomic\n\nnamespace IsPrimitiveRoot\n\nvariable [CommRing L] [IsDomain L] (h\u03bc : IsPrimitiveRoot \u03bc n) [Algebra K L]\n  [IsCyclotomicExtension {n} K L]\n\n/- ./././Mathport/Syntax/Translate/Tactic/Lean3.lean:132:4: warning: unsupported: rw with cfg: { occs := occurrences.pos[occurrences.pos] \u00abexpr[ ,]\u00bb([2]) } -/\n/-- `is_primitive_root.aut_to_pow` is injective in the case that it's considered over a cyclotomic\nfield extension. -/\ntheorem autToPow_injective : Function.Injective <| h\u03bc.autToPow K :=\n  by\n  intro f g hfg\n  apply_fun Units.val  at hfg\n  simp only [IsPrimitiveRoot.coe_autToPow_apply, [anonymous]] at hfg\n  generalize_proofs hf' hg'  at hfg\n  have hf := hf'.some_spec\n  have hg := hg'.some_spec\n  generalize_proofs h\u03b6  at hf hg\n  suffices f h\u03bc.to_roots_of_unity = g h\u03bc.to_roots_of_unity\n    by\n    apply AlgEquiv.coe_algHom_injective\n    apply (h\u03bc.power_basis K).algHom_ext\n    exact this\n  rw [ZMod.eq_iff_modEq_nat] at hfg\n  refine' (hf.trans _).trans hg.symm\n  rw [\u2190 rootsOfUnity.coe_pow _ hf'.some, \u2190 rootsOfUnity.coe_pow _ hg'.some]\n  congr 1\n  rw [pow_eq_pow_iff_modEq]\n  convert hfg\n  rw [h\u03bc.eq_order_of]\n  rw [\u2190 h\u03bc.coe_to_roots_of_unity_coe]\n  rw [orderOf_units, orderOf_subgroup]\n#align is_primitive_root.aut_to_pow_injective IsPrimitiveRoot.autToPow_injective\n\nend IsPrimitiveRoot\n\nnamespace IsCyclotomicExtension\n\nvariable [CommRing L] [IsDomain L] (h\u03bc : IsPrimitiveRoot \u03bc n) [Algebra K L]\n  [IsCyclotomicExtension {n} K L]\n\n/-- Cyclotomic extensions are abelian. -/\nnoncomputable def Aut.commGroup : CommGroup (L \u2243\u2090[K] L) :=\n  ((zeta_spec n K L).autToPow_injective K).CommGroup _ (map_one _) (map_mul _) (map_inv _)\n    (map_div _) (map_pow _) (map_zpow _)\n#align is_cyclotomic_extension.aut.comm_group IsCyclotomicExtension.Aut.commGroup\n\nvariable (h : Irreducible (cyclotomic n K)) {K} (L)\n\ninclude h\n\n/- ./././Mathport/Syntax/Translate/Tactic/Lean3.lean:132:4: warning: unsupported: rw with cfg: { occs := occurrences.pos[occurrences.pos] \u00abexpr[ ,]\u00bb([1, 5]) } -/\n/-- The `mul_equiv` that takes an automorphism `f` to the element `k : (zmod n)\u02e3` such that\n  `f \u03bc = \u03bc ^ k` for any root of unity `\u03bc`. A  strengthening of `is_primitive_root.aut_to_pow`. -/\n@[simps]\nnoncomputable def autEquivPow : (L \u2243\u2090[K] L) \u2243* (ZMod n)\u02e3 :=\n  let h\u03b6 := zeta_spec n K L\n  let h\u03bc t := h\u03b6.pow_of_coprime _ (ZMod.val_coe_unit_coprime t)\n  {\n    (zeta_spec n K L).autToPow\n      K with\n    invFun := fun t =>\n      (h\u03b6.PowerBasis K).equivOfMinpoly ((h\u03bc t).PowerBasis K)\n        (by\n          haveI := IsCyclotomicExtension.ne_zero' n K L\n          simp only [IsPrimitiveRoot.powerBasis_gen]\n          have hr :=\n            IsPrimitiveRoot.minpoly_eq_cyclotomic_of_irreducible\n              ((zeta_spec n K L).pow_of_coprime _ (ZMod.val_coe_unit_coprime t)) h\n          exact ((zeta_spec n K L).minpoly_eq_cyclotomic_of_irreducible h).symm.trans hr)\n    left_inv := fun f => by\n      simp only [MonoidHom.toFun_eq_coe]\n      apply AlgEquiv.coe_algHom_injective\n      apply (h\u03b6.power_basis K).algHom_ext\n      simp only [AlgEquiv.coe_algHom, AlgEquiv.map_pow]\n      rw [PowerBasis.equivOfMinpoly_gen]\n      simp only [IsPrimitiveRoot.powerBasis_gen, IsPrimitiveRoot.autToPow_spec]\n    right_inv := fun x => by\n      simp only [MonoidHom.toFun_eq_coe]\n      generalize_proofs _ h\n      have key := h\u03b6.aut_to_pow_spec K ((h\u03b6.power_basis K).equivOfMinpoly ((h\u03bc x).PowerBasis K) h)\n      have := (h\u03b6.power_basis K).equivOfMinpoly_gen ((h\u03bc x).PowerBasis K) h\n      rw [h\u03b6.power_basis_gen K] at this\n      rw [this, IsPrimitiveRoot.powerBasis_gen] at key\n      rw [\u2190 h\u03b6.coe_to_roots_of_unity_coe] at key\n      simp only [\u2190 coe_coe, \u2190 rootsOfUnity.coe_pow] at key\n      replace key := rootsOfUnity.coe_injective key\n      rw [pow_eq_pow_iff_modEq, \u2190 orderOf_subgroup, \u2190 orderOf_units, h\u03b6.coe_to_roots_of_unity_coe, \u2190\n        (zeta_spec n K L).eq_orderOf, \u2190 ZMod.eq_iff_modEq_nat] at key\n      simp only [ZMod.nat_cast_val, ZMod.cast_id', id.def] at key\n      exact Units.ext key }\n#align is_cyclotomic_extension.aut_equiv_pow IsCyclotomicExtension.autEquivPow\n\ninclude h\u03bc\n\nvariable {L}\n\n/-- Maps `\u03bc` to the `alg_equiv` that sends `is_cyclotomic_extension.zeta` to `\u03bc`. -/\nnoncomputable def fromZetaAut : L \u2243\u2090[K] L :=\n  let h\u03b6 := (zeta_spec n K L).eq_pow_of_pow_eq_one h\u03bc.pow_eq_one n.Pos\n  (autEquivPow L h).symm <|\n    ZMod.unitOfCoprime h\u03b6.some <|\n      ((zeta_spec n K L).pow_iff_coprime n.Pos h\u03b6.some).mp <| h\u03b6.choose_spec.choose_spec.symm \u25b8 h\u03bc\n#align is_cyclotomic_extension.from_zeta_aut IsCyclotomicExtension.fromZetaAut\n\n/- ./././Mathport/Syntax/Translate/Tactic/Lean3.lean:132:4: warning: unsupported: rw with cfg: { occs := occurrences.pos[occurrences.pos] \u00abexpr[ ,]\u00bb([4]) } -/\ntheorem fromZetaAut_spec : fromZetaAut h\u03bc h (zeta n K L) = \u03bc :=\n  by\n  simp_rw [from_zeta_aut, aut_equiv_pow_symm_apply]\n  generalize_proofs h\u03b6 h _ h\u03bc _\n  rw [\u2190 h\u03b6.power_basis_gen K]\n  rw [PowerBasis.equivOfMinpoly_gen, h\u03bc.power_basis_gen K]\n  convert h.some_spec.some_spec\n  exact ZMod.val_cast_of_lt h.some_spec.some\n#align is_cyclotomic_extension.from_zeta_aut_spec IsCyclotomicExtension.fromZetaAut_spec\n\nend IsCyclotomicExtension\n\nsection Gal\n\nvariable [Field L] (h\u03bc : IsPrimitiveRoot \u03bc n) [Algebra K L] [IsCyclotomicExtension {n} K L]\n  (h : Irreducible (cyclotomic n K)) {K}\n\n/-- `is_cyclotomic_extension.aut_equiv_pow` repackaged in terms of `gal`.\nAsserts that the Galois group of `cyclotomic n K` is equivalent to `(zmod n)\u02e3`\nif `cyclotomic n K` is irreducible in the base field. -/\nnoncomputable def galCyclotomicEquivUnitsZmod : (cyclotomic n K).Gal \u2243* (ZMod n)\u02e3 :=\n  (AlgEquiv.autCongr (IsSplittingField.algEquiv _ _)).symm.trans\n    (IsCyclotomicExtension.autEquivPow L h)\n#align gal_cyclotomic_equiv_units_zmod galCyclotomicEquivUnitsZmod\n\n/-- `is_cyclotomic_extension.aut_equiv_pow` repackaged in terms of `gal`.\nAsserts that the Galois group of `X ^ n - 1` is equivalent to `(zmod n)\u02e3`\nif `cyclotomic n K` is irreducible in the base field. -/\nnoncomputable def galXPowEquivUnitsZmod : (X ^ (n : \u2115) - 1).Gal \u2243* (ZMod n)\u02e3 :=\n  (AlgEquiv.autCongr (IsSplittingField.algEquiv _ _)).symm.trans\n    (IsCyclotomicExtension.autEquivPow L h)\n#align gal_X_pow_equiv_units_zmod galXPowEquivUnitsZmod\n\nend Gal\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/Cyclotomic/Gal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7349920754617335}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# A harder question about lattices\n\nI learnt this fact when preparing sheet 2.\n\nWith sets we have `A \u222a (B \u2229 C) = (A \u222a B) \u2229 (A \u222a C)`, and `A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C)`.\nIn sheet 2 we saw an explicit example (the lattice of subspaces of a 2-d vector space)\nof a lattice where neither `A \u2293 (B \u2294 C) = (A \u2294 B) \u2293 (A \u2294 C)` nor `A \u2293 (B \u2294 C) = (A \u2293 B) \u2294 (A \u2293 C)`\nheld. But it turns out that in a general lattice, one equality holds if and only if the\nother one does! This was quite surprising to me.\n\nThe challenge is to prove it in Lean. My strategy would be to prove it on paper first\nand then formalise the proof. If you're not in to puzzles like this, then feel free to skip\nthis question. \n\n-/\n\n-- This is a really unhelpful proof; the argument below is \"a lattice satisfying one of\n-- the distributivity laws is called a `distrib_lattice` in Lean and it's a theorem\n-- in Lean called `inf_sup_left` that a `distrib_lattice` satisfies the other law,\n-- so just apply that\". There is a purely low-level proof though, which you can see by\n-- just looking at mathlib's proof of `inf_sup_left`, and which I will write\n-- down here if I find the time :-/ I'd rather concentrate on getting some groups and\n-- vector spaces into the course repo though, because the first project deadline is imminent.\nexample (L : Type) [lattice L] : \n  (\u2200 a b c : L, a \u2294 (b \u2293 c) = (a \u2294 b) \u2293 (a \u2294 c)) \u2194 (\u2200 a b c : L, a \u2293 (b \u2294 c) = (a \u2293 b) \u2294 (a \u2293 c)) :=\nbegin\n  split,\n  { intro h,\n    -- make a distrib_lattice from `h`\n    letI : distrib_lattice L := {le_sup_inf := \u03bb x y z, by rw \u2190 h; refl , .._inst_1 },\n    intros,\n    -- use `inf_sup_left`, proved in Lean. Look at the proof to see where the actual\n    -- content is.\n    exact inf_sup_left, },\n  { -- other way is the same but using the dual partial order (so `a \u2264 b` is defined to be `b \u2264 a`!)\n    intro h,\n    letI foo : lattice L\u1d52\u1d48 := infer_instance,\n    -- now need to change all infs to sups and vice versa\n    change \u2200 (a b c : L\u1d52\u1d48), a \u2294 (b \u2293 c) = (a \u2294 b) \u2293 (a \u2294 c) at h,\n    change \u2200 (a b c : L\u1d52\u1d48), a \u2293 (b \u2294 c) = (a \u2293 b) \u2294 (a \u2293 c),\n    -- now same proof as before\n    letI : distrib_lattice L\u1d52\u1d48 := {le_sup_inf := \u03bb x y z, by rw \u2190 h; refl , ..foo },\n    intros,\n    exact inf_sup_left, },\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section06orderings_and_lattices/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476784277755, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7349920700941212}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.invertible\nimport algebra.field\nimport algebra.char_p.basic\n\n/-!\n# Invertibility of elements given a characteristic\n\nThis file includes some instances of `invertible` for specific numbers in\ncharacteristic zero. Some more cases are given as a `def`, to be included only\nwhen needed. To construct instances for concrete numbers,\n`invertible_of_nonzero` is a useful definition.\n-/\n\nvariables {K : Type*}\n\nsection field\nvariables [field K]\n\n/-- A natural number `t` is invertible in a field `K` if the charactistic of `K` does not divide\n`t`. -/\ndef invertible_of_ring_char_not_dvd\n  {t : \u2115} (not_dvd : \u00ac(ring_char K \u2223 t)) : invertible (t : K) :=\ninvertible_of_nonzero (\u03bb h, not_dvd ((ring_char.spec K t).mp h))\n\nlemma not_ring_char_dvd_of_invertible {t : \u2115} [invertible (t : K)] :\n  \u00ac(ring_char K \u2223 t) :=\nbegin\n  rw [\u2190 ring_char.spec, \u2190 ne.def],\n  exact nonzero_of_invertible (t : K)\nend\n\n/-- A natural number `t` is invertible in a field `K` of charactistic `p` if `p` does not divide\n`t`. -/\ndef invertible_of_char_p_not_dvd {p : \u2115} [char_p K p]\n  {t : \u2115} (not_dvd : \u00ac(p \u2223 t)) : invertible (t : K) :=\ninvertible_of_nonzero (\u03bb h, not_dvd ((char_p.cast_eq_zero_iff K p t).mp h))\n\ninstance invertible_of_pos [char_zero K] (n : \u2115) [h : fact (0 < n)] :\n  invertible (n : K) :=\ninvertible_of_nonzero $ by simpa [pos_iff_ne_zero] using h.out\n\nend field\n\nsection division_ring\nvariables [division_ring K] [char_zero K]\n\ninstance invertible_succ (n : \u2115) : invertible (n.succ : K) :=\ninvertible_of_nonzero (nat.cast_ne_zero.mpr (nat.succ_ne_zero _))\n\n/-!\nA few `invertible n` instances for small numerals `n`. Feel free to add your own\nnumber when you need its inverse.\n-/\n\ninstance invertible_two : invertible (2 : K) :=\ninvertible_of_nonzero (by exact_mod_cast (dec_trivial : 2 \u2260 0))\n\ninstance invertible_three : invertible (3 : K) :=\ninvertible_of_nonzero (by exact_mod_cast (dec_trivial : 3 \u2260 0))\n\nend division_ring\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/char_p/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8774767746654976, "lm_q1q2_score": 0.7349920567074293}}
{"text": "/- Spatial Reasoning Problem 02 -/\n/- It can be found at: SpatialQs.txt -/\n\n/- (2) If x is on the right of y, and z is on the left of y, then x is on the right of z -/\n\nconstant U : Type\n\nconstants X Y Z : U\nconstants Right Left : U\nconstant ins : U \u2192 U \u2192 Prop\nconstant located : U \u2192 U \u2192 Prop\nconstant subclass : U \u2192 U \u2192 Prop\nconstant orientation: U \u2192 U \u2192 U \u2192 Prop\n\n/- axioms from SUMO -/\naxiom a3 : \u2200 OBJ1 OBJ2,\n    (orientation OBJ1 OBJ2 Right) \u2194 (orientation OBJ2 OBJ1 Left)\n\n/- axioms from problem -/\naxiom a1 : orientation X Y Right            -- (orientation X Y Right)\naxiom a2 : orientation Z Y Left             -- (orientation Z Y Left)\n\n/- axioms to be added -/\naxiom a4 : \u2200 X Y Z, (orientation X Y Right) \u2227 (orientation Z Y Left)\n    \u2192 (orientation X Z Right)\n\ntheorem x_is_on_the_right_of_z: orientation X Z Right :=\n    by exact (a4 _ _ _) \u27e8a1, a2\u27e9\n", "meta": {"author": "own-pt", "repo": "common-sense-lean", "sha": "f672210aecb4172f5bae265e43e6867397e13b1c", "save_path": "github-repos/lean/own-pt-common-sense-lean", "path": "github-repos/lean/own-pt-common-sense-lean/common-sense-lean-f672210aecb4172f5bae265e43e6867397e13b1c/spatial-reasoning/spatial-reasoning-problem-02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.734962144375328}}
{"text": "import data.set\nimport data.list\nopen set\nopen classical\n\nvariable U : Type\nvariables A B C D : set U\n\n-- 1.\nexample : A \u222a (B \u2229 C) = (A \u222a B) \u2229 (A \u222a C) :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        split,\n        cases h,\n            left, assumption,\n            right, exact h.1,\n        cases h,\n            left, assumption,\n            right, exact h.2,\n        \n        assume h,\n        have xinAB : x \u2208 (A \u222a B) := h.1,\n        have xinAC : x \u2208 (A \u222a C) := h.2,\n        cases xinAB with xinA xinB,\n            left, assumption,\n            cases xinAC with xinA xinC,\n                left, assumption,\n                right, exact \u27e8xinB, xinC\u27e9\nend\n\n-- 2.\nexample : -(A \\ B) = -A \u222a B :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        cases em (x \u2208 B) with xinB xnotinB,\n            right, assumption,\n\n            left,\n            assume xinA,\n            have : x \u2208 A \\ B := \u27e8xinA, xnotinB\u27e9,\n            contradiction,\n\n        assume h,\n        assume xinAnotB,\n        cases h,\n            have : x \u2208 A := xinAnotB.1,\n            contradiction,\n\n            have : x \u2209 B := xinAnotB.2,\n            contradiction\nend\n\n-- Question 3 see set_exer2.lean\n\n-- 4.\nexample : (A \\ B) \u222a (B \\ A) = (A \u222a B) \\ (A \u2229 B) :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        split,\n            cases h,\n                left, exact h.1,\n                right, exact h.1,\n            \n            assume xinAandB,\n            cases h,\n                exact h.2 xinAandB.2,\n                exact h.2 xinAandB.1,\n        \n        assume h,\n        have : \u00ac x \u2208 (A \u2229 B) := h.2,\n        cases h.1 with xinA xinB,\n            left,\n            split,\n                assumption,\n                assume xinB,\n                have : x \u2208 (A \u2229 B) := \u27e8xinA, xinB\u27e9,\n                contradiction,\n\n            right,\n            split, \n                assumption,\n                assume xinA,\n                have : x \u2208 (A \u2229 B) := \u27e8xinA, xinB\u27e9,\n                contradiction,\nend\n\n-- 5. Part I\nexample : A \\ (B \u222a C) = (A \\ B) \\ C :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        split,\n            split,\n                exact h.1,\n\n                assume xinB,\n                have : x \u2208 (B \u222a C) := or.inl xinB,\n                exact h.2 this,\n\n            assume xinC,\n            have : x \u2208 (B \u222a C) := or.inr xinC,\n            exact h.2 this,\n\n        assume h,\n        split,\n            exact h.1.1,\n\n            assume xinBorC,\n            cases xinBorC with xinB xinC,\n                exact h.1.2 xinB,\n                exact h.2 xinC,\nend\n\n-- 5. Part II\nexample : C \\ D = C \u2229 -D :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        assumption,\n\n        assume h,\n        assumption,\nend\n\n-- 6.\nexample : (A \\ B) \u222a (A \u2229 B) = A :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        cases h,\n            exact h.1,\n            exact h.1,\n        \n        assume xinA,\n        cases em (x \u2208 B) with xinB xnotinB,\n            right, exact \u27e8xinA, xinB\u27e9,\n            left, exact \u27e8xinA, xnotinB\u27e9,\nend\n\n-- 7. (1)\nexample : A \\ B = A \\ (A \u2229 B) :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        split,\n            exact h.1,\n\n            assume xinAandB,\n            have : x \u2209 B := h.2,\n            exact this xinAandB.2,\n        \n        assume h,\n        split,\n            exact h.1,\n\n            assume : x \u2208 B,\n            have : x \u2208 (A \u2229 B) := \u27e8h.1, this\u27e9,\n            have : x \u2209 (A \u2229 B) := h.2,\n            contradiction,\nend\n\n-- 7. (2)\nexample : A \\ B = (A \u222a B) \\ B :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        split,\n            left, exact h.1,\n            exact h.2,\n        \n        assume h,\n        split,\n            cases h.1,\n                assumption,\n                have : x \u2209 B := h.2,\n                contradiction,\n            exact h.2,\nend\n\n-- 7. (3)\nexample : (A \u2229 B) \\ C = (A \\ C) \u2229 B :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        repeat {\n            assume h,\n            cases h,\n            cases h_left,\n                    repeat {split, repeat {assumption}},\n        }    \nend\n\n-- 8 & 9. Note: theorems are from set_exer2.lean\nsection\n    variables {I J : Type}\n\n    theorem Inter.intro {I : Type} {A : I \u2192 set U} \n    {x : U} (h : \u2200 i, x \u2208 A i) : x \u2208 \u22c2 i, A i :=\n    by simp; assumption\n\n    @[elab_simple]\n    theorem Inter.elim {I : Type} {A : I \u2192 set U} \n    {x : U} (h : x \u2208 \u22c2 i, A i) (i : I) : x \u2208 A i :=\n    by simp at h; apply h\n\n    theorem Union.intro {I : Type} {A : I \u2192 set U} \n    {x : U} (i : I) (h : x \u2208 A i) : x \u2208 \u22c3 i, A i :=\n    by {simp, existsi i, exact h}\n\n    theorem Union.elim {I : Type} {A : I \u2192 set U} {b : Prop} {x : U}\n    (h\u2081 : x \u2208 \u22c3 i, A i) (h\u2082 : \u2200 (i : I), x \u2208 A i \u2192 b) : b :=\n    by {simp at h\u2081, cases h\u2081 with i h, exact h\u2082 i h}\n\n    example : \u2200 {A : I \u2192 J \u2192 set U},\n    (\u22c3 i, \u22c2 j, A i j) \u2286 (\u22c2 j, \u22c3 i, A i j) :=\n    begin\n        intros,\n        assume x,\n        assume h,\n        apply Union.elim U h,\n            intros i this,\n            apply Inter.intro U,\n                assume j,\n                apply Union.intro U i,\n                    apply Inter.elim U this,\n    end\n\n    /-\n    A counter-example of the reverse statement (\u22c2 j, \u22c3 i, A i j) \u2286 (\u22c3 i, \u22c2 j, A i j):\n\n    let A be a array of array of sets of naturals defined below\n    [[{1}, {2}],\n     [{2}, {3}]]\n    So A : \u2115 \u2192 \u2115 \u2192 set \u2115 is indexed by I J : list \u2115 := [0, 1]\n    \u22c2 j, \u22c3 i, A i j = ({1} \u222a {2}) \u2229 ({2} \u222a {3}) = {2}\n    \u22c3 i, \u22c2 j, A i j = ({1} \u2229 {2}) \u222a ({2} \u2229 {3}) = \u2205\n\n    if (\u22c2 j, \u22c3 i, A i j) \u2286 (\u22c3 i, \u22c2 j, A i j), then {2} \u2286 \u2205, which is not true.\n\n    I actually don't know the correct way to create an indexed set, \n    so I used a complicated workaround to finish the proof in Lean\n    -/\n\n    -- define Aij as a list of list of sets of naturals\n    def Aij : list (list (set \u2115)) := [[{1}, {2}],\n                                     [{2}, {3}]]\n\n    -- define a function that converts booleans to 0 and 1\n    def bool_to_nat : bool \u2192 \u2115\n    | tt := 1\n    | ff := 0\n\n    -- define A'' as a set indexed by two boolean values\n    -- in this case, i and j can take only two possible values, namely ff and tt,\n    -- corresponding to indices 0 and 1\n    def A'' : bool \u2192 bool \u2192 set \u2115 :=\n    begin\n        assume i j,\n        -- How to get the nth element from a list? I actually don't know.\n        -- The following way works anyway\n        have : list (set \u2115),\n            exact option.iget (Aij.nth (bool_to_nat i)),\n        exact option.iget (this.nth (bool_to_nat j)),\n    end\n\n    -- Now, A'' tt ff is the element at the second row and first column of A'',\n    -- which is {2}, or in Lean's notation, \u03bb (b : \u2115), b = 2 \u2228 false\n    #reduce A'' tt ff\n\n    example : \u2203 {I : Type} {J : Type} {U : Type} {A : I \u2192 J \u2192 set U}, \u00ac\n    ((\u22c2 j, \u22c3 i, A i j) \u2286 (\u22c3 i, \u22c2 j, A i j)) :=\n    begin\n        apply exists.intro bool,\n        apply exists.intro bool,\n        apply exists.intro \u2115,\n        apply exists.intro A'',\n        assume h,\n        have : 2 \u2208 (\u22c2 j, \u22c3 i, A'' i j),\n            assume s,\n            assume z,\n            apply exists.elim z,\n                intros j a_1,\n                rw a_1,\n                cases j,\n                    apply Union.intro \u2115 tt,\n                        left, trivial,\n                    apply Union.intro \u2115 ff,\n                        left, trivial,\n\n        have : 2 \u2208 (\u22c3 i, \u22c2 j, A'' i j),\n            from h this,\n            \n        apply Union.elim \u2115 this,    \n            assume i,\n            assume h2,\n            have h3 : 2 \u2208 A'' i tt,\n                apply Inter.elim \u2115 h2,\n            have h4 : 2 \u2208 A'' i ff,\n                apply Inter.elim \u2115 h2,\n            cases i,\n                repeat {cases h4},\n                repeat {cases h3},\n    end\n\n    example : \u2200 {A : I \u2192 set U} {B : J \u2192 set U},\n    (\u22c3 i, A i) \u2229 (\u22c3 j, B j) = \u22c3 i, \u22c3 j, (A i \u2229 B j) :=\n    begin\n        intros,\n        apply ext,\n            assume x,\n            split,\n                assume h,\n                cases h,\n                apply Union.elim U h_left,\n                    intros i xinAi,\n                    apply Union.elim U h_right,\n                        intros j xinBj,\n                        apply Union.intro U i,\n                            apply Union.intro U j,\n                                split,\n                                    assumption,\n                                    assumption,\n\n                assume h,\n                apply Union.elim U h,\n                    intros i _,\n                    apply Union.elim U a,\n                        intros j xinAiBj,\n                        split,\n                            apply Union.intro U i,\n                                exact xinAiBj.1,\n                        \n                            apply Union.intro U j,\n                                 exact xinAiBj.2,\n    end\nend\n\n-- 10.\nexample : \u2200 a b c d e f: Type, ((a, b, c) = (d, e, f)) \u2194 a = d \u2227 b = e \u2227 c = f :=\nbegin\n    intros,\n    split,\n        assume h,\n        cases h,\n        repeat {split},\n        \n        assume h,\n        apply prod.ext,\n            exact h.1,\n            apply prod.ext,\n                exact h.2.1,\n                exact h.2.2,\nend\n\n-- Use set.prod to replace the built-in operator \"\u00d7\", because \n-- the default \u00d7 does not represent the Cartesian product between two sets\nlocal infix `\u00d7` : 50 := set.prod\n\n-- 11.\nexample : A \u00d7 (B \u222a C) = (A \u00d7 B) \u222a (A \u00d7 C) :=\nbegin\n    apply ext,\n    assume x,\n    split,\n        assume h,\n        cases h,\n        cases h_right,\n            left,\n            exact \u27e8h_left, h_right\u27e9,\n\n            right,\n            exact \u27e8h_left, h_right\u27e9,\n        \n        assume h,\n        cases h,\n            exact \u27e8h.1, or.inl h.2\u27e9,\n            exact \u27e8h.1, or.inr h.2\u27e9,\nend\n\n-- 12.\nexample : (A \u2229 B) \u00d7 (C \u2229 D) = (A \u00d7 C) \u2229 (B \u00d7 D) :=\nbegin\n    apply ext,\n    assume x,\n        split,\n            assume h,\n            split,\n                cases h,\n                exact \u27e8h_left.1, h_right.1\u27e9,\n\n                cases h,\n                exact \u27e8h_left.2, h_right.2\u27e9,\n            \n            assume h,\n            cases h,\n            cases h_left,\n            cases h_right,\n            repeat {split, \n                    repeat {assumption}},\nend\n\n-- 13. See set_exer2\n\n-- some extra ones\nexample : A = B \u2194 (A \u2229 -B) = \u2205 \u2227 (-A \u2229 B) = \u2205 :=\nbegin\n    split,\n        assume aeqb,\n        split,\n            repeat {            \n                apply ext,\n                assume x,\n                split,\n                    assume h,\n                    rw aeqb at h,\n                    cases h,\n                    contradiction,\n                \n                    assume h,\n                    exact false.elim h,\n            },\n\n            assume h,\n            cases h,\n            apply ext,\n            assume x,\n            split,\n                assume xina,\n                cases em (x \u2208 B) with xinb xninb,\n                    assumption,\n                    have h2 := ((set.ext_iff (A \u2229 -B) \u2205).1 h_left x).1,\n                    have : x \u2208 A \u2229 (-B) := \u27e8xina, xninb\u27e9,\n                    exact false.elim (h2 this),\n                \n                assume xinb,\n                cases em (x \u2208 A) with xina xnina,\n                    assumption,\n                    have h2 := ((set.ext_iff (-A \u2229 B) \u2205).1 h_right x).1,\n                    have : x \u2208 -A \u2229 B := \u27e8xnina, xinb\u27e9,\n                    exact false.elim (h2 this),\nend\n\n#check @set.prod\n#check set.ext", "meta": {"author": "hanzhi713", "repo": "lean-proofs", "sha": "4d8356a878645b9ba7cb036f87737f3f1e68ede5", "save_path": "github-repos/lean/hanzhi713-lean-proofs", "path": "github-repos/lean/hanzhi713-lean-proofs/lean-proofs-4d8356a878645b9ba7cb036f87737f3f1e68ede5/src/other/set_exer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7349621416898856}}
{"text": "/-\nCopyright (c) 2019 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou, S\u00e9bastien Gou\u00ebzel, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport algebra.direct_sum.module\nimport analysis.complex.basic\nimport analysis.normed_space.bounded_linear_maps\nimport linear_algebra.bilinear_form\nimport linear_algebra.sesquilinear_form\n\n/-!\n# Inner product space\n\nThis file defines inner product spaces and proves the basic properties.  We do not formally\ndefine Hilbert spaces, but they can be obtained using the pair of assumptions\n`[inner_product_space \ud835\udd5c E] [complete_space E]`.\n\nAn inner product space is a vector space endowed with an inner product. It generalizes the notion of\ndot product in `\u211d^n` and provides the means of defining the length of a vector and the angle between\ntwo vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero.\nWe define both the real and complex cases at the same time using the `is_R_or_C` typeclass.\n\nThis file proves general results on inner product spaces. For the specific construction of an inner\nproduct structure on `n \u2192 \ud835\udd5c` for `\ud835\udd5c = \u211d` or `\u2102`, see `euclidean_space` in\n`analysis.inner_product_space.pi_L2`.\n\n## Main results\n\n- We define the class `inner_product_space \ud835\udd5c E` extending `normed_space \ud835\udd5c E` with a number of basic\n  properties, most notably the Cauchy-Schwarz inequality. Here `\ud835\udd5c` is understood to be either `\u211d`\n  or `\u2102`, through the `is_R_or_C` typeclass.\n- We show that the inner product is continuous, `continuous_inner`, and bundle it as the\n  the continuous sesquilinear map `innerSL` (see also `inner\u209b\u2097` for the non-continuous version).\n- We define `orthonormal`, a predicate on a function `v : \u03b9 \u2192 E`, and prove the existence of a\n  maximal orthonormal set, `exists_maximal_orthonormal`.  Bessel's inequality,\n  `orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`,\n  the sum of the norm-squares of the inner products `\u27eav i, x\u27eb` is no more than the norm-square of\n  `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file\n  `analysis.inner_product_space.projection`.\n- The `orthogonal_complement` of a submodule `K` is defined, and basic API established.  Some of\n  the more subtle results about the orthogonal complement are delayed to\n  `analysis.inner_product_space.projection`.\n\n## Notation\n\nWe globally denote the real and complex inner products by `\u27ea\u00b7, \u00b7\u27eb_\u211d` and `\u27ea\u00b7, \u00b7\u27eb_\u2102` respectively.\nWe also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,\nwhich respectively introduce the plain notation `\u27ea\u00b7, \u00b7\u27eb` for the real and complex inner product.\n\nThe orthogonal complement of a submodule `K` is denoted by `K\u15ee`.\n\n## Implementation notes\n\nWe choose the convention that inner products are conjugate linear in the first argument and linear\nin the second.\n\n## Tags\n\ninner product space, Hilbert space, norm\n\n## References\n*  [Cl\u00e9ment & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]\n*  [Cl\u00e9ment & Martin, *A Coq formal proof of the Lax\u2013Milgram theorem*]\n\nThe Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>\n-/\n\nnoncomputable theory\n\nopen is_R_or_C real filter\nopen_locale big_operators topological_space complex_conjugate\n\nvariables {\ud835\udd5c E F : Type*} [is_R_or_C \ud835\udd5c]\n\n/-- Syntactic typeclass for types endowed with an inner product -/\nclass has_inner (\ud835\udd5c E : Type*) := (inner : E \u2192 E \u2192 \ud835\udd5c)\n\nexport has_inner (inner)\n\nnotation `\u27ea`x`, `y`\u27eb_\u211d` := @inner \u211d _ _ x y\nnotation `\u27ea`x`, `y`\u27eb_\u2102` := @inner \u2102 _ _ x y\n\nsection notations\n\nlocalized \"notation `\u27ea`x`, `y`\u27eb` := @inner \u211d _ _ x y\" in real_inner_product_space\nlocalized \"notation `\u27ea`x`, `y`\u27eb` := @inner \u2102 _ _ x y\" in complex_inner_product_space\n\nend notations\n\n/--\nAn inner product space is a vector space with an additional operation called inner product.\nThe norm could be derived from the inner product, instead we require the existence of a norm and\nthe fact that `\u2225x\u2225^2 = re \u27eax, x\u27eb` to be able to put instances on `\ud835\udd42` or product\nspaces.\n\nTo construct a norm from an inner product, see `inner_product_space.of_core`.\n-/\nclass inner_product_space (\ud835\udd5c : Type*) (E : Type*) [is_R_or_C \ud835\udd5c]\n  extends normed_group E, normed_space \ud835\udd5c E, has_inner \ud835\udd5c E :=\n(norm_sq_eq_inner : \u2200 (x : E), \u2225x\u2225^2 = re (inner x x))\n(conj_sym  : \u2200 x y, conj (inner y x) = inner x y)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\nattribute [nolint dangerous_instance] inner_product_space.to_normed_group\n-- note [is_R_or_C instance]\n\n/-!\n### Constructing a normed space structure from an inner product\n\nIn the definition of an inner product space, we require the existence of a norm, which is equal\n(but maybe not defeq) to the square root of the scalar product. This makes it possible to put\nan inner product space structure on spaces with a preexisting norm (for instance `\u211d`), with good\nproperties. However, sometimes, one would like to define the norm starting only from a well-behaved\nscalar product. This is what we implement in this paragraph, starting from a structure\n`inner_product_space.core` stating that we have a nice scalar product.\n\nOur goal here is not to develop a whole theory with all the supporting API, as this will be done\nbelow for `inner_product_space`. Instead, we implement the bare minimum to go as directly as\npossible to the construction of the norm and the proof of the triangular inequality.\n\nWarning: Do not use this `core` structure if the space you are interested in already has a norm\ninstance defined on it, otherwise this will create a second non-defeq norm instance!\n-/\n\n/-- A structure requiring that a scalar product is positive definite and symmetric, from which one\ncan construct an `inner_product_space` instance in `inner_product_space.of_core`. -/\n@[nolint has_inhabited_instance]\nstructure inner_product_space.core\n  (\ud835\udd5c : Type*) (F : Type*)\n  [is_R_or_C \ud835\udd5c] [add_comm_group F] [module \ud835\udd5c F] :=\n(inner     : F \u2192 F \u2192 \ud835\udd5c)\n(conj_sym  : \u2200 x y, conj (inner y x) = inner x y)\n(nonneg_re : \u2200 x, 0 \u2264 re (inner x x))\n(definite  : \u2200 x, inner x x = 0 \u2192 x = 0)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\n/- We set `inner_product_space.core` to be a class as we will use it as such in the construction\nof the normed space structure that it produces. However, all the instances we will use will be\nlocal to this proof. -/\nattribute [class] inner_product_space.core\n\nnamespace inner_product_space.of_core\n\nvariables [add_comm_group F] [module \ud835\udd5c F] [c : inner_product_space.core \ud835\udd5c F]\ninclude c\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c F _ x y\nlocal notation `norm_sqK` := @is_R_or_C.norm_sq \ud835\udd5c _\nlocal notation `reK` := @is_R_or_C.re \ud835\udd5c _\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal notation `ext_iff` := @is_R_or_C.ext_iff \ud835\udd5c _\nlocal postfix `\u2020`:90 := star_ring_end _\n\n/-- Inner product defined by the `inner_product_space.core` structure. -/\ndef to_has_inner : has_inner \ud835\udd5c F := { inner := c.inner }\nlocal attribute [instance] to_has_inner\n\n/-- The norm squared function for `inner_product_space.core` structure. -/\ndef norm_sq (x : F) := reK \u27eax, x\u27eb\n\nlocal notation `norm_sqF` := @norm_sq \ud835\udd5c F _ _ _ _\n\nlemma inner_conj_sym (x y : F) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := c.conj_sym x y\n\nlemma inner_self_nonneg {x : F} : 0 \u2264 re \u27eax, x\u27eb := c.nonneg_re _\n\nlemma inner_self_nonneg_im {x : F} : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp [inner_conj_sym]\n\nlemma inner_self_im_zero {x : F} : im \u27eax, x\u27eb = 0 :=\ninner_self_nonneg_im\n\nlemma inner_add_left {x y z : F} : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\nc.add_left _ _ _\n\nlemma inner_add_right {x y z : F} : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby rw [\u2190inner_conj_sym, inner_add_left, ring_hom.map_add]; simp only [inner_conj_sym]\n\nlemma inner_norm_sq_eq_inner_self (x : F) : (norm_sqF x : \ud835\udd5c) = \u27eax, x\u27eb :=\nbegin\n  rw ext_iff,\n  exact \u27e8by simp only [of_real_re]; refl, by simp only [inner_self_nonneg_im, of_real_im]\u27e9\nend\n\nlemma inner_re_symm {x y : F} : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : F} : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : F} {r : \ud835\udd5c} : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\nc.smul_left _ _ _\n\nlemma inner_smul_right {x y : F} {r : \ud835\udd5c} : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_smul_left]; simp only [conj_conj, inner_conj_sym, ring_hom.map_mul]\n\nlemma inner_zero_left {x : F} : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190zero_smul \ud835\udd5c (0 : F), inner_smul_left]; simp only [zero_mul, ring_hom.map_zero]\n\nlemma inner_zero_right {x : F} : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_sym, inner_zero_left]; simp only [ring_hom.map_zero]\n\nlemma inner_self_eq_zero {x : F} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\niff.intro (c.definite _) (by { rintro rfl, exact inner_zero_left })\n\nlemma inner_self_re_to_K {x : F} : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby norm_num [ext_iff, inner_self_nonneg_im]\n\nlemma inner_abs_conj_sym {x y : F} : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\n  by rw [\u2190inner_conj_sym, abs_conj]\n\nlemma inner_neg_left {x y : F} : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\nlemma inner_neg_right {x y : F} : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_sym]\n\nlemma inner_sub_left {x y z : F} : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left, inner_neg_left] }\n\nlemma inner_sub_right {x y z : F} : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right, inner_neg_right] }\n\nlemma inner_mul_conj_re_abs {x y : F} : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw [\u2190inner_conj_sym, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `inner (x + y) (x + y)` -/\nlemma inner_add_add_self {x y : F} : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/- Expand `inner (x - y) (x - y)` -/\nlemma inner_sub_sub_self {x y : F} : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/--\n**Cauchy\u2013Schwarz inequality**. This proof follows \"Proof 2\" on Wikipedia.\nWe need this for the `core` structure to prove the triangle inequality below when\nshowing the core is a normed group.\n-/\nlemma inner_mul_inner_self_le (x y : F) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { change y \u2260 0 at hy,\n    have hy' : \u27eay, y\u27eb \u2260 0 := \u03bb h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := by simp only [inner_self_re_to_K],\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw ext_iff,\n      exact \u27e8by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082,\n                      neg_mul_eq_neg_mul_symm, add_monoid_hom.map_add, mul_re,\n                      conj_im, add_monoid_hom.map_sub, mul_neg_eq_neg_mul_symm, conj_re, neg_neg]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by field_simp [-mul_re, inner_conj_sym, hT, ring_hom.map_div, h\u2081, h\u2083]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw [div_mul_eq_mul_div_comm, \u2190mul_div_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Norm constructed from a `inner_product_space.core` structure, defined to be the square root\nof the scalar product. -/\ndef to_has_norm : has_norm F :=\n{ norm := \u03bb x, sqrt (re \u27eax, x\u27eb) }\n\nlocal attribute [instance] to_has_norm\n\nlemma norm_eq_sqrt_inner (x : F) : \u2225x\u2225 = sqrt (re \u27eax, x\u27eb) := rfl\n\nlemma inner_self_eq_norm_mul_norm (x : F) : re \u27eax, x\u27eb = \u2225x\u2225 * \u2225x\u2225 :=\nby rw [norm_eq_sqrt_inner, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma sqrt_norm_sq_eq_norm {x : F} : sqrt (norm_sqF x) = \u2225x\u2225 := rfl\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : F) : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _))\nbegin\n  have H : \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225) = re \u27eay, y\u27eb * re \u27eax, x\u27eb,\n  { simp only [inner_self_eq_norm_mul_norm], ring, },\n  rw H,\n  conv\n  begin\n    to_lhs, congr, rw [inner_abs_conj_sym],\n  end,\n  exact inner_mul_inner_self_le y x,\nend\n\n/-- Normed group structure constructed from an `inner_product_space.core` structure -/\ndef to_normed_group : normed_group F :=\nnormed_group.of_core F\n{ norm_eq_zero_iff := assume x,\n  begin\n    split,\n    { intro H,\n      change sqrt (re \u27eax, x\u27eb) = 0 at H,\n      rw [sqrt_eq_zero inner_self_nonneg] at H,\n      apply (inner_self_eq_zero : \u27eax, x\u27eb = 0 \u2194 x = 0).mp,\n      rw ext_iff,\n      exact \u27e8by simp [H], by simp [inner_self_im_zero]\u27e9 },\n    { rintro rfl,\n      change sqrt (re \u27ea0, 0\u27eb) = 0,\n      simp only [sqrt_zero, inner_zero_right, add_monoid_hom.map_zero] }\n  end,\n  triangle := assume x y,\n  begin\n    have h\u2081 : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := abs_inner_le_norm _ _,\n    have h\u2082 : re \u27eax, y\u27eb \u2264 abs \u27eax, y\u27eb := re_le_abs _,\n    have h\u2083 : re \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := by linarith,\n    have h\u2084 : re \u27eay, x\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := by rwa [\u2190inner_conj_sym, conj_re],\n    have : \u2225x + y\u2225 * \u2225x + y\u2225 \u2264 (\u2225x\u2225 + \u2225y\u2225) * (\u2225x\u2225 + \u2225y\u2225),\n    { simp [\u2190inner_self_eq_norm_mul_norm, inner_add_add_self, add_mul, mul_add, mul_comm],\n      linarith },\n    exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this\n  end,\n  norm_neg := \u03bb x, by simp only [norm, inner_neg_left, neg_neg, inner_neg_right] }\n\nlocal attribute [instance] to_normed_group\n\n/-- Normed space structure constructed from a `inner_product_space.core` structure -/\ndef to_normed_space : normed_space \ud835\udd5c F :=\n{ norm_smul_le := assume r x,\n  begin\n    rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, \u2190mul_assoc],\n    rw [conj_mul_eq_norm_sq_left, of_real_mul_re, sqrt_mul, \u2190inner_norm_sq_eq_inner_self,\n        of_real_re],\n    { simp [sqrt_norm_sq_eq_norm, is_R_or_C.sqrt_norm_sq_eq_norm] },\n    { exact norm_sq_nonneg r }\n  end }\n\nend inner_product_space.of_core\n\n/-- Given a `inner_product_space.core` structure on a space, one can use it to turn\nthe space into an inner product space, constructing the norm out of the inner product -/\ndef inner_product_space.of_core [add_comm_group F] [module \ud835\udd5c F]\n  (c : inner_product_space.core \ud835\udd5c F) : inner_product_space \ud835\udd5c F :=\nbegin\n  letI : normed_group F := @inner_product_space.of_core.to_normed_group \ud835\udd5c F _ _ _ c,\n  letI : normed_space \ud835\udd5c F := @inner_product_space.of_core.to_normed_space \ud835\udd5c F _ _ _ c,\n  exact { norm_sq_eq_inner := \u03bb x,\n    begin\n      have h\u2081 : \u2225x\u2225^2 = (sqrt (re (c.inner x x))) ^ 2 := rfl,\n      have h\u2082 : 0 \u2264 re (c.inner x x) := inner_product_space.of_core.inner_self_nonneg,\n      simp [h\u2081, sq_sqrt, h\u2082],\n    end,\n    ..c }\nend\n\n/-! ### Properties of inner product spaces -/\n\nvariables [inner_product_space \ud835\udd5c E] [inner_product_space \u211d F]\nvariables [dec_E : decidable_eq E]\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\nlocal notation `IK` := @is_R_or_C.I \ud835\udd5c _\nlocal notation `absR` := has_abs.abs\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal postfix `\u2020`:90 := star_ring_end _\n\nexport inner_product_space (norm_sq_eq_inner)\n\nsection basic_properties\n\n@[simp] lemma inner_conj_sym (x y : E) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := inner_product_space.conj_sym _ _\nlemma real_inner_comm (x y : F) : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := @inner_conj_sym \u211d _ _ _ x y\n\nlemma inner_eq_zero_sym {x y : E} : \u27eax, y\u27eb = 0 \u2194 \u27eay, x\u27eb = 0 :=\n\u27e8\u03bb h, by simp [\u2190inner_conj_sym, h], \u03bb h, by simp [\u2190inner_conj_sym, h]\u27e9\n\n@[simp] lemma inner_self_nonneg_im {x : E} : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp\n\nlemma inner_self_im_zero {x : E} : im \u27eax, x\u27eb = 0 := inner_self_nonneg_im\n\nlemma inner_add_left {x y z : E} : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\ninner_product_space.add_left _ _ _\n\nlemma inner_add_right {x y z : E} : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby { rw [\u2190inner_conj_sym, inner_add_left, ring_hom.map_add], simp only [inner_conj_sym] }\n\nlemma inner_re_symm {x y : E} : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : E} : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : E} {r : \ud835\udd5c} : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\ninner_product_space.smul_left _ _ _\nlemma real_inner_smul_left {x y : F} {r : \u211d} : \u27ear \u2022 x, y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d := inner_smul_left\n\nlemma inner_smul_real_left {x y : E} {r : \u211d} : \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_left, conj_of_real, algebra.smul_def], refl }\n\nlemma inner_smul_right {x y : E} {r : \ud835\udd5c} : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_smul_left, ring_hom.map_mul, conj_conj, inner_conj_sym]\nlemma real_inner_smul_right {x y : F} {r : \u211d} : \u27eax, r \u2022 y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d := inner_smul_right\n\nlemma inner_smul_real_right {x y : E} {r : \u211d} : \u27eax, (r : \ud835\udd5c) \u2022 y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_right, algebra.smul_def], refl }\n\n/-- The inner product as a sesquilinear form. -/\n@[simps]\ndef sesq_form_of_inner : E \u2192\u2097[\ud835\udd5c] E \u2192\u2097\u22c6[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk\u2082'\u209b\u2097 (ring_hom.id \ud835\udd5c) (star_ring_end _)\n  (\u03bb x y, \u27eay, x\u27eb)\n  (\u03bb x y z, inner_add_right)\n  (\u03bb r x y, inner_smul_right)\n  (\u03bb x y z, inner_add_left)\n  (\u03bb r x y, inner_smul_left)\n\n/-- The real inner product as a bilinear form. -/\n@[simps]\ndef bilin_form_of_real_inner : bilin_form \u211d F :=\n{ bilin := inner,\n  bilin_add_left := \u03bb x y z, inner_add_left,\n  bilin_smul_left := \u03bb a x y, inner_smul_left,\n  bilin_add_right := \u03bb x y z, inner_add_right,\n  bilin_smul_right := \u03bb a x y, inner_smul_right }\n\n/-- An inner product with a sum on the left. -/\nlemma sum_inner {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27ea\u2211 i in s, f i, x\u27eb = \u2211 i in s, \u27eaf i, x\u27eb := (sesq_form_of_inner x).map_sum\n\n/-- An inner product with a sum on the right. -/\nlemma inner_sum {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27eax, \u2211 i in s, f i\u27eb = \u2211 i in s, \u27eax, f i\u27eb := (linear_map.flip sesq_form_of_inner x).map_sum\n\n/-- An inner product with a sum on the left, `finsupp` version. -/\nlemma finsupp.sum_inner {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eal.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i), x\u27eb\n  = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), (conj a) \u2022 \u27eav i, x\u27eb) :=\nby { convert sum_inner l.support (\u03bb a, l a \u2022 v a) x, simp [inner_smul_left, finsupp.sum] }\n\n/-- An inner product with a sum on the right, `finsupp` version. -/\nlemma finsupp.inner_sum {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eax, l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i)\u27eb = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 \u27eax, v i\u27eb) :=\nby { convert inner_sum l.support (\u03bb a, l a \u2022 v a) x, simp [inner_smul_right, finsupp.sum] }\n\nlemma dfinsupp.sum_inner {\u03b9 : Type*} [dec : decidable_eq \u03b9] {\u03b1 : \u03b9 \u2192 Type*}\n  [\u03a0 i, add_zero_class (\u03b1 i)] [\u03a0 i (x : \u03b1 i), decidable (x \u2260 0)]\n  (f : \u03a0 i, \u03b1 i \u2192 E) (l : \u03a0\u2080 i, \u03b1 i) (x : E) :\n  \u27eal.sum f, x\u27eb = l.sum (\u03bb i a, \u27eaf i a, x\u27eb) :=\nby simp [dfinsupp.sum, sum_inner] {contextual := tt}\n\nlemma dfinsupp.inner_sum {\u03b9 : Type*} [dec : decidable_eq \u03b9] {\u03b1 : \u03b9 \u2192 Type*}\n  [\u03a0 i, add_zero_class (\u03b1 i)] [\u03a0 i (x : \u03b1 i), decidable (x \u2260 0)]\n  (f : \u03a0 i, \u03b1 i \u2192 E) (l : \u03a0\u2080 i, \u03b1 i) (x : E) :\n  \u27eax, l.sum f\u27eb = l.sum (\u03bb i a, \u27eax, f i a\u27eb) :=\nby simp [dfinsupp.sum, inner_sum] {contextual := tt}\n\n@[simp] lemma inner_zero_left {x : E} : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190 zero_smul \ud835\udd5c (0:E), inner_smul_left, ring_hom.map_zero, zero_mul]\n\nlemma inner_re_zero_left {x : E} : re \u27ea0, x\u27eb = 0 :=\nby simp only [inner_zero_left, add_monoid_hom.map_zero]\n\n@[simp] lemma inner_zero_right {x : E} : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_sym, inner_zero_left, ring_hom.map_zero]\n\nlemma inner_re_zero_right {x : E} : re \u27eax, 0\u27eb = 0 :=\nby simp only [inner_zero_right, add_monoid_hom.map_zero]\n\nlemma inner_self_nonneg {x : E} : 0 \u2264 re \u27eax, x\u27eb :=\nby rw [\u2190norm_sq_eq_inner]; exact pow_nonneg (norm_nonneg x) 2\nlemma real_inner_self_nonneg {x : F} : 0 \u2264 \u27eax, x\u27eb_\u211d := @inner_self_nonneg \u211d F _ _ x\n\n@[simp] lemma inner_self_eq_zero {x : E} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    have h\u2081 : re \u27eax, x\u27eb = 0 := by rw is_R_or_C.ext_iff at h; simp [h.1],\n    rw [\u2190norm_sq_eq_inner x] at h\u2081,\n    rw [\u2190norm_eq_zero],\n    exact pow_eq_zero h\u2081 },\n  { rintro rfl,\n    exact inner_zero_left }\nend\n\n@[simp] lemma inner_self_nonpos {x : E} : re \u27eax, x\u27eb \u2264 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    rw \u2190inner_self_eq_zero,\n    have H\u2081 : re \u27eax, x\u27eb \u2265 0, exact inner_self_nonneg,\n    have H\u2082 : re \u27eax, x\u27eb = 0, exact le_antisymm h H\u2081,\n    rw is_R_or_C.ext_iff,\n    exact \u27e8by simp [H\u2082], by simp [inner_self_nonneg_im]\u27e9 },\n  { rintro rfl,\n    simp only [inner_zero_left, add_monoid_hom.map_zero] }\nend\n\nlemma real_inner_self_nonpos {x : F} : \u27eax, x\u27eb_\u211d \u2264 0 \u2194 x = 0 :=\nby { have h := @inner_self_nonpos \u211d F _ _ x, simpa using h }\n\n@[simp] lemma inner_self_re_to_K {x : E} : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby rw is_R_or_C.ext_iff; exact \u27e8by simp, by simp [inner_self_nonneg_im]\u27e9\n\nlemma inner_self_eq_norm_sq_to_K (x : E) : \u27eax, x\u27eb = (\u2225x\u2225 ^ 2 : \ud835\udd5c) :=\nbegin\n  suffices : (is_R_or_C.re \u27eax, x\u27eb : \ud835\udd5c) = \u2225x\u2225 ^ 2,\n  { simpa [inner_self_re_to_K] using this },\n  exact_mod_cast (norm_sq_eq_inner x).symm\nend\n\nlemma inner_self_re_abs {x : E} : re \u27eax, x\u27eb = abs \u27eax, x\u27eb :=\nbegin\n  conv_rhs { rw [\u2190inner_self_re_to_K] },\n  symmetry,\n  exact is_R_or_C.abs_of_nonneg inner_self_nonneg,\nend\n\nlemma inner_self_abs_to_K {x : E} : (absK \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby { rw [\u2190inner_self_re_abs], exact inner_self_re_to_K }\n\nlemma real_inner_self_abs {x : F} : absR \u27eax, x\u27eb_\u211d = \u27eax, x\u27eb_\u211d :=\nby { have h := @inner_self_abs_to_K \u211d F _ _ x, simpa using h }\n\nlemma inner_abs_conj_sym {x y : E} : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, abs_conj]\n\n@[simp] lemma inner_neg_left {x y : E} : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\n@[simp] lemma inner_neg_right {x y : E} : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_sym]\n\nlemma inner_neg_neg {x y : E} : \u27ea-x, -y\u27eb = \u27eax, y\u27eb := by simp\n\n@[simp] lemma inner_self_conj {x : E} : \u27eax, x\u27eb\u2020 = \u27eax, x\u27eb :=\nby rw [is_R_or_C.ext_iff]; exact \u27e8by rw [conj_re], by rw [conj_im, inner_self_im_zero, neg_zero]\u27e9\n\nlemma inner_sub_left {x y z : E} : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left] }\n\nlemma inner_sub_right {x y z : E} : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right] }\n\nlemma inner_mul_conj_re_abs {x y : E} : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw [\u2190inner_conj_sym, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `\u27eax + y, x + y\u27eb` -/\nlemma inner_add_add_self {x y : E} : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/-- Expand `\u27eax + y, x + y\u27eb_\u211d` -/\nlemma real_inner_add_add_self {x y : F} : \u27eax + y, x + y\u27eb_\u211d = \u27eax, x\u27eb_\u211d + 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  simp [inner_add_add_self, this],\n  ring,\nend\n\n/- Expand `\u27eax - y, x - y\u27eb` -/\nlemma inner_sub_sub_self {x y : E} : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/-- Expand `\u27eax - y, x - y\u27eb_\u211d` -/\nlemma real_inner_sub_sub_self {x y : F} : \u27eax - y, x - y\u27eb_\u211d = \u27eax, x\u27eb_\u211d - 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  simp [inner_sub_sub_self, this],\n  ring,\nend\n\n/-- Parallelogram law -/\nlemma parallelogram_law {x y : E} :\n  \u27eax + y, x + y\u27eb + \u27eax - y, x - y\u27eb = 2 * (\u27eax, x\u27eb + \u27eay, y\u27eb) :=\nby simp [inner_add_add_self, inner_sub_sub_self, two_mul, sub_eq_add_neg, add_comm, add_left_comm]\n\n/-- Cauchy\u2013Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia. -/\nlemma inner_mul_inner_self_le (x y : E) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { change y \u2260 0 at hy,\n    have hy' : \u27eay, y\u27eb \u2260 0 := \u03bb h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := by simp,\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw is_R_or_C.ext_iff,\n      exact \u27e8by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082,\n                      neg_mul_eq_neg_mul_symm, add_monoid_hom.map_add, conj_im,\n                      add_monoid_hom.map_sub, mul_neg_eq_neg_mul_symm, conj_re, neg_neg, mul_re]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by field_simp [-mul_re, hT, ring_hom.map_div, h\u2081, h\u2083, inner_conj_sym]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw [div_mul_eq_mul_div_comm, \u2190mul_div_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Cauchy\u2013Schwarz inequality for real inner products. -/\nlemma real_inner_mul_inner_self_le (x y : F) : \u27eax, y\u27eb_\u211d * \u27eax, y\u27eb_\u211d \u2264 \u27eax, x\u27eb_\u211d * \u27eay, y\u27eb_\u211d :=\nbegin\n  have h\u2081 : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  have h\u2082 := @inner_mul_inner_self_le \u211d F _ _ x y,\n  dsimp at h\u2082,\n  have h\u2083 := abs_mul_abs_self \u27eax, y\u27eb_\u211d,\n  rw [h\u2081] at h\u2082,\n  simpa [h\u2083] using h\u2082,\nend\n\n/-- A family of vectors is linearly independent if they are nonzero\nand orthogonal. -/\nlemma linear_independent_of_ne_zero_of_inner_eq_zero {\u03b9 : Type*} {v : \u03b9 \u2192 E}\n  (hz : \u2200 i, v i \u2260 0) (ho : \u2200 i j, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0) : linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff',\n  intros s g hg i hi,\n  have h' : g i * inner (v i) (v i) = inner (v i) (\u2211 j in s, g j \u2022 v j),\n  { rw inner_sum,\n    symmetry,\n    convert finset.sum_eq_single i _ _,\n    { rw inner_smul_right },\n    { intros j hj hji,\n      rw [inner_smul_right, ho i j hji.symm, mul_zero] },\n    { exact \u03bb h, false.elim (h hi) } },\n  simpa [hg, hz] using h'\nend\n\nend basic_properties\n\nsection orthonormal_sets\nvariables {\u03b9 : Type*} [dec_\u03b9 : decidable_eq \u03b9] (\ud835\udd5c)\n\ninclude \ud835\udd5c\n\n/-- An orthonormal set of vectors in an `inner_product_space` -/\ndef orthonormal (v : \u03b9 \u2192 E) : Prop :=\n(\u2200 i, \u2225v i\u2225 = 1) \u2227 (\u2200 {i j}, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0)\n\nomit \ud835\udd5c\n\nvariables {\ud835\udd5c}\n\ninclude dec_\u03b9\n/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal.  (Inner\nproduct equals Kronecker delta.) -/\nlemma orthonormal_iff_ite {v : \u03b9 \u2192 E} :\n  orthonormal \ud835\udd5c v \u2194 \u2200 i j, \u27eav i, v j\u27eb = if i = j then (1:\ud835\udd5c) else (0:\ud835\udd5c) :=\nbegin\n  split,\n  { intros hv i j,\n    split_ifs,\n    { simp [h, inner_self_eq_norm_sq_to_K, hv.1] },\n    { exact hv.2 h } },\n  { intros h,\n    split,\n    { intros i,\n      have h' : \u2225v i\u2225 ^ 2 = 1 ^ 2 := by simp [norm_sq_eq_inner, h i i],\n      have h\u2081 : 0 \u2264 \u2225v i\u2225 := norm_nonneg _,\n      have h\u2082 : (0:\u211d) \u2264 1 := zero_le_one,\n      rwa sq_eq_sq h\u2081 h\u2082 at h' },\n    { intros i j hij,\n      simpa [hij] using h i j } }\nend\nomit dec_\u03b9\n\ninclude dec_E\n/-- `if ... then ... else` characterization of a set of vectors being orthonormal.  (Inner product\nequals Kronecker delta.) -/\ntheorem orthonormal_subtype_iff_ite {s : set E} :\n  orthonormal \ud835\udd5c (coe : s \u2192 E) \u2194\n  (\u2200 v \u2208 s, \u2200 w \u2208 s, \u27eav, w\u27eb = if v = w then 1 else 0) :=\nbegin\n  rw orthonormal_iff_ite,\n  split,\n  { intros h v hv w hw,\n    convert h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9 using 1,\n    simp },\n  { rintros h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9,\n    convert h v hv w hw using 1,\n    simp }\nend\nomit dec_E\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = l i :=\nby classical; simp [finsupp.total_apply, finsupp.inner_sum, orthonormal_iff_ite.mp hv]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_sum\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) {s : finset \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  \u27eav i, \u2211 i in s, (l i) \u2022 (v i)\u27eb = l i :=\nby classical; simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, \u2211 i : \u03b9, (l i) \u2022 (v i)\u27eb = l i :=\nhv.inner_right_sum l (finset.mem_univ _)\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = conj (l i) :=\nby rw [\u2190 inner_conj_sym, hv.inner_right_finsupp]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_sum\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) {s : finset \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  \u27ea\u2211 i in s, (l i) \u2022 (v i), v i\u27eb = conj (l i) :=\nby classical; simp [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27ea\u2211 i : \u03b9, (l i) \u2022 (v i), v i\u27eb = conj (l i) :=\nhv.inner_left_sum l (finset.mem_univ _)\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum over the first `finsupp`. -/\nlemma orthonormal.inner_finsupp_eq_sum_left\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l\u2081 l\u2082 : \u03b9 \u2192\u2080 \ud835\udd5c) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l\u2081, finsupp.total \u03b9 E \ud835\udd5c v l\u2082\u27eb = l\u2081.sum (\u03bb i y, conj y * l\u2082 i) :=\nby simp [finsupp.total_apply _ l\u2081, finsupp.sum_inner, hv.inner_right_finsupp]\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum over the second `finsupp`. -/\nlemma orthonormal.inner_finsupp_eq_sum_right\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l\u2081 l\u2082 : \u03b9 \u2192\u2080 \ud835\udd5c) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l\u2081, finsupp.total \u03b9 E \ud835\udd5c v l\u2082\u27eb = l\u2082.sum (\u03bb i y, conj (l\u2081 i) * y) :=\nby simp [finsupp.total_apply _ l\u2082, finsupp.inner_sum, hv.inner_left_finsupp, mul_comm]\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum. -/\nlemma orthonormal.inner_sum\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l\u2081 l\u2082 : \u03b9 \u2192 \ud835\udd5c) (s : finset \u03b9) :\n  \u27ea\u2211 i in s, l\u2081 i \u2022 v i, \u2211 i in s, l\u2082 i \u2022 v i\u27eb = \u2211 i in s, conj (l\u2081 i) * l\u2082 i :=\nbegin\n  simp_rw [sum_inner, inner_smul_left],\n  refine finset.sum_congr rfl (\u03bb i hi, _),\n  rw hv.inner_right_sum l\u2082 hi\nend\n\n/--\nThe double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the\nsum of the weights.\n-/\nlemma orthonormal.inner_left_right_finset {s : finset \u03b9}  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v)\n  {a : \u03b9 \u2192 \u03b9 \u2192 \ud835\udd5c} : \u2211 i in s, \u2211 j in s, (a i j) \u2022 \u27eav j, v i\u27eb = \u2211 k in s, a k k :=\nby classical; simp [orthonormal_iff_ite.mp hv, finset.sum_ite_of_true]\n\n/-- An orthonormal set is linearly independent. -/\nlemma orthonormal.linear_independent {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff,\n  intros l hl,\n  ext i,\n  have key : \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = \u27eav i, 0\u27eb := by rw hl,\n  simpa [hv.inner_right_finsupp] using key\nend\n\n/-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an\northonormal family. -/\nlemma orthonormal.comp\n  {\u03b9' : Type*} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : \u03b9' \u2192 \u03b9) (hf : function.injective f) :\n  orthonormal \ud835\udd5c (v \u2218 f) :=\nbegin\n  classical,\n  rw orthonormal_iff_ite at \u22a2 hv,\n  intros i j,\n  convert hv (f i) (f j) using 1,\n  simp [hf.eq_iff]\nend\n\n/-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the\nset. -/\nlemma orthonormal.inner_finsupp_eq_zero\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) {s : set \u03b9} {i : \u03b9} (hi : i \u2209 s) {l : \u03b9 \u2192\u2080 \ud835\udd5c}\n  (hl : l \u2208 finsupp.supported \ud835\udd5c \ud835\udd5c s) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = 0 :=\nbegin\n  rw finsupp.mem_supported' at hl,\n  simp [hv.inner_left_finsupp, hl i hi],\nend\n\n/-- Given an orthonormal family, a second family of vectors is orthonormal if every vector equals\nthe corresponding vector in the original family or its negation. -/\nlemma orthonormal.orthonormal_of_forall_eq_or_eq_neg {v w : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v)\n  (hw : \u2200 i, w i = v i \u2228 w i = -(v i)) : orthonormal \ud835\udd5c w :=\nbegin\n  classical,\n  rw orthonormal_iff_ite at *,\n  intros i j,\n  cases hw i with hi hi; cases hw j with hj hj; split_ifs with h;\n    simpa [hi, hj, h] using hv i j\nend\n\n/- The material that follows, culminating in the existence of a maximal orthonormal subset, is\nadapted from the corresponding development of the theory of linearly independents sets.  See\n`exists_linear_independent` in particular. -/\n\nvariables (\ud835\udd5c E)\nlemma orthonormal_empty : orthonormal \ud835\udd5c (\u03bb x, x : (\u2205 : set E) \u2192 E) :=\nby classical; simp [orthonormal_subtype_iff_ite]\nvariables {\ud835\udd5c E}\n\nlemma orthonormal_Union_of_directed\n  {\u03b7 : Type*} {s : \u03b7 \u2192 set E} (hs : directed (\u2286) s) (h : \u2200 i, orthonormal \ud835\udd5c (\u03bb x, x : s i \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3 i, s i) \u2192 E) :=\nbegin\n  classical,\n  rw orthonormal_subtype_iff_ite,\n  rintros x \u27e8_, \u27e8i, rfl\u27e9, hxi\u27e9 y \u27e8_, \u27e8j, rfl\u27e9, hyj\u27e9,\n  obtain \u27e8k, hik, hjk\u27e9 := hs i j,\n  have h_orth : orthonormal \ud835\udd5c (\u03bb x, x : (s k) \u2192 E) := h k,\n  rw orthonormal_subtype_iff_ite at h_orth,\n  exact h_orth x (hik hxi) y (hjk hyj)\nend\n\nlemma orthonormal_sUnion_of_directed\n  {s : set (set E)} (hs : directed_on (\u2286) s)\n  (h : \u2200 a \u2208 s, orthonormal \ud835\udd5c (\u03bb x, x : (a : set E) \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3\u2080 s) \u2192 E) :=\nby rw set.sUnion_eq_Union; exact orthonormal_Union_of_directed hs.directed_coe (by simpa using h)\n\n/-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set\ncontaining it. -/\nlemma exists_maximal_orthonormal {s : set E} (hs : orthonormal \ud835\udd5c (coe : s \u2192 E)) :\n  \u2203 w \u2287 s, orthonormal \ud835\udd5c (coe : w \u2192 E) \u2227 \u2200 u \u2287 w, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2192 u = w :=\nbegin\n  rcases zorn.zorn_subset_nonempty {b | orthonormal \ud835\udd5c (coe : b \u2192 E)} _ _ hs  with \u27e8b, bi, sb, h\u27e9,\n  { refine \u27e8b, sb, bi, _\u27e9,\n    exact \u03bb u hus hu, h u hu hus },\n  { refine \u03bb c hc cc c0, \u27e8\u22c3\u2080 c, _, _\u27e9,\n    { exact orthonormal_sUnion_of_directed cc.directed_on (\u03bb x xc, hc xc) },\n    { exact \u03bb _, set.subset_sUnion_of_mem } }\nend\n\nlemma orthonormal.ne_zero {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (i : \u03b9) : v i \u2260 0 :=\nbegin\n  have : \u2225v i\u2225 \u2260 0,\n  { rw hv.1 i,\n    norm_num },\n  simpa using this\nend\n\nopen finite_dimensional\n\n/-- A family of orthonormal vectors with the correct cardinality forms a basis. -/\ndef basis_of_orthonormal_of_card_eq_finrank [fintype \u03b9] [nonempty \u03b9] {v : \u03b9 \u2192 E}\n  (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finrank \ud835\udd5c E) :\n  basis \u03b9 \ud835\udd5c E :=\nbasis_of_linear_independent_of_card_eq_finrank hv.linear_independent card_eq\n\n@[simp] lemma coe_basis_of_orthonormal_of_card_eq_finrank [fintype \u03b9] [nonempty \u03b9] {v : \u03b9 \u2192 E}\n  (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finrank \ud835\udd5c E) :\n  (basis_of_orthonormal_of_card_eq_finrank hv card_eq : \u03b9 \u2192 E) = v :=\ncoe_basis_of_linear_independent_of_card_eq_finrank _ _\n\nend orthonormal_sets\n\nsection norm\n\nlemma norm_eq_sqrt_inner (x : E) : \u2225x\u2225 = sqrt (re \u27eax, x\u27eb) :=\nbegin\n  have h\u2081 : \u2225x\u2225^2 = re \u27eax, x\u27eb := norm_sq_eq_inner x,\n  have h\u2082 := congr_arg sqrt h\u2081,\n  simpa using h\u2082,\nend\n\nlemma norm_eq_sqrt_real_inner (x : F) : \u2225x\u2225 = sqrt \u27eax, x\u27eb_\u211d :=\nby { have h := @norm_eq_sqrt_inner \u211d F _ _ x, simpa using h }\n\nlemma inner_self_eq_norm_mul_norm (x : E) : re \u27eax, x\u27eb = \u2225x\u2225 * \u2225x\u2225 :=\nby rw [norm_eq_sqrt_inner, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma inner_self_eq_norm_sq (x : E) : re \u27eax, x\u27eb = \u2225x\u2225^2 :=\nby rw [pow_two, inner_self_eq_norm_mul_norm]\n\nlemma real_inner_self_eq_norm_mul_norm (x : F) : \u27eax, x\u27eb_\u211d = \u2225x\u2225 * \u2225x\u2225 :=\nby { have h := @inner_self_eq_norm_mul_norm \u211d F _ _ x, simpa using h }\n\nlemma real_inner_self_eq_norm_sq (x : F) : \u27eax, x\u27eb_\u211d = \u2225x\u2225^2 :=\nby rw [pow_two, real_inner_self_eq_norm_mul_norm]\n\n/-- Expand the square -/\nlemma norm_add_sq {x y : E} : \u2225x + y\u2225^2 = \u2225x\u2225^2 + 2 * (re \u27eax, y\u27eb) + \u2225y\u2225^2 :=\nbegin\n  repeat {rw [sq, \u2190inner_self_eq_norm_mul_norm]},\n  rw [inner_add_add_self, two_mul],\n  simp only [add_assoc, add_left_inj, add_right_inj, add_monoid_hom.map_add],\n  rw [\u2190inner_conj_sym, conj_re],\nend\n\nalias norm_add_sq \u2190 norm_add_pow_two\n\n/-- Expand the square -/\nlemma norm_add_sq_real {x y : F} : \u2225x + y\u2225^2 = \u2225x\u2225^2 + 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225^2 :=\nby { have h := @norm_add_sq \u211d F _ _, simpa using h }\n\nalias norm_add_sq_real \u2190 norm_add_pow_two_real\n\n/-- Expand the square -/\nlemma norm_add_mul_self {x y : E} : \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + 2 * (re \u27eax, y\u27eb) + \u2225y\u2225 * \u2225y\u2225 :=\nby { repeat {rw [\u2190 sq]}, exact norm_add_sq }\n\n/-- Expand the square -/\nlemma norm_add_mul_self_real {x y : F} : \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225 * \u2225y\u2225 :=\nby { have h := @norm_add_mul_self \u211d F _ _, simpa using h }\n\n/-- Expand the square -/\nlemma norm_sub_sq {x y : E} : \u2225x - y\u2225^2 = \u2225x\u2225^2 - 2 * (re \u27eax, y\u27eb) + \u2225y\u2225^2 :=\nbegin\n  repeat {rw [sq, \u2190inner_self_eq_norm_mul_norm]},\n  rw [inner_sub_sub_self],\n  calc\n    re (\u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb)\n        = re \u27eax, x\u27eb - re \u27eax, y\u27eb - re \u27eay, x\u27eb + re \u27eay, y\u27eb  : by simp\n    ... = -re \u27eay, x\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb  : by ring\n    ... = -re (\u27eax, y\u27eb\u2020) - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw [inner_conj_sym]\n    ... = -re \u27eax, y\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw [conj_re]\n    ... = re \u27eax, x\u27eb - 2*re \u27eax, y\u27eb + re \u27eay, y\u27eb : by ring\nend\n\nalias norm_sub_sq \u2190 norm_sub_pow_two\n\n/-- Expand the square -/\nlemma norm_sub_sq_real {x y : F} : \u2225x - y\u2225^2 = \u2225x\u2225^2 - 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225^2 :=\nnorm_sub_sq\n\nalias norm_sub_sq_real \u2190 norm_sub_pow_two_real\n\n/-- Expand the square -/\nlemma norm_sub_mul_self {x y : E} : \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 - 2 * re \u27eax, y\u27eb + \u2225y\u2225 * \u2225y\u2225 :=\nby { repeat {rw [\u2190 sq]}, exact norm_sub_sq }\n\n/-- Expand the square -/\nlemma norm_sub_mul_self_real {x y : F} : \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 - 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225 * \u2225y\u2225 :=\nby { have h := @norm_sub_mul_self \u211d F _ _, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : E) : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _))\nbegin\n  have : \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225) = (re \u27eax, x\u27eb) * (re \u27eay, y\u27eb),\n    simp only [inner_self_eq_norm_mul_norm], ring,\n  rw this,\n  conv_lhs { congr, skip, rw [inner_abs_conj_sym] },\n  exact inner_mul_inner_self_le _ _\nend\n\nlemma norm_inner_le_norm (x y : E) : \u2225\u27eax, y\u27eb\u2225 \u2264 \u2225x\u2225 * \u2225y\u2225 :=\n(is_R_or_C.norm_eq_abs _).le.trans (abs_inner_le_norm x y)\n\nlemma re_inner_le_norm (x y : E) : re \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nle_trans (re_le_abs (inner x y)) (abs_inner_le_norm x y)\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_real_inner_le_norm (x y : F) : absR \u27eax, y\u27eb_\u211d \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nby { have h := @abs_inner_le_norm \u211d F _ _ x y, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma real_inner_le_norm (x y : F) : \u27eax, y\u27eb_\u211d \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nle_trans (le_abs_self _) (abs_real_inner_le_norm _ _)\n\ninclude \ud835\udd5c\nlemma parallelogram_law_with_norm {x y : E} :\n  \u2225x + y\u2225 * \u2225x + y\u2225 + \u2225x - y\u2225 * \u2225x - y\u2225 = 2 * (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225) :=\nbegin\n  simp only [\u2190 inner_self_eq_norm_mul_norm],\n  rw [\u2190 re.map_add, parallelogram_law, two_mul, two_mul],\n  simp only [re.map_add],\nend\nomit \ud835\udd5c\n\nlemma parallelogram_law_with_norm_real {x y : F} :\n  \u2225x + y\u2225 * \u2225x + y\u2225 + \u2225x - y\u2225 * \u2225x - y\u2225 = 2 * (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225) :=\nby { have h := @parallelogram_law_with_norm \u211d F _ _ x y, simpa using h }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x\u2225 * \u2225x\u2225 - \u2225y\u2225 * \u2225y\u2225) / 2 :=\nby { rw norm_add_mul_self, ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 2 :=\nby { rw [norm_sub_mul_self], ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 4 :=\nby { rw [norm_add_mul_self, norm_sub_mul_self], ring }\n\n/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/\nlemma im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four (x y : E) :\n  im \u27eax, y\u27eb = (\u2225x - IK \u2022 y\u2225 * \u2225x - IK \u2022 y\u2225 - \u2225x + IK \u2022 y\u2225 * \u2225x + IK \u2022 y\u2225) / 4 :=\nby { simp only [norm_add_mul_self, norm_sub_mul_self, inner_smul_right, I_mul_re], ring }\n\n/-- Polarization identity: The inner product, in terms of the norm. -/\nlemma inner_eq_sum_norm_sq_div_four (x y : E) :\n  \u27eax, y\u27eb = (\u2225x + y\u2225 ^ 2 - \u2225x - y\u2225 ^ 2 + (\u2225x - IK \u2022 y\u2225 ^ 2 - \u2225x + IK \u2022 y\u2225 ^ 2) * IK) / 4 :=\nbegin\n  rw [\u2190 re_add_im \u27eax, y\u27eb, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,\n    im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four],\n  push_cast,\n  simp only [sq, \u2190 mul_div_right_comm, \u2190 add_div]\nend\n\nsection\n\nvariables {\u03b9 : Type*} {\u03b9' : Type*} {\u03b9'' : Type*}\nvariables {E' : Type*} [inner_product_space \ud835\udd5c E']\nvariables {E'' : Type*} [inner_product_space \ud835\udd5c E'']\n\n/-- A linear isometry preserves the inner product. -/\n@[simp] lemma linear_isometry.inner_map_map (f : E \u2192\u2097\u1d62[\ud835\udd5c] E') (x y : E) : \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nby simp [inner_eq_sum_norm_sq_div_four, \u2190 f.norm_map]\n\n/-- A linear isometric equivalence preserves the inner product. -/\n@[simp] lemma linear_isometry_equiv.inner_map_map (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') (x y : E) :\n  \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nf.to_linear_isometry.inner_map_map x y\n\n/-- A linear map that preserves the inner product is a linear isometry. -/\ndef linear_map.isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) : E \u2192\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, \u03bb x, by simp only [norm_eq_sqrt_inner, h]\u27e9\n\n@[simp] lemma linear_map.coe_isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_map.isometry_of_inner_to_linear_map (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_map = f := rfl\n\n/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/\ndef linear_equiv.isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, ((f : E \u2192\u2097[\ud835\udd5c] E').isometry_of_inner h).norm_map\u27e9\n\n@[simp] lemma linear_equiv.coe_isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_equiv.isometry_of_inner_to_linear_equiv (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_equiv = f := rfl\n\n/-- A linear isometry preserves the property of being orthonormal. -/\nlemma orthonormal.comp_linear_isometry {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : E \u2192\u2097\u1d62[\ud835\udd5c] E') :\n  orthonormal \ud835\udd5c (f \u2218 v) :=\nbegin\n  classical,\n  simp_rw [orthonormal_iff_ite, linear_isometry.inner_map_map, \u2190orthonormal_iff_ite],\n  exact hv\nend\n\n/-- A linear isometric equivalence preserves the property of being orthonormal. -/\nlemma orthonormal.comp_linear_isometry_equiv {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') :\n  orthonormal \ud835\udd5c (f \u2218 v) :=\nhv.comp_linear_isometry f.to_linear_isometry\n\n/-- A linear map that sends an orthonormal basis to orthonormal vectors is a linear isometry. -/\ndef linear_map.isometry_of_orthonormal (f : E \u2192\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  (hf : orthonormal \ud835\udd5c (f \u2218 v)) : E \u2192\u2097\u1d62[\ud835\udd5c] E' :=\nf.isometry_of_inner $ \u03bb x y, by rw [\u2190v.total_repr x, \u2190v.total_repr y, finsupp.apply_total,\n                                    finsupp.apply_total, hv.inner_finsupp_eq_sum_left,\n                                    hf.inner_finsupp_eq_sum_left]\n\n@[simp] lemma linear_map.coe_isometry_of_orthonormal (f : E \u2192\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E}\n  (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  \u21d1(f.isometry_of_orthonormal hv hf) = f :=\nrfl\n\n@[simp] lemma linear_map.isometry_of_orthonormal_to_linear_map (f : E \u2192\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E}\n  (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  (f.isometry_of_orthonormal hv hf).to_linear_map = f :=\nrfl\n\n/-- A linear equivalence that sends an orthonormal basis to orthonormal vectors is a linear\nisometric equivalence. -/\ndef linear_equiv.isometry_of_orthonormal (f : E \u2243\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  (hf : orthonormal \ud835\udd5c (f \u2218 v)) : E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\nf.isometry_of_inner $ \u03bb x y, begin\n  rw \u2190linear_equiv.coe_coe at hf,\n  rw [\u2190v.total_repr x, \u2190v.total_repr y, \u2190linear_equiv.coe_coe, finsupp.apply_total,\n      finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left]\nend\n\n@[simp] lemma linear_equiv.coe_isometry_of_orthonormal (f : E \u2243\u2097[\ud835\udd5c] E') {v : basis \u03b9 \ud835\udd5c E}\n  (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  \u21d1(f.isometry_of_orthonormal hv hf) = f :=\nrfl\n\n@[simp] lemma linear_equiv.isometry_of_orthonormal_to_linear_equiv (f : E \u2243\u2097[\ud835\udd5c] E')\n  {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) (hf : orthonormal \ud835\udd5c (f \u2218 v)) :\n  (f.isometry_of_orthonormal hv hf).to_linear_equiv = f :=\nrfl\n\n/-- A linear isometric equivalence that sends an orthonormal basis to a given orthonormal basis. -/\ndef orthonormal.equiv {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') : E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\n(v.equiv v' e).isometry_of_orthonormal hv begin\n  have h : (v.equiv v' e) \u2218 v = v' \u2218 e,\n  { ext i,\n    simp },\n  rw h,\n  exact hv'.comp _ e.injective\nend\n\n@[simp] lemma orthonormal.equiv_to_linear_equiv {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  {v' : basis \u03b9' \ud835\udd5c E'} (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') :\n  (hv.equiv hv' e).to_linear_equiv = v.equiv v' e :=\nrfl\n\n@[simp] lemma orthonormal.equiv_apply {\u03b9' : Type*} {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v)\n  {v' : basis \u03b9' \ud835\udd5c E'} (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') (i : \u03b9) :\n  hv.equiv hv' e (v i) = v' (e i) :=\nbasis.equiv_apply _ _ _ _\n\n@[simp] lemma orthonormal.equiv_refl {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) :\n  hv.equiv hv (equiv.refl \u03b9) = linear_isometry_equiv.refl \ud835\udd5c E :=\nv.ext_linear_isometry_equiv $ \u03bb i, by simp\n\n@[simp] lemma orthonormal.equiv_symm {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') : (hv.equiv hv' e).symm = hv'.equiv hv e.symm :=\nv'.ext_linear_isometry_equiv $ \u03bb i, (hv.equiv hv' e).injective (by simp)\n\n@[simp] lemma orthonormal.equiv_trans {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') {v'' : basis \u03b9'' \ud835\udd5c E''} (hv'' : orthonormal \ud835\udd5c v'')\n  (e' : \u03b9' \u2243 \u03b9'') : (hv.equiv hv' e).trans (hv'.equiv hv'' e') = hv.equiv hv'' (e.trans e') :=\nv.ext_linear_isometry_equiv $ \u03bb i, by simp\n\nlemma orthonormal.map_equiv {v : basis \u03b9 \ud835\udd5c E} (hv : orthonormal \ud835\udd5c v) {v' : basis \u03b9' \ud835\udd5c E'}\n  (hv' : orthonormal \ud835\udd5c v') (e : \u03b9 \u2243 \u03b9') :\n  v.map ((hv.equiv hv' e).to_linear_equiv) = v'.reindex e.symm :=\nv.map_equiv _ _\n\nend\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x\u2225 * \u2225x\u2225 - \u2225y\u2225 * \u2225y\u2225) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y\n\n/-- Pythagorean theorem, if-and-only-if vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [norm_add_mul_self, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : \u27eax, y\u27eb = 0) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\nbegin\n  rw [norm_add_mul_self, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  apply or.inr,\n  simp only [h, zero_re'],\nend\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\n(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector\ninner product form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [norm_sub_mul_self, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero,\n      mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, subtracting vectors, vector inner product\nform. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\n(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- The sum and difference of two vectors are orthogonal if and only\nif they have the same norm. -/\nlemma real_inner_add_sub_eq_zero_iff (x y : F) : \u27eax + y, x - y\u27eb_\u211d = 0 \u2194 \u2225x\u2225 = \u2225y\u2225 :=\nbegin\n  conv_rhs { rw \u2190mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _) },\n  simp only [\u2190inner_self_eq_norm_mul_norm, inner_add_left, inner_sub_right,\n            real_inner_comm y x, sub_eq_zero, re_to_real],\n  split,\n  { intro h,\n    rw [add_comm] at h,\n    linarith },\n  { intro h,\n    linarith }\nend\n\n/-- Given two orthogonal vectors, their sum and difference have equal norms. -/\nlemma norm_sub_eq_norm_add {v w : E} (h : \u27eav, w\u27eb = 0) : \u2225w - v\u2225 = \u2225w + v\u2225 :=\nbegin\n  rw \u2190mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _),\n  simp [h, \u2190inner_self_eq_norm_mul_norm, inner_add_left, inner_add_right, inner_sub_left,\n    inner_sub_right, inner_re_symm]\nend\n\n/-- The real inner product of two vectors, divided by the product of their\nnorms, has absolute value at most 1. -/\nlemma abs_real_inner_div_norm_mul_norm_le_one (x y : F) : absR (\u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225)) \u2264 1 :=\nbegin\n  rw _root_.abs_div,\n  by_cases h : 0 = absR (\u2225x\u2225 * \u2225y\u2225),\n  { rw [\u2190h, div_zero],\n    norm_num },\n  { change 0 \u2260 absR (\u2225x\u2225 * \u2225y\u2225) at h,\n    rw div_le_iff' (lt_of_le_of_ne (ge_iff_le.mp (_root_.abs_nonneg (\u2225x\u2225 * \u2225y\u2225))) h),\n    convert abs_real_inner_le_norm x y using 1,\n    rw [_root_.abs_mul, _root_.abs_of_nonneg (norm_nonneg x), _root_.abs_of_nonneg (norm_nonneg y),\n        mul_one] }\nend\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_left (x : F) (r : \u211d) : \u27ear \u2022 x, x\u27eb_\u211d = r * (\u2225x\u2225 * \u2225x\u2225) :=\nby rw [real_inner_smul_left, \u2190real_inner_self_eq_norm_mul_norm]\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_right (x : F) (r : \u211d) : \u27eax, r \u2022 x\u27eb_\u211d = r * (\u2225x\u2225 * \u2225x\u2225) :=\nby rw [inner_smul_right, \u2190real_inner_self_eq_norm_mul_norm]\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : E} {r : \ud835\udd5c} (hx : x \u2260 0) (hr : r \u2260 0) : abs \u27eax, r \u2022 x\u27eb / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  have hx' : \u2225x\u2225 \u2260 0 := by simp [norm_eq_zero, hx],\n  have hr' : abs r \u2260 0 := by simp [is_R_or_C.abs_eq_zero, hr],\n  rw [inner_smul_right, is_R_or_C.abs_mul, \u2190inner_self_re_abs, inner_self_eq_norm_mul_norm,\n      norm_smul],\n  rw [is_R_or_C.norm_eq_abs, \u2190mul_assoc, \u2190div_div_eq_div_mul, mul_div_cancel _ hx',\n     \u2190div_div_eq_div_mul, mul_comm, mul_div_cancel _ hr', div_self hx'],\nend\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r \u2260 0) : absR \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  rw \u2190 abs_to_real,\n  exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr\nend\n\n/-- The inner product of a nonzero vector with a positive multiple of\nitself, divided by the product of their norms, has value 1. -/\nlemma real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : 0 < r) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2225x\u2225, mul_comm _ (absR r),\n      mul_assoc, _root_.abs_of_nonneg (le_of_lt hr), div_self],\n  exact mul_ne_zero (ne_of_gt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of a nonzero vector with a negative multiple of\nitself, divided by the product of their norms, has value -1. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r < 0) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = -1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2225x\u2225, mul_comm _ (absR r),\n      mul_assoc, abs_of_neg hr, \u2190neg_mul_eq_neg_mul, div_neg_eq_neg_div, div_self],\n  exact mul_ne_zero (ne_of_lt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_iff (x y : E) :\n  abs (\u27eax, y\u27eb / (\u2225x\u2225 * \u2225y\u2225)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have hx0 : x \u2260 0,\n    { intro hx0,\n      rw [hx0, inner_zero_left, zero_div] at h,\n      norm_num at h, },\n    refine and.intro hx0 _,\n    set r := \u27eax, y\u27eb / (\u2225x\u2225 * \u2225x\u2225) with hr,\n    use r,\n    set t := y - r \u2022 x with ht,\n    have ht0 : \u27eax, t\u27eb = 0,\n    { rw [ht, inner_sub_right, inner_smul_right, hr],\n      norm_cast,\n      rw [\u2190inner_self_eq_norm_mul_norm, inner_self_re_to_K,\n          div_mul_cancel _ (\u03bb h, hx0 (inner_self_eq_zero.1 h)), sub_self] },\n    replace h : \u2225r \u2022 x\u2225 / \u2225t + r \u2022 x\u2225 = 1,\n    { rw [\u2190sub_add_cancel y (r \u2022 x), \u2190ht, inner_add_right, ht0, zero_add, inner_smul_right,\n        is_R_or_C.abs_div, is_R_or_C.abs_mul, \u2190inner_self_re_abs,\n        inner_self_eq_norm_mul_norm] at h,\n      norm_cast at h,\n      rwa [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm, \u2190mul_assoc, mul_comm,\n        mul_div_mul_left _ _ (\u03bb h, hx0 (norm_eq_zero.1 h)), \u2190is_R_or_C.norm_eq_abs,\n        \u2190norm_smul] at h },\n    have hr0 : r \u2260 0,\n    { intro hr0,\n      rw [hr0, zero_smul, norm_zero, zero_div] at h,\n      norm_num at h },\n    refine and.intro hr0 _,\n    have h2 : \u2225r \u2022 x\u2225 ^ 2 = \u2225t + r \u2022 x\u2225 ^ 2,\n    { rw [eq_of_div_eq_one h] },\n    replace h2 : \u27ear \u2022 x, r \u2022 x\u27eb = \u27eat, t\u27eb + \u27eat, r \u2022 x\u27eb + \u27ear \u2022 x, t\u27eb + \u27ear \u2022 x, r \u2022 x\u27eb,\n    { rw [sq, sq, \u2190inner_self_eq_norm_mul_norm, \u2190inner_self_eq_norm_mul_norm ] at h2,\n      have h2' := congr_arg (\u03bb z : \u211d, (z : \ud835\udd5c)) h2,\n      simp_rw [inner_self_re_to_K, inner_add_add_self] at h2',\n      exact h2' },\n    conv at h2 in \u27ear \u2022 x, t\u27eb { rw [inner_smul_left, ht0, mul_zero] },\n    symmetry' at h2,\n    have h\u2081 : \u27eat, r \u2022 x\u27eb = 0 := by { rw [inner_smul_right, \u2190inner_conj_sym, ht0], simp },\n    rw [add_zero, h\u2081, add_left_eq_self, add_zero, inner_self_eq_zero] at h2,\n    rw h2 at ht,\n    exact eq_of_sub_eq_zero ht.symm },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw [hy, is_R_or_C.abs_div],\n    norm_cast,\n    rw [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm],\n    exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  absR (\u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  have := @abs_inner_div_norm_mul_norm_eq_one_iff \u211d F _ _ x y,\n  simpa [coe_real_eq_id] using this,\nend\n\n/--\nIf the inner product of two vectors is equal to the product of their norms, then the two vectors\nare multiples of each other. One form of the equality case for Cauchy-Schwarz.\nCompare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma abs_inner_eq_norm_iff (x y : E) (hx0 : x \u2260 0) (hy0 : y \u2260 0):\n  abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225 \u2194 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x :=\nbegin\n  have hx0' : \u2225x\u2225 \u2260 0 := by simp [norm_eq_zero, hx0],\n  have hy0' : \u2225y\u2225 \u2260 0 := by simp [norm_eq_zero, hy0],\n  have hxy0 : \u2225x\u2225 * \u2225y\u2225 \u2260 0 := by simp [hx0', hy0'],\n  have h\u2081 : abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225 \u2194 abs (\u27eax, y\u27eb / (\u2225x\u2225 * \u2225y\u2225)) = 1,\n  { refine \u27e8_ ,_\u27e9,\n    { intro h,\n      norm_cast,\n      rw [is_R_or_C.abs_div, h, abs_of_real, _root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm],\n      exact div_self hxy0 },\n    { intro h,\n      norm_cast at h,\n      rwa [is_R_or_C.abs_div, abs_of_real, _root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm,\n          div_eq_one_iff_eq hxy0] at h } },\n  rw [h\u2081, abs_inner_div_norm_mul_norm_eq_one_iff x y],\n  have : x \u2260 0 := \u03bb h, (hx0' $ norm_eq_zero.mpr h),\n  simp [this]\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value 1 if and only if they are nonzero and one is\na positive multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), 0 < r \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrneg,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrneg) hr) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value -1 if and only if they are nonzero and one is\na negative multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225) = -1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r < 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrpos,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrpos) hr.symm) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx hr }\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma inner_eq_norm_mul_iff {x y : E} :\n  \u27eax, y\u27eb = (\u2225x\u2225 : \ud835\udd5c) * \u2225y\u2225 \u2194 (\u2225y\u2225 : \ud835\udd5c) \u2022 x = (\u2225x\u2225 : \ud835\udd5c) \u2022 y :=\nbegin\n  by_cases h : (x = 0 \u2228 y = 0), -- WLOG `x` and `y` are nonzero\n  { cases h; simp [h] },\n  calc \u27eax, y\u27eb = (\u2225x\u2225 : \ud835\udd5c) * \u2225y\u2225 \u2194 \u2225x\u2225 * \u2225y\u2225 = re \u27eax, y\u27eb :\n  begin\n    norm_cast,\n    split,\n    { intros h',\n      simp [h'] },\n    { have cauchy_schwarz := abs_inner_le_norm x y,\n      intros h',\n      rw h' at \u22a2 cauchy_schwarz,\n      rwa re_eq_self_of_le }\n  end\n  ... \u2194 2 * \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225 - re \u27eax, y\u27eb) = 0 :\n    by simp [h, show (2:\u211d) \u2260 0, by norm_num, sub_eq_zero]\n  ... \u2194 \u2225(\u2225y\u2225:\ud835\udd5c) \u2022 x - (\u2225x\u2225:\ud835\udd5c) \u2022 y\u2225 * \u2225(\u2225y\u2225:\ud835\udd5c) \u2022 x - (\u2225x\u2225:\ud835\udd5c) \u2022 y\u2225 = 0 :\n  begin\n    simp only [norm_sub_mul_self, inner_smul_left, inner_smul_right, norm_smul, conj_of_real,\n      is_R_or_C.norm_eq_abs, abs_of_real, of_real_im, of_real_re, mul_re, abs_norm_eq_norm],\n    refine eq.congr _ rfl,\n    ring\n  end\n  ... \u2194 (\u2225y\u2225 : \ud835\udd5c) \u2022 x = (\u2225x\u2225 : \ud835\udd5c) \u2022 y : by simp [norm_sub_eq_zero_iff]\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma inner_eq_norm_mul_iff_real {x y : F} : \u27eax, y\u27eb_\u211d = \u2225x\u2225 * \u2225y\u2225 \u2194 \u2225y\u2225 \u2022 x = \u2225x\u2225 \u2022 y :=\ninner_eq_norm_mul_iff\n\n/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of\nthe equality case for Cauchy-Schwarz. -/\nlemma inner_eq_norm_mul_iff_of_norm_one {x y : E} (hx : \u2225x\u2225 = 1) (hy : \u2225y\u2225 = 1) :\n  \u27eax, y\u27eb = 1 \u2194 x = y :=\nby { convert inner_eq_norm_mul_iff using 2; simp [hx, hy] }\n\nlemma inner_lt_norm_mul_iff_real {x y : F} :\n  \u27eax, y\u27eb_\u211d < \u2225x\u2225 * \u2225y\u2225 \u2194 \u2225y\u2225 \u2022 x \u2260 \u2225x\u2225 \u2022 y :=\ncalc \u27eax, y\u27eb_\u211d < \u2225x\u2225 * \u2225y\u2225\n    \u2194 \u27eax, y\u27eb_\u211d \u2260 \u2225x\u2225 * \u2225y\u2225 : \u27e8ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)\u27e9\n... \u2194 \u2225y\u2225 \u2022 x \u2260 \u2225x\u2225 \u2022 y : not_congr inner_eq_norm_mul_iff_real\n\n/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are\ndistinct. One form of the equality case for Cauchy-Schwarz. -/\nlemma inner_lt_one_iff_real_of_norm_one {x y : F} (hx : \u2225x\u2225 = 1) (hy : \u2225y\u2225 = 1) :\n  \u27eax, y\u27eb_\u211d < 1 \u2194 x \u2260 y :=\nby { convert inner_lt_norm_mul_iff_real; simp [hx, hy] }\n\n/-- The inner product of two weighted sums, where the weights in each\nsum add to 0, in terms of the norms of pairwise differences. -/\nlemma inner_sum_smul_sum_smul_of_sum_eq_zero {\u03b9\u2081 : Type*} {s\u2081 : finset \u03b9\u2081} {w\u2081 : \u03b9\u2081 \u2192 \u211d}\n    (v\u2081 : \u03b9\u2081 \u2192 F) (h\u2081 : \u2211 i in s\u2081, w\u2081 i = 0) {\u03b9\u2082 : Type*} {s\u2082 : finset \u03b9\u2082} {w\u2082 : \u03b9\u2082 \u2192 \u211d}\n    (v\u2082 : \u03b9\u2082 \u2192 F) (h\u2082 : \u2211 i in s\u2082, w\u2082 i = 0) :\n  \u27ea(\u2211 i\u2081 in s\u2081, w\u2081 i\u2081 \u2022 v\u2081 i\u2081), (\u2211 i\u2082 in s\u2082, w\u2082 i\u2082 \u2022 v\u2082 i\u2082)\u27eb_\u211d =\n    (-\u2211 i\u2081 in s\u2081, \u2211 i\u2082 in s\u2082, w\u2081 i\u2081 * w\u2082 i\u2082 * (\u2225v\u2081 i\u2081 - v\u2082 i\u2082\u2225 * \u2225v\u2081 i\u2081 - v\u2082 i\u2082\u2225)) / 2 :=\nby simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,\n            real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two,\n            \u2190div_sub_div_same, \u2190div_add_div_same, mul_sub_left_distrib, left_distrib,\n            finset.sum_sub_distrib, finset.sum_add_distrib, \u2190finset.mul_sum, \u2190finset.sum_mul,\n            h\u2081, h\u2082, zero_mul, mul_zero, finset.sum_const_zero, zero_add, zero_sub, finset.mul_sum,\n            neg_div, finset.sum_div, mul_div_assoc, mul_assoc]\n\n/-- The inner product as a sesquilinear map. -/\ndef inner\u209b\u2097 : E \u2192\u2097\u22c6[\ud835\udd5c] E \u2192\u2097[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk\u2082'\u209b\u2097 _ _ (\u03bb v w, \u27eav, w\u27eb) (\u03bb _ _ _, inner_add_left) (\u03bb _ _ _, inner_smul_left)\n(\u03bb _ _ _, inner_add_right) (\u03bb _ _ _, inner_smul_right)\n\n@[simp] lemma inner\u209b\u2097_apply_coe (v : E) : (inner\u209b\u2097 v : E \u2192 \ud835\udd5c) = \u03bb w, \u27eav, w\u27eb := rfl\n\n@[simp] lemma inner\u209b\u2097_apply (v w : E) : inner\u209b\u2097 v w = \u27eav, w\u27eb := rfl\n\n/-- The inner product as a continuous sesquilinear map. Note that `to_dual_map` (resp. `to_dual`)\nin `inner_product_space.dual` is a version of this given as a linear isometry (resp. linear\nisometric equivalence). -/\ndef innerSL : E \u2192L\u22c6[\ud835\udd5c] E \u2192L[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk_continuous\u2082 inner\u209b\u2097 1\n(\u03bb x y, by simp only [norm_inner_le_norm, one_mul, inner\u209b\u2097_apply])\n\n@[simp] lemma innerSL_apply_coe (v : E) : (innerSL v : E \u2192 \ud835\udd5c) = \u03bb w, \u27eav, w\u27eb := rfl\n\n@[simp] lemma innerSL_apply (v w : E) : innerSL v w = \u27eav, w\u27eb := rfl\n\n/-- `innerSL` is an isometry. Note that the associated `linear_isometry` is defined in\n`inner_product_space.dual` as `to_dual_map`.  -/\n@[simp] lemma innerSL_apply_norm {x : E} : \u2225(innerSL x : E \u2192L[\ud835\udd5c] \ud835\udd5c)\u2225 = \u2225x\u2225 :=\nbegin\n  refine le_antisymm ((innerSL x).op_norm_le_bound (norm_nonneg _) (\u03bb y, norm_inner_le_norm _ _)) _,\n  cases eq_or_lt_of_le (norm_nonneg x) with h h,\n  { have : x = 0 := norm_eq_zero.mp (eq.symm h),\n    simp [this] },\n  { refine (mul_le_mul_right h).mp _,\n    calc \u2225x\u2225 * \u2225x\u2225 = \u2225x\u2225 ^ 2 : by ring\n    ... = re \u27eax, x\u27eb : norm_sq_eq_inner _\n    ... \u2264 abs \u27eax, x\u27eb : re_le_abs _\n    ... = \u2225innerSL x x\u2225 : by { rw [\u2190is_R_or_C.norm_eq_abs], refl }\n    ... \u2264 \u2225innerSL x\u2225 * \u2225x\u2225 : (innerSL x).le_op_norm _ }\nend\n\n/-- The inner product as a continuous sesquilinear map, with the two arguments flipped. -/\ndef innerSL_flip : E \u2192L[\ud835\udd5c] E \u2192L\u22c6[\ud835\udd5c] \ud835\udd5c :=\n@continuous_linear_map.flip\u2097\u1d62' \ud835\udd5c \ud835\udd5c \ud835\udd5c E E \ud835\udd5c _ _ _ _ _ _ _ _ _ (ring_hom.id \ud835\udd5c) (star_ring_end \ud835\udd5c) _ _\n  innerSL\n\n@[simp] lemma innerSL_flip_apply {x y : E} : innerSL_flip x y = \u27eay, x\u27eb := rfl\n\nnamespace continuous_linear_map\n\nvariables  {E' : Type*} [inner_product_space \ud835\udd5c E']\n\n/-- Given `f : E \u2192L[\ud835\udd5c] E'`, construct the continuous sesquilinear form `\u03bb x y, \u27eax, A y\u27eb`, given\nas a continuous linear map. -/\ndef to_sesq_form : (E \u2192L[\ud835\udd5c] E') \u2192L[\ud835\udd5c] E' \u2192L\u22c6[\ud835\udd5c] E \u2192L[\ud835\udd5c] \ud835\udd5c :=\n\u2191((continuous_linear_map.flip\u2097\u1d62' E E' \ud835\udd5c\n  (star_ring_end \ud835\udd5c) (ring_hom.id \ud835\udd5c)).to_continuous_linear_equiv) \u2218L\n(continuous_linear_map.compSL E E' (E' \u2192L\u22c6[\ud835\udd5c] \ud835\udd5c) (ring_hom.id \ud835\udd5c) (ring_hom.id \ud835\udd5c) innerSL_flip)\n\n@[simp] lemma to_sesq_form_apply_coe (f : E \u2192L[\ud835\udd5c] E') (x : E') :\n  to_sesq_form f x = (innerSL x).comp f := rfl\n\nlemma to_sesq_form_apply_norm_le {f : E \u2192L[\ud835\udd5c] E'} {v : E'} : \u2225to_sesq_form f v\u2225 \u2264 \u2225f\u2225 * \u2225v\u2225 :=\nbegin\n  refine op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _,\n  intro x,\n  have h\u2081 : \u2225f x\u2225 \u2264 \u2225f\u2225 * \u2225x\u2225 := le_op_norm _ _,\n  have h\u2082 := @norm_inner_le_norm \ud835\udd5c E' _ _ v (f x),\n  calc \u2225\u27eav, f x\u27eb\u2225 \u2264 \u2225v\u2225 * \u2225f x\u2225       :  h\u2082\n              ... \u2264 \u2225v\u2225 * (\u2225f\u2225 * \u2225x\u2225)  : mul_le_mul_of_nonneg_left h\u2081 (norm_nonneg v)\n              ... = \u2225f\u2225 * \u2225v\u2225 * \u2225x\u2225    : by ring,\nend\n\nend continuous_linear_map\n\n/-- When an inner product space `E` over `\ud835\udd5c` is considered as a real normed space, its inner\nproduct satisfies `is_bounded_bilinear_map`.\n\nIn order to state these results, we need a `normed_space \u211d E` instance. We will later establish\nsuch an instance by restriction-of-scalars, `inner_product_space.is_R_or_C_to_real \ud835\udd5c E`, but this\ninstance may be not definitionally equal to some other \u201cnatural\u201d instance. So, we assume\n`[normed_space \u211d E]`.\n-/\nlemma is_bounded_bilinear_map_inner [normed_space \u211d E] :\n  is_bounded_bilinear_map \u211d (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\n{ add_left := \u03bb _ _ _, inner_add_left,\n  smul_left := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r x, algebra_map_eq_of_real, inner_smul_real_left],\n  add_right := \u03bb _ _ _, inner_add_right,\n  smul_right := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r y, algebra_map_eq_of_real, inner_smul_real_right],\n  bound := \u27e81, zero_lt_one, \u03bb x y,\n    by { rw [one_mul], exact norm_inner_le_norm x y, }\u27e9 }\n\nend norm\n\nsection bessels_inequality\n\nvariables {\u03b9: Type*} (x : E) {v : \u03b9 \u2192 E}\n\n/-- Bessel's inequality for finite sums. -/\nlemma orthonormal.sum_inner_products_le {s : finset \u03b9} (hv : orthonormal \ud835\udd5c v) :\n  \u2211 i in s, \u2225\u27eav i, x\u27eb\u2225 ^ 2 \u2264 \u2225x\u2225 ^ 2 :=\nbegin\n  have h\u2082 : \u2211 i in s, \u2211 j in s, \u27eav i, x\u27eb * \u27eax, v j\u27eb * \u27eav j, v i\u27eb\n    = (\u2211 k in s, (\u27eav k, x\u27eb * \u27eax, v k\u27eb) : \ud835\udd5c),\n  { exact hv.inner_left_right_finset },\n  have h\u2083 : \u2200 z : \ud835\udd5c, re (z * conj (z)) = \u2225z\u2225 ^ 2,\n  { intro z,\n    simp only [mul_conj, norm_sq_eq_def'],\n    norm_cast, },\n  suffices hbf: \u2225x -  \u2211 i in s, \u27eav i, x\u27eb \u2022 (v i)\u2225 ^ 2 = \u2225x\u2225 ^ 2 - \u2211 i in s, \u2225\u27eav i, x\u27eb\u2225 ^ 2,\n  { rw [\u2190sub_nonneg, \u2190hbf],\n    simp only [norm_nonneg, pow_nonneg], },\n  rw [norm_sub_sq, sub_add],\n  simp only [inner_product_space.norm_sq_eq_inner, inner_sum],\n  simp only [sum_inner, two_mul, inner_smul_right, inner_conj_sym, \u2190mul_assoc, h\u2082, \u2190h\u2083,\n  inner_conj_sym, add_monoid_hom.map_sum, finset.mul_sum, \u2190finset.sum_sub_distrib, inner_smul_left,\n  add_sub_cancel'],\nend\n\n/-- Bessel's inequality. -/\nlemma orthonormal.tsum_inner_products_le (hv : orthonormal \ud835\udd5c v) :\n  \u2211' i, \u2225\u27eav i, x\u27eb\u2225 ^ 2 \u2264 \u2225x\u2225 ^ 2 :=\nbegin\n  refine tsum_le_of_sum_le' _ (\u03bb s, hv.sum_inner_products_le x),\n  simp only [norm_nonneg, pow_nonneg]\nend\n\n/-- The sum defined in Bessel's inequality is summable. -/\nlemma orthonormal.inner_products_summable (hv : orthonormal \ud835\udd5c v) : summable (\u03bb i, \u2225\u27eav i, x\u27eb\u2225 ^ 2) :=\nbegin\n  use \u2a06 s : finset \u03b9, \u2211 i in s, \u2225\u27eav i, x\u27eb\u2225 ^ 2,\n  apply has_sum_of_is_lub_of_nonneg,\n  { intro b,\n    simp only [norm_nonneg, pow_nonneg], },\n  { refine is_lub_csupr _,\n    use \u2225x\u2225 ^ 2,\n    rintro y \u27e8s, rfl\u27e9,\n    exact hv.sum_inner_products_le x }\nend\n\nend bessels_inequality\n\n/-- A field `\ud835\udd5c` satisfying `is_R_or_C` is itself a `\ud835\udd5c`-inner product space. -/\ninstance is_R_or_C.inner_product_space : inner_product_space \ud835\udd5c \ud835\udd5c :=\n{ inner := (\u03bb x y, (conj x) * y),\n  norm_sq_eq_inner := \u03bb x,\n    by { unfold inner, rw [mul_comm, mul_conj, of_real_re, norm_sq_eq_def'] },\n  conj_sym := \u03bb x y, by simp [mul_comm],\n  add_left := \u03bb x y z, by simp [inner, add_mul],\n  smul_left := \u03bb x y z, by simp [inner, mul_assoc] }\n\n@[simp] lemma is_R_or_C.inner_apply (x y : \ud835\udd5c) : \u27eax, y\u27eb = (conj x) * y := rfl\n\n/-! ### Inner product space structure on subspaces -/\n\n/-- Induced inner product on a submodule. -/\ninstance submodule.inner_product_space (W : submodule \ud835\udd5c E) : inner_product_space \ud835\udd5c W :=\n{ inner             := \u03bb x y, \u27ea(x:E), (y:E)\u27eb,\n  conj_sym          := \u03bb _ _, inner_conj_sym _ _ ,\n  norm_sq_eq_inner  := \u03bb _, norm_sq_eq_inner _,\n  add_left          := \u03bb _ _ _ , inner_add_left,\n  smul_left         := \u03bb _ _ _, inner_smul_left,\n  ..submodule.normed_space W }\n\n/-- The inner product on submodules is the same as on the ambient space. -/\n@[simp] lemma submodule.coe_inner (W : submodule \ud835\udd5c E) (x y : W) : \u27eax, y\u27eb = \u27ea(x:E), \u2191y\u27eb := rfl\n\n/-! ### Families of mutually-orthogonal subspaces of an inner product space -/\n\nsection orthogonal_family\nvariables {\u03b9 : Type*} [dec_\u03b9 : decidable_eq \u03b9] (\ud835\udd5c)\nopen_locale direct_sum\n\n/-- An indexed family of mutually-orthogonal subspaces of an inner product space `E`.\n\nThe simple way to express this concept would be as a condition on `V : \u03b9 \u2192 submodule \ud835\udd5c E`.  We\nWe instead implement it as a condition on a family of inner product spaces each equipped with an\nisometric embedding into `E`, thus making it a property of morphisms rather than subobjects.\n\nThis definition is less lightweight, but allows for better definitional properties when the inner\nproduct space structure on each of the submodules is important -- for example, when considering\ntheir Hilbert sum (`pi_lp V 2`).  For example, given an orthonormal set of vectors `v : \u03b9 \u2192 E`,\nwe have an associated orthogonal family of one-dimensional subspaces of `E`, which it is convenient\nto be able to discuss using `\u03b9 \u2192 \ud835\udd5c` rather than `\u03a0 i : \u03b9, span \ud835\udd5c (v i)`. -/\ndef orthogonal_family {G : \u03b9 \u2192 Type*} [\u03a0 i, inner_product_space \ud835\udd5c (G i)] (V : \u03a0 i, G i \u2192\u2097\u1d62[\ud835\udd5c] E) :\n  Prop :=\n\u2200 \u2983i j\u2984, i \u2260 j \u2192 \u2200 v : G i, \u2200 w : G j, \u27eaV i v, V j w\u27eb = 0\n\nvariables {\ud835\udd5c} {G : \u03b9 \u2192 Type*} [\u03a0 i, inner_product_space \ud835\udd5c (G i)] {V : \u03a0 i, G i \u2192\u2097\u1d62[\ud835\udd5c] E}\n  (hV : orthogonal_family \ud835\udd5c V) [dec_V : \u03a0 i (x : G i), decidable (x \u2260 0)]\n\nlemma orthonormal.orthogonal_family {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  @orthogonal_family \ud835\udd5c _ _ _ _ (\u03bb i : \u03b9, \ud835\udd5c) _\n    (\u03bb i, linear_isometry.to_span_singleton \ud835\udd5c E (hv.1 i)) :=\n\u03bb i j hij a b, by simp [inner_smul_left, inner_smul_right, hv.2 hij]\n\ninclude hV dec_\u03b9\nlemma orthogonal_family.eq_ite {i j : \u03b9} (v : G i) (w : G j) :\n  \u27eaV i v, V j w\u27eb = ite (i = j) \u27eaV i v, V j w\u27eb 0 :=\nbegin\n  split_ifs,\n  { refl },\n  { exact hV h v w }\nend\n\ninclude dec_V\nlemma orthogonal_family.inner_right_dfinsupp (l : \u2a01 i, G i) (i : \u03b9) (v : G i) :\n  \u27eaV i v, l.sum (\u03bb j, V j)\u27eb = \u27eav, l i\u27eb :=\ncalc \u27eaV i v, l.sum (\u03bb j, V j)\u27eb\n    = l.sum (\u03bb j, \u03bb w, \u27eaV i v, V j w\u27eb) : dfinsupp.inner_sum (\u03bb j, V j) l (V i v)\n... = l.sum (\u03bb j, \u03bb w, ite (i=j) \u27eaV i v, V j w\u27eb 0) :\n  congr_arg l.sum $ funext $ \u03bb j, funext $ hV.eq_ite v\n... = \u27eav, l i\u27eb :\nbegin\n  simp only [dfinsupp.sum, submodule.coe_inner, finset.sum_ite_eq, ite_eq_left_iff,\n    dfinsupp.mem_support_to_fun],\n  split_ifs with h h,\n  { simp },\n  { simp [of_not_not h] },\nend\nomit dec_\u03b9 dec_V\n\nlemma orthogonal_family.inner_right_fintype [fintype \u03b9] (l : \u03a0 i, G i) (i : \u03b9) (v : G i) :\n  \u27eaV i v, \u2211 j : \u03b9, V j (l j)\u27eb = \u27eav, l i\u27eb :=\nby classical;\ncalc \u27eaV i v, \u2211 j : \u03b9, V j (l j)\u27eb\n    = \u2211 j : \u03b9, \u27eaV i v, V j (l j)\u27eb: by rw inner_sum\n... = \u2211 j, ite (i = j) \u27eaV i v, V j (l j)\u27eb 0 :\n  congr_arg (finset.sum finset.univ) $ funext $ \u03bb j, (hV.eq_ite v (l j))\n... = \u27eav, l i\u27eb : by simp\n\nlemma orthogonal_family.inner_sum (l\u2081 l\u2082 : \u03a0 i, G i) (s : finset \u03b9) :\n  \u27ea\u2211 i in s, V i (l\u2081 i), \u2211 j in s, V j (l\u2082 j)\u27eb = \u2211 i in s, \u27eal\u2081 i, l\u2082 i\u27eb :=\nby classical;\ncalc \u27ea\u2211 i in s, V i (l\u2081 i), \u2211 j in s, V j (l\u2082 j)\u27eb\n    = \u2211 j in s, \u2211 i in s, \u27eaV i (l\u2081 i), V j (l\u2082 j)\u27eb : by simp [sum_inner, inner_sum]\n... = \u2211 j in s, \u2211 i in s, ite (i = j) \u27eaV i (l\u2081 i), V j (l\u2082 j)\u27eb 0 :\nbegin\n  congr' with i,\n  congr' with j,\n  apply hV.eq_ite,\nend\n... = \u2211 i in s, \u27eal\u2081 i, l\u2082 i\u27eb : by simp [finset.sum_ite_of_true]\n\nlemma orthogonal_family.norm_sum (l : \u03a0 i, G i) (s : finset \u03b9) :\n  \u2225\u2211 i in s, V i (l i)\u2225 ^ 2 = \u2211 i in s, \u2225l i\u2225 ^ 2 :=\nbegin\n  have : (\u2225\u2211 i in s, V i (l i)\u2225 ^ 2 : \ud835\udd5c) = \u2211 i in s, \u2225l i\u2225 ^ 2,\n  { simp [\u2190 inner_self_eq_norm_sq_to_K, hV.inner_sum] },\n  exact_mod_cast this,\nend\n\n/-- The composition of an orthogonal family of subspaces with an injective function is also an\northogonal family. -/\nlemma orthogonal_family.comp {\u03b3 : Type*} {f : \u03b3 \u2192 \u03b9} (hf : function.injective f) :\n  orthogonal_family \ud835\udd5c (\u03bb g : \u03b3, (V (f g) : G (f g) \u2192\u2097\u1d62[\ud835\udd5c] E)) :=\n\u03bb i j hij v w, hV (hf.ne hij) v w\n\nlemma orthogonal_family.orthonormal_sigma_orthonormal {\u03b1 : \u03b9 \u2192 Type*} {v_family : \u03a0 i, (\u03b1 i) \u2192 G i}\n  (hv_family : \u2200 i, orthonormal \ud835\udd5c (v_family i)) :\n  orthonormal \ud835\udd5c (\u03bb a : \u03a3 i, \u03b1 i, V a.1 (v_family a.1 a.2)) :=\nbegin\n  split,\n  { rintros \u27e8i, v\u27e9,\n    simpa using (hv_family i).1 v },\n  rintros \u27e8i, v\u27e9 \u27e8j, w\u27e9 hvw,\n  by_cases hij : i = j,\n  { subst hij,\n    have : v \u2260 w := by simpa using hvw,\n    simpa using (hv_family i).2 this },\n  { exact hV hij (v_family i v) (v_family j w) }\nend\n\ninclude dec_\u03b9\nlemma orthogonal_family.norm_sq_diff_sum (f : \u03a0 i, G i) (s\u2081 s\u2082 : finset \u03b9) :\n  \u2225\u2211 i in s\u2081, V i (f i) - \u2211 i in s\u2082, V i (f i)\u2225 ^ 2\n  = \u2211 i in s\u2081 \\ s\u2082, \u2225f i\u2225 ^ 2 + \u2211 i in s\u2082 \\ s\u2081, \u2225f i\u2225 ^ 2 :=\nbegin\n  rw [\u2190 finset.sum_sdiff_sub_sum_sdiff, sub_eq_add_neg, \u2190 finset.sum_neg_distrib],\n  let F : \u03a0 i, G i := \u03bb i, if i \u2208 s\u2081 then f i else - (f i),\n  have hF\u2081 : \u2200 i \u2208 s\u2081 \\ s\u2082, F i = f i := \u03bb i hi, if_pos (finset.sdiff_subset _ _ hi),\n  have hF\u2082 : \u2200 i \u2208 s\u2082 \\ s\u2081, F i = - f i := \u03bb i hi, if_neg (finset.mem_sdiff.mp hi).2,\n  have hF : \u2200 i, \u2225F i\u2225 = \u2225f i\u2225,\n  { intros i,\n    dsimp [F],\n    split_ifs;\n    simp, },\n  have : \u2225\u2211 i in s\u2081 \\ s\u2082, V i (F i) + \u2211 i in s\u2082 \\ s\u2081, V i (F i)\u2225 ^ 2 =\n    \u2211 i in s\u2081 \\ s\u2082, \u2225F i\u2225 ^ 2 + \u2211 i in s\u2082 \\ s\u2081, \u2225F i\u2225 ^ 2,\n  { have hs : disjoint (s\u2081 \\ s\u2082) (s\u2082 \\ s\u2081) := disjoint_sdiff_sdiff,\n    simpa only [finset.sum_union hs] using hV.norm_sum F (s\u2081 \\ s\u2082 \u222a s\u2082 \\ s\u2081) },\n  convert this using 4,\n  { refine finset.sum_congr rfl (\u03bb i hi, _),\n    simp [hF\u2081 i hi] },\n  { refine finset.sum_congr rfl (\u03bb i hi, _),\n    simp [hF\u2082 i hi] },\n  { simp [hF] },\n  { simp [hF] },\nend\n\nomit dec_\u03b9\n\n/-- A family `f` of mutually-orthogonal elements of `E` is summable, if and only if\n`(\u03bb i, \u2225f i\u2225 ^ 2)` is summable. -/\nlemma orthogonal_family.summable_iff_norm_sq_summable [complete_space E] (f : \u03a0 i, G i) :\n  summable (\u03bb i, V i (f i)) \u2194 summable (\u03bb i, \u2225f i\u2225 ^ 2) :=\nbegin\n  classical,\n  simp only [summable_iff_cauchy_seq_finset, normed_group.cauchy_seq_iff, real.norm_eq_abs],\n  split,\n  { intros hf \u03b5 h\u03b5,\n    obtain \u27e8a, H\u27e9 := hf _ (sqrt_pos.mpr h\u03b5),\n    use a,\n    intros s\u2081 hs\u2081 s\u2082 hs\u2082,\n    rw \u2190 finset.sum_sdiff_sub_sum_sdiff,\n    refine (_root_.abs_sub _ _).trans_lt _,\n    have : \u2200 i, 0 \u2264 \u2225f i\u2225 ^ 2 := \u03bb i : \u03b9, sq_nonneg _,\n    simp only [finset.abs_sum_of_nonneg' this],\n    have : \u2211 i in s\u2081 \\ s\u2082, \u2225f i\u2225 ^ 2 + \u2211 i in s\u2082 \\ s\u2081, \u2225f i\u2225 ^ 2 < (sqrt \u03b5) ^ 2,\n    { rw \u2190 hV.norm_sq_diff_sum,\n      apply sq_lt_sq,\n      rw [_root_.abs_of_nonneg (sqrt_nonneg _), _root_.abs_of_nonneg (norm_nonneg _)],\n      exact H s\u2081 hs\u2081 s\u2082 hs\u2082 },\n    have h\u03b7 := sq_sqrt (le_of_lt h\u03b5),\n    linarith },\n  { intros hf \u03b5 h\u03b5,\n    have h\u03b5' : 0 < \u03b5 ^ 2 / 2 := half_pos (sq_pos_of_pos h\u03b5),\n    obtain \u27e8a, H\u27e9 := hf _ h\u03b5',\n    use a,\n    intros s\u2081 hs\u2081 s\u2082 hs\u2082,\n    refine (abs_lt_of_sq_lt_sq' _ (le_of_lt h\u03b5)).2,\n    have has : a \u2264 s\u2081 \u2293 s\u2082 := le_inf hs\u2081 hs\u2082,\n    rw hV.norm_sq_diff_sum,\n    have Hs\u2081 : \u2211 (x : \u03b9) in s\u2081 \\ s\u2082, \u2225f x\u2225 ^ 2 < \u03b5 ^ 2 / 2,\n    { convert H _ hs\u2081 _ has,\n      have : s\u2081 \u2293 s\u2082 \u2286 s\u2081 := finset.inter_subset_left _ _,\n      rw [\u2190 finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],\n      { simp },\n      { exact \u03bb i, sq_nonneg _ } },\n    have Hs\u2082 : \u2211 (x : \u03b9) in s\u2082 \\ s\u2081, \u2225f x\u2225 ^ 2 < \u03b5 ^ 2 /2,\n    { convert H _ hs\u2082 _ has,\n      have : s\u2081 \u2293 s\u2082 \u2286 s\u2082 := finset.inter_subset_right _ _,\n      rw [\u2190 finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],\n      { simp },\n      { exact \u03bb i, sq_nonneg _ } },\n    linarith },\nend\n\nomit hV\n\n/-- An orthogonal family forms an independent family of subspaces; that is, any collection of\nelements each from a different subspace in the family is linearly independent. In particular, the\npairwise intersections of elements of the family are 0. -/\nlemma orthogonal_family.independent {V : \u03b9 \u2192 submodule \ud835\udd5c E}\n  (hV : @orthogonal_family \ud835\udd5c _ _ _ _ (\u03bb i, V i) _ (\u03bb i, (V i).subtype\u2097\u1d62)) :\n  complete_lattice.independent V :=\nbegin\n  classical,\n  apply complete_lattice.independent_of_dfinsupp_lsum_injective,\n  rw [\u2190 @linear_map.ker_eq_bot _ _ _ _ _ _ (direct_sum.add_comm_group (\u03bb i, V i)),\n    submodule.eq_bot_iff],\n  intros v hv,\n  rw linear_map.mem_ker at hv,\n  ext i,\n  suffices : \u27ea(v i : E), v i\u27eb = 0,\n  { simpa using this },\n  calc \u27ea(v i : E), v i\u27eb = \u27ea(v i : E), dfinsupp.lsum \u2115 (\u03bb i, (V i).subtype) v\u27eb :\n    by simpa [dfinsupp.sum_add_hom_apply, submodule.coe_subtype]\n      using (hV.inner_right_dfinsupp v i (v i)).symm\n  ... = 0 : by simp [hv],\nend\n\ninclude dec_\u03b9\nlemma direct_sum.submodule_is_internal.collected_basis_orthonormal {V : \u03b9 \u2192 submodule \ud835\udd5c E}\n  (hV : @orthogonal_family \ud835\udd5c _ _ _ _ (\u03bb i, V i) _ (\u03bb i, (V i).subtype\u2097\u1d62))\n  (hV_sum : direct_sum.submodule_is_internal (\u03bb i, V i))\n  {\u03b1 : \u03b9 \u2192 Type*}\n  {v_family : \u03a0 i, basis (\u03b1 i) \ud835\udd5c (V i)} (hv_family : \u2200 i, orthonormal \ud835\udd5c (v_family i)) :\n  orthonormal \ud835\udd5c (hV_sum.collected_basis v_family) :=\nby simpa using hV.orthonormal_sigma_orthonormal hv_family\n\nend orthogonal_family\n\nsection is_R_or_C_to_real\n\nvariables {G : Type*}\n\nvariables (\ud835\udd5c E)\ninclude \ud835\udd5c\n\n/-- A general inner product implies a real inner product. This is not registered as an instance\nsince it creates problems with the case `\ud835\udd5c = \u211d`. -/\ndef has_inner.is_R_or_C_to_real : has_inner \u211d E :=\n{ inner := \u03bb x y, re \u27eax, y\u27eb }\n\n/-- A general inner product space structure implies a real inner product structure. This is not\nregistered as an instance since it creates problems with the case `\ud835\udd5c = \u211d`, but in can be used in a\nproof to obtain a real inner product space structure from a given `\ud835\udd5c`-inner product space\nstructure. -/\ndef inner_product_space.is_R_or_C_to_real : inner_product_space \u211d E :=\n{ norm_sq_eq_inner := norm_sq_eq_inner,\n  conj_sym := \u03bb x y, inner_re_symm,\n  add_left := \u03bb x y z, by\n  { change re \u27eax + y, z\u27eb = re \u27eax, z\u27eb + re \u27eay, z\u27eb,\n    simp [inner_add_left] },\n  smul_left := \u03bb x y r, by\n  { change re \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r * re \u27eax, y\u27eb,\n    simp [inner_smul_left] },\n  ..has_inner.is_R_or_C_to_real \ud835\udd5c E,\n  ..normed_space.restrict_scalars \u211d \ud835\udd5c E }\n\nvariable {E}\n\nlemma real_inner_eq_re_inner (x y : E) :\n  @has_inner.inner \u211d E (has_inner.is_R_or_C_to_real \ud835\udd5c E) x y = re \u27eax, y\u27eb := rfl\n\nlemma real_inner_I_smul_self (x : E) :\n  @has_inner.inner \u211d E (has_inner.is_R_or_C_to_real \ud835\udd5c E) x ((I : \ud835\udd5c) \u2022 x) = 0 :=\nby simp [real_inner_eq_re_inner, inner_smul_right]\n\nomit \ud835\udd5c\n\n/-- A complex inner product implies a real inner product -/\ninstance inner_product_space.complex_to_real [inner_product_space \u2102 G] : inner_product_space \u211d G :=\ninner_product_space.is_R_or_C_to_real \u2102 G\n\nend is_R_or_C_to_real\n\nsection continuous\n\n/-!\n### Continuity of the inner product\n-/\n\nlemma continuous_inner : continuous (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\nbegin\n  letI : inner_product_space \u211d E := inner_product_space.is_R_or_C_to_real \ud835\udd5c E,\n  exact is_bounded_bilinear_map_inner.continuous\nend\n\nvariables {\u03b1 : Type*}\n\nlemma filter.tendsto.inner {f g : \u03b1 \u2192 E} {l : filter \u03b1} {x y : E} (hf : tendsto f l (\ud835\udcdd x))\n  (hg : tendsto g l (\ud835\udcdd y)) :\n  tendsto (\u03bb t, \u27eaf t, g t\u27eb) l (\ud835\udcdd \u27eax, y\u27eb) :=\n(continuous_inner.tendsto _).comp (hf.prod_mk_nhds hg)\n\nvariables [topological_space \u03b1] {f g : \u03b1 \u2192 E} {x : \u03b1} {s : set \u03b1}\n\ninclude \ud835\udd5c\n\nlemma continuous_within_at.inner (hf : continuous_within_at f s x)\n  (hg : continuous_within_at g s x) :\n  continuous_within_at (\u03bb t, \u27eaf t, g t\u27eb) s x :=\nhf.inner hg\n\nlemma continuous_at.inner (hf : continuous_at f x) (hg : continuous_at g x) :\n  continuous_at (\u03bb t, \u27eaf t, g t\u27eb) x :=\nhf.inner hg\n\nlemma continuous_on.inner (hf : continuous_on f s) (hg : continuous_on g s) :\n  continuous_on (\u03bb t, \u27eaf t, g t\u27eb) s :=\n\u03bb x hx, (hf x hx).inner (hg x hx)\n\nlemma continuous.inner (hf : continuous f) (hg : continuous g) : continuous (\u03bb t, \u27eaf t, g t\u27eb) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, hf.continuous_at.inner hg.continuous_at\n\nend continuous\n\nsection re_apply_inner_self\n\n/-- Extract a real bilinear form from an operator `T`, by taking the pairing `\u03bb x, re \u27eaT x, x\u27eb`. -/\ndef continuous_linear_map.re_apply_inner_self (T : E \u2192L[\ud835\udd5c] E) (x : E) : \u211d := re \u27eaT x, x\u27eb\n\nlemma continuous_linear_map.re_apply_inner_self_apply (T : E \u2192L[\ud835\udd5c] E) (x : E) :\n  T.re_apply_inner_self x = re \u27eaT x, x\u27eb :=\nrfl\n\nlemma continuous_linear_map.re_apply_inner_self_continuous (T : E \u2192L[\ud835\udd5c] E) :\n  continuous T.re_apply_inner_self :=\nre_clm.continuous.comp $ T.continuous.inner continuous_id\n\nlemma continuous_linear_map.re_apply_inner_self_smul (T : E \u2192L[\ud835\udd5c] E) (x : E) {c : \ud835\udd5c} :\n  T.re_apply_inner_self (c \u2022 x) = \u2225c\u2225 ^ 2 * T.re_apply_inner_self x :=\nby simp only [continuous_linear_map.map_smul, continuous_linear_map.re_apply_inner_self_apply,\n  inner_smul_left, inner_smul_right, \u2190 mul_assoc, mul_conj, norm_sq_eq_def', \u2190 smul_re,\n  algebra.smul_def (\u2225c\u2225 ^ 2) \u27eaT x, x\u27eb, algebra_map_eq_of_real]\n\nend re_apply_inner_self\n\n/-! ### The orthogonal complement -/\n\nsection orthogonal\nvariables (K : submodule \ud835\udd5c E)\n\n/-- The subspace of vectors orthogonal to a given subspace. -/\ndef submodule.orthogonal : submodule \ud835\udd5c E :=\n{ carrier := {v | \u2200 u \u2208 K, \u27eau, v\u27eb = 0},\n  zero_mem' := \u03bb _ _, inner_zero_right,\n  add_mem' := \u03bb x y hx hy u hu, by rw [inner_add_right, hx u hu, hy u hu, add_zero],\n  smul_mem' := \u03bb c x hx u hu, by rw [inner_smul_right, hx u hu, mul_zero] }\n\nnotation K`\u15ee`:1200 := submodule.orthogonal K\n\n/-- When a vector is in `K\u15ee`. -/\nlemma submodule.mem_orthogonal (v : E) : v \u2208 K\u15ee \u2194 \u2200 u \u2208 K, \u27eau, v\u27eb = 0 := iff.rfl\n\n/-- When a vector is in `K\u15ee`, with the inner product the\nother way round. -/\nlemma submodule.mem_orthogonal' (v : E) : v \u2208 K\u15ee \u2194 \u2200 u \u2208 K, \u27eav, u\u27eb = 0 :=\nby simp_rw [submodule.mem_orthogonal, inner_eq_zero_sym]\n\nvariables {K}\n\n/-- A vector in `K` is orthogonal to one in `K\u15ee`. -/\nlemma submodule.inner_right_of_mem_orthogonal {u v : E} (hu : u \u2208 K) (hv : v \u2208 K\u15ee) : \u27eau, v\u27eb = 0 :=\n(K.mem_orthogonal v).1 hv u hu\n\n/-- A vector in `K\u15ee` is orthogonal to one in `K`. -/\nlemma submodule.inner_left_of_mem_orthogonal {u v : E} (hu : u \u2208 K) (hv : v \u2208 K\u15ee) : \u27eav, u\u27eb = 0 :=\nby rw [inner_eq_zero_sym]; exact submodule.inner_right_of_mem_orthogonal hu hv\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\nlemma inner_right_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v \u2208 (\ud835\udd5c \u2219 u)\u15ee) : \u27eau, v\u27eb = 0 :=\nsubmodule.inner_right_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\nlemma inner_left_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v \u2208 (\ud835\udd5c \u2219 u)\u15ee) : \u27eav, u\u27eb = 0 :=\nsubmodule.inner_left_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector orthogonal to `u` lies in `(\ud835\udd5c \u2219 u)\u15ee`. -/\nlemma mem_orthogonal_singleton_of_inner_right (u : E) {v : E} (hv : \u27eau, v\u27eb = 0) : v \u2208 (\ud835\udd5c \u2219 u)\u15ee :=\nbegin\n  intros w hw,\n  rw submodule.mem_span_singleton at hw,\n  obtain \u27e8c, rfl\u27e9 := hw,\n  simp [inner_smul_left, hv],\nend\n\n/-- A vector orthogonal to `u` lies in `(\ud835\udd5c \u2219 u)\u15ee`. -/\nlemma mem_orthogonal_singleton_of_inner_left (u : E) {v : E} (hv : \u27eav, u\u27eb = 0) : v \u2208 (\ud835\udd5c \u2219 u)\u15ee :=\nmem_orthogonal_singleton_of_inner_right u $ inner_eq_zero_sym.2 hv\n\nvariables (K)\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\nlemma submodule.inf_orthogonal_eq_bot : K \u2293 K\u15ee = \u22a5 :=\nbegin\n  rw submodule.eq_bot_iff,\n  intros x,\n  rw submodule.mem_inf,\n  exact \u03bb \u27e8hx, ho\u27e9, inner_self_eq_zero.1 (ho x hx)\nend\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\nlemma submodule.orthogonal_disjoint : disjoint K K\u15ee :=\nby simp [disjoint_iff, K.inf_orthogonal_eq_bot]\n\n/-- `K\u15ee` can be characterized as the intersection of the kernels of the operations of\ninner product with each of the elements of `K`. -/\nlemma orthogonal_eq_inter : K\u15ee = \u2a05 v : K, (innerSL (v:E)).ker :=\nbegin\n  apply le_antisymm,\n  { rw le_infi_iff,\n    rintros \u27e8v, hv\u27e9 w hw,\n    simpa using hw _ hv },\n  { intros v hv w hw,\n    simp only [submodule.mem_infi] at hv,\n    exact hv \u27e8w, hw\u27e9 }\nend\n\n/-- The orthogonal complement of any submodule `K` is closed. -/\nlemma submodule.is_closed_orthogonal : is_closed (K\u15ee : set E) :=\nbegin\n  rw orthogonal_eq_inter K,\n  convert is_closed_Inter (\u03bb v : K, (innerSL (v:E)).is_closed_ker),\n  simp\nend\n\n/-- In a complete space, the orthogonal complement of any submodule `K` is complete. -/\ninstance [complete_space E] : complete_space K\u15ee := K.is_closed_orthogonal.complete_space_coe\n\nvariables (\ud835\udd5c E)\n\n/-- `submodule.orthogonal` gives a `galois_connection` between\n`submodule \ud835\udd5c E` and its `order_dual`. -/\nlemma submodule.orthogonal_gc :\n  @galois_connection (submodule \ud835\udd5c E) (order_dual $ submodule \ud835\udd5c E) _ _\n    submodule.orthogonal submodule.orthogonal :=\n\u03bb K\u2081 K\u2082, \u27e8\u03bb h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu),\n          \u03bb h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu)\u27e9\n\nvariables {\ud835\udd5c E}\n\n/-- `submodule.orthogonal` reverses the `\u2264` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_le {K\u2081 K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) : K\u2082\u15ee \u2264 K\u2081\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).monotone_l h\n\n/-- `submodule.orthogonal.orthogonal` preserves the `\u2264` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_orthogonal_monotone {K\u2081 K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) :\n  K\u2081\u15ee\u15ee \u2264 K\u2082\u15ee\u15ee :=\nsubmodule.orthogonal_le (submodule.orthogonal_le h)\n\n/-- `K` is contained in `K\u15ee\u15ee`. -/\nlemma submodule.le_orthogonal_orthogonal : K \u2264 K\u15ee\u15ee := (submodule.orthogonal_gc \ud835\udd5c E).le_u_l _\n\n/-- The inf of two orthogonal subspaces equals the subspace orthogonal\nto the sup. -/\nlemma submodule.inf_orthogonal (K\u2081 K\u2082 : submodule \ud835\udd5c E) : K\u2081\u15ee \u2293 K\u2082\u15ee = (K\u2081 \u2294 K\u2082)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_sup.symm\n\n/-- The inf of an indexed family of orthogonal subspaces equals the\nsubspace orthogonal to the sup. -/\nlemma submodule.infi_orthogonal {\u03b9 : Type*} (K : \u03b9 \u2192 submodule \ud835\udd5c E) : (\u2a05 i, (K i)\u15ee) = (supr K)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_supr.symm\n\n/-- The inf of a set of orthogonal subspaces equals the subspace orthogonal to the sup. -/\nlemma submodule.Inf_orthogonal (s : set $ submodule \ud835\udd5c E) : (\u2a05 K \u2208 s, K\u15ee) = (Sup s)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_Sup.symm\n\n@[simp] lemma submodule.top_orthogonal_eq_bot : (\u22a4 : submodule \ud835\udd5c E)\u15ee = \u22a5 :=\nbegin\n  ext,\n  rw [submodule.mem_bot, submodule.mem_orthogonal],\n  exact \u27e8\u03bb h, inner_self_eq_zero.mp (h x submodule.mem_top), by { rintro rfl, simp }\u27e9\nend\n\n@[simp] lemma submodule.bot_orthogonal_eq_top : (\u22a5 : submodule \ud835\udd5c E)\u15ee = \u22a4 :=\nbegin\n  rw [\u2190 submodule.top_orthogonal_eq_bot, eq_top_iff],\n  exact submodule.le_orthogonal_orthogonal \u22a4\nend\n\n@[simp] lemma submodule.orthogonal_eq_top_iff : K\u15ee = \u22a4 \u2194 K = \u22a5 :=\nbegin\n  refine \u27e8_, by { rintro rfl, exact submodule.bot_orthogonal_eq_top }\u27e9,\n  intro h,\n  have : K \u2293 K\u15ee = \u22a5 := K.orthogonal_disjoint.eq_bot,\n  rwa [h, inf_comm, top_inf_eq] at this\nend\n\nend orthogonal\n\n/-! ### Self-adjoint operators -/\n\nnamespace inner_product_space\n\n/-- A (not necessarily bounded) operator on an inner product space is self-adjoint, if for all\n`x`, `y`, we have `\u27eaT x, y\u27eb = \u27eax, T y\u27eb`. -/\ndef is_self_adjoint (T : E \u2192\u2097[\ud835\udd5c] E) : Prop := \u2200 x y, \u27eaT x, y\u27eb = \u27eax, T y\u27eb\n\n/-- An operator `T` on a `\u211d`-inner product space is self-adjoint if and only if it is\n`bilin_form.is_self_adjoint` with respect to the bilinear form given by the inner product. -/\nlemma is_self_adjoint_iff_bilin_form (T : F \u2192\u2097[\u211d] F) :\n  is_self_adjoint T \u2194 bilin_form_of_real_inner.is_self_adjoint T :=\nby simp [is_self_adjoint, bilin_form.is_self_adjoint, bilin_form.is_adjoint_pair]\n\nlemma is_self_adjoint.conj_inner_sym {T : E \u2192\u2097[\ud835\udd5c] E} (hT : is_self_adjoint T) (x y : E) :\n  conj \u27eaT x, y\u27eb = \u27eaT y, x\u27eb :=\nby rw [hT x y, inner_conj_sym]\n\n@[simp] lemma is_self_adjoint.apply_clm {T : E \u2192L[\ud835\udd5c] E} (hT : is_self_adjoint (T : E \u2192\u2097[\ud835\udd5c] E))\n  (x y : E) :\n  \u27eaT x, y\u27eb = \u27eax, T y\u27eb :=\nhT x y\n\n/-- For a self-adjoint operator `T`, the function `\u03bb x, \u27eaT x, x\u27eb` is real-valued. -/\n@[simp] lemma is_self_adjoint.coe_re_apply_inner_self_apply\n  {T : E \u2192L[\ud835\udd5c] E} (hT : is_self_adjoint (T : E \u2192\u2097[\ud835\udd5c] E)) (x : E) :\n  (T.re_apply_inner_self x : \ud835\udd5c) = \u27eaT x, x\u27eb :=\nbegin\n  suffices : \u2203 r : \u211d, \u27eaT x, x\u27eb = r,\n  { obtain \u27e8r, hr\u27e9 := this,\n    simp [hr, T.re_apply_inner_self_apply] },\n  rw \u2190 eq_conj_iff_real,\n  exact hT.conj_inner_sym x x\nend\n\n/-- If a self-adjoint operator preserves a submodule, its restriction to that submodule is\nself-adjoint. -/\nlemma is_self_adjoint.restrict_invariant {T : E \u2192\u2097[\ud835\udd5c] E} (hT : is_self_adjoint T)\n  {V : submodule \ud835\udd5c E} (hV : \u2200 v \u2208 V, T v \u2208 V) :\n  is_self_adjoint (T.restrict hV) :=\n\u03bb v w, hT v w\n\nend inner_product_space\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/inner_product_space/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7349621360096905}}
{"text": "import algebra.group.basic\nimport data.real.basic\nimport group_theory.order_of_element\n\nnoncomputable theory\nopen_locale classical\n\n\ndef star_set := set.Ico (0:\u211d) 1\n\n#check star_set\n\n\nsection star_group\n\n\n#check has_coe_to_sort\n#check semigroup\n\ndef star : \u211d \u2192 \u211d \u2192 \u211d\n| x y := x + y - \u230a x + y \u230b\n\n\nnotation x`\u22c6`y := star x y\nvariables (x y : \u211d) (A : Type*)\n\n#check star_set\n\nlemma star_closed {a b : \u211d} (ha : a \u2208 star_set) (hb : b \u2208 star_set) : (a \u22c6 b) \u2208 star_set :=\nbegin\n    unfold star,\n    unfold star_set,\n    split,\n    exact fract_nonneg (a + b),\n    exact fract_lt_one (a + b),\nend\n\n\nlemma star_assoc {a b c : \u211d} (ha : a \u2208 star_set) (hb : b \u2208 star_set) (hc : c \u2208 star_set): (a \u22c6 b \u22c6 c) = (a \u22c6 (b \u22c6 c)) :=\nbegin\n    unfold star,\n    repeat {rw \u2190 fract},\n    rw fract_eq_fract,\n    let z : \u2124 := _,\n    use z,\n    repeat {rw fract},\n    ring,\n    norm_cast,\n    --thanks Reid!\nend\n\nlemma zero_in_star_set : (0 : \u211d) \u2208 star_set :=\nbegin\n    unfold star_set,\n    split,\n    by refl,\n    exact zero_lt_one,\nend\n\nlemma star_identity_is_zero {a : \u211d} (ha : a \u2208 star_set) : (a \u22c6 0) = a :=\nbegin\n    unfold star,\n    unfold star_set at ha,\n    cases ha with h0 h1,\n    rw add_zero,\n    rw \u2190 fract,\n    have h2 := fract_nonneg a,\n    have h3 := fract_lt_one a,\n    rw fract_eq_iff,\n    split,\n    {exact h0},\n    {split,\n        {exact h1},\n        {use 0, exact sub_self a},\n    },\nend\n\nlemma star_inverses {a : \u211d} (ha : a \u2208 star_set) : \u2203 (b : \u211d), (a \u22c6 b) = (0 : \u211d) \u2227 b \u2208 star_set :=\nbegin\n    by_cases (a = 0),\n    {   rw h,\n        use (0 : \u211d),\n        split,\n        unfold star,\n        rw \u2190 fract,\n        rw add_zero,\n        exact fract_zero,\n        rw h at ha,\n        exact ha\n    },\n    {   use (1 - a),\n        split,\n        {\n            unfold star,\n            rw add_comm,\n            rw sub_add,\n            rw sub_self,\n            rw sub_zero,\n            simp\n        },\n        {\n            unfold star_set,\n            unfold star_set at ha,\n            cases ha with h0 h1,\n            have h2 : 0 < a := by {\n                rw lt_iff_le_and_ne,\n                split,\n                {exact h0},\n                {exact ne.symm h},\n            },\n            split,\n            {   \n                apply le_of_lt,\n                apply lt_sub_right_of_add_lt,\n                rw zero_add,\n                exact h1,\n            },\n            {\n                apply sub_lt_self,\n                exact h2,\n            },\n        },\n    }\nend\n#lint\n\nend star_group\n\nsection my_group\n\nuniverse u\n/- Prove that (a\\_1a_2\u00b7\u00b7\u00b7a_n)^-1 = a_n^\u22121\u00b7\u00b7\u00b7a_2^\u22121a_1^\u22121 \nfor all a_1,a_2,\u00b7\u00b7\u00b7,a_n \u2208G -/\n-- use rcases here cause I guess it does inductive magic <3\n\n--(list.map a (list.range n)), where (a : \u2115 \u2192 G)\n\nvariables (G : Type*) [group G] (a : G)\n\nlemma inv_prod' {G : Type*} [group G] (l : list G) :\n(l.prod)\u207b\u00b9 = (list.map (\u03bb (x : G), x\u207b\u00b9) l.reverse).prod :=\nbegin\n    induction l with hd tl h,\n    simp only [one_inv, list.prod_nil, list.map, list.reverse_nil],\n    simp only [h, list.reverse_cons, mul_inv_rev, mul_one, list.map_append, list.prod_append, list.prod_cons, list.prod_nil, list.map],\nend\n\n\n/-Let x be an element of G.  Prove that if\n|x|=n for some positive integer n then x^\u22121 = x^n\u22121 -/\n/-lemma gpow_eq_mod_order_of' {i : \u2124} : a ^ i = a ^ (i % order_of a) :=\ncalc a ^ i = a ^ (i % order_of a + order_of a * (i / order_of a)) :\n    by rw [int.mod_add_div]\n  ... = a ^ (i % order_of a) :\n    by simp [gpow_add, gpow_mul, pow_order_of_eq_one]-/\n\n\n\n\nend my_group\n", "meta": {"author": "agusakov", "repo": "m845_lean", "sha": "b741f408954b629e56e9ceadbc27fee0ae9eb48e", "save_path": "github-repos/lean/agusakov-m845_lean", "path": "github-repos/lean/agusakov-m845_lean/m845_lean-b741f408954b629e56e9ceadbc27fee0ae9eb48e/src/m845_hw1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939024820841433, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7349394893177712}}
{"text": "--lecture on propositional logic\nvariables P Q R : Prop\n\n--proposition :definitive statement which we may be able to prove\n--propositional connectives\n\n#check P \u2227 Q --and, conjunction \n#check P \u2228 Q -- or, disconjunction \n#check P \u2192 Q -- if-then, implication\n#check \u00ac P --not, negation\n-- \u00ac P = P \u2192 false\n#check P \u2194 Q --if and only if, equivalence\n#check false\n#check true\n\n--P \u2192 (Q\u2192 R)\n\n--tautologies: If we are proving a statement containing propositional variables then this means that the statement is true for all replacements of the variables with actual propositions. We say it is a tautology.\n\ntheorem I: P \u2192 P :=\nbegin\n  assume h,\n  exact h,\nend\n\ntheorem C : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  assume p2q,\n  assume q2r,\n  assume p,\n  apply q2r, --q->r, then r can be replaced by q, goal is q\n  apply p2q, --goal is p\n  exact p,\nend\n\ntheorem swap : (P \u2192 Q \u2192 R) \u2192 (Q \u2192 P \u2192 R) :=\nbegin\n  assume left,\n  assume lq,\n  assume lp,\n  apply left, -- two goals\n  exact lp,\n  exact lq,\nend\n\n\n#print I\n#print C\n#print swap\n\n/--\n  ASSUME => to prove = right after |-\n  APPLY => to use\n  EXACT\n--/\n\n\n\n\n\n\n\n\n\n\n\n\n\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  assume p q, -- p \u2192 q \u2192 r\n  constructor, -- turns goal into two goals\n  exact p,\n  exact q,\nend\n\n\ntheorem comAnd : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  assume pq,\n  cases pq with p q, -- p \u2227 q becomes p and q\n  constructor,\n  exact q,\n  exact p,\nend\n\ntheorem curry: (P \u2192 Q \u2192 R) \u2194 (P \u2227 Q \u2192 R) :=\nbegin\n  constructor, -- left to right, and right to left\n  assume lhs,\n  assume pq,\n  cases pq with p q,\n  apply lhs, -- two goals become three goals necuase p q r in consequence\n  exact p,\n  exact q,\n\n  assume rhs,\n  assume p q,\n  apply rhs, -- two goals become three goals necuase p q r in consequence\n  constructor,\n  exact p,\n  exact q,\nend \n\n/--\n  constuctor => to prove conjunction\n  cases h with x y => to use conjunction\n--/\n\n\n\n\n\n\n\n\n\n\n\n\n\n--disconjunction, or, \u2228 \nexample: P \u2192 P \u2228 Q :=\nbegin\n  assume p,\n  left, --- either prove P or we can prove Q\n  exact p,\nend\n\nexample: Q \u2192 P \u2228 Q :=\nbegin\n  assume q,\n  right, --- either prove P or we can prove Q\n  exact q,\nend\n\ntheorem case_lem : (P \u2192 R) \u2192 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R :=\nbegin\n  assume pr qr pq,\n  cases pq with p q, --seperate two cases, either p or q\n  apply pr,\n  exact p,\n\n  apply qr,\n  exact q,\nend\n\n/--\n  to prove disconjunction -> left, right\n  to use an assumption of disconjunction -> cases h with x y\n--/\n\nexample: P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  assume pq,\n  cases pq with p q,\n  right,\n  exact p,\n  left,\n  exact q,\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\nexample : true :=\nbegin\n  trivial, --/constructor -- can only prove\nend\n\n--efq, Ex falso quod libet \n--from false follows everything.\n-- If pigs can fly then I am the president of America \ntheorem efq: false \u2192 P :=\nbegin\n  assume f,\n  cases f, -- can only use\nend\n\n-- \u00acP = P \u2192 false \ntheorem contr: \u00ac (P \u2227 \u00ac P) :=\nbegin\n  assume pnp, --goal turns to false\n  cases pnp with p np,\n  apply np, -- because \u00acP = P \u2192 false \n  exact p,\nend\n\n/--\n  to prove true : trival\n  to use false: cases (no with)\n--/\n\n\n\n\n\n\n\n\n\n\n\n\n--The truth based logic is called classical logic\n--evidence based one is called intuitionistic logic\n\n--de morgen law\n/--\n  \u00ac (P \u2228 Q) \u2194 \u00ac P \u2227 \u00ac Q\n  \u00ac (P \u2227 Q) \u2194 \u00ac P \u2228 \u00ac Q\n--/\ntheorem dm1 : \u00ac (P \u2228 Q) \u2194 \u00ac P \u2227 \u00ac Q :=\n-- p \u2194 q = p \u2192 q \u2227 q \u2192 p \nbegin\n  constructor, --to prove \u2227 use constructor\n  assume npq,\n  constructor,\n  assume p, --not p = p -> false\n  apply npq,\n  left,\n  exact p,\n\n  assume q,\n  apply npq,\n  right,\n  exact q,\n\n  assume npnq,\n  assume pq,\n  cases npnq with np nq, --to use and , cases with x y\n  cases pq with p q, --to use or , cases with x y\n  apply np,\n  exact p,\n\n  apply nq,\n  exact q,\nend\n\n\n--law of exclude middle : P \u2228 \u00ac P \n--em = excluded middle\n--the third is not given\nopen classical\n#check em P\n\n--It is not the case that I have a cat and that I have a dog\n--I don\u2019t have a cat or I don\u2019t have a dog ?\n--NO\ntheorem dm2 : \u00ac (P \u2227 Q) \u2194 \u00ac P \u2228 \u00ac Q := -----em\nbegin\n  constructor, -- to prove and\n  assume npq,\n  cases (em P) with p np, -- add one more case\n  right,\n  assume q,\n  apply npq,\n  constructor,\n  apply p,\n\n  apply q,\n  \n  left,\n  apply np,\n\n  assume npnq pq,\n  cases npnq with np nq,\n  apply np,\n  cases pq with p q,\n  exact p,\n\n  apply nq,\n  cases pq with p q,\n  exact q,\nend\n-- raa equivalent to the principle of excluded middle\n--indirect proof \ntheorem raa : \u00ac \u00ac P \u2192 P :=\nbegin\n  assume nnp,\n  cases (em P) with p np,\n  exact p,\n  apply efq, -- false -> P \n  apply nnp,\n  exact np\nend\n\ntheorem nn_em : \u00ac \u00ac (P \u2228 \u00ac P) :=\nbegin\n  assume npnp,\n  apply npnp,\n  right,\n  assume p,\n  apply npnp,\n  left,\n  exact p\nend\n\n--em and raa are equivalent \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n--predicate logic\n--Predicate logic extends propositional logic, we can use it to talk about objects and their properties.\n--types (sets)\n#check \u2115 -- \\nat--\\bn\n#check list \u2115 \n#check bool\nvariables A B C : Type\n\n\n--predicates\n--Prime: \u2115 \u2192 Prop\n--Prime 3 : Prop -- 3 is a prime number\n\n--A = type of students\n--isClever : A \u2192 Prop\n\n--relations: leq : \u2115 -> (\u2115 \u2192 Prop)\n--we write x \u2264 y for leq x y\n-- 3 \u2264 4 : Prop\n--leq 3 4 : Prop\n\nvariables PP QQ : A \u2192 Prop --two predicates PP QQ\n--PP x means x is clever\n--QQ x means x is funny\n\n--quantifiers\n-- \u2200 : for all, universal quantifier\n-- \u2203 : exists, existential quantifier\n-- (\u2200 x : A, PP x) all students are clever\n-- (\u2203 x : A, PP x) there is a clever student\n\n\n--equality\n-- a b : A , we can form a = b: Prop, means a is equal to b\n\n--proofs\n--\u2200 x : A, PP x\n--how to prove: assume h\n--how ro use: apply h --h : \u2200 x : A, PP x, and we want to prove PP a\n\n\n--If all students are clever \n--then if all clever students are funny \n--then all students are funny.\nexample : (\u2200 x : A, PP x) \u2192 (\u2200 y : A, PP y \u2192 QQ y) \u2192 \u2200 z : A , QQ z :=\nbegin\n  assume h g,\n  assume george, --using george as an example of z\n  apply g, --pp y -> qq y => pp george\n  apply h, --pp x \nend\n\n--all students are clever and funny is the same as saying that all students are clever and all students are funny.\nexample : (\u2200 x : A, PP x \u2227 QQ x) \u2194 (\u2200 x : A , PP x) \u2227 (\u2200 x : A, QQ x) :=\nbegin\n  constructor,\n  assume h,\n  constructor,\n  assume y,\n  have pq : PP y \u2227 QQ y, --change the goal? add one more assumption?\n  apply h, --one goal eliminated\n  cases pq with p q,\n  exact p, --exact the same, use exact\n\n  assume y,\n  have pq2 : PP y \u2227 QQ y, --change the goal?\n  apply h, --one goal eliminated\n  cases pq2 with p q,\n  exact q, \n\n  assume g,\n  cases g with pp qq,\n  assume z,\n  constructor,\n  apply pp, --x and z are same format but not same element, use apply\n  apply qq,\nend\n\n-- \u2203 x : A, PP x\n--how to prove: existsi a, to show PP a\n-- h : \u2203 x : A, PP x\n--how to use: cases h with a p, given a : A, p : PP a\n\n--If there is a clever student and all clever students are funny then there is a funny student.\nexample : (\u2203 x : A, PP x)\n  \u2192 (\u2200 y : A, PP y \u2192 QQ y)\n  \u2192 \u2203 z : A , QQ z :=\nbegin\n  assume g h,\n  cases g with a p, -- g : \u2203 (x : A), PP x => a : A, p : PP a\n  existsi a,\n  apply h,\n  exact p,\nend\n\n--There is a student who is clever or funny is the same as saying there is a student who is funny or there is a student who is clever.\nexample : (\u2203 x : A, PP x \u2228 QQ x)\n              \u2194 (\u2203 x : A , PP x) \u2228 (\u2203 x : A, QQ x) :=\nbegin\n  constructor,\n  assume h,\n  cases h with a g,\n  cases g with p q,\n  left,\n  existsi a, -- there is already an a as variable on the top\n  exact p,\n  right,\n  existsi a,\n  exact q,\n\n  assume h,\n  cases h with p q,\n  cases p with a pa, -- have to create a variable at first\n  existsi a,\n  left,\n  exact pa,\n  cases q with a q,\n  existsi a,\n  right,\n  exact q,\nend\n\n\nexample : (\u2200  x : A, PP x \u2228 QQ x)\n              \u2194 (\u2200  x : A , PP x) \u2228 (\u2200 x : A, QQ x) :=\nbegin\n  sorry\nend\n/--\n(\u2200  x : A , PP x) \u2228 (\u2200 x : A, QQ x) -> (\u2200  x : A, PP x \u2228 QQ x)\n--/\n\nexample : (\u2203 x : A, PP x \u2227  QQ x)\n              \u2194 (\u2203 x : A , PP x) \u2227 (\u2203 x : A, QQ x) :=\nbegin\n  sorry\nend\n/--\n(\u2203 x : A, PP x \u2227  QQ x)\n              \u2192  (\u2203 x : A , PP x) \u2227 (\u2203 x : A, QQ x) \n--/\n\n\n--have aux: P\n--first i have to prove P\n--then I can use aux : P\n\n\n\n\n\n\n\n\n\n\n\nvariable People : Type\n\nvariable Loves : People \u2192 People \u2192 Prop\n\n--everybody loves somebody\n--predicate logic\n#check \u2200 x : People, \u2203 y : People, Loves x y\n\n--there is somebody who is loved by everyone\n#check \u2203 y : People, \u2200 x : People, Loves x y\n\nexample: (\u2203 y : People, \u2200 x : People, Loves x y) \u2192 (\u2200 x : People, \u2203 y : People, Loves x y) :=\nbegin\n  assume h,\n  assume g,\n  cases h with a alla, --there is no other object for exist to use, we can only use exist to move on\n  existsi a,\n  apply alla,\nend\n\n--everybody loves themselves\n#check \u2200 x : People, Loves x x\n\n--everybody loves at most one person\n#check \u2200 x y z: People, Loves x y \u2192 Loves x z \u2192 y = z\n\n--everybody only loves themselves\n#check \u2200 x y : People, Loves x y \u2192 x = y\n\nexample: (\u2200 x : People, Loves x x) \u2192 (\u2200 x y z: People, Loves x y \u2192 Loves x z \u2192 y = z) \u2192 (\u2200 x y : People, Loves x y \u2192 x = y) :=\nbegin\n  assume h g,\n  assume a b,\n  assume ab,\n  apply g, --question mark here\n  apply h, --everybody loves themselves\n  exact ab,\nend\n\n--currying equivalent\n-- (P \u2227 Q \u2192 R) \u2194 (P\u2192 Q \u2192 R)\n--((\u2203 x : A, PP x) \u2192 R)  \u2194 (\u2200 x : A , PP x \u2192 R)\ntheorem curry_pred : ((\u2203 x : A, PP x) \u2192 R)  \u2194 (\u2200 x : A , PP x \u2192 R)  :=\nbegin\n  constructor,\n  assume h,\n  assume a,\n  assume g,\n  apply h,\n  existsi a,\n  exact g,\n\n  assume h g,\n  cases g with a ppa,\n  apply h,\n  exact ppa, ---? question mark here\n  --apply ppa,\nend\n\n--equality\nexample : \u2200 x : A, x = x :=\nbegin\n  assume h,\n  reflexivity,\nend\n\nexample:  \u2200 x y : A, x = y \u2192 PP y \u2192 PP x :=\nbegin\n  assume a b,\n  assume h,\n  assume g,\n  rewrite h, --change the goal using equality\n  exact g,\nend\n\nexample:  \u2200 x y : A, x=y \u2192 PP x \u2192 PP y :=\nbegin\n  assume a b,\n  assume h,\n  assume g,\n  rewrite \u2190 h, -- another direction of equality, from right to left\n  exact g,\nend\n\n\n/--\n  Equality is an equivalence relation, it mens that it is\n\n  reflexive (\u2200 x : A, x=x),\n  symmetric (\u2200 x y : A, x=y \u2192 y=x)\n  transitive (\u2200 x y z : A, x=y \u2192 y=z \u2192 x=z)\n--/\n\ntheorem sym_eq : \u2200 x y : A, x = y \u2192 y=x :=\nbegin\n  assume x y p,\n  rewrite p, ---automatically uses reflexivity\nend\n\ntheorem trans_eq : \u2200 x y z : A, x=y \u2192 y=z \u2192 x=z :=\nbegin\n  assume x y z,\n  assume xy yz,\n  rewrite xy,\n  exact yz,\nend\n/--equality\n  to prove: reflexivity\n  to use: rewrite h && rewrite \u2190 h\n--/\nexample : \u2200 x y : A, x=y \u2192 y=x :=\nbegin\n  assume x y p,\n  symmetry,\n  exact p,\nend\n\nexample : \u2200 x y z : A, x=y \u2192 y=z \u2192 x=z :=\nbegin\n  assume x y z xy yz,\n  transitivity, --x = ? = z\n  exact xy,\n  exact yz,\nend\n\nexample : \u2200 x y z : A, x=y \u2192 y=z \u2192 x=z :=\nbegin\n  assume x y z xy yz,\n  calc\n    x = y   : by exact xy\n    ... = z : by exact yz, -- last expression of the previous line, in this case y.\nend\n\n\n\n\n\n\n\n\n\n\n\n\n--de morgan for propositional logic\n-- \u00ac (P \u2228 Q) \u2194 \u00ac P \u2227 \u00ac Q\n-- \u00ac (\u2203 x : A, PP x) \u2194 \u2200 x : A, \u00ac PP x\n-- \u00ac (P \u2227 Q) \u2194 \u00ac P \u2228 \u00ac Q\n-- \u00ac (\u2200 x : A, PP x) \u2194 \u2203 x : A, \u00ac PP x \nexample : \u00ac P \u2228 \u00ac Q \u2192 \u00ac (P \u2227 Q):=\nbegin\n  assume h,\n  assume pq,\n  cases pq with p q,\n  cases h with np nq,\n  apply np,\n  exact p,\n\n  apply nq,\n  exact q,\nend\n\n\ntheorem dm1_pred : \u00ac (\u2203 x : A, PP x) \u2194 \u2200 x : A, \u00ac PP x :=\nbegin\n  constructor,\n  assume h,\n  assume a,\n  assume ppa,\n  apply h,\n  existsi a,\n  exact ppa,\n\n  assume h,\n  assume ppx,\n  cases ppx with a ppa,\n  apply h,\n  exact ppa,\nend\n\n--classical logic needed\ntheorem dm2_pred : \u00ac (\u2200 x : A, PP x) \u2194 \u2203 x : A, \u00ac PP x :=\nbegin\n  constructor,\n  assume h,\n  apply raa, --!!q = q, add !! to goal\n  assume npp,\n\n  apply h,\n  assume a,\n  apply raa,---double time\n  assume nppa,\n  apply npp,\n  existsi a,\n  exact nppa,\n\n  assume h,\n  assume nppx,\n  cases h with a nppa,\n  apply nppa,\n  apply nppx,\nend\n/--\n  in every non-empty pub, there is one person such that if this person drinks then everybody is drinking. true\n  A = prople in the pub\n  PP x = x is drinking\n--/\n\ntheorem aux_thm: (\u00ac \u2200 (x : A), PP x) \u2192   \u2203 x : A, \u00ac PP x :=\nbegin\n    assume h,\n    apply raa,\n    assume ng,\n    apply h,\n    assume x,\n    apply raa,\n    assume np,\n    apply ng,\n    existsi x,\n    exact np,\nend\n\ntheorem drinker: (\u2203 x : A, true) \u2192 \u2203 x : A, PP x \u2192 \u2200 x : A, PP x :=\n--(\u2203 x : A,  true) \u2192 (\u2203 x:A, (PP x \u2192 \u2200 x : A,PP x)) :=\nbegin\n  ---b) provable classically\n  assume atr,\n  cases atr with a tr,\n  cases em (\u2200 x : A, PP x) with app napp,  --create two assumptions, P and \u00ac P\n  existsi a,\n  assume ppa,\n  exact app,\n\n  have h :(\u2203 x: A, \u00ac PP x),  --one changes goal, one adds as assumption\n  apply aux_thm, --we know napp and current goal are equal\n  exact napp,\n\n  cases h with a1 npp,\n  existsi a1,\n  assume ppa1,\n  have f: false,\n  apply npp,\n  exact ppa1,\n\n  cases f, --to use false\nend\n\ntheorem ex09 : (\u2203 x : A, true) \u2192 (\u2203 x:A, PP x) \u2192 \u2200 x : A,PP x :=\nbegin ---c) not provable classically\n  sorry\nend\n", "meta": {"author": "kyrran", "repo": "Lean", "sha": "915f45d695eb01a80e58916f03e8f7c1e878be8b", "save_path": "github-repos/lean/kyrran-Lean", "path": "github-repos/lean/kyrran-Lean/Lean-915f45d695eb01a80e58916f03e8f7c1e878be8b/lean1-7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7348305408681999}}
{"text": "-- gcd and div and mod and lt and le are all in core\n-- but most of the theorems about them are here\n\nimport data.int.basic\nimport data.int.order\nimport data.nat.gcd\n\n-- a congruent to b modulo m\ndef cong (a:int) (b: int) (m: int): Prop := m \u2223 a - b\n\n-- p is prime\ndef is_prime (p:nat): Prop := \u2200 x y: int, \u2191p \u2223 (x*y) \u2192 \u2191p \u2223 x \u2228 \u2191p \u2223 y\n\n-- Solution to linear diophantine equation with constants a b k\ndef LDE (a:int) (b:int) (k:int): Prop := \u2203 x y: int, a*x + b*y = k\n\ntheorem WOP {k: nat} (p:nat \u2192 Prop) (H: p k): \u2203 n: nat, p n \u2227 (\u2200 y:nat, p y \u2192 y \u2265 n) :=\nbegin\n    revert H,\n    apply @nat.strong_induction_on (\u03bb h, p h \u2192 (\u2203 (n : \u2115), p n \u2227 \u2200 (y : \u2115), p y \u2192 y \u2265 n)) k,\n    intros x Hx Hpx,\n    induction x,\n    apply exists.intro 0,\n    split, exact Hpx,\n    intros, exact nat.zero_le y,\n    cases classical.em (\u2203 y, y < nat.succ a \u2227 p y),\n    cases a_1,\n    apply Hx, apply a_2.1, apply a_2.2,\n    apply exists.intro (nat.succ a),\n    split, assumption,\n    intros,\n    by_contradiction,\n    apply a_1,\n    apply exists.intro y,\n    exact \u27e8lt_of_not_ge a_3,a_2\u27e9\nend\n\n--\n\nlemma SwapSums (a b x : int) : (a-b) + (-x + x) = (a-x) - (b-x) :=\nbegin\n    simp, rw [add_comm x], simp\nend\n\nlemma NegCommViaMul (a:int) (b:int) : (-1)*(a - b) = b - a := by simp\n\nlemma simplifyTransum (a: int) (b: int) (c: int) : (a-b) + (b-c) = a - c := by simp [add_assoc]\n\ntheorem Mreflex (a:int) (m: int): cong a a m :=\nbegin\n    unfold cong,\n    apply exists.intro (0:\u2124),\n    simp\nend\n\ntheorem Msymmetric {a b : int} {m: int} (H1: cong a b m): cong b a m :=\nbegin\n    cases H1,\n    apply exists.intro (-a_1),\n    simp,\n    rw \u2190a_2,\n    simp\nend\n\ntheorem Mtrans {a b c: int} (m: nat) (H1: cong a b m) (H2: cong b c m): cong a c m :=\nbegin\n    cases H1,\n    cases H2,\n    apply exists.intro (a_1 + a_3),\n    rw [mul_add,\u2190a_2,\u2190a_4],\n    simp,\n    rw [\u2190add_assoc b],\n    simp\nend\n\ntheorem Mmul {x a b: int} (n:int) (H1: cong a b n) : cong (a*x) (b*x) n:=\nbegin\n    cases H1,\n    apply exists.intro (a_1*x),\n    rw [\u2190mul_assoc,\u2190a_2,sub_mul]\nend \n\ntheorem Msub {a b: int} {n:nat} (x:int) (H1: cong a b n) : cong (a-x) (b-x) n:=\nbegin\n    unfold cong at *,\n    simp at *,\n    rw [add_comm x,add_assoc],\n    simp,\n    exact H1\nend \n\ntheorem MinsertLeft {a b c: int} {n:int} (H1: cong a b n) (H2: a = c): cong c b n := begin\n    rw H2 at H1,\n    exact H1\nend\n\ntheorem MinsertRight {a b c: int} {n:int} (H1: cong a b n) (H2: b = c): cong a c n:=\nbegin\n    rw H2 at H1,\n    exact H1\nend\n\ntheorem Madd {a b: int} {n:nat} (x: int) (H1: cong a b n) : cong (a+x) (b+x) n:=\nbegin\n    unfold cong at *,\n    simp at *,\n    rw [add_comm x,add_assoc],\n    simp,\n    exact H1\nend\n\ntheorem Mcancel {p:nat} {a b x} (H1: is_prime p) (H2: cong (x*a) (x*b) p): (cong a b p) \u2228 \u2191p \u2223 x  :=\nbegin\n    unfold is_prime at H1,\n    unfold cong at *,\n    rw \u2190mul_sub at H2,\n    simp at *,\n    cases H2,\n    cases (H1 x (a-b) _),\n    left, exact a_3,\n    right, exact a_3,\n    exact \u27e8a_1,a_2\u27e9\nend \n\ntheorem MDsum {a b c d n: int} (H1: cong a b n) (H2: cong c d n): cong (a+c) (b+d) n :=\nbegin\n    unfold cong at *,\n    simp [add_assoc],\n    rw [add_comm c,add_assoc,add_comm (-d),\u2190add_assoc],\n    cases H1,\n    cases H2,\n    simp at a_2,\n    simp at a_4,\n    rw [a_2,a_4,\u2190mul_add],\n    apply exists.intro (a_1+a_3),\n    refl\nend\n\ntheorem basicInequality {a b : int} (H1: b \u2223 a) (HA: a > 0) : a \u2265 b :=\nbegin\n    cases b,\n    cases a_1,\n    apply le_of_lt HA,\n    cases H1,\n    simp at *,\n    rw nat.succ_eq_add_one,\n    change a \u2265 a_1+1,\n    apply int.add_one_le_of_lt,\n    cases a_2,\n    cases a_2,\n    change a = 0*(a_1+1) at a_3,\n    simp at a_3,\n    apply false.elim (ne_of_lt HA a_3.symm),\n    rw a_3,\n    change (a_1:\u2124) < \u2191((nat.succ a_2) * (nat.succ a_1)),\n    suffices : 1 * a_1 < (nat.succ a_2) * (nat.succ a_1),\n        simp at *,\n        apply int.coe_nat_lt_coe_nat_of_lt,\n        exact this,\n    apply mul_lt_mul',\n        apply nat.le_add_left,\n        apply nat.lt_succ_self,\n        apply nat.zero_le,\n        apply nat.zero_lt_succ,\n    have HA1: a \u2264 0,\n        apply int.le_of_lt,\n        apply int.neg_of_sign_eq_neg_one,\n        rw a_3,\n        apply int.sign_mul,\n    apply false.elim (((lt_iff_not_ge _ _).1 HA) HA1),\n    apply le_of_lt,\n    apply lt_of_lt_of_le,\n    apply int.neg_of_sign_eq_neg_one,\n    simp [int.sign],\n    apply le_of_lt HA\nend\n\n-- Division algorithm\n-- depedencies on data.int.basic and data.int.order\ntheorem DivAlgo (a : int) (b : int) (Hb : b>0): \u2203 q r : int, a = b*q + r \u2227 0 \u2264 r \u2227 b > r :=\nbegin\n    apply exists.intro (a/b),\n    apply exists.intro (a%b),\n    split,\n    rw add_comm,\n    rw int.mod_add_div,\n    split,\n    apply int.mod_nonneg a (int.ne_of_lt Hb).symm,\n    apply int.mod_lt_of_pos, exact Hb\nend\n\n--Lemma for proving that Z is a principal ideal domain later on\n\nlemma LDEsimp {a b p :int} (W1: (LDE a b p \u2227 p > 0) \u2227 (\u2200 (q: int), LDE a b q \u2227 q > 0 \u2192 q \u2265 p)) : p \u2223 a :=\nbegin\n    cases W1.1.1 with x W2,\n    cases W2 with y W3,\n    have App: \u2203 m n: int, a = p*m + n \u2227 0 \u2264 n \u2227 p > n, from DivAlgo a p W1.1.2,\n    cases App with m D1,\n    cases D1 with n D,\n    have D1 := D.1,\n    rw \u2190W3 at D1,\n    have A: a*(1-x*m) + b*(-(y*m)) = n,\n        simp [mul_add],\n        rw [\u2190neg_add,\u2190mul_assoc,\u2190mul_assoc],\n        apply add_neg_eq_of_eq_add,\n        rw [\u2190add_mul,add_comm],\n        apply D1,\n    have Z1: n = 0,\n        cases lt_or_eq_of_le D.2.1,\n            have C0: LDE a b n := \u27e81-x*m,\u27e8-(y*m),A\u27e9\u27e9,\n            have C1: n \u2265 p := W1.2 n \u27e8C0,a_1\u27e9,\n            apply false.elim ((not_lt_of_ge C1) D.2.2),\n            simp [a_1],\n    simp [W3,Z1] at D1,\n    exact \u27e8m,D1\u27e9\nend\n\nlemma LDEcomm {a b p: int} (H: LDE a b p) : LDE b a p :=\nbegin\n    cases H,\n    cases a_2,\n    rw add_comm at a_3,\n    apply exists.intro,\n    apply exists.intro,\n    exact a_3\nend\n\nlemma PisGCD {j b p: int} (W2: p > 0) (W11: LDE j b p) (y: int): y \u2223 j \u2227 y \u2223 b \u2192 p \u2265 y :=\nbegin\n    intro P,\n    have F: y \u2223 p,\n        cases P.1,\n        cases P.2,\n        simp [LDE] at *,\n        cases W11,\n        cases a_5,\n        rw [a_1,a_3,mul_assoc,mul_assoc,\u2190mul_add] at a_6,\n        simp [has_dvd.dvd],\n        exact \u27e8_,a_6.symm\u27e9,\n    exact basicInequality F W2\nend\n\ntheorem mul_sign : \u2200 (i : int), i * int.sign i = int.nat_abs i\n| (n+1:\u2115) := by {simp [int.sign], rw \u2190int.abs_eq_nat_abs, refl}\n| 0       := by {simp [int.sign], refl}\n| -[1+ n] := by {simp [int.sign], refl}\n\ntheorem sign_mul : \u2200 (i : int), int.sign i * i = int.nat_abs i\n| (n+1:\u2115) := by {simp [int.sign], rw \u2190int.abs_eq_nat_abs, refl}\n| 0       := by {simp [int.sign], refl}\n| -[1+ n] := by {simp [int.sign], refl}\n\ntheorem nat_le_int {j b : \u2124} {n : \u2115} (hn : \u2200 (y : \u2115), LDE j b y \u2227 y > 0 \u2192 y \u2265 n) {q : \u2124} (hq : LDE j b q \u2227 q > 0) : q \u2265 n :=\nbegin\n    have hqq : q = \u2191(int.nat_abs q),\n    induction q,\n    refl,\n    exfalso,\n    apply not_le_of_gt hq.2,\n    apply le_of_lt,\n    apply (int.sign_eq_neg_one_iff_neg _).1,\n    simp [int.sign],\n    have hqn : int.nat_abs q \u2265 n,\n    apply hn,\n    exact \u27e8hqq \u25b8 hq.1, (int.nat_abs_pos_of_ne_zero (int.ne_of_lt hq.2).symm)\u27e9,\n    have hqn := int.coe_nat_le_coe_nat_of_le hqn,\n    exact hqq.symm \u25b8 hqn,\nend\n\ntheorem IntegersFormPID (j : int) (b : int): LDE j b (int.gcd j b) :=\nlet p := int.gcd j b in\nbegin\n    cases classical.em (j=0),\n    rw a,\n    unfold LDE,\n    simp [int.gcd],\n    change \u2203 (y : \u2124), b * y = \u2191(nat.gcd 0 (int.nat_abs b)),\n    rw nat.gcd_zero_left,\n    apply exists.intro,\n    exact mul_sign b,\n    have H : \u2203 n: nat, (LDE j b n \u2227 n > 0) \u2227 (\u2200 y:nat, (LDE j b y \u2227 y > 0) \u2192 y \u2265 n),\n        apply @WOP (int.nat_abs j + int.nat_abs b) (\u03bb h, LDE j b h \u2227 h > 0),\n        split,\n        apply exists.intro (int.sign j),\n        apply exists.intro (int.sign b),\n        rw [mul_sign,mul_sign],\n        refl,\n        have H: int.nat_abs j > 0,\n            apply nat.lt_of_le_and_ne,\n            apply nat.zero_le,\n            intro H, apply a, exact int.eq_zero_of_nat_abs_eq_zero H.symm,\n        apply nat.add_pos_left H,\n    cases H with n hn,\n    have Hj : \u2191n \u2223 j,\n        apply LDEsimp,\n        split,\n        split,\n        exact hn.1.1,\n        exact int.coe_nat_lt_coe_nat_of_lt hn.1.2,\n        intros q hq,\n        apply nat_le_int,\n        intros y hy,\n        exact hn.2 y hy,\n        exact hq,\n    have Hb : \u2191n \u2223 b,\n        apply LDEsimp,\n        split,\n        split,\n        exact LDEcomm hn.1.1,\n        exact int.coe_nat_lt_coe_nat_of_lt hn.1.2,\n        intros q hq,\n        apply nat_le_int,\n        intros y hy,\n        exact hn.2 y hy,\n        rw (iff.intro LDEcomm LDEcomm),\n        exact hq,\n    have Hp : nat.gcd (int.nat_abs j) (int.nat_abs b) = p, refl,\n    cases (nat.gcd_dvd_left (int.nat_abs j) (int.nat_abs b)),\n    rw Hp at a_2,\n    have a_2 : int.sign j * int.nat_abs j = int.sign j * p * a_1 := by {rw [a_2,mul_assoc], refl},\n    rw int.sign_mul_nat_abs at a_2,\n    have Hpn : n \u2223 p,\n        unfold has_dvd.dvd at *,\n        cases Hj,\n        cases Hb,\n        apply nat.dvd_gcd,\n        have a_4 : int.nat_abs j = n * int.nat_abs a_3,\n        rw [a_4,int.nat_abs_mul], refl,\n        exact exists.intro _ a_4,\n        have a_6 : int.nat_abs b = n * int.nat_abs a_5,\n        rw [a_6,int.nat_abs_mul], refl,\n        exact exists.intro _ a_6,\n    have Hnp : p \u2223 n,\n        have hj : p \u2223 int.nat_abs j := nat.gcd_dvd_left (int.nat_abs j) (int.nat_abs b),\n        have hb : p \u2223 int.nat_abs b := nat.gcd_dvd_right (int.nat_abs j) (int.nat_abs b),\n        have h := hn.1.1,\n        unfold LDE at h,\n        cases hj,\n        cases hb,\n        have a_4 : j = p * (a_3 * int.sign j),\n            suffices : int.sign j * int.nat_abs j = p * (a_3 * int.sign j),\n            rw [int.sign_mul_nat_abs] at this, exact this,\n            rw a_4,\n            simp, refl,\n        have a_6 : b = p * (a_5 * int.sign b),\n            suffices : int.sign b * int.nat_abs b = p * (a_5 * int.sign b),\n            rw [int.sign_mul_nat_abs] at this, exact this,\n            rw a_6,\n            simp, refl,\n        cases hn.1.1,\n        cases a_8,\n        rw [a_4,a_6,mul_assoc,mul_assoc,mul_assoc,mul_assoc,\u2190mul_add] at a_9,\n        have a_9 := congr_arg int.nat_abs a_9,\n        rw [int.nat_abs_mul] at a_9,\n        change p * _ = n at a_9,\n        apply exists.intro,\n        apply a_9_1.symm,\n    have H : n = p := nat.dvd_antisymm Hpn Hnp,\n    rw H at hn,\n    exact hn.1.1\nend\n", "meta": {"author": "TudorTitan", "repo": "Lean_ElementaryNT", "sha": "e9fa9e1db315fa7aca88666aee9910d5d9d34a11", "save_path": "github-repos/lean/TudorTitan-Lean_ElementaryNT", "path": "github-repos/lean/TudorTitan-Lean_ElementaryNT/Lean_ElementaryNT-e9fa9e1db315fa7aca88666aee9910d5d9d34a11/Congruence_Manipulation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7348305369239259}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module tactic.compute_degree\n! leanprover-community/mathlib commit 2d915e4ef8f55de94a850f0e5363ba8b25dc4c29\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Polynomial.Degree.Lemmas\n\n/-! # `compute_degree_le` a tactic for computing degrees of polynomials\n\nThis file defines the tactic `compute_degree_le`.\n\nUsing `compute_degree_le` when the goal is of the form `f.nat_degree \u2264 d`, tries to solve the goal.\nIt may leave side-goals, in case it is not entirely successful.\n\nSee the doc-string for more details.\n\n##  Future work\n\n* Deal with goals of the form `f.(nat_)degree = d` (PR #14040 does exactly this).\n* Add better functionality to deal with exponents that are not necessarily closed natural numbers.\n* Add support for proving goals of the from `f.(nat_)degree \u2260 0`.\n* Make sure that `degree` and `nat_degree` are equally supported.\n\n##  Implementation details\n\nWe start with a goal of the form `f.(nat_)degree \u2264 d`.  Recurse into `f` breaking apart sums,\nproducts and powers.  Take care of numerals, `C a, X (^ n), monomial a n` separately. -/\n\n\nnamespace Tactic\n\nnamespace ComputeDegree\n\nopen Expr Polynomial\n\n-- failed to format: unknown constant 'term.pseudo.antiquot'\n/--\n      `guess_degree e` assumes that `e` is an expression in a polynomial ring, and makes an attempt\n      at guessing the `nat_degree` of `e`.  Heuristics for `guess_degree`:\n      * `0, 1, C a`,      guess `0`,\n      * `polynomial.X`,   guess `1`,\n      *  `bit0/1 f, -f`,  guess `guess_degree f`,\n      * `f + g, f - g`,   guess `max (guess_degree f) (guess_degree g)`,\n      * `f * g`,          guess `guess_degree f + guess_degree g`,\n      * `f ^ n`,          guess `guess_degree f * n`,\n      * `monomial n r`,   guess `n`,\n      * `f` not as above, guess `f.nat_degree`.\n      \n      The guessed degree should coincide with the behaviour of `resolve_sum_step`:\n      `resolve_sum_step` cannot solve a goal `f.nat_degree \u2264 d` if `guess_degree f < d`.\n       -/\n    unsafe\n  def\n    guess_degree\n    : expr \u2192 tactic expr\n    | q( Zero.zero ) => pure q( 0 )\n      | q( One.one ) => pure q( 0 )\n      | q( - $ ( f ) ) => guess_degree f\n      | app q( \u21d1 C ) x => pure q( 0 )\n      | q( X ) => pure q( 1 )\n      | q( bit0 $ ( a ) ) => guess_degree a\n      | q( bit1 $ ( a ) ) => guess_degree a\n      |\n        q( $ ( a ) + $ ( b ) )\n        =>\n        do\n          let [ da , db ] \u2190 [ a , b ] . mapM guess_degree\n            pure <| expr.mk_app q( ( max : \u2115 \u2192 \u2115 \u2192 \u2115 ) ) [ da , db ]\n      |\n        q( $ ( a ) - $ ( b ) )\n        =>\n        do\n          let [ da , db ] \u2190 [ a , b ] . mapM guess_degree\n            pure <| expr.mk_app q( ( max : \u2115 \u2192 \u2115 \u2192 \u2115 ) ) [ da , db ]\n      |\n        q( $ ( a ) * $ ( b ) )\n        =>\n        do\n          let [ da , db ] \u2190 [ a , b ] . mapM guess_degree\n            pure <| expr.mk_app q( ( ( \u00b7 + \u00b7 ) : \u2115 \u2192 \u2115 \u2192 \u2115 ) ) [ da , db ]\n      |\n        q( $ ( a ) ^ $ ( b ) )\n        =>\n        do let da \u2190 guess_degree a pure <| expr.mk_app q( ( ( \u00b7 * \u00b7 ) : \u2115 \u2192 \u2115 \u2192 \u2115 ) ) [ da , b ]\n      | app q( \u21d1 ( monomial $ ( n ) ) ) x => pure n\n      |\n        e\n        =>\n        do\n          let q( @ Polynomial $ ( R ) $ ( inst ) ) \u2190 infer_type e\n            let pe \u2190 to_expr ` `( @ natDegree $ ( R ) $ ( inst ) ) true false\n            pure <| expr.mk_app pe [ e ]\n#align tactic.compute_degree.guess_degree tactic.compute_degree.guess_degree\n\n-- failed to format: unknown constant 'term.pseudo.antiquot'\n/--\n      `resolve_sum_step` assumes that the current goal is of the form `f.nat_degree \u2264 d`, failing\n      otherwise.  It tries to make progress on the goal by progressing into `f` if `f` is\n      * a sum, difference, opposite, product, or a power;\n      * a monomial;\n      * `C a`;\n      * `0, 1` or `bit0 a, bit1 a` (to deal with numerals).\n      \n      The side-goals produced by `resolve_sum_step` are either again of the same shape `f'.nat_degree \u2264 d`\n      or of the form `m \u2264 n`, where `m n : \u2115`.\n      \n      If `d` is less than `guess_degree f`, this tactic will create unsolvable goals.\n      -/\n    unsafe\n  def\n    resolve_sum_step\n    : tactic Unit\n    :=\n      do\n        let t \u2190 target >>= instantiate_mvars\n          let\n            q( natDegree $ ( tl ) \u2264 $ ( tr ) )\n              \u2190\n              whnf t reducible\n              | throwError \"Goal is not of the form `f.nat_degree \u2264 d`\"\n          match\n            tl\n            with\n            |\n                q( $ ( tl1 ) + $ ( tl2 ) )\n                =>\n                refine ` `( ( natDegree_add_le_iff_left _ _ _ ) . mpr _ )\n              | q( $ ( tl1 ) - $ ( tl2 ) ) => refine ` `( ( natDegree_sub_le_iff_left _ ) . mpr _ )\n              |\n                q( $ ( tl1 ) * $ ( tl2 ) )\n                =>\n                do\n                  let [ d1 , d2 ] \u2190 [ tl1 , tl2 ] . mapM guess_degree\n                    refine\n                      `\n                        `(\n                          natDegree_mul_le . trans\n                            <|\n                            ( add_le_add _ _ ) . trans ( _ : $ ( d1 ) + $ ( d2 ) \u2264 $ ( tr ) )\n                          )\n              | q( - $ ( f ) ) => refine ` `( ( natDegree_neg _ ) . le . trans _ )\n              | q( X ^ $ ( n ) ) => refine ` `( ( natDegree_X_pow_le $ ( n ) ) . trans _ )\n              |\n                app q( \u21d1 ( @ monomial $ ( R ) $ ( inst ) $ ( n ) ) ) x\n                =>\n                refine ` `( ( natDegree_monomial_le $ ( x ) ) . trans _ )\n              |\n                app q( \u21d1 C ) x\n                =>\n                refine ` `( ( natDegree_C $ ( x ) ) . le . trans ( Nat.zero_le $ ( tr ) ) )\n              | q( X ) => refine ` `( natDegree_X_le . trans _ )\n              | q( Zero.zero ) => refine ` `( natDegree_zero . le . trans ( Nat.zero_le _ ) )\n              | q( One.one ) => refine ` `( natDegree_one . le . trans ( Nat.zero_le _ ) )\n              | q( bit0 $ ( a ) ) => refine ` `( ( natDegree_bit0 $ ( a ) ) . trans _ )\n              | q( bit1 $ ( a ) ) => refine ` `( ( natDegree_bit1 $ ( a ) ) . trans _ )\n              |\n                q( $ ( tl1 ) ^ $ ( n ) )\n                =>\n                do\n                  refine ` `( natDegree_pow_le . trans _ )\n                    refine\n                      `\n                        `(\n                          dite\n                            ( $ ( n ) = 0 )\n                              (\n                                fun\n                                  n0\n                                    : $ ( n ) = 0\n                                    =>\n                                    by simp only [ n0 , MulZeroClass.zero_mul , zero_le ]\n                                )\n                              _\n                          )\n                    let n0 \u2190 get_unused_name \"n0\" >>= intro\n                    refine\n                      `\n                        `(\n                          ( mul_comm _ _ ) . le . trans\n                            ( ( Nat.le_div_iff_mul_le' ( Nat.pos_of_ne_zero $ ( n0 ) ) ) . mp _ )\n                          )\n                    let\n                      lem1\n                        \u2190\n                        to_expr ` `( Nat.mul_div_cancel _ ( Nat.pos_of_ne_zero $ ( n0 ) ) ) tt ff\n                    let lem2 \u2190 to_expr ` `( Nat.div_self ( Nat.pos_of_ne_zero $ ( n0 ) ) ) tt ff\n                    focus1\n                        (\n                          refine ` `( ( $ ( n0 ) rfl ) . elim )\n                            <|>\n                            rewrite_target lem1 <|> rewrite_target lem2\n                          )\n                      <|>\n                      skip\n              | e => throwError \"'{ \u2190 e }' is not supported\"\n#align tactic.compute_degree.resolve_sum_step tactic.compute_degree.resolve_sum_step\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/\n/-- `norm_assum` simply tries `norm_num` and `assumption`.\nIt is used to try to discharge as many as possible of the side-goals of `compute_degree_le`.\nSeveral side-goals are of the form `m \u2264 n`, for natural numbers `m, n` or of the form `c \u2260 0`,\nwith `c` a coefficient of the polynomial `f` in question. -/\nunsafe def norm_assum : tactic Unit :=\n  try sorry >> try assumption\n#align tactic.compute_degree.norm_assum tactic.compute_degree.norm_assum\n\n-- failed to format: unknown constant 'term.pseudo.antiquot'\n/--\n      `eval_guessing n e` takes a natural number `n` and an expression `e` and gives an\n      estimate for the evaluation of `eval_expr' \u2115 e`.  It is tailor made for estimating degrees of\n      polynomials.\n      \n      It decomposes `e` recursively as a sequence of additions, multiplications and `max`.\n      On the atoms of the process, `eval_guessing` tries to use `eval_expr' \u2115`, resorting to using\n      `n` if `eval_expr' \u2115` fails.\n      \n      For use with degree of polynomials, we mostly use `n = 0`. -/\n    unsafe\n  def\n    eval_guessing\n    ( n : \u2115 ) : expr \u2192 tactic \u2115\n    | q( $ ( a ) + $ ( b ) ) => ( \u00b7 + \u00b7 ) <$> eval_guessing a <*> eval_guessing b\n      | q( $ ( a ) * $ ( b ) ) => ( \u00b7 * \u00b7 ) <$> eval_guessing a <*> eval_guessing b\n      | q( max $ ( a ) $ ( b ) ) => max <$> eval_guessing a <*> eval_guessing b\n      | e => eval_expr' \u2115 e <|> pure n\n#align tactic.compute_degree.eval_guessing tactic.compute_degree.eval_guessing\n\n/-- A general description of `compute_degree_le_aux` is in the doc-string of `compute_degree`.\nThe difference between the two is that `compute_degree_le_aux` makes no effort to close side-goals,\nnor fails if the goal does not change. -/\nunsafe def compute_degree_le_aux : tactic Unit := do\n  try <| refine ``(degree_le_natDegree.trans (WithBot.coe_le_coe.mpr _))\n  let q(natDegree $(tl) \u2264 $(tr)) \u2190 target |\n    fail \"Goal is not of the form\\n`f.nat_degree \u2264 d` or `f.degree \u2264 d`\"\n  let expected_deg \u2190 guess_degree tl >>= eval_guessing 0\n  let deg_bound \u2190 eval_expr' \u2115 tr <|> pure expected_deg\n  if deg_bound < expected_deg then\n      fail\n        s! \"the given polynomial has a term of expected degree\n          at least '{expected_deg}'\"\n    else repeat <| resolve_sum_step\n#align tactic.compute_degree.compute_degree_le_aux tactic.compute_degree.compute_degree_le_aux\n\nend ComputeDegree\n\nnamespace Interactive\n\nopen ComputeDegree Polynomial\n\n/-- `compute_degree_le` tries to solve a goal of the form `f.nat_degree \u2264 d` or `f.degree \u2264 d`,\nwhere `f : R[X]` and `d : \u2115` or `d : with_bot \u2115`.\n\nIf the given degree `d` is smaller than the one that the tactic computes,\nthen the tactic suggests the degree that it computed.\n\nExamples:\n\n```lean\nopen polynomial\nopen_locale polynomial\n\nvariables {R : Type*} [semiring R] {a b c d e : R}\n\nexample {F} [ring F] {a : F} {n : \u2115} (h : n \u2264 10) :\n  nat_degree (X ^ n + C a * X ^ 10 : F[X]) \u2264 10 :=\nby compute_degree_le\n\nexample : nat_degree (7 * X : R[X]) \u2264 1 :=\nby compute_degree_le\n\nexample {p : R[X]} {n : \u2115} {p0 : p.nat_degree = 0} :\n (p ^ n).nat_degree \u2264 0 :=\nby compute_degree_le\n```\n-/\nunsafe def compute_degree_le : tactic Unit :=\n  focus1 do\n    check_target_changes compute_degree_le_aux\n    try <| any_goals' norm_assum\n#align tactic.interactive.compute_degree_le tactic.interactive.compute_degree_le\n\nadd_tactic_doc\n  { Name := \"compute_degree_le\"\n    category := DocCategory.tactic\n    declNames := [`tactic.interactive.compute_degree_le]\n    tags := [\"arithmetic\", \"finishing\"] }\n\nend Interactive\n\nend Tactic\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Tactic/ComputeDegree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7348305264633964}}
{"text": "import game.limits.L01defs\nimport game.limits.seq_cauchyBdd\n\nnamespace xena -- hide\n\nnotation `|` x `|` := abs x -- hide\n\n\n/-\nRelationship convergent/Cauchy sequences.\n\nWork in progress.\n-/\n\n/- Lemma\nA convergent sequence of real numbers is a Cauchy sequence.\nProve \"if and only if\": WIP. \n-/\nlemma conv_iff_cauchy (a : \u2115 \u2192 \u211d) : \n    is_convergent a \u2192  is_Cauchy a :=\nbegin\n  --split,\n  -- left-right implication: just doing convergent -> Cauchy here\n  -- for the other direction should prove boundedness of Cauchy first\n  intros h e he,\n  set e2 := e / 2 with hde2,\n  have he2 : 0 < e2, from half_pos he,\n  cases h with \u03b1 h\u03b1, \n  have H := h\u03b1 e2 he2,\n  cases H with N hN,\n  use N,\n  intros m n hmn,\n  have hm := hN m hmn.1, \n  have hn := hN n hmn.2,\n  have h1 : a m - a n = (a m - \u03b1) + (\u03b1 - a n), ring,\n  have h2 : | (a m - \u03b1) + (\u03b1 - a n) | \u2264 | a m - \u03b1 | + | \u03b1 - a n |,\n    exact abs_add (a m - \u03b1) (\u03b1 - a n),\n  rw h1,\n  have g1 : |a n - \u03b1| = |\u03b1 - a n|, \n    have g11 : a n - \u03b1 = - ( \u03b1 - a n), norm_num,\n    rw g11, exact abs_neg _,\n  rw g1 at hn,\n  linarith,\n  -- right-left implication\n  --intro H,\n  --sorry,\n\n\nend\n\nend xena -- hide\n\n-- begin hide\n--example (a b c d : \u211d) (h1 : a \u2264 b + c) : a - b \u2264 c  := by library_search\n--example ( a : \u211d ) : |a| = | - a | := by library_search\n-- end hide\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/limits/seq_convCauchy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7348305238914149}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebraic_geometry.prime_spectrum\nimport Mathlib.ring_theory.polynomial.basic\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\nThe morphism `Spec R[x] --> Spec R` induced by the natural inclusion `R --> R[x]` is an open map.\n-/\n\nnamespace algebraic_geometry\n\n\nnamespace polynomial\n\n\n/-- Given a polynomial `f \u2208 R[x]`, `image_of_Df` is the subset of `Spec R` where at least one\nof the coefficients of `f` does not vanish.  Lemma `image_of_Df_eq_comap_C_compl_zero_locus`\nproves that `image_of_Df` is the image of `(zero_locus {f})\u1d9c` under the morphism\n`comap C : Spec R[x] \u2192 Spec R`. -/\ndef image_of_Df {R : Type u_1} [comm_ring R] (f : polynomial R) : set (prime_spectrum R) :=\n  set_of fun (p : prime_spectrum R) => \u2203 (i : \u2115), \u00acpolynomial.coeff f i \u2208 prime_spectrum.as_ideal p\n\ntheorem is_open_image_of_Df {R : Type u_1} [comm_ring R] {f : polynomial R} : is_open (image_of_Df f) := sorry\n\n/-- If a point of `Spec R[x]` is not contained in the vanishing set of `f`, then its image in\n`Spec R` is contained in the open set where at least one of the coefficients of `f` is non-zero.\nThis lemma is a reformulation of `exists_coeff_not_mem_C_inverse`. -/\ntheorem comap_C_mem_image_of_Df {R : Type u_1} [comm_ring R] {f : polynomial R} {I : prime_spectrum (polynomial R)} (H : I \u2208 (prime_spectrum.zero_locus (singleton f)\u1d9c)) : prime_spectrum.comap polynomial.C I \u2208 image_of_Df f :=\n  polynomial.exists_coeff_not_mem_C_inverse (iff.mp prime_spectrum.mem_compl_zero_locus_iff_not_mem H)\n\n/-- The open set `image_of_Df f` coincides with the image of `basic_open f` under the\nmorphism `C\u207a : Spec R[x] \u2192 Spec R`. -/\ntheorem image_of_Df_eq_comap_C_compl_zero_locus {R : Type u_1} [comm_ring R] {f : polynomial R} : image_of_Df f = prime_spectrum.comap polynomial.C '' (prime_spectrum.zero_locus (singleton f)\u1d9c) := sorry\n\n/--  The morphism `C\u207a : Spec R[x] \u2192 Spec R` is open. -/\ntheorem is_open_map_comap_C {R : Type u_1} [comm_ring R] : is_open_map (prime_spectrum.comap polynomial.C) := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebraic_geometry/is_open_comap_C.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8031738057795402, "lm_q1q2_score": 0.7348244875239207}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 2 : `true` and `false`\n\nWe learn about the `true` and `false` propositions.\n\n## Tactics you will need\n\nTo solve the levels on this sheet you will need to know all previous\ntactics, plus the following two new ones. Check out their explanations\nin the course book. Or just try them out and hover over them to see\nif you can understand what's going on.\n\n* `triv`\n* `exfalso`\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\n\n\nexample : true :=\nbegin\n  triv,\nend\n\nexample : true \u2192 true :=\nbegin\n  intro h, triv, \nend\n\nexample : false \u2192 true :=\nbegin\n  intro q,exfalso,triv,\nend\n\nexample : false \u2192 false :=\nbegin\n  triv,\nend\n\nexample : (true \u2192 false) \u2192 false :=\nbegin\n  intro q,exfalso,apply q,triv, \nend\n\nexample : false \u2192 P :=\nbegin\n  intro q,exfalso,triv,\nend\n\nexample : true \u2192 false \u2192 true \u2192 false \u2192 true \u2192 false :=\nbegin\n  intros q w e r t,triv,\nend\n\nexample : P \u2192 ((P \u2192 false) \u2192 false) :=\nbegin\n  intros p pf,apply pf,assumption,\nend\n\nexample : (P \u2192 false) \u2192 P \u2192 Q :=\nbegin\n  intros pf p,exfalso,apply pf,assumption,\nend\n\nexample : (true \u2192 false) \u2192 P :=\nbegin\n  intro q, exfalso,apply q,triv,\nend", "meta": {"author": "yakimk", "repo": "lean2022", "sha": "145d03ca2f5a8d2508de05fe78597299051fb8e9", "save_path": "github-repos/lean/yakimk-lean2022", "path": "github-repos/lean/yakimk-lean2022/lean2022-145d03ca2f5a8d2508de05fe78597299051fb8e9/src/section01logic/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7348244813499057}}
{"text": "/-\nThis file defines natural sequences, here defined as functions \u2115 \u2192 \u2115\nAlso defined here are the comparisons =, \u2260, <, \u2264 and #\n-/\n\nimport data.nat.basic\n\ndef nat_seq := \u2115 \u2192 \u2115\n\nnotation `\ud835\udca9` := nat_seq\n\nnamespace nat_seq\n\ndef zero : \ud835\udca9 := \u03bb n, 0\n\ndef eq (a b : \ud835\udca9) : Prop := \u2200 n : \u2115, a n = b n\n\ninfix `='`:50 := eq\n\nlemma eq_iff {a b : \ud835\udca9} : a = b \u2194 a =' b := function.funext_iff\n\ndef ne (a b : \ud835\udca9) : Prop := \u00ac a =' b\n\ninfix `\u2260'`:50 := ne\n\ndef lt (a b : \ud835\udca9) : Prop := \u2203 n : \u2115, (\u2200 i : \u2115, i < n \u2192 a i = b i) \u2227 a n < b n\n\ninfix `<` := lt\n\ndef le (a b : \ud835\udca9) : Prop := \u2200 n : \u2115, (\u2200 i : \u2115, i < n \u2192 a i = b i) \u2192 a n \u2264 b n \n\ninfix `\u2264` := le\n\ntheorem le_of_eq (a b : \ud835\udca9) (h : a =' b) : a \u2264 b :=\nbegin\n    intro n,\n    intro hn,\n    rw h,\nend\n\nlemma imp_eq_iff_imp_eq (a b : \ud835\udca9) (n: \u2115) : \n    (\u2200 i : \u2115, i < n \u2192 a i = b i) \u2194 (\u2200 i : \u2115, i < n \u2192 b i = a i) :=\nbegin\n    split,\n    repeat {intro h, intro i, intro hi, symmetry, exact h i hi},\nend\n\nlemma imp_eq_trans (a b c : \ud835\udca9) (n : \u2115)\n    (h\u2081 : \u2200 i : \u2115, i < n \u2192 a i = b i)\n    (h\u2082 : \u2200 i : \u2115, i < n \u2192 b i = c i) :\n    \u2200 i : \u2115, i < n \u2192 a i = c i :=\nbegin\n    intro i,\n    intro hi,\n    have aibi := h\u2081 i hi,\n    rw aibi,\n    exact h\u2082 i hi,\nend\n\n@[trans] theorem eq_trans (a b c : \ud835\udca9) : a =' b \u2192 b =' c \u2192 a =' c :=\nbegin\n    intros ab bc n,\n    rw ab n,\n    exact bc n,\nend\n\n@[symm] theorem eq_symm {a b: \ud835\udca9} : a =' b \u2194 b =' a :=\nbegin\n    split,\n    repeat {intros h n, symmetry, exact h n},\nend\n\n@[refl] theorem eq_refl {a : \ud835\udca9} : a =' a :=\nbegin\n    intro n,\n    refl,\nend\n\n@[symm] theorem ne_symm (a b : \ud835\udca9) : a \u2260' b \u2194 b \u2260' a :=\nbegin\n    repeat {rw ne},\n    rw eq_symm,\nend\n\nlemma lt_eq_lt_le (a b : \ud835\udca9) (n m : \u2115)\n        (h1 : \u2200 i : \u2115, i < n \u2192 a i = b i) (h2 : a m < b m) : \n        n \u2264 m :=\nbegin\n    cases le_or_gt n m with nlem ngtm,\n    {-- case: n \u2264 m\n        exact nlem,\n    },\n    {-- case: m < n\n        exfalso,\n        rw gt_iff_lt at ngtm,\n        have aibi := h1 m ngtm,\n        rw eq_iff_le_not_lt at aibi,\n        exact (and.elim_right aibi) h2,\n    }\nend\n\nlemma lt_eq_ne_le (a b : \ud835\udca9) (n m : \u2115)\n        (h1 : \u2200 i : \u2115, i < n \u2192 a i = b i) (h2 : a m \u2260 b m) :\n        n \u2264 m :=\nbegin\n    rw ne_iff_lt_or_gt at h2,\n    cases h2 with hlt hgt,\n    {-- case: a m < b m\n        exact lt_eq_lt_le a b n m h1 hlt,\n    },\n    {\n        rw gt_iff_lt at hgt,\n        rw imp_eq_iff_imp_eq at h1,\n        exact lt_eq_lt_le b a n m h1 hgt,\n    }\nend\n\n--The following lemma immediately follows from lt_eq_ne_le and n = m \u2194 (n \u2264 m \u2228 m \u2264 n)\n--We will use this in reckless.lean to prove weak_LEM_implies_LLPO\nlemma first_zero_eq (a : \ud835\udca9) (n m : \u2115) (hn1 : \u2200 i : \u2115, i < n \u2192 a i = 0) (hn2 : a n \u2260 0)\n        (hm1 : \u2200 i : \u2115, i < m \u2192 a i = 0) (hm2 : a m \u2260 0) :\n        n = m :=\nbegin\n    rw eq_iff_le_not_lt,\n    split,\n    {-- need to prove: n \u2264 m\n        apply lt_eq_ne_le a zero n m hn1 hm2,\n    },\n    {-- need to prove: \u00acn < m\n        apply not_lt_of_le,\n        apply lt_eq_ne_le a zero m n hm1 hn2,\n    }\nend\n\ntheorem le_of_lt (a b : \ud835\udca9) (less: a < b) : a \u2264 b :=\nbegin\n    rw le,\n    rw lt at less,\n    intro n,\n    intro h,\n    cases less with d hd,\n    cases hd with p q,\n    have hnd := lt_eq_lt_le a b n d h q,\n    rw le_iff_eq_or_lt at hnd,\n    cases hnd with ndeq ndlt,\n    { --case n = d\n        rw \u2190 ndeq at q,\n        exact nat.le_of_lt q,\n    },\n    { --case n < d\n        apply nat.le_of_eq,\n        apply p,\n        exact ndlt,\n    }\nend\n\n@[trans] theorem lt_trans (a b c : \ud835\udca9) : a < b \u2192 b < c \u2192 a < c :=\nbegin\n    intros hab hbc,\n    cases hab with n hn,\n    cases hbc with m hm,\n    cases hn with p\u2081 p\u2082,\n    cases hm with q\u2081 q\u2082,\n    use min n m,\n    split,\n    {--need to prove: \u2200 (i : \u2115), i < min n m \u2192 a i = c i\n        intros i hi,\n        rw lt_min_iff at hi,\n        rw p\u2081 i hi.elim_left,\n        exact q\u2081 i hi.elim_right,\n    },\n    {--need to prove: a (min n m) < c (min n m)\n        cases nat.lt_trichotomy n m with nltm h,\n        {-- n < m\n            rw min_eq_left (nat.le_of_lt nltm),\n            rw \u2190 q\u2081 n nltm,\n            exact p\u2082,\n        },\n        {\n            cases h with neqm mltn,\n            {-- n = m\n                rw neqm at *,\n                rw min_self,\n                exact nat.lt_trans p\u2082 q\u2082,\n            },\n            {-- m < n\n                rw min_eq_right (nat.le_of_lt mltn),\n                rw p\u2081 m mltn,\n                exact q\u2082,\n            }\n        }\n    }\nend\n\n-- Doing a finite amount of comparisons is allowed\nlemma all_eq_or_exists_neq (a b : \ud835\udca9) (n : \u2115): \n    (\u2200 i : \u2115, i < n \u2192 a i = b i) \u2228 (\u2203 i : \u2115, i < n \u2227 (\u2200 j : \u2115, j < i \u2192 a j = b j) \u2227 a i \u2260 b i) :=\nbegin\n    induction n with d hd,\n    {-- case: n = 0\n        left,\n        intro i,\n        intro hi,\n        exfalso,\n        rw \u2190 not_le at hi,\n        exact hi (zero_le i),\n    },\n    {-- case: succ(n)\n        cases hd with all_eq exists_neq,\n        {-- hypothesis: \u2200 i < d, a i = b i\n            have tri := lt_trichotomy (a d) (b d),\n            rw or_comm at tri,\n            rw or_assoc at tri,\n            cases tri with aeqb anb,\n            {-- case: a d = b d\n                left,\n                intro i,\n                intro hi,\n                rw nat.lt_succ_iff_lt_or_eq at hi,\n                cases hi with iltd ieqd,\n                exact all_eq i iltd,\n                rw ieqd,\n                exact aeqb,\n            },\n            {-- case: a d \u2260 b d\n                right,\n                use d,\n                split,\n                exact nat.lt_succ_self d,\n                split,\n                exact all_eq,\n                rwa [ne_iff_lt_or_gt, or.comm, gt_iff_lt],\n            }\n        },\n        {-- hypothesis: \u2203 i < d, (\u2200 j < i, a j = b j) \u2227 a i \u2260 b i\n            right,\n            cases exists_neq with i hi,\n            use i,\n            split,\n            exact nat.lt_succ_of_lt (and.elim_left hi),\n            exact and.elim_right hi,\n        }\n    }\nend\n\n\nlemma nat_lt_cotrans (a b : \u2115) (h : a < b) : \u2200 c : \u2115, a < c \u2228 c < b :=\nbegin\n    intro c,\n    induction c with d hd,\n    {-- case: c = d = 0\n        right, -- need to prove: 0 < b\n        have ha := nat.eq_zero_or_pos a,\n        cases ha with hal har,\n        rw hal at h, exact h,\n        rw gt_iff_lt at har,\n        exact nat.lt_trans har h,\n    },\n    {-- case: c = succ(d)\n        cases hd with ad db,\n        {-- case: a < d\n            left,\n            exact nat.lt_trans ad (nat.lt_succ_self d),\n        },\n        {-- case d < b\n            cases db with i hi,\n            {-- b = nat.succ d\n                left,\n                exact h,\n            },\n            {-- b > nat.succ d\n                right,\n                rw nat.lt_succ_iff_lt_or_eq,\n                rw or.comm,\n                rw \u2190 le_iff_eq_or_lt,\n                exact hi,\n            }\n        }\n    }\nend\n\ntheorem lt_cotrans (a b : \ud835\udca9) (h : a < b) : \u2200 c : \ud835\udca9, a < c \u2228 c < b :=\nbegin\n    intro c,\n    rw lt at h,\n    cases h with n hn,\n    cases hn with hnl hnr,\n    cases all_eq_or_exists_neq a c n with all_eq exists_neq,\n    {-- hypothesis all_eq: \u2200 i < n, a i = c i\n        have hlt := nat_lt_cotrans (a n) (b n) hnr,\n        have ltcn := hlt (c n),\n        cases ltcn with ancn cnbn,\n        {-- hypothesis ancn: a n < c n\n            left, -- need to prove: a < c\n            rw lt,\n            use n,\n            exact and.intro all_eq ancn,\n        },\n        {-- hypothesis cnbn: c n < b n\n            right, -- need to prove: c < b\n            rw lt,\n            use n,\n            split,\n            {-- need to prove: \u2200 i < n, c i = b i\n                rw imp_eq_iff_imp_eq a c n at all_eq,\n                exact imp_eq_trans c a b n all_eq hnl,\n            },\n            {-- need to prove: c n < b n\n                exact cnbn,\n            }\n        }\n    },\n    {-- hypothesis exists_neq: \u2203 i < n, a i \u2260 c i\n        cases exists_neq with i hi,\n        cases hi with hil hi2,\n        cases hi2 with him hir,\n        rw ne_iff_lt_or_gt at hir,\n        cases hir with ailtci aigtci,\n        {-- hypothesis ailtci: a i < c i\n            left, -- need to prove: a < c\n            rw lt,\n            use i,\n            split,\n            exact him,\n            exact ailtci,\n        },\n        {-- hypothesis aigtci: i > c i\n            rw gt_iff_lt at aigtci,\n            right, -- need to prove: c < b\n            rw lt,\n            use i,\n            split,\n            {-- need to prove: \u2200 j < i, c j = b j\n                intro j,\n                intro hj,\n                rw \u2190 him j hj,\n                have jltn := nat.lt_trans hj hil,\n                exact hnl j jltn,\n            },\n            {-- need to prove: c i < b i\n                rw hnl i hil at aigtci,\n                exact aigtci,\n            }\n        }\n    }\nend\n\ntheorem le_iff_not_lt (a b : \ud835\udca9) : a \u2264 b \u2194 \u00ac b < a :=\nbegin\n    split,\n    {-- need to prove: a \u2264 b \u2192 \u00ac b < a\n        intro h,\n        intro ex,\n        cases ex with n hn,\n        have g := h n,\n        cases hn with ind blta,\n        rw imp_eq_iff_imp_eq b a n at ind,\n        have aleb := g ind,\n        rw nat.lt_iff_le_not_le at blta,\n        exact and.elim_right blta aleb,\n    },\n    {-- need to prove: \u00ac b < a \u2192 a \u2264 b\n        intros h n hi,\n        cases le_or_gt (a n) (b n) with hle hgt,\n        exact hle, -- case: a \u2264 b\n        exfalso, -- case: b < a\n        rw gt_iff_lt at hgt, \n        apply h,\n        use n,\n        split,\n        {-- need to prove: \u2200 i < n, b i = a i\n            rw imp_eq_iff_imp_eq b a n,\n            exact hi,\n        }, -- need to prove: b n < a n\n        exact hgt,\n    }\nend\n\n-- The following theorem now easily follows from le_iff_not_lt and lt_cotrans\ntheorem le_trans (a b c : \ud835\udca9) : a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c :=\nbegin\n    intro h\u2081,\n    intro h\u2082,\n    rw le_iff_not_lt at *,\n    intro h\u2083,\n    have ltorlt := lt_cotrans c a h\u2083 b,\n    cases ltorlt with cb ba,\n    exact h\u2082 cb,\n    exact h\u2081 ba,\nend\n\ntheorem le_stable (a b : \ud835\udca9) : \u00ac\u00aca \u2264 b \u2192 a \u2264 b :=\nbegin\n    rw le_iff_not_lt,\n    exact not_of_not_not_not,\nend\n\ntheorem eq_of_le_le {a b : \ud835\udca9} (hab : a \u2264 b) (hba : b \u2264 a) : a =' b :=\nbegin\n    intro n,\n    apply nat.strong_induction_on n,\n    intros d hd,\n    rw le at *,\n    have hle := hab d hd,\n    have hge : b d \u2264 a d, by\n    {\n        apply hba,\n        intros i hi,\n        symmetry,\n        exact hd i hi,\n    },\n    exact le_antisymm hle hge,\nend\n\ndef apart (a b : \ud835\udca9) : Prop := \u2203 n, a n \u2260 b n\n\ninfix `#` := apart\n\n-- If two natural sequences are apart from eachother, they are not equal\ntheorem ne_of_apart (a b : \ud835\udca9) : a # b \u2192 a \u2260' b :=\nbegin\n    intros r h,\n    cases r with n hn,\n    apply hn,\n    apply h,\nend\n\ntheorem eq_iff_not_apart (a b : \ud835\udca9) : a =' b \u2194 \u00ac a # b :=\nbegin\n\n    split,\n    {-- a = b \u2192 \u00ac a # b\n        intro h,\n        intro g,\n        cases g with n hn,\n        exact hn (h n),\n    },\n    {-- \u00ac a # b \u2192 a = b\n        intro h,\n        intro n,\n        rwa [apart, not_exists] at h,\n        have g := h n,\n        rwa [ne_iff_lt_or_gt, not_or_distrib] at g,\n        cases lt_trichotomy (a n) (b n) with l r,\n        {-- case: a n < b n, can't happen because \u00ac a n < b n\n            exfalso,\n            exact (and.elim_left g) l,\n        },\n        cases r with rl rr,\n        {-- case: a n = b n, trivial\n            exact rl,\n        },\n        {-- case: b n < a n, can't happen because \u00ac a n > b n\n            exfalso,\n            exact (and.elim_right g) rr,\n        }\n    }\nend\n\ntheorem eq_stable (a b : \ud835\udca9) : \u00ac\u00ac a =' b \u2192 a =' b :=\nbegin\n    rw eq_iff_not_apart,\n    exact not_of_not_not_not,\nend\n\ntheorem apart_iff_lt_or_lt (a b : \ud835\udca9) : a # b \u2194 a < b \u2228 b < a :=\nbegin\n    split,\n    {-- need to prove: a # b \u2192 a < b \u2228 b < a\n        intro ab,\n        cases ab with n hn,\n        have h := all_eq_or_exists_neq a b n,\n        cases h with all_eq exists_neq,\n        {-- case: \u2200 i < n \u2192 a i = b i\n            rw ne_iff_lt_or_gt at hn,\n            cases hn with ab ba,\n            {-- case: a n < b n\n                left,\n                use n,\n                exact and.intro all_eq ab,\n            },\n            {-- case: a n > b n\n                right,\n                use n,\n                rw gt_iff_lt at ba,\n                split,\n                rw imp_eq_iff_imp_eq b a n,\n                exact all_eq,\n                exact ba,\n            }\n        },\n        {-- case: \u2203 i < n, (\u2200 j < i, a j = b j) \u2227 a i \u2260 b i\n            cases exists_neq with i hi,\n            cases hi with iltn r,\n            cases r with ajbj aineqbi,\n            rw ne_iff_lt_or_gt at aineqbi,\n            cases aineqbi with aibi biai,\n            {-- case: a i < b i\n                left,\n                use i,\n                exact and.intro ajbj aibi,\n            },\n            {-- case: b i < a i\n                right,\n                use i,\n                split,\n                rw imp_eq_iff_imp_eq b a i,\n                exact ajbj,\n                rw gt_iff_lt at biai,\n                exact biai,\n            }\n        }\n    },\n    {-- need to prove: a < b \u2228 b < a \u2192 a # b\n        intro aborba,\n        cases aborba with ab ba,\n        {-- case: a < b\n            cases ab with n hn,\n            use n,\n            rw ne_iff_lt_or_gt,\n            left,\n            exact and.elim_right hn,\n        },\n        {-- case: b < a\n            cases ba with n hn,\n            use n,\n            rw ne_iff_lt_or_gt,\n            right,\n            exact and.elim_right hn,\n        }\n    }\nend\n\n-- The following theorem now easily follows from combining lt_cotrans and apart_iff_lt_or_lt\ntheorem apart_cotrans (a b : \ud835\udca9) (h : a # b) : \u2200 c : \ud835\udca9, a # c \u2228 c # b :=\nbegin\n    intro c,\n    repeat {rw apart_iff_lt_or_lt at *},\n    cases h with ab ba,\n    {-- case: a < b\n        cases lt_cotrans a b ab c with ac cb,\n        {-- case: a < c\n            left,\n            left,\n            exact ac,\n        },\n        {-- case: c < b\n            right,\n            left,\n            exact cb,\n        }\n    },\n    {-- case: b < a\n        cases lt_cotrans b a ba c with bc ca,\n        {-- case: b < c\n            right,\n            right,\n            exact bc,\n        },\n        {-- case: c < a\n            left,\n            right,\n            exact ca,\n        }\n    }\nend\n\n@[symm] theorem apart_symm (a b : \ud835\udca9) : a # b \u2194 b # a :=\nbegin\n    split,\n    repeat {\n        intro h,\n        cases h with n hn,\n        use n,\n        symmetry,\n        exact hn,\n    },\nend\n\n-- 0 is the smallest sequence\nlemma zero_le (a : \ud835\udca9) : zero \u2264 a :=\nbegin\n    intros n h,\n    rw zero,\n    simp,\nend\n\nlemma apart_zero_lt (a : \ud835\udca9) (h : a # zero) : zero < a :=\nbegin\n    rw apart_iff_lt_or_lt at h,\n    cases h with alt agt,\n    {-- case: a < 0, impossible\n        exfalso,\n        have h\u2081 := zero_le a,\n        rw le_iff_not_lt at h\u2081,\n        exact h\u2081 alt,\n    },\n    {-- case: 0 < a, trivial\n        exact agt,\n    }\nend\n\n/-\nThere are uncountably (defined positively) many natural sequences.\nThe proof of this theorem is Cantor's Diagonal argument\n-/\ntheorem uncountable (f : \u2115 \u2192 \ud835\udca9) : \u2203 a : \ud835\udca9, \u2200 n : \u2115, a # (f n) :=\nbegin\n    use \u03bb n : \u2115, (f n n) + 1,\n    intro n,\n    use n,\n    exact nat.succ_ne_self (f n n),\nend\n\nend nat_seq", "meta": {"author": "SCRK16", "repo": "Intuitionism", "sha": "a3d9920ae056b39a66e37d1d0e03d246bca1e961", "save_path": "github-repos/lean/SCRK16-Intuitionism", "path": "github-repos/lean/SCRK16-Intuitionism/Intuitionism-a3d9920ae056b39a66e37d1d0e03d246bca1e961/nat_seq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7348244711570708}}
{"text": "import tactic\nvariables P Q : Prop\n\nopen_locale classical\n\n-- BEGIN\nexample (P Q : Prop) : (P \u2192 Q) \u2194 \u00ac P \u2228 Q :=\nbegin\n  split, \n    intro hpq,\n      by_cases h : P,\n        right, \n          exact hpq h,\n        left, \n          exact h, \n    intros hnpq hp,\n      cases hnpq with hnp hq,\n        contradiction,\n        exact hq,\nend\n\n/- using the cases tactic -/\nexample (P Q : Prop) : (P \u2192 Q) \u2194 \u00ac P \u2228 Q :=\nbegin\n  split,\n    intro hpq,\n      by_contra h',\n      push_neg at h',\n      cases h' with h'p h'nq,\n      apply h'nq (hpq (h'p)),\n    intros hnpq hp,\n      cases hnpq with hnp hq,\n      contradiction,\n      exact hq,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/9_Tactics used for classical reasoning/9.5_by_cases/ex1_by_cases_neg_p_or_q.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7348244687103045}}
{"text": "/-\nCopyright (c) 2019 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann, Kyle Miller, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.fib\n! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Init.Data.Nat.Lemmas\nimport Mathlib.Init.Data.Nat.Bitwise\nimport Mathlib.Data.Nat.GCD.Basic\nimport Mathlib.Logic.Function.Iterate\nimport Mathlib.Data.Finset.NatAntidiagonal\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.WLOG\nimport Mathlib.Tactic.Zify\n\n/-!\n# Fibonacci Numbers\n\nThis file defines the fibonacci series, proves results about it and introduces\nmethods to compute it quickly.\n-/\n\n/-!\n# The Fibonacci Sequence\n\n## Summary\n\nDefinition of the Fibonacci sequence `F\u2080 = 0, F\u2081 = 1, F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081`.\n\n## Main Definitions\n\n- `Nat.fib` returns the stream of Fibonacci numbers.\n\n## Main Statements\n\n- `Nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.`.\n- `Nat.fib_gcd`: `fib n` is a strong divisibility sequence.\n- `Nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `Nat.choose` along an antidiagonal.\n- `Nat.fib_succ_eq_succ_sum`: shows that `F\u2080 + F\u2081 + \u22ef + F\u2099 = F\u2099\u208a\u2082 - 1`.\n- `Nat.fib_two_mul` and `nat.fib_two_mul_add_one` are the basis for an efficient algorithm to\n  compute `fib` (see `Nat.fastFib`). There are `bit0`/`bit1` variants of these can be used to\n  simplify `fib` expressions: `simp only [nat.fib_bit0, nat.fib_bit1, nat.fib_bit0_succ,\n  nat.fib_bit1_succ, nat.fib_one, nat.fib_two]`.\n\n## Implementation Notes\n\nFor efficiency purposes, the sequence is defined using `Stream.iterate`.\n\n## Tags\n\nfib, fibonacci\n-/\n\nopen BigOperators\n\nnamespace Nat\n\n\n\n/-- Implementation of the fibonacci sequence satisfying\n`fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`.\n\n*Note:* We use a stream iterator for better performance when compared to the naive recursive\nimplementation.\n-/\n\n-- Porting note: Lean cannot find pp_nodot at the time of this port.\n-- @[pp_nodot]\ndef fib (n : \u2115) : \u2115 :=\n  (((fun p : \u2115 \u00d7 \u2115 => (p.snd, p.fst + p.snd))^[n]) (0, 1)).fst\n#align nat.fib Nat.fib\n\n@[simp]\ntheorem fib_zero : fib 0 = 0 :=\n  rfl\n#align nat.fib_zero Nat.fib_zero\n\n@[simp]\ntheorem fib_one : fib 1 = 1 :=\n  rfl\n#align nat.fib_one Nat.fib_one\n\n@[simp]\n\n\n/-- Shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.` -/\ntheorem fib_add_two {n : \u2115} : fib (n + 2) = fib n + fib (n + 1) := by\n  simp [fib, Function.iterate_succ_apply']\n#align nat.fib_add_two Nat.fib_add_two\n\ntheorem fib_le_fib_succ {n : \u2115} : fib n \u2264 fib (n + 1) := by cases n <;> simp [fib_add_two]\n#align nat.fib_le_fib_succ Nat.fib_le_fib_succ\n\n@[mono]\ntheorem fib_mono : Monotone fib :=\n  monotone_nat_of_le_succ fun _ => fib_le_fib_succ\n#align nat.fib_mono Nat.fib_mono\n\ntheorem fib_pos {n : \u2115} (n_pos : 0 < n) : 0 < fib n :=\n  calc\n    0 < fib 1 := by decide\n    _ \u2264 fib n := fib_mono n_pos\n\n#align nat.fib_pos Nat.fib_pos\n\ntheorem fib_add_two_sub_fib_add_one {n : \u2115} : fib (n + 2) - fib (n + 1) = fib n := by\n  rw [fib_add_two, add_tsub_cancel_right]\n#align nat.fib_add_two_sub_fib_add_one Nat.fib_add_two_sub_fib_add_one\n\ntheorem fib_lt_fib_succ {n : \u2115} (hn : 2 \u2264 n) : fib n < fib (n + 1) :=\n  by\n  rcases exists_add_of_le hn with \u27e8n, rfl\u27e9\n  rw [\u2190 tsub_pos_iff_lt, add_comm 2, fib_add_two_sub_fib_add_one]\n  apply fib_pos (succ_pos n)\n#align nat.fib_lt_fib_succ Nat.fib_lt_fib_succ\n\n/-- `fib (n + 2)` is strictly monotone. -/\ntheorem fib_add_two_strictMono : StrictMono fun n => fib (n + 2) :=\n  by\n  refine' strictMono_nat_of_lt_succ fun n => _\n  rw [add_right_comm]\n  exact fib_lt_fib_succ (self_le_add_left _ _)\n#align nat.fib_add_two_strict_mono Nat.fib_add_two_strictMono\n\ntheorem le_fib_self {n : \u2115} (five_le_n : 5 \u2264 n) : n \u2264 fib n :=\n  by\n  induction' five_le_n with n five_le_n IH\n  \u00b7-- 5 \u2264 fib 5\n    rfl\n  \u00b7 -- n + 1 \u2264 fib (n + 1) for 5 \u2264 n\n    rw [succ_le_iff]\n    calc\n      n \u2264 fib n := IH\n      _ < fib (n + 1) := fib_lt_fib_succ (le_trans (by decide) five_le_n)\n\n#align nat.le_fib_self Nat.le_fib_self\n\n/-- Subsequent Fibonacci numbers are coprime,\n  see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/\ntheorem fib_coprime_fib_succ (n : \u2115) : Nat.coprime (fib n) (fib (n + 1)) :=\n  by\n  induction' n with n ih\n  \u00b7 simp\n  \u00b7 rw [fib_add_two]\n    simp only [coprime_add_self_right]\n    simp [coprime, ih.symm]\n#align nat.fib_coprime_fib_succ Nat.fib_coprime_fib_succ\n\n/-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/\ntheorem fib_add (m n : \u2115) : fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) :=\n  by\n  induction' n with n ih generalizing m\n  \u00b7 simp\n  \u00b7 intros\n    specialize ih (m + 1)\n    rw [add_assoc m 1 n, add_comm 1 n] at ih\n    simp only [fib_add_two, ih]\n    ring\n#align nat.fib_add Nat.fib_add\n\ntheorem fib_two_mul (n : \u2115) : fib (2 * n) = fib n * (2 * fib (n + 1) - fib n) :=\n  by\n  cases n\n  \u00b7 simp\n  \u00b7 rw [Nat.succ_eq_add_one, two_mul, \u2190 add_assoc, fib_add, fib_add_two, two_mul]\n    simp only [\u2190 add_assoc, add_tsub_cancel_right]\n    ring\n#align nat.fib_two_mul Nat.fib_two_mul\n\ntheorem fib_two_mul_add_one (n : \u2115) : fib (2 * n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 :=\n  by\n  rw [two_mul, fib_add]\n  ring\n#align nat.fib_two_mul_add_one Nat.fib_two_mul_add_one\n\nsection deprecated\n\nset_option linter.deprecated false\n\ntheorem fib_bit0 (n : \u2115) : fib (bit0 n) = fib n * (2 * fib (n + 1) - fib n) := by\n  rw [bit0_eq_two_mul, fib_two_mul]\n#align nat.fib_bit0 Nat.fib_bit0\n\ntheorem fib_bit1 (n : \u2115) : fib (bit1 n) = fib (n + 1) ^ 2 + fib n ^ 2 := by\n  rw [Nat.bit1_eq_succ_bit0, bit0_eq_two_mul, fib_two_mul_add_one]\n#align nat.fib_bit1 Nat.fib_bit1\n\ntheorem fib_bit0_succ (n : \u2115) : fib (bit0 n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 :=\n  fib_bit1 n\n#align nat.fib_bit0_succ Nat.fib_bit0_succ\n\n-- porting note: A bunch of issues similar to [this zulip thread](https://github.com/leanprover-community/mathlib4/pull/1576) with `zify`\ntheorem fib_bit1_succ (n : \u2115) : fib (bit1 n + 1) = fib (n + 1) * (2 * fib n + fib (n + 1)) := by\n  rw [Nat.bit1_eq_succ_bit0, fib_add_two, fib_bit0, fib_bit0_succ]\n  have : fib n \u2264 2 * fib (n + 1) :=\n    le_trans (fib_le_fib_succ) (mul_comm 2 _ \u25b8 le_mul_of_pos_right two_pos)\n  zify [this]\n  ring_nf\n#align nat.fib_bit1_succ Nat.fib_bit1_succ\n\nend deprecated\n\n/-- Computes `(nat.fib n, nat.fib (n + 1))` using the binary representation of `n`.\nSupports `nat.fast_fib`. -/\ndef fastFibAux : \u2115 \u2192 \u2115 \u00d7 \u2115 :=\n  Nat.binaryRec (fib 0, fib 1) fun b _ p =>\n    if b then (p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2))\n    else (p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2)\n#align nat.fast_fib_aux Nat.fastFibAux\n\n/-- Computes `nat.fib n` using the binary representation of `n`.\nProved to be equal to `nat.fib` in `nat.fast_fib_eq`. -/\ndef fastFib (n : \u2115) : \u2115 :=\n  (fastFibAux n).1\n#align nat.fast_fib Nat.fastFib\n\ntheorem fast_fib_aux_bit_ff (n : \u2115) :\n    fastFibAux (bit false n) =\n      let p := fastFibAux n\n      (p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2) :=\n  by\n  rw [fastFibAux, binaryRec_eq]\n  \u00b7 rfl\n  \u00b7 simp\n#align nat.fast_fib_aux_bit_ff Nat.fast_fib_aux_bit_ff\n\ntheorem fast_fib_aux_bit_tt (n : \u2115) :\n    fastFibAux (bit true n) =\n      let p := fastFibAux n\n      (p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2)) :=\n  by\n  rw [fastFibAux, binaryRec_eq]\n  \u00b7 rfl\n  \u00b7 simp\n#align nat.fast_fib_aux_bit_tt Nat.fast_fib_aux_bit_tt\n\ntheorem fast_fib_aux_eq (n : \u2115) : fastFibAux n = (fib n, fib (n + 1)) :=\n  by\n  apply Nat.binaryRec _ (fun b n' ih => _) n\n  \u00b7 simp [fastFibAux]\n  \u00b7 intro b\n    intro n'\n    intro ih\n    cases b <;>\n          simp only [fast_fib_aux_bit_ff, fast_fib_aux_bit_tt, congr_arg Prod.fst ih,\n            congr_arg Prod.snd ih, Prod.mk.inj_iff] <;>\n          simp [bit, fib_bit0, fib_bit1, fib_bit0_succ, fib_bit1_succ]\n#align nat.fast_fib_aux_eq Nat.fast_fib_aux_eq\n\ntheorem fast_fib_eq (n : \u2115) : fastFib n = fib n := by rw [fastFib, fast_fib_aux_eq]\n#align nat.fast_fib_eq Nat.fast_fib_eq\n\ntheorem gcd_fib_add_self (m n : \u2115) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) := by\n  cases' Nat.eq_zero_or_pos n with h h\n  \u00b7 rw [h]\n    simp\n  replace h := Nat.succ_pred_eq_of_pos h; rw [\u2190 h, succ_eq_add_one]\n  calc\n    gcd (fib m) (fib (n.pred + 1 + m)) =\n        gcd (fib m) (fib n.pred * fib m + fib (n.pred + 1) * fib (m + 1)) :=\n      by\n        rw [\u2190 fib_add n.pred _]\n        ring_nf\n    _ = gcd (fib m) (fib (n.pred + 1) * fib (m + 1)) :=\n      by\n        rw [add_comm, gcd_add_mul_right_right (fib m) _ (fib n.pred)]\n    _ = gcd (fib m) (fib (n.pred + 1)) :=\n      coprime.gcd_mul_right_cancel_right (fib (n.pred + 1)) (coprime.symm (fib_coprime_fib_succ m))\n\n#align nat.gcd_fib_add_self Nat.gcd_fib_add_self\n\ntheorem gcd_fib_add_mul_self (m n : \u2115) : \u2200 k, gcd (fib m) (fib (n + k * m)) = gcd (fib m) (fib n)\n  | 0 => by simp\n  | k + 1 => by\n    rw [\u2190gcd_fib_add_mul_self m n k,\n      add_mul,\n      \u2190 add_assoc,\n      one_mul,\n      gcd_fib_add_self _ _]\n#align nat.gcd_fib_add_mul_self Nat.gcd_fib_add_mul_self\n\n/-- `fib n` is a strong divisibility sequence,\n  see https://proofwiki.org/wiki/GCD_of_Fibonacci_Numbers -/\ntheorem fib_gcd (m n : \u2115) : fib (gcd m n) = gcd (fib m) (fib n) := by\n  induction m, n using Nat.gcd.induction with\n  | H0 => simp\n  | H1 m n _ h' =>\n    rw [\u2190 gcd_rec m n] at h'\n    conv_rhs => rw [\u2190 mod_add_div' n m]\n    rwa [gcd_fib_add_mul_self m (n % m) (n / m), gcd_comm (fib m) _]\n#align nat.fib_gcd Nat.fib_gcd\n\ntheorem fib_dvd (m n : \u2115) (h : m \u2223 n) : fib m \u2223 fib n := by\n  rwa [gcd_eq_left_iff_dvd, \u2190 fib_gcd, gcd_eq_left_iff_dvd.mp]\n#align nat.fib_dvd Nat.fib_dvd\n\ntheorem fib_succ_eq_sum_choose :\n    \u2200 n : \u2115, fib (n + 1) = \u2211 p in Finset.Nat.antidiagonal n, choose p.1 p.2 :=\n  two_step_induction rfl rfl fun n h1 h2 =>\n    by\n    rw [fib_add_two, h1, h2, Finset.Nat.antidiagonal_succ_succ', Finset.Nat.antidiagonal_succ']\n    simp [choose_succ_succ, Finset.sum_add_distrib, add_left_comm]\n#align nat.fib_succ_eq_sum_choose Nat.fib_succ_eq_sum_choose\n\ntheorem fib_succ_eq_succ_sum (n : \u2115) : fib (n + 1) = (\u2211 k in Finset.range n, fib k) + 1 :=\n  by\n  induction' n with n ih\n  \u00b7 simp\n  \u00b7\n    calc\n      fib (n + 2) = fib n + fib (n + 1) := fib_add_two\n      _ = (fib n + \u2211 k in Finset.range n, fib k) + 1 := by rw [ih, add_assoc]\n      _ = (\u2211 k in Finset.range (n + 1), fib k) + 1 := by simp [Finset.range_add_one]\n\n#align nat.fib_succ_eq_succ_sum Nat.fib_succ_eq_succ_sum\n\nend Nat\n\nnamespace NormNum\n\nopen Tactic Nat\n\n/-! ### `norm_num` plugin for `fib`\n\nThe `norm_num` plugin uses a strategy parallel to that of `nat.fast_fib`, but it instead\nproduces proofs of what `nat.fib` evaluates to.\n-/\n/-\nexpected ')'\n-/\n\nsection deprecated\n\nset_option linter.deprecated false\n\n/-- Auxiliary definition for `prove_fib` plugin. -/\ndef IsFibAux (n a b : \u2115) :=\n  fib n = a \u2227 fib (n + 1) = b\n#align norm_num.is_fib_aux NormNum.IsFibAux\n\ntheorem is_fib_aux_one : IsFibAux 1 1 1 :=\n  \u27e8fib_one, fib_two\u27e9\n#align norm_num.is_fib_aux_one NormNum.is_fib_aux_one\n\ntheorem is_fib_aux_bit0 {n a b c a2 b2 a' b' : \u2115} (H : IsFibAux n a b) (h1 : a + c = bit0 b)\n    (h2 : a * c = a') (h3 : a * a = a2) (h4 : b * b = b2) (h5 : a2 + b2 = b') :\n    IsFibAux (bit0 n) a' b' :=\n  \u27e8by\n    rw [fib_bit0, H.1, H.2, \u2190 bit0_eq_two_mul,\n      show bit0 b - a = c by rw [\u2190 h1, Nat.add_sub_cancel_left], h2],\n    by rw [fib_bit0_succ, H.1, H.2, pow_two, pow_two, h3, h4, add_comm, h5]\u27e9\n#align norm_num.is_fib_aux_bit0 NormNum.is_fib_aux_bit0\n\ntheorem is_fib_aux_bit1 {n a b c a2 b2 a' b' : \u2115} (H : IsFibAux n a b) (h1 : a * a = a2)\n    (h2 : b * b = b2) (h3 : a2 + b2 = a') (h4 : bit0 a + b = c) (h5 : b * c = b') :\n    IsFibAux (bit1 n) a' b' :=\n  \u27e8by rw [fib_bit1, H.1, H.2, pow_two, pow_two, h1, h2, add_comm, h3], by\n    rw [fib_bit1_succ, H.1, H.2, \u2190 bit0_eq_two_mul, h4, h5]\u27e9\n#align norm_num.is_fib_aux_bit1 NormNum.is_fib_aux_bit1\n\ntheorem is_fib_aux_bit0_done {n a b c a' : \u2115} (H : IsFibAux n a b) (h1 : a + c = bit0 b)\n    (h2 : a * c = a') : fib (bit0 n) = a' :=\n  (is_fib_aux_bit0 H h1 h2 rfl rfl rfl).1\n#align norm_num.is_fib_aux_bit0_done NormNum.is_fib_aux_bit0_done\n\ntheorem is_fib_aux_bit1_done {n a b a2 b2 a' : \u2115} (H : IsFibAux n a b) (h1 : a * a = a2)\n    (h2 : b * b = b2) (h3 : a2 + b2 = a') : fib (bit1 n) = a' :=\n  (is_fib_aux_bit1 H h1 h2 h3 rfl rfl).1\n#align norm_num.is_fib_aux_bit1_done NormNum.is_fib_aux_bit1_done\n\nend deprecated\n-- Porting note: This part of the file is tactic related\n/-\n/-- `prove_fib_aux ic n` returns `(ic', a, b, \u22a2 is_fib_aux n a b)`, where `n` is a numeral. -/\nunsafe def prove_fib_aux (ic : instance_cache) : expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr \u00d7 expr)\n  | e =>\n    match match_numeral e with\n    | match_numeral_result.one => pure (ic, q((1 : \u2115)), q((1 : \u2115)), q(is_fib_aux_one))\n    | match_numeral_result.bit0 e => do\n      let (ic, a, b, H) \u2190 prove_fib_aux e\n      let na \u2190 a.toNat\n      let nb \u2190 b.toNat\n      let (ic, c) \u2190 ic.ofNat (2 * nb - na)\n      let (ic, h1) \u2190 prove_add_nat ic a c (q((bit0 : \u2115 \u2192 \u2115)).mk_app [b])\n      let (ic, a', h2) \u2190 prove_mul_nat ic a c\n      let (ic, a2, h3) \u2190 prove_mul_nat ic a a\n      let (ic, b2, h4) \u2190 prove_mul_nat ic b b\n      let (ic, b', h5) \u2190 prove_add_nat' ic a2 b2\n      pure\n          (ic, a', b',\n            q(@is_fib_aux_bit0).mk_app [e, a, b, c, a2, b2, a', b', H, h1, h2, h3, h4, h5])\n    | match_numeral_result.bit1 e => do\n      let (ic, a, b, H) \u2190 prove_fib_aux e\n      let na \u2190 a.toNat\n      let nb \u2190 b.toNat\n      let (ic, c) \u2190 ic.ofNat (2 * na + nb)\n      let (ic, a2, h1) \u2190 prove_mul_nat ic a a\n      let (ic, b2, h2) \u2190 prove_mul_nat ic b b\n      let (ic, a', h3) \u2190 prove_add_nat' ic a2 b2\n      let (ic, h4) \u2190 prove_add_nat ic (q((bit0 : \u2115 \u2192 \u2115)).mk_app [a]) b c\n      let (ic, b', h5) \u2190 prove_mul_nat ic b c\n      pure\n          (ic, a', b',\n            q(@is_fib_aux_bit1).mk_app [e, a, b, c, a2, b2, a', b', H, h1, h2, h3, h4, h5])\n    | _ => failed\n#align norm_num.prove_fib_aux NormNum.prove_fib_aux\n\n/-- A `norm_num` plugin for `fib n` when `n` is a numeral.\nUses the binary representation of `n` like `nat.fast_fib`. -/\nunsafe def prove_fib (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\n  match match_numeral e with\n  | match_numeral_result.zero => pure (ic, q((0 : \u2115)), q(fib_zero))\n  | match_numeral_result.one => pure (ic, q((1 : \u2115)), q(fib_one))\n  | match_numeral_result.bit0 e => do\n    let (ic, a, b, H) \u2190 prove_fib_aux ic e\n    let na \u2190 a.toNat\n    let nb \u2190 b.toNat\n    let (ic, c) \u2190 ic.ofNat (2 * nb - na)\n    let (ic, h1) \u2190 prove_add_nat ic a c (q((bit0 : \u2115 \u2192 \u2115)).mk_app [b])\n    let (ic, a', h2) \u2190 prove_mul_nat ic a c\n    pure (ic, a', q(@is_fib_aux_bit0_done).mk_app [e, a, b, c, a', H, h1, h2])\n  | match_numeral_result.bit1 e => do\n    let (ic, a, b, H) \u2190 prove_fib_aux ic e\n    let (ic, a2, h1) \u2190 prove_mul_nat ic a a\n    let (ic, b2, h2) \u2190 prove_mul_nat ic b b\n    let (ic, a', h3) \u2190 prove_add_nat' ic a2 b2\n    pure (ic, a', q(@is_fib_aux_bit1_done).mk_app [e, a, b, a2, b2, a', H, h1, h2, h3])\n  | _ => failed\n#align norm_num.prove_fib NormNum.prove_fib\n\n/-- A `norm_num` plugin for `fib n` when `n` is a numeral.\n/-\nunknown identifier ''\n-/\nUses the binary representation of `n` like `Nat.fastFib`. -/\n@[norm_num]\nunsafe def eval_fib : expr \u2192 tactic (expr \u00d7 expr)\n  | (fib $(en)) => do\n    let n \u2190 en.toNat\n    match n with\n      | 0 => pure (q((0 : \u2115)), q(fib_zero))\n      | 1 => pure (q((1 : \u2115)), q(fib_one))\n      | 2 => pure (q((1 : \u2115)), q(fib_two))\n      | _ => do\n        let c \u2190 mk_instance_cache q(\u2115)\n        Prod.snd <$> prove_fib c en\n  | _ => failed\n#align norm_num.eval_fib NormNum.eval_fib\n-/\nend NormNum\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7348244609642356}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n-/\nimport algebra.group.with_one\nimport algebra.group.type_tags\nimport algebra.group.prod\nimport algebra.order.monoid_lemmas\nimport order.bounded_order\nimport order.min_max\nimport order.rel_iso\n\n/-!\n# Ordered monoids\n\nThis file develops the basics of ordered monoids.\n\n## Implementation details\n\nUnfortunately, the number of `'` appended to lemmas in this file\nmay differ between the multiplicative and the additive version of a lemma.\nThe reason is that we did not want to change existing names in the library.\n-/\n\nset_option old_structure_cmd true\nopen function\n\nuniverse u\nvariable {\u03b1 : Type u}\n\n/-- An ordered commutative monoid is a commutative monoid\nwith a partial order such that `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone)\n-/\n@[protect_proj, ancestor comm_monoid partial_order]\nclass ordered_comm_monoid (\u03b1 : Type*) extends comm_monoid \u03b1, partial_order \u03b1 :=\n(mul_le_mul_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\n\n/-- An ordered (additive) commutative monoid is a commutative monoid\n  with a partial order such that `a \u2264 b \u2192 c + a \u2264 c + b` (addition is monotone)\n-/\n@[protect_proj, ancestor add_comm_monoid partial_order]\nclass ordered_add_comm_monoid (\u03b1 : Type*) extends add_comm_monoid \u03b1, partial_order \u03b1 :=\n(add_le_add_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n\nattribute [to_additive] ordered_comm_monoid\n\nsection ordered_instances\n\n@[to_additive]\ninstance ordered_comm_monoid.to_covariant_class_left (M : Type*) [ordered_comm_monoid M] :\n  covariant_class M M (*) (\u2264) :=\n{ elim := \u03bb a b c bc, ordered_comm_monoid.mul_le_mul_left _ _ bc a }\n\n/- This instance can be proven with `by apply_instance`.  However, `with_bot \u2115` does not\npick up a `covariant_class M M (function.swap (*)) (\u2264)` instance without it (see PR #7940). -/\n@[to_additive]\ninstance ordered_comm_monoid.to_covariant_class_right (M : Type*) [ordered_comm_monoid M] :\n  covariant_class M M (swap (*)) (\u2264) :=\ncovariant_swap_mul_le_of_covariant_mul_le M\n\nend ordered_instances\n\n/-- An `ordered_comm_monoid` with one-sided 'division' in the sense that\nif `a \u2264 b`, there is some `c` for which `a * c = b`. This is a weaker version\nof the condition on canonical orderings defined by `canonically_ordered_monoid`. -/\nclass has_exists_mul_of_le (\u03b1 : Type u) [ordered_comm_monoid \u03b1] : Prop :=\n(exists_mul_of_le : \u2200 {a b : \u03b1}, a \u2264 b \u2192 \u2203 (c : \u03b1), b = a * c)\n\n/-- An `ordered_add_comm_monoid` with one-sided 'subtraction' in the sense that\nif `a \u2264 b`, then there is some `c` for which `a + c = b`. This is a weaker version\nof the condition on canonical orderings defined by `canonically_ordered_add_monoid`. -/\nclass has_exists_add_of_le (\u03b1 : Type u) [ordered_add_comm_monoid \u03b1] : Prop :=\n(exists_add_of_le : \u2200 {a b : \u03b1}, a \u2264 b \u2192 \u2203 (c : \u03b1), b = a + c)\n\nattribute [to_additive] has_exists_mul_of_le\n\nexport has_exists_mul_of_le (exists_mul_of_le)\n\nexport has_exists_add_of_le (exists_add_of_le)\n\n/-- A linearly ordered additive commutative monoid. -/\n@[protect_proj, ancestor linear_order ordered_add_comm_monoid]\nclass linear_ordered_add_comm_monoid (\u03b1 : Type*)\n  extends linear_order \u03b1, ordered_add_comm_monoid \u03b1.\n\n/-- A linearly ordered commutative monoid. -/\n@[protect_proj, ancestor linear_order ordered_comm_monoid, to_additive]\nclass linear_ordered_comm_monoid (\u03b1 : Type*)\n  extends linear_order \u03b1, ordered_comm_monoid \u03b1.\n\n/-- A linearly ordered commutative monoid with a zero element. -/\nclass linear_ordered_comm_monoid_with_zero (\u03b1 : Type*)\n  extends linear_ordered_comm_monoid \u03b1, comm_monoid_with_zero \u03b1 :=\n(zero_le_one : (0 : \u03b1) \u2264 1)\n\n/-- A linearly ordered commutative monoid with an additively absorbing `\u22a4` element.\n  Instances should include number systems with an infinite element adjoined.` -/\n@[protect_proj, ancestor linear_ordered_add_comm_monoid has_top]\nclass linear_ordered_add_comm_monoid_with_top (\u03b1 : Type*)\n  extends linear_ordered_add_comm_monoid \u03b1, has_top \u03b1 :=\n(le_top : \u2200 x : \u03b1, x \u2264 \u22a4)\n(top_add' : \u2200 x : \u03b1, \u22a4 + x = \u22a4)\n\n@[priority 100]    -- see Note [lower instance priority]\ninstance linear_ordered_add_comm_monoid_with_top.to_order_top (\u03b1 : Type u)\n  [h : linear_ordered_add_comm_monoid_with_top \u03b1] : order_top \u03b1 :=\n{ ..h }\n\nsection linear_ordered_add_comm_monoid_with_top\nvariables [linear_ordered_add_comm_monoid_with_top \u03b1] {a b : \u03b1}\n\n@[simp]\nlemma top_add (a : \u03b1) : \u22a4 + a = \u22a4 := linear_ordered_add_comm_monoid_with_top.top_add' a\n\n@[simp]\nlemma add_top (a : \u03b1) : a + \u22a4 = \u22a4 :=\ntrans (add_comm _ _) (top_add _)\n\nend linear_ordered_add_comm_monoid_with_top\n\n/-- Pullback an `ordered_comm_monoid` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible, to_additive function.injective.ordered_add_comm_monoid\n\"Pullback an `ordered_add_comm_monoid` under an injective map.\"]\ndef function.injective.ordered_comm_monoid [ordered_comm_monoid \u03b1] {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_comm_monoid \u03b2 :=\n{ mul_le_mul_left := \u03bb a b ab c, show f (c * a) \u2264 f (c * b), by\n  { rw [mul, mul], apply mul_le_mul_left', exact ab },\n  ..partial_order.lift f hf,\n  ..hf.comm_monoid f one mul }\n\n/-- Pullback a `linear_ordered_comm_monoid` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible, to_additive function.injective.linear_ordered_add_comm_monoid\n\"Pullback an `ordered_add_comm_monoid` under an injective map.\"]\ndef function.injective.linear_ordered_comm_monoid [linear_ordered_comm_monoid \u03b1] {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  linear_ordered_comm_monoid \u03b2 :=\n{ .. hf.ordered_comm_monoid f one mul,\n  .. linear_order.lift f hf }\n\nlemma bit0_pos [ordered_add_comm_monoid \u03b1] {a : \u03b1} (h : 0 < a) : 0 < bit0 a :=\nadd_pos h h\n\nnamespace units\n\n@[to_additive]\ninstance [monoid \u03b1] [preorder \u03b1] : preorder (units \u03b1) :=\npreorder.lift (coe : units \u03b1 \u2192 \u03b1)\n\n@[simp, norm_cast, to_additive]\ntheorem coe_le_coe [monoid \u03b1] [preorder \u03b1] {a b : units \u03b1} :\n  (a : \u03b1) \u2264 b \u2194 a \u2264 b := iff.rfl\n\n@[simp, norm_cast, to_additive]\ntheorem coe_lt_coe [monoid \u03b1] [preorder \u03b1] {a b : units \u03b1} :\n  (a : \u03b1) < b \u2194 a < b := iff.rfl\n\n@[to_additive]\ninstance [monoid \u03b1] [partial_order \u03b1] : partial_order (units \u03b1) :=\npartial_order.lift coe units.ext\n\n@[to_additive]\ninstance [monoid \u03b1] [linear_order \u03b1] : linear_order (units \u03b1) :=\nlinear_order.lift coe units.ext\n\n@[simp, norm_cast, to_additive]\ntheorem max_coe [monoid \u03b1] [linear_order \u03b1] {a b : units \u03b1} :\n  (\u2191(max a b) : \u03b1) = max a b :=\nby by_cases b \u2264 a; simp [max_def, h]\n\n@[simp, norm_cast, to_additive]\ntheorem min_coe [monoid \u03b1] [linear_order \u03b1] {a b : units \u03b1} :\n  (\u2191(min a b) : \u03b1) = min a b :=\nby by_cases a \u2264 b; simp [min_def, h]\n\nend units\n\nnamespace with_zero\n\nlocal attribute [semireducible] with_zero\n\ninstance [preorder \u03b1] : preorder (with_zero \u03b1) := with_bot.preorder\n\ninstance [partial_order \u03b1] : partial_order (with_zero \u03b1) := with_bot.partial_order\n\ninstance [partial_order \u03b1] : order_bot (with_zero \u03b1) := with_bot.order_bot\n\nlemma zero_le [partial_order \u03b1] (a : with_zero \u03b1) : 0 \u2264 a := order_bot.bot_le a\n\nlemma zero_lt_coe [preorder \u03b1] (a : \u03b1) : (0 : with_zero \u03b1) < a := with_bot.bot_lt_coe a\n\n@[simp, norm_cast] lemma coe_lt_coe [partial_order \u03b1] {a b : \u03b1} : (a : with_zero \u03b1) < b \u2194 a < b :=\nwith_bot.coe_lt_coe\n\n@[simp, norm_cast] lemma coe_le_coe [partial_order \u03b1] {a b : \u03b1} : (a : with_zero \u03b1) \u2264 b \u2194 a \u2264 b :=\nwith_bot.coe_le_coe\n\ninstance [lattice \u03b1] : lattice (with_zero \u03b1) := with_bot.lattice\n\ninstance [linear_order \u03b1] : linear_order (with_zero \u03b1) := with_bot.linear_order\n\nlemma mul_le_mul_left {\u03b1 : Type u} [has_mul \u03b1] [preorder \u03b1]\n  [covariant_class \u03b1 \u03b1 (*) (\u2264)] :\n  \u2200 (a b : with_zero \u03b1),\n    a \u2264 b \u2192 \u2200 (c : with_zero \u03b1), c * a \u2264 c * b :=\nbegin\n  rintro (_ | a) (_ | b) h (_ | c);\n  try { exact \u03bb f hf, option.no_confusion hf },\n  { exact false.elim (not_lt_of_le h (with_zero.zero_lt_coe a))},\n  { simp_rw [some_eq_coe] at h \u22a2,\n    norm_cast at h \u22a2,\n    exact covariant_class.elim _ h }\nend\n\nlemma lt_of_mul_lt_mul_left {\u03b1 : Type u} [has_mul \u03b1] [partial_order \u03b1]\n  [contravariant_class \u03b1 \u03b1 (*) (<)] :\n  \u2200 (a b c : with_zero \u03b1), a * b < a * c \u2192 b < c :=\nbegin\n  rintro (_ | a) (_ | b) (_ | c) h;\n  try { exact false.elim (lt_irrefl none h) },\n  { exact with_zero.zero_lt_coe c },\n  { exact false.elim (not_le_of_lt h (with_zero.zero_le _)) },\n  { simp_rw [some_eq_coe] at h \u22a2,\n    norm_cast at h \u22a2,\n    apply lt_of_mul_lt_mul_left' h }\nend\n\ninstance [ordered_comm_monoid \u03b1] : ordered_comm_monoid (with_zero \u03b1) :=\n{ mul_le_mul_left := with_zero.mul_le_mul_left,\n  ..with_zero.comm_monoid_with_zero,\n  ..with_zero.partial_order }\n\n/-\nNote 1 : the below is not an instance because it requires `zero_le`. It seems\nlike a rather pathological definition because \u03b1 already has a zero.\nNote 2 : there is no multiplicative analogue because it does not seem necessary.\nMathematicians might be more likely to use the order-dual version, where all\nelements are \u2264 1 and then 1 is the top element.\n-/\n\n/--\nIf `0` is the least element in `\u03b1`, then `with_zero \u03b1` is an `ordered_add_comm_monoid`.\n-/\ndef ordered_add_comm_monoid [ordered_add_comm_monoid \u03b1]\n  (zero_le : \u2200 a : \u03b1, 0 \u2264 a) : ordered_add_comm_monoid (with_zero \u03b1) :=\nbegin\n  suffices, refine\n  { add_le_add_left := this,\n    ..with_zero.partial_order,\n    ..with_zero.add_comm_monoid, .. },\n  { intros a b h c ca h\u2082,\n    cases b with b,\n    { rw le_antisymm h bot_le at h\u2082,\n      exact \u27e8_, h\u2082, le_refl _\u27e9 },\n    cases a with a,\n    { change c + 0 = some ca at h\u2082,\n      simp at h\u2082, simp [h\u2082],\n      exact \u27e8_, rfl, by simpa using add_le_add_left (zero_le b) _\u27e9 },\n    { simp at h,\n      cases c with c; change some _ = _ at h\u2082;\n        simp [-add_comm] at h\u2082; subst ca; refine \u27e8_, rfl, _\u27e9,\n      { exact h },\n      { exact add_le_add_left h _ } } }\nend\n\nend with_zero\n\nnamespace with_top\n\nsection has_one\n\nvariables [has_one \u03b1]\n\n@[to_additive] instance : has_one (with_top \u03b1) := \u27e8(1 : \u03b1)\u27e9\n\n@[simp, norm_cast, to_additive] lemma coe_one : ((1 : \u03b1) : with_top \u03b1) = 1 := rfl\n\n@[simp, norm_cast, to_additive] lemma coe_eq_one {a : \u03b1} : (a : with_top \u03b1) = 1 \u2194 a = 1 :=\ncoe_eq_coe\n\n@[simp, norm_cast, to_additive] theorem one_eq_coe {a : \u03b1} : 1 = (a : with_top \u03b1) \u2194 a = 1 :=\ntrans eq_comm coe_eq_one\n\n@[simp, to_additive] theorem top_ne_one : \u22a4 \u2260 (1 : with_top \u03b1) .\n@[simp, to_additive] theorem one_ne_top : (1 : with_top \u03b1) \u2260 \u22a4 .\n\nend has_one\n\ninstance [has_add \u03b1] : has_add (with_top \u03b1) :=\n\u27e8\u03bb o\u2081 o\u2082, o\u2081.bind (\u03bb a, o\u2082.map (\u03bb b, a + b))\u27e9\n\n@[norm_cast] lemma coe_add [has_add \u03b1] {a b : \u03b1} : ((a + b : \u03b1) : with_top \u03b1) = a + b := rfl\n\n@[norm_cast] lemma coe_bit0 [has_add \u03b1] {a : \u03b1} : ((bit0 a : \u03b1) : with_top \u03b1) = bit0 a := rfl\n\n@[norm_cast]\nlemma coe_bit1 [has_add \u03b1] [has_one \u03b1] {a : \u03b1} : ((bit1 a : \u03b1) : with_top \u03b1) = bit1 a := rfl\n\n@[simp] lemma add_top [has_add \u03b1] : \u2200{a : with_top \u03b1}, a + \u22a4 = \u22a4\n| none := rfl\n| (some a) := rfl\n\n@[simp] lemma top_add [has_add \u03b1] {a : with_top \u03b1} : \u22a4 + a = \u22a4 := rfl\n\nlemma add_eq_top [has_add \u03b1] {a b : with_top \u03b1} : a + b = \u22a4 \u2194 a = \u22a4 \u2228 b = \u22a4 :=\nby cases a; cases b; simp [none_eq_top, some_eq_coe, \u2190with_top.coe_add, \u2190with_zero.coe_add]\n\nlemma add_lt_top [has_add \u03b1] [partial_order \u03b1] {a b : with_top \u03b1} : a + b < \u22a4 \u2194 a < \u22a4 \u2227 b < \u22a4 :=\nby simp [lt_top_iff_ne_top, add_eq_top, not_or_distrib]\n\nlemma add_eq_coe [has_add \u03b1] : \u2200 {a b : with_top \u03b1} {c : \u03b1},\n  a + b = c \u2194 \u2203 (a' b' : \u03b1), \u2191a' = a \u2227 \u2191b' = b \u2227 a' + b' = c\n| none b c := by simp [none_eq_top]\n| (some a) none c := by simp [none_eq_top]\n| (some a) (some b) c :=\n    by simp only [some_eq_coe, \u2190 coe_add, coe_eq_coe, exists_and_distrib_left, exists_eq_left]\n\n@[simp] lemma add_coe_eq_top_iff [has_add \u03b1] {x : with_top \u03b1} {y : \u03b1} : x + y = \u22a4 \u2194 x = \u22a4 :=\nby { induction x using with_top.rec_top_coe; simp [\u2190 coe_add, -with_zero.coe_add] }\n\n@[simp] lemma coe_add_eq_top_iff [has_add \u03b1] {x : \u03b1} {y : with_top \u03b1} : \u2191x + y = \u22a4 \u2194 y = \u22a4 :=\nby { induction y using with_top.rec_top_coe; simp [\u2190 coe_add, -with_zero.coe_add] }\n\ninstance [add_semigroup \u03b1] : add_semigroup (with_top \u03b1) :=\n{ add_assoc := begin\n    repeat { refine with_top.rec_top_coe _ _; try { intro }};\n    simp [\u2190with_top.coe_add, add_assoc]\n  end,\n  ..with_top.has_add }\n\ninstance [add_comm_semigroup \u03b1] : add_comm_semigroup (with_top \u03b1) :=\n{ add_comm :=\n  begin\n    repeat { refine with_top.rec_top_coe _ _; try { intro }};\n    simp [\u2190with_top.coe_add, add_comm]\n  end,\n  ..with_top.add_semigroup }\n\ninstance [add_monoid \u03b1] : add_monoid (with_top \u03b1) :=\n{ zero_add :=\n  begin\n    refine with_top.rec_top_coe _ _,\n    { simpa },\n    { intro,\n      rw [\u2190with_top.coe_zero, \u2190with_top.coe_add, zero_add] }\n  end,\n  add_zero :=\n  begin\n    refine with_top.rec_top_coe _ _,\n    { simpa },\n    { intro,\n      rw [\u2190with_top.coe_zero, \u2190with_top.coe_add, add_zero] }\n  end,\n  ..with_top.has_zero,\n  ..with_top.add_semigroup }\n\ninstance [add_comm_monoid \u03b1] : add_comm_monoid (with_top \u03b1) :=\n{ ..with_top.add_monoid, ..with_top.add_comm_semigroup }\n\ninstance [ordered_add_comm_monoid \u03b1] : ordered_add_comm_monoid (with_top \u03b1) :=\n{ add_le_add_left :=\n    begin\n      rintros a b h (_|c), { simp [none_eq_top] },\n      rcases b with (_|b), { simp [none_eq_top] },\n      rcases le_coe_iff.1 h with \u27e8a, rfl, h\u27e9,\n      simp only [some_eq_coe, \u2190 coe_add, coe_le_coe] at h \u22a2,\n      exact add_le_add_left h c\n    end,\n  ..with_top.partial_order, ..with_top.add_comm_monoid }\n\ninstance [linear_ordered_add_comm_monoid \u03b1] :\n  linear_ordered_add_comm_monoid_with_top (with_top \u03b1) :=\n{ top_add' := \u03bb x, with_top.top_add,\n  ..with_top.order_top,\n  ..with_top.linear_order,\n  ..with_top.ordered_add_comm_monoid,\n  ..option.nontrivial }\n\n/-- Coercion from `\u03b1` to `with_top \u03b1` as an `add_monoid_hom`. -/\ndef coe_add_hom [add_monoid \u03b1] : \u03b1 \u2192+ with_top \u03b1 :=\n\u27e8coe, rfl, \u03bb _ _, rfl\u27e9\n\n@[simp] lemma coe_coe_add_hom [add_monoid \u03b1] : \u21d1(coe_add_hom : \u03b1 \u2192+ with_top \u03b1) = coe := rfl\n\n@[simp] lemma zero_lt_top [ordered_add_comm_monoid \u03b1] : (0 : with_top \u03b1) < \u22a4 :=\ncoe_lt_top 0\n\n@[simp, norm_cast] lemma zero_lt_coe [ordered_add_comm_monoid \u03b1] (a : \u03b1) :\n  (0 : with_top \u03b1) < a \u2194 0 < a :=\ncoe_lt_coe\n\nend with_top\n\nnamespace with_bot\n\ninstance [has_zero \u03b1] : has_zero (with_bot \u03b1) := with_top.has_zero\ninstance [has_one \u03b1] : has_one (with_bot \u03b1) := with_top.has_one\ninstance [add_semigroup \u03b1] : add_semigroup (with_bot \u03b1) := with_top.add_semigroup\ninstance [add_comm_semigroup \u03b1] : add_comm_semigroup (with_bot \u03b1) := with_top.add_comm_semigroup\ninstance [add_monoid \u03b1] : add_monoid (with_bot \u03b1) := with_top.add_monoid\ninstance [add_comm_monoid \u03b1] : add_comm_monoid (with_bot \u03b1) :=  with_top.add_comm_monoid\n\ninstance [ordered_add_comm_monoid \u03b1] : ordered_add_comm_monoid (with_bot \u03b1) :=\nbegin\n  suffices, refine\n  { add_le_add_left := this,\n    ..with_bot.partial_order,\n    ..with_bot.add_comm_monoid, ..},\n  { intros a b h c ca h\u2082,\n    cases c with c, {cases h\u2082},\n    cases a with a; cases h\u2082,\n    cases b with b, {cases le_antisymm h bot_le},\n    simp at h,\n    exact \u27e8_, rfl, add_le_add_left h _\u27e9, }\nend\n\ninstance [linear_ordered_add_comm_monoid \u03b1] : linear_ordered_add_comm_monoid (with_bot \u03b1) :=\n{ ..with_bot.linear_order,\n  ..with_bot.ordered_add_comm_monoid }\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_zero [has_zero \u03b1] : ((0 : \u03b1) : with_bot \u03b1) = 0 := rfl\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_one [has_one \u03b1] : ((1 : \u03b1) : with_bot \u03b1) = 1 := rfl\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_eq_zero {\u03b1 : Type*}\n  [add_monoid \u03b1] {a : \u03b1} : (a : with_bot \u03b1) = 0 \u2194 a = 0 :=\nby norm_cast\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_add [add_semigroup \u03b1] (a b : \u03b1) : ((a + b : \u03b1) : with_bot \u03b1) = a + b := by norm_cast\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_bit0 [add_semigroup \u03b1] {a : \u03b1} : ((bit0 a : \u03b1) : with_bot \u03b1) = bit0 a :=\nby norm_cast\n\n-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`\nlemma coe_bit1 [add_semigroup \u03b1] [has_one \u03b1] {a : \u03b1} : ((bit1 a : \u03b1) : with_bot \u03b1) = bit1 a :=\nby norm_cast\n\n@[simp] lemma bot_add [add_semigroup \u03b1] (a : with_bot \u03b1) : \u22a5 + a = \u22a5 := rfl\n\n@[simp] lemma add_bot [add_semigroup \u03b1] (a : with_bot \u03b1) : a + \u22a5 = \u22a5 := by cases a; refl\n\n@[simp] lemma add_eq_bot [add_semigroup \u03b1] {m n : with_bot \u03b1} :\n  m + n = \u22a5 \u2194 m = \u22a5 \u2228 n = \u22a5 :=\nwith_top.add_eq_top\n\nend with_bot\n\n/-- A canonically ordered additive monoid is an ordered commutative additive monoid\n  in which the ordering coincides with the subtractibility relation,\n  which is to say, `a \u2264 b` iff there exists `c` with `b = a + c`.\n  This is satisfied by the natural numbers, for example, but not\n  the integers or other nontrivial `ordered_add_comm_group`s. -/\n@[protect_proj, ancestor ordered_add_comm_monoid has_bot]\nclass canonically_ordered_add_monoid (\u03b1 : Type*) extends ordered_add_comm_monoid \u03b1, has_bot \u03b1 :=\n(bot_le : \u2200 x : \u03b1, \u22a5 \u2264 x)\n(le_iff_exists_add : \u2200 a b : \u03b1, a \u2264 b \u2194 \u2203 c, b = a + c)\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance canonically_ordered_add_monoid.to_order_bot (\u03b1 : Type u)\n  [h : canonically_ordered_add_monoid \u03b1] : order_bot \u03b1 :=\n{ ..h }\n\n/-- A canonically ordered monoid is an ordered commutative monoid\n  in which the ordering coincides with the divisibility relation,\n  which is to say, `a \u2264 b` iff there exists `c` with `b = a * c`.\n  Examples seem rare; it seems more likely that the `order_dual`\n  of a naturally-occurring lattice satisfies this than the lattice\n  itself (for example, dual of the lattice of ideals of a PID or\n  Dedekind domain satisfy this; collections of all things \u2264 1 seem to\n  be more natural that collections of all things \u2265 1).\n-/\n@[protect_proj, ancestor ordered_comm_monoid has_bot, to_additive]\nclass canonically_ordered_monoid (\u03b1 : Type*) extends ordered_comm_monoid \u03b1, has_bot \u03b1 :=\n(bot_le : \u2200 x : \u03b1, \u22a5 \u2264 x)\n(le_iff_exists_mul : \u2200 a b : \u03b1, a \u2264 b \u2194 \u2203 c, b = a * c)\n\n@[priority 100, to_additive]  -- see Note [lower instance priority]\ninstance canonically_ordered_monoid.to_order_bot (\u03b1 : Type u)\n  [h : canonically_ordered_monoid \u03b1] : order_bot \u03b1 :=\n{ ..h }\n\nsection canonically_ordered_monoid\n\nvariables [canonically_ordered_monoid \u03b1] {a b c d : \u03b1}\n\n@[to_additive]\nlemma le_iff_exists_mul : a \u2264 b \u2194 \u2203c, b = a * c :=\ncanonically_ordered_monoid.le_iff_exists_mul a b\n\n@[to_additive]\nlemma self_le_mul_right (a b : \u03b1) : a \u2264 a * b :=\nle_iff_exists_mul.mpr \u27e8b, rfl\u27e9\n\n@[to_additive]\nlemma self_le_mul_left (a b : \u03b1) : a \u2264 b * a :=\nby { rw [mul_comm], exact self_le_mul_right a b }\n\n@[simp, to_additive zero_le] lemma one_le (a : \u03b1) : 1 \u2264 a :=\nle_iff_exists_mul.mpr \u27e8a, (one_mul _).symm\u27e9\n\n@[simp, to_additive] lemma bot_eq_one : (\u22a5 : \u03b1) = 1 :=\nle_antisymm bot_le (one_le \u22a5)\n\n@[simp, to_additive] lemma mul_eq_one_iff : a * b = 1 \u2194 a = 1 \u2227 b = 1 :=\nmul_eq_one_iff' (one_le _) (one_le _)\n\n@[simp, to_additive] lemma le_one_iff_eq_one : a \u2264 1 \u2194 a = 1 :=\niff.intro\n  (assume h, le_antisymm h (one_le a))\n  (assume h, h \u25b8 le_refl a)\n\n@[to_additive] lemma one_lt_iff_ne_one : 1 < a \u2194 a \u2260 1 :=\niff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (one_le _) hne.symm\n\n@[to_additive] lemma exists_pos_mul_of_lt (h : a < b) : \u2203 c > 1, a * c = b :=\nbegin\n  obtain \u27e8c, hc\u27e9 := le_iff_exists_mul.1 h.le,\n  refine \u27e8c, one_lt_iff_ne_one.2 _, hc.symm\u27e9,\n  rintro rfl,\n  simpa [hc, lt_irrefl] using h\nend\n\n@[to_additive] lemma le_mul_left (h : a \u2264 c) : a \u2264 b * c :=\ncalc a = 1 * a : by simp\n  ... \u2264 b * c : mul_le_mul' (one_le _) h\n\n@[to_additive] lemma le_mul_self : a \u2264 b * a :=\nle_mul_left (le_refl a)\n\n@[to_additive] lemma le_mul_right (h : a \u2264 b) : a \u2264 b * c :=\ncalc a = a * 1 : by simp\n  ... \u2264 b * c : mul_le_mul' h (one_le _)\n\n@[to_additive] lemma le_self_mul : a \u2264 a * c :=\nle_mul_right (le_refl a)\n\n@[to_additive]\nlemma lt_iff_exists_mul [covariant_class \u03b1 \u03b1 (*) (<)] : a < b \u2194 \u2203 c > 1, b = a * c :=\nbegin\n  simp_rw [lt_iff_le_and_ne, and_comm, le_iff_exists_mul, \u2190 exists_and_distrib_left, exists_prop],\n  apply exists_congr, intro c,\n  rw [and.congr_left_iff, gt_iff_lt], rintro rfl,\n  split,\n  { rw [one_lt_iff_ne_one], apply mt, rintro rfl, rw [mul_one] },\n  { rw [\u2190 (self_le_mul_right a c).lt_iff_ne], apply lt_mul_of_one_lt_right' }\nend\n\n-- This instance looks absurd: a monoid already has a zero\n/-- Adding a new zero to a canonically ordered additive monoid produces another one. -/\ninstance with_zero.canonically_ordered_add_monoid {\u03b1 : Type u} [canonically_ordered_add_monoid \u03b1] :\n  canonically_ordered_add_monoid (with_zero \u03b1) :=\n{ le_iff_exists_add := \u03bb a b, begin\n    apply with_zero.cases_on a,\n    { exact iff_of_true bot_le \u27e8b, (zero_add b).symm\u27e9 },\n    apply with_zero.cases_on b,\n    { intro b',\n      refine iff_of_false (mt (le_antisymm bot_le) (by simp)) (not_exists.mpr (\u03bb c, _)),\n      apply with_zero.cases_on c;\n      simp [\u2190with_zero.coe_add] },\n    { simp only [le_iff_exists_add, with_zero.coe_le_coe],\n      intros,\n      split; rintro \u27e8c, h\u27e9,\n      { exact \u27e8c, congr_arg coe h\u27e9 },\n      { induction c using with_zero.cases_on,\n        { refine \u27e80, _\u27e9,\n          simpa using h },\n        { refine \u27e8c, _\u27e9,\n          simpa [\u2190with_zero.coe_add] using h } } }\n  end,\n  .. with_zero.order_bot,\n  .. with_zero.ordered_add_comm_monoid zero_le }\n\ninstance with_top.canonically_ordered_add_monoid {\u03b1 : Type u} [canonically_ordered_add_monoid \u03b1] :\n  canonically_ordered_add_monoid (with_top \u03b1) :=\n{ le_iff_exists_add := assume a b,\n  match a, b with\n  | a, none     := show a \u2264 \u22a4 \u2194 \u2203c, \u22a4 = a + c, by simp; refine \u27e8\u22a4, _\u27e9; cases a; refl\n  | (some a), (some b) := show (a:with_top \u03b1) \u2264 \u2191b \u2194 \u2203c:with_top \u03b1, \u2191b = \u2191a + c,\n    begin\n      simp [canonically_ordered_add_monoid.le_iff_exists_add, -add_comm],\n      split,\n      { rintro \u27e8c, rfl\u27e9, refine \u27e8c, _\u27e9, norm_cast },\n      { exact assume h, match b, h with _, \u27e8some c, rfl\u27e9 := \u27e8_, rfl\u27e9 end }\n    end\n  | none, some b := show (\u22a4 : with_top \u03b1) \u2264 b \u2194 \u2203c:with_top \u03b1, \u2191b = \u22a4 + c, by simp\n  end,\n  .. with_top.order_bot,\n  .. with_top.ordered_add_comm_monoid }\n\n@[priority 100, to_additive]\ninstance canonically_ordered_monoid.has_exists_mul_of_le (\u03b1 : Type u)\n  [canonically_ordered_monoid \u03b1] : has_exists_mul_of_le \u03b1 :=\n{ exists_mul_of_le := \u03bb a b hab, le_iff_exists_mul.mp hab }\n\nend canonically_ordered_monoid\n\nlemma pos_of_gt {M : Type*} [canonically_ordered_add_monoid M] {n m : M} (h : n < m) : 0 < m :=\nlt_of_le_of_lt (zero_le _) h\n\n/-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid\n    whose ordering is a linear order. -/\n@[protect_proj, ancestor canonically_ordered_add_monoid linear_order]\nclass canonically_linear_ordered_add_monoid (\u03b1 : Type*)\n      extends canonically_ordered_add_monoid \u03b1, linear_order \u03b1\n\n/-- A canonically linear-ordered monoid is a canonically ordered monoid\n    whose ordering is a linear order. -/\n@[protect_proj, ancestor canonically_ordered_monoid linear_order, to_additive]\nclass canonically_linear_ordered_monoid (\u03b1 : Type*)\n      extends canonically_ordered_monoid \u03b1, linear_order \u03b1\n\nsection canonically_linear_ordered_monoid\nvariables [canonically_linear_ordered_monoid \u03b1]\n\n@[priority 100, to_additive]  -- see Note [lower instance priority]\ninstance canonically_linear_ordered_monoid.semilattice_sup : semilattice_sup \u03b1 :=\n{ ..lattice_of_linear_order }\n\ninstance with_top.canonically_linear_ordered_add_monoid\n  (\u03b1 : Type*) [canonically_linear_ordered_add_monoid \u03b1] :\n    canonically_linear_ordered_add_monoid (with_top \u03b1) :=\n{ .. (infer_instance : canonically_ordered_add_monoid (with_top \u03b1)),\n  .. (infer_instance : linear_order (with_top \u03b1)) }\n\n@[to_additive]\nlemma min_mul_distrib (a b c : \u03b1) : min a (b * c) = min a (min a b * min a c) :=\nbegin\n  cases le_total a b with hb hb,\n  { simp [hb, le_mul_right] },\n  { cases le_total a c with hc hc,\n    { simp [hc, le_mul_left] },\n    { simp [hb, hc] } }\nend\n\n@[to_additive]\nlemma min_mul_distrib' (a b c : \u03b1) : min (a * b) c = min (min a c * min b c) c :=\nby simpa [min_comm _ c] using min_mul_distrib c a b\n\n@[simp, to_additive]\nlemma one_min (a : \u03b1) : min 1 a = 1 :=\nmin_eq_left (one_le a)\n\n@[simp, to_additive]\nlemma min_one (a : \u03b1) : min a 1 = 1 :=\nmin_eq_right (one_le a)\n\nend canonically_linear_ordered_monoid\n\n/-- An ordered cancellative additive commutative monoid\nis an additive commutative monoid with a partial order,\nin which addition is cancellative and monotone. -/\n@[protect_proj, ancestor add_cancel_comm_monoid partial_order]\nclass ordered_cancel_add_comm_monoid (\u03b1 : Type u)\n      extends add_cancel_comm_monoid \u03b1, partial_order \u03b1 :=\n(add_le_add_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n(le_of_add_le_add_left : \u2200 a b c : \u03b1, a + b \u2264 a + c \u2192 b \u2264 c)\n\n/-- An ordered cancellative commutative monoid\nis a commutative monoid with a partial order,\nin which multiplication is cancellative and monotone. -/\n@[protect_proj, ancestor cancel_comm_monoid partial_order, to_additive]\nclass ordered_cancel_comm_monoid (\u03b1 : Type u)\n      extends cancel_comm_monoid \u03b1, partial_order \u03b1 :=\n(mul_le_mul_left       : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\n(le_of_mul_le_mul_left : \u2200 a b c : \u03b1, a * b \u2264 a * c \u2192 b \u2264 c)\n\nsection ordered_cancel_comm_monoid\nvariables [ordered_cancel_comm_monoid \u03b1] {a b c d : \u03b1}\n\n@[to_additive]\nlemma ordered_cancel_comm_monoid.lt_of_mul_lt_mul_left : \u2200 a b c : \u03b1, a * b < a * c \u2192 b < c :=\n\u03bb a b c h, lt_of_le_not_le\n  (ordered_cancel_comm_monoid.le_of_mul_le_mul_left a b c h.le) $\n  mt (\u03bb h, ordered_cancel_comm_monoid.mul_le_mul_left _ _ h _) (not_le_of_gt h)\n\n@[to_additive]\ninstance ordered_cancel_comm_monoid.to_contravariant_class_left\n  (M : Type*) [ordered_cancel_comm_monoid M] :\n  contravariant_class M M (*) (<) :=\n{ elim := \u03bb a b c, ordered_cancel_comm_monoid.lt_of_mul_lt_mul_left _ _ _ }\n\n/- This instance can be proven with `by apply_instance`.  However, by analogy with the\ninstance `ordered_cancel_comm_monoid.to_covariant_class_right` above, I imagine that without\nthis instance, some Type would not have a `contravariant_class M M (function.swap (*)) (<)`\ninstance. -/\n@[to_additive]\ninstance ordered_cancel_comm_monoid.to_contravariant_class_right\n  (M : Type*) [ordered_cancel_comm_monoid M] :\n  contravariant_class M M (swap (*)) (<) :=\ncontravariant_swap_mul_lt_of_contravariant_mul_lt M\n\n@[priority 100, to_additive]    -- see Note [lower instance priority]\ninstance ordered_cancel_comm_monoid.to_ordered_comm_monoid : ordered_comm_monoid \u03b1 :=\n{ ..\u2039ordered_cancel_comm_monoid \u03b1\u203a }\n\n/-- Pullback an `ordered_cancel_comm_monoid` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible, to_additive function.injective.ordered_cancel_add_comm_monoid\n\"Pullback an `ordered_cancel_add_comm_monoid` under an injective map.\"]\ndef function.injective.ordered_cancel_comm_monoid {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_cancel_comm_monoid \u03b2 :=\n{ le_of_mul_le_mul_left := \u03bb a b c (bc : f (a * b) \u2264 f (a * c)),\n    (mul_le_mul_iff_left (f a)).mp (by rwa [\u2190 mul, \u2190 mul]),\n  ..hf.left_cancel_semigroup f mul,\n  ..hf.ordered_comm_monoid f one mul }\n\nend ordered_cancel_comm_monoid\n\n/-! Some lemmas about types that have an ordering and a binary operation, with no\n  rules relating them. -/\n@[to_additive]\nlemma fn_min_mul_fn_max {\u03b2} [linear_order \u03b1] [comm_semigroup \u03b2] (f : \u03b1 \u2192 \u03b2) (n m : \u03b1) :\n  f (min n m) * f (max n m) = f n * f m :=\nby { cases le_total n m with h h; simp [h, mul_comm] }\n\n@[to_additive]\nlemma min_mul_max [linear_order \u03b1] [comm_semigroup \u03b1] (n m : \u03b1) :\n  min n m * max n m = n * m :=\nfn_min_mul_fn_max id n m\n\n/-- A linearly ordered cancellative additive commutative monoid\nis an additive commutative monoid with a decidable linear order\nin which addition is cancellative and monotone. -/\n@[protect_proj, ancestor ordered_cancel_add_comm_monoid linear_ordered_add_comm_monoid]\nclass linear_ordered_cancel_add_comm_monoid (\u03b1 : Type u)\n  extends ordered_cancel_add_comm_monoid \u03b1, linear_ordered_add_comm_monoid \u03b1\n\n/-- A linearly ordered cancellative commutative monoid\nis a commutative monoid with a linear order\nin which multiplication is cancellative and monotone. -/\n@[protect_proj, ancestor ordered_cancel_comm_monoid linear_ordered_comm_monoid, to_additive]\nclass linear_ordered_cancel_comm_monoid (\u03b1 : Type u)\n  extends ordered_cancel_comm_monoid \u03b1, linear_ordered_comm_monoid \u03b1\n\nsection covariant_class_mul_le\nvariables [linear_order \u03b1]\n\nsection has_mul\nvariable [has_mul \u03b1]\n\nsection left\nvariable [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n\n@[to_additive] lemma min_mul_mul_left (a b c : \u03b1) : min (a * b) (a * c) = a * min b c :=\n(monotone_id.const_mul' a).map_min.symm\n\n@[to_additive]\nlemma max_mul_mul_left (a b c : \u03b1) : max (a * b) (a * c) = a * max b c :=\n(monotone_id.const_mul' a).map_max.symm\n\nend left\n\nsection right\nvariable [covariant_class \u03b1 \u03b1 (function.swap (*)) (\u2264)]\n\n@[to_additive]\nlemma min_mul_mul_right (a b c : \u03b1) : min (a * c) (b * c) = min a b * c :=\n(monotone_id.mul_const' c).map_min.symm\n\n@[to_additive]\nlemma max_mul_mul_right (a b c : \u03b1) : max (a * c) (b * c) = max a b * c :=\n(monotone_id.mul_const' c).map_max.symm\n\nend right\n\nend has_mul\n\nvariable [monoid \u03b1]\n\n@[to_additive]\nlemma min_le_mul_of_one_le_right [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b : \u03b1} (hb : 1 \u2264 b) :\n  min a b \u2264 a * b :=\nmin_le_iff.2 $ or.inl $ le_mul_of_one_le_right' hb\n\n@[to_additive]\nlemma min_le_mul_of_one_le_left [covariant_class \u03b1 \u03b1 (function.swap (*)) (\u2264)] {a b : \u03b1}\n  (ha : 1 \u2264 a) : min a b \u2264 a * b :=\nmin_le_iff.2 $ or.inr $ le_mul_of_one_le_left' ha\n\n@[to_additive]\nlemma max_le_mul_of_one_le [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  [covariant_class \u03b1 \u03b1 (function.swap (*)) (\u2264)] {a b : \u03b1} (ha : 1 \u2264 a) (hb : 1 \u2264 b) :\n  max a b \u2264 a * b :=\nmax_le_iff.2 \u27e8le_mul_of_one_le_right' hb, le_mul_of_one_le_left' ha\u27e9\n\nend covariant_class_mul_le\n\nsection linear_ordered_cancel_comm_monoid\nvariables [linear_ordered_cancel_comm_monoid \u03b1]\n\n/-- Pullback a `linear_ordered_cancel_comm_monoid` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible, to_additive function.injective.linear_ordered_cancel_add_comm_monoid\n\"Pullback a `linear_ordered_cancel_add_comm_monoid` under an injective map.\"]\ndef function.injective.linear_ordered_cancel_comm_monoid {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  linear_ordered_cancel_comm_monoid \u03b2 :=\n{ ..hf.linear_ordered_comm_monoid f one mul,\n  ..hf.ordered_cancel_comm_monoid f one mul }\n\nend linear_ordered_cancel_comm_monoid\n\nnamespace order_dual\n\n@[to_additive] instance [h : has_mul \u03b1] : has_mul (order_dual \u03b1) := h\n@[to_additive] instance [h : has_one \u03b1] : has_one (order_dual \u03b1) := h\n@[to_additive] instance [h : monoid \u03b1] : monoid (order_dual \u03b1) := h\n@[to_additive] instance [h : comm_monoid \u03b1] : comm_monoid (order_dual \u03b1) := h\n@[to_additive] instance [h : cancel_comm_monoid \u03b1] : cancel_comm_monoid (order_dual \u03b1) := h\n\n@[to_additive]\ninstance contravariant_class_mul_le [has_le \u03b1] [has_mul \u03b1] [c : contravariant_class \u03b1 \u03b1 (*) (\u2264)] :\n  contravariant_class (order_dual \u03b1) (order_dual \u03b1) (*) (\u2264) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive]\ninstance covariant_class_mul_le [has_le \u03b1] [has_mul \u03b1] [c : covariant_class \u03b1 \u03b1 (*) (\u2264)] :\n  covariant_class (order_dual \u03b1) (order_dual \u03b1) (*) (\u2264) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive] instance contravariant_class_swap_mul_le [has_le \u03b1] [has_mul \u03b1]\n  [c : contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] :\n  contravariant_class (order_dual \u03b1) (order_dual \u03b1) (swap (*)) (\u2264) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive]\ninstance covariant_class_swap_mul_le [has_le \u03b1] [has_mul \u03b1]\n  [c : covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] :\n  covariant_class (order_dual \u03b1) (order_dual \u03b1) (swap (*)) (\u2264) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive]\ninstance contravariant_class_mul_lt [has_lt \u03b1] [has_mul \u03b1] [c : contravariant_class \u03b1 \u03b1 (*) (<)] :\n  contravariant_class (order_dual \u03b1) (order_dual \u03b1) (*) (<) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive]\ninstance covariant_class_mul_lt [has_lt \u03b1] [has_mul \u03b1] [c : covariant_class \u03b1 \u03b1 (*) (<)] :\n  covariant_class (order_dual \u03b1) (order_dual \u03b1) (*) (<) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive] instance contravariant_class_swap_mul_lt [has_lt \u03b1] [has_mul \u03b1]\n  [c : contravariant_class \u03b1 \u03b1 (swap (*)) (<)] :\n  contravariant_class (order_dual \u03b1) (order_dual \u03b1) (swap (*)) (<) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive]\ninstance covariant_class_swap_mul_lt [has_lt \u03b1] [has_mul \u03b1]\n  [c : covariant_class \u03b1 \u03b1 (swap (*)) (<)] :\n  covariant_class (order_dual \u03b1) (order_dual \u03b1) (swap (*)) (<) :=\n\u27e8c.1.flip\u27e9\n\n@[to_additive]\ninstance [ordered_comm_monoid \u03b1] : ordered_comm_monoid (order_dual \u03b1) :=\n{ mul_le_mul_left := \u03bb a b h c, mul_le_mul_left' h c,\n  .. order_dual.partial_order \u03b1,\n  .. order_dual.comm_monoid }\n\n@[to_additive ordered_cancel_add_comm_monoid.to_contravariant_class]\ninstance ordered_cancel_comm_monoid.to_contravariant_class [ordered_cancel_comm_monoid \u03b1] :\n  contravariant_class (order_dual \u03b1) (order_dual \u03b1) has_mul.mul has_le.le :=\n{ elim := \u03bb a b c bc, (ordered_cancel_comm_monoid.le_of_mul_le_mul_left a c b (dual_le.mp bc)) }\n\n@[to_additive]\ninstance [ordered_cancel_comm_monoid \u03b1] : ordered_cancel_comm_monoid (order_dual \u03b1) :=\n{ le_of_mul_le_mul_left := \u03bb a b c : \u03b1, le_of_mul_le_mul_left',\n  .. order_dual.ordered_comm_monoid, .. order_dual.cancel_comm_monoid }\n\n@[to_additive]\ninstance [linear_ordered_cancel_comm_monoid \u03b1] :\n  linear_ordered_cancel_comm_monoid (order_dual \u03b1) :=\n{ .. order_dual.linear_order \u03b1,\n  .. order_dual.ordered_cancel_comm_monoid }\n\n@[to_additive]\ninstance [linear_ordered_comm_monoid \u03b1] :\n  linear_ordered_comm_monoid (order_dual \u03b1) :=\n{ .. order_dual.linear_order \u03b1,\n  .. order_dual.ordered_comm_monoid }\n\nend order_dual\n\nsection linear_ordered_cancel_add_comm_monoid\nvariables [linear_ordered_cancel_add_comm_monoid \u03b1]\n\nlemma lt_or_lt_of_add_lt_add {a b m n : \u03b1} (h : m + n < a + b) : m < a \u2228 n < b :=\nby { contrapose! h, exact add_le_add h.1 h.2 }\n\nend linear_ordered_cancel_add_comm_monoid\n\nsection ordered_cancel_add_comm_monoid\n\nvariable [ordered_cancel_add_comm_monoid \u03b1]\n\nnamespace with_top\n\nlemma add_lt_add_iff_left {a b c : with_top \u03b1} (ha : a \u2260 \u22a4) : a + b < a + c \u2194 b < c :=\nbegin\n  lift a to \u03b1 using ha,\n  cases b; cases c,\n  { simp [none_eq_top] },\n  { simp [some_eq_coe, none_eq_top, coe_lt_top] },\n  { simp [some_eq_coe, none_eq_top, \u2190 coe_add, coe_lt_top] },\n  { simp [some_eq_coe, \u2190 coe_add, coe_lt_coe] }\nend\n\nlemma add_lt_add_iff_right {a b c : with_top \u03b1} (ha : a \u2260 \u22a4) : (c + a < b + a \u2194 c < b) :=\nby simp only [\u2190 add_comm a, add_lt_add_iff_left ha]\n\ninstance contravariant_class_add_lt : contravariant_class (with_top \u03b1) (with_top \u03b1) (+) (<) :=\nbegin\n  refine \u27e8\u03bb a b c h, _\u27e9,\n  cases a,\n  { rw [none_eq_top, top_add, top_add] at h, exact (lt_irrefl \u22a4 h).elim },\n  { exact (add_lt_add_iff_left coe_ne_top).1 h }\nend\n\nend with_top\n\nnamespace with_bot\n\nlemma add_lt_add_iff_left {a b c : with_bot \u03b1} (ha : a \u2260 \u22a5) : a + b < a + c \u2194 b < c :=\n@with_top.add_lt_add_iff_left (order_dual \u03b1) _ a c b ha\n\nlemma add_lt_add_iff_right {a b c : with_bot \u03b1} (ha : a \u2260 \u22a5) : b + a < c + a \u2194 b < c :=\n@with_top.add_lt_add_iff_right (order_dual \u03b1) _ _ _ _ ha\n\ninstance contravariant_class_add_lt : contravariant_class (with_bot \u03b1) (with_bot \u03b1) (+) (<) :=\n@order_dual.contravariant_class_add_lt (with_top $ order_dual \u03b1) _ _ _\n\nend with_bot\n\nend ordered_cancel_add_comm_monoid\n\nnamespace prod\n\nvariables {M N : Type*}\n\n@[to_additive]\ninstance [ordered_cancel_comm_monoid M] [ordered_cancel_comm_monoid N] :\n  ordered_cancel_comm_monoid (M \u00d7 N) :=\n{ mul_le_mul_left := \u03bb a b h c, \u27e8mul_le_mul_left' h.1 _, mul_le_mul_left' h.2 _\u27e9,\n  le_of_mul_le_mul_left := \u03bb a b c h, \u27e8le_of_mul_le_mul_left' h.1, le_of_mul_le_mul_left' h.2\u27e9,\n .. prod.cancel_comm_monoid, .. prod.partial_order M N }\n\nend prod\n\nsection type_tags\n\ninstance : \u03a0 [preorder \u03b1], preorder (multiplicative \u03b1) := id\ninstance : \u03a0 [preorder \u03b1], preorder (additive \u03b1) := id\ninstance : \u03a0 [partial_order \u03b1], partial_order (multiplicative \u03b1) := id\ninstance : \u03a0 [partial_order \u03b1], partial_order (additive \u03b1) := id\ninstance : \u03a0 [linear_order \u03b1], linear_order (multiplicative \u03b1) := id\ninstance : \u03a0 [linear_order \u03b1], linear_order (additive \u03b1) := id\n\ninstance [ordered_add_comm_monoid \u03b1] : ordered_comm_monoid (multiplicative \u03b1) :=\n{ mul_le_mul_left := @ordered_add_comm_monoid.add_le_add_left \u03b1 _,\n  ..multiplicative.partial_order,\n  ..multiplicative.comm_monoid }\n\ninstance [ordered_comm_monoid \u03b1] : ordered_add_comm_monoid (additive \u03b1) :=\n{ add_le_add_left := @ordered_comm_monoid.mul_le_mul_left \u03b1 _,\n  ..additive.partial_order,\n  ..additive.add_comm_monoid }\n\ninstance [ordered_cancel_add_comm_monoid \u03b1] : ordered_cancel_comm_monoid (multiplicative \u03b1) :=\n{ le_of_mul_le_mul_left := @ordered_cancel_add_comm_monoid.le_of_add_le_add_left \u03b1 _,\n  ..multiplicative.left_cancel_semigroup,\n  ..multiplicative.ordered_comm_monoid }\n\ninstance [ordered_cancel_comm_monoid \u03b1] : ordered_cancel_add_comm_monoid (additive \u03b1) :=\n{ le_of_add_le_add_left := @ordered_cancel_comm_monoid.le_of_mul_le_mul_left \u03b1 _,\n  ..additive.add_left_cancel_semigroup,\n  ..additive.ordered_add_comm_monoid }\n\ninstance [linear_ordered_add_comm_monoid \u03b1] : linear_ordered_comm_monoid (multiplicative \u03b1) :=\n{ ..multiplicative.linear_order,\n  ..multiplicative.ordered_comm_monoid }\n\ninstance [linear_ordered_comm_monoid \u03b1] : linear_ordered_add_comm_monoid (additive \u03b1) :=\n{ ..additive.linear_order,\n  ..additive.ordered_add_comm_monoid }\n\nend type_tags\n\n/-- The order embedding sending `b` to `a * b`, for some fixed `a`.\nSee also `order_iso.mul_left` when working in an ordered group. -/\n@[to_additive \"The order embedding sending `b` to `a + b`, for some fixed `a`.\n  See also `order_iso.add_left` when working in an additive ordered group.\", simps]\ndef order_embedding.mul_left\n  {\u03b1 : Type*} [has_mul \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] (m : \u03b1) : \u03b1 \u21aao \u03b1 :=\norder_embedding.of_strict_mono (\u03bb n, m * n) (\u03bb a b w, mul_lt_mul_left' w m)\n\n/-- The order embedding sending `b` to `b * a`, for some fixed `a`.\nSee also `order_iso.mul_right` when working in an ordered group. -/\n@[to_additive \"The order embedding sending `b` to `b + a`, for some fixed `a`.\n  See also `order_iso.add_right` when working in an additive ordered group.\", simps]\ndef order_embedding.mul_right\n  {\u03b1 : Type*} [has_mul \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (swap (*)) (<)] (m : \u03b1) :\n  \u03b1 \u21aao \u03b1 :=\norder_embedding.of_strict_mono (\u03bb n, n * m) (\u03bb a b w, mul_lt_mul_right' w m)\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/order/monoid.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7347630979783414}}
{"text": "/-\nCopyright (c) 2019 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann\n-/\nimport data.nat.gcd\nimport tactic.ring\n\n/-!\n# The Fibonacci Sequence\n\n## Summary\n\nDefinition of the Fibonacci sequence `F\u2080 = 0, F\u2081 = 1, F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081`.\n\n## Main Definitions\n\n- `fib` returns the stream of Fibonacci numbers.\n\n## Main Statements\n\n- `fib_add_two` : shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.`.\n- `fib_gcd`     : `fib n` is a strong divisibility sequence.\n\n## Implementation Notes\n\nFor efficiency purposes, the sequence is defined using `stream.iterate`.\n\n## Tags\n\nfib, fibonacci\n-/\n\nnamespace nat\n\n/--\nImplementation of the fibonacci sequence satisfying\n`fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`.\n\n*Note:* We use a stream iterator for better performance when compared to the naive recursive\nimplementation.\n-/\n@[pp_nodot]\ndef fib (n : \u2115) : \u2115 := ((\u03bb p : \u2115 \u00d7 \u2115, (p.snd, p.fst + p.snd))^[n] (0, 1)).fst\n\n@[simp] lemma fib_zero : fib 0 = 0 := rfl\n@[simp] lemma fib_one : fib 1 = 1 := rfl\n@[simp] lemma fib_two : fib 2 = 1 := rfl\n\n/-- Shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.` -/\nlemma fib_add_two {n : \u2115} : fib (n + 2) = fib n + fib (n + 1) :=\nby simp only [fib, function.iterate_succ']\n\nlemma fib_le_fib_succ {n : \u2115} : fib n \u2264 fib (n + 1) := by { cases n; simp [fib_add_two] }\n\n@[mono] lemma fib_mono : monotone fib :=\nmonotone_nat_of_le_succ $ \u03bb _, fib_le_fib_succ\n\nlemma fib_pos {n : \u2115} (n_pos : 0 < n) : 0 < fib n :=\ncalc 0 < fib 1 : dec_trivial\n   ... \u2264 fib n : fib_mono n_pos\n\nlemma fib_lt_fib_succ {n : \u2115} (hn : 2 \u2264 n) : fib n < fib (n + 1) :=\nbegin\n  rcases le_iff_exists_add.1 hn with \u27e8n, rfl\u27e9,\n  simp only [add_comm 2, fib_add_two], rw add_comm,\n  exact lt_add_of_pos_left _ (fib_pos succ_pos')\nend\n\n/-- `fib (n + 2)` is strictly monotone. -/\nlemma fib_add_two_strict_mono : strict_mono (\u03bb n, fib (n + 2)) :=\nbegin\n  refine strict_mono_nat_of_lt_succ (\u03bb n, _),\n  rw add_right_comm,\n  exact fib_lt_fib_succ (self_le_add_left _ _)\nend\n\nlemma le_fib_self {n : \u2115} (five_le_n : 5 \u2264 n) : n \u2264 fib n :=\nbegin\n  induction five_le_n with n five_le_n IH,\n  { -- 5 \u2264 fib 5\n    refl },\n  { -- n + 1 \u2264 fib (n + 1) for 5 \u2264 n\n    rw succ_le_iff,\n    calc n \u2264 fib n       : IH\n       ... < fib (n + 1) : fib_lt_fib_succ (le_trans dec_trivial five_le_n) }\nend\n\n/-- Subsequent Fibonacci numbers are coprime,\n  see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/\nlemma fib_coprime_fib_succ (n : \u2115) : nat.coprime (fib n) (fib (n + 1)) :=\nbegin\n  induction n with n ih,\n  { simp },\n  { rw [fib_add_two, coprime_add_self_right],\n    exact ih.symm }\nend\n\n/-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/\nlemma fib_add (m n : \u2115) :\n  fib m * fib n + fib (m + 1) * fib (n + 1) = fib (m + n + 1) :=\nbegin\n  induction n with n ih generalizing m,\n  { simp },\n  { intros,\n    specialize ih (m + 1),\n    rw [add_assoc m 1 n, add_comm 1 n] at ih,\n    simp only [fib_add_two, \u2190 ih],\n    ring, }\nend\n\n\nlemma gcd_fib_add_self (m n : \u2115) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) :=\nbegin\n  cases nat.eq_zero_or_pos n,\n  { rw h, simp },\n  replace h := nat.succ_pred_eq_of_pos h, rw [\u2190 h, succ_eq_add_one],\n  calc gcd (fib m) (fib (n.pred + 1 + m))\n        = gcd (fib m) (fib (n.pred) * (fib m) + fib (n.pred + 1) * fib (m + 1)) :\n    by { rw fib_add n.pred _, ring_nf }\n    ... = gcd (fib m) (fib (n.pred + 1) * fib (m + 1)) :\n    by rw [add_comm, gcd_add_mul_self (fib m) _ (fib (n.pred))]\n    ... = gcd (fib m) (fib (n.pred + 1)) :\n    coprime.gcd_mul_right_cancel_right\n      (fib (n.pred + 1)) (coprime.symm (fib_coprime_fib_succ m))\nend\n\nlemma gcd_fib_add_mul_self (m n : \u2115) : \u2200 k, gcd (fib m) (fib (n + k * m)) = gcd (fib m) (fib n)\n| 0     := by simp\n| (k+1) := by rw [\u2190 gcd_fib_add_mul_self k, add_mul, \u2190 add_assoc, one_mul, gcd_fib_add_self _ _]\n\n/-- `fib n` is a strong divisibility sequence,\n  see https://proofwiki.org/wiki/GCD_of_Fibonacci_Numbers -/\n\n\nlemma fib_dvd (m n : \u2115) (h : m \u2223 n) : fib m \u2223 fib n :=\nby rwa [gcd_eq_left_iff_dvd, \u2190 fib_gcd, gcd_eq_left_iff_dvd.mp]\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7347630905832017}}
{"text": "import BrownCs22.Library.Tactics \n\n/-\n\n# Welcome to the Lean section of HW1!\n\nSome general guidelines, before we get started.\n f\n* When you're doing Lean homework assignments, including this one,\n  do *not* edit any of the `import` statements above the \n  opening comment. This will most likely break our autograder.\n\n* Speaking of: when you submit this on Gradescope, you'll \n  upload it to a separate assignment than the PDF with your other\n  solutions. That's because we can autograde Lean, but not normal \n  math! In the future, we hope to let you upload both files to the \n  same assignment. But autograders are tricky and we haven't \n  figured it out yet.\n\n* Your goal in this assignment is to replace the `sorry`s in each \n  part with completed proofs. If you can't finish a problem and \n  want to submit the assignment half-complete, that's fine -- \n  but try to \"finish\" the proof by putting in more `sorry`s.\n\n  For example, if the original problem looks like this:\n-/\n\ntheorem example_1 (p : Prop) : p \u2192 p \u2192 p := by \n  sorry \n\n/- \n  and you work on it, but get stuck at this stage and can't finish:\n\ntheorem example_1 (p : Prop) : p \u2192 p \u2192 p := by \n  intro hp1\n  intro hp2\n\n  then you should \"finish\" it by writing `sorry` again:\n-/\n\ntheorem example_1' (p : Prop) : p \u2192 p \u2192 p := by \n  intro hp1\n  intro hp2\n  sorry\n\n/- \n  Notice that, with the `sorry`, `example_1` is highlighted in yellow.\n  Without the sorry, there is a red error message.\n  It's safest to submit a file with no red error messages,\n  to avoid any unexpected autograder failures.\n  The autograder will give you points if all of the warnings and errors are gone.\n\nLet's get started!\n-/\n\nvariable (p q r s : Prop)\n\n/-\n\n## Problem 1\n\nFill in the `sorry` in the proof below.\nThe elimination and introduction rules we talked about in Lecture 4\nwill be very helpful here!\n\n\n-/\n\n/- 3 points -/\ntheorem problem_1 : (p \u2227 q \u2227 r) \u2192 (p \u2227 r) := by \n  intro hpqr\n  eliminate hpqr with hp hqr\n  eliminate hqr with hq hr\n  split_goal\n  assumption\n  assumption\n/-\n\n## Problem 2\n\nConsider what the theorem below is saying! \n\"If the truth of `p` implies the falsity of `q`,\n then `p` and `q` cannot both be true.\"\n\nDoes that seem like a reasonable statement? \nWhat do the truth tables of `p \u2192 \u00ac q` and `\u00ac (p \u2227 q)` look like?\n(You do not need to write an answer, but think about it for a moment.\n Try the `#truth_table` command if you want.)\n\n\nAgain, your task is to fill in the `sorry` below to prove this statement.\n\n-/\n\n/- 3 points -/\ntheorem problem_2 : (p \u2192 \u00ac q) \u2192 \u00ac (p \u2227 q) := by \nintro hpnotq\nintro hpandq\neliminate hpandq with hp and hq\nhave hx : \u00acq := hpnotq hp\ncontradiction\n/-\n## Problem 3\n\nThis one's a little tricky! Let's reason through it in natural language.\n\nWe want to prove that, if we know `((p \u2228 q) \u2227 (p \u2192 r) \u2227 (q \u2192 s))`,\nthen we know `r \u2228 s`. \nSo suppose that we know `((p \u2228 q) \u2227 (p \u2192 r) \u2227 (q \u2192 s))`.\nOur goal is to show that `r \u2228 s` follows.\n\nFrom that long statement, we know three facts: `p \u2228 q`, `p \u2192 r`, and `q \u2192 s`. \nWe'll reason by cases on `p \u2228 q`.\n\nFirst, if we know `p`, then we know `r`, because `p \u2192 r`. \nAnd if we know `r` then we know `r \u2228 s`. \n\nSecond, if we know `q`, then we know `s`, because `q \u2192 s`. \nAnd if we know `s` then we know `r \u2228 s`.\n\nThat completes our proof!\n\nYour task: translate this argument to Lean.\n\n-/\n\n/- 4 points -/\ntheorem problem_3 : ((p \u2228 q) \u2227 (p \u2192 r) \u2227 (q \u2192 s)) \u2192 (r \u2228 s) := by \n  intro pqprqs\n  eliminate pqprqs with porq prqs\n  eliminate prqs with pr qs\n  eliminate porq with p q\n  { have hr : r := pr p\n    left\n    assumption\n  }\n  { have hs : s := qs q\n    right\n    assumption\n  }\n", "meta": {"author": "yuki-hayashita", "repo": "CS22-Lean-2023", "sha": "e682a80fd43f94d5751ee3ba242f4a5259d4977b", "save_path": "github-repos/lean/yuki-hayashita-CS22-Lean-2023", "path": "github-repos/lean/yuki-hayashita-CS22-Lean-2023/CS22-Lean-2023-e682a80fd43f94d5751ee3ba242f4a5259d4977b/BrownCs22/Homework/Hw1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430353105599, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.7347630868856315}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro, Anne Baanen\n-/\nimport algebra.ring.fin\nimport algebra.ring.prod\nimport linear_algebra.quotient\nimport ring_theory.congruence\nimport ring_theory.ideal.basic\nimport tactic.fin_cases\n/-!\n# Ideal quotients\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines ideal quotients as a special case of submodule quotients and proves some basic\nresults about these quotients.\n\nSee `algebra.ring_quot` for quotients of non-commutative rings.\n\n## Main definitions\n\n - `ideal.quotient`: the quotient of a commutative ring `R` by an ideal `I : ideal R`\n\n## Main results\n\n - `ideal.quotient_inf_ring_equiv_pi_quotient`: the **Chinese Remainder Theorem**\n-/\n\nuniverses u v w\n\nnamespace ideal\n\nopen set\nopen_locale big_operators\n\nvariables {R : Type u} [comm_ring R] (I : ideal R) {a b : R}\nvariables {S : Type v}\n\n/-- The quotient `R/I` of a ring `R` by an ideal `I`.\n\nThe ideal quotient of `I` is defined to equal the quotient of `I` as an `R`-submodule of `R`.\nThis definition is marked `reducible` so that typeclass instances can be shared between\n`ideal.quotient I` and `submodule.quotient I`.\n-/\n-- Note that at present `ideal` means a left-ideal,\n-- so this quotient is only useful in a commutative ring.\n-- We should develop quotients by two-sided ideals as well.\n@[reducible]\ninstance : has_quotient R (ideal R) := submodule.has_quotient\n\nnamespace quotient\nvariables {I} {x y : R}\n\ninstance has_one (I : ideal R) : has_one (R \u29f8 I) := \u27e8submodule.quotient.mk 1\u27e9\n\n/-- On `ideal`s, `submodule.quotient_rel` is a ring congruence. -/\nprotected def ring_con (I : ideal R) : ring_con R :=\n{ mul' := \u03bb a\u2081 b\u2081 a\u2082 b\u2082 h\u2081 h\u2082, begin\n    rw submodule.quotient_rel_r_def at h\u2081 h\u2082 \u22a2,\n    have F := I.add_mem (I.mul_mem_left a\u2082 h\u2081) (I.mul_mem_right b\u2081 h\u2082),\n    have : a\u2081 * a\u2082 - b\u2081 * b\u2082 = a\u2082 * (a\u2081 - b\u2081) + (a\u2082 - b\u2082) * b\u2081,\n    { rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b\u2081] },\n    rw \u2190 this at F,\n    change _ \u2208 _, convert F,\n  end,\n  .. quotient_add_group.con I.to_add_subgroup }\n\ninstance comm_ring (I : ideal R) : comm_ring (R \u29f8 I) :=\n{ ..submodule.quotient.add_comm_group I,  -- to help with unification\n  ..(quotient.ring_con I)^.quotient.comm_ring }\n\n/-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/\ndef mk (I : ideal R) : R \u2192+* (R \u29f8 I) :=\n\u27e8\u03bb a, submodule.quotient.mk a, rfl, \u03bb _ _, rfl, rfl, \u03bb _ _, rfl\u27e9\n\n/- Two `ring_homs`s from the quotient by an ideal are equal if their\ncompositions with `ideal.quotient.mk'` are equal.\n\nSee note [partially-applied ext lemmas]. -/\n@[ext]\nlemma ring_hom_ext [non_assoc_semiring S] \u2983f g : R \u29f8 I \u2192+* S\u2984\n  (h : f.comp (mk I) = g.comp (mk I)) : f = g :=\nring_hom.ext $ \u03bb x, quotient.induction_on' x $ (ring_hom.congr_fun h : _)\n\ninstance inhabited : inhabited (R \u29f8 I) := \u27e8mk I 37\u27e9\n\nprotected theorem eq : mk I x = mk I y \u2194 x - y \u2208 I := submodule.quotient.eq I\n\n@[simp] theorem mk_eq_mk (x : R) : (submodule.quotient.mk x : R \u29f8 I) = mk I x := rfl\n\nlemma eq_zero_iff_mem {I : ideal R} : mk I a = 0 \u2194 a \u2208 I :=\nsubmodule.quotient.mk_eq_zero _\n\ntheorem zero_eq_one_iff {I : ideal R} : (0 : R \u29f8 I) = 1 \u2194 I = \u22a4 :=\neq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm\n\ntheorem zero_ne_one_iff {I : ideal R} : (0 : R \u29f8 I) \u2260 1 \u2194 I \u2260 \u22a4 :=\nnot_congr zero_eq_one_iff\n\nprotected theorem nontrivial {I : ideal R} (hI : I \u2260 \u22a4) : nontrivial (R \u29f8 I) :=\n\u27e8\u27e80, 1, zero_ne_one_iff.2 hI\u27e9\u27e9\n\nlemma subsingleton_iff {I : ideal R} : subsingleton (R \u29f8 I) \u2194 I = \u22a4 :=\nby rw [eq_top_iff_one, \u2190 subsingleton_iff_zero_eq_one, eq_comm,\n       \u2190 I^.quotient.mk^.map_one, quotient.eq_zero_iff_mem]\n\ninstance : unique (R \u29f8 (\u22a4 : ideal R)) :=\n\u27e8\u27e80\u27e9, by rintro \u27e8x\u27e9; exact quotient.eq_zero_iff_mem.mpr submodule.mem_top\u27e9\n\nlemma mk_surjective : function.surjective (mk I) :=\n\u03bb y, quotient.induction_on' y (\u03bb x, exists.intro x rfl)\n\ninstance : ring_hom_surjective (mk I) := \u27e8mk_surjective\u27e9\n\n/-- If `I` is an ideal of a commutative ring `R`, if `q : R \u2192 R/I` is the quotient map, and if\n`s \u2286 R` is a subset, then `q\u207b\u00b9(q(s)) = \u22c3\u1d62(i + s)`, the union running over all `i \u2208 I`. -/\nlemma quotient_ring_saturate (I : ideal R) (s : set R) :\n  mk I \u207b\u00b9' (mk I '' s) = (\u22c3 x : I, (\u03bb y, x.1 + y) '' s) :=\nbegin\n  ext x,\n  simp only [mem_preimage, mem_image, mem_Union, ideal.quotient.eq],\n  exact \u27e8\u03bb \u27e8a, a_in, h\u27e9, \u27e8\u27e8_, I.neg_mem h\u27e9, a, a_in, by simp\u27e9,\n         \u03bb \u27e8\u27e8i, hi\u27e9, a, ha, eq\u27e9,\n           \u27e8a, ha, by rw [\u2190 eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub]; exact I.neg_mem hi\u27e9\u27e9\nend\n\ninstance no_zero_divisors (I : ideal R) [hI : I.is_prime] : no_zero_divisors (R \u29f8 I) :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero := \u03bb a b,\n    quotient.induction_on\u2082' a b $ \u03bb a b hab,\n      (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim\n        (or.inl \u2218 eq_zero_iff_mem.2)\n        (or.inr \u2218 eq_zero_iff_mem.2) }\n\ninstance is_domain (I : ideal R) [hI : I.is_prime] : is_domain (R \u29f8 I) :=\nlet _ := quotient.nontrivial hI.1 in by exactI no_zero_divisors.to_is_domain _\n\nlemma is_domain_iff_prime (I : ideal R) : is_domain (R \u29f8 I) \u2194 I.is_prime :=\nbegin\n  refine \u27e8\u03bb H, \u27e8zero_ne_one_iff.1 _, \u03bb x y h, _\u27e9, \u03bb h, by { resetI, apply_instance }\u27e9,\n  { haveI : nontrivial (R \u29f8 I) := \u27e8H.3\u27e9,\n    exact zero_ne_one },\n  { simp only [\u2190eq_zero_iff_mem, (mk I).map_mul] at \u22a2 h,\n    haveI := @is_domain.to_no_zero_divisors (R \u29f8 I) _ H,\n    exact eq_zero_or_eq_zero_of_mul_eq_zero h }\nend\n\nlemma exists_inv {I : ideal R} [hI : I.is_maximal] :\n  \u2200 {a : (R \u29f8 I)}, a \u2260 0 \u2192 \u2203 b : (R \u29f8 I), a * b = 1 :=\nbegin\n  rintro \u27e8a\u27e9 h,\n  rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with \u27e8b, c, hc, abc\u27e9,\n  rw [mul_comm] at abc,\n  refine \u27e8mk _ b, quot.sound _\u27e9, --quot.sound hb\n  rw \u2190 eq_sub_iff_add_eq' at abc,\n  rw [abc, \u2190 neg_mem_iff, neg_sub] at hc,\n  rw submodule.quotient_rel_r_def,\n  convert hc,\nend\n\nopen_locale classical\n\n/-- quotient by maximal ideal is a field. def rather than instance, since users will have\ncomputable inverses in some applications.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected noncomputable def field (I : ideal R) [hI : I.is_maximal] : field (R \u29f8 I) :=\n{ inv := \u03bb a, if ha : a = 0 then 0 else classical.some (exists_inv ha),\n  mul_inv_cancel := \u03bb a (ha : a \u2260 0), show a * dite _ _ _ = _,\n    by rw dif_neg ha;\n    exact classical.some_spec (exists_inv ha),\n  inv_zero := dif_pos rfl,\n  ..quotient.comm_ring I,\n  ..quotient.is_domain I }\n\n/-- If the quotient by an ideal is a field, then the ideal is maximal. -/\ntheorem maximal_of_is_field (I : ideal R)\n  (hqf : is_field (R \u29f8 I)) : I.is_maximal :=\nbegin\n  apply ideal.is_maximal_iff.2,\n  split,\n  { intro h,\n    rcases hqf.exists_pair_ne with \u27e8\u27e8x\u27e9, \u27e8y\u27e9, hxy\u27e9,\n    exact hxy (ideal.quotient.eq.2 (mul_one (x - y) \u25b8 I.mul_mem_left _ h)) },\n  { intros J x hIJ hxnI hxJ,\n    rcases hqf.mul_inv_cancel (mt ideal.quotient.eq_zero_iff_mem.1 hxnI) with \u27e8\u27e8y\u27e9, hy\u27e9,\n    rw [\u2190 zero_add (1 : R), \u2190 sub_self (x * y), sub_add],\n    refine J.sub_mem (J.mul_mem_right _ hxJ) (hIJ (ideal.quotient.eq.1 hy)) }\nend\n\n/-- The quotient of a ring by an ideal is a field iff the ideal is maximal. -/\ntheorem maximal_ideal_iff_is_field_quotient (I : ideal R) : I.is_maximal \u2194 is_field (R \u29f8 I) :=\n\u27e8\u03bb h, by { letI := @quotient.field _ _ I h, exact field.to_is_field _ }, maximal_of_is_field _\u27e9\n\nvariable [comm_ring S]\n\n/-- Given a ring homomorphism `f : R \u2192+* S` sending all elements of an ideal to zero,\nlift it to the quotient by this ideal. -/\ndef lift (I : ideal R) (f : R \u2192+* S) (H : \u2200 (a : R), a \u2208 I \u2192 f a = 0) :\n  R \u29f8 I \u2192+* S :=\n{ map_one' := f.map_one,\n  map_zero' := f.map_zero,\n  map_add' := \u03bb a\u2081 a\u2082, quotient.induction_on\u2082' a\u2081 a\u2082 f.map_add,\n  map_mul' := \u03bb a\u2081 a\u2082, quotient.induction_on\u2082' a\u2081 a\u2082 f.map_mul,\n  .. quotient_add_group.lift I.to_add_subgroup f.to_add_monoid_hom H }\n\n@[simp] lemma lift_mk (I : ideal R) (f : R \u2192+* S) (H : \u2200 (a : R), a \u2208 I \u2192 f a = 0) :\n  lift I f H (mk I a) = f a := rfl\n\nlemma lift_surjective_of_surjective (I : ideal R) {f : R \u2192+* S} (H : \u2200 (a : R), a \u2208 I \u2192 f a = 0)\n  (hf : function.surjective f) : function.surjective (ideal.quotient.lift I f H) :=\nbegin\n  intro y,\n  obtain \u27e8x, rfl\u27e9 := hf y,\n  use ideal.quotient.mk I x,\n  simp only [ideal.quotient.lift_mk],\nend\n\n/-- The ring homomorphism from the quotient by a smaller ideal to the quotient by a larger ideal.\n\nThis is the `ideal.quotient` version of `quot.factor` -/\ndef factor (S T : ideal R) (H : S \u2264 T) : R \u29f8 S \u2192+* R \u29f8 T :=\nideal.quotient.lift S (T^.quotient.mk) (\u03bb x hx, eq_zero_iff_mem.2 (H hx))\n\n@[simp] lemma factor_mk (S T : ideal R) (H : S \u2264 T) (x : R) :\n  factor S T H (mk S x) = mk T x := rfl\n\n@[simp] lemma factor_comp_mk (S T : ideal R) (H : S \u2264 T) : (factor S T H).comp (mk S) = mk T :=\nby { ext x, rw [ring_hom.comp_apply, factor_mk] }\n\nend quotient\n\n/-- Quotienting by equal ideals gives equivalent rings.\n\nSee also `submodule.quot_equiv_of_eq` and `ideal.quotient_equiv_alg_of_eq`.\n-/\ndef quot_equiv_of_eq {R : Type*} [comm_ring R] {I J : ideal R} (h : I = J) :\n  (R \u29f8 I) \u2243+* R \u29f8 J :=\n{ map_mul' := by { rintro \u27e8x\u27e9 \u27e8y\u27e9, refl },\n  .. submodule.quot_equiv_of_eq I J h }\n\n@[simp]\nlemma quot_equiv_of_eq_mk {R : Type*} [comm_ring R] {I J : ideal R} (h : I = J) (x : R) :\n  quot_equiv_of_eq h (ideal.quotient.mk I x) = ideal.quotient.mk J x :=\nrfl\n\n@[simp]\nlemma quot_equiv_of_eq_symm {R : Type*} [comm_ring R] {I J : ideal R} (h : I = J) :\n  (ideal.quot_equiv_of_eq h).symm = ideal.quot_equiv_of_eq h.symm :=\nby ext; refl\n\nsection pi\nvariables (\u03b9 : Type v)\n\n/-- `R^n/I^n` is a `R/I`-module. -/\ninstance module_pi : module (R \u29f8 I) ((\u03b9 \u2192 R) \u29f8 I.pi \u03b9) :=\n{ smul := \u03bb c m, quotient.lift_on\u2082' c m (\u03bb r m, submodule.quotient.mk $ r \u2022 m) begin\n    intros c\u2081 m\u2081 c\u2082 m\u2082 hc hm,\n    apply ideal.quotient.eq.2,\n    rw submodule.quotient_rel_r_def at hc hm,\n    intro i,\n    exact I.mul_sub_mul_mem hc (hm i),\n  end,\n  one_smul := begin\n    rintro \u27e8a\u27e9,\n    convert_to ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact one_mul (a i),\n  end,\n  mul_smul := begin\n    rintro \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n    convert_to ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    simp only [(\u2022)],\n    congr' with i, exact mul_assoc a b (c i),\n  end,\n  smul_add := begin\n    rintro \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n    convert_to ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact mul_add a (b i) (c i),\n  end,\n  smul_zero := begin\n    rintro \u27e8a\u27e9,\n    convert_to ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact mul_zero a,\n  end,\n  add_smul := begin\n    rintro \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n    convert_to ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact add_mul a b (c i),\n  end,\n  zero_smul := begin\n    rintro \u27e8a\u27e9,\n    convert_to ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact zero_mul (a i),\n  end, }\n\n/-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/\nnoncomputable def pi_quot_equiv : ((\u03b9 \u2192 R) \u29f8 I.pi \u03b9) \u2243\u2097[(R \u29f8 I)] (\u03b9 \u2192 (R \u29f8 I)) :=\n{ to_fun := \u03bb x, quotient.lift_on' x (\u03bb f i, ideal.quotient.mk I (f i)) $\n    \u03bb a b hab, funext (\u03bb i, (submodule.quotient.eq' _).2\n      (quotient_add_group.left_rel_apply.mp hab i)),\n  map_add' := by { rintros \u27e8_\u27e9 \u27e8_\u27e9, refl },\n  map_smul' := by { rintros \u27e8_\u27e9 \u27e8_\u27e9, refl },\n  inv_fun := \u03bb x, ideal.quotient.mk (I.pi \u03b9) $ \u03bb i, quotient.out' (x i),\n  left_inv :=\n  begin\n    rintro \u27e8x\u27e9,\n    exact ideal.quotient.eq.2 (\u03bb i, ideal.quotient.eq.1 (quotient.out_eq' _))\n  end,\n  right_inv :=\n  begin\n    intro x,\n    ext i,\n    obtain \u27e8r, hr\u27e9 := @quot.exists_rep _ _ (x i),\n    simp_rw \u2190hr,\n    convert quotient.out_eq' _\n  end }\n\n/-- If `f : R^n \u2192 R^m` is an `R`-linear map and `I \u2286 R` is an ideal, then the image of `I^n` is\n    contained in `I^m`. -/\nlemma map_pi {\u03b9 : Type*} [finite \u03b9] {\u03b9' : Type w} (x : \u03b9 \u2192 R) (hi : \u2200 i, x i \u2208 I)\n  (f : (\u03b9 \u2192 R) \u2192\u2097[R] (\u03b9' \u2192 R)) (i : \u03b9') : f x i \u2208 I :=\nbegin\n  classical,\n  casesI nonempty_fintype \u03b9,\n  rw pi_eq_sum_univ x,\n  simp only [finset.sum_apply, smul_eq_mul, linear_map.map_sum, pi.smul_apply, linear_map.map_smul],\n  exact I.sum_mem (\u03bb j hj, I.mul_mem_right _ (hi j))\nend\n\nend pi\n\nsection chinese_remainder\nvariables {\u03b9 : Type v}\n\ntheorem exists_sub_one_mem_and_mem (s : finset \u03b9) {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i \u2208 s, \u2200 j \u2208 s, i \u2260 j \u2192 f i \u2294 f j = \u22a4) (i : \u03b9) (his : i \u2208 s) :\n  \u2203 r : R, r - 1 \u2208 f i \u2227 \u2200 j \u2208 s, j \u2260 i \u2192 r \u2208 f j :=\nbegin\n  have : \u2200 j \u2208 s, j \u2260 i \u2192 \u2203 r : R, \u2203 H : r - 1 \u2208 f i, r \u2208 f j,\n  { intros j hjs hji, specialize hf i his j hjs hji.symm,\n    rw [eq_top_iff_one, submodule.mem_sup] at hf,\n    rcases hf with \u27e8r, hri, s, hsj, hrs\u27e9, refine \u27e81 - r, _, _\u27e9,\n    { rw [sub_right_comm, sub_self, zero_sub], exact (f i).neg_mem hri },\n    { rw [\u2190 hrs, add_sub_cancel'], exact hsj } },\n  classical,\n  have : \u2203 g : \u03b9 \u2192 R, (\u2200 j, g j - 1 \u2208 f i) \u2227 \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2208 f j,\n  { choose g hg1 hg2,\n    refine \u27e8\u03bb j, if H : j \u2208 s \u2227 j \u2260 i then g j H.1 H.2 else 1, \u03bb j, _, \u03bb j, _\u27e9,\n    { split_ifs with h, { apply hg1 }, rw sub_self, exact (f i).zero_mem },\n    { intros hjs hji, rw dif_pos, { apply hg2 }, exact \u27e8hjs, hji\u27e9 } },\n  rcases this with \u27e8g, hgi, hgj\u27e9, use (\u220f x in s.erase i, g x), split,\n  { rw [\u2190 quotient.eq, ring_hom.map_one, ring_hom.map_prod],\n    apply finset.prod_eq_one, intros, rw [\u2190 ring_hom.map_one, quotient.eq], apply hgi },\n  intros j hjs hji, rw [\u2190 quotient.eq_zero_iff_mem, ring_hom.map_prod],\n  refine finset.prod_eq_zero (finset.mem_erase_of_ne_of_mem hji hjs) _,\n  rw quotient.eq_zero_iff_mem, exact hgj j hjs hji\nend\n\ntheorem exists_sub_mem [finite \u03b9] {f : \u03b9 \u2192 ideal R} (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4)\n  (g : \u03b9 \u2192 R) :\n  \u2203 r : R, \u2200 i, r - g i \u2208 f i :=\nbegin\n  casesI nonempty_fintype \u03b9,\n  have : \u2203 \u03c6 : \u03b9 \u2192 R, (\u2200 i, \u03c6 i - 1 \u2208 f i) \u2227 (\u2200 i j, i \u2260 j \u2192 \u03c6 i \u2208 f j),\n  { have := exists_sub_one_mem_and_mem (finset.univ : finset \u03b9) (\u03bb i _ j _ hij, hf i j hij),\n    choose \u03c6 h\u03c6,\n    existsi \u03bb i, \u03c6 i (finset.mem_univ i),\n    exact \u27e8\u03bb i, (h\u03c6 i _).1, \u03bb i j hij, (h\u03c6 i _).2 j (finset.mem_univ j) hij.symm\u27e9 },\n  rcases this with \u27e8\u03c6, h\u03c61, h\u03c62\u27e9,\n  use \u2211 i, g i * \u03c6 i,\n  intros i,\n  rw [\u2190 quotient.eq, ring_hom.map_sum],\n  refine eq.trans (finset.sum_eq_single i _ _) _,\n  { intros j _ hji, rw quotient.eq_zero_iff_mem, exact (f i).mul_mem_left _ (h\u03c62 j i hji) },\n  { intros hi, exact (hi $ finset.mem_univ i).elim },\n  specialize h\u03c61 i, rw [\u2190 quotient.eq, ring_hom.map_one] at h\u03c61,\n  rw [ring_hom.map_mul, h\u03c61, mul_one]\nend\n\n/-- The homomorphism from `R/(\u22c2 i, f i)` to `\u220f i, (R / f i)` featured in the Chinese\n  Remainder Theorem. It is bijective if the ideals `f i` are comaximal. -/\ndef quotient_inf_to_pi_quotient (f : \u03b9 \u2192 ideal R) :\n  R \u29f8 (\u2a05 i, f i) \u2192+* \u03a0 i, R \u29f8 f i :=\nquotient.lift (\u2a05 i, f i)\n  (pi.ring_hom (\u03bb i : \u03b9, (quotient.mk (f i) : _))) $\n  \u03bb r hr, begin\n    rw submodule.mem_infi at hr,\n    ext i,\n    exact quotient.eq_zero_iff_mem.2 (hr i)\n  end\n\ntheorem quotient_inf_to_pi_quotient_bijective [finite \u03b9] {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) :\n  function.bijective (quotient_inf_to_pi_quotient f) :=\n\u27e8\u03bb x y, quotient.induction_on\u2082' x y $ \u03bb r s hrs, quotient.eq.2 $\n  (submodule.mem_infi _).2 $ \u03bb i, quotient.eq.1 $\n  show quotient_inf_to_pi_quotient f (quotient.mk' r) i = _, by rw hrs; refl,\n\u03bb g, let \u27e8r, hr\u27e9 := exists_sub_mem hf (\u03bb i, quotient.out' (g i)) in\n\u27e8quotient.mk _ r, funext $ \u03bb i, quotient.out_eq' (g i) \u25b8 quotient.eq.2 (hr i)\u27e9\u27e9\n\n/-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/\nnoncomputable def quotient_inf_ring_equiv_pi_quotient [finite \u03b9] (f : \u03b9 \u2192 ideal R)\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) :\n  R \u29f8 (\u2a05 i, f i) \u2243+* \u03a0 i, R \u29f8 f i :=\n{ .. equiv.of_bijective _ (quotient_inf_to_pi_quotient_bijective hf),\n  .. quotient_inf_to_pi_quotient f }\n\nend chinese_remainder\n\n/-- **Chinese remainder theorem**, specialized to two ideals. -/\nnoncomputable def quotient_inf_equiv_quotient_prod (I J : ideal R)\n  (coprime : I \u2294 J = \u22a4) :\n  (R \u29f8 (I \u2293 J)) \u2243+* (R \u29f8 I) \u00d7 R \u29f8 J :=\nlet f : fin 2 \u2192 ideal R := ![I, J] in\nhave hf : \u2200 (i j : fin 2), i \u2260 j \u2192 f i \u2294 f j = \u22a4,\nby { intros i j h,\n  fin_cases i; fin_cases j; try { contradiction }; simpa [f, sup_comm] using coprime },\n(ideal.quot_equiv_of_eq (by simp [infi, inf_comm])).trans $\n(ideal.quotient_inf_ring_equiv_pi_quotient f hf).trans $\nring_equiv.pi_fin_two (\u03bb i, R \u29f8 f i)\n\n@[simp] lemma quotient_inf_equiv_quotient_prod_fst (I J : ideal R) (coprime : I \u2294 J = \u22a4)\n  (x : R \u29f8 (I \u2293 J)) : (quotient_inf_equiv_quotient_prod I J coprime x).fst =\n  ideal.quotient.factor (I \u2293 J) I inf_le_left x :=\nquot.induction_on x (\u03bb x, rfl)\n\n@[simp] lemma quotient_inf_equiv_quotient_prod_snd (I J : ideal R) (coprime : I \u2294 J = \u22a4)\n  (x : R \u29f8 (I \u2293 J)) : (quotient_inf_equiv_quotient_prod I J coprime x).snd =\n  ideal.quotient.factor (I \u2293 J) J inf_le_right x :=\nquot.induction_on x (\u03bb x, rfl)\n\n@[simp] \n\n@[simp] lemma snd_comp_quotient_inf_equiv_quotient_prod (I J : ideal R) (coprime : I \u2294 J = \u22a4) :\n  (ring_hom.snd _ _).comp\n    (quotient_inf_equiv_quotient_prod I J coprime : R \u29f8 I \u2293 J \u2192+* (R \u29f8 I) \u00d7 R \u29f8 J) =\n  ideal.quotient.factor (I \u2293 J) J inf_le_right :=\nby ext; refl\n\nend ideal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/ideal/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.734747392099494}}
{"text": "import tactic\nimport data.set.finite\nimport data.real.basic -- for metrics\n\n/-\n# (Re)-Building topological spaces in Lean\n\nMathlib has a large library of results on topological spaces, including various\nconstructions, separation axioms, Tychonoff's theorem, sheaves, Stone-\u010cech\ncompactification, Heine-Cantor, to name but a few.\nSee https://leanprover-community.github.io/theories/topology.html which for a\n(subset) of what's in library.\n\nBut today we will ignore all that, and build our own version of topological\nspaces from scratch!\n(On Friday morning Patrick Massot will lead a session exploring the existing\nmathlib library in more detail)\n\nTo get this file run either `leanproject get lftcm2020`, if you didn't already or cd to\nthat folder and run `git pull; leanproject get-mathlib-cache`, this is\n`src/exercise_sources/wednesday/topological_spaces.lean`.\n\nThe exercises are spread throughout, you needn't do them in order! They are marked as\nshort, medium and long, so I suggest you try some short ones first.\n\nFirst a little setup, we will be making definitions involving the real numbers,\nthe theory of which is not computable, and we'll use sets.\n-/\nnoncomputable theory\nopen set\n\n/-!\n## What is a topological space:\n\nThere are many definitions: one from Wikipedia:\n  A topological space is an ordered pair (X, \u03c4), where X is a set and \u03c4 is a\n  collection of subsets of X, satisfying the following axioms:\n  - The empty set and X itself belong to \u03c4.\n  - Any arbitrary (finite or infinite) union of members of \u03c4 still belongs to \u03c4.\n  - The intersection of any finite number of members of \u03c4 still belongs to \u03c4.\n\nWe can formalize this as follows: -/\n\nclass topological_space_wiki :=\n  (X : Type)  -- the underlying Type that the topology will be on\n  (\u03c4 : set (set X))  -- the set of open subsets of X\n  (empty_mem : \u2205 \u2208 \u03c4)  -- empty set is open\n  (univ_mem : univ \u2208 \u03c4)  -- whole space is open\n  (union : \u2200 B \u2286 \u03c4, \u22c3\u2080 B \u2208 \u03c4)  -- arbitrary unions (sUnions) of members of \u03c4 are open\n  (inter : \u2200 (B \u2286 \u03c4) (h : set.finite B), \u22c2\u2080 B \u2208 \u03c4)  -- finite intersections of\n                                                -- members of \u03c4 are open\n\n/-\nBefore we go on we should be sure we want to use this as our definition.\n-/\n\n\n@[ext]\nclass topological_space (X : Type) :=\n  (is_open : set X \u2192 Prop) -- why set X \u2192 Prop not set (set X)? former plays\n                           -- nicer with typeclasses later\n  (empty_mem : is_open \u2205)\n  (univ_mem : is_open univ)\n  (union : \u2200 (B : set (set X)) (h : \u2200 b \u2208 B, is_open b), is_open (\u22c3\u2080 B))\n  (inter : \u2200 (A B : set X) (hA : is_open A) (hB : is_open B), is_open (A \u2229 B))\n\nnamespace topological_space\n\n/- We can now work with topological spaces like this. -/\nexample (X : Type) [topological_space X] (U V W : set X) (hU : is_open U) (hV : is_open V)\n  (hW : is_open W) : is_open (U \u2229 V \u2229 W) :=\nbegin\n  apply inter _ _ _ hW,\n  exact inter _ _ hU hV,\nend\n\n/- ## Exercise 0 [short]:\nOne of the axioms of a topological space we have here is unnecessary, it follows\nfrom the others. If we remove it we'll have less work to do each time we want to\ncreate a new topological space so:\n\n1. Identify and remove the unneeded axiom, make sure to remove it throughout the file.\n2. Add the axiom back as a lemma with the same name and prove it based on the\n   others, so that the _interface_ is the same. -/\n\n\n/- Defining a basic topology now works like so: -/\ndef discrete (X : Type) : topological_space X :=\n{ is_open := \u03bb U, true, -- everything is open\n  empty_mem := trivial,\n  univ_mem := trivial,\n  union := begin intros B h, trivial, end,\n  inter := begin intros A hA B hB, trivial, end }\n\n/- ## Exercise 1 [medium]:\nOne way me might want to create topological spaces in practice is to take\nthe coarsest possible topological space containing a given set of is_open.\nTo define this we might say we want to define what `is_open` is given the set\nof generators.\nSo we want to define the predicate `is_open` by declaring that each generator\nwill be open, the intersection of two opens will be open, and each union of a\nset of opens will be open, and finally the empty and whole space (`univ`) must\nbe open. The cleanest way to do this is as an inductive definition.\n\nThe exercise is to make this definition of the topological space generated by a\ngiven set in Lean.\n\n### Hint:\nAs a hint for this exercise take a look at the following definition of a\nconstructible set of a topological space, defined by saying that an intersection\nof an open and a closed set is constructible and that the union of any pair of\nconstructible sets is constructible.\n\n(Bonus exercise: mathlib doesn't have any theory of constructible sets, make one and PR\nit! [arbitrarily long!], or just prove that open and closed sets are constructible for now) -/\n\ninductive is_constructible {X : Type} (T : topological_space X) : set X \u2192 Prop\n/- Given two open sets in `T`, the intersection of one with the complement of\n   the other open is locally closed, hence constructible: -/\n| locally_closed : \u2200 (A B : set X), is_open A \u2192 is_open B \u2192 is_constructible (A \u2229 B\u1d9c)\n-- Given two constructible sets their union is constructible:\n| union : \u2200 A B, is_constructible A \u2192 is_constructible B \u2192 is_constructible (A \u222a B)\n\n-- For example we can now use this definition to prove the empty set is constructible\nexample {X : Type} (T : topological_space X) : is_constructible T \u2205 :=\nbegin\n  -- The intersection of the whole space (open) with the empty set (closed) is\n  -- locally closed, hence constructible\n  have := is_constructible.locally_closed univ univ T.univ_mem T.univ_mem,\n  -- but simp knows that's just the empty set (`simp` uses `this` automatically)\n  simpa,\nend\n\n/-- The open sets of the least topology containing a collection of basic sets. -/\ninductive generated_open (X : Type) (g : set (set X)) : set X \u2192 Prop\n-- The exercise: Add a definition here defining which sets are generated by `g` like the\n-- `is_constructible` definition above.\n\n\n/-- The smallest topological space containing the collection `g` of basic sets -/\ndef generate_from (X : Type) (g : set (set X)) : topological_space X :=\n{ is_open   := generated_open X g,\n  empty_mem := sorry,\n  univ_mem  := sorry,\n  inter     := sorry,\n  union     := sorry }\n\n/- ## Exercise 2 [short]:\nDefine the indiscrete topology on any type using this.\n(To do it without this it is surprisingly fiddly to prove that the set `{\u2205, univ}`\nactually forms a topology) -/\ndef indiscrete (X : Type) : topological_space X :=\n  sorry\n\nend topological_space\n\nopen topological_space\n/- Now it is quite easy to give a topology on the product of a pair of\n   topological spaces. -/\ninstance prod.topological_space (X Y : Type) [topological_space X]\n  [topological_space Y] : topological_space (X \u00d7 Y) :=\ntopological_space.generate_from (X \u00d7 Y) {U | \u2203 (Ux : set X) (Uy : set Y)\n  (hx : is_open Ux) (hy : is_open Uy), U = Ux \u00d7\u02e2 Uy}\n\n-- the proof of this is bit long so I've left it out for the purpose of this file!\nlemma is_open_prod_iff (X Y : Type) [topological_space X] [topological_space Y]\n  {s : set (X \u00d7 Y)} :\nis_open s \u2194 (\u2200a b, (a, b) \u2208 s \u2192 \u2203 (u : set X) (v : set Y), is_open u \u2227 is_open v \u2227\n                                  a \u2208 u \u2227 b \u2208 v \u2227 u \u00d7\u02e2 v \u2286 s) := sorry\n\n/- # Metric spaces -/\n\nopen_locale big_operators\n\nclass metric_space_basic (X : Type) :=\n  (dist : X \u2192 X \u2192 \u211d)\n  (dist_eq_zero_iff : \u2200 x y, dist x y = 0 \u2194 x = y)\n  (dist_symm : \u2200 x y, dist x y = dist y x)\n  (triangle : \u2200 x y z, dist x z \u2264 dist x y + dist y z)\n\nnamespace metric_space_basic\nopen topological_space\n\n/- ## Exercise 3 [short]:\nWe have defined a metric space with a metric landing in \u211d, and made no mention of\nnonnegativity, (this is in line with the philosophy of using the easiest axioms for our\ndefinitions as possible, to make it easier to define individual metrics). Show that we\nreally did define the usual notion of metric space. -/\nlemma dist_nonneg {X : Type} [metric_space_basic X] (x y : X) : 0 \u2264 dist x y :=\nsorry\n\n/- From a metric space we get an induced topological space structure like so: -/\n\ninstance {X : Type} [metric_space_basic X] : topological_space X :=\ngenerate_from X { B | \u2203 (x : X) r, B = {y | dist x y < r} }\n\nend metric_space_basic\n\nopen metric_space_basic\n\n/- So far so good, now lets define the product of two metric spaces:\n\n## Exercise 4 [medium]:\nFill in the proofs here.\nHint: the computer can do boring casework you would never dream of in real life.\n`max` is equal to `if x < y then y else x` by `max_def` and the `split_ifs` tactic will\nbreak apart if statements. -/\ninstance prod.metric_space_basic (X Y : Type) [metric_space_basic X] [metric_space_basic Y] :\nmetric_space_basic (X \u00d7 Y) :=\n{ dist := \u03bb u v, max (dist u.fst v.fst) (dist u.snd v.snd),\n  dist_eq_zero_iff :=\n  sorry\n  ,\n  dist_symm := sorry,\n  triangle :=\n  sorry\n  }\n\n/- \u2621 Let's try to prove a simple lemma involving the product topology: \u2621 -/\n\nset_option trace.type_context.is_def_eq false\nexample (X : Type) [metric_space_basic X] : is_open {xy : X \u00d7 X | dist xy.fst xy.snd < 100 } :=\nbegin\n  -- rw is_open_prod_iff X X,\n\n  -- this fails, why? Because we have two subtly different topologies on the product\n  -- they are equal but the proof that they are equal is nontrivial and the\n  -- typeclass mechanism can't see that they automatically to apply. We need to change\n  -- our set-up.\n  sorry,\nend\n\n/- Note that lemma works fine when there is only one topology involved. -/\nlemma diag_closed (X : Type) [topological_space X] : is_open {xy : X \u00d7 X | xy.fst \u2260 xy.snd } :=\nbegin\n  rw is_open_prod_iff X X,\n  sorry, -- Don't try and fill this in: see below!\nend\n\n/- ## Exercise 5 [short]:\nThe previous lemma isn't true! It requires a separation axiom. Define a `class`\nthat posits that the topology on a type `X` satisfies this axiom. Mathlib uses\n`T_i` naming scheme for these axioms. -/\nclass t2_space (X : Type) [topological_space X] :=\n(t2 : sorry)\n\n/- (Bonus exercises [medium], the world is your oyster: prove the correct\nversion of the above lemma `diag_closed`, prove that the discrete topology is t2,\nor that any metric topology is t2, ). -/\n\n\n/- Let's fix the broken example from earlier, by redefining the topology on a metric space.\nWe have unfortunately created two topologies on `X \u00d7 Y`, one via `prod.topology`\nthat we defined earlier as the product of the two topologies coming from the\nrespective metric space structures. And one coming from the metric on the product.\n\nThese are equal, i.e. the same topology (otherwise mathematically the product\nwould not be a good definition). However they are not definitionally equal, there\nis as nontrivial proof to show they are the same. The typeclass system (which finds\nthe relevant topological space instance when we use lemmas involving topological\nspaces) isn't able to check that topological space structures which are equal\nfor some nontrivial reason are equal on the fly so it gets stuck.\n\nWe can use `extends` to say that a metric space is an extra structure on top of\nbeing a topological space so we are making a choice of topology for each metric space.\nThis may not be *definitionally* equal to the induced topology, but we should add the\naxiom that the metric and the topology are equal to stop us from creating a metric\ninducing a different topology to the topological structure we chose. -/\nclass metric_space (X : Type) extends topological_space X, metric_space_basic X :=\n  (compatible : \u2200 U, is_open U \u2194 generated_open X { B | \u2203 (x : X) r, B = {y | dist x y < r}} U)\n\nnamespace metric_space\n\nopen topological_space\n\n/- This might seem a bit inconvenient to have to define a topological space each time\nwe want a metric space.\n\nWe would still like a way of making a `metric_space` just given a metric and some\nproperties it satisfies, i.e. a `metric_space_basic`, so we should setup a metric space\nconstructor from a `metric_space_basic` by setting the topology to be the induced one. -/\n\ndef of_basic {X : Type} (m : metric_space_basic X) : metric_space X :=\n{ compatible := begin intros, refl, /- this should work when the above parts are complete -/ end,\n  ..m,\n  ..@metric_space_basic.topological_space X m }\n\n/- Now lets define the product of two metric spaces properly -/\ninstance {X Y : Type} [metric_space X] [metric_space Y] : metric_space (X \u00d7 Y) :=\n{ compatible :=\n  begin\n    -- Let's not fill this in for the demo, let me know if you do it!\n    sorry\n  end,\n  ..prod.topological_space X Y,\n  ..prod.metric_space_basic X Y, }\n\n/- unregister the bad instance we defined earlier -/\nlocal attribute [-instance] metric_space_basic.topological_space\n\n/- Now this will work, there is only one topological space on the product, we can\nrewrite like we tried to before a lemma about topologies our result on metric spaces,\nas there is only one topology here.\n\n## Exercise 6 [long?]:\nComplete the proof of the example (you can generalise the 100 too if it makes it\nfeel less silly). -/\n\nexample (X : Type) [metric_space X] : is_open {xy : X \u00d7 X | dist xy.fst xy.snd < 100 } :=\nbegin\n  rw is_open_prod_iff X X,\n  sorry\nend\n\nend metric_space\n\n\nnamespace topological_space\n/- As mentioned, there are many definitions of a topological space, for instance\none can define them via specifying a set of closed sets satisfying various\naxioms, this is equivalent and sometimes more convenient.\n\nWe _could_ create two distinct Types defined by different data and provide an\nequivalence between theses types, e.g. `topological_space_via_open_sets` and\n`topological_space_via_closed_sets`, but this would quickly get unwieldy.\nWhat's better is to make an alternative _constructor_ for our original\ntopological space. This is a function takes a set of subsets satisfying the\naxioms to be the closed sets of a topological space and creates the\ntopological space defined by the corresponding set of open sets.\n\n## Exercise 7 [medium]:\nComplete the following constructor of a topological space from a set of subsets\nof a given type `X` satisfying the axioms for the closed sets of a topology.\nHint: there are many useful lemmas about complements in mathlib, with names\ninvolving `compl`, like `compl_empty`, `compl_univ`, `compl_compl`, `compl_sUnion`,\n`mem_compl_image`, `compl_inter`, `compl_compl'`, `you can #check them to see what they say. -/\n\ndef mk_closed_sets\n  (X : Type)\n  (\u03c3 : set (set X))\n  (empty_mem : \u2205 \u2208 \u03c3)\n  (univ_mem : univ \u2208 \u03c3)\n  (inter : \u2200 B \u2286 \u03c3, \u22c2\u2080 B \u2208 \u03c3)\n  (union : \u2200 (A \u2208 \u03c3) (B \u2208 \u03c3), A \u222a B \u2208 \u03c3) :\ntopological_space X := {\n  is_open := \u03bb U, U \u2208 compl '' \u03c3, -- the corresponding `is_open`\n  empty_mem :=\n    sorry\n  ,\n  univ_mem :=\n    sorry\n  ,\n  union :=\n    sorry\n  ,\n  inter :=\n    sorry\n    }\n\n/- Here are some more exercises:\n\n## Exercise 8 [medium/long]:\nDefine the cofinite topology on any type (PR it to mathlib?).\n\n## Exercise 9 [medium/long]:\nDefine a normed space?\n\n## Exercise 10 [medium/long]:\nDefine more separation axioms?\n\n-/\n\nend topological_space\n\n", "meta": {"author": "leanprover-community", "repo": "lftcm2020", "sha": "cc683e2b074b61909310746d6acc1fb3d42d6ee2", "save_path": "github-repos/lean/leanprover-community-lftcm2020", "path": "github-repos/lean/leanprover-community-lftcm2020/lftcm2020-cc683e2b074b61909310746d6acc1fb3d42d6ee2/src/exercises_sources/wednesday/topological_spaces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7347473782800573}}
{"text": "/-\nCopyright (c) 2020 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module topology.sets.compacts\n! leanprover-community/mathlib commit 1ead22342e1a078bd44744ace999f85756555d35\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.Sets.Closeds\nimport Mathbin.Topology.QuasiSeparated\n\n/-!\n# Compact sets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define a few types of compact sets in a topological space.\n\n## Main Definitions\n\nFor a topological space `\u03b1`,\n* `compacts \u03b1`: The type of compact sets.\n* `nonempty_compacts \u03b1`: The type of non-empty compact sets.\n* `positive_compacts \u03b1`: The type of compact sets with non-empty interior.\n* `compact_opens \u03b1`: The type of compact open sets. This is a central object in the study of\n  spectral spaces.\n-/\n\n\nopen Set\n\nvariable {\u03b1 \u03b2 : Type _} [TopologicalSpace \u03b1] [TopologicalSpace \u03b2]\n\nnamespace TopologicalSpace\n\n/-! ### Compact sets -/\n\n\n#print TopologicalSpace.Compacts /-\n/-- The type of compact sets of a topological space. -/\nstructure Compacts (\u03b1 : Type _) [TopologicalSpace \u03b1] where\n  carrier : Set \u03b1\n  is_compact' : IsCompact carrier\n#align topological_space.compacts TopologicalSpace.Compacts\n-/\n\nnamespace Compacts\n\nvariable {\u03b1}\n\ninstance : SetLike (Compacts \u03b1) \u03b1 where\n  coe := Compacts.carrier\n  coe_injective' s t h := by\n    cases s\n    cases t\n    congr\n\n#print TopologicalSpace.Compacts.isCompact /-\nprotected theorem isCompact (s : Compacts \u03b1) : IsCompact (s : Set \u03b1) :=\n  s.is_compact'\n#align topological_space.compacts.is_compact TopologicalSpace.Compacts.isCompact\n-/\n\ninstance (K : Compacts \u03b1) : CompactSpace K :=\n  isCompact_iff_compactSpace.1 K.IsCompact\n\ninstance : CanLift (Set \u03b1) (Compacts \u03b1) coe IsCompact where prf K hK := \u27e8\u27e8K, hK\u27e9, rfl\u27e9\n\n#print TopologicalSpace.Compacts.ext /-\n@[ext]\nprotected theorem ext {s t : Compacts \u03b1} (h : (s : Set \u03b1) = t) : s = t :=\n  SetLike.ext' h\n#align topological_space.compacts.ext TopologicalSpace.Compacts.ext\n-/\n\n#print TopologicalSpace.Compacts.coe_mk /-\n@[simp]\ntheorem coe_mk (s : Set \u03b1) (h) : (mk s h : Set \u03b1) = s :=\n  rfl\n#align topological_space.compacts.coe_mk TopologicalSpace.Compacts.coe_mk\n-/\n\n#print TopologicalSpace.Compacts.carrier_eq_coe /-\n@[simp]\ntheorem carrier_eq_coe (s : Compacts \u03b1) : s.carrier = s :=\n  rfl\n#align topological_space.compacts.carrier_eq_coe TopologicalSpace.Compacts.carrier_eq_coe\n-/\n\ninstance : Sup (Compacts \u03b1) :=\n  \u27e8fun s t => \u27e8s \u222a t, s.IsCompact.union t.IsCompact\u27e9\u27e9\n\ninstance [T2Space \u03b1] : Inf (Compacts \u03b1) :=\n  \u27e8fun s t => \u27e8s \u2229 t, s.IsCompact.inter t.IsCompact\u27e9\u27e9\n\ninstance [CompactSpace \u03b1] : Top (Compacts \u03b1) :=\n  \u27e8\u27e8univ, isCompact_univ\u27e9\u27e9\n\ninstance : Bot (Compacts \u03b1) :=\n  \u27e8\u27e8\u2205, isCompact_empty\u27e9\u27e9\n\ninstance : SemilatticeSup (Compacts \u03b1) :=\n  SetLike.coe_injective.SemilatticeSup _ fun _ _ => rfl\n\ninstance [T2Space \u03b1] : DistribLattice (Compacts \u03b1) :=\n  SetLike.coe_injective.DistribLattice _ (fun _ _ => rfl) fun _ _ => rfl\n\ninstance : OrderBot (Compacts \u03b1) :=\n  OrderBot.lift (coe : _ \u2192 Set \u03b1) (fun _ _ => id) rfl\n\ninstance [CompactSpace \u03b1] : BoundedOrder (Compacts \u03b1) :=\n  BoundedOrder.lift (coe : _ \u2192 Set \u03b1) (fun _ _ => id) rfl rfl\n\n/-- The type of compact sets is inhabited, with default element the empty set. -/\ninstance : Inhabited (Compacts \u03b1) :=\n  \u27e8\u22a5\u27e9\n\n/- warning: topological_space.compacts.coe_sup -> TopologicalSpace.Compacts.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.hasSup.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) (Sup.sup.{u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.instSupCompacts.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup\u2093'. -/\n@[simp]\ntheorem coe_sup (s t : Compacts \u03b1) : (\u2191(s \u2294 t) : Set \u03b1) = s \u222a t :=\n  rfl\n#align topological_space.compacts.coe_sup TopologicalSpace.Compacts.coe_sup\n\n/- warning: topological_space.compacts.coe_inf -> TopologicalSpace.Compacts.coe_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] (s : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) (Inf.inf.{u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.hasInf.{u1} \u03b1 _inst_1 _inst_3) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] (s : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) (Inf.inf.{u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.instInfCompacts.{u1} \u03b1 _inst_1 _inst_3) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf\u2093'. -/\n@[simp]\ntheorem coe_inf [T2Space \u03b1] (s t : Compacts \u03b1) : (\u2191(s \u2293 t) : Set \u03b1) = s \u2229 t :=\n  rfl\n#align topological_space.compacts.coe_inf TopologicalSpace.Compacts.coe_inf\n\n#print TopologicalSpace.Compacts.coe_top /-\n@[simp]\ntheorem coe_top [CompactSpace \u03b1] : (\u2191(\u22a4 : Compacts \u03b1) : Set \u03b1) = univ :=\n  rfl\n#align topological_space.compacts.coe_top TopologicalSpace.Compacts.coe_top\n-/\n\n#print TopologicalSpace.Compacts.coe_bot /-\n@[simp]\ntheorem coe_bot : (\u2191(\u22a5 : Compacts \u03b1) : Set \u03b1) = \u2205 :=\n  rfl\n#align topological_space.compacts.coe_bot TopologicalSpace.Compacts.coe_bot\n-/\n\n/- warning: topological_space.compacts.coe_finset_sup -> TopologicalSpace.Compacts.coe_finset_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Type.{u2}} {s : Finset.{u2} \u03b9} {f : \u03b9 -> (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1)}, Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) (Finset.sup.{u1, u2} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b9 (TopologicalSpace.Compacts.semilatticeSup.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.orderBot.{u1} \u03b1 _inst_1) s f)) (Finset.sup.{u1, u2} (Set.{u1} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u1} (Set.{u1} \u03b1) (ConditionallyCompleteLattice.toLattice.{u1} (Set.{u1} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1))))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1))) s (fun (i : \u03b9) => (fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) (f i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Type.{u2}} {s : Finset.{u2} \u03b9} {f : \u03b9 -> (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1)}, Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) (Finset.sup.{u1, u2} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b9 (TopologicalSpace.Compacts.instSemilatticeSupCompacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.instOrderBotCompactsToLEToPreorderToPartialOrderInstSemilatticeSupCompacts.{u1} \u03b1 _inst_1) s f)) (Finset.sup.{u1, u2} (Set.{u1} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u1} (Set.{u1} \u03b1) (ConditionallyCompleteLattice.toLattice.{u1} (Set.{u1} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} \u03b1) (Preorder.toLE.{u1} (Set.{u1} \u03b1) (PartialOrder.toPreorder.{u1} (Set.{u1} \u03b1) (SemilatticeSup.toPartialOrder.{u1} (Set.{u1} \u03b1) (Lattice.toSemilatticeSup.{u1} (Set.{u1} \u03b1) (ConditionallyCompleteLattice.toLattice.{u1} (Set.{u1} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1)))))))))) (CompleteLattice.toBoundedOrder.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1)))))) s (fun (i : \u03b9) => SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b1 _inst_1) (f i)))\nCase conversion may be inaccurate. Consider using '#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup\u2093'. -/\n@[simp]\ntheorem coe_finset_sup {\u03b9 : Type _} {s : Finset \u03b9} {f : \u03b9 \u2192 Compacts \u03b1} :\n    (\u2191(s.sup f) : Set \u03b1) = s.sup fun i => f i := by\n  classical\n    refine' Finset.induction_on s rfl fun a s _ h => _\n    simp_rw [Finset.sup_insert, coe_sup, sup_eq_union]\n    congr\n#align topological_space.compacts.coe_finset_sup TopologicalSpace.Compacts.coe_finset_sup\n\n#print TopologicalSpace.Compacts.map /-\n/-- The image of a compact set under a continuous function. -/\nprotected def map (f : \u03b1 \u2192 \u03b2) (hf : Continuous f) (K : Compacts \u03b1) : Compacts \u03b2 :=\n  \u27e8f '' K.1, K.2.image hf\u27e9\n#align topological_space.compacts.map TopologicalSpace.Compacts.map\n-/\n\n/- warning: topological_space.compacts.coe_map -> TopologicalSpace.Compacts.coe_map is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2} (hf : Continuous.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) (s : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1), Eq.{succ u2} (Set.{u2} \u03b2) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) \u03b2 (TopologicalSpace.Compacts.setLike.{u2} \u03b2 _inst_2)))) (TopologicalSpace.Compacts.map.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f hf s)) (Set.image.{u1, u2} \u03b1 \u03b2 f ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b2] {f : \u03b1 -> \u03b2} (hf : Continuous.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f) (s : TopologicalSpace.Compacts.{u2} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b2) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b2 _inst_2) \u03b2 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b2 _inst_2) (TopologicalSpace.Compacts.map.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f hf s)) (Set.image.{u2, u1} \u03b1 \u03b2 f (SetLike.coe.{u2, u2} (TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u2} \u03b1 _inst_1) s))\nCase conversion may be inaccurate. Consider using '#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map\u2093'. -/\n@[simp]\ntheorem coe_map {f : \u03b1 \u2192 \u03b2} (hf : Continuous f) (s : Compacts \u03b1) : (s.map f hf : Set \u03b2) = f '' s :=\n  rfl\n#align topological_space.compacts.coe_map TopologicalSpace.Compacts.coe_map\n\n#print TopologicalSpace.Compacts.equiv /-\n/-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/\n@[simp]\nprotected def equiv (f : \u03b1 \u2243\u209c \u03b2) : Compacts \u03b1 \u2243 Compacts \u03b2\n    where\n  toFun := Compacts.map f f.Continuous\n  invFun := Compacts.map _ f.symm.Continuous\n  left_inv s := by\n    ext1\n    simp only [coe_map, \u2190 image_comp, f.symm_comp_self, image_id]\n  right_inv s := by\n    ext1\n    simp only [coe_map, \u2190 image_comp, f.self_comp_symm, image_id]\n#align topological_space.compacts.equiv TopologicalSpace.Compacts.equiv\n-/\n\n/- warning: topological_space.compacts.equiv_to_fun_val -> TopologicalSpace.Compacts.equiv_to_fun_val is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2] (f : Homeomorph.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (K : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1), Eq.{succ u2} (Set.{u2} \u03b2) (TopologicalSpace.Compacts.carrier.{u2} \u03b2 _inst_2 (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2)) (fun (_x : Equiv.{succ u1, succ u2} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2)) => (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) -> (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2)) (Equiv.hasCoeToFun.{succ u1, succ u2} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2)) (TopologicalSpace.Compacts.equiv.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) K)) (Set.preimage.{u2, u1} \u03b2 \u03b1 (coeFn.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Homeomorph.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (fun (_x : Homeomorph.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) => \u03b2 -> \u03b1) (Homeomorph.hasCoeToFun.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1) (Homeomorph.symm.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f)) (TopologicalSpace.Compacts.carrier.{u1} \u03b1 _inst_1 K))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b2] (f : Homeomorph.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2) (K : TopologicalSpace.Compacts.{u2} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b2) (TopologicalSpace.Compacts.carrier.{u1} \u03b2 _inst_2 (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (Equiv.{succ u2, succ u1} (TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) (TopologicalSpace.Compacts.{u1} \u03b2 _inst_2)) (TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) (fun (_x : TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) => TopologicalSpace.Compacts.{u1} \u03b2 _inst_2) _x) (Equiv.instFunLikeEquiv.{succ u2, succ u1} (TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) (TopologicalSpace.Compacts.{u1} \u03b2 _inst_2)) (TopologicalSpace.Compacts.equiv.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f) K)) (Set.preimage.{u1, u2} \u03b2 \u03b1 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (Homeomorph.{u1, u2} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 (fun (_x : \u03b2) => \u03b1) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (Homeomorph.{u1, u2} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (EquivLike.toEmbeddingLike.{max (succ u1) (succ u2), succ u1, succ u2} (Homeomorph.{u1, u2} \u03b2 \u03b1 _inst_2 _inst_1) \u03b2 \u03b1 (Homeomorph.instEquivLikeHomeomorph.{u1, u2} \u03b2 \u03b1 _inst_2 _inst_1))) (Homeomorph.symm.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f)) (TopologicalSpace.Compacts.carrier.{u2} \u03b1 _inst_1 K))\nCase conversion may be inaccurate. Consider using '#align topological_space.compacts.equiv_to_fun_val TopologicalSpace.Compacts.equiv_to_fun_val\u2093'. -/\n/-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/\ntheorem equiv_to_fun_val (f : \u03b1 \u2243\u209c \u03b2) (K : Compacts \u03b1) : (Compacts.equiv f K).1 = f.symm \u207b\u00b9' K.1 :=\n  congr_fun (image_eq_preimage_of_inverse f.left_inv f.right_inv) K.1\n#align topological_space.compacts.equiv_to_fun_val TopologicalSpace.Compacts.equiv_to_fun_val\n\n/- warning: topological_space.compacts.prod -> TopologicalSpace.Compacts.prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) -> (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) -> (TopologicalSpace.Compacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) -> (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) -> (TopologicalSpace.Compacts.{max u2 u1} (Prod.{u1, u2} \u03b1 \u03b2) (instTopologicalSpaceProd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nCase conversion may be inaccurate. Consider using '#align topological_space.compacts.prod TopologicalSpace.Compacts.prod\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/-- The product of two `compacts`, as a `compacts` in the product space. -/\nprotected def prod (K : Compacts \u03b1) (L : Compacts \u03b2) : Compacts (\u03b1 \u00d7 \u03b2)\n    where\n  carrier := K \u00d7\u02e2 L\n  is_compact' := IsCompact.prod K.2 L.2\n#align topological_space.compacts.prod TopologicalSpace.Compacts.prod\n\n/- warning: topological_space.compacts.coe_prod -> TopologicalSpace.Compacts.coe_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2] (K : TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (L : TopologicalSpace.Compacts.{u2} \u03b2 _inst_2), Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ((fun (a : Type.{max u1 u2}) (b : Type.{max u1 u2}) [self : HasLiftT.{succ (max u1 u2), succ (max u1 u2)} a b] => self.0) (TopologicalSpace.Compacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (HasLiftT.mk.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.Compacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (CoeTC\u2093.coe.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.Compacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (SetLike.Set.hasCoeT.{max u1 u2, max u1 u2} (TopologicalSpace.Compacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u1, u2} \u03b1 \u03b2) (TopologicalSpace.Compacts.setLike.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))))) (TopologicalSpace.Compacts.prod.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u1, u2} \u03b1 \u03b2 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.setLike.{u1} \u03b1 _inst_1)))) K) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.Compacts.{u2} \u03b2 _inst_2) \u03b2 (TopologicalSpace.Compacts.setLike.{u2} \u03b2 _inst_2)))) L))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b2] (K : TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) (L : TopologicalSpace.Compacts.{u1} \u03b2 _inst_2), Eq.{max (succ u2) (succ u1)} (Set.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2)) (SetLike.coe.{max u2 u1, max u2 u1} (TopologicalSpace.Compacts.{max u1 u2} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u2, u1} \u03b1 \u03b2) (TopologicalSpace.Compacts.instSetLikeCompacts.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (TopologicalSpace.Compacts.prod.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u2, u1} \u03b1 \u03b2 (SetLike.coe.{u2, u2} (TopologicalSpace.Compacts.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Compacts.instSetLikeCompacts.{u2} \u03b1 _inst_1) K) (SetLike.coe.{u1, u1} (TopologicalSpace.Compacts.{u1} \u03b2 _inst_2) \u03b2 (TopologicalSpace.Compacts.instSetLikeCompacts.{u1} \u03b2 _inst_2) L))\nCase conversion may be inaccurate. Consider using '#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[simp]\ntheorem coe_prod (K : Compacts \u03b1) (L : Compacts \u03b2) : (K.Prod L : Set (\u03b1 \u00d7 \u03b2)) = K \u00d7\u02e2 L :=\n  rfl\n#align topological_space.compacts.coe_prod TopologicalSpace.Compacts.coe_prod\n\nend Compacts\n\n/-! ### Nonempty compact sets -/\n\n\n#print TopologicalSpace.NonemptyCompacts /-\n/-- The type of nonempty compact sets of a topological space. -/\nstructure NonemptyCompacts (\u03b1 : Type _) [TopologicalSpace \u03b1] extends Compacts \u03b1 where\n  nonempty' : carrier.Nonempty\n#align topological_space.nonempty_compacts TopologicalSpace.NonemptyCompacts\n-/\n\nnamespace NonemptyCompacts\n\ninstance : SetLike (NonemptyCompacts \u03b1) \u03b1\n    where\n  coe s := s.carrier\n  coe_injective' s t h := by\n    obtain \u27e8\u27e8_, _\u27e9, _\u27e9 := s\n    obtain \u27e8\u27e8_, _\u27e9, _\u27e9 := t\n    congr\n\n#print TopologicalSpace.NonemptyCompacts.isCompact /-\nprotected theorem isCompact (s : NonemptyCompacts \u03b1) : IsCompact (s : Set \u03b1) :=\n  s.is_compact'\n#align topological_space.nonempty_compacts.is_compact TopologicalSpace.NonemptyCompacts.isCompact\n-/\n\n#print TopologicalSpace.NonemptyCompacts.nonempty /-\nprotected theorem nonempty (s : NonemptyCompacts \u03b1) : (s : Set \u03b1).Nonempty :=\n  s.nonempty'\n#align topological_space.nonempty_compacts.nonempty TopologicalSpace.NonemptyCompacts.nonempty\n-/\n\n#print TopologicalSpace.NonemptyCompacts.toCloseds /-\n/-- Reinterpret a nonempty compact as a closed set. -/\ndef toCloseds [T2Space \u03b1] (s : NonemptyCompacts \u03b1) : Closeds \u03b1 :=\n  \u27e8s, s.IsCompact.IsClosed\u27e9\n#align topological_space.nonempty_compacts.to_closeds TopologicalSpace.NonemptyCompacts.toCloseds\n-/\n\n#print TopologicalSpace.NonemptyCompacts.ext /-\n@[ext]\nprotected theorem ext {s t : NonemptyCompacts \u03b1} (h : (s : Set \u03b1) = t) : s = t :=\n  SetLike.ext' h\n#align topological_space.nonempty_compacts.ext TopologicalSpace.NonemptyCompacts.ext\n-/\n\n#print TopologicalSpace.NonemptyCompacts.coe_mk /-\n@[simp]\ntheorem coe_mk (s : Compacts \u03b1) (h) : (mk s h : Set \u03b1) = s :=\n  rfl\n#align topological_space.nonempty_compacts.coe_mk TopologicalSpace.NonemptyCompacts.coe_mk\n-/\n\n#print TopologicalSpace.NonemptyCompacts.carrier_eq_coe /-\n@[simp]\ntheorem carrier_eq_coe (s : NonemptyCompacts \u03b1) : s.carrier = s :=\n  rfl\n#align topological_space.nonempty_compacts.carrier_eq_coe TopologicalSpace.NonemptyCompacts.carrier_eq_coe\n-/\n\ninstance : Sup (NonemptyCompacts \u03b1) :=\n  \u27e8fun s t => \u27e8s.toCompacts \u2294 t.toCompacts, s.Nonempty.mono <| subset_union_left _ _\u27e9\u27e9\n\ninstance [CompactSpace \u03b1] [Nonempty \u03b1] : Top (NonemptyCompacts \u03b1) :=\n  \u27e8\u27e8\u22a4, univ_nonempty\u27e9\u27e9\n\ninstance : SemilatticeSup (NonemptyCompacts \u03b1) :=\n  SetLike.coe_injective.SemilatticeSup _ fun _ _ => rfl\n\ninstance [CompactSpace \u03b1] [Nonempty \u03b1] : OrderTop (NonemptyCompacts \u03b1) :=\n  OrderTop.lift (coe : _ \u2192 Set \u03b1) (fun _ _ => id) rfl\n\n/- warning: topological_space.nonempty_compacts.coe_sup -> TopologicalSpace.NonemptyCompacts.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.setLike.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (TopologicalSpace.NonemptyCompacts.hasSup.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.instSetLikeNonemptyCompacts.{u1} \u03b1 _inst_1) (Sup.sup.{u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (TopologicalSpace.NonemptyCompacts.instSupNonemptyCompacts.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.instSetLikeNonemptyCompacts.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.instSetLikeNonemptyCompacts.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup\u2093'. -/\n@[simp]\ntheorem coe_sup (s t : NonemptyCompacts \u03b1) : (\u2191(s \u2294 t) : Set \u03b1) = s \u222a t :=\n  rfl\n#align topological_space.nonempty_compacts.coe_sup TopologicalSpace.NonemptyCompacts.coe_sup\n\n#print TopologicalSpace.NonemptyCompacts.coe_top /-\n@[simp]\ntheorem coe_top [CompactSpace \u03b1] [Nonempty \u03b1] : (\u2191(\u22a4 : NonemptyCompacts \u03b1) : Set \u03b1) = univ :=\n  rfl\n#align topological_space.nonempty_compacts.coe_top TopologicalSpace.NonemptyCompacts.coe_top\n-/\n\n/-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with\ndefault element the singleton set containing the default element. -/\ninstance [Inhabited \u03b1] : Inhabited (NonemptyCompacts \u03b1) :=\n  \u27e8{  carrier := {default}\n      is_compact' := isCompact_singleton\n      nonempty' := singleton_nonempty _ }\u27e9\n\n#print TopologicalSpace.NonemptyCompacts.toCompactSpace /-\ninstance toCompactSpace {s : NonemptyCompacts \u03b1} : CompactSpace s :=\n  isCompact_iff_compactSpace.1 s.IsCompact\n#align topological_space.nonempty_compacts.to_compact_space TopologicalSpace.NonemptyCompacts.toCompactSpace\n-/\n\n#print TopologicalSpace.NonemptyCompacts.toNonempty /-\ninstance toNonempty {s : NonemptyCompacts \u03b1} : Nonempty s :=\n  s.Nonempty.to_subtype\n#align topological_space.nonempty_compacts.to_nonempty TopologicalSpace.NonemptyCompacts.toNonempty\n-/\n\n/- warning: topological_space.nonempty_compacts.prod -> TopologicalSpace.NonemptyCompacts.prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) -> (TopologicalSpace.NonemptyCompacts.{u2} \u03b2 _inst_2) -> (TopologicalSpace.NonemptyCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) -> (TopologicalSpace.NonemptyCompacts.{u2} \u03b2 _inst_2) -> (TopologicalSpace.NonemptyCompacts.{max u2 u1} (Prod.{u1, u2} \u03b1 \u03b2) (instTopologicalSpaceProd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nCase conversion may be inaccurate. Consider using '#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod\u2093'. -/\n/-- The product of two `nonempty_compacts`, as a `nonempty_compacts` in the product space. -/\nprotected def prod (K : NonemptyCompacts \u03b1) (L : NonemptyCompacts \u03b2) : NonemptyCompacts (\u03b1 \u00d7 \u03b2) :=\n  { K.toCompacts.Prod L.toCompacts with nonempty' := K.Nonempty.Prod L.Nonempty }\n#align topological_space.nonempty_compacts.prod TopologicalSpace.NonemptyCompacts.prod\n\n/- warning: topological_space.nonempty_compacts.coe_prod -> TopologicalSpace.NonemptyCompacts.coe_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2] (K : TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (L : TopologicalSpace.NonemptyCompacts.{u2} \u03b2 _inst_2), Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ((fun (a : Type.{max u1 u2}) (b : Type.{max u1 u2}) [self : HasLiftT.{succ (max u1 u2), succ (max u1 u2)} a b] => self.0) (TopologicalSpace.NonemptyCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (HasLiftT.mk.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.NonemptyCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (CoeTC\u2093.coe.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.NonemptyCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (SetLike.Set.hasCoeT.{max u1 u2, max u1 u2} (TopologicalSpace.NonemptyCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u1, u2} \u03b1 \u03b2) (TopologicalSpace.NonemptyCompacts.setLike.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))))) (TopologicalSpace.NonemptyCompacts.prod.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u1, u2} \u03b1 \u03b2 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.setLike.{u1} \u03b1 _inst_1)))) K) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.NonemptyCompacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.NonemptyCompacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.NonemptyCompacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.NonemptyCompacts.{u2} \u03b2 _inst_2) \u03b2 (TopologicalSpace.NonemptyCompacts.setLike.{u2} \u03b2 _inst_2)))) L))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b2] (K : TopologicalSpace.NonemptyCompacts.{u2} \u03b1 _inst_1) (L : TopologicalSpace.NonemptyCompacts.{u1} \u03b2 _inst_2), Eq.{max (succ u2) (succ u1)} (Set.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2)) (SetLike.coe.{max u2 u1, max u2 u1} (TopologicalSpace.NonemptyCompacts.{max u1 u2} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u2, u1} \u03b1 \u03b2) (TopologicalSpace.NonemptyCompacts.instSetLikeNonemptyCompacts.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (TopologicalSpace.NonemptyCompacts.prod.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u2, u1} \u03b1 \u03b2 (SetLike.coe.{u2, u2} (TopologicalSpace.NonemptyCompacts.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.NonemptyCompacts.instSetLikeNonemptyCompacts.{u2} \u03b1 _inst_1) K) (SetLike.coe.{u1, u1} (TopologicalSpace.NonemptyCompacts.{u1} \u03b2 _inst_2) \u03b2 (TopologicalSpace.NonemptyCompacts.instSetLikeNonemptyCompacts.{u1} \u03b2 _inst_2) L))\nCase conversion may be inaccurate. Consider using '#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[simp]\ntheorem coe_prod (K : NonemptyCompacts \u03b1) (L : NonemptyCompacts \u03b2) :\n    (K.Prod L : Set (\u03b1 \u00d7 \u03b2)) = K \u00d7\u02e2 L :=\n  rfl\n#align topological_space.nonempty_compacts.coe_prod TopologicalSpace.NonemptyCompacts.coe_prod\n\nend NonemptyCompacts\n\n/-! ### Positive compact sets -/\n\n\n#print TopologicalSpace.PositiveCompacts /-\n/-- The type of compact sets with nonempty interior of a topological space.\nSee also `compacts` and `nonempty_compacts`. -/\nstructure PositiveCompacts (\u03b1 : Type _) [TopologicalSpace \u03b1] extends Compacts \u03b1 where\n  interior_nonempty' : (interior carrier).Nonempty\n#align topological_space.positive_compacts TopologicalSpace.PositiveCompacts\n-/\n\nnamespace PositiveCompacts\n\ninstance : SetLike (PositiveCompacts \u03b1) \u03b1\n    where\n  coe s := s.carrier\n  coe_injective' s t h := by\n    obtain \u27e8\u27e8_, _\u27e9, _\u27e9 := s\n    obtain \u27e8\u27e8_, _\u27e9, _\u27e9 := t\n    congr\n\n#print TopologicalSpace.PositiveCompacts.isCompact /-\nprotected theorem isCompact (s : PositiveCompacts \u03b1) : IsCompact (s : Set \u03b1) :=\n  s.is_compact'\n#align topological_space.positive_compacts.is_compact TopologicalSpace.PositiveCompacts.isCompact\n-/\n\n#print TopologicalSpace.PositiveCompacts.interior_nonempty /-\ntheorem interior_nonempty (s : PositiveCompacts \u03b1) : (interior (s : Set \u03b1)).Nonempty :=\n  s.interior_nonempty'\n#align topological_space.positive_compacts.interior_nonempty TopologicalSpace.PositiveCompacts.interior_nonempty\n-/\n\n#print TopologicalSpace.PositiveCompacts.nonempty /-\nprotected theorem nonempty (s : PositiveCompacts \u03b1) : (s : Set \u03b1).Nonempty :=\n  s.interior_nonempty.mono interior_subset\n#align topological_space.positive_compacts.nonempty TopologicalSpace.PositiveCompacts.nonempty\n-/\n\n#print TopologicalSpace.PositiveCompacts.toNonemptyCompacts /-\n/-- Reinterpret a positive compact as a nonempty compact. -/\ndef toNonemptyCompacts (s : PositiveCompacts \u03b1) : NonemptyCompacts \u03b1 :=\n  \u27e8s.toCompacts, s.Nonempty\u27e9\n#align topological_space.positive_compacts.to_nonempty_compacts TopologicalSpace.PositiveCompacts.toNonemptyCompacts\n-/\n\n#print TopologicalSpace.PositiveCompacts.ext /-\n@[ext]\nprotected theorem ext {s t : PositiveCompacts \u03b1} (h : (s : Set \u03b1) = t) : s = t :=\n  SetLike.ext' h\n#align topological_space.positive_compacts.ext TopologicalSpace.PositiveCompacts.ext\n-/\n\n#print TopologicalSpace.PositiveCompacts.coe_mk /-\n@[simp]\ntheorem coe_mk (s : Compacts \u03b1) (h) : (mk s h : Set \u03b1) = s :=\n  rfl\n#align topological_space.positive_compacts.coe_mk TopologicalSpace.PositiveCompacts.coe_mk\n-/\n\n#print TopologicalSpace.PositiveCompacts.carrier_eq_coe /-\n@[simp]\ntheorem carrier_eq_coe (s : PositiveCompacts \u03b1) : s.carrier = s :=\n  rfl\n#align topological_space.positive_compacts.carrier_eq_coe TopologicalSpace.PositiveCompacts.carrier_eq_coe\n-/\n\ninstance : Sup (PositiveCompacts \u03b1) :=\n  \u27e8fun s t =>\n    \u27e8s.toCompacts \u2294 t.toCompacts,\n      s.interior_nonempty.mono <| interior_mono <| subset_union_left _ _\u27e9\u27e9\n\ninstance [CompactSpace \u03b1] [Nonempty \u03b1] : Top (PositiveCompacts \u03b1) :=\n  \u27e8\u27e8\u22a4, interior_univ.symm.subst univ_nonempty\u27e9\u27e9\n\ninstance : SemilatticeSup (PositiveCompacts \u03b1) :=\n  SetLike.coe_injective.SemilatticeSup _ fun _ _ => rfl\n\ninstance [CompactSpace \u03b1] [Nonempty \u03b1] : OrderTop (PositiveCompacts \u03b1) :=\n  OrderTop.lift (coe : _ \u2192 Set \u03b1) (fun _ _ => id) rfl\n\n/- warning: topological_space.positive_compacts.coe_sup -> TopologicalSpace.PositiveCompacts.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.setLike.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (TopologicalSpace.PositiveCompacts.hasSup.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (t : TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.instSetLikePositiveCompacts.{u1} \u03b1 _inst_1) (Sup.sup.{u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (TopologicalSpace.PositiveCompacts.instSupPositiveCompacts.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.instSetLikePositiveCompacts.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.instSetLikePositiveCompacts.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup\u2093'. -/\n@[simp]\ntheorem coe_sup (s t : PositiveCompacts \u03b1) : (\u2191(s \u2294 t) : Set \u03b1) = s \u222a t :=\n  rfl\n#align topological_space.positive_compacts.coe_sup TopologicalSpace.PositiveCompacts.coe_sup\n\n#print TopologicalSpace.PositiveCompacts.coe_top /-\n@[simp]\ntheorem coe_top [CompactSpace \u03b1] [Nonempty \u03b1] : (\u2191(\u22a4 : PositiveCompacts \u03b1) : Set \u03b1) = univ :=\n  rfl\n#align topological_space.positive_compacts.coe_top TopologicalSpace.PositiveCompacts.coe_top\n-/\n\n#print exists_positiveCompacts_subset /-\ntheorem exists_positiveCompacts_subset [LocallyCompactSpace \u03b1] {U : Set \u03b1} (ho : IsOpen U)\n    (hn : U.Nonempty) : \u2203 K : PositiveCompacts \u03b1, \u2191K \u2286 U :=\n  let \u27e8x, hx\u27e9 := hn\n  let \u27e8K, hKc, hxK, hKU\u27e9 := exists_compact_subset ho hx\n  \u27e8\u27e8\u27e8K, hKc\u27e9, \u27e8x, hxK\u27e9\u27e9, hKU\u27e9\n#align exists_positive_compacts_subset exists_positiveCompacts_subset\n-/\n\ninstance [CompactSpace \u03b1] [Nonempty \u03b1] : Inhabited (PositiveCompacts \u03b1) :=\n  \u27e8\u22a4\u27e9\n\n#print TopologicalSpace.PositiveCompacts.nonempty' /-\n/-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/\ninstance nonempty' [LocallyCompactSpace \u03b1] [Nonempty \u03b1] : Nonempty (PositiveCompacts \u03b1) :=\n  nonempty_of_exists <| exists_positiveCompacts_subset isOpen_univ univ_nonempty\n#align topological_space.positive_compacts.nonempty' TopologicalSpace.PositiveCompacts.nonempty'\n-/\n\n/- warning: topological_space.positive_compacts.prod -> TopologicalSpace.PositiveCompacts.prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) -> (TopologicalSpace.PositiveCompacts.{u2} \u03b2 _inst_2) -> (TopologicalSpace.PositiveCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) -> (TopologicalSpace.PositiveCompacts.{u2} \u03b2 _inst_2) -> (TopologicalSpace.PositiveCompacts.{max u2 u1} (Prod.{u1, u2} \u03b1 \u03b2) (instTopologicalSpaceProd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nCase conversion may be inaccurate. Consider using '#align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod\u2093'. -/\n/-- The product of two `positive_compacts`, as a `positive_compacts` in the product space. -/\nprotected def prod (K : PositiveCompacts \u03b1) (L : PositiveCompacts \u03b2) : PositiveCompacts (\u03b1 \u00d7 \u03b2) :=\n  { K.toCompacts.Prod L.toCompacts with\n    interior_nonempty' :=\n      by\n      simp only [compacts.carrier_eq_coe, compacts.coe_prod, interior_prod_eq]\n      exact K.interior_nonempty.prod L.interior_nonempty }\n#align topological_space.positive_compacts.prod TopologicalSpace.PositiveCompacts.prod\n\n/- warning: topological_space.positive_compacts.coe_prod -> TopologicalSpace.PositiveCompacts.coe_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2] (K : TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (L : TopologicalSpace.PositiveCompacts.{u2} \u03b2 _inst_2), Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ((fun (a : Type.{max u1 u2}) (b : Type.{max u1 u2}) [self : HasLiftT.{succ (max u1 u2), succ (max u1 u2)} a b] => self.0) (TopologicalSpace.PositiveCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (HasLiftT.mk.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.PositiveCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (CoeTC\u2093.coe.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.PositiveCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (SetLike.Set.hasCoeT.{max u1 u2, max u1 u2} (TopologicalSpace.PositiveCompacts.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u1, u2} \u03b1 \u03b2) (TopologicalSpace.PositiveCompacts.setLike.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))))) (TopologicalSpace.PositiveCompacts.prod.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u1, u2} \u03b1 \u03b2 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.setLike.{u1} \u03b1 _inst_1)))) K) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.PositiveCompacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.PositiveCompacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.PositiveCompacts.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.PositiveCompacts.{u2} \u03b2 _inst_2) \u03b2 (TopologicalSpace.PositiveCompacts.setLike.{u2} \u03b2 _inst_2)))) L))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b2] (K : TopologicalSpace.PositiveCompacts.{u2} \u03b1 _inst_1) (L : TopologicalSpace.PositiveCompacts.{u1} \u03b2 _inst_2), Eq.{max (succ u2) (succ u1)} (Set.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2)) (SetLike.coe.{max u2 u1, max u2 u1} (TopologicalSpace.PositiveCompacts.{max u1 u2} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u2, u1} \u03b1 \u03b2) (TopologicalSpace.PositiveCompacts.instSetLikePositiveCompacts.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (TopologicalSpace.PositiveCompacts.prod.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u2, u1} \u03b1 \u03b2 (SetLike.coe.{u2, u2} (TopologicalSpace.PositiveCompacts.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.PositiveCompacts.instSetLikePositiveCompacts.{u2} \u03b1 _inst_1) K) (SetLike.coe.{u1, u1} (TopologicalSpace.PositiveCompacts.{u1} \u03b2 _inst_2) \u03b2 (TopologicalSpace.PositiveCompacts.instSetLikePositiveCompacts.{u1} \u03b2 _inst_2) L))\nCase conversion may be inaccurate. Consider using '#align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[simp]\ntheorem coe_prod (K : PositiveCompacts \u03b1) (L : PositiveCompacts \u03b2) :\n    (K.Prod L : Set (\u03b1 \u00d7 \u03b2)) = K \u00d7\u02e2 L :=\n  rfl\n#align topological_space.positive_compacts.coe_prod TopologicalSpace.PositiveCompacts.coe_prod\n\nend PositiveCompacts\n\n/-! ### Compact open sets -/\n\n\n#print TopologicalSpace.CompactOpens /-\n/-- The type of compact open sets of a topological space. This is useful in non Hausdorff contexts,\nin particular spectral spaces. -/\nstructure CompactOpens (\u03b1 : Type _) [TopologicalSpace \u03b1] extends Compacts \u03b1 where\n  is_open' : IsOpen carrier\n#align topological_space.compact_opens TopologicalSpace.CompactOpens\n-/\n\nnamespace CompactOpens\n\ninstance : SetLike (CompactOpens \u03b1) \u03b1\n    where\n  coe s := s.carrier\n  coe_injective' s t h := by\n    obtain \u27e8\u27e8_, _\u27e9, _\u27e9 := s\n    obtain \u27e8\u27e8_, _\u27e9, _\u27e9 := t\n    congr\n\n#print TopologicalSpace.CompactOpens.isCompact /-\nprotected theorem isCompact (s : CompactOpens \u03b1) : IsCompact (s : Set \u03b1) :=\n  s.is_compact'\n#align topological_space.compact_opens.is_compact TopologicalSpace.CompactOpens.isCompact\n-/\n\n#print TopologicalSpace.CompactOpens.isOpen /-\nprotected theorem isOpen (s : CompactOpens \u03b1) : IsOpen (s : Set \u03b1) :=\n  s.is_open'\n#align topological_space.compact_opens.is_open TopologicalSpace.CompactOpens.isOpen\n-/\n\n#print TopologicalSpace.CompactOpens.toOpens /-\n/-- Reinterpret a compact open as an open. -/\n@[simps]\ndef toOpens (s : CompactOpens \u03b1) : Opens \u03b1 :=\n  \u27e8s, s.IsOpen\u27e9\n#align topological_space.compact_opens.to_opens TopologicalSpace.CompactOpens.toOpens\n-/\n\n#print TopologicalSpace.CompactOpens.toClopens /-\n/-- Reinterpret a compact open as a clopen. -/\n@[simps]\ndef toClopens [T2Space \u03b1] (s : CompactOpens \u03b1) : Clopens \u03b1 :=\n  \u27e8s, s.IsOpen, s.IsCompact.IsClosed\u27e9\n#align topological_space.compact_opens.to_clopens TopologicalSpace.CompactOpens.toClopens\n-/\n\n#print TopologicalSpace.CompactOpens.ext /-\n@[ext]\nprotected theorem ext {s t : CompactOpens \u03b1} (h : (s : Set \u03b1) = t) : s = t :=\n  SetLike.ext' h\n#align topological_space.compact_opens.ext TopologicalSpace.CompactOpens.ext\n-/\n\n#print TopologicalSpace.CompactOpens.coe_mk /-\n@[simp]\ntheorem coe_mk (s : Compacts \u03b1) (h) : (mk s h : Set \u03b1) = s :=\n  rfl\n#align topological_space.compact_opens.coe_mk TopologicalSpace.CompactOpens.coe_mk\n-/\n\ninstance : Sup (CompactOpens \u03b1) :=\n  \u27e8fun s t => \u27e8s.toCompacts \u2294 t.toCompacts, s.IsOpen.union t.IsOpen\u27e9\u27e9\n\ninstance [QuasiSeparatedSpace \u03b1] : Inf (CompactOpens \u03b1) :=\n  \u27e8fun U V =>\n    \u27e8\u27e8(U : Set \u03b1) \u2229 (V : Set \u03b1),\n        QuasiSeparatedSpace.inter_isCompact U.1.1 V.1.1 U.2 U.1.2 V.2 V.1.2\u27e9,\n      U.2.inter V.2\u27e9\u27e9\n\ninstance [QuasiSeparatedSpace \u03b1] : SemilatticeInf (CompactOpens \u03b1) :=\n  SetLike.coe_injective.SemilatticeInf _ fun _ _ => rfl\n\ninstance [CompactSpace \u03b1] : Top (CompactOpens \u03b1) :=\n  \u27e8\u27e8\u22a4, isOpen_univ\u27e9\u27e9\n\ninstance : Bot (CompactOpens \u03b1) :=\n  \u27e8\u27e8\u22a5, isOpen_empty\u27e9\u27e9\n\ninstance [T2Space \u03b1] : SDiff (CompactOpens \u03b1) :=\n  \u27e8fun s t => \u27e8\u27e8s \\ t, s.IsCompact.diff\u2093 t.IsOpen\u27e9, s.IsOpen.sdiff t.IsCompact.IsClosed\u27e9\u27e9\n\ninstance [T2Space \u03b1] [CompactSpace \u03b1] : HasCompl (CompactOpens \u03b1) :=\n  \u27e8fun s => \u27e8\u27e8s\u1d9c, s.IsOpen.isClosed_compl.IsCompact\u27e9, s.IsCompact.IsClosed.isOpen_compl\u27e9\u27e9\n\ninstance : SemilatticeSup (CompactOpens \u03b1) :=\n  SetLike.coe_injective.SemilatticeSup _ fun _ _ => rfl\n\ninstance : OrderBot (CompactOpens \u03b1) :=\n  OrderBot.lift (coe : _ \u2192 Set \u03b1) (fun _ _ => id) rfl\n\ninstance [T2Space \u03b1] : GeneralizedBooleanAlgebra (CompactOpens \u03b1) :=\n  SetLike.coe_injective.GeneralizedBooleanAlgebra _ (fun _ _ => rfl) (fun _ _ => rfl) rfl fun _ _ =>\n    rfl\n\ninstance [CompactSpace \u03b1] : BoundedOrder (CompactOpens \u03b1) :=\n  BoundedOrder.lift (coe : _ \u2192 Set \u03b1) (fun _ _ => id) rfl rfl\n\ninstance [T2Space \u03b1] [CompactSpace \u03b1] : BooleanAlgebra (CompactOpens \u03b1) :=\n  SetLike.coe_injective.BooleanAlgebra _ (fun _ _ => rfl) (fun _ _ => rfl) rfl rfl (fun _ => rfl)\n    fun _ _ => rfl\n\n/- warning: topological_space.compact_opens.coe_sup -> TopologicalSpace.CompactOpens.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.hasSup.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) (Sup.sup.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.instSupCompactOpens.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.compact_opens.coe_sup TopologicalSpace.CompactOpens.coe_sup\u2093'. -/\n@[simp]\ntheorem coe_sup (s t : CompactOpens \u03b1) : (\u2191(s \u2294 t) : Set \u03b1) = s \u222a t :=\n  rfl\n#align topological_space.compact_opens.coe_sup TopologicalSpace.CompactOpens.coe_sup\n\n/- warning: topological_space.compact_opens.coe_inf -> TopologicalSpace.CompactOpens.coe_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) (Inf.inf.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.hasInf.{u1} \u03b1 _inst_1 (T2Space.to_quasiSeparatedSpace.{u1} \u03b1 _inst_1 _inst_3)) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) (Inf.inf.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.instInfCompactOpens.{u1} \u03b1 _inst_1 (T2Space.to_quasiSeparatedSpace.{u1} \u03b1 _inst_1 _inst_3)) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.compact_opens.coe_inf TopologicalSpace.CompactOpens.coe_inf\u2093'. -/\n@[simp]\ntheorem coe_inf [T2Space \u03b1] (s t : CompactOpens \u03b1) : (\u2191(s \u2293 t) : Set \u03b1) = s \u2229 t :=\n  rfl\n#align topological_space.compact_opens.coe_inf TopologicalSpace.CompactOpens.coe_inf\n\n#print TopologicalSpace.CompactOpens.coe_top /-\n@[simp]\ntheorem coe_top [CompactSpace \u03b1] : (\u2191(\u22a4 : CompactOpens \u03b1) : Set \u03b1) = univ :=\n  rfl\n#align topological_space.compact_opens.coe_top TopologicalSpace.CompactOpens.coe_top\n-/\n\n#print TopologicalSpace.CompactOpens.coe_bot /-\n@[simp]\ntheorem coe_bot : (\u2191(\u22a5 : CompactOpens \u03b1) : Set \u03b1) = \u2205 :=\n  rfl\n#align topological_space.compact_opens.coe_bot TopologicalSpace.CompactOpens.coe_bot\n-/\n\n/- warning: topological_space.compact_opens.coe_sdiff -> TopologicalSpace.CompactOpens.coe_sdiff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) (SDiff.sdiff.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.hasSdiff.{u1} \u03b1 _inst_1 _inst_3) s t)) (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) (SDiff.sdiff.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.instSDiffCompactOpens.{u1} \u03b1 _inst_1 _inst_3) s t)) (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (Set.instSDiffSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.compact_opens.coe_sdiff TopologicalSpace.CompactOpens.coe_sdiff\u2093'. -/\n@[simp]\ntheorem coe_sdiff [T2Space \u03b1] (s t : CompactOpens \u03b1) : (\u2191(s \\ t) : Set \u03b1) = s \\ t :=\n  rfl\n#align topological_space.compact_opens.coe_sdiff TopologicalSpace.CompactOpens.coe_sdiff\n\n/- warning: topological_space.compact_opens.coe_compl -> TopologicalSpace.CompactOpens.coe_compl is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] [_inst_4 : CompactSpace.{u1} \u03b1 _inst_1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) (HasCompl.compl.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.hasCompl.{u1} \u03b1 _inst_1 _inst_3 _inst_4) s)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T2Space.{u1} \u03b1 _inst_1] [_inst_4 : CompactSpace.{u1} \u03b1 _inst_1] (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) (HasCompl.compl.{u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (TopologicalSpace.CompactOpens.instHasComplCompactOpens.{u1} \u03b1 _inst_1 _inst_3 _inst_4) s)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.instBooleanAlgebraSet.{u1} \u03b1)) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b1 _inst_1) s))\nCase conversion may be inaccurate. Consider using '#align topological_space.compact_opens.coe_compl TopologicalSpace.CompactOpens.coe_compl\u2093'. -/\n@[simp]\ntheorem coe_compl [T2Space \u03b1] [CompactSpace \u03b1] (s : CompactOpens \u03b1) : (\u2191(s\u1d9c) : Set \u03b1) = s\u1d9c :=\n  rfl\n#align topological_space.compact_opens.coe_compl TopologicalSpace.CompactOpens.coe_compl\n\ninstance : Inhabited (CompactOpens \u03b1) :=\n  \u27e8\u22a5\u27e9\n\n#print TopologicalSpace.CompactOpens.map /-\n/-- The image of a compact open under a continuous open map. -/\n@[simps]\ndef map (f : \u03b1 \u2192 \u03b2) (hf : Continuous f) (hf' : IsOpenMap f) (s : CompactOpens \u03b1) : CompactOpens \u03b2 :=\n  \u27e8s.toCompacts.map f hf, hf' _ s.IsOpen\u27e9\n#align topological_space.compact_opens.map TopologicalSpace.CompactOpens.map\n-/\n\n/- warning: topological_space.compact_opens.coe_map -> TopologicalSpace.CompactOpens.coe_map is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2} (hf : Continuous.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) (hf' : IsOpenMap.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) (s : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1), Eq.{succ u2} (Set.{u2} \u03b2) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) \u03b2 (TopologicalSpace.CompactOpens.setLike.{u2} \u03b2 _inst_2)))) (TopologicalSpace.CompactOpens.map.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f hf hf' s)) (Set.image.{u1, u2} \u03b1 \u03b2 f ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b2] {f : \u03b1 -> \u03b2} (hf : Continuous.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f) (hf' : IsOpenMap.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f) (s : TopologicalSpace.CompactOpens.{u2} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b2) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b2 _inst_2) \u03b2 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b2 _inst_2) (TopologicalSpace.CompactOpens.map.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f hf hf' s)) (Set.image.{u2, u1} \u03b1 \u03b2 f (SetLike.coe.{u2, u2} (TopologicalSpace.CompactOpens.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u2} \u03b1 _inst_1) s))\nCase conversion may be inaccurate. Consider using '#align topological_space.compact_opens.coe_map TopologicalSpace.CompactOpens.coe_map\u2093'. -/\n@[simp]\ntheorem coe_map {f : \u03b1 \u2192 \u03b2} (hf : Continuous f) (hf' : IsOpenMap f) (s : CompactOpens \u03b1) :\n    (s.map f hf hf' : Set \u03b2) = f '' s :=\n  rfl\n#align topological_space.compact_opens.coe_map TopologicalSpace.CompactOpens.coe_map\n\n/- warning: topological_space.compact_opens.prod -> TopologicalSpace.CompactOpens.prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) -> (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) -> (TopologicalSpace.CompactOpens.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2], (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) -> (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) -> (TopologicalSpace.CompactOpens.{max u2 u1} (Prod.{u1, u2} \u03b1 \u03b2) (instTopologicalSpaceProd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))\nCase conversion may be inaccurate. Consider using '#align topological_space.compact_opens.prod TopologicalSpace.CompactOpens.prod\u2093'. -/\n/-- The product of two `compact_opens`, as a `compact_opens` in the product space. -/\nprotected def prod (K : CompactOpens \u03b1) (L : CompactOpens \u03b2) : CompactOpens (\u03b1 \u00d7 \u03b2) :=\n  { K.toCompacts.Prod L.toCompacts with is_open' := K.IsOpen.Prod L.IsOpen }\n#align topological_space.compact_opens.prod TopologicalSpace.CompactOpens.prod\n\n/- warning: topological_space.compact_opens.coe_prod -> TopologicalSpace.CompactOpens.coe_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b2] (K : TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (L : TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2), Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) ((fun (a : Type.{max u1 u2}) (b : Type.{max u1 u2}) [self : HasLiftT.{succ (max u1 u2), succ (max u1 u2)} a b] => self.0) (TopologicalSpace.CompactOpens.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (HasLiftT.mk.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.CompactOpens.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (CoeTC\u2093.coe.{succ (max u1 u2), succ (max u1 u2)} (TopologicalSpace.CompactOpens.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (SetLike.Set.hasCoeT.{max u1 u2, max u1 u2} (TopologicalSpace.CompactOpens.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u1, u2} \u03b1 \u03b2) (TopologicalSpace.CompactOpens.setLike.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.topologicalSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))))) (TopologicalSpace.CompactOpens.prod.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u1, u2} \u03b1 \u03b2 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.setLike.{u1} \u03b1 _inst_1)))) K) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) (Set.{u2} \u03b2) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.CompactOpens.{u2} \u03b2 _inst_2) \u03b2 (TopologicalSpace.CompactOpens.setLike.{u2} \u03b2 _inst_2)))) L))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b2] (K : TopologicalSpace.CompactOpens.{u2} \u03b1 _inst_1) (L : TopologicalSpace.CompactOpens.{u1} \u03b2 _inst_2), Eq.{max (succ u2) (succ u1)} (Set.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2)) (SetLike.coe.{max u2 u1, max u2 u1} (TopologicalSpace.CompactOpens.{max u1 u2} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (Prod.{u2, u1} \u03b1 \u03b2) (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{max u2 u1} (Prod.{u2, u1} \u03b1 \u03b2) (instTopologicalSpaceProd.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2)) (TopologicalSpace.CompactOpens.prod.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K L)) (Set.prod.{u2, u1} \u03b1 \u03b2 (SetLike.coe.{u2, u2} (TopologicalSpace.CompactOpens.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u2} \u03b1 _inst_1) K) (SetLike.coe.{u1, u1} (TopologicalSpace.CompactOpens.{u1} \u03b2 _inst_2) \u03b2 (TopologicalSpace.CompactOpens.instSetLikeCompactOpens.{u1} \u03b2 _inst_2) L))\nCase conversion may be inaccurate. Consider using '#align topological_space.compact_opens.coe_prod TopologicalSpace.CompactOpens.coe_prod\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[simp]\ntheorem coe_prod (K : CompactOpens \u03b1) (L : CompactOpens \u03b2) : (K.Prod L : Set (\u03b1 \u00d7 \u03b2)) = K \u00d7\u02e2 L :=\n  rfl\n#align topological_space.compact_opens.coe_prod TopologicalSpace.CompactOpens.coe_prod\n\nend CompactOpens\n\nend TopologicalSpace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/Sets/Compacts.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7347473661007149}}
{"text": "import algebra.group.basic\nimport group_theory.order_of_element\nimport data.fintype.basic\nimport deprecated.group \n\nnoncomputable theory \n\ntheorem df_1_1_16 (G : Type*) [group G] (x : G) :\n  x ^ 2 = 1 \u2194 order_of x = 1 \u2228 order_of x = 2\n:= \nbegin\n  sorry, \nend\n\ntheorem df_1_18\n  (G : Type*) [group G]\n  (x y : G)\n  : x * y = y * x \u2194 y\u207b\u00b9 * x * y = x\n:= \nbegin\n  sorry, \nend\n\ntheorem df_1_1_20 (G: Type*) [group G] (x: G) : \n  order_of x = order_of x\u207b\u00b9 := \nbegin \n  simp, \nend \n\ntheorem df_1_1_22a (G: Type*) [group G] (x g: G) : \norder_of x = order_of (g\u207b\u00b9 * x\u207b\u00b9 *g) := \nbegin \n  sorry, \nend \n\ntheorem df_1_1_22b (G: Type*) [group G] (a b: G) : \norder_of (a*b) = order_of (b*a) :=\nbegin\n  sorry, \nend\n\n\ntheorem df_1_1_25 (G: Type*) [group G]  (h : \u2200 x:G, x * x = 1) : \n  \u2200 a b : G, a*b = b*a := \nbegin \n   intros a b, \n   have ha : _ := h a, \n   have hb : _ := h b, \n   have hab : _ := h (a*b), \n   rw mul_eq_one_iff_eq_inv at ha, \n   rw mul_eq_one_iff_eq_inv at hb, \n   rw mul_eq_one_iff_eq_inv at hab, \n   rw [hab, mul_inv_rev, \u2190ha, \u2190hb],  \nend\n\ndef is_comm (G : Type*) [group G] : Prop := \u2200 (a b : G), a * b = b * a\n\ntheorem df_1_1_29 (G H : Type*) [group G] [group H] : \n  (is_comm (G \u00d7 H)) \u2194 (is_comm G \u2227 is_comm H) :=\nbegin \n  sorry, \nend \n\ntheorem df_1_1_34 (G: Type*) [group G] (x : G) (h : order_of x = 0) : \n  \u2200 n m : \u2115, n \u2260 m \u2192 x ^ n \u2260 x ^ m := \nbegin\n  sorry, \nend\n\ntheorem df_1_6_11 (A : Type*) [group A] (B : Type*) [group B] : \n  (A \u00d7 B) \u2243* (B \u00d7 A) := \nbegin \n  sorry\nend\n\ntheorem df_1_6_1 (G : Type*) [group G] (f : G \u2192 G) (hf : f = \u03bb x : G, x\u207b\u00b9) : \n  is_group_hom f \u2194 is_comm G := \nbegin \n  sorry, \nend\n\ntheorem df_1_6_18 (G : Type*) [group G] (f : G \u2192 G) (hf : f = \u03bb x : G, x ^ 2) :\nis_group_hom f \u2194 is_comm G :=\nbegin \n  sorry, \nend\n\n\n\n\n\n\n\n", "meta": {"author": "wudcscheme", "repo": "lean-challenges", "sha": "dfaf3f6f71148b60db75479e7b09c68012f354c1", "save_path": "github-repos/lean/wudcscheme-lean-challenges", "path": "github-repos/lean/wudcscheme-lean-challenges/lean-challenges-dfaf3f6f71148b60db75479e7b09c68012f354c1/src/group_theory/df_chapter1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520764, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7347090469372389}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n-/\nimport data.nat.order.basic\n\n/-!\n# `nat.upto`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n`nat.upto p`, with `p` a predicate on `\u2115`, is a subtype of elements `n : \u2115` such that no value\n(strictly) below `n` satisfies `p`.\n\nThis type has the property that `>` is well-founded when `\u2203 i, p i`, which allows us to implement\nsearches on `\u2115`, starting at `0` and with an unknown upper-bound.\n\nIt is similar to the well founded relation constructed to define `nat.find` with\nthe difference that, in `nat.upto p`, `p` does not need to be decidable. In fact,\n`nat.find` could be slightly altered to factor decidability out of its\nwell founded relation and would then fulfill the same purpose as this file.\n-/\n\nnamespace nat\n\n/-- The subtype of natural numbers `i` which have the property that\nno `j` less than `i` satisfies `p`. This is an initial segment of the\nnatural numbers, up to and including the first value satisfying `p`.\n\nWe will be particularly interested in the case where there exists a value\nsatisfying `p`, because in this case the `>` relation is well-founded.  -/\n@[reducible]\ndef upto (p : \u2115 \u2192 Prop) : Type := {i : \u2115 // \u2200 j < i, \u00ac p j}\n\nnamespace upto\n\nvariable {p : \u2115 \u2192 Prop}\n\n/-- Lift the \"greater than\" relation on natural numbers to `nat.upto`. -/\nprotected def gt (p) (x y : upto p) : Prop := x.1 > y.1\n\ninstance : has_lt (upto p) := \u27e8\u03bb x y, x.1 < y.1\u27e9\n\n/-- The \"greater than\" relation on `upto p` is well founded if (and only if) there exists a value\nsatisfying `p`. -/\nprotected lemma wf : (\u2203 x, p x) \u2192 well_founded (upto.gt p)\n| \u27e8x, h\u27e9 := begin\n  suffices : upto.gt p = measure (\u03bb y : nat.upto p, x - y.val),\n  { rw this, apply measure_wf },\n  ext \u27e8a, ha\u27e9 \u27e8b, _\u27e9,\n  dsimp [measure, inv_image, upto.gt],\n  rw tsub_lt_tsub_iff_left_of_le,\n  exact le_of_not_lt (\u03bb h', ha _ h' h),\nend\n\n/-- Zero is always a member of `nat.upto p` because it has no predecessors. -/\ndef zero : nat.upto p := \u27e80, \u03bb j h, false.elim (nat.not_lt_zero _ h)\u27e9\n\n/-- The successor of `n` is in `nat.upto p` provided that `n` doesn't satisfy `p`. -/\ndef succ (x : nat.upto p) (h : \u00ac p x.val) : nat.upto p :=\n\u27e8x.val.succ, \u03bb j h', begin\n  rcases nat.lt_succ_iff_lt_or_eq.1 h' with h' | rfl;\n  [exact x.2 _ h', exact h]\nend\u27e9\n\nend upto\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/upto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7346927841495556}}
{"text": "/-\nExamples of matroids.\n-/\nimport matroid data.equiv.list\n\nopen finset\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] {E : finset \u03b1}\nnamespace matroid\n\n/-- the loopy matroid on `E : finset \u03b1` is the matroid where every\nelement of `E` is a loop; equivalently, every subset of `E` is\ndependent -/\ndef loopy (E : finset \u03b1) : indep E :=\n\u27e8{\u2205},\npowerset_mono.mpr $ empty_subset _,\nmem_singleton_self _,\n\u03bb x y h1 h2, mem_singleton.mpr $ subset_empty.mp $ (mem_singleton.mp h1) \u25b8 h2,\n\u03bb x y hx hy hcard, false.elim $ (nat.not_lt_zero $ card x) $\n  card_empty.subst $ (mem_singleton.mp hy).subst hcard\u27e9\n\n/-- the free matroid is the matroid where every subset\nof the ground set is independent; sometimes called the trivial matroid -/\ndef free (E : finset \u03b1) : indep E :=\n\u27e8powerset E,\nsubset.refl _,\nempty_mem_powerset _,\n\u03bb x y h1 h2, mem_powerset.mpr $ subset.trans h2 $ mem_powerset.mp h1,\n\u03bb x y hx hy hcard, exists.elim (exists_sdiff_of_card_lt hcard) $\n  \u03bb e exy, \u27e8e, exy, mem_powerset.mpr $ insert_subset.mpr\n    \u27e8mem_of_subset (mem_powerset.mp hy) (mem_sdiff.mp exy).1, mem_powerset.mp hx\u27e9\u27e9\u27e9\n\n/-- the uniform matroid U_k on `E : finset \u03b1` is the matroid whose\nindependent sets are all subsets of `E` of size `k` or less; Example 1.2.7 in Oxley -/\ndef uniform (k : \u2115) (E : finset \u03b1) : indep E :=\n\u27e8(powerset E).filter (\u03bb x, card x \u2264 k),\nfilter_subset (powerset E),\nmem_filter.mpr \u27e8empty_mem_powerset E, (@card_empty $ finset \u03b1).symm \u25b8 nat.zero_le k\u27e9,\nby { simp only [mem_powerset, and_imp, mem_filter],\n  exact \u03bb x y hx hcardx hy, \u27e8subset.trans hy hx, le_trans (card_le_of_subset hy) hcardx\u27e9 },\nby { simp only [mem_powerset, and_imp, mem_filter, mem_sdiff],\n  exact \u03bb x y hx hcardx hy hcardy hcard, exists.elim (exists_sdiff_of_card_lt hcard) $\n  \u03bb e exy, \u27e8e, \u27e8mem_sdiff.mp exy, \u27e8insert_subset.mpr \u27e8mem_of_subset hy (mem_sdiff.mp exy).1, hx\u27e9,\n    (card_insert_of_not_mem (mem_sdiff.mp exy).2).symm \u25b8\n      nat.succ_le_of_lt $ nat.lt_of_lt_of_le hcard hcardy\u27e9\u27e9\u27e9 }\u27e9\n\ntheorem loopy_eq_uniform_zero (E : finset \u03b1) : loopy E = uniform 0 E :=\nsuffices (loopy E).indep = (uniform 0 E).indep, from eq_of_indep_eq this,\nby { simp only [loopy, uniform, ext, mem_powerset, mem_filter, card_eq_zero, le_zero_iff_eq,\n    iff_false, insert_empty_eq_singleton, mem_singleton, not_mem_empty],\n  intro a, rw \u2190eq_empty_iff_forall_not_mem,\n  exact \u27e8\u03bb ha, \u27e8ha.symm \u25b8 empty_subset E, ha\u27e9, \u03bb ha, ha.2\u27e9 }\n\ntheorem free_eq_uniform_card (E : finset \u03b1) : free E = uniform (card E) E :=\nsuffices (free E).indep = (uniform (card E) E).indep, from eq_of_indep_eq this,\n  by { simp only [free, uniform, ext, mem_powerset, mem_filter, empty_mem_powerset],\n    exact \u03bb a, \u27e8\u03bb ha, \u27e8ha, card_le_of_subset ha\u27e9, \u03bb ha, ha.1\u27e9 }\n\n#eval uniform 2 $ range 4\n\n#eval (is_basis {1,3} $ uniform 2 $ range 4 : bool)\n#eval (is_basis {1,0,3} $ uniform 2 $ range 4 : bool)\n\n#eval bases_of_indep $ loopy $ range 5\n#eval bases_of_indep $ uniform 3 $ range 5\n#eval bases_of_indep $ free $ range 5\n\n#eval (is_circuit {1,2} $ uniform 2 $ range 4 : bool)\n#eval (is_circuit {1,2,4} $ uniform 2 $ range 4 : bool)\n#eval (is_circuit {1,2,3,4} $ uniform 2 $ range 4 : bool)\n\n#eval circuits_of_indep $ loopy $ range 5\n#eval circuits_of_indep $ uniform 3 $ range 5\n#eval circuits_of_indep $ free $ range 5\n\n#eval uniform 3 $ range 5\n#eval indep_of_bases $ bases_of_indep $ uniform 3 $ range 5\n#eval indep_of_circuits $ circuits_of_indep $ uniform 3 $ range 5\n\n/- /- slow -/\n#eval circuit_of_dep_of_insert_indep (dec_trivial : {0,2,3} \u2208 (uniform 3 $ range 5).indep)\n    (dec_trivial : 1 \u2208 range 5) (dec_trivial : _ /-insert 3 {1,2} \u2209 (uniform 2 $ range 4).indep -/)\n#eval fund_circ_of_basis (dec_trivial : is_basis {0,1,2} (uniform 3 $ range 5))\n    (dec_trivial : 4 \u2208 range 5 \\ {0,1,2}) -/\n#eval fund_circ_of_basis (dec_trivial : is_basis \u2205 (loopy $ range 5))\n    (dec_trivial : 4 \u2208 range 5 \\ \u2205)\n\n#eval basis_containing_indep (dec_trivial : {0,2} \u2208 (uniform 3 $ range 5).indep)\n\n#eval basis_of_subset (dec_trivial : {0,4,1,2,3} \u2286 range 5) (uniform 3 $ range 5)\n\n#eval rank_of_subset (dec_trivial : {0,4,1} \u2286 range 5) (uniform 3 $ range 5)\n#eval rank_of_subset (dec_trivial : {0,4,2,1} \u2286 range 5) (uniform 3 $ range 5)\n#eval rank_of_subset (dec_trivial : {0,4} \u2286 range 5) (loopy $ range 5)\n#eval rank_of_subset (dec_trivial : {0,4} \u2286 range 5) (free $ range 5)\n\nend matroid\n", "meta": {"author": "bryangingechen", "repo": "lean-matroids", "sha": "37c2964208f5a0532ef0a3e525ace06d4d7bc156", "save_path": "github-repos/lean/bryangingechen-lean-matroids", "path": "github-repos/lean/bryangingechen-lean-matroids/lean-matroids-37c2964208f5a0532ef0a3e525ace06d4d7bc156/src/matroidexamples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7346927767738665}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\n\nimport algebra.order.absolute_value\nimport algebra.big_operators.basic\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `\u220f` and `\u2211` operations.\n\n-/\n\nopen_locale big_operators\n\nvariables {\u03b9 \u03b1 \u03b2 M N G k R : Type*}\n\nnamespace finset\n\nsection ordered_comm_monoid\n\nvariables [comm_monoid M] [ordered_comm_monoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M \u2192 N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y`. Let `g i`, `i \u2208 s`, be\na nonempty finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u220f x in s, g x) \u2264 \u220f x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\nlemma le_prod_nonempty_of_submultiplicative_on_pred\n  (f : M \u2192 N) (p : M \u2192 Prop) (h_mul : \u2200 x y, p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y)\n  (hp_mul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (g : \u03b9 \u2192 M) (s : finset \u03b9) (hs_nonempty : s.nonempty)\n  (hs : \u2200 i \u2208 s, p (g i)) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  refine le_trans (multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _,\n  { simp [hs_nonempty.ne_empty], },\n  { exact multiset.forall_mem_map_iff.mpr hs, },\n  rw multiset.map_map,\n  refl,\nend\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M \u2192 N` be a map subadditive on `{x | p x}`, i.e., `p x \u2192 p y \u2192 f (x + y) \u2264 f x + f y`. Let\n`g i`, `i \u2208 s`, be a nonempty finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M \u2192 N` is a submultiplicative function, `f (x * y) \u2264 f x * f y` and `g i`, `i \u2208 s`, is a\nnonempty finite family of elements of `M`, then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\nlemma le_prod_nonempty_of_submultiplicative\n  (f : M \u2192 N) (h_mul : \u2200 x y, f (x * y) \u2264 f x * f y) {s : finset \u03b9} (hs : s.nonempty) (g : \u03b9 \u2192 M) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nle_prod_nonempty_of_submultiplicative_on_pred f (\u03bb i, true) (\u03bb x y _ _, h_mul x y)\n  (\u03bb _ _ _ _, trivial) g s hs (\u03bb _ _, trivial)\n\n/-- If `f : M \u2192 N` is a subadditive function, `f (x + y) \u2264 f x + f y` and `g i`, `i \u2208 s`, is a\nnonempty finite family of elements of `M`, then `f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M \u2192 N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y`. Let `g i`, `i \u2208 s`, be a finite family of elements of `M` such\nthat `\u2200 i \u2208 s, p (g i)`. Then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\nlemma le_prod_of_submultiplicative_on_pred (f : M \u2192 N) (p : M \u2192 Prop) (h_one : f 1 = 1)\n  (h_mul : \u2200 x y, p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y)\n  (hp_mul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (g : \u03b9 \u2192 M) {s : finset \u03b9} (hs : \u2200 i \u2208 s, p (g i)) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  rcases eq_empty_or_nonempty s with rfl|hs_nonempty,\n  { simp [h_one] },\n  { exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs, },\nend\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M \u2192 N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x \u2192 p y \u2192 f (x + y) \u2264 f x + f y`.\nLet `g i`, `i \u2208 s`, be a finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u2211 x in s, g x) \u2264 \u2211 x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M \u2192 N` is a submultiplicative function, `f (x * y) \u2264 f x * f y`, `f 1 = 1`, and `g i`,\n`i \u2208 s`, is a finite family of elements of `M`, then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\nlemma le_prod_of_submultiplicative (f : M \u2192 N) (h_one : f 1 = 1)\n  (h_mul : \u2200 x y, f (x * y) \u2264 f x * f y) (s : finset \u03b9) (g : \u03b9 \u2192 M) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  refine le_trans (multiset.le_prod_of_submultiplicative f h_one h_mul _) _,\n  rw multiset.map_map,\n  refl,\nend\n\n/-- If `f : M \u2192 N` is a subadditive function, `f (x + y) \u2264 f x + f y`, `f 0 = 0`, and `g i`,\n`i \u2208 s`, is a finite family of elements of `M`, then `f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariables {f g : \u03b9 \u2192 N} {s t : finset \u03b9}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`\u220f i in s, f i \u2264 \u220f i in s, g i`. -/\n@[to_additive sum_le_sum]\nlemma prod_le_prod'' (h : \u2200 i \u2208 s, f i \u2264 g i) : \u220f i in s, f i \u2264 \u220f i in s, g i :=\nbegin\n  classical,\n  induction s using finset.induction_on with i s hi ihs h,\n  { refl },\n  { simp only [prod_insert hi],\n    exact mul_le_mul' (h _ (mem_insert_self _ _)) (ihs $ \u03bb j hj, h j (mem_insert_of_mem hj)) }\nend\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`\u2211 i in s, f i \u2264 \u2211 i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n@[to_additive sum_nonneg]  lemma one_le_prod' (h : \u2200i \u2208 s, 1 \u2264 f i) : 1 \u2264 (\u220f i in s, f i) :=\nle_trans (by rw prod_const_one) (prod_le_prod'' h)\n\n@[to_additive sum_nonpos] lemma prod_le_one' (h : \u2200i \u2208 s, f i \u2264 1) : (\u220f i in s, f i) \u2264 1 :=\n(prod_le_prod'' h).trans_eq (by rw prod_const_one)\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\nlemma prod_le_prod_of_subset_of_one_le' (h : s \u2286 t) (hf : \u2200 i \u2208 t, i \u2209 s \u2192 1 \u2264 f i) :\n  \u220f i in s, f i \u2264 \u220f i in t, f i :=\nby classical;\ncalc (\u220f i in s, f i) \u2264 (\u220f i in t \\ s, f i) * (\u220f i in s, f i) :\n    le_mul_of_one_le_left' $ one_le_prod' $ by simpa only [mem_sdiff, and_imp]\n  ... = \u220f i in t \\ s \u222a s, f i : (prod_union sdiff_disjoint).symm\n  ... = \u220f i in t, f i         : by rw [sdiff_union_of_subset h]\n\n@[to_additive sum_mono_set_of_nonneg]\nlemma prod_mono_set_of_one_le' (hf : \u2200 x, 1 \u2264 f x) : monotone (\u03bb s, \u220f x in s, f x) :=\n\u03bb s t hst, prod_le_prod_of_subset_of_one_le' hst $ \u03bb x _ _, hf x\n\n@[to_additive sum_le_univ_sum_of_nonneg]\nlemma prod_le_univ_prod_of_one_le' [fintype \u03b9] {s : finset \u03b9} (w : \u2200 x, 1 \u2264 f x) :\n  \u220f x in s, f x \u2264 \u220f x, f x :=\nprod_le_prod_of_subset_of_one_le' (subset_univ s) (\u03bb a _ _, w a)\n\n@[to_additive sum_eq_zero_iff_of_nonneg]\nlemma prod_eq_one_iff_of_one_le' : (\u2200 i \u2208 s, 1 \u2264 f i) \u2192 (\u220f i in s, f i = 1 \u2194 \u2200 i \u2208 s, f i = 1) :=\nbegin\n  classical,\n  apply finset.induction_on s,\n  exact \u03bb _, \u27e8\u03bb _ _, false.elim, \u03bb _, rfl\u27e9,\n  assume a s ha ih H,\n  have : \u2200 i \u2208 s, 1 \u2264 f i, from \u03bb _, H _ \u2218 mem_insert_of_mem,\n  rw [prod_insert ha, mul_eq_one_iff' (H _ $ mem_insert_self _ _) (one_le_prod' this),\n    forall_mem_insert, ih this]\nend\n\n@[to_additive sum_eq_zero_iff_of_nonneg]\nlemma prod_eq_one_iff_of_le_one' : (\u2200 i \u2208 s, f i \u2264 1) \u2192 (\u220f i in s, f i = 1 \u2194 \u2200 i \u2208 s, f i = 1) :=\n@prod_eq_one_iff_of_one_le' _ (order_dual N) _ _ _\n\n@[to_additive single_le_sum]\nlemma single_le_prod' (hf : \u2200 i \u2208 s, 1 \u2264 f i) {a} (h : a \u2208 s) : f a \u2264 (\u220f x in s, f x) :=\ncalc f a = \u220f i in {a}, f i : prod_singleton.symm\n     ... \u2264 \u220f i in s, f i   :\n  prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) $ \u03bb i hi _, hf i hi\n\n@[to_additive]\nlemma prod_le_of_forall_le (s : finset \u03b9) (f : \u03b9 \u2192 N) (n : N) (h : \u2200 x \u2208 s, f x \u2264 n) :\n  s.prod f \u2264 n ^ s.card :=\nbegin\n  refine (multiset.prod_le_of_forall_le (s.val.map f) n _).trans _,\n  { simpa using h },\n  { simpa }\nend\n\n@[to_additive]\nlemma le_prod_of_forall_le (s : finset \u03b9) (f : \u03b9 \u2192 N) (n : N) (h : \u2200 x \u2208 s, n \u2264 f x) :\n  n ^ s.card \u2264 s.prod f :=\n@finset.prod_le_of_forall_le _ (order_dual N) _ _ _ _ h\n\nlemma card_bUnion_le_card_mul [decidable_eq \u03b2] (s : finset \u03b9) (f : \u03b9 \u2192 finset \u03b2) (n : \u2115)\n  (h : \u2200 a \u2208 s, (f a).card \u2264 n) :\n  (s.bUnion f).card \u2264 s.card * n :=\ncard_bUnion_le.trans $ sum_le_of_forall_le _ _ _ h\n\nvariables {\u03b9' : Type*} [decidable_eq \u03b9']\n\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\nlemma prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : finset \u03b9'}\n  {g : \u03b9 \u2192 \u03b9'} {f : \u03b9 \u2192 N} (h : \u2200 y \u2209 t, (1 : N) \u2264 \u220f x in s.filter (\u03bb x, g x = y), f x) :\n  \u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x \u2264 \u220f x in s, f x :=\ncalc (\u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x) \u2264\n  (\u220f y in t \u222a s.image g, \u220f x in s.filter (\u03bb x, g x = y), f x) :\n  prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) $ \u03bb y hyts, h y\n... = \u220f x in s, f x :\n  prod_fiberwise_of_maps_to (\u03bb x hx, mem_union.2 $ or.inr $ mem_image_of_mem _ hx) _\n\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\nlemma prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : finset \u03b9'}\n  {g : \u03b9 \u2192 \u03b9'} {f : \u03b9 \u2192 N} (h : \u2200 y \u2209 t, (\u220f x in s.filter (\u03bb x, g x = y), f x) \u2264 1) :\n  (\u220f x in s, f x) \u2264 \u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x :=\n@prod_fiberwise_le_prod_of_one_le_prod_fiber' _ (order_dual N) _ _ _ _ _ _ _ h\n\nend ordered_comm_monoid\n\nlemma abs_sum_le_sum_abs {G : Type*} [linear_ordered_add_comm_group G] (f : \u03b9 \u2192 G) (s : finset \u03b9) :\n  |\u2211 i in s, f i| \u2264 \u2211 i in s, |f i| :=\nle_sum_of_subadditive _ abs_zero abs_add s f\n\nlemma abs_prod {R : Type*} [linear_ordered_comm_ring R] {f : \u03b9 \u2192 R} {s : finset \u03b9} :\n  |\u220f x in s, f x| = \u220f x in s, |f x| :=\n(abs_hom.to_monoid_hom : R \u2192* R).map_prod _ _\n\nsection pigeonhole\n\nvariable [decidable_eq \u03b2]\n\ntheorem card_le_mul_card_image_of_maps_to {f : \u03b1 \u2192 \u03b2} {s : finset \u03b1} {t : finset \u03b2}\n  (Hf : \u2200 a \u2208 s, f a \u2208 t) (n : \u2115) (hn : \u2200 a \u2208 t, (s.filter (\u03bb x, f x = a)).card \u2264 n) :\n  s.card \u2264 n * t.card :=\ncalc s.card = (\u2211 a in t, (s.filter (\u03bb x, f x = a)).card) : card_eq_sum_card_fiberwise Hf\n        ... \u2264 (\u2211 _ in t, n)                              : sum_le_sum hn\n        ... = _                                          : by simp [mul_comm]\n\ntheorem card_le_mul_card_image {f : \u03b1 \u2192 \u03b2} (s : finset \u03b1)\n  (n : \u2115) (hn : \u2200 a \u2208 s.image f, (s.filter (\u03bb x, f x = a)).card \u2264 n) :\n  s.card \u2264 n * (s.image f).card :=\ncard_le_mul_card_image_of_maps_to (\u03bb x, mem_image_of_mem _) n hn\n\ntheorem mul_card_image_le_card_of_maps_to {f : \u03b1 \u2192 \u03b2} {s : finset \u03b1} {t : finset \u03b2}\n  (Hf : \u2200 a \u2208 s, f a \u2208 t) (n : \u2115) (hn : \u2200 a \u2208 t, n \u2264 (s.filter (\u03bb x, f x = a)).card) :\n  n * t.card \u2264 s.card :=\ncalc n * t.card = (\u2211 _ in t, n) : by simp [mul_comm]\n            ... \u2264 (\u2211 a in t, (s.filter (\u03bb x, f x = a)).card) : sum_le_sum hn\n            ... = s.card : by rw \u2190 card_eq_sum_card_fiberwise Hf\n\ntheorem mul_card_image_le_card {f : \u03b1 \u2192 \u03b2} (s : finset \u03b1)\n  (n : \u2115) (hn : \u2200 a \u2208 s.image f, n \u2264 (s.filter (\u03bb x, f x = a)).card) :\n  n * (s.image f).card \u2264 s.card :=\nmul_card_image_le_card_of_maps_to (\u03bb x, mem_image_of_mem _) n hn\n\nend pigeonhole\n\nsection double_counting\nvariables [decidable_eq \u03b1] {s : finset \u03b1} {B : finset (finset \u03b1)} {n : \u2115}\n\n/-- If every element belongs to at most `n` finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\nlemma sum_card_inter_le (h : \u2200 a \u2208 s, (B.filter $ (\u2208) a).card \u2264 n) :\n  \u2211 t in B, (s \u2229 t).card \u2264 s.card * n :=\nbegin\n  refine le_trans _ (s.sum_le_of_forall_le _ _ h),\n  simp_rw [\u2190filter_mem_eq_inter, card_eq_sum_ones, sum_filter],\n  exact sum_comm.le,\nend\n\n/-- If every element belongs to at most `n` finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\nlemma sum_card_le [fintype \u03b1] (h : \u2200 a, (B.filter $ (\u2208) a).card \u2264 n) :\n  \u2211 s in B, s.card \u2264 fintype.card \u03b1 * n :=\ncalc \u2211 s in B, s.card = \u2211 s in B, (univ \u2229 s).card : by simp_rw univ_inter\n                  ... \u2264 fintype.card \u03b1 * n        : sum_card_inter_le (\u03bb a _, h a)\n\n/-- If every element belongs to at least `n` finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\nlemma le_sum_card_inter (h : \u2200 a \u2208 s, n \u2264 (B.filter $ (\u2208) a).card) :\n  s.card * n \u2264 \u2211 t in B, (s \u2229 t).card :=\nbegin\n  apply (s.le_sum_of_forall_le _ _ h).trans,\n  simp_rw [\u2190filter_mem_eq_inter, card_eq_sum_ones, sum_filter],\n  exact sum_comm.le,\nend\n\n/-- If every element belongs to at least `n` finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\nlemma le_sum_card [fintype \u03b1] (h : \u2200 a, n \u2264 (B.filter $ (\u2208) a).card) :\n  fintype.card \u03b1 * n \u2264 \u2211 s in B, s.card :=\ncalc fintype.card \u03b1 * n \u2264 \u2211 s in B, (univ \u2229 s).card : le_sum_card_inter (\u03bb a _, h a)\n                    ... = \u2211 s in B, s.card          : by simp_rw univ_inter\n\n/-- If every element belongs to exactly `n` finsets, then the sum of their sizes is `n` times how\nmany they are. -/\nlemma sum_card_inter (h : \u2200 a \u2208 s, (B.filter $ (\u2208) a).card = n) :\n  \u2211 t in B, (s \u2229 t).card = s.card * n :=\n(sum_card_inter_le $ \u03bb a ha, (h a ha).le).antisymm (le_sum_card_inter $ \u03bb a ha, (h a ha).ge)\n\n/-- If every element belongs to exactly `n` finsets, then the sum of their sizes is `n` times how\nmany they are. -/\nlemma sum_card [fintype \u03b1] (h : \u2200 a, (B.filter $ (\u2208) a).card = n) :\n  \u2211 s in B, s.card = fintype.card \u03b1 * n :=\nby simp_rw [fintype.card, \u2190sum_card_inter (\u03bb a _, h a), univ_inter]\n\nend double_counting\n\nsection canonically_ordered_monoid\n\nvariables [canonically_ordered_monoid M] {f : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[simp, to_additive sum_eq_zero_iff]\nlemma prod_eq_one_iff' : \u220f x in s, f x = 1 \u2194 \u2200 x \u2208 s, f x = 1 :=\nprod_eq_one_iff_of_one_le' $ \u03bb x hx, one_le (f x)\n\n@[to_additive sum_le_sum_of_subset]\nlemma prod_le_prod_of_subset' (h : s \u2286 t) : \u220f x in s, f x \u2264 \u220f x in t, f x :=\nprod_le_prod_of_subset_of_one_le' h $ assume x h\u2081 h\u2082, one_le _\n\n@[to_additive sum_mono_set]\nlemma prod_mono_set' (f : \u03b9 \u2192 M) : monotone (\u03bb s, \u220f x in s, f x) :=\n\u03bb s\u2081 s\u2082 hs, prod_le_prod_of_subset' hs\n\n@[to_additive sum_le_sum_of_ne_zero]\nlemma prod_le_prod_of_ne_one' (h : \u2200 x \u2208 s, f x \u2260 1 \u2192 x \u2208 t) :\n  \u220f x in s, f x \u2264 \u220f x in t, f x :=\nby classical;\ncalc \u220f x in s, f x = (\u220f x in s.filter (\u03bb x, f x = 1), f x) * \u220f x in s.filter (\u03bb x, f x \u2260 1), f x :\n    by rw [\u2190 prod_union, filter_union_filter_neg_eq];\n       exact disjoint_filter.2 (assume _ _ h n_h, n_h h)\n  ... \u2264 (\u220f x in t, f x) : mul_le_of_le_one_of_le\n      (prod_le_one' $ by simp only [mem_filter, and_imp]; exact \u03bb _ _, le_of_eq)\n      (prod_le_prod_of_subset' $ by simpa only [subset_iff, mem_filter, and_imp])\n\nend canonically_ordered_monoid\n\nsection ordered_cancel_comm_monoid\n\nvariables [ordered_cancel_comm_monoid M] {f g : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (Hle : \u2200 i \u2208 s, f i \u2264 g i) (Hlt : \u2203 i \u2208 s, f i < g i) :\n  \u220f i in s, f i < \u220f i in s, g i :=\nbegin\n  classical,\n  rcases Hlt with \u27e8i, hi, hlt\u27e9,\n  rw [\u2190 insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)],\n  exact mul_lt_mul_of_lt_of_le hlt (prod_le_prod'' $ \u03bb j hj, Hle j  $ mem_of_mem_erase hj)\nend\n\n@[to_additive sum_lt_sum_of_nonempty]\nlemma prod_lt_prod_of_nonempty' (hs : s.nonempty) (Hlt : \u2200 i \u2208 s, f i < g i) :\n  \u220f i in s, f i < \u220f i in s, g i :=\nbegin\n  apply prod_lt_prod',\n  { intros i hi, apply le_of_lt (Hlt i hi) },\n  cases hs with i hi,\n  exact \u27e8i, hi, Hlt i hi\u27e9,\nend\n\n@[to_additive sum_lt_sum_of_subset]\nlemma prod_lt_prod_of_subset' (h : s \u2286 t) {i : \u03b9} (ht : i \u2208 t) (hs : i \u2209 s) (hlt : 1 < f i)\n  (hle : \u2200 j \u2208 t, j \u2209 s \u2192 1 \u2264 f j) :\n  \u220f j in s, f j < \u220f j in t, f j :=\nby classical;\ncalc \u220f j in s, f j < \u220f j in insert i s, f j :\nbegin\n  rw prod_insert hs,\n  exact lt_mul_of_one_lt_left' (\u220f j in s, f j) hlt,\nend\n... \u2264 \u220f j in t, f j :\nbegin\n  apply prod_le_prod_of_subset_of_one_le',\n  { simp [finset.insert_subset, h, ht] },\n  { assume x hx h'x,\n    simp only [mem_insert, not_or_distrib] at h'x,\n    exact hle x hx h'x.2 }\nend\n\n@[to_additive single_lt_sum]\nlemma single_lt_prod' {i j : \u03b9} (hij : j \u2260 i) (hi : i \u2208 s) (hj : j \u2208 s) (hlt : 1 < f j)\n  (hle : \u2200 k \u2208 s, k \u2260 i \u2192 1 \u2264 f k) :\n  f i < \u220f k in s, f k :=\ncalc f i = \u220f k in {i}, f k : prod_singleton.symm\n     ... < \u220f k in s, f k   :\n  prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt $\n    \u03bb k hks hki, hle k hks (mt mem_singleton.2 hki)\n\n@[to_additive sum_pos] lemma one_lt_prod (h : \u2200i \u2208 s, 1 < f i) (hs : s.nonempty) :\n  1 < (\u220f i in s, f i) :=\nlt_of_le_of_lt (by rw prod_const_one) $ prod_lt_prod_of_nonempty' hs h\n\n@[to_additive] lemma prod_lt_one (h : \u2200i \u2208 s, f i < 1) (hs : s.nonempty) :\n  (\u220f i in s, f i) < 1 :=\n(prod_lt_prod_of_nonempty' hs h).trans_le (by rw prod_const_one)\n\nend ordered_cancel_comm_monoid\n\nsection linear_ordered_cancel_comm_monoid\n\nvariables [linear_ordered_cancel_comm_monoid M] {f g : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : \u220f i in s, f i < \u220f i in s, g i) :\n  \u2203 i \u2208 s, f i < g i :=\nbegin\n  contrapose! Hlt with Hle,\n  exact prod_le_prod'' Hle\nend\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.nonempty) (Hle : \u220f i in s, f i \u2264 \u220f i in s, g i) :\n  \u2203 i \u2208 s, f i \u2264 g i :=\nbegin\n  contrapose! Hle with Hlt,\n  exact prod_lt_prod_of_nonempty' hs Hlt\nend\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\nlemma exists_one_lt_of_prod_one_of_exists_ne_one' (f : \u03b9 \u2192 M)\n  (h\u2081 : \u220f i in s, f i = 1) (h\u2082 : \u2203 i \u2208 s, f i \u2260 1) :\n  \u2203 i \u2208 s, 1 < f i :=\nbegin\n  contrapose! h\u2081,\n  obtain \u27e8i, m, i_ne\u27e9 : \u2203 i \u2208 s, f i \u2260 1 := h\u2082,\n  apply ne_of_lt,\n  calc \u220f j in s, f j < \u220f j in s, 1 : prod_lt_prod' h\u2081 \u27e8i, m, (h\u2081 i m).lt_of_ne i_ne\u27e9\n                 ... = 1           : prod_const_one\nend\n\nend linear_ordered_cancel_comm_monoid\n\nsection ordered_comm_semiring\n\nvariables [ordered_comm_semiring R] {f g : \u03b9 \u2192 R} {s t : finset \u03b9}\nopen_locale classical\n\n/- this is also true for a ordered commutative multiplicative monoid -/\nlemma prod_nonneg (h0 : \u2200 i \u2208 s, 0 \u2264 f i) : 0 \u2264 \u220f i in s, f i :=\nprod_induction f (\u03bb i, 0 \u2264 i) (\u03bb _ _ ha hb, mul_nonneg ha hb) zero_le_one h0\n\n/- this is also true for a ordered commutative multiplicative monoid -/\nlemma prod_pos [nontrivial R] (h0 : \u2200 i \u2208 s, 0 < f i) :\n  0 < \u220f i in s, f i :=\nprod_induction f (\u03bb x, 0 < x) (\u03bb _ _ ha hb, mul_pos ha hb) zero_lt_one h0\n\n/-- If all `f i`, `i \u2208 s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `finset.prod_le_prod''` for\nthe case of an ordered commutative multiplicative monoid. -/\nlemma prod_le_prod (h0 : \u2200 i \u2208 s, 0 \u2264 f i) (h1 : \u2200 i \u2208 s, f i \u2264 g i) :\n  \u220f i in s, f i \u2264 \u220f i in s, g i :=\nbegin\n  induction s using finset.induction with a s has ih h,\n  { simp },\n  { simp only [prod_insert has], apply mul_le_mul,\n    { exact h1 a (mem_insert_self a s) },\n    { apply ih (\u03bb x H, h0 _ _) (\u03bb x H, h1 _ _); exact (mem_insert_of_mem H) },\n    { apply prod_nonneg (\u03bb x H, h0 x (mem_insert_of_mem H)) },\n    { apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) } }\nend\n\n/-- If each `f i`, `i \u2208 s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\nlemma prod_le_one (h0 : \u2200 i \u2208 s, 0 \u2264 f i) (h1 : \u2200 i \u2208 s, f i \u2264 1) :\n  \u220f i in s, f i \u2264 1 :=\nbegin\n  convert \u2190 prod_le_prod h0 h1,\n  exact finset.prod_const_one\nend\n\n/-- If `g, h \u2264 f` and `g i + h i \u2264 f i`, then the product of `f` over `s` is at least the\n  sum of the products of `g` and `h`. This is the version for `ordered_comm_semiring`. -/\nlemma prod_add_prod_le {i : \u03b9} {f g h : \u03b9 \u2192 R}\n  (hi : i \u2208 s) (h2i : g i + h i \u2264 f i) (hgf : \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2264 f j)\n  (hhf : \u2200 j \u2208 s, j \u2260 i \u2192 h j \u2264 f j) (hg : \u2200 i \u2208 s, 0 \u2264 g i) (hh : \u2200 i \u2208 s, 0 \u2264 h i) :\n  \u220f i in s, g i + \u220f i in s, h i \u2264 \u220f i in s, f i :=\nbegin\n  simp_rw [prod_eq_mul_prod_diff_singleton hi],\n  refine le_trans _ (mul_le_mul_of_nonneg_right h2i _),\n  { rw [right_distrib],\n    apply add_le_add; apply mul_le_mul_of_nonneg_left; try { apply_assumption; assumption };\n      apply prod_le_prod; simp * { contextual := tt } },\n  { apply prod_nonneg, simp only [and_imp, mem_sdiff, mem_singleton],\n    intros j h1j h2j, exact le_trans (hg j h1j) (hgf j h1j h2j) }\nend\n\nend ordered_comm_semiring\n\nsection canonically_ordered_comm_semiring\n\nvariables [canonically_ordered_comm_semiring R] {f g h : \u03b9 \u2192 R} {s : finset \u03b9} {i : \u03b9}\n\nlemma prod_le_prod' (h : \u2200 i \u2208 s, f i \u2264 g i) :\n  \u220f i in s, f i \u2264 \u220f i in s, g i :=\nbegin\n  classical,\n  induction s using finset.induction with a s has ih h,\n  { simp },\n  { rw [finset.prod_insert has, finset.prod_insert has],\n    apply mul_le_mul',\n    { exact h _ (finset.mem_insert_self a s) },\n    { exact ih (\u03bb i hi, h _ (finset.mem_insert_of_mem hi)) } }\nend\n\n/-- If `g, h \u2264 f` and `g i + h i \u2264 f i`, then the product of `f` over `s` is at least the\n  sum of the products of `g` and `h`. This is the version for `canonically_ordered_comm_semiring`.\n-/\nlemma prod_add_prod_le' (hi : i \u2208 s) (h2i : g i + h i \u2264 f i)\n  (hgf : \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2264 f j) (hhf : \u2200 j \u2208 s, j \u2260 i \u2192 h j \u2264 f j) :\n  \u220f i in s, g i + \u220f i in s, h i \u2264 \u220f i in s, f i :=\nbegin\n  classical, simp_rw [prod_eq_mul_prod_diff_singleton hi],\n  refine le_trans _ (mul_le_mul_right' h2i _),\n  rw [right_distrib],\n  apply add_le_add; apply mul_le_mul_left'; apply prod_le_prod';\n  simp only [and_imp, mem_sdiff, mem_singleton]; intros; apply_assumption; assumption\nend\n\nend canonically_ordered_comm_semiring\n\nend finset\n\nnamespace fintype\n\nvariables [fintype \u03b9]\n\n@[to_additive sum_mono, mono]\nlemma prod_mono' [ordered_comm_monoid M] : monotone (\u03bb f : \u03b9 \u2192 M, \u220f i, f i) :=\n\u03bb f g hfg, finset.prod_le_prod'' $ \u03bb x _, hfg x\n\nattribute [mono] sum_mono\n\n@[to_additive sum_strict_mono]\nlemma prod_strict_mono' [ordered_cancel_comm_monoid M] : strict_mono (\u03bb f : \u03b9 \u2192 M, \u220f x, f x) :=\n\u03bb f g hfg, let \u27e8hle, i, hlt\u27e9 := pi.lt_def.mp hfg in\n  finset.prod_lt_prod' (\u03bb i _, hle i) \u27e8i, finset.mem_univ i, hlt\u27e9\n\nend fintype\n\nnamespace with_top\nopen finset\n\n/-- A product of finite numbers is still finite -/\nlemma prod_lt_top [canonically_ordered_comm_semiring R] [nontrivial R] [decidable_eq R]\n  {s : finset \u03b9} {f : \u03b9 \u2192 with_top R} (h : \u2200 i \u2208 s, f i \u2260 \u22a4) :\n  \u220f i in s, f i < \u22a4 :=\nprod_induction f (\u03bb a, a < \u22a4) (\u03bb a b h\u2081 h\u2082, mul_lt_top h\u2081.ne h\u2082.ne) (coe_lt_top 1) $\n  \u03bb a ha, lt_top_iff_ne_top.2 (h a ha)\n\n/-- A sum of finite numbers is still finite -/\nlemma sum_lt_top [ordered_add_comm_monoid M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M}\n  (h : \u2200 i \u2208 s, f i \u2260 \u22a4) : (\u2211 i in s, f i) < \u22a4 :=\nsum_induction f (\u03bb a, a < \u22a4) (\u03bb a b h\u2081 h\u2082, add_lt_top.2 \u27e8h\u2081, h\u2082\u27e9) zero_lt_top $\n  \u03bb i hi, lt_top_iff_ne_top.2 (h i hi)\n\n/-- A sum of numbers is infinite iff one of them is infinite -/\nlemma sum_eq_top_iff [ordered_add_comm_monoid M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M} :\n  \u2211 i in s, f i = \u22a4 \u2194 \u2203 i \u2208 s, f i = \u22a4 :=\nbegin\n  classical,\n  split,\n  { contrapose!,\n    exact \u03bb h, (sum_lt_top $ \u03bb i hi, (h i hi)).ne },\n  { rintro \u27e8i, his, hi\u27e9,\n    rw [sum_eq_add_sum_diff_singleton his, hi, top_add] }\nend\n\n/-- A sum of finite numbers is still finite -/\nlemma sum_lt_top_iff [ordered_add_comm_monoid M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M} :\n  \u2211 i in s, f i < \u22a4 \u2194 \u2200 i \u2208 s, f i < \u22a4 :=\nby simp only [lt_top_iff_ne_top, ne.def, sum_eq_top_iff, not_exists]\n\nend with_top\n\nsection absolute_value\n\nvariables {S : Type*}\n\nlemma absolute_value.sum_le [semiring R] [ordered_semiring S]\n  (abv : absolute_value R S) (s : finset \u03b9) (f : \u03b9 \u2192 R) :\n  abv (\u2211 i in s, f i) \u2264 \u2211 i in s, abv (f i) :=\nbegin\n  letI := classical.dec_eq \u03b9,\n  refine finset.induction_on s _ (\u03bb i s hi ih, _),\n  { simp },\n  { simp only [finset.sum_insert hi],\n  exact (abv.add_le _ _).trans (add_le_add (le_refl _) ih) },\nend\n\nlemma is_absolute_value.abv_sum [semiring R] [ordered_semiring S] (abv : R \u2192 S)\n  [is_absolute_value abv] (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u2211 i in s, f i) \u2264 \u2211 i in s, abv (f i) :=\n(is_absolute_value.to_absolute_value abv).sum_le _ _\n\nlemma absolute_value.map_prod [comm_semiring R] [nontrivial R] [linear_ordered_comm_ring S]\n  (abv : absolute_value R S) (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u220f i in s, f i) = \u220f i in s, abv (f i) :=\nabv.to_monoid_hom.map_prod f s\n\nlemma is_absolute_value.map_prod [comm_semiring R] [nontrivial R] [linear_ordered_comm_ring S]\n  (abv : R \u2192 S) [is_absolute_value abv] (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u220f i in s, f i) = \u220f i in s, abv (f i) :=\n(is_absolute_value.to_absolute_value abv).map_prod _ _\n\nend absolute_value\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/big_operators/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7346927734008383}}
{"text": "/-\nCopyright (c) 2020 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n-/\nimport data.set.finite\n\n/-!\n# Infinitude of intervals\n\nBounded intervals in dense orders are infinite, as are unbounded intervals\nin orders that are unbounded on the appropriate side. We also prove that an unbounded\npreorder is an infinite type.\n-/\n\nvariables {\u03b1 : Type*} [preorder \u03b1]\n\n/-- A nonempty preorder with no maximal element is infinite. This is not an instance to avoid\na cycle with `infinite \u03b1 \u2192 nontrivial \u03b1 \u2192 nonempty \u03b1`. -/\nlemma no_max_order.infinite [nonempty \u03b1] [no_max_order \u03b1] : infinite \u03b1 :=\nlet \u27e8f, hf\u27e9 := nat.exists_strict_mono \u03b1 in infinite.of_injective f hf.injective\n\n/-- A nonempty preorder with no minimal element is infinite. This is not an instance to avoid\na cycle with `infinite \u03b1 \u2192 nontrivial \u03b1 \u2192 nonempty \u03b1`. -/\nlemma no_min_order.infinite [nonempty \u03b1] [no_min_order \u03b1] : infinite \u03b1 :=\n@no_max_order.infinite \u03b1\u1d52\u1d48 _ _ _\n\nnamespace set\n\nsection densely_ordered\n\nvariables [densely_ordered \u03b1] {a b : \u03b1} (h : a < b)\n\nlemma Ioo.infinite : infinite (Ioo a b) := @no_max_order.infinite _ _ (nonempty_Ioo_subtype h) _\nlemma Ioo_infinite : (Ioo a b).infinite := infinite_coe_iff.1 $ Ioo.infinite h\n\nlemma Ico_infinite : (Ico a b).infinite := (Ioo_infinite h).mono Ioo_subset_Ico_self\nlemma Ico.infinite : infinite (Ico a b) := infinite_coe_iff.2 $ Ico_infinite h\n\nlemma Ioc_infinite : (Ioc a b).infinite := (Ioo_infinite h).mono Ioo_subset_Ioc_self\nlemma Ioc.infinite : infinite (Ioc a b) := infinite_coe_iff.2 $ Ioc_infinite h\n\nlemma Icc_infinite : (Icc a b).infinite := (Ioo_infinite h).mono Ioo_subset_Icc_self\nlemma Icc.infinite : infinite (Icc a b) := infinite_coe_iff.2 $ Icc_infinite h\n\nend densely_ordered\n\ninstance [no_min_order \u03b1] {a : \u03b1} : infinite (Iio a) := no_min_order.infinite\nlemma Iio_infinite [no_min_order \u03b1] (a : \u03b1) : (Iio a).infinite := infinite_coe_iff.1 Iio.infinite\n\ninstance [no_min_order \u03b1] {a : \u03b1} : infinite (Iic a) := no_min_order.infinite\nlemma Iic_infinite [no_min_order \u03b1] (a : \u03b1) : (Iic a).infinite := infinite_coe_iff.1 Iic.infinite\n\ninstance [no_max_order \u03b1] {a : \u03b1} : infinite (Ioi a) := no_max_order.infinite\nlemma Ioi_infinite [no_min_order \u03b1] (a : \u03b1) : (Iio a).infinite := infinite_coe_iff.1 Iio.infinite\n\ninstance [no_max_order \u03b1] {a : \u03b1} : infinite (Ici a) := no_max_order.infinite\nlemma Ici_infinite [no_max_order \u03b1] (a : \u03b1) : (Ici a).infinite := infinite_coe_iff.1 Ici.infinite\n\nend set\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/data/set/intervals/infinite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326726, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7346927728611535}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.bounds\nimport Mathlib.data.set.intervals.image_preimage\nimport Mathlib.PostPort\n\nuniverses u \n\nnamespace Mathlib\n\n/-!\n# Intervals without endpoints ordering\n\nIn any decidable linear order `\u03b1`, we define the set of elements lying between two elements `a` and\n`b` as `Icc (min a b) (max a b)`.\n\n`Icc a b` requires the assumption `a \u2264 b` to be meaningful, which is sometimes inconvenient. The\ninterval as defined in this file is always the set of things lying between `a` and `b`, regardless\nof the relative order of `a` and `b`.\n\nFor real numbers, `Icc (min a b) (max a b)` is the same as `segment a b`.\n\n## Notation\n\nWe use the localized notation `[a, b]` for `interval a b`. One can open the locale `interval` to\nmake the notation available.\n\n-/\n\nnamespace set\n\n\n/-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/\ndef interval {\u03b1 : Type u} [linear_order \u03b1] (a : \u03b1) (b : \u03b1) : set \u03b1 := Icc (min a b) (max a b)\n\n@[simp] theorem interval_of_le {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) :\n    interval a b = Icc a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (interval a b = Icc a b)) (interval.equations._eqn_1 a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (Icc (min a b) (max a b) = Icc a b)) (min_eq_left h)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (Icc a (max a b) = Icc a b)) (max_eq_right h)))\n        (Eq.refl (Icc a b))))\n\n@[simp] theorem interval_of_ge {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : b \u2264 a) :\n    interval a b = Icc b a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (interval a b = Icc b a)) (interval.equations._eqn_1 a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (Icc (min a b) (max a b) = Icc b a)) (min_eq_right h)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (Icc b (max a b) = Icc b a)) (max_eq_left h)))\n        (Eq.refl (Icc b a))))\n\ntheorem interval_swap {\u03b1 : Type u} [linear_order \u03b1] (a : \u03b1) (b : \u03b1) : interval a b = interval b a :=\n  sorry\n\ntheorem interval_of_lt {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) :\n    interval a b = Icc a b :=\n  interval_of_le (le_of_lt h)\n\ntheorem interval_of_gt {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : b < a) :\n    interval a b = Icc b a :=\n  interval_of_ge (le_of_lt h)\n\ntheorem interval_of_not_le {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : \u00aca \u2264 b) :\n    interval a b = Icc b a :=\n  interval_of_gt (lt_of_not_ge h)\n\ntheorem interval_of_not_ge {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} (h : \u00acb \u2264 a) :\n    interval a b = Icc a b :=\n  interval_of_lt (lt_of_not_ge h)\n\n@[simp] theorem interval_self {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} : interval a a = singleton a :=\n  sorry\n\n@[simp] theorem nonempty_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    set.nonempty (interval a b) :=\n  sorry\n\n@[simp] theorem left_mem_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    a \u2208 interval a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 interval a b)) (interval.equations._eqn_1 a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 Icc (min a b) (max a b))) (propext mem_Icc)))\n      { left := min_le_left a b, right := le_max_left a b })\n\n@[simp] theorem right_mem_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    b \u2208 interval a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b \u2208 interval a b)) (interval_swap a b))) left_mem_interval\n\ntheorem Icc_subset_interval {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    Icc a b \u2286 interval a b :=\n  id\n    fun (x : \u03b1) (h : x \u2208 Icc a b) =>\n      eq.mpr\n        (id\n          (Eq._oldrec (Eq.refl (x \u2208 interval a b))\n            (interval_of_le (le_trans (and.left h) (and.right h)))))\n        h\n\ntheorem Icc_subset_interval' {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    Icc b a \u2286 interval a b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (Icc b a \u2286 interval a b)) (interval_swap a b)))\n    Icc_subset_interval\n\ntheorem mem_interval_of_le {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (ha : a \u2264 x)\n    (hb : x \u2264 b) : x \u2208 interval a b :=\n  Icc_subset_interval { left := ha, right := hb }\n\ntheorem mem_interval_of_ge {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1} (hb : b \u2264 x)\n    (ha : x \u2264 a) : x \u2208 interval a b :=\n  Icc_subset_interval' { left := hb, right := ha }\n\ntheorem interval_subset_interval {\u03b1 : Type u} [linear_order \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1}\n    (h\u2081 : a\u2081 \u2208 interval a\u2082 b\u2082) (h\u2082 : b\u2081 \u2208 interval a\u2082 b\u2082) : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082 :=\n  Icc_subset_Icc (le_min (and.left h\u2081) (and.left h\u2082)) (max_le (and.right h\u2081) (and.right h\u2082))\n\ntheorem interval_subset_interval_iff_mem {\u03b1 : Type u} [linear_order \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1}\n    {b\u2082 : \u03b1} : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082 \u2194 a\u2081 \u2208 interval a\u2082 b\u2082 \u2227 b\u2081 \u2208 interval a\u2082 b\u2082 :=\n  { mp :=\n      fun (h : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082) =>\n        { left := h left_mem_interval, right := h right_mem_interval },\n    mpr :=\n      fun (h : a\u2081 \u2208 interval a\u2082 b\u2082 \u2227 b\u2081 \u2208 interval a\u2082 b\u2082) =>\n        interval_subset_interval (and.left h) (and.right h) }\n\ntheorem interval_subset_interval_iff_le {\u03b1 : Type u} [linear_order \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1}\n    {b\u2082 : \u03b1} : interval a\u2081 b\u2081 \u2286 interval a\u2082 b\u2082 \u2194 min a\u2082 b\u2082 \u2264 min a\u2081 b\u2081 \u2227 max a\u2081 b\u2081 \u2264 max a\u2082 b\u2082 :=\n  sorry\n\ntheorem interval_subset_interval_right {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1}\n    (h : x \u2208 interval a b) : interval x b \u2286 interval a b :=\n  interval_subset_interval h right_mem_interval\n\ntheorem interval_subset_interval_left {\u03b1 : Type u} [linear_order \u03b1] {a : \u03b1} {b : \u03b1} {x : \u03b1}\n    (h : x \u2208 interval a b) : interval a x \u2286 interval a b :=\n  interval_subset_interval left_mem_interval h\n\ntheorem bdd_below_bdd_above_iff_subset_interval {\u03b1 : Type u} [linear_order \u03b1] (s : set \u03b1) :\n    bdd_below s \u2227 bdd_above s \u2194 \u2203 (a : \u03b1), \u2203 (b : \u03b1), s \u2286 interval a b :=\n  sorry\n\n@[simp] theorem preimage_const_add_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a + x) \u207b\u00b9' interval b c = interval (b - a) (c - a) :=\n  sorry\n\n@[simp] theorem preimage_add_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x + a) \u207b\u00b9' interval b c = interval (b - a) (c - a) :=\n  sorry\n\n@[simp] theorem preimage_neg_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) : -interval a b = interval (-a) (-b) :=\n  sorry\n\n@[simp] theorem preimage_sub_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x - a) \u207b\u00b9' interval b c = interval (b + a) (c + a) :=\n  sorry\n\n@[simp] theorem preimage_const_sub_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a - x) \u207b\u00b9' interval b c = interval (a - b) (a - c) :=\n  sorry\n\n@[simp] theorem image_const_add_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a + x) '' interval b c = interval (a + b) (a + c) :=\n  sorry\n\n@[simp] theorem image_add_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x + a) '' interval b c = interval (b + a) (c + a) :=\n  sorry\n\n@[simp] theorem image_const_sub_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => a - x) '' interval b c = interval (a - b) (a - c) :=\n  sorry\n\n@[simp] theorem image_sub_const_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1)\n    (b : \u03b1) (c : \u03b1) : (fun (x : \u03b1) => x - a) '' interval b c = interval (b - a) (c - a) :=\n  sorry\n\ntheorem image_neg_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a : \u03b1) (b : \u03b1) :\n    Neg.neg '' interval a b = interval (-a) (-b) :=\n  sorry\n\n/-- If `[x, y]` is a subinterval of `[a, b]`, then the distance between `x` and `y`\nis less than or equal to that of `a` and `b` -/\ntheorem abs_sub_le_of_subinterval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {a : \u03b1} {b : \u03b1}\n    {x : \u03b1} {y : \u03b1} (h : interval x y \u2286 interval a b) : abs (y - x) \u2264 abs (b - a) :=\n  sorry\n\n/-- If `x \u2208 [a, b]`, then the distance between `a` and `x` is less than or equal to\nthat of `a` and `b`  -/\ntheorem abs_sub_left_of_mem_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {a : \u03b1} {b : \u03b1}\n    {x : \u03b1} (h : x \u2208 interval a b) : abs (x - a) \u2264 abs (b - a) :=\n  abs_sub_le_of_subinterval (interval_subset_interval_left h)\n\n/-- If `x \u2208 [a, b]`, then the distance between `x` and `b` is less than or equal to\nthat of `a` and `b`  -/\ntheorem abs_sub_right_of_mem_interval {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {a : \u03b1} {b : \u03b1}\n    {x : \u03b1} (h : x \u2208 interval a b) : abs (b - x) \u2264 abs (b - a) :=\n  abs_sub_le_of_subinterval (interval_subset_interval_right h)\n\n@[simp] theorem preimage_mul_const_interval {k : Type u} [linear_ordered_field k] {a : k}\n    (ha : a \u2260 0) (b : k) (c : k) :\n    (fun (x : k) => x * a) \u207b\u00b9' interval b c = interval (b / a) (c / a) :=\n  sorry\n\n@[simp] theorem preimage_const_mul_interval {k : Type u} [linear_ordered_field k] {a : k}\n    (ha : a \u2260 0) (b : k) (c : k) :\n    (fun (x : k) => a * x) \u207b\u00b9' interval b c = interval (b / a) (c / a) :=\n  sorry\n\n@[simp] theorem preimage_div_const_interval {k : Type u} [linear_ordered_field k] {a : k}\n    (ha : a \u2260 0) (b : k) (c : k) :\n    (fun (x : k) => x / a) \u207b\u00b9' interval b c = interval (b * a) (c * a) :=\n  sorry\n\n@[simp] theorem image_mul_const_interval {k : Type u} [linear_ordered_field k] (a : k) (b : k)\n    (c : k) : (fun (x : k) => x * a) '' interval b c = interval (b * a) (c * a) :=\n  sorry\n\n@[simp] theorem image_const_mul_interval {k : Type u} [linear_ordered_field k] (a : k) (b : k)\n    (c : k) : (fun (x : k) => a * x) '' interval b c = interval (a * b) (a * c) :=\n  sorry\n\n@[simp] theorem image_div_const_interval {k : Type u} [linear_ordered_field k] (a : k) (b : k)\n    (c : k) : (fun (x : k) => x / a) '' interval b c = interval (b / a) (c / a) :=\n  image_mul_const_interval (a\u207b\u00b9) b c\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/set/intervals/unordered_interval_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7346927699378608}}
{"text": "variables a b c d : \u2124\n\nexample : a + 0 = a := add_zero a\nexample : 0 + a = a := zero_add a\nexample : a * 1 = a := mul_one a\nexample : 1 * a = a := one_mul a\nexample : -a + a = 0 := neg_add_self a\nexample : a + -a = 0 := add_neg_self a\nexample : a - a = 0 := sub_self a\nexample : a + b = b + a := add_comm a b\nexample : a + b + c = a + (b + c) := add_assoc a b c\nexample : a * b = b * a := mul_comm a b\nexample : a * b * c = a * (b * c) := mul_assoc a b c\nexample : a * (b + c) = a * b + a * c := mul_add a b c\nexample : a * (b + c) = a * b + a * c := left_distrib a b c\nexample : (a + b) * c = a * c + b * c := add_mul a b c\nexample : (a + b) * c = a * c + b * c := right_distrib a b c\nexample : a * (b - c) = a * b - a * c := mul_sub a b c\nexample : (a - b) * c = a * c - b * c := sub_mul a b c\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0209.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632302488963, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7346894351085291}}
{"text": "/-\nAlgebraic geometry M4P33, Jan-Mar 2020, formalised in Lean.\n\nCopyright (c) 2020 Kevin Buzzard\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, and whoever else in the class wants to join in.\n\nNote: if you are viewing this file in a browser via the following\nlink: \n\nhttps://leanprover-community.github.io/lean-web-editor/#url=https%3A%2F%2Fraw.githubusercontent.com%2FImperialCollegeLondon%2FM4P33%2Fmaster%2Fsrc%2Faffine_algebraic_set%2FV.lean\n\nthen you can click around on the code and see the state of Lean's \"brain\"\nat any point within any begin/end proof block.\n-/\n\n-- imports the theory of multivariable polynomials over rings\nimport data.mv_polynomial\nimport for_mathlib.mv_polynomial\n\n-- imports the concept of the radical of an ideal\nimport ring_theory.ideal_operations\nimport ring_theory.noetherian\nimport ring_theory.polynomial\nimport topology.basic\n\n/-!\n# Lecture 2 : The \ud835\udd4d construction\n\nLet k be a commutative ring and let n be a natural number.\n\nThis file defines the map \ud835\udd4d from subsets of k[X\u2081,X\u2082,\u2026,X\u2099]\nto subsets of k\u207f, and proves basic properties about this map.\n\nTo get \ud835\udd4d in VS Code, type `\\bbV`.\n\nNote: we never assume that the number of variables is finite,\nso actually instead of using a natural number n, we use an\narbitrary set n for our variables.\n\nAll the definitions work for k a commutative ring, but not all\nof the the theorems do. However, computer scientists want us to set\nup the theory in as much generality as possible, and I believe that\nmathematicians should learn to think more like computer scientists. \nSo k starts off being a commutative ring, and occasionally changes later.\n\n## Lean 3 notation: important comments.\n\nBecause we're not using Lean 4, we will have to deal with some\nawkward notational issues.\n\n* the multivariable polynomial ring k[X\u2081,X\u2082,\u2026,X\u2099] is denoted\n  `mv_polynomial n k`.\n\n* The set k\u207f is denoted\n  `n \u2192 k`.\n\n  (note: this means maps from n to k, and if you're thinking\n   about n as {1,2,3,...,n} then you can see that this makes sense).\n\n* subsets of a set X are denoted\n  `set X`\n\n* The subset of X which is all of X is not called X :-) It's called\n  `univ`\n\n* To evaluate a polynomial f on a vector x, we write\n  `eval x f`\n\n  Note the order! \"Maps on the right\".\n\n## Important definitions\n\n* `\ud835\udd4d : set (mv_polynomial n k) \u2192 set (n \u2192 k)` \n  sending a subset S of k[X\u2081,X\u2082,\u2026X\u2099] to the subset of k\u207f cut out\n  by the zeros of all the elements of S.\n\n## References\n\nMartin Orr's lecture notes at\n  https://homepages.warwick.ac.uk/staff/Martin.Orr/2017-8/alg-geom/\n\n## Tags\n\nalgebraic geometry, algebraic variety, \ud835\udd4d\n-/\n-- code starts here\n\n-- We're dealing with multivariable polynomials so let's open the\n-- namespace to get easy access to all the functions\nopen mv_polynomial\n\n-- let k be a commutative ring\nvariables {k : Type*} [comm_semiring k]\n\n-- and let \u03c3 be any set, but pretend it's {1,2,...,n} with n a natural number.\n-- We'll work with polynomials in variables X_i for i \u2208 \u03c3.\nvariable {\u03c3 : Type*}\n\nlocal notation `\ud835\udd38\u207f` := \u03c3 \u2192 k \n\n/- recall:\n\n     Maths                 Lean 3\n     ---------------------------------------\n     k[X\u2081, X\u2082, ..., X\u2099]    mv_polynomial \u03c3 k\n     k\u207f or \ud835\udd38\u207f              \u03c3 \u2192 k\n     subsets of X          set X\n     the subset X of X     univ\n     f(x)                  eval x f\n-/\n\n/-- \ud835\udd4d : the function sending a subset S of k[X\u2081,X\u2082,\u2026X\u2099] to\n  the subset of k\u207f defined as the intersection of the zeros of all\n  the elements of S. For more details, see Martin Orr's notes -/\ndef \ud835\udd4d (S : set (mv_polynomial \u03c3 k)) : set \ud835\udd38\u207f :=\n{x : \ud835\udd38\u207f | \u2200 f \u2208 S, eval x f = 0}\n\n-- Now let's prove a bunch of theorems about \ud835\udd4d, in a namespace\n\nnamespace affine_algebraic_set\n\n-- the theorems will be about sets, so let's open the set namespace\n-- giving us easier access to theorems about sets \n\nopen set\n\n-- The following lemma has a trivial proof so don't worry about it.\n/-- x \u2208 \ud835\udd4d S \u2194 for all f \u2208 S, f(x) = 0. This is true by definition. -/\nlemma mem_\ud835\udd4d_iff {S : set (mv_polynomial \u03c3 k)} {x : \u03c3 \u2192 k} :\n  x \u2208 \ud835\udd4d S \u2194 \u2200 f \u2208 S, eval x f = 0 := iff.rfl\n\n-- The rest of the proofs in this file are supposed to be comprehensible\n-- to mathematicians \n\n/-- \ud835\udd4d(\u2205) = k\u207f -/\nlemma \ud835\udd4d_empty : \ud835\udd4d (\u2205 : set (mv_polynomial \u03c3 k)) = univ :=\nbegin\n  -- We need to show that for all x in k\u207f, x \u2208 \ud835\udd4d \u2205\n  rw eq_univ_iff_forall,\n  -- so say x \u2208 k\u207f.\n  intro x,\n  -- By definition of \ud835\udd4d, we need to check that f(x) = 0 for all f in \u2205\n  rw mem_\ud835\udd4d_iff,\n  -- so say f is a polynomial\n  intro f,\n  -- and f is in the empty set\n  intro hf,\n  -- well, our assumptions give a contradiction,\n  -- and we can deduce anything from a contradiction\n  cases hf,\nend\n\n/-- Over a non-zero commutative ring, \ud835\udd4d (k[X\u2081,X\u2082,\u2026,X\u2099]) = \u2205 -/\nlemma \ud835\udd4d_univ {k : Type*} [nonzero_comm_ring k] {n : Type*} :\n  \ud835\udd4d (univ : set (mv_polynomial n k)) = \u2205 :=\nbegin\n  -- It suffices to show that for all x \u2208 k\u207f, x isn't in \ud835\udd4d (all polynomials)\n  rw eq_empty_iff_forall_not_mem,\n  -- so say x \u2208 k\u207f\n  intro x,\n  -- we need to check that it's not true that for every polynomial f, f(x) = 0\n  rw mem_\ud835\udd4d_iff,\n  -- so let's assume that f(x) = 0 for every polynomial f,\n  intro h,\n  -- and get a contradiction (note that the goal is now `false`).\n  -- Let's consider the constant polynomial 1; we deduce 1(x) = 0.\n  replace h := h (C 1) (mem_univ _),\n  -- evaluating 1 at x gives the value 1\n  rw eval_C at h,\n  -- so 1 = 0 in k, which contradicts k being non-zero\n  exact zero_ne_one h.symm \nend\n\n/-- \ud835\udd4d({0}) = k\u207f -/\nlemma \ud835\udd4d_zero : \ud835\udd4d ({0} : set (mv_polynomial \u03c3 k)) = univ :=\nbegin\n  -- It suffices to prove every element of k\u207f is in \ud835\udd4d(0)\n  rw eq_univ_iff_forall,\n  -- so say x \u2208 k\u207f\n  intro x,\n  -- To prove it's in V(0), we need to show f(x)=0 for all f in {0} \n  rw mem_\ud835\udd4d_iff,\n  -- so take f in {0}\n  intros f hf,\n  -- Then it's zero!\n  rw mem_singleton_iff at hf, \n  -- so we have to prove 0(x) = 0\n  rw hf,\n  -- which is obvious\n  refl,\nend\n\n/-- If k \u2260 0 then \ud835\udd4d({1}) = \u2205 -/\nlemma \ud835\udd4d_one {k : Type*} [nonzero_comm_ring k] {n : Type*} :\n  \ud835\udd4d ({1} : set (mv_polynomial n k)) = \u2205 :=\nbegin\n  -- this is basically the same proof as \ud835\udd4d_univ\n  -- It suffices to show that for all x \u2208 k\u207f, x isn't in \ud835\udd4d ({1})\n  rw eq_empty_iff_forall_not_mem,\n  -- so say x \u2208 k\u207f\n  intro x,\n  -- we need to check that it's not true that for all f \u2208 {1}, f(x) = 0\n  rw mem_\ud835\udd4d_iff,\n  -- so let's assume that f(x) = 0 for every polynomial f in {1},\n  intro h,\n  -- and get a contradiction (note that the goal is now `false`).\n  -- Setting f = 1, we deduce 1(x) = 0.\n  replace h := h (C 1) (mem_singleton _),\n  -- evaluating the polynomial 1 at x gives the value 1\n  rw eval_C at h,\n  -- so 1 = 0 in k, which contradicts k being non-zero\n  exact zero_ne_one h.symm \nend\n\n/-- If S \u2286 T then \ud835\udd4d(T) \u2286 \ud835\udd4d(S) -/\ntheorem \ud835\udd4d_antimono (S T : set (mv_polynomial \u03c3 k)) :\n  S \u2286 T \u2192 \ud835\udd4d T \u2286 \ud835\udd4d S :=\nbegin\n  -- We are assuming S \u2286 T\n  intro hST,\n  -- Let x \u2208 \ud835\udd4d T be arbitrary \n  intros x hx,\n  -- We want to prove x \u2208 \ud835\udd4d S.\n  -- We know that \u2200 t \u2208 T, t(x) = 0, and we want to\n  -- prove that \u2200 s \u2208 S, s(x) = 0. \n  rw mem_\ud835\udd4d_iff at hx \u22a2,\n  -- So say s \u2208 S.\n  intros s hs,\n  -- we want to prove s(x) = 0.\n  -- But t(x) = 0 for all t in T, so it suffices to prove s \u2208 T\n  apply hx,\n  -- and this is clear because S \u2286 T\n  exact hST hs\nend\n\ntheorem \ud835\udd4d_union (S T : set (mv_polynomial \u03c3 k)) :\n\ud835\udd4d (S \u222a T) = \ud835\udd4d S \u2229 \ud835\udd4d T :=\nbegin\n  -- let's prove this equality of sets by proving \u2286 and \u2287\n  apply set.subset.antisymm,\n  { -- Step 1: we prove the inclusion \ud835\udd4d (S \u222a T) \u2286 \ud835\udd4d S \u2229 \ud835\udd4d T.\n    -- So let x be an element of the LHS\n    intros x hx,\n    -- then x \u2208 \ud835\udd4d (S \u222a T) so \u2200 f \u2208 S \u222a T, f(x) = 0. Call this hypothesis `hx`.\n    rw mem_\ud835\udd4d_iff at hx,\n    -- To prove x \u2208 \ud835\udd4d S \u2229 \ud835\udd4d T, it suffices to prove x \u2208 \ud835\udd4d S and x \u2208 \ud835\udd4d T\n    split,\n    { -- We deal with the two cases separately.\n      -- To prove x \u2208 \ud835\udd4d S, we need to show that for all f \u2208 S, f(x) = 0\n      rw mem_\ud835\udd4d_iff,\n      -- so say f \u2208 S\n      intros f hf,\n      -- By hypothesis `hx`, it suffices to prove that f \u2208 S \u222a T\n      apply hx,\n      -- but this is obvious\n      left, assumption\n    },\n    { -- To prove x \u2208 \ud835\udd4d T, the argument is the same,\n      -- so we write it the way a computer scientist would.\n      -- (they prefer one incomprehensible line to four simple ones)\n      exact mem_\ud835\udd4d_iff.2 (\u03bb f hf, hx _ (set.subset_union_right _ _ hf)),\n    },\n  },\n  { -- Step 2: we prove the other inclusion.\n    -- \u22a2 \ud835\udd4d S \u2229 \ud835\udd4d T \u2286 \ud835\udd4d (S \u222a T) (NB `\u22a2` means \"the goal is\")\n    -- say x is in \ud835\udd4d S and \ud835\udd4d T\n    rintro x \u27e8hxS, hxT\u27e9,\n    -- We need to show that for all f \u2208 S \u222a T, f(x) = 0\n    rw mem_\ud835\udd4d_iff,\n    -- so choose f in S \u222a T\n    intros f hf,\n    -- Well, f is either in S or in T, so there are two cases.\n    cases hf,\n    { -- Say f \u2208 S\n      -- Recall that x \u2208 \ud835\udd4d S, so \u2200 f \u2208 S, f(x) = 0\n      rw mem_\ud835\udd4d_iff at hxS,\n      -- so we're done.\n      exact hxS f hf\n    },\n    { -- Say f \u2208 T\n      -- The argument is the same so we do it in one step\n      exact hxT f hf,\n    }\n  }\nend\n\n-- Infinite (or rather, arbitrary) unions work just the same\n-- We consider a collection S\u1d62 of subsets indexed by i \u2208 I.\ntheorem \ud835\udd4d_Union {I : Type*} (S : I \u2192 set (mv_polynomial \u03c3 k)) :\n\ud835\udd4d (\u22c3 i, S i) = \u22c2 i, \ud835\udd4d (S i) :=\nbegin\n  -- To prove equality of two subsets of k\u207f it suffices to prove \u2286 and \u2287.\n  apply set.subset.antisymm,\n  { -- Goal: \ud835\udd4d (\u22c3 i, S i) \u2286 \u22c2 i, \ud835\udd4d (S i)\n    -- Let x be in the left hand side\n    intros x hx,\n    -- it suffices to prove that for all j, x \u2208 \ud835\udd4d (S j) \n    rw set.mem_Inter,\n    -- so choose some j \u2208 I\n    intro j,\n    -- and say f \u2208 S j.\n    intros f hf,\n    -- We now want to prove f(x) = 0.\n    -- Now we know x \u2208 \ud835\udd4d (\u22c3 i, S i), so g(x) = 0 for all g in \u22c3 i, S i\n    -- Hence it suffices to prove that f \u2208 \u22c3 i, S i\n    apply hx,\n    -- By definition of the infinite union, it suffices to find\n    -- some i \u2208 I such that f \u2208 S i\n    rw set.mem_Union,\n    -- and we can use j for this i\n    use j,\n    -- and what we need to show is true now by assumption, because f \u2208 S j\n    assumption\n  },\n  { -- Now the other way.\n    -- \u22a2 (\u22c2 (i : I), \ud835\udd4d (S i)) \u2286 \ud835\udd4d (\u22c3 (i : I), S i)\n    -- Say x is in the left hand side\n    intros x hx,\n    -- It suffices to show that for all f \u2208 \u22c3 i, S i, f(x) = 0\n    rw mem_\ud835\udd4d_iff,\n    -- so say f is a polynomial in this union\n    intros f hf,\n    -- If f is in the union, then it's in one of the S i, so say f \u2208 S j\n    rw set.mem_Union at hf,\n    cases hf with j hj,\n    -- Now we know x is in the intersection of the \ud835\udd4d (S i) for all i,\n    -- so x \u2208 \ud835\udd4d (S j)\n    rw set.mem_Inter at hx,\n    have hxj := hx j,\n    -- and because h(x) = 0 for every element h \u2208 S j, \n    -- and we know f \u2208 S j, we deduce f(x) = 0 as required.\n    exact hxj _ hj\n  }\nend\n\n-- For convenience, let's define multiplication on subsets of k[X\u2081,X\u2082,\u2026,X\u2099]\n-- in the obvious way: S * T := {s * t | s \u2208 S, t \u2208 T}.\ninstance : has_mul (set (mv_polynomial \u03c3 k)) :=\n\u27e8\u03bb S T, {u | \u2203 (s \u2208 S) (t \u2208 T), u = s * t}\u27e9\n\n-- For this theorem, we need that k satisfies a * b = 0 => a = 0 or b = 0\ntheorem \ud835\udd4d_mul {k : Type*} [integral_domain k] {n : Type*}\n  (S T : set (mv_polynomial n k)) :\n\ud835\udd4d (S * T) = \ud835\udd4d S \u222a \ud835\udd4d T :=\nbegin\n  -- to prove that the two sets are equal we will prove \u2286 and \u2287 \n  apply set.subset.antisymm,\n  { -- This is the \"harder\" of the two inclusions;\n    -- we need to check that if x vanishes on every element of S*T, \n    -- then x \u2208 \ud835\udd4d S or x \u2208 \ud835\udd4d T. So let x be in \ud835\udd4d (S * T)\n    intros x hx,\n    -- We then know that for every f \u2208 S * T, f(x) = 0\n    rw mem_\ud835\udd4d_iff at hx,\n    -- Note for logicians: in this proof, we will assume\n    -- the law of the excluded middle.\n    classical, \n    -- If x \u2208 \ud835\udd4d S then the result is easy...\n    by_cases hx2 : x \u2208 \ud835\udd4d S,\n      -- because \ud835\udd4d S \u2286 \ud835\udd4d S \u222a \ud835\udd4d T\n      exact subset_union_left _ _ hx2,\n    -- ...so we can assume assume x \u2209 \ud835\udd4d S,\n    -- and hence that there's s \u2208 S such that s(x) \u2260 0\n    rw mem_\ud835\udd4d_iff at hx2, push_neg at hx2, rcases hx2 with \u27e8s, hs, hsx\u27e9,\n    -- we now show x \u2208 \ud835\udd4d T,\n      right,\n    -- i.e., that for all t \u2208 T we have t(x) = 0\n    rw mem_\ud835\udd4d_iff,\n    -- So say t \u2208 T\n    intros t ht,\n    -- We want to prove that t(x) = 0.\n    -- Now by assumption, x vanishes on s * t. \n    replace hx := hx (s * t) \u27e8s, hs, t, ht, rfl\u27e9,\n    -- so s(x) * t(x) = 0\n    rw eval_mul at hx,\n    -- so either s(x) or t(x) = 0,\n    cases mul_eq_zero.1 hx with hxs hxt,\n      -- So the case s(x) = 0 is a contradiction\n      contradiction,\n    -- and t(x) = 0 is what we wanted to prove\n    assumption\n  },\n  { -- Here's the easier of the two inclusions.\n    -- say x \u2208 \ud835\udd4d S \u222a \ud835\udd4d T,\n    intros x hx,\n    -- it's either in \ud835\udd4d S or \ud835\udd4d T.\n    cases hx with hxS hxT,\n    { -- Say x \u2208 \ud835\udd4d S.\n      -- We know that x vanishes at every element of S.\n      rw mem_\ud835\udd4d_iff at hxS,\n      -- We want to prove x vanishes at every polynomial of the form s * t\n      -- with s \u2208 S and t \u2208 T.\n      rw mem_\ud835\udd4d_iff,\n      -- so let's take a polynomial of the form s * t\n      rintro _ \u27e8s, hs, t, ht, rfl\u27e9,\n      -- we need to show st(x)=0. So it suffices to show s(x)*t(x)=0\n      rw eval_mul,\n      -- Because x \u2208 \ud835\udd4d S, we have s(x)=0.\n      replace hxS := hxS s hs,\n      -- so it suffices to show 0 * t(x) = 0\n      rw hxS,\n      -- but this is obvious\n      apply zero_mul, \n    },\n    { -- This is the case x \u2208 \ud835\udd4d T and it's of course completely analogous.\n      -- If I knew more about Lean's `WLOG` tactic I might not have to do\n      -- this case. I'll just do it the computer science way (i.e., a proof\n      -- which is quick to write but harder for a human to understand)\n      rintro _ \u27e8s, hs, t, ht, rfl\u27e9,\n      rw [eval_mul, hxT t ht, mul_zero],\n    }\n  }\nend\n\n-- Pedantic exercise: we assumed a * b = 0 => a = 0 or b = 0. Give an\n-- example of a commutative ring with that property which is not an\n-- integral domain. Is the theorem still true for this ring?\n\n-- there seems to be no `semiideal.span`. \n\n/-- \ud835\udd4d(S) equals \ud835\udd4d(<S>), where <S> denotes the\n  ideal of k[X\u2081,\u2026,X\u2099] spanned by S. -/\ntheorem \ud835\udd4d_span {k : Type*} [comm_ring k] {n : Type*}\n  (S : set (mv_polynomial n k)) :\n\ud835\udd4d S = \ud835\udd4d (ideal.span S) :=\nbegin\n  -- Let's prove \u2286 and \u2287\n  apply set.subset.antisymm,\n  { -- This way is the tricky way\n    -- We need to prove \ud835\udd4d(S) \u2286 \ud835\udd4d(<S>), and we prove\n    -- this by induction on the ideal <S>.\n    -- Say x \u2208 \ud835\udd4d(S)\n    intros x hx,\n    -- We need to prove that f(x) = 0 for all f in <S>\n    rw mem_\ud835\udd4d_iff,\n    -- so say f \u2208 <S>\n    intros f hf,\n    -- Apply the principle of induction for ideals.\n    apply submodule.span_induction hf,\n    -- We now have four goals!\n    {\n      -- first goal -- check that if g \u2208 S then g(x) = 0\n      intros g hg,\n      -- this follows because x \u2208 \ud835\udd4d(S)\n      exact hx _ hg,\n    },\n    { -- second goal -- check that if g = 0 then g(x) = 0\n      -- this is true by definition\n      refl\n    },\n    { -- third goal -- check that if g(x) = 0 and h(x) = 0\n      -- then (g+h)(x) = 0\n      intros g h hg hh,\n      -- This is easy because (g+h)(x)=g(x)+h(x)\n      rw eval_add,\n      -- and 0 + 0 = 0\n      rw [hg, hh, zero_add],\n    },\n    { -- finally, say g(x) = 0 and r \u2208 k[X\u2081,\u2026,X\u2099]\n      intros r g hg,\n      -- Need to check (r*g)(x) = 0\n      rw smul_eq_mul,\n      -- i.e. that r(x)*g(x)=0\n      rw eval_mul,\n      -- but g(x)=0\n      rw hg,\n      -- so this is obvious\n      exact mul_zero _,\n    }\n  },\n  { -- The fact that \ud835\udd4d(<S>) \u2286 \ud835\udd4d(S) follows from \ud835\udd4d_antimono and \n    -- the fact that S \u2286 <S>\n    apply \ud835\udd4d_antimono,\n    exact ideal.subset_span,\n  }\nend\n\n/-- If I is an ideal of k[X\u2081,\u2026,X\u2099] then \ud835\udd4d(I)=\ud835\udd4d(\u221aI), where \u221aI is\nthe radical of I -/\ntheorem \ud835\udd4d_radical' {k : Type*} [integral_domain k] {n : Type*}\n  (I : ideal (mv_polynomial n k)) :\n  \ud835\udd4d (\u2191I : set (mv_polynomial n k)) = \ud835\udd4d (\u2191(ideal.radical I) : set _) :=\nbegin\n  apply set.subset.antisymm,\n  { -- this is the slightly trickier direction;\n    -- we want to prove \ud835\udd4d(I) \u2286 \ud835\udd4d(\u221aI). So say x \u2208 \ud835\udd4d(I).\n    intros x hx,\n    rw mem_\ud835\udd4d_iff,\n    intro f,\n    intro hf,\n    cases hf with n hfn,\n    rw mem_\ud835\udd4d_iff at hx,\n    replace hx := hx _ hfn,\n    rw eval_pow at hx,\n    exact pow_eq_zero hx,\n  },\n  { -- this is the easy way\n    apply \ud835\udd4d_antimono,\n    apply ideal.le_radical,\n  }\nend\n\nopen_locale classical\n\n-- \ntheorem \ud835\udd4d_fin {k : Type*} [comm_ring k] {n : Type*}\n  (S : set (mv_polynomial n k)) [fintype n] [is_noetherian_ring k] :\n\u2203 (T : finset (mv_polynomial n k)), \ud835\udd4d (S) = \ud835\udd4d (\u2191T) := \nbegin\n  -- We want to utilize the fact that all ideals in a notherian ring are\n  -- finitely generated. In lean this is true by definition. First we use a\n  -- theorem in lean that mv_poynomial n k is notherian\n  haveI : is_noetherian_ring (mv_polynomial n k) :=\n    is_noetherian_ring_mv_polynomial_of_fintype,\n\n  -- We can now use the fact that the ring is notherian to show that S is\n  -- finitely generated\n  have fg_s : (submodule.fg : ideal (mv_polynomial n k) -> Prop) (ideal.span S),\n  {\n    apply (is_noetherian.noetherian (ideal.span S)),\n  },\n  -- unpack the definition of finitely generated S\n  cases fg_s with T span_eq,\n  -- T will satisfy the required property so we \"use T\" and now our goal will\n  -- be to show that T indeed satisfies the property\n  use T,\n  -- We now use the fact that V(S) = V(Span S) and the fact that the span of\n  -- S and T are the same\n  rw [\ud835\udd4d_span S, \ud835\udd4d_span \u2191T, \u2190span_eq],\n  -- The goal is now true by definition, so we use refl\n  refl,\nend\n\nend affine_algebraic_set\n\n-- Questions or comments? You can often find Kevin on the Lean chat\n-- at https://leanprover.zulipchat.com (login required,\n-- real names preferred, be nice)\n\n-- Prove a theorem. Write a function. xenaproject.wordpress.com\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M4P33", "sha": "1a179372db71ad6802d11eacbc1f02f327d55f8f", "save_path": "github-repos/lean/ImperialCollegeLondon-M4P33", "path": "github-repos/lean/ImperialCollegeLondon-M4P33/M4P33-1a179372db71ad6802d11eacbc1f02f327d55f8f/src/affine_algebraic_set/V.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.7346569988352561}}
{"text": "/-\nCopyright (c) 2021 Alena Gusakov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alena Gusakov\n\n! This file was ported from Lean 3 source module combinatorics.simple_graph.strongly_regular\n! leanprover-community/mathlib commit 2b35fc7bea4640cb75e477e83f32fbd538920822\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Combinatorics.SimpleGraph.Basic\nimport Mathlib.Data.Set.Finite\n\n/-!\n# Strongly regular graphs\n\n## Main definitions\n\n* `G.IsSRGWith n k \u2113 \u03bc` (see `SimpleGraph.IsSRGWith`) is a structure for\n  a `SimpleGraph` satisfying the following conditions:\n  * The cardinality of the vertex set is `n`\n  * `G` is a regular graph with degree `k`\n  * The number of common neighbors between any two adjacent vertices in `G` is `\u2113`\n  * The number of common neighbors between any two nonadjacent vertices in `G` is `\u03bc`\n\n## TODO\n- Prove that the parameters of a strongly regular graph\n  obey the relation `(n - k - 1) * \u03bc = k * (k - \u2113 - 1)`\n- Prove that if `I` is the identity matrix and `J` is the all-one matrix,\n  then the adj matrix `A` of SRG obeys relation `A^2 = kI + \u2113A + \u03bc(J - I - A)`\n-/\n\n\nopen Finset\n\nuniverse u\n\nnamespace SimpleGraph\n\nvariable {V : Type u} [Fintype V] [DecidableEq V]\nvariable (G : SimpleGraph V) [DecidableRel G.Adj]\n\n/-- A graph is strongly regular with parameters `n k \u2113 \u03bc` if\n * its vertex set has cardinality `n`\n * it is regular with degree `k`\n * every pair of adjacent vertices has `\u2113` common neighbors\n * every pair of nonadjacent vertices has `\u03bc` common neighbors\n-/\nstructure IsSRGWith (n k \u2113 \u03bc : \u2115) : Prop where\n  card : Fintype.card V = n\n  regular : G.IsRegularOfDegree k\n  of_adj : \u2200 v w : V, G.Adj v w \u2192 Fintype.card (G.commonNeighbors v w) = \u2113\n  of_not_adj : \u2200 v w : V, v \u2260 w \u2192 \u00acG.Adj v w \u2192 Fintype.card (G.commonNeighbors v w) = \u03bc\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with SimpleGraph.IsSRGWith\n\nvariable {G} {n k \u2113 \u03bc : \u2115}\n\n/-- Empty graphs are strongly regular. Note that `\u2113` can take any value\nfor empty graphs, since there are no pairs of adjacent vertices. -/\ntheorem bot_strongly_regular : (\u22a5 : SimpleGraph V).IsSRGWith (Fintype.card V) 0 \u2113 0 where\n  card := rfl\n  regular := bot_degree\n  of_adj := fun v w h => h.elim\n  of_not_adj := fun v w _h => by\n    simp only [card_eq_zero, Fintype.card_ofFinset, forall_true_left, not_false_iff, bot_adj]\n    ext\n    simp [mem_commonNeighbors]\n#align simple_graph.bot_strongly_regular SimpleGraph.bot_strongly_regular\n\n/-- Complete graphs are strongly regular. Note that `\u03bc` can take any value\nfor complete graphs, since there are no distinct pairs of non-adjacent vertices. -/\ntheorem IsSRGWith.top :\n    (\u22a4 : SimpleGraph V).IsSRGWith (Fintype.card V) (Fintype.card V - 1) (Fintype.card V - 2) \u03bc where\n  card := rfl\n  regular := IsRegularOfDegree.top\n  of_adj := fun v w h => by\n    rw [card_commonNeighbors_top]\n    exact h\n  of_not_adj := fun v w h h' => False.elim (h' ((top_adj v w).2 h))\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.top SimpleGraph.IsSRGWith.top\n\ntheorem IsSRGWith.card_neighborFinset_union_eq {v w : V} (h : G.IsSRGWith n k \u2113 \u03bc) :\n    (G.neighborFinset v \u222a G.neighborFinset w).card =\n      2 * k - Fintype.card (G.commonNeighbors v w) := by\n  apply Nat.add_right_cancel (m := Fintype.card (G.commonNeighbors v w))\n  rw [Nat.sub_add_cancel, \u2190 Set.toFinset_card]\n  -- porting note: Set.toFinset_inter needs workaround to use unification to solve for one of the\n  -- instance arguments:\n  \u00b7 simp [commonNeighbors, @Set.toFinset_inter _ _ _ _ _ _ (_),\n      \u2190 neighborFinset_def, Finset.card_union_add_card_inter, card_neighborFinset_eq_degree,\n      h.regular.degree_eq, two_mul]\n  \u00b7 apply le_trans (card_commonNeighbors_le_degree_left _ _ _)\n    simp [h.regular.degree_eq, two_mul]\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.card_neighbor_finset_union_eq SimpleGraph.IsSRGWith.card_neighborFinset_union_eq\n\n/-- Assuming `G` is strongly regular, `2*(k + 1) - m` in `G` is the number of vertices that are\nadjacent to either `v` or `w` when `\u00acG.Adj v w`. So it's the cardinality of\n`G.neighborSet v \u222a G.neighborSet w`. -/\ntheorem IsSRGWith.card_neighborFinset_union_of_not_adj {v w : V} (h : G.IsSRGWith n k \u2113 \u03bc)\n    (hne : v \u2260 w) (ha : \u00acG.Adj v w) :\n    (G.neighborFinset v \u222a G.neighborFinset w).card = 2 * k - \u03bc := by\n  rw [\u2190 h.of_not_adj v w hne ha]\n  apply h.card_neighborFinset_union_eq\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.card_neighbor_finset_union_of_not_adj SimpleGraph.IsSRGWith.card_neighborFinset_union_of_not_adj\n\ntheorem IsSRGWith.card_neighborFinset_union_of_adj {v w : V} (h : G.IsSRGWith n k \u2113 \u03bc)\n    (ha : G.Adj v w) : (G.neighborFinset v \u222a G.neighborFinset w).card = 2 * k - \u2113 := by\n  rw [\u2190 h.of_adj v w ha]\n  apply h.card_neighborFinset_union_eq\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.card_neighbor_finset_union_of_adj SimpleGraph.IsSRGWith.card_neighborFinset_union_of_adj\n\ntheorem compl_neighborFinset_sdiff_inter_eq {v w : V} :\n    G.neighborFinset v\u1d9c \\ {v} \u2229 (G.neighborFinset w\u1d9c \\ {w}) =\n      (G.neighborFinset v\u1d9c \u2229 G.neighborFinset w\u1d9c) \\ ({w} \u222a {v}) := by\n  ext\n  rw [\u2190 not_iff_not]\n  simp [imp_iff_not_or, or_assoc, or_comm, or_left_comm]\n#align simple_graph.compl_neighbor_finset_sdiff_inter_eq SimpleGraph.compl_neighborFinset_sdiff_inter_eq\n\ntheorem sdiff_compl_neighborFinset_inter_eq {v w : V} (h : G.Adj v w) :\n    (G.neighborFinset v\u1d9c \u2229 G.neighborFinset w\u1d9c) \\ ({w} \u222a {v}) =\n      G.neighborFinset v\u1d9c \u2229 G.neighborFinset w\u1d9c := by\n  ext\n  simp only [and_imp, mem_union, mem_sdiff, mem_compl, and_iff_left_iff_imp, mem_neighborFinset,\n    mem_inter, mem_singleton]\n  rintro hnv hnw (rfl | rfl)\n  \u00b7 exact hnv h\n  \u00b7 apply hnw\n    rwa [adj_comm]\n#align simple_graph.sdiff_compl_neighbor_finset_inter_eq SimpleGraph.sdiff_compl_neighborFinset_inter_eq\n\ntheorem IsSRGWith.compl_is_regular (h : G.IsSRGWith n k \u2113 \u03bc) :\n  G\u1d9c.IsRegularOfDegree (n - k - 1) := by\n  rw [\u2190 h.card, Nat.sub_sub, add_comm, \u2190 Nat.sub_sub]\n  exact h.regular.compl\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.compl_is_regular SimpleGraph.IsSRGWith.compl_is_regular\n\ntheorem IsSRGWith.card_commonNeighbors_eq_of_adj_compl (h : G.IsSRGWith n k \u2113 \u03bc) {v w : V}\n    (ha : G\u1d9c.Adj v w) : Fintype.card (\u21a5(G\u1d9c.commonNeighbors v w)) = n - (2 * k - \u03bc) - 2 := by\n  simp only [\u2190 Set.toFinset_card, commonNeighbors, Set.toFinset_inter, neighborSet_compl,\n    Set.toFinset_diff, Set.toFinset_singleton, Set.toFinset_compl, \u2190 neighborFinset_def]\n  simp_rw [compl_neighborFinset_sdiff_inter_eq]\n  have hne : v \u2260 w := ne_of_adj _ ha\n  rw [compl_adj] at ha\n  rw [card_sdiff, \u2190 insert_eq, card_insert_of_not_mem, card_singleton, \u2190 Finset.compl_union]\n  \u00b7 rw [card_compl, h.card_neighborFinset_union_of_not_adj hne ha.2, \u2190 h.card]\n  \u00b7 simp only [hne.symm, not_false_iff, mem_singleton]\n  \u00b7 intro u\n    simp only [mem_union, mem_compl, mem_neighborFinset, mem_inter, mem_singleton]\n    rintro (rfl | rfl) <;> simpa [adj_comm] using ha.2\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.card_common_neighbors_eq_of_adj_compl SimpleGraph.IsSRGWith.card_commonNeighbors_eq_of_adj_compl\n\ntheorem IsSRGWith.card_commonNeighbors_eq_of_not_adj_compl (h : G.IsSRGWith n k \u2113 \u03bc) {v w : V}\n    (hn : v \u2260 w) (hna : \u00acG\u1d9c.Adj v w) :\n    Fintype.card (\u21a5G\u1d9c.commonNeighbors v w) = n - (2 * k - \u2113) := by\n  simp only [\u2190 Set.toFinset_card, commonNeighbors, Set.toFinset_inter, neighborSet_compl,\n    Set.toFinset_diff, Set.toFinset_singleton, Set.toFinset_compl, \u2190 neighborFinset_def]\n  simp only [not_and, Classical.not_not, compl_adj] at hna\n  have h2' := hna hn\n  simp_rw [compl_neighborFinset_sdiff_inter_eq, sdiff_compl_neighborFinset_inter_eq h2']\n  rwa [\u2190 Finset.compl_union, card_compl, h.card_neighborFinset_union_of_adj, \u2190 h.card]\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.card_common_neighbors_eq_of_not_adj_compl SimpleGraph.IsSRGWith.card_commonNeighbors_eq_of_not_adj_compl\n\n/-- The complement of a strongly regular graph is strongly regular. -/\ntheorem IsSRGWith.compl (h : G.IsSRGWith n k \u2113 \u03bc) :\n    G\u1d9c.IsSRGWith n (n - k - 1) (n - (2 * k - \u03bc) - 2) (n - (2 * k - \u2113)) where\n  card := h.card\n  regular := h.compl_is_regular\n  of_adj := fun _v _w ha => h.card_commonNeighbors_eq_of_adj_compl ha\n  of_not_adj := fun _v _w hn hna => h.card_commonNeighbors_eq_of_not_adj_compl hn hna\nset_option linter.uppercaseLean3 false in\n#align simple_graph.is_SRG_with.compl SimpleGraph.IsSRGWith.compl\n\nend SimpleGraph\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/SimpleGraph/StronglyRegular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759583, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7345126571987091}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport algebra.big_operators.order\nimport data.nat.interval\nimport data.nat.prime\n\n/-!\n# Divisor finsets\n\nThis file defines sets of divisors of a natural number. This is particularly useful as background\nfor defining Dirichlet convolution.\n\n## Main Definitions\nLet `n : \u2115`. All of the following definitions are in the `nat` namespace:\n * `divisors n` is the `finset` of natural numbers that divide `n`.\n * `proper_divisors n` is the `finset` of natural numbers that divide `n`, other than `n`.\n * `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n * `perfect n` is true when `n` is positive and the sum of `proper_divisors n` is `n`.\n\n## Implementation details\n * `divisors 0`, `proper_divisors 0`, and `divisors_antidiagonal 0` are defined to be `\u2205`.\n\n## Tags\ndivisors, perfect numbers\n\n-/\n\nopen_locale classical\nopen_locale big_operators\nopen finset\n\nnamespace nat\nvariable (n : \u2115)\n\n/-- `divisors n` is the `finset` of divisors of `n`. As a special case, `divisors 0 = \u2205`. -/\ndef divisors : finset \u2115 := finset.filter (\u03bb x : \u2115, x \u2223 n) (finset.Ico 1 (n + 1))\n\n/-- `proper_divisors n` is the `finset` of divisors of `n`, other than `n`.\n  As a special case, `proper_divisors 0 = \u2205`. -/\ndef proper_divisors : finset \u2115 := finset.filter (\u03bb x : \u2115, x \u2223 n) (finset.Ico 1 n)\n\n/-- `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n  As a special case, `divisors_antidiagonal 0 = \u2205`. -/\ndef divisors_antidiagonal : finset (\u2115 \u00d7 \u2115) :=\n((finset.Ico 1 (n + 1)).product (finset.Ico 1 (n + 1))).filter (\u03bb x, x.fst * x.snd = n)\n\nvariable {n}\n\n@[simp]\nlemma filter_dvd_eq_divisors (h : n \u2260 0) :\n  (finset.range n.succ).filter (\u2223 n) = n.divisors :=\nbegin\n  ext,\n  simp only [divisors, mem_filter, mem_range, mem_Ico, and.congr_left_iff, iff_and_self],\n  exact \u03bb ha _, succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt),\nend\n\n@[simp]\nlemma filter_dvd_eq_proper_divisors (h : n \u2260 0) :\n  (finset.range n).filter (\u2223 n) = n.proper_divisors :=\nbegin\n  ext,\n  simp only [proper_divisors, mem_filter, mem_range, mem_Ico, and.congr_left_iff, iff_and_self],\n  exact \u03bb ha _, succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt),\nend\n\nlemma proper_divisors.not_self_mem : \u00ac n \u2208 proper_divisors n :=\nby simp [proper_divisors]\n\n@[simp]\nlemma mem_proper_divisors {m : \u2115} : n \u2208 proper_divisors m \u2194 n \u2223 m \u2227 n < m :=\nbegin\n  rcases eq_or_ne m 0 with rfl | hm, { simp [proper_divisors] },\n  simp only [and_comm, \u2190filter_dvd_eq_proper_divisors hm, mem_filter, mem_range],\nend\n\nlemma divisors_eq_proper_divisors_insert_self_of_pos (h : 0 < n):\n  divisors n = has_insert.insert n (proper_divisors n) :=\nby rw [divisors, proper_divisors, Ico_succ_right_eq_insert_Ico h, finset.filter_insert,\n  if_pos (dvd_refl n)]\n\n@[simp]\nlemma mem_divisors {m : \u2115} : n \u2208 divisors m \u2194 (n \u2223 m \u2227 m \u2260 0) :=\nbegin\n  rcases eq_or_ne m 0 with rfl | hm, { simp [divisors] },\n  simp only [hm, ne.def, not_false_iff, and_true, \u2190filter_dvd_eq_divisors hm, mem_filter,\n    mem_range, and_iff_right_iff_imp, lt_succ_iff],\n  exact le_of_dvd hm.bot_lt,\nend\n\nlemma mem_divisors_self (n : \u2115) (h : n \u2260 0) : n \u2208 n.divisors := mem_divisors.2 \u27e8dvd_rfl, h\u27e9\n\nlemma dvd_of_mem_divisors {m : \u2115} (h : n \u2208 divisors m) : n \u2223 m :=\nbegin\n  cases m,\n  { apply dvd_zero },\n  { simp [mem_divisors.1 h], }\nend\n\n@[simp]\nlemma mem_divisors_antidiagonal {x : \u2115 \u00d7 \u2115} :\n  x \u2208 divisors_antidiagonal n \u2194 x.fst * x.snd = n \u2227 n \u2260 0 :=\nbegin\n  simp only [divisors_antidiagonal, finset.mem_Ico, ne.def, finset.mem_filter, finset.mem_product],\n  rw and_comm,\n  apply and_congr_right,\n  rintro rfl,\n  split; intro h,\n  { contrapose! h, simp [h], },\n  { rw [nat.lt_add_one_iff, nat.lt_add_one_iff],\n    rw [mul_eq_zero, decidable.not_or_iff_and_not] at h,\n    simp only [succ_le_of_lt (nat.pos_of_ne_zero h.1), succ_le_of_lt (nat.pos_of_ne_zero h.2),\n               true_and],\n    exact \u27e8le_mul_of_pos_right (nat.pos_of_ne_zero h.2),\n      le_mul_of_pos_left (nat.pos_of_ne_zero h.1)\u27e9 }\nend\n\nvariable {n}\n\nlemma divisor_le {m : \u2115}:\nn \u2208 divisors m \u2192 n \u2264 m :=\nbegin\n  cases m,\n  { simp },\n  simp only [mem_divisors, m.succ_ne_zero, and_true, ne.def, not_false_iff],\n  exact nat.le_of_dvd (nat.succ_pos m),\nend\n\nlemma divisors_subset_of_dvd {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) : divisors m \u2286 divisors n :=\nfinset.subset_iff.2 $ \u03bb x hx, nat.mem_divisors.mpr (\u27e8(nat.mem_divisors.mp hx).1.trans h, hzero\u27e9)\n\nlemma divisors_subset_proper_divisors {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) (hdiff : m \u2260 n) :\n  divisors m \u2286 proper_divisors n :=\nbegin\n  apply finset.subset_iff.2,\n  intros x hx,\n  exact nat.mem_proper_divisors.2 (\u27e8(nat.mem_divisors.1 hx).1.trans h,\n    lt_of_le_of_lt (divisor_le hx) (lt_of_le_of_ne (divisor_le (nat.mem_divisors.2\n    \u27e8h, hzero\u27e9)) hdiff)\u27e9)\nend\n\n@[simp]\nlemma divisors_zero : divisors 0 = \u2205 := by { ext, simp }\n\n@[simp]\nlemma proper_divisors_zero : proper_divisors 0 = \u2205 := by { ext, simp }\n\nlemma proper_divisors_subset_divisors : proper_divisors n \u2286 divisors n :=\nbegin\n  cases n,\n  { simp },\n  rw [divisors_eq_proper_divisors_insert_self_of_pos (nat.succ_pos _)],\n  apply subset_insert,\nend\n\n@[simp]\nlemma divisors_one : divisors 1 = {1} := by { ext, simp }\n\n@[simp]\nlemma proper_divisors_one : proper_divisors 1 = \u2205 :=\nbegin\n  ext,\n  simp only [finset.not_mem_empty, nat.dvd_one, not_and, not_lt, mem_proper_divisors, iff_false],\n  apply ge_of_eq,\nend\n\nlemma pos_of_mem_divisors {m : \u2115} (h : m \u2208 n.divisors) : 0 < m :=\nbegin\n  cases m,\n  { rw [mem_divisors, zero_dvd_iff] at h, cases h.2 h.1 },\n  apply nat.succ_pos,\nend\n\nlemma pos_of_mem_proper_divisors {m : \u2115} (h : m \u2208 n.proper_divisors) : 0 < m :=\npos_of_mem_divisors (proper_divisors_subset_divisors h)\n\nlemma one_mem_proper_divisors_iff_one_lt :\n  1 \u2208 n.proper_divisors \u2194 1 < n :=\nby rw [mem_proper_divisors, and_iff_right (one_dvd _)]\n\n@[simp]\nlemma divisors_antidiagonal_zero : divisors_antidiagonal 0 = \u2205 := by { ext, simp }\n\n@[simp]\nlemma divisors_antidiagonal_one : divisors_antidiagonal 1 = {(1,1)} :=\nby { ext, simp [nat.mul_eq_one_iff, prod.ext_iff], }\n\nlemma swap_mem_divisors_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n  x.swap \u2208 divisors_antidiagonal n :=\nbegin\n  rw [mem_divisors_antidiagonal, mul_comm] at h,\n  simp [h.1, h.2],\nend\n\n\n\nlemma snd_mem_divisors_of_mem_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n  x.snd \u2208 divisors n :=\nbegin\n  rw mem_divisors_antidiagonal at h,\n  simp [dvd.intro_left _ h.1, h.2],\nend\n\n@[simp]\nlemma map_swap_divisors_antidiagonal :\n  (divisors_antidiagonal n).map \u27e8prod.swap, prod.swap_right_inverse.injective\u27e9\n  = divisors_antidiagonal n :=\nbegin\n  ext,\n  simp only [exists_prop, mem_divisors_antidiagonal, finset.mem_map, function.embedding.coe_fn_mk,\n             ne.def, prod.swap_prod_mk, prod.exists],\n  split,\n  { rintros \u27e8x, y, \u27e8\u27e8rfl, h\u27e9, rfl\u27e9\u27e9,\n    simp [mul_comm, h], },\n  { rintros \u27e8rfl, h\u27e9,\n    use [a.snd, a.fst],\n    rw mul_comm,\n    simp [h] }\nend\n\nlemma sum_divisors_eq_sum_proper_divisors_add_self :\n\u2211 i in divisors n, i = \u2211 i in proper_divisors n, i + n :=\nbegin\n  cases n,\n  { simp },\n  { rw [divisors_eq_proper_divisors_insert_self_of_pos (nat.succ_pos _),\n        finset.sum_insert (proper_divisors.not_self_mem), add_comm] }\nend\n\n/-- `n : \u2115` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`\n  is positive. -/\ndef perfect (n : \u2115) : Prop := (\u2211 i in proper_divisors n, i = n) \u2227 0 < n\n\ntheorem perfect_iff_sum_proper_divisors (h : 0 < n) :\n  perfect n \u2194 \u2211 i in proper_divisors n, i = n := and_iff_left h\n\ntheorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) :\n  perfect n \u2194 \u2211 i in divisors n, i = 2 * n :=\nbegin\n  rw [perfect_iff_sum_proper_divisors h, sum_divisors_eq_sum_proper_divisors_add_self, two_mul],\n  split; intro h,\n  { rw h },\n  { apply add_right_cancel h }\nend\n\nlemma mem_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) {x : \u2115} :\n  x \u2208 divisors (p ^ k) \u2194 \u2203 (j : \u2115) (H : j \u2264 k), x = p ^ j :=\nby rw [mem_divisors, nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))]\n\nlemma prime.divisors {p : \u2115} (pp : p.prime) :\n  divisors p = {1, p} :=\nbegin\n  ext,\n  rw [mem_divisors, dvd_prime pp, and_iff_left pp.ne_zero, finset.mem_insert, finset.mem_singleton]\nend\n\nlemma prime.proper_divisors {p : \u2115} (pp : p.prime) :\n  proper_divisors p = {1} :=\nby rw [\u2190 erase_insert (proper_divisors.not_self_mem),\n    \u2190 divisors_eq_proper_divisors_insert_self_of_pos pp.pos,\n    pp.divisors, pair_comm, erase_insert (\u03bb con, pp.ne_one (mem_singleton.1 con))]\n\nlemma divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) :\n  divisors (p ^ k) = (finset.range (k + 1)).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\nby { ext, simp [mem_divisors_prime_pow, pp, nat.lt_succ_iff, @eq_comm _ a] }\n\nlemma eq_proper_divisors_of_subset_of_sum_eq_sum {s : finset \u2115} (hsub : s \u2286 n.proper_divisors) :\n  \u2211 x in s, x = \u2211 x in n.proper_divisors, x \u2192 s = n.proper_divisors :=\nbegin\n  cases n,\n  { rw [proper_divisors_zero, subset_empty] at hsub,\n    simp [hsub] },\n  classical,\n  rw [\u2190 sum_sdiff hsub],\n  intros h,\n  apply subset.antisymm hsub,\n  rw [\u2190 sdiff_eq_empty_iff_subset],\n  contrapose h,\n  rw [\u2190 ne.def, \u2190 nonempty_iff_ne_empty] at h,\n  apply ne_of_lt,\n  rw [\u2190 zero_add (\u2211 x in s, x), \u2190 add_assoc, add_zero],\n  apply add_lt_add_right,\n  have hlt := sum_lt_sum_of_nonempty h (\u03bb x hx, pos_of_mem_proper_divisors (sdiff_subset _ _ hx)),\n  simp only [sum_const_zero] at hlt,\n  apply hlt\nend\n\nlemma sum_proper_divisors_dvd (h : \u2211 x in n.proper_divisors, x \u2223 n) :\n  (\u2211 x in n.proper_divisors, x = 1) \u2228 (\u2211 x in n.proper_divisors, x = n) :=\nbegin\n  cases n,\n  { simp },\n  cases n,\n  { contrapose! h,\n    simp, },\n  rw or_iff_not_imp_right,\n  intro ne_n,\n  have hlt : \u2211 x in n.succ.succ.proper_divisors, x < n.succ.succ :=\n    lt_of_le_of_ne (nat.le_of_dvd (nat.succ_pos _) h) ne_n,\n  symmetry,\n  rw [\u2190 mem_singleton, eq_proper_divisors_of_subset_of_sum_eq_sum (singleton_subset_iff.2\n        (mem_proper_divisors.2 \u27e8h, hlt\u27e9)) sum_singleton, mem_proper_divisors],\n  refine \u27e8one_dvd _, nat.succ_lt_succ (nat.succ_pos _)\u27e9,\nend\n\n@[simp, to_additive]\nlemma prime.prod_proper_divisors {\u03b1 : Type*} [comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in p.proper_divisors, f x = f 1 :=\nby simp [h.proper_divisors]\n\n@[simp, to_additive]\nlemma prime.prod_divisors {\u03b1 : Type*} [comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in p.divisors, f x = f p * f 1 :=\nby rw [divisors_eq_proper_divisors_insert_self_of_pos h.pos,\n       prod_insert proper_divisors.not_self_mem, h.prod_proper_divisors]\n\nlemma proper_divisors_eq_singleton_one_iff_prime :\n  n.proper_divisors = {1} \u2194 n.prime :=\n\u27e8\u03bb h, begin\n  have h1 := mem_singleton.2 rfl,\n  rw [\u2190 h, mem_proper_divisors] at h1,\n  refine nat.prime_def_lt''.mpr \u27e8h1.2, \u03bb m hdvd, _\u27e9,\n  rw [\u2190 mem_singleton, \u2190 h, mem_proper_divisors],\n  have hle := nat.le_of_dvd (lt_trans (nat.succ_pos _) h1.2) hdvd,\n  exact or.imp_left (\u03bb hlt, \u27e8hdvd, hlt\u27e9) hle.lt_or_eq\nend, prime.proper_divisors\u27e9\n\nlemma sum_proper_divisors_eq_one_iff_prime :\n  \u2211 x in n.proper_divisors, x = 1 \u2194 n.prime :=\nbegin\n  cases n,\n  { simp [nat.not_prime_zero] },\n  cases n,\n  { simp [nat.not_prime_one] },\n  rw [\u2190 proper_divisors_eq_singleton_one_iff_prime],\n  refine \u27e8\u03bb h, _, \u03bb h, h.symm \u25b8 sum_singleton\u27e9,\n  rw [@eq_comm (finset \u2115) _ _],\n  apply eq_proper_divisors_of_subset_of_sum_eq_sum\n    (singleton_subset_iff.2 (one_mem_proper_divisors_iff_one_lt.2 (succ_lt_succ (nat.succ_pos _))))\n    (eq.trans sum_singleton h.symm)\nend\n\nlemma mem_proper_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) {x : \u2115} :\n  x \u2208 proper_divisors (p ^ k) \u2194 \u2203 (j : \u2115) (H : j < k), x = p ^ j :=\nbegin\n  rw [mem_proper_divisors, nat.dvd_prime_pow pp, \u2190 exists_and_distrib_right],\n  simp only [exists_prop, and_assoc],\n  apply exists_congr,\n  intro a,\n  split; intro h,\n  { rcases h with \u27e8h_left, rfl, h_right\u27e9,\n    rwa pow_lt_pow_iff pp.one_lt at h_right,\n    simpa, },\n  { rcases h with \u27e8h_left, rfl\u27e9,\n    rwa pow_lt_pow_iff pp.one_lt,\n    simp [h_left, le_of_lt], },\nend\n\nlemma proper_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) :\n  proper_divisors (p ^ k) = (finset.range k).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\nby { ext, simp [mem_proper_divisors_prime_pow, pp, nat.lt_succ_iff, @eq_comm _ a], }\n\n@[simp, to_additive]\nlemma prod_proper_divisors_prime_pow {\u03b1 : Type*} [comm_monoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1}\n  (h : p.prime) : \u220f x in (p ^ k).proper_divisors, f x = \u220f x in range k, f (p ^ x) :=\nby simp [h, proper_divisors_prime_pow]\n\n@[simp, to_additive sum_divisors_prime_pow]\nlemma prod_divisors_prime_pow {\u03b1 : Type*} [comm_monoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in (p ^ k).divisors, f x = \u220f x in range (k + 1), f (p ^ x) :=\nby simp [h, divisors_prime_pow]\n\n@[to_additive]\nlemma prod_divisors_antidiagonal {M : Type*} [comm_monoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n  \u220f i in n.divisors_antidiagonal, f i.1 i.2 = \u220f i in n.divisors, f i (n / i) :=\nbegin\n  refine prod_bij (\u03bb i _, i.1) _ _ _ _,\n  { intro i,\n    apply fst_mem_divisors_of_mem_antidiagonal },\n  { rintro \u27e8i, j\u27e9 hij,\n    simp only [mem_divisors_antidiagonal, ne.def] at hij,\n    rw [\u2190hij.1, nat.mul_div_cancel_left],\n    apply nat.pos_of_ne_zero,\n    rintro rfl,\n    simp only [zero_mul] at hij,\n    apply hij.2 hij.1.symm },\n  { simp only [and_imp, prod.forall, mem_divisors_antidiagonal, ne.def],\n    rintro i\u2081 j\u2081 \u27e8i\u2082, j\u2082\u27e9 h - (rfl : i\u2082 * j\u2082 = _) h\u2081 (rfl : _ = i\u2082),\n    simp only [nat.mul_eq_zero, not_or_distrib, \u2190ne.def] at h\u2081,\n    rw mul_right_inj' h\u2081.1 at h,\n    simp [h] },\n  simp only [and_imp, exists_prop, mem_divisors_antidiagonal, exists_and_distrib_right, ne.def,\n    exists_eq_right', mem_divisors, prod.exists],\n  rintro _ \u27e8k, rfl\u27e9 hn,\n  exact \u27e8\u27e8k, rfl\u27e9, hn\u27e9,\nend\n\n@[to_additive]\nlemma prod_divisors_antidiagonal' {M : Type*} [comm_monoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n  \u220f i in n.divisors_antidiagonal, f i.1 i.2 = \u220f i in n.divisors, f (n / i) i :=\nbegin\n  rw [\u2190map_swap_divisors_antidiagonal, finset.prod_map],\n  exact prod_divisors_antidiagonal (\u03bb i j, f j i),\nend\n\n/-- The factors of `n` are the prime divisors -/\nlemma prime_divisors_eq_to_filter_divisors_prime (n : \u2115) :\n  n.factors.to_finset = (divisors n).filter prime :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { simp },\n  { ext q,\n    simpa [hn, hn.ne', mem_factors] using and_comm (prime q) (q \u2223 n) }\nend\n\n@[simp]\nlemma image_div_divisors_eq_divisors (n : \u2115) : image (\u03bb (x : \u2115), n / x) n.divisors = n.divisors :=\nbegin\n  by_cases hn : n = 0, { simp [hn] },\n  ext,\n  split,\n  { rw mem_image,\n    rintros \u27e8x, hx1, hx2\u27e9,\n    rw mem_divisors at *,\n    refine \u27e8_,hn\u27e9,\n    rw \u2190hx2,\n    exact div_dvd_of_dvd hx1.1 },\n  { rw [mem_divisors, mem_image],\n    rintros \u27e8h1, -\u27e9,\n    exact \u27e8n/a, mem_divisors.mpr \u27e8div_dvd_of_dvd h1, hn\u27e9,\n           nat.div_div_self h1 (pos_iff_ne_zero.mpr hn)\u27e9 },\nend\n\n@[simp, to_additive sum_div_divisors]\nlemma prod_div_divisors {\u03b1 : Type*} [comm_monoid \u03b1] (n : \u2115) (f : \u2115 \u2192 \u03b1) :\n  \u220f d in n.divisors, f (n/d) = n.divisors.prod f :=\nbegin\n  by_cases hn : n = 0, { simp [hn] },\n  rw \u2190prod_image,\n  { exact prod_congr (image_div_divisors_eq_divisors n) (by simp) },\n  { intros x hx y hy h,\n    rw mem_divisors at hx hy,\n    exact (div_eq_iff_eq_of_dvd_dvd hn hx.1 hy.1).mp h }\nend\n\nend nat\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/number_theory/divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7345126545532098}}
{"text": "/-\nCopyright (c) 2022 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n-/\nimport analysis.special_functions.log\nimport analysis.special_functions.pow\n\n/-!\n# Real logarithm base `b`\n\nIn this file we define `real.logb` to be the logarithm of a real number in a given base `b`. We\ndefine this as the division of the natural logarithms of the argument and the base, so that we have\na globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and\n`logb (-b) x = logb b x`.\n\nWe prove some basic properties of this function and it's relation to `rpow`.\n\n## Tags\n\nlogarithm, continuity\n-/\n\nopen set filter function\nopen_locale topological_space\nnoncomputable theory\n\nnamespace real\n\nvariables {b x y : \u211d}\n\n/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to\nbe `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/\n@[pp_nodot] noncomputable def logb (b x : \u211d) : \u211d := log x / log b\n\nlemma log_div_log : log x / log b = logb b x := rfl\n\n@[simp] lemma logb_zero : logb b 0 = 0 := by simp [logb]\n\n@[simp] lemma logb_one : logb b 1 = 0 := by simp [logb]\n\n@[simp] lemma logb_abs (x : \u211d) : logb b (|x|) = logb b x := by rw [logb, logb, log_abs]\n\n@[simp] lemma logb_neg_eq_logb (x : \u211d) : logb b (-x) = logb b x :=\nby rw [\u2190 logb_abs x, \u2190 logb_abs (-x), abs_neg]\n\nlemma logb_mul (hx : x \u2260 0) (hy : y \u2260 0) : logb b (x * y) = logb b x + logb b y :=\nby simp_rw [logb, log_mul hx hy, add_div]\n\nlemma logb_div (hx : x \u2260 0) (hy : y \u2260 0) : logb b (x / y) = logb b x - logb b y :=\nby simp_rw [logb, log_div hx hy, sub_div]\n\n@[simp] lemma logb_inv (x : \u211d) : logb b (x\u207b\u00b9) = -logb b x := by simp [logb, neg_div]\n\nsection b_pos_and_ne_one\n\nvariable (b_pos : 0 < b)\nvariable (b_ne_one : b \u2260 1)\ninclude b_pos b_ne_one\n\nprivate lemma log_b_ne_zero : log b \u2260 0 :=\nbegin\n  have b_ne_zero : b \u2260 0, linarith,\n  have b_ne_minus_one : b \u2260 -1, linarith,\n  simp [b_ne_one, b_ne_zero, b_ne_minus_one],\nend\n\n@[simp] lemma logb_rpow :\n  logb b (b ^ x) = x :=\nbegin\n  rw [logb, div_eq_iff, log_rpow b_pos],\n  exact log_b_ne_zero b_pos b_ne_one,\nend\n\nlemma rpow_logb_eq_abs (hx : x \u2260 0) : b ^ (logb b x) = |x| :=\nbegin\n  apply log_inj_on_pos,\n  simp only [set.mem_Ioi],\n  apply rpow_pos_of_pos b_pos,\n  simp only [abs_pos, mem_Ioi, ne.def, hx, not_false_iff],\n  rw [log_rpow b_pos, logb, log_abs],\n  field_simp [log_b_ne_zero b_pos b_ne_one],\nend\n\n@[simp] lemma rpow_logb (hx : 0 < x) : b ^ (logb b x) = x :=\nby { rw rpow_logb_eq_abs b_pos b_ne_one (hx.ne'), exact abs_of_pos hx, }\n\nlemma rpow_logb_of_neg (hx : x < 0) : b ^ (logb b x) = -x :=\nby { rw rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx), exact abs_of_neg hx }\n\nlemma surj_on_logb : surj_on (logb b) (Ioi 0) univ :=\n\u03bb x _, \u27e8rpow b x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one\u27e9\n\nlemma logb_surjective : surjective (logb b) :=\n\u03bb x, \u27e8b ^ x, logb_rpow b_pos b_ne_one\u27e9\n\n@[simp] lemma range_logb : range (logb b) = univ :=\n(logb_surjective b_pos b_ne_one).range_eq\n\nlemma surj_on_logb' : surj_on (logb b) (Iio 0) univ :=\nbegin\n  intros x x_in_univ,\n  use -b ^ x,\n  split,\n  { simp only [right.neg_neg_iff, set.mem_Iio], apply rpow_pos_of_pos b_pos, },\n  { rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one], },\nend\n\nend b_pos_and_ne_one\n\nsection one_lt_b\n\nvariable (hb : 1 < b)\ninclude hb\n\nprivate lemma b_pos : 0 < b := by linarith\n\nprivate lemma b_ne_one : b \u2260 1 := by linarith\n\n@[simp] lemma logb_le_logb (h : 0 < x) (h\u2081 : 0 < y) :\n  logb b x \u2264 logb b y \u2194 x \u2264 y :=\nby { rw [logb, logb, div_le_div_right (log_pos hb), log_le_log h h\u2081], }\n\nlemma logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y :=\nby { rw [logb, logb, div_lt_div_right (log_pos hb)], exact log_lt_log hx hxy, }\n\n@[simp] lemma logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) :\n  logb b x < logb b y \u2194 x < y :=\nby { rw [logb, logb, div_lt_div_right (log_pos hb)], exact log_lt_log_iff hx hy, }\n\nlemma logb_le_iff_le_rpow (hx : 0 < x) : logb b x \u2264 y \u2194 x \u2264 b ^ y :=\nby rw [\u2190rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hx]\n\nlemma logb_lt_iff_lt_rpow (hx : 0 < x) : logb b x < y \u2194 x < b ^ y :=\nby rw [\u2190rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hx]\n\nlemma le_logb_iff_rpow_le (hy : 0 < y) : x \u2264 logb b y \u2194 b ^ x \u2264 y :=\nby rw [\u2190rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hy]\n\nlemma lt_logb_iff_rpow_lt (hy : 0 < y) : x < logb b y \u2194 b ^ x < y :=\nby rw [\u2190rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hy]\n\nlemma logb_pos_iff (hx : 0 < x) : 0 < logb b x \u2194 1 < x :=\nby { rw \u2190 @logb_one b, rw logb_lt_logb_iff hb zero_lt_one hx, }\n\nlemma logb_pos (hx : 1 < x) : 0 < logb b x :=\nby { rw logb_pos_iff hb (lt_trans zero_lt_one hx), exact hx, }\n\nlemma logb_neg_iff (h : 0 < x) : logb b x < 0 \u2194 x < 1 :=\nby { rw \u2190 logb_one, exact logb_lt_logb_iff hb h zero_lt_one, }\n\nlemma logb_neg (h0 : 0 < x) (h1 : x < 1) : logb b x < 0 :=\n(logb_neg_iff hb h0).2 h1\n\nlemma logb_nonneg_iff (hx : 0 < x) : 0 \u2264 logb b x \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, logb_neg_iff hb hx, not_lt]\n\nlemma logb_nonneg (hx : 1 \u2264 x) : 0 \u2264 logb b x :=\n(logb_nonneg_iff hb (zero_lt_one.trans_le hx)).2 hx\n\nlemma logb_nonpos_iff (hx : 0 < x) : logb b x \u2264 0 \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, logb_pos_iff hb hx, not_lt]\n\nlemma logb_nonpos_iff' (hx : 0 \u2264 x) : logb b x \u2264 0 \u2194 x \u2264 1 :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { simp [le_refl, zero_le_one] },\n  exact logb_nonpos_iff hb hx,\nend\n\nlemma logb_nonpos (hx : 0 \u2264 x) (h'x : x \u2264 1) : logb b x \u2264 0 :=\n(logb_nonpos_iff' hb hx).2 h'x\n\nlemma strict_mono_on_logb : strict_mono_on (logb b) (set.Ioi 0) :=\n\u03bb x hx y hy hxy, logb_lt_logb hb hx hxy\n\nlemma strict_anti_on_logb : strict_anti_on (logb b) (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 logb_abs y, \u2190 logb_abs x],\n  refine logb_lt_logb hb (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff],\nend\n\nlemma logb_inj_on_pos : set.inj_on (logb b) (set.Ioi 0) :=\n(strict_mono_on_logb hb).inj_on\n\nlemma eq_one_of_pos_of_logb_eq_zero (h\u2081 : 0 < x) (h\u2082 : logb b x = 0) :\nx = 1 :=\nlogb_inj_on_pos hb (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one)\n  (h\u2082.trans real.logb_one.symm)\n\nlemma logb_ne_zero_of_pos_of_ne_one (hx_pos : 0 < x) (hx : x \u2260 1) :\n  logb b x \u2260 0 :=\nmt (eq_one_of_pos_of_logb_eq_zero hb hx_pos) hx\n\nlemma tendsto_logb_at_top : tendsto (logb b) at_top at_top :=\ntendsto.at_top_div_const (log_pos hb) tendsto_log_at_top\n\nend one_lt_b\n\nsection b_pos_and_b_lt_one\n\nvariable (b_pos : 0 < b)\nvariable (b_lt_one : b < 1)\ninclude b_lt_one\n\nprivate lemma b_ne_one : b \u2260 1 := by linarith\n\ninclude b_pos\n\n@[simp] lemma logb_le_logb_of_base_lt_one (h : 0 < x) (h\u2081 : 0 < y) :\n  logb b x \u2264 logb b y \u2194 y \u2264 x :=\nby { rw [logb, logb, div_le_div_right_of_neg (log_neg b_pos b_lt_one), log_le_log h\u2081 h], }\n\nlemma logb_lt_logb_of_base_lt_one (hx : 0 < x) (hxy : x < y) : logb b y < logb b x :=\nby { rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)], exact log_lt_log hx hxy, }\n\n@[simp] lemma logb_lt_logb_iff_of_base_lt_one (hx : 0 < x) (hy : 0 < y) :\n  logb b x < logb b y \u2194 y < x :=\nby { rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)], exact log_lt_log_iff hy hx }\n\nlemma logb_le_iff_le_rpow_of_base_lt_one (hx : 0 < x) : logb b x \u2264 y \u2194 b ^ y \u2264 x :=\nby rw [\u2190rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]\n\nlemma logb_lt_iff_lt_rpow_of_base_lt_one (hx : 0 < x) : logb b x < y \u2194 b ^ y < x :=\nby rw [\u2190rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]\n\nlemma le_logb_iff_rpow_le_of_base_lt_one (hy : 0 < y) : x \u2264 logb b y \u2194 y \u2264 b ^ x :=\nby rw [\u2190rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]\n\nlemma lt_logb_iff_rpow_lt_of_base_lt_one (hy : 0 < y) : x < logb b y \u2194 y < b ^ x :=\nby rw [\u2190rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]\n\nlemma logb_pos_iff_of_base_lt_one (hx : 0 < x) : 0 < logb b x \u2194 x < 1 :=\nby rw [\u2190 @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one zero_lt_one hx]\n\nlemma logb_pos_of_base_lt_one (hx : 0 < x) (hx' : x < 1) : 0 < logb b x :=\nby { rw logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, exact hx', }\n\nlemma logb_neg_iff_of_base_lt_one (h : 0 < x) : logb b x < 0 \u2194 1 < x :=\nby rw [\u2190 @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one h zero_lt_one]\n\nlemma logb_neg_of_base_lt_one (h1 : 1 < x) : logb b x < 0 :=\n(logb_neg_iff_of_base_lt_one b_pos b_lt_one (lt_trans zero_lt_one h1)).2 h1\n\nlemma logb_nonneg_iff_of_base_lt_one (hx : 0 < x) : 0 \u2264 logb b x \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, logb_neg_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]\n\nlemma logb_nonneg_of_base_lt_one (hx : 0 < x) (hx' : x \u2264 1) : 0 \u2264 logb b x :=\nby {rw [logb_nonneg_iff_of_base_lt_one b_pos b_lt_one hx], exact hx' }\n\nlemma logb_nonpos_iff_of_base_lt_one (hx : 0 < x) : logb b x \u2264 0 \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]\n\nlemma strict_anti_on_logb_of_base_lt_one : strict_anti_on (logb b) (set.Ioi 0) :=\n\u03bb x hx y hy hxy, logb_lt_logb_of_base_lt_one b_pos b_lt_one hx hxy\n\nlemma strict_mono_on_logb_of_base_lt_one : strict_mono_on (logb b) (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 logb_abs y, \u2190 logb_abs x],\n  refine logb_lt_logb_of_base_lt_one b_pos b_lt_one (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff],\nend\n\nlemma logb_inj_on_pos_of_base_lt_one : set.inj_on (logb b) (set.Ioi 0) :=\n(strict_anti_on_logb_of_base_lt_one b_pos b_lt_one).inj_on\n\nlemma eq_one_of_pos_of_logb_eq_zero_of_base_lt_one (h\u2081 : 0 < x) (h\u2082 : logb b x = 0) :\nx = 1 :=\nlogb_inj_on_pos_of_base_lt_one b_pos b_lt_one (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one)\n  (h\u2082.trans real.logb_one.symm)\n\nlemma logb_ne_zero_of_pos_of_ne_one_of_base_lt_one (hx_pos : 0 < x) (hx : x \u2260 1) :\n  logb b x \u2260 0 :=\nmt (eq_one_of_pos_of_logb_eq_zero_of_base_lt_one b_pos b_lt_one hx_pos) hx\n\nlemma tendsto_logb_at_top_of_base_lt_one : tendsto (logb b) at_top at_bot :=\nbegin\n  rw tendsto_at_top_at_bot,\n  intro e,\n  use 1 \u2294 b ^ e,\n  intro a,\n  simp only [and_imp, sup_le_iff],\n  intro ha,\n  rw logb_le_iff_le_rpow_of_base_lt_one b_pos b_lt_one,\n  tauto,\n  exact lt_of_lt_of_le zero_lt_one ha,\nend\n\nend b_pos_and_b_lt_one\n\n@[simp] lemma logb_eq_zero :\n  logb b x = 0 \u2194 b = 0 \u2228 b = 1 \u2228 b = -1 \u2228 x = 0 \u2228 x = 1 \u2228 x = -1 :=\nbegin\n  simp_rw [logb, div_eq_zero_iff, log_eq_zero],\n  tauto,\nend\n\n/- TODO add other limits and continuous API lemmas analogous to those in log.lean -/\n\nopen_locale big_operators\n\nlemma logb_prod {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) (hf : \u2200 x \u2208 s, f x \u2260 0):\n  logb b (\u220f i in s, f i) = \u2211 i in s, logb b (f i) :=\nbegin\n  classical,\n  induction s using finset.induction_on with a s ha ih,\n  { simp },\n  simp only [finset.mem_insert, forall_eq_or_imp] at hf,\n  simp [ha, ih hf.2, logb_mul hf.1 (finset.prod_ne_zero_iff.2 hf.2)],\nend\n\nend real\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/special_functions/logb.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7345126545532098}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport linear_algebra.basis -- basis of a vector space\nimport linear_algebra.matrix.to_lin -- relationship between matrices and linear maps\n/-!\n\n# Basis of a vector space\n\nPlan: \n\n1) If V,W are based vector spaces then matrices = linear maps\n\n2) change of basis\n\n-/\n\n\n\n-- Let V be a vector space over a field k\nvariables (k : Type) [field k] (V : Type) [add_comm_group V] [module k V]\n\n/-\n\nWhat *is* a basis for a vector space `V`? Mathematicians use the term to mean two\ndifferent things! Sometimes it's a subset of `V` (this is particularly common\nif `V` is infinite-dimensional) and sometimes it's a *list* `[e\u2081, e\u2082, ..., e\u2099]`.\nThe issue is whether the basis is *indexed* or not. In `mathlib`, bases are\nindexed, so we have an index type (e.g. `{1,2,3,...,n}`) and a basis\nis a function from this type to `V` satisfying the axioms for a basis.\n\n-/\n\n-- Let `B` be a `k`-basis for `V` indexed by `I`.\nvariables (I : Type) (B : basis I k V)\n\n-- Lean is allowing for the possibility that `I` is infinite, which makes\n-- the theory noncomputable, so let's switch on non-computable mathematics\n\nnoncomputable theory\n\n-- (I always do this when Lean complains something is not computable; this doesn't\n-- mean that you can't do maths with it, it means that we're asking Lean to do things\n-- for which there is no algorithm (e.g. picking a basis, especially in the infinite-dimensional\n-- case)\n\n-- If `(i : I)` then the basis element of `V` corresponding to `i` (i.e. the element e\u1d62 if\n-- you're imagining i={1,2,3,...,n}) is `B i`\n\nvariable (i : I)\n\nexample : V := B i\n\n-- A general element of V is uniquely a `k`-linear combination of elements of the basis.\n-- In the finite-dimensional case we just write v = \u2211\u1d62 c\u1d62e\u1d62. In the infinite-dimensional\n-- case a basis will be infinite, but you can't take infinite sums so from `v` we should\n-- expect to see a finitely-supported function on `I`, i.e., an element of `I \u2192\u2080 k`.\n-- Given a basis `B` with index set `I`, the function `basis.repr B`, or `B.repr`,\n-- is the `k`-linear isomorphism from `V` to these finitely-supported functions.\n\nexample : V \u2243\u2097[k] (I \u2192\u2080 k) := B.repr\n\n-- If `I` is finite, then you can use the space of all functions `I \u2192 k` (because they're\n-- all finitely-supported) but because `I \u2192\u2080 k` isn't *equal* to `I \u2192 k` (they're just\n-- in bijection when `I` is finite) we need a different function to do this.\n\nexample [fintype I] : V \u2243\u2097[k] (I \u2192 k) := B.equiv_fun \n\n-- If you want to see the coefficient of `B i` in the expansion of `v` in terms\n-- of the basis `B`, you can write\n\nexample (v : V) : k := B.repr v i\n\n-- Again if `I` is finite, you can reconstruct `v` as `\u2211 B.repr v i \u2022 B i`, a sum over all `i`.\n\n-- allow notation for sums\nopen_locale big_operators\n\nexample [fintype I] (v : V) : \u2211 i, B.repr v i \u2022 B i = v := B.sum_repr v\n\n-- You can also use `B.coord i`, which is the linear map from `V` to `k` sending a vector `V`\n-- to the coefficient of `B i`\n\nexample : V \u2192\u2097[k] k := B.coord i\n\n-- Now let `W` be another `k`-vector space\nvariables (W : Type) [add_comm_group W] [module k W]\n\n-- Let's prove that any map `f` from `I` to `W` extends uniquely to a linear map `\u03c6` from `V` to `W`\n-- such that forall `i : I`, `f i = \u03c6 (B i)`.\n\n-- The two pieces of API you'll need:\n\n-- the extension of `f : I \u2192 W` to a `k`-linear map `V \u2192\u2096[W]` is `basis.constr B k f`\nexample (f : I \u2192 W) : V \u2192\u2097[k] W := B.constr k f \n\n-- The theorem that `B.constr k f` agrees with `f` (in the sense that `B.constr k f (B i) = f i`\n-- is `basis.constr_basis B k f i`\nexample (f : I \u2192 W) (i : I) : B.constr k f (B i) = f i := B.constr_basis k f i\n\n-- Finally, `basis.ext` is the theorem that two linear maps are equal if they agree\n-- on a basis of the source\nexample (\u03c6 \u03c8 : V \u2192\u2097[k] W) (h : \u2200 (i : I), \u03c6 (B i) = \u03c8 (B i)) : \u03c6 = \u03c8 := B.ext h\n\n-- That should be all you need to do this!\nexample (f : I \u2192 W) : \u2203! \u03c6 : V \u2192\u2097[k] W, \u2200 i, \u03c6 (B i) = f i :=\nbegin\n  sorry,\nend\n\n-- Now say `C` is a basis of `W`, indexed by a type `J`\nvariables (J : Type) (C : basis J k W)\n\n-- If everything is finite-dimensional\nvariables [fintype I] [fintype J]\n\n-- then linear maps from `V` to `W` are the same as matrices with rows \n-- indexed by `I` and columns indexed by `J`\n\nopen_locale classical -- apparently something isn't constructive here?\n\nexample : (V \u2192\u2097[k] W) \u2243\u2097[k] matrix J I k := linear_map.to_matrix B C\n\n-- check that this bijection does give what we expect. \n-- Right-click on `linear_map.to_matrix` and then \"go to definition\" to find\n-- the API for `linear_map.to_matrix`. \n\nexample (\u03c6 : V \u2192\u2097[k] W) (i : I) (j : J) : linear_map.to_matrix B C \u03c6 j i = C.repr (\u03c6 (B i)) j :=\nsorry\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section11vector_spaces/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7345126412147682}}
{"text": "import tactic\n\nset_option pp.generalized_field_notation false\n\nopen nat\n\nnamespace training\n\ndef powerOf2 : \u2115 \u2192 \u2115\n| 0     := 1\n| (n+1) := 2 * powerOf2 n\n\nlemma lowerBoundPowerOf2 (n : \u2115) :\n  1 \u2264 powerOf2 n :=\nbegin\n  induction n; simp [powerOf2], linarith,\nend\n\nlemma sumSamePowerOf2 (n : \u2115) :\n  powerOf2 n + powerOf2 n == 2 * powerOf2 n :=\nby ring\n\nlemma monotonicPowerOf2 :\n  \u2200 {n m}, n \u2264 m \u2192 powerOf2 n \u2264 powerOf2 m\n| 0     m     le := lowerBoundPowerOf2 m\n| (n+1) 0     le := by cases le\n| (n+1) (m+1) le := begin simp [powerOf2], apply monotonicPowerOf2, linarith, end\n\nlemma addPowerOf2 (n m : \u2115) :\n  powerOf2 n * powerOf2 m = powerOf2 (n + m) :=\nbegin\n  induction n; simp [powerOf2], rw [mul_assoc, n_ih, succ_add], simp [powerOf2],\nend\n\ninductive tree : Type\n| leaf : tree\n| node : tree \u2192 tree \u2192 tree\n\nnamespace tree\n\ndef height : tree \u2192 \u2115\n| leaf       := 1\n| (node l r) := max (height l) (height r) + 1\n\ndef nodeCount : tree \u2192 \u2115\n| leaf       := 1\n| (node l r) := nodeCount l + nodeCount r + 1\n\ndef leafCount : tree \u2192 \u2115\n| leaf       := 1\n| (node l r) := leafCount l + leafCount r\n\n-- Move - 1 to LHS to avoid nat subtraction\n\nlemma upperboundForNodeCount (root : tree) :\n  nodeCount root + 1 \u2264 powerOf2 (height root) :=\nbegin\n  induction root with l r ih_l ih_r;\n  simp [height, nodeCount, powerOf2],\n  set hl := height l,\n  set hr := height r,\n  calc\n    nodeCount (node l r) + 1\n        = nodeCount l + nodeCount r + 1 + 1            : rfl\n    ... \u2264 powerOf2 hl + powerOf2 hr                    : by linarith\n    ... \u2264 powerOf2 (max hl hr) + powerOf2 (max hl hr)  :\n      by linarith [ monotonicPowerOf2 (le_max_left hl hr)\n                  , monotonicPowerOf2 (le_max_right hl hr) ]\n    ... = 2 * powerOf2 (max hl hr)                     : by ring\n    ... = powerOf2 (max hl hr + 1)                     : rfl\n    ... = powerOf2 (height (node l r))                 : rfl\nend\n\nend tree\n\nend training\n", "meta": {"author": "inkytonik", "repo": "lean-training", "sha": "7005c0ba8c8a87bd7ea8322926693dec26ec53ec", "save_path": "github-repos/lean/inkytonik-lean-training", "path": "github-repos/lean/inkytonik-lean-training/lean-training-7005c0ba8c8a87bd7ea8322926693dec26ec53ec/src/training2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7344769059553046}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n-/\nimport ring_theory.trace\nimport field_theory.finite.galois_field\n\n/-!\n# The trace map for finite fields\n\nWe state the fact that the trace map from a finite field of\ncharacteristic `p` to `zmod p` is nondegenerate.\n\n## Tags\nfinite field, trace\n-/\n\nnamespace finite_field\n\n/-- The trace map from a finite field to its prime field is nongedenerate. -/\nlemma trace_to_zmod_nondegenerate (F : Type*) [field F] [finite F] {a : F}\n (ha : a \u2260 0) : \u2203 b : F, algebra.trace (zmod (ring_char F)) F (a * b) \u2260 0 :=\nbegin\n  haveI : fact (ring_char F).prime := \u27e8char_p.char_is_prime F _\u27e9,\n  have htr := trace_form_nondegenerate (zmod (ring_char F)) F a,\n  simp_rw [algebra.trace_form_apply] at htr,\n  by_contra' hf,\n  exact ha (htr hf),\nend\n\nend finite_field\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/field_theory/finite/trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7344769052129722}}
{"text": "def mod2 : \u2115 \u2192 \u2115\n| 0 := 0\n| (nat.succ n) := match mod2 n with\n    | 0 := 1\n    | (nat.succ _) := 0\n    end.\n\nopen nat\n\ntheorem mod2_0 : mod2 0 = 0 :=\nbegin\n  simp [mod2],\nend.\n\ntheorem mod2_1 : mod2 1 = 1 :=\nbegin\n  simp [mod2],\nend.\n\ntheorem mod2_return_0_1 : \u2200 n, mod2 n = 0 \u2228 mod2 n = 1 :=\nbegin\n  intro n,\n  induction n,\n    left,\n    unfold mod2,\n  cases n_ih,\n    right,\n    unfold mod2,\n    rw n_ih,\n    unfold mod2._match_1,\n  left,\n  unfold mod2,\n  rw n_ih,\n  unfold mod2._match_1,\nend.\n\ntheorem mod2_mul_2_0 : \u2200 n,  mod2 (2 * n) = 0 :=\nbegin\n  intro n,\n  induction n with n Hn,\n    simp [mod2],\n  rw [mul_succ],\n  unfold mod2,\n  rw Hn,\n  unfold mod2._match_1,\nend.\n\ntheorem mod2_idempotent : \u2200 n,  mod2 (mod2 n) = mod2 n :=\nbegin\n  intro n,\n  cases (mod2_return_0_1 n); simp [h, mod2],\nend.\n\ntheorem mod2_add_homo : \u2200 n m,  mod2 (n + m) = mod2 (mod2 n + mod2 m) :=\nbegin\n  intros n m,\n  revert n,\n  induction m with m IH; intros n,\n    simp [mod2, mod2_idempotent],\n  unfold mod2,\n  rewrite IH,\n  cases (mod2_return_0_1 n) with Hn Hn;\n    cases (mod2_return_0_1 m) with Hm Hm;\n    simp [Hn, Hm, mod2],\nend.\n\ntheorem sq_succ_n {n: nat} : (n+1) * (n+1) = n * n + 2 * n + 1 :=\nbegin\n  simp,\n  rw [nat.mul_succ, nat.mul_comm, nat.mul_succ],\n  have H2n : 2 * n = n + n,\n    rw [nat.mul_comm, nat.mul_succ, nat.mul_one],\n  rw [H2n],\n  simp [add_comm],\nend.\n\nexample : \u2200 n, mod2 n = mod2 (n * n) :=\nbegin\n  intro n,\n  induction n with n,\n    simp [mod2],\n  simp [mod2],\n  rw [sq_succ_n, mod2_add_homo, mod2_1],\n  unfold mod2,\n  rw [mod2_add_homo, \u2190n_ih, mod2_mul_2_0, add_zero],\n  simp [mod2_idempotent],\nend.\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/na4zagin3/top-14.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7344692791802274}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Kenny Lau, Scott Morrison\n-/\nimport data.list.of_fn\nimport data.list.perm\n\n/-!\n# Lists of elements of `fin n`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file develops some results on `fin_range n`.\n-/\n\nuniverse u\n\nnamespace list\nvariables {\u03b1 : Type u}\n\n@[simp] lemma map_coe_fin_range (n : \u2115) : (fin_range n).map coe = list.range n :=\nbegin\n  simp_rw [fin_range, map_pmap, fin.coe_mk, pmap_eq_map],\n  exact list.map_id _\nend\n\nlemma fin_range_succ_eq_map (n : \u2115) :\n  fin_range n.succ = 0 :: (fin_range n).map fin.succ :=\nbegin\n  apply map_injective_iff.mpr fin.coe_injective,\n  rw [map_cons, map_coe_fin_range, range_succ_eq_map, fin.coe_zero, \u2190map_coe_fin_range, map_map,\n    map_map, function.comp, function.comp],\n  congr' 2 with x,\n  exact (fin.coe_succ _).symm,\nend\n\n@[simp] lemma map_nth_le (l : list \u03b1) :\n  (fin_range l.length).map (\u03bb n, l.nth_le n n.2) = l :=\next_le (by rw [length_map, length_fin_range]) $ \u03bb n _ h,\nby { rw \u2190 nth_le_map_rev, congr, { rw nth_le_fin_range, refl }, { rw length_fin_range, exact h } }\n\ntheorem of_fn_eq_pmap {\u03b1 n} {f : fin n \u2192 \u03b1} :\n  of_fn f = pmap (\u03bb i hi, f \u27e8i, hi\u27e9) (range n) (\u03bb _, mem_range.1) :=\nby rw [pmap_eq_map_attach]; from ext_le (by simp)\n  (\u03bb i hi1 hi2, by { simp at hi1, simp [nth_le_of_fn f \u27e8i, hi1\u27e9, -subtype.val_eq_coe] })\n\ntheorem of_fn_id (n) : of_fn id = fin_range n := of_fn_eq_pmap\n\ntheorem of_fn_eq_map {\u03b1 n} {f : fin n \u2192 \u03b1} :\n  of_fn f = (fin_range n).map f :=\nby rw [\u2190 of_fn_id, map_of_fn, function.right_id]\n\ntheorem nodup_of_fn_of_injective {\u03b1 n} {f : fin n \u2192 \u03b1} (hf : function.injective f) :\n  nodup (of_fn f) :=\nby { rw of_fn_eq_pmap, exact (nodup_range n).pmap (\u03bb _ _ _ _ H, fin.veq_of_eq $ hf H) }\n\ntheorem nodup_of_fn {\u03b1 n} {f : fin n \u2192 \u03b1} :\n  nodup (of_fn f) \u2194 function.injective f :=\nbegin\n  refine \u27e8_, nodup_of_fn_of_injective\u27e9,\n  refine fin.cons_induction _ (\u03bb n x\u2080 xs ih, _) f,\n  { intro h,\n    exact function.injective_of_subsingleton _ },\n  { intro h,\n    rw fin.cons_injective_iff,\n    simp_rw [of_fn_succ, fin.cons_succ, nodup_cons, fin.cons_zero, mem_of_fn] at h,\n    exact h.imp_right ih }\nend\n\nend list\n\nopen list\n\nlemma equiv.perm.map_fin_range_perm {n : \u2115} (\u03c3 : equiv.perm (fin n)) :\n  map \u03c3 (fin_range n) ~ fin_range n :=\nbegin\n  rw [perm_ext ((nodup_fin_range n).map \u03c3.injective) $ nodup_fin_range n],\n  simpa only [mem_map, mem_fin_range, true_and, iff_true] using \u03c3.surjective\nend\n\n/-- The list obtained from a permutation of a tuple `f` is permutation equivalent to\nthe list obtained from `f`. -/\nlemma equiv.perm.of_fn_comp_perm {n : \u2115} {\u03b1 : Type u} (\u03c3 : equiv.perm (fin n)) (f : fin n \u2192 \u03b1) :\n  of_fn (f \u2218 \u03c3) ~ of_fn f :=\nbegin\n  rw [of_fn_eq_map, of_fn_eq_map, \u2190map_map],\n  exact \u03c3.map_fin_range_perm.map f,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/list/fin_range.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7343644068906654}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n-/\nimport data.list.prime\nimport data.list.sort\nimport data.nat.gcd\nimport data.nat.sqrt\nimport tactic.norm_num\nimport tactic.wlog\n\n/-!\n# Prime numbers\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\n- `nat.prime`: the predicate that expresses that a natural number `p` is prime\n- `nat.primes`: the subtype of natural numbers that are prime\n- `nat.min_fac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers\n- `nat.factors n`: the prime factorization of `n`\n- `nat.factors_unique`: uniqueness of the prime factorisation\n* `nat.prime_iff`: `nat.prime` coincides with the general definition of `prime`\n* `nat.irreducible_iff_prime`: a non-unit natural number is only divisible by `1` iff it is prime\n\n-/\n\nopen bool subtype\nopen_locale nat\n\nnamespace nat\n\n/-- `prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\n@[pp_nodot]\ndef prime (p : \u2115) := _root_.irreducible p\n\ntheorem _root_.irreducible_iff_nat_prime (a : \u2115) : irreducible a \u2194 nat.prime a := iff.rfl\n\ntheorem not_prime_zero : \u00ac prime 0\n| h := h.ne_zero rfl\n\ntheorem not_prime_one : \u00ac prime 1\n| h := h.ne_one rfl\n\ntheorem prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 := irreducible.ne_zero h\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : 0 < p := nat.pos_of_ne_zero pp.ne_zero\n\ntheorem prime.two_le : \u2200 {p : \u2115}, prime p \u2192 2 \u2264 p\n| 0 h := (not_prime_zero h).elim\n| 1 h := (not_prime_one h).elim\n| (n+2) _ := le_add_self\n\ntheorem prime.one_lt {p : \u2115} : prime p \u2192 1 < p := prime.two_le\n\ninstance prime.one_lt' (p : \u2115) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := \u27e8hp.1.one_lt\u27e9\n\nlemma prime.ne_one {p : \u2115} (hp : p.prime) : p \u2260 1 :=\nhp.one_lt.ne'\n\nlemma two_le_iff (n : \u2115) : 2 \u2264 n \u2194 n \u2260 0 \u2227 \u00acis_unit n :=\nbegin\n  rw nat.is_unit_iff,\n  rcases n with _|_|m; norm_num [one_lt_succ_succ, succ_le_iff]\nend\n\nlemma prime.eq_one_or_self_of_dvd {p : \u2115} (pp : p.prime) (m : \u2115) (hm : m \u2223 p) : m = 1 \u2228 m = p :=\nbegin\n  obtain \u27e8n, hn\u27e9 := hm,\n  have := pp.is_unit_or_is_unit hn,\n  rw [nat.is_unit_iff, nat.is_unit_iff] at this,\n  apply or.imp_right _ this,\n  rintro rfl,\n  rw [hn, mul_one]\nend\n\ntheorem prime_def_lt'' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m \u2223 p, m = 1 \u2228 m = p :=\nbegin\n  refine \u27e8\u03bb h, \u27e8h.two_le, h.eq_one_or_self_of_dvd\u27e9, \u03bb h, _\u27e9,\n  have h1 := one_lt_two.trans_le h.1,\n  refine \u27e8mt nat.is_unit_iff.mp h1.ne', \u03bb a b hab, _\u27e9,\n  simp only [nat.is_unit_iff],\n  apply or.imp_right _ (h.2 a _),\n  { rintro rfl,\n    rw [\u2190nat.mul_right_inj (pos_of_gt h1), \u2190hab, mul_one] },\n  { rw hab,\n    exact dvd_mul_right _ _ }\nend\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\nprime_def_lt''.trans $\nand_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h l d, (h d).resolve_right (ne_of_lt l),\n \u03bb h d, (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left (\u03bb l, h l d)\u27e9\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00ac m \u2223 p :=\nprime_def_lt.trans $ and_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h m2 l d, not_lt_of_ge m2 ((h l d).symm \u25b8 dec_trivial),\n\u03bb h l d, begin\n  rcases m with _|_|m,\n  { rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },\n  { refl },\n  { exact (h dec_trivial l).elim d }\nend\u27e9\n\ntheorem prime_def_le_sqrt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227\n  \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac m \u2223 p :=\nprime_def_lt'.trans $ and_congr_right $ \u03bb p2,\n\u27e8\u03bb a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,\n \u03bb a, have \u2200 {m k}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k, from\n  \u03bb m k mk m1 e, a m m1\n    (le_sqrt.2 (e.symm \u25b8 nat.mul_le_mul_left m mk)) \u27e8k, e\u27e9,\n  \u03bb m m2 l \u27e8k, e\u27e9, begin\n    cases (le_total m k) with mk km,\n    { exact this mk m2 e },\n    { rw [mul_comm] at e,\n      refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,\n      rwa [one_mul, \u2190 e] }\n  end\u27e9\n\ntheorem prime_of_coprime (n : \u2115) (h1 : 1 < n) (h : \u2200 m < n, m \u2260 0 \u2192 n.coprime m) : prime n :=\nbegin\n  refine prime_def_lt.mpr \u27e8h1, \u03bb m mlt mdvd, _\u27e9,\n  have hm : m \u2260 0,\n  { rintro rfl,\n    rw zero_dvd_iff at mdvd,\n    exact mlt.ne' mdvd },\n  exact (h m mlt hm).symm.eq_one_of_dvd mdvd,\nend\n\nsection\n\n/--\n  This instance is slower than the instance `decidable_prime` defined below,\n  but has the advantage that it works in the kernel for small values.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\nlocal attribute [instance]\ndef decidable_prime_1 (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_lt'\n\ntheorem prime_two : prime 2 := dec_trivial\n\nend\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : 0 < pred p :=\nlt_pred_iff.2 pp.one_lt\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : succ (pred p) = p :=\nsucc_pred_eq_of_pos pp.pos\n\ntheorem dvd_prime {p m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n\u27e8\u03bb d, pp.eq_one_or_self_of_dvd m d, \u03bb h, h.elim (\u03bb e, e.symm \u25b8 one_dvd _) (\u03bb e, e.symm \u25b8 dvd_rfl)\u27e9\n\ntheorem dvd_prime_two_le {p m : \u2115} (pp : prime p) (H : 2 \u2264 m) : m \u2223 p \u2194 m = p :=\n(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H\n\ntheorem prime_dvd_prime_iff_eq {p q : \u2115} (pp : p.prime) (qp : q.prime) : p \u2223 q \u2194 p = q :=\ndvd_prime_two_le qp (prime.two_le pp)\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00ac p \u2223 1\n| d := (not_le_of_gt pp.one_lt) $ le_of_dvd dec_trivial d\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00ac prime (a * b) :=\n\u03bb h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $\nby simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)\n\nlemma not_prime_mul' {a b n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) : \u00ac prime n :=\nby { rw \u2190 h, exact not_prime_mul h\u2081 h\u2082 }\n\nsection min_fac\n\nlemma min_fac_lemma (n k : \u2115) (h : \u00ac n < k * k) :\n  sqrt n - k < sqrt n + 2 - k :=\n(tsub_lt_tsub_iff_right $ le_sqrt.2 $ le_of_not_gt h).2 $\nnat.lt_add_of_pos_right dec_trivial\n\n/-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.\n  Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.\n  If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/\ndef min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115\n| k :=\n  if h : n < k * k then n else\n  if k \u2223 n then k else\n  have _, from min_fac_lemma n k h,\n  min_fac_aux (k + 2)\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n/-- Returns the smallest prime factor of `n \u2260 1`. -/\ndef min_fac : \u2115 \u2192 \u2115\n| 0 := 2\n| 1 := 1\n| (n+2) := if 2 \u2223 n then 2 else min_fac_aux (n + 2) 3\n\n@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl\n@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\ntheorem min_fac_eq : \u2200 n, min_fac n = if 2 \u2223 n then 2 else min_fac_aux n 3\n| 0     := by simp\n| 1     := by simp [show 2\u22601, from dec_trivial]; rw min_fac_aux; refl\n| (n+2) :=\n  have 2 \u2223 n + 2 \u2194 2 \u2223 n, from\n    (nat.dvd_add_iff_left (by refl)).symm,\n  by simp [min_fac, this]; congr\n\nprivate def min_fac_prop (n k : \u2115) :=\n  2 \u2264 k \u2227 k \u2223 n \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m\n\ntheorem min_fac_aux_has_prop {n : \u2115} (n2 : 2 \u2264 n) :\n  \u2200 k i, k = 2*i+3 \u2192 (\u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k)\n| k := \u03bb i e a, begin\n  rw min_fac_aux,\n  by_cases h : n < k*k; simp [h],\n  { have pp : prime n :=\n      prime_def_le_sqrt.2 \u27e8n2, \u03bb m m2 l d,\n        not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9,\n    from \u27e8n2, dvd_rfl, \u03bb m m2 d, le_of_eq\n      ((dvd_prime_two_le pp m2).1 d).symm\u27e9 },\n  have k2 : 2 \u2264 k, { subst e, exact dec_trivial },\n  by_cases dk : k \u2223 n; simp [dk],\n  { exact \u27e8k2, dk, a\u27e9 },\n  { refine have _, from min_fac_lemma n k h,\n      min_fac_aux_has_prop (k+2) (i+1)\n        (by simp [e, left_distrib]) (\u03bb m m2 d, _),\n    cases nat.eq_or_lt_of_le (a m m2 d) with me ml,\n    { subst me, contradiction },\n    apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,\n    rw [\u2190 me, e] at d, change 2 * (i + 2) \u2223 n at d,\n    have := a _ le_rfl (dvd_of_mul_right_dvd d),\n    rw e at this, exact absurd this dec_trivial }\nend\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\ntheorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) :\n  min_fac_prop n (min_fac n) :=\nbegin\n  by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},\n  have n2 : 2 \u2264 n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },\n  simp [min_fac_eq],\n  by_cases d2 : 2 \u2223 n; simp [d2],\n  { exact \u27e8le_rfl, d2, \u03bb k k2 d, k2\u27e9 },\n  { refine min_fac_aux_has_prop n2 3 0 rfl\n      (\u03bb m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),\n    exact \u03bb e, e.symm \u25b8 d }\nend\n\ntheorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\nif n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1\n\ntheorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) :=\nlet \u27e8f2, fd, a\u27e9 := min_fac_has_prop n1 in\nprime_def_lt'.2 \u27e8f2, \u03bb m m2 l d, not_le_of_gt l (a m m2 (d.trans fd))\u27e9\n\ntheorem min_fac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, 2 \u2264 m \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\nby by_cases n1 : n = 1;\n  [exact \u03bb m m2 d, n1.symm \u25b8 le_trans dec_trivial m2,\n    exact (min_fac_has_prop n1).2.2]\n\ntheorem min_fac_pos (n : \u2115) : 0 < min_fac n :=\nby by_cases n1 : n = 1;\n    [exact n1.symm \u25b8 dec_trivial, exact (min_fac_prime n1).pos]\n\ntheorem min_fac_le {n : \u2115} (H : 0 < n) : min_fac n \u2264 n :=\nle_of_dvd H (min_fac_dvd n)\n\ntheorem le_min_fac {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, prime p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p pp d, h.elim\n  (by rintro rfl; cases pp.not_dvd_one d)\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp.two_le d),\n  \u03bb H, or_iff_not_imp_left.2 $ \u03bb n1, H _ (min_fac_prime n1) (min_fac_dvd _)\u27e9\n\ntheorem le_min_fac' {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, 2 \u2264 p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p (pp:1<p) d, h.elim\n  (by rintro rfl; cases not_le_of_lt pp (le_of_dvd dec_trivial d))\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp d),\n  \u03bb H, le_min_fac.2 (\u03bb p pp d, H p pp.two_le d)\u27e9\n\ntheorem prime_def_min_fac {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 min_fac p = p :=\n\u27e8\u03bb pp, \u27e8pp.two_le,\n  let \u27e8f2, fd, a\u27e9 := min_fac_has_prop $ ne_of_gt pp.one_lt in\n  ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n  \u03bb \u27e8p2, e\u27e9, e \u25b8 min_fac_prime (ne_of_gt p2)\u27e9\n\n@[simp] lemma prime.min_fac_eq {p : \u2115} (hp : prime p) : min_fac p = p :=\n(prime_def_min_fac.1 hp).2\n\n/--\nThis instance is faster in the virtual machine than `decidable_prime_1`,\nbut slower in the kernel.\n\nIf you need to prove that a particular number is prime, in any case\nyou should not use `dec_trivial`, but rather `by norm_num`, which is\nmuch faster.\n-/\ninstance decidable_prime (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_min_fac\n\ntheorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : 2 \u2264 n) : \u00ac prime n \u2194 min_fac n < n :=\n(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $\n  (lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm\n\nlemma min_fac_le_div {n : \u2115} (pos : 0 < n) (np : \u00ac prime n) : min_fac n \u2264 n / min_fac n :=\nmatch min_fac_dvd n with\n| \u27e80, h0\u27e9     := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial\n| \u27e81, h1\u27e9     :=\n  begin\n    rw mul_one at h1,\n    rw [prime_def_min_fac, not_and_distrib, \u2190 h1, eq_self_iff_true, not_true, or_false,\n      not_le] at np,\n    rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]\n  end\n| \u27e8(x+2), hx\u27e9 :=\n  begin\n    conv_rhs { congr, rw hx },\n    rw [nat.mul_div_cancel_left _ (min_fac_pos _)],\n    exact min_fac_le_of_dvd dec_trivial \u27e8min_fac n, by rwa mul_comm\u27e9\n  end\nend\n\n/--\nThe square of the smallest prime factor of a composite number `n` is at most `n`.\n-/\nlemma min_fac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00ac prime n) : (min_fac n)^2 \u2264 n :=\nhave t : (min_fac n) \u2264 (n/min_fac n) := min_fac_le_div w h,\ncalc\n(min_fac n)^2 = (min_fac n) * (min_fac n)   : sq (min_fac n)\n          ... \u2264 (n/min_fac n) * (min_fac n) : nat.mul_le_mul_right (min_fac n) t\n          ... \u2264 n                           : div_mul_le_self n (min_fac n)\n\n@[simp]\nlemma min_fac_eq_one_iff {n : \u2115} : min_fac n = 1 \u2194 n = 1 :=\nbegin\n  split,\n  { intro h,\n    by_contradiction hn,\n    have := min_fac_prime hn,\n    rw h at this,\n    exact not_prime_one this, },\n  { rintro rfl, refl, }\nend\n\n@[simp]\nlemma min_fac_eq_two_iff (n : \u2115) : min_fac n = 2 \u2194 2 \u2223 n :=\nbegin\n  split,\n  { intro h,\n    convert min_fac_dvd _,\n    rw h, },\n  { intro h,\n    have ub := min_fac_le_of_dvd (le_refl 2) h,\n    have lb := min_fac_pos n,\n    apply ub.eq_or_lt.resolve_right (\u03bb h', _),\n    have := le_antisymm (nat.succ_le_of_lt lb) (lt_succ_iff.mp h'),\n    rw [eq_comm, nat.min_fac_eq_one_iff] at this,\n    subst this,\n    exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two }\nend\n\nend min_fac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n\u27e8min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,\n  ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 2 \u2264 m \u2227 m < n :=\n\u27e8min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,\n  (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_prime_and_dvd {n : \u2115} (n2 : 2 \u2264 n) : \u2203 p, prime p \u2227 p \u2223 n :=\n\u27e8min_fac n, min_fac_prime (ne_of_gt n2), min_fac_dvd _\u27e9\n\n/-- Euclid's theorem on the **infinitude of primes**.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, n \u2264 p \u2227 prime p :=\nlet p := min_fac (n! + 1) in\nhave f1 : n! + 1 \u2260 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,\nhave pp : prime p, from min_fac_prime f1,\nhave np : n \u2264 p, from le_of_not_ge $ \u03bb h,\n  have h\u2081 : p \u2223 n!, from dvd_factorial (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  pp.not_dvd_one h\u2082,\n\u27e8p, np, pp\u27e9\n\nlemma prime.eq_two_or_odd {p : \u2115} (hp : prime p) : p = 2 \u2228 p % 2 = 1 :=\np.mod_two_eq_zero_or_one.imp_left\n  (\u03bb h, ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)\n\ntheorem coprime_of_dvd {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 \u00ac k \u2223 n) : coprime m n :=\nbegin\n  have g1 : 1 \u2264 gcd m n,\n  { refine nat.succ_le_of_lt (pos_iff_ne_zero.mpr (\u03bb g0, _)),\n    rw [eq_zero_of_gcd_eq_zero_left g0, eq_zero_of_gcd_eq_zero_right g0] at H,\n    exact H 2 prime_two (dvd_zero _) (dvd_zero _) },\n  rw [coprime_iff_gcd_eq_one, eq_comm],\n  refine g1.lt_or_eq.resolve_left (\u03bb g2, _),\n  obtain \u27e8p, hp, hpdvd\u27e9 := exists_prime_and_dvd (succ_le_of_lt g2),\n  apply H p hp; apply dvd_trans hpdvd,\n  { exact gcd_dvd_left _ _ },\n  { exact gcd_dvd_right _ _ }\nend\n\ntheorem coprime_of_dvd' {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) : coprime m n :=\ncoprime_of_dvd $ \u03bbk kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn\n\ntheorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=\ndiv_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 list \u2115\n| 0 := []\n| 1 := []\n| n@(k+2) :=\n  let m := min_fac n in have n / m < n := factors_lemma,\n  m :: factors (n / m)\n\n@[simp] lemma factors_zero : factors 0 = [] := by rw factors\n@[simp] lemma factors_one : factors 1 = [] := by rw factors\n\nlemma prime_of_mem_factors : \u2200 {n p}, p \u2208 factors n \u2192 prime p\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb p h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  have h\u2081 : p = m \u2228 p \u2208 (factors (n / m)) :=\n    (list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),\n  or.cases_on h\u2081 (\u03bb h\u2082, h\u2082.symm \u25b8 min_fac_prime dec_trivial)\n    prime_of_mem_factors\n\nlemma prod_factors : \u2200 {n}, 0 < n \u2192 list.prod (factors n) = n\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  show (factors n).prod = n, from\n  have h\u2081 : 0 < n / m :=\n    nat.pos_of_ne_zero $ \u03bb h,\n    have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,\n    by rw zero_mul at this; exact (show k + 2 \u2260 0, from dec_trivial) this,\n  by rw [factors, list.prod_cons, prod_factors h\u2081, nat.mul_div_cancel' (min_fac_dvd _)]\n\nlemma factors_prime {p : \u2115} (hp : nat.prime p) : p.factors = [p] :=\nbegin\n  have : p = (p - 2) + 2 := (tsub_eq_iff_eq_add_of_le hp.two_le).mp rfl,\n  rw [this, nat.factors],\n  simp only [eq.symm this],\n  have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,\n  split,\n  { exact this, },\n  { simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },\nend\n\nlemma factors_chain : \u2200 {n a}, (\u2200 p, prime p \u2192 p \u2223 n \u2192 a \u2264 p) \u2192 list.chain (\u2264) a (factors n)\n| 0       := \u03bb a h, by simp\n| 1       := \u03bb a h, by simp\n| n@(k+2) := \u03bb a h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  begin\n    rw factors,\n    refine list.chain.cons ((le_min_fac.2 h).resolve_left dec_trivial) (factors_chain _),\n    exact \u03bb p pp d, min_fac_le_of_dvd pp.two_le (d.trans $ div_dvd_of_dvd $ min_fac_dvd _),\n  end\n\nlemma factors_chain_2 (n) : list.chain (\u2264) 2 (factors n) := factors_chain $ \u03bb p pp _, pp.two_le\n\nlemma factors_chain' (n) : list.chain' (\u2264) (factors n) :=\n@list.chain'.tail _ _ (_::_) (factors_chain_2 _)\n\nlemma factors_sorted (n : \u2115) : list.sorted (\u2264) (factors n) :=\n(list.chain'_iff_pairwise (@le_trans _ _)).1 (factors_chain' _)\n\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\nlemma factors_add_two (n : \u2115) :\n  factors (n+2) = min_fac (n+2) :: factors ((n+2) / min_fac (n+2)) :=\nby rw factors\n\n@[simp]\nlemma factors_eq_nil (n : \u2115) : n.factors = [] \u2194 n = 0 \u2228 n = 1 :=\nbegin\n  split; intro h,\n  { rcases n with (_ | _ | n),\n    { exact or.inl rfl },\n    { exact or.inr rfl },\n    { rw factors at h, injection h }, },\n  { rcases h with (rfl | rfl),\n    { exact factors_zero },\n    { exact factors_one }, }\nend\n\nlemma eq_of_perm_factors {a b : \u2115} (ha : 0 < a) (hb : 0 < b) (h : a.factors ~ b.factors) : a = b :=\nby simpa [prod_factors ha, prod_factors hb] using list.perm.prod_eq h\n\nlemma eq_of_count_factors_eq {a b : \u2115} (ha : 0 < a) (hb : 0 < b)\n  (h : \u2200 p : \u2115, list.count p a.factors = list.count p b.factors) : a = b :=\neq_of_perm_factors ha hb (list.perm_iff_count.mpr h)\n\ntheorem prime.coprime_iff_not_dvd {p n : \u2115} (pp : prime p) : coprime p n \u2194 \u00ac p \u2223 n :=\n\u27e8\u03bb co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),\n \u03bb nd, coprime_of_dvd $ \u03bb m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm \u25b8 nd\u27e9\n\ntheorem prime.dvd_iff_not_coprime {p n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00ac coprime p n :=\niff_not_comm.2 pp.coprime_iff_not_dvd\n\ntheorem prime.not_coprime_iff_dvd {m n : \u2115} :\n  \u00ac coprime m n \u2194 \u2203p, prime p \u2227 p \u2223 m \u2227 p \u2223 n :=\nbegin\n  apply iff.intro,\n  { intro h,\n    exact \u27e8min_fac (gcd m n), min_fac_prime h,\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_left m n)),\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_right m n))\u27e9 },\n  { intro h,\n    cases h with p hp,\n    apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }\nend\n\ntheorem prime.dvd_mul {p m n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n\u27e8\u03bb H, or_iff_not_imp_left.2 $ \u03bb h,\n  (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n or.rec (\u03bb h : p \u2223 m, h.mul_right _) (\u03bb h : p \u2223 n, h.mul_left _)\u27e9\n\ntheorem prime.not_dvd_mul {p m n : \u2115} (pp : prime p)\n  (Hm : \u00ac p \u2223 m) (Hn : \u00ac p \u2223 n) : \u00ac p \u2223 m * n :=\nmt pp.dvd_mul.1 $ by simp [Hm, Hn]\n\ntheorem prime_iff {p : \u2115} : p.prime \u2194 _root_.prime p :=\n\u27e8\u03bb h, \u27e8h.ne_zero, h.not_unit, \u03bb a b, h.dvd_mul.mp\u27e9, prime.irreducible\u27e9\n\ntheorem irreducible_iff_prime {p : \u2115} : irreducible p \u2194 _root_.prime p :=\nby rw [\u2190prime_iff, prime]\n\ntheorem prime.dvd_of_dvd_pow {p m n : \u2115} (pp : prime p) (h : p \u2223 m^n) : p \u2223 m :=\nbegin\n  induction n with n IH,\n  { exact pp.not_dvd_one.elim h },\n  { rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH }\nend\n\nlemma prime.pow_not_prime {x n : \u2115} (hn : 2 \u2264 n) : \u00ac (x ^ n).prime :=\n\u03bb hp, (hp.eq_one_or_self_of_dvd x $ dvd_trans \u27e8x, sq _\u27e9 (pow_dvd_pow _ hn)).elim\n  (\u03bb hx1, hp.ne_one $ hx1.symm \u25b8 one_pow _)\n  (\u03bb hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm\n     ... < x ^ n : nat.pow_right_strict_mono (hxn.symm \u25b8 hp.two_le) hn\n     ... = x : hxn.symm)\n\nlemma prime.pow_not_prime' {x : \u2115} : \u2200 {n : \u2115}, n \u2260 1 \u2192 \u00ac (x ^ n).prime\n| 0     := \u03bb _, not_prime_one\n| 1     := \u03bb h, (h rfl).elim\n| (n+2) := \u03bb _, prime.pow_not_prime le_add_self\n\nlemma prime.eq_one_of_pow {x n : \u2115} (h : (x ^ n).prime) : n = 1 :=\nnot_imp_not.mp prime.pow_not_prime' h\n\nlemma prime.pow_eq_iff {p a k : \u2115} (hp : p.prime) : a ^ k = p \u2194 a = p \u2227 k = 1 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, by rw [h.1, h.2, pow_one]\u27e9,\n  rw \u2190h at hp,\n  rw [\u2190h, hp.eq_one_of_pow, eq_self_iff_true, and_true, pow_one],\nend\n\nlemma pow_min_fac {n k : \u2115} (hk : k \u2260 0) : (n^k).min_fac = n.min_fac :=\nbegin\n  rcases eq_or_ne n 1 with rfl | hn,\n  { simp },\n  have hnk : n ^ k \u2260 1 := \u03bb hk', hn ((pow_eq_one_iff hk).1 hk'),\n  apply (min_fac_le_of_dvd (min_fac_prime hn).two_le ((min_fac_dvd n).pow hk)).antisymm,\n  apply min_fac_le_of_dvd (min_fac_prime hnk).two_le\n    ((min_fac_prime hnk).dvd_of_dvd_pow (min_fac_dvd _)),\nend\n\nlemma prime.pow_min_fac {p k : \u2115} (hp : p.prime) (hk : k \u2260 0) : (p^k).min_fac = p :=\nby rw [pow_min_fac hk, hp.min_fac_eq]\n\nlemma prime.mul_eq_prime_sq_iff {x y p : \u2115} (hp : p.prime) (hx : x \u2260 1) (hy : y \u2260 1) :\n  x * y = p ^ 2 \u2194 x = p \u2227 y = p :=\n\u27e8\u03bb h, have pdvdxy : p \u2223 x * y, by rw h; simp [sq],\nbegin\n  wlog := hp.dvd_mul.1 pdvdxy using x y,\n  cases case with a ha,\n  have hap : a \u2223 p, from \u27e8y, by rwa [ha, sq,\n        mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at h\u27e9,\n  exact ((nat.dvd_prime hp).1 hap).elim\n    (\u03bb _, by clear_aux_decl; simp [*, sq, nat.mul_right_inj hp.pos] at *\n      {contextual := tt})\n    (\u03bb _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,\n      nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *\n      {contextual := tt})\nend,\n\u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.symm \u25b8 h\u2082.symm \u25b8 (sq _).symm\u27e9\n\nlemma prime.dvd_factorial : \u2200 {n p : \u2115} (hp : prime p), p \u2223 n! \u2194 p \u2264 n\n| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)\n| (n+1) p hp := begin\n  rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],\n  exact \u27e8\u03bb h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,\n    \u03bb h, (_root_.lt_or_eq_of_le h).elim (or.inr \u2218 le_of_lt_succ)\n      (\u03bb h, or.inl $ by rw h)\u27e9\nend\n\ntheorem prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : prime p) (h : \u00ac p \u2223 a) : coprime a (p^m) :=\n(pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n\ntheorem coprime_primes {p q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\npp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : prime p) (pq : prime q) (h : p \u2260 q) :\n  coprime (p^n) (q^m) :=\n((coprime_primes pp pq).2 h).pow _ _\n\ntheorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\nby rw [pp.dvd_iff_not_coprime]; apply em\n\nlemma coprime_of_lt_prime {n p} (n_pos : 0 < n) (hlt : n < p) (pp : prime p) :\n  coprime p n :=\n(coprime_or_dvd_of_prime pp n).resolve_right $ \u03bb h, lt_le_antisymm hlt (le_of_dvd n_pos h)\n\nlemma eq_or_coprime_of_le_prime {n p} (n_pos : 0 < n) (hle : n \u2264 p) (pp : prime p) :\n  p = n \u2228 coprime p n :=\nhle.eq_or_lt.imp eq.symm (\u03bb h, coprime_of_lt_prime n_pos h pp)\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m i : \u2115} : i \u2223 (p^m) \u2194 \u2203 k \u2264 m, i = p^k :=\nbegin\n  induction m with m IH generalizing i, { simp },\n  by_cases p \u2223 i,\n  { cases h with a e, subst e,\n    rw [pow_succ, nat.mul_dvd_mul_iff_left pp.pos, IH],\n    split; intro h; rcases h with \u27e8k, h, e\u27e9,\n    { exact \u27e8succ k, succ_le_succ h, by rw [e, pow_succ]; refl\u27e9 },\n    cases k with k,\n    { apply pp.not_dvd_one.elim,\n      rw [\u2190 pow_zero, \u2190 e], apply dvd_mul_right },\n    { refine \u27e8k, le_of_succ_le_succ h, _\u27e9,\n      rwa [mul_comm, pow_succ', nat.mul_left_inj pp.pos] at e } },\n  { split; intro d,\n    { rw (pp.coprime_pow_of_not_dvd h).eq_one_of_dvd d,\n      exact \u27e80, zero_le _, (pow_zero p).symm\u27e9 },\n    { rcases d with \u27e8k, l, rfl\u27e9,\n      exact pow_dvd_pow _ l } }\nend\n\nlemma prime.dvd_mul_of_dvd_ne {p1 p2 n : \u2115} (h_neq : p1 \u2260 p2) (pp1 : prime p1) (pp2 : prime p2)\n  (h1 : p1 \u2223 n) (h2 : p2 \u2223 n) : (p1 * p2 \u2223 n) :=\ncoprime.mul_dvd_of_dvd_of_dvd ((coprime_primes pp1 pp2).mpr h_neq) h1 h2\n\n/--\nIf `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\nlemma eq_prime_pow_of_dvd_least_prime_pow\n  {a p k : \u2115} (pp : prime p) (h\u2081 : \u00ac(a \u2223 p^k)) (h\u2082 : a \u2223 p^(k+1)) :\n  a = p^(k+1) :=\nbegin\n  obtain \u27e8l, \u27e8h, rfl\u27e9\u27e9 := (dvd_prime_pow pp).1 h\u2082,\n  congr,\n  exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h\u2081)),\nend\n\nlemma ne_one_iff_exists_prime_dvd : \u2200 {n}, n \u2260 1 \u2194 \u2203 p : \u2115, p.prime \u2227 p \u2223 n\n| 0 := by simpa using (Exists.intro 2 nat.prime_two)\n| 1 := by simp [nat.not_prime_one]\n| (n+2) :=\nlet a := n+2 in\nlet ha : a \u2260 1 := nat.succ_succ_ne_one n in\nbegin\n  simp only [true_iff, ne.def, not_false_iff, ha],\n  exact \u27e8a.min_fac, nat.min_fac_prime ha, a.min_fac_dvd\u27e9,\nend\n\nlemma eq_one_iff_not_exists_prime_dvd {n : \u2115} : n = 1 \u2194 \u2200 p : \u2115, p.prime \u2192 \u00acp \u2223 n :=\nby simpa using not_iff_not.mpr ne_one_iff_exists_prime_dvd\n\nsection\nopen list\n\nlemma mem_factors_iff_dvd {n p : \u2115} (hn : 0 < n) (hp : prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n\u27e8\u03bb h, prod_factors hn \u25b8 list.dvd_prod h,\n  \u03bb h, mem_list_primes_of_dvd_prod\n    (prime_iff.mp hp)\n    (\u03bb p h, prime_iff.mp (prime_of_mem_factors h))\n    ((prod_factors hn).symm \u25b8 h)\u27e9\n\nlemma dvd_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2223 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { exact dvd_zero p },\n  { rwa \u2190mem_factors_iff_dvd hn (prime_of_mem_factors h) }\nend\n\nlemma mem_factors {n p} (hn : n \u2260 0) : p \u2208 factors n \u2194 prime p \u2227 p \u2223 n :=\n\u27e8\u03bb h, \u27e8prime_of_mem_factors h, (mem_factors_iff_dvd hn.bot_lt $ prime_of_mem_factors h).mp h\u27e9,\n \u03bb \u27e8hprime, hdvd\u27e9, (mem_factors_iff_dvd hn.bot_lt hprime).mpr hdvd\u27e9\n\n/-- **Fundamental theorem of arithmetic**-/\nlemma factors_unique {n : \u2115} {l : list \u2115} (h\u2081 : prod l = n) (h\u2082 : \u2200 p \u2208 l, prime p) :\n  l ~ factors n :=\nbegin\n  refine perm_of_prod_eq_prod _ _ _,\n  { rw h\u2081,\n    refine (prod_factors (nat.pos_of_ne_zero _)).symm,\n    rintro rfl,\n    rw prod_eq_zero_iff at h\u2081,\n    exact prime.ne_zero (h\u2082 0 h\u2081) rfl },\n  { simp_rw \u2190prime_iff, exact h\u2082 },\n  { simp_rw \u2190prime_iff, exact (\u03bb p, prime_of_mem_factors) },\nend\n\nlemma prime.factors_pow {p : \u2115} (hp : p.prime) (n : \u2115) :\n  (p ^ n).factors = list.repeat p n :=\nbegin\n  symmetry,\n  rw \u2190 list.repeat_perm,\n  apply nat.factors_unique (list.prod_repeat p n),\n  intros q hq,\n  rwa eq_of_mem_repeat hq,\nend\n\n/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul_of_pos {a b : \u2115} (ha : 0 < a) (hb : 0 < b) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  refine (factors_unique _ _).symm,\n  { rw [list.prod_append, prod_factors ha, prod_factors hb] },\n  { intros p hp,\n    rw list.mem_append at hp,\n    cases hp;\n    exact prime_of_mem_factors hp },\nend\n\n/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  exact perm_factors_mul_of_pos ha hb,\nend\n\n/-- For positive `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\nlemma count_factors_mul_of_pos {p a b : \u2115} (ha : 0 < a) (hb : 0 < b) :\n  list.count p (a * b).factors = list.count p a.factors + list.count p b.factors :=\nby rw [perm_iff_count.mp (perm_factors_mul_of_pos ha hb) p, count_append]\n\n/-- For coprime `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\nlemma count_factors_mul_of_coprime {p a b : \u2115} (hab : coprime a b)  :\n  list.count p (a * b).factors = list.count p a.factors + list.count p b.factors :=\nby rw [perm_iff_count.mp (perm_factors_mul_of_coprime hab) p, count_append]\n\nlemma factors_sublist_right {n k : \u2115} (h : k \u2260 0) : n.factors <+ (n * k).factors :=\nbegin\n  cases n,\n  { rw zero_mul },\n  apply list.sublist_of_subperm_of_sorted _ (factors_sorted _) (factors_sorted _),\n  rw (perm_factors_mul_of_pos nat.succ_pos' (nat.pos_of_ne_zero h)).subperm_left,\n  exact (list.sublist_append_left _ _).subperm,\nend\n\nlemma factors_sublist_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors <+ k.factors :=\nbegin\n  obtain \u27e8a, rfl\u27e9 := h,\n  exact factors_sublist_right (right_ne_zero_of_mul h'),\nend\n\nlemma factors_subset_right {n k : \u2115} (h : k \u2260 0) : n.factors \u2286 (n * k).factors :=\n(factors_sublist_right h).subset\n\nlemma factors_subset_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors \u2286 k.factors :=\n(factors_sublist_of_dvd h h').subset\n\n/-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/\nlemma factors_count_pow {n k p : \u2115} : count p (n ^ k).factors = k * count p n.factors :=\nbegin\n  induction k with k IH, { simp },\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { simp [zero_pow (succ_pos k), count_nil, factors_zero, mul_zero] },\n  rw [pow_succ n k, perm_iff_count.mp (perm_factors_mul_of_pos hn (pow_pos hn k)) p],\n  rw [list.count_append, IH, add_comm, mul_comm, \u2190mul_succ (count p n.factors) k, mul_comm],\nend\n\nlemma dvd_of_factors_subperm {a b : \u2115} (ha : a \u2260 0) (h : a.factors <+~ b.factors) : a \u2223 b :=\nbegin\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { exact dvd_zero _ },\n  rcases a with (_|_|a),\n  { exact (ha rfl).elim },\n  { exact one_dvd _ },\n  use (b.factors.diff a.succ.succ.factors).prod,\n  nth_rewrite 0 \u2190nat.prod_factors ha.bot_lt,\n  rw [\u2190list.prod_append,\n      list.perm.prod_eq $ list.subperm_append_diff_self_of_count_le $ list.subperm_ext_iff.mp h,\n      nat.prod_factors hb]\nend\n\nlemma pow_factors_count_dvd (n p : \u2115) :\n  p ^ n.factors.count p \u2223 n :=\nbegin\n  by_cases hp : p.prime,\n  { apply dvd_of_factors_subperm (pow_ne_zero _ hp.ne_zero),\n    rw [hp.factors_pow, list.subperm_ext_iff],\n    intros q hq,\n    simp [list.eq_of_mem_repeat hq] },\n  { rw count_eq_zero_of_not_mem (mt prime_of_mem_factors hp),\n    simp },\nend\n\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m n k l : \u2115}\n      (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k+l+1) \u2223 m*n) :\n      p ^ (k+1) \u2223 m \u2228 p ^ (l+1) \u2223 n :=\nhave hpd : p^(k+l)*p \u2223 m*n, by rwa pow_succ' at hpmn,\nhave hpd2 : p \u2223 (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,\nhave hpd3 : p \u2223 (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,\nhave hpd4 : p \u2223 (m / p^k) * (n / p^l), by simpa [nat.div_mul_div hpm hpn] using hpd3,\nhave hpd5 : p \u2223 (m / p^k) \u2228 p \u2223 (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,\nsuffices p^k*p \u2223 m \u2228 p^l*p \u2223 n, by rwa [pow_succ', pow_succ'],\n  hpd5.elim\n    (assume : p \u2223 m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)\n    (assume : p \u2223 n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)\n\n/-- The type of prime numbers -/\ndef primes := {p : \u2115 // p.prime}\n\nnamespace primes\n\ninstance : has_repr nat.primes := \u27e8\u03bb p, repr p.val\u27e9\ninstance inhabited_primes : inhabited primes := \u27e8\u27e82, prime_two\u27e9\u27e9\n\ninstance coe_nat : has_coe nat.primes \u2115 := \u27e8subtype.val\u27e9\n\ntheorem coe_nat_inj (p q : nat.primes) : (p : \u2115) = (q : \u2115) \u2192 p = q :=\n\u03bb h, subtype.eq h\n\nend primes\n\ninstance monoid.prime_pow {\u03b1 : Type*} [monoid \u03b1] : has_pow \u03b1 primes := \u27e8\u03bb x p, x^p.val\u27e9\n\nend nat\n\n/-! ### Primality prover -/\n\nopen norm_num\n\nnamespace tactic\nnamespace norm_num\n\nlemma is_prime_helper (n : \u2115)\n  (h\u2081 : 1 < n) (h\u2082 : nat.min_fac n = n) : nat.prime n :=\nnat.prime_def_min_fac.2 \u27e8h\u2081, h\u2082\u27e9\n\nlemma min_fac_bit0 (n : \u2115) : nat.min_fac (bit0 n) = 2 :=\nby simp [nat.min_fac_eq, show 2 \u2223 bit0 n, by simp [bit0_eq_two_mul n]]\n\n/-- A predicate representing partial progress in a proof of `min_fac`. -/\ndef min_fac_helper (n k : \u2115) : Prop :=\n0 < k \u2227 bit1 k \u2264 nat.min_fac (bit1 n)\n\ntheorem min_fac_helper.n_pos {n k : \u2115} (h : min_fac_helper n k) : 0 < n :=\npos_iff_ne_zero.2 $ \u03bb e,\nby rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2\n\nlemma min_fac_ne_bit0 {n k : \u2115} : nat.min_fac (bit1 n) \u2260 bit0 k :=\nbegin\n  rw bit0_eq_two_mul,\n  refine (\u03bb e, absurd ((nat.dvd_add_iff_right _).2\n    (dvd_trans \u27e8_, e\u27e9 (nat.min_fac_dvd _))) _); simp\nend\n\nlemma min_fac_helper_0 (n : \u2115) (h : 0 < n) : min_fac_helper n 1 :=\nbegin\n  refine \u27e8zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symm\u27e9,\n  rw nat.succ_le_iff,\n  refine lt_of_le_of_ne (nat.min_fac_pos _) (\u03bb e, nat.not_prime_one _),\n  rw e,\n  exact nat.min_fac_prime (nat.bit1_lt h).ne',\nend\n\nlemma min_fac_helper_1 {n k k' : \u2115} (e : k + 1 = k')\n  (np : nat.min_fac (bit1 n) \u2260 bit1 k)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  rw \u2190 e,\n  refine \u27e8nat.succ_pos _,\n    (lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)\n      min_fac_ne_bit0.symm : bit0 (k+1) < _)\u27e9,\n  { rw add_right_comm, exact h.2 },\n  { rw add_right_comm, exact np.symm }\nend\n\nlemma min_fac_helper_2 (n k k' : \u2115) (e : k + 1 = k')\n  (np : \u00ac nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  intro e\u2081, rw \u2190 e\u2081 at np,\n  exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)\nend\n\nlemma min_fac_helper_3 (n k k' c : \u2115) (e : k + 1 = k')\n  (nc : bit1 n % bit1 k = c) (c0 : 0 < c)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  refine mt _ (ne_of_gt c0), intro e\u2081,\n  rw [\u2190 nc, \u2190 nat.dvd_iff_mod_eq_zero, \u2190 e\u2081],\n  apply nat.min_fac_dvd\nend\n\nlemma min_fac_helper_4 (n k : \u2115) (hd : bit1 n % bit1 k = 0)\n  (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=\nby { rw \u2190 nat.dvd_iff_mod_eq_zero at hd,\n  exact le_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2 }\n\nlemma min_fac_helper_5 (n k k' : \u2115) (e : bit1 k * bit1 k = k')\n  (hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=\nbegin\n  refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2\n    \u27e8nat.bit1_lt h.n_pos, _\u27e9)).2,\n  rw \u2190 e at hd,\n  intros m m2 hm md,\n  have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),\n  rw nat.le_sqrt at this,\n  exact not_le_of_lt hd this\nend\n\n/-- Given `e` a natural numeral and `d : nat` a factor of it, return `\u22a2 \u00ac prime e`. -/\nmeta def prove_non_prime (e : expr) (n d\u2081 : \u2115) : tactic expr :=\ndo let e\u2081 := reflect d\u2081,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n  let d\u2082 := n / d\u2081, let e\u2082 := reflect d\u2082,\n  (c, e', p) \u2190 prove_mul_nat c e\u2081 e\u2082,\n  guard (e' =\u2090 e),\n  (c, p\u2082) \u2190 prove_lt_nat c `(1) e\u2082,\n  return $ `(@nat.not_prime_mul').mk_app [e\u2081, e\u2082, e, p, p\u2081, p\u2082]\n\n/-- Given `a`,`a1 := bit1 a`, `n1` the value of `a1`, `b` and `p : min_fac_helper a b`,\n  returns `(c, \u22a2 min_fac a1 = c)`. -/\nmeta def prove_min_fac_aux (a a1 : expr) (n1 : \u2115) :\n  instance_cache \u2192 expr \u2192 expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| ic b p := do\n  k \u2190 b.to_nat,\n  let k1 := bit1 k,\n  let b1 := `(bit1:\u2115\u2192\u2115).mk_app [b],\n  if n1 < k1*k1 then do\n    (ic, e', p\u2081) \u2190 prove_mul_nat ic b1 b1,\n    (ic, p\u2082) \u2190 prove_lt_nat ic a1 e',\n    return (ic, a1, `(min_fac_helper_5).mk_app [a, b, e', p\u2081, p\u2082, p])\n  else let d := k1.min_fac in\n  if to_bool (d < k1) then do\n    let k' := k+1, let e' := reflect k',\n    (ic, p\u2081) \u2190 prove_succ ic b e',\n    p\u2082 \u2190 prove_non_prime b1 k1 d,\n    prove_min_fac_aux ic e' $ `(min_fac_helper_2).mk_app [a, b, e', p\u2081, p\u2082, p]\n  else do\n    let nc := n1 % k1,\n    (ic, c, pc) \u2190 prove_div_mod ic a1 b1 tt,\n    if nc = 0 then\n      return (ic, b1, `(min_fac_helper_4).mk_app [a, b, pc, p])\n    else do\n      (ic, p\u2080) \u2190 prove_pos ic c,\n      let k' := k+1, let e' := reflect k',\n      (ic, p\u2081) \u2190 prove_succ ic b e',\n      prove_min_fac_aux ic e' $ `(min_fac_helper_3).mk_app [a, b, e', c, p\u2081, pc, p\u2080, p]\n\n/-- Given `a` a natural numeral, returns `(b, \u22a2 min_fac a = b)`. -/\nmeta def prove_min_fac (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\nmatch match_numeral e with\n| match_numeral_result.zero := return (ic, `(2:\u2115), `(nat.min_fac_zero))\n| match_numeral_result.one := return (ic, `(1:\u2115), `(nat.min_fac_one))\n| match_numeral_result.bit0 e := return (ic, `(2), `(min_fac_bit0).mk_app [e])\n| match_numeral_result.bit1 e := do\n  n \u2190 e.to_nat,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p) \u2190 prove_pos c e,\n  let a1 := `(bit1:\u2115\u2192\u2115).mk_app [e],\n  prove_min_fac_aux e a1 (bit1 n) c `(1) (`(min_fac_helper_0).mk_app [e, p])\n| _ := failed\nend\n\n/-- A partial proof of `factors`. Asserts that `l` is a sorted list of primes, lower bounded by a\nprime `p`, which multiplies to `n`. -/\ndef factors_helper (n p : \u2115) (l : list \u2115) : Prop :=\np.prime \u2192 list.chain (\u2264) p l \u2227 (\u2200 a \u2208 l, nat.prime a) \u2227 list.prod l = n\n\nlemma factors_helper_nil (a : \u2115) : factors_helper 1 a [] :=\n\u03bb pa, \u27e8list.chain.nil, by rintro _ \u27e8\u27e9, list.prod_nil\u27e9\n\nlemma factors_helper_cons' (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a \u2264 b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\n\u03bb pa,\n  have pb : b.prime, from nat.prime_def_min_fac.2 \u27e8le_trans pa.two_le h\u2082, h\u2083\u27e9,\n  let \u27e8f\u2081, f\u2082, f\u2083\u27e9 := H pb in\n  \u27e8list.chain.cons h\u2082 f\u2081, \u03bb c h, h.elim (\u03bb e, e.symm \u25b8 pb) (f\u2082 _),\n   by rw [list.prod_cons, f\u2083, h\u2081]\u27e9\n\nlemma factors_helper_cons (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a < b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\nfactors_helper_cons' _ _ _ _ _ h\u2081 h\u2082.le h\u2083 H\n\nlemma factors_helper_sn (n a : \u2115) (h\u2081 : a < n) (h\u2082 : nat.min_fac n = n) : factors_helper n a [n] :=\nfactors_helper_cons _ _ _ _ _ (mul_one _) h\u2081 h\u2082 (factors_helper_nil _)\n\nlemma factors_helper_same (n m a : \u2115) (l : list \u2115) (h : a * m = n)\n  (H : factors_helper m a l) : factors_helper n a (a :: l) :=\n\u03bb pa, factors_helper_cons' _ _ _ _ _ h le_rfl (nat.prime_def_min_fac.1 pa).2 H pa\n\nlemma factors_helper_same_sn (a : \u2115) : factors_helper a a [a] :=\nfactors_helper_same _ _ _ _ (mul_one _) (factors_helper_nil _)\n\nlemma factors_helper_end (n : \u2115) (l : list \u2115) (H : factors_helper n 2 l) : nat.factors n = l :=\nlet \u27e8h\u2081, h\u2082, h\u2083\u27e9 := H nat.prime_two in\nhave _, from (list.chain'_iff_pairwise (@le_trans _ _)).1 (@list.chain'.tail _ _ (_::_) h\u2081),\n(list.eq_of_perm_of_sorted (nat.factors_unique h\u2083 h\u2082) this (nat.factors_sorted _)).symm\n\n/-- Given `n` and `a` natural numerals, returns `(l, \u22a2 factors_helper n a l)`. -/\nmeta def prove_factors_aux :\n  instance_cache \u2192 expr \u2192 expr \u2192 \u2115 \u2192 \u2115 \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| c en ea n a :=\n  let b := n.min_fac in\n  if b < n then do\n    let m := n / b,\n    (c, em) \u2190 c.of_nat m,\n    if b = a then do\n      (c, _, p\u2081) \u2190 prove_mul_nat c ea em,\n      (c, l, p\u2082) \u2190 prove_factors_aux c em ea m a,\n      pure (c, `(%%ea::%%l:list \u2115), `(factors_helper_same).mk_app [en, em, ea, l, p\u2081, p\u2082])\n    else do\n      (c, eb) \u2190 c.of_nat b,\n      (c, _, p\u2081) \u2190 prove_mul_nat c eb em,\n      (c, p\u2082) \u2190 prove_lt_nat c ea eb,\n      (c, _, p\u2083) \u2190 prove_min_fac c eb,\n      (c, l, p\u2084) \u2190 prove_factors_aux c em eb m b,\n      pure (c, `(%%eb::%%l : list \u2115),\n        `(factors_helper_cons).mk_app [en, em, ea, eb, l, p\u2081, p\u2082, p\u2083, p\u2084])\n  else if b = a then\n    pure (c, `([%%ea] : list \u2115), `(factors_helper_same_sn).mk_app [ea])\n  else do\n    (c, p\u2081) \u2190 prove_lt_nat c ea en,\n    (c, _, p\u2082) \u2190 prove_min_fac c en,\n    pure (c, `([%%en] : list \u2115), `(factors_helper_sn).mk_app [en, ea, p\u2081, p\u2082])\n\n/-- Evaluates the `prime` and `min_fac` functions. -/\n@[norm_num] meta def eval_prime : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.prime %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := false_intro `(nat.not_prime_zero)\n  | 1 := false_intro `(nat.not_prime_one)\n  | _ := let d\u2081 := n.min_fac in\n    if d\u2081 < n then prove_non_prime e n d\u2081 >>= false_intro\n    else do\n      let e\u2081 := reflect d\u2081,\n      c \u2190 mk_instance_cache `(\u2115),\n      (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n      (c, e\u2081, p) \u2190 prove_min_fac c e,\n      true_intro $ `(is_prime_helper).mk_app [e, p\u2081, p]\n  end\n| `(nat.min_fac %%e) := do\n  ic \u2190 mk_instance_cache `(\u2115),\n  prod.snd <$> prove_min_fac ic e\n| `(nat.factors %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := pure (`(@list.nil \u2115), `(nat.factors_zero))\n  | 1 := pure (`(@list.nil \u2115), `(nat.factors_one))\n  | _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, l, p) \u2190 prove_factors_aux c e `(2) n 2,\n    pure (l, `(factors_helper_end).mk_app [e, l, p])\n  end\n| _ := failed\n\nend norm_num\nend tactic\n\nnamespace nat\n\ntheorem prime_three : prime 3 := by norm_num\n\ninstance fact_prime_two : fact (prime 2) := \u27e8prime_two\u27e9\n\ninstance fact_prime_three : fact (prime 3) := \u27e8prime_three\u27e9\n\nend nat\n\n\nnamespace nat\n\nlemma mem_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) {p : \u2115} :\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u2228 p \u2208 b.factors :=\nbegin\n  rw [mem_factors (mul_ne_zero ha hb), mem_factors ha, mem_factors hb, \u2190and_or_distrib_left],\n  simpa only [and.congr_right_iff] using prime.dvd_mul\nend\n\n/-- If `a`, `b` are positive, the prime divisors of `a * b` are the union of those of `a` and `b` -/\nlemma factors_mul_to_finset {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a * b).factors.to_finset = a.factors.to_finset \u222a b.factors.to_finset :=\n(list.to_finset.ext $ \u03bb x, (mem_factors_mul ha hb).trans list.mem_union.symm).trans $\n  list.to_finset_union _ _\n\nlemma pow_succ_factors_to_finset (n k : \u2115) :\n  (n^(k+1)).factors.to_finset = n.factors.to_finset :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  induction k with k ih,\n  { simp },\n  rw [pow_succ, factors_mul_to_finset hn (pow_ne_zero _ hn), ih, finset.union_idempotent]\nend\n\nlemma pow_factors_to_finset (n : \u2115) {k : \u2115} (hk : k \u2260 0) :\n  (n^k).factors.to_finset = n.factors.to_finset :=\nbegin\n  cases k,\n  { simpa using hk },\n  rw pow_succ_factors_to_finset\nend\n\n/-- The only prime divisor of positive prime power `p^k` is `p` itself -/\nlemma prime_pow_prime_divisor {p k : \u2115} (hk : k \u2260 0) (hp : prime p) :\n  (p^k).factors.to_finset = {p} :=\nby simp [pow_factors_to_finset p hk, factors_prime hp]\n\n/-- The sets of factors of coprime `a` and `b` are disjoint -/\nlemma coprime_factors_disjoint {a b : \u2115} (hab : a.coprime b) : list.disjoint a.factors b.factors :=\nbegin\n  intros q hqa hqb,\n  apply not_prime_one,\n  rw \u2190(eq_one_of_dvd_coprimes hab (dvd_of_mem_factors hqa) (dvd_of_mem_factors hqb)),\n  exact prime_of_mem_factors hqa\nend\n\nlemma mem_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) (p : \u2115) :\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u222a b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  rw [mem_factors_mul ha.ne' hb.ne', list.mem_union]\nend\n\nlemma factors_mul_to_finset_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factors.to_finset = a.factors.to_finset \u222a b.factors.to_finset :=\n(list.to_finset.ext $ mem_factors_mul_of_coprime hab).trans $ list.to_finset_union _ _\n\nopen list\n\n/-- For `0 < b`, the power of `p` in `a * b` is at least that in `a` -/\nlemma le_factors_count_mul_left {p a b : \u2115} (hb : 0 < b) :\n  list.count p a.factors \u2264 list.count p (a * b).factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp },\n  { rw [perm.count_eq (perm_factors_mul_of_pos ha hb) p, count_append p], simp },\nend\n\n/-- For `a > 0`, the power of `p` in `a * b` is at least that in `b` -/\nlemma le_factors_count_mul_right {p a b : \u2115} (ha : 0 < a) :\n  list.count p b.factors \u2264 list.count p (a * b).factors :=\nby { rw mul_comm, apply le_factors_count_mul_left ha }\n\n/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/\nlemma mem_factors_mul_left {p a b : \u2115} (hpa : p \u2208 a.factors) (hb : 0 < b) : p \u2208 (a*b).factors :=\nby { rw \u2190list.count_pos, exact gt_of_ge_of_gt (le_factors_count_mul_left hb) (count_pos.mpr hpa) }\n\n/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/\nlemma mem_factors_mul_right {p a b : \u2115} (hpb : p \u2208 b.factors) (ha : 0 < a) : p \u2208 (a*b).factors :=\nby { rw mul_comm, exact mem_factors_mul_left hpb ha }\n\n/-- If `p` is a prime factor of `a` then the power of `p` in `a` is the same that in `a * b`,\nfor any `b` coprime to `a`. -/\nlemma factors_count_eq_of_coprime_left {p a b : \u2115} (hab : coprime a b) (hpa : p \u2208 a.factors) :\n  list.count p (a * b).factors = list.count p a.factors :=\nbegin\n  rw count_factors_mul_of_coprime hab,\n  simpa only [count_eq_zero_of_not_mem (coprime_factors_disjoint hab hpa)],\nend\n\n/-- If `p` is a prime factor of `b` then the power of `p` in `b` is the same that in `a * b`,\nfor any `a` coprime to `b`. -/\nlemma factors_count_eq_of_coprime_right {p a b : \u2115} (hab : coprime a b) (hpb : p \u2208 b.factors) :\n  list.count p (a * b).factors = list.count p b.factors :=\nby { rw mul_comm, exact factors_count_eq_of_coprime_left (coprime_comm.mp hab) hpb }\n\nend nat\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/nat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.7343644016980156}}
{"text": "/-\nCopyright (c) 2020 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Yury Kudryashov\n-/\nimport analysis.calculus.deriv\nimport measure_theory.constructions.borel_space\nimport measure_theory.function.strongly_measurable\nimport tactic.ring_exp\n\n/-!\n# Derivative is measurable\n\nIn this file we prove that the derivative of any function with complete codomain is a measurable\nfunction. Namely, we prove:\n\n* `measurable_set_of_differentiable_at`: the set `{x | differentiable_at \ud835\udd5c f x}` is measurable;\n* `measurable_fderiv`: the function `fderiv \ud835\udd5c f` is measurable;\n* `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `\u03bb x, fderiv \ud835\udd5c f x y`\n  is measurable;\n* `measurable_deriv`: the function `deriv f` is measurable (for `f : \ud835\udd5c \u2192 F`).\n\n## Implementation\n\nWe give a proof that avoids second-countability issues, by expressing the differentiability set\nas a function of open sets in the following way. Define `A (L, r, \u03b5)` to be the set of points\nwhere, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the\nlinear map `L`, up to `\u03b5 r`. It is an open set.\nLet also `B (L, r, s, \u03b5) = A (L, r, \u03b5) \u2229 A (L, s, \u03b5)`: we require that at two possibly different\nscales `r` and `s`, the function is well approximated by the linear map `L`. It is also open.\n\nWe claim that the differentiability set of `f` is exactly\n`D = \u22c2 \u03b5 > 0, \u22c3 \u03b4 > 0, \u22c2 r, s < \u03b4, \u22c3 L, B (L, r, s, \u03b5)`.\nIn other words, for any `\u03b5 > 0`, we require that there is a size `\u03b4` such that, for any two scales\nbelow this size, the function is well approximated by a linear map, common to the two scales.\n\nThe set `\u22c3 L, B (L, r, s, \u03b5)` is open, as a union of open sets. Converting the intersections and\nunions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the\ndifferentiability set is measurable.\n\nTo prove the claim, there are two inclusions. One is trivial: if the function is differentiable\nat `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the\ndifferentiability exactly says that the map is well approximated by `L`). This is proved in\n`mem_A_of_differentiable` and `differentiable_set_subset_D`.\n\nFor the other direction, the difficulty is that `L` in the union may depend on `\u03b5, r, s`. The key\npoint is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to\n`A (L, r, \u03b5)` and `A (L', r, \u03b5)`, then `L` and `L'` have to be close on a shell, and thus\n`\u2225L - L'\u2225` is bounded by `\u03b5` (see `norm_sub_le_of_mem_A`). Assume now `x \u2208 D`. If one has two maps\n`L` and `L'` such that `x` belongs to `A (L, r, \u03b5)` and to `A (L', r', \u03b5')`, one deduces that `L` is\nclose to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a\nlinear map `L\u2081` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `\u03b5` (it exists as\n`x` belongs to `D`). Take also `L\u2082` that approximates `f` around `x` both at scales `r'` and `s`\nw.r.t. `\u03b5'`. Then `L\u2081` is close to `L` (as they are close on a shell of radius `r`), and `L\u2082` is\nclose to `L\u2081` (as they are close on a shell of radius `s`), and `L'` is close to `L\u2082` (as they are\nclose on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed.\n\nIt follows that the different approximating linear maps that show up form a Cauchy sequence when\n`\u03b5` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`.\nWith the same kind of arguments, one checks that `f` is differentiable with derivative `f'`.\n\nTo show that the derivative itself is measurable, add in the definition of `B` and `D` a set\n`K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K`\nis exactly the set of points where `f` is differentiable with a derivative in `K`.\n\n## Tags\n\nderivative, measurable function, Borel \u03c3-algebra\n-/\n\nnoncomputable theory\n\nopen set metric asymptotics filter continuous_linear_map\nopen topological_space (second_countable_topology) measure_theory\nopen_locale topological_space\n\nnamespace continuous_linear_map\n\nvariables {\ud835\udd5c E F : Type*} [nondiscrete_normed_field \ud835\udd5c]\n  [normed_group E] [normed_space \ud835\udd5c E] [normed_group F] [normed_space \ud835\udd5c F]\n\nlemma measurable_apply\u2082 [measurable_space E] [opens_measurable_space E]\n  [second_countable_topology E] [second_countable_topology (E \u2192L[\ud835\udd5c] F)]\n  [measurable_space F] [borel_space F] :\n  measurable (\u03bb p : (E \u2192L[\ud835\udd5c] F) \u00d7 E, p.1 p.2) :=\nis_bounded_bilinear_map_apply.continuous.measurable\n\nend continuous_linear_map\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\nvariables {E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\nvariables {F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\nvariables {f : E \u2192 F} (K : set (E \u2192L[\ud835\udd5c] F))\n\nnamespace fderiv_measurable_aux\n\n/-- The set `A f L r \u03b5` is the set of points `x` around which the function `f` is well approximated\nat scale `r` by the linear map `L`, up to an error `\u03b5`. We tweak the definition to make sure that\nthis is an open set.-/\ndef A (f : E \u2192 F) (L : E \u2192L[\ud835\udd5c] F) (r \u03b5 : \u211d) : set E :=\n{x | \u2203 r' \u2208 Ioc (r/2) r, \u2200 y z \u2208 ball x r', \u2225f z - f y - L (z-y)\u2225 \u2264 \u03b5 * r}\n\n/-- The set `B f K r s \u03b5` is the set of points `x` around which there exists a continuous linear map\n`L` belonging to `K` (a given set of continuous linear maps) that approximates well the\nfunction `f` (up to an error `\u03b5`), simultaneously at scales `r` and `s`. -/\ndef B (f : E \u2192 F) (K : set (E \u2192L[\ud835\udd5c] F)) (r s \u03b5 : \u211d) : set E :=\n\u22c3 (L \u2208 K), (A f L r \u03b5) \u2229 (A f L s \u03b5)\n\n/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its\nmain use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,\nwith a derivative in `K`. -/\ndef D (f : E \u2192 F) (K : set (E \u2192L[\ud835\udd5c] F)) : set E :=\n\u22c2 (e : \u2115), \u22c3 (n : \u2115), \u22c2 (p \u2265 n) (q \u2265 n), B f K ((1/2) ^ p) ((1/2) ^ q) ((1/2) ^ e)\n\nlemma is_open_A (L : E \u2192L[\ud835\udd5c] F) (r \u03b5 : \u211d) : is_open (A f L r \u03b5) :=\nbegin\n  rw metric.is_open_iff,\n  rintros x \u27e8r', r'_mem, hr'\u27e9,\n  obtain \u27e8s, s_gt, s_lt\u27e9 : \u2203 (s : \u211d), r / 2 < s \u2227 s < r' := exists_between r'_mem.1,\n  have : s \u2208 Ioc (r/2) r := \u27e8s_gt, le_of_lt (s_lt.trans_le r'_mem.2)\u27e9,\n  refine \u27e8r' - s, by linarith, \u03bb x' hx', \u27e8s, this, _\u27e9\u27e9,\n  have B : ball x' s \u2286 ball x r' := ball_subset (le_of_lt hx'),\n  assume y hy z hz,\n  exact hr' y (B hy) z (B hz)\nend\n\nlemma is_open_B {K : set (E \u2192L[\ud835\udd5c] F)} {r s \u03b5 : \u211d} : is_open (B f K r s \u03b5) :=\nby simp [B, is_open_Union, is_open.inter, is_open_A]\n\nlemma A_mono (L : E \u2192L[\ud835\udd5c] F) (r : \u211d) {\u03b5 \u03b4 : \u211d} (h : \u03b5 \u2264 \u03b4) :\n  A f L r \u03b5 \u2286 A f L r \u03b4 :=\nbegin\n  rintros x \u27e8r', r'r, hr'\u27e9,\n  refine \u27e8r', r'r, \u03bb y hy z hz, (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h _)\u27e9,\n  linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x],\nend\n\n\n\nlemma mem_A_of_differentiable {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {x : E} (hx : differentiable_at \ud835\udd5c f x) :\n  \u2203 R > 0, \u2200 r \u2208 Ioo (0 : \u211d) R, x \u2208 A f (fderiv \ud835\udd5c f x) r \u03b5 :=\nbegin\n  have := hx.has_fderiv_at,\n  simp only [has_fderiv_at, has_fderiv_at_filter, is_o_iff] at this,\n  rcases eventually_nhds_iff_ball.1 (this (half_pos h\u03b5)) with \u27e8R, R_pos, hR\u27e9,\n  refine \u27e8R, R_pos, \u03bb r hr, _\u27e9,\n  have : r \u2208 Ioc (r/2) r := \u27e8half_lt_self hr.1, le_rfl\u27e9,\n  refine \u27e8r, this, \u03bb y hy z hz, _\u27e9,\n  calc  \u2225f z - f y - (fderiv \ud835\udd5c f x) (z - y)\u2225\n      = \u2225(f z - f x - (fderiv \ud835\udd5c f x) (z - x)) - (f y - f x - (fderiv \ud835\udd5c f x) (y - x))\u2225 :\n    by { congr' 1, simp only [continuous_linear_map.map_sub], abel }\n  ... \u2264 \u2225(f z - f x - (fderiv \ud835\udd5c f x) (z - x))\u2225 + \u2225f y - f x - (fderiv \ud835\udd5c f x) (y - x)\u2225 :\n    norm_sub_le _ _\n  ... \u2264 \u03b5 / 2 * \u2225z - x\u2225 + \u03b5 / 2 * \u2225y - x\u2225 :\n    add_le_add (hR _ (lt_trans (mem_ball.1 hz) hr.2)) (hR _ (lt_trans (mem_ball.1 hy) hr.2))\n  ... \u2264 \u03b5 / 2 * r + \u03b5 / 2 * r :\n    add_le_add\n      (mul_le_mul_of_nonneg_left (le_of_lt (mem_ball_iff_norm.1 hz)) (le_of_lt (half_pos h\u03b5)))\n      (mul_le_mul_of_nonneg_left (le_of_lt (mem_ball_iff_norm.1 hy)) (le_of_lt (half_pos h\u03b5)))\n  ... = \u03b5 * r : by ring\nend\n\nlemma norm_sub_le_of_mem_A {c : \ud835\udd5c} (hc : 1 < \u2225c\u2225)\n  {r \u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) (hr : 0 < r) {x : E} {L\u2081 L\u2082 : E \u2192L[\ud835\udd5c] F}\n  (h\u2081 : x \u2208 A f L\u2081 r \u03b5) (h\u2082 : x \u2208 A f L\u2082 r \u03b5) : \u2225L\u2081 - L\u2082\u2225 \u2264 4 * \u2225c\u2225 * \u03b5 :=\nbegin\n  have : 0 \u2264 4 * \u2225c\u2225 * \u03b5 :=\n    mul_nonneg (mul_nonneg (by norm_num : (0 : \u211d) \u2264 4) (norm_nonneg _)) h\u03b5.le,\n  refine op_norm_le_of_shell (half_pos hr) this hc _,\n  assume y ley ylt,\n  rw [div_div_eq_div_mul,\n      div_le_iff' (mul_pos (by norm_num : (0 : \u211d) < 2) (zero_lt_one.trans hc))] at ley,\n  calc \u2225(L\u2081 - L\u2082) y\u2225\n        = \u2225(f (x + y) - f x - L\u2082 ((x + y) - x)) - (f (x + y) - f x - L\u2081 ((x + y) - x))\u2225 : by simp\n    ... \u2264 \u2225(f (x + y) - f x - L\u2082 ((x + y) - x))\u2225 + \u2225(f (x + y) - f x - L\u2081 ((x + y) - x))\u2225 :\n      norm_sub_le _ _\n    ... \u2264 \u03b5 * r + \u03b5 * r :\n      begin\n        apply add_le_add,\n        { apply le_of_mem_A h\u2082,\n          { simp only [le_of_lt (half_pos hr), mem_closed_ball, dist_self] },\n          { simp only [dist_eq_norm, add_sub_cancel', mem_closed_ball, ylt.le], } },\n        { apply le_of_mem_A h\u2081,\n          { simp only [le_of_lt (half_pos hr), mem_closed_ball, dist_self] },\n          { simp only [dist_eq_norm, add_sub_cancel', mem_closed_ball, ylt.le] } },\n      end\n    ... = 2 * \u03b5 * r : by ring\n    ... \u2264 2 * \u03b5 * (2 * \u2225c\u2225 * \u2225y\u2225) : mul_le_mul_of_nonneg_left ley (mul_nonneg (by norm_num) h\u03b5.le)\n    ... = 4 * \u2225c\u2225 * \u03b5 * \u2225y\u2225 : by ring\nend\n\n/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/\nlemma differentiable_set_subset_D : {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} \u2286 D f K :=\nbegin\n  assume x hx,\n  rw [D, mem_Inter],\n  assume e,\n  have : (0 : \u211d) < (1/2) ^ e := pow_pos (by norm_num) _,\n  rcases mem_A_of_differentiable this hx.1 with \u27e8R, R_pos, hR\u27e9,\n  obtain \u27e8n, hn\u27e9 : \u2203 (n : \u2115), (1/2) ^ n < R :=\n    exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : \u211d)/2 < 1),\n  simp only [mem_Union, mem_Inter, B, mem_inter_eq],\n  refine \u27e8n, \u03bb p hp q hq, \u27e8fderiv \ud835\udd5c f x, hx.2, \u27e8_, _\u27e9\u27e9\u27e9;\n  { refine hR _ \u27e8pow_pos (by norm_num) _, lt_of_le_of_lt _ hn\u27e9,\n    exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) }\nend\n\n/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/\nlemma D_subset_differentiable_set {K : set (E \u2192L[\ud835\udd5c] F)} (hK : is_complete K) :\n  D f K \u2286 {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} :=\nbegin\n  have P : \u2200 {n : \u2115}, (0 : \u211d) < (1/2) ^ n := pow_pos (by norm_num),\n  rcases normed_field.exists_one_lt_norm \ud835\udd5c with \u27e8c, hc\u27e9,\n  have cpos : 0 < \u2225c\u2225 := lt_trans zero_lt_one hc,\n  assume x hx,\n  have : \u2200 (e : \u2115), \u2203 (n : \u2115), \u2200 p q, n \u2264 p \u2192 n \u2264 q \u2192 \u2203 L \u2208 K,\n    x \u2208 A f L ((1/2) ^ p) ((1/2) ^ e) \u2229 A f L ((1/2) ^ q) ((1/2) ^ e),\n  { assume e,\n    have := mem_Inter.1 hx e,\n    rcases mem_Union.1 this with \u27e8n, hn\u27e9,\n    refine \u27e8n, \u03bb p q hp hq, _\u27e9,\n    simp only [mem_Inter, ge_iff_le] at hn,\n    rcases mem_Union.1 (hn p hp q hq) with \u27e8L, hL\u27e9,\n    exact \u27e8L, mem_Union.1 hL\u27e9, },\n  /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`\n  such that, for `p, q \u2265 n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and\n  `2 ^ (-q)`, with an error `2 ^ (-e)`. -/\n  choose! n L hn using this,\n  /- All the operators `L e p q` that show up are close to each other. To prove this, we argue\n    that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at\n    scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale\n    `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale\n    `2 ^ (- p')`. -/\n  have M : \u2200 e p q e' p' q', n e \u2264 p \u2192 n e \u2264 q \u2192 n e' \u2264 p' \u2192 n e' \u2264 q' \u2192 e \u2264 e' \u2192\n    \u2225L e p q - L e' p' q'\u2225 \u2264 12 * \u2225c\u2225 * (1/2) ^ e,\n  { assume e p q e' p' q' hp hq hp' hq' he',\n    let r := max (n e) (n e'),\n    have I : ((1:\u211d)/2)^e' \u2264 (1/2)^e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he',\n    have J1 : \u2225L e p q - L e p r\u2225 \u2264 4 * \u2225c\u2225 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p q) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p q hp hq).2.1,\n      have I2 : x \u2208 A f (L e p r) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.1,\n      exact norm_sub_le_of_mem_A hc P P I1 I2 },\n    have J2 : \u2225L e p r - L e' p' r\u2225 \u2264 4 * \u2225c\u2225 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p r) ((1 / 2) ^ r) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.2,\n      have I2 : x \u2208 A f (L e' p' r) ((1 / 2) ^ r) ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.2,\n      exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2) },\n    have J3 : \u2225L e' p' r - L e' p' q'\u2225 \u2264 4 * \u2225c\u2225 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e' p' r) ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.1,\n      have I2 : x \u2208 A f (L e' p' q') ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' q' hp' hq').2.1,\n      exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2) },\n    calc \u2225L e p q - L e' p' q'\u2225\n          = \u2225(L e p q - L e p r) + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')\u2225 :\n        by { congr' 1, abel }\n      ... \u2264 \u2225L e p q - L e p r\u2225 + \u2225L e p r - L e' p' r\u2225 + \u2225L e' p' r - L e' p' q'\u2225 :\n        le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)\n      ... \u2264 4 * \u2225c\u2225 * (1/2)^e + 4 * \u2225c\u2225 * (1/2)^e + 4 * \u2225c\u2225 * (1/2)^e :\n        by apply_rules [add_le_add]\n      ... = 12 * \u2225c\u2225 * (1/2)^e : by ring },\n  /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this\n  is a Cauchy sequence. -/\n  let L0 : \u2115 \u2192 (E \u2192L[\ud835\udd5c] F) := \u03bb e, L e (n e) (n e),\n  have : cauchy_seq L0,\n  { rw metric.cauchy_seq_iff',\n    assume \u03b5 \u03b5pos,\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1/2) ^ e < \u03b5 / (12 * \u2225c\u2225) :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos (mul_pos (by norm_num) cpos)) (by norm_num),\n    refine \u27e8e, \u03bb e' he', _\u27e9,\n    rw [dist_comm, dist_eq_norm],\n    calc \u2225L0 e - L0 e'\u2225\n          \u2264 12 * \u2225c\u2225 * (1/2)^e : M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'\n      ... < 12 * \u2225c\u2225 * (\u03b5 / (12 * \u2225c\u2225)) :\n        mul_lt_mul' le_rfl he (le_of_lt P) (mul_pos (by norm_num) cpos)\n      ... = \u03b5 : by { field_simp [(by norm_num : (12 : \u211d) \u2260 0), ne_of_gt cpos], ring } },\n  /- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.-/\n  obtain \u27e8f', f'K, hf'\u27e9 : \u2203 f' \u2208 K, tendsto L0 at_top (\ud835\udcdd f') :=\n    cauchy_seq_tendsto_of_is_complete hK (\u03bb e, (hn e (n e) (n e) le_rfl le_rfl).1) this,\n  have Lf' : \u2200 e p, n e \u2264 p \u2192 \u2225L e (n e) p - f'\u2225 \u2264 12 * \u2225c\u2225 * (1/2)^e,\n  { assume e p hp,\n    apply le_of_tendsto (tendsto_const_nhds.sub hf').norm,\n    rw eventually_at_top,\n    exact \u27e8e, \u03bb e' he', M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'\u27e9 },\n  /- Let us show that `f` has derivative `f'` at `x`. -/\n  have : has_fderiv_at f f' x,\n  { simp only [has_fderiv_at_iff_is_o_nhds_zero, is_o_iff],\n    /- to get an approximation with a precision `\u03b5`, we will replace `f` with `L e (n e) m` for\n    some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,\n    this makes it possible to cover all scales, and thus to obtain a good linear approximation in\n    the whole ball of radius `(1/2)^(n e)`. -/\n    assume \u03b5 \u03b5pos,\n    have pos : 0 < 4 + 12 * \u2225c\u2225 :=\n      add_pos_of_pos_of_nonneg (by norm_num) (mul_nonneg (by norm_num) (norm_nonneg _)),\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1 / 2) ^ e < \u03b5 / (4 + 12 * \u2225c\u2225) :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos pos) (by norm_num),\n    rw eventually_nhds_iff_ball,\n    refine \u27e8(1/2) ^ (n e + 1), P, \u03bb y hy, _\u27e9,\n    -- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale\n    -- `k` where `k` is chosen with `\u2225y\u2225 \u223c 2 ^ (-k)`.\n    by_cases y_pos : y = 0, {simp [y_pos] },\n    have yzero : 0 < \u2225y\u2225 := norm_pos_iff.mpr y_pos,\n    have y_lt : \u2225y\u2225 < (1/2) ^ (n e + 1), by simpa using mem_ball_iff_norm.1 hy,\n    have yone : \u2225y\u2225 \u2264 1 :=\n      le_trans (y_lt.le) (pow_le_one _ (by norm_num) (by norm_num)),\n    -- define the scale `k`.\n    obtain \u27e8k, hk, h'k\u27e9 : \u2203 (k : \u2115), (1/2) ^ (k + 1) < \u2225y\u2225 \u2227 \u2225y\u2225 \u2264 (1/2) ^ k :=\n      exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : \u211d) < 1/2)\n      (by norm_num : (1 : \u211d)/2 < 1),\n    -- the scale is large enough (as `y` is small enough)\n    have k_gt : n e < k,\n    { have : ((1:\u211d)/2) ^ (k + 1) < (1/2) ^ (n e + 1) := lt_trans hk y_lt,\n      rw pow_lt_pow_iff_of_lt_one (by norm_num : (0 : \u211d) < 1/2) (by norm_num) at this,\n      linarith },\n    set m := k - 1 with hl,\n    have m_ge : n e \u2264 m := nat.le_pred_of_lt k_gt,\n    have km : k = m + 1 := (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm,\n    rw km at hk h'k,\n    -- `f` is well approximated by `L e (n e) k` at the relevant scale\n    -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).\n    have J1 : \u2225f (x + y) - f x - L e (n e) m ((x + y) - x)\u2225 \u2264 (1/2) ^ e * (1/2) ^ m,\n    { apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2,\n      { simp only [mem_closed_ball, dist_self],\n        exact div_nonneg (le_of_lt P) (zero_le_two) },\n      { simpa only [dist_eq_norm, add_sub_cancel', mem_closed_ball, pow_succ', mul_one_div]\n          using h'k } },\n    have J2 : \u2225f (x + y) - f x - L e (n e) m y\u2225 \u2264 4 * (1/2) ^ e * \u2225y\u2225 := calc\n      \u2225f (x + y) - f x - L e (n e) m y\u2225 \u2264 (1/2) ^ e * (1/2) ^ m :\n        by simpa only [add_sub_cancel'] using J1\n      ... = 4 * (1/2) ^ e * (1/2) ^ (m + 2) : by { field_simp, ring_exp }\n      ... \u2264 4 * (1/2) ^ e * \u2225y\u2225 :\n        mul_le_mul_of_nonneg_left (le_of_lt hk) (mul_nonneg (by norm_num) (le_of_lt P)),\n    -- use the previous estimates to see that `f (x + y) - f x - f' y` is small.\n    calc \u2225f (x + y) - f x - f' y\u2225\n        = \u2225(f (x + y) - f x - L e (n e) m y) + (L e (n e) m - f') y\u2225 :\n      congr_arg _ (by simp)\n    ... \u2264 4 * (1/2) ^ e * \u2225y\u2225 + 12 * \u2225c\u2225 * (1/2) ^ e * \u2225y\u2225 :\n      norm_add_le_of_le J2\n        ((le_op_norm _ _).trans (mul_le_mul_of_nonneg_right (Lf' _ _ m_ge) (norm_nonneg _)))\n    ... = (4 + 12 * \u2225c\u2225) * \u2225y\u2225 * (1/2) ^ e : by ring\n    ... \u2264 (4 + 12 * \u2225c\u2225) * \u2225y\u2225 * (\u03b5 / (4 + 12 * \u2225c\u2225)) :\n      mul_le_mul_of_nonneg_left he.le\n        (mul_nonneg (add_nonneg (by norm_num) (mul_nonneg (by norm_num) (norm_nonneg _)))\n          (norm_nonneg _))\n    ... = \u03b5 * \u2225y\u2225 : by { field_simp [ne_of_gt pos], ring } },\n  rw \u2190 this.fderiv at f'K,\n  exact \u27e8this.differentiable_at, f'K\u27e9\nend\n\ntheorem differentiable_set_eq_D (hK : is_complete K) :\n  {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} = D f K :=\nsubset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)\n\nend fderiv_measurable_aux\n\nopen fderiv_measurable_aux\n\nvariables [measurable_space E] [opens_measurable_space E]\nvariables (\ud835\udd5c f)\n\n/-- The set of differentiability points of a function, with derivative in a given complete set,\nis Borel-measurable. -/\ntheorem measurable_set_of_differentiable_at_of_is_complete\n  {K : set (E \u2192L[\ud835\udd5c] F)} (hK : is_complete K) :\n  measurable_set {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} :=\nby simp [differentiable_set_eq_D K hK, D, is_open_B.measurable_set, measurable_set.Inter_Prop,\n         measurable_set.Inter, measurable_set.Union]\n\nvariable [complete_space F]\n\n/-- The set of differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurable_set_of_differentiable_at :\n  measurable_set {x | differentiable_at \ud835\udd5c f x} :=\nbegin\n  have : is_complete (univ : set (E \u2192L[\ud835\udd5c] F)) := complete_univ,\n  convert measurable_set_of_differentiable_at_of_is_complete \ud835\udd5c f this,\n  simp\nend\n\n@[measurability] lemma measurable_fderiv : measurable (fderiv \ud835\udd5c f) :=\nbegin\n  refine measurable_of_is_closed (\u03bb s hs, _),\n  have : fderiv \ud835\udd5c f \u207b\u00b9' s = {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 s} \u222a\n    {x | (0 : E \u2192L[\ud835\udd5c] F) \u2208 s} \u2229 {x | \u00acdifferentiable_at \ud835\udd5c f x} :=\n    set.ext (\u03bb x, mem_preimage.trans fderiv_mem_iff),\n  rw this,\n  exact (measurable_set_of_differentiable_at_of_is_complete _ _ hs.is_complete).union\n    ((measurable_set.const _).inter (measurable_set_of_differentiable_at _ _).compl)\nend\n\n@[measurability] lemma measurable_fderiv_apply_const [measurable_space F] [borel_space F] (y : E) :\n  measurable (\u03bb x, fderiv \ud835\udd5c f x y) :=\n(continuous_linear_map.measurable_apply y).comp (measurable_fderiv \ud835\udd5c f)\n\nvariable {\ud835\udd5c}\n\n@[measurability] lemma measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [measurable_space F] [borel_space F] (f : \ud835\udd5c \u2192 F) : measurable (deriv f) :=\nby simpa only [fderiv_deriv] using measurable_fderiv_apply_const \ud835\udd5c f 1\n\nlemma strongly_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [second_countable_topology F] (f : \ud835\udd5c \u2192 F) :\n  strongly_measurable (deriv f) :=\nby { borelize F, exact (measurable_deriv f).strongly_measurable }\n\nlemma ae_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c] [measurable_space F]\n  [borel_space F] (f : \ud835\udd5c \u2192 F) (\u03bc : measure \ud835\udd5c) : ae_measurable (deriv f) \u03bc :=\n(measurable_deriv f).ae_measurable\n\nlemma ae_strongly_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [second_countable_topology F] (f : \ud835\udd5c \u2192 F) (\u03bc : measure \ud835\udd5c) :\n  ae_strongly_measurable (deriv f) \u03bc :=\n(strongly_measurable_deriv f).ae_strongly_measurable\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/calculus/fderiv_measurable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7342856491690997}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport linear_algebra.matrix.determinant\nimport data.mv_polynomial.basic\nimport data.mv_polynomial.comm_ring\n\n/-!\n# Matrices of multivariate polynomials\n\nIn this file, we prove results about matrices over an mv_polynomial ring.\nIn particular, we provide `matrix.mv_polynomial_X` which associates every entry of a matrix with a\nunique variable.\n\n## Tags\n\nmatrix determinant, multivariate polynomial\n-/\nvariables {m n R S : Type*}\n\nnamespace matrix\n\nvariables (m n R)\n\n/-- The matrix with variable `X (i,j)` at location `(i,j)`. -/\nnoncomputable def mv_polynomial_X [comm_semiring R] : matrix m n (mv_polynomial (m \u00d7 n) R) :=\nof $ \u03bb i j, mv_polynomial.X (i, j)\n\n-- TODO: set as an equation lemma for `mv_polynomial_X`, see mathlib4#3024\n@[simp]\nlemma mv_polynomial_X_apply [comm_semiring R] (i j) :\n  mv_polynomial_X m n R i j = mv_polynomial.X (i, j) := rfl\n\nvariables {m n R S}\n\n/-- Any matrix `A` can be expressed as the evaluation of `matrix.mv_polynomial_X`.\n\nThis is of particular use when `mv_polynomial (m \u00d7 n) R` is an integral domain but `S` is\nnot, as if the `mv_polynomial.eval\u2082` can be pulled to the outside of a goal, it can be solved in\nunder cancellative assumptions. -/\nlemma mv_polynomial_X_map_eval\u2082 [comm_semiring R] [comm_semiring S]\n  (f : R \u2192+* S) (A : matrix m n S) :\n  (mv_polynomial_X m n R).map (mv_polynomial.eval\u2082 f $ \u03bb p : m \u00d7 n, A p.1 p.2) = A :=\next $ \u03bb i j, mv_polynomial.eval\u2082_X _ (\u03bb p : m \u00d7 n, A p.1 p.2) (i, j)\n\n/-- A variant of `matrix.mv_polynomial_X_map_eval\u2082` with a bundled `ring_hom` on the LHS. -/\nlemma mv_polynomial_X_map_matrix_eval [fintype m] [decidable_eq m]\n  [comm_semiring R] (A : matrix m m R) :\n  (mv_polynomial.eval $ \u03bb p : m \u00d7 m, A p.1 p.2).map_matrix (mv_polynomial_X m m R) = A :=\nmv_polynomial_X_map_eval\u2082 _ A\n\nvariables (R)\n\n/-- A variant of `matrix.mv_polynomial_X_map_eval\u2082` with a bundled `alg_hom` on the LHS. -/\nlemma mv_polynomial_X_map_matrix_aeval [fintype m] [decidable_eq m]\n  [comm_semiring R] [comm_semiring S] [algebra R S] (A : matrix m m S) :\n  (mv_polynomial.aeval $ \u03bb p : m \u00d7 m, A p.1 p.2).map_matrix (mv_polynomial_X m m R) = A :=\nmv_polynomial_X_map_eval\u2082 _ A\n\nvariables (m R)\n\n/-- In a nontrivial ring, `matrix.mv_polynomial_X m m R` has non-zero determinant. -/\nlemma det_mv_polynomial_X_ne_zero [decidable_eq m] [fintype m] [comm_ring R] [nontrivial R] :\n  det (mv_polynomial_X m m R) \u2260 0 :=\nbegin\n  intro h_det,\n  have := congr_arg matrix.det (mv_polynomial_X_map_matrix_eval (1 : matrix m m R)),\n  rw [det_one, \u2190ring_hom.map_det, h_det, ring_hom.map_zero] at this,\n  exact zero_ne_one this,\nend\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/mv_polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7342856491362584}}
{"text": "/-\nCopyright (c) 2021 Paula Neeley. All rights reserved.\nAuthor: Paula Neeley\n-/\n\nimport basicmodal.language basicmodal.syntax.syntax\nimport logic.basic data.set.basic\nlocal attribute [instance] classical.prop_decidable\n\nopen form\n\n\n---------------------- Semantics ----------------------\n\n\n-- Definition of relational frame\nstructure frame :=\n(states : Type)\n(h : inhabited states)\n(rel : states \u2192 states \u2192 Prop)\n\n\n-- Definition of forces\ndef forces (f : frame) (v : nat \u2192 f.states \u2192 Prop) : f.states \u2192 form \u2192 Prop\n  | x (bot)    := false\n  | x (var n)  := v n x\n  | x (and \u03c6 \u03c8)  := (forces x \u03c6) \u2227 (forces x \u03c8)\n  | x (impl \u03c6 \u03c8) := (forces x \u03c6) \u2192 (forces x \u03c8)\n  | x (box \u03c6)  := \u2200 y, f.rel x y \u2192 forces y \u03c6\n\n\n-- \u03c6 is valid in a model M = (f,v)\ndef m_valid (\u03c6 : form) (f : frame) \n  (v : nat \u2192 f.states \u2192 Prop) := \n  \u2200 x, forces f v x \u03c6\n\n\n-- \u03c6 is valid in a frame f\ndef f_valid (\u03c6 : form) (f : frame) := \n  \u2200 v x, forces f v x \u03c6\n\n\n-- \u03c6 is valid in a class of frames F\ndef F_valid (\u03c6 : form) (F : set (frame)) := \n  \u2200 f \u2208 F, \u2200 v x, forces f v x \u03c6\n\n\n-- \u03c6 is universally valid (valid in all frames)\ndef u_valid (\u03c6 : form) := \n  \u2200 f v x, forces f v x \u03c6\n\n\n-- A context is true at a world in a model if each \n-- formula of the context is true at that world in that model\ndef forces_ctx (f : frame) (v : nat \u2192 f.states \u2192 Prop) \n  (\u0393 : ctx) := \u2200 \u03c6, \u2200 x, \u03c6 \u2208 \u0393 \u2192 forces f v x \u03c6\n\n\n-- Global semantic consequence\ndef global_sem_csq (\u0393 : ctx) (\u03c6 : form) :=\n  \u2200 f v, forces_ctx f v \u0393 \u2192 \u2200 x, forces f v x \u03c6\n\n\nlemma not_forces_imp :  \u2200 f v x \u03c6, \n  (\u00ac(forces f v x \u03c6)) \u2194 (forces f v x (\u00ac\u03c6)) :=\nbegin\nintros f v x \u03c6, split, \nrepeat {intros h1 h2, exact h1 h2},\nend\n\n\nlemma forces_exists {f : frame} {v : nat \u2192 f.states \u2192 Prop} {x : f.states} {\u03c6 : form} :\n  forces f v x (\u25c7\u03c6) \u2194 \u2203 y : f.states, (f.rel x y \u2227 forces f v y \u03c6) :=\nbegin\nsplit, intro h1,\nrepeat {rw forces at h1},\nhave h2 := not_or_of_imp h1,\ncases h2, push_neg at h2,\ncases h2 with y h2, cases h2 with h2 h3,\nexistsi (y : f.states), split, exact h2,\nhave h4 := (not_forces_imp f v y (\u00ac\u03c6)).mp h3,\nrepeat {rw forces at h4}, repeat {rw imp_false at h4},\nrw not_not at h4, exact h4,\nexact false.elim h2,\nintro h1, cases h1 with y h1,\ncases h1 with h1 h2,\nintro h3,\nexact absurd h2 (h3 y h1)\nend", "meta": {"author": "paulaneeley", "repo": "modal", "sha": "ee5d149d4ecb337005b850bddf4453e56a5daf04", "save_path": "github-repos/lean/paulaneeley-modal", "path": "github-repos/lean/paulaneeley-modal/modal-ee5d149d4ecb337005b850bddf4453e56a5daf04/src/basicmodal/semantics/semantics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7342856326617255}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport linear_algebra.matrix.adjugate\nimport ring_theory.matrix_algebra\nimport ring_theory.polynomial_algebra\nimport tactic.apply_fun\nimport tactic.squeeze\n\n/-!\n# Characteristic polynomials and the Cayley-Hamilton theorem\n\nWe define characteristic polynomials of matrices and\nprove the Cayley\u2013Hamilton theorem over arbitrary commutative rings.\n\n## Main definitions\n\n* `matrix.charpoly` is the characteristic polynomial of a matrix.\n\n## Implementation details\n\nWe follow a nice proof from http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\n-/\n\nnoncomputable theory\n\nuniverses u v w\n\nopen polynomial matrix\nopen_locale big_operators\n\nvariables {R : Type u} [comm_ring R]\nvariables {n : Type w} [decidable_eq n] [fintype n]\n\nopen finset\n\n\n/--\nThe \"characteristic matrix\" of `M : matrix n n R` is the matrix of polynomials $t I - M$.\nThe determinant of this matrix is the characteristic polynomial.\n-/\ndef charmatrix (M : matrix n n R) : matrix n n (polynomial R) :=\nmatrix.scalar n (X : polynomial R) - (C : R \u2192+* polynomial R).map_matrix M\n\n@[simp] lemma charmatrix_apply_eq (M : matrix n n R) (i : n) :\n  charmatrix M i i = (X : polynomial R) - C (M i i) :=\nby simp only [charmatrix, sub_left_inj, pi.sub_apply, scalar_apply_eq,\n  ring_hom.map_matrix_apply, map_apply, dmatrix.sub_apply]\n\n@[simp] lemma charmatrix_apply_ne (M : matrix n n R) (i j : n) (h : i \u2260 j) :\n  charmatrix M i j = - C (M i j) :=\nby simp only [charmatrix, pi.sub_apply, scalar_apply_ne _ _ _ h, zero_sub,\n  ring_hom.map_matrix_apply, map_apply, dmatrix.sub_apply]\n\nlemma mat_poly_equiv_charmatrix (M : matrix n n R) :\n  mat_poly_equiv (charmatrix M) = X - C M :=\nbegin\n  ext k i j,\n  simp only [mat_poly_equiv_coeff_apply, coeff_sub, pi.sub_apply],\n  by_cases h : i = j,\n  { subst h, rw [charmatrix_apply_eq, coeff_sub],\n    simp only [coeff_X, coeff_C],\n    split_ifs; simp, },\n  { rw [charmatrix_apply_ne _ _ _ h, coeff_X, coeff_neg, coeff_C, coeff_C],\n    split_ifs; simp [h], }\nend\n\nlemma charmatrix_reindex {m : Type v} [decidable_eq m] [fintype m] (e : n \u2243 m)\n  (M : matrix n n R) : charmatrix (reindex e e M) = reindex e e (charmatrix M) :=\nbegin\n  ext i j x,\n  by_cases h : i = j,\n  all_goals { simp [h] }\nend\n\n/--\nThe characteristic polynomial of a matrix `M` is given by $\\det (t I - M)$.\n-/\ndef matrix.charpoly (M : matrix n n R) : polynomial R :=\n(charmatrix M).det\n\nlemma matrix.charpoly_reindex {m : Type v} [decidable_eq m] [fintype m] (e : n \u2243 m)\n  (M : matrix n n R) : (reindex e e M).charpoly = M.charpoly :=\nbegin\n  unfold matrix.charpoly,\n  rw [charmatrix_reindex, matrix.det_reindex_self]\nend\n\n/--\nThe **Cayley-Hamilton Theorem**, that the characteristic polynomial of a matrix,\napplied to the matrix itself, is zero.\n\nThis holds over any commutative ring.\n-/\n-- This proof follows http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\ntheorem matrix.aeval_self_charpoly (M : matrix n n R) :\n  aeval M M.charpoly = 0 :=\nbegin\n  -- We begin with the fact $\u03c7_M(t) I = adjugate (t I - M) * (t I - M)$,\n  -- as an identity in `matrix n n (polynomial R)`.\n  have h : M.charpoly \u2022 (1 : matrix n n (polynomial R)) =\n    adjugate (charmatrix M) * (charmatrix M) :=\n    (adjugate_mul _).symm,\n  -- Using the algebra isomorphism `matrix n n (polynomial R) \u2243\u2090[R] polynomial (matrix n n R)`,\n  -- we have the same identity in `polynomial (matrix n n R)`.\n  apply_fun mat_poly_equiv at h,\n  simp only [mat_poly_equiv.map_mul,\n    mat_poly_equiv_charmatrix] at h,\n  -- Because the coefficient ring `matrix n n R` is non-commutative,\n  -- evaluation at `M` is not multiplicative.\n  -- However, any polynomial which is a product of the form $N * (t I - M)$\n  -- is sent to zero, because the evaluation function puts the polynomial variable\n  -- to the right of any coefficients, so everything telescopes.\n  apply_fun (\u03bb p, p.eval M) at h,\n  rw eval_mul_X_sub_C at h,\n  -- Now $\u03c7_M (t) I$, when thought of as a polynomial of matrices\n  -- and evaluated at some `N` is exactly $\u03c7_M (N)$.\n  rw [mat_poly_equiv_smul_one, eval_map] at h,\n  -- Thus we have $\u03c7_M(M) = 0$, which is the desired result.\n  exact h,\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/matrix/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7342583472802003}}
{"text": "-- propositions\n-- proofs\n-- predicates\n    -- sets\n    -- relations\n    -- equality\n-- connectives\n    -- not\n    -- and\n    -- or\n\n\n--We represent propositions as types\n-- proposition\ninductive nifty_was_a_cat : Prop  -- Prop = proposition\n\n-- and axiom is value that needs no furthur proof\n-- we represent proofs as values of those types\n-- proofs\n| there_are_pictures_of_nifty\n| we_remember_nifty_fondly\n\nopen nifty_was_a_cat\n\ntheorem nwac : nifty_was_a_cat := there_are_pictures_of_nifty\ntheorem there_is_a_natural_number : \u2115 := 1\n\n/-\nA predicate is a proposition with a perameter\n-/\n\ninductive pet : Type\n| nifty -- a cat\n| fido -- a dog\n| cheese -- a rat\n| tom -- a cat\n\nopen pet\n\n-- predicate\ninductive was_a_cat : pet \u2192 Prop  -- pet \u2192 Prop is a predicate\n| nifty_proof : was_a_cat nifty\n| tom_proof : was_a_cat tom\n\nopen was_a_cat\n\n#check was_a_cat\n#check was_a_cat nifty  -- Prop\n#check was_a_cat tom    -- Prop\n#check was_a_cat cheese -- Prop\n\ntheorem nwac' : was_a_cat nifty := nifty_proof\n\n-- We can equate sets with predicates\n/-\nProperty of a pet: that of having \nbeen a cat. Some have it. Some don't\n-/\n\n/-\nSet of pets: { nifty, tom }.\n-/\n\n/-\nHow might we assert that \"nifty was\na cat AND cheese was a cat\"? Each of\nthese claims is a proposition, in turn\nan object of type Prop, and what we want\nto build is a bigger proposition. Rather\nthan a one-off solution specific to the\ngiven propositions, we'll create a way\nto conjoin any two propositions into a\nlarger one, a conjunction. To build\none it is necessary and sufficient \nto have proofs of each component\nproposition.\nWe want a way to to build an AND\nproposition based on any two smaller\ncomponent propositions. The type of\nour proposition is Prop, and of the\nsmaller propositions, also Prop. So\nwe really need somthing of type\nProp \u2192 Prop \u2192 Prop. This is just a\nProp parameterized by two Props, \nwhich we might call \u03b1 and \u03b2. We\nneed a polymorphic type. \n-/\n\n#print and\n\nnamespace our_logic\n\n/-\nINTRODUCTION\nGiven proofs, \u03b1 and \u03b2, we can build\na proof, (and.intro \u03b1 \u03b2), of \u03b1 \u2227 \u03b2.\nHere are three ways to write exactly\nthe same inductive definition.\n-/\n\ninductive and'' (\u03b1 \u03b2 : Prop) : Prop\n| intro : \u03b1 \u2192 \u03b2 \u2192 and''\n\ninductive and' (\u03b1 \u03b2 : Prop) : Prop\n| intro (left : \u03b1) (right : \u03b2) : and'\n\nstructure and (a b : Prop) : Prop :=\nintro :: (left : a) (right : b)\n\n\ndef nwac_and_cwac : Prop := \n    and'' (was_a_cat nifty) (was_a_cat cheese)\n\ndef pf : nwac_and_cwac :=\n    and''.intro nifty_proof _\n\ndef pf2 :\n    and'' (was_a_cat nifty) (was_a_cat tom) :=\n        and''.intro nifty_proof tom_proof\n\nend our_logic\n\nnamespace our_logic \n\nnotation P ^ Q := and P Q   -- we don't overload \u2227\n\ntheorem were_cats_nifty_and_cheese :\n    was_a_cat nifty ^ was_a_cat cheese :=\nbegin\n    apply and.intro,\n    exact nifty_proof,\n    sorry -- Stuck: no theorem obtained.\nend\n\ntheorem were_cats_nifty_and_tom :\n    was_a_cat nifty ^ was_a_cat tom :=\nbegin\n    apply and.intro,\n    exact nifty_proof,\n    exact tom_proof,    -- Yay, it's a theorem!\nend\n\n/-\nELIMINATION\nIf we have a proof of P ^ Q, we can obtain\nindividual proofs of P and Q, respectively.\n-/\n\ndef and.elim_left {\u03b1 \u03b2 : Prop} : and \u03b1 \u03b2 \u2192 \u03b1\n| (and.intro a b) := a\n\ndef and.elim_right {\u03b1 \u03b2 : Prop} : and \u03b1 \u03b2 \u2192 \u03b2\n| (and.intro a b) := b\n\n/-\nIf we have a proof that nifty was a cat \u2227\ncheese was a cat, then we can deduce a proof\nthat cheese was a cat. Such a proof must be a\npart of the assumed proof of the conjunction.\n-/\ntheorem conj_impl_left : \n    was_a_cat nifty ^ \n    was_a_cat cheese \u2192 \n    was_a_cat cheese\n| pf_n_and_c := and.elim_right pf_n_and_c\n\n/-\nThere what we just did is kind of amazing.\nWe formalized a proof of a proposition, \n\"if nifty was a cat and cheese was a cat,\nthen cheese was a cat, as a function. That\nthere is such a function proves the truth\nof the logical implication (proposition).\n-/\n\n/-\nNote: We have not proved that cheese was a \ncat. If fact cheese wasn't a cat; he was a\nrat. All we have shown is that *if* we can\ncome up with a proof of the conjunction then\nwe can \"extract\" its right component proof.\nIt does not show that we could actually ever\nbuild a proof of the conjunction in the \nfirst place.\n-/\n\n\n/-\nWe see again that a proof of a conjunction\nin our logic is really just a pair of proofs,\nwith fst and snd (left and right) projection\nfunctions. The and.intro constructor takes a\npair of proofs and packages them up into pair\nthat is accepted as a proof of a conjunction.\n-/\n\nend our_logic\n\n-- PROPOSITIONS!!!\n#check and\ndef P1 : Prop := 0=0\ndef P2 : Prop := 1 = 1\n#check and P1 P2\n\ndef P1_and_P2 : Prop := P1 \u2227 P2    --Infix notation for and\n\ndef p1_and_p2 : P1_and_P2 := and.intro (eq.refl 0) (eq.refl 1)\n\ndef p1_and_p2' : P1_and_P2 :=\nbegin\n    unfold P1_and_P2,\n    apply and.intro _ _,\n    exact (eq.refl 0),\n    exact (eq.refl 1)\nend\n\n\n#check and.elim_left\n#check @and.elim_left\n\n\n/-\nLean provides exactly such this polymorphic\nlogical and connective. It's called \"and\" has\n\u2227 as a conventional infix notation. Here's an\nexample. We also take this moment to introduce\nthe \"example\" construct in Lean. It's just \nlike def or theorem, in that it calls for a\nvalue of a particular type. The difference is\nthat it doesn't bind the value to a name. It\nis a way to prove something without storing\nthe proof as a named object.\n-/\n\nexample : was_a_cat tom \u2227 0 = 0 := \n    and.intro tom_proof (eq.refl 0)\n\n\nexample : was_a_cat tom \u2227 0 = 0 := \nbegin\n    apply and.intro tom_proof (eq.refl 0),\nend\n\nexample : was_a_cat tom \u2227 0 = 0 := \nbegin\n    apply and.intro tom_proof, -- arg as subgoal\n    exact (eq.refl 0)\nend\n\nexample : was_a_cat tom \u2227 0 = 0 := \nbegin\n    apply and.intro,    -- two args as subgoals\n    exact tom_proof,\n    exact (eq.refl 0)\nend\n\n/-\nLet's write some English language proofs.\n-/\n\n/-\nIMPLIES\n-/\n\n/-\nWhat we've seen now is that a proof that an \nimplication is true is a proof that *if* one\nhas a proof of its premise, then from that\none can obtain a proof of its conclusion.\nAgain, as an example, consider that from a \nproof of a conjunction one can obtain (you\ncan also say \"deduce\") a proof of either of\nits conjuncts. If one has a proof of P \u2227 Q,\nfor example, then by applying one of the two\n\"and elimination\" axioms (rules of natural\ndeduction) to the proof of P \u2227 Q, one can\nobtain either a proof of P, or a proof of Q. \nTo prove an implication we thus prove that\nthere is a way to transform any proof of \nits premise into a proof of its conclusion.\nIn natural language, we'd say that we first\n*assume* that the premise is true, and then\nwe'd show that in the context in which we've\nmade that assumption, we can show that the\nconclusion must be true.\nTheorem: For all propositions, P and Q,\n(P \u2227 Q) \u2192 P. \nProof. Suppose that P and Q are arbitrary\nbut specific propositions. What remains to\nprove is that (P \u2227 Q) \u2192 P. To prove this,\nassume we have a proof of P \u2227 Q. Applying\nthe natural deduction principle of and \nelimination (left) yields of proof of P.\nQED. \nTo formalize this idea, we prove such an\nimplication by showing that there is a\nfunction that, *if* given a proof of the\npremise as an argument is able to create\nand return a proof of the conclusion. If\nthere is such a function in Lean (in which\ncase it is a total function, and so can\ntake *any* proof of the premise as an\nargument), then from any proof of the\npremise it is always possible to derive\na proof of the conclusion, so the truth\nof the premise implies the truth of the\nconclusion.\n-/\n\ndef pf1 : \u2200 (P Q : Prop), P \u2227 Q \u2192 P :=\n    \u03bb P Q,\n        \u03bb h, \n            and.elim_left h\n\ndef pf1' : \u2200 (P Q : Prop), P \u2227 Q \u2192 P :=\n    \u03bb X Y,\n        \u03bb h, \n            and.elim_left h\n\n-- Note that names bound by lambda do\n-- not have to be P and Q. You can call\n-- arguments whatever you want, as long\n-- as their names are already in use.\n\n/-\nLet's take that bit by bit. We bind a name,\npf1, to a proof of \u2200 (P Q : Prop), P \u2227 Q \u2192 P. \nWe use \u2200 (P Q : Prop) to give names to two\n*parameters* -- any two propositions, P and\nQ -- so that we can use these names in the\nrest of the proposition: P \u2227 Q \u2192 P. \nWe thus have the overall proposition: for \n*any* propositions, P and Q, if P \u2227 Q (is\ntrue, has a proof) then P (is true, has a\nproof), i.e., P \u2227 Q \u2192 P. In curt English: \n\"If P \u2227 Q then P.\"\nThe lambda expressions take argument values\nthat, in the rest of the function definition,\nare *assumed* to be of the specified types. \nSo in the \"body\" of the function, P and Q are\n*assumed* to be propositions (types, of type\nProp), and h is *assumed* to be a proof (value)\nof (type) P \u2227 Q. \nWhat the expression, (and.elim_left h), then\nshows is that, in the context of *the given \nassumptions*, one can construct and return \na proof of *P*. From the assumption of the\npremise follows the truth of the conclusion.\n-/\n\n/-\nA proof of an implication in constructive\nlogic is a function: one that if given an\nargument of the premise type returns a value\nof the conclusion type. Recall: propositions\nare types, proofs are values of such types.\nWe wrote the formal proof of \u2200 (P Q : Prop), \nP \u2227 Q \u2192 P, to make explicit the overall\nproposition being proved, but we could just\nas well have written it in C style. In fact,\nwe could have written it in any of the ways\navailable to define functions.\nHere are various forms in which exactly the\nsame proof can be expressed. In the first C\nstyle proof, we see even more clearly that\nwe can think of argument to functions as \n*assumptions* that we can then use in the\nfunction body to construct a return result.\n-/\n\ndef pf2 (P Q : Prop) (h : P \u2227 Q) : P :=\n    and.elim_left h -- from h deduce P\n\n#check pf2      -- that's pretty cool\n\n-- script, assume and name args in script\n-- here X and Y refer to P, Q\n-- better in general to keep names P, Q\ndef pf3 : \u2200 (P Q : Prop), P \u2227 Q \u2192 P :=\nbegin\n    assume (X Y : Prop),    \n    assume (h : X \u2227 Y),\n    exact and.elim_left h,\nend\n\n-- proof script, args already assumed\ndef pf4 (P Q : Prop) (h : P \u2227 Q) : P :=\nbegin -- look: arguments are assumptions\n    exact and.elim_left h,\nend\n\n-- using cases notation\ndef pf5 : \u2200 (P Q : Prop), P \u2227 Q \u2192 P\n| P Q h := and.elim_left h\n\n/-\nFalse Elimination: \u2200 (P : Prop), false \u2192 P.\n-/\n\n/-\nIt doesn't matter whether or not one can\never produce a proof of a premise, because\nall that a proof of an implications says\nis that *if* you can give a proof of the\npremise as an argument to a function, then\nit can return a proof of the conclusion. \nA clear example involves the proof that\n\"false implies (the truth of) anything\".\nFormally: \u2200 (P : Prop), false \u2192 P. Take\na moment to make sure you understand what\nthis proposition says!\n-/\n\n/-\nThe proposition (false : Prop) is one with\nno proofs at all.\n-/\n\ninductive false' : Prop\n-- no constructors!\n\n/-\nFor example, it's true that (false \u2192 0 = 1)\neven though one can never produce a proof\nof false. The truth of (false \u2192 0 = 1) is\ndemonstrated by the existence of a function\nthat, *if* it could be given a proof of false, \nwould return a proof of 0 = 1 by applying the\nfalse elimination inference rule to the \n*assumed* proof of false to derive a proof\nof 0 = 1. \n-/\n\ntheorem false_elim_example : false \u2192 0 = 1 :=\n    \u03bb h, false.elim h\n\ntheorem false_elim_example' (h : false) : 0 = 1 :=\n    false.elim h\n\nexample : false \u2192 0 = 1 := \u03bb h, false.elim h", "meta": {"author": "derekjohnsonva", "repo": "CS2102", "sha": "b3f507d4be824a2511838a1054d04fc9aef3304c", "save_path": "github-repos/lean/derekjohnsonva-CS2102", "path": "github-repos/lean/derekjohnsonva-CS2102/CS2102-b3f507d4be824a2511838a1054d04fc9aef3304c/notes/2019.11.05.Prop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.734258345438823}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport data.int.absolute_value\nimport linear_algebra.matrix.determinant\n\n/-!\n# Absolute values and matrices\n\nThis file proves some bounds on matrices involving absolute values.\n\n## Main results\n\n * `matrix.det_le`: if the entries of an `n \u00d7 n` matrix are bounded by `x`,\n   then the determinant is bounded by `n! x^n`\n * `matrix.det_sum_le`: if we have `s` `n \u00d7 n` matrices and the entries of each\n   matrix are bounded by `x`, then the determinant of their sum is bounded by `n! (s * x)^n`\n * `matrix.det_sum_smul_le`: if we have `s` `n \u00d7 n` matrices each multiplied by\n   a constant bounded by `y`, and the entries of each matrix are bounded by `x`,\n   then the determinant of the linear combination is bounded by `n! (s * y * x)^n`\n-/\n\nopen_locale big_operators\nopen_locale matrix\n\nnamespace matrix\n\nopen equiv finset\n\nvariables {R S : Type*} [comm_ring R] [nontrivial R] [linear_ordered_comm_ring S]\nvariables {n : Type*} [fintype n] [decidable_eq n]\n\nlemma det_le {A : matrix n n R} {abv : absolute_value R S}\n  {x : S} (hx : \u2200 i j, abv (A i j) \u2264 x) :\n  abv A.det \u2264 nat.factorial (fintype.card n) \u2022 x ^ (fintype.card n) :=\ncalc  abv A.det\n    = abv (\u2211 \u03c3 : perm n, _) : congr_arg abv (det_apply _)\n... \u2264 \u2211 \u03c3 : perm n, abv _ : abv.sum_le _ _\n... = \u2211 \u03c3 : perm n, (\u220f i, abv (A (\u03c3 i) i)) : sum_congr rfl (\u03bb \u03c3 h\u03c3,\n  by rw [abv.map_units_int_smul, abv.map_prod])\n... \u2264 \u2211 \u03c3 : perm n, (\u220f (i : n), x) :\n  sum_le_sum (\u03bb _ _, prod_le_prod (\u03bb _ _, abv.nonneg _) (\u03bb _ _, hx _ _))\n... = \u2211 \u03c3 : perm n, x ^ (fintype.card n) : sum_congr rfl (\u03bb _ _,\n  by rw [prod_const, finset.card_univ])\n... = nat.factorial (fintype.card n) \u2022 x ^ (fintype.card n) :\n  by rw [sum_const, finset.card_univ, fintype.card_perm]\n\nlemma det_sum_le {\u03b9 : Type*} (s : finset \u03b9) {A : \u03b9 \u2192 matrix n n R}\n  {abv : absolute_value R S} {x : S} (hx : \u2200 k i j, abv (A k i j) \u2264 x) :\n  abv (det (\u2211 k in s, A k)) \u2264\n    nat.factorial (fintype.card n) \u2022 (finset.card s \u2022 x) ^ (fintype.card n) :=\ndet_le $ \u03bb i j,\ncalc  abv ((\u2211 k in s, A k) i j)\n    = abv (\u2211 k in s, A k i j) : by simp only [sum_apply]\n... \u2264 \u2211 k in s, abv (A k i j) : abv.sum_le _ _\n... \u2264 \u2211 k in s, x : sum_le_sum (\u03bb k _, hx k i j)\n... = s.card \u2022 x : sum_const _\n\nlemma det_sum_smul_le {\u03b9 : Type*} (s : finset \u03b9) {c : \u03b9 \u2192 R} {A : \u03b9 \u2192 matrix n n R}\n  {abv : absolute_value R S}\n  {x : S} (hx : \u2200 k i j, abv (A k i j) \u2264 x) {y : S} (hy : \u2200 k, abv (c k) \u2264 y) :\n  abv (det (\u2211 k in s, c k \u2022 A k)) \u2264\n    nat.factorial (fintype.card n) \u2022 (finset.card s \u2022 y * x) ^ (fintype.card n) :=\nby simpa only [smul_mul_assoc] using\ndet_sum_le s (\u03bb k i j,\ncalc  abv (c k * A k i j)\n    = abv (c k) * abv (A k i j) : abv.map_mul _ _\n... \u2264 y * x : mul_le_mul (hy k) (hx k i j) (abv.nonneg _) ((abv.nonneg _).trans (hy k)))\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/absolute_value.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7341411496889768}}
{"text": "import data.real.basic\nimport order.filter.at_top_bot\nimport topology.instances.real\n/-\n\n## Sequences, revisited\n\nRecall that in week 3 we made these definitions:\n\n-/\n\nlocal notation `|` x `|` := abs x\n\n/-- `l` is the limit of the sequence `a` of reals -/\ndefinition is_limit (a : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < \u03b5\n\n/-\n\nWe then spent some time proving things like\nif a\u2099 \u2192 l and b\u2099 \u2192 m then a\u2099 * b\u2099 \u2192 l * m.\n\nLet's see another, much shorter, proof of these things using filters,\nand of course also using facts from `mathlib` about filters.\n\n-/\n\nopen filter\n\nopen_locale topological_space\n\nopen metric\n\ntheorem is_limit_iff_tendsto (a : \u2115 \u2192 \u211d) (l : \u211d) :\nis_limit a l \u2194 tendsto a at_top (\ud835\udcdd l) :=\nbegin\n  rw metric.tendsto_at_top,\n  refl,\nend\n\ntheorem is_limit_mul (a b : \u2115 \u2192 \u211d) (l m : \u211d)\n  (ha : is_limit a l) (hb : is_limit b m) :\n  is_limit (a * b) (l * m) :=\nbegin\n  rw is_limit_iff_tendsto at *,\n  exact tendsto.mul ha hb,\nend\n\n/-\n\nThis was much less painful than what we went through in week 3! So where\ndid the work go?\n\nThe next 130 lines of this file discuss the first proof, namely\n`is_limit_iff_tendsto`. Clearly the key ingredients is\n`metric.tendsto_at_top`. There are no exercises here, I will just\nexplain what's going on, and talk about definitions (e.g. `is_limit`)\nand their cost.\n\nThe second proof uses `is_limit_iff_tendsto` to reduce `is_limit_mul`\nto a theorem about filters, and them proves it with `tendsto.mul`. We will\nprove our own version of `tendsto.mul` in this file. So if you want to\nget on with the proving you can skip straight down to\nthe `## tendsto.mul` section on line 184 or so.\n\nThe first proof \n\n## Definitions in Lean\n\nEach *definition* you make in Lean comes with a cost. For example\ncheck out Lean's definition of `finset`, the type of finite sets.\nRight click on `finset` below and click on \"go to definition\".\nYou see one definition, and then over 2000 lines of theorems\nabout this definition. Don't forget to close the file afterwards!\n-/\n\n#check finset\n\n/-\nThe theorems are necessary because it's no good just defining some\nconcept of a finite set, you need to make it intuitive to use for the\nend user, so you need to prove that a subset of a finite set is finite,\nthe union of two finite sets is finite, the image of a finite set under\na map is finite, the product of two finite sets is finite, a finite product\nof finite sets indexed by a finite set is finite, etc etc. Every one of those\nlemmas in that file is completely obvious to a mathematician, but needs\nto be proved in Lean so that mathematicians can use finite sets the\nway they intuitively want to. See if you can understand some of the\nstatements proved about finite sets in that file. Be very careful\nnot to edit it though! If you do accidentally change it, just close the\nfile without saving, or use ctrl-Z to undo your changes. \n\nWhen we developed the theory of limits of sequences in week 3, we \nmade the definition `is_limit`. This definition comes with a cost;\nto make it useful to the end user, we need to prove a ton of theorems\nabout `is_limit`. This is what happens in an undergraduate analysis\nclass -- you see the definition, and then you make what computer\nscientists call the \"API\" or the \"interface\" -- a bunch of lemmas\nand theorems about `is_limit`, for example `is_limit_add`, which says\nthat `a\u2099 \u2192 l` and `b\u2099 \u2192 m` implies `a_n + b_n \u2192 l + m`, and also `is_limit_neg`,\n`is_limit_sub`, `is_limit_mul` and so on.\n\nBut it turns out that `is_limit` is just a very special case of `tendsto`,\nand because `tendsto` is already in mathlib, there is already a very big\nAPI for `tendsto` which has developed organically over the last few\nyears. It was started by the original writer of `tendsto` and then\nit grew as other people used `tendsto` more, and added to the list of useful\nlemmas as they used `tendsto` to do other things and then abstracted out\nproperties which they discovered were useful. For example, this week\n(I write this in Feb 2021) Heather Macbeth was working on modular forms in Lean\nand she discovered that she needed a lemma about `tendsto`, which, after some\ndiscussion on the Zulip Lean chat, Heather and I realised was a statement\nabout how `tendsto` commutes with a certain kind of coproduct. We proved this\nlemma, Heather is right now in the process of adding it (`tendsto.prod_map_coprod`)\nto `mathlib`, Lean's maths library.\n\nhttps://github.com/leanprover-community/mathlib/pull/6372\n\nI will remark that I would never have worked on that problem with Heather\nif it hadn't been for the fact that I'd been teaching you about filters\nand hence I had to learn about them properly!\n\nLet's take a look at our new proof of `tendsto_mul` again. The proof follows\nfrom two 2-line lemmas. I will talk you through the first one, and you can\nexperiment with the second one. Let's take a look at the first one.\n\n-/\n\nexample (a : \u2115 \u2192 \u211d) (l : \u211d) :\nis_limit a l \u2194 tendsto a at_top (\ud835\udcdd l) :=\nbegin\n  rw metric.tendsto_at_top,\n  refl,\nend\n\n/-\n\nThe guts of the first one is `metric.tendsto_at_top`, which is actually\na statement about metric spaces. It says that in any metric space,\nthe standard metric space epsilon-N definition of a limit of a sequence\nis a special case of this filter `tendsto` predicate. Here is a proof\nwith more details spelt out (`simp_rw` is just a slightly more powerful\nversion of `rw` which we need for technical reasons here, because `rw` will\nnot see under a `\u2200` statement -- it will not \"work under binders\"):\n-/\n\nexample (a : \u2115 \u2192 \u211d) (l : \u211d) :\nis_limit a l \u2194 tendsto a at_top (\ud835\udcdd l) :=\nbegin\n  simp_rw [metric.tendsto_nhds, eventually_iff, mem_at_top_sets],\n  refl,\nend\n\n/-\n\nThis more explicit proof uses the following fancy notation\ncalled \"filter.eventually\" :\n\n`(\u2200\u1da0 (x : \u03b1) in F, P x) \u2194 {x : \u03b1 | P x} \u2208 F` (true by definition, or\nyou can `rw eventually_iff`)\n\nand then it just boils down to the following two mathematical facts\n(here `ball l \u03b5` is the open ball radius `\u03b5` centre `l` ),\nthe first being `metric.tendsto_nhds` and the second `mem_at_top_sets`:\n\n1) If `a` is in a metric space, then `S \u2208 \ud835\udcdd l \u2194 \u2203 \u03b5 > 0, ball l \u03b5 \u2286 S`\n2) If `at_top` is the filter on on `\u2115` that we saw last time then\n`T \u2208 at_top \u2194 \u2203 N : \u2115, {n : \u2115 | N \u2264 n} \u2286 T`\n\nAfter that it's easy, because `tendsto a at_top (\ud835\udcdd l)` then means,\nby definition of `tendsto`, \n\n`\u2200 S : set \u211d, S \u2208 \ud835\udcdd l \u2192 a \u207b\u00b9' S \u2208 at_top`\n\nwhich translates into\n\n`\u2200 S : set \u211d, (\u2203 \u03b5 > 0, ball l \u03b5 \u2286 S) \u2192 (\u2203 N, n \u2265 N \u2192 a n \u2208 S)`\n\nand if you unfold the logical packaging you will see that this is just\nthe usual definition of `is_limit` (note that `a n \u2208 ball l \u03b5` is\ndefinitionally equal to `dist (a n) l < \u03b5` which, for the reals, is\ndefinitionally equal to `|a n - l| < \u03b5`).\n\n## tendsto.mul\n\nNow let's look at the second example.\n\n-/\n\nexample (a b : \u2115 \u2192 \u211d) (l m : \u211d) (ha : is_limit a l) (hb : is_limit b m) :\n  is_limit (a * b) (l * m) :=\nbegin\n  rw is_limit_iff_tendsto at *,\n  exact tendsto.mul ha hb,\nend\n\n/-\n\nIf you hover over `tendsto.mul` in that proof, you will perhaps be able to make\nout that it says the following: if we have a topological space `M` with a\ncontinuous multiplication on it, and if `F` is a filter on `\u03b1` and `f` and `g`\nare maps `\u03b1 \u2192 M`, then `tendsto f F (\ud835\udcdd l)` and `tendsto g F (\ud835\udcdd m)` implies\n`tendsto (f * g) F \ud835\udcdd (l * m)`. We apply this with `F` the cofinite filter\nand we're done, at least modulo the assertion that multiplication\non \u211d is a continuous function. How did Lean know this? Well, \n`[has_continuous_mul M]` was in square brackets so that means that\nthe type class inference system is supposed to deal with it. Let's\nsee how it gets on with the assertion that multiplication is continuous\non the reals.\n\n-/\n\n-- multiplication is continuous on the reals.\nexample : has_continuous_mul \u211d :=\nbegin\n  -- Ask the type class inference system whether it knows this\n  apply_instance\nend\n-- It does!\n\n/-\n\nThe people who defined `\u211d` in Lean made a definition, and the price they\nhad to then pay for making it usable was that they had to make a big API for\n`\u211d`, proving stuff like a non-empty bounded set of reals has a least\nupper bound, and that the reals were a topological ring (and hence\nmultiplication was continuous). But this price was paid way back in 2018\nso we mathematicians can now use these facts for free.\n\nAll that remains then, if we want to see the details, is to\n*prove* `tendsto.mul`, and this is a statement about filters on topological\nspaces, so let's do it. First -- what does `continuous` mean?\n\n## Continuity\n\nLet `X` and `Y` be topological spaces, and say `f : X \u2192 Y` is a function.\n\n-/\nvariables (X Y : Type) [topological_space X] [topological_space Y] (f : X \u2192 Y)\n\n/-\n\nIf `x : X`, then what does it mean for `f` to be continuous at `x`?\nIntuitively, it means that if you move `x` by a small amount, then `f x`\nmoves by a small amount. In other words, `f` sends a small neighbourhood\nof `x` into a small neighbourhood of `f x`. \n\nIf our mental model of the neighbourhood filter `\ud835\udcdd x` is some kind of\ngeneralised set corresponding to an infinitesimally small\nneighbourhood of `x`, you will see why Lean makes the following\ndefinition of `continuous_at`:\n\n-/\n\nlemma continuous_at_def (x : X) :\n  continuous_at f x \u2194 tendsto f (\ud835\udcdd x) (\ud835\udcdd (f x)) :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-\n\nOut of interest, you were probably told the definition of what it means\nfor a function `f : X \u2192 Y` between *metric* spaces to be continuous at `x`.\nWere you ever told what it means for a function between *topological* spaces\nto be continuous at `x`, rather than just continuous on all of `X`? This\nis what it means.\n\nNow let's start on the proof of `tendsto.mul`, by building an API\nfor the `continuous_at` definition. Don't forget things like\n\n`tendsto_id : tendsto id x x`\n`tendsto.comp : tendsto g G H \u2192 tendsto f F G \u2192 tendsto (g \u2218 f) F H`\n\nfrom Part A.\n-/\n\n-- this first lemma called `continuous_at_id`. Prove it yourself using\n-- facts from Part A.\nexample (x : X) : continuous_at id x :=\nbegin\n  sorry\nend\n\n-- recall we have `f : X \u2192 Y`. Now let's add in a `Z`.\nvariables (Z : Type) [topological_space Z] (g : Y \u2192 Z)\n\n-- this is called `continuous_at.comp`. Prove it yourself using\n-- facts from Part A.\nexample (x : X) (hf : continuous_at f x) (hg : continuous_at g (f x)) :\ncontinuous_at (g \u2218 f) x :=\nbegin\n  sorry\nend\n\n/-\n\nNow we prove a key result, called `tendsto.prod_mk_nhds`. Notation for product\nof types: if `Y` and `Z` are types then `Y \u00d7 Z` is the product type, and \nthe notation for a general term is `(y, z) : Y \u00d7 Z` with `y : Y` and `z : Z`.\n\nA special case of the theorem below is that if `f : X \u2192 Y` and `g : X \u2192 Z` are\ncontinuous at `x` then the product map `f \u00d7 g : X \u2192 Y \u00d7 Z` is also continuous\nat `x`. We will actually prove something more general -- if `\u03b1` is any type\nand `F : filter \u03b1` is any filter and if `y : Y` and `z : Z` and if\n`f : \u03b1 \u2192 Y` and `g : \u03b1 \u2192 Z` satisfy `tendsto f F (\ud835\udcdd y)` and `tendsto g F (\ud835\udcdd z)`,\nthen `tendsto (f \u00d7 g) F (\ud835\udcdd (y,z))`, where `f \u00d7 g` is the map `\u03bb x, (f x, g x)`.\nThe key fact you will need from the product topology API is \n`mem_nhds_prod_iff : S \u2208 \ud835\udcdd ((a, b) : X \u00d7 Y) \u2194`\n  `\u2203 (U : set X) (H : U \u2208 \ud835\udcdd a) (V : set Y) (H : V \u2208 \ud835\udcdd b), U.prod V \u2286 S`\nThis is all you should need about the product topology (we won't go into how\nthe product topology is defined, but the key fact mathematically says that a\nneighbourhood of `(a,b) : X \u00d7 Y` contains a product of neighbourhoods of `X` and of `Y`).\n\nYou will also need to know\n\n`mk_mem_prod : a \u2208 U \u2192 b \u2208 V \u2192 (a, b) \u2208 U.prod V`\n\nwhere for `U : set X` and `V : set Y`, `U.prod V = prod U V` is the \nobvious subset of `X \u00d7 Y`. \n\nRecall also from Part A:\n`mem_map : S \u2208 map \u03c6 F \u2194 {x : \u03b1 | \u03c6 x \u2208 S} \u2208 F`\n`tendsto_def : tendsto f F G \u2194 \u2200 (S : set Y), S \u2208 G \u2192 f \u207b\u00b9' S \u2208 F`\n(although there is a gotcha here : the actual definition of \n`tendsto f F G` is `\u2200 {S : set Y}, S \u2208 G ...` )\n-/\n\n-- this is called `tendsto.prod_mk_nhds` in Lean but try proving it yourself.\nexample {\u03b1 : Type} (f : \u03b1 \u2192 Y) (g : \u03b1 \u2192 Z) (x : X) (F : filter \u03b1) (y : Y) (z : Z)\n  (hf : tendsto f F (\ud835\udcdd y)) (hg : tendsto g F (\ud835\udcdd z)) :\n  tendsto (\u03bb x, (f x, g x)) F (\ud835\udcdd (y, z)) :=\nbegin\n  sorry,\nend\n\n/- Armed with `tendsto.prod_mk_nhds`, let's prove the version of `tendsto.mul`\n which we need. I would recommend starting with\n```\nset f1 : M \u00d7 M \u2192 M := \u03bb mn, mn.1 * mn.2 with hf1,\nset f2 : \u03b1 \u2192 M \u00d7 M := \u03bb x, (f x, g x) with hf2,\nhave h1 : f1 \u2218 f2 = f * g,\n...\n```\nbecause it's `f1` and `f2` that we've been proving theorems about,\nand then you can use `tendsto.comp`. \n-/\n\nlemma key_lemma {\u03b1 M : Type} [topological_space M] [has_mul M] \n  {f g : \u03b1 \u2192 M} {F : filter \u03b1} {a b : M} (hf : tendsto f F (\ud835\udcdd a))\n  (hg : tendsto g F (\ud835\udcdd b))\n  (hcontinuous : continuous_at (\u03bb (mn : M \u00d7 M), mn.1 * mn.2) (a,b)) :\n  tendsto (f * g) F (\ud835\udcdd (a * b)) :=\nbegin\n  sorry\nend\n\n-- The final ingredient is that multiplication is continuous on \u211d, which we\n-- just take from the real API:\nlemma real.continuous_mul_at (a b : \u211d) :\n  continuous_at (\u03bb xy : \u211d \u00d7 \u211d, xy.1 * xy.2) (a, b) :=\nbegin\n  -- it's in the library\n  exact continuous.continuous_at real.continuous_mul,\nend\n\n-- and now we have all the ingredients we need for our own proof of `is_limit_mul`!\nexample  (a b : \u2115 \u2192 \u211d) (l m : \u211d)\n  (ha : is_limit a l) (hb : is_limit b m) :\n  is_limit (a * b) (l * m) :=\nbegin\n  rw is_limit_iff_tendsto at *,\n  apply key_lemma ha hb,\n  apply real.continuous_mul_at,\nend\n\n/-\n\nYou might think that this new proof \"feels longer\". But what you have to\nunderstand is that it's shorter in practice, because the user doesn't\nhave to write `tendsto.mul` themselves, it's already there in the library.\nWriting APIs is an extensive process. But using them is easy. \n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_6/Part_B_sequences_again.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7341411388073773}}
{"text": "/-\nCopyright (c) 2022 Bhavik Mehta, Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta, Kexing Ying\n-/\nimport probability.cond_count\n\n/-!\n# Ballot problem\n\nThis file proves Theorem 30 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).\n\nThe ballot problem asks, if in an election, candidate A receives `p` votes whereas candidate B\nreceives `q` votes where `p > q`, what is the probability that candidate A is strictly ahead\nthroughout the count. The probability of this is `(p - q) / (p + q)`.\n\n## Main definitions\n\n* `counted_sequence`: given natural numbers `p` and `q`, `counted_sequence p q` is the set of\n  all lists containing `p` of `1`s and `q` of `-1`s representing the votes of candidate A and B\n  respectively.\n* `stays_positive`: is the set of lists of integers which suffix has positive sum. In particular,\n  the intersection of this set with `counted_sequence` is the set of lists where candidate A is\n  strictly ahead.\n\n## Main result\n\n* `ballot`: the ballot problem.\n\n-/\n\nopen set probability_theory measure_theory\n\nnamespace ballot\n\n/-- The set of nonempty lists of integers which suffix has positive sum. -/\ndef stays_positive : set (list \u2124) := {l | \u2200 l\u2082, l\u2082 \u2260 [] \u2192 l\u2082 <:+ l \u2192 0 < l\u2082.sum}\n\n@[simp] lemma stays_positive_nil : [] \u2208 stays_positive :=\n\u03bb l hl hl\u2081, (hl (list.eq_nil_of_suffix_nil hl\u2081)).elim\n\nlemma stays_positive_cons_pos (x : \u2124) (hx : 0 < x) (l : list \u2124) :\n  (x :: l) \u2208 stays_positive \u2194 l \u2208 stays_positive :=\nbegin\n  split,\n  { intros hl l\u2081 hl\u2081 hl\u2082,\n    apply hl l\u2081 hl\u2081 (hl\u2082.trans (list.suffix_cons _ _)) },\n  { intros hl l\u2081 hl\u2081 hl\u2082,\n    rw list.suffix_cons_iff at hl\u2082,\n    rcases hl\u2082 with (rfl | hl\u2082),\n    { rw list.sum_cons,\n      apply add_pos_of_pos_of_nonneg hx,\n      cases l with hd tl,\n      { simp },\n      { apply le_of_lt (hl (hd :: tl) (list.cons_ne_nil hd tl) (hd :: tl).suffix_refl) } },\n    { apply hl _ hl\u2081 hl\u2082 } }\nend\n\n/--\n`counted_sequence p q` is the set of lists of integers for which every element is `+1` or `-1`,\nthere are `p` lots of `+1` and `q` lots of `-1`.\n\nThis represents vote sequences where candidate `+1` receives `p` votes and candidate `-1` receives\n`q` votes.\n-/\ndef counted_sequence (p q : \u2115) : set (list \u2124) :=\n{l | l.count 1 = p \u2227 l.count (-1) = q \u2227 \u2200 x \u2208 l, x = (1 : \u2124) \u2228 x = -1}\n\n/-- An alternative definition of `counted_sequence` that uses `list.perm`. -/\nlemma mem_counted_sequence_iff_perm {p q l} :\n  l \u2208 counted_sequence p q \u2194 l ~ list.replicate p (1 : \u2124) ++ list.replicate q (-1) :=\nbegin\n  rw [list.perm_replicate_append_replicate],\n  { simp only [counted_sequence, list.subset_def, mem_set_of_eq, list.mem_cons_iff,\n      list.mem_singleton] },\n  { norm_num1 }\nend\n\n@[simp] lemma counted_right_zero (p : \u2115) : counted_sequence p 0 = {list.replicate p 1} :=\nby { ext l, simp [mem_counted_sequence_iff_perm] }\n\n@[simp] lemma counted_left_zero (q : \u2115) : counted_sequence 0 q = {list.replicate q (-1)} :=\nby { ext l, simp [mem_counted_sequence_iff_perm] }\n\nlemma mem_of_mem_counted_sequence {p q} {l} (hl : l \u2208 counted_sequence p q) {x : \u2124} (hx : x \u2208 l) :\n  x = 1 \u2228 x = -1 :=\nhl.2.2 x hx\n\nlemma length_of_mem_counted_sequence {p q} {l : list \u2124} (hl : l \u2208 counted_sequence p q) :\n  l.length = p + q :=\nby simp [(mem_counted_sequence_iff_perm.1 hl).length_eq]\n\nlemma counted_eq_nil_iff {p q : \u2115} {l : list \u2124} (hl : l \u2208 counted_sequence p q) :\n  l = [] \u2194 p = 0 \u2227 q = 0 :=\nlist.length_eq_zero.symm.trans $ by simp [length_of_mem_counted_sequence hl]\n\nlemma counted_ne_nil_left {p q : \u2115} (hp : p \u2260 0) {l : list \u2124} (hl : l \u2208 counted_sequence p q) :\n  l \u2260 [] :=\nby simp [counted_eq_nil_iff hl, hp]\n\nlemma counted_ne_nil_right {p q : \u2115} (hq : q \u2260 0) {l : list \u2124} (hl : l \u2208 counted_sequence p q) :\n  l \u2260 [] :=\nby simp [counted_eq_nil_iff hl, hq]\n\nlemma counted_succ_succ (p q : \u2115) : counted_sequence (p + 1) (q + 1) =\n  list.cons 1 '' counted_sequence p (q + 1) \u222a list.cons (-1) '' counted_sequence (p + 1) q  :=\nbegin\n  ext l,\n  rw [counted_sequence, counted_sequence, counted_sequence],\n  split,\n  { intro hl,\n    have hlnil := counted_ne_nil_left (nat.succ_ne_zero p) hl,\n    obtain \u27e8hl\u2080, hl\u2081, hl\u2082\u27e9 := hl,\n    obtain hlast | hlast := hl\u2082 l.head (list.head_mem_self hlnil),\n    { refine or.inl \u27e8l.tail, \u27e8_, _, _\u27e9, _\u27e9,\n      { rw [list.count_tail l 1 (list.length_pos_of_ne_nil hlnil), hl\u2080, if_pos,\n          nat.add_succ_sub_one, add_zero],\n        rw [list.nth_le_zero, hlast] },\n      { rw [list.count_tail l (-1) (list.length_pos_of_ne_nil hlnil), hl\u2081, if_neg, nat.sub_zero],\n        rw [list.nth_le_zero, hlast],\n        norm_num },\n      { exact \u03bb x hx, hl\u2082 x (list.mem_of_mem_tail hx) },\n      { rw [\u2190 hlast, list.cons_head_tail hlnil] } },\n    { refine or.inr \u27e8l.tail, \u27e8_, _, _\u27e9, _\u27e9,\n      { rw [list.count_tail l 1 (list.length_pos_of_ne_nil hlnil), hl\u2080, if_neg, nat.sub_zero],\n        rw [list.nth_le_zero, hlast],\n        norm_num },\n      { rw [list.count_tail l (-1) (list.length_pos_of_ne_nil hlnil), hl\u2081, if_pos,\n          nat.add_succ_sub_one, add_zero],\n        rw [list.nth_le_zero, hlast] },\n      { exact \u03bb x hx, hl\u2082 x (list.mem_of_mem_tail hx) },\n      { rw [\u2190 hlast, list.cons_head_tail hlnil] } } },\n  { rintro (\u27e8t, \u27e8ht\u2080, ht\u2081, ht\u2082\u27e9, rfl\u27e9 | \u27e8t, \u27e8ht\u2080, ht\u2081, ht\u2082\u27e9, rfl\u27e9),\n    { refine \u27e8_, _, _\u27e9,\n      { rw [list.count_cons, if_pos rfl, ht\u2080] },\n      { rw [list.count_cons, if_neg, ht\u2081],\n        norm_num },\n      { rintro x (hx | hx),\n        exacts [or.inl hx, ht\u2082 x hx] } },\n    { refine \u27e8_, _, _\u27e9,\n      { rw [list.count_cons, if_neg, ht\u2080],\n        norm_num },\n      { rw [list.count_cons, if_pos rfl, ht\u2081] },\n      { rintro x (hx | hx),\n        exacts [or.inr hx, ht\u2082 x hx] } } }\nend\n\nlemma counted_sequence_finite : \u2200 (p q : \u2115), (counted_sequence p q).finite\n| 0 q := by simp\n| (p + 1) 0 := by simp\n| (p + 1) (q + 1) :=\n  begin\n    rw [counted_succ_succ, set.finite_union, set.finite_image_iff (list.cons_injective.inj_on _),\n      set.finite_image_iff (list.cons_injective.inj_on _)],\n    exact \u27e8counted_sequence_finite _ _, counted_sequence_finite _ _\u27e9\n  end\n\nlemma counted_sequence_nonempty : \u2200 (p q : \u2115), (counted_sequence p q).nonempty\n| 0 q := by simp\n| (p + 1) 0 := by simp\n| (p + 1) (q + 1) :=\n  begin\n    rw [counted_succ_succ, union_nonempty, nonempty_image_iff],\n    exact or.inl (counted_sequence_nonempty _ _),\n  end\n\nlemma sum_of_mem_counted_sequence {p q} {l : list \u2124} (hl : l \u2208 counted_sequence p q) :\n  l.sum = p - q :=\nby simp [(mem_counted_sequence_iff_perm.1 hl).sum_eq, sub_eq_add_neg]\n\nlemma disjoint_bits (p q : \u2115) :\n  disjoint (list.cons 1 '' counted_sequence p (q + 1))\n    (list.cons (-1) '' counted_sequence (p + 1) q) :=\nbegin\n  simp_rw [disjoint_left, mem_image, not_exists, exists_imp_distrib],\n  rintros _ _ \u27e8_, rfl\u27e9 _ \u27e8_, _, _\u27e9,\nend\n\nopen measure_theory.measure\n\nprivate def measureable_space_list_int : measurable_space (list \u2124) := \u22a4\n\nlocal attribute [instance] measureable_space_list_int\n\nprivate lemma measurable_singleton_class_list_int : measurable_singleton_class (list \u2124) :=\n{ measurable_set_singleton := \u03bb s, trivial }\n\nlocal attribute [instance] measurable_singleton_class_list_int\n\nprivate lemma list_int_measurable_set {s : set (list \u2124)} : measurable_set s :=\ntrivial\n\nlemma count_counted_sequence : \u2200 p q : \u2115, count (counted_sequence p q) = (p + q).choose p\n| p 0 := by simp [counted_right_zero, count_singleton]\n| 0 q := by simp [counted_left_zero, count_singleton]\n| (p + 1) (q + 1) :=\n  begin\n    rw [counted_succ_succ, measure_union (disjoint_bits _ _) list_int_measurable_set,\n      count_injective_image list.cons_injective, count_counted_sequence,\n      count_injective_image list.cons_injective, count_counted_sequence],\n    { norm_cast,\n      rw [add_assoc, add_comm 1 q, \u2190 nat.choose_succ_succ, nat.succ_eq_add_one, add_right_comm] },\n    all_goals { try { apply_instance } },\n  end\n\nlemma first_vote_pos :\n  \u2200 p q, 0 < p + q \u2192\n    cond_count (counted_sequence p q : set (list \u2124)) {l | l.head = 1} = p / (p + q)\n| (p + 1) 0 h :=\n  begin\n    rw [counted_right_zero, cond_count_singleton],\n    simp [ennreal.div_self _ _],\n  end\n| 0 (q + 1) _ :=\n  begin\n    rw [counted_left_zero, cond_count_singleton],\n    simpa,\n  end\n| (p + 1) (q + 1) h :=\n  begin\n    simp_rw [counted_succ_succ],\n    rw [\u2190 cond_count_disjoint_union ((counted_sequence_finite _ _).image _)\n        ((counted_sequence_finite _ _).image _) (disjoint_bits _ _), \u2190 counted_succ_succ,\n      cond_count_eq_one_of ((counted_sequence_finite p (q + 1)).image _)\n        (nonempty_image_iff.2 (counted_sequence_nonempty _ _))],\n    { have : list.cons (-1) '' counted_sequence (p + 1) q \u2229 {l : list \u2124 | l.head = 1} = \u2205,\n      { ext,\n        simp only [mem_inter_iff, mem_image, mem_set_of_eq, mem_empty_iff_false, iff_false, not_and,\n          forall_exists_index, and_imp],\n        rintro l _ rfl,\n        norm_num },\n      have hint : counted_sequence (p + 1) (q + 1) \u2229 list.cons 1 '' counted_sequence p (q + 1) =\n        list.cons 1 '' counted_sequence p (q + 1),\n      { rw [inter_eq_right_iff_subset, counted_succ_succ],\n        exact subset_union_left _ _ },\n      rw [(cond_count_eq_zero_iff $ (counted_sequence_finite _ _).image _).2 this,\n        cond_count, cond_apply _ list_int_measurable_set, hint,\n        count_injective_image list.cons_injective, count_counted_sequence, count_counted_sequence,\n        one_mul, zero_mul, add_zero, nat.cast_add, nat.cast_one],\n      { rw [mul_comm, \u2190 div_eq_mul_inv, ennreal.div_eq_div_iff],\n        { norm_cast,\n          rw [mul_comm _ (p + 1), \u2190 nat.succ_eq_add_one p, nat.succ_add,\n            nat.succ_mul_choose_eq, mul_comm] },\n          all_goals { simp [(nat.choose_pos $ (le_add_iff_nonneg_right _).2 zero_le').ne.symm] } },\n      all_goals { apply_instance } },\n    { simp },\n    { apply_instance }\n  end\n\nlemma head_mem_of_nonempty {\u03b1 : Type*} [inhabited \u03b1] :\n  \u2200 {l : list \u03b1} (hl : l \u2260 []), l.head \u2208 l\n| [] h := h rfl\n| (x :: l) _ := or.inl rfl\n\nlemma first_vote_neg (p q : \u2115) (h : 0 < p + q) :\n  cond_count (counted_sequence p q) {l | l.head = 1}\u1d9c = q / (p + q) :=\nbegin\n  have := cond_count_compl {l : list \u2124 | l.head = 1}\u1d9c\n    (counted_sequence_finite p q) (counted_sequence_nonempty p q),\n  rw [compl_compl, first_vote_pos _ _ h] at this,\n  rw [(_ : (q / (p + q) : ennreal) = 1 - p / (p + q)), \u2190 this, ennreal.add_sub_cancel_right],\n  { simp only [ne.def, ennreal.div_eq_top, nat.cast_eq_zero, add_eq_zero_iff,\n      ennreal.nat_ne_top, false_and, or_false, not_and],\n    intros,\n    contradiction },\n  rw [eq_comm, ennreal.eq_div_iff, ennreal.mul_sub, ennreal.mul_div_cancel'],\n  all_goals { simp, try { rintro rfl, rw zero_add at h, exact h.ne.symm } },\nend\n\nlemma ballot_same (p : \u2115) : cond_count (counted_sequence (p + 1) (p + 1)) stays_positive = 0 :=\nbegin\n  rw [cond_count_eq_zero_iff (counted_sequence_finite _ _), eq_empty_iff_forall_not_mem],\n  rintro x \u27e8hx, t\u27e9,\n  apply ne_of_gt (t x _ x.suffix_refl),\n  { simpa using sum_of_mem_counted_sequence hx },\n  { refine list.ne_nil_of_length_pos _,\n    rw length_of_mem_counted_sequence hx,\n    exact nat.add_pos_left (nat.succ_pos _) _ },\nend\n\nlemma ballot_edge (p : \u2115) : cond_count (counted_sequence (p + 1) 0) stays_positive = 1 :=\nbegin\n  rw counted_right_zero,\n  refine cond_count_eq_one_of (finite_singleton _) (singleton_nonempty _) _,\n  { intros l hl,\n    rw mem_singleton_iff at hl,\n    subst hl,\n    refine \u03bb l hl\u2081 hl\u2082, list.sum_pos _ (\u03bb x hx, _) hl\u2081,\n    rw list.eq_of_mem_replicate (list.mem_of_mem_suffix hx hl\u2082),\n    norm_num },\nend\n\nlemma counted_sequence_int_pos_counted_succ_succ (p q : \u2115) :\n  (counted_sequence (p + 1) (q + 1)) \u2229 {l | l.head = 1} =\n  (counted_sequence p (q + 1)).image (list.cons 1) :=\nbegin\n  rw [counted_succ_succ, union_inter_distrib_right,\n    (_ : list.cons (-1) '' counted_sequence (p + 1) q \u2229 {l | l.head = 1} = \u2205), union_empty];\n  { ext,\n    simp only [mem_inter_iff, mem_image, mem_set_of_eq, and_iff_left_iff_imp, mem_empty_iff_false,\n      iff_false, not_and, forall_exists_index, and_imp],\n    rintro y hy rfl,\n    norm_num }\nend\n\nlemma ballot_pos (p q : \u2115) :\n  cond_count ((counted_sequence (p + 1) (q + 1)) \u2229 {l | l.head = 1}) stays_positive =\n  cond_count (counted_sequence p (q + 1)) stays_positive :=\nbegin\n  rw [counted_sequence_int_pos_counted_succ_succ, cond_count, cond_count,\n    cond_apply _ list_int_measurable_set, cond_apply _ list_int_measurable_set,\n    count_injective_image list.cons_injective],\n  all_goals { try { apply_instance } },\n  congr' 1,\n  have : (counted_sequence p (q + 1)).image (list.cons 1) \u2229 stays_positive =\n         (counted_sequence p (q + 1) \u2229 stays_positive).image (list.cons 1),\n  { ext t,\n    simp only [mem_inter_iff, mem_image],\n    split,\n    { simp only [and_imp, exists_imp_distrib],\n      rintro l hl rfl t,\n      refine \u27e8l, \u27e8hl, _\u27e9, rfl\u27e9,\n      rwa stays_positive_cons_pos at t,\n      norm_num },\n    { simp only [and_imp, exists_imp_distrib],\n      rintro l hl\u2081 hl\u2082 rfl,\n      refine \u27e8\u27e8_, hl\u2081, rfl\u27e9, _\u27e9,\n      rwa stays_positive_cons_pos,\n      norm_num } },\n  rw [this, count_injective_image],\n  exact list.cons_injective,\nend\n\nlemma counted_sequence_int_neg_counted_succ_succ (p q : \u2115) :\n  (counted_sequence (p + 1) (q + 1)) \u2229 {l | l.head = 1}\u1d9c =\n  (counted_sequence (p + 1) q).image (list.cons (-1)) :=\nbegin\n  rw [counted_succ_succ, union_inter_distrib_right,\n    (_ : list.cons 1 '' counted_sequence p (q + 1) \u2229 {l : list \u2124 | l.head = 1}\u1d9c = \u2205), empty_union];\n  { ext,\n    simp only [mem_inter_iff, mem_image, mem_set_of_eq, and_iff_left_iff_imp, mem_empty_iff_false,\n      iff_false, not_and, forall_exists_index, and_imp],\n    rintro y hy rfl,\n    norm_num }\nend\n\nlemma ballot_neg (p q : \u2115) (qp : q < p) :\n  cond_count ((counted_sequence (p + 1) (q + 1)) \u2229 {l | l.head = 1}\u1d9c) stays_positive =\n  cond_count (counted_sequence (p + 1) q) stays_positive :=\nbegin\n  rw [counted_sequence_int_neg_counted_succ_succ, cond_count, cond_count,\n    cond_apply _ list_int_measurable_set, cond_apply _ list_int_measurable_set,\n    count_injective_image list.cons_injective],\n  all_goals { try { apply_instance } },\n  congr' 1,\n  have : (counted_sequence (p + 1) q).image (list.cons (-1)) \u2229 stays_positive =\n         ((counted_sequence (p + 1) q) \u2229 stays_positive).image (list.cons (-1)),\n  { ext t,\n    simp only [mem_inter_iff, mem_image],\n    split,\n    { simp only [and_imp, exists_imp_distrib],\n      rintro l hl rfl t,\n      exact \u27e8_, \u27e8hl, \u03bb l\u2081 hl\u2081 hl\u2082, t l\u2081 hl\u2081 (hl\u2082.trans (list.suffix_cons _ _))\u27e9, rfl\u27e9 },\n    { simp only [and_imp, exists_imp_distrib],\n      rintro l hl\u2081 hl\u2082 rfl,\n      refine \u27e8\u27e8l, hl\u2081, rfl\u27e9, \u03bb l\u2081 hl\u2083 hl\u2084, _\u27e9,\n      rw list.suffix_cons_iff at hl\u2084,\n      rcases hl\u2084 with (rfl | hl\u2084),\n      { simp [list.sum_cons, sum_of_mem_counted_sequence hl\u2081, sub_eq_add_neg, \u2190 add_assoc, qp] },\n      exact hl\u2082 _ hl\u2083 hl\u2084 } },\n  rw [this, count_injective_image],\n  exact list.cons_injective\nend\n\ntheorem ballot_problem' :\n  \u2200 q p, q < p \u2192 (cond_count (counted_sequence p q) stays_positive).to_real = (p - q) / (p + q) :=\nbegin\n  classical,\n  apply nat.diag_induction,\n  { intro p,\n    rw ballot_same,\n    simp },\n  { intro p,\n    rw ballot_edge,\n    simp only [ennreal.one_to_real, nat.cast_add, nat.cast_one, nat.cast_zero, sub_zero, add_zero],\n    rw div_self ,\n    exact nat.cast_add_one_ne_zero p },\n  { intros q p qp h\u2081 h\u2082,\n    haveI := cond_count_is_probability_measure\n      (counted_sequence_finite p (q + 1)) (counted_sequence_nonempty _ _),\n    haveI := cond_count_is_probability_measure\n      (counted_sequence_finite (p + 1) q) (counted_sequence_nonempty _ _),\n    have h\u2083 : p + 1 + (q + 1) > 0 := nat.add_pos_left (nat.succ_pos _) _,\n    rw [\u2190 cond_count_add_compl_eq {l : list \u2124 | l.head = 1} _ (counted_sequence_finite _ _),\n      first_vote_pos _ _ h\u2083, first_vote_neg _ _ h\u2083, ballot_pos, ballot_neg _ _ qp],\n    rw [ennreal.to_real_add, ennreal.to_real_mul, ennreal.to_real_mul, \u2190 nat.cast_add,\n      ennreal.to_real_div, ennreal.to_real_div, ennreal.to_real_nat, ennreal.to_real_nat,\n      ennreal.to_real_nat, h\u2081, h\u2082],\n    { have h\u2084 : (\u2191(p + 1) + \u2191(q + 1)) \u2260 (0 : \u211d),\n      { apply ne_of_gt,\n        assumption_mod_cast },\n      have h\u2085 : (\u2191(p + 1) + \u2191q) \u2260 (0 : \u211d),\n      { apply ne_of_gt,\n        norm_cast,\n        linarith },\n      have h\u2086 : (\u2191p + \u2191(q + 1)) \u2260 (0 : \u211d),\n      { apply ne_of_gt,\n        norm_cast,\n        linarith },\n      field_simp [h\u2084, h\u2085, h\u2086] at *,\n      ring },\n    all_goals { refine (ennreal.mul_lt_top (measure_lt_top _ _).ne _).ne,\n      simp [ne.def, ennreal.div_eq_top] } }\nend\n\n/-- The ballot problem. -/\ntheorem ballot_problem :\n  \u2200 q p, q < p \u2192 cond_count (counted_sequence p q) stays_positive = (p - q) / (p + q) :=\nbegin\n  intros q p qp,\n  haveI := cond_count_is_probability_measure\n    (counted_sequence_finite p q) (counted_sequence_nonempty _ _),\n  have : (cond_count (counted_sequence p q) stays_positive).to_real =\n    ((p - q) / (p + q) : ennreal).to_real,\n  { rw ballot_problem' q p qp,\n    rw [ennreal.to_real_div, \u2190 nat.cast_add, \u2190 nat.cast_add, ennreal.to_real_nat,\n      ennreal.to_real_sub_of_le, ennreal.to_real_nat, ennreal.to_real_nat],\n    exacts [nat.cast_le.2 qp.le, ennreal.nat_ne_top _] },\n  rwa ennreal.to_real_eq_to_real (measure_lt_top _ _).ne at this,\n  { simp only [ne.def, ennreal.div_eq_top, tsub_eq_zero_iff_le, nat.cast_le,\n      not_le, add_eq_zero_iff, nat.cast_eq_zero, ennreal.add_eq_top, ennreal.nat_ne_top,\n      or_self, not_false_iff, and_true],\n    push_neg,\n    exact \u27e8\u03bb _ _, by linarith, (lt_of_le_of_lt tsub_le_self (ennreal.nat_ne_top p).lt_top).ne\u27e9 },\n  apply_instance,\nend\n\nend ballot\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/100-theorems-list/30_ballot_problem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7341411353850105}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura\n-/\nimport data.finset.card\nopen nat decidable\n\nnamespace finset\nvariable {A : Type}\n\nprotected definition to_nat (s : finset nat) : nat :=\nfinset.Sum s (\u03bb n, 2^n)\n\nopen finset (to_nat)\n\nlemma to_nat_empty : to_nat \u2205 = 0 :=\nrfl\n\nlemma to_nat_insert {n : nat} {s : finset nat} : n \u2209 s \u2192 to_nat (insert n s) = 2^n + to_nat s :=\nassume h, Sum_insert_of_not_mem _ h\n\nprotected definition of_nat (s : nat) : finset nat :=\n{ n \u2208 upto (succ s) | odd (s / 2^n) }\n\nopen finset (of_nat)\n\nprivate lemma of_nat_zero : of_nat 0 = \u2205 :=\nrfl\n\nprivate lemma odd_of_mem_of_nat {n : nat} {s : nat} : n \u2208 of_nat s \u2192 odd (s / 2^n) :=\nassume h, of_mem_sep h\n\nprivate lemma mem_of_nat_of_odd {n : nat} {s : nat} : odd (s / 2^n) \u2192 n \u2208 of_nat s :=\nassume h,\nhave 2^n < succ s, from by_contradiction\n  (suppose \u00ac(2^n < succ s),\n   have 2^n > s, from lt_of_succ_le (le_of_not_gt this),\n   have s / 2^n = 0, from div_eq_zero_of_lt this,\n   by rewrite this at h; exact absurd h dec_trivial),\nhave n < succ s,        from calc\n   n   \u2264 2^n    : le_pow_self dec_trivial n\n   ... < succ s : this,\nhave n \u2208 upto (succ s), from mem_upto_of_lt this,\nmem_sep_of_mem this h\n\nprivate lemma succ_mem_of_nat (n : nat) (s : nat) : succ n \u2208 of_nat s \u2194 n \u2208 of_nat (s / 2) :=\niff.intro\n  (suppose succ n \u2208 of_nat s,\n   have odd (s / 2^(succ n)),    from odd_of_mem_of_nat this,\n   have odd ((s / 2) / (2 ^ n)), by rewrite [pow_succ' at this, nat.div_div_eq_div_mul, mul.comm]; assumption,\n   show n \u2208 of_nat (s / 2),        from mem_of_nat_of_odd this)\n  (suppose n \u2208 of_nat (s / 2),\n   have odd ((s / 2) / (2 ^ n)), from odd_of_mem_of_nat this,\n   have odd (s / 2^(succ n)),      by rewrite [pow_succ', mul.comm, -nat.div_div_eq_div_mul]; assumption,\n   show succ n \u2208 of_nat s,             from mem_of_nat_of_odd this)\n\nprivate lemma odd_of_zero_mem (s : nat) : 0 \u2208 of_nat s \u2194 odd s :=\nbegin\n  unfold of_nat, rewrite [mem_sep_eq, pow_zero, nat.div_one, mem_upto_eq],\n  show 0 < succ s \u2227 odd s \u2194 odd s, from\n  iff.intro\n    (assume h, and.right h)\n    (assume h, and.intro (zero_lt_succ s) h)\nend\n\nprivate lemma even_of_not_zero_mem (s : nat) : 0 \u2209 of_nat s \u2194 even s :=\nhave aux : 0 \u2209 of_nat s \u2194 \u00acodd s, from not_iff_not_of_iff (odd_of_zero_mem s),\niff.intro\n  (suppose 0 \u2209 of_nat s, even_of_not_odd (iff.mp aux this))\n  (suppose even s, iff.mpr aux (not_odd_of_even this))\n\nprivate lemma even_to_nat (s : finset nat) : even (to_nat s) \u2194 0 \u2209 s :=\nfinset.induction_on s dec_trivial\n  (\u03bb a s nains ih,\n    begin\n      rewrite [to_nat_insert nains], apply iff.intro,\n        suppose even (2^a + to_nat s), by_cases\n          (suppose e : even (2^a), by_cases\n            (suppose even (to_nat s),\n              have 0 \u2209 s, from iff.mp ih this,\n              suppose 0 \u2208 insert a s, or.elim (eq_or_mem_of_mem_insert this)\n                (suppose 0 = a, begin rewrite [-this at e], exact absurd e not_even_one end)\n                (by contradiction))\n            (suppose odd  (to_nat s), absurd `even (2^a + to_nat s)` (odd_add_of_even_of_odd `even (2^a)` this)))\n          (suppose o : odd (2^a), by_cases\n            (suppose even (to_nat s), absurd `even (2^a + to_nat s)` (odd_add_of_odd_of_even `odd (2^a)` this))\n            (suppose odd  (to_nat s), suppose 0 \u2208 insert a s, or.elim (eq_or_mem_of_mem_insert this)\n              (suppose 0 = a,\n                have even (to_nat s), from iff.mpr ih (by rewrite -this at nains; exact nains),\n                absurd this `odd (to_nat s)`)\n              (suppose 0 \u2208 s,\n                have a \u2260 0, from suppose a = 0, by subst a; contradiction,\n                begin\n                  cases a with a, exact absurd rfl `0 \u2260 0`,\n                  have odd (2*2^a),  by rewrite [pow_succ' at o, mul.comm]; exact o,\n                  have even (2*2^a), from !even_two_mul,\n                  exact absurd `even (2*2^a)` `odd (2*2^a)`\n                end))),\n        suppose 0 \u2209 insert a s,\n          have a \u2260 0, from suppose a = 0, absurd (by rewrite this; apply mem_insert) `0 \u2209 insert a s`,\n          have 0 \u2209 s, from suppose 0 \u2208 s, absurd (mem_insert_of_mem _ this) `0 \u2209 insert a s`,\n          have even (to_nat s), from iff.mpr ih this,\n          match a with\n          | 0         := suppose a = 0, absurd this `a \u2260 0`\n          | (succ a') := suppose a = succ a',\n            have even (2^(succ a')), by rewrite [pow_succ', mul.comm]; apply even_two_mul,\n            even_add_of_even_of_even this `even (to_nat s)`\n          end rfl\n    end)\n\nprivate lemma of_nat_eq_insert_zero {s : nat} : 0 \u2209 of_nat s \u2192 of_nat (2^0 + s) = insert 0 (of_nat s) :=\nassume h : 0 \u2209 of_nat s,\nhave even s,                  from iff.mp (even_of_not_zero_mem s) h,\nhave   odd (s+1),               from odd_succ_of_even this,\nhave zmem : 0 \u2208 of_nat (s+1), from iff.mpr (odd_of_zero_mem (s+1)) this,\nobtain w (hw : s = 2*w),        from exists_of_even `even s`,\nbegin\n  rewrite [pow_zero, add.comm, hw],\n  show of_nat (2*w+1) = insert 0 (of_nat (2*w)), from\n  finset.ext (\u03bb n,\n    match n with\n    | 0      := iff.intro (\u03bb h, !mem_insert) (\u03bb h, by rewrite [hw at zmem]; exact zmem)\n    | succ m :=\n       have d\u2081  : 1 / 2 = (0:nat),  from dec_trivial,\n       have aux : _, from calc\n         succ m \u2208 of_nat (2 * w + 1) \u2194 m \u2208 of_nat ((2*w+1) / 2) : succ_mem_of_nat\n                  ...                \u2194 m \u2208 of_nat w             : by rewrite [add.comm, add_mul_div_self_left _ _ (dec_trivial : 2 > 0), d\u2081, zero_add]\n                  ...                \u2194 m \u2208 of_nat (2*w / 2)     : by rewrite [mul.comm, nat.mul_div_cancel _ (dec_trivial : 2 > 0)]\n                  ...                \u2194 succ m \u2208 of_nat (2*w)    : succ_mem_of_nat,\n       iff.intro\n         (\u03bb hl, finset.mem_insert_of_mem _ (iff.mp aux hl))\n         (\u03bb hr, or.elim (eq_or_mem_of_mem_insert hr)\n           (by contradiction)\n           (iff.mpr aux))\n    end)\nend\n\nprivate lemma of_nat_eq_insert : \u2200 {n s : nat}, n \u2209 of_nat s \u2192 of_nat (2^n + s) = insert n (of_nat s)\n| 0        s h := of_nat_eq_insert_zero h\n| (succ n) s h :=\n  have n \u2209 of_nat (s / 2),\n    from iff.mp (not_iff_not_of_iff !succ_mem_of_nat) h,\n  have ih : of_nat (2^n + s / 2) = insert n (of_nat (s / 2)), from of_nat_eq_insert this,\n  finset.ext (\u03bb x,\n  have gen : \u2200 m, m \u2208 of_nat (2^(succ n) + s) \u2194 m \u2208 insert (succ n) (of_nat s)\n  | zero     :=\n    have even (2^(succ n)), by rewrite [pow_succ', mul.comm]; apply even_two_mul,\n    have aux\u2081 : odd (2^(succ n) + s) \u2194 odd s, from iff.intro\n      (suppose odd (2^(succ n) + s), by_contradiction\n        (suppose \u00ac odd s,\n         have even s,                from even_of_not_odd this,\n         have even (2^(succ n) + s), from even_add_of_even_of_even `even (2^(succ n))` this,\n         absurd `odd (2^(succ n) + s)` (not_odd_of_even this)))\n      (suppose odd s, odd_add_of_even_of_odd `even (2^(succ n))` this),\n    have aux\u2082 : odd s \u2194 0 \u2208 insert (succ n) (of_nat s), from iff.intro\n      (suppose odd s, finset.mem_insert_of_mem _ (iff.mpr !odd_of_zero_mem this))\n      (suppose 0 \u2208 insert (succ n) (of_nat s), or.elim (eq_or_mem_of_mem_insert this)\n         (by contradiction)\n         (suppose 0 \u2208 of_nat s, iff.mp !odd_of_zero_mem this)),\n    calc\n      0 \u2208 of_nat (2^(succ n) + s) \u2194 odd (2^(succ n) + s)           : odd_of_zero_mem\n                             ...  \u2194 odd s                          : aux\u2081\n                             ...  \u2194 0 \u2208 insert (succ n) (of_nat s) : aux\u2082\n  | (succ m) :=\n    have aux : m \u2208 insert n (of_nat (s / 2)) \u2194 succ m \u2208 insert (succ n) (of_nat s), from iff.intro\n      (assume hl, or.elim (eq_or_mem_of_mem_insert hl)\n        (suppose m = n,                by subst m; apply mem_insert)\n        (suppose m \u2208 of_nat (s / 2), finset.mem_insert_of_mem _ (iff.mpr !succ_mem_of_nat this)))\n      (assume hr, or.elim (eq_or_mem_of_mem_insert hr)\n        (suppose succ m = succ n,\n         have m = n, by injection this; assumption,\n         by subst m; apply mem_insert)\n        (suppose succ m \u2208 of_nat s, finset.mem_insert_of_mem _ (iff.mp !succ_mem_of_nat this))),\n    calc\n      succ m \u2208 of_nat (2^(succ n) + s) \u2194 succ m \u2208 of_nat (2^n * 2 + s)       : by rewrite pow_succ'\n                                 ...   \u2194 m \u2208 of_nat ((2^n * 2 + s) / 2)      : succ_mem_of_nat\n                                 ...   \u2194 m \u2208 of_nat (2^n + s / 2)            : by rewrite [add.comm, add_mul_div_self (dec_trivial : 2 > 0), add.comm]\n                                 ...   \u2194 m \u2208 insert n (of_nat (s / 2))       : by rewrite ih\n                                 ...   \u2194 succ m \u2208 insert (succ n) (of_nat s) : aux,\n  gen x)\n\nlemma of_nat_to_nat (s : finset nat) : of_nat (to_nat s) = s :=\nfinset.induction_on s rfl\n  (\u03bb a s nains ih, by rewrite [to_nat_insert nains, -ih at nains, of_nat_eq_insert nains, ih])\n\nprivate definition predimage (s : finset nat) : finset nat :=\n{ n \u2208 image pred s | succ n \u2208 s }\n\nprivate lemma mem_image_pred_of_succ_mem {n : nat} {s : finset nat} : succ n \u2208 s \u2192 n \u2208 image pred s :=\nassume h,\n  have pred (succ n) \u2208 image pred s, from mem_image_of_mem _ h,\n  begin rewrite [pred_succ at this], assumption end\n\nprivate lemma mem_predimage_of_succ_mem {n : nat} {s : finset nat} : succ n \u2208 s \u2192 n \u2208 predimage s :=\nassume h, begin unfold predimage, rewrite [mem_sep_eq], exact and.intro (mem_image_pred_of_succ_mem h) h end\n\nprivate lemma succ_mem_of_mem_predimage {n : nat} {s : finset nat} : n \u2208 predimage s \u2192 succ n \u2208 s :=\nbegin\n  unfold predimage, rewrite [mem_sep_eq],\n  suppose n \u2208 image pred s \u2227 succ n \u2208 s, and.right this\nend\n\nprivate lemma predimage_insert_zero (s : finset nat) : predimage (insert 0 s) = predimage s :=\nfinset.ext (\u03bb n,\n  begin\n    unfold predimage, rewrite [*mem_sep_eq, image_insert, pred_zero], apply iff.intro,\n    suppose n \u2208 insert 0 (image pred s) \u2227 succ n \u2208 insert 0 s,\n      have succ n \u2208 s, from or.elim (eq_or_mem_of_mem_insert (and.right this))\n        (by contradiction)\n        (\u03bb h, h),\n      and.intro (mem_image_pred_of_succ_mem this) this,\n    suppose n \u2208 image pred s \u2227 succ n \u2208 s,\n      obtain h\u2081 h\u2082, from this,\n      and.intro (mem_insert_of_mem 0 h\u2081) (mem_insert_of_mem 0 h\u2082)\n  end)\n\nprivate lemma predimage_insert_succ (n : nat) (s : finset nat) : predimage (insert (succ n) s) = insert n (predimage s) :=\nfinset.ext (\u03bb m,\n  begin\n    unfold predimage, rewrite [*mem_sep_eq, *image_insert, pred_succ, *mem_insert_eq, *mem_sep_eq], apply iff.intro,\n      suppose (m = n \u2228 m \u2208 image pred s) \u2227 (succ m = succ n \u2228 succ m \u2208 s),\n        obtain h\u2081 h\u2082, from this,\n        or.elim h\u2081\n          (suppose m = n, or.inl this)\n          (suppose m \u2208 image pred s, or.elim h\u2082\n            (suppose succ m = succ n, by injection this; left; assumption)\n            (suppose succ m \u2208 s, by right; split; repeat assumption)),\n      suppose m = n \u2228 m \u2208 image pred s \u2227 succ m \u2208 s, or.elim this\n        (suppose m = n, and.intro (or.inl this) (or.inl (by subst m)))\n        (suppose m \u2208 image pred s \u2227 succ m \u2208 s,\n          obtain h\u2081 h\u2082, from this,\n          and.intro (or.inr h\u2081) (or.inr h\u2082))\n  end)\n\nprivate lemma of_nat_div2 (s : nat) : of_nat (s / 2) = predimage (of_nat s) :=\nfinset.ext (\u03bb n, iff.intro\n  (suppose n \u2208 of_nat (s / 2),\n   have succ n \u2208 of_nat s, from iff.mpr !succ_mem_of_nat this,\n   mem_predimage_of_succ_mem this)\n  (suppose n \u2208 predimage (of_nat s),\n   have succ n \u2208 of_nat s, from succ_mem_of_mem_predimage this,\n   iff.mp !succ_mem_of_nat this))\n\nprivate lemma to_nat_predimage (s : finset nat) : to_nat (predimage s) = (to_nat s) / 2 :=\nbegin\n  induction s with a s nains ih,\n   reflexivity,\n   cases a with a,\n   { rewrite [predimage_insert_zero, ih, to_nat_insert nains, pow_zero],\n     have 0 \u2209 of_nat (to_nat s), begin rewrite of_nat_to_nat, exact nains end,\n     have even (to_nat s), from iff.mp !even_of_not_zero_mem this,\n     obtain (w : nat) (hw : to_nat s = 2*w), from exists_of_even this,\n     begin\n       rewrite hw,\n       have d\u2081 : 1 / 2 = (0:nat),          from dec_trivial,\n       show 2 * w / 2 = (1 + 2 * w) / 2, by\n         rewrite [add_mul_div_self_left _ _ (dec_trivial : 2 > 0), mul.comm,\n                  nat.mul_div_cancel _ (dec_trivial : 2 > 0), d\u2081, zero_add]\n     end },\n   { have a \u2209 predimage s, from suppose a \u2208 predimage s, absurd (succ_mem_of_mem_predimage this) nains,\n     rewrite [predimage_insert_succ, to_nat_insert nains, pow_succ', add.comm,\n              add_mul_div_self (dec_trivial : 2 > 0), -ih, to_nat_insert this, add.comm] }\nend\n\nlemma to_nat_of_nat (s : nat) : to_nat (of_nat s) = s :=\nnat.strong_induction_on s\n  (\u03bb n ih, by_cases\n    (suppose n = 0, by rewrite this)\n    (suppose n \u2260 0,\n      have n / 2 < n, from div_lt_of_ne_zero this,\n      have to_nat (of_nat (n / 2)) = n / 2, from ih _ this,\n      have e\u2081 : to_nat (of_nat n) / 2 = n / 2, from calc\n        to_nat (of_nat n) / 2 = to_nat (predimage (of_nat n)) : by rewrite to_nat_predimage\n                          ...   = to_nat (of_nat (n / 2))     : by rewrite of_nat_div2\n                          ...   = n / 2                       : this,\n      have e\u2082 : even (to_nat (of_nat n)) \u2194 even n, from calc\n        even (to_nat (of_nat n)) \u2194 0 \u2209 of_nat n : even_to_nat\n                             ... \u2194 even n       : even_of_not_zero_mem,\n      eq_of_div2_of_even e\u2081 e\u2082))\n\nopen equiv\n\ndefinition finset_nat_equiv_nat : finset nat \u2243 nat :=\nmk to_nat of_nat of_nat_to_nat to_nat_of_nat\n\nend finset\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/finset/equiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7341411268347764}}
{"text": "/-\n# References\n\n1. Levin, Oscar. Discrete Mathematics: An Open Introduction. 3rd ed., n.d.\n   https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf.\n-/\n\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.Ring\n\n/--[1]\nA 0th-indexed arithmetic sequence.\n-/\nstructure Arithmetic where\n  a\u2080 : Int\n  \u0394 : Int\n\nnamespace Arithmetic\n\n/--[1]\nReturns the value of the `n`th term of an arithmetic sequence.\n-/\ndef termClosed (seq : Arithmetic) (n : Nat) : Int := seq.a\u2080 + seq.\u0394 * n\n\n/--[1]\nReturns the value of the `n`th term of an arithmetic sequence.\n-/\ndef termRecursive : Arithmetic \u2192 Nat \u2192 Int\n  | seq,       0 => seq.a\u2080\n  | seq, (n + 1) => seq.\u0394 + seq.termRecursive n\n\n/--[1]\nThe recursive definition and closed definitions of an arithmetic sequence are\nequivalent.\n-/\ntheorem term_recursive_closed (seq : Arithmetic) (n : Nat)\n        : seq.termRecursive n = seq.termClosed n :=\n  Nat.recOn\n    n\n    (by unfold termRecursive termClosed; norm_num)\n    (fun n ih => calc\n      termRecursive seq (Nat.succ n)\n          = seq.\u0394 + seq.termRecursive n := rfl\n        _ = seq.\u0394 + seq.termClosed n := by rw [ih]\n        _ = seq.\u0394 + (seq.a\u2080 + seq.\u0394 * n) := rfl\n        _ = seq.a\u2080 + seq.\u0394 * (n + 1) := by ring\n        _ = termClosed seq (n + 1) := rfl)\n\n/--[1]\nSummation of the first `n` terms of an arithmetic sequence.\n-/\ndef sum : Arithmetic \u2192 Nat \u2192 Int\n  |   _,       0 => 0\n  | seq, (n + 1) => seq.termClosed n + seq.sum n\n\n/--[1]\nThe closed formula of the summation of the first `n` terms of an arithmetic\nseries.\n--/\ntheorem sum_closed_formula (seq : Arithmetic) (n : Nat)\n        : seq.sum n = (n / 2) * (seq.a\u2080 + seq.termClosed (n - 1)) :=\n  Nat.recOn\n    n\n    (by unfold sum termClosed; norm_num)\n    (fun n ih => calc\n      sum seq n.succ\n          = seq.termClosed n + seq.sum n := rfl\n        _ = seq.termClosed n + (n / 2 * (seq.a\u2080 + seq.termClosed (n - 1))) := by rw [ih]\n        _ = seq.a\u2080 + seq.\u0394 * n + (n / 2 * (seq.a\u2080 + (seq.a\u2080 + seq.\u0394 * \u2191(n - 1)))) := rfl\n        -- TODO: To continue, need to find how to deal with division.\n        _ = \u2191(n + 1) / 2 * (seq.a\u2080 + seq.termClosed n) := by sorry)\n\nend Arithmetic", "meta": {"author": "jrpotter", "repo": "bookshelf", "sha": "aa59363e7402c30f227e38948150f9592820e532", "save_path": "github-repos/lean/jrpotter-bookshelf", "path": "github-repos/lean/jrpotter-bookshelf/bookshelf-aa59363e7402c30f227e38948150f9592820e532/bookshelf/Bookshelf/Sequence/Arithmetic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7341342928833281}}
{"text": "/-\nCopyright (c) 2022 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport algebra.star.basic\nimport group_theory.submonoid.membership\n\n/-!\n# Unitary elements of a star monoid\n\nThis file defines `unitary R`, where `R` is a star monoid, as the submonoid made of the elements\nthat satisfy `star U * U = 1` and `U * star U = 1`, and these form a group.\nThis includes, for instance, unitary operators on Hilbert spaces.\n\nSee also `matrix.unitary_group` for specializations to `unitary (matrix n n R)`.\n\n## Tags\n\nunitary\n-/\n\n/--\nIn a *-monoid, `unitary R` is the submonoid consisting of all the elements `U` of\n`R` such that `star U * U = 1` and `U * star U = 1`.\n-/\ndef unitary (R : Type*) [monoid R] [star_semigroup R] : submonoid R :=\n{ carrier := {U | star U * U = 1 \u2227 U * star U = 1},\n  one_mem' := by simp only [mul_one, and_self, set.mem_set_of_eq, star_one],\n  mul_mem' := \u03bb U B \u27e8hA\u2081, hA\u2082\u27e9 \u27e8hB\u2081, hB\u2082\u27e9,\n  begin\n    refine \u27e8_, _\u27e9,\n    { calc star (U * B) * (U * B) = star B * star U * U * B     : by simp only [mul_assoc, star_mul]\n                            ...   = star B * (star U * U) * B   : by rw [\u2190mul_assoc]\n                            ...   = 1                           : by rw [hA\u2081, mul_one, hB\u2081] },\n    { calc U * B * star (U * B) = U * B * (star B * star U)     : by rw [star_mul]\n                            ... = U * (B * star B) * star U     : by simp_rw [\u2190mul_assoc]\n                            ... = 1                             : by rw [hB\u2082, mul_one, hA\u2082] }\n  end }\n\nvariables {R : Type*}\n\nnamespace unitary\n\nsection monoid\nvariables [monoid R] [star_semigroup R]\n\nlemma mem_iff {U : R} : U \u2208 unitary R \u2194 star U * U = 1 \u2227 U * star U = 1 := iff.rfl\n@[simp] lemma star_mul_self_of_mem {U : R} (hU : U \u2208 unitary R) : star U * U = 1 := hU.1\n@[simp] lemma mul_star_self_of_mem {U : R} (hU : U \u2208 unitary R) : U * star U = 1 := hU.2\n\nlemma star_mem {U : R} (hU : U \u2208 unitary R) : star U \u2208 unitary R :=\n\u27e8by rw [star_star, mul_star_self_of_mem hU], by rw [star_star, star_mul_self_of_mem hU]\u27e9\n\n@[simp] lemma star_mem_iff {U : R} : star U \u2208 unitary R \u2194 U \u2208 unitary R :=\n\u27e8\u03bb h, star_star U \u25b8 star_mem h, star_mem\u27e9\n\ninstance : has_star (unitary R) := \u27e8\u03bb U, \u27e8star U, star_mem U.prop\u27e9\u27e9\n\n@[simp, norm_cast] lemma coe_star {U : unitary R} : \u2191(star U) = (star U : R) := rfl\n\nlemma coe_star_mul_self (U : unitary R) : (star U : R) * U = 1 := star_mul_self_of_mem U.prop\nlemma coe_mul_star_self (U : unitary R) :  (U : R) * star U = 1 := mul_star_self_of_mem U.prop\n\n@[simp] lemma star_mul_self (U : unitary R) : star U * U = 1 := subtype.ext $ coe_star_mul_self U\n@[simp] lemma mul_star_self (U : unitary R) : U * star U = 1 := subtype.ext $ coe_mul_star_self U\n\ninstance : group (unitary R) :=\n{ inv := star,\n  mul_left_inv := star_mul_self,\n  ..submonoid.to_monoid _ }\n\ninstance : has_involutive_star (unitary R) :=\n\u27e8\u03bb _, by { ext, simp only [coe_star, star_star] }\u27e9\n\ninstance : star_semigroup (unitary R) :=\n\u27e8\u03bb _ _, by { ext, simp only [coe_star, submonoid.coe_mul, star_mul] }\u27e9\n\ninstance : inhabited (unitary R) := \u27e81\u27e9\n\nlemma star_eq_inv (U : unitary R) : star U = U\u207b\u00b9 := rfl\n\nlemma star_eq_inv' : (star : unitary R \u2192 unitary R) = has_inv.inv := rfl\n\n/-- The unitary elements embed into the units. -/\n@[simps]\ndef to_units : unitary R \u2192* R\u02e3 :=\n{ to_fun := \u03bb x, \u27e8x, \u2191(x\u207b\u00b9), coe_mul_star_self x, coe_star_mul_self x\u27e9,\n  map_one' := units.ext rfl,\n  map_mul' := \u03bb x y, units.ext rfl }\n\nlemma to_units_injective : function.injective (to_units : unitary R \u2192 R\u02e3) :=\n\u03bb x y h, subtype.ext $ units.ext_iff.mp h\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid R] [star_semigroup R]\n\ninstance : comm_group (unitary R) :=\n{ ..unitary.group,\n  ..submonoid.to_comm_monoid _ }\n\nlemma mem_iff_star_mul_self {U : R} : U \u2208 unitary R \u2194 star U * U = 1 :=\nmem_iff.trans $ and_iff_left_of_imp $ \u03bb h, mul_comm (star U) U \u25b8 h\n\nlemma mem_iff_self_mul_star {U : R} : U \u2208 unitary R \u2194 U * star U = 1 :=\nmem_iff.trans $ and_iff_right_of_imp $ \u03bb h, mul_comm U (star U) \u25b8 h\n\nend comm_monoid\n\nsection group_with_zero\nvariables [group_with_zero R] [star_semigroup R]\n\n@[norm_cast] lemma coe_inv (U : unitary R) : \u2191(U\u207b\u00b9) = (U\u207b\u00b9 : R) :=\neq_inv_of_mul_right_eq_one (coe_mul_star_self _)\n\n@[norm_cast] lemma coe_div (U\u2081 U\u2082 : unitary R) : \u2191(U\u2081 / U\u2082) = (U\u2081 / U\u2082 : R) :=\nby simp only [div_eq_mul_inv, coe_inv, submonoid.coe_mul]\n\n@[norm_cast] lemma coe_zpow (U : unitary R) (z : \u2124) : \u2191(U ^ z) = (U ^ z : R) :=\nbegin\n  induction z,\n  { simp [submonoid.coe_pow], },\n  { simp [coe_inv] },\nend\n\nend group_with_zero\n\nsection ring\nvariables [ring R] [star_ring R]\n\ninstance : has_neg (unitary R) :=\n{ neg := \u03bb U, \u27e8-U, by { simp_rw [mem_iff, star_neg, neg_mul_neg], exact U.prop }\u27e9 }\n\n@[norm_cast] lemma coe_neg (U : unitary R) : \u2191(-U) = (-U : R) := rfl\n\ninstance : has_distrib_neg (unitary R) :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb U, subtype.ext $ neg_neg _,\n  neg_mul := \u03bb U\u2081 U\u2082, subtype.ext $ neg_mul _ _,\n  mul_neg := \u03bb U\u2081 U\u2082, subtype.ext $ mul_neg _ _ }\n\nend ring\n\nend unitary\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/star/unitary.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.734121821155451}}
{"text": "import Mathlib\n\n/-!\n# Subtraction: example of intertwined proofs and definitions. \n\nThe difference of natural numbers is not a natural number. We see three ways of overcoming this problem, which illustrate various important concepts in Lean. \n\nThe first two are in this module while the third is in a sequel. The first two are in fact available in functional programming langauges such as `scala` and `Haskell`. \n\nTo begin with, we see how Lean deals with subtraction on `\u2115`.\n\n```lean\n#eval 4 - 3 -- 1\n\n#eval 3 - 4 -- 0\n```\n\nThe first example is as expected, but the second may be surprising. According to the documentation of Lean 4,  `Nat.sub` is:\n> (Truncated) subtraction of natural numbers. Because natural numbers are not closed under subtraction, we define `m - n` to be 0 when `n < m`.\n\n-/\n\n#eval 4 - 3 -- 1\n\n#eval 3 - 4 -- 0\n\n#check Nat.sub\n\n/-!\n## Subtraction with panic\n\nOur first remedy is to define subtraction as Lean does but with an error message when the result is incorrect. \n\n```lean\ndef Nat.sub! (m n: Nat) :=\nmatch m, n with \n| m, 0 => m\n| m + 1, n + 1 => Nat.sub! m n\n| 0, _ + 1 => panic! \"cannot subtract a larger number from a smaller one\"\n\n#eval Nat.sub! 4 3 -- 1\n#eval Nat.sub! 3 4 -- 0 (but with an error message)\n```\n-/\n\n/-- Subtraction of natural numbers; panics when difference is negative. -/\ndef Nat.sub! (m n: Nat) :=\nmatch m, n with \n| m, 0 => m\n| m + 1, n + 1 => Nat.sub! m n\n| 0, _ + 1 => panic! \"cannot subtract a larger number from a smaller one\"\n\n#eval Nat.sub! 4 3 -- 1\n-- #eval Nat.sub! 3 4 -- 0\n\n/-! \nA brief digression: Lean 4 lets us easily introduce new notation for our variant of subtraction. \n\n```lean\ninfix:64 \"-!\" => Nat.sub!\n```\n-/\n\n/-- infix notation for subtraction with panic. -/\ninfix:64 \"-!\" => Nat.sub!\n\n#eval 4 -! 3\n\n/-!\n## More on panicking\n\nThe intriguing fact about the illegal subtraction is that, while it gave an error, it still had a value. Indeed, we see more of the underlying phenomenon in the following examples. \n\n```lean\ndef panicNat : \u2115  := panic! \"I like to panic\"\n\n#check panicNat  -- \u2115 \n-- #eval panicNat -- 0 (with error)\n```\n\nNote that `panicNat` had a type, and the computation of the type did not give an error. Hence for logical consistency, the value of `panicNat` must be a term of type `\u2115`.\n\nIndeed, if we try to make an analogous definition for `Empty` we get an error. \n\n```lean\ndef badPanic : Empty :=\n  panic! \"sometimes we are not even allowed to panic\"\n```\ngives the error message:\n```lean\nfailed to synthesize instance\n  Inhabited Empty\n```\n\nIndeed the empty type has no inhabitants so allowing a definition of `badPanic` would be a contradiction.\n-/\n\n/-- A natural number obtained by panicking. -/\ndef panicNat : \u2115  := panic! \"I like to panic\"\n\n#check panicNat  -- \u2115 \n-- #eval panicNat -- 0 (with error)\n\n#check Empty -- Type\n\n-- def badPanic : Empty :=\n--   panic! \"sometimes we are not even allowed to panic\"\n\n/-!\n## Default values and typeclasses\n\nThe value returned when panicing is the `default` value of the type. Not every type has a default value. For example, the `Empty` type has no default value. \n\nDefault values can be _synthesized_ from other default values by so called _typeclass_ inference. First we see some examples of default values. \n\n```lean\n\n-/\n\n/-- The default value in `\u2115`. -/\ndef defaultNat : \u2115 := default\n/-!\n```lean\n#eval defaultNat -- 0\n```\n\nAs we have seen earlier, the default value of `\u2115` is `0`. \n-/\n\n#eval defaultNat -- 0\n\n\n/-!\nAs we saw in the case of panic, the default value of `Empty` is not defined. The following gives an error message.\n\n```lean\ndef defaultEmpty : Empty := default\n```\n\n-/\n-- def defaultEmpty : Empty := default\n\n/-- The default value in `\u2115 \u00d7 \u2115`. -/\ndef default\u2081 : \u2115 \u00d7 \u2115 := default\n\n/-!\nA more interesting example is the default value of a product type. \n\n```lean\n#eval default\u2081 -- (0, 0)\n```\n\nThis is inferred from the default values of the components.\n-/\n\n#eval default\u2081 -- (0, 0)\n\n/-!\n### Typeclasses\n\nWe sketch the basic ideas of typeclasses and how they are used here. The `default` value of a type `\u03b1` is based on `Inhabited \u03b1`.\n\n* if `\u03b1` is a type `Inhabited \u03b1` is a type.\n* `Inhabited` is called a _typeclass_.\n* a term of type `Inhabited \u03b1` (called an _instance_) corresponds to a default term of type `\u03b1`.\n* Lean _infers_ instances from other instances.\n-/\n\n/-- The default value in `\u2115 \u00d7 String \u00d7 (String \u2192 \u2115)`. -/\ndef default\u2082 : \u2115 \u00d7 String \u00d7 (String \u2192 \u2115) :=\n      default\n\n#reduce default\u2082 -- (Nat.zero, \"\", fun x => Nat.zero)\n\n/-- The default value in `\u2115 \u00d7 (String \u2192 \u2115) \u00d7 (Empty \u2192 Empty)`. -/\ndef default\u2083 : \u2115 \u00d7 (String \u2192 \u2115) \u00d7 \n  (Empty \u2192 Empty) := default\n\n#reduce default\u2083 -- (Nat.zero, fun x => Nat.zero, fun a => False.rec (fun x => Empty) (_ : False))\n\n/-!\nSome more examples of typeclass inference. \n\n```lean\n#reduce default\u2082 -- (Nat.zero, \"\", fun x => Nat.zero)\n\n#reduce default\u2083 -- (Nat.zero, fun x => Nat.zero, fun a => False.rec (fun x => Empty) (_ : False))\n```\n\nIn the first example, we see that default functions are inferred if the codomains are inhabited, with a constant function used as a default. \n\nLean has inferred a default function from `Empty` to `Empty` by using the default function from `Empty` to `False`. To illustrate introducing new  defaults we introduce a new type `MyEmpty` which is also an empty type.\n-/\n\n/-- An empty type. -/\ninductive MyEmpty where\n\n/-- An instance of `Inhabited` corresponding to the identity function from any type to itself. -/\ninstance (priority := low)(\u03b1 : Type) : Inhabited (\u03b1 \u2192 \u03b1) :=\n    \u27e8id\u27e9\n\n/-- The default value in `\u2115 \u00d7 (String \u2192 \u2115) \u00d7 (\u2115 \u2192 MyEmpty \u2192 MyEmpty)`. -/\ndef default\u2084  : \u2115 \u00d7 (String \u2192 \u2115) \u00d7 \n  (\u2115 \u2192 MyEmpty \u2192 MyEmpty) := default\n\n/-!\nWe see this picked up in the following construction. Note that defining a default for `MyEmpty` gives an error. \n\n\n```lean\n#reduce default\u2084 -- (Nat.zero, fun x => Nat.zero, fun x a => a)\n```\n-/\n\n#reduce default\u2084 -- (Nat.zero, fun x => Nat.zero, fun x a => a)\n\n\n/-- The default value in `\u2115 \u00d7 String (String \u2192 \u2115) \u00d7 (Empty \u00d7 Empty)` in the presence of the identity default instance. -/\ndef default\u2085 : \u2115 \u00d7 (String \u2192 \u2115) \u00d7 \n  (Empty \u2192 Empty) := default\n\n#reduce default\u2085 -- (Nat.zero, fun x => Nat.zero, fun a => a)\n\n/-- The default value in `\u2115 \u00d7 String (\u2115 \u2192 \u2115) \u00d7 (MyEmpty \u00d7 MyEmpty)` in the presence of the identity default instance. -/\ndef default\u2086  : \u2115 \u00d7 (\u2115  \u2192 \u2115) \u00d7 \n  (\u2115 \u2192 MyEmpty \u2192 MyEmpty) := default\n\n#reduce default\u2086 -- (Nat.zero, fun x => Nat.zero, fun x a => a)\n\n/-!\nThe following example shows the effect of priorities of instances. \n\n```lean\n#reduce default\u2086 -- (Nat.zero, fun x => Nat.zero, fun x a => a)\n```\n\nObserve that the second component is the constant function `fun x => Nat.zero` and not the identity function `id`.\n-/\n\n/-! \n## Second rectification: `Option` \n\nThe second choice is to essentially return values only when they are valid, by wrapping them in an `Option`. \n\n* Given `\u03b1` a type `Option \u03b1` is a type\n* Terms of type `Option \u03b1` are of two forms\n   - `some x` where `x : \u03b1`\n   - `none`\n-/\n\n/-- Option valued subtraction of natural numbers -/\ndef Nat.sub? : \u2115 \u2192 \u2115 \u2192 Option \u2115\n| m, 0 => some m\n| m + 1, n + 1 => Nat.sub? m n\n| 0, _ + 1 => none\n\ninfix:64 \"-?\" => Nat.sub?\n\n/-!\nSome examples of subtraction returning option types. \n\n```lean\n#eval 4 -? 3 -- some 1\n\n#eval 3 -? 4 -- none\n```\n-/\n\n#eval 4 -? 3 -- some 1\n\n#eval 3 -? 4 -- none\n\n/-!\nIf we return option types we need to be able to handle them. We illustrate this by defining a function that returns the double of the difference if it is defined. \n\n```lean\ndef Nat.doubleSub? (m n : \u2115) : Option \u2115 :=\n  (m -? n).map (\u00b7  * 2)\n\n#eval Nat.doubleSub? 5 3 -- some 4\n\n#eval Nat.doubleSub? 5 32 -- none\n```\n-/\n\n/-- Optionally return `(m - n) * 2` if `m \u2265 n`. -/\ndef Nat.doubleSub? (m n : \u2115) : Option \u2115 :=\n  (m -? n).map (\u00b7  * 2)\n\n#eval Nat.doubleSub? 5 3 -- some 4\n\n#eval Nat.doubleSub? 5 32 -- none\n\n/-!\nA convenient way to handle option types is to use the `do` notation. \n\n```lean\ndef Nat.tripleSub? (m n : \u2115) : Option \u2115 := \n  do\n    let d \u2190 m -? n \n    return d * 3\n\n#eval Nat.tripleSub? 5 3 -- some 6\n```\n-/\n\n/-- Optionally return `(m - n) * 3` if `m \u2265 n`. -/\ndef Nat.tripleSub? (m n : \u2115) : Option \u2115 := \n  do\n    let d \u2190 m -? n \n    return d * 3\n\n#eval Nat.tripleSub? 5 3 -- some 6\n\n/-- Optionally return `a - b - c` if this is non-negative. -/\ndef Nat.sub_sub? (a b c : \u2115) : Option \u2115 :=\n  do\n    let d\u2081 \u2190 a -? b\n    let d\u2082 \u2190 d\u2081 -? c\n    return d\u2082 \n\n/-!\nThe `do` notation is even more convenient when we compose option valued functions. \n\n```lean\ndef Nat.sub_sub? (a b c : \u2115) : Option \u2115 :=\n  do\n    let d\u2081 \u2190 a -? b\n    let d\u2082 \u2190 d\u2081 -? c\n    return d\u2082 \n```\n-/", "meta": {"author": "siddhartha-gadgil", "repo": "proofs-and-programs-2023", "sha": "9d95a5396c018b9a26ed0d27c52cd446794cd1aa", "save_path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023", "path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023/proofs-and-programs-2023-9d95a5396c018b9a26ed0d27c52cd446794cd1aa/PnP2023/Lec_01_18/NatSub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.855851148805615, "lm_q1q2_score": 0.7341218056172931}}
{"text": "import tactic\n\n-- Let `\u03a9` be a \"big underlying set\" and let `X` and `Y` and `Z` be subsets\n\nvariables (\u03a9 : Type) (X Y Z : set \u03a9) (a b c x y z : \u03a9)\n\nnamespace xena\n\n/-!\n\n# subsets\n\nLet's think about `X \u2286 Y`. Typeset `\u2286` with `\\sub` or `\\ss`\n-/\n\n-- `X \u2286 Y` is the same as `\u2200 a, a \u2208 X \u2192 a \u2208 Y` , by definition.\n\nlemma subset_def : X \u2286 Y \u2194 \u2200 a, a \u2208 X \u2192 a \u2208 Y :=\nbegin\n  -- true by definition\n  refl\nend\n\nlemma subset_refl : X \u2286 X :=\nbegin\n  intros a h,\n  exact h,\nend\n\nlemma subset_trans (hXY : X \u2286 Y) (hYZ : Y \u2286 Z) : X \u2286 Z :=\nbegin\n  -- If you start with `rw subset_def at *` then you\n  -- will have things like `hYZ : \u2200 (a : \u03a9), a \u2208 Y \u2192 a \u2208 Z`\n  -- You need to think of `hYZ` as a function, which has two\n  -- inputs: first a term `a` of type `\u03a9`, and second a proof `haY` that `a \u2208 Y`.\n  -- It then produces one output `haZ`, a proof that `a \u2208 Z`.\n  -- You can also think of it as an implication:\n  -- \"if a is in \u03a9, and if a \u2208 Y, then a \u2208 Z\". Because it's an implication,\n  -- you can `apply hYZ`. This is a really useful skill!\n  intros a h,\n  have hY : a \u2208 Y := \n    begin \n      exact hXY h,\n    end,\n  exact hYZ hY,\nend\n\n/-!\n\n# Equality of sets\n\nTwo sets are equal if and only if they have the same elements.\nThe name of this theorem is `set.ext_iff`.\n-/\n\nexample : X = Y \u2194 (\u2200 a, a \u2208 X \u2194 a \u2208 Y) :=\nbegin\n  exact set.ext_iff\nend\n\n-- In practice, you often have a goal `\u22a2 X = Y` and you want to reduce\n-- it to `a \u2208 X \u2194 a \u2208 Y` for an arbitary `a : \u03a9`. This can be done with\n-- the `ext` tactic. \n\n\nlemma subset.antisymm (hXY : X \u2286 Y) (hYX : Y \u2286 X) : X = Y :=\nbegin\n  -- start with `ext a`,\n  ext a,\n  split,\n  { exact @hXY a },\n  { intro hY,\n    exact hYX hY },\nend\n\n/-!\n\n## Unions and intersections\n\nType `\\cup` or `\\un` for `\u222a`, and `\\cap` or `\\i` for `\u2229`\n\n-/\n\nlemma union_def : a \u2208 X \u222a Y \u2194 a \u2208 X \u2228 a \u2208 Y :=\nbegin\n  -- true by definition\n  refl,\nend\n\nlemma inter_def : a \u2208 X \u2229 Y \u2194 a \u2208 X \u2227 a \u2208 Y :=\nbegin\n  -- true by definition\n  refl,\nend\n\n\n-- You can rewrite with those lemmas above if you're not comfortable with\n-- assuming they're true by definition.\n\n-- union lemmas\n\nlemma union_self : X \u222a X = X :=\nbegin\n  ext a,\n  split,\n  rotate,\n  { intro h, \n    exact or.inl h },\n  { intro h, \n    cases h, \n    repeat {exact h} },\nend\n\nlemma subset_union_left : X \u2286 X \u222a Y :=\nbegin\n  intros a h,\n  exact or.inl h,\nend\n\nlemma subset_union_right : Y \u2286 X \u222a Y :=\nbegin\n  intros a h,\n  exact or.inr h,\nend\n\nlemma union_subset_iff : X \u222a Y \u2286 Z \u2194 X \u2286 Z \u2227 Y \u2286 Z :=\nbegin\n  split,\n  { intro,  \n    split,\n    { apply subset_trans,\n      { exact subset_union_left _ X Y },\n      { assumption }},\n    { apply subset_trans,\n      { exact subset_union_right _ X Y },\n      { assumption }}},\n  { intros h a h',\n    cases h',\n    { exact h.left h' },\n    { exact h.right h' }},\nend\n\nvariable (W : set \u03a9)\n\nlemma union_subset_union (hWX : W \u2286 X) (hYZ : Y \u2286 Z) : W \u222a Y \u2286 X \u222a Z :=\nbegin\n  have h : W \u2286 X \u222a Z := sorry,\n  have h' : Y \u2286 X \u222a Z := sorry,\n  apply (union_subset_iff _ W Y (X \u222a Z)).mpr,\n  exact \u27e8h,h'\u27e9 \nend\n\n#check union_subset_union\n\nlemma union_subset_union_left (hXY : X \u2286 Y) : X \u222a Z \u2286 Y \u222a Z :=\nbegin\n  exact union_subset_union _ _ _ Z _ hXY (subset_refl _ _)  \nend\n\n-- etc etc\n\n-- intersection lemmas\n\nlemma inter_subset_left : X \u2229 Y \u2286 X :=\nbegin\n  sorry\nend\n\n-- don't forget `ext` to make progress with equalities of sets\n\nlemma inter_self : X \u2229 X = X :=\nbegin\n  sorry\nend\n\nlemma inter_comm : X \u2229 Y = Y \u2229 X :=\nbegin\n  ext a,\n  split,\n  repeat { exact \u03bb h, \u27e8h.right,h.left\u27e9 },\nend\n\nlemma inter_assoc : X \u2229 (Y \u2229 Z) = (X \u2229 Y) \u2229 Z :=\nbegin\n  sorry\nend\n\n/-!\n\n### Forall and exists\n\n-/\n\n#check Exists\n\nvariable (P : \u03a9 \u2192 Prop)\n\nlemma not_exists_iff_forall_not : \u00ac (\u2203 a, P a) \u2194 \u2200 b, \u00ac (P b) :=\nbegin\n  split,\n  { intros h b n,\n    exact h (exists.intro _ n)},\n  { intros h n,\n    apply exists.elim n,\n    exact h},\nend\n\nexample : \u00ac (\u2200 a, P a) \u2194 \u2203 b, \u00ac (P b) :=\nbegin\n  split,\n  { intros h', \n    by_contra,\n    apply (not_exists_iff_forall_not \u03a9 (\u03bb a, \u00ac P a)).mpr,\n    intros b n,\n    exact h (exists.intro b n),\n    sorry,\n    },\n  { intros h n, \n    cases h with a h',\n    exact h' (n a),\n    },\nend\n\nend xena\n\n", "meta": {"author": "UofSC-Spring-2023-Math-768-001", "repo": "formalising-mathematics", "sha": "5743b4e2904830d2d0febacf3b82d4b5b288717e", "save_path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalising-mathematics", "path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalising-mathematics/formalising-mathematics-5743b4e2904830d2d0febacf3b82d4b5b288717e/src/week_1/Part_B_sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511359371249, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7341218039145897}}
{"text": "import algebra.group algebra.group_power\n\nvariable A: Type*\n\ntheorem Q_02 (a b: A) [comm_group A]:\n  \u2200 n: \u2115, (a * b) ^ n = a ^ n * b ^ n\n| 0 :=\n  calc (a * b) ^ 0\n      = 1 : by rw pow_zero\n  ... = 1 * 1                 : (mul_one 1).symm\n  ... = (a ^ 0) * (b ^ 0)     : by rw [pow_zero, pow_zero]\n| (k + 1) :=\n  calc (a * b) ^ (k + 1)\n      = a * b * (a * b) ^ k       : pow_succ (a * b) k\n  ... = b * a * (a * b) ^ k       : by rw mul_comm a b\n  ... = b * a * (a ^ k * b ^ k)   : by rw (Q_02 k)\n  ... = b * (a * a ^ k) * b ^ k   : by rw [\u2190 mul_assoc, mul_assoc b a (a ^ k)]\n  ... = b * a ^ (k + 1) * b ^ k   : by rw pow_succ\n  ... = a ^ (k + 1) * (b * b ^ k) : by rw [mul_comm b (a ^ (k + 1)), mul_assoc]\n  ... = a ^ (k + 1) * b ^ (k + 1) : by rw [\u2190pow_succ]\n", "meta": {"author": "group-study-group", "repo": "herstein", "sha": "f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66", "save_path": "github-repos/lean/group-study-group-herstein", "path": "github-repos/lean/group-study-group-herstein/herstein-f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66/src/herstein/ex2_3/Q_02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338057771059, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7341154539939707}}
{"text": "------------------------------------------------------------------------\n-- \u00a7 Introducci\u00f3n                                                     --\n------------------------------------------------------------------------\n\n-- Se importan las t\u00e1cticas.\nimport tactic\n\n-- Nota: Las conectivas l\u00f3gicas son\n-- \u2192 \"condicional\"   se escribe con \\->\n-- \u00ac \"negaci\u00f3n\"      se escribe con \\not\n-- \u2227 \"conjunci\u00f3n\"    se escribe con \\and\n-- \u2194 \"bicondicional\" se escribe con \\<->\n-- \u2228 \"disyunci\u00f3n\"    se escribe con \\or\n\n-- Nota: Colocando el curso sobre un s\u00edmbolo y pulsando C-c C-k se\n-- indican las formas de escribirlo\n\n-- Nota: Se usar\u00e1n las siguientes t\u00e1cticas (que est\u00e1n en\n-- https://bit.ly/3pHFhBO )\n-- + intro\n-- + exact\n-- + apply\n-- + rw\n-- + cases\n-- + split\n-- + left\n-- + right\n\n-- Nota: En https://bit.ly/3pHFhBO se encuentran estas junto con m\u00e1s\n-- t\u00e1cticas. Por ejemplo, cc, tauto, tauto!, finish y library_search.\n\n-- Nota: Para evitar conflictos, se trabajar\u00e1 en el espacio de nombres\n-- oculto.\nnamespace oculto\n\n-- Nota: P, Q y R son variables sobre proposiciones.\nvariables (P Q R : Prop)\n\n------------------------------------------------------------------------\n-- \u00a7 Implicaciones (\u2192)                                                --\n------------------------------------------------------------------------\n\n-- Nota: En esta secci\u00f3n se usar\u00e1n las t\u00e1cticas intro, apply, exact y\n-- assumption.\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Demostrar que\n--    P \u2192 P\n-- ----------------------------------------------------\n\ntheorem id :\n  P \u2192 P :=\nbegin\n  intro hP,\n  exact hP\nend\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que el condicional no es\n-- asociativa probando que\n--    (false \u2192 (false \u2192 false)) \u2194 true\n--    ((false \u2192 false) \u2192 false) \u2194 false\n-- ----------------------------------------------------\n\nexample :\n  (false \u2192 (false \u2192 false)) \u2194 true :=\nby simp\n\nexample :\n  ((false \u2192 false) \u2192 false) \u2194 false :=\nby simp\n\n-- Nota: En Lean el condicional asocia por la derecha;\n-- es decir, (P \u2192 Q \u2192 R) es P \u2192 (Q \u2192 R).\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Demostrar que\n--    (P \u2192 Q \u2192 R) \u2194 (P \u2192 (Q \u2192 R))\n-- ----------------------------------------------------\n\nexample : (P \u2192 Q \u2192 R) \u2194 (P \u2192 (Q \u2192 R)) :=\nbegin\n  refl,\nend\n\n-- ----------------------------------------------------\n-- Ejercicio 4. Demostrar que\n--    P \u2192 Q \u2192 P\n-- ----------------------------------------------------\n\ntheorem imp_intro :\n  P \u2192 Q \u2192 P :=\nbegin\n  intro hP,\n  intro hQ,\n  exact hP,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que\n--    P \u2192 (P \u2192 Q) \u2192 Q\n-- ----------------------------------------------------------------------\n\nlemma modus_ponens :\n  P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  intro hP,\n  intro hPQ,\n  apply hPQ,\n  exact hP,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Demostrar que\n--    (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R)\n-- ----------------------------------------------------------------------\n\nlemma imp_trans :\n  (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  intros hPQ hQR hP,\n  apply hQR,\n  apply hPQ,\n  exact hP,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Demostrar que\n--    (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R)\n-- ----------------------------------------------------------------------\n\nlemma forall_imp :\n  (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  intro hPQR,\n  intro hPQ,\n  intro hP,\n  apply hPQR,\n  { exact hP, },\n  { apply hPQ,\n    exact hP, },\nend\n\n-------------------------------------------------------\n-- \u00a7 Negaci\u00f3n (\u00ac)                                    --\n-------------------------------------------------------\n\n-- Nota: La negaci\u00f3n \u00acP es, por definici\u00f3n (P \u2192 false).\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 8. Demostrar que\n--    \u00ac P \u2194 (P \u2192 false)\n-- ----------------------------------------------------------------------\n\ntheorem not_def\n  : \u00ac P \u2194 (P \u2192 false) :=\nbegin\n  refl,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 9. Demostrar que\n--    P \u2192 \u00ac\u00acP\n-- ----------------------------------------------------------------------\n\ntheorem not_not_intro :\n  P \u2192 \u00ac\u00acP :=\nbegin\n  intro hP,\n  rw not_def,\n  rw not_def,\n  intro hnP,\n  apply hnP,\n  exact hP,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  P \u2192 \u00ac\u00acP :=\nbegin\n  intro hP,\n  intro hnP,\n  apply hnP,\n  exact hP,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  P \u2192 \u00ac\u00acP :=\nbegin\n  intros hP hnP,\n  exact hnP hP,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  P \u2192 \u00ac\u00acP :=\n\u03bb hP hnP, hnP hP\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  P \u2192 \u00ac\u00acP :=\nbegin\n  apply modus_ponens,\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  P \u2192 \u00ac\u00acP :=\n-- by library_search\nnot_not.mpr\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 10. Demostrar que\n--    (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P)\n-- ----------------------------------------------------------------------\n\ntheorem modus_tollens :\n  (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  apply imp_trans,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 11. Demostrar que\n--    \u00ac\u00acP \u2192 P\n-- ----------------------------------------------------------------------\n\ntheorem double_negation_elimination :\n  \u00ac\u00acP \u2192 P :=\nbegin\n  intro hnnP,\n  by_contra h,\n  apply hnnP,\n  exact h,\nend\n\n-------------------------------------------------------\n-- \u00a7 Conjunci\u00f3n                                      --\n-------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 12. Demostrar que\n--    P, Q \u22a2 P \u2227 Q\n-- ----------------------------------------------------------------------\n\nexample\n  (hP : P)\n  (hQ : Q)\n  : P \u2227 Q :=\nbegin\n  split,\n  { exact hP, },\n  { exact hQ, }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 13. Demostrar que\n--    P \u2227 Q \u2192 P\n-- ----------------------------------------------------------------------\n\ntheorem and.elim_left :\n  P \u2227 Q \u2192 P :=\nbegin\n  intro hPaQ,\n  cases hPaQ with hP hQ,\n  exact hP,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 14. Demostrar que\n--    P \u2227 Q \u2192 Q\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\ntheorem and.elim_right :\n  P \u2227 Q \u2192 Q :=\nbegin\n  intro hPaQ,\n  exact hPaQ.2,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : P \u2227 Q \u2192 Q :=\n\u03bb hPaQ, hPaQ.2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 15. Demostrar que\n--    P \u2192 Q \u2192 P \u2227 Q\n-- ----------------------------------------------------------------------\n\n\ntheorem and.intro : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  intros hP hQ,\n  split,\n  { assumption },\n  { assumption }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 16. Demostrar que\n--    P \u2227 Q \u2192 (P \u2192 Q \u2192 R) \u2192 R\n-- ----------------------------------------------------------------------\n\ntheorem and.elim :\n  P \u2227 Q \u2192 (P \u2192 Q \u2192 R) \u2192 R :=\nbegin\n  rintro \u27e8hP, hQ\u27e9 hPQR,\n  exact hPQR hP hQ,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 17. Demostrar que\n--    (P \u2192 Q \u2192 R) \u2192 P \u2227 Q \u2192 R\n-- ----------------------------------------------------------------------\n\ntheorem and.rec :\n  (P \u2192 Q \u2192 R) \u2192 P \u2227 Q \u2192 R :=\nbegin\n  rintro hPQR \u27e8hP, hQ\u27e9,\n  exact hPQR hP hQ,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 18. Demostrar que\n--    P \u2227 Q \u2192 Q \u2227 P\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\ntheorem and.symm :\n  P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  rintro \u27e8hP, hQ\u27e9,\n  exact \u27e8hQ, hP\u27e9\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : P \u2227 Q \u2192 Q \u2227 P :=\n\u03bb \u27e8hP, hQ\u27e9, \u27e8hQ, hP\u27e9\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 19. Demostrar que\n--    (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R)\n-- ----------------------------------------------------------------------\n\ntheorem and.trans :\n  (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n  rintro \u27e8hP, hQ\u27e9 \u27e8hQ', hR\u27e9,\n  exact \u27e8hP, hR\u27e9,\nend\n\nlemma imp_imp_of_and_imp :\n  ((P \u2227 Q) \u2192 R) \u2192 (P \u2192 Q \u2192 R) :=\nbegin\n  intros h hP hQ,\n  exact h \u27e8hP, hQ\u27e9\nend\n\n-------------------------------------------------------\n-- \u00a7 Bicondicional (\u2194)                               --\n-------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 20. Demostrar que\n--    P \u2194 P\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\ntheorem iff.refl :\n  P \u2194 P :=\nbegin\n  split,\n  { apply id },\n  { apply id },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  P \u2194 P :=\nbegin\n  tauto!,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  P \u2194 P :=\nbegin\n  refl\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 21. Demostrar que\n--    (P \u2194 Q) \u2192 (Q \u2194 P)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\ntheorem iff.symm :\n  (P \u2194 Q) \u2192 (Q \u2194 P) :=\nbegin\n  intro h,\n  rw h,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (P \u2194 Q) \u2192 (Q \u2194 P) :=\n\u03bb \u27e8hPQ, hQP\u27e9, \u27e8hQP, hPQ\u27e9\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 22. Demostrar que\n--    (P \u2194 Q) \u2194 (Q \u2194 P)\n-- ----------------------------------------------------------------------\n\ntheorem iff.comm :\n  (P \u2194 Q) \u2194 (Q \u2194 P) :=\nbegin\n  split,\n  { apply iff.symm },\n  { apply iff.symm },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 23. Demostrar que\n--    (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R)\n-- ----------------------------------------------------------------------\n\ntheorem iff.trans :\n  (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intros hPQ hQR,\n  rw hPQ,\n  exact hQR,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 24. Demostrar que\n--    \u00ac(P \u2194 \u00acP)\n-- ----------------------------------------------------------------------\n\ntheorem iff.boss :\n  \u00ac(P \u2194 \u00acP) :=\nbegin\n  rintro \u27e8h1, h2\u27e9,\n  have hnP : \u00acP,\n  { intro hP,\n    exact h1 hP hP, },\n  have hP : P := h2 hnP,\n  exact hnP hP,\nend\n\n-------------------------------------------------------\n-- \u00a7 \u2194 y \u2227                                           --\n-------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 25. Demostrar que\n--    P \u2227 Q \u2194 Q \u2227 P\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\ntheorem and.comm :\n  P \u2227 Q \u2194 Q \u2227 P :=\nbegin\n  split;\n  apply and.symm,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  P \u2227 Q \u2194 Q \u2227 P :=\n\u27e8and.symm _ _, and.symm _ _\u27e9\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 26. Demostrar que\n--    ((P \u2227 Q) \u2227 R) \u2194 (P \u2227 (Q \u2227 R))\n-- ----------------------------------------------------------------------\n\ntheorem and_assoc :\n  ((P \u2227 Q) \u2227 R) \u2194 (P \u2227 (Q \u2227 R)) :=\nbegin\n  split,\n  { rintro \u27e8\u27e8hP, hQ\u27e9, hR\u27e9,\n    exact \u27e8hP, hQ, hR\u27e9 },\n  { rintro \u27e8hP, hQ, hR\u27e9,\n    exact \u27e8\u27e8hP, hQ\u27e9, hR\u27e9 },\nend\n\n-------------------------------------------------------\n-- \u00a7 Disyunci\u00f3n (\u2228)                                  --\n-------------------------------------------------------\n\nvariable (S : Prop)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 27. Demostrar que\n--    P \u2192 P \u2228 Q\n-- ----------------------------------------------------------------------\n\ntheorem or.intro_left :\n  P \u2192 P \u2228 Q :=\nbegin\n  intro P,\n  left,\n  assumption,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 28. Demostrar que\n--    Q \u2192 P \u2228 Q\n-- ----------------------------------------------------------------------\n\ntheorem or.intro_right :\n  Q \u2192 P \u2228 Q :=\nbegin\n  intro Q,\n  right,\n  assumption,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 29. Demostrar que\n--    P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R\n-- ----------------------------------------------------------------------\n\ntheorem or.elim :\n  P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  intros hPoQ hPR hQR,\n  cases hPoQ with hP hQ,\n  { exact hPR hP },\n  { exact hQR hQ },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 30. Demostrar que\n--    P \u2228 Q \u2192 Q \u2228 P\n-- ----------------------------------------------------------------------\n\ntheorem or.symm :\n  P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  intro hPoQ,\n  cases hPoQ with hP hQ,\n  { right, assumption },\n  { left, assumption }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 31. Demostrar que\n--    P \u2228 Q \u2194 Q \u2228 P\n-- ----------------------------------------------------------------------\n\ntheorem or.comm :\n  P \u2228 Q \u2194 Q \u2228 P :=\nbegin\n  split;\n  apply or.symm,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 32. Demostrar que\n--    (P \u2228 Q) \u2228 R \u2194 P \u2228 (Q \u2228 R)\n-- ----------------------------------------------------------------------\n\ntheorem or.assoc :\n  (P \u2228 Q) \u2228 R \u2194 P \u2228 (Q \u2228 R) :=\nbegin\n  split,\n  { rintro ((hP | hQ) | hR),\n    { left, assumption },\n    { right, left, assumption },\n    { right, right, assumption } },\n  { rintro (hP | hQ | hR),\n    { left, left, assumption },\n    { left, right, assumption },\n    { right, assumption } }\nend\n\n-------------------------------------------------------\n-- \u00a7 M\u00e1s sobre \u2192 y and                               --\n-------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 33. Demostrar que\n--    (P \u2192 R) \u2192 (Q \u2192 S) \u2192 P \u2228 Q \u2192 R \u2228 S\n-- ---------------------------------------------------------------------\n\ntheorem or.imp :\n  (P \u2192 R) \u2192 (Q \u2192 S) \u2192 P \u2228 Q \u2192 R \u2228 S :=\nbegin\n  rintro hPR hQS (hP | hQ),\n  { left, exact hPR hP },\n  { right, exact hQS hQ }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 34. Demostrar que\n--    (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R\n-- ----------------------------------------------------------------------\n\ntheorem or.imp_left :\n  (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R :=\nbegin\n  rintro hPQ (hP | hR),\n  { left, exact hPQ hP },\n  { right, assumption },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 35. Demostrar que\n--    (P \u2192 Q) \u2192 R \u2228 P \u2192 R \u2228 Q\n-- ----------------------------------------------------------------------\n\ntheorem or.imp_right :\n  (P \u2192 Q) \u2192 R \u2228 P \u2192 R \u2228 Q :=\nbegin\n  rw or.comm R,\n  rw or.comm R,\n  apply or.imp_left,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 36. Demostrar que\n--    P \u2228 Q \u2228 R \u2194 Q \u2228 P \u2228 R\n-- ----------------------------------------------------------------------\n\ntheorem or.left_comm :\n  P \u2228 Q \u2228 R \u2194 Q \u2228 P \u2228 R :=\nbegin\n  rw [or.comm P, or.assoc, or.comm R],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 37. Demostrar que\n--    (P \u2192 R) \u2192 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n-- ----------------------------------------------------------------------\n\ntheorem or.rec :\n  (P \u2192 R) \u2192 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R :=\nbegin\n  intros hPR hQR hPoQ,\n  exact or.elim _ _ _ hPoQ hPR hQR,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 38. Demostrar que\n--    (P \u2194 R) \u2192 (Q \u2194 S) \u2192 (P \u2228 Q \u2194 R \u2228 S)\n-- ----------------------------------------------------------------------\n\ntheorem or_congr :\n  (P \u2194 R) \u2192 (Q \u2194 S) \u2192 (P \u2228 Q \u2194 R \u2228 S) :=\nbegin\n  rintro hPR hQS,\n  rw [hPR, hQS],\nend\n\n-------------------------------------------------------\n-- \u00a7 true y false                                    --\n-------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 39. Demostrar que\n--    false \u2192 P\n-- ----------------------------------------------------------------------\n\ntheorem false.elim :\n  false \u2192 P :=\nbegin\n  intro h,\n  cases h,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 40. Demostrar que\n--    P \u2227 true \u2194 P\n-- ----------------------------------------------------------------------\n\ntheorem and_true_iff :\n  P \u2227 true \u2194 P :=\nbegin\n  split,\n  { rintro \u27e8hP, -\u27e9,\n    exact hP },\n  { intro hP,\n    split,\n    { exact hP },\n    { trivial } }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 41. Demostrar que\n--    P \u2228 false \u2194 P\n-- ----------------------------------------------------------------------\n\ntheorem or_false_iff :\n  P \u2228 false \u2194 P :=\nbegin\n  split,\n  { rintro (hP | h),\n    { assumption },\n    { cases h} },\n  { intro hP,\n    left,\n    exact hP }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 42. Demostrar que\n--    P \u2228 Q \u2192 \u00acP \u2192 Q\n-- ----------------------------------------------------------------------\n\ntheorem or.resolve_left :\n  P \u2228 Q \u2192 \u00acP \u2192 Q :=\nbegin\n  rintro (hP | hQ) hnP,\n  { apply false.elim,\n    exact hnP hP },\n  { exact hQ },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 43. Demostrar que\n--    P \u2228 Q \u2194 \u00acP \u2192 Q\n-- ----------------------------------------------------------------------\n\ntheorem or_iff_not_imp_left :\n  P \u2228 Q \u2194 \u00acP \u2192 Q :=\nbegin\n  split,\n  { apply or.resolve_left },\n  { intro hnPQ,\n    by_cases h : P,\n    { left, assumption },\n    { right, exact hnPQ h} }\nend\n\nend oculto\n\n-- =====================================================================\n-- \u00a7 Referencias                                                      --\n-- =====================================================================\n\n-- + Kevin Buzzard. \"Formalising mathematics : workshop 1 \u2014 logic, sets,\n--   functions, relations\" https://bit.ly/3kJo231\n-- + Kevin Buzzard. formalising-mathematics: Part_A_logic.lean\n--   https://bit.ly/3m5n9kA\n-- + Kevin Buzzard. formalising-mathematics: Part_A_logic_solutions.lean\n--   https://bit.ly/3oaLwjv\n", "meta": {"author": "jaalonso", "repo": "Formalizacion_de_las_matematicas_en_Lean", "sha": "52bf9748d17a22d819cac19502fca9bc7340f7ae", "save_path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean/Formalizacion_de_las_matematicas_en_Lean-52bf9748d17a22d819cac19502fca9bc7340f7ae/src/1_Basica/1_Logica.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7340778477377609}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura\n\nShow that tail recursive fib is equal to standard one.\n-/\nimport data.nat\nopen nat\n\ndefinition fib : nat \u2192 nat\n| 0     := 1\n| 1     := 1\n| (n+2) := fib (n+1) + fib n\n\nprivate definition fib_fast_aux : nat \u2192 nat \u2192 nat \u2192 nat\n| 0     i j := j\n| (n+1) i j := fib_fast_aux n j (j+i)\n\nlemma fib_fast_aux_lemma : \u2200 n m, fib_fast_aux n (fib m) (fib (succ m)) = fib (succ (n + m))\n| 0        m := by rewrite zero_add\n| (succ n) m :=\n  begin\n    have ih : fib_fast_aux n (fib (succ m)) (fib (succ (succ m))) = fib (succ (n + succ m)), from fib_fast_aux_lemma n (succ m),\n    have h\u2081 : fib (succ m) + fib m = fib (succ (succ m)), from rfl,\n    unfold fib_fast_aux, rewrite [h\u2081, ih, succ_add, add_succ]\n  end\n\ndefinition fib_fast (n: nat) :=\nfib_fast_aux n 0 1\n\nlemma fib_fast_eq_fib : \u2200 n, fib_fast n = fib n\n| 0        := rfl\n| (succ n) :=\n  begin\n    have h\u2081 : fib_fast_aux n (fib 0) (fib 1) = fib (succ n), from !fib_fast_aux_lemma,\n    unfold fib_fast, unfold fib_fast_aux, krewrite h\u2081\n  end\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/nat/examples/fib2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7340778458252292}}
{"text": "import data.set.lattice\nimport data.set.function\nimport analysis.special_functions.log.basic\n\n\n\nsection\nvariables {\u03b1 \u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables s t : set \u03b1\nvariables u v : set \u03b2\nopen function\nopen set\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nby { ext, refl }\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y, split,\n  { rintros \u27e8x, xs | xt, rfl\u27e9,\n    { left, use [x, xs],},\n    { right, use [x, xt]},},\n  { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9),\n    { use [x, or.inl xs]},\n    { use [x, or.inr xt]}},\nend\n\nexample : f '' s \u2286 v \u2194 s \u2286 f \u207b\u00b9' v :=\nbegin \n  split,\n  { rintros fsv x xs,\n    apply fsv,\n    use [x, xs, rfl],},\n  { rintros sfv y \u27e8x, xs, rfl\u27e9,\n    apply sfv,\n    from xs,},\nend\n\n#check image_subset_iff\n\nexample (h : injective f) : f \u207b\u00b9' (f '' s) \u2286 s :=\nbegin \n  rintros y \u27e8x, \u27e8xs, heq\u27e9\u27e9,\n  rw h heq at xs,\n  from xs,\nend \n\n#check injective f \n#check surjective f\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin \n  refine image_subset_iff.mpr _,\n  apply subset.refl,\nend\n\nexample (h : surjective f) : u \u2286 f '' (f\u207b\u00b9' u) :=\nbegin \n  rintros y yu,\n  rcases h y with \u27e8x, rfl\u27e9,\n  use x,\n  split,\n  from yu,\n  refl,\nend\n\nexample (h : s \u2286 t) : f '' s \u2286 f '' t :=\nbegin \n  rintros y \u27e8x, \u27e8xs, fxeq\u27e9\u27e9,\n  use [x, h xs, fxeq],\nend\n\nexample (h : u \u2286 v) : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nbegin \n  intros x xu,\n  apply h,\n  from xu,\nend\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin \n  ext x,\n  split,\n  { rintro (fu | fv),\n    left, from fu,\n    right, from fv,},\n  { rintro (fu | fv),\n    left, from fu,\n    right, from fv,}\nend\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nbegin \n  rintros y \u27e8x, \u27e8\u27e8xs, xt\u27e9, fxeq\u27e9\u27e9,\n  split,\n  { use [x, xs, fxeq]},\n  { use [x, xt, fxeq]},\nend\n\nexample (h : injective f) : f '' s \u2229 f '' t \u2286 f '' (s \u2229 t) :=\nbegin \n  rintros y \u27e8\u27e8x, \u27e8xs, fxeq\u27e9\u27e9, \u27e8z, \u27e8zt, fzeq\u27e9\u27e9\u27e9,\n  use x,\n  split,\n  { split, from xs,\n    have : x = z,\n      apply h,\n      apply eq.trans fxeq fzeq.symm,\n    rwa this.symm at zt,},\n  { from fxeq,},\n    \nend\n\nexample : f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nbegin \n  rintros y \u27e8fs, fnt\u27e9,\n  rcases fs with \u27e8x, \u27e8xs, fxeq\u27e9\u27e9,\n  use x,\n  split,\n  { split,\n    from xs,\n    contrapose! fnt,\n    use [x, fnt, fxeq],},\n  { from fxeq,},\nend\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nbegin \n  rintros x \u27e8xu, xnv\u27e9,\n  split; assumption,\nend\n\nexample : f '' s \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin \n  ext y,\n  split,\n  { rintros \u27e8\u27e8x, \u27e8xs, fxeq\u27e9\u27e9, yv\u27e9,\n    use x,\n    split,\n    { split,\n      from xs,\n      rwa fxeq.symm at yv,},\n    { from fxeq,}},\n  { rintros \u27e8x, \u27e8\u27e8xs, yv\u27e9, fxeq\u27e9\u27e9,\n    use x,\n    from \u27e8xs, fxeq\u27e9,\n    rwa fxeq.symm,}\nend\n\nexample : f '' (s \u2229 f \u207b\u00b9' u) \u2286 f '' s \u222a u :=\nbegin \n  rintros y \u27e8x, \u27e8xs, yu\u27e9, fxeq\u27e9,\n  left,\n  use [x, xs, fxeq],\nend\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\nbegin \n  rintros x \u27e8xs, fxu\u27e9,\n  split,\n  { use [x, xs, rfl],},\n  { from fxu,}\nend\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin \n  rintros x (xs | fxu),\n  { left,\n    use [x, xs, rfl],},\n  { right,\n    use fxu,} \nend\n\n\nvariables {I : Type*} (A : I \u2192 set \u03b1) (B : I \u2192 set \u03b2)\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y, simp,\n  split,\n  { rintros \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9,\n    use [i, x, xAi, fxeq],},\n  { rintros \u27e8i, x, \u27e8xAi, fxeq\u27e9\u27e9,\n    use [x, i, xAi, fxeq],},\nend\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nbegin\n  intro y, simp,\n  intros x h fxeq i,\n  use [x, h i, fxeq],\nend\n\nexample (i : I) (injf : injective f) :\n  (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i) :=\nbegin\n  intro y, simp,\n  intro h,\n  rcases h i with \u27e8x, \u27e8xAi, fxeq\u27e9\u27e9,\n  use x, split,\n  { intro i',\n    rcases h i' with \u27e8x', x'Ai, fx'eq\u27e9,\n    have : f x = f x', by rw [fxeq, fx'eq],\n    have : x = x', from injf this,\n    rwa this,},\n  { from fxeq,},\nend\n\nend\n\n\nsection \nopen set real\n\nexample : inj_on log { x | x > 0 } :=\nbegin\n  intros x xpos y ypos e,\n  calc \n    x = exp (log x) : by rw exp_log xpos\n    ... = exp (log y) : by rw e\n    ... = y : by rw exp_log ypos,\nend\n\nexample : range exp = { y | y > 0 } :=\nbegin\n  ext y, split,\n  { rintros \u27e8x, rfl\u27e9,\n    apply exp_pos,},\n  { intro ypos,\n    use log y,\n    apply exp_log ypos,}\nend\n\n\nexample : inj_on sqrt { x | x \u2265 0 } :=\nbegin \n  intros x xge y yge e,\n  calc \n    x = (sqrt x) ^ 2 : by rw sq_sqrt xge\n    ... = (sqrt y) ^ 2 : by rw e\n    ... = y : by rw sq_sqrt yge,\nend\n\n#check sqrt_sq\n\nexample : inj_on (\u03bb x, x^2) { x : \u211d | x \u2265 0 } :=\nbegin \n  intros x xge y yge,\n  dsimp, intro e,\n  calc \n    x = sqrt (x ^ 2) : by rw sqrt_sq xge\n    ... = sqrt (y ^ 2) : by rw e\n    ... = y : by rw sqrt_sq yge,\nend\n\nexample : sqrt '' { x | x \u2265 0 } = {y | y \u2265 0} :=\nbegin \n  ext y, dsimp, split,\n  { rintro \u27e8x, xge, fxeq\u27e9,\n    rw \u2190fxeq,\n    apply sqrt_nonneg,},\n  { intro yge,\n    use y^2,\n    dsimp,\n    split,\n    apply sq_nonneg,\n    rw sqrt_sq yge,}\nend\n\nexample : range (\u03bb x, x^2) = {y : \u211d  | y \u2265 0} :=\nbegin \n  ext y, split,\n  { rintro \u27e8x, fxeq\u27e9,\n    dsimp at fxeq,\n    dsimp, rw \u2190fxeq,\n    apply sq_nonneg,},\n  { dsimp, intro yge,\n    use sqrt y,\n    dsimp,\n    rw sq_sqrt yge,},\nend\n\n\nend\n\n\n\n\nsection \nvariables {\u03b1 \u03b2 : Type*} [inhabited \u03b1]\n\n#check (default : \u03b1)\n\nvariables (P : \u03b1 \u2192 Prop) (h : \u2203 x, P x)\n\n#check classical.some h\n\nexample : P (classical.some h) := classical.some_spec h\n\n\nnoncomputable theory\nopen_locale classical\n\ndef inverse (f : \u03b1 \u2192 \u03b2) : \u03b2 \u2192 \u03b1 :=\n\u03bb y : \u03b2, if h : \u2203 x, f x = y then classical.some h else default\n\ntheorem inverse_spec {f : \u03b1 \u2192 \u03b2} (y : \u03b2) (h : \u2203 x, f x = y) :\n  f (inverse f y) = y :=\nbegin\n  rw inverse, dsimp, rw dif_pos h,\n  exact classical.some_spec h\nend\n\n\nvariable  f : \u03b1 \u2192 \u03b2\nopen function\n\nexample : injective f \u2194 left_inverse (inverse f) f  :=\nbegin \n  split,\n  { intros injf x,\n    apply injf,\n    apply inverse_spec,\n    use x,},\n  { intros lfi x y e,\n    calc \n      x = inverse f (f x) : by rw lfi\n      ... = inverse f (f y) : by rw e\n      ... = y : by rw lfi,},\nend\n\nexample : surjective f \u2194 right_inverse (inverse f) f :=\nbegin \n  split,\n  { intros surf y,\n    apply inverse_spec,\n    use surf y,},\n  { rintros rfi y,\n    use (inverse f) y,\n    from rfi y,}\nend\n\ntheorem Cantor : \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f :=\nbegin\n  intros f surf,\n  let S := { i | i \u2209 f i},\n  rcases surf S with \u27e8j, h\u27e9,\n  have h\u2081 : j \u2209 f j,\n    intro h',\n    have : j \u2209 f j,\n      by rwa h at h',\n    contradiction,\n  have h\u2082 : j \u2208 S,\n    from h\u2081,\n  have h\u2083 : j \u2209 S,\n    rwa h at h\u2081,\n  contradiction,\nend\n\nend\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/04_Sets_and_Functions/02_Functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7340778382127184}}
{"text": "/- Yair Gueta : 208624908 : t3\n    Exercise 3\n-/\nimport data.nat.basic\nimport data.real.basic\n\nvariables (\u03b1 : Type*) (p q : \u03b1 \u2192 Prop)\n\n---- Q1 ----\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := \niff.intro\n    (assume h :\u2200 x, p x \u2227 q x,\n        have h\u2081 : \u2200 x, p x, from \n            assume y,\n            show p y, from (h y).left,\n        have \u2200 x, q x, from\n            assume k,\n            show q k, from (h k).right,\n        \u27e8h\u2081, this\u27e9)\n    (assume h : (\u2200 x, p x) \u2227 (\u2200 x, q x),\n        assume z,\n            \u27e8h.left z, h.right z\u27e9)\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := \nassume h\u2081 : \u2200 x, p x \u2192 q x,\nassume h\u2082 : \u2200 x, p x,\nassume y,\n    have hpq : p y \u2192 q y, from h\u2081 y,\n    hpq (h\u2082 y)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := \nassume h : (\u2200 x, p x) \u2228 (\u2200 x, q x),\nassume x,\n    h.elim\n        (assume : (\u2200 x, p x),\n            or.inl (this x))\n        (assume : (\u2200 x, q x),\n            or.inr (this x))\n\n\n---- Q2 ----\nopen classical\nvariable r : Prop\n\nexample : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) := \nassume y: \u03b1,\niff.intro\n    (assume : (\u2200 x : \u03b1, r), this y)\n    (assume hr : r, \n        assume y : \u03b1, hr)\n\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r := \niff.intro\n    (assume h : \u2200 x, p x \u2228 r,\n     by_cases\n     (assume hr : r, \n        show (\u2200 x, p x) \u2228 r, from or.inr hr)\n     (assume hnr : \u00acr, \n        suffices (\u2200 x, p x), from or.inl this,\n        assume y, (h y).elim (assume hpy : p y, hpy)(assume hr:r, absurd hr hnr)\n        ))\n    (assume h : (\u2200 x, p x) \u2228 r,\n        h.elim\n        (assume ah : \u2200 x, p x,\n         assume y, or.inl (ah y))\n        (assume hr : r, \n         assume y, or.inr hr))\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) := \niff.intro\n  (assume h : \u2200 x, r \u2192 p x,\n   assume hr : r, assume y, (h y) hr)\n  (assume h : r \u2192 \u2200 x, p x, assume y, assume hr : r, h hr y)\n\n\n---- Q3 ----\nvariables (men : Type*) (barber : men)\nvariable  (shaves : men \u2192 men \u2192 Prop)\n\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) :\n  false := \n  have hb : shaves barber barber \u2194 \u00ac shaves barber barber, from h barber,\n  by_cases\n    (assume hsb : shaves barber barber, hb.elim_left hsb hsb)\n    (assume hnsb : \u00ac shaves barber barber, hnsb (hb.elim_right hnsb))\n\n---- Q4 ----\nnamespace Q4\n    def even (n : \u2115) : Prop := 2 \u2223 n\n\n    def prime (n : \u2115) : Prop := \u2200 (m : \u2115), (m > 1) \u2192 (m < n) \u2192 \u00ac \u2203(l : \u2115), m*l = n \n\n    def infinitely_many_primes : Prop := \u2200 (n : \u2115), \u2203 (p : \u2115), p > n \u2192 prime p\n\n    def Fermat_prime (n : \u2115) : Prop := \u2203 (m : \u2115), prime n \u2194 (n = 2^(2^m)+1)\n\n    def infinitely_many_Fermat_primes : Prop := \u2200 (n : \u2115), \u2203 (p : \u2115), p > n \u2192 Fermat_prime p\n\n    def goldbach_conjecture : Prop := \n        \u2200 (n : \u2115), (even n) \u2192 (n > 2) \u2192 (\u2203 (m l : \u2115 ), prime m \u2192 prime l \u2192 m+l=n)\n\n    def Goldbach's_weak_conjecture : Prop := \n        \u2200 (n : \u2115), (even n) \u2192 (n > 5) \u2192 (\u2203 (m\u2081 m\u2082 m\u2083 : \u2115 ), \n            prime m\u2081 \u2192 prime m\u2082 \u2192 prime m\u2083 \u2192 m\u2081+m\u2082+m\u2083=n)\n\n    def Fermat's_last_theorem : Prop := \u2200 (n : \u2115), n > 2 \u2192 \u00ac (\u2203 (x y z : \u2115), x^n+y^n=z^n)\nend Q4\n\n\n---- Q6 ----\nvariables log exp     : real \u2192 real\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\n    by rw [\u2190log_exp_eq(log x + log y),exp_add,exp_log_eq hx,exp_log_eq hy]\n\n    \n", "meta": {"author": "yairgueta", "repo": "Lean", "sha": "af8a4fa24f76edfdd0dd33f013db194e611e6a86", "save_path": "github-repos/lean/yairgueta-Lean", "path": "github-repos/lean/yairgueta-Lean/Lean-af8a4fa24f76edfdd0dd33f013db194e611e6a86/src/t3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7340778366147266}}
{"text": "-- Chapter 5 Tactics\n\n\n#print \"==================================\"\n#print \"Section 5.1\"\n#print \" \"\n\n/- In this chapter, we describe an alternative approach to constructing proofs, using tactics. \n   A proof term is a representation of a mathematical proof; tactics are commands, or \n   instructions, that describe how to build such a proof. Informally, we might begin a \n   mathematical proof by saying \"to prove the forward direction, unfold the definition, apply \n   the previous lemma, and simplify.\" Just as these are instructions that tell the reader how \n   to find the relevant proof, tactics are instructions that tell Lean how to construct a proof \n   term. They naturally support an incremental style of writing proofs, in which users decompose\n   a proof and work on goals one step at a time. -/\n\n/- We will describe proofs that consist of sequences of tactics as \"tactic-style\" proofs, \n   to contrast with the ways of writing proof terms we have seen so far, which we will call \n   \"term-style\" proofs. Each style has its own advantages and disadvantages. For example, \n   tactic-style proofs can be harder to read, because they require the reader to predict or \n   guess the results of each instruction. But they can also be shorter and easier to write. \n   Moreover, tactics offer a gateway to using Lean's automation, since automated procedures \n   are themselves tactics. -/\n\n\n#print \"===================================\"\n#print \"Section 5.1. Entering Tactic Mode\"\n#print \" \"\n\nnamespace Sec_5_1\n  theorem test (p q : Prop) (hp : p) (hq : q) : p \u2227 q \u2227 p := \n  begin\n    apply and.intro, exact hp, \n    apply and.intro, exact hq, exact hp\n  end \n\n  -- You can see the resulting proof term with the #print command:\n  #print test\n\n  /- You can write a tactic script incrementally. If you run Lean on an incomplete tactic \n     proof bracketed by begin and end, the system reports all the unsolved goals that remain. \n     If you are running Lean with its Emacs interface, you can see this information by putting \n     your cursor on the end symbol, which should be underlined. In the Emacs interface, there \n     is another extremely useful trick: if you put your cursor on a line of a tactic proof and \n     press `C-c C-g`, Lean will show you the goal that remains at the end of the line. -/\n\nend Sec_5_1\n\n#print \"===================================\"\n#print \"Section 5.2. Basic Tactics\"\n#print \" \"\n\n/- In addition to `apply` and `exact`, another useful tactic is `intro`, which \n   introduces a hypothesis. Here's an example of an identity from propositional \n   logic that we proved Section 3.6, now proved using tactics. -/\n\nnamespace Sec_5_2\n\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    apply iff.intro,\n      intro h,\n      apply or.elim (and.right h),\n        intro hq,\n        apply or.inl,\n        apply and.intro (and.left h) hq,\n        intro hr,\n        apply or.inr,\n        apply and.intro (and.left h) hr,\n      intro h,\n      apply or.elim h,\n        intro hpq,\n        apply and.intro hpq.left (or.inl hpq.right),\n      intro hpr,\n      apply and.intro hpr.left (or.inr hpr.right)\n  end \n\n\n  -- The intro command can more generally be used to introduce a variable of any type:\n\n  example (\u03b1 : Type) : \u03b1 \u2192 \u03b1 :=\n  begin\n    intro a, exact a\n  end\n\n  example (\u03b1 : Type) : \u2200 x : \u03b1, x = x :=\n  begin\n    intro x, exact eq.refl x\n  end\n\n  -- `intro` has a plural form, `intros`, that takes a list of names. \n\n  example : \u2200 a b c : \u2115, a = b \u2192 a = c \u2192 b = c :=\n  begin\n    intros a b c h\u2081 h\u2082,\n    exact eq.trans (eq.symm h\u2081) h\u2082\n  end\n    \n  /- The `assumption` tactic looks through the assumptions in context of the current goal, \n     and if there is one matching the conclusion, it applies it. -/\n\n  variable \u03b1 : Type\n  variables x y z w : \u03b1\n\n  example (h\u2081 : x = y) (h\u2082 : y = z) (h\u2083 : z = w) : x = w :=\n  begin\n    apply eq.trans h\u2081,\n    apply eq.trans h\u2082,\n    assumption\n  end\n\n  -- The `assumption` tactic will unify metavariables in the conclusion if necessary:\n\n  example (h\u2081 : x = y) (h\u2082 : y = z) (h\u2083 : z = w) : x = w :=\n  begin\n    apply eq.trans, assumption,\n    apply eq.trans, assumption,\n    assumption\n  end\n\n  -- We could use `intros` to introduce the variables and hypotheses automatically:\n\n  example : \u2200 a b c : \u2115, a = b \u2192 a = c \u2192 b = c :=\n  begin\n    intros,\n    apply eq.trans,\n    apply eq.symm,\n    assumption,\n    assumption\n  end\n\n  /- `reflexivity`, `symmetry`, `transitivity`\n     Using reflexivity, for example, is more general than `apply eq.refl`, \n     because it works for any relation that has been tagged with the `refl` attribute. \n     (Attributes will be discussed in Section 6.4.) \n     `reflexivity` is abbreviated `refl`. -/\n\n  example  (y : \u2115) : (\u03bb x : \u2115, 0) y = 0 := begin refl end\n\n  example (x : \u2115) : x \u2264 x := begin refl end\n\n  example : \u2200 a b c : \u2115, a = b \u2192 a = c \u2192 b = c :=\n  begin\n    intros, transitivity, symmetry, assumption, assumption\n  end\n\n  -- Instead of typing `assumption` twice, we can use the `repeat` combinator:\n  example : \u2200 a b c : \u2115, a = b \u2192 a = c \u2192 b = c :=\n  begin\n    intros, transitivity, symmetry, repeat { assumption }\n  end\n\n  -- the curly braces introduce a new tactic block; equivalent to a nested `begin ... end` pair.\n\n  -- A variant of `apply` called `fapply` is more aggressive in creating new subgoals for args.\n  example : \u2203 a : \u2115,  a = a :=\n  begin\n    fapply exists.intro, -- Creates two goals:  (1) provide a natural number a, \n    exact 0,             --                     (2) prove the nat you provided satisfies a = a. \n    apply rfl            -- Goal (2) depends on (1); solving the first goal instantiates a \n  end                    -- metavariable in the second.\n\n  -- The `revert` tactic is sort of inverse to `intro`, as this silly example illustrates.\n  example (x : \u2115) : x = x :=  \n  begin           -- goal is now `x : \u2115 \u22a2 x = x`\n     revert x,    -- goal is now `\u2200 (x : \u2115), x = x`\n     intro y,     -- goal is now `y : \u2115 \u22a2 y = y`\n     reflexivity \n   end\n  -- This example is silly because we can simply use `reflexivity` from the start:\n  example (x : \u2115) : x = x :=  begin reflexivity end\n\n  -- `revert` can move a hypothesis into the goal, yielding an implication. \n  -- Here's another silly example:\n  example (x y : \u2115) (h : x = y) : y = x :=\n  begin       -- goal: `x y : \u2115, h : x = y \u22a2 y = x`\n    revert h, -- goal: `x y : \u2115 \u22a2 x = y \u2192 y = x`\n    intro h\u2081, -- goal: `x y : \u2115, h\u2081 : x = y \u22a2 y = x`\n    symmetry, -- goal: `x y : \u2115, h\u2081 : x = y \u22a2 x = y`\n    exact h\u2081  -- (or we could use `assumption`)\n  end \n\n  /- But revert is clever in that it reverts not only an element of the context, but \n     also all subsequent elements of the context that depend on it. \n     You can also revert multiple elements of the context at once:   -/\n\n  example (x y : \u2115) (h : x = y) : y = x :=\n  begin         -- goal: `x y : \u2115, h : x = y \u22a2 y = x`\n    revert x y, -- goal: `\u22a2 \u2200 (x y : \u2115), x = y \u2192 y = x`\n    intros,     -- goal: `x y : \u2115, h : x = y \u22a2 y = x`\n    symmetry,   -- goal: `x y : \u2115, h\u2081 : x = y \u22a2 x = y`\n    exact h\n  end\n\n  /- You can only `revert` an element of the local context; that is, a local variable \n     or hypothesis. But you can replace an arbitrary expression in the goal by a \n     fresh variable using the `generalize` tactic. -/\n  example : 3 = 3 :=\n  begin                      -- goal:   `\u22a2 3 = 3`\n    generalize : 3 = x,      -- goal:   `x : \u2115 \u22a2 x = x`\n    revert x,                -- goal:   `\u22a2 \u2200 (x : \u2115), x = x\n    intro y,                 -- goal:   `y : \u2115 \u22a2 y = y\n    reflexivity\n  end \nend Sec_5_2\n\n\n#print \"===================================\"\n#print \"Section 5.3. More Tactics\"\n#print \" \"\n\nnamespace Sec_5_3\n  /- Some additional tactics are useful for constructing and destructing propositions and data.\n     E.g., when applied to the goal p \u2228 q, the tactics `left` and `right` are equivalent to \n     `apply or.inl` and `apply or.inr`, respectively. \n     Conversely, the `cases` tactic can be used to decompose a disjunction. -/\n\n  example (p q : Prop) : p \u2228 q \u2192 q \u2228 p :=\n  begin\n    intro h,             -- goal:  p q : Prop, h : p \u2228 q \u22a2 q \u2228 p\n    cases h with hp hq,  -- two goals:  p q : Prop, hp : p \u22a2 q \u2228 p  (and sim for q \u22a2 q \u2228 p)\n    -- case hp : p\n    right, exact hp,\n    -- case hq : q\n    left, exact hq\n  end     \n\n\n  -- `cases` can also be used to decompose a conjunction.\n  example (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\n  begin\n    intro h,\n    cases h with hp hq,\n    constructor, exact hq, exact hp -- could have used: `apply and.intro hq hp`\n  end\n\n  -- Here's a demo of these tactics using an example from earlier.\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    apply iff.intro,\n    intro h,\n      cases h with hp hqr,\n      cases hqr with hq hr,\n        left, constructor, exact hp, exact hq,\n        right, constructor, exact hp, exact hr,\n    intro h,\n      cases h with hpq hpr,\n      cases hpq with hp hq,\n        constructor, exact hp, left, exact hq,\n      cases hpr with hp hr,\n      constructor, exact hp, right, exact hr\n  end\n\n  /- `cases` decomposes any element of an inductively defined type; \n    `constructor` applies the first constructor of an inductively defined type;\n     `left` and `right` are used with inductively defined types with exactly two constructors. \n  -/   \n\n  -- We can use `cases` and `constructor` with an existential quantifier.\n  example (p q : \u2115 \u2192 Prop) : (\u2203 x, p x) \u2192 \u2203 x, p x \u2228 q x :=\n  begin\n    intro h,\n    cases h with x px,\n    constructor, left, exact px\n  end\n  /- Here, `constructor` leaves the first component of the existential assertion (i.e., `x`) \n     implicit. It is represented by a metavariable, which we must instantiate. The instantiated\n     value is determined by the tactic `exact px`, since `px` has type `p x`. -/\n\n  /- To specify a witness to the exists quantifier explicitly, use the `existsi` tactic: -/\n  example (p q : \u2115 \u2192 Prop) : (\u2203 x, p x) \u2192 \u2203 x, p x \u2228 q x :=\n  begin\n    intro h,\n    cases h with x px,\n    existsi x, left, exact px\n  end\n\n  -- Another example:\n  example (p q : \u2115 \u2192 Prop) : (\u2203 x, p x \u2227 q x) \u2192 (\u2203 x, q x \u2227 p x) :=\n  begin\n    intro h,\n    cases h with x hpq,\n    cases hpq with hpx hqx,\n    existsi x,\n    split; assumption  -- `;` tells Lean to apply `assumption` to both goals of the conj\n  end\n  \n  /- These tactics can be used on data just as well as propositions. -/\n\n  -- Here they're used to define functions that swap components of product and sum types:\n  universes u v\n  def swap_pair {\u03b1 : Type u} {\u03b2 : Type v} : \u03b1 \u00d7 \u03b2 \u2192 \u03b2 \u00d7 \u03b1 :=\n  begin\n    intro h,\n    cases h with ha hb,\n    constructor; assumption\n  end\n\n  def swap_sum {\u03b1 : Type u} {\u03b2 : Type v} : \u03b1 \u2295 \u03b2 \u2192 \u03b2 \u2295 \u03b1 :=\n  begin\n    intro h,\n    cases h with ha hb,\n    right, exact ha, left, exact hb\n  end\n\n  -- `cases` will do case distinctions on a natural number:\n  open nat\n  example (P : \u2115 \u2192 Prop) (h\u2080 : P 0) (h\u2081 : \u2200 n, P (succ n)) (m : \u2115) : P m :=\n  begin\n    cases m with m', exact h\u2080, exact h\u2081 m'\n  end\n\n  -- `contradiction` searches for a contradiction among the current hypotheses:\n  example (p q : Prop) : p \u2227 \u00ac p \u2192 q :=\n  begin\n    intro h,\n    cases h with hp hnp,\n    contradiction\n  end\n\n\nend Sec_5_3\n\n\n#print \"===================================\"\n#print \"Section 5.4. Structuring Tactic Proofs\"\n#print \" \"\n\nnamespace Sec_5_4\n  /- it is possible to mix term-style and tactic-style proofs, and pass between the two freely. \n     `apply` and `exact` expect arbitrary terms, e.g., using `have`, `show`, etc.\n     Conversely, arbitrary terms can use tactic mode by inserting `begin...end`.-/\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    intro h,\n    exact\n      have hp : p, from h.left,\n      have hqr : q \u2228 r, from h.right,\n      show p \u2227 q \u2228 p \u2227 r,\n      begin\n        cases hqr with hq hr,\n        left, split; assumption,   -- alternatively `exact or.inl \u27e8hp, hq\u27e9`\n        right, split; assumption   -- alternatively `exact or.inr \u27e8hp, hr\u27e9` \n      end\n  end\n  -- Here's a more natural example.\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    apply iff.intro,\n      intro h,\n      cases h.right with hq hr,\n        exact or.inl \u27e8h.left, hq\u27e9,\n        exact or.inr \u27e8h.left, hr\u27e9,\n      intro h,\n      cases h with hpq hpr,\n        exact \u27e8hpq.left, or.inl hpq.right\u27e9,\n        exact \u27e8hpr.left, or.inr hpr.right\u27e9\n  end\n \n  /- There is also a `show` tactic, which is analogous to the `show` keyword in a proof term. \n     The `show` tactic declares the type of the goal that is about to be solved, while \n     remaining in tactic mode. And, in tactic mode `from` is an alternative name for `exact`.  -/\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    apply iff.intro,\n      intro h,\n      cases h.right with hq hr,\n        show p \u2227 q \u2228 p \u2227 r,\n          from or.inl \u27e8h.left, hq\u27e9,  -- alternatively, { left, split, exact h.left, assumption },\n        show p \u2227 q \u2228 p \u2227 r,\n          from or.inr \u27e8h.left, hr\u27e9,\n      intro h,\n      cases h with hpq hpr,\n        show p \u2227 (q \u2228 r),\n          from \u27e8hpq.left, or.inl hpq.right\u27e9, \n        show p \u2227 (q \u2228 r),\n          from \u27e8hpr.left, or.inr hpr.right\u27e9\n  end\n\n  -- `show` can be used to rewrite a goal to something definitionally equivalent.\n  example (n : \u2115) : n+1 = nat.succ n := -- could just do `begin reflexivity end`\n  begin\n    show nat.succ n = nat.succ n, reflexivity\n  end\n\n  /- When there are multiple goals, `show` can be used to select which goal to work on.\n     Thus, both of these proofs work:    -/\n  example (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\n  begin\n    intro h, cases h with hp hq, split,\n    show q, from hq,\n    show p, from hp\n  end\n  example (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\n  begin\n    intro h, cases h with hp hq, split,\n    show p, from hp,\n    show q, from hq\n  end\n\n  -- the `have` tactic introduces a new subgoal, just as when writing proof terms:  \n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    intro h,\n    cases h with hp hqr,\n    show (p \u2227 q) \u2228 (p \u2227 r),\n    cases hqr with hq hr,\n      have hpq : p \u2227 q, from and.intro hp hq, left, exact hpq,\n      have hpr : p \u2227 r, from and.intro hp hr, right, exact hpr\n  end\n  \n  \n  -- With both `show` and `have` you can omit `from` and stay in tactic mode;\n  -- you can also omit the hypothesis label and refer to the given term as `this`.\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    intro h,\n    cases h with hp hqr,\n    show (p \u2227 q) \u2228 (p \u2227 r),\n    cases hqr with hq hr,\n      have : p \u2227 q,              -- no label for `p \u2227 q`\n        exact \u27e8hp, hq\u27e9,\n      exact or.inl this,  -- refer to `p \u2227 q` as `this`\n      have : p \u2227 r,\n        exact \u27e8hp, hr\u27e9,\n      exact or.inr this\n  end\n\n  -- alternatively, you can use `:=` instead of `from`\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    intro h,\n    have hp : p := h.left,\n    have hqr : q \u2228 r := h.right,\n    cases hqr with hq hr,\n      exact or.inl \u27e8hp, hq\u27e9,\n      exact or.inr \u27e8hp, hr\u27e9\n  end\n\n  -- the `let` tactic is similar to `have` but introduces local definitions instead\n  -- auxiliary facts. It is the tactic analogue of a `let` in a proof term.\n  example : \u2203 x, x + 2 = 8 :=\n  begin\n    let a := 6,\n    existsi a,\n    reflexivity\n  end\n\n  -- You can nest `begin...end` blocks within other `begin...end` blocks.\n  -- Within a `begin...end` block, nested `begin...end` blocks can be abbrev with curly braces:\n  example (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    apply iff.intro,\n    { intro h,\n      cases h.right with hq hr,\n      { exact or.inl \u27e8h.left, hq\u27e9 },\n      { exact or.inr \u27e8h.left, hr\u27e9 }\n    },\n    { intro h,\n      cases h with hpq hpr,\n      { exact \u27e8hpq.left, or.inl hpq.right\u27e9 },\n      { exact \u27e8hpr.left, or.inr hpr.right\u27e9 }\n    }\n  end\n\n  -- Combining these various mechanisms makes for nicely structured tactic proofs:\n  example (p q : Prop) : p \u2227 q \u2194 q \u2227 p :=\n  begin\n    apply iff.intro,\n    { intro h,\n      exact \u27e8h.right, h.left\u27e9 \n    },\n    { intro h,\n      exact \u27e8h.right, h.left\u27e9\n    }\n  end\n  \nend Sec_5_4\n\n\n\n#print \"===================================\"\n#print \"Section 5.5. Tactic Combinators\"\n#print \" \"\n/- Tactic combinators are operations that form new tactics from old ones. A sequencing combinator\n   is already implicit in the comma that appear in a `begin...end` block. -/\n\nnamespace Sec_5_5\n  example (p q : Prop) (hp : p) : p \u2228 q :=\n  by { left, assumption }\n\n  -- Here `{ left, assumption }` is functionally equiv to a single tactic which first \n  -- applies `left` and then applies `assumption`.\n\n  -- `t\u2081; t\u2082` says \"apply t\u2081 to the current goal and then apply `t\u2082` to *all* resulting subgoals:\n  example (p q : Prop) (hp : p) (hq : q) : p \u2227 q :=\n  by split; assumption\n\n  -- The orelse combinator, denoted <|>, applies one tactic, and then backtracks and \n  -- applies another if the first one failed:\n  example (p q : Prop) (hp : p) : p \u2228 q :=\n  by { left, assumption } <|> { right, assumption} -- first one succeeds\n\n  example (p q : Prop) (hq : q) : p \u2228 q :=\n  by { left, assumption } <|> { right, assumption} -- first one fails, but second succeeds\n  \n\n\nend Sec_5_5\n\n\n#print \"===================================\"\n#print \"Section 5.6. Rewriting\"\n#print \" \"\n  /- The rewrite tactic provide a basic mechanism for applying substitutions to goals and \n     hypotheses, providing a convenient and efficient way of working with equality. -/\n\nnamespace Sec_5_6\n  variables (f : \u2115 \u2192 \u2115) (k : \u2115)\n\n  example (h\u2081 : f 0 = 0) (h\u2082 : k = 0) : f k = 0 :=\n  begin\n    rw h\u2082, -- replace k with 0\n    rw h\u2081  -- replace f 0 with 0\n  end\n\n\nend Sec_5_6\n\n\n#print \"===================================\"\n#print \"Section 5.7. Using the Simplifier\"\n#print \" \"\n  /- Whereas `rewrite` is designed as a surgical tool for manipulating a goal, \n     the simplifier offers a more powerful form of automation. A number of identities \n     in Lean's library have been tagged with the `[simp]` attribute, and the simp tactic \n     uses them to iteratively rewrite subterms in an expression. -/\n\nnamespace Sec_5_7\n\nend Sec_5_7\n\n\n#print \"===================================\"\n#print \"Section 5.8. Exercises\"\n#print \" \"\n\nnamespace Sec_5_8\n\n  -- Ex 1. Go back to the exercises in Chapter 3 and Chapter 4 and redo as many as \n  --       you can now with tactic proofs, using also `rw` and `simp` as appropriate.\n\n\n\n  -- Ex 2. Use tactic combinators to obtain a one line proof of the following:\n  example (p q r : Prop) (hp : p) : (p \u2228 q \u2228 r) \u2227 (q \u2228 p \u2228 r) \u2227 (q \u2228 r \u2228 p) := \n  by exact \u27e8or.inl hp, or.inr (or.inl hp), or.inr (or.inr hp)\u27e9\n\n\nend Sec_5_8\n\n\n", "meta": {"author": "williamdemeo", "repo": "LEAN_wjd", "sha": "13826c75c06ef435166a26a72e76fe984c15bad7", "save_path": "github-repos/lean/williamdemeo-LEAN_wjd", "path": "github-repos/lean/williamdemeo-LEAN_wjd/LEAN_wjd-13826c75c06ef435166a26a72e76fe984c15bad7/theorem_proving/05-tactics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.8539127529517044, "lm_q1q2_score": 0.7340778306002071}}
{"text": "import ..lectures.love05_inductive_predicates_demo\n\n\n/-! # LoVe Homework 11: Logical Foundations of Mathematics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (6 points): Even Numbers as a Subtype\n\nUsually, the most convenient way to represent even natural numbers is to use the\nlarger type `\u2115`, which also includes the odd natural numbers. If we want to\nquantify only over even numbers `n`, we can add an assumption `even n` to our\nlemma statement.\n\nAn alternative is to encode evenness in the type, using a subtype. We will\nexplore this approach.\n\n1.1 (1 point). Define the type `ev\u2115` of even natural numbers, using the `even`\npredicate introduced in the lecture 5 demo. -/\n\n#print even\n\ndef ev\u2115 : Type :=\nsorry\n\n/-! 1.2 (1 point). Prove the following lemma about the `even` predicate. You will\nneed it to answer question 1.3. -/\n\nlemma even.add {m n : \u2115} (hm : even m) (hn : even n) :\n  even (m + n) :=\nsorry\n\n/-! 1.3 (1 point). Define zero and addition of even numbers by filling in the\n`sorry` placeholders. -/\n\ndef ev\u2115.zero : ev\u2115 :=\nsorry\n\ndef ev\u2115.add (m n : ev\u2115) : ev\u2115 :=\nsorry\n\n/-! 1.4 (3 points). Prove that addition of even numbers is commutative and\nassociative, and has 0 as an identity element. -/\n\nlemma ev\u2115.add_comm (m n : ev\u2115) :\n  ev\u2115.add m n = ev\u2115.add n m :=\nsorry\n\nlemma ev\u2115.add_assoc (l m n : ev\u2115) :\n  ev\u2115.add (ev\u2115.add l m) n = ev\u2115.add l (ev\u2115.add m n) :=\nsorry\n\nlemma ev\u2115.add_iden_left (n : ev\u2115) :\n  ev\u2115.add ev\u2115.zero n = n :=\nsorry\n\nlemma ev\u2115.add_iden_right (n : ev\u2115) :\n  ev\u2115.add n ev\u2115.zero = n :=\nsorry\n\n\n\n/- ## Question 2 (6 points): Multisets as a Quotient Type\nA multiset (or bag) is a collection of elements that allows for multiple\n(but finitely many) occurrences of its elements. For example, the multiset\n`{2, 7}` is equal to the multiset `{7, 2}` but different from `{2, 7, 7}`.\nFinite multisets can be defined as a quotient over lists. We start with the\ntype `list \u03b1` of finite lists and consider only the number of occurrences of\nelements in the lists, ignoring the order in which elements occur. Following\nthis scheme, `[2, 7, 7]`, `[7, 2, 7]`, and `[7, 7, 2]` would be three equally\nvalid representations of the multiset `{2, 7, 7}`.\nThe `list.count` function returns the number of occurrences of an element in a\nlist. Since it uses equality on elements of type `\u03b1`, it requires `\u03b1` to belong\nto the `decidable_eq` type class. For this reason, the definitions and lemmas\nbelow all take `[decidable_eq \u03b1]` as type class argument.\n\n2.1 (1 point). Provide the missing proof below. -/\n\n@[instance] def multiset.rel (\u03b1 : Type) [decidable_eq \u03b1] : setoid (list \u03b1) :=\n{ r     := \u03bbas bs, \u2200x, list.count x as = list.count x bs,\n  iseqv :=\n    sorry }\n\n/- 2.2 (1 point). Define the type of multisets as the quotient over the\nrelation `multiset.rel`. -/\n\ndef multiset (\u03b1 : Type) [decidable_eq \u03b1] : Type :=\nsorry\n\n/- 2.3 (2 points). Now we have a type `multiset \u03b1` but no operations on it.\nBasic operations on multisets include the empty multiset (`\u2205`), the singleton\nmultiset (`{x} `for any element `x`), and the sum of two multisets (`A \u228e B` for\nany multisets `A` and `B`). The sum should be defined so that the multiplicities\nof elements are added; thus, `{2} \u228e {2, 2} = {2, 2, 2}`.\nFill in the `sorry` placeholders below to implement the multiset union operation.\noperations. -/\n\ndef multiset.empty {\u03b1 : Type} [decidable_eq \u03b1] : multiset \u03b1 :=\n\u27e6[]\u27e7\n\n\ndef multiset.singleton {\u03b1 : Type} [decidable_eq \u03b1] (a : \u03b1) : multiset \u03b1 :=\n\u27e6[a]\u27e7\n\n\ndef multiset.union {\u03b1 : Type} [decidable_eq \u03b1] :\n  multiset \u03b1 \u2192 multiset \u03b1 \u2192 multiset \u03b1 :=\nquotient.lift\u2082\n  sorry\n  sorry\n\n/- 2.4 (2 points). Prove that `multiset.union` is commutative and associative. -/\n\nlemma multiset.union_comm {\u03b1 : Type} [decidable_eq \u03b1] (A B : multiset \u03b1) :\n  multiset.union A B = multiset.union B A :=\nsorry\n\nlemma multiset.union_assoc {\u03b1 : Type} [decidable_eq \u03b1] (A B C : multiset \u03b1) :\n  multiset.union (multiset.union A B) C =\n  multiset.union A (multiset.union B C) :=\nsorry\n\n/-! ## Question 3 (2 points + 1 bonus point): Hilbert Choice\n\n3.1 (1 bonus point). Prove the following lemma. -/\n\nlemma exists_minimal_arg.aux (f : \u2115 \u2192 \u2115) :\n  \u2200x m, f m = x \u2192 \u2203n, \u2200i, f n \u2264 f i\n| x m eq :=\n  begin\n    cases' classical.em (\u2203n, f n < x),\n    sorry, sorry\n  end\n\n/-! Now this interesting lemma falls off: -/\n\nlemma exists_minimal_arg (f : \u2115 \u2192 \u2115) :\n  \u2203n : \u2115, \u2200i : \u2115, f n \u2264 f i :=\nexists_minimal_arg.aux f _ 0 (by refl)\n\n/-! 3.2 (1 point). Use what you learned in the lecture to define the following\nfunction, which returns the (or an) index of the minimal element in `f`'s\nimage. -/\n\nnoncomputable def minimal_arg (f : \u2115 \u2192 \u2115) : \u2115 :=\nsorry\n\n/-! 3.3 (1 point). Prove the following characteristic lemma about your\ndefinition. -/\n\nlemma minimal_arg_spec (f : \u2115 \u2192 \u2115) :\n  \u2200i : \u2115, f (minimal_arg f) \u2264 f i :=\nsorry\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/homework/love08_logical_foundations_of_mathematics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339907, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.7340778304743912}}
{"text": "import data.real.basic\n\n/- Good work!\nCorrectness 90/90\nStyle 10/10\n-/\n\n\n/-\nEXERCISE 1.\n\nProve the following without using automation, i.e. only with basic tactics\nsuch as `intros`, `apply`, `split`, `cases`, `left`, `right`, and `use`.\n-/\n\nsection\n\nvariables {\u03b1 \u03b2 : Type} (p q : \u03b1 \u2192 Prop) (r : \u03b1 \u2192 \u03b2 \u2192 Prop)\n\n-- Exercise 1a. [10pts]\nexample : (\u2200 x, p x) \u2227 (\u2200 x, q x) \u2192 \u2200 x, p x \u2227 q x :=\nbegin\n  intro h,\n  intro x,\n  split,\n  apply h.left,\n  apply h.right,\nend\n\n-- Exercise 1b. [10pts]\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\nbegin\n  intros h x,\n  cases h,\n  {\n    left, -- changes goal to just LHS\n    apply h,\n  },\n  {\n    right,\n    apply h,\n  }\nend\n\n-- Exercise 1c. [10pts]\nexample : (\u2203 x, \u2200 y, r x y) \u2192 \u2200 y, \u2203 x, r x y :=\nbegin\n  intros h y,\n  cases h with x,\n  use x,\n  apply h_h,\nend\n\nend\n\n/-\nEXERCISE 2.\n\nSuppose two pairs of real numbers {a, b} and {c, d} have the same sum\nand product. The following theorem shows that either a = c and b = d,\nor a = d and b = c. Fill in the details. You can use `ring`, `ring_nf`\nand `linarith` freely.\n-/\n\n-- Exercise 2. [20pts]\ntheorem sum_product_magic (a b c d : \u211d)\n    (sumeq : a + b = c + d) (prodeq : a * b = c * d) :\n  (a = c \u2227 b = d) \u2228 (a = d \u2227 b = c) :=\nbegin\n  have : (a - c) * (a - d) = 0,\n  { ring_nf,\n    nth_rewrite 1 mul_comm,\n    rw \u2190 prodeq,\n    rw \u2190 neg_add',\n    rw \u2190 sumeq,\n    ring_nf,\n},\n  have := eq_zero_or_eq_zero_of_mul_eq_zero this,\n  cases this with h h,\n  { left,\n    split;\n    linarith,},\n  { right,\n    split;\n    linarith,}\n    --Nicely done!\nend\n\n/-\nEXERCISE 3.\n\nThe predicate `approaches_at f b a` should be read \"f(x) approaches b as x\napproaches a\", and the predicate `continuous f` says that f is continuous.\n\nProve the following two theorems.\n\nNote that bounded quantification such as `\u2200 \u03b5 > 0, ..` really means `\u2200 \u03b5, \u03b5 > 0 \u2192 ..`\nand `\u2203 \u03b4 > 0, ..` really means `\u2203 \u03b4, \u03b4 > 0 \u2227 ..`.\n-/\n\ndef approaches_at (f : \u211d \u2192 \u211d) (b : \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, abs (x - a) < \u03b4 \u2192 abs (f x - b) < \u03b5\n\n-- Exercise 3a. [10pts]\ntheorem approaches_at_add_right  {f : \u211d \u2192 \u211d} {a b c: \u211d}\n    (hf : approaches_at f b a) :\n  approaches_at (\u03bb x, f x + c) (b + c) a :=\nbegin\n  intros \u03b5 he,\n  unfold approaches_at at hf,\n  unfold approaches_at,\n  cases (hf \u03b5 he) with \u03b4 hf,\n  cases hf with hd hf,\n  use \u03b4,\n  split,\n  exact hd,\n  intros x hxa\u03b4,\n  ring_nf,\n  exact (hf x hxa\u03b4),\nend\n\n-- Exercise 3b. [10pts]\ntheorem approaches_at_comp {f g : \u211d \u2192 \u211d} {a b c : \u211d}\n  (hf : approaches_at f b a) (hg : approaches_at g c b) :\n    approaches_at (g \u2218 f) c a :=\nbegin\n  unfold approaches_at at hf hg,\n  unfold approaches_at,\n  intros \u03b5 he,\n  cases (hg \u03b5 he) with dg hg,\n  cases hg with hdg hg,\n  cases (hf dg hdg) with \u03b4 hf,\n  cases hf with hd hf,\n  use \u03b4,\n  split,\n  exact hd,\n  intros x hxa\u03b4,\n  dsimp,\n  exact (hg (f x) (hf x hxa\u03b4)),\nend\n\ndef continuous (f : \u211d \u2192 \u211d) := \u2200 x, approaches_at f (f x) x\n\n-- Exercise 3c. [10pts]\ntheorem continuous_add_right {f : \u211d \u2192 \u211d} (ctsf : continuous f) (r : \u211d) :\n  continuous (\u03bb x, f x + r) :=\nbegin\n  unfold continuous,\n  intros x,\n  unfold continuous at ctsf,\n  apply approaches_at_add_right,\n  dsimp,\n  exact ctsf x,\nend\n\n-- Since `f x - r` is the same as `f x + (- r)`, the following is an instance\n-- of the previous theorem.\ntheorem continuous_sub {f : \u211d \u2192 \u211d} (ctsf : continuous f) (r : \u211d) :\n  continuous (\u03bb x, f x - r) :=\ncontinuous_add_right ctsf (-r)\n\n/-\nEXERCISE 4.\n\nIn class, I will prove the intermediate value theorem in the form `ivt`.\nUse that version to prove the more general one that comes after.\n-/\n\n/- We'll do this in class! You don't have to prove it,\n   and you can leave the `sorry` and apply the theorem \n   as a black box. -/\ntheorem ivt {f : \u211d \u2192 \u211d} {a b : \u211d} (aleb : a \u2264 b)\n    (ctsf : continuous f) (hfa : f a < 0) (hfb : 0 < f b) :\n  \u2203 x, a \u2264 x \u2227 x \u2264 b \u2227 f x = 0 :=\nsorry\n\n-- Use `ivt` to prove `ivt'` below.\n\n-- Exercise 4. [20pts]\ntheorem ivt' {f : \u211d \u2192 \u211d} {a b c : \u211d} (aleb : a \u2264 b)\n    (ctsf : continuous f) (hfa : f a < c) (hfb : c < f b) :\n  \u2203 x, a \u2264 x \u2227 x \u2264 b \u2227 f x = c :=\nbegin\n  let g := \u03bb x, f x - c,\n  have : \u2203 x, a \u2264 x \u2227 x \u2264 b \u2227 g x = 0,\n  { dsimp [g],\n    apply ivt aleb,\n    apply continuous_sub ctsf,\n    linarith,\n    linarith,},\n  dsimp [g] at this,\n  cases this with x this,\n  use x,\n  rw sub_eq_zero at this,\n  exact this,\nend\n\n", "meta": {"author": "PriyaMalhotra3", "repo": "har-ifvm-23-PriyaMalhotra3", "sha": "133a717f1d60680042ee0a514392106451853a71", "save_path": "github-repos/lean/PriyaMalhotra3-har-ifvm-23-PriyaMalhotra3", "path": "github-repos/lean/PriyaMalhotra3-har-ifvm-23-PriyaMalhotra3/har-ifvm-23-PriyaMalhotra3-133a717f1d60680042ee0a514392106451853a71/src/assignment4/assignment4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7340757027549374}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module order.circular\n! leanprover-community/mathlib commit a2d2e18906e2b62627646b5d5be856e6a642062f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Basic\nimport Mathlib.Tactic.Set\n\n/-!\n# Circular order hierarchy\n\nThis file defines circular preorders, circular partial orders and circular orders.\n\n## Hierarchy\n\n* A ternary \"betweenness\" relation `btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` forms a `CircularOrder` if it is\n  - reflexive: `btw a a a`\n  - cyclic: `btw a b c \u2192 btw b c a`\n  - antisymmetric: `btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a`\n  - total: `btw a b c \u2228 btw c b a`\n  along with a strict betweenness relation `sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` which respects\n  `sbtw a b c \u2194 btw a b c \u2227 \u00ac btw c b a`, analogously to how `<` and `\u2264` are related, and is\n  - transitive: `sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c`.\n* A `CircularPartialOrder` drops totality.\n* A `CircularPreorder` further drops antisymmetry.\n\nThe intuition is that a circular order is a circle and `btw a b c` means that going around\nclockwise from `a` you reach `b` before `c` (`b` is between `a` and `c` is meaningless on an\nunoriented circle). A circular partial order is several, potentially intersecting, circles. A\ncircular preorder is like a circular partial order, but several points can coexist.\n\nNote that the relations between `CircularPreorder`, `CircularPartialOrder` and `CircularOrder`\nare subtler than between `Preorder`, `PartialOrder`, `LinearOrder`. In particular, one cannot\nsimply extend the `btw` of a `CircularPartialOrder` to make it a `CircularOrder`.\n\nOne can translate from usual orders to circular ones by \"closing the necklace at infinity\". See\n`LE.toBtw` and `LT.toSBtw`. Going the other way involves \"cutting the necklace\" or\n\"rolling the necklace open\".\n\n## Examples\n\nSome concrete circular orders one encounters in the wild are `ZMod n` for `0 < n`, `Circle`,\n`Real.Angle`...\n\n## Main definitions\n\n* `Set.cIcc`: Closed-closed circular interval.\n* `Set.cIoo`: Open-open circular interval.\n\n## Notes\n\nThere's an unsolved diamond on `OrderDual \u03b1` here. The instances `LE \u03b1 \u2192 Btw \u03b1\u1d52\u1d48` and\n`LT \u03b1 \u2192 SBtw \u03b1\u1d52\u1d48` can each be inferred in two ways:\n* `LE \u03b1` \u2192 `Btw \u03b1` \u2192 `Btw \u03b1\u1d52\u1d48` vs\n  `LE \u03b1` \u2192 `LE \u03b1\u1d52\u1d48` \u2192 `Btw \u03b1\u1d52\u1d48`\n* `LT \u03b1` \u2192 `SBtw \u03b1` \u2192 `SBtw \u03b1\u1d52\u1d48` vs\n  `LT \u03b1` \u2192 `LT \u03b1\u1d52\u1d48` \u2192 `SBtw \u03b1\u1d52\u1d48`\nThe fields are propeq, but not defeq. It is temporarily fixed by turning the circularizing instances\ninto definitions.\n\n## TODO\n\nAntisymmetry is quite weak in the sense that there's no way to discriminate which two points are\nequal. This prevents defining closed-open intervals `cIco` and `cIoc` in the neat `=`-less way. We\ncurrently haven't defined them at all.\n\nWhat is the correct generality of \"rolling the necklace\" open? At least, this works for `\u03b1 \u00d7 \u03b2` and\n`\u03b2 \u00d7 \u03b1` where `\u03b1` is a circular order and `\u03b2` is a linear order.\n\nWhat's next is to define circular groups and provide instances for `ZMod n`, the usual circle group\n`Circle`, `Real.Angle`, and `RootsOfUnity M`. What conditions do we need on `M` for this last one\nto work?\n\nWe should have circular order homomorphisms. The typical example is\n`days_to_month : days_of_the_year \u2192c months_of_the_year` which relates the circular order of days\nand the circular order of months. Is `\u03b1 \u2192c \u03b2` a good notation?\n\n## References\n\n* https://en.wikipedia.org/wiki/Cyclic_order\n* https://en.wikipedia.org/wiki/Partial_cyclic_order\n\n## Tags\n\ncircular order, cyclic order, circularly ordered set, cyclically ordered set\n-/\n\n\n/-- Syntax typeclass for a betweenness relation. -/\nclass Btw (\u03b1 : Type _) where\n  /-- Betweenness for circular orders. `btw a b c` states that `b` is between `a` and `c` (in that\n  order). -/\n  btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop\n#align has_btw Btw\n\nexport Btw (btw)\n\n/-- Syntax typeclass for a strict betweenness relation. -/\nclass SBtw (\u03b1 : Type _) where\n  /-- Strict betweenness for circular orders. `sbtw a b c` states that `b` is strictly between `a`\n  and `c` (in that order). -/\n  sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop\n#align has_sbtw SBtw\n\nexport SBtw (sbtw)\n\n/-- A circular preorder is the analogue of a preorder where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive and cyclic. `sbtw` is transitive.\n-/\nclass CircularPreorder (\u03b1 : Type _) extends Btw \u03b1, SBtw \u03b1 where\n  /-- `a` is between `a` and `a`. -/\n  btw_refl (a : \u03b1) : btw a a a\n  /-- If `b` is between `a` and `c`, then `c` is between `b` and `a`.\n  This is motivated by imagining three points on a circle. -/\n  btw_cyclic_left {a b c : \u03b1} : btw a b c \u2192 btw b c a\n  sbtw := fun a b c => btw a b c \u2227 \u00acbtw c b a\n  /-- Strict betweenness is given by betweenness in one direction and non-betweenness in the other.\n\n  I.e., if `b` is between `a` and `c` but not between `c` and `a`, then we say `b` is strictly\n  between `a` and `c`. -/\n  sbtw_iff_btw_not_btw {a b c : \u03b1} : sbtw a b c \u2194 btw a b c \u2227 \u00acbtw c b a := by intros; rfl\n  /-- For any fixed `c`, `fun a b \u21a6 sbtw a b c` is a transitive relation.\n\n  I.e., given `a` `b` `d` `c` in that \"order\", if we have `b` strictly between `a` and `c`, and `d`\n  strictly between `b` and `c`, then `d` is strictly between `a` and `c`. -/\n  sbtw_trans_left {a b c d : \u03b1} : sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c\n#align circular_preorder CircularPreorder\n\nexport CircularPreorder (btw_refl btw_cyclic_left sbtw_trans_left)\n\n/-- A circular partial order is the analogue of a partial order where you can loop around. `\u2264` and\n`<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic and\nantisymmetric. `sbtw` is transitive. -/\nclass CircularPartialOrder (\u03b1 : Type _) extends CircularPreorder \u03b1 where\n  /-- If `b` is between `a` and `c` and also between `c` and `a`, then at least one pair of points\n  among `a`, `b`, `c` are identical. -/\n  btw_antisymm {a b c : \u03b1} : btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a\n#align circular_partial_order CircularPartialOrder\n\nexport CircularPartialOrder (btw_antisymm)\n\n/-- A circular order is the analogue of a linear order where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic, antisymmetric and total.\n`sbtw` is transitive. -/\nclass CircularOrder (\u03b1 : Type _) extends CircularPartialOrder \u03b1 where\n  /-- For any triple of points, the second is between the other two one way or another. -/\n  btw_total : \u2200 a b c : \u03b1, btw a b c \u2228 btw c b a\n#align circular_order CircularOrder\n\nexport CircularOrder (btw_total)\n\n/-! ### Circular preorders -/\n\n\nsection CircularPreorder\n\nvariable {\u03b1 : Type _} [CircularPreorder \u03b1]\n\ntheorem btw_rfl {a : \u03b1} : btw a a a :=\n  btw_refl _\n#align btw_rfl btw_rfl\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_cyclic_left        \u2190 has_btw.btw.cyclic_left\ntheorem Btw.btw.cyclic_left {a b c : \u03b1} (h : btw a b c) : btw b c a :=\n  btw_cyclic_left h\n#align has_btw.btw.cyclic_left Btw.btw.cyclic_left\n\ntheorem btw_cyclic_right {a b c : \u03b1} (h : btw a b c) : btw c a b :=\n  h.cyclic_left.cyclic_left\n#align btw_cyclic_right btw_cyclic_right\n\nalias btw_cyclic_right \u2190 Btw.btw.cyclic_right\n#align has_btw.btw.cyclic_right Btw.btw.cyclic_right\n\n/-- The order of the `\u2194` has been chosen so that `rw btw_cyclic` cycles to the right while\n`rw \u2190btw_cyclic` cycles to the left (thus following the prepended arrow). -/\ntheorem btw_cyclic {a b c : \u03b1} : btw a b c \u2194 btw c a b :=\n  \u27e8btw_cyclic_right, btw_cyclic_left\u27e9\n#align btw_cyclic btw_cyclic\n\ntheorem sbtw_iff_btw_not_btw {a b c : \u03b1} : sbtw a b c \u2194 btw a b c \u2227 \u00acbtw c b a :=\n  CircularPreorder.sbtw_iff_btw_not_btw\n#align sbtw_iff_btw_not_btw sbtw_iff_btw_not_btw\n\ntheorem btw_of_sbtw {a b c : \u03b1} (h : sbtw a b c) : btw a b c :=\n  (sbtw_iff_btw_not_btw.1 h).1\n#align btw_of_sbtw btw_of_sbtw\n\nalias btw_of_sbtw \u2190 SBtw.sbtw.btw\n#align has_sbtw.sbtw.btw SBtw.sbtw.btw\n\ntheorem not_btw_of_sbtw {a b c : \u03b1} (h : sbtw a b c) : \u00acbtw c b a :=\n  (sbtw_iff_btw_not_btw.1 h).2\n#align not_btw_of_sbtw not_btw_of_sbtw\n\nalias not_btw_of_sbtw \u2190 SBtw.sbtw.not_btw\n#align has_sbtw.sbtw.not_btw SBtw.sbtw.not_btw\n\ntheorem not_sbtw_of_btw {a b c : \u03b1} (h : btw a b c) : \u00acsbtw c b a := fun h' => h'.not_btw h\n#align not_sbtw_of_btw not_sbtw_of_btw\n\nalias not_sbtw_of_btw \u2190 Btw.btw.not_sbtw\n#align has_btw.btw.not_sbtw Btw.btw.not_sbtw\n\ntheorem sbtw_of_btw_not_btw {a b c : \u03b1} (habc : btw a b c) (hcba : \u00acbtw c b a) : sbtw a b c :=\n  sbtw_iff_btw_not_btw.2 \u27e8habc, hcba\u27e9\n#align sbtw_of_btw_not_btw sbtw_of_btw_not_btw\n\nalias sbtw_of_btw_not_btw \u2190 Btw.btw.sbtw_of_not_btw\n#align has_btw.btw.sbtw_of_not_btw Btw.btw.sbtw_of_not_btw\n\ntheorem sbtw_cyclic_left {a b c : \u03b1} (h : sbtw a b c) : sbtw b c a :=\n  h.btw.cyclic_left.sbtw_of_not_btw fun h' => h.not_btw h'.cyclic_left\n#align sbtw_cyclic_left sbtw_cyclic_left\n\nalias sbtw_cyclic_left \u2190 SBtw.sbtw.cyclic_left\n#align has_sbtw.sbtw.cyclic_left SBtw.sbtw.cyclic_left\n\ntheorem sbtw_cyclic_right {a b c : \u03b1} (h : sbtw a b c) : sbtw c a b :=\n  h.cyclic_left.cyclic_left\n#align sbtw_cyclic_right sbtw_cyclic_right\n\nalias sbtw_cyclic_right \u2190 SBtw.sbtw.cyclic_right\n#align has_sbtw.sbtw.cyclic_right SBtw.sbtw.cyclic_right\n\n/-- The order of the `\u2194` has been chosen so that `rw sbtw_cyclic` cycles to the right while\n`rw \u2190sbtw_cyclic` cycles to the left (thus following the prepended arrow). -/\ntheorem sbtw_cyclic {a b c : \u03b1} : sbtw a b c \u2194 sbtw c a b :=\n  \u27e8sbtw_cyclic_right, sbtw_cyclic_left\u27e9\n#align sbtw_cyclic sbtw_cyclic\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_trans_left        \u2190 has_btw.btw.trans_left\ntheorem SBtw.sbtw.trans_left {a b c d : \u03b1} (h : sbtw a b c) : sbtw b d c \u2192 sbtw a d c :=\n  sbtw_trans_left h\n#align has_sbtw.sbtw.trans_left SBtw.sbtw.trans_left\n\ntheorem sbtw_trans_right {a b c d : \u03b1} (hbc : sbtw a b c) (hcd : sbtw a c d) : sbtw a b d :=\n  (hbc.cyclic_left.trans_left hcd.cyclic_left).cyclic_right\n#align sbtw_trans_right sbtw_trans_right\n\nalias sbtw_trans_right \u2190 SBtw.sbtw.trans_right\n#align has_sbtw.sbtw.trans_right SBtw.sbtw.trans_right\n\ntheorem sbtw_asymm {a b c : \u03b1} (h : sbtw a b c) : \u00acsbtw c b a :=\n  h.btw.not_sbtw\n#align sbtw_asymm sbtw_asymm\n\nalias sbtw_asymm \u2190 SBtw.sbtw.not_sbtw\n#align has_sbtw.sbtw.not_sbtw SBtw.sbtw.not_sbtw\n\ntheorem sbtw_irrefl_left_right {a b : \u03b1} : \u00acsbtw a b a := fun h => h.not_btw h.btw\n#align sbtw_irrefl_left_right sbtw_irrefl_left_right\n\ntheorem sbtw_irrefl_left {a b : \u03b1} : \u00acsbtw a a b := fun h => sbtw_irrefl_left_right h.cyclic_left\n#align sbtw_irrefl_left sbtw_irrefl_left\n\ntheorem sbtw_irrefl_right {a b : \u03b1} : \u00acsbtw a b b := fun h => sbtw_irrefl_left_right h.cyclic_right\n#align sbtw_irrefl_right sbtw_irrefl_right\n\ntheorem sbtw_irrefl (a : \u03b1) : \u00acsbtw a a a :=\n  sbtw_irrefl_left_right\n#align sbtw_irrefl sbtw_irrefl\n\nend CircularPreorder\n\n/-! ### Circular partial orders -/\n\n\nsection CircularPartialOrder\n\nvariable {\u03b1 : Type _} [CircularPartialOrder \u03b1]\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_antisymm        \u2190 has_btw.btw.antisymm\ntheorem Btw.btw.antisymm {a b c : \u03b1} (h : btw a b c) : btw c b a \u2192 a = b \u2228 b = c \u2228 c = a :=\n  btw_antisymm h\n#align has_btw.btw.antisymm Btw.btw.antisymm\n\nend CircularPartialOrder\n\n/-! ### Circular orders -/\n\n\nsection CircularOrder\n\nvariable {\u03b1 : Type _} [CircularOrder \u03b1]\n\ntheorem btw_refl_left_right (a b : \u03b1) : btw a b a :=\n  (or_self_iff _).1 (btw_total a b a)\n#align btw_refl_left_right btw_refl_left_right\n\ntheorem btw_rfl_left_right {a b : \u03b1} : btw a b a :=\n  btw_refl_left_right _ _\n#align btw_rfl_left_right btw_rfl_left_right\n\ntheorem btw_refl_left (a b : \u03b1) : btw a a b :=\n  btw_rfl_left_right.cyclic_right\n#align btw_refl_left btw_refl_left\n\ntheorem btw_rfl_left {a b : \u03b1} : btw a a b :=\n  btw_refl_left _ _\n#align btw_rfl_left btw_rfl_left\n\ntheorem btw_refl_right (a b : \u03b1) : btw a b b :=\n  btw_rfl_left_right.cyclic_left\n#align btw_refl_right btw_refl_right\n\ntheorem btw_rfl_right {a b : \u03b1} : btw a b b :=\n  btw_refl_right _ _\n#align btw_rfl_right btw_rfl_right\n\ntheorem sbtw_iff_not_btw {a b c : \u03b1} : sbtw a b c \u2194 \u00acbtw c b a := by\n  rw [sbtw_iff_btw_not_btw]\n  exact and_iff_right_of_imp (btw_total _ _ _).resolve_left\n#align sbtw_iff_not_btw sbtw_iff_not_btw\n\ntheorem btw_iff_not_sbtw {a b c : \u03b1} : btw a b c \u2194 \u00acsbtw c b a :=\n  iff_not_comm.1 sbtw_iff_not_btw\n#align btw_iff_not_sbtw btw_iff_not_sbtw\n\nend CircularOrder\n\n/-! ### Circular intervals -/\n\n\nnamespace Set\n\nsection CircularPreorder\n\nvariable {\u03b1 : Type _} [CircularPreorder \u03b1]\n\n/-- Closed-closed circular interval -/\ndef cIcc (a b : \u03b1) : Set \u03b1 :=\n  { x | btw a x b }\n#align set.cIcc Set.cIcc\n\n/-- Open-open circular interval -/\ndef cIoo (a b : \u03b1) : Set \u03b1 :=\n  { x | sbtw a x b }\n#align set.cIoo Set.cIoo\n\n@[simp]\ntheorem mem_cIcc {a b x : \u03b1} : x \u2208 cIcc a b \u2194 btw a x b :=\n  Iff.rfl\n#align set.mem_cIcc Set.mem_cIcc\n\n@[simp]\ntheorem mem_cIoo {a b x : \u03b1} : x \u2208 cIoo a b \u2194 sbtw a x b :=\n  Iff.rfl\n#align set.mem_cIoo Set.mem_cIoo\n\nend CircularPreorder\n\nsection CircularOrder\n\nvariable {\u03b1 : Type _} [CircularOrder \u03b1]\n\ntheorem left_mem_cIcc (a b : \u03b1) : a \u2208 cIcc a b :=\n  btw_rfl_left\n#align set.left_mem_cIcc Set.left_mem_cIcc\n\ntheorem right_mem_cIcc (a b : \u03b1) : b \u2208 cIcc a b :=\n  btw_rfl_right\n#align set.right_mem_cIcc Set.right_mem_cIcc\n\ntheorem compl_cIcc {a b : \u03b1} : cIcc a b\u1d9c = cIoo b a := by\n  ext\n  rw [Set.mem_cIoo, sbtw_iff_not_btw]\n  rfl\n#align set.compl_cIcc Set.compl_cIcc\n\ntheorem compl_cIoo {a b : \u03b1} : cIoo a b\u1d9c = cIcc b a := by\n  ext\n  rw [Set.mem_cIcc, btw_iff_not_sbtw]\n  rfl\n#align set.compl_cIoo Set.compl_cIoo\n\nend CircularOrder\n\nend Set\n\n/-! ### Circularizing instances -/\n\n\n/-- The betweenness relation obtained from \"looping around\" `\u2264`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef LE.toBtw (\u03b1 : Type _) [LE \u03b1] : Btw \u03b1 where\n  btw a b c := a \u2264 b \u2227 b \u2264 c \u2228 b \u2264 c \u2227 c \u2264 a \u2228 c \u2264 a \u2227 a \u2264 b\n#align has_le.to_has_btw LE.toBtw\n\n/-- The strict betweenness relation obtained from \"looping around\" `<`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef LT.toSBtw (\u03b1 : Type _) [LT \u03b1] : SBtw \u03b1 where\n  sbtw a b c := a < b \u2227 b < c \u2228 b < c \u2227 c < a \u2228 c < a \u2227 a < b\n#align has_lt.to_has_sbtw LT.toSBtw\n\n/-- The circular preorder obtained from \"looping around\" a preorder.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef Preorder.toCircularPreorder (\u03b1 : Type _) [Preorder \u03b1] : CircularPreorder \u03b1 where\n  btw a b c := a \u2264 b \u2227 b \u2264 c \u2228 b \u2264 c \u2227 c \u2264 a \u2228 c \u2264 a \u2227 a \u2264 b\n  sbtw a b c := a < b \u2227 b < c \u2228 b < c \u2227 c < a \u2228 c < a \u2227 a < b\n  btw_refl a := Or.inl \u27e8le_rfl, le_rfl\u27e9\n  btw_cyclic_left {a b c} h := by\n    dsimp\n    rwa [\u2190 or_assoc, or_comm]\n  sbtw_trans_left {a b c d} := by\n    rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hbd, hdc\u27e9 | \u27e8hdc, hcb\u27e9 | \u27e8hcb, hbd\u27e9)\n    \u00b7 exact Or.inl \u27e8hab.trans hbd, hdc\u27e9\n    \u00b7 exact (hbc.not_lt hcb).elim\n    \u00b7 exact (hbc.not_lt hcb).elim\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact (hbc.not_lt hcb).elim\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact Or.inr (Or.inr \u27e8hca, hab.trans hbd\u27e9)\n  sbtw_iff_btw_not_btw {a b c} := by\n    simp_rw [lt_iff_le_not_le]\n    have := le_trans a b c\n    have := le_trans b c a\n    have := le_trans c a b\n    tauto\n#align preorder.to_circular_preorder Preorder.toCircularPreorder\n\n/-- The circular partial order obtained from \"looping around\" a partial order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef PartialOrder.toCircularPartialOrder (\u03b1 : Type _) [PartialOrder \u03b1] : CircularPartialOrder \u03b1 :=\n  { Preorder.toCircularPreorder \u03b1 with\n    btw_antisymm := fun {a b c} => by\n      rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hcb, hba\u27e9 | \u27e8hba, hac\u27e9 | \u27e8hac, hcb\u27e9)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inr (Or.inl <| hbc.antisymm hcb)\n      \u00b7 exact Or.inr (Or.inl <| hbc.antisymm hcb)\n      \u00b7 exact Or.inr (Or.inr <| hca.antisymm hac)\n      \u00b7 exact Or.inr (Or.inl <| hbc.antisymm hcb)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inr (Or.inr <| hca.antisymm hac) }\n#align partial_order.to_circular_partial_order PartialOrder.toCircularPartialOrder\n\n/-- The circular order obtained from \"looping around\" a linear order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef LinearOrder.toCircularOrder (\u03b1 : Type _) [LinearOrder \u03b1] : CircularOrder \u03b1 :=\n  { PartialOrder.toCircularPartialOrder \u03b1 with\n    btw_total := fun a b c => by\n      cases' le_total a b with hab hba <;> cases' le_total b c with hbc hcb <;>\n        cases' le_total c a with hca hac\n      \u00b7 exact Or.inl (Or.inl \u27e8hab, hbc\u27e9)\n      \u00b7 exact Or.inl (Or.inl \u27e8hab, hbc\u27e9)\n      \u00b7 exact Or.inl (Or.inr <| Or.inr \u27e8hca, hab\u27e9)\n      \u00b7 exact Or.inr (Or.inr <| Or.inr \u27e8hac, hcb\u27e9)\n      \u00b7 exact Or.inl (Or.inr <| Or.inl \u27e8hbc, hca\u27e9)\n      \u00b7 exact Or.inr (Or.inr <| Or.inl \u27e8hba, hac\u27e9)\n      \u00b7 exact Or.inr (Or.inl \u27e8hcb, hba\u27e9)\n      \u00b7 exact Or.inr (Or.inr <| Or.inl \u27e8hba, hac\u27e9) }\n#align linear_order.to_circular_order LinearOrder.toCircularOrder\n\n/-! ### Dual constructions -/\n\n\nnamespace OrderDual\n\ninstance btw (\u03b1 : Type _) [Btw \u03b1] : Btw \u03b1\u1d52\u1d48 :=\n  \u27e8fun a b c : \u03b1 => Btw.btw c b a\u27e9\n\ninstance sbtw (\u03b1 : Type _) [SBtw \u03b1] : SBtw \u03b1\u1d52\u1d48 :=\n  \u27e8fun a b c : \u03b1 => SBtw.sbtw c b a\u27e9\n\ninstance circularPreorder (\u03b1 : Type _) [CircularPreorder \u03b1] : CircularPreorder \u03b1\u1d52\u1d48 :=\n  { OrderDual.btw \u03b1,\n    OrderDual.sbtw \u03b1 with\n    btw_refl := fun _ => @btw_refl \u03b1 _ _\n    btw_cyclic_left := fun {_ _ _} => @btw_cyclic_right \u03b1 _ _ _ _\n    sbtw_trans_left := fun {_ _ _ _} habc hbdc => hbdc.trans_right habc\n    sbtw_iff_btw_not_btw := fun {a b c} => @sbtw_iff_btw_not_btw \u03b1 _ c b a }\n\ninstance circularPartialOrder (\u03b1 : Type _) [CircularPartialOrder \u03b1] : CircularPartialOrder \u03b1\u1d52\u1d48 :=\n  { OrderDual.circularPreorder \u03b1 with\n    btw_antisymm := fun {_ _ _} habc hcba => @btw_antisymm \u03b1 _ _ _ _ hcba habc }\n\ninstance (\u03b1 : Type _) [CircularOrder \u03b1] : CircularOrder \u03b1\u1d52\u1d48 :=\n  { OrderDual.circularPartialOrder \u03b1 with\n    btw_total := fun {a b c} => @btw_total \u03b1 _ c b a }\n\nend OrderDual\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/Circular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7340137056699758}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-\n\n# More on functions\n\nAnother question on the IUM problem sheet on functions\nis \"If `f : X \u2192 Y` and `g : Y \u2192 Z` and `g \u2218 f` is injective, is it true that `g` is injective?\"\nThis is not true. A counterexample could be made by letting `X` and `Z` have one element, \nand letting `Y` have two elements; `f` and `g` are then not hard to write down. Let's\nsee how to do this in Lean by making inductive types `X`, `Y` and `Z` and functions\n`f` and `g` which give an explicit counterexample.\n\n-/\n\n-- Let X be {a}\ninductive X : Type\n| a : X\n\n-- in fact the term of type X is called `X.a`.\n\n-- Let Y be {b,c}\ninductive Y : Type\n| b : Y\n| c : Y\n\ninductive Z : Type\n| d : Z\n\n-- Define f by f(X.a)=Y.b\ndef f : X \u2192 Y\n| X.a := Y.b\n\n-- define g by g(Y.b)=g(Y.c)=Z.d\ndef g : Y \u2192 Z\n| Y.b := Z.d\n| Y.c := Z.d\n\n-- examples of how these things work\nexample (z : Z) : z = Z.d :=\nbegin\n  cases z,\n  refl,\nend\n\nexample : Y.b \u2260 Y.c :=\nbegin\n  intro h, -- x \u2260 y is definitionally equal to (x = y) \u2192 false\n  cases h, -- there are no cases when they're equal!\nend\n\n\nopen function\n\nlemma gf_injective : injective (g \u2218 f) :=\nbegin\n  sorry,\nend\n\n-- This is a question on the IUM function problem sheet\nexample : \u00ac (\u2200 X Y Z : Type, \u2200 (f : X \u2192 Y) (g : Y \u2192 Z), injective (g \u2218 f) \u2192 injective g) :=\nbegin\n  sorry,\nend\n\n-- This is another one\nexample : \u00ac (\u2200 X Y Z : Type, \u2200 (f : X \u2192 Y) (g : Y \u2192 Z), surjective (g \u2218 f) \u2192 surjective f) :=\nbegin\n  sorry,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2022/functions/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7339923517485104}}
{"text": "/-\nCopyright (c) 2020 Google LLC. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Wong\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.list.basic\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Palindromes\n\nThis module defines *palindromes*, lists which are equal to their reverse.\n\nThe main result is the `palindrome` inductive type, and its associated `palindrome.rec_on` induction\nprinciple. Also provided are conversions to and from other equivalent definitions.\n\n## References\n\n* [Pierre Cast\u00e9ran, *On palindromes*][casteran]\n\n[casteran]: https://www.labri.fr/perso/casteran/CoqArt/inductive-prop-chap/palindrome.html\n\n## Tags\n\npalindrome, reverse, induction\n-/\n\n/--\n`palindrome l` asserts that `l` is a palindrome. This is defined inductively:\n\n* The empty list is a palindrome;\n* A list with one element is a palindrome;\n* Adding the same element to both ends of a palindrome results in a bigger palindrome.\n-/\ninductive palindrome {\u03b1 : Type u_1} : List \u03b1 \u2192 Prop\nwhere\n| nil : palindrome []\n| singleton : \u2200 (x : \u03b1), palindrome [x]\n| cons_concat : \u2200 (x : \u03b1) {l : List \u03b1}, palindrome l \u2192 palindrome (x :: (l ++ [x]))\n\nnamespace palindrome\n\n\ntheorem reverse_eq {\u03b1 : Type u_1} {l : List \u03b1} (p : palindrome l) : list.reverse l = l := sorry\n\ntheorem of_reverse_eq {\u03b1 : Type u_1} {l : List \u03b1} : list.reverse l = l \u2192 palindrome l := sorry\n\ntheorem iff_reverse_eq {\u03b1 : Type u_1} {l : List \u03b1} : palindrome l \u2194 list.reverse l = l :=\n  { mp := reverse_eq, mpr := of_reverse_eq }\n\ntheorem append_reverse {\u03b1 : Type u_1} (l : List \u03b1) : palindrome (l ++ list.reverse l) := sorry\n\nprotected instance decidable {\u03b1 : Type u_1} [DecidableEq \u03b1] (l : List \u03b1) : Decidable (palindrome l) :=\n  decidable_of_iff' (list.reverse l = l) iff_reverse_eq\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/list/palindrome.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.8333246035907932, "lm_q1q2_score": 0.7339898836723974}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.finset.sort\n! leanprover-community/mathlib commit 509de852e1de55e1efa8eacfa11df0823f26f226\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.RelIso.Set\nimport Mathlib.Data.Fintype.Lattice\nimport Mathlib.Data.Multiset.Sort\nimport Mathlib.Data.List.NodupEquivFin\n\n/-!\n# Construct a sorted list from a finset.\n-/\n\n\nnamespace Finset\n\nopen Multiset Nat\n\nvariable {\u03b1 \u03b2 : Type _}\n\n/-! ### sort -/\n\n\nsection sort\n\nvariable (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [DecidableRel r] [IsTrans \u03b1 r] [IsAntisymm \u03b1 r] [IsTotal \u03b1 r]\n\n/-- `sort s` constructs a sorted list from the unordered set `s`.\n  (Uses merge sort algorithm.) -/\ndef sort (s : Finset \u03b1) : List \u03b1 :=\n  Multiset.sort r s.1\n#align finset.sort Finset.sort\n\n@[simp]\ntheorem sort_sorted (s : Finset \u03b1) : List.Sorted r (sort r s) :=\n  Multiset.sort_sorted _ _\n#align finset.sort_sorted Finset.sort_sorted\n\n@[simp]\ntheorem sort_eq (s : Finset \u03b1) : \u2191(sort r s) = s.1 :=\n  Multiset.sort_eq _ _\n#align finset.sort_eq Finset.sort_eq\n\n@[simp]\ntheorem sort_nodup (s : Finset \u03b1) : (sort r s).Nodup :=\n  (by rw [sort_eq]; exact s.2 : @Multiset.Nodup \u03b1 (sort r s))\n#align finset.sort_nodup Finset.sort_nodup\n\n@[simp]\ntheorem sort_toFinset [DecidableEq \u03b1] (s : Finset \u03b1) : (sort r s).toFinset = s :=\n  List.toFinset_eq (sort_nodup r s) \u25b8 eq_of_veq (sort_eq r s)\n#align finset.sort_to_finset Finset.sort_toFinset\n\n@[simp]\ntheorem mem_sort {s : Finset \u03b1} {a : \u03b1} : a \u2208 sort r s \u2194 a \u2208 s :=\n  Multiset.mem_sort _\n#align finset.mem_sort Finset.mem_sort\n\n@[simp]\ntheorem length_sort {s : Finset \u03b1} : (sort r s).length = s.card :=\n  Multiset.length_sort _\n#align finset.length_sort Finset.length_sort\n\n@[simp]\ntheorem sort_empty : sort r \u2205 = [] :=\n  Multiset.sort_zero r\n#align finset.sort_empty Finset.sort_empty\n\n@[simp]\ntheorem sort_singleton (a : \u03b1) : sort r {a} = [a] :=\n  Multiset.sort_singleton r a\n#align finset.sort_singleton Finset.sort_singleton\n\ntheorem sort_perm_toList (s : Finset \u03b1) : sort r s ~ s.toList := by\n  rw [\u2190 Multiset.coe_eq_coe]\n  simp only [coe_toList, sort_eq]\n#align finset.sort_perm_to_list Finset.sort_perm_toList\n\nend sort\n\nsection SortLinearOrder\n\nvariable [LinearOrder \u03b1]\n\ntheorem sort_sorted_lt (s : Finset \u03b1) : List.Sorted (\u00b7 < \u00b7) (sort (\u00b7 \u2264 \u00b7) s) :=\n  (sort_sorted _ _).lt_of_le (sort_nodup _ _)\n#align finset.sort_sorted_lt Finset.sort_sorted_lt\n\ntheorem sorted_zero_eq_min'_aux (s : Finset \u03b1) (h : 0 < (s.sort (\u00b7 \u2264 \u00b7)).length) (H : s.Nonempty) :\n    (s.sort (\u00b7 \u2264 \u00b7)).nthLe 0 h = s.min' H := by\n  let l := s.sort (\u00b7 \u2264 \u00b7)\n  apply le_antisymm\n  \u00b7 have : s.min' H \u2208 l := (Finset.mem_sort (\u03b1 := \u03b1) (\u00b7 \u2264 \u00b7)).mpr (s.min'_mem H)\n    obtain \u27e8i, hi\u27e9 : \u2203 i, l.get i = s.min' H := List.mem_iff_get.1 this\n    rw [\u2190 hi]\n    exact (s.sort_sorted (\u00b7 \u2264 \u00b7)).rel_nthLe_of_le _ _ (Nat.zero_le i)\n  \u00b7 have : l.get \u27e80, h\u27e9 \u2208 s := (Finset.mem_sort (\u03b1 := \u03b1) (\u00b7 \u2264 \u00b7)).1 (List.get_mem l 0 h)\n    exact s.min'_le _ this\n#align finset.sorted_zero_eq_min'_aux Finset.sorted_zero_eq_min'_aux\n\ntheorem sorted_zero_eq_min' {s : Finset \u03b1} {h : 0 < (s.sort (\u00b7 \u2264 \u00b7)).length} :\n    (s.sort (\u00b7 \u2264 \u00b7)).nthLe 0 h = s.min' (card_pos.1 <| by rwa [length_sort] at h) :=\n  sorted_zero_eq_min'_aux _ _ _\n#align finset.sorted_zero_eq_min' Finset.sorted_zero_eq_min'\n\ntheorem min'_eq_sorted_zero {s : Finset \u03b1} {h : s.Nonempty} :\n    s.min' h = (s.sort (\u00b7 \u2264 \u00b7)).nthLe 0 (by rw [length_sort]; exact card_pos.2 h) :=\n  (sorted_zero_eq_min'_aux _ _ _).symm\n#align finset.min'_eq_sorted_zero Finset.min'_eq_sorted_zero\n\ntheorem sorted_last_eq_max'_aux (s : Finset \u03b1)\n    (h : (s.sort (\u00b7 \u2264 \u00b7)).length - 1 < (s.sort (\u00b7 \u2264 \u00b7)).length) (H : s.Nonempty) :\n    (s.sort (\u00b7 \u2264 \u00b7)).nthLe ((s.sort (\u00b7 \u2264 \u00b7)).length - 1) h = s.max' H := by\n  let l := s.sort (\u00b7 \u2264 \u00b7)\n  apply le_antisymm\n  \u00b7 have : l.get \u27e8(s.sort (\u00b7 \u2264 \u00b7)).length - 1, h\u27e9 \u2208 s :=\n      (Finset.mem_sort (\u03b1 := \u03b1) (\u00b7 \u2264 \u00b7)).1 (List.get_mem l _ h)\n    exact s.le_max' _ this\n  \u00b7 have : s.max' H \u2208 l := (Finset.mem_sort (\u03b1 := \u03b1) (\u00b7 \u2264 \u00b7)).mpr (s.max'_mem H)\n    obtain \u27e8i, hi\u27e9 : \u2203 i, l.get i = s.max' H := List.mem_iff_get.1 this\n    rw [\u2190 hi]\n    exact (s.sort_sorted (\u00b7 \u2264 \u00b7)).rel_nthLe_of_le _ _ (Nat.le_pred_of_lt i.prop)\n#align finset.sorted_last_eq_max'_aux Finset.sorted_last_eq_max'_aux\n\ntheorem sorted_last_eq_max' {s : Finset \u03b1}\n    {h : (s.sort (\u00b7 \u2264 \u00b7)).length - 1 < (s.sort (\u00b7 \u2264 \u00b7)).length} :\n    (s.sort (\u00b7 \u2264 \u00b7)).nthLe ((s.sort (\u00b7 \u2264 \u00b7)).length - 1) h =\n      s.max' (by rw [length_sort] at h; exact card_pos.1 (lt_of_le_of_lt bot_le h)) :=\n  sorted_last_eq_max'_aux _ _ _\n#align finset.sorted_last_eq_max' Finset.sorted_last_eq_max'\n\ntheorem max'_eq_sorted_last {s : Finset \u03b1} {h : s.Nonempty} :\n    s.max' h =\n      (s.sort (\u00b7 \u2264 \u00b7)).nthLe ((s.sort (\u00b7 \u2264 \u00b7)).length - 1)\n        (by simpa using Nat.sub_lt (card_pos.mpr h) zero_lt_one) :=\n  (sorted_last_eq_max'_aux _ _ _).symm\n#align finset.max'_eq_sorted_last Finset.max'_eq_sorted_last\n\n/-- Given a finset `s` of cardinality `k` in a linear order `\u03b1`, the map `orderIsoOfFin s h`\nis the increasing bijection between `Fin k` and `s` as an `OrderIso`. Here, `h` is a proof that\nthe cardinality of `s` is `k`. We use this instead of an iso `Fin s.card \u2243o s` to avoid\ncasting issues in further uses of this function. -/\ndef orderIsoOfFin (s : Finset \u03b1) {k : \u2115} (h : s.card = k) : Fin k \u2243o s :=\n  OrderIso.trans (Fin.cast ((length_sort (\u03b1 := \u03b1) (\u00b7 \u2264 \u00b7)).trans h).symm) <|\n    (s.sort_sorted_lt.getIso _).trans <| OrderIso.setCongr _ _ <| Set.ext fun _ => mem_sort _\n#align finset.order_iso_of_fin Finset.orderIsoOfFin\n\n/-- Given a finset `s` of cardinality `k` in a linear order `\u03b1`, the map `orderEmbOfFin s h` is\nthe increasing bijection between `Fin k` and `s` as an order embedding into `\u03b1`. Here, `h` is a\nproof that the cardinality of `s` is `k`. We use this instead of an embedding `Fin s.card \u21aao \u03b1` to\navoid casting issues in further uses of this function. -/\ndef orderEmbOfFin (s : Finset \u03b1) {k : \u2115} (h : s.card = k) : Fin k \u21aao \u03b1 :=\n  (orderIsoOfFin s h).toOrderEmbedding.trans (OrderEmbedding.subtype _)\n#align finset.order_emb_of_fin Finset.orderEmbOfFin\n\n@[simp]\ntheorem coe_orderIsoOfFin_apply (s : Finset \u03b1) {k : \u2115} (h : s.card = k) (i : Fin k) :\n    \u2191(orderIsoOfFin s h i) = orderEmbOfFin s h i :=\n  rfl\n#align finset.coe_order_iso_of_fin_apply Finset.coe_orderIsoOfFin_apply\n\ntheorem orderIsoOfFin_symm_apply (s : Finset \u03b1) {k : \u2115} (h : s.card = k) (x : s) :\n    \u2191((s.orderIsoOfFin h).symm x) = (s.sort (\u00b7 \u2264 \u00b7)).indexOf \u2191x :=\n  rfl\n#align finset.order_iso_of_fin_symm_apply Finset.orderIsoOfFin_symm_apply\n\ntheorem orderEmbOfFin_apply (s : Finset \u03b1) {k : \u2115} (h : s.card = k) (i : Fin k) :\n    s.orderEmbOfFin h i =\n      (s.sort (\u00b7 \u2264 \u00b7)).nthLe i (by rw [length_sort, h]; exact i.2) :=\n  rfl\n#align finset.order_emb_of_fin_apply Finset.orderEmbOfFin_apply\n\n@[simp]\ntheorem orderEmbOfFin_mem (s : Finset \u03b1) {k : \u2115} (h : s.card = k) (i : Fin k) :\n    s.orderEmbOfFin h i \u2208 s :=\n  (s.orderIsoOfFin h i).2\n#align finset.order_emb_of_fin_mem Finset.orderEmbOfFin_mem\n\n@[simp]\ntheorem range_orderEmbOfFin (s : Finset \u03b1) {k : \u2115} (h : s.card = k) :\n    Set.range (s.orderEmbOfFin h) = s := by\n  simp only [orderEmbOfFin, Set.range_comp ((\u2191) : _ \u2192 \u03b1) (s.orderIsoOfFin h),\n  RelEmbedding.coe_trans, Set.image_univ, Finset.orderEmbOfFin, RelIso.range_eq,\n    OrderEmbedding.subtype_apply, OrderIso.coe_toOrderEmbedding, eq_self_iff_true,\n    Subtype.range_coe_subtype, Finset.setOf_mem, Finset.coe_inj]\n#align finset.range_order_emb_of_fin Finset.range_orderEmbOfFin\n\n/-- The bijection `orderEmbOfFin s h` sends `0` to the minimum of `s`. -/\ntheorem orderEmbOfFin_zero {s : Finset \u03b1} {k : \u2115} (h : s.card = k) (hz : 0 < k) :\n    orderEmbOfFin s h \u27e80, hz\u27e9 = s.min' (card_pos.mp (h.symm \u25b8 hz)) := by\n  simp only [orderEmbOfFin_apply, Fin.val_mk, sorted_zero_eq_min']\n#align finset.order_emb_of_fin_zero Finset.orderEmbOfFin_zero\n\n/-- The bijection `orderEmbOfFin s h` sends `k-1` to the maximum of `s`. -/\ntheorem orderEmbOfFin_last {s : Finset \u03b1} {k : \u2115} (h : s.card = k) (hz : 0 < k) :\n    orderEmbOfFin s h \u27e8k - 1, Nat.sub_lt hz (Nat.succ_pos 0)\u27e9 =\n      s.max' (card_pos.mp (h.symm \u25b8 hz)) := by\n  simp [orderEmbOfFin_apply, max'_eq_sorted_last, h]\n#align finset.order_emb_of_fin_last Finset.orderEmbOfFin_last\n\n/-- `orderEmbOfFin {a} h` sends any argument to `a`. -/\n@[simp]\ntheorem orderEmbOfFin_singleton (a : \u03b1) (i : Fin 1) :\n    orderEmbOfFin {a} (card_singleton a) i = a := by\n  rw [Subsingleton.elim i \u27e80, zero_lt_one\u27e9, orderEmbOfFin_zero _ zero_lt_one, min'_singleton]\n#align finset.order_emb_of_fin_singleton Finset.orderEmbOfFin_singleton\n\n/-- Any increasing map `f` from `Fin k` to a finset of cardinality `k` has to coincide with\nthe increasing bijection `orderEmbOfFin s h`. -/\ntheorem orderEmbOfFin_unique {s : Finset \u03b1} {k : \u2115} (h : s.card = k) {f : Fin k \u2192 \u03b1}\n    (hfs : \u2200 x, f x \u2208 s) (hmono : StrictMono f) : f = s.orderEmbOfFin h := by\n  apply Fin.strictMono_unique hmono (s.orderEmbOfFin h).strictMono\n  rw [range_orderEmbOfFin, \u2190 Set.image_univ, \u2190 coe_univ, \u2190 coe_image, coe_inj]\n  refine' eq_of_subset_of_card_le (fun x hx => _) _\n  \u00b7 rcases mem_image.1 hx with \u27e8x, _, rfl\u27e9\n    exact hfs x\n  \u00b7 rw [h, card_image_of_injective _ hmono.injective, card_univ, Fintype.card_fin]\n#align finset.order_emb_of_fin_unique Finset.orderEmbOfFin_unique\n\n/-- An order embedding `f` from `Fin k` to a finset of cardinality `k` has to coincide with\nthe increasing bijection `orderEmbOfFin s h`. -/\n\n\n/-- Two parametrizations `orderEmbOfFin` of the same set take the same value on `i` and `j` if\nand only if `i = j`. Since they can be defined on a priori not defeq types `Fin k` and `Fin l`\n(although necessarily `k = l`), the conclusion is rather written `(i : \u2115) = (j : \u2115)`. -/\n@[simp]\ntheorem orderEmbOfFin_eq_orderEmbOfFin_iff {k l : \u2115} {s : Finset \u03b1} {i : Fin k} {j : Fin l}\n    {h : s.card = k} {h' : s.card = l} :\n    s.orderEmbOfFin h i = s.orderEmbOfFin h' j \u2194 (i : \u2115) = (j : \u2115) := by\n  substs k l\n  exact (s.orderEmbOfFin rfl).eq_iff_eq.trans Fin.ext_iff\n#align\n  finset.order_emb_of_fin_eq_order_emb_of_fin_iff Finset.orderEmbOfFin_eq_orderEmbOfFin_iff\n\n/-- Given a finset `s` of size at least `k` in a linear order `\u03b1`, the map `orderEmbOfCardLe`\nis an order embedding from `Fin k` to `\u03b1` whose image is contained in `s`. Specifically, it maps\n`Fin k` to an initial segment of `s`. -/\ndef orderEmbOfCardLe (s : Finset \u03b1) {k : \u2115} (h : k \u2264 s.card) : Fin k \u21aao \u03b1 :=\n  (Fin.castLe h).trans (s.orderEmbOfFin rfl)\n#align finset.order_emb_of_card_le Finset.orderEmbOfCardLe\n\ntheorem orderEmbOfCardLe_mem (s : Finset \u03b1) {k : \u2115} (h : k \u2264 s.card) (a) :\n    orderEmbOfCardLe s h a \u2208 s := by\n  simp only [orderEmbOfCardLe, RelEmbedding.coe_trans, Finset.orderEmbOfFin_mem,\n    Function.comp_apply]\n#align finset.order_emb_of_card_le_mem Finset.orderEmbOfCardLe_mem\n\nend SortLinearOrder\n\nunsafe instance [Repr \u03b1] : Repr (Finset \u03b1) :=\n  \u27e8fun s _ => repr s.1\u27e9\n\nend Finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Finset/Sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7339898745575018}}
{"text": "/-\nCopyright (c) 2019 Rohan Mitta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport analysis.specific_limits\nimport data.setoid.basic\nimport dynamics.fixed_points.topology\n\n/-!\n# Contracting maps\n\nA Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*.\nIn this file we prove the Banach fixed point theorem, some explicit estimates on the rate\nof convergence, and some properties of the map sending a contracting map to its fixed point.\n\n## Main definitions\n\n* `contracting_with K f` : a Lipschitz continuous self-map with `K < 1`;\n* `efixed_point` : given a contracting map `f` on a complete emetric space and a point `x`\n  such that `edist x (f x) < \u221e`, `efixed_point f hf x hx` is the unique fixed point of `f`\n  in `emetric.ball x \u221e`;\n* `fixed_point` : the unique fixed point of a contracting map on a complete nonempty metric space.\n\n## Tags\n\ncontracting map, fixed point, Banach fixed point theorem\n-/\n\nopen_locale nnreal topological_space classical ennreal\nopen filter function\n\nvariables {\u03b1 : Type*}\n\n/-- A map is said to be `contracting_with K`, if `K < 1` and `f` is `lipschitz_with K`. -/\ndef contracting_with [emetric_space \u03b1] (K : \u211d\u22650) (f : \u03b1 \u2192 \u03b1) :=\n(K < 1) \u2227 lipschitz_with K f\n\nnamespace contracting_with\n\nvariables [emetric_space \u03b1] [cs : complete_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1}\n\nopen emetric set\n\nlemma to_lipschitz_with (hf : contracting_with K f) : lipschitz_with K f := hf.2\n\nlemma one_sub_K_pos' (hf : contracting_with K f) : (0:\u211d\u22650\u221e) < 1 - K := by simp [hf.1]\n\nlemma one_sub_K_ne_zero (hf : contracting_with K f) : (1:\u211d\u22650\u221e) - K \u2260 0 :=\nne_of_gt hf.one_sub_K_pos'\n\nlemma one_sub_K_ne_top : (1:\u211d\u22650\u221e) - K \u2260 \u22a4 :=\nby { norm_cast, exact ennreal.coe_ne_top }\n\nlemma edist_inequality (hf : contracting_with K f) {x y} (h : edist x y < \u22a4) :\n  edist x y \u2264 (edist x (f x) + edist y (f y)) / (1 - K) :=\nsuffices edist x y \u2264 edist x (f x) + edist y (f y) + K * edist x y,\n  by rwa [ennreal.le_div_iff_mul_le (or.inl hf.one_sub_K_ne_zero) (or.inl one_sub_K_ne_top),\n    mul_comm, ennreal.sub_mul (\u03bb _ _, ne_of_lt h), one_mul, ennreal.sub_le_iff_le_add],\ncalc edist x y \u2264 edist x (f x) + edist (f x) (f y) + edist (f y) y : edist_triangle4 _ _ _ _\n  ... = edist x (f x) + edist y (f y) + edist (f x) (f y) : by rw [edist_comm y, add_right_comm]\n  ... \u2264 edist x (f x) + edist y (f y) + K * edist x y : add_le_add (le_refl _) (hf.2 _ _)\n\nlemma edist_le_of_fixed_point (hf : contracting_with K f) {x y}\n  (h : edist x y < \u22a4) (hy : is_fixed_pt f y) :\n  edist x y \u2264 (edist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h\n\nlemma eq_or_edist_eq_top_of_fixed_points (hf : contracting_with K f) {x y}\n  (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) :\n  x = y \u2228 edist x y = \u22a4 :=\nbegin\n  cases eq_or_lt_of_le (le_top : edist x y \u2264 \u22a4), from or.inr h,\n  refine or.inl (edist_le_zero.1 _),\n  simpa only [hx.eq, edist_self, add_zero, ennreal.zero_div]\n    using hf.edist_le_of_fixed_point h hy\nend\n\n/-- If a map `f` is `contracting_with K`, and `s` is a forward-invariant set, then\nrestriction of `f` to `s` is `contracting_with K` as well. -/\nlemma restrict (hf : contracting_with K f) {s : set \u03b1} (hs : maps_to f s s) :\n  contracting_with K (hs.restrict f s s) :=\n\u27e8hf.1, \u03bb x y, hf.2 x y\u27e9\n\ninclude cs\n\n/-- Banach fixed-point theorem, contraction mapping theorem, `emetric_space` version.\nA contracting map on a complete metric space has a fixed point.\nWe include more conclusions in this theorem to avoid proving them again later.\n\nThe main API for this theorem are the functions `efixed_point` and `fixed_point`,\nand lemmas about these functions. -/\ntheorem exists_fixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) < \u22a4) :\n  \u2203 y, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nhave cauchy_seq (\u03bb n, f^[n] x),\nfrom cauchy_seq_of_edist_le_geometric K (edist x (f x)) (ennreal.coe_lt_one_iff.2 hf.1)\n  (ne_of_lt hx) (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x),\nlet \u27e8y, hy\u27e9 := cauchy_seq_tendsto_of_complete this in\n\u27e8y, is_fixed_pt_of_tendsto_iterate hy hf.2.continuous.continuous_at, hy,\n  edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x))\n    (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x) hy\u27e9\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map,\nand `edist x (f x) < \u221e`. Then `efixed_point` is the unique fixed point of `f`\nin `emetric.ball x \u221e`. -/\nnoncomputable def efixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) < \u22a4) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point x hx\n\nvariables {f}\n\nlemma efixed_point_is_fixed_pt (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) < \u22a4) :\n  is_fixed_pt f (efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).1\n\nlemma tendsto_iterate_efixed_point (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) < \u22a4) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.1\n\nlemma apriori_edist_iterate_efixed_point_le (hf : contracting_with K f)\n  {x : \u03b1} (hx : edist x (f x) < \u22a4) (n : \u2115) :\n  edist (f^[n] x) (efixed_point f hf x hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.2 n\n\nlemma edist_efixed_point_le (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) < \u22a4) :\n  edist x (efixed_point f hf x hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le hx 0, simp only [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) < \u22a4) :\n  edist x (efixed_point f hf x hx) < \u22a4 :=\nlt_of_le_of_lt (hf.edist_efixed_point_le hx) (ennreal.mul_lt_top hx $\n  ennreal.lt_top_iff_ne_top.2 $ ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\nlemma efixed_point_eq_of_edist_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) < \u22a4)\n  {y : \u03b1} (hy : edist y (f y) < \u22a4) (h : edist x y < \u22a4) :\n  efixed_point f hf x hx = efixed_point f hf y hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, exact hf.edist_efixed_point_lt_top hx },\n  transitivity y,\n  exacts [h, hf.edist_efixed_point_lt_top hy]\nend\n\nomit cs\n\n/-- Banach fixed-point theorem for maps contracting on a complete subset. -/\ntheorem exists_fixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4) :\n  \u2203 y \u2208 s, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nbegin\n  haveI := hsc.complete_space_coe,\n  rcases hf.exists_fixed_point \u27e8x, hxs\u27e9 hx with \u27e8y, hfy, h_tendsto, hle\u27e9,\n  refine \u27e8y, y.2, subtype.ext_iff_val.1 hfy, _, \u03bb n, _\u27e9,\n  { convert (continuous_subtype_coe.tendsto _).comp h_tendsto, ext n,\n    simp only [(\u2218), maps_to.iterate_restrict, maps_to.coe_restrict_apply, subtype.coe_mk] },\n  { convert hle n,\n    rw [maps_to.iterate_restrict, eq_comm, maps_to.coe_restrict_apply, subtype.coe_mk] }\nend\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s`\nand `x \u2208 s` satisfies `edist x (f x) < \u22a4`, then `efixed_point'` is the unique fixed point\nof the restriction of `f` to `s \u2229 emetric.ball x \u22a4`. -/\nnoncomputable def efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) (x : \u03b1) (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point' hsc hsf hxs hx\n\nvariables {f}\n\nlemma efixed_point_mem' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4) :\n  efixed_point' f hsc hsf hf x hxs hx \u2208 s :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).fst\n\nlemma efixed_point_is_fixed_pt' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4) :\n  is_fixed_pt f (efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.1\n\nlemma tendsto_iterate_efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.1\n\nlemma apriori_edist_iterate_efixed_point_le' {s : set \u03b1} (hsc : is_complete s)\n  (hsf : maps_to f s s) (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s)\n  (hx : edist x (f x) < \u22a4) (n : \u2115) :\n  edist (f^[n] x) (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.2 n\n\nlemma edist_efixed_point_le' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le' hsc hsf hxs hx 0,\n  rw [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) < \u22a4 :=\nlt_of_le_of_lt (hf.edist_efixed_point_le' hsc hsf hxs hx) (ennreal.mul_lt_top hx $\n  ennreal.lt_top_iff_ne_top.2 $ ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\n/-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`,\nand `x \u2208 s` is at a finite distance from `y \u2208 t`, then the `efixed_point'` constructed by `x`\nis the same as the `efixed_point'` constructed by `y`.\n\nThis lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way\nit can be used to prove the desired equality with non-trivial proofs of these facts. -/\nlemma efixed_point_eq_of_edist_lt_top' (hf : contracting_with K f)\n  {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hfs : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) < \u22a4)\n  {t : set \u03b1} (htc : is_complete t) (htf : maps_to f t t)\n  (hft : contracting_with K $ htf.restrict f t t) {y : \u03b1} (hyt : y \u2208 t) (hy : edist y (f y) < \u22a4)\n  (hxy : edist x y < \u22a4) :\n  efixed_point' f hsc hsf hfs x hxs hx = efixed_point' f htc htf hft y hyt hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt' },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, apply edist_efixed_point_lt_top' },\n  transitivity y,\n  exact hxy,\n  apply edist_efixed_point_lt_top'\nend\n\nend contracting_with\n\nnamespace contracting_with\n\nvariables [metric_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1} (hf : contracting_with K f)\ninclude hf\n\nlemma one_sub_K_pos (hf : contracting_with K f) : (0:\u211d) < 1 - K := sub_pos.2 hf.1\n\nlemma dist_le_mul (x y : \u03b1) : dist (f x) (f y) \u2264 K * dist x y :=\nhf.to_lipschitz_with.dist_le_mul x y\n\nlemma dist_inequality (x y) : dist x y \u2264 (dist x (f x) + dist y (f y)) / (1 - K) :=\nsuffices dist x y \u2264 dist x (f x) + dist y (f y) + K * dist x y,\n  by rwa [le_div_iff hf.one_sub_K_pos, mul_comm, sub_mul, one_mul, sub_le_iff_le_add],\ncalc dist x y \u2264 dist x (f x) + dist y (f y) + dist (f x) (f y) : dist_triangle4_right _ _ _ _\n          ... \u2264 dist x (f x) + dist y (f y) + K * dist x y :\n  add_le_add_left (hf.dist_le_mul _ _) _\n\nlemma dist_le_of_fixed_point (x) {y} (hy : is_fixed_pt f y) :\n  dist x y \u2264 (dist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, dist_self, add_zero] using hf.dist_inequality x y\n\ntheorem fixed_point_unique' {x y} (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) : x = y :=\n(hf.eq_or_edist_eq_top_of_fixed_points hx hy).resolve_right (edist_ne_top _ _)\n\n/-- Let `f` be a contracting map with constant `K`; let `g` be another map uniformly\n`C`-close to `f`. If `x` and `y` are their fixed points, then `dist x y \u2264 C / (1 - K)`. -/\n\n\nnoncomputable theory\n\nvariables [nonempty \u03b1] [complete_space \u03b1]\n\nvariable (f)\n/-- The unique fixed point of a contracting map in a nonempty complete metric space. -/\ndef fixed_point : \u03b1 :=\nefixed_point f hf _ (edist_lt_top (classical.choice \u2039nonempty \u03b1\u203a) _)\nvariable {f}\n\n/-- The point provided by `contracting_with.fixed_point` is actually a fixed point. -/\nlemma fixed_point_is_fixed_pt : is_fixed_pt f (fixed_point f hf) :=\nhf.efixed_point_is_fixed_pt _\n\nlemma fixed_point_unique {x} (hx : is_fixed_pt f x) : x = fixed_point f hf :=\nhf.fixed_point_unique' hx hf.fixed_point_is_fixed_pt\n\nlemma dist_fixed_point_le (x) : dist x (fixed_point f hf) \u2264 (dist x (f x)) / (1 - K) :=\nhf.dist_le_of_fixed_point x hf.fixed_point_is_fixed_pt\n\n/-- Aposteriori estimates on the convergence of iterates to the fixed point. -/\nlemma aposteriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist (f^[n] x) (f^[n+1] x)) / (1 - K) :=\nby { rw [iterate_succ'], apply hf.dist_fixed_point_le }\n\nlemma apriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist x (f x)) * K^n / (1 - K) :=\nle_trans (hf.aposteriori_dist_iterate_fixed_point_le x n) $\n  (div_le_div_right hf.one_sub_K_pos).2 $\n    hf.to_lipschitz_with.dist_iterate_succ_le_geometric x n\n\nlemma tendsto_iterate_fixed_point (x) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ fixed_point f hf) :=\nbegin\n  convert tendsto_iterate_efixed_point hf (edist_lt_top x _),\n  refine (fixed_point_unique _ _).symm,\n  apply efixed_point_is_fixed_pt\nend\n\nlemma fixed_point_lipschitz_in_map {g : \u03b1 \u2192 \u03b1} (hg : contracting_with K g)\n  {C} (hfg : \u2200 z, dist (f z) (g z) \u2264 C) :\n  dist (fixed_point f hf) (fixed_point g hg) \u2264 C / (1 - K) :=\nhf.dist_fixed_point_fixed_point_of_dist_le' g hf.fixed_point_is_fixed_pt\n  hg.fixed_point_is_fixed_pt hfg\n\nend contracting_with\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/topology/metric_space/contracting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7339898727345227}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Mario Carneiro\n-/\n\nprelude\nimport init.data.nat.lemmas init.meta.well_founded_tactics\n\nuniverse u\n\nnamespace nat\n\ndef bodd_div2 : \u2115 \u2192 bool \u00d7 \u2115\n| 0        := (ff, 0)\n| (succ n) :=\n    match bodd_div2 n with\n    | (ff, m) := (tt, m)\n    | (tt, m) := (ff, succ m)\n    end\n\ndef div2 (n : \u2115) : \u2115 := (bodd_div2 n).2\n\ndef bodd (n : \u2115) : bool := (bodd_div2 n).1\n\n@[simp] lemma bodd_zero : bodd 0 = ff := rfl\nlemma bodd_one : bodd 1 = tt := rfl\nlemma bodd_two : bodd 2 = ff := rfl\n\n@[simp] lemma bodd_succ (n : \u2115) : bodd (succ n) = bnot (bodd n) :=\nby unfold bodd bodd_div2; cases bodd_div2 n; cases fst; refl\n\n@[simp] lemma bodd_add (m n : \u2115) : bodd (m + n) = bxor (bodd m) (bodd n) :=\nbegin\n    induction n with n IH,\n    { simp, cases bodd m; refl },\n    { simp [add_succ, IH], cases bodd m; cases bodd n; refl }\nend\n\n@[simp] lemma bodd_mul (m n : \u2115) : bodd (m * n) = bodd m && bodd n :=\nbegin\n    induction n with n IH,\n    { simp, cases bodd m; refl },\n    { simp [mul_succ, IH], cases bodd m; cases bodd n; refl }\nend\n\nlemma mod_two_of_bodd (n : \u2115) : n % 2 = cond (bodd n) 1 0 :=\nbegin\n    have := congr_arg bodd (mod_add_div n 2),\n    simp [bnot] at this,\n    rw [show \u2200 b, ff && b = ff, by intros; cases b; refl,\n        show \u2200 b, bxor b ff = b, by intros; cases b; refl] at this,\n    rw [\u2190 this],\n    cases mod_two_eq_zero_or_one n with h h; rw h; refl\nend\n\n@[simp] lemma div2_zero : div2 0 = 0 := rfl\nlemma div2_one : div2 1 = 0 := rfl\nlemma div2_two : div2 2 = 1 := rfl\n\n@[simp] lemma div2_succ (n : \u2115) : div2 (succ n) = cond (bodd n) (succ (div2 n)) (div2 n) :=\nby unfold bodd div2 bodd_div2; cases bodd_div2 n; cases fst; refl\n\nlocal attribute [simp] nat.add_comm nat.add_assoc nat.add_left_comm nat.mul_comm nat.mul_assoc\n\ntheorem bodd_add_div2 : \u2200 n, cond (bodd n) 1 0 + 2 * div2 n = n\n| 0        := rfl\n| (succ n) := begin\n    simp,\n    refine eq.trans _ (congr_arg succ (bodd_add_div2 n)),\n    cases bodd n; simp [cond, bnot],\n    { rw [nat.add_comm, nat.zero_add], },\n    { rw [succ_mul, nat.add_comm 1, nat.zero_add] }\nend\n\ntheorem div2_val (n) : div2 n = n / 2 :=\nbegin\n  refine nat.eq_of_mul_eq_mul_left dec_trivial\n      (nat.add_left_cancel (eq.trans _ (nat.mod_add_div n 2).symm)),\n  rw [mod_two_of_bodd, bodd_add_div2]\nend\n\ndef bit (b : bool) : \u2115 \u2192 \u2115 := cond b bit1 bit0\n\nlemma bit0_val (n : nat) : bit0 n = 2 * n :=\ncalc n + n = 0 + n + n : by rw nat.zero_add\n       ... = n * 2 : rfl\n       ... = 2 * n : nat.mul_comm _ _\n\nlemma bit1_val (n : nat) : bit1 n = 2 * n + 1 := congr_arg succ (bit0_val _)\n\nlemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 :=\nby { cases b, apply bit0_val, apply bit1_val }\n\nlemma bit_decomp (n : nat) : bit (bodd n) (div2 n) = n :=\n(bit_val _ _).trans $ (nat.add_comm _ _).trans $ bodd_add_div2 _\n\ndef bit_cases_on {C : nat \u2192 Sort u} (n) (h : \u2200 b n, C (bit b n)) : C n :=\nby rw [\u2190 bit_decomp n]; apply h\n\nlemma bit_zero : bit ff 0 = 0 := rfl\n\ndef shiftl' (b : bool) (m : \u2115) : \u2115 \u2192 \u2115\n| 0     := m\n| (n+1) := bit b (shiftl' n)\n\ndef shiftl : \u2115 \u2192 \u2115 \u2192 \u2115 := shiftl' ff\n\n@[simp] theorem shiftl_zero (m) : shiftl m 0 = m := rfl\n@[simp] theorem shiftl_succ (m n) : shiftl m (n + 1) = bit0 (shiftl m n) := rfl\n\ndef shiftr : \u2115 \u2192 \u2115 \u2192 \u2115\n| m 0     := m\n| m (n+1) := div2 (shiftr m n)\n\ndef test_bit (m n : \u2115) : bool := bodd (shiftr m n)\n\ndef binary_rec {C : nat \u2192 Sort u} (z : C 0) (f : \u2200 b n, C n \u2192 C (bit b n)) : \u03a0 n, C n\n| n := if n0 : n = 0 then by rw n0; exact z else let n' := div2 n in\n    have n' < n, begin\n      change div2 n < n, rw div2_val,\n      apply (div_lt_iff_lt_mul _ _ (succ_pos 1)).2,\n      have := nat.mul_lt_mul_of_pos_left (lt_succ_self 1)\n        (lt_of_le_of_ne n.zero_le (ne.symm n0)),\n      rwa nat.mul_one at this\n    end,\n    by rw [\u2190 show bit (bodd n) n' = n, from bit_decomp n]; exact\n    f (bodd n) n' (binary_rec n')\n\ndef size : \u2115 \u2192 \u2115 := binary_rec 0 (\u03bb_ _, succ)\n\ndef bits : \u2115 \u2192 list bool := binary_rec [] (\u03bbb _ IH, b :: IH)\n\ndef bitwise (f : bool \u2192 bool \u2192 bool) : \u2115 \u2192 \u2115 \u2192 \u2115 :=\nbinary_rec\n    (\u03bbn, cond (f ff tt) n 0)\n    (\u03bba m Ia, binary_rec\n      (cond (f tt ff) (bit a m) 0)\n      (\u03bbb n _, bit (f a b) (Ia n)))\n\ndef lor   : \u2115 \u2192 \u2115 \u2192 \u2115 := bitwise bor\ndef land  : \u2115 \u2192 \u2115 \u2192 \u2115 := bitwise band\ndef ldiff : \u2115 \u2192 \u2115 \u2192 \u2115 := bitwise (\u03bb a b, a && bnot b)\ndef lxor  : \u2115 \u2192 \u2115 \u2192 \u2115 := bitwise bxor\n\n@[simp] lemma binary_rec_zero {C : nat \u2192 Sort u} (z : C 0) (f : \u2200 b n, C n \u2192 C (bit b n)) :\n    binary_rec z f 0 = z :=\nby {rw [binary_rec], refl}\n\n/- bitwise ops -/\n\nlemma bodd_bit (b n) : bodd (bit b n) = b :=\nby rw bit_val; simp; cases b; cases bodd n; refl\n\nlemma div2_bit (b n) : div2 (bit b n) = n :=\nby rw [bit_val, div2_val, nat.add_comm, add_mul_div_left, div_eq_of_lt, nat.zero_add];\n   cases b; exact dec_trivial\n\nlemma shiftl'_add (b m n) : \u2200 k, shiftl' b m (n + k) = shiftl' b (shiftl' b m n) k\n| 0     := rfl\n| (k+1) := congr_arg (bit b) (shiftl'_add k)\n\nlemma shiftl_add : \u2200 m n k, shiftl m (n + k) = shiftl (shiftl m n) k := shiftl'_add _\n\nlemma shiftr_add (m n) : \u2200 k, shiftr m (n + k) = shiftr (shiftr m n) k\n| 0     := rfl\n| (k+1) := congr_arg div2 (shiftr_add k)\n\nlemma shiftl'_sub (b m) : \u2200 {n k}, k \u2264 n \u2192 shiftl' b m (n - k) = shiftr (shiftl' b m n) k\n| n     0     h := rfl\n| (n+1) (k+1) h := begin\n  simp [shiftl'], rw [nat.add_comm, shiftr_add],\n  simp [shiftr, div2_bit],\n  apply shiftl'_sub (nat.le_of_succ_le_succ h)\nend\n\nlemma shiftl_sub : \u2200 m {n k}, k \u2264 n \u2192 shiftl m (n - k) = shiftr (shiftl m n) k := shiftl'_sub _\n\n@[simp] lemma test_bit_zero (b n) : test_bit (bit b n) 0 = b := bodd_bit _ _\n\nlemma test_bit_succ (m b n) : test_bit (bit b n) (succ m) = test_bit n m :=\nhave bodd (shiftr (shiftr (bit b n) 1) m) = bodd (shiftr n m),\n  by dsimp [shiftr]; rw div2_bit,\nby rw [\u2190 shiftr_add, nat.add_comm] at this; exact this\n\nlemma binary_rec_eq {C : nat \u2192 Sort u} {z : C 0} {f : \u2200 b n, C n \u2192 C (bit b n)}\n  (h : f ff 0 z = z) (b n) :\n  binary_rec z f (bit b n) = f b n (binary_rec z f n) :=\nbegin\n  rw [binary_rec],\n  with_cases { by_cases bit b n = 0 },\n  case pos : h' {\n    simp [dif_pos h'],\n    generalize : binary_rec._main._pack._proof_1 (bit b n) h' = e,\n    revert e,\n    have bf := bodd_bit b n,\n    have n0 := div2_bit b n,\n    rw h' at bf n0,\n    simp at bf n0,\n    rw [\u2190 bf, \u2190 n0, binary_rec_zero],\n    intros, exact h.symm },\n  case neg : h' {\n    simp [dif_neg h'],\n    generalize : binary_rec._main._pack._proof_2 (bit b n) = e,\n    revert e,\n    rw [bodd_bit, div2_bit],\n    intros, refl}\nend\n\nlemma bitwise_bit_aux {f : bool \u2192 bool \u2192 bool} (h : f ff ff = ff) :\n  @binary_rec (\u03bb_, \u2115)\n    (cond (f tt ff) (bit ff 0) 0)\n    (\u03bb b n _, bit (f ff b) (cond (f ff tt) n 0)) =\n  \u03bb (n : \u2115), cond (f ff tt) n 0 :=\nbegin\n  funext n,\n  apply bit_cases_on n, intros b n, rw [binary_rec_eq],\n  { cases b; try {rw h}; induction fft : f ff tt; simp [cond]; refl },\n  { rw [h, show cond (f ff tt) 0 0 = 0, by cases f ff tt; refl,\n           show cond (f tt ff) (bit ff 0) 0 = 0, by cases f tt ff; refl]; refl }\nend\n\n@[simp] lemma bitwise_zero_left (f : bool \u2192 bool \u2192 bool) (n) :\n  bitwise f 0 n = cond (f ff tt) n 0 :=\nby unfold bitwise; rw [binary_rec_zero]\n\n@[simp] lemma bitwise_zero_right (f : bool \u2192 bool \u2192 bool) (h : f ff ff = ff) (m) :\n  bitwise f m 0 = cond (f tt ff) m 0 :=\nby unfold bitwise; apply bit_cases_on m; intros;\n   rw [binary_rec_eq, binary_rec_zero]; exact bitwise_bit_aux h\n\n@[simp] lemma bitwise_zero (f : bool \u2192 bool \u2192 bool) :\n  bitwise f 0 0 = 0 :=\nby rw bitwise_zero_left; cases f ff tt; refl\n\n@[simp] lemma bitwise_bit {f : bool \u2192 bool \u2192 bool} (h : f ff ff = ff) (a m b n) :\n  bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=\nbegin\n  unfold bitwise,\n  rw [binary_rec_eq, binary_rec_eq],\n  { induction ftf : f tt ff; dsimp [cond],\n    rw [show f a ff = ff, by cases a; assumption],\n    apply @congr_arg _ _ _ 0 (bit ff), tactic.swap,\n    rw [show f a ff = a, by cases a; assumption],\n    apply congr_arg (bit a),\n    all_goals {\n      apply bit_cases_on m, intros a m,\n      rw [binary_rec_eq, binary_rec_zero],\n      rw [\u2190 bitwise_bit_aux h, ftf], refl } },\n  { exact bitwise_bit_aux h }\nend\n\ntheorem bitwise_swap {f : bool \u2192 bool \u2192 bool} (h : f ff ff = ff) :\n  bitwise (function.swap f) = function.swap (bitwise f) :=\nbegin\n  funext m n, revert n,\n  dsimp [function.swap],\n  apply binary_rec _ (\u03bb a m' IH, _) m; intro n,\n  { rw [bitwise_zero_left, bitwise_zero_right], exact h },\n  apply bit_cases_on n; intros b n',\n  rw [bitwise_bit, bitwise_bit, IH]; exact h\nend\n\n@[simp] lemma lor_bit : \u2200 (a m b n),\n  lor (bit a m) (bit b n) = bit (a || b) (lor m n) := bitwise_bit rfl\n@[simp] lemma land_bit : \u2200 (a m b n),\n  land (bit a m) (bit b n) = bit (a && b) (land m n) := bitwise_bit rfl\n@[simp] lemma ldiff_bit : \u2200 (a m b n),\n  ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) := bitwise_bit rfl\n@[simp] lemma lxor_bit : \u2200 (a m b n),\n  lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) := bitwise_bit rfl\n\n@[simp] lemma test_bit_bitwise {f : bool \u2192 bool \u2192 bool} (h : f ff ff = ff) (m n k) :\n  test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=\nbegin\n  revert m n; induction k with k IH; intros m n;\n  apply bit_cases_on m; intros a m';\n  apply bit_cases_on n; intros b n';\n  rw bitwise_bit h,\n  { simp [test_bit_zero] },\n  { simp [test_bit_succ, IH] }\nend\n\n@[simp] lemma test_bit_lor : \u2200 (m n k),\n  test_bit (lor m n) k = test_bit m k || test_bit n k := test_bit_bitwise rfl\n@[simp] lemma test_bit_land : \u2200 (m n k),\n  test_bit (land m n) k = test_bit m k && test_bit n k := test_bit_bitwise rfl\n@[simp] ", "meta": {"author": "subfish-zhou", "repo": "N2Lean", "sha": "8e858cc5b01f1ad921094dc355db3cb9473a42fd", "save_path": "github-repos/lean/subfish-zhou-N2Lean", "path": "github-repos/lean/subfish-zhou-N2Lean/N2Lean-8e858cc5b01f1ad921094dc355db3cb9473a42fd/library/init/data/nat/bitwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7339898714193522}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport data.real.basic\nimport analysis.calculus.parametric_integral\n\n/-\n\n# Smooth functions\n\n-/\n\nnoncomputable def \u03c6\u2081 : \u211d \u2192 \u211d \u00d7 \u211d := \n\u03bb x, (real.cos x, real.sin x)\n\n-- `cont_diff_on.prod` is a thing etc etc\nexample : cont_diff_on \u211d \u22a4 \u03c6\u2081 (set.Icc 0 1) :=\nbegin\n  sorry,\nend\n\nopen real\nnoncomputable def \u03c6\u2082 : \u211d \u2192 \u211d \u00d7 \u211d \u00d7 \u211d :=\n\u03bb x, (real.sin x, x^4+37*x^2+1, abs x)\n\nexample : cont_diff_on \u211d \u22a4 \u03c6\u2082 (set.Icc 0 1) :=\nsorry\n\n-- AFAIK nobody did the below example yet (including me)\n\n/- Let `a\u2264b` and `c\u2264d` be reals. Let \u03c6 : [a,b] \u2192 [c,d] and \u03c8 : [c,d] \u2192 [a,b]\n  be inverse bijections, and assume \u03c6 is smooth and \u03c6' is nonvanishing\n  on [a,b]. Then \u03c8 is smooth and \u03c8' is nonvanishing on [c,d],\n  and \u03c8'(y)*\u03c6'(\u03c8(y))=1.\n-/\nexample (\u03c6 : \u211d \u2192 \u211d) (\u03c8 : \u211d \u2192 \u211d) (a b c d : \u211d)\n  (hab : a \u2264 b) (hcd : c \u2264 d) (h\u03c6 : \u2200 x, x \u2208 set.Icc a b \u2192 \u03c6 x \u2208 set.Icc c d)\n  (h\u03c8 : \u2200 y, y \u2208 set.Icc c d \u2192 \u03c8 y \u2208 set.Icc a b)\n  (left_inv : \u2200 x, x \u2208 set.Icc a b \u2192 \u03c8 (\u03c6 x) = x)\n  (right_inv : \u2200 y, y \u2208 set.Icc c d \u2192 \u03c6 (\u03c8 y) = y)\n  (h\u03c6diff : cont_diff_on \u211d \u22a4 \u03c6 (set.Icc a b))\n  (h\u03c6regular : \u2200 x, x \u2208 set.Icc a b \u2192 fderiv \u211d \u03c6 x \u2260 0) :\n  cont_diff_on \u211d \u22a4 \u03c8 (set.Icc c d) \u2227\n  \u2200 y, y \u2208 set.Icc c d \u2192 \u2200 z, fderiv \u211d \u03c8 y (fderiv \u211d \u03c6 (\u03c8(y)) z) = z :=\nsorry\n\n/-\nHeather Macbeth: @Kevin Buzzard This is a toy case of the inverse function theorem, \nbut you might need to glue together several related results. Some starting points: \ndocs#cont_diff_at.to_local_inverse, docs#has_strict_fderiv_at.local_inverse_unique\n\nHeather Macbeth: If you want to construct the inverse, and you want to avoid invoking \nthe inverse function theorem on Banach spaces, you can also route through order theory \nfor a purely one-dimensional construction. Look at the construction of docs#real.arctan \nfor a model; it uses docs#strict_mono_on.order_iso\n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section17curves_and_surfaces/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8333245953120234, "lm_q1q2_score": 0.7339898685579316}}
{"text": "import data.list.sort\nimport data.list.basic\nimport data.multiset\nimport data.set\nimport tactic.induction\nimport tactic.ring\nimport algebra.order.field\nimport algebra.order.ring\nimport tactic.linarith\nimport init.default\n\nset_option trace.simplify.rewrite true\n\nvariable {\u03b1 : Type*}\nvariable r: \u03b1 \u2192 \u03b1 \u2192 Prop\nvariables xs ys: list \u03b1 \nvariable x: \u03b1 \n\n/-\nThis files contains some functions and lemmas that are predefined in __Function Algorithms, Verified!__ and the Isabelle code, \nbut not in Lean.\n-/\n\ndef list.to_set : list \u03b1 \u2192 set \u03b1 -- Source: chapter 10.6 Theorem Proving in Lean.\n| []     := \u2205\n| (h::t) := {h} \u222a list.to_set t\n\ndef multiset.to_set: multiset \u03b1 \u2192 set \u03b1 :=  \n\u03bb m: multiset \u03b1, {x: \u03b1 | x \u2208 m }\n\nlemma member_list_set : x \u2208 xs \u2194 x \u2208 xs.to_set :=\nbegin\n  induction' xs,\n  repeat { simp [list.to_set, *], },\nend\n\n/-\nThis definition follows the definition in __Functional Algorithms, Verified!__ \ninstead of using the predefined function sorted in Lean \nin order to follow the structure of the proofs.\n-/\ndef sorted' [is_linear_order \u03b1 r] : list \u03b1 \u2192 Prop \n| [] := true\n| (h::t) := (\u2200 y \u2208 t.to_set, r h y ) \u2227 sorted' t\n\nlemma set_mset_mset: multiset.to_set \u2191xs = list.to_set xs := \nbegin\n  induction' xs,\n  { refl},\n  { simp [list.to_set,\u2190 ih, multiset.to_set, set.insert_def] }\nend \n\nlemma mset_append : (\u2191 (xs ++ ys): multiset \u03b1) = \u2191 xs + \u2191 ys :=\nbegin\n  simp,\nend\n\nlemma set_append: (xs ++ ys).to_set = xs.to_set \u222a ys.to_set:=\nbegin\n  simp [\u2190 set_mset_mset, multiset.to_set],\n  refl,\nend\n\nlemma sorted'_append [is_linear_order \u03b1 r] : \n  sorted' r (xs ++ ys) \u2194 sorted' r xs \u2227 sorted' r ys \u2227 (\u2200 (x \u2208 xs), \u2200 (y \u2208 ys), r x y) :=\nbegin\n  induction' xs fixing *,\n  { simp [sorted']},\n  simp [sorted', ih, set_append],\n  apply iff.intro,\n  { intro h,\n    apply and.intro,\n    { apply and.intro,\n      { \n        intros,\n        exact h.left y (or.inl H), },\n      exact h.right.left},\n    apply and.intro,\n    { exact h.right.right.left},\n    apply and.intro,\n    { intros,\n      have h2: y \u2208 ys.to_set, from iff.elim_left (member_list_set ys y) H,\n      exact  h.left y (or.inr h2), },\n    exact h.right.right.right},\n  intro h,\n  apply and.intro,\n  { intros,\n    apply or.elim H,\n    { exact h.left.left y },\n    intro h1,\n    have h2: y \u2208 ys, from iff.elim_right (member_list_set ys y) h1,\n    exact h.right.right.left y h2 },\n  apply and.intro,\n  { exact h.left.right},\n  apply and.intro,\n  { exact h.right.left},\n  exact h.right.right.right\nend\n", "meta": {"author": "MaschavanderMarel", "repo": "bachelor_project", "sha": "7ace1dea38fc87bfe73367c3a84273886a7f92e3", "save_path": "github-repos/lean/MaschavanderMarel-bachelor_project", "path": "github-repos/lean/MaschavanderMarel-bachelor_project/bachelor_project-7ace1dea38fc87bfe73367c3a84273886a7f92e3/src/utilities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7339898667349524}}
{"text": "import data.real.basic\n\n#check sub_self\n#check abs_zero\n\ndef converges_to (s : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (s n - a) < \u03b5\n\ntheorem converges_to_const (a : \u211d) : converges_to (\u03bb x : \u2115, a) a :=\nbegin\n  intros \u03b5 epos,\n  dsimp,\n  rw sub_self,\n  norm_num, \n  use 0, \n  intros n nge,\n  exact epos, \nend\n\nexample (a : \u211d) : converges_to (\u03bb x : \u2115, a) a :=\nbegin\n  intros \u03b5 epos,\n  use 0,\n  intros n nge,\n  dsimp,\n  rw sub_self,\n  rw abs_zero,\n  apply epos,\nend\n", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/2_intro(s)/ex10_intro_vari_h_converge_const.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7339353118314165}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport combinatorics.set_family.harris_kleitman\nimport combinatorics.set_family.intersecting\n\n/-!\n# Kleitman's bound on the size of intersecting families\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nAn intersecting family on `n` elements has size at most `2\u207f\u207b\u00b9`, so we could na\u00efvely think that two\nintersecting families could cover all `2\u207f` sets. But actually that's not case because for example\nnone of them can contain the empty set. Intersecting families are in some sense correlated.\nKleitman's bound stipulates that `k` intersecting families cover at most `2\u207f - 2\u207f\u207b\u1d4f` sets.\n\n## Main declarations\n\n* `finset.card_bUnion_le_of_intersecting`: Kleitman's theorem.\n\n## References\n\n* [D. J. Kleitman, *Families of non-disjoint subsets*][kleitman1966]\n-/\n\nopen finset fintype (card)\n\nvariables {\u03b9 \u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1] [nonempty \u03b1]\n\n/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2\u207f\u207b\u00b9` sets, and\neach further intersecting family takes at most half of the sets that are in no previous family. -/\nlemma finset.card_bUnion_le_of_intersecting (s : finset \u03b9) (f : \u03b9 \u2192 finset (finset \u03b1))\n  (hf : \u2200 i \u2208 s, (f i : set (finset \u03b1)).intersecting) :\n  (s.bUnion f).card \u2264 2 ^ card \u03b1 - 2 ^ (card \u03b1 - s.card) :=\nbegin\n  obtain hs | hs := le_total (card \u03b1) s.card,\n  { rw [tsub_eq_zero_of_le hs, pow_zero],\n    refine (card_le_of_subset $  bUnion_subset.2 $ \u03bb i hi a ha, mem_compl.2 $ not_mem_singleton.2 $\n      (hf _ hi).ne_bot ha).trans_eq _,\n    rw [card_compl, fintype.card_finset, card_singleton] },\n  induction s using finset.cons_induction with i s hi ih generalizing f,\n  { simp },\n  classical,\n  set f' : \u03b9 \u2192 finset (finset \u03b1) := \u03bb j,\n    if hj : j \u2208 cons i s hi then (hf j hj).exists_card_eq.some else \u2205 with hf',\n  have hf\u2081 : \u2200 j, j \u2208 cons i s hi \u2192\n    f j \u2286 f' j \u2227 2 * (f' j).card = 2 ^ card \u03b1 \u2227 (f' j : set (finset \u03b1)).intersecting,\n  { rintro j hj,\n    simp_rw [hf', dif_pos hj, \u2190fintype.card_finset],\n    exact classical.some_spec (hf j hj).exists_card_eq },\n  have hf\u2082 : \u2200 j, j \u2208 cons i s hi \u2192 is_upper_set (f' j : set (finset \u03b1)),\n  { refine \u03bb j hj, (hf\u2081 _ hj).2.2.is_upper_set' ((hf\u2081 _ hj).2.2.is_max_iff_card_eq.2 _),\n    rw fintype.card_finset,\n    exact (hf\u2081 _ hj).2.1 },\n  refine (card_le_of_subset $ bUnion_mono $ \u03bb j hj, (hf\u2081 _ hj).1).trans _,\n  nth_rewrite 0 cons_eq_insert i,\n  rw bUnion_insert,\n  refine (card_mono $ @le_sup_sdiff _ _ _ $ f' i).trans ((card_union_le _ _).trans _),\n  rw [union_sdiff_left, sdiff_eq_inter_compl],\n  refine le_of_mul_le_mul_left _ (pow_pos zero_lt_two $ card \u03b1 + 1),\n  rw [pow_succ', mul_add, mul_assoc, mul_comm _ 2, mul_assoc],\n  refine (add_le_add ((mul_le_mul_left $ pow_pos (zero_lt_two' \u2115) _).2\n    (hf\u2081 _ $ mem_cons_self _ _).2.2.card_le) $ (mul_le_mul_left $ zero_lt_two' \u2115).2 $\n    is_upper_set.card_inter_le_finset _ _).trans _,\n  { rw coe_bUnion,\n    exact is_upper_set_Union\u2082 (\u03bb i hi, hf\u2082 _ $ subset_cons _ hi) },\n  { rw coe_compl,\n    exact (hf\u2082 _ $ mem_cons_self _ _).compl },\n  rw [mul_tsub, card_compl, fintype.card_finset, mul_left_comm, mul_tsub,\n    (hf\u2081 _ $ mem_cons_self _ _).2.1, two_mul, add_tsub_cancel_left, \u2190mul_tsub, \u2190mul_two, mul_assoc,\n    \u2190add_mul, mul_comm],\n  refine mul_le_mul_left' _ _,\n  refine (add_le_add_left (ih ((card_le_of_subset $ subset_cons _).trans hs) _ $ \u03bb i hi,\n    (hf\u2081 _ $ subset_cons _ hi).2.2) _).trans _,\n  rw [mul_tsub, two_mul, \u2190pow_succ, \u2190add_tsub_assoc_of_le (pow_le_pow' (one_le_two : (1 : \u2115) \u2264 2)\n    tsub_le_self), tsub_add_eq_add_tsub hs, card_cons, add_tsub_add_eq_tsub_right],\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/set_family/kleitman.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362858, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7339353065247411}}
{"text": "import Mathlib.Data.Nat.Prime\n\nnamespace Intro \n/- \nWe can declare variables of type Prop as \n-/\nvariable (p q : Prop) \n\n/-\nTerms of type (p : Prop) are _proofs_ of the proposition p. \n\nWe state a theorem to declare we want to produce a proof \n-/\ntheorem foo : p := sorry \n\n/-\nOf course we cannot fill in this sorry. Not every proposition in \nthat can be stated in Lean will have a proof. For example, \n-/ \ntheorem crazy : \u2200 (n : \u2115), Nat.Prime n := sorry \n\ndef notGood : Prop := \u2200 (n : \u2115), Nat.Prime n \n\ntheorem also_crazy : notGood := sorry \n\nend Intro \n/- \nUnder the rules of propositional and higher logics, there are \na handful of ways to make new propositions, called _connectives_, \nand a handful to rules to produce new proofs from old ones, _rules \nof inference_. \n\nThe connectives in propositional logic are \n- implication : p \u2192 q \n- conjunction : p \u2227 q  \n- disjunction : p \u2228 q \n- negation : \u00ac p \n- bi-implication : p \u2194 q \n\nEach takes an existing set of propositions and constructs a new one. \nThey can be iterated, eg (p \u2194 q) \u2228 \u00ac p \u2192 q. Note that parentheses \nare important for the order of application of the connectives. \n\nEach connective comes with rules for providing a proof, introduction \nrules, and using as a hypothesis, elimination rules. \n-/\n\n/- \nImplication\n\nSuppose we have (p q : Prop). What do we need to produce a proof of \np \u2192 q? Well, whenever we have a proof of p, we need to construct \na proof of q. In Lean, we can see the difference syntactically. \n-/\n\nvariable {p q r : Prop}\n\ntheorem imp (h : p) : q := sorry \n\ntheorem imp' : p \u2192 q := sorry \n\n/-\nThe introduction rule says that give `imp` we can conclude `imp'`. \nIn Lean, we can give a proof of `imp'` using `imp` and the \ntactics `intro` and `exact`. \n-/\n\nexample : p \u2192 q := by \n  intro h -- the goal is now q and we have (h : p) in the context\n  exact imp h  -- tells Lean that `imp h` is _exactly_ the term we want\n\n/-\nThe elimination rule says that give `f : p \u2192 q` and `h : p` we can \nconclude `q`. \n-/ \n\nexample (h : p) (f : p \u2192 q) : q := by \n  apply f\n  exact h\n\nexample (h : p) : p := by \n  exact h\n\nexample : p \u2192 p := by \n  intro h\n  exact h\n\n/- \nIn Lean, propositional implication is a function type. Application is \nelimination. The tactic `apply` allows us to replace a goal `\u03b2` with \n`\u03b1` if we have a term of type `\u03b1 \u2192 \u03b2` in the context.\n-/\n\n/- \nUnlike implication, conjunction is defined separately in Lean. In Lean \ncore, it is defined as. \n\nstructure And (a b : Prop) : Prop where\n  /-- `And.intro : a \u2192 b \u2192 a \u2227 b` is the constructor for the And operation. -/\n  intro ::\n  /-- Extract the left conjunct from a conjunction. `h : a \u2227 b` then\n  `h.left`, also notated as `h.1`, is a proof of `a`. -/\n  left : a\n  /-- Extract the right conjunct from a conjunction. `h : a \u2227 b` then\n  `h.right`, also notated as `h.2`, is a proof of `b`. -/\n  right : b\n\nBuilt into its definition are its introduction `intro` and its two \nelimination rules `left` and `right`.\n\n-/\n\nexample (u v w : Prop) : (u \u2227 v \u2192 w) \u2192 u \u2192 v \u2192 w := by\n  intro h hp hq \n  apply h\n  apply And.intro \n  \u00b7 exact hp\n  \u00b7 exact hq \n\nexample : (p \u2227 q) \u2192 p := by \n  intro h\n  exact h.left\n\nexample : (p \u2227 q) \u2227 r \u2192 p \u2227 q \u2227 r := by \n  sorry \n\nexample (h : r \u2192 p) (h' : r \u2192 q) : r \u2192 p \u2227 q := by \n  intro h\u2083 \n  apply And.intro \n  . exact h h\u2083 \n  . exact h' h\u2083 \n\n/- \nDisjunction is also its own type. \n\n`Or a b`, or `a \u2228 b`, is the disjunction of propositions. There are two\nconstructors for `Or`, called `Or.inl : a \u2192 a \u2228 b` and `Or.inr : b \u2192 a \u2228 b`,\nand you can use `match` or `cases` to destruct an `Or` assumption into the\ntwo cases.\n\ninductive Or (a b : Prop) : Prop where\n  /-- `Or.inl` is \"left injection\" into an `Or`. If `h : a` then `Or.inl h : a \u2228 b`. -/\n  | inl (h : a) : Or a b\n  /-- `Or.inr` is \"right injection\" into an `Or`. If `h : b` then `Or.inr h : a \u2228 b`. -/\n  | inr (h : b) : Or a b\n\nDisjunction has two introduction rules, intro left or `inl` and intro right or `inr`. \nIt's elimination rule is derived from the fact it is an inductive type. \n-/\n\nexample : (p \u2192 q) \u2192 (q \u2192 q \u2228 r) := by\n  intro _ hq \n  exact .inl hq  \n\nexample : p \u2228 q \u2192 (p \u2192 r) \u2192 (q \u2192 r) \u2192 r := by \n  intro h\u2081 h\u2082 h\u2083\n  match h\u2081 with \n  | .inl h => exact h\u2082 h \n  | .inr h => exact h\u2083 h \n\n\n/- \nNegatation relies on `False : Prop`. \n\n`False` is the empty proposition. Thus, it has no introduction rules.\nIt represents a contradiction. `False` elimination rule \nexpresses the fact that anything follows from a contradiction.\nThis rule is sometimes called ex falso (short for ex falso sequitur quodlibet),\nor the principle of explosion.\n\ninductive False : Prop\n\n-/\n\nexample (f : False) : crazy := by\n  cases f \n  -- exact f.elim \n\n/- \nThere is a corresponding type `True : Prop` with a single constructor. \n`True.intro`. \n\nBy definition in Lean, `\u00ac p` is _defined as_ `p \u2192 False`. \n-/\n\nexample : (p \u2192 q) \u2192 \u00ac q \u2192 \u00ac p := sorry \n\nexample : \u00ac p \u2228 \u00ac q \u2192 \u00ac (p \u2227 q) := sorry \n\n/-\nFinally bi-implication or if-and-only-if looks a bit similar to `And` \nunder the hood. \n\nIf and only if, or logical bi-implication. `a \u2194 b` means that `a` implies `b`\nand vice versa.\n\nstructure Iff (a b : Prop) : Prop where\n  /-- If `a \u2192 b` and `b \u2192 a` then `a` and `b` are equivalent. -/\n  intro ::\n  /-- Modus ponens for if and only if. If `a \u2194 b` and `a`, then `b`. -/\n  mp : a \u2192 b\n  /-- Modus ponens for if and only if, reversed. If `a \u2194 b` and `b`, then `a`. -/\n  mpr : b \u2192 a\n-/\n\nexample (h : p \u2194 q) : (q \u2192 r) \u2192 p \u2192 r := sorry \n\nexample : \u00ac (p \u2194 \u00ac p) := sorry \n", "meta": {"author": "UofSC-Spring-2023-SCHC-411-H01", "repo": "notes", "sha": "ef57142df34fbe92f6204d8eb636ec5061729bd0", "save_path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes", "path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes/notes-ef57142df34fbe92f6204d8eb636ec5061729bd0/Notes4/PropLogic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7339327497605873}}
{"text": "import data.equiv.basic -- bijections with inverses\nimport tactic -- we want to use tactics\n\nopen set\n\n/-- Definition of a partition as a collection of disjoint nonempty\n  subsets of X whose union is X-/\n@[ext] structure partition (X : Type) :=\n(C : set (set X))\n(Hnonempty : \u2200 c \u2208 C, c \u2260 \u2205)\n(Hcover : \u2200 x, \u2203 c \u2208 C, x \u2208 c)\n(Hunique : \u2200 c d \u2208 C, c \u2229 d \u2260 \u2205 \u2192 c = d)\n\n/-- Equivalence class for a binary relation -/\ndef equivalence_class {X : Type} (R : X \u2192 X \u2192 Prop) (x : X) := {y : X | R x y}\n\n\n/-- x is in the equivalence class of x -/\nlemma mem_class {X : Type} {R : X \u2192 X \u2192 Prop} (HR : equivalence R) (x : X) :\n  x \u2208 equivalence_class R x :=\nbegin\n  sorry\nend\n\n/-- There is a bijection between equivalence relations on X and partitions of X -/\nexample (X : Type) : {R : X \u2192 X \u2192 Prop // equivalence R} \u2243 partition X :=\n-- The map in one direction: given a relation, use the set of equivalence classes.\n{ to_fun := \u03bb R, {\n    C := { S : set X | \u2203 x : X, S = equivalence_class R x},\n-- I claim that this is a partition.\n    Hnonempty := begin -- equiv classes are nonempty\n      sorry,\n    end,\n    Hcover := begin -- they cover\n      sorry,\n    end,\n    Hunique := begin -- and distinct equiv classes are disjoint\n      sorry\n    end },\n-- The map the other way: given a partition, say two elements are related\n-- if there's a set in the partition that they both lie in.\n  inv_fun := \u03bb P, \u27e8\u03bb x y, \u2203 c \u2208 P.C, x \u2208 c \u2227 y \u2208 c, \u27e8\n    -- Claim this is an equivalence relation.\n    begin -- reflexive\n      change \u2200 (x : X), \u2203 (c : set X) (H : c \u2208 P.C), x \u2208 c \u2227 x \u2208 c,\n      sorry,\n    end,\n    begin -- symmetric\n      change \u2200 (x y : X), (\u2203 (c : set X) (H : c \u2208 P.C), x \u2208 c \u2227 y \u2208 c) \u2192\n        (\u2203 (d : set X) (H : d \u2208 P.C), y \u2208 d \u2227 x \u2208 d),\n      sorry,\n    end,\n    begin -- transitive\n      change \u2200 (x y z : X),\n        (\u2203 (c : set X) (H : c \u2208 P.C), x \u2208 c \u2227 y \u2208 c) \u2192\n        (\u2203 (d : set X) (H : d \u2208 P.C), y \u2208 d \u2227 z \u2208 d) \u2192\n        (\u2203 (e : set X) (H : e \u2208 P.C), x \u2208 e \u2227 z \u2208 e),\n      sorry,\n    end\n  \u27e9\u27e9,\n  -- Furthermore, I claim that these two constructions are inverse to each other.\n  left_inv := begin\n    sorry,\n  end,\n  -- (in both directions)\n  right_inv := begin\n    sorry,\n  end }\n", "meta": {"author": "ImperialCollegeLondon", "repo": "Example-Lean-Projects", "sha": "87b27ba616eaf03f3642000829a481a1932dd08e", "save_path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects", "path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects/Example-Lean-Projects-87b27ba616eaf03f3642000829a481a1932dd08e/src/equivalence_relations/partitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.733932749517974}}
{"text": "theorem impNot {p q : Prop} : p \u2192 \u00ac q \u2194 \u00ac (p \u2227 q) := \n  \u27e8 \u03bb hpq h => hpq h.1 h.2, \u03bb h hp hq => h <| And.intro hp hq \u27e9  \n\ntheorem Exists.impNot {p q : \u03b1 \u2192 Prop} : (\u2203 x, p x \u2192 \u00ac q x) \u2194 \u2203 x, \u00ac (p x \u2227 q x) := by \n  apply Iff.intro\n  intro h\n  cases h with | intro x hx => \n  { exact \u27e8 x, \u03bb hs => hx hs.1 hs.2 \u27e9 }\n  intro h \n  cases h with | intro x hx => \n  { exact \u27e8 x, \u03bb hpx hqx => hx <| And.intro hpx hqx \u27e9 }\n\nnamespace Classical\n\ntheorem contrapositive {p q : Prop} : (\u00ac q \u2192 \u00ac p) \u2192 p \u2192 q := \n  \u03bb hqp hp => match em q with \n    | Or.inl h => h\n    | Or.inr h => False.elim <| hqp h hp\n  \ntheorem notNot {p : Prop} : \u00ac \u00ac p \u2194 p := by \n  apply Iff.intro\n  { intro hp; cases em p with \n    | inl   => assumption\n    | inr h => exact False.elim <| hp h }\n  { exact \u03bb hp hnp => False.elim <| hnp hp }\n\ntheorem notForall {p : \u03b1 \u2192 Prop} : (\u00ac \u2200 x, p x) \u2192 \u2203 x, \u00ac p x := by \n  { apply contrapositive; intro hx; rw notNot; intro x;\n    cases em (p x); { assumption }\n      { apply False.elim <| hx <| Exists.intro x _; assumption } }  \n\ntheorem notAnd {p q : Prop} : p \u2227 \u00ac q \u2194 \u00ac (p \u2192 q) := by\n  apply Iff.intro\n  { exact \u03bb h himp => h.2 <| himp h.1 }\n  { intro h; apply And.intro;\n    { revert h; apply contrapositive; rw notNot;\n      exact \u03bb hnp hp => False.elim <| hnp hp }\n    { exact \u03bb hq => h <| \u03bb _ => hq } }\n\ntheorem Exists.notAnd {p q : \u03b1 \u2192 Prop} : \n  (\u2203 x, p x \u2227 \u00ac q x) \u2194 \u2203 x, \u00ac (p x \u2192 q x) := by\n  apply Iff.intro\n  { intro h;\n    let \u27e8 x, \u27e8 hp, hnq \u27e9 \u27e9 := h;\n    exact Exists.intro x \u03bb h => hnq <| h hp }\n  { intro h;\n    let \u27e8 x, hx \u27e9 := h;\n    apply Exists.intro x;\n    apply And.intro;\n    { revert hx; apply contrapositive;\n      exact \u03bb hpx hpq => hpq \u03bb hp => False.elim <| hpx hp }\n    { revert hx; apply contrapositive;\n      rw [notNot, notNot]; exact \u03bb h _ => h } }\n\nend Classical\n\ndef Set (\u03b1 : Type u) := \u03b1 \u2192 Prop\n\ndef setOf (p : \u03b1 \u2192 Prop) : Set \u03b1 := p\n\nnamespace Set\n\ninstance : EmptyCollection (Set \u03b1) := \u27e8 \u03bb x => False \u27e9 \n\nvariables {\u03b1 : Type u} {s : Set \u03b1}\n\ndef mem (a : \u03b1) (s : Set \u03b1) := s a\n\ninfix:55 \"\u2208\" => Set.mem\nnotation:55 x \"\u2209\" s => \u00ac x \u2208 s\n\ninstance : CoeSort (Set \u03b1) (Type u) where \n  coe s := Subtype s\n\ntheorem ext {s t : Set \u03b1} (h : \u2200 x, x \u2208 s \u2194 x \u2208 t) : s = t := \n  funext <| \u03bb x => propext <| h x\n\n-- Declaring the index category\ndeclare_syntax_cat index\nsyntax ident : index\nsyntax ident \":\" term : index \nsyntax ident \"\u2208\" term : index\n\n-- Notation for sets\nsyntax \"{\" index \"|\" term \"}\" : term\n\nmacro_rules \n| `({ $x:ident : $t | $p }) => `(setOf (\u03bb ($x:ident : $t) => $p))\n| `({ $x:ident | $p }) => `(setOf (\u03bb ($x:ident) => $p))\n| `({ $x:ident \u2208 $s | $p }) => `(setOf (\u03bb $x => $x \u2208 $s \u2192 $p))\n\ndef union (s t : Set \u03b1) : Set \u03b1 := { x : \u03b1 | x \u2208 s \u2228 x \u2208 t } \n\ndef inter (s t : Set \u03b1) : Set \u03b1 := { x : \u03b1 | x \u2208 s \u2227 x \u2208 t }\n\ntheorem unionDef (s t : Set \u03b1) : union s t = \u03bb x => s x \u2228 t x := rfl\n\ntheorem interDef (s t : Set \u03b1) : inter s t = \u03bb x => s x \u2227 t x := rfl\n\ninfix:60 \"\u222a\" => Set.union\ninfix:60 \"\u2229\" => Set.inter\n\ndef Union (s : Set (Set \u03b1)) : Set \u03b1 := { x : \u03b1 | \u2203 t : Set \u03b1, t \u2208 s \u2192 t x }\n\ndef Inter (s : Set (Set \u03b1)) : Set \u03b1 := { x : \u03b1 | \u2200 t : Set \u03b1, t \u2208 s \u2192 t x }\n\ndef UnionDef (s : Set (Set \u03b1)) : Union s = \u03bb x => \u2203 t : Set \u03b1, t \u2208 s \u2192 t x := rfl\n\ndef InterDef (s : Set (Set \u03b1)) : Inter s = \u03bb x => \u2200 t : Set \u03b1, t \u2208 s \u2192 t x := rfl\n\nsyntax \"\u22c3\" index \",\" term : term\nsyntax \"\u22c2\" index \",\" term : term\n\nmacro_rules\n| `(\u22c3 $s:ident \u2208 $c, $s) => `(Union $c)\n| `(\u22c2 $s:ident \u2208 $c, $s) => `(Inter $c)\n\n-- variables {s : Set (Set \u03b1)}\n\n-- #check \u22c2 t \u2208 s, t\n\n-- Notation for \u2200 x \u2208 s, p and \u2203 x \u2208 s, p\nsyntax \"\u2200\" index \",\" term : term\nsyntax \"\u2203\" index \",\" term : term\n\nmacro_rules\n| `(\u2200 $x:ident \u2208 $s, $p) => `(\u2200 $x:ident, $x \u2208 $s \u2192 $p)\n| `(\u2203 $x:ident \u2208 $s, $p) => `(\u2203 $x:ident, $x \u2208 $s \u2227 $p)\n\ndef Subset (s t : Set \u03b1) := \u2200 x \u2208 s, x \u2208 t\n\ninfix:50 \"\u2286\" => Subset\n\ntheorem Subset.def {s t : Set \u03b1} : s \u2286 t \u2194 \u2200 x \u2208 s, x \u2208 t := Iff.rfl\n\nnamespace Subset\n\ntheorem refl {s : Set \u03b1} : s \u2286 s := \u03bb _ hx => hx\n\ntheorem trans {s t v : Set \u03b1} (hst : s \u2286 t) (htv : t \u2286 v) : s \u2286 t := \n  \u03bb x hx => hst x hx\n\ntheorem antisymm {s t : Set \u03b1} (hst : s \u2286 t) (hts : t \u2286 s) : s = t := \n  Set.ext \u03bb x => \u27e8 \u03bb hx => hst x hx, \u03bb hx => hts x hx \u27e9\n\ntheorem antisymmIff {s t : Set \u03b1} : s = t \u2194 s \u2286 t \u2227 t \u2286 s :=\n  \u27e8 by { intro hst; subst hst; exact \u27e8 refl, refl \u27e9 }, \n    \u03bb \u27e8 hst, hts \u27e9 => antisymm hst hts \u27e9 \n\n-- \u2193 Uses classical logic\ntheorem notSubset : \u00ac s \u2286 t \u2194 \u2203 x \u2208 s, x \u2209 t := by \n  apply Iff.intro;\n  { intro hst; \n    rw Classical.Exists.notAnd;\n    apply Classical.notForall;\n    exact \u03bb h => hst \u03bb x hx => h x hx }\n  { intro h hst;\n    let \u27e8 x, \u27e8 hxs, hxt \u27e9 \u27e9 := h;\n    exact hxt <| hst x hxs }\n\nend Subset\n\ntheorem memEmptySet {x : \u03b1} (h : x \u2208 \u2205) : False := h\n\n@[simp] theorem memEmptySetIff : (\u2203 (x : \u03b1), x \u2208 \u2205) \u2194 False := \n  Iff.intro (\u03bb h => h.2) False.elim \n\n@[simp] theorem setOfFalse : { a : \u03b1 | False } = \u2205 := rfl\n\ndef univ : Set \u03b1 := { x | True }\n\n@[simp] theorem memUniv (x : \u03b1) : x \u2208 univ := True.intro\n\ntheorem Subset.subsetUniv {s : Set \u03b1} : s \u2286 univ := \u03bb x _ => memUniv x \n\ntheorem Subset.univSubsetIff {s : Set \u03b1} : univ \u2286 s \u2194 univ = s := by\n  apply Iff.intro \u03bb hs => Subset.antisymm hs Subset.subsetUniv \n  { intro h; subst h; exact Subset.refl }\n\ntheorem eqUnivIff {s : Set \u03b1} : s = univ \u2194 \u2200 x, x \u2208 s := by \n  apply Iff.intro \n  { intro h x; subst h; exact memUniv x }\n  { exact \u03bb h => ext \u03bb x => Iff.intro (\u03bb _ => memUniv _) \u03bb _ => h x }\n\n/-! ### Unions and Intersections -/\n\nmacro \"extia\" x:term : tactic => `(tactic| apply ext; intro $x; apply Iff.intro)\n\ntheorem unionSelf {s : Set \u03b1} : s \u222a s = s := by \n  extia x\n  { intro hx; cases hx; assumption; assumption }\n  { exact Or.inl }\n\ntheorem unionEmpty {s : Set \u03b1} : s \u222a \u2205 = s := by \n  extia x\n  { intro hx; cases hx with \n    | inl   => assumption\n    | inr h => exact False.elim <| memEmptySet h }\n  { exact Or.inl }\n\ntheorem unionSymm {s t : Set \u03b1} : s \u222a t = t \u222a s := by \n  extia x \n  allGoals { intro hx; cases hx with \n             | inl hx => exact Or.inr hx\n             | inr hx => exact Or.inl hx }\n\ntheorem emptyUnion {s : Set \u03b1} : \u2205 \u222a s = s := by \n  rw unionSymm; exact unionEmpty\n\ntheorem unionAssoc {s t w : Set \u03b1} : s \u222a t \u222a w = s \u222a (t \u222a w) := by \n  extia x\n  { intro hx; cases hx with \n    | inr hx   => exact Or.inr <| Or.inr hx\n    | inl hx   => cases hx with \n      | inr hx => exact Or.inr <| Or.inl hx\n      | inl hx => exact Or.inl hx }\n  { intro hx; cases hx with \n    | inl hx   => exact Or.inl <| Or.inl hx\n    | inr hx   => cases hx with \n      | inr hx => exact Or.inr hx\n      | inl hx => exact Or.inl <| Or.inr hx }\n\nend Set", "meta": {"author": "JasonKYi", "repo": "funWithLean4", "sha": "c00cff02380e83253cc5c9f36e25b1a4e445ef09", "save_path": "github-repos/lean/JasonKYi-funWithLean4", "path": "github-repos/lean/JasonKYi-funWithLean4/funWithLean4-c00cff02380e83253cc5c9f36e25b1a4e445ef09/src/set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7339327432900978}}
{"text": "/-\nCopyright (c) 2019 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport data.set.intervals\nimport data.set.finite\nimport data.pnat.intervals\n\n/-!\n# fintype instances for intervals\n\nWe provide `fintype` instances for `Ico l u`, for `l u : \u2115`, and for `l u : \u2124`.\n-/\n\nnamespace set\n\ninstance Ico_\u2115_fintype (l u : \u2115) : fintype (Ico l u) :=\nfintype.of_finset (finset.Ico l u) $\n  (\u03bb n, by { simp only [mem_Ico, finset.Ico.mem], })\n\n@[simp] lemma Ico_\u2115_card (l u : \u2115) : fintype.card (Ico l u) = u - l :=\ncalc fintype.card (Ico l u) = (finset.Ico l u).card : fintype.card_of_finset _ _\n                        ... = u - l                 : finset.Ico.card l u\n\ninstance Ico_pnat_fintype (l u : \u2115+) : fintype (Ico l u) :=\nfintype.of_finset (pnat.Ico l u) $\n  (\u03bb n, by { simp only [mem_Ico, pnat.Ico.mem], })\n\n@[simp] lemma Ico_pnat_card (l u : \u2115+) : fintype.card (Ico l u) = u - l :=\ncalc fintype.card (Ico l u) = (pnat.Ico l u).card : fintype.card_of_finset _ _\n                        ... = u - l               : pnat.Ico.card l u\n\ninstance Ico_\u2124_fintype (l u : \u2124) : fintype (Ico l u) :=\nfintype.of_finset (finset.Ico_\u2124 l u) $\n  (\u03bb n, by { simp only [mem_Ico, finset.Ico_\u2124.mem], })\n\n@[simp] lemma Ico_\u2124_card (l u : \u2124) : fintype.card (Ico l u) = (u - l).to_nat :=\ncalc fintype.card (Ico l u) = (finset.Ico_\u2124 l u).card : fintype.card_of_finset _ _\n                        ... = (u - l).to_nat          : finset.Ico_\u2124.card l u\n\nlemma Ico_\u2124_finite (l u : \u2124) : set.finite (Ico l u) := \u27e8set.Ico_\u2124_fintype l u\u27e9\nlemma Ioo_\u2124_finite (l u : \u2124) : set.finite (Ioo l u) := Ico_\u2124_finite (l + 1) u\nlemma Icc_\u2124_finite (l u : \u2124) : set.finite (Icc l u) :=\nbegin\n  convert Ico_\u2124_finite l (u + 1),\n  ext,\n  simp only [int.lt_add_one_iff, iff_self, mem_Ico, mem_Icc],\nend\nlemma Ioc_\u2124_finite (l u : \u2124) : set.finite (Ioc l u) := Icc_\u2124_finite (l + 1) u\n\n-- TODO other useful instances: fin n, zmod?\n\nend set\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/fintype/intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.733857988344763}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.finset.powerset\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Lattice\nimport Mathlib.Data.Multiset.Powerset\n\n/-!\n# The powerset of a finset\n-/\n\n\nnamespace Finset\n\nopen Function Multiset\n\nvariable {\u03b1 : Type _} {s t : Finset \u03b1}\n\n/-! ### powerset -/\n\n\nsection Powerset\n\n/-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/\ndef powerset (s : Finset \u03b1) : Finset (Finset \u03b1) :=\n  \u27e8(s.1.powerset.pmap Finset.mk) fun _t h => nodup_of_le (mem_powerset.1 h) s.nodup,\n    s.nodup.powerset.pmap fun _a _ha _b _hb => congr_arg Finset.val\u27e9\n#align finset.powerset Finset.powerset\n\n@[simp]\ntheorem mem_powerset {s t : Finset \u03b1} : s \u2208 powerset t \u2194 s \u2286 t := by\n  cases s\n  simp [powerset, mem_mk, mem_pmap, mk.injEq, mem_powerset, exists_prop, exists_eq_right,\n    \u2190 val_le_iff]\n#align finset.mem_powerset Finset.mem_powerset\n\n@[simp, norm_cast]\ntheorem coe_powerset (s : Finset \u03b1) :\n    (s.powerset : Set (Finset \u03b1)) = ((\u2191) : Finset \u03b1 \u2192 Set \u03b1) \u207b\u00b9' (s : Set \u03b1).powerset :=\n  by\n  ext\n  simp\n#align finset.coe_powerset Finset.coe_powerset\n\n--Porting note: remove @[simp], simp can prove it\n\n\n--Porting note: remove @[simp], simp can prove it\ntheorem mem_powerset_self (s : Finset \u03b1) : s \u2208 powerset s :=\n  mem_powerset.2 Subset.rfl\n#align finset.mem_powerset_self Finset.mem_powerset_self\n\ntheorem powerset_nonempty (s : Finset \u03b1) : s.powerset.Nonempty :=\n  \u27e8\u2205, empty_mem_powerset _\u27e9\n#align finset.powerset_nonempty Finset.powerset_nonempty\n\n@[simp]\ntheorem powerset_mono {s t : Finset \u03b1} : powerset s \u2286 powerset t \u2194 s \u2286 t :=\n  \u27e8fun h => mem_powerset.1 <| h <| mem_powerset_self _, fun st _u h =>\n    mem_powerset.2 <| Subset.trans (mem_powerset.1 h) st\u27e9\n#align finset.powerset_mono Finset.powerset_mono\n\ntheorem powerset_injective : Injective (powerset : Finset \u03b1 \u2192 Finset (Finset \u03b1)) :=\n  (injective_of_le_imp_le _) powerset_mono.1\n#align finset.powerset_injective Finset.powerset_injective\n\n@[simp]\ntheorem powerset_inj : powerset s = powerset t \u2194 s = t :=\n  powerset_injective.eq_iff\n#align finset.powerset_inj Finset.powerset_inj\n\n@[simp]\ntheorem powerset_empty : (\u2205 : Finset \u03b1).powerset = {\u2205} :=\n  rfl\n#align finset.powerset_empty Finset.powerset_empty\n\n@[simp]\ntheorem powerset_eq_singleton_empty : s.powerset = {\u2205} \u2194 s = \u2205 := by\n  rw [\u2190 powerset_empty, powerset_inj]\n#align finset.powerset_eq_singleton_empty Finset.powerset_eq_singleton_empty\n\n/-- **Number of Subsets of a Set** -/\n@[simp]\ntheorem card_powerset (s : Finset \u03b1) : card (powerset s) = 2 ^ card s :=\n  (card_pmap _ _ _).trans (Multiset.card_powerset s.1)\n#align finset.card_powerset Finset.card_powerset\n\ntheorem not_mem_of_mem_powerset_of_not_mem {s t : Finset \u03b1} {a : \u03b1} (ht : t \u2208 s.powerset)\n    (h : a \u2209 s) : a \u2209 t := by\n  apply mt _ h\n  apply mem_powerset.1 ht\n#align finset.not_mem_of_mem_powerset_of_not_mem Finset.not_mem_of_mem_powerset_of_not_mem\n\ntheorem powerset_insert [DecidableEq \u03b1] (s : Finset \u03b1) (a : \u03b1) :\n    powerset (insert a s) = s.powerset \u222a s.powerset.image (insert a) :=\n  by\n  ext t\n  simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff]\n  by_cases h : a \u2208 t\n  \u00b7 constructor\n    \u00b7 exact fun H => Or.inr \u27e8_, H, insert_erase h\u27e9\n    \u00b7 intro H\n      cases' H with H H\n      \u00b7 exact Subset.trans (erase_subset a t) H\n      \u00b7 rcases H with \u27e8u, hu\u27e9\n        rw [\u2190 hu.2]\n        exact Subset.trans (erase_insert_subset a u) hu.1\n  \u00b7 have : \u00ac\u2203 u : Finset \u03b1, u \u2286 s \u2227 insert a u = t := by simp [Ne.symm (ne_insert_of_not_mem _ _ h)]\n    simp [Finset.erase_eq_of_not_mem h, this]\n#align finset.powerset_insert Finset.powerset_insert\n\n/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/\ninstance decidableExistsOfDecidableSubsets {s : Finset \u03b1} {p : \u2200 (t) (_ : t \u2286 s), Prop}\n    [\u2200 (t) (h : t \u2286 s), Decidable (p t h)] : Decidable (\u2203 (t : _)(h : t \u2286 s), p t h) :=\n  decidable_of_iff (\u2203 (t : _)(hs : t \u2208 s.powerset), p t (mem_powerset.1 hs))\n    \u27e8fun \u27e8t, _, hp\u27e9 => \u27e8t, _, hp\u27e9, fun \u27e8t, hs, hp\u27e9 => \u27e8t, mem_powerset.2 hs, hp\u27e9\u27e9\n#align finset.decidable_exists_of_decidable_subsets Finset.decidableExistsOfDecidableSubsets\n\n/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/\ninstance decidableForallOfDecidableSubsets {s : Finset \u03b1} {p : \u2200 (t) (_ : t \u2286 s), Prop}\n    [\u2200 (t) (h : t \u2286 s), Decidable (p t h)] : Decidable (\u2200 (t) (h : t \u2286 s), p t h) :=\n  decidable_of_iff (\u2200 (t) (h : t \u2208 s.powerset), p t (mem_powerset.1 h))\n    \u27e8fun h t hs => h t (mem_powerset.2 hs), fun h _ _ => h _ _\u27e9\n#align finset.decidable_forall_of_decidable_subsets Finset.decidableForallOfDecidableSubsets\n\n/-- A version of `Finset.decidableExistsOfDecidableSubsets` with a non-dependent `p`.\nTypeclass inference cannot find `hu` here, so this is not an instance. -/\ndef decidableExistsOfDecidableSubsets' {s : Finset \u03b1} {p : Finset \u03b1 \u2192 Prop}\n    (hu : \u2200 (t) (_h : t \u2286 s), Decidable (p t)) : Decidable (\u2203 (t : _)(_h : t \u2286 s), p t) :=\n  @Finset.decidableExistsOfDecidableSubsets _ _ _ hu\n#align finset.decidable_exists_of_decidable_subsets' Finset.decidableExistsOfDecidableSubsets'\n\n/-- A version of `Finset.decidableForallOfDecidableSubsets` with a non-dependent `p`.\nTypeclass inference cannot find `hu` here, so this is not an instance. -/\ndef decidableForallOfDecidableSubsets' {s : Finset \u03b1} {p : Finset \u03b1 \u2192 Prop}\n    (hu : \u2200 (t) (_h : t \u2286 s), Decidable (p t)) : Decidable (\u2200 (t) (_h : t \u2286 s), p t) :=\n  @Finset.decidableForallOfDecidableSubsets _ _ _ hu\n#align finset.decidable_forall_of_decidable_subsets' Finset.decidableForallOfDecidableSubsets'\n\nend Powerset\n\nsection Ssubsets\n\nvariable [DecidableEq \u03b1]\n\n/-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/\ndef ssubsets (s : Finset \u03b1) : Finset (Finset \u03b1) :=\n  erase (powerset s) s\n#align finset.ssubsets Finset.ssubsets\n\n@[simp]\ntheorem mem_ssubsets {s t : Finset \u03b1} : t \u2208 s.ssubsets \u2194 t \u2282 s := by\n  rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and_comm]\n#align finset.mem_ssubsets Finset.mem_ssubsets\n\ntheorem empty_mem_ssubsets {s : Finset \u03b1} (h : s.Nonempty) : \u2205 \u2208 s.ssubsets :=\n  by\n  rw [mem_ssubsets, ssubset_iff_subset_ne]\n  exact \u27e8empty_subset s, h.ne_empty.symm\u27e9\n#align finset.empty_mem_ssubsets Finset.empty_mem_ssubsets\n/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/\ninstance decidableExistsOfDecidableSsubsets {s : Finset \u03b1} {p : \u2200 (t) (_ : t \u2282 s), Prop}\n    [\u2200 (t) (h : t \u2282 s), Decidable (p t h)] : Decidable (\u2203 t h, p t h) :=\n  decidable_of_iff (\u2203 (t : _)(hs : t \u2208 s.ssubsets), p t (mem_ssubsets.1 hs))\n    \u27e8fun \u27e8t, _, hp\u27e9 => \u27e8t, _, hp\u27e9, fun \u27e8t, hs, hp\u27e9 => \u27e8t, mem_ssubsets.2 hs, hp\u27e9\u27e9\n#align finset.decidable_exists_of_decidable_ssubsets Finset.decidableExistsOfDecidableSsubsets\n\n/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/\ninstance decidableForallOfDecidableSsubsets {s : Finset \u03b1} {p : \u2200 (t) (_ : t \u2282 s), Prop}\n    [\u2200 (t) (h : t \u2282 s), Decidable (p t h)] : Decidable (\u2200 t h, p t h) :=\n  decidable_of_iff (\u2200 (t) (h : t \u2208 s.ssubsets), p t (mem_ssubsets.1 h))\n    \u27e8fun h t hs => h t (mem_ssubsets.2 hs), fun h _ _ => h _ _\u27e9\n#align finset.decidable_forall_of_decidable_ssubsets Finset.decidableForallOfDecidableSsubsets\n\n/-- A version of `Finset.decidableExistsOfDecidableSsubsets` with a non-dependent `p`.\nTypeclass inference cannot find `hu` here, so this is not an instance. -/\ndef decidableExistsOfDecidableSsubsets' {s : Finset \u03b1} {p : Finset \u03b1 \u2192 Prop}\n    (hu : \u2200 (t) (_h : t \u2282 s), Decidable (p t)) : Decidable (\u2203 (t : _)(_h : t \u2282 s), p t) :=\n  @Finset.decidableExistsOfDecidableSsubsets _ _ _ _ hu\n#align finset.decidable_exists_of_decidable_ssubsets' Finset.decidableExistsOfDecidableSsubsets'\n\n/-- A version of `Finset.decidableForallOfDecidableSsubsets` with a non-dependent `p`.\nTypeclass inference cannot find `hu` here, so this is not an instance. -/\ndef decidableForallOfDecidableSsubsets' {s : Finset \u03b1} {p : Finset \u03b1 \u2192 Prop}\n    (hu : \u2200 (t) (_h : t \u2282 s), Decidable (p t)) : Decidable (\u2200 (t) (_h : t \u2282 s), p t) :=\n  @Finset.decidableForallOfDecidableSsubsets _ _ _ _ hu\n#align finset.decidable_forall_of_decidable_ssubsets' Finset.decidableForallOfDecidableSsubsets'\n\nend Ssubsets\n\nsection PowersetLen\n\n/-- Given an integer `n` and a finset `s`, then `powersetLen n s` is the finset of subsets of `s`\nof cardinality `n`. -/\ndef powersetLen (n : \u2115) (s : Finset \u03b1) : Finset (Finset \u03b1) :=\n  \u27e8((s.1.powersetLen n).pmap Finset.mk) fun _t h => nodup_of_le (mem_powersetLen.1 h).1 s.2,\n    s.2.powersetLen.pmap fun _a _ha _b _hb => congr_arg Finset.val\u27e9\n#align finset.powerset_len Finset.powersetLen\n\n/-- **Formula for the Number of Combinations** -/\ntheorem mem_powersetLen {n} {s t : Finset \u03b1} : s \u2208 powersetLen n t \u2194 s \u2286 t \u2227 card s = n := by\n  cases s; simp [powersetLen, val_le_iff.symm]\n#align finset.mem_powerset_len Finset.mem_powersetLen\n\n@[simp]\ntheorem powersetLen_mono {n} {s t : Finset \u03b1} (h : s \u2286 t) : powersetLen n s \u2286 powersetLen n t :=\n  fun _u h' => mem_powersetLen.2 <| And.imp (fun h\u2082 => Subset.trans h\u2082 h) id (mem_powersetLen.1 h')\n#align finset.powerset_len_mono Finset.powersetLen_mono\n\n/-- **Formula for the Number of Combinations** -/\n@[simp]\ntheorem card_powersetLen (n : \u2115) (s : Finset \u03b1) : card (powersetLen n s) = Nat.choose (card s) n :=\n  (card_pmap _ _ _).trans (Multiset.card_powersetLen n s.1)\n#align finset.card_powerset_len Finset.card_powersetLen\n\n@[simp]\ntheorem powersetLen_zero (s : Finset \u03b1) : Finset.powersetLen 0 s = {\u2205} :=\n  by\n  ext; rw [mem_powersetLen, mem_singleton, card_eq_zero]\n  refine'\n    \u27e8fun h => h.2, fun h => by\n      rw [h]\n      exact \u27e8empty_subset s, rfl\u27e9\u27e9\n#align finset.powerset_len_zero Finset.powersetLen_zero\n\n@[simp]\ntheorem powersetLen_empty (n : \u2115) {s : Finset \u03b1} (h : s.card < n) : powersetLen n s = \u2205 :=\n  Finset.card_eq_zero.mp (by rw [card_powersetLen, Nat.choose_eq_zero_of_lt h])\n#align finset.powerset_len_empty Finset.powersetLen_empty\n\ntheorem powersetLen_eq_filter {n} {s : Finset \u03b1} :\n    powersetLen n s = (powerset s).filter fun x => x.card = n :=\n  by\n  ext\n  simp [mem_powersetLen]\n#align finset.powerset_len_eq_filter Finset.powersetLen_eq_filter\n\ntheorem powersetLen_succ_insert [DecidableEq \u03b1] {x : \u03b1} {s : Finset \u03b1} (h : x \u2209 s) (n : \u2115) :\n    powersetLen n.succ (insert x s) = powersetLen n.succ s \u222a (powersetLen n s).image (insert x) :=\n  by\n  rw [powersetLen_eq_filter, powerset_insert, filter_union, \u2190 powersetLen_eq_filter]\n  congr\n  rw [powersetLen_eq_filter, image_filter]\n  congr 1\n  ext t\n  simp only [mem_powerset, mem_filter, Function.comp_apply, and_congr_right_iff]\n  intro ht\n  have : x \u2209 t := fun H => h (ht H)\n  simp [card_insert_of_not_mem this, Nat.succ_inj']\n#align finset.powerset_len_succ_insert Finset.powersetLen_succ_insert\n\ntheorem powersetLen_nonempty {n : \u2115} {s : Finset \u03b1} (h : n \u2264 s.card) :\n    (powersetLen n s).Nonempty := by\n  classical\n    induction' s using Finset.induction_on with x s hx IH generalizing n\n    \u00b7 rw [card_empty, le_zero_iff] at h\n      rw [h, powersetLen_zero]\n      exact Finset.singleton_nonempty _\n    \u00b7 cases n\n      \u00b7 simp\n      \u00b7 rw [card_insert_of_not_mem hx, Nat.succ_le_succ_iff] at h\n        rw [powersetLen_succ_insert hx]\n        refine' Nonempty.mono _ ((IH h).image (insert x))\n        exact subset_union_right _ _\n#align finset.powerset_len_nonempty Finset.powersetLen_nonempty\n\n@[simp]\ntheorem powersetLen_self (s : Finset \u03b1) : powersetLen s.card s = {s} :=\n  by\n  ext\n  rw [mem_powersetLen, mem_singleton]\n  constructor\n  \u00b7 exact fun \u27e8hs, hc\u27e9 => eq_of_subset_of_card_le hs hc.ge\n  \u00b7 rintro rfl\n    simp\n#align finset.powerset_len_self Finset.powersetLen_self\n\ntheorem pairwise_disjoint_powersetLen (s : Finset \u03b1) :\n    Pairwise fun i j => Disjoint (s.powersetLen i) (s.powersetLen j) := fun _i _j hij =>\n  Finset.disjoint_left.mpr fun _x hi hj =>\n    hij <| (mem_powersetLen.mp hi).2.symm.trans (mem_powersetLen.mp hj).2\n#align finset.pairwise_disjoint_powerset_len Finset.pairwise_disjoint_powersetLen\n\ntheorem powerset_card_disjUnion\u1d62 (s : Finset \u03b1) :\n    Finset.powerset s =\n      (range (s.card + 1)).disjUnion\u1d62 (fun i => powersetLen i s)\n        (s.pairwise_disjoint_powersetLen.set_pairwise _) :=\n  by\n  refine' ext fun a => \u27e8fun ha => _, fun ha => _\u27e9\n  \u00b7 rw [mem_disjUnion\u1d62]\n    exact\n      \u27e8a.card, mem_range.mpr (Nat.lt_succ_of_le (card_le_of_subset (mem_powerset.mp ha))),\n        mem_powersetLen.mpr \u27e8mem_powerset.mp ha, rfl\u27e9\u27e9\n  \u00b7 rcases mem_disjUnion\u1d62.mp ha with \u27e8i, _hi, ha\u27e9\n    exact mem_powerset.mpr (mem_powersetLen.mp ha).1\n#align finset.powerset_card_disj_Union Finset.powerset_card_disjUnion\u1d62\n\ntheorem powerset_card_bunion\u1d62 [DecidableEq (Finset \u03b1)] (s : Finset \u03b1) :\n    Finset.powerset s = (range (s.card + 1)).bunion\u1d62 fun i => powersetLen i s := by\n  simpa only [disjUnion\u1d62_eq_bunion\u1d62] using powerset_card_disjUnion\u1d62 s\n#align finset.powerset_card_bUnion Finset.powerset_card_bunion\u1d62\n\ntheorem powerset_len_sup [DecidableEq \u03b1] (u : Finset \u03b1) (n : \u2115) (hn : n < u.card) :\n    (powersetLen n.succ u).sup id = u := by\n  apply le_antisymm\n  \u00b7 simp_rw [Finset.sup_le_iff, mem_powersetLen]\n    rintro x \u27e8h, -\u27e9\n    exact h\n  \u00b7 rw [sup_eq_bunion\u1d62, le_iff_subset, subset_iff]\n    cases' (Nat.succ_le_of_lt hn).eq_or_lt with h' h'\n    \u00b7 simp [h']\n    \u00b7 intro x hx\n      simp only [mem_bunion\u1d62, exists_prop, id.def]\n      obtain \u27e8t, ht\u27e9 : \u2203 t, t \u2208 powersetLen n (u.erase x) := powersetLen_nonempty\n        (le_trans (Nat.le_pred_of_lt hn) pred_card_le_card_erase)\n      \u00b7 refine' \u27e8insert x t, _, mem_insert_self _ _\u27e9\n        rw [\u2190 insert_erase hx, powersetLen_succ_insert (not_mem_erase _ _)]\n        exact mem_union_right _ (mem_image_of_mem _ ht)\n#align finset.powerset_len_sup Finset.powerset_len_sup\n\n@[simp]\ntheorem powersetLen_card_add (s : Finset \u03b1) {i : \u2115} (hi : 0 < i) :\n    s.powersetLen (s.card + i) = \u2205 :=\n  Finset.powersetLen_empty _ (lt_add_of_pos_right (Finset.card s) hi)\n#align finset.powerset_len_card_add Finset.powersetLen_card_add\n\n@[simp]\ntheorem map_val_val_powersetLen (s : Finset \u03b1) (i : \u2115) :\n    (s.powersetLen i).val.map Finset.val = s.1.powersetLen i := by\n  simp [Finset.powersetLen, map_pmap, pmap_eq_map, map_id']\n#align finset.map_val_val_powerset_len Finset.map_val_val_powersetLen\n\ntheorem powersetLen_map {\u03b2 : Type _} (f : \u03b1 \u21aa \u03b2) (n : \u2115) (s : Finset \u03b1) :\n    powersetLen n (s.map f) = (powersetLen n s).map (mapEmbedding f).toEmbedding :=\n  ext <| fun t => by\n    simp only [card_map, mem_powersetLen, le_eq_subset, gt_iff_lt, mem_map, mapEmbedding_apply]\n    constructor\n    . classical\n      intro h\n      have : map f (filter (fun x => (f x \u2208 t)) s) = t := by\n        ext x\n        simp only [mem_map, mem_filter, decide_eq_true_eq]\n        exact \u27e8fun \u27e8_y, \u27e8_hy\u2081, hy\u2082\u27e9, hy\u2083\u27e9 => hy\u2083 \u25b8 hy\u2082,\n          fun hx => let \u27e8y, hy\u27e9 := mem_map.1 (h.1 hx); \u27e8y, \u27e8hy.1, hy.2 \u25b8 hx\u27e9, hy.2\u27e9\u27e9\n      refine' \u27e8_, _, this\u27e9\n      rw [\u2190 card_map f, this, h.2]; simp\n    . rintro \u27e8a, \u27e8has, rfl\u27e9, rfl\u27e9\n      simp [*]\n#align finset.powerset_len_map Finset.powersetLen_map\n\nend PowersetLen\n\nend Finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Finset/Powerset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571774, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7338579740194934}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johan Commelin\n-/\nimport data.polynomial.field_division\nimport ring_theory.integral_closure\nimport ring_theory.polynomial.gauss_lemma\n\n/-!\n# Minimal polynomials\n\nThis file defines the minimal polynomial of an element `x` of an `A`-algebra `B`,\nunder the assumption that x is integral over `A`.\n\nAfter stating the defining property we specialize to the setting of field extensions\nand derive some well-known properties, amongst which the fact that minimal polynomials\nare irreducible, and uniquely determined by their defining property.\n\n-/\n\nopen_locale classical\nopen polynomial set function\n\nvariables {A B : Type*}\n\nsection min_poly_def\nvariables (A) [comm_ring A] [ring B] [algebra A B]\n\n/--\nSuppose `x : B`, where `B` is an `A`-algebra.\n\nThe minimal polynomial `minpoly A x` of `x`\nis a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root,\nif such exists (`is_integral A x`) or zero otherwise.\n\nFor example, if `V` is a `\ud835\udd5c`-vector space for some field `\ud835\udd5c` and `f : V \u2192\u2097[\ud835\udd5c] V` then\nthe minimal polynomial of `f` is `minpoly \ud835\udd5c f`.\n-/\nnoncomputable def minpoly (x : B) : polynomial A :=\nif hx : is_integral A x then well_founded.min degree_lt_wf _ hx else 0\n\nend min_poly_def\n\nnamespace minpoly\n\nsection ring\nvariables [comm_ring A] [ring B] [algebra A B]\nvariables {x : B}\n\n/-- A minimal polynomial is monic. -/\nlemma monic (hx : is_integral A x) : monic (minpoly A x) :=\nby { delta minpoly, rw dif_pos hx, exact (well_founded.min_mem degree_lt_wf _ hx).1 }\n\n/-- A minimal polynomial is nonzero. -/\nlemma ne_zero [nontrivial A] (hx : is_integral A x) : minpoly A x \u2260 0 :=\nne_zero_of_monic (monic hx)\n\nlemma eq_zero (hx : \u00ac is_integral A x) : minpoly A x = 0 :=\ndif_neg hx\n\nvariables (A x)\n\n/-- An element is a root of its minimal polynomial. -/\n@[simp] lemma aeval : aeval x (minpoly A x) = 0 :=\nbegin\n  delta minpoly, split_ifs with hx,\n  { exact (well_founded.min_mem degree_lt_wf _ hx).2 },\n  { exact aeval_zero _ }\nend\n\nlemma mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) : x \u2208 (algebra_map A B).range :=\nbegin\n  have h : is_integral A x,\n  { by_contra h,\n    rw [eq_zero h, degree_zero, \u2190with_bot.coe_one] at hx,\n    exact (ne_of_lt (show \u22a5 < \u21911, from with_bot.bot_lt_coe 1) hx) },\n  have key := minpoly.aeval A x,\n  rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leading_coeff, C_1, one_mul, aeval_add,\n      aeval_C, aeval_X, \u2190eq_neg_iff_add_eq_zero, \u2190ring_hom.map_neg] at key,\n  exact \u27e8-(minpoly A x).coeff 0, key.symm\u27e9,\nend\n\n/-- The defining property of the minimal polynomial of an element `x`:\nit is the monic polynomial with smallest degree that has `x` as its root. -/\nlemma min {p : polynomial A} (pmonic : p.monic) (hp : polynomial.aeval x p = 0) :\n  degree (minpoly A x) \u2264 degree p :=\nbegin\n  delta minpoly, split_ifs with hx,\n  { exact le_of_not_lt (well_founded.not_lt_min degree_lt_wf _ hx \u27e8pmonic, hp\u27e9) },\n  { simp only [degree_zero, bot_le] }\nend\n\nend ring\n\nsection integral_domain\n\nvariables [integral_domain A]\n\nsection ring\n\nvariables [ring B] [algebra A B] [nontrivial B]\nvariables {x : B}\n\n/-- The degree of a minimal polynomial, as a natural number, is positive. -/\nlemma nat_degree_pos (hx : is_integral A x) : 0 < nat_degree (minpoly A x) :=\nbegin\n  rw pos_iff_ne_zero,\n  intro ndeg_eq_zero,\n  have eq_one : minpoly A x = 1,\n  { rw eq_C_of_nat_degree_eq_zero ndeg_eq_zero, convert C_1,\n    simpa only [ndeg_eq_zero.symm] using (monic hx).leading_coeff },\n  simpa only [eq_one, alg_hom.map_one, one_ne_zero] using aeval A x\nend\n\n/-- The degree of a minimal polynomial is positive. -/\nlemma degree_pos (hx : is_integral A x) : 0 < degree (minpoly A x) :=\nnat_degree_pos_iff_degree_pos.mp (nat_degree_pos hx)\n\n/-- If `B/A` is an injective ring extension, and `a` is an element of `A`,\nthen the minimal polynomial of `algebra_map A B a` is `X - C a`. -/\nlemma eq_X_sub_C_of_algebra_map_inj [nontrivial A]\n  (a : A) (hf : function.injective (algebra_map A B)) :\n  minpoly A (algebra_map A B a) = X - C a :=\nbegin\n  have hdegle : (minpoly A (algebra_map A B a)).nat_degree \u2264 1,\n  { apply with_bot.coe_le_coe.1,\n    rw [\u2190degree_eq_nat_degree (ne_zero (@is_integral_algebra_map A B _ _ _ a)),\n      with_top.coe_one, \u2190degree_X_sub_C a],\n    refine min A (algebra_map A B a) (monic_X_sub_C a) _,\n    simp only [aeval_C, aeval_X, alg_hom.map_sub, sub_self] },\n  have hdeg : (minpoly A (algebra_map A B a)).degree = 1,\n  { apply (degree_eq_iff_nat_degree_eq (ne_zero (@is_integral_algebra_map A B _ _ _ a))).2,\n    apply le_antisymm hdegle (nat_degree_pos (@is_integral_algebra_map A B _ _ _ a)) },\n  have hrw := eq_X_add_C_of_degree_eq_one hdeg,\n  simp only [monic (@is_integral_algebra_map A B _ _ _ a), one_mul,\n    monic.leading_coeff, ring_hom.map_one] at hrw,\n  have h0 : (minpoly A (algebra_map A B a)).coeff 0 = -a,\n  { have hroot := aeval A (algebra_map A B a),\n    rw [hrw, add_comm] at hroot,\n    simp only [aeval_C, aeval_X, aeval_add] at hroot,\n    replace hroot := eq_neg_of_add_eq_zero hroot,\n    rw [\u2190ring_hom.map_neg _ a] at hroot,\n    exact (hf hroot) },\n  rw hrw,\n  simp only [h0, ring_hom.map_neg, sub_eq_add_neg],\nend\n\nvariables (A x)\n\n/-- A minimal polynomial is not a unit. -/\nlemma not_is_unit : \u00ac is_unit (minpoly A x) :=\nbegin\n  by_cases hx : is_integral A x,\n  { assume H, exact (ne_of_lt (degree_pos hx)).symm (degree_eq_zero_of_is_unit H) },\n  { delta minpoly, rw dif_neg hx, simp only [not_is_unit_zero, not_false_iff] }\nend\n\nend ring\n\nsection domain\n\nvariables [domain B] [algebra A B]\nvariables {x : B}\n\n/-- If `a` strictly divides the minimal polynomial of `x`, then `x` cannot be a root for `a`. -/\nlemma aeval_ne_zero_of_dvd_not_unit_minpoly {a : polynomial A} (hx : is_integral A x)\n  (hamonic : a.monic) (hdvd : dvd_not_unit a (minpoly A x)) :\n  polynomial.aeval x a \u2260 0 :=\nbegin\n  intro ha,\n  refine not_lt_of_ge (minpoly.min A x hamonic ha) _,\n  obtain \u27e8hzeroa, b, hb_nunit, prod\u27e9 := hdvd,\n  have hbmonic : b.monic,\n  { rw monic.def,\n    have := monic hx,\n    rwa [monic.def, prod, leading_coeff_mul, monic.def.mp hamonic, one_mul] at this },\n  have hzerob : b \u2260 0 := hbmonic.ne_zero,\n  have degbzero : 0 < b.nat_degree,\n  { apply nat.pos_of_ne_zero,\n    intro h,\n    have h\u2081 := eq_C_of_nat_degree_eq_zero h,\n    rw [\u2190h, \u2190leading_coeff, monic.def.1 hbmonic, C_1] at h\u2081,\n    rw h\u2081 at hb_nunit,\n    have := is_unit_one,\n    contradiction },\n  rw [prod, degree_mul, degree_eq_nat_degree hzeroa, degree_eq_nat_degree hzerob],\n  exact_mod_cast lt_add_of_pos_right _ degbzero,\nend\n\n/-- A minimal polynomial is irreducible. -/\nlemma irreducible (hx : is_integral A x) : irreducible (minpoly A x) :=\nbegin\n  cases irreducible_or_factor (minpoly A x) (not_is_unit A x) with hirr hred,\n  { exact hirr },\n  exfalso,\n  obtain \u27e8a, b, ha_nunit, hb_nunit, hab_eq\u27e9 := hred,\n  have coeff_prod : a.leading_coeff * b.leading_coeff = 1,\n  { rw [\u2190monic.def.1 (monic hx), \u2190hab_eq],\n    simp only [leading_coeff_mul] },\n  have hamonic : (a * C b.leading_coeff).monic,\n  { rw monic.def,\n    simp only [coeff_prod, leading_coeff_mul, leading_coeff_C] },\n  have hbmonic : (b * C a.leading_coeff).monic,\n  { rw [monic.def, mul_comm],\n    simp only [coeff_prod, leading_coeff_mul, leading_coeff_C] },\n  have prod : minpoly A x = (a * C b.leading_coeff) * (b * C a.leading_coeff),\n  { symmetry,\n    calc a * C b.leading_coeff * (b * C a.leading_coeff)\n        = a * b * (C a.leading_coeff * C b.leading_coeff) : by ring\n    ... = a * b * (C (a.leading_coeff * b.leading_coeff)) : by simp only [ring_hom.map_mul]\n    ... = a * b : by rw [coeff_prod, C_1, mul_one]\n    ... = minpoly A x : hab_eq },\n  have hzero := aeval A x,\n  rw [prod, aeval_mul, mul_eq_zero] at hzero,\n  cases hzero,\n  { refine aeval_ne_zero_of_dvd_not_unit_minpoly hx hamonic _ hzero,\n    exact \u27e8hamonic.ne_zero, _, mt is_unit_of_mul_is_unit_left hb_nunit, prod\u27e9 },\n  { refine aeval_ne_zero_of_dvd_not_unit_minpoly hx hbmonic _ hzero,\n    rw mul_comm at prod,\n    exact \u27e8hbmonic.ne_zero, _, mt is_unit_of_mul_is_unit_left ha_nunit, prod\u27e9 },\nend\n\nend domain\n\nend integral_domain\n\nsection field\nvariables [field A]\n\nsection ring\nvariables [ring B] [algebra A B]\nvariables {x : B}\n\nvariables (A x)\n\n/-- If an element `x` is a root of a nonzero polynomial `p`,\nthen the degree of `p` is at least the degree of the minimal polynomial of `x`. -/\nlemma degree_le_of_ne_zero\n  {p : polynomial A} (pnz : p \u2260 0) (hp : polynomial.aeval x p = 0) :\n  degree (minpoly A x) \u2264 degree p :=\ncalc degree (minpoly A x) \u2264 degree (p * C (leading_coeff p)\u207b\u00b9) :\n    min A x (monic_mul_leading_coeff_inv pnz) (by simp [hp])\n  ... = degree p : degree_mul_leading_coeff_inv p pnz\n\n/-- The minimal polynomial of an element `x` is uniquely characterized by its defining property:\nif there is another monic polynomial of minimal degree that has `x` as a root,\nthen this polynomial is equal to the minimal polynomial of `x`. -/\nlemma unique {p : polynomial A}\n  (pmonic : p.monic) (hp : polynomial.aeval x p = 0)\n  (pmin : \u2200 q : polynomial A, q.monic \u2192 polynomial.aeval x q = 0 \u2192 degree p \u2264 degree q) :\n  p = minpoly A x :=\nbegin\n  have hx : is_integral A x := \u27e8p, pmonic, hp\u27e9,\n  symmetry, apply eq_of_sub_eq_zero,\n  by_contra hnz,\n  have := degree_le_of_ne_zero A x hnz (by simp [hp]),\n  contrapose! this,\n  apply degree_sub_lt _ (ne_zero hx),\n  { rw [(monic hx).leading_coeff, pmonic.leading_coeff] },\n  { exact le_antisymm (min A x pmonic hp)\n      (pmin (minpoly A x) (monic hx) (aeval A x)) }\nend\n\n/-- If an element `x` is a root of a polynomial `p`,\nthen the minimal polynomial of `x` divides `p`. -/\nlemma dvd {p : polynomial A} (hp : polynomial.aeval x p = 0) : minpoly A x \u2223 p :=\nbegin\n  by_cases hp0 : p = 0,\n  { simp only [hp0, dvd_zero] },\n  have hx : is_integral A x,\n  { rw \u2190 is_algebraic_iff_is_integral, exact \u27e8p, hp0, hp\u27e9 },\n  rw \u2190 dvd_iff_mod_by_monic_eq_zero (monic hx),\n  by_contra hnz,\n  have := degree_le_of_ne_zero A x hnz _,\n  { contrapose! this,\n    exact degree_mod_by_monic_lt _ (monic hx) (ne_zero hx) },\n  { rw \u2190 mod_by_monic_add_div p (monic hx) at hp,\n    simpa using hp }\nend\n\nlemma dvd_map_of_is_scalar_tower (A K : Type*) {R : Type*} [comm_ring A] [field K] [comm_ring R]\n  [algebra A K] [algebra A R] [algebra K R] [is_scalar_tower A K R] (x : R) :\n  minpoly K x \u2223 (minpoly A x).map (algebra_map A K) :=\nby { refine minpoly.dvd K x _, rw [\u2190 is_scalar_tower.aeval_apply, minpoly.aeval] }\n\nvariables {A x}\n\ntheorem unique' [nontrivial B] {p : polynomial A} (hp1 : _root_.irreducible p)\n  (hp2 : polynomial.aeval x p = 0) (hp3 : p.monic) : p = minpoly A x :=\nlet \u27e8q, hq\u27e9 := dvd A x hp2 in\neq_of_monic_of_associated hp3 (monic \u27e8p, \u27e8hp3, hp2\u27e9\u27e9) $\nmul_one (minpoly A x) \u25b8 hq.symm \u25b8 associated_mul_mul (associated.refl _) $\nassociated_one_iff_is_unit.2 $ (hp1.is_unit_or_is_unit hq).resolve_left $ not_is_unit A x\n\n/-- If `y` is the image of `x` in an extension, their minimal polynomials coincide.\n\nWe take `h : y = algebra_map L T x` as an argument because `rw h` typically fails\nsince `is_integral R y` depends on y.\n-/\nlemma eq_of_algebra_map_eq {K S T : Type*} [field K] [comm_ring S] [comm_ring T]\n  [algebra K S] [algebra K T] [algebra S T]\n  [is_scalar_tower K S T] (hST : function.injective (algebra_map S T))\n  {x : S} {y : T} (hx : is_integral K x) (h : y = algebra_map S T x) :\n  minpoly K x = minpoly K y :=\nminpoly.unique _ _ (minpoly.monic hx)\n  (by rw [h, \u2190 is_scalar_tower.algebra_map_aeval, minpoly.aeval, ring_hom.map_zero])\n  (\u03bb q q_monic root_q, minpoly.min _ _ q_monic\n    (is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero K S T hST\n      (h \u25b8 root_q : polynomial.aeval (algebra_map S T x) q = 0)))\n\nsection gcd_domain\n\n/-- For GCD domains, the minimal polynomial over the ring is the same as the minimal polynomial\nover the fraction field. -/\nlemma gcd_domain_eq_field_fractions {A K R : Type*} [integral_domain A]\n  [gcd_monoid A] [field K] [integral_domain R] (f : fraction_map A K) [algebra f.codomain R]\n  [algebra A R] [is_scalar_tower A f.codomain R] {x : R} (hx : is_integral A x) :\n  minpoly f.codomain x = (minpoly A x).map (localization_map.to_ring_hom f) :=\nbegin\n  refine (unique' _ _ _).symm,\n  { exact (polynomial.is_primitive.irreducible_iff_irreducible_map_fraction_map f\n  (polynomial.monic.is_primitive (monic hx))).1 (irreducible hx) },\n  { have htower := is_scalar_tower.aeval_apply A f.codomain R x (minpoly A x),\n    simp only [localization_map.algebra_map_eq, aeval] at htower,\n    exact htower.symm },\n  { exact monic_map _ (monic hx) }\nend\n\n/-- The minimal polynomial over `\u2124` is the same as the minimal polynomial over `\u211a`. -/\n--TODO use `gcd_domain_eq_field_fractions` directly when localizations are defined\n-- in terms of algebras instead of `ring_hom`s\nlemma over_int_eq_over_rat {A : Type*} [integral_domain A] {x : A} [h\u211aA : algebra \u211a A]\n  (hx : is_integral \u2124 x) :\n  minpoly \u211a x = map (int.cast_ring_hom \u211a) (minpoly \u2124 x) :=\nbegin\n  refine (unique' _ _ _).symm,\n  { exact (is_primitive.int.irreducible_iff_irreducible_map_cast\n  (polynomial.monic.is_primitive (monic hx))).1 (irreducible hx) },\n  { have htower := is_scalar_tower.aeval_apply \u2124 \u211a A x (minpoly \u2124 x),\n    simp only [localization_map.algebra_map_eq, aeval] at htower,\n    exact htower.symm },\n  { exact monic_map _ (monic hx) }\nend\n\n/-- For GCD domains, the minimal polynomial divides any primitive polynomial that has the integral\nelement as root. -/\nlemma gcd_domain_dvd {A K R : Type*}\n  [integral_domain A] [gcd_monoid A] [field K] [integral_domain R]\n  (f : fraction_map A K) [algebra f.codomain R] [algebra A R] [is_scalar_tower A f.codomain R]\n  {x : R} (hx : is_integral A x)\n  {P : polynomial A} (hprim : is_primitive P) (hroot : polynomial.aeval x P = 0) :\n  minpoly A x \u2223 P :=\nbegin\n  apply (is_primitive.dvd_iff_fraction_map_dvd_fraction_map f\n    (monic.is_primitive (monic hx)) hprim ).2,\n  rw [\u2190 gcd_domain_eq_field_fractions f hx],\n  refine dvd _ _ _,\n  rwa [\u2190 localization_map.algebra_map_eq, \u2190 is_scalar_tower.aeval_apply]\nend\n\n/-- The minimal polynomial over `\u2124` divides any primitive polynomial that has the integral element\nas root. -/\n-- TODO use `gcd_domain_dvd` directly when localizations are defined in terms of algebras\n-- instead of `ring_hom`s\nlemma integer_dvd {A : Type*} [integral_domain A] [algebra \u211a A] {x : A} (hx : is_integral \u2124 x)\n  {P : polynomial \u2124} (hprim : is_primitive P) (hroot : polynomial.aeval x P = 0) :\n  minpoly \u2124 x \u2223 P :=\nbegin\n  apply (is_primitive.int.dvd_iff_map_cast_dvd_map_cast _ _\n    (monic.is_primitive (monic hx)) hprim ).2,\n  rw [\u2190 over_int_eq_over_rat hx],\n  refine dvd _ _ _,\n  rwa [(int.cast_ring_hom \u211a).ext_int (algebra_map \u2124 \u211a), \u2190 is_scalar_tower.aeval_apply]\nend\n\nend gcd_domain\n\nvariables (B) [nontrivial B]\n\n/-- If `B/K` is a nontrivial algebra over a field, and `x` is an element of `K`,\nthen the minimal polynomial of `algebra_map K B x` is `X - C x`. -/\nlemma eq_X_sub_C (a : A) : minpoly A (algebra_map A B a) = X - C a :=\neq_X_sub_C_of_algebra_map_inj a (algebra_map A B).injective\n\nlemma eq_X_sub_C' (a : A) : minpoly A a = X - C a := eq_X_sub_C A a\n\nvariables (A)\n\n/-- The minimal polynomial of `0` is `X`. -/\n@[simp] lemma zero : minpoly A (0:B) = X :=\nby simpa only [add_zero, C_0, sub_eq_add_neg, neg_zero, ring_hom.map_zero]\n  using eq_X_sub_C B (0:A)\n\n/-- The minimal polynomial of `1` is `X - 1`. -/\n@[simp] lemma one : minpoly A (1:B) = X - 1 :=\nby simpa only [ring_hom.map_one, C_1, sub_eq_add_neg] using eq_X_sub_C B (1:A)\n\nend ring\n\nsection domain\nvariables [domain B] [algebra A B]\nvariables {x : B}\n\n/-- A minimal polynomial is prime. -/\nlemma prime (hx : is_integral A x) : prime (minpoly A x) :=\nbegin\n  refine \u27e8ne_zero hx, not_is_unit A x, _\u27e9,\n  rintros p q \u27e8d, h\u27e9,\n  have :    polynomial.aeval x (p*q) = 0 := by simp [h, aeval A x],\n  replace : polynomial.aeval x p = 0 \u2228 polynomial.aeval x q = 0 := by simpa,\n  exact or.imp (dvd A x) (dvd A x) this\nend\n\n/-- If `L/K` is a field extension and an element `y` of `K` is a root of the minimal polynomial\nof an element `x \u2208 L`, then `y` maps to `x` under the field embedding. -/\nlemma root {x : B} (hx : is_integral A x) {y : A} (h : is_root (minpoly A x) y) :\n  algebra_map A B y = x :=\nhave key : minpoly A x = X - C y :=\neq_of_monic_of_associated (monic hx) (monic_X_sub_C y) (associated_of_dvd_dvd\n  (dvd_symm_of_irreducible (irreducible_X_sub_C y) (irreducible hx) (dvd_iff_is_root.2 h))\n  (dvd_iff_is_root.2 h)),\nby { have := aeval A x, rwa [key, alg_hom.map_sub, aeval_X, aeval_C, sub_eq_zero, eq_comm] at this }\n\n/-- The constant coefficient of the minimal polynomial of `x` is `0` if and only if `x = 0`. -/\n@[simp] lemma coeff_zero_eq_zero (hx : is_integral A x) : coeff (minpoly A x) 0 = 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    have zero_root := zero_is_root_of_coeff_zero_eq_zero h,\n    rw \u2190 root hx zero_root,\n    exact ring_hom.map_zero _ },\n  { rintro rfl, simp }\nend\n\n/-- The minimal polynomial of a nonzero element has nonzero constant coefficient. -/\nlemma coeff_zero_ne_zero (hx : is_integral A x) (h : x \u2260 0) : coeff (minpoly A x) 0 \u2260 0 :=\nby { contrapose! h, simpa only [hx, coeff_zero_eq_zero] using h }\n\nend domain\n\nend field\n\nend minpoly\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/field_theory/minpoly.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7338410435758874}}
{"text": "import data.real.basic\nopen function\n\n/-\n# Chapter 6 : Functions\n\n## Level 5\n\nA classical result in composition of functions.\nNow going the other way around.\n-/\n\n/- Lemma\nIf composition of $f$ and $g$ is injective, then $f$ is injective.\n-/\ntheorem composition_injective \n    (X Y Z : set \u211d) (f : X \u2192 Y) (g : Y \u2192 Z) : injective (g \u2218 f) \u2192 injective f :=\nbegin\n    intros h a b ha,\n    have applyg : g (f a) = g (f a), refl,\n    rw ha at applyg {occs := occurrences.pos [2]},\n    apply h,\n    exact applyg, done \nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/functions/composition_injective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.73380538493725}}
{"text": "import game.limits.L01defs\nimport game.limits.seq_limitTimesConst\n\nnamespace xena -- hide\n\nnotation `|` x `|` := abs x -- hide\n\n/-\nUse the previous results to obtain linearity.\n-/\n\n\n/- Lemma\nIf $\\lim_{n \\to \\infty} a_n = \\alpha$ and $\\lim_{n \\to \\infty} b_n = \\beta$\nand $c$ is a constant, then \n$\\lim_{n \\to \\infty} ( c * a_n + c * b_n) = c \\alpha + c \\beta$\n-/\nlemma lim_linear (a : \u2115 \u2192 \u211d) (b : \u2115 \u2192 \u211d) (\u03b1 \u03b2 c d : \u211d) \n    (ha : is_limit a \u03b1) (hb : is_limit b \u03b2) : \n    is_limit ( \u03bb n, c * (a n) + d * (b n) ) (c * \u03b1 + d * \u03b2) :=\nbegin\n    apply lim_add,\n    exact lim_times_const a \u03b1 c ha,\n    exact lim_times_const b \u03b2 d hb,\n    done\nend\n\nend xena -- hide\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/limits/seq_limitLinear.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686199, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7338053841755022}}
{"text": "/- LoVe Demo 5: Inductive Predicates -/\n\nimport .love04_functional_programming_demo\n\nnamespace LoVe\n\n\n/- Introductory Example -/\n\ninductive even : \u2115 \u2192 Prop\n| zero    : even 0\n| add_two : \u2200n, even n \u2192 even (n + 2)\n\n\n/- Logical Symbols -/\n\n#print false\n#print true\n#print and\n#print or\n#print Exists\n#print eq\n\n#check nat.le.dest\n\nlemma nat.le.dest2 :\n  \u2200n m : \u2115, n \u2264 m \u2192 \u2203k, k + n = m :=\nbegin\n  intros n m h_gt,\n  cases @nat.le.dest n m h_gt with k nk_eq_m,\n  use k,\n  linarith\nend\n\n\n/- Example: Full Binary Trees -/\n\n#check btree\n\ninductive is_full {\u03b1 : Type} : btree \u03b1 \u2192 Prop\n| empty : is_full empty\n| node (a : \u03b1) (l r : btree \u03b1) (hl : is_full l) (hr : is_full r)\n    (empty_iff : l = empty \u2194 r = empty) :\n  is_full (node a l r)\n\ninductive is_full\u2082 {\u03b1 : Type} : btree \u03b1 \u2192 Prop\n| empty : is_full\u2082 empty\n| node : \u2200(a : \u03b1) (l r : btree \u03b1), is_full\u2082 l \u2192 is_full\u2082 r \u2192\n    (l = empty \u2194 r = empty) \u2192\n  is_full\u2082 (node a l r)\n\nlemma is_full_singleton {\u03b1 : Type} (a : \u03b1) :\n  is_full (node a empty empty) :=\nbegin\n  apply is_full.node,\n  repeat { apply is_full.empty },\n  refl\nend\n\nlemma is_full_t0 :\n  is_full t0 :=\nis_full_singleton _\n\nlemma is_full_t1 :\n  is_full t1 :=\nis_full_singleton _\n\nlemma is_full_t2 :\n  is_full t2 :=\nbegin\n  rw t2,\n  apply is_full.node,\n  { exact is_full_t0 },\n  { exact is_full_t1 },\n  { simp [t0, t1] }\nend\n\nlemma is_full_mirror {\u03b1 : Type} :\n  \u2200t : btree \u03b1, is_full t \u2192 is_full (mirror t)\n| empty        := by intro; assumption\n| (node a l r) :=\n  begin\n    intro full_t,\n    cases full_t,\n    rw mirror,\n    apply is_full.node,\n    repeat { apply is_full_mirror, assumption },\n    simp [mirror_eq_empty_iff, *]\n  end\n\nlemma is_full_mirror\u2082 {\u03b1 : Type} :\n  \u2200t : btree \u03b1, is_full t \u2192 is_full (mirror t)\n| _ is_full.empty :=\n  begin\n    rw mirror,\n    exact is_full.empty\n  end\n| _ (is_full.node a l r hl hr empty_iff) :=\n  begin\n    rw mirror,\n    apply is_full.node,\n    repeat { apply is_full_mirror\u2082, assumption },\n    simp [mirror_eq_empty_iff, *]\n  end\n\nlemma is_full_node_iff {\u03b1 : Type} (a : \u03b1) (l r : btree \u03b1) :\n  is_full (node a l r) \u2194\n  is_full l \u2227 is_full r \u2227 (l = empty \u2194 r = empty) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases h,\n    cc },\n  { intro h,\n    apply is_full.node,\n    repeat { cc } }\nend\n\nlemma is_full_mirror\u2083 {\u03b1 : Type} :\n  \u2200t : btree \u03b1, is_full t \u2192 is_full (mirror t)\n| _ is_full.empty                        :=\n  by rw mirror; exact is_full.empty\n| _ (is_full.node a l r hl hr empty_iff) :=\n  by simp [mirror, is_full_node_iff, is_full_mirror\u2083 l hl,\n    is_full_mirror\u2083 r hr, mirror_eq_empty_iff, empty_iff]\n\n\n/- Example: Sorted Lists -/\n\ninductive sorted : list \u2115 \u2192 Prop\n| nil : sorted []\n| single {x : \u2115} : sorted [x]\n| two_or_more {x y : \u2115} {xs : list \u2115} (xy : x \u2264 y)\n    (yxs : sorted (y :: xs)) :\n  sorted (x :: y :: xs)\n\nexample :\n  sorted [] :=\nsorted.nil\n\nexample :\n  sorted [2] :=\nsorted.single\n\nexample :\n  sorted [3, 5] :=\nbegin\n  apply sorted.two_or_more,\n  { linarith },\n  { exact sorted.single }\nend\n\nexample :\n  sorted [3, 5] :=\nsorted.two_or_more (by linarith) sorted.single\n\nexample :\n  sorted [7, 9, 9, 11] :=\nsorted.two_or_more (by linarith)\n  (sorted.two_or_more (by linarith)\n    (sorted.two_or_more (by linarith)\n      sorted.single))\n\nexample :\n  \u00ac sorted [17, 13] :=\nassume h : sorted [17, 13],\nhave 17 \u2264 13 :=\n  match h with\n  | sorted.two_or_more xy yxs := xy\n  end,\nhave \u00ac (17 \u2264 13) := by linarith,\nshow false, from by cc\n\n\n/- Example: Well-formed and Ground First-Order Terms -/\n\ninductive term (\u03b1 \u03b2 : Type) : Type\n| var {} : \u03b2 \u2192 term\n| fn     : \u03b1 \u2192 list term \u2192 term\n\nexport term (var fn)\n\ninductive well_formed {\u03b1 \u03b2 : Type} (arity : \u03b1 \u2192 \u2115) :\n  term \u03b1 \u03b2 \u2192 Prop\n| var (x : \u03b2) : well_formed (var x)\n| fn (f : \u03b1) (ts : list (term \u03b1 \u03b2))\n    (hargs : \u2200t \u2208 ts, well_formed t)\n    (hlen : list.length ts = arity f) :\n  well_formed (fn f ts)\n\ninductive variable_free {\u03b1 \u03b2 : Type} : term \u03b1 \u03b2 \u2192 Prop\n| fn (f : \u03b1) (ts : list (term \u03b1 \u03b2))\n    (hargs : \u2200t \u2208 ts, variable_free t) :\n  variable_free (fn f ts)\n\n\n/- Example: Reflexive Transitive Closure -/\n\ninductive rtc {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : \u03b1 \u2192 \u03b1 \u2192 Prop\n| base (a b : \u03b1) : r a b \u2192 rtc a b\n| refl (a : \u03b1) : rtc a a\n| trans (a b c : \u03b1) : rtc a b \u2192 rtc b c \u2192 rtc a c\n\nlemma rtc_rtc_iff_rtc {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (a b : \u03b1) :\n  rtc (rtc r) a b \u2194 rtc r a b :=\nbegin\n  apply iff.intro,\n  { intro h,\n    induction h,\n    case rtc.base : x y {\n      assumption },\n    case rtc.refl : x {\n      apply rtc.refl },\n    case rtc.trans : x y z {\n      apply rtc.trans,\n      assumption,\n      assumption } },\n  { intro h,\n    apply rtc.base,\n    assumption }\nend\n\nlemma rtc_rtc_eq_rtc {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  rtc (rtc r) = rtc r :=\nbegin\n  apply funext,\n  intro a,\n  apply funext,\n  intro b,\n  apply propext,\n  apply rtc_rtc_iff_rtc\nend\n\n\n/- New Tactics -/\n\nexample {\u03b1 : Type} (a b c d : \u03b1) (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n    (hab : a = c) (hcd : b = d) :\n  f a b = f c d :=\nby cc\n\nexample (i : \u2124) (hagt : i > 5) :\n  2 * i > 8 :=\nby linarith\n\nexample (i : \u2124) :\n  1 + (i + -1) = i :=\nby norm_num\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love05_inductive_predicates_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.7338053835483626}}
{"text": "import data.real.basic\nimport lib.attempt\n\nnamespace challenges\n\n-- basic definitions\ndef upper_bounds (S : set \u211d) : set \u211d := { b | \u2200s \u2208 S, s \u2264 b }\ndef lower_bounds (S : set \u211d) : set \u211d := { b | \u2200s \u2208 S, b \u2264 s }\ndef is_least (S : set \u211d) (l : \u211d) : Prop := l \u2208 S \u2227 l \u2208 lower_bounds S\ndef is_lub (S : set \u211d) (l : \u211d) : Prop := is_least (upper_bounds S) l\n\n/-- A set has at most one least upper bound -/\ntheorem challenge2 (S : set \u211d) (a b : \u211d) (ha : is_lub S a) (hb : is_lub S b) : a = b :=\nattempt begin\n  unfold is_lub is_least upper_bounds lower_bounds at *,\n  cases ha with ha1 ha2,\n  cases hb with hb1 hb2,\n  unfold set_of has_mem.mem set.mem at *,\n  have hab := ha2 b hb1,\n  have hba := hb2 a ha1,\n  -- suggest,\n  exact le_antisymm (ha2 b hb1) (hb2 a ha1),\nend $\nbegin\n  exact le_antisymm (ha.2 b hb.1) (hb.2 a ha.1),\nend\n\nend challenges\n", "meta": {"author": "AtnNn", "repo": "lean-sandbox", "sha": "8c68afbdc09213173aef1be195da7a9a86060a97", "save_path": "github-repos/lean/AtnNn-lean-sandbox", "path": "github-repos/lean/AtnNn-lean-sandbox/lean-sandbox-8c68afbdc09213173aef1be195da7a9a86060a97/src/xena_challenge/challenge2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.7853085834000791, "lm_q1q2_score": 0.7337885457349632}}
{"text": "import .lovelib\n\n\n/-! # LoVe Homework 1: Definitions and Statements\n\nHomework must be done individually.\n\nReplace the placeholders (e.g., `:= sorry`) with your solutions. -/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (1 points): Snoc\n\n1.1 (1 point). Define the function `snoc` that appends a single element to the\nend of a list. Your function should be defined by recursion and not using `++`\n(`list.append`). -/\n\ndef snoc {\u03b1 : Type} : list \u03b1 \u2192 \u03b1 \u2192 list \u03b1\n| list.nil a := [a]\n| (list.cons head tail) a := list.cons head (snoc tail a)\n\n/-! 1.2 (0 point). Convince yourself that your definition of `snoc` works by\ntesting it on a few examples. -/\n\n#reduce snoc [1] 2\n-- invoke `#reduce` or `#eval` here\n\n\n/-! ## Question 2 (3 points): Map\n\n2.1 (1 point). Define a generic `map` function that applies a function to every\nelement in a list. -/\n\ndef map {\u03b1 : Type} {\u03b2 : Type} (f : \u03b1 \u2192 \u03b2) : list \u03b1 \u2192 list \u03b2\n| list.nil := list.nil\n| (list.cons head tail) := list.cons (f head) (map tail)\n\n/-! 2.2 (2 points). State (without proving them) the so-called functorial\nproperties of `map` as lemmas. Schematically:\n\n     map (\u03bbx, x) xs = xs\n     map (\u03bbx, g (f x)) xs = map g (map f xs)\n\nTry to give meaningful names to your lemmas. Also, make sure to state the second\nproperty as generally as possible, for arbitrary types. -/\n\n-- enter your lemma statements here\n\n\n/-! ## Question 3 (5 points): \u03bb-Terms\n\nWe start by declaring four new opaque types. -/\n\nconstants \u03b1 \u03b2 \u03b3 \u03b4 : Type\n\n/-! 3.1 (2 points). Complete the following definitions, by providing terms with\nthe expected type.\n\nPlease use reasonable names for the bound variables, e.g., `a : \u03b1`, `b : \u03b2`,\n`c : \u03b3`.\n\nHint: A procedure for doing so systematically is described in Section 1.1.4 of\nthe Hitchhiker's Guide. As explained there, you can use `_` as a placeholder\nwhile constructing a term. By hovering over `_`, you will see the current\nlogical context. -/\n\ndef B : (\u03b1 \u2192 \u03b2) \u2192 (\u03b3 \u2192 \u03b1) \u2192 \u03b3 \u2192 \u03b2 :=\n\u03bbf g a, f (g a)\n\ndef S : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 (\u03b1 \u2192 \u03b2) \u2192 \u03b1 \u2192 \u03b3 :=\n\u03bbf g a, f a (g a)\n\ndef more_nonsense : ((\u03b1 \u2192 \u03b2) \u2192 \u03b3 \u2192 \u03b4) \u2192 \u03b3 \u2192 \u03b2 \u2192 \u03b4 :=\n\u03bbf a b, f (\u03bbg, b) a\n\ndef even_more_nonsense : (\u03b1 \u2192 \u03b2) \u2192 (\u03b1 \u2192 \u03b3) \u2192 \u03b1 \u2192 \u03b2 \u2192 \u03b3 :=\n\u03bbf g a b, g a\n\n/-! 3.2 (1 point). Complete the following definition.\n\nThis one looks more difficult, but it should be fairly straightforward if you\nfollow the procedure described in the Hitchhiker's Guide.\n\nNote: Peirce is pronounced like the English word \"purse\". -/\n\ndef weak_peirce : ((((\u03b1 \u2192 \u03b2) \u2192 \u03b1) \u2192 \u03b1) \u2192 \u03b2) \u2192 \u03b2 :=\nsorry\n\n/-! 3.3 (2 points). Show the typing derivation for your definition of `B` above,\nusing ASCII or Unicode art. You might find the characters `\u2013` (to draw\nhorizontal bars) and `\u22a2` useful.\n\nFeel free to introduce abbreviations to avoid repeating large contexts `\u0393`. -/\n\n-- write your solution here\n\nend LoVe\n", "meta": {"author": "superestos", "repo": "-logical_verification", "sha": "dab8b8704680679a78b83c2f82e1113ff098b34f", "save_path": "github-repos/lean/superestos--logical_verification", "path": "github-repos/lean/superestos--logical_verification/-logical_verification-dab8b8704680679a78b83c2f82e1113ff098b34f/lean/love01_definitions_and_statements_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7336821425714756}}
{"text": "import data.set\nimport .src_17_even_odd_further\n\nopen set function\n\nnamespace mth1001\n\nsection pre_image\n/-\nSuppose `f : \u03b1 \u2192 \u03b2` is a function from a type `\u03b1` to a type `\u03b2`. Suppose\n`B` is a set on `\u03b2`. The *preimage* of `B` under `f` is `{x : \u03b1 | f x \u2208 B}`.\nIt is denoted `f\u207b\u00b9 B` in matheamtics and either `preimage f B` or `f\u207b\u00b9' B` in Lean.\n\nWARNING: `f\u207b\u00b9 B` is a *set*. It is related to, but is not the same thing as the inverse of `f`.\n-/\n\nsection pre_image_examples\n/-\nAs an example, consider `g : \u2124 \u2192 \u2115` given by `g n := |n| + 1`. Let `T := {1, 3, 5}`. Then the\npreimage of `T` under `g` is the set `{0, 2, -2, 4, -4}`.\n-/\n\ndef g (n : \u2124) : \u2115 := int.nat_abs n + 1\ndef T : set \u2115 := {1, 3, 5}\n\nlemma eq_or_eq_neg_of_nat_abs_eq {x : \u2124} {y : \u2115}: int.nat_abs x = y \u2192 (x = y) \u2228 (x = -y) := \n\u03bb h, h \u25b8 (h \u25b8 (int.nat_abs_eq x))\n\nexample : g\u207b\u00b9' T = {0, 2, -2, 4, -4} :=\nbegin\n  ext, unfold T,\n  split,\n  { unfold preimage,\n    intro h,\n    rw mem_set_of_eq at h,\n    unfold g at h,\n    rcases h with h | h | h | \u27e8\u27e8\u27e9\u27e9,\n    { rcases (eq_or_eq_neg_of_nat_abs_eq (nat.succ_inj h)) with rfl | rfl;\n      simp, },\n    { rcases (eq_or_eq_neg_of_nat_abs_eq (nat.succ_inj h)) with rfl | rfl;\n      simp, },\n    { rw (int.eq_zero_of_nat_abs_eq_zero (nat.succ_inj h)), simp, }, },\n  { intro h,\n    finish, },\nend\n\n/-\nAs an example, conisder `f : \u2124 \u2192 \u2124` defined by `f n = n + 1`. Let `B` be the set of even integers.\nWe'll show the preimage of `B` under `f` is the set of odd integers\n-/\n\ndef f (n : \u2124) : \u2124 := n + 1\ndef B := {y : \u2124 | even y}\ndef C := {m : \u2124 | odd m}\n\nexample : f\u207b\u00b9' B = C :=\nbegin\n  ext, -- Assume `x \u2208 \u2124`. We must show `x \u2208 f\u207b\u00b9' B \u2194 x \u2208 C`.\n  split,\n  { rintro \u27e8b, h\u27e9, -- Assume `b : \u2124` and `h : f x = 2 * b`. We must show `x \u2208 C`.\n    unfold f at h, -- By defintion, `h : f x = 2 * b`.\n    use (b - 1), -- It suffices to prove `x = 2 * b + 1`.\n    linarith, }, -- The goal follows by linear arithmetic.\n  { rintro \u27e8c, h\u27e9, -- Assume `c : \u2124` and `h : x = 2 * c + `. We must show `x \u2208 f\u207b\u00b9' B`.\n    have h\u2082 : f x \u2208 B,\n    { rw h,\n      unfold f,\n      use (c + 1),\n      linarith, },\n    unfold preimage,\n    rw mem_set_of_eq,\n    exact h\u2082, },\nend\n\nend pre_image_examples\n\nsection pre_image_theorems\n\nvariable {\u03b1 : Type*}\nvariable {\u03b2 : Type*}\n\n#check preimage_inter\n\n/-\nThe following proof uses the power of `rintro` to decompose intersections, etc.\nNote that, unlike images, intersections are preserved by the preimage.\n-/\ntheorem preimage_inter {B C : set \u03b2} {f : \u03b1 \u2192 \u03b2} : f\u207b\u00b9' (B \u2229 C) = f\u207b\u00b9' B \u2229 f\u207b\u00b9' C :=\nbegin\n  ext, -- Assume `x : \u2124`. It suffices to prove `x \u2208 f\u207b\u00b9' (B \u2229 C) \u2194 x \u2208 f\u207b\u00b9' B \u2229 f\u207b\u00b9' C`.\n  split, -- Decompose the `\u2194` proof into two implication proofs.\n  { rintro \u27e8hb, hc\u27e9, -- Assume `hb : f x \u2208 B` and `hc : f x \u2208 B`. STP `x \u2208 f\u207b\u00b9' B \u2229 f\u207b\u00b9' C`.\n    exact and.intro hb hc, }, -- This follows by `\u2227` introduction on `hb` and `hc`.\n  { rintro \u27e8hb, hc\u27e9, -- Assume `hb : x \u2208 f\u207b\u00b9' B` and `hc : x \u2208 f\u207b\u00b9' C`. STP `x \u2208 f\u207b\u00b9' B \u2229 C`.\n    exact and.intro hb hc, } -- The goal follows by `\u2227` introduction on `hb` and `hc`.\nend\n\n/-\nIn fact, as the same tactic applies to both subgoals after the split above, the proof can be\nshortened using the `;` combinator:\n-/\nexample {B C : set \u03b2} {f : \u03b1 \u2192 \u03b2} : f\u207b\u00b9' (B \u2229 C) = f\u207b\u00b9' B \u2229 f\u207b\u00b9' C :=\nbegin\n  ext, -- Assume `x : \u2124`. It suffices to prove `x \u2208 f\u207b\u00b9' (B \u2229 C) \u2194 x \u2208 f\u207b\u00b9' B \u2229 f\u207b\u00b9' C`.\n  split; -- Decompose the `\u2194` proof into two implication proofs.\n  { rintro \u27e8hb, hc\u27e9, exact and.intro hb hc, },\nend\n\n-- Exercise 144:\n-- The preimage of a union is the union of preimages.\ntheorem preimage_union {B C : set \u03b2} {f : \u03b1 \u2192 \u03b2} : f\u207b\u00b9' (B \u222a C) = f\u207b\u00b9' B \u222a f\u207b\u00b9' C :=\nbegin\n  sorry  \nend\n\nend pre_image_theorems\n\nend pre_image\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_30_preimages_of_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.865224070413529, "lm_q1q2_score": 0.7336821287800996}}
{"text": "/-\nCopyright (c) 2020 Benjamin Davidson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.arctan_deriv\n\n/-! ### Leibniz's Series for Pi -/\n\nnamespace real\n\nopen filter set\nopen_locale classical big_operators topological_space real\nlocal notation `|`x`|` := abs x\n\n/-- This theorem establishes **Leibniz's series for `\u03c0`**: The alternating sum of the reciprocals\n  of the odd numbers is `\u03c0/4`. Note that this is a conditionally rather than absolutely convergent\n  series. The main tool that this proof uses is the Mean Value Theorem (specifically avoiding the\n  Fundamental Theorem of Calculus).\n\n  Intuitively, the theorem holds because Leibniz's series is the Taylor series of `arctan x`\n  centered about `0` and evaluated at the value `x = 1`. Therefore, much of this proof consists of\n  reasoning about a function\n    `f := arctan x - \u2211 i in finset.range k, (-(1:\u211d))^i * x^(2*i+1) / (2*i+1)`,\n  the difference between `arctan` and the `k`-th partial sum of its Taylor series. Some ingenuity is\n  required due to the fact that the Taylor series is not absolutely convergent at `x = 1`.\n\n  This proof requires a bound on `f 1`, the key idea being that `f 1` can be split as the sum of\n  `f 1 - f u` and `f u`, where `u` is a sequence of values in [0,1], carefully chosen such that\n  each of these two terms can be controlled (in different ways).\n\n  We begin the proof by (1) introducing that sequence `u` and then proving that another sequence\n  constructed from `u` tends to `0` at `+\u221e`. After (2) converting the limit in our goal to an\n  inequality, we (3) introduce the auxiliary function `f` defined above. Next, we (4) compute the\n  derivative of `f`, denoted by `f'`, first generally and then on each of two subintervals of [0,1].\n  We then (5) prove a bound for `f'`, again both generally as well as on each of the two\n  subintervals. Finally, we (6) apply the Mean Value Theorem twice, obtaining bounds on `f 1 - f u`\n  and `f u - f 0` from the bounds on `f'` (note that `f 0 = 0`). -/\ntheorem tendsto_sum_pi_div_four :\n  tendsto (\u03bb k, \u2211 i in finset.range k, ((-(1:\u211d))^i / (2*i+1))) at_top (\ud835\udcdd (\u03c0/4)) :=\nbegin\n  rw [tendsto_iff_norm_tendsto_zero, \u2190 tendsto_zero_iff_norm_tendsto_zero],\n  -- (1) We introduce a useful sequence `u` of values in [0,1], then prove that another sequence\n  --     constructed from `u` tends to `0` at `+\u221e`\n  let u := \u03bb k : \u2115, (k:nnreal) ^ (-1 / (2 * (k:\u211d) + 1)),\n  have H : tendsto (\u03bb k : \u2115, (1:\u211d) - (u k) + (u k) ^ (2 * (k:\u211d) + 1)) at_top (\ud835\udcdd 0),\n  { convert (((tendsto_rpow_div_mul_add (-1) 2 1 two_ne_zero.symm).neg.const_add 1).add\n      tendsto_inv_at_top_zero).comp tendsto_coe_nat_at_top_at_top,\n    { ext k,\n      simp only [nnreal.coe_nat_cast, function.comp_app, nnreal.coe_rpow],\n      rw [\u2190 rpow_mul (nat.cast_nonneg k) ((-1)/(2*(k:\u211d)+1)) (2*(k:\u211d)+1),\n         @div_mul_cancel _ _ _ (2*(k:\u211d)+1)\n            (by { norm_cast, simp only [nat.succ_ne_zero, not_false_iff] }), rpow_neg_one k,\n          sub_eq_add_neg] },\n    { simp only [add_zero, add_right_neg] } },\n  -- (2) We convert the limit in our goal to an inequality\n  refine squeeze_zero_norm _ H,\n  intro k,\n  -- Since `k` is now fixed, we henceforth denote `u k` as `U`\n  let U := u k,\n  -- (3) We introduce an auxiliary function `f`\n  let b := \u03bb (i:\u2115) x, (-(1:\u211d))^i * x^(2*i+1) / (2*i+1),\n  let f := \u03bb x, arctan x - (\u2211 i in finset.range k, b i x),\n  suffices f_bound : |f 1 - f 0| \u2264 (1:\u211d) - U + U ^ (2 * (k:\u211d) + 1),\n  { rw \u2190 norm_neg,\n    convert f_bound,\n    simp only [f], simp [b] },\n  -- We show that `U` is indeed in [0,1]\n  have hU1 : (U:\u211d) \u2264 1,\n  { by_cases hk : k = 0,\n    { simpa only [U, hk] using zero_rpow_le_one _ },\n    { exact rpow_le_one_of_one_le_of_nonpos (by { norm_cast, exact nat.succ_le_iff.mpr\n        (nat.pos_of_ne_zero hk) }) (le_of_lt (@div_neg_of_neg_of_pos _ _ (-(1:\u211d)) (2*k+1)\n          (neg_neg_iff_pos.mpr zero_lt_one) (by { norm_cast, exact nat.succ_pos' }))) } },\n  have hU2 := nnreal.coe_nonneg U,\n  -- (4) We compute the derivative of `f`, denoted by `f'`\n  let f' := \u03bb x : \u211d, (-x^2) ^ k / (1 + x^2),\n  have has_deriv_at_f : \u2200 x, has_deriv_at f (f' x) x,\n  { intro x,\n    have has_deriv_at_b : \u2200 i \u2208 finset.range k, (has_deriv_at (b i) ((-x^2)^i) x),\n    { intros i hi,\n      convert has_deriv_at.const_mul ((-1:\u211d)^i / (2*i+1)) (@has_deriv_at.pow _ _ _ _ _ (2*i+1)\n        (has_deriv_at_id x)),\n      { ext y,\n        simp only [b, id.def],\n        ring },\n      { simp only [nat.add_succ_sub_one, add_zero, mul_one, id.def, nat.cast_bit0, nat.cast_add,\n                  nat.cast_one, nat.cast_mul],\n        rw [\u2190 mul_assoc, @div_mul_cancel _ _ _ (2*(i:\u211d)+1) (by { norm_cast, linarith }),\n            pow_mul x 2 i, \u2190 mul_pow (-1) (x^2) i],\n        ring_nf } },\n    convert (has_deriv_at_arctan x).sub (has_deriv_at.sum has_deriv_at_b),\n    have g_sum :=\n      @geom_sum_eq _ _ (-x^2) ((neg_nonpos.mpr (sq_nonneg x)).trans_lt zero_lt_one).ne k,\n    simp only [geom_sum, f'] at g_sum \u22a2,\n    rw [g_sum, \u2190 neg_add' (x^2) 1, add_comm (x^2) 1, sub_eq_add_neg, neg_div', neg_div_neg_eq],\n    ring },\n  have hderiv1 : \u2200 x \u2208 Icc (U:\u211d) 1, has_deriv_within_at f (f' x) (Icc (U:\u211d) 1) x :=\n    \u03bb x hx, (has_deriv_at_f x).has_deriv_within_at,\n  have hderiv2 : \u2200 x \u2208 Icc 0 (U:\u211d), has_deriv_within_at f (f' x) (Icc 0 (U:\u211d)) x :=\n    \u03bb x hx, (has_deriv_at_f x).has_deriv_within_at,\n  -- (5) We prove a general bound for `f'` and then more precise bounds on each of two subintervals\n  have f'_bound : \u2200 x \u2208 Icc (-1:\u211d) 1, |f' x| \u2264 |x|^(2*k),\n  { intros x hx,\n    rw [abs_div, is_absolute_value.abv_pow abs (-x^2) k, abs_neg, is_absolute_value.abv_pow abs x 2,\n       tactic.ring_exp.pow_e_pf_exp rfl rfl],\n    refine div_le_of_nonneg_of_le_mul (abs_nonneg _) (pow_nonneg (abs_nonneg _) _) _,\n    refine le_mul_of_one_le_right (pow_nonneg (abs_nonneg _) _) _,\n    rw abs_of_nonneg ((add_nonneg zero_le_one (sq_nonneg x)) : (0 : \u211d) \u2264 _),\n    exact (le_add_of_nonneg_right (sq_nonneg x) : (1 : \u211d) \u2264 _) },\n  have hbound1 : \u2200 x \u2208 Ico (U:\u211d) 1, |f' x| \u2264 1,\n  { rintros x \u27e8hx_left, hx_right\u27e9,\n    have hincr := pow_le_pow_of_le_left (le_trans hU2 hx_left) (le_of_lt hx_right) (2*k),\n    rw [one_pow (2*k), \u2190 abs_of_nonneg (le_trans hU2 hx_left)] at hincr,\n    rw \u2190 abs_of_nonneg (le_trans hU2 hx_left) at hx_right,\n    linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_of_lt hx_right)))] },\n  have hbound2 : \u2200 x \u2208 Ico 0 (U:\u211d), |f' x| \u2264 U ^ (2*k),\n  { rintros x \u27e8hx_left, hx_right\u27e9,\n    have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2*k),\n    rw \u2190 abs_of_nonneg hx_left at hincr hx_right,\n    rw \u2190 abs_of_nonneg hU2 at hU1 hx_right,\n    linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_trans (le_of_lt hx_right) hU1)))] },\n  -- (6) We twice apply the Mean Value Theorem to obtain bounds on `f` from the bounds on `f'`\n  have mvt1 :=\n    norm_image_sub_le_of_norm_deriv_le_segment' hderiv1 hbound1 _ (right_mem_Icc.mpr hU1),\n  have mvt2 :=\n    norm_image_sub_le_of_norm_deriv_le_segment' hderiv2 hbound2 _ (right_mem_Icc.mpr hU2),\n  -- The following algebra is enough to complete the proof\n  calc |f 1 - f 0| = |(f 1 - f U) + (f U - f 0)| : by ring_nf\n               ... \u2264 1 * (1-U) + U^(2*k) * (U - 0) : le_trans (abs_add (f 1 - f U) (f U - f 0))\n                                                      (add_le_add mvt1 mvt2)\n               ... = 1 - U + U^(2*k) * U : by ring\n               ... = 1 - (u k) + (u k)^(2*(k:\u211d)+1) : by { rw [\u2190 pow_succ' (U:\u211d) (2*k)], norm_cast },\nend\n\nend real\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/real/pi/leibniz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7336319252351337}}
{"text": "/-\nCopyright (c) 2023 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\n\nimport ring_theory.localization.module\nimport ring_theory.norm\n\n/-!\n\n# Field/algebra norm and localization\n\nThis file contains results on the combination of `algebra.norm` and `is_localization`.\n\n## Main results\n\n * `algebra.norm_localization`: let `S` be an extension of `R` and `R\u2098 S\u2098` be localizations at `M`\n  of `R S` respectively. Then the norm of `a : S\u2098` over `R\u2098` is the norm of `a : S` over `R`\n  if `S` is free as `R`-module\n\n## Tags\n\nfield norm, algebra norm, localization\n\n-/\n\nopen_locale non_zero_divisors\n\nvariables (R : Type*) {S : Type*} [comm_ring R] [comm_ring S] [algebra R S]\nvariables {R\u2098 S\u2098 : Type*} [comm_ring R\u2098] [algebra R R\u2098] [comm_ring S\u2098] [algebra S S\u2098]\nvariables (M : submonoid R)\nvariables [is_localization M R\u2098] [is_localization (algebra.algebra_map_submonoid S M) S\u2098]\nvariables [algebra R\u2098 S\u2098] [algebra R S\u2098] [is_scalar_tower R R\u2098 S\u2098] [is_scalar_tower R S S\u2098]\ninclude M\n\n/-- Let `S` be an extension of `R` and `R\u2098 S\u2098` be localizations at `M` of `R S` respectively.\nThen the norm of `a : S\u2098` over `R\u2098` is the norm of `a : S` over `R` if `S` is free as `R`-module.\n-/\nlemma algebra.norm_localization [module.free R S] [module.finite R S] (a : S) :\n  algebra.norm R\u2098 (algebra_map S S\u2098 a) = algebra_map R R\u2098 (algebra.norm R a) :=\nbegin\n  casesI subsingleton_or_nontrivial R,\n  { haveI : subsingleton R\u2098 := module.subsingleton R R\u2098,\n    simp },\n  let b := module.free.choose_basis R S,\n  letI := classical.dec_eq (module.free.choose_basis_index R S),\n  rw [algebra.norm_eq_matrix_det (b.localization_localization R\u2098 M S\u2098),\n      algebra.norm_eq_matrix_det b, ring_hom.map_det],\n  congr,\n  ext i j,\n  simp only [matrix.map_apply, ring_hom.map_matrix_apply, algebra.left_mul_matrix_eq_repr_mul,\n      basis.localization_localization_apply, \u2190 _root_.map_mul],\n  apply basis.localization_localization_repr_algebra_map\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/localization/norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.7336319193283729}}
{"text": "import tactic\n\n/-\n\n\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u043a\u0443\u0440\u0441\u0430 Formalising Mathematics:\nhttps://github.com/ImperialCollegeLondon/formalising-mathematics/blob/master/src/week_1/Part_D_relations.lean\n\n\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0438\u043f `\u03b1` \u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0434 `\u03b1`: `R : \u03b1 \u2192 \u03b1 \u2192 Prop`.\n\u0414\u043b\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u0432 Lean \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0432\u043d\u043e\u0441\u0442\u0438, \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438:\n\n`reflexive R := \u2200 (x : \u03b1), R x x`\n`symmetric R := \u2200 \u2983x y : \u03b1\u2984, R x y \u2192 R y x`\n`transitive R := \u2200 \u2983x y z : \u03b1\u2984, R x y \u2192 R y z \u2192 R x z`\n\n\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 `R` \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435\u043c \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0432\u0441\u0435\u043c \u0442\u0440\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0432\u044b\u0448\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\u043c:\n\n`equivalence R := reflexive R \u2227 symmetric R \u2227 transitive R`\n\n\u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043c\u044b \u0434\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u0438\u0435\u043a\u0446\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0442\u0438\u043f\u0435 `\u03b1` \u0438 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 `\u03b1` \u043d\u0430 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 (\u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c\u0441\u044f, \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0431\u043b\u043e\u043a\u0430\u043c\u0438).\n\n\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0442\u0438\u043f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 `\u03b1`. \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:\n1) `C : set (set \u03b1)` - \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0431\u043b\u043e\u043a\u043e\u0432.\n2) `Hnonempty` - \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 \u0431\u043b\u043e\u043a\u0438 \u043d\u0435\u043f\u0443\u0441\u0442\u044b.\n3) `Hcover` - \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 `a : \u03b1` \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0431\u043b\u043e\u043a\u0435.\n4) `Hdisjoint` - \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f.\n\n\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e `structure` \u0437\u0430\u0434\u0430\u0435\u0442 \u0442\u0438\u043f \u0441 \u043e\u0434\u043d\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c (\u043e\u043d \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c `partition.mk`) \u0438 \u0438\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \"\u043f\u043e\u043b\u044f\u043c\u0438\". \u0415\u0441\u043b\u0438 `P : partition \u03b1`, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c `P.C`, `P.Hnonempty` \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435. \n-/\n\n@[ext] structure partition (\u03b1 : Type) :=\n(C : set (set \u03b1))\n(Hnonempty : \u2200 X \u2208 C, (X : set \u03b1).nonempty)\n(Hcover : \u2200 a, \u2203 X \u2208 C, a \u2208 X)\n(Hdisjoint : \u2200 X Y \u2208 C, (X \u2229 Y : set \u03b1).nonempty \u2192 X = Y)\n\nnamespace partition\n\nvariables {\u03b1 : Type} {P : partition \u03b1} {X Y : set \u03b1}\n\n-- `X.nonempty` (\u0438\u043b\u0438 `set.nonempty X`) \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 `X`\nlemma nonempty_def : X.nonempty \u2194 \u2203 a, a \u2208 X :=\nbegin\n  refl,\nend\n\n/-- \u0415\u0441\u043b\u0438 `a` \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0431\u043b\u043e\u043a\u0430\u0445 `X` \u0438 `Y` -/\ntheorem eq_of_mem (hX : X \u2208 P.C) (hY : Y \u2208 P.C) {a : \u03b1} (haX : a \u2208 X)\n  (haY : a \u2208 Y) : X = Y :=\nbegin\n  apply P.Hdisjoint X Y hX hY,\n  use [a, haX, haY],\nend\n\ntheorem mem_of_mem (hX : X \u2208 P.C) (hY : Y \u2208 P.C) {a b : \u03b1}\n  (haX : a \u2208 X) (haY : a \u2208 Y) (hbX : b \u2208 X) : b \u2208 Y :=\nbegin\n  have heq := eq_of_mem hX hY haX haY,\n  rwa heq at hbX,\nend\n\nend partition\n\nsection equivalence_classes\n\n\nvariables {\u03b1 : Type} (R : \u03b1 \u2192 \u03b1 \u2192 Prop) (hR : equivalence R)\n\n-- \u041a\u043b\u0430\u0441\u0441\u043e\u043c \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 `a` \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 `b`, \u0447\u0442\u043e `R b a`\ndef cl (a : \u03b1) := {b : \u03b1 | R b a}\n\n-- \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e, `b` \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 `a`, \u0435\u0441\u043b\u0438 `R b a`\nlemma mem_cl_iff {a b : \u03b1} : b \u2208 cl R a \u2194 R b a :=\nbegin\n  refl\nend\n\n-- `a` \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u043b\u0430\u0441\u0441\u0443 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 `a`\nlemma mem_cl_self (hR : equivalence R) (a : \u03b1) : a \u2208 cl R a :=\nbegin\n  -- \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0432\u043d\u043e\u0441\u0442\u044c `R`, \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c `hR`\n  -- \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e `rcases`: `rcases hR with \u27e8hrefl, hsymm, htrans\u27e9`, \u0438\u043b\u0438\n  -- `obtain \u27e8hrefl, hsymm, htrans\u27e9 := hR`\n  rcases hR with \u27e8hrefl, hsymm, htrans\u27e9,\n  exact hrefl a,\nend\n\n-- \u0415\u0441\u043b\u0438 `a` \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 `b`, \u0442\u043e \u0432\u0435\u0441\u044c \u043a\u043b\u0430\u0441\u0441 `a` - \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u0430 `b`\nlemma cl_sub_cl_of_mem_cl {a b : \u03b1} (hR : equivalence R) : a \u2208 cl R b \u2192 cl R a \u2286 cl R b :=\nbegin\n  rcases hR with \u27e8hrefl, hsymm, htrans\u27e9,\n  rintro h x Rxa,\n  exact htrans Rxa h,\nend\n\n-- \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435: `set.subset.antisymm : X \u2286 Y \u2192 Y \u2286 X \u2192 X = Y`\nlemma cl_eq_cl_of_mem_cl {a b : \u03b1} (hR : equivalence R) : a \u2208 cl R b \u2192 cl R a = cl R b :=\nbegin\n  intro h,\n  apply set.subset.antisymm,\n  refine cl_sub_cl_of_mem_cl R hR h,\n  refine cl_sub_cl_of_mem_cl R hR _,\n  exact hR.2.1 h,\nend\n\nend equivalence_classes\n\nopen partition\n\n-- \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0442\u0438\u043f\u043e\u0432 `X \u2243 Y`, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 `X \u2192 Y`, \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 `Y \u2192 X`, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u0438 \u0434\u0432\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u043e\u0431\u0440\u0430\u0442\u043d\u044b\n\n-- \u0414\u0430\u043b\u0435\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0438 \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u0435 \u0446\u0435\u043b\u0438, \u043d\u043e \u043c\u044b \u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u0442\u0438\u043a `change` \u0438 `show`\n--   \n\nexample (\u03b1 : Type) : {R : \u03b1 \u2192 \u03b1 \u2192 Prop // equivalence R} \u2243 partition \u03b1 :=\n{ -- \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 `R`\u0432 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435:\n  to_fun := \u03bb R, {\n    -- \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0437\u0430 `C` \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 `\u03b1` \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e R\n    C := { B : set \u03b1 | \u2203 x : \u03b1, B = cl R.1 x},\n    -- \u0414\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0431\u043b\u043e\u043a\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0440\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439: `Hnonempty`, `Hcover` \u0438 `Hdisjoint`. \u0414\u043e\u043a\u0430\u0436\u0435\u043c \u0438\u0445:\n    Hnonempty := begin\n      -- \u041b\u044e\u0431\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u043f\u0443\u0441\u0442.\n      cases R with R hR,\n      change \u2200 (X : set \u03b1), (\u2203 (a : \u03b1), X = cl R a) \u2192 X.nonempty,\n      rintro X \u27e8a, rfl\u27e9,\n      -- \u041a\u0440\u0443\u0442\u043e\u0439 \u0445\u0430\u043a: \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0443 \u0432\u0438\u0434\u0430 `A = B` \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043c\u043e\u0436\u043d\u043e \u0432 `rintro` \u0438 `rcases` \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c `rfl` \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0438 (\u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e), \u0432\u043e \u0432\u0441\u0435\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 `A` \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043d\u0430 `B` \u0438 \u0443\u0439\u0434\u0435\u0442 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\n      use a,\n      apply mem_cl_self R hR,\n    end,\n    Hcover := begin\n      -- \u041a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 `\u03b1` \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438.\n      cases R with R hR,\n      change \u2200 (a : \u03b1), \u2203 (X : set \u03b1) (H : \u2203 (b : \u03b1), X = cl R b), a \u2208 X,\n      intro a,\n      use [cl R a],\n      refine \u27e8\u27e8a, rfl\u27e9, mem_cl_self R hR _\u27e9,\n    end,\n    Hdisjoint := begin\n      -- \u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f, \u0442\u043e \u043e\u043d\u0438 \u0440\u0430\u0432\u043d\u044b.\n      cases R with R hR,\n      change \u2200 (X Y : set \u03b1), (\u2203 (a : \u03b1), X = cl R a) \u2192\n        (\u2203 (b : \u03b1), Y = cl _ b) \u2192 (X \u2229 Y).nonempty \u2192 X = Y,\n      rintro _ _ \u27e8a, rfl\u27e9 \u27e8b, rfl\u27e9 \u27e8c, \u27e8Rac, Rbc\u27e9\u27e9,\n      apply cl_eq_cl_of_mem_cl R hR,\n      rcases hR with \u27e8hrefl, hsymm, htrans\u27e9,\n      refine htrans _ Rbc,\n      refine hsymm Rac,\n    end },\n  -- \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044e\n  inv_fun := \u03bb P, \n    -- \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 `R`:\n    -- `R a b` \u0435\u0441\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0431\u043b\u043e\u043a, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 `a`, \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 `b`.\n    \u27e8\u03bb a b, \u2200 X \u2208 P.C, a \u2208 X \u2192 b \u2208 X, begin\n      -- \u0414\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438\n    split,\n    { -- \u041e\u043d\u043e \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0432\u043d\u043e\n      unfold reflexive, \n      rintro x A hA xA,\n      exact xA,\n    },\n    split,\n    { -- \u041e\u043d\u043e \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u043e\n      unfold symmetric,\n      rintro x y hxy X hX yX,\n      obtain \u27e8Y, hY, xY\u27e9 := P.Hcover x,\n      specialize hxy Y hY xY,\n      have h := eq_of_mem hX hY yX hxy,\n      rwa h,\n    },\n    { -- \u041e\u043d\u043e \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\n      unfold transitive,\n      show \u2200 (a b c : \u03b1),\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 b \u2208 X) \u2192\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 b \u2208 X \u2192 c \u2208 X) \u2192\n         \u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 c \u2208 X,\n      rintro a b c hab hbc X hX aX,\n      apply hbc X hX,\n      apply hab X hX,\n      exact aX,\n    }\n  end\u27e9,\n  -- \u0415\u0441\u043b\u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f `R` \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f `R`\n  left_inv := begin\n    rintro \u27e8R, hR\u27e9,\n    -- \u0421\u0442\u0440\u0430\u0448\u043d\u0430\u044f \u0446\u0435\u043b\u044c, \u043d\u043e \u043e\u043d\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439:\n    suffices h : (\u03bb (a b : \u03b1), \u2200 (c : \u03b1), a \u2208 cl R c \u2192 b \u2208 cl R c) = R,\n    simpa using h,\n    -- ... \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u0434\u0432\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0442\u0430\u043a\u0442\u0438\u043a\u0430 `ext` \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442 \u0446\u0435\u043b\u044c \u0432 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 `a` \u0438 `b`\n    ext a b,\n\n    split, {\n      intro h,\n      specialize h a (mem_cl_self _ hR _),\n      apply hR.2.1, -- \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u043e\u0441\u0442\u044c\n      exact h,\n    }, {\n      rintro hab c Rac,\n      -- \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043c \u0432\u0441\u0451 \u0434\u043e \u0432\u0438\u0434\u0430 R _ _\n      rw [cl, set.mem_set_of_eq] at *,\n      -- hR.2.2 - \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\n      apply hR.2.2 (hR.2.1 hab) Rac,\n    }\n  end,\n  -- \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u043e \u0436\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435\n  right_inv := begin\n    intro P,\n    ext X,\n    show (\u2203 (a : \u03b1), X = cl _ a) \u2194 X \u2208 P.C,\n    dsimp only,\n    split, {\n      rintro \u27e8a, ha\u27e9,\n      obtain \u27e8Y, hY, aY\u27e9 := P.Hcover a,\n      -- \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e `X` \u044d\u0442\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0431\u043b\u043e\u043a `Y`, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0439 `a`\n      suffices hXY : X = Y, {\n        rwa hXY,\n      },\n      subst ha,\n      ext t, split, {\n        intro ht,\n        -- \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 t \u2208 <\u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435>, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c\n        -- `squeeze_simp` \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043b\u0435\u043c\u043c \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 `simp only [...]`\n        -- \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043b\u0435\u043c\u043c \u0434\u043b\u044f `simp` \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f, \u0438 \u0441\u0442\u0430\u0440\u044b\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u043c\u0430\u044e\u0442\u0441\u044f\n        -- \u0442\u0430\u043a\u0436\u0435 \u0447\u0430\u0441\u0442\u043e \u043d\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0435 (\u0442\u0435, \u0447\u0442\u043e \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u0446\u0435\u043b\u044c) `simp` \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043e\u0434\u043e\u0431\u0440\u044f\u044e\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e\u0442 `simp only`\n        squeeze_simp [cl] at ht,\n        obtain \u27e8Z, hZ, tZ\u27e9 := P.Hcover t,\n        have aZ := ht Z hZ tZ,\n        -- a \u2208 Y \u2227 a \u2208 Z \u2192 Y = Z\n        have hYZ := eq_of_mem hY hZ aY aZ,\n        rwa hYZ,\n      }, {\n        simp [cl],\n        rintro tY Z hZ tZ,\n        refine mem_of_mem hY hZ tY tZ aY, \n      }\n    }, {\n      intro hX,\n      obtain \u27e8a, aX\u27e9 := P.Hnonempty X hX,\n      use a,\n      ext t, split, {\n        simp [cl],\n        rintro tX Y hY tY,\n        refine mem_of_mem hX hY tX tY aX, \n      }, {\n        simp [cl],\n        intro h,\n        obtain \u27e8Y, hY, tY\u27e9 := P.Hcover t,\n        refine mem_of_mem hY hX _ aX tY,\n        -- \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u22a2 a \u2208 Y\n        apply h Y hY tY,\n      }\n    }\n  end }\n", "meta": {"author": "VArtem", "repo": "lean-itmo", "sha": "dc44cd06f9f5b984d051831b3aaa7364e64c2dc4", "save_path": "github-repos/lean/VArtem-lean-itmo", "path": "github-repos/lean/VArtem-lean-itmo/lean-itmo-dc44cd06f9f5b984d051831b3aaa7364e64c2dc4/src/week-02/solutions/e03-relations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7335766731569233}}
{"text": "import subgroup.cyclic\n\n/- In this file we will define the commutator and some lemmas about it. -/\n\nnamespace mygroup\n\nopen_locale classical\n\nopen mygroup.subgroup mygroup.quotient group_hom function set\n\nvariables {G : Type} [group G]\n\n/-- The commutator of two elements `a`, `b` of a group `G` is `a * b * a\u207b\u00b9 * b\u207b\u00b9`-/\ndef commutator (a b : G) := a * b * a \u207b\u00b9 * b\u207b\u00b9\n\n@[simp] lemma commutator_def {a b : G} : commutator a b = a * b * a\u207b\u00b9 * b\u207b\u00b9 := rfl\n\ndef commutators (G : Type) [group G] := { c | \u2203 a b : G, c = commutator a b }\n\n@[simp] lemma commutators_def : commutators G = \n  { c | \u2203 a b : G, c = commutator a b } := rfl\n\n@[simp] lemma mem_commutators_iff (x : G) : x \u2208 commutators G \u2194 \n  \u2203 a b : G, x = commutator a b := iff.rfl\n\n-- To show that the subgroup generated by the set of commutators is normal, we \n-- first need a more general lemma for showing normal'ness' of closures, i.e. \n-- the fact that the closure is normal if the set is closed under conjugation\n\n-- We will use the induction principle on closure of subgroups\n\nnamespace subgroup\n\n/-- The closure of an invariant set is also invariant under conjugation -/\nlemma closure_normal {s : set G} (hs : \u2200 t \u2208 s, \u2200 g : G, g * t * g\u207b\u00b9 \u2208 s) : \n  \u2200 t \u2208 closure s, \u2200 g : G, g * t * g\u207b\u00b9 \u2208 closure s := \nbegin\n  intros t ht g,\n  apply closure_induction ht,\n    exact \u03bb x hx, le_closure _ (hs x hx g),\n    simp [one_mem],\n    intros x y hx hy,\n    conv_lhs \n      { congr, congr, skip, congr, \n        rw [show x = x * g\u207b\u00b9 * g, by simp [group.mul_assoc]] },\n    rw [show g * (x * g\u207b\u00b9 * g * y) * g\u207b\u00b9 = g * x * g\u207b\u00b9 * (g * y * g\u207b\u00b9), \n        by simp [group.mul_assoc]],\n    refine mul_mem _ hx hy,\n    intros x hx, refine (inv_mem_iff _).1 _,\n    simpa [\u2190 group.mul_assoc],\nend\n\n/-- The commutator is the normal subgroup generated by the set of commutators -/\ndef commutator_normal (G : Type) [group G] : normal G := \n{ conj_mem' := \n  begin\n    intros n hn g,\n    refine closure_normal _ _ hn _,\n    rintro t \u27e8a, b, rfl\u27e9 g,\n    rw [commutator_def, show g * (a * b * a\u207b\u00b9 * b\u207b\u00b9) * g\u207b\u00b9 = \n          g * a * g\u207b\u00b9 * (g * b * g\u207b\u00b9) * (g * a * g\u207b\u00b9)\u207b\u00b9 * (g * b * g\u207b\u00b9)\u207b\u00b9, \n          by simp [group.mul_assoc]],\n    exact \u27e8g * a * g\u207b\u00b9, (g * b * g\u207b\u00b9), rfl\u27e9,\n  end .. closure $ commutators G }\n\n/-- A group `G` the abelian if and only if the commutator subgroup is `{1}`-/\nlemma comm_group_iff : (commutator_normal G : set G) = {1} \u2194 @commutative G (*) :=\nbegin\n  split, intros h a b,\n    { change (closure (commutators G) : set G) = _ at h,\n      have : {c : G | \u2203 (a b : G), c = commutator a b} = {1},\n        apply subset.antisymm, rw \u2190 h, exact le_closure _,\n        rw singleton_subset_iff, exact \u27e8a, a\u207b\u00b9, by simp\u27e9,\n      rw eq_singleton_iff_unique_mem at this,\n      rw [\u2190 group.mul_right_cancel_iff (a\u207b\u00b9 * b\u207b\u00b9),\n          (this.right (a * b * (a\u207b\u00b9 * b\u207b\u00b9)) \n          \u27e8a, b, by simp [group.mul_assoc]\u27e9).symm],\n      simp [group.mul_assoc] },\n    { intros h, apply subset.antisymm,\n      { change closure (commutators G) \u2264 trivial,\n        rw closure_le, rintro _ \u27e8a, b, rfl\u27e9, rw [commutator_def, h a b, mem_coe'], \n        simp [group.mul_assoc, subgroup.trivial, \u2190 mem_coe] },\n      { intros x hx, rw mem_singleton_iff at hx, subst hx, exact one_mem _ } }\nend\n\nlemma comm_group_iff' : (commutator_normal G : subgroup G) = \u22a5 \u2194 \n  @commutative G (*) :=\nbegin\n  rw \u2190 comm_group_iff, \n  split; intro h,\n    { change (commutator_normal G).carrier = _,\n      change (commutator_normal G).to_subgroup = _ at h,\n      rw [h, bot_eq_trivial], refl },\n    { apply ext', rw bot_eq_trivial, exact h }\nend\n\nlemma commutator_normal_eq_bot_iff : \n  (commutator_normal G : subgroup G) = \u22a5 \u2194 commutators G = {1} :=\nbegin\n  change closure (commutators G) = _ \u2194 _,\n  rw eq_bot_iff,\n  split; intro h,\n    { ext, split; intro hx,\n        { change x \u2208 subgroup.trivial.carrier,\n          rw \u2190 bot_eq_trivial,\n          exact h (le_closure _ hx) },\n        { exact hx.symm \u25b8 \u27e81, 1, by simp\u27e9 } },\n    { rw [closure_le, h],\n      intros x hx, rw mem_singleton_iff at hx,\n      subst hx, exact one_mem _ }\nend\n\n/-- Given the group homomorphism `f : G \u2192 H` where `H` is a abelian, for all `x`\n  in the commutators of `G`, `f x = 1` -/\nlemma map_commutators_eq_one {H : Type} [comm_group H] (f : G \u2192* H) : \n  \u2200 x \u2208 commutators G, f x = 1 :=\nbegin\n  intros x hx,\n  rw mem_commutators_iff at hx,\n  rcases hx with \u27e8a, b, rfl\u27e9,\n  simp [group.mul_comm],\nend\n\nlemma closure_eq_kernel_of_map_eq_one {H : Type} [group H] \n  {f : G \u2192* H} {S : set G} (hS : \u2200 s \u2208 S, f s = 1) : closure S \u2264 kernel f :=\nbegin\n  intros x hx,\n  erw mem_closure_iff at hx,\n  specialize hx (comap f \u22a5) _,\n  rw mem_comap' at hx,\n  change f x = 1,\n  rw [\u2190 mem_singleton_iff, \u2190 bot_eq_singleton_one],\n  exact hx,\n  intros s hs,\n  erw mem_comap', \n  rw mem_bot_iff,\n  exact hS s hs,\nend\n\nlemma map_le_iff_le_comap {H : Type} [group H] \n  {f : G \u2192* H} {S : subgroup G} {T : subgroup H} : \n  map f S \u2264 T \u2194 S \u2264 comap f T := \nbegin\n  split; intro h,\n    { intros x hx, erw mem_comap',\n      apply h, erw mem_map,\n      refine \u27e8x, hx, rfl\u27e9 },\n    { intros x hx, \n      erw mem_map at hx,\n      rcases hx with \u27e8y, hy, rfl\u27e9,\n      erw \u2190 mem_comap',\n      exact h hy }\nend\n\nlemma kernel_eq_comap_bot {H : Type} [group H] (f : G \u2192* H) : \n  (kernel f : subgroup G) = comap f \u22a5 := \nby ext; erw [mem_kernel, \u2190 mem_bot_iff, mem_comap']\n\nlemma map_commutator_normal_le_bot {H : Type} [comm_group H] (f : G \u2192* H) : \n  map f (commutator_normal G) \u2264 \u22a5 := \nbegin\n  rw map_le_iff_le_comap,\n  convert closure_eq_kernel_of_map_eq_one (map_commutators_eq_one f),\n  exact (kernel_eq_comap_bot f).symm\nend\n\nend subgroup\n\n-- Disadvantage with using bundled normal: we don't have a lattice structure for \n-- normal subgroups\n\n-- \u22a2 commutators G \u2286 \u2191N \u2194 commutators (G /\u2098 N) = {1}\n-- Consider mk : G \u2192 G /\u2098 N is a surjective homomorphism with the kernel N,\n-- so the goal is saying the commutators is in the kernel iff the \n-- commutators of G /\u2098 N  is 1, i.e. we need to show that \n-- commutators (G /\u2098 N) \u2286 quotient.mk N '' commutators G \nlemma quotient.comm_iff_commutators_subset (N : normal G) : \n  commutators G \u2286 N \u2194 @commutative (G /\u2098 N) (*) :=\nbegin\n  rw [\u2190 subgroup.comm_group_iff', subgroup.commutator_normal_eq_bot_iff],\n  have : commutators (G /\u2098 N) \u2286  quotient.mk N '' commutators G,\n    rintro x \u27e8a, b, rfl\u27e9,\n    rcases exists_mk a with \u27e8a, rfl\u27e9,\n    rcases exists_mk b with \u27e8b, rfl\u27e9,\n    exact \u27e8commutator a b, \u27e8a, b, rfl\u27e9, rfl\u27e9,\n  conv_lhs { rw \u2190 @kernel_mk _ _ N },\n  split; intro h,\n    { apply subset.antisymm,\n        { refine subset.trans this (\u03bb _ hx, _),\n          rcases hx with \u27e8x, hx, rfl\u27e9, \n          rw [mem_singleton_iff, \u2190 mem_kernel],\n          exact h hx },\n        { intros x hx,\n          rw mem_singleton_iff at hx,\n          rw hx, exact \u27e81, 1, by simp\u27e9 } },\n    { rintro _ \u27e8a, b, rfl\u27e9,\n      change _ \u2208 (mk N).kernel,\n      rw [mem_kernel, \u2190 mem_singleton_iff, \u2190 h],\n      exact \u27e8a, b, rfl\u27e9 }\nend\n\n/-- For all `N : normal G`, if it contains the comutator subgroup, then \n  `G /\u2098 N` is abelian. -/\ntheorem quotient.comm_iff_commutators_le (N : normal G) : \n  subgroup.commutator_normal G \u2264 N \u2194 @commutative (G /\u2098 N) (*) := \nshow closure (commutators G) \u2264 _ \u2194 _, \n  by rw [\u2190 quotient.comm_iff_commutators_subset, closure_le]; refl\n\n/-- A subgroup is normal if it comatins the commutators -/\ndef normal.of_subset_commutators (H : subgroup G) (hH : commutators G \u2286 H) := \n  normal.of_subgroup H \nbegin\n  intros n hn g, \n  rw [show g * n * g\u207b\u00b9 = g * n * g\u207b\u00b9 * n\u207b\u00b9 * n, by simp [group.mul_assoc]],\n  exact mul_mem _ (hH \u27e8g, n, rfl\u27e9) hn\nend\n\ndef group.comm_group_of (G : Type) [group G] (hG : @commutative G (*)) : \n  comm_group G := { mul_comm := hG, .. \u2039group G\u203a }\n\n/-- The Abelianization of a group is the group quotiented out by its commutator\n  normal subgroup -/\ndef abelianization (G : Type) [group G] := G /\u2098 subgroup.commutator_normal G\n\n-- The Abelianization of a group is commutative\ninstance := group.comm_group_of (G /\u2098 subgroup.commutator_normal G) \n  ((quotient.comm_iff_commutators_subset _).1 (le_closure _))\n\nnamespace abelianization\n\nvariables {H : Type} [comm_group H]\n\ndef lift (f : G \u2192* H) := quotient.lift f (subgroup.commutator_normal G)\nbegin\n  convert subgroup.map_le_iff_le_comap.1  \n    (subgroup.map_commutator_normal_le_bot f),\n  exact subgroup.kernel_eq_comap_bot f\nend\n\n@[simp] lemma lift_def (f : G \u2192* H) : \n  (lift f \u2218* quotient.mk (subgroup.commutator_normal G)) = f := by ext; refl\n\n/-- The universal property of Abelianization of Groups -/\nlemma lift.exists_unique (H : Type) [comm_group H] (f : G \u2192* H) : \n  \u2203! F : (G /\u2098 subgroup.commutator_normal G) \u2192* H, \n  f = (F \u2218* quotient.mk (subgroup.commutator_normal G)) :=\n\u27e8abelianization.lift f, by simp, by rintros F rfl; tidy\u27e9\n\nend abelianization\n\nend mygroup", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/src/subgroup/commutator.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7335766706536673}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.fintype.powerset\n! leanprover-community/mathlib commit 509de852e1de55e1efa8eacfa11df0823f26f226\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Data.Finset.Powerset\n\n/-!\n# fintype instance for `Set \u03b1`, when `\u03b1` is a fintype\n-/\n\n\nvariable {\u03b1 : Type _}\n\nopen Finset\n\ninstance Finset.fintype [Fintype \u03b1] : Fintype (Finset \u03b1) :=\n  \u27e8univ.powerset, fun _ => Finset.mem_powerset.2 (Finset.subset_univ _)\u27e9\n#align finset.fintype Finset.fintype\n\n@[simp]\ntheorem Fintype.card_finset [Fintype \u03b1] : Fintype.card (Finset \u03b1) = 2 ^ Fintype.card \u03b1 :=\n  Finset.card_powerset Finset.univ\n#align fintype.card_finset Fintype.card_finset\n\n@[simp]\ntheorem Finset.powerset_univ [Fintype \u03b1] : (univ : Finset \u03b1).powerset = univ :=\n  coe_injective <| by simp [-coe_eq_univ]\n#align finset.powerset_univ Finset.powerset_univ\n\n@[simp]\ntheorem Finset.powerset_eq_univ [Fintype \u03b1] {s : Finset \u03b1} : s.powerset = univ \u2194 s = univ := by\n  rw [\u2190 Finset.powerset_univ, powerset_inj]\n#align finset.powerset_eq_univ Finset.powerset_eq_univ\n\ntheorem Finset.mem_powerset_len_univ_iff [Fintype \u03b1] {s : Finset \u03b1} {k : \u2115} :\n    s \u2208 powersetLen k (univ : Finset \u03b1) \u2194 card s = k :=\n  mem_powersetLen.trans <| and_iff_right <| subset_univ _\n#align finset.mem_powerset_len_univ_iff Finset.mem_powerset_len_univ_iff\n\n@[simp]\ntheorem Finset.univ_filter_card_eq (\u03b1 : Type _) [Fintype \u03b1] (k : \u2115) :\n    ((Finset.univ : Finset (Finset \u03b1)).filter fun s => s.card = k) = Finset.univ.powersetLen k :=\n  by\n  ext\n  simp [Finset.mem_powersetLen]\n#align finset.univ_filter_card_eq Finset.univ_filter_card_eq\n\n@[simp]\ntheorem Fintype.card_finset_len [Fintype \u03b1] (k : \u2115) :\n    Fintype.card { s : Finset \u03b1 // s.card = k } = Nat.choose (Fintype.card \u03b1) k := by\n  simp [Fintype.subtype_card, Finset.card_univ]\n#align fintype.card_finset_len Fintype.card_finset_len\n\ninstance Set.fintype [Fintype \u03b1] : Fintype (Set \u03b1) :=\n  \u27e8(@Finset.univ \u03b1 _).powerset.map \u27e8(\u2191), coe_injective\u27e9, fun s => by\n    classical\n      refine' mem_map.2 \u27e8Finset.univ.filter s, Finset.mem_powerset.2 (Finset.subset_univ _), _\u27e9\n      apply (coe_filter _ _).trans\n      simp\n      rfl\u27e9\n#align set.fintype Set.fintype\n\n-- Not to be confused with `Set.Finite`, the predicate\ninstance Set.finite' [Finite \u03b1] : Finite (Set \u03b1) := by\n  cases nonempty_fintype \u03b1\n  infer_instance\n#align set.finite' Set.finite'\n\n@[simp]\ntheorem Fintype.card_set [Fintype \u03b1] : Fintype.card (Set \u03b1) = 2 ^ Fintype.card \u03b1 :=\n  (Finset.card_map _).trans (Finset.card_powerset _)\n#align fintype.card_set Fintype.card_set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Fintype/Powerset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7335766697130865}}
{"text": "-- Razonamiento sobre programas\n-- ============================\n\n-- En este tema se demuestra con Lean las\n-- propiedades de los programas funcionales como se\n-- expone en el tema 8 del curso \"Inform\u00e1tica\" que\n-- puede leerse en http://bit.ly/2Za6YWY\n\nimport tactic\nimport data.list.basic\nimport data.nat.basic\nopen list nat\n\nuniverses u v w w\u2081 w\u2082\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\nvariable  x : \u03b1\nvariables (xs ys zs : list \u03b1)\nvariable  y : \u03b2\nvariable  n : \u2115\nvariable  ns : list \u2115\n\n-- \u00a7 Razonamiento ecuacional\n-- =========================\n\n-- ----------------------------------------------------\n-- Ejercicio 1.a. Definir, por recursi\u00f3n, la funci\u00f3n\n--    longitud : list \u03b1 \u2192 \u2115\n-- tal que (longitud xs) es la longitud de la listas\n-- xs. Por ejemplo,\n--    longitud [a,c,d] = 3\n-- ----------------------------------------------------\n\n@[simp] def longitud : list \u03b1 \u2192 nat\n| []        := 0\n| (x :: xs) := longitud xs + 1\n\n-- ----------------------------------------------------\n-- Ejercicio 1.b. Calcular\n--    longitud [4,2,5]\n-- ----------------------------------------------------\n\n-- #eval longitud [4,2,5]\n-- da 3\n\n-- ----------------------------------------------------\n-- Ejermplo 1.c. Demostrar los siguientes lemas\n-- + longitud_nil :\n--     longitud ([] : list \u03b1) = 0\n-- + longitud_cons :\n--     longitud (x :: xs) = longitud xs + 1\n-- ----------------------------------------------------\n\nlemma longitud_nil :\n  longitud ([] : list \u03b1) = 0 :=\nrfl\n\nlemma longitud_cons :\n  longitud (x :: xs) = longitud xs + 1 :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    longitud [4,2,5] = 3\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (a b c : \u03b1)\n  : longitud [a,b,c] = 3 :=\nbegin\n  rw longitud_cons,\n  rw longitud_cons,\n  rw longitud_cons,\n  rw longitud_nil,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (a b c : \u03b1)\n  : longitud [a,b,c] = 3 :=\nby rw [longitud_cons,\n       longitud_cons,\n       longitud_cons,\n       longitud_nil]\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (a b c : \u03b1)\n  : longitud [a,b,c] = 3 :=\nby simp only [longitud_cons,\n              longitud_nil]\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (a b c : \u03b1)\n  : longitud [a,b,c] = 3 :=\nrfl\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (a b c : \u03b1)\n  : longitud [a,b,c] = 3 :=\ncalc\n  longitud [a,b,c]\n      = longitud [b,c] + 1          : by rw longitud_cons\n  ... = (longitud [c] + 1) + 1      : by rw longitud_cons\n  ... = ((longitud [] + 1) + 1) + 1 : by rw longitud_cons\n  ... = ((0 + 1) + 1) + 1           : by rw longitud_nil\n  ... = 3                           : rfl\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (a b c : \u03b1)\n  : longitud [a,b,c] = 3 :=\ncalc\n  longitud [a,b,c]\n      = longitud [b,c] + 1          : rfl\n  ... = (longitud [c] + 1) + 1      : rfl\n  ... = ((longitud [] + 1) + 1) + 1 : rfl\n  ... = ((0 + 1) + 1) + 1           : rfl\n  ... = 3                           : rfl\n\n-- ----------------------------------------------------\n-- Ejercicio 3.a. Definir la funci\u00f3n\n--    intercambia :: \u03b1 \u00d7 \u03b2 \u2192 \u03b2 \u00d7 \u03b1\n-- tal que (intercambia p) es el par obtenido\n-- intercambiando las componentes del par p. Por\n-- ejemplo,\n--    intercambia (u,v) = (v,u)\n-- ----------------------------------------------------\n\ndef intercambia : \u03b1 \u00d7 \u03b2 \u2192 \u03b2 \u00d7 \u03b1 :=\n\u03bbp, (p.2, p.1)\n\n-- ----------------------------------------------------\n-- Ejercicio 3.b. Demostrar el lema\n--    intercambia_simp : intercambia p = (p.2, p.1)\n-- ----------------------------------------------------\n\nlemma intercambia_simp\n  {p : \u03b1 \u00d7 \u03b2}\n  : intercambia p = (p.2, p.1) :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 4. (p.6) Demostrar que\n--    intercambia (intercambia (x,y)) = (x,y)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : \u2200 p : \u03b1 \u00d7 \u03b2, intercambia (intercambia p) = p :=\nbegin\n  rintro \u27e8x,y\u27e9,\n  rw intercambia_simp,\n  rw intercambia_simp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : \u2200 p : \u03b1 \u00d7 \u03b2, intercambia (intercambia p) = p :=\n\u03bb \u27e8x,y\u27e9, by simp only [intercambia_simp]\n\n-- 3\u00aa demostraci\u00f3n\nexample : \u2200 p : \u03b1 \u00d7 \u03b2, intercambia (intercambia p) = p\n| (x,y) := rfl\n\n-- ----------------------------------------------------\n-- Ejercicio 5.a. Definir, por recursi\u00f3n, la funci\u00f3n\n--    inversa :: list \u03b1 \u2192 list \u03b1\n-- tal que (inversa xs) es la lista obtenida\n-- invirtiendo el orden de los elementos de xs.\n-- Por ejemplo,\n--    inversa [3,2,5] = [5,2,3]\n-- ----------------------------------------------------\n\n@[simp] def inversa : list \u03b1 \u2192 list \u03b1\n| []        := []\n| (x :: xs) := inversa xs ++ [x]\n\n-- #eval inversa [3,2,5]\n\n-- ----------------------------------------------------\n-- Ejermplo 5.b. Demostrar los siguientes lemas\n-- + inversa_nil :\n--     inversa ([] : list \u03b1) = []\n-- + inversa_cons :\n--     inversa (x :: xs) = inversa xs ++ [x]\n-- ----------------------------------------------------\n\nlemma inversa_nil :\n  inversa ([] : list \u03b1) = [] :=\nrfl\n\nlemma inversa_cons :\n  inversa (x :: xs) = inversa xs ++ [x] :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 6. (p. 9) Demostrar que\n--    inversa [x] = [x]\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\nbegin\n  rw inversa_cons,\n  rw inversa_nil,\n  rw nil_append,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\nby simp [inversa_cons,\n         inversa_nil,\n         nil_append]\n\n-- 3\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\nrfl\n\n-- 4\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\ncalc inversa [x]\n         = inversa ([] : list \u03b1) ++ [x] : by rw inversa_cons\n     ... = ([] : list \u03b1) ++ [x]         : by rw inversa_nil\n     ... = [x]                          : by rw nil_append\n\n-- 5\u00aa demostraci\u00f3n (con predefinida)\nexample : reverse [x] = [x] :=\n-- by library_search\nreverse_singleton x\n\n-- \u00a7 Razonamiento por inducci\u00f3n sobre los naturales\n-- ================================================\n\n-- [Principio de inducci\u00f3n sobre los naturales] Para\n-- demostrar una propiedad P para todos los n\u00fameros\n-- naturales basta probar que el 0 tiene la propiedad P\n-- y que si n tiene la propiedad P, entonces n+1\n-- tambi\u00e9n la tiene.\n--\n-- En Lean el principio de inducci\u00f3n sobre los\n-- naturales est\u00e1 formalizado en el lema nat.rec_on.\n\n-- ----------------------------------------------------\n-- Ejercicio 7.a. Definir la funci\u00f3n\n--    repite :: \u2115 \u2192 \u03b1 \u2192 list \u03b1\n-- tal que (repite n x) es la lista formada por n\n-- copias del elemento x. Por ejemplo,\n--    repite 3 7 = [7,7,7]\n-- ----------------------------------------------------\n\n@[simp] def repite : \u2115 \u2192 \u03b1 \u2192 list \u03b1\n| 0 x        := []\n| (succ n) x := x :: repite n x\n\n-- #eval repite 3 7\n\n-- ----------------------------------------------------\n-- Ejermplo 7.b. Demostrar los siguientes lemas\n-- + repite_cero :\n--     repite 0 x = []\n-- + repite_suc :\n--     repite (succ n) x = x :: repite n x\n-- ----------------------------------------------------\n\nlemma repite_cero :\n  repite 0 x = [] :=\nrfl\n\nlemma repite_suc :\n  repite (succ n) x = x :: repite n x :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 8. (p. 18) Demostrar que\n--    longitud (repite n x) = n\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : longitud (repite n x) = n :=\nbegin\n  induction n with n HI,\n  { rw repite_cero,\n    rw longitud_nil, },\n  { rw repite_suc,\n    rw longitud_cons,\n    rw HI, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : longitud (repite n x) = n :=\nbegin\n  induction n with n HI,\n  { simp only [repite_cero, longitud_nil], },\n  { simp only [repite_suc, longitud_cons, HI], },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : longitud (repite n x) = n :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { simp [HI], },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample : longitud (repite n x) = n :=\nby induction n ; simp [*]\n\n-- 5\u00aa demostraci\u00f3n\nexample : longitud (repite n x) = n :=\nbegin\n  induction n with n HI,\n  { calc\n      longitud (repite 0 x)\n          = longitud []\n              : by rw repite_cero\n      ... = 0\n              : by rw longitud_nil },\n  { calc\n      longitud (repite (succ n) x)\n          = longitud (x :: repite n x)\n              : by rw repite_suc\n      ... = longitud (repite n x) + 1\n              : by rw longitud_cons\n      ... = n + 1\n              : by rw HI\n      ... = succ n\n              : rfl, },\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample : longitud (repite n x) = n :=\nnat.rec_on n\n  ( show longitud (repite 0 x) = 0, from\n      calc\n        longitud (repite 0 x)\n            = longitud []\n                : by rw repite_cero\n        ... = 0\n                : by rw longitud_nil )\n  ( assume n,\n    assume HI : longitud (repite n x) = n,\n    show longitud (repite (succ n) x) = succ n, from\n      calc\n      longitud (repite (succ n) x)\n          = longitud (x :: repite n x)\n              : by rw repite_suc\n      ... = longitud (repite n x) + 1\n              : by rw longitud_cons\n      ... = n + 1\n              : by rw HI\n      ... = succ n\n              : rfl )\n\n-- 6\u00aa demostraci\u00f3n\nexample : longitud (repite n x) = n :=\nnat.rec_on n\n  ( by simp )\n  ( \u03bb n HI, by simp [*])\n\n-- 7\u00aa demostraci\u00f3n\nlemma longitud_repite_1 :\n  \u2200 n, longitud (repite n x) = n\n| 0 := by calc\n    longitud (repite 0 x)\n        = longitud ([] : list \u03b1)\n          : by rw repite_cero\n    ... = 0\n          : by rw longitud_nil\n| (n+1) := by calc\n    longitud (repite (n + 1) x)\n        = longitud (x :: repite n x)\n          : by rw repite_suc\n    ... = longitud (repite n x) + 1\n          : by rw longitud_cons\n    ... = n + 1\n          : by rw longitud_repite_1\n\n-- 8\u00aa demostraci\u00f3n\nlemma longitud_repite_2 :\n  \u2200 n, longitud (repite n x) = n\n| 0     := by simp\n| (n+1) := by simp [*]\n\n-- 9\u00aa demostraci\u00f3n (con predefinidas)\nexample : length (repeat x n) = n :=\n-- by library_search\nlength_repeat x n\n\n-- \u00a7 Razonamiento por inducci\u00f3n sobre listas\n-- =========================================\n\n-- Para demostrar una propiedad para todas las listas\n-- basta demostrar que la lista vac\u00eda tiene la\n-- propiedad y que al a\u00f1adir un elemento a una lista\n-- que tiene la propiedad se obtiene otra lista que\n-- tambi\u00e9n tiene la propiedad.\n--\n-- En Lean el principio de inducci\u00f3n sobre listas est\u00e1\n-- formalizado mediante el teorema list.rec_on que se\n-- puede ver con\n--    #check list.rec_on\n\n-- ----------------------------------------------------\n-- Ejercicio 9.a. Definir la funci\u00f3n\n--    conc :: list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n-- tal que (conc xs ys) es la concatenci\u00f3n de las\n-- listas xs e ys. Por ejemplo,\n--    conc [1,4] [2,4,1,3] = [1,4,2,4,1,3]\n-- ----------------------------------------------------\n\n@[simp] def conc : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| []        ys := ys\n| (x :: xs) ys := x :: (conc xs ys)\n\n-- #eval conc [1,4] [2,4,1,3]\n\n-- ----------------------------------------------------\n-- Ejermplo 9.b. Demostrar los siguientes lemas\n-- + conc_nil :\n--     conc ([] : list \u03b1) ys = ys\n-- + conc_cons :\n--     conc (x :: xs) ys = x :: (conc xs ys)\n-- ----------------------------------------------------\n\nlemma conc_nil :\n  conc ([] : list \u03b1) ys = ys :=\nrfl\n\nlemma conc_cons :\n  conc (x :: xs) ys = x :: (conc xs ys) :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 10. (p. 24) Demostrar que\n--    conc xs (conc ys zs) = conc (conc xs ys) zs\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  conc xs (conc ys zs) = conc (conc xs ys) zs :=\nbegin\n  induction xs with x xs HI,\n  { rw conc_nil,\n    rw conc_nil, },\n  { rw conc_cons,\n    rw HI,\n    rw conc_cons,\n    rw conc_cons, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  conc xs (conc ys zs) = conc (conc xs ys) zs :=\nbegin\n  induction xs with x xs HI,\n  { calc conc nil (conc ys zs)\n         = conc ys zs            : by rw conc_nil\n     ... = conc (conc nil ys) zs : by rw conc_nil, },\n  { calc conc (x :: xs) (conc ys zs)\n         = x :: conc xs (conc ys zs)\n           : by rw conc_cons\n     ... = x :: conc (conc xs ys) zs\n           : by rw HI\n     ... = conc (x :: conc xs ys) zs\n           : by rw conc_cons\n     ... = conc (conc (x :: xs) ys) zs\n           : by rw \u2190conc_cons, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  conc xs (conc ys zs) = conc (conc xs ys) zs :=\nbegin\n  induction xs with x xs HI,\n  { simp, },\n  { simp [HI], },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  conc xs (conc ys zs) = conc (conc xs ys) zs :=\nby induction xs ; simp [*]\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  conc xs (conc ys zs) = conc (conc xs ys) zs :=\nlist.rec_on xs\n  ( show conc nil (conc ys zs) = conc (conc nil ys) zs,\n      from calc conc nil (conc ys zs)\n                = conc ys zs\n                    : by rw conc_nil\n            ... = conc (conc nil ys) zs\n                    : by rw conc_nil )\n    ( assume x xs,\n      assume HI : conc xs (conc ys zs) =\n                  conc (conc xs ys) zs,\n      show conc (x :: xs) (conc ys zs) =\n           conc (conc (x :: xs) ys) zs, from\n        calc conc (x :: xs) (conc ys zs)\n             = x :: conc xs (conc ys zs)\n               : by rw conc_cons\n        ... = x :: conc (conc xs ys) zs\n              : by rw HI\n        ... = conc (x :: conc xs ys) zs\n              : by rw conc_cons\n        ... = conc (conc (x :: xs) ys) zs\n              : by rw \u2190conc_cons)\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  conc xs (conc ys zs) = conc (conc xs ys) zs :=\nlist.rec_on xs\n  (by simp)\n  (by simp [*])\n\n-- 7\u00aa demostraci\u00f3n\nlemma conc_asoc_1 :\n  \u2200 xs, conc xs (conc ys zs) = conc (conc xs ys) zs\n| [] := by calc\n    conc [] (conc ys zs)\n        = conc ys zs\n          : by rw conc_nil\n    ... = conc (conc [] ys) zs\n          : by rw conc_nil\n| (x :: xs) := by calc\n    conc (x :: xs) (conc ys zs)\n        = x :: conc xs (conc ys zs)\n          : by rw conc_cons\n    ... = x :: conc (conc xs ys) zs\n          : by rw conc_asoc_1\n    ... = conc (x :: conc xs ys) zs\n          : by rw conc_cons\n    ... = conc (conc (x :: xs) ys) zs\n          : by rw \u2190conc_cons\n\n-- 8\u00aa demostraci\u00f3n\nlemma conc_asoc_2 :\n  \u2200 xs, conc xs (conc ys zs) = conc (conc xs ys) zs\n| []         := by simp\n| (x :: xs)  := by simp [conc_asoc_2 xs]\n\n-- 9\u00aa demostraci\u00f3n (con predefinas)\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\n-- by library_search\n(append_assoc xs ys zs).symm\n\n-- ----------------------------------------------------\n-- Ejercicio 12. (p. 28) Demostrar que\n--    conc xs [] = xs\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nbegin\n  induction xs with x xs HI,\n  { rw conc_nil, },\n  { rw conc_cons,\n    rw HI, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nbegin\n  induction xs with x xs HI,\n  { rw [conc_nil], },\n  { rw [conc_cons, HI], },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nbegin\n  induction xs with x xs HI,\n  { simp only [conc_nil], },\n  { simp only [conc_cons, HI],\n    cc, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nbegin\n  induction xs with x xs HI,\n  { simp , },\n  { simp [HI], },\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nby induction xs ; simp [*]\n\n-- 6\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nbegin\n  induction xs with x xs HI,\n  { calc\n      conc [] [] = [] : by rw conc_nil, },\n  { calc\n      conc (x :: xs) []\n          = x :: (conc xs []) : by rw conc_cons\n      ... = x :: xs           : by rw HI, },\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nlist.rec_on xs\n  ( show conc [] [] = [], from calc\n      conc [] [] = [] : by rw conc_nil )\n  ( assume x xs,\n    assume HI : conc xs [] = xs,\n    show conc (x :: xs) [] = x :: xs, from calc\n      conc (x :: xs) []\n          = x :: (conc xs []) : by rw conc_cons\n      ... = x :: xs           : by rw HI)\n\n-- 8\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nlist.rec_on xs\n  ( show conc [] [] = [], by simp)\n  ( assume x xs,\n    assume HI : conc xs [] = xs,\n    show conc (x :: xs) [] = x :: xs, by simp [HI])\n\n-- 9\u00aa demostraci\u00f3n\nexample : conc xs [] = xs :=\nlist.rec_on xs\n  (by simp)\n  (\u03bb x xs HI, by simp [HI])\n\n-- 10\u00aa demostraci\u00f3n\nlemma conc_nil_1:\n  \u2200 xs : list \u03b1, conc xs [] = xs\n| []        := by calc\n    conc [] [] = [] : by rw conc_nil\n| (x :: xs) := by calc\n    conc (x :: xs) []\n        = x :: conc xs [] : by rw conc_cons\n    ... = x :: xs         : by rw conc_nil_1\n\n-- 11\u00aa demostraci\u00f3n\nlemma conc_nil_2:\n  \u2200 xs : list \u03b1, conc xs [] = xs\n| []        := by simp\n| (x :: xs) := by simp [conc_nil_2 xs]\n\n-- 12\u00aa demostraci\u00f3n (con predefinida)\nexample : xs ++ [] = xs :=\n-- by library_search\nappend_nil xs\n\n-- ----------------------------------------------------\n-- Ejercicio 13. (p. 30) Demostrar que\n--    longitud (conc xs ys) = longitud xs + longitud ys\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nbegin\n  induction xs with x xs HI,\n  { rw conc_nil,\n    rw longitud_nil,\n    rw nat.zero_add, },\n  { rw conc_cons,\n    rw longitud_cons,\n    rw HI,\n    rw longitud_cons,\n    rw add_assoc,\n    rw add_comm (longitud ys),\n    rw add_assoc, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nbegin\n  induction xs with x xs HI,\n  { rw conc_nil,\n    rw longitud_nil,\n    rw nat.zero_add, },\n  { rw conc_cons,\n    rw longitud_cons,\n    rw HI,\n    rw longitud_cons,\n    -- library_search,\n    exact add_right_comm (longitud xs) (longitud ys) 1},\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nbegin\n  induction xs with x xs HI,\n  { rw conc_nil,\n    rw longitud_nil,\n    rw nat.zero_add, },\n  { rw conc_cons,\n    rw longitud_cons,\n    rw HI,\n    rw longitud_cons,\n    -- by hint,\n    linarith, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nbegin\n  induction xs with x xs HI,\n  { simp, },\n  { simp [HI],\n    linarith, },\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nbegin\n  induction xs with x xs HI,\n  { simp, },\n  { finish [HI],},\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nby induction xs ; finish [*]\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nbegin\n  induction xs with x xs HI,\n  { calc longitud (conc [] ys)\n         = longitud ys\n           : by rw conc_nil\n     ... = 0 + longitud ys\n           : by exact (zero_add (longitud ys)).symm\n     ... = longitud [] + longitud ys\n           : by rw longitud_nil },\n  { calc longitud (conc (x :: xs) ys)\n         = longitud (x :: conc xs ys)\n           : by rw conc_cons\n     ... = longitud (conc xs ys) + 1\n           : by rw longitud_cons\n     ... = (longitud xs + longitud ys) + 1\n           : by rw HI\n     ... = (longitud xs + 1) + longitud ys\n           : by exact add_right_comm (longitud xs) (longitud ys) 1\n     ... = longitud (x :: xs) + longitud ys\n           : by rw longitud_cons, },\nend\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nlist.rec_on xs\n  ( show longitud (conc [] ys) =\n         longitud [] + longitud ys, from\n      calc longitud (conc [] ys)\n           = longitud ys\n             : by rw conc_nil\n       ... = 0 + longitud ys\n             : by exact (zero_add (longitud ys)).symm\n       ... = longitud [] + longitud ys\n             : by rw longitud_nil )\n  ( assume x xs,\n    assume HI : longitud (conc xs ys) =\n                longitud xs + longitud ys,\n    show longitud (conc (x :: xs) ys) =\n         longitud (x :: xs) + longitud ys, from\n      calc longitud (conc (x :: xs) ys)\n           = longitud (x :: conc xs ys)\n             : by rw conc_cons\n       ... = longitud (conc xs ys) + 1\n             : by rw longitud_cons\n       ... = (longitud xs + longitud ys) + 1\n             : by rw HI\n       ... = (longitud xs + 1) + longitud ys\n             : by exact add_right_comm (longitud xs) (longitud ys) 1\n       ... = longitud (x :: xs) + longitud ys\n             : by rw longitud_cons)\n\n-- 9\u00aa demostraci\u00f3n\nexample :\n  longitud (conc xs ys) = longitud xs + longitud ys :=\nlist.rec_on xs\n  ( by simp)\n  ( \u03bb x xs HI, by simp [HI, add_right_comm])\n\n-- 10\u00aa demostraci\u00f3n\nlemma longitud_conc_1 :\n  \u2200 xs, longitud (conc xs ys) = longitud xs + longitud ys\n| [] := by calc\n    longitud (conc [] ys)\n        = longitud ys\n          : by rw conc_nil\n    ... = 0 + longitud ys\n          : by rw zero_add\n    ... = longitud [] + longitud ys\n          : by rw longitud_nil\n| (x :: xs) := by calc\n    longitud (conc (x :: xs) ys)\n        = longitud (x :: conc xs ys)\n          : by rw conc_cons\n    ... = longitud (conc xs ys) + 1\n          : by rw longitud_cons\n    ... = (longitud xs + longitud ys) + 1\n          : by rw longitud_conc_1\n    ... = (longitud xs + 1) + longitud ys\n          : by exact add_right_comm (longitud xs) (longitud ys) 1\n    ... = longitud (x :: xs) + longitud ys\n          : by rw longitud_cons\n\n-- 11\u00aa demostraci\u00f3n\nlemma longitud_conc_2 :\n  \u2200 xs, longitud (conc xs ys) = longitud xs + longitud ys\n| []        := by simp\n| (x :: xs) := by simp [longitud_conc_2 xs,\n                        add_right_comm]\n\n-- 12\u00aa demostraci\u00f3n /con predefinidas)\nexample :\n  length (xs ++ ys) = length xs + length ys :=\n-- by library_search\nlength_append xs ys\n\n-- \u00a7 Inducci\u00f3n correspondiente a la definici\u00f3n recursiva\n-- =====================================================\n\n-- ----------------------------------------------------\n-- Ejercicio 14.a. Definir la funci\u00f3n\n--    coge : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n-- tal que (coge n xs) es la lista de los n primeros\n-- elementos de xs. Por ejemplo,\n--    coge 2 [1,4,2,7,0] =  [1,4]\n-- ----------------------------------------------------\n\n@[simp] def coge : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0        xs        := []\n| (succ n) []        := []\n| (succ n) (x :: xs) := x :: coge n xs\n\n-- #eval coge 2 [1,4,2,7]\n\n-- ----------------------------------------------------\n-- Ejercicio 14.b. Demostrar los siguientes lemas\n-- + coge_cero :\n--      coge 0 xs = []\n-- + coge_nil :\n--      coge n [] = []\n-- + coge_cons :\n--      coge (succ n) (x :: xs) = x :: coge n xs\n-- ----------------------------------------------------\n\nlemma coge_cero :\n  coge 0 xs = [] :=\nrfl\n\nlemma coge_nil :\n  \u2200 n, coge n ([] : list \u03b1) = []\n| 0     := rfl\n| (n+1) := rfl\n\nlemma coge_cons :\n  coge (succ n) (x :: xs) = x :: coge n xs :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 15.a. Definir la funci\u00f3n\n--    elimina : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n-- tal que (elimina n xs) es la lista obtenida eliminando los n primeros\n-- elementos de xs. Por ejemplo,\n--    elimina 2 [1,4,2,7,0] = [2,7,0]\n-- ----------------------------------------------------\n\n@[simp] def elimina : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0        xs        := xs\n| (succ n) []        := []\n| (succ n) (x :: xs) := elimina n xs\n\n-- #eval elimina 2 [1,4,2,7,0]\n\n-- ----------------------------------------------------\n-- Ejermplo 15.b. Demostrar los siguientes lemas\n-- + elimina_cero :\n--      elimina 0 xs = xs\n-- + elimina_nil :\n--      elimina n [] = []\n-- + elimina_cons :\n--      elimina (succ n) (x :: xs) = elimina n xs\n-- ----------------------------------------------------\n\nlemma elimina_cero :\n  elimina 0 xs = xs :=\nrfl\n\nlemma elimina_nil :\n  \u2200 n, elimina n ([] : list \u03b1) = []\n| 0     := rfl\n| (n+1) := rfl\n\nlemma elimina_cons :\n  elimina (succ n) (x :: xs) = elimina n xs :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 16. (p. 35) Demostrar que\n--    conc (coge n xs) (elimina n xs) = xs\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nlemma conc_coge_elimina_1 :\n  \u2200 (n : \u2115) (xs : list \u03b1),\n  conc (coge n xs) (elimina n xs) = xs\n| 0 xs := by calc\n    conc (coge 0 xs) (elimina 0 xs)\n        = conc [] (elimina 0 xs)\n          : by rw coge_cero\n    ... = conc [] xs\n          : by rw elimina_cero\n    ... = xs\n          : by rw conc_nil\n| (succ n) [] := by calc\n    conc (coge (succ n) []) (elimina (succ n) [])\n        = conc ([] : list \u03b1) (elimina (succ n) [])\n          : by rw coge_nil\n    ... = conc [] []\n          : by rw elimina_nil\n    ... = []\n          : by rw conc_nil\n| (succ n) (x :: xs) := by calc\n    conc (coge (succ n) (x :: xs)) (elimina (succ n) (x :: xs))\n        = conc (x :: coge n xs) (elimina (succ n) (x :: xs))\n          : by rw coge_cons\n    ... = conc (x :: coge n xs) (elimina n xs)\n          : by rw elimina_cons\n    ... = x :: conc (coge n xs) (elimina n xs)\n          : by rw conc_cons\n    ... = x :: xs\n          : by rw conc_coge_elimina_1\n\n-- 2\u00aa demostraci\u00f3n\nlemma conc_coge_elimina_2 :\n  \u2200 (n : \u2115) (xs : list \u03b1),\n  conc (coge n xs) (elimina n xs) = xs\n| 0        xs        := by simp\n| (succ n) []        := by simp\n| (succ n) (x :: xs) := by simp [conc_coge_elimina_2]\n\n-- 3\u00aa demostraci\u00f3n\nlemma conc_coge_elimina_3 :\n  \u2200 (n : \u2115) (xs : list \u03b1),\n  conc (coge n xs) (elimina n xs) = xs\n| 0        xs        := rfl\n| (succ n) []        := rfl\n| (succ n) (x :: xs) := congr_arg (cons x) (conc_coge_elimina_3 n xs)\n\n-- 4\u00aa demostraci\u00f3n (usando predefinidas)\nexample : take n xs ++ drop n xs = xs :=\n-- by library_search\ntake_append_drop n xs\n\n-- \u00a7 Razonamiento por casos\n-- ========================\n\n-- ----------------------------------------------------\n-- Ejercicio 17.a. Definir la funci\u00f3n\n--    esVacia : list \u03b1 \u2192 bool\n-- tal que (esVacia xs) se verifica si xs es la lista\n-- vac\u00eda. Por ejemplo,\n--    esVacia []  = tt\n--    esVacia [1] = ff\n-- ----------------------------------------------------\n\n@[simp] def esVacia : list \u03b1 \u2192 bool\n| [] := tt\n| _  := ff\n\n-- #eval esVacia ([] : list \u2115)\n-- #eval esVacia [1]\n\n-- ----------------------------------------------------\n-- Ejercicio 17.b. Demostrar los siguientes lemas\n-- + esVacia_nil :\n--      esVacia ([] : list \u03b1) = tt :=\n-- + esVacia_cons :\n--      esVacia (x :: xs) = ff :=\n-- ----------------------------------------------------\n\nlemma esVacia_nil :\n  esVacia ([] : list \u03b1) = tt :=\nrfl\n\nlemma esVacia_cons :\n  esVacia (x :: xs) = ff :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 18 (p. 39) . Demostrar que\n--    esVacia xs = esVacia (conc xs xs)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : esVacia xs = esVacia (conc xs xs) :=\nbegin\n  cases xs,\n  { rw conc_nil, },\n  { rw conc_cons,\n    rw esVacia_cons,\n    rw esVacia_cons, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nlemma esVacia_conc_1\n  : \u2200 xs : list \u03b1, esVacia xs = esVacia (conc xs xs)\n| []        := by calc\n    esVacia [] = esVacia (conc [] [])\n    : by rw conc_nil\n| (x :: xs) := by calc\n    esVacia (x :: xs)\n        = ff\n          : by rw esVacia_cons\n    ... = esVacia (x :: conc xs (x :: xs))\n          : by rw esVacia_cons\n    ... = esVacia (conc (x :: xs) (x :: xs))\n          : by rw conc_cons\n\n-- 3\u00aa demostraci\u00f3n\nlemma esVacia_conc_2\n  : \u2200 xs : list \u03b1, esVacia xs = esVacia (conc xs xs)\n| []        := by simp\n| (x :: xs) := by simp\n\n-- 3\u00aa demostraci\u00f3n\nexample : esVacia xs = esVacia (conc xs xs) :=\nby cases xs ; simp\n\n-- \u00a7 Heur\u00edstica de generalizaci\u00f3n\n-- ==============================\n\n-- ----------------------------------------------------\n-- Ejercicio 19. Definir la funci\u00f3n\n--    inversaAc : list \u03b1 \u2192 list \u03b1\n-- tal que (inversaAc xs) es a inversa de xs calculada\n-- usando acumuladores. Por ejemplo,\n--    inversaAc [1,3,2,5] = [5,3,2,1]\n-- ----------------------------------------------------\n\n@[simp] def inversaAcAux : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| []        ys := ys\n| (x :: xs) ys := inversaAcAux xs (x :: ys)\n\n@[simp] def inversaAc : list \u03b1 \u2192 list \u03b1 :=\n\u03bb xs, inversaAcAux xs []\n\n-- #eval inversaAc [1,3,2,5]\n\nlemma inversaAcAux_nil :\n  inversaAcAux [] ys = ys :=\nrfl\n\nlemma inversaAcAux_cons :\n  inversaAcAux (x :: xs) ys =\n  inversaAcAux xs (x :: ys) :=\nrfl\n\n-- [Ejercicio de equivalencia entre las definiciones]\n-- La inversa de [a,b,c] es lo mismo calculada con la\n-- primera definici\u00f3n\n-- que con la segunda.\n\nexample : inversaAc [1,2,3] = inversa [1,2,3] :=\nrfl\n\n-- Nota [Ejercicio fallido de demostraci\u00f3n por inducci\u00f3n]\n-- El siguiente intento de demostrar que para cualquier\n-- lista xs, se tiene que  \"inversaAc xs = inversa xs\"\n-- falla.\n\n/-\nexample : inversaAc xs = inversa xs :=\nbegin\n  induction xs with x xs HI,\n  { simp, },\n  { simp,\n    sorry, },\nend\n-/\n\n-- Nota. [Heur\u00edstica de generalizaci\u00f3n]\n-- Cuando se use demostraci\u00f3n estructural, cuantificar\n-- universalmente las  variables libres.\n\n-- ----------------------------------------------------\n-- Ejercicio 20. (p. 44) Demostrar que\n--    inversaAcAux xs ys = (inversa xs) ++ ys\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  inversaAcAux xs ys = (inversa xs) ++ ys :=\nbegin\n  induction xs with x xs HI generalizing ys,\n  { rw inversaAcAux_nil,\n    rw inversa_nil,\n    rw nil_append, },\n  { rw inversaAcAux_cons,\n    rw (HI (x :: ys)),\n    rw inversa_cons,\n    rw append_assoc,\n    rw singleton_append, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  inversaAcAux xs ys = (inversa xs) ++ ys :=\nbegin\n  induction xs with x xs HI generalizing ys,\n  { calc inversaAcAux [] ys\n         = ys\n           : by rw inversaAcAux_nil\n     ... = [] ++ ys\n           : by rw nil_append\n     ... = inversa [] ++ ys\n           : by rw inversa_nil },\n  { calc inversaAcAux (x :: xs) ys\n         = inversaAcAux xs (x :: ys)\n           : by rw inversaAcAux_cons\n     ... = inversa xs ++ (x :: ys)\n           : by rw (HI (x :: ys))\n     ... = inversa xs ++ ([x] ++ ys)\n           : by rw singleton_append\n     ... = (inversa xs ++ [x]) ++ ys\n           : by rw append_assoc\n     ... = inversa (x :: xs) ++ ys\n           : by rw inversa_cons },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  inversaAcAux xs ys = (inversa xs) ++ ys :=\nbegin\n  induction xs with x xs HI generalizing ys,\n  { simp, },\n  { simp [HI (x :: ys)], },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  inversaAcAux xs ys = (inversa xs) ++ ys :=\nby induction xs generalizing ys ; simp [*]\n\n-- 5\u00aa demostraci\u00f3n\nlemma inversa_equiv :\n  \u2200 xs : list \u03b1, \u2200 ys, inversaAcAux xs ys = (inversa xs) ++ ys\n| []         := by simp\n| (x :: xs)  := by simp [inversa_equiv xs]\n\n-- ----------------------------------------------------\n-- Ejercicio 21. (p. 43) Demostrar que\n--    inversaAc xs = inversa xs\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : inversaAc xs = inversa xs :=\ncalc inversaAc xs\n     = inversaAcAux xs [] : rfl\n ... = inversa xs ++ []   : by rw inversa_equiv\n ... = inversa xs         : by rw append_nil\n\n-- 2\u00aa demostraci\u00f3n\nexample : inversaAc xs = inversa xs :=\nby simp [inversa_equiv]\n\n-- \u00a7 Inducci\u00f3n para funciones de orden superior\n-- ============================================\n\n-- ----------------------------------------------------\n-- Ejercicio 22.a. Definir la funci\u00f3n\n--    suma : list \u2115 \u2192 \u2115\n-- tal que (suma xs) es la suma de los elementos de\n-- xs. Por ejemplo,\n--    suma [3,2,5] = 10\n-- ----------------------------------------------------\n\n@[simp] def suma : list \u2115 \u2192 \u2115\n| []        := 0\n| (n :: ns) := n + suma ns\n\n-- #eval sum [3,2,5]\n\n-- ----------------------------------------------------\n-- Ejermplo 22.b. Demostrar los siguientes lemas\n-- + suma_nil :\n--      suma ([] : list \u2115) = 0 :=\n-- + suma_cons :\n--      suma (n :: ns) = n + suma ns :=\n-- ----------------------------------------------------\n\nlemma suma_nil :\n  suma ([] : list \u2115) = 0 :=\nrfl\n\nlemma suma_cons :\n  suma (n :: ns) = n + suma ns :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 23.a Definir la funci\u00f3n\n--    aplica_a_todos : (\u03b1 \u2192 \u03b2) \u2192 list \u03b1 \u2192 'b list\n-- tal que (aplica_a_todos f xs) es la lista obtenida\n-- aplicando la funci\u00f3n f a los elementos de xs. Por\n-- ejemplo,\n--    aplica_a_todos (\u03bbx, 2*x) [3,2,5] = [6,4,10]\n--    aplica_a_todos ((*) 2)   [3,2,5] = [6,4,10]\n--    aplica_a_todos ((+) 2)   [3,2,5] = [5,4,7]\n-- ----------------------------------------------------\n\n@[simp] def aplica_a_todos : (\u03b1 \u2192 \u03b2) \u2192 list \u03b1 \u2192 list \u03b2\n| f []        := []\n| f (x :: xs) := (f x) :: aplica_a_todos f xs\n\n-- #eval aplica_a_todos (\u03bbx, 2*x) [3,2,5]\n-- #eval aplica_a_todos ((*) 2) [3,2,5]\n-- #eval aplica_a_todos ((+) 2) [3,2,5]\n\n-- ----------------------------------------------------\n-- Ejermplo 23.b. Demostrar los siguientes lemas\n-- + aplica_a_todos_nil :\n--      aplica_a_todos ([] : list \u2115) = 0 :=\n-- + aplica_a_todos_cons :\n--      aplica_a_todos (n :: ns) = n + aplica_a_todos ns :=\n-- ----------------------------------------------------\n\nlemma aplica_a_todos_nil\n  (f : \u03b1 \u2192 \u03b2)\n  : aplica_a_todos f [] = [] :=\nrfl\n\nlemma aplica_a_todos_cons\n  (f : \u03b1 \u2192 \u03b2)\n  : aplica_a_todos f (x :: xs) =\n    (f x) :: aplica_a_todos f xs :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 24. (p. 45) Demostrar que\n--    suma (aplica_a_todos (\u03bb x, 2*x) ns) = 2 * (suma ns)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  suma (aplica_a_todos (\u03bb x, 2*x) ns) = 2 * (suma ns) :=\nbegin\n  induction ns with n ns HI,\n  { rw aplica_a_todos_nil,\n    rw suma_nil,\n    rw mul_zero, },\n  { rw aplica_a_todos_cons,\n    rw suma_cons,\n    rw HI,\n    rw suma_cons,\n    rw mul_add, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  suma (aplica_a_todos (\u03bb x, 2*x) ns) = 2 * (suma ns) :=\nbegin\n  induction ns with n ns HI,\n  { calc suma (aplica_a_todos (\u03bb (x : \u2115), 2 * x) [])\n         = suma []\n           : by rw aplica_a_todos_nil\n     ... = 0\n           : by rw suma_nil\n     ... = 2 * 0\n           : by rw mul_zero\n     ... = 2 * suma []\n           : by rw suma_nil, },\n  { calc suma (aplica_a_todos (\u03bb x, 2 * x) (n :: ns))\n         = suma (2 * n :: aplica_a_todos (\u03bb x, 2 * x) ns)\n           : by rw aplica_a_todos_cons\n     ... = 2 * n + suma (aplica_a_todos (\u03bb x, 2 * x) ns)\n           : by rw suma_cons\n     ... = 2 * n + 2 * suma ns\n           : by rw HI\n     ... = 2 * (n + suma ns)\n           : by rw mul_add\n     ... = 2 * suma (n :: ns)\n           : by rw suma_cons, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  suma (aplica_a_todos (\u03bb x, 2*x) ns) = 2 * (suma ns) :=\nby induction ns ; simp [*, mul_add]\n\n-- ----------------------------------------------------\n-- Ejercicio 25. (p. 48) Demostrar que\n--    longitud (aplica_a_todos f xs) = longitud xs\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (f : \u03b1 \u2192 \u03b2)\n  : longitud (aplica_a_todos f xs) = longitud xs :=\nbegin\n  induction xs with x xs HI,\n  { rw aplica_a_todos_nil,\n    rw longitud_nil,\n    rw longitud_nil, },\n  { rw aplica_a_todos_cons,\n    rw longitud_cons,\n    rw HI,\n    rw longitud_cons, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (f : \u03b1 \u2192 \u03b2)\n  : longitud (aplica_a_todos f xs) = longitud xs :=\nbegin\n  induction xs with x xs HI,\n  { calc longitud (aplica_a_todos f [])\n         = longitud []\n           : by rw aplica_a_todos_nil\n     ... = 0\n           : by rw longitud_nil\n     ... = longitud []\n           : by rw longitud_nil, },\n  { calc longitud (aplica_a_todos f (x :: xs))\n         = longitud (f x :: aplica_a_todos f xs)\n           : by rw aplica_a_todos_cons\n     ... = longitud (aplica_a_todos f xs) + 1\n           : by rw longitud_cons\n     ... = longitud xs + 1\n           : by rw HI\n     ... = longitud (x :: xs)\n           : by rw longitud_cons, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (f : \u03b1 \u2192 \u03b2)\n  : longitud (aplica_a_todos f xs) = longitud xs :=\nby induction xs ; simp [*]\n\n-- \u00a7 Referencias\n-- =============\n\n-- + J.A. Alonso. \"Razonamiento sobre programas\" http://goo.gl/R06O3\n-- + G. Hutton. \"Programming in Haskell\". Cap. 13 \"Reasoning about\n--   programms\".\n-- + S. Thompson. \"Haskell: the Craft of Functional Programming, 3rd\n--   Edition. Cap. 8 \"Reasoning about programms\".\n-- + L. Paulson. \"ML for the Working Programmer, 2nd Edition\". Cap. 6.\n--   \"Reasoning about functional programs\".\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/7_Programas/Razonamiento_sobre_programas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.7335766618773912}}
{"text": "/-\nCopyright (c) 2022 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n\n! This file was ported from Lean 3 source module data.fin.succ_pred\n! leanprover-community/mathlib commit 7c523cb78f4153682c2929e3006c863bfef463d0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fin.Basic\nimport Mathlib.Order.SuccPred.Basic\n\n/-!\n# Successors and predecessors of `Fin n`\n\nIn this file, we show that `Fin n` is both a `SuccOrder` and a `PredOrder`. Note that they are\nalso archimedean, but this is derived from the general instance for well-orderings as opposed\nto a specific `Fin` instance.\n\n-/\n\n\nnamespace Fin\n\ninstance : \u2200 {n : \u2115}, SuccOrder (Fin n)\n  | 0 => by constructor <;> first | assumption | intro a; exact elim0 a\n  | n + 1 =>\n    SuccOrder.ofCore (fun i => if i < Fin.last n then i + 1 else i)\n      (by\n        intro a ha b\n        rw [isMax_iff_eq_top, eq_top_iff, not_le, top_eq_last] at ha\n        dsimp\n        rw [if_pos ha, lt_iff_val_lt_val, le_iff_val_le_val, val_add_one_of_lt ha]\n        exact Nat.lt_iff_add_one_le)\n      (by\n        intro a ha\n        rw [isMax_iff_eq_top, top_eq_last] at ha\n        dsimp\n        rw [if_neg ha.not_lt])\n\n@[simp]\ntheorem succ_eq {n : \u2115} : SuccOrder.succ = fun a => if a < Fin.last n then a + 1 else a :=\n  rfl\n#align fin.succ_eq Fin.succ_eq\n\n@[simp]\ntheorem succ_apply {n : \u2115} (a) : SuccOrder.succ a = if a < Fin.last n then a + 1 else a :=\n  rfl\n#align fin.succ_apply Fin.succ_apply\n\ninstance : \u2200 {n : \u2115}, PredOrder (Fin n)\n  | 0 => by constructor <;> first | assumption | intro a; exact elim0 a\n  | n + 1 =>\n    PredOrder.ofCore (fun x => if x = 0 then 0 else x - 1)\n      (by\n        intro a ha b\n        rw [isMin_iff_eq_bot, eq_bot_iff, not_le, bot_eq_zero] at ha\n        dsimp\n        rw [if_neg ha.ne', lt_iff_val_lt_val, le_iff_val_le_val, coe_sub_one, if_neg ha.ne',\n          le_tsub_iff_right, Iff.comm]\n        exact Nat.lt_iff_add_one_le\n        exact ha)\n      (by\n        intro a ha\n        rw [isMin_iff_eq_bot, bot_eq_zero] at ha\n        dsimp\n        rwa [if_pos ha, eq_comm])\n\n@[simp]\ntheorem pred_eq {n} : PredOrder.pred = fun a : Fin (n + 1) => if a = 0 then 0 else a - 1 :=\n  rfl\n#align fin.pred_eq Fin.pred_eq\n\n@[simp]\ntheorem pred_apply {n : \u2115} (a : Fin (n + 1)) : PredOrder.pred a = if a = 0 then 0 else a - 1 :=\n  rfl\n#align fin.pred_apply Fin.pred_apply\n\nend Fin\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Fin/SuccPred.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7335766597913452}}
{"text": "namespace hidden\n\ndef divides (m n : \u2115) : Prop := \u2203 k, m * k = n\n\ninstance : has_dvd nat := \u27e8divides\u27e9\n\ndef even (n : \u2115) : Prop := 2 \u2223 n\n\n-- BEGIN\ndef prime (n : \u2115) : Prop :=\n\u00ac\u2203 m, m > 1 \u2227 m < n \u2227 (m \u2223 n)\n\ndef infinitely_many_primes : Prop :=\n\u2200 n, \u2203 p, p > n \u2227 prime p\n\ndef Fermat_number (n : \u2115) : Prop :=\n\u2203 k : \u2115, 2^(2^k) + 1 = n\n\ndef Fermat_prime (n : \u2115) : Prop :=\nprime n \u2227 Fermat_number n\n\ndef infinitely_many_Fermat_primes : Prop :=\n\u2200 n, \u2203 fp, fp > n \u2227 Fermat_prime fp\n\n-- Every even integer greater than 2 can be expressed as the sum of two primes\ndef goldbach_conjecture : Prop :=\n\u2200 n, n > 2 \u2192 \u2203 p q, p + q = n \u2227 prime p \u2227 prime q\n\n-- Every odd number greater than 5 can be expressed as the sum of three primes\ndef Goldbach's_weak_conjecture : Prop :=\n\u2200 n, even n \u2227 n > 5 \u2192 \u2203 p p' p'', p + p' + p'' = n \u2227 prime p \u2227 prime p' \u2227 prime p''\n\n-- no three positive integers a, b, and c satisfy the equation an + bn = cn for\n-- any integer value of n greater than 2\ndef Fermat's_last_theorem : Prop :=\n\u2200 n, n > 2 \u2192 \u00ac\u2203 a b c, a^n + b^n = c^n \u2227 a > 0 \u2227 b > 0 \u2227 c > 0\n\n-- END\n\nend hidden\n", "meta": {"author": "hyponymous", "repo": "theorem-proving-in-lean-solutions", "sha": "a95320ae81c90c1b15da04574602cd378794400d", "save_path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions", "path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions/theorem-proving-in-lean-solutions-a95320ae81c90c1b15da04574602cd378794400d/4.6.4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7335345717138628}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen\n\n! This file was ported from Lean 3 source module ring_theory.localization.basic\n! leanprover-community/mathlib commit b69c9a770ecf37eb21f7b8cf4fa00de3b62694ec\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Algebra.Tower\nimport Mathlib.Algebra.Ring.Equiv\nimport Mathlib.GroupTheory.MonoidLocalization\nimport Mathlib.RingTheory.Ideal.Basic\nimport Mathlib.RingTheory.NonZeroDivisors\nimport Mathlib.Tactic.Ring\n\n/-!\n# Localizations of commutative rings\n\nWe characterize the localization of a commutative ring `R` at a submonoid `M` up to\nisomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a\nring homomorphism `f : R \u2192+* S` satisfying 3 properties:\n1. For all `y \u2208 M`, `f y` is a unit;\n2. For all `z : S`, there exists `(x, y) : R \u00d7 M` such that `z * f y = f x`;\n3. For all `x, y : R`, `f x = f y` iff there exists `c \u2208 M` such that `x * c = y * c`.\n\nIn the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras\nand `M, T` be submonoids of `R` and `P` respectively, e.g.:\n```\nvariables (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q]\nvariables [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P)\n```\n\n## Main definitions\n\n * `IsLocalization (M : Submonoid R) (S : Type*)` is a typeclass expressing that `S` is a\n   localization of `R` at `M`, i.e. the canonical map `algebraMap R S : R \u2192+* S` is a\n   localization map (satisfying the above properties).\n * `IsLocalization.mk' S` is a surjection sending `(x, y) : R \u00d7 M` to `f x * (f y)\u207b\u00b9`\n * `IsLocalization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R`\n   which maps elements of `M` to invertible elements of the codomain.\n * `IsLocalization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements\n   of `M` to elements of `T`\n * `IsLocalization.ringEquivOfRingEquiv`: if `R` and `P` are isomorphic by an isomorphism\n   sending `M` to `T`, then `S` and `Q` are isomorphic\n * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q`\n   are isomorphic as `R`-algebras\n\n## Main results\n\n * `Localization M S`, a construction of the localization as a quotient type, defined in\n   `GroupTheory.MonoidLocalization`, has `CommRing`, `Algebra R` and `IsLocalization M`\n   instances if `R` is a ring. `Localization.Away`, `Localization.AtPrime` and `FractionRing`\n   are abbreviations for `Localization`s and have their corresponding `IsLocalization` instances\n\n## Implementation notes\n\nIn maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one\nstructure with an isomorphic one; one way around this is to isolate a predicate characterizing\na structure up to isomorphism, and reason about things that satisfy the predicate.\n\nA previous version of this file used a fully bundled type of ring localization maps,\nthen used a type synonym `f.codomain` for `f : :ocalizationMap M S` to instantiate the\n`R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already\ndefined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`,\nwe can ensure the localization map commutes nicely with other `algebraMap`s.\n\nTo prove most lemmas about a localization map `algebraMap R S` in this file we invoke the\ncorresponding proof for the underlying `CommMonoid` localization map\n`IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization`\nand the namespace `Submonoid.LocalizationMap`.\n\nTo reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas.\nThese show the quotient map `mk : R \u2192 M \u2192 Localization M` equals the surjection\n`LocalizationMap.mk'` induced by the map `algebraMap : R \u2192+* Localization M`.\nThe lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file,\nwhich are about the `LocalizationMap.mk'` induced by any localization map.\n\nThe proof that \"a `CommRing` `K` which is the localization of an integral domain `R` at `R \\ {0}`\nis a field\" is a `def` rather than an `instance`, so if you want to reason about a field of\nfractions `K`, assume `[Field K]` instead of just `[CommRing K]`.\n\n## Tags\nlocalization, ring localization, commutative ring localization, characteristic predicate,\ncommutative ring, field of fractions\n-/\n\n\nopen Function\n\nopen BigOperators\n\nsection CommSemiring\n\nvariable {R : Type _} [CommSemiring R] (M : Submonoid R) (S : Type _) [CommSemiring S]\n\nvariable [Algebra R S] {P : Type _} [CommSemiring P]\n\n/-- The typeclass `IsLocalization (M : Submodule R) S` where `S` is an `R`-algebra\nexpresses that `S` is isomorphic to the localization of `R` at `M`. -/\nclass IsLocalization : Prop where\n--Porting note: add ' to fields, and made new versions of these with either `S` or `M` explicit.\n  /-- Everything in the image of `algebraMap` is a unit -/\n  map_units' : \u2200 y : M, IsUnit (algebraMap R S y)\n  /-- the `algebraMap` is surjective -/\n  surj' : \u2200 z : S, \u2203 x : R \u00d7 M, z * algebraMap R S x.2 = algebraMap R S x.1\n  /-- The kernel of `algebraMap` is the annihilator of `M` -/\n  eq_iff_exists' : \u2200 {x y}, algebraMap R S x = algebraMap R S y \u2194 \u2203 c : M, \u2191c * x = \u2191c * y\n#align is_localization IsLocalization\n\nvariable {M}\n\nnamespace IsLocalization\n\nsection IsLocalization\n\nvariable [IsLocalization M S]\n\nsection\n\n@[inherit_doc IsLocalization.map_units']\ntheorem map_units : \u2200 y : M, IsUnit (algebraMap R S y) :=\n  IsLocalization.map_units'\n\nvariable (M) {S}\n@[inherit_doc IsLocalization.surj']\ntheorem surj : \u2200 z : S, \u2203 x : R \u00d7 M, z * algebraMap R S x.2 = algebraMap R S x.1 :=\n  IsLocalization.surj'\n\nvariable (S)\n@[inherit_doc IsLocalization.eq_iff_exists']\ntheorem eq_iff_exists {x y} : algebraMap R S x = algebraMap R S y \u2194 \u2203 c : M, \u2191c * x = \u2191c * y :=\n  IsLocalization.eq_iff_exists'\n\nvariable {S}\ntheorem of_le (N : Submonoid R) (h\u2081 : M \u2264 N) (h\u2082 : \u2200 r \u2208 N, IsUnit (algebraMap R S r)) :\n    IsLocalization N S :=\n  { map_units' := fun r => h\u2082 r r.2\n    surj' := fun s => by\n      obtain \u27e8\u27e8x, y, hy\u27e9, H\u27e9 := IsLocalization.surj M s\n      exact \u27e8\u27e8x, y, h\u2081 hy\u27e9, H\u27e9\n    eq_iff_exists' := @fun x y => by\n      constructor\n      \u00b7 rw [IsLocalization.eq_iff_exists M]\n        rintro \u27e8c, hc\u27e9\n        exact \u27e8\u27e8c, h\u2081 c.2\u27e9, hc\u27e9\n      \u00b7 rintro \u27e8c, h\u27e9\n        simpa only [map_mul, (h\u2082 c c.2).mul_right_inj] using\n          congr_arg (algebraMap R S) h }\n#align is_localization.of_le IsLocalization.of_le\n\nvariable (S)\n\n/-- `IsLocalization.toLocalizationWithZeroMap M S` shows `S` is the monoid localization of\n`R` at `M`. -/\n@[simps]\ndef toLocalizationWithZeroMap : Submonoid.LocalizationWithZeroMap M S :=\n  { algebraMap R S with\n    toFun := algebraMap R S\n    map_units' := IsLocalization.map_units _\n    surj' := IsLocalization.surj _\n    eq_iff_exists' := fun _ _ => IsLocalization.eq_iff_exists _ _ }\n#align is_localization.to_localization_with_zero_map IsLocalization.toLocalizationWithZeroMap\n\n/-- `IsLocalization.toLocalizationMap M S` shows `S` is the monoid localization of `R` at `M`. -/\nabbrev toLocalizationMap : Submonoid.LocalizationMap M S :=\n  (toLocalizationWithZeroMap M S).toLocalizationMap\n#align is_localization.to_localization_map IsLocalization.toLocalizationMap\n\n@[simp]\ntheorem toLocalizationMap_toMap : (toLocalizationMap M S).toMap = (algebraMap R S : R \u2192*\u2080 S) :=\n  rfl\n#align is_localization.to_localization_map_to_map IsLocalization.toLocalizationMap_toMap\n\ntheorem toLocalizationMap_toMap_apply (x) : (toLocalizationMap M S).toMap x = algebraMap R S x :=\n  rfl\n#align is_localization.to_localization_map_to_map_apply IsLocalization.toLocalizationMap_toMap_apply\n\nend\n\nvariable (M) {S}\n\n/-- Given a localization map `f : M \u2192* N`, a section function sending `z : N` to some\n`(x, y) : M \u00d7 S` such that `f x * (f y)\u207b\u00b9 = z`. -/\nnoncomputable def sec (z : S) : R \u00d7 M :=\n  Classical.choose <| IsLocalization.surj _ z\n#align is_localization.sec IsLocalization.sec\n\n@[simp]\ntheorem toLocalizationMap_sec : (toLocalizationMap M S).sec = sec M :=\n  rfl\n#align is_localization.to_localization_map_sec IsLocalization.toLocalizationMap_sec\n\n/-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R \u00d7 M` such\nthat `z * f y = f x` (so this lemma is true by definition). -/\ntheorem sec_spec (z : S) :\n    z * algebraMap R S (IsLocalization.sec M z).2 = algebraMap R S (IsLocalization.sec M z).1 :=\n  Classical.choose_spec <| IsLocalization.surj _ z\n#align is_localization.sec_spec IsLocalization.sec_spec\n\n/-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R \u00d7 M` such\nthat `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/\ntheorem sec_spec' (z : S) :\n    algebraMap R S (IsLocalization.sec M z).1 = algebraMap R S (IsLocalization.sec M z).2 * z := by\n  rw [mul_comm, sec_spec]\n#align is_localization.sec_spec' IsLocalization.sec_spec'\n\nvariable {M}\n\ntheorem map_right_cancel {x y} {c : M} (h : algebraMap R S (c * x) = algebraMap R S (c * y)) :\n    algebraMap R S x = algebraMap R S y :=\n  (toLocalizationMap M S).map_right_cancel h\n#align is_localization.map_right_cancel IsLocalization.map_right_cancel\n\ntheorem map_left_cancel {x y} {c : M} (h : algebraMap R S (x * c) = algebraMap R S (y * c)) :\n    algebraMap R S x = algebraMap R S y :=\n  (toLocalizationMap M S).map_left_cancel h\n#align is_localization.map_left_cancel IsLocalization.map_left_cancel\n\ntheorem eq_zero_of_fst_eq_zero {z x} {y : M} (h : z * algebraMap R S y = algebraMap R S x)\n    (hx : x = 0) : z = 0 := by\n  rw [hx, (algebraMap R S).map_zero] at h\n  exact (IsUnit.mul_left_eq_zero (IsLocalization.map_units S y)).1 h\n#align is_localization.eq_zero_of_fst_eq_zero IsLocalization.eq_zero_of_fst_eq_zero\n\nvariable (M S)\n\ntheorem map_eq_zero_iff (r : R) : algebraMap R S r = 0 \u2194 \u2203 m : M, \u2191m * r = 0 := by\n  constructor\n  intro h\n  \u00b7 obtain \u27e8m, hm\u27e9 := (IsLocalization.eq_iff_exists M S).mp ((algebraMap R S).map_zero.trans h.symm)\n    exact \u27e8m, by simpa using hm.symm\u27e9\n  \u00b7 rintro \u27e8m, hm\u27e9\n    rw [\u2190 (IsLocalization.map_units S m).mul_right_inj, mul_zero, \u2190 RingHom.map_mul, hm,\n      RingHom.map_zero]\n#align is_localization.map_eq_zero_iff IsLocalization.map_eq_zero_iff\n\nvariable {M}\n\n/-- `IsLocalization.mk' S` is the surjection sending `(x, y) : R \u00d7 M` to\n`f x * (f y)\u207b\u00b9`. -/\nnoncomputable def mk' (x : R) (y : M) : S :=\n  (toLocalizationMap M S).mk' x y\n#align is_localization.mk' IsLocalization.mk'\n\n@[simp]\ntheorem mk'_sec (z : S) : mk' S (IsLocalization.sec M z).1 (IsLocalization.sec M z).2 = z :=\n  (toLocalizationMap M S).mk'_sec _\n#align is_localization.mk'_sec IsLocalization.mk'_sec\n\ntheorem mk'_mul (x\u2081 x\u2082 : R) (y\u2081 y\u2082 : M) : mk' S (x\u2081 * x\u2082) (y\u2081 * y\u2082) = mk' S x\u2081 y\u2081 * mk' S x\u2082 y\u2082 :=\n  (toLocalizationMap M S).mk'_mul _ _ _ _\n#align is_localization.mk'_mul IsLocalization.mk'_mul\n\ntheorem mk'_one (x) : mk' S x (1 : M) = algebraMap R S x :=\n  (toLocalizationMap M S).mk'_one _\n#align is_localization.mk'_one IsLocalization.mk'_one\n\n@[simp]\ntheorem mk'_spec (x) (y : M) : mk' S x y * algebraMap R S y = algebraMap R S x :=\n  (toLocalizationMap M S).mk'_spec _ _\n#align is_localization.mk'_spec IsLocalization.mk'_spec\n\n@[simp]\ntheorem mk'_spec' (x) (y : M) : algebraMap R S y * mk' S x y = algebraMap R S x :=\n  (toLocalizationMap M S).mk'_spec' _ _\n#align is_localization.mk'_spec' IsLocalization.mk'_spec'\n\n@[simp]\ntheorem mk'_spec_mk (x) (y : R) (hy : y \u2208 M) :\n    mk' S x \u27e8y, hy\u27e9 * algebraMap R S y = algebraMap R S x :=\n  mk'_spec S x \u27e8y, hy\u27e9\n#align is_localization.mk'_spec_mk IsLocalization.mk'_spec_mk\n\n@[simp]\ntheorem mk'_spec'_mk (x) (y : R) (hy : y \u2208 M) :\n    algebraMap R S y * mk' S x \u27e8y, hy\u27e9 = algebraMap R S x :=\n  mk'_spec' S x \u27e8y, hy\u27e9\n#align is_localization.mk'_spec'_mk IsLocalization.mk'_spec'_mk\n\nvariable {S}\n\ntheorem eq_mk'_iff_mul_eq {x} {y : M} {z} :\n    z = mk' S x y \u2194 z * algebraMap R S y = algebraMap R S x :=\n  (toLocalizationMap M S).eq_mk'_iff_mul_eq\n#align is_localization.eq_mk'_iff_mul_eq IsLocalization.eq_mk'_iff_mul_eq\n\ntheorem mk'_eq_iff_eq_mul {x} {y : M} {z} :\n    mk' S x y = z \u2194 algebraMap R S x = z * algebraMap R S y :=\n  (toLocalizationMap M S).mk'_eq_iff_eq_mul\n#align is_localization.mk'_eq_iff_eq_mul IsLocalization.mk'_eq_iff_eq_mul\n\ntheorem mk'_add_eq_iff_add_mul_eq_mul {x} {y : M} {z\u2081 z\u2082} :\n    mk' S x y + z\u2081 = z\u2082 \u2194 algebraMap R S x + z\u2081 * algebraMap R S y = z\u2082 * algebraMap R S y := by\n  rw [\u2190 mk'_spec S x y, \u2190 IsUnit.mul_left_inj (IsLocalization.map_units S y), right_distrib]\n#align is_localization.mk'_add_eq_iff_add_mul_eq_mul IsLocalization.mk'_add_eq_iff_add_mul_eq_mul\n\nvariable (M)\n\ntheorem mk'_surjective (z : S) : \u2203 (x : _)(y : M), mk' S x y = z :=\n  let \u27e8r, hr\u27e9 := IsLocalization.surj _ z\n  \u27e8r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symm\u27e9\n#align is_localization.mk'_surjective IsLocalization.mk'_surjective\n\nvariable (S)\n\n/-- The localization of a `Fintype` is a `Fintype`. Cannot be an instance. -/\nnoncomputable def fintype' [Fintype R] : Fintype S :=\n  have := Classical.propDecidable\n  Fintype.ofSurjective (Function.uncurry <| IsLocalization.mk' S) fun a =>\n    Prod.exists'.mpr <| IsLocalization.mk'_surjective M a\n#align is_localization.fintype' IsLocalization.fintype'\n\nvariable {M S}\n\n/-- Localizing at a submonoid with 0 inside it leads to the trivial ring. -/\ndef uniqueOfZeroMem (h : (0 : R) \u2208 M) : Unique S :=\n  uniqueOfZeroEqOne <| by simpa using IsLocalization.map_units S \u27e80, h\u27e9\n#align is_localization.unique_of_zero_mem IsLocalization.uniqueOfZeroMem\n\ntheorem mk'_eq_iff_eq {x\u2081 x\u2082} {y\u2081 y\u2082 : M} :\n    mk' S x\u2081 y\u2081 = mk' S x\u2082 y\u2082 \u2194 algebraMap R S (y\u2082 * x\u2081) = algebraMap R S (y\u2081 * x\u2082) :=\n  (toLocalizationMap M S).mk'_eq_iff_eq\n#align is_localization.mk'_eq_iff_eq IsLocalization.mk'_eq_iff_eq\n\ntheorem mk'_eq_iff_eq' {x\u2081 x\u2082} {y\u2081 y\u2082 : M} :\n    mk' S x\u2081 y\u2081 = mk' S x\u2082 y\u2082 \u2194 algebraMap R S (x\u2081 * y\u2082) = algebraMap R S (x\u2082 * y\u2081) :=\n  (toLocalizationMap M S).mk'_eq_iff_eq'\n#align is_localization.mk'_eq_iff_eq' IsLocalization.mk'_eq_iff_eq'\n\ntheorem mk'_mem_iff {x} {y : M} {I : Ideal S} : mk' S x y \u2208 I \u2194 algebraMap R S x \u2208 I := by\n  constructor <;> intro h\n  \u00b7 rw [\u2190 mk'_spec S x y, mul_comm]\n    exact I.mul_mem_left ((algebraMap R S) y) h\n  \u00b7 rw [\u2190 mk'_spec S x y] at h\n    obtain \u27e8b, hb\u27e9 := isUnit_iff_exists_inv.1 (map_units S y)\n    have := I.mul_mem_left b h\n    rwa [mul_comm, mul_assoc, hb, mul_one] at this\n#align is_localization.mk'_mem_iff IsLocalization.mk'_mem_iff\n\nprotected theorem eq {a\u2081 b\u2081} {a\u2082 b\u2082 : M} :\n    mk' S a\u2081 a\u2082 = mk' S b\u2081 b\u2082 \u2194 \u2203 c : M, \u2191c * (\u2191b\u2082 * a\u2081) = c * (a\u2082 * b\u2081) :=\n  (toLocalizationMap M S).eq\n#align is_localization.eq IsLocalization.eq\n\ntheorem mk'_eq_zero_iff (x : R) (s : M) : mk' S x s = 0 \u2194 \u2203 m : M, \u2191m * x = 0 := by\n  rw [\u2190 (map_units S s).mul_left_inj, mk'_spec, zero_mul, map_eq_zero_iff M]\n#align is_localization.mk'_eq_zero_iff IsLocalization.mk'_eq_zero_iff\n\n@[simp]\ntheorem mk'_zero (s : M) : IsLocalization.mk' S 0 s = 0 := by\n  rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, zero_mul, map_zero]\n#align is_localization.mk'_zero IsLocalization.mk'_zero\n\ntheorem ne_zero_of_mk'_ne_zero {x : R} {y : M} (hxy : IsLocalization.mk' S x y \u2260 0) : x \u2260 0 := by\n  rintro rfl\n  exact hxy (IsLocalization.mk'_zero _)\n#align is_localization.ne_zero_of_mk'_ne_zero IsLocalization.ne_zero_of_mk'_ne_zero\n\nsection Ext\n\nvariable [Algebra R P] [IsLocalization M P]\n\ntheorem eq_iff_eq {x y} :\n    algebraMap R S x = algebraMap R S y \u2194 algebraMap R P x = algebraMap R P y :=\n  (toLocalizationMap M S).eq_iff_eq (toLocalizationMap M P)\n#align is_localization.eq_iff_eq IsLocalization.eq_iff_eq\n\ntheorem mk'_eq_iff_mk'_eq {x\u2081 x\u2082} {y\u2081 y\u2082 : M} :\n    mk' S x\u2081 y\u2081 = mk' S x\u2082 y\u2082 \u2194 mk' P x\u2081 y\u2081 = mk' P x\u2082 y\u2082 :=\n  (toLocalizationMap M S).mk'_eq_iff_mk'_eq (toLocalizationMap M P)\n#align is_localization.mk'_eq_iff_mk'_eq IsLocalization.mk'_eq_iff_mk'_eq\n\ntheorem mk'_eq_of_eq {a\u2081 b\u2081 : R} {a\u2082 b\u2082 : M} (H : \u2191a\u2082 * b\u2081 = \u2191b\u2082 * a\u2081) :\n    mk' S a\u2081 a\u2082 = mk' S b\u2081 b\u2082 :=\n  (toLocalizationMap M S).mk'_eq_of_eq H\n#align is_localization.mk'_eq_of_eq IsLocalization.mk'_eq_of_eq\n\n\n\nvariable (S)\n\n@[simp]\ntheorem mk'_self {x : R} (hx : x \u2208 M) : mk' S x \u27e8x, hx\u27e9 = 1 :=\n  (toLocalizationMap M S).mk'_self _ hx\n#align is_localization.mk'_self IsLocalization.mk'_self\n\n@[simp]\ntheorem mk'_self' {x : M} : mk' S (x : R) x = 1 :=\n  (toLocalizationMap M S).mk'_self' _\n#align is_localization.mk'_self' IsLocalization.mk'_self'\n\ntheorem mk'_self'' {x : M} : mk' S x.1 x = 1 :=\n  mk'_self' _\n#align is_localization.mk'_self'' IsLocalization.mk'_self''\n\nend Ext\n\ntheorem mul_mk'_eq_mk'_of_mul (x y : R) (z : M) :\n    (algebraMap R S) x * mk' S y z = mk' S (x * y) z :=\n  (toLocalizationMap M S).mul_mk'_eq_mk'_of_mul _ _ _\n#align is_localization.mul_mk'_eq_mk'_of_mul IsLocalization.mul_mk'_eq_mk'_of_mul\n\ntheorem mk'_eq_mul_mk'_one (x : R) (y : M) : mk' S x y = (algebraMap R S) x * mk' S 1 y :=\n  ((toLocalizationMap M S).mul_mk'_one_eq_mk' _ _).symm\n#align is_localization.mk'_eq_mul_mk'_one IsLocalization.mk'_eq_mul_mk'_one\n\n@[simp]\ntheorem mk'_mul_cancel_left (x : R) (y : M) : mk' S (y * x : R) y = (algebraMap R S) x :=\n  (toLocalizationMap M S).mk'_mul_cancel_left _ _\n#align is_localization.mk'_mul_cancel_left IsLocalization.mk'_mul_cancel_left\n\ntheorem mk'_mul_cancel_right (x : R) (y : M) : mk' S (x * y) y = (algebraMap R S) x :=\n  (toLocalizationMap M S).mk'_mul_cancel_right _ _\n#align is_localization.mk'_mul_cancel_right IsLocalization.mk'_mul_cancel_right\n\n@[simp]\ntheorem mk'_mul_mk'_eq_one (x y : M) : mk' S (x : R) y * mk' S (y : R) x = 1 := by\n  rw [\u2190 mk'_mul, mul_comm]; exact mk'_self _ _\n#align is_localization.mk'_mul_mk'_eq_one IsLocalization.mk'_mul_mk'_eq_one\n\ntheorem mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x \u2208 M) : mk' S x y * mk' S (y : R) \u27e8x, h\u27e9 = 1 :=\n  mk'_mul_mk'_eq_one \u27e8x, h\u27e9 _\n#align is_localization.mk'_mul_mk'_eq_one' IsLocalization.mk'_mul_mk'_eq_one'\n\nsection\n\nvariable (M)\n\ntheorem isUnit_comp (j : S \u2192+* P) (y : M) : IsUnit (j.comp (algebraMap R S) y) :=\n  (toLocalizationMap M S).isUnit_comp j.toMonoidHom _\n#align is_localization.is_unit_comp IsLocalization.isUnit_comp\n\nend\n\n/-- Given a localization map `f : R \u2192+* S` for a submonoid `M \u2286 R` and a map of `CommSemiring`s\n`g : R \u2192+* P` such that `g(M) \u2286 Units P`, `f x = f y \u2192 g x = g y` for all `x y : R`. -/\ntheorem eq_of_eq {g : R \u2192+* P} (hg : \u2200 y : M, IsUnit (g y)) {x y}\n    (h : (algebraMap R S) x = (algebraMap R S) y) : g x = g y :=\n  @Submonoid.LocalizationMap.eq_of_eq _ _ _ _ _ _ _ (toLocalizationMap M S) g.toMonoidHom hg _ _ h\n#align is_localization.eq_of_eq IsLocalization.eq_of_eq\n\ntheorem mk'_add (x\u2081 x\u2082 : R) (y\u2081 y\u2082 : M) :\n    mk' S (x\u2081 * y\u2082 + x\u2082 * y\u2081) (y\u2081 * y\u2082) = mk' S x\u2081 y\u2081 + mk' S x\u2082 y\u2082 :=\n  mk'_eq_iff_eq_mul.2 <|\n    Eq.symm\n      (by\n        rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul,\n          mul_comm (_ * _), \u2190 mul_assoc, add_comm, \u2190 map_mul, mul_mk'_eq_mk'_of_mul,\n          add_comm _ (mk' _ _ _), mk'_add_eq_iff_add_mul_eq_mul]\n        simp only [map_add, Submonoid.coe_mul, map_mul]\n        ring)\n#align is_localization.mk'_add IsLocalization.mk'_add\n\ntheorem mul_add_inv_left {g : R \u2192+* P} (h : \u2200 y : M, IsUnit (g y)) (y : M) (w z\u2081 z\u2082 : P) :\n    w * \u2191(IsUnit.liftRight (g.toMonoidHom.restrict M) h y)\u207b\u00b9 + z\u2081 = z\u2082 \u2194 w + g y * z\u2081 = g y * z\u2082 :=\n  by\n  rw [mul_comm, \u2190 one_mul z\u2081, \u2190 Units.inv_mul (IsUnit.liftRight (g.toMonoidHom.restrict M) h y),\n    mul_assoc, \u2190 mul_add, Units.inv_mul_eq_iff_eq_mul, Units.inv_mul_cancel_left,\n    IsUnit.coe_liftRight]\n  simp [RingHom.toMonoidHom_eq_coe, MonoidHom.restrict_apply]\n#align is_localization.mul_add_inv_left IsLocalization.mul_add_inv_left\n\ntheorem lift_spec_mul_add {g : R \u2192+* P} (hg : \u2200 y : M, IsUnit (g y)) (z w w' v) :\n    ((toLocalizationWithZeroMap M S).lift g.toMonoidWithZeroHom hg) z * w + w' = v \u2194\n      g ((toLocalizationMap M S).sec z).1 * w + g ((toLocalizationMap M S).sec z).2 * w' =\n        g ((toLocalizationMap M S).sec z).2 * v := by\n  erw [mul_comm, \u2190 mul_assoc, mul_add_inv_left hg, mul_comm]\n  rfl\n#align is_localization.lift_spec_mul_add IsLocalization.lift_spec_mul_add\n\n/-- Given a localization map `f : R \u2192+* S` for a submonoid `M \u2286 R` and a map of `CommSemiring`s\n`g : R \u2192+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from\n`S` to `P` sending `z : S` to `g x * (g y)\u207b\u00b9`, where `(x, y) : R \u00d7 M` are such that\n`z = f x * (f y)\u207b\u00b9`. -/\nnoncomputable def lift {g : R \u2192+* P} (hg : \u2200 y : M, IsUnit (g y)) : S \u2192+* P :=\n  {\n    @Submonoid.LocalizationWithZeroMap.lift _ _ _ _ _ _ _ (toLocalizationWithZeroMap M S)\n      g.toMonoidWithZeroHom hg with\n    map_add' := by\n      intro x y\n      erw [(toLocalizationMap M S).lift_spec, mul_add, mul_comm, eq_comm, lift_spec_mul_add,\n        add_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, lift_spec_mul_add]\n      simp_rw [\u2190 mul_assoc]\n      show g _ * g _ * g _ + g _ * g _ * g _ = g _ * g _ * g _\n      simp_rw [\u2190 map_mul g, \u2190 map_add g]\n      apply @eq_of_eq _ _ _ S _ _ _ _ _ g hg\n      simp only [sec_spec', toLocalizationMap_sec, map_add, map_mul]\n      ring }\n#align is_localization.lift IsLocalization.lift\n\nvariable {g : R \u2192+* P} (hg : \u2200 y : M, IsUnit (g y))\n\n/-- Given a localization map `f : R \u2192+* S` for a submonoid `M \u2286 R` and a map of `CommSemiring`s\n`g : R \u2192* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from\n`S` to `P` maps `f x * (f y)\u207b\u00b9` to `g x * (g y)\u207b\u00b9` for all `x : R, y \u2208 M`. -/\ntheorem lift_mk' (x y) :\n    lift hg (mk' S x y) = g x * \u2191(IsUnit.liftRight (g.toMonoidHom.restrict M) hg y)\u207b\u00b9 :=\n  (toLocalizationMap M S).lift_mk' _ _ _\n#align is_localization.lift_mk' IsLocalization.lift_mk'\n\ntheorem lift_mk'_spec (x v) (y : M) : lift hg (mk' S x y) = v \u2194 g x = g y * v :=\n  (toLocalizationMap M S).lift_mk'_spec _ _ _ _\n#align is_localization.lift_mk'_spec IsLocalization.lift_mk'_spec\n\n@[simp]\ntheorem lift_eq (x : R) : lift hg ((algebraMap R S) x) = g x :=\n  (toLocalizationMap M S).lift_eq _ _\n#align is_localization.lift_eq IsLocalization.lift_eq\n\ntheorem lift_eq_iff {x y : R \u00d7 M} :\n    lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) \u2194 g (x.1 * y.2) = g (y.1 * x.2) :=\n  (toLocalizationMap M S).lift_eq_iff _\n#align is_localization.lift_eq_iff IsLocalization.lift_eq_iff\n\n@[simp]\ntheorem lift_comp : (lift hg).comp (algebraMap R S) = g :=\n  RingHom.ext <| (FunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_comp _\n#align is_localization.lift_comp IsLocalization.lift_comp\n\n@[simp]\ntheorem lift_of_comp (j : S \u2192+* P) : lift (isUnit_comp M j) = j :=\n  RingHom.ext <| (FunLike.ext_iff (F := MonoidHom _ _)).1 <|\n    (toLocalizationMap M S).lift_of_comp j.toMonoidHom\n#align is_localization.lift_of_comp IsLocalization.lift_of_comp\n\nvariable (M)\n\n/-- See note [partially-applied ext lemmas] -/\ntheorem monoidHom_ext \u2983j k : S \u2192* P\u2984\n    (h : j.comp (algebraMap R S : R \u2192* S) = k.comp (algebraMap R S)) : j = k :=\n  Submonoid.LocalizationMap.epic_of_localizationMap (toLocalizationMap M S) <| FunLike.congr_fun h\n#align is_localization.monoid_hom_ext IsLocalization.monoidHom_ext\n\n/-- See note [partially-applied ext lemmas] -/\ntheorem ringHom_ext \u2983j k : S \u2192+* P\u2984 (h : j.comp (algebraMap R S) = k.comp (algebraMap R S)) :\n    j = k :=\n  RingHom.coe_monoidHom_injective <| monoidHom_ext M <| MonoidHom.ext <| RingHom.congr_fun h\n#align is_localization.ring_hom_ext IsLocalization.ringHom_ext\n\n/- This is not an instance because the submonoid `M` would become a metavariable\n  in typeclass search. -/\ntheorem algHom_subsingleton [Algebra R P] : Subsingleton (S \u2192\u2090[R] P) :=\n  \u27e8fun f g =>\n    AlgHom.coe_ringHom_injective <|\n      IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]\u27e9\n#align is_localization.alg_hom_subsingleton IsLocalization.algHom_subsingleton\n\n/-- To show `j` and `k` agree on the whole localization, it suffices to show they agree\non the image of the base ring, if they preserve `1` and `*`. -/\nprotected theorem ext (j k : S \u2192 P) (hj1 : j 1 = 1) (hk1 : k 1 = 1)\n    (hjm : \u2200 a b, j (a * b) = j a * j b) (hkm : \u2200 a b, k (a * b) = k a * k b)\n    (h : \u2200 a, j (algebraMap R S a) = k (algebraMap R S a)) : j = k :=\n  let j' : MonoidHom S P :=\n    { toFun := j, map_one' := hj1, map_mul' := hjm }\n  let k' : MonoidHom S P :=\n    { toFun := k, map_one' := hk1, map_mul' := hkm }\n  have : j' = k' := monoidHom_ext M (MonoidHom.ext h)\n  show j'.toFun = k'.toFun by rw [this]\n#align is_localization.ext IsLocalization.ext\n\nvariable {M}\n\ntheorem lift_unique {j : S \u2192+* P} (hj : \u2200 x, j ((algebraMap R S) x) = g x) : lift hg = j :=\n  RingHom.ext <|\n    (FunLike.ext_iff (F := MonoidHom _ _)).1 <|\n      @Submonoid.LocalizationMap.lift_unique _ _ _ _ _ _ _ (toLocalizationMap M S) g.toMonoidHom hg\n        j.toMonoidHom hj\n#align is_localization.lift_unique IsLocalization.lift_unique\n\n@[simp]\ntheorem lift_id (x) : lift (map_units S : \u2200 _ : M, IsUnit _) x = x :=\n  (toLocalizationMap M S).lift_id _\n#align is_localization.lift_id IsLocalization.lift_id\n\ntheorem lift_surjective_iff :\n    Surjective (lift hg : S \u2192 P) \u2194 \u2200 v : P, \u2203 x : R \u00d7 M, v * g x.2 = g x.1 :=\n  (toLocalizationMap M S).lift_surjective_iff hg\n#align is_localization.lift_surjective_iff IsLocalization.lift_surjective_iff\n\ntheorem lift_injective_iff :\n    Injective (lift hg : S \u2192 P) \u2194 \u2200 x y, algebraMap R S x = algebraMap R S y \u2194 g x = g y :=\n  (toLocalizationMap M S).lift_injective_iff hg\n#align is_localization.lift_injective_iff IsLocalization.lift_injective_iff\n\nsection Map\n\nvariable {T : Submonoid P} {Q : Type _} [CommSemiring Q] (hy : M \u2264 T.comap g)\n\nvariable [Algebra P Q] [IsLocalization T Q]\n\nsection\n\nvariable (Q)\n\n/-- Map a homomorphism `g : R \u2192+* P` to `S \u2192+* Q`, where `S` and `Q` are\nlocalizations of `R` and `P` at `M` and `T` respectively,\nsuch that `g(M) \u2286 T`.\n\nWe send `z : S` to `algebraMap P Q (g x) * (algebraMap P Q (g y))\u207b\u00b9`, where\n`(x, y) : R \u00d7 M` are such that `z = f x * (f y)\u207b\u00b9`. -/\nnoncomputable def map (g : R \u2192+* P) (hy : M \u2264 T.comap g) : S \u2192+* Q :=\n  @lift R _ M _ _ _ _ _ _ ((algebraMap P Q).comp g) fun y => map_units _ \u27e8g y, hy y.2\u27e9\n#align is_localization.map IsLocalization.map\n\nend\n\n--Porting note: added `simp` attribute, since it proves very similar lemmas marked `simp`\n@[simp]\ntheorem map_eq (x) : map Q g hy ((algebraMap R S) x) = algebraMap P Q (g x) :=\n  lift_eq (fun y => map_units _ \u27e8g y, hy y.2\u27e9) x\n#align is_localization.map_eq IsLocalization.map_eq\n\n@[simp]\ntheorem map_comp : (map Q g hy).comp (algebraMap R S) = (algebraMap P Q).comp g :=\n  lift_comp fun y => map_units _ \u27e8g y, hy y.2\u27e9\n#align is_localization.map_comp IsLocalization.map_comp\n\ntheorem map_mk' (x) (y : M) : map Q g hy (mk' S x y) = mk' Q (g x) \u27e8g y, hy y.2\u27e9 :=\n  @Submonoid.LocalizationMap.map_mk' _ _ _ _ _ _ _ (toLocalizationMap M S) g.toMonoidHom _\n    (fun y => hy y.2) _ _ (toLocalizationMap T Q) _ _\n#align is_localization.map_mk' IsLocalization.map_mk'\n\n--Porting note: new theorem\n@[simp]\ntheorem map_id_mk' {Q : Type _} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] (x) (y : M) :\n    map Q (RingHom.id R) (le_refl M) (mk' S x y) = mk' Q x y :=\n  map_mk' _ _ _\n\n@[simp]\ntheorem map_id (z : S) (h : M \u2264 M.comap (RingHom.id R) := le_refl M) :\n    map S (RingHom.id _) h z = z :=\n  lift_id _\n#align is_localization.map_id IsLocalization.map_id\n\ntheorem map_unique (j : S \u2192+* Q) (hj : \u2200 x : R, j (algebraMap R S x) = algebraMap P Q (g x)) :\n    map Q g hy = j :=\n  lift_unique (fun y => map_units _ \u27e8g y, hy y.2\u27e9) hj\n#align is_localization.map_unique IsLocalization.map_unique\n\n/-- If `CommSemiring` homs `g : R \u2192+* P, l : P \u2192+* A` induce maps of localizations, the composition\nof the induced maps equals the map of localizations induced by `l \u2218 g`. -/\ntheorem map_comp_map {A : Type _} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W]\n    [Algebra A W] [IsLocalization U W] {l : P \u2192+* A} (hl : T \u2264 U.comap l) :\n    (map W l hl).comp (map Q g hy : S \u2192+* _) = map W (l.comp g) fun _ hx => hl (hy hx) :=\n  RingHom.ext fun x =>\n    @Submonoid.LocalizationMap.map_map _ _ _ _ _ P _ (toLocalizationMap M S) g _ _ _ _ _ _ _ _ _ _\n      (toLocalizationMap U W) l _ x\n#align is_localization.map_comp_map IsLocalization.map_comp_map\n\n/-- If `CommSemiring` homs `g : R \u2192+* P, l : P \u2192+* A` induce maps of localizations, the composition\nof the induced maps equals the map of localizations induced by `l \u2218 g`. -/\ntheorem map_map {A : Type _} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W]\n    [IsLocalization U W] {l : P \u2192+* A} (hl : T \u2264 U.comap l) (x : S) :\n    map W l hl (map Q g hy x) = map W (l.comp g) (fun x hx => hl (hy hx)) x := by\n  rw [\u2190 map_comp_map (Q := Q) hy hl]; rfl\n#align is_localization.map_map IsLocalization.map_map\n\ntheorem map_smul (x : S) (z : R) : map Q g hy (z \u2022 x : S) = g z \u2022 map Q g hy x := by\n  rw [Algebra.smul_def, Algebra.smul_def, RingHom.map_mul, map_eq]\n#align is_localization.map_smul IsLocalization.map_smul\n\nsection\n\nvariable (S Q)\n\n/-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M, T` respectively, an\nisomorphism `j : R \u2243+* P` such that `j(M) = T` induces an isomorphism of localizations\n`S \u2243+* Q`. -/\n@[simps]\nnoncomputable def ringEquivOfRingEquiv (h : R \u2243+* P) (H : M.map h.toMonoidHom = T) : S \u2243+* Q :=\n  have H' : T.map h.symm.toMonoidHom = M := by\n    rw [\u2190 M.map_id, \u2190 H, Submonoid.map_map]\n    congr\n    ext\n    apply h.symm_apply_apply\n  {\n    map Q (h : R \u2192+* P)\n      _ with\n    toFun := map Q (h : R \u2192+* P) (M.le_comap_of_map_le (le_of_eq H))\n    invFun := map S (h.symm : P \u2192+* R) (T.le_comap_of_map_le (le_of_eq H'))\n    left_inv := fun x => by\n      rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply]\n      simp\n    right_inv := fun x => by\n      rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply]\n      simp }\n#align is_localization.ring_equiv_of_ring_equiv IsLocalization.ringEquivOfRingEquiv\n\nend\n\ntheorem ringEquivOfRingEquiv_eq_map {j : R \u2243+* P} (H : M.map j.toMonoidHom = T) :\n    (ringEquivOfRingEquiv S Q j H : S \u2192+* Q) =\n      map Q (j : R \u2192+* P) (M.le_comap_of_map_le (le_of_eq H)) :=\n  rfl\n#align is_localization.ring_equiv_of_ring_equiv_eq_map IsLocalization.ringEquivOfRingEquiv_eq_map\n\n--Porting note: removed `simp`, `simp` can prove it\ntheorem ringEquivOfRingEquiv_eq {j : R \u2243+* P} (H : M.map j.toMonoidHom = T) (x) :\n    ringEquivOfRingEquiv S Q j H ((algebraMap R S) x) = algebraMap P Q (j x) :=\n  map_eq _ _\n#align is_localization.ring_equiv_of_ring_equiv_eq IsLocalization.ringEquivOfRingEquiv_eq\n\ntheorem ringEquivOfRingEquiv_mk' {j : R \u2243+* P} (H : M.map j.toMonoidHom = T) (x : R) (y : M) :\n    ringEquivOfRingEquiv S Q j H (mk' S x y) =\n      mk' Q (j x) \u27e8j y, show j y \u2208 T from H \u25b8 Set.mem_image_of_mem j y.2\u27e9 :=\n  map_mk' _ _ _\n#align is_localization.ring_equiv_of_ring_equiv_mk' IsLocalization.ringEquivOfRingEquiv_mk'\n\nend Map\n\nsection AlgEquiv\n\nvariable {Q : Type _} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q]\n\nsection\n\nvariable (M S Q)\n\n/-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively,\nthere is an isomorphism of localizations `S \u2243\u2090[R] Q`. -/\n@[simps!]\nnoncomputable def algEquiv : S \u2243\u2090[R] Q :=\n  { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with\n    commutes' := ringEquivOfRingEquiv_eq _ }\n#align is_localization.alg_equiv IsLocalization.algEquiv\n\nend\n\n--Porting note: removed `simp`, `simp` can prove it\ntheorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y :=\n  map_mk' _ _ _\n\n#align is_localization.alg_equiv_mk' IsLocalization.algEquiv_mk'\n\n--Porting note: removed `simp`, `simp` can prove it\ntheorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y :=\n  map_mk' _ _ _\n#align is_localization.alg_equiv_symm_mk' IsLocalization.algEquiv_symm_mk'\n\nend AlgEquiv\n\nend IsLocalization\n\nsection\n\nvariable (M) {S}\n\ntheorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S \u2243\u2090[R] P) :\n    IsLocalization M P := by\n  constructor\n  \u00b7 intro y\n    convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom\n    exact (h.commutes y).symm\n  \u00b7 intro y\n    obtain \u27e8\u27e8x, s\u27e9, e\u27e9 := IsLocalization.surj M (h.symm y)\n    apply_fun (show S \u2192 P from h) at e\n    simp only [h.map_mul, h.apply_symm_apply, h.commutes] at e\n    exact \u27e8\u27e8x, s\u27e9, e\u27e9\n  \u00b7 intro x y\n    rw [\u2190 h.symm.toEquiv.injective.eq_iff, \u2190 IsLocalization.eq_iff_exists M S, \u2190 h.symm.commutes, \u2190\n      h.symm.commutes]\n    rfl\n#align is_localization.is_localization_of_alg_equiv IsLocalization.isLocalization_of_algEquiv\n\ntheorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S \u2243\u2090[R] P) :\n    IsLocalization M S \u2194 IsLocalization M P :=\n  \u27e8fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm\u27e9\n#align is_localization.is_localization_iff_of_alg_equiv IsLocalization.isLocalization_iff_of_algEquiv\n\ntheorem isLocalization_iff_of_ringEquiv (h : S \u2243+* P) :\n    IsLocalization M S \u2194 @IsLocalization _ _ M P _ (h.toRingHom.comp <| algebraMap R S).toAlgebra :=\n  letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra\n  isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl }\n#align is_localization.is_localization_iff_of_ring_equiv IsLocalization.isLocalization_iff_of_ringEquiv\n\nvariable (S)\n\ntheorem isLocalization_of_base_ringEquiv [IsLocalization M S] (h : R \u2243+* P) :\n    @IsLocalization _ _ (M.map h.toMonoidHom) S _\n      ((algebraMap R S).comp h.symm.toRingHom).toAlgebra := by\n  letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra\n  constructor\n  \u00b7 rintro \u27e8_, \u27e8y, hy, rfl\u27e9\u27e9\n    convert IsLocalization.map_units S \u27e8y, hy\u27e9\n    dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply]\n    exact congr_arg _ (h.symm_apply_apply _)\n  \u00b7 intro y\n    obtain \u27e8\u27e8x, s\u27e9, e\u27e9 := IsLocalization.surj M y\n    refine' \u27e8\u27e8h x, _, _, s.prop, rfl\u27e9, _\u27e9\n    dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply] at e\u22a2\n    convert e <;> exact h.symm_apply_apply _\n  \u00b7 intro x y\n    rw [RingHom.algebraMap_toAlgebra, RingHom.comp_apply, RingHom.comp_apply,\n      IsLocalization.eq_iff_exists M S]\n    simp_rw [\u2190 h.toEquiv.apply_eq_iff_eq]\n    change (\u2203 c : M, h (c * h.symm x) = h (c * h.symm y)) \u2194 _\n    simp only [RingEquiv.apply_symm_apply, RingEquiv.map_mul]\n    exact\n      \u27e8fun \u27e8c, e\u27e9 => \u27e8\u27e8_, _, c.prop, rfl\u27e9, e\u27e9, fun \u27e8\u27e8_, c, h, e\u2081\u27e9, e\u2082\u27e9 => \u27e8\u27e8_, h\u27e9, e\u2081.symm \u25b8 e\u2082\u27e9\u27e9\n#align is_localization.is_localization_of_base_ring_equiv IsLocalization.isLocalization_of_base_ringEquiv\n\ntheorem isLocalization_iff_of_base_ringEquiv (h : R \u2243+* P) :\n    IsLocalization M S \u2194\n      @IsLocalization _ _ (M.map h.toMonoidHom) S _\n        ((algebraMap R S).comp h.symm.toRingHom).toAlgebra := by\n  letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra\n  refine' \u27e8fun _ => isLocalization_of_base_ringEquiv M S h, _\u27e9\n  intro H\n  convert isLocalization_of_base_ringEquiv (Submonoid.map (RingEquiv.toMonoidHom h) M) S h.symm\n  \u00b7 erw [Submonoid.map_equiv_eq_comap_symm, Submonoid.comap_map_eq_of_injective]\n    exact h.toEquiv.injective\n  rw [RingHom.algebraMap_toAlgebra, RingHom.comp_assoc]\n  simp only [RingHom.comp_id, RingEquiv.symm_symm, RingEquiv.symm_toRingHom_comp_toRingHom]\n  apply Algebra.algebra_ext\n  intro r\n  rw [RingHom.algebraMap_toAlgebra]\n#align is_localization.is_localization_iff_of_base_ring_equiv IsLocalization.isLocalization_iff_of_base_ringEquiv\n\nend\n\nvariable (M)\n\ntheorem nonZeroDivisors_le_comap [IsLocalization M S] :\n    nonZeroDivisors R \u2264 (nonZeroDivisors S).comap (algebraMap R S) := by\n  rintro a ha b (e : b * algebraMap R S a = 0)\n  obtain \u27e8x, s, rfl\u27e9 := mk'_surjective M b\n  rw [\u2190 @mk'_one R _ M, \u2190 mk'_mul, \u2190 (algebraMap R S).map_zero, \u2190 @mk'_one R _ M,\n    IsLocalization.eq] at e\n  obtain \u27e8c, e\u27e9 := e\n  rw [mul_zero, mul_zero, Submonoid.coe_one, one_mul, \u2190 mul_assoc] at e\n  rw [mk'_eq_zero_iff]\n  exact \u27e8c, ha _ e\u27e9\n#align is_localization.non_zero_divisors_le_comap IsLocalization.nonZeroDivisors_le_comap\n\ntheorem map_nonZeroDivisors_le [IsLocalization M S] :\n    (nonZeroDivisors R).map (algebraMap R S) \u2264 nonZeroDivisors S :=\n  Submonoid.map_le_iff_le_comap.mpr (nonZeroDivisors_le_comap M S)\n#align is_localization.map_non_zero_divisors_le IsLocalization.map_nonZeroDivisors_le\n\nend IsLocalization\n\nnamespace Localization\n\nopen IsLocalization\n\n/-! ### Constructing a localization at a given submonoid -/\n\nsection\n\ninstance [Subsingleton R] : Unique (Localization M) :=\n  \u27e8\u27e81\u27e9, by\n    intro a; refine Localization.induction_on a ?_; intro a;\n    refine Localization.induction_on default ?_\n    intro b;\n    congr\n    exact Subsingleton.elim _ _\n    exact Subsingleton.elim _ _\u27e9\n\n/-- Addition in a ring localization is defined as `\u27e8a, b\u27e9 + \u27e8c, d\u27e9 = \u27e8b * c + d * a, b * d\u27e9`.\n\nShould not be confused with `addLocalization.add`, which is defined as\n`\u27e8a, b\u27e9 + \u27e8c, d\u27e9 = \u27e8a + c, b + d\u27e9`.\n-/\nprotected def add (z w : Localization M) : Localization M :=\n  Localization.liftOn\u2082 z w (fun a b c d => mk ((b : R) * c + d * a) (b * d))\n    @fun a a' b b' c c' d d' h1 h2 =>\n    mk_eq_mk_iff.2\n      (by\n        rw [r_eq_r'] at h1 h2\u22a2\n        cases' h1 with t\u2085 ht\u2085\n        cases' h2 with t\u2086 ht\u2086\n        use t\u2085 * t\u2086\n        dsimp only\n        calc\n          \u2191t\u2085 * \u2191t\u2086 * (\u2191b' * \u2191d' * ((b : R) * c + d * a)) =\n              t\u2086 * (d' * c) * (t\u2085 * (b' * b)) + t\u2085 * (b' * a) * (t\u2086 * (d' * d)) :=\n            by ring\n          _ = t\u2085 * t\u2086 * (b * d * (b' * c' + d' * a')) := by rw [ht\u2086, ht\u2085]; ring\n          )\n#align localization.add Localization.add\n\ninstance : Add (Localization M) :=\n  \u27e8Localization.add\u27e9\n\ntheorem add_mk (a b c d) : (mk a b : Localization M) + mk c d =\n    mk ((b : R) * c + (d : R) * a) (b * d) := by\n  show Localization.add (mk a b) (mk c d) = mk _ _\n  simp [Localization.add]\n#align localization.add_mk Localization.add_mk\n\n--Porting note: `Localization.add` was an `irreducible_def`, but then I couldn't prove `add_mk`\nattribute [irreducible] Localization.add\n\ntheorem add_mk_self (a b c) : (mk a b : Localization M) + mk c b = mk (a + c) b := by\n  rw [add_mk, mk_eq_mk_iff, r_eq_r']\n  refine' (r' M).symm \u27e81, _\u27e9\n  simp only [Submonoid.coe_one, Submonoid.coe_mul]\n  ring\n#align localization.add_mk_self Localization.add_mk_self\n\nlocal macro \"localization_tac\": tactic =>\n  `(tactic|\n   { intros\n     simp only [add_mk, Localization.mk_mul, \u2190 Localization.mk_zero 1]\n     refine mk_eq_mk_iff.mpr (r_of_eq ?_)\n     simp only [Submonoid.coe_mul]\n     ring  })\n\ninstance : CommSemiring (Localization M) :=\n  { (show CommMonoidWithZero (Localization M) by infer_instance) with\n    add := (\u00b7 + \u00b7)\n    nsmul := (\u00b7 \u2022 \u00b7)\n    nsmul_zero := fun x =>\n      Localization.induction_on x fun x => by simp only [smul_mk, zero_nsmul, mk_zero]\n    nsmul_succ := fun n x =>\n      Localization.induction_on x fun x => by simp only [smul_mk, succ_nsmul, add_mk_self]\n    add_assoc := fun m n k =>\n      Localization.induction_on\u2083 m n k\n        (by localization_tac)\n    zero_add := fun y =>\n      Localization.induction_on y\n        (by localization_tac)\n    add_zero := fun y =>\n      Localization.induction_on y\n        (by localization_tac)\n    add_comm := fun y z =>\n      Localization.induction_on\u2082 z y\n        (by localization_tac)\n    left_distrib := fun m n k =>\n      Localization.induction_on\u2083 m n k\n        (by localization_tac)\n    right_distrib := fun m n k =>\n      Localization.induction_on\u2083 m n k\n        (by localization_tac) }\n\n/-- For any given denominator `b : M`, the map `a \u21a6 a / b` is an `AddMonoidHom` from `R` to\n  `Localization M`-/\n@[simps]\ndef mkAddMonoidHom (b : M) : R \u2192+ Localization M\n    where\n  toFun a := mk a b\n  map_zero' := mk_zero _\n  map_add' _ _ := (add_mk_self _ _ _).symm\n#align localization.mk_add_monoid_hom Localization.mkAddMonoidHom\n\ntheorem mk_sum {\u03b9 : Type _} (f : \u03b9 \u2192 R) (s : Finset \u03b9) (b : M) :\n    mk (\u2211 i in s, f i) b = \u2211 i in s, mk (f i) b :=\n  (mkAddMonoidHom b).map_sum f s\n#align localization.mk_sum Localization.mk_sum\n\ntheorem mk_list_sum (l : List R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum :=\n  (mkAddMonoidHom b).map_list_sum l\n#align localization.mk_list_sum Localization.mk_list_sum\n\ntheorem mk_multiset_sum (l : Multiset R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum :=\n  (mkAddMonoidHom b).map_multiset_sum l\n#align localization.mk_multiset_sum Localization.mk_multiset_sum\n\ninstance {S : Type _} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] :\n    DistribMulAction S (Localization M)\n    where\n  smul_zero s := by simp only [\u2190 Localization.mk_zero 1, Localization.smul_mk, smul_zero]\n  smul_add s x y :=\n    Localization.induction_on\u2082 x y <|\n      Prod.rec fun r\u2081 x\u2081 =>\n        Prod.rec fun r\u2082 x\u2082 => by\n          simp only [Localization.smul_mk, Localization.add_mk, smul_add, mul_comm _ (s \u2022 _),\n            mul_comm _ r\u2081, mul_comm _ r\u2082, smul_mul_assoc]\n\ninstance {S : Type _} [Semiring S] [MulSemiringAction S R] [IsScalarTower S R R] :\n    MulSemiringAction S (Localization M) :=\n  { inferInstanceAs (MulDistribMulAction S (Localization M)),\n    inferInstanceAs (DistribMulAction S (Localization M)) with }\n\ninstance {S : Type _} [Semiring S] [Module S R] [IsScalarTower S R R] : Module S (Localization M) :=\n  { inferInstanceAs (DistribMulAction S (Localization M)) with\n    zero_smul :=\n      Localization.ind <|\n        Prod.rec <| by\n          intros\n          simp only [Localization.smul_mk, zero_smul, mk_zero]\n    add_smul := fun s\u2081 s\u2082 =>\n      Localization.ind <|\n        Prod.rec <| by\n          intros\n          simp only [Localization.smul_mk, add_smul, add_mk_self] }\n\ninstance {S : Type _} [CommSemiring S] [Algebra S R] : Algebra S (Localization M)\n    where\n  toRingHom :=\n    RingHom.comp\n      { Localization.monoidOf M with\n        toFun := (monoidOf M).toMap\n        map_zero' := by rw [\u2190 mk_zero (1 : M), mk_one_eq_monoidOf_mk]\n        map_add' := fun x y => by\n          simp only [\u2190 mk_one_eq_monoidOf_mk, add_mk, Submonoid.coe_one, one_mul, add_comm] }\n      (algebraMap S R)\n  smul_def' s :=\n    Localization.ind <|\n      Prod.rec <| by\n        intro r x\n        dsimp\n        simp only [\u2190 mk_one_eq_monoidOf_mk, mk_mul, Localization.smul_mk, one_mul,\n          Algebra.smul_def]\n  commutes' s :=\n    Localization.ind <|\n      Prod.rec <| by\n        intro r x\n        dsimp\n        simp only [\u2190 mk_one_eq_monoidOf_mk, mk_mul, Localization.smul_mk, one_mul, mul_one,\n          Algebra.commutes]\n\ninstance : IsLocalization M (Localization M) where\n  map_units' := (Localization.monoidOf M).map_units\n  surj' := (Localization.monoidOf M).surj\n  eq_iff_exists' := (Localization.monoidOf M).eq_iff_exists\n\nend\n\n@[simp]\ntheorem toLocalizationMap_eq_monoidOf : toLocalizationMap M (Localization M) = monoidOf M :=\n  rfl\n#align localization.to_localization_map_eq_monoid_of Localization.toLocalizationMap_eq_monoidOf\n\ntheorem monoidOf_eq_algebraMap (x) : (monoidOf M).toMap x = algebraMap R (Localization M) x :=\n  rfl\n#align localization.monoid_of_eq_algebra_map Localization.monoidOf_eq_algebraMap\n\ntheorem mk_one_eq_algebraMap (x) : mk x 1 = algebraMap R (Localization M) x :=\n  rfl\n#align localization.mk_one_eq_algebra_map Localization.mk_one_eq_algebraMap\n\ntheorem mk_eq_mk'_apply (x y) : mk x y = IsLocalization.mk' (Localization M) x y := by\n  rw [mk_eq_monoidOf_mk'_apply, mk', toLocalizationMap_eq_monoidOf]\n#align localization.mk_eq_mk'_apply Localization.mk_eq_mk'_apply\n\n--Porting note: removed `simp`. Left hand side can be simplified; not clear what normal form should\n--be.\ntheorem mk_eq_mk' : (mk : R \u2192 M \u2192 Localization M) = IsLocalization.mk' (Localization M) :=\n  mk_eq_monoidOf_mk'\n#align localization.mk_eq_mk' Localization.mk_eq_mk'\n\ntheorem mk_algebraMap {A : Type _} [CommSemiring A] [Algebra A R] (m : A) :\n    mk (algebraMap A R m) 1 = algebraMap A (Localization M) m := by\n  rw [mk_eq_mk', mk'_eq_iff_eq_mul, Submonoid.coe_one, map_one, mul_one]; rfl\n#align localization.mk_algebra_map Localization.mk_algebraMap\n\ntheorem mk_nat_cast (m : \u2115) : (mk m 1 : Localization M) = m := by\n  simpa using @mk_algebraMap R _ M \u2115 _ _ m\n#align localization.mk_nat_cast Localization.mk_nat_cast\n\nvariable [IsLocalization M S]\n\nsection\n\nvariable (M)\n\n/-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/\n@[simps!]\nnoncomputable def algEquiv : Localization M \u2243\u2090[R] S :=\n  IsLocalization.algEquiv M _ _\n#align localization.alg_equiv Localization.algEquiv\n\n/-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/\nnoncomputable def _root_.IsLocalization.unique (R R\u2098) [CommSemiring R] [CommSemiring R\u2098]\n    (M : Submonoid R) [Subsingleton R] [Algebra R R\u2098] [IsLocalization M R\u2098] : Unique R\u2098 :=\n  have : Inhabited R\u2098 := \u27e81\u27e9\n  (algEquiv M R\u2098).symm.injective.unique\n#align is_localization.unique IsLocalization.unique\n\nend\n\n--Porting note: removed `simp`, `simp` can prove it\nnonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y :=\n  algEquiv_mk' _ _\n#align localization.alg_equiv_mk' Localization.algEquiv_mk'\n\n--Porting note: removed `simp`, `simp` can prove it\nnonrec theorem algEquiv_symm_mk' (x : R) (y : M) :\n    (algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y :=\n  algEquiv_symm_mk' _ _\n#align localization.alg_equiv_symm_mk' Localization.algEquiv_symm_mk'\n\ntheorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk']\n#align localization.alg_equiv_mk Localization.algEquiv_mk\n\ntheorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by\n  rw [mk_eq_mk', algEquiv_symm_mk']\n#align localization.alg_equiv_symm_mk Localization.algEquiv_symm_mk\n\nend Localization\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type _} [CommRing R] {M : Submonoid R} (S : Type _) [CommRing S]\n\nvariable [Algebra R S] {P : Type _} [CommRing P]\n\nnamespace Localization\n\n/-- Negation in a ring localization is defined as `-\u27e8a, b\u27e9 = \u27e8-a, b\u27e9`. -/\nprotected def neg (z : Localization M) : Localization M :=\n  Localization.liftOn z (fun a b => mk (-a) b) @fun a b c d h =>\n    mk_eq_mk_iff.2\n      (by\n        rw [r_eq_r'] at h\u22a2\n        cases' h with t ht\n        use t\n        rw [mul_neg, mul_neg, ht]\n        ring_nf)\n#align localization.neg Localization.neg\n\ninstance : Neg (Localization M) :=\n  \u27e8Localization.neg\u27e9\n\ntheorem neg_mk (a b) : -(mk a b : Localization M) = mk (-a) b := by\n  show Localization.neg (mk a b) = mk (-a) b\n  apply liftOn_mk\n#align localization.neg_mk Localization.neg_mk\n\n--Porting note: `Localization.neg` was an `irreducible_def`, but then I couldn't prove `neg_mk`\nattribute [irreducible] Localization.neg\n\ninstance : CommRing (Localization M) :=\n  { inferInstanceAs (CommSemiring (Localization M)) with\n    zsmul := (\u00b7 \u2022 \u00b7)\n    zsmul_zero' := fun x =>\n      Localization.induction_on x fun x => by simp only [smul_mk, zero_zsmul, mk_zero]\n    zsmul_succ' := fun n x =>\n      Localization.induction_on x fun x => by\n        simp [smul_mk, add_mk_self, -mk_eq_monoidOf_mk', add_comm (n : \u2124) 1, add_smul]\n    zsmul_neg' := fun n x =>\n      Localization.induction_on x fun x => by\n        dsimp only\n        rw [smul_mk, smul_mk, neg_mk, \u2190 neg_smul]\n        rfl\n    neg := Neg.neg\n    sub := fun x y => x + -y\n    sub_eq_add_neg := fun x y => rfl\n    add_left_neg := fun y =>\n      Localization.induction_on y\n        (by\n          intros\n          simp only [add_mk, Localization.mk_mul, neg_mk, \u2190 mk_zero 1]\n          refine' mk_eq_mk_iff.mpr (r_of_eq _)\n          simp only [Submonoid.coe_mul]\n          ring) }\n\ntheorem sub_mk (a c) (b d) : (mk a b : Localization M) - mk c d =\n    mk ((d : R) * a - b * c) (b * d) :=\n  calc\n    mk a b - mk c d = mk a b + -mk c d := sub_eq_add_neg _ _\n    _ = mk a b + mk (-c) d := by rw [neg_mk]\n    _ = mk (b * -c + d * a) (b * d) := (add_mk _ _ _ _)\n    _ = mk (d * a - b * c) (b * d) := by congr; ring\n\n#align localization.sub_mk Localization.sub_mk\n\ntheorem mk_int_cast (m : \u2124) : (mk m 1 : Localization M) = m := by\n  simpa using @mk_algebraMap R _ M \u2124 _ _ m\n#align localization.mk_int_cast Localization.mk_int_cast\n\nend Localization\n\nnamespace IsLocalization\n\nvariable {K : Type _} [IsLocalization M S]\n\ntheorem to_map_eq_zero_iff {x : R} (hM : M \u2264 nonZeroDivisors R) : algebraMap R S x = 0 \u2194 x = 0 := by\n  rw [\u2190 (algebraMap R S).map_zero]\n  constructor <;> intro h\n  \u00b7 cases' (eq_iff_exists M S).mp h with c hc\n    rw [mul_zero, mul_comm] at hc\n    exact hM c.2 x hc\n  \u00b7 rw [h]\n#align is_localization.to_map_eq_zero_iff IsLocalization.to_map_eq_zero_iff\n\nprotected theorem injective (hM : M \u2264 nonZeroDivisors R) : Injective (algebraMap R S) := by\n  rw [injective_iff_map_eq_zero (algebraMap R S)]\n  intro a ha\n  rwa [to_map_eq_zero_iff S hM] at ha\n#align is_localization.injective IsLocalization.injective\n\nprotected theorem to_map_ne_zero_of_mem_nonZeroDivisors [Nontrivial R] (hM : M \u2264 nonZeroDivisors R)\n    {x : R} (hx : x \u2208 nonZeroDivisors R) : algebraMap R S x \u2260 0 :=\n  show (algebraMap R S).toMonoidWithZeroHom x \u2260 0 from\n    map_ne_zero_of_mem_nonZeroDivisors (algebraMap R S) (IsLocalization.injective S hM) hx\n#align is_localization.to_map_ne_zero_of_mem_non_zero_divisors IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors\n\nvariable {S}\n\ntheorem sec_snd_ne_zero [Nontrivial R] (hM : M \u2264 nonZeroDivisors R) (x : S) :\n    ((sec M x).snd : R) \u2260 0 :=\n  nonZeroDivisors.coe_ne_zero \u27e8(sec M x).snd.val, hM (sec M x).snd.property\u27e9\n#align is_localization.sec_snd_ne_zero IsLocalization.sec_snd_ne_zero\n\ntheorem sec_fst_ne_zero [Nontrivial R] [NoZeroDivisors S] (hM : M \u2264 nonZeroDivisors R) {x : S}\n    (hx : x \u2260 0) : (sec M x).fst \u2260 0 := by\n  have hsec := sec_spec M x\n  intro hfst\n  rw [hfst, map_zero, mul_eq_zero, _root_.map_eq_zero_iff] at hsec\n  \u00b7 exact Or.elim hsec hx (sec_snd_ne_zero hM x)\n  \u00b7 exact IsLocalization.injective S hM\n#align is_localization.sec_fst_ne_zero IsLocalization.sec_fst_ne_zero\n\nvariable (S M) (Q : Type _) [CommRing Q] {g : R \u2192+* P} [Algebra P Q]\n\n/-- Injectivity of a map descends to the map induced on localizations. -/\ntheorem map_injective_of_injective (hg : Function.Injective g)\n    [i : IsLocalization (M.map g : Submonoid P) Q] :\n    --Porting note: Why does `i` need to be given explicitly?\n    Function.Injective (@map _ _ _ _ _ _ _ _ _ _ Q _ _ i g (Submonoid.le_comap_map M) : S \u2192 Q) := by\n  rw [injective_iff_map_eq_zero]\n  intro z hz\n  obtain \u27e8a, b, rfl\u27e9 := mk'_surjective M z\n  rw [map_mk', mk'_eq_zero_iff] at hz\n  obtain \u27e8\u27e8m', hm'\u27e9, hm\u27e9 := hz\n  rw [Submonoid.mem_map] at hm'\n  obtain \u27e8n, hn, hnm\u27e9 := hm'\n  rw [Subtype.coe_mk, \u2190 hnm, \u2190 map_mul, \u2190 map_zero g] at hm\n  rw [mk'_eq_zero_iff]\n  exact \u27e8\u27e8n, hn\u27e9, hg hm\u27e9\n#align is_localization.map_injective_of_injective IsLocalization.map_injective_of_injective\n\nvariable {S Q M}\n\nvariable (A : Type _) [CommRing A] [IsDomain A]\n\n/-- A `CommRing` `S` which is the localization of a ring `R` without zero divisors at a subset of\nnon-zero elements does not have zero divisors.\nSee note [reducible non-instances]. -/\n@[reducible]\ntheorem noZeroDivisors_of_le_nonZeroDivisors [Algebra A S] {M : Submonoid A} [IsLocalization M S]\n    (hM : M \u2264 nonZeroDivisors A) : NoZeroDivisors S :=\n  {\n    eq_zero_or_eq_zero_of_mul_eq_zero := by\n      intro z w h\n      cases' surj M z with x hx\n      cases' surj M w with y hy\n      have :\n        z * w * algebraMap A S y.2 * algebraMap A S x.2 = algebraMap A S x.1 * algebraMap A S y.1 :=\n        by rw [mul_assoc z, hy, \u2190 hx]; ring\n      rw [h, zero_mul, zero_mul, \u2190 (algebraMap A S).map_mul] at this\n      cases' eq_zero_or_eq_zero_of_mul_eq_zero ((to_map_eq_zero_iff S hM).mp this.symm) with H H\n      \u00b7 exact Or.inl (eq_zero_of_fst_eq_zero hx H)\n      \u00b7 exact Or.inr (eq_zero_of_fst_eq_zero hy H) }\n#align is_localization.no_zero_divisors_of_le_non_zero_divisors IsLocalization.noZeroDivisors_of_le_nonZeroDivisors\n\n/-- A `CommRing` `S` which is the localization of an integral domain `R` at a subset of\nnon-zero elements is an integral domain.\nSee note [reducible non-instances]. -/\n@[reducible]\ntheorem isDomain_of_le_nonZeroDivisors [Algebra A S] {M : Submonoid A} [IsLocalization M S]\n    (hM : M \u2264 nonZeroDivisors A) : IsDomain S := by\n  apply @NoZeroDivisors.to_isDomain _ _ (id _) (id _)\n  \u00b7 exact\n      \u27e8\u27e8(algebraMap A S) 0, (algebraMap A S) 1, fun h =>\n          zero_ne_one (IsLocalization.injective S hM h)\u27e9\u27e9\n  \u00b7 exact noZeroDivisors_of_le_nonZeroDivisors _ hM\n#align is_localization.is_domain_of_le_non_zero_divisors IsLocalization.isDomain_of_le_nonZeroDivisors\n\nvariable {A}\n\n/-- The localization at of an integral domain to a set of non-zero elements is an integral domain.\nSee note [reducible non-instances]. -/\n@[reducible]\ntheorem isDomain_localization {M : Submonoid A} (hM : M \u2264 nonZeroDivisors A) :\n    IsDomain (Localization M) :=\n  isDomain_of_le_nonZeroDivisors _ hM\n#align is_localization.is_domain_localization IsLocalization.isDomain_localization\n\nend IsLocalization\n\nopen IsLocalization\n\n/-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/\ntheorem IsField.localization_map_bijective {R R\u2098 : Type _} [CommRing R] [CommRing R\u2098]\n    {M : Submonoid R} (hM : (0 : R) \u2209 M) (hR : IsField R) [Algebra R R\u2098] [IsLocalization M R\u2098] :\n    Function.Bijective (algebraMap R R\u2098) := by\n  letI := hR.toField\n  replace hM := le_nonZeroDivisors_of_noZeroDivisors hM\n  refine' \u27e8IsLocalization.injective _ hM, fun x => _\u27e9\n  obtain \u27e8r, \u27e8m, hm\u27e9, rfl\u27e9 := mk'_surjective M x\n  obtain \u27e8n, hn\u27e9 := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm)\n  exact \u27e8r * n, by erw [eq_mk'_iff_mul_eq, \u2190 map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]\u27e9\n#align is_field.localization_map_bijective IsField.localization_map_bijective\n\n/-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/\ntheorem Field.localization_map_bijective {K K\u2098 : Type _} [Field K] [CommRing K\u2098] {M : Submonoid K}\n    (hM : (0 : K) \u2209 M) [Algebra K K\u2098] [IsLocalization M K\u2098] :\n    Function.Bijective (algebraMap K K\u2098) :=\n  (Field.toIsField K).localization_map_bijective hM\n#align field.localization_map_bijective Field.localization_map_bijective\n\n-- this looks weird due to the `letI` inside the above lemma, but trying to do it the other\n-- way round causes issues with defeq of instances, so this is actually easier.\nsection Algebra\n\nvariable {S} {R\u2098 S\u2098 : Type _} [CommRing R\u2098] [CommRing S\u2098]\n\nvariable [Algebra R R\u2098] [IsLocalization M R\u2098]\n\nvariable [Algebra S S\u2098] [i : IsLocalization (Algebra.algebraMapSubmonoid S M) S\u2098]\n\nsection\n\nvariable (S M)\n\n/-- Definition of the natural algebra induced by the localization of an algebra.\nGiven an algebra `R \u2192 S`, a submonoid `R` of `M`, and a localization `R\u2098` for `M`,\nlet `S\u2098` be the localization of `S` to the image of `M` under `algebraMap R S`.\nThen this is the natural algebra structure on `R\u2098 \u2192 S\u2098`, such that the entire square commutes,\nwhere `localization_map.map_comp` gives the commutativity of the underlying maps.\n\nThis instance can be helpful if you define `S\u2098 := Localization (Algebra.algebraMapSubmonoid S M)`,\nhowever we will instead use the hypotheses `[Algebra R\u2098 S\u2098] [IsScalarTower R R\u2098 S\u2098]` in lemmas\nsince the algebra structure may arise in different ways.\n-/\nnoncomputable def localizationAlgebra : Algebra R\u2098 S\u2098 :=\n  (map S\u2098 (algebraMap R S)\n        (show _ \u2264 (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) :\n      R\u2098 \u2192+* S\u2098).toAlgebra\n#align localization_algebra localizationAlgebra\n\nend\n\nsection\n\nvariable [Algebra R\u2098 S\u2098] [Algebra R S\u2098] [IsScalarTower R R\u2098 S\u2098] [IsScalarTower R S S\u2098]\n\nvariable (S R\u2098 S\u2098)\n\ntheorem IsLocalization.map_units_map_submonoid (y : M) : IsUnit (algebraMap R S\u2098 y) := by\n  rw [IsScalarTower.algebraMap_apply _ S]\n  exact IsLocalization.map_units S\u2098 \u27e8algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y\u27e9\n#align is_localization.map_units_map_submonoid IsLocalization.map_units_map_submonoid\n\n@[simp]\ntheorem IsLocalization.algebraMap_mk' (x : R) (y : M) :\n    algebraMap R\u2098 S\u2098 (IsLocalization.mk' R\u2098 x y) =\n      IsLocalization.mk' S\u2098 (algebraMap R S x)\n        \u27e8algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y\u27e9 := by\n  rw [IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, \u2190 IsScalarTower.algebraMap_apply, \u2190\n    IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R R\u2098 S\u2098,\n    IsScalarTower.algebraMap_apply R R\u2098 S\u2098, \u2190 _root_.map_mul, mul_comm,\n    IsLocalization.mul_mk'_eq_mk'_of_mul]\n  exact congr_arg (algebraMap R\u2098 S\u2098) (IsLocalization.mk'_mul_cancel_left x y)\n#align is_localization.algebra_map_mk' IsLocalization.algebraMap_mk'\n\nvariable (M)\n\n/-- If the square below commutes, the bottom map is uniquely specified:\n```\nR  \u2192  S\n\u2193     \u2193\nR\u2098 \u2192 S\u2098\n```\n-/\ntheorem IsLocalization.algebraMap_eq_map_map_submonoid :\n    algebraMap R\u2098 S\u2098 =\n      map S\u2098 (algebraMap R S)\n        (show _ \u2264 (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) :=\n  Eq.symm <|\n    IsLocalization.map_unique _ (algebraMap R\u2098 S\u2098) fun x => by\n      rw [\u2190 IsScalarTower.algebraMap_apply R S S\u2098, \u2190 IsScalarTower.algebraMap_apply R R\u2098 S\u2098]\n#align is_localization.algebra_map_eq_map_map_submonoid IsLocalization.algebraMap_eq_map_map_submonoid\n\n/-- If the square below commutes, the bottom map is uniquely specified:\n```\nR  \u2192  S\n\u2193     \u2193\nR\u2098 \u2192 S\u2098\n```\n-/\ntheorem IsLocalization.algebraMap_apply_eq_map_map_submonoid (x) :\n    algebraMap R\u2098 S\u2098 x =\n      map S\u2098 (algebraMap R S)\n        (show _ \u2264 (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) x :=\n  FunLike.congr_fun (IsLocalization.algebraMap_eq_map_map_submonoid _ _ _ _) x\n#align is_localization.algebra_map_apply_eq_map_map_submonoid IsLocalization.algebraMap_apply_eq_map_map_submonoid\n\ntheorem IsLocalization.lift_algebraMap_eq_algebraMap :\n    @IsLocalization.lift R _ M R\u2098 _ _ S\u2098 _ _ (algebraMap R S\u2098)\n        (IsLocalization.map_units_map_submonoid S S\u2098) =\n      algebraMap R\u2098 S\u2098 :=\n  IsLocalization.lift_unique _ fun _ => (IsScalarTower.algebraMap_apply _ _ _ _).symm\n#align is_localization.lift_algebra_map_eq_algebra_map IsLocalization.lift_algebraMap_eq_algebraMap\n\nend\n\nvariable (R\u2098 S\u2098)\n\n/-- Injectivity of the underlying `algebraMap` descends to the algebra induced by localization. -/\ntheorem localizationAlgebra_injective (hRS : Function.Injective (algebraMap R S)) :\n    Function.Injective (@algebraMap R\u2098 S\u2098 _ _ (localizationAlgebra M S)) :=\n  --Porting note: I don't understand why `i` needs to be explicit or why writing `(i := i)`\n  --doesn't work.\n  @IsLocalization.map_injective_of_injective _ _ M R\u2098 _ _ _ _ _ S\u2098 _ _ _ hRS i\n#align localization_algebra_injective localizationAlgebra_injective\n\nend Algebra\n\nend CommRing\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/Localization/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002789, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.7335345705336869}}
{"text": "import Mathlib.Data.Rat.Order\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Existsi\n\n/- 4 points -/\ntheorem problem1 {a b : \u211a} (h1 : a - b = 4) (h2 : a * b = 1) :\n    (a + b) ^ 2 = 20 :=\n  calc (a + b) ^ 2 = (a - b) ^ 2 + 4 * (a * b) := by ring\n  _ = 4 ^ 2 + 4 * 1 := by rw [h1, h2]\n  _ = 20 := by ring\n\n/- 2 points -/\ntheorem problem2 {a : \u211a} (h : \u2203 b : \u211a, a = b ^ 2) : a \u2265 0 := by\n  cases' h with b hb\n  calc a = b ^ 2 := hb\n  _ \u2265 0 := by apply sq_nonneg\n\ntheorem you_might_use_this_theorem_in_your_answer :\n    1 + 1 = 2 := by\n  norm_num\n\n/- 4 points -/\ntheorem problem3 : \u2203 n : \u2124, 12 * n = 84 := by\n  existsi 7\n  norm_num\n", "meta": {"author": "hrmacbeth", "repo": "autograder_test_instructor", "sha": "86c0bb71a07a1ced42ffad1585b09ae07afb2e1c", "save_path": "github-repos/lean/hrmacbeth-autograder_test_instructor", "path": "github-repos/lean/hrmacbeth-autograder_test_instructor/autograder_test_instructor-86c0bb71a07a1ced42ffad1585b09ae07afb2e1c/ProblemSets/ProblemSet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416413, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.733519721934175}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Johan Commelin, Mario Carneiro\n-/\n\nimport data.mv_polynomial.monad\nimport data.set.disjointed\n\n/-!\n# Degrees and variables of polynomials\n\nThis file establishes many results about the degree and variable sets of a multivariate polynomial.\n\nThe *variable set* of a polynomial $P \\in R[X]$ is a `finset` containing each $x \\in X$\nthat appears in a monomial in $P$.\n\nThe *degree set* of a polynomial $P \\in R[X]$ is a `multiset` containing, for each $x$ in the\nvariable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a\nmonomial of $P$.\n\n## Main declarations\n\n* `mv_polynomial.degrees p` : the multiset of variables representing the union of the multisets\n  corresponding to each non-zero monomial in `p`.\n  For example if `7 \u2260 0` in `R` and `p = x\u00b2y+7y\u00b3` then `degrees p = {x, x, y, y, y}`\n\n* `mv_polynomial.vars p` : the finset of variables occurring in `p`.\n  For example if `p = x\u2074y+yz` then `vars p = {x, y, z}`\n\n* `mv_polynomial.degree_of n p : \u2115` : the total degree of `p` with respect to the variable `n`.\n  For example if `p = x\u2074y+yz` then `degree_of y p = 1`.\n\n* `mv_polynomial.total_degree p : \u2115` :\n  the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`.\n  For example if `p = x\u2074y+yz` then `total_degree p = 5`.\n\n## Notation\n\nAs in other polynomial files, we typically use the notation:\n\n+ `\u03c3 \u03c4 : Type*` (indexing the variables)\n\n+ `R : Type*` `[comm_semiring R]` (the coefficients)\n\n+ `s : \u03c3 \u2192\u2080 \u2115`, a function from `\u03c3` to `\u2115` which is zero away from a finite set.\nThis will give rise to a monomial in `mv_polynomial \u03c3 R` which mathematicians might call `X^s`\n\n+ `r : R`\n\n+ `i : \u03c3`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians\n\n+ `p : mv_polynomial \u03c3 R`\n\n-/\n\nnoncomputable theory\n\nopen_locale classical big_operators\n\nopen set function finsupp add_monoid_algebra\nopen_locale big_operators\n\nuniverses u v w\nvariables {R : Type u} {S : Type v}\n\nnamespace mv_polynomial\nvariables {\u03c3 \u03c4 : Type*} {r : R} {e : \u2115} {n m : \u03c3} {s : \u03c3 \u2192\u2080 \u2115}\n\nsection comm_semiring\nvariables [comm_semiring R] {p q : mv_polynomial \u03c3 R}\n\n\nsection degrees\n\n/-! ### `degrees` -/\n\n/--\nThe maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.\n\n(For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.)\n-/\ndef degrees (p : mv_polynomial \u03c3 R) : multiset \u03c3 :=\np.support.sup (\u03bbs:\u03c3 \u2192\u2080 \u2115, s.to_multiset)\n\nlemma degrees_monomial (s : \u03c3 \u2192\u2080 \u2115) (a : R) : degrees (monomial s a) \u2264 s.to_multiset :=\nfinset.sup_le $ assume t h,\nbegin\n  have := finsupp.support_single_subset h,\n  rw [finset.mem_singleton] at this,\n  rw this\nend\n\nlemma degrees_monomial_eq (s : \u03c3 \u2192\u2080 \u2115) (a : R) (ha : a \u2260 0) :\n  degrees (monomial s a) = s.to_multiset :=\nle_antisymm (degrees_monomial s a) $ finset.le_sup $\n  by rw [support_monomial, if_neg ha, finset.mem_singleton]\n\nlemma degrees_C (a : R) : degrees (C a : mv_polynomial \u03c3 R) = 0 :=\nmultiset.le_zero.1 $ degrees_monomial _ _\n\nlemma degrees_X' (n : \u03c3) : degrees (X n : mv_polynomial \u03c3 R) \u2264 {n} :=\nle_trans (degrees_monomial _ _) $ le_of_eq $ to_multiset_single _ _\n\n@[simp] lemma degrees_X [nontrivial R] (n : \u03c3) : degrees (X n : mv_polynomial \u03c3 R) = {n} :=\n(degrees_monomial_eq _ _ one_ne_zero).trans (to_multiset_single _ _)\n\n@[simp] lemma degrees_zero : degrees (0 : mv_polynomial \u03c3 R) = 0 :=\nby { rw \u2190 C_0, exact degrees_C 0 }\n\n@[simp] lemma degrees_one : degrees (1 : mv_polynomial \u03c3 R) = 0 := degrees_C 1\n\nlemma degrees_add (p q : mv_polynomial \u03c3 R) : (p + q).degrees \u2264 p.degrees \u2294 q.degrees :=\nbegin\n  refine finset.sup_le (assume b hb, _),\n  have := finsupp.support_add hb, rw finset.mem_union at this,\n  cases this,\n  { exact le_sup_left_of_le (finset.le_sup this) },\n  { exact le_sup_right_of_le (finset.le_sup this) },\nend\n\nlemma degrees_sum {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 mv_polynomial \u03c3 R) :\n  (\u2211 i in s, f i).degrees \u2264 s.sup (\u03bbi, (f i).degrees) :=\nbegin\n  refine s.induction _ _,\n  { simp only [finset.sum_empty, finset.sup_empty, degrees_zero], exact le_refl _ },\n  { assume i s his ih,\n    rw [finset.sup_insert, finset.sum_insert his],\n    exact le_trans (degrees_add _ _) (sup_le_sup_left ih _) }\nend\n\nlemma degrees_mul (p q : mv_polynomial \u03c3 R) : (p * q).degrees \u2264 p.degrees + q.degrees :=\nbegin\n  refine finset.sup_le (assume b hb, _),\n  have := support_mul p q hb,\n  simp only [finset.mem_bUnion, finset.mem_singleton] at this,\n  rcases this with \u27e8a\u2081, h\u2081, a\u2082, h\u2082, rfl\u27e9,\n  rw [finsupp.to_multiset_add],\n  exact add_le_add (finset.le_sup h\u2081) (finset.le_sup h\u2082)\nend\n\nlemma degrees_prod {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 mv_polynomial \u03c3 R) :\n  (\u220f i in s, f i).degrees \u2264 \u2211 i in s, (f i).degrees :=\nbegin\n  refine s.induction _ _,\n  { simp only [finset.prod_empty, finset.sum_empty, degrees_one] },\n  { assume i s his ih,\n    rw [finset.prod_insert his, finset.sum_insert his],\n    exact le_trans (degrees_mul _ _) (add_le_add_left ih _) }\nend\n\nlemma degrees_pow (p : mv_polynomial \u03c3 R) :\n  \u2200(n : \u2115), (p^n).degrees \u2264 n \u2022 p.degrees\n| 0       := begin rw [pow_zero, degrees_one], exact multiset.zero_le _ end\n| (n + 1) := by { rw [pow_succ, add_smul, add_comm, one_smul],\n    exact le_trans (degrees_mul _ _) (add_le_add_left (degrees_pow n) _) }\n\nlemma mem_degrees {p : mv_polynomial \u03c3 R} {i : \u03c3} :\n  i \u2208 p.degrees \u2194 \u2203 d, p.coeff d \u2260 0 \u2227 i \u2208 d.support :=\nby simp only [degrees, multiset.mem_sup, \u2190 mem_support_iff,\n    finsupp.mem_to_multiset, exists_prop]\n\nlemma le_degrees_add {p q : mv_polynomial \u03c3 R} (h : p.degrees.disjoint q.degrees) :\n  p.degrees \u2264 (p + q).degrees :=\nbegin\n  apply finset.sup_le,\n  intros d hd,\n  rw multiset.disjoint_iff_ne at h,\n  rw multiset.le_iff_count,\n  intros i,\n  rw [degrees, multiset.count_sup],\n  simp only [finsupp.count_to_multiset],\n  by_cases h0 : d = 0,\n  { simp only [h0, zero_le, finsupp.zero_apply], },\n  { refine @finset.le_sup _ _ _ (p + q).support _ d _,\n    rw [mem_support_iff, coeff_add],\n    suffices : q.coeff d = 0,\n    { rwa [this, add_zero, coeff, \u2190 finsupp.mem_support_iff], },\n    rw [\u2190 finsupp.support_eq_empty, \u2190 ne.def, \u2190 finset.nonempty_iff_ne_empty] at h0,\n    obtain \u27e8j, hj\u27e9 := h0,\n    contrapose! h,\n    rw mem_support_iff at hd,\n    refine \u27e8j, _, j, _, rfl\u27e9,\n    all_goals { rw mem_degrees, refine \u27e8d, _, hj\u27e9, assumption } }\nend\n\nlemma degrees_add_of_disjoint\n  {p q : mv_polynomial \u03c3 R} (h : multiset.disjoint p.degrees q.degrees) :\n  (p + q).degrees = p.degrees \u222a q.degrees :=\nbegin\n  apply le_antisymm,\n  { apply degrees_add },\n  { apply multiset.union_le,\n    { apply le_degrees_add h },\n    { rw add_comm, apply le_degrees_add h.symm } }\nend\n\nlemma degrees_map [comm_semiring S] (p : mv_polynomial \u03c3 R) (f : R \u2192+* S) :\n  (map f p).degrees \u2286 p.degrees :=\nbegin\n  dsimp only [degrees],\n  apply multiset.subset_of_le,\n  apply finset.sup_mono,\n  apply mv_polynomial.support_map_subset\nend\n\nlemma degrees_rename (f : \u03c3 \u2192 \u03c4) (\u03c6 : mv_polynomial \u03c3 R) :\n  (rename f \u03c6).degrees \u2286 (\u03c6.degrees.map f) :=\nbegin\n  intros i,\n  rw [mem_degrees, multiset.mem_map],\n  rintro \u27e8d, hd, hi\u27e9,\n  obtain \u27e8x, rfl, hx\u27e9 := coeff_rename_ne_zero _ _ _ hd,\n  simp only [map_domain, finsupp.mem_support_iff] at hi,\n  rw [sum_apply, finsupp.sum] at hi,\n  contrapose! hi,\n  rw [finset.sum_eq_zero],\n  intros j hj,\n  simp only [exists_prop, mem_degrees] at hi,\n  specialize hi j \u27e8x, hx, hj\u27e9,\n  rw [single_apply, if_neg hi],\nend\n\nlemma degrees_map_of_injective [comm_semiring S] (p : mv_polynomial \u03c3 R)\n  {f : R \u2192+* S} (hf : injective f) : (map f p).degrees = p.degrees :=\nby simp only [degrees, mv_polynomial.support_map_of_injective _ hf]\n\nend degrees\n\nsection vars\n\n/-! ### `vars` -/\n\n/-- `vars p` is the set of variables appearing in the polynomial `p` -/\ndef vars (p : mv_polynomial \u03c3 R) : finset \u03c3 := p.degrees.to_finset\n\n@[simp] lemma vars_0 : (0 : mv_polynomial \u03c3 R).vars = \u2205 :=\nby rw [vars, degrees_zero, multiset.to_finset_zero]\n\n@[simp] lemma vars_monomial (h : r \u2260 0) : (monomial s r).vars = s.support :=\nby rw [vars, degrees_monomial_eq _ _ h, finsupp.to_finset_to_multiset]\n\n@[simp] lemma vars_C : (C r : mv_polynomial \u03c3 R).vars = \u2205 :=\nby rw [vars, degrees_C, multiset.to_finset_zero]\n\n@[simp] lemma vars_X [nontrivial R] : (X n : mv_polynomial \u03c3 R).vars = {n} :=\nby rw [X, vars_monomial (@one_ne_zero R _ _), finsupp.support_single_ne_zero (one_ne_zero : 1 \u2260 0)]\n\nlemma mem_vars (i : \u03c3) :\n  i \u2208 p.vars \u2194 \u2203 (d : \u03c3 \u2192\u2080 \u2115) (H : d \u2208 p.support), i \u2208 d.support :=\nby simp only [vars, multiset.mem_to_finset, mem_degrees, mem_support_iff,\n  exists_prop]\n\nlemma mem_support_not_mem_vars_zero\n  {f : mv_polynomial \u03c3 R} {x : \u03c3 \u2192\u2080 \u2115} (H : x \u2208 f.support) {v : \u03c3} (h : v \u2209 vars f) :\n  x v = 0 :=\nbegin\n  rw [vars, multiset.mem_to_finset] at h,\n  rw \u2190 finsupp.not_mem_support_iff,\n  contrapose! h,\n  unfold degrees,\n  rw (show f.support = insert x f.support, from eq.symm $ finset.insert_eq_of_mem H),\n  rw finset.sup_insert,\n  simp only [multiset.mem_union, multiset.sup_eq_union],\n  left,\n  rwa [\u2190to_finset_to_multiset, multiset.mem_to_finset] at h,\nend\n\nlemma vars_add_subset (p q : mv_polynomial \u03c3 R) :\n  (p + q).vars \u2286 p.vars \u222a q.vars :=\nbegin\n  intros x hx,\n  simp only [vars, finset.mem_union, multiset.mem_to_finset] at hx \u22a2,\n  simpa using multiset.mem_of_le (degrees_add _ _) hx,\nend\n\n\n\nsection mul\n\nlemma vars_mul (\u03c6 \u03c8 : mv_polynomial \u03c3 R) : (\u03c6 * \u03c8).vars \u2286 \u03c6.vars \u222a \u03c8.vars :=\nbegin\n  intro i,\n  simp only [mem_vars, finset.mem_union],\n  rintro \u27e8d, hd, hi\u27e9,\n  rw [mem_support_iff, coeff_mul] at hd,\n  contrapose! hd, cases hd,\n  rw finset.sum_eq_zero,\n  rintro \u27e8d\u2081, d\u2082\u27e9 H,\n  rw finsupp.mem_antidiagonal_support at H,\n  subst H,\n  obtain H|H : i \u2208 d\u2081.support \u2228 i \u2208 d\u2082.support,\n  { simpa only [finset.mem_union] using finsupp.support_add hi, },\n  { suffices : coeff d\u2081 \u03c6 = 0, by simp [this],\n    rw [coeff, \u2190 finsupp.not_mem_support_iff], intro, solve_by_elim, },\n  { suffices : coeff d\u2082 \u03c8 = 0, by simp [this],\n    rw [coeff, \u2190 finsupp.not_mem_support_iff], intro, solve_by_elim, },\nend\n\n@[simp] lemma vars_one : (1 : mv_polynomial \u03c3 R).vars = \u2205 :=\nvars_C\n\nlemma vars_pow (\u03c6 : mv_polynomial \u03c3 R) (n : \u2115) : (\u03c6 ^ n).vars \u2286 \u03c6.vars :=\nbegin\n  induction n with n ih,\n  { simp },\n  { rw pow_succ,\n    apply finset.subset.trans (vars_mul _ _),\n    exact finset.union_subset (finset.subset.refl _) ih }\nend\n\n/--\nThe variables of the product of a family of polynomials\nare a subset of the union of the sets of variables of each polynomial.\n-/\nlemma vars_prod {\u03b9 : Type*} {s : finset \u03b9} (f : \u03b9 \u2192 mv_polynomial \u03c3 R) :\n  (\u220f i in s, f i).vars \u2286 s.bUnion (\u03bb i, (f i).vars) :=\nbegin\n  apply s.induction_on,\n  { simp },\n  { intros a s hs hsub,\n    simp only [hs, finset.bUnion_insert, finset.prod_insert, not_false_iff],\n    apply finset.subset.trans (vars_mul _ _),\n    exact finset.union_subset_union (finset.subset.refl _) hsub }\nend\n\nsection integral_domain\nvariables {A : Type*} [integral_domain A]\n\nlemma vars_C_mul (a : A) (ha : a \u2260 0) (\u03c6 : mv_polynomial \u03c3 A) : (C a * \u03c6).vars = \u03c6.vars :=\nbegin\n  ext1 i,\n  simp only [mem_vars, exists_prop, mem_support_iff],\n  apply exists_congr,\n  intro d,\n  apply and_congr _ iff.rfl,\n  rw [coeff_C_mul, mul_ne_zero_iff, eq_true_intro ha, true_and],\nend\n\nend integral_domain\n\nend mul\n\nsection sum\n\nvariables {\u03b9 : Type*} (t : finset \u03b9) (\u03c6 : \u03b9 \u2192 mv_polynomial \u03c3 R)\n\nlemma vars_sum_subset :\n  (\u2211 i in t, \u03c6 i).vars \u2286 finset.bUnion t (\u03bb i, (\u03c6 i).vars) :=\nbegin\n  apply t.induction_on,\n  { simp },\n  { intros a s has hsum,\n    rw [finset.bUnion_insert, finset.sum_insert has],\n    refine finset.subset.trans (vars_add_subset _ _)\n      (finset.union_subset_union (finset.subset.refl _) _),\n    assumption }\nend\n\nlemma vars_sum_of_disjoint (h : pairwise $ disjoint on (\u03bb i, (\u03c6 i).vars)) :\n  (\u2211 i in t, \u03c6 i).vars = finset.bUnion t (\u03bb i, (\u03c6 i).vars) :=\nbegin\n  apply t.induction_on,\n  { simp },\n  { intros a s has hsum,\n    rw [finset.bUnion_insert, finset.sum_insert has, vars_add_of_disjoint, hsum],\n    unfold pairwise on_fun at h,\n    rw hsum,\n    simp only [finset.disjoint_iff_ne] at h \u22a2,\n    intros v hv v2 hv2,\n    rw finset.mem_bUnion at hv2,\n    rcases hv2 with \u27e8i, his, hi\u27e9,\n    refine h a i _ _ hv _ hi,\n    rintro rfl,\n    contradiction }\nend\n\nend sum\n\nsection map\n\nvariables [comm_semiring S] (f : R \u2192+* S)\nvariable (p)\n\nlemma vars_map : (map f p).vars \u2286 p.vars :=\nby simp [vars, degrees_map]\n\nvariable {f}\nlemma vars_map_of_injective (hf : injective f) :\n  (map f p).vars = p.vars :=\nby simp [vars, degrees_map_of_injective _ hf]\n\nlemma vars_monomial_single (i : \u03c3) {e : \u2115} {r : R} (he : e \u2260 0) (hr : r \u2260 0) :\n  (monomial (finsupp.single i e) r).vars = {i} :=\nby rw [vars_monomial hr, finsupp.support_single_ne_zero he]\n\nlemma vars_eq_support_bUnion_support : p.vars = p.support.bUnion finsupp.support :=\nby { ext i, rw [mem_vars, finset.mem_bUnion] }\n\nend map\n\nend vars\n\nsection degree_of\n\n/-! ### `degree_of` -/\n\n/-- `degree_of n p` gives the highest power of X_n that appears in `p` -/\ndef degree_of (n : \u03c3) (p : mv_polynomial \u03c3 R) : \u2115 := p.degrees.count n\n\nend degree_of\n\nsection total_degree\n\n/-! ### `total_degree` -/\n\n/-- `total_degree p` gives the maximum |s| over the monomials X^s in `p` -/\ndef total_degree (p : mv_polynomial \u03c3 R) : \u2115 := p.support.sup (\u03bbs, s.sum $ \u03bbn e, e)\n\nlemma total_degree_eq (p : mv_polynomial \u03c3 R) :\n  p.total_degree = p.support.sup (\u03bbm, m.to_multiset.card) :=\nbegin\n  rw [total_degree],\n  congr, funext m,\n  exact (finsupp.card_to_multiset _).symm\nend\n\nlemma total_degree_le_degrees_card (p : mv_polynomial \u03c3 R) :\n  p.total_degree \u2264 p.degrees.card :=\nbegin\n  rw [total_degree_eq],\n  exact finset.sup_le (assume s hs, multiset.card_le_of_le $ finset.le_sup hs)\nend\n\n@[simp] lemma total_degree_C (a : R) : (C a : mv_polynomial \u03c3 R).total_degree = 0 :=\nnat.eq_zero_of_le_zero $ finset.sup_le $ assume n hn,\n  have _ := finsupp.support_single_subset hn,\n  begin\n    rw [finset.mem_singleton] at this,\n    subst this,\n    exact le_refl _\n  end\n\n@[simp] lemma total_degree_zero : (0 : mv_polynomial \u03c3 R).total_degree = 0 :=\nby rw [\u2190 C_0]; exact total_degree_C (0 : R)\n\n@[simp] lemma total_degree_one : (1 : mv_polynomial \u03c3 R).total_degree = 0 :=\ntotal_degree_C (1 : R)\n\n@[simp] lemma total_degree_X {R} [comm_semiring R] [nontrivial R] (s : \u03c3) :\n  (X s : mv_polynomial \u03c3 R).total_degree = 1 :=\nbegin\n  rw [total_degree, support_X],\n  simp only [finset.sup, sum_single_index, finset.fold_singleton, sup_bot_eq],\nend\n\nlemma total_degree_add (a b : mv_polynomial \u03c3 R) :\n  (a + b).total_degree \u2264 max a.total_degree b.total_degree :=\nfinset.sup_le $ assume n hn,\n  have _ := finsupp.support_add hn,\n  begin\n    rw finset.mem_union at this,\n    cases this,\n    { exact le_max_left_of_le (finset.le_sup this) },\n    { exact le_max_right_of_le (finset.le_sup this) }\n  end\n\nlemma total_degree_mul (a b : mv_polynomial \u03c3 R) :\n  (a * b).total_degree \u2264 a.total_degree + b.total_degree :=\nfinset.sup_le $ assume n hn,\n  have _ := add_monoid_algebra.support_mul a b hn,\n  begin\n    simp only [finset.mem_bUnion, finset.mem_singleton] at this,\n    rcases this with \u27e8a\u2081, h\u2081, a\u2082, h\u2082, rfl\u27e9,\n    rw [finsupp.sum_add_index],\n    { exact add_le_add (finset.le_sup h\u2081) (finset.le_sup h\u2082) },\n    { assume a, refl },\n    { assume a b\u2081 b\u2082, refl }\n  end\n\nlemma total_degree_pow (a : mv_polynomial \u03c3 R) (n : \u2115) :\n  (a ^ n).total_degree \u2264 n * a.total_degree :=\nbegin\n  induction n with n ih,\n  { simp only [nat.nat_zero_eq_zero, zero_mul, pow_zero, total_degree_one] },\n  rw pow_succ,\n  calc total_degree (a * a ^ n) \u2264 a.total_degree + (a^n).total_degree : total_degree_mul _ _\n    ... \u2264 a.total_degree + n * a.total_degree : add_le_add_left ih _\n    ... = (n+1) * a.total_degree : by rw [add_mul, one_mul, add_comm]\nend\n\nlemma total_degree_list_prod :\n  \u2200(s : list (mv_polynomial \u03c3 R)), s.prod.total_degree \u2264 (s.map mv_polynomial.total_degree).sum\n| []        := by rw [@list.prod_nil (mv_polynomial \u03c3 R) _, total_degree_one]; refl\n| (p :: ps) :=\n  begin\n    rw [@list.prod_cons (mv_polynomial \u03c3 R) _, list.map, list.sum_cons],\n    exact le_trans (total_degree_mul _ _) (add_le_add_left (total_degree_list_prod ps) _)\n  end\n\nlemma total_degree_multiset_prod (s : multiset (mv_polynomial \u03c3 R)) :\n  s.prod.total_degree \u2264 (s.map mv_polynomial.total_degree).sum :=\nbegin\n  refine quotient.induction_on s (assume l, _),\n  rw [multiset.quot_mk_to_coe, multiset.coe_prod, multiset.coe_map, multiset.coe_sum],\n  exact total_degree_list_prod l\nend\n\nlemma total_degree_finset_prod {\u03b9 : Type*}\n  (s : finset \u03b9) (f : \u03b9 \u2192 mv_polynomial \u03c3 R) :\n  (s.prod f).total_degree \u2264 \u2211 i in s, (f i).total_degree :=\nbegin\n  refine le_trans (total_degree_multiset_prod _) _,\n  rw [multiset.map_map],\n  refl\nend\n\nlemma exists_degree_lt [fintype \u03c3] (f : mv_polynomial \u03c3 R) (n : \u2115)\n  (h : f.total_degree < n * fintype.card \u03c3) {d : \u03c3 \u2192\u2080 \u2115} (hd : d \u2208 f.support) :\n  \u2203 i, d i < n :=\nbegin\n  contrapose! h,\n  calc n * fintype.card \u03c3\n        = \u2211 s:\u03c3, n         : by rw [finset.sum_const, nat.nsmul_eq_mul, mul_comm, finset.card_univ]\n    ... \u2264 \u2211 s, d s         : finset.sum_le_sum (\u03bb s _, h s)\n    ... \u2264 d.sum (\u03bb i e, e) : by { rw [finsupp.sum_fintype], intros, refl }\n    ... \u2264 f.total_degree   : finset.le_sup hd,\nend\n\nlemma coeff_eq_zero_of_total_degree_lt {f : mv_polynomial \u03c3 R} {d : \u03c3 \u2192\u2080 \u2115}\n  (h : f.total_degree < \u2211 i in d.support, d i) :\n  coeff d f = 0 :=\nbegin\n  classical,\n  rw [total_degree, finset.sup_lt_iff] at h,\n  { specialize h d, rw mem_support_iff at h,\n    refine not_not.mp (mt h _), exact lt_irrefl _, },\n  { exact lt_of_le_of_lt (nat.zero_le _) h, }\nend\n\nlemma total_degree_rename_le (f : \u03c3 \u2192 \u03c4) (p : mv_polynomial \u03c3 R) :\n  (rename f p).total_degree \u2264 p.total_degree :=\nfinset.sup_le $ assume b,\nbegin\n  assume h,\n  rw rename_eq at h,\n  have h' := finsupp.map_domain_support h,\n  rw finset.mem_image at h',\n  rcases h' with \u27e8s, hs, rfl\u27e9,\n  rw finsupp.sum_map_domain_index,\n  exact le_trans (le_refl _) (finset.le_sup hs),\n  exact assume _, rfl,\n  exact assume _ _ _, rfl\nend\n\nend total_degree\n\nsection eval_vars\n\n/-! ### `vars` and `eval` -/\n\nvariables [comm_semiring S]\n\nlemma eval\u2082_hom_eq_constant_coeff_of_vars (f : R \u2192+* S) {g : \u03c3 \u2192 S}\n  {p : mv_polynomial \u03c3 R} (hp : \u2200 i \u2208 p.vars, g i = 0) :\n  eval\u2082_hom f g p = f (constant_coeff p) :=\nbegin\n  conv_lhs { rw p.as_sum },\n  simp only [ring_hom.map_sum, eval\u2082_hom_monomial],\n  by_cases h0 : constant_coeff p = 0,\n  work_on_goal 0\n  { rw [h0, f.map_zero, finset.sum_eq_zero],\n    intros d hd },\n  work_on_goal 1\n  { rw [finset.sum_eq_single (0 : \u03c3 \u2192\u2080 \u2115)],\n    { rw [finsupp.prod_zero_index, mul_one],\n      refl },\n    intros d hd hd0, },\n  repeat\n  { obtain \u27e8i, hi\u27e9 : d.support.nonempty,\n    { rw [constant_coeff_eq, coeff, \u2190 finsupp.not_mem_support_iff] at h0,\n      rw [finset.nonempty_iff_ne_empty, ne.def, finsupp.support_eq_empty],\n      rintro rfl, contradiction },\n    rw [finsupp.prod, finset.prod_eq_zero hi, mul_zero],\n    rw [hp, zero_pow (nat.pos_of_ne_zero $ finsupp.mem_support_iff.mp hi)],\n    rw [mem_vars],\n    exact \u27e8d, hd, hi\u27e9 },\n  { rw [constant_coeff_eq, coeff, \u2190 ne.def, \u2190 finsupp.mem_support_iff] at h0,\n    intro, contradiction }\nend\n\nlemma aeval_eq_constant_coeff_of_vars [algebra R S] {g : \u03c3 \u2192 S}\n  {p : mv_polynomial \u03c3 R} (hp : \u2200 i \u2208 p.vars, g i = 0) :\n  aeval g p = algebra_map _ _ (constant_coeff p) :=\neval\u2082_hom_eq_constant_coeff_of_vars _ hp\n\nlemma eval\u2082_hom_congr' {f\u2081 f\u2082 : R \u2192+* S} {g\u2081 g\u2082 : \u03c3 \u2192 S} {p\u2081 p\u2082 : mv_polynomial \u03c3 R} :\n  f\u2081 = f\u2082 \u2192 (\u2200 i, i \u2208 p\u2081.vars \u2192 i \u2208 p\u2082.vars \u2192 g\u2081 i = g\u2082 i) \u2192 p\u2081 = p\u2082 \u2192\n   eval\u2082_hom f\u2081 g\u2081 p\u2081 = eval\u2082_hom f\u2082 g\u2082 p\u2082 :=\nbegin\n  rintro rfl h rfl,\n  rename [p\u2081 p, f\u2081 f],\n  rw p.as_sum,\n  simp only [ring_hom.map_sum, eval\u2082_hom_monomial],\n  apply finset.sum_congr rfl,\n  intros d hd,\n  congr' 1,\n  simp only [finsupp.prod],\n  apply finset.prod_congr rfl,\n  intros i hi,\n  have : i \u2208 p.vars, { rw mem_vars, exact \u27e8d, hd, hi\u27e9 },\n  rw h i this this,\nend\n\nlemma vars_bind\u2081 (f : \u03c3 \u2192 mv_polynomial \u03c4 R) (\u03c6 : mv_polynomial \u03c3 R) :\n  (bind\u2081 f \u03c6).vars \u2286 \u03c6.vars.bUnion (\u03bb i, (f i).vars) :=\nbegin\n  calc (bind\u2081 f \u03c6).vars\n      = (\u03c6.support.sum (\u03bb (x : \u03c3 \u2192\u2080 \u2115), (bind\u2081 f) (monomial x (coeff x \u03c6)))).vars :\n        by { rw [\u2190 alg_hom.map_sum, \u2190 \u03c6.as_sum], }\n  ... \u2264 \u03c6.support.bUnion (\u03bb (i : \u03c3 \u2192\u2080 \u2115), ((bind\u2081 f) (monomial i (coeff i \u03c6))).vars) :\n        vars_sum_subset _ _\n  ... = \u03c6.support.bUnion (\u03bb (d : \u03c3 \u2192\u2080 \u2115), (C (coeff d \u03c6) * \u220f i in d.support, f i ^ d i).vars) :\n        by simp only [bind\u2081_monomial]\n  ... \u2264 \u03c6.support.bUnion (\u03bb (d : \u03c3 \u2192\u2080 \u2115), d.support.bUnion (\u03bb i, (f i).vars)) : _ -- proof below\n  ... \u2264 \u03c6.vars.bUnion (\u03bb (i : \u03c3), (f i).vars) : _, -- proof below\n  { apply finset.bUnion_mono,\n    intros d hd,\n    calc (C (coeff d \u03c6) * \u220f (i : \u03c3) in d.support, f i ^ d i).vars\n        \u2264 (C (coeff d \u03c6)).vars \u222a (\u220f (i : \u03c3) in d.support, f i ^ d i).vars : vars_mul _ _\n    ... \u2264 (\u220f (i : \u03c3) in d.support, f i ^ d i).vars :\n      by simp only [finset.empty_union, vars_C, finset.le_iff_subset, finset.subset.refl]\n    ... \u2264 d.support.bUnion (\u03bb (i : \u03c3), (f i ^ d i).vars) : vars_prod _\n    ... \u2264 d.support.bUnion (\u03bb (i : \u03c3), (f i).vars) : _,\n    apply finset.bUnion_mono,\n    intros i hi,\n    apply vars_pow, },\n  { intro j,\n    simp_rw finset.mem_bUnion,\n    rintro \u27e8d, hd, \u27e8i, hi, hj\u27e9\u27e9,\n    exact \u27e8i, (mem_vars _).mpr \u27e8d, hd, hi\u27e9, hj\u27e9 }\nend\n\nlemma mem_vars_bind\u2081 (f : \u03c3 \u2192 mv_polynomial \u03c4 R) (\u03c6 : mv_polynomial \u03c3 R) {j : \u03c4}\n  (h : j \u2208 (bind\u2081 f \u03c6).vars) :\n  \u2203 (i : \u03c3), i \u2208 \u03c6.vars \u2227 j \u2208 (f i).vars :=\nby simpa only [exists_prop, finset.mem_bUnion, mem_support_iff, ne.def] using vars_bind\u2081 f \u03c6 h\n\nlemma vars_rename (f : \u03c3 \u2192 \u03c4) (\u03c6 : mv_polynomial \u03c3 R) :\n  (rename f \u03c6).vars \u2286 (\u03c6.vars.image f) :=\nbegin\n  intros i hi,\n  simp only [vars, exists_prop, multiset.mem_to_finset, finset.mem_image] at hi \u22a2,\n  simpa only [multiset.mem_map] using degrees_rename _ _ hi\nend\n\nlemma mem_vars_rename (f : \u03c3 \u2192 \u03c4) (\u03c6 : mv_polynomial \u03c3 R) {j : \u03c4} (h : j \u2208 (rename f \u03c6).vars) :\n  \u2203 (i : \u03c3), i \u2208 \u03c6.vars \u2227 f i = j :=\nby simpa only [exists_prop, finset.mem_image] using vars_rename f \u03c6 h\n\nend eval_vars\n\nend comm_semiring\n\nend mv_polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/mv_polynomial/variables.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7334625095270249}}
{"text": "/-\n# References\n\n1. Avigad, Jeremy. \u2018Theorem Proving in Lean\u2019, n.d.\n-/\n\n-- Exercise 1\n--\n-- Go back to the exercises in Chapter 3 and Chapter 4 and redo as many as you\n-- can now with tactic proofs, using also `rw` and `simp` as appropriate.\nnamespace ex1\n\n-- Exercises 3.1\n\nsection ex3_1\n\nvariable (p q r : Prop)\n\n-- Commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := by\n  apply Iff.intro\n  \u00b7 intro \u27e8hp, hq\u27e9\n    exact \u27e8hq, hp\u27e9\n  \u00b7 intro \u27e8hq, hp\u27e9\n    exact \u27e8hp, hq\u27e9\n\nexample : p \u2228 q \u2194 q \u2228 p := by\n  apply Iff.intro\n  \u00b7 intro\n    | Or.inl hp => exact Or.inr hp\n    | Or.inr hq => exact Or.inl hq\n  \u00b7 intro\n    | Or.inl hq => exact Or.inr hq\n    | Or.inr hp => exact Or.inl hp\n\n-- Associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := by\n  apply Iff.intro\n  \u00b7 intro \u27e8\u27e8hp, hq\u27e9, hr\u27e9\n    exact \u27e8hp, hq, hr\u27e9\n  \u00b7 intro \u27e8hp, hq, hr\u27e9\n    exact \u27e8\u27e8hp, hq\u27e9, hr\u27e9\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := by\n  apply Iff.intro\n  \u00b7 intro\n    | Or.inl (Or.inl hp) => exact Or.inl hp\n    | Or.inl (Or.inr hq) => exact Or.inr (Or.inl hq)\n    | Or.inr         hr  => exact Or.inr (Or.inr hr)\n  \u00b7 intro\n    | Or.inl         hp  => exact Or.inl (Or.inl hp)\n    | Or.inr (Or.inl hq) => exact Or.inl (Or.inr hq)\n    | Or.inr (Or.inr hr) => exact Or.inr hr\n\n-- Distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by\n  apply Iff.intro\n  \u00b7 intro\n    | \u27e8hp, Or.inl hq\u27e9 => exact Or.inl \u27e8hp, hq\u27e9\n    | \u27e8hp, Or.inr hr\u27e9 => exact Or.inr \u27e8hp, hr\u27e9\n  \u00b7 intro\n    | Or.inl \u27e8hp, hq\u27e9 => exact \u27e8hp, Or.inl hq\u27e9\n    | Or.inr \u27e8hp, hr\u27e9 => exact \u27e8hp, Or.inr hr\u27e9\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := by\n  apply Iff.intro\n  \u00b7 intro\n    | Or.inl      hp  => exact \u27e8Or.inl hp, Or.inl hp\u27e9\n    | Or.inr \u27e8hq, hr\u27e9 => exact \u27e8Or.inr hq, Or.inr hr\u27e9\n  \u00b7 intro\n    | \u27e8Or.inl hp,         _\u27e9 => exact Or.inl hp\n    | \u27e8Or.inr  _, Or.inl hp\u27e9 => exact Or.inl hp\n    | \u27e8Or.inr hq, Or.inr hr\u27e9 => exact Or.inr \u27e8hq, hr\u27e9\n\n-- Other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := by\n  apply Iff.intro\n  \u00b7 intro h \u27e8hp, hq\u27e9\n    exact h hp hq\n  \u00b7 intro h hp hq\n    exact h \u27e8hp, hq\u27e9\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := by\n  apply Iff.intro\n  \u00b7 intro h\n    apply And.intro\n    \u00b7 intro hp\n      exact h (Or.inl hp)\n    \u00b7 intro hq\n      exact h (Or.inr hq)\n  \u00b7 intro \u27e8hpr, hqr\u27e9 h\n    apply Or.elim h\n    \u00b7 intro hp\n      exact hpr hp\n    \u00b7 intro hq\n      exact hqr hq\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := by\n  apply Iff.intro\n  \u00b7 intro h\n    apply And.intro\n    \u00b7 intro hp\n      exact h (Or.inl hp)\n    \u00b7 intro hq\n      exact h (Or.inr hq)\n  \u00b7 intro \u27e8np, nq\u27e9\n    intro\n    | Or.inl hp => exact absurd hp np\n    | Or.inr hq => exact absurd hq nq\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := by\n  intro\n  | Or.inl np => intro h; exact absurd h.left np\n  | Or.inr nq => intro h; exact absurd h.right nq\n\nexample : \u00ac(p \u2227 \u00acp) := by\n  intro \u27e8hp, np\u27e9\n  exact absurd hp np\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := by\n  intro \u27e8hp, nq\u27e9 h\n  exact absurd (h hp) nq\n\nexample : \u00acp \u2192 (p \u2192 q) := by\n  intro np hp\n  exact absurd hp np\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := by\n  intro\n  | Or.inl np => intro hp; exact absurd hp np\n  | Or.inr hq => exact fun _ => hq\n\nexample : p \u2228 False \u2194 p := by\n  apply Iff.intro\n  \u00b7 intro\n    | Or.inl hp => exact hp\n    | Or.inr ff => exact False.elim ff\n  \u00b7 intro hp\n    exact Or.inl hp\n\nexample : p \u2227 False \u2194 False := by\n  apply Iff.intro\n  \u00b7 intro \u27e8_, ff\u27e9\n    exact ff\n  \u00b7 intro ff\n    exact False.elim ff\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := by\n  intro hpq nq hp\n  exact absurd (hpq hp) nq\n\nend ex3_1\n\n-- Exercises 3.2\n\nsection ex3_2\n\nopen Classical\n\nvariable (p q r s : Prop)\n\nexample (hp : p) : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := by\n  intro h\n  apply (h hp).elim\n  \u00b7 intro hr\n    exact Or.inl (fun _ => hr)\n  \u00b7 intro hs\n    exact Or.inr (fun _ => hs)\n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := by\n  intro h\n  apply (em p).elim\n  \u00b7 intro hp\n    apply (em q).elim\n    \u00b7 intro hq\n      exact False.elim (h \u27e8hp, hq\u27e9)\n    \u00b7 intro nq\n      exact Or.inr nq\n  \u00b7 intro np\n    exact Or.inl np\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := by\n  intro h\n  apply And.intro\n  \u00b7 apply byContradiction\n    intro np\n    apply h\n    intro hp\n    exact absurd hp np\n  \u00b7 intro hq\n    apply h\n    intro _\n    exact hq\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := by\n  intro hpq\n  apply (em p).elim\n  \u00b7 intro hp\n    exact Or.inr (hpq hp)\n  \u00b7 intro np\n    exact Or.inl np\n\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := by\n  intro hqp hp\n  apply byContradiction\n  intro nq\n  exact absurd hp (hqp nq)\n\nexample : p \u2228 \u00acp := by apply em\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := by\n  intro h\n  apply (em p).elim\n  \u00b7 intro hp\n    exact hp\n  \u00b7 intro np\n    apply h\n    intro hp\n    exact absurd hp np\n\nend ex3_2\n\n-- Exercises 3.3\n\nsection ex3_3\n\nvariable (p : Prop)\n\nexample (hp : p) : \u00ac(p \u2194 \u00acp) := by\n  intro h\n  exact absurd hp (h.mp hp)\n\nend ex3_3\n\n-- Exercises 4.1\n\nsection ex4_1\n\nvariable (\u03b1 : Type _)\nvariable (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := by\n  apply Iff.intro\n  \u00b7 intro h\n    apply And.intro\n    \u00b7 intro hx; exact And.left (h hx)\n    \u00b7 intro hx; exact And.right (h hx)\n  \u00b7 intro h hx\n    have lhs : \u2200 (x : \u03b1), p x := And.left h\n    have rhs : \u2200 (x : \u03b1), q x := And.right h\n    exact \u27e8lhs hx, rhs hx\u27e9\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := by\n  intro h\u2081 h\u2082 hx\n  exact h\u2081 hx (h\u2082 hx)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := by\n  intro\n  | Or.inl h => intro hx; exact Or.inl (h hx)\n  | Or.inr h => intro hx; exact Or.inr (h hx)\n\nend ex4_1\n\n-- Exercises 4.2\n\nsection ex4_2\n\nvariable (\u03b1 : Type _)\nvariable (p q : \u03b1 \u2192 Prop)\nvariable (r : Prop)\n\nexample : \u03b1 \u2192 ((\u2200 _ : \u03b1, r) \u2194 r) := by\n  intro ha\n  apply Iff.intro\n  \u00b7 intro har\n    apply har\n    exact ha\n  \u00b7 intro hr _\n    exact hr\n\nsection\n\nopen Classical\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r := by\n  apply Iff.intro\n  \u00b7 intro h\n    apply (em r).elim\n    \u00b7 intro hr\n      exact Or.inr hr\n    \u00b7 intro nr\n      apply Or.inl\n      \u00b7 intro hx\n        apply (h hx).elim\n        \u00b7 exact id\n        \u00b7 intro hr\n          exact absurd hr nr\n  \u00b7 intro h\u2081 hx\n    apply h\u2081.elim\n    \u00b7 intro h\u2082\n      exact Or.inl (h\u2082 hx)\n    \u00b7 intro hr\n      exact Or.inr hr\n\nend\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) := by\n  apply Iff.intro\n  \u00b7 intro h hr hx\n    exact h hx hr\n  \u00b7 intro h hx hr\n    exact h hr hx\n\nend ex4_2\n\n-- Exercises 4.3\n\nsection ex4_3\n\nopen Classical\n\nvariable (men : Type _)\nvariable (barber : men)\nvariable (shaves : men \u2192 men \u2192 Prop)\n\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : False := by\n  apply (em (shaves barber barber)).elim\n  \u00b7 intro hb\n    exact absurd hb ((h barber).mp hb)\n  \u00b7 intro nb\n    exact absurd ((h barber).mpr nb) nb\n\nend ex4_3\n\n-- Exercises 4.5\n\nsection ex4_5\n\nopen Classical\n\nvariable (\u03b1 : Type _)\nvariable (p q : \u03b1 \u2192 Prop)\nvariable (r s : Prop)\n\nexample : (\u2203 _ : \u03b1, r) \u2192 r := by\n  intro \u27e8_, hr\u27e9\n  exact hr\n\nexample (a : \u03b1) : r \u2192 (\u2203 _ : \u03b1, r) := by\n  intro hr\n  exact \u27e8a, hr\u27e9\n\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := by\n  apply Iff.intro\n  \u00b7 intro \u27e8hx, hp, hr\u27e9\n    exact \u27e8\u27e8hx, hp\u27e9, hr\u27e9\n  \u00b7 intro \u27e8\u27e8hx, hp\u27e9, hr\u27e9\n    exact \u27e8hx, hp, hr\u27e9\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := by\n  apply Iff.intro\n  \u00b7 intro\n    | \u27e8hx, Or.inl hp\u27e9 => exact Or.inl \u27e8hx, hp\u27e9\n    | \u27e8hx, Or.inr hq\u27e9 => exact Or.inr \u27e8hx, hq\u27e9\n  \u00b7 intro\n    | Or.inl \u27e8hx, hp\u27e9 => exact \u27e8hx, Or.inl hp\u27e9\n    | Or.inr \u27e8hx, hq\u27e9 => exact \u27e8hx, Or.inr hq\u27e9\n\nexample : (\u2200 x, p x) \u2194 \u00ac(\u2203 x, \u00acp x) := by\n  apply Iff.intro\n  \u00b7 intro ha \u27e8hx, np\u27e9\n    exact absurd (ha hx) np\n  \u00b7 intro he hx\n    apply byContradiction\n    intro np\n    exact he \u27e8hx, np\u27e9\n\nexample : (\u2203 x, p x) \u2194 \u00ac(\u2200 x, \u00acp x) := by\n  apply Iff.intro\n  \u00b7 intro \u27e8hx, hp\u27e9 h\n    exact absurd hp (h hx)\n  \u00b7 intro h\u2081\n    apply byContradiction\n    intro h\u2082\n    apply h\u2081\n    intro hx hp\n    exact h\u2082 \u27e8hx, hp\u27e9\n\nexample : (\u00ac\u2203 x, p x) \u2194 (\u2200 x, \u00acp x) := by\n  apply Iff.intro\n  \u00b7 intro h hx hp\n    exact h \u27e8hx, hp\u27e9\n  \u00b7 intro h \u27e8hx, hp\u27e9\n    exact absurd hp (h hx)\n\ntheorem forall_negation : (\u00ac\u2200 x, p x) \u2194 (\u2203 x, \u00acp x) := by\n  apply Iff.intro\n  \u00b7 intro h\u2081\n    apply byContradiction\n    intro h\u2082\n    exact h\u2081 (fun (x : \u03b1) => by\n      apply byContradiction\n      intro np\n      exact h\u2082 \u27e8x, np\u27e9)\n  \u00b7 intro \u27e8hx, np\u27e9 h\n    exact absurd (h hx) np\n\nexample : (\u00ac\u2200 x, p x) \u2194 (\u2203 x, \u00acp x) := forall_negation \u03b1 p\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := by\n  apply Iff.intro\n  \u00b7 intro h \u27e8hx, hp\u27e9\n    exact h hx hp\n  \u00b7 intro h hx hp\n    exact h \u27e8hx, hp\u27e9\n\nexample (a : \u03b1) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := by\n  apply Iff.intro\n  \u00b7 intro \u27e8hx, hp\u27e9 h\n    apply hp\n    exact h hx\n  \u00b7 intro h\u2081\n    apply (em (\u2200 x, p x)).elim\n    \u00b7 intro h\u2082\n      exact \u27e8a, fun _ => h\u2081 h\u2082\u27e9\n    \u00b7 intro h\u2082\n      have \u27e8hx, np\u27e9 : (\u2203 x, \u00acp x) := (forall_negation \u03b1 p).mp h\u2082\n      exact \u27e8hx, fun hp => absurd hp np\u27e9\n\nexample (a : \u03b1) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := by\n  apply Iff.intro\n  \u00b7 intro \u27e8hx, h\u27e9 hr\n    exact \u27e8hx, h hr\u27e9\n  \u00b7 intro h\n    apply (em r).elim\n    \u00b7 intro hr\n      have \u27e8hx, hp\u27e9 := h hr\n      exact \u27e8hx, fun _ => hp\u27e9\n    \u00b7 intro nr\n      exact \u27e8a, fun hr => absurd hr nr\u27e9\n\nend ex4_5\n\nend ex1\n\n-- Exercise 2\n--\n-- Use tactic combinators to obtain a one line proof of the following:\nnamespace ex2\n\nexample (p q r : Prop) (hp : p) : (p \u2228 q \u2228 r) \u2227 (q \u2228 p \u2228 r) \u2227 (q \u2228 r \u2228 p) :=\nby simp [*]\n\nend ex2\n", "meta": {"author": "jrpotter", "repo": "bookshelf", "sha": "aa59363e7402c30f227e38948150f9592820e532", "save_path": "github-repos/lean/jrpotter-bookshelf", "path": "github-repos/lean/jrpotter-bookshelf/bookshelf-aa59363e7402c30f227e38948150f9592820e532/theorem-proving-in-lean/TheoremProvingInLean/Exercises5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7334625076330812}}
{"text": "/-\nCopyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mathieu Guay-Paquet\n-/\nimport order.ideal\n\n/-!\n# Order filters\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections\nrequire more structure, such as a bottom element, a top element, or\na join-semilattice structure.\n\n- `order.pfilter P`: The type of nonempty, downward directed, upward closed\n               subsets of `P`. This is dual to `order.ideal`, so it\n               simply wraps `order.ideal P\u1d52\u1d48`.\n- `order.is_pfilter P`: a predicate for when a `set P` is a filter.\n\n\nNote the relation between `order/filter` and `order/pfilter`: for any\ntype `\u03b1`, `filter \u03b1` represents the same mathematical object as\n`pfilter (set \u03b1)`.\n\n## References\n\n- <https://en.wikipedia.org/wiki/Filter_(mathematics)>\n\n## Tags\n\npfilter, filter, ideal, dual\n\n-/\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- A filter on a preorder `P` is a subset of `P` that is\n  - nonempty\n  - downward directed\n  - upward closed. -/\nstructure pfilter (P) [preorder P] :=\n(dual : ideal P\u1d52\u1d48)\n\n/-- A predicate for when a subset of `P` is a filter. -/\ndef is_pfilter [preorder P] (F : set P) : Prop :=\n@is_ideal P\u1d52\u1d48 _ F\n\n\n\n/-- Create an element of type `order.pfilter` from a set satisfying the predicate\n`order.is_pfilter`. -/\ndef is_pfilter.to_pfilter [preorder P] {F : set P} (h : is_pfilter F) : pfilter P :=\n\u27e8h.to_ideal\u27e9\n\nnamespace pfilter\n\nsection preorder\nvariables [preorder P] {x y : P} (F s t : pfilter P)\n\ninstance [inhabited P] : inhabited (pfilter P) := \u27e8\u27e8default\u27e9\u27e9\n\n/-- A filter on `P` is a subset of `P`. -/\ninstance : has_coe (pfilter P) (set P) := \u27e8\u03bb F, F.dual.carrier\u27e9\n\n/-- For the notation `x \u2208 F`. -/\ninstance : has_mem P (pfilter P) := \u27e8\u03bb x F, x \u2208 (F : set P)\u27e9\n\n@[simp] lemma mem_coe : x \u2208 (F : set P) \u2194 x \u2208 F := iff_of_eq rfl\n\nlemma is_pfilter : is_pfilter (F : set P) :=\nF.dual.is_ideal\n\nlemma nonempty : (F : set P).nonempty := F.dual.nonempty\n\nlemma directed : directed_on (\u2265) (F : set P) := F.dual.directed\n\nlemma mem_of_le {F : pfilter P} : x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F := \u03bb h, F.dual.lower h\n\n/-- Two filters are equal when their underlying sets are equal. -/\n@[ext] lemma ext (h : (s : set P) = t) : s = t :=\nby { cases s, cases t, exact congr_arg _ (ideal.ext h) }\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (pfilter P) := partial_order.lift coe ext\n\n@[trans] lemma mem_of_mem_of_le {F G : pfilter P} : x \u2208 F \u2192 F \u2264 G \u2192 x \u2208 G :=\nideal.mem_of_mem_of_le\n\n/-- The smallest filter containing a given element. -/\ndef principal (p : P) : pfilter P := \u27e8ideal.principal p\u27e9\n\n@[simp] lemma mem_def (x : P) (I : ideal P\u1d52\u1d48) :\n  x \u2208 (\u27e8I\u27e9 : pfilter P) \u2194 order_dual.to_dual x \u2208 I :=\niff.rfl\n\n@[simp] lemma principal_le_iff {F : pfilter P} : principal x \u2264 F \u2194 x \u2208 F :=\nideal.principal_le_iff\n\n@[simp] lemma mem_principal : x \u2208 principal y \u2194 y \u2264 x :=\nideal.mem_principal -- defeq abuse\n\nlemma antitone_principal : antitone (principal : P \u2192 pfilter P) := by delta antitone; simp\n\nlemma principal_le_principal_iff {p q : P} : principal q \u2264 principal p \u2194 p \u2264 q :=\nby simp\n\nend preorder\n\nsection order_top\nvariables [preorder P] [order_top P] {F : pfilter P}\n\n/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/\n@[simp] lemma top_mem : \u22a4 \u2208 F := ideal.bot_mem _\n\n/-- There is a bottom filter when `P` has a top element. -/\ninstance : order_bot (pfilter P) :=\n{ bot := \u27e8\u22a5\u27e9,\n  bot_le := \u03bb F, (bot_le : \u22a5 \u2264 F.dual) }\n\nend order_top\n\n/-- There is a top filter when `P` has a bottom element. -/\ninstance {P} [preorder P] [order_bot P] : order_top (pfilter P) :=\n{ top := \u27e8\u22a4\u27e9,\n  le_top := \u03bb F, (le_top : F.dual \u2264 \u22a4) }\n\nsection semilattice_inf\nvariables [semilattice_inf P] {x y : P} {F : pfilter P}\n\n/-- A specific witness of `pfilter.directed` when `P` has meets. -/\nlemma inf_mem (hx : x \u2208 F) (hy : y \u2208 F) : x \u2293 y \u2208 F := ideal.sup_mem hx hy\n\n@[simp] lemma inf_mem_iff : x \u2293 y \u2208 F \u2194 x \u2208 F \u2227 y \u2208 F :=\nideal.sup_mem_iff\n\nend semilattice_inf\n\nsection complete_semilattice_Inf\n\nvariables [complete_semilattice_Inf P] {F : pfilter P}\n\nlemma Inf_gc : galois_connection (\u03bb x, order_dual.to_dual (principal x))\n  (\u03bb F, Inf (order_dual.of_dual F : pfilter P)) :=\n\u03bb x F, by { simp, refl }\n\n/-- If a poset `P` admits arbitrary `Inf`s, then `principal` and `Inf` form a Galois coinsertion. -/\ndef Inf_gi : galois_coinsertion (\u03bb x, order_dual.to_dual (principal x))\n  (\u03bb F, Inf (order_dual.of_dual F : pfilter P)) :=\n{ choice := \u03bb F _, Inf (id F : pfilter P),\n  gc := Inf_gc,\n  u_l_le := \u03bb s, Inf_le $ mem_principal.2 $ le_refl s,\n  choice_eq := \u03bb _ _, rfl }\n\nend complete_semilattice_Inf\n\nend pfilter\n\nend order\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/pfilter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.7334625044168325}}
{"text": "import game.limits.L01defs\nimport game.limits.seq_lim_add\n\nnamespace xena -- hide\n\nnotation `|` x `|` := abs x -- hide\n\n/-\nA basic result for working with sequences.\n-/\n\n/- Lemma\nIf $\\lim_{n \\to \\infty} a_n = \\alpha$ and $c \\in \\mathbb{R}$, then\n $\\lim_{n \\to \\infty} (c \\cdot a_n) = c \\cdot \\alpha$\n-/\nlemma lim_times_const (a : \u2115 \u2192 \u211d) (\u03b1 c : \u211d) (hL : is_limit a \u03b1) : \n    is_limit (\u03bb n, c * (a n)) (c*\u03b1) :=\nbegin\n  rcases lt_trichotomy c 0 with hc | hc | hc,\n  {\n    intros \u03b5 h\u03b5,\n    set e := \u03b5 / |c| with he,\n    have cnz : c \u2260 0, linarith,\n    have habsc := abs_pos_iff.mpr cnz,\n    have he_pos := div_pos h\u03b5 habsc,\n    cases hL e he_pos with M hM,\n    use M, intros n hn, rw he at hM, simp,\n    have H := hM n hn,\n    have G := (lt_div_iff' habsc).mp H,\n    have F := abs_mul c,\n    set b := a n - \u03b1 with hb,\n    have E := F b,\n    rw hb at E,\n    have D := mul_sub c (a n) \u03b1,\n    rw D at E, \n    rw \u2190 hb at E,\n    linarith,\n  },\n  {\n    intros \u03b5 h\u03b5,\n    cases hL \u03b5 h\u03b5 with M hM,\n    use M, intros n hn, simp,\n    have H : c * (a n) = 0, norm_num, left, exact hc, rw H,\n    have G : c * \u03b1 = 0, norm_num, left, exact hc, rw G,\n    norm_num, exact h\u03b5,\n  },\n  { -- this can be merged with first case\n    intros \u03b5 h\u03b5,\n    set e := \u03b5 / c with he,\n    have he_pos := div_pos h\u03b5 hc,\n    cases hL e he_pos with M hM,\n    use M, intros n hn, rw he at hM, simp,\n    have H := hM n hn,\n    have G := (lt_div_iff' hc).mp H,\n    have F := abs_mul c,\n    set b := a n - \u03b1 with hb,\n    have E := F b,\n    have D : |c| = c, exact abs_of_pos hc,\n    rw D at E, rw hb at E,\n    have C := mul_sub c (a n) \u03b1,\n    rw C at E, \n    rw \u2190 hb at E,\n    linarith,\n  }, \n  done\nend\n\nend xena -- hide\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/limits/seq_limitTimesConst.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7334625006289451}}
{"text": "/-\nCOMP2009-ACE\n\nExercise 05 (Natural numbers)\n\n    This exercise has 2 parts both count for 50%.\n\n    In the first part the goal is to complete the proof that the\n    natural numbers with addition and multiplication form a\n    semiring. I include the proof the addition forms a commutative\n    monoid (which we have done in the lecture.\n\n    You are not supposed to use the ring tactic for the first part\n    (otherwise it would be no challenge).\n\n    Yes, you may need some additional lemmas.\n\n    In the 2nd part you should show that \u2264 is anti-symmetric. I\n    include the proofs (from the lecture) that it is reflexive and\n    transitive. You are allowed to use the ring tactic for this part. \n    (but note that you have to create a lean project to access the\n    tactic library).\n\n    You create a lean project using \n    leanproject new my_project\n    which creates a folder my_project. You need to stire the exercise\n    in my_project/src\n    See https://leanprover-community.github.io/install/project.html\n    for details.\n\n    However, if you work with the web interface you don't need to\n    create a project - ity should work out of the box.\n\n    Please only submit the lean file not the whole project directory.\n\n-/\nimport tactic -- will fail if you haven't created a project.\nset_option pp.structure_projections false\n\nnamespace ex05_01\n\nopen nat\n\n-- definition of addition:\ndef add : \u2115 \u2192 \u2115 \u2192 \u2115 \n| n zero     := n\n| n (succ m) := succ (add n m)\n\nlocal notation m + n := add m n\n\n-- have shown that it is a commutative monoid\n\ntheorem add_rneutr : \u2200 n : \u2115, n + 0 = n :=\nbegin\n  assume n,\n  reflexivity,\nend\n\ntheorem add_lneutr : \u2200 n : \u2115, 0 + n  = n :=\nbegin\n  assume n,\n  induction n with n' ih,\n  reflexivity,\n  dsimp [(+),add],\n  rewrite ih,\nend\n\ntheorem add_assoc : \u2200 l m n : \u2115 , (l + m) + n = l + (m + n) :=\nbegin\n  assume l m n,\n  induction n with n' ih,\n  reflexivity,\n  dsimp [(+),add],\n  rewrite ih,\nend\n\nlemma add_succ_lem : \u2200 m n : \u2115, succ m + n = succ (m + n) :=\nbegin\n  assume m n,\n  induction n with n' ih,\n  reflexivity,\n  apply congr_arg succ,\n  exact ih,\nend\n\ntheorem add_comm : \u2200 m n : \u2115 , m + n = n + m :=\nbegin\n  assume m n,\n  induction m with m' ih,\n  apply add_lneutr,\n  calc \n    succ m' + n = succ (m' + n) : by apply add_succ_lem\n    ... = succ (n + m') : by apply congr_arg succ; exact ih\n    ... = n + succ m' : by reflexivity,\nend\n\n-- now we define addition\n\n def mul : \u2115 \u2192 \u2115 \u2192 \u2115\n | m 0     := 0\n | m (succ n) := (mul m n) + m\n\n local notation m * n := mul m n\n\n-- and your task is to show that it is a commutative semiring, i.e.\n\ntheorem mult_rneutr : \u2200 n : \u2115, n * 1 = n :=\nbegin\n  assume n,\n  induction n with n' ih,\n  reflexivity,\n  dsimp[(*), mul],\n  apply add_lneutr,\nend\n\ntheorem mult_lneutr : \u2200 n : \u2115, 1 * n  = n :=\nbegin\n  assume n,\n  induction n with n' ih,\n  reflexivity,\n  apply (congr_arg succ),\n  rewrite ih,\n  reflexivity,\nend\n\ntheorem mult_zero_l : \u2200 n : \u2115 , 0 * n = 0 :=\nbegin\n  assume n,\n  induction n with n' ih,\n  reflexivity,\n  dsimp[(*), mul],\n  rewrite ih,\n  reflexivity,\nend \n\ntheorem mult_zero_r : \u2200 n : \u2115 , n * 0 = 0 :=\nbegin\n  assume n,\n  induction n with n' ih,\n  reflexivity,\n  dsimp[(*),mul],\n  reflexivity,\nend\n\n\ntheorem mult_distr_r :  \u2200 l m n : \u2115 , l * (m + n) = l * m + l * n :=\nbegin\n  assume l m n,\n  induction n with n' ih,\n  dsimp [(+),add],\n  apply congr_arg,\n  reflexivity,\n\n  induction l with l' ih2,\n  rewrite mult_zero_l,\n  rewrite mult_zero_l,\n  rewrite mult_zero_l,\n  reflexivity,\n\n  apply (congr_arg succ),\n  rewrite ih,\n  rewrite add_assoc,\nend\n\n\ntheorem mult_distr_l :  \u2200 l m n : \u2115 , (m + n) * l = m * l + n * l :=\nbegin\n  assume l m n,\n  induction l with l' ih3,\n  reflexivity,\n\n  dsimp[(*),mul],   \n  rewrite ih3,\n  \n  rewrite add_assoc,\n  rewrite (add_comm (n * l') (m + n)),\n  rewrite \u2190 add_assoc,\n  rewrite \u2190 add_assoc,\n  rewrite (add_comm (n * l') n),\n  rewrite \u2190 add_assoc,\nend\n\n\ntheorem mult_assoc : \u2200 l m n : \u2115 , (l * m) * n = l * (m * n) :=\nbegin\n  assume l m n,\n  induction n with n' ih2,\n  reflexivity,\n\n  induction l with l' ih,\n  rewrite mult_zero_l,\n  rewrite mult_zero_l,\n  rewrite mult_zero_l,\n\n  dsimp[(*), mul],\n  rewrite ih2,\n  rewrite mult_distr_r,\nend\n\nlemma helper : \u2200 m n :\u2115 , succ n * m = n * m + m  :=\nbegin\n  assume m n,\n  induction m with m' ih,\n  reflexivity,\n  dsimp[(*),mul],\n  apply congr_arg succ,\n  rewrite ih,\n  rewrite (add_comm  (n * m') m' ),\n  rewrite (add_comm (n * m' + n) m'),\n  rewrite \u2190 add_assoc,\nend\n\ntheorem mult_comm :  \u2200 m n : \u2115 , m * n = n * m :=\nbegin\n  assume m n,\n  induction n with n' ih,\n  dsimp[(*),mul],\n  rewrite mult_zero_l,\n  dsimp[(*),mul],\n  rewrite ih,\n  rewrite helper,\nend\n\nend ex05_01\n\nnamespace ex05_2\n-- part 2\n-- we define \u2264 as follows\nopen nat \n\ndef le(m n : \u2115) : Prop :=\n  \u2203 k : \u2115 , k + m = n\n\nlocal notation x \u2264 y := le x y\nlocal notation x \u2265 y := le y x\n\n-- and we have shown that it is a preorder, i.e. reflexive and transitive:\n-- note that we have used the ring tactic to do all the equational reasoning:\nexample : \u2200 m n : nat, succ m = succ n \u2192 m = n :=\nbegin\n  assume m n h,\n  injection h,\nend\n\ntheorem le_refl : \u2200 x : \u2115 , x \u2264 x :=\nbegin\n  assume x,\n  existsi 0,\n  ring,\nend\n\ntheorem le_trans : \u2200 x y z : \u2115 , x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z :=\nbegin\n  assume x y z xy yz,\n  cases xy with k p,\n  cases yz with l q,\n  existsi (k+l),\n  rewrite\u2190 q,\n  rewrite\u2190 p,\n  ring,\nend\n\n-- Your task is to show that \u2264 is antisymmetric, and hence a *partial order*\n-- you are allowed to use the ring tactic.\n-- Yes, you may need some lemmas!\naxiom add_succ_lem : \u2200 m n : \u2115, succ m + n = succ (m + n)\n\nlemma leq_meaning : \u2200 x  y :\u2115 , x \u2264 y \u2192 x =y \u2228 succ x \u2264  y :=\nbegin\n  assume x y yx,\n  dsimp[le]at yx,\n  cases yx with a h,\n  induction a with a' ih,\n  left,\n  rewrite \u2190 h,\n  ring,\n\n  right,\n  dsimp[le],\n  existsi a',\n  calc\n    a' + succ x = succ (a'+ x) : by reflexivity\n    ... = succ a' + x: by rewrite add_succ_lem\n    ... = y : by exact h,\nend\n\nlemma leq_absurd : \u2200 x:\u2115 , \u00ac (succ x \u2264 x) :=\nbegin\n  assume x,\n  assume h,\n  cases h with a g,\n  induction x with x' ih,\n  contradiction,\n  apply ih,\n  injection g,\nend\n\ntheorem anti_sym : \u2200 x y : \u2115 , x \u2264 y \u2192 y \u2264 x \u2192 x = y :=\nbegin\n  assume x y xy yx, \n  have aux : x =y \u2228 succ x \u2264  y,\n  apply leq_meaning,\n  exact xy,\n\n  cases aux,\n  exact aux,\n\n  have p : succ x \u2264 x,\n  apply le_trans,\n  exact aux,\n  exact yx,\n  have np : \u00ac (succ x \u2264 x),\n  apply leq_absurd,\n  contradiction,\nend\n\nend ex05_2", "meta": {"author": "kyrran", "repo": "Lean", "sha": "915f45d695eb01a80e58916f03e8f7c1e878be8b", "save_path": "github-repos/lean/kyrran-Lean", "path": "github-repos/lean/kyrran-Lean/Lean-915f45d695eb01a80e58916f03e8f7c1e878be8b/ex05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7334623559675625}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n\n! This file was ported from Lean 3 source module data.fintype.fin\n! leanprover-community/mathlib commit 759575657f189ccb424b990164c8b1fa9f55cdfe\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fin.Interval\n\n/-!\n# The structure of `Fintype (Fin n)`\n\nThis file contains some basic results about the `Fintype` instance for `Fin`,\nespecially properties of `Finset.univ : Finset (Fin n)`.\n-/\n\nopen Finset\n\nopen Fintype\n\nnamespace Fin\n\nvariable {\u03b1 \u03b2 : Type _} {n : \u2115}\n\ntheorem map_valEmbedding_univ : (Finset.univ : Finset (Fin n)).map Fin.valEmbedding = Iio n := by\n  ext\n  simp [orderIsoSubtype.symm.surjective.exists, OrderIso.symm]\n#align fin.map_subtype_embedding_univ Fin.map_valEmbedding_univ\n\n@[simp]\n\n\n@[simp]\ntheorem Iio_last_eq_map : Iio (Fin.last n) = Finset.univ.map Fin.castSucc.toEmbedding := by\n  apply Finset.map_injective Fin.valEmbedding\n  rw [Finset.map_map, Fin.map_valEmbedding_Iio, Fin.val_last]\n  exact map_valEmbedding_univ.symm\n#align fin.Iio_last_eq_map Fin.Iio_last_eq_map\n\n@[simp]\ntheorem Ioi_succ (i : Fin n) : Ioi i.succ = (Ioi i).map (Fin.succEmbedding _).toEmbedding := by\n  ext i\n  simp only [mem_filter, mem_Ioi, mem_map, mem_univ, true_and_iff, Function.Embedding.coeFn_mk,\n    exists_true_left]\n  constructor\n  \u00b7 refine' cases _ _ i\n    \u00b7 rintro \u27e8\u27e8\u27e9\u27e9\n    \u00b7 intro i hi\n      refine' \u27e8i, succ_lt_succ_iff.mp hi, rfl\u27e9\n  \u00b7 rintro \u27e8i, hi, rfl\u27e9\n    simpa\n#align fin.Ioi_succ Fin.Ioi_succ\n\n@[simp]\ntheorem Iio_castSucc (i : Fin n) : Iio (castSucc i) = (Iio i).map Fin.castSucc.toEmbedding := by\n  apply Finset.map_injective Fin.valEmbedding\n  rw [Finset.map_map, Fin.map_valEmbedding_Iio]\n  exact (Fin.map_valEmbedding_Iio i).symm\n#align fin.Iio_cast_succ Fin.Iio_castSucc\n\ntheorem card_filter_univ_succ' (p : Fin (n + 1) \u2192 Prop) [DecidablePred p] :\n    (univ.filter p).card = ite (p 0) 1 0 + (univ.filter (p \u2218 Fin.succ)).card := by\n  rw [Fin.univ_succ, filter_cons, card_disjUnion, filter_map, card_map]\n  split_ifs <;> simp\n#align fin.card_filter_univ_succ' Fin.card_filter_univ_succ'\n\ntheorem card_filter_univ_succ (p : Fin (n + 1) \u2192 Prop) [DecidablePred p] :\n    (univ.filter p).card =\n    if p 0 then (univ.filter (p \u2218 Fin.succ)).card + 1 else (univ.filter (p \u2218 Fin.succ)).card :=\n  (card_filter_univ_succ' p).trans (by split_ifs <;> simp [add_comm 1])\n#align fin.card_filter_univ_succ Fin.card_filter_univ_succ\n\ntheorem card_filter_univ_eq_vector_get_eq_count [DecidableEq \u03b1] (a : \u03b1) (v : Vector \u03b1 n) :\n    (univ.filter fun i => a = v.get i).card = v.toList.count a := by\n  induction' v using Vector.inductionOn with n x xs hxs\n  \u00b7 simp\n  \u00b7 simp_rw [card_filter_univ_succ', Vector.get_cons_zero, Vector.toList_cons, Function.comp,\n      Vector.get_cons_succ, hxs, List.count_cons', add_comm (ite (a = x) 1 0)]\n#align fin.card_filter_univ_eq_vector_nth_eq_count Fin.card_filter_univ_eq_vector_get_eq_count\n\nend Fin\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Fintype/Fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7334623389899412}}
{"text": "/-\n0. Read the class notes through Section \n3.7, Implication. It is important that \nyou do this before classes next week, as\nwe will move somewhat quickly through a\nfew of these chapters.\n\nTo complete the rest of this homework,\nsolve the problems given as specified,\nthen save and submit this file.\n-/\n\n\n/-\n1. \n\nShow that if you're given proofs\nof a = b and c = b you can construct\na proof of a = c. Do it by completing\nthe following function. Note that we\ncan use parenthesis to enclose terms \nthat appear within larger terms. This\nis often necessary to make sure that\nLean understands how you want to group\nthings. \n-/\n\ntheorem eq_snart { T : Type}\n             { a b c: T }\n             (ab: a = b)\n             (cb: c = b) : \n             a = c :=\neq.trans\n    ab \n    (eq.symm cb)\n\n/-\nNow, given the following assumptions, apply\nyour newly proved inference rule, eq.snart,\nto show that Harry = Bob. Yes: Once you've\nproved a theorem, you can apply it as if it\nwere a function, to arguments of the right\ntypes, to get a proof that you need. Try it.\n-/\n\naxiom Person : Type\naxioms Harry Bob Jose: Person\naxioms (hj : Harry = Bob) (jb : Jose = Bob)\nexample : Harry = Jose := eq_snart hj jb\n\n/-\n2. Use example to assert and then prove that if\na, b, c, and d are nats, and if you have proofs\nof a = b, b = c, and c = d, you can construct a\nproof of a = d. Put the proof in the placeholder\nbelow.\n\nHint: Equality propositions are types. Think of\nthe problem here as one of producing a function\nof the specific type. Use lambdas. We've gotten\nyou started. The first lambda \"assumes\" that a,\nb, c, and d are natural numbers. What's left to\ndo is to prove a function (yes, start with lambda)\nthat takes three arguments of the specified kinds \n(use lambda to give them names) and that finally\nproduces a result of the type at the end of the \nchain.\n-/\n\ntheorem transit : \n\u2200 a b c d : \u2115, \n    (a = b) \u2192 (b = c) \u2192 (c = d) \u2192 (a = d) \n:= \n    \u03bb a b c d,\n        \u03bb (ab: a = b),\n            \u03bb (bc: b = c),\n                \u03bb (cd: c = d),\n                    eq.trans (eq.trans ab bc) cd\n\n/-\n3. In the context of the axioms in the following\nnamespace, write an exact proof term to prove \nthat Yuanfang is friendly. Hint #1: Just apply \nthe relevant inference rule as a function to the\nright arguments. Hint #2: The direction in which\nan equality is written matters. If, for example,\nyou have a proof of x = y and you want to apply \nan inference rule that requires a proof of y = x,\nthen you need to find a way to get what you need\nfrom what you have to work with in your context.\n-/\n\naxioms Mary Yuanfang : Person\naxiom Friendly : Person \u2192 Prop\naxiom mf : Friendly Mary\naxiom yeqm : Yuanfang = Mary\nexample : Friendly Yuanfang :=\n    eq.subst (eq.symm yeqm) mf\n\n\n\n/-\n4. The subtitution rule for equality lets\nyou rewrite proof goals by substituting one \nterm for another, in a goal, as long as you \nalready have a proof that the two  terms \nare equal. The reasoning is that replacing \none term with another makes no difference to \nthe truth of a proposition if the two terms\nare equal. \n\nSuppose for example that you have a proof, \nh, of y = x (yes we can and do give names \nto proofs, as we consider them to be values), \nand a proof, y1, of y = 1, and that your \ngoal is to prove (x = 1). You can justify \nrewriting this goal as (y = 1), for which \nyou already have a proof, because you know \nthat y = x; so making this substitution \ndoesn't change the truth of the proposition. \n\nIn the tactic scripting libraries that Lean\nprovides, there is a tactic for rewriting a \ngoal in this way. If h is a proof of x = y,\nthen the tactic, \"rw h\" (\"rw\" is short for \n\"rewrite\") replaces all occurrences of x (the \nleft side of h) with y (it's right side).\n\nHere's an example.\n-/\n\ndef foo (x y : \u2115) (y1 : y = 1) (h: x = y) : (x = 1) :=\nbegin\nrewrite h,\nexact y1,\nend\n\n\n/-\nUse what you just learned to state and prove \nthe proposition that for any type, T, and for \nany objects, a, b, and c, of this type, if \n(a = b) and (b = c) then (c = a). Do this by\nfinishing off the tactic script that follows.  \nNote that to apply an inference rule within a\ntactic script you use the \"apply\" tactic. Read \nthe further explanation and hint that follow \nbefore attempting to solve this problem.\n-/\n\ndef ac (T : Type) (a b c : T) \n       (ab : a = b) (bc : b = c) \n    : (c = a) := \nbegin\nrewrite ab,\nexact eq.symm bc\nend\n\n/-\nNote that the \"foralls\" in the natural language \nstatement are represented in this code *not* by \nusing  \u2200 but by declaring them to be arguments \nto our function. If you can write a function of \nthe specified type then you have in effect proven\nthat for *any* T and any a, b, c, of type T, if \nif you also have a proof of a=b and a proof of \nb=c, then a value of type c=a can be constructed \nand returned. The reason this is true is that in\nLean all functions are total, as you now recall!\n\nKey hint: The tactic application \"rw h\" changes\nall occurrences of the left side of the equality\nh, in the goal, into what's on its right side. \nIf you want the rewriting to go from right to \nleft, use \"rw<-h\". When you're just about done, \ndon't be surprised if the rewrite tactic applies \nrfl automatically.\n-/", "meta": {"author": "justinqcai", "repo": "CS2102", "sha": "d309f0db3f1df52eb77206ee1e8665a3b49d7a0c", "save_path": "github-repos/lean/justinqcai-CS2102", "path": "github-repos/lean/justinqcai-CS2102/CS2102-d309f0db3f1df52eb77206ee1e8665a3b49d7a0c/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7334237948741229}}
{"text": "-- Si_es_menor_o_igual_entonces_la_diferencia_es_positiva.lean\n-- Si R es un anillo ordenado, entonces \u2200 a b \u2208 R, a \u2264 b \u2192 0 \u2264 b - a\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 26-octubre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si R es un anillo ordenado y a, b \u2208 R, entonces\n--    a \u2264 b \u2192 0 \u2264 b - a\n-- ----------------------------------------------------------------------\n\nimport algebra.order.ring\nvariables {R : Type*} [ordered_ring R]\nvariables a b : R\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a \u2264 b \u2192 0 \u2264 b - a :=\nbegin\n  intro h,\n  calc\n    0   = a - a : (sub_self a).symm\n    ... \u2264 b - a : sub_le_sub_right h a\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a \u2264 b \u2192 0 \u2264 b - a :=\n-- by library_search\nsub_nonneg.mpr\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a \u2264 b \u2192 0 \u2264 b - a :=\n-- by hint\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Si_es_menor_o_igual_entonces_la_diferencia_es_positiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7334237919763426}}
{"text": "/-\nCopyright (c) 2021 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport linear_algebra.determinant\n\n/-!\n# Orientations of modules and rays in modules\n\nThis file defines rays in modules and orientations of modules.\n\n## Main definitions\n\n* `module.ray` is a type for the equivalence class of nonzero vectors in a module with some\ncommon positive multiple.\n\n* `orientation` is a type synonym for `module.ray` for the case where the module is that of\nalternating maps from a module to its underlying ring.  An orientation may be associated with an\nalternating map or with a basis.\n\n* `module.oriented` is a type class for a choice of orientation of a module that is considered\nthe positive orientation.\n\n## Implementation notes\n\n`orientation` is defined for an arbitrary index type, but the main intended use case is when\nthat index type is a `fintype` and there exists a basis of the same cardinality.\n\n## References\n\n* https://en.wikipedia.org/wiki/Orientation_(vector_space)\n\n-/\n\nnoncomputable theory\n\nsection ordered_comm_semiring\n\nvariables (R : Type*) [ordered_comm_semiring R]\nvariables {M : Type*} [add_comm_monoid M] [module R M]\nvariables (\u03b9 : Type*) [decidable_eq \u03b9]\n\n/-- Two vectors are in the same ray if some positive multiples of them are equal (in the typical\ncase over a field, this means each is a positive multiple of the other).  Over a field, this\nis equivalent to `mul_action.orbit_rel`. -/\ndef same_ray (v\u2081 v\u2082 : M) : Prop :=\n\u2203 (r\u2081 r\u2082 : R), 0 < r\u2081 \u2227 0 < r\u2082 \u2227 r\u2081 \u2022 v\u2081 = r\u2082 \u2022 v\u2082\n\nvariables (M)\n\n/-- `same_ray` is symmetric. -/\nlemma symmetric_same_ray : symmetric (same_ray R : M \u2192 M \u2192 Prop) :=\n\u03bb _ _ \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9, \u27e8r\u2082, r\u2081, hr\u2082, hr\u2081, h.symm\u27e9\n\n/-- `same_ray` is transitive. -/\nlemma transitive_same_ray :\n  transitive (same_ray R : M \u2192 M \u2192 Prop) :=\n\u03bb _ _ _ \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u2081\u27e9 \u27e8r\u2083, r\u2084, hr\u2083, hr\u2084, h\u2082\u27e9,\n  \u27e8r\u2083 * r\u2081, r\u2082 * r\u2084, mul_pos hr\u2083 hr\u2081, mul_pos hr\u2082 hr\u2084,\n   by rw [mul_smul, mul_smul, h\u2081, \u2190h\u2082, smul_comm]\u27e9\n\n/-- `same_ray` is reflexive. -/\nlemma reflexive_same_ray [nontrivial R] :\n  reflexive (same_ray R : M \u2192 M \u2192 Prop) :=\n\u03bb _, \u27e81, 1, zero_lt_one, zero_lt_one, rfl\u27e9\n\n/-- `same_ray` is an equivalence relation. -/\nlemma equivalence_same_ray [nontrivial R] :\n  equivalence (same_ray R : M \u2192 M \u2192 Prop) :=\n\u27e8reflexive_same_ray R M, symmetric_same_ray R M, transitive_same_ray R M\u27e9\n\nvariables {R M}\n\n/-- A vector is in the same ray as a positive multiple of itself. -/\nlemma same_ray_pos_smul_right (v : M) {r : R} (h : 0 < r) : same_ray R v (r \u2022 v) :=\n\u27e8r, 1, h, let f := nontrivial_of_lt _ _ h in by exactI zero_lt_one, (one_smul _ _).symm\u27e9\n\n/-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/\nlemma same_ray.pos_smul_right {v\u2081 v\u2082 : M} {r : R} (h : same_ray R v\u2081 v\u2082) (hr : 0 < r) :\n  same_ray R v\u2081 (r \u2022 v\u2082) :=\ntransitive_same_ray R M h (same_ray_pos_smul_right v\u2082 hr)\n\n/-- A positive multiple of a vector is in the same ray as that vector. -/\nlemma same_ray_pos_smul_left (v : M) {r : R} (h : 0 < r) : same_ray R (r \u2022 v) v :=\n\u27e81, r, let f := nontrivial_of_lt _ _ h in by exactI zero_lt_one, h, one_smul _ _\u27e9\n\n/-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/\nlemma same_ray.pos_smul_left {v\u2081 v\u2082 : M} {r : R} (h : same_ray R v\u2081 v\u2082) (hr : 0 < r) :\n  same_ray R (r \u2022 v\u2081) v\u2082 :=\ntransitive_same_ray R M (same_ray_pos_smul_left v\u2081 hr) h\n\nvariables (R M)\n\n/-- The setoid of the `same_ray` relation for elements of a module. -/\ndef same_ray_setoid [nontrivial R] : setoid M :=\n{ r := \u03bb v\u2081 v\u2082, same_ray R v\u2081 v\u2082, iseqv := equivalence_same_ray R M }\n\n/-- Nonzero vectors, as used to define rays. -/\n@[reducible] def ray_vector := {v : M // v \u2260 0}\n\n/-- The setoid of the `same_ray` relation for the subtype of nonzero vectors. -/\ndef ray_vector.same_ray_setoid [nontrivial R] : setoid (ray_vector M) :=\n(same_ray_setoid R M).comap coe\n\nlocal attribute [instance] ray_vector.same_ray_setoid\n\nvariables {R M}\n\n/-- Equivalence of nonzero vectors, in terms of same_ray. -/\nlemma equiv_iff_same_ray [nontrivial R] (v\u2081 v\u2082 : ray_vector M) :\n  v\u2081 \u2248 v\u2082 \u2194 same_ray R (v\u2081 : M) v\u2082 :=\niff.rfl\n\nvariables (R M)\n\n/-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/\n@[nolint has_inhabited_instance]\ndef module.ray [nontrivial R] := quotient (ray_vector.same_ray_setoid R M)\n\n/-- An orientation of a module, intended to be used when `\u03b9` is a `fintype` with the same\ncardinality as a basis. -/\nabbreviation orientation [nontrivial R] := module.ray R (alternating_map R M R \u03b9)\n\n/-- A type class fixing an orientation of a module. -/\nclass module.oriented [nontrivial R] :=\n(positive_orientation : orientation R M \u03b9)\n\nvariables {M}\n\n/-- The ray given by a nonzero vector. -/\nprotected def ray_of_ne_zero [nontrivial R] (v : M) (h : v \u2260 0) : module.ray R M :=\n\u27e6\u27e8v, h\u27e9\u27e7\n\n/-- An induction principle for `module.ray`, used as `induction x using module.ray.ind`. -/\nlemma module.ray.ind [nontrivial R] {C : module.ray R M \u2192 Prop}\n  (h : \u03a0 v (hv : v \u2260 0), C (ray_of_ne_zero R v hv)) (x : module.ray R M) : C x :=\nquotient.ind (subtype.rec $ by exact h) x\n\n/-- The rays given by two nonzero vectors are equal if and only if those vectors\nsatisfy `same_ray`. -/\nlemma ray_eq_iff [nontrivial R] {v\u2081 v\u2082 : M} (hv\u2081 : v\u2081 \u2260 0) (hv\u2082 : v\u2082 \u2260 0) :\n  ray_of_ne_zero R _ hv\u2081 = ray_of_ne_zero R _ hv\u2082 \u2194 same_ray R v\u2081 v\u2082 :=\nquotient.eq\n\nvariables {R}\n\n/-- The ray given by a positive multiple of a nonzero vector. -/\n@[simp] lemma ray_pos_smul [nontrivial R] {v : M} (h : v \u2260 0) {r : R} (hr : 0 < r)\n  (hrv : r \u2022 v \u2260 0) : ray_of_ne_zero R _ hrv = ray_of_ne_zero R _ h :=\nbegin\n  rw ray_eq_iff,\n  exact same_ray_pos_smul_left v hr\nend\n\nnamespace module.ray\n\n/-- An arbitrary `ray_vector` giving a ray. -/\ndef some_ray_vector [nontrivial R] (x : module.ray R M) : ray_vector M :=\nquotient.out x\n\n/-- The ray of `some_ray_vector`. -/\n@[simp] lemma some_ray_vector_ray [nontrivial R] (x : module.ray R M) :\n  (\u27e6x.some_ray_vector\u27e7 : module.ray R M) = x :=\nquotient.out_eq _\n\n/-- An arbitrary nonzero vector giving a ray. -/\ndef some_vector [nontrivial R] (x : module.ray R M) : M :=\nx.some_ray_vector\n\n/-- `some_vector` is nonzero. -/\n@[simp] lemma some_vector_ne_zero [nontrivial R] (x : module.ray R M) : x.some_vector \u2260 0 :=\nx.some_ray_vector.property\n\n/-- The ray of `some_vector`. -/\n@[simp] lemma some_vector_ray [nontrivial R] (x : module.ray R M) :\n  ray_of_ne_zero R _ x.some_vector_ne_zero = x :=\n(congr_arg _ (subtype.coe_eta _ _) : _).trans x.out_eq\n\nend module.ray\n\nend ordered_comm_semiring\n\nsection ordered_comm_ring\n\nlocal attribute [instance] ray_vector.same_ray_setoid\n\nvariables {R : Type*} [ordered_comm_ring R]\nvariables {M : Type*} [add_comm_group M] [module R M]\n\n/-- If two vectors are in the same ray, so are their negations. -/\nlemma same_ray.neg {v\u2081 v\u2082 : M} : same_ray R v\u2081 v\u2082 \u2192 same_ray R (-v\u2081) (-v\u2082) :=\n\u03bb \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9, \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, by rwa [smul_neg, smul_neg, neg_inj]\u27e9\n\n/-- `same_ray.neg` as an `iff`. -/\n@[simp] lemma same_ray_neg_iff {v\u2081 v\u2082 : M} : same_ray R (-v\u2081) (-v\u2082) \u2194 same_ray R v\u2081 v\u2082 :=\n\u27e8\u03bb h, by simpa only [neg_neg] using h.neg, same_ray.neg\u27e9\n\nlemma same_ray_neg_swap {v\u2081 v\u2082 : M} : same_ray R (-v\u2081) v\u2082 \u2194 same_ray R v\u2081 (-v\u2082) :=\n\u27e8\u03bb h, by simpa only [neg_neg] using h.neg, \u03bb h, by simpa only [neg_neg] using h.neg\u27e9\n\n/-- If a vector is in the same ray as its negation, that vector is zero. -/\nlemma eq_zero_of_same_ray_self_neg [no_zero_smul_divisors R M] {v\u2081 : M} (h : same_ray R v\u2081 (-v\u2081)) :\n  v\u2081 = 0 :=\nbegin\n  rcases h with \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9,\n  rw [smul_neg, \u2190neg_smul, \u2190sub_eq_zero, \u2190sub_smul, sub_neg_eq_add, smul_eq_zero] at h,\n  exact h.resolve_left (add_pos hr\u2081 hr\u2082).ne',\nend\n\nnamespace ray_vector\n\nvariables {R}\n\n/-- Negating a nonzero vector. -/\ninstance : has_neg (ray_vector M) := \u27e8\u03bb v, \u27e8-v, neg_ne_zero.2 v.prop\u27e9\u27e9\n\n/-- Negating a nonzero vector commutes with coercion to the underlying module. -/\n@[simp, norm_cast] lemma coe_neg (v : ray_vector M) : \u2191(-v) = -(v : M) := rfl\n\n/-- Negating a nonzero vector twice produces the original vector. -/\n@[simp] protected lemma neg_neg (v : ray_vector M) : -(-v) = v :=\nby rw [subtype.ext_iff, coe_neg, coe_neg, neg_neg]\n\nvariables (R)\n\n/-- If two nonzero vectors are equivalent, so are their negations. -/\n@[simp] lemma equiv_neg_iff [nontrivial R] (v\u2081 v\u2082 : ray_vector M) : -v\u2081 \u2248 -v\u2082 \u2194 v\u2081 \u2248 v\u2082 :=\nby rw [equiv_iff_same_ray, equiv_iff_same_ray, coe_neg, coe_neg, same_ray_neg_iff]\n\nend ray_vector\n\nvariables (R)\n\n/-- Negating a ray. -/\ninstance [nontrivial R] : has_neg (module.ray R M) :=\n\u27e8quotient.map (\u03bb v, -v) (\u03bb v\u2081 v\u2082, (ray_vector.equiv_neg_iff R v\u2081 v\u2082).2)\u27e9\n\n/-- The ray given by the negation of a nonzero vector. -/\nlemma ray_neg [nontrivial R] (v : M) (h : v \u2260 0) :\n  ray_of_ne_zero R _ (show -v \u2260 0, by rw neg_ne_zero; exact h) = -(ray_of_ne_zero R _ h) :=\nrfl\n\nnamespace module.ray\n\nvariables {R}\n\n/-- Negating a ray twice produces the original ray. -/\n@[simp] protected lemma neg_neg [nontrivial R] (x : module.ray R M) : -(-x) = x :=\nquotient.ind (\u03bb a, congr_arg quotient.mk $ ray_vector.neg_neg _) x\n\n/-- A ray does not equal its own negation. -/\nlemma ne_neg_self [nontrivial R] [no_zero_smul_divisors R M] (x : module.ray R M) : x \u2260 -x :=\nbegin\n  intro h,\n  induction x using module.ray.ind,\n  rw [\u2190ray_neg, ray_eq_iff] at h,\n  exact x_hv (eq_zero_of_same_ray_self_neg h)\nend\n\nend module.ray\n\nnamespace basis\n\nvariables {R} {\u03b9 : Type*} [fintype \u03b9] [decidable_eq \u03b9]\n\n/-- The orientation given by a basis. -/\nprotected def orientation [nontrivial R] (e : basis \u03b9 R M) : orientation R M \u03b9 :=\nray_of_ne_zero R _ e.det_ne_zero\n\nend basis\n\nend ordered_comm_ring\n\nsection linear_ordered_comm_ring\n\nvariables {R : Type*} [linear_ordered_comm_ring R]\nvariables {M : Type*} [add_comm_group M] [module R M]\nvariables {\u03b9 : Type*} [decidable_eq \u03b9]\n\n/-- `same_ray` follows from membership of `mul_action.orbit` for the `units.pos_subgroup`. -/\nlemma same_ray_of_mem_orbit {v\u2081 v\u2082 : M} (h : v\u2081 \u2208 mul_action.orbit (units.pos_subgroup R) v\u2082) :\n  same_ray R v\u2081 v\u2082 :=\nbegin\n  rcases h with \u27e8\u27e8r, hr\u27e9, (rfl : r \u2022 v\u2082 = v\u2081)\u27e9,\n  exact same_ray_pos_smul_left _ hr,\nend\n\n/-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple\nis positive. -/\n@[simp] lemma same_ray_smul_right_iff [no_zero_smul_divisors R M] {v : M} (hv : v \u2260 0) (r : R) :\n  same_ray R v (r \u2022 v) \u2194 0 < r :=\nbegin\n  split,\n  { rintros \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9,\n    rw [smul_smul, \u2190sub_eq_zero, \u2190sub_smul, sub_eq_add_neg, neg_mul_eq_mul_neg] at h,\n    by_contradiction hr,\n    rw [not_lt, \u2190neg_le_neg_iff, neg_zero] at hr,\n    have hzzz := ne_of_gt (add_pos_of_pos_of_nonneg hr\u2081 (mul_nonneg hr\u2082.le hr)),\n    simpa [ne_of_gt (add_pos_of_pos_of_nonneg hr\u2081 (mul_nonneg hr\u2082.le hr)),\n           -mul_neg_eq_neg_mul_symm] using h },\n  { exact \u03bb h, same_ray_pos_smul_right v h }\nend\n\n/-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple\nis positive. -/\n@[simp] lemma same_ray_smul_left_iff [no_zero_smul_divisors R M] {v : M} (hv : v \u2260 0) (r : R) :\n  same_ray R (r \u2022 v) v \u2194 0 < r :=\nbegin\n  rw (symmetric_same_ray R M).iff,\n  exact same_ray_smul_right_iff hv r\nend\n\n/-- The negation of a nonzero vector is in the same ray as a multiple of that vector if and\nonly if that multiple is negative. -/\n@[simp] lemma same_ray_neg_smul_right_iff [no_zero_smul_divisors R M] {v : M} (hv : v \u2260 0)\n  (r : R) : same_ray R (-v) (r \u2022 v) \u2194 r < 0 :=\nbegin\n  rw [\u2190same_ray_neg_iff, neg_neg, \u2190neg_smul, same_ray_smul_right_iff hv (-r)],\n  exact right.neg_pos_iff\nend\n\n/-- A multiple of a nonzero vector is in the same ray as the negation of that vector if and\nonly if that multiple is negative. -/\n@[simp] lemma same_ray_neg_smul_left_iff [no_zero_smul_divisors R M] {v : M} (hv : v \u2260 0)\n  (r : R) : same_ray R (r \u2022 v) (-v) \u2194 r < 0 :=\nbegin\n  rw [\u2190same_ray_neg_iff, neg_neg, \u2190neg_smul, same_ray_smul_left_iff hv (-r)],\n  exact left.neg_pos_iff\nend\n\nnamespace basis\n\nvariables [fintype \u03b9]\n\n/-- The orientations given by two bases are equal if and only if the determinant of one basis\nwith respect to the other is positive. -/\nlemma orientation_eq_iff_det_pos (e\u2081 e\u2082 : basis \u03b9 R M) :\n  e\u2081.orientation = e\u2082.orientation \u2194 0 < e\u2081.det e\u2082 :=\nby rw [basis.orientation, basis.orientation, ray_eq_iff,\n       e\u2081.det.eq_smul_basis_det e\u2082, alternating_map.smul_apply, basis.det_self, smul_eq_mul,\n       mul_one, same_ray_smul_left_iff e\u2082.det_ne_zero (_ : R)]\n\n/-- Given a basis, any orientation equals the orientation given by that basis or its negation. -/\nlemma orientation_eq_or_eq_neg (e : basis \u03b9 R M) (x : orientation R M \u03b9) :\n  x = e.orientation \u2228 x = -e.orientation :=\nbegin\n  rw [basis.orientation, \u2190x.some_vector_ray, ray_eq_iff, \u2190ray_neg, ray_eq_iff,\n      x.some_vector.eq_smul_basis_det e],\n  rcases lt_trichotomy (x.some_vector e) 0 with h|h|h,\n  { right,\n    exact (same_ray_neg_smul_left_iff e.det_ne_zero (_ : R)).2 h },\n  { simpa [h] using x.some_vector.eq_smul_basis_det e },\n  { left,\n    exact (same_ray_smul_left_iff e.det_ne_zero (_ : R)).2 h }\nend\n\nend basis\n\nend linear_ordered_comm_ring\n\nsection linear_ordered_field\n\nvariables (R : Type*) [linear_ordered_field R]\nvariables {M : Type*} [add_comm_group M] [module R M]\nvariables {\u03b9 : Type*} [decidable_eq \u03b9]\n\n/-- `same_ray` is equivalent to membership of `mul_action.orbit` for the `units.pos_subgroup`. -/\nlemma same_ray_iff_mem_orbit (v\u2081 v\u2082 : M) :\n  same_ray R v\u2081 v\u2082 \u2194 v\u2081 \u2208 mul_action.orbit (units.pos_subgroup R) v\u2082 :=\nbegin\n  split,\n  { rintros \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9,\n    rw mul_action.mem_orbit_iff,\n    have h' : (r\u2081\u207b\u00b9 * r\u2082) \u2022 v\u2082 = v\u2081,\n    { rw [mul_smul, \u2190h, \u2190mul_smul, inv_mul_cancel (ne_of_lt hr\u2081).symm, one_smul] },\n    have hr' : 0 < (r\u2081\u207b\u00b9 * r\u2082) := mul_pos (inv_pos.2 hr\u2081) hr\u2082,\n    change (\u27e8units.mk0 (r\u2081\u207b\u00b9 * r\u2082) (ne_of_lt hr').symm, hr'\u27e9 : units.pos_subgroup R) \u2022 v\u2082 = v\u2081\n      at h',\n    exact \u27e8_, h'\u27e9 },\n  { exact same_ray_of_mem_orbit }\nend\n\n/-- `same_ray_setoid` equals `mul_action.orbit_rel` for the `units.pos_subgroup`. -/\nlemma same_ray_setoid_eq_orbit_rel :\n  same_ray_setoid R M = mul_action.orbit_rel (units.pos_subgroup R) M :=\nsetoid.ext' $ same_ray_iff_mem_orbit R\n\nvariables {R}\n\nnamespace orientation\n\nvariables [fintype \u03b9] [finite_dimensional R M]\n\nopen finite_dimensional\n\n/-- If the index type has cardinality equal to the finite dimension, any two orientations are\nequal or negations. -/\nlemma eq_or_eq_neg (x\u2081 x\u2082 : orientation R M \u03b9) (h : fintype.card \u03b9 = finrank R M) :\n  x\u2081 = x\u2082 \u2228 x\u2081 = -x\u2082 :=\nbegin\n  have e := (fin_basis R M).reindex (fintype.equiv_fin_of_card_eq h).symm,\n  rcases e.orientation_eq_or_eq_neg x\u2081 with h\u2081|h\u2081;\n    rcases e.orientation_eq_or_eq_neg x\u2082 with h\u2082|h\u2082;\n    simp [h\u2081, h\u2082]\nend\n\nend orientation\n\nend linear_ordered_field\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/orientation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642806, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7332373570737523}}
{"text": "\nvariables p q r s : Prop\ntheorem t1 : p \u2192 q \u2192 p := \u03bb hp, \u03bb hq, hp\n\ntheorem t2 : \u2200 (p q : Prop), p \u2192 q \u2192 p := \u03bb (p q), \u03bb hp, \u03bb hq, hp\n\ntheorem t3 (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q) : p \u2192 r := \u03bb hp, h\u2081 (h\u2082 hp)\n\nexample (h : p \u2227 q) : p := and.elim_left h\n\nvariables  (hp : p) (hq : q)\n\n#check (\u27e8hp, hq\u27e9 : p \u2227 q)\n\nexample (h : p \u2227 q) : q \u2227 p \u2227 q := \u27e8h.right, h.left, h.right\u27e9\n\nexample (hp : p) : p \u2228 q := or.intro_left q hp\n\nexample (hq : q) : p \u2228 q := or.intro_right p hq\n\nexample (h : p \u2228 q) : q \u2228 p := or.elim h (\u03bb hp, or.inr hp) (\u03bb hq, or.inl hq)\n\nexample (hnp : \u00acp) (hq : q) (hqp : q \u2192 p) : r := absurd (hqp hq) hnp\n\ntheorem and_swap : p \u2227 q \u2194 q \u2227 p := iff.intro \n(\u03bb hpq, and.intro (and.right hpq) (and.left hpq)) \n(\u03bb hqp, and.intro (and.right hqp) (and.left hqp))\n\nexample (h : p \u2227 q) : q \u2227 p :=\nhave hp : p, from and.left h,\nhave hq : q, from and.right h,\nshow q \u2227 p, from and.intro hq hp\n\nexample (h : p \u2227 q) : q \u2227 p := \n(\u03bb (hp : p), (\u03bb (hq : q), and.intro hq hp) (and.right h)) (and.left h)\n\nopen classical\n\nexample (h : \u00ac\u00acp) : p :=\nby_cases\n  (assume h1 : p, h1)\n  (assume h1 : \u00acp, absurd h1 h)\n\nexample (h : \u00ac\u00acp) : p :=\nby_cases (\u03bb hp : p, hp) (\u03bb hnp : \u00acp, absurd hnp h)\n\nexample (h : \u00ac\u00acp) : p :=\nby_contradiction\n  (assume h1 : \u00acp,\n    show false, from h h1)\n\nexample (h : \u00ac\u00acp) : p :=\nby_contradiction (\u03bb hnp : \u00acp, absurd hnp h)\n\nexample (h : \u00ac(p \u2227 q)) : \u00acp \u2228 \u00acq := \nor.elim (em p)\n(\u03bb hp : p, or.inr (\u03bb hq : q, h \u27e8hp, hq\u27e9)) \n(\u03bb hnp : \u00acp, or.inl hnp)\n\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := \niff.intro \n(\u03bb h, or.elim h.right (\u03bb hq, or.inl \u27e8h.left, hq\u27e9) (\u03bb hr, or.inr \u27e8h.left, hr\u27e9))\n(\u03bb h, or.elim h (\u03bb h0, \u27e8h0.left, or.inl h0.right\u27e9) (\u03bb h0, \u27e8h0.left, or.inr h0.right\u27e9))\n\nexample : \u00ac(p \u2227 \u00acq) \u2192 (p \u2192 q) := \u03bb h hp, \nor.elim (em q) (\u03bb hq, hq) (\u03bb hnq, absurd (and.intro hp hnq) h)\n\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := \niff.intro (\u03bb h, \u27e8h.right, h.left\u27e9) (\u03bb h, \u27e8h.right, h.left\u27e9)\nexample : p \u2228 q \u2194 q \u2228 p := \niff.intro (\u03bb h, or.elim h or.inr or.inl) \n(\u03bb h, or.elim h or.inr or.inl)\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := \niff.intro (\u03bb h, \u27e8h.left.left, \u27e8h.left.right, h.right\u27e9\u27e9)\n(\u03bb h, \u27e8\u27e8h.left, h.right.left\u27e9, h.right.right\u27e9)\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := \niff.intro (\u03bb h, or.elim h \n(\u03bb h, or.elim h or.inl (\u03bb hq, or.inr (or.inl hq))) \n(\u03bb h, or.inr (or.inr h)))\n(\u03bb h, or.elim h \n(\u03bb hp, or.inl (or.inl hp)) \n(\u03bb h, or.elim h (\u03bb hq, or.inl (or.inr hq)) or.inr))\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := iff.intro \n(\u03bb h, or.elim h.right (\u03bb hq, or.inl \u27e8h.left, hq\u27e9) (\u03bb hr, or.inr \u27e8h.left, hr\u27e9))\n(\u03bb h, or.elim h (\u03bb h0, \u27e8h0.left, or.inl h0.right\u27e9) (\u03bb h0, \u27e8h0.left, or.inr h0.right\u27e9))\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := iff.intro \n(\u03bb h, or.elim h (\u03bb hp, \u27e8or.intro_left q hp, or.intro_left r hp\u27e9) \n(\u03bb h, \u27e8or.intro_right p h.left, or.intro_right p h.right\u27e9))\n(\u03bb h, or.elim (em p) or.inl \n(\u03bb hnp, or.elim h.left (\u03bb hp, absurd hp hnp) \n(\u03bb hq, or.elim h.right (\u03bb hp, absurd hp hnp) (\u03bb hr, or.inr \u27e8hq, hr\u27e9))))\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := iff.intro (\u03bb hpqr hpq, (hpqr hpq.left hpq.right)) \n(\u03bb hpqr hp hq, hpqr \u27e8hp, hq\u27e9)\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := iff.intro (\u03bb h, \n\u27e8(\u03bb hp, h (@or.intro_left p q hp)), (\u03bb hq, h (@or.intro_right p q hq))\u27e9) \n(\u03bb h hpq, or.elim hpq (\u03bb hp, h.left hp) (\u03bb hq, h.right hq))\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := iff.intro \n(\u03bb h, \u27e8(\u03bb hp, h ((or.intro_left q) hp)), (\u03bb hq, h ((or.intro_right p) hq))\u27e9)\n(\u03bb h hpq, hpq.elim h.left h.right)\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := \u03bb h hpq, or.elim h (\u03bb hnp, absurd hpq.left hnp) \n(\u03bb hnq, absurd hpq.right hnq)\nexample : \u00ac(p \u2227 \u00acp) := \u03bb h, h.right h.left\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := \u03bb h hpq, h.right (hpq h.left)\nexample : \u00acp \u2192 (p \u2192 q) := \u03bb hnp hp, absurd hp hnp\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := \u03bb h hp, or.elim h (absurd hp) (\u03bb hq, hq)\nexample : p \u2228 false \u2194 p := iff.intro (\u03bb h, or.elim h (\u03bb hp, hp) false.elim) \n(\u03bb hp, or.intro_left false hp)\nexample : p \u2227 false \u2194 false := iff.intro (\u03bb h, h.right.elim) false.elim\nexample : \u00ac(p \u2194 \u00acp) := \u03bb h, (\u03bb (hnp : \u00acp), hnp (h.elim_right hnp)) (\u03bb hp, h.elim_left hp hp)\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := \u03bb hpq hnq hp, hnq (hpq hp)\n\n-- these require classical reasoning\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := \u03bb h, (em p).elim \n(\u03bb hp, (h hp).elim (\u03bb hr, or.inl (\u03bb hp, hr)) (\u03bb hs, or.inr (\u03bb hp, hs))) \n(\u03bb hnp, or.inl (\u03bb hp, absurd hp hnp))\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := \u03bb h, (em p).elim (\u03bb hp, (em q).elim \n(\u03bb hq, absurd (and.intro hp hq) h) or.inr) or.inl\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := \u03bb h, and.intro ((em p).elim id (\u03bb hnp, absurd \n(\u03bb hp : p, false.elim (hnp hp)) h)) ((em q).elim (\u03bb hq, absurd (\u03bb hp : p, hq) h) id)\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := \u03bb h, or.elim (em p) (\u03bb hp, or.inr (h hp)) or.inl\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := \u03bb h hp, by_contradiction (\u03bb hnq, absurd hp (h hnq))\nexample : p \u2228 \u00acp := em p\nexample : ((p \u2192 q) \u2192 p) \u2192 p := \u03bb h, or.elim (em p) id\n(\u03bb hnp, by_contradiction (\u03bb hnp, hnp (h (\u03bb hp, absurd hp hnp))))", "meta": {"author": "AlexandruBosinta", "repo": "MyLeanPlayground", "sha": "5dc50a590d784bfc27e7fb37b6361a6dcc1b2790", "save_path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground", "path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground/MyLeanPlayground-5dc50a590d784bfc27e7fb37b6361a6dcc1b2790/3. Propopositions and Proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8221891305219503, "lm_q1q2_score": 0.7332373551309748}}
{"text": "-- CS_de_y_le_x.lean\n-- Pruebas de \"(\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x\"\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 15 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Sean x, y \u2208 \u211d. Demostrar que\n--    (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {x y : \u211d}\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192 y \u2264 x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split,\n  { apply half_pos,\n    exact sub_pos.mpr h, },\n  { calc x + (y - x) / 2\n         = (x + y) / 2   : by ring_nf\n     ... < (y + y) / 2   : div_lt_div_of_lt zero_lt_two (add_lt_add_right h y)\n     ... = (2 * y) / 2   : congr_arg2 (/) (two_mul y).symm rfl\n     ... = y             : by ring_nf, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192 y \u2264 x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split,\n  { exact half_pos (sub_pos.mpr h), },\n  { calc x + (y - x) / 2\n         = (x + y) / 2   : by ring_nf\n     ... < (y + y) / 2   : by linarith\n     ... = (2 * y) / 2   : by ring_nf\n     ... = y             : by ring_nf, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192 y \u2264 x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split,\n  { linarith },\n  { linarith },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192 y \u2264 x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192 y \u2264 x :=\nbegin\n  intro h1,\n  by_contradiction h2,\n  replace h2 : x < y := not_le.mp h2,\n  rcases (exists_between h2) with \u27e8z, h3, h4\u27e9,\n  replace h3 : 0 < z - x := sub_pos.mpr h3,\n  replace h1 : y \u2264 x + (z - x) := h1 (z - x) h3,\n  replace h1 : y \u2264 z := by finish,\n  have h4 : y < y := gt_of_gt_of_ge h4 h1,\n  exact absurd h4 (irrefl y),\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192 y \u2264 x :=\nbegin\n  intro h1,\n  by_contradiction h2,\n  replace h2 : x < y := not_le.mp h2,\n  rcases (exists_between h2) with \u27e8z, hxz, hzy\u27e9,\n  apply lt_irrefl y,\n  calc y \u2264 x + (z - x) : h1 (z - x) (sub_pos.mpr hxz)\n     ... = z           : by ring\n     ... < y           : hzy,\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/CS_de_y_le_x.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7332373499812601}}
{"text": "import project.identities\nimport tactic.linarith\nimport tactic.tidy\nimport data.list\nimport data.list.basic\nimport data.int.basic\nimport tactic.ring\nimport data.nat.gcd\n\n/- Collaboration between\n   Travis Hance (thance)\n   Katherine Cordwell (kcordwell)\n-/\n\n/-\n    Catalan numbers.\n\n    In this file we:\n\n        - Define `balanced`: balanced strings of parentheses\n          (`tt` is   and open paren, `ff` is a close paren).\n\n        - Define `catalan`: the catalan numbers by recurrence\n\n        - Show that the set of balanced strings of length 2*n\n          is catalan n. (theorem `has_card_set_balanced`)\n          by induction, by showing that a balanced string of\n          length 2*(m+1) corresponds to a pair of balanced\n          strings whose lengths sum to 2*m.\n\n        - Define `below_diagonal_path`, a proposition which\n          indicates that a path of length (2n+1) goes from\n          (0,0) to (n,n+1) while never going above the\n          (0,0)--(n,n+1) diagonal.\n        \n        - Show that balanced strings of length 2*n are in bijection\n          with below_diagonal_path strings of length 2*n+1.\n          (theorem `has_card_set_below_diagonal_path_catalan`)\n        \n        - Take all 2*n+1 rotations of all below_diagonal_path\n          strings, and show that this gives *all* paths\n          from (0,0) to (n,n+1)\n          (theorem `theorem has_card_set_n_choose_k_catalan`)\n        \n        - Finally, show that\n            catalan n = (choose (2*n+1) n) / (2*n + 1)\n          (theorem `catalan_identity`)\n\n    We define `catalan` by recurence, then show that `catalan n`\n    is the cardinality of the set of balanced strings of length 2n.\n    (theorem `has_card_set_balanced`)\n\n    Then by doing a bijection through paths from (0,0) to (n,n+1),\n    we prove our main result, the theorem\n    `catalan_identity`.\n-/\n\n/-\n    Define balanced strings of parentheses.\n    `tt` represents an open paren, `ff` represents a closed paren.\n-/\n\ndef balanced_aux : (list bool) \u2192 (\u2115) \u2192 Prop\n    | [] 0 := true\n    | [] (d + 1) := false\n    | (tt :: l) d := balanced_aux l (d + 1)\n    | (ff :: l) 0 := false\n    | (ff :: l) (d + 1) := balanced_aux l d\n\ndef balanced (l : list bool) : Prop := balanced_aux l 0\n\n/-\n    Define the set of balanced parentheses of length 2*n\n    (that is, n pairs of parentheses)\n-/\n\ndef set_balanced (n : \u2115) : set (list bool) :=\n    { l : list bool | list.length l = 2 * n \u2227 balanced l }\n\n/-\n    Define the catalan numbers\n-/\n\ndef sum_to : \u03a0 (n:\u2115) , (\u03a0 (x:\u2115) , (x<n) \u2192 \u2115) \u2192 \u2115\n    | 0 f := 0\n    | (n+1) f :=\n        have h : n < (n+1) , by linarith ,\n        have f' : (\u03a0 (x:\u2115) , (x<n) \u2192 \u2115) , from \n            (\u03bb x , \u03bb ineq , f x (by linarith)) ,\n        f n h + sum_to n f'\n\ndef catalan : \u2115 \u2192 \u2115\n    | 0 := 1\n    | (n+1) := sum_to (n+1) (\u03bb i , \u03bb i_le_n ,\n            have nmi_le_n : (n-i < (n+1)),\n                by apply nat.sub_lt_succ ,\n            catalan i * catalan (n-i)\n        )\n\n/- split (A)B into A, B -/\ndef split_parens_aux : (list bool) \u2192 (\u2115) \u2192 (list bool \u00d7 list bool)\n| ([]) n := ([],[])\n| (ff :: l) 0 := \u27e8 [], [] \u27e9 /- doesn't matter -/\n| (ff :: l) 1 := \u27e8 [], l \u27e9\n| (ff :: l) (d + 2) := let p := split_parens_aux l (d+1) in \u27e8 ff :: p.1 , p.2 \u27e9\n| (tt :: l) (d) := let p := split_parens_aux l (d+1) in \u27e8 tt :: p.1 , p.2 \u27e9\ndef split_parens : (list bool) \u2192 (list bool \u00d7 list bool)\n| [] := ([],[]) /- doesn't matter -/\n| (tt :: l) := split_parens_aux l 1\n| (ff :: l) := ([],[]) /- doesn't matter -/\n\n/- combined A, B into (A)B -/\ndef combine_parens (l : list bool) (m : list bool) : (list bool) :=\n    tt :: l ++ ff :: m\n\n/- lemmas about balanced parentheses -/\n\ntheorem balanced_split_parens_2_aux : \u2200 (l:list bool) (d:\u2115) ,\n    balanced_aux l d -> balanced (split_parens_aux l d).2\n    | [] 0 :=\n    begin\n        intros ,\n        rw [split_parens_aux] , simp ,\n    end\n    | [] (d + 1) :=\n    begin\n        intros ,\n        rw [balanced_aux] at * , contradiction ,\n    end\n    | (tt :: l) d :=\n    begin\n        intros , rw [balanced_aux] at * ,\n        rw [split_parens_aux] ,\n        simp ,\n        apply balanced_split_parens_2_aux , assumption ,\n    end\n    | (ff :: l) 0 :=\n    begin\n        intros ,\n        rw [split_parens_aux, balanced], simp ,\n    end\n    | (ff :: l) (d + 1) :=\n    begin\n        intros ,\n        cases d,\n        {\n            simp , rw [split_parens_aux] , simp ,\n            rw [balanced_aux] at a , rw [balanced] , assumption ,\n        },\n        {\n            rw [split_parens_aux] , simp ,\n            apply balanced_split_parens_2_aux ,\n            rw [balanced_aux] at a,\n            have h : (d + 1) = nat.succ d := rfl ,\n            rw [h] , assumption ,\n        }\n    end\n\ntheorem balanced_split_parens_1_aux : \u2200 (l:list bool) (d:\u2115) ,\n    balanced_aux l (d+1) -> balanced_aux (split_parens_aux l (d+1)).1 d\n    | [] 0 :=\n    begin\n        intros ,\n        rw [split_parens_aux] , simp ,\n    end\n    | [] (d + 1) :=\n    begin\n        intros ,\n        rw [balanced_aux] at * , contradiction ,\n    end\n    | (tt :: l) d :=\n    begin\n        intros ,\n        rw [split_parens_aux] , simp ,\n        apply balanced_split_parens_1_aux , \n        rw [balanced_aux] at a , assumption ,\n    end\n    | (ff :: l) 0 :=\n    begin\n        intros ,\n        rw [split_parens_aux] , simp , \n    end\n    | (ff :: l) (d + 1) :=\n    begin\n        intros ,\n        rw [split_parens_aux] , simp , rw [balanced_aux] ,\n        apply balanced_split_parens_1_aux ,\n        rw [balanced_aux] at a ,\n        assumption ,\n    end\n\ntheorem balanced_split_parens_1 : \u2200 (l : list bool) ,\n    balanced l -> balanced (split_parens l).1 :=\n    begin\n        intros ,\n        rw [balanced] ,\n        cases l ,\n        {\n            rw [split_parens, balanced_aux] , trivial ,\n        },\n        cases l_hd ,\n        {\n            rw [balanced] at a,\n            rw [balanced_aux] at a ,\n            contradiction ,\n        },\n        {\n            rw [split_parens] ,\n            apply balanced_split_parens_1_aux ,\n            rw [balanced] at a , rw [balanced_aux] at a ,\n            assumption ,\n        }\n    end\n\ntheorem balanced_split_parens_2 : \u2200 (l : list bool) ,\n    balanced l -> balanced (split_parens l).2 :=\n    begin\n        intros ,\n        rw [balanced] ,\n        cases l ,\n        {\n            rw split_parens , simp , \n        },\n        cases l_hd ,\n        {\n            rw [balanced] at a,\n            rw [balanced_aux] at a ,\n            contradiction ,   \n        },\n        {\n            apply balanced_split_parens_2_aux ,\n            rw [balanced, balanced_aux] at a , simp at a , assumption ,\n        }\n    end\n\ntheorem balanced_combine_aux : \u2200 (l : list bool) (m : list bool) (d:\u2115) ,\n    balanced_aux l d \u2192\n    balanced m \u2192\n    balanced_aux (l ++ ff :: m) (d+1)\n| [] m :=\n    begin\n        intros , simp , rw [balanced_aux] ,\n        cases d ,\n        {\n            rw [balanced] at a_1 , assumption ,\n        },\n        {\n            rw [balanced_aux] at a , contradiction ,\n        }\n    end\n| (x :: l) m :=\n    begin\n        intros ,\n        cases x ,\n        {\n            have h : (ff :: l ++ ff :: m = ff :: (l ++ ff :: m)) := by simp,\n            rw h ,\n            rw [balanced_aux] ,\n            cases d ,\n            {\n                rw [balanced_aux] at a , contradiction ,\n            },\n            {\n                apply balanced_combine_aux ,\n                rw [balanced_aux] at a , assumption ,\n                assumption ,\n            }\n        },\n        {\n            have h : (tt :: l ++ ff :: m = tt :: (l ++ ff :: m)) := by simp,\n            rw h ,\n            rw [balanced_aux] ,\n            apply balanced_combine_aux ,\n            rw [balanced_aux] at a , assumption,\n            assumption,\n        }\n    end\n\ntheorem balanced_combine : \u2200 (l : list bool) (m : list bool) ,\n    balanced l \u2192\n    balanced m \u2192\n    balanced (combine_parens l m) :=\nbegin\n    intros , rw [combine_parens] , \n    rw [balanced] ,\n    have h : (tt :: l ++ ff :: m = tt :: (l ++ ff :: m)) := by simp,\n    rw h ,\n    rw [balanced_aux] ,\n    apply balanced_combine_aux ,\n    rw [balanced] at a ,\n    assumption ,\n    assumption ,\nend\n\ntheorem split_parens_combine_parens_aux : \u2200 (l : list bool) (m : list bool) (d:\u2115) ,\n    balanced_aux l d \u2192\n    balanced m \u2192\n    split_parens_aux (l ++ ff :: m) (d+1) = \u27e8l, m\u27e9\n| [] m 0 :=\n    begin\n        intros , simp [split_parens_aux] ,\n    end\n| [] m (d + 1) :=\n    begin\n        intros , simp [balanced_aux] at a , contradiction ,\n    end\n| (tt :: l) m d :=\n    begin\n        intros ,\n        simp [split_parens_aux] ,\n        have q : balanced_aux l (d+1) := begin\n            rw [balanced_aux] at a , assumption ,\n        end,\n        have h := split_parens_combine_parens_aux l m (d+1) q a_1,\n        simp at h , rw h , simp , \n    end\n| (ff :: l) m 0 :=\n    begin\n        intros ,\n        simp [balanced_aux] at a , contradiction ,\n    end\n| (ff :: l) m (d + 1) :=\n    begin\n        intros ,\n        simp [split_parens_aux] ,\n        have q : balanced_aux l d := begin\n            rw [balanced_aux] at a , assumption ,\n        end,\n        have h := split_parens_combine_parens_aux l m d q a_1,\n        rw h , simp , \n    end\n\ntheorem split_parens_combine_parens : \u2200 (l : list bool) (m : list bool) ,\n    balanced l \u2192\n    balanced m \u2192\n    split_parens (combine_parens l m) = \u27e8l, m\u27e9 :=\nbegin\n    intros ,\n    rw [combine_parens],\n    have h : (tt :: l ++ ff :: m = tt :: (l ++ ff :: m)) := by simp,\n    rw h,\n    rw [split_parens] ,\n    apply split_parens_combine_parens_aux ,\n    rw [balanced] at a , assumption ,\n    assumption ,\nend\n\ntheorem combine_parens_split_parens_aux : \u2200 (l : list bool) (d:\u2115) ,\n    balanced_aux l (d+1) \u2192\n    (split_parens_aux l (d+1)).1 ++ ff :: (split_parens_aux l (d+1)).2 = l\n| [] d :=\n    begin\n        intros , rw [balanced_aux] at a , contradiction ,\n    end\n| (tt :: l) d :=\n    begin\n        intros ,\n        rw [split_parens_aux] , simp ,\n        rw [balanced_aux] at a ,\n        have h := combine_parens_split_parens_aux l (d+1) a,\n        simp at a h, assumption,\n    end\n| (ff :: l) 0 :=\n    begin\n        intros , rw [balanced_aux] at a ,\n        rw [split_parens_aux] , simp ,\n    end\n| (ff :: l) (d+1) :=\n    begin\n        intros ,\n        rw [split_parens_aux] , simp ,\n        rw [balanced_aux] at a ,\n        have h := combine_parens_split_parens_aux l d a,\n        assumption,\n    end\n\ntheorem combine_parens_split_parens : \u2200 (l : list bool) ,\n    balanced l \u2192\n    \u00ac(l = list.nil) \u2192 \n    combine_parens (split_parens l).1 (split_parens l).2 = l :=\nbegin\n    intros ,\n    cases l ,\n    simp at a_1, contradiction ,\n    cases l_hd ,\n    rw [balanced, balanced_aux] at a , contradiction ,\n    rw [split_parens] , rw [combine_parens] , simp ,\n    apply combine_parens_split_parens_aux ,\n    simp , rw [balanced] at a , rw [balanced_aux] at a , simp at a ,\n    assumption ,\nend\n\ntheorem length_combine_parens : \u2200 (l : list bool) (m : list bool) ,\n    balanced l \u2192\n    balanced m \u2192\n    list.length (combine_parens l m) = list.length l + list.length m + 2\n    :=\nbegin\n    intros , rw [combine_parens] , simp , rw [<- add_assoc] , simp ,\nend\n\ntheorem length_split_parens_eq_minus : \u2200 (l : list bool) (n:\u2115) (a:\u2115) ,\n    list.length l = 2 * (n + 1) \u2192 \n    balanced l \u2192\n    list.length ((split_parens l).1) = 2 * a \u2192\n    list.length ((split_parens l).2) = 2 * (n - a) :=\nbegin\n    intros ,\n    have h :\n        list.length (combine_parens (split_parens l).1 (split_parens l).2) = list.length (split_parens l).1 +\n          list.length (split_parens l).2 + 2 :=\n        begin\n            apply length_combine_parens ,\n            apply balanced_split_parens_1 , assumption ,\n            apply balanced_split_parens_2 , assumption ,\n        end,\n    calc list.length ((split_parens l).2) =\n        list.length (split_parens l).1 + list.length (split_parens l).2 + 2 -\n        (list.length (split_parens l).1 + 2) : begin\n            rw [@nat.add_comm (list.length ((split_parens l).fst)) _] ,\n            rw nat.add_assoc ,\n            rw nat.add_sub_cancel ,\n        end\n    ... = list.length (\n            combine_parens (split_parens l).1 (split_parens l).2) - (list.length (split_parens l).1 + 2) : by rw h \n    ... = list.length l - (list.length (split_parens l).1 + 2) :\n        begin\n            rw combine_parens_split_parens , assumption ,\n            apply not.intro , intros , subst l , simp at a_1,\n            contradiction ,\n        end\n    ... = list.length l - (2 * a + 2) : by rw a_3\n    ... = 2 * (n + 1) - (2 * a + 2) : by rw a_1\n    ... = 2 * (n + 1) - (2 * a + 2 * 1) : by simp\n    ... = 2 * (n + 1) - 2 * (a + 1) : by rw [mul_add 2 a 1]\n    ... = 2 * ((n+1) - (a+1)) : by rw [nat.mul_sub_left_distrib 2 (n+1) (a+1)]\n    ... = 2 * (n - a) : by simp\nend\n\ntheorem even_length_of_balanced_aux : \u2200 (l : list bool) (d : \u2115) ,\n    balanced_aux l d \u2192 \n    (\u2203 m , list.length l + d = 2 * m)\n    | [] 0 :=\n    begin\n        intros , existsi 0 , simp ,\n    end\n    | [] (d + 1) :=\n    begin\n        intros , rw [balanced_aux] at a , contradiction ,\n    end\n    | (tt :: l) d :=\n    begin\n        intros ,\n        rw [balanced_aux] at a ,\n        have h := even_length_of_balanced_aux l (d+1) a ,\n        cases h ,\n        existsi h_w ,\n        simp ,\n        simp at h_h , assumption ,\n    end\n    | (ff :: l) 0 :=\n    begin\n        intros , rw [balanced_aux] at a , contradiction ,\n    end\n    | (ff :: l) (d + 1) :=\n    begin\n        intros ,\n        rw [balanced_aux] at a ,\n        have h := even_length_of_balanced_aux l d a ,\n        cases h ,\n        existsi (h_w + 1) ,\n        rw [mul_add] , simp , rw <- h_h , simp ,\n        rw [<- add_assoc] , simp ,\n    end\n\ntheorem even_length_of_balanced : \u2200 (l : list bool) ,\n    balanced l \u2192\n    2 \u2223 list.length l\n    :=\nbegin\n    intros ,\n    rw [balanced] at a ,\n    have h := even_length_of_balanced_aux l 0 a ,\n    cases h ,\n    simp at h_h ,\n    rw h_h ,\n    apply dvd_mul_right ,\nend\n\ntheorem length_split_parens_1_le : \u2200 (l : list bool) ,\n    balanced l \u2192\n    \u00ac(l = list.nil) \u2192\n    list.length (split_parens l).1 \u2264 list.length l - 2 :=\nbegin\n    intros ,\n    have h : (combine_parens (split_parens l).1 (split_parens l).2 = l)\n        := combine_parens_split_parens l a a_1 ,\n    have h2 : (list.length (combine_parens (split_parens l).1 (split_parens l).2) = list.length (split_parens l).1 + list.length (split_parens l).2 + 2)\n        :=\n    begin\n        apply length_combine_parens ,\n        apply balanced_split_parens_1 , assumption ,\n        apply balanced_split_parens_2 , assumption ,\n    end,\n    rw h at h2 ,\n    calc list.length ((split_parens l).fst)\n        \u2264 list.length ((split_parens l).fst) + list.length ((split_parens l).snd) : by linarith \n    ... = list.length ((split_parens l).fst) + list.length ((split_parens l).snd) + 2 - 2 : by simp\n    ... = list.length l - 2 : by rw h2\nend\n\nlemma catalan_set_eq_with_bound : \u2200 (n:\u2115) ,\n    {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l} = \n    {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227\n                     list.length (split_parens l).1 < 2*(n+1)} :=\nbegin\n    intros , \n    apply set.ext ,\n    intros , split ,\n    {\n        intros ,\n        split ,\n        cases a, assumption ,\n        split ,\n        cases a , assumption ,\n        simp at a , cases a , \n        calc list.length (split_parens x).1 \u2264 (list.length x) - 2\n                : (begin\n                    apply length_split_parens_1_le , assumption ,\n                    apply not.intro , intros , subst x , simp at a_left , trivial ,\n                  end)\n            ... = 2 * n\n                : (begin\n                    rw a_left,\n                    rw mul_add , simp ,\n                  end)\n            ... < 2 * (n + 1)\n                : by linarith\n    },\n    {\n        intros ,\n        cases a , cases a_right , simp , split , assumption ,\n        assumption ,\n    }\nend \n\n/- annoying arithmetic lemmas -/\n\ntheorem nat_lt_of_not_eq : \u2200 (n:\u2115) (m:\u2115) ,\n    n < m+1 \u2192 \u00ac(n = m) \u2192 n < m :=\nbegin\n    intros ,\n    by_contradiction ,\n    have h : (n = m) := nat.eq_of_lt_succ_of_not_lt a a_2 ,\n    contradiction ,\nend\n\ntheorem even_nat_lt : \u2200 (n:\u2115) (m:\u2115) ,\n    (n) < 2*(m + 1) \u2192 \n    \u00ac ((n) = 2*m) \u2192\n    2 \u2223 n \u2192 \n    n < 2*m :=\nbegin\n    intros ,\n    by_cases (n = 2 * m + 1) ,\n    { \n        subst n ,\n        /- derive a contradiction from 2 | 2*m + 1\n           (surely there was an easier way to do this?) -/\n        have h : (2 \u2223 (2 * int.of_nat m)) := dvd_mul_right _ _,\n        have h1 : (2 \u2223 (2 * int.of_nat m) + 1) := begin\n            have h3 : (2 \u2223 int.of_nat (2*m + 1)) :=\n                begin\n                    apply int.of_nat_dvd_of_dvd_nat_abs ,\n                    simp , simp at a_2 , assumption ,\n                end,\n            have two_eq : 2 = int.of_nat 2 := by refl ,\n            rw two_eq ,\n            have one_eq : 1 = int.of_nat 1 := by refl ,\n            rw one_eq ,\n            rw <- int.of_nat_mul ,\n            rw <- int.of_nat_add ,\n            assumption ,\n        end,\n        have h2 : (2 \u2223 ((2 * int.of_nat m) + 1) - (2 * int.of_nat m)) :=\n            begin\n                apply dvd_sub , assumption , assumption ,\n            end,\n        simp at h2,\n        have h3 : ((1:int) % 2 = 0) := begin\n                apply int.mod_eq_zero_of_dvd , assumption ,\n            end,\n        have h4 : ((1:int) % 2 = 1) := rfl ,\n        rw h4 at h3 ,\n        simp at h3 ,\n        contradiction ,\n    },\n    {\n        have i : (2*(m+1) = (2*m + 1) + 1) := begin\n            rw [mul_add] , simp , rw [<- @nat.add_assoc 1 _] ,\n        end,\n        have j : (n < ((2*m) + 1) + 1) := begin\n            rw <- i , assumption ,\n        end ,\n        have k : (n < (2*m) + 1) := nat_lt_of_not_eq _ _ j h ,\n        have l : (n < (2*m)) := nat_lt_of_not_eq _ _ k a_1 ,\n        assumption ,\n    }\nend\n\nlemma catalan_set_induction : \u2200 (n:\u2115) (i:\u2115) (a:\u2115) (b:\u2115) ,\n    has_card {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227\n                     list.length (split_parens l).1 < 2*i} a \u2192\n    has_card {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227\n                     list.length (split_parens l).1 = 2*i} b \u2192\n    has_card {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227\n                     list.length (split_parens l).1 < 2*(i+1)} (a+b) :=\nbegin\n    intros ,\n    apply card_split _ \n        {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227\n                     list.length (split_parens l).1 < 2*i}\n        {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227\n                     list.length (split_parens l).1 = 2*i}\n        a b ,\n    {\n        intros , simp , simp at a_3 , cases a_3 , cases a_3_right ,\n        split, assumption , split, assumption , linarith , \n    },\n    {\n        intros , simp , simp at a_3 , cases a_3 , cases a_3_right ,\n        split, assumption , split, assumption , linarith , \n    },\n    {\n        simp ,\n        intros ,\n        by_cases (list.length (split_parens x).1 = 2*i) ,\n        {\n            right , split, assumption, split, assumption, assumption ,\n        },\n        {\n            left, split, assumption, split, assumption, \n            apply even_nat_lt ,\n            assumption ,\n            assumption ,\n            apply even_length_of_balanced ,\n            apply balanced_split_parens_1 ,\n            assumption ,\n        }\n    },\n    {\n        simp , intros ,\n        apply not.intro , intros , \n        rw a_8 at a_5 ,\n        linarith ,\n    },\n    {\n        assumption ,\n    },\n    {\n        assumption ,\n    },\nend\n\nlemma catalan_set_base : \u2200 (n:\u2115) ,\n    has_card {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227\n                     list.length (split_parens l).1 < 2*0} 0 :=\nbegin\n    intros,\n    apply card_0 ,\n    simp ,\nend\n\n/-\n    Show that balanced parentheses have cardinality the catalan\n    numbers by splitting the parentheses strings into pairs.\n    We do induction on `bound`.\n-/\n\nlemma has_card_set_balanced_aux : \u2200 bound n ,\n    n < bound \u2192\n    has_card (set_balanced n) (catalan n)\n| 0 n :=\n    begin\n        intros ,\n        linarith ,\n    end\n| (bound+1) 0 :=\n    begin\n        intros ,\n        rw [set_balanced, catalan] ,\n        apply (card_1 _ []) ,\n        simp ,\n        intros , simp at a_1 , cases a_1 , cases y ; trivial ,\n    end\n| (bound+1) (n+1) :=\n    begin\n        intros , \n        rw catalan ,\n        rw set_balanced ,\n\n        /- add the bound that the first part of the split is < 2*(n+1) -/\n        rw catalan_set_eq_with_bound ,\n\n        /- replace n+1 with j (why is this so annoying omg) -/\n        have j' : (\u2203 j , j = n+1) , existsi (n+1), trivial, cases j', rename j'_w j ,\n        have e : (\n            {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227 list.length ((split_parens l).fst) < 2 * (n + 1)} =\n            {l : list bool | list.length l = 2 * (n + 1) \u2227 balanced l \u2227 list.length ((split_parens l).fst) < 2 * j}) ,\n        rw j'_h ,\n        rw e ,\n        clear e ,\n        have e : (\n                sum_to (n + 1) (\u03bb (i : \u2115) (i_le_n : i < n + 1), catalan i * catalan (n - i))\n                 =\n                sum_to j (\u03bb (i : \u2115) (i_le_n : i < j), catalan i * catalan (n - i))) := by rw j'_h,\n        rw e , clear e,\n        have n_bound : (n+1) < (bound+1) := a , /- copy this -/\n        have j_bound : j \u2264 (n+1) := \n            begin\n                subst j , \n            end ,\n        clear a , clear j'_h ,\n\n        /- do induction on j for the summation of the recursion -/\n        induction j, \n        {\n            rw [sum_to] ,\n            apply catalan_set_base ,\n        },\n        {\n            rw [sum_to] , simp ,\n            rw [@nat.add_comm (catalan j_n * catalan (n - j_n)) _] ,\n            apply catalan_set_induction ,\n            {\n                apply j_ih ,\n                calc j_n \u2264 j_n + 1 : by linarith\n                ... = nat.succ j_n : by refl \n                ... \u2264 n + 1 : by assumption\n            },\n            {\n                /- Show that the length of balanced strings\n                   of the form (A)B where |A|=2*j_n is\n                   catalan j_n * catalan (n-j_n). -/\n\n                clear j_ih ,\n                apply (card_product\n                    {l : list bool | list.length l = 2 * j_n \u2227      \n                        balanced l}\n                    {l : list bool | list.length l = 2 * (n - j_n) \u2227      \n                        balanced l}\n                    _\n                    (catalan j_n)\n                    (catalan (n - j_n))\n                    combine_parens\n                 ) ,\n                 {\n                     simp, intros,\n                     split ,\n                     rw [combine_parens] , simp , rw a , rw a_2 ,\n                     {\n                        calc 1 + (1 + (2 * j_n + 2 * (n - j_n))) = 2 * (n + 1) : begin\n                            rw [<- mul_add] ,\n                            rw [add_comm j_n] ,\n                            rw [nat.sub_add_cancel] , ring,\n                            have h : (nat.succ j_n = j_n + 1) := rfl ,\n                            rw h at j_bound , linarith ,\n                        end\n                     },\n                     {\n                         split,\n                         apply balanced_combine , assumption, assumption ,\n                         rw split_parens_combine_parens , simp , assumption ,\n                         assumption, assumption,\n                     }\n                 },\n                 {\n                    simp, intros ,\n                    existsi (split_parens z).1 ,\n                    split ,\n                    split , assumption ,\n                    apply balanced_split_parens_1 , assumption ,\n                    existsi (split_parens z).2 ,\n                    split ,\n                    split ,\n                    apply length_split_parens_eq_minus ; assumption ,\n                    apply balanced_split_parens_2 , assumption ,\n                    apply combine_parens_split_parens ,\n                    assumption ,\n                    apply not.intro , intros , subst z , simp at a ,linarith , \n                 },\n                 {\n                    simp, intros , \n                    have e : (( x, y ) = ( x', y' )) := (\n                    calc ( x, y ) = split_parens (combine_parens x y) :\n                            (begin\n                                rw split_parens_combine_parens ,\n                                assumption, assumption ,\n                            end)\n                        ... = split_parens (combine_parens x' y') :\n                            (begin\n                                rw a_8 ,\n                            end)\n                        ... = ( x', y' ) :\n                            (begin\n                                rw split_parens_combine_parens ,\n                                assumption, assumption ,\n                            end)),\n                    simp at e ,\n                    assumption ,\n                 },\n                 {\n                     apply (has_card_set_balanced_aux bound) ,\n                     have h : (nat.succ j_n = j_n + 1) := rfl ,\n                     rw h at j_bound , linarith ,\n                 },\n                 {\n                     apply (has_card_set_balanced_aux bound) ,\n                     have h : (nat.succ j_n = j_n + 1) := rfl ,\n                     rw h at j_bound ,\n                     have t : (n - j_n \u2264 n) := nat.sub_le_self _ _ ,\n                     linarith ,\n                 },\n            }\n        }\n\n    end\n\n/- main theorem that balanced parentheses strings of length 2*n\n   has cardinality catalan n -/\n\ntheorem has_card_set_balanced : \u2200 n ,\n    has_card (set_balanced n) (catalan n) :=\nbegin\n    intros ,\n    apply (has_card_set_balanced_aux (n+1) n) ,\n    linarith ,\nend\n\n/- below_diagonal_path is a proposition that indicates\n   a sequence represents a path\n    from (0,0) to (n, n+1) (where tt is +1 in x direction\n   and ff is +1 in y direction) which always stays below\n   the diagonal.\n\n   We will biject such paths with the balanced parentheses,\n   (theorem `has_card_set_below_diagonal_path_catalan`)\n   which will show that they have cardinality `catalan n`.\n\n   Then we will show that (2n+1) rotations of\n   of these paths will be the set of all paths from (0,0) to (n,n+1),\n   which has number (2n+1 choose n).\n    -/\n\ndef below_diagonal_path (n : \u2115) (l : list bool) :=\n    list.length l = 2*n + 1 \u2227\n    count_tt l = n \u2227\n    (forall (i:\u2115) , i \u2264 (2*n + 1) \u2192\n        ((int.of_nat i) * (int.of_nat n) -\n            (2*(int.of_nat n)+1) * (int.of_nat (count_tt (list.take i l))) \u2264 0))\n\ndef argmax : (\u2115 \u2192 \u2124) \u2192 \u2115 \u2192 \u2115\n    | f 0 := 0\n    | f (n+1) := if f (n+1) > f (argmax f n) then (n+1) else argmax f n\n\n/-\n    Gets the point on a path from (0,0) to (n,n+1)\n    which is farthest above the (0,0)--(n,n+1) diagonal.\n    This is important because if we rotate the path to this\n    point, then it will be a below_diagonal_path.\n    (theorem below_diagonal_path_rotate_best_point).\n-/\n\ndef best_point (n:\u2115) (l : list bool) :=\n    argmax (\u03bb i ,\n        (int.of_nat n) * (int.of_nat i) -\n            (2*(int.of_nat n) + 1) * (int.of_nat (count_tt (list.take i l)))\n    ) (2*n)\n\n/-\n    A bunch of lemmas dealing with rotations and argmax and\n    miscellaneous. We represent rotations as numbers i\n    where 0 \u2264 i < n. And implement them as\n    `list.drop i l + list.take i l`.\n    (In retrospect it might have made more sense to use list.rotate\n    more heavily.) \n-/\n\ndef negate_rotation (n:\u2115) (i:\u2115) :=\n    if i = 0 then 0 else n - i\n\ndef compose_rotation (n:\u2115) (i:\u2115) (j:\u2115) :=\n    (i + j) % n\n\ntheorem argmax_lt_length : \u2200 (f : \u2115 \u2192 \u2124) (n : \u2115) ,\n    argmax f n < n+1\n| f 0 := begin intros, rw [argmax] , linarith , end\n| f (n+1) :=\n    begin\n        rw argmax ,\n        split_ifs ,\n        linarith ,\n        have h : argmax f n < n + 1 := argmax_lt_length f n ,\n        linarith ,\n    end\n\ntheorem func_argmax_ge : \u2200 (f: \u2115 \u2192 \u2124) (n : \u2115) (i : \u2115) ,\n    i \u2264 n \u2192 \n    f (argmax f n) \u2265 f i\n| f 0 0 :=\n    begin\n        intros , rw [argmax] , linarith ,\n    end\n| f 0 (i+1) :=\n    begin\n        intros , linarith ,\n    end\n| f (n+1) i :=\n    begin\n        intros ,\n        {\n            rw [argmax] , split_ifs ,\n            {\n                rename h h' ,\n                by_cases (i = n+1) ,\n                {\n                    subst i , linarith ,\n                },\n                {\n                    apply le_of_lt ,\n                    have h2 : (i < n+1) := begin\n                        apply nat_lt_of_not_eq, linarith , assumption ,\n                    end,\n                    calc f i \u2264 f (argmax f n) :\n                        (begin\n                            apply func_argmax_ge ,\n                            rw <- nat.lt_succ_iff ,\n                            assumption ,\n                        end)\n                    ... < f (n+1) : h'\n                }\n            },\n            {\n                have h' : (f (argmax f n) \u2265 f (n + 1)) := begin\n                    apply le_of_not_gt , assumption ,\n                end,\n                by_cases (i=n+1) ,\n                {\n                    subst i , assumption ,\n                },\n                {\n                    have h2 : (i < n+1) := begin\n                        apply nat_lt_of_not_eq, linarith , assumption ,\n                    end,\n                    rw nat.lt_succ_iff at h2 ,\n                    apply func_argmax_ge , assumption,\n                }\n            },\n        }\n    end\n\ntheorem best_point_gt (n:\u2115) (l : list bool) (j:\u2115) :\n    j < 2 * n + 1 \u2192 \n    (int.of_nat n) * (int.of_nat (best_point n l)) -\n            (2*(int.of_nat n) + 1) * (int.of_nat (count_tt (list.take (best_point n l) l)))\n    \u2265\n    (int.of_nat n) * (int.of_nat j) -\n            (2*(int.of_nat n) + 1) * (int.of_nat (count_tt (list.take j l)))\n            :=\nbegin\n    rw [best_point] ,\n    intros ,\n    have ineq : j \u2264 (2*n) := begin\n        rw <- nat.lt_succ_iff , assumption ,\n    end,\n    have h := func_argmax_ge (\u03bb (i : \u2115),\n                int.of_nat n * int.of_nat i - (2 * int.of_nat n + 1) * int.of_nat (count_tt (list.take i l)))\n                (2*n) j ineq ,\n    simp at h ,\n    rw [add_comm] , assumption ,\nend\n\ntheorem negate_rotation_lt : \u2200 (n:\u2115) (i:\u2115) ,\n    0 < n \u2192 negate_rotation n i < n :=\nbegin\n    intros, rw [negate_rotation] ,\n    split_ifs , assumption , apply nat.sub_lt_self , assumption ,\n    cases i , contradiction ,\n    have h : (nat.succ i = i + 1) := rfl ,\n    rw h , linarith ,\nend\n\ntheorem compose_rotation_lt : \u2200 (n:\u2115) (i:\u2115) (j:\u2115) ,\n    0 < n \u2192 compose_rotation n i j < n :=\nbegin\n    intros , rw [compose_rotation] ,\n    apply nat.mod_lt , assumption ,\nend\n\ntheorem eq_0_of_dvd_of_lt : \u2200 (n:\u2115) (m:\u2115) ,\n    n < m \u2192 m \u2223 n \u2192 n = 0 :=\nbegin\n    intros , cases a_1 , cases a_1_w ,\n    simp at a_1_h , assumption ,\n    have h : (nat.succ a_1_w = a_1_w + 1) := rfl ,\n    rw h at a_1_h ,\n    have h2 : n > n := (\n        calc n = m * (a_1_w + 1) : a_1_h\n        ... = m * a_1_w + m*1 : by rw mul_add \n        ... = m * a_1_w + m : by simp\n        ... \u2265 m : by linarith\n        ... > n : a),\n    linarith ,\nend\n\ntheorem eq_0_of_compose_negate : \u2200 (n:\u2115) (i:\u2115) (j:\u2115) ,\n    i < n \u2192\n    j < n \u2192 \n    compose_rotation n (negate_rotation n i) j = 0 \u2192\n    i = j :=\nbegin\n    intros ,\n    rw [negate_rotation] at a_2 ,\n    rw [compose_rotation] at a_2 ,\n    split_ifs at a_2 ,\n    {\n        simp at a_2 ,\n        have h : (n \u2223 j) := begin\n            apply nat.dvd_of_mod_eq_zero , assumption ,\n        end,\n        subst i ,\n        symmetry ,\n        apply (eq_0_of_dvd_of_lt j n) , assumption, assumption ,\n    },\n    {\n        have h : (n \u2223 n - i + j) := begin\n            apply nat.dvd_of_mod_eq_zero ,\n            assumption ,\n        end,\n        clear a_2 , cases h ,\n        cases h_w,\n        {\n            /- n - i + j = 0 case (find contradiction) -/\n            have r : (n - i + j > n - i + j) := (\n                calc n - i + j \u2265 n - i + 0 : begin\n                    apply nat.add_le_add_left , linarith\n                end\n                ... = n - i : by simp\n                ... > 0: begin\n                    apply nat.sub_pos_of_lt, assumption ,\n                end\n                ... = n * 0 : begin rw mul_zero,  end\n                ... = n - i + j : by rw h_h\n            ),\n            linarith ,\n        },\n        cases h_w ,\n        {\n            /- n - i + j = n case (show i = j) -/\n            rw [mul_one] at h_h ,\n            have h2 : j + (n - i) = n := begin rw add_comm , assumption end,\n            have h3 : (j + n) - i = n := begin rw nat.add_sub_assoc , assumption , apply le_of_lt , assumption, end,\n            have h4 : (j + n) - i + i = n + i := by rw h3 ,\n            have h5 : (j + n) - i + i = (n + j) := begin\n                rw [nat.sub_add_cancel], rw [nat.add_comm], \n                linarith , \n            end,\n            have h5 : n + i = n + j := begin\n                rw <- h4 , rw <- h5 , \n            end,\n            apply (@nat.add_left_cancel n i j) , assumption ,\n        },\n        {\n            /- n - i + j \u2265 2*n case (find contradiction) -/\n            have h2 : nat.succ (nat.succ h_w) = h_w + 2 := rfl ,\n            have h3 : n - i \u2264 n := begin\n                    apply nat.sub_le_self ,\n                end,\n            rw h2 at * ,\n            have h3 : n - i + j < n - i + j := (calc\n                n - i + j \u2264 n + j : by linarith\n                ... < n + n : by linarith\n                ... \u2264 n * h_w + (n + n) : by linarith\n                ... = n * (h_w + 2) : by ring\n                ... = n - i + j : by rw h_h\n            ),\n            linarith\n        }\n    }\nend\n\ntheorem compose_compose_rotation {\u03b1 : Type} : \u2200 (l:list \u03b1) (i:\u2115) (j:\u2115) ,\n    i < list.length l \u2192\n    j < list.length l \u2192\n    list.drop i\n        (list.drop j l ++ list.take j l) ++\n      list.take i\n        (list.drop j l ++ list.take j l) =\n    list.drop (compose_rotation (list.length l) i j) l ++\n    list.take (compose_rotation (list.length l) i j) l :=\nbegin\n    intros ,\n    rw <- list.rotate_eq_take_append_drop ,\n    rw <- list.rotate_eq_take_append_drop ,\n    rw <- list.rotate_eq_take_append_drop ,\n    rw [compose_rotation] ,\n    rw list.rotate_mod ,\n    rw list.rotate_rotate , rw nat.add_comm ,\n    apply le_of_lt , apply compose_rotation_lt ,\n    linarith ,\n    apply le_of_lt , assumption ,\n    rw <- list.rotate_eq_take_append_drop ,\n    rw list.length_rotate , apply le_of_lt, assumption ,\n    apply le_of_lt, assumption,\nend\n\ntheorem negate_negate_rotation {\u03b1 : Type} : \u2200 (l:list \u03b1) (i:\u2115) ,\n    i < list.length l \u2192 \n    list.drop (negate_rotation (list.length l) i)\n        (list.drop i l ++ list.take i l) ++\n      list.take (negate_rotation (list.length l) i)\n        (list.drop i l ++ list.take i l) =\n    l :=\nbegin\n    intros ,\n    rw <- list.rotate_eq_take_append_drop ,\n    rw <- list.rotate_eq_take_append_drop ,\n    rw [negate_rotation] ,\n    split_ifs ,\n    {\n        subst i , simp , \n    },\n    {\n        rw list.rotate_rotate , rw add_comm, rw nat.sub_add_cancel ,\n        rw <- list.rotate_mod , simp , apply le_of_lt, assumption,\n    },\n    apply le_of_lt, assumption ,\n    rw <- list.rotate_eq_take_append_drop ,\n    apply le_of_lt , rw list.length_rotate ,\n    apply negate_rotation_lt , linarith , apply le_of_lt, assumption,\nend\n\ntheorem best_point_lt_length : \u2200 (n : \u2115) (l : list bool) ,\n    best_point n l < 1 + 2 * n :=\nbegin\n    intros , rw [best_point] , rw (@nat.add_comm 1 (2*n)) ,\n    apply argmax_lt_length ,\nend\n\ntheorem take_app {\u03b1 : Type} : \u2200 (a : list \u03b1) (b : list \u03b1) ,\n    list.take (list.length a) (a ++ b) = a :=\nbegin\n    intros , rw list.take_append_of_le_length , rw list.take_all ,\n    trivial ,\nend\n\ntheorem count_tt_app : \u2200 (a : list bool) (b : list bool) ,\n    (count_tt (a ++ b)) = (count_tt a) + (count_tt b) :=\nbegin\n    intros , induction a , simp [count_tt] ,\n    cases a_hd ,\n    simp [count_tt] , rw add_comm , assumption ,\n    simp [count_tt] , rw a_ih , ring , \nend\n\ntheorem take_append_of_ge_length {\u03b1 : Type} : \u2200 (i : \u2115) \n    (a : list \u03b1) (b : list \u03b1) ,\n    list.take (list.length a + i) (a ++ b) = a ++ list.take i b :=\nbegin\n    intros, induction a, simp ,\n    simp , rw (nat.add_comm 1) , rw <- nat.add_assoc , rw [list.take] ,\n    rw nat.add_comm , rw a_ih , \nend\n\ntheorem count_tt_take_drop : \u2200 (i:\u2115) (p:\u2115) (l:list bool) ,\n    i + p < list.length l \u2192 \n    int.of_nat (count_tt (list.take i (list.drop p l ++ list.take p l))) =\n    int.of_nat (count_tt (list.take (p+i) l)) -\n        int.of_nat (count_tt (list.take p l)) :=\nbegin\n    intros ,\n    rw list.take_append_of_le_length ,\n    have h : (\n            int.of_nat (count_tt (list.take i (list.drop p l))) +\n            int.of_nat (count_tt (list.take p l)) =\n            int.of_nat (count_tt (list.take (p + i) l))) :=\n        begin\n            rw add_comm ,\n            rw [<- int.of_nat_add] ,\n            rw [<- count_tt_app] ,\n            rw [<- take_append_of_ge_length] ,\n            rw [list.take_append_drop] ,\n            rw [list.length_take] ,\n            rw [min_eq_left] ,\n            linarith ,\n        end,\n    rw <- h , ring ,\n    rw list.length_drop ,\n    rw <- nat.add_le_to_le_sub ,\n    apply le_of_lt , assumption , linarith ,\nend\n\ntheorem count_tt_take_drop_2 : \u2200 (i:\u2115) (p:\u2115) (l:list bool) ,\n    p + i \u2265 list.length l \u2192 \n    i \u2264 list.length l \u2192\n    p \u2264 list.length l \u2192\n    int.of_nat (count_tt (list.take i (list.drop p l ++ list.take p l))) =\n        int.of_nat (count_tt l) -\n        int.of_nat (count_tt (list.take p l)) +\n        int.of_nat (count_tt (list.take (p+i-list.length l) l)) :=\nbegin\n    intros ,\n    have h : (i = list.length (list.drop p l) + (p+i-list.length l)) :=\n        begin\n            rw list.length_drop ,\n            have h' : int.of_nat i = int.of_nat (list.length l - p + (p + i - list.length l)) := begin\n                rw int.of_nat_add , rw int.of_nat_sub , rw int.of_nat_sub ,\n                rw int.of_nat_add , ring , assumption , assumption ,\n            end,\n            simp at h' , simp , assumption ,\n        end,\n    have h2 := (calc\n        int.of_nat (count_tt (list.take i (list.drop p l ++ list.take p l)))\n        = \n        int.of_nat (count_tt (list.take (list.length (list.drop p l) + (p+i-list.length l)) (list.drop p l ++ list.take p l))) : by rw <- h\n    ),\n    rw h2, clear h2 , clear h ,\n    rw take_append_of_ge_length ,\n    rw list.take_take , rw min_eq_left ,\n    rw count_tt_app , rw int.of_nat_add ,\n\n    have q : int.of_nat (count_tt (list.drop p l)) =\n    int.of_nat (count_tt l) - int.of_nat (count_tt (list.take p l)) :=\n        begin\n            have t :\n                int.of_nat (count_tt (list.take p l)) + int.of_nat (count_tt (list.drop p l)) = int.of_nat (count_tt l) :=\n                    begin\n                        rw <- int.of_nat_add, rw <- count_tt_app ,\n                        rw list.take_append_drop ,\n                    end,\n            rw <- t, ring ,\n        end,\n\n    rw q ,\n\n    rw nat.sub_le_iff , rw (nat.add_comm p i) , rw nat.add_sub_cancel ,\n    assumption ,\nend\n\ntheorem mul_int_of_nat_1 : \u2200 (a:\u2124) ,\n    a * (int.of_nat 1) = a :=\nbegin\n    have h : int.of_nat 1 = 1 := rfl ,\n    intros , rw h , simp ,\nend\n\n/-\n    This shows that given any path, we can rotate it to be a\n    below_diagonal_path.\n-/\n\ntheorem below_diagonal_path_rotate_best_point : \u2200 (n : \u2115) (l : list bool) ,\n    list.length l = 2*n + 1 \u2192\n    count_tt l = n \u2192\n    below_diagonal_path n (list.drop (best_point n l) l ++\n                           list.take (best_point n l) l) :=\nbegin\n    intros ,\n    rw [below_diagonal_path] ,\n    split ,\n    {\n        calc list.length (list.drop (best_point n l) l ++ list.take (best_point n l) l) =\n        list.length (list.drop (best_point n l) l) + list.length (list.take (best_point n l) l) : by simp\n        ... = list.length (list.take (best_point n l) l) + list.length (list.drop (best_point n l) l) : (by rw [nat.add_comm])\n        ... = list.length (list.take (best_point n l) l ++ list.drop (best_point n l) l) :\n            begin\n                simp , rw min_eq_left , rw nat.sub_add_cancel ,\n                apply le_of_lt , rw a , simp , apply best_point_lt_length ,\n                apply le_of_lt , rw a , simp , apply best_point_lt_length ,\n            end\n        ... = list.length (l) : by rw list.take_append_drop\n        ... = 2 * n + 1 : (by rw a)\n    },\n    split ,\n    {\n        calc count_tt (list.drop (best_point n l) l ++ list.take (best_point n l) l) =\n        count_tt (list.drop (best_point n l) l) + count_tt (list.take (best_point n l) l) : by rw count_tt_app\n        ... = count_tt (list.take (best_point n l) l) + count_tt (list.drop (best_point n l) l) : (by rw [nat.add_comm])\n        ... = count_tt (list.take (best_point n l) l ++ list.drop (best_point n l) l) : by rw count_tt_app\n        ... = count_tt (l) : by rw list.take_append_drop\n        ... = n : (by rw a_1)\n    },\n    {\n        intros ,\n\n        have j' : (\u2203 j , j = best_point n l) , existsi (best_point n l), trivial, cases j', rename j'_w p, rename j'_h p_eq ,\n        \n        rw [<- p_eq] ,\n\n        by_cases ((p+i) < 2*n + 1) ,\n        {\n            have ineq := best_point_gt n l (p + i) h,\n            rw [<- p_eq] at ineq ,\n            calc int.of_nat i * int.of_nat n -\n                (2 * int.of_nat n + 1) * int.of_nat (count_tt\n                (list.take i (list.drop p l ++ list.take p l)))\n            = int.of_nat i * int.of_nat n -\n                (2 * int.of_nat n + 1) * (\n                    int.of_nat (count_tt (list.take (p + i) l)) -\n                    int.of_nat (count_tt (list.take (p) l))\n                ) :\n                begin\n                    rw count_tt_take_drop ,\n                    rw [a, nat.add_comm] , assumption ,\n                end\n            ... =\n            (int.of_nat n * int.of_nat (p + i) - (2 * int.of_nat n + 1) * int.of_nat (count_tt (list.take (p + i) l))) - \n            (int.of_nat n * int.of_nat p - (2 * int.of_nat n + 1) * int.of_nat (count_tt (list.take p l))) :\n                begin\n                    clear ineq,\n                    simp [add_mul, int.of_nat_add, mul_add] ,\n                    apply mul_comm ,\n                end\n            ... \u2264 0 :\n                begin\n                    linarith ,\n                end\n        },\n        {\n            have ineq := best_point_gt n l (p + i - (2*n+1))\n                (begin\n                    have h : (p < (2*n+1)) := begin\n                        rw p_eq , simp , apply best_point_lt_length ,\n                    end,\n                    rw nat.sub_lt_left_iff_lt_add ,\n                    linarith , linarith ,\n                end),\n            rw [<- p_eq] at ineq ,\n\n            calc int.of_nat i * int.of_nat n - \n                (2 * int.of_nat n + 1) * int.of_nat (count_tt\n                (list.take i (list.drop p l ++ list.take p l)))\n            = int.of_nat i * int.of_nat n - \n                (2 * int.of_nat n + 1) * (\n                    int.of_nat (count_tt l) -\n                    int.of_nat (count_tt (list.take p l)) +\n                    int.of_nat (count_tt (list.take (p+i-(2*n+1)) l))\n                ) :\n                begin\n                    rw count_tt_take_drop_2 ,\n                    rw a ,\n                    linarith , linarith ,\n                    rw a , simp , rw p_eq , apply le_of_lt ,\n                    apply best_point_lt_length ,\n                end\n            ... =\n            (int.of_nat n * int.of_nat (p + i - (2*n+1)) - (2 * int.of_nat n + 1) * int.of_nat (count_tt (list.take (p + i - (2*n+1)) l))) -\n            (int.of_nat n * int.of_nat p - (2 * int.of_nat n + 1) * int.of_nat (count_tt (list.take p l))) :\n                begin\n                    clear ineq,\n                    rw a_1 ,\n                    rw int.of_nat_sub ,\n                    simp [add_mul, int.of_nat_add, mul_add, mul_int_of_nat_1, int.of_nat_mul] ,\n                    rw [int.mul_comm] ,\n                    simp ,\n                    rw (@int.mul_comm (int.of_nat n) (int.of_nat 2 * int.of_nat n)),\n                    refl,\n                    linarith ,\n                end\n            ... \u2264 0 :\n                begin\n                    linarith ,\n                end\n        }\n    }\n\nend\n\ntheorem le_add_cancel : \u2200 (a:\u2124) (b:\u2124) (c:\u2124) ,\n    a + c \u2264 b + c \u2192 a \u2264 b :=\n    begin\n        intros, linarith ,\n    end\n\ntheorem a_plus_1_ge_a : \u2200 (a:\u2124) ,\n    a < a + 1 :=\n    begin\n        intros, linarith\n    end\n\ntheorem nat_succ_a_le_b : \u2200 (a b:\u2115) ,\n    a < b \u2192 nat.succ a \u2264 b:=\n    begin\n        intros a b h,\n        have h: a + 1 \u2264 b, from nat.succ_le_of_lt h,\n        have h2: nat.succ a = a + 1 , from rfl,\n        have h3: nat.succ a \u2264 a + 1, from le_of_eq h2,\n        exact le_trans h3 h\n    end\n\ntheorem nat_le_of_int_le : \u2200 (a:\u2115) (b:\u2115) ,\n    int.of_nat a \u2264 int.of_nat b \u2192 a \u2264 b := begin\n    intros a b h,\n    induction a,\n    {induction b, {trivial}, simp[int.of_nat_zero, int.of_nat_succ]},\n    have hor: int.of_nat (nat.succ a_n) < int.of_nat b \u2228 int.of_nat (nat.succ a_n) = int.of_nat b, \n        from lt_or_eq_of_le h,\n    apply or.elim hor,\n    {intro caseh, simp[int.of_nat_succ] at caseh, \n    have transh: int.of_nat a_n < int.of_nat a_n + 1, from a_plus_1_ge_a (int.of_nat a_n),\n    have indh: int.of_nat a_n < int.of_nat b, from lt_trans transh caseh, \n    have h1: a_n \u2264 b, from a_ih (le_of_lt indh),\n    have hor: a_n < b \u2228 a_n = b, from lt_or_eq_of_le h1,\n    apply or.elim hor,\n    {intro hor1, exact nat_succ_a_le_b a_n b hor1},\n    intro hor,\n    have nexth: int.of_nat a_n = int.of_nat b, from (congr_arg _) hor,\n    have nothexth:  int.of_nat a_n \u2260  int.of_nat b, from ne_of_lt indh,\n    contradiction\n    },\n    intro caseh, rw h at *, have h1: nat.succ a_n = b, from int.no_confusion caseh id,\n    apply le_of_eq h1\n    end\n\ntheorem a_plus_a_plus_1_ge : \u2200 (a:\u2115) (b:\u2115) ,\n    a \u2265 b \u2192 a + a + 1 \u2265 b + b + 1 :=\n    begin\n        intros, linarith ,\n    end\n\n/-\n    Given a below_diagonal_path, it must end in an `ff`\n    (an edge going up) and the rest of it must be balanced.\n-/\n\ntheorem below_diagonal_path_ends_in_ff_aux :\n    \u2200 (n : \u2115) (l : list bool) (d : \u2115) (j_tt : \u2115) (j_ff : \u2115) ,\n    j_tt + j_ff + list.length l = 2*n + 1 \u2192\n    j_tt + count_tt l = n \u2192\n    j_tt = j_ff + d \u2192\n    \u00ac(l = list.nil) \u2192 \n    (forall (i:\u2115) , j_tt + j_ff \u2264 i \u2192 i \u2264 2*n + 1 \u2192\n        ((int.of_nat i) * (int.of_nat n) -\n            (2*(int.of_nat n)+1) * (int.of_nat (j_tt + count_tt (list.take (i - (j_tt + j_ff)) l))) \u2264 0)) \u2192\n    (exists t , l = t ++ [ff] \u2227 balanced_aux t d)\n| n [] d j_tt j_ff :=\n    begin\n        /- theorem only applies to non-empty lists -/\n        intros , contradiction , \n    end\n| n [ff] d j_tt j_ff :=\n    begin\n        /- list ends in ff: easy -/\n        intros , existsi list.nil , split , simp , simp at a ,\n        simp [count_tt] at a_1 , rw a_1 at * ,\n        have h := (calc\n            j_ff + (n+1) = n + (j_ff + 1) : by ring\n            ... = 1 + 2 * n : by assumption\n            ... = n + (n+1) : by ring\n        ),\n        have h2 : (j_ff = n) := add_right_cancel h ,\n        rw h2 at * ,\n        have h3 : (n + 0 = n + d) := calc n + 0 = n : by ring ... = n + d : by assumption ,\n        have h4 : (0 = d) := add_left_cancel h3 ,\n        rw <- h4 ,\n        simp [balanced_aux] ,\n    end\n| n [tt] d j_tt j_ff :=\n    begin\n        /- list ends in tt: contradiction -/\n        intros ,\n        simp at a ,\n        simp [count_tt] at a_1 ,\n        have h := a_4 (j_tt + j_ff) (by linarith) (by linarith) ,\n        simp at h , rw [count_tt] at h , simp at h ,\n        have h2 : (j_tt + j_ff = 2*n) := add_right_cancel (calc\n                j_tt + j_ff + 1 =\n                j_tt + (j_ff + 1) : by simp \n                ... = 1 + 2 * n : by assumption\n                ... = 2*n + 1 : by ring\n            ),\n        rw h2 at h ,\n        rw <- a_1 at h ,\n        simp [int.of_nat_mul, int.of_nat_add] at h ,\n        simp [mul_add] at h ,\n        linarith , \n    end\n| n (ff :: (x::l)) 0 j_tt j_ff :=\n    begin\n        /- step up crossing the diagonal: contradiction -/\n        intros ,\n        /- substitute j_tt = j_ff -/\n        simp at a_2 , rw a_2 at * ,\n        /- the point (j_ff, j_ff + 1) is above the diagonal,\n           that's where we derive the contradiction -/\n        have h := a_4 (j_ff + j_ff + 1) (by linarith)\n            (begin\n                simp at a , linarith ,\n            end),\n        rwa (@nat.add_comm (j_ff + j_ff) 1) at h,\n        rw nat.add_sub_cancel at h,\n        simp [list.take, count_tt] at h,\n        simp [int.of_nat_add, add_mul] at h,\n        rw <- add_assoc at h ,\n        /-have q : (2 * int.of_nat j_ff * int.of_nat n) = (int.of_nat j_ff * int.of_nat n) + (int.of_nat j_ff * int.of_nat n) := begin\n             rw <- two_mul ,\n            end,-/\n        have r : int.of_nat 1 = 1 := rfl ,\n        /-rw <- q at h ,-/\n        rw r at  h,\n        rw <- two_mul at h,\n        simp at h,\n        rw (mul_comm (int.of_nat j_ff) (int.of_nat n)) at h ,\n        rw mul_assoc at h ,\n        have h2 : int.of_nat n \u2264 int.of_nat j_ff := le_add_cancel (int.of_nat n) (int.of_nat j_ff) (2 * (int.of_nat n * int.of_nat j_ff)) h ,\n        have h3 : n \u2264 j_ff := nat_le_of_int_le n j_ff h2 ,\n        have h4 : 2*n + 1 > 2*n + 1 := (calc \n            2 * n + 1 = j_ff + j_ff + list.length (ff :: x :: l) : by rw a\n            ... = j_ff + j_ff + 1 + 1 + list.length l : begin\n                simp , rw <- add_assoc , simp ,\n            end\n            ... > j_ff + j_ff + 1 : by linarith\n            ... \u2265 n + n + 1 : a_plus_a_plus_1_ge j_ff n h3\n            ... = 2*n + 1 : by rw two_mul\n        ),\n        linarith ,\n    end\n| n (ff :: (x::l)) (d+1) j_tt j_ff :=\n    begin\n        /- step up without crossing the diagonal -/\n        intros ,\n        have b1 : (j_tt + (j_ff + 1) + list.length (x :: l) = 2 * n + 1) := begin\n            simp at a , simp , assumption ,\n            end,\n        have b2 : (j_tt + count_tt (x :: l) = n) := begin\n            simp [count_tt] at a_1 , assumption ,\n            end,\n        have b3 : (j_tt = j_ff + 1 + d) := begin\n            simp at a_2 , simp, assumption,\n            end,\n        have b4 : \u00ac(((x :: l) : list bool) = (list.nil : list bool)) := begin\n            simp ,\n            end,\n        have b5 : ((\u2200 (i : \u2115),\n            j_tt + (j_ff + 1) \u2264 i \u2192\n            i \u2264 2 * n + 1 \u2192\n            int.of_nat i * int.of_nat n -\n         (2 * int.of_nat n + 1) * int.of_nat (j_tt + count_tt (list.take (i - (j_tt + (j_ff + 1))) (x :: l))) \u2264 0)) :=\n            begin\n                intros ,\n                have t := a_4 i (by linarith) (by linarith) ,\n                have s : (i - (j_tt + (j_ff + 1))) + 1 = (i - (j_tt + j_ff)) := begin\n                        rw <- (add_assoc j_tt) ,\n                        rw <- nat.sub_sub ,\n                        rw nat.sub_add_cancel ,\n                        rw <- add_assoc at a_5 ,\n                        rw add_comm at a_5 ,\n                        rw nat.add_le_to_le_sub at a_5 ,\n                        assumption , linarith ,\n                    end ,\n                rw <- s at t,\n                rw [list.take] at t,\n                assumption ,\n            end,\n        have ih := below_diagonal_path_ends_in_ff_aux n (x::l) d j_tt (j_ff + 1) b1 b2 b3 b4 b5,\n        clear below_diagonal_path_ends_in_ff_aux b1 b2 b3 b4 b5 ,\n        cases ih , rename ih_w l' , existsi ((ff :: l') : list bool) ,\n        cases ih_h , split , rw ih_h_left ,\n        simp ,\n        rw [balanced_aux] , assumption ,\n    end\n| n (tt :: (x::l)) d j_tt j_ff :=\n    begin\n        intros ,\n        have b1 : (j_tt + 1 + j_ff + list.length (x :: l) = 2 * n + 1) := begin\n                simp , simp at a , assumption ,\n            end ,\n        have b2 : (j_tt + 1 + count_tt (x :: l) = n) :=\n            begin\n                simp [count_tt], simp [count_tt] at a_1 , assumption ,\n            end,\n        have b3 : (j_tt + 1 = j_ff + (d + 1)) :=\n            begin\n                rw a_2 , simp ,\n            end ,\n        have b4 : \u00ac(((x :: l) : list bool) = list.nil) :=\n            begin\n                simp ,\n            end,\n        have b5 : (\u2200 (i : \u2115),\n            j_tt + 1 + j_ff \u2264 i \u2192\n            i \u2264 2 * n + 1 \u2192\n            int.of_nat i * int.of_nat n -\n            (2 * int.of_nat n + 1) * int.of_nat (j_tt + 1 + count_tt (list.take (i - (j_tt + 1 + j_ff)) (x :: l))) \u2264\n            0) :=\n            begin\n                intros ,\n                have t := a_4 i (by linarith) (by linarith) ,\n                have s : (i - (j_tt + (j_ff + 1))) + 1 = (i - (j_tt + j_ff)) := begin\n                        rw <- (add_assoc j_tt) ,\n                        rw <- nat.sub_sub ,\n                        rw nat.sub_add_cancel ,\n                        rw (add_comm j_tt 1) at a_5 ,\n                        rw add_assoc at a_5 ,\n                        rw nat.add_le_to_le_sub at a_5 ,\n                        assumption , linarith ,\n                    end ,\n                rw <- s at t,\n                rw [list.take] at t,\n                rw [count_tt] at t,\n                rw (add_assoc j_tt 1 j_ff) ,\n                simp , simp at t ,\n                assumption ,\n            end ,\n        have ih := below_diagonal_path_ends_in_ff_aux n (x::l) (d+1) (j_tt + 1) j_ff b1 b2 b3 b4 b5 , \n        clear below_diagonal_path_ends_in_ff_aux b1 b2 b3 b4 b5,\n        cases ih ,\n        rename ih_w l' ,\n        existsi ((tt :: l') : list bool) ,\n        cases ih_h, split,\n        rw ih_h_left , simp ,\n        rw [balanced_aux], assumption,\n    end\n\ntheorem below_diagonal_path_ends_in_ff : \u2200 (n : \u2115) (l : list bool) ,\n    below_diagonal_path n l \u2192\n    (exists t , l = t ++ [ff] \u2227 balanced t) :=\nbegin\n    intros ,\n    have h : (\u2203 (t : list bool), l = t ++ [ff] \u2227 balanced_aux t 0) :=\n    begin\n        rw [below_diagonal_path] at a, cases a , cases a_right ,\n        apply (below_diagonal_path_ends_in_ff_aux n l 0 0 0) ,\n        simp , simp at a_left , assumption ,\n        simp , assumption ,\n        simp ,\n        apply not.intro , intros , rw a at * , simp at a_left ,\n        have h := (calc 0 = 1 + 2 * n : a_left ... > 0 : by linarith),\n        linarith ,\n        simp , simp at a_right_right , assumption ,\n    end,\n    cases h ,\n    existsi h_w ,\n    rw [balanced] , assumption ,\nend\n\ntheorem count_tt_of_balanced_aux : \u2200 (l : list bool) (d : \u2115) ,\n    balanced_aux l d \u2192\n    count_tt l * 2 + d = list.length l\n    | [] 0 :=\n        begin\n            intros , simp [count_tt] , \n        end\n    | [] (d + 1) :=\n        begin\n            intros , simp [balanced_aux] at a , contradiction ,\n        end\n    | (tt :: l) d :=\n        begin\n            intros , simp [count_tt] ,\n            rw add_mul , simp ,\n            have h := count_tt_of_balanced_aux l (d+1) (begin\n                    rw [balanced_aux] at a ,\n                    assumption ,\n                end),\n            linarith ,\n        end\n    | (ff :: l) 0 :=\n        begin\n            intros , simp [balanced_aux] at a , contradiction ,\n        end\n    | (ff :: l) (d + 1) :=\n        begin\n            intros , simp [count_tt] ,\n            have h := count_tt_of_balanced_aux l d (begin\n                    rw [balanced_aux] at a ,\n                    assumption ,\n                end),\n            linarith ,\n        end\n\ntheorem count_tt_drop_of_balanced_aux : \u2200 (l : list bool) (i : \u2115) (d : \u2115) ,\n    balanced_aux l d \u2192\n    i \u2264 list.length l \u2192\n    count_tt (list.drop i l) * 2 + i \u2264 list.length l\n    | [] i 0 :=\n        begin\n            intros , simp [list.drop, count_tt] , simp at a_1 ,\n            assumption ,\n        end\n    | [] i (d + 1) :=\n        begin\n            intros , rw [balanced_aux] at a , contradiction ,\n        end\n    | (tt :: l) (i+1) d :=\n        begin\n            intros ,  rw [list.drop] , rw [list.length] ,\n            rw <- add_assoc ,\n            apply add_le_add_right , \n            apply (count_tt_drop_of_balanced_aux l i (d+1)) ,\n            rw [balanced_aux] at a , assumption ,\n            simp at a_1, linarith ,\n        end\n    | (ff :: l) i 0 :=\n        begin\n            intros, rw [balanced_aux] at a , contradiction ,\n        end\n    | (ff :: l) (i + 1) (d + 1) :=\n        begin\n            intros, rw [list.drop], rw [list.length] ,\n            rw <- add_assoc ,\n            apply add_le_add_right , \n            apply (count_tt_drop_of_balanced_aux l i d) ,\n            rw [balanced_aux] at a , assumption ,\n            simp at a_1, linarith ,\n        end\n    | l 0 d :=\n        begin\n            simp [list.drop] , intros ,\n            have h := count_tt_of_balanced_aux l d a ,\n            linarith ,\n        end\n\ntheorem count_tt_drop_of_balanced : \u2200 (l : list bool) (n : \u2115) (i : \u2115) ,\n    balanced l \u2192\n    list.length l = 2 * n \u2192\n    i \u2264 list.length l \u2192\n    count_tt (list.drop i l) * 2 + i \u2264 2 * n :=\nbegin\n    intros ,\n    rw <- a_1, \n    apply (count_tt_drop_of_balanced_aux l i 0) ,\n    rw [balanced] at a, assumption ,\n    assumption ,\nend\n\ntheorem two_cancel : \u2200 (n: \u2115) (m: \u2115),\n    2*n = 2*m \u2192 n = m :=\nbegin\n    intros ,\n    have h : ((2*n) / 2) = ((2*m) / 2) := by rw a ,\n    rw mul_comm at h , rw nat.mul_div_cancel at h ,\n    rw mul_comm at h , rw nat.mul_div_cancel at h ,\n    assumption, linarith , linarith ,\nend\n\ntheorem count_tt_of_balanced : \u2200 (l : list bool) (n : \u2115) ,\n    balanced l \u2192 list.length l = 2 * n \u2192 count_tt l = n :=\nbegin\n    intros ,\n    rw [balanced] at a , \n    have h := count_tt_of_balanced_aux l 0 a,\n    simp at h ,\n    rw a_1 at h ,\n    rw mul_comm at h ,\n    exact two_cancel _ _ h ,\nend\n\ntheorem count_tt_take_of_balanced : \u2200 (l : list bool) (n : \u2115) (i : \u2115) ,\n    balanced l \u2192\n    list.length l = 2 * n \u2192\n    i \u2264 list.length l \u2192\n    count_tt (list.take i l) * 2 \u2265 i :=\nbegin\n    intros ,\n    have h := count_tt_drop_of_balanced l n i a a_1 a_2 ,\n    have j := count_tt_of_balanced l n a a_1 ,\n    have q := (calc\n        count_tt (list.take i l) + count_tt (list.drop i l) =\n        count_tt (list.take i l ++ list.drop i l) : by rw count_tt_app\n        ... = count_tt l : by rw list.take_append_drop\n        ... = n : by rw j\n    ),\n    linarith ,\nend\n\ntheorem le_of_double_le : \u2200 (a:\u2124) ,\n    2 * a \u2264 0 \u2192 a \u2264 0 := begin\n    intros, linarith ,\nend\n\ntheorem int_of_nat_ge : \u2200 (a:\u2115) (b:\u2115) ,\n    a \u2265 b \u2192\n    int.of_nat a \u2265 int.of_nat b :=\nbegin\n    /- ugh, whatever -/\n    intros, induction a, cases b , trivial ,\n    have h : (nat.succ b = b + 1) := rfl ,\n    rw h at * , linarith ,\n    have q : (nat.succ a_n = a_n + 1) := rfl ,\n    rw q at * ,\n    by_cases (a_n + 1 = b) , rw h , linarith ,\n    have r : (a_n \u2265 b) := begin\n        have s : (b < a_n + 1) := begin\n            apply nat_lt_of_not_eq , apply nat.lt_succ_of_le ,\n            assumption, apply not.intro , intros ,\n            rw a at h , contradiction ,\n        end,\n        apply nat.le_of_lt_succ , assumption ,\n    end,\n    calc int.of_nat (a_n + 1)\n        = int.of_nat a_n + int.of_nat 1 : by rw int.of_nat_add\n    ... = int.of_nat a_n + 1 : rfl\n    ... \u2265 int.of_nat a_n : by linarith\n    ... \u2265 int.of_nat b : begin\n            apply a_ih , assumption ,\n        end\nend \n\ntheorem int_of_nat_ge_zero : \u2200 (n:\u2115) ,\n    int.of_nat n \u2265 0 :=\nbegin\n    intros , trivial ,\nend\n\ntheorem a_minus_b_minus_a_le_zero : \u2200 (a:\u2124) (b:\u2115) ,\n    a + (-int.of_nat b + -a) \u2264 0 :=\nbegin\n    intros , simp ,\nend\n\ntheorem a_minus_b_minus_times_c_le : \u2200 (a:\u2124) (b:\u2124) (c:\u2124) (d:\u2124) ,\n    b \u2265 0 \u2192\n    c \u2265 d \u2192 \n    a - b * c \u2264 a - b * d :=\nbegin\n    intros ,\n    have t : b*d \u2264 b*c := begin\n        apply mul_le_mul_of_nonneg_left , assumption, assumption ,\n    end ,\n    linarith ,\nend\n\ntheorem two_n_plus_1_ge : \u2200 (a:\u2115) ,\n    2 * (int.of_nat a) + 1 \u2265 0 :=\nbegin\n    intros ,\n    have h : (int.of_nat a \u2265 0) := int_of_nat_ge_zero a ,\n    linarith ,\nend\n\n/- Given a balanced string, we can append one `ff` (up-edge or\n   parenthesis, depending on interpretation) and get a\n   below_diagonal_path. -/\n\ntheorem below_diagonal_path_of_balanced : \u2200 (n : \u2115) (l : list bool) ,\n    list.length l = 2 * n \u2192\n    balanced l \u2192\n    below_diagonal_path n (l ++ [ff]) :=\nbegin\n    intros , rw [below_diagonal_path] ,\n    split,\n    {\n        simp , assumption ,\n    },\n    split ,\n    {\n        rw count_tt_app , simp [count_tt],\n        apply count_tt_of_balanced , assumption, assumption,\n    },\n    {\n        intros ,\n        by_cases (i = 2*n + 1) ,\n        {\n            have h1 := (calc list.length (l ++ [ff]) = list.length l + 1 : by simp\n            ... = 2*n + 1 :\n                begin\n                    rw a ,\n                end\n            ... = i :\n                begin\n                    rw h ,\n                end),\n            rw <- h1, rw list.take_all , rw h1 ,\n            rw count_tt_app , simp [count_tt], \n            rw (count_tt_of_balanced l n) ,\n            rw h,\n            simp [int.of_nat_add, int.of_nat_mul] ,\n            apply le_of_eq , refl ,\n            assumption, assumption,\n        },\n        {\n            have h1 := nat_lt_of_not_eq i (2*n+1) (by linarith) (by assumption) , clear a_2 h ,\n            \n            rw list.take_append_of_le_length ,\n            have h2 := count_tt_take_of_balanced l n i a_1 a (begin\n                    rw a , apply nat.le_of_lt_succ ,  assumption ,\n                end),\n            exact (le_of_double_le _ (calc\n                2 * (int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * int.of_nat (count_tt (list.take i l)))\n                =\n                2 * int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * (2 * int.of_nat (count_tt (list.take i l))) : by ring\n                ... =\n                2 * int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * (int.of_nat 2 * int.of_nat (count_tt (list.take i l))) : rfl\n                ... = 2 * int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * (int.of_nat (2 * count_tt (list.take i l))) :\n                    begin\n                        rw int.of_nat_mul ,\n                    end\n                ... \u2264 2 * int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * (int.of_nat i) :\n                    begin\n                        apply a_minus_b_minus_times_c_le,\n                        apply two_n_plus_1_ge ,\n                        apply int_of_nat_ge ,\n                        rw mul_comm , assumption ,\n                    end\n                ... \u2264 0 :\n                    begin\n                        simp [add_mul] ,\n                        rw mul_assoc ,\n                        rw (mul_comm (int.of_nat i) (int.of_nat n)) ,\n                        rw <- mul_assoc ,\n                        simp ,\n                        apply a_minus_b_minus_a_le_zero ,\n                    end\n            )) ,\n\n            rw a , apply nat.le_of_lt_succ, assumption,\n        }\n    }\nend\n\ntheorem eq_of_le_zero : \u2200 (a:\u2124) (b:\u2124) ,\n    a \u2264 0 \u2192 b \u2264 0 \u2192 (a+b) = 0 \u2192 a = 0 := begin intros, linarith, end\n\ntheorem gcd_2_n_plus_1 : \u2200 (n:\u2115) ,\n    nat.gcd (2*n + 1) n = 1 :=\nbegin\n    intros , rw nat.gcd_comm , rw nat.gcd_rec , simp ,\n    /- casework on n=0, n=1, or n=2 -/\n    cases n ,\n    simp ,\n    cases n ,\n    simp ,\n    have h : (nat.succ (nat.succ n)) = n + 2 := rfl , rw h,\n    rw nat.mod_eq_of_lt , simp , linarith ,\nend\n\n/-\n    If one below_diagonal_path rotates to another, then the rotation\n    must be 0. This ultimately shows that each orbit of path rotations \n    contains only one below_diagonal_path.\n-/\n\ntheorem below_diagonal_rotation_is_0 : \u2200 (n : \u2115) (l : list bool) (i : \u2115) ,\n    i < (2*n + 1) \u2192\n    below_diagonal_path n l \u2192\n    below_diagonal_path n (list.drop i l ++ list.take i l) \u2192\n    i = 0 :=\nbegin\n    intros ,\n    rw [below_diagonal_path] at * ,\n    cases a_1 ,\n    cases a_1_right ,\n    cases a_2 ,\n    cases a_2_right ,\n    have h1 := a_1_right_right i (begin\n        apply le_of_lt , assumption ,\n    end),\n    have h2 := a_2_right_right ((2*n + 1) - i) (begin\n        apply nat.sub_le_self ,\n    end),\n    clear a_1_right_right , clear a_2_right_right ,\n\n    have f := (\n        calc list.length (list.drop i l) = (list.length l - i) :\n            by rw list.length_drop\n         ... = 2*n + 1 - i :\n            by rw a_1_left\n    ),\n    have e : ((list.take (2 * n + 1 - i) (list.drop i l ++ list.take i l))\n        = list.drop i l) :=\n        begin\n            rw <- f ,\n            apply take_app ,\n        end,\n    rw e at h2 ,\n    have g := (calc\n        int.of_nat (count_tt (list.drop i l)) = \n            int.of_nat (count_tt (list.take i l)) +\n            int.of_nat (count_tt (list.drop i l)) -\n            int.of_nat (count_tt (list.take i l)) : by ring\n        ... = int.of_nat (count_tt (list.take i l) + count_tt (list.drop i l)) -\n              int.of_nat (count_tt (list.take i l)) : by rw int.of_nat_add\n        ... = int.of_nat (count_tt (list.take i l ++ list.drop i l)) -\n              int.of_nat (count_tt (list.take i l)) : by rw count_tt_app\n        ... = int.of_nat (count_tt l) -\n              int.of_nat (count_tt (list.take i l)) : by rw list.take_append_drop\n        ... = int.of_nat n - int.of_nat (count_tt (list.take i l)) : by rw a_1_right_left\n    ),\n    rw g at h2 ,\n\n    /- replace int.of_nat (count_tt (list.take i l)) with x -/\n    have j' : (\u2203 j , j = (count_tt (list.take i l))) , existsi (count_tt (list.take i l)), trivial, cases j', rename j'_w x ,\n    rw <- j'_h at * ,\n\n    have sum_eq_z := (calc\n    (int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * int.of_nat x) +\n    (int.of_nat (2 * n + 1 - i) * int.of_nat n - (2 * int.of_nat n + 1) * (int.of_nat n - int.of_nat x)) = 0 : begin\n        have two_eq : 2 = int.of_nat 2 := by refl ,\n        rw two_eq ,\n        have one_eq : 1 = int.of_nat 1 := by refl ,\n        rw one_eq ,\n        simp [int.of_nat_mul, int.of_nat_add] ,\n        rw int.of_nat_sub ,\n        simp [int.of_nat_mul, int.of_nat_add] ,\n        ring ,\n        apply le_of_lt, rw add_comm, assumption,\n    end),\n\n    have eq_z := (eq_of_le_zero \n        (int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * int.of_nat x)\n    (int.of_nat (2 * n + 1 - i) * int.of_nat n - (2 * int.of_nat n + 1) * (int.of_nat n - int.of_nat x)) h1 h2 sum_eq_z) ,\n\n    have t := (calc\n        int.of_nat i * int.of_nat n\n            = int.of_nat i * int.of_nat n - 0 : by ring\n        ... = int.of_nat i * int.of_nat n -\n        (int.of_nat i * int.of_nat n - (2 * int.of_nat n + 1) * int.of_nat x) : by rw eq_z\n        ... = (2*int.of_nat n+1) * int.of_nat x : by ring\n    ),\n    have t' : (int.of_nat (i * n) = int.of_nat ((2 * n + 1) * x)) :=\n        begin\n            simp [int.of_nat_add, int.of_nat_mul] ,\n            have one' : (int.of_nat 1 = 1) := rfl ,\n            have two' : (int.of_nat 2 = 2) := rfl ,\n            rw one', rw two',\n            simp at t , assumption ,\n        end,\n    have u : i * n = (2 * n + 1) * x := begin\n            simp at t' , simp, assumption,\n        end ,\n    have gcd1 : (nat.gcd (2 * n + 1) n = 1) := gcd_2_n_plus_1 n,\n    have div0: (2 * n + 1) \u2223 (2 * n + 1) * x := begin\n        apply dvd_mul_right ,\n    end, \n    have div1 : (2 * n + 1) \u2223 (i * n) := begin\n        rw <- u at div0 , assumption ,\n    end ,\n    have div2 : (2*n + 1) \u2223 i :=\n        begin\n            apply (@nat.coprime.dvd_of_dvd_mul_right i n) ,\n            rw [nat.coprime] , assumption , assumption ,\n        end,\n    have i_eq_0 : (i = 0) := begin\n        cases div2 , cases div2_w , simp at div2_h , assumption ,\n        have i_gt_i : (i > i) :=\n            (calc i = (2 * n + 1) * nat.succ div2_w : div2_h\n               ... = (2 * n + 1) * (div2_w + 1) : by refl\n               ... = (2 * n + 1) * (1 + div2_w) : by rw [@nat.add_comm 1]\n               ... = (2 * n + 1) * 1 + (2 * n + 1) * div2_w : by rw mul_add\n               ... = (2 * n + 1) + (2 * n + 1) * div2_w : by simp\n               ... \u2265 (2 * n + 1) : by linarith\n               ... > i : by assumption\n            ),\n        linarith ,\n    end,\n    assumption ,\nend\n\ntheorem below_diagonal_rotations_eq : \u2200 (n : \u2115) (l : list bool) (l' : list bool) (i : \u2115) (i' : \u2115) ,\n    below_diagonal_path n l \u2192\n    below_diagonal_path n l' \u2192\n    i < 1 + 2 * n \u2192 \n    i' < 1 + 2 * n \u2192 \n    list.drop i l ++ list.take i l = list.drop i' l' ++ list.take i' l' \u2192 \n    l = l' \u2227 i = i' :=\nbegin\n    intros ,\n    have e := (calc\n        l = \n            list.drop (negate_rotation (1+2*n) i)\n                (list.drop i l ++ list.take i l) ++\n            list.take (negate_rotation (1+2*n) i)\n                (list.drop i l ++ list.take i l) : by\n                begin\n                    rw [below_diagonal_path] at a ,\n                    cases a ,\n                    rw nat.add_comm at a_left ,\n                    rw <- a_left ,\n                    rw [negate_negate_rotation] ,\n                    rw a_left , assumption ,\n                end\n        ... = \n            list.drop (negate_rotation (1+2*n) i)\n                (list.drop i' l' ++ list.take i' l') ++\n            list.take (negate_rotation (1+2*n) i)\n                (list.drop i' l' ++ list.take i' l') : by rw a_4\n        ... =\n            list.drop (compose_rotation (1+2*n) (negate_rotation (1+2*n) i) i') l'\n            ++\n            list.take (compose_rotation (1+2*n) (negate_rotation (1+2*n) i) i') l' : by\n            begin\n                rw [below_diagonal_path] at a_1 ,\n                cases a_1 ,\n                rw nat.add_comm at a_1_left ,\n                rw <- a_1_left ,\n                rw [compose_compose_rotation] ,\n                apply negate_rotation_lt ,\n                rw a_1_left , linarith ,\n                rw a_1_left , assumption ,\n            end\n        ) ,\n    have h : ((compose_rotation (1 + 2 * n) (negate_rotation (1 + 2 * n) i) i') = 0)\n        :=\n        (begin\n            apply (below_diagonal_rotation_is_0 n l' _) ,\n            rw nat.add_comm ,\n            apply compose_rotation_lt , linarith ,\n            assumption ,\n            rw [<- e] , assumption ,\n        end),\n    rw h at e ,\n    rw [list.drop, list.take] at e , simp at e ,\n    split ,\n    {\n        assumption ,\n    },\n    {\n        apply (eq_0_of_compose_negate (1+2*n)) ,\n        assumption, assumption, assumption ,\n    },\nend\n\n/-\n    set of `below_diagonal_path n` strings has cardinality\n    `catalan n`. This is done with the correspondence between\n    balanced parentheses strings and below_diagonal_paths.\n-/\n\ntheorem has_card_set_below_diagonal_path_catalan : \u2200 n ,\n    has_card {l : list bool | below_diagonal_path n l} (catalan n) :=\nbegin\n    intros ,\n    apply (card_bijection (set_balanced n) _\n        (catalan n)\n        (\u03bb l , l ++ [ff])) ,\n    {\n        rw set_balanced , simp , intros ,\n        apply below_diagonal_path_of_balanced , assumption , assumption ,\n    },\n    {\n        simp , intros ,\n        existsi (list.take (2*n) y) ,\n        have h := below_diagonal_path_ends_in_ff n y a ,\n        cases h , cases h_h ,\n        have e := (\n            calc list.length h_w = list.length (h_w ++ [ff]) - list.length [ff] : \n                by simp \n            ... = list.length y - list.length [ff] : by subst y\n            ... = list.length y - 1 : by simp\n            ... = (2*n + 1) - 1 : (begin\n                rw below_diagonal_path at * ,\n                cases a, \n                rw a_left ,\n            end)\n            ... = (2 * n) : by simp\n        ),\n        have e2 := (\n            calc list.take (2 * n) y = list.take (list.length h_w) y : by rw e\n            ... = list.take (list.length h_w) (h_w ++ [ff]) : by subst y\n            ... = h_w : by rw take_app\n        ),\n        rw e2 ,\n        split , rw [set_balanced] , simp , split , assumption, assumption ,\n        subst y ,\n    },\n    {\n        rw set_balanced , simp , intros ,\n        calc x = list.take (list.length x) (x ++ [ff]) : by rw take_app\n        ... = list.take (list.length x') (x' ++ [ff]) : by rw [a, a_2, a_4]\n        ... = x' : by rw take_app\n    },\n    {\n        apply has_card_set_balanced\n    },\nend\n\n/-\n    Shows that all the rotations of all the below_diagonal_path\n    strings are all unique and make up all paths. \n-/\n\ntheorem has_card_set_n_choose_k_catalan : \u2200 n ,\n    has_card (set_n_choose_k (2*n+1) n) (catalan n * (2*n+1)) :=\nbegin\n    intros ,\n    apply (card_product_nat\n        {l : list bool | below_diagonal_path n l}\n        (2*n + 1)\n        (set_n_choose_k (2*n+1) n)\n        (catalan n)\n        (\u03bb l , \u03bb i , list.drop i l ++ list.take i l)\n    ) ,\n    {\n        rw set_n_choose_k , simp , intros ,\n        split ,\n        rw below_diagonal_path at * , cases a ,\n        rw a_left ,\n        have e : min y (2 * n + 1) = y :=\n            (begin\n                apply min_eq_left , apply le_of_lt , rw nat.add_comm , assumption ,\n            end),\n        {\n            calc 2 * n + 1 - y + min y (2 * n + 1) = 2 * n + 1 - y + y : by rw e\n            ... = 2 * n + 1 :\n                begin\n                    rw nat.sub_add_cancel , apply le_of_lt , rw add_comm,\n                    assumption, \n                end\n            ... = 1 + 2 * n : by apply nat.add_comm\n        },\n        {\n            rw below_diagonal_path at a , cases a , cases a_right ,\n            calc count_tt (list.drop y x ++ list.take y x)\n                = count_tt (list.drop y x) + count_tt (list.take y x) : by rw count_tt_app\n            ... = count_tt (list.take y x) + count_tt (list.drop y x) : by rw nat.add_comm\n            ... = count_tt (list.take y x ++ list.drop y x) : by rw count_tt_app\n            ... = count_tt x : by rw list.take_append_drop\n            ... = n : by rw a_right_left\n        },\n    },\n    {\n        intros ,\n        rw set_n_choose_k at * ,\n        simp at a ,\n        cases a ,\n        simp ,\n        existsi (list.drop (best_point n z) z ++ list.take (best_point n z) z) ,\n        split ,\n        {\n            apply below_diagonal_path_rotate_best_point ,\n            rw nat.add_comm , assumption ,\n            assumption ,\n        },\n        existsi (negate_rotation (1+2*n) (best_point n z)) ,\n        split ,\n        {\n            apply negate_rotation_lt , linarith ,\n        },\n        {\n            rw [<- a_left] ,\n            apply negate_negate_rotation ,\n            rw a_left ,\n            apply best_point_lt_length ,\n        },\n    },\n    {\n        simp , intros ,\n        apply (below_diagonal_rotations_eq n x x' y y') ; assumption ,\n    },\n    {\n        apply has_card_set_below_diagonal_path_catalan ,\n    },\nend\n\n/- Our main theorem -/\n\ntheorem catalan_identity : \u2200 (n:\u2115) ,\n    catalan n * (2*n+1) = choose (2*n + 1) n :=\nbegin\n    intros ,\n    have h : has_card (set_n_choose_k (2*n+1) n) (catalan n * (2*n+1)) :=\n        has_card_set_n_choose_k_catalan n,\n    have i : has_card (set_n_choose_k (2*n+1) n) (choose (2*n+1) n) :=\n        has_card_set_n_choose_k (2*n+1) n ,\n    apply cardinality_unique (set_n_choose_k (2*n+1) n) _ _ ,\n    assumption, assumption ,\nend\n", "meta": {"author": "tjhance", "repo": "lean-project", "sha": "c00a01e02ae2fee4e90d48bfd8504d2d45fdb43c", "save_path": "github-repos/lean/tjhance-lean-project", "path": "github-repos/lean/tjhance-lean-project/lean-project-c00a01e02ae2fee4e90d48bfd8504d2d45fdb43c/catalan.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7332373405246034}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.polynomial.hasse_deriv\n\n/-!\n# Taylor expansions of polynomials\n\n## Main declarations\n\n* `polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`\n* `polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is\n  `(polynomial.hasse_deriv k f).eval r`\n* `polynomial.eq_zero_of_hasse_deriv_eq_zero`:\n  the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero\n\n-/\n\nnoncomputable theory\n\nnamespace polynomial\n\nvariables {R : Type*} [semiring R] (r : R) (f : polynomial R)\n\n/-- The Taylor expansion of a polynomial `f` at `r`. -/\ndef taylor (r : R) : polynomial R \u2192\u2097[R] polynomial R :=\n{ to_fun := \u03bb f, f.comp (X + C r),\n  map_add' := \u03bb f g, add_comp,\n  map_smul' := \u03bb c f, by simp only [smul_eq_C_mul, C_mul_comp, ring_hom.id_apply] }\n\nlemma taylor_apply : taylor r f = f.comp (X + C r) := rfl\n\n@[simp] lemma taylor_X : taylor r X = X + C r :=\nby simp only [taylor_apply, X_comp]\n\n@[simp] lemma taylor_C (x : R) : taylor r (C x) = C x :=\nby simp only [taylor_apply, C_comp]\n\n@[simp] lemma taylor_one : taylor r (1 : polynomial R) = C 1 :=\nby rw [\u2190 C_1, taylor_C]\n\n/-- The `k`th coefficient of `polynomial.taylor r f` is `(polynomial.hasse_deriv k f).eval r`. -/\nlemma taylor_coeff (n : \u2115) : (taylor r f).coeff n = (hasse_deriv n f).eval r :=\nshow (lcoeff R n).comp (taylor r) f = (leval r).comp (hasse_deriv n) f,\nbegin\n  congr' 1, clear f, ext i,\n  simp only [leval_apply, mul_one, one_mul, eval_monomial, linear_map.comp_apply, coeff_C_mul,\n    hasse_deriv_monomial, taylor_apply, monomial_comp, C_1,\n    (commute_X (C r)).add_pow i, linear_map.map_sum],\n  simp only [lcoeff_apply, \u2190 C_eq_nat_cast, mul_assoc, \u2190 C_pow, \u2190 C_mul, coeff_mul_C,\n    (nat.cast_commute _ _).eq, coeff_X_pow, boole_mul, finset.sum_ite_eq, finset.mem_range],\n  split_ifs with h, { refl },\n  push_neg at h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero],\nend\n\n@[simp] lemma taylor_coeff_zero : (taylor r f).coeff 0 = f.eval r :=\nby rw [taylor_coeff, hasse_deriv_zero, linear_map.id_apply]\n\n@[simp] lemma taylor_coeff_one : (taylor r f).coeff 1 = f.derivative.eval r :=\nby rw [taylor_coeff, hasse_deriv_one]\n\nlemma taylor_eval {R} [comm_semiring R] (r : R) (f : polynomial R) (s : R) :\n  (taylor r f).eval s = f.eval (s + r) :=\nby simp only [taylor_apply, eval_comp, eval_C, eval_X, eval_add]\n\nlemma taylor_eval_sub {R} [comm_ring R] (r : R) (f : polynomial R) (s : R) :\n  (taylor r f).eval (s - r) = f.eval s :=\nby rw [taylor_eval, sub_add_cancel]\n\nlemma taylor_injective {R} [comm_ring R] (r : R) : function.injective (taylor r) :=\nbegin\n  intros f g h,\n  apply_fun taylor (-r) at h,\n  simpa only [taylor_apply, comp_assoc, add_comp, X_comp, C_comp, C_neg,\n    neg_add_cancel_right, comp_X] using h,\nend\n\n\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/taylor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.733237334696272}}
{"text": "import tactic --hide\n\nlemma not_iff_imp_false (P : Prop) : \u00ac P \u2194 P \u2192 false := iff.rfl -- hide\nlemma contra (P Q : Prop) : (P \u2227 \u00ac P) \u2192 Q := by {cc} --hide\nlemma P_not_P_false (P : Prop) : P \u2227 \u00ac P \u2192 false := by {cc} --hide\n\n-- Level name : De Morgan's laws, First Boss\n\n/-\nIt is time to tackle our final bosses, the *De Morgans laws*. Use your tactics wisely!\n\n-/\n\n/-Hint : First Aid\n\nYou can do this only using `split`, `intro`, `apply`, `left`, `right`.\n\n-/\n\n/- Hint : Second Aid\n\nIf you have a goal `\u00acP` then `intro h` will turn your goal into `false` and give you\nan extra assumption `h : P`.\n\n-/\n\n/- Hint : Third Aid\n\nIf you have a goal `false` and an assumption `h : \u00acP`, then `apply h` will turn your goal \ninto `P`.\n\n-/\n\n/-Lemma\nIf $P,Q$ are logical statements  $\u00ac(P \u2228 Q)$ is equivalent to $\u00ac P \u2227 \u00acQ$.\n-/\n\nlemma DeMorgan_one (P Q : Prop) : \u00ac (P \u2228 Q) \u2194 \u00ac P \u2227 \u00ac Q :=\nbegin\n  split,\n  { intro h,\n    split,\n    { intro hP,\n      apply h,\n      left, \n      exact hP },\n    { intro hQ,\n      apply h,\n      right,\n      exact hQ } },\n  { intro h,\n    intro h2,\n    cases h,\n    cases h2,\n    apply h_left,\n    exact h2,\n    apply h_right,\n    exact h2,}\n    \nend\n", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic3/notlogic3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.733218064428224}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.eval\nimport tactic.interval_cases\n\n/-!\n# Theory of degrees of polynomials\n\nSome of the main results include\n- `nat_degree_comp_le` : The degree of the composition is at most the product of degrees\n\n-/\n\nnoncomputable theory\nopen_locale classical polynomial\n\nopen finsupp finset\n\nnamespace polynomial\nuniverses u v w\nvariables {R : Type u} {S : Type v} { \u03b9 : Type w} {a b : R} {m n : \u2115}\n\nsection semiring\nvariables [semiring R] {p q r : R[X]}\n\nsection degree\n\nlemma nat_degree_comp_le : nat_degree (p.comp q) \u2264 nat_degree p * nat_degree q :=\nif h0 : p.comp q = 0 then by rw [h0, nat_degree_zero]; exact nat.zero_le _\nelse with_bot.coe_le_coe.1 $\n  calc \u2191(nat_degree (p.comp q)) = degree (p.comp q) : (degree_eq_nat_degree h0).symm\n  ... = _ : congr_arg degree comp_eq_sum_left\n  ... \u2264 _ : degree_sum_le _ _\n  ... \u2264 _ : sup_le (\u03bb n hn,\n    calc degree (C (coeff p n) * q ^ n)\n        \u2264 degree (C (coeff p n)) + degree (q ^ n) : degree_mul_le _ _\n    ... \u2264 nat_degree (C (coeff p n)) + n \u2022 (degree q) :\n      add_le_add degree_le_nat_degree (degree_pow_le _ _)\n    ... \u2264 nat_degree (C (coeff p n)) + n \u2022 (nat_degree q) :\n      add_le_add_left (nsmul_le_nsmul_of_le_right (@degree_le_nat_degree _ _ q) n) _\n    ... = (n * nat_degree q : \u2115) :\n     by rw [nat_degree_C, with_bot.coe_zero, zero_add, \u2190 with_bot.coe_nsmul,\n       nsmul_eq_mul]; simp\n    ... \u2264 (nat_degree p * nat_degree q : \u2115) : with_bot.coe_le_coe.2 $\n      mul_le_mul_of_nonneg_right\n        (le_nat_degree_of_ne_zero (mem_support_iff.1 hn))\n        (nat.zero_le _))\n\nlemma degree_pos_of_root {p : R[X]} (hp : p \u2260 0) (h : is_root p a) : 0 < degree p :=\nlt_of_not_ge $ \u03bb hlt, begin\n  have := eq_C_of_degree_le_zero hlt,\n  rw [is_root, this, eval_C] at h,\n  simp only [h, ring_hom.map_zero] at this,\n  exact hp this,\nend\n\nlemma nat_degree_le_iff_coeff_eq_zero :\n  p.nat_degree \u2264 n \u2194 \u2200 N : \u2115, n < N \u2192 p.coeff N = 0 :=\nby simp_rw [nat_degree_le_iff_degree_le, degree_le_iff_coeff_zero, with_bot.coe_lt_coe]\n\nlemma nat_degree_C_mul_le (a : R) (f : R[X]) :\n  (C a * f).nat_degree \u2264 f.nat_degree :=\ncalc\n  (C a * f).nat_degree \u2264 (C a).nat_degree + f.nat_degree : nat_degree_mul_le\n  ... = 0 + f.nat_degree : by rw nat_degree_C a\n  ... = f.nat_degree : zero_add _\n\nlemma nat_degree_mul_C_le (f : R[X]) (a : R) :\n  (f * C a).nat_degree \u2264 f.nat_degree :=\ncalc\n  (f * C a).nat_degree \u2264 f.nat_degree + (C a).nat_degree : nat_degree_mul_le\n  ... = f.nat_degree + 0 : by rw nat_degree_C a\n  ... = f.nat_degree : add_zero _\n\nlemma eq_nat_degree_of_le_mem_support (pn : p.nat_degree \u2264 n) (ns : n \u2208 p.support) :\n  p.nat_degree = n :=\nle_antisymm pn (le_nat_degree_of_mem_supp _ ns)\n\nlemma nat_degree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) :\n  (C a * p).nat_degree = p.nat_degree :=\nle_antisymm (nat_degree_C_mul_le a p) (calc\n  p.nat_degree = (1 * p).nat_degree : by nth_rewrite 0 [\u2190 one_mul p]\n  ... = (C ai * (C a * p)).nat_degree : by rw [\u2190 C_1, \u2190 au, ring_hom.map_mul, \u2190 mul_assoc]\n  ... \u2264 (C a * p).nat_degree : nat_degree_C_mul_le ai (C a * p))\n\nlemma nat_degree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) :\n  (p * C a).nat_degree = p.nat_degree :=\nle_antisymm (nat_degree_mul_C_le p a) (calc\n  p.nat_degree = (p * 1).nat_degree : by nth_rewrite 0 [\u2190 mul_one p]\n  ... = ((p * C a) * C ai).nat_degree : by rw [\u2190 C_1, \u2190 au, ring_hom.map_mul, \u2190 mul_assoc]\n  ... \u2264 (p * C a).nat_degree : nat_degree_mul_C_le (p * C a) ai)\n\n/-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero`\nforce the polynomial `p` to be non-zero, via `p.leading_coeff \u2260 0`.\nLemma `nat_degree_mul_C_eq_of_no_zero_divisors` below separates cases, in order to overcome this\nhurdle.\n-/\nlemma nat_degree_mul_C_eq_of_mul_ne_zero (h : p.leading_coeff * a \u2260 0) :\n  (p * C a).nat_degree = p.nat_degree :=\nbegin\n  refine eq_nat_degree_of_le_mem_support (nat_degree_mul_C_le p a) _,\n  refine mem_support_iff.mpr _,\n  rwa coeff_mul_C,\nend\n\n/-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero`\nforce the polynomial `p` to be non-zero, via `p.leading_coeff \u2260 0`.\nLemma `nat_degree_C_mul_eq_of_no_zero_divisors` below separates cases, in order to overcome this\nhurdle.\n-/\nlemma nat_degree_C_mul_eq_of_mul_ne_zero (h : a * p.leading_coeff \u2260 0) :\n  (C a * p).nat_degree = p.nat_degree :=\nbegin\n  refine eq_nat_degree_of_le_mem_support (nat_degree_C_mul_le a p) _,\n  refine mem_support_iff.mpr _,\n  rwa coeff_C_mul,\nend\n\nlemma nat_degree_add_coeff_mul (f g : R[X]) :\n  (f * g).coeff (f.nat_degree + g.nat_degree) = f.coeff f.nat_degree * g.coeff g.nat_degree :=\nby simp only [coeff_nat_degree, coeff_mul_degree_add_degree]\n\nlemma nat_degree_lt_coeff_mul (h : p.nat_degree + q.nat_degree < m + n) :\n  (p * q).coeff (m + n) = 0 :=\ncoeff_eq_zero_of_nat_degree_lt (nat_degree_mul_le.trans_lt h)\n\n\n\nlemma nat_degree_sum_eq_of_disjoint (f : S \u2192 R[X]) (s : finset S)\n  (h : set.pairwise { i | i \u2208 s \u2227 f i \u2260 0 } (ne on (nat_degree \u2218 f))) :\n  nat_degree (s.sum f) = s.sup (\u03bb i, nat_degree (f i)) :=\nbegin\n  by_cases H : \u2203 x \u2208 s, f x \u2260 0,\n  { obtain \u27e8x, hx, hx'\u27e9 := H,\n    have hs : s.nonempty := \u27e8x, hx\u27e9,\n    refine nat_degree_eq_of_degree_eq_some _,\n    rw degree_sum_eq_of_disjoint,\n    { rw [\u2190finset.sup'_eq_sup hs, \u2190finset.sup'_eq_sup hs, finset.coe_sup', \u2190finset.sup'_eq_sup hs],\n      refine le_antisymm _ _,\n      { rw finset.sup'_le_iff,\n        intros b hb,\n        by_cases hb' : f b = 0,\n        { simpa [hb'] using hs },\n        rw degree_eq_nat_degree hb',\n        exact finset.le_sup' _ hb },\n      { rw finset.sup'_le_iff,\n        intros b hb,\n        simp only [finset.le_sup'_iff, exists_prop, function.comp_app],\n        by_cases hb' : f b = 0,\n        { refine \u27e8x, hx, _\u27e9,\n          contrapose! hx',\n          simpa [hb', degree_eq_bot] using hx' },\n        exact \u27e8b, hb, (degree_eq_nat_degree hb').ge\u27e9 } },\n    { exact h.imp (\u03bb x y hxy hxy', hxy (nat_degree_eq_of_degree_eq hxy')) } },\n  { push_neg at H,\n    rw [finset.sum_eq_zero H, nat_degree_zero, eq_comm, show 0 = \u22a5, from rfl,\n        finset.sup_eq_bot_iff],\n    intros x hx,\n    simp [H x hx] }\nend\n\nvariables [semiring S]\n\nlemma nat_degree_pos_of_eval\u2082_root {p : R[X]} (hp : p \u2260 0) (f : R \u2192+* S)\n  {z : S} (hz : eval\u2082 f z p = 0) (inj : \u2200 (x : R), f x = 0 \u2192 x = 0) :\n  0 < nat_degree p :=\nlt_of_not_ge $ \u03bb hlt, begin\n  have A : p = C (p.coeff 0) := eq_C_of_nat_degree_le_zero hlt,\n  rw [A, eval\u2082_C] at hz,\n  simp only [inj (p.coeff 0) hz, ring_hom.map_zero] at A,\n  exact hp A\nend\n\nlemma degree_pos_of_eval\u2082_root {p : R[X]} (hp : p \u2260 0) (f : R \u2192+* S)\n  {z : S} (hz : eval\u2082 f z p = 0) (inj : \u2200 (x : R), f x = 0 \u2192 x = 0) :\n  0 < degree p :=\nnat_degree_pos_iff_degree_pos.mp (nat_degree_pos_of_eval\u2082_root hp f hz inj)\n\n@[simp] lemma coe_lt_degree {p : R[X]} {n : \u2115} :\n  ((n : with_bot \u2115) < degree p) \u2194 n < nat_degree p :=\nbegin\n  by_cases h : p = 0,\n  { simp [h] },\n  rw [degree_eq_nat_degree h, with_bot.coe_lt_coe],\nend\n\nend degree\nend semiring\n\nsection no_zero_divisors\nvariables [semiring R] [no_zero_divisors R] {p q : R[X]}\n\nlemma nat_degree_mul_C_eq_of_no_zero_divisors (a0 : a \u2260 0) :\n  (p * C a).nat_degree = p.nat_degree :=\nbegin\n  by_cases p0 : p = 0,\n  { rw [p0, zero_mul] },\n  { exact nat_degree_mul_C_eq_of_mul_ne_zero (mul_ne_zero (leading_coeff_ne_zero.mpr p0) a0) }\nend\n\nlemma nat_degree_C_mul_eq_of_no_zero_divisors (a0 : a \u2260 0) :\n  (C a * p).nat_degree = p.nat_degree :=\nbegin\n  by_cases p0 : p = 0,\n  { rw [p0, mul_zero] },\n  { exact nat_degree_C_mul_eq_of_mul_ne_zero (mul_ne_zero a0 (leading_coeff_ne_zero.mpr p0)) }\nend\n\nlemma nat_degree_comp : nat_degree (p.comp q) = nat_degree p * nat_degree q :=\nbegin\n  by_cases q0 : q.nat_degree = 0,\n  { rw [degree_le_zero_iff.mp (nat_degree_eq_zero_iff_degree_le_zero.mp q0), comp_C, nat_degree_C,\n      nat_degree_C, mul_zero] },\n  { by_cases p0 : p = 0, { simp only [p0, zero_comp, nat_degree_zero, zero_mul] },\n    refine le_antisymm nat_degree_comp_le (le_nat_degree_of_ne_zero _),\n    simp only [coeff_comp_degree_mul_degree q0, p0, mul_eq_zero, leading_coeff_eq_zero, or_self,\n      ne_zero_of_nat_degree_gt (nat.pos_of_ne_zero q0), pow_ne_zero, ne.def, not_false_iff] }\nend\n\nlemma leading_coeff_comp (hq : nat_degree q \u2260 0) :\n  leading_coeff (p.comp q) = leading_coeff p * leading_coeff q ^ nat_degree p :=\nby rw [\u2190 coeff_comp_degree_mul_degree hq, \u2190 nat_degree_comp, coeff_nat_degree]\n\nend no_zero_divisors\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/polynomial/degree/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.733200180512949}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport data.polynomial.ring_division\nimport dynamics.periodic_pts\n\n/-!\n# IMO 2006 Q5\n\nLet $P(x)$ be a polynomial of degree $n>1$ with integer coefficients, and let $k$ be a positive\ninteger. Consider the polynomial $Q(x) = P(P(\\ldots P(P(x))\\ldots))$, where $P$ occurs $k$ times.\nProve that there are at most $n$ integers $t$ such that $Q(t)=t$.\n\n## Sketch of solution\n\nThe following solution is adapted from\nhttps://artofproblemsolving.com/wiki/index.php/2006_IMO_Problems/Problem_5.\n\nLet $P^k$ denote the polynomial $P$ composed with itself $k$ times. We rely on a key observation: if\n$P^k(t)=t$, then $P(P(t))=t$. We prove this by building the cyclic list\n$(P(t)-t,P^2(t)-P(t),\\ldots)$, and showing that each entry divides the next, which by transitivity\nimplies they all divide each other, and thus have the same absolute value.\n\nIf the entries in this list are all pairwise equal, then we can show inductively that for positive\n$n$, $P^n(t)-t$ must always have the same sign as $P(t)-t$. Substituting $n=k$ gives us $P(t)=t$ and\nin particular $P(P(t))=t$.\n\nOtherwise, there must be two consecutive entries that are opposites of one another. This means\n$P^{n+2}(t)-P^{n+1}(t)=P^n(t)-P^{n+1}(t)$, which implies $P^{n+2}(t)=P^n(t)$ and $P(P(t))=t$.\n\nWith this lemma, we can reduce the problem to the case $k=2$. If every root of $P(P(t))-t$ is also a\nroot of $P(t)-t$, then we're done. Otherwise, there exist $a$ and $b$ with $a\\ne b$ and $P(a)=b$,\n$P(b)=a$. For any root $t$ of $P(P(t))-t$, defining $u=P(t)$, we easily verify $a-t\\mid b-u$,\n$b-u\\mid a-t$, $a-u\\mid b-t$, $b-t\\mid a-u$, which imply $|a-t|=|b-u|$ and $|a-u|=|b-t|$. By casing\non these equalities, we deduce $a+b=t+u$. This means that every root of $P(P(t))-t$ is a root of\n$P(t)+t-a-b$, and we're again done.\n-/\n\nopen function polynomial\n\n/-- If every entry in a cyclic list of integers divides the next, then they all have the same\nabsolute value. -/\ntheorem int.nat_abs_eq_of_chain_dvd {l : cycle \u2124} {x y : \u2124} (hl : l.chain (\u2223))\n  (hx : x \u2208 l) (hy : y \u2208 l) : x.nat_abs = y.nat_abs :=\nbegin\n  rw cycle.chain_iff_pairwise at hl,\n  exact int.nat_abs_eq_of_dvd_dvd (hl x hx y hy) (hl y hy x hx)\nend\n\ntheorem int.add_eq_add_of_nat_abs_eq_of_nat_abs_eq {a b c d : \u2124} (hne : a \u2260 b)\n  (h\u2081 : (c - a).nat_abs = (d - b).nat_abs) (h\u2082 : (c - b).nat_abs = (d - a).nat_abs) :\n  a + b = c + d :=\nbegin\n  cases int.nat_abs_eq_nat_abs_iff.1 h\u2081 with h\u2081 h\u2081,\n  { cases int.nat_abs_eq_nat_abs_iff.1 h\u2082 with h\u2082 h\u2082,\n    { exact (hne $ by linarith).elim },\n    { linarith } },\n  { linarith }\nend\n\n/-- The main lemma in the proof: if $P^k(t)=t$, then $P(P(t))=t$. -/\ntheorem polynomial.is_periodic_pt_eval_two {P : polynomial \u2124} {t : \u2124}\n  (ht : t \u2208 periodic_pts (\u03bb x, P.eval x)) : is_periodic_pt (\u03bb x, P.eval x) 2 t :=\nbegin\n  -- The cycle [P(t) - t, P(P(t)) - P(t), ...]\n  let C : cycle \u2124 := (periodic_orbit (\u03bb x, P.eval x) t).map (\u03bb x, P.eval x - x),\n  have HC : \u2200 {n : \u2115}, (\u03bb x, P.eval x)^[n + 1] t - ((\u03bb x, P.eval x)^[n] t) \u2208 C,\n  { intro n,\n    rw [cycle.mem_map, function.iterate_succ_apply'],\n    exact \u27e8_, iterate_mem_periodic_orbit ht n, rfl\u27e9 },\n\n  -- Elements in C are all divisible by one another.\n  have Hdvd : C.chain (\u2223),\n  { rw [cycle.chain_map, periodic_orbit_chain' _ ht],\n    intro n,\n    convert sub_dvd_eval_sub ((\u03bb x, P.eval x)^[n + 1] t) ((\u03bb x, P.eval x)^[n] t) P;\n    rw function.iterate_succ_apply' },\n\n  -- Any two entries in C have the same absolute value.\n  have Habs : \u2200 m n : \u2115, ((\u03bb x, P.eval x)^[m + 1] t - ((\u03bb x, P.eval x)^[m] t)).nat_abs =\n    ((\u03bb x, P.eval x)^[n + 1] t - ((\u03bb x, P.eval x)^[n] t)).nat_abs :=\n  \u03bb m n, int.nat_abs_eq_of_chain_dvd Hdvd HC HC,\n\n  -- We case on whether the elements on C are pairwise equal.\n  by_cases HC' : C.chain (=),\n  { -- Any two entries in C are equal.\n    have Heq : \u2200 m n : \u2115, (\u03bb x, P.eval x)^[m + 1] t - ((\u03bb x, P.eval x)^[m] t) =\n      ((\u03bb x, P.eval x)^[n + 1] t - ((\u03bb x, P.eval x)^[n] t)) :=\n    \u03bb m n, cycle.chain_iff_pairwise.1 HC' _ HC _ HC,\n\n    -- The sign of P^n(t) - t is the same as P(t) - t for positive n. Proven by induction on n.\n    have IH : \u2200 n : \u2115, ((\u03bb x, P.eval x)^[n + 1] t - t).sign = (P.eval t - t).sign,\n    { intro n,\n      induction n with n IH,\n      { refl },\n      { apply eq.trans _ (int.sign_add_eq_of_sign_eq IH),\n        have H := Heq n.succ 0,\n        dsimp at H \u22a2,\n        rw [\u2190H, sub_add_sub_cancel'] } },\n\n    -- This implies that the sign of P(t) - t is the same as the sign of P^k(t) - t, which is 0.\n    -- Hence P(t) = t and P(P(t)) = P(t).\n    rcases ht with \u27e8(_ | k), hk, hk'\u27e9,\n    { exact (irrefl 0 hk).elim },\n    { have H := IH k,\n      rw [hk'.is_fixed_pt.eq, sub_self, int.sign_zero, eq_comm, int.sign_eq_zero_iff_zero,\n        sub_eq_zero] at H,\n      simp [is_periodic_pt, is_fixed_pt, H] } },\n  { -- We take two nonequal consecutive entries.\n    rw [cycle.chain_map, periodic_orbit_chain' _ ht] at HC',\n    push_neg at HC',\n    cases HC' with n hn,\n\n    -- They must have opposite sign, so that P^{k + 1}(t) - P^k(t) = P^{k + 2}(t) - P^{k + 1}(t).\n    cases int.nat_abs_eq_nat_abs_iff.1 (Habs n n.succ) with hn' hn',\n    { apply (hn _).elim,\n      convert hn';\n      simp only [function.iterate_succ_apply'] },\n\n    -- We deduce P^{k + 2}(t) = P^k(t) and hence P(P(t)) = t.\n    { rw [neg_sub, sub_right_inj] at hn',\n      simp only [function.iterate_succ_apply'] at hn',\n      exact @is_periodic_pt_of_mem_periodic_pts_of_is_periodic_pt_iterate _ _ t 2 n ht hn'.symm } }\nend\n\ntheorem polynomial.iterate_comp_sub_X_ne {P : polynomial \u2124} (hP : 1 < P.nat_degree) {k : \u2115}\n  (hk : 0 < k) : P.comp^[k] X - X \u2260 0 :=\nby { rw sub_ne_zero, apply_fun nat_degree, simpa using (one_lt_pow hP hk.ne').ne' }\n\n/-- We solve the problem for the specific case k = 2 first. -/\ntheorem imo2006_q5' {P : polynomial \u2124} (hP : 1 < P.nat_degree) :\n  (P.comp P - X).roots.to_finset.card \u2264 P.nat_degree :=\nbegin\n  -- Auxiliary lemmas on degrees.\n  have hPX : (P - X).nat_degree = P.nat_degree,\n  { rw nat_degree_sub_eq_left_of_nat_degree_lt,\n    simpa using hP },\n  have hPX' : P - X \u2260 0,\n  { intro h,\n    rw [h, nat_degree_zero] at hPX,\n    rw \u2190hPX at hP,\n    exact (zero_le_one.not_lt hP).elim },\n\n  -- If every root of P(P(t)) - t is also a root of P(t) - t, then we're done.\n  by_cases H : (P.comp P - X).roots.to_finset \u2286 (P - X).roots.to_finset,\n  { exact (finset.card_le_of_subset H).trans ((multiset.to_finset_card_le _).trans\n      ((card_roots' _).trans_eq hPX)) },\n\n  -- Otherwise, take a, b with P(a) = b, P(b) = a, a \u2260 b.\n  { rcases finset.not_subset.1 H with \u27e8a, ha, hab\u27e9,\n    replace ha := is_root_of_mem_roots (multiset.mem_to_finset.1 ha),\n    simp [sub_eq_zero] at ha,\n    simp [mem_roots hPX'] at hab,\n    set b := P.eval a,\n    rw sub_eq_zero at hab,\n\n    -- More auxiliary lemmas on degrees.\n    have hPab : (P + X - a - b).nat_degree = P.nat_degree,\n    { rw [sub_sub, \u2190int.cast_add],\n      have h\u2081 : (P + X).nat_degree = P.nat_degree,\n      { rw nat_degree_add_eq_left_of_nat_degree_lt,\n        simpa using hP },\n      rw nat_degree_sub_eq_left_of_nat_degree_lt;\n      rwa h\u2081,\n      rw nat_degree_int_cast,\n      exact zero_lt_one.trans hP },\n    have hPab' : P + X - a - b \u2260 0,\n    { intro h,\n      rw [h, nat_degree_zero] at hPab,\n      rw \u2190hPab at hP,\n      exact (zero_le_one.not_lt hP).elim },\n\n    -- We claim that every root of P(P(t)) - t is a root of P(t) + t - a - b. This allows us to\n    -- conclude the problem.\n    suffices H' : (P.comp P - X).roots.to_finset \u2286 (P + X - a - b).roots.to_finset,\n    { exact (finset.card_le_of_subset H').trans ((multiset.to_finset_card_le _).trans $\n        (card_roots' _).trans_eq hPab) },\n\n    { -- Let t be a root of P(P(t)) - t, define u = P(t).\n      intros t ht,\n      replace ht := is_root_of_mem_roots (multiset.mem_to_finset.1 ht),\n      simp [sub_eq_zero] at ht,\n      simp only [mem_roots hPab', sub_eq_iff_eq_add, multiset.mem_to_finset, is_root.def, eval_sub,\n        eval_add, eval_X, eval_C, eval_int_cast, int.cast_id, zero_add],\n\n      -- An auxiliary lemma proved earlier implies we only need to show |t - a| = |u - b| and\n      -- |t - b| = |u - a|. We prove this by establishing that each side of either equation divides\n      -- the other.\n      apply (int.add_eq_add_of_nat_abs_eq_of_nat_abs_eq hab _ _).symm;\n      apply int.nat_abs_eq_of_dvd_dvd;\n      set u := P.eval t,\n      { rw [\u2190ha, \u2190ht], apply sub_dvd_eval_sub },\n      { apply sub_dvd_eval_sub },\n      { rw \u2190ht, apply sub_dvd_eval_sub },\n      { rw \u2190ha, apply sub_dvd_eval_sub } } }\nend\n\n/-- The general problem follows easily from the k = 2 case. -/\ntheorem imo2006_q5 {P : polynomial \u2124} (hP : 1 < P.nat_degree) {k : \u2115} (hk : 0 < k) :\n  (P.comp^[k] X - X).roots.to_finset.card \u2264 P.nat_degree :=\nbegin\n  apply (finset.card_le_of_subset $ \u03bb t ht, _).trans (imo2006_q5' hP),\n  have hP' : P.comp P - X \u2260 0 := by simpa using polynomial.iterate_comp_sub_X_ne hP zero_lt_two,\n  replace ht := is_root_of_mem_roots (multiset.mem_to_finset.1 ht),\n  simp only [sub_eq_zero, is_root.def, eval_sub, iterate_comp_eval, eval_X] at ht,\n  simpa [mem_roots hP', sub_eq_zero] using polynomial.is_periodic_pt_eval_two \u27e8k, hk, ht\u27e9\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2006_q5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.733200174288223}}
{"text": "import ..lectures.love01_definitions_and_statements_demo\n\n\n/-! # LoVe Homework 1: Definitions and Statements\n\nHomework must be done individually.\n\nReplace the placeholders (e.g., `:= sorry`) with your solutions. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (1 point): Fibonacci Numbers\n\n1.1 (1 point). Define the function `fib` that computes the Fibonacci\nnumbers. -/\n\ndef fib : \u2115 \u2192 \u2115 :=\nsorry\n\n/-! 1.2 (0 points). Check that your function works as expected. -/\n\n#eval fib 0   -- expected: 0\n#eval fib 1   -- expected: 1\n#eval fib 2   -- expected: 1\n#eval fib 3   -- expected: 2\n#eval fib 4   -- expected: 3\n#eval fib 5   -- expected: 5\n#eval fib 6   -- expected: 8\n#eval fib 7   -- expected: 13\n#eval fib 8   -- expected: 21\n\n\n/-! # Question 2 (5 points): Lists - Singletons and Flatten\n\n2.1 (1 point). Define the function `singletons` that turns a list into a list of\nsingleton lists, where the singleton at each position contains the element in\nthat position in the original list.\n\nFor instance, `singletons [1, 2, 3, 4]` should evaluate to\n`[[1], [2], [3], [4]]`.\n-/\n\ndef singletons {\u03b1 : Type} : list \u03b1 \u2192 list (list \u03b1) :=\nsorry\n\n/-! 2.2 (2 points). Define the function `flatten` that takes a list of lists and\n\"flattens\" it into a single list containing all of the elements of the inner\nlists.\n\nFor example, `flatten [[1], [2, 3], [], [4]]` should evaluate to `[1, 2, 3, 4]`.\n\nYou should not call any form of append function (`(++)`, `list.append`, etc.) in\nyour solution.\n-/\n\ndef flatten {\u03b1 : Type} : list (list \u03b1) \u2192 list \u03b1 :=\nsorry\n\n/-! 2.3 (1 point). State a theorem that says that applying `singletons` and then\n    `flatten` to any list gives the same list you started with.\n-/\n\n-- Replace `true` with your lemma statement. No need to fill in the `sorry`!\nlemma flatten_singletons : true := sorry\n\n/-! 2.4 (1 point). Is it true that applying `flatten` and then `singletons` to a\nlist gives you back the same list you started with? If so, explain why; if not,\nprovide an example of a list for which this claim does not hold.\n-/\n\n/-\nWrite your response to part 4 here.\n-/\n\n\n/-! ## Question 3 (5 points): \u03bb-Terms\n\n3.1 (2 points). Complete the following definitions, by replacing the `sorry`\nplaceholders by terms of the expected type.\n\nPlease use reasonable names for the bound variables, e.g., `a : \u03b1`, `b : \u03b2`,\n`c : \u03b3`.\n\nHint: A procedure for doing so systematically is described in Section 1.1.4 of\nthe Hitchhiker's Guide. As explained there, you can use `_` as a placeholder\nwhile constructing a term. By hovering over `_`, you will see the current\nlogical context. -/\n\ndef B : (\u03b1 \u2192 \u03b2) \u2192 (\u03b3 \u2192 \u03b1) \u2192 \u03b3 \u2192 \u03b2 :=\nsorry\n\ndef S : (\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 (\u03b1 \u2192 \u03b2) \u2192 \u03b1 \u2192 \u03b3 :=\nsorry\n\ndef more_nonsense : (\u03b3 \u2192 (\u03b1 \u2192 \u03b2) \u2192 \u03b1) \u2192 \u03b3 \u2192 \u03b2 \u2192 \u03b1 :=\nsorry\n\ndef even_more_nonsense : (\u03b1 \u2192 \u03b1 \u2192 \u03b2) \u2192 (\u03b2 \u2192 \u03b3) \u2192 \u03b1 \u2192 \u03b2 \u2192 \u03b3 :=\nsorry\n\n/-! 3.2 (1 point). Complete the following definition.\n\nThis one looks more difficult, but it should be fairly straightforward if you\nfollow the procedure described in the Hitchhiker's Guide.\n\nNote: Peirce is pronounced like the English word \"purse\". -/\n\ndef weak_peirce : ((((\u03b1 \u2192 \u03b2) \u2192 \u03b1) \u2192 \u03b1) \u2192 \u03b2) \u2192 \u03b2 :=\nsorry\n\n/-! 3.3 (2 points). Show the typing derivation for your definition of `S` above,\nusing ASCII or Unicode art. You might find the characters `\u2013` (to draw\nhorizontal bars) and `\u22a2` useful.\n\nFeel free to introduce abbreviations to avoid repeating large contexts `C`. -/\n\n-- write your solution here\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/homework/love01_definitions_and_statements_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826789824086, "lm_q2_score": 0.8438951104066295, "lm_q1q2_score": 0.7331986797228345}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Manuel Candales\n-/\nimport analysis.inner_product_space.projection\nimport algebra.quadratic_discriminant\n\n/-!\n# Euclidean spaces\n\nThis file makes some definitions and proves very basic geometrical\nresults about real inner product spaces and Euclidean affine spaces.\nResults about real inner product spaces that involve the norm and\ninner product but not angles generally go in\n`analysis.normed_space.inner_product`.  Results with longer\nproofs or more geometrical content generally go in separate files.\n\n## Main definitions\n\n* `euclidean_geometry.orthogonal_projection` is the orthogonal\n  projection of a point onto an affine subspace.\n\n* `euclidean_geometry.reflection` is the reflection of a point in an\n  affine subspace.\n\n## Implementation notes\n\nTo declare `P` as the type of points in a Euclidean affine space with\n`V` as the type of vectors, use\n`[normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]`.\nThis works better with `out_param` to make\n`V` implicit in most cases than having a separate type alias for\nEuclidean affine spaces.\n\nRather than requiring Euclidean affine spaces to be finite-dimensional\n(as in the definition on Wikipedia), this is specified only for those\ntheorems that need it.\n\n## References\n\n* https://en.wikipedia.org/wiki/Euclidean_space\n\n-/\n\nnoncomputable theory\nopen_locale big_operators\nopen_locale classical\nopen_locale real_inner_product_space\n\nnamespace euclidean_geometry\n/-!\n### Geometrical results on Euclidean affine spaces\n\nThis section develops some geometrical definitions and results on\nEuclidean affine spaces.\n-/\n\nvariables {V : Type*} {P : Type*}\nvariables [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P]\nvariables [normed_add_torsor V P]\ninclude V\n\n/-- The midpoint of the segment AB is the same distance from A as it is from B. -/\nlemma dist_left_midpoint_eq_dist_right_midpoint (p1 p2 : P) :\n  dist p1 (midpoint \u211d p1 p2) = dist p2 (midpoint \u211d p1 p2) :=\nby rw [dist_left_midpoint p1 p2, dist_right_midpoint p1 p2]\n\n/-- The inner product of two vectors given with `weighted_vsub`, in\nterms of the pairwise distances. -/\nlemma inner_weighted_vsub {\u03b9\u2081 : Type*} {s\u2081 : finset \u03b9\u2081} {w\u2081 : \u03b9\u2081 \u2192 \u211d} (p\u2081 : \u03b9\u2081 \u2192 P)\n    (h\u2081 : \u2211 i in s\u2081, w\u2081 i = 0) {\u03b9\u2082 : Type*} {s\u2082 : finset \u03b9\u2082} {w\u2082 : \u03b9\u2082 \u2192 \u211d} (p\u2082 : \u03b9\u2082 \u2192 P)\n    (h\u2082 : \u2211 i in s\u2082, w\u2082 i = 0) :\n  \u27eas\u2081.weighted_vsub p\u2081 w\u2081, s\u2082.weighted_vsub p\u2082 w\u2082\u27eb =\n    (-\u2211 i\u2081 in s\u2081, \u2211 i\u2082 in s\u2082,\n      w\u2081 i\u2081 * w\u2082 i\u2082 * (dist (p\u2081 i\u2081) (p\u2082 i\u2082) * dist (p\u2081 i\u2081) (p\u2082 i\u2082))) / 2 :=\nbegin\n  rw [finset.weighted_vsub_apply, finset.weighted_vsub_apply,\n      inner_sum_smul_sum_smul_of_sum_eq_zero _ h\u2081 _ h\u2082],\n  simp_rw [vsub_sub_vsub_cancel_right],\n  rcongr i\u2081 i\u2082; rw dist_eq_norm_vsub V (p\u2081 i\u2081) (p\u2082 i\u2082)\nend\n\n/-- The distance between two points given with `affine_combination`,\nin terms of the pairwise distances between the points in that\ncombination. -/\n\n\n/-- Suppose that `c\u2081` is equidistant from `p\u2081` and `p\u2082`, and the same\napplies to `c\u2082`.  Then the vector between `c\u2081` and `c\u2082` is orthogonal\nto that between `p\u2081` and `p\u2082`.  (In two dimensions, this says that the\ndiagonals of a kite are orthogonal.) -/\nlemma inner_vsub_vsub_of_dist_eq_of_dist_eq {c\u2081 c\u2082 p\u2081 p\u2082 : P} (hc\u2081 : dist p\u2081 c\u2081 = dist p\u2082 c\u2081)\n  (hc\u2082 : dist p\u2081 c\u2082 = dist p\u2082 c\u2082) : \u27eac\u2082 -\u1d65 c\u2081, p\u2082 -\u1d65 p\u2081\u27eb = 0 :=\nbegin\n  have h : \u27ea(c\u2082 -\u1d65 c\u2081) + (c\u2082 -\u1d65 c\u2081), p\u2082 -\u1d65 p\u2081\u27eb = 0,\n  { conv_lhs { congr, congr, rw \u2190vsub_sub_vsub_cancel_right c\u2082 c\u2081 p\u2081,\n               skip, rw \u2190vsub_sub_vsub_cancel_right c\u2082 c\u2081 p\u2082 },\n    rw [sub_add_sub_comm, inner_sub_left],\n    conv_lhs { congr, rw \u2190vsub_sub_vsub_cancel_right p\u2082 p\u2081 c\u2082,\n               skip, rw \u2190vsub_sub_vsub_cancel_right p\u2082 p\u2081 c\u2081 },\n    rw [dist_comm p\u2081, dist_comm p\u2082, dist_eq_norm_vsub V _ p\u2081,\n        dist_eq_norm_vsub V _ p\u2082, \u2190real_inner_add_sub_eq_zero_iff] at hc\u2081 hc\u2082,\n    simp_rw [\u2190neg_vsub_eq_vsub_rev c\u2081, \u2190neg_vsub_eq_vsub_rev c\u2082, sub_neg_eq_add,\n             neg_add_eq_sub, hc\u2081, hc\u2082, sub_zero] },\n  simpa [inner_add_left, \u2190mul_two, (by norm_num : (2 : \u211d) \u2260 0)] using h\nend\n\n/-- The squared distance between points on a line (expressed as a\nmultiple of a fixed vector added to a point) and another point,\nexpressed as a quadratic. -/\nlemma dist_smul_vadd_sq (r : \u211d) (v : V) (p\u2081 p\u2082 : P) :\n  dist (r \u2022 v +\u1d65 p\u2081) p\u2082 * dist (r \u2022 v +\u1d65 p\u2081) p\u2082 =\n    \u27eav, v\u27eb * r * r + 2 * \u27eav, p\u2081 -\u1d65 p\u2082\u27eb * r + \u27eap\u2081 -\u1d65 p\u2082, p\u2081 -\u1d65 p\u2082\u27eb :=\nbegin\n  rw [dist_eq_norm_vsub V _ p\u2082, \u2190real_inner_self_eq_norm_mul_norm, vadd_vsub_assoc,\n    real_inner_add_add_self, real_inner_smul_left, real_inner_smul_left, real_inner_smul_right],\n  ring\nend\n\n/-- The condition for two points on a line to be equidistant from\nanother point. -/\nlemma dist_smul_vadd_eq_dist {v : V} (p\u2081 p\u2082 : P) (hv : v \u2260 0) (r : \u211d) :\n  dist (r \u2022 v +\u1d65 p\u2081) p\u2082 = dist p\u2081 p\u2082 \u2194 (r = 0 \u2228 r = -2 * \u27eav, p\u2081 -\u1d65 p\u2082\u27eb / \u27eav, v\u27eb) :=\nbegin\n  conv_lhs { rw [\u2190mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_smul_vadd_sq,\n                 \u2190sub_eq_zero, add_sub_assoc, dist_eq_norm_vsub V p\u2081 p\u2082,\n                 \u2190real_inner_self_eq_norm_mul_norm, sub_self] },\n  have hvi : \u27eav, v\u27eb \u2260 0, by simpa using hv,\n  have hd : discrim \u27eav, v\u27eb (2 * \u27eav, p\u2081 -\u1d65 p\u2082\u27eb) 0 =\n    (2 * \u27eav, p\u2081 -\u1d65 p\u2082\u27eb) * (2 * \u27eav, p\u2081 -\u1d65 p\u2082\u27eb),\n  { rw discrim, ring },\n  rw [quadratic_eq_zero_iff hvi hd, add_left_neg, zero_div, neg_mul_eq_neg_mul,\n      \u2190mul_sub_right_distrib, sub_eq_add_neg, \u2190mul_two, mul_assoc, mul_div_assoc,\n      mul_div_mul_left, mul_div_assoc],\n  norm_num\nend\n\nopen affine_subspace finite_dimensional\n\n/-- Distances `r\u2081` `r\u2082` of `p` from two different points `c\u2081` `c\u2082` determine at\nmost two points `p\u2081` `p\u2082` in a two-dimensional subspace containing those points\n(two circles intersect in at most two points). -/\nlemma eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two {s : affine_subspace \u211d P}\n  [finite_dimensional \u211d s.direction] (hd : finrank \u211d s.direction = 2) {c\u2081 c\u2082 p\u2081 p\u2082 p : P}\n  (hc\u2081s : c\u2081 \u2208 s) (hc\u2082s : c\u2082 \u2208 s) (hp\u2081s : p\u2081 \u2208 s) (hp\u2082s : p\u2082 \u2208 s) (hps : p \u2208 s) {r\u2081 r\u2082 : \u211d}\n  (hc : c\u2081 \u2260 c\u2082) (hp : p\u2081 \u2260 p\u2082) (hp\u2081c\u2081 : dist p\u2081 c\u2081 = r\u2081) (hp\u2082c\u2081 : dist p\u2082 c\u2081 = r\u2081)\n  (hpc\u2081 : dist p c\u2081 = r\u2081) (hp\u2081c\u2082 : dist p\u2081 c\u2082 = r\u2082) (hp\u2082c\u2082 : dist p\u2082 c\u2082 = r\u2082)\n  (hpc\u2082 : dist p c\u2082 = r\u2082) : p = p\u2081 \u2228 p = p\u2082 :=\nbegin\n  have ho : \u27eac\u2082 -\u1d65 c\u2081, p\u2082 -\u1d65 p\u2081\u27eb = 0 :=\n    inner_vsub_vsub_of_dist_eq_of_dist_eq (hp\u2081c\u2081.trans hp\u2082c\u2081.symm) (hp\u2081c\u2082.trans hp\u2082c\u2082.symm),\n  have hop : \u27eac\u2082 -\u1d65 c\u2081, p -\u1d65 p\u2081\u27eb = 0 :=\n    inner_vsub_vsub_of_dist_eq_of_dist_eq (hp\u2081c\u2081.trans hpc\u2081.symm) (hp\u2081c\u2082.trans hpc\u2082.symm),\n  let b : fin 2 \u2192 V := ![c\u2082 -\u1d65 c\u2081, p\u2082 -\u1d65 p\u2081],\n  have hb : linear_independent \u211d b,\n  { refine linear_independent_of_ne_zero_of_inner_eq_zero _ _,\n    { intro i,\n      fin_cases i; simp [b, hc.symm, hp.symm], },\n    { intros i j hij,\n      fin_cases i; fin_cases j; try { exact false.elim (hij rfl) },\n      { exact ho },\n      { rw real_inner_comm, exact ho } } },\n  have hbs : submodule.span \u211d (set.range b) = s.direction,\n  { refine eq_of_le_of_finrank_eq _ _,\n    { rw [submodule.span_le, set.range_subset_iff],\n      intro i,\n      fin_cases i,\n      { exact vsub_mem_direction hc\u2082s hc\u2081s },\n      { exact vsub_mem_direction hp\u2082s hp\u2081s } },\n    { rw [finrank_span_eq_card hb, fintype.card_fin, hd] } },\n  have hv : \u2200 v \u2208 s.direction, \u2203 t\u2081 t\u2082 : \u211d, v = t\u2081 \u2022 (c\u2082 -\u1d65 c\u2081) + t\u2082 \u2022 (p\u2082 -\u1d65 p\u2081),\n  { intros v hv,\n    have hr : set.range b = {c\u2082 -\u1d65 c\u2081, p\u2082 -\u1d65 p\u2081},\n    { have hu : (finset.univ : finset (fin 2)) = {0, 1}, by dec_trivial,\n      rw [\u2190fintype.coe_image_univ, hu],\n      simp,\n      refl },\n    rw [\u2190hbs, hr, submodule.mem_span_insert] at hv,\n    rcases hv with \u27e8t\u2081, v', hv', hv\u27e9,\n    rw submodule.mem_span_singleton at hv',\n    rcases hv' with \u27e8t\u2082, rfl\u27e9,\n    exact \u27e8t\u2081, t\u2082, hv\u27e9 },\n  rcases hv (p -\u1d65 p\u2081) (vsub_mem_direction hps hp\u2081s) with \u27e8t\u2081, t\u2082, hpt\u27e9,\n  simp only [hpt, inner_add_right, inner_smul_right, ho, mul_zero, add_zero, mul_eq_zero,\n             inner_self_eq_zero, vsub_eq_zero_iff_eq, hc.symm, or_false] at hop,\n  rw [hop, zero_smul, zero_add, \u2190eq_vadd_iff_vsub_eq] at hpt,\n  subst hpt,\n  have hp' : (p\u2082 -\u1d65 p\u2081 : V) \u2260 0, { simp [hp.symm] },\n  have hp\u2082 : dist ((1 : \u211d) \u2022 (p\u2082 -\u1d65 p\u2081) +\u1d65 p\u2081) c\u2081 = r\u2081, { simp [hp\u2082c\u2081] },\n  rw [\u2190hp\u2081c\u2081, dist_smul_vadd_eq_dist _ _ hp'] at hpc\u2081 hp\u2082,\n  simp only [one_ne_zero, false_or] at hp\u2082,\n  rw hp\u2082.symm at hpc\u2081,\n  cases hpc\u2081; simp [hpc\u2081]\nend\n\n/-- Distances `r\u2081` `r\u2082` of `p` from two different points `c\u2081` `c\u2082` determine at\nmost two points `p\u2081` `p\u2082` in two-dimensional space (two circles intersect in at\nmost two points). -/\nlemma eq_of_dist_eq_of_dist_eq_of_finrank_eq_two [finite_dimensional \u211d V] (hd : finrank \u211d V = 2)\n  {c\u2081 c\u2082 p\u2081 p\u2082 p : P} {r\u2081 r\u2082 : \u211d} (hc : c\u2081 \u2260 c\u2082) (hp : p\u2081 \u2260 p\u2082) (hp\u2081c\u2081 : dist p\u2081 c\u2081 = r\u2081)\n  (hp\u2082c\u2081 : dist p\u2082 c\u2081 = r\u2081) (hpc\u2081 : dist p c\u2081 = r\u2081) (hp\u2081c\u2082 : dist p\u2081 c\u2082 = r\u2082)\n  (hp\u2082c\u2082 : dist p\u2082 c\u2082 = r\u2082) (hpc\u2082 : dist p c\u2082 = r\u2082) : p = p\u2081 \u2228 p = p\u2082 :=\nbegin\n  have hd' : finrank \u211d (\u22a4 : affine_subspace \u211d P).direction = 2,\n  { rw [direction_top, finrank_top],\n    exact hd },\n  exact eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd'\n    (mem_top \u211d V _) (mem_top \u211d V _) (mem_top \u211d V _) (mem_top \u211d V _) (mem_top \u211d V _)\n    hc hp hp\u2081c\u2081 hp\u2082c\u2081 hpc\u2081 hp\u2081c\u2082 hp\u2082c\u2082 hpc\u2082\nend\n\nvariables {V}\n\n/-- The orthogonal projection of a point onto a nonempty affine\nsubspace, whose direction is complete, as an unbundled function.  This\ndefinition is only intended for use in setting up the bundled version\n`orthogonal_projection` and should not be used once that is\ndefined. -/\ndef orthogonal_projection_fn (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction]\n  (p : P) : P :=\nclassical.some $ inter_eq_singleton_of_nonempty_of_is_compl\n  (nonempty_subtype.mp \u2039_\u203a)\n  (mk'_nonempty p s.direction\u15ee)\n  begin\n    rw direction_mk' p s.direction\u15ee,\n    exact submodule.is_compl_orthogonal_of_complete_space,\n  end\n\n/-- The intersection of the subspace and the orthogonal subspace\nthrough the given point is the `orthogonal_projection_fn` of that\npoint onto the subspace.  This lemma is only intended for use in\nsetting up the bundled version and should not be used once that is\ndefined. -/\nlemma inter_eq_singleton_orthogonal_projection_fn {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  (s : set P) \u2229 (mk' p s.direction\u15ee) = {orthogonal_projection_fn s p} :=\nclassical.some_spec $ inter_eq_singleton_of_nonempty_of_is_compl\n  (nonempty_subtype.mp \u2039_\u203a)\n  (mk'_nonempty p s.direction\u15ee)\n  begin\n    rw direction_mk' p s.direction\u15ee,\n    exact submodule.is_compl_orthogonal_of_complete_space\n  end\n\n/-- The `orthogonal_projection_fn` lies in the given subspace.  This\nlemma is only intended for use in setting up the bundled version and\nshould not be used once that is defined. -/\nlemma orthogonal_projection_fn_mem {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] (p : P) : orthogonal_projection_fn s p \u2208 s :=\nbegin\n  rw [\u2190mem_coe, \u2190set.singleton_subset_iff, \u2190inter_eq_singleton_orthogonal_projection_fn],\n  exact set.inter_subset_left _ _\nend\n\n/-- The `orthogonal_projection_fn` lies in the orthogonal\nsubspace.  This lemma is only intended for use in setting up the\nbundled version and should not be used once that is defined. -/\nlemma orthogonal_projection_fn_mem_orthogonal {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  orthogonal_projection_fn s p \u2208 mk' p s.direction\u15ee :=\nbegin\n  rw [\u2190mem_coe, \u2190set.singleton_subset_iff, \u2190inter_eq_singleton_orthogonal_projection_fn],\n  exact set.inter_subset_right _ _\nend\n\n/-- Subtracting `p` from its `orthogonal_projection_fn` produces a\nresult in the orthogonal direction.  This lemma is only intended for\nuse in setting up the bundled version and should not be used once that\nis defined. -/\nlemma orthogonal_projection_fn_vsub_mem_direction_orthogonal {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  orthogonal_projection_fn s p -\u1d65 p \u2208 s.direction\u15ee :=\ndirection_mk' p s.direction\u15ee \u25b8\n  vsub_mem_direction (orthogonal_projection_fn_mem_orthogonal p) (self_mem_mk' _ _)\n\nlocal attribute [instance] affine_subspace.to_add_torsor\n\n/-- The orthogonal projection of a point onto a nonempty affine\nsubspace, whose direction is complete. The corresponding linear map\n(mapping a vector to the difference between the projections of two\npoints whose difference is that vector) is the `orthogonal_projection`\nfor real inner product spaces, onto the direction of the affine\nsubspace being projected onto. -/\ndef orthogonal_projection (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction] :\n  P \u2192\u1d43[\u211d] s :=\n{ to_fun := \u03bb p, \u27e8orthogonal_projection_fn s p, orthogonal_projection_fn_mem p\u27e9,\n  linear := orthogonal_projection s.direction,\n  map_vadd' := \u03bb p v, begin\n    have hs : ((orthogonal_projection s.direction) v : V) +\u1d65 orthogonal_projection_fn s p \u2208 s :=\n      vadd_mem_of_mem_direction (orthogonal_projection s.direction v).2\n                                (orthogonal_projection_fn_mem p),\n    have ho : ((orthogonal_projection s.direction) v : V) +\u1d65 orthogonal_projection_fn s p \u2208\n      mk' (v +\u1d65 p) s.direction\u15ee,\n    { rw [\u2190vsub_right_mem_direction_iff_mem (self_mem_mk' _ _) _, direction_mk',\n          vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_comm, add_sub_assoc],\n      refine submodule.add_mem _ (orthogonal_projection_fn_vsub_mem_direction_orthogonal p) _,\n      rw submodule.mem_orthogonal',\n      intros w hw,\n      rw [\u2190neg_sub, inner_neg_left, orthogonal_projection_inner_eq_zero _ w hw, neg_zero], },\n    have hm : ((orthogonal_projection s.direction) v : V) +\u1d65 orthogonal_projection_fn s p \u2208\n      ({orthogonal_projection_fn s (v +\u1d65 p)} : set P),\n    { rw \u2190inter_eq_singleton_orthogonal_projection_fn (v +\u1d65 p),\n      exact set.mem_inter hs ho },\n    rw set.mem_singleton_iff at hm,\n    ext,\n    exact hm.symm\n  end }\n\n@[simp] lemma orthogonal_projection_fn_eq {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  orthogonal_projection_fn s p = orthogonal_projection s p :=\nrfl\n\n/-- The linear map corresponding to `orthogonal_projection`. -/\n@[simp] lemma orthogonal_projection_linear {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] :\n  (orthogonal_projection s).linear = _root_.orthogonal_projection s.direction :=\nrfl\n\n/-- The intersection of the subspace and the orthogonal subspace\nthrough the given point is the `orthogonal_projection` of that point\nonto the subspace. -/\nlemma inter_eq_singleton_orthogonal_projection {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  (s : set P) \u2229 (mk' p s.direction\u15ee) = {orthogonal_projection s p} :=\nbegin\n  rw \u2190orthogonal_projection_fn_eq,\n  exact inter_eq_singleton_orthogonal_projection_fn p\nend\n\n/-- The `orthogonal_projection` lies in the given subspace. -/\nlemma orthogonal_projection_mem {s : affine_subspace \u211d P} [nonempty s] [complete_space s.direction]\n  (p : P) : \u2191(orthogonal_projection s p) \u2208 s :=\n(orthogonal_projection s p).2\n\n/-- The `orthogonal_projection` lies in the orthogonal subspace. -/\nlemma orthogonal_projection_mem_orthogonal (s : affine_subspace \u211d P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  \u2191(orthogonal_projection s p) \u2208 mk' p s.direction\u15ee :=\northogonal_projection_fn_mem_orthogonal p\n\n/-- Subtracting a point in the given subspace from the\n`orthogonal_projection` produces a result in the direction of the\ngiven subspace. -/\nlemma orthogonal_projection_vsub_mem_direction {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p1 : P} (p2 : P) (hp1 : p1 \u2208 s) :\n  \u2191(orthogonal_projection s p2 -\u1d65 \u27e8p1, hp1\u27e9 : s.direction) \u2208 s.direction :=\n(orthogonal_projection s p2 -\u1d65 \u27e8p1, hp1\u27e9 : s.direction).2\n\n/-- Subtracting the `orthogonal_projection` from a point in the given\nsubspace produces a result in the direction of the given subspace. -/\nlemma vsub_orthogonal_projection_mem_direction {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p1 : P} (p2 : P) (hp1 : p1 \u2208 s) :\n  \u2191((\u27e8p1, hp1\u27e9 : s) -\u1d65 orthogonal_projection s p2 : s.direction) \u2208 s.direction :=\n((\u27e8p1, hp1\u27e9 : s) -\u1d65 orthogonal_projection s p2 : s.direction).2\n\n/-- A point equals its orthogonal projection if and only if it lies in\nthe subspace. -/\nlemma orthogonal_projection_eq_self_iff {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p : P} :\n  \u2191(orthogonal_projection s p) = p \u2194 p \u2208 s :=\nbegin\n  split,\n  { exact \u03bb h, h \u25b8 orthogonal_projection_mem p },\n  { intro h,\n    have hp : p \u2208 ((s : set P) \u2229 mk' p s.direction\u15ee) := \u27e8h, self_mem_mk' p _\u27e9,\n    rw [inter_eq_singleton_orthogonal_projection p] at hp,\n    symmetry,\n    exact hp }\nend\n\n@[simp] lemma orthogonal_projection_mem_subspace_eq_self {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] (p : s) :\n  orthogonal_projection s p = p :=\nbegin\n  ext,\n  rw orthogonal_projection_eq_self_iff,\n  exact p.2\nend\n\n/-- Orthogonal projection is idempotent. -/\n@[simp] lemma orthogonal_projection_orthogonal_projection (s : affine_subspace \u211d P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  orthogonal_projection s (orthogonal_projection s p) = orthogonal_projection s p :=\nbegin\n  ext,\n  rw orthogonal_projection_eq_self_iff,\n  exact orthogonal_projection_mem p,\nend\n\nlemma eq_orthogonal_projection_of_eq_subspace {s s' : affine_subspace \u211d P} [nonempty s]\n  [nonempty s'] [complete_space s.direction] [complete_space s'.direction] (h : s = s') (p : P) :\n  (orthogonal_projection s p : P) = (orthogonal_projection s' p : P) :=\nbegin\n  change orthogonal_projection_fn s p = orthogonal_projection_fn s' p,\n  congr,\n  exact h\nend\n\n/-- The distance to a point's orthogonal projection is 0 iff it lies in the subspace. -/\nlemma dist_orthogonal_projection_eq_zero_iff {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p : P} :\n  dist p (orthogonal_projection s p) = 0 \u2194 p \u2208 s :=\nby rw [dist_comm, dist_eq_zero, orthogonal_projection_eq_self_iff]\n\n/-- The distance between a point and its orthogonal projection is\nnonzero if it does not lie in the subspace. -/\nlemma dist_orthogonal_projection_ne_zero_of_not_mem {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p : P} (hp : p \u2209 s) :\n  dist p (orthogonal_projection s p) \u2260 0 :=\nmt dist_orthogonal_projection_eq_zero_iff.mp hp\n\n/-- Subtracting `p` from its `orthogonal_projection` produces a result\nin the orthogonal direction. -/\nlemma orthogonal_projection_vsub_mem_direction_orthogonal (s : affine_subspace \u211d P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  (orthogonal_projection s p : P) -\u1d65 p \u2208 s.direction\u15ee :=\northogonal_projection_fn_vsub_mem_direction_orthogonal p\n\n/-- Subtracting the `orthogonal_projection` from `p` produces a result\nin the orthogonal direction. -/\nlemma vsub_orthogonal_projection_mem_direction_orthogonal (s : affine_subspace \u211d P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  p -\u1d65 orthogonal_projection s p \u2208 s.direction\u15ee :=\ndirection_mk' p s.direction\u15ee \u25b8\n  vsub_mem_direction (self_mem_mk' _ _) (orthogonal_projection_mem_orthogonal s p)\n\n/-- Subtracting the `orthogonal_projection` from `p` produces a result in the kernel of the linear\npart of the orthogonal projection. -/\nlemma orthogonal_projection_vsub_orthogonal_projection (s : affine_subspace \u211d P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  _root_.orthogonal_projection s.direction (p -\u1d65 orthogonal_projection s p) = 0 :=\nbegin\n  apply orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero,\n  intros c hc,\n  rw [\u2190 neg_vsub_eq_vsub_rev, inner_neg_right,\n    (orthogonal_projection_vsub_mem_direction_orthogonal s p c hc), neg_zero]\nend\n\n/-- Adding a vector to a point in the given subspace, then taking the\northogonal projection, produces the original point if the vector was\nin the orthogonal direction. -/\nlemma orthogonal_projection_vadd_eq_self {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p : P} (hp : p \u2208 s) {v : V}\n  (hv : v \u2208 s.direction\u15ee) :\n  orthogonal_projection s (v +\u1d65 p) = \u27e8p, hp\u27e9 :=\nbegin\n  have h := vsub_orthogonal_projection_mem_direction_orthogonal s (v +\u1d65 p),\n  rw [vadd_vsub_assoc, submodule.add_mem_iff_right _ hv] at h,\n  refine (eq_of_vsub_eq_zero _).symm,\n  ext,\n  refine submodule.disjoint_def.1 s.direction.orthogonal_disjoint _ _ h,\n  exact (_ : s.direction).2\nend\n\n/-- Adding a vector to a point in the given subspace, then taking the\northogonal projection, produces the original point if the vector is a\nmultiple of the result of subtracting a point's orthogonal projection\nfrom that point. -/\nlemma orthogonal_projection_vadd_smul_vsub_orthogonal_projection {s : affine_subspace \u211d P}\n  [nonempty s] [complete_space s.direction] {p1 : P} (p2 : P) (r : \u211d) (hp : p1 \u2208 s) :\n  orthogonal_projection s (r \u2022 (p2 -\u1d65 orthogonal_projection s p2 : V) +\u1d65 p1) = \u27e8p1, hp\u27e9 :=\northogonal_projection_vadd_eq_self hp\n  (submodule.smul_mem _ _ (vsub_orthogonal_projection_mem_direction_orthogonal s _))\n\n/-- The square of the distance from a point in `s` to `p2` equals the\nsum of the squares of the distances of the two points to the\n`orthogonal_projection`. -/\nlemma dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq\n  {s : affine_subspace \u211d P} [nonempty s] [complete_space s.direction] {p1 : P}\n  (p2 : P) (hp1 : p1 \u2208 s) :\n  dist p1 p2 * dist p1 p2 =\n    dist p1 (orthogonal_projection s p2) * dist p1 (orthogonal_projection s p2) +\n    dist p2 (orthogonal_projection s p2) * dist p2 (orthogonal_projection s p2) :=\nbegin\n  rw [dist_comm p2 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V p1 _,\n    dist_eq_norm_vsub V _ p2, \u2190 vsub_add_vsub_cancel p1 (orthogonal_projection s p2) p2,\n    norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero],\n  exact submodule.inner_right_of_mem_orthogonal\n    (vsub_orthogonal_projection_mem_direction p2 hp1)\n    (orthogonal_projection_vsub_mem_direction_orthogonal s p2),\nend\n\n/-- The square of the distance between two points constructed by\nadding multiples of the same orthogonal vector to points in the same\nsubspace. -/\nlemma dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd {s : affine_subspace \u211d P}\n    {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) (r1 r2 : \u211d) {v : V}\n    (hv : v \u2208 s.direction\u15ee) :\n  dist (r1 \u2022 v +\u1d65 p1) (r2 \u2022 v +\u1d65 p2) * dist (r1 \u2022 v +\u1d65 p1) (r2 \u2022 v +\u1d65 p2) =\n    dist p1 p2 * dist p1 p2 + (r1 - r2) * (r1 - r2) * (\u2016v\u2016 * \u2016v\u2016) :=\ncalc dist (r1 \u2022 v +\u1d65 p1) (r2 \u2022 v +\u1d65 p2) * dist (r1 \u2022 v +\u1d65 p1) (r2 \u2022 v +\u1d65 p2)\n    = \u2016(p1 -\u1d65 p2) + (r1 - r2) \u2022 v\u2016 * \u2016(p1 -\u1d65 p2) + (r1 - r2) \u2022 v\u2016\n  : by rw [dist_eq_norm_vsub V (r1 \u2022 v +\u1d65 p1), vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, sub_smul,\n      add_comm, add_sub_assoc]\n... = \u2016p1 -\u1d65 p2\u2016 * \u2016p1 -\u1d65 p2\u2016 + \u2016(r1 - r2) \u2022 v\u2016 * \u2016(r1 - r2) \u2022 v\u2016\n  : norm_add_sq_eq_norm_sq_add_norm_sq_real\n      (submodule.inner_right_of_mem_orthogonal (vsub_mem_direction hp1 hp2)\n        (submodule.smul_mem _ _ hv))\n... = \u2016(p1 -\u1d65 p2 : V)\u2016 * \u2016(p1 -\u1d65 p2 : V)\u2016 + |r1 - r2| * |r1 - r2| * \u2016v\u2016 * \u2016v\u2016\n  : by { rw [norm_smul, real.norm_eq_abs], ring }\n... = dist p1 p2 * dist p1 p2 + (r1 - r2) * (r1 - r2) * (\u2016v\u2016 * \u2016v\u2016)\n  : by { rw [dist_eq_norm_vsub V p1, abs_mul_abs_self, mul_assoc] }\n\n/-- Reflection in an affine subspace, which is expected to be nonempty\nand complete.  The word \"reflection\" is sometimes understood to mean\nspecifically reflection in a codimension-one subspace, and sometimes\nmore generally to cover operations such as reflection in a point.  The\ndefinition here, of reflection in an affine subspace, is a more\ngeneral sense of the word that includes both those common cases. -/\ndef reflection (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction] :\n  P \u2243\u1d43\u2071[\u211d] P :=\naffine_isometry_equiv.mk'\n  (\u03bb p, (\u2191(orthogonal_projection s p) -\u1d65 p) +\u1d65 orthogonal_projection s p)\n  (_root_.reflection s.direction)\n  \u2191(classical.arbitrary s)\n  begin\n    intros p,\n    let v := p -\u1d65 \u2191(classical.arbitrary s),\n    let a : V := _root_.orthogonal_projection s.direction v,\n    let b : P := \u2191(classical.arbitrary s),\n    have key : a +\u1d65 b -\u1d65 (v +\u1d65 b) +\u1d65 (a +\u1d65 b) = a + a - v +\u1d65 (b -\u1d65 b +\u1d65 b),\n    { rw [\u2190 add_vadd, vsub_vadd_eq_vsub_sub, vsub_vadd, vadd_vsub],\n      congr' 1,\n      abel },\n    have : p = v +\u1d65 \u2191(classical.arbitrary s) := (vsub_vadd p \u2191(classical.arbitrary s)).symm,\n    simpa only [coe_vadd, reflection_apply, affine_map.map_vadd, orthogonal_projection_linear,\n      orthogonal_projection_mem_subspace_eq_self, vadd_vsub, continuous_linear_map.coe_coe,\n      continuous_linear_equiv.coe_coe, this] using key,\n  end\n\n/-- The result of reflecting. -/\nlemma reflection_apply (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction] (p : P) :\n  reflection s p = (\u2191(orthogonal_projection s p) -\u1d65 p) +\u1d65 orthogonal_projection s p :=\nrfl\n\nlemma eq_reflection_of_eq_subspace {s s' : affine_subspace \u211d P} [nonempty s]\n  [nonempty s'] [complete_space s.direction] [complete_space s'.direction] (h : s = s') (p : P) :\n  (reflection s p : P) = (reflection s' p : P) :=\nby unfreezingI { subst h }\n\n/-- Reflecting twice in the same subspace. -/\n@[simp] lemma reflection_reflection (s : affine_subspace \u211d P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  reflection s (reflection s p) = p :=\nbegin\n  have : \u2200 a : s, \u2200 b : V, (_root_.orthogonal_projection s.direction) b = 0\n    \u2192 reflection s (reflection s (b +\u1d65 a)) = b +\u1d65 a,\n  { intros a b h,\n    have : (a:P) -\u1d65 (b +\u1d65 a) = - b,\n    { rw [vsub_vadd_eq_vsub_sub, vsub_self, zero_sub] },\n    simp [reflection, h, this] },\n  rw \u2190 vsub_vadd p (orthogonal_projection s p),\n  exact this (orthogonal_projection s p) _ (orthogonal_projection_vsub_orthogonal_projection s p),\nend\n\n/-- Reflection is its own inverse. -/\n@[simp] lemma reflection_symm (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction] :\n  (reflection s).symm = reflection s :=\nby { ext, rw \u2190 (reflection s).injective.eq_iff, simp }\n\n/-- Reflection is involutive. -/\nlemma reflection_involutive (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction] :\n  function.involutive (reflection s) :=\nreflection_reflection s\n\n/-- A point is its own reflection if and only if it is in the\nsubspace. -/\nlemma reflection_eq_self_iff {s : affine_subspace \u211d P} [nonempty s] [complete_space s.direction]\n  (p : P) : reflection s p = p \u2194 p \u2208 s :=\nbegin\n  rw [\u2190orthogonal_projection_eq_self_iff, reflection_apply],\n  split,\n  { intro h,\n    rw [\u2190@vsub_eq_zero_iff_eq V, vadd_vsub_assoc,\n        \u2190two_smul \u211d (\u2191(orthogonal_projection s p) -\u1d65 p), smul_eq_zero] at h,\n    norm_num at h,\n    exact h },\n  { intro h,\n    simp [h] }\nend\n\n/-- Reflecting a point in two subspaces produces the same result if\nand only if the point has the same orthogonal projection in each of\nthose subspaces. -/\nlemma reflection_eq_iff_orthogonal_projection_eq (s\u2081 s\u2082 : affine_subspace \u211d P)\n  [nonempty s\u2081] [nonempty s\u2082] [complete_space s\u2081.direction] [complete_space s\u2082.direction] (p : P) :\n  reflection s\u2081 p = reflection s\u2082 p \u2194\n    (orthogonal_projection s\u2081 p : P) = orthogonal_projection s\u2082 p :=\nbegin\n  rw [reflection_apply, reflection_apply],\n  split,\n  { intro h,\n    rw [\u2190@vsub_eq_zero_iff_eq V, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_comm,\n        add_sub_assoc, vsub_sub_vsub_cancel_right,\n        \u2190two_smul \u211d ((orthogonal_projection s\u2081 p : P) -\u1d65 orthogonal_projection s\u2082 p),\n        smul_eq_zero] at h,\n    norm_num at h,\n    exact h },\n  { intro h,\n    rw h }\nend\n\n/-- The distance between `p\u2081` and the reflection of `p\u2082` equals that\nbetween the reflection of `p\u2081` and `p\u2082`. -/\nlemma dist_reflection (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction]\n  (p\u2081 p\u2082 : P) :\n  dist p\u2081 (reflection s p\u2082) = dist (reflection s p\u2081) p\u2082 :=\nbegin\n  conv_lhs { rw \u2190reflection_reflection s p\u2081 },\n  exact (reflection s).dist_map _ _\nend\n\n/-- A point in the subspace is equidistant from another point and its\nreflection. -/\nlemma dist_reflection_eq_of_mem (s : affine_subspace \u211d P) [nonempty s] [complete_space s.direction]\n  {p\u2081 : P} (hp\u2081 : p\u2081 \u2208 s) (p\u2082 : P) :\n  dist p\u2081 (reflection s p\u2082) = dist p\u2081 p\u2082 :=\nbegin\n  rw \u2190reflection_eq_self_iff p\u2081 at hp\u2081,\n  convert (reflection s).dist_map p\u2081 p\u2082,\n  rw hp\u2081\nend\n\n/-- The reflection of a point in a subspace is contained in any larger\nsubspace containing both the point and the subspace reflected in. -/\nlemma reflection_mem_of_le_of_mem {s\u2081 s\u2082 : affine_subspace \u211d P} [nonempty s\u2081]\n  [complete_space s\u2081.direction] (hle : s\u2081 \u2264 s\u2082) {p : P}\n  (hp : p \u2208 s\u2082) : reflection s\u2081 p \u2208 s\u2082 :=\nbegin\n  rw [reflection_apply],\n  have ho : \u2191(orthogonal_projection s\u2081 p) \u2208 s\u2082 := hle (orthogonal_projection_mem p),\n  exact vadd_mem_of_mem_direction (vsub_mem_direction ho hp) ho\nend\n\n/-- Reflecting an orthogonal vector plus a point in the subspace\nproduces the negation of that vector plus the point. -/\nlemma reflection_orthogonal_vadd {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p : P} (hp : p \u2208 s) {v : V}\n  (hv : v \u2208 s.direction\u15ee) : reflection s (v +\u1d65 p) = -v +\u1d65 p :=\nbegin\n  rw [reflection_apply, orthogonal_projection_vadd_eq_self hp hv, vsub_vadd_eq_vsub_sub],\n  simp\nend\n\n/-- Reflecting a vector plus a point in the subspace produces the\nnegation of that vector plus the point if the vector is a multiple of\nthe result of subtracting a point's orthogonal projection from that\npoint. -/\nlemma reflection_vadd_smul_vsub_orthogonal_projection {s : affine_subspace \u211d P} [nonempty s]\n  [complete_space s.direction] {p\u2081 : P} (p\u2082 : P) (r : \u211d) (hp\u2081 : p\u2081 \u2208 s) :\n  reflection s (r \u2022 (p\u2082 -\u1d65 orthogonal_projection s p\u2082) +\u1d65 p\u2081) =\n    -(r \u2022 (p\u2082 -\u1d65 orthogonal_projection s p\u2082)) +\u1d65 p\u2081 :=\nreflection_orthogonal_vadd hp\u2081\n  (submodule.smul_mem _ _ (vsub_orthogonal_projection_mem_direction_orthogonal s _))\n\nend euclidean_geometry\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.7331692730004907}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport order.upper_lower.basic\nimport topology.separation\n\n/-!\n# Priestley spaces\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines Priestley spaces. A Priestley space is an ordered compact topological space such\nthat any two distinct points can be separated by a clopen upper set.\n\n## Main declarations\n\n* `priestley_space`: Prop-valued mixin stating the Priestley separation axiom: Any two distinct\n  points can be separated by a clopen upper set.\n\n## Implementation notes\n\nWe do not include compactness in the definition, so a Priestley space is to be declared as follows:\n`[preorder \u03b1] [topological_space \u03b1] [compact_space \u03b1] [priestley_space \u03b1]`\n\n## References\n\n* [Wikipedia, *Priestley space*](https://en.wikipedia.org/wiki/Priestley_space)\n* [Davey, Priestley *Introduction to Lattices and Order*][davey_priestley]\n-/\n\nopen set\n\nvariables {\u03b1 : Type*}\n\n/-- A Priestley space is an ordered topological space such that any two distinct points can be\nseparated by a clopen upper set. Compactness is often assumed, but we do not include it here. -/\nclass priestley_space (\u03b1 : Type*) [preorder \u03b1] [topological_space \u03b1] :=\n(priestley {x y : \u03b1} : \u00ac x \u2264 y \u2192 \u2203 U : set \u03b1, is_clopen U \u2227 is_upper_set U \u2227 x \u2208 U \u2227 y \u2209 U)\n\nvariables [topological_space \u03b1]\n\nsection preorder\nvariables [preorder \u03b1] [priestley_space \u03b1] {x y : \u03b1}\n\nlemma exists_clopen_upper_of_not_le :\n  \u00ac x \u2264 y \u2192 \u2203 U : set \u03b1, is_clopen U \u2227 is_upper_set U \u2227 x \u2208 U \u2227 y \u2209 U :=\npriestley_space.priestley\n\nlemma exists_clopen_lower_of_not_le (h : \u00ac x \u2264 y) :\n  \u2203 U : set \u03b1, is_clopen U \u2227 is_lower_set U \u2227 x \u2209 U \u2227 y \u2208 U :=\nlet \u27e8U, hU, hU', hx, hy\u27e9 := exists_clopen_upper_of_not_le h in\n  \u27e8U\u1d9c, hU.compl, hU'.compl, not_not.2 hx, hy\u27e9\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] [priestley_space \u03b1] {x y : \u03b1}\n\nlemma exists_clopen_upper_or_lower_of_ne (h : x \u2260 y) :\n  \u2203 U : set \u03b1, is_clopen U \u2227 (is_upper_set U \u2228 is_lower_set U) \u2227 x \u2208 U \u2227 y \u2209 U :=\nbegin\n  obtain (h | h) := h.not_le_or_not_le,\n  { exact (exists_clopen_upper_of_not_le h).imp (\u03bb U, and.imp_right $ and.imp_left or.inl) },\n  { obtain \u27e8U, hU, hU', hy, hx\u27e9 := exists_clopen_lower_of_not_le h,\n    exact \u27e8U, hU, or.inr hU', hx, hy\u27e9 }\nend\n\n@[priority 100] -- See note [lower instance priority]\ninstance priestley_space.to_t2_space : t2_space \u03b1 :=\n\u27e8\u03bb x y h, let \u27e8U, hU, _, hx, hy\u27e9 := exists_clopen_upper_or_lower_of_ne h in\n   \u27e8U, U\u1d9c, hU.is_open, hU.compl.is_open, hx, hy, disjoint_compl_right\u27e9\u27e9\n\nend partial_order\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/order/priestley.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7331692586088854}}
{"text": "\n/-\nCopyright (c) 2018 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Kevin Buzzard, Kenny Lau, \n\n144 is the largest square in the Fibonacci sequence.\n-/\n\n/- 144 is the largest square in the Fibonacci sequence.\n  Copyright Kevin Buzzard.\n\nAuthors :\n  Kevin Buzzard\n  Nicholas Scheel\n  Kenny Lau\n  Reid Barton \n  \n-/\n\n-- definition of Fibonacci sequence \nimport definitions \n\n-- Statement of main theorem\ntheorem largest_square_in_fibonacci_sequence (n d : \u2115) : fib n = d ^ 2 \u2192 fib n \u2264 144 := sorry \n", "meta": {"author": "kbuzzard", "repo": "lean-squares-in-fibonacci", "sha": "8cea20e5ce88ab7d17b020932d84d316532a84a8", "save_path": "github-repos/lean/kbuzzard-lean-squares-in-fibonacci", "path": "github-repos/lean/kbuzzard-lean-squares-in-fibonacci/lean-squares-in-fibonacci-8cea20e5ce88ab7d17b020932d84d316532a84a8/src/squares_in_fibonacci.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7331418393856661}}
{"text": "import week_7.solutions.Part_A_quotients\nimport week_7.solutions.Part_B_universal_property\n\n/-\n\n# `Z \u2243 \u2124` \n\nLet's use the previous parts to show that Z and \u2124 are isomorphic.\n\n-/\n\n-- Let's define p\u2124 to be the usual subtraction function \u2115\u00b2 \u2192 \u2124\ndef p\u2124 (ab : N2) : \u2124 := (ab.1 : \u2124) - ab.2\n\n@[simp] lemma p\u2124_def (a b : \u2115) : p\u2124 (a, b) = (a : \u2124) - b := rfl\n\n-- Start with `intro z, apply int.induction_on z` to prove this.\ntheorem p\u2124surj : function.surjective p\u2124 :=\nbegin\n  intro z,\n  apply int.induction_on z,\n  { use (0, 0),\n    simp,\n  },\n  { rintro i \u27e8\u27e8a, b\u27e9, h\u27e9,\n    use \u27e8a + 1, b\u27e9,\n    rw [\u2190h],\n    simp,\n    ring },\n  { rintro i \u27e8\u27e8a, b\u27e9, h\u27e9,\n    use \u27e8a, b + 1\u27e9,\n    rw [\u2190h],\n    simp,\n    ring }\nend\n\n-- The fibres of p\u2124 are equivalence classes.\ntheorem p\u2124equiv (ab cd : N2) : ab \u2248 cd \u2194 p\u2124 ab = p\u2124 cd :=\nbegin\n  cases ab with a b,\n  cases cd with c d,\n  split;\n  { simp,\n    intros,\n    linarith },\nend\n\n-- It's helpful to have a random one-sided inverse coming from surjectivity\nnoncomputable def invp : \u2124 \u2192 N2 :=\n\u03bb z, classical.some (p\u2124surj z)\n\n-- Here's the proof that it is an inverse.\n@[simp] theorem invp_inv (z : \u2124) : p\u2124 (invp z) = z :=\nclassical.some_spec (p\u2124surj z)\n\n-- Now we can prove that \u2124 and p\u2124 are universal.\ntheorem int_is_universal : is_universal \u2124 p\u2124 :=\nbegin\n  split,\n  { rintros \u27e8a, b\u27e9 \u27e8c, d\u27e9,\n    rw [N2.equiv_def, p\u2124],\n    simp,\n    intros,\n    linarith },\n  { intros T p h,\n    use (\u03bb z, p (invp z)),\n    split,\n    { ext ab,\n      simp,\n      apply h,\n      rw p\u2124equiv,\n      simp },\n    { intros k hk,\n      ext z,\n      rw [hk, function.comp],\n      simp } },\nend\n\n-- and now we can prove they're in bijection\nnoncomputable example : \u2124 \u2243 Z :=\nuniversal_equiv_quotient _ _ _ int_is_universal \n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_7/solutions/Part_C_back_to_Z.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7331418391884549}}
{"text": "--import data.set\nimport tactic\n\n-- dEAduction tactics\nimport structures2      -- hypo_analysis, targets_analysis\nimport utils            -- no_meta_vars\nimport user_notations   -- notations that can be used in deaduction UI for a new object\nimport push_neg_once\n\n-- dEAduction definitions\nimport set_definitions\n\n-- General principles :\n-- Type should be defined as parameters, in order to be implicit everywhere\n-- other parameters are implicit in definitions, i.e. defined using '{}' (e.g. {A : set X} )\n-- but explicit everywhere else, i.e. defined using '()' (e.g. (A : set X) )\n-- each definition must be an iff statement (since it will be called with 'rw' or 'symp_rw')\n\n---------------------\n-- Course metadata --\n---------------------\n-- logic names ['and', 'or', 'negate', 'implicate', 'iff', 'forall', 'exists', 'equal', 'map']\n-- proofs names ['use_proof_methods', 'new_object']\n-- proof methods names ['cbr', 'contrapose', 'absurdum', 'sorry']\n-- magic names ['compute', 'assumption']\n\n\n\n/- dEAduction\nTitle\n    exercices de math\u00e9matiques discretes.\nAuthor\n    Alice Laroche\nInstitution\n    \nAvailableMagic\n    ALL\nDescription\n    Exercices d'un cours de maths discr\u00e8tes \u00e0 Sorbonne Universit\u00e9.\n    Les num\u00e9ros de questions font r\u00e9f\u00e9rence \u00e0 la feuille de TD.\n-/\n\nnamespace set\n\n-- def disjoint {X : Type} (A B : set X) : Prop := A \u2229 B = \u2205\n\ndef partition {X :Type} (A : set (set X)) := (\u2200A\u2081 \u2208 A , A\u2081 \u2260 \u2205) \u2227 (\u2200A\u2081 A\u2082 \u2208 A, (A\u2081 \u2229 A\u2082 = \u2205) \u2228 A\u2081 = A\u2082) \u2227 (\u2200x, \u2203A\u2081 \u2208 A, x \u2208 A\u2081)\n\nend set\n\nnamespace relation\n\ndef inv {X Y : Type} (R : set (X \u00d7 Y)) : set (Y \u00d7 X)\n| (x, y) := (y, x) \u2208 R\n\ndef product {X Y Z : Type} (R : set (X \u00d7 Y)) (R' : set (Y \u00d7 Z)) : set (X \u00d7 Z)\n| (x, y) := \u2203z, (x, z) \u2208 R \u2227 (z, y) \u2208 R'\n\ndef identite {X: Type} : set (X \u00d7 X)\n| (x, y) := x = y\n\ndef reflexive {X : Type} (R : set (X \u00d7 X)) := \u2200x, (x, x) \u2208 R\n\ndef transitive {X : Type} (R: set (X \u00d7 X)) := \u2200x y z, (x, y) \u2208 R \u2227 (y, z) \u2208 R \u2192 (x, z) \u2208 R\n\ndef symetrique {X : Type} (R : set (X \u00d7 X)) := \u2200x y, (x, y) \u2208 R \u2192 (y, x) \u2208 R\n\ndef antisymetrique {X : Type} (R : set (X \u00d7 X)) := \u2200x y, (x, y) \u2208 R \u2227 (y, x) \u2208 R \u2192 x = y\n\ndef relation_equivalence {X : Type} (R : set (X \u00d7 X)) := reflexive R \u2227 transitive R \u2227 symetrique R\n\ndef relation_ordre {X : Type} (R : set (X \u00d7 X)) := reflexive R \u2227 transitive R \u2227 antisymetrique R\n\ndef classe_equivalence {X : Type} (R : set (X \u00d7 X)) (H1 : relation_equivalence R) (e : X) : set X\n| e' :=  (e, e')  \u2208 R\n\n\ndef deterministe {X Y : Type} (R : set (X \u00d7 Y)) := \u2200x y z, (x, y) \u2208 R \u2227 (x, z) \u2208 R \u2192 y = z \n\ndef total_gauche {X Y : Type} (R : set (X \u00d7 Y)) := \u2200x, \u2203y, (x, y) \u2208 R \n\ndef application {X Y : Type} (R : set (X \u00d7 Y)) := deterministe R \u2227 total_gauche R\n\ndef injective {X Y : Type} (R : set (X \u00d7 Y)) := \u2200x y z, (x, z) \u2208 R \u2227 (y, z) \u2208 R \u2192 x = y\n\ndef surjective {X Y : Type} (R : set (X \u00d7 Y)) := \u2200y, \u2203x, (x, y) \u2208 R\n\ndef application_injective {X Y : Type} (R : set (X \u00d7 Y)) := application R \u2227 injective R\n\ndef application_surjective {X Y : Type} (R : set (X \u00d7 Y)) := application R \u2227 surjective R\n\ndef application_bijective {X Y : Type} (R : set (X \u00d7 Y)) := application R \u2227 injective R \u2227 surjective R\n\ndef image {X Y : Type} (R : set (X \u00d7 Y)) (x : X) (y : Y) := (x, y) \u2208 R \n\nend relation\n\n\nlocal attribute [instance] classical.prop_decidable\n\n---------------------------------------------\n-- global parameters = implicit variables --\n---------------------------------------------\nsection course\nparameters {X Y Z: Type}\n\nopen set\nopen relation\n\nnotation [parsing_only] R `.` S := relation.product R S\n\nnotation R `\u207b\u00b9`  := relation.inv R\nnotation R `dot` S := relation.product R S\n\n\n------------------\n-- COURSE TITLE --\n------------------\nnamespace math_discretes\n/- dEAduction\nPrettyName\n    Math\u00e9matiques discr\u00e8tes\n-/\n\nnamespace generalites\n/- dEAduction\nPrettyName\n    G\u00e9n\u00e9ralit\u00e9s\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\nlemma definition.inclusion {A B : set X} : A \u2286 B \u2194 \u2200 {x:X}, x \u2208 A \u2192 x \u2208 B :=\n/- dEAduction\nPrettyName\n    Inclusion\nImplicitUse\n    True    \n-/\nbegin\n    todo,\nend\n\nlemma definition.egalite_deux_ensembles {A A' : set X} :\n(A = A') \u2194 ( \u2200 x, x \u2208 A \u2194 x \u2208 A' ) :=\n/- dEAduction\nPrettyName\n    Egalit\u00e9 de deux ensembles\nImplicitUse\n    False\n-/\nbegin\n    exact set.ext_iff,\nend\n\n-- lemma definition.inegalite_deux_ensembles {A A' : set X} :\n-- (A \u2260 A') \u2194 ( \u2203x, (x \u2208 A \u2227 x \u2209 A') \u2228 (x \u2208 A' \u2227 x \u2209 A)) :=\n-- /- dEAduction\n-- PrettyName\n--     In\u00e9galit\u00e9 de deux ensembles\n-- -/\n-- begin\n--     todo,\n-- end\n\nlemma definition.ensemble_vide\n(A: set X) :\n(A = \u2205) \u2194 \u2200 x : X, x \u2209 A\n:=\nbegin\n    exact eq_empty_iff_forall_not_mem,\nend\n\nlemma definition.ensemble_extension {X: Type}  {P : X \u2192 Prop} {x:X} :\n x \u2208 {x | P x} \u2194 P x\n:=\n/- dEAduction\nPrettyName\n    Ensemble en extension\n-/\nbegin\n    refl,\nend\n\nlemma definition.singleton {X : Type} {x y : X}: x \u2208 ({y} : set X) \u2194 x = y\n:=\n/- dEAduction\nPrettyName\n    Singleton\n-/\nbegin\n    exact mem_singleton_iff,\nend\n\nlemma definition.double_inclusion (A A' : set X) :\nA = A' \u2194 (A \u2286 A' \u2227 A' \u2286 A) :=\n/- dEAduction\nPrettyName\n    Double inclusion\nImplicitUse\n    True\n-/\nbegin\n    exact set.subset.antisymm_iff,\nend\n\nlemma definition.ensemble_partie (A A' : set X) :\nA' \u2208 \ud835\udcab(A) \u2194  A' \u2286 A\n:= \n/- dEAduction\nPrettyName\n    Ensemble des parties\n-/\nbegin\n    refl,\nend\n\nend generalites\n\n\nnamespace union_intersection\n/- dEAduction\nPrettyName\n    Unions et intersections\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\n\nlemma definition.intersection_deux_ensembles {A B : set X} {x : X} :\nx \u2208 A \u2229 B \u2194 ( x \u2208 A \u2227 x \u2208 B) :=\n/- dEAduction\nPrettyName\n    Intersection de deux ensembles\nImplicitUse\n    True\n-/\nbegin\n    exact iff.rfl,\nend\n\nlemma definition.intersection_union (A B C : set X) :\nA \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\n/- dEAduction\nPrettyName\n   Intersection avec une union\nImplicitUse\n    True\n-/\nbegin\n  exact set.inter_distrib_left A B C,\nend\n\nlemma definition.partition \n {P : set (set X)} : \n partition P \u2194 (\u2200A\u2081 \u2208 P , A\u2081 \u2260 \u2205) \u2227 (\u2200A\u2081 A\u2082 \u2208 P, (A\u2081 \u2229 A\u2082 = \u2205) \u2228 A\u2081 = A\u2082) \u2227 (\u2200x, \u2203A\u2081 \u2208 P, x \u2208 A\u2081)\n:=\n/- dEAduction\nPrettyName\n   Partition\n-/\nbegin\n    todo\nend\n-- lemma definition.intersection_videI (A : set X) :\n-- A \u2229 \u2205 = \u2205 :=\n-- /- dEAduction\n-- PrettyName\n--     Intersection avec l'ensemble vide I \n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact inter_empty A,\n-- end\n\n-- lemma definition.intersection_videII (A : set X) :\n-- \u2205 \u2229 A = \u2205 :=\n-- /- dEAduction\n-- PrettyName\n--     Intersection avec l'ensemble vide II\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact empty_inter A,\n-- end\n\n-- lemma definition.union_deux_ensembles  {A : set X} {B : set X} {x : X} :\n-- x \u2208 A \u222a B \u2194 ( x \u2208 A \u2228 x \u2208 B) :=\n-- /- dEAduction\n-- PrettyName\n--     Union de deux ensembles\n-- ImplicitUse\n--     True\n-- -/\n-- begin\n--     exact iff.rfl,\n-- end\n\n-- lemma definition.union_intersection (A B C : set X) :\n-- A \u222a (B \u2229 C) = (A \u222a B) \u2229 (A \u222a C) :=\n-- /- dEAduction\n-- PrettyName\n--    Union avec une intersection\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--   exact set.union_distrib_left A B C,\n-- end\n\n-- lemma definition.union_videI (A : set X) :\n-- A \u222a \u2205 = A :=\n-- /- dEAduction\n-- PrettyName\n--     Union avec l'ensemble vide I\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact union_empty A,\n-- end\n\n-- lemma definition.union_videII (A : set X) :\n-- \u2205 \u222a A = A :=\n-- /- dEAduction\n-- PrettyName\n--     Union avec l'ensemble vide II\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact empty_union A,\n-- end\n\nend union_intersection\n\nnamespace complementaire\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\n\nlemma definition.complement {A : set X} {x : X} : x \u2208 set.compl A \u2194 not (x \u2208 A) :=\n/- dEAduction\nPrettyName\n    Complementaire\nImplicitUse\n    False\n-/\nbegin\n    -- split, intro H, targets_analysis,\n    finish,\nend\n\nlemma definition.difference {A A' : set X} {x : X} : x \u2208 set.diff A A' \u2194 x \u2208 A \u2227 x \u2209 A' :=\n/- dEAduction\nPrettyName\n    Diff\u00e9rence\nImplicitUse\n    False\n-/\nbegin\n    finish,\nend\n-- lemma definition.complement_complement {A : set X} : (set.compl (set.compl A)) = A :=\n-- /- dEAduction\n-- PrettyName\n--     Complementaire du complementaire\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact compl_compl',\n-- end\n\n-- lemma definition.complement_intersection {A B : set X} :\n-- set.compl (A \u2229 B) = (set.compl A) \u222a (set.compl B) :=\n-- /- dEAduction\n-- PrettyName\n--     Complementaire d'une intersection\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact compl_inter A B,\n-- end\n\n-- lemma definition.intersection_complement {A : set X} :\n-- A \u2229 set.compl (A) = \u2205 :=\n-- /- dEAduction\n-- PrettyName\n--     Intersection avec le compl\u00e9mentaire\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact inter_compl_self A,\n-- end\n\n-- lemma definition.complement_union {A B : set X} :\n-- set.compl (A \u222a B) = (set.compl A) \u2229 (set.compl B) :=\n-- /- dEAduction\n-- PrettyName\n--     Complementaire d'une union\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact compl_union A B,\n-- end\n\n-- lemma definition.union_complement {A : set X} :\n-- A \u222a set.compl (A) = univ :=\n-- /- dEAduction\n-- PrettyName\n--     Union avec le compl\u00e9mentaire\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact union_compl_self A,\n-- end\n\nend complementaire\n\nnamespace produits_cartesiens\n/- dEAduction\nPrettyName\n    Produits cart\u00e9siens\n-/\n\n-- lemma definition.type_produit :\n-- \u2200 z:X \u00d7 Y, \u2203 x:X, \u2203 y:Y, z = (x,y) :=\n-- /- dEAduction\n-- PrettyName\n--     Element d'un produit cart\u00e9sien de deux ensembles\n-- -/\n-- begin\n--     todo\n-- end\n\n\nlemma definition.produit_de_parties {A : set X} {B : set Y} {x:X} {y:Y} :\n(x,y) \u2208 set.prod A B \u2194 x \u2208 A \u2227 y \u2208 B :=\n/- dEAduction\nPrettyName\n    Produit cart\u00e9sien de deux parties\n-/\nbegin\n    todo\nend\n\nend produits_cartesiens\n\nnamespace relations\n/- dEAduction\nPrettyName\n    Relations\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\n\nlemma definition.inv {R : set (X \u00d7 Y)} {x : X} {y : Y} :\n(y,x) \u2208 (inv R) \u2194 (x,y) \u2208 R :=\n/- dEAduction\nPrettyName\n    Inverse d'une relation\n-/\nbegin\n    refl,\nend\n\nlemma definition.prod {R : set (X \u00d7 Y)} {S : set (Y \u00d7 Z)} {x : X} {z : Z} :\n(x,z) \u2208 (product R S) \u2194 \u2203y, (x,y) \u2208 R \u2227 (y,z) \u2208 S :=\n/- dEAduction\nPrettyName\n    Produit de deux relations\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.id {x : X} {y : X} :\n(x,y) \u2208 (identite : set (X \u00d7 X))  \u2194 x = y :=\n/- dEAduction\nPrettyName\n    Relation identit\u00e9\n-/\nbegin\n    refl,\nend\n\nlemma theorem.id :\n\u2200 x:X,  (x,x) \u2208 (identite : set (X \u00d7 X)) :=\n/- dEAduction\nPrettyName\n    Relation identit\u00e9\n-/\nbegin\n    intro x, rw definition.id,\nend\n\nlemma definition.reflexive {R : set (X \u00d7 X)} :\nreflexive R \u2194 \u2200x, (x, x) \u2208 R :=\n/- dEAduction\nPrettyName\n    R\u00e9flexivit\u00e9\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.transitive {R : set (X \u00d7 X)} :\ntransitive R \u2194 \u2200x y z, (x, y) \u2208 R \u2227 (y, z) \u2208 R \u2192 (x, z) \u2208 R :=\n/- dEAduction\nPrettyName\n    Transitivit\u00e9\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.symetrique {R : set (X \u00d7 X)} :\nsymetrique R \u2194 \u2200x y, (x, y) \u2208 R \u2192 (y, x) \u2208 R:=\n/- dEAduction\nPrettyName\n    Sym\u00e9trie\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.antisymetrique {R : set (X \u00d7 X)} :\nantisymetrique R \u2194 \u2200x y, (x, y) \u2208 R \u2227 (y, x) \u2208 R \u2192 x = y :=\n/- dEAduction\nPrettyName\n    Antisym\u00e9trie\n-/\nbegin\n    refl,\nend\n\nlemma definition.equivalence {R : set (X \u00d7 X)} :\nrelation_equivalence R \u2194 reflexive R \u2227 transitive R \u2227 symetrique R :=\n/- dEAduction\nPrettyName\n    Relation d'\u00e9quivalence\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.ordre {R : set (X \u00d7 X)} :\nrelation_ordre R \u2194 reflexive R \u2227 transitive R \u2227 antisymetrique R :=\n/- dEAduction\nPrettyName\n    Relation d'ordre\n-/\nbegin\n    refl,\nend\n\nlemma definition.classe_equivalence {x y : X} {R : set (X \u00d7 X)} {H1 : relation_equivalence R}:\ny \u2208 classe_equivalence R H1 x \u2194 (x, y) \u2208 R :=\n/- dEAduction\nPrettyName\n    Classe d'\u00e9quivalence\n-/\nbegin\n    refl,\nend \nend relations\n\n-- namespace applications\n\n-- lemma definition.deterministe {X Y : Type} (R : set (X \u00d7 Y)) \n-- : deterministe R \u2194 \u2200x y z, (x, y) \u2208 R \u2227 (x, z) \u2208 R \u2192 y = z :=\n-- /- dEAduction\n-- PrettyName\n--     Relation d\u00e9terministe\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.total_gauche {X Y : Type} (R : set (X \u00d7 Y)) :\n-- total_gauche R \u2194 \u2200x, \u2203y, (x, y) \u2208 R :=\n-- /- dEAduction\n-- PrettyName\n--     Relation totale\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application R \u2194 deterministe R \u2227 total_gauche R :=\n-- /- dEAduction\n-- PrettyName\n--      Relation et application\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.relation_injective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- relation.injective R \u2194 \u2200x y z, (x, z) \u2208 R \u2227 (y, z) \u2208 R \u2192 x = y :=\n-- /- dEAduction\n-- PrettyName\n--     Relation injective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.relation_surjective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- relation.surjective R \u2194 \u2200y, \u2203x, (x, y) \u2208 R :=\n-- /- dEAduction\n-- PrettyName\n--     Relation surjective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application_injective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application_injective R \u2194 application R \u2227 relation.injective R :=\n-- /- dEAduction\n-- PrettyName\n--     Application injective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application_surjective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application_surjective R \u2194 application R \u2227 relation.surjective R :=\n-- /- dEAduction\n-- PrettyName\n--     Application surjective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application_bijective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application_bijective R \u2194 application R \u2227 relation.injective R \u2227 relation.surjective R :=\n-- /- dEAduction\n-- PrettyName\n--     Application bijective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.image {X Y : Type} (R : set (X \u00d7 Y)) (x : X) (y : Y) : \n-- image R x y \u2194 (x, y) \u2208 R :=\n-- /- dEAduction\n-- PrettyName\n--     Image d'une relation\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- end applications\n\n---------------\n-- EXERCICES --\n---------------\nnamespace exercices \n/- dEAduction\nPrettyName\n    Exercices\n-/\n\nvariables  {A B C : set X}\n\nnamespace exercice2\n/- dEAduction\nPrettyName\n    Exercice 2\n-/\n\nlemma exercise.question1 :\n(A \u2229 compl (A \u2229 B)) = (A \u2229 compl B) :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question2 :\nA \u2229 B = A \u2229 C \u2192 A \u2229 compl B = A \u2229 compl C :=\n/- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 :\nA \u2229 B = A \u2229 C \u2194 A \u2229 (compl B) = A \u2229 (compl C) :=\n/- dEAduction\nPrettyName\n    Question 3\nDescription\n    Deduire de la question pr\u00e9cedente l'\u00e9quivalence des deux \u00e9nonc\u00e9s.\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question4 :\nA \u222a B \u2286 A \u222a C \u2227 A \u2229 B \u2286 A \u2229 C \u2192 B \u2286 C :=\n/- dEAduction\nPrettyName\n    Question 4\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question5 : \nset.prod A (B \u222a C) = set.prod A B \u222a set.prod A C :=\n/- dEAduction\nPrettyName\n    Question 5\n-/ \nbegin\n    todo,\nend\n\n-- lemma exercise.question61 :\n-- \ud835\udcab(A \u222a B) = \ud835\udcab(A) \u222a \ud835\udcab(B) \u2228 \u00ac\ud835\udcab(A \u222a B) = \ud835\udcab(A) \u222a \ud835\udcab(B) :=  \n-- /- dEAduction\n-- PrettyName\n--     Question 6.1\n-- OpenQuestion\n--     True\n-- -/\n-- begin\n--     todo,\n-- end\n\nlemma exercise.question62 :\n\ud835\udcab(A \u2229 B) = \ud835\udcab(A) \u2229 \ud835\udcab(B) :=  \n/- dEAduction\nPrettyName\n    Question 6.2\n-/\nbegin\n    todo,\nend\n\n--\ud835\udcab(E \u222a {x}) = \ud835\udcab(E) \u222a {A' | \u2203A \u2208 \ud835\udcab(E), A' = A \u222a {x}} :=\nlemma exercise.question7 (F : Type) (E : set F) (x : F) (h : x \u2209 E) :\n\ud835\udcab(E \u222a {x}) = \ud835\udcab(E) \u222a {A' | \u2203A \u2286 E, A' = A \u222a {x}} :=\n/- dEAduction\nPrettyName\n    Question 7\n-/\nbegin\n    todo,\nend\n\nend exercice2\n\nnamespace exercice5\n/- dEAduction\nPrettyName\n    Exercice 5\n-/\n\nlemma exercise.question2_produit_inverse (X Y Z : Type) (R : set (X \u00d7 Y)) (S : set (Y \u00d7 Z)) :\n (R dot S) \u207b\u00b9 = ((S \u207b\u00b9) dot (R \u207b\u00b9)) :=\n /- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\nend exercice5\n\nnamespace exercice6\n/- dEAduction\nPrettyName\n    Exercice 6\n-/\n\nlemma exercise.question1 (X: Type) (R : set (X \u00d7 X)) :\nreflexive R \u2194 identite \u2286 R :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question2 (X: Type) (R : set (X \u00d7 X)) :\nsymetrique R \u2194 R = inv R  :=\n/- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 (X: Type) (R : set (X \u00d7 X)) :\nantisymetrique R \u2194 (R \u2229 (inv R)) \u2286 identite :=\n/- dEAduction\nPrettyName\n    Question 3\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question4 (X: Type) (R : set (X \u00d7 X)) :\ntransitive R \u2194 (product R R) \u2286 R :=\n/- dEAduction\nPrettyName\n    Question 4\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question5 (X: Type) (R : set (X \u00d7 X)) :\nreflexive R \u2192 R \u2286 (R dot R) \u2227 reflexive (R dot R) :=\n/- dEAduction\nPrettyName\n    Question 5\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question6 (X: Type) (R : set (X \u00d7 X)) :\nsymetrique R \u2192 (R \u207b\u00b9 dot R) = (R dot R \u207b\u00b9) :=\n/- dEAduction\nPrettyName\n    Question 6\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question7 (X: Type) (R : set (X \u00d7 X)) :\ntransitive R \u2192 transitive (R dot R) :=\n/- dEAduction\nPrettyName\n    Question 7\n-/\nbegin\n    todo,\nend\nend exercice6\n\nnamespace exercice8\n/- dEAduction\nPrettyName\n    Exercice 8\n-/\n\nlemma exercise.question1 (A : Type) (R : set (A \u00d7 A)) (H1 : relation_equivalence R) :\n\u2200a, a \u2208 classe_equivalence R H1 a :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question2 (A : Type) (R : set (A \u00d7 A)) (H1 : relation_equivalence R) (a b : A) :\nclasse_equivalence R H1 a = classe_equivalence R H1 b \u2194 (a,b) \u2208 R :=\n/- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 (A : Type) (R : set (A \u00d7 A)) (H1 : relation_equivalence R) (a b : A) :\nclasse_equivalence R H1 a \u2260 classe_equivalence R H1 b \u2192 classe_equivalence R H1 a \u2229 classe_equivalence R H1 b = \u2205 :=\n/- dEAduction\nPrettyName\n    Question 3\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question5 (A : Type) (R : set (A \u00d7 A)) (H1 : relation_equivalence R) :\npartition {A\u2081 | \u2203x, A\u2081 = classe_equivalence R H1 x} :=\n/- dEAduction\nPrettyName\n    Question 5\n-/\nbegin\n    todo,\nend\n\nend exercice8\n\n-- namespace exercice15\n-- /- dEAduction\n-- PrettyName\n--     Exercice 15\n-- -/\n\n-- -- TODO: int\u00e9grer les defs pour applications (composition, id, bijective)\n-- lemma exercise.question (X : Type) (f : X \u2192 X) :\n-- ((composition f f) = id : X \u2192 X) \u2192 bijective f:=\n-- /- dEAduction\n-- PrettyName\n--     Question 1\n-- -/\n-- begin\n--     todo,\n-- end\n-- end exercice15\n\nnamespace exercice22\n/- dEAduction\nPrettyName\n    Exercice 22\n-/\n\nlemma exercise.question1 (X Y : Type) (f : X \u2192 Y) (R : set (X \u00d7 X)) (H1 : \u2200x x', (x, x') \u2208 R \u2194 f x = f x') :\nrelation_equivalence R :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 (X Y : Type) (f : X \u2192 Y) (R : set (X \u00d7 X)) (H1 : \u2200x x', (x, x') \u2208 R \u2194 f x = f x')\n(H2: relation_equivalence R) :\n\u2200x y, x \u2208 classe_equivalence R H2 y \u2192 classe_equivalence R H2 x = classe_equivalence R H2 y :=\n/- dEAduction\nPrettyName\n    Question 3\n-/\nbegin\n    todo,\nend\n\n-- lemma exercise.question41 (E F : Type) (f : set (E \u00d7 F)) (H1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (S : set (E \u00d7 (set E))) (h6 : \u2200x y, relation.image S x y \u2194 y = classe_equivalence Rf h3 x) :\n-- relation.injective S \u2228 \u00acrelation.injective S :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 4.1\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question42 (E F : Type) (f : set (E \u00d7 F)) (H1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (S : set (E \u00d7 (set E))) (h6 : \u2200x y, relation.image S x y \u2194 y = classe_equivalence Rf h3 x) :\n-- relation.surjective S \u2228 \u00acrelation.surjective S :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 4.2\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question5 (E F : Type) (f : set (E \u00d7 F)) (H1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (f' : set ((set E) \u00d7 F)) (h6 : \u2200X y, (X, y) \u2208 f' \u2194 \u2203x \u2208 X, relation.image f x y) :\n-- application f' :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 5\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question61 (E F : Type) (f : set (E \u00d7 F)) (H1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (f' : set ((set E) \u00d7 F)) (h6 : \u2200X y, (X, y) \u2208 f' \u2194 \u2203x \u2208 X, relation.image f x y) :\n-- relation.injective f' \u2228 \u00ac relation.injective f' :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 6.1\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question62 (E F : Type) (f : set (E \u00d7 F)) (H1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (f' : set ((set E) \u00d7 F)) (h6 : \u2200X y, (X, y) \u2208 f' \u2194 \u2203x \u2208 X, relation.image f x y) :\n-- relation.injective f' \u2228 \u00ac relation.injective f' :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 6.2\n-- -/\n-- begin\n--     todo,\n-- end\n\n\nend exercice22\n\nend exercices\n\n\nend math_discretes\nend course\n\n", "meta": {"author": "dEAduction", "repo": "dEAduction-lean", "sha": "4fe1d642078fc94f9081ccbed08e047e86a741fd", "save_path": "github-repos/lean/dEAduction-dEAduction-lean", "path": "github-repos/lean/dEAduction-dEAduction-lean/dEAduction-lean-4fe1d642078fc94f9081ccbed08e047e86a741fd/src/exercises_deaduction_synchro/experimental/exercices_math_discretes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569268, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.73314183490252}}
{"text": "/-\nCopyright (c) 2020 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.specific_limits\nimport analysis.asymptotics.asymptotics\n\n/-!\n# The group of units of a complete normed ring\n\nThis file contains the basic theory for the group of units (invertible elements) of a complete\nnormed ring (Banach algebras being a notable special case).\n\n## Main results\n\nThe constructions `one_sub`, `add` and `unit_of_nearby` state, in varying forms, that perturbations\nof a unit are units.  The latter two are not stated in their optimal form; more precise versions\nwould use the spectral radius.\n\nThe first main result is `is_open`:  the group of units of a complete normed ring is an open subset\nof the ring.\n\nThe function `inverse` (defined in `algebra.ring`), for a ring `R`, sends `a : R` to `a\u207b\u00b9` if `a` is\na unit and 0 if not.  The other major results of this file (notably `inverse_add`,\n`inverse_add_norm` and `inverse_add_norm_diff_nth_order`) cover the asymptotic properties of\n`inverse (x + t)` as `t \u2192 0`.\n\n-/\n\nnoncomputable theory\nopen_locale topological_space\nvariables {R : Type*} [normed_ring R] [complete_space R]\n\nnamespace units\n\n/-- In a complete normed ring, a perturbation of `1` by an element `t` of distance less than `1`\nfrom `1` is a unit.  Here we construct its `units` structure.  -/\ndef one_sub (t : R) (h : \u2225t\u2225 < 1) : units R :=\n{ val := 1 - t,\n  inv := \u2211' n : \u2115, t ^ n,\n  val_inv := mul_neg_geom_series t h,\n  inv_val := geom_series_mul_neg t h }\n\n@[simp] lemma one_sub_coe (t : R) (h : \u2225t\u2225 < 1) : \u2191(one_sub t h) = 1 - t := rfl\n\n/-- In a complete normed ring, a perturbation of a unit `x` by an element `t` of distance less than\n`\u2225x\u207b\u00b9\u2225\u207b\u00b9` from `x` is a unit.  Here we construct its `units` structure. -/\ndef add (x : units R) (t : R) (h : \u2225t\u2225 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9) : units R :=\nx * (units.one_sub (-(\u2191x\u207b\u00b9 * t))\nbegin\n  nontriviality R using [zero_lt_one],\n  have hpos : 0 < \u2225(\u2191x\u207b\u00b9 : R)\u2225 := units.norm_pos x\u207b\u00b9,\n  calc \u2225-(\u2191x\u207b\u00b9 * t)\u2225\n      = \u2225\u2191x\u207b\u00b9 * t\u2225                    : by { rw norm_neg }\n  ... \u2264 \u2225(\u2191x\u207b\u00b9 : R)\u2225 * \u2225t\u2225            : norm_mul_le \u2191x\u207b\u00b9 _\n  ... < \u2225(\u2191x\u207b\u00b9 : R)\u2225 * \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9 : by nlinarith only [h, hpos]\n  ... = 1                             : mul_inv_cancel (ne_of_gt hpos)\nend)\n\n@[simp] lemma add_coe (x : units R) (t : R) (h : \u2225t\u2225 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9) :\n  ((x.add t h) : R) = x + t := by { unfold units.add, simp [mul_add] }\n\n/-- In a complete normed ring, an element `y` of distance less than `\u2225x\u207b\u00b9\u2225\u207b\u00b9` from `x` is a unit.\nHere we construct its `units` structure. -/\ndef unit_of_nearby (x : units R) (y : R) (h : \u2225y - x\u2225 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9) : units R :=\nx.add ((y : R) - x) h\n\n@[simp] lemma unit_of_nearby_coe (x : units R) (y : R) (h : \u2225y - x\u2225 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9) :\n  \u2191(x.unit_of_nearby y h) = y := by { unfold units.unit_of_nearby, simp }\n\n/-- The group of units of a complete normed ring is an open subset of the ring. -/\nprotected lemma is_open : is_open {x : R | is_unit x} :=\nbegin\n  nontriviality R,\n  apply metric.is_open_iff.mpr,\n  rintros x' \u27e8x, rfl\u27e9,\n  refine \u27e8\u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9, inv_pos.mpr (units.norm_pos x\u207b\u00b9), _\u27e9,\n  intros y hy,\n  rw [metric.mem_ball, dist_eq_norm] at hy,\n  exact \u27e8x.unit_of_nearby y hy, unit_of_nearby_coe _ _ _\u27e9\nend\n\nprotected lemma nhds (x : units R) : {x : R | is_unit x} \u2208 \ud835\udcdd (x : R) :=\nmem_nhds_sets units.is_open x.is_unit\n\nend units\n\nnamespace normed_ring\nopen_locale classical big_operators\nopen asymptotics filter metric finset ring\n\nlemma inverse_one_sub (t : R) (h : \u2225t\u2225 < 1) : inverse (1 - t) = \u2191(units.one_sub t h)\u207b\u00b9 :=\nby rw [\u2190 inverse_unit (units.one_sub t h), units.one_sub_coe]\n\n/-- The formula `inverse (x + t) = inverse (1 + x\u207b\u00b9 * t) * x\u207b\u00b9` holds for `t` sufficiently small. -/\nlemma inverse_add (x : units R) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((x : R) + t) = inverse (1 + \u2191x\u207b\u00b9 * t) * \u2191x\u207b\u00b9 :=\nbegin\n  nontriviality R,\n  rw [eventually_iff, mem_nhds_iff],\n  have hinv : 0 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9, by cancel_denoms,\n  use [\u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9, hinv],\n  intros t ht,\n  simp only [mem_ball, dist_zero_right] at ht,\n  have ht' : \u2225-\u2191x\u207b\u00b9 * t\u2225 < 1,\n  { refine lt_of_le_of_lt (norm_mul_le _ _) _,\n    rw norm_neg,\n    refine lt_of_lt_of_le (mul_lt_mul_of_pos_left ht x\u207b\u00b9.norm_pos) _,\n    cancel_denoms },\n  have hright := inverse_one_sub (-\u2191x\u207b\u00b9 * t) ht',\n  have hleft := inverse_unit (x.add t ht),\n  simp only [\u2190 neg_mul_eq_neg_mul, sub_neg_eq_add] at hright,\n  simp only [units.add_coe] at hleft,\n  simp [hleft, hright, units.add]\nend\n\nlemma inverse_one_sub_nth_order (n : \u2115) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((1:R) - t) = (\u2211 i in range n, t ^ i) + (t ^ n) * inverse (1 - t) :=\nbegin\n  simp only [eventually_iff, mem_nhds_iff],\n  use [1, by norm_num],\n  intros t ht,\n  simp only [mem_ball, dist_zero_right] at ht,\n  simp only [inverse_one_sub t ht, set.mem_set_of_eq],\n  have h : 1 = ((range n).sum (\u03bb i, t ^ i)) * (units.one_sub t ht) + t ^ n,\n  { simp only [units.one_sub_coe],\n    rw [\u2190 geom_sum, geom_sum_mul_neg],\n    simp },\n  rw [\u2190 one_mul \u2191(units.one_sub t ht)\u207b\u00b9, h, add_mul],\n  congr,\n  { rw [mul_assoc, (units.one_sub t ht).mul_inv],\n    simp },\n  { simp only [units.one_sub_coe],\n    rw [\u2190 add_mul, \u2190 geom_sum, geom_sum_mul_neg],\n    simp }\nend\n\n/-- The formula\n`inverse (x + t) = (\u2211 i in range n, (- x\u207b\u00b9 * t) ^ i) * x\u207b\u00b9 + (- x\u207b\u00b9 * t) ^ n * inverse (x + t)`\nholds for `t` sufficiently small. -/\nlemma inverse_add_nth_order (x : units R) (n : \u2115) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((x : R) + t)\n  = (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9 + (- \u2191x\u207b\u00b9 * t) ^ n * inverse (x + t) :=\nbegin\n  refine (inverse_add x).mp _,\n  have hzero : tendsto (\u03bb (t : R), - \u2191x\u207b\u00b9 * t) (\ud835\udcdd 0) (\ud835\udcdd 0),\n  { convert ((mul_left_continuous (- (\u2191x\u207b\u00b9 : R))).tendsto 0).comp tendsto_id,\n    simp },\n  refine (hzero.eventually (inverse_one_sub_nth_order n)).mp (eventually_of_forall _),\n  simp only [neg_mul_eq_neg_mul_symm, sub_neg_eq_add],\n  intros t h1 h2,\n  have h := congr_arg (\u03bb (a : R), a * \u2191x\u207b\u00b9) h1,\n  dsimp at h,\n  convert h,\n  rw [add_mul, mul_assoc],\n  simp [h2.symm]\nend\n\nlemma inverse_one_sub_norm : is_O (\u03bb t, inverse ((1:R) - t)) (\u03bb t, (1:\u211d)) (\ud835\udcdd (0:R)) :=\nbegin\n  simp only [is_O, is_O_with, eventually_iff, mem_nhds_iff],\n  refine \u27e8\u2225(1:R)\u2225 + 1, (2:\u211d)\u207b\u00b9, by norm_num, _\u27e9,\n  intros t ht,\n  simp only [ball, dist_zero_right, set.mem_set_of_eq] at ht,\n  have ht' : \u2225t\u2225 < 1,\n  { have : (2:\u211d)\u207b\u00b9 < 1 := by cancel_denoms,\n    linarith },\n  simp only [inverse_one_sub t ht', norm_one, mul_one, set.mem_set_of_eq],\n  change \u2225\u2211' n : \u2115, t ^ n\u2225 \u2264 _,\n  have := normed_ring.tsum_geometric_of_norm_lt_1 t ht',\n  have : (1 - \u2225t\u2225)\u207b\u00b9 \u2264 2,\n  { rw \u2190 inv_inv' (2:\u211d),\n    refine inv_le_inv_of_le (by norm_num) _,\n    have : (2:\u211d)\u207b\u00b9 + (2:\u211d)\u207b\u00b9 = 1 := by ring,\n    linarith },\n  linarith\nend\n\n/-- The function `\u03bb t, inverse (x + t)` is O(1) as `t \u2192 0`. -/\nlemma inverse_add_norm (x : units R) : is_O (\u03bb t, inverse (\u2191x + t)) (\u03bb t, (1:\u211d)) (\ud835\udcdd (0:R)) :=\nbegin\n  nontriviality R,\n  simp only [is_O_iff, norm_one, mul_one],\n  cases is_O_iff.mp (@inverse_one_sub_norm R _ _) with C hC,\n  use C * \u2225((x\u207b\u00b9:units R):R)\u2225,\n  have hzero : tendsto (\u03bb t, - (\u2191x\u207b\u00b9 : R) * t) (\ud835\udcdd 0) (\ud835\udcdd 0),\n  { convert ((mul_left_continuous (-\u2191x\u207b\u00b9 : R)).tendsto 0).comp tendsto_id,\n    simp },\n  refine (inverse_add x).mp ((hzero.eventually hC).mp (eventually_of_forall _)),\n  intros t bound iden,\n  rw iden,\n  simp at bound,\n  have hmul := norm_mul_le (inverse (1 + \u2191x\u207b\u00b9 * t)) \u2191x\u207b\u00b9,\n  nlinarith [norm_nonneg (\u2191x\u207b\u00b9 : R)]\nend\n\n/-- The function\n`\u03bb t, inverse (x + t) - (\u2211 i in range n, (- x\u207b\u00b9 * t) ^ i) * x\u207b\u00b9`\nis `O(t ^ n)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_nth_order (x : units R) (n : \u2115) :\n  is_O (\u03bb (t : R), inverse (\u2191x + t) - (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9)\n  (\u03bb t, \u2225t\u2225 ^ n) (\ud835\udcdd (0:R)) :=\nbegin\n  by_cases h : n = 0,\n  { simpa [h] using inverse_add_norm x },\n  have hn : 0 < n := nat.pos_of_ne_zero h,\n  simp [is_O_iff],\n  cases (is_O_iff.mp (inverse_add_norm x)) with C hC,\n  use C * \u2225(1:\u211d)\u2225 * \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n,\n  have h : eventually_eq (\ud835\udcdd (0:R))\n    (\u03bb t, inverse (\u2191x + t) - (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9)\n    (\u03bb t, ((- \u2191x\u207b\u00b9 * t) ^ n) * inverse (x + t)),\n  { refine (inverse_add_nth_order x n).mp (eventually_of_forall _),\n    intros t ht,\n    convert congr_arg (\u03bb a, a - (range n).sum (pow (-\u2191x\u207b\u00b9 * t)) * \u2191x\u207b\u00b9) ht,\n    simp },\n  refine h.mp (hC.mp (eventually_of_forall _)),\n  intros t _ hLHS,\n  simp only [neg_mul_eq_neg_mul_symm] at hLHS,\n  rw hLHS,\n  refine le_trans (norm_mul_le _ _ ) _,\n  have h' : \u2225(-(\u2191x\u207b\u00b9 * t)) ^ n\u2225 \u2264 \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n * \u2225t\u2225 ^ n,\n  { calc \u2225(-(\u2191x\u207b\u00b9 * t)) ^ n\u2225 \u2264 \u2225(-(\u2191x\u207b\u00b9 * t))\u2225 ^ n : norm_pow_le' _ hn\n    ... = \u2225\u2191x\u207b\u00b9 * t\u2225 ^ n : by rw norm_neg\n    ... \u2264 (\u2225(\u2191x\u207b\u00b9 : R)\u2225 * \u2225t\u2225) ^ n : _\n    ... =  \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n * \u2225t\u2225 ^ n : mul_pow _ _ n,\n    exact pow_le_pow_of_le_left (norm_nonneg _) (norm_mul_le \u2191x\u207b\u00b9 t) n },\n  have h'' : 0 \u2264 \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n * \u2225t\u2225 ^ n,\n  { refine mul_nonneg _ _;\n    exact pow_nonneg (norm_nonneg _) n },\n  nlinarith [norm_nonneg (inverse (\u2191x + t))],\nend\n\n/-- The function `\u03bb t, inverse (x + t) - x\u207b\u00b9` is `O(t)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_first_order (x : units R) :\n  is_O (\u03bb t, inverse (\u2191x + t) - \u2191x\u207b\u00b9) (\u03bb t, \u2225t\u2225) (\ud835\udcdd (0:R)) :=\nby { convert inverse_add_norm_diff_nth_order x 1; simp }\n\n/-- The function\n`\u03bb t, inverse (x + t) - x\u207b\u00b9 + x\u207b\u00b9 * t * x\u207b\u00b9`\nis `O(t ^ 2)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_second_order (x : units R) :\n  is_O (\u03bb t, inverse (\u2191x + t) - \u2191x\u207b\u00b9 + \u2191x\u207b\u00b9 * t * \u2191x\u207b\u00b9) (\u03bb t, \u2225t\u2225 ^ 2) (\ud835\udcdd (0:R)) :=\nbegin\n  convert inverse_add_norm_diff_nth_order x 2,\n  ext t,\n  simp only [range_succ, range_one, sum_insert, mem_singleton, sum_singleton, not_false_iff,\n    one_ne_zero, pow_zero, add_mul],\n  abel,\n  simp\nend\n\n/-- The function `inverse` is continuous at each unit of `R`. -/\nlemma inverse_continuous_at (x : units R) : continuous_at inverse (x : R) :=\nbegin\n  have h_is_o : is_o (\u03bb (t : R), \u2225inverse (\u2191x + t) - \u2191x\u207b\u00b9\u2225) (\u03bb (t : R), (1:\u211d)) (\ud835\udcdd 0),\n  { refine is_o_norm_left.mpr ((inverse_add_norm_diff_first_order x).trans_is_o _),\n    exact is_o_norm_left.mpr (is_o_id_const one_ne_zero) },\n  have h_lim : tendsto (\u03bb (y:R), y - x) (\ud835\udcdd x) (\ud835\udcdd 0),\n  { refine tendsto_zero_iff_norm_tendsto_zero.mpr _,\n    exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },\n  simp only [continuous_at],\n  rw [tendsto_iff_norm_tendsto_zero, inverse_unit],\n  convert h_is_o.tendsto_0.comp h_lim,\n  ext, simp\nend\n\nend normed_ring\n\nnamespace units\nopen opposite filter normed_ring\n\n/-- In a normed ring, the coercion from `units R` (equipped with the induced topology from the\nembedding in `R \u00d7 R`) to `R` is an open map. -/\nlemma is_open_map_coe : is_open_map (coe : units R \u2192 R) :=\nbegin\n  rw is_open_map_iff_nhds_le,\n  intros x s,\n  rw [mem_map, mem_nhds_induced],\n  rintros \u27e8t, ht, hts\u27e9,\n  obtain \u27e8u, hu, v, hv, huvt\u27e9 :\n    \u2203 (u : set R), u \u2208 \ud835\udcdd \u2191x \u2227 \u2203 (v : set R\u1d52\u1d56), v \u2208 \ud835\udcdd (opposite.op \u2191x\u207b\u00b9) \u2227 u.prod v \u2286 t,\n  { simpa [embed_product, mem_nhds_prod_iff] using ht },\n  have : u \u2229 (op \u2218 ring.inverse) \u207b\u00b9' v \u2229 (set.range (coe : units R \u2192 R)) \u2208 \ud835\udcdd \u2191x,\n  { refine inter_mem_sets (inter_mem_sets hu _) (units.nhds x),\n    refine (continuous_op.continuous_at.comp (inverse_continuous_at x)).preimage_mem_nhds _,\n    simpa using hv },\n  refine mem_sets_of_superset this _,\n  rintros _ \u27e8\u27e8huy, hvy\u27e9, \u27e8y, rfl\u27e9\u27e9,\n  have : embed_product R y \u2208 u.prod v := \u27e8huy, by simpa using hvy\u27e9,\n  simpa using hts (huvt this)\nend\n\n/-- In a normed ring, the coercion from `units R` (equipped with the induced topology from the\nembedding in `R \u00d7 R`) to `R` is an open embedding. -/\nlemma open_embedding_coe : open_embedding (coe : units R \u2192 R) :=\nopen_embedding_of_continuous_injective_open continuous_coe ext is_open_map_coe\n\nend units\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/normed_space/units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7331370880640904}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport ring_theory.matrix_algebra\nimport data.polynomial.algebra_map\n\n/-!\n# Algebra isomorphism between matrices of polynomials and polynomials of matrices\n\nGiven `[comm_ring R] [ring A] [algebra R A]`\nwe show `polynomial A \u2243\u2090[R] (A \u2297[R] polynomial R)`.\nCombining this with the isomorphism `matrix n n A \u2243\u2090[R] (A \u2297[R] matrix n n R)` proved earlier\nin `ring_theory.matrix_algebra`, we obtain the algebra isomorphism\n```\ndef mat_poly_equiv :\n  matrix n n (polynomial R) \u2243\u2090[R] polynomial (matrix n n R)\n```\nwhich is characterized by\n```\ncoeff (mat_poly_equiv m) k i j = coeff (m i j) k\n```\n\nWe will use this algebra isomorphism to prove the Cayley-Hamilton theorem.\n-/\n\nuniverses u v w\n\nopen_locale tensor_product\n\nopen polynomial\nopen tensor_product\nopen algebra.tensor_product (alg_hom_of_linear_map_tensor_product include_left)\n\nnoncomputable theory\n\nvariables (R A : Type*)\nvariables [comm_semiring R]\nvariables [semiring A] [algebra R A]\n\nnamespace poly_equiv_tensor\n\n/--\n(Implementation detail).\nThe bare function underlying `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`, on pure tensors.\n-/\ndef to_fun (a : A) (p : polynomial R) : polynomial A :=\np.sum (\u03bb n r, monomial n (a * algebra_map R A r))\n\n/--\n(Implementation detail).\nThe function underlying `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`,\nas a linear map in the second factor.\n-/\ndef to_fun_linear_right (a : A) : polynomial R \u2192\u2097[R] polynomial A :=\n{ to_fun := to_fun R A a,\n  map_smul' := \u03bb r p,\n  begin\n    dsimp [to_fun],\n    rw finsupp.sum_smul_index,\n    { dsimp [finsupp.sum],\n      rw finset.smul_sum,\n      apply finset.sum_congr rfl,\n      intros k hk,\n      rw [monomial_eq_smul_X, monomial_eq_smul_X, algebra.smul_def, \u2190 C_mul', \u2190 C_mul',\n          \u2190 mul_assoc],\n      congr' 1,\n      rw [\u2190 algebra.commutes, \u2190 algebra.commutes],\n      simp only [ring_hom.map_mul, polynomial.algebra_map_apply, mul_assoc], },\n    { intro i, simp only [ring_hom.map_zero, mul_zero, monomial_zero_right] },\n  end,\n  map_add' := \u03bb p q,\n  begin\n    simp only [to_fun],\n    rw finsupp.sum_add_index,\n    { simp only [monomial_zero_right, forall_const, ring_hom.map_zero, mul_zero], },\n    { intros i r s, simp only [ring_hom.map_add, mul_add, monomial_add], },\n  end, }\n\n/--\n(Implementation detail).\nThe function underlying `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`,\nas a bilinear function of two arguments.\n-/\ndef to_fun_bilinear : A \u2192\u2097[R] polynomial R \u2192\u2097[R] polynomial A :=\n{ to_fun := to_fun_linear_right R A,\n  map_smul' := by {\n    intros, unfold to_fun_linear_right,\n    congr, simp only [linear_map.coe_mk],\n    unfold to_fun finsupp.sum,\n    simp_rw [finset.smul_sum, smul_monomial,  \u2190 algebra.smul_mul_assoc],\n    refl },\n  map_add' := by {\n    intros, unfold to_fun_linear_right,\n    congr, simp only [linear_map.coe_mk],\n    unfold to_fun finsupp.sum,\n    simp_rw [\u2190 finset.sum_add_distrib, \u2190 monomial_add, \u2190 add_mul],\n    refl } }\n\n/--\n(Implementation detail).\nThe function underlying `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`,\nas a linear map.\n-/\ndef to_fun_linear : A \u2297[R] polynomial R \u2192\u2097[R] polynomial A :=\ntensor_product.lift (to_fun_bilinear R A)\n\n-- We apparently need to provide the decidable instance here\n-- in order to successfully rewrite by this lemma.\nlemma to_fun_linear_mul_tmul_mul_aux_1\n  (p : polynomial R) (k : \u2115) (h : decidable (\u00acp.coeff k = 0)) (a : A) :\n  ite (\u00accoeff p k = 0) (a * (algebra_map R A) (coeff p k)) 0 = a * (algebra_map R A) (coeff p k) :=\nby { classical, split_ifs; simp *, }\n\nlemma to_fun_linear_mul_tmul_mul_aux_2 (k : \u2115) (a\u2081 a\u2082 : A) (p\u2081 p\u2082 : polynomial R) :\n  a\u2081 * a\u2082 * (algebra_map R A) ((p\u2081 * p\u2082).coeff k) =\n    (finset.nat.antidiagonal k).sum\n      (\u03bb x, a\u2081 * (algebra_map R A) (coeff p\u2081 x.1) * (a\u2082 * (algebra_map R A) (coeff p\u2082 x.2))) :=\nbegin\n  simp_rw [mul_assoc, algebra.commutes, \u2190finset.mul_sum, mul_assoc, \u2190finset.mul_sum],\n  congr,\n  simp_rw [algebra.commutes (coeff p\u2082 _), coeff_mul, ring_hom.map_sum, ring_hom.map_mul],\nend\n\nlemma to_fun_linear_mul_tmul_mul (a\u2081 a\u2082 : A) (p\u2081 p\u2082 : polynomial R) :\n  (to_fun_linear R A) ((a\u2081 * a\u2082) \u2297\u209c[R] (p\u2081 * p\u2082)) =\n    (to_fun_linear R A) (a\u2081 \u2297\u209c[R] p\u2081) * (to_fun_linear R A) (a\u2082 \u2297\u209c[R] p\u2082) :=\nbegin\n  dsimp [to_fun_linear],\n  simp only [lift.tmul],\n  dsimp [to_fun_bilinear, to_fun_linear_right, to_fun],\n  ext k,\n  -- TODO This is a bit annoying: the polynomial API is breaking down.\n  have apply_eq_coeff : \u2200 {p : \u2115 \u2192\u2080 R} {n : \u2115}, p n = coeff p n := by { intros, refl },\n  simp_rw [coeff_sum, coeff_monomial, finsupp.sum, finset.sum_ite_eq', finsupp.mem_support_iff,\n    ne.def, coeff_mul, finset_sum_coeff, coeff_monomial,\n    finset.sum_ite_eq', finsupp.mem_support_iff, ne.def,\n    mul_ite, mul_zero, ite_mul, zero_mul, apply_eq_coeff],\n  simp_rw [ite_mul_zero_left (\u00accoeff p\u2081 _ = 0) (a\u2081 * (algebra_map R A) (coeff p\u2081 _))],\n  simp_rw [ite_mul_zero_right (\u00accoeff p\u2082 _ = 0) _ (_ * _)],\n  simp_rw [to_fun_linear_mul_tmul_mul_aux_1, to_fun_linear_mul_tmul_mul_aux_2],\nend\n\nlemma to_fun_linear_algebra_map_tmul_one (r : R) :\n  (to_fun_linear R A) ((algebra_map R A) r \u2297\u209c[R] 1) = (algebra_map R (polynomial A)) r :=\nbegin\n  dsimp [to_fun_linear],\n  simp only [lift.tmul],\n  dsimp [to_fun_bilinear, to_fun_linear_right, to_fun],\n  rw [\u2190 C_1, \u2190monomial_zero_left],\n  refine (finsupp.sum_single_index _).trans _; simp [algebra_map_apply]\nend\n\n/--\n(Implementation detail).\nThe algebra homomorphism `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`.\n-/\ndef to_fun_alg_hom : A \u2297[R] polynomial R \u2192\u2090[R] polynomial A :=\nalg_hom_of_linear_map_tensor_product\n  (to_fun_linear R A)\n  (to_fun_linear_mul_tmul_mul R A)\n  (to_fun_linear_algebra_map_tmul_one R A)\n\n@[simp] lemma to_fun_alg_hom_apply_tmul (a : A) (p : polynomial R) :\n  to_fun_alg_hom R A (a \u2297\u209c[R] p) = p.sum (\u03bb n r, monomial n (a * (algebra_map R A) r)) :=\nby simp [to_fun_alg_hom, to_fun_linear, to_fun_bilinear, to_fun_linear_right, to_fun]\n\n/--\n(Implementation detail.)\n\nThe bare function `polynomial A \u2192 A \u2297[R] polynomial R`.\n(We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.)\n-/\ndef inv_fun (p : polynomial A) : A \u2297[R] polynomial R :=\np.eval\u2082\n  (include_left : A \u2192\u2090[R] A \u2297[R] polynomial R)\n  ((1 : A) \u2297\u209c[R] (X : polynomial R))\n\n@[simp]\nlemma inv_fun_add {p q} : inv_fun R A (p + q) = inv_fun R A p + inv_fun R A q :=\nby simp only [inv_fun, eval\u2082_add]\n\nlemma inv_fun_monomial (n : \u2115) (a : A) :\n  inv_fun R A (monomial n a) = include_left a * ((1 : A) \u2297\u209c[R] (X : polynomial R)) ^ n :=\neval\u2082_monomial _ _\n\nlemma left_inv (x : A \u2297 polynomial R) :\n  inv_fun R A ((to_fun_alg_hom R A) x) = x :=\nbegin\n  apply tensor_product.induction_on x,\n  { simp [inv_fun], },\n  { intros a p, dsimp only [inv_fun],\n    rw [to_fun_alg_hom_apply_tmul, eval\u2082_sum],\n    simp_rw [eval\u2082_monomial, alg_hom.coe_to_ring_hom, algebra.tensor_product.tmul_pow, one_pow,\n      algebra.tensor_product.include_left_apply, algebra.tensor_product.tmul_mul_tmul,\n      mul_one, one_mul, \u2190algebra.commutes, \u2190algebra.smul_def'', smul_tmul],\n    rw [finsupp.sum, \u2190tmul_sum],\n    conv_rhs { rw [\u2190sum_C_mul_X_eq p], },\n    simp only [algebra.smul_def''],\n    refl, },\n  { intros p q hp hq,\n    simp only [alg_hom.map_add, inv_fun_add, hp, hq], },\nend\n\nlemma right_inv (x : polynomial A) :\n  (to_fun_alg_hom R A) (inv_fun R A x) = x :=\nbegin\n  apply polynomial.induction_on' x,\n  { intros p q hp hq, simp only [inv_fun_add, alg_hom.map_add, hp, hq], },\n  { intros n a,\n    rw [inv_fun_monomial, algebra.tensor_product.include_left_apply,\n      algebra.tensor_product.tmul_pow, one_pow, algebra.tensor_product.tmul_mul_tmul,\n      mul_one, one_mul, to_fun_alg_hom_apply_tmul, X_pow_eq_monomial],\n    dsimp [monomial],\n    rw [finsupp.sum_single_index]; simp, }\nend\n\n/--\n(Implementation detail)\n\nThe equivalence, ignoring the algebra structure, `(A \u2297[R] polynomial R) \u2243 polynomial A`.\n-/\ndef equiv : (A \u2297[R] polynomial R) \u2243 polynomial A :=\n{ to_fun := to_fun_alg_hom R A,\n  inv_fun := inv_fun R A,\n  left_inv := left_inv R A,\n  right_inv := right_inv R A, }\n\nend poly_equiv_tensor\n\nopen poly_equiv_tensor\n\n/--\nThe `R`-algebra isomorphism `polynomial A \u2243\u2090[R] (A \u2297[R] polynomial R)`.\n-/\ndef poly_equiv_tensor : polynomial A \u2243\u2090[R] (A \u2297[R] polynomial R) :=\nalg_equiv.symm\n{ ..(poly_equiv_tensor.to_fun_alg_hom R A), ..(poly_equiv_tensor.equiv R A) }\n\n@[simp]\nlemma poly_equiv_tensor_apply (p : polynomial A) :\n  poly_equiv_tensor R A p =\n    p.eval\u2082 (include_left : A \u2192\u2090[R] A \u2297[R] polynomial R) ((1 : A) \u2297\u209c[R] (X : polynomial R)) :=\nrfl\n\n@[simp]\nlemma poly_equiv_tensor_symm_apply_tmul (a : A) (p : polynomial R) :\n  (poly_equiv_tensor R A).symm (a \u2297\u209c p) = p.sum (\u03bb n r, monomial n (a * algebra_map R A r)) :=\nbegin\n  simp [poly_equiv_tensor, to_fun_alg_hom, alg_hom_of_linear_map_tensor_product, to_fun_linear],\n  refl,\nend\n\nopen dmatrix matrix\nopen_locale big_operators\n\nvariables {R}\nvariables {n : Type w} [decidable_eq n] [fintype n]\n\n/--\nThe algebra isomorphism stating \"matrices of polynomials are the same as polynomials of matrices\".\n\n(You probably shouldn't attempt to use this underlying definition ---\nit's an algebra equivalence, and characterised extensionally by the lemma\n`mat_poly_equiv_coeff_apply` below.)\n-/\nnoncomputable def mat_poly_equiv :\n  matrix n n (polynomial R) \u2243\u2090[R] polynomial (matrix n n R) :=\n(((matrix_equiv_tensor R (polynomial R) n)).trans\n  (algebra.tensor_product.comm R _ _)).trans\n  (poly_equiv_tensor R (matrix n n R)).symm\n\nopen finset\n\nlemma mat_poly_equiv_coeff_apply_aux_1 (i j : n) (k : \u2115) (x : R) :\n  mat_poly_equiv (std_basis_matrix i j $ monomial k x) =\n    monomial k (std_basis_matrix i j x) :=\nbegin\n  simp only [mat_poly_equiv, alg_equiv.trans_apply,\n    matrix_equiv_tensor_apply_std_basis],\n  apply (poly_equiv_tensor R (matrix n n R)).injective,\n  simp only [alg_equiv.apply_symm_apply],\n  convert algebra.tensor_product.comm_tmul _ _ _ _ _,\n  simp only [poly_equiv_tensor_apply],\n  convert eval\u2082_monomial _ _,\n  simp only [algebra.tensor_product.tmul_mul_tmul, one_pow, one_mul, matrix.mul_one,\n    algebra.tensor_product.tmul_pow, algebra.tensor_product.include_left_apply, mul_eq_mul],\n  rw [monomial_eq_smul_X, \u2190 tensor_product.smul_tmul],\n  congr' with i' j'; simp\nend\n\nlemma mat_poly_equiv_coeff_apply_aux_2\n  (i j : n) (p : polynomial R) (k : \u2115) :\n  coeff (mat_poly_equiv (std_basis_matrix i j p)) k =\n    std_basis_matrix i j (coeff p k) :=\nbegin\n  apply polynomial.induction_on' p,\n  { intros p q hp hq, ext,\n    simp [hp, hq, coeff_add, add_apply, std_basis_matrix_add], },\n  { intros k x,\n    simp only [mat_poly_equiv_coeff_apply_aux_1, coeff_monomial],\n    split_ifs; { funext, simp, }, }\nend\n\n@[simp] lemma mat_poly_equiv_coeff_apply\n  (m : matrix n n (polynomial R)) (k : \u2115) (i j : n) :\n  coeff (mat_poly_equiv m) k i j = coeff (m i j) k :=\nbegin\n  apply matrix.induction_on' m,\n  { simp, },\n  { intros p q hp hq, simp [hp, hq], },\n  { intros i' j' x,\n    erw mat_poly_equiv_coeff_apply_aux_2,\n    dsimp [std_basis_matrix],\n    split_ifs,\n    { rcases h with \u27e8rfl, rfl\u27e9, simp [std_basis_matrix], },\n    { simp [std_basis_matrix, h], }, },\nend\n\n@[simp] lemma mat_poly_equiv_symm_apply_coeff\n  (p : polynomial (matrix n n R)) (i j : n) (k : \u2115) :\n  coeff (mat_poly_equiv.symm p i j) k = coeff p k i j :=\nbegin\n  have t : p = mat_poly_equiv\n    (mat_poly_equiv.symm p) := by simp,\n  conv_rhs { rw t, },\n  simp only [mat_poly_equiv_coeff_apply],\nend\n\nlemma mat_poly_equiv_smul_one (p : polynomial R) :\n  mat_poly_equiv (p \u2022 1) = p.map (algebra_map R (matrix n n R)) :=\nbegin\n  ext m i j,\n  simp only [coeff_map, one_apply, algebra_map_matrix_apply, mul_boole,\n    smul_apply, mat_poly_equiv_coeff_apply],\n  split_ifs; simp,\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/polynomial_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7331370841526548}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport AdvancedAdditionWorld.Level1 --  succ_inj\nimport AdvancedAdditionWorld.Level9 --  zero_ne_succ\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Inequality world.\n\n## Level 13: `not_succ_le_self`\n\nTurns out that `\u00ac P` is *by definition* `P \u2192 false`, so you can just\nstart this one with `intro h` if you like.\n\n##  Lemma : not_succ_le_self\nFor all naturals `a`, `succ a` is not at most `a`.\n-/\ntheorem not_succ_le_self (a : MyNat) : \u00ac (succ a \u2264 a) := by\n  intro h\n  cases h with\n  | _ c h =>\n    induction a with\n    | zero =>\n      rw [succ_add] at h\n      exact zero_ne_succ _ h\n    | succ d hd =>\n      rw [succ_add] at h\n      apply hd\n      apply succ_inj\n      exact h\n\n/-!\n\n## Pro tip:\n\nThe `conv` tactic allows you to perform targeted rewriting on a goal or hypothesis, by focusing\non particular subexpressions.\n\n```\n  conv =>\n    lhs\n    rw hc\n```\n\nThis is an incantation which rewrites `hc` only on the left hand side of the goal.\nYou didn't need to use `conv` in the above proof\nbut it's a helpful trick when `rw` is rewriting too much.\n\nFor a deeper discussion on `conv` see [Conversion Tactic Mode](https://leanprover.github.io/theorem_proving_in_lean4/conv.html)\n\n\nNext up [Level 14](./Level14.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7331187895346554}}
{"text": "/-\nCopyright (c) 2021 Chris Hughes, Junyan Xu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Junyan Xu\n-/\nimport data.polynomial.basic\nimport set_theory.cardinal.ordinal\n/-!\n# Cardinality of Polynomial Ring\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe reuslt in this file is that the cardinality of `R[X]` is at most the maximum\nof `#R` and `\u2135\u2080`.\n-/\nuniverse u\n\nopen_locale cardinal polynomial\nopen cardinal\n\nnamespace polynomial\n\n@[simp] lemma cardinal_mk_eq_max {R : Type u} [semiring R] [nontrivial R] : #R[X] = max (#R) \u2135\u2080 :=\n(to_finsupp_iso R).to_equiv.cardinal_eq.trans $\n  by { rw [add_monoid_algebra, mk_finsupp_lift_of_infinite, lift_uzero, max_comm], refl }\n\nlemma cardinal_mk_le_max {R : Type u} [semiring R] : #R[X] \u2264 max (#R) \u2135\u2080 :=\nbegin\n  casesI subsingleton_or_nontrivial R,\n  { exact (mk_eq_one _).trans_le (le_max_of_le_right one_le_aleph_0) },\n  { exact cardinal_mk_eq_max.le },\nend\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7331187873299828}}
{"text": "/-\nCopyright (c) 2021 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n\n! This file was ported from Lean 3 source module measure_theory.measure.with_density_vector_measure\n! leanprover-community/mathlib commit d1bd9c5df2867c1cb463bc6364446d57bdd9f7f1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.VectorMeasure\nimport Mathbin.MeasureTheory.Function.AeEqOfIntegral\n\n/-!\n\n# Vector measure defined by an integral\n\nGiven a measure `\u03bc` and an integrable function `f : \u03b1 \u2192 E`, we can define a vector measure `v` such\nthat for all measurable set `s`, `v i = \u222b x in s, f x \u2202\u03bc`. This definition is useful for\nthe Radon-Nikodym theorem for signed measures.\n\n## Main definitions\n\n* `measure_theory.measure.with_density\u1d65`: the vector measure formed by integrating a function `f`\n  with respect to a measure `\u03bc` on some set if `f` is integrable, and `0` otherwise.\n\n-/\n\n\nnoncomputable section\n\nopen Classical MeasureTheory NNReal ENNReal\n\nvariable {\u03b1 \u03b2 : Type _} {m : MeasurableSpace \u03b1}\n\nnamespace MeasureTheory\n\nopen TopologicalSpace\n\nvariable {\u03bc \u03bd : Measure \u03b1}\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] [CompleteSpace E]\n\n/-- Given a measure `\u03bc` and an integrable function `f`, `\u03bc.with_density\u1d65 f` is\nthe vector measure which maps the set `s` to `\u222b\u209b f \u2202\u03bc`. -/\ndef Measure.withDensity\u1d65 {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) (f : \u03b1 \u2192 E) : VectorMeasure \u03b1 E :=\n  if hf : Integrable f \u03bc then\n    { measureOf' := fun s => if MeasurableSet s then \u222b x in s, f x \u2202\u03bc else 0\n      empty' := by simp\n      not_measurable' := fun s hs => if_neg hs\n      m_Union' := fun s hs\u2081 hs\u2082 =>\n        by\n        convert has_sum_integral_Union hs\u2081 hs\u2082 hf.integrable_on\n        \u00b7 ext n\n          rw [if_pos (hs\u2081 n)]\n        \u00b7 rw [if_pos (MeasurableSet.union\u1d62 hs\u2081)] }\n  else 0\n#align measure_theory.measure.with_density\u1d65 MeasureTheory.Measure.withDensity\u1d65\n\nopen Measure\n\ninclude m\n\nvariable {f g : \u03b1 \u2192 E}\n\ntheorem withDensity\u1d65_apply (hf : Integrable f \u03bc) {s : Set \u03b1} (hs : MeasurableSet s) :\n    \u03bc.withDensity\u1d65 f s = \u222b x in s, f x \u2202\u03bc :=\n  by\n  rw [with_density\u1d65, dif_pos hf]\n  exact dif_pos hs\n#align measure_theory.with_density\u1d65_apply MeasureTheory.withDensity\u1d65_apply\n\n@[simp]\ntheorem withDensity\u1d65_zero : \u03bc.withDensity\u1d65 (0 : \u03b1 \u2192 E) = 0 :=\n  by\n  ext1 s hs\n  erw [with_density\u1d65_apply (integrable_zero \u03b1 E \u03bc) hs]\n  simp\n#align measure_theory.with_density\u1d65_zero MeasureTheory.withDensity\u1d65_zero\n\n@[simp]\ntheorem withDensity\u1d65_neg : \u03bc.withDensity\u1d65 (-f) = -\u03bc.withDensity\u1d65 f :=\n  by\n  by_cases hf : integrable f \u03bc\n  \u00b7 ext1 i hi\n    rw [vector_measure.neg_apply, with_density\u1d65_apply hf hi, \u2190 integral_neg,\n      with_density\u1d65_apply hf.neg hi]\n    rfl\n  \u00b7 rw [with_density\u1d65, with_density\u1d65, dif_neg hf, dif_neg, neg_zero]\n    rwa [integrable_neg_iff]\n#align measure_theory.with_density\u1d65_neg MeasureTheory.withDensity\u1d65_neg\n\ntheorem withDensity\u1d65_neg' : (\u03bc.withDensity\u1d65 fun x => -f x) = -\u03bc.withDensity\u1d65 f :=\n  withDensity\u1d65_neg\n#align measure_theory.with_density\u1d65_neg' MeasureTheory.withDensity\u1d65_neg'\n\n@[simp]\ntheorem withDensity\u1d65_add (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    \u03bc.withDensity\u1d65 (f + g) = \u03bc.withDensity\u1d65 f + \u03bc.withDensity\u1d65 g :=\n  by\n  ext1 i hi\n  rw [with_density\u1d65_apply (hf.add hg) hi, vector_measure.add_apply, with_density\u1d65_apply hf hi,\n    with_density\u1d65_apply hg hi]\n  simp_rw [Pi.add_apply]\n  rw [integral_add] <;> rw [\u2190 integrable_on_univ]\n  \u00b7 exact hf.integrable_on.restrict MeasurableSet.univ\n  \u00b7 exact hg.integrable_on.restrict MeasurableSet.univ\n#align measure_theory.with_density\u1d65_add MeasureTheory.withDensity\u1d65_add\n\ntheorem withDensity\u1d65_add' (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    (\u03bc.withDensity\u1d65 fun x => f x + g x) = \u03bc.withDensity\u1d65 f + \u03bc.withDensity\u1d65 g :=\n  withDensity\u1d65_add hf hg\n#align measure_theory.with_density\u1d65_add' MeasureTheory.withDensity\u1d65_add'\n\n@[simp]\ntheorem withDensity\u1d65_sub (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    \u03bc.withDensity\u1d65 (f - g) = \u03bc.withDensity\u1d65 f - \u03bc.withDensity\u1d65 g := by\n  rw [sub_eq_add_neg, sub_eq_add_neg, with_density\u1d65_add hf hg.neg, with_density\u1d65_neg]\n#align measure_theory.with_density\u1d65_sub MeasureTheory.withDensity\u1d65_sub\n\ntheorem withDensity\u1d65_sub' (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    (\u03bc.withDensity\u1d65 fun x => f x - g x) = \u03bc.withDensity\u1d65 f - \u03bc.withDensity\u1d65 g :=\n  withDensity\u1d65_sub hf hg\n#align measure_theory.with_density\u1d65_sub' MeasureTheory.withDensity\u1d65_sub'\n\n@[simp]\ntheorem withDensity\u1d65_smul {\ud835\udd5c : Type _} [NontriviallyNormedField \ud835\udd5c] [NormedSpace \ud835\udd5c E]\n    [SMulCommClass \u211d \ud835\udd5c E] (f : \u03b1 \u2192 E) (r : \ud835\udd5c) : \u03bc.withDensity\u1d65 (r \u2022 f) = r \u2022 \u03bc.withDensity\u1d65 f :=\n  by\n  by_cases hf : integrable f \u03bc\n  \u00b7 ext1 i hi\n    rw [with_density\u1d65_apply (hf.smul r) hi, vector_measure.smul_apply, with_density\u1d65_apply hf hi, \u2190\n      integral_smul r f]\n    rfl\n  \u00b7 by_cases hr : r = 0\n    \u00b7 rw [hr, zero_smul, zero_smul, with_density\u1d65_zero]\n    \u00b7 rw [with_density\u1d65, with_density\u1d65, dif_neg hf, dif_neg, smul_zero]\n      rwa [integrable_smul_iff hr f]\n#align measure_theory.with_density\u1d65_smul MeasureTheory.withDensity\u1d65_smul\n\ntheorem withDensity\u1d65_smul' {\ud835\udd5c : Type _} [NontriviallyNormedField \ud835\udd5c] [NormedSpace \ud835\udd5c E]\n    [SMulCommClass \u211d \ud835\udd5c E] (f : \u03b1 \u2192 E) (r : \ud835\udd5c) :\n    (\u03bc.withDensity\u1d65 fun x => r \u2022 f x) = r \u2022 \u03bc.withDensity\u1d65 f :=\n  withDensity\u1d65_smul f r\n#align measure_theory.with_density\u1d65_smul' MeasureTheory.withDensity\u1d65_smul'\n\ntheorem Measure.withDensity\u1d65AbsolutelyContinuous (\u03bc : Measure \u03b1) (f : \u03b1 \u2192 \u211d) :\n    \u03bc.withDensity\u1d65 f \u226a\u1d65 \u03bc.toEnnrealVectorMeasure :=\n  by\n  by_cases hf : integrable f \u03bc\n  \u00b7 refine' vector_measure.absolutely_continuous.mk fun i hi\u2081 hi\u2082 => _\n    rw [to_ennreal_vector_measure_apply_measurable hi\u2081] at hi\u2082\n    rw [with_density\u1d65_apply hf hi\u2081, measure.restrict_zero_set hi\u2082, integral_zero_measure]\n  \u00b7 rw [with_density\u1d65, dif_neg hf]\n    exact vector_measure.absolutely_continuous.zero _\n#align measure_theory.measure.with_density\u1d65_absolutely_continuous MeasureTheory.Measure.withDensity\u1d65AbsolutelyContinuous\n\n/-- Having the same density implies the underlying functions are equal almost everywhere. -/\ntheorem Integrable.ae_eq_of_withDensity\u1d65_eq {f g : \u03b1 \u2192 E} (hf : Integrable f \u03bc)\n    (hg : Integrable g \u03bc) (hfg : \u03bc.withDensity\u1d65 f = \u03bc.withDensity\u1d65 g) : f =\u1d50[\u03bc] g :=\n  by\n  refine' hf.ae_eq_of_forall_set_integral_eq f g hg fun i hi _ => _\n  rw [\u2190 with_density\u1d65_apply hf hi, hfg, with_density\u1d65_apply hg hi]\n#align measure_theory.integrable.ae_eq_of_with_density\u1d65_eq MeasureTheory.Integrable.ae_eq_of_withDensity\u1d65_eq\n\ntheorem WithDensity\u1d65Eq.congr_ae {f g : \u03b1 \u2192 E} (h : f =\u1d50[\u03bc] g) :\n    \u03bc.withDensity\u1d65 f = \u03bc.withDensity\u1d65 g :=\n  by\n  by_cases hf : integrable f \u03bc\n  \u00b7 ext (i hi)\n    rw [with_density\u1d65_apply hf hi, with_density\u1d65_apply (hf.congr h) hi]\n    exact integral_congr_ae (ae_restrict_of_ae h)\n  \u00b7 have hg : \u00acintegrable g \u03bc := by\n      intro hg\n      exact hf (hg.congr h.symm)\n    rw [with_density\u1d65, with_density\u1d65, dif_neg hf, dif_neg hg]\n#align measure_theory.with_density\u1d65_eq.congr_ae MeasureTheory.WithDensity\u1d65Eq.congr_ae\n\ntheorem Integrable.withDensity\u1d65_eq_iff {f g : \u03b1 \u2192 E} (hf : Integrable f \u03bc) (hg : Integrable g \u03bc) :\n    \u03bc.withDensity\u1d65 f = \u03bc.withDensity\u1d65 g \u2194 f =\u1d50[\u03bc] g :=\n  \u27e8fun hfg => hf.ae_eq_of_withDensity\u1d65_eq hg hfg, fun h => WithDensity\u1d65Eq.congr_ae h\u27e9\n#align measure_theory.integrable.with_density\u1d65_eq_iff MeasureTheory.Integrable.withDensity\u1d65_eq_iff\n\nsection SignedMeasure\n\ntheorem withDensity\u1d65_toReal {f : \u03b1 \u2192 \u211d\u22650\u221e} (hfm : AeMeasurable f \u03bc) (hf : (\u222b\u207b x, f x \u2202\u03bc) \u2260 \u221e) :\n    (\u03bc.withDensity\u1d65 fun x => (f x).toReal) =\n      @toSignedMeasure \u03b1 _ (\u03bc.withDensity f) (isFiniteMeasureWithDensity hf) :=\n  by\n  have hfi := integrable_to_real_of_lintegral_ne_top hfm hf\n  ext (i hi)\n  rw [with_density\u1d65_apply hfi hi, to_signed_measure_apply_measurable hi, with_density_apply _ hi,\n    integral_to_real hfm.restrict]\n  refine' ae_lt_top' hfm.restrict (ne_top_of_le_ne_top hf _)\n  conv_rhs => rw [\u2190 set_lintegral_univ]\n  exact lintegral_mono_set (Set.subset_univ _)\n#align measure_theory.with_density\u1d65_to_real MeasureTheory.withDensity\u1d65_toReal\n\ntheorem withDensity\u1d65_eq_withDensity_pos_part_sub_withDensity_neg_part {f : \u03b1 \u2192 \u211d}\n    (hfi : Integrable f \u03bc) :\n    \u03bc.withDensity\u1d65 f =\n      @toSignedMeasure \u03b1 _ (\u03bc.withDensity fun x => ENNReal.ofReal <| f x)\n          (isFiniteMeasureWithDensityOfReal hfi.2) -\n        @toSignedMeasure \u03b1 _ (\u03bc.withDensity fun x => ENNReal.ofReal <| -f x)\n          (isFiniteMeasureWithDensityOfReal hfi.neg.2) :=\n  by\n  ext (i hi)\n  rw [with_density\u1d65_apply hfi hi,\n    integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi.integrable_on,\n    vector_measure.sub_apply, to_signed_measure_apply_measurable hi,\n    to_signed_measure_apply_measurable hi, with_density_apply _ hi, with_density_apply _ hi]\n#align measure_theory.with_density\u1d65_eq_with_density_pos_part_sub_with_density_neg_part MeasureTheory.withDensity\u1d65_eq_withDensity_pos_part_sub_withDensity_neg_part\n\ntheorem Integrable.withDensity\u1d65_trim_eq_integral {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n    (hm : m \u2264 m0) {f : \u03b1 \u2192 \u211d} (hf : Integrable f \u03bc) {i : Set \u03b1} (hi : measurable_set[m] i) :\n    (\u03bc.withDensity\u1d65 f).trim hm i = \u222b x in i, f x \u2202\u03bc := by\n  rw [vector_measure.trim_measurable_set_eq hm hi, with_density\u1d65_apply hf (hm _ hi)]\n#align measure_theory.integrable.with_density\u1d65_trim_eq_integral MeasureTheory.Integrable.withDensity\u1d65_trim_eq_integral\n\ntheorem Integrable.withDensity\u1d65TrimAbsolutelyContinuous {m m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1}\n    (hm : m \u2264 m0) (hfi : Integrable f \u03bc) :\n    (\u03bc.withDensity\u1d65 f).trim hm \u226a\u1d65 (\u03bc.trim hm).toEnnrealVectorMeasure :=\n  by\n  refine' vector_measure.absolutely_continuous.mk fun j hj\u2081 hj\u2082 => _\n  rw [measure.to_ennreal_vector_measure_apply_measurable hj\u2081, trim_measurable_set_eq hm hj\u2081] at hj\u2082\n  rw [vector_measure.trim_measurable_set_eq hm hj\u2081, with_density\u1d65_apply hfi (hm _ hj\u2081)]\n  simp only [measure.restrict_eq_zero.mpr hj\u2082, integral_zero_measure]\n#align measure_theory.integrable.with_density\u1d65_trim_absolutely_continuous MeasureTheory.Integrable.withDensity\u1d65TrimAbsolutelyContinuous\n\nend SignedMeasure\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Measure/WithDensityVectorMeasure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.7331187869064062}}
{"text": "import algebra.group algebra.group_power\n\nvariables {G: Type*} (a b : G)\n\n@[symm] theorem gpow_add' {G : Type*} [group G] (a : G) (i : \u2124): a^(i + 1) = a * a^i :=\nby rw [add_comm, gpow_add]; simp\n\n@[symm] theorem gpow_add'' {G : Type*} [group G] (a : G) (i : \u2124): a^(i + 1) = a^i * a :=\nby rw [gpow_add]; simp\n\ndef Q04H {G : Type*} [group G] (a b : G) (i : \u2124): Prop := \n(a * b)^i = a^i * b^i\n\ntheorem Q04Alt [group G] \n(H : \u2200 a b : G, \n\u2203 i : \u2124, (Q04H a b i) \u2227 (Q04H a b (i + 1)) \u2227 (Q04H a b (i + 1 + 1)) ) :\n\u2200 a b : G, a * b = b * a := \u03bb a b : G, \nexists.elim (H a b)\n(\u03bb i Hi, \nhave H1 : b * a^i = a^i * b, from \n    have H10 : (a * b)^(i + 1) = a^(i + 1) * b^(i + 1), from Hi.2.1,\n    have H11 : (a*b) * (a*b)^i = (a * a^i) * (b * b^i), \n        by {rw [(gpow_add' (a*b) i).symm, (gpow_add' a i).symm, (gpow_add' b i).symm], exact H10}, \n    have H12 : a * ( b * (a*b)^i) = a * (a^i * (b * b^i)), \n        by {rw [mul_assoc, mul_assoc] at H11, exact H11}, \n    have H13 : b * (a*b)^i = a^i * (b * b^i), from mul_left_cancel H12, \n    have H14 : b * (a^i * b^i) = a^i * (b * b^i), from Hi.1 \u25b8 H13, \n    have H15 : b * a^i * b^i = a^i * b * b^i, from by {rw [mul_assoc, mul_assoc], exact H14}, \n(mul_right_inj (b^i)).mp H15, \n\nshow a * b = b * a, from \n    have H20 : a * b * (a * b)^(i+1) =  a * a^(i+1) * (b * b^(i+1)), \n        by {rw [(gpow_add' (a*b) (i+1)).symm, (gpow_add' a (i+1)).symm, (gpow_add' b (i+1)).symm], exact Hi.2.2}, \n    have H21 : a * b * (a^(i+1)*b^(i+1)) = a * a^(i+1) * (b * b^(i+1)), from Hi.2.1 \u25b8 H20, \n    have H22 : a * b * a^(i+1) * b^(i+1) = a * a^(i+1) * b * b^(i+1), \n        by {conv {to_lhs, rw [mul_assoc]}, conv {to_rhs, rw [mul_assoc]}, exact H21},  \n    have H23 : a * b * a^(i+1) = a * a^(i+1) * b, from mul_right_cancel H22, \n    have H24 : a * (b * a^(i+1)) = a * (a^(i+1) * b), by {rw [mul_assoc, mul_assoc] at H23; exact H23}, \n    have H25 : b * a^(i+1) = a^(i+1) * b, from mul_left_cancel H24, \n    have H26 : b * (a^i * a) = (a^i * a) * b, from (gpow_add'' a i) \u25b8 H25, \n    have H27 : b * a^i * a = a^i * a * b, by {rw [mul_assoc], exact H26}, \n    have H28 : a^i * b * a = a^i * a * b, from H1 \u25b8 H27, \n    have H29 : a^i * (b * a) = a^i * (a * b), by {rw [mul_assoc, mul_assoc] at H28, exact H28}, \n    have H30 : b * a = a * b, from mul_left_cancel H29, \nH30.symm )\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/- \ntheorem Q04AltAlt [group G] : \n(\u2200 a b : G, \n(\u2203 i : \u2124, (Q04H a b i) \u2227 (Q04H a b (i + 1)) \u2227 (Q04H a b (i + 2)))) \n\u2192 \u2200 a b : G, a * b = b * a := \nbegin\n    intro H0, \n    intros a b, \n    apply exists.elim (H0 a b), \n    intros i Hi, \n    unfold Q04H at Hi,\n    have H1 : a^i * b = b * a^i,   \n        apply (mul_right_inj (b^i)).1, \n        apply eq.symm, \n        rw mul_assoc,  \n        rw \u2190(Hi.1), \n        apply (mul_left_inj (a)).1, \n        rw [\u2190mul_assoc, \u2190mul_assoc, \u2190mul_assoc],\n        rw [\u2190gpow_add', \u2190gpow_add', mul_assoc, \u2190gpow_add'], \n    from Hi.2.1, \n    \n    let H3  : _ ^ ( i + ( 1 + 1)) = _ := Hi.2.2, \n    rw \u2190add_assoc at H3, \n    rw gpow_add' at H3, \n    rw (show i + 2 = (i + 1) + 1, by rw [add_assoc];refl) at H3,\n    conv at H3 begin\n      to_rhs,\n      rw gpow_add',\n    end,\n    rw gpow_add' at H3,\n    rw [mul_assoc, mul_assoc a (a^(i + 1))] at H3, \n    rw mul_left_inj at H3, \n    rw Hi.1 at H3, \n    rw (gpow_add' b ) at H3, \n    rw (gpow_add' b ) at H3,\n    repeat {rw [\u2190mul_assoc] at H3}, \n    rw mul_right_inj at H3, \n    rw (gpow_add' a) at H3, \n    rw mul_assoc (a) at H3, \n    rw (H1) at H3, \n    rw [mul_assoc a] at H3,\n    rw mul_assoc b (a^i) b at H3, \n    rw H1 at H3, \n    repeat {rw [\u2190mul_assoc] at H3}, \n    rw mul_right_inj at H3, \n    rw mul_right_inj at H3,\n    rw H3, \nend -/", "meta": {"author": "group-study-group", "repo": "herstein", "sha": "f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66", "save_path": "github-repos/lean/group-study-group-herstein", "path": "github-repos/lean/group-study-group-herstein/herstein-f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66/src/herstein/ex2_3/Q_04_Alt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7331187824102715}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.nat.factorial.cast\n! leanprover-community/mathlib commit d50b12ae8e2bd910d08a94823976adae9825718b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.RingTheory.Polynomial.Pochhammer\n\n/-!\n# Cast of factorials\n\nThis file allows calculating factorials (including ascending and descending ones) as elements of a\nsemiring.\n\nThis is particularly crucial for `Nat.descFactorial` as subtraction on `\u2115` does **not** correspond\nto subtraction on a general semiring. For example, we can't rely on existing cast lemmas to prove\n`\u2191(a.descFactorial 2) = \u2191a * (\u2191a - 1)`. We must use the fact that, whenever `\u2191(a - 1)` is not equal\nto `\u2191a - 1`, the other factor is `0` anyway.\n-/\n\n\nopen Nat\n\nvariable (S : Type _)\n\nnamespace Nat\n\nsection Semiring\n\nvariable [Semiring S] (a b : \u2115)\n\n-- Porting note: added type ascription around a + 1\ntheorem cast_ascFactorial : (a.ascFactorial b : S) = (pochhammer S b).eval (a + 1 : S) := by\n  rw [\u2190 pochhammer_nat_eq_ascFactorial, pochhammer_eval_cast, Nat.cast_add, Nat.cast_one]\n#align nat.cast_asc_factorial Nat.cast_ascFactorial\n\n-- Porting note: added type ascription around a - (b - 1)\ntheorem cast_descFactorial : (a.descFactorial b : S) = (pochhammer S b).eval (a - (b - 1) : S) := by\n  rw [\u2190 pochhammer_eval_cast, pochhammer_nat_eq_descFactorial]\n  induction' b with b\n  \u00b7 simp\n  \u00b7 simp_rw [add_succ, succ_sub_one]\n    obtain h | h := le_total a b\n    \u00b7 rw [descFactorial_of_lt (lt_succ_of_le h), descFactorial_of_lt (lt_succ_of_le _)]\n      rw [tsub_eq_zero_iff_le.mpr h, zero_add]\n    \u00b7 rw [tsub_add_cancel_of_le h]\n#align nat.cast_desc_factorial Nat.cast_descFactorial\n\ntheorem cast_factorial : (a ! : S) = (pochhammer S a).eval 1 := by\n  rw [\u2190 zero_ascFactorial, cast_ascFactorial, cast_zero, zero_add]\n#align nat.cast_factorial Nat.cast_factorial\n\nend Semiring\n\nsection Ring\n\nvariable [Ring S] (a b : \u2115)\n\n/-- Convenience lemma. The `a - 1` is not using truncated subtraction, as opposed to the definition\nof `Nat.descFactorial` as a natural. -/\ntheorem cast_descFactorial_two : (a.descFactorial 2 : S) = a * (a - 1) := by\n  rw [cast_descFactorial]\n  cases a\n  \u00b7 simp\n  \u00b7 rw [succ_sub_succ, tsub_zero, cast_succ, add_sub_cancel, pochhammer_succ_right, pochhammer_one,\n      Polynomial.X_mul, Polynomial.eval_mul_X, Polynomial.eval_add, Polynomial.eval_X, cast_one,\n      Polynomial.eval_one]\n#align nat.cast_desc_factorial_two Nat.cast_descFactorial_two\n\nend Ring\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Factorial/Cast.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7331174136881833}}
{"text": "/-\nQuick&dirty port of some parts of `data.equiv.basic` from Lean 3.\n\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\n-/\n\n\n\nimport mathlib4_experiments.Data.Notation\n\n\n\nset_option autoBoundImplicitLocal false\n\nuniverses u\u2081 u\u2082 u\u2083 u\u2084 v\n\n\n\nstructure Equiv (\u03b1 : Sort u\u2081) (\u03b2 : Sort u\u2082) where\n(toFun    : \u03b1 \u2192 \u03b2)\n(invFun   : \u03b2 \u2192 \u03b1)\n(leftInv  : \u2200 x, invFun (toFun x) = x)\n(rightInv : \u2200 y, toFun (invFun y) = y)\n\nnamespace Equiv\n\ninstance : HasEquivalence (Sort u\u2081) (Sort u\u2082) := \u27e8Equiv\u27e9\ninstance (\u03b1 : Sort u\u2081) (\u03b2 : Sort u\u2082) : CoeFun (\u03b1 \u2243 \u03b2) (\u03bb _ => \u03b1 \u2192 \u03b2) := \u27e8Equiv.toFun\u27e9\n\ndef refl (\u03b1 : Sort u\u2081) : \u03b1 \u2243 \u03b1 := \u27e8id, id, \u03bb x => rfl, \u03bb y => rfl\u27e9\n\ndef symm {\u03b1 : Sort u\u2081} {\u03b2 : Sort u\u2082} (e : \u03b1 \u2243 \u03b2) : \u03b2 \u2243 \u03b1 := \u27e8e.invFun, e.toFun, e.rightInv, e.leftInv\u27e9\n\ntheorem trans_leftInv {\u03b1 : Sort u\u2081} {\u03b2 : Sort u\u2082} {\u03b3 : Sort u\u2083} (e\u2081 : \u03b1 \u2243 \u03b2) (e\u2082 : \u03b2 \u2243 \u03b3) (x : \u03b1) :\n  e\u2081.invFun (e\u2082.invFun (e\u2082.toFun (e\u2081.toFun x))) = x :=\nEq.trans (congrArg e\u2081.invFun (e\u2082.leftInv (e\u2081.toFun x))) (e\u2081.leftInv x)\n\ndef trans {\u03b1 : Sort u\u2081} {\u03b2 : Sort u\u2082} {\u03b3 : Sort u\u2083} (e\u2081 : \u03b1 \u2243 \u03b2) (e\u2082 : \u03b2 \u2243 \u03b3) : \u03b1 \u2243 \u03b3 :=\n\u27e8e\u2082.toFun \u2218 e\u2081.toFun, e\u2081.invFun \u2218 e\u2082.invFun, trans_leftInv e\u2081 e\u2082, trans_leftInv (symm e\u2082) (symm e\u2081)\u27e9\n\nvariable {\u03b1 : Sort u\u2081} {\u03b2 : Sort u\u2082} {\u03b3 : Sort u\u2083} {\u03b4 : Sort u\u2084}\n\n@[simp] theorem symm_symm (e : \u03b1 \u2243 \u03b2) : symm (symm e) = e := match e with\n| \u27e8toFun, invFun, leftInv, rightInv\u27e9 => rfl\n\n@[simp] theorem trans_refl (e : \u03b1 \u2243 \u03b2) : trans e (refl \u03b2) = e := match e with\n| \u27e8toFun, invFun, leftInv, rightInv\u27e9 => rfl\n\n@[simp] theorem refl_symm : symm (refl \u03b1) = refl \u03b1 := rfl\n\n@[simp] theorem refl_trans (e : \u03b1 \u2243 \u03b2) : trans (refl \u03b1) e = e := match e with\n| \u27e8toFun, invFun, leftInv, rightInv\u27e9 => rfl\n\n@[simp] theorem symm_trans (e : \u03b1 \u2243 \u03b2) : trans (symm e) e = refl \u03b2 :=\nlet h\u2081 : e.toFun \u2218 e.invFun = id := funext e.rightInv;\n-- Need to figure out how to recover injectivity of constructors in Lean 4.\nsorry\n\n@[simp] theorem trans_symm (e : \u03b1 \u2243 \u03b2) : trans e (symm e) = refl \u03b1 := symm_trans (symm e)\n\n@[simp] theorem symm_trans_symm (ab : \u03b1 \u2243 \u03b2) (bc : \u03b2 \u2243 \u03b3) :\n  symm (trans ab bc) = trans (symm bc) (symm ab) := rfl\n\ntheorem trans_assoc (ab : \u03b1 \u2243 \u03b2) (bc : \u03b2 \u2243 \u03b3) (cd : \u03b3 \u2243 \u03b4) :\n  trans (trans ab bc) cd = trans ab (trans bc cd) := rfl\n\nend Equiv\n", "meta": {"author": "kbuzzard", "repo": "mathlib4_experiments", "sha": "87cb879b4d602c8ecfd9283b7c0b06015abdbab1", "save_path": "github-repos/lean/kbuzzard-mathlib4_experiments", "path": "github-repos/lean/kbuzzard-mathlib4_experiments/mathlib4_experiments-87cb879b4d602c8ecfd9283b7c0b06015abdbab1/mathlib4_experiments/Data/Equiv/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7331174083342618}}
{"text": "/-\nWR Scott's Group Theory in Lean\n\nPermutation Groups\n-/\nimport .definitions\n\nnamespace permutations\nvariables {A M U : Type}\n\n definition injective (f : A \u2192 A) : Prop :=\n    \u2200 x y, f x = f y \u2192 x = y\n\n-- a permutation of a set M is a 1-1 function into M onto M\n-- Sym(M) is a set of permutation of M, (f : M \u2192 M) \u2208 Sym(M)\n-- Sym is a group, fg is the binary operation (function product)\nclass Sym (A : Type) :=\n  (perms : set (A \u2192 A))\n  (mult : (A \u2192 A) \u2192 (A \u2192 A) \u2192 (A \u2192 A))\n  (symm : \u2200 (f : (A \u2192 A)), (f \u2208 perms) \u2192 injective f)\ninfix \u2218 := Sym.mult\n\n-- to prove subgroup, start with a set S\n-- show that multiplication membership holds\n-- show that one membership holds\n-- show that inverse membership holds\nclass subgroup [definitions.Group (U \u2192 U)] (S : set (U \u2192 U)) : Prop :=\n  (mul_mem : \u2200 {a b}, a \u2208 S \u2192 b \u2208 S \u2192 a * b \u2208 S)\n  (one_mem : definitions.Group.one \u2208 S)\n  (inv_mem: \u2200 {a}, a \u2208 S \u2192 (definitions.Group.inv a) \u2208 S)\n\n-- Exercise 1.3.1 if M is a set and Sym M is a set of permutations of M,\n-- the Sym M is a group \ntheorem is_group [definitions.Group (A \u2192 A)] [S : Sym A] : subgroup (S.perms) := \nbegin\n  refine {..},\n  intros p p q r,\n  -- proof that f * g \u2208 S\n  -- f \u2218 g is a function by theorem\n  -- prove that f * g is onto S\n  -- prove that f * g is one - to - one\n  -- then f \u2218 g is a permutation of M  \n  repeat {sorry},\nend\nend permutations", "meta": {"author": "EthanJamesLew", "repo": "group-theory-lean", "sha": "7cc60f4fa895bbfcd370de06d1da97f9d86ece3b", "save_path": "github-repos/lean/EthanJamesLew-group-theory-lean", "path": "github-repos/lean/EthanJamesLew-group-theory-lean/group-theory-lean-7cc60f4fa895bbfcd370de06d1da97f9d86ece3b/src/permutations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7331087922926167}}
{"text": "/- 10 Feb 2020 -/\n-- srgs\n-- box product\n-- hamming graph\n-- triangular graph\n-- paley graph\nimport combinatorics.simple_graph.basic\n\nuniverses u v\nvariables (V : Type u) {W : Type u}\n\nnamespace simple_graph\n\nvariables {V}\n\n\n/-\nThe box product of `G : simple_graph V` and `H : simple_graph W` is a graph on `V \u00d7 W` such that\n`(x.1, w1)` is adjacent to `(y.1, y.2)` when `x.1 = y.1` and `H.adj w1 y.2` or `G.adj x.1 y.1` and `w1 = y.2`.\nIn other words, the vertices differ by one coordinate. \n-/\ndef box_product (G : simple_graph V) (H : simple_graph W) : simple_graph (V \u00d7 W) := \n{ adj := \u03bb x y, (x.1 = y.1 \u2227 H.adj x.2 y.2) \u2228 (G.adj x.1 y.1 \u2227 x.2 = y.2),\n  sym := \u03bb x y h,\n    begin\n      cases h with hv hw,\n      { left,\n        exact \u27e8eq.symm hv.1, (H.edge_symm x.2 y.2).1 hv.2\u27e9 },\n      { right,\n        exact \u27e8(G.edge_symm x.1 y.1).1 hw.1, eq.symm hw.2\u27e9 },\n    end,\n  loopless := \u03bb \u27e8v, w\u27e9 h, \n    begin\n      cases h with hw hv,\n      { exact H.irrefl hw.2 },\n      { exact G.irrefl hv.1 },\n    end }\n\nnotation G ` \u25a1 ` := box_product G\n\nvariables (G : simple_graph V) [decidable_rel G.adj]\n\n\nvariables [decidable_eq V] [decidable_eq W]\n\ninstance decidable_rel_box_product (H : simple_graph W) [decidable_rel H.adj] : decidable_rel (G \u25a1 H).adj :=\n\u03bb _ _, or.decidable\n\nvariables [fintype V] [decidable_eq V]\n\n/--\nA graph is strongly regular with parameters `n k l m` if\n * its vertex set has cardinality `n`\n * it is regular with degree `k`\n * every pair of adjacent vertices has `l` common neighbors\n * every pair of nonadjacent vertices has `m` common neighbors\n-/\nstructure is_SRG_of (n k l m : \u2115) : Prop :=\n(card : fintype.card V = n)\n(regular : G.is_regular_of_degree k)\n(adj_common : \u2200 (v w : V), G.adj v w \u2192 fintype.card (G.common_neighbors v w) = l)\n(nadj_common : \u2200 (v w : V), \u00ac G.adj v w \u2192 fintype.card (G.common_neighbors v w) = m)\n\nlemma hamming_srg : ((complete_graph V) \u25a1 (complete_graph V)).is_SRG_of ((fintype.card V)^2) (2*(fintype.card V - 1)) (fintype.card V - 2) 2 := \nbegin\n  sorry,\nend\n\n\ndef incident (e f : sym2 V) : Prop := \u2203 (v : V), v \u2208 e \u2227 v \u2208 f\n\n/-def line_graph (G : simple_graph V) : simple_graph G.edge_set := \n{ adj := \u03bb e f, incident e f,\n  sym := _,\n  loopless := _ }-/\n\nend simple_graph", "meta": {"author": "agusakov", "repo": "math-688-lean", "sha": "67dc27ebff55a74c6b5a1c469ba04e7981d2e550", "save_path": "github-repos/lean/agusakov-math-688-lean", "path": "github-repos/lean/agusakov-math-688-lean/math-688-lean-67dc27ebff55a74c6b5a1c469ba04e7981d2e550/src/math-888/lec-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7330503789484907}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport data.real.basic\nimport analysis.calculus.parametric_integral\n\n/-\n\n# Basic calculus\n\n-/\n\n-- Thanks to Moritz Doll on the Zulip for writing this one!\n/-- If `f : \u211d \u2192 \u211d` is differentiable at `x`, then the obvious induced function `\u211d \u2192 \u2102` is\nalso differentiable at `x`. -/\nlemma complex.differentiable_at_coe {f : \u211d \u2192 \u211d} {x : \u211d } (hf : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bb y, (f y : \u2102)) x :=\nbegin\n  apply complex.of_real_clm.differentiable_at.comp _ hf,\nend\n\n-- Here's a harder example\nexample (a : \u2102) (x : \u211d) : differentiable_at \u211d (\u03bb (y : \u211d), complex.exp (-(a * \u2191y ^ 2))) x :=\nbegin\n  sorry,\nend\n\nnoncomputable def \u03c6\u2081 : \u211d \u2192 \u211d \u00d7 \u211d := \n\u03bb x, (real.cos x, real.sin x)\n\nexample : cont_diff_on \u211d \u22a4 (\u03bb x, (real.cos x, real.sin x)) (set.Icc 0 1) :=\nbegin\n  sorry,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section17curves_and_surfaces/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7330503665194857}}
{"text": "import tactic\n\nlemma part_a : \u00ac (\u2200 n k : \u2115, n > 0 \u2192 k > 0 \u2192 k \u2223 n ^ k - n) :=\nbegin\n  -- True for k prime\n  intro h,\n  specialize h 2 4,\n  norm_num at h,\nend\n\n/-\n  https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/arithmetic.20timeout.20with.20a.5E2.2Bb.5E2.2Bc.5E2.3D7\n  Thanks to Patrick Johnson\n  Also a way via zmod by Alex J. Best\n-/\n\nlemma part_b : \u00ac (\u2200 n : \u2115, n > 0 \u2192 \u2203 a b c : \u2115, n = a^2 + b^2 + c^2) :=\nbegin\n  -- True for n <= 6\n  intro h,\n  specialize h 7,\n  have lt_three : \u2200 {a b c : \u2115}, 7 = a ^ 2 + b ^ 2 + c ^ 2 \u2192 a < 3,\n  { intros a b c h, nlinarith, },\n  simp at h,\n  rcases h with \u27e8a, b, c, h\u27e9,\n  have ha := lt_three h,\n  have hb := lt_three (by linarith : 7 = b^2 + a^2 + c^2),\n  have hc := lt_three (by linarith : 7 = c^2 + a^2 + b^2),\n  interval_cases a; interval_cases b; interval_cases c; -- Generate 3 x 3 x 3 = 27 goals\n  cases h,\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "m1fexplained_lean3", "sha": "570c9a3ff8cfc3805047f2796864516a49f51510", "save_path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3", "path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3/m1fexplained_lean3-570c9a3ff8cfc3805047f2796864516a49f51510/src/chapter01/exercises/exercise07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7329929648612838}}
{"text": "/-\nCopyright (c) 2018 . All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Thomas Browning\n-/\n\nimport data.zmod.basic\nimport group_theory.index\nimport group_theory.group_action.conj_act\nimport group_theory.perm.cycle_type\nimport group_theory.quotient_group\n\n/-!\n# p-groups\n\nThis file contains a proof that if `G` is a `p`-group acting on a finite set `\u03b1`,\nthen the number of fixed points of the action is congruent mod `p` to the cardinality of `\u03b1`.\nIt also contains proofs of some corollaries of this lemma about existence of fixed points.\n-/\n\nopen_locale big_operators\n\nopen fintype mul_action\n\nvariables (p : \u2115) (G : Type*) [group G]\n\n/-- A p-group is a group in which every element has prime power order -/\ndef is_p_group : Prop := \u2200 g : G, \u2203 k : \u2115, g ^ (p ^ k) = 1\n\nvariables {p} {G}\n\nnamespace is_p_group\n\nlemma iff_order_of [hp : fact p.prime] :\n  is_p_group p G \u2194 \u2200 g : G, \u2203 k : \u2115, order_of g = p ^ k :=\nforall_congr (\u03bb g, \u27e8\u03bb \u27e8k, hk\u27e9, exists_imp_exists (by exact \u03bb j, Exists.snd)\n  ((nat.dvd_prime_pow hp.out).mp (order_of_dvd_of_pow_eq_one hk)),\n  exists_imp_exists (\u03bb k hk, by rw [\u2190hk, pow_order_of_eq_one])\u27e9)\n\nlemma of_card [fintype G] {n : \u2115} (hG : card G = p ^ n) : is_p_group p G :=\n\u03bb g, \u27e8n, by rw [\u2190hG, pow_card_eq_one]\u27e9\n\nlemma of_bot : is_p_group p (\u22a5 : subgroup G) :=\nof_card (subgroup.card_bot.trans (pow_zero p).symm)\n\nlemma iff_card [fact p.prime] [fintype G] :\n  is_p_group p G \u2194 \u2203 n : \u2115, card G = p ^ n :=\nbegin\n  have hG : card G \u2260 0 := card_ne_zero,\n  refine \u27e8\u03bb h, _, \u03bb \u27e8n, hn\u27e9, of_card hn\u27e9,\n  suffices : \u2200 q \u2208 nat.factors (card G), q = p,\n  { use (card G).factors.length,\n    rw [\u2190list.prod_repeat, \u2190list.eq_repeat_of_mem this, nat.prod_factors hG] },\n  intros q hq,\n  obtain \u27e8hq1, hq2\u27e9 := (nat.mem_factors hG).mp hq,\n  haveI : fact q.prime := \u27e8hq1\u27e9,\n  obtain \u27e8g, hg\u27e9 := equiv.perm.exists_prime_order_of_dvd_card q hq2,\n  obtain \u27e8k, hk\u27e9 := (iff_order_of.mp h) g,\n  exact (hq1.pow_eq_iff.mp (hg.symm.trans hk).symm).1.symm,\nend\n\nsection G_is_p_group\n\nvariables (hG : is_p_group p G)\n\ninclude hG\n\nlemma of_injective {H : Type*} [group H] (\u03d5 : H \u2192* G) (h\u03d5 : function.injective \u03d5) :\n  is_p_group p H :=\nbegin\n  simp_rw [is_p_group, \u2190h\u03d5.eq_iff, \u03d5.map_pow, \u03d5.map_one],\n  exact \u03bb h, hG (\u03d5 h),\nend\n\nlemma to_subgroup (H : subgroup G) : is_p_group p H :=\nhG.of_injective H.subtype subtype.coe_injective\n\nlemma of_surjective {H : Type*} [group H] (\u03d5 : G \u2192* H) (h\u03d5 : function.surjective \u03d5) :\n  is_p_group p H :=\nbegin\n  refine \u03bb h, exists.elim (h\u03d5 h) (\u03bb g hg, exists_imp_exists (\u03bb k hk, _) (hG g)),\n  rw [\u2190hg, \u2190\u03d5.map_pow, hk, \u03d5.map_one],\nend\n\nlemma to_quotient (H : subgroup G) [H.normal] :\n  is_p_group p (G \u29f8 H) :=\nhG.of_surjective (quotient_group.mk' H) quotient.surjective_quotient_mk'\n\nlemma of_equiv {H : Type*} [group H] (\u03d5 : G \u2243* H) : is_p_group p H :=\nhG.of_surjective \u03d5.to_monoid_hom \u03d5.surjective\n\nvariables [hp : fact p.prime]\n\ninclude hp\n\nlemma index (H : subgroup G) [fintype (G \u29f8 H)] :\n  \u2203 n : \u2115, H.index = p ^ n :=\nbegin\n  obtain \u27e8n, hn\u27e9 := iff_card.mp (hG.to_quotient H.normal_core),\n  obtain \u27e8k, hk1, hk2\u27e9 := (nat.dvd_prime_pow hp.out).mp ((congr_arg _\n    (H.normal_core.index_eq_card.trans hn)).mp (subgroup.index_dvd_of_le H.normal_core_le)),\n  exact \u27e8k, hk2\u27e9,\nend\n\nvariables {\u03b1 : Type*} [mul_action G \u03b1]\n\nlemma card_orbit (a : \u03b1) [fintype (orbit G a)] :\n  \u2203 n : \u2115, card (orbit G a) = p ^ n :=\nbegin\n  let \u03d5 := orbit_equiv_quotient_stabilizer G a,\n  haveI := fintype.of_equiv (orbit G a) \u03d5,\n  rw [card_congr \u03d5, \u2190subgroup.index_eq_card],\n  exact hG.index (stabilizer G a),\nend\n\nvariables (\u03b1) [fintype \u03b1] [fintype (fixed_points G \u03b1)]\n\n/-- If `G` is a `p`-group acting on a finite set `\u03b1`, then the number of fixed points\n  of the action is congruent mod `p` to the cardinality of `\u03b1` -/\nlemma card_modeq_card_fixed_points : card \u03b1 \u2261 card (fixed_points G \u03b1) [MOD p] :=\nbegin\n  classical,\n  calc card \u03b1 = card (\u03a3 y : quotient (orbit_rel G \u03b1), {x // quotient.mk' x = y}) :\n    card_congr (equiv.sigma_preimage_equiv (@quotient.mk' _ (orbit_rel G \u03b1))).symm\n  ... = \u2211 a : quotient (orbit_rel G \u03b1), card {x // quotient.mk' x = a} : card_sigma _\n  ... \u2261 \u2211 a : fixed_points G \u03b1, 1 [MOD p] : _\n  ... = _ : by simp; refl,\n  rw [\u2190zmod.eq_iff_modeq_nat p, nat.cast_sum, nat.cast_sum],\n  have key : \u2200 x, card {y // (quotient.mk' y : quotient (orbit_rel G \u03b1)) = quotient.mk' x} =\n    card (orbit G x) := \u03bb x, by simp only [quotient.eq']; congr,\n  refine eq.symm (finset.sum_bij_ne_zero (\u03bb a _ _, quotient.mk' a.1) (\u03bb _ _ _, finset.mem_univ _)\n    (\u03bb a\u2081 a\u2082 _ _ _ _ h, subtype.eq ((mem_fixed_points' \u03b1).mp a\u2082.2 a\u2081.1 (quotient.exact' h)))\n      (\u03bb b, quotient.induction_on' b (\u03bb b _ hb, _)) (\u03bb a ha _, by\n      { rw [key, mem_fixed_points_iff_card_orbit_eq_one.mp a.2] })),\n  obtain \u27e8k, hk\u27e9 := hG.card_orbit b,\n  have : k = 0 := nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge (mt (pow_dvd_pow p)\n    (by rwa [pow_one, \u2190hk, \u2190nat.modeq_zero_iff_dvd, \u2190zmod.eq_iff_modeq_nat, \u2190key])))),\n  exact \u27e8\u27e8b, mem_fixed_points_iff_card_orbit_eq_one.2 $ by rw [hk, this, pow_zero]\u27e9,\n    finset.mem_univ _, (ne_of_eq_of_ne nat.cast_one one_ne_zero), rfl\u27e9,\nend\n\n/-- If a p-group acts on `\u03b1` and the cardinality of `\u03b1` is not a multiple\n  of `p` then the action has a fixed point. -/\nlemma nonempty_fixed_point_of_prime_not_dvd_card (hp\u03b1 : \u00ac p \u2223 card \u03b1) :\n  (fixed_points G \u03b1).nonempty :=\n@set.nonempty_of_nonempty_subtype _ _ begin\nrw [\u2190card_pos_iff, pos_iff_ne_zero],\n  contrapose! hp\u03b1,\n  rw [\u2190nat.modeq_zero_iff_dvd, \u2190hp\u03b1],\n  exact hG.card_modeq_card_fixed_points \u03b1,\nend\n\n/-- If a p-group acts on `\u03b1` and the cardinality of `\u03b1` is a multiple\n  of `p`, and the action has one fixed point, then it has another fixed point. -/\nlemma exists_fixed_point_of_prime_dvd_card_of_fixed_point\n  (hp\u03b1 : p \u2223 card \u03b1) {a : \u03b1} (ha : a \u2208 fixed_points G \u03b1) :\n  \u2203 b, b \u2208 fixed_points G \u03b1 \u2227 a \u2260 b :=\nhave hpf : p \u2223 card (fixed_points G \u03b1) :=\n  nat.modeq_zero_iff_dvd.mp ((hG.card_modeq_card_fixed_points \u03b1).symm.trans hp\u03b1.modeq_zero_nat),\nhave h\u03b1 : 1 < card (fixed_points G \u03b1) :=\n  (fact.out p.prime).one_lt.trans_le (nat.le_of_dvd (card_pos_iff.2 \u27e8\u27e8a, ha\u27e9\u27e9) hpf),\nlet \u27e8\u27e8b, hb\u27e9, hba\u27e9 := exists_ne_of_one_lt_card h\u03b1 \u27e8a, ha\u27e9 in\n\u27e8b, hb, \u03bb hab, hba (by simp_rw [hab])\u27e9\n\nlemma center_nontrivial [nontrivial G] [fintype G] : nontrivial (subgroup.center G) :=\nbegin\n  classical,\n  have := (hG.of_equiv conj_act.to_conj_act).exists_fixed_point_of_prime_dvd_card_of_fixed_point G,\n  rw conj_act.fixed_points_eq_center at this,\n  obtain \u27e8g, hg\u27e9 := this _ (subgroup.center G).one_mem,\n  { exact \u27e8\u27e81, \u27e8g, hg.1\u27e9, mt subtype.ext_iff.mp hg.2\u27e9\u27e9 },\n  { obtain \u27e8n, hn\u27e9 := is_p_group.iff_card.mp hG,\n    rw hn,\n    apply dvd_pow_self,\n    rintro rfl,\n    exact (fintype.one_lt_card).ne' hn },\nend\n\nlemma bot_lt_center [nontrivial G] [fintype G] : \u22a5 < subgroup.center G :=\nbegin\n  haveI := center_nontrivial hG,\n  classical,\n  exact bot_lt_iff_ne_bot.mpr ((subgroup.center G).one_lt_card_iff_ne_bot.mp fintype.one_lt_card),\nend\n\nend G_is_p_group\n\nlemma to_le {H K : subgroup G} (hK : is_p_group p K) (hHK : H \u2264 K) : is_p_group p H :=\nhK.of_injective (subgroup.inclusion hHK) (\u03bb a b h, subtype.ext (show _, from subtype.ext_iff.mp h))\n\nlemma to_inf_left {H K : subgroup G} (hH : is_p_group p H) : is_p_group p (H \u2293 K : subgroup G) :=\nhH.to_le inf_le_left\n\nlemma to_inf_right {H K : subgroup G} (hK : is_p_group p K) : is_p_group p (H \u2293 K : subgroup G) :=\nhK.to_le inf_le_right\n\nlemma map {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]\n  (\u03d5 : G \u2192* K) : is_p_group p (H.map \u03d5) :=\nbegin\n  rw [\u2190H.subtype_range, monoid_hom.map_range],\n  exact hH.of_surjective (\u03d5.restrict H).range_restrict (\u03d5.restrict H).range_restrict_surjective,\nend\n\nlemma comap_of_ker_is_p_group {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]\n  (\u03d5 : K \u2192* G) (h\u03d5 : is_p_group p \u03d5.ker) : is_p_group p (H.comap \u03d5) :=\nbegin\n  intro g,\n  obtain \u27e8j, hj\u27e9 := hH \u27e8\u03d5 g.1, g.2\u27e9,\n  rw [subtype.ext_iff, H.coe_pow, subtype.coe_mk, \u2190\u03d5.map_pow] at hj,\n  obtain \u27e8k, hk\u27e9 := h\u03d5 \u27e8g.1 ^ p ^ j, hj\u27e9,\n  rwa [subtype.ext_iff, \u03d5.ker.coe_pow, subtype.coe_mk, \u2190pow_mul, \u2190pow_add] at hk,\n  exact \u27e8j + k, by rwa [subtype.ext_iff, (H.comap \u03d5).coe_pow]\u27e9,\nend\n\nlemma ker_is_p_group_of_injective {K : Type*} [group K] {\u03d5 : K \u2192* G} (h\u03d5 : function.injective \u03d5) :\n  is_p_group p \u03d5.ker :=\n(congr_arg (\u03bb Q : subgroup K, is_p_group p Q) (\u03d5.ker_eq_bot_iff.mpr h\u03d5)).mpr is_p_group.of_bot\n\nlemma comap_of_injective {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]\n  (\u03d5 : K \u2192* G) (h\u03d5 : function.injective \u03d5) : is_p_group p (H.comap \u03d5) :=\nhH.comap_of_ker_is_p_group \u03d5 (ker_is_p_group_of_injective h\u03d5)\n\nlemma comap_subtype {H : subgroup G} (hH : is_p_group p H) {K : subgroup G} :\n  is_p_group p (H.comap K.subtype) :=\nhH.comap_of_injective K.subtype subtype.coe_injective\n\nlemma to_sup_of_normal_right {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  [K.normal] : is_p_group p (H \u2294 K : subgroup G) :=\nbegin\n  rw [\u2190quotient_group.ker_mk K, \u2190subgroup.comap_map_eq],\n  apply (hH.map (quotient_group.mk' K)).comap_of_ker_is_p_group,\n  rwa quotient_group.ker_mk,\nend\n\nlemma to_sup_of_normal_left {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  [H.normal] : is_p_group p (H \u2294 K : subgroup G) :=\n(congr_arg (\u03bb H : subgroup G, is_p_group p H) sup_comm).mp (to_sup_of_normal_right hK hH)\n\nlemma to_sup_of_normal_right' {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  (hHK : H \u2264 K.normalizer) : is_p_group p (H \u2294 K : subgroup G) :=\nlet hHK' := to_sup_of_normal_right (hH.of_equiv (subgroup.comap_subtype_equiv_of_le hHK).symm)\n  (hK.of_equiv (subgroup.comap_subtype_equiv_of_le subgroup.le_normalizer).symm) in\n((congr_arg (\u03bb H : subgroup K.normalizer, is_p_group p H)\n  (subgroup.sup_subgroup_of_eq hHK subgroup.le_normalizer)).mp hHK').of_equiv\n  (subgroup.comap_subtype_equiv_of_le (sup_le hHK subgroup.le_normalizer))\n\nlemma to_sup_of_normal_left' {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  (hHK : K \u2264 H.normalizer) : is_p_group p (H \u2294 K : subgroup G) :=\n(congr_arg (\u03bb H : subgroup G, is_p_group p H) sup_comm).mp (to_sup_of_normal_right' hK hH hHK)\n\n/-- finite p-groups with different p have coprime orders -/\nlemma coprime_card_of_ne {G\u2082 : Type*} [group G\u2082]\n  (p\u2081 p\u2082 : \u2115) [hp\u2081 : fact p\u2081.prime] [hp\u2082 : fact p\u2082.prime] (hne : p\u2081 \u2260 p\u2082)\n  (H\u2081 : subgroup G) (H\u2082 : subgroup G\u2082) [fintype H\u2081] [fintype H\u2082]\n  (hH\u2081 : is_p_group p\u2081 H\u2081) (hH\u2082 : is_p_group p\u2082 H\u2082) :\n  nat.coprime (fintype.card H\u2081) (fintype.card H\u2082) :=\nbegin\n  obtain \u27e8n\u2081, heq\u2081\u27e9 := iff_card.mp hH\u2081, rw heq\u2081, clear heq\u2081,\n  obtain \u27e8n\u2082, heq\u2082\u27e9 := iff_card.mp hH\u2082, rw heq\u2082, clear heq\u2082,\n  exact nat.coprime_pow_primes _ _ (hp\u2081.elim) (hp\u2082.elim) hne,\nend\n\n/-- p-groups with different p are disjoint -/\nlemma disjoint_of_ne (p\u2081 p\u2082 : \u2115) [hp\u2081 : fact p\u2081.prime] [hp\u2082 : fact p\u2082.prime] (hne : p\u2081 \u2260 p\u2082)\n  (H\u2081 H\u2082 : subgroup G) (hH\u2081 : is_p_group p\u2081 H\u2081) (hH\u2082 : is_p_group p\u2082 H\u2082) :\n  disjoint H\u2081 H\u2082 :=\nbegin\n  rintro x \u27e8hx\u2081, hx\u2082\u27e9,\n  rw subgroup.mem_bot,\n  obtain \u27e8n\u2081, hn\u2081\u27e9 := iff_order_of.mp hH\u2081 \u27e8x, hx\u2081\u27e9,\n  obtain \u27e8n\u2082, hn\u2082\u27e9 := iff_order_of.mp hH\u2082 \u27e8x, hx\u2082\u27e9,\n  rw [\u2190 order_of_subgroup, subgroup.coe_mk] at hn\u2081 hn\u2082,\n  have : p\u2081 ^ n\u2081 = p\u2082 ^ n\u2082, by rw [\u2190 hn\u2081, \u2190 hn\u2082],\n  have : n\u2081 = 0,\n  { contrapose! hne with h,\n    rw \u2190 associated_iff_eq at this \u22a2,\n    exact associated.of_pow_associated_of_prime\n      (nat.prime_iff.mp hp\u2081.elim) (nat.prime_iff.mp hp\u2082.elim) (ne.bot_lt h) this },\n  simpa [this] using hn\u2081,\nend\n\nend is_p_group\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/group_theory/p_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7329929588069442}}
{"text": "/-\nThe complex numbers.\nA documented remix of part of mathlib\n\nOur goal is to define the complex numbers, and then \"extract some API\".\nOur first goal is to define addition and multiplication,\nand prove that the complex numbers are a commutative ring.\nWe then do a slightly more computer-sciency worked development of the\nnatural inclusion from the reals to the complexes. \n\nThere are then a bunch of API-building exercises, which can be solved in term mode\nor tactic mode. The first is `I`, the second is complex conjugation,\nand the third is the \"squared norm\" function. \n\nThere is then a speculative last exercise on harder properties\nof the complexes.\n-/\n\n-- We will assume that the real numbers are a field.\nimport data.real.basic\n\n/-- A complex number is defined to be a structure consisting of two real numbers,\n    the real part and the imaginary part of the complex number   . -/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\n-- Let's use the usual notation for the complex numbers\nnotation `\u2102` := complex\n\n-- You make the complex number with real part 3 and imaginary part 4 like this:\nexample : \u2102 :=\n{ re := 3,\n  im := 4 }\n\n-- Or like this:\nexample : \u2102 := complex.mk 3 4\n\n-- or like this:\nexample : \u2102 := \u27e83, 4\u27e9\n\n-- They all give the same complex number.\n\n-- If you have a complex number, then you can get its real and \n-- imaginary parts with the `complex.re` and `complex.im` functions.\n\nexample : \u211d := complex.re(complex.mk 3 4) -- this term is (3 : \u211d)\n\nexample : complex.re(complex.mk 3 4) = 3 := rfl -- true by definition.\n\n-- We clearly don't want to be constantly saying `complex.blah` so let's\n-- move into the `complex` namespace\n\nnamespace complex\n\n-- All our theorems and definitions will now be called complex.something,\n-- and we can in general just drop `complex.`\n\n-- For example\n\nexample : re(mk 3 4) = 3 := rfl\n\n-- Computer scientists prefer the style `z.re` to `re(z)` for some reason. \n\nexample : (mk 3 4).re = 3 := rfl\n\nexample (z : \u2102) : re(z) = z.re := rfl\n\n-- We now prove the basic theorems and make the basic definitions for\n-- complex numbers. For example, we will define addition and multiplication on\n-- the complex numbers, and prove that it is a commutative ring.\n\n/-! # Mathematical trivialities -/\n\n/-! ## The first triviality -/\n\n-- We start with some facts about complex numbers which are so obvious that we do not\n-- often explicitly state them. The first is that if z is a complex number, then\n-- the complex number with real part re(z) and imaginary part im(z) is equal to z.\n-- This is called eta reduction in type theory. Let's work through the\n-- simple tactic mode proof.\n\nexample : \u2200 z : \u2102, complex.mk z.re z.im = z :=\nbegin\n  intro z,\n  cases z with x y, \n  -- goal now looks complicated, and contains terms which look\n  -- like {re := a, im := b}.re which obviously simplify to a.\n  -- The `dsimp` tactic will do some tidying up for us, although\n  -- it is not logically necessary. `dsimp` does definitional simplification.\n  dsimp,\n  -- Now we see the goal can be solved by reflexivity\n  refl,\nend\n\n-- The proof was \"unfold everything, and it's true by definition\".\n-- This proof does not teach a mathematician anything, so we may as well write\n-- it in term mode, because each tactic has a term equivalent.\n-- The equation compiler does the `intro` and `cases` steps,\n-- and `dsimp` was unnecessary -- the two sides of the equation \n-- were definitionally equal.\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8x, y\u27e9 := rfl\n\n/-! ### Digression on `simp` -/\n\n-- It's important we give this theorem a name (and we called it `eta`\n-- because that's what computer scientists call lemmas of this form).\n-- The reason it's important is that we want `simp`\n-- to be able to use it. In short, the `simp` tactic tries to solve\n-- goals of the form A = B, when `refl` doesn't work (i.e. the goals are\n-- not definitionally equal) but when any mathematician would be able\n-- to simplify A and B via \"obvious\" steps such as `0 + x = x` or\n-- `\u27e8z.re, z.im\u27e9 = z`. These things are sometimes not true by definition,\n-- but they should be tagged as being well-known ways to simplify an equality.\n-- When building our API for the complex numbers, if we prove a theorem of the\n-- form `A = B` where `B` is a bit simpler than `A`, we should probably\n-- tag it with the `@[simp]` attribute, so `simp` can use it.\n\n-- Note: `simp` does *not* prove \"all simple things\". It proves *equalities*.\n-- It proves `A = B` when, and only when, it can do it by applying \n-- its \"simplification rules\", where a simplification rule is simply a proof\n-- of a theorem of the form `A = B` and `B` is simpler than `A`.  \n\n/-! ## The second triviality -/\n\n-- The second triviality is the assertion that two complex numbers\n-- with the same and imaginary parts are equal. Again this is not\n-- hard to prove, and mathematicians deem it not worth documenting.\n\nexample (z w : \u2102) : z.re = w.re \u2192 z.im = w.im \u2192 z = w :=\nbegin\n  cases z with zr zi,\n  cases w,\n  intros, cc,\nend\n\n-- This lemma is called extensionality by type theorists.\n-- Here is another tactic mode proof. Note that we have moved\n-- the z and w to the other side of the colon; this does not\n-- change the fully expanded proof term. It shows the power\n-- of the `rintros` tactic.\n\nexample : \u2200 z w : \u2102, z.re = w.re \u2192 z.im = w.im \u2192 z = w :=\nbegin\n  rintros \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 \u27e8rfl\u27e9 \u27e8rfl\u27e9,\n  refl,\nend\n\n-- `rintros` does `cases` as many times as you like using this cool `\u27e8, \u27e9` syntax\n-- for the case splits. Note that if you do cases on `h : a = b` then, because\n-- `=` is notation for `eq`, an inductive type with one constructor `a = a`, \n-- it will just delete `b` and change all `b`s to `a`s. That is one of the\n-- things going on in the above proof.\n\n-- Here is the same proof in term mode. Even though it's obvious, we still\n-- give it a name, namely `ext`. It's important to prove it, so we can\n-- tag it with the `ext` attribute. If we do this, the `ext` tactic can use it.\n-- The `ext` tactic applies all theorems of the form \"two\n-- objects are the same if they are made from the same pieces\".\n\n@[ext]\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\n-- The theorem `complex.ext` is trivially true to a mathematician.\n-- But it is often used: for example it will be used all the time\n-- in our proof that the complex numbers are a ring.\n\n-- Note that `ext` is an implication -- if re(z)=re(w) and im(z)=im(w) then z=w.\n-- The below variant `ext_iff` is the two-way implication: two complex\n-- numbers are equal if and only if they have the same real and imaginary part.\n-- Let's first see a tactic mode proof. See how the `ext` tactic is used?\n-- After it is applied, we have two goals, both of which are hypotheses.\n-- The semicolon means \"apply the next tactic to all the goals produced by this one\"\n\nexample (z w : \u2102) : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\nbegin\n  split,\n  { intro H,\n    simp [H]},\n  {\n    rintro \u27e8hre, him\u27e9,\n    ext; assumption,\n  }\nend\n\n-- Again this is easy to write in term mode, and no mathematician\n-- wants to read the proof anyway.\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\n/-! # Main course: the complex numbers are a ring. -/\n\n-- Our goal is to prove that the complexes are a ring. Let's\n-- define the structure first; the zero, one, addition and multiplication\n-- on the complexes. \n\n/-! ## 0 -/\n\n-- Let's define the zero complex number. Once we have done this we will be\n-- able to talk about (0 : \u2102).\n\n/-- notation: `0`, or (0 : \u2102), will mean the complex number with\n  real and imaginary part equal to (0 : \u211d). -/\ninstance : has_zero \u2102 := \u27e8\u27e80, 0\u27e9\u27e9\n\n-- Let's prove its basic properties, all of which are true by definition,\n-- and then tag them with the appropriate attributes.\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n\n/-! ## 1 -/\n\n-- Now let's do the same thing for 1.\n\n/-- Notation `1` or `(1 : \u2102)`, means `\u27e8(1 : \u211d), (0 : \u211d)\u27e9`. -/\ninstance : has_one \u2102 := \u27e8\u27e81, 0\u27e9\u27e9 \n\n-- name basic properties and tag them appropriately\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n\n/-! ## + -/\n\n-- Now let's define addition\n\n/-- Notation `+` for usual addition of complex numbers-/\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n-- and state and tag its basic properties. We want to prove\n-- theorems like $$a(b+c)=ab+ac$$ by checking on real and\n-- imaginary parts, so we need to teach the simplifier\n-- these tricks.\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n\n\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n\n/-! ## Example of what `simp` can now do -/\n\nexample (a b c : \u2102) : re(a*(b+c)) = re(a) * (re(b) + re(c)) - im(a) * (im(b) + im(c)) :=\nbegin\n  simp,\nend\n\n\n/-! # Theorem:  The complex numbers are a commutative ring -/\n\n-- Proof: we've defined all the structure, and every axiom can be checked by reducing it\n-- to checking real and imaginary parts with `ext`, expanding everything out with `simp`\n-- and then using the fact that the real numbers are a ring.\ninstance : comm_ring \u2102 :=\nby refine { zero := 0, add := (+), neg := has_neg.neg, one := 1, mul := (*), ..};\n   { intros, apply ext_iff.2; split; simp; ring }\n\n-- That is the end of the proof that the complexes form a ring. We built\n-- a basic API which was honed towards the general idea that to prove\n-- certain statements about the complex numbers, for example distributivity,\n-- we could just check on real and imaginary parts. We trained the `simp`\n-- lemma to simplify every\n\n\n/-! # Coercion \n\nThis is a worked example of how coercions work from the reals to the complexes.\nIt's convenient to do this early, and very straightforward.\n I have left in the term mode proofs, with explanations.\n\n-/\n\n-- Let's define a \"canonical\" map from \u211d to \u2102. Instead of making it a definition, we will\n-- make it a coercion instance, which means that if `(r : \u211d)` is a real\n-- number, then `(r : \u2102)` or `(\u2191r : \u2102)` will indicate the corresponding\n-- complex number with no imaginary part\n\n/-- The coercion from \u211d to \u2102 sending `r` to the complex number `\u27e8r, 0\u27e9` -/\ninstance : has_coe \u211d \u2102 := \u27e8\u03bb r, \u27e8r, 0\u27e9\u27e9\n\n-- The concept of the complex number associated\n-- to a real number `r` is a new definition, so we had better formulate its basic\n-- properties immediately, namely what its real and imaginary parts are,\n-- and their basic behaviour. Here are two properties, both true by definition.\n-- We name them because we want to tag them.\n@[simp, norm_cast] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\n\n-- The `simp` tactic will now simplify `re(\u2191r)` to `r` and `im(\u2191r)` to `0`.\n-- The `norm_cast` tactic might help you if you have proved a general\n-- equality about complex numbers but you want it to be about real numbers,\n-- or vice-versa.\n\n-- The map from the reals to the complexes is injective, something we\n-- write in iff form so `simp` can use it; `simp` also works on `iff` goals.\n@[simp, norm_cast] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\n-- We now go through all our basic constants, namely 0, 1, + and *,\n-- and tell the simplifier how they behave with respect to this new function. \n\n/-! ## 0 -/\n@[simp, norm_cast] lemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\n/-! ## 1 -/\n@[simp, norm_cast] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\n/-! ## + -/\n\n-- TODO: some crazy bug? in Lean is sometimes stopping me from\n-- uncommenting the following example and then putting\n-- some code after it. Probably the commit before this one.\n\n-- It is a theorem that the canonical map from \u211d to \u2102 commutes with addition.\n-- We should prove this and tag it appropriately.\n\nexample (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s :=\nbegin\n  -- goal: to prove two complex numbers are equal.\n  ext,\n  -- goal: to prove that their real and imaginary\n  -- parts are equal. \n  { -- real part\n    simp},\n  { -- imaginary part\n    simp},\nend\n\n-- Here's the term mode version. It's not true by definition, but `ext` and `simp` solve it.\n@[simp, norm_cast] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s := ext_iff.2 $ by simp\n\n/-! ## - -/\n@[simp, norm_cast] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\n/-! ## * -/\n\n@[simp, norm_cast] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\n/-! ## Example `simp` usage -/\n\n-- examples of the power of `simp` now. Change to -- `by squeeze_simp` to see which\n-- lemmas `simp` uses\nlemma smul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp -- or by squeeze_simp\nlemma smul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp -- or by squeeze_simp\n\n/-! ## Appendix: numerals.\n\nIf you're not a computer scientist feel free to skip 15 lines down to `I`.\n\nThese last two are to do with the canonical map from numerals into the complexes, e.g. `(23 : \u2102)`.\nLean stores the numeral in binary. See for example\n\nset_option pp.numerals false\n#check (37 : \u2102)-- bit1 (bit0 (bit1 (bit0 (bit0 has_one.one)))) : \u2102\n-/\n\n@[simp, norm_cast] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r := ext_iff.2 $ by simp [bit0]\n@[simp, norm_cast] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r := ext_iff.2 $ by simp [bit1]\n\n/-! \n\n# Exercise 1: I \n\nI find it unbelievable that we have written 350+ lines of code about the complex numbers\nand we've still never defined i, or j, or I, or $$\\sqrt{-1}$$, or whatever it's called. \nI will supply the definition, Why don't you try making its basic API?\n\nAll the proofs below are sorried. You can try them in tactic mode\nby replacing `sorry` with `begin end` and then starting to write \ntactics in the `begin end` block.\n-/\n\n/-- complex.I is the square root of -1 above the imaginary axis -/\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := sorry\n@[simp] lemma I_im : I.im = 1 := sorry\n\n@[simp] lemma I_mul_I : I * I = -1 := sorry\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I := sorry\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z := sorry\n\n-- boss level\nlemma I_ne_zero : (I : \u2102) \u2260 0 := sorry\n\n/-! \n\n# Exercise 2: Complex conjugation\n\nAgain I'll give you the definition, you supply the proofs.\n\n-/\n\n\ndef conj (z : \u2102) : \u2102 := \u27e8z.re, -z.im\u27e9\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := sorry\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := sorry\n\n@[simp] lemma conj_of_real (r : \u211d) : conj r = r := sorry\n\n@[simp] lemma conj_zero : conj 0 = 0 := sorry\n@[simp] lemma conj_one : conj 1 = 1 := sorry\n@[simp] lemma conj_I : conj I = -I := sorry\n\n@[simp] lemma conj_add (z w : \u2102) : conj (z + w) = conj z + conj w :=\nsorry\n\n@[simp] lemma conj_neg (z : \u2102) : conj (-z) = -conj z := sorry\n\n@[simp] lemma conj_neg_I : conj (-I) = I := sorry\n\n@[simp] lemma conj_mul (z w : \u2102) : conj (z * w) = conj z * conj w :=\nsorry\n\n@[simp] lemma conj_conj (z : \u2102) : conj (conj z) = z :=\nsorry\n\nlemma conj_involutive : function.involutive conj := sorry\n\nlemma conj_bijective : function.bijective conj := sorry\n\nlemma conj_inj {z w : \u2102} : conj z = conj w \u2194 z = w :=\nsorry\n\n@[simp] lemma conj_eq_zero {z : \u2102} : conj z = 0 \u2194 z = 0 :=\nsorry\n\nlemma eq_conj_iff_real {z : \u2102} : conj z = z \u2194 \u2203 r : \u211d, z = r :=\nsorry\n\nlemma eq_conj_iff_re {z : \u2102} : conj z = z \u2194 (z.re : \u2102) = z :=\nsorry\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\nsorry\n\n/-- the ring homomorphism complex conjugation -/\ndef Conj : \u2102 \u2192+* \u2102 :=\n{ to_fun := conj,\n  map_one' := sorry,\n  map_mul' := sorry,\n  map_zero' := sorry,\n  map_add' := sorry}\n\n/-! \n\n# Exercise 3: Norms\n\n-/\n\ndef norm_sq (z : \u2102) : \u211d := z.re * z.re + z.im * z.im\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nsorry\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := sorry\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := sorry\n@[simp] lemma norm_sq_I : norm_sq I = 1 := sorry\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z := sorry\n\n@[simp] lemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\nsorry\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\nsorry\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nsorry\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nsorry\n\n@[simp] lemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nsorry\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nsorry\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nsorry\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nsorry\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\nsorry\n\nend complex\n\n/-! # Exercise 4 (advanced) \n\n1) Prove the complex numbers are a field.\n\n2) Prove the complex numbers are an algebraically closed field. \n\n\n-/\n\ninstance : field \u2102 := sorry\n\n-- As for it being algebraically closed, [here](https://github.com/leanprover-community/mathlib/blob/3710744/src/analysis/complex/polynomial.lean#L34)\n-- is where it is proved in mathlib. The mathlib proof was written by Chris Hughes, a mathematics\n-- undergraduate at Imperial College London.\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Mathematics_In_Lean_ideas/complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7329929567888309}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.derivative\nimport tactic.linear_combination\nimport tactic.ring_exp\n\n/-!\n# Theory of univariate polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe main def is `binom_expansion`.\n-/\n\nnoncomputable theory\n\nnamespace polynomial\nopen_locale polynomial\nuniverses u v w x y z\nvariables {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type x} {k : Type y} {A : Type z}\n  {a b : R} {m n : \u2115}\n\nsection identities\n\n/- @TODO: pow_add_expansion and pow_sub_pow_factor are not specific to polynomials.\n  These belong somewhere else. But not in group_power because they depend on tactic.ring_exp\n\nMaybe use data.nat.choose to prove it.\n -/\n/--\n`(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring.\n-/\ndef pow_add_expansion {R : Type*} [comm_semiring R] (x y : R) : \u2200 (n : \u2115),\n  {k // (x + y)^n = x^n + n*x^(n-1)*y + k * y^2}\n| 0 := \u27e80, by simp\u27e9\n| 1 := \u27e80, by simp\u27e9\n| (n+2) :=\n  begin\n    cases pow_add_expansion (n+1) with z hz,\n    existsi x*z + (n+1)*x^n+z*y,\n    calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) : by ring_exp\n    ... = (x + y) * (x ^ (n + 1) + \u2191(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) : by rw hz\n    ... = x ^ (n + 2) + \u2191(n + 2) * x ^ (n + 1) * y + (x*z + (n+1)*x^n+z*y) * y ^ 2 :\n      by { push_cast, ring_exp! }\n  end\n\nvariables [comm_ring R]\n\nprivate def poly_binom_aux1 (x y : R) (e : \u2115) (a : R) :\n  {k : R // a * (x + y)^e = a * (x^e + e*x^(e-1)*y + k*y^2)} :=\nbegin\n  existsi (pow_add_expansion x y e).val,\n  congr,\n  apply (pow_add_expansion _ _ _).property\nend\n\nprivate lemma poly_binom_aux2 (f : R[X]) (x y : R) :\n  f.eval (x + y) = f.sum (\u03bb e a, a * (x^e + e*x^(e-1)*y + (poly_binom_aux1 x y e a).val*y^2)) :=\nbegin\n  unfold eval eval\u2082, congr' with n z,\n  apply (poly_binom_aux1 x y _ _).property\nend\n\nprivate lemma poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) =\n  f.sum (\u03bb e a, a * x^e) +\n  f.sum (\u03bb e a, (a * e * x^(e-1)) * y) +\n  f.sum (\u03bb e a, (a *(poly_binom_aux1 x y e a).val)*y^2) :=\nby { rw poly_binom_aux2, simp [left_distrib, sum_add, mul_assoc] }\n\n/--\nA polynomial `f` evaluated at `x + y` can be expressed as\nthe evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`,\nplus some element `k : R` times `y^2`.\n-/\ndef binom_expansion (f : R[X]) (x y : R) :\n  {k : R // f.eval (x + y) = f.eval x + (f.derivative.eval x) * y + k * y^2} :=\nbegin\n  existsi f.sum (\u03bb e a, a *((poly_binom_aux1 x y e a).val)),\n  rw poly_binom_aux3,\n  congr,\n  { rw [\u2190eval_eq_sum], },\n  { rw derivative_eval, exact finset.sum_mul.symm },\n  { exact finset.sum_mul.symm }\nend\n\n/--\n`x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring.\n-/\ndef pow_sub_pow_factor (x y : R) : \u03a0 (i : \u2115), {z : R // x^i - y^i = z * (x - y)}\n| 0 := \u27e80, by simp\u27e9\n| 1 := \u27e81, by simp\u27e9\n| (k+2) :=\n  begin\n    cases @pow_sub_pow_factor (k+1) with z hz,\n    existsi z*x + y^(k+1),\n    linear_combination x * hz with { normalization_tactic := `[ring_exp] }\n  end\n\n/--\nFor any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)`\nfor some `z` in the ring.\n-/\ndef eval_sub_factor (f : R[X]) (x y : R) :\n  {z : R // f.eval x - f.eval y = z * (x - y)} :=\nbegin\n  refine \u27e8f.sum (\u03bb i r, r * (pow_sub_pow_factor x y i).val), _\u27e9,\n  delta eval eval\u2082,\n  simp only [sum, \u2190 finset.sum_sub_distrib, finset.sum_mul],\n  dsimp,\n  congr' with i r,\n  rw [mul_assoc, \u2190(pow_sub_pow_factor x y _).prop, mul_sub],\nend\n\nend identities\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/identities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7329929521958961}}
{"text": "namespace hide\n\ninductive nat : Type :=\n| zero : nat\n| succ : nat \u2192 nat\n\nnamespace nat\n\ndefinition add (m n : nat) : nat :=\nnat.rec_on n m (fun n add_m_n, succ add_m_n)\n\nnotation 0 := zero\ninfix `+` := add\n\ntheorem add_zero (m : nat) : m + 0 = m := rfl\n\ntheorem add_succ (m n : nat) : m + succ n = succ (m + n) := rfl\n\nlocal abbreviation induction_on := @nat.induction_on\n\ntheorem zero_add (n : nat) : 0 + n = n :=\ninduction_on n\n  (show 0 + 0 = 0, from rfl)\n  (take n,\n    assume IH : 0 + n = n,\n    show 0 + succ n = succ n, from\n      calc\n        0 + succ n = succ (0 + n) : rfl\n          ... = succ n : IH)\n\nattribute add [reducible]\ntheorem add_assoc (m n k : nat) : m + n + k = m + (n + k) :=\ninduction_on k rfl (take k IH, eq.subst IH rfl)\n\ntheorem succ_add (m n : nat) : succ m + n = succ (m + n) :=\ninduction_on n\n  (show succ m + 0 = succ (m + 0), from rfl)\n  (take n,\n    assume IH : succ m + n = succ (m + n),\n    show succ m + succ n = succ (m + succ n), from\n      calc\n        succ m + succ n = succ (succ m + n) : rfl\n          ... = succ (succ (m + n)) : IH\n          ... = succ (m + succ n) : rfl)\n\ntheorem add_comm (m n : nat) : m + n = n + m :=\ninduction_on n\n  (show m + 0 = 0 + m, from eq.symm (zero_add m))\n  (take n,\n    assume IH : m + n = n + m,\n    calc\n      m + succ n = succ (m + n) : rfl\n        ... = succ (n + m) : IH\n        ... = succ n + m : succ_add)\n\n-- define mul by recursion on the second argument\ndefinition mul (m n : nat) : nat :=\n  nat.rec_on n 0 (fun n mul_m_n, mul_m_n + m)\n\ninfix `*` := mul\n\n-- these should be proved by rfl\ntheorem mul_zero (m : nat) : m * 0 = 0 := rfl\n\ntheorem mul_succ (m n : nat) : m * (succ n) = m * n + m :=\n  induction_on n\n    (show m * (succ 0) = m * 0 + m, from rfl)\n    (take n,\n      assume IH : m * (succ n) = m * n + m,\n      calc\n        m * (succ (succ n)) = m * (succ n) + m : rfl)\n\ntheorem zero_mul (n : nat) : 0 * n = 0 :=\n  induction_on n\n    (show 0 * 0 = 0, from rfl)\n    (take n,\n      assume IH : 0 * n = 0,\n      calc\n        0 * (succ n) = (0 * n) + 0 : rfl\n        ... = 0 + 0 : IH\n        ... = 0 : rfl)\n\ntheorem mul_distrib (m n k : nat) : m * (n + k) = m * n + m * k :=\n  induction_on k\n    (show m * (n + 0) = m * n + m * 0, from rfl)\n    (take k,\n      assume IH : m * (n + k) = m * n + m * k,\n      calc\n        m * (n + (succ k)) = m * succ (n + k) : rfl\n        ... = m * (n + k) + m : mul_succ\n        ... = (m * n + m * k) + m : IH\n        ... = m * n + (m * k + m) : add_assoc\n        ... = m * n + m * (succ k) : mul_succ)\n\ntheorem mul_assoc (m n k : nat) : m * n * k = m * (n * k) :=\n  induction_on k \n    rfl\n    (take k,\n      assume IH : m * n * k = m * (n * k),\n        calc\n          m * n * succ k = m * n * k + m * n : mul_succ\n          ... = m * (n * k) + m * n : IH\n          ... = m * (n * k + n) : mul_distrib\n          ... = m * (n * succ k) : mul_succ)\n\n-- hint: you will need to prove an auxiliary statement\ntheorem succ_mul (m n : nat) : succ m * n = m * n + n :=\n  induction_on n\n    rfl\n    (take n,\n      assume IH : succ m * n = m * n + n,\n        calc\n          succ m * succ n = succ m * n + succ m : mul_succ\n          ... = (m * n + n) + succ m : IH\n          ... = m * n + (n + succ m) : add_assoc\n          ... = m * n + succ (n + m) : add_succ\n          ... = m * n + (succ n + m) : succ_add\n          ... = m * n + (m + succ n) : add_comm\n          ... = (m * n + m) + succ n : add_assoc\n          ... = m * succ n + succ n : mul_succ)\n\ntheorem mul_comm (m n : nat) : m * n = n * m :=\n  induction_on n\n    (show m * 0 = 0 * m, from\n      calc \n        m * 0 = 0 : mul_zero\n        ... = 0 * m : zero_mul)\n    (take n,\n      assume IH : m * n = n * m,\n      calc\n        m * succ n = m * n + m : mul_succ\n        ... = n * m + m : IH\n        ... = succ n * m : succ_mul)\n\ndefinition pred (n : nat) : nat := nat.cases_on n zero (fun n, n)\n\ntheorem pred_succ (n : nat) : pred (succ n) = n := rfl\n\ntheorem succ_pred (n : nat) : n \u2260 0 \u2192 succ (pred n) = n :=\n  nat.rec_on n\n    (\u03bb H : 0 \u2260 0,\n      have H' : 0 = 0, from rfl,\n      absurd H' H)\n    (take n,\n      assume IH : n \u2260 0 \u2192 succ (pred n) = n,\n        (\u03bb H : succ n \u2260 0,\n          calc\n            succ (pred (succ n)) = succ n : rfl))\n\n\nend nat\n\nend hide\n\nnamespace hide\n\ninductive list (A : Type) : Type :=\n| nil {} : list A\n| cons : A \u2192 list A \u2192 list A\n\nnamespace list\n\nnotation `[` l:(foldr `,` (h t, cons h t) nil) `]` := l\n\nvariable {A : Type}\n\nnotation h :: t  := cons h t\n\ndefinition append (s t : list A) : list A :=\nlist.rec_on s t (\u03bb x l u, x::u)\n\nnotation s ++ t := append s t\n\ntheorem nil_append (t : list A) : nil ++ t = t := rfl\n\ntheorem cons_append (x : A) (s t : list A) : x::s ++ t = x::(s ++ t) := rfl\n\ntheorem append_nil (t : list A) : t ++ nil = t :=\n  list.induction_on t\n    rfl\n    (\u03bb x t,\n      assume IH : t ++ nil = t,\n        calc\n          (x :: t) ++ nil = x :: (t ++ nil) : rfl\n          ... = x :: t : IH)\n        \ntheorem append_assoc (r s t : list A) : r ++ s ++ t = r ++ (s ++ t) :=\n  list.induction_on r\n    rfl\n    (\u03bb x r,\n      assume IH : r ++ s ++ t = r ++ (s ++ t),\n        calc\n        (x :: r) ++ s ++ t = x :: (r ++ s) ++ t : rfl\n        ... = x :: (r ++ s ++ t) : rfl\n        ... = x :: (r ++ (s ++ t)) : IH\n        ... = (x :: r) ++ (s ++ t) : rfl)\n\nend list\nend hide\n\nnamespace hide\n\ninductive eq {A : Type} (a : A) : A \u2192 Prop :=\n  refl : eq a a\n\ntheorem cast {A B : Type} (p : eq A B) (a : A) : B :=\n  (eq.rec a) p\n\ntheorem subst {A : Type} {a b : A} {P : A \u2192 Prop}\n  (H_1 : eq a b) (H_2 : P a) : P b :=\n  (eq.rec H_2) H_1\n\ntheorem symm {A : Type} {a b : A} (H : eq a b) : eq b a :=\n  (eq.rec (eq.refl a)) H\n\ntheorem trans {A : Type} {a b c : A} (H_1 : eq a b) (H_2 : eq b c) : eq a c :=\n  eq.rec H_1 H_2\n\ntheorem congr {A B : Type} {a b : A} (f : A \u2192 B) (H : eq a b) : eq (f a) (f b) :=\n  eq.rec (eq.refl (f a)) H\n\ntheorem hcongr {A : Type} {B : A \u2192 Type} {a b : A} (f : \u03a0 x : A, B x)\n      (H : eq a b) : eq (eq.rec_on H (f a)) (f b) :=\n  have h1 : \u2200 h : eq a a, eq (eq.rec_on h (f a)) (f a), from\n    (assume h : eq a a, eq.refl (eq.rec_on h (f a))),\n  have h2 : \u2200 h : eq a b, eq (eq.rec_on h (f a)) (f b), from\n    eq.rec_on H h1,\n  show eq (eq.rec_on H (f a)) (f b), from\n    h2 H\n\nend hide\n\nnamespace hide\n \ninductive tree (A : Type) : Type :=\n| leaf : A \u2192 tree A\n| node : tree A \u2192 tree A \u2192 tree A\n\nopen tree\n \nvariable {A : Type}\n\ntheorem leaf_ne_node {a : A} {l r : tree A}\n    (h : leaf a = node l r) : false :=\n  tree.no_confusion h\n\ntheorem leaf_inj {a b : A} (h : leaf a = leaf b) : a = b :=\n  tree.no_confusion h (fun e : a = b, e)\n\ntheorem node_inj_left {l1 r1 l2 r2 : tree A}\n    (h : node l1 r1 = node l2 r2) : l1 = l2 :=\n  tree.no_confusion h (fun (l : l1 = l2) (r : r1 = r2), l)\n\ntheorem node_inj_right {l1 r1 l2 r2 : tree A}\n    (h : node l1 r1 = node l2 r2) : r1 = r2 :=\n  tree.no_confusion h (fun (l : l1 = l2) (r : r1 = r2), r)\n     \nend hide\n", "meta": {"author": "0xpr", "repo": "lean_tutorial", "sha": "56ef609d8df9e392916012db5354bf182cbbb8d8", "save_path": "github-repos/lean/0xpr-lean_tutorial", "path": "github-repos/lean/0xpr-lean_tutorial/lean_tutorial-56ef609d8df9e392916012db5354bf182cbbb8d8/ch6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7329929520103265}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Importar las teor\u00edas: \n-- + algebra.group_power de potencias en grupos\n-- + tactic de t\u00e1cticas\n-- ----------------------------------------------------------------------\n\nimport algebra.group_power \nimport tactic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declara R como una variable sobre dominios de integridad. \n-- ----------------------------------------------------------------------\n\nvariables {R : Type*} [integral_domain R]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar x e y como variables sobre R. \n-- ----------------------------------------------------------------------\n\nvariables (x y : R)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar si\n--    x^2 = 1\n-- entonces\n--    x = 1 \u2228 x = -1 \n-- ----------------------------------------------------------------------\n\nexample \n  (h : x^2 = 1) \n  : x = 1 \u2228 x = -1 :=\nbegin\n  have h1 : (x - 1) * (x + 1) = 0,\n    calc (x - 1) * (x + 1) = x^2 - 1 : by ring\n                       ... = 1 - 1   : by rw h\n                       ... = 0       : by ring,\n  have h2 : x - 1 = 0 \u2228 x + 1 = 0, \n    { apply eq_zero_or_eq_zero_of_mul_eq_zero h1 },\n  cases h2,\n  { left,\n    exact sub_eq_zero.mp h2 },\n  { right,\n    exact eq_neg_of_add_eq_zero h2 },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar si\n--    x^2 = y^2\n-- entonces\n--    x = y \u2228 x = -y \n-- ----------------------------------------------------------------------\n\nexample \n  (h : x^2 = y^2) \n  : x = y \u2228 x = -y :=\nbegin\n  have h1 : (x - y) * (x + y) = 0,\n    calc (x - y) * (x + y) = x^2 - y^2 : by ring\n                       ... = y^2 - y^2 : by rw h\n                       ... = 0         : by ring,\n  have h2 : x - y = 0 \u2228 x + y = 0, \n    { apply eq_zero_or_eq_zero_of_mul_eq_zero h1 },\n  cases h2,\n  { left,\n    exact sub_eq_zero.mp h2 },\n  { right,\n    exact eq_neg_of_add_eq_zero h2 },\nend\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Igualdad_de_cuadrados_en_dominios_de_integridad.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.732844824742713}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module data.polynomial.denoms_clearable\n! leanprover-community/mathlib commit 85d9f2189d9489f9983c0d01536575b0233bd305\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.EraseLead\nimport Mathlib.Data.Polynomial.Eval\n\n/-!\n# Denominators of evaluation of polynomials at ratios\n\nLet `i : R \u2192 K` be a homomorphism of semirings.  Assume that `K` is commutative.  If `a` and\n`b` are elements of `R` such that `i b \u2208 K` is invertible, then for any polynomial\n`f \u2208 R[X]` the \"mathematical\" expression `b ^ f.natDegree * f (a / b) \u2208 K` is in\nthe image of the homomorphism `i`.\n-/\n\n\nopen Polynomial Finset\n\nopen Polynomial\n\nsection DenomsClearable\n\nvariable {R K : Type _} [Semiring R] [CommSemiring K] {i : R \u2192+* K}\n\nvariable {a b : R} {bi : K}\n\n-- TODO: use hypothesis (ub : IsUnit (i b)) to work with localizations.\n/-- `denomsClearable` formalizes the property that `b ^ N * f (a / b)`\ndoes not have denominators, if the inequality `f.natDegree \u2264 N` holds.\n\nThe definition asserts the existence of an element `D` of `R` and an\nelement `bi = 1 / i b` of `K` such that clearing the denominators of\nthe fraction equals `i D`.\n-/\ndef DenomsClearable (a b : R) (N : \u2115) (f : R[X]) (i : R \u2192+* K) : Prop :=\n  \u2203 (D : R)(bi : K), bi * i b = 1 \u2227 i D = i b ^ N * eval (i a * bi) (f.map i)\n#align denoms_clearable DenomsClearable\n\ntheorem denomsClearable_zero (N : \u2115) (a : R) (bu : bi * i b = 1) : DenomsClearable a b N 0 i :=\n  \u27e80, bi, bu, by\n    simp only [eval_zero, RingHom.map_zero, MulZeroClass.mul_zero, Polynomial.map_zero]\u27e9\n#align denoms_clearable_zero denomsClearable_zero\n\ntheorem denomsClearable_C_mul_X_pow {N : \u2115} (a : R) (bu : bi * i b = 1) {n : \u2115} (r : R)\n    (nN : n \u2264 N) : DenomsClearable a b N (C r * X ^ n) i := by\n  refine' \u27e8r * a ^ n * b ^ (N - n), bi, bu, _\u27e9\n  rw [C_mul_X_pow_eq_monomial, map_monomial, \u2190 C_mul_X_pow_eq_monomial, eval_mul, eval_pow, eval_C]\n  rw [RingHom.map_mul, RingHom.map_mul, RingHom.map_pow, RingHom.map_pow, eval_X, mul_comm]\n  rw [\u2190 tsub_add_cancel_of_le nN]\n  conv_lhs => rw [\u2190 mul_one (i a), \u2190 bu]\n  simp [mul_assoc, mul_comm, mul_left_comm, pow_add, mul_pow]\nset_option linter.uppercaseLean3 false in\n#align denoms_clearable_C_mul_X_pow denomsClearable_C_mul_X_pow\n\ntheorem DenomsClearable.add {N : \u2115} {f g : R[X]} :\n    DenomsClearable a b N f i \u2192 DenomsClearable a b N g i \u2192 DenomsClearable a b N (f + g) i :=\n  fun \u27e8Df, bf, bfu, Hf\u27e9 \u27e8Dg, bg, bgu, Hg\u27e9 =>\n  \u27e8Df + Dg, bf, bfu,\n    by\n    rw [RingHom.map_add, Polynomial.map_add, eval_add, mul_add, Hf, Hg]\n    congr\n    refine' @inv_unique K _ (i b) bg bf _ _ <;> rwa [mul_comm]\u27e9\n#align denoms_clearable.add DenomsClearable.add\n\ntheorem denomsClearable_of_natDegree_le (N : \u2115) (a : R) (bu : bi * i b = 1) :\n    \u2200 f : R[X], f.natDegree \u2264 N \u2192 DenomsClearable a b N f i :=\n  induction_with_natDegree_le _ N (denomsClearable_zero N a bu)\n    (fun _ r _ => denomsClearable_C_mul_X_pow a bu r) fun _ _ _ _ df dg => df.add dg\n#align denoms_clearable_of_nat_degree_le denomsClearable_of_natDegree_le\n\n/-- If `i : R \u2192 K` is a ring homomorphism, `f` is a polynomial with coefficients in `R`,\n`a, b` are elements of `R`, with `i b` invertible, then there is a `D \u2208 R` such that\n`b ^ f.natDegree * f (a / b)` equals `i D`. -/\ntheorem denomsClearable_natDegree (i : R \u2192+* K) (f : R[X]) (a : R) (bu : bi * i b = 1) :\n    DenomsClearable a b f.natDegree f i :=\n  denomsClearable_of_natDegree_le f.natDegree a bu f le_rfl\n#align denoms_clearable_nat_degree denomsClearable_natDegree\n\nend DenomsClearable\n\nopen RingHom\n\n--Porting note: `etaExperiment` is required to synthesize the `RingHomClass (\u2124 \u2192+* K) \u2124 K` instance\nset_option synthInstance.etaExperiment true in\n/-- Evaluating a polynomial with integer coefficients at a rational number and clearing\ndenominators, yields a number greater than or equal to one.  The target can be any\n`LinearOrderedField K`.\nThe assumption on `K` could be weakened to `LinearOrderedCommRing` assuming that the\nimage of the denominator is invertible in `K`. -/\ntheorem one_le_pow_mul_abs_eval_div {K : Type _} [LinearOrderedField K] {f : \u2124[X]} {a b : \u2124}\n    (b0 : 0 < b) (fab : eval ((a : K) / b) (f.map (algebraMap \u2124 K)) \u2260 0) :\n    (1 : K) \u2264 (b : K) ^ f.natDegree * |eval ((a : K) / b) (f.map (algebraMap \u2124 K))| := by\n  obtain \u27e8ev, bi, bu, hF\u27e9 :=\n    denomsClearable_natDegree (b := b) (algebraMap \u2124 K) f a\n      (by\n        rw [eq_intCast, one_div_mul_cancel]\n        rw [Int.cast_ne_zero]\n        exact b0.ne.symm)\n  obtain Fa := _root_.congr_arg abs hF\n  rw [eq_one_div_of_mul_eq_one_left bu, eq_intCast, eq_intCast, abs_mul] at Fa\n  rw [abs_of_pos (pow_pos (Int.cast_pos.mpr b0) _ : 0 < (b : K) ^ _), one_div, eq_intCast] at Fa\n  rw [div_eq_mul_inv, \u2190Fa, \u2190 Int.cast_abs, \u2190 Int.cast_one, Int.cast_le]\n  refine' Int.le_of_lt_add_one ((lt_add_iff_pos_left 1).mpr (abs_pos.mpr fun F0 => fab _))\n  rw [eq_one_div_of_mul_eq_one_left bu, F0, one_div, eq_intCast, Int.cast_zero, zero_eq_mul] at hF\n  cases' hF with hF hF\n  \u00b7 exact (not_le.mpr b0 (le_of_eq (Int.cast_eq_zero.mp (pow_eq_zero hF)))).elim\n  \u00b7 rwa [div_eq_mul_inv]\n#align one_le_pow_mul_abs_eval_div one_le_pow_mul_abs_eval_div\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/DenomsClearable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7328448125572378}}
{"text": "import SciLean.Core.Functions\n-- import SciLean.Tactic.AutoDiff.Main\n\nnamespace SciLean\n\nvariable {\u03b1 \u03b2 \u03b3 : Type}\nvariable {X Y Z : Type} [Vec X] [Vec Y] [Vec Z]\n\nvariable (f : Y \u2192 Z) [IsSmooth f]\nvariable (g : X \u2192 Y) [IsSmooth g]\nvariable (f1 : X \u2192 X) [IsSmooth f1]\nvariable (f2 : Y \u2192 Y) [IsSmooth f2]\nvariable (f3 : Z \u2192 Z) [IsSmooth f3]\nvariable (F : X \u2192 Y \u2192 Z) [IsSmooth F] [\u2200 x, IsSmooth (F x)]\nvariable (G : X \u00d7 Y \u2192 Z) [IsSmooth G]\n\nvariable (x dx : X) (y dy : Y) (z dz : Z)\n\n-- macro \"diff_simp\" : tactic => `(autodiff_core (config := {singlePass := true}))\nmacro \"diff_simp\" : tactic => `(simp) -- `(autodiff_core (config := {singlePass := true}))\n\nexample : \u2202 (\u03bb x => x) x dx = dx := by diff_simp done\nexample : \u2202 (\u03bb x => f (g x)) x dx = \u2202 f (g x) (\u2202 g x dx) := by diff_simp done\nexample : \u2202 (\u03bb x => f (g (f1 x))) x dx = \u2202 f (g (f1 x)) (\u2202 g (f1 x) (\u2202 f1 x dx)) := by diff_simp done\nexample (y x dx : X) : \u2202 (\u03bb x : X => y) x dx = 0 := by diff_simp done\nexample : \u2202 (\u03bb x => x + x) x dx = dx + dx := by diff_simp done\nexample : \u2202 (\u03bb (x : X) => F x (g x)) x dx = \u2202 F x dx (g x) + \u2202 (F x) (g x) (\u2202 g x dx) := by diff_simp  done\nexample : \u2202 (\u03bb (x : X) => f3 (F x (g x))) x dx = \u2202 f3 (F x (g x)) (\u2202 F x dx (g x) + \u2202 (F x) (g x) (\u2202 g x dx)) := by diff_simp done\nexample g dg x : \u2202 (\u03bb (g : X \u2192 Y) => f (g x)) g dg = \u2202 f (g x) (dg x) := by diff_simp done\nexample g dg x : \u2202 (\u03bb (g : X \u2192 Y) (x : X) => F x (g x)) g dg x = \u2202 (F x) (g x) (dg x) := by diff_simp done\nexample g dg x : \u2202 (\u03bb (g : X \u2192 X) (y : Y) => F (g x) y) g dg y = \u2202 F (g x) (dg x) y := by diff_simp done\nexample (r dr : \u211d) : \u2202 (\u03bb x : \u211d => x*x + x) r dr = dr * r + r * dr + dr := by diff_simp; done\nexample (r dr : \u211d) : \u2202 (\u03bb x : \u211d => x*x*x + x) r dr = (dr * r + r * dr) * r + r * r * dr + dr := by diff_simp; done\nexample g dg y : \u2202 (\u03bb (g : X \u2192 X) (x : X) => F (g x) y) g dg x = \u2202 F (g x) (dg x) y := by diff_simp done \n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/test/basic_differential_tests.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7328448068199296}}
{"text": "-- Monotonia_de_la_suma_por_la_derecha.lean\n-- Monoton\u00eda de la suma por la derecha\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 14 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si a, b y c son n\u00fameros reles tales que \n-- a \u2264 b, entonces a + c \u2264 b + c.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\nvariables {a b c : \u211d}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nbegin\n  rw \u2190 sub_nonneg,\n  have h : (b + c) - (a + c) = b - a, \n  { ring, },  \n  { rw h, \n    rw sub_nonneg,\n    exact hab, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nbegin\n  rw \u2190 sub_nonneg,\n  calc 0   \u2264 b - a           : by exact sub_nonneg.mpr hab\n       ... = b + c - (a + c) : by exact (add_sub_add_right_eq_sub b a c).symm, \nend\n\n-- Comentario: Se usa el lema\n-- + add_sub_add_right_eq_sub : a + c - (b + c) = a - b \n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nbegin\n  rw \u2190 sub_nonneg,\n  calc 0   \u2264 b - a           : sub_nonneg.mpr hab\n       ... = b + c - (a + c) : (add_sub_add_right_eq_sub b a c).symm, \nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nbegin\n  rw \u2190 sub_nonneg,\n  calc 0   \u2264 b - a           : sub_nonneg.mpr hab\n       ... = b + c - (a + c) : by ring,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nbegin\n  rw \u2190 sub_nonneg,\n  simp,\n  exact hab,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nbegin\n  rw \u2190 sub_nonneg,\n  simp [hab],\nend\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nbegin\n  simp [hab],\nend\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nby simp [hab]\n\n-- 9\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nadd_le_add_right hab c\n\n-- Comentario: Se ha usado el lema\n-- + add_le_add_right : a \u2264 b \u2192 \u2200 (c : \u211d), a + c \u2264 b + c \n\n-- 10\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nby linarith\n\n-- 11\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hab : a \u2264 b) \n  : a + c \u2264 b + c :=\nby finish\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/2_Conectivas/Monotonia_de_la_suma_por_la_derecha.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8840392878563335, "lm_q1q2_score": 0.732814473784942}}
{"text": "/-\nCopyright (c) 2022 David Loeffler. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Loeffler\n-/\nimport measure_theory.integral.exp_decay\nimport analysis.calculus.parametric_integral\nimport analysis.special_functions.integrals\nimport analysis.convolution\nimport analysis.special_functions.trigonometric.euler_sine_prod\n\n/-!\n# The Gamma and Beta functions\n\nThis file defines the `\u0393` function (of a real or complex variable `s`). We define this by Euler's\nintegral `\u0393(s) = \u222b x in Ioi 0, exp (-x) * x ^ (s - 1)` in the range where this integral converges\n(i.e., for `0 < s` in the real case, and `0 < re s` in the complex case).\n\nWe show that this integral satisfies `\u0393(1) = 1` and `\u0393(s + 1) = s * \u0393(s)`; hence we can define\n`\u0393(s)` for all `s` as the unique function satisfying this recurrence and agreeing with Euler's\nintegral in the convergence range. (If `s = -n` for `n \u2208 \u2115`, then the function is undefined, and we\nset it to be `0` by convention.)\n\n## Gamma function: main statements (complex case)\n\n* `complex.Gamma`: the `\u0393` function (of a complex variable).\n* `complex.Gamma_eq_integral`: for `0 < re s`, `\u0393(s)` agrees with Euler's integral.\n* `complex.Gamma_add_one`: for all `s : \u2102` with `s \u2260 0`, we have `\u0393 (s + 1) = s \u0393(s)`.\n* `complex.Gamma_nat_eq_factorial`: for all `n : \u2115` we have `\u0393 (n + 1) = n!`.\n* `complex.differentiable_at_Gamma`: `\u0393` is complex-differentiable at all `s : \u2102` with\n  `s \u2209 {-n : n \u2208 \u2115}`.\n* `complex.Gamma_ne_zero`: for all `s : \u2102` with `s \u2209 {-n : n \u2208 \u2115}` we have `\u0393 s \u2260 0`.\n* `complex.Gamma_seq_tendsto_Gamma`: for all `s`, the limit as `n \u2192 \u221e` of the sequence\n  `n \u21a6 n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `\u0393(s)`.\n* `complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula\n  `Gamma s * Gamma (1 - s) = \u03c0 / sin \u03c0 s`.\n\n## Gamma function: main statements (real case)\n\n* `real.Gamma`: the `\u0393` function (of a real variable).\n* Real counterparts of all the properties of the complex Gamma function listed above:\n  `real.Gamma_eq_integral`, `real.Gamma_add_one`, `real.Gamma_nat_eq_factorial`,\n  `real.differentiable_at_Gamma`, `real.Gamma_ne_zero`, `real.Gamma_seq_tendsto_Gamma`,\n  `real.Gamma_mul_Gamma_one_sub`.\n* `real.convex_on_log_Gamma` : `log \u2218 \u0393` is convex on `Ioi 0`.\n* `real.eq_Gamma_of_log_convex` : the Bohr-Mollerup theorem, which states that the `\u0393` function is\n  the unique log-convex, positive-valued function on `Ioi 0` satisfying the functional equation\n  and having `\u0393 1 = 1`.\n\n## Beta function\n\n* `complex.beta_integral`: the Beta function `\u0392(u, v)`, where `u`, `v` are complex with positive\n  real part.\n* `complex.Gamma_mul_Gamma_eq_beta_integral`: the formula\n  `Gamma u * Gamma v = Gamma (u + v) * beta_integral u v`.\n\n## Tags\n\nGamma\n-/\n\nnoncomputable theory\nopen filter interval_integral set real measure_theory asymptotics\nopen_locale nat topology ennreal big_operators complex_conjugate\n\nlemma integral_exp_neg_Ioi : \u222b (x : \u211d) in Ioi 0, exp (-x) = 1 :=\nbegin\n  refine tendsto_nhds_unique (interval_integral_tendsto_integral_Ioi _ _ tendsto_id) _,\n  { simpa only [neg_mul, one_mul] using exp_neg_integrable_on_Ioi 0 zero_lt_one, },\n  { simpa using tendsto_exp_neg_at_top_nhds_0.const_sub 1, },\nend\n\nnamespace real\n\n/-- Asymptotic bound for the `\u0393` function integrand. -/\nlemma Gamma_integrand_is_o (s : \u211d) :\n  (\u03bb x:\u211d, exp (-x) * x ^ s) =o[at_top] (\u03bb x:\u211d, exp (-(1/2) * x)) :=\nbegin\n  refine is_o_of_tendsto (\u03bb x hx, _) _,\n  { exfalso, exact (exp_pos (-(1 / 2) * x)).ne' hx },\n  have : (\u03bb (x:\u211d), exp (-x) * x ^ s / exp (-(1 / 2) * x)) = (\u03bb (x:\u211d), exp ((1 / 2) * x) / x ^ s )\u207b\u00b9,\n  { ext1 x,\n    field_simp [exp_ne_zero, exp_neg, \u2190 real.exp_add],\n    left,\n    ring },\n  rw this,\n  exact (tendsto_exp_mul_div_rpow_at_top s (1 / 2) one_half_pos).inv_tendsto_at_top,\nend\n\n/-- The Euler integral for the `\u0393` function converges for positive real `s`. -/\nlemma Gamma_integral_convergent {s : \u211d} (h : 0 < s) :\n  integrable_on (\u03bb x:\u211d, exp (-x) * x ^ (s - 1)) (Ioi 0) :=\nbegin\n  rw [\u2190Ioc_union_Ioi_eq_Ioi (@zero_le_one \u211d _ _ _ _), integrable_on_union],\n  split,\n  { rw \u2190integrable_on_Icc_iff_integrable_on_Ioc,\n    refine integrable_on.continuous_on_mul continuous_on_id.neg.exp _ is_compact_Icc,\n    refine (interval_integrable_iff_integrable_Icc_of_le zero_le_one).mp _,\n    exact interval_integrable_rpow' (by linarith), },\n  { refine integrable_of_is_O_exp_neg one_half_pos _ (Gamma_integrand_is_o _ ).is_O,\n    refine continuous_on_id.neg.exp.mul (continuous_on_id.rpow_const _),\n    intros x hx,\n    exact or.inl ((zero_lt_one : (0 : \u211d) < 1).trans_le hx).ne' }\nend\n\nend real\n\nnamespace complex\n/- Technical note: In defining the Gamma integrand exp (-x) * x ^ (s - 1) for s complex, we have to\nmake a choice between \u2191(real.exp (-x)), complex.exp (\u2191(-x)), and complex.exp (-\u2191x), all of which are\nequal but not definitionally so. We use the first of these throughout. -/\n\n\n/-- The integral defining the `\u0393` function converges for complex `s` with `0 < re s`.\n\nThis is proved by reduction to the real case. -/\nlemma Gamma_integral_convergent {s : \u2102} (hs : 0 < s.re) :\n  integrable_on (\u03bb x, (-x).exp * x ^ (s - 1) : \u211d \u2192 \u2102) (Ioi 0) :=\nbegin\n  split,\n  { refine continuous_on.ae_strongly_measurable _ measurable_set_Ioi,\n    apply (continuous_of_real.comp continuous_neg.exp).continuous_on.mul,\n    apply continuous_at.continuous_on,\n    intros x hx,\n    have : continuous_at (\u03bb x:\u2102, x ^ (s - 1)) \u2191x,\n    { apply continuous_at_cpow_const, rw of_real_re, exact or.inl hx, },\n    exact continuous_at.comp this continuous_of_real.continuous_at },\n  { rw \u2190has_finite_integral_norm_iff,\n    refine has_finite_integral.congr (real.Gamma_integral_convergent hs).2 _,\n    refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    dsimp only,\n    rw [norm_eq_abs, map_mul, abs_of_nonneg $ le_of_lt $ exp_pos $ -x,\n      abs_cpow_eq_rpow_re_of_pos hx _],\n    simp }\nend\n\n/-- Euler's integral for the `\u0393` function (of a complex variable `s`), defined as\n`\u222b x in Ioi 0, exp (-x) * x ^ (s - 1)`.\n\nSee `complex.Gamma_integral_convergent` for a proof of the convergence of the integral for\n`0 < re s`. -/\ndef Gamma_integral (s : \u2102) : \u2102 := \u222b x in Ioi (0:\u211d), \u2191(-x).exp * \u2191x ^ (s - 1)\n\nlemma Gamma_integral_conj (s : \u2102) : Gamma_integral (conj s) = conj (Gamma_integral s) :=\nbegin\n  rw [Gamma_integral, Gamma_integral, \u2190integral_conj],\n  refine set_integral_congr measurable_set_Ioi (\u03bb x hx, _),\n  dsimp only,\n  rw [ring_hom.map_mul, conj_of_real, cpow_def_of_ne_zero (of_real_ne_zero.mpr (ne_of_gt hx)),\n    cpow_def_of_ne_zero (of_real_ne_zero.mpr (ne_of_gt hx)), \u2190exp_conj, ring_hom.map_mul,\n    \u2190of_real_log (le_of_lt hx), conj_of_real, ring_hom.map_sub, ring_hom.map_one],\nend\n\nlemma Gamma_integral_of_real (s : \u211d) :\n  Gamma_integral \u2191s = \u2191(\u222b x:\u211d in Ioi 0, real.exp (-x) * x ^ (s - 1)) :=\nbegin\n  rw [Gamma_integral, \u2190_root_.integral_of_real],\n  refine set_integral_congr measurable_set_Ioi _,\n  intros x hx, dsimp only,\n  rw [of_real_mul, of_real_cpow (mem_Ioi.mp hx).le],\n  simp,\nend\n\nlemma Gamma_integral_one : Gamma_integral 1 = 1 :=\nby simpa only [\u2190of_real_one, Gamma_integral_of_real, of_real_inj, sub_self,\n  rpow_zero, mul_one] using integral_exp_neg_Ioi\n\nend complex\n\n/-! Now we establish the recurrence relation `\u0393(s + 1) = s * \u0393(s)` using integration by parts. -/\n\nnamespace complex\n\nsection Gamma_recurrence\n\n/-- The indefinite version of the `\u0393` function, `\u0393(s, X) = \u222b x \u2208 0..X, exp(-x) x ^ (s - 1)`. -/\ndef partial_Gamma (s : \u2102) (X : \u211d) : \u2102 := \u222b x in 0..X, (-x).exp * x ^ (s - 1)\n\nlemma tendsto_partial_Gamma {s : \u2102} (hs: 0 < s.re) :\n  tendsto (\u03bb X:\u211d, partial_Gamma s X) at_top (\ud835\udcdd $ Gamma_integral s) :=\ninterval_integral_tendsto_integral_Ioi 0 (Gamma_integral_convergent hs) tendsto_id\n\nprivate lemma Gamma_integrand_interval_integrable (s : \u2102) {X : \u211d} (hs : 0 < s.re) (hX : 0 \u2264 X):\n  interval_integrable (\u03bb x, (-x).exp * x ^ (s - 1) : \u211d \u2192 \u2102) volume 0 X :=\nbegin\n  rw interval_integrable_iff_integrable_Ioc_of_le hX,\n  exact integrable_on.mono_set (Gamma_integral_convergent hs) Ioc_subset_Ioi_self\nend\n\nprivate lemma Gamma_integrand_deriv_integrable_A {s : \u2102} (hs : 0 < s.re) {X : \u211d} (hX : 0 \u2264 X):\n interval_integrable (\u03bb x, -((-x).exp * x ^ s) : \u211d \u2192 \u2102) volume 0 X :=\nbegin\n  convert (Gamma_integrand_interval_integrable (s+1) _ hX).neg,\n  { ext1, simp only [add_sub_cancel, pi.neg_apply] },\n  { simp only [add_re, one_re], linarith,},\nend\n\nprivate lemma Gamma_integrand_deriv_integrable_B {s : \u2102} (hs : 0 < s.re) {Y : \u211d} (hY : 0 \u2264 Y) :\n  interval_integrable (\u03bb (x : \u211d), (-x).exp * (s * x ^ (s - 1)) : \u211d \u2192 \u2102) volume 0 Y :=\nbegin\n  have : (\u03bb x, (-x).exp * (s * x ^ (s - 1)) : \u211d \u2192 \u2102) =\n    (\u03bb x, s * ((-x).exp * x ^ (s - 1)) : \u211d \u2192 \u2102),\n  { ext1, ring, },\n  rw [this, interval_integrable_iff_integrable_Ioc_of_le hY],\n  split,\n  { refine (continuous_on_const.mul _).ae_strongly_measurable measurable_set_Ioc,\n    apply (continuous_of_real.comp continuous_neg.exp).continuous_on.mul,\n    apply continuous_at.continuous_on,\n    intros x hx,\n    refine (_ : continuous_at (\u03bb x:\u2102, x ^ (s - 1)) _).comp continuous_of_real.continuous_at,\n    apply continuous_at_cpow_const, rw of_real_re, exact or.inl hx.1, },\n  rw \u2190has_finite_integral_norm_iff,\n  simp_rw [norm_eq_abs, map_mul],\n  refine (((real.Gamma_integral_convergent hs).mono_set\n    Ioc_subset_Ioi_self).has_finite_integral.congr _).const_mul _,\n  rw [eventually_eq, ae_restrict_iff'],\n  { apply ae_of_all, intros x hx,\n    rw [abs_of_nonneg (exp_pos _).le,abs_cpow_eq_rpow_re_of_pos hx.1],\n    simp },\n  { exact measurable_set_Ioc},\nend\n\n/-- The recurrence relation for the indefinite version of the `\u0393` function. -/\nlemma partial_Gamma_add_one {s : \u2102} (hs: 0 < s.re) {X : \u211d} (hX : 0 \u2264 X) :\n  partial_Gamma (s + 1) X = s * partial_Gamma s X - (-X).exp * X ^ s :=\nbegin\n  rw [partial_Gamma, partial_Gamma, add_sub_cancel],\n  have F_der_I: (\u2200 (x:\u211d), (x \u2208 Ioo 0 X) \u2192 has_deriv_at (\u03bb x, (-x).exp * x ^ s : \u211d \u2192 \u2102)\n    ( -((-x).exp * x ^ s) + (-x).exp * (s * x ^ (s - 1))) x),\n  { intros x hx,\n    have d1 : has_deriv_at (\u03bb (y: \u211d), (-y).exp) (-(-x).exp) x,\n    { simpa using (has_deriv_at_neg x).exp },\n    have d2 : has_deriv_at (\u03bb (y : \u211d), \u2191y ^ s) (s * x ^ (s - 1)) x,\n    { have t := @has_deriv_at.cpow_const _ _ _ s (has_deriv_at_id \u2191x) _,\n      simpa only [mul_one] using t.comp_of_real,\n      simpa only [id.def, of_real_re, of_real_im,\n        ne.def, eq_self_iff_true, not_true, or_false, mul_one] using hx.1, },\n    simpa only [of_real_neg, neg_mul] using d1.of_real_comp.mul d2 },\n  have cont := (continuous_of_real.comp continuous_neg.exp).mul\n    (continuous_of_real_cpow_const hs),\n  have der_ible := (Gamma_integrand_deriv_integrable_A hs hX).add\n    (Gamma_integrand_deriv_integrable_B hs hX),\n  have int_eval := integral_eq_sub_of_has_deriv_at_of_le hX cont.continuous_on F_der_I der_ible,\n  -- We are basically done here but manipulating the output into the right form is fiddly.\n  apply_fun (\u03bb x:\u2102, -x) at int_eval,\n  rw [interval_integral.integral_add (Gamma_integrand_deriv_integrable_A hs hX)\n    (Gamma_integrand_deriv_integrable_B hs hX), interval_integral.integral_neg, neg_add, neg_neg]\n    at int_eval,\n  rw [eq_sub_of_add_eq int_eval, sub_neg_eq_add, neg_sub, add_comm, add_sub],\n  simp only [sub_left_inj, add_left_inj],\n  have : (\u03bb x, (-x).exp * (s * x ^ (s - 1)) : \u211d \u2192 \u2102) = (\u03bb x, s * (-x).exp * x ^ (s - 1) : \u211d \u2192 \u2102),\n  { ext1, ring,},\n  rw this,\n  have t := @integral_const_mul 0 X volume _ _ s (\u03bb x:\u211d, (-x).exp * x ^ (s - 1)),\n  dsimp at t, rw [\u2190t, of_real_zero, zero_cpow],\n  { rw [mul_zero, add_zero], congr', ext1, ring },\n  { contrapose! hs, rw [hs, zero_re] }\nend\n\n/-- The recurrence relation for the `\u0393` integral. -/\ntheorem Gamma_integral_add_one {s : \u2102} (hs: 0 < s.re) :\n  Gamma_integral (s + 1) = s * Gamma_integral s :=\nbegin\n  suffices : tendsto (s+1).partial_Gamma at_top (\ud835\udcdd $ s * Gamma_integral s),\n  { refine tendsto_nhds_unique _ this,\n    apply tendsto_partial_Gamma, rw [add_re, one_re], linarith, },\n  have : (\u03bb X:\u211d, s * partial_Gamma s X - X ^ s * (-X).exp) =\u1da0[at_top] (s+1).partial_Gamma,\n  { apply eventually_eq_of_mem (Ici_mem_at_top (0:\u211d)),\n    intros X hX,\n    rw partial_Gamma_add_one hs (mem_Ici.mp hX),\n    ring_nf, },\n  refine tendsto.congr' this _,\n  suffices : tendsto (\u03bb X, -X ^ s * (-X).exp : \u211d \u2192 \u2102) at_top (\ud835\udcdd 0),\n  { simpa using tendsto.add (tendsto.const_mul s (tendsto_partial_Gamma hs)) this },\n  rw tendsto_zero_iff_norm_tendsto_zero,\n  have : (\u03bb (e : \u211d), \u2016-(e:\u2102) ^ s * (-e).exp\u2016 ) =\u1da0[at_top] (\u03bb (e : \u211d), e ^ s.re * (-1 * e).exp ),\n  { refine eventually_eq_of_mem (Ioi_mem_at_top 0) _,\n    intros x hx, dsimp only,\n    rw [norm_eq_abs, map_mul, abs.map_neg, abs_cpow_eq_rpow_re_of_pos hx,\n      abs_of_nonneg (exp_pos(-x)).le, neg_mul, one_mul],},\n  exact (tendsto_congr' this).mpr (tendsto_rpow_mul_exp_neg_mul_at_top_nhds_0 _ _ zero_lt_one),\nend\n\nend Gamma_recurrence\n\n/-! Now we define `\u0393(s)` on the whole complex plane, by recursion. -/\n\nsection Gamma_def\n\n/-- The `n`th function in this family is `\u0393(s)` if `-n < s.re`, and junk otherwise. -/\nnoncomputable def Gamma_aux : \u2115 \u2192 (\u2102 \u2192 \u2102)\n| 0      := Gamma_integral\n| (n+1)  := \u03bb s:\u2102, (Gamma_aux n (s+1)) / s\n\nlemma Gamma_aux_recurrence1 (s : \u2102) (n : \u2115) (h1 : -s.re < \u2191n) :\n  Gamma_aux n s = Gamma_aux n (s+1) / s :=\nbegin\n  induction n with n hn generalizing s,\n  { simp only [nat.cast_zero, neg_lt_zero] at h1,\n    dsimp only [Gamma_aux], rw Gamma_integral_add_one h1,\n    rw [mul_comm, mul_div_cancel], contrapose! h1, rw h1,\n    simp },\n  { dsimp only [Gamma_aux],\n    have hh1 : -(s+1).re < n,\n    { rw [nat.succ_eq_add_one, nat.cast_add, nat.cast_one] at h1,\n      rw [add_re, one_re], linarith, },\n    rw \u2190(hn (s+1) hh1) }\nend\n\nlemma Gamma_aux_recurrence2 (s : \u2102) (n : \u2115) (h1 : -s.re < \u2191n) :\n  Gamma_aux n s = Gamma_aux (n+1) s :=\nbegin\n  cases n,\n  { simp only [nat.cast_zero, neg_lt_zero] at h1,\n    dsimp only [Gamma_aux],\n    rw [Gamma_integral_add_one h1, mul_div_cancel_left],\n    rintro rfl,\n    rw [zero_re] at h1,\n    exact h1.false },\n  { dsimp only [Gamma_aux],\n    have : (Gamma_aux n (s + 1 + 1)) / (s+1) = Gamma_aux n (s + 1),\n    { have hh1 : -(s+1).re < n,\n      { rw [nat.succ_eq_add_one, nat.cast_add, nat.cast_one] at h1,\n        rw [add_re, one_re], linarith, },\n      rw Gamma_aux_recurrence1 (s+1) n hh1, },\n    rw this },\nend\n\n/-- The `\u0393` function (of a complex variable `s`). -/\n@[pp_nodot] def Gamma (s : \u2102) : \u2102 := Gamma_aux \u230a1 - s.re\u230b\u208a s\n\nlemma Gamma_eq_Gamma_aux (s : \u2102) (n : \u2115) (h1 : -s.re < \u2191n) : Gamma s = Gamma_aux n s :=\nbegin\n  have u : \u2200 (k : \u2115), Gamma_aux (\u230a1 - s.re\u230b\u208a + k) s = Gamma s,\n  { intro k, induction k with k hk,\n    { simp [Gamma],},\n    { rw [\u2190hk, nat.succ_eq_add_one, \u2190add_assoc],\n      refine (Gamma_aux_recurrence2 s (\u230a1 - s.re\u230b\u208a + k) _).symm,\n      rw nat.cast_add,\n      have i0 := nat.sub_one_lt_floor (1 - s.re),\n      simp only [sub_sub_cancel_left] at i0,\n      refine lt_add_of_lt_of_nonneg i0 _,\n      rw [\u2190nat.cast_zero, nat.cast_le], exact nat.zero_le k, } },\n  convert (u $ n - \u230a1 - s.re\u230b\u208a).symm, rw nat.add_sub_of_le,\n  by_cases (0 \u2264 1 - s.re),\n  { apply nat.le_of_lt_succ,\n    exact_mod_cast lt_of_le_of_lt (nat.floor_le h) (by linarith : 1 - s.re < n + 1) },\n  { rw nat.floor_of_nonpos, linarith, linarith },\nend\n\n/-- The recurrence relation for the `\u0393` function. -/\ntheorem Gamma_add_one (s : \u2102) (h2 : s \u2260 0) : Gamma (s+1) = s * Gamma s :=\nbegin\n  let n := \u230a1 - s.re\u230b\u208a,\n  have t1 : -s.re < n,\n  { simpa only [sub_sub_cancel_left] using nat.sub_one_lt_floor (1 - s.re) },\n  have t2 : -(s+1).re < n,\n  { rw [add_re, one_re], linarith, },\n  rw [Gamma_eq_Gamma_aux s n t1, Gamma_eq_Gamma_aux (s+1) n t2, Gamma_aux_recurrence1 s n t1],\n  field_simp, ring,\nend\n\ntheorem Gamma_eq_integral {s : \u2102} (hs : 0 < s.re) : Gamma s = Gamma_integral s :=\nGamma_eq_Gamma_aux s 0 (by { norm_cast, linarith })\n\n\n\ntheorem Gamma_nat_eq_factorial (n : \u2115) : Gamma (n+1) = n! :=\nbegin\n  induction n with n hn,\n  { simpa using Gamma_one },\n  { rw (Gamma_add_one n.succ $ nat.cast_ne_zero.mpr $ nat.succ_ne_zero n),\n    simp only [nat.cast_succ, nat.factorial_succ, nat.cast_mul], congr, exact hn },\nend\n\n/-- At `0` the Gamma function is undefined; by convention we assign it the value `0`. -/\nlemma Gamma_zero : Gamma 0 = 0 :=\nby simp_rw [Gamma, zero_re, sub_zero, nat.floor_one, Gamma_aux, div_zero]\n\n/-- At `-n` for `n \u2208 \u2115`, the Gamma function is undefined; by convention we assign it the value 0. -/\nlemma Gamma_neg_nat_eq_zero (n : \u2115) : Gamma (-n) = 0 :=\nbegin\n  induction n with n IH,\n  { rw [nat.cast_zero, neg_zero, Gamma_zero] },\n  { have A : -(n.succ : \u2102) \u2260 0,\n    { rw [neg_ne_zero, nat.cast_ne_zero],\n      apply nat.succ_ne_zero },\n    have : -(n:\u2102) = -\u2191n.succ + 1, by simp,\n    rw [this, Gamma_add_one _ A] at IH,\n    contrapose! IH,\n    exact mul_ne_zero A IH }\nend\n\nlemma Gamma_conj (s : \u2102) : Gamma (conj s) = conj (Gamma s) :=\nbegin\n  suffices : \u2200 (n:\u2115) (s:\u2102) , Gamma_aux n (conj s) = conj (Gamma_aux n s), from this _ _,\n  intro n,\n  induction n with n IH,\n  { rw Gamma_aux, exact Gamma_integral_conj, },\n  { intro s,\n    rw Gamma_aux,\n    dsimp only,\n    rw [div_eq_mul_inv _ s, ring_hom.map_mul, conj_inv, \u2190div_eq_mul_inv],\n    suffices : conj s + 1 = conj (s + 1), by rw [this, IH],\n    rw [ring_hom.map_add, ring_hom.map_one] }\nend\n\nend Gamma_def\n\nend complex\n\n/-! Now check that the `\u0393` function is differentiable, wherever this makes sense. -/\n\nsection Gamma_has_deriv\n\n/-- Integrand for the derivative of the `\u0393` function -/\ndef dGamma_integrand (s : \u2102) (x : \u211d) : \u2102 := exp (-x) * log x * x ^ (s - 1)\n\n/-- Integrand for the absolute value of the derivative of the `\u0393` function -/\ndef dGamma_integrand_real (s x : \u211d) : \u211d := |exp (-x) * log x * x ^ (s - 1)|\n\nlemma dGamma_integrand_is_o_at_top (s : \u211d) :\n  (\u03bb x : \u211d, exp (-x) * log x * x ^ (s - 1)) =o[at_top] (\u03bb x, exp (-(1/2) * x)) :=\nbegin\n  refine is_o_of_tendsto (\u03bb x hx, _) _,\n  { exfalso, exact (-(1/2) * x).exp_pos.ne' hx, },\n  have : eventually_eq at_top (\u03bb (x : \u211d), exp (-x) * log x * x ^ (s - 1) / exp (-(1 / 2) * x))\n    (\u03bb (x : \u211d),  (\u03bb z:\u211d, exp (1 / 2 * z) / z ^ s) x * (\u03bb z:\u211d, z / log z) x)\u207b\u00b9,\n  { refine eventually_of_mem (Ioi_mem_at_top 1) _,\n    intros x hx, dsimp,\n    replace hx := lt_trans zero_lt_one (mem_Ioi.mp hx),\n    rw [real.exp_neg, neg_mul, real.exp_neg, rpow_sub hx],\n    have : exp x = exp(x/2) * exp(x/2),\n    { rw [\u2190real.exp_add, add_halves], },\n    rw this, field_simp [hx.ne', exp_ne_zero (x/2)], ring, },\n  refine tendsto.congr' this.symm (tendsto.inv_tendsto_at_top _),\n  apply tendsto.at_top_mul_at_top (tendsto_exp_mul_div_rpow_at_top s (1/2) one_half_pos),\n  refine tendsto.congr' _ ((tendsto_exp_div_pow_at_top 1).comp tendsto_log_at_top),\n  apply eventually_eq_of_mem (Ioi_mem_at_top (0:\u211d)),\n  intros x hx, simp [exp_log hx],\nend\n\n/-- Absolute convergence of the integral which will give the derivative of the `\u0393` function on\n`1 < re s`. -/\nlemma dGamma_integral_abs_convergent (s : \u211d) (hs : 1 < s) :\n  integrable_on (\u03bb x:\u211d, \u2016exp (-x) * log x * x ^ (s-1)\u2016) (Ioi 0) :=\nbegin\n  rw [\u2190Ioc_union_Ioi_eq_Ioi (@zero_le_one \u211d _ _ _ _), integrable_on_union],\n  refine \u27e8\u27e8_, _\u27e9, _\u27e9,\n  { refine continuous_on.ae_strongly_measurable (continuous_on.mul _ _).norm measurable_set_Ioc,\n    { refine (continuous_exp.comp continuous_neg).continuous_on.mul (continuous_on_log.mono _),\n      simp, },\n    { apply continuous_on_id.rpow_const, intros x hx, right, linarith }, },\n  { apply has_finite_integral_of_bounded,\n    swap, { exact 1 / (s - 1), },\n    refine (ae_restrict_iff' measurable_set_Ioc).mpr (ae_of_all _ (\u03bb x hx, _)),\n    rw [norm_norm, norm_eq_abs, mul_assoc, abs_mul, \u2190one_mul (1 / (s - 1))],\n    refine mul_le_mul _ _ (abs_nonneg _) zero_le_one,\n    { rw [abs_of_pos (exp_pos(-x)), exp_le_one_iff, neg_le, neg_zero], exact hx.1.le },\n    { exact (abs_log_mul_self_rpow_lt x (s-1) hx.1 hx.2 (sub_pos.mpr hs)).le }, },\n  { have := (dGamma_integrand_is_o_at_top s).is_O.norm_left,\n    refine integrable_of_is_O_exp_neg one_half_pos (continuous_on.mul _ _).norm this,\n    { refine (continuous_exp.comp continuous_neg).continuous_on.mul (continuous_on_log.mono _),\n      simp, },\n    { apply continuous_at.continuous_on (\u03bb x hx, _),\n      apply continuous_at_id.rpow continuous_at_const,\n      dsimp, right, linarith, }, }\nend\n\n/-- A uniform bound for the `s`-derivative of the `\u0393` integrand for `s` in vertical strips. -/\nlemma loc_unif_bound_dGamma_integrand {t : \u2102} {s1 s2 x : \u211d} (ht1 : s1 \u2264 t.re)\n  (ht2: t.re \u2264 s2) (hx : 0 < x) :\n  \u2016dGamma_integrand t x\u2016 \u2264 dGamma_integrand_real s1 x + dGamma_integrand_real s2 x :=\nbegin\n  rcases le_or_lt 1 x with h|h,\n  { -- case 1 \u2264 x\n    refine le_add_of_nonneg_of_le (abs_nonneg _) _,\n    rw [dGamma_integrand, dGamma_integrand_real, complex.norm_eq_abs, map_mul, abs_mul,\n      \u2190complex.of_real_mul, complex.abs_of_real],\n    refine mul_le_mul_of_nonneg_left _ (abs_nonneg _),\n    rw complex.abs_cpow_eq_rpow_re_of_pos hx,\n    refine le_trans _ (le_abs_self _),\n    apply rpow_le_rpow_of_exponent_le h,\n    rw [complex.sub_re, complex.one_re], linarith, },\n  { refine le_add_of_le_of_nonneg _ (abs_nonneg _),\n    rw [dGamma_integrand, dGamma_integrand_real, complex.norm_eq_abs, map_mul, abs_mul,\n      \u2190complex.of_real_mul, complex.abs_of_real],\n    refine mul_le_mul_of_nonneg_left _ (abs_nonneg _),\n    rw complex.abs_cpow_eq_rpow_re_of_pos hx,\n    refine le_trans _ (le_abs_self _),\n    apply rpow_le_rpow_of_exponent_ge hx h.le,\n    rw [complex.sub_re, complex.one_re], linarith, },\nend\n\nnamespace complex\n\n/-- The derivative of the `\u0393` integral, at any `s \u2208 \u2102` with `1 < re s`, is given by the integral\nof `exp (-x) * log x * x ^ (s - 1)` over `[0, \u221e)`. -/\ntheorem has_deriv_at_Gamma_integral {s : \u2102} (hs : 1 < s.re) :\n  (integrable_on (\u03bb x, real.exp (-x) * real.log x * x ^ (s - 1) : \u211d \u2192 \u2102) (Ioi 0) volume) \u2227\n  (has_deriv_at Gamma_integral (\u222b x:\u211d in Ioi 0, real.exp (-x) * real.log x * x ^ (s - 1)) s) :=\nbegin\n  let \u03b5 := (s.re - 1) / 2,\n  let \u03bc := volume.restrict (Ioi (0:\u211d)),\n  let bound := (\u03bb x:\u211d, dGamma_integrand_real (s.re - \u03b5) x + dGamma_integrand_real (s.re + \u03b5) x),\n  have cont : \u2200 (t : \u2102), continuous_on (\u03bb x, real.exp (-x) * x ^ (t - 1) : \u211d \u2192 \u2102) (Ioi 0),\n  { intro t, apply (continuous_of_real.comp continuous_neg.exp).continuous_on.mul,\n    apply continuous_at.continuous_on, intros x hx,\n    refine (continuous_at_cpow_const _).comp continuous_of_real.continuous_at,\n    exact or.inl hx, },\n  have eps_pos: 0 < \u03b5 := div_pos (sub_pos.mpr hs) zero_lt_two,\n  have hF_meas : \u2200\u1da0 (t : \u2102) in \ud835\udcdd s,\n    ae_strongly_measurable (\u03bb x, real.exp(-x) * x ^ (t - 1) : \u211d \u2192 \u2102) \u03bc,\n  { apply eventually_of_forall, intro t,\n    exact (cont t).ae_strongly_measurable measurable_set_Ioi, },\n  have hF'_meas : ae_strongly_measurable (dGamma_integrand s) \u03bc,\n  { refine continuous_on.ae_strongly_measurable _ measurable_set_Ioi,\n    have : dGamma_integrand s = (\u03bb x, real.exp (-x) * x ^ (s - 1) * real.log x : \u211d \u2192 \u2102),\n    { ext1, simp only [dGamma_integrand], ring },\n    rw this,\n    refine continuous_on.mul (cont s) (continuous_at.continuous_on _),\n    exact \u03bb x hx, continuous_of_real.continuous_at.comp (continuous_at_log (mem_Ioi.mp hx).ne'), },\n  have h_bound : \u2200\u1d50 (x : \u211d) \u2202\u03bc, \u2200 (t : \u2102), t \u2208 metric.ball s \u03b5 \u2192 \u2016 dGamma_integrand t x \u2016 \u2264 bound x,\n  { refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    intros t ht,\n    rw [metric.mem_ball, complex.dist_eq] at ht,\n    replace ht := lt_of_le_of_lt (complex.abs_re_le_abs $ t - s ) ht,\n    rw [complex.sub_re, @abs_sub_lt_iff \u211d _ t.re s.re ((s.re - 1) / 2) ] at ht,\n    refine loc_unif_bound_dGamma_integrand _ _ hx,\n    all_goals { simp only [\u03b5], linarith } },\n  have bound_integrable : integrable bound \u03bc,\n  { apply integrable.add,\n    { refine dGamma_integral_abs_convergent (s.re - \u03b5) _,\n      field_simp, rw one_lt_div,\n      { linarith }, { exact zero_lt_two }, },\n    { refine dGamma_integral_abs_convergent (s.re + \u03b5) _, linarith, }, },\n  have h_diff : \u2200\u1d50 (x : \u211d) \u2202\u03bc, \u2200 (t : \u2102), t \u2208 metric.ball s \u03b5\n    \u2192 has_deriv_at (\u03bb u, real.exp (-x) * x ^ (u - 1) : \u2102 \u2192 \u2102) (dGamma_integrand t x) t,\n  { refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    intros t ht, rw mem_Ioi at hx,\n    simp only [dGamma_integrand],\n    rw mul_assoc,\n    apply has_deriv_at.const_mul,\n    rw [of_real_log hx.le, mul_comm],\n    have := ((has_deriv_at_id t).sub_const 1).const_cpow (or.inl (of_real_ne_zero.mpr hx.ne')),\n    rwa mul_one at this },\n  exact (has_deriv_at_integral_of_dominated_loc_of_deriv_le eps_pos hF_meas\n    (Gamma_integral_convergent (zero_lt_one.trans hs)) hF'_meas h_bound bound_integrable h_diff),\nend\n\nlemma differentiable_at_Gamma_aux (s : \u2102) (n : \u2115) (h1 : (1 - s.re) < n ) (h2 : \u2200 m : \u2115, s \u2260 -m) :\n  differentiable_at \u2102 (Gamma_aux n) s :=\nbegin\n  induction n with n hn generalizing s,\n  { refine (has_deriv_at_Gamma_integral _).2.differentiable_at,\n    rw nat.cast_zero at h1, linarith },\n  { dsimp only [Gamma_aux],\n    specialize hn (s + 1),\n    have a : 1 - (s + 1).re < \u2191n,\n    { rw nat.cast_succ at h1, rw [complex.add_re, complex.one_re], linarith },\n    have b : \u2200 m : \u2115, s + 1 \u2260 -m,\n    { intro m, have := h2 (1 + m),\n      contrapose! this,\n      rw \u2190eq_sub_iff_add_eq at this,\n      simpa using this },\n    refine differentiable_at.div (differentiable_at.comp _ (hn a b) _) _ _,\n    simp, simp, simpa using h2 0 }\nend\n\ntheorem differentiable_at_Gamma (s : \u2102) (hs : \u2200 m : \u2115, s \u2260 -m) : differentiable_at \u2102 Gamma s :=\nbegin\n  let n := \u230a1 - s.re\u230b\u208a + 1,\n  have hn : 1 - s.re < n := by exact_mod_cast nat.lt_floor_add_one (1 - s.re),\n  apply (differentiable_at_Gamma_aux s n hn hs).congr_of_eventually_eq,\n  let S := { t : \u2102 | 1 - t.re < n },\n  have : S \u2208 \ud835\udcdd s,\n  { rw mem_nhds_iff, use S,\n    refine \u27e8subset.rfl, _, hn\u27e9,\n    have : S = re\u207b\u00b9' Ioi (1 - n : \u211d),\n    { ext, rw [preimage,Ioi, mem_set_of_eq, mem_set_of_eq, mem_set_of_eq], exact sub_lt_comm },\n    rw this,\n    refine continuous.is_open_preimage continuous_re _ is_open_Ioi, },\n  apply eventually_eq_of_mem this,\n  intros t ht, rw mem_set_of_eq at ht,\n  apply Gamma_eq_Gamma_aux, linarith,\nend\n\nend complex\n\nend Gamma_has_deriv\n\nnamespace real\n\n/-- The `\u0393` function (of a real variable `s`). -/\n@[pp_nodot] def Gamma (s : \u211d) : \u211d := (complex.Gamma s).re\n\nlemma Gamma_eq_integral {s : \u211d} (hs : 0 < s) : Gamma s = \u222b x in Ioi 0, exp (-x) * x ^ (s - 1) :=\nbegin\n  rw [Gamma, complex.Gamma_eq_integral (by rwa complex.of_real_re : 0 < complex.re s)],\n  dsimp only [complex.Gamma_integral],\n  simp_rw [\u2190complex.of_real_one, \u2190complex.of_real_sub],\n  suffices : \u222b (x : \u211d) in Ioi 0, \u2191(exp (-x)) * (x : \u2102) ^ ((s - 1 : \u211d) : \u2102) =\n    \u222b (x : \u211d) in Ioi 0, ((exp (-x) * x ^ (s - 1) : \u211d) : \u2102),\n  { rw [this, _root_.integral_of_real, complex.of_real_re], },\n  refine set_integral_congr measurable_set_Ioi (\u03bb x hx, _),\n  push_cast,\n  rw complex.of_real_cpow (le_of_lt hx),\n  push_cast,\nend\n\nlemma Gamma_add_one {s : \u211d} (hs : s \u2260 0) : Gamma (s + 1) = s * Gamma s :=\nbegin\n  simp_rw Gamma,\n  rw [complex.of_real_add, complex.of_real_one, complex.Gamma_add_one, complex.of_real_mul_re],\n  rwa complex.of_real_ne_zero,\nend\n\nlemma Gamma_one : Gamma 1 = 1 :=\nby rw [Gamma, complex.of_real_one, complex.Gamma_one, complex.one_re]\n\nlemma _root_.complex.Gamma_of_real (s : \u211d) : complex.Gamma (s : \u2102) = Gamma s :=\nby rw [Gamma, eq_comm, \u2190complex.eq_conj_iff_re, \u2190complex.Gamma_conj, complex.conj_of_real]\n\ntheorem Gamma_nat_eq_factorial (n : \u2115) : Gamma (n + 1) = n! :=\nby rw [Gamma, complex.of_real_add, complex.of_real_nat_cast, complex.of_real_one,\n  complex.Gamma_nat_eq_factorial, \u2190complex.of_real_nat_cast, complex.of_real_re]\n\n/-- At `0` the Gamma function is undefined; by convention we assign it the value `0`. -/\nlemma Gamma_zero : Gamma 0 = 0 :=\nby simpa only [\u2190complex.of_real_zero, complex.Gamma_of_real, complex.of_real_inj]\n  using complex.Gamma_zero\n\n/-- At `-n` for `n \u2208 \u2115`, the Gamma function is undefined; by convention we assign it the value `0`.\n-/\nlemma Gamma_neg_nat_eq_zero (n : \u2115) : Gamma (-n) = 0 :=\nbegin\n  simpa only [\u2190complex.of_real_nat_cast, \u2190complex.of_real_neg, complex.Gamma_of_real,\n    complex.of_real_eq_zero] using complex.Gamma_neg_nat_eq_zero n,\nend\n\nlemma Gamma_pos_of_pos {s : \u211d} (hs : 0 < s) : 0 < Gamma s :=\nbegin\n  rw Gamma_eq_integral hs,\n  have : function.support (\u03bb (x : \u211d), exp (-x) * x ^ (s - 1)) \u2229 Ioi 0 = Ioi 0,\n  { rw inter_eq_right_iff_subset,\n    intros x hx,\n    rw function.mem_support,\n    exact mul_ne_zero (exp_pos _).ne' (rpow_pos_of_pos hx _).ne' },\n  rw set_integral_pos_iff_support_of_nonneg_ae,\n  { rw [this, volume_Ioi, \u2190ennreal.of_real_zero],\n    exact ennreal.of_real_lt_top },\n  { refine eventually_of_mem (self_mem_ae_restrict measurable_set_Ioi) _,\n    exact \u03bb x hx, (mul_pos (exp_pos _) (rpow_pos_of_pos hx _)).le },\n  { exact Gamma_integral_convergent hs },\nend\n\n/-- The Gamma function does not vanish on `\u211d` (except at non-positive integers, where the function\nis mathematically undefined and we set it to `0` by convention). -/\nlemma Gamma_ne_zero {s : \u211d} (hs : \u2200 m : \u2115, s \u2260 -m) : Gamma s \u2260 0 :=\nbegin\n  suffices : \u2200 {n : \u2115}, (-(n:\u211d) < s) \u2192 Gamma s \u2260 0,\n  { apply this,\n    swap, use (\u230a-s\u230b\u208a + 1),\n    rw [neg_lt, nat.cast_add, nat.cast_one],\n    exact nat.lt_floor_add_one _ },\n  intro n,\n  induction n generalizing s,\n  { intro hs,\n    refine (Gamma_pos_of_pos _).ne',\n    rwa [nat.cast_zero, neg_zero] at hs },\n  { intro hs',\n    have : Gamma (s + 1) \u2260 0,\n    { apply n_ih,\n      { intro m,\n        specialize hs (1 + m),\n        contrapose! hs,\n        rw \u2190eq_sub_iff_add_eq at hs,\n        rw hs,\n        push_cast,\n        ring },\n      { rw [nat.succ_eq_add_one, nat.cast_add, nat.cast_one, neg_add] at hs',\n        linarith }  },\n    rw [Gamma_add_one, mul_ne_zero_iff] at this,\n    { exact this.2 },\n    { simpa using hs 0 } },\nend\n\nlemma Gamma_eq_zero_iff (s : \u211d) : Gamma s = 0 \u2194 \u2203 m : \u2115, s = -m :=\n\u27e8by { contrapose!, exact Gamma_ne_zero }, by { rintro \u27e8m, rfl\u27e9, exact Gamma_neg_nat_eq_zero m }\u27e9\n\nlemma differentiable_at_Gamma {s : \u211d} (hs : \u2200 m : \u2115, s \u2260 -m) : differentiable_at \u211d Gamma s :=\nbegin\n  refine ((complex.differentiable_at_Gamma _ _).has_deriv_at).real_of_complex.differentiable_at,\n  simp_rw [\u2190complex.of_real_nat_cast, \u2190complex.of_real_neg, ne.def, complex.of_real_inj],\n  exact hs,\nend\n\n/-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form),\nproved using the H\u00f6lder inequality applied to Euler's integral. -/\nlemma Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : \u211d}\n  (hs : 0 < s) (ht : 0 < t) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :\n  Gamma (a * s + b * t) \u2264 Gamma s ^ a * Gamma t ^ b :=\nbegin\n  -- We will apply H\u00f6lder's inequality, for the conjugate exponents `p = 1 / a`\n  -- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows:\n  let f : \u211d \u2192 \u211d \u2192 \u211d \u2192 \u211d := \u03bb c u x, exp (-c * x) * x ^ (c * (u - 1)),\n  have e : is_conjugate_exponent (1 / a) (1 / b) := real.is_conjugate_exponent_one_div ha hb hab,\n  have hab' : b = 1 - a := by linarith,\n  have hst : 0 < a * s + b * t := add_pos (mul_pos ha hs) (mul_pos hb ht),\n  -- some properties of f:\n  have posf : \u2200 (c u x : \u211d), x \u2208 Ioi (0:\u211d) \u2192 0 \u2264 f c u x :=\n    \u03bb c u x hx, mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le,\n  have posf' : \u2200 (c u : \u211d), \u2200\u1d50 (x : \u211d) \u2202volume.restrict (Ioi 0), 0 \u2264 f c u x :=\n    \u03bb c u, (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (posf c u)),\n  have fpow : \u2200 {c x : \u211d} (hc : 0 < c) (u : \u211d) (hx : 0 < x),\n    exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c),\n  { intros c x hc u hx,\n    dsimp only [f],\n    rw [mul_rpow (exp_pos _).le ((rpow_nonneg_of_nonneg hx.le) _), \u2190exp_mul, \u2190rpow_mul hx.le],\n    congr' 2;\n    { field_simp [hc.ne'], ring } },\n  -- show `f c u` is in `\u2112p` for `p = 1/c`:\n  have f_mem_Lp : \u2200 {c u : \u211d} (hc : 0 < c) (hu : 0 < u),\n    mem_\u2112p (f c u) (ennreal.of_real (1 / c)) (volume.restrict (Ioi 0)),\n  { intros c u hc hu,\n    have A : ennreal.of_real (1 / c) \u2260 0,\n      by rwa [ne.def, ennreal.of_real_eq_zero, not_le, one_div_pos],\n    have B : ennreal.of_real (1 / c) \u2260 \u221e, from ennreal.of_real_ne_top,\n    rw [\u2190mem_\u2112p_norm_rpow_iff _ A B, ennreal.to_real_of_real (one_div_nonneg.mpr hc.le),\n      ennreal.div_self A B, mem_\u2112p_one_iff_integrable],\n    { apply integrable.congr (Gamma_integral_convergent hu),\n      refine eventually_eq_of_mem (self_mem_ae_restrict measurable_set_Ioi) (\u03bb x hx, _),\n      dsimp only,\n      rw fpow hc u hx,\n      congr' 1,\n      exact (norm_of_nonneg (posf _ _ x hx)).symm },\n    { refine continuous_on.ae_strongly_measurable _ measurable_set_Ioi,\n      refine (continuous.continuous_on _).mul (continuous_at.continuous_on (\u03bb x hx, _)),\n      { exact continuous_exp.comp (continuous_const.mul continuous_id'), },\n      { exact continuous_at_rpow_const _ _ (or.inl (ne_of_lt hx).symm), } } },\n  -- now apply H\u00f6lder:\n  rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst],\n  convert measure_theory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t)\n    (f_mem_Lp ha hs) (f_mem_Lp hb ht) using 1,\n  { refine set_integral_congr measurable_set_Ioi (\u03bb x hx, _),\n    dsimp only [f],\n    have A : exp (-x) = exp (-a * x) * exp (-b * x),\n    { rw [\u2190exp_add, \u2190add_mul, \u2190neg_add, hab, neg_one_mul] },\n    have B : x ^ (a * s + b * t - 1) = (x ^ (a * (s - 1))) * (x ^ (b * (t - 1))),\n    { rw [\u2190rpow_add hx, hab'], congr' 1, ring },\n    rw [A, B],\n    ring },\n  { rw [one_div_one_div, one_div_one_div],\n    congr' 2;\n    exact set_integral_congr measurable_set_Ioi (\u03bb x hx, fpow (by assumption) _ hx) },\nend\n\nlemma convex_on_log_Gamma : convex_on \u211d (Ioi 0) (log \u2218 Gamma) :=\nbegin\n  refine convex_on_iff_forall_pos.mpr \u27e8convex_Ioi _, \u03bb x hx y hy a b ha hb hab, _\u27e9,\n  have : b = 1 - a := by linarith, subst this,\n  simp_rw [function.comp_app, smul_eq_mul],\n  rw [\u2190log_rpow (Gamma_pos_of_pos hy), \u2190log_rpow (Gamma_pos_of_pos hx),\n    \u2190log_mul\n      ((rpow_pos_of_pos (Gamma_pos_of_pos hx) _).ne') (rpow_pos_of_pos (Gamma_pos_of_pos hy) _).ne',\n    log_le_log\n      (Gamma_pos_of_pos (add_pos (mul_pos ha hx) (mul_pos hb hy)))\n      (mul_pos\n        (rpow_pos_of_pos (Gamma_pos_of_pos hx) _) (rpow_pos_of_pos (Gamma_pos_of_pos hy) _))],\n  exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab,\nend\n\nlemma convex_on_Gamma : convex_on \u211d (Ioi 0) Gamma :=\nbegin\n  refine \u27e8convex_Ioi 0, \u03bb x hx y hy a b ha hb hab, _\u27e9,\n  have := convex_on.comp (convex_on_exp.subset (subset_univ _) _) convex_on_log_Gamma\n    (\u03bb u hu v hv huv, exp_le_exp.mpr huv),\n  convert this.2 hx hy ha hb hab,\n  { rw [function.comp_app, exp_log (Gamma_pos_of_pos $ this.1 hx hy ha hb hab)] },\n  { rw [function.comp_app, exp_log (Gamma_pos_of_pos hx)] },\n  { rw [function.comp_app, exp_log (Gamma_pos_of_pos hy)] },\n  { rw convex_iff_is_preconnected,\n    refine is_preconnected_Ioi.image _ (\u03bb x hx, continuous_at.continuous_within_at _),\n    refine (differentiable_at_Gamma (\u03bb m, _)).continuous_at.log (Gamma_pos_of_pos hx).ne',\n    exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg hx (nat.cast_nonneg m))).ne' }\nend\n\nsection bohr_mollerup\n\n/-! ## The Bohr-Mollerup theorem\n\nIn this section we prove two interrelated statements about the `\u0393` function on the positive reals:\n\n* the Euler limit formula `real.bohr_mollerup.tendsto_log_gamma_seq`, stating that for positive\n  real `x` the sequence `x * log n + log n! - \u2211 (m : \u2115) in finset.range (n + 1), log (x + m)`\n  tends to `log \u0393(x)` as `n \u2192 \u221e`.\n* the Bohr-Mollerup theorem (`real.eq_Gamma_of_log_convex`) which states that `\u0393` is the unique\n  *log-convex*, positive-real-valued function on the positive reals satisfying\n  `f (x + 1) = x f x` and `f 1 = 1`.\n\nTo do this, we prove that any function satisfying the hypotheses of the Bohr--Mollerup theorem must\nagree with the limit in the Euler limit formula, so there is at most one such function. Then we\nshow that `\u0393` satisfies these conditions.\n\nSince most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the\ncontext of this proof, we place them in a separate namespace `real.bohr_mollerup` to avoid clutter.\n(This includes the logarithmic form of the Euler limit formula, since later we will prove a more\ngeneral form of the Euler limit formula valid for any real or complex `x`; see\n`real.Gamma_seq_tendsto_Gamma` and `complex.Gamma_seq_tendsto_Gamma`.)\n-/\n\nnamespace bohr_mollerup\n\n/-- The function `n \u21a6 x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to\n`log (Gamma x)` as `n \u2192 \u221e`. -/\ndef log_gamma_seq (x : \u211d) (n : \u2115) : \u211d :=\nx * log n + log n! - \u2211 (m : \u2115) in finset.range (n + 1), log (x + m)\n\nvariables {f : \u211d \u2192 \u211d} {x : \u211d} {n : \u2115}\n\nlemma f_nat_eq (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y) (hn : n \u2260 0) :\n  f n = f 1 + log (n - 1)! :=\nbegin\n  refine nat.le_induction (by simp) (\u03bb m hm IH, _) n (nat.one_le_iff_ne_zero.2 hn),\n  have A : 0 < (m : \u211d), from nat.cast_pos.2 hm,\n  simp only [hf_feq A, nat.cast_add, algebra_map.coe_one, nat.add_succ_sub_one, add_zero],\n  rw [IH, add_assoc, \u2190 log_mul (nat.cast_ne_zero.mpr (nat.factorial_ne_zero _)) A.ne',\n    \u2190 nat.cast_mul],\n  conv_rhs { rw [\u2190 nat.succ_pred_eq_of_pos hm, nat.factorial_succ, mul_comm] },\n  congr,\n  exact (nat.succ_pred_eq_of_pos hm).symm\nend\n\nlemma f_add_nat_eq (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y) (hx : 0 < x) (n : \u2115) :\n  f (x + n) = f x + \u2211 (m : \u2115) in finset.range n, log (x + m) :=\nbegin\n  induction n with n hn,\n  { simp },\n  { have : x + n.succ = (x + n) + 1,\n    { push_cast, ring },\n    rw [this, hf_feq, hn],\n    rw [finset.range_succ, finset.sum_insert (finset.not_mem_range_self)],\n    abel,\n    linarith [(nat.cast_nonneg n : 0 \u2264 (n:\u211d))] },\nend\n\n/-- Linear upper bound for `f (x + n)` on unit interval -/\nlemma f_add_nat_le\n  (hf_conv : convex_on \u211d (Ioi 0) f) (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y)\n  (hn : n \u2260 0) (hx : 0 < x) (hx' : x \u2264 1) :\n  f (n + x) \u2264 f n + x * log n :=\nbegin\n  have hn': 0 < (n:\u211d) := nat.cast_pos.mpr (nat.pos_of_ne_zero hn),\n  have : f n + x * log n = (1 - x) * f n + x * f (n + 1),\n  { rw [hf_feq hn'], ring, },\n  rw [this, (by ring : (n:\u211d) + x = (1 - x) * n + x * (n + 1))],\n  simpa only [smul_eq_mul] using hf_conv.2 hn' (by linarith : 0 < (n + 1 : \u211d))\n    (by linarith : 0 \u2264 1 - x) hx.le (by linarith),\nend\n\n/-- Linear lower bound for `f (x + n)` on unit interval -/\nlemma f_add_nat_ge\n  (hf_conv : convex_on \u211d (Ioi 0) f) (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y)\n  (hn : 2 \u2264 n) (hx : 0 < x) :\n  f n + x * log (n - 1) \u2264 f (n + x) :=\nbegin\n  have npos : 0 < (n:\u211d) - 1,\n  { rw [\u2190nat.cast_one, sub_pos, nat.cast_lt], linarith, },\n  have c := (convex_on_iff_slope_mono_adjacent.mp $ hf_conv).2\n    npos (by linarith : 0 < (n:\u211d) + x) (by linarith : (n:\u211d) - 1 < (n:\u211d)) (by linarith),\n  rw [add_sub_cancel', sub_sub_cancel, div_one] at c,\n  have : f (\u2191n - 1) = f n - log (\u2191n - 1),\n  { nth_rewrite_rhs 0 (by ring : (n:\u211d) = (\u2191n - 1) + 1),\n    rw [hf_feq npos, add_sub_cancel] },\n  rwa [this, le_div_iff hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c,\nend\n\nlemma log_gamma_seq_add_one (x : \u211d) (n : \u2115) :\n  log_gamma_seq (x + 1) n = log_gamma_seq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) :=\nbegin\n  dsimp only [nat.factorial_succ, log_gamma_seq],\n  conv_rhs { rw [finset.sum_range_succ', nat.cast_zero, add_zero],  },\n  rw [nat.cast_mul, log_mul], rotate,\n  { rw nat.cast_ne_zero, exact nat.succ_ne_zero n },\n  { rw nat.cast_ne_zero, exact nat.factorial_ne_zero n, },\n  have : \u2211 (m : \u2115) in finset.range (n + 1), log (x + 1 + \u2191m) =\n    \u2211 (k : \u2115) in finset.range (n + 1), log (x + \u2191(k + 1)),\n  { refine finset.sum_congr (by refl) (\u03bb m hm, _),\n    congr' 1,\n    push_cast,\n    abel },\n  rw [\u2190this, nat.cast_add_one n],\n  ring,\nend\n\nlemma le_log_gamma_seq\n  (hf_conv : convex_on \u211d (Ioi 0) f) (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y)\n  (hx : 0 < x) (hx' : x \u2264 1) (n : \u2115) :\n  f x \u2264 f 1 + x * log (n + 1) - x * log n + log_gamma_seq x n :=\nbegin\n  rw [log_gamma_seq, \u2190add_sub_assoc, le_sub_iff_add_le, \u2190f_add_nat_eq @hf_feq hx, add_comm x],\n  refine (f_add_nat_le hf_conv @hf_feq (nat.add_one_ne_zero n) hx hx').trans (le_of_eq _),\n  rw [f_nat_eq @hf_feq (by linarith : n + 1 \u2260 0), nat.add_sub_cancel, nat.cast_add_one],\n  ring,\nend\n\nlemma ge_log_gamma_seq\n  (hf_conv : convex_on \u211d (Ioi 0) f) (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y)\n  (hx : 0 < x) (hn : n \u2260 0) :\n  f 1 + log_gamma_seq x n \u2264 f x :=\nbegin\n  dsimp [log_gamma_seq],\n  rw [\u2190add_sub_assoc, sub_le_iff_le_add, \u2190f_add_nat_eq @hf_feq hx, add_comm x _],\n  refine le_trans (le_of_eq _) (f_add_nat_ge hf_conv @hf_feq _ hx),\n  { rw [f_nat_eq @hf_feq, nat.add_sub_cancel, nat.cast_add_one, add_sub_cancel],\n    { ring },\n    { exact nat.succ_ne_zero _} },\n  { apply nat.succ_le_succ,\n    linarith [nat.pos_of_ne_zero hn] },\nend\n\nlemma tendsto_log_gamma_seq_of_le_one\n  (hf_conv : convex_on \u211d (Ioi 0) f) (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y)\n  (hx : 0 < x) (hx' : x \u2264 1) :\n  tendsto (log_gamma_seq x) at_top (\ud835\udcdd $ f x - f 1) :=\nbegin\n  refine tendsto_of_tendsto_of_tendsto_of_le_of_le' _ tendsto_const_nhds _ _,\n  show \u2200\u1da0 (n : \u2115) in at_top, log_gamma_seq x n \u2264 f x - f 1,\n  { refine eventually.mp (eventually_ne_at_top 0) (eventually_of_forall (\u03bb n hn, _)),\n    exact le_sub_iff_add_le'.mpr (ge_log_gamma_seq hf_conv @hf_feq hx hn) },\n  show \u2200\u1da0 (n : \u2115) in at_top, f x - f 1 - x * (log (n + 1) - log n) \u2264 log_gamma_seq x n,\n  { refine eventually_of_forall (\u03bb n, _),\n    rw [sub_le_iff_le_add', sub_le_iff_le_add'],\n    convert le_log_gamma_seq hf_conv @hf_feq hx hx' n using 1,\n    ring },\n  { have : f x - f 1 = (f x - f 1) - x * 0 := by ring,\n    nth_rewrite 0 this,\n    exact tendsto.sub tendsto_const_nhds (tendsto_log_nat_add_one_sub_log.const_mul _), }\nend\n\nlemma tendsto_log_gamma_seq\n  (hf_conv : convex_on \u211d (Ioi 0) f) (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = f y + log y)\n  (hx : 0 < x) :\n  tendsto (log_gamma_seq x) at_top (\ud835\udcdd $ f x - f 1) :=\nbegin\n  suffices : \u2200 (m : \u2115), \u2191m < x \u2192 x \u2264 m + 1 \u2192\n    tendsto (log_gamma_seq x) at_top (\ud835\udcdd $ f x - f 1),\n  { refine this (\u2308x - 1\u2309\u208a) _ _,\n    { rcases lt_or_le x 1,\n      { rwa [nat.ceil_eq_zero.mpr (by linarith : x - 1 \u2264 0), nat.cast_zero] },\n      { convert nat.ceil_lt_add_one (by linarith : 0 \u2264 x - 1),\n        abel } },\n    { rw \u2190sub_le_iff_le_add, exact nat.le_ceil _}, },\n  intro m,\n  induction m with m hm generalizing x,\n  { rw [nat.cast_zero, zero_add],\n    exact \u03bb _ hx', tendsto_log_gamma_seq_of_le_one hf_conv @hf_feq hx hx' },\n  { intros hy hy',\n    rw [nat.cast_succ, \u2190sub_le_iff_le_add] at hy',\n    rw [nat.cast_succ, \u2190lt_sub_iff_add_lt] at hy,\n    specialize hm ((nat.cast_nonneg _).trans_lt hy) hy hy',\n    -- now massage gauss_product n (x - 1) into gauss_product (n - 1) x\n    have : \u2200\u1da0 (n:\u2115) in at_top, log_gamma_seq (x - 1) n = log_gamma_seq x (n - 1) +\n      x * (log (\u2191(n - 1) + 1) - log \u2191(n - 1)) - log (x - 1),\n    { refine eventually.mp (eventually_ge_at_top 1) (eventually_of_forall (\u03bb n hn, _)),\n      have := log_gamma_seq_add_one (x - 1) (n - 1),\n      rw [sub_add_cancel, nat.sub_add_cancel hn] at this,\n      rw this,\n      ring },\n    replace hm := ((tendsto.congr' this hm).add\n      (tendsto_const_nhds : tendsto (\u03bb _, log (x - 1)) _ _)).comp (tendsto_add_at_top_nat 1),\n    have :\n      (\u03bb (x_1 : \u2115), (\u03bb (n : \u2115), log_gamma_seq x (n - 1) +\n      x * (log (\u2191(n - 1) + 1) - log \u2191(n - 1)) - log (x - 1)) x_1 +\n      (\u03bb (b : \u2115), log (x - 1)) x_1) \u2218 (\u03bb (a : \u2115), a + 1) =\n      \u03bb n, log_gamma_seq x n + x * (log (\u2191n + 1) - log \u2191n),\n    { ext1 n,\n      dsimp only [function.comp_app],\n      rw [sub_add_cancel, nat.add_sub_cancel] },\n    rw this at hm,\n    convert hm.sub (tendsto_log_nat_add_one_sub_log.const_mul x) using 2,\n    { ext1 n, ring },\n    { have := hf_feq ((nat.cast_nonneg m).trans_lt hy),\n      rw sub_add_cancel at this,\n      rw this,\n      ring } },\nend\n\nlemma tendsto_log_Gamma {x : \u211d} (hx : 0 < x) :\n  tendsto (log_gamma_seq x) at_top (\ud835\udcdd $ log (Gamma x)) :=\nbegin\n  have : log (Gamma x) = (log \u2218 Gamma) x - (log \u2218 Gamma) 1,\n  { simp_rw [function.comp_app, Gamma_one, log_one, sub_zero] },\n  rw this,\n  refine bohr_mollerup.tendsto_log_gamma_seq convex_on_log_Gamma (\u03bb y hy, _) hx,\n  rw [function.comp_app, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm],\nend\n\nend bohr_mollerup -- (namespace)\n\n/-- The **Bohr-Mollerup theorem**: the Gamma function is the *unique* log-convex, positive-valued\nfunction on the positive reals which satisfies `f 1 = 1` and `f (x + 1) = x * f x` for all `x`. -/\nlemma eq_Gamma_of_log_convex {f : \u211d \u2192 \u211d}\n  (hf_conv : convex_on \u211d (Ioi 0) (log \u2218 f))\n  (hf_feq : \u2200 {y:\u211d}, 0 < y \u2192 f (y + 1) = y * f y)\n  (hf_pos : \u2200 {y:\u211d}, 0 < y \u2192 0 < f y)\n  (hf_one : f 1 = 1) :\n  eq_on f Gamma (Ioi (0:\u211d)) :=\nbegin\n  suffices : eq_on (log \u2218 f) (log \u2218 Gamma) (Ioi (0:\u211d)),\n    from \u03bb x hx, log_inj_on_pos (hf_pos hx) (Gamma_pos_of_pos hx) (this hx),\n  intros x hx,\n  have e1 := bohr_mollerup.tendsto_log_gamma_seq hf_conv _ hx,\n  { rw [function.comp_app log f 1, hf_one, log_one, sub_zero] at e1,\n    exact tendsto_nhds_unique e1 (bohr_mollerup.tendsto_log_Gamma hx) },\n  { intros y hy,\n    rw [function.comp_app, hf_feq hy, log_mul hy.ne' (hf_pos hy).ne'],\n    ring }\nend\n\nend bohr_mollerup -- (section)\n\nsection strict_mono\n\nlemma Gamma_two : Gamma 2 = 1 := by simpa using Gamma_nat_eq_factorial 1\n\nlemma Gamma_three_div_two_lt_one : Gamma (3 / 2) < 1 :=\nbegin\n  -- This can also be proved using the closed-form evaluation of `Gamma (1 / 2)` in\n  -- `analysis.special_functions.gaussian`, but we give a self-contained proof using log-convexity\n  -- to avoid unnecessary imports.\n  have A : (0:\u211d) < 3/2, by norm_num,\n  have := bohr_mollerup.f_add_nat_le convex_on_log_Gamma (\u03bb y hy, _) two_ne_zero one_half_pos\n    (by norm_num : 1/2 \u2264 (1:\u211d)),\n  swap, { rw [function.comp_app, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne',\n    add_comm] },\n  rw [function.comp_app, function.comp_app, nat.cast_two, Gamma_two, log_one, zero_add,\n    (by norm_num : (2:\u211d) + 1/2 = 3/2 + 1), Gamma_add_one A.ne',\n    log_mul A.ne' (Gamma_pos_of_pos A).ne', \u2190le_sub_iff_add_le',\n    log_le_iff_le_exp (Gamma_pos_of_pos A)] at this,\n  refine this.trans_lt (exp_lt_one_iff.mpr _),\n  rw [mul_comm, \u2190mul_div_assoc, div_sub' _ _ (2:\u211d) two_ne_zero],\n  refine div_neg_of_neg_of_pos _ two_pos,\n  rw [sub_neg, mul_one, \u2190nat.cast_two, \u2190log_pow, \u2190exp_lt_exp, nat.cast_two, exp_log two_pos,\n    exp_log];\n  norm_num,\nend\n\nlemma Gamma_strict_mono_on_Ici : strict_mono_on Gamma (Ici 2) :=\nbegin\n  convert convex_on_Gamma.strict_mono_of_lt (by norm_num : (0:\u211d) < 3/2)\n    (by norm_num : (3/2 : \u211d) < 2) (Gamma_two.symm \u25b8 Gamma_three_div_two_lt_one),\n  symmetry,\n  rw inter_eq_right_iff_subset,\n  exact \u03bb x hx, two_pos.trans_le hx,\nend\n\nend strict_mono\n\nend real\n\nsection beta_integral\n\n/-! ## The Beta function -/\n\nnamespace complex\n\nnotation `cexp` := complex.exp\n\n/-- The Beta function `\u0392 (u, v)`, defined as `\u222b x:\u211d in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/\nnoncomputable def beta_integral (u v : \u2102) : \u2102 :=\n\u222b (x:\u211d) in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)\n\n/-- Auxiliary lemma for `beta_integral_convergent`, showing convergence at the left endpoint. -/\nlemma beta_integral_convergent_left {u : \u2102} (hu : 0 < re u) (v : \u2102) :\n  interval_integrable (\u03bb x, x ^ (u - 1) * (1 - x) ^ (v - 1) : \u211d \u2192 \u2102) volume 0 (1 / 2) :=\nbegin\n  apply interval_integrable.mul_continuous_on,\n  { refine interval_integral.interval_integrable_cpow' _,\n    rwa [sub_re, one_re, \u2190zero_sub, sub_lt_sub_iff_right] },\n  { apply continuous_at.continuous_on,\n    intros x hx,\n    rw uIcc_of_le (by positivity: (0:\u211d) \u2264 1/2) at hx,\n    apply continuous_at.cpow,\n    { exact (continuous_const.sub continuous_of_real).continuous_at },\n    { exact continuous_at_const },\n    { rw [sub_re, one_re, of_real_re, sub_pos],\n      exact or.inl (hx.2.trans_lt (by norm_num : (1/2:\u211d) < 1)) } }\nend\n\n/-- The Beta integral is convergent for all `u, v` of positive real part. -/\nlemma beta_integral_convergent {u v : \u2102} (hu : 0 < re u) (hv : 0 < re v) :\n  interval_integrable (\u03bb x, x ^ (u - 1) * (1 - x) ^ (v - 1) : \u211d \u2192 \u2102) volume 0 1 :=\nbegin\n  refine (beta_integral_convergent_left hu v).trans _,\n  rw interval_integrable.iff_comp_neg,\n  convert ((beta_integral_convergent_left hv u).comp_add_right 1).symm,\n  { ext1 x,\n    conv_lhs { rw mul_comm },\n    congr' 2;\n    { push_cast, ring } },\n  { norm_num },\n  { norm_num }\nend\n\nlemma beta_integral_symm (u v : \u2102) :\n  beta_integral v u = beta_integral u v :=\nbegin\n  rw [beta_integral, beta_integral],\n  have := interval_integral.integral_comp_mul_add\n    (\u03bb x:\u211d, (x:\u2102) ^ (u - 1) * (1 - \u2191x) ^ (v - 1)) (neg_one_lt_zero.ne) 1,\n  rw [inv_neg, inv_one, neg_one_smul, \u2190interval_integral.integral_symm] at this,\n  convert this,\n  { ext1 x, rw mul_comm, congr;\n    { push_cast, ring } },\n  { ring }, { ring }\nend\n\nlemma beta_integral_eval_one_right {u : \u2102} (hu : 0 < re u) :\n  beta_integral u 1 = 1 / u :=\nbegin\n  simp_rw [beta_integral, sub_self, cpow_zero, mul_one],\n  rw integral_cpow (or.inl _),\n  { rw [of_real_zero, of_real_one, one_cpow, zero_cpow,\n    sub_zero, sub_add_cancel],\n    rw sub_add_cancel,\n    contrapose! hu, rw [hu, zero_re] },\n  { rwa [sub_re, one_re, \u2190sub_pos, sub_neg_eq_add, sub_add_cancel] },\nend\n\nlemma beta_integral_scaled (s t : \u2102) {a : \u211d} (ha : 0 < a) :\n  \u222b x in 0..a, (x:\u2102) ^ (s - 1) * (a - x) ^ (t - 1) = a ^ (s + t - 1) * beta_integral s t :=\nbegin\n  have ha' : (a:\u2102) \u2260 0, from of_real_ne_zero.mpr ha.ne',\n  rw beta_integral,\n  have A : (a:\u2102) ^ (s + t - 1) = a * (a ^ (s - 1) * a ^ (t - 1)),\n  { rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)),\n      cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one, mul_assoc] },\n  rw [A, mul_assoc, \u2190interval_integral.integral_const_mul ((\u2191a) ^ _ * _),\n    \u2190real_smul, \u2190(zero_div a), \u2190div_self ha.ne',\n    \u2190interval_integral.integral_comp_div _ ha.ne', zero_div],\n  simp_rw interval_integral.integral_of_le ha.le,\n  refine set_integral_congr measurable_set_Ioc (\u03bb x hx, _),\n  dsimp only,\n  rw mul_mul_mul_comm,\n  congr' 1,\n  { rw [\u2190mul_cpow_of_real_nonneg ha.le (div_pos hx.1 ha).le, of_real_div, mul_div_cancel' _ ha'] },\n  { rw [(by push_cast : (1:\u2102) - \u2191(x / a) = \u2191(1 - x / a)),\n      \u2190mul_cpow_of_real_nonneg ha.le (sub_nonneg.mpr $ (div_le_one ha).mpr hx.2)],\n    push_cast,\n    rw [mul_sub, mul_one, mul_div_cancel' _ ha'] }\nend\n\n/-- Relation between Beta integral and Gamma function.  -/\nlemma Gamma_mul_Gamma_eq_beta_integral {s t : \u2102} (hs : 0 < re s) (ht : 0 < re t) :\n  Gamma s * Gamma t = Gamma (s + t) * beta_integral s t :=\nbegin\n  -- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate\n  -- this as a formula for the Beta function.\n  have conv_int := integral_pos_convolution (Gamma_integral_convergent hs)\n    (Gamma_integral_convergent ht) (continuous_linear_map.mul \u211d \u2102),\n  simp_rw continuous_linear_map.mul_apply' at conv_int,\n  have hst : 0 < re (s + t),\n  { rw add_re, exact add_pos hs ht },\n  rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, Gamma_integral,\n    Gamma_integral, Gamma_integral, \u2190conv_int, \u2190integral_mul_right (beta_integral _ _)],\n  refine set_integral_congr measurable_set_Ioi (\u03bb x hx, _),\n  dsimp only,\n  rw [mul_assoc, \u2190beta_integral_scaled s t hx, \u2190interval_integral.integral_const_mul],\n  congr' 1 with y:1,\n  push_cast,\n  suffices : cexp (-x) = cexp (-y) * cexp (-(x - y)),\n  { rw this, ring },\n  { rw \u2190complex.exp_add, congr' 1, abel },\nend\n\n/-- Recurrence formula for the Beta function. -/\nlemma beta_integral_recurrence {u v : \u2102} (hu : 0 < re u) (hv : 0 < re v) :\n  u * beta_integral u (v + 1) = v * beta_integral (u + 1) v :=\nbegin\n  -- NB: If we knew `Gamma (u + v + 1) \u2260 0` this would be an easy consequence of\n  -- `Gamma_mul_Gamma_eq_beta_integral`; but we don't know that yet. We will prove it later, but\n  -- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.\n  let F : \u211d \u2192 \u2102 := \u03bb x, x ^ u * (1 - x) ^ v,\n  have hu' : 0 < re (u + 1), by { rw [add_re, one_re], positivity },\n  have hv' : 0 < re (v + 1), by { rw [add_re, one_re], positivity },\n  have hc : continuous_on F (Icc 0 1),\n  { refine (continuous_at.continuous_on (\u03bb x hx, _)).mul (continuous_at.continuous_on (\u03bb x hx, _)),\n    { refine (continuous_at_cpow_const_of_re_pos (or.inl _) hu).comp\n        continuous_of_real.continuous_at,\n      rw of_real_re, exact hx.1 },\n    { refine (continuous_at_cpow_const_of_re_pos (or.inl _) hv).comp\n        (continuous_const.sub continuous_of_real).continuous_at,\n      rw [sub_re, one_re, of_real_re, sub_nonneg],\n      exact hx.2 } },\n  have hder : \u2200 (x : \u211d), x \u2208 Ioo (0:\u211d) 1 \u2192 has_deriv_at F\n    (u * (\u2191x ^ (u - 1) * (1 - \u2191x) ^ v) - v * (\u2191x ^ u * (1 - \u2191x) ^ (v - 1))) x,\n  { intros x hx,\n    have U : has_deriv_at (\u03bb y:\u2102, y ^ u) (u * \u2191x ^ (u - 1)) \u2191x,\n    { have := has_deriv_at.cpow_const (has_deriv_at_id \u2191x) (or.inl _),\n      { rw mul_one at this, exact this },\n      { rw [id.def, of_real_re], exact hx.1 } },\n    have V : has_deriv_at (\u03bb y:\u2102, (1 - y) ^ v) (-v * (1 - \u2191x) ^ (v - 1)) \u2191x,\n    { have A := has_deriv_at.cpow_const (has_deriv_at_id (1 - \u2191x)) (or.inl _),\n      rotate, { exact v },\n      { rw [id.def, sub_re, one_re, of_real_re, sub_pos], exact hx.2 },\n      simp_rw [id.def] at A,\n      have B : has_deriv_at (\u03bb y:\u2102, 1 - y) (-1) \u2191x,\n      { apply has_deriv_at.const_sub, apply has_deriv_at_id },\n      convert has_deriv_at.comp \u2191x A B using 1,\n      ring },\n    convert (U.mul V).comp_of_real,\n    ring },\n  have h_int := ((beta_integral_convergent hu hv').const_mul u).sub\n    ((beta_integral_convergent hu' hv).const_mul v),\n  dsimp only at h_int,\n  rw [add_sub_cancel, add_sub_cancel] at h_int,\n  have int_ev := interval_integral.integral_eq_sub_of_has_deriv_at_of_le zero_le_one hc hder h_int,\n  have hF0 : F 0 = 0,\n  { simp only [mul_eq_zero, of_real_zero, cpow_eq_zero_iff, eq_self_iff_true,\n      ne.def, true_and, sub_zero, one_cpow, one_ne_zero, or_false],\n    contrapose! hu, rw [hu, zero_re] },\n  have hF1 : F 1 = 0,\n  { simp only [mul_eq_zero, of_real_one, one_cpow, one_ne_zero, sub_self,\n      cpow_eq_zero_iff, eq_self_iff_true, ne.def, true_and, false_or],\n    contrapose! hv, rw [hv, zero_re] },\n  rw [hF0, hF1, sub_zero, interval_integral.integral_sub,\n    interval_integral.integral_const_mul, interval_integral.integral_const_mul] at int_ev,\n  { rw [beta_integral, beta_integral, \u2190sub_eq_zero],\n    convert int_ev;\n    { ext1 x, congr, abel } },\n  { apply interval_integrable.const_mul,\n    convert beta_integral_convergent hu hv',\n    ext1 x, rw add_sub_cancel },\n  { apply interval_integrable.const_mul,\n    convert beta_integral_convergent hu' hv,\n    ext1 x, rw add_sub_cancel },\nend\n\n/-- Explicit formula for the Beta function when second argument is a positive integer. -/\nlemma beta_integral_eval_nat_add_one_right {u : \u2102} (hu : 0 < re u) (n : \u2115) :\n  beta_integral u (n + 1) = n! / \u220f (j:\u2115) in finset.range (n + 1), (u + j) :=\nbegin\n  induction n with n IH generalizing u,\n  { rw [nat.cast_zero, zero_add, beta_integral_eval_one_right hu,\n      nat.factorial_zero, nat.cast_one, zero_add, finset.prod_range_one, nat.cast_zero, add_zero] },\n  { have := beta_integral_recurrence hu (_ : 0 < re n.succ),\n    swap, { rw [\u2190of_real_nat_cast, of_real_re], positivity },\n    rw [mul_comm u _, \u2190eq_div_iff] at this,\n    swap, { contrapose! hu, rw [hu, zero_re] },\n    rw [this, finset.prod_range_succ', nat.cast_succ, IH],\n    swap, { rw [add_re, one_re], positivity },\n    rw [nat.factorial_succ, nat.cast_mul, nat.cast_add, nat.cast_one, nat.cast_zero, add_zero,\n      \u2190mul_div_assoc, \u2190div_div],\n    congr' 3 with j:1,\n    push_cast, abel }\nend\n\nend complex\n\nend beta_integral\n\nsection limit_formula\n\n/-! ## The Euler limit formula -/\n\nnamespace complex\n\n/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.\nWe will show that this tends to `\u0393(s)` as `n \u2192 \u221e`. -/\nnoncomputable def Gamma_seq (s : \u2102) (n : \u2115) :=\n(n:\u2102) ^ s * n! / \u220f (j:\u2115) in finset.range (n + 1), (s + j)\n\nlemma Gamma_seq_eq_beta_integral_of_re_pos {s : \u2102} (hs : 0 < re s) (n : \u2115) :\n  Gamma_seq s n = n ^ s * beta_integral s (n + 1) :=\nby rw [Gamma_seq, beta_integral_eval_nat_add_one_right hs n, \u2190mul_div_assoc]\n\nlemma Gamma_seq_add_one_left (s : \u2102) {n : \u2115} (hn : n \u2260 0) :\n  (Gamma_seq (s + 1) n) / s = n / (n + 1 + s) * Gamma_seq s n :=\nbegin\n  conv_lhs { rw [Gamma_seq, finset.prod_range_succ, div_div] },\n  conv_rhs { rw [Gamma_seq, finset.prod_range_succ', nat.cast_zero, add_zero, div_mul_div_comm,\n    \u2190mul_assoc, \u2190mul_assoc, mul_comm _ (finset.prod _ _)] },\n  congr' 3,\n  { rw [cpow_add _ _ (nat.cast_ne_zero.mpr hn), cpow_one, mul_comm] },\n  { refine finset.prod_congr (by refl) (\u03bb x hx, _),\n    push_cast, ring },\n  { abel }\nend\n\nlemma Gamma_seq_eq_approx_Gamma_integral {s : \u2102} (hs : 0 < re s) {n : \u2115} (hn : n \u2260 0) :\n  Gamma_seq s n = \u222b x:\u211d in 0..n, \u2191((1 - x / n) ^ n) * (x:\u2102) ^ (s - 1) :=\nbegin\n  have : \u2200 (x : \u211d), x = x / n * n, by { intro x, rw div_mul_cancel, exact nat.cast_ne_zero.mpr hn },\n  conv in (\u2191_ ^ _) { congr, rw this x },\n  rw Gamma_seq_eq_beta_integral_of_re_pos hs,\n  rw [beta_integral, @interval_integral.integral_comp_div _ _ _ _ 0 n _\n    (\u03bb x, \u2191((1 - x) ^ n) * \u2191(x * \u2191n) ^ (s - 1) : \u211d \u2192 \u2102) (nat.cast_ne_zero.mpr hn),\n    real_smul, zero_div, div_self, add_sub_cancel, \u2190interval_integral.integral_const_mul,\n    \u2190interval_integral.integral_const_mul],\n  swap, { exact nat.cast_ne_zero.mpr hn },\n  simp_rw interval_integral.integral_of_le zero_le_one,\n  refine set_integral_congr measurable_set_Ioc (\u03bb x hx, _),\n  push_cast,\n  have hn' : (n : \u2102) \u2260 0, from nat.cast_ne_zero.mpr hn,\n  have A : (n : \u2102) ^ s = (n : \u2102) ^ (s - 1)  * n,\n  { conv_lhs { rw [(by ring : s = (s - 1) + 1), cpow_add _ _ hn'] },\n    simp },\n  have B : ((x : \u2102) * \u2191n) ^ (s - 1) = (x : \u2102) ^ (s - 1) * \u2191n ^ (s - 1),\n  { rw [\u2190of_real_nat_cast,\n      mul_cpow_of_real_nonneg hx.1.le (nat.cast_pos.mpr (nat.pos_of_ne_zero hn)).le] },\n  rw [A, B, cpow_nat_cast], ring,\nend\n\n/-- The main techical lemma for `Gamma_seq_tendsto_Gamma`, expressing the integral defining the\nGamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/\nlemma approx_Gamma_integral_tendsto_Gamma_integral {s : \u2102} (hs : 0 < re s) :\n  tendsto (\u03bb n:\u2115, \u222b x:\u211d in 0..n, \u2191((1 - x / n) ^ n) * (x:\u2102) ^ (s - 1)) at_top (\ud835\udcdd $ Gamma s) :=\nbegin\n  rw [Gamma_eq_integral hs],\n  -- We apply dominated convergence to the following function, which we will show is uniformly\n  -- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.\n  let f : \u2115 \u2192 \u211d \u2192 \u2102 := \u03bb n, indicator (Ioc 0 (n:\u211d))\n    (\u03bb x:\u211d, \u2191((1 - x / n) ^ n) * (x:\u2102) ^ (s - 1)),\n  -- integrability of f\n  have f_ible : \u2200 (n:\u2115), integrable (f n) (volume.restrict (Ioi 0)),\n  { intro n,\n    rw [integrable_indicator_iff (measurable_set_Ioc : measurable_set (Ioc (_:\u211d) _)),\n      integrable_on, measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, \u2190integrable_on,\n      \u2190interval_integrable_iff_integrable_Ioc_of_le (by positivity : (0:\u211d) \u2264 n)],\n    apply interval_integrable.continuous_on_mul,\n    { refine interval_integral.interval_integrable_cpow' _,\n      rwa [sub_re, one_re, \u2190zero_sub, sub_lt_sub_iff_right] },\n    { apply continuous.continuous_on, continuity } },\n  -- pointwise limit of f\n  have f_tends : \u2200 x:\u211d, x \u2208 Ioi (0:\u211d) \u2192\n    tendsto (\u03bb n:\u2115, f n x) at_top (\ud835\udcdd $ \u2191(real.exp (-x)) * (x:\u2102) ^ (s - 1)),\n  { intros x hx,\n    apply tendsto.congr',\n    show \u2200\u1da0 n:\u2115 in at_top, \u2191((1 - x / n) ^ n) * (x:\u2102) ^ (s - 1) = f n x,\n    { refine eventually.mp (eventually_ge_at_top \u2308x\u2309\u208a) (eventually_of_forall (\u03bb n hn, _)),\n      rw nat.ceil_le at hn,\n      dsimp only [f],\n      rw indicator_of_mem,\n      exact \u27e8hx, hn\u27e9 },\n    { simp_rw mul_comm _ (\u2191x ^ _),\n      refine (tendsto.comp (continuous_of_real.tendsto _) _).const_mul _,\n      convert tendsto_one_plus_div_pow_exp (-x),\n      ext1 n,\n      rw [neg_div, \u2190sub_eq_add_neg] } },\n  -- let `convert` identify the remaining goals\n  convert tendsto_integral_of_dominated_convergence _ (\u03bb n, (f_ible n).1)\n    (real.Gamma_integral_convergent hs) _\n    ((ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ f_tends)),\n  -- limit of f is the integrand we want\n  { ext1 n,\n    rw [integral_indicator (measurable_set_Ioc : measurable_set (Ioc (_:\u211d) _)),\n      interval_integral.integral_of_le (by positivity: 0 \u2264 (n:\u211d)),\n      measure.restrict_restrict_of_subset Ioc_subset_Ioi_self] },\n  -- f is uniformly bounded by the Gamma integrand\n  { intro n,\n    refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    dsimp only [f],\n    rcases lt_or_le (n:\u211d) x with hxn | hxn,\n    { rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,\n        mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)],\n      exact rpow_nonneg_of_nonneg (le_of_lt hx) _ },\n    { rw [indicator_of_mem (mem_Ioc.mpr \u27e8hx, hxn\u27e9), norm_mul, complex.norm_eq_abs,\n        complex.abs_of_nonneg\n          (pow_nonneg (sub_nonneg.mpr $ div_le_one_of_le hxn $ by positivity) _),\n        complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,\n        mul_le_mul_right (rpow_pos_of_pos hx _ )],\n      exact one_sub_div_pow_le_exp_neg hxn } }\nend\n\n/-- Euler's limit formula for the complex Gamma function. -/\nlemma Gamma_seq_tendsto_Gamma (s : \u2102) :\n  tendsto (Gamma_seq s) at_top (\ud835\udcdd $ Gamma s) :=\nbegin\n  suffices : \u2200 m : \u2115, (-\u2191m < re s) \u2192 tendsto (Gamma_seq s) at_top (\ud835\udcdd $ Gamma_aux m s),\n  { rw Gamma,\n    apply this,\n    rw neg_lt,\n    rcases lt_or_le 0 (re s) with hs | hs,\n    { exact (neg_neg_of_pos hs).trans_le (nat.cast_nonneg _), },\n    { refine (nat.lt_floor_add_one _).trans_le _,\n      rw [sub_eq_neg_add, nat.floor_add_one (neg_nonneg.mpr hs), nat.cast_add_one] } },\n  intro m,\n  induction m with m IH generalizing s,\n  { -- Base case: `0 < re s`, so Gamma is given by the integral formula\n    intro hs,\n    rw [nat.cast_zero, neg_zero] at hs,\n    rw [\u2190Gamma_eq_Gamma_aux],\n    { refine tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs),\n      refine (eventually_ne_at_top 0).mp (eventually_of_forall (\u03bb n hn, _)),\n      exact (Gamma_seq_eq_approx_Gamma_integral hs hn).symm },\n    { rwa [nat.cast_zero, neg_lt_zero] } },\n  { -- Induction step: use recurrence formulae in `s` for Gamma and Gamma_seq\n    intro hs,\n    rw [nat.cast_succ, neg_add, \u2190sub_eq_add_neg, sub_lt_iff_lt_add, \u2190one_re, \u2190add_re] at hs,\n    rw Gamma_aux,\n    have := tendsto.congr' ((eventually_ne_at_top 0).mp (eventually_of_forall (\u03bb n hn, _)))\n      ((IH _ hs).div_const s),\n    swap 3, { exact Gamma_seq_add_one_left s hn }, -- doesn't work if inlined?\n    conv at this in (_ / _ * _) { rw mul_comm },\n    rwa [\u2190mul_one (Gamma_aux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' \u2102)] at this,\n    simp_rw add_assoc,\n    exact tendsto_coe_nat_div_add_at_top (1 + s) }\nend\n\nend complex\n\nend limit_formula\n\nsection gamma_reflection\n/-! ## The reflection formula -/\n\nopen_locale real\nnamespace complex\n\nlemma Gamma_seq_mul (z : \u2102) {n : \u2115} (hn : n \u2260 0) :\n  Gamma_seq z n * Gamma_seq (1 - z) n =\n  n / (n + 1 - z) * (1 / (z * \u220f j in finset.range n, (1 - z ^ 2 / (j + 1) ^ 2))) :=\nbegin\n  -- also true for n = 0 but we don't need it\n  have aux : \u2200 (a b c d : \u2102), a * b * (c * d) = a * c * (b * d), by { intros, ring },\n  rw [Gamma_seq, Gamma_seq, div_mul_div_comm, aux, \u2190pow_two],\n  have : (n : \u2102) ^ z * n ^ (1 - z) = n,\n  { rw [\u2190cpow_add _ _ (nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one] },\n  rw [this, finset.prod_range_succ', finset.prod_range_succ, aux, \u2190finset.prod_mul_distrib,\n    nat.cast_zero, add_zero, add_comm (1 - z) n, \u2190add_sub_assoc],\n  have : \u2200 (j : \u2115), (z + \u2191(j + 1)) * (1 - z + \u2191j) = \u2191((j + 1) ^ 2) * (1 - z ^ 2 / (\u2191j + 1) ^ 2),\n  { intro j,\n    push_cast,\n    have : (j:\u2102) + 1 \u2260 0, by { rw [\u2190nat.cast_succ, nat.cast_ne_zero], exact nat.succ_ne_zero j },\n    field_simp, ring },\n  simp_rw this,\n  rw [finset.prod_mul_distrib, \u2190nat.cast_prod, finset.prod_pow,\n    finset.prod_range_add_one_eq_factorial, nat.cast_pow,\n    (by {intros, ring} : \u2200 (a b c d : \u2102), a * b * (c * d) = a * (d * (b * c))),\n    \u2190div_div, mul_div_cancel, \u2190div_div, mul_comm z _, mul_one_div],\n  exact pow_ne_zero 2 (nat.cast_ne_zero.mpr $ nat.factorial_ne_zero n),\nend\n\n/-- Euler's reflection formula for the complex Gamma function. -/\ntheorem Gamma_mul_Gamma_one_sub (z : \u2102) : Gamma z * Gamma (1 - z) = \u03c0 / sin (\u03c0 * z) :=\nbegin\n  have pi_ne : (\u03c0 : \u2102) \u2260 0, from complex.of_real_ne_zero.mpr pi_ne_zero,\n  by_cases hs : sin (\u2191\u03c0 * z) = 0,\n  { -- first deal with silly case z = integer\n    rw [hs, div_zero],\n    rw [\u2190neg_eq_zero, \u2190complex.sin_neg, \u2190mul_neg, complex.sin_eq_zero_iff, mul_comm] at hs,\n    obtain \u27e8k, hk\u27e9 := hs,\n    rw [mul_eq_mul_right_iff, eq_false_intro (of_real_ne_zero.mpr pi_pos.ne'), or_false,\n      neg_eq_iff_eq_neg] at hk,\n    rw hk,\n    cases k,\n    { rw [int.cast_of_nat, complex.Gamma_neg_nat_eq_zero, zero_mul] },\n    { rw [int.cast_neg_succ_of_nat, neg_neg, nat.cast_add, nat.cast_one, add_comm, sub_add_cancel',\n        complex.Gamma_neg_nat_eq_zero, mul_zero] } },\n  refine tendsto_nhds_unique ((Gamma_seq_tendsto_Gamma z).mul (Gamma_seq_tendsto_Gamma $ 1 - z)) _,\n  have : \u2191\u03c0 / sin (\u2191\u03c0 * z) = 1 * (\u03c0 / sin (\u03c0 * z)), by rw one_mul, rw this,\n  refine tendsto.congr' ((eventually_ne_at_top 0).mp\n    (eventually_of_forall (\u03bb n hn, (Gamma_seq_mul z hn).symm))) (tendsto.mul _ _),\n  { convert tendsto_coe_nat_div_add_at_top (1 - z), ext1 n, rw add_sub_assoc },\n  { have : \u2191\u03c0 / sin (\u2191\u03c0 * z) = 1 / (sin (\u03c0 * z) / \u03c0), by field_simp, rw this,\n    refine tendsto_const_nhds.div _ (div_ne_zero hs pi_ne),\n    rw [\u2190tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne],\n    convert tendsto_euler_sin_prod z,\n    ext1 n, rw [mul_comm, \u2190mul_assoc] },\nend\n\n/-- The Gamma function does not vanish on `\u2102` (except at non-positive integers, where the function\nis mathematically undefined and we set it to `0` by convention). -/\ntheorem Gamma_ne_zero {s : \u2102} (hs : \u2200 m : \u2115, s \u2260 -m) : Gamma s \u2260 0 :=\nbegin\n  by_cases h_im : s.im = 0,\n  { have : s = \u2191s.re,\n    { conv_lhs { rw \u2190complex.re_add_im s }, rw [h_im, of_real_zero, zero_mul, add_zero] },\n    rw [this, Gamma_of_real, of_real_ne_zero],\n    refine real.Gamma_ne_zero (\u03bb n, _),\n    specialize hs n,\n    contrapose! hs,\n    rwa [this, \u2190of_real_nat_cast, \u2190of_real_neg, of_real_inj] },\n  { have : sin (\u2191\u03c0 * s) \u2260 0,\n    { rw complex.sin_ne_zero_iff,\n      intro k,\n      apply_fun im,\n      rw [of_real_mul_im, \u2190of_real_int_cast, \u2190of_real_mul, of_real_im],\n      exact mul_ne_zero real.pi_pos.ne' h_im },\n    have A := div_ne_zero (of_real_ne_zero.mpr real.pi_pos.ne') this,\n    rw [\u2190complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A,\n    exact A.1 }\nend\n\nlemma Gamma_eq_zero_iff (s : \u2102) : Gamma s = 0 \u2194 \u2203 m : \u2115, s = -m :=\nbegin\n  split,\n  { contrapose!, exact Gamma_ne_zero },\n  { rintro \u27e8m, rfl\u27e9, exact Gamma_neg_nat_eq_zero m },\nend\n\nend complex\n\nnamespace real\n\n/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We\nwill show that this tends to `\u0393(s)` as `n \u2192 \u221e`. -/\nnoncomputable def Gamma_seq (s : \u211d) (n : \u2115) :=\n(n : \u211d) ^ s * n! / \u220f (j : \u2115) in finset.range (n + 1), (s + j)\n\n/-- Euler's limit formula for the real Gamma function. -/\nlemma Gamma_seq_tendsto_Gamma (s : \u211d) : tendsto (Gamma_seq s) at_top (\ud835\udcdd $ Gamma s) :=\nbegin\n  suffices : tendsto (coe \u2218 Gamma_seq s : \u2115 \u2192 \u2102) at_top (\ud835\udcdd $ complex.Gamma s),\n    from (complex.continuous_re.tendsto (complex.Gamma \u2191s)).comp this,\n  convert complex.Gamma_seq_tendsto_Gamma s,\n  ext1 n,\n  dsimp only [Gamma_seq, function.comp_app, complex.Gamma_seq],\n  push_cast,\n  rw [complex.of_real_cpow n.cast_nonneg, complex.of_real_nat_cast]\nend\n\n/-- Euler's reflection formula for the real Gamma function. -/\nlemma Gamma_mul_Gamma_one_sub (s : \u211d) : Gamma s * Gamma (1 - s) = \u03c0 / sin (\u03c0 * s) :=\nbegin\n  simp_rw [\u2190complex.of_real_inj, complex.of_real_div, complex.of_real_sin,\n    complex.of_real_mul, \u2190complex.Gamma_of_real, complex.of_real_sub, complex.of_real_one],\n  exact complex.Gamma_mul_Gamma_one_sub s\nend\n\nend real\n\nend gamma_reflection\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/gamma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7328144692586667}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Michael Howes\n-/\nimport group_theory.commutator\nimport group_theory.quotient_group\n\n/-!\n# The abelianization of a group\n\nThis file defines the commutator and the abelianization of a group. It furthermore prepares for the\nresult that the abelianization is left adjoint to the forgetful functor from abelian groups to\ngroups, which can be found in `algebra/category/Group/adjunctions`.\n\n## Main definitions\n\n* `commutator`: defines the commutator of a group `G` as a subgroup of `G`.\n* `abelianization`: defines the abelianization of a group `G` as the quotient of a group by its\n  commutator subgroup.\n* `abelianization.map`: lifts a group homomorphism to a homomorphism between the abelianizations\n* `mul_equiv.abelianization_congr`: Equivalent groups have equivalent abelianizations\n\n-/\n\nuniverses u v w\n\n-- Let G be a group.\nvariables (G : Type u) [group G]\n\n/-- The commutator subgroup of a group G is the normal subgroup\n  generated by the commutators [p,q]=`p*q*p\u207b\u00b9*q\u207b\u00b9`. -/\n@[derive subgroup.normal]\ndef commutator : subgroup G :=\n\u2045(\u22a4 : subgroup G), \u22a4\u2046\n\nlemma commutator_def : commutator G = \u2045(\u22a4 : subgroup G), \u22a4\u2046 := rfl\n\nlemma commutator_eq_closure : commutator G = subgroup.closure {g | \u2203 g\u2081 g\u2082 : G, \u2045g\u2081, g\u2082\u2046 = g} :=\nby simp_rw [commutator, subgroup.commutator_def, subgroup.mem_top, exists_true_left]\n\nlemma commutator_eq_normal_closure :\n  commutator G = subgroup.normal_closure {g | \u2203 g\u2081 g\u2082 : G, \u2045g\u2081, g\u2082\u2046 = g} :=\nby simp_rw [commutator, subgroup.commutator_def', subgroup.mem_top, exists_true_left]\n\ninstance commutator_characteristic : (commutator G).characteristic :=\nsubgroup.commutator_characteristic \u22a4 \u22a4\n\nlemma commutator_centralizer_commutator_le_center :\n  \u2045(commutator G).centralizer, (commutator G).centralizer\u2046 \u2264 subgroup.center G :=\nbegin\n  rw [\u2190subgroup.centralizer_top, \u2190subgroup.commutator_eq_bot_iff_le_centralizer],\n  suffices : \u2045\u2045\u22a4, (commutator G).centralizer\u2046, (commutator G).centralizer\u2046 = \u22a5,\n  { refine subgroup.commutator_commutator_eq_bot_of_rotate _ this,\n    rwa subgroup.commutator_comm (commutator G).centralizer },\n  rw [subgroup.commutator_comm, subgroup.commutator_eq_bot_iff_le_centralizer],\n  exact set.centralizer_subset (subgroup.commutator_mono le_top le_top),\nend\n\n/-- The abelianization of G is the quotient of G by its commutator subgroup. -/\ndef abelianization : Type u :=\nG \u29f8 (commutator G)\n\nnamespace abelianization\n\nlocal attribute [instance] quotient_group.left_rel\n\ninstance : comm_group (abelianization G) :=\n{ mul_comm := \u03bb x y, quotient.induction_on\u2082' x y $ \u03bb a b, quotient.sound' $\n    subgroup.subset_closure \u27e8b\u207b\u00b9, subgroup.mem_top b\u207b\u00b9, a\u207b\u00b9, subgroup.mem_top a\u207b\u00b9, by group\u27e9,\n.. quotient_group.quotient.group _ }\n\ninstance : inhabited (abelianization G) := \u27e81\u27e9\n\ninstance [fintype G] [decidable_pred (\u2208 commutator G)] :\n  fintype (abelianization G) :=\nquotient_group.fintype (commutator G)\n\nvariable {G}\n\n/-- `of` is the canonical projection from G to its abelianization. -/\ndef of : G \u2192* abelianization G :=\n{ to_fun := quotient_group.mk,\n  map_one' := rfl,\n  map_mul' := \u03bb x y, rfl }\n\n@[simp] lemma mk_eq_of (a : G) : quot.mk _ a = of a := rfl\n\nsection lift\n-- So far we have built G\u1d43\u1d47 and proved it's an abelian group.\n-- Furthremore we defined the canonical projection `of : G \u2192 G\u1d43\u1d47`\n\n-- Let `A` be an abelian group and let `f` be a group homomorphism from `G` to `A`.\nvariables {A : Type v} [comm_group A] (f : G \u2192* A)\n\nlemma commutator_subset_ker : commutator G \u2264 f.ker :=\nbegin\n  rw [commutator_eq_closure, subgroup.closure_le],\n  rintros x \u27e8p, q, rfl\u27e9,\n  simp [monoid_hom.mem_ker, mul_right_comm (f p) (f q), commutator_element_def],\nend\n\n/-- If `f : G \u2192 A` is a group homomorphism to an abelian group, then `lift f` is the unique map from\n  the abelianization of a `G` to `A` that factors through `f`. -/\ndef lift : (G \u2192* A) \u2243 (abelianization G \u2192* A) :=\n{ to_fun := \u03bb f, quotient_group.lift _ f (\u03bb x h, f.mem_ker.2 $ commutator_subset_ker _ h),\n  inv_fun := \u03bb F, F.comp of,\n  left_inv := \u03bb f, monoid_hom.ext $ \u03bb x, rfl,\n  right_inv := \u03bb F, monoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ \u03bb z, rfl }\n\n@[simp] lemma lift.of (x : G) : lift f (of x) = f x :=\nrfl\n\ntheorem lift.unique\n  (\u03c6 : abelianization G \u2192* A)\n  -- h\u03c6 : \u03c6 agrees with f on the image of G in G\u1d43\u1d47\n  (h\u03c6 : \u2200 (x : G), \u03c6 (of x) = f x)\n  {x : abelianization G} :\n  \u03c6 x = lift f x :=\nquotient_group.induction_on x h\u03c6\n\n@[simp] lemma lift_of : lift of = monoid_hom.id (abelianization G) :=\nlift.apply_symm_apply $ monoid_hom.id _\n\nend lift\n\nvariables {A : Type v} [monoid A]\n\n/-- See note [partially-applied ext lemmas]. -/\n@[ext]\ntheorem hom_ext (\u03c6 \u03c8 : abelianization G \u2192* A)\n  (h : \u03c6.comp of = \u03c8.comp of) : \u03c6 = \u03c8 :=\nmonoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ monoid_hom.congr_fun h\n\nsection map\n\nvariables {H : Type v} [group H] (f : G \u2192* H)\n\n/-- The map operation of the `abelianization` functor -/\ndef map : abelianization G \u2192* abelianization H := lift (of.comp f)\n\n@[simp]\nlemma map_of (x : G) : map f (of x) = of (f x) := rfl\n\n@[simp]\nlemma map_id : map (monoid_hom.id G) = monoid_hom.id (abelianization G) := hom_ext _ _ rfl\n\n@[simp]\nlemma map_comp {I : Type w} [group I] (g : H \u2192* I) :\n  (map g).comp (map f) = map (g.comp f) := hom_ext _ _ rfl\n\n@[simp]\nlemma map_map_apply {I : Type w} [group I] {g : H \u2192* I} {x : abelianization G}:\n  map g (map f x) = map (g.comp f) x := monoid_hom.congr_fun (map_comp _ _) x\n\nend map\n\nend abelianization\n\nsection abelianization_congr\n\nvariables {G} {H : Type v} [group H] (e : G \u2243* H)\n\n/-- Equivalent groups have equivalent abelianizations -/\ndef mul_equiv.abelianization_congr : abelianization G \u2243* abelianization H :=\n{ to_fun := abelianization.map e.to_monoid_hom,\n  inv_fun := abelianization.map e.symm.to_monoid_hom,\n  left_inv := by { rintros \u27e8a\u27e9, simp },\n  right_inv := by { rintros \u27e8a\u27e9, simp },\n  map_mul' := monoid_hom.map_mul _ }\n\n@[simp]\nlemma abelianization_congr_of (x : G) :\n  (e.abelianization_congr) (abelianization.of x) = abelianization.of (e x) := rfl\n\n@[simp]\nlemma abelianization_congr_refl :\n  (mul_equiv.refl G).abelianization_congr = mul_equiv.refl (abelianization G) :=\nmul_equiv.to_monoid_hom_injective abelianization.lift_of\n\n@[simp]\nlemma abelianization_congr_symm  :\n  e.abelianization_congr.symm = e.symm.abelianization_congr := rfl\n\n@[simp]\nlemma abelianization_congr_trans {I : Type v} [group I] (e\u2082 : H \u2243* I) :\n  e.abelianization_congr.trans e\u2082.abelianization_congr = (e.trans e\u2082).abelianization_congr :=\nmul_equiv.to_monoid_hom_injective (abelianization.hom_ext _ _ rfl)\n\nend abelianization_congr\n\n/-- An Abelian group is equivalent to its own abelianization. -/\n@[simps] def abelianization.equiv_of_comm {H : Type*} [comm_group H] :\n  H \u2243* abelianization H :=\n{ to_fun    := abelianization.of,\n  inv_fun   := abelianization.lift (monoid_hom.id H),\n  left_inv  := \u03bb a, rfl,\n  right_inv := by { rintros \u27e8a\u27e9, refl, },\n  .. abelianization.of }\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/group_theory/abelianization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7328144692586666}}
{"text": "/-\nCopyright (c) 2019 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard\n\n! This file was ported from Lean 3 source module data.real.ereal\n! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Real.Basic\nimport Mathlib.Data.Real.ENNReal\nimport Mathlib.Data.Sign\n\n/-!\n# The extended reals [-\u221e, \u221e].\n\nThis file defines `EReal`, the real numbers together with a top and bottom element,\nreferred to as \u22a4 and \u22a5. It is implemented as `WithBot (WithTop \u211d)`\n\nAddition and multiplication are problematic in the presence of \u00b1\u221e, but\nnegation has a natural definition and satisfies the usual properties.\n\nAn ad hoc addition is defined, for which `EReal` is an `AddCommMonoid`, and even an ordered one\n(if `a \u2264 a'` and `b \u2264 b'` then `a + b \u2264 a' + b'`).\nNote however that addition is badly behaved at `(\u22a5, \u22a4)` and `(\u22a4, \u22a5)` so this can not be upgraded\nto a group structure. Our choice is that `\u22a5 + \u22a4 = \u22a4 + \u22a5 = \u22a5`, to make sure that the exponential\nand the logarithm between `EReal` and `\u211d\u22650\u221e` respect the operations (notice that the\nconvention `0 * \u221e = 0` on `\u211d\u22650\u221e` is enforced by measure theory).\n\nAn ad hoc subtraction is then defined by `x - y = x + (-y)`. It does not have nice properties,\nbut it is sometimes convenient to have.\n\nAn ad hoc multiplication is defined, for which `EReal` is a `CommMonoidWithZero`. We make the\nchoice that `0 * x = x * 0 = 0` for any `x` (while the other cases are defined non-ambiguously).\nThis does not distribute with addition, as `\u22a5 = \u22a5 + \u22a4 = 1*\u22a5 + (-1)*\u22a5 \u2260 (1 - 1) * \u22a5 = 0 * \u22a5 = 0`.\n\n`EReal` is a `CompleteLinearOrder`; this is deduced by type class inference from\nthe fact that `WithBot (WithTop L)` is a complete linear order if `L` is\na conditionally complete linear order.\n\nCoercions from `\u211d` and from `\u211d\u22650\u221e` are registered, and their basic properties are proved. The main\none is the real coercion, and is usually referred to just as `coe` (lemmas such as\n`EReal.coe_add` deal with this coercion). The one from `ENNReal` is usually called `coe_ennreal`\nin the `EReal` namespace.\n\nWe define an absolute value `EReal.abs` from `EReal` to `\u211d\u22650\u221e`. Two elements of `EReal` coincide\nif and only if they have the same absolute value and the same sign.\n\n## Tags\n\nreal, ereal, complete lattice\n-/\n\nopen Function ENNReal NNReal Set\n\nnoncomputable section\n\n/-- ereal : The type `[-\u221e, \u221e]` -/\ndef EReal := WithBot (WithTop \u211d)\n  deriving Bot, Zero, One, Nontrivial, AddMonoid, PartialOrder\n#align ereal EReal\n\ninstance : ZeroLEOneClass EReal := inferInstanceAs (ZeroLEOneClass (WithBot (WithTop \u211d)))\ninstance : SupSet EReal := inferInstanceAs (SupSet (WithBot (WithTop \u211d)))\ninstance : InfSet EReal := inferInstanceAs (InfSet (WithBot (WithTop \u211d)))\n\ninstance : CompleteLinearOrder EReal :=\n  inferInstanceAs (CompleteLinearOrder (WithBot (WithTop \u211d)))\n\ninstance : LinearOrderedAddCommMonoid EReal :=\n  inferInstanceAs (LinearOrderedAddCommMonoid (WithBot (WithTop \u211d)))\n\ninstance : DenselyOrdered EReal :=\n  inferInstanceAs (DenselyOrdered (WithBot (WithTop \u211d)))\n\n/-- The canonical inclusion froms reals to ereals. Registered as a coercion. -/\n@[coe] def Real.toEReal : \u211d \u2192 EReal := some \u2218 some\n#align real.to_ereal Real.toEReal\n\nnamespace EReal\n\n-- things unify with `WithBot.decidableLT` later if we we don't provide this explicitly.\ninstance decidableLt : DecidableRel ((\u00b7 < \u00b7) : EReal \u2192 EReal \u2192 Prop) :=\n  WithBot.decidableLT\n#align ereal.decidable_lt EReal.decidableLt\n\n-- TODO: Provide explicitly, otherwise it is inferred noncomputably from `CompleteLinearOrder`\ninstance : Top EReal := \u27e8some \u22a4\u27e9\n\ninstance : Coe \u211d EReal := \u27e8Real.toEReal\u27e9\n\ntheorem coe_strictMono : StrictMono Real.toEReal :=\n  WithBot.coe_strictMono.comp WithTop.coe_strictMono\n#align ereal.coe_strict_mono EReal.coe_strictMono\n\ntheorem coe_injective : Injective Real.toEReal :=\n  coe_strictMono.injective\n#align ereal.coe_injective EReal.coe_injective\n\n@[simp, norm_cast]\nprotected theorem coe_le_coe_iff {x y : \u211d} : (x : EReal) \u2264 (y : EReal) \u2194 x \u2264 y :=\n  coe_strictMono.le_iff_le\n#align ereal.coe_le_coe_iff EReal.coe_le_coe_iff\n\n@[simp, norm_cast]\nprotected theorem coe_lt_coe_iff {x y : \u211d} : (x : EReal) < (y : EReal) \u2194 x < y :=\n  coe_strictMono.lt_iff_lt\n#align ereal.coe_lt_coe_iff EReal.coe_lt_coe_iff\n\n@[simp, norm_cast]\nprotected theorem coe_eq_coe_iff {x y : \u211d} : (x : EReal) = (y : EReal) \u2194 x = y :=\n  coe_injective.eq_iff\n#align ereal.coe_eq_coe_iff EReal.coe_eq_coe_iff\n\nprotected theorem coe_ne_coe_iff {x y : \u211d} : (x : EReal) \u2260 (y : EReal) \u2194 x \u2260 y :=\n  coe_injective.ne_iff\n#align ereal.coe_ne_coe_iff EReal.coe_ne_coe_iff\n\n/-- The canonical map from nonnegative extended reals to extended reals -/\n@[coe] def _root_.ENNReal.toEReal : \u211d\u22650\u221e \u2192 EReal\n  | \u22a4 => \u22a4\n  | .some x => x.1\n#align ennreal.to_ereal ENNReal.toEReal\n\ninstance hasCoeENNReal : Coe \u211d\u22650\u221e EReal :=\n  \u27e8ENNReal.toEReal\u27e9\n#align ereal.has_coe_ennreal EReal.hasCoeENNReal\n\ninstance : Inhabited EReal := \u27e80\u27e9\n\n@[simp, norm_cast]\ntheorem coe_zero : ((0 : \u211d) : EReal) = 0 := rfl\n#align ereal.coe_zero EReal.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : ((1 : \u211d) : EReal) = 1 := rfl\n#align ereal.coe_one EReal.coe_one\n\n/-- A recursor for `EReal` in terms of the coercion.\n\nA typical invocation looks like `induction x using EReal.rec`. Note that using `induction`\ndirectly will unfold `EReal` to `Option` which is undesirable.\n\nWhen working in term mode, note that pattern matching can be used directly. -/\n@[elab_as_elim]\nprotected def rec {C : EReal \u2192 Sort _} (h_bot : C \u22a5) (h_real : \u2200 a : \u211d, C a) (h_top : C \u22a4) :\n    \u2200 a : EReal, C a\n  | \u22a5 => h_bot\n  | (a : \u211d) => h_real a\n  | \u22a4 => h_top\n#align ereal.rec EReal.rec\n\n/-- The multiplication on `EReal`. Our definition satisfies `0 * x = x * 0 = 0` for any `x`, and\npicks the only sensible value elsewhere. -/\nprotected def mul : EReal \u2192 EReal \u2192 EReal\n  | \u22a5, \u22a5 => \u22a4\n  | \u22a5, \u22a4 => \u22a5\n  | \u22a5, (y : \u211d) => if 0 < y then \u22a5 else if y = 0 then 0 else \u22a4\n  | \u22a4, \u22a5 => \u22a5\n  | \u22a4, \u22a4 => \u22a4\n  | \u22a4, (y : \u211d) => if 0 < y then \u22a4 else if y = 0 then 0 else \u22a5\n  | (x : \u211d), \u22a4 => if 0 < x then \u22a4 else if x = 0 then 0 else \u22a5\n  | (x : \u211d), \u22a5 => if 0 < x then \u22a5 else if x = 0 then 0 else \u22a4\n  | (x : \u211d), (y : \u211d) => (x * y : \u211d)\n#align ereal.mul EReal.mul\n\ninstance : Mul EReal := \u27e8EReal.mul\u27e9\n\n@[simp, norm_cast]\ntheorem coe_mul (x y : \u211d) : (\u2191(x * y) : EReal) = x * y :=\n  rfl\n#align ereal.coe_mul EReal.coe_mul\n\n/-- Induct on two ereals by performing case splits on the sign of one whenever the other is\ninfinite. -/\n@[elab_as_elim]\ntheorem induction\u2082 {P : EReal \u2192 EReal \u2192 Prop} (top_top : P \u22a4 \u22a4) (top_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a4 x)\n    (top_zero : P \u22a4 0) (top_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a4 x) (top_bot : P \u22a4 \u22a5)\n    (pos_top : \u2200 x : \u211d, 0 < x \u2192 P x \u22a4) (pos_bot : \u2200 x : \u211d, 0 < x \u2192 P x \u22a5) (zero_top : P 0 \u22a4)\n    (coe_coe : \u2200 x y : \u211d, P x y) (zero_bot : P 0 \u22a5) (neg_top : \u2200 x : \u211d, x < 0 \u2192 P x \u22a4)\n    (neg_bot : \u2200 x : \u211d, x < 0 \u2192 P x \u22a5) (bot_top : P \u22a5 \u22a4) (bot_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a5 x)\n    (bot_zero : P \u22a5 0) (bot_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a5 x) (bot_bot : P \u22a5 \u22a5) : \u2200 x y, P x y\n  | \u22a5, \u22a5 => bot_bot\n  | \u22a5, (y : \u211d) => by\n    rcases lt_trichotomy y 0 with (hy | rfl | hy)\n    exacts [bot_neg y hy, bot_zero, bot_pos y hy]\n  | \u22a5, \u22a4 => bot_top\n  | (x : \u211d), \u22a5 => by\n    rcases lt_trichotomy x 0 with (hx | rfl | hx)\n    exacts [neg_bot x hx, zero_bot, pos_bot x hx]\n  | (x : \u211d), (y : \u211d) => coe_coe _ _\n  | (x : \u211d), \u22a4 => by\n    rcases lt_trichotomy x 0 with (hx | rfl | hx)\n    exacts [neg_top x hx, zero_top, pos_top x hx]\n  | \u22a4, \u22a5 => top_bot\n  | \u22a4, (y : \u211d) => by\n    rcases lt_trichotomy y 0 with (hy | rfl | hy)\n    exacts [top_neg y hy, top_zero, top_pos y hy]\n  | \u22a4, \u22a4 => top_top\n#align ereal.induction\u2082 EReal.induction\u2082\n\n/-- Induct on two ereals by performing case splits on the sign of one whenever the other is\ninfinite. This version eliminates some cases by assuming that the relation is symmetric. -/\n@[elab_as_elim]\ntheorem induction\u2082_symm {P : EReal \u2192 EReal \u2192 Prop} (symm : Symmetric P) (top_top : P \u22a4 \u22a4)\n    (top_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a4 x) (top_zero : P \u22a4 0) (top_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a4 x)\n    (top_bot : P \u22a4 \u22a5) (pos_bot : \u2200 x : \u211d, 0 < x \u2192 P x \u22a5) (coe_coe : \u2200 x y : \u211d, P x y)\n    (zero_bot : P 0 \u22a5) (neg_bot : \u2200 x : \u211d, x < 0 \u2192 P x \u22a5) (bot_bot : P \u22a5 \u22a5) : \u2200 x y, P x y :=\n  @induction\u2082 P top_top top_pos top_zero top_neg top_bot (fun _ h => symm <| top_pos _ h)\n    pos_bot (symm top_zero) coe_coe zero_bot (fun _ h => symm <| top_neg _ h) neg_bot (symm top_bot)\n    (fun _ h => symm <| pos_bot _ h) (symm zero_bot) (fun _ h => symm <| neg_bot _ h) bot_bot\n\n/-! `EReal` with its multiplication is a `CommMonoidWithZero`. However, the proof of\nassociativity by hand is extremely painful (with 125 cases...). Instead, we will deduce it later\non from the facts that the absolute value and the sign are multiplicative functions taking value\nin associative objects, and that they characterize an extended real number. For now, we only\nrecord more basic properties of multiplication.\n-/\n\nprotected theorem mul_comm (x y : EReal) : x * y = y * x := by\n  induction' x using EReal.rec with x <;> induction' y using EReal.rec with y <;>\n    try { rfl }\n  rw [\u2190 coe_mul, \u2190 coe_mul, mul_comm]\n#align ereal.mul_comm EReal.mul_comm\n\nprotected theorem one_mul : \u2200 x : EReal, 1 * x = x\n  | \u22a4 => if_pos one_pos\n  | \u22a5 => if_pos one_pos\n  | (x : \u211d) => congr_arg Real.toEReal (one_mul x)\n\nprotected theorem zero_mul : \u2200 x : EReal, 0 * x = 0\n  | \u22a4 => (if_neg (lt_irrefl _)).trans (if_pos rfl)\n  | \u22a5 => (if_neg (lt_irrefl _)).trans (if_pos rfl)\n  | (x : \u211d) => congr_arg Real.toEReal (zero_mul x)\n\ninstance : MulZeroOneClass EReal where\n  one_mul := EReal.one_mul\n  mul_one := fun x => by rw [EReal.mul_comm, EReal.one_mul]\n  zero_mul := EReal.zero_mul\n  mul_zero := fun x => by rw [EReal.mul_comm, EReal.zero_mul]\n\n/-! ### Real coercion -/\n\ninstance canLift : CanLift EReal \u211d (\u2191) fun r => r \u2260 \u22a4 \u2227 r \u2260 \u22a5 where\n  prf x hx := by\n    induction x using EReal.rec\n    \u00b7 simp at hx\n    \u00b7 simp\n    \u00b7 simp at hx\n#align ereal.can_lift EReal.canLift\n\n/-- The map from extended reals to reals sending infinities to zero. -/\ndef toReal : EReal \u2192 \u211d\n  | \u22a5 => 0\n  | \u22a4 => 0\n  | (x : \u211d) => x\n#align ereal.to_real EReal.toReal\n\n@[simp]\ntheorem toReal_top : toReal \u22a4 = 0 :=\n  rfl\n#align ereal.to_real_top EReal.toReal_top\n\n@[simp]\ntheorem toReal_bot : toReal \u22a5 = 0 :=\n  rfl\n#align ereal.to_real_bot EReal.toReal_bot\n\n@[simp]\ntheorem toReal_zero : toReal 0 = 0 :=\n  rfl\n#align ereal.to_real_zero EReal.toReal_zero\n\n@[simp]\ntheorem toReal_one : toReal 1 = 1 :=\n  rfl\n#align ereal.to_real_one EReal.toReal_one\n\n@[simp]\ntheorem toReal_coe (x : \u211d) : toReal (x : EReal) = x :=\n  rfl\n#align ereal.to_real_coe EReal.toReal_coe\n\n@[simp]\ntheorem bot_lt_coe (x : \u211d) : (\u22a5 : EReal) < x :=\n  WithBot.bot_lt_coe _\n#align ereal.bot_lt_coe EReal.bot_lt_coe\n\n@[simp]\ntheorem coe_ne_bot (x : \u211d) : (x : EReal) \u2260 \u22a5 :=\n  (bot_lt_coe x).ne'\n#align ereal.coe_ne_bot EReal.coe_ne_bot\n\n@[simp]\ntheorem bot_ne_coe (x : \u211d) : (\u22a5 : EReal) \u2260 x :=\n  (bot_lt_coe x).ne\n#align ereal.bot_ne_coe EReal.bot_ne_coe\n\n@[simp]\ntheorem coe_lt_top (x : \u211d) : (x : EReal) < \u22a4 :=\n  WithBot.coe_lt_coe.2 <| WithTop.coe_lt_top _\n#align ereal.coe_lt_top EReal.coe_lt_top\n\n@[simp]\ntheorem coe_ne_top (x : \u211d) : (x : EReal) \u2260 \u22a4 :=\n  (coe_lt_top x).ne\n#align ereal.coe_ne_top EReal.coe_ne_top\n\n@[simp]\ntheorem top_ne_coe (x : \u211d) : (\u22a4 : EReal) \u2260 x :=\n  (coe_lt_top x).ne'\n#align ereal.top_ne_coe EReal.top_ne_coe\n\n@[simp]\ntheorem bot_lt_zero : (\u22a5 : EReal) < 0 :=\n  bot_lt_coe 0\n#align ereal.bot_lt_zero EReal.bot_lt_zero\n\n@[simp]\ntheorem bot_ne_zero : (\u22a5 : EReal) \u2260 0 :=\n  (coe_ne_bot 0).symm\n#align ereal.bot_ne_zero EReal.bot_ne_zero\n\n@[simp]\ntheorem zero_ne_bot : (0 : EReal) \u2260 \u22a5 :=\n  coe_ne_bot 0\n#align ereal.zero_ne_bot EReal.zero_ne_bot\n\n@[simp]\ntheorem zero_lt_top : (0 : EReal) < \u22a4 :=\n  coe_lt_top 0\n#align ereal.zero_lt_top EReal.zero_lt_top\n\n@[simp]\ntheorem zero_ne_top : (0 : EReal) \u2260 \u22a4 :=\n  coe_ne_top 0\n#align ereal.zero_ne_top EReal.zero_ne_top\n\n@[simp]\ntheorem top_ne_zero : (\u22a4 : EReal) \u2260 0 :=\n  (coe_ne_top 0).symm\n#align ereal.top_ne_zero EReal.top_ne_zero\n\ntheorem range_coe : range Real.toEReal = {\u22a5, \u22a4}\u1d9c := by\n  ext x\n  induction x using EReal.rec <;> simp\n\ntheorem range_coe_eq_Ioo : range Real.toEReal = Ioo \u22a5 \u22a4 := by\n  ext x\n  induction x using EReal.rec <;> simp\n\n@[simp, norm_cast]\ntheorem coe_add (x y : \u211d) : (\u2191(x + y) : EReal) = x + y :=\n  rfl\n#align ereal.coe_add EReal.coe_add\n\n-- `coe_mul` moved up\n\n@[norm_cast]\ntheorem coe_nsmul (n : \u2115) (x : \u211d) : (\u2191(n \u2022 x) : EReal) = n \u2022 (x : EReal) :=\n  map_nsmul (\u27e8\u27e8Real.toEReal, coe_zero\u27e9, coe_add\u27e9 : \u211d \u2192+ EReal) _ _\n#align ereal.coe_nsmul EReal.coe_nsmul\n\n#noalign ereal.coe_bit0\n#noalign ereal.coe_bit1\n\n@[simp, norm_cast]\ntheorem coe_eq_zero {x : \u211d} : (x : EReal) = 0 \u2194 x = 0 :=\n  EReal.coe_eq_coe_iff\n#align ereal.coe_eq_zero EReal.coe_eq_zero\n\n@[simp, norm_cast]\ntheorem coe_eq_one {x : \u211d} : (x : EReal) = 1 \u2194 x = 1 :=\n  EReal.coe_eq_coe_iff\n#align ereal.coe_eq_one EReal.coe_eq_one\n\ntheorem coe_ne_zero {x : \u211d} : (x : EReal) \u2260 0 \u2194 x \u2260 0 :=\n  EReal.coe_ne_coe_iff\n#align ereal.coe_ne_zero EReal.coe_ne_zero\n\ntheorem coe_ne_one {x : \u211d} : (x : EReal) \u2260 1 \u2194 x \u2260 1 :=\n  EReal.coe_ne_coe_iff\n#align ereal.coe_ne_one EReal.coe_ne_one\n\n@[simp, norm_cast]\nprotected theorem coe_nonneg {x : \u211d} : (0 : EReal) \u2264 x \u2194 0 \u2264 x :=\n  EReal.coe_le_coe_iff\n#align ereal.coe_nonneg EReal.coe_nonneg\n\n@[simp, norm_cast]\nprotected theorem coe_nonpos {x : \u211d} : (x : EReal) \u2264 0 \u2194 x \u2264 0 :=\n  EReal.coe_le_coe_iff\n#align ereal.coe_nonpos EReal.coe_nonpos\n\n@[simp, norm_cast]\nprotected theorem coe_pos {x : \u211d} : (0 : EReal) < x \u2194 0 < x :=\n  EReal.coe_lt_coe_iff\n#align ereal.coe_pos EReal.coe_pos\n\n@[simp, norm_cast]\nprotected theorem coe_neg' {x : \u211d} : (x : EReal) < 0 \u2194 x < 0 :=\n  EReal.coe_lt_coe_iff\n#align ereal.coe_neg' EReal.coe_neg'\n\ntheorem toReal_le_toReal {x y : EReal} (h : x \u2264 y) (hx : x \u2260 \u22a5) (hy : y \u2260 \u22a4) :\n    x.toReal \u2264 y.toReal := by\n  lift x to \u211d using \u27e8ne_top_of_le_ne_top hy h, hx\u27e9\n  lift y to \u211d using \u27e8hy, ne_bot_of_le_ne_bot hx h\u27e9\n  simpa using h\n#align ereal.to_real_le_to_real EReal.toReal_le_toReal\n\ntheorem coe_toReal {x : EReal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) : (x.toReal : EReal) = x := by\n  lift x to \u211d using \u27e8hx, h'x\u27e9\n  rfl\n#align ereal.coe_to_real EReal.coe_toReal\n\ntheorem le_coe_toReal {x : EReal} (h : x \u2260 \u22a4) : x \u2264 x.toReal := by\n  by_cases h' : x = \u22a5\n  \u00b7 simp only [h', bot_le]\n  \u00b7 simp only [le_refl, coe_toReal h h']\n#align ereal.le_coe_to_real EReal.le_coe_toReal\n\ntheorem coe_toReal_le {x : EReal} (h : x \u2260 \u22a5) : \u2191x.toReal \u2264 x := by\n  by_cases h' : x = \u22a4\n  \u00b7 simp only [h', le_top]\n  \u00b7 simp only [le_refl, coe_toReal h' h]\n#align ereal.coe_to_real_le EReal.coe_toReal_le\n\ntheorem eq_top_iff_forall_lt (x : EReal) : x = \u22a4 \u2194 \u2200 y : \u211d, (y : EReal) < x := by\n  constructor\n  \u00b7 rintro rfl\n    exact EReal.coe_lt_top\n  \u00b7 contrapose!\n    intro h\n    exact \u27e8x.toReal, le_coe_toReal h\u27e9\n#align ereal.eq_top_iff_forall_lt EReal.eq_top_iff_forall_lt\n\ntheorem eq_bot_iff_forall_lt (x : EReal) : x = \u22a5 \u2194 \u2200 y : \u211d, x < (y : EReal) := by\n  constructor\n  \u00b7 rintro rfl\n    exact bot_lt_coe\n  \u00b7 contrapose!\n    intro h\n    exact \u27e8x.toReal, coe_toReal_le h\u27e9\n#align ereal.eq_bot_iff_forall_lt EReal.eq_bot_iff_forall_lt\n\n/-! ### ennreal coercion -/\n\n@[simp]\ntheorem toReal_coe_ennreal : \u2200 {x : \u211d\u22650\u221e}, toReal (x : EReal) = ENNReal.toReal x\n  | \u22a4 => rfl\n  | .some _ => rfl\n#align ereal.to_real_coe_ennreal EReal.toReal_coe_ennreal\n\n@[simp]\ntheorem coe_ennreal_ofReal {x : \u211d} : (ENNReal.ofReal x : EReal) = max x 0 :=\n  rfl\n#align ereal.coe_ennreal_of_real EReal.coe_ennreal_ofReal\n\ntheorem coe_nnreal_eq_coe_real (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : EReal) = (x : \u211d) :=\n  rfl\n#align ereal.coe_nnreal_eq_coe_real EReal.coe_nnreal_eq_coe_real\n\n@[simp, norm_cast]\ntheorem coe_ennreal_zero : ((0 : \u211d\u22650\u221e) : EReal) = 0 :=\n  rfl\n#align ereal.coe_ennreal_zero EReal.coe_ennreal_zero\n\n@[simp, norm_cast]\ntheorem coe_ennreal_one : ((1 : \u211d\u22650\u221e) : EReal) = 1 :=\n  rfl\n#align ereal.coe_ennreal_one EReal.coe_ennreal_one\n\n@[simp, norm_cast]\ntheorem coe_ennreal_top : ((\u22a4 : \u211d\u22650\u221e) : EReal) = \u22a4 :=\n  rfl\n#align ereal.coe_ennreal_top EReal.coe_ennreal_top\n\ntheorem coe_ennreal_strictMono : StrictMono ((\u2191) : \u211d\u22650\u221e \u2192 EReal) :=\n  WithTop.strictMono_iff.2 \u27e8fun _ _ => EReal.coe_lt_coe_iff.2, fun _ => coe_lt_top _\u27e9\n#align ereal.coe_ennreal_strict_mono EReal.coe_ennreal_strictMono\n\ntheorem coe_ennreal_injective : Injective ((\u2191) : \u211d\u22650\u221e \u2192 EReal) :=\n  coe_ennreal_strictMono.injective\n#align ereal.coe_ennreal_injective EReal.coe_ennreal_injective\n\n@[simp]\ntheorem coe_ennreal_eq_top_iff {x : \u211d\u22650\u221e} : (x : EReal) = \u22a4 \u2194 x = \u22a4 :=\n  coe_ennreal_injective.eq_iff' rfl\n#align ereal.coe_ennreal_eq_top_iff EReal.coe_ennreal_eq_top_iff\n\ntheorem coe_nnreal_ne_top (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : EReal) \u2260 \u22a4 := coe_ne_top x\n#align ereal.coe_nnreal_ne_top EReal.coe_nnreal_ne_top\n\n@[simp]\ntheorem coe_nnreal_lt_top (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : EReal) < \u22a4 := coe_lt_top x\n#align ereal.coe_nnreal_lt_top EReal.coe_nnreal_lt_top\n\n@[simp, norm_cast]\ntheorem coe_ennreal_le_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) \u2264 (y : EReal) \u2194 x \u2264 y :=\n  coe_ennreal_strictMono.le_iff_le\n#align ereal.coe_ennreal_le_coe_ennreal_iff EReal.coe_ennreal_le_coe_ennreal_iff\n\n@[simp, norm_cast]\ntheorem coe_ennreal_lt_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) < (y : EReal) \u2194 x < y :=\n  coe_ennreal_strictMono.lt_iff_lt\n#align ereal.coe_ennreal_lt_coe_ennreal_iff EReal.coe_ennreal_lt_coe_ennreal_iff\n\n@[simp, norm_cast]\ntheorem coe_ennreal_eq_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) = (y : EReal) \u2194 x = y :=\n  coe_ennreal_injective.eq_iff\n#align ereal.coe_ennreal_eq_coe_ennreal_iff EReal.coe_ennreal_eq_coe_ennreal_iff\n\ntheorem coe_ennreal_ne_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) \u2260 (y : EReal) \u2194 x \u2260 y :=\n  coe_ennreal_injective.ne_iff\n#align ereal.coe_ennreal_ne_coe_ennreal_iff EReal.coe_ennreal_ne_coe_ennreal_iff\n\n@[simp, norm_cast]\ntheorem coe_ennreal_eq_zero {x : \u211d\u22650\u221e} : (x : EReal) = 0 \u2194 x = 0 := by\n  rw [\u2190 coe_ennreal_eq_coe_ennreal_iff, coe_ennreal_zero]\n#align ereal.coe_ennreal_eq_zero EReal.coe_ennreal_eq_zero\n\n@[simp, norm_cast]\ntheorem coe_ennreal_eq_one {x : \u211d\u22650\u221e} : (x : EReal) = 1 \u2194 x = 1 := by\n  rw [\u2190 coe_ennreal_eq_coe_ennreal_iff, coe_ennreal_one]\n#align ereal.coe_ennreal_eq_one EReal.coe_ennreal_eq_one\n\n@[norm_cast]\ntheorem coe_ennreal_ne_zero {x : \u211d\u22650\u221e} : (x : EReal) \u2260 0 \u2194 x \u2260 0 :=\n  coe_ennreal_eq_zero.not\n#align ereal.coe_ennreal_ne_zero EReal.coe_ennreal_ne_zero\n\n@[norm_cast]\ntheorem coe_ennreal_ne_one {x : \u211d\u22650\u221e} : (x : EReal) \u2260 1 \u2194 x \u2260 1 :=\n  coe_ennreal_eq_one.not\n#align ereal.coe_ennreal_ne_one EReal.coe_ennreal_ne_one\n\ntheorem coe_ennreal_nonneg (x : \u211d\u22650\u221e) : (0 : EReal) \u2264 x :=\n  coe_ennreal_le_coe_ennreal_iff.2 (zero_le x)\n#align ereal.coe_ennreal_nonneg EReal.coe_ennreal_nonneg\n\n@[simp] theorem range_coe_ennreal : range ((\u2191) : \u211d\u22650\u221e \u2192 EReal) = Set.Ici 0 :=\n  Subset.antisymm (range_subset_iff.2 coe_ennreal_nonneg) fun x => match x with\n    | \u22a5 => fun h => absurd h bot_lt_zero.not_le\n    | \u22a4 => fun _ => \u27e8\u22a4, rfl\u27e9\n    | (x : \u211d) => fun h => \u27e8.some \u27e8x, EReal.coe_nonneg.1 h\u27e9, rfl\u27e9\n\ninstance : CanLift EReal \u211d\u22650\u221e (\u2191) (0 \u2264 \u00b7) := \u27e8range_coe_ennreal.ge\u27e9\n\n@[simp, norm_cast]\ntheorem coe_ennreal_pos {x : \u211d\u22650\u221e} : (0 : EReal) < x \u2194 0 < x := by\n  rw [\u2190 coe_ennreal_zero, coe_ennreal_lt_coe_ennreal_iff]\n#align ereal.coe_ennreal_pos EReal.coe_ennreal_pos\n\n@[simp]\ntheorem bot_lt_coe_ennreal (x : \u211d\u22650\u221e) : (\u22a5 : EReal) < x :=\n  (bot_lt_coe 0).trans_le (coe_ennreal_nonneg _)\n#align ereal.bot_lt_coe_ennreal EReal.bot_lt_coe_ennreal\n\n@[simp]\ntheorem coe_ennreal_ne_bot (x : \u211d\u22650\u221e) : (x : EReal) \u2260 \u22a5 :=\n  (bot_lt_coe_ennreal x).ne'\n#align ereal.coe_ennreal_ne_bot EReal.coe_ennreal_ne_bot\n\n@[simp, norm_cast]\ntheorem coe_ennreal_add (x y : ENNReal) : ((x + y : \u211d\u22650\u221e) : EReal) = x + y := by\n  cases x <;> cases y <;> rfl\n#align ereal.coe_ennreal_add EReal.coe_ennreal_add\n\nprivate theorem coe_ennreal_top_mul (x : \u211d\u22650) : ((\u22a4 * x : \u211d\u22650\u221e) : EReal) = \u22a4 * x := by\n  rcases eq_or_ne x 0 with (rfl | h0)\n  \u00b7 simp\n  \u00b7 rw [ENNReal.top_mul (ENNReal.coe_ne_zero.2 h0)]\n    exact Eq.symm <| if_pos <| NNReal.coe_pos.2 h0.bot_lt\n\n@[simp, norm_cast]\ntheorem coe_ennreal_mul : \u2200 x y : \u211d\u22650\u221e, ((x * y : \u211d\u22650\u221e) : EReal) = (x : EReal) * y\n  | \u22a4, \u22a4 => rfl\n  | \u22a4, (y : \u211d\u22650) => coe_ennreal_top_mul y\n  | (x : \u211d\u22650), \u22a4 => by\n    rw [mul_comm, coe_ennreal_top_mul, EReal.mul_comm, coe_ennreal_top]\n  | (x : \u211d\u22650), (y : \u211d\u22650) => by\n    simp only [\u2190 ENNReal.coe_mul, coe_nnreal_eq_coe_real, NNReal.coe_mul, EReal.coe_mul]\n#align ereal.coe_ennreal_mul EReal.coe_ennreal_mul\n\n@[norm_cast]\ntheorem coe_ennreal_nsmul (n : \u2115) (x : \u211d\u22650\u221e) : (\u2191(n \u2022 x) : EReal) = n \u2022 (x : EReal) :=\n  map_nsmul (\u27e8\u27e8(\u2191), coe_ennreal_zero\u27e9, coe_ennreal_add\u27e9 : \u211d\u22650\u221e \u2192+ EReal) _ _\n#align ereal.coe_ennreal_nsmul EReal.coe_ennreal_nsmul\n\n#noalign ereal.coe_ennreal_bit0\n#noalign ereal.coe_ennreal_bit1\n\n/-! ### Order -/\n\ntheorem exists_rat_btwn_of_lt :\n    \u2200 {a b : EReal}, a < b \u2192 \u2203 x : \u211a, a < (x : \u211d) \u2227 ((x : \u211d) : EReal) < b\n  | \u22a4, b, h => (not_top_lt h).elim\n  | (a : \u211d), \u22a5, h => (lt_irrefl _ ((bot_lt_coe a).trans h)).elim\n  | (a : \u211d), (b : \u211d), h => by simp [exists_rat_btwn (EReal.coe_lt_coe_iff.1 h)]\n  | (a : \u211d), \u22a4, _ =>\n    let \u27e8b, hab\u27e9 := exists_rat_gt a\n    \u27e8b, by simpa using hab, coe_lt_top _\u27e9\n  | \u22a5, \u22a5, h => (lt_irrefl _ h).elim\n  | \u22a5, (a : \u211d), _ =>\n    let \u27e8b, hab\u27e9 := exists_rat_lt a\n    \u27e8b, bot_lt_coe _, by simpa using hab\u27e9\n  | \u22a5, \u22a4, _ => \u27e80, bot_lt_coe _, coe_lt_top _\u27e9\n#align ereal.exists_rat_btwn_of_lt EReal.exists_rat_btwn_of_lt\n\ntheorem lt_iff_exists_rat_btwn {a b : EReal} :\n    a < b \u2194 \u2203 x : \u211a, a < (x : \u211d) \u2227 ((x : \u211d) : EReal) < b :=\n  \u27e8fun hab => exists_rat_btwn_of_lt hab, fun \u27e8_x, ax, xb\u27e9 => ax.trans xb\u27e9\n#align ereal.lt_iff_exists_rat_btwn EReal.lt_iff_exists_rat_btwn\n\ntheorem lt_iff_exists_real_btwn {a b : EReal} : a < b \u2194 \u2203 x : \u211d, a < x \u2227 (x : EReal) < b :=\n  \u27e8fun hab =>\n    let \u27e8x, ax, xb\u27e9 := exists_rat_btwn_of_lt hab\n    \u27e8(x : \u211d), ax, xb\u27e9,\n    fun \u27e8_x, ax, xb\u27e9 => ax.trans xb\u27e9\n#align ereal.lt_iff_exists_real_btwn EReal.lt_iff_exists_real_btwn\n\n/-- The set of numbers in `EReal` that are not equal to `\u00b1\u221e` is equivalent to `\u211d`. -/\ndef neTopBotEquivReal : ({\u22a5, \u22a4}\u1d9c : Set EReal) \u2243 \u211d where\n  toFun x := EReal.toReal x\n  invFun x := \u27e8x, by simp\u27e9\n  left_inv := fun \u27e8x, hx\u27e9 => by\n      lift x to \u211d\n      \u00b7 simpa [not_or, and_comm] using hx\n      \u00b7 simp\n  right_inv x := by simp\n#align ereal.ne_top_bot_equiv_real EReal.neTopBotEquivReal\n\n/-! ### Addition -/\n\n@[simp]\ntheorem add_bot (x : EReal) : x + \u22a5 = \u22a5 :=\n  WithBot.add_bot _\n#align ereal.add_bot EReal.add_bot\n\n@[simp]\ntheorem bot_add (x : EReal) : \u22a5 + x = \u22a5 :=\n  WithBot.bot_add _\n#align ereal.bot_add EReal.bot_add\n\n@[simp]\ntheorem add_eq_bot_iff {x y : EReal} : x + y = \u22a5 \u2194 x = \u22a5 \u2228 y = \u22a5 :=\n  WithBot.add_eq_bot\n#align ereal.add_eq_bot_iff EReal.add_eq_bot_iff\n\n@[simp]\ntheorem bot_lt_add_iff {x y : EReal} : \u22a5 < x + y \u2194 \u22a5 < x \u2227 \u22a5 < y := by\n  simp [bot_lt_iff_ne_bot, not_or]\n#align ereal.bot_lt_add_iff EReal.bot_lt_add_iff\n\n@[simp]\ntheorem top_add_top : (\u22a4 : EReal) + \u22a4 = \u22a4 :=\n  rfl\n#align ereal.top_add_top EReal.top_add_top\n\n@[simp]\ntheorem top_add_coe (x : \u211d) : (\u22a4 : EReal) + x = \u22a4 :=\n  rfl\n#align ereal.top_add_coe EReal.top_add_coe\n\n@[simp]\ntheorem coe_add_top (x : \u211d) : (x : EReal) + \u22a4 = \u22a4 :=\n  rfl\n#align ereal.coe_add_top EReal.coe_add_top\n\ntheorem toReal_add {x y : EReal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) (hy : y \u2260 \u22a4) (h'y : y \u2260 \u22a5) :\n    toReal (x + y) = toReal x + toReal y := by\n  lift x to \u211d using \u27e8hx, h'x\u27e9\n  lift y to \u211d using \u27e8hy, h'y\u27e9\n  rfl\n#align ereal.to_real_add EReal.toReal_add\n\ntheorem addLECancellable_coe (x : \u211d) : AddLECancellable (x : EReal)\n  | _, \u22a4, _ => le_top\n  | \u22a5, _, _ => bot_le\n  | \u22a4, (z : \u211d), h => by simp only [coe_add_top, \u2190 coe_add, top_le_iff, coe_ne_top] at h\n  | _, \u22a5, h => by simpa using h\n  | (y : \u211d), (z : \u211d), h => by\n    simpa only [\u2190 coe_add, EReal.coe_le_coe_iff, add_le_add_iff_left] using h\n\n-- porting note: todo: add `MulLECancellable.strictMono*` etc\ntheorem add_lt_add_right_coe {x y : EReal} (h : x < y) (z : \u211d) : x + z < y + z :=\n  not_le.1 <| mt (addLECancellable_coe z).add_le_add_iff_right.1 h.not_le\n#align ereal.add_lt_add_right_coe EReal.add_lt_add_right_coe\n\ntheorem add_lt_add_left_coe {x y : EReal} (h : x < y) (z : \u211d) : (z : EReal) + x < z + y := by\n  simpa [add_comm] using add_lt_add_right_coe h z\n#align ereal.add_lt_add_left_coe EReal.add_lt_add_left_coe\n\ntheorem add_lt_add {x y z t : EReal} (h1 : x < y) (h2 : z < t) : x + z < y + t := by\n  rcases eq_or_ne x \u22a5 with (rfl | hx)\n  \u00b7 simp [h1, bot_le.trans_lt h2]\n  \u00b7 lift x to \u211d using \u27e8h1.ne_top, hx\u27e9\n    calc (x : EReal) + z < x + t := add_lt_add_left_coe h2 _\n    _ \u2264 y + t := add_le_add_right h1.le _\n#align ereal.add_lt_add EReal.add_lt_add\n\ntheorem add_lt_add_of_lt_of_le' {x y z t : EReal} (h : x < y) (h' : z \u2264 t) (hbot : t \u2260 \u22a5)\n    (htop : t = \u22a4 \u2192 z = \u22a4 \u2192 x = \u22a5) : x + z < y + t := by\n  rcases h'.eq_or_lt with (rfl | hlt)\n  \u00b7 rcases eq_or_ne z \u22a4 with (rfl | hz)\n    \u00b7 obtain rfl := htop rfl rfl\n      simpa\n    lift z to \u211d using \u27e8hz, hbot\u27e9\n    exact add_lt_add_right_coe h z\n  \u00b7 exact add_lt_add h hlt\n\n/-- See also `EReal.add_lt_add_of_lt_of_le'` for a version with weaker but less convenient\nassumptions. -/\ntheorem add_lt_add_of_lt_of_le {x y z t : EReal} (h : x < y) (h' : z \u2264 t) (hz : z \u2260 \u22a5)\n    (ht : t \u2260 \u22a4) : x + z < y + t :=\n  add_lt_add_of_lt_of_le' h h' (ne_bot_of_le_ne_bot hz h') <| fun ht' => (ht ht').elim\n#align ereal.add_lt_add_of_lt_of_le EReal.add_lt_add_of_lt_of_le\n\ntheorem add_lt_top {x y : EReal} (hx : x \u2260 \u22a4) (hy : y \u2260 \u22a4) : x + y < \u22a4 := by\n  rw [\u2190 EReal.top_add_top]\n  exact EReal.add_lt_add hx.lt_top hy.lt_top\n#align ereal.add_lt_top EReal.add_lt_top\n\n/-! ### Negation -/\n\n/-- negation on `EReal` -/\nprotected def neg : EReal \u2192 EReal\n  | \u22a5 => \u22a4\n  | \u22a4 => \u22a5\n  | (x : \u211d) => (-x : \u211d)\n#align ereal.neg EReal.neg\n\ninstance : Neg EReal := \u27e8EReal.neg\u27e9\n\ninstance : SubNegZeroMonoid EReal where\n  neg_zero := congr_arg Real.toEReal neg_zero\n\n@[simp]\ntheorem neg_top : -(\u22a4 : EReal) = \u22a5 :=\n  rfl\n#align ereal.neg_top EReal.neg_top\n\n@[simp]\ntheorem neg_bot : -(\u22a5 : EReal) = \u22a4 :=\n  rfl\n#align ereal.neg_bot EReal.neg_bot\n\n@[simp, norm_cast] theorem coe_neg (x : \u211d) : (\u2191(-x) : EReal) = -\u2191x := rfl\n#align ereal.coe_neg EReal.coe_neg\n#align ereal.neg_def EReal.coe_neg\n\n@[simp, norm_cast] theorem coe_sub (x y : \u211d) : (\u2191(x - y) : EReal) = x - y := rfl\n#align ereal.coe_sub EReal.coe_sub\n\n@[norm_cast]\ntheorem coe_zsmul (n : \u2124) (x : \u211d) : (\u2191(n \u2022 x) : EReal) = n \u2022 (x : EReal) :=\n  map_zsmul' (\u27e8\u27e8(\u2191), coe_zero\u27e9, coe_add\u27e9 : \u211d \u2192+ EReal) coe_neg _ _\n#align ereal.coe_zsmul EReal.coe_zsmul\n\ninstance : InvolutiveNeg EReal where\n  neg_neg a :=\n    match a with\n    | \u22a5 => rfl\n    | \u22a4 => rfl\n    | (a : \u211d) => congr_arg Real.toEReal (neg_neg a)\n\n@[simp]\ntheorem toReal_neg : \u2200 {a : EReal}, toReal (-a) = -toReal a\n  | \u22a4 => by simp\n  | \u22a5 => by simp\n  | (x : \u211d) => rfl\n#align ereal.to_real_neg EReal.toReal_neg\n\n@[simp]\ntheorem neg_eq_top_iff {x : EReal} : -x = \u22a4 \u2194 x = \u22a5 :=\n  neg_injective.eq_iff' rfl\n#align ereal.neg_eq_top_iff EReal.neg_eq_top_iff\n\n@[simp]\ntheorem neg_eq_bot_iff {x : EReal} : -x = \u22a5 \u2194 x = \u22a4 :=\n  neg_injective.eq_iff' rfl\n#align ereal.neg_eq_bot_iff EReal.neg_eq_bot_iff\n\n@[simp]\ntheorem neg_eq_zero_iff {x : EReal} : -x = 0 \u2194 x = 0 :=\n  neg_injective.eq_iff' neg_zero\n#align ereal.neg_eq_zero_iff EReal.neg_eq_zero_iff\n\ntheorem neg_strictAnti : StrictAnti (- \u00b7 : EReal \u2192 EReal) :=\n  WithBot.strictAnti_iff.2 \u27e8WithTop.strictAnti_iff.2\n    \u27e8coe_strictMono.comp_strictAnti fun _ _ => neg_lt_neg, fun _ => bot_lt_coe _\u27e9,\n      WithTop.forall.2 \u27e8bot_lt_top, fun _ => coe_lt_top _\u27e9\u27e9\n\n@[simp] theorem neg_le_neg_iff {a b : EReal} : -a \u2264 -b \u2194 b \u2264 a := neg_strictAnti.le_iff_le\n#align ereal.neg_le_neg_iff EReal.neg_le_neg_iff\n\n-- porting note: new lemma\n@[simp] theorem neg_lt_neg_iff {a b : EReal} : -a < -b \u2194 b < a := neg_strictAnti.lt_iff_lt\n\n/-- `-a \u2264 b \u2194 -b \u2264 a` on `EReal`. -/\nprotected theorem neg_le {a b : EReal} : -a \u2264 b \u2194 -b \u2264 a := by\n rw [\u2190 neg_le_neg_iff, neg_neg]\n#align ereal.neg_le EReal.neg_le\n\n/-- if `-a \u2264 b` then `-b \u2264 a` on `EReal`. -/\nprotected theorem neg_le_of_neg_le {a b : EReal} (h : -a \u2264 b) : -b \u2264 a := EReal.neg_le.mp h\n#align ereal.neg_le_of_neg_le EReal.neg_le_of_neg_le\n\n/-- `a \u2264 -b \u2192 b \u2264 -a` on ereal -/\ntheorem le_neg_of_le_neg {a b : EReal} (h : a \u2264 -b) : b \u2264 -a := by\n  rwa [\u2190 neg_neg b, EReal.neg_le, neg_neg]\n#align ereal.le_neg_of_le_neg EReal.le_neg_of_le_neg\n\n/-- Negation as an order reversing isomorphism on `EReal`. -/\ndef negOrderIso : EReal \u2243o EReal\u1d52\u1d48 :=\n  { Equiv.neg EReal with\n    toFun := fun x => OrderDual.toDual (-x)\n    invFun := fun x => -OrderDual.ofDual x\n    map_rel_iff' := neg_le_neg_iff }\n#align ereal.neg_order_iso EReal.negOrderIso\n\ntheorem neg_lt_iff_neg_lt {a b : EReal} : -a < b \u2194 -b < a := by\n  rw [\u2190 neg_lt_neg_iff, neg_neg]\n#align ereal.neg_lt_iff_neg_lt EReal.neg_lt_iff_neg_lt\n\ntheorem neg_lt_of_neg_lt {a b : EReal} (h : -a < b) : -b < a := neg_lt_iff_neg_lt.1 h\n#align ereal.neg_lt_of_neg_lt EReal.neg_lt_of_neg_lt\n\n/-!\n### Subtraction\n\nSubtraction on `EReal` is defined by `x - y = x + (-y)`. Since addition is badly behaved at some\npoints, so is subtraction. There is no standard algebraic typeclass involving subtraction that is\nregistered on `EReal`, beyond `SubNegZeroMonoid`, because of this bad behavior.\n-/\n\n@[simp]\ntheorem bot_sub (x : EReal) : \u22a5 - x = \u22a5 :=\n  bot_add x\n#align ereal.bot_sub EReal.bot_sub\n\n@[simp]\ntheorem sub_top (x : EReal) : x - \u22a4 = \u22a5 :=\n  add_bot x\n#align ereal.sub_top EReal.sub_top\n\n@[simp]\ntheorem top_sub_bot : (\u22a4 : EReal) - \u22a5 = \u22a4 :=\n  rfl\n#align ereal.top_sub_bot EReal.top_sub_bot\n\n@[simp]\ntheorem top_sub_coe (x : \u211d) : (\u22a4 : EReal) - x = \u22a4 :=\n  rfl\n#align ereal.top_sub_coe EReal.top_sub_coe\n\n@[simp]\ntheorem coe_sub_bot (x : \u211d) : (x : EReal) - \u22a5 = \u22a4 :=\n  rfl\n#align ereal.coe_sub_bot EReal.coe_sub_bot\n\ntheorem sub_le_sub {x y z t : EReal} (h : x \u2264 y) (h' : t \u2264 z) : x - z \u2264 y - t :=\n  add_le_add h (neg_le_neg_iff.2 h')\n#align ereal.sub_le_sub EReal.sub_le_sub\n\ntheorem sub_lt_sub_of_lt_of_le {x y z t : EReal} (h : x < y) (h' : z \u2264 t) (hz : z \u2260 \u22a5)\n    (ht : t \u2260 \u22a4) : x - t < y - z :=\n  add_lt_add_of_lt_of_le h (neg_le_neg_iff.2 h') (by simp [ht]) (by simp [hz])\n#align ereal.sub_lt_sub_of_lt_of_le EReal.sub_lt_sub_of_lt_of_le\n\ntheorem coe_real_ereal_eq_coe_toNNReal_sub_coe_toNNReal (x : \u211d) :\n    (x : EReal) = Real.toNNReal x - Real.toNNReal (-x) := by\n  rcases le_total 0 x with (h | h)\n  \u00b7 lift x to \u211d\u22650 using h\n    rw [Real.toNNReal_of_nonpos (neg_nonpos.mpr x.coe_nonneg), Real.toNNReal_coe, ENNReal.coe_zero,\n      coe_ennreal_zero, sub_zero]\n    rfl\n  \u00b7 rw [Real.toNNReal_of_nonpos h, ENNReal.coe_zero, coe_ennreal_zero, coe_nnreal_eq_coe_real,\n      Real.coe_toNNReal, zero_sub, coe_neg, neg_neg]\n    exact neg_nonneg.2 h\n#align ereal.coe_real_ereal_eq_coe_to_nnreal_sub_coe_to_nnreal EReal.coe_real_ereal_eq_coe_toNNReal_sub_coe_toNNReal\n\ntheorem toReal_sub {x y : EReal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) (hy : y \u2260 \u22a4) (h'y : y \u2260 \u22a5) :\n    toReal (x - y) = toReal x - toReal y := by\n  lift x to \u211d using \u27e8hx, h'x\u27e9\n  lift y to \u211d using \u27e8hy, h'y\u27e9\n  rfl\n#align ereal.to_real_sub EReal.toReal_sub\n\n/-! ### Multiplication -/\n\n@[simp] theorem top_mul_top : (\u22a4 : EReal) * \u22a4 = \u22a4 := rfl\n#align ereal.top_mul_top EReal.top_mul_top\n\n@[simp] theorem top_mul_bot : (\u22a4 : EReal) * \u22a5 = \u22a5 := rfl\n#align ereal.top_mul_bot EReal.top_mul_bot\n\n@[simp] theorem bot_mul_top : (\u22a5 : EReal) * \u22a4 = \u22a5 := rfl\n#align ereal.bot_mul_top EReal.bot_mul_top\n\n@[simp] theorem bot_mul_bot : (\u22a5 : EReal) * \u22a5 = \u22a4 := rfl\n#align ereal.bot_mul_bot EReal.bot_mul_bot\n\ntheorem coe_mul_top_of_pos {x : \u211d} (h : 0 < x) : (x : EReal) * \u22a4 = \u22a4 :=\n  if_pos h\n#align ereal.coe_mul_top_of_pos EReal.coe_mul_top_of_pos\n\ntheorem coe_mul_top_of_neg {x : \u211d} (h : x < 0) : (x : EReal) * \u22a4 = \u22a5 :=\n  (if_neg h.not_lt).trans (if_neg h.ne)\n#align ereal.coe_mul_top_of_neg EReal.coe_mul_top_of_neg\n\ntheorem top_mul_coe_of_pos {x : \u211d} (h : 0 < x) : (\u22a4 : EReal) * x = \u22a4 :=\n  if_pos h\n#align ereal.top_mul_coe_of_pos EReal.top_mul_coe_of_pos\n\ntheorem top_mul_coe_of_neg {x : \u211d} (h : x < 0) : (\u22a4 : EReal) * x = \u22a5 :=\n  (if_neg h.not_lt).trans (if_neg h.ne)\n#align ereal.top_mul_coe_of_neg EReal.top_mul_coe_of_neg\n\ntheorem mul_top_of_pos : \u2200 {x : EReal}, 0 < x \u2192 x * \u22a4 = \u22a4\n  | \u22a5, h => absurd h not_lt_bot\n  | (x : \u211d), h => coe_mul_top_of_pos (EReal.coe_pos.1 h)\n  | \u22a4, _ => rfl\n#align ereal.mul_top_of_pos EReal.mul_top_of_pos\n\ntheorem mul_top_of_neg : \u2200 {x : EReal}, x < 0 \u2192 x * \u22a4 = \u22a5\n  | \u22a5, _ => rfl\n  | (x : \u211d), h => coe_mul_top_of_neg (EReal.coe_neg'.1 h)\n  | \u22a4, h => absurd h not_top_lt\n#align ereal.mul_top_of_neg EReal.mul_top_of_neg\n\ntheorem top_mul_of_pos {x : EReal} (h : 0 < x) : \u22a4 * x = \u22a4 := by\n  rw [EReal.mul_comm]\n  exact mul_top_of_pos h\n#align ereal.top_mul_of_pos EReal.top_mul_of_pos\n\ntheorem top_mul_of_neg {x : EReal} (h : x < 0) : \u22a4 * x = \u22a5 := by\n  rw [EReal.mul_comm]\n  exact mul_top_of_neg h\n#align ereal.top_mul_of_neg EReal.top_mul_of_neg\n\ntheorem coe_mul_bot_of_pos {x : \u211d} (h : 0 < x) : (x : EReal) * \u22a5 = \u22a5 :=\n  if_pos h\n#align ereal.coe_mul_bot_of_pos EReal.coe_mul_bot_of_pos\n\ntheorem coe_mul_bot_of_neg {x : \u211d} (h : x < 0) : (x : EReal) * \u22a5 = \u22a4 :=\n  (if_neg h.not_lt).trans (if_neg h.ne)\n#align ereal.coe_mul_bot_of_neg EReal.coe_mul_bot_of_neg\n\ntheorem bot_mul_coe_of_pos {x : \u211d} (h : 0 < x) : (\u22a5 : EReal) * x = \u22a5 :=\n  if_pos h\n#align ereal.bot_mul_coe_of_pos EReal.bot_mul_coe_of_pos\n\ntheorem bot_mul_coe_of_neg {x : \u211d} (h : x < 0) : (\u22a5 : EReal) * x = \u22a4 :=\n  (if_neg h.not_lt).trans (if_neg h.ne)\n#align ereal.bot_mul_coe_of_neg EReal.bot_mul_coe_of_neg\n\ntheorem mul_bot_of_pos : \u2200 {x : EReal}, 0 < x \u2192 x * \u22a5 = \u22a5\n  | \u22a5, h => absurd h not_lt_bot\n  | (x : \u211d), h => coe_mul_bot_of_pos (EReal.coe_pos.1 h)\n  | \u22a4, _ => rfl\n#align ereal.mul_bot_of_pos EReal.mul_bot_of_pos\n\ntheorem mul_bot_of_neg : \u2200 {x : EReal}, x < 0 \u2192 x * \u22a5 = \u22a4\n  | \u22a5, _ => rfl\n  | (x : \u211d), h => coe_mul_bot_of_neg (EReal.coe_neg'.1 h)\n  | \u22a4, h => absurd h not_top_lt\n#align ereal.mul_bot_of_neg EReal.mul_bot_of_neg\n\ntheorem bot_mul_of_pos {x : EReal} (h : 0 < x) : \u22a5 * x = \u22a5 := by\n  rw [EReal.mul_comm]\n  exact mul_bot_of_pos h\n#align ereal.bot_mul_of_pos EReal.bot_mul_of_pos\n\ntheorem bot_mul_of_neg {x : EReal} (h : x < 0) : \u22a5 * x = \u22a4 := by\n  rw [EReal.mul_comm]\n  exact mul_bot_of_neg h\n#align ereal.bot_mul_of_neg EReal.bot_mul_of_neg\n\ntheorem toReal_mul {x y : EReal} : toReal (x * y) = toReal x * toReal y := by\n  induction x, y using induction\u2082_symm with\n  | top_zero | zero_bot | top_top | top_bot | bot_bot => simp\n  | symm h => rwa [mul_comm, EReal.mul_comm]\n  | coe_coe => norm_cast\n  | top_pos _ h => simp [top_mul_coe_of_pos h]\n  | top_neg _ h => simp [top_mul_coe_of_neg h]\n  | pos_bot _ h => simp [coe_mul_bot_of_pos h]\n  | neg_bot _ h => simp [coe_mul_bot_of_neg h]\n#align ereal.to_real_mul EReal.toReal_mul\n\n/-- Induct on two ereals by performing case splits on the sign of one whenever the other is\ninfinite. This version eliminates some cases by assuming that `P x y` implies `P (-x) y` for all\n`x`, `y`. -/\n@[elab_as_elim]\ntheorem induction\u2082_neg_left {P : EReal \u2192 EReal \u2192 Prop} (neg_left : \u2200 {x y}, P x y \u2192 P (-x) y)\n    (top_top : P \u22a4 \u22a4) (top_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a4 x)\n    (top_zero : P \u22a4 0) (top_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a4 x) (top_bot : P \u22a4 \u22a5)\n    (zero_top : P 0 \u22a4) (zero_bot : P 0 \u22a5)\n    (pos_top : \u2200 x : \u211d, 0 < x \u2192 P x \u22a4) (pos_bot : \u2200 x : \u211d, 0 < x \u2192 P x \u22a5)\n    (coe_coe : \u2200 x y : \u211d, P x y) : \u2200 x y, P x y :=\n  have : \u2200 y, (\u2200 x : \u211d, 0 < x \u2192 P x y) \u2192 \u2200 x : \u211d, x < 0 \u2192 P x y := fun _ h x hx =>\n    neg_neg (x : EReal) \u25b8 neg_left <| h _ (neg_pos_of_neg hx)\n  @induction\u2082 P top_top top_pos top_zero top_neg top_bot pos_top pos_bot zero_top\n    coe_coe zero_bot (this _ pos_top) (this _ pos_bot) (neg_left top_top)\n    (fun x hx => neg_left <| top_pos x hx) (neg_left top_zero)\n    (fun x hx => neg_left <| top_neg x hx) (neg_left top_bot)\n\n/-- Induct on two ereals by performing case splits on the sign of one whenever the other is\ninfinite. This version eliminates some cases by assuming that `P` is symmetric and `P x y` implies\n`P (-x) y` for all `x`, `y`. -/\n@[elab_as_elim]\ntheorem induction\u2082_symm_neg {P : EReal \u2192 EReal \u2192 Prop}\n    (symm : Symmetric P) (neg_left : \u2200 {x y}, P x y \u2192 P (-x) y) (top_top : P \u22a4 \u22a4)\n    (top_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a4 x) (top_zero : P \u22a4 0) (coe_coe : \u2200 x y : \u211d, P x y) :\n    \u2200 x y, P x y :=\n  have neg_right : \u2200 {x y}, P x y \u2192 P x (-y) := fun h => symm <| neg_left <| symm h\n  have : \u2200 x, (\u2200 y : \u211d, 0 < y \u2192 P x y) \u2192 \u2200 y : \u211d, y < 0 \u2192 P x y := fun _ h y hy =>\n    neg_neg (y : EReal) \u25b8 neg_right (h _ (neg_pos_of_neg hy))\n  @induction\u2082_neg_left P neg_left top_top top_pos top_zero (this _ top_pos) (neg_right top_top)\n    (symm top_zero) (symm <| neg_left top_zero) (fun x hx => symm <| top_pos x hx)\n    (fun x hx => symm <| neg_left <| top_pos x hx) coe_coe\n\nprotected theorem neg_mul (x y : EReal) : -x * y = -(x * y) := by\n  induction x, y using induction\u2082_neg_left with\n  | top_zero | zero_top | zero_bot => simp only [zero_mul, mul_zero, neg_zero]\n  | top_top | top_bot => rfl\n  | neg_left h => rw [h, neg_neg, neg_neg]\n  | coe_coe => norm_cast; exact neg_mul _ _\n  | top_pos _ h => rw [top_mul_coe_of_pos h, neg_top, bot_mul_coe_of_pos h]\n  | pos_top _ h => rw [coe_mul_top_of_pos h, neg_top, \u2190 coe_neg,\n    coe_mul_top_of_neg (neg_neg_of_pos h)]\n  | top_neg _ h => rw [top_mul_coe_of_neg h, neg_top, bot_mul_coe_of_neg h, neg_bot]\n  | pos_bot _ h => rw [coe_mul_bot_of_pos h, neg_bot, \u2190 coe_neg,\n    coe_mul_bot_of_neg (neg_neg_of_pos h)]\n#align ereal.neg_mul EReal.neg_mul\n\ninstance : HasDistribNeg EReal where\n  neg_mul := EReal.neg_mul\n  mul_neg := fun x y => by\n    rw [x.mul_comm, x.mul_comm]\n    exact y.neg_mul x\n\n/-! ### Absolute value -/\n\n-- porting note: todo: use `Real.nnabs` for the case `(x : \u211d)`\n/-- The absolute value from `EReal` to `\u211d\u22650\u221e`, mapping `\u22a5` and `\u22a4` to `\u22a4` and\na real `x` to `|x|`. -/\nprotected def abs : EReal \u2192 \u211d\u22650\u221e\n  | \u22a5 => \u22a4\n  | \u22a4 => \u22a4\n  | (x : \u211d) => ENNReal.ofReal (|x|)\n#align ereal.abs EReal.abs\n\n@[simp] theorem abs_top : (\u22a4 : EReal).abs = \u22a4 := rfl\n#align ereal.abs_top EReal.abs_top\n\n@[simp] theorem abs_bot : (\u22a5 : EReal).abs = \u22a4 := rfl\n#align ereal.abs_bot EReal.abs_bot\n\ntheorem abs_def (x : \u211d) : (x : EReal).abs = ENNReal.ofReal (|x|) := rfl\n#align ereal.abs_def EReal.abs_def\n\ntheorem abs_coe_lt_top (x : \u211d) : (x : EReal).abs < \u22a4 :=\n  ENNReal.ofReal_lt_top\n#align ereal.abs_coe_lt_top EReal.abs_coe_lt_top\n\n@[simp]\ntheorem abs_eq_zero_iff {x : EReal} : x.abs = 0 \u2194 x = 0 := by\n  induction x using EReal.rec\n  \u00b7 simp only [abs_bot, ENNReal.top_ne_zero, bot_ne_zero]\n  \u00b7 simp only [abs_def, coe_eq_zero, ENNReal.ofReal_eq_zero, abs_nonpos_iff]\n  \u00b7 simp only [abs_top, ENNReal.top_ne_zero, top_ne_zero]\n#align ereal.abs_eq_zero_iff EReal.abs_eq_zero_iff\n\n@[simp]\ntheorem abs_zero : (0 : EReal).abs = 0 := by rw [abs_eq_zero_iff]\n#align ereal.abs_zero EReal.abs_zero\n\n@[simp]\ntheorem coe_abs (x : \u211d) : ((x : EReal).abs : EReal) = (|x| : \u211d) := by\n  rw [abs_def, \u2190 Real.coe_nnabs, ENNReal.ofReal_coe_nnreal]; rfl\n#align ereal.coe_abs EReal.coe_abs\n\n@[simp]\nprotected theorem abs_neg : \u2200 x : EReal, (-x).abs = x.abs\n  | \u22a4 => rfl\n  | \u22a5 => rfl\n  | (x : \u211d) => by rw [abs_def, \u2190 coe_neg, abs_def, abs_neg]\n\n@[simp]\ntheorem abs_mul (x y : EReal) : (x * y).abs = x.abs * y.abs := by\n  induction x, y using induction\u2082_symm_neg with\n  | top_zero => simp only [zero_mul, mul_zero, abs_zero]\n  | top_top => rfl\n  | symm h => rwa [mul_comm, EReal.mul_comm]\n  | coe_coe => simp only [\u2190 coe_mul, abs_def, _root_.abs_mul, ENNReal.ofReal_mul (abs_nonneg _)]\n  | top_pos _ h =>\n    rw [top_mul_coe_of_pos h, abs_top, ENNReal.top_mul]\n    rw [Ne.def, abs_eq_zero_iff, coe_eq_zero]\n    exact h.ne'\n  | neg_left h => rwa [neg_mul, EReal.abs_neg, EReal.abs_neg]\n#align ereal.abs_mul EReal.abs_mul\n\n/-! ### Sign -/\n\nopen SignType (sign)\n\ntheorem sign_top : sign (\u22a4 : EReal) = 1 := rfl\n#align ereal.sign_top EReal.sign_top\n\ntheorem sign_bot : sign (\u22a5 : EReal) = -1 := rfl\n#align ereal.sign_bot EReal.sign_bot\n\n@[simp]\ntheorem sign_coe (x : \u211d) : sign (x : EReal) = sign x := by\n  simp only [sign, OrderHom.coe_fun_mk, EReal.coe_pos, EReal.coe_neg']\n#align ereal.sign_coe EReal.sign_coe\n\n@[simp, norm_cast]\ntheorem coe_coe_sign (x : SignType) : ((x : \u211d) : EReal) = x := by cases x <;> rfl\n\n@[simp] theorem sign_neg : \u2200 x : EReal, sign (-x) = -sign x\n  | \u22a4 => rfl\n  | \u22a5 => rfl\n  | (x : \u211d) => by rw [\u2190 coe_neg, sign_coe, sign_coe, Left.sign_neg]\n\n@[simp]\ntheorem sign_mul (x y : EReal) : sign (x * y) = sign x * sign y := by\n  induction x, y using induction\u2082_symm_neg with\n  | top_zero => simp only [zero_mul, mul_zero, sign_zero]\n  | top_top => rfl\n  | symm h => rwa [mul_comm, EReal.mul_comm]\n  | coe_coe => simp only [\u2190 coe_mul, sign_coe, _root_.sign_mul, ENNReal.ofReal_mul (abs_nonneg _)]\n  | top_pos _ h =>\n    rw [top_mul_coe_of_pos h, sign_top, one_mul, sign_pos (EReal.coe_pos.2 h)]\n  | neg_left h => rw [neg_mul, sign_neg, sign_neg, h, neg_mul]\n#align ereal.sign_mul EReal.sign_mul\n\n@[simp] protected theorem sign_mul_abs : \u2200 x : EReal, (sign x * x.abs : EReal) = x\n  | \u22a5 => by simp\n  | \u22a4 => by simp\n  | (x : \u211d) => by rw [sign_coe, coe_abs, \u2190 coe_coe_sign, \u2190 coe_mul, sign_mul_abs]\n#align ereal.sign_mul_abs EReal.sign_mul_abs\n\n@[simp] protected theorem abs_mul_sign (x : EReal) : (x.abs * sign x : EReal) = x := by\n  rw [EReal.mul_comm, EReal.sign_mul_abs]\n\ntheorem sign_eq_and_abs_eq_iff_eq {x y : EReal} :\n    x.abs = y.abs \u2227 sign x = sign y \u2194 x = y := by\n  constructor\n  \u00b7 rintro \u27e8habs, hsign\u27e9\n    rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs, habs, hsign]\n  \u00b7 rintro rfl\n    exact \u27e8rfl, rfl\u27e9\n#align ereal.sign_eq_and_abs_eq_iff_eq EReal.sign_eq_and_abs_eq_iff_eq\n\ntheorem le_iff_sign {x y : EReal} :\n    x \u2264 y \u2194 sign x < sign y \u2228\n      sign x = SignType.neg \u2227 sign y = SignType.neg \u2227 y.abs \u2264 x.abs \u2228\n        sign x = SignType.zero \u2227 sign y = SignType.zero \u2228\n          sign x = SignType.pos \u2227 sign y = SignType.pos \u2227 x.abs \u2264 y.abs := by\n  constructor\n  \u00b7 intro h\n    refine (sign.monotone h).lt_or_eq.imp_right (fun hs => ?_)\n    rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs] at h\n    cases hy : sign y <;> rw [hs, hy] at h \u22a2\n    \u00b7 simp\n    \u00b7 left; simpa using h\n    \u00b7 right; right; simpa using h\n  \u00b7 rintro (h | h | h | h)\n    \u00b7 exact (sign.monotone.reflect_lt h).le\n    all_goals rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs]; simp [h]\n#align ereal.le_iff_sign EReal.le_iff_sign\n\ninstance : CommMonoidWithZero EReal :=\n  { inferInstanceAs (MulZeroOneClass EReal) with\n    mul_assoc := fun x y z => by\n      rw [\u2190 sign_eq_and_abs_eq_iff_eq]\n      simp only [mul_assoc, abs_mul, eq_self_iff_true, sign_mul, and_self_iff]\n    mul_comm := EReal.mul_comm }\n\ninstance : PosMulMono EReal := posMulMono_iff_covariant_pos.2 <| .mk <| by\n  rintro \u27e8x, x0\u27e9 a b h\n  simp only [le_iff_sign, EReal.sign_mul, sign_pos x0, one_mul, EReal.abs_mul] at h \u22a2\n  exact h.imp_right <| Or.imp (And.imp_right <| And.imp_right (mul_le_mul_left' \u00b7 _)) <|\n    Or.imp_right <| And.imp_right <| And.imp_right (mul_le_mul_left' \u00b7 _)\n\ninstance : MulPosMono EReal := posMulMono_iff_mulPosMono.1 inferInstance\n\ninstance : PosMulReflectLT EReal := PosMulMono.toPosMulReflectLT\n\ninstance : MulPosReflectLT EReal :=\n  MulPosMono.toMulPosReflectLT\n\n@[simp, norm_cast]\ntheorem coe_pow (x : \u211d) (n : \u2115) : (\u2191(x ^ n) : EReal) = (x : EReal) ^ n :=\n  map_pow (\u27e8\u27e8(\u2191), coe_one\u27e9, coe_mul\u27e9 : \u211d \u2192* EReal) _ _\n#align ereal.coe_pow EReal.coe_pow\n\n@[simp, norm_cast]\n\n\nend EReal\n\n/-\nnamespace Tactic\n\nopen Positivity\n\nprivate theorem ereal_coe_ne_zero {r : \u211d} : r \u2260 0 \u2192 (r : EReal) \u2260 0 :=\n  EReal.coe_ne_zero.2\n#align tactic.ereal_coe_ne_zero tactic.ereal_coe_ne_zero\n\nprivate theorem ereal_coe_nonneg {r : \u211d} : 0 \u2264 r \u2192 0 \u2264 (r : EReal) :=\n  EReal.coe_nonneg.2\n#align tactic.ereal_coe_nonneg tactic.ereal_coe_nonneg\n\nprivate theorem ereal_coe_pos {r : \u211d} : 0 < r \u2192 0 < (r : EReal) :=\n  EReal.coe_pos.2\n#align tactic.ereal_coe_pos tactic.ereal_coe_pos\n\nprivate theorem ereal_coe_ennreal_pos {r : \u211d\u22650\u221e} : 0 < r \u2192 0 < (r : EReal) :=\n  EReal.coe_ennreal_pos.2\n#align tactic.ereal_coe_ennreal_pos tactic.ereal_coe_ennreal_pos\n\n/-- Extension for the `positivity` tactic: cast from `\u211d` to `EReal`. -/\n@[positivity]\nunsafe def positivity_coe_real_ereal : expr \u2192 tactic strictness\n  | q(@coe _ _ $(inst) $(a)) => do\n    unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoe)\n    let strictness_a \u2190 core a\n    match strictness_a with\n      | positive p => positive <$> mk_app `` ereal_coe_pos [p]\n      | nonnegative p => nonnegative <$> mk_mapp `` ereal_coe_nonneg [a, p]\n      | nonzero p => nonzero <$> mk_mapp `` ereal_coe_ne_zero [a, p]\n  | e =>\n    pp e >>= fail \u2218 format.bracket \"The expression \" \" is not of the form `(r : ereal)` for `r : \u211d`\"\n#align tactic.positivity_coe_real_ereal tactic.positivity_coe_real_ereal\n\n/-- Extension for the `positivity` tactic: cast from `\u211d\u22650\u221e` to `EReal`. -/\n@[positivity]\nunsafe def positivity_coe_ennreal_ereal : expr \u2192 tactic strictness\n  | q(@coe _ _ $(inst) $(a)) => do\n    unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoeENNReal)\n    let strictness_a \u2190 core a\n    match strictness_a with\n      | positive p => positive <$> mk_app `` ereal_coe_ennreal_pos [p]\n      | _ => nonnegative <$> mk_mapp `ereal.coe_ennreal_nonneg [a]\n  | e =>\n    pp e >>=\n      fail \u2218 format.bracket \"The expression \" \" is not of the form `(r : ereal)` for `r : \u211d\u22650\u221e`\"\n#align tactic.positivity_coe_ennreal_ereal tactic.positivity_coe_ennreal_ereal\n\nend Tactic\n-/\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Real/EReal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7328144668519253}}
{"text": "/-\nCopyright (c) 2022 Tomaz Gomes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Tomaz Gomes.\n-/\nimport data.list.sort tactic\nimport data.nat.log\nimport init.data.nat\n/-\n# Timed Merge\n  This file defines a new version of Merge that, besides combining the input lists, counts the\n  number of operations made through the execution of the algorithm. Also, it presents proofs of\n  it's time complexity and it's equivalence to the one defined in data/list/sort.lean\n## Main Definition\n  - Timed.merge : list \u03b1 \u2192 list \u03b1 \u2192 (list \u03b1 \u00d7 \u2115)\n## Main Results\n  - Timed.merge_complexity :\n      \u2200 l\u2081 l\u2082 : list \u03b1, (Timed.merge l\u2081 l\u2082).snd \u2264 l\u2081.length + l\u2082.length\n  - Timed.merge_equivalence :\n      \u2200 l\u2081 l\u2082 : list \u03b1, (Timed.merge l\u2081 l\u2082).fst = list.merge l\u2081 l\u2082\n-/\n\nvariables {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [decidable_rel r]\nlocal infix ` \u227c ` : 50 := r\n\nnamespace Timed\n\ninclude r\n\n@[simp] def merge : list \u03b1 \u2192 list \u03b1 \u2192 (list \u03b1 \u00d7 \u2115)\n| []       l\u2082        := (l\u2082, 0)\n| l\u2081        []       := (l\u2081,  0)\n| (h\u2081 :: t\u2081) (h\u2082 :: t\u2082) := if h\u2081 \u227c h\u2082\n                           then let (l\u2083, n) := merge t\u2081 (h\u2082 :: t\u2082)\n                                in  (h\u2081 :: l\u2083, n + 1)\n                           else let (l\u2083, n) := merge (h\u2081 :: t\u2081) t\u2082\n                                in  (h\u2082 :: l\u2083, n + 1)\n\ntheorem merge_complexity : \u2200 l\u2081 l\u2082 : list \u03b1,\n  (merge r l\u2081 l\u2082).snd \u2264 l\u2081.length + l\u2082.length\n| []   []               := by { unfold merge, simp }\n| []   (h\u2082 :: t\u2082)       := by { unfold merge, simp }\n| (h\u2081 :: t\u2081)    []      := by { unfold merge, simp }\n| (h\u2081 :: t\u2081) (h\u2082 :: t\u2082) :=\nbegin\n  unfold merge, split_ifs,\n  { have IH := merge_complexity t\u2081 (h\u2082 :: t\u2082),\n    cases (merge r t\u2081 (h\u2082 :: t\u2082)) with l\u2081 l\u2082,\n    unfold merge,\n    simp only [list.length] at IH,\n    simp only [list.length],\n    linarith,\n  },\n  { have IH := merge_complexity (h\u2081 :: t\u2081) t\u2082,\n    cases (merge r (h\u2081 :: t\u2081) t\u2082) with l\u2081 l\u2082,\n    unfold merge,\n    simp only [list.length] at IH,\n    simp only [list.length],\n    linarith,\n  }\nend\n\ntheorem merge_equivalence : \u2200 l\u2081 l\u2082 : list \u03b1,\n  (merge r l\u2081 l\u2082).fst = list.merge r l\u2081 l\u2082\n| []       []         := by { unfold merge, unfold list.merge }\n| []       (h' :: t') := by { unfold merge, unfold list.merge }\n| (h :: t) []         := by { unfold merge, unfold list.merge }\n| (h :: t) (h' :: t') :=\nbegin\n  unfold merge,\n  split_ifs,\n  { have IH := merge_equivalence t (h' :: t'),\n    cases (merge r t (h' :: t')) with l\u2081 l\u2082,\n    unfold merge,\n\n    unfold list.merge,\n    split_ifs,\n    exact \u27e8 rfl, IH \u27e9,\n  },\n  { have IH := merge_equivalence (h :: t) t',\n    cases (merge r (h :: t) t') with l\u2081 l\u2082,\n    unfold merge,\n\n    unfold list.merge,\n    split_ifs,\n    exact \u27e8 rfl, IH \u27e9,\n  }\nend\n\nend Timed\n", "meta": {"author": "tomaz1502", "repo": "RunTimeFormalization", "sha": "6390f8bd4e2c0ac0811aa74cddaf06ab2716c59e", "save_path": "github-repos/lean/tomaz1502-RunTimeFormalization", "path": "github-repos/lean/tomaz1502-RunTimeFormalization/RunTimeFormalization-6390f8bd4e2c0ac0811aa74cddaf06ab2716c59e/src/MergeSort/Merge.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7328144637806026}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, S\u00e9bastien Gou\u00ebzel, Heather Macbeth\n-/\nimport analysis.inner_product_space.projection\nimport analysis.normed_space.pi_Lp\n\n/-!\n# `L\u00b2` inner product space structure on finite products of inner product spaces\n\nThe `L\u00b2` norm on a finite product of inner product spaces is compatible with an inner product\n$$\n\\langle x, y\\rangle = \\sum \\langle x_i, y_i \\rangle.\n$$\nThis is recorded in this file as an inner product space instance on `pi_Lp 2`.\n\n## Main definitions\n\n- `euclidean_space \ud835\udd5c n`: defined to be `pi_Lp 2 (n \u2192 \ud835\udd5c)` for any `fintype n`, i.e., the space\n  from functions to `n` to `\ud835\udd5c` with the `L\u00b2` norm. We register several instances on it (notably\n  that it is a finite-dimensional inner product space).\n\n- `basis.isometry_euclidean_of_orthonormal`: provides the isometry to Euclidean space\n  from a given finite-dimensional inner product space, induced by a basis of the space.\n\n- `linear_isometry_equiv.of_inner_product_space`: provides an arbitrary isometry to Euclidean space\n  from a given finite-dimensional inner product space, induced by choosing an arbitrary basis.\n\n- `complex.isometry_euclidean`: standard isometry from `\u2102` to `euclidean_space \u211d (fin 2)`\n\n-/\n\nopen real set filter is_R_or_C\nopen_locale big_operators uniformity topological_space nnreal ennreal complex_conjugate direct_sum\n\nlocal attribute [instance] fact_one_le_two_real\n\nlocal attribute [instance] fact_one_le_two_real\n\nnoncomputable theory\n\nvariables {\u03b9 : Type*}\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {E : Type*} [inner_product_space \ud835\udd5c E]\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\n\n/-\n If `\u03b9` is a finite type and each space `f i`, `i : \u03b9`, is an inner product space,\nthen `\u03a0 i, f i` is an inner product space as well. Since `\u03a0 i, f i` is endowed with the sup norm,\nwe use instead `pi_Lp 2 f` for the product space, which is endowed with the `L^2` norm.\n-/\ninstance pi_Lp.inner_product_space {\u03b9 : Type*} [fintype \u03b9] (f : \u03b9 \u2192 Type*)\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] : inner_product_space \ud835\udd5c (pi_Lp 2 f) :=\n{ inner := \u03bb x y, \u2211 i, inner (x i) (y i),\n  norm_sq_eq_inner :=\n  begin\n    intro x,\n    have h\u2081 : \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u2115) = \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d),\n    { apply finset.sum_congr rfl,\n      intros j hj,\n      simp [\u2190rpow_nat_cast] },\n    have h\u2082 : 0 \u2264 \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d),\n    { rw [\u2190h\u2081],\n      exact finset.sum_nonneg (\u03bb j (hj : j \u2208 finset.univ), pow_nonneg (norm_nonneg (x j)) 2) },\n    simp [norm, add_monoid_hom.map_sum, \u2190norm_sq_eq_inner],\n    rw [\u2190rpow_nat_cast ((\u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d)) ^ (2 : \u211d)\u207b\u00b9) 2],\n    rw [\u2190rpow_mul h\u2082],\n    norm_num [h\u2081],\n  end,\n  conj_sym :=\n  begin\n    intros x y,\n    unfold inner,\n    rw ring_equiv.map_sum,\n    apply finset.sum_congr rfl,\n    rintros z -,\n    apply inner_conj_sym,\n  end,\n  add_left := \u03bb x y z,\n    show \u2211 i, inner (x i + y i) (z i) = \u2211 i, inner (x i) (z i) + \u2211 i, inner (y i) (z i),\n    by simp only [inner_add_left, finset.sum_add_distrib],\n  smul_left := \u03bb x y r,\n    show \u2211 (i : \u03b9), inner (r \u2022 x i) (y i) = (conj r) * \u2211 i, inner (x i) (y i),\n    by simp only [finset.mul_sum, inner_smul_left] }\n\n@[simp] lemma pi_Lp.inner_apply {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 Type*}\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] (x y : pi_Lp 2 f) :\n  \u27eax, y\u27eb = \u2211 i, \u27eax i, y i\u27eb :=\nrfl\n\nlemma pi_Lp.norm_eq_of_L2 {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 Type*}\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] (x : pi_Lp 2 f) :\n  \u2225x\u2225 = sqrt (\u2211 (i : \u03b9), \u2225x i\u2225 ^ 2) :=\nby { rw [pi_Lp.norm_eq_of_nat 2]; simp [sqrt_eq_rpow] }\n\n\n/-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional\nspace use `euclidean_space \ud835\udd5c (fin n)`. -/\n@[reducible, nolint unused_arguments]\ndef euclidean_space (\ud835\udd5c : Type*) [is_R_or_C \ud835\udd5c]\n  (n : Type*) [fintype n] : Type* := pi_Lp 2 (\u03bb (i : n), \ud835\udd5c)\n\nlemma euclidean_space.norm_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x : euclidean_space \ud835\udd5c n) : \u2225x\u2225 = real.sqrt (\u2211 (i : n), \u2225x i\u2225 ^ 2) :=\npi_Lp.norm_eq_of_L2 x\n\nsection\nlocal attribute [reducible] pi_Lp\n\nvariables [fintype \u03b9]\n\ninstance : finite_dimensional \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\ninstance : inner_product_space \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\n\n@[simp] lemma finrank_euclidean_space :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) = fintype.card \u03b9 := by simp\n\nlemma finrank_euclidean_space_fin {n : \u2115} :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c (fin n)) = n := by simp\n\n/-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry\nfrom `E` to `pi_Lp 2` of the subspaces equipped with the `L2` inner product. -/\ndef direct_sum.submodule_is_internal.isometry_L2_of_orthogonal_family\n  [decidable_eq \u03b9] {V : \u03b9 \u2192 submodule \ud835\udd5c E} (hV : direct_sum.submodule_is_internal V)\n  (hV' : orthogonal_family \ud835\udd5c V) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] pi_Lp 2 (\u03bb i, V i) :=\nbegin\n  let e\u2081 := direct_sum.linear_equiv_fun_on_fintype \ud835\udd5c \u03b9 (\u03bb i, V i),\n  let e\u2082 := linear_equiv.of_bijective _ hV.injective hV.surjective,\n  refine (e\u2082.symm.trans e\u2081).isometry_of_inner _,\n  suffices : \u2200 v w, \u27eav, w\u27eb = \u27eae\u2082 (e\u2081.symm v), e\u2082 (e\u2081.symm w)\u27eb,\n  { intros v\u2080 w\u2080,\n    convert this (e\u2081 (e\u2082.symm v\u2080)) (e\u2081 (e\u2082.symm w\u2080));\n    simp only [linear_equiv.symm_apply_apply, linear_equiv.apply_symm_apply] },\n  intros v w,\n  transitivity \u27ea(\u2211 i, (v i : E)), \u2211 i, (w i : E)\u27eb,\n  { simp [sum_inner, hV'.inner_right_fintype] },\n  { congr; simp }\nend\n\n@[simp] lemma direct_sum.submodule_is_internal.isometry_L2_of_orthogonal_family_symm_apply\n  [decidable_eq \u03b9] {V : \u03b9 \u2192 submodule \ud835\udd5c E} (hV : direct_sum.submodule_is_internal V)\n  (hV' : orthogonal_family \ud835\udd5c V) (w : pi_Lp 2 (\u03bb i, V i)) :\n  (hV.isometry_L2_of_orthogonal_family hV').symm w = \u2211 i, (w i : E) :=\nbegin\n  classical,\n  let e\u2081 := direct_sum.linear_equiv_fun_on_fintype \ud835\udd5c \u03b9 (\u03bb i, V i),\n  let e\u2082 := linear_equiv.of_bijective _ hV.injective hV.surjective,\n  suffices : \u2200 v : \u2a01 i, V i, e\u2082 v = \u2211 i, e\u2081 v i,\n  { exact this (e\u2081.symm w) },\n  intros v,\n  simp [e\u2082, direct_sum.submodule_coe, direct_sum.to_module, dfinsupp.sum_add_hom_apply]\nend\n\n/-- An orthonormal basis on a fintype `\u03b9` for an inner product space induces an isometry with\n`euclidean_space \ud835\udd5c \u03b9`. -/\ndef basis.isometry_euclidean_of_orthonormal\n  (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9 :=\nv.equiv_fun.isometry_of_inner\nbegin\n  intros x y,\n  let p : euclidean_space \ud835\udd5c \u03b9 := v.equiv_fun x,\n  let q : euclidean_space \ud835\udd5c \u03b9 := v.equiv_fun y,\n  have key : \u27eap, q\u27eb = \u27ea\u2211 i, p i \u2022 v i, \u2211 i, q i \u2022 v i\u27eb,\n  { simp [sum_inner, inner_smul_left, hv.inner_right_fintype] },\n  convert key,\n  { rw [\u2190 v.equiv_fun.symm_apply_apply x, v.equiv_fun_symm_apply] },\n  { rw [\u2190 v.equiv_fun.symm_apply_apply y, v.equiv_fun_symm_apply] }\nend\n\n@[simp] lemma basis.coe_isometry_euclidean_of_orthonormal\n  (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  (v.isometry_euclidean_of_orthonormal hv : E \u2192 euclidean_space \ud835\udd5c \u03b9) = v.equiv_fun :=\nrfl\n\n@[simp] lemma basis.coe_isometry_euclidean_of_orthonormal_symm\n  (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  ((v.isometry_euclidean_of_orthonormal hv).symm : euclidean_space \ud835\udd5c \u03b9 \u2192 E) = v.equiv_fun.symm :=\nrfl\n\nend\n\n/-- `\u2102` is isometric to `\u211d\u00b2` with the Euclidean inner product. -/\ndef complex.isometry_euclidean : \u2102 \u2243\u2097\u1d62[\u211d] (euclidean_space \u211d (fin 2)) :=\ncomplex.basis_one_I.isometry_euclidean_of_orthonormal\nbegin\n  rw orthonormal_iff_ite,\n  intros i, fin_cases i;\n  intros j; fin_cases j;\n  simp [real_inner_eq_re_inner]\nend\n\n@[simp] lemma complex.isometry_euclidean_symm_apply (x : euclidean_space \u211d (fin 2)) :\n  complex.isometry_euclidean.symm x = (x 0) + (x 1) * I :=\nbegin\n  convert complex.basis_one_I.equiv_fun_symm_apply x,\n  { simpa },\n  { simp },\nend\n\nlemma complex.isometry_euclidean_proj_eq_self (z : \u2102) :\n  \u2191(complex.isometry_euclidean z 0) + \u2191(complex.isometry_euclidean z 1) * (I : \u2102) = z :=\nby rw [\u2190 complex.isometry_euclidean_symm_apply (complex.isometry_euclidean z),\n  complex.isometry_euclidean.symm_apply_apply z]\n\n@[simp] lemma complex.isometry_euclidean_apply_zero (z : \u2102) :\n  complex.isometry_euclidean z 0 = z.re :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\n@[simp] lemma complex.isometry_euclidean_apply_one (z : \u2102) :\n  complex.isometry_euclidean z 1 = z.im :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\nopen finite_dimensional\n\n/-- Given a natural number `n` equal to the `finrank` of a finite-dimensional inner product space,\nthere exists an isometry from the space to `euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.of_inner_product_space\n  [finite_dimensional \ud835\udd5c E] {n : \u2115} (hn : finrank \ud835\udd5c E = n) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\n(fin_orthonormal_basis hn).isometry_euclidean_of_orthonormal (fin_orthonormal_basis_orthonormal hn)\n\nlocal attribute [instance] fact_finite_dimensional_of_finrank_eq_succ\n\n/-- Given a natural number `n` one less than the `finrank` of a finite-dimensional inner product\nspace, there exists an isometry from the orthogonal complement of a nonzero singleton to\n`euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.from_orthogonal_span_singleton\n  (n : \u2115) [fact (finrank \ud835\udd5c E = n + 1)] {v : E} (hv : v \u2260 0) :\n  (\ud835\udd5c \u2219 v)\u15ee \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\nlinear_isometry_equiv.of_inner_product_space (finrank_orthogonal_span_singleton hv)\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/inner_product_space/pi_L2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7328144604576979}}
{"text": "import game.world10.level13 -- hide\nnamespace mynat -- hide\n/- \n\n# Inequality world. \n\n## Level 14: `add_le_add_left`\n\nI know these are easy and we've done several already, but this is one\nof the axioms for an ordered commutative monoid! The nature of formalising\nis that we should formalise all \"obvious\" lemmas, and then when we're\nactually using $\\le$ in real life, everything will be there. Note also,\nof course, that all of these lemmas are already formalised in Lean's\nmaths library already, for Lean's inbuilt natural numbers. \n-/\n\n/- Lemma\nIf $a\\le b$ then for all $t$, $t+a\\le t+b$. \n-/\ntheorem add_le_add_left {a b : mynat} (h : a \u2264 b) (t : mynat) :\n  t + a \u2264 t + b :=\nbegin [nat_num_game]\n  cases h with c hc,\n  use c,\n  rw hc,\n  ring,\n\n\nend\n\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world10/level14.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8175744739711884, "lm_q1q2_score": 0.7327522494669415}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n\n! This file was ported from Lean 3 source module analysis.special_functions.complex.arg\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Order.ToIntervalMod\nimport Mathbin.Analysis.SpecialFunctions.Trigonometric.Angle\nimport Mathbin.Analysis.SpecialFunctions.Trigonometric.Inverse\n\n/-!\n# The argument of a complex number.\n\nWe define `arg : \u2102 \u2192 \u211d`, returing a real number in the range (-\u03c0, \u03c0],\nsuch that for `x \u2260 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,\nwhile `arg 0` defaults to `0`\n-/\n\n\nnoncomputable section\n\nnamespace Complex\n\nopen ComplexConjugate Real Topology\n\nopen Filter Set\n\n/-- `arg` returns values in the range (-\u03c0, \u03c0], such that for `x \u2260 0`,\n  `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,\n  `arg 0` defaults to `0` -/\nnoncomputable def arg (x : \u2102) : \u211d :=\n  if 0 \u2264 x.re then Real.arcsin (x.im / x.abs)\n  else if 0 \u2264 x.im then Real.arcsin ((-x).im / x.abs) + \u03c0 else Real.arcsin ((-x).im / x.abs) - \u03c0\n#align complex.arg Complex.arg\n\ntheorem sin_arg (x : \u2102) : Real.sin (arg x) = x.im / x.abs := by\n  unfold arg <;> split_ifs <;>\n    simp [sub_eq_add_neg, arg,\n      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,\n      Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg]\n#align complex.sin_arg Complex.sin_arg\n\ntheorem cos_arg {x : \u2102} (hx : x \u2260 0) : Real.cos (arg x) = x.re / x.abs :=\n  by\n  have habs : 0 < abs x := abs.pos hx\n  have him : |im x / abs x| \u2264 1 := by\n    rw [_root_.abs_div, abs_abs]\n    exact div_le_one_of_le x.abs_im_le_abs (abs.nonneg x)\n  rw [abs_le] at him\n  rw [arg]\n  split_ifs with h\u2081 h\u2082 h\u2082\n  \u00b7 rw [Real.cos_arcsin]\n    field_simp [Real.sqrt_sq, habs.le, *]\n  \u00b7 rw [Real.cos_add_pi, Real.cos_arcsin]\n    field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h\u2081),\n      *]\n  \u00b7 rw [Real.cos_sub_pi, Real.cos_arcsin]\n    field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h\u2081),\n      *]\n#align complex.cos_arg Complex.cos_arg\n\n@[simp]\ntheorem abs_mul_exp_arg_mul_i (x : \u2102) : \u2191(abs x) * exp (arg x * I) = x :=\n  by\n  rcases eq_or_ne x 0 with (rfl | hx)\n  \u00b7 simp\n  \u00b7 have : abs x \u2260 0 := abs.ne_zero hx\n    ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)]\n#align complex.abs_mul_exp_arg_mul_I Complex.abs_mul_exp_arg_mul_i\n\n@[simp]\ntheorem abs_mul_cos_add_sin_mul_i (x : \u2102) : (abs x * (cos (arg x) + sin (arg x) * I) : \u2102) = x := by\n  rw [\u2190 exp_mul_I, abs_mul_exp_arg_mul_I]\n#align complex.abs_mul_cos_add_sin_mul_I Complex.abs_mul_cos_add_sin_mul_i\n\ntheorem abs_eq_one_iff (z : \u2102) : abs z = 1 \u2194 \u2203 \u03b8 : \u211d, exp (\u03b8 * I) = z :=\n  by\n  refine' \u27e8fun hz => \u27e8arg z, _\u27e9, _\u27e9\n  \u00b7\n    calc\n      exp (arg z * I) = abs z * exp (arg z * I) := by rw [hz, of_real_one, one_mul]\n      _ = z := abs_mul_exp_arg_mul_I z\n      \n  \u00b7 rintro \u27e8\u03b8, rfl\u27e9\n    exact Complex.abs_exp_ofReal_mul_I \u03b8\n#align complex.abs_eq_one_iff Complex.abs_eq_one_iff\n\n@[simp]\ntheorem range_exp_mul_i : (range fun x : \u211d => exp (x * I)) = Metric.sphere 0 1 :=\n  by\n  ext x\n  simp only [mem_sphere_zero_iff_norm, norm_eq_abs, abs_eq_one_iff, mem_range]\n#align complex.range_exp_mul_I Complex.range_exp_mul_i\n\ntheorem arg_mul_cos_add_sin_mul_i {r : \u211d} (hr : 0 < r) {\u03b8 : \u211d} (h\u03b8 : \u03b8 \u2208 Ioc (-\u03c0) \u03c0) :\n    arg (r * (cos \u03b8 + sin \u03b8 * I)) = \u03b8 :=\n  by\n  simp only [arg, map_mul, abs_cos_add_sin_mul_I, abs_of_nonneg hr.le, mul_one]\n  simp only [of_real_mul_re, of_real_mul_im, neg_im, \u2190 of_real_cos, \u2190 of_real_sin, \u2190\n    mk_eq_add_mul_I, neg_div, mul_div_cancel_left _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr]\n  by_cases h\u2081 : \u03b8 \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)\n  \u00b7 rw [if_pos]\n    exacts[Real.arcsin_sin' h\u2081, Real.cos_nonneg_of_mem_Icc h\u2081]\n  \u00b7 rw [mem_Icc, not_and_or, not_le, not_le] at h\u2081\n    cases h\u2081\n    \u00b7 replace h\u03b8 := h\u03b8.1\n      have hcos : Real.cos \u03b8 < 0 := by\n        rw [\u2190 neg_pos, \u2190 Real.cos_add_pi]\n        refine' Real.cos_pos_of_mem_Ioo \u27e8_, _\u27e9 <;> linarith\n      have hsin : Real.sin \u03b8 < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) h\u03b8\n      rw [if_neg, if_neg, \u2190 Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel] <;> [linarith,\n        linarith, exact hsin.not_le, exact hcos.not_le]\n    \u00b7 replace h\u03b8 := h\u03b8.2\n      have hcos : Real.cos \u03b8 < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h\u2081 (by linarith)\n      have hsin : 0 \u2264 Real.sin \u03b8 := Real.sin_nonneg_of_mem_Icc \u27e8by linarith, h\u03b8\u27e9\n      rw [if_neg, if_pos, \u2190 Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith,\n        linarith, exact hsin, exact hcos.not_le]\n#align complex.arg_mul_cos_add_sin_mul_I Complex.arg_mul_cos_add_sin_mul_i\n\ntheorem arg_cos_add_sin_mul_i {\u03b8 : \u211d} (h\u03b8 : \u03b8 \u2208 Ioc (-\u03c0) \u03c0) : arg (cos \u03b8 + sin \u03b8 * I) = \u03b8 := by\n  rw [\u2190 one_mul (_ + _), \u2190 of_real_one, arg_mul_cos_add_sin_mul_I zero_lt_one h\u03b8]\n#align complex.arg_cos_add_sin_mul_I Complex.arg_cos_add_sin_mul_i\n\n@[simp]\ntheorem arg_zero : arg 0 = 0 := by simp [arg, le_refl]\n#align complex.arg_zero Complex.arg_zero\n\ntheorem ext_abs_arg {x y : \u2102} (h\u2081 : x.abs = y.abs) (h\u2082 : x.arg = y.arg) : x = y := by\n  rw [\u2190 abs_mul_exp_arg_mul_I x, \u2190 abs_mul_exp_arg_mul_I y, h\u2081, h\u2082]\n#align complex.ext_abs_arg Complex.ext_abs_arg\n\ntheorem ext_abs_arg_iff {x y : \u2102} : x = y \u2194 abs x = abs y \u2227 arg x = arg y :=\n  \u27e8fun h => h \u25b8 \u27e8rfl, rfl\u27e9, and_imp.2 ext_abs_arg\u27e9\n#align complex.ext_abs_arg_iff Complex.ext_abs_arg_iff\n\ntheorem arg_mem_Ioc (z : \u2102) : arg z \u2208 Ioc (-\u03c0) \u03c0 :=\n  by\n  have h\u03c0 : 0 < \u03c0 := Real.pi_pos\n  rcases eq_or_ne z 0 with (rfl | hz); simp [h\u03c0, h\u03c0.le]\n  rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-\u03c0) with \u27e8N, hN, -\u27e9\n  rw [two_mul, neg_add_cancel_left, \u2190 two_mul, zsmul_eq_mul] at hN\n  rw [\u2190 abs_mul_cos_add_sin_mul_I z, \u2190 cos_add_int_mul_two_pi _ N, \u2190 sin_add_int_mul_two_pi _ N]\n  simp only [\u2190 of_real_one, \u2190 of_real_bit0, \u2190 of_real_mul, \u2190 of_real_add, \u2190 of_real_int_cast]\n  rwa [arg_mul_cos_add_sin_mul_I (abs.pos hz) hN]\n#align complex.arg_mem_Ioc Complex.arg_mem_Ioc\n\n@[simp]\ntheorem range_arg : range arg = Ioc (-\u03c0) \u03c0 :=\n  (range_subset_iff.2 arg_mem_Ioc).antisymm fun x hx => \u27e8_, arg_cos_add_sin_mul_i hx\u27e9\n#align complex.range_arg Complex.range_arg\n\ntheorem arg_le_pi (x : \u2102) : arg x \u2264 \u03c0 :=\n  (arg_mem_Ioc x).2\n#align complex.arg_le_pi Complex.arg_le_pi\n\ntheorem neg_pi_lt_arg (x : \u2102) : -\u03c0 < arg x :=\n  (arg_mem_Ioc x).1\n#align complex.neg_pi_lt_arg Complex.neg_pi_lt_arg\n\ntheorem abs_arg_le_pi (z : \u2102) : |arg z| \u2264 \u03c0 :=\n  abs_le.2 \u27e8(neg_pi_lt_arg z).le, arg_le_pi z\u27e9\n#align complex.abs_arg_le_pi Complex.abs_arg_le_pi\n\n@[simp]\ntheorem arg_nonneg_iff {z : \u2102} : 0 \u2264 arg z \u2194 0 \u2264 z.im :=\n  by\n  rcases eq_or_ne z 0 with (rfl | h\u2080); \u00b7 simp\n  calc\n    0 \u2264 arg z \u2194 0 \u2264 Real.sin (arg z) :=\n      \u27e8fun h => Real.sin_nonneg_of_mem_Icc \u27e8h, arg_le_pi z\u27e9,\n        by\n        contrapose!\n        intro h\n        exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)\u27e9\n    _ \u2194 _ := by rw [sin_arg, le_div_iff (abs.pos h\u2080), MulZeroClass.zero_mul]\n    \n#align complex.arg_nonneg_iff Complex.arg_nonneg_iff\n\n@[simp]\ntheorem arg_neg_iff {z : \u2102} : arg z < 0 \u2194 z.im < 0 :=\n  lt_iff_lt_of_le_iff_le arg_nonneg_iff\n#align complex.arg_neg_iff Complex.arg_neg_iff\n\ntheorem arg_real_mul (x : \u2102) {r : \u211d} (hr : 0 < r) : arg (r * x) = arg x :=\n  by\n  rcases eq_or_ne x 0 with (rfl | hx); \u00b7 rw [MulZeroClass.mul_zero]\n  conv_lhs =>\n    rw [\u2190 abs_mul_cos_add_sin_mul_I x, \u2190 mul_assoc, \u2190 of_real_mul,\n      arg_mul_cos_add_sin_mul_I (mul_pos hr (abs.pos hx)) x.arg_mem_Ioc]\n#align complex.arg_real_mul Complex.arg_real_mul\n\ntheorem arg_eq_arg_iff {x y : \u2102} (hx : x \u2260 0) (hy : y \u2260 0) :\n    arg x = arg y \u2194 (abs y / abs x : \u2102) * x = y :=\n  by\n  simp only [ext_abs_arg_iff, map_mul, map_div\u2080, abs_of_real, abs_abs,\n    div_mul_cancel _ (abs.ne_zero hx), eq_self_iff_true, true_and_iff]\n  rw [\u2190 of_real_div, arg_real_mul]\n  exact div_pos (abs.pos hy) (abs.pos hx)\n#align complex.arg_eq_arg_iff Complex.arg_eq_arg_iff\n\n@[simp]\ntheorem arg_one : arg 1 = 0 := by simp [arg, zero_le_one]\n#align complex.arg_one Complex.arg_one\n\n@[simp]\ntheorem arg_neg_one : arg (-1) = \u03c0 := by simp [arg, le_refl, not_le.2 (zero_lt_one' \u211d)]\n#align complex.arg_neg_one Complex.arg_neg_one\n\n@[simp]\ntheorem arg_i : arg I = \u03c0 / 2 := by simp [arg, le_refl]\n#align complex.arg_I Complex.arg_i\n\n@[simp]\ntheorem arg_neg_i : arg (-I) = -(\u03c0 / 2) := by simp [arg, le_refl]\n#align complex.arg_neg_I Complex.arg_neg_i\n\n@[simp]\ntheorem tan_arg (x : \u2102) : Real.tan (arg x) = x.im / x.re :=\n  by\n  by_cases h : x = 0\n  \u00b7 simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re]\n  rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (abs.ne_zero h)]\n#align complex.tan_arg Complex.tan_arg\n\ntheorem arg_of_real_of_nonneg {x : \u211d} (hx : 0 \u2264 x) : arg x = 0 := by simp [arg, hx]\n#align complex.arg_of_real_of_nonneg Complex.arg_of_real_of_nonneg\n\ntheorem arg_eq_zero_iff {z : \u2102} : arg z = 0 \u2194 0 \u2264 z.re \u2227 z.im = 0 :=\n  by\n  refine' \u27e8fun h => _, _\u27e9\n  \u00b7 rw [\u2190 abs_mul_cos_add_sin_mul_I z, h]\n    simp [abs.nonneg]\n  \u00b7 cases' z with x y\n    rintro \u27e8h, rfl : y = 0\u27e9\n    exact arg_of_real_of_nonneg h\n#align complex.arg_eq_zero_iff Complex.arg_eq_zero_iff\n\ntheorem arg_eq_pi_iff {z : \u2102} : arg z = \u03c0 \u2194 z.re < 0 \u2227 z.im = 0 :=\n  by\n  by_cases h\u2080 : z = 0; \u00b7 simp [h\u2080, lt_irrefl, real.pi_ne_zero.symm]\n  constructor\n  \u00b7 intro h\n    rw [\u2190 abs_mul_cos_add_sin_mul_I z, h]\n    simp [h\u2080]\n  \u00b7 cases' z with x y\n    rintro \u27e8h : x < 0, rfl : y = 0\u27e9\n    rw [\u2190 arg_neg_one, \u2190 arg_real_mul (-1) (neg_pos.2 h)]\n    simp [\u2190 of_real_def]\n#align complex.arg_eq_pi_iff Complex.arg_eq_pi_iff\n\ntheorem arg_lt_pi_iff {z : \u2102} : arg z < \u03c0 \u2194 0 \u2264 z.re \u2228 z.im \u2260 0 := by\n  rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or, not_le, Classical.not_not, arg_eq_pi_iff]\n#align complex.arg_lt_pi_iff Complex.arg_lt_pi_iff\n\ntheorem arg_of_real_of_neg {x : \u211d} (hx : x < 0) : arg x = \u03c0 :=\n  arg_eq_pi_iff.2 \u27e8hx, rfl\u27e9\n#align complex.arg_of_real_of_neg Complex.arg_of_real_of_neg\n\ntheorem arg_eq_pi_div_two_iff {z : \u2102} : arg z = \u03c0 / 2 \u2194 z.re = 0 \u2227 0 < z.im :=\n  by\n  by_cases h\u2080 : z = 0; \u00b7 simp [h\u2080, lt_irrefl, real.pi_div_two_pos.ne]\n  constructor\n  \u00b7 intro h\n    rw [\u2190 abs_mul_cos_add_sin_mul_I z, h]\n    simp [h\u2080]\n  \u00b7 cases' z with x y\n    rintro \u27e8rfl : x = 0, hy : 0 < y\u27e9\n    rw [\u2190 arg_I, \u2190 arg_real_mul I hy, of_real_mul', I_re, I_im, MulZeroClass.mul_zero, mul_one]\n#align complex.arg_eq_pi_div_two_iff Complex.arg_eq_pi_div_two_iff\n\ntheorem arg_eq_neg_pi_div_two_iff {z : \u2102} : arg z = -(\u03c0 / 2) \u2194 z.re = 0 \u2227 z.im < 0 :=\n  by\n  by_cases h\u2080 : z = 0; \u00b7 simp [h\u2080, lt_irrefl, Real.pi_ne_zero]\n  constructor\n  \u00b7 intro h\n    rw [\u2190 abs_mul_cos_add_sin_mul_I z, h]\n    simp [h\u2080]\n  \u00b7 cases' z with x y\n    rintro \u27e8rfl : x = 0, hy : y < 0\u27e9\n    rw [\u2190 arg_neg_I, \u2190 arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I]\n    simp\n#align complex.arg_eq_neg_pi_div_two_iff Complex.arg_eq_neg_pi_div_two_iff\n\ntheorem arg_of_re_nonneg {x : \u2102} (hx : 0 \u2264 x.re) : arg x = Real.arcsin (x.im / x.abs) :=\n  if_pos hx\n#align complex.arg_of_re_nonneg Complex.arg_of_re_nonneg\n\ntheorem arg_of_re_neg_of_im_nonneg {x : \u2102} (hx_re : x.re < 0) (hx_im : 0 \u2264 x.im) :\n    arg x = Real.arcsin ((-x).im / x.abs) + \u03c0 := by\n  simp only [arg, hx_re.not_le, hx_im, if_true, if_false]\n#align complex.arg_of_re_neg_of_im_nonneg Complex.arg_of_re_neg_of_im_nonneg\n\ntheorem arg_of_re_neg_of_im_neg {x : \u2102} (hx_re : x.re < 0) (hx_im : x.im < 0) :\n    arg x = Real.arcsin ((-x).im / x.abs) - \u03c0 := by\n  simp only [arg, hx_re.not_le, hx_im.not_le, if_false]\n#align complex.arg_of_re_neg_of_im_neg Complex.arg_of_re_neg_of_im_neg\n\ntheorem arg_of_im_nonneg_of_ne_zero {z : \u2102} (h\u2081 : 0 \u2264 z.im) (h\u2082 : z \u2260 0) :\n    arg z = Real.arccos (z.re / abs z) := by\n  rw [\u2190 cos_arg h\u2082, Real.arccos_cos (arg_nonneg_iff.2 h\u2081) (arg_le_pi _)]\n#align complex.arg_of_im_nonneg_of_ne_zero Complex.arg_of_im_nonneg_of_ne_zero\n\ntheorem arg_of_im_pos {z : \u2102} (hz : 0 < z.im) : arg z = Real.arccos (z.re / abs z) :=\n  arg_of_im_nonneg_of_ne_zero hz.le fun h => hz.ne' <| h.symm \u25b8 rfl\n#align complex.arg_of_im_pos Complex.arg_of_im_pos\n\ntheorem arg_of_im_neg {z : \u2102} (hz : z.im < 0) : arg z = -Real.arccos (z.re / abs z) :=\n  by\n  have h\u2080 : z \u2260 0 := mt (congr_arg im) hz.ne\n  rw [\u2190 cos_arg h\u2080, \u2190 Real.cos_neg, Real.arccos_cos, neg_neg]\n  exacts[neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le]\n#align complex.arg_of_im_neg Complex.arg_of_im_neg\n\ntheorem arg_conj (x : \u2102) : arg (conj x) = if arg x = \u03c0 then \u03c0 else -arg x :=\n  by\n  simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, abs_conj, neg_div, neg_neg,\n    Real.arcsin_neg, apply_ite Neg.neg, neg_add, neg_sub, neg_neg, \u2190 sub_eq_add_neg, sub_neg_eq_add,\n    add_comm \u03c0]\n  rcases lt_trichotomy x.re 0 with (hr | hr | hr) <;>\n    rcases lt_trichotomy x.im 0 with (hi | hi | hi)\n  \u00b7 simp [hr, hr.not_le, hi.le, hi.ne, not_le.2 hi]\n  \u00b7 simp [hr, hr.not_le, hi]\n  \u00b7 simp [hr, hr.not_le, hi.ne.symm, hi.le, not_le.2 hi]\n  \u00b7 simp [hr]\n  \u00b7 simp [hr]\n  \u00b7 simp [hr]\n  \u00b7 simp [hr, hr.le, hi.ne]\n  \u00b7 simp [hr, hr.le, hr.le.not_lt]\n  \u00b7 simp [hr, hr.le, hr.le.not_lt]\n#align complex.arg_conj Complex.arg_conj\n\ntheorem arg_inv (x : \u2102) : arg x\u207b\u00b9 = if arg x = \u03c0 then \u03c0 else -arg x :=\n  by\n  rw [\u2190 arg_conj, inv_def, mul_comm]\n  by_cases hx : x = 0\n  \u00b7 simp [hx]\n  \u00b7 exact arg_real_mul (conj x) (by simp [hx])\n#align complex.arg_inv Complex.arg_inv\n\ntheorem arg_le_pi_div_two_iff {z : \u2102} : arg z \u2264 \u03c0 / 2 \u2194 0 \u2264 re z \u2228 im z < 0 :=\n  by\n  cases' le_or_lt 0 (re z) with hre hre\n  \u00b7 simp only [hre, arg_of_re_nonneg hre, Real.arcsin_le_pi_div_two, true_or_iff]\n  simp only [hre.not_le, false_or_iff]\n  cases' le_or_lt 0 (im z) with him him\n  \u00b7 simp only [him.not_lt]\n    rw [iff_false_iff, not_le, arg_of_re_neg_of_im_nonneg hre him, \u2190 sub_lt_iff_lt_add, half_sub,\n      Real.neg_pi_div_two_lt_arcsin, neg_im, neg_div, neg_lt_neg_iff, div_lt_one, \u2190\n      _root_.abs_of_nonneg him, abs_im_lt_abs]\n    exacts[hre.ne, abs.pos <| ne_of_apply_ne re hre.ne]\n  \u00b7 simp only [him]\n    rw [iff_true_iff, arg_of_re_neg_of_im_neg hre him]\n    exact (sub_le_self _ real.pi_pos.le).trans (Real.arcsin_le_pi_div_two _)\n#align complex.arg_le_pi_div_two_iff Complex.arg_le_pi_div_two_iff\n\ntheorem neg_pi_div_two_le_arg_iff {z : \u2102} : -(\u03c0 / 2) \u2264 arg z \u2194 0 \u2264 re z \u2228 0 \u2264 im z :=\n  by\n  cases' le_or_lt 0 (re z) with hre hre\n  \u00b7 simp only [hre, arg_of_re_nonneg hre, Real.neg_pi_div_two_le_arcsin, true_or_iff]\n  simp only [hre.not_le, false_or_iff]\n  cases' le_or_lt 0 (im z) with him him\n  \u00b7 simp only [him]\n    rw [iff_true_iff, arg_of_re_neg_of_im_nonneg hre him]\n    exact (Real.neg_pi_div_two_le_arcsin _).trans (le_add_of_nonneg_right real.pi_pos.le)\n  \u00b7 simp only [him.not_le]\n    rw [iff_false_iff, not_le, arg_of_re_neg_of_im_neg hre him, sub_lt_iff_lt_add', \u2190\n      sub_eq_add_neg, sub_half, Real.arcsin_lt_pi_div_two, div_lt_one, neg_im, \u2190 abs_of_neg him,\n      abs_im_lt_abs]\n    exacts[hre.ne, abs.pos <| ne_of_apply_ne re hre.ne]\n#align complex.neg_pi_div_two_le_arg_iff Complex.neg_pi_div_two_le_arg_iff\n\n@[simp]\ntheorem abs_arg_le_pi_div_two_iff {z : \u2102} : |arg z| \u2264 \u03c0 / 2 \u2194 0 \u2264 re z := by\n  rw [abs_le, arg_le_pi_div_two_iff, neg_pi_div_two_le_arg_iff, \u2190 or_and_left, \u2190 not_le,\n    and_not_self_iff, or_false_iff]\n#align complex.abs_arg_le_pi_div_two_iff Complex.abs_arg_le_pi_div_two_iff\n\n@[simp]\ntheorem arg_conj_coe_angle (x : \u2102) : (arg (conj x) : Real.Angle) = -arg x := by\n  by_cases h : arg x = \u03c0 <;> simp [arg_conj, h]\n#align complex.arg_conj_coe_angle Complex.arg_conj_coe_angle\n\n@[simp]\ntheorem arg_inv_coe_angle (x : \u2102) : (arg x\u207b\u00b9 : Real.Angle) = -arg x := by\n  by_cases h : arg x = \u03c0 <;> simp [arg_inv, h]\n#align complex.arg_inv_coe_angle Complex.arg_inv_coe_angle\n\ntheorem arg_neg_eq_arg_sub_pi_of_im_pos {x : \u2102} (hi : 0 < x.im) : arg (-x) = arg x - \u03c0 :=\n  by\n  rw [arg_of_im_pos hi, arg_of_im_neg (show (-x).im < 0 from Left.neg_neg_iff.2 hi)]\n  simp [neg_div, Real.arccos_neg]\n#align complex.arg_neg_eq_arg_sub_pi_of_im_pos Complex.arg_neg_eq_arg_sub_pi_of_im_pos\n\ntheorem arg_neg_eq_arg_add_pi_of_im_neg {x : \u2102} (hi : x.im < 0) : arg (-x) = arg x + \u03c0 :=\n  by\n  rw [arg_of_im_neg hi, arg_of_im_pos (show 0 < (-x).im from Left.neg_pos_iff.2 hi)]\n  simp [neg_div, Real.arccos_neg, add_comm, \u2190 sub_eq_add_neg]\n#align complex.arg_neg_eq_arg_add_pi_of_im_neg Complex.arg_neg_eq_arg_add_pi_of_im_neg\n\ntheorem arg_neg_eq_arg_sub_pi_iff {x : \u2102} : arg (-x) = arg x - \u03c0 \u2194 0 < x.im \u2228 x.im = 0 \u2227 x.re < 0 :=\n  by\n  rcases lt_trichotomy x.im 0 with (hi | hi | hi)\n  \u00b7\n    simp [hi, hi.ne, hi.not_lt, arg_neg_eq_arg_add_pi_of_im_neg, sub_eq_add_neg, \u2190\n      add_eq_zero_iff_eq_neg, Real.pi_ne_zero]\n  \u00b7 rw [(ext rfl hi : x = x.re)]\n    rcases lt_trichotomy x.re 0 with (hr | hr | hr)\n    \u00b7 rw [arg_of_real_of_neg hr, \u2190 of_real_neg, arg_of_real_of_nonneg (Left.neg_pos_iff.2 hr).le]\n      simp [hr]\n    \u00b7 simp [hr, hi, Real.pi_ne_zero]\n    \u00b7 rw [arg_of_real_of_nonneg hr.le, \u2190 of_real_neg, arg_of_real_of_neg (Left.neg_neg_iff.2 hr)]\n      simp [hr.not_lt, \u2190 add_eq_zero_iff_eq_neg, Real.pi_ne_zero]\n  \u00b7 simp [hi, arg_neg_eq_arg_sub_pi_of_im_pos]\n#align complex.arg_neg_eq_arg_sub_pi_iff Complex.arg_neg_eq_arg_sub_pi_iff\n\ntheorem arg_neg_eq_arg_add_pi_iff {x : \u2102} : arg (-x) = arg x + \u03c0 \u2194 x.im < 0 \u2228 x.im = 0 \u2227 0 < x.re :=\n  by\n  rcases lt_trichotomy x.im 0 with (hi | hi | hi)\n  \u00b7 simp [hi, arg_neg_eq_arg_add_pi_of_im_neg]\n  \u00b7 rw [(ext rfl hi : x = x.re)]\n    rcases lt_trichotomy x.re 0 with (hr | hr | hr)\n    \u00b7 rw [arg_of_real_of_neg hr, \u2190 of_real_neg, arg_of_real_of_nonneg (Left.neg_pos_iff.2 hr).le]\n      simp [hr.not_lt, \u2190 two_mul, Real.pi_ne_zero]\n    \u00b7 simp [hr, hi, real.pi_ne_zero.symm]\n    \u00b7 rw [arg_of_real_of_nonneg hr.le, \u2190 of_real_neg, arg_of_real_of_neg (Left.neg_neg_iff.2 hr)]\n      simp [hr]\n  \u00b7\n    simp [hi, hi.ne.symm, hi.not_lt, arg_neg_eq_arg_sub_pi_of_im_pos, sub_eq_add_neg, \u2190\n      add_eq_zero_iff_neg_eq, Real.pi_ne_zero]\n#align complex.arg_neg_eq_arg_add_pi_iff Complex.arg_neg_eq_arg_add_pi_iff\n\ntheorem arg_neg_coe_angle {x : \u2102} (hx : x \u2260 0) : (arg (-x) : Real.Angle) = arg x + \u03c0 :=\n  by\n  rcases lt_trichotomy x.im 0 with (hi | hi | hi)\n  \u00b7 rw [arg_neg_eq_arg_add_pi_of_im_neg hi, Real.Angle.coe_add]\n  \u00b7 rw [(ext rfl hi : x = x.re)]\n    rcases lt_trichotomy x.re 0 with (hr | hr | hr)\n    \u00b7\n      rw [arg_of_real_of_neg hr, \u2190 of_real_neg, arg_of_real_of_nonneg (Left.neg_pos_iff.2 hr).le, \u2190\n        Real.Angle.coe_add, \u2190 two_mul, Real.Angle.coe_two_pi, Real.Angle.coe_zero]\n    \u00b7 exact False.elim (hx (ext hr hi))\n    \u00b7\n      rw [arg_of_real_of_nonneg hr.le, \u2190 of_real_neg, arg_of_real_of_neg (Left.neg_neg_iff.2 hr),\n        Real.Angle.coe_zero, zero_add]\n  \u00b7 rw [arg_neg_eq_arg_sub_pi_of_im_pos hi, Real.Angle.coe_sub, Real.Angle.sub_coe_pi_eq_add_coe_pi]\n#align complex.arg_neg_coe_angle Complex.arg_neg_coe_angle\n\ntheorem arg_mul_cos_add_sin_mul_i_eq_toIocMod {r : \u211d} (hr : 0 < r) (\u03b8 : \u211d) :\n    arg (r * (cos \u03b8 + sin \u03b8 * I)) = toIocMod (-\u03c0) Real.two_pi_pos \u03b8 :=\n  by\n  have hi : toIocMod (-\u03c0) Real.two_pi_pos \u03b8 \u2208 Ioc (-\u03c0) \u03c0 :=\n    by\n    convert toIocMod_mem_Ioc _ Real.two_pi_pos _\n    ring\n  convert arg_mul_cos_add_sin_mul_I hr hi using 3\n  simp [toIocMod, cos_sub_int_mul_two_pi, sin_sub_int_mul_two_pi]\n#align complex.arg_mul_cos_add_sin_mul_I_eq_to_Ioc_mod Complex.arg_mul_cos_add_sin_mul_i_eq_toIocMod\n\ntheorem arg_cos_add_sin_mul_i_eq_toIocMod (\u03b8 : \u211d) :\n    arg (cos \u03b8 + sin \u03b8 * I) = toIocMod (-\u03c0) Real.two_pi_pos \u03b8 := by\n  rw [\u2190 one_mul (_ + _), \u2190 of_real_one, arg_mul_cos_add_sin_mul_I_eq_to_Ioc_mod zero_lt_one]\n#align complex.arg_cos_add_sin_mul_I_eq_to_Ioc_mod Complex.arg_cos_add_sin_mul_i_eq_toIocMod\n\ntheorem arg_mul_cos_add_sin_mul_i_sub {r : \u211d} (hr : 0 < r) (\u03b8 : \u211d) :\n    arg (r * (cos \u03b8 + sin \u03b8 * I)) - \u03b8 = 2 * \u03c0 * \u230a(\u03c0 - \u03b8) / (2 * \u03c0)\u230b :=\n  by\n  rw [arg_mul_cos_add_sin_mul_I_eq_to_Ioc_mod hr, toIocMod_sub_self, toIocDiv_eq_neg_floor,\n    zsmul_eq_mul]\n  ring_nf\n#align complex.arg_mul_cos_add_sin_mul_I_sub Complex.arg_mul_cos_add_sin_mul_i_sub\n\ntheorem arg_cos_add_sin_mul_i_sub (\u03b8 : \u211d) :\n    arg (cos \u03b8 + sin \u03b8 * I) - \u03b8 = 2 * \u03c0 * \u230a(\u03c0 - \u03b8) / (2 * \u03c0)\u230b := by\n  rw [\u2190 one_mul (_ + _), \u2190 of_real_one, arg_mul_cos_add_sin_mul_I_sub zero_lt_one]\n#align complex.arg_cos_add_sin_mul_I_sub Complex.arg_cos_add_sin_mul_i_sub\n\ntheorem arg_mul_cos_add_sin_mul_i_coe_angle {r : \u211d} (hr : 0 < r) (\u03b8 : Real.Angle) :\n    (arg (r * (Real.Angle.cos \u03b8 + Real.Angle.sin \u03b8 * I)) : Real.Angle) = \u03b8 :=\n  by\n  induction \u03b8 using Real.Angle.induction_on\n  rw [Real.Angle.cos_coe, Real.Angle.sin_coe, Real.Angle.angle_eq_iff_two_pi_dvd_sub]\n  use \u230a(\u03c0 - \u03b8) / (2 * \u03c0)\u230b\n  exact_mod_cast arg_mul_cos_add_sin_mul_I_sub hr \u03b8\n#align complex.arg_mul_cos_add_sin_mul_I_coe_angle Complex.arg_mul_cos_add_sin_mul_i_coe_angle\n\ntheorem arg_cos_add_sin_mul_i_coe_angle (\u03b8 : Real.Angle) :\n    (arg (Real.Angle.cos \u03b8 + Real.Angle.sin \u03b8 * I) : Real.Angle) = \u03b8 := by\n  rw [\u2190 one_mul (_ + _), \u2190 of_real_one, arg_mul_cos_add_sin_mul_I_coe_angle zero_lt_one]\n#align complex.arg_cos_add_sin_mul_I_coe_angle Complex.arg_cos_add_sin_mul_i_coe_angle\n\ntheorem arg_mul_coe_angle {x y : \u2102} (hx : x \u2260 0) (hy : y \u2260 0) :\n    (arg (x * y) : Real.Angle) = arg x + arg y :=\n  by\n  convert arg_mul_cos_add_sin_mul_I_coe_angle (mul_pos (abs.pos hx) (abs.pos hy))\n      (arg x + arg y : Real.Angle) using\n    3\n  simp_rw [\u2190 Real.Angle.coe_add, Real.Angle.sin_coe, Real.Angle.cos_coe, of_real_cos, of_real_sin,\n    cos_add_sin_I, of_real_add, add_mul, exp_add, of_real_mul]\n  rw [mul_assoc, mul_comm (exp _), \u2190 mul_assoc (abs y : \u2102), abs_mul_exp_arg_mul_I, mul_comm y, \u2190\n    mul_assoc, abs_mul_exp_arg_mul_I]\n#align complex.arg_mul_coe_angle Complex.arg_mul_coe_angle\n\ntheorem arg_div_coe_angle {x y : \u2102} (hx : x \u2260 0) (hy : y \u2260 0) :\n    (arg (x / y) : Real.Angle) = arg x - arg y := by\n  rw [div_eq_mul_inv, arg_mul_coe_angle hx (inv_ne_zero hy), arg_inv_coe_angle, sub_eq_add_neg]\n#align complex.arg_div_coe_angle Complex.arg_div_coe_angle\n\n@[simp]\ntheorem arg_coe_angle_toReal_eq_arg (z : \u2102) : (arg z : Real.Angle).toReal = arg z :=\n  by\n  rw [Real.Angle.toReal_coe_eq_self_iff_mem_Ioc]\n  exact arg_mem_Ioc _\n#align complex.arg_coe_angle_to_real_eq_arg Complex.arg_coe_angle_toReal_eq_arg\n\ntheorem arg_coe_angle_eq_iff_eq_toReal {z : \u2102} {\u03b8 : Real.Angle} :\n    (arg z : Real.Angle) = \u03b8 \u2194 arg z = \u03b8.toReal := by\n  rw [\u2190 Real.Angle.toReal_inj, arg_coe_angle_to_real_eq_arg]\n#align complex.arg_coe_angle_eq_iff_eq_to_real Complex.arg_coe_angle_eq_iff_eq_toReal\n\n@[simp]\ntheorem arg_coe_angle_eq_iff {x y : \u2102} : (arg x : Real.Angle) = arg y \u2194 arg x = arg y := by\n  simp_rw [\u2190 Real.Angle.toReal_inj, arg_coe_angle_to_real_eq_arg]\n#align complex.arg_coe_angle_eq_iff Complex.arg_coe_angle_eq_iff\n\nsection Continuity\n\nvariable {x z : \u2102}\n\ntheorem arg_eq_nhds_of_re_pos (hx : 0 < x.re) : arg =\u1da0[\ud835\udcdd x] fun x => Real.arcsin (x.im / x.abs) :=\n  ((continuous_re.Tendsto _).Eventually (lt_mem_nhds hx)).mono fun y hy => arg_of_re_nonneg hy.le\n#align complex.arg_eq_nhds_of_re_pos Complex.arg_eq_nhds_of_re_pos\n\ntheorem arg_eq_nhds_of_re_neg_of_im_pos (hx_re : x.re < 0) (hx_im : 0 < x.im) :\n    arg =\u1da0[\ud835\udcdd x] fun x => Real.arcsin ((-x).im / x.abs) + \u03c0 :=\n  by\n  suffices h_forall_nhds : \u2200\u1da0 y : \u2102 in \ud835\udcdd x, y.re < 0 \u2227 0 < y.im\n  exact h_forall_nhds.mono fun y hy => arg_of_re_neg_of_im_nonneg hy.1 hy.2.le\n  refine' IsOpen.eventually_mem _ (\u27e8hx_re, hx_im\u27e9 : x.re < 0 \u2227 0 < x.im)\n  exact\n    IsOpen.and (isOpen_lt continuous_re continuous_zero) (isOpen_lt continuous_zero continuous_im)\n#align complex.arg_eq_nhds_of_re_neg_of_im_pos Complex.arg_eq_nhds_of_re_neg_of_im_pos\n\ntheorem arg_eq_nhds_of_re_neg_of_im_neg (hx_re : x.re < 0) (hx_im : x.im < 0) :\n    arg =\u1da0[\ud835\udcdd x] fun x => Real.arcsin ((-x).im / x.abs) - \u03c0 :=\n  by\n  suffices h_forall_nhds : \u2200\u1da0 y : \u2102 in \ud835\udcdd x, y.re < 0 \u2227 y.im < 0\n  exact h_forall_nhds.mono fun y hy => arg_of_re_neg_of_im_neg hy.1 hy.2\n  refine' IsOpen.eventually_mem _ (\u27e8hx_re, hx_im\u27e9 : x.re < 0 \u2227 x.im < 0)\n  exact\n    IsOpen.and (isOpen_lt continuous_re continuous_zero) (isOpen_lt continuous_im continuous_zero)\n#align complex.arg_eq_nhds_of_re_neg_of_im_neg Complex.arg_eq_nhds_of_re_neg_of_im_neg\n\ntheorem arg_eq_nhds_of_im_pos (hz : 0 < im z) : arg =\u1da0[\ud835\udcdd z] fun x => Real.arccos (x.re / abs x) :=\n  ((continuous_im.Tendsto _).Eventually (lt_mem_nhds hz)).mono fun x => arg_of_im_pos\n#align complex.arg_eq_nhds_of_im_pos Complex.arg_eq_nhds_of_im_pos\n\ntheorem arg_eq_nhds_of_im_neg (hz : im z < 0) : arg =\u1da0[\ud835\udcdd z] fun x => -Real.arccos (x.re / abs x) :=\n  ((continuous_im.Tendsto _).Eventually (gt_mem_nhds hz)).mono fun x => arg_of_im_neg\n#align complex.arg_eq_nhds_of_im_neg Complex.arg_eq_nhds_of_im_neg\n\ntheorem continuousAt_arg (h : 0 < x.re \u2228 x.im \u2260 0) : ContinuousAt arg x :=\n  by\n  have h\u2080 : abs x \u2260 0 := by\n    rw [abs.ne_zero_iff]\n    rintro rfl\n    simpa using h\n  rw [\u2190 lt_or_lt_iff_ne] at h\n  rcases h with (hx_re | hx_im | hx_im)\n  exacts[(real.continuous_at_arcsin.comp\n          (continuous_im.continuous_at.div continuous_abs.continuous_at h\u2080)).congr\n      (arg_eq_nhds_of_re_pos hx_re).symm,\n    (real.continuous_arccos.continuous_at.comp\n            (continuous_re.continuous_at.div continuous_abs.continuous_at h\u2080)).neg.congr\n      (arg_eq_nhds_of_im_neg hx_im).symm,\n    (real.continuous_arccos.continuous_at.comp\n          (continuous_re.continuous_at.div continuous_abs.continuous_at h\u2080)).congr\n      (arg_eq_nhds_of_im_pos hx_im).symm]\n#align complex.continuous_at_arg Complex.continuousAt_arg\n\ntheorem tendsto_arg_nhdsWithin_im_neg_of_re_neg_of_im_zero {z : \u2102} (hre : z.re < 0)\n    (him : z.im = 0) : Tendsto arg (\ud835\udcdd[{ z : \u2102 | z.im < 0 }] z) (\ud835\udcdd (-\u03c0)) :=\n  by\n  suffices H :\n    tendsto (fun x : \u2102 => Real.arcsin ((-x).im / x.abs) - \u03c0) (\ud835\udcdd[{ z : \u2102 | z.im < 0 }] z) (\ud835\udcdd (-\u03c0))\n  \u00b7 refine' H.congr' _\n    have : \u2200\u1da0 x : \u2102 in \ud835\udcdd z, x.re < 0 := continuous_re.tendsto z (gt_mem_nhds hre)\n    filter_upwards [self_mem_nhdsWithin, mem_nhdsWithin_of_mem_nhds this]with _ him hre\n    rw [arg, if_neg hre.not_le, if_neg him.not_le]\n  convert(real.continuous_at_arcsin.comp_continuous_within_at\n          ((continuous_im.continuous_at.comp_continuous_within_at continuousWithinAt_neg).div\n            continuous_abs.continuous_within_at _)).sub\n      tendsto_const_nhds\n  \u00b7 simp [him]\n  \u00b7 lift z to \u211d using him\n    simpa using hre.ne\n#align complex.tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero Complex.tendsto_arg_nhdsWithin_im_neg_of_re_neg_of_im_zero\n\ntheorem continuousWithinAt_arg_of_re_neg_of_im_zero {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n    ContinuousWithinAt arg { z : \u2102 | 0 \u2264 z.im } z :=\n  by\n  have : arg =\u1da0[\ud835\udcdd[{ z : \u2102 | 0 \u2264 z.im }] z] fun x => Real.arcsin ((-x).im / x.abs) + \u03c0 :=\n    by\n    have : \u2200\u1da0 x : \u2102 in \ud835\udcdd z, x.re < 0 := continuous_re.tendsto z (gt_mem_nhds hre)\n    filter_upwards [self_mem_nhdsWithin, mem_nhdsWithin_of_mem_nhds this]with _ him hre\n    rw [arg, if_neg hre.not_le, if_pos him]\n  refine' ContinuousWithinAt.congr_of_eventuallyEq _ this _\n  \u00b7 refine'\n      (real.continuous_at_arcsin.comp_continuous_within_at\n            ((continuous_im.continuous_at.comp_continuous_within_at continuousWithinAt_neg).div\n              continuous_abs.continuous_within_at _)).add\n        tendsto_const_nhds\n    lift z to \u211d using him\n    simpa using hre.ne\n  \u00b7 rw [arg, if_neg hre.not_le, if_pos him.ge]\n#align complex.continuous_within_at_arg_of_re_neg_of_im_zero Complex.continuousWithinAt_arg_of_re_neg_of_im_zero\n\ntheorem tendsto_arg_nhdsWithin_im_nonneg_of_re_neg_of_im_zero {z : \u2102} (hre : z.re < 0)\n    (him : z.im = 0) : Tendsto arg (\ud835\udcdd[{ z : \u2102 | 0 \u2264 z.im }] z) (\ud835\udcdd \u03c0) := by\n  simpa only [arg_eq_pi_iff.2 \u27e8hre, him\u27e9] using\n    (continuous_within_at_arg_of_re_neg_of_im_zero hre him).Tendsto\n#align complex.tendsto_arg_nhds_within_im_nonneg_of_re_neg_of_im_zero Complex.tendsto_arg_nhdsWithin_im_nonneg_of_re_neg_of_im_zero\n\ntheorem continuousAt_arg_coe_angle (h : x \u2260 0) : ContinuousAt (coe \u2218 arg : \u2102 \u2192 Real.Angle) x :=\n  by\n  by_cases hs : 0 < x.re \u2228 x.im \u2260 0\n  \u00b7 exact real.angle.continuous_coe.continuous_at.comp (continuous_at_arg hs)\n  \u00b7 rw [\u2190 Function.comp.right_id (coe \u2218 arg),\n      (Function.funext_iff.2 fun _ => (neg_neg _).symm : (id : \u2102 \u2192 \u2102) = Neg.neg \u2218 Neg.neg), \u2190\n      Function.comp.assoc]\n    refine' ContinuousAt.comp _ continuous_neg.continuous_at\n    suffices ContinuousAt (Function.update ((coe \u2218 arg) \u2218 Neg.neg : \u2102 \u2192 Real.Angle) 0 \u03c0) (-x) by\n      rwa [continuousAt_update_of_ne (neg_ne_zero.2 h)] at this\n    have ha :\n      Function.update ((coe \u2218 arg) \u2218 Neg.neg : \u2102 \u2192 Real.Angle) 0 \u03c0 = fun z =>\n        (arg z : Real.Angle) + \u03c0 :=\n      by\n      rw [Function.update_eq_iff]\n      exact \u27e8by simp, fun z hz => arg_neg_coe_angle hz\u27e9\n    rw [ha]\n    push_neg  at hs\n    refine'\n      (real.angle.continuous_coe.continuous_at.comp (continuous_at_arg (Or.inl _))).add\n        continuousAt_const\n    rw [neg_re, neg_pos]\n    exact hs.1.lt_of_ne fun h0 => h (ext_iff.2 \u27e8h0, hs.2\u27e9)\n#align complex.continuous_at_arg_coe_angle Complex.continuousAt_arg_coe_angle\n\nend Continuity\n\nend Complex\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/SpecialFunctions/Complex/Arg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7327522469275535}}
{"text": "import game.sup_inf.level02\nimport data.real.basic\n\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 3\n-/\n\n/- \nThis level asks you to prove what the supremum of a given open set is.\n-/\n\ndefinition reals_lt_59 := {x : \u211d | x < 59}\n\n-- begin hide\n-- The next result must be placed in the sidebar axioms.\ntheorem helper_lemma (x y : \u211d) (H : x < y) : x < (x + y) / 2 \u2227 (x + y) / 2 < y :=\nbegin\n  have two_ge_zero : (2 : \u211d) \u2265 0 := by norm_num,\n  split,\n  { apply lt_of_mul_lt_mul_right _ two_ge_zero,\n    rw [mul_two,div_mul_cancel],\n    apply add_lt_add_left H,\n    norm_num},\n  { apply lt_of_mul_lt_mul_right _ two_ge_zero,\n    rw [div_mul_cancel,mul_two],\n    apply add_lt_add_right H,\n    norm_num,\n  },\nend\n-- end hide\n\n/- Lemma\nThe LUB of...\n-/\nlemma lub_of_open_set : is_lub reals_lt_59 59 := \nbegin\n  split,\n  intro h,\n  intro j,\n  exact le_of_lt j,\n\n  intro h,\n  intro j,\n  apply le_of_not_gt,\n  intro k,\n  let s := (h + 59) / 2,\n  have H1 : h < s := (helper_lemma _ _ k).1,\n  have H2 : s < 59 := (helper_lemma _ _ k).2,\n  unfold is_upper_bound at j,\n  have H1' := j s H2,\n  exact not_le_of_lt H1 H1',\nend \n\nend xena -- hide\n\n\n\n\n\n\n\n/-\nsplit,\n  { intros s Hs,\n    exact le_of_lt Hs,\n  },\n  { intros y Hy,\n    apply le_of_not_gt,\n    intro H,\n    let s := (y + 59) / 2,\n    have H1 : y < s := (helper_lemma _ _ H).1,\n    have H2 : s < 59 := (helper_lemma _ _ H).2,\n--    unfold is_upper_bound at Hy,\n    have H1' := Hy s H2,\n    exact not_le_of_lt H1 H1', --of_not_gt\n  }\n-/", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/sup_inf/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.732752246106289}}
{"text": "import plane_separation_world.hilbertaxioms --hide\nopen IncidencePlane --hide\n\n/- Axiom :\npasch (hnc: \u00ac C \u2208 line_through A B)\n(hnAl: \u00ac (A \u2208 \u2113)) (hnBl: \u00ac B \u2208 \u2113) (hnCl: \u00ac C \u2208 \u2113) (hDl: D \u2208 \u2113) (hADB: A * D * B) :\n(\u2203 E ,  E \u2208 \u2113 \u2227 (A * E * C)) xor (\u2203 E, E \u2208 \u2113 \u2227 (B * E * C))\n-/\n\n/-\n# Plane Separation World\n\n## Level 1: a new world of possibilities...\n\nThe notion of **plane separation** comes from the fourth axiom of order, which is the Pasch's Axiom. \n\n**B.4) Pasch's Axiom:** Let A, B, C be three non-collinear points and let \u2113 be a line lying in the plane ABC\nand not passing through any of the points A, B, C. Then, if the line \u2113 passes through a point of the segment A\u00b7B, \nit will also pass through either a point of the segment B\u00b7C or a point of the segment A\u00b7C (but not both).\n\nIn Lean, the Pasch's Axiom may be useful to complete following levels:\n\n* `lemma pasch {A B C D : \u03a9} {\u2113 : Line \u03a9} (hnc: \u00ac C \u2208 line_through A B)\n(hnAl: \u00ac (A \u2208 \u2113)) (hnBl: \u00ac B \u2208 \u2113) (hnCl: \u00ac C \u2208 \u2113) (hDl: D \u2208 \u2113) (hADB: A * D * B) :\n(\u2203 E ,  E \u2208 \u2113 \u2227 (A * E * C)) xor (\u2203 E, E \u2208 \u2113 \u2227 (B * E * C))`\n\nThanks to this, we can define what \"being on the same side\" means. \n\n**Definition:** Given a line \u2113 and the points A and B, such that A, B \u2209 \u2113, we say that A and B are on the same side if\nthe segment A\u00b7B does not meet \u2113 or A = B.\n\nIn Lean, the definition of `same_side` is represented as follows: \n\n* `def same_side (\u2113 : Line \u03a9) (P Q : \u03a9) :=  pts (P\u2b1dQ) \u2229 \u2113 = \u2205`\n\nThe text `pts (P\u2b1dQ) \u2229 \u2113 = \u2205` can be read as \"the intersection (**\u2229**) of the points in the segment P\u2b1dQ and the line \u2113 is an empty set (**\u2205**)\". Therefore, \nP and Q are on the same side of \u2113. \n\n[**Rule of thumb:** Whenever you see `same_side` in Lean, use the `unfold` tactic. In this way, it will be easier to understand what it means. If it is \nlocated at the hypothesis `h2`, for example, then `unfold same_side at h2,` will make progress. If it is located at the goal, then `unfold same_side,` will be enough \nto rewrite the goal. This will change `same_side` into a text of the form `pts (P\u2b1dQ) \u2229 \u2113 = \u2205`. Then, you can use the `simp` tactic in the same way to change a text\nof the form `pts (P\u2b1dQ) \u2229 \u2113 = \u2205` into `{x : \u03a9 | x = P \u2228 x = Q \u2228 P*x*Q} \u2229 \u2191\u2113 = \u2205`, which may feel more understandable to you.]\n\n## Let Lean put in the donkey work...\n\nDo you remember when we said that Lean can complete some moderately difficult statements on its own?  To solve this level, we are going to learn some AI\n`tactics`. Before anything else, read the lemma and try to think of a mathematical proof. Can you see that we can prove it by contradiction? Let's solve this!\n\nTo begin with, delete the `sorry` and note that the hypothesis `h` shows the definition of `same_side`. Then, we can type `unfold same_side at h,` to change it\ninto `h: pts (A\u2b1dB) \u2229 \u2191\u2113 = \u2205`. \n\nSubsequently, we can tell Lean to help us. Type `simp at h,` and see how it now turns into `h: {x : \u03a9 | x = A \u2228 x = B \u2228 A*x*B} \u2229 \u2191\u2113 = \u2205`.\n\nNow it comes the genius idea. Because we know that the segment A\u00b7B does not intersect the line \u2113, let us assume the opposite of what we want to\nprove. That is, type `by_contradiction h1,` to add the hypothesis `h1 : A \u2208 \u2113` and change the goal into `\u22a2 false`.\n\nRight after, add the hypothesis `A \u2208 pts(A\u2b1dB) \u2229 \u2113`. That is, assume that the point A is an element of the intersection between the segment A\u00b7B and the line \u2113.\nTo prove it, you will need to type `split,` and type `simp [h1],` twice. What does this mean? The `simp` tactic will look for the lemmas that Lean remembers and\ntry to close the goal with them. \n\nTo finish with, can you see that the hypothesis that you've just proved (`A \u2208 pts(A\u2b1dB) \u2229 \u2113`) contradicts the hypothesis `h : {x : \u03a9 | x = A \u2228 x = B \u2228 A*x*B} \u2229 \u2191\u2113 = \u2205`?\nBecause of this reason, we can type `finish,` to \"finish\" the proof. This tactic uses propositional logic and works only when the laws of logic are able to close a goal.\nIn this case, since the `finish` tactic finds a contradiction between two hypotheses, then it can close the goal and hence finish the proof.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nDon't forget to finish every line with a comma. Still bewildered? Click on \"View source\" (located on the top right\ncorner of the game screen) to see the solution. \n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B C P Q R : \u03a9} --hide\nvariables {\u2113 r s t : Line \u03a9} --hide\n\n/- Lemma :\nIf the segment `P\u00b7Q` is on the same side of a line \u2113, then `P \u2209 \u2113`.\n-/\nlemma not_in_line_of_same_side_left (h : same_side \u2113 A B) : A \u2209 \u2113 :=\nbegin\n  unfold same_side at h,\n  simp at h,\n  by_contradiction h1,\n  have h2 : A \u2208 pts(A\u2b1dB) \u2229 \u2113,\n  {\n    split,\n    simp [h1],\n    simp [h1],\n  },\n  finish,\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/plane_separation_world/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7327522358731411}}
{"text": "import tactic\nimport data.real.basic\n\n-- Some notes on Lean's coercion\n\n-- Here since 1 and 2 are Natural numbers and so 1 - 2 evaluates to 0\n#eval (1 : \u2115) - (2 : \u2115)\n\n-- When using integers you get correct value of -1 : \u2124\n#eval (1 : \u2124) - (2 : \u2124)\n\n\n-- Note, Natural numbers are automaticially coerced to Integers\nexample : (2 : \u2124) = (2 : \u2115) := begin\n  -- If you look at the goal for this you will actually see\n  -- 2 = \u21912\n  -- the up arrow is coercing 2 as a Natrual number to 2 as an Integer\n  refl,\n  -- the proof isn't that 2 as an integer is 2 as a nutural number\n  -- it's a proof that 2 as an integer is the same as 2 the natural number coerced (converted to) an integer\nend\n\n-- This doesn't work the other way around because the Lean elaborator processes left to right\n-- if it sees 2 : \u2115 first, then it expects Natural numbers.\n-- In this case we have to manually add the \u2191 to coerce the natural number 2.\nexample : \u2191(2 : \u2115) = (2 : \u2124) := begin\n  -- the proof by reflextivity is the same however.\n  refl,\nend\n\n-- NOTE: The coersion \u2191 character is entered by typing \\u\n\n-- Here's the same example using real numbers rather than integers.\nexample : (2 : \u211d) = (2 : \u2115) := begin\n  -- refl  doesn't solve this goal, but norm_cast will\n  norm_cast,\nend\n\n-- As before, this way around and we need to manually add the coercion.\nexample : \u2191(2 : \u2115) = (2 : \u211d) := begin\n  norm_cast,\nend\n\n\n-- Just to complete the set, here's the examples with real and integers.\nexample : (2 : \u211d) = (2 : \u2124) := begin\n  norm_cast,\nend\n\nexample : \u2191(2 : \u2124) = (2 : \u211d) := begin\n  norm_cast,\nend\n", "meta": {"author": "andrewparr", "repo": "my_lean_project", "sha": "6c42f8a5d8b6548b5871d589054820b4bd8eedcc", "save_path": "github-repos/lean/andrewparr-my_lean_project", "path": "github-repos/lean/andrewparr-my_lean_project/my_lean_project-6c42f8a5d8b6548b5871d589054820b4bd8eedcc/src/notes/coercion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460027, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7327477864543324}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Eric Wieser\n\n! This file was ported from Lean 3 source module algebra.char_p.quotient\n! leanprover-community/mathlib commit 85e3c05a94b27c84dc6f234cf88326d5e0096ec3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.CharP.Basic\nimport Mathlib.RingTheory.Ideal.Quotient\n\n/-!\n# Characteristic of quotients rings\n-/\n\n\nuniverse u v\n\nnamespace CharP\n\ntheorem quotient (R : Type u) [CommRing R] (p : \u2115) [hp1 : Fact p.Prime] (hp2 : \u2191p \u2208 nonunits R) :\n    CharP (R \u29f8 (Ideal.span ({(p : R)} : Set R) : Ideal R)) p :=\n  have hp0 : (p : R \u29f8 (Ideal.span {(p : R)} : Ideal R)) = 0 :=\n    map_natCast (Ideal.Quotient.mk (Ideal.span {(p : R)} : Ideal R)) p \u25b8\n      Ideal.Quotient.eq_zero_iff_mem.2 (Ideal.subset_span <| Set.mem_singleton _)\n  ringChar.of_eq <|\n    Or.resolve_left ((Nat.dvd_prime hp1.1).1 <| ringChar.dvd hp0) fun h1 =>\n      hp2 <|\n        isUnit_iff_dvd_one.2 <|\n          Ideal.mem_span_singleton.1 <|\n            Ideal.Quotient.eq_zero_iff_mem.1 <|\n              @Subsingleton.elim _ (@CharOne.subsingleton _ _ (ringChar.of_eq h1)) _ _\n#align char_p.quotient CharP.quotient\n\n/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient\ninherits the characteristic of the underlying ring. -/\ntheorem quotient' {R : Type _} [CommRing R] (p : \u2115) [CharP R p] (I : Ideal R)\n    (h : \u2200 x : \u2115, (x : R) \u2208 I \u2192 (x : R) = 0) : CharP (R \u29f8 I) p :=\n  \u27e8fun x => by\n    rw [\u2190 cast_eq_zero_iff R p x, \u2190 map_natCast (Ideal.Quotient.mk I)]\n    refine' Ideal.Quotient.eq.trans (_ : \u2191x - 0 \u2208 I \u2194 _)\n    rw [sub_zero]\n    exact \u27e8h x, fun h' => h'.symm \u25b8 I.zero_mem\u27e9\u27e9\n#align char_p.quotient' CharP.quotient'\n\nend CharP\n\nset_option synthInstance.etaExperiment true in\ntheorem Ideal.Quotient.index_eq_zero {R : Type _} [CommRing R] (I : Ideal R) :\n    (\u2191I.toAddSubgroup.index : R \u29f8 I) = 0 := by\n  rw [AddSubgroup.index, Nat.card_eq]\n  split_ifs with hq; swap; simp\n  by_contra h\n  -- TODO: can we avoid rewriting the `I.to_add_subgroup` here?\n  letI : Fintype (R \u29f8 I) := @Fintype.ofFinite _ hq\n  have h : (Fintype.card (R \u29f8 I) : R \u29f8 I) \u2260 0 := h\n  simp at h\n#align ideal.quotient.index_eq_zero Ideal.Quotient.index_eq_zero\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/CharP/Quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7326337692656602}}
{"text": "/-\nCopyright (c) 2018 Guy Leroy. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport data.nat.prime\n/-!\n# Extended GCD and divisibility over \u2124\n\n## Main definitions\n\n* Given `x y : \u2115`, `xgcd x y` computes the pair of integers `(a, b)` such that\n  `gcd x y = x * a + y * b`. `gcd_a x y` and `gcd_b x y` are defined to be `a` and `b`,\n  respectively.\n\n## Main statements\n\n* `gcd_eq_gcd_ab`: B\u00e9zout's lemma, given `x y : \u2115`, `gcd x y = x * gcd_a x y + y * gcd_b x y`.\n\n-/\n\n/-! ### Extended Euclidean algorithm -/\nnamespace nat\n\n/-- Helper function for the extended GCD algorithm (`nat.xgcd`). -/\ndef xgcd_aux : \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u00d7 \u2124 \u00d7 \u2124\n| 0          s t r' s' t' := (r', s', t')\n| r@(succ _) s t r' s' t' :=\n  have r' % r < r, from mod_lt _ $ succ_pos _,\n  let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t\n\n@[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=\nby simp [xgcd_aux]\n\ntheorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) :\n  xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=\nby cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}]\n\n/-- Use the extended GCD algorithm to generate the `a` and `b` values\n  satisfying `gcd x y = x * a + y * b`. -/\ndef xgcd (x y : \u2115) : \u2124 \u00d7 \u2124 := (xgcd_aux x 1 0 y 0 1).2\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a (x y : \u2115) : \u2124 := (xgcd x y).1\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b (x y : \u2115) : \u2124 := (xgcd x y).2\n\n@[simp] theorem gcd_a_zero_left {s : \u2115} : gcd_a 0 s = 0 :=\nby { unfold gcd_a, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_b_zero_left {s : \u2115} : gcd_b 0 s = 1 :=\nby { unfold gcd_b, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_a_zero_right {s : \u2115} (h : s \u2260 0) : gcd_a s 0 = 1 :=\nbegin\n  unfold gcd_a xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem gcd_b_zero_right {s : \u2115} (h : s \u2260 0) : gcd_b s 0 = 0 :=\nbegin\n  unfold gcd_b xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem xgcd_aux_fst (x y) : \u2200 s t s' t',\n  (xgcd_aux x s t y s' t').1 = gcd x y :=\ngcd.induction x y (by simp) (\u03bb x y h IH s t s' t', by simp [xgcd_aux_rec, h, IH]; rw \u2190 gcd_rec)\n\ntheorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=\nby rw [xgcd, \u2190 xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl\n\ntheorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nby unfold gcd_a gcd_b; cases xgcd x y; refl\n\nsection\nparameters (x y : \u2115)\n\nprivate def P : \u2115 \u00d7 \u2124 \u00d7 \u2124 \u2192 Prop\n| (r, s, t) := (r : \u2124) = x * s + y * t\n\ntheorem xgcd_aux_P {r r'} : \u2200 {s t s' t'}, P (r, s, t) \u2192 P (r', s', t') \u2192\n  P (xgcd_aux r s t r' s' t') :=\ngcd.induction r r' (by simp) $ \u03bb a b h IH s t s' t' p p', begin\n  rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *,\n  rw [int.mod_def], generalize : (b / a : \u2124) = k,\n  rw [p, p'],\n  simp [mul_add, mul_comm, mul_left_comm, add_comm, add_left_comm, sub_eq_neg_add, mul_assoc]\nend\n\n/-- B\u00e9zout's lemma: given `x y : \u2115`, `gcd x y = x * a + y * b`, where `a = gcd_a x y` and\n`b = gcd_b x y` are computed by the extended Euclidean algorithm.\n-/\ntheorem gcd_eq_gcd_ab : (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y :=\nby have := @xgcd_aux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P]);\n   rwa [xgcd_aux_val, xgcd_val] at this\nend\n\nlemma exists_mul_mod_eq_gcd {k n : \u2115} (hk : gcd n k < k) :\n  \u2203 m, n * m % k = gcd n k :=\nbegin\n  have hk' := int.coe_nat_ne_zero.mpr (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk)),\n  have key := congr_arg (\u03bb m, int.nat_mod m k) (gcd_eq_gcd_ab n k),\n  simp_rw int.nat_mod at key,\n  rw [int.add_mul_mod_self_left, \u2190int.coe_nat_mod, int.to_nat_coe_nat, mod_eq_of_lt hk] at key,\n  refine \u27e8(n.gcd_a k % k).to_nat, eq.trans (int.coe_nat_inj _) key.symm\u27e9,\n  rw [int.coe_nat_mod, int.coe_nat_mul, int.to_nat_of_nonneg (int.mod_nonneg _ hk'),\n      int.to_nat_of_nonneg (int.mod_nonneg _ hk'), int.mul_mod, int.mod_mod, \u2190int.mul_mod],\nend\n\nlemma exists_mul_mod_eq_one_of_coprime {k n : \u2115} (hkn : coprime n k) (hk : 1 < k) :\n  \u2203 m, n * m % k = 1 :=\nExists.cases_on (exists_mul_mod_eq_gcd (lt_of_le_of_lt (le_of_eq hkn) hk))\n  (\u03bb m hm, \u27e8m, hm.trans hkn\u27e9)\n\nend nat\n\n/-! ### Divisibility over \u2124 -/\nnamespace int\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a : \u2124 \u2192 \u2124 \u2192 \u2124\n| (of_nat m) n := m.gcd_a n.nat_abs\n| -[1+ m]    n := -m.succ.gcd_a n.nat_abs\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b : \u2124 \u2192 \u2124 \u2192 \u2124\n| m (of_nat n) := m.nat_abs.gcd_b n\n| m -[1+ n]    := -m.nat_abs.gcd_b n.succ\n\ntheorem gcd_eq_gcd_ab : \u2200 x y : \u2124, (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y\n| (m : \u2115) (n : \u2115) := nat.gcd_eq_gcd_ab _ _\n| (m : \u2115) -[1+ n] := show (_ : \u2124) = _ + -(n+1) * -_, by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] (n : \u2115) := show (_ : \u2124) = -(m+1) * -_ + _ , by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] -[1+ n] := show (_ : \u2124) = -(m+1) * -_ + -(n+1) * -_,\n  by { rw [neg_mul_neg, neg_mul_neg], apply nat.gcd_eq_gcd_ab }\n\ntheorem nat_abs_div (a b : \u2124) (H : b \u2223 a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) :=\nbegin\n  cases (nat.eq_zero_or_pos (nat_abs b)),\n  {rw eq_zero_of_nat_abs_eq_zero h, simp [int.div_zero]},\n  calc\n  nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one\n    ... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h\n    ... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ (dvd_refl _))\n    ... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b)\n    ... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H,\nend\n\ntheorem nat_abs_dvd_abs_iff {i j : \u2124} : i.nat_abs \u2223 j.nat_abs \u2194 i \u2223 j :=\n\u27e8assume (H : i.nat_abs \u2223 j.nat_abs), dvd_nat_abs.mp (nat_abs_dvd.mp (coe_nat_dvd.mpr H)),\nassume H : (i \u2223 j), coe_nat_dvd.mp (dvd_nat_abs.mpr (nat_abs_dvd.mpr H))\u27e9\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : nat.prime p) {m n : \u2124} {k l : \u2115}\n      (hpm : \u2191(p ^ k) \u2223 m)\n      (hpn : \u2191(p ^ l) \u2223 n) (hpmn : \u2191(p ^ (k+l+1)) \u2223 m*n) : \u2191(p ^ (k+1)) \u2223 m \u2228 \u2191(p ^ (l+1)) \u2223 n :=\nhave hpm' : p ^ k \u2223 m.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpm,\nhave hpn' : p ^ l \u2223 n.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpn,\nhave hpmn' : (p ^ (k+l+1)) \u2223 m.nat_abs*n.nat_abs,\n  by rw \u2190int.nat_abs_mul; apply (int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpmn),\nlet hsd := nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn' in\nhsd.elim\n  (\u03bb hsd1, or.inl begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd1 end)\n  (\u03bb hsd2, or.inr begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd2 end)\n\ntheorem dvd_of_mul_dvd_mul_left {i j k : \u2124} (k_non_zero : k \u2260 0) (H : k * i \u2223 k * j) : i \u2223 j :=\ndvd.elim H (\u03bbl H1, by rw mul_assoc at H1; exact \u27e8_, mul_left_cancel' k_non_zero H1\u27e9)\n\ntheorem dvd_of_mul_dvd_mul_right {i j k : \u2124} (k_non_zero : k \u2260 0) (H : i * k \u2223 j * k) : i \u2223 j :=\nby rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H\n\nlemma prime.dvd_nat_abs_of_coe_dvd_sq {p : \u2115} (hp : p.prime) (k : \u2124) (h : \u2191p \u2223 k ^ 2) :\n  p \u2223 k.nat_abs :=\nbegin\n  apply @nat.prime.dvd_of_dvd_pow _ _ 2 hp,\n  rwa [sq, \u2190 nat_abs_mul, \u2190 coe_nat_dvd_left, \u2190 sq]\nend\n\n/-- \u2124 specific version of least common multiple. -/\ndef lcm (i j : \u2124) : \u2115 := nat.lcm (nat_abs i) (nat_abs j)\n\ntheorem lcm_def (i j : \u2124) : lcm i j = nat.lcm (nat_abs i) (nat_abs j) := rfl\n\ntheorem gcd_dvd_left (i j : \u2124) : (gcd i j : \u2124) \u2223 i :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_left _ _\n\ntheorem gcd_dvd_right (i j : \u2124) : (gcd i j : \u2124) \u2223 j :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_right _ _\n\ntheorem dvd_gcd {i j k : \u2124} (h1 : k \u2223 i) (h2 : k \u2223 j) : k \u2223 gcd i j :=\nnat_abs_dvd.1 $ coe_nat_dvd.2 $ nat.dvd_gcd (nat_abs_dvd_abs_iff.2 h1) (nat_abs_dvd_abs_iff.2 h2)\n\ntheorem gcd_mul_lcm (i j : \u2124) : gcd i j * lcm i j = nat_abs (i * j) :=\nby rw [int.gcd, int.lcm, nat.gcd_mul_lcm, nat_abs_mul]\n\ntheorem gcd_comm (i j : \u2124) : gcd i j = gcd j i := nat.gcd_comm _ _\n\ntheorem gcd_assoc (i j k : \u2124) : gcd (gcd i j) k = gcd i (gcd j k) := nat.gcd_assoc _ _ _\n\n@[simp] theorem gcd_self (i : \u2124) : gcd i i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_left (i : \u2124) : gcd 0 i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_right (i : \u2124) : gcd i 0 = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_one_left (i : \u2124) : gcd 1 i = 1 := nat.gcd_one_left _\n\n@[simp] theorem gcd_one_right (i : \u2124) : gcd i 1 = 1 := nat.gcd_one_right _\n\ntheorem gcd_mul_left (i j k : \u2124) : gcd (i * j) (i * k) = nat_abs i * gcd j k :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_left }\n\ntheorem gcd_mul_right (i j k : \u2124) : gcd (i * j) (k * j) = gcd i k * nat_abs j :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_right }\n\ntheorem gcd_pos_of_non_zero_left {i : \u2124} (j : \u2124) (i_non_zero : i \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_left (nat_abs j) (nat_abs_pos_of_ne_zero i_non_zero)\n\ntheorem gcd_pos_of_non_zero_right (i : \u2124) {j : \u2124} (j_non_zero : j \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_right (nat_abs i) (nat_abs_pos_of_ne_zero j_non_zero)\n\ntheorem gcd_eq_zero_iff {i j : \u2124} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 :=\nbegin\n  rw int.gcd,\n  split,\n  { intro h,\n    exact \u27e8nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_left h),\n      nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_right h)\u27e9 },\n  { intro h, rw [nat_abs_eq_zero.mpr h.left, nat_abs_eq_zero.mpr h.right],\n    apply nat.gcd_zero_left }\nend\n\ntheorem gcd_div {i j k : \u2124} (H1 : k \u2223 i) (H2 : k \u2223 j) :\n  gcd (i / k) (j / k) = gcd i j / nat_abs k :=\nby rw [gcd, nat_abs_div i k H1, nat_abs_div j k H2];\nexact nat.gcd_div (nat_abs_dvd_abs_iff.mpr H1) (nat_abs_dvd_abs_iff.mpr H2)\n\ntheorem gcd_div_gcd_div_gcd {i j : \u2124} (H : 0 < gcd i j) :\n  gcd (i / gcd i j) (j / gcd i j) = 1 :=\nbegin\n  rw [gcd_div (gcd_dvd_left i j) (gcd_dvd_right i j)],\n  rw [nat_abs_of_nat, nat.div_self H]\nend\n\ntheorem gcd_dvd_gcd_of_dvd_left {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd i j \u2223 gcd k j :=\nint.coe_nat_dvd.1 $ dvd_gcd (dvd.trans (gcd_dvd_left i j) H) (gcd_dvd_right i j)\n\ntheorem gcd_dvd_gcd_of_dvd_right {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd j i \u2223 gcd j k :=\nint.coe_nat_dvd.1 $ dvd_gcd (gcd_dvd_left j i) (dvd.trans (gcd_dvd_right j i) H)\n\ntheorem gcd_dvd_gcd_mul_left (i j k : \u2124) : gcd i j \u2223 gcd (k * i) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (i j k : \u2124) : gcd i j \u2223 gcd (i * k) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (i j k : \u2124) : gcd i j \u2223 gcd i (k * j) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (i j k : \u2124) : gcd i j \u2223 gcd i (j * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {i j : \u2124} (H : i \u2223 j) : gcd i j = nat_abs i :=\nnat.dvd_antisymm (by unfold gcd; exact nat.gcd_dvd_left _ _)\n                 (by unfold gcd; exact nat.dvd_gcd (dvd_refl _) (nat_abs_dvd_abs_iff.mpr H))\n\ntheorem gcd_eq_right {i j : \u2124} (H : j \u2223 i) : gcd i j = nat_abs j :=\nby rw [gcd_comm, gcd_eq_left H]\n\ntheorem ne_zero_of_gcd {x y : \u2124}\n  (hc : gcd x y \u2260 0) : x \u2260 0 \u2228 y \u2260 0 :=\nbegin\n  contrapose! hc,\n  rw [hc.left, hc.right, gcd_zero_right, nat_abs_zero]\nend\n\ntheorem exists_gcd_one {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (m' n' : \u2124), gcd m' n' = 1 \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n\u27e8_, _, gcd_div_gcd_div_gcd H,\n  (int.div_mul_cancel (gcd_dvd_left m n)).symm,\n  (int.div_mul_cancel (gcd_dvd_right m n)).symm\u27e9\n\ntheorem exists_gcd_one' {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (g : \u2115) (m' n' : \u2124), 0 < g \u2227 gcd m' n' = 1 \u2227 m = m' * g \u2227 n = n' * g :=\nlet \u27e8m', n', h\u27e9 := exists_gcd_one H in \u27e8_, m', n', H, h\u27e9\n\ntheorem pow_dvd_pow_iff {m n : \u2124} {k : \u2115} (k0 : 0 < k) : m ^ k \u2223 n ^ k \u2194 m \u2223 n :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, pow_dvd_pow_of_dvd h _\u27e9,\n  apply int.nat_abs_dvd_abs_iff.mp,\n  apply (nat.pow_dvd_pow_iff k0).mp,\n  rw [\u2190 int.nat_abs_pow, \u2190 int.nat_abs_pow],\n  exact int.nat_abs_dvd_abs_iff.mpr h\nend\n\n/-! ### lcm -/\n\ntheorem lcm_comm (i j : \u2124) : lcm i j = lcm j i :=\nby { rw [int.lcm, int.lcm], exact nat.lcm_comm _ _ }\n\ntheorem lcm_assoc (i j k : \u2124) : lcm (lcm i j) k = lcm i (lcm j k) :=\nby { rw [int.lcm, int.lcm, int.lcm, int.lcm, nat_abs_of_nat, nat_abs_of_nat], apply nat.lcm_assoc }\n\n@[simp] theorem lcm_zero_left (i : \u2124) : lcm 0 i = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_left }\n\n@[simp] theorem lcm_zero_right (i : \u2124) : lcm i 0 = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_right }\n\n@[simp] theorem lcm_one_left (i : \u2124) : lcm 1 i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_left }\n\n@[simp] theorem lcm_one_right (i : \u2124) : lcm i 1 = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_right }\n\n@[simp] theorem lcm_self (i : \u2124) : lcm i i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_self }\n\ntheorem dvd_lcm_left (i j : \u2124) : i \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_left }\n\ntheorem dvd_lcm_right (i j : \u2124) : j \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_right }\n\ntheorem lcm_dvd {i j k : \u2124}  : i \u2223 k \u2192 j \u2223 k \u2192 (lcm i j : \u2124) \u2223 k :=\nbegin\n  rw int.lcm,\n  intros hi hj,\n  exact coe_nat_dvd_left.mpr\n    (nat.lcm_dvd (nat_abs_dvd_abs_iff.mpr hi) (nat_abs_dvd_abs_iff.mpr hj))\nend\n\nend int\n\nlemma pow_gcd_eq_one {M : Type*} [monoid M] (x : M) {m n : \u2115} (hm : x ^ m = 1) (hn : x ^ n = 1) :\n  x ^ m.gcd n = 1 :=\nbegin\n  cases m, { simp only [hn, nat.gcd_zero_left] },\n  obtain \u27e8x, rfl\u27e9 : is_unit x,\n  { apply is_unit_of_pow_eq_one _ _ hm m.succ_pos },\n  simp only [\u2190 units.coe_pow] at *,\n  rw [\u2190 units.coe_one, \u2190 gpow_coe_nat, \u2190 units.ext_iff] at *,\n  simp only [nat.gcd_eq_gcd_ab, gpow_add, gpow_mul, hm, hn, one_gpow, one_mul]\nend\n\nlemma gcd_nsmul_eq_zero {M : Type*} [add_monoid M] (x : M) {m n : \u2115} (hm : m \u2022 x = 0)\n  (hn : n \u2022 x = 0) : (m.gcd n) \u2022 x = 0 :=\nbegin\n  apply multiplicative.of_add.injective,\n  rw [of_add_nsmul, of_add_zero, pow_gcd_eq_one];\n  rwa [\u2190of_add_nsmul, \u2190of_add_zero, equiv.apply_eq_iff_eq]\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/int/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7326337648040208}}
{"text": "-- Divisibilidad_de_cuadrado.lean\n-- Si x \u2208 \u2115, entonces x \u2223 x^2.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 7-octubre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si x \u2208 \u2115, entonces\n--    x \u2223 x^2\n-- ----------------------------------------------------------------------\n\nimport data.nat.pow\nvariable x : \u2115\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2223 x^2 :=\nbegin\n  rw pow_two,\n  apply dvd_mul_right,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2223 x^2 :=\nby apply dvd_mul_right\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Divisibilidad_de_cuadrado.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7326337635758546}}
{"text": "import tactic.cancel_denoms\nimport tactic.ring\n\nvariables {\u03b1 : Type} [linear_ordered_field \u03b1] (a b c d : \u03b1)\n\nexample (h : a / 5 + b / 4 < c) : 4*a + 5*b < 20*c :=\nbegin\n  cancel_denoms at h,\n  exact h\nend\n\nexample (h : a > 0) : a / 5 > 0 :=\nbegin\n  cancel_denoms,\n  exact h\nend\n\nexample (h : a + b = c) : a/5 + d*(b/4) = c - 4*a/5 + b*2*d/8 - b :=\nbegin\n  cancel_denoms,\n  rw \u2190 h,\n  ring,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/test/cancel_denoms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.732633757384722}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport solutions.section14polynomials.sheet03aux_ideal\n\n/-!\n\nThis sheet contains a couple of trickier proofs about `aux_ideal`. \n\nHere is an explanation of the first -- igt's called `coeff_span_lift_gens`. \n\nSay R is Noetherian, and `c \u2208 aux_ideal I n`. Recall that `hR.gens (aux_ideal I n)`\nis a (finite) set which spans `aux_ideal I n` as an `R`-ideal. So in particular\nwe know that `c` is in the span of these generators.\n\nThe claim is that if we let `T : finset R[X]` be random `lift`s of these generators to `R[X]`,\nthen there's a polynomial `y` in the `R`-span of these lifts such that the coefficient of `X^n`\nin `y` is `c` again.\n\nOne way of doing this would be to write `c` as a finite `R`-linear combination of the generators,\nand then use the corresponding finite `R`-linear combination of the lifts. But that is a pain\nto code. \n\nThe proof I came up with of this uses `submodule.span_image`, which says that the span\nof the image equals the image of the span. In particular, the image of the lifts is just\nthe generators `hR.gens (aux_ideal I n)` again, so the image of the span is `aux_ideal I n`.\nThe theorem says that this means that the image of the `R`-span of the lifts in `R[X]` under\nthe `coeff` map is `aux_ideal I n` and so our element `y` comes for free.\n\nA key intermediate step in my proof is\n\nhave h : (hR.gens (aux_ideal I n) : set R) \u2286 (polynomial.lcoeff R n)'' \n    (finset.image (\u03bb (r : R), aux_ideal.lift I n r) (hR.gens (aux_ideal I n))),\n\nsaying that the generators are a subset of the image of the lift of the generators.\nI don't need to prove equality. After that it's just `submodule.span_image` and unravelling.\nMore precisely, `hcI` tells us that `c` is in the span of the generators, \nand `ideal.span_mono` reduces us to the case that `c` is in the span\nof the image under an `R`-module map of some set (namely the image of `lift`),\nBy `submodule.span_image` we're now done.\n-/\n\nvariables {R : Type} [comm_ring R] (I : ideal (polynomial R))\nvariables {n : \u2115} {r : R} [decidable (r \u2208 aux_ideal I n)]\n\nopen polynomial\n\nnamespace aux_ideal\n\nlemma coeff_span_lift_gens [\u2200 r, decidable (r \u2208 aux_ideal I n)] [decidable_eq (polynomial R)] \n  (hR : is_noetherian_ring R) {c : R} (hcI : c \u2208 aux_ideal I n) :\n\u2203 (y : polynomial R), y \u2208 submodule.span R ((\u03bb (r : R), lift I n r) '' \u2191(hR.gens (aux_ideal I n))) \u2227\n  (lcoeff R n) y = c :=\nbegin\n  -- so c \u2208 span of the generators `hR.gens`\n  have h : (hR.gens (aux_ideal I n) : set R) \u2286 (polynomial.lcoeff R n)'' \n    (finset.image (\u03bb (r : R), aux_ideal.lift I n r) (hR.gens (aux_ideal I n))),\n  { intros r hr,\n    refine \u27e8lift I n r, _, lift_spec _\u27e9,\n    { simp, refine \u27e8r, hr, rfl\u27e9 },\n    { apply hR.gens_subset _ hr } },\n  rw \u2190 hR.span_gens (aux_ideal I n) at hcI,\n  replace hcI := submodule.span_mono h hcI,\n  rw submodule.span_image at hcI,\n  rcases hcI with \u27e8y, hy\u27e9,\n  use y,\n  simpa using hy,\nend\n\n/-\n\nThe conclusion of the previous lemma says that there's some polynomial\nin `submodule.span R ((\u03bb (r : R), lift I n r) '' \u2191(hR.gens (aux_ideal I n)))`. \nThe below lemma shows that such a polynomial has degree at most `n`, and\nthe reason is simply that all the generators have degree at most `n`.\nTo solve this one you'll need to know `submodule.span_le` from mathlib\nand `lift_nat_degree_le` from a previous sheet.\n-/\n\nlemma nat_deg_le_of_mem_span_lift_gens [\u2200 r, decidable (r \u2208 aux_ideal I n)] \n  (hR : is_noetherian_ring R) {p : polynomial R}\n  (hp : p \u2208 submodule.span R ((\u03bb (r : R), lift I n r) '' (hR.gens (aux_ideal I n)))) :\np.nat_degree \u2264 n :=\nbegin\n  suffices : submodule.span R ((\u03bb (r : R), lift I n r) '' \u2191(hR.gens (aux_ideal I n))) \u2264 M R n,\n  { exact this hp, },\n  rw submodule.span_le,\n  intros f hf,\n  simp at hf,\n  rcases hf with \u27e8r, hr, rfl\u27e9,\n  apply lift_nat_degree_le,\nend\n\nend aux_ideal\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/solutions/section14polynomials/sheet04more_aux_ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7326146305325422}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.special_functions.exp\nimport topology.continuous_function.basic\nimport analysis.normed.field.unit_ball\n\n/-!\n# The circle\n\nThis file defines `circle` to be the metric sphere (`metric.sphere`) in `\u2102` centred at `0` of\nradius `1`.  We equip it with the following structure:\n\n* a submonoid of `\u2102`\n* a group\n* a topological group\n\nWe furthermore define `exp_map_circle` to be the natural map `\u03bb t, exp (t * I)` from `\u211d` to\n`circle`, and show that this map is a group homomorphism.\n\n## Implementation notes\n\nBecause later (in `geometry.manifold.instances.sphere`) one wants to equip the circle with a smooth\nmanifold structure borrowed from `metric.sphere`, the underlying set is\n`{z : \u2102 | abs (z - 0) = 1}`.  This prevents certain algebraic facts from working definitionally --\nfor example, the circle is not defeq to `{z : \u2102 | abs z = 1}`, which is the kernel of `complex.abs`\nconsidered as a homomorphism from `\u2102` to `\u211d`, nor is it defeq to `{z : \u2102 | norm_sq z = 1}`, which\nis the kernel of the homomorphism `complex.norm_sq` from `\u2102` to `\u211d`.\n\n-/\n\nnoncomputable theory\n\nopen complex metric\nopen_locale complex_conjugate\n\n/-- The unit circle in `\u2102`, here given the structure of a submonoid of `\u2102`. -/\ndef circle : submonoid \u2102 := submonoid.unit_sphere \u2102\n\n@[simp] lemma mem_circle_iff_abs {z : \u2102} : z \u2208 circle \u2194 abs z = 1 := mem_sphere_zero_iff_norm\n\nlemma circle_def : \u2191circle = {z : \u2102 | abs z = 1} := set.ext $ \u03bb z, mem_circle_iff_abs\n\n@[simp] lemma abs_coe_circle (z : circle) : abs z = 1 :=\nmem_circle_iff_abs.mp z.2\n\nlemma mem_circle_iff_norm_sq {z : \u2102} : z \u2208 circle \u2194 norm_sq z = 1 :=\nby simp [complex.abs]\n\n@[simp] lemma norm_sq_eq_of_mem_circle (z : circle) : norm_sq z = 1 := by simp [norm_sq_eq_abs]\n\nlemma ne_zero_of_mem_circle (z : circle) : (z:\u2102) \u2260 0 := ne_zero_of_mem_unit_sphere z\n\ninstance : comm_group circle := metric.sphere.comm_group\n\n@[simp] lemma coe_inv_circle (z : circle) : \u2191(z\u207b\u00b9) = (z : \u2102)\u207b\u00b9 := rfl\n\nlemma coe_inv_circle_eq_conj (z : circle) : \u2191(z\u207b\u00b9) = conj (z : \u2102) :=\nby rw [coe_inv_circle, inv_def, norm_sq_eq_of_mem_circle, inv_one, of_real_one, mul_one]\n\n@[simp] lemma coe_div_circle (z w : circle) : \u2191(z / w) = (z:\u2102) / w :=\ncircle.subtype.map_div z w\n\n/-- The elements of the circle embed into the units. -/\ndef circle.to_units : circle \u2192* units \u2102 := unit_sphere_to_units \u2102\n\n-- written manually because `@[simps]` was slow and generated the wrong lemma\n@[simp] lemma circle.to_units_apply (z : circle) :\n  circle.to_units z = units.mk0 z (ne_zero_of_mem_circle z) := rfl\n\ninstance : compact_space circle := metric.sphere.compact_space _ _\n\ninstance : topological_group circle := metric.sphere.topological_group\n\n/-- If `z` is a nonzero complex number, then `conj z / z` belongs to the unit circle. -/\n@[simps] def circle.of_conj_div_self (z : \u2102) (hz : z \u2260 0) : circle :=\n\u27e8conj z / z, mem_circle_iff_abs.2 $ by rw [map_div\u2080, abs_conj, div_self (complex.abs.ne_zero hz)]\u27e9\n\n/-- The map `\u03bb t, exp (t * I)` from `\u211d` to the unit circle in `\u2102`. -/\ndef exp_map_circle : C(\u211d, circle) :=\n{ to_fun := \u03bb t, \u27e8exp (t * I), by simp [exp_mul_I, abs_cos_add_sin_mul_I]\u27e9 }\n\n@[simp] lemma exp_map_circle_apply (t : \u211d) : \u2191(exp_map_circle t) = complex.exp (t * complex.I) :=\nrfl\n\n@[simp] lemma exp_map_circle_zero : exp_map_circle 0 = 1 :=\nsubtype.ext $ by rw [exp_map_circle_apply, of_real_zero, zero_mul, exp_zero, submonoid.coe_one]\n\n@[simp] lemma exp_map_circle_add (x y : \u211d) :\n  exp_map_circle (x + y) = exp_map_circle x * exp_map_circle y :=\nsubtype.ext $ by simp only [exp_map_circle_apply, submonoid.coe_mul, of_real_add, add_mul,\n  complex.exp_add]\n\n/-- The map `\u03bb t, exp (t * I)` from `\u211d` to the unit circle in `\u2102`, considered as a homomorphism of\ngroups. -/\n@[simps]\ndef exp_map_circle_hom : \u211d \u2192+ (additive circle) :=\n{ to_fun := additive.of_mul \u2218 exp_map_circle,\n  map_zero' := exp_map_circle_zero,\n  map_add' := exp_map_circle_add }\n\n@[simp] lemma exp_map_circle_sub (x y : \u211d) :\n  exp_map_circle (x - y) = exp_map_circle x / exp_map_circle y :=\nexp_map_circle_hom.map_sub x y\n\n@[simp] lemma exp_map_circle_neg (x : \u211d) : exp_map_circle (-x) = (exp_map_circle x)\u207b\u00b9 :=\nexp_map_circle_hom.map_neg x\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/complex/circle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7326146224351885}}
{"text": "import algebra.category.CommRing.basic\nimport algebra.ring\nimport tactic\nimport data.polynomial\nimport algebra.ring\nimport category_theory.types\nimport data.int.basic\nuniverses v u \nopen CommRing\nopen is_ring_hom\nopen category_theory\nopen polynomial\nopen int\n/--\n## The goal is study the set of solution of polynomial equation in one variable ! We form a functor  V_P : CommRing \u2192 Type v \n##    For all ring \n## \n-/\n\nvariables(R : Type v)[comm_ring R](P : polynomial \u2124)\nstructure V  (R: Type v)[comm_ring R] :=      --  set of solution of P(x) = 0  with x in R    \n(x : R)                                       --  if \u03c6 : R \u2192 R' is a ring morphism then we have application\n(certif : eval\u2082(int.cast) (x) (P) = 0 )       --  \u03c6 : V(P)(R) \u2192 V(P(R')    \n@[ext]lemma ext : \u2200 {\u03b61 \u03b62 : V P R}, \u03b61.x = \u03b62.x \u2192  \u03b61 = \u03b62 := \u03bb \u03b61 \u03b62,  \nbegin\n  cases \u03b61,                                        \n  cases \u03b62,\n  intro h,\n  congr ; try { assumption },\nend\ndefinition map_V {R : Type v} [comm_ring R] {R' : Type v}[comm_ring R'] (f : R \u2192 R') [is_ring_hom f] : (V P R) \u2192 (V P R') := \u03bb \u03b6,begin \nexact  {x := f \u03b6.x, certif := \nbegin\n    have H : eval\u2082 (f \u2218 int.cast) (f \u03b6.x) P = f (eval\u2082 int.cast (\u03b6.x) P), \n        rw \u2190  hom_eval\u2082  P  int.cast f \u03b6.x,\n    have G : f \u2218 int.cast = int.cast,\n        exact (int.eq_cast') (f \u2218 int.cast),\n    rw G at H,\n    rw H,\n    have cer : eval\u2082 int.cast \u03b6.x P =0,\n        exact \u03b6.certif, \n    rw cer,\n    exact map_zero f,\n    end}\nend\nlemma map_V_comp {R : Type v} [comm_ring R] {R' : Type v}[comm_ring R'] (f : R \u2192 R') [is_ring_hom f](\u03b6 : V P R) : (map_V P f \u03b6).x = f \u03b6.x := rfl\ndef V_i : CommRing \u2964 Type v :=  \n{ obj := \u03bb R, V P R,\n  map := \u03bb R R' f, map_V P  f, \n  map_id' := \u03bb R, begin \n    apply funext,\n    intro \u03b6,\n    ext,\n    rw types_id,\n    rw map_V_comp,\n    exact rfl,\n   end, \n  map_comp' := \u03bb R R' R'' f g,\n  begin \n    apply funext, \n    intro \u03b6, \n    ext, \n    rw map_V_comp,\n    rw types_comp,\n    rw map_V_comp,\n    rw map_V_comp,\n    exact rfl,\n end\n}\ndef  F :=  (V_i P).obj \n#print F ", "meta": {"author": "Or7ando", "repo": "lean", "sha": "d41169cf4e416a0d42092fb6bdc14131cee9dd15", "save_path": "github-repos/lean/Or7ando-lean", "path": "github-repos/lean/Or7ando-lean/lean-d41169cf4e416a0d42092fb6bdc14131cee9dd15/.github/workflows/project_1_a_decrire/projet_A2/sous_foncteur.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7325538826286659}}
{"text": "-- Try giving a definition of primes.\n-- Includes establishing decidability.\n-- Prove infinitude of primes using factorial.\n\nimport data.nat.basic\nimport algebra  -- Makes simp more powerful.\n\ndef myprime (n : \u2115) := 1 < n \u2227 \u2200 (k : \u2115), 1 < k \u2192 k < n \u2192 \u00ac(k \u2223 n)\n\n@[simp]\nlemma not_prime_zero : \u00ac myprime 0 :=\nbegin\n  rw myprime, simp,\nend\n\n@[simp]\nlemma not_prime_one : \u00ac myprime 1 :=\nbegin\n  rw myprime, simp,\nend\n\nlemma prime_to_one_lt {n : \u2115} : myprime n \u2192 1 < n :=\nbegin\n  rw myprime,\n  cases n, simp,\n  cases n, simp,\n  simp,\nend\n\n-- Couldn't find this in mathlib and it makes things simpler.\nlemma nat_succ_le_iff (m n : \u2115) : m < n \u2194 m.succ \u2264 n :=\nbegin\n  apply iff.intro,\n    intro h,\n    apply has_lt.lt.nat_succ_le,\n    assumption,\n  intro h,\n  apply has_lt.lt.nat_succ_le,\n  assumption,  -- Weird? Equal by definition?\nend\n\n@[simp]\nlemma prime_two : myprime 2 :=\nbegin\n  rw myprime,\n  simp,\n  intro k,\n  rw nat_succ_le_iff,\n  intro h1,\n  -- rw nat.lt_iff_add_one_le at h1,  -- Easier way to do this?\n  intro h2,\n  exfalso,\n  apply has_le.le.not_lt h1,\n  exact h2,\nend\n\nlemma prime_three : myprime 3 :=\nbegin\n  rw myprime, simp,\n  intro k,\n  rw nat_succ_le_iff,\n  rw nat.lt_succ_iff,\n  intro hk,\n  rw has_le.le.ge_iff_eq hk,\n  intro h,\n  rw \u2190 h,\n  simp,\nend\n\n-- If a non-trivial divisor exists, n is not prime.\n-- This is just De Morgan's law (direction that doesn't require excluded middle).\nlemma exists_dvd_to_not_prime {n : \u2115}\n: (\u2203 (k : \u2115), 1 < k \u2227 k < n \u2227 k \u2223 n) \u2192 \u00acmyprime n :=\nbegin\n  intro h,\n  rw myprime,\n  intro h_prime,\n  cases h with w h,\n  clarify,\nend\n\n\n-- Now try to prove decidability!\n-- (find_max_factor_below n k) returns largest divisor m such that m < k.\n-- (find_max_factor_below n n) gives the largest factor of n.\ndef find_max_factor_below : \u2115 \u2192 \u2115 \u2192 \u2115\n| _ 0 := 0\n| n (k+1) := (if k \u2223 n then k else (find_max_factor_below n k))\n\n-- (find_max_factor n) = 1 is equivalent to being prime.\ndef find_max_factor (n : \u2115) := find_max_factor_below n n\n\n-- Use ite_eq_iff to prove things with ite (if-then-else).\n-- Use generalize to transform propositions about ite statements.\n\nlemma max_factor_below_eq_zero_iff {n k : \u2115} :\n  find_max_factor_below n k = 0 \u2194 k < 2 :=\nbegin\n  apply iff.intro,\n    cases k, simp,\n    cases k, simp,\n    rw nat.succ_lt_succ_iff, simp,\n    induction k with j hj,\n      rw find_max_factor_below, simp,\n    rw find_max_factor_below,\n    rw ite_eq_iff,\n    simp,\n    intro h',\n    assumption,\n  cases k,\n    simp, rw find_max_factor_below,\n  cases k,\n    simp, rw find_max_factor_below, rw find_max_factor_below, simp,\n  rw nat.succ_lt_succ_iff, simp,\nend\n\nlemma max_factor_below_dvd {n k : \u2115} :\n  1 < k \u2192 find_max_factor_below n k \u2223 n :=\nbegin\n  generalize hm : find_max_factor_below n k = m,\n  cases k, simp,  -- k = 0\n  cases k, simp,  -- k = 1\n  simp,\n  induction k with j hj,\n    rw \u2190 hm, rw find_max_factor_below, simp,\n  rw find_max_factor_below at hm,\n  rw ite_eq_iff at hm,\n  cases hm,\n    rw \u2190 hm.right,\n    exact hm.left,\n  apply hj,\n  exact hm.right,\nend\n\nlemma max_factor_below_lt {n k : \u2115} :\n  0 < k \u2192 find_max_factor_below n k < k :=\nbegin\n  generalize hm : find_max_factor_below n k = m,\n  cases k, simp,\n  simp,\n  revert hm,\n  induction k,\n    rw find_max_factor_below,\n    rw ite_eq_iff,\n    rw find_max_factor_below, simp,\n    rw \u2190 or_and_distrib_right, simp,\n    rw @eq_comm _ m,\n    simp,\n  rw find_max_factor_below,\n  rw ite_eq_iff,\n  intro hm,\n  cases hm,\n    rw \u2190 hm.right,\n    apply nat.lt_succ_self,\n  apply lt_trans _ (nat.lt_succ_self _),\n  apply k_ih,\n  exact hm.right,\nend\n\nlemma one_lt_iff {n : \u2115} : 1 < n \u2194 \u00ac(n = 0 \u2228 n = 1) :=\nbegin\n  apply iff.intro,\n    cases n, simp,\n    cases n, simp,\n    simp,\n  cases n, simp,\n  cases n, simp,\n  simp,\nend\n\nlemma one_lt_max_factor_below_to_exists {n k : \u2115} :\n  1 < find_max_factor_below n k \u2192 \u2203 (d : \u2115), 1 < d \u2227 d < k \u2227 d \u2223 n :=\nbegin\n  cases k,\n    rw find_max_factor_below, simp,\n  cases k,\n    rw find_max_factor_below, simp,\n    rw find_max_factor_below, simp,\n  intro h,\n  apply exists.intro (find_max_factor_below n k.succ.succ),\n  apply and.intro, assumption,\n  apply and.intro,\n    apply max_factor_below_lt, simp,\n  apply max_factor_below_dvd, simp,\nend\n\nlemma one_lt_max_factor_to_not_prime {n : \u2115} :\n  1 < find_max_factor n \u2192 \u00acmyprime n :=\nbegin\n  rw find_max_factor,\n  assume h,\n  apply exists_dvd_to_not_prime,\n  apply one_lt_max_factor_below_to_exists,\n  assumption,\nend\n\nlemma max_factor_below_eq_one_to_not_dvd {n k : \u2115} :\n  find_max_factor_below n k = 1 \u2192 \u2200 (m : \u2115), 1 < m \u2192 m < k \u2192 \u00ac(m \u2223 n) :=\nbegin\n  cases k,  -- k = 0\n    rw find_max_factor_below, simp,\n  cases k,  -- k = 1\n    rw find_max_factor_below, simp,\n    rw find_max_factor_below, simp,\n  induction k with j hj,\n    rw find_max_factor_below, simp,\n    intro m, intro hm, intro hm',\n    exfalso,\n    -- 1 < m \u2194 1.succ \u2264 m\n    rw \u2190 nat.succ_le_iff at hm,\n    -- 1 \u2264 m \u2194 \u00ac(m < 1)\n    rw nat.lt_iff_le_not_le at hm',\n    apply hm'.right,\n    assumption,\n  rw find_max_factor_below,\n  rw ite_eq_iff,\n  simp,\n  intro h, intro h',\n  intro m, intro hm,\n  rw nat.lt_succ_iff_lt_or_eq,\n  intro hm',\n  cases hm',\n    apply hj h' m hm hm',\n  rw hm', assumption,\nend\n\ntheorem max_factor_eq_one_to_prime {n : \u2115} : find_max_factor n = 1 \u2192 myprime n :=\nbegin\n  rw find_max_factor,\n  cases n,  -- n = 0\n    rw find_max_factor_below, simp,\n  cases n,  -- n = 1\n    rw find_max_factor_below,\n    rw find_max_factor_below,\n    simp,\n  intro h,\n  rw myprime,\n  apply and.intro, simp,\n  apply max_factor_below_eq_one_to_not_dvd,\n  assumption,\nend\n\nlemma prime_to_max_factor_below_eq_one {n : \u2115} :\n  myprime n \u2192 \u2200 k : \u2115, 1 < k \u2192 k \u2264 n \u2192 find_max_factor_below n k = 1 :=\nbegin\n  rw myprime,\n  intro h,\n  intro k,\n  cases k, simp,\n  cases k, simp,\n  intro hk1,\n  intro hkn,\n  induction k,\n    rw find_max_factor_below, simp,\n  rw find_max_factor_below,\n  rw ite_eq_iff,\n  simp,\n  apply and.intro,\n    apply h.right,\n      dec_trivial,\n    apply has_le.le.trans_lt' hkn,\n    apply nat.lt_succ_self,\n  apply k_ih,\n    dec_trivial,\n  apply has_lt.lt.trans (nat.lt_succ_self _),\n  assumption,\nend\n\ntheorem prime_to_max_factor_eq_one {n : \u2115} : myprime n \u2192 find_max_factor n = 1 :=\nbegin\n  rw find_max_factor,\n  intro h,\n  apply prime_to_max_factor_below_eq_one,\n      assumption,\n    exact h.left,\n  simp,\nend\n\ntheorem prime_iff_max_factor_eq_one {n : \u2115} : myprime n \u2194 find_max_factor n = 1 :=\nbegin\n  apply iff.intro,\n    apply prime_to_max_factor_eq_one,\n  apply max_factor_eq_one_to_prime,\nend\n\ninstance myprime_decidable {n : \u2115} : decidable (myprime n) :=\n  decidable_of_iff' _ prime_iff_max_factor_eq_one\n\n\n-- Now show that any number is prime or has a prime factor.\n-- Uses decidability of myprime.\n\nlemma zero_lt_max_factor_iff {n : \u2115} : 1 < n \u2194 0 < find_max_factor n :=\nbegin\n  rw zero_lt_iff, rw find_max_factor, simp,\n  rw max_factor_below_eq_zero_iff, simp,\n  trivial,\nend\n\ntheorem not_prime_iff_one_lt_max_factor {n : \u2115} :\n  1 < n \u2192 (\u00acmyprime n \u2194 1 < find_max_factor n) :=\nbegin\n  cases n, simp,\n  cases n, simp,\n  intro hn,\n  apply iff.intro,\n    rw prime_iff_max_factor_eq_one,\n    intro h,\n    rw one_lt_iff,\n    intro h_or,\n    cases h_or,\n      rw zero_lt_max_factor_iff at hn,\n      rw h_or at hn,\n      simp at hn, trivial,\n    trivial,\n  intro h,\n  rw myprime,\n  apply exists_dvd_to_not_prime,\n  -- generalize hx : find_max_factor n.succ.succ = x,\n  apply exists.intro (find_max_factor n.succ.succ),\n  apply and.intro, assumption,\n  apply and.intro,\n    rw find_max_factor,\n    apply @max_factor_below_lt _ n.succ.succ _, simp,\n  rw find_max_factor,\n  apply @max_factor_below_dvd _ n.succ.succ _, simp,\nend\n\n-- Need to use generalize, clear and revert.\ntheorem prime_or_has_prime_factor (n : \u2115) :\n  1 < n \u2192 (myprime n \u2228 \u2203 (p : \u2115), myprime p \u2227 p \u2223 n) :=\nbegin\n  -- Introduce m = n.\n  generalize hm_eq : n = m,\n  rw eq_comm at hm_eq,\n  intro hm,\n  cases n, revert hm, rw hm_eq, simp,\n  cases n, revert hm, rw hm_eq, simp,\n  -- Replace m = n with m \u2264 n.\n  have hm_le := le_of_eq hm_eq,\n  clear hm_eq,\n  -- Include all m \u2264 n in induction.\n  revert m,\n  induction n with k hk,\n    intro m, intro hm, intro hn,\n    cases nat.eq_or_lt_of_le hn,\n      rw h, simp,\n    exfalso,\n    apply not_lt_of_ge _ h, simp,\n    apply has_lt.lt.nat_succ_le, assumption,\n  intro m, intro hm, intro hn,\n  cases decidable.em (myprime m),\n    apply or.inl, assumption,\n  -- m is not prime; look at its (non-trivial) factor\n  apply or.inr,\n  rw not_prime_iff_one_lt_max_factor hm at h,\n  have hkx := hk (find_max_factor m) h _,\n    cases hkx,\n      -- (find max_factor m) is prime\n      apply exists.intro (find_max_factor m),\n      apply and.intro, assumption,\n      rw find_max_factor,\n      apply max_factor_below_dvd hm,\n    -- (find max_factor m) is not prime; has a prime factor\n    cases hkx with w hw,\n    apply exists.intro w,\n    apply and.intro hw.left,\n    apply dvd_trans hw.right,\n    rw find_max_factor,\n    apply max_factor_below_dvd hm,\n  rw \u2190 nat.succ_le_succ_iff,\n  apply le_trans _ hn,\n  rw nat.succ_le_iff,\n  rw find_max_factor,\n  apply @max_factor_below_lt m,\n  apply lt_trans _ hm, simp,\nend\n\n\ndef factorial : \u2115 \u2192 \u2115\n| 0 := 1\n| (n+1) := (n+1) * (factorial n)\n\nexample (n : \u2115) : 0 < n \u2192 n \u2223 factorial n :=\nbegin\n  cases n, simp,\n  simp,\n  rw factorial,\n  simp,\nend\n\n-- Want to prove \u2200 (n k : \u2115) : k > 0 \u2192 k \u2264 n \u2192 k \u2223 factorial n\n-- What's the induction that we will use?\n-- factorial n = n * (factorial (n-1))\n--             = n * (n-1) * (factorial (n-2))\n-- k \u2223 factorial k\n-- k \u2223 (factorial k) * (k + 1) = factorial (k+1)\nlemma dvd_factorial {n k : \u2115} : 0 < k \u2192 k \u2264 n \u2192 k \u2223 factorial n :=\nbegin\n  cases k, simp,\n  simp,\n  intro hn,\n  have hn := nat.le.dest hn,\n  cases hn with d hd,\n  rw \u2190 hd,\n  clear hn hd n,\n  induction d with j hj,\n    simp, rw factorial, simp,\n  rw nat.add_succ,\n  rw factorial,\n  apply has_dvd.dvd.mul_left,\n  assumption,\nend\n\n-- Use dvd_factorial to prove not divisor of factorial + 1.\nlemma not_dvd_succ_factorial {n k : \u2115} :\n  1 < k \u2192 k \u2264 n \u2192 \u00ac(k \u2223 (factorial n) + 1) :=\nbegin\n  intro hk1,\n  intro hkn,\n  have hk0 : 0 < k := lt_trans nat.zero_lt_one hk1,  -- Used multiple times.\n  have h := dvd_factorial hk0 hkn,\n  cases h with a ha,\n  rw \u2190 (nat.not_dvd_iff_between_consec_multiples (factorial n + 1) hk0),\n  rw ha,\n  apply exists.intro a,\n  apply and.intro,\n    simp,\n  simp [mul_add],\n  exact hk1,\nend\n\nlemma zero_lt_factorial {n : \u2115} : 0 < factorial n :=\nbegin\n  induction n with k hk,\n    rw factorial, simp,\n  rw factorial, simp, assumption,\nend\n\nlemma self_le_factorial {n : \u2115} : n \u2264 factorial n :=\nbegin\n  induction n with k hk,\n    rw factorial, simp,\n  rw factorial, simp,\n  apply has_lt.lt.nat_succ_le,\n  apply zero_lt_factorial,\nend\n\n\ntheorem infinite_primes (n : \u2115) : \u2203 (p : \u2115), n < p \u2227 myprime p :=\nbegin\n  -- Consider factors of factorial + 1.\n  have h_or := prime_or_has_prime_factor (factorial n).succ _,\n    cases h_or,\n      apply exists.intro (factorial n).succ,\n      apply and.intro,\n        rw nat.lt_succ_iff,\n        exact self_le_factorial,\n      assumption,\n    cases h_or with m hm,\n    apply exists.intro m,\n    apply and.intro,\n      cases decidable.em (m \u2264 n) with h_le h_not_le,\n        exfalso,\n        apply not_dvd_succ_factorial _ h_le hm.right,\n        apply prime_to_one_lt,\n        exact hm.left,\n      simp at h_not_le,\n      assumption,\n    exact hm.left,\n  rw nat.succ_lt_succ_iff,\n  apply zero_lt_factorial,\nend\n", "meta": {"author": "jvlmdr", "repo": "from_the_book", "sha": "d4f557b920d52b69791fc939092a0dd407e895bc", "save_path": "github-repos/lean/jvlmdr-from_the_book", "path": "github-repos/lean/jvlmdr-from_the_book/from_the_book-d4f557b920d52b69791fc939092a0dd407e895bc/src/ch01_define_prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7325538798662173}}
{"text": "import tactic\nimport data.set data.set.finite data.finset\n\nstructure simplicial_complex := mk ::\n(vertices : Type*)\n(deceq : decidable_eq vertices)\n(simplices : set (finset vertices))\n(nonempty : \u2200 {\u03c3 : (finset vertices)}, \u03c3 \u2208 simplices \u2192 finset.nonempty \u03c3)\n(singleton : \u2200 v : vertices, {v} \u2208 simplices)\n(downwards : \u2200 {\u03c3 \u03c4 : (finset vertices)}, \u03c3 \u2208 simplices \u2192 \u03c4 \u2286 \u03c3 \u2192 \u03c4.nonempty \u2192 \u03c4 \u2208 simplices)\n\nnamespace simplicial_complex\n\nvariable {K : simplicial_complex}\n\ninstance : decidable_eq K.vertices := K.deceq\n\nlemma nonempty' : \u00ac ((\u2205 : finset K.vertices) \u2208 K.simplices) := \u03bb h, \n  finset.not_nonempty_empty (K.nonempty h)\n\ndef singleton_simplex (v : K.vertices) : K.simplices := \n  \u27e8{v}, K.singleton v\u27e9 \n\ndef empty : simplicial_complex := {\n  vertices := empty,\n  deceq := by apply_instance,\n  simplices := \u2205,\n  nonempty := \u03bb \u03c3 h, (set.not_mem_empty \u03c3 h).elim,\n  singleton := \u03bb v, empty.elim v,\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, (set.not_mem_empty \u03c3 h\u03c3).elim\n}\n\ndef discrete (V : Type*) [decidable_eq V] : simplicial_complex := {\n  vertices := V,\n  deceq := by apply_instance,\n  simplices := (set.univ : set V).image (\u03bb (v : V), {v}),\n  nonempty := \u03bb \u03c3 h, begin\n    rw[set.mem_image] at h, rcases h with \u27e8v, v_in_univ, rfl\u27e9,\n    use v, exact finset.mem_singleton_self v\n  end,\n  singleton := \u03bb v, \u27e8v,set.mem_univ v,rfl\u27e9,\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, begin\n    rw[set.mem_image] at h\u03c3 \u22a2,\n    rcases h\u03c3 with \u27e8v, v_in_univ, rfl\u27e9,\n    rcases finset.subset_singleton_iff.mp h\u03c4\u03c3 with (rfl|rfl),\n    { exfalso, exact finset.not_nonempty_empty h\u03c4 },\n    { exact \u27e8v, set.mem_univ v, rfl\u27e9 }\n  end\n}\n\ndef indiscrete (V : Type*) [decidable_eq V] : simplicial_complex := {\n  vertices := V,\n  deceq := by apply_instance,\n  simplices := { \u03c3 : finset V | \u03c3.nonempty },\n  nonempty := \u03bb \u03c3 h, h,\n  singleton := \u03bb v, finset.singleton_nonempty v,\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, h\u03c4 \n}\n\ndef standard (n : \u2115) : simplicial_complex := indiscrete (fin n.succ)\n\ndef dim (\u03c3 : K.simplices) : \u2115 := (\u03c3 : finset K.vertices).card.pred\n\nlemma simplex_card (\u03c3 : K.simplices) : \n   (\u03c3 : finset K.vertices).card = simplicial_complex.dim \u03c3 + 1 := \nbegin\n  rcases \u03c3 with \u27e8\u03c3, h\u03c3\u27e9,\n  symmetry,\n  apply nat.succ_pred_eq_of_pos, apply nat.pos_of_ne_zero,\n  change \u03c3.card \u2260 0,\n  intro h,\n  rw[finset.card_eq_zero.mp h] at h\u03c3,\n  exact simplicial_complex.nonempty' h\u03c3\nend\n\ndef subdim (K : simplicial_complex) (n : \u2115) := \n  \u2200 (\u03c3 : K.simplices), simplicial_complex.dim \u03c3 \u2264 n\n\ndef supdim (K : simplicial_complex) (n : \u2115) := \n  \u2203 (\u03c3 : K.simplices), simplicial_complex.dim \u03c3 \u2265 n\n\ndef dimeq (K : simplicial_complex) (n : \u2115) := \n  subdim K n \u2227 supdim K n\n\nlemma dim_standard (n : \u2115) : dimeq (standard n) n := \nbegin\n  split,\n  { rintro \u27e8\u03c3 : finset (fin n.succ),h\u03c3\u27e9, change \u03c3.card.pred \u2264 n,\n    have := finset.card_le_univ \u03c3,\n    rw[fintype.card_fin, \u2190 nat.pred_le_iff] at this,\n    exact this\n  }, {\n    let \u03c3 : { s : finset (fin n.succ) | s.nonempty } := \n      \u27e8finset.univ, \u27e80, finset.mem_univ 0\u27e9\u27e9,\n    use \u03c3,\n    change finset.univ.card.pred \u2265 n,\n    rw[finset.card_univ], \n    change (fintype.card (fin n.succ)).pred \u2265 n,\n    rw[fintype.card_fin, nat.pred_succ],\n    exact le_refl n\n  }\nend\n\nstructure hom (K L : simplicial_complex) := mk ::\n(to_fun : K.vertices \u2192 L.vertices)\n(map_simplex : \u2200 {\u03c3 : finset K.vertices} (h : \u03c3 \u2208 K.simplices), \u03c3.image to_fun \u2208 L.simplices)\n\nnamespace hom \n\ndef to_fun' {K L : simplicial_complex} (f : hom K L) : K.simplices \u2192 L.simplices := \n  \u03bb \u03c3, \u27e8(\u03c3 : finset K.vertices).image f.to_fun, f.map_simplex \u03c3.property\u27e9\n\ndef id (K : simplicial_complex) : hom K K := {\n  to_fun := id,\n  map_simplex := \u03bb \u03c3 h, by { rw[finset.image_id], exact h }\n}\n\nlemma id' (K : simplicial_complex) : (id K).to_fun' = (_root_.id : K.simplices \u2192 K.simplices) :=\nbegin\n  funext \u03c3, rcases \u03c3 with \u27e8\u03c3,h\u27e9, ext1,\n  change \u03c3.image _root_.id = \u03c3, rw[finset.image_id]\nend\n\ndef comp {K L M : simplicial_complex} (g : hom L M) (f : hom K L) : hom K M := {\n  to_fun := g.to_fun \u2218 f.to_fun,\n  map_simplex := \u03bb \u03c3 h,\n  begin \n    rw[\u2190 finset.image_image],\n    exact g.map_simplex (f.map_simplex h)\n  end\n}\n\ndef comp' {K L M : simplicial_complex} (g : hom L M) (f : hom K L) : \n  (comp g f).to_fun' = g.to_fun' \u2218 f.to_fun' := \nbegin\n  funext \u03c3, rcases \u03c3 with \u27e8\u03c3,h\u27e9, ext1,\n  rw[function.comp],\n  change \u03c3.image (g.to_fun \u2218 f.to_fun) = (\u03c3.image f.to_fun).image g.to_fun,\n  rw[finset.image_image]\nend\n\ndef const (K : simplicial_complex) {L : simplicial_complex} (w : L.vertices) : hom K L := {\n  to_fun := function.const K.vertices w,\n  map_simplex := \u03bb \u03c3 h, by {\n    rw[finset.image_const (K.nonempty h) w], exact L.singleton w\n  }\n}\n\nlemma const' (K : simplicial_complex) {L : simplicial_complex} (w : L.vertices) :\n  (const K w).to_fun' = function.const K.simplices (simplicial_complex.singleton_simplex w) := \nbegin\n  funext \u03c3, rcases \u03c3 with \u27e8\u03c3, h\u27e9, ext1,\n  change \u03c3.image (function.const _ w) = {w},\n  rw[finset.image_const (K.nonempty h) w]\nend\n\nend hom\n\nend simplicial_complex", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/exercises/loh/simplicial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7325397367731576}}
{"text": "/-\nCopyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Adam Topaz, Bryan Gin-ge Chen\n-/\n\nimport order.boolean_algebra\n\n/-!\n# Symmetric difference\n\nThe symmetric difference or disjunctive union of sets `A` and `B` is the set of elements that are\nin either `A` or `B` but not both. Translated into propositions, the symmetric difference is `xor`.\n\nThe symmetric difference operator (`symm_diff`) is defined in this file for any type with `\u2294` and\n`\\` via the formula `(A \\ B) \u2294 (B \\ A)`, however the theorems proved about it only hold for\n`generalized_boolean_algebra`s and `boolean_algebra`s.\n\nThe symmetric difference is the addition operator in the Boolean ring structure on Boolean algebras.\n\n## Main declarations\n\n* `symm_diff`: the symmetric difference operator, defined as `(A \\ B) \u2294 (B \\ A)`\n\nIn generalized Boolean algebras, the symmetric difference operator is:\n\n* `symm_diff_comm`: commutative, and\n* `symm_diff_assoc`: associative.\n\n## Notations\n\n* `a \u2206 b`: `symm_diff a b`\n\n## References\n\nThe proof of associativity follows the note \"Associativity of the Symmetric Difference of Sets: A\nProof from the Book\" by John McCuan:\n\n* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>\n\n## Tags\nboolean ring, generalized boolean algebra, boolean algebra, symmetric differences\n-/\n\nopen function\n\n/-- The symmetric difference operator on a type with `\u2294` and `\\` is `(A \\ B) \u2294 (B \\ A)`. -/\ndef symm_diff {\u03b1 : Type*} [has_sup \u03b1] [has_sdiff \u03b1] (A B : \u03b1) : \u03b1 := (A \\ B) \u2294 (B \\ A)\n\n/- This notation might conflict with the Laplacian once we have it. Feel free to put it in locale\n`order` or `symm_diff` if that happens. -/\ninfix ` \u2206 `:100 := symm_diff\n\nlemma symm_diff_def {\u03b1 : Type*} [has_sup \u03b1] [has_sdiff \u03b1] (A B : \u03b1) :\n  A \u2206 B = (A \\ B) \u2294 (B \\ A) :=\nrfl\n\nlemma symm_diff_eq_xor (p q : Prop) : p \u2206 q = xor p q := rfl\n\n@[simp] lemma bool.symm_diff_eq_bxor : \u2200 p q : bool, p \u2206 q = bxor p q := dec_trivial\n\nsection generalized_boolean_algebra\nvariables {\u03b1 : Type*} [generalized_boolean_algebra \u03b1] (a b c d : \u03b1)\n\nlemma symm_diff_comm : a \u2206 b = b \u2206 a := by simp only [(\u2206), sup_comm]\n\ninstance symm_diff_is_comm : is_commutative \u03b1 (\u2206) := \u27e8symm_diff_comm\u27e9\n\n@[simp] lemma symm_diff_self : a \u2206 a = \u22a5 := by rw [(\u2206), sup_idem, sdiff_self]\n@[simp] lemma symm_diff_bot : a \u2206 \u22a5 = a := by rw [(\u2206), sdiff_bot, bot_sdiff, sup_bot_eq]\n@[simp] lemma bot_symm_diff : \u22a5 \u2206 a = a := by rw [symm_diff_comm, symm_diff_bot]\n\nlemma symm_diff_eq_sup_sdiff_inf : a \u2206 b = (a \u2294 b) \\ (a \u2293 b) :=\nby simp [sup_sdiff, sdiff_inf, sup_comm, (\u2206)]\n\n@[simp] lemma sup_sdiff_symm_diff : (a \u2294 b) \\ (a \u2206 b) = a \u2293 b :=\nsdiff_eq_symm inf_le_sup (by rw symm_diff_eq_sup_sdiff_inf)\n\nlemma disjoint_symm_diff_inf : disjoint (a \u2206 b) (a \u2293 b) :=\nbegin\n  rw [symm_diff_eq_sup_sdiff_inf],\n  exact disjoint_sdiff_self_left,\nend\n\nlemma symm_diff_le_sup : a \u2206 b \u2264 a \u2294 b := by { rw symm_diff_eq_sup_sdiff_inf, exact sdiff_le }\n\nlemma inf_symm_diff_distrib_left : a \u2293 (b \u2206 c) = (a \u2293 b) \u2206 (a \u2293 c) :=\nby rw [symm_diff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left,\n  symm_diff_eq_sup_sdiff_inf]\n\nlemma inf_symm_diff_distrib_right : (a \u2206 b) \u2293 c = (a \u2293 c) \u2206 (b \u2293 c) :=\nby simp_rw [@inf_comm _ _ _ c, inf_symm_diff_distrib_left]\n\nlemma sdiff_symm_diff : c \\ (a \u2206 b) = (c \u2293 a \u2293 b) \u2294 ((c \\ a) \u2293 (c \\ b)) :=\nby simp only [(\u2206), sdiff_sdiff_sup_sdiff']\n\nlemma sdiff_symm_diff' : c \\ (a \u2206 b) = (c \u2293 a \u2293 b) \u2294 (c \\ (a \u2294 b)) :=\nby rw [sdiff_symm_diff, sdiff_sup, sup_comm]\n\nlemma symm_diff_sdiff : (a \u2206 b) \\ c = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) :=\nby rw [symm_diff_def, sup_sdiff, sdiff_sdiff_left, sdiff_sdiff_left]\n\n@[simp] lemma symm_diff_sdiff_left : (a \u2206 b) \\ a = b \\ a :=\nby rw [symm_diff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]\n\n@[simp] lemma symm_diff_sdiff_right : (a \u2206 b) \\ b = a \\ b :=\nby rw [symm_diff_comm, symm_diff_sdiff_left]\n\n@[simp] lemma sdiff_symm_diff_self : a \\ (a \u2206 b) = a \u2293 b := by simp [sdiff_symm_diff]\n\nlemma symm_diff_eq_iff_sdiff_eq {a b c : \u03b1} (ha : a \u2264 c) :\n  a \u2206 b = c \u2194 c \\ a = b :=\nbegin\n  split; intro h,\n  { have hba : disjoint (a \u2293 b) c := begin\n      rw [\u2190h, disjoint.comm],\n      exact disjoint_symm_diff_inf _ _,\n    end,\n    have hca : _ := congr_arg (\\ a) h,\n    rw [symm_diff_sdiff_left] at hca,\n    rw [\u2190hca, sdiff_eq_self_iff_disjoint],\n    exact hba.of_disjoint_inf_of_le ha },\n  { have hd : disjoint a b := by { rw \u2190h, exact disjoint_sdiff_self_right },\n    rw [symm_diff_def, hd.sdiff_eq_left, hd.sdiff_eq_right, \u2190h, sup_sdiff_cancel_right ha] }\nend\n\nlemma disjoint.symm_diff_eq_sup {a b : \u03b1} (h : disjoint a b) : a \u2206 b = a \u2294 b :=\nby rw [(\u2206), h.sdiff_eq_left, h.sdiff_eq_right]\n\nlemma symm_diff_eq_sup : a \u2206 b = a \u2294 b \u2194 disjoint a b :=\nbegin\n  split; intro h,\n  { rw [symm_diff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h,\n    exact h.of_disjoint_inf_of_le le_sup_left, },\n  { exact h.symm_diff_eq_sup, },\nend\n\n@[simp] lemma le_symm_diff_iff_left : a \u2264 a \u2206 b \u2194 disjoint a b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, h.symm_diff_eq_sup.symm \u25b8 le_sup_left\u27e9,\n  rw symm_diff_eq_sup_sdiff_inf at h,\n  exact (le_sdiff_iff.1 $ inf_le_of_left_le h).le,\nend\n\n@[simp] lemma le_symm_diff_iff_right : b \u2264 a \u2206 b \u2194 disjoint a b :=\nby rw [symm_diff_comm, le_symm_diff_iff_left, disjoint.comm]\n\nlemma symm_diff_symm_diff_left :\n  a \u2206 b \u2206 c = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294 (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c) :=\ncalc a \u2206 b \u2206 c = ((a \u2206 b) \\ c) \u2294 (c \\ (a \u2206 b))   : symm_diff_def _ _\n           ... = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294\n                   ((c \\ (a \u2294 b)) \u2294 (c \u2293 a \u2293 b)) :\n                                by rw [sdiff_symm_diff', @sup_comm _ _ (c \u2293 a \u2293 b), symm_diff_sdiff]\n           ... = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294\n                   (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c)   : by ac_refl\n\nlemma symm_diff_symm_diff_right :\n  a \u2206 (b \u2206 c) = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294 (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c) :=\ncalc a \u2206 (b \u2206 c) = (a \\ (b \u2206 c)) \u2294 ((b \u2206 c) \\ a) : symm_diff_def _ _\n             ... = (a \\ (b \u2294 c)) \u2294 (a \u2293 b \u2293 c) \u2294\n                     (b \\ (c \u2294 a) \u2294 c \\ (b \u2294 a))   :\n                                by rw [sdiff_symm_diff', @sup_comm _ _ (a \u2293 b \u2293 c), symm_diff_sdiff]\n             ... = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294\n                     (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c)   : by ac_refl\n\n@[simp] lemma symm_diff_symm_diff_inf : a \u2206 b \u2206 (a \u2293 b) = a \u2294 b :=\nby rw [symm_diff_eq_iff_sdiff_eq (symm_diff_le_sup _ _), sup_sdiff_symm_diff]\n\n@[simp] lemma inf_symm_diff_symm_diff : (a \u2293 b) \u2206 (a \u2206 b) = a \u2294 b :=\nby rw [symm_diff_comm, symm_diff_symm_diff_inf]\n\nlemma symm_diff_triangle : a \u2206 c \u2264 a \u2206 b \u2294 b \u2206 c :=\nbegin\n  refine (sup_le_sup (sdiff_triangle a b c) $ sdiff_triangle _ b _).trans_eq _,\n  rw [@sup_comm _ _ (c \\ b), sup_sup_sup_comm],\n  refl,\nend\n\nlemma symm_diff_assoc : a \u2206 b \u2206 c = a \u2206 (b \u2206 c) :=\nby rw [symm_diff_symm_diff_left, symm_diff_symm_diff_right]\n\ninstance symm_diff_is_assoc : is_associative \u03b1 (\u2206) := \u27e8symm_diff_assoc\u27e9\n\nlemma symm_diff_left_comm : a \u2206 (b \u2206 c) = b \u2206 (a \u2206 c) :=\nby simp_rw [\u2190symm_diff_assoc, symm_diff_comm]\n\nlemma symm_diff_right_comm : a \u2206 b \u2206 c = a \u2206 c \u2206 b := by simp_rw [symm_diff_assoc, symm_diff_comm]\n\nlemma symm_diff_symm_diff_symm_diff_comm : (a \u2206 b) \u2206 (c \u2206 d) = (a \u2206 c) \u2206 (b \u2206 d) :=\nby simp_rw [symm_diff_assoc, symm_diff_left_comm]\n\n@[simp] lemma symm_diff_symm_diff_cancel_left : a \u2206 (a \u2206 b) = b := by simp [\u2190symm_diff_assoc]\n@[simp] lemma symm_diff_symm_diff_cancel_right : b \u2206 a \u2206 a = b := by simp [symm_diff_assoc]\n\n@[simp] lemma symm_diff_symm_diff_self' : a \u2206 b \u2206 a = b :=\nby rw [symm_diff_comm,symm_diff_symm_diff_cancel_left]\n\nlemma symm_diff_left_involutive (a : \u03b1) : involutive (\u2206 a) := symm_diff_symm_diff_cancel_right _\nlemma symm_diff_right_involutive (a : \u03b1) : involutive ((\u2206) a) := symm_diff_symm_diff_cancel_left _\nlemma symm_diff_left_injective (a : \u03b1) : injective (\u2206 a) := (symm_diff_left_involutive _).injective\nlemma symm_diff_right_injective (a : \u03b1) : injective ((\u2206) a) :=\n(symm_diff_right_involutive _).injective\nlemma symm_diff_left_surjective (a : \u03b1) : surjective (\u2206 a) :=\n(symm_diff_left_involutive _).surjective\nlemma symm_diff_right_surjective (a : \u03b1) : surjective ((\u2206) a) :=\n(symm_diff_right_involutive _).surjective\n\nvariables {a b c}\n\n@[simp] lemma symm_diff_left_inj : a \u2206 b = c \u2206 b \u2194 a = c := (symm_diff_left_injective _).eq_iff\n@[simp] lemma symm_diff_right_inj : a \u2206 b = a \u2206 c \u2194 b = c := (symm_diff_right_injective _).eq_iff\n\n@[simp] lemma symm_diff_eq_left : a \u2206 b = a \u2194 b = \u22a5 :=\ncalc a \u2206 b = a \u2194 a \u2206 b = a \u2206 \u22a5 : by rw symm_diff_bot\n           ... \u2194     b = \u22a5     : by rw symm_diff_right_inj\n\n@[simp] lemma symm_diff_eq_right : a \u2206 b = b \u2194 a = \u22a5 := by rw [symm_diff_comm, symm_diff_eq_left]\n\n@[simp] lemma symm_diff_eq_bot : a \u2206 b = \u22a5 \u2194 a = b :=\ncalc a \u2206 b = \u22a5 \u2194 a \u2206 b = a \u2206 a : by rw symm_diff_self\n           ... \u2194     a = b     : by rw [symm_diff_right_inj, eq_comm]\n\nprotected lemma disjoint.symm_diff_left (ha : disjoint a c) (hb : disjoint b c) :\n  disjoint (a \u2206 b) c :=\nby { rw symm_diff_eq_sup_sdiff_inf, exact (ha.sup_left hb).disjoint_sdiff_left }\n\nprotected lemma disjoint.symm_diff_right (ha : disjoint a b) (hb : disjoint a c) :\n  disjoint a (b \u2206 c) :=\n(ha.symm.symm_diff_left hb.symm).symm\n\nend generalized_boolean_algebra\n\nsection boolean_algebra\nvariables {\u03b1 : Type*} [boolean_algebra \u03b1] (a b c : \u03b1)\n\nlemma symm_diff_eq : a \u2206 b = (a \u2293 b\u1d9c) \u2294 (b \u2293 a\u1d9c) := by simp only [(\u2206), sdiff_eq]\n\n@[simp] lemma symm_diff_top : a \u2206 \u22a4 = a\u1d9c := by simp [symm_diff_eq]\n@[simp] lemma top_symm_diff : \u22a4 \u2206 a = a\u1d9c := by rw [symm_diff_comm, symm_diff_top]\n\nlemma compl_symm_diff : (a \u2206 b)\u1d9c = (a \u2293 b) \u2294 (a\u1d9c \u2293 b\u1d9c) :=\nby simp only [\u2190top_sdiff, sdiff_symm_diff, top_inf_eq]\n\nlemma symm_diff_eq_top_iff : a \u2206 b = \u22a4 \u2194 is_compl a b :=\nby rw [symm_diff_eq_iff_sdiff_eq le_top, top_sdiff, compl_eq_iff_is_compl]\n\nlemma is_compl.symm_diff_eq_top (h : is_compl a b) : a \u2206 b = \u22a4 := (symm_diff_eq_top_iff a b).2 h\n\n@[simp] lemma compl_symm_diff_self : a\u1d9c \u2206 a = \u22a4 :=\nby simp only [symm_diff_eq, compl_compl, inf_idem, compl_sup_eq_top]\n\n@[simp] lemma symm_diff_compl_self : a \u2206 a\u1d9c = \u22a4 := by rw [symm_diff_comm, compl_symm_diff_self]\n\nlemma symm_diff_symm_diff_right' :\n  a \u2206 (b \u2206 c) = (a \u2293 b \u2293 c) \u2294 (a \u2293 b\u1d9c \u2293 c\u1d9c) \u2294 (a\u1d9c \u2293 b \u2293 c\u1d9c) \u2294 (a\u1d9c \u2293 b\u1d9c \u2293 c) :=\ncalc a \u2206 (b \u2206 c) = (a \u2293 ((b \u2293 c) \u2294 (b\u1d9c \u2293 c\u1d9c))) \u2294\n                     (((b \u2293 c\u1d9c) \u2294 (c \u2293 b\u1d9c)) \u2293 a\u1d9c)  : by rw [symm_diff_eq, compl_symm_diff,\n                                                            symm_diff_eq]\n             ... = (a \u2293 b \u2293 c) \u2294 (a \u2293 b\u1d9c \u2293 c\u1d9c) \u2294\n                     (b \u2293 c\u1d9c \u2293 a\u1d9c) \u2294 (c \u2293 b\u1d9c \u2293 a\u1d9c) : by rw [inf_sup_left, inf_sup_right,\n                                                            \u2190sup_assoc, \u2190inf_assoc, \u2190inf_assoc]\n             ... = (a \u2293 b \u2293 c) \u2294 (a \u2293 b\u1d9c \u2293 c\u1d9c) \u2294\n                     (a\u1d9c \u2293 b \u2293 c\u1d9c) \u2294 (a\u1d9c \u2293 b\u1d9c \u2293 c) : begin\n                                                       congr' 1,\n                                                       { congr' 1,\n                                                         rw [inf_comm, inf_assoc], },\n                                                       { apply inf_left_right_swap }\n                                                     end\n\nend boolean_algebra\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/order/symm_diff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7325397193401607}}
{"text": "import tactic\nimport data.set.finite\nimport data.real.basic -- for metrics\nimport .topologia\nimport .bases\n\nopen set\nopen topological_space\n\n/- # Metric spaces -/\nnoncomputable theory\n\nclass metric_space_basic (X : Type) :=\n  (dist : X \u2192 X \u2192 \u211d)\n  (dist_eq_zero_iff : \u2200 x y, dist x y = 0 \u2194 x = y)\n  (dist_symm : \u2200 x y, dist x y = dist y x)\n  (triangle : \u2200 x y z, dist x z \u2264 dist x y + dist y z)\n\nnamespace metric_space_basic\n\n@[simp]\nlemma dist_eq_zero_iff' {X : Type} (x y : X) [metric_space_basic X] :\n  dist x y = 0 \u2194 x = y := dist_eq_zero_iff x y\n\nlemma dist_nonneg {X : Type} [metric_space_basic X] (x y : X) : 0 \u2264 dist x y :=\nbegin\n  have h1 : dist x x = 0,\n    rw (dist_eq_zero_iff x x).2, refl,\n  suffices : 0 \u2264 dist x y + dist x y,\n  { linarith },\n  rw \u2190 h1,\n  nth_rewrite_rhs 1 dist_symm x y,\n  exact triangle _ _ _,\nend\n\n\n@[simp]\nlemma dist_self_zero {X : Type} [metric_space_basic X] {x : X} : dist x x = 0 := by simp\n\ndef ball {X : Type} [metric_space_basic X] (x : X) (r : \u211d) := {y | dist x y < r}\n\n@[simp]\nlemma ball_def {X : Type} [metric_space_basic X] (x : X) (r : \u211d) : ball x r = { y | dist x y < r} := rfl\n\n@[simp]\nlemma mem_center_ball_iff {X : Type} [metric_space_basic X] {x : X} {r : \u211d} :\n  x \u2208 ball x r \u2194 0 < r :=\nbegin\n  split;\n  { exact \u03bb h, by simpa using h },\nend\n\nlemma ball_subset_ball {X : Type} [metric_space_basic X] {x : X} {r s : \u211d} (h : r \u2264 s) :\n  ball x r \u2286 ball x s :=\nbegin\n  simp,\n  intros a ha,\n  linarith,\nend\n\n@[simp]\nlemma ball_nonempty_iff {X : Type} [metric_space_basic X] {x : X} {r : \u211d} :\n  ball x r \u2260 \u2205 \u2194 0 < r :=\nbegin\n  simp,\n  split,\n  {\n    intro h,\n    obtain \u27e8z, hz\u27e9 := h,\n    have H := dist_nonneg x z,\n    linarith,\n  },\n  {\n    intro h,\n    use x,\n    rw dist_self_zero,\n    exact h,\n  }\nend\n\nlemma ball_around_interior_point {X : Type} [metric_space_basic X] {r : \u211d}\n  {x y : X} (h: y \u2208 ball x r) : \u2203 s, 0 < s \u2227 ball y s \u2286 ball x r :=\nbegin\n  have : 0 < r,\n  {\n    have hne : ball x r \u2260 \u2205,\n    {\n      unfold ball,\n      simp,\n      use y,\n      simpa using h,\n    },\n    apply (@ball_nonempty_iff X _ x r).1 hne,\n  },\n  use r - dist x y,\n  split,\n  { simpa using h },\n  {\n    simp,\n    intros a ha,\n    replace ha : dist x y + dist y a < r,\n    { linarith },\n    calc dist x a \u2264 dist x y + dist y a : triangle x y a\n      ... < r : ha,\n  }\nend\n\nlemma balls_form_basis {X : Type} [metric_space_basic X] :\n basis_condition { B | \u2203 (x : X) r, B = {y | dist x y < r} } :=\nbegin\n  fconstructor,\n  {\n    intro x,\n    simp,\n    use {y | dist x y < 1},\n    use x, use 1,\n    simp [dist_eq_zero_iff],\n  },\n  {\n    intros U V hU hV,\n    obtain \u27e8x, r, hU\u27e9 := hU,\n    obtain \u27e8y, s, hV\u27e9 := hV,\n    subst hU, subst hV,\n    intros z hz,\n    -- here is the proof that if z in B x r \u2229 B y s then one can find some ball B \u2286 B x r \u2229 B y s\n    simp at hz,\n    use ball z (min (r - dist x z) (s - dist y z)),\n    simp,\n    split,\n    {\n      use z, use (min (r - dist x z) (s - dist y z)),\n      simp,\n    },\n    {\n      split,\n      { assumption },\n      split,\n      {\n        intros a ha1 ha2,\n        calc dist x a \u2264 dist x z + dist z a : triangle x z a\n            ... < r : lt_sub_iff_add_lt'.mp ha1,\n      },\n      {\n        intros a ha1 ha2,\n        calc dist y a \u2264 dist y z + dist z a : triangle y z a\n          ... < s : lt_sub_iff_add_lt'.mp ha2,\n      },\n    }\n  }\nend\n\nlemma metric_space_is_open_compatible {X : Type} [metric_space_basic X] {U : set X} :\n@is_open X (generate_from_basis balls_form_basis) U \u2194\n(\u2200 x \u2208 U, \u2203 r, 0 < r \u2227 {y | dist x y < r} \u2286 U) :=\nbegin\n  simp [generate_from_basis_open_iff'],\n  split,\n  {\n    intros h x hx,\n    specialize h x hx,\n    obtain \u27e8B, \u27e8\u27e8z, h, hB\u27e9, \u27e8hz1, hz2\u27e9\u27e9\u27e9 := h,\n    subst hB,\n    simp at hz1 hz2,\n    obtain \u27e8s, hs, hsr\u27e9 := ball_around_interior_point hz1,\n    use s,\n    split,\n    { exact hs },\n    rw \u2190ball_def at hz2 \u22a2,\n    exact subset.trans hsr hz2,\n  },\n  {\n    intros h x hx,\n    obtain \u27e8r, hr1, hr2\u27e9 := h x hx,\n    use {y : X | dist x y < r},\n    use x, use r,\n    simp,\n    tauto,\n  }\nend\n\n\nend metric_space_basic\n\nopen metric_space_basic\n\ninstance prod.metric_space_basic (X Y : Type) [metric_space_basic X] [metric_space_basic Y] :\nmetric_space_basic (X \u00d7 Y) :=\n{ dist := \u03bb u v, max (dist u.fst v.fst) (dist u.snd v.snd),\n  dist_eq_zero_iff :=\n  begin\n    intro xy1,\n    intro xy2,\n    split,\n    {\n      intro h,\n      have h1: dist xy1.fst xy2.fst \u2265 0 := dist_nonneg _ _,\n      have h2: dist xy1.snd xy2.snd \u2265 0 := dist_nonneg _ _,\n      have h3: dist xy1.fst xy2.fst = 0, \n      begin\n        have h5 : max (dist xy1.fst xy2.fst) (dist xy1.snd xy2.snd) \u2264 0 :=\n          by linarith,\n        have h4 := max_le_iff.mp h5,\n        linarith,\n      end,\n\n      have h6: dist xy1.snd xy2.snd = 0, \n      begin\n        have h5 : max (dist xy1.fst xy2.fst) (dist xy1.snd xy2.snd) \u2264 0 := by linarith,\n        have h4 := max_le_iff.mp h5,\n        linarith,\n      end,\n      ext;\n      {\n        rw [\u2190dist_eq_zero_iff _ _],\n        tauto,\n      },\n     },\n    {\n      intro h,\n      subst h, \n      rw (dist_eq_zero_iff xy1.fst xy1.fst).mpr (refl _),\n      rw (dist_eq_zero_iff xy1.snd xy1.snd).mpr (refl _),\n      exact max_self 0,\n    },\n  end,\n  dist_symm := \n  begin\n    intros xy1 xy2,\n    simp only [dist_symm],\n  end,\n  triangle :=\n   begin\n    intros x y z,\n    let  xy_X := (dist x.fst y.fst),\n    let  yz_X := (dist y.fst z.fst),\n    let  xy_Y := (dist x.snd y.snd),\n    let  yz_Y :=  (dist y.snd z.snd),\n\n    -- We introduce a refinement.\n    calc  max (dist x.fst z.fst) (dist x.snd z.snd) \u2264 (max (xy_X + yz_X) ( xy_Y + yz_Y)): by { apply max_le_max; exact triangle _ _ _ }\n        ... \u2264 max (dist x.fst y.fst) (dist x.snd y.snd) + max (dist y.fst z.fst) (dist y.snd z.snd):\n     begin\n      refine max_le_iff.mpr _,\n      split;\n      {\n        apply add_le_add;\n        finish,\n      }, \n    end,\n   end,\n}\n\n@[simp]\nlemma prod_balls_def (X Y : Type) [metric_space_basic X] [metric_space_basic Y] {x : X} {y : Y} {r : \u211d} :\n  (ball x r).prod (ball y r) = ball (x,y) r :=\nbegin\n  unfold ball,\n  unfold dist,\n  ext,\n  simp,\nend\n\n@[simp]\nlemma prod_balls_def' (X Y : Type) [metric_space_basic X] [metric_space_basic Y] {x : X} {y : Y} {r : \u211d} :\n  {z | dist x z < r}.prod {z | dist y z < r} = {z | dist (x,y) z < r} :=\nbegin\n  ext,\n  unfold dist,\n  simp,\nend\n\nclass metric_space (X : Type) extends topological_space X, metric_space_basic X :=\n  (compatible : \u2200 (U : set X), is_open U \u2194 (\u2200 x \u2208 U, \u2203 r, 0 < r \u2227 {y | dist x y < r} \u2286 U))\n\n\nnamespace metric_space\n\nopen topological_space\n\n/-\nWe would still like a way of making a `metric_space` just given a metric and some\nproperties it satisfies, i.e. a `metric_space_basic`, so we should setup a metric space\nconstructor from a `metric_space_basic` by setting the topology to be the induced one. -/\n\ndef of_basic {X : Type} (m : metric_space_basic X) : metric_space X :=\n{ compatible := begin \n  intros,\n  rw generate_from_basis_open_iff',\n  simp,\n  split,\n  all_goals {\n    intro h,\n    intros x hx,\n  },\n  {\n    obtain \u27e8B, \u27e8a, r, har\u27e9, \u27e8hB1, hB2\u27e9\u27e9 := h x hx,\n    subst har,\n    use (r - dist a x),\n    simp at hB1 hB2,\n    split,\n    { linarith [hB1] },\n    {\n      apply subset.trans _ hB2,\n      simp,\n      intros z hz,\n      calc dist a z \u2264 dist a x + dist x z : triangle a x z\n      ... < r : lt_sub_iff_add_lt'.mp hz,\n    }\n  },\n  {\n    obtain \u27e8r, hr, hU\u27e9 := h x hx,\n    use {y | dist x y < r},\n    use x, use r,\n    simp,\n    split;\n    simp [hr, hU],\n  }\n end,\n  ..m,\n  ..generate_from_basis balls_form_basis\n}\n\n\n/-- Open balls are open -/\nlemma open_of_ball {X : Type} [metric_space X] {x : X} {r : \u211d} :\n  is_open (ball x r) :=\nbegin\n\n  have H:= @generate_from_basis_open_iff' X _ balls_form_basis {y : X | dist x y < r},\n  rw [ball_def, compatible, \u2190metric_space_is_open_compatible, H],\n  intros y hy,\n  use {y : X | dist x y < r},\n  use x, use r,\n  { tauto },\nend\n\n\nend metric_space\n", "meta": {"author": "mmasdeu", "repo": "barcelonaleanseminar", "sha": "140478080f6680ea5e3ce61e6523272e7e12219f", "save_path": "github-repos/lean/mmasdeu-barcelonaleanseminar", "path": "github-repos/lean/mmasdeu-barcelonaleanseminar/barcelonaleanseminar-140478080f6680ea5e3ce61e6523272e7e12219f/src/metrics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7325397140919163}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Neil Strickland\n-/\nimport data.nat.basic\n\n/-!\n# The positive natural numbers\n\nThis file defines the type `\u2115+` or `pnat`, the subtype of natural numbers that are positive.\n-/\n\n/-- `\u2115+` is the type of positive natural numbers. It is defined as a subtype,\n  and the VM representation of `\u2115+` is the same as `\u2115` because the proof\n  is not stored. -/\ndef pnat := {n : \u2115 // 0 < n}\nnotation `\u2115+` := pnat\n\ninstance coe_pnat_nat : has_coe \u2115+ \u2115 := \u27e8subtype.val\u27e9\ninstance : has_repr \u2115+ := \u27e8\u03bb n, repr n.1\u27e9\n\n/-- Predecessor of a `\u2115+`, as a `\u2115`. -/\ndef pnat.nat_pred (i : \u2115+) : \u2115 := i - 1\n\n@[simp] lemma pnat.one_add_nat_pred (n : \u2115+) : 1 + n.nat_pred = n :=\nby rw [pnat.nat_pred, add_tsub_cancel_iff_le.mpr $ show 1 \u2264 (n : \u2115), from n.2]\n\n@[simp] lemma pnat.nat_pred_add_one (n : \u2115+) : n.nat_pred + 1 = n :=\n(add_comm _ _).trans n.one_add_nat_pred\n\n@[simp] lemma pnat.nat_pred_eq_pred {n : \u2115} (h : 0 < n) :\npnat.nat_pred (\u27e8n, h\u27e9 : \u2115+) = n.pred := rfl\n\nnamespace nat\n\n/-- Convert a natural number to a positive natural number. The\n  positivity assumption is inferred by `dec_trivial`. -/\ndef to_pnat (n : \u2115) (h : 0 < n . tactic.exact_dec_trivial) : \u2115+ := \u27e8n, h\u27e9\n\n/-- Write a successor as an element of `\u2115+`. -/\ndef succ_pnat (n : \u2115) : \u2115+ := \u27e8succ n, succ_pos n\u27e9\n\n@[simp] theorem succ_pnat_coe (n : \u2115) : (succ_pnat n : \u2115) = succ n := rfl\n\ntheorem succ_pnat_inj {n m : \u2115} : succ_pnat n = succ_pnat m \u2192 n = m :=\n\u03bb h, by { let h' := congr_arg (coe : \u2115+ \u2192 \u2115) h, exact nat.succ.inj h' }\n\n/-- Convert a natural number to a pnat. `n+1` is mapped to itself,\n  and `0` becomes `1`. -/\ndef to_pnat' (n : \u2115) : \u2115+ := succ_pnat (pred n)\n\n@[simp] theorem to_pnat'_coe : \u2200 (n : \u2115),\n ((to_pnat' n) : \u2115) = ite (0 < n) n 1\n| 0 := rfl\n| (m + 1) := by {rw [if_pos (succ_pos m)], refl}\n\nend nat\n\nnamespace pnat\n\nopen nat\n\n/-- We now define a long list of structures on \u2115+ induced by\n similar structures on \u2115. Most of these behave in a completely\n obvious way, but there are a few things to be said about\n subtraction, division and powers.\n-/\n\ninstance : decidable_eq \u2115+ := \u03bb (a b : \u2115+), by apply_instance\n\ninstance : linear_order \u2115+ :=\nsubtype.linear_order _\n\n@[simp] lemma mk_le_mk (n k : \u2115) (hn : 0 < n) (hk : 0 < k) :\n  (\u27e8n, hn\u27e9 : \u2115+) \u2264 \u27e8k, hk\u27e9 \u2194 n \u2264 k := iff.rfl\n\n@[simp] lemma mk_lt_mk (n k : \u2115) (hn : 0 < n) (hk : 0 < k) :\n  (\u27e8n, hn\u27e9 : \u2115+) < \u27e8k, hk\u27e9 \u2194 n < k := iff.rfl\n\n@[simp, norm_cast] lemma coe_le_coe (n k : \u2115+) : (n : \u2115) \u2264 k \u2194 n \u2264 k := iff.rfl\n\n@[simp, norm_cast] lemma coe_lt_coe (n k : \u2115+) : (n : \u2115) < k \u2194 n < k := iff.rfl\n\n@[simp] theorem pos (n : \u2115+) : 0 < (n : \u2115) := n.2\n\n-- see note [fact non_instances]\nlemma fact_pos (n : \u2115+) : fact (0 < \u2191n) := \u27e8n.pos\u27e9\n\ntheorem eq {m n : \u2115+} : (m : \u2115) = n \u2192 m = n := subtype.eq\n\n@[simp] lemma coe_inj {m n : \u2115+} : (m : \u2115) = n \u2194 m = n := set_coe.ext_iff\n\nlemma coe_injective : function.injective (coe : \u2115+ \u2192 \u2115) := subtype.coe_injective\n\n@[simp] theorem mk_coe (n h) : ((\u27e8n, h\u27e9 : \u2115+) : \u2115) = n := rfl\n\ninstance : has_add \u2115+ := \u27e8\u03bb a b, \u27e8(a  + b : \u2115), add_pos a.pos b.pos\u27e9\u27e9\n\ninstance : add_comm_semigroup \u2115+ := coe_injective.add_comm_semigroup coe (\u03bb _ _, rfl)\n\n@[simp] theorem add_coe (m n : \u2115+) : ((m + n : \u2115+) : \u2115) = m + n := rfl\n\n/-- `pnat.coe` promoted to an `add_hom`, that is, a morphism which preserves addition. -/\ndef coe_add_hom : add_hom \u2115+ \u2115 :=\n{ to_fun := coe,\n  map_add' := add_coe }\n\ninstance : add_left_cancel_semigroup \u2115+ :=\ncoe_injective.add_left_cancel_semigroup coe (\u03bb _ _, rfl)\n\ninstance : add_right_cancel_semigroup \u2115+ :=\ncoe_injective.add_right_cancel_semigroup coe (\u03bb _ _, rfl)\n\n@[simp] theorem ne_zero (n : \u2115+) : (n : \u2115) \u2260 0 := n.2.ne'\n\ntheorem to_pnat'_coe {n : \u2115} : 0 < n \u2192 (n.to_pnat' : \u2115) = n := succ_pred_eq_of_pos\n\n@[simp] theorem coe_to_pnat' (n : \u2115+) : (n : \u2115).to_pnat' = n := eq (to_pnat'_coe n.pos)\n\ninstance : has_mul \u2115+ := \u27e8\u03bb m n, \u27e8m.1 * n.1, mul_pos m.2 n.2\u27e9\u27e9\ninstance : has_one \u2115+ := \u27e8succ_pnat 0\u27e9\n\ninstance : comm_monoid \u2115+ := coe_injective.comm_monoid coe rfl (\u03bb _ _, rfl)\n\ntheorem lt_add_one_iff : \u2200 {a b : \u2115+}, a < b + 1 \u2194 a \u2264 b :=\n\u03bb a b, nat.lt_add_one_iff\n\ntheorem add_one_le_iff : \u2200 {a b : \u2115+}, a + 1 \u2264 b \u2194 a < b :=\n\u03bb a b, nat.add_one_le_iff\n\n@[simp] lemma one_le (n : \u2115+) : (1 : \u2115+) \u2264 n := n.2\n\ninstance : order_bot \u2115+ :=\n{ bot := 1,\n  bot_le := \u03bb a, a.property }\n\n@[simp] lemma bot_eq_one : (\u22a5 : \u2115+) = 1 := rfl\n\ninstance : inhabited \u2115+ := \u27e81\u27e9\n\n-- Some lemmas that rewrite `pnat.mk n h`, for `n` an explicit numeral, into explicit numerals.\n@[simp] lemma mk_one {h} : (\u27e81, h\u27e9 : \u2115+) = (1 : \u2115+) := rfl\n@[simp] lemma mk_bit0 (n) {h} : (\u27e8bit0 n, h\u27e9 : \u2115+) = (bit0 \u27e8n, pos_of_bit0_pos h\u27e9 : \u2115+) := rfl\n@[simp] lemma mk_bit1 (n) {h} {k} : (\u27e8bit1 n, h\u27e9 : \u2115+) = (bit1 \u27e8n, k\u27e9 : \u2115+) := rfl\n\n-- Some lemmas that rewrite inequalities between explicit numerals in `\u2115+`\n-- into the corresponding inequalities in `\u2115`.\n-- TODO: perhaps this should not be attempted by `simp`,\n-- and instead we should expect `norm_num` to take care of these directly?\n-- TODO: these lemmas are perhaps incomplete:\n-- * 1 is not represented as a bit0 or bit1\n-- * strict inequalities?\n@[simp] lemma bit0_le_bit0 (n m : \u2115+) : (bit0 n) \u2264 (bit0 m) \u2194 (bit0 (n : \u2115)) \u2264 (bit0 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit0_le_bit1 (n m : \u2115+) : (bit0 n) \u2264 (bit1 m) \u2194 (bit0 (n : \u2115)) \u2264 (bit1 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit1_le_bit0 (n m : \u2115+) : (bit1 n) \u2264 (bit0 m) \u2194 (bit1 (n : \u2115)) \u2264 (bit0 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit1_le_bit1 (n m : \u2115+) : (bit1 n) \u2264 (bit1 m) \u2194 (bit1 (n : \u2115)) \u2264 (bit1 (m : \u2115)) :=\niff.rfl\n\n@[simp] theorem one_coe : ((1 : \u2115+) : \u2115) = 1 := rfl\n@[simp] theorem mul_coe (m n : \u2115+) : ((m * n : \u2115+) : \u2115) = m * n := rfl\n\n/-- `pnat.coe` promoted to a `monoid_hom`. -/\ndef coe_monoid_hom : \u2115+ \u2192* \u2115 :=\n{ to_fun := coe,\n  map_one' := one_coe,\n  map_mul' := mul_coe }\n\n@[simp] lemma coe_coe_monoid_hom : (coe_monoid_hom : \u2115+ \u2192 \u2115) = coe := rfl\n\n@[simp]\nlemma coe_eq_one_iff {m : \u2115+} :\n(m : \u2115) = 1 \u2194 m = 1 := by { split; intro h; try { apply pnat.eq}; rw h; simp }\n\n\n@[simp] lemma coe_bit0 (a : \u2115+) : ((bit0 a : \u2115+) : \u2115) = bit0 (a : \u2115) := rfl\n@[simp] lemma coe_bit1 (a : \u2115+) : ((bit1 a : \u2115+) : \u2115) = bit1 (a : \u2115) := rfl\n\n@[simp] theorem pow_coe (m : \u2115+) (n : \u2115) : ((m ^ n : \u2115+) : \u2115) = (m : \u2115) ^ n :=\nby induction n with n ih;\n [refl, rw [pow_succ', pow_succ, mul_coe, mul_comm, ih]]\n\ninstance : ordered_cancel_comm_monoid \u2115+ :=\n{ mul_le_mul_left := by { intros, apply nat.mul_le_mul_left, assumption },\n  le_of_mul_le_mul_left := by { intros a b c h, apply nat.le_of_mul_le_mul_left h a.property, },\n  mul_left_cancel := \u03bb a b c h, by\n { replace h := congr_arg (coe : \u2115+ \u2192 \u2115) h,\n   exact eq ((nat.mul_right_inj a.pos).mp h)},\n  .. pnat.comm_monoid,\n  .. pnat.linear_order }\n\ninstance : distrib \u2115+ := coe_injective.distrib coe (\u03bb _ _, rfl) (\u03bb _ _, rfl)\n\n/-- Subtraction a - b is defined in the obvious way when\n  a > b, and by a - b = 1 if a \u2264 b.\n-/\ninstance : has_sub \u2115+ := \u27e8\u03bb a b, to_pnat' (a - b : \u2115)\u27e9\n\ntheorem sub_coe (a b : \u2115+) : ((a - b : \u2115+) : \u2115) = ite (b < a) (a - b : \u2115) 1 :=\nbegin\n  change ((to_pnat' ((a : \u2115) - (b :  \u2115)) : \u2115)) =\n    ite ((a : \u2115) > (b : \u2115)) ((a : \u2115) - (b : \u2115)) 1,\n  split_ifs with h,\n  { exact to_pnat'_coe (tsub_pos_of_lt h) },\n  { rw [tsub_eq_zero_iff_le.mpr (le_of_not_gt h)], refl }\nend\n\ntheorem add_sub_of_lt {a b : \u2115+} : a < b \u2192 a + (b - a) = b :=\n \u03bb h, eq $ by { rw [add_coe, sub_coe, if_pos h],\n                exact add_tsub_cancel_of_le h.le }\n\ninstance : has_well_founded \u2115+ := \u27e8(<), measure_wf coe\u27e9\n\n/-- Strong induction on `\u2115+`. -/\ndef strong_induction_on {p : \u2115+ \u2192 Sort*} : \u2200 (n : \u2115+) (h : \u2200 k, (\u2200 m, m < k \u2192 p m) \u2192 p k), p n\n| n := \u03bb IH, IH _ (\u03bb a h, strong_induction_on a IH)\nusing_well_founded { dec_tac := `[assumption] }\n\n/-- If `n : \u2115+` is different from `1`, then it is the successor of some `k : \u2115+`. -/\nlemma exists_eq_succ_of_ne_one : \u2200 {n : \u2115+} (h1 : n \u2260 1), \u2203 (k : \u2115+), n = k + 1\n| \u27e81, _\u27e9 h1 := false.elim $ h1 rfl\n| \u27e8n+2, _\u27e9 _ := \u27e8\u27e8n+1, by simp\u27e9, rfl\u27e9\n\n/-- Strong induction on `\u2115+`, with `n = 1` treated separately. -/\ndef case_strong_induction_on {p : \u2115+ \u2192 Sort*} (a : \u2115+) (hz : p 1)\n  (hi : \u2200 n, (\u2200 m, m \u2264 n \u2192 p m) \u2192 p (n + 1)) : p a :=\nbegin\n  apply strong_induction_on a,\n  rintro \u27e8k, kprop\u27e9 hk,\n  cases k with k,\n  { exact (lt_irrefl 0 kprop).elim },\n  cases k with k,\n  { exact hz },\n  exact hi \u27e8k.succ, nat.succ_pos _\u27e9 (\u03bb m hm, hk _ (lt_succ_iff.2 hm)),\nend\n\n/-- An induction principle for `\u2115+`: it takes values in `Sort*`, so it applies also to Types,\nnot only to `Prop`. -/\n@[elab_as_eliminator]\ndef rec_on (n : \u2115+) {p : \u2115+ \u2192 Sort*} (p1 : p 1) (hp : \u2200 n, p n \u2192 p (n + 1)) : p n :=\nbegin\n  rcases n with \u27e8n, h\u27e9,\n  induction n with n IH,\n  { exact absurd h dec_trivial },\n  { cases n with n,\n    { exact p1 },\n    { exact hp _ (IH n.succ_pos) } }\nend\n\n@[simp] theorem rec_on_one {p} (p1 hp) : @pnat.rec_on 1 p p1 hp = p1 := rfl\n\n@[simp] theorem rec_on_succ (n : \u2115+) {p : \u2115+ \u2192 Sort*} (p1 hp) :\n  @pnat.rec_on (n + 1) p p1 hp = hp n (@pnat.rec_on n p p1 hp) :=\nby { cases n with n h, cases n; [exact absurd h dec_trivial, refl] }\n\n/-- We define `m % k` and `m / k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` and\n  `m / k = n - 1`.  This ensures that `m % k` is always positive\n  and `m = (m % k) + k * (m / k)` in all cases.  Later we\n  define a function `div_exact` which gives the usual `m / k`\n  in the case where `k` divides `m`.\n-/\ndef mod_div_aux : \u2115+ \u2192 \u2115 \u2192 \u2115 \u2192 \u2115+ \u00d7 \u2115\n| k 0 q := \u27e8k, q.pred\u27e9\n| k (r + 1) q := \u27e8\u27e8r + 1, nat.succ_pos r\u27e9, q\u27e9\n\nlemma mod_div_aux_spec : \u2200 (k : \u2115+) (r q : \u2115) (h : \u00ac (r = 0 \u2227 q = 0)),\n (((mod_div_aux k r q).1 : \u2115) + k * (mod_div_aux k r q).2 = (r + k * q))\n| k 0 0 h := (h \u27e8rfl, rfl\u27e9).elim\n| k 0 (q + 1) h := by\n{ change (k : \u2115) + (k : \u2115) * (q + 1).pred = 0 + (k : \u2115) * (q + 1),\n  rw [nat.pred_succ, nat.mul_succ, zero_add, add_comm]}\n| k (r + 1) q h := rfl\n\n/-- `mod_div m k = (m % k, m / k)`.\n  We define `m % k` and `m / k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` and\n  `m / k = n - 1`.  This ensures that `m % k` is always positive\n  and `m = (m % k) + k * (m / k)` in all cases.  Later we\n  define a function `div_exact` which gives the usual `m / k`\n  in the case where `k` divides `m`.\n-/\ndef mod_div (m k : \u2115+) : \u2115+ \u00d7 \u2115 := mod_div_aux k ((m : \u2115) % (k : \u2115)) ((m : \u2115) / (k : \u2115))\n\n/-- We define `m % k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` This ensures that `m % k` is always positive.\n-/\ndef mod (m k : \u2115+) : \u2115+ := (mod_div m k).1\n\n/-- We define `m / k` in the same way as for `\u2115` except that when `m = n * k` we take\n  `m / k = n - 1`. This ensures that `m = (m % k) + k * (m / k)` in all cases. Later we\n  define a function `div_exact` which gives the usual `m / k` in the case where `k` divides `m`.\n-/\ndef div (m k : \u2115+) : \u2115  := (mod_div m k).2\n\ntheorem mod_add_div (m k : \u2115+) : ((mod m k) + k * (div m k) : \u2115) = m :=\nbegin\n  let h\u2080 := nat.mod_add_div (m : \u2115) (k : \u2115),\n  have : \u00ac ((m : \u2115) % (k : \u2115) = 0 \u2227 (m : \u2115) / (k : \u2115) = 0),\n  by { rintro \u27e8hr, hq\u27e9, rw [hr, hq, mul_zero, zero_add] at h\u2080,\n       exact (m.ne_zero h\u2080.symm).elim },\n  have := mod_div_aux_spec k ((m : \u2115) % (k : \u2115)) ((m : \u2115) / (k : \u2115)) this,\n  exact (this.trans h\u2080),\nend\n\ntheorem div_add_mod (m k : \u2115+) : (k * (div m k) + mod m k : \u2115) = m :=\n(add_comm _ _).trans (mod_add_div _ _)\n\nlemma mod_add_div' (m k : \u2115+) : ((mod m k) + (div m k) * k : \u2115) = m :=\nby { rw mul_comm, exact mod_add_div _ _ }\n\nlemma div_add_mod' (m k : \u2115+) : ((div m k) * k + mod m k : \u2115) = m :=\nby { rw mul_comm, exact div_add_mod _ _ }\n\ntheorem mod_coe (m k : \u2115+) :\n ((mod m k) : \u2115) = ite ((m : \u2115) % (k : \u2115) = 0) (k : \u2115) ((m : \u2115) % (k : \u2115)) :=\nbegin\n  dsimp [mod, mod_div],\n  cases (m : \u2115) % (k : \u2115),\n  { rw [if_pos rfl], refl },\n  { rw [if_neg n.succ_ne_zero], refl }\nend\n\ntheorem div_coe (m k : \u2115+) :\n ((div m k) : \u2115) = ite ((m : \u2115) % (k : \u2115) = 0) ((m : \u2115) / (k : \u2115)).pred ((m : \u2115) / (k : \u2115)) :=\nbegin\n  dsimp [div, mod_div],\n  cases (m : \u2115) % (k : \u2115),\n  { rw [if_pos rfl], refl },\n  { rw [if_neg n.succ_ne_zero], refl }\nend\n\ntheorem mod_le (m k : \u2115+) : mod m k \u2264 m \u2227 mod m k \u2264 k :=\nbegin\n  change ((mod m k) : \u2115) \u2264 (m : \u2115) \u2227 ((mod m k) : \u2115) \u2264 (k : \u2115),\n  rw [mod_coe], split_ifs,\n  { have hm : (m : \u2115) > 0 := m.pos,\n    rw [\u2190 nat.mod_add_div (m : \u2115) (k : \u2115), h, zero_add] at hm \u22a2,\n    by_cases h' : ((m : \u2115) / (k : \u2115)) = 0,\n    { rw [h', mul_zero] at hm, exact (lt_irrefl _ hm).elim},\n    { let h' := nat.mul_le_mul_left (k : \u2115)\n             (nat.succ_le_of_lt (nat.pos_of_ne_zero h')),\n      rw [mul_one] at h', exact \u27e8h', le_refl (k : \u2115)\u27e9 } },\n  { exact \u27e8nat.mod_le (m : \u2115) (k : \u2115), (nat.mod_lt (m : \u2115) k.pos).le\u27e9 }\nend\n\ntheorem dvd_iff {k m : \u2115+} : k \u2223 m \u2194 (k : \u2115) \u2223 (m : \u2115) :=\nbegin\n  split; intro h, rcases h with \u27e8_, rfl\u27e9, apply dvd_mul_right,\n  rcases h with \u27e8a, h\u27e9, cases a, { contrapose h, apply ne_zero, },\n  use a.succ, apply nat.succ_pos, rw [\u2190 coe_inj, h, mul_coe, mk_coe],\nend\n\ntheorem dvd_iff' {k m : \u2115+} : k \u2223 m \u2194 mod m k = k :=\nbegin\n  rw dvd_iff,\n  rw [nat.dvd_iff_mod_eq_zero], split,\n  { intro h, apply eq, rw [mod_coe, if_pos h] },\n  { intro h, by_cases h' : (m : \u2115) % (k : \u2115) = 0,\n    { exact h'},\n    { replace h : ((mod m k) : \u2115) = (k : \u2115) := congr_arg _ h,\n      rw [mod_coe, if_neg h'] at h,\n      exact ((nat.mod_lt (m : \u2115) k.pos).ne h).elim } }\nend\n\nlemma le_of_dvd {m n : \u2115+} : m \u2223 n \u2192 m \u2264 n :=\nby { rw dvd_iff', intro h, rw \u2190 h, apply (mod_le n m).left }\n\n/-- If `h : k | m`, then `k * (div_exact m k) = m`. Note that this is not equal to `m / k`. -/\ndef div_exact (m k : \u2115+) : \u2115+ :=\n \u27e8(div m k).succ, nat.succ_pos _\u27e9\n\ntheorem mul_div_exact {m k : \u2115+} (h : k \u2223 m) : k * (div_exact m k) = m :=\nbegin\n apply eq, rw [mul_coe],\n change (k : \u2115) * (div m k).succ = m,\n rw [\u2190 div_add_mod m k, dvd_iff'.mp h, nat.mul_succ]\nend\n\n\n\ntheorem dvd_one_iff (n : \u2115+) : n \u2223 1 \u2194 n = 1 :=\n \u27e8\u03bb h, dvd_antisymm h (one_dvd n), \u03bb h, h.symm \u25b8 (dvd_refl 1)\u27e9\n\nlemma pos_of_div_pos {n : \u2115+} {a : \u2115} (h : a \u2223 n) : 0 < a :=\nbegin\n  apply pos_iff_ne_zero.2,\n  intro hzero,\n  rw hzero at h,\n  exact pnat.ne_zero n (eq_zero_of_zero_dvd h)\nend\n\nend pnat\n\nsection can_lift\n\ninstance nat.can_lift_pnat : can_lift \u2115 \u2115+ :=\n\u27e8coe, \u03bb n, 0 < n, \u03bb n hn, \u27e8nat.to_pnat' n, pnat.to_pnat'_coe hn\u27e9\u27e9\n\ninstance int.can_lift_pnat : can_lift \u2124 \u2115+ :=\n\u27e8coe, \u03bb n, 0 < n, \u03bb n hn, \u27e8nat.to_pnat' (int.nat_abs n),\n  by rw [coe_coe, nat.to_pnat'_coe, if_pos (int.nat_abs_pos_of_ne_zero hn.ne'),\n    int.nat_abs_of_nonneg hn.le]\u27e9\u27e9\n\nend can_lift\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/pnat/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7325397092302446}}
{"text": "-- A Formal Proof of the Lovasz Local Lemma and Symmetric Lovasz Local Lemma\n\n-- This import covers everything we need; finsets, measure theory, ennreals, and probability theory.\nimport probability.independence\n\n/-\n  Since we are constantly dealing with finite sets, measures, and big products/intersections, it will make the proof\n  much more readable if we open these libraries/locales.\n-/ \nopen finset measure_theory\nopen_locale big_operators\n\n/-\n  If the events E\u1d62 are all independent and occur with probability less than 1, then it's obviously true that one can\n  avoid them all with nonzero probability, simply due to the fact that a product of positive quantities is positive.\n  The Lovasz Local Lemma says the same holds if the events are \"almost independent\", a notion captured by some\n  \"pseudo-probabilities\" X and a dependency digraph \u0393. I'm following the proof from these notes (and, for readability,\n  using it's notation as well): https://theory.stanford.edu/~jvondrak/MATH233A-2018/Math233-lec02.pdf\n\n  To be more precise, here is the full theorem statement in English: Suppose we have a probability space \u03a9 with\n  probability measure \u2119, as well as events E\u2081,\u2026,E\u2099. Let G be a dependency digraph for these events, and let \u0393(i) be\n  the neighborhood of E\u1d62 in G. In other words, \u0393(i) lists all other event indices j such that j \u2260 i and E\u1d62 depends on\n  E\u2c7c. Also, assume that we have real numbers X\u2081,\u2026,X\u2099 in the open interval (0, 1) such that, for each i, we have that\n  \u2119(E\u1d62) \u2264 X\u1d62 * (\u220f j, 1 - X\u2c7c), where the product is taken over all j \u2208 \u0393(i). Given all of this, theorem says that we\n  can avoid all the events; the probability of the intersection of their complements is nonzero. In particular, it is\n  bounded from below by (\u220f j, 1 - X\u2c7c), where the product is taken over all j \u2208 {1,\u2026,n}.\n-/\ntheorem lovasz_local_lemma\n  {\u03a9 : Type*}\n  [measurable_space \u03a9]\n  {\u2119 : measure \u03a9}\n  [is_probability_measure \u2119]\n  {n : \u2115}\n  {E : fin n \u2192 set \u03a9}\n  {h_events : \u2200 i, measurable_set (E i)}\n  {\u0393 : fin n \u2192 finset (fin n)}\n  (h_no_self_loops : \u2200 i, i \u2209 \u0393 i)\n  (h_dependency_digraph : \u2200 i, \u2200 J \u2286 ({i} \u222a (\u0393 i))\u1d9c, probability_theory.indep_sets {E i} {\u22c2 j \u2208 J, (E j)\u1d9c} \u2119) \n  {X : fin n \u2192 ennreal}\n  (h_pseudo_probability : \u2200 i, 0 < X i \u2227 X i < 1)\n  (h_independence_bound : \u2200 i, \u2119 (E i) \u2264 X i * \u220f j in \u0393 i, (1 - X j)) :\n\u2119 (\u22c2 i, (E i)\u1d9c) \u2260 0 \u2227 \u220f i, (1 - X i) \u2264 \u2119 (\u22c2 i, (E i)\u1d9c) :=\nbegin\n  /-\n    To make life easier, we make a few local definitions:\n    - Firstly, we extend the dependency digraph \u0393 to include self-loops; after all, nontrivial\n      events are dependent on themselves. Call this new digraph \u0393'.\n    - Secondly, we define shorthand for the intersection of the complements some subset of our events,\n      since we'll be using it a lot.\n    - Thirdly, we define shorthand for the probability of the above intersection.\n  -/\n  let \u0393' : (fin n \u2192 finset (fin n)) := \u03bb i, insert i (\u0393 i),\n  let inter_over : (finset (fin n) \u2192 set \u03a9) := \u03bb S, \u22c2 i \u2208 S, (E i)\u1d9c,\n  let P : (finset (fin n) \u2192 ennreal) := \u03bb S, \u2119 (inter_over S),\n\n  /-\n    We'll also prove a few helpful lemmas about these definitions and the definitions in the theorem statement.\n    - 1. The probability of the empty intersection is 1.\n    - 2. The intersection of more sets is smaller than the intersection of fewer sets.\n    - 3. We have 0 < 1 - X i < 1 for all i.\n    - 4. P finset.univ is the probability of the intersection of the complements.\n    - 5. Given S, a \u2208 S, and any set T, (S \\ insert a T) is of course a subset of (S.erase a). We use this a lot.\n    - 6. Given S, a \u2208 S, and any set T, (S \\ insert a T) is of course a strict subset of S. We also use this a lot.\n    All of these lemmas have simple proofs, so I didn't think any annotations were necessary.\n  -/\n  have P_empty_eq_one : P \u2205 = 1 :=\n  begin\n    have inter_over_empty_eq_univ : inter_over \u2205 = set.univ :=\n    begin\n      rw set.Inter_eq_univ,\n      intro i,\n      ext x,\n      split,\n      {\n        intro _,\n        exact set.mem_univ x,\n      },\n      {\n        intro _,\n        rw set.mem_Inter,\n        intro i_in_empty,\n        exfalso,\n        exact set.not_mem_empty i i_in_empty,\n      },\n    end,\n    simp only [P],\n    rw inter_over_empty_eq_univ,\n    exact measure_univ,\n  end,\n  have inter_subset_of_supset : \u2200 M N : finset (fin n), N \u2286 M \u2192 inter_over M \u2286 inter_over N :=\n  begin\n    intros M N N_subset_M,\n    intros x hx,\n    rw set.mem_Inter,\n    intro i,\n    rw set.mem_Inter,\n    intro hi,\n    rw set.mem_Inter at hx,\n    specialize hx i,\n    rw set.mem_Inter at hx,\n    exact hx (mem_of_subset N_subset_M hi),\n  end,\n  have one_minus_pprob_is_pprob : \u2200 i, 0 < 1 - X i \u2227 1 - X i < 1 :=\n  begin\n    intro i,\n    split,\n    {\n      rw tsub_pos_iff_lt,\n      exact (h_pseudo_probability i).2,\n    },\n    exact ennreal.sub_lt_self ennreal.one_ne_top one_ne_zero (ne_of_gt (h_pseudo_probability i).1),\n  end,\n  have P_univ_eq_prob_inter : P univ = \u2119 (\u22c2 i, (E i)\u1d9c) :=\n  begin\n    simp only [P, inter_over],\n    simp only [mem_univ, set.Inter_true],\n  end,\n  have sdiff_subset : \u2200 S : finset (fin n), \u2200 a \u2208 S, \u2200 T : finset (fin n), S \\ insert a T \u2286 S.erase a :=\n  begin\n    intros S a a_in_S T,\n    rw \u2190 sdiff_singleton_eq_erase,\n    exact sdiff_subset_sdiff (subset_refl S) (singleton_subset_iff.2 (mem_insert_self a T)),\n  end,\n  have sdiff_ssubset : \u2200 S : finset (fin n), \u2200 a \u2208 S, \u2200 T : finset (fin n), S \\ insert a T \u2282 S :=\n  begin\n    intros S a a_in_S T,\n    apply finset.ssubset_of_subset_of_ssubset,\n    exact sdiff_subset _ _ a_in_S _,\n    exact erase_ssubset a_in_S,\n  end,\n\n  /-\n    The bulk of the work is done by the following lemma: For all S \u2286 {1,...,n}, we have that the probability of\n    avoiding all events E\u2090 for a \u2208 S is nonzero, as well as the fact that the probability of avoiding all events E\u2090\n    for a \u2208 S is more than (1 - X\u2090) times the probability of avoiding all events E\u1d62 for i \u2208 S \\ {a}.\n  -/\n  have main_lemma : \u2200 S : finset (fin n), P S \u2260 0 \u2227 \u2200 a \u2208 S, P (S.erase a) * (1 - X a) \u2264 P S :=\n  begin\n    -- We go by strong induction on S; the predicate we're trying to prove is of course:\n    let predicate : (finset (fin n) \u2192 Prop) := \u03bb S, P S \u2260 0 \u2227 \u2200 a \u2208 S, P (S.erase a) * (1 - X a) \u2264 P S,\n\n    -- As is typical in strong induction, the induction step absorbs the base case.\n    have induction_step : \u2200 S : finset (fin n), (\u2200 T \u2282 S, predicate T) \u2192 predicate S :=\n    begin\n      -- Stop using predicate notation.\n      simp only [predicate],\n      clear predicate,\n\n      -- Let S be arbitrary and assume the claim holds for all strictly smaller sets.\n      intros S induction_hypothesis,\n\n      /-\n        We now prove the main part of our goal as a lemma, for convenience (it implies the other part). This section\n        contains nearly all of the hard work for proving the Lovasz Local Lemma.\n      -/\n      have main_inequality : \u2200 a \u2208 S, P (S.erase a) * (1 - X a) \u2264 P S :=\n      begin\n        -- Fortunately we can fix our element a right away.\n        intros a a_in_S,\n\n        -- First, we use independence and probability basics to get a lower bound on P S.\n        have lower_bound : P (S.erase a) - \u2119 (E a) * P (S \\ \u0393' a) \u2264 P S :=\n        begin\n          -- We pull (E a)\u1d9c out of the intersection over S.\n          have inter_over_S_split : inter_over S = (E a)\u1d9c \u2229 inter_over (S.erase a) :=\n          begin\n            simp only [inter_over],\n            rw [\u2190 insert_erase a_in_S, set_bInter_insert a (S.erase a), insert_erase a_in_S],\n          end,\n\n          -- Using the above, we pull (E a)\u1d9c out and use complementary measure.\n          have P_S_split : P S = P (S.erase a) - \u2119 ((E a) \u2229 inter_over (S.erase a)) :=\n          begin\n            simp only [P],\n            rw inter_over_S_split,\n            symmetry,\n            apply ennreal.sub_eq_of_eq_add,\n            {\n              exact ne_of_lt (measure_lt_top \u2119 _),\n            },\n            symmetry,\n            rw [\u2190 set.diff_eq_compl_inter, set.inter_comm],\n            apply measure_diff_add_inter,\n            exact h_events a,\n          end,\n\n          -- We have a simple inequality arising from monotonicity of measure.\n          have inequality : P (S.erase a) - \u2119 ((E a) \u2229 inter_over (S \\ \u0393' a)) \u2264 \n                            P (S.erase a) - \u2119 ((E a) \u2229 inter_over (S.erase a)) :=\n          begin\n            -- This immediately follows from lemma (2).\n            have subset : (E a) \u2229 inter_over (S.erase a) \u2286\n                          (E a) \u2229 inter_over (S \\ \u0393' a) :=\n            begin\n              intros x hx,\n              split,\n              {\n                exact hx.1,\n              },\n              have subset := sdiff_subset S a a_in_S (\u0393 a),\n              exact set.mem_of_subset_of_mem (inter_subset_of_supset (S.erase a) (S \\ \u0393' a) subset) hx.2,\n            end,\n            exact tsub_le_tsub_left (measure_theory.outer_measure.mono' \u2119.to_outer_measure subset) _,\n          end,\n\n          -- Finally, we use independence to separate (E a) from its independent sets as given by S \\ \u0393' a.\n          have prob_inter_eq_prod : \u2119 ((E a) \u2229 inter_over (S \\ \u0393' a)) = \u2119 (E a) * P (S \\ \u0393' a) :=\n          begin\n            specialize h_dependency_digraph a (S \\ \u0393' a),\n            have subset : S \\ \u0393' a \u2286 (\u0393' a)\u1d9c :=\n            begin\n              rw sdiff_eq_inter_compl,\n              intros x hx,\n              rw mem_inter at hx,\n              exact hx.2,\n            end,\n            exact probability_theory.indep_sets_singleton_iff.1 (h_dependency_digraph subset),\n          end,\n\n          -- We combine the above to complete the proof.\n          rw \u2190 P_S_split at inequality,\n          rwa \u2190 prob_inter_eq_prod,\n        end,\n\n        /-\n          Now, we write P (S \\ \u0393' a) / P (S.erase a) as a telescoping product, and apply induction_hypothesis to\n          each of the terms. In practice, we'll do this one term at a time using another induction.\n        -/ \n        have product_bound : P (S \\ \u0393' a) \u2264 P (S.erase a) * (\u220f i in (S \u2229 (\u0393 a)), (1 - X i)\u207b\u00b9) :=\n        begin\n          -- We go by induction on T; the predicate we're trying to prove is:\n          let predicate : (finset (fin n) \u2192 Prop) := \n            \u03bb T, P (S \\ \u0393' a) \u2264 P (S.erase a) * (\u220f i in T, (1 - X i)\u207b\u00b9) * P (S \\ \u0393' a) * (P (S \\ (insert a T)))\u207b\u00b9,\n\n          have induction_lemma : predicate (S \u2229 \u0393 a) :=\n          begin\n            -- The base case is more or less immediate.\n            have base_case : predicate \u2205 :=\n            begin\n              -- Stop using predicate notation.\n              simp only [predicate],\n              clear predicate,\n\n              rw [\n                insert_eq, prod_empty, mul_one, union_empty, sdiff_singleton_eq_erase a S, mul_comm, \u2190 mul_assoc,\n                ennreal.inv_mul_cancel\n              ],\n              {\n                rw one_mul,\n                exact le_refl _,\n              },\n              {\n                exact (induction_hypothesis (S.erase a) (erase_ssubset a_in_S)).1,\n              },\n              exact ne_of_lt (measure_lt_top \u2119 _),\n            end,\n\n            -- The induction step makes use of induction_hypothesis to show the upper bound for one more term.\n            have induction_step : \u2200 b, \u2200 T, b \u2208 S \u2229 \u0393 a \u2192 T \u2286 S \u2229 \u0393 a \u2192 b \u2209 T \u2192 predicate T \u2192 predicate (insert b T) :=\n            begin\n              -- Stop using predicate notation.\n              simp only [predicate],\n              clear base_case,\n              clear predicate,\n\n              -- Let T and b be arbitrary such that b \u2209 T, and assume the claim holds for S.\n              intros b T b_in_S_cap_Gam_a T_subset b_notin_T ih_lem,\n\n              -- First, we pull b out of the product.\n              rw [prod_insert b_notin_T, mul_comm (1 - X b)\u207b\u00b9 _, mul_assoc],\n\n              /-\n                Next, (1 - X b)\u207b\u00b9 is lower bounded by the desired ratio; this follows from the inductive_hypothesis.\n                Although this ends up being rather difficult in Lean, it's not anything mathematically interesting;\n                it's an immediate application of the inductive hypothesis to (S \\ insert a T) and basic inequality\n                manipulation. So, I didn't feel it necessary to provide annotations here.\n              -/\n              have ih_lower_bound :  P (S \\ insert a (insert b T)) * (P (S \\ insert a T))\u207b\u00b9 \u2264 (1 - X b)\u207b\u00b9 :=\n              begin\n                specialize induction_hypothesis (S \\ insert a T) (sdiff_ssubset S a a_in_S T),\n                have induction_bound := induction_hypothesis.2 b,\n                rw [\n                  ennreal.le_inv_iff_mul_le, mul_assoc, mul_comm _ (1 - X b), \u2190 mul_assoc,\n                  \u2190 ennreal.le_inv_iff_mul_le, inv_inv\n                ],\n                repeat { rw insert_eq },\n                rw \u2190 sdiff_insert at induction_bound,\n                repeat { rw insert_eq at induction_bound },\n                rw [union_comm, union_assoc, union_comm T _],\n                have b_in_set : b \u2208 S \\ ({a} \u222a T) :=\n                begin\n                  rw mem_sdiff,\n                  split,\n                  {\n                    rw mem_inter at b_in_S_cap_Gam_a,\n                    exact b_in_S_cap_Gam_a.1,\n                  },\n                  rw not_mem_union,\n                  split,\n                  {\n                    rw not_mem_singleton,\n                    by_contradiction b_eq_a,\n                    rw b_eq_a at b_in_S_cap_Gam_a,\n                    exact (not_mem_mono (inter_subset_right S (\u0393 a)) (h_no_self_loops a)) b_in_S_cap_Gam_a,\n                  },\n                  exact b_notin_T,\n                end,\n                exact induction_bound b_in_set,\n              end,\n\n              -- To make what follows easier, we move the term (1 - X b)\u207b\u00b9 all the way to the right.\n              rw [mul_assoc, mul_assoc _ (1 - X b)\u207b\u00b9 _, mul_comm (1 - X b)\u207b\u00b9 _],\n              repeat { rw \u2190 mul_assoc },\n\n              -- We can use transitivity with the lemma's induction hypothesis to reduce the inequality.\n              transitivity',\n              exact ih_lem,\n\n              -- We split a ratio (i.e. use a/c = a/b * b/c) to prepare the inequality for applying ih_lower_bound.\n              rw \u2190 mul_one (P (S \\ \u0393' a)),\n              have ne_zero : P (S \\ insert a (insert b T)) \u2260 0 :=\n                (induction_hypothesis (S \\ insert a (insert b T)) (sdiff_ssubset S a a_in_S (insert b T))).1,\n              have ne_top : P (S \\ insert a (insert b T)) \u2260 \u22a4 := ne_of_lt (measure_lt_top \u2119 _),\n              nth_rewrite_lhs 0 [\u2190 ennreal.inv_mul_cancel ne_zero ne_top],\n              rw mul_one,\n              repeat { rw \u2190 mul_assoc },\n              rw mul_assoc _ _ (P (S \\ insert a T))\u207b\u00b9,\n\n              -- Finally, we apply ih_lower_bound, which completes the induction step.\n              exact ennreal.mul_le_mul (le_refl _) ih_lower_bound,\n            end,\n            \n            -- Invoking the induction theorem for finite sets completes the proof.\n            exact finset.induction_on' (S \u2229 \u0393 a) base_case induction_step,\n          end,\n\n          -- Stop using predicate notation.\n          simp only [predicate] at induction_lemma,\n          clear predicate,\n\n          -- The desired bound follows easily from the induction_lemma; we just need to cancel the division.\n          have same_set : S \\ (insert a (S \u2229 \u0393 a)) = S \\ \u0393' a :=\n          begin\n            simp only [\u0393'],\n            repeat { rw insert_eq },\n            rw [\n              union_distrib_left, sdiff_inter_distrib_right, sdiff_eq_empty_iff_subset.2 (subset_union_right _ _),\n              empty_union _\n            ],\n          end,\n          rwa [same_set, mul_assoc, ennreal.mul_inv_cancel, mul_one] at induction_lemma,\n          {\n            have ssubset := finset.ssubset_of_subset_of_ssubset (sdiff_subset S a a_in_S (\u0393 a)) (erase_ssubset a_in_S),\n            exact (induction_hypothesis (S \\ \u0393' a) ssubset).1,\n          },\n          exact ne_of_lt (measure_lt_top \u2119 _),\n        end,\n\n        -- The last big task is getting rid of the two products; we'll first need to combine them into one.\n        have prod_cancel : (\u220f i in \u0393 a, (1 - X i)) * (\u220f i in S \u2229 \u0393 a, (1 - X i)\u207b\u00b9) = \u220f i in \u0393 a \\ S, (1 - X i) :=\n        begin\n          have prod_split : (\u220f i in \u0393 a, (1 - X i)) = (\u220f i in \u0393 a \\ S, (1 - X i)) * (\u220f i in S \u2229 \u0393 a, (1 - X i)) :=\n          begin\n            rw [inter_comm, mul_comm],\n            have piecewise_same := set.piecewise_same (\u2191S) (\u03bb i, (1 - X i)),\n            nth_rewrite 0 [\u2190 piecewise_same],\n            rw [piecewise_coe, prod_piecewise],\n          end,\n          have cancel : \u2200 i \u2208 S \u2229 \u0393 a, (1 - X i) * (1 - X i)\u207b\u00b9 = 1 :=\n          begin\n            intros i _,\n            rw ennreal.mul_inv_cancel,\n            exact ne_of_gt (one_minus_pprob_is_pprob i).1,\n            exact ne_of_lt (lt_trans (one_minus_pprob_is_pprob i).2 ennreal.one_lt_top),\n          end,\n          rw [prod_split, mul_assoc, \u2190 prod_mul_distrib, prod_eq_one cancel, mul_one],\n        end,\n\n        -- And now we can of course upper bound this resulting product by 1.\n        have prod_le_one : (\u220f i in \u0393 a \\ S, (1 - X i)) \u2264 1 :=\n        begin\n          have le_one : \u2200 i \u2208 \u0393 a \\ S, 1 - X i \u2264 1 :=\n          begin\n            intros i _,\n            exact le_of_lt (one_minus_pprob_is_pprob i).2,\n          end,\n          exact prod_le_one' le_one,\n        end,\n\n        -- Using the above work, we combine the independence and product bounds and then simplify the big products.\n        have two_products := ennreal.mul_le_mul (h_independence_bound a) product_bound,\n        rw mul_comm (P (S.erase a)) _ at two_products,\n        repeat { rw mul_assoc at two_products },\n        rw [\u2190 mul_assoc _ _ (P (S.erase a)), prod_cancel] at two_products,\n\n        -- From here, we can upper bound the product by 1 and conclude that P (S.erase a) * (1 - X a) \u2264 P S.\n        rw [mul_comm _ (P (S.erase a)), \u2190 mul_assoc _ (P (S.erase a)) _, mul_comm _ (P (S.erase a))] at two_products,\n        have no_products := ennreal.mul_le_mul (refl (P (S.erase a) * X a)) prod_le_one,\n        rw mul_one at no_products,\n        have final_inequality := le_trans two_products no_products,\n        \n        -- Combining the above with the lower bound from earlier, we complete the proof of the main inequality!\n        rw ennreal.mul_sub,\n        swap,\n        {\n          intros _ _,\n          exact ne_of_lt (measure_lt_top \u2119 _),\n        },\n        rw mul_one,\n        exact le_trans (tsub_le_tsub_left final_inequality (P (S.erase a))) lower_bound,\n      end,\n\n      -- Using the main part of our goal, we can now quickly prove the easier part of our goal (that P S \u2260 0).\n      split,\n      {\n        by_cases S_nonempty : S = \u2205,\n        {\n          rw [S_nonempty, P_empty_eq_one],\n          exact one_ne_zero,\n        },\n        cases nonempty_iff_ne_empty.2 S_nonempty with a a_in_S,\n        apply ne_of_gt,\n        specialize main_inequality a a_in_S,\n        specialize induction_hypothesis (S.erase a) (erase_ssubset a_in_S),\n        apply lt_of_le_of_lt',\n        {\n          exact main_inequality,\n        },\n        exact ennreal.mul_pos induction_hypothesis.1 (ne_of_gt (one_minus_pprob_is_pprob a).1),\n      },\n\n      -- Finally, we complete the proof; we've already finished proving the second part of the goal.\n      exact main_inequality,\n    end,\n\n    -- Invoking the strong induction theorem for finite sets completes the proof.\n    intro S,\n    exact finset.strong_induction_on S induction_step,\n  end,\n  \n  -- Now that we've proven the lemma, we can immediately conclude the first part the theorem.\n  split,\n  {\n    have events_avoidable := (main_lemma univ).1,\n    rwa P_univ_eq_prob_inter at events_avoidable,\n  },\n\n  /-\n    We'll now use induction to create a stronger version of our lemma. NOTE: Unfortunately, as tempting as it was to\n    use finset.prod_range_induction, I couldn't find a good way to deal with the fact that E : fin n \u2192 set \u03a9 rather\n    than E : \u2115 \u2192 set \u03a9. In particular, that theorem has a hypothesis \"\u2200 (k : \u2115), s (k + 1) = s k * f k\", and I\n    couldn't think of a good way to expand E to domain \u2115 without breaking this hypothesis condition for k = n. \n  -/ \n  have stronger_lemma : \u2200 S : finset (fin n), P S\u1d9c * \u220f i in S, (1 - X i) \u2264 P univ :=\n  begin\n    -- We go by induction on S; the predicate we're trying to prove is of course:\n    let predicate : (finset (fin n) \u2192 Prop) := \u03bb S, P S\u1d9c * \u220f i in S, (1 - X i) \u2264 P univ,\n\n    have base_case : predicate \u2205 :=\n    begin\n      -- Stop using predicate notation.\n      simp only [predicate],\n      clear predicate,\n\n      rw [finset.prod_empty, mul_one, compl_empty],\n      exact le_refl _,\n    end,\n\n    have induction_step : \u2200 a : fin n, \u2200 S : finset (fin n), a \u2209 S \u2192 predicate S \u2192 predicate (insert a S) :=\n    begin\n      -- Stop using predicate notation.\n      simp only [predicate],\n      clear base_case,\n      clear predicate,\n      \n      -- Let S and a be arbitrary such that a \u2209 S, and assume the claim holds for S.\n      intros a S a_notin_S induction_hypothesis,\n\n      -- We pull an element out of S\u1d9c, which is the same as adding an element to S, and apply the main lemma to it.\n      specialize main_lemma S\u1d9c,\n      have main_lemma_ineq := main_lemma.2,\n      clear main_lemma,\n      specialize main_lemma_ineq a (mem_compl.2 a_notin_S),\n      rw \u2190 compl_insert at main_lemma_ineq,\n\n      -- Now we turn the product over (insert a S) into the product over S times the term at a\n      rw [prod_insert a_notin_S, \u2190 mul_assoc],\n\n      -- Transitivity and multiplicativity of \u2264 for nonnegative reals completes the proof.\n      exact le_trans (ennreal.mul_le_mul main_lemma_ineq (refl _)) induction_hypothesis,\n    end,\n\n    -- Invoking the induction theorem for finite sets completes the proof.\n    exact finset.induction base_case induction_step,\n  end,\n\n  -- Finally, we can use this stronger version to conclude the proof of the theorem!\n  specialize stronger_lemma univ,\n  rwa [P_univ_eq_prob_inter, \u2190 compl_empty, compl_involutive, P_empty_eq_one, one_mul] at stronger_lemma,\nend\n\n/-\n  There is also a \"symmetric\" version of the theorem, which is typically the one used in practice since it only\n  deals with an upper the number of other events that an event is dependent on rather than the specific events.\n\n  To be precise, it says if each event is individually avoidable (probability strictly less than 1, call it p), each\n  event depends on at most d other events, and ep(d + 1) \u2264 1 (where e is Euler's number), then the events are\n  collectively avoidable; the probability of the intersection of their complements is nonzero.\n\n  NOTE: I couldn't find anything on Euler's number in Lean, so I decided to just use the slightly tighter bound \n  p \u2264 (1 - 1/(d + 1))^d / (d + 1). Indeed ep(d + 1) \u2264 1, we have p(d + 1) \u2264 e^(-1) \u2264 e^(-d/(d + 1)). By a classical\n  inequality, this is at most (1 - 1/(d + 1))^d, so our assumption is indeed stronger.\n-/\ntheorem symmetric_lovasz_local_lemma\n  {\u03a9 : Type*}\n  [measurable_space \u03a9]\n  {\u2119 : measure \u03a9}\n  [is_probability_measure \u2119]\n  {n : \u2115}\n  {E : fin n \u2192 set \u03a9}\n  {h_events : \u2200 i, measurable_set (E i)}\n  {\u0393 : fin n \u2192 finset (fin n)}\n  (h_no_self_loops : \u2200 i, i \u2209 \u0393 i)\n  (h_dependency_digraph : \u2200 i, \u2200 J \u2286 ({i} \u222a (\u0393 i))\u1d9c, probability_theory.indep_sets {E i} {\u22c2 j \u2208 J, (E j)\u1d9c} \u2119) \n  (p : ennreal)\n  (h_probability : 0 < p \u2227 p < 1)\n  (h_event_probability_bound : \u2200 i, \u2119 (E i) \u2264 p)\n  (d : \u2115) \n  (h_d_pos : 1 \u2264 d)\n  (h_maximum_dependence : \u2200 i, (\u0393 i).card \u2264 d)\n  (h_p_bound : p \u2264 (d + 1)\u207b\u00b9 * (1 - (d + 1)\u207b\u00b9)^d) :\n\u2119 (\u22c2 i, (E i)\u1d9c) \u2260 0 :=\nbegin\n  -- We take our pseudo-probabiliies to be X\u1d62 = 1 / (d + 1)\n  let X : fin n \u2192 ennreal := \u03bb _, (d + 1)\u207b\u00b9,\n\n  -- First, we need to show that X actually gives pseudo-probabilities.\n  have h_pseudo_probability : \u2200 i, 0 < X i \u2227 X i < 1 :=\n  begin\n    intro i,\n    simp only [X],\n    split,\n    {\n      simp,\n    },\n    rw ennreal.inv_lt_one,\n    apply lt_of_lt_of_le,\n    exact ennreal.one_lt_two,\n    rw \u2190 one_add_one_eq_two,\n    apply' add_le_add,\n    {\n      norm_cast,\n      exact h_d_pos,\n    },\n    exact le_refl _,\n  end,\n\n  -- The main work here is showing that X actually gives an independence bound; it uses a classical inequality.\n  have h_independence_bound : \u2200 i, \u2119 (E i) \u2264 X i * \u220f j in \u0393 i, (1 - X j) :=\n  begin\n    intro i,\n    transitivity',\n    exact h_event_probability_bound i,\n\n    -- We upper bound p using the h_p_bound,\n    transitivity',\n    exact h_p_bound,\n    \n    -- We now simplify the right-hand side using the definition of X.\n    simp only [X],\n    apply' ennreal.mul_le_mul,\n    exact le_refl _,\n\n    -- Finally, we're just left with a constant product over \u0393 i.\n    rw prod_const,\n    have le_one : 1 - (ennreal.has_coe.coe d + 1)\u207b\u00b9 \u2264 1 := by simp,\n    exact ennreal.pow_le_pow_of_le_one le_one (h_maximum_dependence i),\n  end,\n\n  -- From here, it's just a direct aplication of the (asymmetric) Lovasz Local Lemma.\n  have result := lovasz_local_lemma h_no_self_loops h_dependency_digraph h_pseudo_probability h_independence_bound,\n  swap,\n  exact h_events,\n  exact result.1,\nend", "meta": {"author": "nsglover", "repo": "lean-lovasz-local-lemma", "sha": "6d45e9054815a2197273d254e8038de80a62c3ec", "save_path": "github-repos/lean/nsglover-lean-lovasz-local-lemma", "path": "github-repos/lean/nsglover-lean-lovasz-local-lemma/lean-lovasz-local-lemma-6d45e9054815a2197273d254e8038de80a62c3ec/src/lovasz_local_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541611, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7324591240104243}}
{"text": "/-\nCopyright (c) 2019 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n-/\nimport algebra.order.ring\nimport data.nat.basic\nimport data.set.lattice\nimport order.directed\nimport tactic.monotonicity.basic\n\nvariables {\u03b1 : Type*}\n\n@[mono]\nlemma mul_mono_nonneg {x y z : \u03b1} [ordered_semiring \u03b1]\n  (h' : 0 \u2264 z)\n  (h : x \u2264 y)\n: x * z \u2264 y * z :=\nby apply mul_le_mul_of_nonneg_right; assumption\n\nlemma lt_of_mul_lt_mul_neg_right {a b c : \u03b1}  [linear_ordered_ring \u03b1]\n  (h : a * c < b * c) (hc : c \u2264 0) : b < a :=\nhave nhc : -c \u2265 0, from neg_nonneg_of_nonpos hc,\nhave h2 : -(b * c) < -(a * c), from neg_lt_neg h,\nhave h3 : b * (-c) < a * (-c), from calc\n     b * (-c) = - (b * c)    : by rewrite neg_mul_eq_mul_neg\n          ... < - (a * c)    : h2\n          ... = a * (-c)     : by rewrite neg_mul_eq_mul_neg,\nlt_of_mul_lt_mul_right h3 nhc\n\n@[mono]\nlemma mul_mono_nonpos {x y z : \u03b1} [linear_ordered_ring \u03b1]\n  (h' : z \u2264 0) (h : y \u2264 x) : x * z \u2264 y * z :=\nbegin\n  classical,\n  by_contradiction h'',\n  revert h,\n  apply not_le_of_lt,\n  apply lt_of_mul_lt_mul_neg_right _ h',\n  apply lt_of_not_ge h''\nend\n\n@[mono]\nlemma nat.sub_mono_left_strict {x y z : \u2115}\n  (h' : z \u2264 x)\n  (h : x < y)\n: x - z < y - z :=\nbegin\n  have : z \u2264 y,\n  { transitivity, assumption, apply le_of_lt h, },\n  apply @nat.lt_of_add_lt_add_left z,\n  rw [add_tsub_cancel_of_le,add_tsub_cancel_of_le];\n    solve_by_elim\nend\n\n@[mono]\nlemma nat.sub_mono_right_strict {x y z : \u2115}\n  (h' : x \u2264 z)\n  (h : y < x)\n: z - x < z - y :=\nbegin\n  have h'' : y \u2264 z,\n  { transitivity, apply le_of_lt h, assumption },\n  apply @nat.lt_of_add_lt_add_right _ x,\n  rw [tsub_add_cancel_of_le h'],\n  apply @lt_of_le_of_lt _ _ _ (z - y + y),\n  rw [tsub_add_cancel_of_le h''],\n  apply nat.add_lt_add_left h\nend\n\nopen set\n\nattribute [mono] inter_subset_inter union_subset_union\n                 sUnion_mono Union\u2082_mono sInter_subset_sInter Inter\u2082_mono\n                 image_subset preimage_mono prod_mono monotone.set_prod seq_mono\n                 image2_subset order_embedding.monotone\nattribute [mono] upper_bounds_mono_set lower_bounds_mono_set\n                 upper_bounds_mono_mem  lower_bounds_mono_mem\n                 upper_bounds_mono  lower_bounds_mono\n                 bdd_above.mono bdd_below.mono\n\nattribute [mono] add_le_add mul_le_mul neg_le_neg\n         mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right\n         imp_imp_imp le_implies_le_of_le_of_le\n         sub_le_sub tsub_le_tsub tsub_le_tsub_right abs_le_abs sup_le_sup\n         inf_le_inf\nattribute [mono left] add_lt_add_of_le_of_lt mul_lt_mul'\nattribute [mono right] add_lt_add_of_lt_of_le mul_lt_mul\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/tactic/monotonicity/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7324184289328396}}
{"text": "/-\nThis file contains the definition of a Boolean literal.\nThe type of the underlying Boolean variable is polymorphic, such\nthat Boolean variables may be represented by nats, strings, etc.\n \nAuthors: Cayden Codel, Jeremy Avigad, Marijn Heule\nCarnegie Mellon University\n-/\n\nimport tactic\n\n-- Represents the type of the variable stored in the literal\nvariable {V : Type*}\n\n/-\nAll propositional formulas are comprised of Boolean literals.\nLiterals are positive or negative forms of the underlying variable type.\n-/\n@[derive decidable_eq]\ninductive literal (V : Type*)\n| Pos (v : V) : literal\n| Neg (v : V) : literal\n\n/-\nPropositional formulas may be evaluated under truth assignments.\nAssignments give boolean values to the variables in the formula.\n-/\ndef assignment (V : Type*) := V \u2192 bool\n\nnamespace literal\n\nopen function\n\n/-! # Properties -/\n\ninstance [inhabited V] : inhabited (literal V) := \u27e8Pos (arbitrary V)\u27e9\n\nprotected def repr [has_repr V] : literal V \u2192 string\n| (Pos v) := \"Pos \" ++ (has_repr.repr v)\n| (Neg v) := \"Neg \" ++ (has_repr.repr v)\n\ninstance [has_repr V] : has_repr (literal V) := \u27e8literal.repr\u27e9\ninstance [has_repr V] : has_to_string (literal V) := \u27e8literal.repr\u27e9\n\n/-! # Var -/\n\n/- Extracts the underlying variable of the literal -/\ndef var : literal V \u2192 V\n| (Pos v) := v\n| (Neg v) := v\n\ntheorem var_surjective : surjective (var : literal V \u2192 V) :=\nassume v, exists.intro (Pos v) (by simp only [var])\n\ntheorem ne_of_ne_var {l\u2081 l\u2082 : literal V} : l\u2081.var \u2260 l\u2082.var \u2192 l\u2081 \u2260 l\u2082 :=\nassume h\u2081 h\u2082, h\u2081 (congr_arg var h\u2082)\n\n/-! # Evaluation -/\n\n/-\nWhen provided an assignment, literals may be evaluated against\nthat assignment. Negated literals flip the truth value of the\nunderlying variable when evaluated on the assignment.\n-/\nprotected def eval (\u03c4 : assignment V) : literal V \u2192 bool\n| (Pos v) := \u03c4 v\n| (Neg v) := bnot (\u03c4 v)\n\n/-! # Flip -/\n\n/- Flips the parity of the literal from positive to negative and vice versa -/\nprotected def flip : literal V \u2192 literal V\n| (Pos v) := Neg v\n| (Neg v) := Pos v\n\n@[simp] theorem flip_ne [decidable_eq V] : \u2200 (l : literal V), l.flip \u2260 l\n| (Pos v) := dec_trivial\n| (Neg v) := dec_trivial\n\ntheorem flip_flip : \u2200 (l : literal V), l.flip.flip = l\n| (Pos v) := rfl\n| (Neg v) := rfl\n\ntheorem flip_var_eq : \u2200 (l : literal V), l.flip.var = l.var\n| (Pos v) := rfl\n| (Neg v) := rfl\n\n@[simp] theorem flip_injective : injective (literal.flip : literal V \u2192 literal V) :=\nassume l\u2081 l\u2082 h, (flip_flip l\u2082) \u25b8 ((flip_flip l\u2081) \u25b8 (congr_arg literal.flip h))\n\ntheorem flip_inj {l\u2081 l\u2082 : literal V} : l\u2081.flip = l\u2082.flip \u2194 l\u2081 = l\u2082 :=\nflip_injective.eq_iff\n\n@[simp] theorem flip_surjective : surjective (literal.flip : literal V \u2192 literal V) :=\nassume l, exists.intro l.flip (flip_flip l)\n\n@[simp] theorem flip_bijective : bijective (literal.flip : literal V \u2192 literal V) :=\n\u27e8flip_injective, flip_surjective\u27e9\n\ntheorem exists_flip_eq (l\u2081 : literal V) : \u2203 (l\u2082 : literal V), l\u2082.flip = l\u2081 :=\n\u27e8l\u2081.flip, flip_flip l\u2081\u27e9\n\nsection -- Various lemmas on how var and flip interact\n\nvariables {l\u2081 l\u2082 : literal V}\n\ntheorem var_eq_iff_eq_or_flip_eq : l\u2081.var = l\u2082.var \u2194 l\u2081 = l\u2082 \u2228 l\u2081.flip = l\u2082 :=\nby cases l\u2081; cases l\u2082; simp [literal.flip, var]\n\ntheorem flip_eq_iff_eq_flip : l\u2081.flip = l\u2082 \u2194 l\u2081 = l\u2082.flip :=\n\u27e8\u03bb h, congr_arg literal.flip h \u25b8 (flip_flip l\u2081).symm, \n \u03bb h, (congr_arg literal.flip h).symm \u25b8 flip_flip l\u2082\u27e9\n\ntheorem flip_ne_iff_ne_flip : l\u2081.flip \u2260 l\u2082 \u2194 l\u2081 \u2260 l\u2082.flip :=\n\u27e8\u03bb h\u2081 h\u2082, absurd (flip_eq_iff_eq_flip.mpr h\u2082) h\u2081, \n \u03bb h\u2081 h\u2082, absurd (flip_eq_iff_eq_flip.mp h\u2082) h\u2081\u27e9\n\ntheorem flip_eq_of_ne_of_var_eq : l\u2081 \u2260 l\u2082 \u2192 l\u2081.var = l\u2082.var \u2192 l\u2081.flip = l\u2082 :=\n\u03bb h\u2081 h\u2082, or.elim (var_eq_iff_eq_or_flip_eq.mp h\u2082) (\u03bb h, absurd h h\u2081) id\n\ntheorem eq_of_flip_ne_of_var_eq : l\u2081.flip \u2260 l\u2082 \u2192 l\u2081.var = l\u2082.var \u2192 l\u2081 = l\u2082 :=\n\u03bb h\u2081 h\u2082, or.elim (var_eq_iff_eq_or_flip_eq.mp h\u2082) id (\u03bb h, absurd h h\u2081)\n\nend /- end section -/\n\n/-! # Flip evaluation -/\n\n-- When a literal is flipped, its truth assignment is negated\n@[simp] theorem eval_flip (\u03c4 : assignment V) (l : literal V) : \n  l.flip.eval \u03c4 = bnot (l.eval \u03c4) :=\nby cases l; simp only [literal.flip, literal.eval, bnot_bnot]\n\n-- A slight modification where the negation is the flipped literal\ntheorem eval_flip2 (\u03c4 : assignment V) (l : literal V) :\n  l.eval \u03c4 = bnot (l.flip.eval \u03c4) :=\nby cases l; simp only [literal.flip, literal.eval, bnot_bnot]\n\ntheorem eval_flip_of_eval {\u03c4 : assignment V} {l : literal V} {b : bool} :\n  l.eval \u03c4 = b \u2192 l.flip.eval \u03c4 = bnot b :=\nassume h, congr_arg bnot h \u25b8 eval_flip \u03c4 l\n\ntheorem eval_of_eval_flip {\u03c4 : assignment V} {l : literal V} {b : bool} :\n  literal.eval \u03c4 l.flip = b \u2192 literal.eval \u03c4 l = bnot b :=\nassume h, congr_arg bnot h \u25b8 eval_flip2 \u03c4 l\n\n/-! # Positives and negatives -/\n\nprotected def is_pos : literal V \u2192 Prop\n| (Pos _) := true\n| (Neg _) := false\n\nprotected def is_neg : literal V \u2192 Prop\n| (Pos _) := false\n| (Neg _) := true\n\n-- Must be protected because of decidable.is_true\nprotected def is_true (\u03c4 : assignment V) (l : literal V) : Prop := \nliteral.eval \u03c4 l = tt\n\nprotected def is_false (\u03c4 : assignment V) (l : literal V) : Prop :=\nliteral.eval \u03c4 l = ff\n\ninstance : decidable_pred (literal.is_pos : literal V \u2192 Prop)\n| (Pos v) := decidable.true\n| (Neg v) := decidable.false\n\ninstance : decidable_pred (literal.is_neg : literal V \u2192 Prop)\n| (Pos v) := decidable.false\n| (Neg v) := decidable.true\n\ninstance (\u03c4 : assignment V) : decidable_pred (literal.is_true \u03c4) :=\n\u03bb l, by cases h : l.eval \u03c4; { unfold literal.is_true, rw h, exact eq.decidable _ _ }\n\ninstance (\u03c4 : assignment V) : decidable_pred (literal.is_false \u03c4) :=\n\u03bb l, by cases h : l.eval \u03c4; { unfold literal.is_false, rw h, exact eq.decidable _ _ }\n\n-- A literal can never be both positive and negative\ntheorem is_pos_ne_is_neg (l : literal V) :\n  literal.is_pos l \u2260 literal.is_neg l :=\nby cases l; simp [literal.is_pos, literal.is_neg]\n\n-- A literal can never be both true and false under the same assignment\n-- NOTE: A strange proof, can probably be simplified\ntheorem is_true_ne_is_false [inhabited V] (\u03c4 : assignment V) :\n  (literal.is_true \u03c4) \u2260 (literal.is_false \u03c4) :=\nbegin\n  intro h,\n  have v := arbitrary (literal V),\n  have := congr_arg (\u03bb (f : literal V \u2192 Prop), f v) h,\n  cases he : literal.eval \u03c4 v;\n  { simp [literal.is_true, literal.is_false, he] at this, assumption }\nend\n\nend literal", "meta": {"author": "ccodel", "repo": "verified-encodings", "sha": "ee22a6a04ee56cc568f91fbee5a70d39e5e261f8", "save_path": "github-repos/lean/ccodel-verified-encodings", "path": "github-repos/lean/ccodel-verified-encodings/verified-encodings-ee22a6a04ee56cc568f91fbee5a70d39e5e261f8/src/cnf/literal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7323929319764542}}
{"text": "import .love09_hoare_logic_demo\n\n\n/- # LoVe Exercise 9: Hoare Logic -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1: Program Verification\n\nThe following WHILE program is intended to compute the Gaussian sum up to `n`,\nleaving the result in `r`. -/\n\ndef GAUSS : stmt :=\nstmt.assign \"r\" (\u03bbs, 0) ;;\nstmt.while (\u03bbs, s \"n\" \u2260 0)\n  (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"n\") ;;\n   stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n\n/- The summation function: -/\n\ndef sum_upto : \u2115 \u2192 \u2115\n| 0       := 0\n| (n + 1) := n + 1 + sum_upto n\n\n/- 1.1. Prove the correctness of `GAUSS` using `vcg`. The main challenge is to\nfigure out which invariant to use for the while loop. The invariant should\ncapture both the work that has been done already (the intermediate result) and\nthe work that remains to be done. -/\n\nlemma GAUSS_correct (n\u2080 : \u2115) :\n  {* \u03bbs, s \"n\" = n\u2080 *} GAUSS {* \u03bbs, s \"r\" = sum_upto n\u2080 *} :=\nsorry\n\n/- 1.2. The following WHILE program is intended to compute the product of `n`\nand `m`, leaving the result in `r`. Prove its correctness using `vcg`.\n\nHint: If a variable `x` does not change in a program, it might be useful to\nrecord this in the invariant, by adding a conjunct `s \"x\" = x\u2080`. -/\n\ndef MUL : stmt :=\nstmt.assign \"r\" (\u03bbs, 0) ;;\nstmt.while (\u03bbs, s \"n\" \u2260 0)\n  (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"m\") ;;\n   stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n\nlemma MUL_correct (n\u2080 m\u2080 : \u2115) :\n  {* \u03bbs, s \"n\" = n\u2080 \u2227 s \"m\" = m\u2080 *} MUL {* \u03bbs, s \"r\" = n\u2080 * m\u2080 *} :=\nsorry\n\n\n/- ## Question 2: Hoare Triples for Total Correctness -/\n\ndef total_hoare (P : state \u2192 Prop) (S : stmt) (Q : state \u2192 Prop) : Prop :=\n\u2200s, P s \u2192 \u2203t, (S, s) \u27f9 t \u2227 Q t\n\nnotation `[* ` P : 1 ` *] ` S : 1 ` [* ` Q : 1 ` *]` :=\ntotal_hoare P S Q\n\nnamespace total_hoare\n\n/- 2.1. Prove the consequence rule. -/\n\nlemma consequence {P P' Q Q' : state \u2192 Prop} {S}\n    (hS : [* P *] S [* Q *]) (hP : \u2200s, P' s \u2192 P s) (hQ : \u2200s, Q s \u2192 Q' s) :\n  [* P' *] S [* Q' *] :=\nsorry\n\n/- 2.2. Prove the rule for `skip`. -/\n\nlemma skip_intro {P} :\n  [* P *] stmt.skip [* P *] :=\nsorry\n\n/- 2.3. Prove the rule for `assign`. -/\n\nlemma assign_intro {P : state \u2192 Prop} {x} {a : state \u2192 \u2115} :\n  [* \u03bbs, P (s{x \u21a6 a s}) *] stmt.assign x a [* P *] :=\nsorry\n\n/- 2.4. Prove the rule for `seq`. -/\n\nlemma seq_intro {P Q R S T} (hS : [* P *] S [* Q *]) (hT : [* Q *] T [* R *]) :\n  [* P *] S ;; T [* R *] :=\nsorry\n\n/- 2.5. Complete the proof of the rule for `ite`.\n\nHint: This requires a case distinction on the truth value of `b s`. -/\n\nlemma ite_intro {b P Q : state \u2192 Prop} {S T}\n    (hS : [* \u03bbs, P s \u2227 b s *] S [* Q *])\n    (hT : [* \u03bbs, P s \u2227 \u00ac b s *] T [* Q *]) :\n  [* P *] stmt.ite b S T [* Q *] :=\nsorry\n\n/- 2.6 (**optional**). Try to prove the rule for `while`.\n\nThe rule is parameterized by a loop invariant `I` and by a variant `V` that\ndecreases with each iteration of the loop body.\n\nBefore we prove the desired lemma, we introduce an auxiliary lemma. Its proof\nrequires well-founded induction. When using `while_var_intro_aux` as induction\nhypothesis we recommend to do it directly after proving that the argument is\nless than `v\u2080`:\n\n    have ih : \u2203u, (stmt.while b S, t) \u27f9 u \u2227 I u \u2227 \u00ac b u :=\n      have V t < v\u2080 :=\n        \u2026,\n      while_var_intro_aux (V t) \u2026,\n\nSimilarly to `ite`, the proof requires a case distinction on `b s \u2228 \u00ac b s`. -/\n\nlemma while_var_intro_aux {b : state \u2192 Prop} (I : state \u2192 Prop) (V : state \u2192 \u2115)\n  {S} (h_inv : \u2200v\u2080, [* \u03bbs, I s \u2227 b s \u2227 V s = v\u2080 *] S [* \u03bbs, I s \u2227 V s < v\u2080 *]) :\n  \u2200v\u2080 s, V s = v\u2080 \u2192 I s \u2192 \u2203t, (stmt.while b S, s) \u27f9 t \u2227 I t \u2227 \u00ac b t\n| v\u2080 s V_eq hs :=\nsorry\n\nlemma while_var_intro {b : state \u2192 Prop} (I : state \u2192 Prop) (V : state \u2192 \u2115) {S}\n  (hinv : \u2200v\u2080, [* \u03bbs, I s \u2227 b s \u2227 V s = v\u2080 *] S [* \u03bbs, I s \u2227 V s < v\u2080 *]) :\n  [* I *] stmt.while b S [* \u03bbs, I s \u2227 \u00ac b s *] :=\nsorry\n\nend total_hoare\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love09_hoare_logic_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.732392922282171}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem amc12b_2020_p2 :\n  ((100 ^ 2 - 7 ^ 2):\u211d) / (70 ^ 2 - 11 ^ 2) * ((70 - 11) * (70 + 11) / ((100 - 7) * (100 + 7))) = 1 :=\nbegin\n  norm_num,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/amc/12/2020/b/p2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7323350986776214}}
{"text": "import game.order.level04\nimport game.order.H\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 5\n\nAnother well-known property of the absolute value.\n-/\n\nnotation `|` x `|` := abs x -- hide\n\n\n/-\nHint: negate abs_le_if_pos_neg_le\n-/\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$| |a| - |b| | \u2264 |a - b|$$.\n-/\ntheorem abs_of_sub_le_abs (a b : \u211d) : | |a| - |b| | \u2264 |a - b| :=\nbegin\n    have h1 : a = (a - b) + b,\n    norm_num,\n    have h2 : | a | = | (a - b) + b |,\n    norm_num,\n    have h3 : | (a - b) + b | \u2264 |a - b| + |b|,\n    exact abs_add _ _,\n    rw \u2190 h2 at h3,\n    have h4 : | a | - | b | \u2264 | a - b |,\n    linarith,\n    have k1 : b = (b - a) + a,\n    norm_num,\n    have k2 : | b | = | (b - a) + a |,\n    norm_num,\n    have k3 : | (b - a) + a | \u2264 |b - a| + |a|,\n    exact abs_add _ _,\n    rw \u2190 k2 at k3,\n    have k4 : | b | - | a | \u2264 | b - a |,\n    linarith,\n    clear h1 h2 h3 k1 k2 k3,\n    have h := eq.symm (abs_neg (a-b)),\n    have h2 : -(a - b) = b - a,\n    norm_num,\n    rw h2 at h,\n    rw \u2190 h at k4,\n    have H := abs_le_if_pos_neg_le (|a| - |b|) (|a - b|),\n    apply H,\n    have G := abs_le_if_pos_neg_le(|b| - |a|) (|b - a|),\n    norm_num,\n    split,\n    exact h4,\n    exact k4,\nend\n\nend xena --hide\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/order/level05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.7879312006227323, "lm_q1q2_score": 0.7323350979033734}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport data.set.intervals.basic\nimport data.set.n_ary\n\n/-!\n\n# Upper / lower bounds\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define:\n\n* `upper_bounds`, `lower_bounds` : the set of upper bounds (resp., lower bounds) of a set;\n* `bdd_above s`, `bdd_below s` : the set `s` is bounded above (resp., below), i.e., the set of upper\n  (resp., lower) bounds of `s` is nonempty;\n* `is_least s a`, `is_greatest s a` : `a` is a least (resp., greatest) element of `s`;\n  for a partial order, it is unique if exists;\n* `is_lub s a`, `is_glb s a` : `a` is a least upper bound (resp., a greatest lower bound)\n  of `s`; for a partial order, it is unique if exists.\n\nWe also prove various lemmas about monotonicity, behaviour under `\u222a`, `\u2229`, `insert`, and provide\nformulas for `\u2205`, `univ`, and intervals.\n-/\n\nopen function set order_dual (to_dual of_dual)\n\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x}\n\nsection\nvariables [preorder \u03b1] [preorder \u03b2] {s t : set \u03b1} {a b : \u03b1}\n\n/-!\n### Definitions\n-/\n\n/-- The set of upper bounds of a set. -/\ndef upper_bounds (s : set \u03b1) : set \u03b1 := { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 a \u2264 x }\n/-- The set of lower bounds of a set. -/\ndef lower_bounds (s : set \u03b1) : set \u03b1 := { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 x \u2264 a }\n\n/-- A set is bounded above if there exists an upper bound. -/\ndef bdd_above (s : set \u03b1) := (upper_bounds s).nonempty\n/-- A set is bounded below if there exists a lower bound. -/\ndef bdd_below (s : set \u03b1) := (lower_bounds s).nonempty\n\n/-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/\ndef is_least (s : set \u03b1) (a : \u03b1) : Prop := a \u2208 s \u2227 a \u2208 lower_bounds s\n/-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists -/\ndef is_greatest (s : set \u03b1) (a : \u03b1) : Prop := a \u2208 s \u2227 a \u2208 upper_bounds s\n\n/-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/\ndef is_lub (s : set \u03b1) : \u03b1 \u2192 Prop := is_least (upper_bounds s)\n/-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/\ndef is_glb (s : set \u03b1) : \u03b1 \u2192 Prop := is_greatest (lower_bounds s)\n\nlemma mem_upper_bounds : a \u2208 upper_bounds s \u2194 \u2200 x \u2208 s, x \u2264 a := iff.rfl\nlemma mem_lower_bounds : a \u2208 lower_bounds s \u2194 \u2200 x \u2208 s, a \u2264 x := iff.rfl\n\nlemma bdd_above_def : bdd_above s \u2194 \u2203 x, \u2200 y \u2208 s, y \u2264 x := iff.rfl\nlemma bdd_below_def : bdd_below s \u2194 \u2203 x, \u2200 y \u2208 s, x \u2264 y := iff.rfl\n\nlemma bot_mem_lower_bounds [order_bot \u03b1] (s : set \u03b1) : \u22a5 \u2208 lower_bounds s := \u03bb _ _, bot_le\nlemma top_mem_upper_bounds [order_top \u03b1] (s : set \u03b1) : \u22a4 \u2208 upper_bounds s := \u03bb _ _, le_top\n\n@[simp] lemma is_least_bot_iff [order_bot \u03b1] : is_least s \u22a5 \u2194 \u22a5 \u2208 s :=\nand_iff_left $ bot_mem_lower_bounds _\n\n@[simp] lemma is_greatest_top_iff [order_top \u03b1] : is_greatest s \u22a4 \u2194 \u22a4 \u2208 s :=\nand_iff_left $ top_mem_upper_bounds _\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not greater than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(y \u2264 x)`. A version for linear orders is called `not_bdd_above_iff`. -/\nlemma not_bdd_above_iff' : \u00acbdd_above s \u2194 \u2200 x, \u2203 y \u2208 s, \u00ac(y \u2264 x) :=\nby simp [bdd_above, upper_bounds, set.nonempty]\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not less than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(x \u2264 y)`. A version for linear orders is called `not_bdd_below_iff`. -/\nlemma not_bdd_below_iff' : \u00acbdd_below s \u2194 \u2200 x, \u2203 y \u2208 s, \u00ac x \u2264 y := @not_bdd_above_iff' \u03b1\u1d52\u1d48 _ _\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` that is greater\nthan `x`. A version for preorders is called `not_bdd_above_iff'`. -/\nlemma not_bdd_above_iff {\u03b1 : Type*} [linear_order \u03b1] {s : set \u03b1} :\n  \u00acbdd_above s \u2194 \u2200 x, \u2203 y \u2208 s, x < y :=\nby simp only [not_bdd_above_iff', not_le]\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` that is less\nthan `x`. A version for preorders is called `not_bdd_below_iff'`. -/\nlemma not_bdd_below_iff {\u03b1 : Type*} [linear_order \u03b1] {s : set \u03b1} :\n  \u00acbdd_below s \u2194 \u2200 x, \u2203 y \u2208 s, y < x :=\n@not_bdd_above_iff \u03b1\u1d52\u1d48 _ _\n\nlemma bdd_above.dual (h : bdd_above s) : bdd_below (of_dual \u207b\u00b9' s) := h\n\nlemma bdd_below.dual (h : bdd_below s) : bdd_above (of_dual \u207b\u00b9' s) := h\n\nlemma is_least.dual (h : is_least s a) : is_greatest (of_dual \u207b\u00b9' s) (to_dual a) := h\n\nlemma is_greatest.dual (h : is_greatest s a) : is_least (of_dual \u207b\u00b9' s) (to_dual a) := h\n\nlemma is_lub.dual (h : is_lub s a) : is_glb (of_dual \u207b\u00b9' s) (to_dual a) := h\n\nlemma is_glb.dual (h : is_glb s a) : is_lub (of_dual \u207b\u00b9' s) (to_dual a) := h\n\n/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/\n@[reducible] def is_least.order_bot (h : is_least s a) : order_bot s :=\n{ bot := \u27e8a, h.1\u27e9,\n  bot_le := subtype.forall.2 h.2 }\n\n/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/\n@[reducible] def is_greatest.order_top (h : is_greatest s a) : order_top s :=\n{ top := \u27e8a, h.1\u27e9,\n  le_top := subtype.forall.2 h.2 }\n\n/-!\n### Monotonicity\n-/\n\nlemma upper_bounds_mono_set \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) :\n  upper_bounds t \u2286 upper_bounds s :=\n\u03bb b hb x h, hb $ hst h\n\nlemma lower_bounds_mono_set \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) :\n  lower_bounds t \u2286 lower_bounds s :=\n\u03bb b hb x h, hb $ hst h\n\nlemma upper_bounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : a \u2208 upper_bounds s \u2192 b \u2208 upper_bounds s :=\n\u03bb ha x h, le_trans (ha h) hab\n\nlemma lower_bounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : b \u2208 lower_bounds s \u2192 a \u2208 lower_bounds s :=\n\u03bb hb x h, le_trans hab (hb h)\n\nlemma upper_bounds_mono \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n  a \u2208 upper_bounds t \u2192 b \u2208 upper_bounds s :=\n\u03bb ha, upper_bounds_mono_set hst $ upper_bounds_mono_mem hab ha\n\nlemma lower_bounds_mono \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n  b \u2208 lower_bounds t \u2192 a \u2208 lower_bounds s :=\n\u03bb hb, lower_bounds_mono_set hst $ lower_bounds_mono_mem hab hb\n\n/-- If `s \u2286 t` and `t` is bounded above, then so is `s`. -/\nlemma bdd_above.mono \u2983s t : set \u03b1\u2984 (h : s \u2286 t) : bdd_above t \u2192 bdd_above s :=\nnonempty.mono $ upper_bounds_mono_set h\n\n/-- If `s \u2286 t` and `t` is bounded below, then so is `s`. -/\nlemma bdd_below.mono \u2983s t : set \u03b1\u2984 (h : s \u2286 t) : bdd_below t \u2192 bdd_below s :=\nnonempty.mono $ lower_bounds_mono_set h\n\n/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\nlemma is_lub.of_subset_of_superset {s t p : set \u03b1} (hs : is_lub s a) (hp : is_lub p a)\n  (hst : s \u2286 t) (htp : t \u2286 p) : is_lub t a :=\n\u27e8upper_bounds_mono_set htp hp.1, lower_bounds_mono_set (upper_bounds_mono_set hst) hs.2\u27e9\n\n/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\nlemma is_glb.of_subset_of_superset {s t p : set \u03b1} (hs : is_glb s a) (hp : is_glb p a)\n  (hst : s \u2286 t) (htp : t \u2286 p) : is_glb t a :=\nhs.dual.of_subset_of_superset hp hst htp\n\nlemma is_least.mono (ha : is_least s a) (hb : is_least t b) (hst : s \u2286 t) : b \u2264 a :=\nhb.2 (hst ha.1)\n\nlemma is_greatest.mono (ha : is_greatest s a) (hb : is_greatest t b) (hst : s \u2286 t) : a \u2264 b :=\nhb.2 (hst ha.1)\n\nlemma is_lub.mono (ha : is_lub s a) (hb : is_lub t b) (hst : s \u2286 t) : a \u2264 b :=\nhb.mono ha $ upper_bounds_mono_set hst\n\nlemma is_glb.mono (ha : is_glb s a) (hb : is_glb t b) (hst : s \u2286 t) : b \u2264 a :=\nhb.mono ha $ lower_bounds_mono_set hst\n\nlemma subset_lower_bounds_upper_bounds (s : set \u03b1) : s \u2286 lower_bounds (upper_bounds s) :=\n\u03bb x hx y hy, hy hx\n\nlemma subset_upper_bounds_lower_bounds (s : set \u03b1) : s \u2286 upper_bounds (lower_bounds s) :=\n\u03bb x hx y hy, hy hx\n\nlemma set.nonempty.bdd_above_lower_bounds (hs : s.nonempty) : bdd_above (lower_bounds s) :=\nhs.mono (subset_upper_bounds_lower_bounds s)\n\nlemma set.nonempty.bdd_below_upper_bounds (hs : s.nonempty) : bdd_below (upper_bounds s) :=\nhs.mono (subset_lower_bounds_upper_bounds s)\n\n/-!\n### Conversions\n-/\n\nlemma is_least.is_glb (h : is_least s a) : is_glb s a := \u27e8h.2, \u03bb b hb, hb h.1\u27e9\n\nlemma is_greatest.is_lub (h : is_greatest s a) : is_lub s a := \u27e8h.2, \u03bb b hb, hb h.1\u27e9\n\nlemma is_lub.upper_bounds_eq (h : is_lub s a) : upper_bounds s = Ici a :=\nset.ext $ \u03bb b, \u27e8\u03bb hb, h.2 hb, \u03bb hb, upper_bounds_mono_mem hb h.1\u27e9\n\nlemma is_glb.lower_bounds_eq (h : is_glb s a) : lower_bounds s = Iic a := h.dual.upper_bounds_eq\n\nlemma is_least.lower_bounds_eq (h : is_least s a) : lower_bounds s = Iic a :=\nh.is_glb.lower_bounds_eq\n\nlemma is_greatest.upper_bounds_eq (h : is_greatest s a) : upper_bounds s = Ici a :=\nh.is_lub.upper_bounds_eq\n\nlemma is_lub_le_iff (h : is_lub s a) : a \u2264 b \u2194 b \u2208 upper_bounds s :=\nby { rw h.upper_bounds_eq, refl }\n\nlemma le_is_glb_iff (h : is_glb s a) : b \u2264 a \u2194 b \u2208 lower_bounds s :=\nby { rw h.lower_bounds_eq, refl }\n\nlemma is_lub_iff_le_iff : is_lub s a \u2194 \u2200 b, a \u2264 b \u2194 b \u2208 upper_bounds s :=\n\u27e8\u03bb h b, is_lub_le_iff h, \u03bb H, \u27e8(H _).1 le_rfl, \u03bb b hb, (H b).2 hb\u27e9\u27e9\n\nlemma is_glb_iff_le_iff : is_glb s a \u2194 \u2200 b, b \u2264 a \u2194 b \u2208 lower_bounds s :=\n@is_lub_iff_le_iff \u03b1\u1d52\u1d48 _ _ _\n\n/-- If `s` has a least upper bound, then it is bounded above. -/\nlemma is_lub.bdd_above (h : is_lub s a) : bdd_above s := \u27e8a, h.1\u27e9\n\n/-- If `s` has a greatest lower bound, then it is bounded below. -/\nlemma is_glb.bdd_below (h : is_glb s a) : bdd_below s := \u27e8a, h.1\u27e9\n\n/-- If `s` has a greatest element, then it is bounded above. -/\nlemma is_greatest.bdd_above (h : is_greatest s a) : bdd_above s := \u27e8a, h.2\u27e9\n\n/-- If `s` has a least element, then it is bounded below. -/\nlemma is_least.bdd_below (h : is_least s a) : bdd_below s := \u27e8a, h.2\u27e9\n\nlemma is_least.nonempty (h : is_least s a) : s.nonempty := \u27e8a, h.1\u27e9\n\nlemma is_greatest.nonempty (h : is_greatest s a) : s.nonempty := \u27e8a, h.1\u27e9\n\n/-!\n### Union and intersection\n-/\n\n@[simp] lemma upper_bounds_union : upper_bounds (s \u222a t) = upper_bounds s \u2229 upper_bounds t :=\nsubset.antisymm\n  (\u03bb b hb, \u27e8\u03bb x hx, hb (or.inl hx), \u03bb x hx, hb (or.inr hx)\u27e9)\n  (\u03bb b hb x hx, hx.elim (\u03bb hs, hb.1 hs) (\u03bb ht, hb.2 ht))\n\n@[simp] lemma lower_bounds_union : lower_bounds (s \u222a t) = lower_bounds s \u2229 lower_bounds t :=\n@upper_bounds_union \u03b1\u1d52\u1d48 _ s t\n\nlemma union_upper_bounds_subset_upper_bounds_inter :\n  upper_bounds s \u222a upper_bounds t \u2286 upper_bounds (s \u2229 t) :=\nunion_subset\n  (upper_bounds_mono_set $ inter_subset_left _ _)\n  (upper_bounds_mono_set $ inter_subset_right _ _)\n\nlemma union_lower_bounds_subset_lower_bounds_inter :\n  lower_bounds s \u222a lower_bounds t \u2286 lower_bounds (s \u2229 t) :=\n@union_upper_bounds_subset_upper_bounds_inter \u03b1\u1d52\u1d48 _ s t\n\nlemma is_least_union_iff {a : \u03b1} {s t : set \u03b1} :\n  is_least (s \u222a t) a \u2194 (is_least s a \u2227 a \u2208 lower_bounds t \u2228 a \u2208 lower_bounds s \u2227 is_least t a) :=\nby simp [is_least, lower_bounds_union, or_and_distrib_right, and_comm (a \u2208 t), and_assoc]\n\nlemma is_greatest_union_iff :\n  is_greatest (s \u222a t) a \u2194 (is_greatest s a \u2227 a \u2208 upper_bounds t \u2228\n    a \u2208 upper_bounds s \u2227 is_greatest t a) :=\n@is_least_union_iff \u03b1\u1d52\u1d48 _ a s t\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\nlemma bdd_above.inter_of_left (h : bdd_above s) : bdd_above (s \u2229 t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\nlemma bdd_above.inter_of_right (h : bdd_above t) : bdd_above (s \u2229 t) :=\nh.mono $ inter_subset_right s t\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\nlemma bdd_below.inter_of_left (h : bdd_below s) : bdd_below (s \u2229 t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\nlemma bdd_below.inter_of_right (h : bdd_below t) : bdd_below (s \u2229 t) :=\nh.mono $ inter_subset_right s t\n\n/-- If `s` and `t` are bounded above sets in a `semilattice_sup`, then so is `s \u222a t`. -/\nlemma bdd_above.union [semilattice_sup \u03b3] {s t : set \u03b3} :\n  bdd_above s \u2192 bdd_above t \u2192 bdd_above (s \u222a t) :=\nbegin\n  rintros \u27e8bs, hs\u27e9 \u27e8bt, ht\u27e9,\n  use bs \u2294 bt,\n  rw upper_bounds_union,\n  exact \u27e8upper_bounds_mono_mem le_sup_left hs,\n    upper_bounds_mono_mem le_sup_right ht\u27e9\nend\n\n/-- The union of two sets is bounded above if and only if each of the sets is. -/\nlemma bdd_above_union [semilattice_sup \u03b3] {s t : set \u03b3} :\n  bdd_above (s \u222a t) \u2194 bdd_above s \u2227 bdd_above t :=\n\u27e8\u03bb h, \u27e8h.mono $ subset_union_left s t, h.mono $ subset_union_right s t\u27e9,\n  \u03bb h, h.1.union h.2\u27e9\n\nlemma bdd_below.union [semilattice_inf \u03b3] {s t : set \u03b3} :\n  bdd_below s \u2192 bdd_below t \u2192 bdd_below (s \u222a t) :=\n@bdd_above.union \u03b3\u1d52\u1d48 _ s t\n\n/--The union of two sets is bounded above if and only if each of the sets is.-/\nlemma bdd_below_union [semilattice_inf \u03b3] {s t : set \u03b3} :\n  bdd_below (s \u222a t) \u2194 bdd_below s \u2227 bdd_below t :=\n@bdd_above_union \u03b3\u1d52\u1d48 _ s t\n\n/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,\nthen `a \u2294 b` is the least upper bound of `s \u222a t`. -/\nlemma is_lub.union [semilattice_sup \u03b3] {a b : \u03b3} {s t : set \u03b3}\n  (hs : is_lub s a) (ht : is_lub t b) :\n  is_lub (s \u222a t) (a \u2294 b) :=\n\u27e8\u03bb c h, h.cases_on (\u03bb h, le_sup_of_le_left $ hs.left h) (\u03bb h, le_sup_of_le_right $ ht.left h),\n  \u03bb c hc, sup_le (hs.right $ \u03bb d hd, hc $ or.inl hd) (ht.right $ \u03bb d hd, hc $ or.inr hd)\u27e9\n\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a \u2293 b` is the greatest lower bound of `s \u222a t`. -/\nlemma is_glb.union [semilattice_inf \u03b3] {a\u2081 a\u2082 : \u03b3} {s t : set \u03b3}\n  (hs : is_glb s a\u2081) (ht : is_glb t a\u2082) :\n  is_glb (s \u222a t) (a\u2081 \u2293 a\u2082) :=\nhs.dual.union ht\n\n/-- If `a` is the least element of `s` and `b` is the least element of `t`,\nthen `min a b` is the least element of `s \u222a t`. -/\nlemma is_least.union [linear_order \u03b3] {a b : \u03b3} {s t : set \u03b3}\n  (ha : is_least s a) (hb : is_least t b) : is_least (s \u222a t) (min a b) :=\n\u27e8by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_glb.union hb.is_glb).1\u27e9\n\n/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,\nthen `max a b` is the greatest element of `s \u222a t`. -/\nlemma is_greatest.union [linear_order \u03b3] {a b : \u03b3} {s t : set \u03b3}\n  (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (s \u222a t) (max a b) :=\n\u27e8by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_lub.union hb.is_lub).1\u27e9\n\nlemma is_lub.inter_Ici_of_mem [linear_order \u03b3] {s : set \u03b3} {a b : \u03b3} (ha : is_lub s a)\n  (hb : b \u2208 s) : is_lub (s \u2229 Ici b) a :=\n\u27e8\u03bb x hx, ha.1 hx.1, \u03bb c hc, have hbc : b \u2264 c, from hc \u27e8hb, le_rfl\u27e9,\n  ha.2 $ \u03bb x hx, (le_total x b).elim (\u03bb hxb, hxb.trans hbc) $ \u03bb hbx, hc \u27e8hx, hbx\u27e9\u27e9\n\nlemma is_glb.inter_Iic_of_mem [linear_order \u03b3] {s : set \u03b3} {a b : \u03b3} (ha : is_glb s a)\n  (hb : b \u2208 s) : is_glb (s \u2229 Iic b) a :=\nha.dual.inter_Ici_of_mem hb\n\nlemma bdd_above_iff_exists_ge [semilattice_sup \u03b3] {s : set \u03b3} (x\u2080 : \u03b3) :\n  bdd_above s \u2194 \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x :=\nby { rw [bdd_above_def, exists_ge_and_iff_exists], exact monotone.ball (\u03bb x hx, monotone_le) }\n\nlemma bdd_below_iff_exists_le [semilattice_inf \u03b3] {s : set \u03b3} (x\u2080 : \u03b3) :\n  bdd_below s \u2194 \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\nbdd_above_iff_exists_ge (to_dual x\u2080)\n\nlemma bdd_above.exists_ge  [semilattice_sup \u03b3] {s : set \u03b3} (hs : bdd_above s) (x\u2080 : \u03b3) :\n  \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x :=\n(bdd_above_iff_exists_ge x\u2080).mp hs\n\nlemma bdd_below.exists_le  [semilattice_inf \u03b3] {s : set \u03b3} (hs : bdd_below s) (x\u2080 : \u03b3) :\n  \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\n(bdd_below_iff_exists_le x\u2080).mp hs\n\n/-!\n### Specific sets\n\n#### Unbounded intervals\n-/\n\nlemma is_least_Ici : is_least (Ici a) a := \u27e8left_mem_Ici, \u03bb x, id\u27e9\n\nlemma is_greatest_Iic : is_greatest (Iic a) a := \u27e8right_mem_Iic, \u03bb x, id\u27e9\n\nlemma is_lub_Iic : is_lub (Iic a) a := is_greatest_Iic.is_lub\n\nlemma is_glb_Ici : is_glb (Ici a) a := is_least_Ici.is_glb\n\nlemma upper_bounds_Iic : upper_bounds (Iic a) = Ici a := is_lub_Iic.upper_bounds_eq\n\nlemma lower_bounds_Ici : lower_bounds (Ici a) = Iic a := is_glb_Ici.lower_bounds_eq\n\nlemma bdd_above_Iic : bdd_above (Iic a) := is_lub_Iic.bdd_above\n\nlemma bdd_below_Ici : bdd_below (Ici a) := is_glb_Ici.bdd_below\n\nlemma bdd_above_Iio : bdd_above (Iio a) := \u27e8a, \u03bb x hx, le_of_lt hx\u27e9\n\nlemma bdd_below_Ioi : bdd_below (Ioi a) := \u27e8a, \u03bb x hx, le_of_lt hx\u27e9\n\nlemma lub_Iio_le (a : \u03b1) (hb : is_lub (set.Iio a) b) : b \u2264 a :=\n(is_lub_le_iff hb).mpr $ \u03bb k hk, le_of_lt hk\n\nlemma le_glb_Ioi (a : \u03b1) (hb : is_glb (set.Ioi a) b) : a \u2264 b := @lub_Iio_le \u03b1\u1d52\u1d48 _ _ a hb\n\nlemma lub_Iio_eq_self_or_Iio_eq_Iic [partial_order \u03b3] {j : \u03b3} (i : \u03b3) (hj : is_lub (set.Iio i) j) :\n  j = i \u2228 set.Iio i = set.Iic j :=\nbegin\n  cases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i,\n  { exact or.inl hj_eq_i, },\n  { right,\n    exact set.ext (\u03bb k, \u27e8\u03bb hk_lt, hj.1 hk_lt, \u03bb hk_le_j, lt_of_le_of_lt hk_le_j hj_lt_i\u27e9), },\nend\n\nlemma glb_Ioi_eq_self_or_Ioi_eq_Ici [partial_order \u03b3] {j : \u03b3} (i : \u03b3) (hj : is_glb (set.Ioi i) j) :\n  j = i \u2228 set.Ioi i = set.Ici j :=\n@lub_Iio_eq_self_or_Iio_eq_Iic \u03b3\u1d52\u1d48 _ j i hj\n\nsection\n\nvariables [linear_order \u03b3]\n\nlemma exists_lub_Iio (i : \u03b3) : \u2203 j, is_lub (set.Iio i) j :=\nbegin\n  by_cases h_exists_lt : \u2203 j, j \u2208 upper_bounds (set.Iio i) \u2227 j < i,\n  { obtain \u27e8j, hj_ub, hj_lt_i\u27e9 := h_exists_lt,\n    exact \u27e8j, hj_ub, \u03bb k hk_ub, hk_ub hj_lt_i\u27e9, },\n  { refine \u27e8i, \u03bb j hj, le_of_lt hj, _\u27e9,\n    rw mem_lower_bounds,\n    by_contra,\n    refine h_exists_lt _,\n    push_neg at h,\n    exact h, },\nend\n\nlemma exists_glb_Ioi (i : \u03b3) : \u2203 j, is_glb (set.Ioi i) j := @exists_lub_Iio \u03b3\u1d52\u1d48 _ i\n\nvariables [densely_ordered \u03b3]\n\nlemma is_lub_Iio {a : \u03b3} : is_lub (Iio a) a :=\n\u27e8\u03bb x hx, le_of_lt hx, \u03bb y hy, le_of_forall_ge_of_dense hy\u27e9\n\nlemma is_glb_Ioi {a : \u03b3} : is_glb (Ioi a) a := @is_lub_Iio \u03b3\u1d52\u1d48 _ _ a\n\nlemma upper_bounds_Iio {a : \u03b3} : upper_bounds (Iio a) = Ici a := is_lub_Iio.upper_bounds_eq\n\nlemma lower_bounds_Ioi {a : \u03b3} : lower_bounds (Ioi a) = Iic a := is_glb_Ioi.lower_bounds_eq\n\nend\n\n/-!\n#### Singleton\n-/\n\nlemma is_greatest_singleton : is_greatest {a} a :=\n\u27e8mem_singleton a, \u03bb x hx, le_of_eq $ eq_of_mem_singleton hx\u27e9\n\nlemma is_least_singleton : is_least {a} a := @is_greatest_singleton \u03b1\u1d52\u1d48 _ a\n\nlemma is_lub_singleton : is_lub {a} a := is_greatest_singleton.is_lub\n\nlemma is_glb_singleton : is_glb {a} a := is_least_singleton.is_glb\n\nlemma bdd_above_singleton : bdd_above ({a} : set \u03b1) := is_lub_singleton.bdd_above\n\nlemma bdd_below_singleton : bdd_below ({a} : set \u03b1) := is_glb_singleton.bdd_below\n\n@[simp] lemma upper_bounds_singleton : upper_bounds {a} = Ici a := is_lub_singleton.upper_bounds_eq\n\n@[simp] lemma lower_bounds_singleton : lower_bounds {a} = Iic a := is_glb_singleton.lower_bounds_eq\n\n/-!\n#### Bounded intervals\n-/\n\nlemma bdd_above_Icc : bdd_above (Icc a b) := \u27e8b, \u03bb _, and.right\u27e9\n\nlemma bdd_below_Icc : bdd_below (Icc a b) := \u27e8a, \u03bb _, and.left\u27e9\n\nlemma bdd_above_Ico : bdd_above (Ico a b) := bdd_above_Icc.mono Ico_subset_Icc_self\n\nlemma bdd_below_Ico : bdd_below (Ico a b) := bdd_below_Icc.mono Ico_subset_Icc_self\n\nlemma bdd_above_Ioc : bdd_above (Ioc a b) := bdd_above_Icc.mono Ioc_subset_Icc_self\n\nlemma bdd_below_Ioc : bdd_below (Ioc a b) := bdd_below_Icc.mono Ioc_subset_Icc_self\n\nlemma bdd_above_Ioo : bdd_above (Ioo a b) := bdd_above_Icc.mono Ioo_subset_Icc_self\n\nlemma bdd_below_Ioo : bdd_below (Ioo a b) := bdd_below_Icc.mono Ioo_subset_Icc_self\n\nlemma is_greatest_Icc (h : a \u2264 b) : is_greatest (Icc a b) b :=\n\u27e8right_mem_Icc.2 h, \u03bb x, and.right\u27e9\n\nlemma is_lub_Icc (h : a \u2264 b) : is_lub (Icc a b) b := (is_greatest_Icc h).is_lub\n\nlemma upper_bounds_Icc (h : a \u2264 b) : upper_bounds (Icc a b) = Ici b :=\n(is_lub_Icc h).upper_bounds_eq\n\nlemma is_least_Icc (h : a \u2264 b) : is_least (Icc a b) a :=\n\u27e8left_mem_Icc.2 h, \u03bb x, and.left\u27e9\n\nlemma is_glb_Icc (h : a \u2264 b) : is_glb (Icc a b) a := (is_least_Icc h).is_glb\n\nlemma lower_bounds_Icc (h : a \u2264 b) : lower_bounds (Icc a b) = Iic a :=\n(is_glb_Icc h).lower_bounds_eq\n\nlemma is_greatest_Ioc (h : a < b) : is_greatest (Ioc a b) b :=\n\u27e8right_mem_Ioc.2 h, \u03bb x, and.right\u27e9\n\nlemma is_lub_Ioc (h : a < b) : is_lub (Ioc a b) b :=\n(is_greatest_Ioc h).is_lub\n\nlemma upper_bounds_Ioc (h : a < b) : upper_bounds (Ioc a b) = Ici b :=\n(is_lub_Ioc h).upper_bounds_eq\n\nlemma is_least_Ico (h : a < b) : is_least (Ico a b) a :=\n\u27e8left_mem_Ico.2 h, \u03bb x, and.left\u27e9\n\nlemma is_glb_Ico (h : a < b) : is_glb (Ico a b) a :=\n(is_least_Ico h).is_glb\n\nlemma lower_bounds_Ico (h : a < b) : lower_bounds (Ico a b) = Iic a :=\n(is_glb_Ico h).lower_bounds_eq\n\nsection\n\nvariables [semilattice_sup \u03b3] [densely_ordered \u03b3]\n\nlemma is_glb_Ioo {a b : \u03b3} (h : a < b) :\n  is_glb (Ioo a b) a :=\n\u27e8\u03bb x hx, hx.1.le, \u03bb x hx,\nbegin\n  cases eq_or_lt_of_le (le_sup_right : a \u2264 x \u2294 a) with h\u2081 h\u2082,\n  { exact h\u2081.symm \u25b8 le_sup_left },\n  obtain \u27e8y, lty, ylt\u27e9 := exists_between h\u2082,\n  apply (not_lt_of_le (sup_le (hx \u27e8lty, ylt.trans_le (sup_le _ h.le)\u27e9) lty.le) ylt).elim,\n  obtain \u27e8u, au, ub\u27e9 := exists_between h,\n  apply (hx \u27e8au, ub\u27e9).trans ub.le,\nend\u27e9\n\nlemma lower_bounds_Ioo {a b : \u03b3} (hab : a < b) : lower_bounds (Ioo a b) = Iic a :=\n(is_glb_Ioo hab).lower_bounds_eq\n\nlemma is_glb_Ioc {a b : \u03b3} (hab : a < b) : is_glb (Ioc a b) a :=\n(is_glb_Ioo hab).of_subset_of_superset (is_glb_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self\n\nlemma lower_bound_Ioc {a b : \u03b3} (hab : a < b) : lower_bounds (Ioc a b) = Iic a :=\n(is_glb_Ioc hab).lower_bounds_eq\n\nend\n\nsection\n\nvariables [semilattice_inf \u03b3] [densely_ordered \u03b3]\n\nlemma is_lub_Ioo {a b : \u03b3} (hab : a < b) : is_lub (Ioo a b) b :=\nby simpa only [dual_Ioo] using is_glb_Ioo hab.dual\n\nlemma upper_bounds_Ioo {a b : \u03b3} (hab : a < b) : upper_bounds (Ioo a b) = Ici b :=\n(is_lub_Ioo hab).upper_bounds_eq\n\nlemma is_lub_Ico {a b : \u03b3} (hab : a < b) : is_lub (Ico a b) b :=\nby simpa only [dual_Ioc] using is_glb_Ioc hab.dual\n\nlemma upper_bounds_Ico {a b : \u03b3} (hab : a < b) : upper_bounds (Ico a b) = Ici b :=\n(is_lub_Ico hab).upper_bounds_eq\n\nend\n\nlemma bdd_below_iff_subset_Ici : bdd_below s \u2194 \u2203 a, s \u2286 Ici a := iff.rfl\n\nlemma bdd_above_iff_subset_Iic : bdd_above s \u2194 \u2203 a, s \u2286 Iic a := iff.rfl\n\nlemma bdd_below_bdd_above_iff_subset_Icc : bdd_below s \u2227 bdd_above s \u2194 \u2203 a b, s \u2286 Icc a b :=\nby simp only [Ici_inter_Iic.symm, subset_inter_iff, bdd_below_iff_subset_Ici,\n  bdd_above_iff_subset_Iic, exists_and_distrib_left, exists_and_distrib_right]\n\n/-!\n#### Univ\n-/\n\n@[simp] lemma is_greatest_univ_iff : is_greatest univ a \u2194 is_top a :=\nby simp [is_greatest, mem_upper_bounds, is_top]\n\nlemma is_greatest_univ [order_top \u03b1] : is_greatest (univ : set \u03b1) \u22a4 :=\nis_greatest_univ_iff.2 is_top_top\n\n@[simp] lemma order_top.upper_bounds_univ [partial_order \u03b3] [order_top \u03b3] :\n  upper_bounds (univ : set \u03b3) = {\u22a4} :=\nby rw [is_greatest_univ.upper_bounds_eq, Ici_top]\n\nlemma is_lub_univ [order_top \u03b1] : is_lub (univ : set \u03b1) \u22a4 := is_greatest_univ.is_lub\n\n@[simp] lemma order_bot.lower_bounds_univ [partial_order \u03b3] [order_bot \u03b3] :\n  lower_bounds (univ : set \u03b3) = {\u22a5} :=\n@order_top.upper_bounds_univ \u03b3\u1d52\u1d48 _ _\n\n@[simp] lemma is_least_univ_iff : is_least univ a \u2194 is_bot a := @is_greatest_univ_iff \u03b1\u1d52\u1d48 _ _\nlemma is_least_univ [order_bot \u03b1] : is_least (univ : set \u03b1) \u22a5 := @is_greatest_univ \u03b1\u1d52\u1d48 _ _\nlemma is_glb_univ [order_bot \u03b1] : is_glb (univ : set \u03b1) \u22a5 := is_least_univ.is_glb\n\n@[simp] lemma no_max_order.upper_bounds_univ [no_max_order \u03b1] : upper_bounds (univ : set \u03b1) = \u2205 :=\neq_empty_of_subset_empty $ \u03bb b hb, let \u27e8x, hx\u27e9 := exists_gt b in\nnot_le_of_lt hx (hb trivial)\n\n@[simp] lemma no_min_order.lower_bounds_univ [no_min_order \u03b1] : lower_bounds (univ : set \u03b1) = \u2205 :=\n@no_max_order.upper_bounds_univ \u03b1\u1d52\u1d48 _ _\n\n@[simp] lemma not_bdd_above_univ [no_max_order \u03b1] : \u00acbdd_above (univ : set \u03b1) :=\nby simp [bdd_above]\n\n@[simp] lemma not_bdd_below_univ [no_min_order \u03b1] : \u00acbdd_below (univ : set \u03b1) :=\n@not_bdd_above_univ \u03b1\u1d52\u1d48 _ _\n\n/-!\n#### Empty set\n-/\n\n@[simp] lemma upper_bounds_empty : upper_bounds (\u2205 : set \u03b1) = univ :=\nby simp only [upper_bounds, eq_univ_iff_forall, mem_set_of_eq, ball_empty_iff, forall_true_iff]\n\n@[simp] lemma lower_bounds_empty : lower_bounds (\u2205 : set \u03b1) = univ := @upper_bounds_empty \u03b1\u1d52\u1d48 _\n\n@[simp] lemma bdd_above_empty [nonempty \u03b1] : bdd_above (\u2205 : set \u03b1) :=\nby simp only [bdd_above, upper_bounds_empty, univ_nonempty]\n\n@[simp] lemma bdd_below_empty [nonempty \u03b1] : bdd_below (\u2205 : set \u03b1) :=\nby simp only [bdd_below, lower_bounds_empty, univ_nonempty]\n\n@[simp] lemma is_glb_empty_iff : is_glb \u2205 a \u2194 is_top a := by simp [is_glb]\n@[simp] lemma is_lub_empty_iff : is_lub \u2205 a \u2194 is_bot a := @is_glb_empty_iff \u03b1\u1d52\u1d48 _ _\n\nlemma is_glb_empty [order_top \u03b1] : is_glb \u2205 (\u22a4:\u03b1) := is_glb_empty_iff.2 is_top_top\nlemma is_lub_empty [order_bot \u03b1] : is_lub \u2205 (\u22a5:\u03b1) := @is_glb_empty \u03b1\u1d52\u1d48 _ _\n\nlemma is_lub.nonempty [no_min_order \u03b1] (hs : is_lub s a) : s.nonempty :=\nlet \u27e8a', ha'\u27e9 := exists_lt a in\nnonempty_iff_ne_empty.2 $ \u03bb h, not_le_of_lt ha' $ hs.right $ by simp only [h, upper_bounds_empty]\n\nlemma is_glb.nonempty [no_max_order \u03b1] (hs : is_glb s a) : s.nonempty := hs.dual.nonempty\n\nlemma nonempty_of_not_bdd_above [ha : nonempty \u03b1] (h : \u00acbdd_above s) : s.nonempty :=\nnonempty.elim ha $ \u03bb x, (not_bdd_above_iff'.1 h x).imp $ \u03bb a ha, ha.fst\n\nlemma nonempty_of_not_bdd_below [ha : nonempty \u03b1] (h : \u00acbdd_below s) : s.nonempty :=\n@nonempty_of_not_bdd_above \u03b1\u1d52\u1d48 _ _ _ h\n\n/-!\n#### insert\n-/\n\n/-- Adding a point to a set preserves its boundedness above. -/\n@[simp] lemma bdd_above_insert [semilattice_sup \u03b3] (a : \u03b3) {s : set \u03b3} :\n  bdd_above (insert a s) \u2194 bdd_above s :=\nby simp only [insert_eq, bdd_above_union, bdd_above_singleton, true_and]\n\nlemma bdd_above.insert [semilattice_sup \u03b3] (a : \u03b3) {s : set \u03b3} (hs : bdd_above s) :\n  bdd_above (insert a s) :=\n(bdd_above_insert a).2 hs\n\n/--Adding a point to a set preserves its boundedness below.-/\n@[simp] lemma bdd_below_insert [semilattice_inf \u03b3] (a : \u03b3) {s : set \u03b3} :\n  bdd_below (insert a s) \u2194 bdd_below s :=\nby simp only [insert_eq, bdd_below_union, bdd_below_singleton, true_and]\n\nlemma bdd_below.insert [semilattice_inf \u03b3] (a : \u03b3) {s : set \u03b3} (hs : bdd_below s) :\n  bdd_below (insert a s) :=\n(bdd_below_insert a).2 hs\n\nlemma is_lub.insert [semilattice_sup \u03b3] (a) {b} {s : set \u03b3} (hs : is_lub s b) :\n  is_lub (insert a s) (a \u2294 b) :=\nby { rw insert_eq, exact is_lub_singleton.union hs }\n\nlemma is_glb.insert [semilattice_inf \u03b3] (a) {b} {s : set \u03b3} (hs : is_glb s b) :\n  is_glb (insert a s) (a \u2293 b) :=\nby { rw insert_eq, exact is_glb_singleton.union hs }\n\nlemma is_greatest.insert [linear_order \u03b3] (a) {b} {s : set \u03b3} (hs : is_greatest s b) :\n  is_greatest (insert a s) (max a b) :=\nby { rw insert_eq, exact is_greatest_singleton.union hs }\n\nlemma is_least.insert [linear_order \u03b3] (a) {b} {s : set \u03b3} (hs : is_least s b) :\n  is_least (insert a s) (min a b) :=\nby { rw insert_eq, exact is_least_singleton.union hs }\n\n@[simp] lemma upper_bounds_insert (a : \u03b1) (s : set \u03b1) :\n  upper_bounds (insert a s) = Ici a \u2229 upper_bounds s :=\nby rw [insert_eq, upper_bounds_union, upper_bounds_singleton]\n\n@[simp] lemma lower_bounds_insert (a : \u03b1) (s : set \u03b1) :\n  lower_bounds (insert a s) = Iic a \u2229 lower_bounds s :=\nby rw [insert_eq, lower_bounds_union, lower_bounds_singleton]\n\n/-- When there is a global maximum, every set is bounded above. -/\n@[simp] protected lemma order_top.bdd_above [order_top \u03b1] (s : set \u03b1) : bdd_above s :=\n\u27e8\u22a4, \u03bb a ha, order_top.le_top a\u27e9\n\n/-- When there is a global minimum, every set is bounded below. -/\n@[simp] protected lemma order_bot.bdd_below [order_bot \u03b1] (s : set \u03b1) : bdd_below s :=\n\u27e8\u22a5, \u03bb a ha, order_bot.bot_le a\u27e9\n\n/-!\n#### Pair\n-/\n\nlemma is_lub_pair [semilattice_sup \u03b3] {a b : \u03b3} : is_lub {a, b} (a \u2294 b) :=\nis_lub_singleton.insert _\n\nlemma is_glb_pair [semilattice_inf \u03b3] {a b : \u03b3} : is_glb {a, b} (a \u2293 b) :=\nis_glb_singleton.insert _\n\nlemma is_least_pair [linear_order \u03b3] {a b : \u03b3} : is_least {a, b} (min a b) :=\nis_least_singleton.insert _\n\nlemma is_greatest_pair [linear_order \u03b3] {a b : \u03b3} : is_greatest {a, b} (max a b) :=\nis_greatest_singleton.insert _\n\n/-!\n#### Lower/upper bounds\n-/\n\n@[simp] lemma is_lub_lower_bounds : is_lub (lower_bounds s) a \u2194 is_glb s a :=\n\u27e8\u03bb H, \u27e8\u03bb x hx, H.2 $ subset_upper_bounds_lower_bounds s hx, H.1\u27e9, is_greatest.is_lub\u27e9\n\n@[simp] lemma is_glb_upper_bounds : is_glb (upper_bounds s) a \u2194 is_lub s a :=\n@is_lub_lower_bounds \u03b1\u1d52\u1d48 _ _ _\n\nend\n\n/-!\n### (In)equalities with the least upper bound and the greatest lower bound\n-/\n\nsection preorder\nvariables [preorder \u03b1] {s : set \u03b1} {a b : \u03b1}\n\nlemma lower_bounds_le_upper_bounds (ha : a \u2208 lower_bounds s) (hb : b \u2208 upper_bounds s) :\n  s.nonempty \u2192 a \u2264 b\n| \u27e8c, hc\u27e9 := le_trans (ha hc) (hb hc)\n\nlemma is_glb_le_is_lub (ha : is_glb s a) (hb : is_lub s b) (hs : s.nonempty) : a \u2264 b :=\nlower_bounds_le_upper_bounds ha.1 hb.1 hs\n\nlemma is_lub_lt_iff (ha : is_lub s a) : a < b \u2194 \u2203 c \u2208 upper_bounds s, c < b :=\n\u27e8\u03bb hb, \u27e8a, ha.1, hb\u27e9, \u03bb \u27e8c, hcs, hcb\u27e9, lt_of_le_of_lt (ha.2 hcs) hcb\u27e9\n\nlemma lt_is_glb_iff (ha : is_glb s a) : b < a \u2194 \u2203 c \u2208 lower_bounds s, b < c := is_lub_lt_iff ha.dual\n\nlemma le_of_is_lub_le_is_glb {x y} (ha : is_glb s a) (hb : is_lub s b) (hab : b \u2264 a)\n  (hx : x \u2208 s) (hy : y \u2208 s) : x \u2264 y :=\ncalc x \u2264 b : hb.1 hx\n   ... \u2264 a : hab\n   ... \u2264 y : ha.1 hy\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] {s : set \u03b1} {a b : \u03b1}\n\nlemma is_least.unique (Ha : is_least s a) (Hb : is_least s b) : a = b :=\nle_antisymm (Ha.right Hb.left) (Hb.right Ha.left)\n\nlemma is_least.is_least_iff_eq (Ha : is_least s a) : is_least s b \u2194 a = b :=\niff.intro Ha.unique (\u03bb h, h \u25b8 Ha)\n\nlemma is_greatest.unique (Ha : is_greatest s a) (Hb : is_greatest s b) : a = b :=\nle_antisymm (Hb.right Ha.left) (Ha.right Hb.left)\n\nlemma is_greatest.is_greatest_iff_eq (Ha : is_greatest s a) : is_greatest s b \u2194 a = b :=\niff.intro Ha.unique (\u03bb h, h \u25b8 Ha)\n\nlemma is_lub.unique (Ha : is_lub s a) (Hb : is_lub s b) : a = b :=\nHa.unique Hb\n\nlemma is_glb.unique (Ha : is_glb s a) (Hb : is_glb s b) : a = b :=\nHa.unique Hb\n\nlemma set.subsingleton_of_is_lub_le_is_glb (Ha : is_glb s a) (Hb : is_lub s b) (hab : b \u2264 a) :\n  s.subsingleton :=\n\u03bb x hx y hy, le_antisymm (le_of_is_lub_le_is_glb Ha Hb hab hx hy)\n  (le_of_is_lub_le_is_glb Ha Hb hab hy hx)\n\nlemma is_glb_lt_is_lub_of_ne (Ha : is_glb s a) (Hb : is_lub s b)\n  {x y} (Hx : x \u2208 s) (Hy : y \u2208 s) (Hxy : x \u2260 y) :\n  a < b :=\nlt_iff_le_not_le.2\n  \u27e8lower_bounds_le_upper_bounds Ha.1 Hb.1 \u27e8x, Hx\u27e9,\n    \u03bb hab, Hxy $ set.subsingleton_of_is_lub_le_is_glb Ha Hb hab Hx Hy\u27e9\n\nend partial_order\n\nsection linear_order\nvariables [linear_order \u03b1] {s : set \u03b1} {a b : \u03b1}\n\nlemma lt_is_lub_iff (h : is_lub s a) : b < a \u2194 \u2203 c \u2208 s, b < c :=\nby simp only [\u2190 not_le, is_lub_le_iff h, mem_upper_bounds, not_forall]\n\nlemma is_glb_lt_iff (h : is_glb s a) : a < b \u2194 \u2203 c \u2208 s, c < b := lt_is_lub_iff h.dual\n\nlemma is_lub.exists_between (h : is_lub s a) (hb : b < a) :\n  \u2203 c \u2208 s, b < c \u2227 c \u2264 a :=\nlet \u27e8c, hcs, hbc\u27e9 := (lt_is_lub_iff h).1 hb in \u27e8c, hcs, hbc, h.1 hcs\u27e9\n\nlemma is_lub.exists_between' (h : is_lub s a) (h' : a \u2209 s) (hb : b < a) :\n  \u2203 c \u2208 s, b < c \u2227 c < a :=\nlet \u27e8c, hcs, hbc, hca\u27e9 := h.exists_between hb\nin \u27e8c, hcs, hbc, hca.lt_of_ne $ \u03bb hac, h' $ hac \u25b8 hcs\u27e9\n\nlemma is_glb.exists_between (h : is_glb s a) (hb : a < b) :\n  \u2203 c \u2208 s, a \u2264 c \u2227 c < b :=\nlet \u27e8c, hcs, hbc\u27e9 := (is_glb_lt_iff h).1 hb in \u27e8c, hcs, h.1 hcs, hbc\u27e9\n\nlemma is_glb.exists_between' (h : is_glb s a) (h' : a \u2209 s) (hb : a < b) :\n  \u2203 c \u2208 s, a < c \u2227 c < b :=\nlet \u27e8c, hcs, hac, hcb\u27e9 := h.exists_between hb\nin \u27e8c, hcs, hac.lt_of_ne $ \u03bb hac, h' $ hac.symm \u25b8 hcs, hcb\u27e9\n\nend linear_order\n\n\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\nnamespace monotone_on\n\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : set \u03b1}\n  (Hf : monotone_on f t) {a : \u03b1} (Hst : s \u2286 t)\ninclude Hf\n\nlemma mem_upper_bounds_image (Has : a \u2208 upper_bounds s) (Hat : a \u2208 t) :\n  f a \u2208 upper_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf (Hst H) Hat (Has H))\n\nlemma mem_upper_bounds_image_self : a \u2208 upper_bounds t \u2192 a \u2208 t \u2192 f a \u2208 upper_bounds (f '' t) :=\nHf.mem_upper_bounds_image subset_rfl\n\nlemma mem_lower_bounds_image (Has : a \u2208 lower_bounds s) (Hat : a \u2208 t) :\n  f a \u2208 lower_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf Hat (Hst H) (Has H))\n\nlemma mem_lower_bounds_image_self : a \u2208 lower_bounds t \u2192 a \u2208 t \u2192 f a \u2208 lower_bounds (f '' t) :=\nHf.mem_lower_bounds_image subset_rfl\n\nlemma image_upper_bounds_subset_upper_bounds_image (Hst : s \u2286 t) :\n  f '' (upper_bounds s \u2229 t) \u2286 upper_bounds (f '' s) :=\nby { rintro _ \u27e8a, ha, rfl\u27e9, exact Hf.mem_upper_bounds_image Hst ha.1 ha.2 }\n\nlemma image_lower_bounds_subset_lower_bounds_image :\n  f '' (lower_bounds s \u2229 t) \u2286 lower_bounds (f '' s) :=\nHf.dual.image_upper_bounds_subset_upper_bounds_image Hst\n\n/-- The image under a monotone function on a set `t` of a subset which has an upper bound in `t`\n  is bounded above. -/\nlemma map_bdd_above : (upper_bounds s \u2229 t).nonempty \u2192 bdd_above (f '' s) :=\n\u03bb \u27e8C, hs, ht\u27e9, \u27e8f C, Hf.mem_upper_bounds_image Hst hs ht\u27e9\n\n/-- The image under a monotone function on a set `t` of a subset which has a lower bound in `t`\n  is bounded below. -/\nlemma map_bdd_below : (lower_bounds s \u2229 t).nonempty \u2192 bdd_below (f '' s) :=\n\u03bb \u27e8C, hs, ht\u27e9, \u27e8f C, Hf.mem_lower_bounds_image Hst hs ht\u27e9\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\nlemma map_is_least (Ha : is_least t a) : is_least (f '' t) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image_self Ha.2 Ha.1\u27e9\n\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\nlemma map_is_greatest (Ha : is_greatest t a) : is_greatest (f '' t) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image_self Ha.2 Ha.1\u27e9\n\nend monotone_on\n\nnamespace antitone_on\n\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : set \u03b1}\n  (Hf : antitone_on f t) {a : \u03b1} (Hst : s \u2286 t)\ninclude Hf\n\nlemma mem_upper_bounds_image (Has : a \u2208 lower_bounds s) : a \u2208 t \u2192 f a \u2208 upper_bounds (f '' s) :=\nHf.dual_right.mem_lower_bounds_image Hst Has\n\nlemma mem_upper_bounds_image_self : a \u2208 lower_bounds t \u2192 a \u2208 t \u2192 f a \u2208 upper_bounds (f '' t) :=\nHf.dual_right.mem_lower_bounds_image_self\n\nlemma mem_lower_bounds_image : a \u2208 upper_bounds s \u2192 a \u2208 t \u2192 f a \u2208 lower_bounds (f '' s) :=\nHf.dual_right.mem_upper_bounds_image Hst\n\nlemma mem_lower_bounds_image_self : a \u2208 upper_bounds t \u2192 a \u2208 t \u2192 f a \u2208 lower_bounds (f '' t) :=\nHf.dual_right.mem_upper_bounds_image_self\n\nlemma image_lower_bounds_subset_upper_bounds_image :\n  f '' (lower_bounds s \u2229 t) \u2286 upper_bounds (f '' s) :=\nHf.dual_right.image_lower_bounds_subset_lower_bounds_image Hst\n\nlemma image_upper_bounds_subset_lower_bounds_image :\n  f '' (upper_bounds s \u2229 t) \u2286 lower_bounds (f '' s) :=\nHf.dual_right.image_upper_bounds_subset_upper_bounds_image Hst\n\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\nlemma map_bdd_above : (upper_bounds s \u2229 t).nonempty \u2192 bdd_below (f '' s) :=\nHf.dual_right.map_bdd_above Hst\n\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\nlemma map_bdd_below : (lower_bounds s \u2229 t).nonempty \u2192 bdd_above (f '' s) :=\nHf.dual_right.map_bdd_below Hst\n\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\nlemma map_is_greatest : is_greatest t a \u2192 is_least (f '' t) (f a) :=\nHf.dual_right.map_is_greatest\n\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\nlemma map_is_least : is_least t a \u2192 is_greatest (f '' t) (f a) :=\nHf.dual_right.map_is_least\n\nend antitone_on\n\nnamespace monotone\n\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (Hf : monotone f) {a : \u03b1} {s : set \u03b1}\ninclude Hf\n\nlemma mem_upper_bounds_image (Ha : a \u2208 upper_bounds s) : f a \u2208 upper_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf (Ha H))\n\nlemma mem_lower_bounds_image (Ha : a \u2208 lower_bounds s) : f a \u2208 lower_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf (Ha H))\n\nlemma image_upper_bounds_subset_upper_bounds_image : f '' upper_bounds s \u2286 upper_bounds (f '' s) :=\nby { rintro _ \u27e8a, ha, rfl\u27e9, exact Hf.mem_upper_bounds_image ha }\n\nlemma image_lower_bounds_subset_lower_bounds_image : f '' lower_bounds s \u2286 lower_bounds (f '' s) :=\nHf.dual.image_upper_bounds_subset_upper_bounds_image\n\n/-- The image under a monotone function of a set which is bounded above is bounded above. See also\n`bdd_above.image2`. -/\nlemma map_bdd_above : bdd_above s \u2192 bdd_above (f '' s)\n| \u27e8C, hC\u27e9 := \u27e8f C, Hf.mem_upper_bounds_image hC\u27e9\n\n/-- The image under a monotone function of a set which is bounded below is bounded below. See also\n`bdd_below.image2`. -/\nlemma map_bdd_below : bdd_below s \u2192 bdd_below (f '' s)\n| \u27e8C, hC\u27e9 := \u27e8f C, Hf.mem_lower_bounds_image hC\u27e9\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\nlemma map_is_least (Ha : is_least s a) : is_least (f '' s) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image Ha.2\u27e9\n\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\nlemma map_is_greatest (Ha : is_greatest s a) : is_greatest (f '' s) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image Ha.2\u27e9\n\nend monotone\n\nnamespace antitone\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : antitone f) {a : \u03b1} {s : set \u03b1}\n\nlemma mem_upper_bounds_image : a \u2208 lower_bounds s \u2192 f a \u2208 upper_bounds (f '' s) :=\nhf.dual_right.mem_lower_bounds_image\n\nlemma mem_lower_bounds_image : a \u2208 upper_bounds s \u2192 f a \u2208 lower_bounds (f '' s) :=\nhf.dual_right.mem_upper_bounds_image\n\nlemma image_lower_bounds_subset_upper_bounds_image : f '' lower_bounds s \u2286 upper_bounds (f '' s) :=\nhf.dual_right.image_lower_bounds_subset_lower_bounds_image\n\nlemma image_upper_bounds_subset_lower_bounds_image : f '' upper_bounds s \u2286 lower_bounds (f '' s) :=\nhf.dual_right.image_upper_bounds_subset_upper_bounds_image\n\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\nlemma map_bdd_above : bdd_above s \u2192 bdd_below (f '' s) :=\nhf.dual_right.map_bdd_above\n\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\nlemma map_bdd_below : bdd_below s \u2192 bdd_above (f '' s) :=\nhf.dual_right.map_bdd_below\n\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\nlemma map_is_greatest : is_greatest s a \u2192 is_least (f '' s) (f a) :=\nhf.dual_right.map_is_greatest\n\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\nlemma map_is_least : is_least s a \u2192 is_greatest (f '' s) (f a) :=\nhf.dual_right.map_is_least\n\nend antitone\n\nsection image2\nvariables [preorder \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {s : set \u03b1} {t : set \u03b2} {a : \u03b1}\n  {b : \u03b2}\n\nsection monotone_monotone\nvariables (h\u2080 : \u2200 b, monotone (swap f b)) (h\u2081 : \u2200 a, monotone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2 (ha : a \u2208 upper_bounds s) (hb : b \u2208 upper_bounds t) :\n  f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2 (ha : a \u2208 lower_bounds s) (hb : b \u2208 lower_bounds t) :\n  f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_upper_bounds_upper_bounds_subset :\n  image2 f (upper_bounds s) (upper_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_upper_bounds_image2 h\u2080 h\u2081 ha hb }\n\nlemma image2_lower_bounds_lower_bounds_subset :\n  image2 f (lower_bounds s) (lower_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_lower_bounds_image2 h\u2080 h\u2081 ha hb }\n\n/-- See also `monotone.map_bdd_above`. -/\nlemma bdd_above.image2 : bdd_above s \u2192 bdd_above t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, exact \u27e8f a b, mem_upper_bounds_image2 h\u2080 h\u2081 ha hb\u27e9 }\n\n/-- See also `monotone.map_bdd_below`. -/\nlemma bdd_below.image2 : bdd_below s \u2192 bdd_below t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, exact \u27e8f a b, mem_lower_bounds_image2 h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_greatest.image2 (ha : is_greatest s a) (hb : is_greatest t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_least.image2 (ha : is_least s a) (hb : is_least t b) : is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend monotone_monotone\n\nsection monotone_antitone\nvariables (h\u2080 : \u2200 b, monotone (swap f b)) (h\u2081 : \u2200 a, antitone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds (ha : a \u2208 upper_bounds s)\n  (hb : b \u2208 lower_bounds t) : f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds (ha : a \u2208 lower_bounds s)\n  (hb : b \u2208 upper_bounds t) : f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_upper_bounds_lower_bounds_subset_upper_bounds_image2 :\n  image2 f (upper_bounds s) (lower_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb }\n\nlemma image2_lower_bounds_upper_bounds_subset_lower_bounds_image2 :\n  image2 f (lower_bounds s) (upper_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb }\n\nlemma bdd_above.bdd_above_image2_of_bdd_below :\n  bdd_above s \u2192 bdd_below t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma bdd_below.bdd_below_image2_of_bdd_above :\n  bdd_below s \u2192 bdd_above t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_greatest.is_greatest_image2_of_is_least (ha : is_greatest s a) (hb : is_least t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_least.is_least_image2_of_is_greatest (ha : is_least s a) (hb : is_greatest t b) :\n  is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend monotone_antitone\n\nsection antitone_antitone\nvariables (h\u2080 : \u2200 b, antitone (swap f b)) (h\u2081 : \u2200 a, antitone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2_of_mem_lower_bounds (ha : a \u2208 lower_bounds s)\n  (hb : b \u2208 lower_bounds t) :\n  f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2_of_mem_upper_bounds (ha : a \u2208 upper_bounds s)\n  (hb : b \u2208 upper_bounds t) :\n  f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_upper_bounds_upper_bounds_subset_upper_bounds_image2 :\n  image2 f (lower_bounds s) (lower_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_upper_bounds_image2_of_mem_lower_bounds h\u2080 h\u2081 ha hb }\n\nlemma image2_lower_bounds_lower_bounds_subset_lower_bounds_image2 :\n  image2 f (upper_bounds s) (upper_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_lower_bounds_image2_of_mem_upper_bounds h\u2080 h\u2081 ha hb }\n\nlemma bdd_below.image2_bdd_above : bdd_below s \u2192 bdd_below t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_upper_bounds_image2_of_mem_lower_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma bdd_above.image2_bdd_below : bdd_above s \u2192 bdd_above t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_lower_bounds_image2_of_mem_upper_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_least.is_greatest_image2 (ha : is_least s a) (hb : is_least t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2_of_mem_lower_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_greatest.is_least_image2 (ha : is_greatest s a) (hb : is_greatest t b) :\n  is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2_of_mem_upper_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend antitone_antitone\n\nsection antitone_monotone\nvariables (h\u2080 : \u2200 b, antitone (swap f b)) (h\u2081 : \u2200 a, monotone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds (ha : a \u2208 lower_bounds s)\n  (hb : b \u2208 upper_bounds t) : f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds (ha : a \u2208 upper_bounds s)\n  (hb : b \u2208 lower_bounds t) : f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_lower_bounds_upper_bounds_subset_upper_bounds_image2 :\n  image2 f (lower_bounds s) (upper_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb }\n\nlemma image2_upper_bounds_lower_bounds_subset_lower_bounds_image2 :\n  image2 f (upper_bounds s) (lower_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb }\n\nlemma bdd_below.bdd_above_image2_of_bdd_above :\n  bdd_below s \u2192 bdd_above t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma bdd_above.bdd_below_image2_of_bdd_above :\n  bdd_above s \u2192 bdd_below t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_least.is_greatest_image2_of_is_greatest (ha : is_least s a) (hb : is_greatest t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_greatest.is_least_image2_of_is_least (ha : is_greatest s a) (hb : is_least t b) :\n  is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend antitone_monotone\nend image2\n\nlemma is_glb.of_image [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n  {s : set \u03b1} {x : \u03b1} (hx : is_glb (f '' s) (f x)) :\n  is_glb s x :=\n\u27e8\u03bb y hy, hf.1 $ hx.1 $ mem_image_of_mem _ hy,\n  \u03bb y hy, hf.1 $ hx.2 $ monotone.mem_lower_bounds_image (\u03bb x y, hf.2) hy\u27e9\n\nlemma is_lub.of_image [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n  {s : set \u03b1} {x : \u03b1} (hx : is_lub (f '' s) (f x)) :\n  is_lub s x :=\n@is_glb.of_image \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ f (\u03bb x y, hf) _ _ hx\n\nlemma is_lub_pi {\u03c0 : \u03b1 \u2192 Type*} [\u03a0 a, preorder (\u03c0 a)] {s : set (\u03a0 a, \u03c0 a)} {f : \u03a0 a, \u03c0 a} :\n  is_lub s f \u2194 \u2200 a, is_lub (function.eval a '' s) (f a) :=\nbegin\n  classical,\n  refine \u27e8\u03bb H a, \u27e8(function.monotone_eval a).mem_upper_bounds_image H.1, \u03bb b hb, _\u27e9, \u03bb H, \u27e8_, _\u27e9\u27e9,\n  { suffices : function.update f a b \u2208 upper_bounds s,\n      from function.update_same a b f \u25b8 H.2 this a,\n    refine \u03bb g hg, le_update_iff.2 \u27e8hb $ mem_image_of_mem _ hg, \u03bb i hi, H.1 hg i\u27e9 },\n  { exact \u03bb g hg a, (H a).1 (mem_image_of_mem _ hg) },\n  { exact \u03bb g hg a, (H a).2 ((function.monotone_eval a).mem_upper_bounds_image hg) }\nend\n\nlemma is_glb_pi {\u03c0 : \u03b1 \u2192 Type*} [\u03a0 a, preorder (\u03c0 a)] {s : set (\u03a0 a, \u03c0 a)} {f : \u03a0 a, \u03c0 a} :\n  is_glb s f \u2194 \u2200 a, is_glb (function.eval a '' s) (f a) :=\n@is_lub_pi \u03b1 (\u03bb a, (\u03c0 a)\u1d52\u1d48) _ s f\n\nlemma is_lub_prod [preorder \u03b1] [preorder \u03b2] {s : set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n  is_lub s p \u2194 is_lub (prod.fst '' s) p.1 \u2227 is_lub (prod.snd '' s) p.2 :=\nbegin\n  refine \u27e8\u03bb H, \u27e8\u27e8monotone_fst.mem_upper_bounds_image H.1, \u03bb a ha, _\u27e9,\n    \u27e8monotone_snd.mem_upper_bounds_image H.1, \u03bb a ha, _\u27e9\u27e9, \u03bb H, \u27e8_, _\u27e9\u27e9,\n  { suffices : (a, p.2) \u2208 upper_bounds s, from (H.2 this).1,\n    exact \u03bb q hq, \u27e8ha $ mem_image_of_mem _ hq, (H.1 hq).2\u27e9 },\n  { suffices : (p.1, a) \u2208 upper_bounds s, from (H.2 this).2,\n    exact \u03bb q hq, \u27e8(H.1 hq).1, ha $ mem_image_of_mem _ hq\u27e9 },\n  { exact \u03bb q hq, \u27e8H.1.1 $ mem_image_of_mem _ hq, H.2.1 $ mem_image_of_mem _ hq\u27e9 },\n  { exact \u03bb q hq, \u27e8H.1.2 $ monotone_fst.mem_upper_bounds_image hq,\n      H.2.2 $ monotone_snd.mem_upper_bounds_image hq\u27e9 }\nend\n\nlemma is_glb_prod [preorder \u03b1] [preorder \u03b2] {s : set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n  is_glb s p \u2194 is_glb (prod.fst '' s) p.1 \u2227 is_glb (prod.snd '' s) p.2 :=\n@is_lub_prod \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/bounds/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7322826519197446}}
{"text": "/-\nCopyright (c) 2020 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bryan Gin-ge Chen, Kevin Lacker\n\n! This file was ported from Lean 3 source module algebra.group_power.identities\n! leanprover-community/mathlib commit c4658a649d216f57e99621708b09dcb3dcccbd23\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Tactic.Ring\n\n/-!\n# Identities\n\nThis file contains some \"named\" commutative ring identities.\n-/\n\n\nvariable {R : Type _} [CommRing R] {a b x\u2081 x\u2082 x\u2083 x\u2084 x\u2085 x\u2086 x\u2087 x\u2088 y\u2081 y\u2082 y\u2083 y\u2084 y\u2085 y\u2086 y\u2087 y\u2088 n : R}\n\n/-- Brahmagupta-Fibonacci identity or Diophantus identity, see\n<https://en.wikipedia.org/wiki/Brahmagupta%E2%80%93Fibonacci_identity>.\n\nThis sign choice here corresponds to the signs obtained by multiplying two complex numbers.\n-/\ntheorem sq_add_sq_mul_sq_add_sq :\n    (x\u2081 ^ 2 + x\u2082 ^ 2) * (y\u2081 ^ 2 + y\u2082 ^ 2) = (x\u2081 * y\u2081 - x\u2082 * y\u2082) ^ 2 + (x\u2081 * y\u2082 + x\u2082 * y\u2081) ^ 2 := by\n  ring\n#align sq_add_sq_mul_sq_add_sq sq_add_sq_mul_sq_add_sq\n\n/-- Brahmagupta's identity, see <https://en.wikipedia.org/wiki/Brahmagupta%27s_identity>\n-/\ntheorem sq_add_mul_sq_mul_sq_add_mul_sq :\n    (x\u2081 ^ 2 + n * x\u2082 ^ 2) * (y\u2081 ^ 2 + n * y\u2082 ^ 2) =\n    (x\u2081 * y\u2081 - n * x\u2082 * y\u2082) ^ 2 + n * (x\u2081 * y\u2082 + x\u2082 * y\u2081) ^ 2 := by\n  ring\n#align sq_add_mul_sq_mul_sq_add_mul_sq sq_add_mul_sq_mul_sq_add_mul_sq\n\n/-- Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>.\n-/\ntheorem pow_four_add_four_mul_pow_four :\n    a ^ 4 + 4 * b ^ 4 = ((a - b) ^ 2 + b ^ 2) * ((a + b) ^ 2 + b ^ 2) := by\n  ring\n#align pow_four_add_four_mul_pow_four pow_four_add_four_mul_pow_four\n\n/-- Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>.\n-/\ntheorem pow_four_add_four_mul_pow_four' :\n    a ^ 4 + 4 * b ^ 4 = (a ^ 2 - 2 * a * b + 2 * b ^ 2) * (a ^ 2 + 2 * a * b + 2 * b ^ 2) := by\n  ring\n#align pow_four_add_four_mul_pow_four' pow_four_add_four_mul_pow_four'\n\n/-- Euler's four-square identity, see <https://en.wikipedia.org/wiki/Euler%27s_four-square_identity>.\n\nThis sign choice here corresponds to the signs obtained by multiplying two quaternions.\n-/\ntheorem sum_four_sq_mul_sum_four_sq :\n    (x\u2081 ^ 2 + x\u2082 ^ 2 + x\u2083 ^ 2 + x\u2084 ^ 2) * (y\u2081 ^ 2 + y\u2082 ^ 2 + y\u2083 ^ 2 + y\u2084 ^ 2) =\n      (x\u2081 * y\u2081 - x\u2082 * y\u2082 - x\u2083 * y\u2083 - x\u2084 * y\u2084) ^ 2 + (x\u2081 * y\u2082 + x\u2082 * y\u2081 + x\u2083 * y\u2084 - x\u2084 * y\u2083) ^ 2 +\n          (x\u2081 * y\u2083 - x\u2082 * y\u2084 + x\u2083 * y\u2081 + x\u2084 * y\u2082) ^ 2 +\n        (x\u2081 * y\u2084 + x\u2082 * y\u2083 - x\u2083 * y\u2082 + x\u2084 * y\u2081) ^ 2 :=\n  by ring\n#align sum_four_sq_mul_sum_four_sq sum_four_sq_mul_sum_four_sq\n\n/-- Degen's eight squares identity, see <https://en.wikipedia.org/wiki/Degen%27s_eight-square_identity>.\n\nThis sign choice here corresponds to the signs obtained by multiplying two octonions.\n-/\ntheorem sum_eight_sq_mul_sum_eight_sq :\n    (x\u2081 ^ 2 + x\u2082 ^ 2 + x\u2083 ^ 2 + x\u2084 ^ 2 + x\u2085 ^ 2 + x\u2086 ^ 2 + x\u2087 ^ 2 + x\u2088 ^ 2) *\n      (y\u2081 ^ 2 + y\u2082 ^ 2 + y\u2083 ^ 2 + y\u2084 ^ 2 + y\u2085 ^ 2 + y\u2086 ^ 2 + y\u2087 ^ 2 + y\u2088 ^ 2) =\n    (x\u2081 * y\u2081 - x\u2082 * y\u2082 - x\u2083 * y\u2083 - x\u2084 * y\u2084 - x\u2085 * y\u2085 - x\u2086 * y\u2086 - x\u2087 * y\u2087 - x\u2088 * y\u2088) ^ 2 +\n      (x\u2081 * y\u2082 + x\u2082 * y\u2081 + x\u2083 * y\u2084 - x\u2084 * y\u2083 + x\u2085 * y\u2086 - x\u2086 * y\u2085 - x\u2087 * y\u2088 + x\u2088 * y\u2087) ^ 2 +\n      (x\u2081 * y\u2083 - x\u2082 * y\u2084 + x\u2083 * y\u2081 + x\u2084 * y\u2082 + x\u2085 * y\u2087 + x\u2086 * y\u2088 - x\u2087 * y\u2085 - x\u2088 * y\u2086) ^ 2 +\n      (x\u2081 * y\u2084 + x\u2082 * y\u2083 - x\u2083 * y\u2082 + x\u2084 * y\u2081 + x\u2085 * y\u2088 - x\u2086 * y\u2087 + x\u2087 * y\u2086 - x\u2088 * y\u2085) ^ 2 +\n      (x\u2081 * y\u2085 - x\u2082 * y\u2086 - x\u2083 * y\u2087 - x\u2084 * y\u2088 + x\u2085 * y\u2081 + x\u2086 * y\u2082 + x\u2087 * y\u2083 + x\u2088 * y\u2084) ^ 2 +\n      (x\u2081 * y\u2086 + x\u2082 * y\u2085 - x\u2083 * y\u2088 + x\u2084 * y\u2087 - x\u2085 * y\u2082 + x\u2086 * y\u2081 - x\u2087 * y\u2084 + x\u2088 * y\u2083) ^ 2 +\n      (x\u2081 * y\u2087 + x\u2082 * y\u2088 + x\u2083 * y\u2085 - x\u2084 * y\u2086 - x\u2085 * y\u2083 + x\u2086 * y\u2084 + x\u2087 * y\u2081 - x\u2088 * y\u2082) ^ 2 +\n      (x\u2081 * y\u2088 - x\u2082 * y\u2087 + x\u2083 * y\u2086 + x\u2084 * y\u2085 - x\u2085 * y\u2084 - x\u2086 * y\u2083 + x\u2087 * y\u2082 + x\u2088 * y\u2081) ^ 2 := by\n  ring\n#align sum_eight_sq_mul_sum_eight_sq sum_eight_sq_mul_sum_eight_sq\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/GroupPower/Identities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973294, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7322711833477543}}
{"text": "open classical\n\ntheorem Ex007(a b : Prop): (( a \u2192 b) \u2192 a) \u2192 a := \nassume H1:( a \u2192 b) \u2192 a,\n  have A:\u00ac\u00aca,from not.intro \n  (\n    assume H2:\u00aca,\n    have B:a, from H1 \n      (\n        assume H3:a,\n        show b, from absurd H3 H2\n      ),\n    show false, from H2 B\n  ),\n  by_contradiction\n  (\n    assume C:\u00aca,\n    show false, from A C\n  )\n", "meta": {"author": "SvenWille", "repo": "LeanLogicExercises", "sha": "2dbc920feadd63bbc50f87e69646c0081db26eba", "save_path": "github-repos/lean/SvenWille-LeanLogicExercises", "path": "github-repos/lean/SvenWille-LeanLogicExercises/LeanLogicExercises-2dbc920feadd63bbc50f87e69646c0081db26eba/src/propLogic/Ex007.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.732271181232315}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport analysis.calculus.parametric_integral\n\n/-\n\n# Basic calculus\n\nLet's figure out how to do differentiability in Lean together (because as I'm writing this\nI have very little clue :-/\n\nsection differentiability_in_general\n\n-- OK so this seems to be how to say a function is differentiable:\n\n-- these variables will only live in this section\n-- Let \ud835\udd5c be a field equipped with a non-trivial norm (e.g. \u211d)\nvariables (\ud835\udd5c : Type) [nontrivially_normed_field \ud835\udd5c] \n\n-- Let `E` be a \ud835\udd5c-vector space with a norm (e.g. \u211d or \u211d\u00b2)\nvariables (E : Type) [normed_add_comm_group E] [normed_space \ud835\udd5c E]\n\n-- and let `F` be another one\nvariables (F : Type) [normed_add_comm_group F] [normed_space \ud835\udd5c F]\n\n-- Then it makes sense to say that a function `f : E \u2192 F` is differentiable\nvariable (f : E \u2192 F)\n\n-- This is the true-false statement that `f` is differentiable.\nexample : Prop := differentiable \ud835\udd5c f\n\n-- You can also ask that `f` is differentiable at `e : E`\n\nexample (e : E) : Prop := differentiable_at \ud835\udd5c f e\n\n-- Here's how you say \"`f` is continuously differentiable 37 times\"\n-- (i.e. you can differentiate f 37 times and when you're done the answer is continuous\n-- but might not be differentiable)\n\nexample : Prop := cont_diff \ud835\udd5c 37 f\n\n-- Here's how you say \"`f` is smooth, i.e. infinitely differentiable\"\n\nexample : Prop := cont_diff \ud835\udd5c \u22a4 f\n\n-- That's `\u22a4` as in \"the top element of a lattice\" as in `+\u221e`, not `T` as in \"the letter T\".\n-- Indeed, `cont_diff \ud835\udd5c` takes an element of `\u2115\u221e`.\n\nend differentiability_in_general\n\n-- Let's now just assume `\ud835\udd5c = \u211d`; then `E` and `F` can be `\u211d` or `\u2102` or `\u211d \u00d7 \u211d` or `fin n \u2192 \u211d` (the\n-- way we say `\u211d\u207f` in mathlib) or ...\n\nopen real -- because there is `real.cos` and `complex.cos`, \n\n-- This says \"the cos(sin(x))*exp(x) is differentiable\"\nexample : differentiable \u211d (\u03bb x, cos (sin x) * exp x) :=\nbegin\n  apply differentiable.mul,\n  { -- \u22a2 differentiable \u211d (\u03bb (y : \u211d), cos (sin y))\n    apply differentiable.comp,\n    { exact differentiable_cos, },\n    { exact differentiable_sin, }, },\n  { exact differentiable_exp },\nend\n\n-- Alternative approach:\nexample : differentiable \u211d (\u03bb x, cos (sin x) * exp x) :=\nbegin\n  simp, -- I am a bit freaked out that this works.\nend\n\n-- I am less freaked out about this though.\nexample (x : \u211d) : deriv (\u03bb x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=\nby { simp, ring }\n\n-- Try this one:\nexample (a : \u211d) (x : \u211d) : differentiable_at \u211d (\u03bb (y : \u211d), exp (-(a * y ^ 2))) x :=\nbegin\n  apply differentiable_at.comp,\n  { apply differentiable_at.exp,\n    apply differentiable_at_id', },\n  { apply differentiable_at.neg,\n    apply differentiable_at.mul,\n    { apply differentiable_at_const, },\n    { apply differentiable_at.pow,\n      apply differentiable_at_id', } },\nend\n\nexample (a : \u211d) (x : \u211d) : differentiable_at \u211d (\u03bb (y : \u211d), exp (-(a * y ^ 2))) x :=\ndifferentiable_at_id'.exp.comp x $ differentiable_at.neg $ (differentiable_at_const a).mul $ differentiable_at_id'.pow 2\n\nexample (a : \u211d) (x : \u211d) : differentiable_at \u211d (\u03bb (y : \u211d), exp (-(a * y ^ 2))) x :=\nby simp\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section17curves_and_surfaces/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7321788486531864}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n-/\nimport data.nat.gcd.basic\nimport algebra.big_operators.basic\n\n/-! # Lemmas about coprimality with big products.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThese lemmas are kept separate from `data.nat.gcd.basic` in order to minimize imports.\n-/\n\nnamespace nat\n\nopen_locale big_operators\n\n/-- See `is_coprime.prod_left` for the corresponding lemma about `is_coprime` -/\nlemma coprime_prod_left\n  {\u03b9 : Type*} {x : \u2115} {s : \u03b9 \u2192 \u2115} {t : finset \u03b9} :\n  (\u2200 (i : \u03b9), i \u2208 t \u2192 coprime (s i) x) \u2192 coprime (\u220f (i : \u03b9) in t, s i) x :=\nfinset.prod_induction s (\u03bb y, y.coprime x) (\u03bb a b, coprime.mul) (by simp)\n\n/-- See `is_coprime.prod_right` for the corresponding lemma about `is_coprime` -/\nlemma coprime_prod_right\n  {\u03b9 : Type*} {x : \u2115} {s : \u03b9 \u2192 \u2115} {t : finset \u03b9} :\n  (\u2200 (i : \u03b9), i \u2208 t \u2192 coprime x (s i)) \u2192 coprime x (\u220f (i : \u03b9) in t, s i) :=\nfinset.prod_induction s (\u03bb y, x.coprime y) (\u03bb a b, coprime.mul_right) (by simp)\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/gcd/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7321619883868592}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport algebra.gcd_monoid.multiset\nimport combinatorics.partition\nimport group_theory.perm.cycles\nimport ring_theory.int.basic\nimport tactic.linarith\n\n/-!\n# Cycle Types\n\nIn this file we define the cycle type of a permutation.\n\n## Main definitions\n\n- `\u03c3.cycle_type` where `\u03c3` is a permutation of a `fintype`\n- `\u03c3.partition` where `\u03c3` is a permutation of a `fintype`\n\n## Main results\n\n- `sum_cycle_type` : The sum of `\u03c3.cycle_type` equals `\u03c3.support.card`\n- `lcm_cycle_type` : The lcm of `\u03c3.cycle_type` equals `order_of \u03c3`\n- `is_conj_iff_cycle_type_eq` : Two permutations are conjugate if and only if they have the same\n  cycle type.\n* `exists_prime_order_of_dvd_card`: For every prime `p` dividing the order of a finite group `G`\n  there exists an element of order `p` in `G`. This is known as Cauchy`s theorem.\n-/\n\nnamespace equiv.perm\nopen equiv list multiset\n\nvariables {\u03b1 : Type*} [fintype \u03b1]\n\nsection cycle_type\n\nvariables [decidable_eq \u03b1]\n\n/-- The cycle type of a permutation -/\ndef cycle_type (\u03c3 : perm \u03b1) : multiset \u2115 :=\n\u03c3.cycle_factors_finset.1.map (finset.card \u2218 support)\n\nlemma cycle_type_def (\u03c3 : perm \u03b1) :\n  \u03c3.cycle_type = \u03c3.cycle_factors_finset.1.map (finset.card \u2218 support) := rfl\n\nlemma cycle_type_eq' {\u03c3 : perm \u03b1} (s : finset (perm \u03b1))\n  (h1 : \u2200 f : perm \u03b1, f \u2208 s \u2192 f.is_cycle) (h2 : \u2200 (a \u2208 s) (b \u2208 s), a \u2260 b \u2192 disjoint a b)\n  (h0 : s.noncomm_prod id\n    (\u03bb a ha b hb, (em (a = b)).by_cases (\u03bb h, h \u25b8 commute.refl a)\n      (set.pairwise.mono' (\u03bb _ _, disjoint.commute) h2 a ha b hb)) = \u03c3) :\n  \u03c3.cycle_type = s.1.map (finset.card \u2218 support) :=\nbegin\n  rw cycle_type_def,\n  congr,\n  rw cycle_factors_finset_eq_finset,\n  exact \u27e8h1, h2, h0\u27e9\nend\n\nlemma cycle_type_eq {\u03c3 : perm \u03b1} (l : list (perm \u03b1)) (h0 : l.prod = \u03c3)\n  (h1 : \u2200 \u03c3 : perm \u03b1, \u03c3 \u2208 l \u2192 \u03c3.is_cycle) (h2 : l.pairwise disjoint) :\n  \u03c3.cycle_type = l.map (finset.card \u2218 support) :=\nbegin\n  have hl : l.nodup := nodup_of_pairwise_disjoint_cycles h1 h2,\n  rw cycle_type_eq' l.to_finset,\n  { simp [list.erase_dup_eq_self.mpr hl] },\n  { simpa using h1 },\n  { simpa [hl] using h0 },\n  { simpa [list.erase_dup_eq_self.mpr hl] using list.forall_of_pairwise disjoint.symmetric h2 }\nend\n\nlemma cycle_type_one : (1 : perm \u03b1).cycle_type = 0 :=\ncycle_type_eq [] rfl (\u03bb _, false.elim) pairwise.nil\n\nlemma cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type = 0 \u2194 \u03c3 = 1 :=\nby simp [cycle_type_def, cycle_factors_finset_eq_empty_iff]\n\nlemma card_cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 0 \u2194 \u03c3 = 1 :=\nby rw [card_eq_zero, cycle_type_eq_zero]\n\nlemma two_le_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 2 \u2264 n :=\nbegin\n  simp only [cycle_type_def, \u2190finset.mem_def, function.comp_app, multiset.mem_map,\n    mem_cycle_factors_finset_iff] at h,\n  obtain \u27e8_, \u27e8hc, -\u27e9, rfl\u27e9 := h,\n  exact hc.two_le_card_support\nend\n\nlemma one_lt_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 1 < n :=\ntwo_le_of_mem_cycle_type h\n\nlemma is_cycle.cycle_type {\u03c3 : perm \u03b1} (h\u03c3 : is_cycle \u03c3) : \u03c3.cycle_type = [\u03c3.support.card] :=\ncycle_type_eq [\u03c3] (mul_one \u03c3) (\u03bb \u03c4 h\u03c4, (congr_arg is_cycle (list.mem_singleton.mp h\u03c4)).mpr h\u03c3)\n  (pairwise_singleton disjoint \u03c3)\n\nlemma card_cycle_type_eq_one {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 1 \u2194 \u03c3.is_cycle :=\nbegin\n  rw card_eq_one,\n  simp_rw [cycle_type_def, multiset.map_eq_singleton, \u2190finset.singleton_val,\n           finset.val_inj, cycle_factors_finset_eq_singleton_iff],\n  split,\n  { rintro \u27e8_, _, \u27e8h, -\u27e9, -\u27e9,\n    exact h },\n  { intro h,\n    use [\u03c3.support.card, \u03c3],\n    simp [h] }\nend\n\nlemma disjoint.cycle_type {\u03c3 \u03c4 : perm \u03b1} (h : disjoint \u03c3 \u03c4) :\n  (\u03c3 * \u03c4).cycle_type = \u03c3.cycle_type + \u03c4.cycle_type :=\nbegin\n  rw [cycle_type_def, cycle_type_def, cycle_type_def, h.cycle_factors_finset_mul_eq_union,\n      \u2190multiset.map_add, finset.union_val, multiset.add_eq_union_iff_disjoint.mpr _],\n  rw [\u2190finset.disjoint_val],\n  exact h.disjoint_cycle_factors_finset\nend\n\nlemma cycle_type_inv (\u03c3 : perm \u03b1) : \u03c3\u207b\u00b9.cycle_type = \u03c3.cycle_type :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4\u207b\u00b9.cycle_type = \u03c4.cycle_type) \u03c3 rfl\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, h\u03c3.inv.cycle_type, support_inv])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [mul_inv_rev, h\u03c3\u03c4.cycle_type, \u2190h\u03c3, \u2190h\u03c4, add_comm,\n    disjoint.cycle_type (\u03bb x, or.imp (\u03bb h : \u03c4 x = x, inv_eq_iff_eq.mpr h.symm)\n    (\u03bb h : \u03c3 x = x, inv_eq_iff_eq.mpr h.symm) (h\u03c3\u03c4 x).symm)])\n\nlemma cycle_type_conj {\u03c3 \u03c4 : perm \u03b1} : (\u03c4 * \u03c3 * \u03c4\u207b\u00b9).cycle_type = \u03c3.cycle_type :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intro,\n    simp },\n  { intros \u03c3 h\u03c3 \u03c4,\n    rw [h\u03c3.cycle_type, h\u03c3.is_cycle_conj.cycle_type, card_support_conj] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4 \u03c0,\n    rw [\u2190 conj_mul, hd.cycle_type, disjoint.cycle_type, h\u03c3, h\u03c4],\n    intro a,\n    apply (hd (\u03c0\u207b\u00b9 a)).imp _ _;\n    { intro h, rw [perm.mul_apply, perm.mul_apply, h, apply_inv_self] } }\nend\n\nlemma sum_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.sum = \u03c3.support.card :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.sum = \u03c4.support.card) \u03c3\n  (by rw [cycle_type_one, sum_zero, support_one, finset.card_empty])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, coe_sum, list.sum_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, sum_add, h\u03c3, h\u03c4, h\u03c3\u03c4.card_support_mul])\n\nlemma sign_of_cycle_type (\u03c3 : perm \u03b1) :\n  sign \u03c3 = (\u03c3.cycle_type.map (\u03bb n, -(-1 : units \u2124) ^ n)).prod :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, sign \u03c4 = (\u03c4.cycle_type.map (\u03bb n, -(-1 : units \u2124) ^ n)).prod) \u03c3\n  (by rw [sign_one, cycle_type_one, multiset.map_zero, prod_zero])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.sign, h\u03c3.cycle_type, coe_map, coe_prod,\n    list.map_singleton, list.prod_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [sign_mul, h\u03c3, h\u03c4, h\u03c3\u03c4.cycle_type, multiset.map_add, prod_add])\n\nlemma lcm_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.lcm = order_of \u03c3 :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.lcm = order_of \u03c4) \u03c3\n  (by rw [cycle_type_one, lcm_zero, order_of_one])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, \u2190singleton_coe, \u2190singleton_eq_cons, lcm_singleton,\n    order_of_is_cycle h\u03c3, normalize_eq])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, lcm_add, lcm_eq_nat_lcm, h\u03c3\u03c4.order_of, h\u03c3, h\u03c4])\n\nlemma dvd_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : n \u2223 order_of \u03c3 :=\nbegin\n  rw \u2190 lcm_cycle_type,\n  exact dvd_lcm h,\nend\n\nlemma order_of_cycle_of_dvd_order_of (f : perm \u03b1) (x : \u03b1) :\n  order_of (cycle_of f x) \u2223 order_of f :=\nbegin\n  by_cases hx : f x = x,\n  { rw \u2190cycle_of_eq_one_iff at hx,\n    simp [hx] },\n  { refine dvd_of_mem_cycle_type _,\n    rw [cycle_type, multiset.mem_map],\n    refine \u27e8f.cycle_of x, _, _\u27e9,\n    { rwa [\u2190finset.mem_def, cycle_of_mem_cycle_factors_finset_iff, mem_support] },\n    { simp [order_of_is_cycle (is_cycle_cycle_of _ hx)] } }\nend\n\nlemma two_dvd_card_support {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ 2 = 1) : 2 \u2223 \u03c3.support.card :=\n(congr_arg (has_dvd.dvd 2) \u03c3.sum_cycle_type).mp\n  (multiset.dvd_sum (\u03bb n hn, by rw le_antisymm (nat.le_of_dvd zero_lt_two $\n  (dvd_of_mem_cycle_type hn).trans $ order_of_dvd_of_pow_eq_one h\u03c3) (two_le_of_mem_cycle_type hn)))\n\nlemma cycle_type_prime_order {\u03c3 : perm \u03b1} (h\u03c3 : (order_of \u03c3).prime) :\n  \u2203 n : \u2115, \u03c3.cycle_type = repeat (order_of \u03c3) (n + 1) :=\nbegin\n  rw eq_repeat_of_mem (\u03bb n hn, or_iff_not_imp_left.mp\n    (h\u03c3.2 n (dvd_of_mem_cycle_type hn)) (ne_of_gt (one_lt_of_mem_cycle_type hn))),\n  use \u03c3.cycle_type.card - 1,\n  rw tsub_add_cancel_of_le,\n  rw [nat.succ_le_iff, pos_iff_ne_zero, ne, card_cycle_type_eq_zero],\n  rintro rfl,\n  rw order_of_one at h\u03c3,\n  exact h\u03c3.ne_one rfl,\nend\n\nlemma is_cycle_of_prime_order {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : \u03c3.support.card < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  obtain \u27e8n, hn\u27e9 := cycle_type_prime_order h1,\n  rw [\u2190\u03c3.sum_cycle_type, hn, multiset.sum_repeat, nsmul_eq_mul, nat.cast_id, mul_lt_mul_right\n      (order_of_pos \u03c3), nat.succ_lt_succ_iff, nat.lt_succ_iff, nat.le_zero_iff] at h2,\n  rw [\u2190card_cycle_type_eq_one, hn, card_repeat, h2],\nend\n\nlemma cycle_type_le_of_mem_cycle_factors_finset {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  f.cycle_type \u2264 g.cycle_type :=\nbegin\n  rw mem_cycle_factors_finset_iff at hf,\n  rw [cycle_type_def, cycle_type_def, hf.left.cycle_factors_finset_eq_singleton],\n  refine map_le_map _,\n  simpa [\u2190finset.mem_def, mem_cycle_factors_finset_iff] using hf\nend\n\nlemma cycle_type_mul_mem_cycle_factors_finset_eq_sub {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  (g * f\u207b\u00b9).cycle_type = g.cycle_type - f.cycle_type :=\nbegin\n  suffices : (g * f\u207b\u00b9).cycle_type + f.cycle_type = g.cycle_type - f.cycle_type + f.cycle_type,\n  { rw tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf) at this,\n    simp [\u2190this] },\n  simp [\u2190(disjoint_mul_inv_of_mem_cycle_factors_finset hf).cycle_type,\n    tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf)]\nend\n\ntheorem is_conj_of_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} (h : cycle_type \u03c3 = cycle_type \u03c4) : is_conj \u03c3 \u03c4 :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intros \u03c4 h,\n    rw [cycle_type_one, eq_comm, cycle_type_eq_zero] at h,\n    rw h },\n  { intros \u03c3 h\u03c3 \u03c4 h\u03c3\u03c4,\n    have h\u03c4 := card_cycle_type_eq_one.2 h\u03c3,\n    rw [h\u03c3\u03c4, card_cycle_type_eq_one] at h\u03c4,\n    apply h\u03c3.is_conj h\u03c4,\n    rw [h\u03c3.cycle_type, h\u03c4.cycle_type, coe_eq_coe, singleton_perm] at h\u03c3\u03c4,\n    simp only [and_true, eq_self_iff_true] at h\u03c3\u03c4,\n    exact h\u03c3\u03c4 },\n  { intros \u03c3 \u03c4 h\u03c3\u03c4 h\u03c3 h1 h2 \u03c0 h\u03c0,\n    rw [h\u03c3\u03c4.cycle_type] at h\u03c0,\n    { have h : \u03c3.support.card \u2208 map (finset.card \u2218 perm.support) \u03c0.cycle_factors_finset.val,\n      { simp [\u2190cycle_type_def, \u2190h\u03c0, h\u03c3.cycle_type] },\n      obtain \u27e8\u03c3', h\u03c3'l, h\u03c3'\u27e9 := multiset.mem_map.mp h,\n      have key : is_conj (\u03c3' * (\u03c0 * \u03c3'\u207b\u00b9)) \u03c0,\n      { rw is_conj_iff,\n        use \u03c3'\u207b\u00b9,\n        simp [mul_assoc] },\n      refine is_conj.trans _ key,\n      have hs : \u03c3.cycle_type = \u03c3'.cycle_type,\n      { rw [\u2190finset.mem_def, mem_cycle_factors_finset_iff] at h\u03c3'l,\n        rw [h\u03c3.cycle_type, \u2190h\u03c3', h\u03c3'l.left.cycle_type] },\n      refine h\u03c3\u03c4.is_conj_mul (h1 hs) (h2 _) _,\n      { rw [cycle_type_mul_mem_cycle_factors_finset_eq_sub, \u2190h\u03c0, add_comm, hs,\n            add_tsub_cancel_right],\n        rwa finset.mem_def },\n      { exact (disjoint_mul_inv_of_mem_cycle_factors_finset h\u03c3'l).symm } } }\nend\n\ntheorem is_conj_iff_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.cycle_type = \u03c4.cycle_type :=\n\u27e8\u03bb h, begin\n  obtain \u27e8\u03c0, rfl\u27e9 := is_conj_iff.1 h,\n  rw cycle_type_conj,\nend, is_conj_of_cycle_type_eq\u27e9\n\n@[simp] lemma cycle_type_extend_domain {\u03b2 : Type*} [fintype \u03b2] [decidable_eq \u03b2]\n  {p : \u03b2 \u2192 Prop} [decidable_pred p] (f : \u03b1 \u2243 subtype p) {g : perm \u03b1} :\n  cycle_type (g.extend_domain f) = cycle_type g :=\nbegin\n  apply cycle_induction_on _ g,\n  { rw [extend_domain_one, cycle_type_one, cycle_type_one] },\n  { intros \u03c3 h\u03c3,\n    rw [(h\u03c3.extend_domain f).cycle_type, h\u03c3.cycle_type, card_support_extend_domain] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4,\n    rw [hd.cycle_type, \u2190 extend_domain_mul, (hd.extend_domain f).cycle_type, h\u03c3, h\u03c4] }\nend\n\nlemma mem_cycle_type_iff {n : \u2115} {\u03c3 : perm \u03b1} :\n  n \u2208 cycle_type \u03c3 \u2194 \u2203 c \u03c4 : perm \u03b1, \u03c3 = c * \u03c4 \u2227 disjoint c \u03c4 \u2227 is_cycle c \u2227 c.support.card = n :=\nbegin\n  split,\n  { intro h,\n    obtain \u27e8l, rfl, hlc, hld\u27e9 := trunc_cycle_factors \u03c3,\n    rw cycle_type_eq _ rfl hlc hld at h,\n    obtain \u27e8c, cl, rfl\u27e9 := list.exists_of_mem_map h,\n    rw (list.perm_cons_erase cl).pairwise_iff (\u03bb _ _ hd, _) at hld,\n    swap, { exact hd.symm },\n    refine \u27e8c, (l.erase c).prod, _, _, hlc _ cl, rfl\u27e9,\n    { rw [\u2190 list.prod_cons,\n        (list.perm_cons_erase cl).symm.prod_eq' (hld.imp (\u03bb _ _, disjoint.commute))] },\n    { exact disjoint_prod_right _ (\u03bb g, list.rel_of_pairwise_cons hld) } },\n  { rintros \u27e8c, t, rfl, hd, hc, rfl\u27e9,\n    simp [hd.cycle_type, hc.cycle_type] }\nend\n\nlemma le_card_support_of_mem_cycle_type {n : \u2115} {\u03c3 : perm \u03b1} (h : n \u2208 cycle_type \u03c3) :\n  n \u2264 \u03c3.support.card :=\n(le_sum_of_mem h).trans (le_of_eq \u03c3.sum_cycle_type)\n\nlemma cycle_type_of_card_le_mem_cycle_type_add_two {n : \u2115} {g : perm \u03b1}\n  (hn2 : fintype.card \u03b1 < n + 2) (hng : n \u2208 g.cycle_type) :\n  g.cycle_type = {n} :=\nbegin\n  obtain \u27e8c, g', rfl, hd, hc, rfl\u27e9 := mem_cycle_type_iff.1 hng,\n  by_cases g'1 : g' = 1,\n  { rw [hd.cycle_type, hc.cycle_type, multiset.singleton_eq_cons, multiset.singleton_coe,\n      g'1, cycle_type_one, add_zero] },\n  contrapose! hn2,\n  apply le_trans _ (c * g').support.card_le_univ,\n  rw [hd.card_support_mul],\n  exact add_le_add_left (two_le_card_support_of_ne_one g'1) _,\nend\n\nend cycle_type\n\nlemma card_compl_support_modeq [decidable_eq \u03b1] {p n : \u2115} [hp : fact p.prime] {\u03c3 : perm \u03b1}\n  (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u03c3.support\u1d9c.card \u2261 fintype.card \u03b1 [MOD p] :=\nbegin\n  rw [nat.modeq_iff_dvd' \u03c3.support\u1d9c.card_le_univ, \u2190finset.card_compl, compl_compl],\n  refine (congr_arg _ \u03c3.sum_cycle_type).mp (multiset.dvd_sum (\u03bb k hk, _)),\n  obtain \u27e8m, -, hm\u27e9 := (nat.dvd_prime_pow hp.out).mp (order_of_dvd_of_pow_eq_one h\u03c3),\n  obtain \u27e8l, -, rfl\u27e9 := (nat.dvd_prime_pow hp.out).mp\n    ((congr_arg _ hm).mp (dvd_of_mem_cycle_type hk)),\n  exact dvd_pow_self _ (\u03bb h, (one_lt_of_mem_cycle_type hk).ne $ by rw [h, pow_zero]),\nend\n\nlemma exists_fixed_point_of_prime {p n : \u2115} [hp : fact p.prime] (h\u03b1 : \u00ac p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u2203 a : \u03b1, \u03c3 a = a :=\nbegin\n  classical,\n  contrapose! h\u03b1,\n  simp_rw \u2190 mem_support at h\u03b1,\n  exact nat.modeq_zero_iff_dvd.mp ((congr_arg _ (finset.card_eq_zero.mpr (compl_eq_bot.mpr\n    (finset.eq_univ_iff_forall.mpr h\u03b1)))).mp (card_compl_support_modeq h\u03c3).symm),\nend\n\nlemma exists_fixed_point_of_prime' {p n : \u2115} [hp : fact p.prime] (h\u03b1 : p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) {a : \u03b1} (ha : \u03c3 a = a) : \u2203 b : \u03b1, \u03c3 b = b \u2227 b \u2260 a :=\nbegin\n  classical,\n  have h : \u2200 b : \u03b1, b \u2208 \u03c3.support\u1d9c \u2194 \u03c3 b = b :=\n  \u03bb b, by rw [finset.mem_compl, mem_support, not_not],\n  obtain \u27e8b, hb1, hb2\u27e9 := finset.exists_ne_of_one_lt_card (lt_of_lt_of_le hp.out.one_lt\n    (nat.le_of_dvd (finset.card_pos.mpr \u27e8a, (h a).mpr ha\u27e9) (nat.modeq_zero_iff_dvd.mp\n    ((card_compl_support_modeq h\u03c3).trans (nat.modeq_zero_iff_dvd.mpr h\u03b1))))) a,\n  exact \u27e8b, (h b).mp hb1, hb2\u27e9,\nend\n\nlemma is_cycle_of_prime_order' {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : fintype.card \u03b1 < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  classical,\n  exact is_cycle_of_prime_order h1 (lt_of_le_of_lt \u03c3.support.card_le_univ h2),\nend\n\nlemma is_cycle_of_prime_order'' {\u03c3 : perm \u03b1} (h1 : (fintype.card \u03b1).prime)\n  (h2 : order_of \u03c3 = fintype.card \u03b1) : \u03c3.is_cycle :=\nis_cycle_of_prime_order' ((congr_arg nat.prime h2).mpr h1)\nbegin\n  classical,\n  rw [\u2190one_mul (fintype.card \u03b1), \u2190h2, mul_lt_mul_right (order_of_pos \u03c3)],\n  exact one_lt_two,\nend\n\nsection cauchy\n\nvariables (G : Type*) [group G] (n : \u2115)\n\n/-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/\ndef vectors_prod_eq_one : set (vector G n) :=\n{v | v.to_list.prod = 1}\n\nnamespace vectors_prod_eq_one\n\nlemma mem_iff {n : \u2115} (v : vector G n) :\nv \u2208 vectors_prod_eq_one G n \u2194 v.to_list.prod = 1 := iff.rfl\n\nlemma zero_eq : vectors_prod_eq_one G 0 = {vector.nil} :=\nset.eq_singleton_iff_unique_mem.mpr \u27e8eq.refl (1 : G), \u03bb v hv, v.eq_nil\u27e9\n\nlemma one_eq : vectors_prod_eq_one G 1 = {vector.nil.cons 1} :=\nbegin\n  simp_rw [set.eq_singleton_iff_unique_mem, mem_iff,\n    vector.to_list_singleton, list.prod_singleton, vector.head_cons],\n  exact \u27e8rfl, \u03bb v hv, v.cons_head_tail.symm.trans (congr_arg2 vector.cons hv v.tail.eq_nil)\u27e9,\nend\n\ninstance zero_unique : unique (vectors_prod_eq_one G 0) :=\nby { rw zero_eq, exact set.unique_singleton vector.nil }\n\ninstance one_unique : unique (vectors_prod_eq_one G 1) :=\nby { rw one_eq, exact set.unique_singleton (vector.nil.cons 1) }\n\n/-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`,\nby appending the inverse of the product of `v`. -/\n@[simps] def vector_equiv : vector G n \u2243 vectors_prod_eq_one G (n + 1) :=\n{ to_fun := \u03bb v, \u27e8v.to_list.prod\u207b\u00b9 ::\u1d65 v,\n    by rw [mem_iff, vector.to_list_cons, list.prod_cons, inv_mul_self]\u27e9,\n  inv_fun := \u03bb v, v.1.tail,\n  left_inv := \u03bb v, v.tail_cons v.to_list.prod\u207b\u00b9,\n  right_inv := \u03bb v, subtype.ext ((congr_arg2 vector.cons (eq_inv_of_mul_eq_one (by\n  { rw [\u2190list.prod_cons, \u2190vector.to_list_cons, v.1.cons_head_tail],\n    exact v.2 })).symm rfl).trans v.1.cons_head_tail) }\n\n/-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`,\nby deleting the last entry of `v`. -/\ndef equiv_vector : vectors_prod_eq_one G n \u2243 vector G (n - 1) :=\n((vector_equiv G (n - 1)).trans (if hn : n = 0 then (show vectors_prod_eq_one G (n - 1 + 1) \u2243\n  vectors_prod_eq_one G n, by { rw hn, exact equiv_of_unique_of_unique })\n  else by rw tsub_add_cancel_of_le (nat.pos_of_ne_zero hn).nat_succ_le)).symm\n\ninstance [fintype G] : fintype (vectors_prod_eq_one G n) :=\nfintype.of_equiv (vector G (n - 1)) (equiv_vector G n).symm\n\nlemma card [fintype G] :\n  fintype.card (vectors_prod_eq_one G n) = fintype.card G ^ (n - 1) :=\n(fintype.card_congr (equiv_vector G n)).trans (card_vector (n - 1))\n\nvariables {G n} {g : G} (v : vectors_prod_eq_one G n) (j k : \u2115)\n\n/-- Rotate a vector whose product is 1. -/\ndef rotate : vectors_prod_eq_one G n :=\n\u27e8\u27e8_, (v.1.1.length_rotate k).trans v.1.2\u27e9, list.prod_rotate_eq_one_of_prod_eq_one v.2 k\u27e9\n\nlemma rotate_zero : rotate v 0 = v :=\nsubtype.ext (subtype.ext v.1.1.rotate_zero)\n\nlemma rotate_rotate : rotate (rotate v j) k = rotate v (j + k) :=\nsubtype.ext (subtype.ext (v.1.1.rotate_rotate j k))\n\nlemma rotate_length : rotate v n = v :=\nsubtype.ext (subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length))\n\nend vectors_prod_eq_one\n\nlemma exists_prime_order_of_dvd_card {G : Type*} [group G] [fintype G] (p : \u2115) [hp : fact p.prime]\n  (hdvd : p \u2223 fintype.card G) : \u2203 x : G, order_of x = p :=\nbegin\n  have hp' : p - 1 \u2260 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_lt hp.out.one_lt),\n  have Scard := calc p \u2223 fintype.card G ^ (p - 1) : hdvd.trans (dvd_pow (dvd_refl _) hp')\n  ... = fintype.card (vectors_prod_eq_one G p) : (vectors_prod_eq_one.card G p).symm,\n  let f : \u2115 \u2192 vectors_prod_eq_one G p \u2192 vectors_prod_eq_one G p :=\n  \u03bb k v, vectors_prod_eq_one.rotate v k,\n  have hf1 : \u2200 v, f 0 v = v := vectors_prod_eq_one.rotate_zero,\n  have hf2 : \u2200 j k v, f k (f j v) = f (j + k) v :=\n  \u03bb j k v, vectors_prod_eq_one.rotate_rotate v j k,\n  have hf3 : \u2200 v, f p v = v := vectors_prod_eq_one.rotate_length,\n  let \u03c3 := equiv.mk (f 1) (f (p - 1))\n    (\u03bb s, by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3])\n    (\u03bb s, by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3]),\n  have h\u03c3 : \u2200 k v, (\u03c3 ^ k) v = f k v :=\n  \u03bb k v, nat.rec (hf1 v).symm (\u03bb k hk, eq.trans (by exact congr_arg \u03c3 hk) (hf2 k 1 v)) k,\n  replace h\u03c3 : \u03c3 ^ (p ^ 1) = 1 := perm.ext (\u03bb v, by rw [pow_one, h\u03c3, hf3, one_apply]),\n  let v\u2080 : vectors_prod_eq_one G p := \u27e8vector.repeat 1 p, (list.prod_repeat 1 p).trans (one_pow p)\u27e9,\n  have hv\u2080 : \u03c3 v\u2080 = v\u2080 := subtype.ext (subtype.ext (list.rotate_repeat (1 : G) p 1)),\n  obtain \u27e8v, hv1, hv2\u27e9 := exists_fixed_point_of_prime' Scard h\u03c3 hv\u2080,\n  refine exists_imp_exists (\u03bb g hg, order_of_eq_prime _ (\u03bb hg', hv2 _))\n    (list.rotate_one_eq_self_iff_eq_repeat.mp (subtype.ext_iff.mp (subtype.ext_iff.mp hv1))),\n  { rw [\u2190list.prod_repeat, \u2190v.1.2, \u2190hg, (show v.val.val.prod = 1, from v.2)] },\n  { rw [subtype.ext_iff_val, subtype.ext_iff_val, hg, hg', v.1.2],\n    refl },\nend\n\nend cauchy\n\nlemma subgroup_eq_top_of_swap_mem [decidable_eq \u03b1] {H : subgroup (perm \u03b1)}\n  [d : decidable_pred (\u2208 H)] {\u03c4 : perm \u03b1} (h0 : (fintype.card \u03b1).prime)\n  (h1 : fintype.card \u03b1 \u2223 fintype.card H) (h2 : \u03c4 \u2208 H) (h3 : is_swap \u03c4) :\n  H = \u22a4 :=\nbegin\n  haveI : fact (fintype.card \u03b1).prime := \u27e8h0\u27e9,\n  obtain \u27e8\u03c3, h\u03c3\u27e9 := exists_prime_order_of_dvd_card (fintype.card \u03b1) h1,\n  have h\u03c31 : order_of (\u03c3 : perm \u03b1) = fintype.card \u03b1 := (order_of_subgroup \u03c3).trans h\u03c3,\n  have h\u03c32 : is_cycle \u2191\u03c3 := is_cycle_of_prime_order'' h0 h\u03c31,\n  have h\u03c33 : (\u03c3 : perm \u03b1).support = \u22a4 :=\n    finset.eq_univ_of_card (\u03c3 : perm \u03b1).support ((order_of_is_cycle h\u03c32).symm.trans h\u03c31),\n  have h\u03c34 : subgroup.closure {\u2191\u03c3, \u03c4} = \u22a4 := closure_prime_cycle_swap h0 h\u03c32 h\u03c33 h3,\n  rw [eq_top_iff, \u2190h\u03c34, subgroup.closure_le, set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8subtype.mem \u03c3, h2\u27e9,\nend\n\nsection partition\n\nvariables [decidable_eq \u03b1]\n\n/-- The partition corresponding to a permutation -/\ndef partition (\u03c3 : perm \u03b1) : (fintype.card \u03b1).partition :=\n{ parts := \u03c3.cycle_type + repeat 1 (fintype.card \u03b1 - \u03c3.support.card),\n  parts_pos := \u03bb n hn,\n  begin\n    cases mem_add.mp hn with hn hn,\n    { exact zero_lt_one.trans (one_lt_of_mem_cycle_type hn) },\n    { exact lt_of_lt_of_le zero_lt_one (ge_of_eq (multiset.eq_of_mem_repeat hn)) },\n  end,\n  parts_sum := by rw [sum_add, sum_cycle_type, multiset.sum_repeat, nsmul_eq_mul,\n    nat.cast_id, mul_one, add_tsub_cancel_of_le \u03c3.support.card_le_univ] }\n\nlemma parts_partition {\u03c3 : perm \u03b1} :\n  \u03c3.partition.parts = \u03c3.cycle_type + repeat 1 (fintype.card \u03b1 - \u03c3.support.card) := rfl\n\nlemma filter_parts_partition_eq_cycle_type {\u03c3 : perm \u03b1} :\n  (partition \u03c3).parts.filter (\u03bb n, 2 \u2264 n) = \u03c3.cycle_type :=\nbegin\n  rw [parts_partition, filter_add, multiset.filter_eq_self.2 (\u03bb _, two_le_of_mem_cycle_type),\n    multiset.filter_eq_nil.2 (\u03bb a h, _), add_zero],\n  rw multiset.eq_of_mem_repeat h,\n  dec_trivial\nend\n\nlemma partition_eq_of_is_conj {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.partition = \u03c4.partition :=\nbegin\n  rw [is_conj_iff_cycle_type_eq],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rw [nat.partition.ext_iff, parts_partition, parts_partition,\n      \u2190 sum_cycle_type, \u2190 sum_cycle_type, h] },\n  { rw [\u2190 filter_parts_partition_eq_cycle_type, \u2190 filter_parts_partition_eq_cycle_type, h] }\nend\n\nend partition\n\n/-!\n### 3-cycles\n-/\n\n/-- A three-cycle is a cycle of length 3. -/\ndef is_three_cycle [decidable_eq \u03b1] (\u03c3 : perm \u03b1) : Prop := \u03c3.cycle_type = {3}\n\nnamespace is_three_cycle\n\nvariables [decidable_eq \u03b1] {\u03c3 : perm \u03b1}\n\nlemma cycle_type (h : is_three_cycle \u03c3) : \u03c3.cycle_type = {3} := h\n\nlemma card_support (h : is_three_cycle \u03c3) : \u03c3.support.card = 3 :=\nby rw [\u2190sum_cycle_type, h.cycle_type, multiset.sum_singleton]\n\nlemma _root_.card_support_eq_three_iff : \u03c3.support.card = 3 \u2194 \u03c3.is_three_cycle :=\nbegin\n  refine \u27e8\u03bb h, _, is_three_cycle.card_support\u27e9,\n  by_cases h0 : \u03c3.cycle_type = 0,\n  { rw [\u2190sum_cycle_type, h0, sum_zero] at h,\n    exact (ne_of_lt zero_lt_three h).elim },\n  obtain \u27e8n, hn\u27e9 := exists_mem_of_ne_zero h0,\n  by_cases h1 : \u03c3.cycle_type.erase n = 0,\n  { rw [\u2190sum_cycle_type, \u2190cons_erase hn, h1, \u2190singleton_eq_cons, multiset.sum_singleton] at h,\n    rw [is_three_cycle, \u2190cons_erase hn, h1, h, singleton_eq_cons] },\n  obtain \u27e8m, hm\u27e9 := exists_mem_of_ne_zero h1,\n  rw [\u2190sum_cycle_type, \u2190cons_erase hn, \u2190cons_erase hm, multiset.sum_cons, multiset.sum_cons] at h,\n  linarith [two_le_of_mem_cycle_type hn, two_le_of_mem_cycle_type (mem_of_mem_erase hm)],\nend\n\nlemma is_cycle (h : is_three_cycle \u03c3) : is_cycle \u03c3 :=\nby rw [\u2190card_cycle_type_eq_one, h.cycle_type, card_singleton]\n\nlemma sign (h : is_three_cycle \u03c3) : sign \u03c3 = 1 :=\nbegin\n  rw [sign_of_cycle_type, h.cycle_type],\n  refl,\nend\n\nlemma inv {f : perm \u03b1} (h : is_three_cycle f) : is_three_cycle (f\u207b\u00b9) :=\nby rwa [is_three_cycle, cycle_type_inv]\n\n@[simp] lemma inv_iff {f : perm \u03b1} : is_three_cycle (f\u207b\u00b9) \u2194 is_three_cycle f :=\n\u27e8by { rw \u2190 inv_inv f, apply inv }, inv\u27e9\n\nlemma order_of {g : perm \u03b1} (ht : is_three_cycle g) :\n  order_of g = 3 :=\nby rw [\u2190lcm_cycle_type, ht.cycle_type, multiset.lcm_singleton, normalize_eq]\n\nlemma is_three_cycle_sq {g : perm \u03b1} (ht : is_three_cycle g) :\n  is_three_cycle (g * g) :=\nbegin\n  rw [\u2190pow_two, \u2190card_support_eq_three_iff, support_pow_coprime, ht.card_support],\n  rw [ht.order_of, nat.coprime_iff_gcd_eq_one],\n  norm_num,\nend\n\nend is_three_cycle\n\nsection\nvariable [decidable_eq \u03b1]\n\nlemma is_three_cycle_swap_mul_swap_same\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) (bc : b \u2260 c) :\n  is_three_cycle (swap a b * swap a c) :=\nbegin\n  suffices h : support (swap a b * swap a c) = {a, b, c},\n  { rw [\u2190card_support_eq_three_iff, h],\n    simp [ab, ac, bc] },\n  apply le_antisymm ((support_mul_le _ _).trans (\u03bb x, _)) (\u03bb x hx, _),\n  { simp [ab, ac, bc] },\n  { simp only [finset.mem_insert, finset.mem_singleton] at hx,\n    rw mem_support,\n    simp only [perm.coe_mul, function.comp_app, ne.def],\n    obtain rfl | rfl | rfl := hx,\n    { rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm],\n      exact ac.symm },\n    { rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right],\n      exact ab },\n    { rw [swap_apply_right, swap_apply_left],\n      exact bc } }\nend\n\nopen subgroup\n\nlemma swap_mul_swap_same_mem_closure_three_cycles\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) :\n  (swap a b * swap a c) \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  by_cases bc : b = c,\n  { subst bc,\n    simp [one_mem] },\n  exact subset_closure (is_three_cycle_swap_mul_swap_same ab ac bc)\nend\n\nlemma is_swap.mul_mem_closure_three_cycles {\u03c3 \u03c4 : perm \u03b1}\n  (h\u03c3 : is_swap \u03c3) (h\u03c4 : is_swap \u03c4) :\n  \u03c3 * \u03c4 \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  obtain \u27e8a, b, ab, rfl\u27e9 := h\u03c3,\n  obtain \u27e8c, d, cd, rfl\u27e9 := h\u03c4,\n  by_cases ac : a = c,\n  { subst ac,\n    exact swap_mul_swap_same_mem_closure_three_cycles ab cd },\n  have h' : swap a b * swap c d = swap a b * swap a c * (swap c a * swap c d),\n  { simp [swap_comm c a, mul_assoc] },\n  rw h',\n  exact mul_mem _ (swap_mul_swap_same_mem_closure_three_cycles ab ac)\n    (swap_mul_swap_same_mem_closure_three_cycles (ne.symm ac) cd),\nend\n\nend\n\nend equiv.perm\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/group_theory/perm/cycle_type.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7321619877061745}}
{"text": "variables p q r s : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\nbegin\n    apply iff.intro,\n        assume pq,\n        show q \u2227 p, from and.intro pq.2 pq.1,\n\n        assume qp,\n        show p \u2227 q, from and.intro qp.2 qp.1\nend\nexample : p \u2228 q \u2194 q \u2228 p :=\nbegin\n    apply iff.intro,\n        assume pq,\n        cases pq with pfp pfq,\n            show q \u2228 p, from or.inr pfp,\n            show q \u2228 p, from or.inl pfq,\n        \n        assume qp,\n        cases qp with pfq pfp,\n            show p \u2228 q, from or.inr pfq,\n            show p \u2228 q, from or.inl pfp\nend\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\nbegin\n    apply iff.intro,\n        assume pqr,\n        show p \u2227 (q \u2227 r), from and.intro pqr.1.1 (and.intro pqr.1.2 pqr.2),\n\n        assume pqr,\n        show (p \u2227 q) \u2227 r, from and.intro (and.intro pqr.1 pqr.2.1) pqr.2.2\nend\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\nbegin\n    apply iff.intro,\n        assume pqr,\n            cases pqr with pq pfr,\n            cases pq with pfp pfq,\n                show p \u2228 (q \u2228 r), from or.inl pfp,\n                show p \u2228 (q \u2228 r), from or.inr (or.inl pfq),\n                show p \u2228 (q \u2228 r), from or.inr (or.inr pfr),\n\n        assume pqr,\n            cases pqr with pfp qr,\n                show (p \u2228 q) \u2228 r, from or.inl (or.inl pfp),\n            cases qr with pfq pfr,\n                show (p \u2228 q) \u2228 r, from or.inl (or.inr pfq),\n                show (p \u2228 q) \u2228 r, from or.inr pfr\nend\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n    apply iff.intro,\n    assume pqr,\n        have pfp := pqr.1,\n        have qr := pqr.2,\n        cases qr with pfq pfr,\n            show (p \u2227 q) \u2228 (p \u2227 r), from or.inl (and.intro pfp pfq),\n            show (p \u2227 q) \u2228 (p \u2227 r), from or.inr (and.intro pfp pfr),\n    \n    assume pqpr,\n    cases pqpr with pq pr,\n        have pfp := pq.1,\n        have right := or.inl pq.2,\n        show p \u2227 (q \u2228 r), from and.intro pfp right,\n\n        have pfp := pr.1,\n        have right := or.inr pr.2,\n        show p \u2227 (q \u2228 r), from and.intro pfp right\nend\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\nbegin\n    apply iff.intro,\n    assume pqr,\n        cases pqr with pfp qr,\n            show (p \u2228 q) \u2227 (p \u2228 r), from and.intro (or.inl pfp) (or.inl pfp),\n\n            have pfq := qr.1,\n            have pfr := qr.2,\n            show (p \u2228 q) \u2227 (p \u2228 r), from and.intro (or.inr pfq) (or.inr pfr),\n    \n    assume pqpr,\n        have pq := pqpr.1,\n        have pr := pqpr.2,\n        cases pq with pfp pfq,\n            show p \u2228 (q \u2227 r), from or.inl pfp,\n        cases pr with pfp pfr,\n            show p \u2228 (q \u2227 r), from or.inl pfp,\n            show p \u2228 (q \u2227 r), from or.inr (and.intro pfq pfr)\nend\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\nbegin\n    apply iff.intro,\n        assume pqr,\n        assume pq,\n        show r, from pqr pq.1 pq.2,\n    \n        assume pqr,\n        assume p q,\n        show r, from pqr (and.intro p q),\nend\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\nbegin\n    apply iff.intro,\n        assume pqr,\n        apply and.intro,\n            assume p,\n            show r, from pqr (or.inl p),\n\n            assume q,\n            show r, from pqr (or.inr q),\n        \n        assume pqr,\n        have pr := pqr.1,\n        have qr := pqr.2,\n        assume pq,\n        cases pq with pfp pfq,\n            show r, from pr pfp,\n            show r, from qr pfq\nend\n\n-- First Demorgan's law\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\nbegin\n    apply iff.intro,\n        assume npq,\n        apply and.intro,\n            assume p,\n            show false, from npq (or.inl p),\n\n            assume q,\n            show false, from npq (or.inr q),\n\n        assume npnq,\n        assume porq,\n        cases porq with pfp pfq,\n            show false, from npnq.1 pfp,\n            show false, from npnq.2 pfq\nend\n\n-- Second Demorgan's law\n-- This direction does not require classical reasoning\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n    begin\n        assume npornq,\n        assume pandq,\n        cases npornq with np nq,\n            show false, from np pandq.1,\n            show false, from nq pandq.2\n    end\n\nexample : \u00ac(p \u2227 \u00acp) :=\n    begin\n        assume h,\n        show false, from h.2 h.1\n    end\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := \n    begin\n        assume pandnotq,\n        assume ptoq,\n            have q := ptoq pandnotq.1,\n            show false, from pandnotq.2 q\n    end\n\nexample : \u00acp \u2192 (p \u2192 q) := \n    begin\n        assume notp,\n        assume p,\n        show q, from false.elim (notp p)\n    end\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := \n    begin\n        assume notporq,\n        assume p,\n        cases notporq with notp pfq,\n            show q, from false.elim (notp p),\n            show q, from pfq\n    end\n\nexample : p \u2228 false \u2194 p :=\nbegin\n    apply iff.intro,\n        assume pfalse,\n        cases pfalse with pfp pff,\n            show p, from pfp,\n            show p, from false.elim pff,\n        \n        assume pfp,\n            show p \u2228 false, from or.inl pfp\nend\n\nexample : p \u2227 false \u2194 false :=\nbegin\n    apply iff.intro,\n        assume pf,\n        show false, from pf.2,\n\n        assume f,\n        show p \u2227 false, from and.intro (false.elim f) f\nend\n\nexample : \u00ac(p \u2194 \u00acp) :=\nbegin\n    assume h,\n    have forward := iff.elim_left h,\n    have backward := iff.elim_right h,\n\n    have np : \u00acp := assume p, (forward p) p,\n    show false, from np (backward np)\nend\n\ntheorem modus_tollens : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := \n    begin\n        assume pq,\n        assume notq,\n        assume pfp,\n            have pfq : q := pq pfp,\n            show false, from notq pfq\n    end\n\n-- an alternative proof to \u00ac(p \u2194 \u00acp)\ntheorem piffnpf : \u00ac(p \u2194 \u00acp) :=\nbegin\n    apply iff.elim,\n        assume pnp,\n        assume npp,\n\n        apply modus_tollens,\n            exact npp,\n\n            assume p, \n            show false, from (pnp p) p,\n\n            assume p,\n            show false, from (pnp p) p\nend\n\n-- these require classical reasoning\nopen classical\ntheorem double_neg_elim: \u2200 { P }, \u00ac\u00acP \u2192 P := \nbegin\n    assume P : Prop,\n    assume pfNotNotP : \u00ac\u00acP,\n    cases em P with pfP pfnP,\n        show P, from pfP,\n\n        have f: false := pfNotNotP pfnP,\n        show P, from false.elim f\nend\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\nbegin\n    assume prs,\n    cases em p with pfp pfnp,\n        have rs := prs pfp,\n        cases rs with pfr pfs,\n            apply or.inl,\n                show p \u2192 r, from assume pfp, pfr,\n\n            apply or.inr,\n                show p \u2192 s, from assume pfp, pfs,\n\n        apply or.inl,\n            assume p,\n            show r, from false.elim (pfnp p)\nend\n\n-- Second Demorgan's law, \n-- the direction that requires classical reasoning\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := \nbegin\n    assume notPandQ,\n    cases em p with pfP pfnotP,\n    cases em q with pfQ pfnotQ,\n        show \u00acp \u2228 \u00acq, from false.elim (notPandQ (and.intro pfP pfQ)),\n        show \u00acp \u2228 \u00acq, from or.inr pfnotQ,\n        show \u00acp \u2228 \u00acq, from or.inl pfnotP,\nend\n\n-- I don't use \"example\" here because it's used in following proofs\ntheorem pf_by_contrapositive: (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := \n    begin\n        assume nqnp : \u00acq \u2192 \u00acp,\n        assume pfP : p,\n        have nnq : \u00acq \u2192 false :=\n            begin \n                assume nq : \u00acq,\n                have np : \u00acp := nqnp nq,\n                show false, from np pfP\n            end,\n        show q, from double_neg_elim nnq\n    end\n#check pf_by_contrapositive\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nbegin\n    assume notpq,\n    apply and.intro,\n        show \u00acq, --note: \"show\" can be used to switch the order of goals\n            assume pfq,\n            have pq : p \u2192 q := assume pfp, pfq,\n            show false, from notpq pq,\n\n        cases em p with pfp pfnp,\n            assumption,\n            have pq : p \u2192 q := \n                assume pfp, false.elim (pfnp pfp),\n            show p, from false.elim (notpq pq)\nend\n\n-- an alternative proof to the previous one\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nbegin\n    assume notpq,\n    cases em p with pfp pfnp,\n    cases em q with pfq pfnq,\n        have pq : p \u2192 q := assume p, pfq,\n        show p \u2227 \u00acq, from false.elim (notpq pq),\n\n        show p \u2227 \u00acq, from and.intro pfp pfnq,\n        \n        have nqnp : \u00acq \u2192 \u00acp := assume nq, pfnp,\n        have pq : p \u2192 q := pf_by_contrapositive p q nqnp,\n        show p \u2227 \u00acq, from false.elim (notpq pq)\nend\n\n-- an alternative proof to the previous one\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nbegin\n    assume notpq,\n    apply and.intro,\n        cases em p with pfp pfnp,\n        cases em q with pfq pfnq,\n            show p, from pfp,\n            show p, from pfp,\n\n            have pq : p \u2192 q := assume p, false.elim (pfnp p),\n            show p, from false.elim (notpq pq),\n\n            assume pfq,\n            have pq : p \u2192 q := assume p, pfq,\n            show false, from notpq pq\nend\n\n-- an alternative proof to the previous one\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nbegin\n    assume notpq,\n    apply and.intro,\n        cases em p with pfp pfnp,\n            show p, from pfp,\n\n            have nqnp : \u00acq \u2192 \u00acp := assume nq, pfnp,\n            have pq : p \u2192 q := pf_by_contrapositive p q nqnp,\n            show p, from false.elim (notpq pq),\n\n            assume pfq,\n            have pq : p \u2192 q := assume p, pfq,\n            show false, from notpq pq\nend\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\nbegin\n    assume pq,\n    cases em p with pfp pfnp,\n        show \u00acp \u2228 q, from or.inr (pq pfp),\n        show \u00acp \u2228 q, from or.inl pfnp\nend\n\nexample : p \u2228 \u00acp := \n    begin\n        apply em\n    end\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := \nbegin\n    assume pqp,\n    cases em p with pfp pfnp,\n        show p, from pfp,\n\n        have n: \u00acq \u2192 \u00acp := assume nq, pfnp,\n        have pq : p \u2192 q := pf_by_contrapositive p q n,\n        show p, from pqp pq\nend\n\n-- an alternative proof to the previous one\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := \nbegin\n    assume pqp,\n    cases em p with pfp pfnp,\n        show p, from pfp,\n\n        have pq: p \u2192 q :=\n            assume pfp, false.elim (pfnp pfp),\n        show p, from pqp pq\nend\n\n-- Proof that double negation elimination implies axiom of excluded middle\n-- First prove that \u2200 P, \u00ac\u00ac(P \u2228 \u00acP). \n-- This proof makes use of the property that \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq\nlemma notnotem: \u2200 P, \u00ac\u00ac(P \u2228 \u00acP) :=\nbegin\n    assume P,   \n    assume npornp,\n    have np: \u00acP := assume p, npornp (or.inl p),\n    have nnp: \u00ac\u00acP := assume np, npornp (or.inr np),\n    show false, from nnp np\nend\n\n#check notnotem\n#check non_contradictory_em -- notnotem is actually a built-in lemma\n\ntheorem DNEtoEM : (\u2200 P, \u00ac\u00acP \u2192 P) \u2192 (\u2200 P, P \u2228 \u00acP) :=\nbegin\n    assume notnotPtoP P,\n    have duo_neg_elim_em : \u00ac\u00ac(P \u2228 \u00acP) \u2192 P \u2228 \u00acP := notnotPtoP (P \u2228 \u00acP),\n    show P \u2228 \u00acP, from duo_neg_elim_em (notnotem P)\nend\n", "meta": {"author": "hanzhi713", "repo": "lean-proofs", "sha": "4d8356a878645b9ba7cb036f87737f3f1e68ede5", "save_path": "github-repos/lean/hanzhi713-lean-proofs", "path": "github-repos/lean/hanzhi713-lean-proofs/lean-proofs-4d8356a878645b9ba7cb036f87737f3f1e68ede5/src/chapter_exercises/chap3_exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7321619852863727}}
{"text": "import data.set.function\nimport tactic.linarith\n\nimport tactic.norm_num\n\nopen function\n\nnamespace mth1001\n\nsection identity\n\n/-\nFor a given type `\u03b1`, there is a special function, the identity function `id : \u03b1 \u2192 \u03b1` defined so\nthat `id a = a`, for every `a : \u03b1`.\n-/\n\ndef p\u2081 (x : \u2115) : \u2124 := 3 * x\n\n/-\nFor every function `f : \u03b1 \u2192 \u03b2`, we have `id \u2218 f = f` and `f \u2218 id = f`.\n-/\n#eval (p\u2081 \u2218 id) 6\n#eval (id \u2218 p\u2081) 6\n\n/-\nTo be more precise, we should acknowledge that the identity function `id : \u03b1 \u2192 \u03b1` depends on the\ntype `\u03b1`. In Lean, we dentote this function by `@id \u03b1`. In mathematical writing, we may use a\nsubscript `id_\u03b1` instead.\n\nSo if `f : \u03b1 \u2192 \u03b2`, then `f \u2218 @id \u03b1 = f` and `@id \u03b2 \u2218 f = f`.\n-/\n\n#check p\u2081 \u2218 @id \u2115\n#check @id \u2124 \u2218 p\u2081\n\nend identity\n\nsection inverse_examples\n\n/-\nGiven a function `f : \u03b1 \u2192 \u03b2`, a function `g : \u03b2 \u2192 \u03b1` is a *right inverse* of `f` if\n`\u2200 b : \u03b2, f (g b) = b`. The function `h : \u03b2 \u2192 \u03b1` is a *left inverse* of `f` if\n`\u2200 a : \u03b1, h (f a) = a`. The notions are captured by the Lean defintions `right_inverse` and\n`left_inverse`.\n\nAn equivalent characterisation:\n\nGiven a function `f : \u03b1 \u2192 \u03b2`, a function `g : \u03b2 \u2192 \u03b1` is a *right inverse* of `f` if `f \u2218 g = @id \u03b2`.\nA function `h : \u03b2 \u2192 \u03b1` is a *left inverse* of `f` if `h \u2218 f = @id \u03b1`.\n\nGiven `k\u2081 : left_inverse h f`, i.e. that `h` is a left inverse of `f` &\ngiven `k\u2082 : right_inverse g f`, i.e. that `g` is a right inverse of `f`,\n`left_inverse.comp_eq_id k\u2081` is a proof that `h \u2218 f = id` and\n`right_inverse.comp_eq_id k\u2082` is a proof that `f \u2218 g = id`.\n\nNote: if `g` is a right inverse of `f`, then `f` is a left inverse of `g`, and vice versa.\n-/\n#print left_inverse\n#print right_inverse\n\n\n-- We'll construct a left inverse of the function `f\u2081 : \u2115 \u2192 \u2124`, `f\u2081 x = x + 3`.\ndef f\u2081 (x : \u2115) : \u2124 := x + 3\n\n/-\nThe function `\u03c6\u2081` below is defined piecewise.\n-/\ndef \u03c6\u2081 : \u2124 \u2192 \u2115\n| (n + 3 : \u2115) := n -- If `x \u2265 -3`, then `\u03c6\u2081 x = x - 3`.\n| _ := 0           -- Otherwise, `\u03c6\u2081 x = 0`.\n\n#eval \u03c6\u2081 2 -- `\u03c6\u2081 2 = 0`\n#eval \u03c6\u2081 8 -- `\u03c6\u2081 8 = 8 - 3 = 5`.\n\n-- We show `\u03c6\u2081` is a left inverse of `f\u2081` (equally, `f\u2081` is a right inverse of `\u03c6\u2081`).\nlemma left_inv_phi1f1: left_inverse \u03c6\u2081 f\u2081 :=\nbegin\n  intro x, -- Assume `x : \u2115`. It suffices to prove `\u03c6\u2081 (f\u2081 x) = x`.\n  split, -- This holds for each of the cases that define `\u03c6\u2081`.\nend\n\n/-\nHere's another piecewise function.\n-/\ndef \u03c6\u2082 : \u2124 \u2192 \u2115\n| (n + 3 : \u2115) := n -- If `x \u2265 3`, then `\u03c6\u2082 x = x - 3`.\n| _ := 720           -- Otherwise, `\u03c6\u2082 x = 720`.\n\n#eval \u03c6\u2082 2 -- `\u03c6\u2082 2 = 720`\n#eval \u03c6\u2082 8 -- `\u03c6\u2082 8 = 8 - 3 = 5`.\n\n-- We show `\u03c6\u2082` is also a left inverse of `f\u2081` (equally, `f\u2081` is a right inverse of `\u03c6\u2082`).\nlemma left_inv_phi2f1 : left_inverse \u03c6\u2082 f\u2081  :=\nbegin\n  intro x, -- Assume `x : \u2115`. It suffices to prove `\u03c6\u2082 (f\u2081 x) = x`.\n  split, -- This holds for each of the cases that define `\u03c6\u2082`.\nend\n\n/-\nThe upshot of these two examples is that even when a function has a left inverse, that left inverse\nneed not be *unique*. Here, both `\u03c6\u2081` and `\u03c6\u2082` are left inverses of `f\u2081`.\n-/\n\n/-\nAs noted, `f\u2081` is a right inverse of `\u03c6\u2081`. We'll now find *another* right inverse of `\u03c6\u2081`.\n-/\ndef f\u2082 : \u2115 \u2192 \u2124\n| 0 := 2        -- `f\u2082 0 = 2`. For other values, `n`, of the input,\n| n := n + 3    -- `f\u2082 n = n + 3`.\n\nexample : right_inverse f\u2082 \u03c6\u2081 :=\nbegin\n  intro x, -- Assume `x : \u2115`. It suffices to prove `\u03c6\u2081 (f\u2082 x) = x`.\n  by_cases h : (x = 0), -- We consider two cases 1. `h : x = 0` and 2. `h : x \u2260 0`.\n  { rw h, -- Substituting `h : x = 0`, the goal is `\u03c6\u2081 (f\u2082 0) = 0`.\n    refl, }, -- This is true, by reflexivity.\n  { rw f\u2082,   -- Use the definition of `f\u2082`.\n    { split, },     -- Consider all\n    { exact h, },}, -- possible cases.\nend\n\nend inverse_examples\n\nsection uniqueness_theorems\n\nvariable {\u03b1 : Type*}\nvariable {\u03b2 : Type*}\n\n-- A function that has both a left and a right inverse is said to be *invertible*.\ndef invertible (f : \u03b1 \u2192 \u03b2) := has_left_inverse f \u2227 has_right_inverse f\n\n-- For example, the identity function on any type is invertible.\nexample : invertible (@id \u03b1) :=\nbegin \n  split, -- It suffices to prove `has_left_inverse (@id \u03b1)` and `has_right_inverse (@id \u03b1)`.\n  { use (@id \u03b1), -- It suffices to show `@id \u03b1` is a left inverse of `@id \u03b1`.\n    intro x, -- Assume `x : \u03b1`. It suffices to prove `id (id x) = x`.\n    unfold id, }, -- This follows by definition of `id`.\n  { use (@id \u03b1), -- It suffces to show `@id \u03b1` is a right inverse of `@id \u03b1`.\n    intro x, -- Assume `x : \u03b1`. It suffices to prove `id (id x) = x`.\n    unfold id, }, -- This follos by definition of `id`.\nend\n\n/-\nInverses are unique in the following sense. If a function `f : \u03b1 \u2192 \u03b2` has a left inverse\n`h : \u03b2 \u2192 \u03b1` and a right inverse `g : \u03b2 \u2192 \u03b1`, then `h = g`.\n\nThe proof below uses *functional extensionality*. This is the principle that, given functions\n`h : \u03b2 \u2192 \u03b1` and `g : \u03b2 \u2192 \u03b1`, the claim `h = g` is equivalent to the claim `\u2200 b : \u03b2, h b = g b`.\n-/\ntheorem left_inverse_eq_right_inverse (f : \u03b1 \u2192 \u03b2) (g h : \u03b2 \u2192 \u03b1) (k\u2081 : left_inverse h f)\n  (k\u2082 : right_inverse g f) : h = g :=\nbegin\n  ext b, -- Assume `b : \u03b2`. It suffices to prove `h b = g b`.\n  calc h b = h (f (g b)) : by rw k\u2082 b  -- Note `f (g b) = b`, as `g` is a right inverse of `f`.\n       ... = g b         : k\u2081 (g b) -- Further, `h (f (g b)) = g b`, as `h` is left inverse of `f`.\nend\n\n/-\nThe result can also be proved using the composite-based definition of left and right inverses.\nThe proof below, though longer, is illustrative of more general principles in algebra that you\nwill see next term and in later years.\n-/\nexample  (f : \u03b1 \u2192 \u03b2) (g h : \u03b2 \u2192 \u03b1) (k\u2081 : left_inverse h f)\n  (k\u2082 : right_inverse g f) : h = g :=\nbegin\n  calc  h = h \u2218 id        : rfl  -- This holds by reflexivity\n      ... = h \u2218 (f \u2218 g)   : by rw (right_inverse.comp_eq_id k\u2082)\n      ... = (h \u2218 f) \u2218 g   : rfl \n      ... = id \u2218 g        : by rw (left_inverse.comp_eq_id k\u2081)\n      ... = g             : rfl \nend\n\n/-\nAs a simple corrolary, every invertible function has exactly one left inverse and exactly one right\ninverse. \n-/\ntheorem unique_left_inverse_of_invertible (f : \u03b1 \u2192 \u03b2) (fi : invertible f) (h\u2081 h\u2082 : \u03b2 \u2192 \u03b1)\n  (k\u2081 : left_inverse h\u2081 f) (k\u2082 : left_inverse h\u2082 f) : h\u2081 = h\u2082 :=\nbegin\n  sorry  \nend\n\ntheorem unique_right_inverse_of_invertible (f : \u03b1 \u2192 \u03b2) (fi : invertible f) (g\u2081 g\u2082 : \u03b2 \u2192 \u03b1)\n  (k\u2081 : right_inverse g\u2081 f) (k\u2082 : right_inverse g\u2082 f) : g\u2081 = g\u2082 :=\nbegin\n  sorry  \nend\n\n/-\nThe function `f\u2081 : \u2115 \u2192 \u2124` defined before by `f x := x + 3` has (at least) two different left\ninverses, `\u03c6\u2081` and `\u03c6\u2082`. We infer that `f\u2081` cannot be invertible!\n-/\n\nend uniqueness_theorems\n\nsection inverse_theorems\n\nvariable {\u03b1 : Type*}\nvariable {\u03b2 : Type*}\n\n/-\nWe'll show that a function is surjective if it has a right inverse.\n-/\ntheorem surjective_of_right_inverse (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) (h : right_inverse g f) :\n  surjective f :=\nbegin\n  sorry  \nend\n\n/-\nNow we'll show a function is injective if it has a left inverse. We'll give two proofs.\nThe second is nicer but it introduces some new Lean syntax.\n-/\nexample (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) (h : left_inverse g f) : injective f :=\nbegin\n  intros a\u2081 a\u2082 h\u2082, -- Assume `a\u2081 a\u2082 : \u03b1` and `h\u2082 : f a\u2081 = f a\u2082`.\n  have h\u2083 : g (f a\u2081) = g (f a\u2082),\n  { rw h\u2082, },\n  have h\u2084 : a\u2081 = g (f a\u2081), from (h a\u2081).symm,\n  have h\u2085 : g (f a\u2082) = a\u2082, from h a\u2082,\n  transitivity,\n  { exact h\u2084, },\n  { transitivity,\n    { exact h\u2083, },\n    { exact h\u2085, }, }, \nend\n\n/-\nThe proof above used two applications of transitivity on three new hypotheses.\nCalculations like this can be expressed in `calc` mode, which simulates a\nmathematical series of calculations.\n-/\ntheorem injective_of_left_inverse (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) (h : left_inverse g f) : injective f :=\nbegin\n  intros a\u2081 a\u2082 h\u2082, -- Assume `a\u2081 a\u2082 : \u03b1` and `h\u2082 : f a\u2081 = f a\u2082`.\n  calc a\u2081 = g (f a\u2081) : (h a\u2081).symm\n      ... = g (f a\u2082) : by rw h\u2082\n      ... = a\u2082       : h a\u2082\nend\n\n/-\nCombining the results above, we see that every invertible function is bijective.\n-/\n\ntheorem bijective_of_invertible (f : \u03b1 \u2192 \u03b2) (k : invertible f) : bijective f :=\nbegin\n  sorry    \nend\n\nend inverse_theorems\n\nsection application_of_inverse_theorems\n\n/-\nEarlier, we showed that the function `f\u2081 : \u2115 \u2192 \u2124` given by `f\u2081 x = x + 3` has a left inverse\n(indeed, it has more than one left inverse).  We infer that `f\u2081` is injective.\n-/\nexample : injective f\u2081 :=\ninjective_of_left_inverse f\u2081 \u03c6\u2081 left_inv_phi1f1\n\n/-\nIt wasn't clear at the time whether `f\u2081` has a right inverse.\nWe'll now show that `f\u2081` *doesn't* have a right inverse. We do this by using the contrapositive\nof the result that a function with a right inverse is surjective.\n-/\nexample : \u00ac(has_right_inverse f\u2081) :=\nbegin\n  intro h,\n  have h\u2082 : surjective f\u2081, from surjective_of_has_right_inverse h,\n  have h\u2083 : \u00ac(\u2203 x : \u2115, f\u2081 x = -1), -- We have `h\u2083`: there is no `x : \u2115` for which `f\u2081 x = -1`.\n  { push_neg,                      -- Don't be too concerned about the details\n    intro x,                       -- of the proof of `h\u2083`.\n    unfold f\u2081,\n    have : \u2191x + (3 : \u2124) \u2265 0,\n    { norm_num, },\n    linarith, },\n  specialize h\u2082 (-1 : \u2124), -- By surjectivity of `f\u2081`, `\u2203 a : \u2115, f\u2081 a = -1`.\n  exact h\u2083 h\u2082, -- But this contradicts `h\u2083`.\nend\n\n/-\nLikewise, we'll show that `\u03c6\u2081` is surjective, but does not have a left inverse.\nN.B. `left_inv_phi1f1` below is equivalent to the assertion that `f\u2081` is a right inverse of `\u03c6\u2081`.\n-/\n\nexample : surjective \u03c6\u2081 :=\nsurjective_of_right_inverse \u03c6\u2081 f\u2081 left_inv_phi1f1\n\nexample : \u00ac(has_left_inverse \u03c6\u2081) :=\nbegin\n  intro h,\n  have h\u2082 : injective \u03c6\u2081, from injective_of_has_left_inverse h,\n  unfold injective at h\u2082,\n  have h\u2083 : \u03c6\u2081 0 = \u03c6\u2081 1,\n  { split, },\n  have h\u2084 : (0 : \u2124) = 1, from h\u2082 h\u2083,\n  linarith,\nend\n\nend application_of_inverse_theorems\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_33_identity_and_inverse_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.732161981429468}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n-/\nimport data.complex.exponential\nimport analysis.calculus.inverse\nimport measure_theory.borel_space\nimport analysis.complex.real_deriv\n\n/-!\n# Complex and real exponential, real logarithm\n\n## Main statements\n\nThis file establishes the basic analytical properties of the complex and real exponential functions\n(continuity, differentiability, computation of the derivative).\n\nIt also contains the definition of the real logarithm function (as the inverse of the\nexponential on `(0, +\u221e)`, extended to `\u211d` by setting `log (-x) = log x`) and its basic\nproperties (continuity, differentiability, formula for the derivative).\n\nThe complex logarithm is *not* defined in this file as it relies on trigonometric functions. See\ninstead `trigonometric.lean`.\n\n## Tags\n\nexp, log\n-/\n\nnoncomputable theory\n\nopen finset filter metric asymptotics set function\nopen_locale classical topological_space\n\nnamespace complex\n\nlemma measurable_re : measurable re := continuous_re.measurable\n\nlemma measurable_im : measurable im := continuous_im.measurable\n\nlemma measurable_of_real : measurable (coe : \u211d \u2192 \u2102) := continuous_of_real.measurable\n\n/-- The complex exponential is everywhere differentiable, with the derivative `exp x`. -/\nlemma has_deriv_at_exp (x : \u2102) : has_deriv_at exp (exp x) x :=\nbegin\n  rw has_deriv_at_iff_is_o_nhds_zero,\n  have : (1 : \u2115) < 2 := by norm_num,\n  refine (is_O.of_bound (\u2225exp x\u2225) _).trans_is_o (is_o_pow_id this),\n  filter_upwards [metric.ball_mem_nhds (0 : \u2102) zero_lt_one],\n  simp only [metric.mem_ball, dist_zero_right, normed_field.norm_pow],\n  intros z hz,\n  calc \u2225exp (x + z) - exp x - z * exp x\u2225\n    = \u2225exp x * (exp z - 1 - z)\u2225 : by { congr, rw [exp_add], ring }\n    ... = \u2225exp x\u2225 * \u2225exp z - 1 - z\u2225 : normed_field.norm_mul _ _\n    ... \u2264 \u2225exp x\u2225 * \u2225z\u2225^2 :\n      mul_le_mul_of_nonneg_left (abs_exp_sub_one_sub_id_le (le_of_lt hz)) (norm_nonneg _)\nend\n\nlemma differentiable_exp : differentiable \u2102 exp :=\n\u03bbx, (has_deriv_at_exp x).differentiable_at\n\nlemma differentiable_at_exp {x : \u2102} : differentiable_at \u2102 exp x :=\ndifferentiable_exp x\n\n@[simp] lemma deriv_exp : deriv exp = exp :=\nfunext $ \u03bb x, (has_deriv_at_exp x).deriv\n\n@[simp] lemma iter_deriv_exp : \u2200 n : \u2115, (deriv^[n] exp) = exp\n| 0 := rfl\n| (n+1) := by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]\n\n@[continuity] lemma continuous_exp : continuous exp :=\ndifferentiable_exp.continuous\n\nlemma continuous_on_exp {s : set \u2102} : continuous_on exp s :=\ncontinuous_exp.continuous_on\n\nlemma times_cont_diff_exp : \u2200 {n}, times_cont_diff \u2102 n exp :=\nbegin\n  refine times_cont_diff_all_iff_nat.2 (\u03bb n, _),\n  induction n with n ihn,\n  { exact times_cont_diff_zero.2 continuous_exp },\n  { rw times_cont_diff_succ_iff_deriv,\n    use differentiable_exp,\n    rwa deriv_exp }\nend\n\nlemma has_strict_deriv_at_exp (x : \u2102) : has_strict_deriv_at exp (exp x) x :=\ntimes_cont_diff_exp.times_cont_diff_at.has_strict_deriv_at' (has_deriv_at_exp x) le_rfl\n\nlemma is_open_map_exp : is_open_map exp :=\nopen_map_of_strict_deriv has_strict_deriv_at_exp exp_ne_zero\n\nlemma measurable_exp : measurable exp := continuous_exp.measurable\n\nend complex\n\nsection\nvariables {f : \u2102 \u2192 \u2102} {f' x : \u2102} {s : set \u2102}\n\nlemma has_strict_deriv_at.cexp (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.exp (f x)) (complex.exp (f x) * f') x :=\n(complex.has_strict_deriv_at_exp (f x)).comp x hf\n\nlemma has_deriv_at.cexp (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.exp (f x)) (complex.exp (f x) * f') x :=\n(complex.has_deriv_at_exp (f x)).comp x hf\n\nlemma has_deriv_within_at.cexp (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.exp (f x)) (complex.exp (f x) * f') s x :=\n(complex.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_cexp (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.exp (f x)) s x = complex.exp (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.cexp.deriv_within hxs\n\n@[simp] lemma deriv_cexp (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.exp (f x)) x = complex.exp (f x) * (deriv f x) :=\nhc.has_deriv_at.cexp.deriv\n\nend\n\nsection\n\nvariables {E : Type*} [normed_group E] [normed_space \u2102 E] {f : E \u2192 \u2102} {f' : E \u2192L[\u2102] \u2102}\n  {x : E} {s : set E}\n\nlemma measurable.cexp {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u2102} (hf : measurable f) :\n  measurable (\u03bb x, complex.exp (f x)) :=\ncomplex.measurable_exp.comp hf\n\nlemma has_strict_fderiv_at.cexp (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.exp (f x)) (complex.exp (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_exp (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_within_at.cexp (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.exp (f x)) (complex.exp (f x) \u2022 f') s x :=\n(complex.has_deriv_at_exp (f x)).comp_has_fderiv_within_at x hf\n\nlemma has_fderiv_at.cexp (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.exp (f x)) (complex.exp (f x) \u2022 f') x :=\nhas_fderiv_within_at_univ.1 $ hf.has_fderiv_within_at.cexp\n\nlemma differentiable_within_at.cexp (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.exp (f x)) s x :=\nhf.has_fderiv_within_at.cexp.differentiable_within_at\n\n@[simp] lemma differentiable_at.cexp (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.exp (f x)) x :=\nhc.has_fderiv_at.cexp.differentiable_at\n\nlemma differentiable_on.cexp (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.exp (f x)) s :=\n\u03bbx h, (hc x h).cexp\n\n@[simp] lemma differentiable.cexp (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.exp (f x)) :=\n\u03bbx, (hc x).cexp\n\nlemma times_cont_diff.cexp {n} (h : times_cont_diff \u2102 n f) :\n  times_cont_diff \u2102 n (\u03bb x, complex.exp (f x)) :=\ncomplex.times_cont_diff_exp.comp h\n\nlemma times_cont_diff_at.cexp {n} (hf : times_cont_diff_at \u2102 n f x) :\n  times_cont_diff_at \u2102 n (\u03bb x, complex.exp (f x)) x :=\ncomplex.times_cont_diff_exp.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.cexp {n} (hf : times_cont_diff_on \u2102 n f s) :\n  times_cont_diff_on \u2102 n (\u03bb x, complex.exp (f x)) s :=\ncomplex.times_cont_diff_exp.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.cexp {n} (hf : times_cont_diff_within_at \u2102 n f s x) :\n  times_cont_diff_within_at \u2102 n (\u03bb x, complex.exp (f x)) s x :=\ncomplex.times_cont_diff_exp.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\nend\n\nnamespace real\n\nvariables {x y z : \u211d}\n\nlemma has_strict_deriv_at_exp (x : \u211d) : has_strict_deriv_at exp (exp x) x :=\n(complex.has_strict_deriv_at_exp x).real_of_complex\n\nlemma has_deriv_at_exp (x : \u211d) : has_deriv_at exp (exp x) x :=\n(complex.has_deriv_at_exp x).real_of_complex\n\nlemma times_cont_diff_exp {n} : times_cont_diff \u211d n exp :=\ncomplex.times_cont_diff_exp.real_of_complex\n\nlemma differentiable_exp : differentiable \u211d exp :=\n\u03bbx, (has_deriv_at_exp x).differentiable_at\n\nlemma differentiable_at_exp : differentiable_at \u211d exp x :=\ndifferentiable_exp x\n\n@[simp] lemma deriv_exp : deriv exp = exp :=\nfunext $ \u03bb x, (has_deriv_at_exp x).deriv\n\n@[simp] lemma iter_deriv_exp : \u2200 n : \u2115, (deriv^[n] exp) = exp\n| 0 := rfl\n| (n+1) := by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]\n\n@[continuity] lemma continuous_exp : continuous exp :=\ndifferentiable_exp.continuous\n\nlemma continuous_on_exp {s : set \u211d} : continuous_on exp s :=\ncontinuous_exp.continuous_on\n\nlemma measurable_exp : measurable exp := continuous_exp.measurable\n\nend real\n\n\nsection\n/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable\nfunction, for standalone use and use with `simp`. -/\n\nvariables {f : \u211d \u2192 \u211d} {f' x : \u211d} {s : set \u211d}\n\nlemma has_strict_deriv_at.exp (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.exp (f x)) (real.exp (f x) * f') x :=\n(real.has_strict_deriv_at_exp (f x)).comp x hf\n\nlemma has_deriv_at.exp (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.exp (f x)) (real.exp (f x) * f') x :=\n(real.has_deriv_at_exp (f x)).comp x hf\n\nlemma has_deriv_within_at.exp (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.exp (f x)) (real.exp (f x) * f') s x :=\n(real.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_exp (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.exp (f x)) s x = real.exp (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.exp.deriv_within hxs\n\n@[simp] lemma deriv_exp (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.exp (f x)) x = real.exp (f x) * (deriv f x) :=\nhc.has_deriv_at.exp.deriv\n\nend\n\nsection\n/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable\nfunction, for standalone use and use with `simp`. -/\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E] {f : E \u2192 \u211d} {f' : E \u2192L[\u211d] \u211d}\n  {x : E} {s : set E}\n\nlemma measurable.exp {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d} (hf : measurable f) :\n  measurable (\u03bb x, real.exp (f x)) :=\nreal.measurable_exp.comp hf\n\nlemma times_cont_diff.exp {n} (hf : times_cont_diff \u211d n f) :\n  times_cont_diff \u211d n (\u03bb x, real.exp (f x)) :=\nreal.times_cont_diff_exp.comp hf\n\nlemma times_cont_diff_at.exp {n} (hf : times_cont_diff_at \u211d n f x) :\n  times_cont_diff_at \u211d n (\u03bb x, real.exp (f x)) x :=\nreal.times_cont_diff_exp.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.exp {n} (hf : times_cont_diff_on \u211d n f s) :\n  times_cont_diff_on \u211d n (\u03bb x, real.exp (f x)) s :=\nreal.times_cont_diff_exp.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.exp {n} (hf : times_cont_diff_within_at \u211d n f s x) :\n  times_cont_diff_within_at \u211d n (\u03bb x, real.exp (f x)) s x :=\nreal.times_cont_diff_exp.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\nlemma has_fderiv_within_at.exp (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.exp (f x)) (real.exp (f x) \u2022 f') s x :=\n(real.has_deriv_at_exp (f x)).comp_has_fderiv_within_at x hf\n\nlemma has_fderiv_at.exp (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.exp (f x)) (real.exp (f x) \u2022 f') x :=\n(real.has_deriv_at_exp (f x)).comp_has_fderiv_at x hf\n\nlemma has_strict_fderiv_at.exp (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.exp (f x)) (real.exp (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_exp (f x)).comp_has_strict_fderiv_at x hf\n\nlemma differentiable_within_at.exp (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.exp (f x)) s x :=\nhf.has_fderiv_within_at.exp.differentiable_within_at\n\n@[simp] lemma differentiable_at.exp (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.exp (f x)) x :=\nhc.has_fderiv_at.exp.differentiable_at\n\nlemma differentiable_on.exp (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.exp (f x)) s :=\n\u03bb x h, (hc x h).exp\n\n@[simp] lemma differentiable.exp (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.exp (f x)) :=\n\u03bb x, (hc x).exp\n\nlemma fderiv_within_exp (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.exp (f x)) s x = real.exp (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.exp.fderiv_within hxs\n\n@[simp] lemma fderiv_exp (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.exp (f x)) x = real.exp (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.exp.fderiv\n\nend\n\nnamespace real\n\nvariables {x y z : \u211d}\n\n/-- The real exponential function tends to `+\u221e` at `+\u221e`. -/\nlemma tendsto_exp_at_top : tendsto exp at_top at_top :=\nbegin\n  have A : tendsto (\u03bbx:\u211d, x + 1) at_top at_top :=\n    tendsto_at_top_add_const_right at_top 1 tendsto_id,\n  have B : \u2200\u1da0 x in at_top, x + 1 \u2264 exp x :=\n    eventually_at_top.2 \u27e80, \u03bbx hx, add_one_le_exp_of_nonneg hx\u27e9,\n  exact tendsto_at_top_mono' at_top B A\nend\n\n/-- The real exponential function tends to `0` at `-\u221e` or, equivalently, `exp(-x)` tends to `0`\nat `+\u221e` -/\nlemma tendsto_exp_neg_at_top_nhds_0 : tendsto (\u03bbx, exp (-x)) at_top (\ud835\udcdd 0) :=\n(tendsto_inv_at_top_zero.comp tendsto_exp_at_top).congr (\u03bbx, (exp_neg x).symm)\n\n/-- The real exponential function tends to `1` at `0`. -/\nlemma tendsto_exp_nhds_0_nhds_1 : tendsto exp (\ud835\udcdd 0) (\ud835\udcdd 1) :=\nby { convert continuous_exp.tendsto 0, simp }\n\nlemma tendsto_exp_at_bot : tendsto exp at_bot (\ud835\udcdd 0) :=\n(tendsto_exp_neg_at_top_nhds_0.comp tendsto_neg_at_bot_at_top).congr $\n  \u03bb x, congr_arg exp $ neg_neg x\n\nlemma tendsto_exp_at_bot_nhds_within : tendsto exp at_bot (\ud835\udcdd[Ioi 0] 0) :=\ntendsto_inf.2 \u27e8tendsto_exp_at_bot, tendsto_principal.2 $ eventually_of_forall exp_pos\u27e9\n\n/-- `real.exp` as an order isomorphism between `\u211d` and `(0, +\u221e)`. -/\ndef exp_order_iso : \u211d \u2243o Ioi (0 : \u211d) :=\nstrict_mono.order_iso_of_surjective _ (exp_strict_mono.cod_restrict exp_pos) $\n  (continuous_subtype_mk _ continuous_exp).surjective\n    (by simp only [tendsto_Ioi_at_top, subtype.coe_mk, tendsto_exp_at_top])\n    (by simp [tendsto_exp_at_bot_nhds_within])\n\n@[simp] lemma coe_exp_order_iso_apply (x : \u211d) : (exp_order_iso x : \u211d) = exp x := rfl\n\n@[simp] lemma coe_comp_exp_order_iso : coe \u2218 exp_order_iso = exp := rfl\n\n@[simp] lemma range_exp : range exp = Ioi 0 :=\nby rw [\u2190 coe_comp_exp_order_iso, range_comp, exp_order_iso.range_eq, image_univ, subtype.range_coe]\n\n@[simp] lemma map_exp_at_top : map exp at_top = at_top :=\nby rw [\u2190 coe_comp_exp_order_iso, \u2190 filter.map_map, order_iso.map_at_top, map_coe_Ioi_at_top]\n\n@[simp] lemma comap_exp_at_top : comap exp at_top = at_top :=\nby rw [\u2190 map_exp_at_top, comap_map exp_injective, map_exp_at_top]\n\n@[simp] lemma tendsto_exp_comp_at_top {\u03b1 : Type*} {l : filter \u03b1} {f : \u03b1 \u2192 \u211d} :\n  tendsto (\u03bb x, exp (f x)) l at_top \u2194 tendsto f l at_top :=\nby rw [\u2190 tendsto_comap_iff, comap_exp_at_top]\n\nlemma tendsto_comp_exp_at_top {\u03b1 : Type*} {l : filter \u03b1} {f : \u211d \u2192 \u03b1} :\n  tendsto (\u03bb x, f (exp x)) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 tendsto_map'_iff, map_exp_at_top]\n\n@[simp] lemma map_exp_at_bot : map exp at_bot = \ud835\udcdd[Ioi 0] 0 :=\nby rw [\u2190 coe_comp_exp_order_iso, \u2190 filter.map_map, exp_order_iso.map_at_bot, \u2190 map_coe_Ioi_at_bot]\n\nlemma comap_exp_nhds_within_Ioi_zero : comap exp (\ud835\udcdd[Ioi 0] 0) = at_bot :=\nby rw [\u2190 map_exp_at_bot, comap_map exp_injective]\n\nlemma tendsto_comp_exp_at_bot {\u03b1 : Type*} {l : filter \u03b1} {f : \u211d \u2192 \u03b1} :\n  tendsto (\u03bb x, f (exp x)) at_bot l \u2194 tendsto f (\ud835\udcdd[Ioi 0] 0) l :=\nby rw [\u2190 map_exp_at_bot, tendsto_map'_iff]\n\n/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,\nto `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to\n`(-\u221e, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and\nthe derivative of `log` is `1/x` away from `0`. -/\n@[pp_nodot] noncomputable def log (x : \u211d) : \u211d :=\nif hx : x = 0 then 0 else exp_order_iso.symm \u27e8abs x, abs_pos.2 hx\u27e9\n\nlemma log_of_ne_zero (hx : x \u2260 0) : log x = exp_order_iso.symm \u27e8abs x, abs_pos.2 hx\u27e9 := dif_neg hx\n\nlemma log_of_pos (hx : 0 < x) : log x = exp_order_iso.symm \u27e8x, hx\u27e9 :=\nby { rw [log_of_ne_zero hx.ne'], congr, exact abs_of_pos hx }\n\nlemma exp_log_eq_abs (hx : x \u2260 0) : exp (log x) = abs x :=\nby rw [log_of_ne_zero hx, \u2190 coe_exp_order_iso_apply, order_iso.apply_symm_apply, subtype.coe_mk]\n\nlemma exp_log (hx : 0 < x) : exp (log x) = x :=\nby { rw exp_log_eq_abs hx.ne', exact abs_of_pos hx }\n\nlemma exp_log_of_neg (hx : x < 0) : exp (log x) = -x :=\nby { rw exp_log_eq_abs (ne_of_lt hx), exact abs_of_neg hx }\n\n@[simp] lemma log_exp (x : \u211d) : log (exp x) = x :=\nexp_injective $ exp_log (exp_pos x)\n\nlemma surj_on_log : surj_on log (Ioi 0) univ :=\n\u03bb x _, \u27e8exp x, exp_pos x, log_exp x\u27e9\n\nlemma log_surjective : surjective log :=\n\u03bb x, \u27e8exp x, log_exp x\u27e9\n\n@[simp] lemma range_log : range log = univ :=\nlog_surjective.range_eq\n\n@[simp] lemma log_zero : log 0 = 0 := dif_pos rfl\n\n@[simp] lemma log_one : log 1 = 0 :=\nexp_injective $ by rw [exp_log zero_lt_one, exp_zero]\n\n@[simp] lemma log_abs (x : \u211d) : log (abs x) = log x :=\nbegin\n  by_cases h : x = 0,\n  { simp [h] },\n  { rw [\u2190 exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] }\nend\n\n@[simp] lemma log_neg_eq_log (x : \u211d) : log (-x) = log x :=\nby rw [\u2190 log_abs x, \u2190 log_abs (-x), abs_neg]\n\nlemma surj_on_log' : surj_on log (Iio 0) univ :=\n\u03bb x _, \u27e8-exp x, neg_lt_zero.2 $ exp_pos x, by rw [log_neg_eq_log, log_exp]\u27e9\n\nlemma log_mul (hx : x \u2260 0) (hy : y \u2260 0) : log (x * y) = log x + log y :=\nexp_injective $\nby rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]\n\nlemma log_div (hx : x \u2260 0) (hy : y \u2260 0) : log (x / y) = log x - log y :=\nexp_injective $\nby rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]\n\n@[simp] lemma log_inv (x : \u211d) : log (x\u207b\u00b9) = -log x :=\nbegin\n  by_cases hx : x = 0, { simp [hx] },\n  rw [\u2190 exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]\nend\n\nlemma log_le_log (h : 0 < x) (h\u2081 : 0 < y) : real.log x \u2264 real.log y \u2194 x \u2264 y :=\nby rw [\u2190 exp_le_exp, exp_log h, exp_log h\u2081]\n\nlemma log_lt_log (hx : 0 < x) : x < y \u2192 log x < log y :=\nby { intro h, rwa [\u2190 exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] }\n\nlemma log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y \u2194 x < y :=\nby { rw [\u2190 exp_lt_exp, exp_log hx, exp_log hy] }\n\nlemma log_pos_iff (hx : 0 < x) : 0 < log x \u2194 1 < x :=\nby { rw \u2190 log_one, exact log_lt_log_iff zero_lt_one hx }\n\nlemma log_pos (hx : 1 < x) : 0 < log x :=\n(log_pos_iff (lt_trans zero_lt_one hx)).2 hx\n\nlemma log_neg_iff (h : 0 < x) : log x < 0 \u2194 x < 1 :=\nby { rw \u2190 log_one, exact log_lt_log_iff h zero_lt_one }\n\nlemma log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1\n\nlemma log_nonneg_iff (hx : 0 < x) : 0 \u2264 log x \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, log_neg_iff hx, not_lt]\n\nlemma log_nonneg (hx : 1 \u2264 x) : 0 \u2264 log x :=\n(log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx\n\nlemma log_nonpos_iff (hx : 0 < x) : log x \u2264 0 \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, log_pos_iff hx, not_lt]\n\nlemma log_nonpos_iff' (hx : 0 \u2264 x) : log x \u2264 0 \u2194 x \u2264 1 :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { simp [le_refl, zero_le_one] },\n  exact log_nonpos_iff hx\nend\n\nlemma log_nonpos (hx : 0 \u2264 x) (h'x : x \u2264 1) : log x \u2264 0 :=\n(log_nonpos_iff' hx).2 h'x\n\nlemma strict_mono_incr_on_log : strict_mono_incr_on log (set.Ioi 0) :=\n\u03bb x hx y hy hxy, log_lt_log hx hxy\n\nlemma strict_mono_decr_on_log : strict_mono_decr_on log (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 log_abs y, \u2190 log_abs x],\n  refine log_lt_log (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]\nend\n\nlemma log_inj_on_pos : set.inj_on log (set.Ioi 0) :=\nstrict_mono_incr_on_log.inj_on\n\nlemma eq_one_of_pos_of_log_eq_zero {x : \u211d} (h\u2081 : 0 < x) (h\u2082 : log x = 0) : x = 1 :=\nlog_inj_on_pos (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one) (h\u2082.trans real.log_one.symm)\n\nlemma log_ne_zero_of_pos_of_ne_one {x : \u211d} (hx_pos : 0 < x) (hx : x \u2260 1) : log x \u2260 0 :=\nmt (eq_one_of_pos_of_log_eq_zero hx_pos) hx\n\n/-- The real logarithm function tends to `+\u221e` at `+\u221e`. -/\nlemma tendsto_log_at_top : tendsto log at_top at_top :=\ntendsto_comp_exp_at_top.1 $ by simpa only [log_exp] using tendsto_id\n\nlemma tendsto_log_nhds_within_zero : tendsto log (\ud835\udcdd[{0}\u1d9c] 0) at_bot :=\nbegin\n  rw [\u2190 (show _ = log, from funext log_abs)],\n  refine tendsto.comp _ tendsto_abs_nhds_within_zero,\n  simpa [\u2190 tendsto_comp_exp_at_bot] using tendsto_id\nend\n\nlemma continuous_on_log : continuous_on log {0}\u1d9c :=\nbegin\n  rw [continuous_on_iff_continuous_restrict, restrict],\n  conv in (log _) { rw [log_of_ne_zero (show (x : \u211d) \u2260 0, from x.2)] },\n  exact exp_order_iso.symm.continuous.comp (continuous_subtype_mk _ continuous_subtype_coe.norm)\nend\n\n@[continuity] lemma continuous_log' : continuous (\u03bb x : {x : \u211d // 0 < x}, log x) :=\ncontinuous_on_iff_continuous_restrict.1 $ continuous_on_log.mono $ \u03bb x hx, ne_of_gt hx\n\nlemma continuous_at_log (hx : x \u2260 0) : continuous_at log x :=\n(continuous_on_log x hx).continuous_at $ mem_nhds_sets is_open_compl_singleton hx\n\n@[simp] lemma continuous_at_log_iff : continuous_at log x \u2194 x \u2260 0 :=\nbegin\n  refine \u27e8_, continuous_at_log\u27e9,\n  rintros h rfl,\n  exact not_tendsto_nhds_of_tendsto_at_bot tendsto_log_nhds_within_zero _\n    (h.tendsto.mono_left inf_le_left)\nend\n\nlemma has_strict_deriv_at_log_of_pos (hx : 0 < x) : has_strict_deriv_at log x\u207b\u00b9 x :=\nhave has_strict_deriv_at log (exp $ log x)\u207b\u00b9 x,\nfrom (has_strict_deriv_at_exp $ log x).of_local_left_inverse (continuous_at_log hx.ne')\n  (ne_of_gt $ exp_pos _) $ eventually.mono (lt_mem_nhds hx) @exp_log,\nby rwa [exp_log hx] at this\n\nlemma has_strict_deriv_at_log (hx : x \u2260 0) : has_strict_deriv_at log x\u207b\u00b9 x :=\nbegin\n  cases hx.lt_or_lt with hx hx,\n  { convert (has_strict_deriv_at_log_of_pos (neg_pos.mpr hx)).comp x (has_strict_deriv_at_neg x),\n    { ext y, exact (log_neg_eq_log y).symm },\n    { field_simp [hx.ne] } },\n  { exact has_strict_deriv_at_log_of_pos hx }\nend\n\nlemma has_deriv_at_log (hx : x \u2260 0) : has_deriv_at log x\u207b\u00b9 x :=\n(has_strict_deriv_at_log hx).has_deriv_at\n\nlemma differentiable_at_log (hx : x \u2260 0) : differentiable_at \u211d log x :=\n(has_deriv_at_log hx).differentiable_at\n\nlemma differentiable_on_log : differentiable_on \u211d log {0}\u1d9c :=\n\u03bb x hx, (differentiable_at_log hx).differentiable_within_at\n\n@[simp] lemma differentiable_at_log_iff : differentiable_at \u211d log x \u2194 x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_log_iff.1 h.continuous_at, differentiable_at_log\u27e9\n\nlemma deriv_log (x : \u211d) : deriv log x = x\u207b\u00b9 :=\nif hx : x = 0 then\n  by rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_log_iff.1 (not_not.2 hx)), hx,\n    inv_zero]\nelse (has_deriv_at_log hx).deriv\n\n@[simp] lemma deriv_log' : deriv log = has_inv.inv := funext deriv_log\n\nlemma measurable_log : measurable log :=\nmeasurable_of_measurable_on_compl_singleton 0 $ continuous.measurable $\n  continuous_on_iff_continuous_restrict.1 continuous_on_log\n\nlemma times_cont_diff_on_log {n : with_top \u2115} : times_cont_diff_on \u211d n log {0}\u1d9c :=\nbegin\n  suffices : times_cont_diff_on \u211d \u22a4 log {0}\u1d9c, from this.of_le le_top,\n  refine (times_cont_diff_on_top_iff_deriv_of_open is_open_compl_singleton).2 _,\n  simp [differentiable_on_log, times_cont_diff_on_inv]\nend\n\nlemma times_cont_diff_at_log {n : with_top \u2115} : times_cont_diff_at \u211d n log x \u2194 x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_log_iff.1 h.continuous_at,\n  \u03bb hx, (times_cont_diff_on_log x hx).times_cont_diff_at $\n    mem_nhds_sets is_open_compl_singleton hx\u27e9\n\nend real\n\nsection log_differentiable\nopen real\n\nsection continuity\n\nvariables {\u03b1 : Type*}\n\nlemma filter.tendsto.log {f : \u03b1 \u2192 \u211d} {l : filter \u03b1} {x : \u211d} (h : tendsto f l (\ud835\udcdd x)) (hx : x \u2260 0) :\n  tendsto (\u03bb x, log (f x)) l (\ud835\udcdd (log x)) :=\n(continuous_at_log hx).tendsto.comp h\n\nvariables [topological_space \u03b1] {f : \u03b1 \u2192 \u211d} {s : set \u03b1} {a : \u03b1}\n\nlemma continuous.log (hf : continuous f) (h\u2080 : \u2200 x, f x \u2260 0) : continuous (\u03bb x, log (f x)) :=\ncontinuous_on_log.comp_continuous hf h\u2080\n\nlemma continuous_at.log (hf : continuous_at f a) (h\u2080 : f a \u2260 0) :\n  continuous_at (\u03bb x, log (f x)) a :=\nhf.log h\u2080\n\nlemma continuous_within_at.log (hf : continuous_within_at f s a) (h\u2080 : f a \u2260 0) :\n  continuous_within_at (\u03bb x, log (f x)) s a :=\nhf.log h\u2080\n\nlemma continuous_on.log (hf : continuous_on f s) (h\u2080 : \u2200 x \u2208 s, f x \u2260 0) :\n  continuous_on (\u03bb x, log (f x)) s :=\n\u03bb x hx, (hf x hx).log (h\u2080 x hx)\n\nend continuity\n\nsection deriv\n\nvariables {f : \u211d \u2192 \u211d} {x f' : \u211d} {s : set \u211d}\n\nlemma measurable.log {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d} (hf : measurable f) :\n  measurable (\u03bb x, log (f x)) :=\nmeasurable_log.comp hf\n\nlemma has_deriv_within_at.log (hf : has_deriv_within_at f f' s x) (hx : f x \u2260 0) :\n  has_deriv_within_at (\u03bb y, log (f y)) (f' / (f x)) s x :=\nbegin\n  rw div_eq_inv_mul,\n  exact (has_deriv_at_log hx).comp_has_deriv_within_at x hf\nend\n\nlemma has_deriv_at.log (hf : has_deriv_at f f' x) (hx : f x \u2260 0) :\n  has_deriv_at (\u03bb y, log (f y)) (f' / f x) x :=\nbegin\n  rw \u2190 has_deriv_within_at_univ at *,\n  exact hf.log hx\nend\n\nlemma has_strict_deriv_at.log (hf : has_strict_deriv_at f f' x) (hx : f x \u2260 0) :\n  has_strict_deriv_at (\u03bb y, log (f y)) (f' / f x) x :=\nbegin\n  rw div_eq_inv_mul,\n  exact (has_strict_deriv_at_log hx).comp x hf\nend\n\nlemma deriv_within.log (hf : differentiable_within_at \u211d f s x) (hx : f x \u2260 0)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, log (f x)) s x = (deriv_within f s x) / (f x) :=\n(hf.has_deriv_within_at.log hx).deriv_within hxs\n\n@[simp] lemma deriv.log (hf : differentiable_at \u211d f x) (hx : f x \u2260 0) :\n  deriv (\u03bbx, log (f x)) x = (deriv f x) / (f x) :=\n(hf.has_deriv_at.log hx).deriv\n\nend deriv\n\nsection fderiv\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E] {f : E \u2192 \u211d} {x : E} {f' : E \u2192L[\u211d] \u211d}\n  {s : set E}\n\nlemma has_fderiv_within_at.log (hf : has_fderiv_within_at f f' s x) (hx : f x \u2260 0) :\n  has_fderiv_within_at (\u03bb x, log (f x)) ((f x)\u207b\u00b9 \u2022 f') s x :=\n(has_deriv_at_log hx).comp_has_fderiv_within_at x hf\n\nlemma has_fderiv_at.log (hf : has_fderiv_at f f' x) (hx : f x \u2260 0) :\n  has_fderiv_at (\u03bb x, log (f x)) ((f x)\u207b\u00b9 \u2022 f') x :=\n(has_deriv_at_log hx).comp_has_fderiv_at x hf\n\nlemma has_strict_fderiv_at.log (hf : has_strict_fderiv_at f f' x) (hx : f x \u2260 0) :\n  has_strict_fderiv_at (\u03bb x, log (f x)) ((f x)\u207b\u00b9 \u2022 f') x :=\n(has_strict_deriv_at_log hx).comp_has_strict_fderiv_at x hf\n\nlemma differentiable_within_at.log (hf : differentiable_within_at \u211d f s x) (hx : f x \u2260 0) :\n  differentiable_within_at \u211d (\u03bbx, log (f x)) s x :=\n(hf.has_fderiv_within_at.log hx).differentiable_within_at\n\n@[simp] lemma differentiable_at.log (hf : differentiable_at \u211d f x) (hx : f x \u2260 0) :\n  differentiable_at \u211d (\u03bbx, log (f x)) x :=\n(hf.has_fderiv_at.log hx).differentiable_at\n\nlemma times_cont_diff_at.log {n} (hf : times_cont_diff_at \u211d n f x) (hx : f x \u2260 0) :\n  times_cont_diff_at \u211d n (\u03bb x, log (f x)) x :=\n(times_cont_diff_at_log.2 hx).comp x hf\n\nlemma times_cont_diff_within_at.log {n} (hf : times_cont_diff_within_at \u211d n f s x) (hx : f x \u2260 0) :\n  times_cont_diff_within_at \u211d n (\u03bb x, log (f x)) s x :=\n(times_cont_diff_at_log.2 hx).comp_times_cont_diff_within_at x hf\n\nlemma times_cont_diff_on.log {n} (hf : times_cont_diff_on \u211d n f s) (hs : \u2200 x \u2208 s, f x \u2260 0) :\n  times_cont_diff_on \u211d n (\u03bb x, log (f x)) s :=\n\u03bb x hx, (hf x hx).log (hs x hx)\n\nlemma times_cont_diff.log {n} (hf : times_cont_diff \u211d n f) (h : \u2200 x, f x \u2260 0) :\n  times_cont_diff \u211d n (\u03bb x, log (f x)) :=\ntimes_cont_diff_iff_times_cont_diff_at.2 $ \u03bb x, hf.times_cont_diff_at.log (h x)\n\nlemma differentiable_on.log (hf : differentiable_on \u211d f s) (hx : \u2200 x \u2208 s, f x \u2260 0) :\n  differentiable_on \u211d (\u03bbx, log (f x)) s :=\n\u03bbx h, (hf x h).log (hx x h)\n\n@[simp] lemma differentiable.log (hf : differentiable \u211d f) (hx : \u2200 x, f x \u2260 0) :\n  differentiable \u211d (\u03bbx, log (f x)) :=\n\u03bbx, (hf x).log (hx x)\n\nlemma fderiv_within.log (hf : differentiable_within_at \u211d f s x) (hx : f x \u2260 0)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, log (f x)) s x = (f x)\u207b\u00b9 \u2022 fderiv_within \u211d f s x :=\n(hf.has_fderiv_within_at.log hx).fderiv_within hxs\n\n@[simp] lemma fderiv.log (hf : differentiable_at \u211d f x) (hx : f x \u2260 0) :\n  fderiv \u211d (\u03bbx, log (f x)) x = (f x)\u207b\u00b9 \u2022 fderiv \u211d f x :=\n(hf.has_fderiv_at.log hx).fderiv\n\nend fderiv\n\nend log_differentiable\n\nnamespace real\n\n/-- The function `exp(x)/x^n` tends to `+\u221e` at `+\u221e`, for any natural number `n` -/\nlemma tendsto_exp_div_pow_at_top (n : \u2115) : tendsto (\u03bbx, exp x / x^n) at_top at_top :=\nbegin\n  refine (at_top_basis_Ioi.tendsto_iff (at_top_basis' 1)).2 (\u03bb C hC\u2081, _),\n  have hC\u2080 : 0 < C, from zero_lt_one.trans_le hC\u2081,\n  have : 0 < (exp 1 * C)\u207b\u00b9 := inv_pos.2 (mul_pos (exp_pos _) hC\u2080),\n  obtain \u27e8N, hN\u27e9 : \u2203 N, \u2200 k \u2265 N, (\u2191k ^ n : \u211d) / exp 1 ^ k < (exp 1 * C)\u207b\u00b9 :=\n    eventually_at_top.1 ((tendsto_pow_const_div_const_pow_of_one_lt n\n      (one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)),\n  simp only [\u2190 exp_nat_mul, mul_one, div_lt_iff, exp_pos, \u2190 div_eq_inv_mul] at hN,\n  refine \u27e8N, trivial, \u03bb x hx, _\u27e9, rw mem_Ioi at hx,\n  have hx\u2080 : 0 < x, from N.cast_nonneg.trans_lt hx,\n  rw [mem_Ici, le_div_iff (pow_pos hx\u2080 _), \u2190 le_div_iff' hC\u2080],\n  calc x ^ n \u2264 (nat_ceil x) ^ n : pow_le_pow_of_le_left hx\u2080.le (le_nat_ceil _) _\n  ... \u2264 exp (nat_ceil x) / (exp 1 * C) : (hN _ (lt_nat_ceil.2 hx).le).le\n  ... \u2264 exp (x + 1) / (exp 1 * C) : div_le_div_of_le (mul_pos (exp_pos _) hC\u2080).le\n    (exp_le_exp.2 $ (nat_ceil_lt_add_one hx\u2080.le).le)\n  ... = exp x / C : by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne']\nend\n\n/-- The function `x^n * exp(-x)` tends to `0` at `+\u221e`, for any natural number `n`. -/\nlemma tendsto_pow_mul_exp_neg_at_top_nhds_0 (n : \u2115) : tendsto (\u03bbx, x^n * exp (-x)) at_top (\ud835\udcdd 0) :=\n(tendsto_inv_at_top_zero.comp (tendsto_exp_div_pow_at_top n)).congr $ \u03bbx,\n  by rw [comp_app, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg]\n\n/-- The function `(b * exp x + c) / (x ^ n)` tends to `+\u221e` at `+\u221e`, for any positive natural number\n`n` and any real numbers `b` and `c` such that `b` is positive. -/\nlemma tendsto_mul_exp_add_div_pow_at_top (b c : \u211d) (n : \u2115) (hb : 0 < b) (hn : 1 \u2264 n) :\n  tendsto (\u03bb x, (b * (exp x) + c) / (x^n)) at_top at_top :=\nbegin\n  refine tendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top 0) _)\n    (((tendsto_exp_div_pow_at_top n).const_mul_at_top hb).at_top_add\n      ((tendsto_pow_neg_at_top hn).mul (@tendsto_const_nhds _ _ _ c _))),\n  intros x hx,\n  simp only [fpow_neg x n],\n  ring,\nend\n\n/-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+\u221e`, for any positive natural number\n`n` and any real numbers `b` and `c` such that `b` is nonzero. -/\nlemma tendsto_div_pow_mul_exp_add_at_top (b c : \u211d) (n : \u2115) (hb : 0 \u2260 b) (hn : 1 \u2264 n) :\n  tendsto (\u03bb x, x^n / (b * (exp x) + c)) at_top (\ud835\udcdd 0) :=\nbegin\n  have H : \u2200 d e, 0 < d \u2192 tendsto (\u03bb (x:\u211d), x^n / (d * (exp x) + e)) at_top (\ud835\udcdd 0),\n  { intros b' c' h,\n    convert (tendsto_mul_exp_add_div_pow_at_top b' c' n h hn).inv_tendsto_at_top ,\n    ext x,\n    simpa only [pi.inv_apply] using inv_div.symm },\n  cases lt_or_gt_of_ne hb,\n  { exact H b c h },\n  { convert (H (-b) (-c) (neg_pos.mpr h)).neg,\n    { ext x,\n      field_simp,\n      rw [\u2190 neg_add (b * exp x) c, neg_div_neg_eq] },\n    { exact neg_zero.symm } },\nend\n\nopen_locale big_operators\n\n/-- A crude lemma estimating the difference between `log (1-x)` and its Taylor series at `0`,\nwhere the main point of the bound is that it tends to `0`. The goal is to deduce the series\nexpansion of the logarithm, in `has_sum_pow_div_log_of_abs_lt_1`.\n-/\nlemma abs_log_sub_add_sum_range_le {x : \u211d} (h : abs x < 1) (n : \u2115) :\n  abs ((\u2211 i in range n, x^(i+1)/(i+1)) + log (1-x)) \u2264 (abs x)^(n+1) / (1 - abs x) :=\nbegin\n  /- For the proof, we show that the derivative of the function to be estimated is small,\n  and then apply the mean value inequality. -/\n  let F : \u211d \u2192 \u211d := \u03bb x, \u2211 i in range n, x^(i+1)/(i+1) + log (1-x),\n  -- First step: compute the derivative of `F`\n  have A : \u2200 y \u2208 Ioo (-1 : \u211d) 1, deriv F y = - (y^n) / (1 - y),\n  { assume y hy,\n    have : (\u2211 i in range n, (\u2191i + 1) * y ^ i / (\u2191i + 1)) = (\u2211 i in range n, y ^ i),\n    { congr' with i,\n      have : (i : \u211d) + 1 \u2260 0 := ne_of_gt (nat.cast_add_one_pos i),\n      field_simp [this, mul_comm] },\n    field_simp [F, this, \u2190 geom_sum_def, geom_sum_eq (ne_of_lt hy.2),\n                sub_ne_zero_of_ne (ne_of_gt hy.2), sub_ne_zero_of_ne (ne_of_lt hy.2)],\n    ring },\n  -- second step: show that the derivative of `F` is small\n  have B : \u2200 y \u2208 Icc (-abs x) (abs x), abs (deriv F y) \u2264 (abs x)^n / (1 - abs x),\n  { assume y hy,\n    have : y \u2208 Ioo (-(1 : \u211d)) 1 := \u27e8lt_of_lt_of_le (neg_lt_neg h) hy.1, lt_of_le_of_lt hy.2 h\u27e9,\n    calc abs (deriv F y) = abs (-(y^n) / (1 - y)) : by rw [A y this]\n    ... \u2264 (abs x)^n / (1 - abs x) :\n      begin\n        have : abs y \u2264 abs x := abs_le.2 hy,\n        have : 0 < 1 - abs x, by linarith,\n        have : 1 - abs x \u2264 abs (1 - y) := le_trans (by linarith [hy.2]) (le_abs_self _),\n        simp only [\u2190 pow_abs, abs_div, abs_neg],\n        apply_rules [div_le_div, pow_nonneg, abs_nonneg, pow_le_pow_of_le_left]\n      end },\n  -- third step: apply the mean value inequality\n  have C : \u2225F x - F 0\u2225 \u2264 ((abs x)^n / (1 - abs x)) * \u2225x - 0\u2225,\n  { have : \u2200 y \u2208 Icc (- abs x) (abs x), differentiable_at \u211d F y,\n    { assume y hy,\n      have : 1 - y \u2260 0 := sub_ne_zero_of_ne (ne_of_gt (lt_of_le_of_lt hy.2 h)),\n      simp [F, this] },\n    apply convex.norm_image_sub_le_of_norm_deriv_le this B (convex_Icc _ _) _ _,\n    { simpa using abs_nonneg x },\n    { simp [le_abs_self x, neg_le.mp (neg_le_abs_self x)] } },\n  -- fourth step: conclude by massaging the inequality of the third step\n  simpa [F, norm_eq_abs, div_mul_eq_mul_div, pow_succ'] using C\nend\n\n/-- Power series expansion of the logarithm around `1`. -/\ntheorem has_sum_pow_div_log_of_abs_lt_1 {x : \u211d} (h : abs x < 1) :\n  has_sum (\u03bb (n : \u2115), x ^ (n + 1) / (n + 1)) (-log (1 - x)) :=\nbegin\n  rw summable.has_sum_iff_tendsto_nat,\n  show tendsto (\u03bb (n : \u2115), \u2211 (i : \u2115) in range n, x ^ (i + 1) / (i + 1)) at_top (\ud835\udcdd (-log (1 - x))),\n  { rw [tendsto_iff_norm_tendsto_zero],\n    simp only [norm_eq_abs, sub_neg_eq_add],\n    refine squeeze_zero (\u03bb n, abs_nonneg _) (abs_log_sub_add_sum_range_le h) _,\n    suffices : tendsto (\u03bb (t : \u2115), abs x ^ (t + 1) / (1 - abs x)) at_top\n      (\ud835\udcdd (abs x * 0 / (1 - abs x))), by simpa,\n    simp only [pow_succ],\n    refine (tendsto_const_nhds.mul _).div_const,\n    exact tendsto_pow_at_top_nhds_0_of_lt_1 (abs_nonneg _) h },\n  show summable (\u03bb (n : \u2115), x ^ (n + 1) / (n + 1)),\n  { refine summable_of_norm_bounded _ (summable_geometric_of_lt_1 (abs_nonneg _) h) (\u03bb i, _),\n    calc \u2225x ^ (i + 1) / (i + 1)\u2225\n    = abs x ^ (i+1) / (i+1) :\n      begin\n        have : (0 : \u211d) \u2264 i + 1 := le_of_lt (nat.cast_add_one_pos i),\n        rw [norm_eq_abs, abs_div, \u2190 pow_abs, abs_of_nonneg this],\n      end\n    ... \u2264 abs x ^ (i+1) / (0 + 1) :\n      begin\n        apply_rules [div_le_div_of_le_left, pow_nonneg, abs_nonneg, add_le_add_right,\n          i.cast_nonneg],\n        norm_num,\n      end\n    ... \u2264 abs x ^ i :\n      by simpa [pow_succ'] using mul_le_of_le_one_right (pow_nonneg (abs_nonneg x) i) (le_of_lt h) }\nend\n\nend real\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/special_functions/exp_log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055544, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7321445499120148}}
{"text": "import Mathlib.Tactic.Basic\nimport Mathlib.Tactic.Cases\nimport Mathlib.Init.Data.Nat.Basic\n\n/-!\n## Binary Trees\n\nInductive types with constructors taking several recursive arguments define treelike objects.\n_Binary trees_ have nodes with at most two children. A possible definition of binary trees follows:\n-/\ninductive BTree (\u03b1 : Type) : Type\n| empty : BTree \u03b1\n| node : \u03b1 \u2192 BTree \u03b1 \u2192 BTree \u03b1 \u2192 BTree \u03b1\nderiving Repr\n/-!\n\n-- BUGBUG - can you do this in lean4?  lean3 example had `| empty {} : BTree`\n\n(The `{}` annotation is often used with nullary constructors of polymorphic types.\nHere, it indicates that the type `\u03b1` should be implicitly derived from the context\naround `BTree.empty`. We can then write `BTree.empty` instead of `BTree.empty N`,\n`tree.empty _`, etc.)\n\nWith binary trees, structural induction gives rise to two induction hypotheses:\none for the left subtree of an inner node and one for the right subtree. To prove a\ngoal `t : tree \u03b1 \u22a2 P[t]` by structural induction on `t`, we need to show the sub-goals\n\n```lean\n\u22a2 P[tree.empty]\na : \u03b1, l r : tree \u03b1, ih_l : P[l], ih_r : P[r] \u22a2 P[tree.node a l r]\n```\n\nThe tree counterpart to list reversal is the mirror operation:\n-/\ndef mirror {\u03b1 : Type} : BTree \u03b1 \u2192 BTree \u03b1\n| BTree.empty => BTree.empty\n| (BTree.node a l r) => BTree.node a (mirror r) (mirror l)\n\n/-!\nMirroring can be defined directly, without appealing to some append operation. As a result,\nreasoning about `mirror` is simpler than reasoning about `reverse`, as we can see below:\n-/\nlemma mirror_mirror {\u03b1 : Type} (t : BTree \u03b1) :\n  mirror (mirror t) = t := by\n  induction t with\n  | empty => rfl\n  | node a l r ih_l ih_r =>\n    simp [mirror, ih_l, ih_r]\n/-!\nA more detailed informal proof would be as follows:\n\n- The proof is by structural induction on t.\n- Case `tree.empty`: We must show that\n`mirror (mirror tree.empty) = tree.empty`.\nThis follows directly from the definition of `mirror`.\n\n- Case `tree.node a l r`: The induction hypotheses are\n`(ih_l) mirror (mirror l) = l` and `(ih_r) mirror (mirror r) = r`\n- We must show `mirror (mirror (tree.node a l r)) = tree.node a l r`.\n- We have:\n- `mirror (mirror (tree.node a l r))`\n- `= mirror (tree.node a (mirror r) (mirror l)) (by def. of mirror)`\n- `= tree.node a (mirror (mirror l)) (mirror (mirror r)) (ditto)`\n- `= tree.node a l (mirror (mirror r)) (by ih_l)`\n- `= tree.node a l r (by ih_r)` <span class=\"qed\"></span>\n\nTo achieve the same level of detail in the Lean proof, we could use a calculational\nblock ([Section 3.4](../ForwardProofs/CalculationProofs.lean.md)) instead of `simp`:\n\n-/\nlemma mirror_mirror2 {\u03b1 : Type} :\n    \u2200t : BTree \u03b1, mirror (mirror t) = t\n| BTree.empty => by rfl\n| (BTree.node a l r) =>\ncalc mirror (mirror (BTree.node a l r))\n  = mirror (BTree.node a (mirror r) (mirror l)) :=\n    by rfl\n  _ = BTree.node a (mirror (mirror l)) (mirror (mirror r)) :=\n    by rfl\n  _ = BTree.node a l (mirror (mirror r)) :=\n    by rw [mirror_mirror2 l]\n  _ = BTree.node a l r :=\n    by rw [mirror_mirror2 r]\n\n/-!\n\nSo now you can see all the work that the `simp` tactic is doing for you, all it\nneeded was the hint _use mirror, ih_l, ih_r_.\n\nThe following lemma will be useful in Chapter 5, it simply states that the\nmirror of a tree is empty iff the tree is empty.\n-/\nlemma mirror_eq_empty_iff {\u03b1 : Type} :\n\u2200t : BTree \u03b1, mirror t = BTree.empty \u2194 t = BTree.empty\n| BTree.empty => by rfl\n| (BTree.node _ _ _) => by simp [mirror]\n", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/FunctionalProgramming/BinaryTrees.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199592797929, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.7321445463689461}}
{"text": "import Scripts.logic\n--=============================--\n------ T\u0395\u039fR\u00cdA DE CONJUNTOS ------\n--=============================--\n\n--------------------\n--- Definiciones ---\n--------------------\n-- Definici\u00f3n del tipo 'Set'. 'Set \u03b1' es el tipo de los conjuntos formados por elementos de \u03b1\ndef Set (\u03b1 : Type u) := \u03b1 \u2192 Prop\n\n\n-- Dado un conjunto s : Set \u03b1 y un t\u00e9rmino a : \u03b1, una prueba de que 'a' pertenece \n-- a 's' es una prueba de 's a'\n-- Lean 4 tiene una clase 'Membership \u03b1 \u03b2' que sirve para indicar que hay una noci\u00f3n de pertenencia \n-- de tipo '\u03b1 \u2192 \u03b2 \u2192 Prop' entre elementos de \u03b1 y elementos de \u03b2.\n \n#print Membership\n\ndef member (a : \u03b1) (s : Set \u03b1) : Prop := s a\ninstance : Membership (\u03b1 : Type u) (Set \u03b1) := Membership.mk (fun a s => s a)\n\n-- Esa instancia nos permite utilizar la notaci\u00f3n 'a \u2208 s' para 's a'\n\n-- Conjunto vac\u00edo\ndef empty : Set \u03b1 := fun _ => False\n\n-- Conjunto total (conjunto formado por todos los elementos de \u03b1)\ndef univ : Set \u03b1 := fun _ => True\n\n-- Para usar la notaci\u00f3n \u2205 para el conjunto vac\u00edo:\ninstance : EmptyCollection (Set \u03b1) := EmptyCollection.mk empty\n\n-- Definici\u00f3n de subconjunto \ndef subset (s1 s2 : Set \u03b1) : Prop :=\n  \u2200 {a}, a \u2208 s1 \u2192 a \u2208 s2\n\n-- Introducimos la notaci\u00f3n s \u2286 t para subconjunto s t\ninfix:50 \" \u2286 \" => subset\n\n-- Uni\u00f3n finita\ndef union (s t : Set \u03b1) : Set \u03b1 := \n  fun a => a \u2208 s \u2228 a \u2208 t\n\ninfixl:65 \"\u222a\" => union\n\n-- Intersecci\u00f3n finita\ndef inter (s t : Set \u03b1) : Set \u03b1 :=\n  fun a => a \u2208 s \u2227 a \u2208 t \n\ninfixl:65 \"\u2229\" => inter\n\n-- Union de familia arbitraria de conjuntos\ndef unionF (F : Set (Set \u03b1)) : Set \u03b1 := \n  fun a => \u2203 s, s \u2208 F \u2227 a \u2208 s\n\nprefix:110 \"\u22c3\u2080\" => unionF\n\n-- Intersecci\u00f3n de familia arbitraria de conjuntos \ndef interF (F : Set (Set \u03b1)) : Set \u03b1 :=\n fun a => \u2200 s, s \u2208 F \u2192 a \u2208 s \n\nprefix:110 \"\u22c2\u2080\" => interF\n\n-- Conjunto complementario\ndef compl (s : Set \u03b1) : Set \u03b1 := \n  fun a => \u00ac a \u2208 s\n\n-- Para la notaci\u00f3n '-a' para 'compl a'\ninstance : Neg (Set \u03b1) := Neg.mk compl\n\n-- Familia de complementarios\ndef complF (F : Set (Set \u03b1)) : Set (Set \u03b1) := \n  fun s => -s \u2208 F\n\n-- Imagen inversa\ndef preimage (f : \u03b1 \u2192 \u03b2) (s : Set \u03b2) : Set \u03b1 := fun a => f a \u2208 s\n  \nnotation f \"\u207b\u00b9(\" s \")\" => preimage f s\n\n-- Imagen\ndef image (f : \u03b1 \u2192 \u03b2) (s : Set \u03b1) : Set \u03b2 :=\n  fun b => \u2203 a : \u03b1, a \u2208 s \u2227 f a = b\n\nnotation  \"Im(\" f \",\" s \")\" => image f s\n\n-- Conjuntos disjuntos\ndef disjoint (s t : Set \u03b1) : Prop := (s \u2229 t) \u2286 \u2205 \n\n-- Conjunto unitario\ndef singleton (a : \u03b1) : Set \u03b1 := fun b => b = a\n\nnotation \"{ \" a \" }\" => singleton a\n\n-------------------\n--- PROPIEDADES ---\n-------------------\n\n-- Extensionalidad para conjuntos: dos conjuntos son iguales si tienen los mismos elementos\ntheorem setext {s t : Set \u03b1} (h: \u2200 {a}, a \u2208 s \u2194 a \u2208 t) : s = t := \n  funext (fun _ => propext h)\n\ntheorem obv : (\u2205 : Set \u03b1) = (fun _ => 0 = 1) := \n  setext \u27e8fun h => h.elim, fun h => by contradiction\u27e9\n\ntheorem eq_inter_union {s t1 t2 : Set \u03b1} : s \u2229 (t1 \u222a t2) = (s \u2229 t1) \u222a (s \u2229 t2) :=\n  setext and_or_iff\n\n-- La uni\u00f3n arbitraria de la familia vac\u00eda es el conjunto vac\u00edo\ntheorem unionF_empty : \u22c3\u2080 (\u2205 : Set (Set \u03b1)) = (\u2205 : Set \u03b1) := \n  setext \u27e8fun h => h.elim (fun _ hand => hand.left), fun h => h.elim\u27e9\n\n\ntheorem eq_unionF_of_union {A B : Set (Set \u03b1)} : \u22c3\u2080 (A \u222a B) = (\u22c3\u2080 A) \u222a (\u22c3\u2080 B) := \n  setext \n    \u27e8fun hex => hex.elim (fun s \u27e8hor,hs\u27e9 => hor.elim (fun hA => Or.inl (Exists.intro s \u27e8hA,hs\u27e9))\n                                                     (fun hB => Or.inr (Exists.intro s \u27e8hB,hs\u27e9))),\n    fun hor => hor.elim (fun \u27e8s,\u27e8hA,hs\u27e9\u27e9 => \u27e8s,\u27e8Or.inl hA,hs\u27e9\u27e9)\n                        (fun \u27e8s,\u27e8hB,hs\u27e9\u27e9 => \u27e8s,\u27e8Or.inr hB,hs\u27e9\u27e9)\u27e9\n\n-----------------------------------\n--- Propiedades de subconjuntos ---\n-----------------------------------\n\n-- Si dos conjuntos son iguales, entonces est\u00e1n contenidos\n-- el uno en el otro\ntheorem subset_of_eq {s t : Set \u03b1} : s = t \u2192 subset s t :=\n  fun heq => fun hsa => heq \u25b8 hsa\n\n-- \"Ser subconjunto de\" es una relaci\u00f3n transitiva\ntheorem subset_trans {s t u : Set \u03b1} : s \u2286 t \u2192 t \u2286 u \u2192 s \u2286 u := \n  fun hst htu => fun hs => htu (hst hs)\n\n-- \"Ser subconjunto de\" es una relaci\u00f3n antisim\u00e9trica\ntheorem eq_of_mutual_subsets {s t : Set \u03b1} : s \u2286 t \u2192 t \u2286 s \u2192 s = t :=\n  fun h1 h2 => setext \u27e8h1,h2\u27e9\n\n-- La uni\u00f3n de dos conjuntos 's' y 't' est\u00e1 contenida en un tercer conjunto 'u'\n-- si y solo si 's' y 't' est\u00e1n ambos contenidos en 'u'\ntheorem iff_union_of_subsets {s t u : Set \u03b1} : (s \u222a t) \u2286 u \u2194 s \u2286 u \u2227 t \u2286 u :=\n  \u27e8fun h => \u27e8fun hsa => h (Or.inl hsa), fun hta => h (Or.inr hta)\u27e9,\n  fun h => fun hunion => hunion.elim (fun hs => h.left hs) (fun ht => h.right ht)\u27e9\n\n-- Si 's' est\u00e1 contenido en 't', entonces 's' est\u00e1\n-- contenido en la uni\u00f3n de 't' con cualquier otro conjunto.\ntheorem subset_of_union {s t : Set \u03b1} (u : Set \u03b1): s \u2286 t \u2192 s \u2286 (t \u222a u) \u2227 s \u2286 (u \u222a t) :=\n  fun h => \u27e8fun hs => Or.inl (h hs), fun hs => Or.inr (h hs)\u27e9\n\n-- Si 's' est\u00e1 contenido en 't', entonces 's' es la intersecci\u00f3n de 't' con 's'\ntheorem eq_subset_inter_subset {s t : Set \u03b1} : s \u2286 t \u2192 s = s \u2229 t := \n  fun hsub => setext \u27e8fun hsa => \u27e8hsa, hsub hsa\u27e9, fun hinter => hinter.left\u27e9\n\n-- Si 's' est\u00e1 contenido en 't1' y en 't2', entonces est\u00e1 contenido en\n-- la intersecci\u00f3n de 't1' y 't2'\ntheorem inter_of_double_subset {s t1 t2 : Set \u03b1} : s \u2286 t1 \u2192 s \u2286 t2 \u2192 s \u2286 (t1 \u2229 t2) := \n  fun ht1 ht2 => fun hs => \u27e8ht1 hs, ht2 hs\u27e9\n\n--------------------------------------\n--- Propiedades del conjunto vac\u00edo ---\n--------------------------------------\n\n-- El conjunto vac\u00edo est\u00e1 contenido en cualquier conjunto\ntheorem empty_subset (s : Set \u03b1) : \u2205 \u2286 s :=\n  fun hfalse => hfalse.elim \n\n-- Todo subconjunto del vac\u00edo es vac\u00edo\ntheorem eq_empty_of_subset_empty {s : Set \u03b1} : s \u2286 \u2205 \u2192 s = \u2205 := \n  fun h => eq_of_mutual_subsets h (empty_subset s)\n\n-- La intersecci\u00f3n con el conjunto vac\u00edo es el conjunto vac\u00edo\ntheorem eq_inter_empty (s : Set \u03b1) : s \u2229 \u2205 = \u2205 :=\n  eq_empty_of_subset_empty (fun hinter => hinter.right)\n\n-- Si 's' es subconjunto de conjuntos disjuntos, entonces 's' es vac\u00edo\ntheorem empty_of_subset_of_disjoints {s t1 t2 : Set \u03b1} (hdisj : disjoint t1 t2) : s \u2286 t1 \u2192 s \u2286 t2 \u2192 s = \u2205 := \n  fun ht1 ht2 => eq_empty_of_subset_empty (subset_trans (inter_of_double_subset ht1 ht2) hdisj)\n\n-- No existe ning\u00fan elemento en el conjunto vac\u00edo\ntheorem notexists_in_empty {\u03b1 : Type u}: \u00ac \u2203 a : \u03b1, a \u2208 (\u2205 : Set \u03b1) := \n  fun hex => hex.elim (fun _ hinempty => hinempty.elim)\n\n-- Si existe un elemento que pertenece a 's', entonces 's' no es el\n-- conjunto vac\u00edo\ntheorem nonemptyset_of_exists {s : Set \u03b1} : (\u2203 a, s a) \u2192 \u00ac s = \u2205 :=\n  fun hex hempty =>  (notexists_in_empty (hempty \u25b8 hex)).elim\n\n-- Si no existe ning\u00fan elemento que pertenezca a 's', entonces 's'\n-- es vac\u00edo\ntheorem emptyset_of_notexists {s : Set \u03b1} : (\u00ac \u2203 a, s a) \u2192 s = \u2205 :=\n  fun hnex => (eq_empty_of_subset_empty (fun {a} hsa => hnex \u27e8a,hsa\u27e9))\n\n-- La imagen de un conjunto no vac\u00edo es no vac\u00eda\ntheorem image_of_nonempty {s : Set \u03b1} (f : \u03b1 \u2192 \u03b2) : \u00ac s = \u2205 \u2192 \u00ac Im(f,s) = \u2205 := \n  fun hnotemptys => fun hemptyfs =>\n    have hsubempty : s \u2286 empty := fun {a} hsa => \n      have hfaIm : (f a) \u2208 Im(f,s) := Exists.intro a \u27e8hsa,rfl\u27e9\n      have hinempty : (f a) \u2208 (\u2205 : Set \u03b2) := hemptyfs \u25b8 hfaIm\n      hinempty.elim\n    hnotemptys (eq_empty_of_subset_empty hsubempty)\n\n\n----------------------------------------------\n--- Propiedades de los conjuntos unitarios ---\n----------------------------------------------\n\n-- Los conjuntos unitarios son no vac\u00edos\ntheorem nonempty_singleton (a : \u03b1) : \u00ac singleton a = empty := nonemptyset_of_exists \u27e8a,rfl\u27e9\n\n-- La intersecci\u00f3n con un conjunto unitario es o bien el vac\u00edo, \n-- o bien el propio conjunto unitario\ntheorem empty_or_singleton_eq_inter_singleton {s : Set \u03b1} {a : \u03b1} : \n  empty = (s \u2229 { a }) \u2228 { a } = (s \u2229 { a }) := \n  (Classical.em (s a)).elim\n  (fun hsa => \n    Or.inr (setext \u27e8fun heqab => \u27e8heqab \u25b8 hsa, heqab\u27e9, fun hinter => hinter.right\u27e9))\n  (fun hnsa =>\n    Or.inl (setext \u27e8fun hfalse => hfalse.elim, fun hinter => (hnsa (hinter.right \u25b8 hinter.left)).elim\u27e9))\n\n-- La uni\u00f3n de la familia formada por un solo conjunto 's' es igual a 's'\ntheorem unionF_singleton (s : Set \u03b1) : \u22c3\u2080 { s } = s := \n  setext \u27e8fun hunion => hunion.elim (fun _ \u27e8hsinglF,hta\u27e9 => hsinglF \u25b8 hta),\n                     fun hsa => Exists.intro s \u27e8rfl,hsa\u27e9\u27e9\n\n-- La imagen de un conjunto unitario { x } es el conjunto unitario formado\n-- por la imagen de 'x'\ntheorem image_singleton (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :  Im(f,{ a }) = { f a } := \n  setext (Iff.intro \n    (fun himb => himb.elim (fun _ \u27e8hsingaa',heqfa'b\u27e9 => hsingaa' \u25b8 heqfa'b.symm))\n    (fun hsingfab => Exists.intro a \u27e8rfl,hsingfab.symm\u27e9))\n\n-- Un elemento pertenece a un cierto conjunto si y solo si el conjunto\n-- unitario formado por ese elemento est\u00e1 contenido en el conjunto\ntheorem in_set_iff_singleton_subset {s : Set \u03b1} {a : \u03b1} : a \u2208 s \u2194 { a } \u2286 s :=\n  Iff.intro\n  (fun hsa => fun hbsingl => hbsingl \u25b8 hsa)\n  (fun hsub => hsub rfl)\n\n--------------------------------------\n--- Propiedades del complementario ---\n--------------------------------------\n\n-- El complementario del vacio es el total\ntheorem eq_compl_empty :  -(\u2205 : Set \u03b1) = (univ : Set \u03b1) := \n  setext notfalse_iff_true\n\n-- El complementario del total es el vac\u00edo\ntheorem eq_compl_univ :  -univ = (\u2205 : Set \u03b1) := \n  setext nottrue_iff_false\n\n-- Propiedad involutiva del complementario\ntheorem compl_compl_eq {\u03b1 : Type u} {s : Set \u03b1} :  -(-s) = s := \n  setext iff_not_not\n\n-- Complementario de la instersecci\u00f3n\ntheorem compl_inter_eq_union_compl {s t : Set \u03b1} : - (s \u2229 t) = (-s) \u222a (-t) :=\n  setext or_not_iff_not_and\n\n-- Familia de complementarios\ntheorem complF_of_F {F : Set (Set \u03b1)} {s : Set \u03b1} : s \u2208 F \u2192 (-s) \u2208 complF F  :=\n  fun h : F s =>  \n    have h_compl_compl : (-(-s)) \u2208 F := compl_compl_eq \u25b8 h\n    h_compl_compl\n\n-- Propiedad involutiva del complementario para familias\ntheorem complF_complF_eq (F : Set (Set \u03b1)) : complF (complF F) = F :=\n  have h : \u2200 s, s \u2208 complF (complF F) \u2194 s \u2208 F := \n    fun s => \n    \u27e8 fun hccs : complF (complF F) s => \n        have h_compl_compl_s : F (- (-s)) := hccs\n        show F s from @compl_compl_eq \u03b1 s \u25b8 h_compl_compl_s,\n      fun h_s : F s => \n        have h_ccF_cc_s : complF (complF F) (compl (compl s)) := complF_of_F  (complF_of_F  h_s)\n        @compl_compl_eq \u03b1 s \u25b8 h_ccF_cc_s\n    \u27e9\n  setext @h\n\n-- Lema\ntheorem forall_comp {p : Set \u03b1 \u2192 Prop} {F : Set (Set \u03b1)} : (\u2200 s, s \u2208 F \u2192 p (-s)) \u2192 \u2200 s, s \u2208 (complF F) \u2192 p s :=\n  fun h s h_cF_s => @compl_compl_eq \u03b1 s \u25b8 h (-s) h_cF_s\n\n-- El complementario de la union de una familia de conjuntos\n-- es la intersecci\u00f3n de la familia de los complementarios\ntheorem compl_unionF {F : Set (Set \u03b1)} : - (\u22c3\u2080 F) = \u22c2\u2080 (complF F) :=\n  have h : \u2200 a,  a \u2208 - (unionF F) \u2194 a \u2208 \u22c2\u2080 (complF F) := \n    fun a =>\n      \u27e8fun h_compl_union : a \u2208 - (\u22c3\u2080 F) => \n        forall_comp (fun s => implies_of_not_and (forall_of_not_exists h_compl_union s)), \n       fun h_inter_compl : a \u2208 \u22c2\u2080 (complF F) =>\n          fun hunion : a \u2208 (\u22c3\u2080 F) =>\n            hunion.elim \n            (fun s hFssa =>  \n              have hcsa : a \u2208 (- s) := h_inter_compl (- s) (complF_of_F hFssa.left)\n              hcsa hFssa.right)\n      \u27e9\n  setext @h", "meta": {"author": "rodripalUS", "repo": "TFM_cap3", "sha": "c4c3dbd71afb72468cf31b89711f20565fd2d5e5", "save_path": "github-repos/lean/rodripalUS-TFM_cap3", "path": "github-repos/lean/rodripalUS-TFM_cap3/TFM_cap3-c4c3dbd71afb72468cf31b89711f20565fd2d5e5/Scripts/set_theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7321445379456227}}
{"text": "import analysis.mean_inequalities data.multiset.fintype\n\n/-! # IMO 2014 C2 -/\n\nnamespace IMOSL\nnamespace IMO2014C2\n\nopen multiset\nopen_locale nnreal\n\ndef good {\u03b1 : Type*} [has_add \u03b1] (S T : multiset \u03b1) :=\n  \u2203 (R : multiset \u03b1) (a b : \u03b1), S = R + {a, b} \u2227 T = R + repeat (a + b) 2\n\n\n\nsection extra_lemmas\n\nsection cons_last\n\nvariable {\u03b1 : Type*} \n\n/-- Wrapper for the last element of a cons list `a :: l`, guaranteed to be non-empty. -/\nprivate def cons_last (a : \u03b1) (l : list \u03b1) : \u03b1 := (list.cons a l).last (list.cons_ne_nil a l)\n\nprivate lemma cons_last_nil (a : \u03b1) : cons_last a list.nil = a :=\n  by rw [cons_last, list.last_singleton]\n\nprivate lemma cons_last_cons (a b : \u03b1) (l : list \u03b1) : cons_last a (b :: l) = cons_last b l :=\n  by rw [cons_last, list.last, cons_last]; refl\n\nprivate lemma cons_last_ne_nil (a : \u03b1) {l : list \u03b1} (h : l \u2260 list.nil) :\n  cons_last a l = l.last h :=\n  by rw [cons_last, list.last_cons]\n\nend cons_last\n\n\nprivate lemma multiset_AM_GM (S : multiset \u211d\u22650) : S.prod \u2264 (S.sum / S.card) ^ S.card :=\nbegin\n  rcases eq_or_ne S 0 with rfl | h,\n  rw [card_zero, pow_zero, prod_zero],\n  rw [ne.def, \u2190 card_eq_zero] at h,\n  rw [sum_eq_sum_coe, \u2190 inv_mul_eq_div, finset.mul_sum],\n  refine le_of_eq_of_le _\n    (pow_le_pow_of_le_left (zero_le _) (nnreal.geom_mean_le_arith_mean_weighted _ _ _ _) _),\n  simp_rw [\u2190 finset.prod_pow, nonneg.coe_inv, nnreal.coe_nat_cast,\n           nnreal.rpow_nat_inv_pow_nat _ h, \u2190 prod_eq_prod_coe],\n  rw [finset.sum_const, finset.card_univ, card_coe, nsmul_eq_mul],\n  apply mul_inv_cancel; rwa nat.cast_ne_zero\nend\n\nend extra_lemmas\n\n\n\nprivate lemma good_card_eq {\u03b1 : Type*} [has_add \u03b1] {S T : multiset \u03b1} (h : good S T) :\n  T.card = S.card :=\n  by rcases h with \u27e8R, a, b, rfl, rfl\u27e9;\n    rw [card_add, card_repeat, card_add, insert_eq_cons, card_cons, card_singleton]\n\nprivate lemma good_chain_card_eq {\u03b1 : Type*} [has_add \u03b1]\n  {S : multiset \u03b1} {C : list (multiset \u03b1)} (h : list.chain good S C) :\n  (cons_last S C).card = S.card :=\nbegin\n  revert S h; induction C with T C h0,\n  rintros S -; rw cons_last_nil,\n  intros S h; rw list.chain_cons at h,\n  rw [cons_last_cons, h0 h.2, good_card_eq h.1]\nend\n\nprivate lemma good_prod_le {S T : multiset \u211d\u22650} (h : good S T) : 4 * S.prod \u2264 T.prod :=\nbegin\n  rcases h with \u27e8R, a, b, rfl, rfl\u27e9,\n  simp_rw [prod_add, insert_eq_cons, prod_cons, prod_singleton],\n  rw mul_left_comm; apply mul_le_mul_left',\n  rw [prod_repeat, add_sq', bit0, add_mul, \u2190 mul_assoc, add_le_add_iff_right, \u2190 nnreal.coe_le_coe],\n  simp_rw [nnreal.coe_add, nnreal.coe_pow, nnreal.coe_mul],\n  rw [nnreal.coe_bit0, nnreal.coe_one, \u2190 sub_nonneg, \u2190 sub_sq'],\n  exact sq_nonneg (a - b)\nend\n\nprivate lemma good_chain_le_prod\n    {S : multiset \u211d\u22650} {C : list (multiset \u211d\u22650)} (h : list.chain good S C) :\n  4 ^ C.length * S.prod \u2264 (cons_last S C).prod :=\nbegin\n  revert S h; induction C with T C h0,\n  rintros S -; rw [list.length, pow_zero, one_mul, cons_last_nil S],\n  intros S h; rw list.chain_cons at h,\n  rw [list.length, pow_succ', mul_assoc, cons_last_cons],\n  exact le_trans (mul_le_mul_left' (good_prod_le h.1) _) (h0 h.2)\nend\n\n/-- A generalized form of the final solution -/\nprivate lemma good_chain_le_sum\n    {S : multiset \u211d\u22650} {C : list (multiset \u211d\u22650)} (h : list.chain good S C) :\n  4 ^ C.length * S.prod \u2264 ((cons_last S C).sum / S.card) ^ S.card :=\n  by rw \u2190 good_chain_card_eq h; exact le_trans (good_chain_le_prod h) (multiset_AM_GM _)\n\n\n\n\n\n\n\n/-- Final solution -/\ntheorem final_solution {m : \u2115} (h : 0 < m) {C : list (multiset \u211d\u22650)}\n  (h0 : C.length = m * 2 ^ (m - 1)) (h1 : list.chain good (repeat (1 : \u211d\u22650) (2 ^ m)) C) :\n  4 ^ m \u2264 (cons_last (repeat (1 : \u211d\u22650) (2 ^ m)) C).sum :=\nbegin\n  have h2 := good_chain_le_sum h1,\n  rw h0 at h2; clear h0 h1,\n  generalize_hyp : (cons_last  (repeat (1 : \u211d\u22650) (2 ^ m)) C).sum = x at h2 \u22a2,\n  rw [prod_repeat, one_pow, mul_one, card_repeat, bit0, \u2190 mul_two, \u2190 sq, \u2190 pow_mul,\n      mul_left_comm, \u2190 pow_succ, nat.sub_add_cancel h, pow_mul] at h2,\n  replace h2 := le_of_pow_le_pow (2 ^ m) (zero_le (x / \u2191(2 ^ m))) (pow_pos two_pos _) h2,\n  rw [nat.cast_pow, nat.cast_bit0, nat.cast_one,\n      le_div_iff (pow_pos _ _), \u2190 mul_pow, two_mul, \u2190 bit0] at h2,\n  exacts [h2, two_pos]\nend\n\nend IMO2014C2\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2014/C2/C2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7321445353786051}}
{"text": "import tactic --hide\n\n-- Level name : And's\n\n/-\nLets now look at making some more complicated logical statements. Recall that if we have two\nstatements `P,Q` then we can form `P \u2227 Q` which is true if and only if both `P` and `Q` are true.\n\nTo help us with this, lets introduce some new tactics.\n\n## Tactics for Level 2\n\n## The `split` tactic\n\nIf your goal is an \"and\" goal:\n\n```\n\u22a2 P \u2227 Q\n```\n\nthen the `split` tactic will turn it\ninto *two* goals\n\n\n```\n\u22a2 P\n```\n\nand\n\n```\n\u22a2 Q\n```\n\nIt is best practice to indicate when you are working with two goals, either by using squiggly \nbrackets like this:\n\n```\n...\nsplit,\n{ working on P,\n  end of proof of P },\n{ working on Q,\n  end of proof of Q },\n```\n\nor by using indentation like this:\n\n```\nsplit,\n  working on P,\n  end of proof of P,\nworking on Q,\n...\n```\n\nMoreover, if you have an if and only if `\u2194` then splitting it will give you two goals,\n`\u2192` and `\u2190` to prove.\n\n## `left` and `right`\n\nIf your goal is\n\n```\n\u22a2 P \u2228 Q\n```\n\nthen `left` changes the goal to `\u22a2 P`. The logic is that `P` implies `P \u2228 Q`\nso we can `apply` this implication. Similarly `right` changes the goal to `\u22a2 Q`\n\n## The `cases` tactic\n\n`cases` is a very general-purpose tactic for \"deconstructing\" hypotheses.\nIf `h` is a hypothesis which somehow \"bundles up\" two pieces of information,\nthen `cases h with h1 h2` will make hypothesis `h` vanish and will replace it\nwith the two \"components\" which made the proof of `h` in the first place.\nAn example of this occurring in logic sheet 4 is `h : P \u2227 Q` which is a\nbundling of a proof of `P` and a proof of `Q`.\n\n### Example\n\nIf you have a hypothesis\n\n```\nhPaQ : P \u2227 Q\n```\n\nthen\n\n`cases hPaQ with hP hQ,`\n\nwill delete `hPaQ` and replace it with\n\n```\nhP : P\nhQ : Q\n```\n\nYou can also use it for \"or's\". Specifically, if you have `h : P \u2228 Q` then `cases h` will\ngive you two goals, one where `P` is true and one where `Q` is true.\n\n\n-/\n\nexample (P Q : Prop) (p : P) : P \u2228 Q :=\nbegin\n  left,\n  exact p,\nend\n\nexample (P Q : Prop) (p : P) (q : Q) : P \u2227 Q :=\nbegin\n  split,\n  exact p,\n  exact q,\nend\n\nexample (P : Prop) : P \u2194 P :=\nbegin\n  split,\n  intro p,\n  exact p,\n  intro p,\n  exact p,\nend\n\nexample (P Q : Prop) (hPQ: P \u2227 Q) : P :=\nbegin \n  cases hPQ with hP hQ,\n  exact hP,\nend\n\nexample (P : Prop) (hp : P \u2228 P) : P :=\nbegin\n  cases hp,\n  exact hp,\n  exact hp,\nend\n\n\n/- Tactic : split\n\nIf your goal is an \"and\" goal:\n\n```\n\u22a2 P \u2227 Q\n```\n\nthen the `split` tactic will turn it\ninto *two* goals\n\n\n```\n\u22a2 P\n```\n\nand\n\n```\n\u22a2 Q\n```\nMoreover, if you have an iff `\u2194` then splitting it will give you two goals, `\u2192` and `\u2190` to prove.\n\n-/\n\n/- Tactic : left and right\n\nIf your goal is\n\n```\n\u22a2 P \u2228 Q\n```\n\nthen `left` changes the goal to `\u22a2 P`. The logic is that `P` implies `P \u2228 Q`\nso we can `apply` this implication. Similarly `right` changes the goal to `\u22a2 Q`\n\n-/\n\n/- Tactic : cases\n\nIf you have a hypothesis\n\n```\nhPaQ : P \u2227 Q\n```\n\nthen\n\n`cases hPaQ with hP hQ,`\n\nwill delete `hPaQ` and replace it with\n\n```\nhP : P\nhQ : Q\n```\n\nYou can also use it for \"or's\". Specifically, if you have `h : P \u2228 Q` then `cases h` will\ngive you two goals, one where `P` is true and one where `Q` is true.\n\n-/", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic2/logical_ands.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.7321282436406761}}
{"text": "import data.mv_polynomial.basic\nimport data.mv_polynomial.comm_ring\nimport data.zmod.basic\n\nopen mv_polynomial\nnoncomputable theory\n\nsection \n\nabbreviation R := mv_polynomial (fin 6) (zmod 101)\ndef f : R  := (X 0)*(X 1)*(X 2) - (X 3)*(X 4)*(X 5)\ndef g : R  := (X 0)*(X 1)*(X 2)\ndef h : R  := (X 3)*(X 4)*(X 5)\n\n#check R\n#check f\n#check g\n#check h\n\nlemma g_minus_h_eq_f : g - h = f := rfl\n\nlemma g_eq_h_plus_f : g = h + f :=\nbegin\n  rw [f, g, h],\n  ring,\nend\n\nlemma g_eq_h_plus_f_one : g = (1:R)*h + (1:R)*f :=\nbegin\n  rw [f, g, h],\n  ring,\nend\nend\n", "meta": {"author": "mkummini", "repo": "ideal-membership", "sha": "59f823e657939e386d0e53a5d9be47392bab3e41", "save_path": "github-repos/lean/mkummini-ideal-membership", "path": "github-repos/lean/mkummini-ideal-membership/ideal-membership-59f823e657939e386d0e53a5d9be47392bab3e41/src/mwe1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.7321009132800413}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Ya\u00ebl Dillies\n-/\nimport analysis.normed.group.pointwise\nimport analysis.normed_space.basic\n\n/-!\n# Properties of pointwise scalar multiplication of sets in normed spaces.\n\nWe explore the relationships between scalar multiplication of sets in vector spaces, and the norm.\nNotably, we express arbitrary balls as rescaling of other balls, and we show that the\nmultiplication of bounded sets remain bounded.\n-/\n\nopen metric set\nopen_locale pointwise topological_space\n\nvariables {\ud835\udd5c E : Type*} [normed_field \ud835\udd5c]\n\nsection semi_normed_group\nvariables [semi_normed_group E] [normed_space \ud835\udd5c E]\n\ntheorem smul_ball {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 ball x r = ball (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hc,\n  conv_lhs { rw \u2190inv_smul_smul\u2080 hc x },\n  simp [\u2190 div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hc), mul_comm _ r, dist_smul],\nend\n\nlemma smul_unit_ball {c : \ud835\udd5c} (hc : c \u2260 0) : c \u2022 ball (0 : E) (1 : \u211d) = ball (0 : E) (\u2225c\u2225) :=\nby rw [smul_ball hc, smul_zero, mul_one]\n\ntheorem smul_sphere' {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 sphere x r = sphere (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hc,\n  conv_lhs { rw \u2190inv_smul_smul\u2080 hc x },\n  simp only [mem_sphere, dist_smul, norm_inv, \u2190 div_eq_inv_mul,\n    div_eq_iff (norm_pos_iff.2 hc).ne', mul_comm r],\nend\n\ntheorem smul_closed_ball' {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 closed_ball x r = closed_ball (c \u2022 x) (\u2225c\u2225 * r) :=\nby simp only [\u2190 ball_union_sphere, set.smul_set_union, smul_ball hc, smul_sphere' hc]\n\nlemma metric.bounded.smul {s : set E} (hs : bounded s) (c : \ud835\udd5c) :\n  bounded (c \u2022 s) :=\nbegin\n  obtain \u27e8R, hR\u27e9 : \u2203 (R : \u211d), \u2200 x \u2208 s, \u2225x\u2225 \u2264 R := hs.exists_norm_le,\n  refine (bounded_iff_exists_norm_le).2 \u27e8\u2225c\u2225 * R, _\u27e9,\n  assume z hz,\n  obtain \u27e8y, ys, rfl\u27e9 : \u2203 (y : E), y \u2208 s \u2227 c \u2022 y = z := mem_smul_set.1 hz,\n  calc \u2225c \u2022 y\u2225 = \u2225c\u2225 * \u2225y\u2225 : norm_smul _ _\n  ... \u2264 \u2225c\u2225 * R : mul_le_mul_of_nonneg_left (hR y ys) (norm_nonneg _)\nend\n\n/-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r \u2022 s` is contained in any\nfixed neighborhood of `x`. -/\nlemma eventually_singleton_add_smul_subset\n  {x : E} {s : set E} (hs : bounded s) {u : set E} (hu : u \u2208 \ud835\udcdd x) :\n  \u2200\u1da0 r in \ud835\udcdd (0 : \ud835\udd5c), {x} + r \u2022 s \u2286 u :=\nbegin\n  obtain \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9 : \u2203 \u03b5 (h\u03b5 : 0 < \u03b5), closed_ball x \u03b5 \u2286 u :=\n    nhds_basis_closed_ball.mem_iff.1 hu,\n  obtain \u27e8R, Rpos, hR\u27e9 : \u2203 (R : \u211d), 0 < R \u2227 s \u2286 closed_ball 0 R := hs.subset_ball_lt 0 0,\n  have : metric.closed_ball (0 : \ud835\udd5c) (\u03b5 / R) \u2208 \ud835\udcdd (0 : \ud835\udd5c) :=\n    closed_ball_mem_nhds _ (div_pos \u03b5pos Rpos),\n  filter_upwards [this] with r hr,\n  simp only [image_add_left, singleton_add],\n  assume y hy,\n  obtain \u27e8z, zs, hz\u27e9 : \u2203 (z : E), z \u2208 s \u2227 r \u2022 z = -x + y, by simpa [mem_smul_set] using hy,\n  have I : \u2225r \u2022 z\u2225 \u2264 \u03b5 := calc\n    \u2225r \u2022 z\u2225 = \u2225r\u2225 * \u2225z\u2225 : norm_smul _ _\n    ... \u2264 (\u03b5 / R) * R :\n      mul_le_mul (mem_closed_ball_zero_iff.1 hr)\n        (mem_closed_ball_zero_iff.1 (hR zs)) (norm_nonneg _) (div_pos \u03b5pos Rpos).le\n    ... = \u03b5 : by field_simp [Rpos.ne'],\n  have : y = x + r \u2022 z, by simp only [hz, add_neg_cancel_left],\n  apply h\u03b5,\n  simpa only [this, dist_eq_norm, add_sub_cancel', mem_closed_ball] using I,\nend\n\nvariables [normed_space \u211d E] {x y z : E} {\u03b4 \u03b5 : \u211d}\n\n/-- In a real normed space, the image of the unit ball under scalar multiplication by a positive\nconstant `r` is the ball of radius `r`. -/\nlemma smul_unit_ball_of_pos {r : \u211d} (hr : 0 < r) : r \u2022 ball 0 1 = ball (0 : E) r :=\nby rw [smul_unit_ball hr.ne', real.norm_of_nonneg hr.le]\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_eq (x z : E) {a b : \u211d} (ha : 0 \u2264 a) (hb : 0 \u2264 b) (hab : a + b = 1) :\n  \u2203 y, dist x y = b * dist x z \u2227 dist y z = a * dist x z :=\nbegin\n  use a \u2022 x + b \u2022 z,\n  nth_rewrite 0 [\u2190one_smul \u211d x],\n  nth_rewrite 3 [\u2190one_smul \u211d z],\n  simp [dist_eq_norm, \u2190hab, add_smul, \u2190smul_sub, norm_smul_of_nonneg, ha, hb],\nend\n\nlemma exists_dist_le_le (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 \u2264 \u03b5) (h : dist x z \u2264 \u03b5 + \u03b4) :\n  \u2203 y, dist x y \u2264 \u03b4 \u2227 dist y z \u2264 \u03b5 :=\nbegin\n  obtain rfl | h\u03b5' := h\u03b5.eq_or_lt,\n  { exact \u27e8z, by rwa zero_add at h, (dist_self _).le\u27e9 },\n  have h\u03b5\u03b4 := add_pos_of_pos_of_nonneg h\u03b5' h\u03b4,\n  refine (exists_dist_eq x z (div_nonneg h\u03b5 $ add_nonneg h\u03b5 h\u03b4) (div_nonneg h\u03b4 $ add_nonneg h\u03b5 h\u03b4) $\n    by rw [\u2190add_div, div_self h\u03b5\u03b4.ne']).imp (\u03bb y hy, _),\n  rw [hy.1, hy.2, div_mul_comm, div_mul_comm \u03b5],\n  rw \u2190div_le_one h\u03b5\u03b4 at h,\n  exact \u27e8mul_le_of_le_one_left h\u03b4 h, mul_le_of_le_one_left h\u03b5 h\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_le_lt (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 < \u03b5) (h : dist x z < \u03b5 + \u03b4) :\n  \u2203 y, dist x y \u2264 \u03b4 \u2227 dist y z < \u03b5 :=\nbegin\n  refine (exists_dist_eq x z (div_nonneg h\u03b5.le $ add_nonneg h\u03b5.le h\u03b4) (div_nonneg h\u03b4 $ add_nonneg\n    h\u03b5.le h\u03b4) $ by rw [\u2190add_div, div_self (add_pos_of_pos_of_nonneg h\u03b5 h\u03b4).ne']).imp (\u03bb y hy, _),\n  rw [hy.1, hy.2, div_mul_comm, div_mul_comm \u03b5],\n  rw \u2190div_lt_one (add_pos_of_pos_of_nonneg h\u03b5 h\u03b4) at h,\n  exact \u27e8mul_le_of_le_one_left h\u03b4 h.le, mul_lt_of_lt_one_left h\u03b5 h\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_lt_le (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 \u2264 \u03b5) (h : dist x z < \u03b5 + \u03b4) :\n  \u2203 y, dist x y < \u03b4 \u2227 dist y z \u2264 \u03b5 :=\nbegin\n  obtain \u27e8y, yz, xy\u27e9 := exists_dist_le_lt h\u03b5 h\u03b4\n    (show dist z x < \u03b4 + \u03b5, by simpa only [dist_comm, add_comm] using h),\n  exact \u27e8y, by simp [dist_comm x y, dist_comm y z, *]\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_lt_lt (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 < \u03b5) (h : dist x z < \u03b5 + \u03b4) :\n  \u2203 y, dist x y < \u03b4 \u2227 dist y z < \u03b5 :=\nbegin\n  refine (exists_dist_eq x z (div_nonneg h\u03b5.le $ add_nonneg h\u03b5.le h\u03b4.le) (div_nonneg h\u03b4.le $\n    add_nonneg h\u03b5.le h\u03b4.le) $ by rw [\u2190add_div, div_self (add_pos h\u03b5 h\u03b4).ne']).imp (\u03bb y hy, _),\n  rw [hy.1, hy.2, div_mul_comm, div_mul_comm \u03b5],\n  rw \u2190div_lt_one (add_pos h\u03b5 h\u03b4) at h,\n  exact \u27e8mul_lt_of_lt_one_left h\u03b4 h, mul_lt_of_lt_one_left h\u03b5 h\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma disjoint_ball_ball_iff (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 < \u03b5) :\n  disjoint (ball x \u03b4) (ball y \u03b5) \u2194 \u03b4 + \u03b5 \u2264 dist x y :=\nbegin\n  refine \u27e8\u03bb h, le_of_not_lt $ \u03bb hxy, _, ball_disjoint_ball\u27e9,\n  rw add_comm at hxy,\n  obtain \u27e8z, hxz, hzy\u27e9 := exists_dist_lt_lt h\u03b4 h\u03b5 hxy,\n  rw dist_comm at hxz,\n  exact h \u27e8hxz, hzy\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma disjoint_ball_closed_ball_iff (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 \u2264 \u03b5) :\n  disjoint (ball x \u03b4) (closed_ball y \u03b5) \u2194 \u03b4 + \u03b5 \u2264 dist x y :=\nbegin\n  refine \u27e8\u03bb h, le_of_not_lt $ \u03bb hxy, _, ball_disjoint_closed_ball\u27e9,\n  rw add_comm at hxy,\n  obtain \u27e8z, hxz, hzy\u27e9 := exists_dist_lt_le h\u03b4 h\u03b5 hxy,\n  rw dist_comm at hxz,\n  exact h \u27e8hxz, hzy\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma disjoint_closed_ball_ball_iff (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 < \u03b5) :\n  disjoint (closed_ball x \u03b4) (ball y \u03b5) \u2194 \u03b4 + \u03b5 \u2264 dist x y :=\nby rw [disjoint.comm, disjoint_ball_closed_ball_iff h\u03b5 h\u03b4, add_comm, dist_comm]; apply_instance\n\nlemma disjoint_closed_ball_closed_ball_iff (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 \u2264 \u03b5) :\n  disjoint (closed_ball x \u03b4) (closed_ball y \u03b5) \u2194 \u03b4 + \u03b5 < dist x y :=\nbegin\n  refine \u27e8\u03bb h, lt_of_not_ge $ \u03bb hxy, _, closed_ball_disjoint_closed_ball\u27e9,\n  rw add_comm at hxy,\n  obtain \u27e8z, hxz, hzy\u27e9 := exists_dist_le_le h\u03b4 h\u03b5 hxy,\n  rw dist_comm at hxz,\n  exact h \u27e8hxz, hzy\u27e9,\nend\n\nopen emetric ennreal\n\n@[simp] lemma inf_edist_thickening (h\u03b4 : 0 < \u03b4) (s : set E) (x : E) :\n  inf_edist x (thickening \u03b4 s) = inf_edist x s - ennreal.of_real \u03b4 :=\nbegin\n  obtain hs | hs := lt_or_le (inf_edist x s) (ennreal.of_real \u03b4),\n  { rw [inf_edist_zero_of_mem, tsub_eq_zero_of_le hs.le], exact hs },\n  refine (tsub_le_iff_right.2 inf_edist_le_inf_edist_thickening_add).antisymm' _,\n  refine le_sub_of_add_le_right of_real_ne_top _,\n  refine le_inf_edist.2 (\u03bb z hz, le_of_forall_lt' $ \u03bb r h, _),\n  cases r,\n  { exact add_lt_top.2 \u27e8lt_top_iff_ne_top.2 $ inf_edist_ne_top \u27e8z, self_subset_thickening h\u03b4 _ hz\u27e9,\n      of_real_lt_top\u27e9 },\n  have hr : 0 < \u2191r - \u03b4,\n  { refine sub_pos_of_lt _,\n    have := hs.trans_lt ((inf_edist_le_edist_of_mem hz).trans_lt h),\n    rw [of_real_eq_coe_nnreal h\u03b4.le, some_eq_coe] at this,\n    exact_mod_cast this },\n  rw [some_eq_coe, edist_lt_coe, \u2190dist_lt_coe, \u2190add_sub_cancel'_right \u03b4 (\u2191r)] at h,\n  obtain \u27e8y, hxy, hyz\u27e9 := exists_dist_lt_lt hr h\u03b4 h,\n  refine (ennreal.add_lt_add_right of_real_ne_top $ inf_edist_lt_iff.2\n    \u27e8_, mem_thickening_iff.2 \u27e8_, hz, hyz\u27e9, edist_lt_of_real.2 hxy\u27e9).trans_le _,\n  rw [\u2190of_real_add hr.le h\u03b4.le, sub_add_cancel, of_real_coe_nnreal],\n  exact le_rfl,\nend\n\n@[simp] lemma thickening_thickening (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (s : set E) :\n  thickening \u03b5 (thickening \u03b4 s) = thickening (\u03b5 + \u03b4) s :=\n(thickening_thickening_subset _ _ _).antisymm $ \u03bb x, begin\n  simp_rw mem_thickening_iff,\n  rintro \u27e8z, hz, hxz\u27e9,\n  rw add_comm at hxz,\n  obtain \u27e8y, hxy, hyz\u27e9 := exists_dist_lt_lt h\u03b5 h\u03b4 hxz,\n  exact \u27e8y, \u27e8_, hz, hyz\u27e9, hxy\u27e9,\nend\n\n@[simp] lemma cthickening_thickening (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (s : set E) :\n  cthickening \u03b5 (thickening \u03b4 s) = cthickening (\u03b5 + \u03b4) s :=\n(cthickening_thickening_subset h\u03b5 _ _).antisymm $ \u03bb x, begin\n  simp_rw [mem_cthickening_iff, ennreal.of_real_add h\u03b5 h\u03b4.le, inf_edist_thickening h\u03b4],\n  exact tsub_le_iff_right.2,\nend\n\n-- Note: `interior (cthickening \u03b4 s) \u2260 thickening \u03b4 s` in general\n@[simp] lemma closure_thickening (h\u03b4 : 0 < \u03b4) (s : set E) :\n  closure (thickening \u03b4 s) = cthickening \u03b4 s :=\nby { rw [\u2190cthickening_zero, cthickening_thickening le_rfl h\u03b4, zero_add], apply_instance }\n\n@[simp] lemma inf_edist_cthickening (\u03b4 : \u211d) (s : set E) (x : E) :\n  inf_edist x (cthickening \u03b4 s) = inf_edist x s - ennreal.of_real \u03b4 :=\nbegin\n  obtain h\u03b4 | h\u03b4 := le_or_lt \u03b4 0,\n  { rw [cthickening_of_nonpos h\u03b4, inf_edist_closure, of_real_of_nonpos h\u03b4, tsub_zero] },\n  { rw [\u2190closure_thickening h\u03b4, inf_edist_closure, inf_edist_thickening h\u03b4]; apply_instance }\nend\n\n@[simp] lemma thickening_cthickening (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (s : set E) :\n  thickening \u03b5 (cthickening \u03b4 s) = thickening (\u03b5 + \u03b4) s :=\nbegin\n  obtain rfl | h\u03b4 := h\u03b4.eq_or_lt,\n  { rw [cthickening_zero, thickening_closure, add_zero] },\n  { rw [\u2190closure_thickening h\u03b4, thickening_closure, thickening_thickening h\u03b5 h\u03b4]; apply_instance }\nend\n\n@[simp] lemma cthickening_cthickening (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (s : set E) :\n  cthickening \u03b5 (cthickening \u03b4 s) = cthickening (\u03b5 + \u03b4) s :=\n(cthickening_cthickening_subset h\u03b5 h\u03b4 _).antisymm $ \u03bb x, begin\n  simp_rw [mem_cthickening_iff, ennreal.of_real_add h\u03b5 h\u03b4, inf_edist_cthickening],\n  exact tsub_le_iff_right.2,\nend\n\n@[simp] lemma thickening_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (x : E) :\n  thickening \u03b5 (ball x \u03b4) = ball x (\u03b5 + \u03b4) :=\nby rw [\u2190thickening_singleton, thickening_thickening h\u03b5 h\u03b4, thickening_singleton]; apply_instance\n\n@[simp] lemma thickening_closed_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  thickening \u03b5 (closed_ball x \u03b4) = ball x (\u03b5 + \u03b4) :=\nby rw [\u2190cthickening_singleton _ h\u03b4, thickening_cthickening h\u03b5 h\u03b4, thickening_singleton];\n  apply_instance\n\n@[simp] lemma cthickening_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (x : E) :\n  cthickening \u03b5 (ball x \u03b4) = closed_ball x (\u03b5 + \u03b4) :=\nby rw [\u2190thickening_singleton, cthickening_thickening h\u03b5 h\u03b4,\n  cthickening_singleton _ (add_nonneg h\u03b5 h\u03b4.le)]; apply_instance\n\n@[simp] lemma cthickening_closed_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  cthickening \u03b5 (closed_ball x \u03b4) = closed_ball x (\u03b5 + \u03b4) :=\nby rw [\u2190cthickening_singleton _ h\u03b4, cthickening_cthickening h\u03b5 h\u03b4,\n  cthickening_singleton _ (add_nonneg h\u03b5 h\u03b4)]; apply_instance\n\nlemma ball_add_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  ball a \u03b5 + ball b \u03b4 = ball (a + b) (\u03b5 + \u03b4) :=\nby rw [ball_add, thickening_ball h\u03b5 h\u03b4, vadd_ball, vadd_eq_add]; apply_instance\n\nlemma ball_sub_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  ball a \u03b5 - ball b \u03b4 = ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_ball, ball_add_ball h\u03b5 h\u03b4]\n\nlemma ball_add_closed_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  ball a \u03b5 + closed_ball b \u03b4 = ball (a + b) (\u03b5 + \u03b4) :=\nby rw [ball_add, thickening_closed_ball h\u03b5 h\u03b4, vadd_ball, vadd_eq_add]; apply_instance\n\nlemma ball_sub_closed_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  ball a \u03b5 - closed_ball b \u03b4 = ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_closed_ball, ball_add_closed_ball h\u03b5 h\u03b4]\n\nlemma closed_ball_add_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  closed_ball a \u03b5 + ball b \u03b4 = ball (a + b) (\u03b5 + \u03b4) :=\nby rw [add_comm, ball_add_closed_ball h\u03b4 h\u03b5, add_comm, add_comm \u03b4]; apply_instance\n\nlemma closed_ball_sub_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  closed_ball a \u03b5 - ball b \u03b4 = ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_ball, closed_ball_add_ball h\u03b5 h\u03b4]\n\nlemma closed_ball_add_closed_ball [proper_space E] (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  closed_ball a \u03b5 + closed_ball b \u03b4 = closed_ball (a + b) (\u03b5 + \u03b4) :=\nby rw [(is_compact_closed_ball _ _).add_closed_ball h\u03b4, cthickening_closed_ball h\u03b4 h\u03b5,\n  vadd_closed_ball, vadd_eq_add, add_comm, add_comm \u03b4]; apply_instance\n\nlemma closed_ball_sub_closed_ball [proper_space E] (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  closed_ball a \u03b5 - closed_ball b \u03b4 = closed_ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_closed_ball, closed_ball_add_closed_ball h\u03b5 h\u03b4]\n\nend semi_normed_group\n\nsection normed_group\nvariables [normed_group E] [normed_space \ud835\udd5c E]\n\ntheorem smul_closed_ball (c : \ud835\udd5c) (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  c \u2022 closed_ball x r = closed_ball (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  rcases eq_or_ne c 0 with rfl|hc,\n  { simp [hr, zero_smul_set, set.singleton_zero, \u2190 nonempty_closed_ball] },\n  { exact smul_closed_ball' hc x r }\nend\n\nlemma smul_closed_unit_ball (c : \ud835\udd5c) : c \u2022 closed_ball (0 : E) (1 : \u211d) = closed_ball (0 : E) (\u2225c\u2225) :=\nby rw [smul_closed_ball _ _ zero_le_one, smul_zero, mul_one]\n\nvariables [normed_space \u211d E]\n\n/-- In a real normed space, the image of the unit closed ball under multiplication by a nonnegative\nnumber `r` is the closed ball of radius `r` with center at the origin. -/\nlemma smul_closed_unit_ball_of_nonneg {r : \u211d} (hr : 0 \u2264 r) :\n  r \u2022 closed_ball 0 1 = closed_ball (0 : E) r :=\nby rw [smul_closed_unit_ball, real.norm_of_nonneg hr]\n\n/-- In a nontrivial real normed space, a sphere is nonempty if and only if its radius is\nnonnegative. -/\n@[simp] lemma normed_space.sphere_nonempty [nontrivial E] {x : E} {r : \u211d} :\n  (sphere x r).nonempty \u2194 0 \u2264 r :=\nbegin\n  obtain \u27e8y, hy\u27e9 := exists_ne x,\n  refine \u27e8\u03bb h, nonempty_closed_ball.1 (h.mono sphere_subset_closed_ball), \u03bb hr,\n    \u27e8r \u2022 \u2225y - x\u2225\u207b\u00b9 \u2022 (y - x) + x, _\u27e9\u27e9,\n  have : \u2225y - x\u2225 \u2260 0, by simpa [sub_eq_zero],\n  simp [norm_smul, this, real.norm_of_nonneg hr],\nend\n\nlemma smul_sphere [nontrivial E] (c : \ud835\udd5c) (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  c \u2022 sphere x r = sphere (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  rcases eq_or_ne c 0 with rfl|hc,\n  { simp [zero_smul_set, set.singleton_zero, hr] },\n  { exact smul_sphere' hc x r }\nend\n\n/-- Any ball `metric.ball x r`, `0 < r` is the image of the unit ball under `\u03bb y, x + r \u2022 y`. -/\nlemma affinity_unit_ball {r : \u211d} (hr : 0 < r) (x : E) : x +\u1d65 r \u2022 ball 0 1 = ball x r :=\nby rw [smul_unit_ball_of_pos hr, vadd_ball_zero]\n\n/-- Any closed ball `metric.closed_ball x r`, `0 \u2264 r` is the image of the unit closed ball under\n`\u03bb y, x + r \u2022 y`. -/\nlemma affinity_unit_closed_ball {r : \u211d} (hr : 0 \u2264 r) (x : E) :\n  x +\u1d65 r \u2022 closed_ball 0 1 = closed_ball x r :=\nby rw [smul_closed_unit_ball, real.norm_of_nonneg hr, vadd_closed_ball_zero]\n\nend normed_group\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/normed_space/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7321006654340764}}
{"text": "import algebra.archimedean\nimport data.list\nimport all\n\nimport .trythis\n\nnamespace nng\n\nlemma add_assoc (a b c : \u2115)\n  : (a + b) + c = a + (b + c) :=\nbegin\n  -- rw [nat.add_assoc, nat.add_comm a],\n  simp [nat.add_assoc]\nend\n\nopen nat\n\nlemma succ_add (a b : \u2115)\n  : succ a + b = succ (a + b) :=\nbegin\n  -- rw [\u2190 add_succ, add_succ, succ_add]\n  apply succ_add; rw [nat.add_comm, nat.zero_add]; refl\nend\n\nlemma add_right_comm (a b c : \u2115)\n  : a + b + c = a + c + b :=\nbegin\n  -- rw [add_comm a, add_comm a, add_assoc],\n  -- rw [add_comm b, add_comm a, add_assoc]\n  rw add_right_comm; refl\nend\n\nlemma succ_mul (a b : \u2115)\n  : succ a * b = a * b + b :=\nbegin\n  -- rw [\u2190 nat.succ_mul],\n  rw [\u2190 add_one, succ_mul]\nend\n\ntheorem add_le_add_right {a b : \u2115}\n  : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) :=\nbegin\n  -- intros h t,\n  -- rw [nat.add_comm a t, nat.add_comm b t],\n  -- apply nat.add_le_add_left h _\n  apply nat.add_le_add_right\nend\n\ntheorem mul_left_cancel (a b c : \u2115) (ha : a \u2260 0)\n  : a * b = (a + 0) * c \u2192 b = 1 * c :=\nbegin\n  -- simp,\n  -- rintro (\u27e8\u27e8h\u2081, h\u2082\u27e9, rfl\u27e9 | \u27e8\u27e8h\u2081, h\u2082\u27e9, rfl\u27e9),\n  -- assumption,\n  -- contradiction\n  simpa [one_mul] using (mul_left_inj' ha).mp\nend\n\nlemma lt_aux_two (a b : \u2115) : succ a \u2264 b \u2192 a \u2264 b \u2227 \u00ac (b \u2264 a) :=\nbegin\n  intro h, exact \u27e8nat.le_of_succ_le h, not_le_of_gt h\u27e9\nend\n\nuniverse u\nvariables {R : Type u} [linear_ordered_ring R] [floor_ring R] {x : R}\n\nlemma floor_ciel (z : \u2124) : z = \u2308(z:R)\u2309 :=\nbegin\n  -- rw [ceil, \u2190 int.cast_neg, floor_coe, neg_neg]\n  simp\nend\n\nexample (x y : \u2124) : (- - x) - y = -(y - x) :=\nbegin\n  -- simp\n  simp\nend\n\nvariables {G : Type u} [group G]\n\nexample (x y z : G) : (x * z) * (z\u207b\u00b9 * y) = x * y :=\nbegin\n  -- group\n  rw [\u2190mul_assoc, mul_inv_cancel_right]\nend\n\nopen list\n\nexample {\u03b1: Type u} (a : \u03b1) (l : list \u03b1)\n  : list.reverse (l ++ [a]) = a :: l.reverse :=\nbegin\n  simp\n  -- induction l, {refl}, {simp only [*, cons_append, reverse_cons, append_assoc, reverse_nil, perm.nil, append_nil, perm.cons], simp}\nend\n\nend nng\n", "meta": {"author": "jesse-michael-han", "repo": "lean-tpe-public", "sha": "87c7bb8dfb8271d8fcf917aae0e731600c4f4c6c", "save_path": "github-repos/lean/jesse-michael-han-lean-tpe-public", "path": "github-repos/lean/jesse-michael-han-lean-tpe-public/lean-tpe-public-87c7bb8dfb8271d8fcf917aae0e731600c4f4c6c/src/demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7320683720532986}}
{"text": "-- Una_funcion_tiene_inversa_por_la_derecha_si_y_solo_si_es_suprayectiva.lean\n-- Una funci\u00f3n tiene inversa por la derecha si y solo si es suprayectiva\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 7 de agosto de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, que g es una inversa por la izquierda de f est\u00e1 definido por\n--    left_inverse (g : \u03b2 \u2192 \u03b1) (f : \u03b1 \u2192 \u03b2) : Prop :=\n--       \u2200 x, g (f x) = x\n-- que g es una inversa por la derecha de f est\u00e1 definido por\n--    right_inverse (g : \u03b2 \u2192 \u03b1) (f : \u03b1 \u2192 \u03b2) : Prop :=\n--       left_inverse f g\n-- y que f tenga inversa por la derecha est\u00e1 definido por\n--    has_right_inverse (f : \u03b1 \u2192 \u03b2) : Prop :=\n--       \u2203 g : \u03b2 \u2192 \u03b1, right_inverse g f\n-- Finalmente, que f es suprayectiva est\u00e1 definido por\n--    def surjective (f : \u03b1 \u2192 \u03b2) : Prop :=\n--       \u2200 b, \u2203 a, f a = b\n--\n-- Demostrar que la funci\u00f3n f tiene inversa por la derecha si y solo si\n-- es suprayectiva.\n-- ---------------------------------------------------------------------\n\nimport tactic\nopen function classical\n\nvariables {\u03b1 \u03b2: Type*}\nvariable  {f : \u03b1 \u2192 \u03b2}\n\n-- 1\u00aa demostraci\u00f3n\nexample : has_right_inverse f \u2194 surjective f :=\nbegin\n  split,\n  { intros hf b,\n    cases hf with g hg,\n    use g b,\n    exact hg b, },\n  { intro hf,\n    let g := \u03bb y, some (hf y),\n    use g,\n    intro b,\n    apply some_spec (hf b), },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : has_right_inverse f \u2194 surjective f :=\nsurjective_iff_has_right_inverse.symm\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Una_funcion_tiene_inversa_por_la_derecha_si_y_solo_si_es_suprayectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.7320683676106037}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin.\nAll rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Damiano Testa, Kevin Buzzard\n-/\nimport algebra.order.monoid.defs\nimport algebra.order.monoid.with_zero.defs\n\n/-!\nAn example of a `linear_ordered_comm_monoid_with_zero` in which the product of two positive\nelements vanishes.\n\nThis is the monoid with 3 elements `0, \u03b5, 1` where `\u03b5 ^ 2 = 0` and everything else is forced.\nThe order is `0 < \u03b5 < 1`.  Since `\u03b5 ^ 2 = 0`, the product of strictly positive elements can vanish.\n\nRelevant Zulip chat:\nhttps://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/mul_pos\n-/\n\n/--  The three element monoid. -/\n@[derive [decidable_eq]]\ninductive foo\n| zero\n| eps\n| one\n\n\nnamespace foo\n\ninstance inhabited : inhabited foo := \u27e8zero\u27e9\n\ninstance : has_zero foo := \u27e8zero\u27e9\ninstance : has_one foo := \u27e8one\u27e9\nlocal notation `\u03b5` := eps\n\n/-- The order on `foo` is the one induced by the natural order on the image of `aux1`. -/\ndef aux1 : foo \u2192 \u2115\n| 0 := 0\n| \u03b5 := 1\n| 1 := 2\n\n/-- A tactic to prove facts by cases. -/\nmeta def boom : tactic unit :=\n`[repeat {rintro \u27e8\u27e9}; dec_trivial]\n\nlemma aux1_inj : function.injective aux1 :=\nby boom\n\ninstance : linear_order foo :=\nlinear_order.lift' aux1 aux1_inj\n\n/-- Multiplication on `foo`: the only external input is that `\u03b5 ^ 2 = 0`. -/\ndef mul : foo \u2192 foo \u2192 foo\n| 1 x := x\n| x 1 := x\n| _ _ := 0\n\ninstance : comm_monoid foo :=\n{ mul := mul,\n  one := 1,\n  one_mul := by boom,\n  mul_one := by boom,\n  mul_comm := by boom,\n  mul_assoc := by boom }\n\ninstance : linear_ordered_comm_monoid_with_zero foo :=\n{ zero := 0,\n  zero_mul := by boom,\n  mul_zero := by boom,\n  mul_le_mul_left := by { rintro \u27e8\u27e9 \u27e8\u27e9 h \u27e8\u27e9; revert h; dec_trivial },\n  zero_le_one := dec_trivial,\n  .. foo.linear_order,\n  .. foo.comm_monoid }\n\nlemma not_mul_pos : \u00ac \u2200 {M : Type} [linear_ordered_comm_monoid_with_zero M], by exactI \u2200\n  (a b : M) (ha : 0 < a) (hb : 0 < b),\n  0 < a * b :=\nbegin\n  intros h,\n  specialize h \u03b5 \u03b5 (by boom) (by boom),\n  exact (lt_irrefl 0 (h.trans_le (by boom))).elim,\nend\n\nexample : 0 < \u03b5 \u2227 \u03b5 * \u03b5 = 0 := by boom\n\nend foo\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/counterexamples/linear_order_with_pos_mul_pos_eq_zero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7320683582911608}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Eric Rodriguez\n-/\n\nimport data.nat.choose.basic\nimport data.nat.cast\nimport algebra.group_power.lemmas\n\n/-!\n# Inequalities for binomial coefficients\n\nThis file proves exponential bounds on binomial coefficients. We might want to add here the\nbounds `n^r/r^r \u2264 n.choose r \u2264 e^r n^r/r^r` in the future.\n\n## Main declarations\n\n* `nat.choose_le_pow`: `n.choose r \u2264 n^r / r!`\n* `nat.pow_le_choose`: `(n + 1 - r)^r / r! \u2264 n.choose r`. Beware of the fishy \u2115-subtraction.\n-/\n\nopen_locale nat\n\nvariables {\u03b1 : Type*} [linear_ordered_field \u03b1]\n\nnamespace nat\n\nlemma choose_le_pow (r n : \u2115) : (n.choose r : \u03b1) \u2264 n^r / r! :=\nbegin\n  rw le_div_iff',\n  { norm_cast,\n    rw \u2190nat.desc_factorial_eq_factorial_mul_choose,\n    exact n.desc_factorial_le_pow r },\n  exact_mod_cast r.factorial_pos,\nend\n\n-- horrific casting is due to \u2115-subtraction\nlemma pow_le_choose (r n : \u2115) : ((n + 1 - r : \u2115)^r : \u03b1) / r! \u2264 n.choose r :=\nbegin\n  rw div_le_iff',\n  { norm_cast,\n    rw [\u2190nat.desc_factorial_eq_factorial_mul_choose],\n    exact n.pow_sub_le_desc_factorial r },\n  exact_mod_cast r.factorial_pos,\nend\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/combinatorics/choose/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7320118233865491}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport tactic\n\n/-! \n# Nuevas t\u00e1cticas\n* `use`\n* `intro` (nueva forma de uso)\n* `cases` (nueva forma de uso)\n* `rintro`\n* `ext`\n-/\n\n/- ## use \nDada una meta de la forma `\u22a2 \u2203 a, P a`, donde `P a` es una proposici\u00f3n, si `x : X` es el t\u00e9rmino que\nqueremos utilizar en la demostraci\u00f3n, la t\u00e1ctica `use x` convertir\u00e1 la meta en `\u22a2 P x`.\n-/\n\nexample : \u2203 P : Prop, P \u2227 true \u2194 false :=\nbegin\n  use false,\n  tauto,  -- cierra la meta construyendo una tabla de verdad\nend\n\n/- ## intro (nueva forma de uso)\nSi la meta actual es de la forma `\u2200 x : t, u`, entonces `intro x` introduce una hip\u00f3tesis local \n`x : t` y modifica la meta a `\u22a2 u`.\n -/\n\nexample (X : Type) : \u2200 x : X, x = x :=\nbegin\n  intro x,\n  refl,\nend\n\n/- ## rintro \nLa t\u00e1ctica `rintro` permite combinar `intro` y `cases` en una misma aplicaci\u00f3n.\n-/\n\n/- Dada una meta de la forma `P \u2227 Q \u2192 R`,  `rintro \u27e8hP, hQ\u27e9` es equivalente a la secuencia\n`intro h, cases h with hP hQ,`. Es decir, introduce dos hip\u00f3tesis `hP : P` y `hQ : Q` y\ncambia la meta a `R`. -/\nexample (P Q : Prop) : P \u2227 Q \u2192 P :=\nbegin\n  rintro \u27e8hP, hQ\u27e9,\n  exact hP,\nend\n\n/- Dada una meta de la forma `P \u2228 Q \u2192 R`,  `rintro (hP | hQ)` es equivalente a la secuencia\n`intro h, cases h with hP hQ,`. Es decir, introduce dos metas de la forma `\u22a2 R`, una asumiendo\n `hP : P` la otra asumiendo `hQ : Q`. -/\nexample (P Q R : Prop) (hPR : P \u2192 R) (hQR : Q \u2192 R) : P \u2228 Q \u2192 R :=\nbegin\n  rintro (hP | hQ),\n  { exact hPR hP },\n  { exact hQR hQ },\nend\n\n/- ## cases (nueva forma de uso) \nDada una hip\u00f3tesis `h : \u2203 a : X, P a`, donde `P a` es una proposici\u00f3n, la t\u00e1ctica \n`cases h with x hx` devuelve un t\u00e9rmino `x : X` y una demostraci\u00f3n `hx : P x`.\n-/\nexample (X : Type) (P Q : X \u2192 Prop) (h : \u2203 x : X, P x) : \u2203 x : X, P x \u2228 Q x :=\nbegin\n  cases h with x hx,\n  use x,\n  left,\n  exact hx,\nend\n\n/- ## ext \nPara demostrar que dos conjuntos son iguales, basta demostrar que tienen los mismos elementos.#check\nDada la meta `\u22a2 S = T`, donde `S` y `T` son conjuntos (de elementos de mismo tipo), `ext a`\nconvierte la meta en `\u22a2 a \u2208 S \u2194 a \u2208 T`.\n-/\n\nexample (X : Type) (S T : set X) (hST : S \u2286 T) (hTS : T \u2286 S) : S = T :=\nbegin\n  ext a,\n  split,\n  { apply hST },\n  { apply hTS }\nend\n", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_2/tacticas_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7320118213929889}}
{"text": "/- A matroid is defined as a rank function, so this file is the biggest part of the\n   matroid API. \n-/\n\nimport matroid.axioms  matroid.dual \nimport prelim.collections prelim.minmax \nopen set \n\nuniverses u\n\nopen_locale classical \nopen_locale big_operators \nnoncomputable theory \n----------------------------------------------------------------\nnamespace matroid \nvariables {\u03b1 : Type*} [fintype \u03b1] {M : matroid \u03b1} {e f x y z : \u03b1}\n{X Y Z X' Y' Z' F B I C C\u2081 C\u2082 F\u2081 F\u2082 P  L\u2081 L\u2082 : set \u03b1}\n\n-- probably split up these set notations by section...\n\nsection /- rank -/ rank\n\n\ndef rank (M : matroid \u03b1) := M.r univ \n\ndef r_nat (M : matroid \u03b1) (X : set \u03b1) := (M.r X).to_nat \n\ndef rank_nat (M : matroid \u03b1) := M.r_nat univ\n\n@[simp] lemma rank_eq (M : matroid \u03b1) : M.rank = M.r univ := rfl \n\nlemma r_nat_eq : M.r_nat X = (M.r X).to_nat := rfl\n\nlemma rank_nat_eq : M.rank_nat = (M.r univ).to_nat := rfl \n\n/-- rank is nonnegative -/\nlemma rank_nonneg (M : matroid \u03b1) (X : set \u03b1) :\n  0 \u2264 M.r X := \nM.R0 X \n\n@[simp] lemma coe_r_nat (M : matroid \u03b1) (X : set \u03b1) :\n  (M.r_nat X : \u2124) = M.r X := \nint.to_nat_of_nonneg (M.rank_nonneg X)\n\n@[simp] lemma coe_rank_nat (M : matroid \u03b1) :\n  (M.rank_nat : \u2124) = M.r univ := \nint.to_nat_of_nonneg (M.rank_nonneg _)\n\n/-- rank is bounded above by size -/\nlemma rank_le_size (M : matroid \u03b1) (X : set \u03b1) :\n  M.r X \u2264 size X := \nM.R1 X \n\n/-- rank is monotone wrt set inclusion -/\nlemma rank_mono (M : matroid \u03b1) :\n  X \u2286 Y \u2192 M.r X \u2264 M.r Y := \nM.R2 X Y\n\n/-- rank is submodular -/\nlemma rank_submod (M : matroid \u03b1) (X Y : set \u03b1) :\n  M.r (X \u222a Y) + M.r (X \u2229 Y) \u2264 M.r X + M.r Y := \nM.R3 X Y \n\nlemma rank_mono_inter_left (M : matroid \u03b1) (X Y : set \u03b1) : \n  M.r (X \u2229 Y) \u2264 M.r X := \nM.rank_mono (inter_subset_left X Y)\n\nlemma rank_mono_union_left (M : matroid \u03b1) (X Y : set \u03b1) : \n  M.r X \u2264 M.r (X \u222a Y) := \nM.rank_mono (subset_union_left X Y)\n\nlemma rank_mono_inter_right (M : matroid \u03b1) (X Y : set \u03b1) : \n  M.r (X \u2229 Y) \u2264 M.r Y := \nM.rank_mono (inter_subset_right X Y)\n\nlemma rank_mono_union_right (M : matroid \u03b1) (X Y : set \u03b1) : \n  M.r Y \u2264 M.r (X \u222a Y) := \nM.rank_mono (subset_union_right X Y)\n\nlemma rank_mono_diff (M : matroid \u03b1) (X Y : set \u03b1) :\n  M.r (X \\ Y) \u2264 M.r X := \nby {rw diff_eq, apply rank_mono_inter_left}\n\nlemma rank_eq_zero_of_le_zero :\n  M.r X \u2264 0 \u2192 M.r X = 0 := \n\u03bb h, le_antisymm h (M.rank_nonneg X)\n\nlemma rank_zero_of_subset_rank_zero : \n  X \u2286 Y \u2192 M.r Y = 0 \u2192 M.r X = 0 := \n\u03bb hXY hY, by {apply rank_eq_zero_of_le_zero, rw \u2190hY, exact rank_mono M hXY}\n\nlemma rank_zero_of_inter_rank_zero (X : set \u03b1) :\n  M.r Y = 0 \u2192 M.r (X \u2229 Y) = 0 :=\n\u03bb hY, by {apply rank_zero_of_subset_rank_zero _ hY, simp }\n\n@[simp] lemma rank_empty (M : matroid \u03b1) : \n  M.r \u2205 = 0 := \nrank_eq_zero_of_le_zero (by {convert M.rank_le_size _, rw size_empty })\n\nlemma rank_lt_size_ne_empty : \n  M.r X < size X \u2192 X \u2260 \u2205 := \n\u03bb h hX, by {rw [hX, size_empty, rank_empty] at h, from lt_irrefl _ h,  }\n\nlemma nonempty_of_r_nonzero (M : matroid \u03b1) : \n  M.r X \u2260 0 \u2192 X.nonempty := \nby {contrapose!, intro h, rw not_nonempty_iff_eq_empty at h, rw [h, rank_empty],  } \n\nlemma rank_single_ub (M : matroid \u03b1) (e : \u03b1) :\n  M.r {e} \u2264 1 := \nby {rw \u2190(size_singleton e), exact M.rank_le_size {e}}\n\nlemma rank_le_univ (M : matroid \u03b1) (X : set \u03b1) : \n  M.r X \u2264 M.r univ := \nM.rank_mono (subset_univ X)\n\nlemma rank_compl_univ (M : matroid \u03b1) : \n  M.r (univ\u1d9c) = 0 := \nby rw [compl_univ, rank_empty]\n\nlemma rank_gt_zero_of_ne :\n  M.r X \u2260 0 \u2192 0 < M.r X := \n\u03bb h, lt_of_le_of_ne (M.rank_nonneg X) (ne.symm h)\n\nlemma rank_eq_of_le_supset :\n  X \u2286 Y \u2192 (M.r Y \u2264 M.r X) \u2192 M.r X = M.r Y :=\n\u03bb h h', (le_antisymm (M.rank_mono h) h') \n\nlemma rank_eq_of_le_union :\n  M.r (X \u222a Y) \u2264 M.r X \u2192 M.r (X \u222a Y) = M.r X :=\n\u03bb h, ((rank_eq_of_le_supset ((subset_union_left _ _))) h).symm\n\nlemma rank_eq_of_le_inter :\n  M.r X \u2264 M.r (X \u2229 Y) \u2192  M.r (X \u2229 Y) = M.r X :=\n\u03bb h, (rank_eq_of_le_supset (inter_subset_left _ _) h)\n\nlemma rank_eq_of_not_lt_supset :\n  X \u2286 Y \u2192 \u00ac(M.r X < M.r Y) \u2192 M.r X = M.r Y :=\n\u03bb h h', rank_eq_of_le_supset h (int.le_of_not_gt' h')\n\nlemma rank_eq_of_not_lt_union :\n  \u00ac (M.r X < M.r (X \u222a Y)) \u2192 M.r (X \u222a Y) = M.r X :=\n\u03bb h', rank_eq_of_le_union (int.le_of_not_gt' h')\n\n@[simp] lemma rank_eq_rank_union_rank_zero (X : set \u03b1){Y :set \u03b1} (hY : M.r Y = 0) :\n  M.r (X \u222a Y) = M.r X := \nby {apply rank_eq_of_le_union, linarith [M.rank_nonneg (X \u2229 Y ), M.rank_submod X Y],} \n\nlemma rank_eq_rank_diff_rank_zero (X : set \u03b1) (hY : M.r Y = 0) : \n  M.r (X \\ Y) = M.r X :=\nbegin\n  refine le_antisymm (rank_mono_diff _ _ _) _,\n  rw \u2190rank_eq_rank_union_rank_zero (X \\ Y) hY, \n   exact rank_mono _ (\u03bb x hx, by {rw [mem_union, mem_diff ], tauto,}), \nend\n\nlemma rank_zero_of_union_rank_zero :\n  M.r X = 0 \u2192 M.r Y = 0 \u2192 M.r (X \u222a Y) = 0 :=\n\u03bb hX hY, by {rw (rank_eq_rank_union_rank_zero _ hY), exact hX }\n\nlemma rank_eq_of_union_eq_rank_subset (Z: set \u03b1) :\n  X \u2286 Y \u2192 M.r X = M.r Y \u2192 M.r (X \u222a Z) = M.r (Y \u222a Z) := \nbegin\n  intros hXY hr, apply rank_eq_of_le_supset (union_subset_union_left Z hXY), \n  have : M.r ((X \u222a Z) \u2229 Y) = _ := by rw [inter_distrib_right, subset_iff_inter_eq_left.mp hXY] ,\n  have : M.r ((X \u222a Z) \u222a Y) = _ := by rw [union_assoc, union_comm Z Y, \u2190union_assoc, \n                                      subset_iff_union_eq_left.mp hXY ],\n  linarith [M.rank_submod (X \u222a Z) Y , M.rank_mono_union_left X (Z \u2229 Y) ], \nend \n\nlemma rank_eq_of_union_eq_rank_subsets (hX : X \u2286 X') (hY : Y \u2286 Y')\n(hXX' : M.r X = M.r X') (hYY' : M.r Y = M.r Y') :\n  M.r (X \u222a Y) = M.r (X' \u222a Y') :=\nby rw [rank_eq_of_union_eq_rank_subset Y hX hXX', union_comm, union_comm _ Y',\n       rank_eq_of_union_eq_rank_subset _ hY hYY']  \n\nlemma rank_eq_of_inter_union (X Y A : set \u03b1) :\n  M.r (X \u2229 A) = M.r X \u2192 M.r ((X \u2229 A) \u222a Y) = M.r (X \u222a Y) :=\n\u03bb h, rank_eq_of_union_eq_rank_subset _ (inter_subset_left _ _) h \n  \nlemma rank_eq_of_union_rank_diff_eq (Z : set \u03b1) (hX : M.r (X \\ Y) = M.r X) :\n  M.r (Z \u222a (X \\ Y)) = M.r (Z \u222a X) := \nby {rw diff_eq at *, rw [union_comm _ X, \u2190 rank_eq_of_inter_union _ Z _ hX, union_comm Z]} \n\nlemma rank_subadditive (M : matroid \u03b1) (X Y : set \u03b1) : \n  M.r (X \u222a Y) \u2264 M.r X + M.r Y :=\nby linarith [M.rank_submod X Y, M.rank_nonneg (X \u2229 Y)]\n\nlemma rank_subadditive_sUnion (M : matroid \u03b1) (S : set (set \u03b1)) :\n  M.r (\u22c3\u2080 S) \u2264 \u2211\u1da0 X in S, M.r X := \nbegin\n  set P := \u03bb (S : set (set \u03b1)), M.r (\u22c3\u2080 S) \u2264 \u2211\u1da0 X in S, M.r X with hP, \n  refine induction_set_size_insert P (by {rw hP, simp}) (\u03bb X A hA hX, _) _, \n  rw [hP, sUnion_insert, fin.finsum_in_insert _ hA],\n  exact le_trans (rank_subadditive M _ _) (int.add_le_add_left hX _), \nend \n\nlemma rank_augment_single_ub (M : matroid \u03b1) (X : set \u03b1) (e : \u03b1) : \n  M.r (X \u222a {e}) \u2264 M.r X + 1 := \nby linarith [rank_subadditive M X {e}, rank_single_ub M e]\n\nlemma rank_eq_add_one_of_ne_aug :\n  M.r (X \u222a {e}) \u2260 M.r X \u2192 M.r (X \u222a {e}) = M.r X + 1 := \nbegin\n  intro h, apply le_antisymm,\n  from (rank_augment_single_ub M X e), \n  from (int.add_one_le_of_lt (lt_of_le_of_ne (rank_mono_union_left M _ _) (ne.symm h))),\nend\n\nlemma rank_eq_of_le_aug :\n  M.r (X \u222a {e}) \u2264 M.r X \u2192 M.r (X \u222a {e}) = M.r X :=  \n\u03bb h, le_antisymm h (rank_mono_union_left _ _ _) \n\nlemma rank_diff_subadditive (M : matroid \u03b1) (X Y : set \u03b1) :\n  M.r Y \u2264 M.r X + M.r (Y \\ X) := \nle_trans (M.rank_mono (by simp)) (rank_subadditive M X (Y \\ X))\n\nlemma rank_remove_single_lb (M : matroid \u03b1) (X : set \u03b1) (e : \u03b1) :\n  M.r X - 1 \u2264 M.r (X \\ {e}) :=\nby linarith [rank_diff_subadditive M {e} X, rank_single_ub M e]\n\nlemma rank_eq_sub_one_of_ne_remove (M : matroid \u03b1) (X : set \u03b1) (e : \u03b1) :\n  M.r X \u2260 M.r (X \\ {e}) \u2192 M.r (X \\ {e}) = M.r X - 1 :=\nbegin\n  intro h, apply le_antisymm  _ (rank_remove_single_lb M X e), \n  apply int.le_sub_one_of_le_of_ne _ (ne.symm h), \n  apply rank_mono_diff, \nend\n\nlemma rank_diff_le_size_diff (M : matroid \u03b1) (hXY : X \u2286 Y) :\n  M.r Y - M.r X \u2264 size Y - size X := \nby linarith [rank_diff_subadditive M X Y, diff_size hXY, M.rank_le_size (Y \\ X )]\n  \n\nlemma submod_three_sets (M : matroid \u03b1) (X Y Y' : set \u03b1) :\n  M.r (X \u222a (Y \u222a Y')) + M.r (X \u222a (Y \u2229 Y')) \u2264 M.r (X \u222a Y) + M.r (X \u222a Y') := \nby {have := M.rank_submod (X \u222a Y) (X \u222a Y'), rw [\u2190union_distrib_left, \u2190union_distrib_union_right] at this, exact this}\n\nlemma submod_three_sets_right (M : matroid \u03b1) (X Y Y' : set \u03b1) :\n  M.r ((Y \u222a Y') \u222a X) + M.r ((Y \u2229 Y') \u222a X) \u2264 M.r (Y \u222a X) + M.r (Y' \u222a X) := \nby {simp_rw \u2190(union_comm X), apply submod_three_sets} \n\nlemma submod_three_sets_disj (M : matroid \u03b1) (X Y Y' : set \u03b1) (hYY' : Y \u2229 Y' = \u2205) :\n  M.r (X \u222a (Y \u222a Y')) + M.r (X) \u2264 M.r (X \u222a Y) + M.r (X \u222a Y') := \nby {have := submod_three_sets M X Y Y', rw [hYY', union_empty] at this, exact this}\n\n/-lemma union_rank_diff_le_rank_diff (M : matroid \u03b1) (X Y Z : set \u03b1) (hXY : X \u2286 Y) :\n  M.r (Y \u222a Z) - M.r (X \u222a Z) \u2264 M.r Y - M.r X :=\nbegin\n  have := rank_submod M Y Z, \n  have := rank_submod M X Z, \nend -/\n\n\ntheorem rank_augment  {X Z : set \u03b1} : (M.r X < M.r Z) \u2192 \n  \u2203 (z : \u03b1), z \u2208 Z \u2227 M.r X < M.r (X \u222a {z}) := \nlet P : set \u03b1 \u2192 Prop := \u03bb X', \n  (M.r X' = M.r X) \u2227 (X' \u2286 X \u222a Z) \u2227 (\u2200 (e:\u03b1), e \u2208 X \u222a Z \u2192 M.r (X' \u222a {e}) = M.r X') in  \nbegin\n  intro hXZ, \n  \n  by_contra h_con, push_neg at h_con, \n  replace h_con : \u2200 (z:\u03b1), z \u2208 X \u222a Z \u2192 M.r (X \u222a {z}) = M.r X := \n  by {  intros z hz, rw mem_union_iff at hz, cases hz, \n        rw union_mem_singleton hz, \n        from (rank_eq_of_le_supset (subset_union_left _ _) (h_con z hz)).symm\n        },\n\n  rcases maximal_example_aug P \u27e8rfl, \u27e8subset_union_left _ _, h_con\u27e9\u27e9 \n    with \u27e8Y, \u27e8hXY,\u27e8\u27e8hYX, \u27e8hYXZ, h_aug\u27e9\u27e9 , hYmax\u27e9\u27e9\u27e9, \n  by_cases Y = X \u222a Z, \n  rw h at hYX,\n  linarith [M.rank_mono_union_right X Z],  \n  cases mem_diff_ssubset (ssubset_of_subset_ne hYXZ h) with e he,\n  rw mem_diff_iff at he, \n  have h_aug_e := h_aug e he.1, \n  have hYe := hYmax e he.2, push_neg at hYe,\n  rcases hYe (eq.trans h_aug_e hYX) (union_subset hYXZ (singleton_subset_iff.mpr he.1))\n    with \u27e8f, \u27e8hf, h_aug_ef\u27e9\u27e9, \n  replace h_aug_ef := rank_eq_add_one_of_ne_aug h_aug_ef,\n  rw union_assoc at h_aug_ef, \n  have h_aug_f := h_aug f hf, \n  \n  have hef : ({e} \u2229 {f} : set \u03b1) = \u2205 := inter_distinct_singles\n    (\u03bb h, by {rw [h, union_self] at h_aug_ef, linarith}),\n  \n  linarith [submod_three_sets_disj M Y {e} {f} hef],\nend\n\nlemma rank_eq_of_rank_all_insert_eq (hXY : X \u2286 Y) :\n  (\u2200 e : Y, M.r X = M.r (X \u222a {e})) \u2192 M.r X = M.r Y := \nbegin\n  refine (\u03bb h, rank_eq_of_le_supset hXY (by_contra (\u03bb hn, _))),\n  obtain \u27e8f,hfY,hf\u27e9 := rank_augment (not_le.mp hn), \n  specialize h \u27e8f, hfY\u27e9, rw [subtype.coe_mk] at h, linarith, \nend  \n\nlemma rank_eq_of_rank_all_insert_le (hXY : X \u2286 Y) :\n  (\u2200 e : Y, M.r (X \u222a {e}) \u2264 M.r X) \u2192 M.r X = M.r Y := \nbegin\n  refine (\u03bb h, rank_eq_of_le_supset hXY (by_contra (\u03bb hn, _))),\n  obtain \u27e8f,hfY,hf\u27e9 := rank_augment (not_le.mp hn), \n  specialize h \u27e8f, hfY\u27e9, rw [subtype.coe_mk] at h, linarith, \nend  \n\nlemma loopy_rank_zero  (he : (\u2200 (e:\u03b1), e \u2208 X \u2192 M.r {e} = 0)) : \n  M.r X = 0 :=\nbegin\n  by_contra h, \n  replace h := rank_gt_zero_of_ne h, \n  rcases rank_augment (by linarith [rank_empty M] : M.r \u2205 < M.r X) with \u27e8f,hf, hf'\u27e9,\n  rw [empty_union, rank_empty, he _ hf] at hf', \n  apply lt_irrefl _ hf', \nend \n\nend rank \n\n-- Independence \n\nsection indep\n\n/-- is independent in M; rank equals size -/\ndef is_indep (M : matroid \u03b1) : set \u03b1 \u2192 Prop :=\n  \u03bb X, M.r X = size X\n\n/-- independent set type -/ \ndef indep (M : matroid \u03b1) := {I : set \u03b1 // M.is_indep I}\n\ninstance coe_indep : has_coe (M.indep) (set \u03b1) := \n  coe_subtype   \n\n\ninstance fintype_indep : fintype (M.indep) := \nby {unfold indep, apply_instance }\n\n\ndef is_indep_subset_of (M : matroid \u03b1) (X : set \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb I, I \u2286 X \u2227 M.is_indep I \n\ndef indep_subset_of (M : matroid \u03b1) (X : set \u03b1) := {I : set \u03b1 // M.is_indep_subset_of X I}\n\n/-- is dependent in M; negation of independence -/\ndef is_dep (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n   \u03bb X, \u00ac(M.is_indep X)\n\nlemma indep_iff_r : \n  M.is_indep X \u2194 M.r X = size X := \nby refl \n\nlemma indep_iff_size_le_r : \n  M.is_indep X \u2194 size X \u2264 M.r X := \nby {rw [indep_iff_r], exact \u27e8\u03bb h, by rw h, \u03bb h, le_antisymm (M.rank_le_size X) h\u27e9} \n\nlemma r_indep :\n  M.is_indep X \u2192 M.r X = size X :=\nindep_iff_r.mp \n\nlemma dep_iff_r :\n  is_dep M X \u2194 M.r X < size X := \nby {unfold is_dep, rw indep_iff_r, exact \u27e8\u03bb h, (ne.le_iff_lt h).mp (M.rank_le_size X), \u03bb h, by linarith\u27e9}\n\n--instance coe_coindep : has_coe (coindep M) \u03b1 := \u27e8\u03bb I, I.val\u27e9  \n\nlemma indep_or_dep (M : matroid \u03b1) (X : set \u03b1) : \n  M.is_indep X \u2228 M.is_dep X := \nby {rw [dep_iff_r, indep_iff_r], exact eq_or_lt_of_le (M.rank_le_size X)}\n\nlemma dep_iff_not_indep : \n  M.is_dep X \u2194 \u00acM.is_indep X := \nby {rw [indep_iff_r, dep_iff_r], exact \u27e8\u03bb h, by linarith, \u03bb h, (ne.le_iff_lt h).mp (M.rank_le_size X)\u27e9}\n\nlemma not_indep_iff_r :\n  \u00acis_indep M X \u2194 M.r X < size X := \nby {rw \u2190dep_iff_not_indep, apply dep_iff_r, }\n\nlemma indep_iff_not_dep : \n  M.is_indep X \u2194 \u00acM.is_dep X := \nby {rw dep_iff_not_indep, simp}\n\nlemma coindep_iff_r  :\n  (dual M).is_indep X \u2194 (M.r X\u1d9c = M.r univ) := \nby {unfold is_indep dual, dsimp only, split; {intros h, linarith}}\n\nlemma codep_iff_r  : \n  is_dep (dual M) X \u2194 (M.r X\u1d9c < M.r univ) := \nby {rw [dep_iff_not_indep, coindep_iff_r], exact \u27e8\u03bb h, (ne.le_iff_lt h).mp (rank_le_univ M X\u1d9c), \u03bb h, by linarith\u27e9}\n    \nlemma not_coindep_iff_r :\n  \u00acis_indep (dual M) X \u2194 (M.r X\u1d9c < M.r univ) := \nby rw [\u2190dep_iff_not_indep, codep_iff_r] \n\nlemma empty_indep (M : matroid \u03b1) :\n  M.is_indep \u2205 :=  \nby rw [indep_iff_r, size_empty, rank_empty]\n\nlemma dep_nonempty   (hdep : is_dep M X ) :\n  X \u2260 \u2205 := \n\u03bb h, let h' := empty_indep M in by {rw \u2190h at h', exact hdep h'}\n\nlemma subset_indep : \n  X \u2286 Y \u2192 M.is_indep Y \u2192 M.is_indep X := \nbegin \n  intro hXY, simp_rw indep_iff_r, intro hY, \n  linarith [M.rank_le_size X, M.rank_le_size (Y \\ X ), diff_size hXY, rank_diff_subadditive M X Y]\nend \n\nlemma indep_aug : \n  size X < size Y \u2192 M.is_indep X \u2192 M.is_indep Y \u2192 (\u2203 (e:\u03b1), e \u2208 Y \u2227 e \u2209 X \u2227 M.is_indep (X \u222a {e})) := \nbegin\n  simp_rw indep_iff_r,\n  intros hXY hIX hIY,\n  rcases rank_augment (by linarith : M.r X < M.r Y) with \u27e8e,\u27e8h\u2081, h\u2082\u27e9\u27e9, \n  have hx : \u00ac({e} \u2286 X),\n  { exact (\u03bb he, by {rw [union_comm, subset_iff_union_eq_left.mp he] at h\u2082, linarith})}, \n  rw singleton_subset_iff at hx,\n  refine \u27e8e,\u27e8h\u2081,hx,_\u27e9\u27e9, \n  have hs := (size_modular X {e}),\n  rw [ eq.trans (inter_comm X {e}) (nonmem_disjoint hx), size_empty] at hs, \n  linarith [size_singleton e, M.rank_le_size (X \u222a {e}), int.add_one_le_iff.mpr h\u2082],  \nend\n\nlemma indep_aug_diff : \n  size X < size Y \u2192 M.is_indep X \u2192 M.is_indep Y  \u2192 (\u2203 (e:\u03b1), e \u2208 Y \\ X  \u2227 M.is_indep (X \u222a {e})) := \n\u03bb h\u2081 h\u2082 h\u2083, by {simp_rw mem_diff_iff, simp_rw and_assoc, exact indep_aug h\u2081 h\u2082 h\u2083}\n\nlemma indep_of_indep_aug :\n  M.is_indep I \u2192 M.r I < M.r (I \u222a {e}) \u2192 M.is_indep (I \u222a {e}) :=\nbegin\n  intros hI h, \n  rw indep_iff_r at *, \n  apply le_antisymm (M.rank_le_size _ ),\n  refine le_trans (size_union_singleton_ub) _, \n  rw hI at h, convert h, \nend\n\n\nlemma dep_subset : \n  X \u2286 Y \u2192 is_dep M X \u2192 is_dep M Y := \nby {intro hXY, repeat {rw dep_iff_not_indep}, contrapose!, exact subset_indep hXY}\n\nlemma empty_indep_r (M : matroid \u03b1) :\n   M.r \u2205 = size (\u2205 : set \u03b1) :=\n(empty_indep M)\n\nlemma subset_indep_r : \n  X \u2286 Y \u2192 M.r Y = size Y \u2192 M.r X = size X := \n\u03bb h, by {have := subset_indep h, rw [indep_iff_r, indep_iff_r] at this, assumption} \n\n\nlemma mem_indep_r (he : e \u2208 I) (hI : M.is_indep I) :\n  M.r {e} = 1 := \nbegin \n  rw [\u2190singleton_subset_iff] at he, \n  rw [\u2190size_singleton e, \u2190indep_iff_r], \n  exact subset_indep_r he hI, \nend\n\ninstance nonempty_indep : nonempty (M.indep) := \nby {apply nonempty_subtype.mpr, from \u27e8\u2205, M.empty_indep\u27e9}\n\nlemma indep_of_subset_indep : \n  X \u2286 Y \u2192 M.is_indep Y \u2192 M.is_indep X := \nbegin \n  intro hXY, simp_rw indep_iff_r, intro hY, \n  linarith [M.rank_le_size X, M.rank_le_size (Y \\ X ), \n  diff_size hXY, rank_diff_subadditive M X Y]\nend \n\nlemma inter_indep_of_indep_right (X Y : set \u03b1) :\n  M.is_indep Y \u2192 M.is_indep (X \u2229 Y) :=\n\u03bb h, indep_of_subset_indep (inter_subset_right _ _) h \n\nlemma inter_indep_of_indep_left (X Y : set \u03b1) :\n  M.is_indep X \u2192 M.is_indep (X \u2229 Y) :=\n\u03bb h, indep_of_subset_indep (inter_subset_left _ _) h \n\nlemma indep_of_union_indep_right :\n  M.is_indep (X \u222a Y) \u2192 M.is_indep Y :=\n\u03bb h, indep_of_subset_indep (subset_union_right _ _) h\n\nlemma indep_of_union_indep_left :\n  M.is_indep (X \u222a Y) \u2192 M.is_indep X :=\n\u03bb h, indep_of_subset_indep (subset_union_left _ _) h \n\nlemma I3 : \n  size X < size Y \u2192 M.is_indep X \u2192 M.is_indep Y \u2192 (\u2203 (e:\u03b1), e \u2208 Y \\ X \u2227 M.is_indep (X \u222a {e})) := \n  indep_aug_diff \n\nlemma indep_inter_rank_zero (hI : M.is_indep I) (hX : M.r X = 0) : \n   I \u2229 X = \u2205 :=\nbegin\n  have h := inter_indep_of_indep_left I X hI, \n  rwa [indep_iff_r,rank_zero_of_inter_rank_zero I hX, eq_comm, size_zero_iff_empty] at h, \nend\n\n/-- converts a matroid to an independence family -/\ndef to_indep_family (M : matroid \u03b1) : indep_family \u03b1 := \n  \u27e8M.is_indep, empty_indep M, @indep_of_subset_indep _ _ M, @I3 _ _ M\u27e9\n\n\ninstance nonempty_indep_subset_of (M : matroid \u03b1) (X : set \u03b1) : nonempty (indep_subset_of M X) :=\nby {apply nonempty_subtype.mpr, exact \u27e8\u2205,\u27e8empty_subset _, M.empty_indep\u27e9 \u27e9, }\n\ninstance fintype_indep_subset_of (M : matroid \u03b1) (X : set \u03b1) : fintype (indep_subset_of M X) :=\nby {unfold indep_subset_of, apply_instance, } \n\n\n\nend indep \n\nsection /-Circuits-/ circuit\n\n/-- is a circuit of M : minimally dependent -/\ndef is_circuit (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb X, (\u00acis_indep M X \u2227  \u2200 Y: set \u03b1, Y \u2282 X \u2192 M.is_indep Y)\n\n/-- circuit type -/\ndef circuit (M : matroid \u03b1) := { C : set \u03b1 // M.is_circuit C }\n\ninstance coe_circuit : has_coe (M.circuit) (set \u03b1) := \n  coe_subtype    \n\ninstance fintype_circuit : fintype (M.circuit) := \nby {unfold circuit, apply_instance }\n\n/-- is a cocircuit of M: circuit of the dual -/\ndef is_cocircuit (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  is_circuit (dual M)\n\n/-- cocircuit type -/ \ndef cocircuit (M : matroid \u03b1) := { C : set \u03b1 // M.is_cocircuit C }\n\ninstance coe_cocircuit : has_coe (cocircuit M) (set \u03b1) := \n  coe_subtype    \ninstance fintype_cocircuit : fintype (cocircuit M) := \nby {unfold cocircuit, apply_instance}   \n\nlemma circuit_iff_i : \n  M.is_circuit X \u2194 \u00acis_indep M X \u2227  \u2200 Y: set \u03b1, Y \u2282 X \u2192 M.is_indep Y :=\nby rw is_circuit \n\nlemma circuit_iff_r  (X : set \u03b1) :\n  M.is_circuit X \u2194 (M.r X = size X - 1) \u2227 (\u2200 Y: set \u03b1, Y \u2282 X \u2192 M.r Y = size Y) := \nbegin\n  unfold is_circuit,\n  rw not_indep_iff_r, \n  simp_rw indep_iff_r, \n  split, \n  { rintros \u27e8hr, hmin\u27e9,\n    split, \n    { obtain \u27e8Y, \u27e8hY\u2081, hY\u2082\u27e9\u27e9 := has_sub_one_size_ssubset_of_ne_empty (rank_lt_size_ne_empty hr), \n      specialize hmin Y hY\u2081,  \n      linarith [M.rank_mono hY\u2081.1]},\n    exact \u03bb Y hY, hmin _ hY},\n  rintros \u27e8h\u2081, h\u2082\u27e9, \n  refine \u27e8by linarith, \u03bb Y hY, _ \u27e9,  \n  from h\u2082 _ hY, \nend\n\nlemma r_cct  :\n  M.is_circuit C \u2192 M.r C = size C - 1 := \n\u03bb hC, ((circuit_iff_r C).mp hC).1\n  \nlemma r_cct_ssub  {C Y : set \u03b1} : \n  M.is_circuit C \u2192 (Y \u2282 C) \u2192 M.r Y = size Y :=\n\u03bb hC hYC, (((circuit_iff_r C).mp hC).2 Y hYC)\n\nlemma cocircuit_iff_r  (X : set \u03b1) :\n  M.is_cocircuit X \u2194 (M.r X\u1d9c = M.r univ - 1) \u2227 (\u2200 Y: set \u03b1, Y \u2282 X \u2192 M.r Y\u1d9c = M.r univ) := \nbegin \n  simp_rw [is_cocircuit, is_circuit, not_coindep_iff_r, coindep_iff_r],\n  split, rintros \u27e8h\u2081, h\u2082\u27e9, split, \n  have h_nonempty : X \u2260 \u2205 := by {intros h, rw [h,compl_empty] at h\u2081, exact int.lt_irrefl _ h\u2081}, \n  rcases (has_sub_one_size_ssubset_of_ne_empty h_nonempty) with \u27e8Y,\u27e8hY\u2081, hY\u2082\u27e9\u27e9 ,\n  specialize h\u2082 _ hY\u2081,  \n  rw [\u2190compl_compl Y, \u2190compl_compl X, compl_size, compl_size X\u1d9c] at hY\u2082, \n  linarith[M.rank_diff_le_size_diff (compl_subset_compl.mpr hY\u2081.1)], \n  exact h\u2082, rintros \u27e8h\u2081, h\u2082\u27e9, exact \u27e8by linarith, h\u2082\u27e9, \nend \n\nlemma dep_iff_contains_circuit  :\n  is_dep M X \u2194 \u2203 C, M.is_circuit C \u2227 C \u2286 X := \nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _ \u27e9, \n  rcases (minimal_example _ h) with \u27e8Z,\u27e8h\u2081Z,h\u2082Z, h\u2083Z\u27e9\u27e9, \n  refine \u27e8Z, \u27e8\u27e8h\u2082Z, (\u03bb Y hY, _)\u27e9, h\u2081Z\u27e9\u27e9, \n  rw indep_iff_not_dep, exact h\u2083Z Y hY,  \n  cases h with C hC, exact dep_subset hC.2 hC.1.1, \nend \n\n/-- circuits nonempty unless matroid is free -/\ninstance nonempty_circuit (hM : M.r univ < size univ) : nonempty (M.circuit) := \nbegin \n  apply nonempty_subtype.mpr, \n  rw [\u2190dep_iff_r, dep_iff_contains_circuit] at hM, \n  cases hM with C hC, \n  from \u27e8C,hC.1\u27e9, \nend \n\n/-- cocircuits nonempty unless matroid is loopy -/\ninstance nonempty_cocircuit (hM : 0 < M.r univ) : nonempty (cocircuit M) := \nbegin\n  refine matroid.nonempty_circuit (_ : (dual M).r univ < size univ), \n  rw [dual_r, compl_univ, M.rank_empty], linarith, \nend\n\nlemma circuit_dep :\n  M.is_circuit C \u2192 M.is_dep C := \n\u03bb h, dep_iff_contains_circuit.mpr \u27e8C,h,subset_refl _\u27e9 \n\nlemma indep_iff_contains_no_circuit : \n  M.is_indep X \u2194 \u00ac\u2203 C, M.is_circuit C \u2227 C \u2286 X :=\nby rw [\u2190not_iff_not, \u2190dep_iff_not_indep, dep_iff_contains_circuit, not_not]\n\n\nlemma empty_not_cct (M : matroid \u03b1) : \n  \u00acM.is_circuit \u2205 := \nby {rw circuit_iff_r, intros h, have := h.1, linarith [rank_empty M, size_empty \u03b1]}\n\nlemma nested_circuits_equal (M : matroid \u03b1) : \n  C\u2081 \u2286 C\u2082 \u2192 M.is_circuit C\u2081 \u2192 M.is_circuit C\u2082 \u2192 C\u2081 = C\u2082 := \nbegin \n  intros hC\u2081C\u2082 hC\u2081 hC\u2082, \n  rw circuit_iff_r at hC\u2081 hC\u2082, \n  by_contra a, \n  linarith [hC\u2082.2 _ (ssubset_of_subset_ne hC\u2081C\u2082 a)],\nend \n\nlemma circuit_not_ssubset_circuit :\n  M.is_circuit C\u2081 \u2192 M.is_circuit C\u2082 \u2192 \u00ac(C\u2081 \u2282 C\u2082) :=\n  \u03bb hC\u2081 hC\u2082 hC\u2081C\u2082, ne_of_ssubset hC\u2081C\u2082 (nested_circuits_equal M hC\u2081C\u2082.1 hC\u2081 hC\u2082)\n\nlemma not_circuit_of_ssubset_circuit {X C : set \u03b1} (hXC : X \u2282 C) (hC : M.is_circuit C) :\n  \u00acM.is_circuit X := \nby_contra (\u03bb hX, by {rw not_not at hX, exact circuit_not_ssubset_circuit hX hC hXC, })\n\n\nlemma inter_circuits_ssubset :\n  M.is_circuit C\u2081 \u2192 M.is_circuit C\u2082 \u2192 C\u2081 \u2260 C\u2082 \u2192 C\u2081 \u2229 C\u2082 \u2282 C\u2081 := \nbegin\n  intros hC\u2081 hC\u2082 hC\u2081C\u2082, \n  refine ssubset_of_subset_ne (inter_subset_left _ _) (\u03bb h, _), \n  rw \u2190subset_iff_inter_eq_left at h, exact hC\u2081C\u2082 (nested_circuits_equal M h hC\u2081 hC\u2082 ),\nend\n\nlemma circuit_elim (hC\u2081C\u2082 : C\u2081 \u2260 C\u2082) (hC\u2081 : M.is_circuit C\u2081) (hC\u2082 : M.is_circuit C\u2082)\n(he : e \u2208 C\u2081 \u2229 C\u2082): \n   \u2203 C, M.is_circuit C \u2227 C \u2286 ((C\u2081 \u222a C\u2082) \\ {e}) := \nbegin\n  rw [\u2190dep_iff_contains_circuit, dep_iff_r], \n  have hI : C\u2081 \u2229 C\u2082 \u2282 C\u2081 := inter_circuits_ssubset hC\u2081 hC\u2082 hC\u2081C\u2082, \n  have he\u03b1 := mem_of_mem_of_subset he (inter_subset_union C\u2081 C\u2082),\n  have hcalc : M.r ((C\u2081 \u222a C\u2082) \\ {e}) \u2264 size ((C\u2081 \u222a C\u2082) \\ {e}) -1 := \n  by linarith [M.rank_mono (diff_subset (C\u2081 \u222a C\u2082) {e} ), M.rank_submod C\u2081 C\u2082, \n        r_cct hC\u2081, r_cct hC\u2082, r_cct_ssub hC\u2081 hI, size_modular C\u2081 C\u2082, size_remove_mem he\u03b1],\n  exact int.le_sub_one_iff.mp hcalc,\nend \n\ndef matroid_to_cct_family (M : matroid \u03b1) : cct_family \u03b1 := \n  \u27e8\u03bb X, M.is_circuit X, \n   empty_not_cct M, \n   \u03bb C\u2081 C\u2082, circuit_not_ssubset_circuit, \n   \u03bb C\u2081 C\u2082 h, circuit_elim \u27e9\n\nend circuit\n\nsection closure\n\n/-- is spanning in M: closure is univ -/\n@[simp] def is_spanning (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb X, M.r X = M.r univ \n\n/-- X spans Y if the rank of X is the rank of X \u222a Y -/\ndef spans (M : matroid \u03b1) : set \u03b1 \u2192 set \u03b1 \u2192 Prop := \n  \u03bb X Y, M.r (X \u222a Y) = M.r X \n\nlemma spanning_iff_r :\n  M.is_spanning X \u2194 M.r X = M.r univ := \nby refl \n\nlemma spans_iff_r  :\n  M.spans X Y \u2194 M.r (X \u222a Y) = M.r X :=\nby refl \n\nlemma not_spans_iff_r : \n  \u00acM.spans X Y \u2194 M.r X < M.r (X \u222a Y) :=\nby {rw [spans_iff_r, eq_comm], \n    exact \u27e8\u03bb h, lt_of_le_of_ne (rank_mono_union_left M _ _) h, \u03bb h, ne_of_lt h\u27e9}\n\nlemma spanned_union (M : matroid \u03b1){X Y Y' : set \u03b1} :\n  M.spans X Y \u2192 M.spans X Y' \u2192 M.spans X (Y \u222a Y') := \nbegin\n  unfold spans, intros h h', \n  linarith [submod_three_sets M X Y Y', M.rank_mono_union_left X (Y \u2229 Y'), \n    M.rank_mono_union_left X (Y \u222a Y')],\nend\n\nlemma spanned_union_closed (M : matroid \u03b1) (X : set \u03b1) :\n   union_closed (\u03bb Y, spans M X Y) :=\nbegin\n  refine \u27e8_, \u03bb Y Y' hY hY', spanned_union M hY hY'\u27e9, \n  have : M.r (X \u222a \u2205) = M.r X := by rw union_empty, assumption, \nend\n\nlemma spans_refl (M : matroid \u03b1) (X : set \u03b1) : \n  M.spans X X :=\nby {unfold spans, rw [union_self]} \n\nlemma spans_subset (M : matroid \u03b1) : \n  Y \u2286 Y' \u2192 M.spans X Y' \u2192 M.spans X Y :=\nbegin\n  unfold spans, intros hYY' hXY, \n  linarith [M.rank_mono_union_left X Y,  M.rank_mono (union_subset_union_right X hYY')], \nend\n\nlemma spans_rank_zero (X : set \u03b1){L : set \u03b1} (hL : M.r L = 0) :\n  M.spans X L := \nby rw [spans_iff_r, rank_eq_rank_union_rank_zero X hL] \n\n/-- closure of X in M : union of all sets spanned by X -/\ndef cl (M : matroid \u03b1) : set \u03b1 \u2192 set \u03b1 :=\n  \u03bb X, max_of_union_closed (spanned_union_closed M X)\n\n-- cl X is the (unique) maximal set that is spanned by X\nlemma cl_iff_max {X F : set \u03b1} : \n  M.cl X = F \u2194 M.spans X F \u2227 \u2200 Y, F \u2282 Y \u2192 \u00acM.spans X Y :=\nlet huc := spanned_union_closed M X, \n   h_eq := (union_closed_max_iff_in_and_ub huc F) in \nby {dsimp at h_eq, unfold is_maximal at h_eq, rw [h_eq], \n      unfold cl, rw [eq_comm, \u2190is_max_of_union_closed_iff huc]}\n  \n-- cl X is also the set spanned by X that contains all sets spanned by X\nlemma cl_iff_spanned_ub {X F : set \u03b1} :\n   M.cl X = F \u2194 M.spans X F \u2227 \u2200 Y, M.spans X Y \u2192 Y \u2286 F := \nby {unfold cl, rw [eq_comm, is_max_of_union_closed_iff], refl}\n\nlemma cl_iff_spanned_ub_r {X F : set \u03b1} :\n   M.cl X = F \u2194 M.r (X \u222a F) = M.r X \u2227 \u2200 Y, (M.r (X \u222a Y) = M.r X) \u2192 Y \u2286 F := \nby {unfold cl, rw [eq_comm, is_max_of_union_closed_iff], refl}\n\nlemma cl_is_max :\n  M.spans X (M.cl X) \u2227 \u2200 Y, (M.cl X) \u2282 Y \u2192 \u00acM.spans X Y :=\ncl_iff_max.mp rfl\n\nlemma cl_is_ub :\n  \u2200 Y, M.spans X Y \u2192 Y \u2286 (M.cl X) := \n(cl_iff_spanned_ub.mp rfl).2 \n\nlemma subset_cl (M : matroid \u03b1) (X : set \u03b1) : \n  X \u2286 M.cl X := \n(cl_iff_spanned_ub.mp rfl).2 _ (spans_refl M X)\n\nlemma mem_cl_of_mem (he : e \u2208 X): \n  e \u2208 M.cl X := \nmem_of_mem_of_subset he (M.subset_cl X)\n\nlemma mem_cl_single (M : matroid \u03b1) (e : \u03b1) : \n  e \u2208 M.cl {e} :=\nmem_cl_of_mem (mem_singleton e) \n\nlemma spans_cl (M : matroid \u03b1) (X : set \u03b1) :\n  M.spans X (M.cl X) := \n(cl_iff_max.mp rfl).1 \n\nlemma supset_cl (X : set \u03b1) :\n  \u2200 Y, (M.cl X \u2282 Y) \u2192 \u00acM.spans X Y := \n(cl_iff_max.mp rfl).2\n\nlemma spanned_subset_cl : \n  M.spans X Y \u2192 Y \u2286 M.cl X := \n\u03bb h, cl_is_ub Y h \n\nlemma rank_zero_subset_cl (X : set \u03b1){L : set \u03b1} (hL : M.r L = 0) :\n  L \u2286 M.cl X := \nspanned_subset_cl (spans_rank_zero X hL)\n\nlemma subset_cl_iff (X Y: set \u03b1) :\n  Y \u2286 M.cl X \u2194 M.spans X Y := \n\u27e8\u03bb h, spans_subset M h (spans_cl _ _ ), \u03bb h, spanned_subset_cl h\u27e9 \n\nlemma subset_cl_iff_r (X Y : set \u03b1) :\n  Y \u2286 M.cl X \u2194 M.r (X \u222a Y) = M.r X :=\nby {rw subset_cl_iff, refl}\n\nlemma spanning_iff_cl_univ (X : set \u03b1) :\n  M.is_spanning X \u2194 M.cl X = univ :=\nbegin\n  rw cl_iff_spanned_ub, unfold spans is_spanning, refine \u27e8\u03bb h, \u27e8_,\u03bb Y hY, _\u27e9, \u03bb h, _\u27e9, \n  rw [h, union_univ], apply subset_univ, rw [\u2190h.1, union_univ], \nend   \n  \nlemma cl_univ (M : matroid \u03b1) :\n  M.cl univ = univ := \nby {rw \u2190spanning_iff_cl_univ, obviously}\n\n@[simp] lemma rank_cl (M : matroid \u03b1) (X : set \u03b1) : \n  M.r (cl M X) = M.r X := \nbegin\n  have : M.r (X \u222a M.cl X) = M.r X := M.spans_cl X,\n  linarith [M.rank_mono_union_right X (M.cl X), M.rank_mono (M.subset_cl X)], \nend \n\nlemma union_cl_rank_left (M : matroid \u03b1) (X Y : set \u03b1) :\n  M.r ((M.cl X) \u222a Y) = M.r (X \u222a Y) := \nby {rw eq_comm, exact rank_eq_of_union_eq_rank_subset _ (subset_cl _ _) (rank_cl _ _).symm}\n  \nlemma union_cl_rank_right (M : matroid \u03b1) (X Y : set \u03b1) :\n  M.r (X \u222a (M.cl Y)) = M.r (X \u222a Y) :=\nby {rw [union_comm, union_comm _ Y], apply union_cl_rank_left} \n\nlemma cl_idem (M : matroid \u03b1) (X : set \u03b1) :\n  cl M (cl M X) = cl M X := \nbegin\n  rw cl_iff_spanned_ub, refine \u27e8by apply spans_refl, \u03bb Y hY, _\u27e9,  \n  rw subset_cl_iff, unfold spans, unfold spans at hY, \n  apply rank_eq_of_le_union, \n  linarith [M.rank_cl X, M.union_cl_rank_left X Y], \nend\n\nlemma spans_iff_cl_spans :\n  M.spans X Y \u2194 M.spans (M.cl X) Y :=\nbegin   \n  repeat {rw spans_iff_r}, \n  rw [rank_eq_of_union_eq_rank_subset, rank_cl],  \n  apply subset_cl, exact (rank_cl _ _).symm,  \nend\n\nlemma cl_monotone (M : matroid \u03b1) :\n  X \u2286 Y \u2192 M.cl X \u2286 M.cl Y :=\n\u03bb h, by {rw subset_cl_iff_r, apply rank_eq_of_le_union, \n          rw [union_cl_rank_right, union_comm, subset_iff_union_eq_left.mp h]}\n  \nlemma nonmem_cl_iff_r :\n  e \u2209 M.cl X \u2194 M.r (X \u222a {e}) = M.r X + 1 :=\nbegin\n  rw [\u2190singleton_subset_iff, subset_cl_iff_r], refine \u27e8\u03bb h, _, \u03bb _, \u03bb _, by linarith\u27e9, \n  linarith [rank_augment_single_ub M X e, \n  int.add_one_le_iff.mpr ((ne.symm h).le_iff_lt.mp (rank_mono_union_left M X {e}))],\nend\n\nlemma mem_cl_iff_r : \n  e \u2208 M.cl X \u2194 M.r (X \u222a {e}) = M.r X := \nby rw [\u2190singleton_subset_iff, subset_cl_iff_r]\n\nlemma mem_cl_iff_spans :\n  e \u2208 M.cl X \u2194 M.spans X {e} :=\nby rw [spans_iff_r,mem_cl_iff_r]\n\nlemma nonmem_cl_iff_nonspans :\n  e \u2209 M.cl X \u2194 \u00acM.spans X {e} :=\n\u27e8\u03bb h, \u03bb hn, h (mem_cl_iff_spans.mpr hn), \u03bb h, \u03bb hn, h (mem_cl_iff_spans.mp hn)\u27e9\n\nlemma rank_removal_iff_closure (X : set \u03b1) (e : \u03b1) (h : e \u2208 X) :\n  M.r (X \\ {e}) = M.r X \u2194 e \u2208 M.cl (X \\ {e}) :=\nby rw [mem_cl_iff_r, remove_union_mem_singleton h, eq_comm]\n  \n\nlemma cl4 (M : matroid \u03b1) (X : set \u03b1) (e f : \u03b1) : \n  e \u2208 M.cl (X \u222a {f}) \\ M.cl X  \u2192 f \u2208 M.cl (X \u222a {e}) \\ M.cl X := \nbegin \n  repeat {rw [mem_diff_iff, nonmem_cl_iff_r, mem_cl_iff_r]}, \n  rw union_right_comm, refine \u03bb h, \u27e8_,_\u27e9, \n  apply rank_eq_of_le_union, linarith [rank_augment_single_ub M X f],  \n  cases h with h1 h2, \n  linarith [h2, rank_augment_single_ub M X f, rank_mono_union_left M (X \u222a {e}) {f}],  \nend\n\n\nend closure \n\n\nsection /-Flats-/ flat\n\n/-- set for which all proper supersets have larger rank -/\ndef is_flat (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb F, \u2200 (X : set \u03b1), F \u2282 X \u2192 M.r F < M.r X\n\n/-- subtype of flats of M -/\ndef flat (M : matroid \u03b1) := { F : set \u03b1 // M.is_flat F }  \n\ninstance coe_flat : has_coe (M.flat) (set \u03b1) := \n  coe_subtype   \n  \ninstance fintype_flat : fintype (flat M) := \nby {unfold flat, apply_instance }\n\n\n/-- flat of rank k -/\ndef is_rank_k_flat (M : matroid \u03b1) (k : \u2124) : set \u03b1 \u2192 Prop := \n  \u03bb F, M.is_flat F \u2227 M.r F = k \n\n/-- the unique rank zero flat -/\ndef loops : matroid \u03b1 \u2192 set \u03b1 := \n  \u03bb M, M.cl \u2205 \n\nlemma loops_def :\n  M.loops = M.cl \u2205 := \nrfl \n\n/-- is a rank -one flat -/\ndef is_point (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb F, M.is_rank_k_flat 1 F\n\n/-- is a rank-two flat -/\ndef is_line (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb F, M.is_rank_k_flat 2 F\n\n/-- is a rank-three flat -/\ndef is_plane (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb F, M.is_rank_k_flat 3 F\n\n/-- flat of rank r M - 1 -/\ndef is_hyperplane (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb H, M.is_rank_k_flat (M.r univ - 1) H \n\n\n\nlemma is_point.r (h : M.is_point P): M.r P = 1 := h.2 \nlemma is_point.flat (h : M.is_point P) : M.is_flat P := h.1 \n\nlemma is_line.r (h : M.is_line X) : M.r X = 2 := h.2 \nlemma is_line.flat (h : M.is_line P) : M.is_flat P := h.1 \n\nlemma is_plane.r (h : M.is_plane X) : M.r X = 3 := h.2\nlemma is_plane.flat (h : M.is_plane P) : M.is_flat P := h.1 \n\ndef point (M : matroid \u03b1)  := {P : set \u03b1 // M.is_point P}\ninstance point_fin : fintype M.point := by {unfold point, apply_instance}\ninstance point_coe : has_coe M.point (set \u03b1) := \u27e8subtype.val\u27e9 \nlemma point.r (P : M.point): M.r P = 1 := P.2.r \nlemma point.flat (P : M.point) : M.is_flat P := P.2.flat \n\ndef line (M : matroid \u03b1) := {L : set \u03b1 // M.is_line L}\ninstance line_fin : fintype M.line := by {unfold line, apply_instance}\ninstance line_coe : has_coe M.line (set \u03b1) := \u27e8subtype.val\u27e9 \nlemma line.r (P : M.line): M.r P = 2 := P.2.r \nlemma line.flat (P : M.line) : M.is_flat P := P.2.flat \n\ndef plane (M : matroid \u03b1) := {L : set \u03b1 // M.is_plane L}\ninstance plane_fin : fintype M.plane := by {unfold plane, apply_instance}\ninstance plane_coe : has_coe M.plane (set \u03b1) := \u27e8subtype.val\u27e9 \nlemma plane.r (P : M.plane): M.r P = 3 := P.2.r \nlemma plane.flat (P : M.plane) : M.is_flat P := P.2.flat \n\nlemma rank_loops (M: matroid \u03b1) : \n  M.r (M.loops) = 0 := \nby rw [loops, rank_cl, rank_empty]\n\nlemma rank_zero_iff_subset_loops :\n  M.r X = 0 \u2194 X \u2286 M.loops :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, rank_eq_zero_of_le_zero _ \u27e9,  \n  rw [loops, subset_cl_iff_r], \n  simp, from h, \n  convert M.rank_mono h, \n  from eq.symm (rank_loops M), \nend\n\nlemma spans_loops (M : matroid \u03b1) (X : set \u03b1) :\n  M.spans X M.loops := \nspans_rank_zero X (rank_loops M)\n\nlemma loops_subset_cl (M : matroid \u03b1) (X : set \u03b1) :\n  M.loops \u2286 M.cl X := \nrank_zero_subset_cl X (rank_loops M)\n\nlemma rank_zero_iff_cl_eq_loops :\n  M.r X = 0 \u2194 M.cl X = M.loops := \nbegin\n  rw rank_zero_iff_subset_loops, \n  refine \u27e8\u03bb h, subset.antisymm _ (M.loops_subset_cl _), \u03bb h, _\u27e9, \n  { rw [loops_def] at *, rw [\u2190 M.cl_idem \u2205], exact M.cl_monotone h,  }, \n  rw \u2190h, \n  exact subset_cl M X, \nend\n\nlemma flat_iff_r  (X : set \u03b1) :\n  M.is_flat X \u2194 \u2200 Y, X \u2282 Y \u2192 M.r X < M.r Y := \nby refl \n\nlemma cl_is_flat (M : matroid \u03b1) (X : set \u03b1) : \n  M.is_flat (cl M X) := \nbegin\n  rw flat_iff_r, intros Y hY, have hne := cl_is_max.2 _ hY, \n  rw [spans_iff_cl_spans, spans_iff_r] at hne, \n  rw \u2190subset_iff_union_eq_left.mp hY.1, \n  from lt_of_le_of_ne (M.rank_mono_union_left (cl M X) Y) (ne.symm hne), \nend\n\nlemma flat_iff_own_cl :\n  M.is_flat F \u2194 M.cl F = F :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, by {have := cl_is_flat M F, rw h at this, exact this}\u27e9,\n  rw [cl_iff_max, spans_iff_r], simp_rw not_spans_iff_r,  \n  from \u27e8by rw union_self, \u03bb Y hFY, lt_of_lt_of_le (h Y hFY) (by {rw union_comm, apply rank_mono_union_left})\u27e9,\nend \n\nlemma loops_subset_flat (M : matroid \u03b1) (hF : M.is_flat F) :\n  M.loops \u2286 F := \nby {rw \u2190flat_iff_own_cl.mp hF, apply loops_subset_cl}\n\n\nlemma flat_iff_is_cl : \n  M.is_flat  F \u2194 \u2203 X : set \u03b1, cl M X = F := \n\u27e8\u03bb h, \u27e8F, flat_iff_own_cl.mp h\u27e9, \u03bb h, \n    by {cases h with X hX, rw flat_iff_own_cl, rw \u2190hX, apply cl_idem}\u27e9\n\n\nlemma subset_flat (X F : set \u03b1) :\n  X \u2286 F \u2192 M.is_flat F \u2192 M.cl X \u2286 F :=\nbegin\n  rw flat_iff_own_cl, \n  intros hXF hF, \n  rw \u2190hF, apply cl_monotone _ hXF, \nend\n\nlemma flat_iff_add_r :\n  M.is_flat F \u2194 \u2200 e, e \u2209 F \u2192 M.r F < M.r (F \u222a {e}) :=\nbegin\n  rw flat_iff_r, \n  refine \u27e8\u03bb h, \u03bb e he, h _ (ssub_of_add_nonmem he), \u03bb h, \u03bb Y hY, _\u27e9,\n  cases add_from_nonempty_diff.mp hY with e he, \n  exact lt_of_lt_of_le (h e he.1) (M.rank_mono he.2), \nend\n\nlemma flat_iff_add :\n  M.is_flat F \u2194 \u2200 (e : \u03b1), e \u2209 F \u2192 \u00acM.spans F {e} := \nby {rw [flat_iff_add_r], simp_rw not_spans_iff_r}\n\nlemma univ_is_flat (M : matroid \u03b1) : \n  M.is_flat univ := \nby {rw [flat_iff_own_cl, cl_univ]}\n\nlemma fullrank_flat_is_univ :\n  M.is_flat F \u2192 M.r F = M.r univ \u2192 F = univ := \nbegin\n  intros hF hFr, \n  rw [flat_iff_own_cl] at hF, \n  rw [\u2190hF, \u2190spanning_iff_cl_univ], \n  from hFr, \nend\n\nlemma flats_eq_of_nested_ge_rank \n(hF\u2081 : M.is_flat F\u2081) (hF\u2082 : M.is_flat F\u2082) (hF\u2081F\u2082 : F\u2081 \u2286 F\u2082) (hr : M.r F\u2082 \u2264 M.r F\u2081) :\n  F\u2081 = F\u2082 :=\nbegin\n  suffices h' : F\u2082 \u2286 F\u2081, exact subset.antisymm hF\u2081F\u2082 h', \n  by_contra hn, \n  rw [subset_def] at hn, \n  push_neg at hn, \n  obtain \u27e8x, h\u2082, h\u2081\u27e9 := hn, \n  linarith [\n    flat_iff_add_r.mp hF\u2081 _ h\u2081, \n    M.rank_mono (union_subset hF\u2081F\u2082 (singleton_subset_iff.mpr h\u2082))], \nend\n\n\n\nlemma hyperplane_iff_r  (X : set \u03b1) :\n  M.is_hyperplane X \u2194 M.r X = M.r univ - 1 \u2227 \u2200 Y, X \u2282 Y \u2192 M.r Y = M.r univ := \nbegin\n  unfold is_hyperplane is_rank_k_flat, rw flat_iff_r, \n  refine \u27e8\u03bb h, \u27e8h.2, \u03bb Y hXY, _ \u27e9, \u03bb h, \u27e8\u03bb Y hXY, _, h.1\u27e9 \u27e9,\n  have := h.1 Y hXY, rw h.2 at this, linarith [rank_le_univ M Y],  \n  rw [h.1,h.2 Y hXY], exact sub_one_lt _,   \nend\n\nlemma hyperplane_iff_maximal_nonspanning  (X : set \u03b1) : \n  M.is_hyperplane X \u2194 \u00acM.is_spanning X \u2227 \u2200 (Y: set \u03b1), X \u2282 Y \u2192 M.is_spanning Y :=\nbegin\n  rw hyperplane_iff_r, split, \n  intro h, simp only [is_spanning], split, linarith [h.2],\n  intros Y hXY, linarith [h.2 Y hXY, h.2, rank_le_univ M Y],\n  simp only [is_spanning], \n  refine \u03bb h, \u27e8_,h.2\u27e9, cases h with h1 h2,  \n  rcases ne_univ_has_add_one_size_ssupset (\u03bb h', by {rw h' at h1, from h1 rfl} : X \u2260 univ) with \u27e8Y,hY\u2081, hY\u2082\u27e9,\n  linarith [rank_diff_le_size_diff M hY\u2081.1, h2 _ hY\u2081, \n            int.le_sub_one_of_le_of_ne (rank_le_univ M X) h1],   \nend \n\nlemma hyperplane_iff_maximal_subflat  (H : set \u03b1) :\n  M.is_hyperplane H \u2194 H \u2260 univ \u2227 M.is_flat H \u2227 (\u2200 X, M.is_flat X \u2192 H \u2282 X \u2192 X = univ) := \nbegin\n  refine \u27e8\u03bb h, \u27e8\u03bb hH, _,\u27e8h.1, \u03bb X hX hHX, _\u27e9\u27e9, \u03bb h, \u27e8h.2.1,_\u27e9\u27e9,  \n  rw [hH, hyperplane_iff_r] at h, linarith, \n  cases h with hHf hHr, \n  rw flat_iff_r at hHf, \n  rw [\u2190(flat_iff_own_cl.mp hX), \u2190spanning_iff_cl_univ, is_spanning], \n  linarith [hHf _ hHX, rank_le_univ M X],   \n  \n  rcases h with \u27e8h_univ, h_flat, hmax\u27e9, \n  by_cases h1 : M.r H \u2264 M.r univ - 2, \n  rcases ne_univ_has_add_one_size_ssupset_element h_univ with \u27e8e, he\u2081, he\u2082\u27e9,\n  have := hmax (cl M (H \u222a {e})) (cl_is_flat _ _) (subset.lt_of_lt_of_le he\u2081 _),\n  rw [\u2190spanning_iff_cl_univ, spanning_iff_r] at this,  \n  linarith [rank_augment_single_ub M H e],\n  apply subset_cl, \n  push_neg at h1, \n\n  by_cases h2: (M.r H < M.r univ), \n  from le_antisymm (int.le_sub_one_of_lt h2) (by linarith only [h1]), \n\n  have : M.r H = M.r univ := by linarith [rank_le_univ M H],\n  from false.elim (h_univ (fullrank_flat_is_univ h_flat this)), \nend\n\nlemma cocircuit_iff_compl_hyperplane  (X : set \u03b1) : \n  M.is_cocircuit X \u2194 M.is_hyperplane X\u1d9c := \nbegin\n  rw [cocircuit_iff_r, hyperplane_iff_r], \n  refine \u27e8\u03bb h, \u27e8h.1,\u03bb Y hXY, _\u27e9 , \u03bb h, \u27e8h.1,\u03bb Y hXY, h.2 _ (compl_ssubset_compl_iff.mpr hXY)\u27e9\u27e9, \n  rw [\u2190(h.2 _ (compl_ssubset_comm.mp hXY)), compl_compl], \nend\n\nlemma inter_flats_is_flat (M : matroid \u03b1) (F\u2081 F\u2082 : set \u03b1) :\n  M.is_flat F\u2081 \u2192 M.is_flat F\u2082 \u2192 M.is_flat (F\u2081 \u2229 F\u2082) := \nbegin \n  repeat {rw [flat_iff_add]}, simp_rw \u2190nonmem_cl_iff_nonspans, \n  intros h\u2081 h\u2082 e he, rw nonmem_inter_iff at he, cases he, \n  exact \u03bb h, (h\u2081 e he) (mem_of_mem_of_subset h (cl_monotone M (inter_subset_left F\u2081 F\u2082))), \n  exact \u03bb h, (h\u2082 e he) (mem_of_mem_of_subset h (cl_monotone M (inter_subset_right F\u2081 F\u2082))), \nend\n\nlemma rank_inter_eq_rank_flats_lt\n(hF\u2081 : M.is_flat F\u2081) (hF\u2082 : M.is_flat F\u2082) (hr : M.r F\u2081 = M.r F\u2082) (hF\u2081F\u2082 : F\u2081 \u2260 F\u2082):\n  M.r (F\u2081 \u2229 F\u2082) < M.r F\u2081 := \nbegin\n  by_contra hn, apply hF\u2081F\u2082, \n  push_neg at hn, \n  replace hn := rank_eq_of_le_supset (inter_subset_left _ _) hn, \n  apply subset.antisymm, \n  { rw subset_iff_inter_eq_left, \n    exact flats_eq_of_nested_ge_rank (M.inter_flats_is_flat _ _ hF\u2081 hF\u2082) hF\u2081 \n      (inter_subset_left _ _) (by rw hn)},\n  rw hr at hn, rw subset_iff_inter_eq_right, \n  apply flats_eq_of_nested_ge_rank (M.inter_flats_is_flat _ _ hF\u2081 hF\u2082) hF\u2082\n    (inter_subset_right _ _) (by rw hn),  \nend\n\nlemma rank_inter_lines_le_one (hL\u2081 : M.is_line L\u2081) (hL\u2082 : M.is_line L\u2082) (h : L\u2081 \u2260 L\u2082): \n  M.r (L\u2081 \u2229 L\u2082) \u2264 1 := \nbegin\n  apply int.le_of_lt_add_one, \n  convert rank_inter_eq_rank_flats_lt hL\u2081.flat hL\u2082.flat (by {rw [hL\u2081.r, hL\u2082.r]}) h, \n  rw hL\u2081.r, norm_num,  \nend\n\n/-- is both a circuit and a hyperplane -/\ndef is_circuit_hyperplane (M : matroid \u03b1) (C : set \u03b1) := \n  M.is_circuit C \u2227 M.is_hyperplane C \n\nlemma circuit_hyperplane_rank (hC : is_circuit_hyperplane M C) :\n  M.r C = M.r univ - 1 := \nby {simp_rw [is_circuit_hyperplane, hyperplane_iff_r] at hC, from hC.2.1}\n\nlemma circuit_hyperplane_size (hC : is_circuit_hyperplane M C) :\n  size C = M.r univ := \nby {have := circuit_hyperplane_rank hC, simp_rw [is_circuit_hyperplane, circuit_iff_r] at hC, linarith [hC.1.1]}\n\nlemma circuit_hyperplane_rank_size (hC : is_circuit_hyperplane M C) :\n  M.r C = size C - 1 := \nby linarith [circuit_hyperplane_size hC, circuit_hyperplane_rank hC]\n\nlemma circuit_hyperplane_ssubset_rank {C X : set \u03b1} (hC : is_circuit_hyperplane M C) :\n  X \u2282 C \u2192 M.r X = size X := \n\u03bb hXC, by {simp_rw [is_circuit_hyperplane, circuit_iff_r] at hC, from hC.1.2 _ hXC,}\n\nlemma circuit_hyperplane_ssupset_rank {C X : set \u03b1} (hC : is_circuit_hyperplane M C) :\n  C \u2282 X \u2192 M.r X = M.r univ := \n\u03bb hXC, by {simp_rw [is_circuit_hyperplane, hyperplane_iff_r] at hC, from hC.2.2 _ hXC,}\n\nlemma circuit_hyperplane_dual :\n  M.is_circuit_hyperplane C \u2194 (dual M).is_circuit_hyperplane C\u1d9c := \nbegin\n  simp_rw [is_circuit_hyperplane, \u2190cocircuit_iff_compl_hyperplane, is_cocircuit],  \n  rw [dual_dual, \u2190is_cocircuit, cocircuit_iff_compl_hyperplane, compl_compl, and_comm], \nend\n\n\n--lemma closure_eq_iff_flat  {X F : set \u03b1} : \n--  cl M X = F \u2194 X \u2286 F \u2227 is_flat M F \u2227 \u2200 F', is_flat \n\nend flat\n\nsection loopnonloop\n/-- is a rank-zero element -/\ndef is_loop (M : matroid \u03b1) : \u03b1 \u2192 Prop := \n  \u03bb e, M.r {e} = 0 \n\n/-- is a rank-one element -/\ndef is_nonloop (M : matroid \u03b1) : \u03b1 \u2192 Prop := \n  \u03bb e, M.r {e} = 1 \n\n/-- is a loop of the dual -/\ndef is_coloop (M : matroid \u03b1) : \u03b1 \u2192 Prop := \n  is_loop (dual M) \n\n/-- is not a coloop of the dual -/\ndef is_noncoloop (M : matroid \u03b1) : \u03b1 \u2192 Prop := \n  is_coloop (dual M)\n\ndef nonloops (M : matroid \u03b1) : set \u03b1 := \n  { e : \u03b1 | M.is_nonloop e }\n\nlemma nonloop_iff_r :\n  M.is_nonloop e \u2194 M.r {e} = 1 := \niff.rfl \n\nlemma nonloop_iff_mem_nonloops : \n  M.is_nonloop e \u2194 e \u2208 M.nonloops := \niff.rfl \n\nlemma loop_iff_r :\n  M.is_loop e \u2194 M.r {e} = 0 := \niff.rfl \n\nlemma nonloop_iff_one_le_rank :\n  M.is_nonloop e \u2194 1 \u2264 M.r {e} := \nby {rw nonloop_iff_r, split; {intro, linarith [rank_single_ub M e]}}\n\nlemma loop_iff_circuit :\n  M.is_loop e \u2194 M.is_circuit {e} :=\nby simp [loop_iff_r, circuit_iff_r, size_singleton, ssubset_singleton_iff_empty] \n\nlemma nonloop_iff_indep :\n  M.is_nonloop e \u2194 M.is_indep {e} := \nby rw [is_nonloop, indep_iff_r, size_singleton] \n\nlemma rank_nonloop :\n  M.is_nonloop e \u2192 M.r {(e : \u03b1)} = 1 :=\nby {unfold is_nonloop, from \u03bb h, h}\n\nlemma is_nonloop.r (h : M.is_nonloop e) : M.r {e} = 1 := \nh \n\n\n\nlemma rank_loop :\n  M.is_loop e \u2192 M.r {e} = 0 :=\nby {unfold is_loop, from \u03bb h, h}\n\nlemma cl_loop_eq_loops (he : M.is_loop e) :\n  M.cl {e} = M.loops := \nrank_zero_iff_cl_eq_loops.mp (rank_loop he)\n\nlemma loop_of_mem_rank_zero (he : e \u2208 X) (hX : M.r X = 0) :\n  M.is_loop e :=\nby {rw loop_iff_r, apply rank_zero_of_subset_rank_zero (singleton_subset_iff.mpr he) hX,  } \n\nlemma loop_iff_mem_loops  : \n  M.is_loop e \u2194 e \u2208 M.loops := \nby {simp_rw [is_loop, \u2190singleton_subset_iff], from rank_zero_iff_subset_loops}  \n\nlemma nonloop_iff_not_mem_loops : \n  M.is_nonloop e \u2194 e \u2209 M.loops := \nbegin\n  simp_rw [is_nonloop, \u2190singleton_subset_iff, \u2190rank_zero_iff_subset_loops], \n  refine \u27e8\u03bb h h', by linarith, \u03bb h, _\u27e9, \n  linarith [rank_single_ub M e, rank_gt_zero_of_ne h], \nend\n\nlemma nonloop_iff_not_loop  : \n  M.is_nonloop e \u2194 \u00ac M.is_loop e := \nbegin \n  unfold is_loop is_nonloop, refine \u27e8\u03bb h, _ ,\u03bb h, _\u27e9,rw h ,\n  simp only [not_false_iff, one_ne_zero], \n  have := M.rank_le_size {e}, rw size_singleton at this,       \n  linarith [(ne.le_iff_lt (ne.symm h)).mp (M.rank_nonneg {e})],  \nend\n\nlemma nonloops_eq_compl_loops (M : matroid \u03b1 ): \n  M.nonloops = M.loops\u1d9c := \nby {ext, rw [\u2190 nonloop_iff_mem_nonloops, nonloop_iff_not_mem_loops ],  refl}\n\nlemma loop_iff_not_nonloop  : \n  M.is_loop e \u2194 \u00ac M.is_nonloop e := \nby simp [nonloop_iff_not_loop]\n\nlemma loop_or_nonloop (M : matroid \u03b1) (e : \u03b1) :\n  M.is_loop e \u2228 M.is_nonloop e :=\nby {rw [loop_iff_not_nonloop], tauto}\n\nlemma rank_eq_rank_insert_loop (X : set \u03b1) (he : M.is_loop e) :\n  M.r (X \u222a {e}) = M.r X := \nrank_eq_rank_union_rank_zero _ (loop_iff_r.mp he)\n\nlemma rank_eq_rank_remove_loop (X : set \u03b1) (he : M.is_loop e) :\n  M.r (X \\ {e}) = M.r X := \nrank_eq_rank_diff_rank_zero _ (loop_iff_r.mp he)\n\n@[simp] lemma rank_eq_rank_diff_loops (X : set \u03b1) :\n  M.r (X \\ M.loops) = M.r X := \nrank_eq_rank_diff_rank_zero _ (M.rank_loops)\n\nlemma nonloop_of_one_le_rank (h : 1 \u2264 M.r {e}) : \n  M.is_nonloop e :=\nby {rw [nonloop_iff_r, eq_comm], exact le_antisymm h (by {convert M.rank_le_size _, simp, })} \n\nlemma nonloop_of_rank_lt_insert (h : M.r X < M.r (X \u222a {e})) :\n  M.is_nonloop e :=\nby_contra (\u03bb hn,\n  by {rw rank_eq_rank_insert_loop _ (loop_iff_not_nonloop.mpr hn) at h, exact lt_irrefl _ h,})\n\nlemma coloop_iff_r  (e : \u03b1) :\n  M.is_coloop e \u2194 M.r {e}\u1d9c = M.r univ - 1 := \nbegin\n  unfold is_coloop is_loop, rw [dual_r,size_singleton],\n  exact \u27e8\u03bbh, by linarith,\u03bb h, by linarith\u27e9,   \nend\n\nlemma coloop_iff_r_less  (e : \u03b1) :\n  M.is_coloop e \u2194 M.r {e}\u1d9c < M.r univ := \nbegin\n  unfold is_coloop is_loop, rw [dual_r,size_singleton],\n  refine \u27e8\u03bbh,by linarith,\u03bb h,_\u27e9, \n  have := rank_diff_le_size_diff M (subset_univ {e}\u1d9c), \n  rw [\u2190size_compl, size_singleton] at this, \n  linarith [int.le_sub_one_iff.mpr h],\nend\n\nlemma point_eq_cl_mem \n(hP : M.is_point P) (he : M.is_nonloop e) (heP : e \u2208 P) :\n  M.cl {e} = P := \nbegin\n  apply flats_eq_of_nested_ge_rank (M.cl_is_flat {e}) hP.1,\n  { rw \u2190 singleton_subset_iff at heP, \n    rw \u2190 flat_iff_own_cl.mp hP.1,  \n    apply M.cl_monotone heP,},  \n  rw [hP.2, rank_cl, rank_nonloop he], \nend\n  \n\n/-- nonloop as subtype -/\ndef nonloop (M : matroid \u03b1) := { e : \u03b1 // is_nonloop M e}\n\ninstance coe_nonloop : has_coe (nonloop M) (\u03b1) := \u27e8\u03bb e, e.val\u27e9  \n--def noncoloop (M : matroid \u03b1) : Type := { e : \u03b1 // is_nonloop (dual M) e}\n\ninstance fin_nonloop : fintype M.nonloop := \nby {unfold nonloop, apply_instance}\n\nlemma eq_nonloop_coe (h : M.is_nonloop e) : \n  e = coe (\u27e8e, h\u27e9 : M.nonloop) := \nrfl \n\nlemma rank_coe_nonloop (e : nonloop M) : \n  M.r {(e : \u03b1)} = 1 := \nrank_nonloop (e.2)\n\nlemma coe_nonloop_indep (e : nonloop M) :\n  M.is_indep {(e : \u03b1)} := \nby {rw [indep_iff_r], simp only [size_singleton, coe_coe], apply rank_coe_nonloop e,}\n\nlemma rank_two_nonloops_lb  (e f : nonloop M) :\n  1 \u2264 M.r ({e,f}) := \nbegin\n  rw \u2190union_singletons_eq_pair, \n  linarith [rank_coe_nonloop e, M.rank_mono_union_left {e} {f}],\nend \n\nlemma rank_two_nonloops_ub  (e f : nonloop M) : \n  M.r ({e,f}) \u2264 2 := \nbegin\n  rw \u2190union_singletons_eq_pair, \n  linarith [rank_coe_nonloop e, rank_coe_nonloop f, \n    M.rank_nonneg ({e} \u2229 {f}), M.rank_submod {e} {f}], \nend \n\n/-- a version of rank_augment where the conclusion asserts that z is a nonloop -/\ntheorem rank_augment_nonloop (h : M.r X < M.r Z) :\n  \u2203 (z \u2208 Z), M.is_nonloop z \u2227 M.r X < M.r (X \u222a {z}) := \nbegin\n  obtain \u27e8z, hz, hr\u27e9 := rank_augment h, \n  refine \u27e8z,hz, nonloop_iff_not_loop.mpr (\u03bb hz', _), hr\u27e9, \n  rw rank_eq_rank_insert_loop _ hz' at hr, \n  exact lt_irrefl _ hr, \nend\n\n\nlemma contains_nonloop_of_one_le_rank (h : 1 \u2264 M.r X): \n  \u2203 e \u2208 X, M.is_nonloop e :=\nbegin\n  obtain \u27e8z, hz, hz', -\u27e9 := rank_augment_nonloop (by {rw rank_empty, linarith} : M.r \u2205 < M.r X), \n  exact \u27e8z,hz,hz'\u27e9, \nend\n\n\nend loopnonloop\n\nsection /-Bases-/ basis\n\n\n/-- B is a basis of X : an independent subset of X spanning X -/\ndef is_basis_of (M : matroid \u03b1) (B X : set \u03b1) : Prop := \n  B \u2286 X \u2227 M.r B = size B \u2227 M.r B = M.r X \n\n/-- B is a basis of M: an independent set spanning M -/\ndef is_basis (M : matroid \u03b1) (B : set \u03b1) : Prop := \n  M.is_basis_of B univ \n\n/-- basis type -/\ndef basis (M : matroid \u03b1) := {B : set \u03b1 // M.is_basis B}\n\ninstance coe_subtype_basis : has_coe (M.basis) (set \u03b1) :=\n  coe_subtype\n\ninstance finite_basis : fintype (M.basis) := \nby {unfold basis, apply_instance }\n\n/-- basis of set X type -/\ndef basis_of (M : matroid \u03b1) (X : set \u03b1) := {B : set \u03b1 // M.is_basis_of B X}\n\ninstance coe_subtype_basis_of (X : set \u03b1) : has_coe (M.basis_of X) (set \u03b1) :=\n  coe_subtype\n\ninstance fintype_basis_of (X : set \u03b1) : fintype (M.basis_of X) := \nby {unfold basis_of, apply_instance }\n\n\nlemma is_basis_of.size_eq_r (h : M.is_basis_of B X) : \n  size B = M.r X := \nby rw [\u2190 h.2.2, \u2190 h.2.1]\n\nlemma is_basis_of.indep (h : M.is_basis_of B X): \n  M.is_indep B := \nby rw [indep_iff_r, h.2.1] \n\nlemma is_basis_of.size_eq_r_self (h : M.is_basis_of B X) : \n  size B = M.r B := \nby rw [h.size_eq_r, h.2.2]\n\nlemma is_basis_of.is_subset_of (h : M.is_basis_of B X): \n  B \u2286 X := \nh.1 \n\nlemma size_basis :\n  M.is_basis B \u2192 size B = M.r univ := \nis_basis_of.size_eq_r \n\n\n\nlemma bases_of_equicardinal (M : matroid \u03b1){B\u2081 B\u2082 X: set \u03b1} :\n  M.is_basis_of B\u2081 X \u2192 M.is_basis_of B\u2082 X \u2192 size B\u2081 = size B\u2082 := \n\u03bb h\u2081 h\u2082, by rw[is_basis_of.size_eq_r h\u2081, is_basis_of.size_eq_r h\u2082]\n\nlemma bases_equicardinal (M : matroid \u03b1){B\u2081 B\u2082 : set \u03b1} :\n  M.is_basis B\u2081 \u2192 M.is_basis B\u2082 \u2192 size B\u2081 = size B\u2082 := \nbases_of_equicardinal M \n\nlemma basis_iff_r  :\n  M.is_basis B \u2194 M.r B = size B \u2227 M.r B = M.r univ :=\n\u27e8\u03bb h, h.2, \u03bb h, \u27e8subset_univ B,h\u27e9\u27e9\n\n/-- is a basis of the dual -/\ndef is_cobasis (M : matroid \u03b1) : set \u03b1 \u2192 Prop := \n  \u03bb B, (dual M).is_basis B \n\ndef cobasis (M : matroid \u03b1) := {B : set \u03b1 // M.is_cobasis B}\n\n@[simp] lemma cobasis_iff  :\n  M.is_cobasis B \u2194 (dual M).is_basis B :=\nby rw is_cobasis\n\n@[simp] lemma basis_of_iff_augment : \n  M.is_basis_of B X \u2194 B \u2286 X \u2227 M.r B = size B \u2227 \u2200 (e:\u03b1), e \u2208 X \u2192 M.r (B \u222a {e}) = M.r B := \nbegin\n  refine \u27e8\u03bb h, \u27e8h.1,\u27e8h.2.1,\u03bb e he, _\u27e9\u27e9, \u03bb h, \u27e8h.1,\u27e8h.2.1,_\u27e9\u27e9\u27e9, \n  { linarith [h.2.2, \n      M.rank_mono (union_subset h.1 (singleton_subset_iff.mpr he)), \n      M.rank_mono (subset_union_left B {e})]}, \n  refine rank_eq_of_not_lt_supset h.1 (\u03bb hBX, _), \n  cases rank_augment hBX with e he, \n  linarith [h.2.2 e he.1, he.2],   \nend\n\nlemma basis_iff_augment :\n  M.is_basis B \u2194 M.r B = size B \u2227 \u2200 (e:\u03b1), M.r (B \u222a {e}) = M.r B := \nbegin\n  unfold is_basis, rw basis_of_iff_augment, \n  refine \u27e8\u03bb h, \u27e8h.2.1,\u03bb e, h.2.2 e (mem_univ e)\u27e9, \u03bb h, \u27e8subset_univ B, \u27e8h.1,\u03bb e he,h.2 e\u27e9\u27e9 \u27e9, \nend\n\nlemma basis_of_iff_augment_i : \n  M.is_basis_of B X \u2194 B \u2286 X \u2227 M.is_indep B \u2227 \u2200 (e:\u03b1), e \u2208 X \\ B \u2192 \u00acM.is_indep (B \u222a {e}) :=\nbegin\n  rw basis_of_iff_augment, \n  refine \u27e8\u03bb h, \u27e8h.1,\u27e8h.2.1,\u03bb e he hi, _\u27e9\u27e9, \u03bb h, \u27e8h.1,\u27e8h.2.1,\u03bb e he, _\u27e9 \u27e9\u27e9, \n  rw indep_iff_r at hi, \n  rw mem_diff_iff at he, \n  linarith [h.2.2 e he.1, size_union_nonmem_singleton he.2], \n  by_cases heB: e \u2208 B, \n  rw (union_mem_singleton heB), \n  have : e \u2208 X \\ B := by {rw mem_diff_iff, from \u27e8he,heB\u27e9},\n  have := h.2.2 _ this, \n  rw not_indep_iff_r at this, \n  have hi := h.2.1, rw indep_iff_r at hi, \n  linarith [size_union_nonmem_singleton heB, M.rank_mono (subset_union_left B {e})], \nend \n\nlemma basis_iff_augment_i : \n  is_basis M B \u2194 M.is_indep B \u2227 \u2200 (e:\u03b1), e \u2209 B \u2192 \u00acM.is_indep (B \u222a {e}) := \nbegin\n  simp_rw [is_basis, basis_of_iff_augment_i, \u2190mem_compl_iff, univ_diff], \n  from \u27e8\u03bb h, \u27e8h.2.1,\u03bb e he, h.2.2 _ he\u27e9, \u03bb h, \u27e8subset_univ B, h\u27e9\u27e9, \nend\n\nlemma basis_of_iff_indep_full_rank {B X : set \u03b1} :\n  M.is_basis_of B X \u2194 B \u2286 X \u2227 M.is_indep B \u2227 size B = M.r X := \nbegin\n  simp_rw [is_basis_of, indep_iff_r], \n  refine \u27e8\u03bb h, \u27e8h.1, \u27e8_,_\u27e9\u27e9, \u03bb h, \u27e8h.1,\u27e8_,_\u27e9\u27e9\u27e9; \n  linarith, \nend\n\nlemma basis_iff_indep_full_rank :\n  M.is_basis B \u2194 M.is_indep B \u2227 size B = M.r univ :=\nbegin\n  simp_rw [basis_iff_r, indep_iff_r], \n  refine \u27e8\u03bb h, \u27e8h.1, _\u27e9, \u03bb h, \u27e8h.1,_\u27e9\u27e9;\n  linarith, \nend\n\nlemma basis_is_indep : \n  M.is_basis B \u2192 M.is_indep B := \n  \u03bb h, (basis_iff_indep_full_rank.mp h).1 \n\nlemma cobasis_iff_r :\n  M.is_cobasis B \u2194 M.r B\u1d9c = size B\u1d9c \u2227 M.r B\u1d9c = M.r univ := \nbegin\n  simp_rw [is_cobasis, basis_iff_r, dual],\n  refine \u27e8\u03bb _, \u27e8_,_\u27e9, \u03bb _, \u27e8_,_\u27e9\u27e9;\n  linarith [size_compl B, rank_compl_univ M], \nend\n\nlemma cobasis_iff_compl_basis :\n  M.is_cobasis B \u2194 M.is_basis B\u1d9c := \nby rw [cobasis_iff_r, basis_iff_r] \n\nlemma compl_cobasis_iff_basis :\n  M.is_cobasis B\u1d9c \u2194 M.is_basis B := \nby rw [cobasis_iff, \u2190cobasis_iff_compl_basis, cobasis_iff, dual_dual]\n\nlemma basis_exchange (M : matroid \u03b1){B\u2081 B\u2082 : set \u03b1} (hB\u2081 : M.is_basis B\u2081)\n(hB\u2082 : M.is_basis B\u2082) (he : e \u2208 B\u2081 \\ B\u2082) :\n  \u2203 (f : \u03b1), f \u2208 (B\u2082 \\ B\u2081) \u2227 M.is_basis (B\u2081 \\ {e} \u222a {f}) :=\nbegin\n  rw basis_iff_indep_full_rank at hB\u2081 hB\u2082, \n  simp_rw basis_iff_indep_full_rank,   \n  cases mem_diff_iff.mp he with he\u2081 he\u2082, \n  have h' : M.is_indep (B\u2081 \\ {e}) := subset_indep (diff_subset _ _) hB\u2081.1, \n  rcases indep_aug_diff (by { rw size_remove_mem he\u2081, linarith, }) h' hB\u2082.1 \n    with \u27e8f,\u27e8hf, hf_aug\u27e9\u27e9, \n  have h'' : B\u2082 \\ (B\u2081 \\ {e}) = B\u2082 \\ B\u2081, \n  { repeat {rw diff_eq}, \n    rw [compl_inter, compl_compl, inter_distrib_left, \n    inter_comm _ {e}, nonmem_disjoint_iff.mp he\u2082, union_empty]},\n  rw h'' at hf, \n  cases mem_diff_iff.mp hf with hf\u2081 hf\u2082, \n  refine \u27e8f, hf, hf_aug, _\u27e9, \n  rw size_remove_union_singleton he\u2081 hf\u2082, exact hB\u2081.2, \nend  \n\nlemma extends_to_basis_of :\n  I \u2286 X \u2192 M.is_indep I \u2192 \u2203 B, I \u2286 B \u2227 M.is_basis_of B X := \nlet P := \u03bb J, I \u2286 J \u2227 M.is_indep J \u2227 J \u2286 X in \nbegin\n  intros hIX hIi, \n  rcases maximal_example_aug P \u27e8subset_refl I,\u27e8hIi,hIX\u27e9\u27e9 with \u27e8B, \u27e8_, \u27e8hPB,hBmax\u27e9\u27e9\u27e9 , \n  simp_rw basis_of_iff_augment_i, \n  refine \u27e8B, \u27e8hPB.1,\u27e8hPB.2.2,\u27e8hPB.2.1,\u03bb e he hecon,_\u27e9\u27e9 \u27e9\u27e9, \n  rw mem_diff_iff at he, \n  have := hBmax _ he.2, \n  push_neg at this, \n  from this (subset.trans h_left (subset_union_left _ _)) hecon (union_subset hPB.2.2 (singleton_subset_iff.mpr he.1)), \nend \n\nlemma exists_basis_of (M : matroid \u03b1) (X : set \u03b1) : \n  \u2203 B, M.is_basis_of B X := \nby {cases extends_to_basis_of (empty_subset X) (empty_indep M) with B hB, from \u27e8B,hB.2\u27e9}\n\nlemma exists_basis (M : matroid \u03b1) : \n  \u2203 B, M.is_basis B := \nby apply exists_basis_of \n\nlemma extends_to_basis :\n  M.is_indep I \u2192 \u2203 B, I \u2286 B \u2227 M.is_basis B := \n  \u03bb h, extends_to_basis_of (subset_univ I) h \n\nlemma flat_eq_cl_basis {B F : set \u03b1} (hF : M.is_flat F) (hBF : M.is_basis_of B F) :\n  F = M.cl B :=\nbegin\n  apply subset.antisymm, \n  rw [subset_cl_iff_r, subset_iff_union_eq_left.mp hBF.1, hBF.2.2], \n  rw [\u2190flat_iff_own_cl.mp hF], \n  apply M.cl_monotone hBF.1,  \nend\n\nlemma flat_iff_cl_indep :\n  M.is_flat F \u2194 \u2203 I, M.is_indep I \u2227 F = M.cl I := \nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n    rcases M.exists_basis_of F with \u27e8I,hI\u27e9,\n    simp_rw [indep_iff_r, flat_eq_cl_basis h hI], \n    refine \u27e8I, by rw hI.2.1, rfl\u27e9, \n  rcases h with \u27e8I,-,rfl\u27e9, \n  apply cl_is_flat, \nend\n\nlemma rank_k_flat_iff_cl_indep {k : \u2124} :\n  M.is_rank_k_flat k F \u2194 \u2203 I, M.is_indep I \u2227 size I = k \u2227 F = M.cl I := \nbegin\n  simp_rw [is_rank_k_flat, flat_iff_cl_indep], \n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rcases h with \u27e8\u27e8I,hI,rfl\u27e9,hF\u27e9, \n    refine \u27e8I, hI, _, rfl\u27e9, \n    rw [\u2190hF, rank_cl, \u2190(indep_iff_r.mp hI)],},\n  rcases h with \u27e8I, hI, hk, rfl\u27e9, \n  refine \u27e8\u27e8I, hI, rfl\u27e9,_\u27e9, \n  rw [rank_cl, (indep_iff_r.mp hI), hk],\nend\n\nlemma point_iff_cl_nonloop :\n  M.is_point P \u2194 \u2203 e, M.is_nonloop e \u2227 P = M.cl {e} := \nbegin\n  simp_rw [is_point, rank_k_flat_iff_cl_indep, size_one_iff_eq_singleton],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rcases h with \u27e8I,hs,\u27e8e,rfl\u27e9,rfl\u27e9,\n    exact \u27e8e, by {rwa nonloop_iff_indep}, rfl\u27e9, },\n  rcases h with \u27e8e,he,rfl\u27e9, \n  exact \u27e8{e}, by {rwa \u2190nonloop_iff_indep}, \u27e8e,rfl\u27e9, rfl\u27e9, \nend\n\nlemma point_of_cl_nonloop (he : M.is_nonloop e):\n  M.is_point (M.cl {e}) := \npoint_iff_cl_nonloop.mpr \u27e8e,he,rfl\u27e9\n\nlemma indep_iff_contained_in_basis :\n  M.is_indep X \u2194 \u2203 B, X \u2286 B \u2227 M.is_basis B := \nbegin\n  refine \u27e8\u03bb h, extends_to_basis h,  \u03bb h, _\u27e9, \n  cases h with B hB, \n  from indep_of_subset_indep hB.1 (basis_is_indep hB.2),  \nend\n\nlemma mem_cl_iff_i :\n  e \u2208 M.cl X \n  \u2194 \u2203 I \u2286 X, M.is_indep I \u2227 \u2200 J \u2286 X \u222a {e}, is_indep M J \u2192 size J \u2264 size I :=\nbegin\n  rw mem_cl_iff_r, \n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9, \n  rcases M.exists_basis_of X with \u27e8I, \u27e8hI\u2081, hI\u2082, hI\u2083\u27e9\u27e9, \n  refine \u27e8_, hI\u2081, hI\u2082, \u03bb J hJx hJ, _\u27e9, \n  rw [\u2190hI\u2082, hI\u2083, \u2190h, \u2190indep_iff_r.mp hJ], exact M.rank_mono hJx,\n  rw eq_comm, \n  refine rank_eq_of_le_supset (subset_union_left _ _) _,\n  rcases M.exists_basis_of (X \u222a {e}) with \u27e8J, \u27e8hJ\u2081, hJ\u2082, hJ\u2083\u27e9\u27e9, \n  rcases h with \u27e8I,hI,\u27e8hIind,hIX\u27e9\u27e9,\n  specialize hIX J hJ\u2081 hJ\u2082,   \n  rw [\u2190hJ\u2083,hJ\u2082], rw \u2190(r_indep hIind) at hIX,  \n  from le_trans hIX (M.rank_mono hI), \nend\n\nlemma rank_eq_iff_exists_basis_of (M : matroid \u03b1) (X : set \u03b1){n : \u2124} :\n  M.r X = n \u2194 \u2203 B, M.is_basis_of B X \u2227 size B = n := \nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9, \n  subst h, cases exists_basis_of M X with B hB,\n  exact \u27e8B, hB, is_basis_of.size_eq_r hB\u27e9, \n  rcases h with \u27e8B,\u27e8\u27e8h\u2081,h\u2082\u27e9,h\u2083\u27e9\u27e9, \n  rw [\u2190h\u2082.2, h\u2082.1], exact h\u2083, \nend\n\nlemma rank_as_indep (M : matroid \u03b1) (X : set \u03b1) :\n  M.r X = max_val (\u03bb I: indep_subset_of M X, size I.val) := \nbegin\n  rcases max_spec (\u03bb I: indep_subset_of M X, size I.val) with \u27e8\u27e8B,h,h'\u27e9, h\u2081, h\u2082\u27e9, \n  dsimp only at *, rw [\u2190h\u2081], clear h\u2081, \n  rw [\u2190indep_iff_r.mp h'], \n  apply le_antisymm _ (M.rank_mono h), \n  by_contra hcon, push_neg at hcon, \n  rcases rank_augment hcon with \u27e8z, hz, hB\u27e9, \n  specialize h\u2082 \u27e8B \u222a {z}, _\u27e9, swap, dsimp at h\u2082, \n    have : B \u2282 (B \u222a {z}), from \n      ssubset_of_subset_ne (subset_union_left _ _) (\u03bb h, by {rw \u2190h at hB, linarith,}), \n    linarith [size_strict_monotone this], \n  exact \u27e8union_singleton_subset_of_subset_mem h hz, indep_of_indep_aug h' hB\u27e9,\nend\n\nlemma r_univ_eq_max_size_indep (M : matroid \u03b1) :\n  M.r univ = max_val (\u03bb I : M.indep, size I.val) :=\nbegin\n  rw rank_as_indep, \n  set \u03c6 : M.indep_subset_of univ \u2192 M.indep := \u03bb X, \u27e8X.val, X.property.2\u27e9 with h\u03c6, \n  have : function.surjective \u03c6, \n    from \u03bb X, by {use \u27e8X.val, \u27e8subset_univ X.val, X.property\u27e9\u27e9, rw h\u03c6, simp,}, \n  rw [max_reindex \u03c6 this (\u03bb X, size X.val)], \n  refl, \nend\n\nlemma not_indep_iff_exists_removal : \n  \u00acM.is_indep X \u2194 \u2203 (e : \u03b1), e \u2208 X \u2227 M.r (X \\ {e}) = M.r X := \nbegin\n  rw not_indep_iff_r, rcases exists_basis_of M X with \u27e8B, \u27e8h,h',h''\u27e9\u27e9, \n  refine \u27e8\u03bb h1, _, \u03bb h1,_\u27e9, \n  { rw [\u2190h'', h'] at h1,\n    rcases mem_diff_of_size_lt h1 with \u27e8e,he1,he2\u27e9, \n    refine \u27e8e,he1,_\u27e9, \n    apply rank_eq_of_le_supset, intro x, simp, tauto,  \n    rw [\u2190h'',diff_eq], \n    apply M.rank_mono (subset_inter h _),  tidy, },\n  rcases h1 with \u27e8e, heX, he\u27e9, \n  rw \u2190he, refine lt_of_le_of_lt (M.rank_le_size _) _, \n  rw size_remove_mem heX, linarith,  \nend\n\nend basis \n\nsection ext \n\nvariables {M\u2081 M\u2082 : matroid \u03b1}\n\nlemma rank_ext :\n  M\u2081.r = M\u2082.r \u2192 M\u2081 = M\u2082 := \n\u03bb h, by {ext, rw h}\n\nlemma indep_ext :\n  M\u2081.is_indep = M\u2082.is_indep \u2192 M\u2081 = M\u2082 := \nbegin\n  intro h, ext X,\n  cases exists_basis_of M\u2081 X with B hB, \n  rw \u2190is_basis_of.size_eq_r hB, \n  rw basis_of_iff_augment_i at hB, \n  simp_rw h at hB, \n  rw \u2190basis_of_iff_augment_i at hB, \n  rw \u2190is_basis_of.size_eq_r hB, \nend\n\nlemma circuit_ext : \n  M\u2081.is_circuit = M\u2082.is_circuit \u2192 M\u2081 = M\u2082 :=\nbegin\n  intro h, apply indep_ext, ext X,\n  simp_rw [indep_iff_contains_no_circuit, h], \nend\n\nlemma cocircuit_ext :\n  M\u2081.is_cocircuit = M\u2082.is_cocircuit \u2192 M\u2081 = M\u2082 := \n  \u03bb h, dual_inj (circuit_ext h)\n\nlemma hyperplane_ext :\n  M\u2081.is_hyperplane = M\u2082.is_hyperplane \u2192 M\u2081 = M\u2082 := \nbegin\n  intro h, apply cocircuit_ext, ext X,\n  simp_rw [cocircuit_iff_compl_hyperplane, h], \nend\n\nlemma flat_ext : \n  M\u2081.is_flat = M\u2082.is_flat \u2192 M\u2081 = M\u2082 := \nbegin\n  intro h, apply hyperplane_ext, ext X, \n  simp_rw [hyperplane_iff_maximal_subflat, h], \nend\n\nlemma basis_ext : \n  M\u2081.is_basis = M\u2082.is_basis \u2192 M\u2081 = M\u2082 := \nbegin\n  intro h, apply indep_ext, ext X, \n  simp_rw [indep_iff_contained_in_basis, h], \nend\n\nlemma circuit_ind_of_distinct (hM\u2081M\u2082 : M\u2081 \u2260 M\u2082) :\n  \u2203 X, (M\u2081.is_circuit X \u2227 M\u2082.is_indep X) \u2228 (M\u2082.is_circuit X \u2227 M\u2081.is_indep X) := \nbegin\n  by_contra h, push_neg at h, \n  refine hM\u2081M\u2082 (indep_ext _), ext Y,\n  simp_rw [indep_iff_contains_no_circuit, not_iff_not],\n  refine \u27e8\u03bb h\u2081, _, \u03bb h\u2082, _\u27e9, \n  rcases h\u2081 with \u27e8C, \u27e8hC, hCY\u27e9\u27e9, \n  have := (h C).1 hC, \n  simp_rw [\u2190dep_iff_not_indep, dep_iff_contains_circuit] at this, \n  rcases this with \u27e8C\u2082, \u27e8hC\u2082, hC\u2082C\u27e9\u27e9, \n  from \u27e8C\u2082, \u27e8hC\u2082, subset.trans hC\u2082C hCY\u27e9\u27e9, \n  rcases h\u2082 with \u27e8C, \u27e8hC, hCY\u27e9\u27e9, \n  have := (h C).2 hC, \n  simp_rw [\u2190dep_iff_not_indep, dep_iff_contains_circuit] at this, \n  rcases this with \u27e8C\u2082, \u27e8hC\u2082, hC\u2082C\u27e9\u27e9, \n  from \u27e8C\u2082, \u27e8hC\u2082, subset.trans hC\u2082C hCY\u27e9\u27e9, \nend\n\nend ext\n\nend matroid \n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_basic/rankfun.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.73201124450814}}
{"text": "-- Estudante: Lucas Emanuel Resck Domingues\n\nimport data.set\n\n-- Exercise 1\n\nsection\n    open function int algebra\n\n    def f (x : \u2124) : \u2124 := x + 3\n    def g (x : \u2124) : \u2124 := -x\n    def h (x : \u2124) : \u2124 := 2 * x + 3\n\n    example : injective f :=\n        assume x1 x2,\n            assume h1 : x1 + 3 = x2 + 3,   -- Lean knows this is the same as f x1 = f x2\n                show x1 = x2, from eq_of_add_eq_add_right h1\n\n    example : surjective f :=\n        assume y,\n            have h1 : f (y - 3) = y, from calc\n                f (y - 3) = (y - 3) + 3 : rfl\n                    ... = y           : by rw sub_add_cancel,\n        show \u2203 x, f x = y, from exists.intro (y - 3) h1\n\n    example (x y : \u2124) (h : 2 * x = 2 * y) : x = y :=\n            have h1 : 2 \u2260 (0 : \u2124), from dec_trivial,  -- this tells Lean to figure it out itself\n        show x = y, from eq_of_mul_eq_mul_left h1 h\n\n    example (x : \u2124) : -(-x) = x := neg_neg x\n\n    example (A B : Type) (u : A \u2192 B) (v : B \u2192 A) (h : left_inverse u v) :\n        \u2200 x, u (v x) = x :=\n            h\n\n    example (A B : Type) (u : A \u2192 B) (v : B \u2192 A) (h : left_inverse u v) :\n        right_inverse v u :=\n            h\n\n    -- fill in the sorry's in the following proofs\n\n    example : injective h :=\n        begin\n            intros a b h1,\n            have h2, from eq_of_add_eq_add_right h1,\n            have h3 : 2 \u2260 (0 : \u2124), from dec_trivial,\n            have h4, from eq_of_mul_eq_mul_left h3 h2,\n            assumption\n        end\n\n    example : surjective g :=\n        show \u2200 y, \u2203 x, g x = y, from\n            assume y,\n                have h1 : g (-y) = y, from\n                    calc\n                        g (-y) = -(-y) : rfl\n                        ... = y     : neg_neg y,\n            show \u2203 x, g x = y, from exists.intro (-y) h1\n\n    example (A B : Type) (u : A \u2192 B) (v1 : B \u2192 A) (v2 : B \u2192 A)\n    (h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=\n        funext\n            (assume x,\n                calc\n                    v1 x = v1 (u (v2 x)) : by rw h2\n                 ... = v2 x              : by rw h1)\nend\n\n-- Exercise 2\n\nsection\n    open function set\n\n    variables {X Y : Type}\n    variable  f : X \u2192 Y\n    variables A B : set X\n\n    example : f '' (A \u222a B) = f '' A \u222a f '' B :=\n    eq_of_subset_of_subset\n    (assume y,\n        assume h1 : y \u2208 f '' (A \u222a B),\n        exists.elim h1 $\n        assume x h,\n        have h2 : x \u2208 A \u222a B, from h.left,\n        have h3 : f x = y, from h.right,\n        or.elim h2\n        (assume h4 : x \u2208 A,\n            have h5 : y \u2208 f '' A, from \u27e8x, h4, h3\u27e9,\n            show y \u2208 f '' A \u222a f '' B, from or.inl h5)\n        (assume h4 : x \u2208 B,\n            have h5 : y \u2208 f ''  B, from \u27e8x, h4, h3\u27e9,\n            show y \u2208 f '' A \u222a f '' B, from or.inr h5))\n    (assume y,\n        assume h2 : y \u2208 f '' A \u222a f '' B,\n        or.elim h2\n        (assume h3 : y \u2208 f '' A,\n            exists.elim h3 $\n            assume x h,\n            have h4 : x \u2208 A, from h.left,\n            have h5 : f x = y, from h.right,\n            have h6 : x \u2208 A \u222a B, from or.inl h4,\n            show y \u2208 f '' (A \u222a B), from \u27e8x, h6, h5\u27e9)\n        (assume h3 : y \u2208 f '' B,\n            exists.elim h3 $\n            assume x h,\n            have h4 : x \u2208 B, from h.left,\n            have h5 : f x = y, from h.right,\n            have h6 : x \u2208 A \u222a B, from or.inr h4,\n            show y \u2208 f '' (A \u222a B), from \u27e8x, h6, h5\u27e9))\n\n    -- remember, x \u2208 A \u2229 B is the same as x \u2208 A \u2227 x \u2208 B\n    example (x : X) (h1 : x \u2208 A) (h2 : x \u2208 B) : x \u2208 A \u2229 B :=\n    and.intro h1 h2\n\n    example (x : X) (h1 : x \u2208 A \u2229 B) : x \u2208 A :=\n    and.left h1\n\n    -- Fill in the proof below.\n    -- (It should take about 8 lines.)\n\n    example : f '' (A \u2229 B) \u2286 f '' A \u2229 f '' B :=\n        assume y,\n            assume h1 : y \u2208 f '' (A \u2229 B),\n            show y \u2208 f '' A \u2229 f '' B, from\n                begin\n                    cases h1 with x h2,\n                    cases h2 with h3 h4,\n                    cases h3 with h5 h6,\n                    apply and.intro,\n                    have h7, from exists.intro x (and.intro h5 h4),\n                    exact h7,\n                    have h7, from exists.intro x (and.intro h6 h4),\n                    exact h7        \n                end\n\n    example : f '' (A \u2229 B) \u2286 f '' A \u2229 f '' B :=\n        assume y,\n            assume h1 : y \u2208 f '' (A \u2229 B),\n            have h3 : \u2203 x, x \u2208 A \u2227 f x = y, from exists.elim h1\n                (assume x (h5 : x \u2208 A \u2229 B \u2227 f x = y),\n                exists.intro x (and.intro h5.left.left h5.right)),\n            have h4 : \u2203 x, x \u2208 B \u2227 f x = y, from exists.elim h1\n                (assume x (h5 : x \u2208 A \u2229 B \u2227 f x = y),\n                exists.intro x (and.intro h5.left.right h5.right)),\n            show y \u2208 f '' A \u2229 f '' B, from and.intro h3 h4\nend", "meta": {"author": "lucasresck", "repo": "Discrete-Mathematics", "sha": "0a08081c5f393e5765259d3f1253c3a6dd043dac", "save_path": "github-repos/lean/lucasresck-Discrete-Mathematics", "path": "github-repos/lean/lucasresck-Discrete-Mathematics/Discrete-Mathematics-0a08081c5f393e5765259d3f1253c3a6dd043dac/Lists of exercises/List 7/cap16-LucasDomingues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7320112443793433}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport ring_theory.roots_of_unity\nimport analysis.special_functions.trigonometric\nimport analysis.special_functions.pow\n\n/-!\n# Complex roots of unity\n\nIn this file we show that the `n`-th complex roots of unity\nare exactly the complex numbers `e ^ (2 * real.pi * complex.I * (i / n))` for `i \u2208 finset.range n`.\n\n## Main declarations\n\n* `complex.mem_roots_of_unity`: the complex `n`-th roots of unity are exactly the\n  complex numbers of the form `e ^ (2 * real.pi * complex.I * (i / n))` for some `i < n`.\n* `complex.card_roots_of_unity`: the number of `n`-th roots of unity is exactly `n`.\n\n-/\n\nnamespace complex\n\nopen polynomial real\nopen_locale nat real\n\nlemma is_primitive_root_exp_of_coprime (i n : \u2115) (h0 : n \u2260 0) (hi : i.coprime n) :\n  is_primitive_root (exp (2 * \u03c0 * I * (i / n))) n :=\nbegin\n  rw is_primitive_root.iff_def,\n  simp only [\u2190 exp_nat_mul, exp_eq_one_iff],\n  have hn0 : (n : \u2102) \u2260 0, by exact_mod_cast h0,\n  split,\n  { use i,\n    field_simp [hn0, mul_comm (i : \u2102), mul_comm (n : \u2102)] },\n  { simp only [hn0, mul_right_comm _ _ \u2191n, mul_left_inj' two_pi_I_ne_zero, ne.def, not_false_iff,\n      mul_comm _ (i : \u2102), \u2190 mul_assoc _ (i : \u2102), exists_imp_distrib] with field_simps,\n    norm_cast,\n    rintro l k hk,\n    have : n \u2223 i * l,\n    { rw [\u2190 int.coe_nat_dvd, hk], apply dvd_mul_left },\n    exact hi.symm.dvd_of_dvd_mul_left this }\nend\n\nlemma is_primitive_root_exp (n : \u2115) (h0 : n \u2260 0) : is_primitive_root (exp (2 * \u03c0 * I / n)) n :=\nby simpa only [nat.cast_one, one_div]\n  using is_primitive_root_exp_of_coprime 1 n h0 n.coprime_one_left\n\nlemma is_primitive_root_iff (\u03b6 : \u2102) (n : \u2115) (hn : n \u2260 0) :\n  is_primitive_root \u03b6 n \u2194 (\u2203 (i < (n : \u2115)) (hi : i.coprime n), exp (2 * \u03c0 * I * (i / n)) = \u03b6) :=\nbegin\n  have hn0 : (n : \u2102) \u2260 0 := by exact_mod_cast hn,\n  split, swap,\n  { rintro \u27e8i, -, hi, rfl\u27e9, exact is_primitive_root_exp_of_coprime i n hn hi },\n  intro h,\n  obtain \u27e8i, hi, rfl\u27e9 :=\n    (is_primitive_root_exp n hn).eq_pow_of_pow_eq_one h.pow_eq_one (nat.pos_of_ne_zero hn),\n  refine \u27e8i, hi, ((is_primitive_root_exp n hn).pow_iff_coprime (nat.pos_of_ne_zero hn) i).mp h, _\u27e9,\n  rw [\u2190 exp_nat_mul],\n  congr' 1,\n  field_simp [hn0, mul_comm (i : \u2102)]\nend\n\n/-- The complex `n`-th roots of unity are exactly the\ncomplex numbers of the form `e ^ (2 * real.pi * complex.I * (i / n))` for some `i < n`. -/\nlemma mem_roots_of_unity (n : \u2115+) (x : units \u2102) :\n  x \u2208 roots_of_unity n \u2102 \u2194 (\u2203 i < (n : \u2115), exp (2 * \u03c0 * I * (i / n)) = x) :=\nbegin\n  rw [mem_roots_of_unity, units.ext_iff, units.coe_pow, units.coe_one],\n  have hn0 : (n : \u2102) \u2260 0 := by exact_mod_cast (n.ne_zero),\n  split,\n  { intro h,\n    obtain \u27e8i, hi, H\u27e9 : \u2203 i < (n : \u2115), exp (2 * \u03c0 * I / n) ^ i = x,\n    { simpa only using (is_primitive_root_exp n n.ne_zero).eq_pow_of_pow_eq_one h n.pos },\n    refine \u27e8i, hi, _\u27e9,\n    rw [\u2190 H, \u2190 exp_nat_mul],\n    congr' 1,\n    field_simp [hn0, mul_comm (i : \u2102)] },\n  { rintro \u27e8i, hi, H\u27e9,\n    rw [\u2190 H, \u2190 exp_nat_mul, exp_eq_one_iff],\n    use i,\n    field_simp [hn0, mul_comm ((n : \u2115) : \u2102), mul_comm (i : \u2102)] }\nend\n\nlemma card_roots_of_unity (n : \u2115+) : fintype.card (roots_of_unity n \u2102) = n :=\n(is_primitive_root_exp n n.ne_zero).card_roots_of_unity\n\nlemma card_primitive_roots (k : \u2115) (h : k \u2260 0) : (primitive_roots k \u2102).card = \u03c6 k :=\n(is_primitive_root_exp k h).card_primitive_roots (nat.pos_of_ne_zero h)\n\nend complex\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/complex/roots_of_unity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7319902434418752}}
{"text": "-- Ley_de_absorcion_2.lean\n-- Si R es un ret\u00edculo y x, y \u2208 R, entonces x \u2294 (x \u2293 y) = x\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 21-octubre-2022\n-- ---------------------------------------------------------------------\n\nimport order.lattice\nvariables {R : Type*} [lattice R]\nvariables x y : R\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\nbegin\n  have h1 : x \u2294 (x \u2293 y) \u2264 x, finish,\n  have h2 : x \u2264 x \u2294 (x \u2293 y), finish,\n  show x \u2294 (x \u2293 y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\nbegin\n  have h1 : x \u2294 (x \u2293 y) \u2264 x,\n  { have h1a : x \u2264 x := le_rfl,\n    have h1b : x \u2293 y \u2264 x := inf_le_left,\n    show x \u2294 (x \u2293 y) \u2264 x,\n      by exact sup_le h1a h1b,\n  },\n  have h2 : x \u2264 x \u2294 (x \u2293 y) := le_sup_left,\n  show x \u2294 (x \u2293 y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\nbegin\n  apply le_antisymm,\n  { apply sup_le,\n    { apply le_refl },\n    { apply inf_le_left }},\n  { apply le_sup_left },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\n-- by library_search\nsup_inf_self\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 (x \u2293 y) = x :=\n-- by hint\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Ley_de_absorcion_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7319902328369917}}
{"text": "import data.complex.basic data.real.cau_seq tactic.norm_num data.nat.basic tactic.ring algebra.archimedean .limits data.nat.choose\nsection a\nopen real nat is_absolute_value finset\nnoncomputable theory\nlocal attribute [instance, priority 0] classical.prop_decidable\n\nlemma pow_inv' {\u03b1 : Type*} [discrete_field \u03b1] (a : \u03b1) (n : \u2115) : (a ^ n)\u207b\u00b9 = a\u207b\u00b9 ^ n :=\nby induction n; simp [_root_.pow_succ, *, mul_inv', mul_comm]\n\nlemma pow_incrs_of_gt_one {\u03b1 : Type*}  [linear_ordered_semiring \u03b1] {x : \u03b1} {n m : \u2115} \n  (h1x : 1 < x) (hnm : n < m) : x ^ n < x ^ m := \nbegin\n  rw [\u2190 nat.sub_add_cancel hnm, _root_.pow_add, _root_.pow_succ, \u2190 mul_assoc],\n  refine (lt_mul_iff_one_lt_left (pow_pos (lt_trans (by norm_num) h1x) _)).2 _,\n  rw \u2190 one_mul (1 : \u03b1),\n  refine mul_lt_mul' (one_le_pow_of_one_le (le_of_lt h1x) _) h1x (by norm_num) \n    (pow_pos (lt_trans (by norm_num) h1x) _)  \nend\n\nlemma pow_dcrs_of_lt_one_of_pos {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1] {x : \u03b1} {n m : \u2115}\n  (hx1 : x < 1) (h0x : 0 < x) (hnm : n < m) : x ^ m < x ^ n :=\nbegin\n  refine (inv_lt_inv _ _).1 _, \n  { exact pow_pos h0x _ },\n  { exact pow_pos h0x _ },\n  { rw [pow_inv', pow_inv'],\n    refine pow_incrs_of_gt_one (one_lt_inv h0x hx1) hnm }\nend\n\nopen finset\n\n@[simp] lemma sum_range_zero {\u03b1 : Type*} [add_comm_monoid \u03b1] (f : \u2115 \u2192 \u03b1) : \n  (range 0).sum f = 0 := rfl\n\nlemma sum_range_succ {\u03b1 : Type*} [add_comm_monoid \u03b1] (f : \u2115 \u2192 \u03b1) (n : \u2115) :\n  (range (succ n)).sum f = f n + (range n).sum f := by simp\n\nlemma sum_range_succ' {\u03b1 : Type*} [add_comm_monoid \u03b1] (f : \u2115 \u2192 \u03b1) : \n  \u2200 n : \u2115, (range (nat.succ n)).sum f = (range n).sum (f \u2218 nat.succ) + f 0\n| 0       := by simp\n| (n + 1) := by rw [sum_range_succ (\u03bb m, f (nat.succ m)), add_assoc, \u2190 sum_range_succ'];\n  exact sum_range_succ _ _\n\n/-- The binomial theorem -/\ntheorem add_pow {\u03b1 : Type*} [comm_semiring \u03b1] (x y : \u03b1) : \u2200 n : \u2115,\n    (x + y) ^ n = (range (succ n)).sum (\u03bb m, x ^ m * y ^ (n - m) * choose n m)\n| 0        := by simp\n| (succ n) :=\nhave h\u2081 : x * (x ^ n * y ^ (n - n) * choose n n) =\n    x ^ succ n * y ^ (succ n - succ n) * choose (succ n) (succ n),\n  by simp [_root_.pow_succ, mul_assoc, mul_comm, mul_left_comm],\nhave  h\u2082 : y * (x^0 * y^(n - 0) * choose n 0) = x^0 * y^(succ n - 0) * choose (succ n) 0,\n  by simp [_root_.pow_succ, mul_assoc, mul_comm, mul_left_comm],\nhave h\u2083 : (range n).sum (\u03bb m, x * (x ^ m * y ^ (n - m) * choose n m) + y *\n    (x ^ succ m * y ^ (n - succ m) * choose n (succ m)))\n    = (range n).sum (\u03bb m, x ^ succ m * y ^ (succ n - succ m) * \u2191(choose (succ n) (succ m))),\n  from finset.sum_congr rfl $ \u03bb m hm,\n    begin\n      simp only [mul_assoc, mul_left_comm y, mul_left_comm (y ^ (n - succ m)), mul_comm y],\n      rw [\u2190 _root_.pow_succ', add_one, \u2190 succ_sub (mem_range.1 hm)],\n      simp [choose_succ_succ, mul_comm, mul_assoc, mul_left_comm, add_mul, mul_add, _root_.pow_succ]\n    end,\nby rw [_root_.pow_succ, add_pow, add_mul, finset.mul_sum, finset.mul_sum, sum_range_succ, sum_range_succ',\n    sum_range_succ, sum_range_succ', add_assoc, \u2190 add_assoc ((range n).sum _), \n    \u2190 finset.sum_add_distrib, h\u2081, h\u2082, h\u2083]\n\nlemma geo_series_eq {\u03b1 : Type*} [field \u03b1] {x : \u03b1} (n : \u2115) (hx1 : x \u2260 1) : \n  (range n).sum (\u03bb m, x ^ m) = (1 - x ^ n) / (1 - x) :=\nhave 1 - x \u2260 0 := mt sub_eq_zero_iff_eq.1 hx1.symm, \nbegin\n  induction n with n ih,\n  { simp },\n  { rw [sum_range_succ, \u2190 mul_div_cancel (x ^ n) this, ih, \u2190 add_div, _root_.pow_succ],\n    refine congr_fun (congr_arg _ _) _,\n    ring }\nend\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} \n  [discrete_linear_ordered_field \u03b1] [archimedean \u03b1] {abv : \u03b2 \u2192 \u03b1}\n\nlemma forall_ge_le_of_forall_le_succ {\u03b1 : Type*} [preorder \u03b1] (f : \u2115 \u2192 \u03b1) {m : \u2115}\n  (h : \u2200 n \u2265 m, f (succ n) \u2264 f n) : \u2200 l, \u2200 k \u2265 m, k \u2264 l \u2192 f l \u2264 f k :=\nbegin\n  assume l k hkm hkl,\n  generalize hp : l - k = p,\n  have : l = k + p := add_comm p k \u25b8 (nat.sub_eq_iff_eq_add hkl).1 hp,\n  subst this,\n  clear hkl hp,\n  induction p with p ih,\n  { simp },\n  { exact le_trans (h _ (le_trans hkm (nat.le_add_right _ _))) ih }\nend\n\nlemma is_cau_of_dcrs_bounded {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1] \n  [archimedean \u03b1] (f : \u2115 \u2192 \u03b1) \n  {a : \u03b1} {m : \u2115} (ham : \u2200 n \u2265 m, abs (f n) \u2264 a) \n  (hnm : \u2200 n \u2265 m, f (succ n) \u2264 f n) : is_cau_seq abs f := \n\u03bb \u03b5 \u03b50, \nlet \u27e8k, hk\u27e9 := archimedean.arch a \u03b50 in\nhave h : \u2203 l, \u2200 n \u2265 m, a - add_monoid.smul l \u03b5 < f n :=\n  \u27e8k + k + 1, \u03bb n hnm, lt_of_lt_of_le \n    (show a - add_monoid.smul (k + (k + 1)) \u03b5 < -abs (f n), \n      from lt_neg.1 $ lt_of_le_of_lt (ham n hnm) (begin\n        rw [neg_sub, lt_sub_iff_add_lt, add_monoid.add_smul],\n        exact add_lt_add_of_le_of_lt hk (lt_of_le_of_lt hk \n          (lt_add_of_pos_left _ \u03b50)),\n      end))\n    (neg_le.2 $ (abs_neg (f n)) \u25b8 le_abs_self _)\u27e9,\nlet l := nat.find h in\nhave hl : \u2200 (n : \u2115), n \u2265 m \u2192 f n > a - add_monoid.smul l \u03b5 := nat.find_spec h,\nhave hl0 : l \u2260 0 := \u03bb hl0, not_lt_of_ge (ham m (le_refl _))\n  (lt_of_lt_of_le (by have := hl m (le_refl m); simpa [hl0] using this) (le_abs_self (f m))),\nbegin\n  cases classical.not_forall.1\n    (nat.find_min h (pred_lt hl0)) with i hi,\n  rw [not_imp, not_lt] at hi,\n  existsi i,\n  assume j hj,\n  have hfij : f j \u2264 f i := forall_ge_le_of_forall_le_succ f hnm _ _ hi.1 hj,\n  rw [abs_of_nonpos (sub_nonpos.2 hfij), neg_sub, sub_lt_iff_lt_add'],\n  exact calc f i \u2264 a - add_monoid.smul (pred l) \u03b5 : hi.2\n    ... = a - add_monoid.smul l \u03b5 + \u03b5 : \n      by conv {to_rhs, rw [\u2190 succ_pred_eq_of_pos (nat.pos_of_ne_zero hl0), succ_smul',\n        sub_add, add_sub_cancel] }\n    ... < f j + \u03b5 : add_lt_add_right (hl j (le_trans hi.1 hj)) _\nend\n\nlemma is_cau_of_incrs_bounded {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1] \n  [archimedean \u03b1] (f : \u2115 \u2192 \u03b1) \n  {a : \u03b1} {m : \u2115} (ham : \u2200 n \u2265 m, abs (f n) \u2264 a) \n  (hnm : \u2200 n \u2265 m, f n \u2264 f (succ n)) : is_cau_seq abs f :=\nbegin\n  refine @eq.rec_on (\u2115 \u2192 \u03b1) _ (is_cau_seq abs) _ _\n    (-\u27e8_, @is_cau_of_dcrs_bounded _ _ _ (\u03bb n, -f n) a m (by simpa) (by simpa)\u27e9 : cau_seq \u03b1 abs).2,\n  ext,\n  exact neg_neg _\nend\n\nlemma series_cau_of_abv_le_cau {\u03b1 : Type*} {\u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2] {f : \u2115 \u2192 \u03b2}\n    {g : \u2115 \u2192 \u03b1} {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv] (n : \u2115) : (\u2200 m, n \u2264 m \u2192 abv (f m) \u2264 g m) \u2192 \n    is_cau_seq abs (\u03bb n, (range n).sum g) \u2192 is_cau_seq abv (\u03bb n, (range n).sum f) := begin\n  assume hm hg \u03b5 \u03b50,cases hg (\u03b5 / 2) (div_pos \u03b50 (by norm_num)) with i hi,\n  existsi max n i,\n  assume j ji,\n  have hi\u2081 := hi j (le_trans (le_max_right n i) ji),\n  have hi\u2082 := hi (max n i) (le_max_right n i),\n  have sub_le := abs_sub_le ((range j).sum g) ((range i).sum g) ((range (max n i)).sum g),\n  have := add_lt_add hi\u2081 hi\u2082,\n  rw abs_sub ((range (max n i)).sum g) at this,\n  rw add_halves \u03b5 at this,\n  refine lt_of_le_of_lt (le_trans (le_trans _ (le_abs_self _)) sub_le) this,\n  generalize hk : j - max n i = k,clear this hi\u2082 hi\u2081 hi \u03b50 \u03b5 hg sub_le,\n  rw nat.sub_eq_iff_eq_add ji at hk,rw hk, clear hk ji j,\n  induction k with k' hi,\n  { simp [abv_zero abv] },\n  { dsimp at *,\n    rw [succ_add, sum_range_succ, sum_range_succ, add_assoc, add_assoc],\n    refine le_trans (abv_add _ _ _) _,\n    exact add_le_add (hm _ (le_add_of_nonneg_of_le (nat.zero_le _) (le_max_left _ _))) hi },\nend\n\nlemma pow_abv {\u03b1 \u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [domain \u03b2] (abv : \u03b2 \u2192 \u03b1) [is_absolute_value abv]\n  (a : \u03b2) (n : \u2115) : abv (a ^ n) = abv a ^ n :=\nby induction n; simp [abv_mul abv, _root_.pow_succ, abv_one abv, *]\n\nlemma series_cau_of_abv_cau {\u03b1 : Type*} {\u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2] {abv : \u03b2 \u2192 \u03b1} {f : \u2115 \u2192 \u03b2} \n    [is_absolute_value abv] : is_cau_seq abs (\u03bb m, (range m).sum (\u03bb n, abv (f n))) \u2192 is_cau_seq abv (\u03bb m, (range m).sum f) := \n   \u03bb h, series_cau_of_abv_le_cau 0 (\u03bb n h, le_refl _) h\n\nlemma geo_series_cau {\u03b1 \u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [archimedean \u03b1] [field \u03b2]\n  {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv]\n   (x : \u03b2) (hx1 : abv x < 1) : is_cau_seq abv (\u03bb n, (range n).sum (\u03bb m, x ^ m)) :=\nhave hx1' : abv x \u2260 1 := \u03bb h, by simpa [h, lt_irrefl] using hx1,\nseries_cau_of_abv_cau\nbegin\n  simp only [pow_abv abv, geo_series_eq _ hx1'] {eta := ff},\n  refine @is_cau_of_incrs_bounded _ _ _ _ ((1 : \u03b1) / (1 - abv x)) 0 _ _,\n  { assume n hn,\n    rw abs_of_nonneg ,\n    refine div_le_div_of_le_of_pos (sub_le_self _ (pow_abv abv x n \u25b8 abv_nonneg _ _)) \n      (sub_pos.2 hx1),\n    refine div_nonneg (sub_nonneg.2 _) (sub_pos.2 hx1),\n    clear hn,\n    induction n with n ih,\n    { simp },\n    { rw [_root_.pow_succ, \u2190 one_mul (1 : \u03b1)],\n      refine mul_le_mul (le_of_lt hx1) ih (pow_abv abv x n \u25b8 abv_nonneg _ _) (by norm_num) } },\n  { assume n hn,\n    refine div_le_div_of_le_of_pos (sub_le_sub_left _ _) (sub_pos.2 hx1), \n    rw [\u2190 one_mul (_ ^ n), _root_.pow_succ],\n    exact mul_le_mul_of_nonneg_right (le_of_lt hx1) (pow_nonneg (abv_nonneg _ _) _) }\nend\n\nlemma geo_series_const_cau {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1] [archimedean \u03b1] (a x : \u03b1) :\n  abs x < 1 \u2192 is_cau_seq abs (\u03bb m, (range m).sum (\u03bb n, a * x ^ n)) :=\n\u03bb hx1, begin\n  have : is_cau_seq abs (\u03bb m, a * (range m).sum (\u03bb n, x ^ n)) := (cau_seq.const abs a * \u27e8_, geo_series_cau x hx1\u27e9).2,\n  simpa only [mul_sum] using this\nend\n\n-- The form of ratio test with  0 \u2264 r < 1, and abv (f (succ m)) \u2264 r * abv (f m) handled zero terms of series the best\nlemma series_ratio_test {\u03b1 : Type*} {\u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2] \n    [archimedean \u03b1] {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv] {f : \u2115 \u2192 \u03b2} (n : \u2115) (r : \u03b1) :\n    0 \u2264 r \u2192 r < 1 \u2192 (\u2200 m, n \u2264 m \u2192 abv (f (succ m)) \u2264 r * abv (f m)) \u2192 is_cau_seq abv (\u03bb m, (range m).sum f)\n  := begin\n  assume r0 r1 h,\n  refine series_cau_of_abv_le_cau (succ n) _ (geo_series_const_cau (abv (f (succ n)) * r\u207b\u00b9 ^ (succ n)) r _),\n  assume m mn,\n  generalize hk : m - (succ n) = k,rw nat.sub_eq_iff_eq_add mn at hk,\n  cases classical.em (r = 0) with r_zero r_pos,have m_pos := lt_of_lt_of_le (succ_pos n) mn,\n  have := pred_le_pred mn,simp at this,\n  have := h (pred m) this,simp[r_zero,succ_pred_eq_of_pos m_pos] at this,\n  refine le_trans this _,refine mul_nonneg _ _,\n  refine mul_nonneg (abv_nonneg _ _) (pow_nonneg (inv_nonneg.mpr r0) _),exact pow_nonneg r0 _,\n  replace r_pos : 0 < r,cases lt_or_eq_of_le r0 with h h,exact h,exact absurd h.symm r_pos,\n  revert m n,\n  induction k with k' hi,assume m n h mn hk,\n  rw [hk,zero_add,mul_right_comm,\u2190pow_inv',\u2190div_eq_mul_inv,mul_div_cancel],\n  exact (ne_of_lt (pow_pos r_pos _)).symm,\n  assume m n h mn hk,rw [hk,succ_add],\n  have kn : k' + (succ n) \u2265 (succ n), rw \u2190zero_add (succ n),refine add_le_add _ _,exact zero_le _,simp,\n  replace hi := hi (k' + (succ n)) n h kn rfl,\n  rw [(by simp [_root_.pow_succ'] : r ^ (succ (k' + succ n)) = r ^ (k' + succ n) * r),\u2190mul_assoc],\n  replace h := h (k' + succ n) (le_of_succ_le kn),rw mul_comm at h,\n  exact le_trans h (mul_le_mul_of_nonneg_right hi r0),\n  rwa abs_of_nonneg r0,\nend\n\nlemma sum_range_diag_flip {\u03b1 : Type*} [add_comm_monoid \u03b1] (n : \u2115) (f : \u2115 \u2192 \u2115 \u2192 \u03b1) : \n    (range n).sum (\u03bb m, (range (m + 1)).sum (\u03bb k, f k (m - k))) = \n    (range n).sum (\u03bb m, (range (n - m)).sum (f m)) :=\nhave h\u2081 : ((range n).sigma (range \u2218 succ)).sum\n    (\u03bb (a : \u03a3 m, \u2115), f (a.2) (a.1 - a.2)) = \n    (range n).sum (\u03bb m, (range (m + 1)).sum\n    (\u03bb k, f k (m - k))) := sum_sigma,\nhave h\u2082 : ((range n).sigma (\u03bb m, range (n - m))).sum (\u03bb a : \u03a3 (m : \u2115), \u2115, f (a.1) (a.2)) =\n    (range n).sum (\u03bb m, sum (range (n - m)) (f m)) := sum_sigma,\nh\u2081 \u25b8 h\u2082 \u25b8 sum_bij \n(\u03bb a _, \u27e8a.2, a.1 - a.2\u27e9)\n(\u03bb a ha, have h\u2081 : a.1 < n := mem_range.1 (mem_sigma.1 ha).1,\n  have h\u2082 : a.2 < succ a.1 := mem_range.1 (mem_sigma.1 ha).2,\n    mem_sigma.2 \u27e8mem_range.2 (lt_of_lt_of_le h\u2082 h\u2081), \n    mem_range.2 ((nat.sub_lt_sub_right_iff (le_of_lt_succ h\u2082)).2 h\u2081)\u27e9) \n(\u03bb _ _, rfl) \n(\u03bb \u27e8a\u2081, a\u2082\u27e9 \u27e8b\u2081, b\u2082\u27e9 ha hb h,\n  have ha : a\u2081 < n \u2227 a\u2082 \u2264 a\u2081 := \n      \u27e8mem_range.1 (mem_sigma.1 ha).1, le_of_lt_succ (mem_range.1 (mem_sigma.1 ha).2)\u27e9,\n  have hb : b\u2081 < n \u2227 b\u2082 \u2264 b\u2081 :=\n      \u27e8mem_range.1 (mem_sigma.1 hb).1, le_of_lt_succ (mem_range.1 (mem_sigma.1 hb).2)\u27e9,\n  have h : a\u2082 = b\u2082 \u2227 _ := sigma.mk.inj h,\n  have h' : a\u2081 = b\u2081 - b\u2082 + a\u2082 := (nat.sub_eq_iff_eq_add ha.2).1 (eq_of_heq h.2),\n  sigma.mk.inj_iff.2  \n    \u27e8nat.sub_add_cancel hb.2 \u25b8 h'.symm \u25b8 h.1 \u25b8 rfl, \n    (heq_of_eq h.1)\u27e9)\n(\u03bb \u27e8a\u2081, a\u2082\u27e9 ha,\n  have ha : a\u2081 < n \u2227 a\u2082 < n - a\u2081 := \n      \u27e8mem_range.1 (mem_sigma.1 ha).1, (mem_range.1 (mem_sigma.1 ha).2)\u27e9,\n  \u27e8\u27e8a\u2082 + a\u2081, a\u2081\u27e9, \u27e8mem_sigma.2 \u27e8mem_range.2 ((nat.lt_sub_right_iff_add_lt \n      (le_of_lt ha.1)).1 ha.2),\n    mem_range.2 (lt_succ_of_le (le_add_left _ _))\u27e9, \n  sigma.mk.inj_iff.2 \u27e8rfl, heq_of_eq (nat.add_sub_cancel _ _).symm\u27e9\u27e9\u27e9)\n\nlemma abv_sum_le_sum_abv {\u03b1 \u03b2 \u03b3 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2]\n  (abv : \u03b2 \u2192 \u03b1) [is_absolute_value abv] (f : \u03b3 \u2192 \u03b2) (s : finset \u03b3) : abv (s.sum f) \u2264 s.sum (abv \u2218 f) :=\nfinset.induction_on s (by simp [abv_zero abv]) $ \u03bb a s has ih, \nby rw [sum_insert has, sum_insert has];\n  exact le_trans (abv_add abv _ _) (add_le_add_left ih _)\n\nlemma sum_nonneg {\u03b1 \u03b2 : Type*} [ordered_comm_monoid \u03b1] {f : \u03b2 \u2192 \u03b1} {s : finset \u03b2} :\n  (\u2200 x \u2208 s, 0 \u2264 f x) \u2192 0 \u2264 s.sum f :=\nfinset.induction_on s (by simp) $ \u03bb a s has ih h, begin\n  rw [sum_insert has],\n  exact add_nonneg' (h a (by simp)) (ih (\u03bbx hx, by simp *)),\nend\n\nlemma neg_sum {\u03b1 \u03b2 : Type*} [add_comm_group \u03b1] {f : \u03b2 \u2192 \u03b1} {s : finset \u03b2} :\n  -s.sum f = s.sum (\u03bb x, -f x) :=\nfinset.induction_on s (by simp) (by simp {contextual := tt})\n\n@[simp] lemma filter_true {\u03b1 : Type*} (s : finset \u03b1) : s.filter (\u03bb _, true) = s :=\nfinset.ext.2 $ by simp\n\nlemma sum_range_sub_sum_range {\u03b1 : Type*} [add_comm_group \u03b1] {f : \u2115 \u2192 \u03b1} \n  {n m : \u2115} (hnm : n \u2264 m) : (range m).sum f - (range n).sum f = \n  ((range m).filter (\u03bb k, n \u2264 k)).sum f :=\nbegin\n  rw [\u2190 sum_sdiff (@filter_subset _ (\u03bb k, n \u2264 k) _ (range m)),\n    sub_eq_iff_eq_add, \u2190 eq_sub_iff_add_eq, add_sub_cancel'],\n  refine finset.sum_congr \n    (finset.ext.2 $ \u03bb a, \u27e8\u03bb h, by simp at *; finish,\n    \u03bb h, have ham : a < m := lt_of_lt_of_le (mem_range.1 h) hnm, \n      by simp * at *\u27e9)\n    (\u03bb _ _, rfl),\nend\n\nlemma series_cauchy_prod {\u03b1 \u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2] {a b : \u2115 \u2192 \u03b2}\n  {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv] : is_cau_seq abs (\u03bb m, (range m).sum (\u03bb n, abv (a n))) \u2192 is_cau_seq abv (\u03bb m, (range m).sum b) \u2192 \n  \u2200 \u03b5 : \u03b1, 0 < \u03b5 \u2192 \u2203 i : \u2115, \u2200 j \u2265 i, abv ((range j).sum a * (range j).sum b - (range j).sum (\u03bb n, \n  (range (n + 1)).sum (\u03bb m, a m * b (n - m))) ) < \u03b5 :=\nbegin\n-- slightly adapted version of theorem 9.4.7 from \"The Real Numbers and Real Analysis\", Ethan D. Bloch\n  assume ha hb \u03b5 \u03b50,\n  cases cau_seq.bounded \u27e8_, hb\u27e9 with Q hQ,simp at hQ,\n  cases cau_seq.bounded \u27e8_, ha\u27e9 with P hP,simp at hP,\n  have P0 : 0 < P,exact lt_of_le_of_lt (abs_nonneg _) (hP 0),\n  have P\u03b50 := div_pos \u03b50 (mul_pos (show (2 : \u03b1) > 0, from by norm_num) P0),\n  cases cau_seq.cauchy\u2082 \u27e8_, hb\u27e9 P\u03b50 with N hN,simp at hN,\n  have Q\u03b50 := div_pos \u03b50 (mul_pos (show (4 : \u03b1) > 0, from by norm_num) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))),\n  cases cau_seq.cauchy\u2082 \u27e8_, ha\u27e9 Q\u03b50 with M hM,simp at hM,\n  existsi 2 * (max N M + 1),\n  assume K hK,\n  have := sum_range_diag_flip K (\u03bb m n, a m * b n),\n  dsimp at this,\n  rw this,\n  have : (\u03bb (i : \u2115), (range (K - i)).sum (\u03bb (k : \u2115), a i * b k)) = (\u03bb (i : \u2115), a i * (range (K - i)).sum b),\n    by simp [finset.mul_sum],\n  rw this,clear this,\n  have : (range K).sum (\u03bb (i : \u2115), a i * (range (K - i)).sum b) = \n    (range K).sum (\u03bb (i : \u2115), a i * ((range (K - i)).sum b - (range K).sum b))\n    + (range K).sum (\u03bb i, a i * (range K).sum b),\n    {rw \u2190sum_add_distrib,simp[(mul_add _ _ _).symm]},\n  rw this, clear this,\n  rw sum_mul, simp,\n  rw abv_neg abv,\n  refine lt_of_le_of_lt (abv_sum_le_sum_abv _ _ _) _,\n  simp [abv_mul abv],\n  suffices : (range (max N M + 1)).sum (\u03bb (i : \u2115), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) +\n    ((range K).sum (\u03bb (i : \u2115), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) -(range (max N M + 1)).sum\n     (\u03bb (i : \u2115), \n    abv (a i) * abv ((range (K - i)).sum b - (range K).sum b))) < \u03b5 / (2 * P) * P + \u03b5 / (4 * Q) * (2 * Q),\n  { simp [(div_div_eq_div_mul _ _ _).symm] at this,\n    rwa[div_mul_cancel _ (ne_of_lt P0).symm,(by norm_num : (4 : \u03b1) = 2 * 2),\u2190div_div_eq_div_mul,mul_comm (2 : \u03b1),\u2190_root_.mul_assoc,\n    div_mul_cancel _ (ne_of_lt (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))).symm,div_mul_cancel,add_halves] at this,\n    norm_num},\n  refine add_lt_add _ _,\n  {have : (range (max N M + 1)).sum (\u03bb (i : \u2115), abv (a i) * \n    abv ((range (K - i)).sum b - (range K).sum b)) \u2264 (range (max N M + 1)).sum\n  (\u03bb (i : \u2115), abv (a i) * (\u03b5 / (2 * P))) := by\n    {refine sum_le_sum _,assume m mJ,refine mul_le_mul_of_nonneg_left _ _,\n      {refine le_of_lt (hN (K - m) K _ _),{\n      refine nat.le_sub_left_of_add_le (le_trans _ hK),\n      rw[succ_mul,_root_.one_mul],\n      exact add_le_add (le_of_lt (mem_range.1 mJ)) (le_trans (le_max_left _ _) (le_of_lt (lt_add_one _)))},\n      {refine le_trans _ hK,rw \u2190_root_.one_mul N,\n      refine mul_le_mul (by norm_num) (by rw _root_.one_mul;exact le_trans (le_max_left _ _) \n      (le_of_lt (lt_add_one _))) (zero_le _) (zero_le _)}},\n      exact abv_nonneg abv _},\n  refine lt_of_le_of_lt this _,\n  rw [\u2190 sum_mul, mul_comm],\n  specialize hP (max N M + 1),rwa abs_of_nonneg at hP,\n  exact (mul_lt_mul_left P\u03b50).mpr hP,\n  exact sum_nonneg (\u03bb x h, abv_nonneg abv _)},\n  {have hNMK : max N M + 1 < K := by\n    {refine lt_of_lt_of_le _ hK,\n    rw [succ_mul,_root_.one_mul,\u2190add_zero (max N M + 1)],\n    refine add_lt_add_of_le_of_lt (le_refl _) _,rw add_zero,\n    refine add_pos_of_nonneg_of_pos (zero_le _) (by norm_num)},\n  rw sum_range_sub_sum_range (le_of_lt hNMK),\n  exact calc sum (filter (\u03bb (k : \u2115), max N M + 1 \u2264 k) (range K))\n      (\u03bb (i : \u2115), abv (a i) * abv (sum (range (K - i)) b - sum (range K) b))\n      \u2264 sum (filter (\u03bb (k : \u2115), max N M + 1 \u2264 k) (range K)) (\u03bb i, abv (a i) * (2 * Q)) : \n    sum_le_sum (begin \n      assume n hn,\n      refine mul_le_mul_of_nonneg_left _ (abv_nonneg _ _),\n      rw sub_eq_add_neg,\n      refine le_trans (abv_add _ _ _) _,\n      rw [two_mul, abv_neg abv],\n      refine add_le_add (le_of_lt (hQ _)) (le_of_lt (hQ _)),\n    end)\n    ... < _ : begin \n      rw [\u2190 sum_mul, \u2190 sum_range_sub_sum_range (le_of_lt hNMK)],\n      refine (mul_lt_mul_right _).2 _,\n      rw two_mul,\n      refine add_pos (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0)) \n        (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0)),\n      refine lt_of_le_of_lt (le_abs_self _) _,\n      refine hM _ _ (le_trans (le_succ_of_le (le_max_right _ _)) (le_of_lt hNMK))\n        (le_succ_of_le (le_max_right _ _))\n     end }  \nend\n\nend a\n\nopen nat finset\nlemma complex.exp_series_abs_cau (z : \u2102) : is_cau_seq abs (\u03bb n, (range n).sum (\u03bb m, complex.abs (z ^ m / fact m))) := begin\n  cases exists_nat_gt (complex.abs z) with n hn,\n  have n_pos : (0 : \u211d) < n := lt_of_le_of_lt (complex.abs_nonneg _) hn,\n  refine series_ratio_test n (complex.abs z / n) _ _ _,exact div_nonneg_of_nonneg_of_pos (complex.abs_nonneg _) n_pos,rwa [div_lt_iff n_pos,one_mul],\n  assume m mn,rw [abs_of_nonneg (complex.abs_nonneg _),abs_of_nonneg (complex.abs_nonneg _)],\n  unfold fact,simp only [_root_.pow_succ, complex.abs_div,complex.abs_mul,div_eq_mul_inv,mul_inv',\n    nat.cast_mul,complex.abs_inv],\n  have : complex.abs z * complex.abs (z ^ m) * ((complex.abs \u2191(fact m))\u207b\u00b9 * (complex.abs \u2191(succ m))\u207b\u00b9) = complex.abs z * \n    complex.abs (z ^ m) * (complex.abs \u2191(fact m))\u207b\u00b9 * (complex.abs \u2191(succ m))\u207b\u00b9,ring,rw this,\n  have : complex.abs z * (\u2191n)\u207b\u00b9 * (complex.abs (z ^ m) * (complex.abs \u2191(fact m))\u207b\u00b9) = complex.abs z * complex.abs (z ^ m) * (complex.abs \u2191(fact m))\u207b\u00b9 * (\u2191n)\u207b\u00b9,ring,\n  rw this,\n  rw[(by simp : (succ m : \u2102) = ((succ m : \u211d) : \u2102)),complex.abs_of_nonneg],\n  refine mul_le_mul_of_nonneg_left _ _,\n  rw [inv_le_inv,nat.cast_le],exact le_succ_of_le mn,\n  rw [\u2190nat.cast_zero,nat.cast_lt],exact succ_pos _,exact n_pos,rw[\u2190complex.abs_inv,\u2190complex.abs_mul,\u2190complex.abs_mul],\n  exact complex.abs_nonneg _,rw[\u2190nat.cast_zero,nat.cast_le],exact zero_le _,\nend\n\nlemma complex.exp_series_cau (z : \u2102) : is_cau_seq complex.abs (\u03bb n, (range n).sum (\u03bb m, z ^ m / fact m)) := \n  series_cau_of_abv_cau (complex.exp_series_abs_cau z)\n\ndef exp' (z : \u2102) : cau_seq \u2102 complex.abs := \u27e8_, complex.exp_series_cau z\u27e9\n\nopen complex\ndef exp (z : \u2102) : \u2102 := complex.lim (exp' z)\n\ndef sin (z : \u2102) : \u2102 := (exp (I * z) - exp (-I * z)) / (2 * I)\n\ndef cos (z : \u2102) : \u2102 := (exp (I * z) + exp (-I * z)) / 2\n\ndef tan (z : \u2102) : \u2102 := sin z / cos z\n\ndef sinh (z : \u2102) : \u2102 := (exp z - exp (-z)) / 2\n\ndef cosh (z : \u2102) : \u2102 := (exp z + exp (-z)) / 2\n\ndef tanh (z : \u2102) : \u2102 := sinh z / cosh z\n\n@[simp] lemma exp_zero : exp 0 = 1 := begin\n  unfold exp exp',\n  refine lim_eq_of_equiv_const _,\n  assume \u03b5 \u03b50,\n  existsi 1,\n  assume j hj,\n  dsimp [exp'],\n  suffices : complex.abs (sum (range j) (\u03bb (m : \u2115), 0 ^ m / \u2191(fact m)) + -1) = 0,\n    rwa this,\n  cases j,\n  { exact absurd hj (by norm_num) },\n  { induction j,\n    { simpa },\n    { rw \u2190 j_ih dec_trivial,\n      simp only [sum_range_succ, _root_.pow_succ],\n      simp } }\nend\n\nlemma exp_add (x y : \u2102) : exp (x + y) = exp x * exp y := \nshow complex.lim (\u27e8_, complex.exp_series_cau (x + y)\u27e9 : cau_seq \u2102 abs) = \n  complex.lim \u21d1(show cau_seq \u2102 abs, from \u27e8_, complex.exp_series_cau x\u27e9)\n  * complex.lim (show cau_seq \u2102 abs, from \u27e8_, complex.exp_series_cau y\u27e9),\nbegin\n have hxa := complex.exp_series_abs_cau x,\n have hx := complex.exp_series_cau x,\n have hy := complex.exp_series_cau y,\n have hxy := complex.exp_series_cau (x + y),\n   rw complex.lim_mul_lim, \n have hj : \u2200 j : \u2115, (range j).sum (\u03bb (m : \u2115),\n    (x + y) ^ m / \u2191(fact m)) = (range j).sum \n    (\u03bb i, (range (i + 1)).sum (\u03bb k, x ^ k / fact k *\n    (y ^ (i - k) / fact (i - k)))),\n    { assume j,\n      refine finset.sum_congr rfl (\u03bb m hm, _),\n      rw [add_pow, div_eq_mul_inv, sum_mul],\n      refine finset.sum_congr rfl (\u03bb i hi, _),\n      have := choose_mul_fact_mul_fact (le_of_lt_succ $ finset.mem_range.1 hi),\n      rw [\u2190 this, nat.cast_mul, nat.cast_mul, mul_inv', mul_inv'],\n      simp only [mul_left_comm (choose m i : \u2102), mul_assoc, mul_left_comm (choose m i : \u2102)\u207b\u00b9,\n        mul_comm (choose m i : \u2102)],\n      have : (choose m i : \u2102) \u2260 0 := nat.cast_ne_zero.2 (\u03bb h, \n        by have := choose_pos (le_of_lt_succ (mem_range.1 hi)); simpa [h, lt_irrefl] using this),\n      rw inv_mul_cancel this,\n      simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] },\n  have hf := funext hj, have hxy1 := hxy, rw hf at hxy1,\n  have := series_cauchy_prod hxa hy,\n  refine eq.symm (lim_eq_lim_of_equiv _),\n  assume \u03b5 \u03b50,\n  dsimp,\n  simp only [hj],\n  exact this \u03b5 \u03b50,\nend\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/exponential_complex1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7319902308975189}}
{"text": "import MyNat.Definition\nimport MyNat.Addition\nimport AdditionWorld.Level5 -- succ_eq_add_one\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Advanced Addition World\n\n## Level 12: `add_one_eq_succ`\n\nWe have\n\n  * `succ_eq_add_one (n : MyNat) : succ n = n + 1`\n\nbut sometimes the other way is also convenient.\n\n## Theorem\nFor any natural number `d`, we have ` d+1 = succ d. `\n-/\ntheorem add_one_eq_succ (d : MyNat) : d + 1 = succ d := by\n  rw [succ_eq_add_one]\n\n/-!\nNext up [Level 13](./Level13.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedAdditionWorld/Level12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7319476435488876}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland, Yury Kudryashov\n-/\nimport algebra.group.semiconj\n\n/-!\n# Commuting pairs of elements in monoids\n\nWe define the predicate `commute a b := a * b = b * a` and provide some operations on terms `(h :\ncommute a b)`. E.g., if `a`, `b`, and c are elements of a semiring, and that `hb : commute a b` and\n`hc : commute a c`.  Then `hb.pow_left 5` proves `commute (a ^ 5) b` and `(hb.pow_right 2).add_right\n(hb.mul_right hc)` proves `commute a (b ^ 2 + b * c)`.\n\nLean does not immediately recognise these terms as equations, so for rewriting we need syntax like\n`rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`.\n\nThis file defines only a few operations (`mul_left`, `inv_right`, etc).  Other operations\n(`pow_right`, field inverse etc) are in the files that define corresponding notions.\n\n## Implementation details\n\nMost of the proofs come from the properties of `semiconj_by`.\n-/\n\nvariables {G : Type*}\n\n/-- Two elements commute if `a * b = b * a`. -/\n@[to_additive add_commute \"Two elements additively commute if `a + b = b + a`\"]\ndef commute {S : Type*} [has_mul S] (a b : S) : Prop := semiconj_by a b b\n\nnamespace commute\n\nsection has_mul\n\nvariables {S : Type*} [has_mul S]\n\n/-- Equality behind `commute a b`; useful for rewriting. -/\n@[to_additive \"Equality behind `add_commute a b`; useful for rewriting.\"]\nprotected lemma eq {a b : S} (h : commute a b) : a * b = b * a := h\n\n/-- Any element commutes with itself. -/\n@[refl, simp, to_additive \"Any element commutes with itself.\"]\nprotected lemma refl (a : S) : commute a a := eq.refl (a * a)\n\n/-- If `a` commutes with `b`, then `b` commutes with `a`. -/\n@[symm, to_additive \"If `a` commutes with `b`, then `b` commutes with `a`.\"]\nprotected lemma symm {a b : S} (h : commute a b) : commute b a := eq.symm h\n\n@[to_additive] protected theorem semiconj_by {a b : S} (h : commute a b) : semiconj_by a b b := h\n\n@[to_additive]\nprotected theorem symm_iff {a b : S} : commute a b \u2194 commute b a :=\n\u27e8commute.symm, commute.symm\u27e9\n\nend has_mul\n\nsection semigroup\n\nvariables {S : Type*} [semigroup S] {a b c : S}\n\n/-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/\n@[simp, to_additive \"If `a` commutes with both `b` and `c`, then it commutes with their sum.\"]\nlemma mul_right (hab : commute a b) (hac : commute a c) : commute a (b * c) := hab.mul_right hac\n\n/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/\n@[simp, to_additive \"If both `a` and `b` commute with `c`, then their product commutes with `c`.\"]\nlemma mul_left (hac : commute a c) (hbc : commute b c) : commute (a * b) c := hac.mul_left hbc\n\n@[to_additive] protected lemma right_comm (h : commute b c) (a : S) :\n  a * b * c = a * c * b :=\nby simp only [mul_assoc, h.eq]\n\n@[to_additive] protected lemma left_comm (h : commute a b) (c) :\n  a * (b * c) = b * (a * c) :=\nby simp only [\u2190 mul_assoc, h.eq]\n\nend semigroup\n\n@[to_additive]\nprotected \n\nsection mul_one_class\n\nvariables {M : Type*} [mul_one_class M]\n\n@[simp, to_additive] theorem one_right (a : M) : commute a 1 := semiconj_by.one_right a\n@[simp, to_additive] theorem one_left (a : M) : commute 1 a := semiconj_by.one_left a\n\nend mul_one_class\n\nsection monoid\n\nvariables {M : Type*} [monoid M] {a b : M} {u u\u2081 u\u2082 : M\u02e3}\n\n@[simp, to_additive]\ntheorem pow_right (h : commute a b) (n : \u2115) : commute a (b ^ n) := h.pow_right n\n@[simp, to_additive]\ntheorem pow_left (h : commute a b) (n : \u2115) : commute (a ^ n) b := (h.symm.pow_right n).symm\n@[simp, to_additive]\ntheorem pow_pow (h : commute a b) (m n : \u2115) : commute (a ^ m) (b ^ n) :=\n(h.pow_left m).pow_right n\n\n@[simp, to_additive]\ntheorem self_pow (a : M) (n : \u2115) : commute a (a ^ n) := (commute.refl a).pow_right n\n@[simp, to_additive]\ntheorem pow_self (a : M) (n : \u2115) : commute (a ^ n) a := (commute.refl a).pow_left n\n@[simp, to_additive]\ntheorem pow_pow_self (a : M) (m n : \u2115) : commute (a ^ m) (a ^ n) :=\n(commute.refl a).pow_pow m n\n\n@[to_additive succ_nsmul'] theorem _root_.pow_succ' (a : M) (n : \u2115) : a ^ (n + 1) = a ^ n * a :=\n(pow_succ a n).trans (self_pow _ _)\n\n@[to_additive] theorem units_inv_right : commute a u \u2192 commute a \u2191u\u207b\u00b9 :=\nsemiconj_by.units_inv_right\n\n@[simp, to_additive] theorem units_inv_right_iff :\n  commute a \u2191u\u207b\u00b9 \u2194 commute a u :=\nsemiconj_by.units_inv_right_iff\n\n@[to_additive] theorem units_inv_left : commute \u2191u a \u2192 commute \u2191u\u207b\u00b9 a :=\nsemiconj_by.units_inv_symm_left\n\n@[simp, to_additive]\ntheorem units_inv_left_iff: commute \u2191u\u207b\u00b9 a \u2194 commute \u2191u a :=\nsemiconj_by.units_inv_symm_left_iff\n\n@[to_additive]\ntheorem units_coe : commute u\u2081 u\u2082 \u2192 commute (u\u2081 : M) u\u2082 := semiconj_by.units_coe\n@[to_additive]\ntheorem units_of_coe : commute (u\u2081 : M) u\u2082 \u2192 commute u\u2081 u\u2082 := semiconj_by.units_of_coe\n@[simp, to_additive]\ntheorem units_coe_iff : commute (u\u2081 : M) u\u2082 \u2194 commute u\u2081 u\u2082 := semiconj_by.units_coe_iff\n\n@[to_additive] lemma is_unit_mul_iff (h : commute a b) :\n  is_unit (a * b) \u2194 is_unit a \u2227 is_unit b :=\nbegin\n  refine \u27e8_, \u03bb H, H.1.mul H.2\u27e9,\n  rintro \u27e8u, hu\u27e9,\n  have : b * \u2191u\u207b\u00b9 * a = 1,\n  { have : commute a u := hu.symm \u25b8 (commute.refl _).mul_right h,\n    rw [\u2190 this.units_inv_right.right_comm, \u2190 h.eq, \u2190 hu, u.mul_inv] },\n  split,\n  { refine \u27e8\u27e8a, b * \u2191u\u207b\u00b9, _, this\u27e9, rfl\u27e9,\n    rw [\u2190 mul_assoc, \u2190 hu, u.mul_inv] },\n  { rw mul_assoc at this,\n    refine \u27e8\u27e8b, \u2191u\u207b\u00b9 * a, this, _\u27e9, rfl\u27e9,\n    rw [mul_assoc, \u2190 hu, u.inv_mul] }\nend\n\n@[simp, to_additive] lemma _root_.is_unit_mul_self_iff :\n  is_unit (a * a) \u2194 is_unit a :=\n(commute.refl a).is_unit_mul_iff.trans (and_self _)\n\nend monoid\n\nsection division_monoid\nvariables [division_monoid G] {a b : G}\n\n@[to_additive] lemma inv_inv : commute a b \u2192 commute a\u207b\u00b9 b\u207b\u00b9 := semiconj_by.inv_inv_symm\n@[simp, to_additive]\nlemma inv_inv_iff : commute a\u207b\u00b9 b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_inv_symm_iff\n\nend division_monoid\n\nsection group\n\nvariables [group G] {a b : G}\n\n@[to_additive]\ntheorem inv_right : commute a b \u2192 commute a b\u207b\u00b9 := semiconj_by.inv_right\n@[simp, to_additive]\ntheorem inv_right_iff : commute a b\u207b\u00b9 \u2194 commute a b := semiconj_by.inv_right_iff\n\n@[to_additive] theorem inv_left :  commute a b \u2192 commute a\u207b\u00b9 b := semiconj_by.inv_symm_left\n@[simp, to_additive]\ntheorem inv_left_iff : commute a\u207b\u00b9 b \u2194 commute a b := semiconj_by.inv_symm_left_iff\n\n@[to_additive]\nprotected theorem inv_mul_cancel (h : commute a b) : a\u207b\u00b9 * b * a = b :=\nby rw [h.inv_left.eq, inv_mul_cancel_right]\n\n@[to_additive]\ntheorem inv_mul_cancel_assoc (h : commute a b) : a\u207b\u00b9 * (b * a) = b :=\nby rw [\u2190 mul_assoc, h.inv_mul_cancel]\n\n@[to_additive]\nprotected theorem mul_inv_cancel (h : commute a b) : a * b * a\u207b\u00b9 = b :=\nby rw [h.eq, mul_inv_cancel_right]\n\n@[to_additive]\ntheorem mul_inv_cancel_assoc (h : commute a b) : a * (b * a\u207b\u00b9) = b :=\nby rw [\u2190 mul_assoc, h.mul_inv_cancel]\n\nend group\n\nend commute\n\nsection comm_group\n\nvariables [comm_group G] (a b : G)\n\n@[simp, to_additive] lemma mul_inv_cancel_comm : a * b * a\u207b\u00b9 = b :=\n(commute.all a b).mul_inv_cancel\n\n@[simp, to_additive] lemma mul_inv_cancel_comm_assoc : a * (b * a\u207b\u00b9) = b :=\n(commute.all a b).mul_inv_cancel_assoc\n\n@[simp, to_additive] lemma inv_mul_cancel_comm : a\u207b\u00b9 * b * a = b :=\n(commute.all a b).inv_mul_cancel\n\n@[simp, to_additive] lemma inv_mul_cancel_comm_assoc : a\u207b\u00b9 * (b * a) = b :=\n(commute.all a b).inv_mul_cancel_assoc\n\nend comm_group\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/group/commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8031738057795402, "lm_q1q2_score": 0.7318356754392924}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport measure_theory.measure.hausdorff\n\n/-!\n# Hausdorff dimension\n\nThe Hausdorff dimension of a set `X` in an (extended) metric space is the unique number\n`dimH s : \u211d\u22650\u221e` such that for any `d : \u211d\u22650` we have\n\n- `\u03bcH[d] s = 0` if `dimH s < d`, and\n- `\u03bcH[d] s = \u221e` if `d < dimH s`.\n\nIn this file we define `dimH s` to be the Hausdorff dimension of `s`, then prove some basic\nproperties of Hausdorff dimension.\n\n## Main definitions\n\n* `measure_theory.dimH`: the Hausdorff dimension of a set. For the Hausdorff dimension of the whole\n  space we use `measure_theory.dimH (set.univ : set X)`.\n\n## Main results\n\n### Basic properties of Hausdorff dimension\n\n* `hausdorff_measure_of_lt_dimH`, `dimH_le_of_hausdorff_measure_ne_top`,\n  `le_dimH_of_hausdorff_measure_eq_top`, `hausdorff_measure_of_dimH_lt`, `measure_zero_of_dimH_lt`,\n  `le_dimH_of_hausdorff_measure_ne_zero`, `dimH_of_hausdorff_measure_ne_zero_ne_top`: various forms\n  of the characteristic property of the Hausdorff dimension;\n* `dimH_union`: the Hausdorff dimension of the union of two sets is the maximum of their Hausdorff\n  dimensions.\n* `dimH_Union`, `dimH_bUnion`, `dimH_sUnion`: the Hausdorff dimension of a countable union of sets\n  is the supremum of their Hausdorff dimensions;\n* `dimH_empty`, `dimH_singleton`, `set.subsingleton.dimH_zero`, `set.countable.dimH_zero` : `dimH s\n  = 0` whenever `s` is countable;\n\n### (Pre)images under (anti)lipschitz and H\u00f6lder continuous maps\n\n* `holder_with.dimH_image_le` etc: if `f : X \u2192 Y` is H\u00f6lder continuous with exponent `r > 0`, then\n  for any `s`, `dimH (f '' s) \u2264 dimH s / r`. We prove versions of this statement for `holder_with`,\n  `holder_on_with`, and locally H\u00f6lder maps, as well as for `set.image` and `set.range`.\n* `lipschitz_with.dimH_image_le` etc: Lipschitz continuous maps do not increase the Hausdorff\n  dimension of sets.\n* for a map that is known to be both Lipschitz and antilipschitz (e.g., for an `isometry` or\n  a `continuous_linear_equiv`) we also prove `dimH (f '' s) = dimH s`.\n\n### Hausdorff measure in `\u211d\u207f`\n\n* `real.dimH_of_nonempty_interior`: if `s` is a set in a finite dimensional real vector space `E`\n  with nonempty interior, then the Hausdorff dimension of `s` is equal to the dimension of `E`.\n* `dense_compl_of_dimH_lt_finrank`: if `s` is a set in a finite dimensional real vector space `E`\n  with Hausdorff dimension strictly less than the dimension of `E`, the `s` has a dense complement.\n* `cont_diff.dense_compl_range_of_finrank_lt_finrank`: the complement to the range of a `C\u00b9`\n  smooth map is dense provided that the dimension of the domain is strictly less than the dimension\n  of the codomain.\n\n## Notations\n\nWe use the following notation localized in `measure_theory`. It is defined in\n`measure_theory.measure.hausdorff`.\n\n- `\u03bcH[d]` : `measure_theory.measure.hausdorff_measure d`\n\n## Implementation notes\n\n* The definition of `dimH` explicitly uses `borel X` as a measurable space structure. This way we\n  can formulate lemmas about Hausdorff dimension without assuming that the environment has a\n  `[measurable_space X]` instance that is equal but possibly not defeq to `borel X`.\n\n  Lemma `dimH_def` unfolds this definition using whatever `[measurable_space X]` instance we have in\n  the environment (as long as it is equal to `borel X`).\n\n* The definition `dimH` is irreducible; use API lemmas or `dimH_def` instead.\n\n## Tags\n\nHausdorff measure, Hausdorff dimension, dimension\n-/\nopen_locale measure_theory ennreal nnreal topology\nopen measure_theory measure_theory.measure set topological_space finite_dimensional filter\n\nvariables {\u03b9 X Y : Type*} [emetric_space X] [emetric_space Y]\n\n/-- Hausdorff dimension of a set in an (e)metric space. -/\n@[irreducible] noncomputable def dimH (s : set X) : \u211d\u22650\u221e :=\nby { borelize X, exact \u2a06 (d : \u211d\u22650) (hd : @hausdorff_measure X _ _ \u27e8rfl\u27e9 d s = \u221e), d }\n\n/-!\n### Basic properties\n-/\nsection measurable\n\nvariables [measurable_space X] [borel_space X]\n\n/-- Unfold the definition of `dimH` using `[measurable_space X] [borel_space X]` from the\nenvironment. -/\nlemma dimH_def (s : set X) : dimH s = \u2a06 (d : \u211d\u22650) (hd : \u03bcH[d] s = \u221e), d :=\nby { borelize X, rw dimH }\n\nlemma hausdorff_measure_of_lt_dimH {s : set X} {d : \u211d\u22650} (h : \u2191d < dimH s) : \u03bcH[d] s = \u221e :=\nbegin\n  simp only [dimH_def, lt_supr_iff] at h,\n  rcases h with \u27e8d', hsd', hdd'\u27e9,\n  rw [ennreal.coe_lt_coe, \u2190 nnreal.coe_lt_coe] at hdd',\n  exact top_unique (hsd' \u25b8 hausdorff_measure_mono hdd'.le _)\nend\n\nlemma dimH_le {s : set X} {d : \u211d\u22650\u221e} (H : \u2200 d' : \u211d\u22650, \u03bcH[d'] s = \u221e \u2192 \u2191d' \u2264 d) : dimH s \u2264 d :=\n(dimH_def s).trans_le $ supr\u2082_le H\n\nlemma dimH_le_of_hausdorff_measure_ne_top {s : set X} {d : \u211d\u22650} (h : \u03bcH[d] s \u2260 \u221e) :\n  dimH s \u2264 d :=\nle_of_not_lt $ mt hausdorff_measure_of_lt_dimH h\n\nlemma le_dimH_of_hausdorff_measure_eq_top {s : set X} {d : \u211d\u22650} (h : \u03bcH[d] s = \u221e) :\n  \u2191d \u2264 dimH s :=\nby { rw dimH_def, exact le_supr\u2082 d h }\n\nlemma hausdorff_measure_of_dimH_lt {s : set X} {d : \u211d\u22650}\n  (h : dimH s < d) : \u03bcH[d] s = 0 :=\nbegin\n  rw dimH_def at h,\n  rcases ennreal.lt_iff_exists_nnreal_btwn.1 h with \u27e8d', hsd', hd'd\u27e9,\n  rw [ennreal.coe_lt_coe, \u2190 nnreal.coe_lt_coe] at hd'd,\n  exact (hausdorff_measure_zero_or_top hd'd s).resolve_right (\u03bb h, hsd'.not_le $ le_supr\u2082 d' h)\nend\n\nlemma measure_zero_of_dimH_lt {\u03bc : measure X} {d : \u211d\u22650}\n  (h : \u03bc \u226a \u03bcH[d]) {s : set X} (hd : dimH s < d) :\n  \u03bc s = 0 :=\nh $ hausdorff_measure_of_dimH_lt hd\n\nlemma le_dimH_of_hausdorff_measure_ne_zero {s : set X} {d : \u211d\u22650} (h : \u03bcH[d] s \u2260 0) :\n  \u2191d \u2264 dimH s :=\nle_of_not_lt $ mt hausdorff_measure_of_dimH_lt h\n\nlemma dimH_of_hausdorff_measure_ne_zero_ne_top {d : \u211d\u22650} {s : set X} (h : \u03bcH[d] s \u2260 0)\n  (h' : \u03bcH[d] s \u2260 \u221e) : dimH s = d :=\nle_antisymm (dimH_le_of_hausdorff_measure_ne_top h') (le_dimH_of_hausdorff_measure_ne_zero h)\n\nend measurable\n\n@[mono] lemma dimH_mono {s t : set X} (h : s \u2286 t) : dimH s \u2264 dimH t :=\nbegin\n  borelize X,\n  exact dimH_le (\u03bb d hd, le_dimH_of_hausdorff_measure_eq_top $\n    top_unique $ hd \u25b8 measure_mono h)\nend\n\nlemma dimH_subsingleton {s : set X} (h : s.subsingleton) : dimH s = 0 :=\nbegin\n  borelize X,\n  apply le_antisymm _ (zero_le _),\n  refine dimH_le_of_hausdorff_measure_ne_top _,\n  exact ((hausdorff_measure_le_one_of_subsingleton h le_rfl).trans_lt ennreal.one_lt_top).ne,\nend\n\nalias dimH_subsingleton \u2190 set.subsingleton.dimH_zero\n\n@[simp] lemma dimH_empty : dimH (\u2205 : set X) = 0 := subsingleton_empty.dimH_zero\n\n@[simp] lemma dimH_singleton (x : X) : dimH ({x} : set X) = 0 := subsingleton_singleton.dimH_zero\n\n@[simp] lemma dimH_Union [encodable \u03b9] (s : \u03b9 \u2192 set X) :\n  dimH (\u22c3 i, s i) = \u2a06 i, dimH (s i) :=\nbegin\n  borelize X,\n  refine le_antisymm (dimH_le $ \u03bb d hd, _) (supr_le $ \u03bb i, dimH_mono $ subset_Union _ _),\n  contrapose! hd,\n  have : \u2200 i, \u03bcH[d] (s i) = 0,\n    from \u03bb i, hausdorff_measure_of_dimH_lt ((le_supr (\u03bb i, dimH (s i)) i).trans_lt hd),\n  rw measure_Union_null this,\n  exact ennreal.zero_ne_top\nend\n\n@[simp] lemma dimH_bUnion {s : set \u03b9} (hs : s.countable) (t : \u03b9 \u2192 set X) :\n  dimH (\u22c3 i \u2208 s, t i) = \u2a06 i \u2208 s, dimH (t i) :=\nbegin\n  haveI := hs.to_encodable,\n  rw [bUnion_eq_Union, dimH_Union, \u2190 supr_subtype'']\nend\n\n@[simp] lemma dimH_sUnion {S : set (set X)} (hS : S.countable) : dimH (\u22c3\u2080 S) = \u2a06 s \u2208 S, dimH s :=\nby rw [sUnion_eq_bUnion, dimH_bUnion hS]\n\n@[simp] lemma dimH_union (s t : set X) : dimH (s \u222a t) = max (dimH s) (dimH t) :=\nby rw [union_eq_Union, dimH_Union, supr_bool_eq, cond, cond, ennreal.sup_eq_max]\n\nlemma dimH_countable {s : set X} (hs : s.countable) : dimH s = 0 :=\nbUnion_of_singleton s \u25b8 by simp only [dimH_bUnion hs, dimH_singleton, ennreal.supr_zero_eq_zero]\n\nalias dimH_countable \u2190 set.countable.dimH_zero\n\nlemma dimH_finite {s : set X} (hs : s.finite) : dimH s = 0 := hs.countable.dimH_zero\n\nalias dimH_finite \u2190 set.finite.dimH_zero\n\n@[simp] lemma dimH_coe_finset (s : finset X) : dimH (s : set X) = 0 := s.finite_to_set.dimH_zero\n\nalias dimH_coe_finset \u2190 finset.dimH_zero\n\n/-!\n### Hausdorff dimension as the supremum of local Hausdorff dimensions\n-/\n\nsection\n\nvariables [second_countable_topology X]\n\n/-- If `r` is less than the Hausdorff dimension of a set `s` in an (extended) metric space with\nsecond countable topology, then there exists a point `x \u2208 s` such that every neighborhood\n`t` of `x` within `s` has Hausdorff dimension greater than `r`. -/\nlemma exists_mem_nhds_within_lt_dimH_of_lt_dimH {s : set X} {r : \u211d\u22650\u221e} (h : r < dimH s) :\n  \u2203 x \u2208 s, \u2200 t \u2208 \ud835\udcdd[s] x, r < dimH t :=\nbegin\n  contrapose! h, choose! t htx htr using h,\n  rcases countable_cover_nhds_within htx with \u27e8S, hSs, hSc, hSU\u27e9,\n  calc dimH s \u2264 dimH (\u22c3 x \u2208 S, t x) : dimH_mono hSU\n  ... = \u2a06 x \u2208 S, dimH (t x) : dimH_bUnion hSc _\n  ... \u2264 r : supr\u2082_le (\u03bb x hx, htr x $ hSs hx)\nend\n\n/-- In an (extended) metric space with second countable topology, the Hausdorff dimension\nof a set `s` is the supremum over `x \u2208 s` of the limit superiors of `dimH t` along\n`(\ud835\udcdd[s] x).small_sets`. -/\nlemma bsupr_limsup_dimH (s : set X) : (\u2a06 x \u2208 s, limsup dimH (\ud835\udcdd[s] x).small_sets) = dimH s :=\nbegin\n  refine le_antisymm (supr\u2082_le $ \u03bb x hx, _) _,\n  { refine Limsup_le_of_le (by apply_auto_param) (eventually_map.2 _),\n    exact eventually_small_sets.2 \u27e8s, self_mem_nhds_within, \u03bb t, dimH_mono\u27e9 },\n  { refine le_of_forall_ge_of_dense (\u03bb r hr, _),\n    rcases exists_mem_nhds_within_lt_dimH_of_lt_dimH hr with \u27e8x, hxs, hxr\u27e9,\n    refine le_supr\u2082_of_le x hxs _, rw limsup_eq, refine le_Inf (\u03bb b hb, _),\n    rcases eventually_small_sets.1 hb with \u27e8t, htx, ht\u27e9,\n    exact (hxr t htx).le.trans (ht t subset.rfl) }\nend\n\n/-- In an (extended) metric space with second countable topology, the Hausdorff dimension\nof a set `s` is the supremum over all `x` of the limit superiors of `dimH t` along\n`(\ud835\udcdd[s] x).small_sets`. -/\nlemma supr_limsup_dimH (s : set X) : (\u2a06 x, limsup dimH (\ud835\udcdd[s] x).small_sets) = dimH s :=\nbegin\n  refine le_antisymm (supr_le $ \u03bb x, _) _,\n  { refine Limsup_le_of_le (by apply_auto_param) (eventually_map.2 _),\n    exact eventually_small_sets.2 \u27e8s, self_mem_nhds_within, \u03bb t, dimH_mono\u27e9 },\n  { rw \u2190 bsupr_limsup_dimH, exact supr\u2082_le_supr _ _ }\nend\n\nend\n\n/-!\n### Hausdorff dimension and H\u00f6lder continuity\n-/\n\nvariables {C K r : \u211d\u22650} {f : X \u2192 Y} {s t : set X}\n\n/-- If `f` is a H\u00f6lder continuous map with exponent `r > 0`, then `dimH (f '' s) \u2264 dimH s / r`. -/\nlemma holder_on_with.dimH_image_le (h : holder_on_with C r f s) (hr : 0 < r) :\n  dimH (f '' s) \u2264 dimH s / r :=\nbegin\n  borelize [X, Y],\n  refine dimH_le (\u03bb d hd, _),\n  have := h.hausdorff_measure_image_le hr d.coe_nonneg,\n  rw [hd, ennreal.coe_rpow_of_nonneg _ d.coe_nonneg, top_le_iff] at this,\n  have Hrd : \u03bcH[(r * d : \u211d\u22650)] s = \u22a4,\n  { contrapose this, exact ennreal.mul_ne_top ennreal.coe_ne_top this },\n  rw [ennreal.le_div_iff_mul_le, mul_comm, \u2190 ennreal.coe_mul],\n  exacts [le_dimH_of_hausdorff_measure_eq_top Hrd, or.inl (mt ennreal.coe_eq_zero.1 hr.ne'),\n    or.inl ennreal.coe_ne_top]\nend\n\nnamespace holder_with\n\n/-- If `f : X \u2192 Y` is H\u00f6lder continuous with a positive exponent `r`, then the Hausdorff dimension\nof the image of a set `s` is at most `dimH s / r`. -/\nlemma dimH_image_le (h : holder_with C r f) (hr : 0 < r) (s : set X) :\n  dimH (f '' s) \u2264 dimH s / r :=\n(h.holder_on_with s).dimH_image_le hr\n\n/-- If `f` is a H\u00f6lder continuous map with exponent `r > 0`, then the Hausdorff dimension of its\nrange is at most the Hausdorff dimension of its domain divided by `r`. -/\nlemma dimH_range_le (h : holder_with C r f) (hr : 0 < r) :\n  dimH (range f) \u2264 dimH (univ : set X) / r :=\n@image_univ _ _ f \u25b8 h.dimH_image_le hr univ\n\nend holder_with\n\n/-- If `s` is a set in a space `X` with second countable topology and `f : X \u2192 Y` is H\u00f6lder\ncontinuous in a neighborhood within `s` of every point `x \u2208 s` with the same positive exponent `r`\nbut possibly different coefficients, then the Hausdorff dimension of the image `f '' s` is at most\nthe Hausdorff dimension of `s` divided by `r`. -/\nlemma dimH_image_le_of_locally_holder_on [second_countable_topology X] {r : \u211d\u22650} {f : X \u2192 Y}\n  (hr : 0 < r) {s : set X} (hf : \u2200 x \u2208 s, \u2203 (C : \u211d\u22650) (t \u2208 \ud835\udcdd[s] x), holder_on_with C r f t) :\n  dimH (f '' s) \u2264 dimH s / r :=\nbegin\n  choose! C t htn hC using hf,\n  rcases countable_cover_nhds_within htn with \u27e8u, hus, huc, huU\u27e9,\n  replace huU := inter_eq_self_of_subset_left huU, rw inter_Union\u2082 at huU,\n  rw [\u2190 huU, image_Union\u2082, dimH_bUnion huc, dimH_bUnion huc], simp only [ennreal.supr_div],\n  exact supr\u2082_mono (\u03bb x hx, ((hC x (hus hx)).mono (inter_subset_right _ _)).dimH_image_le hr)\nend\n\n/-- If `f : X \u2192 Y` is H\u00f6lder continuous in a neighborhood of every point `x : X` with the same\npositive exponent `r` but possibly different coefficients, then the Hausdorff dimension of the range\nof `f` is at most the Hausdorff dimension of `X` divided by `r`. -/\nlemma dimH_range_le_of_locally_holder_on [second_countable_topology X] {r : \u211d\u22650} {f : X \u2192 Y}\n  (hr : 0 < r) (hf : \u2200 x : X, \u2203 (C : \u211d\u22650) (s \u2208 \ud835\udcdd x), holder_on_with C r f s) :\n  dimH (range f) \u2264 dimH (univ : set X) / r :=\nbegin\n  rw \u2190 image_univ,\n  refine dimH_image_le_of_locally_holder_on hr (\u03bb x _, _),\n  simpa only [exists_prop, nhds_within_univ] using hf x\nend\n\n/-!\n### Hausdorff dimension and Lipschitz continuity\n-/\n\n/-- If `f : X \u2192 Y` is Lipschitz continuous on `s`, then `dimH (f '' s) \u2264 dimH s`. -/\nlemma lipschitz_on_with.dimH_image_le (h : lipschitz_on_with K f s) : dimH (f '' s) \u2264 dimH s :=\nby simpa using h.holder_on_with.dimH_image_le zero_lt_one\n\nnamespace lipschitz_with\n\n/-- If `f` is a Lipschitz continuous map, then `dimH (f '' s) \u2264 dimH s`. -/\nlemma dimH_image_le (h : lipschitz_with K f) (s : set X) : dimH (f '' s) \u2264 dimH s :=\n(h.lipschitz_on_with s).dimH_image_le\n\n/-- If `f` is a Lipschitz continuous map, then the Hausdorff dimension of its range is at most the\nHausdorff dimension of its domain. -/\nlemma dimH_range_le (h : lipschitz_with K f) : dimH (range f) \u2264 dimH (univ : set X) :=\n@image_univ _ _ f \u25b8 h.dimH_image_le univ\n\nend lipschitz_with\n\n/-- If `s` is a set in an extended metric space `X` with second countable topology and `f : X \u2192 Y`\nis Lipschitz in a neighborhood within `s` of every point `x \u2208 s`, then the Hausdorff dimension of\nthe image `f '' s` is at most the Hausdorff dimension of `s`. -/\nlemma dimH_image_le_of_locally_lipschitz_on [second_countable_topology X] {f : X \u2192 Y}\n  {s : set X} (hf : \u2200 x \u2208 s, \u2203 (C : \u211d\u22650) (t \u2208 \ud835\udcdd[s] x), lipschitz_on_with C f t) :\n  dimH (f '' s) \u2264 dimH s :=\nbegin\n  have : \u2200 x \u2208 s, \u2203 (C : \u211d\u22650) (t \u2208 \ud835\udcdd[s] x), holder_on_with C 1 f t,\n    by simpa only [holder_on_with_one] using hf,\n  simpa only [ennreal.coe_one, div_one]\n    using dimH_image_le_of_locally_holder_on zero_lt_one this\nend\n\n/-- If `f : X \u2192 Y` is Lipschitz in a neighborhood of each point `x : X`, then the Hausdorff\ndimension of `range f` is at most the Hausdorff dimension of `X`. -/\nlemma dimH_range_le_of_locally_lipschitz_on [second_countable_topology X] {f : X \u2192 Y}\n  (hf : \u2200 x : X, \u2203 (C : \u211d\u22650) (s \u2208 \ud835\udcdd x), lipschitz_on_with C f s) :\n  dimH (range f) \u2264 dimH (univ : set X) :=\nbegin\n  rw \u2190 image_univ,\n  refine dimH_image_le_of_locally_lipschitz_on (\u03bb x _, _),\n  simpa only [exists_prop, nhds_within_univ] using hf x\nend\n\nnamespace antilipschitz_with\n\nlemma dimH_preimage_le (hf : antilipschitz_with K f) (s : set Y) :\n  dimH (f \u207b\u00b9' s) \u2264 dimH s :=\nbegin\n  borelize [X, Y],\n  refine dimH_le (\u03bb d hd, le_dimH_of_hausdorff_measure_eq_top _),\n  have := hf.hausdorff_measure_preimage_le d.coe_nonneg s,\n  rw [hd, top_le_iff] at this,\n  contrapose! this,\n  exact ennreal.mul_ne_top (by simp) this\nend\n\nlemma le_dimH_image (hf : antilipschitz_with K f) (s : set X) :\n  dimH s \u2264 dimH (f '' s) :=\ncalc dimH s \u2264 dimH (f \u207b\u00b9' (f '' s)) : dimH_mono (subset_preimage_image _ _)\n        ... \u2264 dimH (f '' s)         : hf.dimH_preimage_le _\n\nend antilipschitz_with\n\n/-!\n### Isometries preserve Hausdorff dimension\n-/\n\nlemma isometry.dimH_image (hf : isometry f) (s : set X) : dimH (f '' s) = dimH s :=\nle_antisymm (hf.lipschitz.dimH_image_le _) (hf.antilipschitz.le_dimH_image _)\n\nnamespace isometry_equiv\n\n@[simp] lemma dimH_image (e : X \u2243\u1d62 Y) (s : set X) : dimH (e '' s) = dimH s :=\ne.isometry.dimH_image s\n\n@[simp] lemma dimH_preimage (e : X \u2243\u1d62 Y) (s : set Y) : dimH (e \u207b\u00b9' s) = dimH s :=\nby rw [\u2190 e.image_symm, e.symm.dimH_image]\n\nlemma dimH_univ (e : X \u2243\u1d62 Y) : dimH (univ : set X) = dimH (univ : set Y) :=\nby rw [\u2190 e.dimH_preimage univ, preimage_univ]\n\nend isometry_equiv\n\nnamespace continuous_linear_equiv\n\nvariables {\ud835\udd5c E F : Type*} [nontrivially_normed_field \ud835\udd5c]\n  [normed_add_comm_group E] [normed_space \ud835\udd5c E] [normed_add_comm_group F] [normed_space \ud835\udd5c F]\n\n@[simp] lemma dimH_image (e : E \u2243L[\ud835\udd5c] F) (s : set E) : dimH (e '' s) = dimH s :=\nle_antisymm (e.lipschitz.dimH_image_le s) $\n  by simpa only [e.symm_image_image] using e.symm.lipschitz.dimH_image_le (e '' s)\n\n@[simp] lemma dimH_preimage (e : E \u2243L[\ud835\udd5c] F) (s : set F) : dimH (e \u207b\u00b9' s) = dimH s :=\nby rw [\u2190 e.image_symm_eq_preimage, e.symm.dimH_image]\n\nlemma dimH_univ (e : E \u2243L[\ud835\udd5c] F) : dimH (univ : set E) = dimH (univ : set F) :=\nby rw [\u2190 e.dimH_preimage, preimage_univ]\n\nend continuous_linear_equiv\n\n/-!\n### Hausdorff dimension in a real vector space\n-/\n\nnamespace real\n\nvariables {E : Type*} [fintype \u03b9] [normed_add_comm_group E] [normed_space \u211d E]\n  [finite_dimensional \u211d E]\n\ntheorem dimH_ball_pi (x : \u03b9 \u2192 \u211d) {r : \u211d} (hr : 0 < r) :\n  dimH (metric.ball x r) = fintype.card \u03b9 :=\nbegin\n  casesI is_empty_or_nonempty \u03b9,\n  { rwa [dimH_subsingleton, eq_comm, nat.cast_eq_zero, fintype.card_eq_zero_iff],\n    exact \u03bb x _ y _, subsingleton.elim x y },\n  { rw \u2190 ennreal.coe_nat,\n    have : \u03bcH[fintype.card \u03b9] (metric.ball x r) = ennreal.of_real ((2 * r) ^ fintype.card \u03b9),\n      by rw [hausdorff_measure_pi_real, real.volume_pi_ball _ hr],\n    refine dimH_of_hausdorff_measure_ne_zero_ne_top _ _; rw [nnreal.coe_nat_cast, this],\n    { simp [pow_pos (mul_pos (zero_lt_two' \u211d) hr)] },\n    { exact ennreal.of_real_ne_top } }\nend\n\ntheorem dimH_ball_pi_fin {n : \u2115} (x : fin n \u2192 \u211d) {r : \u211d} (hr : 0 < r) :\n  dimH (metric.ball x r) = n :=\nby rw [dimH_ball_pi x hr, fintype.card_fin]\n\ntheorem dimH_univ_pi (\u03b9 : Type*) [fintype \u03b9] : dimH (univ : set (\u03b9 \u2192 \u211d)) = fintype.card \u03b9 :=\nby simp only [\u2190 metric.Union_ball_nat_succ (0 : \u03b9 \u2192 \u211d), dimH_Union,\n  dimH_ball_pi _ (nat.cast_add_one_pos _), supr_const]\n\ntheorem dimH_univ_pi_fin (n : \u2115) : dimH (univ : set (fin n \u2192 \u211d)) = n :=\nby rw [dimH_univ_pi, fintype.card_fin]\n\ntheorem dimH_of_mem_nhds {x : E} {s : set E} (h : s \u2208 \ud835\udcdd x) :\n  dimH s = finrank \u211d E :=\nbegin\n  have e : E \u2243L[\u211d] (fin (finrank \u211d E) \u2192 \u211d),\n    from continuous_linear_equiv.of_finrank_eq (finite_dimensional.finrank_fin_fun \u211d).symm,\n  rw \u2190 e.dimH_image,\n  refine le_antisymm _ _,\n  { exact (dimH_mono (subset_univ _)).trans_eq (dimH_univ_pi_fin _) },\n  { have : e '' s \u2208 \ud835\udcdd (e x), by { rw \u2190 e.map_nhds_eq, exact image_mem_map h },\n    rcases metric.nhds_basis_ball.mem_iff.1 this with \u27e8r, hr0, hr\u27e9,\n    simpa only [dimH_ball_pi_fin (e x) hr0] using dimH_mono hr }\nend\n\ntheorem dimH_of_nonempty_interior {s : set E} (h : (interior s).nonempty) :\n  dimH s = finrank \u211d E :=\nlet \u27e8x, hx\u27e9 := h in dimH_of_mem_nhds (mem_interior_iff_mem_nhds.1 hx)\n\nvariable (E)\n\ntheorem dimH_univ_eq_finrank : dimH (univ : set E) = finrank \u211d E :=\ndimH_of_mem_nhds (@univ_mem _ (\ud835\udcdd 0))\n\ntheorem dimH_univ : dimH (univ : set \u211d) = 1 :=\nby rw [dimH_univ_eq_finrank \u211d, finite_dimensional.finrank_self, nat.cast_one]\n\nend real\n\nvariables {E F : Type*}\n  [normed_add_comm_group E] [normed_space \u211d E] [finite_dimensional \u211d E]\n  [normed_add_comm_group F] [normed_space \u211d F]\n\ntheorem dense_compl_of_dimH_lt_finrank {s : set E} (hs : dimH s < finrank \u211d E) : dense s\u1d9c :=\nbegin\n  refine \u03bb x, mem_closure_iff_nhds.2 (\u03bb t ht, nonempty_iff_ne_empty.2 $ \u03bb he, hs.not_le _),\n  rw [\u2190 diff_eq, diff_eq_empty] at he,\n  rw [\u2190 real.dimH_of_mem_nhds ht],\n  exact dimH_mono he\nend\n\n/-!\n### Hausdorff dimension and `C\u00b9`-smooth maps\n\n`C\u00b9`-smooth maps are locally Lipschitz continuous, hence they do not increase the Hausdorff\ndimension of sets.\n-/\n\n/-- Let `f` be a function defined on a finite dimensional real normed space. If `f` is `C\u00b9`-smooth\non a convex set `s`, then the Hausdorff dimension of `f '' s` is less than or equal to the Hausdorff\ndimension of `s`.\n\nTODO: do we actually need `convex \u211d s`? -/\nlemma cont_diff_on.dimH_image_le {f : E \u2192 F} {s t : set E} (hf : cont_diff_on \u211d 1 f s)\n  (hc : convex \u211d s) (ht : t \u2286 s) :\n  dimH (f '' t) \u2264 dimH t :=\ndimH_image_le_of_locally_lipschitz_on $ \u03bb x hx,\n  let \u27e8C, u, hu, hf\u27e9 := (hf x (ht hx)).exists_lipschitz_on_with hc\n  in \u27e8C, u, nhds_within_mono _ ht hu, hf\u27e9\n\n/-- The Hausdorff dimension of the range of a `C\u00b9`-smooth function defined on a finite dimensional\nreal normed space is at most the dimension of its domain as a vector space over `\u211d`. -/\nlemma cont_diff.dimH_range_le {f : E \u2192 F} (h : cont_diff \u211d 1 f) :\n  dimH (range f) \u2264 finrank \u211d E :=\ncalc dimH (range f) = dimH (f '' univ) : by rw image_univ\n... \u2264 dimH (univ : set E) : h.cont_diff_on.dimH_image_le convex_univ subset.rfl\n... = finrank \u211d E : real.dimH_univ_eq_finrank E\n\n/-- A particular case of Sard's Theorem. Let `f : E \u2192 F` be a map between finite dimensional real\nvector spaces. Suppose that `f` is `C\u00b9` smooth on a convex set `s` of Hausdorff dimension strictly\nless than the dimension of `F`. Then the complement of the image `f '' s` is dense in `F`. -/\nlemma cont_diff_on.dense_compl_image_of_dimH_lt_finrank [finite_dimensional \u211d F] {f : E \u2192 F}\n  {s t : set E} (h : cont_diff_on \u211d 1 f s) (hc : convex \u211d s) (ht : t \u2286 s)\n  (htF : dimH t < finrank \u211d F) :\n  dense (f '' t)\u1d9c :=\ndense_compl_of_dimH_lt_finrank $ (h.dimH_image_le hc ht).trans_lt htF\n\n/-- A particular case of Sard's Theorem. If `f` is a `C\u00b9` smooth map from a real vector space to a\nreal vector space `F` of strictly larger dimension, then the complement of the range of `f` is dense\nin `F`. -/\nlemma cont_diff.dense_compl_range_of_finrank_lt_finrank [finite_dimensional \u211d F] {f : E \u2192 F}\n  (h : cont_diff \u211d 1 f) (hEF : finrank \u211d E < finrank \u211d F) :\n  dense (range f)\u1d9c :=\ndense_compl_of_dimH_lt_finrank $ h.dimH_range_le.trans_lt $ nat.cast_lt.2 hEF\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/metric_space/hausdorff_dimension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7318356687907815}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport number_theory.lucas_lehmer\n\n/-!\n# Explicit Mersenne primes\n\nWe run some Lucas-Lehmer tests to prove some Mersenne primes are prime.\n\nSee the discussion at the end of [src/number_theory/lucas_lehmer.lean]\nfor ideas about extending this to larger Mersenne primes.\n-/\n\nexample : (mersenne 13).prime :=\nlucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\nexample : (mersenne 17).prime :=\nlucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\nexample : (mersenne 19).prime :=\nlucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n\n/-- 2147483647.prime, Euler (1772) -/\nexample : (mersenne 31).prime :=\nlucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n\n/-!\nThe next four primality tests are too slow to run interactively with -T100000,\nbut work fine on the command line.\n-/\n\n-- /-- 2305843009213693951.prime, Pervouchine (1883), Seelhoff (1886) -/\n-- example : (mersenne 61).prime :=\n-- lucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n-- /-- 618970019642690137449562111.prime, Powers (1911) -/\n-- -- takes ~100s\n-- example : (mersenne 89).prime :=\n-- lucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n-- /-- 162259276829213363391578010288127.prime, Power (1914) -/\n-- -- takes ~190s\n-- example : (mersenne 107).prime :=\n-- lucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n-- /-- 170141183460469231731687303715884105727.prime, Lucas (1876) -/\n-- -- takes ~370s\n-- example : (mersenne 127).prime :=\n-- lucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n\n/- This still doesn't get us over the big gap and into the computer era, unfortunately. -/\n\n-- /-- (2^521 - 1).prime, Robinson (1954) -/\n-- -- This has not been run successfully!\n-- example : (mersenne 521).prime :=\n-- lucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/examples/mersenne_primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7318356649163689}}
{"text": "import tactic\nvariables P Q : Prop \n\nopen_locale classical\n\n-- BEGIN\nexample (P Q : Prop) : (P \u2192 Q) \u2194 \u00ac P \u2228 Q :=\nbegin\n  split,\n    intro hpq,\n      by_contra h',\n      push_neg at h',\n      cases h' with h'p h'nq,\n      apply h'nq (hpq (h'p)),\n    intros hnpq hp,\n      cases hnpq with hnp hq,\n      contradiction,\n      exact hq,\nend\n\n/- using the by_cases tactic -/\nexample (P Q : Prop) : (P \u2192 Q) \u2194 \u00ac P \u2228 Q :=\nbegin\n  split, \n    intro hpq,\n      by_cases h : P,\n        right, \n          exact hpq h,\n        left, \n          exact h, \n    intros hnpq hp,\n      cases hnpq with hnp hq,\n        contradiction,\n        exact hq,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.2_cases_conjunc/ex3_cases_not_p_or_q.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7318356563306513}}
{"text": "variable (p q r : Prop)\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := \n  Iff.intro\n    (fun hpq : p \u2227 q =>\n      \u27e8hpq.right, hpq.left\u27e9 \n    )\n    (fun hqp : q \u2227 p =>\n      \u27e8hqp.right, hqp.left\u27e9\n    )\n\nexample : p \u2228 q \u2194 q \u2228 p :=\n  Iff.intro\n    (fun hpq : p \u2228 q =>\n      Or.elim\n        hpq\n        (fun hp : p => Or.intro_right q hp)\n        (fun hq : q => Or.intro_left p hq)\n    )\n    (fun hqp : q \u2228 p =>\n      Or.elim\n        hqp\n        (fun hq : q => Or.intro_right p hq)\n        (fun hp : p => Or.intro_left q hp)\n    )\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n    Iff.intro\n      (fun itz : (p \u2227 q) \u2227 r => \u27e8itz.left.left, itz.left.right, itz.right\u27e9)\n      (fun itz : p \u2227 (q \u2227 r) => \u27e8\u27e8itz.left, itz.right.left\u27e9, itz.right.right\u27e9)\n\n   \nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := \n    Iff.intro\n      (fun lbrack : (p \u2228 q) \u2228 r =>\n        Or.elim\n          lbrack\n          (fun hpq : p \u2228 q =>\n            Or.elim\n              hpq\n              (fun hp : p => Or.intro_left (q \u2228 r) hp)\n              (fun hq : q => Or.intro_right p (Or.intro_left r hq))\n          )\n          (fun hr : r => Or.intro_right p (Or.intro_right q hr))\n      )\n      (fun rbrack : p \u2228 (q \u2228 r) =>\n        Or.elim\n          rbrack\n          (fun hp : p => Or.intro_left r (Or.intro_left q hp))\n          (fun hqr : q \u2228 r =>\n            Or.elim\n            hqr\n            (fun hq : q => Or.intro_left r (Or.intro_right p hq))\n            (fun hr : r => Or.intro_right (p \u2228 q) hr)\n          )\n      )\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := \n    Iff.intro\n      (fun hyp : p \u2227 (q \u2228 r) =>\n        Or.elim\n          hyp.right\n          (fun hq : q => Or.intro_left (p \u2227 r) \u27e8hyp.left, hq\u27e9)\n          (fun hr : r => Or.intro_right (p \u2227 q) \u27e8hyp.left, hr\u27e9)\n      )\n      (fun hyp : (p \u2227 q) \u2228 (p \u2227 r) =>\n        Or.elim\n          hyp\n          (fun hpq : p \u2227 q => And.intro hpq.left (Or.intro_left r hpq.right))\n          (fun hpr : p \u2227 r => And.intro hpr.left (Or.intro_right q hpr.right))\n      )\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n    Iff.intro\n      (fun hyp : p \u2228 (q \u2227 r) =>\n        Or.elim\n          hyp\n          (fun hp : p => And.intro (Or.intro_left q hp) (Or.intro_left r hp))\n          (fun hqr : q \u2227 r => And.intro (Or.intro_right p hqr.left) (Or.intro_right p hqr.right))\n      )\n      (fun hyp : (p \u2228 q) \u2227 (p \u2228 r) =>\n        Or.elim\n          hyp.left\n          (fun hp : p => Or.intro_left (q \u2227 r) hp)\n          (fun hq : q =>\n            Or.elim\n              hyp.right\n              (fun hp : p => Or.intro_left (q \u2227 r) hp)\n              (fun hr : r => Or.intro_right p \u27e8hq, hr\u27e9)\n          )\n      )\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n    Iff.intro\n      (fun hpqr : p \u2192 (q \u2192 r) =>\n        fun hpq : p \u2227 q =>\n          hpqr hpq.left hpq.right \n      )\n      (fun hpqr : p \u2227 q \u2192 r =>\n        fun hp : p =>\n          fun hq : q =>\n            hpqr \u27e8hp, hq\u27e9    \n      )\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := \n    Iff.intro\n      (fun hpqr : (p \u2228 q) \u2192 r =>\n        And.intro\n          (fun hp : p => hpqr (Or.intro_left q hp))\n          (fun hq : q => hpqr (Or.intro_right p hq))\n      )\n      (fun conj : (p \u2192 r) \u2227 (q \u2192 r) =>\n        fun disj : p \u2228 q =>\n          Or.elim\n            disj\n            (fun hp : p => conj.left hp)\n            (fun hq : q => conj.right hq)\n      )\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n    Iff.intro\n      (fun hpq : \u00ac(p \u2228 q) =>\n        And.intro\n          (fun hp : p =>\n            show False from hpq (Or.intro_left q hp)\n          )\n          (fun hq : q =>\n            show False from hpq (Or.intro_right p hq)\n          )\n      )\n      (fun hpq : \u00acp \u2227 \u00acq =>\n        (fun disj : p \u2228 q =>\n          show False from\n            Or.elim\n             disj\n             (fun hp : p => hpq.left hp)\n             (fun hq : q => hpq.right hq)\n        )\n      )\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n    fun hpq : \u00acp \u2228 \u00acq =>\n      Or.elim\n        hpq\n        (fun hp : \u00acp =>\n          fun hpq : p \u2227 q =>\n            show False from hp hpq.left\n        )\n        (fun hq : \u00acq =>\n          fun hpq : p \u2227 q =>\n            show False from hq hpq.right \n        )\n\nexample : \u00ac(p \u2227 \u00acp) :=\n    fun nonc : p \u2227 \u00acp =>\n      show False from nonc.right nonc.left\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n    fun hpq : p \u2227 \u00acq =>\n      fun con : p \u2192 q =>\n        show False from hpq.right (con hpq.left)\n\nexample : \u00acp \u2192 (p \u2192 q) :=\n    fun hnp : \u00acp =>\n      fun hp : p =>\n        False.elim (hnp hp)\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n    fun hpq : \u00acp \u2228 q =>\n      Or.elim\n        hpq\n        (fun hnp : \u00acp => (fun hp : p => False.elim (hnp hp)))\n        (fun hq : q => (fun p => hq))\n\nexample : p \u2228 False \u2194 p :=\n    Iff.intro\n      (fun hpf : p \u2228 False =>\n        Or.elim\n          hpf\n          (fun p => p)\n          (fun False => False.elim)\n      )\n      (fun hp : p => Or.intro_left False hp)\n\nexample : p \u2227 False \u2194 False :=\n    Iff.intro\n      (fun hpf : p \u2227 False => hpf.right)\n      (fun False => False.elim)\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n  fun hpq : p \u2192 q =>\n    fun hnq : \u00acq =>\n      fun hp : p => show False from hnq (hpq hp)", "meta": {"author": "Pasarel", "repo": "lean-warmup", "sha": "abddd28c30cb2d0e16229979769d72a00d179d09", "save_path": "github-repos/lean/Pasarel-lean-warmup", "path": "github-repos/lean/Pasarel-lean-warmup/lean-warmup-abddd28c30cb2d0e16229979769d72a00d179d09/Proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7318356507282552}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Neil Strickland\n\n! This file was ported from Lean 3 source module data.pnat.defs\n! leanprover-community/mathlib commit c4658a649d216f57e99621708b09dcb3dcccbd23\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\n\nimport Mathlib.Algebra.NeZero\nimport Mathlib.Data.Nat.Cast.Defs\nimport Mathlib.Order.Basic\nimport Mathlib.Tactic.Coe\nimport Mathlib.Tactic.Lift\n\n/-!\n# The positive natural numbers\n\nThis file contains the definitions, and basic results.\nMost algebraic facts are deferred to `Data.PNat.Basic`, as they need more imports.\n-/\n\n\n/-- `\u2115+` is the type of positive natural numbers. It is defined as a subtype,\n  and the VM representation of `\u2115+` is the same as `\u2115` because the proof\n  is not stored. -/\ndef PNat := { n : \u2115 // 0 < n }\n  deriving DecidableEq, LinearOrder\n#align pnat PNat\n\n@[inherit_doc]\nnotation \"\u2115+\" => PNat\n\ninstance : One \u2115+ :=\n  \u27e8\u27e81, Nat.zero_lt_one\u27e9\u27e9\n\n/-- The underlying natural number -/\n@[coe]\ndef PNat.val : \u2115+ \u2192 \u2115 := Subtype.val\n\ninstance coePNatNat : Coe \u2115+ \u2115 :=\n  \u27e8PNat.val\u27e9\n#align coe_pnat_nat coePNatNat\n\ninstance : Repr \u2115+ :=\n  \u27e8fun n n' => reprPrec n.1 n'\u27e9\n\n--Porting note: New instance not in Lean3\ninstance (n : \u2115) : OfNat \u2115+ (n+1) :=\n  \u27e8\u27e8n + 1, Nat.succ_pos n\u27e9\u27e9\n\nnamespace PNat\n\n-- Note: similar to Subtype.coe_mk\n@[simp]\ntheorem mk_coe (n h) : (PNat.val (\u27e8n, h\u27e9 : \u2115+) : \u2115) = n :=\n  rfl\n#align pnat.mk_coe PNat.mk_coe\n\n/-- Predecessor of a `\u2115+`, as a `\u2115`. -/\ndef natPred (i : \u2115+) : \u2115 :=\n  i - 1\n#align pnat.nat_pred PNat.natPred\n\n@[simp]\n\n\nend PNat\n\nnamespace Nat\n\n/-- Convert a natural number to a positive natural number. The\n  positivity assumption is inferred by `dec_trivial`. -/\ndef toPNat (n : \u2115) (h : 0 < n := by decide) : \u2115+ :=\n  \u27e8n, h\u27e9\n#align nat.to_pnat Nat.toPNat\n\n/-- Write a successor as an element of `\u2115+`. -/\ndef succPNat (n : \u2115) : \u2115+ :=\n  \u27e8succ n, succ_pos n\u27e9\n#align nat.succ_pnat Nat.succPNat\n\n@[simp]\ntheorem succPNat_coe (n : \u2115) : (succPNat n : \u2115) = succ n :=\n  rfl\n#align nat.succ_pnat_coe Nat.succPNat_coe\n\n@[simp]\ntheorem natPred_succPNat (n : \u2115) : n.succPNat.natPred = n :=\n  rfl\n#align nat.nat_pred_succ_pnat Nat.natPred_succPNat\n\n@[simp]\ntheorem _root_.PNat.succPNat_natPred (n : \u2115+) : n.natPred.succPNat = n :=\n  Subtype.eq <| succ_pred_eq_of_pos n.2\n#align pnat.succ_pnat_nat_pred PNat.succPNat_natPred\n\n/-- Convert a natural number to a `PNat`. `n+1` is mapped to itself,\n  and `0` becomes `1`. -/\ndef toPNat' (n : \u2115) : \u2115+ :=\n  succPNat (pred n)\n#align nat.to_pnat' Nat.toPNat'\n\n@[simp]\ntheorem toPNat'_coe : \u2200 n : \u2115, (toPNat' n : \u2115) = ite (0 < n) n 1\n  | 0 => rfl\n  | m + 1 => by\n    rw [if_pos (succ_pos m)]\n    rfl\n#align nat.to_pnat'_coe Nat.toPNat'_coe\n\nend Nat\n\nnamespace PNat\n\nopen Nat\n\n/-- We now define a long list of structures on \u2115+ induced by\n similar structures on \u2115. Most of these behave in a completely\n obvious way, but there are a few things to be said about\n subtraction, division and powers.\n-/\n-- Porting note: no `simp`  because simp can prove it\ntheorem mk_le_mk (n k : \u2115) (hn : 0 < n) (hk : 0 < k) : (\u27e8n, hn\u27e9 : \u2115+) \u2264 \u27e8k, hk\u27e9 \u2194 n \u2264 k :=\n  Iff.rfl\n#align pnat.mk_le_mk PNat.mk_le_mk\n\n-- Porting note: no `simp`  because simp can prove it\ntheorem mk_lt_mk (n k : \u2115) (hn : 0 < n) (hk : 0 < k) : (\u27e8n, hn\u27e9 : \u2115+) < \u27e8k, hk\u27e9 \u2194 n < k :=\n  Iff.rfl\n#align pnat.mk_lt_mk PNat.mk_lt_mk\n\n@[simp, norm_cast]\ntheorem coe_le_coe (n k : \u2115+) : (n : \u2115) \u2264 k \u2194 n \u2264 k :=\n  Iff.rfl\n#align pnat.coe_le_coe PNat.coe_le_coe\n\n@[simp, norm_cast]\ntheorem coe_lt_coe (n k : \u2115+) : (n : \u2115) < k \u2194 n < k :=\n  Iff.rfl\n#align pnat.coe_lt_coe PNat.coe_lt_coe\n\n@[simp]\ntheorem pos (n : \u2115+) : 0 < (n : \u2115) :=\n  n.2\n#align pnat.pos PNat.pos\n\ntheorem eq {m n : \u2115+} : (m : \u2115) = n \u2192 m = n :=\n  Subtype.eq\n#align pnat.eq PNat.eq\n\ntheorem coe_injective : Function.Injective (fun (a : \u2115+) => (a : \u2115)) :=\n  Subtype.coe_injective\n#align pnat.coe_injective PNat.coe_injective\n\n@[simp]\ntheorem ne_zero (n : \u2115+) : (n : \u2115) \u2260 0 :=\n  n.2.ne'\n#align pnat.ne_zero PNat.ne_zero\n\ninstance _root_.NeZero.pnat {a : \u2115+} : NeZero (a : \u2115) :=\n  \u27e8a.ne_zero\u27e9\n#align ne_zero.pnat NeZero.pnat\n\ntheorem toPNat'_coe {n : \u2115} : 0 < n \u2192 (n.toPNat' : \u2115) = n :=\n  succ_pred_eq_of_pos\n#align pnat.to_pnat'_coe PNat.toPNat'_coe\n\n@[simp]\ntheorem coe_toPNat' (n : \u2115+) : (n : \u2115).toPNat' = n :=\n  eq (toPNat'_coe n.pos)\n#align pnat.coe_to_pnat' PNat.coe_toPNat'\n\n@[simp]\ntheorem one_le (n : \u2115+) : (1 : \u2115+) \u2264 n :=\n  n.2\n#align pnat.one_le PNat.one_le\n\n@[simp]\ntheorem not_lt_one (n : \u2115+) : \u00acn < 1 :=\n  not_lt_of_le n.one_le\n#align pnat.not_lt_one PNat.not_lt_one\n\ninstance : Inhabited \u2115+ :=\n  \u27e81\u27e9\n\n-- Some lemmas that rewrite `PNat.mk n h`, for `n` an explicit numeral, into explicit numerals.\n@[simp]\ntheorem mk_one {h} : (\u27e81, h\u27e9 : \u2115+) = (1 : \u2115+) :=\n  rfl\n#align pnat.mk_one PNat.mk_one\n\n@[simp, norm_cast]\ntheorem one_coe : ((1 : \u2115+) : \u2115) = 1 :=\n  rfl\n#align pnat.one_coe PNat.one_coe\n\n@[simp, norm_cast]\ntheorem coe_eq_one_iff {m : \u2115+} : (m : \u2115) = 1 \u2194 m = 1 :=\n  Subtype.coe_injective.eq_iff' one_coe\n#align pnat.coe_eq_one_iff PNat.coe_eq_one_iff\n\ninstance : WellFoundedRelation \u2115+ :=\n  measure (fun (a : \u2115+) => (a : \u2115))\n\n/-- Strong induction on `\u2115+`. -/\ndef strongInductionOn {p : \u2115+ \u2192 Sort _} (n : \u2115+) : (\u2200 k, (\u2200 m, m < k \u2192 p m) \u2192 p k) \u2192 p n\n  | IH => IH _ fun a _ => strongInductionOn a IH\ntermination_by _ => n.1\n\n#align pnat.strong_induction_on PNat.strongInductionOn\n\n/-- We define `m % k` and `m / k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` and\n  `m / k = n - 1`.  This ensures that `m % k` is always positive\n  and `m = (m % k) + k * (m / k)` in all cases.  Later we\n  define a function `div_exact` which gives the usual `m / k`\n  in the case where `k` divides `m`.\n-/\ndef modDivAux : \u2115+ \u2192 \u2115 \u2192 \u2115 \u2192 \u2115+ \u00d7 \u2115\n  | k, 0, q => \u27e8k, q.pred\u27e9\n  | _, r + 1, q => \u27e8\u27e8r + 1, Nat.succ_pos r\u27e9, q\u27e9\n#align pnat.mod_div_aux PNat.modDivAux\n\n/-- `mod_div m k = (m % k, m / k)`.\n  We define `m % k` and `m / k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` and\n  `m / k = n - 1`.  This ensures that `m % k` is always positive\n  and `m = (m % k) + k * (m / k)` in all cases.  Later we\n  define a function `div_exact` which gives the usual `m / k`\n  in the case where `k` divides `m`.\n-/\ndef modDiv (m k : \u2115+) : \u2115+ \u00d7 \u2115 :=\n  modDivAux k ((m : \u2115) % (k : \u2115)) ((m : \u2115) / (k : \u2115))\n#align pnat.mod_div PNat.modDiv\n\n/-- We define `m % k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` This ensures that `m % k` is always positive.\n-/\ndef mod (m k : \u2115+) : \u2115+ :=\n  (modDiv m k).1\n#align pnat.mod PNat.mod\n\n/-- We define `m / k` in the same way as for `\u2115` except that when `m = n * k` we take\n  `m / k = n - 1`. This ensures that `m = (m % k) + k * (m / k)` in all cases. Later we\n  define a function `div_exact` which gives the usual `m / k` in the case where `k` divides `m`.\n-/\ndef div (m k : \u2115+) : \u2115 :=\n  (modDiv m k).2\n#align pnat.div PNat.div\n\ntheorem mod_coe (m k : \u2115+) :\n  (mod m k : \u2115) = ite ((m : \u2115) % (k : \u2115) = 0) (k : \u2115) ((m : \u2115) % (k : \u2115)) := by\n  dsimp [mod, modDiv]\n  cases (m : \u2115) % (k : \u2115) with\n  | zero =>\n    rw [if_pos rfl]\n    rfl\n\n  | succ n =>\n    rw [if_neg n.succ_ne_zero]\n    rfl\n\n#align pnat.mod_coe PNat.mod_coe\n\ntheorem div_coe (m k : \u2115+) :\n  (div m k : \u2115) = ite ((m : \u2115) % (k : \u2115) = 0) ((m : \u2115) / (k : \u2115)).pred ((m : \u2115) / (k : \u2115)) := by\n  dsimp [div, modDiv]\n  cases (m : \u2115) % (k : \u2115) with\n  | zero =>\n    rw [if_pos rfl]\n    rfl\n\n  | succ n =>\n    rw [if_neg n.succ_ne_zero]\n    rfl\n\n#align pnat.div_coe PNat.div_coe\n\n/-- If `h : k | m`, then `k * (div_exact m k) = m`. Note that this is not equal to `m / k`. -/\ndef divExact (m k : \u2115+) : \u2115+ :=\n  \u27e8(div m k).succ, Nat.succ_pos _\u27e9\n#align pnat.div_exact PNat.divExact\n\nend PNat\n\nsection CanLift\n\ninstance Nat.canLiftPNat : CanLift \u2115 \u2115+ (\u2191) (fun n => 0 < n) :=\n  \u27e8fun n hn => \u27e8Nat.toPNat' n, PNat.toPNat'_coe hn\u27e9\u27e9\n#align nat.can_lift_pnat Nat.canLiftPNat\n\ninstance Int.canLiftPNat : CanLift \u2124 \u2115+ (\u2191) ((0 < \u00b7)) :=\n  \u27e8fun n hn =>\n    \u27e8Nat.toPNat' (Int.natAbs n), by\n      rw [Nat.toPNat'_coe, if_pos (Int.natAbs_pos.2 hn.ne'),\n        Int.natAbs_of_nonneg hn.le]\u27e9\u27e9\n#align int.can_lift_pnat Int.canLiftPNat\n\nend CanLift\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/PNat/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7318303804028519}}
{"text": "-- \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435\n\nexample : \u2203 x : \u2115, x > 0 :=                     -- \u0441 \u043c\u0435\u0441\u0442\u0430 \u0432 \u043a\u0430\u0440\u044c\u0435\u0440 \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 (\\exists \u0434\u043b\u044f \u2203) \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \n  have h : 1 > 0, from nat.zero_lt_succ 0,      -- \u0431\u043e\u043b\u044c\u0448\u0435 0 \u043f\u0440\u0435\u0434\u044a\u044f\u0432\u0438\u043c 1, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f \u043f\u043e \u0432\u0435\u043b\u0438\u043a\u043e\u0439 \u043b\u0435\u043c\u043c\u0435 zero_lt_one\n  show \u2203 x : \u2115, x > 0, from exists.intro 1 h    -- \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e exists.intro \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0438\u0437 h \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\n\n#check (\u27e81, zero_lt_one\u27e9 : \u2203 x : \u2115, x > 0)      -- \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043b\u044f exists.intro a b \u2014 \u27e8a, b\u27e9\n\n#check @exists.intro -- \u2200 {\u03b1 : Type u} {p : \u03b1 \u2192 Prop} (w : \u03b1), p w \u2192 Exists p\n                                                -- \u044d\u0442\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 Exists p \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \n                                                -- \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c p \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f\n                                                \nvariable g : \u2115 \u2192 \u2115 \u2192 \u2115                          -- \u0432 \u0437\u0430\u043f\u0438\u0441\u0435 exists.intro \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 {p : \u03b1 \u2192 Prop},\nvariable hg : g 0 0 = 0                         -- \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\n\nset_option pp.implicit true                     -- \u043f\u043e\u043a\u0430\u0437 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438 \u043f\u0435\u0447\u0430\u0442\u0438\n\ntheorem gex1 : \u2203 x, g x x = x := \u27e80, hg\u27e9        -- p = \u03bb (x : \u2115), g x x = x\n#print gex1\n\ntheorem gex2 : \u2203 x, g x 0 = x := \u27e80, hg\u27e9        -- p = \u03bb (x : \u2115), g x 0 = x\n#print gex2\n\ntheorem gex3 : \u2203 x, g 0 0 = x := \u27e80, hg\u27e9        -- p = \u03bb (x : \u2115), g 0 0 = x\n#print gex3\n\ntheorem gex4 : \u2203 x, g x x = 0 := \u27e80, hg\u27e9        -- p = \u03bb (x : \u2115), g x x = 0\n#print gex4\n\n#check @Exists -- \u03a0 {\u03b1 : Type u}, (\u03b1 \u2192 Prop) \u2192 Prop\n                                                -- \u0442\u0438\u043f \u0441\u0430\u043c\u043e\u0433\u043e Exists \u043f\u043e\u043d\u044f\u0442\u0435\u043d: \u0438\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u0432 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438\n                                                -- \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0434\u0435\u043b\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0438\u0441\u0442\u0438\u043d\u044b\u043c\n                                                -- exists.intro \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u0442\u0438\u043f\u0430 Exists\n\nexample (x y z : \u2115)                             -- \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440\n        (hxy : x < y)                           -- \u0434\u0432\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 x, y \u0438 z \u0435\u0441\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a: x < y < z\n        (hyz : y < z) : \n        \u2203 w : \u2115, x < w \u2227 w < z :=               -- \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 w, \u0447\u0442\u043e \u043e\u043d \u043c\u0435\u0436\u0434\u0443 y \u0438 z\n  have x < y \u2227 y < z, from and.intro hxy hyz,   -- \u0442\u0430\u043a\u043e\u0439 w \u0435\u0441\u0442\u044c \u2013 \u044d\u0442\u043e \u0441\u0430\u043c y, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044f \u043a\u043e\u043d\u044a\u044e\u043d\u043a\u0446\u0438\u0435\u0439 \u0434\u0432\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\n  show \u2203 w : \u2115, x < w \u2227 w < z,                  -- \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0443\u0442\u0435\u043c \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f exists.intro\n    from exists.intro y this\n\nexample (x y z : \u2115)                             -- \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440 \u0434\u043b\u044f and.intro \u0438 exists.intro\n        (hxy : x < y)                           \n        (hyz : y < z) : \n        \u2203 w : \u2115, x < w \u2227 w < z := \n  have x < y \u2227 y < z, from \u27e8hxy, hyz\u27e9,          -- \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442 and\n  show \u2203 w : \u2115, x < w \u2227 w < z, from \u27e8y, this\u27e9   -- \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442 exists.intro (\u0438 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a :) )\n                                                -- \u043f\u0440\u0438 \u044d\u0442\u043e\u043c this = \u27e8hxy, hyz\u27e9, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u043e\u0436\u0435\u043c \u0435\u0449\u0435 \u0441\u0438\u043b\u044c\u043d\u0435\u0435 \u0443\u043a\u043e\u0440\u043e\u0442\u0438\u0442\u044c\n                                                -- \u043f\u0440\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a. \u2203 x : \u03b1, p x - \u044d\u0442\u043e \u0441\u0430\u0445\u0430\u0440 \u0434\u043b\u044f \u03a3 x : \u03b1, p x :)\n                                                -- \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 - \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0430\u044f \u043f\u0430\u0440\u0430 \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430\n\nexample (x y z : \u2115)                             \n        (hxy : x < y)                           \n        (hyz : y < z) : \n        \u2203 w : \u2115, x < w \u2227 w < z := \n  show \u2203 w : \u2115, x < w \u2227 w < z,                  -- show \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c, \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043b\u043e from\n    from \u27e8y, \u27e8hxy, hyz\u27e9\u27e9                        -- \u0441\u043a\u043e\u0431\u043a\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b, \u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c\n\nexample (x y z : \u2115)                             -- \u0432\u043e\u0442 \u0438 \u0432\u0441\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e\n        (hxy : x < y)                           \n        (hyz : y < z) : \n        \u2203 w : \u2115, x < w \u2227 w < z := \n  \u27e8y, hxy, hyz\u27e9\n\n-- \u0420\u0430\u0437\u0431\u043e\u0440 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f\n\nuniverse u\nvariable \u03b1 : Type u\nvariables p q : \u03b1 \u2192 Prop\n\nexample (h : \u2203 x : \u03b1, p x \u2227 q x) :              -- \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\n          \u2203 y : \u03b1, q y \u2227 p y :=\n  exists.elim h                                 -- exists.elim \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0443\u044e \u043f\u0430\u0440\u0443 \u043d\u0430 \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430,\n    (assume w : \u03b1,                              -- \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0442\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\n     assume hw : p w \u2227 q w,\n     show \u2203 y : \u03b1, q y \u2227 p y, from exists.intro w \u27e8hw.right, hw.left\u27e9)\n\n#check @exists.elim -- \u2200 {a : Type u} {p : \u03b1 \u2192 Prop} {b : Prop}\n                    --   (\u2203 x : \u03b1, p x) \u2192 (\u2200 a : \u03b1, p a \u2192 b) \u2192 b\n                    --                       |      |\n                    --                       |      +-- \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0430\u0440\u044b\n                    --                       +-- \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0430\u0440\u044b\n\nexample (h : \u2203 x : \u03b1, p x \u2227 q x) :              -- \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 pattern matching\n          \u2203 y : \u03b1, q y \u2227 p y :=                 -- \u043b\u044e\u0431\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u044d\u0442\u0447\u0438\u0442\u044c \u0441 \u043f\u0430\u0440\u043e\u0439\n  match h with \u27e8w, hw\u27e9 :=\n    exists.intro w \u27e8hw.right, hw.left\u27e9          -- \u0437\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u27e8w, hw.right, hw.left\u27e9\n  end\n\n-- \u043e\u0431\u0449\u0438\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 match:\n-- match {expr} with {pattern} :=\n--   {operations}\n-- end\n\nexample (h : \u2203 x : \u03b1, p x \u2227 q x) :              -- \u043f\u0440\u0438 pattern matching \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043d\u044a\u044e\u043d\u043a\u0446\u0438\u044e\n          \u2203 y : \u03b1, q y \u2227 p y :=\n  match h with \u27e8w, hwl, hwr\u27e9 :=\n    \u27e8w, hwr, hwl\u27e9\n  end\n\nexample (h : \u2203 x : \u03b1, p x \u2227 q x) :              -- \u0442\u0430\u043a\u0436\u0435 pattern matching \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u0440\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0438\n          \u2203 y : \u03b1, q y \u2227 p y :=\n  let \u27e8w, hwl, hwr\u27e9 := h in \u27e8w, hwr, hwl\u27e9\n\n-- \u041f\u0440\u0438\u043c\u0435\u0440 \u0442\u0435\u043e\u0440\u0435\u043c\u044b\n\ndef is_even (n : \u2115) : Prop :=\n  \u2203 b : \u2115, n = 2 * b\n\ntheorem even_plus_even {a b : \u2115}                -- \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0432\u0430 \u0447\u0435\u0442\u043d\u044b\u0445 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430\n                       (h\u2081 : is_even a)         -- \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0438\u0445 \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438\n                       (h\u2082 : is_even b) :\n                         is_even (a + b) :=     -- \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u044c \u0438\u0445 \u0441\u0443\u043c\u043c\u044b\n  exists.elim h\u2081                                -- \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430\n    (assume w\u2081  : \u2115,                            -- \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0435 w\u2081, \u0447\u0442\u043e a = 2 * w\u2081\n     assume hw\u2081 : a = 2 * w\u2081,\n     exists.elim h\u2082                             -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430\n       (assume w\u2082  : \u2115,                         -- \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0435 w\u2082, \u0447\u0442\u043e b = 2 * w\u2082\n        assume hw\u2082 : b = 2 * w\u2082,\n        exists.intro (w\u2081 + w\u2082)                  -- \u043f\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0435 (w\u2081 + w\u2082), \u0447\u0442\u043e a + b = 2 * (w\u2081 + w\u2082)\n          (calc\n            a + b = 2 * w\u2081 + 2 * w\u2082 : by rw [hw\u2081, hw\u2082]\n            ...   = 2 * (w\u2081 + w\u2082)   : by rw mul_add)\n       ))\n\ntheorem even_plus_even' {a b : \u2115}               -- \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0442\u043e \u0436\u0435, \u0447\u0435\u0440\u0435\u0437 pattern matching\n                        (h\u2081 : is_even a)         \n                        (h\u2082 : is_even b) :\n                          is_even (a + b) :=\n  match h\u2081, h\u2082 with                             -- \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u0448\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f\n    \u27e8w\u2081, hw\u2081\u27e9, \u27e8w\u2082, hw\u2082\u27e9 := \n      exists.intro  (w\u2081 + w\u2082)                   -- \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0438 \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0432 calc \u043a\u0430\u043a by rw [hw\u2081, hw\u2082, mul_add]\n        (calc\n          a + b = 2 * w\u2081 + 2 * w\u2082 : by rw [hw\u2081, hw\u2082]\n          ...   = 2 * (w\u2081 + w\u2082)   : by rw mul_add)\n  end", "meta": {"author": "zmactep", "repo": "llfgg", "sha": "ed684ae69b94a4a042615c412fef68bdec8fc80c", "save_path": "github-repos/lean/zmactep-llfgg", "path": "github-repos/lean/zmactep-llfgg/llfgg-ed684ae69b94a4a042615c412fef68bdec8fc80c/5_existential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952852648487, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7318303641009286}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.normed_space.basic\n\n/-!\n# Matrices as a normed space\n\nIn this file we provide the following non-instances on matrices, using the elementwise norm:\n\n* `matrix.semi_normed_group`\n* `matrix.normed_group`\n* `matrix.normed_space`\n\nThese are not declared as instances because there are several natural choices for defining the norm\nof a matrix.\n-/\n\nnoncomputable theory\n\nnamespace matrix\n\nvariables {R n m \u03b1 : Type*} [fintype n] [fintype m]\n\nsection semi_normed_group\nvariables [semi_normed_group \u03b1]\n\n/-- Seminormed group instance (using sup norm of sup norm) for matrices over a seminormed ring. Not\ndeclared as an instance because there are several natural choices for defining the norm of a\nmatrix. -/\nprotected def semi_normed_group : semi_normed_group (matrix n m \u03b1) :=\npi.semi_normed_group\n\nlocal attribute [instance] matrix.semi_normed_group\n\nlemma norm_le_iff {r : \u211d} (hr : 0 \u2264 r) {A : matrix n m \u03b1} :\n  \u2225A\u2225 \u2264 r \u2194 \u2200 i j, \u2225A i j\u2225 \u2264 r :=\nby simp [pi_norm_le_iff hr]\n\nlemma norm_lt_iff {r : \u211d} (hr : 0 < r) {A : matrix n m \u03b1} :\n  \u2225A\u2225 < r \u2194 \u2200 i j, \u2225A i j\u2225 < r :=\nby simp [pi_norm_lt_iff hr]\n\nlemma norm_entry_le_entrywise_sup_norm (A : matrix n m \u03b1) {i : n} {j : m} :\n  \u2225A i j\u2225 \u2264 \u2225A\u2225 :=\n(norm_le_pi_norm (A i) j).trans (norm_le_pi_norm A i)\n\nend semi_normed_group\n\n/-- Normed group instance (using sup norm of sup norm) for matrices over a normed ring.  Not\ndeclared as an instance because there are several natural choices for defining the norm of a\nmatrix. -/\nprotected def normed_group [normed_group \u03b1] : normed_group (matrix n m \u03b1) :=\npi.normed_group\n\n\nsection normed_space\nlocal attribute [instance] matrix.semi_normed_group\n\nvariables [normed_field R] [semi_normed_group \u03b1] [normed_space R \u03b1]\n\n/-- Normed space instance (using sup norm of sup norm) for matrices over a normed field.  Not\ndeclared as an instance because there are several natural choices for defining the norm of a\nmatrix. -/\nprotected def normed_space : normed_space R (matrix n m \u03b1) :=\npi.normed_space\n\nend normed_space\n\nend matrix\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7318303636344186}}
{"text": "import .basic\n\nnamespace vect\n\ndefinition is_all {\u03b1 : Type _} (p : \u03b1 \u2192 Prop) : \u2200 {n : \u2115}, vect \u03b1 n \u2192 Prop\n| _ \u2045\u2046 := true\n| _ (a \u223a as) := p a \u2227 is_all as\n\ndefinition is_any {\u03b1 : Type _} (p : \u03b1 \u2192 Prop) : \u2200 {n : \u2115}, vect \u03b1 n \u2192 Prop\n| _ \u2045\u2046 := false\n| _ (a \u223a as) := p a \u2228 is_any as\n\n--- All entries of `vect` of sybtype `subtype p` satisfy `p`\ntheorem is_all_subtype {\u03b1 : Type _} {p : \u03b1 \u2192 Prop} : \u2200 {n} {xs : vect {a//p a} n}, is_all p (xs.map subtype.val)\n| _ \u2045\u2046 := true.intro\n| _ (x \u223a xs) := \u27e8x.property, is_all_subtype\u27e9\n\n--- If all mapped values of `f` satisfy `p`, then all entries of `map f` of a vector satisfy `p`.\ntheorem map_all {\u03b1 \u03b2 : Type _} {f : \u03b1 \u2192 \u03b2} (p : \u03b2 \u2192 Prop) (hpf : \u2200 a, p (f a)) : \u2200 {n : \u2115} {v : vect \u03b1 n}, is_all p (vect.map f v)\n| _ \u2045\u2046 := true.intro\n| _ (a \u223a as) := \u27e8hpf a, map_all\u27e9\n\n--- Assertion that a given vector consists of a unique element.\ndefinition is_diagonal {\u03b1 : Type _} (a : \u03b1) : \u2200 {n : \u2115}, vect \u03b1 n \u2192 Prop := @is_all \u03b1 (\u03bb b, a=b)\n\ntheorem is_diagonal_eq_repeat {\u03b1 : Type _} (a : \u03b1) : \u2200 {n : \u2115} {as : vect \u03b1 n}, is_diagonal a as \u2192 as = repeat a n\n| _ \u2045\u2046 _ := rfl\n| (n+1) (a' \u223a as) hdiag :=\n  begin\n    dsimp [repeat];\n    rw [\u2190hdiag.left, is_diagonal_eq_repeat hdiag.right],\n  end\n\nend vect\n", "meta": {"author": "Junology", "repo": "groth-lean", "sha": "5aa1ba624cd0f5145f63fa86130f99b85bbbcac2", "save_path": "github-repos/lean/Junology-groth-lean", "path": "github-repos/lean/Junology-groth-lean/groth-lean-5aa1ba624cd0f5145f63fa86130f99b85bbbcac2/src/data/vect/search.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7318303611867494}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n-/\nimport algebra.char_p.basic\nimport group_theory.perm.cycle.type\n\n/-!\n# Characteristic and cardinality\n\nWe prove some results relating characteristic and cardinality of finite rings\n\n## Tags\ncharacterstic, cardinality, ring\n-/\n\n/-- A prime `p` is a unit in a commutative ring `R` of nonzero characterstic iff it does not divide\nthe characteristic. -/\nlemma is_unit_iff_not_dvd_char_of_ring_char_ne_zero (R : Type*) [comm_ring R] (p : \u2115) [fact p.prime]\n  (hR : ring_char R \u2260 0) :\n  is_unit (p : R) \u2194 \u00ac p \u2223 ring_char R :=\nbegin\n  have hch := char_p.cast_eq_zero R (ring_char R),\n  have hp : p.prime := fact.out p.prime,\n  split,\n  { rintros h\u2081 \u27e8q, hq\u27e9,\n    rcases is_unit.exists_left_inv h\u2081 with \u27e8a, ha\u27e9,\n    have h\u2083 : \u00ac ring_char R \u2223 q :=\n    begin\n      rintro \u27e8r, hr\u27e9,\n      rw [hr, \u2190 mul_assoc, mul_comm p, mul_assoc] at hq,\n      nth_rewrite 0 \u2190 mul_one (ring_char R) at hq,\n      exact nat.prime.not_dvd_one hp \u27e8r, mul_left_cancel\u2080 hR hq\u27e9,\n    end,\n    have h\u2084 := mt (char_p.int_cast_eq_zero_iff R (ring_char R) q).mp,\n    apply_fun (coe : \u2115 \u2192 R) at hq,\n    apply_fun ((*) a) at hq,\n    rw [nat.cast_mul, hch, mul_zero, \u2190 mul_assoc, ha, one_mul] at hq,\n    norm_cast at h\u2084,\n    exact h\u2084 h\u2083 hq.symm, },\n  { intro h,\n    rcases (hp.coprime_iff_not_dvd.mpr h).is_coprime with \u27e8a, b, hab\u27e9,\n    apply_fun (coe : \u2124 \u2192 R) at hab,\n    push_cast at hab,\n    rw [hch, mul_zero, add_zero, mul_comm] at hab,\n    exact is_unit_of_mul_eq_one (p : R) a hab, },\nend\n\n/-- A prime `p` is a unit in a finite commutative ring `R`\niff it does not divide the characteristic. -/\nlemma is_unit_iff_not_dvd_char (R : Type*) [comm_ring R] (p : \u2115) [fact p.prime] [finite R] :\n  is_unit (p : R) \u2194 \u00ac p \u2223 ring_char R :=\nis_unit_iff_not_dvd_char_of_ring_char_ne_zero R p $ char_p.char_ne_zero_of_finite R (ring_char R)\n\n/-- The prime divisors of the characteristic of a finite commutative ring are exactly\nthe prime divisors of its cardinality. -/\nlemma prime_dvd_char_iff_dvd_card {R : Type*} [comm_ring R] [fintype R] (p : \u2115) [fact p.prime] :\n  p \u2223 ring_char R \u2194 p \u2223 fintype.card R :=\nbegin\n  refine \u27e8\u03bb h, h.trans $ int.coe_nat_dvd.mp $ (char_p.int_cast_eq_zero_iff R (ring_char R)\n    (fintype.card R)).mp $ by exact_mod_cast char_p.cast_card_eq_zero R, \u03bb h, _\u27e9,\n  by_contra h\u2080,\n  rcases exists_prime_add_order_of_dvd_card p h with \u27e8r, hr\u27e9,\n  have hr\u2081 := add_order_of_nsmul_eq_zero r,\n  rw [hr, nsmul_eq_mul] at hr\u2081,\n  rcases is_unit.exists_left_inv ((is_unit_iff_not_dvd_char R p).mpr h\u2080) with \u27e8u, hu\u27e9,\n  apply_fun ((*) u) at hr\u2081,\n  rw [mul_zero, \u2190 mul_assoc, hu, one_mul] at hr\u2081,\n  exact mt add_monoid.order_of_eq_one_iff.mpr\n          (ne_of_eq_of_ne hr (nat.prime.ne_one (fact.out p.prime))) hr\u2081,\nend\n\n/-- A prime that does not divide the cardinality of a finite commutative ring `R`\nis a unit in `R`. -/\nlemma not_is_unit_prime_of_dvd_card {R : Type*} [comm_ring R] [fintype R] (p : \u2115) [fact p.prime]\n (hp : p \u2223 fintype.card R) : \u00ac is_unit (p : R) :=\nmt (is_unit_iff_not_dvd_char R p).mp (not_not.mpr ((prime_dvd_char_iff_dvd_card p).mpr hp))\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/char_p/char_and_card.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952838963489, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7318303589554586}}
{"text": "import game.order.level03\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 4\n\nThis level invites you to work out a property of the absolute value.\nIn Lean the absolute value of $x$ is denoted by `abs x`. \nFor ease of use, a notation can be used around that definition as below.\nFeel free to use the triangle inequality on the real numbers,\n\n`abs_add : \u2200 (a b : ?M_1), |a + b| \u2264 |a| + |b|`\n\ntogether with the `linarith` and `norm_num` tactics.\n-/\n\nnotation `|` x `|` := abs x\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$| a - b| \u2264 |a| + |b|$$.\n-/\ntheorem abs_sub_le_sum_abs (a b : \u211d) : |a - b| \u2264 |a| + |b| :=\nbegin\n    have H : a - b = a + (-b), linarith,\n    rw H, \n    have G := abs_add a (-b),\n    have F : abs (-b) = abs b, norm_num,\n    rw F at G, exact G, done\nend\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545289551958, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.731826903144613}}
{"text": "import data.real.basic\n\nexample (a b c : \u211d) : (a * b) * c = b * (a * c) := \nbegin \n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n\nexample (a b c : \u211d) : (c * b) * a = b * (a * c) :=\nbegin\n  rw mul_comm c b,\n  rw mul_assoc b c a,\n  rw mul_comm c a,\nend\n\nexample (a b c : \u211d) : a * (b * c) = b * (a * c) :=\nbegin\n  rw mul_comm a (b * c),\n  rw mul_assoc b c a,\n  rw mul_comm c a,\nend\n\n\nexample (a b c : \u211d) : a * (b * c) = b * (c * a) :=\nbegin\n  rw mul_comm,\n  rw mul_assoc,\nend\n\nexample (a b c : \u211d) : a * (b * c) = b * (a * c) :=\nbegin\n  rw mul_comm a,\n  rw mul_assoc,\n  rw mul_comm c,\nend\n\nexample (a b c d e f : \u211d) (h : a * b = c * d) (h' : e = f) :\n  a * (b * e) = c * (d * f) :=\nbegin\n  rw h',\n  rw \u2190mul_assoc,\n  rw h,\n  rw mul_assoc,\nend\n\n\nexample (a b c d e f : \u211d) (h : b * c = e * f) :\n  a * b * c * d = a * e * f * d :=\nbegin\n  rw mul_assoc a b c,\n  rw h,\n  rw \u2190mul_assoc,\nend\n\nexample (a b c d : \u211d) (hyp : c = b * a - d) (hyp' : d = a * b) : c = 0 :=\nbegin\n  rw hyp,\n  rw hyp',\n  rw mul_comm,\n  rw sub_self,\nend\n\nvariables a b c d e f g : \u211d\n\nexample : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nbegin\n  rw [add_mul, mul_add, mul_add],\n  rw add_assoc (a * a) (a * b) (b * a + b * b),\n  rw \u2190add_assoc (a * b) (b * a) (b * b),\n  rw mul_comm b a,\n  rw \u2190two_mul,\n  rw add_assoc,\nend\n\nexample : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\ncalc\n  (a + b) * (a + b)\n      = a * a + b * a + (a * b + b * b) :\n          by rw [mul_add, add_mul, add_mul]\n  ... = a * a + (b * a + a * b) + b * b :\n          by rw [\u2190add_assoc, add_assoc (a * a)]\n  ... = a * a + 2 * (a * b) + b * b     :\n          by rw [mul_comm b a, \u2190two_mul]\n\n\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nbegin\n  rw [mul_add, add_mul, add_mul, \u2190add_assoc],\n  rw [add_assoc, add_assoc, \u2190add_assoc (b*c)],\n  rw [add_comm (b * c)],\n  rw [add_assoc, \u2190add_assoc, \u2190add_assoc],\nend\n\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\ncalc \n  (a + b) * (c + d) \n      = a * c + b * c + a * d + b * d : \n        by rw [mul_add, add_mul, add_mul, \u2190add_assoc]\n  ... = a * c + (b * c + a * d + b * d) :\n        by rw [add_assoc, add_assoc, \u2190add_assoc (b*c)]\n  ... = a * c + (a * d + b * c + b * d) :\n        by rw [add_comm (b * c)]\n  ... = a * c + a * d + b * c + b * d :\n        by rw [add_assoc, \u2190add_assoc, \u2190add_assoc]\n\n\nexample (a b : \u211d) : (a + b) * (a - b) = a^2 - b^2 :=\nbegin\n  rw [add_mul, mul_sub, mul_sub],\n  rw [add_sub, sub_add, mul_comm a b],\n  rw [sub_self, sub_zero, pow_two, pow_two],\nend\n\n#check pow_two a\n#check mul_sub a b c\n#check add_mul a b c\n#check add_sub a b c\n#check sub_sub a b c\n#check add_zero a\n\n\nexample (a b c d : \u211d) (hyp : c = d * a + b) (hyp' : b = a * d) :\n  c = 2 * a * d :=\nbegin\n  rw hyp' at hyp,\n  rw [mul_comm] at hyp,\n  rw [\u2190two_mul, \u2190mul_assoc] at hyp,\n  assumption\nend\n\nexample : (c * b) * a = b * (a * c) :=\nby ring\n\nexample : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nby ring\n\nexample : (a + b) * (a - b) = a^2 - b^2 :=\nby ring\n\nexample (hyp : c = d * a + b) (hyp' : b = a * d) :\n  c = 2 * a * d :=\nbegin\n  rw [hyp, hyp'],\n  ring\nend\n\n\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/02_Basics/01_Calculating.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7317056198273914}}
{"text": "/-\n  Copyright (c) 2021 Arthur Paulino. All rights reserved.\n  Released under Apache 2.0 license as described in the file LICENSE.\n  Authors: Arthur Paulino\n-/\n\nimport LeanMusic.Utils\n\nabbrev Intervals := List Int\n\nnamespace Intervals\n\n@[simp] def allPositive : Intervals \u2192 Prop\n  | h :: t => 0 < h \u2227 allPositive t\n  | _      => True\n\n@[simp] def delta : Intervals \u2192 Int\n  | h :: t => h + delta t\n  | _      => 0\n\ndef invertedAt : Intervals \u2192 Int \u2192 Intervals\n  | h :: (t : Intervals), a => t ++ [a - delta (h :: t)]\n  | _,                    _ => []\n\ntheorem appendPosOfPos (l l' : Intervals)\n    (hpl : l.allPositive) (hpl' : l'.allPositive) :\n      (l ++ l').allPositive := by\n  induction l with\n    | nil         => rw [List.nil_append]; exact hpl'\n    | cons _ _ hi => exact \u27e8hpl.1, hi hpl.2\u27e9\n\ntheorem deltaAppendEqSumDeltas (l l' : Intervals) :\n    delta (l ++ l') = delta l + delta l' := by\n  induction l with\n    | nil         => simp [Int.ZeroAdd]\n    | cons _ _ hi =>\n      simp only [HAppend.hAppend, Append.append] at hi\n      simp [hi, Int.AddAssoc]\n\ntheorem posInvOfPosAndBound (l : Intervals) (i : Int)\n    (hp : l.allPositive) (hb : l.delta < i) :\n      (l.invertedAt i).allPositive := by\n  cases l with\n    | nil      => simp\n    | cons h t =>\n      let iSubDelta := [(i - (h + delta t))]\n      have hpid : allPositive iSubDelta := by\n        exact \u27e8Int.zeroLtSubOfLt (h + delta t) i hb, \u27e8\u27e9\u27e9\n      exact appendPosOfPos t iSubDelta hp.2 hpid\n\ntheorem boundInvOfPosAndBound (l : Intervals) (i : Int)\n    (hp : l.allPositive) (hb : l.delta < i) :\n      (l.invertedAt i).delta < i := by\n  cases l with\n    | nil => exact hb\n    | cons h t =>\n      simp only [invertedAt, deltaAppendEqSumDeltas]\n      exact Int.what (delta t) i h hp.1\n\nend Intervals\n", "meta": {"author": "arthurpaulino", "repo": "LeanMusic", "sha": "aac6cdc34fd7cc950898a150816ef2a505dc7fda", "save_path": "github-repos/lean/arthurpaulino-LeanMusic", "path": "github-repos/lean/arthurpaulino-LeanMusic/LeanMusic-aac6cdc34fd7cc950898a150816ef2a505dc7fda/LeanMusic/Intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7317056134951947}}
{"text": "variables P Q : Prop\n\nvariable forward: P \u2192 Q\nvariable backward: Q \u2192 P\n\ndef pqEquiv : P \u2194 Q := (iff.intro forward backward)\n#check pqEquiv\n#check iff.elim_left (pqEquiv P Q forward backward)\n\ntheorem ifftrans' {P Q R : Prop} (pq: P \u2194 Q)  (qr: Q \u2194 R): P \u2194 R :=\nbegin\n    apply iff.intro,\n        assume p,\n            have ptq := iff.elim_left pq,\n            have qtr := iff.elim_left qr,\n            show R, from qtr (ptq p),\n\n        assume r,\n            have qtp := iff.elim_right pq,\n            have rtq := iff.elim_right qr,\n            show P, from qtp (rtq r),\nend\n\n-- cheating here\ntheorem ifftrans'' {P Q R : Prop} (pq: P \u2194 Q) (qr: Q \u2194 R) : P \u2194 R :=\nbegin\n    exact iff.trans pq qr\nend\n\n#check ifftrans'\n#check iff.trans\n\ntheorem ifftrans : \u2200 {P Q R}, (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n    assume P Q R,\n    assume pq qr,\n        apply iff.intro,\n            assume p,\n                have ptq := iff.elim_left pq,\n                have qtr := iff.elim_left qr,\n                show R, from qtr (ptq p),\n\n            assume r,\n                have qtp := iff.elim_right pq,\n                have rtq := iff.elim_right qr,\n                show P, from qtp (rtq r),\nend\n\nlemma andcomm : \u2200 {P Q}, P \u2227 Q \u2194 Q \u2227 P :=\nby {assume p q, apply iff.intro, \nassume pq, split, exact pq.2, exact pq.1, \nassume qp, split, exact qp.2, exact qp.1}\n\nlemma andcomm' : \u2200 {P Q}, P \u2227 Q \u2194 Q \u2227 P := \u03bb P Q, and.comm\n\nlemma a_imp_b_imp_c_iff_a_and_b_imp_c:\n    \u2200 A B C: Prop, (A \u2192 B \u2192 C) \u2194 ((A \u2227 B) \u2192 C) :=\n    \u03bb A B C: Prop,\n    begin\n        apply iff.intro,\n            assume abc,\n            assume aandb,\n            exact abc aandb.1 aandb.2,\n\n            assume abc,\n            assume a,\n            assume b,\n            exact abc (and.intro a b)\n    end\n\nexample : 0 = 1 \u2228 0 = 0 :=\nbegin\n    apply or.intro_right,\n    apply rfl\nend", "meta": {"author": "hanzhi713", "repo": "lean-proofs", "sha": "4d8356a878645b9ba7cb036f87737f3f1e68ede5", "save_path": "github-repos/lean/hanzhi713-lean-proofs", "path": "github-repos/lean/hanzhi713-lean-proofs/lean-proofs-4d8356a878645b9ba7cb036f87737f3f1e68ede5/src/lessons/lesson8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7317056090287839}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport group_theory.group_action.defs\nimport algebra.group.units\nimport algebra.group_with_zero\nimport data.equiv.mul_add\nimport data.equiv.mul_add_aut\nimport group_theory.perm.basic\n\n/-!\n# Group actions applied to various types of group\n\nThis file contains lemmas about `smul` on `units`, `group_with_zero`, and `group`.\n-/\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nsection mul_action\n\nsection units\nvariables [monoid \u03b1] [mul_action \u03b1 \u03b2]\n\n@[simp, to_additive] lemma units.inv_smul_smul (u : units \u03b1) (x : \u03b2) :\n  (\u2191u\u207b\u00b9:\u03b1) \u2022 (u:\u03b1) \u2022 x = x :=\nby rw [smul_smul, u.inv_mul, one_smul]\n\n@[simp, to_additive] lemma units.smul_inv_smul (u : units \u03b1) (x : \u03b2) :\n  (u:\u03b1) \u2022 (\u2191u\u207b\u00b9:\u03b1) \u2022 x = x :=\nby rw [smul_smul, u.mul_inv, one_smul]\n\n/-- If a monoid `\u03b1` acts on `\u03b2`, then each `u : units \u03b1` defines a permutation of `\u03b2`. -/\n@[to_additive] def units.smul_perm (u : units \u03b1) : equiv.perm \u03b2 :=\n\u27e8\u03bb x, (u:\u03b1) \u2022 x, \u03bb x, (\u2191u\u207b\u00b9:\u03b1) \u2022 x, u.inv_smul_smul, u.smul_inv_smul\u27e9\n\n/-- If an additive monoid `\u03b1` acts on `\u03b2`, then each `u : add_units \u03b1` defines a permutation\nof `\u03b2`. -/\nadd_decl_doc add_units.vadd_perm\n\n/-- If a monoid `\u03b1` acts on `\u03b2`, then each `u : units \u03b1` defines a permutation of `\u03b2`. -/\ndef units.smul_perm_hom : units \u03b1 \u2192* equiv.perm \u03b2 :=\n{ to_fun := units.smul_perm,\n  map_one' := equiv.ext $ one_smul \u03b1,\n  map_mul' := \u03bb u\u2081 u\u2082, equiv.ext $ mul_smul (u\u2081:\u03b1) u\u2082 }\n\n/-- If an additive monoid `\u03b1` acts on `\u03b2`, then each `u : add_units \u03b1` defines a permutation\nof `\u03b2`. -/\ndef add_units.vadd_perm_hom {M : Type*} [add_monoid M] [add_action M \u03b2] :\n  add_units M \u2192+ additive (equiv.perm \u03b2) :=\n{ to_fun := \u03bb u, additive.of_mul u.vadd_perm,\n  map_zero' := equiv.ext $ zero_vadd M,\n  map_add' := \u03bb u\u2081 u\u2082, equiv.ext $ add_vadd (u\u2081:M) u\u2082 }\n\n@[simp, to_additive] lemma units.smul_left_cancel (u : units \u03b1) {x y : \u03b2} :\n  (u:\u03b1) \u2022 x = (u:\u03b1) \u2022 y \u2194 x = y :=\nu.smul_perm.apply_eq_iff_eq\n\n@[to_additive] lemma units.smul_eq_iff_eq_inv_smul (u : units \u03b1) {x y : \u03b2} :\n  (u:\u03b1) \u2022 x = y \u2194 x = (\u2191u\u207b\u00b9:\u03b1) \u2022 y :=\nu.smul_perm.apply_eq_iff_eq_symm_apply\n\n@[to_additive] lemma is_unit.smul_left_cancel {a : \u03b1} (ha : is_unit a) {x y : \u03b2} :\n  a \u2022 x = a \u2022 y \u2194 x = y :=\nlet \u27e8u, hu\u27e9 := ha in hu \u25b8 u.smul_left_cancel\n\nend units\n\nsection gwz\nvariables [group_with_zero \u03b1] [mul_action \u03b1 \u03b2]\n\n@[simp]\nlemma inv_smul_smul' {c : \u03b1} (hc : c \u2260 0) (x : \u03b2) : c\u207b\u00b9 \u2022 c \u2022 x = x :=\n(units.mk0 c hc).inv_smul_smul x\n\n@[simp]\nlemma smul_inv_smul' {c : \u03b1} (hc : c \u2260 0) (x : \u03b2) : c \u2022 c\u207b\u00b9 \u2022 x = x :=\n(units.mk0 c hc).smul_inv_smul x\n\nlemma inv_smul_eq_iff' {a : \u03b1} (ha : a \u2260 0) {x y : \u03b2} : a\u207b\u00b9 \u2022 x = y \u2194 x = a \u2022 y :=\n(units.mk0 a ha).smul_perm.symm_apply_eq\n\nlemma eq_inv_smul_iff' {a : \u03b1} (ha : a \u2260 0) {x y : \u03b2} : x = a\u207b\u00b9 \u2022 y \u2194 a \u2022 x = y :=\n(units.mk0 a ha).smul_perm.eq_symm_apply\n\nend gwz\n\nsection group\nvariables [group \u03b1] [mul_action \u03b1 \u03b2]\n\n@[simp, to_additive] lemma inv_smul_smul (c : \u03b1) (x : \u03b2) : c\u207b\u00b9 \u2022 c \u2022 x = x :=\n(to_units c).inv_smul_smul x\n\n@[simp, to_additive] lemma smul_inv_smul (c : \u03b1) (x : \u03b2) : c \u2022 c\u207b\u00b9 \u2022 x = x :=\n(to_units c).smul_inv_smul x\n\n@[to_additive] lemma inv_smul_eq_iff {a : \u03b1} {x y : \u03b2} : a\u207b\u00b9 \u2022 x = y \u2194 x = a \u2022 y :=\n(to_units a).smul_perm.symm_apply_eq\n\n@[to_additive] lemma eq_inv_smul_iff {a : \u03b1} {x y : \u03b2} : x = a\u207b\u00b9 \u2022 y \u2194 a \u2022 x = y :=\n(to_units a).smul_perm.eq_symm_apply\n\nvariables (\u03b1) (\u03b2)\n\n/-- Given an action of a group `\u03b1` on a set `\u03b2`, each `g : \u03b1` defines a permutation of `\u03b2`. -/\ndef mul_action.to_perm : \u03b1 \u2192* equiv.perm \u03b2 :=\nunits.smul_perm_hom.comp to_units.to_monoid_hom\n\nvariables {\u03b1} {\u03b2}\n\n@[to_additive] protected lemma mul_action.bijective (g : \u03b1) : function.bijective (\u03bb b : \u03b2, g \u2022 b) :=\n(to_units g).smul_perm.bijective\n\n@[to_additive] protected lemma mul_action.injective (g : \u03b1) : function.injective (\u03bb b : \u03b2, g \u2022 b) :=\n(mul_action.bijective g).injective\n\n@[to_additive] lemma smul_left_cancel (g : \u03b1) {x y : \u03b2} (h : g \u2022 x = g \u2022 y) : x = y :=\nmul_action.injective g h\n\n@[simp, to_additive] lemma smul_left_cancel_iff (g : \u03b1) {x y : \u03b2} : g \u2022 x = g \u2022 y \u2194 x = y :=\n(mul_action.injective g).eq_iff\n\nend group\n\nend mul_action\n\nsection distrib_mul_action\nvariables [monoid \u03b1] [add_monoid \u03b2] [distrib_mul_action \u03b1 \u03b2]\n\ntheorem units.smul_eq_zero (u : units \u03b1) {x : \u03b2} : (u : \u03b1) \u2022 x = 0 \u2194 x = 0 :=\n\u27e8\u03bb h, by rw [\u2190 u.inv_smul_smul x, h, smul_zero], \u03bb h, h.symm \u25b8 smul_zero _\u27e9\n\ntheorem units.smul_ne_zero (u : units \u03b1) {x : \u03b2} : (u : \u03b1) \u2022 x \u2260 0 \u2194 x \u2260 0 :=\nnot_congr u.smul_eq_zero\n\n@[simp] theorem is_unit.smul_eq_zero {u : \u03b1} (hu : is_unit u) {x : \u03b2} :\n  u \u2022 x = 0 \u2194 x = 0 :=\nexists.elim hu $ \u03bb u hu, hu \u25b8 u.smul_eq_zero\n\nend distrib_mul_action\n\nsection arrow\n\n/-- If `G` acts on `A`, then it acts also on `A \u2192 B`, by `(g \u2022 F) a = F (g\u207b\u00b9 \u2022 a)`. -/\n@[simps] def arrow_action {G A B : Type*} [group G] [mul_action G A] : mul_action G (A \u2192 B) :=\n{ smul := \u03bb g F a, F (g\u207b\u00b9 \u2022 a),\n  one_smul := by { intro, simp only [one_inv, one_smul] },\n  mul_smul := by { intros, simp only [mul_smul, mul_inv_rev] } }\n\nlocal attribute [instance] arrow_action\n\n/-- Given groups `G H` with `G` acting on `A`, `G` acts by\n  multiplicative automorphisms on `A \u2192 H`. -/\n@[simps] def mul_aut_arrow {G A H} [group G] [mul_action G A] [group H] : G \u2192* mul_aut (A \u2192 H) :=\n{ to_fun := \u03bb g,\n  { to_fun := \u03bb F, g \u2022 F,\n    inv_fun := \u03bb F, g\u207b\u00b9 \u2022 F,\n    left_inv := \u03bb F, inv_smul_smul g F,\n    right_inv := \u03bb F, smul_inv_smul g F,\n    map_mul' := by { intros, ext, simp only [arrow_action_to_has_scalar_smul, pi.mul_apply] } },\n  map_one' := by { ext, simp only [mul_aut.one_apply, mul_equiv.coe_mk, one_smul] },\n  map_mul' := by { intros, ext, simp only [mul_smul, mul_equiv.coe_mk, mul_aut.mul_apply] } }\n\nend arrow\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/group_action/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7317056045263632}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jeremy Avigad\n\nInsertion sort and merge sort.\n-/\nimport data.list.perm\nopen list.perm\n\nnamespace list\n\nsection sorted\nuniverse variable uu\nvariables {\u03b1 : Type uu} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\n/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`\n  is a `<` or `\u2264`-like relation (transitive and antisymmetric or asymmetric) -/\ndef sorted := @pairwise\n\n@[simp] theorem sorted_nil : sorted r [] := pairwise.nil\n\n@[simp] theorem sorted_singleton (a : \u03b1) : sorted r [a] := pairwise_singleton _ _\n\ntheorem sorted_of_sorted_cons {a : \u03b1} {l : list \u03b1} : sorted r (a :: l) \u2192 sorted r l :=\npairwise_of_pairwise_cons\n\ntheorem rel_of_sorted_cons {a : \u03b1} {l : list \u03b1} : sorted r (a :: l) \u2192\n  \u2200 b \u2208 l, r a b :=\nrel_of_pairwise_cons\n\n@[simp] theorem sorted_cons {a : \u03b1} {l : list \u03b1} :\n  sorted r (a :: l) \u2194 (\u2200 b \u2208 l, r a b) \u2227 sorted r l :=\npairwise_cons\n\ntheorem eq_of_sorted_of_perm [is_antisymm \u03b1 r]\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) (s\u2081 : sorted r l\u2081) (s\u2082 : sorted r l\u2082) : l\u2081 = l\u2082 :=\nbegin\n  induction s\u2081 with a l\u2081 h\u2081 s\u2081 IH generalizing l\u2082,\n  { rw eq_nil_of_perm_nil p },\n  { have : a \u2208 l\u2082 := perm_subset p (mem_cons_self _ _),\n    rcases mem_split this with \u27e8u\u2082, v\u2082, rfl\u27e9,\n    have p' := (perm_cons a).1 (p.trans perm_middle),\n    have := IH p' (pairwise_of_sublist (by simp) s\u2082), subst l\u2081,\n    change a::u\u2082 ++ v\u2082 = u\u2082 ++ ([a] ++ v\u2082), rw \u2190 append_assoc, congr,\n    have : \u2200 (x : \u03b1) (h : x \u2208 u\u2082), x = a := \u03bb x m,\n      antisymm ((pairwise_append.1 s\u2082).2.2 _ m a (mem_cons_self _ _))\n        (h\u2081 _ (by simp [m])),\n    rw [(@eq_repeat _ a (length u\u2082 + 1) (a::u\u2082)).2,\n        (@eq_repeat _ a (length u\u2082 + 1) (u\u2082++[a])).2];\n    split; simp [iff_true_intro this, or_comm] }\nend\n\nend sorted\n\n/-\n  sorting procedures\n-/\n\nsection sort\nuniverse variable uu\nparameters {\u03b1 : Type uu} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [decidable_rel r]\nlocal infix `\u227c` : 50 := r\n\n/- insertion sort -/\n\nsection insertion_sort\n\n/-- `ordered_insert a l` inserts `a` into `l` at such that\n  `ordered_insert a l` is sorted if `l` is. -/\n@[simp] def ordered_insert (a : \u03b1) : list \u03b1 \u2192 list \u03b1\n| []       := [a]\n| (b :: l) := if a \u227c b then a :: b :: l else b :: ordered_insert l\n\n/-- `insertion_sort l` returns `l` sorted using the insertion sort algorithm. -/\n@[simp] def insertion_sort : list \u03b1 \u2192 list \u03b1\n| []       := []\n| (b :: l) := ordered_insert b (insertion_sort l)\n\nsection correctness\nopen perm\n\ntheorem perm_ordered_insert (a) : \u2200 l : list \u03b1, ordered_insert a l ~ a :: l\n| []       := perm.refl _\n| (b :: l) := by by_cases a \u227c b; [simp [ordered_insert, h],\n  simpa [ordered_insert, h] using\n    (perm.skip _ (perm_ordered_insert l)).trans (perm.swap _ _ _)]\n\ntheorem perm_insertion_sort : \u2200 l : list \u03b1, insertion_sort l ~ l\n| []       := perm.nil\n| (b :: l) := by simpa [insertion_sort] using\n  (perm_ordered_insert _ _ _).trans (perm.skip b (perm_insertion_sort l))\n\nsection total_and_transitive\nvariables [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted_ordered_insert (a : \u03b1) : \u2200 l, sorted r l \u2192 sorted r (ordered_insert a l)\n| []       h := sorted_singleton a\n| (b :: l) h := begin\n  by_cases h' : a \u227c b,\n  { simpa [ordered_insert, h', h] using \u03bb b' bm, trans h' (rel_of_sorted_cons h _ bm) },\n  { suffices : \u2200 (b' : \u03b1), b' \u2208 ordered_insert r a l \u2192 r b b',\n    { simpa [ordered_insert, h', sorted_ordered_insert l (sorted_of_sorted_cons h)] },\n    intros b' bm,\n    cases (show b' = a \u2228 b' \u2208 l, by simpa using\n      perm_subset (perm_ordered_insert _ _ _) bm) with be bm,\n    { subst b', exact (total_of r _ _).resolve_left h' },\n    { exact rel_of_sorted_cons h _ bm } }\nend\n\ntheorem sorted_insertion_sort : \u2200 l, sorted r (insertion_sort l)\n| []       := sorted_nil\n| (a :: l) := sorted_ordered_insert a _ (sorted_insertion_sort l)\n\nend total_and_transitive\nend correctness\nend insertion_sort\n\n/- merge sort -/\n\nsection merge_sort\n\n-- TODO(Jeremy): observation: if instead we write (a :: (split l).1, b :: (split l).2), the\n-- equation compiler can't prove the third equation\n\n/-- Split `l` into two lists of approximately equal length.\n\n     split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) -/\n@[simp] def split : list \u03b1 \u2192 list \u03b1 \u00d7 list \u03b1\n| []       := ([], [])\n| (a :: l) := let (l\u2081, l\u2082) := split l in (a :: l\u2082, l\u2081)\n\ntheorem split_cons_of_eq (a : \u03b1) {l l\u2081 l\u2082 : list \u03b1} (h : split l = (l\u2081, l\u2082)) :\n  split (a :: l) = (a :: l\u2082, l\u2081) :=\nby rw [split, h]; refl\n\ntheorem length_split_le : \u2200 {l l\u2081 l\u2082 : list \u03b1},\n  split l = (l\u2081, l\u2082) \u2192 length l\u2081 \u2264 length l \u2227 length l\u2082 \u2264 length l\n| []     ._  ._  rfl := \u27e8nat.le_refl 0, nat.le_refl 0\u27e9\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ h\u2082, nat.le_succ_of_le h\u2081\u27e9\nend\n\ntheorem length_split_lt {a b} {l l\u2081 l\u2082 : list \u03b1} (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  length l\u2081 < length (a::b::l) \u2227 length l\u2082 < length (a::b::l) :=\nbegin\n  cases e : split l with l\u2081' l\u2082',\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l\u2081 l\u2082,\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ (nat.succ_le_succ h\u2081), nat.succ_le_succ (nat.succ_le_succ h\u2082)\u27e9\nend\n\ntheorem perm_split : \u2200 {l l\u2081 l\u2082 : list \u03b1}, split l = (l\u2081, l\u2082) \u2192 l ~ l\u2081 ++ l\u2082\n| []     ._  ._  rfl := perm.refl _\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  exact perm.skip a ((perm_split e).trans perm_app_comm),\nend\n\n/-- Merge two sorted lists into one in linear time.\n\n     merge [1, 2, 4, 5] [0, 1, 3, 4] = [0, 1, 1, 2, 3, 4, 4, 5] -/\ndef merge : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| []       l'        := l'\n| l        []        := l\n| (a :: l) (b :: l') := if a \u227c b then a :: merge l (b :: l') else b :: merge (a :: l) l'\n\ninclude r\n/-- Implementation of a merge sort algorithm to sort a list. -/\ndef merge_sort : list \u03b1 \u2192 list \u03b1\n| []        := []\n| [a]       := [a]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  exact merge r (merge_sort l\u2081) (merge_sort l\u2082)\nend\nusing_well_founded {\n  rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_cons_cons {a b} {l l\u2081 l\u2082 : list \u03b1}\n  (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  merge_sort (a::b::l) = merge (merge_sort l\u2081) (merge_sort l\u2082) :=\nbegin\n  suffices : \u2200 (L : list \u03b1) h1, @@and.rec\n    (\u03bb a a (_ : length l\u2081 < length l + 1 + 1 \u2227\n      length l\u2082 < length l + 1 + 1), L) h1 h1 = L,\n  { simp [merge_sort, h], apply this },\n  intros, cases h1, refl\nend\n\nsection correctness\n\ntheorem perm_merge : \u2200 (l l' : list \u03b1), merge l l' ~ l ++ l'\n| []       []        := perm.nil\n| []       (b :: l') := by simp [merge]\n| (a :: l) []        := by simp [merge]\n| (a :: l) (b :: l') := begin\n  by_cases a \u227c b,\n  { simpa [merge, h] using skip _ (perm_merge _ _) },\n  { suffices : b :: merge r (a :: l) l' ~ a :: (l ++ b :: l'), {simpa [merge, h]},\n    exact (skip _ (perm_merge _ _)).trans ((swap _ _ _).trans (skip _ perm_middle.symm)) }\nend\n\ntheorem perm_merge_sort : \u2200 l : list \u03b1, merge_sort l ~ l\n| []        := perm.refl _\n| [a]       := perm.refl _\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  apply (perm_merge r _ _).trans,\n  exact (perm_app (perm_merge_sort l\u2081) (perm_merge_sort l\u2082)).trans (perm_split e).symm\nend\nusing_well_founded {\n  rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\nsection total_and_transitive\nvariables [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted_merge : \u2200 {l l' : list \u03b1}, sorted r l \u2192 sorted r l' \u2192 sorted r (merge l l')\n| []       []        h\u2081 h\u2082 := sorted_nil\n| []       (b :: l') h\u2081 h\u2082 := by simpa [merge] using h\u2082\n| (a :: l) []        h\u2081 h\u2082 := by simpa [merge] using h\u2081\n| (a :: l) (b :: l') h\u2081 h\u2082 := begin\n  by_cases a \u227c b,\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r l (b :: l')), r a b',\n    { simpa [merge, h, sorted_merge (sorted_of_sorted_cons h\u2081) h\u2082] },\n    intros b' bm,\n    rcases (show b' = b \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa [or.left_comm] using\n      perm_subset (perm_merge _ _ _) bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact rel_of_sorted_cons h\u2081 _ bl },\n    { exact trans h (rel_of_sorted_cons h\u2082 _ bl') } },\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r (a :: l) l'), r b b',\n    { simpa [merge, h, sorted_merge h\u2081 (sorted_of_sorted_cons h\u2082)] },\n    intros b' bm,\n    have ba : b \u227c a := (total_of r _ _).resolve_left h,\n    rcases (show b' = a \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa using\n      perm_subset (perm_merge _ _ _) bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact trans ba (rel_of_sorted_cons h\u2081 _ bl) },\n    { exact rel_of_sorted_cons h\u2082 _ bl' } }\nend\n\ntheorem sorted_merge_sort : \u2200 l : list \u03b1, sorted r (merge_sort l)\n| []        := sorted_nil\n| [a]       := sorted_singleton _\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  exact sorted_merge r (sorted_merge_sort l\u2081) (sorted_merge_sort l\u2082)\nend\nusing_well_founded {\n  rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_eq_self [is_antisymm \u03b1 r] {l : list \u03b1} : sorted r l \u2192 merge_sort l = l :=\neq_of_sorted_of_perm (perm_merge_sort _) (sorted_merge_sort _)\n\nend total_and_transitive\nend correctness\nend merge_sort\nend sort\n\n/- try them out! -/\n\n--#eval insertion_sort (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\n--#eval merge_sort     (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\nend list\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/data/list/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.731687226078376}}
{"text": "/-\nCopyright (c) 2020 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n-/\nimport algebra.lie.basic\nimport linear_algebra.direct_sum.finsupp\n\n/-!\n# Direct sums of Lie algebras and Lie modules\n\nDirect sums of Lie algebras and Lie modules carry natural algbebra and module structures.\n\n## Tags\n\nlie algebra, lie module, direct sum\n-/\n\nuniverses u v w w\u2081\n\nnamespace direct_sum\nopen dfinsupp\nopen_locale direct_sum\n\nvariables {R : Type u} {\u03b9 : Type v} [comm_ring R]\n\nsection modules\n\n/-! The direct sum of Lie modules over a fixed Lie algebra carries a natural Lie module\nstructure. -/\n\nvariables {L : Type w\u2081} {M : \u03b9 \u2192 Type w}\nvariables [lie_ring L] [lie_algebra R L]\nvariables [\u03a0 i, add_comm_group (M i)] [\u03a0 i, module R (M i)]\nvariables [\u03a0 i, lie_ring_module L (M i)] [\u03a0 i, lie_module R L (M i)]\n\ninstance : lie_ring_module L (\u2a01 i, M i) :=\n{ bracket     := \u03bb x m, m.map_range (\u03bb i m', \u2045x, m'\u2046) (\u03bb i, lie_zero x),\n  add_lie     := \u03bb x y m, by { ext, simp only [map_range_apply, add_apply, add_lie], },\n  lie_add     := \u03bb x m n, by { ext, simp only [map_range_apply, add_apply, lie_add], },\n  leibniz_lie := \u03bb x y m, by { ext, simp only [map_range_apply, lie_lie, add_apply,\n    sub_add_cancel], }, }\n\n@[simp] lemma lie_module_bracket_apply (x : L) (m : \u2a01 i, M i) (i : \u03b9) :\n  \u2045x, m\u2046 i = \u2045x, m i\u2046 := map_range_apply _ _ m i\n\ninstance : lie_module R L (\u2a01 i, M i) :=\n{ smul_lie := \u03bb t x m, by { ext i, simp only [smul_lie, lie_module_bracket_apply, smul_apply], },\n  lie_smul := \u03bb t x m, by { ext i, simp only [lie_smul, lie_module_bracket_apply, smul_apply], }, }\n\nvariables (R \u03b9 L M)\n\n/-- The inclusion of each component into a direct sum as a morphism of Lie modules. -/\ndef lie_module_of [decidable_eq \u03b9] (j : \u03b9) : M j \u2192\u2097\u2045R,L\u2046 \u2a01 i, M i :=\n{ map_lie' := \u03bb x m,\n    begin\n      ext i, by_cases h : j = i,\n      { rw \u2190 h, simp, },\n      { simp [lof, single_eq_of_ne h], },\n    end,\n  ..lof R \u03b9 M j }\n\n/-- The projection map onto one component, as a morphism of Lie modules. -/\ndef lie_module_component (j : \u03b9) : (\u2a01 i, M i) \u2192\u2097\u2045R,L\u2046 M j :=\n{ map_lie' := \u03bb x m,\n    by simp only [component, lapply_apply, lie_module_bracket_apply, linear_map.to_fun_eq_coe],\n  ..component R \u03b9 M j }\n\nend modules\n\nsection algebras\n\n/-! The direct sum of Lie algebras carries a natural Lie algebra structure. -/\n\nvariables {L : \u03b9 \u2192 Type w}\nvariables [\u03a0 i, lie_ring (L i)] [\u03a0 i, lie_algebra R (L i)]\n\ninstance : lie_ring (\u2a01 i, L i) :=\n{ bracket     := zip_with (\u03bb i, \u03bb x y, \u2045x, y\u2046) (\u03bb i, lie_zero 0),\n  add_lie     := \u03bb x y z, by { ext, simp only [zip_with_apply, add_apply, add_lie], },\n  lie_add     := \u03bb x y z, by { ext, simp only [zip_with_apply, add_apply, lie_add], },\n  lie_self    := \u03bb x, by { ext, simp only [zip_with_apply, add_apply, lie_self, zero_apply], },\n  leibniz_lie := \u03bb x y z, by { ext, simp only [sub_apply,\n    zip_with_apply, add_apply, zero_apply], apply leibniz_lie, },\n  ..(infer_instance : add_comm_group _) }\n\n@[simp] lemma bracket_apply (x y : \u2a01 i, L i) (i : \u03b9) :\n  \u2045x, y\u2046 i = \u2045x i, y i\u2046 := zip_with_apply _ _ x y i\n\ninstance : lie_algebra R (\u2a01 i, L i) :=\n{ lie_smul := \u03bb c x y, by { ext, simp only [\n    zip_with_apply, smul_apply, bracket_apply, lie_smul] },\n  ..(infer_instance : module R _) }\n\nvariables (R \u03b9 L)\n\n/-- The inclusion of each component into the direct sum as morphism of Lie algebras. -/\ndef lie_algebra_of [decidable_eq \u03b9] (j : \u03b9) : L j \u2192\u2097\u2045R\u2046 \u2a01 i, L i :=\n{ map_lie' := \u03bb x y, by\n  { ext i, by_cases h : j = i,\n    { rw \u2190 h, simp, },\n    { simp [lof, single_eq_of_ne h], }, },\n  ..lof R \u03b9 L j, }\n\n/-- The projection map onto one component, as a morphism of Lie algebras. -/\ndef lie_algebra_component (j : \u03b9) : (\u2a01 i, L i) \u2192\u2097\u2045R\u2046 L j :=\n{ map_lie' := \u03bb x y,\n    by simp only [component, bracket_apply, lapply_apply, linear_map.to_fun_eq_coe],\n  ..component R \u03b9 L j }\n\nend algebras\n\nend direct_sum\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/lie/direct_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.73157348045478}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard\n-/\n\nimport algebra.module.basic\nimport linear_algebra.finsupp\nimport linear_algebra.free_module.basic\n\n/-!\n\n# Projective modules\n\nThis file contains a definition of a projective module, the proof that\nour definition is equivalent to a lifting property, and the\nproof that all free modules are projective.\n\n## Main definitions\n\nLet `R` be a ring (or a semiring) and let `M` be an `R`-module.\n\n* `is_projective R M` : the proposition saying that `M` is a projective `R`-module.\n\n## Main theorems\n\n* `is_projective.lifting_property` : a map from a projective module can be lifted along\n  a surjection.\n\n* `is_projective.of_lifting_property` : If for all R-module surjections `A \u2192\u2097 B`, all\n  maps `M \u2192\u2097 B` lift to `M \u2192\u2097 A`, then `M` is projective.\n\n* `is_projective.of_free` : Free modules are projective\n\n## Implementation notes\n\nThe actual definition of projective we use is that the natural R-module map\nfrom the free R-module on the type M down to M splits. This is more convenient\nthan certain other definitions which involve quantifying over universes,\nand also universe-polymorphic (the ring and module can be in different universes).\n\nWe require that the module sits in at least as high a universe as the ring:\nwithout this, free modules don't even exist,\nand it's unclear if projective modules are even a useful notion.\n\n## References\n\nhttps://en.wikipedia.org/wiki/Projective_module\n\n## TODO\n\n- Direct sum of two projective modules is projective.\n- Arbitrary sum of projective modules is projective.\n\nAll of these should be relatively straightforward.\n\n## Tags\n\nprojective module\n\n-/\n\nuniverses u v\n\n/- The actual implementation we choose: `P` is projective if the natural surjection\n   from the free `R`-module on `P` to `P` splits. -/\n/-- An R-module is projective if it is a direct summand of a free module, or equivalently\n  if maps from the module lift along surjections. There are several other equivalent\n  definitions. -/\nclass module.projective (R : Type u) [semiring R] (P : Type (max u v)) [add_comm_monoid P]\n  [module R P] : Prop :=\n(out : \u2203 s : P \u2192\u2097[R] (P \u2192\u2080 R), function.left_inverse (finsupp.total P P R id) s)\n\nnamespace module\n\nlemma projective_def {R : Type u} [semiring R] {P : Type (max u v)} [add_comm_monoid P]\n  [module R P] : projective R P \u2194\n  (\u2203 s : P \u2192\u2097[R] (P \u2192\u2080 R), function.left_inverse (finsupp.total P P R id) s) :=\n\u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\nsection semiring\n\nvariables {R : Type u} [semiring R] {P : Type (max u v)} [add_comm_monoid P] [module R P]\n  {M : Type (max u v)} [add_comm_group M] [module R M] {N : Type*} [add_comm_group N] [module R N]\n\n/-- A projective R-module has the property that maps from it lift along surjections. -/\ntheorem projective_lifting_property [h : projective R P] (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N)\n  (hf : function.surjective f) : \u2203 (h : P \u2192\u2097[R] M), f.comp h = g :=\nbegin\n  /-\n  Here's the first step of the proof.\n  Recall that `X \u2192\u2080 R` is Lean's way of talking about the free `R`-module\n  on a type `X`. The universal property `finsupp.total` says that to a map\n  `X \u2192 N` from a type to an `R`-module, we get an associated R-module map\n  `(X \u2192\u2080 R) \u2192\u2097 N`. Apply this to a (noncomputable) map `P \u2192 M` coming from the map\n  `P \u2192\u2097 N` and a random splitting of the surjection `M \u2192\u2097 N`, and we get\n  a map `\u03c6 : (P \u2192\u2080 R) \u2192\u2097 M`.\n  -/\n  let \u03c6 : (P \u2192\u2080 R) \u2192\u2097[R] M := finsupp.total _ _ _ (\u03bb p, function.surj_inv hf (g p)),\n  -- By projectivity we have a map `P \u2192\u2097 (P \u2192\u2080 R)`;\n  cases h.out with s hs,\n  -- Compose to get `P \u2192\u2097 M`. This works.\n  use \u03c6.comp s,\n  ext p,\n  conv_rhs {rw \u2190 hs p},\n  simp [\u03c6, finsupp.total_apply, function.surj_inv_eq hf],\nend\n\n/-- A module which satisfies the universal property is projective. Note that the universe variables\nin `huniv` are somewhat restricted. -/\ntheorem projective_of_lifting_property'\n  -- If for all surjections of `R`-modules `M \u2192\u2097 N`, all maps `P \u2192\u2097 N` lift to `P \u2192\u2097 M`,\n  (huniv : \u2200 {M : Type (max v u)} {N : Type (max u v)} [add_comm_monoid M] [add_comm_monoid N],\n    by exactI\n    \u2200 [module R M] [module R N],\n    by exactI\n    \u2200 (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N),\n  function.surjective f \u2192 \u2203 (h : P \u2192\u2097[R] M), f.comp h = g) :\n  -- then `P` is projective.\n  projective R P :=\nbegin\n  -- let `s` be the universal map `(P \u2192\u2080 R) \u2192\u2097 P` coming from the identity map `P \u2192\u2097 P`.\n  obtain \u27e8s, hs\u27e9 : \u2203 (s : P \u2192\u2097[R] P \u2192\u2080 R),\n    (finsupp.total P P R id).comp s = linear_map.id :=\n    huniv (finsupp.total P P R (id : P \u2192 P)) (linear_map.id : P \u2192\u2097[R] P) _,\n  -- This `s` works.\n  { use s,\n    rwa linear_map.ext_iff at hs },\n  { intro p,\n    use finsupp.single p 1,\n    simp },\nend\n\nend semiring\n\nsection ring\n\nvariables {R : Type u} [ring R] {P : Type (max u v)} [add_comm_group P] [module R P]\n\n/-- A variant of `of_lifting_property'` when we're working over a `[ring R]`,\nwhich only requires quantifying over modules with an `add_comm_group` instance. -/\ntheorem projective_of_lifting_property\n  -- If for all surjections of `R`-modules `M \u2192\u2097 N`, all maps `P \u2192\u2097 N` lift to `P \u2192\u2097 M`,\n  (huniv : \u2200 {M : Type (max v u)} {N : Type (max u v)} [add_comm_group M] [add_comm_group N],\n    by exactI\n    \u2200 [module R M] [module R N],\n    by exactI\n    \u2200 (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N),\n  function.surjective f \u2192 \u2203 (h : P \u2192\u2097[R] M), f.comp h = g) :\n  -- then `P` is projective.\n  projective R P :=\n-- We could try and prove this *using* `of_lifting_property`,\n-- but this quickly leads to typeclass hell,\n-- so we just prove it over again.\nbegin\n  -- let `s` be the universal map `(P \u2192\u2080 R) \u2192\u2097 P` coming from the identity map `P \u2192\u2097 P`.\n  obtain \u27e8s, hs\u27e9 : \u2203 (s : P \u2192\u2097[R] P \u2192\u2080 R),\n    (finsupp.total P P R id).comp s = linear_map.id :=\n    huniv (finsupp.total P P R (id : P \u2192 P)) (linear_map.id : P \u2192\u2097[R] P) _,\n  -- This `s` works.\n  { use s,\n    rwa linear_map.ext_iff at hs },\n  { intro p,\n    use finsupp.single p 1,\n    simp },\nend\n\n/-- Free modules are projective. -/\ntheorem projective_of_basis {\u03b9 : Type*} (b : basis \u03b9 R P) : projective R P :=\nbegin\n  -- need P \u2192\u2097 (P \u2192\u2080 R) for definition of projective.\n  -- get it from `\u03b9 \u2192 (P \u2192\u2080 R)` coming from `b`.\n  use b.constr \u2115 (\u03bb i, finsupp.single (b i) (1 : R)),\n  intro m,\n  simp only [b.constr_apply, mul_one, id.def, finsupp.smul_single', finsupp.total_single,\n    linear_map.map_finsupp_sum],\n  exact b.total_repr m,\nend\n\n@[priority 100]\ninstance projective_of_free [module.free R P] : module.projective R P :=\nprojective_of_basis $ module.free.choose_basis R P\n\nend ring\n\nend module\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/module/projective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676514011486, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.731573477271909}}
{"text": "import tactic\nimport algebra.ring\n\nsection defs\n/- Let R be an arbitrary commutative ring -/\nvariables (R : Type*) [comm_ring R]\n\n/- Definition of an ideal.\n  In order to define an ideal, one needs to specify its\n  underlying set (carrier), as well as three proofs\n-/\n@[ext] structure ideal :=\n(carrier : set R)\n(zero_mem' : (0 : R) \u2208 carrier)\n(add_mem' {x y : R} : x \u2208 carrier \u2192 y \u2208 carrier \u2192 x + y \u2208 carrier)\n(smul_mem' (r : R) {x : R} : x \u2208 carrier \u2192 r*x \u2208 carrier)\n\n/- The set {0} is an ideal -/\ninstance : has_zero (ideal R) := \u27e8{\n  carrier := {0}, --the singleton set containing 0\n  zero_mem' := rfl, --proof that 0 \u2208 {0}\n  add_mem' := \u03bb x y hx hy, by simp * at *, --proof that if x \u2208 {0} and y \u2208 {0}, then\n                                          -- x + y \u2208 {0}. \"simp\" is a tactic that is\n                                          -- able to perform basic simplifications,\n                                          -- so it can replace the hypothesis x \u2208 {0}\n                                          -- with x = 0, and it knows 0 + 0 = 0.\n  smul_mem' := \u03bb r x hx, by simp * at *   --simp also knows r*0 = 0\n}\u27e9\n\n/- R itself is an ideal-/\ndef univ : ideal R := {\n  carrier := set.univ, --set.univ is the set of all elements of R\n  zero_mem' := by triv,\n  add_mem' := by simp,\n  smul_mem' := by simp\n}\n\n/- Definition of a principal ideal -/\ndef prin {R : Type*} [comm_ring R] (x : R) : ideal R := {\n  carrier := {r : R | \u2203 s : R, r = s*x},\n  zero_mem' := \u27e80, (zero_mul x).symm\u27e9,\n  add_mem' :=\n    begin\n      rintros _ _ \u27e8a, rfl\u27e9 \u27e8b, rfl\u27e9, --if a*x, b*x \u2208 prin x...\n      exact \u27e8a + b, by rw \u2190 add_mul\u27e9, --then a*x + b*x = (a + b)*x \u2208 prin x\n    end,\n  smul_mem' :=\n    begin\n      rintros r _ \u27e8a, rfl\u27e9, -- if a*x \u2208 prin x...\n      exact \u27e8r * a, (mul_assoc _ _ _).symm\u27e9 -- then r*(a*x) = (r*a)*x \u2208 prin x\n    end\n}\n\nlemma univ_eq_prin_one : univ R = prin (1 : R) :=\nbegin\n  ext,\n  split,\n  { intro h,\n    simp [prin],}, --what is going on here??\n  { intro h,\n    triv,\n  },\nend\n\nend defs\n\n/- Here we define the membership relation, as well as any\n  operations on ideals: intersection, sum, etc.\n  We could also add a lot from e.g. Atiyah MacDonald ch 1:\n  ideal quotients, radical ideals, the radical operation,\n  and facts about these objects.\n-/\nsection operations\nvariables {R : Type*} [comm_ring R]\n\n/- This lets us write r \u2208 I for r : R and I : ideal R -/\ninstance : has_mem R (ideal R) := \u27e8\u03bb x I, x \u2208 I.carrier\u27e9\n/- This lets us write I \u2286 J for I J : ideal R -/\ninstance : has_subset (ideal R) := \u27e8\u03bb I J, I.carrier \u2286 J.carrier\u27e9\n/- This lets us write I \u2282 J for I J : ideal R -/\ninstance : has_ssubset (ideal R) := \u27e8\u03bb I J, I.carrier \u2282 J.carrier\u27e9\n/- This lets us write I \u2229 J for I J : ideal R -/\ninstance : has_inter (ideal R) := \u27e8\u03bb I J,\n  {\n    carrier := I.carrier \u2229 J.carrier,\n    zero_mem' := \u27e8I.zero_mem', J.zero_mem'\u27e9,\n    add_mem' := \u03bb x y hx hy, \u27e8I.add_mem' hx.1 hy.1, J.add_mem' hx.2 hy.2\u27e9,\n    smul_mem' := \u03bb r x hx, \u27e8I.smul_mem' r hx.1, J.smul_mem' r hx.2\u27e9,\n  }\u27e9\n\n/- This lets us write I + J for I J : ideal R -/\ninstance : has_add (ideal R) := \u27e8\u03bb I J,\n  {\n    carrier := {x | \u2203 i j : R, i \u2208 I \u2227 j \u2208 J \u2227 x = i + j},\n    zero_mem' := \u27e80,0, I.zero_mem', J.zero_mem', by simp\u27e9,\n    add_mem' :=\n      begin\n        rintros _ _ \u27e8ix, jx, hix, hjx, rfl\u27e9 \u27e8iy, jy, hiy, hjy, rfl\u27e9,\n        exact \u27e8ix + iy, jx + jy, I.add_mem' hix hiy, J.add_mem' hjx hjy, by ring\u27e9,\n      end,\n    smul_mem' :=\n      begin\n        rintros r _ \u27e8i, j, hi, hj, rfl\u27e9,\n        exact \u27e8r*i, r*j, I.smul_mem' r hi, J.smul_mem' r hj, by ring\u27e9\n      end\n  }\u27e9\n\ndef union_of_directed_family {I} [inhabited I] (f : I \u2192 ideal R) (d : directed (\u2286) f) : ideal R := {\n  carrier := \u22c3 i, (f i).carrier,\n  zero_mem' := \u27e8(f (arbitrary I)).carrier, \u27e8arbitrary I, eq.refl _\u27e9, ideal.zero_mem' _\u27e9,\n  add_mem' := by {\n    intros x y hx hy,\n    cases hx with S hx, cases hx with w hx, cases w with i hi, subst hi,\n    cases hy with S' hy, cases hy with w hy, cases w with j hj, subst hj,\n    cases d i j with k hk, \n    existsi (f k).carrier, existsi _,\n    { cases hk, apply ideal.add_mem', \n      { apply hk_left, assumption },\n      { apply hk_right, assumption } },\n    { existsi k, refl } },\n  smul_mem' := by {\n    intros x r hx, cases hx with S hx, cases hx with w hx, cases w with i hi, subst hi,\n    existsi (f i).carrier, existsi _,\n    { apply ideal.smul_mem', assumption },\n    { existsi i, refl }\n  }\n}\n\n/- Easy lemmas -/\n@[simp] lemma zero_mem (I : ideal R) : (0 : R) \u2208 I := I.zero_mem'\n@[simp] lemma sub_add_left (I J : ideal R) : I \u2286 I + J := \u03bb i hi, \u27e8i, 0, hi, by simp\u27e9\n@[simp] lemma sub_add_right (I J : ideal R) : J \u2286 I + J := \u03bb j hj, \u27e80, j, by simp, hj, by simp\u27e9\n\nend operations\n\nlemma mem_prin {R : Type*} [comm_ring R] (x : R) : x \u2208 prin x := \u27e81, by simp\u27e9\n\n\n/- Definitions and facts about prime and maximal ideals -/\nvariables {R : Type*} [comm_ring R]\ndef is_prin (I : ideal R) := \u2203 (x : R), I = prin x\ndef radical (I : ideal R) := \u2200 (x : R) (n : \u2115), x^(n + 1) \u2208 I \u2192 x \u2208 I\ndef prime (I : ideal R) := ((1 : R) \u2209 I) \u2227 (\u2200 x y : R, x*y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I)\ndef maximal (I : ideal R) := (1 : R) \u2209 I \u2227 \u2200 J : ideal R, I \u2282 J \u2192 J = univ R\n\n/- TODO replace prime with ideal.prime, etc -/\n-- (preimage my_ideal_object).prime\n--example : \u00ac (univ R).prime :=\n--begin\n--  intro h,\n--  unfold ideal.prime at h,\n--  apply h.1,\n--  triv,\n--end\n\nlemma is_unit_iff (x : R) : is_unit x \u2194 \u2203 y : R, x*y = 1 :=\n  begin\n    split,\n    { intro h,\n      rcases h with \u27e8x,rfl\u27e9,\n      cases x with x y h1 h2,\n      use y,\n      exact h1,\n    },\n    { rintros \u27e8y,hy\u27e9,\n      unfold is_unit,\n      use x,\n      exact y,\n      exact hy,\n      rw mul_comm,\n      exact hy,\n      refl,\n    }\n  end\ndef irreducible (x : R) := \u2200 y z : R, y*z = x \u2192 is_unit y \u2228 is_unit z\ndef preimage {S : Type*} [comm_ring S] (f: S \u2192+* R) (I : ideal R) : ideal S :=\n  { carrier := f \u207b\u00b9' (I.carrier),\n    zero_mem' := by simp[map_zero f, ideal.zero_mem'],\n    add_mem' := \u03bb x y hx hy, by simp [ideal.add_mem' I hx hy],\n    smul_mem' := \u03bb r x hx, by simp [ideal.smul_mem' I (f r) hx],\n  }\n@[simp] lemma mem_preimage_iff {S : Type*} [comm_ring S] (f: S \u2192+* R) (I : ideal R) (x : S) :\n    x \u2208 preimage f I \u2194 f x \u2208 I := iff.rfl\n\n/- Pretty messy, definitely could use more outside lemmas\n  This is what formalizing proofs \"usually\" looks like,\n  with the entire thing written in tactic mode\n-/\ntheorem prime_of_maximal {I : ideal R} (hI : maximal I) : prime I :=\nbegin\n  split,\n  exact hI.1,\n  intros x y hxy,\n  by_cases h : x \u2208 I,\n  { left,\n    exact h\n  },\n  { right,\n    have h2 := sub_add_left I (prin x),\n    have h3 : I \u2282 I + (prin x),\n    {\n      unfold has_ssubset.ssubset,\n      simp,\n      rw set.ssubset_iff_of_subset,\n      use x,\n      exact \u27e8(sub_add_right I (prin x)) (mem_prin x), h\u27e9,\n      exact h2,\n    },\n    have h4 := hI.2 (I + prin x) h3,\n    have h5 : (1 : R) \u2208 univ R := by simp [univ],\n    rw \u2190 h4 at h5,\n    rcases h5 with \u27e8i, _, hi, \u27e8s, rfl\u27e9, hh\u27e9,\n    rw \u2190 (one_mul y),\n    rw hh,\n    rw add_mul,\n    apply I.add_mem',\n    { rw mul_comm,\n      exact I.smul_mem' y hi,\n    },\n    { rw mul_assoc,\n      exact I.smul_mem' s hxy,\n    }\n  }\nend\n\ntheorem prime_of_preimage {S : Type*} [comm_ring S]\n  (f : R \u2192+* S) {I : ideal S}\n  (hI : prime I) : prime (preimage f I) :=\nbegin\n  unfold prime,\n  split,\n  { intros h1,\n    simp * at *,\n    exact hI.1 h1,},\n  { intros x y g,\n    simp only [mem_preimage_iff, map_mul] at *,\n    exact hI.2 _ _ g,}\nend\n\ntheorem radical_of_prime {I : ideal R} (hI : prime I) : radical I :=\nbegin\n  intros x n h,\n  induction n with m hm,\n  { simp at h,\n    exact h,\n  },\n  {\n    have h2 : x*x^(m+1) \u2208 I,\n    {\n      convert h,\n      rw nat.succ_eq_add_one,\n      repeat {rw pow_add},\n      ring,\n    },\n    cases (hI.2 x (x^(m+1)) h2) with hx hbig,\n    {\n      exact hx,\n    },\n    {\n      exact hm hbig,\n    }\n  }\nend", "meta": {"author": "leomayer1", "repo": "WXML_Sp2022", "sha": "214629a945e942e589c1526e9dbd042cad48c03f", "save_path": "github-repos/lean/leomayer1-WXML_Sp2022", "path": "github-repos/lean/leomayer1-WXML_Sp2022/WXML_Sp2022-214629a945e942e589c1526e9dbd042cad48c03f/src/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.8175744828610096, "lm_q1q2_score": 0.7315570373120754}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.exp_deriv\n\n/-!\n# Differentiability of trigonometric functions\n\n## Main statements\n\nThe differentiability of the usual trigonometric functions is proved, and their derivatives are\ncomputed.\n\n## Tags\n\nsin, cos, tan, angle\n-/\n\nnoncomputable theory\nopen_locale classical topological_space filter\nopen set filter\n\nnamespace complex\n\n/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/\nlemma has_strict_deriv_at_sin (x : \u2102) : has_strict_deriv_at sin (cos x) x :=\nbegin\n  simp only [cos, div_eq_mul_inv],\n  convert ((((has_strict_deriv_at_id x).neg.mul_const I).cexp.sub\n    ((has_strict_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:\u2102)\u207b\u00b9,\n  simp only [function.comp, id],\n  rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,\n      I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]\nend\n\n/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/\nlemma has_deriv_at_sin (x : \u2102) : has_deriv_at sin (cos x) x :=\n(has_strict_deriv_at_sin x).has_deriv_at\n\nlemma cont_diff_sin {n} : cont_diff \u2102 n sin :=\n(((cont_diff_neg.mul cont_diff_const).cexp.sub\n  (cont_diff_id.mul cont_diff_const).cexp).mul cont_diff_const).div_const\n\nlemma differentiable_sin : differentiable \u2102 sin :=\n\u03bbx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin {x : \u2102} : differentiable_at \u2102 sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ \u03bb x, (has_deriv_at_sin x).deriv\n\n/-- The complex cosine function is everywhere strictly differentiable, with the derivative\n`-sin x`. -/\nlemma has_strict_deriv_at_cos (x : \u2102) : has_strict_deriv_at cos (-sin x) x :=\nbegin\n  simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],\n  convert (((has_strict_deriv_at_id x).mul_const I).cexp.add\n    ((has_strict_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:\u2102)\u207b\u00b9,\n  simp only [function.comp, id],\n  ring\nend\n\n/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/\nlemma has_deriv_at_cos (x : \u2102) : has_deriv_at cos (-sin x) x :=\n(has_strict_deriv_at_cos x).has_deriv_at\n\nlemma cont_diff_cos {n} : cont_diff \u2102 n cos :=\n((cont_diff_id.mul cont_diff_const).cexp.add\n  (cont_diff_neg.mul cont_diff_const).cexp).div_const\n\nlemma differentiable_cos : differentiable \u2102 cos :=\n\u03bbx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos {x : \u2102} : differentiable_at \u2102 cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos {x : \u2102} : deriv cos x = -sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (\u03bb x, -sin x) :=\nfunext $ \u03bb x, deriv_cos\n\n/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative\n`cosh x`. -/\nlemma has_strict_deriv_at_sinh (x : \u2102) : has_strict_deriv_at sinh (cosh x) x :=\nbegin\n  simp only [cosh, div_eq_mul_inv],\n  convert ((has_strict_deriv_at_exp x).sub (has_strict_deriv_at_id x).neg.cexp).mul_const (2:\u2102)\u207b\u00b9,\n  rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]\nend\n\n/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative\n`cosh x`. -/\nlemma has_deriv_at_sinh (x : \u2102) : has_deriv_at sinh (cosh x) x :=\n(has_strict_deriv_at_sinh x).has_deriv_at\n\nlemma cont_diff_sinh {n} : cont_diff \u2102 n sinh :=\n(cont_diff_exp.sub cont_diff_neg.cexp).div_const\n\nlemma differentiable_sinh : differentiable \u2102 sinh :=\n\u03bbx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh {x : \u2102} : differentiable_at \u2102 sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ \u03bb x, (has_deriv_at_sinh x).deriv\n\n/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the\nderivative `sinh x`. -/\nlemma has_strict_deriv_at_cosh (x : \u2102) : has_strict_deriv_at cosh (sinh x) x :=\nbegin\n  simp only [sinh, div_eq_mul_inv],\n  convert ((has_strict_deriv_at_exp x).add (has_strict_deriv_at_id x).neg.cexp).mul_const (2:\u2102)\u207b\u00b9,\n  rw [id, mul_neg_one, sub_eq_add_neg]\nend\n\n/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative\n`sinh x`. -/\nlemma has_deriv_at_cosh (x : \u2102) : has_deriv_at cosh (sinh x) x :=\n(has_strict_deriv_at_cosh x).has_deriv_at\n\nlemma cont_diff_cosh {n} : cont_diff \u2102 n cosh :=\n(cont_diff_exp.add cont_diff_neg.cexp).div_const\n\nlemma differentiable_cosh : differentiable \u2102 cosh :=\n\u03bbx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh {x : \u2102} : differentiable_at \u2102 cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ \u03bb x, (has_deriv_at_cosh x).deriv\n\nend complex\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, complex.cos (f x)` etc., `f : \u2102 \u2192 \u2102` -/\n\nvariables {f : \u2102 \u2192 \u2102} {f' x : \u2102} {s : set \u2102}\n\n/-! #### `complex.cos` -/\n\nlemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') x :=\n(complex.has_strict_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') x :=\n(complex.has_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=\n(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_ccos (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.ccos.deriv_within hxs\n\n@[simp] lemma deriv_ccos (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=\nhc.has_deriv_at.ccos.deriv\n\n/-! #### `complex.sin` -/\n\nlemma has_strict_deriv_at.csin (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') x :=\n(complex.has_strict_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_at.csin (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') x :=\n(complex.has_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') s x :=\n(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_csin (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.csin.deriv_within hxs\n\n@[simp] lemma deriv_csin (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=\nhc.has_deriv_at.csin.deriv\n\n/-! #### `complex.cosh` -/\n\nlemma has_strict_deriv_at.ccosh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=\n(complex.has_strict_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=\n(complex.has_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_ccosh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.ccosh.deriv_within hxs\n\n@[simp] lemma deriv_ccosh (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=\nhc.has_deriv_at.ccosh.deriv\n\n/-! #### `complex.sinh` -/\n\nlemma has_strict_deriv_at.csinh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=\n(complex.has_strict_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=\n(complex.has_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_csinh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.csinh.deriv_within hxs\n\n@[simp] lemma deriv_csinh (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=\nhc.has_deriv_at.csinh.deriv\n\nend\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, complex.cos (f x)` etc., `f : E \u2192 \u2102` -/\n\nvariables {E : Type*} [normed_group E] [normed_space \u2102 E] {f : E \u2192 \u2102} {f' : E \u2192L[\u2102] \u2102}\n  {x : E} {s : set E}\n\n/-! #### `complex.cos` -/\n\nlemma has_strict_fderiv_at.ccos (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') x :=\n(complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') s x :=\n(complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.ccos (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.cos (f x)) s x :=\nhf.has_fderiv_within_at.ccos.differentiable_within_at\n\n@[simp] lemma differentiable_at.ccos (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.cos (f x)) x :=\nhc.has_fderiv_at.ccos.differentiable_at\n\nlemma differentiable_on.ccos (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.cos (f x)) s :=\n\u03bbx h, (hc x h).ccos\n\n@[simp] lemma differentiable.ccos (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.cos (f x)) :=\n\u03bbx, (hc x).ccos\n\nlemma fderiv_within_ccos (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.cos (f x)) s x = - complex.sin (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.ccos.fderiv_within hxs\n\n@[simp] lemma fderiv_ccos (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.cos (f x)) x = - complex.sin (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.ccos.fderiv\n\nlemma cont_diff.ccos {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.cos (f x)) :=\ncomplex.cont_diff_cos.comp h\n\nlemma cont_diff_at.ccos {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.cos (f x)) x :=\ncomplex.cont_diff_cos.cont_diff_at.comp x hf\n\nlemma cont_diff_on.ccos {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.cos (f x)) s :=\ncomplex.cont_diff_cos.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.ccos {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.cos (f x)) s x :=\ncomplex.cont_diff_cos.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `complex.sin` -/\n\nlemma has_strict_fderiv_at.csin (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') x :=\n(complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') s x :=\n(complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.csin (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.sin (f x)) s x :=\nhf.has_fderiv_within_at.csin.differentiable_within_at\n\n@[simp] lemma differentiable_at.csin (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.sin (f x)) x :=\nhc.has_fderiv_at.csin.differentiable_at\n\nlemma differentiable_on.csin (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.sin (f x)) s :=\n\u03bbx h, (hc x h).csin\n\n@[simp] lemma differentiable.csin (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.sin (f x)) :=\n\u03bbx, (hc x).csin\n\nlemma fderiv_within_csin (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.sin (f x)) s x = complex.cos (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.csin.fderiv_within hxs\n\n@[simp] lemma fderiv_csin (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.sin (f x)) x = complex.cos (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.csin.fderiv\n\nlemma cont_diff.csin {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.sin (f x)) :=\ncomplex.cont_diff_sin.comp h\n\nlemma cont_diff_at.csin {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.sin (f x)) x :=\ncomplex.cont_diff_sin.cont_diff_at.comp x hf\n\nlemma cont_diff_on.csin {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.sin (f x)) s :=\ncomplex.cont_diff_sin.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.csin {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.sin (f x)) s x :=\ncomplex.cont_diff_sin.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `complex.cosh` -/\n\nlemma has_strict_fderiv_at.ccosh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') s x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.ccosh (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.cosh (f x)) s x :=\nhf.has_fderiv_within_at.ccosh.differentiable_within_at\n\n@[simp] lemma differentiable_at.ccosh (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.cosh (f x)) x :=\nhc.has_fderiv_at.ccosh.differentiable_at\n\nlemma differentiable_on.ccosh (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.cosh (f x)) s :=\n\u03bbx h, (hc x h).ccosh\n\n@[simp] lemma differentiable.ccosh (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.cosh (f x)) :=\n\u03bbx, (hc x).ccosh\n\nlemma fderiv_within_ccosh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.cosh (f x)) s x = complex.sinh (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.ccosh.fderiv_within hxs\n\n@[simp] lemma fderiv_ccosh (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.cosh (f x)) x = complex.sinh (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.ccosh.fderiv\n\nlemma cont_diff.ccosh {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.cosh (f x)) :=\ncomplex.cont_diff_cosh.comp h\n\nlemma cont_diff_at.ccosh {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.cosh (f x)) x :=\ncomplex.cont_diff_cosh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.ccosh {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.cosh (f x)) s :=\ncomplex.cont_diff_cosh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.ccosh {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.cosh (f x)) s x :=\ncomplex.cont_diff_cosh.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `complex.sinh` -/\n\nlemma has_strict_fderiv_at.csinh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') s x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.csinh (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.sinh (f x)) s x :=\nhf.has_fderiv_within_at.csinh.differentiable_within_at\n\n@[simp] lemma differentiable_at.csinh (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.sinh (f x)) x :=\nhc.has_fderiv_at.csinh.differentiable_at\n\nlemma differentiable_on.csinh (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.sinh (f x)) s :=\n\u03bbx h, (hc x h).csinh\n\n@[simp] lemma differentiable.csinh (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.sinh (f x)) :=\n\u03bbx, (hc x).csinh\n\nlemma fderiv_within_csinh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.sinh (f x)) s x = complex.cosh (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.csinh.fderiv_within hxs\n\n@[simp] lemma fderiv_csinh (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.sinh (f x)) x = complex.cosh (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.csinh.fderiv\n\nlemma cont_diff.csinh {n} (h : cont_diff \u2102 n f) :\n  cont_diff \u2102 n (\u03bb x, complex.sinh (f x)) :=\ncomplex.cont_diff_sinh.comp h\n\nlemma cont_diff_at.csinh {n} (hf : cont_diff_at \u2102 n f x) :\n  cont_diff_at \u2102 n (\u03bb x, complex.sinh (f x)) x :=\ncomplex.cont_diff_sinh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.csinh {n} (hf : cont_diff_on \u2102 n f s) :\n  cont_diff_on \u2102 n (\u03bb x, complex.sinh (f x)) s :=\ncomplex.cont_diff_sinh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.csinh {n} (hf : cont_diff_within_at \u2102 n f s x) :\n  cont_diff_within_at \u2102 n (\u03bb x, complex.sinh (f x)) s x :=\ncomplex.cont_diff_sinh.cont_diff_at.comp_cont_diff_within_at x hf\n\nend\n\nnamespace real\n\nvariables {x y z : \u211d}\n\nlemma has_strict_deriv_at_sin (x : \u211d) : has_strict_deriv_at sin (cos x) x :=\n(complex.has_strict_deriv_at_sin x).real_of_complex\n\nlemma has_deriv_at_sin (x : \u211d) : has_deriv_at sin (cos x) x :=\n(has_strict_deriv_at_sin x).has_deriv_at\n\nlemma cont_diff_sin {n} : cont_diff \u211d n sin :=\ncomplex.cont_diff_sin.real_of_complex\n\nlemma differentiable_sin : differentiable \u211d sin :=\n\u03bbx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin : differentiable_at \u211d sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ \u03bb x, (has_deriv_at_sin x).deriv\n\nlemma has_strict_deriv_at_cos (x : \u211d) : has_strict_deriv_at cos (-sin x) x :=\n(complex.has_strict_deriv_at_cos x).real_of_complex\n\nlemma has_deriv_at_cos (x : \u211d) : has_deriv_at cos (-sin x) x :=\n(complex.has_deriv_at_cos x).real_of_complex\n\nlemma cont_diff_cos {n} : cont_diff \u211d n cos :=\ncomplex.cont_diff_cos.real_of_complex\n\nlemma differentiable_cos : differentiable \u211d cos :=\n\u03bbx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos : differentiable_at \u211d cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos : deriv cos x = - sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (\u03bb x, - sin x) :=\nfunext $ \u03bb _, deriv_cos\n\nlemma has_strict_deriv_at_sinh (x : \u211d) : has_strict_deriv_at sinh (cosh x) x :=\n(complex.has_strict_deriv_at_sinh x).real_of_complex\n\nlemma has_deriv_at_sinh (x : \u211d) : has_deriv_at sinh (cosh x) x :=\n(complex.has_deriv_at_sinh x).real_of_complex\n\nlemma cont_diff_sinh {n} : cont_diff \u211d n sinh :=\ncomplex.cont_diff_sinh.real_of_complex\n\nlemma differentiable_sinh : differentiable \u211d sinh :=\n\u03bbx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh : differentiable_at \u211d sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ \u03bb x, (has_deriv_at_sinh x).deriv\n\nlemma has_strict_deriv_at_cosh (x : \u211d) : has_strict_deriv_at cosh (sinh x) x :=\n(complex.has_strict_deriv_at_cosh x).real_of_complex\n\nlemma has_deriv_at_cosh (x : \u211d) : has_deriv_at cosh (sinh x) x :=\n(complex.has_deriv_at_cosh x).real_of_complex\n\nlemma cont_diff_cosh {n} : cont_diff \u211d n cosh :=\ncomplex.cont_diff_cosh.real_of_complex\n\nlemma differentiable_cosh : differentiable \u211d cosh :=\n\u03bbx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh : differentiable_at \u211d cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ \u03bb x, (has_deriv_at_cosh x).deriv\n\n/-- `sinh` is strictly monotone. -/\nlemma sinh_strict_mono : strict_mono sinh :=\nstrict_mono_of_deriv_pos $ by { rw real.deriv_sinh, exact cosh_pos }\n\nend real\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, real.cos (f x)` etc., `f : \u211d \u2192 \u211d` -/\n\nvariables {f : \u211d \u2192 \u211d} {f' x : \u211d} {s : set \u211d}\n\n/-! #### `real.cos` -/\n\nlemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') x :=\n(real.has_strict_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_at.cos (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') x :=\n(real.has_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') s x :=\n(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_cos (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.cos.deriv_within hxs\n\n@[simp] lemma deriv_cos (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=\nhc.has_deriv_at.cos.deriv\n\n/-! #### `real.sin` -/\n\nlemma has_strict_deriv_at.sin (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') x :=\n(real.has_strict_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_at.sin (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') x :=\n(real.has_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') s x :=\n(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_sin (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.sin.deriv_within hxs\n\n@[simp] lemma deriv_sin (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=\nhc.has_deriv_at.sin.deriv\n\n/-! #### `real.cosh` -/\n\nlemma has_strict_deriv_at.cosh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') x :=\n(real.has_strict_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') x :=\n(real.has_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') s x :=\n(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_cosh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.cosh.deriv_within hxs\n\n@[simp] lemma deriv_cosh (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=\nhc.has_deriv_at.cosh.deriv\n\n/-! #### `real.sinh` -/\n\nlemma has_strict_deriv_at.sinh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') x :=\n(real.has_strict_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') x :=\n(real.has_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') s x :=\n(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_sinh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.sinh.deriv_within hxs\n\n@[simp] lemma deriv_sinh (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=\nhc.has_deriv_at.sinh.deriv\n\nend\n\nsection\n\n/-! ### Simp lemmas for derivatives of `\u03bb x, real.cos (f x)` etc., `f : E \u2192 \u211d` -/\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E] {f : E \u2192 \u211d} {f' : E \u2192L[\u211d] \u211d}\n  {x : E} {s : set E}\n\n/-! #### `real.cos` -/\n\nlemma has_strict_fderiv_at.cos (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') x :=\n(real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') s x :=\n(real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.cos (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.cos (f x)) s x :=\nhf.has_fderiv_within_at.cos.differentiable_within_at\n\n@[simp] lemma differentiable_at.cos (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.cos (f x)) x :=\nhc.has_fderiv_at.cos.differentiable_at\n\nlemma differentiable_on.cos (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.cos (f x)) s :=\n\u03bbx h, (hc x h).cos\n\n@[simp] lemma differentiable.cos (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.cos (f x)) :=\n\u03bbx, (hc x).cos\n\nlemma fderiv_within_cos (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.cos (f x)) s x = - real.sin (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.cos.fderiv_within hxs\n\n@[simp] lemma fderiv_cos (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.cos (f x)) x = - real.sin (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.cos.fderiv\n\nlemma cont_diff.cos {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.cos (f x)) :=\nreal.cont_diff_cos.comp h\n\nlemma cont_diff_at.cos {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.cos (f x)) x :=\nreal.cont_diff_cos.cont_diff_at.comp x hf\n\nlemma cont_diff_on.cos {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.cos (f x)) s :=\nreal.cont_diff_cos.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.cos {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.cos (f x)) s x :=\nreal.cont_diff_cos.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `real.sin` -/\n\nlemma has_strict_fderiv_at.sin (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') x :=\n(real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') s x :=\n(real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.sin (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.sin (f x)) s x :=\nhf.has_fderiv_within_at.sin.differentiable_within_at\n\n@[simp] lemma differentiable_at.sin (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.sin (f x)) x :=\nhc.has_fderiv_at.sin.differentiable_at\n\nlemma differentiable_on.sin (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.sin (f x)) s :=\n\u03bbx h, (hc x h).sin\n\n@[simp] lemma differentiable.sin (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.sin (f x)) :=\n\u03bbx, (hc x).sin\n\nlemma fderiv_within_sin (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.sin (f x)) s x = real.cos (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.sin.fderiv_within hxs\n\n@[simp] lemma fderiv_sin (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.sin (f x)) x = real.cos (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.sin.fderiv\n\nlemma cont_diff.sin {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.sin (f x)) :=\nreal.cont_diff_sin.comp h\n\nlemma cont_diff_at.sin {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.sin (f x)) x :=\nreal.cont_diff_sin.cont_diff_at.comp x hf\n\nlemma cont_diff_on.sin {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.sin (f x)) s :=\nreal.cont_diff_sin.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.sin {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.sin (f x)) s x :=\nreal.cont_diff_sin.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `real.cosh` -/\n\nlemma has_strict_fderiv_at.cosh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') x :=\n(real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') s x :=\n(real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.cosh (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.cosh (f x)) s x :=\nhf.has_fderiv_within_at.cosh.differentiable_within_at\n\n@[simp] lemma differentiable_at.cosh (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.cosh (f x)) x :=\nhc.has_fderiv_at.cosh.differentiable_at\n\nlemma differentiable_on.cosh (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.cosh (f x)) s :=\n\u03bbx h, (hc x h).cosh\n\n@[simp] lemma differentiable.cosh (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.cosh (f x)) :=\n\u03bbx, (hc x).cosh\n\nlemma fderiv_within_cosh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.cosh (f x)) s x = real.sinh (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.cosh.fderiv_within hxs\n\n@[simp] lemma fderiv_cosh (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.cosh (f x)) x = real.sinh (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.cosh.fderiv\n\nlemma cont_diff.cosh {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.cosh (f x)) :=\nreal.cont_diff_cosh.comp h\n\nlemma cont_diff_at.cosh {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.cosh (f x)) x :=\nreal.cont_diff_cosh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.cosh {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.cosh (f x)) s :=\nreal.cont_diff_cosh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.cosh {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.cosh (f x)) s x :=\nreal.cont_diff_cosh.cont_diff_at.comp_cont_diff_within_at x hf\n\n/-! #### `real.sinh` -/\n\nlemma has_strict_fderiv_at.sinh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') x :=\n(real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') s x :=\n(real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.sinh (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.sinh (f x)) s x :=\nhf.has_fderiv_within_at.sinh.differentiable_within_at\n\n@[simp] lemma differentiable_at.sinh (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.sinh (f x)) x :=\nhc.has_fderiv_at.sinh.differentiable_at\n\nlemma differentiable_on.sinh (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.sinh (f x)) s :=\n\u03bbx h, (hc x h).sinh\n\n@[simp] lemma differentiable.sinh (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.sinh (f x)) :=\n\u03bbx, (hc x).sinh\n\nlemma fderiv_within_sinh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.sinh (f x)) s x = real.cosh (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.sinh.fderiv_within hxs\n\n@[simp] lemma fderiv_sinh (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.sinh (f x)) x = real.cosh (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.sinh.fderiv\n\nlemma cont_diff.sinh {n} (h : cont_diff \u211d n f) :\n  cont_diff \u211d n (\u03bb x, real.sinh (f x)) :=\nreal.cont_diff_sinh.comp h\n\nlemma cont_diff_at.sinh {n} (hf : cont_diff_at \u211d n f x) :\n  cont_diff_at \u211d n (\u03bb x, real.sinh (f x)) x :=\nreal.cont_diff_sinh.cont_diff_at.comp x hf\n\nlemma cont_diff_on.sinh {n} (hf : cont_diff_on \u211d n f s) :\n  cont_diff_on \u211d n (\u03bb x, real.sinh (f x)) s :=\nreal.cont_diff_sinh.comp_cont_diff_on  hf\n\nlemma cont_diff_within_at.sinh {n} (hf : cont_diff_within_at \u211d n f s x) :\n  cont_diff_within_at \u211d n (\u03bb x, real.sinh (f x)) s x :=\nreal.cont_diff_sinh.cont_diff_at.comp_cont_diff_within_at x hf\n\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/special_functions/trigonometric/deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7315570327244544}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport set_theory.pgame\n\n/-!\n# Basic definitions about who has a winning stratergy\n\nWe define `G.first_loses`, `G.first_wins`, `G.left_wins` and `G.right_wins` for a pgame `G`, which\nmeans the second, first, left and right players have a winning strategy respectively.\nThese are defined by inequalities which can be unfolded with `pgame.lt_def` and `pgame.le_def`.\n-/\n\nnamespace pgame\n\nlocal infix ` \u2248 ` := equiv\n\n/-- The player who goes first loses -/\ndef first_loses (G : pgame) : Prop := G \u2264 0 \u2227 0 \u2264 G\n\n/-- The player who goes first wins -/\ndef first_wins (G : pgame) : Prop := 0 < G \u2227 G < 0\n\n/-- The left player can always win -/\ndef left_wins (G : pgame) : Prop := 0 < G \u2227 0 \u2264 G\n\n/-- The right player can always win -/\ndef right_wins (G : pgame) : Prop := G \u2264 0 \u2227 G < 0\n\ntheorem zero_first_loses : first_loses 0 := by tidy\ntheorem one_left_wins : left_wins 1 :=\n\u27e8by { rw lt_def_le, tidy }, by rw le_def; tidy\u27e9\n\ntheorem star_first_wins : first_wins star := \u27e8zero_lt_star, star_lt_zero\u27e9\ntheorem omega_left_wins : left_wins omega :=\n\u27e8by { rw lt_def_le, exact or.inl \u27e8ulift.up 0, by tidy\u27e9 }, by rw le_def; tidy\u27e9\n\nlemma winner_cases (G : pgame) : G.left_wins \u2228 G.right_wins \u2228 G.first_loses \u2228 G.first_wins :=\nbegin\n  classical,\n  by_cases hpos : 0 < G;\n  by_cases hneg : G < 0;\n  { try { rw not_lt at hpos },\n    try { rw not_lt at hneg },\n    try { left, exact \u27e8hpos, hneg\u27e9 },\n    try { right, left, exact \u27e8hpos, hneg\u27e9 },\n    try { right, right, left, exact \u27e8hpos, hneg\u27e9 },\n    try { right, right, right, exact \u27e8hpos, hneg\u27e9 } }\nend\n\nlemma first_loses_is_zero {G : pgame} : G.first_loses \u2194 G \u2248 0 := by refl\n\nlemma first_loses_of_equiv {G H : pgame} (h : G \u2248 H) : G.first_loses \u2192 H.first_loses :=\n\u03bb hGp, \u27e8le_of_equiv_of_le h.symm hGp.1, le_of_le_of_equiv hGp.2 h\u27e9\nlemma first_wins_of_equiv {G H : pgame} (h : G \u2248 H) : G.first_wins \u2192 H.first_wins :=\n\u03bb hGn, \u27e8lt_of_lt_of_equiv hGn.1 h, lt_of_equiv_of_lt h.symm hGn.2\u27e9\nlemma left_wins_of_equiv {G H : pgame} (h : G \u2248 H) : G.left_wins \u2192 H.left_wins :=\n\u03bb hGl, \u27e8lt_of_lt_of_equiv hGl.1 h, le_of_le_of_equiv hGl.2 h\u27e9\nlemma right_wins_of_equiv {G H : pgame} (h : G \u2248 H) : G.right_wins \u2192 H.right_wins :=\n\u03bb hGr, \u27e8le_of_equiv_of_le h.symm hGr.1, lt_of_equiv_of_lt h.symm hGr.2\u27e9\n\nlemma first_loses_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.first_loses \u2194 H.first_loses :=\n\u27e8first_loses_of_equiv h, first_loses_of_equiv h.symm\u27e9\nlemma first_wins_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.first_wins \u2194 H.first_wins :=\n\u27e8first_wins_of_equiv h, first_wins_of_equiv h.symm\u27e9\nlemma left_wins_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.left_wins \u2194 H.left_wins :=\n\u27e8left_wins_of_equiv h, left_wins_of_equiv h.symm\u27e9\nlemma right_wins_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.right_wins \u2194 H.right_wins :=\n\u27e8right_wins_of_equiv h, right_wins_of_equiv h.symm\u27e9\n\nlemma not_first_wins_of_first_loses {G : pgame} : G.first_loses \u2192 \u00acG.first_wins :=\nbegin\n  rw first_loses_is_zero,\n  rintros h \u27e8h\u2080, -\u27e9,\n  exact lt_irrefl 0 (lt_of_lt_of_equiv h\u2080 h)\nend\n\nlemma not_first_loses_of_first_wins {G : pgame} : G.first_wins \u2192 \u00acG.first_loses :=\nimp_not_comm.1 $ not_first_wins_of_first_loses\n\nend pgame\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/set_theory/game/winner.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7315570162050558}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.set.intervals.basic\nimport Mathlib.algebra.ordered_group\nimport Mathlib.PostPort\n\nuniverses u u_1 w v \n\nnamespace Mathlib\n\n/-!\n\n# Upper / lower bounds\n\nIn this file we define:\n\n* `upper_bounds`, `lower_bounds` : the set of upper bounds (resp., lower bounds) of a set;\n* `bdd_above s`, `bdd_below s` : the set `s` is bounded above (resp., below), i.e., the set of upper\n  (resp., lower) bounds of `s` is nonempty;\n* `is_least s a`, `is_greatest s a` : `a` is a least (resp., greatest) element of `s`;\n  for a partial order, it is unique if exists;\n* `is_lub s a`, `is_glb s a` : `a` is a least upper bound (resp., a greatest lower bound)\n  of `s`; for a partial order, it is unique if exists.\n\nWe also prove various lemmas about monotonicity, behaviour under `\u222a`, `\u2229`, `insert`, and provide\nformulas for `\u2205`, `univ`, and intervals.\n-/\n\n/-!\n### Definitions\n-/\n\n/-- The set of upper bounds of a set. -/\n/-- The set of lower bounds of a set. -/\ndef upper_bounds {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) : set \u03b1 :=\n  set_of fun (x : \u03b1) => \u2200 {a : \u03b1}, a \u2208 s \u2192 a \u2264 x\n\ndef lower_bounds {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) : set \u03b1 :=\n  set_of fun (x : \u03b1) => \u2200 {a : \u03b1}, a \u2208 s \u2192 x \u2264 a\n\n/-- A set is bounded above if there exists an upper bound. -/\n/-- A set is bounded below if there exists a lower bound. -/\ndef bdd_above {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) := set.nonempty (upper_bounds s)\n\ndef bdd_below {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) := set.nonempty (lower_bounds s)\n\n/-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/\n/-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists -/\ndef is_least {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) (a : \u03b1) := a \u2208 s \u2227 a \u2208 lower_bounds s\n\ndef is_greatest {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) (a : \u03b1) := a \u2208 s \u2227 a \u2208 upper_bounds s\n\n/-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/\n/-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/\ndef is_lub {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) : \u03b1 \u2192 Prop := is_least (upper_bounds s)\n\ndef is_glb {\u03b1 : Type u} [preorder \u03b1] (s : set \u03b1) : \u03b1 \u2192 Prop := is_greatest (lower_bounds s)\n\ntheorem mem_upper_bounds {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} :\n    a \u2208 upper_bounds s \u2194 \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2264 a :=\n  iff.rfl\n\ntheorem mem_lower_bounds {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} :\n    a \u2208 lower_bounds s \u2194 \u2200 (x : \u03b1), x \u2208 s \u2192 a \u2264 x :=\n  iff.rfl\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not greater than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(y \u2264 x)`. A version for linear orders is called `not_bdd_above_iff`. -/\ntheorem not_bdd_above_iff' {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} :\n    \u00acbdd_above s \u2194 \u2200 (x : \u03b1), \u2203 (y : \u03b1), \u2203 (H : y \u2208 s), \u00acy \u2264 x :=\n  sorry\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not less than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(x \u2264 y)`. A version for linear orders is called `not_bdd_below_iff`. -/\ntheorem not_bdd_below_iff' {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} :\n    \u00acbdd_below s \u2194 \u2200 (x : \u03b1), \u2203 (y : \u03b1), \u2203 (H : y \u2208 s), \u00acx \u2264 y :=\n  not_bdd_above_iff'\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` that is greater\nthan `x`. A version for preorders is called `not_bdd_above_iff'`. -/\ntheorem not_bdd_above_iff {\u03b1 : Type u_1} [linear_order \u03b1] {s : set \u03b1} :\n    \u00acbdd_above s \u2194 \u2200 (x : \u03b1), \u2203 (y : \u03b1), \u2203 (H : y \u2208 s), x < y :=\n  sorry\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` that is less\nthan `x`. A version for preorders is called `not_bdd_below_iff'`. -/\ntheorem not_bdd_below_iff {\u03b1 : Type u_1} [linear_order \u03b1] {s : set \u03b1} :\n    \u00acbdd_below s \u2194 \u2200 (x : \u03b1), \u2203 (y : \u03b1), \u2203 (H : y \u2208 s), y < x :=\n  not_bdd_above_iff\n\n/-!\n### Monotonicity\n-/\n\ntheorem upper_bounds_mono_set {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} (hst : s \u2286 t) :\n    upper_bounds t \u2286 upper_bounds s :=\n  fun (b : \u03b1) (hb : b \u2208 upper_bounds t) (x : \u03b1) (h : x \u2208 s) => hb (hst h)\n\ntheorem lower_bounds_mono_set {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} (hst : s \u2286 t) :\n    lower_bounds t \u2286 lower_bounds s :=\n  fun (b : \u03b1) (hb : b \u2208 lower_bounds t) (x : \u03b1) (h : x \u2208 s) => hb (hst h)\n\ntheorem upper_bounds_mono_mem {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (hab : a \u2264 b) :\n    a \u2208 upper_bounds s \u2192 b \u2208 upper_bounds s :=\n  fun (ha : a \u2208 upper_bounds s) (x : \u03b1) (h : x \u2208 s) => le_trans (ha h) hab\n\ntheorem lower_bounds_mono_mem {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (hab : a \u2264 b) :\n    b \u2208 lower_bounds s \u2192 a \u2208 lower_bounds s :=\n  fun (hb : b \u2208 lower_bounds s) (x : \u03b1) (h : x \u2208 s) => le_trans hab (hb h)\n\ntheorem upper_bounds_mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} (hst : s \u2286 t) {a : \u03b1}\n    {b : \u03b1} (hab : a \u2264 b) : a \u2208 upper_bounds t \u2192 b \u2208 upper_bounds s :=\n  fun (ha : a \u2208 upper_bounds t) => upper_bounds_mono_set hst (upper_bounds_mono_mem hab ha)\n\ntheorem lower_bounds_mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} (hst : s \u2286 t) {a : \u03b1}\n    {b : \u03b1} (hab : a \u2264 b) : b \u2208 lower_bounds t \u2192 a \u2208 lower_bounds s :=\n  fun (hb : b \u2208 lower_bounds t) => lower_bounds_mono_set hst (lower_bounds_mono_mem hab hb)\n\n/-- If `s \u2286 t` and `t` is bounded above, then so is `s`. -/\ntheorem bdd_above.mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} (h : s \u2286 t) :\n    bdd_above t \u2192 bdd_above s :=\n  set.nonempty.mono (upper_bounds_mono_set h)\n\n/-- If `s \u2286 t` and `t` is bounded below, then so is `s`. -/\ntheorem bdd_below.mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} (h : s \u2286 t) :\n    bdd_below t \u2192 bdd_below s :=\n  set.nonempty.mono (lower_bounds_mono_set h)\n\n/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\ntheorem is_lub.of_subset_of_superset {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {s : set \u03b1} {t : set \u03b1}\n    {p : set \u03b1} (hs : is_lub s a) (hp : is_lub p a) (hst : s \u2286 t) (htp : t \u2286 p) : is_lub t a :=\n  { left := upper_bounds_mono_set htp (and.left hp),\n    right := lower_bounds_mono_set (upper_bounds_mono_set hst) (and.right hs) }\n\n/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\ntheorem is_glb.of_subset_of_superset {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {s : set \u03b1} {t : set \u03b1}\n    {p : set \u03b1} (hs : is_glb s a) (hp : is_glb p a) (hst : s \u2286 t) (htp : t \u2286 p) : is_glb t a :=\n  is_lub.of_subset_of_superset hs hp hst htp\n\ntheorem is_least.mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (ha : is_least s a) (hb : is_least t b) (hst : s \u2286 t) : b \u2264 a :=\n  and.right hb a (hst (and.left ha))\n\ntheorem is_greatest.mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (ha : is_greatest s a) (hb : is_greatest t b) (hst : s \u2286 t) : a \u2264 b :=\n  and.right hb a (hst (and.left ha))\n\ntheorem is_lub.mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (ha : is_lub s a) (hb : is_lub t b) (hst : s \u2286 t) : a \u2264 b :=\n  is_least.mono hb ha (upper_bounds_mono_set hst)\n\ntheorem is_glb.mono {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (ha : is_glb s a) (hb : is_glb t b) (hst : s \u2286 t) : b \u2264 a :=\n  is_greatest.mono hb ha (lower_bounds_mono_set hst)\n\n/-!\n### Conversions\n-/\n\ntheorem is_least.is_glb {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_least s a) :\n    is_glb s a :=\n  { left := and.right h, right := fun (b : \u03b1) (hb : b \u2208 lower_bounds s) => hb (and.left h) }\n\ntheorem is_greatest.is_lub {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_greatest s a) :\n    is_lub s a :=\n  { left := and.right h, right := fun (b : \u03b1) (hb : b \u2208 upper_bounds s) => hb (and.left h) }\n\ntheorem is_lub.upper_bounds_eq {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_lub s a) :\n    upper_bounds s = set.Ici a :=\n  sorry\n\ntheorem is_glb.lower_bounds_eq {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_glb s a) :\n    lower_bounds s = set.Iic a :=\n  is_lub.upper_bounds_eq h\n\ntheorem is_least.lower_bounds_eq {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_least s a) :\n    lower_bounds s = set.Iic a :=\n  is_glb.lower_bounds_eq (is_least.is_glb h)\n\ntheorem is_greatest.upper_bounds_eq {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1}\n    (h : is_greatest s a) : upper_bounds s = set.Ici a :=\n  is_lub.upper_bounds_eq (is_greatest.is_lub h)\n\ntheorem is_lub_le_iff {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (h : is_lub s a) :\n    a \u2264 b \u2194 b \u2208 upper_bounds s :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 b \u2194 b \u2208 upper_bounds s)) (is_lub.upper_bounds_eq h)))\n    (iff.refl (a \u2264 b))\n\ntheorem le_is_glb_iff {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (h : is_glb s a) :\n    b \u2264 a \u2194 b \u2208 lower_bounds s :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b \u2264 a \u2194 b \u2208 lower_bounds s)) (is_glb.lower_bounds_eq h)))\n    (iff.refl (b \u2264 a))\n\n/-- If `s` has a least upper bound, then it is bounded above. -/\ntheorem is_lub.bdd_above {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_lub s a) :\n    bdd_above s :=\n  Exists.intro a (and.left h)\n\n/-- If `s` has a greatest lower bound, then it is bounded below. -/\ntheorem is_glb.bdd_below {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_glb s a) :\n    bdd_below s :=\n  Exists.intro a (and.left h)\n\n/-- If `s` has a greatest element, then it is bounded above. -/\ntheorem is_greatest.bdd_above {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_greatest s a) :\n    bdd_above s :=\n  Exists.intro a (and.right h)\n\n/-- If `s` has a least element, then it is bounded below. -/\ntheorem is_least.bdd_below {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_least s a) :\n    bdd_below s :=\n  Exists.intro a (and.right h)\n\ntheorem is_least.nonempty {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_least s a) :\n    set.nonempty s :=\n  Exists.intro a (and.left h)\n\ntheorem is_greatest.nonempty {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} (h : is_greatest s a) :\n    set.nonempty s :=\n  Exists.intro a (and.left h)\n\n/-!\n### Union and intersection\n-/\n\n@[simp] theorem upper_bounds_union {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} :\n    upper_bounds (s \u222a t) = upper_bounds s \u2229 upper_bounds t :=\n  sorry\n\n@[simp] theorem lower_bounds_union {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} :\n    lower_bounds (s \u222a t) = lower_bounds s \u2229 lower_bounds t :=\n  upper_bounds_union\n\ntheorem union_upper_bounds_subset_upper_bounds_inter {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1}\n    {t : set \u03b1} : upper_bounds s \u222a upper_bounds t \u2286 upper_bounds (s \u2229 t) :=\n  set.union_subset (upper_bounds_mono_set (set.inter_subset_left s t))\n    (upper_bounds_mono_set (set.inter_subset_right s t))\n\ntheorem union_lower_bounds_subset_lower_bounds_inter {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1}\n    {t : set \u03b1} : lower_bounds s \u222a lower_bounds t \u2286 lower_bounds (s \u2229 t) :=\n  union_upper_bounds_subset_upper_bounds_inter\n\ntheorem is_least_union_iff {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {s : set \u03b1} {t : set \u03b1} :\n    is_least (s \u222a t) a \u2194 is_least s a \u2227 a \u2208 lower_bounds t \u2228 a \u2208 lower_bounds s \u2227 is_least t a :=\n  sorry\n\ntheorem is_greatest_union_iff {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1} {a : \u03b1} :\n    is_greatest (s \u222a t) a \u2194\n        is_greatest s a \u2227 a \u2208 upper_bounds t \u2228 a \u2208 upper_bounds s \u2227 is_greatest t a :=\n  is_least_union_iff\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\ntheorem bdd_above.inter_of_left {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1}\n    (h : bdd_above s) : bdd_above (s \u2229 t) :=\n  bdd_above.mono (set.inter_subset_left s t) h\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\ntheorem bdd_above.inter_of_right {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1}\n    (h : bdd_above t) : bdd_above (s \u2229 t) :=\n  bdd_above.mono (set.inter_subset_right s t) h\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\ntheorem bdd_below.inter_of_left {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1}\n    (h : bdd_below s) : bdd_below (s \u2229 t) :=\n  bdd_below.mono (set.inter_subset_left s t) h\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\ntheorem bdd_below.inter_of_right {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {t : set \u03b1}\n    (h : bdd_below t) : bdd_below (s \u2229 t) :=\n  bdd_below.mono (set.inter_subset_right s t) h\n\n/-- If `s` and `t` are bounded above sets in a `semilattice_sup`, then so is `s \u222a t`. -/\ntheorem bdd_above.union {\u03b3 : Type w} [semilattice_sup \u03b3] {s : set \u03b3} {t : set \u03b3} :\n    bdd_above s \u2192 bdd_above t \u2192 bdd_above (s \u222a t) :=\n  sorry\n\n/-- The union of two sets is bounded above if and only if each of the sets is. -/\ntheorem bdd_above_union {\u03b3 : Type w} [semilattice_sup \u03b3] {s : set \u03b3} {t : set \u03b3} :\n    bdd_above (s \u222a t) \u2194 bdd_above s \u2227 bdd_above t :=\n  sorry\n\ntheorem bdd_below.union {\u03b3 : Type w} [semilattice_inf \u03b3] {s : set \u03b3} {t : set \u03b3} :\n    bdd_below s \u2192 bdd_below t \u2192 bdd_below (s \u222a t) :=\n  bdd_above.union\n\n/--The union of two sets is bounded above if and only if each of the sets is.-/\ntheorem bdd_below_union {\u03b3 : Type w} [semilattice_inf \u03b3] {s : set \u03b3} {t : set \u03b3} :\n    bdd_below (s \u222a t) \u2194 bdd_below s \u2227 bdd_below t :=\n  bdd_above_union\n\n/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,\nthen `a \u2294 b` is the least upper bound of `s \u222a t`. -/\ntheorem is_lub.union {\u03b3 : Type w} [semilattice_sup \u03b3] {a : \u03b3} {b : \u03b3} {s : set \u03b3} {t : set \u03b3}\n    (hs : is_lub s a) (ht : is_lub t b) : is_lub (s \u222a t) (a \u2294 b) :=\n  sorry\n\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a \u2293 b` is the greatest lower bound of `s \u222a t`. -/\ntheorem is_glb.union {\u03b3 : Type w} [semilattice_inf \u03b3] {a\u2081 : \u03b3} {a\u2082 : \u03b3} {s : set \u03b3} {t : set \u03b3}\n    (hs : is_glb s a\u2081) (ht : is_glb t a\u2082) : is_glb (s \u222a t) (a\u2081 \u2293 a\u2082) :=\n  is_lub.union hs ht\n\n/-- If `a` is the least element of `s` and `b` is the least element of `t`,\nthen `min a b` is the least element of `s \u222a t`. -/\ntheorem is_least.union {\u03b3 : Type w} [linear_order \u03b3] {a : \u03b3} {b : \u03b3} {s : set \u03b3} {t : set \u03b3}\n    (ha : is_least s a) (hb : is_least t b) : is_least (s \u222a t) (min a b) :=\n  sorry\n\n/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,\nthen `max a b` is the greatest element of `s \u222a t`. -/\ntheorem is_greatest.union {\u03b3 : Type w} [linear_order \u03b3] {a : \u03b3} {b : \u03b3} {s : set \u03b3} {t : set \u03b3}\n    (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (s \u222a t) (max a b) :=\n  sorry\n\n/-!\n### Specific sets\n\n#### Unbounded intervals\n-/\n\ntheorem is_least_Ici {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_least (set.Ici a) a :=\n  { left := set.left_mem_Ici, right := fun (x : \u03b1) => id }\n\ntheorem is_greatest_Iic {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_greatest (set.Iic a) a :=\n  { left := set.right_mem_Iic, right := fun (x : \u03b1) => id }\n\ntheorem is_lub_Iic {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_lub (set.Iic a) a :=\n  is_greatest.is_lub is_greatest_Iic\n\ntheorem is_glb_Ici {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_glb (set.Ici a) a :=\n  is_least.is_glb is_least_Ici\n\ntheorem upper_bounds_Iic {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : upper_bounds (set.Iic a) = set.Ici a :=\n  is_lub.upper_bounds_eq is_lub_Iic\n\ntheorem lower_bounds_Ici {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : lower_bounds (set.Ici a) = set.Iic a :=\n  is_glb.lower_bounds_eq is_glb_Ici\n\ntheorem bdd_above_Iic {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : bdd_above (set.Iic a) :=\n  is_lub.bdd_above is_lub_Iic\n\ntheorem bdd_below_Ici {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : bdd_below (set.Ici a) :=\n  is_glb.bdd_below is_glb_Ici\n\ntheorem bdd_above_Iio {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : bdd_above (set.Iio a) :=\n  Exists.intro a fun (x : \u03b1) (hx : x \u2208 set.Iio a) => le_of_lt hx\n\ntheorem bdd_below_Ioi {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : bdd_below (set.Ioi a) :=\n  Exists.intro a fun (x : \u03b1) (hx : x \u2208 set.Ioi a) => le_of_lt hx\n\ntheorem is_lub_Iio {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} :\n    is_lub (set.Iio a) a :=\n  { left := fun (x : \u03b3) (hx : x \u2208 set.Iio a) => le_of_lt hx,\n    right := fun (y : \u03b3) (hy : y \u2208 upper_bounds (set.Iio a)) => le_of_forall_ge_of_dense hy }\n\ntheorem is_glb_Ioi {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} :\n    is_glb (set.Ioi a) a :=\n  is_lub_Iio\n\ntheorem upper_bounds_Iio {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} :\n    upper_bounds (set.Iio a) = set.Ici a :=\n  is_lub.upper_bounds_eq is_lub_Iio\n\ntheorem lower_bounds_Ioi {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} :\n    lower_bounds (set.Ioi a) = set.Iic a :=\n  is_glb.lower_bounds_eq is_glb_Ioi\n\n/-!\n#### Singleton\n-/\n\ntheorem is_greatest_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_greatest (singleton a) a :=\n  { left := set.mem_singleton a,\n    right := fun (x : \u03b1) (hx : x \u2208 singleton a) => le_of_eq (set.eq_of_mem_singleton hx) }\n\ntheorem is_least_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_least (singleton a) a :=\n  is_greatest_singleton\n\ntheorem is_lub_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_lub (singleton a) a :=\n  is_greatest.is_lub is_greatest_singleton\n\ntheorem is_glb_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : is_glb (singleton a) a :=\n  is_least.is_glb is_least_singleton\n\ntheorem bdd_above_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : bdd_above (singleton a) :=\n  is_lub.bdd_above is_lub_singleton\n\ntheorem bdd_below_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} : bdd_below (singleton a) :=\n  is_glb.bdd_below is_glb_singleton\n\n@[simp] theorem upper_bounds_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} :\n    upper_bounds (singleton a) = set.Ici a :=\n  is_lub.upper_bounds_eq is_lub_singleton\n\n@[simp] theorem lower_bounds_singleton {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} :\n    lower_bounds (singleton a) = set.Iic a :=\n  is_glb.lower_bounds_eq is_glb_singleton\n\n/-!\n#### Bounded intervals\n-/\n\ntheorem bdd_above_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_above (set.Icc a b) :=\n  Exists.intro b fun (_x : \u03b1) => and.right\n\ntheorem bdd_below_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_below (set.Icc a b) :=\n  Exists.intro a fun (_x : \u03b1) => and.left\n\ntheorem bdd_above_Ico {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_above (set.Ico a b) :=\n  bdd_above.mono set.Ico_subset_Icc_self bdd_above_Icc\n\ntheorem bdd_below_Ico {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_below (set.Ico a b) :=\n  bdd_below.mono set.Ico_subset_Icc_self bdd_below_Icc\n\ntheorem bdd_above_Ioc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_above (set.Ioc a b) :=\n  bdd_above.mono set.Ioc_subset_Icc_self bdd_above_Icc\n\ntheorem bdd_below_Ioc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_below (set.Ioc a b) :=\n  bdd_below.mono set.Ioc_subset_Icc_self bdd_below_Icc\n\ntheorem bdd_above_Ioo {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_above (set.Ioo a b) :=\n  bdd_above.mono set.Ioo_subset_Icc_self bdd_above_Icc\n\ntheorem bdd_below_Ioo {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} : bdd_below (set.Ioo a b) :=\n  bdd_below.mono set.Ioo_subset_Icc_self bdd_below_Icc\n\ntheorem is_greatest_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) :\n    is_greatest (set.Icc a b) b :=\n  { left := iff.mpr set.right_mem_Icc h, right := fun (x : \u03b1) => and.right }\n\ntheorem is_lub_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) : is_lub (set.Icc a b) b :=\n  is_greatest.is_lub (is_greatest_Icc h)\n\ntheorem upper_bounds_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) :\n    upper_bounds (set.Icc a b) = set.Ici b :=\n  is_lub.upper_bounds_eq (is_lub_Icc h)\n\ntheorem is_least_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) :\n    is_least (set.Icc a b) a :=\n  { left := iff.mpr set.left_mem_Icc h, right := fun (x : \u03b1) => and.left }\n\ntheorem is_glb_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) : is_glb (set.Icc a b) a :=\n  is_least.is_glb (is_least_Icc h)\n\ntheorem lower_bounds_Icc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) :\n    lower_bounds (set.Icc a b) = set.Iic a :=\n  is_glb.lower_bounds_eq (is_glb_Icc h)\n\ntheorem is_greatest_Ioc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) :\n    is_greatest (set.Ioc a b) b :=\n  { left := iff.mpr set.right_mem_Ioc h, right := fun (x : \u03b1) => and.right }\n\ntheorem is_lub_Ioc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) : is_lub (set.Ioc a b) b :=\n  is_greatest.is_lub (is_greatest_Ioc h)\n\ntheorem upper_bounds_Ioc {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) :\n    upper_bounds (set.Ioc a b) = set.Ici b :=\n  is_lub.upper_bounds_eq (is_lub_Ioc h)\n\ntheorem is_least_Ico {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) :\n    is_least (set.Ico a b) a :=\n  { left := iff.mpr set.left_mem_Ico h, right := fun (x : \u03b1) => and.left }\n\ntheorem is_glb_Ico {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) : is_glb (set.Ico a b) a :=\n  is_least.is_glb (is_least_Ico h)\n\ntheorem lower_bounds_Ico {\u03b1 : Type u} [preorder \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) :\n    lower_bounds (set.Ico a b) = set.Iic a :=\n  is_glb.lower_bounds_eq (is_glb_Ico h)\n\ntheorem is_glb_Ioo {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3} (hab : a < b) :\n    is_glb (set.Ioo a b) a :=\n  sorry\n\ntheorem lower_bounds_Ioo {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3}\n    (hab : a < b) : lower_bounds (set.Ioo a b) = set.Iic a :=\n  is_glb.lower_bounds_eq (is_glb_Ioo hab)\n\ntheorem is_glb_Ioc {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3} (hab : a < b) :\n    is_glb (set.Ioc a b) a :=\n  is_glb.of_subset_of_superset (is_glb_Ioo hab) (is_glb_Icc (le_of_lt hab)) set.Ioo_subset_Ioc_self\n    set.Ioc_subset_Icc_self\n\ntheorem lower_bound_Ioc {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3}\n    (hab : a < b) : lower_bounds (set.Ioc a b) = set.Iic a :=\n  is_glb.lower_bounds_eq (is_glb_Ioc hab)\n\ntheorem is_lub_Ioo {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3} (hab : a < b) :\n    is_lub (set.Ioo a b) b :=\n  sorry\n\ntheorem upper_bounds_Ioo {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3}\n    (hab : a < b) : upper_bounds (set.Ioo a b) = set.Ici b :=\n  is_lub.upper_bounds_eq (is_lub_Ioo hab)\n\ntheorem is_lub_Ico {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3} (hab : a < b) :\n    is_lub (set.Ico a b) b :=\n  sorry\n\ntheorem upper_bounds_Ico {\u03b3 : Type w} [linear_order \u03b3] [densely_ordered \u03b3] {a : \u03b3} {b : \u03b3}\n    (hab : a < b) : upper_bounds (set.Ico a b) = set.Ici b :=\n  is_lub.upper_bounds_eq (is_lub_Ico hab)\n\ntheorem bdd_below_iff_subset_Ici {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} :\n    bdd_below s \u2194 \u2203 (a : \u03b1), s \u2286 set.Ici a :=\n  iff.rfl\n\ntheorem bdd_above_iff_subset_Iic {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} :\n    bdd_above s \u2194 \u2203 (a : \u03b1), s \u2286 set.Iic a :=\n  iff.rfl\n\ntheorem bdd_below_bdd_above_iff_subset_Icc {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} :\n    bdd_below s \u2227 bdd_above s \u2194 \u2203 (a : \u03b1), \u2203 (b : \u03b1), s \u2286 set.Icc a b :=\n  sorry\n\n/-!\n### Univ\n-/\n\ntheorem order_top.upper_bounds_univ {\u03b3 : Type w} [order_top \u03b3] :\n    upper_bounds set.univ = singleton \u22a4 :=\n  sorry\n\ntheorem is_greatest_univ {\u03b3 : Type w} [order_top \u03b3] : is_greatest set.univ \u22a4 := sorry\n\ntheorem is_lub_univ {\u03b3 : Type w} [order_top \u03b3] : is_lub set.univ \u22a4 :=\n  is_greatest.is_lub is_greatest_univ\n\ntheorem order_bot.lower_bounds_univ {\u03b3 : Type w} [order_bot \u03b3] :\n    lower_bounds set.univ = singleton \u22a5 :=\n  order_top.upper_bounds_univ\n\ntheorem is_least_univ {\u03b3 : Type w} [order_bot \u03b3] : is_least set.univ \u22a5 := is_greatest_univ\n\ntheorem is_glb_univ {\u03b3 : Type w} [order_bot \u03b3] : is_glb set.univ \u22a5 := is_least.is_glb is_least_univ\n\ntheorem no_top_order.upper_bounds_univ {\u03b1 : Type u} [preorder \u03b1] [no_top_order \u03b1] :\n    upper_bounds set.univ = \u2205 :=\n  sorry\n\ntheorem no_bot_order.lower_bounds_univ {\u03b1 : Type u} [preorder \u03b1] [no_bot_order \u03b1] :\n    lower_bounds set.univ = \u2205 :=\n  no_top_order.upper_bounds_univ\n\n/-!\n### Empty set\n-/\n\n@[simp] theorem upper_bounds_empty {\u03b1 : Type u} [preorder \u03b1] : upper_bounds \u2205 = set.univ := sorry\n\n@[simp] theorem lower_bounds_empty {\u03b1 : Type u} [preorder \u03b1] : lower_bounds \u2205 = set.univ :=\n  upper_bounds_empty\n\n@[simp] theorem bdd_above_empty {\u03b1 : Type u} [preorder \u03b1] [Nonempty \u03b1] : bdd_above \u2205 := sorry\n\n@[simp] theorem bdd_below_empty {\u03b1 : Type u} [preorder \u03b1] [Nonempty \u03b1] : bdd_below \u2205 := sorry\n\ntheorem is_glb_empty {\u03b3 : Type w} [order_top \u03b3] : is_glb \u2205 \u22a4 := sorry\n\ntheorem is_lub_empty {\u03b3 : Type w} [order_bot \u03b3] : is_lub \u2205 \u22a5 := is_glb_empty\n\ntheorem is_lub.nonempty {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} [no_bot_order \u03b1]\n    (hs : is_lub s a) : set.nonempty s :=\n  sorry\n\ntheorem is_glb.nonempty {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} [no_top_order \u03b1]\n    (hs : is_glb s a) : set.nonempty s :=\n  is_lub.nonempty hs\n\ntheorem nonempty_of_not_bdd_above {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} [ha : Nonempty \u03b1]\n    (h : \u00acbdd_above s) : set.nonempty s :=\n  nonempty.elim ha\n    fun (x : \u03b1) =>\n      Exists.imp (fun (a : \u03b1) (ha : \u2203 (H : a \u2208 s), \u00aca \u2264 x) => Exists.fst ha)\n        (iff.mp not_bdd_above_iff' h x)\n\ntheorem nonempty_of_not_bdd_below {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} [ha : Nonempty \u03b1]\n    (h : \u00acbdd_below s) : set.nonempty s :=\n  nonempty_of_not_bdd_above h\n\n/-!\n### insert\n-/\n\n/-- Adding a point to a set preserves its boundedness above. -/\n@[simp] theorem bdd_above_insert {\u03b3 : Type w} [semilattice_sup \u03b3] (a : \u03b3) {s : set \u03b3} :\n    bdd_above (insert a s) \u2194 bdd_above s :=\n  sorry\n\ntheorem bdd_above.insert {\u03b3 : Type w} [semilattice_sup \u03b3] (a : \u03b3) {s : set \u03b3} (hs : bdd_above s) :\n    bdd_above (insert a s) :=\n  iff.mpr (bdd_above_insert a) hs\n\n/--Adding a point to a set preserves its boundedness below.-/\n@[simp] theorem bdd_below_insert {\u03b3 : Type w} [semilattice_inf \u03b3] (a : \u03b3) {s : set \u03b3} :\n    bdd_below (insert a s) \u2194 bdd_below s :=\n  sorry\n\ntheorem bdd_below.insert {\u03b3 : Type w} [semilattice_inf \u03b3] (a : \u03b3) {s : set \u03b3} (hs : bdd_below s) :\n    bdd_below (insert a s) :=\n  iff.mpr (bdd_below_insert a) hs\n\ntheorem is_lub.insert {\u03b3 : Type w} [semilattice_sup \u03b3] (a : \u03b3) {b : \u03b3} {s : set \u03b3}\n    (hs : is_lub s b) : is_lub (insert a s) (a \u2294 b) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (is_lub (insert a s) (a \u2294 b))) (set.insert_eq a s)))\n    (is_lub.union is_lub_singleton hs)\n\ntheorem is_glb.insert {\u03b3 : Type w} [semilattice_inf \u03b3] (a : \u03b3) {b : \u03b3} {s : set \u03b3}\n    (hs : is_glb s b) : is_glb (insert a s) (a \u2293 b) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (is_glb (insert a s) (a \u2293 b))) (set.insert_eq a s)))\n    (is_glb.union is_glb_singleton hs)\n\ntheorem is_greatest.insert {\u03b3 : Type w} [linear_order \u03b3] (a : \u03b3) {b : \u03b3} {s : set \u03b3}\n    (hs : is_greatest s b) : is_greatest (insert a s) (max a b) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (is_greatest (insert a s) (max a b))) (set.insert_eq a s)))\n    (is_greatest.union is_greatest_singleton hs)\n\ntheorem is_least.insert {\u03b3 : Type w} [linear_order \u03b3] (a : \u03b3) {b : \u03b3} {s : set \u03b3}\n    (hs : is_least s b) : is_least (insert a s) (min a b) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (is_least (insert a s) (min a b))) (set.insert_eq a s)))\n    (is_least.union is_least_singleton hs)\n\n@[simp] theorem upper_bounds_insert {\u03b1 : Type u} [preorder \u03b1] (a : \u03b1) (s : set \u03b1) :\n    upper_bounds (insert a s) = set.Ici a \u2229 upper_bounds s :=\n  sorry\n\n@[simp] theorem lower_bounds_insert {\u03b1 : Type u} [preorder \u03b1] (a : \u03b1) (s : set \u03b1) :\n    lower_bounds (insert a s) = set.Iic a \u2229 lower_bounds s :=\n  sorry\n\n/-- When there is a global maximum, every set is bounded above. -/\n@[simp] protected theorem order_top.bdd_above {\u03b3 : Type w} [order_top \u03b3] (s : set \u03b3) :\n    bdd_above s :=\n  Exists.intro \u22a4 fun (a : \u03b3) (ha : a \u2208 s) => order_top.le_top a\n\n/-- When there is a global minimum, every set is bounded below. -/\n@[simp] protected theorem order_bot.bdd_below {\u03b3 : Type w} [order_bot \u03b3] (s : set \u03b3) :\n    bdd_below s :=\n  Exists.intro \u22a5 fun (a : \u03b3) (ha : a \u2208 s) => order_bot.bot_le a\n\n/-!\n### Pair\n-/\n\ntheorem is_lub_pair {\u03b3 : Type w} [semilattice_sup \u03b3] {a : \u03b3} {b : \u03b3} :\n    is_lub (insert a (singleton b)) (a \u2294 b) :=\n  is_lub.insert a is_lub_singleton\n\ntheorem is_glb_pair {\u03b3 : Type w} [semilattice_inf \u03b3] {a : \u03b3} {b : \u03b3} :\n    is_glb (insert a (singleton b)) (a \u2293 b) :=\n  is_glb.insert a is_glb_singleton\n\ntheorem is_least_pair {\u03b3 : Type w} [linear_order \u03b3] {a : \u03b3} {b : \u03b3} :\n    is_least (insert a (singleton b)) (min a b) :=\n  is_least.insert a is_least_singleton\n\ntheorem is_greatest_pair {\u03b3 : Type w} [linear_order \u03b3] {a : \u03b3} {b : \u03b3} :\n    is_greatest (insert a (singleton b)) (max a b) :=\n  is_greatest.insert a is_greatest_singleton\n\n/-!\n### (In)equalities with the least upper bound and the greatest lower bound\n-/\n\ntheorem lower_bounds_le_upper_bounds {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (ha : a \u2208 lower_bounds s) (hb : b \u2208 upper_bounds s) : set.nonempty s \u2192 a \u2264 b :=\n  fun (\u1fb0 : set.nonempty s) =>\n    Exists.dcases_on \u1fb0 fun (\u1fb0_w : \u03b1) (\u1fb0_h : \u1fb0_w \u2208 s) => idRhs (a \u2264 b) (le_trans (ha \u1fb0_h) (hb \u1fb0_h))\n\ntheorem is_glb_le_is_lub {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (ha : is_glb s a)\n    (hb : is_lub s b) (hs : set.nonempty s) : a \u2264 b :=\n  lower_bounds_le_upper_bounds (and.left ha) (and.left hb) hs\n\ntheorem is_lub_lt_iff {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (ha : is_lub s a) :\n    a < b \u2194 \u2203 (c : \u03b1), \u2203 (H : c \u2208 upper_bounds s), c < b :=\n  sorry\n\ntheorem lt_is_glb_iff {\u03b1 : Type u} [preorder \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (ha : is_glb s a) :\n    b < a \u2194 \u2203 (c : \u03b1), \u2203 (H : c \u2208 lower_bounds s), b < c :=\n  is_lub_lt_iff ha\n\ntheorem is_least.unique {\u03b1 : Type u} [partial_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (Ha : is_least s a) (Hb : is_least s b) : a = b :=\n  le_antisymm (and.right Ha b (and.left Hb)) (and.right Hb a (and.left Ha))\n\ntheorem is_least.is_least_iff_eq {\u03b1 : Type u} [partial_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (Ha : is_least s a) : is_least s b \u2194 a = b :=\n  { mp := is_least.unique Ha, mpr := fun (h : a = b) => h \u25b8 Ha }\n\ntheorem is_greatest.unique {\u03b1 : Type u} [partial_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (Ha : is_greatest s a) (Hb : is_greatest s b) : a = b :=\n  le_antisymm (and.right Hb a (and.left Ha)) (and.right Ha b (and.left Hb))\n\ntheorem is_greatest.is_greatest_iff_eq {\u03b1 : Type u} [partial_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (Ha : is_greatest s a) : is_greatest s b \u2194 a = b :=\n  { mp := is_greatest.unique Ha, mpr := fun (h : a = b) => h \u25b8 Ha }\n\ntheorem is_lub.unique {\u03b1 : Type u} [partial_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (Ha : is_lub s a)\n    (Hb : is_lub s b) : a = b :=\n  is_least.unique Ha Hb\n\ntheorem is_glb.unique {\u03b1 : Type u} [partial_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (Ha : is_glb s a)\n    (Hb : is_glb s b) : a = b :=\n  is_greatest.unique Ha Hb\n\ntheorem lt_is_lub_iff {\u03b1 : Type u} [linear_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (h : is_lub s a) :\n    b < a \u2194 \u2203 (c : \u03b1), \u2203 (H : c \u2208 s), b < c :=\n  sorry\n\ntheorem is_glb_lt_iff {\u03b1 : Type u} [linear_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1} (h : is_glb s a) :\n    a < b \u2194 \u2203 (c : \u03b1), \u2203 (H : c \u2208 s), c < b :=\n  lt_is_lub_iff h\n\ntheorem is_lub.exists_between {\u03b1 : Type u} [linear_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (h : is_lub s a) (hb : b < a) : \u2203 (c : \u03b1), \u2203 (H : c \u2208 s), b < c \u2227 c \u2264 a :=\n  sorry\n\ntheorem is_lub.exists_between' {\u03b1 : Type u} [linear_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (h : is_lub s a) (h' : \u00aca \u2208 s) (hb : b < a) : \u2203 (c : \u03b1), \u2203 (H : c \u2208 s), b < c \u2227 c < a :=\n  sorry\n\ntheorem is_glb.exists_between {\u03b1 : Type u} [linear_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (h : is_glb s a) (hb : a < b) : \u2203 (c : \u03b1), \u2203 (H : c \u2208 s), a \u2264 c \u2227 c < b :=\n  sorry\n\ntheorem is_glb.exists_between' {\u03b1 : Type u} [linear_order \u03b1] {s : set \u03b1} {a : \u03b1} {b : \u03b1}\n    (h : is_glb s a) (h' : \u00aca \u2208 s) (hb : a < b) : \u2203 (c : \u03b1), \u2203 (H : c \u2208 s), a < c \u2227 c < b :=\n  sorry\n\n/-!\n### Least upper bound and the greatest lower bound in linear ordered additive commutative groups\n-/\n\ntheorem is_glb.exists_between_self_add {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {s : set \u03b1}\n    {a : \u03b1} {\u03b5 : \u03b1} (h : is_glb s a) (h\u03b5 : 0 < \u03b5) : \u2203 (b : \u03b1), \u2203 (H : b \u2208 s), a \u2264 b \u2227 b < a + \u03b5 :=\n  is_glb.exists_between h (lt_add_of_pos_right a h\u03b5)\n\ntheorem is_glb.exists_between_self_add' {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {s : set \u03b1}\n    {a : \u03b1} {\u03b5 : \u03b1} (h : is_glb s a) (h\u2082 : \u00aca \u2208 s) (h\u03b5 : 0 < \u03b5) :\n    \u2203 (b : \u03b1), \u2203 (H : b \u2208 s), a < b \u2227 b < a + \u03b5 :=\n  is_glb.exists_between' h h\u2082 (lt_add_of_pos_right a h\u03b5)\n\ntheorem is_lub.exists_between_sub_self {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {s : set \u03b1}\n    {a : \u03b1} {\u03b5 : \u03b1} (h : is_lub s a) (h\u03b5 : 0 < \u03b5) : \u2203 (b : \u03b1), \u2203 (H : b \u2208 s), a - \u03b5 < b \u2227 b \u2264 a :=\n  is_lub.exists_between h (sub_lt_self a h\u03b5)\n\ntheorem is_lub.exists_between_sub_self' {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] {s : set \u03b1}\n    {a : \u03b1} {\u03b5 : \u03b1} (h : is_lub s a) (h\u2082 : \u00aca \u2208 s) (h\u03b5 : 0 < \u03b5) :\n    \u2203 (b : \u03b1), \u2203 (H : b \u2208 s), a - \u03b5 < b \u2227 b < a :=\n  is_lub.exists_between' h h\u2082 (sub_lt_self a h\u03b5)\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\nnamespace monotone\n\n\ntheorem mem_upper_bounds_image {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (Hf : monotone f) {a : \u03b1} {s : set \u03b1} (Ha : a \u2208 upper_bounds s) : f a \u2208 upper_bounds (f '' s) :=\n  set.ball_image_of_ball fun (x : \u03b1) (H : x \u2208 s) => Hf (Ha H)\n\ntheorem mem_lower_bounds_image {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (Hf : monotone f) {a : \u03b1} {s : set \u03b1} (Ha : a \u2208 lower_bounds s) : f a \u2208 lower_bounds (f '' s) :=\n  set.ball_image_of_ball fun (x : \u03b1) (H : x \u2208 s) => Hf (Ha H)\n\n/-- The image under a monotone function of a set which is bounded above is bounded above. -/\ntheorem map_bdd_above {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1}\n    (hf : monotone f) : bdd_above s \u2192 bdd_above (f '' s) :=\n  sorry\n\n/-- The image under a monotone function of a set which is bounded below is bounded below. -/\ntheorem map_bdd_below {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1}\n    (hf : monotone f) : bdd_below s \u2192 bdd_below (f '' s) :=\n  sorry\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\ntheorem map_is_least {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (Hf : monotone f) {a : \u03b1} {s : set \u03b1} (Ha : is_least s a) : is_least (f '' s) (f a) :=\n  { left := set.mem_image_of_mem f (and.left Ha),\n    right := mem_lower_bounds_image Hf (and.right Ha) }\n\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\ntheorem map_is_greatest {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (Hf : monotone f) {a : \u03b1} {s : set \u03b1} (Ha : is_greatest s a) : is_greatest (f '' s) (f a) :=\n  { left := set.mem_image_of_mem f (and.left Ha),\n    right := mem_upper_bounds_image Hf (and.right Ha) }\n\ntheorem is_lub_image_le {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (Hf : monotone f) {a : \u03b1} {s : set \u03b1} (Ha : is_lub s a) {b : \u03b2} (Hb : is_lub (f '' s) b) :\n    b \u2264 f a :=\n  and.right Hb (f a) (mem_upper_bounds_image Hf (and.left Ha))\n\ntheorem le_is_glb_image {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (Hf : monotone f) {a : \u03b1} {s : set \u03b1} (Ha : is_glb s a) {b : \u03b2} (Hb : is_glb (f '' s) b) :\n    f a \u2264 b :=\n  and.right Hb (f a) (mem_lower_bounds_image Hf (and.left Ha))\n\nend monotone\n\n\ntheorem is_glb.of_image {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (hf : \u2200 {x y : \u03b1}, f x \u2264 f y \u2194 x \u2264 y) {s : set \u03b1} {x : \u03b1} (hx : is_glb (f '' s) (f x)) :\n    is_glb s x :=\n  sorry\n\ntheorem is_lub.of_image {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (hf : \u2200 {x y : \u03b1}, f x \u2264 f y \u2194 x \u2264 y) {s : set \u03b1} {x : \u03b1} (hx : is_lub (f '' s) (f x)) :\n    is_lub s x :=\n  is_glb.of_image (fun (x y : order_dual \u03b1) => hf) hx\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/bounds_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7315570119226156}}
{"text": "variable (A B C : Prop)\n\nexample : A \u2227 B := sorry \n\nexample : \u00ac A := sorry \n\nexample : A \u2228 B := sorry \n\nexample : A \u2192 B := sorry \n\nexample : A \u2194 B := sorry \n\n-- Elimination and introduction for \u2192 \n\nexample (a : A) : A := a \n\nexample : True := trivial \n\nexample : A \u2192 A := fun (a:A) => a \n\ntheorem myAwesomeTheorem ( a : A ) : B :=\nsorry \n\n#check myAwesomeTheorem A B \n\n-- introduction \nexample : A \u2192 B := myAwesomeTheorem A B \n\n-- elimination\nexample (a : A) (f : A \u2192 B) : B := f a \n\nexample : A \u2192 B \u2192 A := fun (a : A) => \nfun (_ : B) => a\n\n-- Elimination and introduction for \u2227 \n\nexample (p : A \u2227 B) : A := And.left p \n\nexample (p : A \u2227 B) : B := And.right p \n\n#check And.left \n\nexample (a : A) (b : B) : A \u2227 B := And.intro a b \n\n#check And.intro \n\n-- Elimination and introduction for \u2228 \n\nexample (a : A) : A \u2228 B := Or.inl a \n\nexample (b : B) : A \u2228 B := Or.inr b \n\n#check Or.elim\n\nexample (h : A \u2228 B) : B \u2228 A := \n  Or.elim h (Or.intro_right B) (Or.intro_left A) \n\n-- Elimination and introduction for \\iff \n\nexample (f : A \u2192 B) (g : B \u2192 A) : A \u2194 B := \n  Iff.intro f g \n\nexample (h : A \u2194 B) (a : A) : B := Iff.mp h a \n\nexample (h : A \u2194 B) (b : B) : A := Iff.mpr h b \n\n#check @Iff.mpr A B ", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "lean-notes", "sha": "40c1fe4cff620355bc3c9fa31ad886cb7836f7f3", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-lean-notes", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-lean-notes/lean-notes-40c1fe4cff620355bc3c9fa31ad886cb7836f7f3/09_14-notes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.731485505671582}}
{"text": "import Chap4\nnamespace HTPI\nset_option pp.funBinderTypes true\n\n/- Definitions and theorems in HTPIDefs\ndef graph {A B : Type} (f : A \u2192 B) : Set (A \u00d7 B) :=\n  { (a, b) : A \u00d7 B | f a = b }\n\ndef is_func_graph {A B : Type} (G : Set (A \u00d7 B)) : Prop :=\n  \u2200 (x : A), \u2203! (y : B), (x, y) \u2208 G\n\ntheorem func_from_graph {A B : Type} (F : Set (A \u00d7 B)) :\n    (\u2203 (f : A \u2192 B), graph f = F) \u2194 is_func_graph F := by\n-/\n\n/- Definitions -/\ndef onto {A B : Type} (f : A \u2192 B) : Prop :=\n  \u2200 (y : B), \u2203 (x : A), f x = y\n\ndef one_to_one {A B : Type} (f : A \u2192 B) : Prop :=\n  \u2200 (x1 x2 : A), f x1 = f x2 \u2192 x1 = x2\n\ndef closed {A : Type} (f : A \u2192 A) (C : Set A) : Prop := \u2200 x \u2208 C, f x \u2208 C\n\ndef closure {A : Type} (f : A \u2192 A) (B C : Set A) : Prop :=\n  smallestElt (sub A) C { D : Set A | B \u2286 D \u2227 closed f D }\n\ndef closed2 {A : Type} (f : A \u2192 A \u2192 A) (C : Set A) : Prop :=\n  \u2200 x \u2208 C, \u2200 y \u2208 C, f x y \u2208 C\n\ndef closure2 {A : Type} (f : A \u2192 A \u2192 A) (B C : Set A) : Prop := \n  smallestElt (sub A) C { D : Set A | B \u2286 D \u2227 closed2 f D }\n\ndef closed_family {A : Type} (F : Set (A \u2192 A)) (C : Set A) : Prop :=\n  \u2200 f \u2208 F, closed f C\n\ndef closure_family {A : Type} (F : Set (A \u2192 A)) (B C : Set A) : Prop :=\n  smallestElt (sub A) C { D : Set A | B \u2286 D \u2227 closed_family F D }\n\ndef image {A B : Type} (f : A \u2192 B) (X : Set A) : Set B :=\n  { f x | x \u2208 X }\n\ndef inverse_image {A B : Type} (f : A \u2192 B) (Y : Set B) : Set A :=\n  { a : A | f a \u2208 Y }\n\n/- Section 5.1 -/\ntheorem graph_def {A B : Type} (f : A \u2192 B) (a : A) (b : B) :\n    (a, b) \u2208 graph f \u2194 f a = b := by rfl\n\ntheorem Theorem_5_1_4 {A B : Type} (f g : A \u2192 B) :\n    (\u2200 (a : A), f a = g a) \u2192 f = g := funext\n\nexample {A B : Type} (f g : A \u2192 B) :\n    graph f = graph g \u2192 f = g := by\n  assume h1 : graph f = graph g  --Goal : f = g\n  apply funext                   --Goal : \u2200 (x : A), f x = g x\n  fix x : A\n  have h2 : (x, f x) \u2208 graph f := by\n    define                       --Goal : f x = f x\n    rfl\n    done\n  rewrite [h1] at h2             --h2 : (x, f x) \u2208 graph g\n  define at h2                   --h2 : g x = f x\n  show f x = g x from h2.symm\n  done\n\ndef square1 (n : Nat) : Nat := n ^ 2\n\ndef square2 : Nat \u2192 Nat := fun (n : Nat) => n ^ 2\n\nexample : square1 = square2 := by rfl\n\n#eval square1 7     --Answer: 49\n\ntheorem Theorem_5_1_5 {A B C : Type} (f : A \u2192 B) (g : B \u2192 C) :\n    \u2203 (h : A \u2192 C), graph h = comp (graph g) (graph f) := by\n  let h : A \u2192 C := fun (x : A) => g (f x)\n  apply Exists.intro h\n  apply Set.ext\n  fix (a, c) : A \u00d7 C\n  apply Iff.intro\n  \u00b7 -- Proof that (a, c) \u2208 graph h \u2192 (a, c) \u2208 comp (graph g) (graph f)\n    assume h1 : (a, c) \u2208 graph h\n    define at h1  --h1 : h a = c\n    define        --Goal : \u2203 (x : B), (a, x) \u2208 graph f \u2227 (x, c) \u2208 graph g\n    apply Exists.intro (f a)\n    apply And.intro\n    \u00b7 -- Proof that (a, f a) \u2208 graph f\n      define\n      rfl\n      done\n    \u00b7 -- Proof that (f a, c) \u2208 graph g\n      define\n      show g (f a) = c from h1\n      done\n    done\n  \u00b7 -- Proof that (a, c) \u2208 comp (graph g) (graph f) \u2192 (a, c) \u2208 graph h\n    assume h1 : (a, c) \u2208 comp (graph g) (graph f)\n    define        --Goal : h a = c\n    define at h1  --h1 : \u2203 (x : B), (a, x) \u2208 graph f \u2227 (x, c) \u2208 graph g\n    obtain (b : B) (h2 : (a, b) \u2208 graph f \u2227 (b, c) \u2208 graph g) from h1\n    have h3 : (a, b) \u2208 graph f := h2.left\n    have h4 : (b, c) \u2208 graph g := h2.right\n    define at h3          --h3 : f a = b\n    define at h4          --h4 : g b = c\n    rewrite [\u2190h3] at h4   --h4 : g (f a) = c\n    show h a = c from h4\n    done\n  done\n\nexample {A B C D : Type} (f : A \u2192 B) (g : B \u2192 C) (h : C \u2192 D) :\n    h \u2218 (g \u2218 f) = (h \u2218 g) \u2218 f := by rfl\n\nexample {A B : Type} (f : A \u2192 B) : f \u2218 id = f := by rfl\n\nexample {A B : Type} (f : A \u2192 B) : id \u2218 f = f := by rfl\n\n/- Section 5.2 -/\ntheorem Theorem_5_2_5_1 {A B C : Type} (f : A \u2192 B) (g : B \u2192 C) :\n    one_to_one f \u2192 one_to_one g \u2192 one_to_one (g \u2218 f) := by\n  assume h1 : one_to_one f\n  assume h2 : one_to_one g\n  define at h1  --h1 : \u2200 (x1 x2 : A), f x1 = f x2 \u2192 x1 = x2\n  define at h2  --h2 : \u2200 (x1 x2 : B), g x1 = g x2 \u2192 x1 = x2\n  define        --Goal : \u2200 (x1 x2 : A), (g \u2218 f) x1 = (g \u2218 f) x2 \u2192 x1 = x2\n  fix a1 : A\n  fix a2 : A    --Goal : (g \u2218 f) a1 = (g \u2218 f) a2 \u2192 a1 = a2\n  define : (g \u2218 f) a1; define : (g \u2218 f) a2\n                --Goal : g (f a1) = g (f a2) \u2192 a1 = a2\n  assume h3 : g (f a1) = g (f a2)\n  have h4 : f a1 = f a2 := h2 (f a1) (f a2) h3\n  show a1 = a2 from h1 a1 a2 h4\n  done\n\ntheorem Theorem_5_2_5_2 {A B C : Type} (f : A \u2192 B) (g : B \u2192 C) :\n    onto f \u2192 onto g \u2192 onto (g \u2218 f) := by\n  assume h1 : onto f\n  assume h2 : onto g\n  define at h1           --h1 : \u2200 (y : B), \u2203 (x : A), f x = y\n  define at h2           --h2 : \u2200 (y : C), \u2203 (x : B), g x = y\n  define                 --Goal : \u2200 (y : C), \u2203 (x : A), (g \u2218 f) x = y\n  fix c : C\n  obtain (b : B) (h3 : g b = c) from h2 c\n  obtain (a : A) (h4 : f a = b) from h1 b\n  apply Exists.intro a   --Goal : (g \u2218 f) a = c\n  define : (g \u2218 f) a     --Goal : g (f a) = c\n  rewrite [\u2190h4] at h3\n  show g (f a) = c from h3\n  done\n\n/- Section 5.3 -/\ntheorem Theorem_5_3_1 {A B : Type}\n    (f : A \u2192 B) (h1 : one_to_one f) (h2 : onto f) :\n    \u2203 (g : B \u2192 A), graph g = inv (graph f) := by\n  rewrite [func_from_graph]   --Goal : is_func_graph (inv (graph f))\n  define        --Goal : \u2200 (x : B), \u2203! (y : A), (x, y) \u2208 inv (graph f)\n  fix b : B\n  exists_unique\n  \u00b7 -- Existence\n    define at h2          --h2 : \u2200 (y : B), \u2203 (x : A), f x = y\n    obtain (a : A) (h4 : f a = b) from h2 b\n    apply Exists.intro a  --Goal : (b, a) \u2208 inv (graph f)\n    define                --Goal : f a = b\n    show f a = b from h4\n    done\n  \u00b7 -- Uniqueness\n    fix a1 : A; fix a2 : A\n    assume h3 : (b, a1) \u2208 inv (graph f)\n    assume h4 : (b, a2) \u2208 inv (graph f) --Goal : a1 = a2\n    define at h3          --h3 : f a1 = b\n    define at h4          --h4 : f a2 = b\n    rewrite [\u2190h4] at h3   --h3 : f a1 = f a2\n    define at h1          --h1 : \u2200 (x1 x2 : A), f x1 = f x2 \u2192 x1 = x2\n    show a1 = a2 from h1 a1 a2 h3\n    done\n  done\n\ntheorem Theorem_5_3_2_1 {A B : Type} (f : A \u2192 B) (g : B \u2192 A)\n    (h1 : graph g = inv (graph f)) : g \u2218 f = id := by\n  apply funext           --Goal : \u2200 (x : A), (g \u2218 f) x = id x\n  fix a : A              --Goal : (g \u2218 f) a = id a\n  have h2 : (f a, a) \u2208 graph g := by\n    rewrite [h1]         --Goal : (f a, a) \u2208 inv (graph f)\n    define               --Goal : f a = f a\n    rfl\n    done\n  define at h2           --h2 : g (f a) = a\n  show (g \u2218 f) a = id a from h2\n  done\n\ntheorem Theorem_5_3_2_2 {A B : Type} (f : A \u2192 B) (g : B \u2192 A)\n    (h1 : graph g = inv (graph f)) : f \u2218 g = id := sorry\n\ntheorem Theorem_5_3_3_1 {A B : Type} (f : A \u2192 B) :\n    (\u2203 (g : B \u2192 A), g \u2218 f = id) \u2192 one_to_one f := by\n  assume h1 : \u2203 (g : B \u2192 A), g \u2218 f = id\n  obtain (g : B \u2192 A) (h2 : g \u2218 f = id) from h1\n  define              --Goal : \u2200 (x1 x2 : A), f x1 = f x2 \u2192 x1 = x2\n  fix a1 : A; fix a2 : A\n  assume h3 : f a1 = f a2\n  show a1 = a2 from\n    calc a1\n      _ = id a1 := by rfl\n      _ = (g \u2218 f) a1 := by rw [h2]\n      _ = g (f a1) := by rfl\n      _ = g (f a2) := by rw [h3]\n      _ = (g \u2218 f) a2 := by rfl\n      _ = id a2 := by rw [h2]\n      _ = a2 := by rfl\n  done\n\ntheorem Theorem_5_3_3_2 {A B : Type} (f : A \u2192 B) :\n    (\u2203 (g : B \u2192 A), f \u2218 g = id) \u2192 onto f := sorry\n\ntheorem Theorem_5_3_5 {A B : Type} (f : A \u2192 B) (g : B \u2192 A)\n    (h1 : g \u2218 f = id) (h2 : f \u2218 g = id) : graph g = inv (graph f) := by\n  have h3 : one_to_one f := Theorem_5_3_3_1 f (Exists.intro g h1)\n  have h4 : onto f := Theorem_5_3_3_2 f (Exists.intro g h2)\n  obtain (g' : B \u2192 A) (h5 : graph g' = inv (graph f))\n    from Theorem_5_3_1 f h3 h4\n  have h6 : g' \u2218 f = id := Theorem_5_3_2_1 f g' h5\n  have h7 : g = g' :=\n    calc g\n      _ = id \u2218 g := by rfl\n      _ = (g' \u2218 f) \u2218 g := by rw [h6]\n      _ = g' \u2218 (f \u2218 g) := by rfl\n      _ = g' \u2218 id := by rw [h2]\n      _ = g' := by rfl\n  rewrite [\u2190h7] at h5\n  show graph g = inv (graph f) from h5\n  done\n\n/- Section 5.4 -/\ntheorem Theorem_5_4_5 {A : Type} (f : A \u2192 A) (B : Set A) :\n    \u2203 (C : Set A), closure f B C := by\n  let F : Set (Set A) := { D : Set A | B \u2286 D \u2227 closed f D }\n  let C : Set A := \u22c2\u2080 F\n  apply Exists.intro C    --Goal : closure f B C\n  define                  --Goal : C \u2208 F \u2227 \u2200 x \u2208 F, C \u2286 x\n  apply And.intro\n  \u00b7 -- Proof that C \u2208 F\n    define                  --Goal : B \u2286 C \u2227 closed f C\n    apply And.intro\n    \u00b7 -- Proof that B \u2286 C\n      fix a : A\n      assume h1 : a \u2208 B       --Goal : a \u2208 C\n      define                  --Goal : \u2200 t \u2208 F, a \u2208 t\n      fix D : Set A\n      assume h2 : D \u2208 F\n      define at h2            --h2 : B \u2286 D \u2227 closed f D\n      show a \u2208 D from h2.left h1\n      done\n    \u00b7 -- Proof that C is closed under f\n      define                  --Goal : \u2200 x \u2208 C, f x \u2208 C\n      fix a : A\n      assume h1 : a \u2208 C       --Goal : f a \u2208 C\n      define                  --Goal : \u2200 t \u2208 F, f a \u2208 t\n      fix D : Set A\n      assume h2 : D \u2208 F       --Goal : f a \u2208 D\n      define at h1            --h1 : \u2200 t \u2208 F, a \u2208 t\n      have h3 : a \u2208 D := h1 D h2\n      define at h2            --h2 : B \u2286 D \u2227 closed f D\n      have h4 : closed f D := h2.right\n      define at h4            --h4 : \u2200 x \u2208 D, f x \u2208 D\n      show f a \u2208 D from h4 a h3\n      done\n    done\n  \u00b7 -- Proof that C is smallest\n    fix D : Set A\n    assume h1 : D \u2208 F      --Goal : sub A C D\n    define\n    fix a : A\n    assume h2 : a \u2208 C       --Goal : a \u2208 D\n    define at h2            --h2 : \u2200 t \u2208 F, a \u2208 t\n    show a \u2208 D from h2 D h1\n    done\n  done\n\ndef plus (m n : Int) : Int := m + n\n\ndef plus' : Int \u2192 Int \u2192 Int := fun (m n : Int) => m + n\n\ndef plus'' : Int \u2192 Int \u2192 Int := fun (m : Int) => (fun (n : Int) => m + n)\n\nexample : plus = plus'' := by rfl\n\nexample : plus' = plus'' := by rfl\n\n#eval plus 3 2     --Answer: 5\n\ntheorem Theorem_5_4_9 {A : Type} (f : A \u2192 A \u2192 A) (B : Set A) :\n    \u2203 (C : Set A), closure2 f B C := sorry\n\n/- Section 5.5 -/\ntheorem image_def {A B : Type} (f : A \u2192 B) (X : Set A) (b : B) :\n    b \u2208 image f X \u2194 \u2203 x \u2208 X, f x = b := by rfl\n\ntheorem inverse_image_def {A B : Type} (f : A \u2192 B) (Y : Set B) (a : A) :\n    a \u2208 inverse_image f Y \u2194 f a \u2208 Y := by rfl\n\ntheorem Theorem_5_5_2_1 {A B : Type} (f : A \u2192 B) (W X : Set A) :\n    image f (W \u2229 X) \u2286 image f W \u2229 image f X := by\n  fix y : B\n  assume h1 : y \u2208 image f (W \u2229 X)  --Goal : y \u2208 image f W \u2229 image f X\n  define at h1                     --h1 : \u2203 (x : A), x \u2208 W \u2229 X \u2227 f x = y\n  obtain (x : A) (h2 : x \u2208 W \u2229 X \u2227 f x = y) from h1\n  define : x \u2208 W \u2229 X at h2         --h2 : (x \u2208 W \u2227 x \u2208 X) \u2227 f x = y\n  apply And.intro\n  \u00b7 -- Proof that y \u2208 image f W\n    define                         --Goal : \u2203 (x : A), x \u2208 W \u2227 f x = y\n    show \u2203 (x : A), x \u2208 W \u2227 f x = y from\n      Exists.intro x (And.intro h2.left.left h2.right)\n    done\n  \u00b7 -- Proof that y \u2208 image f X\n    show y \u2208 image f X from\n      Exists.intro x (And.intro h2.left.right h2.right)\n    done\n  done\n\ntheorem Theorem_5_5_2_2 {A B : Type} (f : A \u2192 B) (W X : Set A)\n    (h1 : one_to_one f) : image f (W \u2229 X) = image f W \u2229 image f X := by\n  apply Set.ext\n  fix y : B      --Goal : y \u2208 image f (W \u2229 X) \u2194 y \u2208 image f W \u2229 image f X\n  apply Iff.intro\n  \u00b7 -- (\u2192)\n    assume h2 : y \u2208 image f (W \u2229 X)\n    show y \u2208 image f W \u2229 image f X from Theorem_5_5_2_1 f W X h2\n    done\n  \u00b7 -- (\u2190)\n    assume h2 : y \u2208 image f W \u2229 image f X  --Goal : y \u2208 image f (W \u2229 X)\n    define at h2                  --h2 : y \u2208 image f W \u2227 y \u2208 image f X\n    rewrite [image_def, image_def] at h2\n          --h2 : (\u2203 (x : A), x \u2208 W \u2227 f x = y) \u2227 \u2203 (x : A), x \u2208 X \u2227 f x = y\n    obtain (x1 : A) (h3 : x1 \u2208 W \u2227 f x1 = y) from h2.left\n    obtain (x2 : A) (h4 : x2 \u2208 X \u2227 f x2 = y) from h2.right\n    have h5 : f x2 = y := h4.right\n    rewrite [\u2190h3.right] at h5  --h5 : f x2 = f x1\n    define at h1               --h1 : \u2200 (x1 x2 : A), f x1 = f x2 \u2192 x1 = x2\n    have h6 : x2 = x1 := h1 x2 x1 h5\n    rewrite [h6] at h4           --h4 : x1 \u2208 X \u2227 f x1 = y\n    show y \u2208 image f (W \u2229 X) from\n      Exists.intro x1 (And.intro (And.intro h3.left h4.left) h3.right)\n    done\n  done", "meta": {"author": "djvelleman", "repo": "HTPILeanPackage", "sha": "b4a0ab0d0d5473ef27fbbbfba3f5d3208d5377da", "save_path": "github-repos/lean/djvelleman-HTPILeanPackage", "path": "github-repos/lean/djvelleman-HTPILeanPackage/HTPILeanPackage-b4a0ab0d0d5473ef27fbbbfba3f5d3208d5377da/HTPILib/Chap5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7314786982238074}}
{"text": "-- El_cociente_aplica_relaciones_de_equivalencia_en_particiones.lean\n-- El cociente aplica relaciones de equivalencia en particiones\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 8 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Definir la funci\u00f3n\n--    cociente : {R : A \u2192 A \u2192 Prop // equivalence R} \u2192 particion A\n-- tal que (cociente R) es la partici\u00f3n de A formada por las clases de\n-- equivalencia de la relaci\u00f3n de equivalencia R.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n@[ext] structure particion (A : Type) :=\n(Bloques    : set (set A))\n(Hno_vacios : \u2200 X \u2208 Bloques, (X : set A).nonempty)\n(Hrecubren  : \u2200 a, \u2203 X \u2208 Bloques, a \u2208 X)\n(Hdisjuntos : \u2200 X Y \u2208 Bloques, (X \u2229 Y : set A).nonempty \u2192 X = Y)\n\nnamespace particion\n\nvariable  {A : Type}\nvariable  {P : particion A}\nvariables {X Y : set A}\nvariable  (R : A \u2192 A \u2192 Prop)\n\ndef clase (a : A) :=\n  {b : A | R b a}\n\ndef clases : (A \u2192 A \u2192 Prop) \u2192 set (set A) :=\n  \u03bb R, {B : set A | \u2203 x : A, B = clase R x}\n\nlemma pertenece_clase_syss\n  {a b : A}\n  : b \u2208 clase R a \u2194 R b a :=\nby refl\n\nlemma clases_no_vacias\n  (hR: equivalence R)\n  : \u2200 (X : set A), X \u2208 clases R \u2192 X.nonempty :=\nbegin\n  rintros _ \u27e8a, rfl\u27e9,\n  use a,\n  rw pertenece_clase_syss,\n  apply hR.1,\nend\n\nlemma clases_recubren\n  (hR: equivalence R)\n  : \u2200 a, \u2203 X \u2208 clases R, a \u2208 X :=\nbegin\n  intro a,\n  use clase R a,\n  split,\n  { use a, },\n  { exact hR.1 a, },\nend\n\nlemma subclase_si_pertenece\n  {R : A \u2192 A \u2192 Prop}\n  (hR: equivalence R)\n  {a b : A}\n  : a \u2208 clase R b \u2192 clase R a \u2286 clase R b :=\n\u03bb hab z hza, hR.2.2 hza hab\n\nlemma clases_iguales_si_pertenece\n  {R : A \u2192 A \u2192 Prop}\n  (hR: equivalence R)\n  {a b : A}\n  : a \u2208 clase R b \u2192 clase R a = clase R b :=\n\u03bb hab, set.subset.antisymm\n        (subclase_si_pertenece hR hab)\n        (subclase_si_pertenece hR (hR.2.1 hab))\n\nlemma clases_disjuntas\n  (hR: equivalence R)\n  : \u2200 X Y \u2208 clases R, (X \u2229 Y : set A).nonempty \u2192 X = Y :=\nbegin\n  rintros X \u27e8a, rfl\u27e9 Y \u27e8b, rfl\u27e9 \u27e8c, hca, hcb\u27e9,\n  exact clases_iguales_si_pertenece hR (hR.2.2 (hR.2.1 hca) hcb),\nend\n\ndef cociente : {R : A \u2192 A \u2192 Prop // equivalence R} \u2192 particion A :=\n  \u03bb R, { Bloques    := {B : set A | \u2203 x : A, B = clase R.1 x},\n         Hno_vacios := clases_no_vacias R.1 R.2,\n         Hrecubren  := clases_recubren R.1 R.2,\n         Hdisjuntos := clases_disjuntas R.1 R.2, }\n\nend particion\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/El_cociente_aplica_relaciones_de_equivalencia_en_particiones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7314786977562567}}
{"text": "/-\nCopyright (c) 2021 Alex J. Best. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex J. Best\n-/\nimport analysis.convex.measure\nimport measure_theory.group.fundamental_domain\nimport measure_theory.measure.haar_lebesgue\n\n/-!\n# Geometry of numbers\n\nIn this file we prove some of the fundamental theorems in the geometry of numbers, as studied by\nHermann Minkowski.\n\n## Main results\n\n* `exists_pair_mem_lattice_not_disjoint_vadd`: Blichfeldt's principle, existence of two distinct\n  points in a subgroup such that the translates of a set by these two points are not disjoint when\n  the covolume of the subgroup is larger than the volume of the\n* `exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure`: Minkowski's theorem, existence of\n  a non-zero lattice point inside a convex symmetric domain of large enough volume.\n\n## TODO\n\n* Calculate the volume of the fundamental domain of a finite index subgroup\n* Voronoi diagrams\n* See [Pete L. Clark, *Abstract Geometry of Numbers: Linear Forms* (arXiv)](https://arxiv.org/abs/1405.2119)\n  for some more ideas.\n\n## References\n\n* [Pete L. Clark, *Geometry of Numbers with Applications to Number Theory*][clark_gon] p.28\n-/\n\nnamespace measure_theory\n\nopen ennreal finite_dimensional measure_theory measure_theory.measure set\nopen_locale pointwise\n\nvariables {E L : Type*} [measurable_space E] {\u03bc : measure E} {F s : set E}\n\n/-- **Blichfeldt's Theorem**. If the volume of the set `s` is larger than the covolume of the\ncountable subgroup `L` of `E`, then there exists two distincts points `x, y \u2208 L` such that `(x + s)`\nand `(y + s)` are not disjoint. -/\nlemma exists_pair_mem_lattice_not_disjoint_vadd [add_comm_group L] [countable L]\n  [add_action L E] [measurable_space L] [has_measurable_vadd L E] [vadd_invariant_measure L E \u03bc]\n  (fund : is_add_fundamental_domain L F \u03bc) (hS : null_measurable_set s \u03bc) (h : \u03bc F < \u03bc s) :\n  \u2203 x y : L, x \u2260 y \u2227 \u00ac disjoint (x +\u1d65 s) (y +\u1d65 s) :=\nbegin\n  contrapose! h,\n  exact ((fund.measure_eq_tsum _).trans (measure_Union\u2080 (pairwise.mono h $ \u03bb i j hij,\n    (hij.mono inf_le_left inf_le_left).ae_disjoint) $ \u03bb _,\n    (hS.vadd _).inter fund.null_measurable_set).symm).trans_le\n    (measure_mono $ Union_subset $ \u03bb _, inter_subset_right _ _),\nend\n\n/-- The **Minkowksi Convex Body Theorem**. If `s` is a convex symmetric domain of `E` whose volume\nis large enough compared to the covolume of a lattice `L` of `E`, then it contains a non-zero\nlattice point of `L`.  -/\nlemma exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure [normed_add_comm_group E]\n  [normed_space \u211d E] [borel_space E] [finite_dimensional \u211d E] [is_add_haar_measure \u03bc]\n  {L : add_subgroup E} [countable L] (fund : is_add_fundamental_domain L F \u03bc)\n  (h : \u03bc F * 2 ^ finrank \u211d E < \u03bc s) (h_symm : \u2200 x \u2208 s, -x \u2208 s) (h_conv : convex \u211d s) :\n  \u2203 x \u2260 0, ((x : L) : E) \u2208 s :=\nbegin\n  have h_vol : \u03bc F < \u03bc ((2\u207b\u00b9 : \u211d) \u2022 s),\n  { rwa [add_haar_smul_of_nonneg \u03bc (by norm_num : 0 \u2264 (2 : \u211d)\u207b\u00b9) s, \u2190mul_lt_mul_right\n      (pow_ne_zero (finrank \u211d E) (two_ne_zero' _)) (pow_ne_top two_ne_top), mul_right_comm,\n      of_real_pow (by norm_num : 0 \u2264 (2 : \u211d)\u207b\u00b9), \u2190of_real_inv_of_pos zero_lt_two, of_real_bit0,\n      of_real_one, \u2190mul_pow, ennreal.inv_mul_cancel two_ne_zero two_ne_top, one_pow, one_mul] },\n  obtain \u27e8x, y, hxy, h\u27e9 := exists_pair_mem_lattice_not_disjoint_vadd fund\n    ((h_conv.smul _).null_measurable_set _) h_vol,\n  obtain \u27e8_, \u27e8v, hv, rfl\u27e9, w, hw, hvw\u27e9 := not_disjoint_iff.mp h,\n  refine \u27e8x - y, sub_ne_zero.2 hxy, _\u27e9,\n  rw mem_inv_smul_set_iff\u2080 (two_ne_zero' \u211d) at hv hw,\n  simp_rw [add_subgroup.vadd_def, vadd_eq_add, add_comm _ w, \u2190sub_eq_sub_iff_add_eq_add,\n    \u2190add_subgroup.coe_sub] at hvw,\n  rw [\u2190hvw, \u2190inv_smul_smul\u2080 (two_ne_zero' \u211d) (_ - _), smul_sub, sub_eq_add_neg, smul_add],\n  refine h_conv hw (h_symm _ hv) _ _ _; norm_num,\nend\n\nend measure_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/group/geometry_of_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7314664147116446}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport analysis.inner_product_space.projection\nimport linear_algebra.orientation\n\n/-!\n# Orientations of real inner product spaces.\n\nThis file provides definitions and proves lemmas about orientations of real inner product spaces.\n\n## Main definitions\n\n* `orientation.fin_orthonormal_basis` is an orthonormal basis, indexed by `fin n`, with the given\norientation.\n\n-/\n\nnoncomputable theory\n\nvariables {E : Type*} [inner_product_space \u211d E]\nvariables {\u03b9 : Type*} [fintype \u03b9] [decidable_eq \u03b9]\n\nopen finite_dimensional\n\n/-- `basis.adjust_to_orientation`, applied to an orthonormal basis, produces an orthonormal\nbasis. -/\nlemma orthonormal.orthonormal_adjust_to_orientation [nonempty \u03b9] {e : basis \u03b9 \u211d E}\n  (h : orthonormal \u211d e) (x : orientation \u211d E \u03b9) : orthonormal \u211d (e.adjust_to_orientation x) :=\nh.orthonormal_of_forall_eq_or_eq_neg (e.adjust_to_orientation_apply_eq_or_eq_neg x)\n\n/-- An orthonormal basis, indexed by `fin n`, with the given orientation. -/\nprotected def orientation.fin_orthonormal_basis {n : \u2115} (hn : 0 < n) (h : finrank \u211d E = n)\n  (x : orientation \u211d E (fin n)) : basis (fin n) \u211d E :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  haveI := finite_dimensional_of_finrank (h.symm \u25b8 hn : 0 < finrank \u211d E),\n  exact (fin_std_orthonormal_basis h).adjust_to_orientation x\nend\n\n/-- `orientation.fin_orthonormal_basis` is orthonormal. -/\nprotected lemma orientation.fin_orthonormal_basis_orthonormal {n : \u2115} (hn : 0 < n)\n  (h : finrank \u211d E = n) (x : orientation \u211d E (fin n)) :\n  orthonormal \u211d (x.fin_orthonormal_basis hn h) :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  haveI := finite_dimensional_of_finrank (h.symm \u25b8 hn : 0 < finrank \u211d E),\n  exact (fin_std_orthonormal_basis_orthonormal h).orthonormal_adjust_to_orientation _\nend\n\n/-- `orientation.fin_orthonormal_basis` gives a basis with the required orientation. -/\n@[simp] lemma orientation.fin_orthonormal_basis_orientation {n : \u2115} (hn : 0 < n)\n  (h : finrank \u211d E = n) (x : orientation \u211d E (fin n)) :\n  (x.fin_orthonormal_basis hn h).orientation = x :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  exact basis.orientation_adjust_to_orientation _ _\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/inner_product_space/orientation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7314663972229083}}
{"text": "/-\nCopyright (c) 2021 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Devon Tuma\n-/\nimport analysis.asymptotics.asymptotics\nimport analysis.normed_space.ordered\nimport data.polynomial.eval\nimport topology.algebra.order.liminf_limsup\n\n/-!\n# Super-Polynomial Function Decay\n\nThis file defines a predicate `asymptotics.superpolynomial_decay f` for a function satisfying\n  one of following equivalent definitions (The definition is in terms of the first condition):\n\n* `x ^ n * f` tends to `\ud835\udcdd 0` for all (or sufficiently large) naturals `n`\n* `|x ^ n * f|` tends to `\ud835\udcdd 0` for all naturals `n` (`superpolynomial_decay_iff_abs_tendsto_zero`)\n* `|x ^ n * f|` is bounded for all naturals `n` (`superpolynomial_decay_iff_abs_is_bounded_under`)\n* `f` is `o(x ^ c)` for all integers `c` (`superpolynomial_decay_iff_is_o`)\n* `f` is `O(x ^ c)` for all integers `c` (`superpolynomial_decay_iff_is_O`)\n\nThese conditions are all equivalent to conditions in terms of polynomials, replacing `x ^ c` with\n  `p(x)` or `p(x)\u207b\u00b9` as appropriate, since asymptotically `p(x)` behaves like `X ^ p.nat_degree`.\nThese further equivalences are not proven in mathlib but would be good future projects.\n\nThe definition of superpolynomial decay for `f : \u03b1 \u2192 \u03b2` is relative to a parameter `k : \u03b1 \u2192 \u03b2`.\nSuper-polynomial decay then means `f x` decays faster than `(k x) ^ c` for all integers `c`.\nEquivalently `f x` decays faster than `p.eval (k x)` for all polynomials `p : polynomial \u03b2`.\nThe definition is also relative to a filter `l : filter \u03b1` where the decay rate is compared.\n\nWhen the map `k` is given by `n \u21a6 \u2191n : \u2115 \u2192 \u211d` this defines negligible functions:\nhttps://en.wikipedia.org/wiki/Negligible_function\n\nWhen the map `k` is given by `(r\u2081,...,r\u2099) \u21a6 r\u2081*...*r\u2099 : \u211d\u207f \u2192 \u211d` this is equivalent\n  to the definition of rapidly decreasing functions given here:\nhttps://ncatlab.org/nlab/show/rapidly+decreasing+function\n\n# Main Theorems\n\n* `superpolynomial_decay.polynomial_mul` says that if `f(x)` is negligible,\n    then so is `p(x) * f(x)` for any polynomial `p`.\n* `superpolynomial_decay_iff_zpow_tendsto_zero` gives an equivalence between definitions in terms\n    of decaying faster than `k(x) ^ n` for all naturals `n` or `k(x) ^ c` for all integer `c`.\n-/\n\nnamespace asymptotics\n\nopen_locale topological_space\nopen filter\n\n/-- `f` has superpolynomial decay in parameter `k` along filter `l` if\n  `k ^ n * f` tends to zero at `l` for all naturals `n` -/\ndef superpolynomial_decay {\u03b1 \u03b2 : Type*} [topological_space \u03b2] [comm_semiring \u03b2]\n  (l : filter \u03b1) (k : \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) :=\n\u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), (k a) ^ n * f a) l (\ud835\udcdd 0)\n\nvariables {\u03b1 \u03b2 : Type*} {l : filter \u03b1} {k : \u03b1 \u2192 \u03b2} {f g g' : \u03b1 \u2192 \u03b2}\n\nsection comm_semiring\n\nvariables [topological_space \u03b2] [comm_semiring \u03b2]\n\nlemma superpolynomial_decay.congr' (hf : superpolynomial_decay l k f)\n  (hfg : f =\u1da0[l] g) : superpolynomial_decay l k g :=\n\u03bb z, (hf z).congr' (eventually_eq.mul (eventually_eq.refl l _) hfg)\n\nlemma superpolynomial_decay.congr (hf : superpolynomial_decay l k f)\n  (hfg : \u2200 x, f x = g x) : superpolynomial_decay l k g :=\n\u03bb z, (hf z).congr (\u03bb x, congr_arg (\u03bb a, k x ^ z * a) $ hfg x)\n\n@[simp]\nlemma superpolynomial_decay_zero (l : filter \u03b1) (k : \u03b1 \u2192 \u03b2) :\n  superpolynomial_decay l k 0 :=\n\u03bb z, by simpa only [pi.zero_apply, mul_zero] using tendsto_const_nhds\n\nlemma superpolynomial_decay.add [has_continuous_add \u03b2] (hf : superpolynomial_decay l k f)\n  (hg : superpolynomial_decay l k g) : superpolynomial_decay l k (f + g) :=\n\u03bb z, by simpa only [mul_add, add_zero, pi.add_apply] using (hf z).add (hg z)\n\nlemma superpolynomial_decay.mul [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (hg : superpolynomial_decay l k g) : superpolynomial_decay l k (f * g) :=\n\u03bb z, by simpa only [mul_assoc, one_mul, mul_zero, pow_zero] using (hf z).mul (hg 0)\n\nlemma superpolynomial_decay.mul_const [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (c : \u03b2) : superpolynomial_decay l k (\u03bb n, f n * c) :=\n\u03bb z, by simpa only [\u2190mul_assoc, zero_mul] using tendsto.mul_const c (hf z)\n\nlemma superpolynomial_decay.const_mul [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (c : \u03b2) : superpolynomial_decay l k (\u03bb n, c * f n) :=\n(hf.mul_const c).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.param_mul (hf : superpolynomial_decay l k f) :\n  superpolynomial_decay l k (k * f) :=\n\u03bb z, tendsto_nhds.2 (\u03bb s hs hs0, l.sets_of_superset ((tendsto_nhds.1 (hf $ z + 1)) s hs hs0)\n  (\u03bb x hx, by simpa only [set.mem_preimage, pi.mul_apply, \u2190 mul_assoc, \u2190 pow_succ'] using hx))\n\nlemma superpolynomial_decay.mul_param (hf : superpolynomial_decay l k f) :\n  superpolynomial_decay l k (f * k) :=\n(hf.param_mul).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.param_pow_mul (hf : superpolynomial_decay l k f)\n  (n : \u2115) : superpolynomial_decay l k (k ^ n * f) :=\nbegin\n  induction n with n hn,\n  { simpa only [one_mul, pow_zero] using hf },\n  { simpa only [pow_succ, mul_assoc] using hn.param_mul }\nend\n\nlemma superpolynomial_decay.mul_param_pow (hf : superpolynomial_decay l k f)\n  (n : \u2115) : superpolynomial_decay l k (f * k ^ n) :=\n(hf.param_pow_mul n).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.polynomial_mul [has_continuous_add \u03b2] [has_continuous_mul \u03b2]\n  (hf : superpolynomial_decay l k f) (p : polynomial \u03b2) :\n  superpolynomial_decay l k (\u03bb x, (p.eval $ k x) * f x) :=\npolynomial.induction_on' p (\u03bb p q hp hq, by simpa [add_mul] using hp.add hq)\n  (\u03bb n c, by simpa [mul_assoc] using (hf.param_pow_mul n).const_mul c)\n\nlemma superpolynomial_decay.mul_polynomial [has_continuous_add \u03b2] [has_continuous_mul \u03b2]\n  (hf : superpolynomial_decay l k f) (p : polynomial \u03b2) :\n  superpolynomial_decay l k (\u03bb x, f x * (p.eval $ k x)) :=\n(hf.polynomial_mul p).congr (\u03bb _, mul_comm _ _)\n\nend comm_semiring\n\nsection ordered_comm_semiring\n\nvariables [topological_space \u03b2] [ordered_comm_semiring \u03b2] [order_topology \u03b2]\n\n\n\nend ordered_comm_semiring\n\nsection linear_ordered_comm_ring\n\nvariables [topological_space \u03b2] [linear_ordered_comm_ring \u03b2] [order_topology \u03b2]\n\nvariables (l k f)\n\nlemma superpolynomial_decay_iff_abs_tendsto_zero :\n  superpolynomial_decay l k f \u2194 \u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), |(k a) ^ n * f a|) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h z, (tendsto_zero_iff_abs_tendsto_zero _).1 (h z),\n  \u03bb h z, (tendsto_zero_iff_abs_tendsto_zero _).2 (h z)\u27e9\n\nlemma superpolynomial_decay_iff_superpolynomial_decay_abs :\n  superpolynomial_decay l k f \u2194 superpolynomial_decay l (\u03bb a, |k a|) (\u03bb a, |f a|) :=\n(superpolynomial_decay_iff_abs_tendsto_zero l k f).trans\n  (by simp_rw [superpolynomial_decay, abs_mul, abs_pow])\n\nvariables {l k f}\n\nlemma superpolynomial_decay.trans_eventually_abs_le (hf : superpolynomial_decay l k f)\n  (hfg : abs \u2218 g \u2264\u1da0[l] abs \u2218 f) : superpolynomial_decay l k g :=\nbegin\n  rw superpolynomial_decay_iff_abs_tendsto_zero at hf \u22a2,\n  refine \u03bb z, tendsto_of_tendsto_of_tendsto_of_le_of_le' (tendsto_const_nhds) (hf z)\n    (eventually_of_forall $ \u03bb x, abs_nonneg _) (hfg.mono $ \u03bb x hx, _),\n  calc |k x ^ z * g x| = |k x ^ z| * |g x| : abs_mul (k x ^ z) (g x)\n    ... \u2264 |k x ^ z| * |f x| : mul_le_mul le_rfl hx (abs_nonneg _) (abs_nonneg _)\n    ... = |k x ^ z * f x| : (abs_mul (k x ^ z) (f x)).symm,\nend\n\nlemma superpolynomial_decay.trans_abs_le (hf : superpolynomial_decay l k f)\n  (hfg : \u2200 x, |g x| \u2264 |f x|) : superpolynomial_decay l k g :=\nhf.trans_eventually_abs_le (eventually_of_forall hfg)\n\nend linear_ordered_comm_ring\n\nsection field\n\nvariables [topological_space \u03b2] [field \u03b2] (l k f)\n\nlemma superpolynomial_decay_mul_const_iff [has_continuous_mul \u03b2] {c : \u03b2} (hc0 : c \u2260 0) :\n  superpolynomial_decay l k (\u03bb n, f n * c) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.mul_const c\u207b\u00b9).congr (\u03bb x, by simp [mul_assoc, mul_inv_cancel hc0]), \u03bb h, h.mul_const c\u27e9\n\nlemma superpolynomial_decay_const_mul_iff [has_continuous_mul \u03b2] {c : \u03b2} (hc0 : c \u2260 0) :\n  superpolynomial_decay l k (\u03bb n, c * f n) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.const_mul c\u207b\u00b9).congr (\u03bb x, by simp [\u2190 mul_assoc, inv_mul_cancel hc0]), \u03bb h, h.const_mul c\u27e9\n\nvariables {l k f}\n\nend field\n\nsection linear_ordered_field\n\nvariables [topological_space \u03b2] [linear_ordered_field \u03b2] [order_topology \u03b2]\n\nvariable (f)\n\nlemma superpolynomial_decay_iff_abs_is_bounded_under (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2115), is_bounded_under (\u2264) l (\u03bb (a : \u03b1), |(k a) ^ z * f a|) :=\nbegin\n  refine \u27e8\u03bb h z, tendsto.is_bounded_under_le (tendsto.abs (h z)),\n    \u03bb h, (superpolynomial_decay_iff_abs_tendsto_zero l k f).2 (\u03bb z, _)\u27e9,\n  obtain \u27e8m, hm\u27e9 := h (z + 1),\n  have h1 : tendsto (\u03bb (a : \u03b1), (0 : \u03b2)) l (\ud835\udcdd 0) := tendsto_const_nhds,\n  have h2 : tendsto (\u03bb (a : \u03b1), |(k a)\u207b\u00b9| * m) l (\ud835\udcdd 0) := (zero_mul m) \u25b8 tendsto.mul_const m\n    ((tendsto_zero_iff_abs_tendsto_zero _).1 hk.inv_tendsto_at_top),\n  refine tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 h2\n    (eventually_of_forall (\u03bb x, abs_nonneg _)) ((eventually_map.1 hm).mp _),\n  refine ((eventually_ne_of_tendsto_at_top hk 0).mono $ \u03bb x hk0 hx, _),\n  refine le_trans (le_of_eq _) (mul_le_mul_of_nonneg_left hx $ abs_nonneg (k x)\u207b\u00b9),\n  rw [\u2190 abs_mul, \u2190 mul_assoc, pow_succ, \u2190 mul_assoc, inv_mul_cancel hk0, one_mul],\nend\n\nlemma superpolynomial_decay_iff_zpow_tendsto_zero (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), tendsto (\u03bb (a : \u03b1), (k a) ^ z * f a) l (\ud835\udcdd 0) :=\nbegin\n  refine \u27e8\u03bb h z, _, \u03bb h n, by simpa only [zpow_coe_nat] using h (n : \u2124)\u27e9,\n  by_cases hz : 0 \u2264 z,\n  { lift z to \u2115 using hz,\n    simpa using h z },\n  { have : tendsto (\u03bb a, (k a) ^ z) l (\ud835\udcdd 0) :=\n      tendsto.comp (tendsto_zpow_at_top_zero (not_le.1 hz)) hk,\n    have h : tendsto f l (\ud835\udcdd 0) := by simpa using h 0,\n    exact (zero_mul (0 : \u03b2)) \u25b8 this.mul h },\nend\n\nvariable {f}\n\nlemma superpolynomial_decay.param_zpow_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) (z : \u2124) : superpolynomial_decay l k (\u03bb a, k a ^ z * f a) :=\nbegin\n  rw superpolynomial_decay_iff_zpow_tendsto_zero _ hk at hf \u22a2,\n  refine \u03bb z', (hf $ z' + z).congr' ((eventually_ne_of_tendsto_at_top hk 0).mono (\u03bb x hx, _)),\n  simp [zpow_add\u2080 hx, mul_assoc, pi.mul_apply],\nend\n\nlemma superpolynomial_decay.mul_param_zpow (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) (z : \u2124) : superpolynomial_decay l k (\u03bb a, f a * k a ^ z) :=\n(hf.param_zpow_mul hk z).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.inv_param_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) : superpolynomial_decay l k (k\u207b\u00b9 * f) :=\nby simpa using (hf.param_zpow_mul hk (-1))\n\nlemma superpolynomial_decay.param_inv_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) : superpolynomial_decay l k (f * k\u207b\u00b9) :=\n(hf.inv_param_mul hk).congr (\u03bb _, mul_comm _ _)\n\nvariable (f)\n\nlemma superpolynomial_decay_param_mul_iff (hk : tendsto k l at_top) :\n  superpolynomial_decay l k (k * f) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.inv_param_mul hk).congr' ((eventually_ne_of_tendsto_at_top hk 0).mono\n  (\u03bb x hx, by simp [\u2190 mul_assoc, inv_mul_cancel hx])), \u03bb h, h.param_mul\u27e9\n\nlemma superpolynomial_decay_mul_param_iff (hk : tendsto k l at_top) :\n  superpolynomial_decay l k (f * k) \u2194 superpolynomial_decay l k f :=\nby simpa [mul_comm k] using superpolynomial_decay_param_mul_iff f hk\n\nlemma superpolynomial_decay_param_pow_mul_iff (hk : tendsto k l at_top) (n : \u2115) :\n  superpolynomial_decay l k (k ^ n * f) \u2194 superpolynomial_decay l k f :=\nbegin\n  induction n with n hn,\n  { simp },\n  { simpa [pow_succ, \u2190 mul_comm k, mul_assoc,\n      superpolynomial_decay_param_mul_iff (k ^ n * f) hk] using hn }\nend\n\nlemma superpolynomial_decay_mul_param_pow_iff (hk : tendsto k l at_top) (n : \u2115) :\n  superpolynomial_decay l k (f * k ^ n) \u2194 superpolynomial_decay l k f :=\nby simpa [mul_comm f] using superpolynomial_decay_param_pow_mul_iff f hk n\n\nvariable {f}\n\nend linear_ordered_field\n\nsection normed_linear_ordered_field\n\nvariable [normed_linear_ordered_field \u03b2]\n\nvariables (l k f)\n\nlemma superpolynomial_decay_iff_norm_tendsto_zero :\n  superpolynomial_decay l k f \u2194 \u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), \u2225(k a) ^ n * f a\u2225) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h z, tendsto_zero_iff_norm_tendsto_zero.1 (h z),\n  \u03bb h z, tendsto_zero_iff_norm_tendsto_zero.2 (h z)\u27e9\n\nlemma superpolynomial_decay_iff_superpolynomial_decay_norm :\n  superpolynomial_decay l k f \u2194 superpolynomial_decay l (\u03bb a, \u2225k a\u2225) (\u03bb a, \u2225f a\u2225) :=\n(superpolynomial_decay_iff_norm_tendsto_zero l k f).trans (by simp [superpolynomial_decay])\n\nvariables {l k}\n\nvariable [order_topology \u03b2]\n\nlemma superpolynomial_decay_iff_is_O (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), is_O f (\u03bb (a : \u03b1), (k a) ^ z) l :=\nbegin\n  refine (superpolynomial_decay_iff_zpow_tendsto_zero f hk).trans _,\n  have hk0 : \u2200\u1da0 x in l, k x \u2260 0 := eventually_ne_of_tendsto_at_top hk 0,\n  refine \u27e8\u03bb h z, _, \u03bb h z, _\u27e9,\n  { refine is_O_of_div_tendsto_nhds (hk0.mono (\u03bb x hx hxz, absurd (zpow_eq_zero hxz) hx)) 0 _,\n    have : (\u03bb (a : \u03b1), k a ^ z)\u207b\u00b9 = (\u03bb (a : \u03b1), k a ^ (- z)) := funext (\u03bb x, by simp),\n    rw [div_eq_mul_inv, mul_comm f, this],\n    exact h (-z) },\n  { suffices : is_O (\u03bb (a : \u03b1), k a ^ z * f a) (\u03bb (a : \u03b1), (k a)\u207b\u00b9) l,\n    from is_O.trans_tendsto this hk.inv_tendsto_at_top,\n    refine ((is_O_refl (\u03bb a, (k a) ^ z) l).mul (h (- (z + 1)))).trans\n      (is_O.of_bound 1 $ hk0.mono (\u03bb a ha0, _)),\n    simp only [one_mul, neg_add z 1, zpow_add\u2080 ha0, \u2190 mul_assoc, zpow_neg\u2080,\n      mul_inv_cancel (zpow_ne_zero z ha0), zpow_one] }\nend\n\nlemma superpolynomial_decay_iff_is_o (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), is_o f (\u03bb (a : \u03b1), (k a) ^ z) l :=\nbegin\n  refine \u27e8\u03bb h z, _, \u03bb h, (superpolynomial_decay_iff_is_O f hk).2 (\u03bb z, (h z).is_O)\u27e9,\n  have hk0 : \u2200\u1da0 x in l, k x \u2260 0 := eventually_ne_of_tendsto_at_top hk 0,\n  have : is_o (\u03bb (x : \u03b1), (1 : \u03b2)) k l := is_o_of_tendsto'\n    (hk0.mono (\u03bb x hkx hkx', absurd hkx' hkx)) (by simpa using hk.inv_tendsto_at_top),\n  have : is_o f (\u03bb (x : \u03b1), k x * k x ^ (z - 1)) l,\n  by simpa using this.mul_is_O (((superpolynomial_decay_iff_is_O f hk).1 h) $ z - 1),\n  refine this.trans_is_O (is_O.of_bound 1 (hk0.mono $ \u03bb x hkx, le_of_eq _)),\n  rw [one_mul, zpow_sub_one\u2080 hkx, mul_comm (k x), mul_assoc, inv_mul_cancel hkx, mul_one],\nend\n\nvariable {f}\n\nend normed_linear_ordered_field\n\nend asymptotics\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/asymptotics/superpolynomial_decay.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7314663933962839}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n-/\nimport measure_theory.constructions.pi\n\n/-!\n# Independence of sets of sets and measure spaces (\u03c3-algebras)\n\n* A family of sets of sets `\u03c0 : \u03b9 \u2192 set (set \u03a9)` is independent with respect to a measure `\u03bc` if for\n  any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 \u2208 \u03c0 i_1, ..., f i_n \u2208 \u03c0 i_n`,\n  `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i) `. It will be used for families of \u03c0-systems.\n* A family of measurable space structures (i.e. of \u03c3-algebras) is independent with respect to a\n  measure `\u03bc` (typically defined on a finer \u03c3-algebra) if the family of sets of measurable sets they\n  define is independent. I.e., `m : \u03b9 \u2192 measurable_space \u03a9` is independent with respect to a\n  measure `\u03bc` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets\n  `f i_1 \u2208 m i_1, ..., f i_n \u2208 m i_n`, then `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i)`.\n* Independence of sets (or events in probabilistic parlance) is defined as independence of the\n  measurable space structures they generate: a set `s` generates the measurable space structure with\n  measurable sets `\u2205, s, s\u1d9c, univ`.\n* Independence of functions (or random variables) is also defined as independence of the measurable\n  space structures they generate: a function `f` for which we have a measurable space `m` on the\n  codomain generates `measurable_space.comap f m`.\n\n## Main statements\n\n* `Indep_sets.Indep`: if \u03c0-systems are independent as sets of sets, then the\n  measurable space structures they generate are independent.\n* `indep_sets.indep`: variant with two \u03c0-systems.\n* `measure_zero_or_one_of_measurable_set_limsup_at_top`: Kolmogorov's 0-1 law. Any set which is\n  measurable with respect to the tail \u03c3-algebra `limsup s at_top` of an independent sequence of\n  \u03c3-algebras `s` has probability 0 or 1.\n\n## Implementation notes\n\nWe provide one main definition of independence:\n* `Indep_sets`: independence of a family of sets of sets `pi : \u03b9 \u2192 set (set \u03a9)`.\nThree other independence notions are defined using `Indep_sets`:\n* `Indep`: independence of a family of measurable space structures `m : \u03b9 \u2192 measurable_space \u03a9`,\n* `Indep_set`: independence of a family of sets `s : \u03b9 \u2192 set \u03a9`,\n* `Indep_fun`: independence of a family of functions. For measurable spaces\n  `m : \u03a0 (i : \u03b9), measurable_space (\u03b2 i)`, we consider functions `f : \u03a0 (i : \u03b9), \u03a9 \u2192 \u03b2 i`.\n\nAdditionally, we provide four corresponding statements for two measurable space structures (resp.\nsets of sets, sets, functions) instead of a family. These properties are denoted by the same names\nas for a family, but without a capital letter, for example `indep_fun` is the version of `Indep_fun`\nfor two functions.\n\nThe definition of independence for `Indep_sets` uses finite sets (`finset`). An alternative and\nequivalent way of defining independence would have been to use countable sets.\nTODO: prove that equivalence.\n\nMost of the definitions and lemma in this file list all variables instead of using the `variables`\nkeyword at the beginning of a section, for example\n`lemma indep.symm {\u03a9} {m\u2081 m\u2082 : measurable_space \u03a9} [measurable_space \u03a9] {\u03bc : measure \u03a9} ...` .\nThis is intentional, to be able to control the order of the `measurable_space` variables. Indeed\nwhen defining `\u03bc` in the example above, the measurable space used is the last one defined, here\n`[measurable_space \u03a9]`, and not `m\u2081` or `m\u2082`.\n\n## References\n\n* Williams, David. Probability with martingales. Cambridge university press, 1991.\nPart A, Chapter 4.\n-/\n\nopen measure_theory measurable_space\nopen_locale big_operators measure_theory ennreal\n\nnamespace probability_theory\n\nvariables {\u03a9 \u03b9 : Type*}\n\nsection definitions\n\n/-- A family of sets of sets `\u03c0 : \u03b9 \u2192 set (set \u03a9)` is independent with respect to a measure `\u03bc` if\nfor any finite set of indices `s = {i_1, ..., i_n}`, for any sets\n`f i_1 \u2208 \u03c0 i_1, ..., f i_n \u2208 \u03c0 i_n`, then `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i) `.\nIt will be used for families of pi_systems. -/\ndef Indep_sets [measurable_space \u03a9] (\u03c0 : \u03b9 \u2192 set (set \u03a9)) (\u03bc : measure \u03a9 . volume_tac) :\n  Prop :=\n\u2200 (s : finset \u03b9) {f : \u03b9 \u2192 set \u03a9} (H : \u2200 i, i \u2208 s \u2192 f i \u2208 \u03c0 i), \u03bc (\u22c2 i \u2208 s, f i) = \u220f i in s, \u03bc (f i)\n\n/-- Two sets of sets `s\u2081, s\u2082` are independent with respect to a measure `\u03bc` if for any sets\n`t\u2081 \u2208 p\u2081, t\u2082 \u2208 s\u2082`, then `\u03bc (t\u2081 \u2229 t\u2082) = \u03bc (t\u2081) * \u03bc (t\u2082)` -/\ndef indep_sets [measurable_space \u03a9] (s1 s2 : set (set \u03a9)) (\u03bc : measure \u03a9 . volume_tac) : Prop :=\n\u2200 t1 t2 : set \u03a9, t1 \u2208 s1 \u2192 t2 \u2208 s2 \u2192 \u03bc (t1 \u2229 t2) = \u03bc t1 * \u03bc t2\n\n/-- A family of measurable space structures (i.e. of \u03c3-algebras) is independent with respect to a\nmeasure `\u03bc` (typically defined on a finer \u03c3-algebra) if the family of sets of measurable sets they\ndefine is independent. `m : \u03b9 \u2192 measurable_space \u03a9` is independent with respect to measure `\u03bc` if\nfor any finite set of indices `s = {i_1, ..., i_n}`, for any sets\n`f i_1 \u2208 m i_1, ..., f i_n \u2208 m i_n`, then `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i) `. -/\ndef Indep (m : \u03b9 \u2192 measurable_space \u03a9) [measurable_space \u03a9] (\u03bc : measure \u03a9 . volume_tac) :\n  Prop :=\nIndep_sets (\u03bb x, {s | measurable_set[m x] s}) \u03bc\n\n/-- Two measurable space structures (or \u03c3-algebras) `m\u2081, m\u2082` are independent with respect to a\nmeasure `\u03bc` (defined on a third \u03c3-algebra) if for any sets `t\u2081 \u2208 m\u2081, t\u2082 \u2208 m\u2082`,\n`\u03bc (t\u2081 \u2229 t\u2082) = \u03bc (t\u2081) * \u03bc (t\u2082)` -/\ndef indep (m\u2081 m\u2082 : measurable_space \u03a9) [measurable_space \u03a9] (\u03bc : measure \u03a9 . volume_tac) :\n  Prop :=\nindep_sets {s | measurable_set[m\u2081] s} {s | measurable_set[m\u2082] s} \u03bc\n\n/-- A family of sets is independent if the family of measurable space structures they generate is\nindependent. For a set `s`, the generated measurable space has measurable sets `\u2205, s, s\u1d9c, univ`. -/\ndef Indep_set [measurable_space \u03a9] (s : \u03b9 \u2192 set \u03a9) (\u03bc : measure \u03a9 . volume_tac) : Prop :=\nIndep (\u03bb i, generate_from {s i}) \u03bc\n\n/-- Two sets are independent if the two measurable space structures they generate are independent.\nFor a set `s`, the generated measurable space structure has measurable sets `\u2205, s, s\u1d9c, univ`. -/\ndef indep_set [measurable_space \u03a9] (s t : set \u03a9) (\u03bc : measure \u03a9 . volume_tac) : Prop :=\nindep (generate_from {s}) (generate_from {t}) \u03bc\n\n/-- A family of functions defined on the same space `\u03a9` and taking values in possibly different\nspaces, each with a measurable space structure, is independent if the family of measurable space\nstructures they generate on `\u03a9` is independent. For a function `g` with codomain having measurable\nspace structure `m`, the generated measurable space structure is `measurable_space.comap g m`. -/\ndef Indep_fun [measurable_space \u03a9] {\u03b2 : \u03b9 \u2192 Type*} (m : \u03a0 (x : \u03b9), measurable_space (\u03b2 x))\n  (f : \u03a0 (x : \u03b9), \u03a9 \u2192 \u03b2 x) (\u03bc : measure \u03a9 . volume_tac) : Prop :=\nIndep (\u03bb x, measurable_space.comap (f x) (m x)) \u03bc\n\n/-- Two functions are independent if the two measurable space structures they generate are\nindependent. For a function `f` with codomain having measurable space structure `m`, the generated\nmeasurable space structure is `measurable_space.comap f m`. -/\ndef indep_fun {\u03b2 \u03b3} [measurable_space \u03a9] [m\u03b2 : measurable_space \u03b2] [m\u03b3 : measurable_space \u03b3]\n  (f : \u03a9 \u2192 \u03b2) (g : \u03a9 \u2192 \u03b3) (\u03bc : measure \u03a9 . volume_tac) : Prop :=\nindep (measurable_space.comap f m\u03b2) (measurable_space.comap g m\u03b3) \u03bc\n\nend definitions\n\nsection indep\n\n@[symm] lemma indep_sets.symm {s\u2081 s\u2082 : set (set \u03a9)} [measurable_space \u03a9] {\u03bc : measure \u03a9}\n  (h : indep_sets s\u2081 s\u2082 \u03bc) :\n  indep_sets s\u2082 s\u2081 \u03bc :=\nby { intros t1 t2 ht1 ht2, rw [set.inter_comm, mul_comm], exact h t2 t1 ht2 ht1, }\n\n@[symm] lemma indep.symm {m\u2081 m\u2082 : measurable_space \u03a9} [measurable_space \u03a9] {\u03bc : measure \u03a9}\n  (h : indep m\u2081 m\u2082 \u03bc) :\n  indep m\u2082 m\u2081 \u03bc :=\nindep_sets.symm h\n\nlemma indep_bot_right (m' : measurable_space \u03a9) {m : measurable_space \u03a9}\n  {\u03bc : measure \u03a9} [is_probability_measure \u03bc] :\n  indep m' \u22a5 \u03bc :=\nbegin\n  intros s t hs ht,\n  rw [set.mem_set_of_eq, measurable_space.measurable_set_bot_iff] at ht,\n  cases ht,\n  { rw [ht, set.inter_empty, measure_empty, mul_zero], },\n  { rw [ht, set.inter_univ, measure_univ, mul_one], },\nend\n\nlemma indep_bot_left (m' : measurable_space \u03a9) {m : measurable_space \u03a9}\n  {\u03bc : measure \u03a9} [is_probability_measure \u03bc] :\n  indep \u22a5 m' \u03bc :=\n(indep_bot_right m').symm\n\nlemma indep_set_empty_right {m : measurable_space \u03a9} {\u03bc : measure \u03a9} [is_probability_measure \u03bc]\n  (s : set \u03a9) :\n  indep_set s \u2205 \u03bc :=\nby { simp only [indep_set, generate_from_singleton_empty], exact indep_bot_right _, }\n\nlemma indep_set_empty_left {m : measurable_space \u03a9} {\u03bc : measure \u03a9} [is_probability_measure \u03bc]\n  (s : set \u03a9) :\n  indep_set \u2205 s \u03bc :=\n(indep_set_empty_right s).symm\n\nlemma indep_sets_of_indep_sets_of_le_left {s\u2081 s\u2082 s\u2083: set (set \u03a9)} [measurable_space \u03a9]\n  {\u03bc : measure \u03a9} (h_indep : indep_sets s\u2081 s\u2082 \u03bc) (h31 : s\u2083 \u2286 s\u2081) :\n  indep_sets s\u2083 s\u2082 \u03bc :=\n\u03bb t1 t2 ht1 ht2, h_indep t1 t2 (set.mem_of_subset_of_mem h31 ht1) ht2\n\nlemma indep_sets_of_indep_sets_of_le_right {s\u2081 s\u2082 s\u2083: set (set \u03a9)} [measurable_space \u03a9]\n  {\u03bc : measure \u03a9} (h_indep : indep_sets s\u2081 s\u2082 \u03bc) (h32 : s\u2083 \u2286 s\u2082) :\n  indep_sets s\u2081 s\u2083 \u03bc :=\n\u03bb t1 t2 ht1 ht2, h_indep t1 t2 ht1 (set.mem_of_subset_of_mem h32 ht2)\n\nlemma indep_of_indep_of_le_left {m\u2081 m\u2082 m\u2083: measurable_space \u03a9} [measurable_space \u03a9]\n  {\u03bc : measure \u03a9} (h_indep : indep m\u2081 m\u2082 \u03bc) (h31 : m\u2083 \u2264 m\u2081) :\n  indep m\u2083 m\u2082 \u03bc :=\n\u03bb t1 t2 ht1 ht2, h_indep t1 t2 (h31 _ ht1) ht2\n\nlemma indep_of_indep_of_le_right {m\u2081 m\u2082 m\u2083: measurable_space \u03a9} [measurable_space \u03a9]\n  {\u03bc : measure \u03a9} (h_indep : indep m\u2081 m\u2082 \u03bc) (h32 : m\u2083 \u2264 m\u2082) :\n  indep m\u2081 m\u2083 \u03bc :=\n\u03bb t1 t2 ht1 ht2, h_indep t1 t2 ht1 (h32 _ ht2)\n\nlemma indep_sets.union [measurable_space \u03a9] {s\u2081 s\u2082 s' : set (set \u03a9)} {\u03bc : measure \u03a9}\n  (h\u2081 : indep_sets s\u2081 s' \u03bc) (h\u2082 : indep_sets s\u2082 s' \u03bc) :\n  indep_sets (s\u2081 \u222a s\u2082) s' \u03bc :=\nbegin\n  intros t1 t2 ht1 ht2,\n  cases (set.mem_union _ _ _).mp ht1 with ht1\u2081 ht1\u2082,\n  { exact h\u2081 t1 t2 ht1\u2081 ht2, },\n  { exact h\u2082 t1 t2 ht1\u2082 ht2, },\nend\n\n@[simp] lemma indep_sets.union_iff [measurable_space \u03a9] {s\u2081 s\u2082 s' : set (set \u03a9)}\n  {\u03bc : measure \u03a9} :\n  indep_sets (s\u2081 \u222a s\u2082) s' \u03bc \u2194 indep_sets s\u2081 s' \u03bc \u2227 indep_sets s\u2082 s' \u03bc :=\n\u27e8\u03bb h, \u27e8indep_sets_of_indep_sets_of_le_left h (set.subset_union_left s\u2081 s\u2082),\n    indep_sets_of_indep_sets_of_le_left h (set.subset_union_right s\u2081 s\u2082)\u27e9,\n  \u03bb h, indep_sets.union h.left h.right\u27e9\n\nlemma indep_sets.Union [measurable_space \u03a9] {s : \u03b9 \u2192 set (set \u03a9)} {s' : set (set \u03a9)}\n  {\u03bc : measure \u03a9} (hyp : \u2200 n, indep_sets (s n) s' \u03bc) :\n  indep_sets (\u22c3 n, s n) s' \u03bc :=\nbegin\n  intros t1 t2 ht1 ht2,\n  rw set.mem_Union at ht1,\n  cases ht1 with n ht1,\n  exact hyp n t1 t2 ht1 ht2,\nend\n\nlemma indep_sets.bUnion [measurable_space \u03a9] {s : \u03b9 \u2192 set (set \u03a9)} {s' : set (set \u03a9)}\n  {\u03bc : measure \u03a9} {u : set \u03b9} (hyp : \u2200 n \u2208 u, indep_sets (s n) s' \u03bc) :\n  indep_sets (\u22c3 n \u2208 u, s n) s' \u03bc :=\nbegin\n  intros t1 t2 ht1 ht2,\n  simp_rw set.mem_Union at ht1,\n  rcases ht1 with \u27e8n, hpn, ht1\u27e9,\n  exact hyp n hpn t1 t2 ht1 ht2,\nend\n\nlemma indep_sets.inter [measurable_space \u03a9] {s\u2081 s' : set (set \u03a9)} (s\u2082 : set (set \u03a9))\n  {\u03bc : measure \u03a9} (h\u2081 : indep_sets s\u2081 s' \u03bc) :\n  indep_sets (s\u2081 \u2229 s\u2082) s' \u03bc :=\n\u03bb t1 t2 ht1 ht2, h\u2081 t1 t2 ((set.mem_inter_iff _ _ _).mp ht1).left ht2\n\nlemma indep_sets.Inter [measurable_space \u03a9] {s : \u03b9 \u2192 set (set \u03a9)} {s' : set (set \u03a9)}\n  {\u03bc : measure \u03a9} (h : \u2203 n, indep_sets (s n) s' \u03bc) :\n  indep_sets (\u22c2 n, s n) s' \u03bc :=\nby {intros t1 t2 ht1 ht2, cases h with n h, exact h t1 t2 (set.mem_Inter.mp ht1 n) ht2 }\n\nlemma indep_sets.bInter [measurable_space \u03a9] {s : \u03b9 \u2192 set (set \u03a9)} {s' : set (set \u03a9)}\n  {\u03bc : measure \u03a9} {u : set \u03b9} (h : \u2203 n \u2208 u, indep_sets (s n) s' \u03bc) :\n  indep_sets (\u22c2 n \u2208 u, s n) s' \u03bc :=\nbegin\n  intros t1 t2 ht1 ht2,\n  rcases h with \u27e8n, hn, h\u27e9,\n  exact h t1 t2 (set.bInter_subset_of_mem hn ht1) ht2,\nend\n\nlemma indep_sets_singleton_iff [measurable_space \u03a9] {s t : set \u03a9} {\u03bc : measure \u03a9} :\n  indep_sets {s} {t} \u03bc \u2194 \u03bc (s \u2229 t) = \u03bc s * \u03bc t :=\n\u27e8\u03bb h, h s t rfl rfl,\n  \u03bb h s1 t1 hs1 ht1, by rwa [set.mem_singleton_iff.mp hs1, set.mem_singleton_iff.mp ht1]\u27e9\n\nend indep\n\n/-! ### Deducing `indep` from `Indep` -/\nsection from_Indep_to_indep\n\nlemma Indep_sets.indep_sets {s : \u03b9 \u2192 set (set \u03a9)} [measurable_space \u03a9] {\u03bc : measure \u03a9}\n  (h_indep : Indep_sets s \u03bc) {i j : \u03b9} (hij : i \u2260 j) :\n  indep_sets (s i) (s j) \u03bc :=\nbegin\n  classical,\n  intros t\u2081 t\u2082 ht\u2081 ht\u2082,\n  have hf_m : \u2200 (x : \u03b9), x \u2208 {i, j} \u2192 (ite (x=i) t\u2081 t\u2082) \u2208 s x,\n  { intros x hx,\n    cases finset.mem_insert.mp hx with hx hx,\n    { simp [hx, ht\u2081], },\n    { simp [finset.mem_singleton.mp hx, hij.symm, ht\u2082], }, },\n  have h1 : t\u2081 = ite (i = i) t\u2081 t\u2082, by simp only [if_true, eq_self_iff_true],\n  have h2 : t\u2082 = ite (j = i) t\u2081 t\u2082, by simp only [hij.symm, if_false],\n  have h_inter : (\u22c2 (t : \u03b9) (H : t \u2208 ({i, j} : finset \u03b9)), ite (t = i) t\u2081 t\u2082)\n      = (ite (i = i) t\u2081 t\u2082) \u2229 (ite (j = i) t\u2081 t\u2082),\n    by simp only [finset.set_bInter_singleton, finset.set_bInter_insert],\n  have h_prod : (\u220f (t : \u03b9) in ({i, j} : finset \u03b9), \u03bc (ite (t = i) t\u2081 t\u2082))\n      = \u03bc (ite (i = i) t\u2081 t\u2082) * \u03bc (ite (j = i) t\u2081 t\u2082),\n    by simp only [hij, finset.prod_singleton, finset.prod_insert, not_false_iff,\n      finset.mem_singleton],\n  rw h1,\n  nth_rewrite 1 h2,\n  nth_rewrite 3 h2,\n  rw [\u2190 h_inter, \u2190 h_prod, h_indep {i, j} hf_m],\nend\n\nlemma Indep.indep {m : \u03b9 \u2192 measurable_space \u03a9} [measurable_space \u03a9] {\u03bc : measure \u03a9}\n  (h_indep : Indep m \u03bc) {i j : \u03b9} (hij : i \u2260 j) :\n  indep (m i) (m j) \u03bc :=\nbegin\n  change indep_sets ((\u03bb x, measurable_set[m x]) i) ((\u03bb x, measurable_set[m x]) j) \u03bc,\n  exact Indep_sets.indep_sets h_indep hij,\nend\n\nlemma Indep_fun.indep_fun {m\u2080 : measurable_space \u03a9} {\u03bc : measure \u03a9} {\u03b2 : \u03b9 \u2192 Type*}\n  {m : \u03a0 x, measurable_space (\u03b2 x)} {f : \u03a0 i, \u03a9 \u2192 \u03b2 i} (hf_Indep : Indep_fun m f \u03bc)\n  {i j : \u03b9} (hij : i \u2260 j) :\n  indep_fun (f i) (f j) \u03bc :=\nhf_Indep.indep hij\n\nend from_Indep_to_indep\n\n/-!\n## \u03c0-system lemma\n\nIndependence of measurable spaces is equivalent to independence of generating \u03c0-systems.\n-/\n\nsection from_measurable_spaces_to_sets_of_sets\n/-! ### Independence of measurable space structures implies independence of generating \u03c0-systems -/\n\nlemma Indep.Indep_sets [measurable_space \u03a9] {\u03bc : measure \u03a9} {m : \u03b9 \u2192 measurable_space \u03a9}\n  {s : \u03b9 \u2192 set (set \u03a9)} (hms : \u2200 n, m n = generate_from (s n))\n  (h_indep : Indep m \u03bc) :\n  Indep_sets s \u03bc :=\n\u03bb S f hfs, h_indep S $ \u03bb x hxS,\n  ((hms x).symm \u25b8 measurable_set_generate_from (hfs x hxS) : measurable_set[m x] (f x))\n\nlemma indep.indep_sets [measurable_space \u03a9] {\u03bc : measure \u03a9} {s1 s2 : set (set \u03a9)}\n  (h_indep : indep (generate_from s1) (generate_from s2) \u03bc) :\n  indep_sets s1 s2 \u03bc :=\n\u03bb t1 t2 ht1 ht2, h_indep t1 t2 (measurable_set_generate_from ht1) (measurable_set_generate_from ht2)\n\nend from_measurable_spaces_to_sets_of_sets\n\nsection from_pi_systems_to_measurable_spaces\n/-! ### Independence of generating \u03c0-systems implies independence of measurable space structures -/\n\nprivate lemma indep_sets.indep_aux {m2 : measurable_space \u03a9}\n  {m : measurable_space \u03a9} {\u03bc : measure \u03a9} [is_probability_measure \u03bc] {p1 p2 : set (set \u03a9)}\n  (h2 : m2 \u2264 m) (hp2 : is_pi_system p2) (hpm2 : m2 = generate_from p2)\n  (hyp : indep_sets p1 p2 \u03bc) {t1 t2 : set \u03a9} (ht1 : t1 \u2208 p1) (ht2m : measurable_set[m2] t2) :\n  \u03bc (t1 \u2229 t2) = \u03bc t1 * \u03bc t2 :=\nbegin\n  let \u03bc_inter := \u03bc.restrict t1,\n  let \u03bd := (\u03bc t1) \u2022 \u03bc,\n  have h_univ : \u03bc_inter set.univ = \u03bd set.univ,\n  by rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one],\n  haveI : is_finite_measure \u03bc_inter := @restrict.is_finite_measure \u03a9 _ t1 \u03bc \u27e8measure_lt_top \u03bc t1\u27e9,\n  rw [set.inter_comm, \u2190 measure.restrict_apply (h2 t2 ht2m)],\n  refine ext_on_measurable_space_of_generate_finite m p2 (\u03bb t ht, _) h2 hpm2 hp2 h_univ ht2m,\n  have ht2 : measurable_set[m] t,\n  { refine h2 _ _,\n    rw hpm2,\n    exact measurable_set_generate_from ht, },\n  rw [measure.restrict_apply ht2, measure.smul_apply, set.inter_comm],\n  exact hyp t1 t ht1 ht,\nend\n\nlemma indep_sets.indep {m1 m2 : measurable_space \u03a9} {m : measurable_space \u03a9}\n  {\u03bc : measure \u03a9} [is_probability_measure \u03bc] {p1 p2 : set (set \u03a9)} (h1 : m1 \u2264 m) (h2 : m2 \u2264 m)\n  (hp1 : is_pi_system p1) (hp2 : is_pi_system p2) (hpm1 : m1 = generate_from p1)\n  (hpm2 : m2 = generate_from p2) (hyp : indep_sets p1 p2 \u03bc) :\n  indep m1 m2 \u03bc :=\nbegin\n  intros t1 t2 ht1 ht2,\n  let \u03bc_inter := \u03bc.restrict t2,\n  let \u03bd := (\u03bc t2) \u2022 \u03bc,\n  have h_univ : \u03bc_inter set.univ = \u03bd set.univ,\n  by rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one],\n  haveI : is_finite_measure \u03bc_inter := @restrict.is_finite_measure \u03a9 _ t2 \u03bc \u27e8measure_lt_top \u03bc t2\u27e9,\n  rw [mul_comm, \u2190 measure.restrict_apply (h1 t1 ht1)],\n  refine ext_on_measurable_space_of_generate_finite m p1 (\u03bb t ht, _) h1 hpm1 hp1 h_univ ht1,\n  have ht1 : measurable_set[m] t,\n  { refine h1 _ _,\n    rw hpm1,\n    exact measurable_set_generate_from ht, },\n  rw [measure.restrict_apply ht1, measure.smul_apply, smul_eq_mul, mul_comm],\n  exact indep_sets.indep_aux h2 hp2 hpm2 hyp ht ht2,\nend\n\nlemma indep_sets.indep' {m : measurable_space \u03a9}\n  {\u03bc : measure \u03a9} [is_probability_measure \u03bc] {p1 p2 : set (set \u03a9)}\n  (hp1m : \u2200 s \u2208 p1, measurable_set s) (hp2m : \u2200 s \u2208 p2, measurable_set s)\n  (hp1 : is_pi_system p1) (hp2 : is_pi_system p2) (hyp : indep_sets p1 p2 \u03bc) :\n  indep (generate_from p1) (generate_from p2) \u03bc :=\nhyp.indep (generate_from_le hp1m) (generate_from_le hp2m) hp1 hp2 rfl rfl\n\nvariables {m0 : measurable_space \u03a9} {\u03bc : measure \u03a9}\n\nlemma indep_sets_pi_Union_Inter_of_disjoint [is_probability_measure \u03bc]\n  {s : \u03b9 \u2192 set (set \u03a9)} {S T : set \u03b9}\n  (h_indep : Indep_sets s \u03bc) (hST : disjoint S T) :\n  indep_sets (pi_Union_Inter s S) (pi_Union_Inter s T) \u03bc :=\nbegin\n  rintros t1 t2 \u27e8p1, hp1, f1, ht1_m, ht1_eq\u27e9 \u27e8p2, hp2, f2, ht2_m, ht2_eq\u27e9,\n  classical,\n  let g := \u03bb i, ite (i \u2208 p1) (f1 i) set.univ \u2229 ite (i \u2208 p2) (f2 i) set.univ,\n  have h_P_inter : \u03bc (t1 \u2229 t2) = \u220f n in p1 \u222a p2, \u03bc (g n),\n  { have hgm : \u2200 i \u2208 p1 \u222a p2, g i \u2208 s i,\n    { intros i hi_mem_union,\n      rw finset.mem_union at hi_mem_union,\n      cases hi_mem_union with hi1 hi2,\n      { have hi2 : i \u2209 p2 := \u03bb hip2, set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2),\n        simp_rw [g, if_pos hi1, if_neg hi2, set.inter_univ],\n        exact ht1_m i hi1, },\n      { have hi1 : i \u2209 p1 := \u03bb hip1, set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1),\n        simp_rw [g, if_neg hi1, if_pos hi2, set.univ_inter],\n        exact ht2_m i hi2, }, },\n    have h_p1_inter_p2 : ((\u22c2 x \u2208 p1, f1 x) \u2229 \u22c2 x \u2208 p2, f2 x)\n      = \u22c2 i \u2208 p1 \u222a p2, (ite (i \u2208 p1) (f1 i) set.univ \u2229 ite (i \u2208 p2) (f2 i) set.univ),\n    { ext1 x,\n      simp only [set.mem_ite_univ_right, set.mem_inter_iff, set.mem_Inter, finset.mem_union],\n      exact \u27e8\u03bb h i _, \u27e8h.1 i, h.2 i\u27e9,\n        \u03bb h, \u27e8\u03bb i hi, (h i (or.inl hi)).1 hi, \u03bb i hi, (h i (or.inr hi)).2 hi\u27e9\u27e9, },\n    rw [ht1_eq, ht2_eq, h_p1_inter_p2, \u2190 h_indep _ hgm], },\n  have h_\u03bcg : \u2200 n, \u03bc (g n) = (ite (n \u2208 p1) (\u03bc (f1 n)) 1) * (ite (n \u2208 p2) (\u03bc (f2 n)) 1),\n  { intro n,\n    simp_rw g,\n    split_ifs,\n    { exact absurd rfl (set.disjoint_iff_forall_ne.mp hST _ (hp1 h) _ (hp2 h_1)), },\n    all_goals { simp only [measure_univ, one_mul, mul_one, set.inter_univ, set.univ_inter], }, },\n  simp_rw [h_P_inter, h_\u03bcg, finset.prod_mul_distrib,\n    finset.prod_ite_mem (p1 \u222a p2) p1 (\u03bb x, \u03bc (f1 x)),\n    finset.union_inter_cancel_left, finset.prod_ite_mem (p1 \u222a p2) p2 (\u03bb x, \u03bc (f2 x)),\n    finset.union_inter_cancel_right, ht1_eq, \u2190 h_indep p1 ht1_m, ht2_eq, \u2190 h_indep p2 ht2_m],\nend\n\nlemma Indep_set.indep_generate_from_of_disjoint [is_probability_measure \u03bc] {s : \u03b9 \u2192 set \u03a9}\n  (hsm : \u2200 n, measurable_set (s n)) (hs : Indep_set s \u03bc) (S T : set \u03b9) (hST : disjoint S T) :\n  indep (generate_from {t | \u2203 n \u2208 S, s n = t}) (generate_from {t | \u2203 k \u2208 T, s k = t}) \u03bc :=\nbegin\n  rw [\u2190 generate_from_pi_Union_Inter_singleton_left,\n    \u2190 generate_from_pi_Union_Inter_singleton_left],\n  refine indep_sets.indep'\n    (\u03bb t ht, generate_from_pi_Union_Inter_le _ _ _ _ (measurable_set_generate_from ht))\n    (\u03bb t ht, generate_from_pi_Union_Inter_le _ _ _ _ (measurable_set_generate_from ht))\n    _ _ _,\n  { exact \u03bb k, generate_from_le $ \u03bb t ht, (set.mem_singleton_iff.1 ht).symm \u25b8 hsm k, },\n  { exact \u03bb k, generate_from_le $ \u03bb t ht, (set.mem_singleton_iff.1 ht).symm \u25b8 hsm k, },\n  { exact is_pi_system_pi_Union_Inter _ (\u03bb k, is_pi_system.singleton _) _, },\n  { exact is_pi_system_pi_Union_Inter _ (\u03bb k, is_pi_system.singleton _) _, },\n  { classical,\n    exact indep_sets_pi_Union_Inter_of_disjoint (Indep.Indep_sets (\u03bb n, rfl) hs) hST, },\nend\n\nlemma indep_supr_of_disjoint [is_probability_measure \u03bc] {m : \u03b9 \u2192 measurable_space \u03a9}\n  (h_le : \u2200 i, m i \u2264 m0) (h_indep : Indep m \u03bc) {S T : set \u03b9} (hST : disjoint S T) :\n  indep (\u2a06 i \u2208 S, m i) (\u2a06 i \u2208 T, m i) \u03bc :=\nbegin\n  refine indep_sets.indep (supr\u2082_le (\u03bb i _, h_le i)) (supr\u2082_le (\u03bb i _, h_le i)) _ _\n    (generate_from_pi_Union_Inter_measurable_set m S).symm\n    (generate_from_pi_Union_Inter_measurable_set m T).symm _,\n  { exact is_pi_system_pi_Union_Inter _ (\u03bb n, @is_pi_system_measurable_set \u03a9 (m n)) _, },\n  { exact is_pi_system_pi_Union_Inter _ (\u03bb n, @is_pi_system_measurable_set \u03a9 (m n)) _ , },\n  { classical,\n    exact indep_sets_pi_Union_Inter_of_disjoint h_indep hST, },\nend\n\nlemma indep_supr_of_directed_le {\u03a9} {m : \u03b9 \u2192 measurable_space \u03a9}\n  {m' m0 : measurable_space \u03a9} {\u03bc : measure \u03a9} [is_probability_measure \u03bc]\n  (h_indep : \u2200 i, indep (m i) m' \u03bc) (h_le : \u2200 i, m i \u2264 m0) (h_le' : m' \u2264 m0)\n  (hm : directed (\u2264) m) :\n  indep (\u2a06 i, m i) m' \u03bc :=\nbegin\n  let p : \u03b9 \u2192 set (set \u03a9) := \u03bb n, {t | measurable_set[m n] t},\n  have hp : \u2200 n, is_pi_system (p n) := \u03bb n, @is_pi_system_measurable_set \u03a9 (m n),\n  have h_gen_n : \u2200 n, m n = generate_from (p n),\n    from \u03bb n, (@generate_from_measurable_set \u03a9 (m n)).symm,\n  have hp_supr_pi : is_pi_system (\u22c3 n, p n) := is_pi_system_Union_of_directed_le p hp hm,\n  let p' := {t : set \u03a9 | measurable_set[m'] t},\n  have hp'_pi : is_pi_system p' := @is_pi_system_measurable_set \u03a9 m',\n  have h_gen' : m' = generate_from p' := (@generate_from_measurable_set \u03a9 m').symm,\n  -- the \u03c0-systems defined are independent\n  have h_pi_system_indep : indep_sets (\u22c3 n, p n) p' \u03bc,\n  { refine indep_sets.Union _,\n    simp_rw [h_gen_n, h_gen'] at h_indep,\n    exact \u03bb n, (h_indep n).indep_sets, },\n  -- now go from \u03c0-systems to \u03c3-algebras\n  refine indep_sets.indep (supr_le h_le) h_le' hp_supr_pi hp'_pi _ h_gen' h_pi_system_indep,\n  exact (generate_from_Union_measurable_set _).symm,\nend\n\nlemma Indep_set.indep_generate_from_lt [preorder \u03b9] [is_probability_measure \u03bc]\n  {s : \u03b9 \u2192 set \u03a9} (hsm : \u2200 n, measurable_set (s n)) (hs : Indep_set s \u03bc) (i : \u03b9) :\n  indep (generate_from {s i}) (generate_from {t | \u2203 j < i, s j = t}) \u03bc :=\nbegin\n  convert hs.indep_generate_from_of_disjoint hsm {i} {j | j < i}\n    (set.disjoint_singleton_left.mpr (lt_irrefl _)),\n  simp only [set.mem_singleton_iff, exists_prop, exists_eq_left, set.set_of_eq_eq_singleton'],\nend\n\nlemma Indep_set.indep_generate_from_le [linear_order \u03b9] [is_probability_measure \u03bc]\n  {s : \u03b9 \u2192 set \u03a9} (hsm : \u2200 n, measurable_set (s n)) (hs : Indep_set s \u03bc)\n  (i : \u03b9) {k : \u03b9} (hk : i < k) :\n  indep (generate_from {s k}) (generate_from {t | \u2203 j \u2264 i, s j = t}) \u03bc :=\nbegin\n  convert hs.indep_generate_from_of_disjoint hsm {k} {j | j \u2264 i}\n    (set.disjoint_singleton_left.mpr hk.not_le),\n  simp only [set.mem_singleton_iff, exists_prop, exists_eq_left, set.set_of_eq_eq_singleton'],\nend\n\nlemma Indep_set.indep_generate_from_le_nat [is_probability_measure \u03bc]\n  {s : \u2115 \u2192 set \u03a9} (hsm : \u2200 n, measurable_set (s n)) (hs : Indep_set s \u03bc) (n : \u2115):\n  indep (generate_from {s (n + 1)}) (generate_from {t | \u2203 k \u2264 n, s k = t}) \u03bc :=\nhs.indep_generate_from_le hsm _ n.lt_succ_self\n\nlemma indep_supr_of_monotone [semilattice_sup \u03b9] {\u03a9} {m : \u03b9 \u2192 measurable_space \u03a9}\n  {m' m0 : measurable_space \u03a9} {\u03bc : measure \u03a9} [is_probability_measure \u03bc]\n  (h_indep : \u2200 i, indep (m i) m' \u03bc) (h_le : \u2200 i, m i \u2264 m0) (h_le' : m' \u2264 m0) (hm : monotone m) :\n  indep (\u2a06 i, m i) m' \u03bc :=\nindep_supr_of_directed_le h_indep h_le h_le' (monotone.directed_le hm)\n\nlemma indep_supr_of_antitone [semilattice_inf \u03b9] {\u03a9} {m : \u03b9 \u2192 measurable_space \u03a9}\n  {m' m0 : measurable_space \u03a9} {\u03bc : measure \u03a9} [is_probability_measure \u03bc]\n  (h_indep : \u2200 i, indep (m i) m' \u03bc) (h_le : \u2200 i, m i \u2264 m0) (h_le' : m' \u2264 m0) (hm : antitone m) :\n  indep (\u2a06 i, m i) m' \u03bc :=\nindep_supr_of_directed_le h_indep h_le h_le' (directed_of_inf hm)\n\nlemma Indep_sets.pi_Union_Inter_of_not_mem {\u03c0 : \u03b9 \u2192 set (set \u03a9)} {a : \u03b9} {S : finset \u03b9}\n  (hp_ind : Indep_sets \u03c0 \u03bc) (haS : a \u2209 S) :\n  indep_sets (pi_Union_Inter \u03c0 S) (\u03c0 a) \u03bc :=\nbegin\n  rintros t1 t2 \u27e8s, hs_mem, ft1, hft1_mem, ht1_eq\u27e9 ht2_mem_pia,\n  rw [finset.coe_subset] at hs_mem,\n  classical,\n  let f := \u03bb n, ite (n = a) t2 (ite (n \u2208 s) (ft1 n) set.univ),\n  have h_f_mem : \u2200 n \u2208 insert a s, f n \u2208 \u03c0 n,\n  { intros n hn_mem_insert,\n    simp_rw f,\n    cases (finset.mem_insert.mp hn_mem_insert) with hn_mem hn_mem,\n    { simp [hn_mem, ht2_mem_pia], },\n    { have hn_ne_a : n \u2260 a, by { rintro rfl, exact haS (hs_mem hn_mem), },\n      simp [hn_ne_a, hn_mem, hft1_mem n hn_mem], }, },\n  have h_f_mem_pi : \u2200 n \u2208 s, f n \u2208 \u03c0 n, from \u03bb x hxS, h_f_mem x (by simp [hxS]),\n  have h_t1 : t1 = \u22c2 n \u2208 s, f n,\n  { suffices h_forall : \u2200 n \u2208 s, f n = ft1 n,\n    { rw ht1_eq,\n      congr' with n x,\n      congr' with hns y,\n      simp only [(h_forall n hns).symm], },\n    intros n hnS,\n    have hn_ne_a : n \u2260 a, by { rintro rfl, exact haS (hs_mem hnS), },\n    simp_rw [f, if_pos hnS, if_neg hn_ne_a], },\n  have h_\u03bc_t1 : \u03bc t1 = \u220f n in s, \u03bc (f n), by rw [h_t1, \u2190 hp_ind s h_f_mem_pi],\n  have h_t2 : t2 = f a, by { simp_rw [f], simp, },\n  have h_\u03bc_inter : \u03bc (t1 \u2229 t2) = \u220f n in insert a s, \u03bc (f n),\n  { have h_t1_inter_t2 : t1 \u2229 t2 = \u22c2 n \u2208 insert a s, f n,\n      by rw [h_t1, h_t2, finset.set_bInter_insert, set.inter_comm],\n    rw [h_t1_inter_t2, \u2190 hp_ind (insert a s) h_f_mem], },\n  have has : a \u2209 s := \u03bb has_mem, haS (hs_mem has_mem),\n  rw [h_\u03bc_inter, finset.prod_insert has, h_t2, mul_comm, h_\u03bc_t1],\nend\n\n/-- The measurable space structures generated by independent pi-systems are independent. -/\ntheorem Indep_sets.Indep [is_probability_measure \u03bc] (m : \u03b9 \u2192 measurable_space \u03a9)\n  (h_le : \u2200 i, m i \u2264 m0) (\u03c0 : \u03b9 \u2192 set (set \u03a9)) (h_pi : \u2200 n, is_pi_system (\u03c0 n))\n  (h_generate : \u2200 i, m i = generate_from (\u03c0 i)) (h_ind : Indep_sets \u03c0 \u03bc) :\n  Indep m \u03bc :=\nbegin\n  classical,\n  refine finset.induction _ _,\n  { simp only [measure_univ, implies_true_iff, set.Inter_false, set.Inter_univ, finset.prod_empty,\n      eq_self_iff_true], },\n  intros a S ha_notin_S h_rec f hf_m,\n  have hf_m_S : \u2200 x \u2208 S, measurable_set[m x] (f x) := \u03bb x hx, hf_m x (by simp [hx]),\n  rw [finset.set_bInter_insert, finset.prod_insert ha_notin_S, \u2190 h_rec hf_m_S],\n  let p := pi_Union_Inter \u03c0 S,\n  set m_p := generate_from p with hS_eq_generate,\n  have h_indep : indep m_p (m a) \u03bc,\n  { have hp : is_pi_system p := is_pi_system_pi_Union_Inter \u03c0 h_pi S,\n    have h_le' : \u2200 i, generate_from (\u03c0 i) \u2264 m0 := \u03bb i, (h_generate i).symm.trans_le (h_le i),\n    have hm_p : m_p \u2264 m0 := generate_from_pi_Union_Inter_le \u03c0 h_le' S,\n    exact indep_sets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a)\n      (h_ind.pi_Union_Inter_of_not_mem ha_notin_S), },\n  refine h_indep.symm (f a) (\u22c2 n \u2208 S, f n) (hf_m a (finset.mem_insert_self a S)) _,\n  have h_le_p : \u2200 i \u2208 S, m i \u2264 m_p,\n  { intros n hn,\n    rw [hS_eq_generate, h_generate n],\n    exact le_generate_from_pi_Union_Inter S hn, },\n  have h_S_f : \u2200 i \u2208 S, measurable_set[m_p] (f i) := \u03bb i hi, (h_le_p i hi) (f i) (hf_m_S i hi),\n  exact S.measurable_set_bInter h_S_f,\nend\n\nend from_pi_systems_to_measurable_spaces\n\nsection indep_set\n/-! ### Independence of measurable sets\n\nWe prove the following equivalences on `indep_set`, for measurable sets `s, t`.\n* `indep_set s t \u03bc \u2194 \u03bc (s \u2229 t) = \u03bc s * \u03bc t`,\n* `indep_set s t \u03bc \u2194 indep_sets {s} {t} \u03bc`.\n-/\n\nvariables {s t : set \u03a9} (S T : set (set \u03a9))\n\nlemma indep_set_iff_indep_sets_singleton {m0 : measurable_space \u03a9}\n  (hs_meas : measurable_set s) (ht_meas : measurable_set t)\n  (\u03bc : measure \u03a9 . volume_tac) [is_probability_measure \u03bc] :\n  indep_set s t \u03bc \u2194 indep_sets {s} {t} \u03bc :=\n\u27e8indep.indep_sets, \u03bb h, indep_sets.indep\n  (generate_from_le (\u03bb u hu, by rwa set.mem_singleton_iff.mp hu))\n  (generate_from_le (\u03bb u hu, by rwa set.mem_singleton_iff.mp hu)) (is_pi_system.singleton s)\n  (is_pi_system.singleton t) rfl rfl h\u27e9\n\nlemma indep_set_iff_measure_inter_eq_mul {m0 : measurable_space \u03a9}\n  (hs_meas : measurable_set s) (ht_meas : measurable_set t)\n  (\u03bc : measure \u03a9 . volume_tac) [is_probability_measure \u03bc] :\n  indep_set s t \u03bc \u2194 \u03bc (s \u2229 t) = \u03bc s * \u03bc t :=\n(indep_set_iff_indep_sets_singleton hs_meas ht_meas \u03bc).trans indep_sets_singleton_iff\n\nlemma indep_sets.indep_set_of_mem {m0 : measurable_space \u03a9} (hs : s \u2208 S) (ht : t \u2208 T)\n  (hs_meas : measurable_set s) (ht_meas : measurable_set t) (\u03bc : measure \u03a9 . volume_tac)\n  [is_probability_measure \u03bc] (h_indep : indep_sets S T \u03bc) :\n  indep_set s t \u03bc :=\n(indep_set_iff_measure_inter_eq_mul hs_meas ht_meas \u03bc).mpr (h_indep s t hs ht)\n\nlemma indep.indep_set_of_measurable_set {m\u2081 m\u2082 m0 : measurable_space \u03a9} {\u03bc : measure \u03a9}\n  (h_indep : indep m\u2081 m\u2082 \u03bc) {s t : set \u03a9} (hs : measurable_set[m\u2081] s) (ht : measurable_set[m\u2082] t) :\n  indep_set s t \u03bc :=\nbegin\n  refine \u03bb s' t' hs' ht', h_indep s' t' _ _,\n  { refine generate_from_induction (\u03bb u, measurable_set[m\u2081] u) {s} _ _ _ _ hs',\n    { simp only [hs, set.mem_singleton_iff, set.mem_set_of_eq, forall_eq], },\n    { exact @measurable_set.empty _ m\u2081, },\n    { exact \u03bb u hu, hu.compl, },\n    { exact \u03bb f hf, measurable_set.Union hf, }, },\n  { refine generate_from_induction (\u03bb u, measurable_set[m\u2082] u) {t} _ _ _ _ ht',\n    { simp only [ht, set.mem_singleton_iff, set.mem_set_of_eq, forall_eq], },\n    { exact @measurable_set.empty _ m\u2082, },\n    { exact \u03bb u hu, hu.compl, },\n    { exact \u03bb f hf, measurable_set.Union hf, },},\nend\n\nlemma indep_iff_forall_indep_set (m\u2081 m\u2082 : measurable_space \u03a9) {m0 : measurable_space \u03a9}\n  (\u03bc : measure \u03a9) :\n  indep m\u2081 m\u2082 \u03bc \u2194 \u2200 s t, measurable_set[m\u2081] s \u2192 measurable_set[m\u2082] t \u2192 indep_set s t \u03bc :=\n\u27e8\u03bb h, \u03bb s t hs ht, h.indep_set_of_measurable_set hs ht,\n  \u03bb h s t hs ht, h s t hs ht s t (measurable_set_generate_from (set.mem_singleton s))\n    (measurable_set_generate_from (set.mem_singleton t))\u27e9\n\nend indep_set\n\nsection indep_fun\n\n/-! ### Independence of random variables\n\n-/\n\nvariables {\u03b2 \u03b2' \u03b3 \u03b3' : Type*} {m\u03a9 : measurable_space \u03a9} {\u03bc : measure \u03a9} {f : \u03a9 \u2192 \u03b2} {g : \u03a9 \u2192 \u03b2'}\n\nlemma indep_fun_iff_measure_inter_preimage_eq_mul\n  {m\u03b2 : measurable_space \u03b2} {m\u03b2' : measurable_space \u03b2'} :\n  indep_fun f g \u03bc\n    \u2194 \u2200 s t, measurable_set s \u2192 measurable_set t\n      \u2192 \u03bc (f \u207b\u00b9' s \u2229 g \u207b\u00b9' t) = \u03bc (f \u207b\u00b9' s) * \u03bc (g \u207b\u00b9' t) :=\nbegin\n  split; intro h,\n  { refine \u03bb s t hs ht, h (f \u207b\u00b9' s) (g \u207b\u00b9' t) \u27e8s, hs, rfl\u27e9 \u27e8t, ht, rfl\u27e9, },\n  { rintros _ _ \u27e8s, hs, rfl\u27e9 \u27e8t, ht, rfl\u27e9, exact h s t hs ht, },\nend\n\nlemma Indep_fun_iff_measure_inter_preimage_eq_mul {\u03b9 : Type*} {\u03b2 : \u03b9 \u2192 Type*}\n  (m : \u03a0 x, measurable_space (\u03b2 x)) (f : \u03a0 i, \u03a9 \u2192 \u03b2 i) :\n  Indep_fun m f \u03bc\n    \u2194 \u2200 (S : finset \u03b9) {sets : \u03a0 i : \u03b9, set (\u03b2 i)} (H : \u2200 i, i \u2208 S \u2192 measurable_set[m i] (sets i)),\n      \u03bc (\u22c2 i \u2208 S, (f i) \u207b\u00b9' (sets i)) = \u220f i in S, \u03bc ((f i) \u207b\u00b9' (sets i)) :=\nbegin\n  refine \u27e8\u03bb h S sets h_meas, h _ (\u03bb i hi_mem, \u27e8sets i, h_meas i hi_mem, rfl\u27e9), _\u27e9,\n  intros h S sets\u03a9 h_meas,\n  classical,\n  let sets\u03b2 : (\u03a0 i : \u03b9, set (\u03b2 i)) := \u03bb i,\n    dite (i \u2208 S) (\u03bb hi_mem, (h_meas i hi_mem).some) (\u03bb _, set.univ),\n  have h_meas\u03b2 : \u2200 i \u2208 S, measurable_set[m i] (sets\u03b2 i),\n  { intros i hi_mem,\n    simp_rw [sets\u03b2, dif_pos hi_mem],\n    exact (h_meas i hi_mem).some_spec.1, },\n  have h_preim : \u2200 i \u2208 S, sets\u03a9 i = (f i) \u207b\u00b9' (sets\u03b2 i),\n  { intros i hi_mem,\n    simp_rw [sets\u03b2, dif_pos hi_mem],\n    exact (h_meas i hi_mem).some_spec.2.symm, },\n  have h_left_eq : \u03bc (\u22c2 i \u2208 S, sets\u03a9 i) = \u03bc (\u22c2 i \u2208 S, (f i) \u207b\u00b9' (sets\u03b2 i)),\n  { congr' with i x,\n    simp only [set.mem_Inter],\n    split; intros h hi_mem; specialize h hi_mem,\n    { rwa h_preim i hi_mem at h, },\n    { rwa h_preim i hi_mem, }, },\n  have h_right_eq : (\u220f i in S, \u03bc (sets\u03a9 i)) = \u220f i in S, \u03bc ((f i) \u207b\u00b9' (sets\u03b2 i)),\n  { refine finset.prod_congr rfl (\u03bb i hi_mem, _),\n    rw h_preim i hi_mem, },\n  rw [h_left_eq, h_right_eq],\n  exact h S h_meas\u03b2,\nend\n\nlemma indep_fun_iff_indep_set_preimage {m\u03b2 : measurable_space \u03b2} {m\u03b2' : measurable_space \u03b2'}\n  [is_probability_measure \u03bc] (hf : measurable f) (hg : measurable g) :\n  indep_fun f g \u03bc \u2194 \u2200 s t, measurable_set s \u2192 measurable_set t \u2192 indep_set (f \u207b\u00b9' s) (g \u207b\u00b9' t) \u03bc :=\nbegin\n  refine indep_fun_iff_measure_inter_preimage_eq_mul.trans _,\n  split; intros h s t hs ht; specialize h s t hs ht,\n  { rwa indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) \u03bc, },\n  { rwa \u2190 indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) \u03bc, },\nend\n\n@[symm] lemma indep_fun.symm {m\u03b2 : measurable_space \u03b2} {f g : \u03a9 \u2192 \u03b2} (hfg : indep_fun f g \u03bc) :\n  indep_fun g f \u03bc :=\nhfg.symm\n\nlemma indep_fun.ae_eq {m\u03b2 : measurable_space \u03b2} {f g f' g' : \u03a9 \u2192 \u03b2}\n  (hfg : indep_fun f g \u03bc) (hf : f =\u1d50[\u03bc] f') (hg : g =\u1d50[\u03bc] g') :\n  indep_fun f' g' \u03bc :=\nbegin\n  rintro _ _ \u27e8A, hA, rfl\u27e9 \u27e8B, hB, rfl\u27e9,\n  have h1 : f \u207b\u00b9' A =\u1d50[\u03bc] f' \u207b\u00b9' A := hf.fun_comp A,\n  have h2 : g \u207b\u00b9' B =\u1d50[\u03bc] g' \u207b\u00b9' B := hg.fun_comp B,\n  rw [\u2190 measure_congr h1, \u2190 measure_congr h2, \u2190 measure_congr (h1.inter h2)],\n  exact hfg _ _ \u27e8_, hA, rfl\u27e9 \u27e8_, hB, rfl\u27e9\nend\n\nlemma indep_fun.comp {m\u03b2 : measurable_space \u03b2} {m\u03b2' : measurable_space \u03b2'}\n  {m\u03b3 : measurable_space \u03b3} {m\u03b3' : measurable_space \u03b3'} {\u03c6 : \u03b2 \u2192 \u03b3} {\u03c8 : \u03b2' \u2192 \u03b3'}\n  (hfg : indep_fun f g \u03bc) (h\u03c6 : measurable \u03c6) (h\u03c8 : measurable \u03c8) :\n  indep_fun (\u03c6 \u2218 f) (\u03c8 \u2218 g) \u03bc :=\nbegin\n  rintro _ _ \u27e8A, hA, rfl\u27e9 \u27e8B, hB, rfl\u27e9,\n  apply hfg,\n  { exact \u27e8\u03c6 \u207b\u00b9' A, h\u03c6 hA, set.preimage_comp.symm\u27e9 },\n  { exact \u27e8\u03c8 \u207b\u00b9' B, h\u03c8 hB, set.preimage_comp.symm\u27e9 }\nend\n\n/-- If `f` is a family of mutually independent random variables (`Indep_fun m f \u03bc`) and `S, T` are\ntwo disjoint finite index sets, then the tuple formed by `f i` for `i \u2208 S` is independent of the\ntuple `(f i)_i` for `i \u2208 T`. -/\nlemma Indep_fun.indep_fun_finset [is_probability_measure \u03bc]\n  {\u03b9 : Type*} {\u03b2 : \u03b9 \u2192 Type*} {m : \u03a0 i, measurable_space (\u03b2 i)}\n  {f : \u03a0 i, \u03a9 \u2192 \u03b2 i} (S T : finset \u03b9) (hST : disjoint S T) (hf_Indep : Indep_fun m f \u03bc)\n  (hf_meas : \u2200 i, measurable (f i)) :\n  indep_fun (\u03bb a (i : S), f i a) (\u03bb a (i : T), f i a) \u03bc :=\nbegin\n  -- We introduce \u03c0-systems, build from the \u03c0-system of boxes which generates `measurable_space.pi`.\n  let \u03c0S\u03b2 := (set.pi (set.univ : set S) ''\n    (set.pi (set.univ : set S) (\u03bb i, {s : set (\u03b2 i) | measurable_set[m i] s}))),\n  let \u03c0S := {s : set \u03a9 | \u2203 t \u2208 \u03c0S\u03b2, (\u03bb a (i : S), f i a) \u207b\u00b9' t = s},\n  have h\u03c0S_pi : is_pi_system \u03c0S := is_pi_system_pi.comap (\u03bb a i, f i a),\n  have h\u03c0S_gen : measurable_space.pi.comap (\u03bb a (i : S), f i a) = generate_from \u03c0S,\n  { rw [generate_from_pi.symm, comap_generate_from],\n    { congr' with s,\n      simp only [set.mem_image, set.mem_set_of_eq, exists_prop], },\n    { apply_instance } },\n  let \u03c0T\u03b2 := (set.pi (set.univ : set T) ''\n    (set.pi (set.univ : set T) (\u03bb i, {s : set (\u03b2 i) | measurable_set[m i] s}))),\n  let \u03c0T := {s : set \u03a9 | \u2203 t \u2208 \u03c0T\u03b2, (\u03bb a (i : T), f i a) \u207b\u00b9' t = s},\n  have h\u03c0T_pi : is_pi_system \u03c0T := is_pi_system_pi.comap (\u03bb a i, f i a),\n  have h\u03c0T_gen : measurable_space.pi.comap (\u03bb a (i : T), f i a) = generate_from \u03c0T,\n  { rw [generate_from_pi.symm, comap_generate_from],\n    { congr' with s,\n      simp only [set.mem_image, set.mem_set_of_eq, exists_prop], },\n    { apply_instance } },\n\n  -- To prove independence, we prove independence of the generating \u03c0-systems.\n  refine indep_sets.indep (measurable.comap_le (measurable_pi_iff.mpr (\u03bb i, hf_meas i)))\n    (measurable.comap_le (measurable_pi_iff.mpr (\u03bb i, hf_meas i))) h\u03c0S_pi h\u03c0T_pi h\u03c0S_gen h\u03c0T_gen _,\n\n  rintros _ _ \u27e8s, \u27e8sets_s, hs1, hs2\u27e9, rfl\u27e9 \u27e8t, \u27e8sets_t, ht1, ht2\u27e9, rfl\u27e9,\n  simp only [set.mem_univ_pi, set.mem_set_of_eq] at hs1 ht1,\n  rw [\u2190 hs2, \u2190 ht2],\n  classical,\n  let sets_s' : (\u03a0 i : \u03b9, set (\u03b2 i)) := \u03bb i, dite (i \u2208 S) (\u03bb hi, sets_s \u27e8i, hi\u27e9) (\u03bb _, set.univ),\n  have h_sets_s'_eq : \u2200 {i} (hi : i \u2208 S), sets_s' i = sets_s \u27e8i, hi\u27e9,\n  { intros i hi, simp_rw [sets_s', dif_pos hi], },\n  have h_sets_s'_univ : \u2200 {i} (hi : i \u2208 T), sets_s' i = set.univ,\n  { intros i hi, simp_rw [sets_s', dif_neg (finset.disjoint_right.mp hST hi)], },\n  let sets_t' : (\u03a0 i : \u03b9, set (\u03b2 i)) := \u03bb i, dite (i \u2208 T) (\u03bb hi, sets_t \u27e8i, hi\u27e9) (\u03bb _, set.univ),\n  have h_sets_t'_univ : \u2200 {i} (hi : i \u2208 S), sets_t' i = set.univ,\n  { intros i hi, simp_rw [sets_t', dif_neg (finset.disjoint_left.mp hST hi)], },\n  have h_meas_s' : \u2200 i \u2208 S, measurable_set (sets_s' i),\n  { intros i hi, rw h_sets_s'_eq hi, exact hs1 _, },\n  have h_meas_t' : \u2200 i \u2208 T, measurable_set (sets_t' i),\n  { intros i hi, simp_rw [sets_t', dif_pos hi], exact ht1 _, },\n  have h_eq_inter_S : (\u03bb (\u03c9 : \u03a9) (i : \u21a5S), f \u2191i \u03c9) \u207b\u00b9' set.pi set.univ sets_s\n    = \u22c2 i \u2208 S, (f i) \u207b\u00b9' (sets_s' i),\n  { ext1 x,\n    simp only [set.mem_preimage, set.mem_univ_pi, set.mem_Inter],\n    split; intro h,\n    { intros i hi, rw [h_sets_s'_eq hi], exact h \u27e8i, hi\u27e9, },\n    { rintros \u27e8i, hi\u27e9, specialize h i hi, rw [h_sets_s'_eq hi] at h, exact h, }, },\n  have h_eq_inter_T : (\u03bb (\u03c9 : \u03a9) (i : \u21a5T), f \u2191i \u03c9) \u207b\u00b9' set.pi set.univ sets_t\n    = \u22c2 i \u2208 T, (f i) \u207b\u00b9' (sets_t' i),\n  { ext1 x,\n    simp only [set.mem_preimage, set.mem_univ_pi, set.mem_Inter],\n    split; intro h,\n    { intros i hi, simp_rw [sets_t', dif_pos hi], exact h \u27e8i, hi\u27e9, },\n    { rintros \u27e8i, hi\u27e9, specialize h i hi, simp_rw [sets_t', dif_pos hi] at h, exact h, }, },\n  rw Indep_fun_iff_measure_inter_preimage_eq_mul at hf_Indep,\n  rw [h_eq_inter_S, h_eq_inter_T, hf_Indep S h_meas_s', hf_Indep T h_meas_t'],\n  have h_Inter_inter : (\u22c2 i \u2208 S, (f i) \u207b\u00b9' (sets_s' i)) \u2229 (\u22c2 i \u2208 T, (f i) \u207b\u00b9' (sets_t' i))\n    = \u22c2 i \u2208 (S \u222a T), (f i) \u207b\u00b9' (sets_s' i \u2229 sets_t' i),\n  { ext1 x,\n    simp only [set.mem_inter_iff, set.mem_Inter, set.mem_preimage, finset.mem_union],\n    split; intro h,\n    { intros i hi,\n      cases hi,\n      { rw h_sets_t'_univ hi, exact \u27e8h.1 i hi, set.mem_univ _\u27e9, },\n      { rw h_sets_s'_univ hi, exact \u27e8set.mem_univ _, h.2 i hi\u27e9, }, },\n    { exact \u27e8\u03bb i hi, (h i (or.inl hi)).1, \u03bb i hi, (h i (or.inr hi)).2\u27e9, }, },\n  rw [h_Inter_inter, hf_Indep (S \u222a T)],\n  swap, { intros i hi_mem,\n    rw finset.mem_union at hi_mem,\n    cases hi_mem,\n    { rw [h_sets_t'_univ hi_mem, set.inter_univ], exact h_meas_s' i hi_mem, },\n    { rw [h_sets_s'_univ hi_mem, set.univ_inter], exact h_meas_t' i hi_mem, }, },\n  rw finset.prod_union hST,\n  congr' 1,\n  { refine finset.prod_congr rfl (\u03bb i hi, _),\n    rw [h_sets_t'_univ hi, set.inter_univ], },\n  { refine finset.prod_congr rfl (\u03bb i hi, _),\n    rw [h_sets_s'_univ hi, set.univ_inter], },\nend\n\nlemma Indep_fun.indep_fun_prod [is_probability_measure \u03bc]\n  {\u03b9 : Type*} {\u03b2 : \u03b9 \u2192 Type*} {m : \u03a0 i, measurable_space (\u03b2 i)}\n  {f : \u03a0 i, \u03a9 \u2192 \u03b2 i} (hf_Indep : Indep_fun m f \u03bc) (hf_meas : \u2200 i, measurable (f i))\n  (i j k : \u03b9) (hik : i \u2260 k) (hjk : j \u2260 k) :\n  indep_fun (\u03bb a, (f i a, f j a)) (f k) \u03bc :=\nbegin\n  classical,\n  have h_right : f k = (\u03bb p : (\u03a0 j : ({k} : finset \u03b9), \u03b2 j), p \u27e8k, finset.mem_singleton_self k\u27e9)\n    \u2218 (\u03bb a (j : ({k} : finset \u03b9)), f j a) := rfl,\n  have h_meas_right : measurable\n      (\u03bb p : (\u03a0 j : ({k} : finset \u03b9), \u03b2 j), p \u27e8k, finset.mem_singleton_self k\u27e9),\n    from measurable_pi_apply \u27e8k, finset.mem_singleton_self k\u27e9,\n  let s : finset \u03b9 := {i, j},\n  have h_left : (\u03bb \u03c9, (f i \u03c9, f j \u03c9))\n    = (\u03bb p : (\u03a0 l : s, \u03b2 l), (p \u27e8i, finset.mem_insert_self i _\u27e9,\n        p \u27e8j, finset.mem_insert_of_mem (finset.mem_singleton_self _)\u27e9))\n      \u2218 (\u03bb a (j : s), f j a),\n  { ext1 a,\n    simp only [prod.mk.inj_iff],\n    split; refl, },\n  have h_meas_left : measurable (\u03bb p : (\u03a0 l : s, \u03b2 l), (p \u27e8i, finset.mem_insert_self i _\u27e9,\n      p \u27e8j, finset.mem_insert_of_mem (finset.mem_singleton_self _)\u27e9)),\n    from measurable.prod (measurable_pi_apply \u27e8i, finset.mem_insert_self i {j}\u27e9)\n      (measurable_pi_apply \u27e8j, finset.mem_insert_of_mem (finset.mem_singleton_self j)\u27e9),\n  rw [h_left, h_right],\n  refine (hf_Indep.indep_fun_finset s {k} _ hf_meas).comp h_meas_left h_meas_right,\n  rw finset.disjoint_singleton_right,\n  simp only [finset.mem_insert, finset.mem_singleton, not_or_distrib],\n  exact \u27e8hik.symm, hjk.symm\u27e9,\nend\n\n@[to_additive]\nlemma Indep_fun.mul [is_probability_measure \u03bc]\n  {\u03b9 : Type*} {\u03b2 : Type*} {m : measurable_space \u03b2} [has_mul \u03b2] [has_measurable_mul\u2082 \u03b2]\n  {f : \u03b9 \u2192 \u03a9 \u2192 \u03b2} (hf_Indep : Indep_fun (\u03bb _, m) f \u03bc) (hf_meas : \u2200 i, measurable (f i))\n  (i j k : \u03b9) (hik : i \u2260 k) (hjk : j \u2260 k) :\n  indep_fun (f i * f j) (f k) \u03bc :=\nbegin\n  have : indep_fun (\u03bb \u03c9, (f i \u03c9, f j \u03c9)) (f k) \u03bc := hf_Indep.indep_fun_prod hf_meas i j k hik hjk,\n  change indep_fun ((\u03bb p : \u03b2 \u00d7 \u03b2, p.fst * p.snd) \u2218 (\u03bb \u03c9, (f i \u03c9, f j \u03c9))) (id \u2218 (f k)) \u03bc,\n  exact indep_fun.comp this (measurable_fst.mul measurable_snd) measurable_id,\nend\n\n@[to_additive]\nlemma Indep_fun.indep_fun_finset_prod_of_not_mem [is_probability_measure \u03bc]\n  {\u03b9 : Type*} {\u03b2 : Type*} {m : measurable_space \u03b2} [comm_monoid \u03b2] [has_measurable_mul\u2082 \u03b2]\n  {f : \u03b9 \u2192 \u03a9 \u2192 \u03b2} (hf_Indep : Indep_fun (\u03bb _, m) f \u03bc) (hf_meas : \u2200 i, measurable (f i))\n  {s : finset \u03b9} {i : \u03b9} (hi : i \u2209 s) :\n  indep_fun (\u220f j in s, f j) (f i) \u03bc :=\nbegin\n  classical,\n  have h_right : f i = (\u03bb p : (\u03a0 j : ({i} : finset \u03b9), \u03b2), p \u27e8i, finset.mem_singleton_self i\u27e9)\n    \u2218 (\u03bb a (j : ({i} : finset \u03b9)), f j a) := rfl,\n  have h_meas_right : measurable\n      (\u03bb p : (\u03a0 j : ({i} : finset \u03b9), \u03b2), p \u27e8i, finset.mem_singleton_self i\u27e9),\n    from measurable_pi_apply \u27e8i, finset.mem_singleton_self i\u27e9,\n  have h_left : (\u220f j in s, f j) = (\u03bb p : (\u03a0 j : s, \u03b2), \u220f j, p j) \u2218 (\u03bb a (j : s), f j a),\n  { ext1 a,\n    simp only [function.comp_app],\n    have : (\u220f (j : \u21a5s), f \u2191j a) = (\u220f (j : \u21a5s), f \u2191j) a, by rw finset.prod_apply,\n    rw [this, finset.prod_coe_sort], },\n  have h_meas_left : measurable (\u03bb p : (\u03a0 j : s, \u03b2), \u220f j, p j),\n    from finset.univ.measurable_prod (\u03bb (j : \u21a5s) (H : j \u2208 finset.univ), measurable_pi_apply j),\n  rw [h_left, h_right],\n  exact (hf_Indep.indep_fun_finset s {i} (finset.disjoint_singleton_left.mpr hi).symm hf_meas).comp\n    h_meas_left h_meas_right,\nend\n\n@[to_additive]\nlemma Indep_fun.indep_fun_prod_range_succ [is_probability_measure \u03bc]\n  {\u03b2 : Type*} {m : measurable_space \u03b2} [comm_monoid \u03b2] [has_measurable_mul\u2082 \u03b2]\n  {f : \u2115 \u2192 \u03a9 \u2192 \u03b2} (hf_Indep : Indep_fun (\u03bb _, m) f \u03bc) (hf_meas : \u2200 i, measurable (f i))\n  (n : \u2115) :\n  indep_fun (\u220f j in finset.range n, f j) (f n) \u03bc :=\nhf_Indep.indep_fun_finset_prod_of_not_mem hf_meas finset.not_mem_range_self\n\nlemma Indep_set.Indep_fun_indicator [has_zero \u03b2] [has_one \u03b2] {m : measurable_space \u03b2}\n  {s : \u03b9 \u2192 set \u03a9} (hs : Indep_set s \u03bc) :\n  Indep_fun (\u03bb n, m) (\u03bb n, (s n).indicator (\u03bb \u03c9, 1)) \u03bc :=\nbegin\n  classical,\n  rw Indep_fun_iff_measure_inter_preimage_eq_mul,\n  rintro S \u03c0 h\u03c0,\n  simp_rw set.indicator_const_preimage_eq_union,\n  refine @hs S (\u03bb i, ite (1 \u2208 \u03c0 i) (s i) \u2205 \u222a ite ((0 : \u03b2) \u2208 \u03c0 i) (s i)\u1d9c \u2205) (\u03bb i hi, _),\n  have hsi : measurable_set[generate_from {s i}] (s i),\n    from measurable_set_generate_from (set.mem_singleton _),\n  refine measurable_set.union (measurable_set.ite' (\u03bb _, hsi) (\u03bb _, _))\n    (measurable_set.ite' (\u03bb _, hsi.compl) (\u03bb _, _)),\n  { exact @measurable_set.empty _ (generate_from {s i}), },\n  { exact @measurable_set.empty _ (generate_from {s i}), },\nend\n\nend indep_fun\n\n\n/-! ### Kolmogorov's 0-1 law\n\nLet `s : \u03b9 \u2192 measurable_space \u03a9` be an independent sequence of sub-\u03c3-algebras. Then any set which\nis measurable with respect to the tail \u03c3-algebra `limsup s at_top` has probability 0 or 1.\n-/\n\nsection zero_one_law\n\nvariables {m m0 : measurable_space \u03a9} {\u03bc : measure \u03a9}\n\nlemma measure_eq_zero_or_one_or_top_of_indep_set_self {t : set \u03a9} (h_indep : indep_set t t \u03bc) :\n  \u03bc t = 0 \u2228 \u03bc t = 1 \u2228 \u03bc t = \u221e :=\nbegin\n  specialize h_indep t t (measurable_set_generate_from (set.mem_singleton t))\n    (measurable_set_generate_from (set.mem_singleton t)),\n  by_cases h0 : \u03bc t = 0,\n  { exact or.inl h0, },\n  by_cases h_top : \u03bc t = \u221e,\n  { exact or.inr (or.inr h_top), },\n  rw [\u2190 one_mul (\u03bc (t \u2229 t)), set.inter_self, ennreal.mul_eq_mul_right h0 h_top] at h_indep,\n  exact or.inr (or.inl h_indep.symm),\nend\n\nlemma measure_eq_zero_or_one_of_indep_set_self [is_finite_measure \u03bc] {t : set \u03a9}\n  (h_indep : indep_set t t \u03bc) :\n  \u03bc t = 0 \u2228 \u03bc t = 1 :=\nbegin\n  have h_0_1_top := measure_eq_zero_or_one_or_top_of_indep_set_self h_indep,\n  simpa [measure_ne_top \u03bc] using h_0_1_top,\nend\n\nvariables [is_probability_measure \u03bc] {s : \u03b9 \u2192 measurable_space \u03a9}\n\nopen filter\n\nlemma indep_bsupr_compl (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) (t : set \u03b9) :\n  indep (\u2a06 n \u2208 t, s n) (\u2a06 n \u2208 t\u1d9c, s n) \u03bc :=\nindep_supr_of_disjoint h_le h_indep disjoint_compl_right\n\nsection abstract\nvariables {\u03b1 : Type*} {p : set \u03b9 \u2192 Prop} {f : filter \u03b9} {ns : \u03b1 \u2192 set \u03b9}\n\n/-! We prove a version of Kolmogorov's 0-1 law for the \u03c3-algebra `limsup s f` where `f` is a filter\nfor which we can define the following two functions:\n* `p : set \u03b9 \u2192 Prop` such that for a set `t`, `p t \u2192 t\u1d9c \u2208 f`,\n* `ns : \u03b1 \u2192 set \u03b9` a directed sequence of sets which all verify `p` and such that\n  `\u22c3 a, ns a = set.univ`.\n\nFor the example of `f = at_top`, we can take `p = bdd_above` and `ns : \u03b9 \u2192 set \u03b9 := \u03bb i, set.Iic i`.\n-/\n\nlemma indep_bsupr_limsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc)\n  (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f) {t : set \u03b9} (ht : p t) :\n  indep (\u2a06 n \u2208 t, s n) (limsup s f) \u03bc :=\nbegin\n  refine indep_of_indep_of_le_right (indep_bsupr_compl h_le h_indep t) _,\n  refine Limsup_le_of_le (by is_bounded_default) _,\n  simp only [set.mem_compl_iff, eventually_map],\n  exact eventually_of_mem (hf t ht) le_supr\u2082,\nend\n\nlemma indep_supr_directed_limsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc)\n  (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f) (hns : directed (\u2264) ns) (hnsp : \u2200 a, p (ns a)) :\n  indep (\u2a06 a, \u2a06 n \u2208 (ns a), s n) (limsup s f) \u03bc :=\nbegin\n  refine indep_supr_of_directed_le _ _ _ _,\n  { exact \u03bb a, indep_bsupr_limsup h_le h_indep hf (hnsp a), },\n  { exact \u03bb a, supr\u2082_le (\u03bb n hn, h_le n), },\n  { exact limsup_le_supr.trans (supr_le h_le), },\n  { intros a b,\n    obtain \u27e8c, hc\u27e9 := hns a b,\n    refine \u27e8c, _, _\u27e9; refine supr_mono (\u03bb n, supr_mono' (\u03bb hn, \u27e8_, le_rfl\u27e9)),\n    { exact hc.1 hn, },\n    { exact hc.2 hn, }, },\nend\n\nlemma indep_supr_limsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f)\n  (hns : directed (\u2264) ns) (hnsp : \u2200 a, p (ns a)) (hns_univ : \u2200 n, \u2203 a, n \u2208 ns a) :\n  indep (\u2a06 n, s n) (limsup s f) \u03bc :=\nbegin\n  suffices : (\u2a06 a, \u2a06 n \u2208 (ns a), s n) = \u2a06 n, s n,\n  { rw \u2190 this,\n    exact indep_supr_directed_limsup h_le h_indep hf hns hnsp, },\n  rw supr_comm,\n  refine supr_congr (\u03bb n, _),\n  have : (\u2a06 (i : \u03b1) (H : n \u2208 ns i), s n) = (\u2a06 (h : \u2203 i, n \u2208 ns i), s n), by rw supr_exists,\n  haveI : nonempty (\u2203 (i : \u03b1), n \u2208 ns i) := \u27e8hns_univ n\u27e9,\n  rw [this, supr_const],\nend\n\nlemma indep_limsup_self (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f)\n  (hns : directed (\u2264) ns) (hnsp : \u2200 a, p (ns a)) (hns_univ : \u2200 n, \u2203 a, n \u2208 ns a) :\n  indep (limsup s f) (limsup s f) \u03bc :=\nindep_of_indep_of_le_left (indep_supr_limsup h_le h_indep hf hns hnsp hns_univ) limsup_le_supr\n\ntheorem measure_zero_or_one_of_measurable_set_limsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc)\n  (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f) (hns : directed (\u2264) ns) (hnsp : \u2200 a, p (ns a))\n  (hns_univ : \u2200 n, \u2203 a, n \u2208 ns a) {t : set \u03a9} (ht_tail : measurable_set[limsup s f] t) :\n  \u03bc t = 0 \u2228 \u03bc t = 1 :=\nmeasure_eq_zero_or_one_of_indep_set_self\n  ((indep_limsup_self h_le h_indep hf hns hnsp hns_univ).indep_set_of_measurable_set\n    ht_tail ht_tail)\n\nend abstract\n\nsection at_top\nvariables [semilattice_sup \u03b9] [no_max_order \u03b9] [nonempty \u03b9]\n\nlemma indep_limsup_at_top_self (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) :\n  indep (limsup s at_top) (limsup s at_top) \u03bc :=\nbegin\n  let ns : \u03b9 \u2192 set \u03b9 := set.Iic,\n  have hnsp : \u2200 i, bdd_above (ns i) := \u03bb i, bdd_above_Iic,\n  refine indep_limsup_self h_le h_indep _ _ hnsp _,\n  { simp only [mem_at_top_sets, ge_iff_le, set.mem_compl_iff, bdd_above, upper_bounds,\n      set.nonempty],\n    rintros t \u27e8a, ha\u27e9,\n    obtain \u27e8b, hb\u27e9 : \u2203 b, a < b := exists_gt a,\n    refine \u27e8b, \u03bb c hc hct, _\u27e9,\n    suffices : \u2200 i \u2208 t, i < c, from lt_irrefl c (this c hct),\n    exact \u03bb i hi, (ha hi).trans_lt (hb.trans_le hc), },\n  { exact monotone.directed_le (\u03bb i j hij k hki, le_trans hki hij), },\n  { exact \u03bb n, \u27e8n, le_rfl\u27e9, },\nend\n\n/-- **Kolmogorov's 0-1 law** : any event in the tail \u03c3-algebra of an independent sequence of\nsub-\u03c3-algebras has probability 0 or 1.\nThe tail \u03c3-algebra `limsup s at_top` is the same as `\u22c2 n, \u22c3 i \u2265 n, s i`. -/\ntheorem measure_zero_or_one_of_measurable_set_limsup_at_top (h_le : \u2200 n, s n \u2264 m0)\n  (h_indep : Indep s \u03bc) {t : set \u03a9} (ht_tail : measurable_set[limsup s at_top] t) :\n  \u03bc t = 0 \u2228 \u03bc t = 1 :=\nmeasure_eq_zero_or_one_of_indep_set_self\n  ((indep_limsup_at_top_self h_le h_indep).indep_set_of_measurable_set ht_tail ht_tail)\n\nend at_top\n\nsection at_bot\nvariables [semilattice_inf \u03b9] [no_min_order \u03b9] [nonempty \u03b9]\n\nlemma indep_limsup_at_bot_self (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) :\n  indep (limsup s at_bot) (limsup s at_bot) \u03bc :=\nbegin\n  let ns : \u03b9 \u2192 set \u03b9 := set.Ici,\n  have hnsp : \u2200 i, bdd_below (ns i) := \u03bb i, bdd_below_Ici,\n  refine indep_limsup_self h_le h_indep _ _ hnsp _,\n  { simp only [mem_at_bot_sets, ge_iff_le, set.mem_compl_iff, bdd_below, lower_bounds,\n      set.nonempty],\n    rintros t \u27e8a, ha\u27e9,\n    obtain \u27e8b, hb\u27e9 : \u2203 b, b < a := exists_lt a,\n    refine \u27e8b, \u03bb c hc hct, _\u27e9,\n    suffices : \u2200 i \u2208 t, c < i, from lt_irrefl c (this c hct),\n    exact \u03bb i hi, hc.trans_lt (hb.trans_le (ha hi)), },\n  { exact directed_of_inf (\u03bb i j hij k hki, hij.trans hki), },\n  { exact \u03bb n, \u27e8n, le_rfl\u27e9, },\nend\n\n/-- **Kolmogorov's 0-1 law** : any event in the tail \u03c3-algebra of an independent sequence of\nsub-\u03c3-algebras has probability 0 or 1. -/\ntheorem measure_zero_or_one_of_measurable_set_limsup_at_bot (h_le : \u2200 n, s n \u2264 m0)\n  (h_indep : Indep s \u03bc) {t : set \u03a9} (ht_tail : measurable_set[limsup s at_bot] t) :\n  \u03bc t = 0 \u2228 \u03bc t = 1 :=\nmeasure_eq_zero_or_one_of_indep_set_self\n  ((indep_limsup_at_bot_self h_le h_indep).indep_set_of_measurable_set ht_tail ht_tail)\n\nend at_bot\n\nend zero_one_law\n\nend probability_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/probability/independence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.731466392850724}}
{"text": "/-\nCopyright (c) 2022 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n\n! This file was ported from Lean 3 source module combinatorics.simple_graph.trails\n! leanprover-community/mathlib commit edaaaa4a5774e6623e0ddd919b2f2db49c65add4\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Combinatorics.SimpleGraph.Connectivity\nimport Mathlib.Data.Nat.Parity\n\n/-!\n\n# Trails and Eulerian trails\n\nThis module contains additional theory about trails, including Eulerian trails (also known\nas Eulerian circuits).\n\n## Main definitions\n\n* `SimpleGraph.Walk.IsEulerian` is the predicate that a trail is an Eulerian trail.\n* `SimpleGraph.Walk.IsTrail.even_countp_edges_iff` gives a condition on the number of edges\n  in a trail that can be incident to a given vertex.\n* `SimpleGraph.Walk.IsEulerian.even_degree_iff` gives a condition on the degrees of vertices\n  when there exists an Eulerian trail.\n* `SimpleGraph.Walk.IsEulerian.card_odd_degree` gives the possible numbers of odd-degree\n  vertices when there exists an Eulerian trail.\n\n## Todo\n\n* Prove that there exists an Eulerian trail when the conclusion to\n  `SimpleGraph.Walk.IsEulerian.card_odd_degree` holds.\n\n## Tags\n\nEulerian trails\n\n-/\n\n\nnamespace SimpleGraph\n\nvariable {V : Type _} {G : SimpleGraph V}\n\nnamespace Walk\n\n/-- The edges of a trail as a finset, since each edge in a trail appears exactly once. -/\n@[reducible]\ndef IsTrail.edgesFinset {u v : V} {p : G.Walk u v} (h : p.IsTrail) : Finset (Sym2 V) :=\n  \u27e8p.edges, h.edges_nodup\u27e9\n#align simple_graph.walk.is_trail.edges_finset SimpleGraph.Walk.IsTrail.edgesFinset\n\nvariable [DecidableEq V]\n\ntheorem IsTrail.even_countp_edges_iff {u v : V} {p : G.Walk u v} (ht : p.IsTrail) (x : V) :\n    Even (p.edges.countp fun e => x \u2208 e) \u2194 u \u2260 v \u2192 x \u2260 u \u2227 x \u2260 v := by\n  induction' p with u u v w huv p ih\n  \u00b7 simp\n  \u00b7 rw [cons_isTrail_iff] at ht\n    specialize ih ht.1\n    simp only [List.countp_cons, Ne.def, edges_cons, Sym2.mem_iff]\n    split_ifs with h\n    \u00b7 rw [decide_eq_true_eq] at h\n      obtain (rfl | rfl) := h\n      \u00b7 rw [Nat.even_add_one, ih]\n        simp only [huv.ne, imp_false, Ne.def, not_false_iff, true_and_iff, not_forall,\n          Classical.not_not, exists_prop, eq_self_iff_true, not_true, false_and_iff,\n          and_iff_right_iff_imp]\n        rintro rfl rfl\n        exact G.loopless _ huv\n      \u00b7 rw [Nat.even_add_one, ih, \u2190 not_iff_not]\n        simp only [huv.ne.symm, Ne.def, eq_self_iff_true, not_true, false_and_iff, not_forall,\n          not_false_iff, exists_prop, and_true_iff, Classical.not_not, true_and_iff, iff_and_self]\n        rintro rfl\n        exact huv.ne\n    \u00b7 rw [decide_eq_true_eq, not_or] at h\n      simp only [h.1, h.2, not_false_iff, true_and_iff, add_zero, Ne.def] at ih\u22a2\n      rw [ih]\n      constructor <;>\n        \u00b7 rintro h' h'' rfl\n          simp only [imp_false, eq_self_iff_true, not_true, Classical.not_not] at h'\n          cases h'\n          simp only [not_true, and_false, false_and] at h\n#align simple_graph.walk.is_trail.even_countp_edges_iff SimpleGraph.Walk.IsTrail.even_countp_edges_iff\n\n/-- An *Eulerian trail* (also known as an \"Eulerian path\") is a walk\n`p` that visits every edge exactly once.  The lemma `SimpleGraph.Walk.IsEulerian.IsTrail` shows\nthat these are trails.\n\nCombine with `p.IsCircuit` to get an Eulerian circuit (also known as an \"Eulerian cycle\"). -/\ndef IsEulerian {u v : V} (p : G.Walk u v) : Prop :=\n  \u2200 e, e \u2208 G.edgeSet \u2192 p.edges.count e = 1\n#align simple_graph.walk.is_eulerian SimpleGraph.Walk.IsEulerian\n\ntheorem IsEulerian.isTrail {u v : V} {p : G.Walk u v} (h : p.IsEulerian) : p.IsTrail := by\n  rw [isTrail_def, List.nodup_iff_count_le_one]\n  intro e\n  by_cases he : e \u2208 p.edges\n  \u00b7 exact (h e (edges_subset_edgeSet _ he)).le\n  \u00b7 simp [he]\n#align simple_graph.walk.is_eulerian.is_trail SimpleGraph.Walk.IsEulerian.isTrail\n\ntheorem IsEulerian.mem_edges_iff {u v : V} {p : G.Walk u v} (h : p.IsEulerian) {e : Sym2 V} :\n    e \u2208 p.edges \u2194 e \u2208 G.edgeSet :=\n  \u27e8fun h => p.edges_subset_edgeSet h, fun he => by simpa using (h e he).ge\u27e9\n#align simple_graph.walk.is_eulerian.mem_edges_iff SimpleGraph.Walk.IsEulerian.mem_edges_iff\n\n/-- The edge set of an Eulerian graph is finite. -/\ndef IsEulerian.fintypeEdgeSet {u v : V} {p : G.Walk u v} (h : p.IsEulerian) :\n    Fintype G.edgeSet :=\n  Fintype.ofFinset h.isTrail.edgesFinset fun e => by\n    simp only [Finset.mem_mk, Multiset.mem_coe, h.mem_edges_iff]\n#align simple_graph.walk.is_eulerian.fintype_edge_set SimpleGraph.Walk.IsEulerian.fintypeEdgeSet\n\ntheorem IsTrail.isEulerian_of_forall_mem {u v : V} {p : G.Walk u v} (h : p.IsTrail)\n    (hc : \u2200 e, e \u2208 G.edgeSet \u2192 e \u2208 p.edges) : p.IsEulerian := fun e he =>\n  List.count_eq_one_of_mem h.edges_nodup (hc e he)\n#align simple_graph.walk.is_trail.is_eulerian_of_forall_mem SimpleGraph.Walk.IsTrail.isEulerian_of_forall_mem\n\ntheorem isEulerian_iff {u v : V} (p : G.Walk u v) :\n    p.IsEulerian \u2194 p.IsTrail \u2227 \u2200 e, e \u2208 G.edgeSet \u2192 e \u2208 p.edges := by\n  constructor\n  \u00b7 intro h\n    exact \u27e8h.isTrail, fun _ => h.mem_edges_iff.mpr\u27e9\n  \u00b7 rintro \u27e8h, hl\u27e9\n    exact h.isEulerian_of_forall_mem hl\n#align simple_graph.walk.is_eulerian_iff SimpleGraph.Walk.isEulerian_iff\n\ntheorem IsEulerian.edgesFinset_eq [Fintype G.edgeSet] {u v : V} {p : G.Walk u v}\n    (h : p.IsEulerian) : h.isTrail.edgesFinset = G.edgeFinset := by\n  ext e\n  simp [h.mem_edges_iff]\n#align simple_graph.walk.is_eulerian.edges_finset_eq SimpleGraph.Walk.IsEulerian.edgesFinset_eq\n\ntheorem IsEulerian.even_degree_iff {x u v : V} {p : G.Walk u v} (ht : p.IsEulerian) [Fintype V]\n    [DecidableRel G.Adj] : Even (G.degree x) \u2194 u \u2260 v \u2192 x \u2260 u \u2227 x \u2260 v := by\n  convert ht.isTrail.even_countp_edges_iff x\n  rw [\u2190 Multiset.coe_countp, Multiset.countp_eq_card_filter, \u2190 card_incidenceFinset_eq_degree]\n  change Multiset.card _ = _\n  congr 1\n  convert_to _ = (ht.isTrail.edgesFinset.filter (Membership.mem x)).val\n  have : Fintype G.edgeSet := fintypeEdgeSet ht\n  rw [ht.edgesFinset_eq, G.incidenceFinset_eq_filter x]\n#align simple_graph.walk.is_eulerian.even_degree_iff SimpleGraph.Walk.IsEulerian.even_degree_iff\n\ntheorem IsEulerian.card_filter_odd_degree [Fintype V] [DecidableRel G.Adj] {u v : V}\n    {p : G.Walk u v} (ht : p.IsEulerian) {s}\n    (h : s = (Finset.univ : Finset V).filter fun v => Odd (G.degree v)) :\n    s.card = 0 \u2228 s.card = 2 := by\n  subst s\n  simp only [Nat.odd_iff_not_even, Finset.card_eq_zero]\n  simp only [ht.even_degree_iff, Ne.def, not_forall, not_and, Classical.not_not, exists_prop]\n  obtain rfl | hn := eq_or_ne u v\n  \u00b7 left\n    simp\n  \u00b7 right\n    convert_to _ = ({u, v} : Finset V).card\n    \u00b7 simp [hn]\n    \u00b7 congr\n      ext x\n      simp [hn, imp_iff_not_or]\n#align simple_graph.walk.is_eulerian.card_filter_odd_degree SimpleGraph.Walk.IsEulerian.card_filter_odd_degree\n\ntheorem IsEulerian.card_odd_degree [Fintype V] [DecidableRel G.Adj] {u v : V} {p : G.Walk u v}\n    (ht : p.IsEulerian) :\n    Fintype.card { v : V | Odd (G.degree v) } = 0 \u2228 Fintype.card { v : V | Odd (G.degree v) } = 2 :=\n  by\n  rw [\u2190 Set.toFinset_card]\n  apply IsEulerian.card_filter_odd_degree ht\n  ext v\n  simp\n#align simple_graph.walk.is_eulerian.card_odd_degree SimpleGraph.Walk.IsEulerian.card_odd_degree\n\nend Walk\n\nend SimpleGraph\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/SimpleGraph/Trails.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7314223328226988}}
{"text": "import data.nat.basic\nimport data.set\n\n\ndef odd : \u2115 \u2192 Prop := \u03bb n, \u2203 m, n = 2 * m + 1\ndef even : \u2115 \u2192 Prop := \u03bb n, \u2203 m, n = 2 * m\n\ntheorem even_or_odd : \u2200 n, (even n \u2228 odd n) :=\nbegin\n    assume n,\n    apply @nat.rec_on (\u03bb n, even n \u2228 odd n),\n        left, exact \u27e80, rfl\u27e9,\n\n        assume k,\n        assume h,\n        cases h,\n            right, \n            apply exists.elim h,\n                assume m,\n                assume f,\n                rw f,\n                exact \u27e8m, rfl\u27e9,\n            \n            left,\n            apply exists.elim h,\n                assume m,\n                assume f,\n                rw f,\n                exact \u27e8m + 1, rfl\u27e9,\nend\n\ntheorem not_both_even_and_odd : \u2200 n, \u00ac (even n \u2227 odd n) :=\nbegin\n    assume n,\n    apply @nat.rec_on (\u03bb n, \u00ac (even n \u2227 odd n)),\n        assume h,\n        apply exists.elim h.2,\n            assume _ f, cases f,\n\n        assume k,\n        assume h,\n        assume h1,\n        have : even k \u2227 odd k,\n            let f : \u2115 \u2192 \u2115 := \u03bb n, n - 1,\n            split,\n                apply exists.elim h1.2,\n                    assume m,\n                    assume h2,\n                    exact \u27e8m, congr_arg f h2\u27e9,\n                    \n                apply exists.elim h1.1,\n                    assume m,\n                    assume h2,\n                    apply exists.intro (m - 1),\n                        have : k = 2 * m - 1 := congr_arg f h2,\n                        rw this,\n                        cases m,\n                            trivial,\n\n                            simp,\n                            calc\n                                2 * nat.succ m - 1 = 2 * (m + 1) - 1 : by trivial\n                                ... = 2 * m + 2 * 1 - 1 : by rw mul_add\n                                ... = 2 * m + (2 * 1 - 1) : by rw (@nat.add_sub_assoc (2*1) 1 dec_trivial)\n                                ... = 1 + 2 * m : by simp,\n        contradiction\n\nend\n\ntheorem not_even_odd: \u2200 n, \u00ac even n \u2194 odd n :=\nbegin\n    assume n,\n    split,\n        assume not_even,\n        have h := even_or_odd n,\n        cases h,\n            contradiction,\n            assumption,\n\n        assume oddn,\n        assume evenn,\n        have h := not_both_even_and_odd n,\n        exact h \u27e8evenn, oddn\u27e9\nend\n\ntheorem not_odd_even: \u2200 n, \u00ac odd n \u2194 even n :=\nbegin\n    assume n,\n    split,\n        assume not_odd,\n        have h := even_or_odd n,\n        cases h,\n            assumption,\n            contradiction,\n\n        assume evenn,\n        assume oddn,\n        have h := not_both_even_and_odd n,\n        exact h \u27e8evenn, oddn\u27e9\nend\n\nnamespace hidden\n\ndef tilda : \u2115 \u2192 \u2115 \u2192 Prop := \u03bb m n, ((even m) \u2227 (n = m + 1)) \u2228 ((odd m) \u2227 n = m - 1) \u2228 (m = n)\n\ndef equiv_tilda : \u2115 \u2192 set \u2115 := \u03bb a, {b | tilda a b}\n\nexample : equiv_tilda 5 = {4, 5} :=\nbegin\n    apply set.ext,\n    assume x,\n    split,\n        assume h,\n        cases h,\n        have : odd 5 := \u27e82, rfl\u27e9,\n        have : even 5 \u2227 odd 5 := \u27e8h.1, this\u27e9,\n        have : false := not_both_even_and_odd 5 this,\n        contradiction,\n\n        cases h,\n            cases h,\n            rw h_right,\n            simp,\n\n            rw \u2190h,\n            simp,\n\n        assume h,\n        cases h,\n            right, right, \n            apply eq.symm h,\n\n            cases h,\n                right, left,\n                split, \n                    exact \u27e82, rfl\u27e9,\n                    rw h,\n\n                cases h,\nend\n\ndef set_nat : set \u2115 := {n | true}\n\ntheorem Union.intro {U : Type} {I : Type} {A : I \u2192 set U} \n    {x : U} (i : I) (h : x \u2208 A i) : x \u2208 \u22c3 i, A i :=\n    by {simp, existsi i, exact h}\n\ntheorem Union.elim {U : Type} {I : Type} {A : I \u2192 set U} {b : Prop} {x : U}\n    (h\u2081 : x \u2208 \u22c3 i, A i) (h\u2082 : \u2200 (i : I), x \u2208 A i \u2192 b) : b :=\n    by {simp at h\u2081, cases h\u2081 with i h, exact h\u2082 i h}\n\nexample : (\u22c3 i, equiv_tilda i) = set_nat :=\nbegin\n    apply set.ext,\n        assume x,\n        split,\n            assume h,\n            trivial,\n\n            assume h,\n            apply @nat.rec_on (\u03bb k, k \u2208 \u22c3 i, equiv_tilda i),\n                apply Union.intro 0,\n                right, right, trivial,\n\n                assume k hk,\n                apply Union.elim hk,\n                    assume i hi,\n                    let f : \u2115 \u2192 \u2115 := \u03bb n, n + 1,\n                    cases hi,\n                        apply Union.intro (i+2),\n                            right, right, \n                            rw hi.2,\n\n                        cases hi,\n                        apply Union.intro (i),\n                            right, right,\n                            rw hi.2,\n                            rw \u2190nat.add_one,\n                            rw nat.sub_add_cancel,\n                            apply exists.elim hi.1,\n                                assume a ha,\n                                rw ha,\n                                have : 2 * a + 1 \u2265 1 := dec_trivial,\n                                assumption,\n                        \n                        apply Union.intro (i+1),\n                            right, right, \n                            rw hi,\nend\n\nend hidden", "meta": {"author": "hanzhi713", "repo": "lean-proofs", "sha": "4d8356a878645b9ba7cb036f87737f3f1e68ede5", "save_path": "github-repos/lean/hanzhi713-lean-proofs", "path": "github-repos/lean/hanzhi713-lean-proofs/lean-proofs-4d8356a878645b9ba7cb036f87737f3f1e68ede5/src/other/odd_and_even_nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7314223236906232}}
{"text": "theorem not_succ_le_self (a : mynat) : \u00ac (succ a \u2264 a) :=\nbegin\nintro h,\ncases h with c hc,\ninduction a with d hd,\nrw succ_add at hc,\nexact zero_ne_succ _ hc,\nrw succ_add at hc,\napply hd,\napply succ_inj,\nexact hc,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world10/level13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7313160418324747}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis file defines a typeclass for biadditive maps, i.e. maps\n`m : \u03b1 \u2192 \u03b2 \u2192 \u03b3` (where \u03b1, \u03b2 and \u03b3 are commutative additive monoids)\nsuch that `m a b` is an additive function of `a` and also an \nadditive function of `b`.  In other words, `m` should be bilinear\nover `\u2115`.\n-/\n\nimport algebra.group algebra.big_operators algebra.module\n\nvariables {\u03b9 : Type*} {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\nvariables [add_comm_monoid \u03b1] [add_comm_monoid \u03b2] [add_comm_monoid \u03b3]\n\nclass is_biadditive (m : \u03b1 \u2192 \u03b2 \u2192 \u03b3) : Prop := \n(zero_mul' : \u2200 b, m 0 b = 0)\n(add_mul'  : \u2200 a\u2081 a\u2082 b, m (a\u2081 + a\u2082) b = m a\u2081 b + m a\u2082 b)\n(mul_zero' : \u2200 a, m a 0 = 0)\n(mul_add'  : \u2200 a b\u2081 b\u2082, m a (b\u2081 + b\u2082) = m a b\u2081 + m a b\u2082)\n\nnamespace is_biadditive\n\nvariables (m : \u03b1 \u2192 \u03b2 \u2192 \u03b3) [is_biadditive m]\n\ndef zero_mul (b : \u03b2) : m 0 b = 0 := @is_biadditive.zero_mul' \u03b1 \u03b2 \u03b3 _ _ _ m _ b\ndef mul_zero (a : \u03b1) : m a 0 = 0 := @is_biadditive.mul_zero' \u03b1 \u03b2 \u03b3 _ _ _ m _ a\ndef add_mul (a\u2081 a\u2082 : \u03b1) (b : \u03b2) : m (a\u2081 + a\u2082) b = m a\u2081 b + m a\u2082 b := \n @is_biadditive.add_mul' \u03b1 \u03b2 \u03b3 _ _ _ m _ a\u2081 a\u2082 b\ndef mul_add (a : \u03b1) (b\u2081 b\u2082 : \u03b2) : m a (b\u2081 + b\u2082) = m a b\u2081 + m a b\u2082 := \n @is_biadditive.mul_add' \u03b1 \u03b2 \u03b3 _ _ _ m _ a b\u2081 b\u2082\n\ndef hom_right (a : \u03b1) : \u03b2 \u2192+ \u03b3 := {\n  to_fun := m a,\n  map_zero' := is_biadditive.mul_zero' a,\n  map_add'  := is_biadditive.mul_add' a \n}\n\ndef hom_left (b : \u03b2) : \u03b1 \u2192+ \u03b3 := {\n  to_fun := \u03bb a, m a b,\n  map_zero' := is_biadditive.zero_mul' b,\n  map_add'  := \u03bb a\u2081 a\u2082, is_biadditive.add_mul' a\u2081 a\u2082 b \n}\n\nlemma sum_mul (s : finset \u03b9) (a : \u03b9 \u2192 \u03b1) (b : \u03b2) : \n m (s.sum a) b = s.sum (\u03bb x, m (a x) b) := \n  (hom_left m b).map_sum a s \n\nlemma mul_sum (s : finset \u03b9) (a : \u03b1) (b : \u03b9 \u2192 \u03b2) : \n m a (s.sum b) = s.sum (\u03bb x, m a (b x)) := \n  (hom_right m a).map_sum b s\n\nend is_biadditive\n\nnamespace semiring\n\nvariables (R : Type*) [semiring R]\n\ninstance : is_biadditive ((*) : R \u2192 R \u2192 R) := {\n zero_mul' := \u03bb b, by {rw[_root_.zero_mul]},\n mul_zero' := \u03bb b, by {rw[_root_.mul_zero]},\n add_mul'  := \u03bb a\u2081 a\u2082 b, by {rw[_root_.add_mul]},\n mul_add'  := \u03bb a b\u2081 b\u2082, by {rw[_root_.mul_add]},\n}\n\nend semiring \n\nnamespace semimodule\n\nvariables (R : Type*) [semiring R]\nvariables (M : Type*) [add_comm_monoid M] [module R M]\n\ninstance : is_biadditive ((\u2022) : R \u2192 M \u2192 M) := {\n zero_mul' := \u03bb b, by {rw[_root_.zero_smul]},\n mul_zero' := \u03bb b, by {rw[_root_.smul_zero]},\n add_mul' := \u03bb a\u2081 a\u2082 b, by {rw[_root_.add_smul]},\n mul_add'  := \u03bb a b\u2081 b\u2082, by {rw[_root_.smul_add]},\n}\n\nend semimodule ", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/algebra/biadditive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871156, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7313160313762138}}
{"text": "theorem add_left_cancel (t a b : \u2115) : t + a = t + b \u2192 a = b :=\nbegin\n    intro h,\n    rw nat.add_comm t a at h,\n    rw nat.add_comm t b at h,\n    apply nat.add_right_cancel h,\nend", "meta": {"author": "Samyak-Surti", "repo": "LeanCode", "sha": "944eac3e5f43e2614ed246083b97fbdf24181d83", "save_path": "github-repos/lean/Samyak-Surti-LeanCode", "path": "github-repos/lean/Samyak-Surti-LeanCode/LeanCode-944eac3e5f43e2614ed246083b97fbdf24181d83/nat_num_game/src/Advanced_Addition_World/adv_add_wrld6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7313160309289166}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport measure_theory.measurable_space\n\n/-\n\n# Measure theory\n\n## More on sigma algebras.\n\n-/\n\n-- Intersection of sigma algebras is a sigma algebra\n\n-- Let \ud835\udcd0 be a family of sigma algebras on a type `X`\nvariables (X : Type) (I : Type) (\ud835\udcd0 : I \u2192 measurable_space X)\n\n-- Then their intersection is also a sigma algebra\n\nopen_locale measure_theory -- to get notation `measurable_set[S] U` \n-- for \"U is in the sigma algebra S\"\n\nexample : measurable_space X :=\n{ measurable_set' := \u03bb U, \u2200 i : I, measurable_set[\ud835\udcd0 i] U,\n  measurable_set_empty := begin\n    sorry\n  end,\n  measurable_set_compl := begin\n    sorry\n  end,\n  measurable_set_Union := begin\n    sorry\n  end }\n\n-- Lean knows that sigma algebras on X are a complete lattice\n-- so you could also make it like this:\nexample : measurable_space X := \u2a05 i, \ud835\udcd0 i\n\n-- Sigma algebras are closed under countable intersection\n-- Here, because there's only one sigma algebra involved,\n-- I use the typeclass inference system to say \"fix a canonical\n-- sigma algebra on X\" and just use that one throughout the question.\nexample (X : Type) [measurable_space X] (f : \u2115 \u2192 set X)\n  (hf : \u2200 n, measurable_set (f n)) : measurable_set (\u22c2 n, f n) :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section12measure_theory/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897509188345, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7312757524907091}}
{"text": "import analysis.inner_product_space.adjoint\n\nvariables {E \ud835\udd5c : Type*}\n[is_R_or_C \ud835\udd5c]\n[inner_product_space \ud835\udd5c E]\n[finite_dimensional \ud835\udd5c E]\n\nnamespace inner_product_space\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c E _ x y\n\nlemma gram_self_adjoint (T : E \u2192\u2097[\ud835\udd5c] E): is_self_adjoint (T.adjoint * T) :=\nbegin\n  intros x y,\n  simp only [linear_map.mul_apply, linear_map.adjoint_inner_left, linear_map.adjoint_inner_right],\nend\n\nlemma gram_positive (T : E \u2192\u2097[\ud835\udd5c] E) :\n\u2200 (x : E), is_R_or_C.re \u27ea (T.adjoint * T) x, x \u27eb \u2265 0 \u2227 is_R_or_C.im \u27ea (T.adjoint * T) x, x\u27eb = 0 :=\nbegin\n  intro x,\n  rw [linear_map.mul_apply, linear_map.adjoint_inner_left, inner_self_eq_norm_sq_to_K],\n  norm_cast,\n  split,\n  {apply sq_nonneg _},\n  {refl},\nend\n\nend inner_product_space", "meta": {"author": "hparshall", "repo": "lean-matrix-analysis", "sha": "cc1b9949065257b6c19f047a5a996bfac29f178e", "save_path": "github-repos/lean/hparshall-lean-matrix-analysis", "path": "github-repos/lean/hparshall-lean-matrix-analysis/lean-matrix-analysis-cc1b9949065257b6c19f047a5a996bfac29f178e/src/gram_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810466522863, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7312299058066104}}
{"text": "import mynat.definition\nimport mynat.add\n-- import world2.level1\n-- import world2.level3\n-- import world6.level8\n-- import world7.level1\n-- import world8.level4\nimport world8.level6\n\nnamespace mynat\n\ntheorem eq_zero_of_add_right_eq_self (a b : mynat) : a + b = a \u2192 b = 0 :=\nbegin [nat_num_game]\n    intro h,\n    apply add_left_cancel b a,\n    rw add_zero,\n    exact h,\nend\n\n-- lemma add_succ_ne_self (a b : mynat) : a + succ(b) \u2260 a :=\n-- begin [nat_num_game]\n--     induction a with n hd,\n--     {\n--         rw zero_add,\n--         rw ne_comm,\n--         exact zero_ne_succ b,\n--     },\n--     {\n--         rw succ_add,\n--         rw ne_from_not_eq,\n--         rw eq_iff_succ_eq_succ,\n--         rw \u2190 ne_from_not_eq,\n--         exact hd,\n--     },\n-- end\n\n-- theorem eq_zero_of_add_right_eq_self (a b : mynat) : a + b = a \u2192 b = 0 :=\n-- begin [nat_num_game]\n--     induction b with n hd,\n--     {\n--         intro h,\n--         refl,\n--     },\n--     {\n--         intro h,\n--         exfalso,\n--         have nh := add_succ_ne_self a n,\n--         rw ne_from_not_eq at nh,\n--         rw not_iff_imp_false at nh,\n--         have f := nh h,\n--         exact f,\n--     },\n-- end\n\nend mynat", "meta": {"author": "nomoid", "repo": "lean-proofs", "sha": "b9f03a24623d1a1d111d6c2bbf53c617e2596d6a", "save_path": "github-repos/lean/nomoid-lean-proofs", "path": "github-repos/lean/nomoid-lean-proofs/lean-proofs-b9f03a24623d1a1d111d6c2bbf53c617e2596d6a/src/world8/level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.731226596635798}}
{"text": "variables A B C D : Prop\n\nsection \n  example : A \u2227 (A \u2192 B) \u2192 B :=\n    assume h: A \u2227 (A \u2192 B),\n    have h1: A \u2192 B, from and.elim_right h,\n    have h2: A, from and.elim_left h,\n    show B, from h1 h2\nend\n\nsection\nexample : A \u2192 \u00ac(\u00acA \u2227 B) :=\n  assume h1: A,\n  assume h2: \u00acA \u2227B,\n  show false, from (and.left h2) h1\nend\n\nsection \n  example : \u00ac(A \u2227 B) \u2192 (A \u2192 \u00acB) :=\n    assume ha: \u00ac(A \u2227 B),\n    assume hb: A,\n    assume hc: B,\n    show false, from (ha (and.intro hb hc))\nend\n\nsection\n  example (h1 : A \u2228 B) (h2 : A \u2192 C) (h3 : B \u2192 D) : C \u2228 D :=\n\n  or.elim h1\n  (\n    assume ha: A,\n    have hb: C, from h2 ha,\n    have hc: C \u2228 D, from or.inl hb,\n    show C \u2228 D, from hc\n  )\n\n  (\n    assume hd: B,\n    have he: D, from h3 hd,\n    have hf: C \u2228 D, from or.inr he,\n    show C \u2228 D, from hf \n  )\nend\n\nsection\n  example (h : \u00acA \u2227 \u00acB) : \u00ac(A \u2228 B) :=\n\n    assume h1: A \u2228 B,\n\n    show false, from or.elim h1\n      (\n      assume h3: A,\n      have h4: \u00acA, from and.elim_left h,\n      show false, from h4 h3\n      )\n\n      (\n      assume h3: B,\n      have h4: \u00acB, from and.elim_right h,\n      show false, from h4 h3\n      )\nend\n\nsection\nexample : \u00ac(A \u2194 \u00acA) :=\n  assume ha: (A \u2194 (A \u2192 false)),\n\n  have h1: A \u2192 (A \u2192 false), from iff.elim_left ha,\n  have h2: (A \u2192 false) \u2192 A, from iff.elim_right ha,\n  have hc: (A \u2192 false), from (assume hb: A, ((h1 hb) hb)),\n  have hd: A, from h2 hc,  \n  show false, from (h1 hd) hd\nend\n", "meta": {"author": "ju211256", "repo": "CS205", "sha": "3bf7e3f8d51dff3f51fac07eb0dba377703ee587", "save_path": "github-repos/lean/ju211256-CS205", "path": "github-repos/lean/ju211256-CS205/CS205-3bf7e3f8d51dff3f51fac07eb0dba377703ee587/LEAN/hw1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7312265688166228}}
{"text": "/-\nCopyright (c) 2018 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Johannes H\u00f6lzl, R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module order.liminf_limsup\n! leanprover-community/mathlib commit 4c19a16e4b705bf135cf9a80ac18fcc99c438514\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Filter.Cofinite\nimport Mathlib.Order.Hom.CompleteLattice\n\n/-!\n# liminfs and limsups of functions and filters\n\nDefines the liminf/limsup of a function taking values in a conditionally complete lattice, with\nrespect to an arbitrary filter.\n\nWe define `limsup\u209b f` (`liminf\u209b f`) where `f` is a filter taking values in a conditionally complete\nlattice. `limsup\u209b f` is the smallest element `a` such that, eventually, `u \u2264 a` (and vice versa for\n`liminf\u209b f`). To work with the Limsup along a function `u` use `limsup\u209b (map u f)`.\n\nUsually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter.\nFor instance, in \u2115 along a function `u`, this is `inf_n (sup_{k \u2265 n} u k)` (and the latter quantity\ndecreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible\nthat `u` is not bounded on the whole space, only eventually (think of `limsup (fun x \u21a6 1/x)` on \u211d.\nThen there is no guarantee that the quantity above really decreases (the value of the `sup`\nbeforehand isnot really well defined, as one can not use \u221e), so that the Inf could be anything.\nSo one can not use this `inf sup ...` definition in conditionally complete lattices, and one has\nto use a less tractable definition.\n\nIn conditionally complete lattices, the definition is only useful for filters which are eventually\nbounded above (otherwise, the Limsup would morally be +\u221e, which does not belong to the space) and\nwhich are frequently bounded below (otherwise, the Limsup would morally be -\u221e, which is not in the\nspace either). We start with definitions of these concepts for arbitrary filters, before turning to\nthe definitions of Limsup and Liminf.\n\nIn complete lattices, however, it coincides with the `Inf Sup` definition.\n-/\n\n\nopen Filter Set\n\nopen Filter\n\nvariable {\u03b1 \u03b2 \u03b3 \u03b9 : Type _}\n\nnamespace Filter\n\nsection Relation\n\n/-- `f.IsBounded (\u227a)`: the filter `f` is eventually bounded w.r.t. the relation `\u227a`, i.e.\neventually, it is bounded by some uniform bound.\n`r` will be usually instantiated with `\u2264` or `\u2265`. -/\ndef IsBounded (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (f : Filter \u03b1) :=\n  \u2203 b, \u2200\u1da0 x in f, r x b\n#align filter.is_bounded Filter.IsBounded\n\n/-- `f.IsBoundedUnder (\u227a) u`: the image of the filter `f` under `u` is eventually bounded w.r.t.\nthe relation `\u227a`, i.e. eventually, it is bounded by some uniform bound. -/\ndef IsBoundedUnder (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (f : Filter \u03b2) (u : \u03b2 \u2192 \u03b1) :=\n  (map u f).IsBounded r\n#align filter.is_bounded_under Filter.IsBoundedUnder\n\nvariable {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {f g : Filter \u03b1}\n\n/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is\nbounded. -/\ntheorem isBounded_iff : f.IsBounded r \u2194 \u2203 s \u2208 f.sets, \u2203 b, s \u2286 { x | r x b } :=\n  Iff.intro (fun \u27e8b, hb\u27e9 => \u27e8{ a | r a b }, hb, b, Subset.refl _\u27e9) fun \u27e8_, hs, b, hb\u27e9 =>\n    \u27e8b, mem_of_superset hs hb\u27e9\n#align filter.is_bounded_iff Filter.isBounded_iff\n\n/-- A bounded function `u` is in particular eventually bounded. -/\ntheorem isBoundedUnder_of {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} : (\u2203 b, \u2200 x, r (u x) b) \u2192 f.IsBoundedUnder r u\n  | \u27e8b, hb\u27e9 => \u27e8b, show \u2200\u1da0 x in f, r (u x) b from eventually_of_forall hb\u27e9\n#align filter.is_bounded_under_of Filter.isBoundedUnder_of\n\ntheorem isBounded_bot : IsBounded r \u22a5 \u2194 Nonempty \u03b1 := by simp [IsBounded, exists_true_iff_nonempty]\n#align filter.is_bounded_bot Filter.isBounded_bot\n\ntheorem isBounded_top : IsBounded r \u22a4 \u2194 \u2203 t, \u2200 x, r x t := by simp [IsBounded, eq_univ_iff_forall]\n#align filter.is_bounded_top Filter.isBounded_top\n\ntheorem isBounded_principal (s : Set \u03b1) : IsBounded r (\ud835\udcdf s) \u2194 \u2203 t, \u2200 x \u2208 s, r x t := by\n  simp [IsBounded, subset_def]\n#align filter.is_bounded_principal Filter.isBounded_principal\n\ntheorem isBounded_sup [IsTrans \u03b1 r] (hr : \u2200 b\u2081 b\u2082, \u2203 b, r b\u2081 b \u2227 r b\u2082 b) :\n    IsBounded r f \u2192 IsBounded r g \u2192 IsBounded r (f \u2294 g)\n  | \u27e8b\u2081, h\u2081\u27e9, \u27e8b\u2082, h\u2082\u27e9 =>\n    let \u27e8b, rb\u2081b, rb\u2082b\u27e9 := hr b\u2081 b\u2082\n    \u27e8b, eventually_sup.mpr\n      \u27e8h\u2081.mono fun _ h => _root_.trans h rb\u2081b, h\u2082.mono fun _ h => _root_.trans h rb\u2082b\u27e9\u27e9\n#align filter.is_bounded_sup Filter.isBounded_sup\n\ntheorem IsBounded.mono (h : f \u2264 g) : IsBounded r g \u2192 IsBounded r f\n  | \u27e8b, hb\u27e9 => \u27e8b, h hb\u27e9\n#align filter.is_bounded.mono Filter.IsBounded.mono\n\ntheorem IsBoundedUnder.mono {f g : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} (h : f \u2264 g) :\n    g.IsBoundedUnder r u \u2192 f.IsBoundedUnder r u := fun hg => IsBounded.mono (map_mono h) hg\n#align filter.is_bounded_under.mono Filter.IsBoundedUnder.mono\n\ntheorem IsBoundedUnder.mono_le [Preorder \u03b2] {l : Filter \u03b1} {u v : \u03b1 \u2192 \u03b2}\n    (hu : IsBoundedUnder (\u00b7 \u2264 \u00b7) l u) (hv : v \u2264\u1da0[l] u) : IsBoundedUnder (\u00b7 \u2264 \u00b7) l v := by\n  apply hu.imp\n  exact fun b hb => (eventually_map.1 hb).mp <| hv.mono fun x => le_trans\n#align filter.is_bounded_under.mono_le Filter.IsBoundedUnder.mono_le\n\ntheorem IsBoundedUnder.mono_ge [Preorder \u03b2] {l : Filter \u03b1} {u v : \u03b1 \u2192 \u03b2}\n    (hu : IsBoundedUnder (\u00b7 \u2265 \u00b7) l u) (hv : u \u2264\u1da0[l] v) : IsBoundedUnder (\u00b7 \u2265 \u00b7) l v :=\n  IsBoundedUnder.mono_le (\u03b2 := \u03b2\u1d52\u1d48) hu hv\n#align filter.is_bounded_under.mono_ge Filter.IsBoundedUnder.mono_ge\n\ntheorem isBoundedUnder_const [IsRefl \u03b1 r] {l : Filter \u03b2} {a : \u03b1} : IsBoundedUnder r l fun _ => a :=\n  \u27e8a, eventually_map.2 <| eventually_of_forall fun _ => refl _\u27e9\n#align filter.is_bounded_under_const Filter.isBoundedUnder_const\n\ntheorem IsBounded.isBoundedUnder {q : \u03b2 \u2192 \u03b2 \u2192 Prop} {u : \u03b1 \u2192 \u03b2}\n    (hf : \u2200 a\u2080 a\u2081, r a\u2080 a\u2081 \u2192 q (u a\u2080) (u a\u2081)) : f.IsBounded r \u2192 f.IsBoundedUnder q u\n  | \u27e8b, h\u27e9 => \u27e8u b, show \u2200\u1da0 x in f, q (u x) (u b) from h.mono fun x => hf x b\u27e9\n#align filter.is_bounded.is_bounded_under Filter.IsBounded.isBoundedUnder\n\ntheorem not_isBoundedUnder_of_tendsto_atTop [Preorder \u03b2] [NoMaxOrder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : Filter \u03b1}\n    [l.NeBot] (hf : Tendsto f l atTop) : \u00acIsBoundedUnder (\u00b7 \u2264 \u00b7) l f := by\n  rintro \u27e8b, hb\u27e9\n  rw [eventually_map] at hb\n  obtain \u27e8b', h\u27e9 := exists_gt b\n  have hb' := (tendsto_atTop.mp hf) b'\n  have : { x : \u03b1 | f x \u2264 b } \u2229 { x : \u03b1 | b' \u2264 f x } = \u2205 :=\n    eq_empty_of_subset_empty fun x hx => (not_le_of_lt h) (le_trans hx.2 hx.1)\n  exact (nonempty_of_mem (hb.and hb')).ne_empty this\n#align filter.not_is_bounded_under_of_tendsto_at_top Filter.not_isBoundedUnder_of_tendsto_atTop\n\ntheorem not_isBoundedUnder_of_tendsto_atBot [Preorder \u03b2] [NoMinOrder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : Filter \u03b1}\n    [l.NeBot] (hf : Tendsto f l atBot) : \u00acIsBoundedUnder (\u00b7 \u2265 \u00b7) l f :=\n  not_isBoundedUnder_of_tendsto_atTop (\u03b2 := \u03b2\u1d52\u1d48)  hf\n#align filter.not_is_bounded_under_of_tendsto_at_bot Filter.not_isBoundedUnder_of_tendsto_atBot\n\ntheorem IsBoundedUnder.bddAbove_range_of_cofinite [SemilatticeSup \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (hf : IsBoundedUnder (\u00b7 \u2264 \u00b7) cofinite f) : BddAbove (range f) := by\n  rcases hf with \u27e8b, hb\u27e9\n  haveI : Nonempty \u03b2 := \u27e8b\u27e9\n  rw [\u2190 image_univ, \u2190 union_compl_self { x | f x \u2264 b }, image_union, bddAbove_union]\n  exact \u27e8\u27e8b, ball_image_iff.2 fun x => id\u27e9, (hb.image f).bddAbove\u27e9\n#align filter.is_bounded_under.bdd_above_range_of_cofinite Filter.IsBoundedUnder.bddAbove_range_of_cofinite\n\ntheorem IsBoundedUnder.bddBelow_range_of_cofinite [SemilatticeInf \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (hf : IsBoundedUnder (\u00b7 \u2265 \u00b7) cofinite f) : BddBelow (range f) :=\n  IsBoundedUnder.bddAbove_range_of_cofinite (\u03b2 := \u03b2\u1d52\u1d48)  hf\n#align filter.is_bounded_under.bdd_below_range_of_cofinite Filter.IsBoundedUnder.bddBelow_range_of_cofinite\n\ntheorem IsBoundedUnder.bddAbove_range [SemilatticeSup \u03b2] {f : \u2115 \u2192 \u03b2}\n    (hf : IsBoundedUnder (\u00b7 \u2264 \u00b7) atTop f) : BddAbove (range f) := by\n  rw [\u2190 Nat.cofinite_eq_atTop] at hf\n  exact hf.bddAbove_range_of_cofinite\n#align filter.is_bounded_under.bdd_above_range Filter.IsBoundedUnder.bddAbove_range\n\ntheorem IsBoundedUnder.bddBelow_range [SemilatticeInf \u03b2] {f : \u2115 \u2192 \u03b2}\n    (hf : IsBoundedUnder (\u00b7 \u2265 \u00b7) atTop f) : BddBelow (range f) :=\n  IsBoundedUnder.bddAbove_range (\u03b2 := \u03b2\u1d52\u1d48) hf\n#align filter.is_bounded_under.bdd_below_range Filter.IsBoundedUnder.bddBelow_range\n\n/-- `IsCobounded (\u227a) f` states that the filter `f` does not tend to infinity w.r.t. `\u227a`. This is\nalso called frequently bounded. Will be usually instantiated with `\u2264` or `\u2265`.\n\nThere is a subtlety in this definition: we want `f.IsCobounded` to hold for any `f` in the case of\ncomplete lattices. This will be relevant to deduce theorems on complete lattices from their\nversions on conditionally complete lattices with additional assumptions. We have to be careful in\nthe edge case of the trivial filter containing the empty set: the other natural definition\n  `\u00ac \u2200 a, \u2200\u1da0 n in f, a \u2264 n`\nwould not work as well in this case.\n-/\ndef IsCobounded (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (f : Filter \u03b1) :=\n  \u2203 b, \u2200 a, (\u2200\u1da0 x in f, r x a) \u2192 r b a\n#align filter.is_cobounded Filter.IsCobounded\n\n/-- `IsCoboundedUnder (\u227a) f u` states that the image of the filter `f` under the map `u` does not\ntend to infinity w.r.t. `\u227a`. This is also called frequently bounded. Will be usually instantiated\nwith `\u2264` or `\u2265`. -/\ndef IsCoboundedUnder (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (f : Filter \u03b2) (u : \u03b2 \u2192 \u03b1) :=\n  (map u f).IsCobounded r\n#align filter.is_cobounded_under Filter.IsCoboundedUnder\n\n/-- To check that a filter is frequently bounded, it suffices to have a witness\nwhich bounds `f` at some point for every admissible set.\n\nThis is only an implication, as the other direction is wrong for the trivial filter.-/\ntheorem IsCobounded.mk [IsTrans \u03b1 r] (a : \u03b1) (h : \u2200 s \u2208 f, \u2203 x \u2208 s, r a x) : f.IsCobounded r :=\n  \u27e8a, fun _ s =>\n    let \u27e8_, h\u2081, h\u2082\u27e9 := h _ s\n    _root_.trans h\u2082 h\u2081\u27e9\n#align filter.is_cobounded.mk Filter.IsCobounded.mk\n\n/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite\ndirection). At least if the filter is not trivial. -/\ntheorem IsBounded.isCobounded_flip [IsTrans \u03b1 r] [NeBot f] : f.IsBounded r \u2192 f.IsCobounded (flip r)\n  | \u27e8a, ha\u27e9 =>\n    \u27e8a, fun b hb =>\n      let \u27e8_, rxa, rbx\u27e9 := (ha.and hb).exists\n      show r b a from _root_.trans rbx rxa\u27e9\n#align filter.is_bounded.is_cobounded_flip Filter.IsBounded.isCobounded_flip\n\ntheorem IsBounded.isCobounded_ge [Preorder \u03b1] [NeBot f] (h : f.IsBounded (\u00b7 \u2264 \u00b7)) :\n    f.IsCobounded (\u00b7 \u2265 \u00b7) :=\n  h.isCobounded_flip\n#align filter.is_bounded.is_cobounded_ge Filter.IsBounded.isCobounded_ge\n\ntheorem IsBounded.isCobounded_le [Preorder \u03b1] [NeBot f] (h : f.IsBounded (\u00b7 \u2265 \u00b7)) :\n    f.IsCobounded (\u00b7 \u2264 \u00b7) :=\n  h.isCobounded_flip\n#align filter.is_bounded.is_cobounded_le Filter.IsBounded.isCobounded_le\n\ntheorem isCobounded_bot : IsCobounded r \u22a5 \u2194 \u2203 b, \u2200 x, r b x := by simp [IsCobounded]\n#align filter.is_cobounded_bot Filter.isCobounded_bot\n\ntheorem isCobounded_top : IsCobounded r \u22a4 \u2194 Nonempty \u03b1 := by\n  simp (config := { contextual := true }) [IsCobounded, eq_univ_iff_forall,\n    exists_true_iff_nonempty]\n#align filter.is_cobounded_top Filter.isCobounded_top\n\ntheorem isCobounded_principal (s : Set \u03b1) :\n    (\ud835\udcdf s).IsCobounded r \u2194 \u2203 b, \u2200 a, (\u2200 x \u2208 s, r x a) \u2192 r b a := by simp [IsCobounded, subset_def]\n#align filter.is_cobounded_principal Filter.isCobounded_principal\n\ntheorem IsCobounded.mono (h : f \u2264 g) : f.IsCobounded r \u2192 g.IsCobounded r\n  | \u27e8b, hb\u27e9 => \u27e8b, fun a ha => hb a (h ha)\u27e9\n#align filter.is_cobounded.mono Filter.IsCobounded.mono\n\nend Relation\n\ntheorem isCobounded_le_of_bot [Preorder \u03b1] [OrderBot \u03b1] {f : Filter \u03b1} : f.IsCobounded (\u00b7 \u2264 \u00b7) :=\n  \u27e8\u22a5, fun _ _ => bot_le\u27e9\n#align filter.is_cobounded_le_of_bot Filter.isCobounded_le_of_bot\n\ntheorem isCobounded_ge_of_top [Preorder \u03b1] [OrderTop \u03b1] {f : Filter \u03b1} : f.IsCobounded (\u00b7 \u2265 \u00b7) :=\n  \u27e8\u22a4, fun _ _ => le_top\u27e9\n#align filter.is_cobounded_ge_of_top Filter.isCobounded_ge_of_top\n\ntheorem isBounded_le_of_top [Preorder \u03b1] [OrderTop \u03b1] {f : Filter \u03b1} : f.IsBounded (\u00b7 \u2264 \u00b7) :=\n  \u27e8\u22a4, eventually_of_forall fun _ => le_top\u27e9\n#align filter.is_bounded_le_of_top Filter.isBounded_le_of_top\n\ntheorem isBounded_ge_of_bot [Preorder \u03b1] [OrderBot \u03b1] {f : Filter \u03b1} : f.IsBounded (\u00b7 \u2265 \u00b7) :=\n  \u27e8\u22a5, eventually_of_forall fun _ => bot_le\u27e9\n#align filter.is_bounded_ge_of_bot Filter.isBounded_ge_of_bot\n\n@[simp]\ntheorem _root_.OrderIso.isBoundedUnder_le_comp [Preorder \u03b1] [Preorder \u03b2] (e : \u03b1 \u2243o \u03b2) {l : Filter \u03b3}\n    {u : \u03b3 \u2192 \u03b1} : (IsBoundedUnder (\u00b7 \u2264 \u00b7) l fun x => e (u x)) \u2194 IsBoundedUnder (\u00b7 \u2264 \u00b7) l u :=\n  (Function.Surjective.exists e.surjective).trans <|\n    exists_congr fun a => by simp only [eventually_map, e.le_iff_le]\n\n#align order_iso.is_bounded_under_le_comp OrderIso.isBoundedUnder_le_comp\n\n@[simp]\ntheorem _root_.OrderIso.isBoundedUnder_ge_comp [Preorder \u03b1] [Preorder \u03b2] (e : \u03b1 \u2243o \u03b2) {l : Filter \u03b3}\n    {u : \u03b3 \u2192 \u03b1} : (IsBoundedUnder (\u00b7 \u2265 \u00b7) l fun x => e (u x)) \u2194 IsBoundedUnder (\u00b7 \u2265 \u00b7) l u :=\n  OrderIso.isBoundedUnder_le_comp e.dual\n#align order_iso.is_bounded_under_ge_comp OrderIso.isBoundedUnder_ge_comp\n\n@[to_additive (attr := simp)]\ntheorem isBoundedUnder_le_inv [OrderedCommGroup \u03b1] {l : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} :\n    (IsBoundedUnder (\u00b7 \u2264 \u00b7) l fun x => (u x)\u207b\u00b9) \u2194 IsBoundedUnder (\u00b7 \u2265 \u00b7) l u :=\n  (OrderIso.inv \u03b1).isBoundedUnder_ge_comp\n#align filter.is_bounded_under_le_inv Filter.isBoundedUnder_le_inv\n#align filter.is_bounded_under_le_neg Filter.isBoundedUnder_le_neg\n\n@[to_additive (attr := simp)]\ntheorem isBoundedUnder_ge_inv [OrderedCommGroup \u03b1] {l : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} :\n    (IsBoundedUnder (\u00b7 \u2265 \u00b7) l fun x => (u x)\u207b\u00b9) \u2194 IsBoundedUnder (\u00b7 \u2264 \u00b7) l u :=\n  (OrderIso.inv \u03b1).isBoundedUnder_le_comp\n#align filter.is_bounded_under_ge_inv Filter.isBoundedUnder_ge_inv\n#align filter.is_bounded_under_ge_neg Filter.isBoundedUnder_ge_neg\n\ntheorem IsBoundedUnder.sup [SemilatticeSup \u03b1] {f : Filter \u03b2} {u v : \u03b2 \u2192 \u03b1} :\n    f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u \u2192\n      f.IsBoundedUnder (\u00b7 \u2264 \u00b7) v \u2192 f.IsBoundedUnder (\u00b7 \u2264 \u00b7) fun a => u a \u2294 v a\n  | \u27e8bu, (hu : \u2200\u1da0 x in f, u x \u2264 bu)\u27e9, \u27e8bv, (hv : \u2200\u1da0 x in f, v x \u2264 bv)\u27e9 =>\n    \u27e8bu \u2294 bv, show \u2200\u1da0 x in f, u x \u2294 v x \u2264 bu \u2294 bv by filter_upwards [hu, hv]with _ using sup_le_sup\u27e9\n#align filter.is_bounded_under.sup Filter.IsBoundedUnder.sup\n\n@[simp]\ntheorem isBoundedUnder_le_sup [SemilatticeSup \u03b1] {f : Filter \u03b2} {u v : \u03b2 \u2192 \u03b1} :\n    (f.IsBoundedUnder (\u00b7 \u2264 \u00b7) fun a => u a \u2294 v a) \u2194\n      f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u \u2227 f.IsBoundedUnder (\u00b7 \u2264 \u00b7) v :=\n  \u27e8fun h =>\n    \u27e8h.mono_le <| eventually_of_forall fun _ => le_sup_left,\n      h.mono_le <| eventually_of_forall fun _ => le_sup_right\u27e9,\n    fun h => h.1.sup h.2\u27e9\n#align filter.is_bounded_under_le_sup Filter.isBoundedUnder_le_sup\n\ntheorem IsBoundedUnder.inf [SemilatticeInf \u03b1] {f : Filter \u03b2} {u v : \u03b2 \u2192 \u03b1} :\n    f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u \u2192\n      f.IsBoundedUnder (\u00b7 \u2265 \u00b7) v \u2192 f.IsBoundedUnder (\u00b7 \u2265 \u00b7) fun a => u a \u2293 v a :=\n  IsBoundedUnder.sup (\u03b1 := \u03b1\u1d52\u1d48)\n#align filter.is_bounded_under.inf Filter.IsBoundedUnder.inf\n\n@[simp]\ntheorem isBoundedUnder_ge_inf [SemilatticeInf \u03b1] {f : Filter \u03b2} {u v : \u03b2 \u2192 \u03b1} :\n    (f.IsBoundedUnder (\u00b7 \u2265 \u00b7) fun a => u a \u2293 v a) \u2194\n      f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u \u2227 f.IsBoundedUnder (\u00b7 \u2265 \u00b7) v :=\n  isBoundedUnder_le_sup (\u03b1 := \u03b1\u1d52\u1d48)\n#align filter.is_bounded_under_ge_inf Filter.isBoundedUnder_ge_inf\n\ntheorem isBoundedUnder_le_abs [LinearOrderedAddCommGroup \u03b1] {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} :\n    (f.IsBoundedUnder (\u00b7 \u2264 \u00b7) fun a => |u a|) \u2194\n      f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u \u2227 f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u :=\n  isBoundedUnder_le_sup.trans <| and_congr Iff.rfl isBoundedUnder_le_neg\n#align filter.is_bounded_under_le_abs Filter.isBoundedUnder_le_abs\n\n/-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements\nin complete and conditionally complete lattices but let automation fill automatically the\nboundedness proofs in complete lattices, we use the tactic `isBounded_default` in the statements,\nin the form `(hf : f.IsBounded (\u2265) . isBoundedDefault)`. -/\n\nmacro \"isBoundedDefault \": tactic =>\n  `(tactic| (first\n  | apply isCobounded_le_of_bot\n  | apply isCobounded_ge_of_top\n  | apply isBounded_le_of_top\n  | apply isBounded_ge_of_bot))\n\n-- Porting note: The above is a lean 4 reconstruction of (note that applyc is not available (yet?)):\n-- unsafe def is_bounded_default : tactic Unit :=\n--   tactic.applyc `` is_cobounded_le_of_bot <|>\n--     tactic.applyc `` is_cobounded_ge_of_top <|>\n--       tactic.applyc `` is_bounded_le_of_top <|> tactic.applyc `` is_bounded_ge_of_bot\n-- #align filter.is_bounded_default filter.IsBounded_default\n\n\nsection ConditionallyCompleteLattice\n\nvariable [ConditionallyCompleteLattice \u03b1]\n\n-- Porting note: Renamed from Limsup and Liminf to limsup\u209b and liminf\u209b\n/-- The `limsup\u209b` of a filter `f` is the infimum of the `a` such that, eventually for `f`,\nholds `x \u2264 a`. -/\ndef limsup\u209b (f : Filter \u03b1) : \u03b1 :=\n  inf\u209b { a | \u2200\u1da0 n in f, n \u2264 a }\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup Filter.limsup\u209b\n\nset_option linter.uppercaseLean3 false in\n/-- The `liminf\u209b` of a filter `f` is the supremum of the `a` such that, eventually for `f`,\nholds `x \u2265 a`. -/\ndef liminf\u209b (f : Filter \u03b1) : \u03b1 :=\n  sup\u209b { a | \u2200\u1da0 n in f, a \u2264 n }\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf Filter.liminf\u209b\n\n/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,\neventually for `f`, holds `u x \u2264 a`. -/\ndef limsup (u : \u03b2 \u2192 \u03b1) (f : Filter \u03b2) : \u03b1 :=\n  limsup\u209b (map u f)\n#align filter.limsup Filter.limsup\n\n/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,\neventually for `f`, holds `u x \u2265 a`. -/\ndef liminf (u : \u03b2 \u2192 \u03b1) (f : Filter \u03b2) : \u03b1 :=\n  liminf\u209b (map u f)\n#align filter.liminf Filter.liminf\n\n/-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum\nof the `a` such that, eventually for `f`, `u x \u2264 a` whenever `p x` holds. -/\ndef blimsup (u : \u03b2 \u2192 \u03b1) (f : Filter \u03b2) (p : \u03b2 \u2192 Prop) :=\n  inf\u209b { a | \u2200\u1da0 x in f, p x \u2192 u x \u2264 a }\n#align filter.blimsup Filter.blimsup\n\n/-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum\nof the `a` such that, eventually for `f`, `a \u2264 u x` whenever `p x` holds. -/\ndef bliminf (u : \u03b2 \u2192 \u03b1) (f : Filter \u03b2) (p : \u03b2 \u2192 Prop) :=\n  sup\u209b { a | \u2200\u1da0 x in f, p x \u2192 a \u2264 u x }\n#align filter.bliminf Filter.bliminf\n\nsection\n\nvariable {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} {p : \u03b2 \u2192 Prop}\n\ntheorem limsup_eq : limsup u f = inf\u209b { a | \u2200\u1da0 n in f, u n \u2264 a } :=\n  rfl\n#align filter.limsup_eq Filter.limsup_eq\n\ntheorem liminf_eq : liminf u f = sup\u209b { a | \u2200\u1da0 n in f, a \u2264 u n } :=\n  rfl\n#align filter.liminf_eq Filter.liminf_eq\n\ntheorem blimsup_eq : blimsup u f p = inf\u209b { a | \u2200\u1da0 x in f, p x \u2192 u x \u2264 a } :=\n  rfl\n#align filter.blimsup_eq Filter.blimsup_eq\n\ntheorem bliminf_eq : bliminf u f p = sup\u209b { a | \u2200\u1da0 x in f, p x \u2192 a \u2264 u x } :=\n  rfl\n#align filter.bliminf_eq Filter.bliminf_eq\n\nend\n\n@[simp]\ntheorem blimsup_true (f : Filter \u03b2) (u : \u03b2 \u2192 \u03b1) : (blimsup u f fun _ => True) = limsup u f := by\n  simp [blimsup_eq, limsup_eq]\n#align filter.blimsup_true Filter.blimsup_true\n\n@[simp]\ntheorem bliminf_true (f : Filter \u03b2) (u : \u03b2 \u2192 \u03b1) : (bliminf u f fun _ => True) = liminf u f := by\n  simp [bliminf_eq, liminf_eq]\n#align filter.bliminf_true Filter.bliminf_true\n\ntheorem blimsup_eq_limsup_subtype {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} {p : \u03b2 \u2192 Prop} :\n    blimsup u f p = limsup (u \u2218 ((\u2191) : { x | p x } \u2192 \u03b2)) (comap (\u2191) f) := by\n  simp only [blimsup_eq, limsup_eq, Function.comp_apply, eventually_comap, SetCoe.forall,\n    Subtype.coe_mk, mem_setOf_eq]\n  congr\n  ext a\n  simp_rw [Subtype.forall]\n  exact eventually_congr (\n       eventually_of_forall\n        fun x => \u27e8fun hx y hy hxy => hxy.symm \u25b8 hx (hxy \u25b8 hy), fun hx hx' => hx x hx' rfl\u27e9)\n#align filter.blimsup_eq_limsup_subtype Filter.blimsup_eq_limsup_subtype\n\ntheorem bliminf_eq_liminf_subtype {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} {p : \u03b2 \u2192 Prop} :\n    bliminf u f p = liminf (u \u2218 ((\u2191) : { x | p x } \u2192 \u03b2)) (comap (\u2191) f) :=\n  blimsup_eq_limsup_subtype (\u03b1 := \u03b1\u1d52\u1d48)\n#align filter.bliminf_eq_liminf_subtype Filter.bliminf_eq_liminf_subtype\n\ntheorem limsup\u209b_le_of_le {f : Filter \u03b1} {a}\n    (hf : f.IsCobounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault)\n    (h : \u2200\u1da0 n in f, n \u2264 a) : limsup\u209b f \u2264 a :=\n  cinf\u209b_le hf h\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup_le_of_le Filter.limsup\u209b_le_of_le\n\ntheorem le_liminf\u209b_of_le {f : Filter \u03b1} {a}\n    (hf : f.IsCobounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault)\n    (h : \u2200\u1da0 n in f, a \u2264 n) : a \u2264 liminf\u209b f :=\n  le_csup\u209b hf h\nset_option linter.uppercaseLean3 false in\n#align filter.le_Liminf_of_le Filter.le_liminf\u209b_of_le\n\ntheorem limsup_le_of_le {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} {a}\n    (hf : f.IsCoboundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (h : \u2200\u1da0 n in f, u n \u2264 a) : limsup u f \u2264 a :=\n  cinf\u209b_le hf h\n#align filter.limsup_le_of_le Filter.limsup\u209b_le_of_le\n\ntheorem le_liminf_of_le {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} {a}\n    (hf : f.IsCoboundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault)\n    (h : \u2200\u1da0 n in f, a \u2264 u n) : a \u2264 liminf u f :=\n  le_csup\u209b hf h\n#align filter.le_liminf_of_le Filter.le_liminf_of_le\n\ntheorem le_limsup\u209b_of_le {f : Filter \u03b1} {a}\n    (hf : f.IsBounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault)\n    (h : \u2200 b, (\u2200\u1da0 n in f, n \u2264 b) \u2192 a \u2264 b) : a \u2264 limsup\u209b f :=\n  le_cinf\u209b hf h\nset_option linter.uppercaseLean3 false in\n#align filter.le_Limsup_of_le Filter.le_limsup\u209b_of_le\n\ntheorem liminf\u209b_le_of_le {f : Filter \u03b1} {a}\n    (hf : f.IsBounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault)\n    (h : \u2200 b, (\u2200\u1da0 n in f, b \u2264 n) \u2192 b \u2264 a) : liminf\u209b f \u2264 a :=\n  csup\u209b_le hf h\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_le_of_le Filter.liminf\u209b_le_of_le\n\ntheorem le_limsup_of_le {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} {a}\n    (hf : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (h : \u2200 b, (\u2200\u1da0 n in f, u n \u2264 b) \u2192 a \u2264 b) : a \u2264 limsup u f :=\n  le_cinf\u209b hf h\n#align filter.le_limsup_of_le Filter.le_limsup_of_le\n\ntheorem liminf_le_of_le {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} {a}\n    (hf : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault)\n    (h : \u2200 b, (\u2200\u1da0 n in f, b \u2264 u n) \u2192 b \u2264 a) : liminf u f \u2264 a :=\n  csup\u209b_le hf h\n#align filter.liminf_le_of_le Filter.liminf_le_of_le\n\ntheorem liminf\u209b_le_limsup\u209b {f : Filter \u03b1} [NeBot f]\n    (h\u2081 : f.IsBounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault)\n    (h\u2082 : f.IsBounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault):\n    liminf\u209b f \u2264 limsup\u209b f :=\n  liminf_le_of_le h\u2082 fun a\u2080 ha\u2080 =>\n    le_limsup_of_le h\u2081 fun a\u2081 ha\u2081 =>\n      show a\u2080 \u2264 a\u2081 from\n        let \u27e8_, hb\u2080, hb\u2081\u27e9 := (ha\u2080.and ha\u2081).exists\n        le_trans hb\u2080 hb\u2081\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_le_Limsup Filter.liminf\u209b_le_limsup\u209b\n\ntheorem liminf_le_limsup {f : Filter \u03b2} [NeBot f] {u : \u03b2 \u2192 \u03b1}\n    (h : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (h' : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault):\n    liminf u f \u2264 limsup u f :=\n  liminf\u209b_le_limsup\u209b h h'\n#align filter.liminf_le_limsup Filter.liminf_le_limsup\n\ntheorem limsup\u209b_le_limsup\u209b {f g : Filter \u03b1}\n    (hf : f.IsCobounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault)\n    (hg : g.IsBounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault)\n    (h : \u2200 a, (\u2200\u1da0 n in g, n \u2264 a) \u2192 \u2200\u1da0 n in f, n \u2264 a) : limsup\u209b f \u2264 limsup\u209b g :=\n  cinf\u209b_le_cinf\u209b hf hg h\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup_le_Limsup Filter.limsup\u209b_le_limsup\u209b\n\ntheorem liminf\u209b_le_liminf\u209b {f g : Filter \u03b1}\n    (hf : f.IsBounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault)\n    (hg : g.IsCobounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault)\n    (h : \u2200 a, (\u2200\u1da0 n in f, a \u2264 n) \u2192 \u2200\u1da0 n in g, a \u2264 n) : liminf\u209b f \u2264 liminf\u209b g :=\n  csup\u209b_le_csup\u209b hg hf h\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_le_Liminf Filter.liminf\u209b_le_liminf\u209b\n\ntheorem limsup_le_limsup {\u03b1 : Type _} [ConditionallyCompleteLattice \u03b2] {f : Filter \u03b1} {u v : \u03b1 \u2192 \u03b2}\n    (h : u \u2264\u1da0[f] v)\n    (hu : f.IsCoboundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (hv : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) v := by isBoundedDefault) :\n    limsup u f \u2264 limsup v f :=\n  limsup\u209b_le_limsup\u209b hu hv fun _ => h.trans\n#align filter.limsup_le_limsup Filter.limsup_le_limsup\n\ntheorem liminf_le_liminf {\u03b1 : Type _} [ConditionallyCompleteLattice \u03b2] {f : Filter \u03b1} {u v : \u03b1 \u2192 \u03b2}\n    (h : \u2200\u1da0 a in f, u a \u2264 v a)\n    (hu : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault)\n    (hv : f.IsCoboundedUnder (\u00b7 \u2265 \u00b7) v := by isBoundedDefault) :\n    liminf u f \u2264 liminf v f :=\n  limsup_le_limsup (\u03b2 := \u03b2\u1d52\u1d48) h hv hu\n#align filter.liminf_le_liminf Filter.liminf_le_liminf\n\ntheorem limsup\u209b_le_limsup\u209b_of_le {f g : Filter \u03b1} (h : f \u2264 g)\n    (hf : f.IsCobounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault)\n    (hg : g.IsBounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault) :\n    limsup\u209b f \u2264 limsup\u209b g :=\n  limsup\u209b_le_limsup\u209b hf hg fun _ ha => h ha\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup_le_Limsup_of_le Filter.limsup\u209b_le_limsup\u209b_of_le\n\ntheorem liminf\u209b_le_liminf\u209b_of_le {f g : Filter \u03b1} (h : g \u2264 f)\n    (hf : f.IsBounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault)\n    (hg : g.IsCobounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault) :\n    liminf\u209b f \u2264 liminf\u209b g :=\n  liminf\u209b_le_liminf\u209b hf hg fun _ ha => h ha\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_le_Liminf_of_le Filter.liminf\u209b_le_liminf\u209b_of_le\n\ntheorem limsup_le_limsup_of_le {\u03b1 \u03b2} [ConditionallyCompleteLattice \u03b2] {f g : Filter \u03b1} (h : f \u2264 g)\n    {u : \u03b1 \u2192 \u03b2}\n    (hf : f.IsCoboundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (hg : g.IsBoundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault) :\n    limsup u f \u2264 limsup u g :=\n  limsup\u209b_le_limsup\u209b_of_le (map_mono h) hf hg\n#align filter.limsup_le_limsup_of_le Filter.limsup_le_limsup_of_le\n\ntheorem liminf_le_liminf_of_le {\u03b1 \u03b2} [ConditionallyCompleteLattice \u03b2] {f g : Filter \u03b1} (h : g \u2264 f)\n    {u : \u03b1 \u2192 \u03b2}\n    (hf : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault)\n    (hg : g.IsCoboundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault) :\n    liminf u f \u2264 liminf u g :=\n  liminf\u209b_le_liminf\u209b_of_le (map_mono h) hf hg\n#align filter.liminf_le_liminf_of_le Filter.liminf_le_liminf_of_le\n\ntheorem limsup\u209b_principal {s : Set \u03b1} (h : BddAbove s) (hs : s.Nonempty) : limsup\u209b (\ud835\udcdf s) = sup\u209b s :=\n  by simp only [limsup\u209b, eventually_principal]; exact cinf\u209b_upper_bounds_eq_csup\u209b h hs\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup_principal Filter.limsup\u209b_principal\n\ntheorem liminf\u209b_principal {s : Set \u03b1} (h : BddBelow s) (hs : s.Nonempty) : liminf\u209b (\ud835\udcdf s) = inf\u209b s :=\n  limsup\u209b_principal (\u03b1 := \u03b1\u1d52\u1d48) h hs\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_principal Filter.liminf\u209b_principal\n\ntheorem limsup_congr {\u03b1 : Type _} [ConditionallyCompleteLattice \u03b2] {f : Filter \u03b1} {u v : \u03b1 \u2192 \u03b2}\n    (h : \u2200\u1da0 a in f, u a = v a) : limsup u f = limsup v f := by\n  rw [limsup_eq]\n  congr with b\n  exact eventually_congr (h.mono fun x hx => by simp [hx])\n#align filter.limsup_congr Filter.limsup_congr\n\ntheorem blimsup_congr {f : Filter \u03b2} {u v : \u03b2 \u2192 \u03b1} {p : \u03b2 \u2192 Prop} (h : \u2200\u1da0 a in f, p a \u2192 u a = v a) :\n    blimsup u f p = blimsup v f p := by\n  rw [blimsup_eq]\n  congr with b\n  refine' eventually_congr (h.mono fun x hx => \u27e8fun h\u2081 h\u2082 => _, fun h\u2081 h\u2082 => _\u27e9)\n  \u00b7 rw [\u2190 hx h\u2082]\n    exact h\u2081 h\u2082\n  \u00b7 rw [hx h\u2082]\n    exact h\u2081 h\u2082\n#align filter.blimsup_congr Filter.blimsup_congr\n\ntheorem bliminf_congr {f : Filter \u03b2} {u v : \u03b2 \u2192 \u03b1} {p : \u03b2 \u2192 Prop} (h : \u2200\u1da0 a in f, p a \u2192 u a = v a) :\n    bliminf u f p = bliminf v f p :=\n  blimsup_congr (\u03b1 := \u03b1\u1d52\u1d48) h\n#align filter.bliminf_congr Filter.bliminf_congr\n\ntheorem liminf_congr {\u03b1 : Type _} [ConditionallyCompleteLattice \u03b2] {f : Filter \u03b1} {u v : \u03b1 \u2192 \u03b2}\n    (h : \u2200\u1da0 a in f, u a = v a) : liminf u f = liminf v f :=\n  limsup_congr (\u03b2 := \u03b2\u1d52\u1d48) h\n#align filter.liminf_congr Filter.liminf_congr\n\ntheorem limsup_const {\u03b1 : Type _} [ConditionallyCompleteLattice \u03b2] {f : Filter \u03b1} [NeBot f]\n    (b : \u03b2) : limsup (fun _ => b) f = b := by\n  simpa only [limsup_eq, eventually_const] using cinf\u209b_Ici\n#align filter.limsup_const Filter.limsup_const\n\ntheorem liminf_const {\u03b1 : Type _} [ConditionallyCompleteLattice \u03b2] {f : Filter \u03b1} [NeBot f]\n    (b : \u03b2) : liminf (fun _ => b) f = b :=\n  limsup_const (\u03b2 := \u03b2\u1d52\u1d48) b\n#align filter.liminf_const Filter.liminf_const\n\nend ConditionallyCompleteLattice\n\nsection CompleteLattice\n\nvariable [CompleteLattice \u03b1]\n\n@[simp]\ntheorem limsup\u209b_bot : limsup\u209b (\u22a5 : Filter \u03b1) = \u22a5 :=\n  bot_unique <| inf\u209b_le <| by simp\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup_bot Filter.limsup\u209b_bot\n\n@[simp]\ntheorem liminf\u209b_bot : liminf\u209b (\u22a5 : Filter \u03b1) = \u22a4 :=\n  top_unique <| le_sup\u209b <| by simp\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_bot Filter.liminf\u209b_bot\n\n@[simp]\ntheorem limsup\u209b_top : limsup\u209b (\u22a4 : Filter \u03b1) = \u22a4 :=\n  top_unique <| le_inf\u209b <| by simp [eq_univ_iff_forall]; exact fun b hb => top_unique <| hb _\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup_top Filter.limsup\u209b_top\n\n@[simp]\ntheorem liminf\u209b_top : liminf\u209b (\u22a4 : Filter \u03b1) = \u22a5 :=\n  bot_unique <| sup\u209b_le <| by simp [eq_univ_iff_forall]; exact fun b hb => bot_unique <| hb _\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_top Filter.liminf\u209b_top\n\n@[simp]\ntheorem blimsup_false {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} : (blimsup u f fun _ => False) = \u22a5 := by\n  simp [blimsup_eq]\n#align filter.blimsup_false Filter.blimsup_false\n\n@[simp]\ntheorem bliminf_false {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} : (bliminf u f fun _ => False) = \u22a4 := by\n  simp [bliminf_eq]\n#align filter.bliminf_false Filter.bliminf_false\n\n/-- Same as limsup_const applied to `\u22a5` but without the `NeBot f` assumption -/\ntheorem limsup_const_bot {f : Filter \u03b2} : limsup (fun _ : \u03b2 => (\u22a5 : \u03b1)) f = (\u22a5 : \u03b1) := by\n  rw [limsup_eq, eq_bot_iff]\n  exact inf\u209b_le (eventually_of_forall fun _ => le_rfl)\n#align filter.limsup_const_bot Filter.limsup_const_bot\n\n/-- Same as limsup_const applied to `\u22a4` but without the `NeBot f` assumption -/\ntheorem liminf_const_top {f : Filter \u03b2} : liminf (fun _ : \u03b2 => (\u22a4 : \u03b1)) f = (\u22a4 : \u03b1) :=\n  limsup_const_bot (\u03b1 := \u03b1\u1d52\u1d48)\n#align filter.liminf_const_top Filter.liminf_const_top\n\ntheorem HasBasis.limsup\u209b_eq_inf\u1d62_sup\u209b {\u03b9} {p : \u03b9 \u2192 Prop} {s} {f : Filter \u03b1} (h : f.HasBasis p s) :\n    limsup\u209b f = \u2a05 (i) (_hi : p i), sup\u209b (s i) :=\n  le_antisymm (le_inf\u1d62\u2082 fun i hi => inf\u209b_le <| h.eventually_iff.2 \u27e8i, hi, fun _ => le_sup\u209b\u27e9)\n    (le_inf\u209b fun _ ha =>\n      let \u27e8_, hi, ha\u27e9 := h.eventually_iff.1 ha\n      inf\u1d62\u2082_le_of_le _ hi <| sup\u209b_le ha)\nset_option linter.uppercaseLean3 false in\n#align filter.has_basis.Limsup_eq_infi_Sup Filter.HasBasis.limsup\u209b_eq_inf\u1d62_sup\u209b\n\ntheorem HasBasis.liminf\u209b_eq_sup\u1d62_inf\u209b {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 Set \u03b1} {f : Filter \u03b1}\n    (h : f.HasBasis p s) : liminf\u209b f = \u2a06 (i) (_hi : p i), inf\u209b (s i) :=\n  HasBasis.limsup\u209b_eq_inf\u1d62_sup\u209b (\u03b1 := \u03b1\u1d52\u1d48) h\nset_option linter.uppercaseLean3 false in\n#align filter.has_basis.Liminf_eq_supr_Inf Filter.HasBasis.liminf\u209b_eq_sup\u1d62_inf\u209b\n\ntheorem limsup\u209b_eq_inf\u1d62_sup\u209b {f : Filter \u03b1} : limsup\u209b f = \u2a05 s \u2208 f, sup\u209b s :=\n  f.basis_sets.limsup\u209b_eq_inf\u1d62_sup\u209b\nset_option linter.uppercaseLean3 false in\n#align filter.Limsup_eq_infi_Sup Filter.limsup\u209b_eq_inf\u1d62_sup\u209b\n\ntheorem liminf\u209b_eq_sup\u1d62_inf\u209b {f : Filter \u03b1} : liminf\u209b f = \u2a06 s \u2208 f, inf\u209b s :=\n  limsup\u209b_eq_inf\u1d62_sup\u209b (\u03b1 := \u03b1\u1d52\u1d48)\nset_option linter.uppercaseLean3 false in\n#align filter.Liminf_eq_supr_Inf Filter.liminf\u209b_eq_sup\u1d62_inf\u209b\n\ntheorem limsup_le_sup\u1d62 {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} : limsup u f \u2264 \u2a06 n, u n :=\n  limsup_le_of_le (by isBoundedDefault) (eventually_of_forall (le_sup\u1d62 u))\n#align filter.limsup_le_supr Filter.limsup_le_sup\u1d62\n\ntheorem inf\u1d62_le_liminf {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} : (\u2a05 n, u n) \u2264 liminf u f :=\n  le_liminf_of_le (by isBoundedDefault) (eventually_of_forall (inf\u1d62_le u))\n#align filter.infi_le_liminf Filter.inf\u1d62_le_liminf\n\n/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter\nof the supremum of the function over `s` -/\ntheorem limsup_eq_inf\u1d62_sup\u1d62 {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} : limsup u f = \u2a05 s \u2208 f, \u2a06 a \u2208 s, u a :=\n  (f.basis_sets.map u).limsup\u209b_eq_inf\u1d62_sup\u209b.trans <| by simp only [sup\u209b_image, id]\n#align filter.limsup_eq_infi_supr Filter.limsup_eq_inf\u1d62_sup\u1d62\n\ntheorem limsup_eq_inf\u1d62_sup\u1d62_of_nat {u : \u2115 \u2192 \u03b1} : limsup u atTop = \u2a05 n : \u2115, \u2a06 i \u2265 n, u i :=\n  (atTop_basis.map u).limsup\u209b_eq_inf\u1d62_sup\u209b.trans <| by simp only [sup\u209b_image, inf\u1d62_const]; rfl\n#align filter.limsup_eq_infi_supr_of_nat Filter.limsup_eq_inf\u1d62_sup\u1d62_of_nat\n\ntheorem limsup_eq_inf\u1d62_sup\u1d62_of_nat' {u : \u2115 \u2192 \u03b1} : limsup u atTop = \u2a05 n : \u2115, \u2a06 i : \u2115, u (i + n) := by\n  simp only [limsup_eq_inf\u1d62_sup\u1d62_of_nat, sup\u1d62_ge_eq_sup\u1d62_nat_add]\n#align filter.limsup_eq_infi_supr_of_nat' Filter.limsup_eq_inf\u1d62_sup\u1d62_of_nat'\n\ntheorem HasBasis.limsup_eq_inf\u1d62_sup\u1d62 {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 Set \u03b2} {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1}\n    (h : f.HasBasis p s) : limsup u f = \u2a05 (i) (_hi : p i), \u2a06 a \u2208 s i, u a :=\n  (h.map u).limsup\u209b_eq_inf\u1d62_sup\u209b.trans <| by simp only [sup\u209b_image, id]\n#align filter.has_basis.limsup_eq_infi_supr Filter.HasBasis.limsup_eq_inf\u1d62_sup\u1d62\n\ntheorem blimsup_congr' {f : Filter \u03b2} {p q : \u03b2 \u2192 Prop} {u : \u03b2 \u2192 \u03b1}\n    (h : \u2200\u1da0 x in f, u x \u2260 \u22a5 \u2192 (p x \u2194 q x)) : blimsup u f p = blimsup u f q := by\n  simp only [blimsup_eq]\n  congr\n  ext a\n  refine' eventually_congr (h.mono fun b hb => _)\n  cases' eq_or_ne (u b) \u22a5 with hu hu; \u00b7 simp [hu]\n  rw [hb hu]\n#align filter.blimsup_congr' Filter.blimsup_congr'\n\ntheorem bliminf_congr' {f : Filter \u03b2} {p q : \u03b2 \u2192 Prop} {u : \u03b2 \u2192 \u03b1}\n    (h : \u2200\u1da0 x in f, u x \u2260 \u22a4 \u2192 (p x \u2194 q x)) : bliminf u f p = bliminf u f q :=\n  blimsup_congr' (\u03b1 := \u03b1\u1d52\u1d48)  h\n#align filter.bliminf_congr' Filter.bliminf_congr'\n\ntheorem blimsup_eq_inf\u1d62_bsup\u1d62 {f : Filter \u03b2} {p : \u03b2 \u2192 Prop} {u : \u03b2 \u2192 \u03b1} :\n    blimsup u f p = \u2a05 s \u2208 f, \u2a06 (b) (_hb : p b \u2227 b \u2208 s), u b := by\n  refine' le_antisymm (inf\u209b_le_inf\u209b _) (inf\u1d62_le_iff.mpr fun a ha => le_inf\u209b_iff.mpr fun a' ha' => _)\n  \u00b7 rintro - \u27e8s, rfl\u27e9\n    simp only [mem_setOf_eq, le_inf\u1d62_iff]\n    conv =>\n      congr\n      ext\n      rw [Imp.swap]\n    refine'\n      eventually_imp_distrib_left.mpr fun h => eventually_iff_exists_mem.2 \u27e8s, h, fun x h\u2081 h\u2082 => _\u27e9\n    exact @le_sup\u1d62\u2082 \u03b1 \u03b2 (fun b => p b \u2227 b \u2208 s) _ (fun b _ => u b) x \u27e8h\u2082, h\u2081\u27e9\n  \u00b7 obtain \u27e8s, hs, hs'\u27e9 := eventually_iff_exists_mem.mp ha'\n    have : \u2200 (y : \u03b2), p y \u2192 y \u2208 s \u2192 u y \u2264 a' := fun y \u21a6 by rw [Imp.swap]; exact hs' y\n    exact (le_inf\u1d62_iff.mp (ha s) hs).trans (by simpa only [sup\u1d62\u2082_le_iff, and_imp] )\n#align filter.blimsup_eq_infi_bsupr Filter.blimsup_eq_inf\u1d62_bsup\u1d62\n\ntheorem blimsup_eq_inf\u1d62_bsup\u1d62_of_nat {p : \u2115 \u2192 Prop} {u : \u2115 \u2192 \u03b1} :\n    blimsup u atTop p = \u2a05 i, \u2a06 (j) (_hj : p j \u2227 i \u2264 j), u j := by\n  -- Porting note: Making this into a single simp only does not work?\n  simp only [blimsup_eq_limsup_subtype, Function.comp,\n    (atTop_basis.comap ((\u2191) : { x | p x } \u2192 \u2115)).limsup_eq_inf\u1d62_sup\u1d62, sup\u1d62_subtype, sup\u1d62_and]\n  simp only [mem_setOf_eq, mem_preimage, mem_Ici, not_le, inf\u1d62_pos]\n#align filter.blimsup_eq_infi_bsupr_of_nat Filter.blimsup_eq_inf\u1d62_bsup\u1d62_of_nat\n\n/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter\nof the supremum of the function over `s` -/\ntheorem liminf_eq_sup\u1d62_inf\u1d62 {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1} : liminf u f = \u2a06 s \u2208 f, \u2a05 a \u2208 s, u a :=\n  @limsup_eq_inf\u1d62_sup\u1d62 \u03b1\u1d52\u1d48 \u03b2 _ _ _\n#align filter.liminf_eq_supr_infi Filter.liminf_eq_sup\u1d62_inf\u1d62\n\ntheorem liminf_eq_sup\u1d62_inf\u1d62_of_nat {u : \u2115 \u2192 \u03b1} : liminf u atTop = \u2a06 n : \u2115, \u2a05 i \u2265 n, u i :=\n  @limsup_eq_inf\u1d62_sup\u1d62_of_nat \u03b1\u1d52\u1d48 _ u\n#align filter.liminf_eq_supr_infi_of_nat Filter.liminf_eq_sup\u1d62_inf\u1d62_of_nat\n\ntheorem liminf_eq_sup\u1d62_inf\u1d62_of_nat' {u : \u2115 \u2192 \u03b1} : liminf u atTop = \u2a06 n : \u2115, \u2a05 i : \u2115, u (i + n) :=\n  @limsup_eq_inf\u1d62_sup\u1d62_of_nat' \u03b1\u1d52\u1d48 _ _\n#align filter.liminf_eq_supr_infi_of_nat' Filter.liminf_eq_sup\u1d62_inf\u1d62_of_nat'\n\ntheorem HasBasis.liminf_eq_sup\u1d62_inf\u1d62 {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 Set \u03b2} {f : Filter \u03b2} {u : \u03b2 \u2192 \u03b1}\n    (h : f.HasBasis p s) : liminf u f = \u2a06 (i) (_hi : p i), \u2a05 a \u2208 s i, u a :=\n  @HasBasis.limsup_eq_inf\u1d62_sup\u1d62 \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ h\n#align filter.has_basis.liminf_eq_supr_infi Filter.HasBasis.liminf_eq_sup\u1d62_inf\u1d62\n\ntheorem bliminf_eq_sup\u1d62_binf\u1d62 {f : Filter \u03b2} {p : \u03b2 \u2192 Prop} {u : \u03b2 \u2192 \u03b1} :\n    bliminf u f p = \u2a06 s \u2208 f, \u2a05 (b) (_hb : p b \u2227 b \u2208 s), u b :=\n  @blimsup_eq_inf\u1d62_bsup\u1d62 \u03b1\u1d52\u1d48 \u03b2 _ f p u\n#align filter.bliminf_eq_supr_binfi Filter.bliminf_eq_sup\u1d62_binf\u1d62\n\ntheorem bliminf_eq_sup\u1d62_binf\u1d62_of_nat {p : \u2115 \u2192 Prop} {u : \u2115 \u2192 \u03b1} :\n    bliminf u atTop p = \u2a06 i, \u2a05 (j) (_hj : p j \u2227 i \u2264 j), u j :=\n  @blimsup_eq_inf\u1d62_bsup\u1d62_of_nat \u03b1\u1d52\u1d48 _ p u\n#align filter.bliminf_eq_supr_binfi_of_nat Filter.bliminf_eq_sup\u1d62_binf\u1d62_of_nat\n\ntheorem limsup_eq_inf\u209b_sup\u209b {\u03b9 R : Type _} (F : Filter \u03b9) [CompleteLattice R] (a : \u03b9 \u2192 R) :\n    limsup a F = inf\u209b ((fun I => sup\u209b (a '' I)) '' F.sets) := by\n  refine' le_antisymm _ _\n  \u00b7 rw [limsup_eq]\n    refine' inf\u209b_le_inf\u209b fun x hx => _\n    rcases(mem_image _ F.sets x).mp hx with \u27e8I, \u27e8I_mem_F, hI\u27e9\u27e9\n    filter_upwards [I_mem_F]with i hi\n    exact hI \u25b8 le_sup\u209b (mem_image_of_mem _ hi)\n  \u00b7 refine'\n      le_inf\u209b_iff.mpr fun b hb =>\n        inf\u209b_le_of_le (mem_image_of_mem _ <| Filter.mem_sets.mpr hb) <| sup\u209b_le _\n    rintro _ \u27e8_, h, rfl\u27e9\n    exact h\nset_option linter.uppercaseLean3 false in\n#align filter.limsup_eq_Inf_Sup Filter.limsup_eq_inf\u209b_sup\u209b\n\ntheorem liminf_eq_sup\u209b_inf\u209b {\u03b9 R : Type _} (F : Filter \u03b9) [CompleteLattice R] (a : \u03b9 \u2192 R) :\n    liminf a F = sup\u209b ((fun I => inf\u209b (a '' I)) '' F.sets) :=\n  @Filter.limsup_eq_inf\u209b_sup\u209b \u03b9 (OrderDual R) _ _ a\nset_option linter.uppercaseLean3 false in\n#align filter.liminf_eq_Sup_Inf Filter.liminf_eq_sup\u209b_inf\u209b\n\n-- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself.\n@[simp, nolint simpNF]\ntheorem liminf_nat_add (f : \u2115 \u2192 \u03b1) (k : \u2115) : liminf (fun i => f (i + k)) atTop = liminf f atTop :=\n  by\n  simp_rw [liminf_eq_sup\u1d62_inf\u1d62_of_nat]\n  exact sup\u1d62_inf\u1d62_ge_nat_add f k\n#align filter.liminf_nat_add Filter.liminf_nat_add\n\n-- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself.\n@[simp, nolint simpNF]\ntheorem limsup_nat_add (f : \u2115 \u2192 \u03b1) (k : \u2115) : limsup (fun i => f (i + k)) atTop = limsup f atTop :=\n  @liminf_nat_add \u03b1\u1d52\u1d48 _ f k\n#align filter.limsup_nat_add Filter.limsup_nat_add\n\ntheorem liminf_le_of_frequently_le' {\u03b1 \u03b2} [CompleteLattice \u03b2] {f : Filter \u03b1} {u : \u03b1 \u2192 \u03b2} {x : \u03b2}\n    (h : \u2203\u1da0 a in f, u a \u2264 x) : liminf u f \u2264 x := by\n  rw [liminf_eq]\n  refine' sup\u209b_le fun b hb => _\n  have hbx : \u2203\u1da0 _a in f, b \u2264 x := by\n    revert h\n    rw [\u2190 not_imp_not, not_frequently, not_frequently]\n    exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax))\n  exact hbx.exists.choose_spec\n#align filter.liminf_le_of_frequently_le' Filter.liminf_le_of_frequently_le'\n\ntheorem le_limsup_of_frequently_le' {\u03b1 \u03b2} [CompleteLattice \u03b2] {f : Filter \u03b1} {u : \u03b1 \u2192 \u03b2} {x : \u03b2}\n    (h : \u2203\u1da0 a in f, x \u2264 u a) : x \u2264 limsup u f :=\n  @liminf_le_of_frequently_le' _ \u03b2\u1d52\u1d48 _ _ _ _ h\n#align filter.le_limsup_of_frequently_le' Filter.le_limsup_of_frequently_le'\n\n/-- If `f : \u03b1 \u2192 \u03b1` is a morphism of complete lattices, then the limsup of its iterates of any\n`a : \u03b1` is a fixed point. -/\n@[simp]\ntheorem CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom \u03b1 \u03b1) (a : \u03b1) :\n    f (limsup (fun n => (f^[n]) a) atTop) = limsup (fun n => (f^[n]) a) atTop := by\n  rw [limsup_eq_inf\u1d62_sup\u1d62_of_nat', map_inf\u1d62]\n  simp_rw [_root_.map_sup\u1d62, \u2190 Function.comp_apply (f := f), \u2190 Function.iterate_succ' f,\n    \u2190 Nat.add_succ]\n  conv_rhs => rw [inf\u1d62_split _ ((\u00b7 < \u00b7) (0 : \u2115))]\n  simp only [not_lt, le_zero_iff, inf\u1d62_inf\u1d62_eq_left, add_zero, inf\u1d62_nat_gt_zero_eq, left_eq_inf]\n  refine' (inf\u1d62_le (fun i => \u2a06 j, (f^[j + (i + 1)]) a) 0).trans _\n  simp only [zero_add, Function.comp_apply, sup\u1d62_le_iff]\n  exact fun i => le_sup\u1d62 (fun i => (f^[i]) a) (i + 1)\n#align filter.complete_lattice_hom.apply_limsup_iterate Filter.CompleteLatticeHom.apply_limsup_iterate\n\n/-- If `f : \u03b1 \u2192 \u03b1` is a morphism of complete lattices, then the liminf of its iterates of any\n`a : \u03b1` is a fixed point. -/\ntheorem CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom \u03b1 \u03b1) (a : \u03b1) :\n    f (liminf (fun n => (f^[n]) a) atTop) = liminf (fun n => (f^[n]) a) atTop :=\n  apply_limsup_iterate (CompleteLatticeHom.dual f) _\n#align filter.complete_lattice_hom.apply_liminf_iterate Filter.CompleteLatticeHom.apply_liminf_iterate\n\nvariable {f g : Filter \u03b2} {p q : \u03b2 \u2192 Prop} {u v : \u03b2 \u2192 \u03b1}\n\ntheorem blimsup_mono (h : \u2200 x, p x \u2192 q x) : blimsup u f p \u2264 blimsup u f q :=\n  inf\u209b_le_inf\u209b fun a ha => ha.mono <| by tauto\n#align filter.blimsup_mono Filter.blimsup_mono\n\ntheorem bliminf_antitone (h : \u2200 x, p x \u2192 q x) : bliminf u f q \u2264 bliminf u f p :=\n  sup\u209b_le_sup\u209b fun a ha => ha.mono <| by tauto\n#align filter.bliminf_antitone Filter.bliminf_antitone\n\ntheorem mono_blimsup' (h : \u2200\u1da0 x in f, p x \u2192 u x \u2264 v x) : blimsup u f p \u2264 blimsup v f p :=\n  inf\u209b_le_inf\u209b fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx')\n#align filter.mono_blimsup' Filter.mono_blimsup'\n\ntheorem mono_blimsup (h : \u2200 x, p x \u2192 u x \u2264 v x) : blimsup u f p \u2264 blimsup v f p :=\n  mono_blimsup' <| eventually_of_forall h\n#align filter.mono_blimsup Filter.mono_blimsup\n\ntheorem mono_bliminf' (h : \u2200\u1da0 x in f, p x \u2192 u x \u2264 v x) : bliminf u f p \u2264 bliminf v f p :=\n  sup\u209b_le_sup\u209b fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx')\n#align filter.mono_bliminf' Filter.mono_bliminf'\n\ntheorem mono_bliminf (h : \u2200 x, p x \u2192 u x \u2264 v x) : bliminf u f p \u2264 bliminf v f p :=\n  mono_bliminf' <| eventually_of_forall h\n#align filter.mono_bliminf Filter.mono_bliminf\n\ntheorem bliminf_antitone_filter (h : f \u2264 g) : bliminf u g p \u2264 bliminf u f p :=\n  sup\u209b_le_sup\u209b fun _ ha => ha.filter_mono h\n#align filter.bliminf_antitone_filter Filter.bliminf_antitone_filter\n\ntheorem blimsup_monotone_filter (h : f \u2264 g) : blimsup u f p \u2264 blimsup u g p :=\n  inf\u209b_le_inf\u209b fun _ ha => ha.filter_mono h\n#align filter.blimsup_monotone_filter Filter.blimsup_monotone_filter\n\n\n-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux versions below\ntheorem blimsup_and_le_inf : (blimsup u f fun x => p x \u2227 q x) \u2264 blimsup u f p \u2293 blimsup u f q :=\n  le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)\n#align filter.blimsup_and_le_inf Filter.blimsup_and_le_inf\n\n@[simp]\ntheorem bliminf_sup_le_inf_aux_left :\n  (blimsup u f fun x => p x \u2227 q x) \u2264 blimsup u f p :=\n  blimsup_and_le_inf.trans inf_le_left\n\n@[simp]\ntheorem bliminf_sup_le_inf_aux_right :\n    (blimsup u f fun x => p x \u2227 q x) \u2264 blimsup u f q :=\n  blimsup_and_le_inf.trans inf_le_right\n\n-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp version below\ntheorem bliminf_sup_le_and : bliminf u f p \u2294 bliminf u f q \u2264 bliminf u f fun x => p x \u2227 q x :=\n  blimsup_and_le_inf (\u03b1 := \u03b1\u1d52\u1d48)\n#align filter.bliminf_sup_le_and Filter.bliminf_sup_le_and\n\n@[simp]\ntheorem bliminf_sup_le_and_aux_left : bliminf u f p \u2264 bliminf u f fun x => p x \u2227 q x :=\n  le_sup_left.trans bliminf_sup_le_and\n\n@[simp]\ntheorem bliminf_sup_le_and_aux_right : bliminf u f q \u2264 bliminf u f fun x => p x \u2227 q x :=\n  le_sup_right.trans bliminf_sup_le_and\n\n/-- See also `Filter.blimsup_or_eq_sup`. -/\n-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp versions below\ntheorem blimsup_sup_le_or : blimsup u f p \u2294 blimsup u f q \u2264 blimsup u f fun x => p x \u2228 q x :=\n  sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)\n#align filter.blimsup_sup_le_or Filter.blimsup_sup_le_or\n\n@[simp]\ntheorem bliminf_sup_le_or_aux_left : blimsup u f p \u2264 blimsup u f fun x => p x \u2228 q x :=\n  le_sup_left.trans blimsup_sup_le_or\n\n@[simp]\ntheorem bliminf_sup_le_or_aux_right : blimsup u f q \u2264 blimsup u f fun x => p x \u2228 q x :=\n  le_sup_right.trans blimsup_sup_le_or\n\n/-- See also `Filter.bliminf_or_eq_inf`. -/\n--@[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp versions below\ntheorem bliminf_or_le_inf : (bliminf u f fun x => p x \u2228 q x) \u2264 bliminf u f p \u2293 bliminf u f q :=\n  blimsup_sup_le_or (\u03b1 := \u03b1\u1d52\u1d48)\n#align filter.bliminf_or_le_inf Filter.bliminf_or_le_inf\n\n@[simp]\ntheorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x \u2228 q x) \u2264 bliminf u f p :=\n  bliminf_or_le_inf.trans inf_le_left\n\n@[simp]\n\n\n/- Porting note: Replaced `e` with `FunLike.coe e` to override the strange\n coercion to `\u2191(RelIso.toRelEmbedding e).toEmbedding`.-/\ntheorem OrderIso.apply_blimsup [CompleteLattice \u03b3] (e : \u03b1 \u2243o \u03b3) :\n    FunLike.coe e (blimsup u f p) = blimsup ((FunLike.coe e) \u2218 u) f p := by\n  simp only [blimsup_eq, map_inf\u209b, Function.comp_apply]\n  congr\n  ext c\n  obtain \u27e8a, rfl\u27e9 := e.surjective c\n  -- Porting note: Also needed to add this next line\n  have : \u2191(RelIso.toRelEmbedding e).toEmbedding = FunLike.coe e := rfl\n  simp [this]\n#align filter.order_iso.apply_blimsup Filter.OrderIso.apply_blimsup\n\ntheorem OrderIso.apply_bliminf [CompleteLattice \u03b3] (e : \u03b1 \u2243o \u03b3) :\n    e (bliminf u f p) = bliminf (e \u2218 u) f p :=\n  OrderIso.apply_blimsup (\u03b1 := \u03b1\u1d52\u1d48) (\u03b3 := \u03b3\u1d52\u1d48) e.dual\n#align filter.order_iso.apply_bliminf Filter.OrderIso.apply_bliminf\n\ntheorem SupHom.apply_blimsup_le [CompleteLattice \u03b3] (g : Sup\u209bHom \u03b1 \u03b3) :\n    g (blimsup u f p) \u2264 blimsup (g \u2218 u) f p := by\n  simp only [blimsup_eq_inf\u1d62_bsup\u1d62, Function.comp]\n  refine' ((OrderHomClass.mono g).map_inf\u1d62\u2082_le _).trans _\n  simp only [_root_.map_sup\u1d62, le_refl]\n#align filter.Sup_hom.apply_blimsup_le Filter.SupHom.apply_blimsup_le\n\ntheorem InfHom.le_apply_bliminf [CompleteLattice \u03b3] (g : Inf\u209bHom \u03b1 \u03b3) :\n    bliminf (g \u2218 u) f p \u2264 g (bliminf u f p) :=\n  SupHom.apply_blimsup_le (\u03b1 := \u03b1\u1d52\u1d48) (\u03b3 := \u03b3\u1d52\u1d48) (Inf\u209bHom.dual g)\n#align filter.Inf_hom.le_apply_bliminf Filter.InfHom.le_apply_bliminf\n\nend CompleteLattice\n\nsection CompleteDistribLattice\n\nvariable [CompleteDistribLattice \u03b1] {f : Filter \u03b2} {p q : \u03b2 \u2192 Prop} {u : \u03b2 \u2192 \u03b1}\n\n@[simp]\ntheorem blimsup_or_eq_sup : (blimsup u f fun x => p x \u2228 q x) = blimsup u f p \u2294 blimsup u f q := by\n  refine' le_antisymm _ blimsup_sup_le_or\n  simp only [blimsup_eq, inf\u209b_sup_eq, sup_inf\u209b_eq, le_inf\u1d62\u2082_iff, mem_setOf_eq]\n  refine' fun a' ha' a ha => inf\u209b_le ((ha.and ha').mono fun b h hb => _)\n  exact Or.elim hb (fun hb => le_sup_of_le_left <| h.1 hb) fun hb => le_sup_of_le_right <| h.2 hb\n#align filter.blimsup_or_eq_sup Filter.blimsup_or_eq_sup\n\n@[simp]\ntheorem bliminf_or_eq_inf : (bliminf u f fun x => p x \u2228 q x) = bliminf u f p \u2293 bliminf u f q :=\n  blimsup_or_eq_sup (\u03b1 := \u03b1\u1d52\u1d48)\n#align filter.bliminf_or_eq_inf Filter.bliminf_or_eq_inf\n\ntheorem sup_limsup [NeBot f] (a : \u03b1) : a \u2294 limsup u f = limsup (fun x => a \u2294 u x) f := by\n  simp only [limsup_eq_inf\u1d62_sup\u1d62, sup\u1d62_sup_eq, sup_inf\u1d62\u2082_eq]\n  congr ; ext s; congr ; ext hs; congr\n  exact (bsup\u1d62_const (nonempty_of_mem hs)).symm\n#align filter.sup_limsup Filter.sup_limsup\n\ntheorem inf_liminf [NeBot f] (a : \u03b1) : a \u2293 liminf u f = liminf (fun x => a \u2293 u x) f :=\n  sup_limsup (\u03b1 := \u03b1\u1d52\u1d48) a\n#align filter.inf_liminf Filter.inf_liminf\n\ntheorem sup_liminf (a : \u03b1) : a \u2294 liminf u f = liminf (fun x => a \u2294 u x) f := by\n  simp only [liminf_eq_sup\u1d62_inf\u1d62]\n  rw [sup_comm, bsup\u1d62_sup (\u27e8univ, univ_mem\u27e9 : \u2203 i : Set \u03b2, i \u2208 f)]\n  simp_rw [inf\u1d62\u2082_sup_eq, sup_comm (a := a)]\n#align filter.sup_liminf Filter.sup_liminf\n\ntheorem inf_limsup (a : \u03b1) : a \u2293 limsup u f = limsup (fun x => a \u2293 u x) f :=\n  sup_liminf (\u03b1 := \u03b1\u1d52\u1d48) a\n#align filter.inf_limsup Filter.inf_limsup\n\nend CompleteDistribLattice\n\nsection CompleteBooleanAlgebra\n\nvariable [CompleteBooleanAlgebra \u03b1] (f : Filter \u03b2) (u : \u03b2 \u2192 \u03b1)\n\ntheorem limsup_compl : limsup u f\u1d9c = liminf (compl \u2218 u) f := by\n  simp only [limsup_eq_inf\u1d62_sup\u1d62, compl_inf\u1d62, compl_sup\u1d62, liminf_eq_sup\u1d62_inf\u1d62, Function.comp_apply]\n#align filter.limsup_compl Filter.limsup_compl\n\ntheorem liminf_compl : liminf u f\u1d9c = limsup (compl \u2218 u) f := by\n  simp only [limsup_eq_inf\u1d62_sup\u1d62, compl_inf\u1d62, compl_sup\u1d62, liminf_eq_sup\u1d62_inf\u1d62, Function.comp_apply]\n#align filter.liminf_compl Filter.liminf_compl\n\ntheorem limsup_sdiff (a : \u03b1) : limsup u f \\ a = limsup (fun b => u b \\ a) f := by\n  simp only [limsup_eq_inf\u1d62_sup\u1d62, sdiff_eq]\n  rw [binf\u1d62_inf (\u27e8univ, univ_mem\u27e9 : \u2203 i : Set \u03b2, i \u2208 f)]\n  simp_rw [inf_comm, inf_sup\u1d62\u2082_eq, inf_comm]\n#align filter.limsup_sdiff Filter.limsup_sdiff\n\ntheorem liminf_sdiff [NeBot f] (a : \u03b1) : liminf u f \\ a = liminf (fun b => u b \\ a) f := by\n  simp only [sdiff_eq, inf_comm (b := a\u1d9c), inf_liminf]\n#align filter.liminf_sdiff Filter.liminf_sdiff\n\ntheorem sdiff_limsup [NeBot f] (a : \u03b1) : a \\ limsup u f = liminf (fun b => a \\ u b) f := by\n  rw [\u2190 compl_inj_iff]\n  simp only [sdiff_eq, liminf_compl, (\u00b7 \u2218 \u00b7), compl_inf, compl_compl, sup_limsup]\n#align filter.sdiff_limsup Filter.sdiff_limsup\n\ntheorem sdiff_liminf (a : \u03b1) : a \\ liminf u f = limsup (fun b => a \\ u b) f := by\n  rw [\u2190 compl_inj_iff]\n  simp only [sdiff_eq, limsup_compl, (\u00b7 \u2218 \u00b7), compl_inf, compl_compl, sup_liminf]\n#align filter.sdiff_liminf Filter.sdiff_liminf\n\nend CompleteBooleanAlgebra\n\nsection SetLattice\n\nvariable {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 Set \u03b1}\n\ntheorem cofinite.blimsup_set_eq : blimsup s cofinite p = { x | { n | p n \u2227 x \u2208 s n }.Infinite } :=\n  by\n  simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, inf\u209b_eq_inter\u209b, exists_prop]\n  ext x\n  refine' \u27e8fun h => _, fun hx t h => _\u27e9 <;> contrapose! h\n  \u00b7 simp only [mem_inter\u209b, mem_setOf_eq, not_forall, exists_prop]\n    exact \u27e8{x}\u1d9c, by simpa using h, by simp\u27e9\n  \u00b7 exact hx.mono fun i hi => \u27e8hi.1, fun hit => h (hit hi.2)\u27e9\n#align filter.cofinite.blimsup_set_eq Filter.cofinite.blimsup_set_eq\n\ntheorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n \u2227 x \u2209 s n }.Finite } := by\n  rw [\u2190 compl_inj_iff]\n  simp only [bliminf_eq_sup\u1d62_binf\u1d62, compl_inf\u1d62, compl_sup\u1d62, \u2190 blimsup_eq_inf\u1d62_bsup\u1d62,\n    cofinite.blimsup_set_eq]\n  rfl\n#align filter.cofinite.bliminf_set_eq Filter.cofinite.bliminf_set_eq\n\n/-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s`\ninfinitely often. -/\ntheorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x \u2208 s n }.Infinite } := by\n  simp only [\u2190 cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and_iff]\n#align filter.cofinite.limsup_set_eq Filter.cofinite.limsup_set_eq\n\n/-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s`\nfinitely often. -/\ntheorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x \u2209 s n }.Finite } := by\n  simp only [\u2190 cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and_iff]\n#align filter.cofinite.liminf_set_eq Filter.cofinite.liminf_set_eq\n\ntheorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter \u03b2} {b : \u03b9 \u2192 Set \u03b2} {q : \u03b9 \u2192 Prop}\n    (hl : l.HasBasis q b) {u : \u03b2 \u2192 Set \u03b1} {p : \u03b2 \u2192 Prop} {x : \u03b1} (hx : x \u2208 blimsup u l p) :\n    \u2203 f : { i | q i } \u2192 \u03b2, \u2200 i, x \u2208 u (f i) \u2227 p (f i) \u2227 f i \u2208 b i := by\n  rw [blimsup_eq_inf\u1d62_bsup\u1d62] at hx\n  simp only [sup\u1d62_eq_union\u1d62, inf\u1d62_eq_inter\u1d62, mem_inter\u1d62, mem_union\u1d62, exists_prop] at hx\n  choose g hg hg' using hx\n  refine' \u27e8fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => \u27e8_, _\u27e9\u27e9\n  \u00b7 exact hg' (b i) (hl.mem_of_mem i.2)\n  \u00b7 exact hg (b i) (hl.mem_of_mem i.2)\n#align filter.exists_forall_mem_of_has_basis_mem_blimsup Filter.exists_forall_mem_of_hasBasis_mem_blimsup\n\ntheorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter \u03b2} {b : \u03b9 \u2192 Set \u03b2}\n    (hl : l.HasBasis (fun _ => True) b) {u : \u03b2 \u2192 Set \u03b1} {p : \u03b2 \u2192 Prop} {x : \u03b1}\n    (hx : x \u2208 blimsup u l p) : \u2203 f : \u03b9 \u2192 \u03b2, \u2200 i, x \u2208 u (f i) \u2227 p (f i) \u2227 f i \u2208 b i := by\n  obtain \u27e8f, hf\u27e9 := exists_forall_mem_of_hasBasis_mem_blimsup hl hx\n  exact \u27e8fun i => f \u27e8i, trivial\u27e9, fun i => hf \u27e8i, trivial\u27e9\u27e9\n#align filter.exists_forall_mem_of_has_basis_mem_blimsup' Filter.exists_forall_mem_of_hasBasis_mem_blimsup'\n\nend SetLattice\n\nsection ConditionallyCompleteLinearOrder\n\ntheorem frequently_lt_of_lt_limsup\u209b {f : Filter \u03b1} [ConditionallyCompleteLinearOrder \u03b1] {a : \u03b1}\n    (hf : f.IsCobounded (\u00b7 \u2264 \u00b7) := by isBoundedDefault)\n    (h : a < limsup\u209b f) : \u2203\u1da0 n in f, a < n := by\n  contrapose! h\n  simp only [not_frequently, not_lt] at h\n  exact limsup\u209b_le_of_le hf h\nset_option linter.uppercaseLean3 false in\n#align filter.frequently_lt_of_lt_Limsup Filter.frequently_lt_of_lt_limsup\u209b\n\ntheorem frequently_lt_of_liminf\u209b_lt {f : Filter \u03b1} [ConditionallyCompleteLinearOrder \u03b1] {a : \u03b1}\n    (hf : f.IsCobounded (\u00b7 \u2265 \u00b7) := by isBoundedDefault)\n    (h : liminf\u209b f < a) : \u2203\u1da0 n in f, n < a :=\n  frequently_lt_of_lt_limsup\u209b (\u03b1 := OrderDual \u03b1) hf h\nset_option linter.uppercaseLean3 false in\n#align filter.frequently_lt_of_Liminf_lt Filter.frequently_lt_of_liminf\u209b_lt\n\ntheorem eventually_lt_of_lt_liminf {f : Filter \u03b1} [ConditionallyCompleteLinearOrder \u03b2] {u : \u03b1 \u2192 \u03b2}\n    {b : \u03b2} (h : b < liminf u f)\n    (hu : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault) :\n    \u2200\u1da0 a in f, b < u a := by\n  obtain \u27e8c, hc, hbc\u27e9 : \u2203 (c : \u03b2) (_ : c \u2208 { c : \u03b2 | \u2200\u1da0 n : \u03b1 in f, c \u2264 u n }), b < c := by\n    simp_rw [exists_prop]\n    exact exists_lt_of_lt_csup\u209b hu h\n  exact hc.mono fun x hx => lt_of_lt_of_le hbc hx\n#align filter.eventually_lt_of_lt_liminf Filter.eventually_lt_of_lt_liminf\n\ntheorem eventually_lt_of_limsup_lt {f : Filter \u03b1} [ConditionallyCompleteLinearOrder \u03b2] {u : \u03b1 \u2192 \u03b2}\n    {b : \u03b2} (h : limsup u f < b)\n    (hu : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault) :\n    \u2200\u1da0 a in f, u a < b :=\n  eventually_lt_of_lt_liminf (\u03b2 := \u03b2\u1d52\u1d48) h hu\n#align filter.eventually_lt_of_limsup_lt Filter.eventually_lt_of_limsup_lt\n\ntheorem le_limsup_of_frequently_le {\u03b1 \u03b2} [ConditionallyCompleteLinearOrder \u03b2] {f : Filter \u03b1}\n    {u : \u03b1 \u2192 \u03b2} {b : \u03b2} (hu_le : \u2203\u1da0 x in f, b \u2264 u x)\n    (hu : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault) :\n    b \u2264 limsup u f := by\n  revert hu_le\n  rw [\u2190 not_imp_not, not_frequently]\n  simp_rw [\u2190 lt_iff_not_ge]\n  exact fun h => eventually_lt_of_limsup_lt h hu\n#align filter.le_limsup_of_frequently_le Filter.le_limsup_of_frequently_le\n\ntheorem liminf_le_of_frequently_le {\u03b1 \u03b2} [ConditionallyCompleteLinearOrder \u03b2] {f : Filter \u03b1}\n    {u : \u03b1 \u2192 \u03b2} {b : \u03b2} (hu_le : \u2203\u1da0 x in f, u x \u2264 b)\n    (hu : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault) :\n    liminf u f \u2264 b :=\n  le_limsup_of_frequently_le (\u03b2 := \u03b2\u1d52\u1d48) hu_le hu\n#align filter.liminf_le_of_frequently_le Filter.liminf_le_of_frequently_le\n\ntheorem frequently_lt_of_lt_limsup {\u03b1 \u03b2} [ConditionallyCompleteLinearOrder \u03b2] {f : Filter \u03b1}\n    {u : \u03b1 \u2192 \u03b2} {b : \u03b2}\n    (hu : f.IsCoboundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (h : b < limsup u f) : \u2203\u1da0 x in f, b < u x := by\n  contrapose! h\n  apply limsup\u209b_le_of_le hu\n  simpa using h\n#align filter.frequently_lt_of_lt_limsup Filter.frequently_lt_of_lt_limsup\n\ntheorem frequently_lt_of_liminf_lt {\u03b1 \u03b2} [ConditionallyCompleteLinearOrder \u03b2] {f : Filter \u03b1}\n    {u : \u03b1 \u2192 \u03b2} {b : \u03b2}\n    (hu : f.IsCoboundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault)\n    (h : liminf u f < b) : \u2203\u1da0 x in f, u x < b :=\n  frequently_lt_of_lt_limsup (\u03b2 := \u03b2\u1d52\u1d48) hu h\n#align filter.frequently_lt_of_liminf_lt Filter.frequently_lt_of_liminf_lt\n\nend ConditionallyCompleteLinearOrder\n\nend Filter\n\nsection Order\n\nopen Filter\n\ntheorem Monotone.isBoundedUnder_le_comp [Nonempty \u03b2] [LinearOrder \u03b2] [Preorder \u03b3] [NoMaxOrder \u03b3]\n    {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} {l : Filter \u03b1} (hg : Monotone g) (hg' : Tendsto g atTop atTop) :\n    IsBoundedUnder (\u00b7 \u2264 \u00b7) l (g \u2218 f) \u2194 IsBoundedUnder (\u00b7 \u2264 \u00b7) l f := by\n  refine' \u27e8_, fun h => h.isBoundedUnder (\u03b1 := \u03b2) hg\u27e9\n  rintro \u27e8c, hc\u27e9; rw [eventually_map] at hc\n  obtain \u27e8b, hb\u27e9 : \u2203 b, \u2200 a \u2265 b, c < g a := eventually_atTop.1 (hg'.eventually_gt_atTop c)\n  exact \u27e8b, hc.mono fun x hx => not_lt.1 fun h => (hb _ h.le).not_le hx\u27e9\n#align monotone.is_bounded_under_le_comp Monotone.isBoundedUnder_le_comp\n\ntheorem Monotone.isBoundedUnder_ge_comp [Nonempty \u03b2] [LinearOrder \u03b2] [Preorder \u03b3] [NoMinOrder \u03b3]\n    {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} {l : Filter \u03b1} (hg : Monotone g) (hg' : Tendsto g atBot atBot) :\n    IsBoundedUnder (\u00b7 \u2265 \u00b7) l (g \u2218 f) \u2194 IsBoundedUnder (\u00b7 \u2265 \u00b7) l f :=\n  hg.dual.isBoundedUnder_le_comp hg'\n#align monotone.is_bounded_under_ge_comp Monotone.isBoundedUnder_ge_comp\n\ntheorem Antitone.isBoundedUnder_le_comp [Nonempty \u03b2] [LinearOrder \u03b2] [Preorder \u03b3] [NoMaxOrder \u03b3]\n    {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} {l : Filter \u03b1} (hg : Antitone g) (hg' : Tendsto g atBot atTop) :\n    IsBoundedUnder (\u00b7 \u2264 \u00b7) l (g \u2218 f) \u2194 IsBoundedUnder (\u00b7 \u2265 \u00b7) l f :=\n  hg.dual_right.isBoundedUnder_ge_comp hg'\n#align antitone.is_bounded_under_le_comp Antitone.isBoundedUnder_le_comp\n\ntheorem Antitone.isBoundedUnder_ge_comp [Nonempty \u03b2] [LinearOrder \u03b2] [Preorder \u03b3] [NoMinOrder \u03b3]\n    {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} {l : Filter \u03b1} (hg : Antitone g) (hg' : Tendsto g atTop atBot) :\n    IsBoundedUnder (\u00b7 \u2265 \u00b7) l (g \u2218 f) \u2194 IsBoundedUnder (\u00b7 \u2264 \u00b7) l f :=\n  hg.dual_right.isBoundedUnder_le_comp hg'\n#align antitone.is_bounded_under_ge_comp Antitone.isBoundedUnder_ge_comp\n\ntheorem GaloisConnection.l_limsup_le [ConditionallyCompleteLattice \u03b2]\n    [ConditionallyCompleteLattice \u03b3] {f : Filter \u03b1} {v : \u03b1 \u2192 \u03b2} {l : \u03b2 \u2192 \u03b3} {u : \u03b3 \u2192 \u03b2}\n    (gc : GaloisConnection l u)\n    (hlv : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) fun x => l (v x) := by isBoundedDefault)\n    (hv_co : f.IsCoboundedUnder (\u00b7 \u2264 \u00b7) v := by isBoundedDefault) :\n    l (limsup v f) \u2264 limsup (fun x => l (v x)) f := by\n  refine' le_limsup\u209b_of_le hlv fun c hc => _\n  rw [Filter.eventually_map] at hc\n  simp_rw [gc _ _] at hc\u22a2\n  exact limsup\u209b_le_of_le hv_co hc\n#align galois_connection.l_limsup_le GaloisConnection.l_limsup_le\n\ntheorem OrderIso.limsup_apply {\u03b3} [ConditionallyCompleteLattice \u03b2] [ConditionallyCompleteLattice \u03b3]\n    {f : Filter \u03b1} {u : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2243o \u03b3)\n    (hu : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (hu_co : f.IsCoboundedUnder (\u00b7 \u2264 \u00b7) u := by isBoundedDefault)\n    (hgu : f.IsBoundedUnder (\u00b7 \u2264 \u00b7) fun x => g (u x) := by isBoundedDefault)\n    (hgu_co : f.IsCoboundedUnder (\u00b7 \u2264 \u00b7) fun x => g (u x) := by isBoundedDefault) :\n    g (limsup u f) = limsup (fun x => g (u x)) f := by\n  refine' le_antisymm ((OrderIso.to_galoisConnection g).l_limsup_le hgu hu_co) _\n  rw [\u2190 g.symm.symm_apply_apply <| limsup (fun x => g (u x)) f, g.symm_symm]\n  refine' g.monotone _\n  have hf : u = fun i => g.symm (g (u i)) := funext fun i => (g.symm_apply_apply (u i)).symm\n  -- Porting note: nth_rw 1 to nth_rw 2\n  nth_rw 2 [hf]\n  refine' (OrderIso.to_galoisConnection g.symm).l_limsup_le _ hgu_co\n  simp_rw [g.symm_apply_apply]\n  exact hu\n#align order_iso.limsup_apply OrderIso.limsup_apply\n\ntheorem OrderIso.liminf_apply {\u03b3} [ConditionallyCompleteLattice \u03b2] [ConditionallyCompleteLattice \u03b3]\n    {f : Filter \u03b1} {u : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2243o \u03b3)\n    (hu : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault)\n    (hu_co : f.IsCoboundedUnder (\u00b7 \u2265 \u00b7) u := by isBoundedDefault)\n    (hgu : f.IsBoundedUnder (\u00b7 \u2265 \u00b7) fun x => g (u x) := by isBoundedDefault)\n    (hgu_co : f.IsCoboundedUnder (\u00b7 \u2265 \u00b7) fun x => g (u x) := by isBoundedDefault) :\n    g (liminf u f) = liminf (fun x => g (u x)) f :=\n  OrderIso.limsup_apply (\u03b2 := \u03b2\u1d52\u1d48) (\u03b3 := \u03b3\u1d52\u1d48) g.dual hu hu_co hgu hgu_co\n#align order_iso.liminf_apply OrderIso.liminf_apply\n\nend Order\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/LiminfLimsup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.731222994164086}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport linear_algebra.affine_space.basic\nimport linear_algebra.tensor_product\nimport data.set.intervals.unordered_interval\n\n/-!\n# Affine spaces\n\nThis file defines affine subspaces (over modules) and the affine span of a set of points.\n\n## Main definitions\n\n* `affine_subspace k P` is the type of affine subspaces.  Unlike\n  affine spaces, affine subspaces are allowed to be empty, and lemmas\n  that do not apply to empty affine subspaces have `nonempty`\n  hypotheses.  There is a `complete_lattice` structure on affine\n  subspaces.\n* `affine_subspace.direction` gives the `submodule` spanned by the\n  pairwise differences of points in an `affine_subspace`.  There are\n  various lemmas relating to the set of vectors in the `direction`,\n  and relating the lattice structure on affine subspaces to that on\n  their directions.\n* `affine_span` gives the affine subspace spanned by a set of points,\n  with `vector_span` giving its direction.  `affine_span` is defined\n  in terms of `span_points`, which gives an explicit description of\n  the points contained in the affine span; `span_points` itself should\n  generally only be used when that description is required, with\n  `affine_span` being the main definition for other purposes.  Two\n  other descriptions of the affine span are proved equivalent: it is\n  the `Inf` of affine subspaces containing the points, and (if\n  `[nontrivial k]`) it contains exactly those points that are affine\n  combinations of points in the given set.\n\n## Implementation notes\n\n`out_param` is used in the definiton of `add_torsor V P` to make `V` an implicit argument (deduced\nfrom `P`) in most cases; `include V` is needed in many cases for `V`, and type classes using it, to\nbe added as implicit arguments to individual lemmas.  As for modules, `k` is an explicit argument\nrather than implied by `P` or `V`.\n\nThis file only provides purely algebraic definitions and results.\nThose depending on analysis or topology are defined elsewhere; see\n`analysis.normed_space.add_torsor` and `topology.algebra.affine`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Affine_space\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n-/\n\nnoncomputable theory\nopen_locale big_operators classical affine\n\nopen set\n\nsection\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\nvariables [affine_space V P]\ninclude V\n\n/-- The submodule spanning the differences of a (possibly empty) set\nof points. -/\ndef vector_span (s : set P) : submodule k V := submodule.span k (s -\u1d65 s)\n\n/-- The definition of `vector_span`, for rewriting. -/\nlemma vector_span_def (s : set P) : vector_span k s = submodule.span k (s -\u1d65 s) :=\nrfl\n\n/-- `vector_span` is monotone. -/\nlemma vector_span_mono {s\u2081 s\u2082 : set P} (h : s\u2081 \u2286 s\u2082) : vector_span k s\u2081 \u2264 vector_span k s\u2082 :=\nsubmodule.span_mono (vsub_self_mono h)\n\nvariables (P)\n\n/-- The `vector_span` of the empty set is `\u22a5`. -/\n@[simp] lemma vector_span_empty : vector_span k (\u2205 : set P) = (\u22a5 : submodule k V) :=\nby rw [vector_span_def, vsub_empty, submodule.span_empty]\n\nvariables {P}\n\n/-- The `vector_span` of a single point is `\u22a5`. -/\n@[simp] lemma vector_span_singleton (p : P) : vector_span k ({p} : set P) = \u22a5 :=\nby simp [vector_span_def]\n\n/-- The `s -\u1d65 s` lies within the `vector_span k s`. -/\nlemma vsub_set_subset_vector_span (s : set P) : s -\u1d65 s \u2286 \u2191(vector_span k s) :=\nsubmodule.subset_span\n\n/-- Each pairwise difference is in the `vector_span`. -/\nlemma vsub_mem_vector_span {s : set P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n  p1 -\u1d65 p2 \u2208 vector_span k s :=\nvsub_set_subset_vector_span k s (vsub_mem_vsub hp1 hp2)\n\n/-- The points in the affine span of a (possibly empty) set of\npoints. Use `affine_span` instead to get an `affine_subspace k P`. -/\ndef span_points (s : set P) : set P :=\n{p | \u2203 p1 \u2208 s, \u2203 v \u2208 (vector_span k s), p = v +\u1d65 p1}\n\n/-- A point in a set is in its affine span. -/\nlemma mem_span_points (p : P) (s : set P) : p \u2208 s \u2192 p \u2208 span_points k s\n| hp := \u27e8p, hp, 0, submodule.zero_mem _, (zero_vadd V p).symm\u27e9\n\n/-- A set is contained in its `span_points`. -/\nlemma subset_span_points (s : set P) : s \u2286 span_points k s :=\n\u03bb p, mem_span_points k p s\n\n/-- The `span_points` of a set is nonempty if and only if that set\nis. -/\n@[simp] lemma span_points_nonempty (s : set P) :\n  (span_points k s).nonempty \u2194 s.nonempty :=\nbegin\n  split,\n  { contrapose,\n    rw [set.not_nonempty_iff_eq_empty, set.not_nonempty_iff_eq_empty],\n    intro h,\n    simp [h, span_points] },\n  { exact \u03bb h, h.mono (subset_span_points _ _) }\nend\n\n/-- Adding a point in the affine span and a vector in the spanning\nsubmodule produces a point in the affine span. -/\nlemma vadd_mem_span_points_of_mem_span_points_of_mem_vector_span {s : set P} {p : P} {v : V}\n    (hp : p \u2208 span_points k s) (hv : v \u2208 vector_span k s) : v +\u1d65 p \u2208 span_points k s :=\nbegin\n  rcases hp with \u27e8p2, \u27e8hp2, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9,\n  rw [hv2p, vadd_vadd],\n  use [p2, hp2, v + v2, (vector_span k s).add_mem hv hv2, rfl]\nend\n\n/-- Subtracting two points in the affine span produces a vector in the\nspanning submodule. -/\nlemma vsub_mem_vector_span_of_mem_span_points_of_mem_span_points {s : set P} {p1 p2 : P}\n    (hp1 : p1 \u2208 span_points k s) (hp2 : p2 \u2208 span_points k s) :\n  p1 -\u1d65 p2 \u2208 vector_span k s :=\nbegin\n  rcases hp1 with \u27e8p1a, \u27e8hp1a, \u27e8v1, \u27e8hv1, hv1p\u27e9\u27e9\u27e9\u27e9,\n  rcases hp2 with \u27e8p2a, \u27e8hp2a, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9,\n  rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +\u1d65 p1a), vadd_vsub_assoc, add_comm, add_sub_assoc],\n  have hv1v2 : v1 - v2 \u2208 vector_span k s,\n  { rw sub_eq_add_neg,\n    apply (vector_span k s).add_mem hv1,\n    rw \u2190neg_one_smul k v2,\n    exact (vector_span k s).smul_mem (-1 : k) hv2 },\n  refine (vector_span k s).add_mem _ hv1v2,\n  exact vsub_mem_vector_span k hp1a hp2a\nend\n\nend\n\n/-- An `affine_subspace k P` is a subset of an `affine_space V P`\nthat, if not empty, has an affine space structure induced by a\ncorresponding subspace of the `module k V`. -/\nstructure affine_subspace (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V]\n    [module k V] [affine_space V P] :=\n(carrier : set P)\n(smul_vsub_vadd_mem : \u2200 (c : k) {p1 p2 p3 : P}, p1 \u2208 carrier \u2192 p2 \u2208 carrier \u2192 p3 \u2208 carrier \u2192\n  c \u2022 (p1 -\u1d65 p2 : V) +\u1d65 p3 \u2208 carrier)\n\nnamespace submodule\n\nvariables {k V : Type*} [ring k] [add_comm_group V] [module k V]\n\n/-- Reinterpret `p : submodule k V` as an `affine_subspace k V`. -/\ndef to_affine_subspace (p : submodule k V) : affine_subspace k V :=\n{ carrier := p,\n  smul_vsub_vadd_mem := \u03bb c p\u2081 p\u2082 p\u2083 h\u2081 h\u2082 h\u2083, p.add_mem (p.smul_mem _ (p.sub_mem h\u2081 h\u2082)) h\u2083 }\n\nend submodule\n\nnamespace affine_subspace\n\nvariables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\ninstance : has_coe (affine_subspace k P) (set P) := \u27e8carrier\u27e9\ninstance : has_mem P (affine_subspace k P) := \u27e8\u03bb p s, p \u2208 (s : set P)\u27e9\n\n/-- A point is in an affine subspace coerced to a set if and only if\nit is in that affine subspace. -/\n@[simp] lemma mem_coe (p : P) (s : affine_subspace k P) :\n  p \u2208 (s : set P) \u2194 p \u2208 s :=\niff.rfl\n\nvariables {k P}\n\n/-- The direction of an affine subspace is the submodule spanned by\nthe pairwise differences of points.  (Except in the case of an empty\naffine subspace, where the direction is the zero submodule, every\nvector in the direction is the difference of two points in the affine\nsubspace.) -/\ndef direction (s : affine_subspace k P) : submodule k V := vector_span k (s : set P)\n\n/-- The direction equals the `vector_span`. -/\nlemma direction_eq_vector_span (s : affine_subspace k P) :\n  s.direction = vector_span k (s : set P) :=\nrfl\n\n/-- Alternative definition of the direction when the affine subspace\nis nonempty.  This is defined so that the order on submodules (as used\nin the definition of `submodule.span`) can be used in the proof of\n`coe_direction_eq_vsub_set`, and is not intended to be used beyond\nthat proof. -/\ndef direction_of_nonempty {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  submodule k V :=\n{ carrier := (s : set P) -\u1d65 s,\n  zero_mem' := begin\n    cases h with p hp,\n    exact (vsub_self p) \u25b8 vsub_mem_vsub hp hp\n  end,\n  add_mem' := begin\n    intros a b ha hb,\n    rcases ha with \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    rcases hb with \u27e8p3, p4, hp3, hp4, rfl\u27e9,\n    rw [\u2190vadd_vsub_assoc],\n    refine vsub_mem_vsub _ hp4,\n    convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3,\n    rw one_smul\n  end,\n  smul_mem' := begin\n    intros c v hv,\n    rcases hv with \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    rw [\u2190vadd_vsub (c \u2022 (p1 -\u1d65 p2)) p2],\n    refine vsub_mem_vsub _ hp2,\n    exact s.smul_vsub_vadd_mem c hp1 hp2 hp2\n  end }\n\n/-- `direction_of_nonempty` gives the same submodule as\n`direction`. -/\nlemma direction_of_nonempty_eq_direction {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  direction_of_nonempty h = s.direction :=\nle_antisymm (vsub_set_subset_vector_span k s) (submodule.span_le.2 set.subset.rfl)\n\n/-- The set of vectors in the direction of a nonempty affine subspace\nis given by `vsub_set`. -/\nlemma coe_direction_eq_vsub_set {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  (s.direction : set V) = (s : set P) -\u1d65 s :=\ndirection_of_nonempty_eq_direction h \u25b8 rfl\n\n/-- A vector is in the direction of a nonempty affine subspace if and\nonly if it is the subtraction of two vectors in the subspace. -/\nlemma mem_direction_iff_eq_vsub {s : affine_subspace k P} (h : (s : set P).nonempty) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p1 \u2208 s, \u2203 p2 \u2208 s, v = p1 -\u1d65 p2 :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set h],\n  exact \u27e8\u03bb \u27e8p1, p2, hp1, hp2, hv\u27e9, \u27e8p1, hp1, p2, hp2, hv.symm\u27e9,\n         \u03bb \u27e8p1, hp1, p2, hp2, hv\u27e9, \u27e8p1, p2, hp1, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Adding a vector in the direction to a point in the subspace\nproduces a point in the subspace. -/\nlemma vadd_mem_of_mem_direction {s : affine_subspace k P} {v : V} (hv : v \u2208 s.direction) {p : P}\n    (hp : p \u2208 s) : v +\u1d65 p \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub \u27e8p, hp\u27e9 at hv,\n  rcases hv with \u27e8p1, hp1, p2, hp2, hv\u27e9,\n  rw hv,\n  convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp,\n  rw one_smul\nend\n\n/-- Subtracting two points in the subspace produces a vector in the\ndirection. -/\nlemma vsub_mem_direction {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n  (p1 -\u1d65 p2) \u2208 s.direction :=\nvsub_mem_vector_span k hp1 hp2\n\n/-- Adding a vector to a point in a subspace produces a point in the\nsubspace if and only if the vector is in the direction. -/\nlemma vadd_mem_iff_mem_direction {s : affine_subspace k P} (v : V) {p : P} (hp : p \u2208 s) :\n  v +\u1d65 p \u2208 s \u2194 v \u2208 s.direction :=\n\u27e8\u03bb h, by simpa using vsub_mem_direction h hp, \u03bb h, vadd_mem_of_mem_direction h hp\u27e9\n\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nright. -/\nlemma coe_direction_eq_vsub_set_right {s : affine_subspace k P} {p : P} (hp : p \u2208 s) :\n  (s.direction : set V) = (-\u1d65 p) '' s :=\nbegin\n  rw coe_direction_eq_vsub_set \u27e8p, hp\u27e9,\n  refine le_antisymm _ _,\n  { rintros v \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    exact \u27e8p1 -\u1d65 p2 +\u1d65 p,\n           vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp,\n           (vadd_vsub _ _)\u27e9 },\n  { rintros v \u27e8p2, hp2, rfl\u27e9,\n    exact \u27e8p2, p, hp2, hp, rfl\u27e9 }\nend\n\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nleft. -/\nlemma coe_direction_eq_vsub_set_left {s : affine_subspace k P} {p : P} (hp : p \u2208 s) :\n  (s.direction : set V) = (-\u1d65) p '' s :=\nbegin\n  ext v,\n  rw [set_like.mem_coe, \u2190submodule.neg_mem_iff, \u2190set_like.mem_coe,\n      coe_direction_eq_vsub_set_right hp, set.mem_image_iff_bex, set.mem_image_iff_bex],\n  conv_lhs { congr, funext, rw [\u2190neg_vsub_eq_vsub_rev, neg_inj] }\nend\n\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the right. -/\nlemma mem_direction_iff_eq_vsub_right {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p2 -\u1d65 p :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set_right hp],\n  exact \u27e8\u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9, \u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the left. -/\nlemma mem_direction_iff_eq_vsub_left {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p -\u1d65 p2 :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set_left hp],\n  exact \u27e8\u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9, \u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the right is in the direction if and only if the other point\nis in the subspace. -/\nlemma vsub_right_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n  p2 -\u1d65 p \u2208 s.direction \u2194 p2 \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub_right hp,\n  simp\nend\n\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the left is in the direction if and only if the other point\nis in the subspace. -/\nlemma vsub_left_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n  p -\u1d65 p2 \u2208 s.direction \u2194 p2 \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub_left hp,\n  simp\nend\n\n/-- Two affine subspaces are equal if they have the same points. -/\n@[ext] lemma ext {s1 s2 : affine_subspace k P} (h : (s1 : set P) = s2) : s1 = s2 :=\nbegin\n  cases s1,\n  cases s2,\n  congr,\n  exact h\nend\n\n/-- Two affine subspaces with the same direction and nonempty\nintersection are equal. -/\nlemma ext_of_direction_eq {s1 s2 : affine_subspace k P} (hd : s1.direction = s2.direction)\n    (hn : ((s1 : set P) \u2229 s2).nonempty) : s1 = s2 :=\nbegin\n  ext p,\n  have hq1 := set.mem_of_mem_inter_left hn.some_mem,\n  have hq2 := set.mem_of_mem_inter_right hn.some_mem,\n  split,\n  { intro hp,\n    rw \u2190vsub_vadd p hn.some,\n    refine vadd_mem_of_mem_direction _ hq2,\n    rw \u2190hd,\n    exact vsub_mem_direction hp hq1 },\n  { intro hp,\n    rw \u2190vsub_vadd p hn.some,\n    refine vadd_mem_of_mem_direction _ hq1,\n    rw hd,\n    exact vsub_mem_direction hp hq2 }\nend\n\ninstance to_add_torsor (s : affine_subspace k P) [nonempty s] : add_torsor s.direction s :=\n{ vadd := \u03bb a b, \u27e8(a:V) +\u1d65 (b:P), vadd_mem_of_mem_direction a.2 b.2\u27e9,\n  zero_vadd := by simp,\n  add_vadd := \u03bb a b c, by { ext, apply add_vadd },\n  vsub := \u03bb a b, \u27e8(a:P) -\u1d65 (b:P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2 \u27e9,\n  nonempty := by apply_instance,\n  vsub_vadd' := \u03bb a b, by { ext, apply add_torsor.vsub_vadd' },\n  vadd_vsub' := \u03bb a b, by { ext, apply add_torsor.vadd_vsub' } }\n\n@[simp, norm_cast] lemma coe_vsub (s : affine_subspace k P) [nonempty s] (a b : s) :\n  \u2191(a -\u1d65 b) = (a:P) -\u1d65 (b:P) :=\nrfl\n\n@[simp, norm_cast] lemma coe_vadd (s : affine_subspace k P) [nonempty s] (a : s.direction) (b : s) :\n  \u2191(a +\u1d65 b) = (a:V) +\u1d65 (b:P) :=\nrfl\n\n/-- Two affine subspaces with nonempty intersection are equal if and\nonly if their directions are equal. -/\nlemma eq_iff_direction_eq_of_mem {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h\u2081 : p \u2208 s\u2081)\n  (h\u2082 : p \u2208 s\u2082) : s\u2081 = s\u2082 \u2194 s\u2081.direction = s\u2082.direction :=\n\u27e8\u03bb h, h \u25b8 rfl, \u03bb h, ext_of_direction_eq h \u27e8p, h\u2081, h\u2082\u27e9\u27e9\n\n/-- Construct an affine subspace from a point and a direction. -/\ndef mk' (p : P) (direction : submodule k V) : affine_subspace k P :=\n{ carrier := {q | \u2203 v \u2208 direction, q = v +\u1d65 p},\n  smul_vsub_vadd_mem := \u03bb c p1 p2 p3 hp1 hp2 hp3, begin\n    rcases hp1 with \u27e8v1, hv1, hp1\u27e9,\n    rcases hp2 with \u27e8v2, hv2, hp2\u27e9,\n    rcases hp3 with \u27e8v3, hv3, hp3\u27e9,\n    use [c \u2022 (v1 - v2) + v3,\n         direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3],\n    simp [hp1, hp2, hp3, vadd_vadd]\n  end }\n\n/-- An affine subspace constructed from a point and a direction contains\nthat point. -/\nlemma self_mem_mk' (p : P) (direction : submodule k V) :\n  p \u2208 mk' p direction :=\n\u27e80, \u27e8direction.zero_mem, (zero_vadd _ _).symm\u27e9\u27e9\n\n/-- An affine subspace constructed from a point and a direction contains\nthe result of adding a vector in that direction to that point. -/\nlemma vadd_mem_mk' {v : V} (p : P) {direction : submodule k V} (hv : v \u2208 direction) :\n  v +\u1d65 p \u2208 mk' p direction :=\n\u27e8v, hv, rfl\u27e9\n\n/-- An affine subspace constructed from a point and a direction is\nnonempty. -/\nlemma mk'_nonempty (p : P) (direction : submodule k V) : (mk' p direction : set P).nonempty :=\n\u27e8p, self_mem_mk' p direction\u27e9\n\n/-- The direction of an affine subspace constructed from a point and a\ndirection. -/\n@[simp] lemma direction_mk' (p : P) (direction : submodule k V) :\n  (mk' p direction).direction = direction :=\nbegin\n  ext v,\n  rw mem_direction_iff_eq_vsub (mk'_nonempty _ _),\n  split,\n  { rintros \u27e8p1, \u27e8v1, hv1, hp1\u27e9, p2, \u27e8v2, hv2, hp2\u27e9, hv\u27e9,\n    rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right],\n    exact direction.sub_mem  hv1 hv2 },\n  { exact \u03bb hv, \u27e8v +\u1d65 p, vadd_mem_mk' _ hv, p,\n                 self_mem_mk' _ _, (vadd_vsub _ _).symm\u27e9 }\nend\n\n/-- Constructing an affine subspace from a point in a subspace and\nthat subspace's direction yields the original subspace. -/\n@[simp] lemma mk'_eq {s : affine_subspace k P} {p : P} (hp : p \u2208 s) : mk' p s.direction = s :=\next_of_direction_eq (direction_mk' p s.direction)\n                    \u27e8p, set.mem_inter (self_mem_mk' _ _) hp\u27e9\n\n/-- If an affine subspace contains a set of points, it contains the\n`span_points` of that set. -/\nlemma span_points_subset_coe_of_subset_coe {s : set P} {s1 : affine_subspace k P} (h : s \u2286 s1) :\n  span_points k s \u2286 s1 :=\nbegin\n  rintros p \u27e8p1, hp1, v, hv, hp\u27e9,\n  rw hp,\n  have hp1s1 : p1 \u2208 (s1 : set P) := set.mem_of_mem_of_subset hp1 h,\n  refine vadd_mem_of_mem_direction _ hp1s1,\n  have hs : vector_span k s \u2264 s1.direction := vector_span_mono k h,\n  rw set_like.le_def at hs,\n  rw \u2190set_like.mem_coe,\n  exact set.mem_of_mem_of_subset hv hs\nend\n\nend affine_subspace\n\nsection affine_span\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\n/-- The affine span of a set of points is the smallest affine subspace\ncontaining those points. (Actually defined here in terms of spans in\nmodules.) -/\ndef affine_span (s : set P) : affine_subspace k P :=\n{ carrier := span_points k s,\n  smul_vsub_vadd_mem := \u03bb c p1 p2 p3 hp1 hp2 hp3,\n    vadd_mem_span_points_of_mem_span_points_of_mem_vector_span k hp3\n      ((vector_span k s).smul_mem c\n        (vsub_mem_vector_span_of_mem_span_points_of_mem_span_points k hp1 hp2)) }\n\n/-- The affine span, converted to a set, is `span_points`. -/\n@[simp] lemma coe_affine_span (s : set P) :\n  (affine_span k s : set P) = span_points k s :=\nrfl\n\n/-- A set is contained in its affine span. -/\nlemma subset_affine_span (s : set P) : s \u2286 affine_span k s :=\nsubset_span_points k s\n\n/-- The direction of the affine span is the `vector_span`. -/\nlemma direction_affine_span (s : set P) : (affine_span k s).direction = vector_span k s :=\nbegin\n  apply le_antisymm,\n  { refine submodule.span_le.2 _,\n    rintros v \u27e8p1, p3, \u27e8p2, hp2, v1, hv1, hp1\u27e9, \u27e8p4, hp4, v2, hv2, hp3\u27e9, rfl\u27e9,\n    rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, set_like.mem_coe],\n    exact (vector_span k s).sub_mem ((vector_span k s).add_mem hv1\n      (vsub_mem_vector_span k hp2 hp4)) hv2 },\n  { exact vector_span_mono k (subset_span_points k s) }\nend\n\n/-- A point in a set is in its affine span. -/\nlemma mem_affine_span {p : P} {s : set P} (hp : p \u2208 s) : p \u2208 affine_span k s :=\nmem_span_points k p s hp\n\nend affine_span\n\nnamespace affine_subspace\n\nvariables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [S : affine_space V P]\ninclude S\n\ninstance : complete_lattice (affine_subspace k P) :=\n{ sup := \u03bb s1 s2, affine_span k (s1 \u222a s2),\n  le_sup_left := \u03bb s1 s2, set.subset.trans (set.subset_union_left s1 s2)\n                                           (subset_span_points k _),\n  le_sup_right :=  \u03bb s1 s2, set.subset.trans (set.subset_union_right s1 s2)\n                                             (subset_span_points k _),\n  sup_le := \u03bb s1 s2 s3 hs1 hs2, span_points_subset_coe_of_subset_coe (set.union_subset hs1 hs2),\n  inf := \u03bb s1 s2, mk (s1 \u2229 s2)\n                     (\u03bb c p1 p2 p3 hp1 hp2 hp3,\n                       \u27e8s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1,\n                       s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2\u27e9),\n  inf_le_left := \u03bb _ _, set.inter_subset_left _ _,\n  inf_le_right := \u03bb _ _, set.inter_subset_right _ _,\n  le_inf := \u03bb _ _ _, set.subset_inter,\n  top := { carrier := set.univ,\n    smul_vsub_vadd_mem := \u03bb _ _ _ _ _ _ _, set.mem_univ _ },\n  le_top := \u03bb _ _ _, set.mem_univ _,\n  bot := { carrier := \u2205,\n    smul_vsub_vadd_mem := \u03bb _ _ _ _, false.elim },\n  bot_le := \u03bb _ _, false.elim,\n  Sup := \u03bb s, affine_span k (\u22c3 s' \u2208 s, (s' : set P)),\n  Inf := \u03bb s, mk (\u22c2 s' \u2208 s, (s' : set P))\n                 (\u03bb c p1 p2 p3 hp1 hp2 hp3, set.mem_bInter_iff.2 $ \u03bb s2 hs2,\n                   s2.smul_vsub_vadd_mem c (set.mem_bInter_iff.1 hp1 s2 hs2)\n                                           (set.mem_bInter_iff.1 hp2 s2 hs2)\n                                           (set.mem_bInter_iff.1 hp3 s2 hs2)),\n  le_Sup := \u03bb _ _ h, set.subset.trans (set.subset_bUnion_of_mem h) (subset_span_points k _),\n  Sup_le := \u03bb _ _ h, span_points_subset_coe_of_subset_coe (set.bUnion_subset h),\n  Inf_le := \u03bb _ _, set.bInter_subset_of_mem,\n  le_Inf := \u03bb _ _, set.subset_bInter,\n  .. partial_order.lift (coe : affine_subspace k P \u2192 set P) (\u03bb _ _, ext) }\n\ninstance : inhabited (affine_subspace k P) := \u27e8\u22a4\u27e9\n\n/-- The `\u2264` order on subspaces is the same as that on the corresponding\nsets. -/\nlemma le_def (s1 s2 : affine_subspace k P) : s1 \u2264 s2 \u2194 (s1 : set P) \u2286 s2 :=\niff.rfl\n\n/-- One subspace is less than or equal to another if and only if all\nits points are in the second subspace. -/\nlemma le_def' (s1 s2 : affine_subspace k P) : s1 \u2264 s2 \u2194 \u2200 p \u2208 s1, p \u2208 s2 :=\niff.rfl\n\n/-- The `<` order on subspaces is the same as that on the corresponding\nsets. -/\nlemma lt_def (s1 s2 : affine_subspace k P) : s1 < s2 \u2194 (s1 : set P) \u2282 s2 :=\niff.rfl\n\n/-- One subspace is not less than or equal to another if and only if\nit has a point not in the second subspace. -/\nlemma not_le_iff_exists (s1 s2 : affine_subspace k P) : \u00ac s1 \u2264 s2 \u2194 \u2203 p \u2208 s1, p \u2209 s2 :=\nset.not_subset\n\n/-- If a subspace is less than another, there is a point only in the\nsecond. -/\nlemma exists_of_lt {s1 s2 : affine_subspace k P} (h : s1 < s2) : \u2203 p \u2208 s2, p \u2209 s1 :=\nset.exists_of_ssubset h\n\n/-- A subspace is less than another if and only if it is less than or\nequal to the second subspace and there is a point only in the\nsecond. -/\nlemma lt_iff_le_and_exists (s1 s2 : affine_subspace k P) : s1 < s2 \u2194 s1 \u2264 s2 \u2227 \u2203 p \u2208 s2, p \u2209 s1 :=\nby rw [lt_iff_le_not_le, not_le_iff_exists]\n\n/-- If an affine subspace is nonempty and contained in another with\nthe same direction, they are equal. -/\nlemma eq_of_direction_eq_of_nonempty_of_le {s\u2081 s\u2082 : affine_subspace k P}\n  (hd : s\u2081.direction = s\u2082.direction) (hn : (s\u2081 : set P).nonempty) (hle : s\u2081 \u2264 s\u2082) :\n  s\u2081 = s\u2082 :=\nlet \u27e8p, hp\u27e9 := hn in ext_of_direction_eq hd \u27e8p, hp, hle hp\u27e9\n\nvariables (k V)\n\n/-- The affine span is the `Inf` of subspaces containing the given\npoints. -/\nlemma affine_span_eq_Inf (s : set P) : affine_span k s = Inf {s' | s \u2286 s'} :=\nle_antisymm (span_points_subset_coe_of_subset_coe (set.subset_bInter (\u03bb _ h, h)))\n            (Inf_le (subset_span_points k _))\n\nvariables (P)\n\n/-- The Galois insertion formed by `affine_span` and coercion back to\na set. -/\nprotected def gi : galois_insertion (affine_span k) (coe : affine_subspace k P \u2192 set P) :=\n{ choice := \u03bb s _, affine_span k s,\n  gc := \u03bb s1 s2, \u27e8\u03bb h, set.subset.trans (subset_span_points k s1) h,\n                       span_points_subset_coe_of_subset_coe\u27e9,\n  le_l_u := \u03bb _, subset_span_points k _,\n  choice_eq := \u03bb _ _, rfl }\n\n/-- The span of the empty set is `\u22a5`. -/\n@[simp] lemma span_empty : affine_span k (\u2205 : set P) = \u22a5 :=\n(affine_subspace.gi k V P).gc.l_bot\n\n/-- The span of `univ` is `\u22a4`. -/\n@[simp] lemma span_univ : affine_span k (set.univ : set P) = \u22a4 :=\neq_top_iff.2 $ subset_span_points k _\n\nvariables {P}\n\n/-- The affine span of a single point, coerced to a set, contains just\nthat point. -/\n@[simp] lemma coe_affine_span_singleton (p : P) : (affine_span k ({p} : set P) : set P) = {p} :=\nbegin\n  ext x,\n  rw [mem_coe, \u2190vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_singleton p)) _,\n      direction_affine_span],\n  simp\nend\n\n/-- A point is in the affine span of a single point if and only if\nthey are equal. -/\n@[simp] lemma mem_affine_span_singleton (p1 p2 : P) :\n  p1 \u2208 affine_span k ({p2} : set P) \u2194 p1 = p2 :=\nby simp [\u2190mem_coe]\n\n/-- The span of a union of sets is the sup of their spans. -/\nlemma span_union (s t : set P) : affine_span k (s \u222a t) = affine_span k s \u2294 affine_span k t :=\n(affine_subspace.gi k V P).gc.l_sup\n\n/-- The span of a union of an indexed family of sets is the sup of\ntheir spans. -/\nlemma span_Union {\u03b9 : Type*} (s : \u03b9 \u2192 set P) :\n  affine_span k (\u22c3 i, s i) = \u2a06 i, affine_span k (s i) :=\n(affine_subspace.gi k V P).gc.l_supr\n\nvariables (P)\n\n/-- `\u22a4`, coerced to a set, is the whole set of points. -/\n@[simp] lemma top_coe : ((\u22a4 : affine_subspace k P) : set P) = set.univ :=\nrfl\n\nvariables {P}\n\n/-- All points are in `\u22a4`. -/\nlemma mem_top (p : P) : p \u2208 (\u22a4 : affine_subspace k P) :=\nset.mem_univ p\n\nvariables (P)\n\n/-- The direction of `\u22a4` is the whole module as a submodule. -/\n@[simp] lemma direction_top : (\u22a4 : affine_subspace k P).direction = \u22a4 :=\nbegin\n  cases S.nonempty with p,\n  ext v,\n  refine \u27e8imp_intro submodule.mem_top, \u03bb hv, _\u27e9,\n  have hpv : (v +\u1d65 p -\u1d65 p : V) \u2208 (\u22a4 : affine_subspace k P).direction :=\n    vsub_mem_direction (mem_top k V _) (mem_top k V _),\n  rwa vadd_vsub at hpv\nend\n\n/-- `\u22a5`, coerced to a set, is the empty set. -/\n@[simp] lemma bot_coe : ((\u22a5 : affine_subspace k P) : set P) = \u2205 :=\nrfl\n\nvariables {P}\n\n/-- No points are in `\u22a5`. -/\nlemma not_mem_bot (p : P) : p \u2209 (\u22a5 : affine_subspace k P) :=\nset.not_mem_empty p\n\nvariables (P)\n\n/-- The direction of `\u22a5` is the submodule `\u22a5`. -/\n@[simp] lemma direction_bot : (\u22a5 : affine_subspace k P).direction = \u22a5 :=\nby rw [direction_eq_vector_span, bot_coe, vector_span_def, vsub_empty, submodule.span_empty]\n\nvariables {k V P}\n\n/-- A nonempty affine subspace is `\u22a4` if and only if its direction is\n`\u22a4`. -/\n@[simp] lemma direction_eq_top_iff_of_nonempty {s : affine_subspace k P}\n  (h : (s : set P).nonempty) : s.direction = \u22a4 \u2194 s = \u22a4 :=\nbegin\n  split,\n  { intro hd,\n    rw \u2190direction_top k V P at hd,\n    refine ext_of_direction_eq hd _,\n    simp [h] },\n  { rintro rfl,\n    simp }\nend\n\n/-- The inf of two affine subspaces, coerced to a set, is the\nintersection of the two sets of points. -/\n@[simp] lemma inf_coe (s1 s2 : affine_subspace k P) : ((s1 \u2293 s2) : set P) = s1 \u2229 s2 :=\nrfl\n\n/-- A point is in the inf of two affine subspaces if and only if it is\nin both of them. -/\nlemma mem_inf_iff (p : P) (s1 s2 : affine_subspace k P) : p \u2208 s1 \u2293 s2 \u2194 p \u2208 s1 \u2227 p \u2208 s2 :=\niff.rfl\n\n/-- The direction of the inf of two affine subspaces is less than or\nequal to the inf of their directions. -/\nlemma direction_inf (s1 s2 : affine_subspace k P) :\n  (s1 \u2293 s2).direction \u2264 s1.direction \u2293 s2.direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact le_inf\n    (Inf_le_Inf (\u03bb p hp, trans (vsub_self_mono (inter_subset_left _ _)) hp))\n    (Inf_le_Inf (\u03bb p hp, trans (vsub_self_mono (inter_subset_right _ _)) hp))\nend\n\n/-- If two affine subspaces have a point in common, the direction of\ntheir inf equals the inf of their directions. -/\nlemma direction_inf_of_mem {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h\u2081 : p \u2208 s\u2081) (h\u2082 : p \u2208 s\u2082) :\n  (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\nbegin\n  ext v,\n  rw [submodule.mem_inf, \u2190vadd_mem_iff_mem_direction v h\u2081, \u2190vadd_mem_iff_mem_direction v h\u2082,\n      \u2190vadd_mem_iff_mem_direction v ((mem_inf_iff p s\u2081 s\u2082).2 \u27e8h\u2081, h\u2082\u27e9), mem_inf_iff]\nend\n\n/-- If two affine subspaces have a point in their inf, the direction\nof their inf equals the inf of their directions. -/\nlemma direction_inf_of_mem_inf {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h : p \u2208 s\u2081 \u2293 s\u2082) :\n  (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\ndirection_inf_of_mem ((mem_inf_iff p s\u2081 s\u2082).1 h).1 ((mem_inf_iff p s\u2081 s\u2082).1 h).2\n\n/-- If one affine subspace is less than or equal to another, the same\napplies to their directions. -/\nlemma direction_le {s1 s2 : affine_subspace k P} (h : s1 \u2264 s2) : s1.direction \u2264 s2.direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact vector_span_mono k h\nend\n\n/-- If one nonempty affine subspace is less than another, the same\napplies to their directions -/\nlemma direction_lt_of_nonempty {s1 s2 : affine_subspace k P} (h : s1 < s2)\n    (hn : (s1 : set P).nonempty) : s1.direction < s2.direction :=\nbegin\n  cases hn with p hp,\n  rw lt_iff_le_and_exists at h,\n  rcases h with \u27e8hle, p2, hp2, hp2s1\u27e9,\n  rw set_like.lt_iff_le_and_exists,\n  use [direction_le hle, p2 -\u1d65 p, vsub_mem_direction hp2 (hle hp)],\n  intro hm,\n  rw vsub_right_mem_direction_iff_mem hp p2 at hm,\n  exact hp2s1 hm\nend\n\n/-- The sup of the directions of two affine subspaces is less than or\nequal to the direction of their sup. -/\nlemma sup_direction_le (s1 s2 : affine_subspace k P) :\n  s1.direction \u2294 s2.direction \u2264 (s1 \u2294 s2).direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact sup_le\n    (Inf_le_Inf (\u03bb p hp, set.subset.trans (vsub_self_mono (le_sup_left : s1 \u2264 s1 \u2294 s2)) hp))\n    (Inf_le_Inf (\u03bb p hp, set.subset.trans (vsub_self_mono (le_sup_right : s2 \u2264 s1 \u2294 s2)) hp))\nend\n\n/-- The sup of the directions of two nonempty affine subspaces with\nempty intersection is less than the direction of their sup. -/\nlemma sup_direction_lt_of_nonempty_of_inter_empty {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty) (he : (s1 \u2229 s2 : set P) = \u2205) :\n  s1.direction \u2294 s2.direction < (s1 \u2294 s2).direction :=\nbegin\n  cases h1 with p1 hp1,\n  cases h2 with p2 hp2,\n  rw set_like.lt_iff_le_and_exists,\n  use [sup_direction_le s1 s2, p2 -\u1d65 p1,\n       vsub_mem_direction ((le_sup_right : s2 \u2264 s1 \u2294 s2) hp2) ((le_sup_left : s1 \u2264 s1 \u2294 s2) hp1)],\n  intro h,\n  rw submodule.mem_sup at h,\n  rcases h with \u27e8v1, hv1, v2, hv2, hv1v2\u27e9,\n  rw [\u2190sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc,\n      \u2190vadd_vsub_assoc, \u2190neg_neg v2, add_comm, \u2190sub_eq_add_neg, \u2190vsub_vadd_eq_vsub_sub,\n      vsub_eq_zero_iff_eq] at hv1v2,\n  refine set.nonempty.ne_empty _ he,\n  use [v1 +\u1d65 p1, vadd_mem_of_mem_direction hv1 hp1],\n  rw hv1v2,\n  exact vadd_mem_of_mem_direction (submodule.neg_mem _ hv2) hp2\nend\n\n/-- If the directions of two nonempty affine subspaces span the whole\nmodule, they have nonempty intersection. -/\nlemma inter_nonempty_of_nonempty_of_sup_direction_eq_top {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)\n    (hd : s1.direction \u2294 s2.direction = \u22a4) : ((s1 : set P) \u2229 s2).nonempty :=\nbegin\n  by_contradiction h,\n  rw set.not_nonempty_iff_eq_empty at h,\n  have hlt := sup_direction_lt_of_nonempty_of_inter_empty h1 h2 h,\n  rw hd at hlt,\n  exact not_top_lt hlt\nend\n\n/-- If the directions of two nonempty affine subspaces are complements\nof each other, they intersect in exactly one point. -/\nlemma inter_eq_singleton_of_nonempty_of_is_compl {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)\n    (hd : is_compl s1.direction s2.direction) : \u2203 p, (s1 : set P) \u2229 s2 = {p} :=\nbegin\n  cases inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top with p hp,\n  use p,\n  ext q,\n  rw set.mem_singleton_iff,\n  split,\n  { rintros \u27e8hq1, hq2\u27e9,\n    have hqp : q -\u1d65 p \u2208 s1.direction \u2293 s2.direction :=\n      \u27e8vsub_mem_direction hq1 hp.1, vsub_mem_direction hq2 hp.2\u27e9,\n    rwa [hd.inf_eq_bot, submodule.mem_bot, vsub_eq_zero_iff_eq] at hqp },\n  { exact \u03bb h, h.symm \u25b8 hp }\nend\n\n/-- Coercing a subspace to a set then taking the affine span produces\nthe original subspace. -/\n@[simp] lemma affine_span_coe (s : affine_subspace k P) : affine_span k (s : set P) = s :=\nbegin\n  refine le_antisymm _ (subset_span_points _ _),\n  rintros p \u27e8p1, hp1, v, hv, rfl\u27e9,\n  exact vadd_mem_of_mem_direction hv hp1\nend\n\nend affine_subspace\n\nsection affine_space'\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\nvariables {\u03b9 : Type*}\ninclude V\n\nopen affine_subspace set\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left. -/\nlemma vector_span_eq_span_vsub_set_left {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65) p '' s) :=\nbegin\n  rw vector_span_def,\n  refine le_antisymm _ (submodule.span_mono _),\n  { rw submodule.span_le,\n    rintros v \u27e8p1, p2, hp1, hp2, hv\u27e9,\n    rw \u2190vsub_sub_vsub_cancel_left p1 p2 p at hv,\n    rw [\u2190hv, set_like.mem_coe, submodule.mem_span],\n    exact \u03bb m hm, submodule.sub_mem _ (hm \u27e8p2, hp2, rfl\u27e9) (hm \u27e8p1, hp1, rfl\u27e9) },\n  { rintros v \u27e8p2, hp2, hv\u27e9,\n    exact \u27e8p, p2, hp, hp2, hv\u27e9 }\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right. -/\nlemma vector_span_eq_span_vsub_set_right {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65 p) '' s) :=\nbegin\n  rw vector_span_def,\n  refine le_antisymm _ (submodule.span_mono _),\n  { rw submodule.span_le,\n    rintros v \u27e8p1, p2, hp1, hp2, hv\u27e9,\n    rw \u2190vsub_sub_vsub_cancel_right p1 p2 p at hv,\n    rw [\u2190hv, set_like.mem_coe, submodule.mem_span],\n    exact \u03bb m hm, submodule.sub_mem _ (hm \u27e8p1, hp1, rfl\u27e9) (hm \u27e8p2, hp2, rfl\u27e9) },\n  { rintros v \u27e8p2, hp2, hv\u27e9,\n    exact \u27e8p2, p, hp2, hp, hv\u27e9 }\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_set_left_ne {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65) p '' (s \\ {p})) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_left k hp, \u2190set.insert_eq_of_mem hp,\n                 \u2190set.insert_diff_singleton, set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_set_right_ne {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65 p) '' (s \\ {p})) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_right k hp, \u2190set.insert_eq_of_mem hp,\n                 \u2190set.insert_diff_singleton, set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the left, excluding the\nsubtraction of that point from itself. -/\nlemma vector_span_image_eq_span_vsub_set_left_ne (p : \u03b9 \u2192 P) {s : set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  vector_span k (p '' s) = submodule.span k ((-\u1d65) (p i) '' (p '' (s \\ {i}))) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_left k (set.mem_image_of_mem p hi),\n                 \u2190set.insert_eq_of_mem hi, \u2190set.insert_diff_singleton, set.image_insert_eq,\n                 set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the right, excluding the\nsubtraction of that point from itself. -/\nlemma vector_span_image_eq_span_vsub_set_right_ne (p : \u03b9 \u2192 P) {s : set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  vector_span k (p '' s) = submodule.span k ((-\u1d65 (p i)) '' (p '' (s \\ {i}))) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_right k (set.mem_image_of_mem p hi),\n                 \u2190set.insert_eq_of_mem hi, \u2190set.insert_diff_singleton, set.image_insert_eq,\n                 set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left. -/\nlemma vector_span_range_eq_span_range_vsub_left (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : \u03b9), p i0 -\u1d65 p i)) :=\nby rw [vector_span_eq_span_vsub_set_left k (set.mem_range_self i0), \u2190set.range_comp]\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right. -/\nlemma vector_span_range_eq_span_range_vsub_right (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : \u03b9), p i -\u1d65 p i0)) :=\nby rw [vector_span_eq_span_vsub_set_right k (set.mem_range_self i0), \u2190set.range_comp]\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left, excluding the subtraction\nof that point from itself. -/\nlemma vector_span_range_eq_span_range_vsub_left_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : {x // x \u2260 i\u2080}), p i\u2080 -\u1d65 p i)) :=\nbegin\n  rw [\u2190set.image_univ, vector_span_image_eq_span_vsub_set_left_ne k _ (set.mem_univ i\u2080)],\n  congr' with v,\n  simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,\n             subtype.coe_mk],\n  split,\n  { rintros \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9,\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9 },\n  { exact \u03bb \u27e8i\u2081, hi\u2081, hv\u27e9, \u27e8p i\u2081, \u27e8i\u2081, \u27e8set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9 }\nend\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right, excluding the subtraction\nof that point from itself. -/\nlemma vector_span_range_eq_span_range_vsub_right_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : {x // x \u2260 i\u2080}), p i -\u1d65 p i\u2080)) :=\nbegin\n  rw [\u2190set.image_univ, vector_span_image_eq_span_vsub_set_right_ne k _ (set.mem_univ i\u2080)],\n  congr' with v,\n  simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,\n             subtype.coe_mk],\n  split,\n  { rintros \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9,\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9 },\n  { exact \u03bb \u27e8i\u2081, hi\u2081, hv\u27e9, \u27e8p i\u2081, \u27e8i\u2081, \u27e8set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9 }\nend\n\n/-- The affine span of a set is nonempty if and only if that set\nis. -/\nlemma affine_span_nonempty (s : set P) :\n  (affine_span k s : set P).nonempty \u2194 s.nonempty :=\nspan_points_nonempty k s\n\n/-- The affine span of a nonempty set is nonempty. -/\ninstance {s : set P} [nonempty s] : nonempty (affine_span k s) :=\n((affine_span_nonempty k s).mpr (nonempty_subtype.mp \u2039_\u203a)).to_subtype\n\nvariables {k}\n\n/-- Suppose a set of vectors spans `V`.  Then a point `p`, together\nwith those vectors added to `p`, spans `P`. -/\nlemma affine_span_singleton_union_vadd_eq_top_of_span_eq_top {s : set V} (p : P)\n    (h : submodule.span k (set.range (coe : s \u2192 V)) = \u22a4) :\n  affine_span k ({p} \u222a (\u03bb v, v +\u1d65 p) '' s) = \u22a4 :=\nbegin\n  convert ext_of_direction_eq _\n    \u27e8p,\n     mem_affine_span k (set.mem_union_left _ (set.mem_singleton _)),\n     mem_top k V p\u27e9,\n  rw [direction_affine_span, direction_top,\n      vector_span_eq_span_vsub_set_right k\n        ((set.mem_union_left _ (set.mem_singleton _)) : p \u2208 _), eq_top_iff, \u2190h],\n  apply submodule.span_mono,\n  rintros v \u27e8v', rfl\u27e9,\n  use (v' : V) +\u1d65 p,\n  simp\nend\n\nvariables (k)\n\n/-- `affine_span` is monotone. -/\nlemma affine_span_mono {s\u2081 s\u2082 : set P} (h : s\u2081 \u2286 s\u2082) : affine_span k s\u2081 \u2264 affine_span k s\u2082 :=\nspan_points_subset_coe_of_subset_coe (set.subset.trans h (subset_affine_span k _))\n\n/-- Taking the affine span of a set, adding a point and taking the\nspan again produces the same results as adding the point to the set\nand taking the span. -/\nlemma affine_span_insert_affine_span (p : P) (ps : set P) :\n  affine_span k (insert p (affine_span k ps : set P)) = affine_span k (insert p ps) :=\nby rw [set.insert_eq, set.insert_eq, span_union, span_union, affine_span_coe]\n\n/-- If a point is in the affine span of a set, adding it to that set\ndoes not change the affine span. -/\nlemma affine_span_insert_eq_affine_span {p : P} {ps : set P} (h : p \u2208 affine_span k ps) :\n  affine_span k (insert p ps) = affine_span k ps :=\nbegin\n  rw \u2190mem_coe at h,\n  rw [\u2190affine_span_insert_affine_span, set.insert_eq_of_mem h, affine_span_coe]\nend\n\nend affine_space'\n\nnamespace affine_subspace\n\nvariables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\n/-- The direction of the sup of two nonempty affine subspaces is the\nsup of the two directions and of any one difference between points in\nthe two subspaces. -/\nlemma direction_sup {s1 s2 : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s1) (hp2 : p2 \u2208 s2) :\n  (s1 \u2294 s2).direction = s1.direction \u2294 s2.direction \u2294 k \u2219 (p2 -\u1d65 p1) :=\nbegin\n  refine le_antisymm _ _,\n  { change (affine_span k ((s1 : set P) \u222a s2)).direction \u2264 _,\n    rw \u2190mem_coe at hp1,\n    rw [direction_affine_span, vector_span_eq_span_vsub_set_right k (set.mem_union_left _ hp1),\n        submodule.span_le],\n    rintros v \u27e8p3, hp3, rfl\u27e9,\n    cases hp3,\n    { rw [sup_assoc, sup_comm, set_like.mem_coe, submodule.mem_sup],\n      use [0, submodule.zero_mem _, p3 -\u1d65 p1, vsub_mem_direction hp3 hp1],\n      rw zero_add },\n    { rw [sup_assoc, set_like.mem_coe, submodule.mem_sup],\n      use [0, submodule.zero_mem _, p3 -\u1d65 p1],\n      rw [and_comm, zero_add],\n      use rfl,\n      rw [\u2190vsub_add_vsub_cancel p3 p2 p1, submodule.mem_sup],\n      use [p3 -\u1d65 p2, vsub_mem_direction hp3 hp2, p2 -\u1d65 p1,\n           submodule.mem_span_singleton_self _] } },\n  { refine sup_le (sup_direction_le _ _) _,\n    rw [direction_eq_vector_span, vector_span_def],\n    exact Inf_le_Inf (\u03bb p hp, set.subset.trans\n      (set.singleton_subset_iff.2\n        (vsub_mem_vsub (mem_span_points k p2 _ (set.mem_union_right _ hp2))\n                       (mem_span_points k p1 _ (set.mem_union_left _ hp1))))\n      hp) }\nend\n\n/-- The direction of the span of the result of adding a point to a\nnonempty affine subspace is the sup of the direction of that subspace\nand of any one difference between that point and a point in the\nsubspace. -/\nlemma direction_affine_span_insert {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) :\n  (affine_span k (insert p2 (s : set P))).direction = submodule.span k {p2 -\u1d65 p1} \u2294 s.direction :=\nbegin\n  rw [sup_comm, \u2190set.union_singleton, \u2190coe_affine_span_singleton k V p2],\n  change (s \u2294 affine_span k {p2}).direction = _,\n  rw [direction_sup hp1 (mem_affine_span k (set.mem_singleton _)), direction_affine_span],\n  simp\nend\n\n/-- Given a point `p1` in an affine subspace `s`, and a point `p2`, a\npoint `p` is in the span of `s` with `p2` added if and only if it is a\nmultiple of `p2 -\u1d65 p1` added to a point in `s`. -/\nlemma mem_affine_span_insert_iff {s : affine_subspace k P} {p1 : P} (hp1 : p1 \u2208 s) (p2 p : P) :\n  p \u2208 affine_span k (insert p2 (s : set P)) \u2194\n    \u2203 (r : k) (p0 : P) (hp0 : p0 \u2208 s), p = r \u2022 (p2 -\u1d65 p1 : V) +\u1d65 p0 :=\nbegin\n  rw \u2190mem_coe at hp1,\n  rw [\u2190vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_insert_of_mem _ hp1)),\n      direction_affine_span_insert hp1, submodule.mem_sup],\n  split,\n  { rintros \u27e8v1, hv1, v2, hv2, hp\u27e9,\n    rw submodule.mem_span_singleton at hv1,\n    rcases hv1 with \u27e8r, rfl\u27e9,\n    use [r, v2 +\u1d65 p1, vadd_mem_of_mem_direction hv2 hp1],\n    symmetry' at hp,\n    rw [\u2190sub_eq_zero, \u2190vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hp,\n    rw [hp, vadd_vadd] },\n  { rintros \u27e8r, p3, hp3, rfl\u27e9,\n    use [r \u2022 (p2 -\u1d65 p1), submodule.mem_span_singleton.2 \u27e8r, rfl\u27e9, p3 -\u1d65 p1,\n         vsub_mem_direction hp3 hp1],\n    rw [vadd_vsub_assoc, add_comm] }\nend\n\nend affine_subspace\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/linear_algebra/affine_space/affine_subspace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7312229870078921}}
{"text": "import data.nat.basic\n\nuniverse u\n\nnamespace sandbox\n\nopen nat\n\ndef mod : nat \u2192 nat \u2192 nat\n| _ 0 := 0\n| a (succ b) := if h : a \u2265 succ b then\nhave a - succ b < a := sub_lt_of_pos_le _ _ succ_pos' h,\nmod (a - succ b) (succ b)\nelse a\n\nlocal infix % := mod\n\nlemma mod_zero {a} : mod a 0 = 0 :=\nbegin\n  unfold mod\nend\n\nlemma mod_step {a b} (h : a \u2265 b) : mod a b = mod (a - b) b :=\nbegin\n  cases b,\n  { refl },\n  { rw mod.equations._eqn_2,\n    rwa if_pos }\nend\n\nlemma mod_eq_of_lt {a b : nat} (h : a < b) : a % b = a :=\nbegin\n  cases b,\n  { exfalso, exact not_succ_le_zero a h },\n  { rw mod.equations._eqn_2,\n    rw if_neg,\n    exact not_le.mpr h }\nend\n\nlemma zero_mod {b} : 0 % b = 0 :=\nbegin\n  cases b,\n  { exact mod_zero },\n  { apply mod_eq_of_lt,\n    apply nat.zero_lt_succ }\nend\n\nlemma mod_lt {a b} (h : b \u2260 0) : mod a b < b :=\nbegin\n  cases b,\n  { exfalso, exact h rfl },\n  { induction a using nat.case_strong_induction_on with x ih,\n    { rw zero_mod,\n      apply nat.zero_lt_succ },\n    { apply nat.lt_ge_by_cases,\n      { intro h, rw mod_eq_of_lt h, exact h },\n      { intro h,\n        rw mod_step h,\n        apply ih,\n        replace h := le_of_succ_le_succ h,\n        rw nat.succ_sub_succ,\n        exact sub_le _ _ } } }\nend\n\nlemma mod_prop {a b} : \u2203 k, mod a b * k = a :=\nbegin\n  sorry\nend\n\nend sandbox\n\n", "meta": {"author": "AtnNn", "repo": "lean-sandbox", "sha": "8c68afbdc09213173aef1be195da7a9a86060a97", "save_path": "github-repos/lean/AtnNn-lean-sandbox", "path": "github-repos/lean/AtnNn-lean-sandbox/lean-sandbox-8c68afbdc09213173aef1be195da7a9a86060a97/src/mod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.731189927161543}}
{"text": "/-\nCopyright (c) 2019 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebraic_geometry.presheafed_space\nimport Mathlib.topology.sheaves.stalks\nimport Mathlib.PostPort\n\nuniverses v u \n\nnamespace Mathlib\n\n/-!\n# Stalks for presheaved spaces\n\nThis file lifts constructions of stalks and pushforwards of stalks to work with\nthe category of presheafed spaces.\n-/\n\nnamespace algebraic_geometry.PresheafedSpace\n\n\n/--\nThe stalk at `x` of a `PresheafedSpace`.\n-/\ndef stalk {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] (X : PresheafedSpace C) (x : \u21a5X) : C :=\n  Top.presheaf.stalk (PresheafedSpace.presheaf X) x\n\n/--\nA morphism of presheafed spaces induces a morphism of stalks.\n-/\ndef stalk_map {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : PresheafedSpace C} {Y : PresheafedSpace C} (\u03b1 : X \u27f6 Y) (x : \u21a5X) : stalk Y (coe_fn (hom.base \u03b1) x) \u27f6 stalk X x :=\n  category_theory.functor.map (Top.presheaf.stalk_functor C (coe_fn (hom.base \u03b1) x)) (hom.c \u03b1) \u226b\n    Top.presheaf.stalk_pushforward C (hom.base \u03b1) (PresheafedSpace.presheaf X) x\n\n-- PROJECT: restriction preserves stalks.\n\n-- We'll want to define cofinal functors, show precomposing with a cofinal functor preserves colimits,\n\n-- and (easily) verify that \"open neighbourhoods of x within U\" is cofinal in \"open neighbourhoods of x\".\n\n/-\ndef restrict_stalk_iso {U : Top} (X : PresheafedSpace C)\n  (f : U \u27f6 (X : Top.{v})) (h : open_embedding f) (x : U) :\n  (X.restrict f h).stalk x \u2245 X.stalk (f x) :=\nbegin\n  dsimp only [stalk, Top.presheaf.stalk, stalk_functor],\n  dsimp [colim],\n  sorry\nend\n\n-- TODO `restrict_stalk_iso` is compatible with `germ`.\n\n-- TODO `restrict_stalk_iso` is compatible with `germ`.\n-/\n\nnamespace stalk_map\n\n\n@[simp] theorem id {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] (X : PresheafedSpace C) (x : \u21a5X) : stalk_map \ud835\udfd9 x = \ud835\udfd9 := sorry\n\n-- TODO understand why this proof is still gross (i.e. requires using `erw`)\n\n@[simp] theorem comp {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : PresheafedSpace C} {Y : PresheafedSpace C} {Z : PresheafedSpace C} (\u03b1 : X \u27f6 Y) (\u03b2 : Y \u27f6 Z) (x : \u21a5X) : stalk_map (\u03b1 \u226b \u03b2) x = stalk_map \u03b2 (coe_fn (hom.base \u03b1) x) \u226b stalk_map \u03b1 x := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebraic_geometry/stalks.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7311816886459317}}
{"text": "/-\nCopyright (c) 2021 Kalle Kyt\u00f6l\u00e4. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kyt\u00f6l\u00e4\n-/\nimport measure_theory.measure.measure_space\nimport measure_theory.integral.bochner\nimport topology.continuous_function.bounded\nimport topology.algebra.module.weak_dual\n\n/-!\n# Weak convergence of (finite) measures\n\nThis file will define the topology of weak convergence of finite measures and probability measures\non topological spaces. The topology of weak convergence is the coarsest topology w.r.t. which\nfor every bounded continuous `\u211d\u22650`-valued function `f`, the integration of `f` against the\nmeasure is continuous.\n\nTODOs:\n* Define the topologies (the current version only defines the types) via\n  `weak_dual \u211d\u22650 (\u03b1 \u2192\u1d47 \u211d\u22650)`.\n* Prove that an equivalent definition of the topologies is obtained requiring continuity of\n  integration of bounded continuous `\u211d`-valued functions instead.\n* Include the portmanteau theorem on characterizations of weak convergence of (Borel) probability\n  measures.\n\n## Main definitions\n\nThe main definitions are the\n * types `finite_measure \u03b1` and `probability_measure \u03b1`;\n * `to_weak_dual_bounded_continuous_nnreal : finite_measure \u03b1 \u2192 (weak_dual \u211d\u22650 (\u03b1 \u2192\u1d47 \u211d\u22650))`\n   allowing to interpret a finite measure as a continuous linear functional on the space of\n   bounded continuous nonnegative functions on `\u03b1`. This will be used for the definition of the\n   topology of weak convergence.\n\nTODO:\n* Define the topologies on the above types.\n\n## Main results\n\n * Finite measures `\u03bc` on `\u03b1` give rise to continuous linear functionals on the space of\n   bounded continuous nonnegative functions on `\u03b1` via integration:\n   `to_weak_dual_of_bounded_continuous_nnreal : finite_measure \u03b1 \u2192 (weak_dual \u211d\u22650 (\u03b1 \u2192\u1d47 \u211d\u22650))`.\n\nTODO:\n* Portmanteau theorem.\n\n## Notations\n\nNo new notation is introduced.\n\n## Implementation notes\n\nThe topology of weak convergence of finite Borel measures will be defined using a mapping from\n`finite_measure \u03b1` to `weak_dual \u211d\u22650 (\u03b1 \u2192\u1d47 \u211d\u22650)`, inheriting the topology from the latter.\n\nThe current implementation of `finite_measure \u03b1` and `probability_measure \u03b1` is directly as\nsubtypes of `measure \u03b1`, and the coercion to a function is the composition `ennreal.to_nnreal`\nand the coercion to function of `measure \u03b1`. Another alternative would be to use a bijection\nwith `vector_measure \u03b1 \u211d\u22650` as an intermediate step. The choice of implementation should not have\ndrastic downstream effects, so it can be changed later if appropriate.\n\nPotential advantages of using the `nnreal`-valued vector measure alternative:\n * The coercion to function would avoid need to compose with `ennreal.to_nnreal`, the\n   `nnreal`-valued API could be more directly available.\nPotential drawbacks of the vector measure alternative:\n * The coercion to function would lose monotonicity, as non-measurable sets would be defined to\n   have measure 0.\n * No integration theory directly. E.g., the topology definition requires `lintegral` w.r.t.\n   a coercion to `measure \u03b1` in any case.\n\n## References\n\n* [Billingsley, *Convergence of probability measures*][billingsley1999]\n\n## Tags\n\nweak convergence of measures, finite measure, probability measure\n\n-/\n\nnoncomputable theory\nopen measure_theory\nopen set\nopen filter\nopen bounded_continuous_function\nopen_locale topological_space ennreal nnreal bounded_continuous_function\n\nnamespace measure_theory\n\nvariables {\u03b1 : Type*} [measurable_space \u03b1]\n\n/-- Finite measures are defined as the subtype of measures that have the property of being finite\nmeasures (i.e., their total mass is finite). -/\ndef finite_measure (\u03b1 : Type*) [measurable_space \u03b1] : Type* :=\n{\u03bc : measure \u03b1 // is_finite_measure \u03bc}\n\nnamespace finite_measure\n\n/-- A finite measure can be interpreted as a measure. -/\ninstance : has_coe (finite_measure \u03b1) (measure_theory.measure \u03b1) := coe_subtype\n\ninstance is_finite_measure (\u03bc : finite_measure \u03b1) :\n  is_finite_measure (\u03bc : measure \u03b1) := \u03bc.prop\n\ninstance : has_coe_to_fun (finite_measure \u03b1) (\u03bb _, set \u03b1 \u2192 \u211d\u22650) :=\n\u27e8\u03bb \u03bc s, (\u03bc s).to_nnreal\u27e9\n\nlemma coe_fn_eq_to_nnreal_coe_fn_to_measure (\u03bd : finite_measure \u03b1) :\n  (\u03bd : set \u03b1 \u2192 \u211d\u22650) = \u03bb s, ((\u03bd : measure \u03b1) s).to_nnreal := rfl\n\n@[simp] lemma ennreal_coe_fn_eq_coe_fn_to_measure (\u03bd : finite_measure \u03b1) (s : set \u03b1) :\n  (\u03bd s : \u211d\u22650\u221e) = (\u03bd : measure \u03b1) s := ennreal.coe_to_nnreal (measure_lt_top \u2191\u03bd s).ne\n\n@[simp] lemma val_eq_to_measure (\u03bd : finite_measure \u03b1) : \u03bd.val = (\u03bd : measure \u03b1) := rfl\n\nlemma coe_injective : function.injective (coe : finite_measure \u03b1 \u2192 measure \u03b1) :=\nsubtype.coe_injective\n\n/-- The (total) mass of a finite measure `\u03bc` is `\u03bc univ`, i.e., the cast to `nnreal` of\n`(\u03bc : measure \u03b1) univ`. -/\ndef mass (\u03bc : finite_measure \u03b1) : \u211d\u22650 := \u03bc univ\n\n@[simp] lemma ennreal_mass {\u03bc : finite_measure \u03b1} :\n  (\u03bc.mass : \u211d\u22650\u221e) = (\u03bc : measure \u03b1) univ := ennreal_coe_fn_eq_coe_fn_to_measure \u03bc set.univ\n\ninstance has_zero : has_zero (finite_measure \u03b1) :=\n{ zero := \u27e80, measure_theory.is_finite_measure_zero\u27e9 }\n\ninstance : inhabited (finite_measure \u03b1) := \u27e80\u27e9\n\ninstance : has_add (finite_measure \u03b1) :=\n{ add := \u03bb \u03bc \u03bd, \u27e8\u03bc + \u03bd, measure_theory.is_finite_measure_add\u27e9 }\n\ninstance : has_scalar \u211d\u22650 (finite_measure \u03b1) :=\n{ smul := \u03bb (c : \u211d\u22650) \u03bc, \u27e8c \u2022 \u03bc, measure_theory.is_finite_measure_smul_nnreal\u27e9, }\n\n@[simp, norm_cast] lemma coe_zero : (coe : finite_measure \u03b1 \u2192 measure \u03b1) 0 = 0 := rfl\n\n@[simp, norm_cast] lemma coe_add (\u03bc \u03bd : finite_measure \u03b1) : \u2191(\u03bc + \u03bd) = (\u2191\u03bc + \u2191\u03bd : measure \u03b1) := rfl\n\n@[simp, norm_cast] lemma coe_smul (c : \u211d\u22650) (\u03bc : finite_measure \u03b1) :\n  \u2191(c \u2022 \u03bc) = (c \u2022 \u2191\u03bc : measure \u03b1) := rfl\n\n@[simp, norm_cast] lemma coe_fn_zero :\n  (\u21d1(0 : finite_measure \u03b1) : set \u03b1 \u2192 \u211d\u22650) = (0 : set \u03b1 \u2192 \u211d\u22650) := by { funext, refl, }\n\n@[simp, norm_cast] lemma coe_fn_add (\u03bc \u03bd : finite_measure \u03b1) :\n  (\u21d1(\u03bc + \u03bd) : set \u03b1 \u2192 \u211d\u22650) = (\u21d1\u03bc + \u21d1\u03bd : set \u03b1 \u2192 \u211d\u22650) :=\nby { funext, simp [\u2190 ennreal.coe_eq_coe], }\n\n@[simp, norm_cast] lemma coe_fn_smul (c : \u211d\u22650) (\u03bc : finite_measure \u03b1) :\n  (\u21d1(c \u2022 \u03bc) : set \u03b1 \u2192 \u211d\u22650) = c \u2022 (\u21d1\u03bc : set \u03b1 \u2192 \u211d\u22650) :=\nby { funext, simp [\u2190 ennreal.coe_eq_coe], }\n\ninstance : add_comm_monoid (finite_measure \u03b1) :=\nfinite_measure.coe_injective.add_comm_monoid\n  (coe : finite_measure \u03b1 \u2192 measure \u03b1) finite_measure.coe_zero finite_measure.coe_add\n\n/-- Coercion is an `add_monoid_hom`. -/\n@[simps]\ndef coe_add_monoid_hom : finite_measure \u03b1 \u2192+ measure \u03b1 :=\n{ to_fun := coe, map_zero' := coe_zero, map_add' := coe_add }\n\ninstance {\u03b1 : Type*} [measurable_space \u03b1] : module \u211d\u22650 (finite_measure \u03b1) :=\nfunction.injective.module _ coe_add_monoid_hom finite_measure.coe_injective coe_smul\n\nvariables [topological_space \u03b1]\n\n/-- The pairing of a finite (Borel) measure `\u03bc` with a nonnegative bounded continuous\nfunction is obtained by (Lebesgue) integrating the (test) function against the measure.\nThis is `finite_measure.test_against_nn`. -/\ndef test_against_nn (\u03bc : finite_measure \u03b1) (f : \u03b1 \u2192\u1d47 \u211d\u22650) : \u211d\u22650 :=\n(\u222b\u207b x, f x \u2202(\u03bc : measure \u03b1)).to_nnreal\n\nlemma _root_.bounded_continuous_function.nnreal.to_ennreal_comp_measurable {\u03b1 : Type*}\n  [topological_space \u03b1] [measurable_space \u03b1] [opens_measurable_space \u03b1] (f : \u03b1 \u2192\u1d47 \u211d\u22650) :\n  measurable (\u03bb x, (f x : \u211d\u22650\u221e)) :=\nmeasurable_coe_nnreal_ennreal.comp f.continuous.measurable\n\nlemma lintegral_lt_top_of_bounded_continuous_to_nnreal (\u03bc : finite_measure \u03b1) (f : \u03b1 \u2192\u1d47 \u211d\u22650) :\n  \u222b\u207b x, f x \u2202(\u03bc : measure \u03b1) < \u221e :=\nbegin\n  apply is_finite_measure.lintegral_lt_top_of_bounded_to_ennreal,\n  use nndist f 0,\n  intros x,\n  have key := bounded_continuous_function.nnreal.upper_bound f x,\n  rw ennreal.coe_le_coe,\n  have eq : nndist f 0 = \u27e8dist f 0, dist_nonneg\u27e9,\n  { ext,\n    simp only [real.coe_to_nnreal', max_eq_left_iff, subtype.coe_mk, coe_nndist], },\n  rwa eq at key,\nend\n\n@[simp] lemma test_against_nn_coe_eq {\u03bc : finite_measure \u03b1} {f : \u03b1 \u2192\u1d47 \u211d\u22650} :\n  (\u03bc.test_against_nn f : \u211d\u22650\u221e) = \u222b\u207b x, f x \u2202(\u03bc : measure \u03b1) :=\nennreal.coe_to_nnreal (lintegral_lt_top_of_bounded_continuous_to_nnreal \u03bc f).ne\n\nlemma test_against_nn_const (\u03bc : finite_measure \u03b1) (c : \u211d\u22650) :\n  \u03bc.test_against_nn (bounded_continuous_function.const \u03b1 c) = c * \u03bc.mass :=\nby simp [\u2190 ennreal.coe_eq_coe]\n\nlemma test_against_nn_mono (\u03bc : finite_measure \u03b1)\n  {f g : \u03b1 \u2192\u1d47 \u211d\u22650} (f_le_g : (f : \u03b1 \u2192 \u211d\u22650) \u2264 g) :\n  \u03bc.test_against_nn f \u2264 \u03bc.test_against_nn g :=\nbegin\n  simp only [\u2190ennreal.coe_le_coe, test_against_nn_coe_eq],\n  apply lintegral_mono,\n  exact \u03bb x, ennreal.coe_mono (f_le_g x),\nend\n\nvariables [opens_measurable_space \u03b1]\n\nlemma test_against_nn_add (\u03bc : finite_measure \u03b1) (f\u2081 f\u2082 : \u03b1 \u2192\u1d47 \u211d\u22650) :\n  \u03bc.test_against_nn (f\u2081 + f\u2082) = \u03bc.test_against_nn f\u2081 + \u03bc.test_against_nn f\u2082 :=\nbegin\n  simp only [\u2190ennreal.coe_eq_coe, bounded_continuous_function.coe_add, ennreal.coe_add,\n             pi.add_apply, test_against_nn_coe_eq],\n  apply lintegral_add;\n  exact bounded_continuous_function.nnreal.to_ennreal_comp_measurable _,\nend\n\nlemma test_against_nn_smul (\u03bc : finite_measure \u03b1) (c : \u211d\u22650) (f : \u03b1 \u2192\u1d47 \u211d\u22650) :\n  \u03bc.test_against_nn (c \u2022 f) = c * \u03bc.test_against_nn f :=\nbegin\n  simp only [\u2190ennreal.coe_eq_coe, algebra.id.smul_eq_mul, bounded_continuous_function.coe_smul,\n             test_against_nn_coe_eq, ennreal.coe_mul],\n  exact @lintegral_const_mul _ _ (\u03bc : measure \u03b1) c _\n                   (bounded_continuous_function.nnreal.to_ennreal_comp_measurable f),\nend\n\nlemma test_against_nn_lipschitz_estimate (\u03bc : finite_measure \u03b1) (f g : \u03b1 \u2192\u1d47 \u211d\u22650) :\n  \u03bc.test_against_nn f \u2264 \u03bc.test_against_nn g + (nndist f g) * \u03bc.mass :=\nbegin\n  simp only [\u2190\u03bc.test_against_nn_const (nndist f g), \u2190test_against_nn_add, \u2190ennreal.coe_le_coe,\n             bounded_continuous_function.coe_add, const_apply, ennreal.coe_add, pi.add_apply,\n             coe_nnreal_ennreal_nndist, test_against_nn_coe_eq],\n  apply lintegral_mono,\n  have le_dist : \u2200 x, dist (f x) (g x) \u2264 nndist f g :=\n  bounded_continuous_function.dist_coe_le_dist,\n  intros x,\n  have le' : f(x) \u2264 g(x) + nndist f g,\n  { apply (nnreal.le_add_nndist (f x) (g x)).trans,\n    rw add_le_add_iff_left,\n    exact dist_le_coe.mp (le_dist x), },\n  have le : (f(x) : \u211d\u22650\u221e) \u2264 (g(x) : \u211d\u22650\u221e) + (nndist f g),\n  by { rw \u2190ennreal.coe_add, exact ennreal.coe_mono le', },\n  rwa [coe_nnreal_ennreal_nndist] at le,\nend\n\nlemma test_against_nn_lipschitz (\u03bc : finite_measure \u03b1) :\n  lipschitz_with \u03bc.mass (\u03bb (f : \u03b1 \u2192\u1d47 \u211d\u22650), \u03bc.test_against_nn f) :=\nbegin\n  rw lipschitz_with_iff_dist_le_mul,\n  intros f\u2081 f\u2082,\n  suffices : abs (\u03bc.test_against_nn f\u2081 - \u03bc.test_against_nn f\u2082 : \u211d) \u2264 \u03bc.mass * (dist f\u2081 f\u2082),\n  { rwa nnreal.dist_eq, },\n  apply abs_le.mpr,\n  split,\n  { have key' := \u03bc.test_against_nn_lipschitz_estimate f\u2082 f\u2081,\n    rw mul_comm at key',\n    suffices : \u2191(\u03bc.test_against_nn f\u2082) \u2264 \u2191(\u03bc.test_against_nn f\u2081) + \u2191(\u03bc.mass) * dist f\u2081 f\u2082,\n    { linarith, },\n    have key := nnreal.coe_mono key',\n    rwa [nnreal.coe_add, nnreal.coe_mul, nndist_comm] at key, },\n  { have key' := \u03bc.test_against_nn_lipschitz_estimate f\u2081 f\u2082,\n    rw mul_comm at key',\n    suffices : \u2191(\u03bc.test_against_nn f\u2081) \u2264 \u2191(\u03bc.test_against_nn f\u2082) + \u2191(\u03bc.mass) * dist f\u2081 f\u2082,\n    { linarith, },\n    have key := nnreal.coe_mono key',\n    rwa [nnreal.coe_add, nnreal.coe_mul] at key, },\nend\n\n/-- Finite measures yield elements of the `weak_dual` of bounded continuous nonnegative\nfunctions via `finite_measure.test_against_nn`, i.e., integration. -/\ndef to_weak_dual_bounded_continuous_nnreal (\u03bc : finite_measure \u03b1) :\n  weak_dual \u211d\u22650 (\u03b1 \u2192\u1d47 \u211d\u22650) :=\n{ to_fun := \u03bb f, \u03bc.test_against_nn f,\n  map_add' := test_against_nn_add \u03bc,\n  map_smul' := test_against_nn_smul \u03bc,\n  cont := \u03bc.test_against_nn_lipschitz.continuous, }\n\nend finite_measure\n\n/-- Probability measures are defined as the subtype of measures that have the property of being\nprobability measures (i.e., their total mass is one). -/\ndef probability_measure (\u03b1 : Type*) [measurable_space \u03b1] : Type* :=\n{\u03bc : measure \u03b1 // is_probability_measure \u03bc}\n\nnamespace probability_measure\n\ninstance [inhabited \u03b1] : inhabited (probability_measure \u03b1) :=\n\u27e8\u27e8measure.dirac default, measure.dirac.is_probability_measure\u27e9\u27e9\n\n/-- A probability measure can be interpreted as a measure. -/\ninstance : has_coe (probability_measure \u03b1) (measure_theory.measure \u03b1) := coe_subtype\n\ninstance : has_coe_to_fun (probability_measure \u03b1) (\u03bb _, set \u03b1 \u2192 \u211d\u22650) :=\n\u27e8\u03bb \u03bc s, (\u03bc s).to_nnreal\u27e9\n\ninstance (\u03bc : probability_measure \u03b1) : is_probability_measure (\u03bc : measure \u03b1) := \u03bc.prop\n\nlemma coe_fn_eq_to_nnreal_coe_fn_to_measure (\u03bd : probability_measure \u03b1) :\n  (\u03bd : set \u03b1 \u2192 \u211d\u22650) = \u03bb s, ((\u03bd : measure \u03b1) s).to_nnreal := rfl\n\n@[simp] lemma val_eq_to_measure (\u03bd : probability_measure \u03b1) : \u03bd.val = (\u03bd : measure \u03b1) := rfl\n\nlemma coe_injective : function.injective (coe : probability_measure \u03b1 \u2192 measure \u03b1) :=\nsubtype.coe_injective\n\n@[simp] lemma coe_fn_univ (\u03bd : probability_measure \u03b1) : \u03bd univ = 1 :=\ncongr_arg ennreal.to_nnreal \u03bd.prop.measure_univ\n\n/-- A probability measure can be interpreted as a finite measure. -/\ndef to_finite_measure (\u03bc : probability_measure \u03b1) : finite_measure \u03b1 := \u27e8\u03bc, infer_instance\u27e9\n\n@[simp] lemma coe_comp_to_finite_measure_eq_coe (\u03bd : probability_measure \u03b1) :\n  (\u03bd.to_finite_measure : measure \u03b1) = (\u03bd : measure \u03b1) := rfl\n\n@[simp] lemma coe_fn_comp_to_finite_measure_eq_coe_fn (\u03bd : probability_measure \u03b1) :\n  (\u03bd.to_finite_measure : set \u03b1 \u2192 \u211d\u22650) = (\u03bd : set \u03b1 \u2192 \u211d\u22650) := rfl\n\n@[simp] lemma ennreal_coe_fn_eq_coe_fn_to_measure (\u03bd : probability_measure \u03b1) (s : set \u03b1) :\n  (\u03bd s : \u211d\u22650\u221e) = (\u03bd : measure \u03b1) s :=\nby { rw [\u2190 coe_fn_comp_to_finite_measure_eq_coe_fn,\n     finite_measure.ennreal_coe_fn_eq_coe_fn_to_measure], refl, }\n\n@[simp] lemma mass_to_finite_measure (\u03bc : probability_measure \u03b1) :\n  \u03bc.to_finite_measure.mass = 1 := \u03bc.coe_fn_univ\n\nvariables [topological_space \u03b1]\n\n/-- The pairing of a (Borel) probability measure `\u03bc` with a nonnegative bounded continuous\nfunction is obtained by (Lebesgue) integrating the (test) function against the measure. This\nis `probability_measure.test_against_nn`. -/\ndef test_against_nn\n  (\u03bc : probability_measure \u03b1) (f : \u03b1 \u2192\u1d47 \u211d\u22650) : \u211d\u22650 :=\n(lintegral (\u03bc : measure \u03b1) ((coe : \u211d\u22650 \u2192 \u211d\u22650\u221e) \u2218 f)).to_nnreal\n\nlemma lintegral_lt_top_of_bounded_continuous_to_nnreal (\u03bc : probability_measure \u03b1) (f : \u03b1 \u2192\u1d47 \u211d\u22650) :\n  \u222b\u207b x, f x \u2202(\u03bc : measure \u03b1) < \u221e :=\n\u03bc.to_finite_measure.lintegral_lt_top_of_bounded_continuous_to_nnreal f\n\n@[simp] lemma test_against_nn_coe_eq {\u03bc : probability_measure \u03b1} {f : \u03b1 \u2192\u1d47 \u211d\u22650} :\n  (\u03bc.test_against_nn f : \u211d\u22650\u221e) = \u222b\u207b x, f x \u2202(\u03bc : measure \u03b1) :=\nennreal.coe_to_nnreal (lintegral_lt_top_of_bounded_continuous_to_nnreal \u03bc f).ne\n\n@[simp] lemma to_finite_measure_test_against_nn_eq_test_against_nn\n  {\u03bc : probability_measure \u03b1} {f : \u03b1 \u2192\u1d47 nnreal} :\n  \u03bc.to_finite_measure.test_against_nn f = \u03bc.test_against_nn f := rfl\n\nlemma test_against_nn_const (\u03bc : probability_measure \u03b1) (c : \u211d\u22650) :\n  \u03bc.test_against_nn (bounded_continuous_function.const \u03b1 c) = c :=\nby simp [\u2190 ennreal.coe_eq_coe, (measure_theory.is_probability_measure \u03bc).measure_univ]\n\nlemma test_against_nn_mono (\u03bc : probability_measure \u03b1)\n  {f g : \u03b1 \u2192\u1d47 \u211d\u22650} (f_le_g : (f : \u03b1 \u2192 \u211d\u22650) \u2264 g) :\n  \u03bc.test_against_nn f \u2264 \u03bc.test_against_nn g :=\nby simpa using \u03bc.to_finite_measure.test_against_nn_mono f_le_g\n\nvariables [opens_measurable_space \u03b1]\n\nlemma test_against_nn_lipschitz (\u03bc : probability_measure \u03b1) :\n  lipschitz_with 1 (\u03bb (f : \u03b1 \u2192\u1d47 \u211d\u22650), \u03bc.test_against_nn f) :=\nbegin\n  have key := \u03bc.to_finite_measure.test_against_nn_lipschitz,\n  rwa \u03bc.mass_to_finite_measure at key,\nend\n\n/-- Probability measures yield elements of the `weak_dual` of bounded continuous nonnegative\nfunctions via `probability_measure.test_against_nn`, i.e., integration. -/\ndef to_weak_dual_bounded_continuous_nnreal (\u03bc : probability_measure \u03b1) :\n  weak_dual \u211d\u22650 (\u03b1 \u2192\u1d47 \u211d\u22650) :=\n{ to_fun := \u03bb f, \u03bc.test_against_nn f,\n  map_add' := \u03bc.to_finite_measure.test_against_nn_add,\n  map_smul' := \u03bc.to_finite_measure.test_against_nn_smul,\n  cont := \u03bc.test_against_nn_lipschitz.continuous, }\n\nend probability_measure\n\nend measure_theory\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/measure_theory/measure/finite_measure_weak_convergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7310701093216279}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport field_theory.galois\n/-\n\n# Galois extensions\n\nAn extension is Galois if it's algebraic, normal and separable (note that both\nnormal and separable imply algebraic in Lean).\n\n-/\n\nvariables (E F : Type) [field E] [field F] [algebra E F] [is_galois E F]\n\n/-\n\nThe Galois group Gal(F/E) doesn't have special notation, it's just the F-algebra isomorphisms\nfrom E to itself\n\n-/\n\nexample : Type := F \u2243\u2090[E] F\n\n-- It's a group\n\nexample : group (F \u2243\u2090[E] F) := infer_instance\n\n-- If F/E is furthermore finite-dimensional then its dimension is the size of the group.\n\nopen finite_dimensional\n\nexample [finite_dimensional E F] : fintype.card (F \u2243\u2090[E] F) = finrank E F :=\nis_galois.card_aut_eq_finrank E F \n\n-- The fundamental theorem of Galois theory for finite Galois extensions\n-- is an order-reversing bijection between subgroups of the Galois group \n-- and intermediate fields of the field extension. Here are the maps:\n\nexample : subgroup (F \u2243\u2090[E] F) \u2192 intermediate_field E F := intermediate_field.fixed_field\nexample : intermediate_field E F \u2192 subgroup (F \u2243\u2090[E] F) := intermediate_field.fixing_subgroup\n\nopen intermediate_field\n\nvariable [finite_dimensional E F]\n\n-- They're inverse bijections\nexample (H : subgroup (F \u2243\u2090[E] F)) : fixing_subgroup (fixed_field H) = H := fixing_subgroup_fixed_field H\nexample (L : intermediate_field E F) : fixed_field (fixing_subgroup L) = L := is_galois.fixed_field_fixing_subgroup L\n-- weirdly, one of those is in the `is_galois` namespace and the other isn't. \n\n-- In the finite Galois case, this can be summarised as follows (\u2243o is order-preserving bijection; \u1d52\u1d48 is \"same set but reverse the order\")\nexample : intermediate_field E F \u2243o (subgroup (F \u2243\u2090[E] F))\u1d52\u1d48 := is_galois.intermediate_field_equiv_subgroup\n\n-- I don't know if we have the result that the subgroup `H` is normal iff the subfield `L` is normal over `E`.\n\n-- The results described above and the techniques used to prove them are described in this 2021 paper\n-- by Browning and Lutz : https://arxiv.org/abs/2107.10988\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section21galois_theory/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7310701086491909}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport data.zsqrtd.basic\nimport data.complex.basic\nimport ring_theory.principal_ideal_domain\nimport number_theory.quadratic_reciprocity\n/-!\n# Gaussian integers\n\nThe Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both\nintegers.\n\n## Main definitions\n\nThe Euclidean domain structure on `\u2124[i]` is defined in this file.\n\nThe homomorphism `to_complex` into the complex numbers is also defined in this file.\n\n## Main statements\n\n`prime_iff_mod_four_eq_three_of_nat_prime`\nA prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4`\n\n## Notations\n\nThis file uses the local notation `\u2124[i]` for `gaussian_int`\n\n## Implementation notes\n\nGaussian integers are implemented using the more general definition `zsqrtd`, the type of integers\nadjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties\nand definitions about `zsqrtd` can easily be used.\n-/\n\nopen zsqrtd complex\n\n@[reducible] def gaussian_int : Type := zsqrtd (-1)\n\nlocal notation `\u2124[i]` := gaussian_int\n\nnamespace gaussian_int\n\ninstance : has_repr \u2124[i] := \u27e8\u03bb x, \"\u27e8\" ++ repr x.re ++ \", \" ++ repr x.im ++ \"\u27e9\"\u27e9\n\ninstance : comm_ring \u2124[i] := zsqrtd.comm_ring\n\nsection\nlocal attribute [-instance] complex.field -- Avoid making things noncomputable unnecessarily.\n\n/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/\ndef to_complex : \u2124[i] \u2192+* \u2102 :=\nzsqrtd.lift \u27e8I, by simp\u27e9\nend\n\ninstance : has_coe (\u2124[i]) \u2102 := \u27e8to_complex\u27e9\n\nlemma to_complex_def (x : \u2124[i]) : (x : \u2102) = x.re + x.im * I := rfl\n\nlemma to_complex_def' (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102) = x + y * I := by simp [to_complex_def]\n\nlemma to_complex_def\u2082 (x : \u2124[i]) : (x : \u2102) = \u27e8x.re, x.im\u27e9 :=\nby apply complex.ext; simp [to_complex_def]\n\n@[simp] lemma to_real_re (x : \u2124[i]) : ((x.re : \u2124) : \u211d) = (x : \u2102).re := by simp [to_complex_def]\n@[simp] lemma to_real_im (x : \u2124[i]) : ((x.im : \u2124) : \u211d) = (x : \u2102).im := by simp [to_complex_def]\n@[simp] lemma to_complex_re (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).re = x := by simp [to_complex_def]\n@[simp] lemma to_complex_im (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).im = y := by simp [to_complex_def]\n@[simp] lemma to_complex_add (x y : \u2124[i]) : ((x + y : \u2124[i]) : \u2102) = x + y := to_complex.map_add _ _\n@[simp] lemma to_complex_mul (x y : \u2124[i]) : ((x * y : \u2124[i]) : \u2102) = x * y := to_complex.map_mul _ _\n@[simp] lemma to_complex_one : ((1 : \u2124[i]) : \u2102) = 1 := to_complex.map_one\n@[simp] lemma to_complex_zero : ((0 : \u2124[i]) : \u2102) = 0 := to_complex.map_zero\n@[simp] lemma to_complex_neg (x : \u2124[i]) : ((-x : \u2124[i]) : \u2102) = -x := to_complex.map_neg _\n@[simp] lemma to_complex_sub (x y : \u2124[i]) : ((x - y : \u2124[i]) : \u2102) = x - y := to_complex.map_sub _ _\n\n@[simp] lemma to_complex_inj {x y : \u2124[i]} : (x : \u2102) = y \u2194 x = y :=\nby cases x; cases y; simp [to_complex_def\u2082]\n\n@[simp] lemma to_complex_eq_zero {x : \u2124[i]} : (x : \u2102) = 0 \u2194 x = 0 :=\nby rw [\u2190 to_complex_zero, to_complex_inj]\n\n@[simp] lemma nat_cast_real_norm (x : \u2124[i]) : (x.norm : \u211d) = (x : \u2102).norm_sq :=\nby rw [norm, norm_sq]; simp\n\n@[simp] lemma nat_cast_complex_norm (x : \u2124[i]) : (x.norm : \u2102) = (x : \u2102).norm_sq :=\nby cases x; rw [norm, norm_sq]; simp\n\nlemma norm_nonneg (x : \u2124[i]) : 0 \u2264 norm x := norm_nonneg (by norm_num) _\n\n@[simp] lemma norm_eq_zero {x : \u2124[i]} : norm x = 0 \u2194 x = 0 :=\nby rw [\u2190 @int.cast_inj \u211d _ _ _]; simp\n\nlemma norm_pos {x : \u2124[i]} : 0 < norm x \u2194 x \u2260 0 :=\nby rw [lt_iff_le_and_ne, ne.def, eq_comm, norm_eq_zero]; simp [norm_nonneg]\n\n@[simp] lemma coe_nat_abs_norm (x : \u2124[i]) : (x.norm.nat_abs : \u2124) = x.norm :=\nint.nat_abs_of_nonneg (norm_nonneg _)\n\n@[simp] lemma nat_cast_nat_abs_norm {\u03b1 : Type*} [ring \u03b1]\n  (x : \u2124[i]) : (x.norm.nat_abs : \u03b1) = x.norm :=\nby rw [\u2190 int.cast_coe_nat, coe_nat_abs_norm]\n\nlemma nat_abs_norm_eq (x : \u2124[i]) : x.norm.nat_abs =\n  x.re.nat_abs * x.re.nat_abs + x.im.nat_abs * x.im.nat_abs :=\nint.coe_nat_inj $ begin simp, simp [norm] end\n\nprotected def div (x y : \u2124[i]) : \u2124[i] :=\nlet n := (rat.of_int (norm y))\u207b\u00b9 in let c := y.conj in\n\u27e8round (rat.of_int (x * c).re * n : \u211a),\n round (rat.of_int (x * c).im * n : \u211a)\u27e9\n\ninstance : has_div \u2124[i] := \u27e8gaussian_int.div\u27e9\n\nlemma div_def (x y : \u2124[i]) : x / y = \u27e8round ((x * conj y).re / norm y : \u211a),\n  round ((x * conj y).im / norm y : \u211a)\u27e9 :=\nshow zsqrtd.mk _ _ = _, by simp [rat.of_int_eq_mk, rat.mk_eq_div, div_eq_mul_inv]\n\nlemma to_complex_div_re (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).re = round ((x / y : \u2102).re) :=\nby rw [div_def, \u2190 @rat.cast_round \u211d _ _];\n  simp [-rat.cast_round, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlemma to_complex_div_im (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).im = round ((x / y : \u2102).im) :=\nby rw [div_def, \u2190 @rat.cast_round \u211d _ _, \u2190 @rat.cast_round \u211d _ _];\n  simp [-rat.cast_round, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlocal notation `abs'` := _root_.abs\n\nlemma norm_sq_le_norm_sq_of_re_le_of_im_le {x y : \u2102} (hre : abs' x.re \u2264 abs' y.re)\n  (him : abs' x.im \u2264 abs' y.im) : x.norm_sq \u2264 y.norm_sq :=\nby rw [norm_sq_apply, norm_sq_apply, \u2190 _root_.abs_mul_self, _root_.abs_mul,\n  \u2190 _root_.abs_mul_self y.re, _root_.abs_mul y.re,\n  \u2190 _root_.abs_mul_self x.im, _root_.abs_mul x.im,\n  \u2190 _root_.abs_mul_self y.im, _root_.abs_mul y.im]; exact\n(add_le_add (mul_self_le_mul_self (abs_nonneg _) hre)\n  (mul_self_le_mul_self (abs_nonneg _) him))\n\nlemma norm_sq_div_sub_div_lt_one (x y : \u2124[i]) :\n  ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq < 1 :=\ncalc ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq =\n    ((x / y : \u2102).re - ((x / y : \u2124[i]) : \u2102).re +\n    ((x / y : \u2102).im - ((x / y : \u2124[i]) : \u2102).im) * I : \u2102).norm_sq :\n      congr_arg _ $ by apply complex.ext; simp\n  ... \u2264 (1 / 2 + 1 / 2 * I).norm_sq :\n  have abs' (2\u207b\u00b9 : \u211d) = 2\u207b\u00b9, from _root_.abs_of_nonneg (by norm_num),\n  norm_sq_le_norm_sq_of_re_le_of_im_le\n    (by rw [to_complex_div_re]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).re)\n    (by rw [to_complex_div_im]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).im)\n  ... < 1 : by simp [norm_sq]; norm_num\n\nprotected def mod (x y : \u2124[i]) : \u2124[i] := x - y * (x / y)\n\ninstance : has_mod \u2124[i] := \u27e8gaussian_int.mod\u27e9\n\nlemma mod_def (x y : \u2124[i]) : x % y = x - y * (x / y) := rfl\n\nlemma norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) : (x % y).norm < y.norm :=\nhave (y : \u2102) \u2260 0, by rwa [ne.def, \u2190 to_complex_zero, to_complex_inj],\n(@int.cast_lt \u211d _ _ _ _).1 $\n  calc \u2191(norm (x % y)) = (x - y * (x / y : \u2124[i]) : \u2102).norm_sq : by simp [mod_def]\n  ... = (y : \u2102).norm_sq * (((x / y) - (x / y : \u2124[i])) : \u2102).norm_sq :\n    by rw [\u2190 norm_sq_mul, mul_sub, mul_div_cancel' _ this]\n  ... < (y : \u2102).norm_sq * 1 : mul_lt_mul_of_pos_left (norm_sq_div_sub_div_lt_one _ _)\n    (norm_sq_pos.2 this)\n  ... = norm y : by simp\n\nlemma nat_abs_norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (x % y).norm.nat_abs < y.norm.nat_abs :=\nint.coe_nat_lt.1 (by simp [-int.coe_nat_lt, norm_mod_lt x hy])\n\nlemma norm_le_norm_mul_left (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (norm x).nat_abs \u2264 (norm (x * y)).nat_abs :=\nby rw [norm_mul, int.nat_abs_mul];\n  exact le_mul_of_one_le_right (nat.zero_le _)\n    (int.coe_nat_le.1 (by rw [coe_nat_abs_norm]; exact int.add_one_le_of_lt (norm_pos.2 hy)))\n\ninstance : nontrivial \u2124[i] :=\n\u27e8\u27e80, 1, dec_trivial\u27e9\u27e9\n\ninstance : euclidean_domain \u2124[i] :=\n{ quotient := (/),\n  remainder := (%),\n  quotient_zero := by { simp [div_def], refl },\n  quotient_mul_add_remainder_eq := \u03bb _ _, by simp [mod_def],\n  r := _,\n  r_well_founded := measure_wf (int.nat_abs \u2218 norm),\n  remainder_lt := nat_abs_norm_mod_lt,\n  mul_left_not_lt := \u03bb a b hb0, not_lt_of_ge $ norm_le_norm_mul_left a hb0,\n  .. gaussian_int.comm_ring,\n  .. gaussian_int.nontrivial }\n\nopen principal_ideal_ring\n\nlemma mod_four_eq_three_of_nat_prime_of_prime (p : \u2115) [hp : fact p.prime] (hpi : prime (p : \u2124[i])) :\n  p % 4 = 3 :=\nhp.1.eq_two_or_odd.elim\n  (\u03bb hp2, absurd hpi (mt irreducible_iff_prime.2 $\n    \u03bb \u27e8hu, h\u27e9, begin\n      have := h \u27e81, 1\u27e9 \u27e81, -1\u27e9 (hp2.symm \u25b8 rfl),\n      rw [\u2190 norm_eq_one_iff, \u2190 norm_eq_one_iff] at this,\n      exact absurd this dec_trivial\n    end))\n  (\u03bb hp1, by_contradiction $ \u03bb hp3 : p % 4 \u2260 3,\n    have hp41 : p % 4 = 1,\n      begin\n        rw [\u2190 nat.mod_mul_left_mod p 2 2, show 2 * 2 = 4, from rfl] at hp1,\n        have := nat.mod_lt p (show 0 < 4, from dec_trivial),\n        revert this hp3 hp1,\n        generalize : p % 4 = m, dec_trivial!,\n      end,\n    let \u27e8k, hk\u27e9 := (zmod.exists_sq_eq_neg_one_iff_mod_four_ne_three p).2 $\n      by rw hp41; exact dec_trivial in\n    begin\n      obtain \u27e8k, k_lt_p, rfl\u27e9 : \u2203 (k' : \u2115) (h : k' < p), (k' : zmod p) = k,\n      { refine \u27e8k.val, k.val_lt, zmod.nat_cast_zmod_val k\u27e9 },\n      have hpk : p \u2223 k ^ 2 + 1,\n        by rw [\u2190 char_p.cast_eq_zero_iff (zmod p) p]; simp *,\n      have hkmul : (k ^ 2 + 1 : \u2124[i]) = \u27e8k, 1\u27e9 * \u27e8k, -1\u27e9 :=\n        by simp [sq, zsqrtd.ext],\n      have hpne1 : p \u2260 1 := ne_of_gt hp.1.one_lt,\n      have hkltp : 1 + k * k < p * p,\n        from calc 1 + k * k \u2264 k + k * k :\n          add_le_add_right (nat.pos_of_ne_zero\n            (\u03bb hk0, by clear_aux_decl; simp [*, pow_succ'] at *)) _\n        ... = k * (k + 1) : by simp [add_comm, mul_add]\n        ... < p * p : mul_lt_mul k_lt_p k_lt_p (nat.succ_pos _) (nat.zero_le _),\n      have hpk\u2081 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, -1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (norm \u27e8k, -1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (-1 : \u2124) \u2260 0, from dec_trivial) $\n              by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpk\u2082 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, 1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (norm \u27e8k, 1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (1 : \u2124) \u2260 0, from dec_trivial) $\n                by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2\n        (by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n        exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1),\n      obtain \u27e8y, hy\u27e9 := hpk,\n      have := hpi.2.2 \u27e8k, 1\u27e9 \u27e8k, -1\u27e9 \u27e8y, by rw [\u2190 hkmul, \u2190 nat.cast_mul p, \u2190 hy]; simp\u27e9,\n      clear_aux_decl, tauto\n    end)\n\nlemma sq_add_sq_of_nat_prime_of_not_irreducible (p : \u2115) [hp : fact p.prime]\n  (hpi : \u00acirreducible (p : \u2124[i])) : \u2203 a b, a^2 + b^2 = p :=\nhave hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2 $\n  by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n    exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1,\nhave hab : \u2203 a b, (p : \u2124[i]) = a * b \u2227 \u00ac is_unit a \u2227 \u00ac is_unit b,\n  by simpa [irreducible_iff, hpu, not_forall, not_or_distrib] using hpi,\nlet \u27e8a, b, hpab, hau, hbu\u27e9 := hab in\nhave hnap : (norm a).nat_abs = p, from ((hp.1.mul_eq_prime_sq_iff\n    (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 $\n  by rw [\u2190 int.coe_nat_inj', int.coe_nat_pow, sq,\n    \u2190 @norm_nat_cast (-1), hpab];\n    simp).1,\n\u27e8a.re.nat_abs, a.im.nat_abs, by simpa [nat_abs_norm_eq, sq] using hnap\u27e9\n\nlemma prime_of_nat_prime_of_mod_four_eq_three (p : \u2115) [hp : fact p.prime] (hp3 : p % 4 = 3) :\n  prime (p : \u2124[i]) :=\nirreducible_iff_prime.1 $ classical.by_contradiction $ \u03bb hpi,\n  let \u27e8a, b, hab\u27e9 := sq_add_sq_of_nat_prime_of_not_irreducible p hpi in\nhave \u2200 a b : zmod 4, a^2 + b^2 \u2260 p, by erw [\u2190 zmod.nat_cast_mod 4 p, hp3]; exact dec_trivial,\nthis a b (hab \u25b8 by simp)\n\n/-- A prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4` -/\nlemma prime_iff_mod_four_eq_three_of_nat_prime (p : \u2115) [hp : fact p.prime] :\n  prime (p : \u2124[i]) \u2194 p % 4 = 3 :=\n\u27e8mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p\u27e9\n\nend gaussian_int\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/zsqrtd/gaussian_int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8397339676722394, "lm_q1q2_score": 0.7310701012645396}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson, Jalex Stark\n-/\nimport algebra.order.with_zero\nimport data.polynomial.monic\n/-!\n# Lemmas for the interaction between polynomials and `\u2211` and `\u220f`.\n\nRecall that `\u2211` and `\u220f` are notation for `finset.sum` and `finset.prod` respectively.\n\n## Main results\n\n- `polynomial.nat_degree_prod_of_monic` : the degree of a product of monic polynomials is the\n  product of degrees. We prove this only for `[comm_semiring R]`,\n  but it ought to be true for `[semiring R]` and `list.prod`.\n- `polynomial.nat_degree_prod` : for polynomials over an integral domain,\n  the degree of the product is the sum of degrees.\n- `polynomial.leading_coeff_prod` : for polynomials over an integral domain,\n  the leading coefficient is the product of leading coefficients.\n- `polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing\n  the second coefficient of the characteristic polynomial.\n-/\n\nopen finset\nopen multiset\n\nopen_locale big_operators\n\nuniverses u w\n\nvariables {R : Type u} {\u03b9 : Type w}\n\nnamespace polynomial\n\nvariables (s : finset \u03b9)\n\nsection semiring\n\nvariables {\u03b1 : Type*} [semiring \u03b1]\n\nlemma nat_degree_list_sum_le (l : list (polynomial \u03b1)) :\n  nat_degree l.sum \u2264 (l.map nat_degree).foldr max 0 :=\nlist.sum_le_foldr_max nat_degree (by simp) nat_degree_add_le _\n\nlemma nat_degree_multiset_sum_le (l : multiset (polynomial \u03b1)) :\n  nat_degree l.sum \u2264 (l.map nat_degree).foldr max max_left_comm 0 :=\nquotient.induction_on l (by simpa using nat_degree_list_sum_le)\n\nlemma nat_degree_sum_le (f : \u03b9 \u2192 polynomial \u03b1) :\n  nat_degree (\u2211 i in s, f i) \u2264 s.fold max 0 (nat_degree \u2218 f) :=\nby simpa using nat_degree_multiset_sum_le (s.val.map f)\n\nlemma degree_list_sum_le (l : list (polynomial \u03b1)) :\n  degree l.sum \u2264 (l.map nat_degree).maximum :=\nbegin\n  by_cases h : l.sum = 0,\n  { simp [h] },\n  { rw degree_eq_nat_degree h,\n    suffices : (l.map nat_degree).maximum = ((l.map nat_degree).foldr max 0 : \u2115),\n    { rw this,\n      simpa [this] using nat_degree_list_sum_le l },\n    rw list.maximum_eq_coe_foldr_max_of_ne_nil,\n    { congr },\n    contrapose! h,\n    rw [list.map_eq_nil] at h,\n    simp [h] }\nend\n\n\n\nlemma coeff_list_prod_of_nat_degree_le (l : list (polynomial \u03b1)) (n : \u2115)\n  (hl : \u2200 p \u2208 l, nat_degree p \u2264 n) :\n  coeff (list.prod l) (l.length * n) = (l.map (\u03bb p, coeff p n)).prod :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { have hl' : \u2200 (p \u2208 tl), nat_degree p \u2264 n := \u03bb p hp, hl p (list.mem_cons_of_mem _ hp),\n    simp only [list.prod_cons, list.map, list.length],\n    rw [add_mul, one_mul, add_comm, \u2190IH hl', mul_comm tl.length],\n    have h : nat_degree tl.prod \u2264 n * tl.length,\n    { refine (nat_degree_list_prod_le _).trans _,\n      rw [\u2190tl.length_map nat_degree, mul_comm],\n      refine list.sum_le_of_forall_le _ _ _,\n      simpa using hl' },\n    have hdn : nat_degree hd \u2264 n := hl _ (list.mem_cons_self _ _),\n    rcases hdn.eq_or_lt with rfl|hdn',\n    { cases h.eq_or_lt with h' h',\n      { rw [\u2190h', coeff_mul_degree_add_degree, leading_coeff, leading_coeff] },\n      { rw [coeff_eq_zero_of_nat_degree_lt, coeff_eq_zero_of_nat_degree_lt h', mul_zero],\n        exact nat_degree_mul_le.trans_lt (add_lt_add_left h' _) } },\n    { rw [coeff_eq_zero_of_nat_degree_lt hdn', coeff_eq_zero_of_nat_degree_lt, zero_mul],\n      exact nat_degree_mul_le.trans_lt (add_lt_add_of_lt_of_le hdn' h) } }\nend\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R] (f : \u03b9 \u2192 polynomial R) (t : multiset (polynomial R))\n\nlemma nat_degree_multiset_prod_le :\n  t.prod.nat_degree \u2264 (t.map nat_degree).sum :=\nquotient.induction_on t (by simpa using nat_degree_list_prod_le)\n\nlemma nat_degree_prod_le : (\u220f i in s, f i).nat_degree \u2264 \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_le (s.1.map f)\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_multiset_prod' (h : (t.map leading_coeff).prod \u2260 0) :\n  t.prod.leading_coeff = (t.map leading_coeff).prod :=\nbegin\n  induction t using multiset.induction_on with a t ih, { simp },\n  simp only [map_cons, multiset.prod_cons] at h \u22a2,\n  rw polynomial.leading_coeff_mul'; { rwa ih, apply right_ne_zero_of_mul h }\nend\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod' (s.1.map f) (by simpa using h)\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_multiset_prod' (h : (t.map (\u03bb f, leading_coeff f)).prod \u2260 0) :\n  t.prod.nat_degree = (t.map (\u03bb f, nat_degree f)).sum :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _), { simp },\n  rw [map_cons, multiset.prod_cons] at ht \u22a2,\n  rw [multiset.sum_cons, polynomial.nat_degree_mul', ih],\n  { apply right_ne_zero_of_mul ht },\n  { rwa polynomial.leading_coeff_multiset_prod', apply right_ne_zero_of_mul ht },\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod' (s.1.map f) (by simpa using h)\n\nlemma nat_degree_multiset_prod_of_monic [nontrivial R] (h : \u2200 f \u2208 t, monic f) :\n  t.prod.nat_degree = (t.map nat_degree).sum :=\nbegin\n  apply nat_degree_multiset_prod',\n  suffices : (t.map (\u03bb f, leading_coeff f)).prod = 1, { rw this, simp },\n  convert prod_repeat (1 : R) t.card,\n  { simp only [eq_repeat, multiset.card_map, eq_self_iff_true, true_and],\n    rintros i hi,\n    obtain \u27e8i, hi, rfl\u27e9 := multiset.mem_map.mp hi,\n    apply h, assumption },\n  { simp }\nend\n\nlemma nat_degree_prod_of_monic [nontrivial R] (h : \u2200 i \u2208 s, (f i).monic) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_of_monic (s.1.map f) (by simpa using h)\n\nlemma coeff_multiset_prod_of_nat_degree_le (n : \u2115)\n  (hl : \u2200 p \u2208 t, nat_degree p \u2264 n) :\n  coeff t.prod (t.card * n) = (t.map (\u03bb p, coeff p n)).prod :=\nbegin\n  induction t using quotient.induction_on,\n  simpa using coeff_list_prod_of_nat_degree_le _ _ hl\nend\n\nlemma coeff_prod_of_nat_degree_le (f : \u03b9 \u2192 polynomial R) (n : \u2115)\n  (h : \u2200 p \u2208 s, nat_degree (f p) \u2264 n) :\n  coeff (\u220f i in s, f i) (s.card * n) = \u220f i in s, coeff (f i) n :=\nbegin\n  cases s with l hl,\n  convert coeff_multiset_prod_of_nat_degree_le (l.map f) _ _,\n  { simp },\n  { simp },\n  { simpa using h }\nend\n\nlemma coeff_zero_multiset_prod :\n  t.prod.coeff 0 = (t.map (\u03bb f, coeff f 0)).prod :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ht, _), { simp },\n  rw [multiset.prod_cons, map_cons, multiset.prod_cons, polynomial.mul_coeff_zero, ht]\nend\n\nlemma coeff_zero_prod :\n  (\u220f i in s, f i).coeff 0 = \u220f i in s, (f i).coeff 0 :=\nby simpa using coeff_zero_multiset_prod (s.1.map f)\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nopen monic\n-- Eventually this can be generalized with Vieta's formulas\n-- plus the connection between roots and factorization.\nlemma multiset_prod_X_sub_C_next_coeff [nontrivial R] (t : multiset R) :\n  next_coeff (t.map (\u03bb x, X - C x)).prod = -t.sum :=\nbegin\n  rw next_coeff_multiset_prod,\n  { simp only [next_coeff_X_sub_C],\n    refine t.sum_hom \u27e8has_neg.neg, _, _\u27e9; simp [add_comm] },\n  { intros, apply monic_X_sub_C }\nend\n\nlemma prod_X_sub_C_next_coeff [nontrivial R] {s : finset \u03b9} (f : \u03b9 \u2192 R) :\n  next_coeff \u220f i in s, (X - C (f i)) = -\u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_next_coeff (s.1.map f)\n\nlemma multiset_prod_X_sub_C_coeff_card_pred [nontrivial R] (t : multiset R) (ht : 0 < t.card) :\n  (t.map (\u03bb x, (X - C x))).prod.coeff (t.card - 1) = -t.sum :=\nbegin\n  convert multiset_prod_X_sub_C_next_coeff (by assumption),\n  rw next_coeff, split_ifs,\n  { rw nat_degree_multiset_prod_of_monic at h; simp only [multiset.mem_map] at *,\n    swap, { rintros _ \u27e8_, _, rfl\u27e9, apply monic_X_sub_C },\n    simp_rw [multiset.sum_eq_zero_iff, multiset.mem_map] at h,\n    contrapose! h,\n    obtain \u27e8x, hx\u27e9 := card_pos_iff_exists_mem.mp ht,\n    exact \u27e8_, \u27e8_, \u27e8x, hx, rfl\u27e9, nat_degree_X_sub_C _\u27e9, one_ne_zero\u27e9 },\n  congr, rw nat_degree_multiset_prod_of_monic; { simp [nat_degree_X_sub_C, monic_X_sub_C] },\nend\n\nlemma prod_X_sub_C_coeff_card_pred [nontrivial R] (s : finset \u03b9) (f : \u03b9 \u2192 R) (hs : 0 < s.card) :\n  (\u220f i in s, (X - C (f i))).coeff (s.card - 1) = - \u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_coeff_card_pred (s.1.map f) (by simpa using hs)\n\nend comm_ring\n\nsection no_zero_divisors\nvariables [comm_ring R] [no_zero_divisors R] (f : \u03b9 \u2192 polynomial R) (t : multiset (polynomial R))\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees.\n\nSee `polynomial.nat_degree_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma nat_degree_prod [nontrivial R] (h : \u2200 i \u2208 s, f i \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nbegin\n  apply nat_degree_prod',\n  rw prod_ne_zero_iff,\n  intros x hx, simp [h x hx]\nend\n\nlemma nat_degree_multiset_prod [nontrivial R] (s : multiset (polynomial R))\n  (h : (0 : polynomial R) \u2209 s) :\n  nat_degree s.prod = (s.map nat_degree).sum :=\nbegin\n  rw nat_degree_multiset_prod',\n  simp_rw [ne.def, multiset.prod_eq_zero_iff, multiset.mem_map, leading_coeff_eq_zero],\n  rintro \u27e8_, h, rfl\u27e9,\n  contradiction\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_multiset_prod [nontrivial R] :\n  t.prod.degree = (t.map (\u03bb f, degree f)).sum :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ht, _), { simp },\n  { rw [multiset.prod_cons, degree_mul, ht, map_cons, multiset.sum_cons] }\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_prod [nontrivial R] : (\u220f i in s, f i).degree = \u2211 i in s, (f i).degree :=\nby simpa using degree_multiset_prod (s.1.map f)\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_multiset_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_multiset_prod :\n  t.prod.leading_coeff = (t.map (\u03bb f, leading_coeff f)).prod :=\nby { rw [\u2190 leading_coeff_hom_apply, monoid_hom.map_multiset_prod], refl }\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_prod :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod (s.1.map f)\n\nend no_zero_divisors\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/polynomial/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7310700836758629}}
{"text": "\ntheorem Ex011(a b : Prop): (a \u2227 \u00aca) \u2192 b := \n  assume H1:(a \u2227 \u00aca),\n  have A:a, from and.elim_left H1,\n  have B:\u00aca, from and.elim_right H1,\n  have C:false, from B A,\n  show b, from false.elim C \n", "meta": {"author": "SvenWille", "repo": "LeanLogicExercises", "sha": "2dbc920feadd63bbc50f87e69646c0081db26eba", "save_path": "github-repos/lean/SvenWille-LeanLogicExercises", "path": "github-repos/lean/SvenWille-LeanLogicExercises/LeanLogicExercises-2dbc920feadd63bbc50f87e69646c0081db26eba/src/propLogic/Ex011.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9683812327313545, "lm_q2_score": 0.7549149923816046, "lm_q1q2_score": 0.7310455109298793}}
{"text": "/-\nCopyright (c) 2021 Ivan Sadofschi Costa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Ivan Sadofschi Costa.\n-/\nimport data.mv_polynomial.basic\nimport data.mv_polynomial.variables\nimport algebra.algebra.basic\nimport data.mv_polynomial.comm_ring\nimport data.nat.basic\nimport degree\n\nuniverses u v\n\nvariables {\u03b1 : Type v}\n\nopen set function finsupp add_monoid_algebra\n\n\nopen_locale big_operators \n\nnamespace mv_polynomial \n\nvariables {R : Type*} {\u03c3 : Type*} \n\n/- \n  \n  New definitions: monomial_degree, max_degree_monomial, dominant_monomial\n\n-/\n\n-- this def is also given in flt-regular\ndef monomial_degree {s : Type*} (t : s \u2192\u2080 \u2115) : \u2115 := t.sum (\u03bb _ e, e)\n\nlemma nat.term_le_sum {s : finset \u03b1 } (f : \u03b1 \u2192 \u2115){j : \u03b1} (hj : j \u2208 s) : f j \u2264 s.sum f :=\nbegin\n  revert j,\n  apply finset.cons_induction_on s,\n  { simp },\n  { clear s,\n    intros x s hx hj j hc,\n    rw finset.sum_cons,\n    simp only [finset.mem_cons] at hc,\n    cases hc with j_eq_x j_in_s,\n    { simp [j_eq_x] },\n    { simp [(hj j_in_s).trans] } },\nend\n\nlemma le_monomial_degree {s : Type*} (t : s \u2192\u2080 \u2115) (j : s) : t j \u2264 monomial_degree t :=\nbegin\n  by_cases c : j \u2208 t.support,\n  { exact nat.term_le_sum _ c },\n  { simp only [not_not, finsupp.mem_support_iff] at c,\n    simp [c] },\nend\n\n-- this holds for [ordered_add_comm_monoid N] if 0 \u2264 n forall n \u2208 N \nlemma finsupp.support_subset_of_le {s : Type*} {f g : s \u2192\u2080 \u2115} (h : f \u2264 g) :\nf.support \u2286 g.support := \nbegin\n  simp only [has_subset.subset, finsupp.mem_support_iff, ne.def],\n  intros a ha,\n  by_contra c,\n  simpa [c] using lt_of_lt_of_le (nat.pos_of_ne_zero ha) (h a),\nend\n\n-- this holds for [ordered_add_comm_monoid N] (with a different proof)\nlemma finsupp.sum_le_sum {s : Type*} {f g : s \u2192\u2080 \u2115} (h : f \u2264 g) :\nf.sum (\u03bb x y , y) \u2264 g.sum (\u03bb x y , y) :=\nbegin\n  rw [sum_of_support_subset f (finsupp.support_subset_of_le h) (\u03bb x y, y) (by simp), finsupp.sum],\n  apply finset.sum_le_sum,\n  intros i hi,\n  simp only [h i],\nend\n\nlemma monomial_degree_le_of_le {\u03c3 : Type*} {m m' : \u03c3 \u2192\u2080 \u2115} (h : m' \u2264 m) : \n  monomial_degree m' \u2264 monomial_degree m :=\nby simpa [monomial_degree] using finsupp.sum_le_sum h\n\nlemma monomial_degree_add {\u03c3 : Type*} (m m' : \u03c3 \u2192\u2080 \u2115) : \n  monomial_degree (m + m') = monomial_degree m + monomial_degree m' :=\nby simp [monomial_degree, sum_add_index]\n\nlemma monomial_degree_sub {\u03c3 : Type*} {m m' : \u03c3 \u2192\u2080 \u2115} (h : m' \u2264 m) : \n  monomial_degree (m - m') = monomial_degree m - monomial_degree m' := \nbegin\n  rw [eq_tsub_iff_add_eq_of_le (monomial_degree_le_of_le h), \u2190 monomial_degree_add],\n  congr,\n  ext a,\n  rw le_def at h,\n  simp only [pi.add_apply, coe_tsub, coe_add, pi.sub_apply, nat.sub_add_cancel (h a)],\nend\n\n-- is this on mathlib? name?\nlemma nat_lemma_2 { a b c : \u2115} (h' : c - a \u2264 b):  c \u2264 b + a :=\nbegin\n  by_cases h : a \u2264 c,\n  { zify,\n    rw [\u2190sub_le_iff_le_add, \u2190int.coe_nat_sub],\n    { rw int.coe_nat_le,\n      exact h' },\n    { exact h } },\n  { linarith }\nend\n\nlemma nat_lemma_1 {a b c : \u2115} (h : c \u2264 b) (h' : b - c \u2264 a) : a - (b - c) = a + c - b :=\nbegin\n  zify,\n  rw int.coe_nat_sub,\n  { rw [int.coe_nat_add, \u2190sub_add, sub_add_eq_add_sub] },\n  { apply nat_lemma_2 h' }\nend\n\nlemma monomial_lemma_2 { \u03c3 : Type*} { m m' a: \u03c3 \u2192\u2080 \u2115} (c : a - m \u2264 m') :  a \u2264 m' + m :=\nbegin\n  intro i,\n  simp only [pi.add_apply, coe_add],\n  apply nat_lemma_2 (c i),\nend\n\nlemma monomial_lemma_3 { \u03c3 : Type*} { m m' : \u03c3 \u2192\u2080 \u2115} : m \u2264 (m - m') + m' :=\nmonomial_lemma_2 (le_refl _)\n\nlemma monomial_lemma_1 { \u03c3 : Type*} { m m' a: \u03c3 \u2192\u2080 \u2115}\n  (h_m_le_a : m \u2264 a) (c : a - m \u2264 m'):  m' - (a - m) = m' + m - a :=\nbegin\n  ext i,\n  simp only [pi.add_apply, coe_tsub, coe_add, pi.sub_apply],\n  apply nat_lemma_1 (h_m_le_a i) (c i),\nend\n\nlemma monomial_degree_sub_le {\u03c3 : Type*} (m m' : \u03c3 \u2192\u2080 \u2115) : \n  monomial_degree m - monomial_degree m' \u2264 monomial_degree (m - m') := \nbegin\n  simp only [tsub_le_iff_right, \u2190monomial_degree_add],\n  apply monomial_degree_le_of_le,\n  apply monomial_lemma_3,\nend\n\nlemma monomial_degree_zero_iff {\u03c3 : Type*} {m : \u03c3 \u2192\u2080 \u2115} : monomial_degree m = 0 \u2194 m = 0 :=\nbegin\n  split,\n  { intro h,\n    ext i,\n    apply nat.eq_zero_of_le_zero _,\n    apply (le_monomial_degree m i).trans,\n    rw h, },\n  { intro h,\n    simp [h, monomial_degree], },\nend\n\n-- This depends on flt-regular. Use total_degree_monomial once its merged into mathlib\nlemma total_degree_monomial_eq_monomial_degree {\u03c3 R : Type*} [comm_semiring R] {m : \u03c3 \u2192\u2080 \u2115} {a : R} \n  (h : a \u2260 0): total_degree (monomial m a) = monomial_degree m :=\nby convert total_degree_monomial m h\n\n-- Use monomial instead of single!\nlemma monomial_degree_single {\u03c3 : Type*} {j : \u03c3} {d : \u2115} : monomial_degree (single j d) = d :=\nby simp [monomial_degree]\n\nlemma eq_single_of_monomial_degree_eq {\u03c3 : Type*}\n(m :  \u03c3 \u2192\u2080 \u2115) (i : \u03c3) : monomial_degree m = m i \u2192 m = single i (m i) :=\nbegin\n  intro h,\n  rw monomial_degree at h,\n  have h0 : single i (m i) \u2264 m := by simp,\n  suffices y : \u2200 j \u2208 m.support, m j \u2264 single i (m i) j,\n  { ext,\n    by_cases c : a \u2208 m.support,\n    { exact le_antisymm (y a c) (h0 a) },\n    { by_cases c' : i = a,\n      { simp only [c', single_eq_same] },\n      { simpa [c', single_eq_of_ne, ne.def, not_false_iff] using c, } } },\n  by_contra c,\n  simp only [not_le, not_forall] at c,\n  suffices x : m.sum (\u03bb (_x : \u03c3) (e : \u2115), e) < m.support.sum \u21d1m,\n  by simpa [finsupp.sum] using x,\n  simpa only [h, \u2190sum_of_support_subset _ (finsupp.support_subset_of_le h0) (\u03bb x y, y) (by simp),\n              sum_single_index] \n    using @finset.sum_lt_sum \u03c3 \u2115 _ (single i (m i)) m m.support (\u03bb i h, h0 i) c,\nend\n\nlemma monomial_degree_le_iff_eq_single {\u03c3 : Type*}\n  (m :  \u03c3 \u2192\u2080 \u2115) (i : \u03c3) : monomial_degree m \u2264 m i \u2194 m = single i (m i) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    exact eq_single_of_monomial_degree_eq m i (le_antisymm (le_monomial_degree m i) h).symm },\n  { intro h,\n    rw h,\n    simp [monomial_degree_single] },\nend\n\nlemma monomial_degree_le_total_degree {\u03c3 R : Type*}[comm_semiring R] {m : \u03c3 \u2192\u2080 \u2115} {f : mv_polynomial \u03c3 R} \n  (h : m \u2208 f.support) : monomial_degree m \u2264 total_degree f :=\nby simp [total_degree, monomial_degree, finset.le_sup h]\n\nlemma le_total_degree {R \u03c3 : Type*} [comm_semiring R] {i: \u03c3} {p : mv_polynomial \u03c3 R}\n  {m: \u03c3 \u2192\u2080 \u2115} (h_m : m \u2208 p.support) : m i \u2264 p.total_degree\n:= (le_monomial_degree m i).trans $ monomial_degree_le_total_degree h_m\n\nlemma coeff_zero_of_degree_greater_than_total_degree {R : Type*} [comm_semiring R]  (t : \u03c3 \u2192\u2080 \u2115) \n  (f : mv_polynomial \u03c3 R) : monomial_degree t > total_degree f \u2192 coeff t f = 0 :=\nbegin\n  intro h,\n  by_cases c: t \u2208 f.support,\n  { exfalso,\n    simpa using lt_of_le_of_lt (monomial_degree_le_total_degree c) h },\n  { simp only [not_not, mem_support_iff] at c,\n    exact c },\nend\n\ndef max_degree_monomial {R : Type*} [comm_semiring R] (t : \u03c3 \u2192\u2080 \u2115) (f : mv_polynomial \u03c3 R) : Prop\n:= t \u2208 f.support \u2227 monomial_degree t = total_degree f\n\n-- this uses a lemma from flt-regular\nlemma support_nonempty_iff {R \u03c3: Type*} [comm_semiring R]  {f : mv_polynomial \u03c3 R} :\n  f.support.nonempty \u2194 f \u2260 0 :=\nbegin\n  rw iff_not_comm,\n  simp only [support_eq_empty, finset.not_nonempty_iff_eq_empty], \nend\n\n-- see also flt-regular's exists_coeff_ne_zero_total_degree\nlemma exists_max_degree_monomial {R : Type*} [comm_semiring R] \n  {f : mv_polynomial \u03c3 R} (h : f \u2260 0) : \u2203 t, max_degree_monomial t f :=\nbegin\n  simp only [max_degree_monomial, total_degree, monomial_degree],\n  cases finset.exists_mem_eq_sup (f.support) (support_nonempty_iff.2 h)\n    (\u03bb (s : \u03c3 \u2192\u2080 \u2115), s.sum (\u03bb (n : \u03c3) (e : \u2115), e)) with m hm,\n  exact \u27e8m, \u27e8hm.1, hm.2.symm\u27e9\u27e9,\nend\n\nlemma eq_and_eq_of_le_add_le_eq {a1 a2 b1 b2 : \u2115} (h1: a1 \u2264 b1) (h2 : a2 \u2264 b2)\n  (h : a1 + a2 = b1 + b2) : a1 = b1 \u2227 a2 = b2 :=\nbegin\n  apply and.intro,\n  { by_cases c : a1 < b1,\n    { simpa [h] using add_lt_add_of_lt_of_le c h2 },\n    { exact le_antisymm h1 (not_lt.1 c) } },\n  { by_cases c : a2 < b2,\n    { simpa [h] using add_lt_add_of_le_of_lt h1 c },\n    { exact le_antisymm h2 (not_lt.1 c) } },\nend\n\nlemma max_degree_monomial_mul {\u03c3 R : Type*}[comm_ring R][is_domain R] {f g : mv_polynomial \u03c3 R}\n  {m : \u03c3 \u2192\u2080 \u2115} (hf : f \u2260 0) (hg : g \u2260 0) (h : max_degree_monomial m (f * g)) :\n  \u2203 mf mg, max_degree_monomial mf f \u2227 max_degree_monomial mg g \u2227 mf + mg = m := \nbegin\n  rw max_degree_monomial at h,\n  rcases support_mul'' h.1 with \u27e8mf, \u27e8mg, h'\u27e9\u27e9,\n  use mf,\n  use mg,\n  suffices x : monomial_degree mf = f.total_degree \u2227 monomial_degree mg = g.total_degree,\n  { exact \u27e8 \u27e8h'.1, x.1\u27e9 , \u27e8h'.2.1, x.2\u27e9, h'.2.2 \u27e9, },\n  apply eq_and_eq_of_le_add_le_eq (monomial_degree_le_total_degree h'.1)\n    (monomial_degree_le_total_degree h'.2.1),\n  simpa [ h.2, h'.2.2, \u2190monomial_degree_add] using total_degree_mul' hf hg,\nend\n\ndef dominant_monomial {R : Type*} [comm_semiring R]  (t : \u03c3 \u2192\u2080 \u2115) (f : mv_polynomial \u03c3 R) : Prop :=\nmax_degree_monomial t f \u2227 (\u2200 t' : \u03c3 \u2192\u2080 \u2115, max_degree_monomial t' f \u2192 t' = t)\n\nlemma dominant_monomial_of_factor_is_factor_of_max_degree_monomial\n  {R : Type*} [comm_ring R] [is_domain R] (S : finset R) (t t' : \u03c3 \u2192\u2080 \u2115 ) \n  (f g : mv_polynomial \u03c3 R) (hfg : max_degree_monomial t (f*g))\n  (hf : f \u2260 0) (hg : dominant_monomial t' g) : t' \u2264 t :=\nbegin\n  by_cases c : g = 0,\n  { rw [c, dominant_monomial, max_degree_monomial] at hg,\n    simpa using hg.1.1 },\n  { rcases max_degree_monomial_mul hf c hfg with \u27e8mf, \u27e8mg,h\u27e9\u27e9,\n    rw dominant_monomial at hg,\n    simp [\u2190hg.2 mg h.2.1, \u2190 h.2.2] },\nend\n\n-- near total_degree_eq\nlemma total_degree_eq' {R \u03c3 : Type*} [comm_semiring R] (p : mv_polynomial \u03c3 R) :\n  p.total_degree = p.support.sup (monomial_degree) :=\nbegin\n  rw [total_degree],\n  congr, funext m,\nend\n\nlemma total_degree_lt_iff {R \u03c3 : Type*} [comm_semiring R] {f : mv_polynomial \u03c3 R} {d : \u2115} (h : 0 < d) :\n  total_degree f < d \u2194 \u2200 m : \u03c3 \u2192\u2080 \u2115, m \u2208 f.support \u2192 monomial_degree m < d :=\nby rwa [total_degree_eq', finset.sup_lt_iff]\n\nlemma total_degree_sub_lt {R \u03c3 : Type*} [comm_ring R] [is_domain R] \n{f g : mv_polynomial \u03c3 R} {k : \u2115} (h : 0 < k)\n  (hf : \u2200 (m : \u03c3 \u2192\u2080 \u2115), m \u2208 f.support \u2192 (k \u2264 monomial_degree m) \u2192 coeff m f = coeff m g)\n  (hg : \u2200 (m : \u03c3 \u2192\u2080 \u2115), m \u2208 g.support \u2192 (k \u2264 monomial_degree m) \u2192 coeff m f = coeff m g) :\n  total_degree (f - g) < k :=\nbegin\n  rw total_degree_lt_iff h,\n  intros m hm,\n  by_contra hc,\n  simp only [not_lt] at hc,\n  have h' := support_sub \u03c3 f g hm,\n  simp only [mem_support_iff, ne.def, coeff_sub, sub_eq_zero] at hm,\n  simp [mem_union] at h',\n  cases h' with cf cg,\n  { exact hm (hf m (by simpa using cf) hc) },\n  { exact hm (hg m (by simpa using cg) hc) }\nend\n\nlemma max_degree_monomial_iff_of_eq_degree' {R \u03c3 : Type*} [comm_semiring R] (p : mv_polynomial \u03c3 R)\n {m m' : \u03c3 \u2192\u2080 \u2115} (hm' : m' \u2208 p.support) (h : monomial_degree m = monomial_degree m' ) : \n max_degree_monomial m p \u2192 max_degree_monomial m' p :=\nbegin\n  intro h',\n  split,\n  { exact hm' },\n  { rw \u2190 h,\n    exact h'.2 }\n end\n\nlemma max_degree_monomial_iff_of_eq_degree {R \u03c3 : Type*} [comm_semiring R] (p : mv_polynomial \u03c3 R)\n {m m' : \u03c3 \u2192\u2080 \u2115} (hm : m \u2208 p.support) (hm' : m' \u2208 p.support) (h : monomial_degree m = monomial_degree m') : \n max_degree_monomial m p \u2194 max_degree_monomial m' p :=\nbegin\n  split,\n  { apply max_degree_monomial_iff_of_eq_degree',\n    { exact hm' },\n    { exact h } },\n  { apply max_degree_monomial_iff_of_eq_degree',\n    { exact hm },\n    { exact h.symm } }\n end\n\nlemma max_degree_monomial_iff {R \u03c3 : Type*} [comm_ring R]\n{f : mv_polynomial \u03c3 R} { m : \u03c3 \u2192\u2080 \u2115} :\nmax_degree_monomial m f \u2194 m \u2208 f.support \u2227 \u2200 m' \u2208 f.support, \n  monomial_degree m' \u2264 monomial_degree m :=\nbegin\n  split,\n  { intro h,\n    split,\n    { exact h.1 },\n    { intros m' hm',\n      have t := h.2,\n      rw total_degree_eq' at t,\n      rw t,\n      apply finset.le_sup hm' } },\n  { intro h,\n    split,\n    { exact h.1 },\n    { rw total_degree_eq',\n      rw \u2190 finset.sup'_eq_sup,\n      { apply le_antisymm,\n        { apply finset.le_sup',\n          exact h.1 },\n        { apply finset.sup'_le,\n          exact h.2 } } } },\nend\n\nlemma dominant_monomial_iff {R \u03c3 : Type*} [comm_ring R]  {f : mv_polynomial \u03c3 R} { m : \u03c3 \u2192\u2080 \u2115} :\n  dominant_monomial m f \u2192 \u2200 m' \u2208 f.support, monomial_degree m' \u2264 monomial_degree m \n    \u2227 (monomial_degree m' = monomial_degree m \u2192 m' = m) :=\nbegin\n  intros h m' hm',\n  split,\n  { apply (max_degree_monomial_iff.1 h.1).2,\n    exact hm' },\n  { intro h1,\n    apply h.2,\n    rw max_degree_monomial_iff_of_eq_degree f hm' h.1.1 h1,\n    exact h.1}\nend\n\nlemma induction_on_total_degree {R \u03c3 : Type*} [comm_semiring R] {M : mv_polynomial \u03c3 R \u2192 Prop}\n (p : mv_polynomial \u03c3 R) (h : \u2200 (p' : mv_polynomial \u03c3 R),\n   (\u2200 q,  total_degree q < total_degree p' \u2192 M q) \u2192 M p') : M p :=\nbegin\n  let P : \u2115 \u2192 Prop := \u03bb n, \u2200 p : mv_polynomial \u03c3 R, total_degree p \u2264 n \u2192 M p,\n  suffices l' : \u2200 n, P n,\n  { apply l' (total_degree p),\n    refl },\n  { intro n,\n    induction n with d hd,\n    { intros p hp,\n      apply h p,\n      intros q hq,\n      simpa using lt_of_lt_of_le hq hp },\n    { intros p hp,\n      apply h p,\n      intros q hq,\n      exact hd q (nat.le_of_lt_succ (lt_of_lt_of_le hq hp)) } },\nend\n\nlocal attribute [instance] classical.prop_decidable\n\nlemma induction_on_new {R \u03c3 : Type*} [comm_semiring R] {M : mv_polynomial \u03c3 R \u2192 Prop} (p : mv_polynomial \u03c3 R)\n  (h_add_weak : \u2200 (a : \u03c3 \u2192\u2080 \u2115) (b : R) (f : (\u03c3 \u2192\u2080 \u2115) \u2192\u2080 R),\n    a \u2209 f.support \u2192 b \u2260 0 \u2192 M f \u2192 M (monomial a b) \u2192 M (monomial a b + f))\n  (h_monomial : \u2200 m : \u03c3 \u2192\u2080 \u2115, \u2200 b : R, \n    (\u2200 p : mv_polynomial \u03c3 R, total_degree p < monomial_degree m \u2192 M p) \u2192 M (monomial m b)) : M p :=\n  begin\n    apply induction_on_total_degree,\n    { intros p,\n      apply induction_on''' p,\n      { intros a h,\n        apply h_monomial,\n        intros x h2,\n        simpa [monomial_degree] using h2 },\n      { intros a b f ha hb hMf h,\n        apply h_add_weak a b f ha hb (hMf _),\n        { apply h_monomial,\n          intros p' hp',\n          suffices h' : p'.total_degree < (monomial a b).total_degree,\n          { apply (h p') \u2218 (lt_of_lt_of_le h'),\n            rw total_degree_add_eq_of_disjoint_support,\n            { simp only [le_refl, true_or, le_max_iff] },\n            { simpa only [ support_monomial, hb, not_not, mem_support_iff, if_false, \n                          finset.disjoint_singleton_left, not_not, finsupp.mem_support_iff]\n                using ha} },\n          rw total_degree_monomial_eq_monomial_degree,\n          { exact hp' },\n          { exact hb } },\n        { intros q hq,\n          apply (h q) \u2218 (lt_of_lt_of_le hq),\n          rw total_degree_add_eq_of_disjoint_support,\n          { simp only [le_refl, or_true, le_max_iff] },\n          { simpa only [support_monomial, hb, not_not, mem_support_iff, if_false, \n                        finset.disjoint_singleton_left, not_not, finsupp.mem_support_iff] \n             using ha} } } },\n  end\n  \nend mv_polynomial", "meta": {"author": "isadofschi", "repo": "combinatorial_nullstellensatz", "sha": "b5f2e75d51c3c8b9345d698a3ff4964c95bb5028", "save_path": "github-repos/lean/isadofschi-combinatorial_nullstellensatz", "path": "github-repos/lean/isadofschi-combinatorial_nullstellensatz/combinatorial_nullstellensatz-b5f2e75d51c3c8b9345d698a3ff4964c95bb5028/src/degree_new.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7310184391883996}}
{"text": "import data.real.basic analysis.special_functions.pow\n\nnamespace IMOSL\nnamespace extra\n\n/-!\n# Natural root in \u211d\n\nWe define the `n`th root in \u211d where `n` is a natural number.\nFor `n` even, we define the `n`th root of a negative real number `x` as `-(x^(1/n))`.\nIt has useful properties especially when `n` is odd.\n\nTODO:\n1. Prove properties when `n` is a `bit0`.\n2. Prove more properties in general.\n-/\n\nopen real function\nopen_locale classical\n\nnamespace real\n\n/-- odd-function `n`th root in \u211d -/\nnoncomputable def nat_root (n : \u2115) (x : \u211d) := ite (0 \u2264 x) (x ^ (n : \u211d)\u207b\u00b9) (- ((-x) ^ (n : \u211d)\u207b\u00b9))\n\nlemma nat_root_pow_self_bit1 (n : \u2115) (x : \u211d) : nat_root (bit1 n) (x ^ (bit1 n)) = x :=\nbegin\n  simp only [nat_root, pow_bit1_nonneg_iff],\n  by_cases h : 0 \u2264 x,\n  rw if_pos h; exact pow_nat_rpow_nat_inv h (nat.bit1_ne_zero n),\n  rw [if_neg h, \u2190 neg_pow_bit1, pow_nat_rpow_nat_inv _ (nat.bit1_ne_zero n), neg_neg],\n  rw [\u2190 lt_iff_not_le, \u2190 neg_pos] at h,\n  exact le_of_lt h\nend\n\nlemma pow_nat_root_self_bit1 (n : \u2115) (x : \u211d) : (nat_root (bit1 n) x) ^ (bit1 n) = x :=\nbegin\n  dsimp only [nat_root],\n  by_cases h : 0 \u2264 x,\n  rw if_pos h; exact rpow_nat_inv_pow_nat h (nat.bit1_ne_zero n),\n  rw [if_neg h, neg_pow_bit1, rpow_nat_inv_pow_nat _ (nat.bit1_ne_zero n), neg_neg],\n  rw [\u2190 lt_iff_not_le, \u2190 neg_pos] at h,\n  exact le_of_lt h\nend\n\nlemma pow_bit1_inj (n : \u2115) : injective (\u03bb x : \u211d, x ^ (bit1 n)) :=\nbegin\n  intros x y h; simp only [] at h,\n  rw [\u2190 nat_root_pow_self_bit1 n x, h, nat_root_pow_self_bit1]\nend\n\nlemma nat_root_bit1_inj (n : \u2115) : injective (nat_root (bit1 n)) :=\n  \u03bb x y h, by rw [\u2190 pow_nat_root_self_bit1 n x, h, pow_nat_root_self_bit1]\n\nlemma nat_root_bit1_mul (n : \u2115) (x y : \u211d) :\n    nat_root (bit1 n) (x * y) = nat_root (bit1 n) x * nat_root (bit1 n) y :=\n  pow_bit1_inj n (by simp only [mul_pow, pow_nat_root_self_bit1])\n\nlemma nat_root_bit1_inv (n : \u2115) (x : \u211d) : nat_root (bit1 n) x\u207b\u00b9 = (nat_root (bit1 n) x)\u207b\u00b9 :=\n  pow_bit1_inj n (by simp only [inv_pow, pow_nat_root_self_bit1])\n\nlemma nat_root_bit1_one (n : \u2115) : nat_root (bit1 n) 1 = 1 :=\n  pow_bit1_inj n (by simp only [pow_nat_root_self_bit1, one_pow])\n\nlemma nat_root_bit1_zero (n : \u2115) : nat_root (bit1 n) 0 = 0 :=\n  pow_bit1_inj n (by simp only [pow_nat_root_self_bit1, zero_pow (nat.zero_lt_bit1 n)])\n\nlemma nat_root_bit1_neg (n : \u2115) (x : \u211d) : nat_root (bit1 n) (-x) = -(nat_root (bit1 n) x) :=\n  pow_bit1_inj n (by simp only [pow_nat_root_self_bit1, neg_pow_bit1])\n\nlemma nat_root_bit1_pow (n : \u2115) (x : \u211d) (k : \u2115) :\n  nat_root (bit1 n) (x ^ k) = nat_root (bit1 n) x ^ k :=\nbegin\n  induction k with k k_ih,\n  rw [pow_zero, pow_zero, nat_root_bit1_one],\n  rw [pow_succ, nat_root_bit1_mul, k_ih, pow_succ]\nend\n\nlemma nat_root_bit1_left_mul (n : \u2115) (x y : \u211d) :\n    x * nat_root (bit1 n) y = nat_root (bit1 n) (x ^ (bit1 n) * y) :=\n  by rw [nat_root_bit1_mul, nat_root_pow_self_bit1]\n\nlemma nat_root_bit1_ne_zero (n : \u2115) {x : \u211d} (h : x \u2260 0) : nat_root (bit1 n) x \u2260 0 :=\n  by contrapose! h; apply nat_root_bit1_inj; rw [h, nat_root_bit1_zero]\n\nlemma nat_root_bit1_eq_one_iff (n : \u2115) (x : \u211d) : nat_root (bit1 n) x = 1 \u2194 x = 1 :=\n  \u27e8\u03bb h, nat_root_bit1_inj n (by rw [h, nat_root_bit1_one]), \u03bb h, by rw [h, nat_root_bit1_one]\u27e9\n\nlemma pow_bit1_eq_one_iff (n : \u2115) (x : \u211d) : x ^ (bit1 n) = 1 \u2194 x = 1 :=\n  \u27e8\u03bb h, pow_bit1_inj n (by simp only [h, one_pow]), \u03bb h, by rw [h, one_pow]\u27e9\n\nend real\n\nend extra\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/extra/real_prop/real_nat_root.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7309876856931604}}
{"text": "import data.set.finite group_theory.coset\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [group \u03b1]\n\nclass is_group_action (f : \u03b1 \u2192 \u03b2 \u2192 \u03b2) : Prop :=\n(one : \u2200 a : \u03b2, f (1 : \u03b1) a = a)\n(mul : \u2200 (x y : \u03b1) (a : \u03b2), f (x * y) a = f x (f y a))\n\nnamespace is_group_action\n\nvariables (f : \u03b1 \u2192 \u03b2 \u2192 \u03b2) [is_group_action f] \n\n@[simp] lemma one_apply (a : \u03b2) : f 1 a = a := is_group_action.one f a\n\nlemma mul_apply (x y : \u03b1) (a : \u03b2) : f (x * y) a = f x (f y a) := is_group_action.mul _ _ _ _\n\nlemma bijective (g : \u03b1) : function.bijective (f g) :=\nfunction.bijective_iff_has_inverse.2 \u27e8f (g\u207b\u00b9), \n  \u03bb a, by rw [\u2190 mul_apply f, inv_mul_self, one_apply f],\n  \u03bb a, by rw [\u2190 mul_apply f, mul_inv_self, one_apply f]\u27e9 \n\ndef orbit (a : \u03b2) := set.range (\u03bb x : \u03b1, f x a)\n\nlemma mem_orbit_iff {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} [is_group_action f] {a b : \u03b2} :\n  b \u2208 orbit f a \u2194 \u2203 x : \u03b1, f x a = b :=\niff.rfl\n\n@[simp] lemma mem_orbit (a : \u03b2) (x : \u03b1) :\n  f x a \u2208 orbit f a :=\n\u27e8x, rfl\u27e9\n\n@[simp] lemma mem_orbit_self (a : \u03b2) :\n  a \u2208 orbit f a :=\n\u27e81, show f 1 a = a, by simp [one_apply f]\u27e9\n\nlemma orbit_eq_iff {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} [is_group_action f] {a b : \u03b2} : \n  a \u2208 orbit f b \u2194 orbit f a = orbit f b :=\n\u27e8\u03bb \u27e8x, (hx : f x b = a)\u27e9, set.ext (\u03bb c, \u27e8\u03bb \u27e8y, (hy : f y a = c)\u27e9, \u27e8y * x,\n  show f (y * x) b = c, by rwa [mul_apply f, hx]\u27e9,\n\u03bb \u27e8y, (hy : f y b = c)\u27e9, \u27e8y * x\u207b\u00b9,\n  show f (y * x\u207b\u00b9) a = c, by\n    conv {to_rhs, rw [\u2190 hy, \u2190 mul_one y, \u2190 inv_mul_self x, \u2190 mul_assoc,\n      mul_apply f, hx]}\u27e9\u27e9), \u03bb h, h \u25b8 mem_orbit_self _ _\u27e9\n\ninstance orbit_fintype (a : \u03b2) [fintype \u03b1] [decidable_eq \u03b2] :\nfintype (orbit f a) := set.fintype_range _\n\ndef stabilizer (a : \u03b2) : set \u03b1 :=\n{x : \u03b1 | f x a = a}\n\nlemma mem_stabilizer_iff {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} [is_group_action f] {a : \u03b2} {x : \u03b1} :\n  x \u2208 stabilizer f a \u2194 f x a = a :=\niff.rfl\n\ninstance (a : \u03b2) : is_subgroup (stabilizer f a) :=\n{ one_mem := one_apply _ _,\n  mul_mem := \u03bb x y (hx : f x a = a) (hy : f y a = a),\n    show f (x * y) a = a, by rw mul_apply f; simp *,\n  inv_mem := \u03bb x (hx : f x a = a), show f x\u207b\u00b9 a = a,\n    by rw [\u2190 hx, \u2190 mul_apply f, inv_mul_self, one_apply f, hx] }\n\nnoncomputable lemma orbit_equiv_left_cosets (a : \u03b2) :\n  orbit f a \u2243 left_cosets (stabilizer f a) :=\nby letI := left_rel (stabilizer f a); exact\nequiv.symm (@equiv.of_bijective _ _ \n  (\u03bb x : left_cosets (stabilizer f a), quotient.lift_on x \n    (\u03bb x, (\u27e8f x a, mem_orbit _ _ _\u27e9 : orbit f a)) \n    (\u03bb g h (H : _ = _), subtype.eq $ (is_group_action.bijective f (g\u207b\u00b9)).1\n      $ show f g\u207b\u00b9 (f g a) = f g\u207b\u00b9 (f h a),\n      by rw [\u2190 mul_apply f, \u2190 mul_apply f, H, inv_mul_self, one_apply f])) \n\u27e8\u03bb g h, quotient.induction_on\u2082 g h (\u03bb g h H, quotient.sound $\n  have H : f g a = f h a := subtype.mk.inj H, \n  show f (g\u207b\u00b9 * h) a = a,\n  by rw [mul_apply f, \u2190 H, \u2190 mul_apply f, inv_mul_self, one_apply f]), \n  \u03bb \u27e8b, \u27e8g, hgb\u27e9\u27e9, \u27e8\u27e6g\u27e7, subtype.eq hgb\u27e9\u27e9)\n\ndef fixed_points : set \u03b2 := {a : \u03b2 | \u2200 x, x \u2208 stabilizer f a}\n\nlemma mem_fixed_points {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} [is_group_action f] {a : \u03b2} :\n  a \u2208 fixed_points f \u2194 \u2200 x : \u03b1, f x a = a := iff.rfl\n\nlemma mem_fixed_points' {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} [is_group_action f] {a : \u03b2} : a \u2208 fixed_points f \u2194\n  (\u2200 b, b \u2208 orbit f a \u2192 b = a) :=\n\u27e8\u03bb h b h\u2081, let \u27e8x, hx\u27e9 := mem_orbit_iff.1 h\u2081 in hx \u25b8 h x,\n\u03bb h b, mem_stabilizer_iff.2 (h _ (mem_orbit _ _ _))\u27e9\n\nend is_group_action", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/xenalib/Group_actions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932333, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7309876814198186}}
{"text": "import data.real.basic\nimport algebra.pi_instances\n\nnotation `|`x`|` := abs x\n\n/-\nIn this file we manipulate the elementary definition of limits of\nsequences of real numbers. \nmathlib has a much more general definition of limits, but here\nwe want to practice using the logical operators and relations\ncovered in the previous files.\nA sequence u is a function from \u2115 to \u211d, hence Lean says\nu : \u2115 \u2192 \u211d\nThe definition we'll be using is:\n-- Definition of \u00ab u tends to l \u00bb\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\nNote the use of `\u2200 \u03b5 > 0, ...` which is an abbreviation of\n`\u2200 \u03b5, \u03b5 > 0 \u2192 ... `\nIn particular, a statement like `h : \u2200 \u03b5 > 0, ...`\ncan be specialized to a given \u03b5\u2080 by\n  `specialize h \u03b5\u2080 h\u03b5\u2080`\nwhere h\u03b5\u2080 is a proof of \u03b5\u2080 > 0.\nAlso recall that, wherever Lean expects some proof term, we can\nstart a tactic mode proof using the keyword `by` (followed by curly braces\nif you need more than one tactic invocation).\nFor instance, if the local context contains:\n\u03b4 : \u211d\n\u03b4_pos : \u03b4 > 0\nh : \u2200 \u03b5 > 0, ...\nthen we can specialize h to the real number \u03b4/2 using:\n  `specialize h (\u03b4/2) (by linarith)`\nwhere `by linarith` will provide the proof of `\u03b4/2 > 0` expected by Lean.\nWe'll take this opportunity to use two new tactics:\n`norm_num` will perform numerical normalization on the goal and `norm_num at h` \nwill do the same in assumption `h`. This will get rid of trivial calculations on numbers,\nlike replacing |l - l| by zero in the next exercise.\n`congr'` will try to prove equalities between applications of functions by recursively \nproving the arguments are the same. \nFor instance, if the goal is `f x + g y = f z + g t` then congr will replace it by\ntwo goals: `x = z` and `y = t`.\nYou can limit the recursion depth by specifying a natural number after `congr'`. \nFor instance, in the above example, `congr' 1` will give new goals\n`f x = f z` and `g y = g t`, which only inspect arguments of the addition and not deeper.\n-/\n\nvariables (u v w : \u2115 \u2192 \u211d) (l l' : \u211d)\n\n-- If u is constant with value l then u tends to l\nexample : (\u2200 n, u n = 1) \u2192 seq_limit u l :=\nbegin\n  sorry,\nend", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/exercises/sequence_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932333, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.7309876772910768}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.order.euclidean_absolute_value\nimport data.polynomial.field_division\n\n/-!\n# Absolute value on polynomials over a finite field.\n\nLet `Fq` be a finite field of cardinality `q`, then the map sending a polynomial `p`\nto `q ^ degree p` (where `q ^ degree 0 = 0`) is an absolute value.\n\n## Main definitions\n\n * `polynomial.card_pow_degree` is an absolute value on `\ud835\udd3d_q[t]`, the ring of\n   polynomials over a finite field of cardinality `q`, mapping a polynomial `p`\n   to `q ^ degree p` (where `q ^ degree 0 = 0`)\n\n## Main results\n * `polynomial.card_pow_degree_is_euclidean`: `card_pow_degree` respects the\n   Euclidean domain structure on the ring of polynomials\n\n-/\n\nnamespace polynomial\n\nvariables {Fq : Type*} [field Fq] [fintype Fq]\n\nopen absolute_value\n\nopen_locale classical\n\n/-- `card_pow_degree` is the absolute value on `\ud835\udd3d_q[t]` sending `f` to `q ^ degree f`.\n\n`card_pow_degree 0` is defined to be `0`. -/\nnoncomputable def card_pow_degree :\n  absolute_value (polynomial Fq) \u2124 :=\nhave card_pos : 0 < fintype.card Fq := fintype.card_pos_iff.mpr infer_instance,\nhave pow_pos : \u2200 n, 0 < (fintype.card Fq : \u2124) ^ n := \u03bb n, pow_pos (int.coe_nat_pos.mpr card_pos) n,\n{ to_fun := \u03bb p, if p = 0 then 0 else fintype.card Fq ^ p.nat_degree,\n  nonneg' := \u03bb p, by { dsimp, split_ifs, { refl }, exact pow_nonneg (int.coe_zero_le _) _ },\n  eq_zero' := \u03bb p, ite_eq_left_iff.trans $ \u27e8\u03bb h, by { contrapose! h, exact \u27e8h, (pow_pos _).ne'\u27e9 },\n    absurd\u27e9,\n  add_le' := \u03bb p q, begin\n    by_cases hp : p = 0, { simp [hp] },\n    by_cases hq : q = 0, { simp [hq] },\n    by_cases hpq : p + q = 0,\n    { simp only [hpq, hp, hq, eq_self_iff_true, if_true, if_false],\n      exact add_nonneg (pow_pos _).le (pow_pos _).le },\n    simp only [hpq, hp, hq, if_false],\n    refine le_trans (pow_le_pow (by linarith) (polynomial.nat_degree_add_le _ _)) _,\n    refine le_trans (le_max_iff.mpr _)\n      (max_le_add_of_nonneg (pow_nonneg (by linarith) _) (pow_nonneg (by linarith) _)),\n    exact (max_choice p.nat_degree q.nat_degree).imp (\u03bb h, by rw [h]) (\u03bb h, by rw [h])\n  end,\n  map_mul' := \u03bb p q, begin\n    by_cases hp : p = 0, { simp [hp] },\n    by_cases hq : q = 0, { simp [hq] },\n    have hpq : p * q \u2260 0 := mul_ne_zero hp hq,\n    simp only [hpq, hp, hq, eq_self_iff_true, if_true, if_false,\n      polynomial.nat_degree_mul hp hq, pow_add],\n  end }\n\nlemma card_pow_degree_apply (p : polynomial Fq) :\n  card_pow_degree p = if p = 0 then 0 else fintype.card Fq ^ nat_degree p := rfl\n\n@[simp] lemma card_pow_degree_zero : card_pow_degree (0 : polynomial Fq) = 0 := if_pos rfl\n\n@[simp] lemma card_pow_degree_nonzero (p : polynomial Fq) (hp : p \u2260 0) :\n  card_pow_degree p = fintype.card Fq ^ p.nat_degree :=\nif_neg hp\n\nlemma card_pow_degree_is_euclidean :\n  is_euclidean (card_pow_degree : absolute_value (polynomial Fq) \u2124) :=\nhave card_pos : 0 < fintype.card Fq := fintype.card_pos_iff.mpr infer_instance,\nhave pow_pos : \u2200 n, 0 < (fintype.card Fq : \u2124) ^ n := \u03bb n, pow_pos (int.coe_nat_pos.mpr card_pos) n,\n{ map_lt_map_iff' := \u03bb p q, begin\n    simp only [euclidean_domain.r, card_pow_degree_apply],\n    split_ifs with hp hq hq,\n    { simp only [hp, hq, lt_self_iff_false] },\n    { simp only [hp, hq, degree_zero, ne.def, bot_lt_iff_ne_bot,\n        degree_eq_bot, pow_pos, not_false_iff] },\n    { simp only [hp, hq, degree_zero, not_lt_bot, (pow_pos _).not_lt] },\n    { rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq, with_bot.coe_lt_coe, pow_lt_pow_iff],\n      exact_mod_cast @fintype.one_lt_card Fq _ _ },\n  end }\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/degree/card_pow_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192066862062, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7309876771464768}}
{"text": "import order.complete_lattice\n\n\nlemma le_supr'' {\u03b1 : Type*} {\u03b9 : Sort*} [_inst_1 : complete_lattice \u03b1] (s : \u03b9 \u2192 \u03b1) (i : \u03b9) (x:\u03b1):\n  (x \u2264 s i) \u2192 x \u2264 supr s :=\nbegin\n  intro A1,\n  apply le_trans A1,\n  apply le_supr,\nend \n\n\nlemma infi_prop_def {\u03b1:Type*} [complete_lattice \u03b1]\n    {v:\u03b1} {P:Prop} (H:P):(\u2a05 (H2:P), v) = v :=\nbegin\n  apply le_antisymm,\n  { apply infi_le, apply H },\n  { apply @le_infi, intro A1, apply le_refl v },\nend\n\nlemma supr_prop_def {\u03b1:Type*} [complete_lattice \u03b1]\n    {v:\u03b1} {P:Prop} (H:P):(\u2a06 (H2:P), v) = v :=\nbegin\n  apply le_antisymm,\n  {\n    apply supr_le,\n    intro A1,\n    apply le_refl v,\n  },\n  {\n    apply @le_supr \u03b1 P _ (\u03bb H2:P, v),\n    apply H,\n  },\nend\n\nlemma supr_prop_false {\u03b1:Type*} [complete_lattice \u03b1]\n    {v:\u03b1} {P:Prop} (H:\u00acP):(\u2a06 (H2:P), v) = \u22a5 :=\nbegin\n  apply le_antisymm,\n  {\n    apply supr_le,\n    intro A1,\n    exfalso,\n    apply H,\n    apply A1,\n  },\n  {\n    apply bot_le,\n  },\nend\n\nlemma infi_prop_false {\u03b1:Type*} [complete_lattice \u03b1]\n    {v:\u03b1} {P:Prop} (H:\u00acP):(\u2a05 (H2:P), v) = \u22a4 :=\nbegin\n  apply le_antisymm,\n  {\n    apply le_top,\n  },\n  {\n    apply le_infi,\n    intro A1,\n    exfalso,\n    apply H,\n    apply A1,\n  },\nend\n\nlemma infi_le_trans {\u03b1 \u03b2:Type*} [complete_lattice \u03b2] (a:\u03b1) (f:\u03b1 \u2192 \u03b2) \n    (b:\u03b2):(f a \u2264 b) \u2192 (\u2a05 (c:\u03b1), (f c)) \u2264 b :=\nbegin\n  intros A1,\n  apply le_trans _ A1,\n  apply @infi_le _ _ _, \nend\n\n/-\n  I saw this pattern a bunch below. It could be more widely used.\n -/\nlemma infi_set_le_trans {\u03b1 \u03b2:Type*} [complete_lattice \u03b2] (a:\u03b1) (P:\u03b1 \u2192 Prop) (f:\u03b1 \u2192 \u03b2) \n    (b:\u03b2):(P a) \u2192 (f a \u2264 b) \u2192 (\u2a05 (c:\u03b1) (H:P c), f c) \u2264 b :=\nbegin\n  intros A1 A2,\n  apply infi_le_trans a,\n  rw infi_prop_def A1,\n  apply A2,\nend\n\nlemma infi_set_image {\u03b1 \u03b2 \u03b3:Type*} [complete_lattice \u03b3] (S:set \u03b1) (f:\u03b1 \u2192 \u03b2) \n    (g:\u03b2 \u2192 \u03b3):(\u2a05 (c\u2208 (f '' S)), g c) = \u2a05  (a\u2208 S), (g \u2218 f) a :=\nbegin\n  apply le_antisymm;simp,\n  {\n    intros a B1,\n    apply infi_le_trans (f a),\n    apply infi_le_trans a,\n    rw infi_prop_def,\n    apply and.intro B1,\n    refl,\n  },\n  {\n    intros b h_b,\n    apply infi_le_of_le b,\n    apply infi_le_of_le h_b,\n    apply le_refl,\n  },\nend\n", "meta": {"author": "google", "repo": "formal-ml", "sha": "630011d19fdd9539c8d6493a69fe70af5d193590", "save_path": "github-repos/lean/google-formal-ml", "path": "github-repos/lean/google-formal-ml/formal-ml-630011d19fdd9539c8d6493a69fe70af5d193590/src/formal_ml/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7309599413737331}}
{"text": "\n\n-- let's define the real numbers to be a number system which satisfies\n-- the basic properties of the real numbers which we will need.\n\nnoncomputable theory \nconstant real : Type\n@[instance] constant real_field : linear_ordered_field real\n\n-- This piece of magic means that \"real\" now behaves a lot like\n-- the real numbers. In particular we now have a bunch\n-- of theorems:\n\nexample : \u2200 x y : real, x * y = y * x := mul_comm\n\n\nvariable x : real\nvariable n : nat\n\n-- We do _not_ have powers though. So we need to make them.\n\nopen nat \n\ndefinition natural_power : real \u2192 nat \u2192 real\n| x 0 := 1\n| x (succ n) := (natural_power x n) * x\n\ntheorem T : \u2200 x:real, \u2200 m n:nat, natural_power x (m+n) = natural_power x m *natural_power x n :=\nbegin\nassume x m n,\ninduction n with n H,\nunfold natural_power,\nrw [add_zero, mul_one],\nunfold natural_power,\nrw [H, mul_assoc],\nend\n\ntheorem T2 : \u2200 x: real, \u2200 m n : nat, natural_power (natural_power x m) n = natural_power x (m*n) :=\nbegin\nassume x m n,\ninduction n with n H,\nunfold natural_power,\nrw [mul_zero, eq_comm],\nunfold natural_power,\nrw [succ_eq_add_one, mul_add, mul_one, add_one],\nunfold natural_power,\nrw[T, H],\nend\n\ntheorem T3 : \u2200 x y:real, \u2200 n:nat, (natural_power x n) * (natural_power y n) = natural_power (x*y) n :=\nbegin\nassume x y n,\ninduction n with n H,\nunfold natural_power,\nsimp,\nunfold natural_power,\ncc,\nend\n\n\n\nconstant nth_root (x : real) (n : nat) : (x>0) \u2192 (n>0) \u2192 real\n\naxiom is_nth_root (x : real) (n : nat) (Hx : x>0) (Hn : n>0) : natural_power (nth_root x n Hx Hn) n = x \n\ndefinition rational_power_v0 (x : real) (n : nat) (d : nat) (Hx : x > 0) (Hd : d > 0) : real :=\nnatural_power (nth_root x d Hx Hd) n \n\ntheorem T4 : \u2200 x y:real,\u2200 Hx:x\u22650,\u2200 Hy:y\u22650,\u2200 n:nat,natural_power x (n+1) = natural_power y (n+1) \u2192 x = y:=\nbegin\nassume x y Hx Hy n,\ninduction n with n H,\n    rw[add_one],\n    unfold natural_power,\n    rw[mul_comm,mul_one,mul_comm,mul_one],\n    assume H1,\n    exact(H1),\n    unfold natural_power,\n    assume H2,\n    calc\n    natural_power x n * x * x = natural_power y n * y * y : H2\n    ... =\n\n        \n        \n\n\n\nend\n/-\ntheorem T5 : \u2200 x:real, \u2200 n d k:nat, \u2200 Hx: x > 0, \n\u2200 Hd: d >0, \u2200 Hkd: (k*d) >0, \nrational_power_v0 x n d Hx Hd = rational_power_v0 x (k*n) (k*d) Hx Hkd:=\nbegin\nassume x n d k Hx Hd Hkd,\nunfold rational_power_v0,\nrw[\u2190 T2],\nhave H1 :natural_power (rational_power_v0 x n d Hx Hd) d= natural_power x n :=\nbegin\nunfold rational_power_v0,\nrw[T2, mul_comm,\u2190 T2,is_nth_root],\nend,\nlet y:real := x,\nhave H1 y=x,\nbegin\n\nend\nend\n-/\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/test4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.95041097139764, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.730942295197118}}
{"text": "/-\nCopyright (c) 2020 The Xena project. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Kevin Buzzard\nThanks: Imperial College London, leanprover-community\n-/\n\n-- import level 1\nimport complex.Level_01_of_real\n\n/-! \n\n# Level 2: I \n\nI find it unbelievable that we have written quite a lot of code about the\ncomplex numbers and we've still never defined i, or j, or I, or $$\\sqrt{-1}$$,\nor whatever it's called.  Why don't you supply the definition, and make the\nbasic API?\n\nAll the proofs below are sorried. You can try them in tactic mode\nby replacing `sorry` with `begin end` and then starting to write \ntactics in the `begin end` block.\n-/\n\nnamespace complex\n\n/-- complex.I is the square root of -1 above the imaginary axis -/\ndef I : \u2102 := sorry\n\n/-\n\n Easy lemmas, tagged with `simp` so Lean can prove things about `I` by equating\n real and imaginary parts.\n \n-/\n\n/-- re(I) = 0 -/\n@[simp] lemma I_re : re(I) = 0 :=\nbegin\n  sorry\nend\n\n/-- im(I) = 1 -/\n@[simp] lemma I_im : im(I) = 1 :=\nbegin\n  sorry\nend\n\n/-- I*I = -1 -/\n@[simp] lemma I_mul_I : I * I = -1 :=\nbegin\n  sorry\nend\n\nlemma mk_eq_add_mul_I (a b : \u211d) : (\u27e8a, b\u27e9 : \u2102) = a + b * I := sorry\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z := sorry\n\n\n/-\n  Bonus level. Hint: don't forget ext_iff. It's defined\n  in complex.basic and its type is below.\n   \n  ext_iff : \u2200 {z w : \u2102}, z = w \u2194 z.re = w.re \u2227 z.im = w.im\n-/\n\n/-- I is non-zero -/\nlemma I_ne_zero : (I : \u2102) \u2260 0 :=\nbegin\n  sorry\nend\n\nend complex\n", "meta": {"author": "ImperialCollegeLondon", "repo": "complex-number-game", "sha": "49d6ca66ded53a56dcd8a3f6dc87dbd755fcd0ac", "save_path": "github-repos/lean/ImperialCollegeLondon-complex-number-game", "path": "github-repos/lean/ImperialCollegeLondon-complex-number-game/complex-number-game-49d6ca66ded53a56dcd8a3f6dc87dbd755fcd0ac/src/complex/Level_02_I.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7308663906631833}}
{"text": "open classical tactic expr list\n\nsection prop_equivalence\n\n  local attribute [instance] prop_decidable\n  variables {a b : Prop}\n\n  theorem not_not_iff (a : Prop) : \u00ac\u00aca \u2194 a :=\n  iff.intro classical.by_contradiction not_not_intro\n\n  theorem implies_iff_not_or (a b : Prop) : (a \u2192 b) \u2194 (\u00ac a \u2228 b) :=\n  iff.intro\n    (\u03bb h, if ha : a then or.inr (h ha) else or.inl ha)\n    (\u03bb h, or.elim h (\u03bb hna ha, absurd ha hna) (\u03bb hb ha, hb))\n\n  theorem not_and_of_not_or_not (h : \u00ac a \u2228 \u00ac b) : \u00ac (a \u2227 b) :=\n  assume \u27e8ha, hb\u27e9, or.elim h (assume hna, hna ha) (assume hnb, hnb hb)\n\n  theorem not_or_not_of_not_and (h : \u00ac (a \u2227 b)) : \u00ac a \u2228 \u00ac b :=\n  if ha : a then\n    or.inr (show \u00ac b, from assume hb, h \u27e8ha, hb\u27e9)\n  else\n    or.inl ha\n\n  theorem not_and_iff (a b : Prop) : \u00ac (a \u2227 b) \u2194 \u00aca \u2228 \u00acb :=\n  iff.intro not_or_not_of_not_and not_and_of_not_or_not\n\n  theorem not_or_of_not_and_not (h : \u00ac a \u2227 \u00ac b) : \u00ac (a \u2228 b) :=\n  assume h\u2081, or.elim h\u2081 (assume ha, h^.left ha) (assume hb, h^.right hb)\n\n  theorem not_and_not_of_not_or (h : \u00ac (a \u2228 b)) : \u00ac a \u2227 \u00ac b :=\n  and.intro (assume ha, h (or.inl ha)) (assume hb, h (or.inr hb))\n\n  theorem not_or_iff (a b : Prop) : \u00ac (a \u2228 b) \u2194 \u00ac a \u2227 \u00ac b :=\n  iff.intro not_and_not_of_not_or not_or_of_not_and_not\n\n  theorem iff_eq (a b : Prop) : (a \u2194 b) = ((a \u2192 b) \u2227 (b \u2192 a)) := rfl\n\n  check and.comm\n  check or.comm\n\nend prop_equivalence\n\nsection prenex_equivalence\n\n  variables {A : Type}\n  variables {p : Prop}\n  variables {q : A \u2192 Prop}\n  variable [inhabited A]\n\n  theorem forall_not_of_not_exists : (\u00ac \u2203 x, q x) \u2192 \u2200 x, \u00ac q x := \n  \u03bb h x hqx, h (exists.intro x hqx)\n\n  theorem exists_not_of_not_forall : (\u00ac \u2200 x, q x) \u2192 \u2203 x, \u00ac q x := \n  \u03bb h, by_contradiction\n  (\u03bb neg, have \u2200 x, \u00ac \u00ac q x, from forall_not_of_not_exists neg, \n    have \u2200 x, q x, from \u03bb x, iff.elim_left (not_not_iff (q x)) (this x),\n  show _, from h this)\n\n  theorem forall_p_iff_p : (\u2200 x : A, p) \u2194 p := \n  iff.intro (\u03bb h, h (default A)) (\u03bb h x, h)\n\n  theorem exists_p_iff_p : (\u2203 x : A, p) \u2194 p := \n  iff.intro (\u03bb h, exists.elim h (\u03bb x hx, hx)) (\u03bb h, exists.intro (default A) h)\n\n  theorem forall_of_forall_and_left : (\u2200 x, q x) \u2227 p \u2194 \u2200 x, q x \u2227 p := \n  iff.intro (\u03bb h x, and.intro (h^.left x) h^.right) \n  (\u03bb h, and.intro (\u03bb x, (h x)^.left) (h (default A))^.right)\n\n  theorem forall_of_forall_and_right : p \u2227 (\u2200 x, q x) \u2194 \u2200 x, q x \u2227 p := \n  iff.trans and.comm forall_of_forall_and_left\n\n  theorem forall_of_forall_or_left : (\u2200 x, q x) \u2228 p \u2194 \u2200 x, q x \u2228 p := \n  iff.intro (\u03bb h x, or.elim h (\u03bb l, or.inl (l x)) (\u03bb r, or.inr r)) \n  (\u03bb h, or.elim (em p) (\u03bb l, or.inr l) (\u03bb r, or.inl (\u03bb x, or.resolve_right (h x) r)))\n\n  theorem forall_of_forall_or_right : p \u2228 (\u2200 x, q x) \u2194 \u2200 x, q x \u2228 p := \n  iff.trans or.comm forall_of_forall_or_left\n\n  theorem exists_of_exists_and_left : (\u2203 x, q x) \u2227 p \u2194 \u2203 x, q x \u2227 p := \n  iff.intro (\u03bb h, exists.elim h^.left (\u03bb x hx, exists.intro x (and.intro hx h^.right)) ) \n  (\u03bb h, exists.elim h (\u03bb x hx, and.intro (exists.intro x hx^.left) hx^.right))\n\n  theorem exists_of_exists_and_right : p \u2227 (\u2203 x, q x) \u2194 \u2203 x, q x \u2227 p := \n  iff.trans and.comm exists_of_exists_and_left\n\n  theorem exists_of_exists_or_left : (\u2203 x, q x) \u2228 p \u2194 \u2203 x, q x \u2228 p := \n  iff.intro (\u03bb h, or.elim h (\u03bb l, exists.elim l (\u03bb x hx, exists.intro x (or.inl hx))) \n    (\u03bb r, exists.intro (default A) (or.inr r))) \n  (\u03bb h, exists.elim h (\u03bb x hx, or.elim hx (\u03bb l, or.inl (exists.intro x l)) (\u03bb r, or.inr r)))\n\n  theorem exists_of_exists_or_right : p \u2228 (\u2203 x, q x) \u2194 \u2203 x, q x \u2228 p := \n  iff.trans or.comm exists_of_exists_or_left\n\nend prenex_equivalence\n\nmeta def nnf_lemmas : list name := [``forall_not_of_not_exists, ``exists_not_of_not_forall, \n                                ``iff_eq, ``implies_iff_not_or, ``not_and_iff, ``not_or_iff, \n                                ``not_not_iff, ``not_true_iff, ``not_false_iff]\n\nmeta def normalize_hyp (lemmas : list expr) (hyp : expr) : tactic unit :=\ndo try (simp_at_using lemmas hyp)\n\nmeta def nnf_hyps : tactic unit :=\ndo hyps \u2190 local_context,\n   lemmas \u2190 monad.mapm mk_const nnf_lemmas,\n   monad.for' hyps (normalize_hyp lemmas)\n\nmeta def pnf_lemmas : list name := [``forall_p_iff_p, ``exists_p_iff_p, ``forall_of_forall_and_left, \n                             ``forall_of_forall_and_right, ``forall_of_forall_or_left, \n                             ``forall_of_forall_or_right, ``exists_of_exists_and_left, \n                             ``exists_of_exists_and_right, ``exists_of_exists_or_left, ``exists_of_exists_or_right]\n\nmeta def pnf_hyps : tactic unit :=\ndo hyps \u2190 local_context,\n   pnf_lemmas \u2190 monad.mapm mk_const pnf_lemmas,\n   monad.for' hyps (normalize_hyp pnf_lemmas)\n\nexample (p q r : Prop) (h\u2081 : \u00ac (p \u2194 (q \u2227 \u00ac r))) (h\u2082 : \u00ac (p \u2192 (q \u2192 \u00ac r))) : true :=\nby do nnf_hyps,\n      trace_state,\n      triv\n\n-- TODO: think about the order of applying simp rules.\n\nexample (A : Type) (p : Prop) (q : A \u2192 Prop) (h\u2081 : \u00ac p \u2192 ((\u2200 x, q x) \u2192 p)) [inhabited A] : true :=\nby do nnf_hyps,\n      trace_state,\n      pnf_hyps,\n      trace_state,\n      triv\n\nprint simplify\n\n", "meta": {"author": "minchaowu", "repo": "auto-", "sha": "7079dcad4e38b2addb8a1e01781547db67fd278e", "save_path": "github-repos/lean/minchaowu-auto-", "path": "github-repos/lean/minchaowu-auto-/auto--7079dcad4e38b2addb8a1e01781547db67fd278e/prenex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7308663845491331}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport data.set.lattice\nimport data.list.basic\n\n/-!\n# Languages\n\nThis file contains the definition and operations on formal languages over an alphabet. Note strings\nare implemented as lists over the alphabet.\nThe operations in this file define a [Kleene algebra](https://en.wikipedia.org/wiki/Kleene_algebra)\nover the languages.\n-/\n\nuniverses u v\n\nvariables {\u03b1 : Type u}\n\n/-- A language is a set of strings over an alphabet. -/\n@[derive [has_mem (list \u03b1), has_singleton (list \u03b1), has_insert (list \u03b1), complete_boolean_algebra]]\ndef language (\u03b1) := set (list \u03b1)\n\nnamespace language\n\nlocal attribute [reducible] language\n\n/-- Zero language has no elements. -/\ninstance : has_zero (language \u03b1) := \u27e8(\u2205 : set _)\u27e9\n/-- `1 : language \u03b1` contains only one element `[]`. -/\ninstance : has_one (language \u03b1) := \u27e8{[]}\u27e9\n\ninstance : inhabited (language \u03b1) := \u27e80\u27e9\n\n/-- The sum of two languages is the union of  -/\ninstance : has_add (language \u03b1) := \u27e8set.union\u27e9\ninstance : has_mul (language \u03b1) := \u27e8set.image2 (++)\u27e9\n\nlemma zero_def : (0 : language \u03b1) = (\u2205 : set _) := rfl\nlemma one_def : (1 : language \u03b1) = {[]} := rfl\n\nlemma add_def (l m : language \u03b1) : l + m = l \u222a m := rfl\nlemma mul_def (l m : language \u03b1) : l * m = set.image2 (++) l m := rfl\n\n/-- The star of a language `L` is the set of all strings which can be written by concatenating\n  strings from `L`. -/\ndef star (l : language \u03b1) : language \u03b1 :=\n{ x | \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l}\n\nlemma star_def (l : language \u03b1) :\n  l.star = { x | \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l} := rfl\n\n@[simp] lemma mem_one (x : list \u03b1) : x \u2208 (1 : language \u03b1) \u2194 x = [] := by refl\n@[simp] lemma mem_add (l m : language \u03b1) (x : list \u03b1) : x \u2208 l + m \u2194 x \u2208 l \u2228 x \u2208 m :=\nby simp [add_def]\nlemma mem_mul (l m : language \u03b1) (x : list \u03b1) : x \u2208 l * m \u2194 \u2203 a b, a \u2208 l \u2227 b \u2208 m \u2227 a ++ b = x :=\nby simp [mul_def]\nlemma mem_star (l : language \u03b1) (x : list \u03b1) :\n  x \u2208 l.star \u2194 \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l :=\niff.rfl\n\ninstance : semiring (language \u03b1) :=\n{ add := (+),\n  add_assoc := set.union_assoc,\n  zero := 0,\n  zero_add := set.empty_union,\n  add_zero := set.union_empty,\n  add_comm := set.union_comm,\n  mul := (*),\n  mul_assoc := \u03bb l m n,\n    by simp only [mul_def, set.image2_image2_left, set.image2_image2_right, list.append_assoc],\n  zero_mul := by simp [zero_def, mul_def],\n  mul_zero := by simp [zero_def, mul_def],\n  one := 1,\n  one_mul := \u03bb l, by simp [mul_def, one_def],\n  mul_one := \u03bb l, by simp [mul_def, one_def],\n  left_distrib := \u03bb l m n, by simp only [mul_def, add_def, set.image2_union_right],\n  right_distrib := \u03bb l m n, by simp only [mul_def, add_def, set.image2_union_left] }\n\n@[simp] lemma add_self (l : language \u03b1) : l + l = l := sup_idem\n\nlemma star_def_nonempty (l : language \u03b1) :\n  l.star = {x | \u2203 S : list (list \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l \u2227 y \u2260 []} :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8S, rfl, h\u27e9,\n    refine \u27e8S.filter (\u03bb l, \u00aclist.empty l), by simp, \u03bb y hy, _\u27e9,\n    rw [list.mem_filter, list.empty_iff_eq_nil] at hy,\n    exact \u27e8h y hy.1, hy.2\u27e9 },\n  { rintro \u27e8S, hx, h\u27e9,\n    exact \u27e8S, hx, \u03bb y hy, (h y hy).1\u27e9 }\nend\n\n\n\nlemma le_mul_congr {l\u2081 l\u2082 m\u2081 m\u2082 : language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 * l\u2082 \u2264 m\u2081 * m\u2082 :=\nbegin\n  intros h\u2081 h\u2082 x hx,\n  simp only [mul_def, exists_and_distrib_left, set.mem_image2, set.image_prod] at hx \u22a2,\n  tauto\nend\n\nlemma le_add_congr {l\u2081 l\u2082 m\u2081 m\u2082 : language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 + l\u2082 \u2264 m\u2081 + m\u2082 := sup_le_sup\n\nlemma mem_supr {\u03b9 : Sort v} {l : \u03b9 \u2192 language \u03b1} {x : list \u03b1} :\n  x \u2208 (\u2a06 i, l i) \u2194 \u2203 i, x \u2208 l i :=\nset.mem_Union\n\nlemma supr_mul {\u03b9 : Sort v} (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  (\u2a06 i, l i) * m = \u2a06 i, l i * m :=\nset.image2_Union_left _ _ _\n\nlemma mul_supr {\u03b9 : Sort v} (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  m * (\u2a06 i, l i) = \u2a06 i, m * l i :=\nset.image2_Union_right _ _ _\n\nlemma supr_add {\u03b9 : Sort v} [nonempty \u03b9] (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  (\u2a06 i, l i) + m = \u2a06 i, l i + m := supr_sup\n\nlemma add_supr {\u03b9 : Sort v} [nonempty \u03b9] (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n  m + (\u2a06 i, l i) = \u2a06 i, m + l i := sup_supr\n\nlemma mem_pow {l : language \u03b1} {x : list \u03b1} {n : \u2115} :\n  x \u2208 l ^ n \u2194 \u2203 S : list (list \u03b1), x = S.join \u2227 S.length = n \u2227 \u2200 y \u2208 S, y \u2208 l :=\nbegin\n  induction n with n ihn generalizing x,\n  { simp only [mem_one, pow_zero, list.length_eq_zero],\n    split,\n    { rintro rfl, exact \u27e8[], rfl, rfl, \u03bb y h, h.elim\u27e9 },\n    { rintro \u27e8_, rfl, rfl, _\u27e9, refl } },\n  { simp only [pow_succ, mem_mul, ihn],\n    split,\n    { rintro \u27e8a, b, ha, \u27e8S, rfl, rfl, hS\u27e9, rfl\u27e9,\n      exact \u27e8a :: S, rfl, rfl, list.forall_mem_cons.2 \u27e8ha, hS\u27e9\u27e9 },\n    { rintro \u27e8_|\u27e8a, S\u27e9, rfl, hn, hS\u27e9; cases hn,\n      rw list.forall_mem_cons at hS,\n      exact \u27e8a, _, hS.1, \u27e8S, rfl, rfl, hS.2\u27e9, rfl\u27e9 } }\nend\n\nlemma star_eq_supr_pow (l : language \u03b1) : l.star = \u2a06 i : \u2115, l ^ i :=\nbegin\n  ext x,\n  simp only [mem_star, mem_supr, mem_pow],\n  split,\n  { rintro \u27e8S, rfl, hS\u27e9, exact \u27e8_, S, rfl, rfl, hS\u27e9 },\n  { rintro \u27e8_, S, rfl, rfl, hS\u27e9, exact \u27e8S, rfl, hS\u27e9 }\nend\n\nlemma mul_self_star_comm (l : language \u03b1) : l.star * l = l * l.star :=\nby simp only [star_eq_supr_pow, mul_supr, supr_mul, \u2190 pow_succ, \u2190 pow_succ']\n\n@[simp] lemma one_add_self_mul_star_eq_star (l : language \u03b1) : 1 + l * l.star = l.star :=\nbegin\n  simp only [star_eq_supr_pow, mul_supr, \u2190 pow_succ, \u2190 pow_zero l],\n  exact sup_supr_nat_succ _\nend\n\n@[simp] lemma one_add_star_mul_self_eq_star (l : language \u03b1) : 1 + l.star * l = l.star :=\nby rw [mul_self_star_comm, one_add_self_mul_star_eq_star]\n\nlemma star_mul_le_right_of_mul_le_right (l m : language \u03b1) : l * m \u2264 m \u2192 l.star * m \u2264 m :=\nbegin\n  intro h,\n  rw [star_eq_supr_pow, supr_mul],\n  refine supr_le _,\n  intro n,\n  induction n with n ih,\n  { simp },\n  rw [pow_succ', mul_assoc (l^n) l m],\n  exact le_trans (le_mul_congr (le_refl _) h) ih,\nend\n\nlemma star_mul_le_left_of_mul_le_left (l m : language \u03b1) : m * l \u2264 m \u2192 m * l.star \u2264 m :=\nbegin\n  intro h,\n  rw [star_eq_supr_pow, mul_supr],\n  refine supr_le _,\n  intro n,\n  induction n with n ih,\n  { simp },\n  rw [pow_succ, \u2190mul_assoc m l (l^n)],\n  exact le_trans (le_mul_congr h (le_refl _)) ih\nend\n\nend language\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/computability/language.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.73084570569267}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n-/\nimport number_theory.legendre_symbol.quadratic_reciprocity\n\n/-!\n# The Jacobi Symbol\n\nWe define the Jacobi symbol and prove its main properties.\n\n## Main definitions\n\nWe define the Jacobi symbol, `jacobi_sym a b`, for integers `a` and natural numbers `b`\nas the product over the prime factors `p` of `b` of the Legendre symbols `legendre_sym p a`.\nThis agrees with the mathematical definition when `b` is odd.\n\nThe prime factors are obtained via `nat.factors`. Since `nat.factors 0 = []`,\nthis implies in particular that `jacobi_sym a 0 = 1` for all `a`.\n\n## Main statements\n\nWe prove the main properties of the Jacobi symbol, including the following.\n\n* Multiplicativity in both arguments (`jacobi_sym.mul_left`, `jacobi_sym.mul_right`)\n\n* The value of the symbol is `1` or `-1` when the arguments are coprime\n  (`jacobi_sym.eq_one_or_neg_one`)\n\n* The symbol vanishes if and only if `b \u2260 0` and the arguments are not coprime\n  (`jacobi_sym.eq_zero_iff`)\n\n* If the symbol has the value `-1`, then `a : zmod b` is not a square\n  (`zmod.nonsquare_of_jacobi_sym_eq_neg_one`); the converse holds when `b = p` is a prime\n  (`zmod.nonsquare_iff_jacobi_sym_eq_neg_one`); in particular, in this case `a` is a\n  square mod `p` when the symbol has the value `1` (`zmod.is_square_of_jacobi_sym_eq_one`).\n\n* Quadratic reciprocity (`jacobi_sym.quadratic_reciprocity`,\n  `jacobi_sym.quadratic_reciprocity_one_mod_four`,\n  `jacobi_sym.quadratic_reciprocity_three_mod_four`)\n\n* The supplementary laws for `a = -1`, `a = 2`, `a = -2` (`jacobi_sym.at_neg_one`,\n  `jacobi_sym.at_two`, `jacobi_sym.at_neg_two`)\n\n* The symbol depends on `a` only via its residue class mod `b` (`jacobi_sym.mod_left`)\n  and on `b` only via its residue class mod `4*a` (`jacobi_sym.mod_right`)\n\n## Notations\n\nWe define the notation `J(a | b)` for `jacobi_sym a b`, localized to `number_theory_symbols`.\n\n## Tags\nJacobi symbol, quadratic reciprocity\n-/\n\nsection jacobi\n\n/-!\n### Definition of the Jacobi symbol\n\nWe define the Jacobi symbol $\\Bigl(\\frac{a}{b}\\Bigr)$ for integers `a` and natural numbers `b`\nas the product of the Legendre symbols $\\Bigl(\\frac{a}{p}\\Bigr)$, where `p` runs through the\nprime divisors (with multiplicity) of `b`, as provided by `b.factors`. This agrees with the\nJacobi symbol when `b` is odd and gives less meaningful values when it is not (e.g., the symbol\nis `1` when `b = 0`). This is called `jacobi_sym a b`.\n\nWe define localized notation (locale `number_theory_symbols`) `J(a | b)` for the Jacobi\nsymbol `jacobi_sym a b`.\n-/\n\nopen nat zmod\n\n/-- The Jacobi symbol of `a` and `b` -/\n-- Since we need the fact that the factors are prime, we use `list.pmap`.\ndef jacobi_sym (a : \u2124) (b : \u2115) : \u2124 :=\n(b.factors.pmap (\u03bb p pp, @legendre_sym p \u27e8pp\u27e9 a) (\u03bb p pf, prime_of_mem_factors pf)).prod\n\n-- Notation for the Jacobi symbol.\nlocalized \"notation `J(` a ` | ` b `)` := jacobi_sym a b\" in number_theory_symbols\n\n/-!\n### Properties of the Jacobi symbol\n-/\nnamespace jacobi_sym\n\n/-- The symbol `J(a | 0)` has the value `1`. -/\n@[simp] lemma zero_right (a : \u2124) : J(a | 0) = 1 :=\nby simp only [jacobi_sym, factors_zero, list.prod_nil, list.pmap]\n\n/-- The symbol `J(a | 1)` has the value `1`. -/\n@[simp] lemma one_right (a : \u2124) : J(a | 1) = 1 :=\nby simp only [jacobi_sym, factors_one, list.prod_nil, list.pmap]\n\n/-- The Legendre symbol `legendre_sym p a` with an integer `a` and a prime number `p`\nis the same as the Jacobi symbol `J(a | p)`. -/\nlemma _root_.legendre_sym.to_jacobi_sym (p : \u2115) [fp : fact p.prime] (a : \u2124) :\n  legendre_sym p a = J(a | p) :=\nby simp only [jacobi_sym, factors_prime fp.1, list.prod_cons, list.prod_nil, mul_one, list.pmap]\n\n/-- The Jacobi symbol is multiplicative in its second argument. -/\nlemma mul_right' (a : \u2124) {b\u2081 b\u2082 : \u2115} (hb\u2081 : b\u2081 \u2260 0) (hb\u2082 : b\u2082 \u2260 0) :\n  J(a | b\u2081 * b\u2082) = J(a | b\u2081) * J(a | b\u2082) :=\nbegin\n  rw [jacobi_sym, ((perm_factors_mul hb\u2081 hb\u2082).pmap _).prod_eq, list.pmap_append, list.prod_append],\n  exacts [rfl, \u03bb p hp, (list.mem_append.mp hp).elim prime_of_mem_factors prime_of_mem_factors],\nend\n\n/-- The Jacobi symbol is multiplicative in its second argument. -/\nlemma mul_right (a : \u2124) (b\u2081 b\u2082 : \u2115) [ne_zero b\u2081] [ne_zero b\u2082] :\n  J(a | b\u2081 * b\u2082) = J(a | b\u2081) * J(a | b\u2082) :=\nmul_right' a (ne_zero.ne b\u2081) (ne_zero.ne b\u2082)\n\n/-- The Jacobi symbol takes only the values `0`, `1` and `-1`. -/\nlemma trichotomy (a : \u2124) (b : \u2115) : J(a | b) = 0 \u2228 J(a | b) = 1 \u2228 J(a | b) = -1 :=\n((@sign_type.cast_hom \u2124 _ _).to_monoid_hom.mrange.copy {0, 1, -1} $\n  by {rw set.pair_comm, exact (sign_type.range_eq sign_type.cast_hom).symm}).list_prod_mem\nbegin\n  intros _ ha',\n  rcases list.mem_pmap.mp ha' with \u27e8p, hp, rfl\u27e9,\n  haveI : fact p.prime := \u27e8prime_of_mem_factors hp\u27e9,\n  exact quadratic_char_is_quadratic (zmod p) a,\nend\n\n/-- The symbol `J(1 | b)` has the value `1`. -/\n@[simp] lemma one_left (b : \u2115) : J(1 | b) = 1 :=\nlist.prod_eq_one (\u03bb z hz,\n                  let \u27e8p, hp, he\u27e9 := list.mem_pmap.1 hz in by rw [\u2190 he, legendre_sym.at_one])\n\n/-- The Jacobi symbol is multiplicative in its first argument. -/\nlemma mul_left (a\u2081 a\u2082 : \u2124) (b : \u2115) : J(a\u2081 * a\u2082 | b) = J(a\u2081 | b) * J(a\u2082 | b) :=\nby { simp_rw [jacobi_sym, list.pmap_eq_map_attach, legendre_sym.mul], exact list.prod_map_mul }\n\n/-- The symbol `J(a | b)` vanishes iff `a` and `b` are not coprime (assuming `b \u2260 0`). -/\nlemma eq_zero_iff_not_coprime {a : \u2124} {b : \u2115} [ne_zero b] : J(a | b) = 0 \u2194 a.gcd b \u2260 1 :=\nlist.prod_eq_zero_iff.trans begin\n  rw [list.mem_pmap, int.gcd_eq_nat_abs, ne, prime.not_coprime_iff_dvd],\n  simp_rw [legendre_sym.eq_zero_iff, int_coe_zmod_eq_zero_iff_dvd, mem_factors (ne_zero.ne b),\n    \u2190 int.coe_nat_dvd_left, int.coe_nat_dvd, exists_prop, and_assoc, and_comm],\nend\n\n/-- The symbol `J(a | b)` is nonzero when `a` and `b` are coprime. -/\nprotected\nlemma ne_zero {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a | b) \u2260 0 :=\nbegin\n  casesI eq_zero_or_ne_zero b with hb,\n  { rw [hb, zero_right],\n    exact one_ne_zero },\n  { contrapose! h, exact eq_zero_iff_not_coprime.1 h },\nend\n\n/-- The symbol `J(a | b)` vanishes if and only if `b \u2260 0` and `a` and `b` are not coprime. -/\nlemma eq_zero_iff {a : \u2124} {b : \u2115} : J(a | b) = 0 \u2194 b \u2260 0 \u2227 a.gcd b \u2260 1 :=\n\u27e8\u03bb h, begin\n  casesI eq_or_ne b 0 with hb hb,\n  { rw [hb, zero_right] at h, cases h },\n  exact \u27e8hb, mt jacobi_sym.ne_zero $ not_not.2 h\u27e9,\nend, \u03bb \u27e8hb, h\u27e9, by { rw \u2190 ne_zero_iff at hb, exactI eq_zero_iff_not_coprime.2 h }\u27e9\n\n/-- The symbol `J(0 | b)` vanishes when `b > 1`. -/\nlemma zero_left {b : \u2115} (hb : 1 < b) : J(0 | b) = 0 :=\n(@eq_zero_iff_not_coprime 0 b \u27e8ne_zero_of_lt hb\u27e9).mpr $\n  by { rw [int.gcd_zero_left, int.nat_abs_of_nat], exact hb.ne' }\n\n/-- The symbol `J(a | b)` takes the value `1` or `-1` if `a` and `b` are coprime. -/\nlemma eq_one_or_neg_one {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a | b) = 1 \u2228 J(a | b) = -1 :=\n(trichotomy a b).resolve_left $ jacobi_sym.ne_zero h\n\n/-- We have that `J(a^e | b) = J(a | b)^e`. -/\nlemma pow_left (a : \u2124) (e b : \u2115) : J(a ^ e | b) = J(a | b) ^ e :=\nnat.rec_on e (by rw [pow_zero, pow_zero, one_left]) $\n  \u03bb _ ih, by rw [pow_succ, pow_succ, mul_left, ih]\n\n/-- We have that `J(a | b^e) = J(a | b)^e`. -/\nlemma pow_right (a : \u2124) (b e : \u2115) : J(a | b ^ e) = J(a | b) ^ e :=\nbegin\n  induction e with e ih,\n  { rw [pow_zero, pow_zero, one_right], },\n  { casesI eq_zero_or_ne_zero b with hb,\n    { rw [hb, zero_pow (succ_pos e), zero_right, one_pow], },\n    { rw [pow_succ, pow_succ, mul_right, ih], } }\nend\n\n/-- The square of `J(a | b)` is `1` when `a` and `b` are coprime. -/\nlemma sq_one {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a | b) ^ 2 = 1 :=\nby cases eq_one_or_neg_one h with h\u2081 h\u2081; rw h\u2081; refl\n\n/-- The symbol `J(a^2 | b)` is `1` when `a` and `b` are coprime. -/\nlemma sq_one' {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a ^ 2 | b) = 1 :=\nby rw [pow_left, sq_one h]\n\n/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/\nlemma mod_left (a : \u2124) (b : \u2115) : J(a | b) = J(a % b | b) :=\ncongr_arg list.prod $ list.pmap_congr _ begin\n  rintro p hp _ _,\n  conv_rhs { rw [legendre_sym.mod, int.mod_mod_of_dvd _\n    (int.coe_nat_dvd.2 $ dvd_of_mem_factors hp), \u2190 legendre_sym.mod] },\nend\n\n/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/\nlemma mod_left' {a\u2081 a\u2082 : \u2124} {b : \u2115} (h : a\u2081 % b = a\u2082 % b) : J(a\u2081 | b) = J(a\u2082 | b) :=\nby rw [mod_left, h, \u2190 mod_left]\n\nend jacobi_sym\n\nnamespace zmod\n\nopen jacobi_sym\n\n/-- If `J(a | b)` is `-1`, then `a` is not a square modulo `b`. -/\nlemma nonsquare_of_jacobi_sym_eq_neg_one {a : \u2124} {b : \u2115} (h : J(a | b) = -1) :\n  \u00ac is_square (a : zmod b) :=\n\u03bb \u27e8r, ha\u27e9, begin\n  rw [\u2190 r.coe_val_min_abs, \u2190 int.cast_mul, int_coe_eq_int_coe_iff', \u2190 sq] at ha,\n  apply (by norm_num : \u00ac (0 : \u2124) \u2264 -1),\n  rw [\u2190 h, mod_left, ha, \u2190 mod_left, pow_left],\n  apply sq_nonneg,\nend\n\n/-- If `p` is prime, then `J(a | p)` is `-1` iff `a` is not a square modulo `p`. -/\nlemma nonsquare_iff_jacobi_sym_eq_neg_one {a : \u2124} {p : \u2115} [fact p.prime] :\n  J(a | p) = -1 \u2194 \u00ac is_square (a : zmod p) :=\nby { rw [\u2190 legendre_sym.to_jacobi_sym], exact legendre_sym.eq_neg_one_iff p }\n\n/-- If `p` is prime and `J(a | p) = 1`, then `a` is q square mod `p`. -/\nlemma is_square_of_jacobi_sym_eq_one {a : \u2124} {p : \u2115} [fact p.prime] (h : J(a | p) = 1) :\n  is_square (a : zmod p) :=\nnot_not.mp $ by { rw [\u2190 nonsquare_iff_jacobi_sym_eq_neg_one, h], dec_trivial }\n\nend zmod\n\n/-!\n### Values at `-1`, `2` and `-2`\n-/\n\nnamespace jacobi_sym\n\n/-- If `\u03c7` is a multiplicative function such that `J(a | p) = \u03c7 p` for all odd primes `p`,\nthen `J(a | b)` equals `\u03c7 b` for all odd natural numbers `b`. -/\nlemma value_at (a : \u2124) {R : Type*} [comm_semiring R] (\u03c7 : R \u2192* \u2124)\n  (hp : \u2200 (p : \u2115) (pp : p.prime) (h2 : p \u2260 2), @legendre_sym p \u27e8pp\u27e9 a = \u03c7 p) {b : \u2115} (hb : odd b) :\n  J(a | b) = \u03c7 b :=\nbegin\n  conv_rhs { rw [\u2190 prod_factors hb.pos.ne', cast_list_prod, \u03c7.map_list_prod] },\n  rw [jacobi_sym, list.map_map, \u2190 list.pmap_eq_map nat.prime _ _ (\u03bb _, prime_of_mem_factors)],\n  congr' 1, apply list.pmap_congr,\n  exact \u03bb p h pp _, hp p pp (hb.ne_two_of_dvd_nat $ dvd_of_mem_factors h)\nend\n\n/-- If `b` is odd, then `J(-1 | b)` is given by `\u03c7\u2084 b`. -/\nlemma at_neg_one {b : \u2115} (hb : odd b) : J(-1 | b) = \u03c7\u2084 b :=\nvalue_at (-1) \u03c7\u2084 (\u03bb p pp, @legendre_sym.at_neg_one p \u27e8pp\u27e9) hb\n\n/-- If `b` is odd, then `J(-a | b) = \u03c7\u2084 b * J(a | b)`. -/\nprotected\nlemma neg (a : \u2124) {b : \u2115} (hb : odd b) : J(-a | b) = \u03c7\u2084 b * J(a | b) :=\nby rw [neg_eq_neg_one_mul, mul_left, at_neg_one hb]\n\n/-- If `b` is odd, then `J(2 | b)` is given by `\u03c7\u2088 b`. -/\nlemma at_two {b : \u2115} (hb : odd b) : J(2 | b) = \u03c7\u2088 b :=\nvalue_at 2 \u03c7\u2088 (\u03bb p pp, @legendre_sym.at_two p \u27e8pp\u27e9) hb\n\n/-- If `b` is odd, then `J(-2 | b)` is given by `\u03c7\u2088' b`. -/\nlemma at_neg_two {b : \u2115} (hb : odd b) : J(-2 | b) = \u03c7\u2088' b :=\nvalue_at (-2) \u03c7\u2088' (\u03bb p pp, @legendre_sym.at_neg_two p \u27e8pp\u27e9) hb\n\nend jacobi_sym\n\n/-!\n### Quadratic Reciprocity\n-/\n\n/-- The bi-multiplicative map giving the sign in the Law of Quadratic Reciprocity -/\ndef qr_sign (m n : \u2115) : \u2124 := J(\u03c7\u2084 m | n)\n\nnamespace qr_sign\n\n/-- We can express `qr_sign m n` as a power of `-1` when `m` and `n` are odd. -/\nlemma neg_one_pow {m n : \u2115} (hm : odd m) (hn : odd n) :\n  qr_sign m n = (-1) ^ ((m / 2) * (n / 2)) :=\nbegin\n  rw [qr_sign, pow_mul, \u2190 \u03c7\u2084_eq_neg_one_pow (odd_iff.mp hm)],\n  cases odd_mod_four_iff.mp (odd_iff.mp hm) with h h,\n  { rw [\u03c7\u2084_nat_one_mod_four h, jacobi_sym.one_left, one_pow], },\n  { rw [\u03c7\u2084_nat_three_mod_four h, \u2190 \u03c7\u2084_eq_neg_one_pow (odd_iff.mp hn), jacobi_sym.at_neg_one hn], }\nend\n\n/-- When `m` and `n` are odd, then the square of `qr_sign m n` is `1`. -/\nlemma sq_eq_one {m n : \u2115} (hm : odd m) (hn : odd n) : (qr_sign m n) ^ 2 = 1 :=\nby rw [neg_one_pow hm hn, \u2190 pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]\n\n/-- `qr_sign` is multiplicative in the first argument. -/\nlemma mul_left (m\u2081 m\u2082 n : \u2115) : qr_sign (m\u2081 * m\u2082) n = qr_sign m\u2081 n * qr_sign m\u2082 n :=\nby simp_rw [qr_sign, nat.cast_mul, map_mul, jacobi_sym.mul_left]\n\n/-- `qr_sign` is multiplicative in the second argument. -/\nlemma mul_right (m n\u2081 n\u2082 : \u2115) [ne_zero n\u2081] [ne_zero n\u2082] :\n  qr_sign m (n\u2081 * n\u2082) = qr_sign m n\u2081 * qr_sign m n\u2082 :=\njacobi_sym.mul_right (\u03c7\u2084 m) n\u2081 n\u2082\n\n/-- `qr_sign` is symmetric when both arguments are odd. -/\nprotected\nlemma symm {m n : \u2115} (hm : odd m) (hn : odd n) : qr_sign m n = qr_sign n m :=\nby rw [neg_one_pow hm hn, neg_one_pow hn hm, mul_comm (m / 2)]\n\n/-- We can move `qr_sign m n` from one side of an equality to the other when `m` and `n` are odd. -/\nlemma eq_iff_eq {m n : \u2115} (hm : odd m) (hn : odd n) (x y : \u2124) :\n  qr_sign m n * x = y \u2194 x = qr_sign m n * y :=\nby refine \u27e8\u03bb h', let h := h'.symm in _, \u03bb h, _\u27e9;\n   rw [h, \u2190 mul_assoc, \u2190 pow_two, sq_eq_one hm hn, one_mul]\n\nend qr_sign\n\nnamespace jacobi_sym\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol, version with `qr_sign` -/\nlemma quadratic_reciprocity' {a b : \u2115} (ha : odd a) (hb : odd b) :\n  J(a | b) = qr_sign b a * J(b | a) :=\nbegin\n  -- define the right hand side for fixed `a` as a `\u2115 \u2192* \u2124`\n  let rhs : \u2115 \u2192 \u2115 \u2192* \u2124 := \u03bb a,\n  { to_fun := \u03bb x, qr_sign x a * J(x | a),\n    map_one' := by { convert \u2190 mul_one _, symmetry, all_goals { apply one_left } },\n    map_mul' := \u03bb x y, by rw [qr_sign.mul_left, nat.cast_mul, mul_left,\n                              mul_mul_mul_comm] },\n  have rhs_apply : \u2200 (a b : \u2115), rhs a b = qr_sign b a * J(b | a) := \u03bb a b, rfl,\n  refine value_at a (rhs a) (\u03bb p pp hp, eq.symm _) hb,\n  have hpo := pp.eq_two_or_odd'.resolve_left hp,\n  rw [@legendre_sym.to_jacobi_sym p \u27e8pp\u27e9, rhs_apply, nat.cast_id,\n      qr_sign.eq_iff_eq hpo ha, qr_sign.symm hpo ha],\n  refine value_at p (rhs p) (\u03bb q pq hq, _) ha,\n  have hqo := pq.eq_two_or_odd'.resolve_left hq,\n  rw [rhs_apply, nat.cast_id, \u2190 @legendre_sym.to_jacobi_sym p \u27e8pp\u27e9, qr_sign.symm hqo hpo,\n      qr_sign.neg_one_pow hpo hqo, @legendre_sym.quadratic_reciprocity' p q \u27e8pp\u27e9 \u27e8pq\u27e9 hp hq],\nend\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol -/\nlemma quadratic_reciprocity {a b : \u2115} (ha : odd a) (hb : odd b) :\n  J(a | b) = (-1) ^ ((a / 2) * (b / 2)) * J(b | a) :=\nby rw [\u2190 qr_sign.neg_one_pow ha hb, qr_sign.symm ha hb, quadratic_reciprocity' ha hb]\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers\nwith `a % 4 = 1` and `b` odd, then `J(a | b) = J(b | a)`. -/\ntheorem quadratic_reciprocity_one_mod_four {a b : \u2115} (ha : a % 4 = 1) (hb : odd b) :\n  J(a | b) = J(b | a) :=\nby rw [quadratic_reciprocity (odd_iff.mpr (odd_of_mod_four_eq_one ha)) hb,\n       pow_mul, neg_one_pow_div_two_of_one_mod_four ha, one_pow, one_mul]\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers\nwith `a` odd and `b % 4 = 1`, then `J(a | b) = J(b | a)`. -/\ntheorem quadratic_reciprocity_one_mod_four' {a b : \u2115} (ha : odd a) (hb : b % 4 = 1) :\n  J(a | b) = J(b | a) :=\n(quadratic_reciprocity_one_mod_four hb ha).symm\n\n/-- The Law of Quadratic Reciprocityfor the Jacobi symbol: if `a` and `b` are natural numbers\nboth congruent to `3` mod `4`, then `J(a | b) = -J(b | a)`. -/\ntheorem quadratic_reciprocity_three_mod_four {a b : \u2115} (ha : a % 4 = 3) (hb : b % 4 = 3) :\n  J(a | b) = - J(b | a) :=\nlet nop := @neg_one_pow_div_two_of_three_mod_four in begin\n  rw [quadratic_reciprocity, pow_mul, nop ha, nop hb, neg_one_mul];\n  rwa [odd_iff, odd_of_mod_four_eq_three],\nend\n\n/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a` (version for `a : \u2115`). -/\nlemma mod_right' (a : \u2115) {b : \u2115} (hb : odd b) : J(a | b) = J(a | b % (4 * a)) :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha\u2080,\n  { rw [mul_zero, mod_zero], },\n  have hb' : odd (b % (4 * a)) := hb.mod_even (even.mul_right (by norm_num) _),\n  rcases exists_eq_pow_mul_and_not_dvd ha\u2080 2 (by norm_num) with \u27e8e, a', ha\u2081', ha\u2082\u27e9,\n  have ha\u2081 := odd_iff.mpr (two_dvd_ne_zero.mp ha\u2081'),\n  nth_rewrite 1 [ha\u2082], nth_rewrite 0 [ha\u2082],\n  rw [nat.cast_mul, mul_left, mul_left, quadratic_reciprocity' ha\u2081 hb,\n      quadratic_reciprocity' ha\u2081 hb', nat.cast_pow, pow_left, pow_left,\n      nat.cast_two, at_two hb, at_two hb'],\n  congr' 1, swap, congr' 1,\n  { simp_rw [qr_sign],\n    rw [\u03c7\u2084_nat_mod_four, \u03c7\u2084_nat_mod_four (b % (4 * a)), mod_mod_of_dvd b (dvd_mul_right 4 a) ] },\n  { rw [mod_left \u2191(b % _), mod_left b, int.coe_nat_mod, int.mod_mod_of_dvd b],\n    simp only [ha\u2082, nat.cast_mul, \u2190 mul_assoc],\n    exact dvd_mul_left a' _, },\n  cases e, { refl },\n  { rw [\u03c7\u2088_nat_mod_eight, \u03c7\u2088_nat_mod_eight (b % (4 * a)), mod_mod_of_dvd b],\n    use 2 ^ e * a', rw [ha\u2082, pow_succ], ring, }\nend\n\n/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a`. -/\nlemma mod_right (a : \u2124) {b : \u2115} (hb : odd b) : J(a | b) = J(a | b % (4 * a.nat_abs)) :=\nbegin\n  cases int.nat_abs_eq a with ha ha; nth_rewrite 1 [ha]; nth_rewrite 0 [ha],\n  { exact mod_right' a.nat_abs hb, },\n  { have hb' : odd (b % (4 * a.nat_abs)) := hb.mod_even (even.mul_right (by norm_num) _),\n    rw [jacobi_sym.neg _ hb, jacobi_sym.neg _ hb', mod_right' _ hb, \u03c7\u2084_nat_mod_four,\n        \u03c7\u2084_nat_mod_four (b % (4 * _)), mod_mod_of_dvd b (dvd_mul_right 4 _)], }\nend\n\nend jacobi_sym\n\nend jacobi\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/legendre_symbol/jacobi_symbol.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7308456955897551}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n\nThe complex numbers, modelled as R^2 in the obvious way.\n-/\nimport data.real.basic tactic.ring algebra.field\n\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8a, b\u27e9 := rfl\n\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\ndef of_real (r : \u211d) : \u2102 := \u27e8r, 0\u27e9\ninstance : has_coe \u211d \u2102 := \u27e8of_real\u27e9\n@[simp] lemma of_real_eq_coe (r : \u211d) : of_real r = r := rfl\n\n@[simp] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\n\n@[simp] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\ninstance : has_zero \u2102 := \u27e8(0 : \u211d)\u27e9\ninstance : inhabited \u2102 := \u27e80\u27e9\n\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\nlemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\n@[simp] theorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\ninstance : has_one \u2102 := \u27e8(1 : \u211d)\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n@[simp] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := rfl\n@[simp] lemma I_im : I.im = 1 := rfl\n\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n@[simp] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s := rfl\n\n@[simp] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r := rfl\n@[simp] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r := rfl\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n@[simp] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\next_iff.2 $ by simp\n\ndef conj (z : \u2102) : \u2102 := \u27e8z.re, -z.im\u27e9\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := rfl\n\n@[simp] lemma conj_of_real (r : \u211d) : conj r = r :=\next_iff.2 $ by simp\n\n@[simp] lemma conj_zero : conj 0 = 0 := conj_of_real 0\n@[simp] lemma conj_one : conj 1 = 1 := conj_of_real 1\n@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp\n\n@[simp] lemma conj_add (z w : \u2102) : conj (z + w) = conj z + conj w :=\next_iff.2 $ by simp\n\n@[simp] lemma conj_neg (z : \u2102) : conj (-z) = -conj z :=\next_iff.2 $ by simp\n\n@[simp] lemma conj_mul (z w : \u2102) : conj (z * w) = conj z * conj w :=\next_iff.2 $ by simp\n\n@[simp] lemma conj_conj (z : \u2102) : conj (conj z) = z :=\next_iff.2 $ by simp\n\nlemma conj_bijective : function.bijective conj :=\n\u27e8function.injective_of_has_left_inverse \u27e8conj, conj_conj\u27e9,\n function.surjective_of_has_right_inverse \u27e8conj, conj_conj\u27e9\u27e9\n\nlemma conj_inj {z w : \u2102} : conj z = conj w \u2194 z = w :=\nconj_bijective.1.eq_iff\n\n@[simp] lemma conj_eq_zero {z : \u2102} : conj z = 0 \u2194 z = 0 :=\nby simpa using @conj_inj z 0\n\n@[simp] lemma eq_conj_iff_real (z : \u2102) : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n\u27e8\u03bb h, \u27e8z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)\u27e9,\n \u03bb \u27e8h, e\u27e9, e.symm \u25b8 rfl\u27e9\n\ndef norm_sq (z : \u2102) : \u211d := z.re * z.re + z.im * z.im\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := by simp [norm_sq]\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := by simp [norm_sq]\n@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\n@[simp] lemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\n\u27e8\u03bb h, ext\n  (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n  (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),\n \u03bb h, h.symm \u25b8 norm_sq_zero\u27e9\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\nby rw [lt_iff_le_and_ne, ne, eq_comm]; simp [norm_sq_nonneg]\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nby dsimp [norm_sq]; ring\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nby dsimp [norm_sq]; ring\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm]\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\next_iff.2 $ by simp [two_mul]\n\ninstance : comm_ring \u2102 :=\nby refine { zero := 0, add := (+), neg := has_neg.neg, one := 1, mul := (*), ..};\n   { intros, apply ext_iff.2; split; simp; ring }\n\n@[simp] lemma sub_re (z w : \u2102) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : \u2102) : (z - w).im = z.im - w.im := rfl\n@[simp] lemma of_real_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s := rfl\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\next_iff.2 $ by simp [two_mul]\n\nlemma norm_sq_sub (z w : \u2102) : norm_sq (z - w) =\n  norm_sq z + norm_sq w - 2 * (z * conj w).re :=\nby rw [sub_eq_add_neg, norm_sq_add]; simp [-mul_re]\n\nnoncomputable instance : has_inv \u2102 := \u27e8\u03bb z, conj z * ((norm_sq z)\u207b\u00b9:\u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((norm_sq z)\u207b\u00b9:\u211d) := rfl\n@[simp] lemma inv_re (z : \u2102) : (z\u207b\u00b9).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : \u2102) : (z\u207b\u00b9).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\nlemma of_real_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = r\u207b\u00b9 :=\next_iff.2 $ begin\n  simp,\n  by_cases r = 0, {simp [h]},\n  rw [\u2190 div_div_eq_div_mul, div_self h, one_div_eq_inv]\nend\n\nlemma inv_zero : (0\u207b\u00b9 : \u2102) = 0 :=\nby rw [\u2190 of_real_zero, \u2190 of_real_inv, inv_zero]\n\ntheorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nby rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 of_real_mul,\n  mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]\n\nnoncomputable instance : discrete_field \u2102 :=\n{ inv := has_inv.inv,\n  zero_ne_one := mt (congr_arg re) zero_ne_one,\n  mul_inv_cancel := @mul_inv_cancel,\n  inv_mul_cancel := \u03bb z h, by rw [mul_comm, mul_inv_cancel h],\n  inv_zero := inv_zero,\n  has_decidable_eq := classical.dec_eq _,\n  ..complex.comm_ring }\n\n@[simp] lemma of_real_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\nby rw [division_def, of_real_mul, division_def, of_real_inv]\n\n@[simp] theorem of_real_int_cast : \u2200 n : \u2124, ((n : \u211d) : \u2102) = n :=\nint.eq_cast (\u03bb n, ((n : \u211d) : \u2102)) rfl (by simp)\n\n@[simp] theorem of_real_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\nby rw [\u2190 int.cast_coe_nat, of_real_int_cast]; refl\n\n@[simp] lemma conj_inv (z : \u2102) : conj z\u207b\u00b9 = (conj z)\u207b\u00b9 :=\nif h : z = 0 then by simp [h] else\n(domain.mul_left_inj (mt conj_eq_zero.1 h)).1 $\nby rw [\u2190 conj_mul]; simp [h, -conj_mul]\n\n@[simp] lemma conj_div (z w : \u2102) : conj (z / w) = conj z / conj w :=\nby rw [division_def, conj_mul, conj_inv]; refl\n\n@[simp] lemma norm_sq_inv (z : \u2102) : norm_sq z\u207b\u00b9 = (norm_sq z)\u207b\u00b9 :=\nif h : z = 0 then by simp [h] else\n(domain.mul_left_inj (mt norm_sq_eq_zero.1 h)).1 $\nby rw [\u2190 norm_sq_mul]; simp [h, -norm_sq_mul]\n\n@[simp] lemma norm_sq_div (z w : \u2102) : norm_sq (z / w) = norm_sq z / norm_sq w :=\nby rw [division_def, norm_sq_mul, norm_sq_inv]; refl\n\ninstance char_zero_complex : char_zero \u2102 :=\nadd_group.char_zero_of_inj_zero $ \u03bb n h,\nby rwa [\u2190 of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h\n\n@[simp] theorem of_real_rat_cast : \u2200 n : \u211a, ((n : \u211d) : \u2102) = n :=\nby apply rat.eq_cast (\u03bb n, ((n : \u211d) : \u2102)); simp\n\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 :=\nby rw [add_conj]; simp; rw [mul_div_cancel_left (z.re:\u2102) two_ne_zero']\n\nnoncomputable def abs (z : \u2102) : \u211d := (norm_sq z).sqrt\n\nlocal notation `abs'` := _root_.abs\n\n@[simp] lemma abs_of_real (r : \u211d) : abs r = abs' r :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\nlemma mul_self_abs (z : \u2102) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]\n@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]\n@[simp] lemma abs_I : abs I = 1 := by simp [abs]\n\nlemma abs_nonneg (z : \u2102) : 0 \u2264 abs z :=\nreal.sqrt_nonneg _\n\n@[simp] lemma abs_eq_zero {z : \u2102} : abs z = 0 \u2194 z = 0 :=\n(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero\n\n@[simp] lemma abs_conj (z : \u2102) : abs (conj z) = abs z :=\nby simp [abs]\n\n@[simp] lemma abs_mul (z w : \u2102) : abs (z * w) = abs z * abs w :=\nby rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl\n\nlemma abs_re_le_abs (z : \u2102) : abs' z.re \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply re_sq_le_norm_sq\n\nlemma abs_im_le_abs (z : \u2102) : abs' z.im \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply im_sq_le_norm_sq\n\nlemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : \u2102) : z.im \u2264 abs z :=\n(abs_le.1 (abs_im_le_abs _)).2\n\nlemma abs_add (z w : \u2102) : abs (z + w) \u2264 abs z + abs w :=\n(mul_self_le_mul_self_iff (abs_nonneg _)\n  (add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $\nbegin\n  rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,\n      add_right_comm, norm_sq_add, add_le_add_iff_left,\n      mul_assoc, mul_le_mul_left (@two_pos \u211d _)],\n  simpa [-mul_re] using re_le_abs (z * conj w)\nend\n\ninstance : is_absolute_value abs :=\n{ abv_nonneg  := abs_nonneg,\n  abv_eq_zero := \u03bb _, abs_eq_zero,\n  abv_add     := abs_add,\n  abv_mul     := abs_mul }\nopen is_absolute_value\n\n@[simp] lemma abs_abs (z : \u2102) : abs' (abs z) = abs z :=\n_root_.abs_of_nonneg (abs_nonneg _)\n\n@[simp] lemma abs_pos {z : \u2102} : 0 < abs z \u2194 z \u2260 0 := abv_pos abs\n@[simp] lemma abs_neg : \u2200 z, abs (-z) = abs z := abv_neg abs\nlemma abs_sub : \u2200 z w, abs (z - w) = abs (w - z) := abv_sub abs\nlemma abs_sub_le : \u2200 a b c, abs (a - c) \u2264 abs (a - b) + abs (b - c) := abv_sub_le abs\n@[simp] theorem abs_inv : \u2200 z, abs z\u207b\u00b9 = (abs z)\u207b\u00b9 := abv_inv abs\n@[simp] theorem abs_div : \u2200 z w, abs (z / w) = abs z / abs w := abv_div abs\nlemma abs_abs_sub_le_abs_sub : \u2200 z w, abs' (abs z - abs w) \u2264 abs (z - w) := abs_abv_sub_le_abv_sub abs\n\nlemma abs_le_abs_re_add_abs_im (z : \u2102) : abs z \u2264 abs' z.re + abs' z.im :=\nby simpa [re_add_im] using abs_add z.re (z.im * I)\n\nnoncomputable def lim (f : \u2115 \u2192 \u2102) : \u2102 :=\n\u27e8real.lim (\u03bb n, (f n).re), real.lim (\u03bb n, (f n).im)\u27e9\n\ntheorem is_cau_seq_re (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).re) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n\ntheorem is_cau_seq_im (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).im) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n\ntheorem equiv_lim (f : cau_seq \u2102 abs) : f \u2248 cau_seq.const abs (lim f) :=\n\u03bb \u03b5 \u03b50, (exists_forall_ge_and\n  (real.equiv_lim \u27e8_, is_cau_seq_re f\u27e9 _ (half_pos \u03b50))\n  (real.equiv_lim \u27e8_, is_cau_seq_im f\u27e9 _ (half_pos \u03b50))).imp $\n\u03bb i H j ij, begin\n  cases H _ ij with H\u2081 H\u2082,\n  apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),\n  simpa using add_lt_add H\u2081 H\u2082\nend\n\nend complex\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8840392741081575, "lm_q1q2_score": 0.7308456943268907}}
{"text": "---------------\n-- *Tactics* --\n---------------\n\n--------------------------\n-- Entering Tactic Mode --\n--------------------------\n\ntheorem test (p q : Prop) (hp : p) (hq : q) : p \u2227 q \u2227 p := by \n  apply And.intro\n  exact hp\n  apply And.intro\n  exact hq\n  exact hp\n\n/- The *apply tactic* applies an expression, viewed as denoting a function with \nzero or more arguments. It unifies the conclusion with the expression in the \ncurrent goal, and creates new goals for the remaining arguments, provided that \nno later arguments depend on them. In the example above, the command \n*apply And.intro* yields two subgoals: \n\n    case left\n    p : Prop,\n    q : Prop,\n    hp : p,\n    hq : q\n    \u22a2 p\n\n    case right\n    p : Prop,\n    q : Prop,\n    hp : p,\n    hq : q\n    \u22a2 q \u2227 p\n\n-/\n\n/- The first goal is met with the command *exact hp*. The exact command is just a \nvariant of apply which signals that the expression given should fill the goal\nexactly. It is good form to use it in a tactic proof, since its failure signals \nthat something has gone wrong. It is also more robust than apply, since the \nelaborator takes the expected type, given by the target of the goal, into \naccount when processing the expression that is being applied. In this case, \nhowever, apply would work just as well.-/\n\n/- You can see the resulting proof term with the *#print* command:-/\n\n#print test\n\n/- Tactic commands can take compound expressions, not just single identifiers. \nThe following is a shorter version of the preceding proof: -/\n\ntheorem test' (p q : Prop) (hp : p) (hq : q) : p \u2227 q \u2227 p := by\n  apply And.intro hp\n  exact And.intro hq hp\n\n/- Tactics that may produce multiple subgoals often tag them. For example, the \ntactic apply And.intro tagged the first sugoal as left, and the second as right. \nIn the case of the apply tactic, the tags are inferred from the parameters \nnames used in the And.intro declaration. You can structure your tactics using \nthe notation case <tag> => <tactics>. The following is a structured version of \nour first tactic proof in this chapter. -/\n\ntheorem test'' (p q : Prop) (hp : p) (hq : q) : p \u2227 q \u2227 p := by\n  apply And.intro\n  case left => exact hp\n  case right =>\n    apply And.intro\n    case left => exact hq\n    case right => exact hp\n\n/- For simple sugoals, it may not be worth selecting a subgoal using its tag, but you may still\n want to structure the proof. Lean also provides the \"bullet\" notation \n . <tactics> (or \u00b7 <tactics>) for structuring proof. -/\n\ntheorem test''' (p q : Prop) (hp : p) (hq : q) : p \u2227 q \u2227 p := by\n  apply And.intro\n  . exact hp\n  . apply And.intro\n    . exact hq\n    . exact hp\n\n-------------------\n-- Basic Tactics --\n-------------------\n\n/- In addition to apply and exact, another useful tactic is *intro*, which \nintroduces a hypothesis. What follows is an example of an identity from \npropositional logic that we proved in a previous chapter, now proved using \ntactics. -/\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by\n  apply Iff.intro\n  . intro h\n    apply Or.elim (And.right h)\n    . intro hq\n      apply Or.inl\n      apply And.intro\n      . exact And.left h\n      . exact hq\n    . intro hr\n      apply Or.inr\n      apply And.intro\n      . exact And.left h\n      . exact hr\n  . intro h\n    apply Or.elim h\n    . intro hpq\n      apply And.intro\n      . exact And.left hpq\n      . apply Or.inl\n        exact And.right hpq\n    . intro hpr\n      apply And.intro\n      . exact And.left hpr\n      . apply Or.inr\n        exact And.right hpr\n\n/- The intro command can more generally be used to introduce a variable of any type: -/\n\nexample (\u03b1 : Type) : \u03b1 \u2192 \u03b1 := by \n  intro a \n  exact a\n\nexample (\u03b1 : Type) : \u2200 x : \u03b1, x = x := by\n  intro x\n  exact rfl\n\n/- You can use it to introduce several variables: -/\n\nexample : \u2200 a b c : Nat, a = b \u2192 a = c \u2192 c = b := by\n  intro a b c h\u2081 h\u2082 \n  exact Eq.trans (Eq.symm h\u2082) h\u2081\n\n/- As the apply tactic is a command for constructing function applications\ninteractively, the intro tactic is a command for constructing function \nabstractions interactively (i.e., terms of the form fun x => e). As with \nlambda abstraction notation, the intro tactic allows us to use an implicit match.-/\n\nexample (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, q x \u2227 p x := by\n  intro \u27e8w, hpw, hqw\u27e9\n  exact \u27e8w, hqw, hpw\u27e9\n\n\n/- You can also provide multiple alternatives like in the match expression.-/\nexample (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, q x \u2227 p x := by \n  intro \n  | \u27e8w, hpw, hqw\u27e9 => exact \u27e8w, hqw, hpw\u27e9\n\nexample (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) : (\u2203 x, p x \u2228 q x) \u2192 \u2203 x, q x \u2228 p x := by\n  intro\n    | \u27e8w, Or.inl h\u27e9 => exact \u27e8w, Or.inr h\u27e9\n    | \u27e8w, Or.inr h\u27e9 => exact \u27e8w, Or.inl h\u27e9\n\n/- The *assumption* tactic looks through the assumptions in context of the \ncurrent goal, and if there is one matching the conclusion, it applies it. -/\n\nexample (x y z w : Nat) (h\u2081 : x = y) (h\u2082 : y = z) (h\u2083 : z = w) : x = w := by\n  apply Eq.trans h\u2081\n  apply Eq.trans h\u2082\n  assumption\n\nexample (x y z w : Nat) (h\u2081 : x = y) (h\u2082 : y = z) (h\u2083 : z = w) : x = w := by\n  apply Eq.trans h\u2081\n  apply Eq.trans h\u2082\n  apply Eq.trans h\u2083\n  exact rfl\n\n/- The following example uses the intros command to introduce the three \nvariables and two hypotheses automatically: -/\n\nexample : \u2200 a b c : Nat, a = b \u2192 a = c \u2192 c = b := by\n  intros\n  apply Eq.trans\n  apply Eq.symm\n  assumption\n  assumption\n\n/- The rfl tactic is syntax sugar for exact rfl -/\nexample (y : Nat) : (fun x : Nat => 0) y = 0 :=\n  by rfl\n\n/- The repeat combinator can be used to apply a tactic several times. -/\nexample : \u2200 a b c : Nat, a = b \u2192 a = c \u2192 c = b := by\n  intros\n  apply Eq.trans\n  apply Eq.symm\n  repeat assumption\n\n/- Another tactic that is sometimes useful is the *revert* tactic, \nwhich is, in a sense, an inverse to intro.-/\n\nexample (x : Nat) : x = x := by\n  revert x -- goal is \u22a2 \u2200 (x : Nat), x = x\n  intro y -- goal is y : Nat \u22a2 y = y\n  rfl\n\nexample (x : Nat) : x = x := by rfl\n\n/- Moving a hypothesis into the goal yields an implication: -/\nexample (x y : Nat) (h : x = y) : y = x := by\n  apply Eq.symm h \n\nexample (x y : Nat) (h : x = y) : y = x := by\n  revert h \n  intro h\u2081 \n  apply Eq.symm \n  assumption\n\n/- But revert is even more clever, in that it will revert not only an element of \nthe context but also all the subsequent elements of the context that depend on it. \nFor example, reverting x in the example above brings h along with it: -/\n\nexample (x y : Nat) (h : x = y) : y = x := by\n  revert x -- goal is y : Nat \u22a2 \u2200 (x : Nat), x = y \u2192 y = x\n  intros\n  apply Eq.symm\n  assumption\n\n/- The mnemonic in the notation above is that you are generalizing the goal by \nsetting 3 to an arbitrary variable x. Be careful: not every generalization \npreserves the validity of the goal. Here, *generalize* replaces a goal that could \nbe proved using rfl with one that is not provable:-/\n\nexample : 2 + 3 = 5 := by rfl\n\nexample : 2 + 3 = 5 := by\n  generalize  3 = x -- goal is x : Nat \u22a2 2 + x = 5\n  admit\n\n/- In this example, the admit tactic is the analogue of the sorry proof term. \nIt closes the current goal, producing the usual warning that sorry has been used.\nTo preserve the validity of the previous goal, the generalize tactic allows us \nto record the fact that 3 has been replaced by x. All you need to do is to \nprovide a label, and generalize uses it to store the assignment in the local \ncontext:-/\n\nexample : 2 + 3 = 5 := by\n  generalize h : 3 = x -- goal is x : Nat, h : 3 = x \u22a2 2 + x = 5\n  rw [\u2190 h]\n\n--------------------\n-- *More Tactics* --\n--------------------\n\n/- Some additional tactics are useful for constructing and destructing propositions \nand data. For example, when applied to a goal of the form p \u2228 q, you use tactics \nsuch as apply Or.inl and apply Or.inr. Conversely, the cases tactic can be used to \ndecompose a disjunction. -/\n\nexample (p q : Prop) : p \u2228 q \u2192 q \u2228 p := by\n  intro h\n  cases h with\n  | inl hp => apply Or.inr; exact hp\n  | inr hq => apply Or.inl; exact hq\n\n/- You can also use a *(unstructured)* cases without the with and a tactic for \neach alternative. -/\n\nexample (p q : Prop) : p \u2228 q \u2192 q \u2228 p := by\n  intro h\n  cases h\n  apply Or.inr\n  assumption\n  apply Or.inl\n  assumption\n\n/- The (unstructured) cases is particularly useful when you can close several \nsubgoals using the same tactic. -/\n\n-- example (p q : Prop) : p \u2228 q \u2192 q \u2228 p := by\n--   intro h\n--   cases h \n--   repeat assumption\n\n/- The cases tactic can also be used to decompose a conjunction. -/\n\nexample (p q : Prop) : p \u2227 q \u2192 q \u2227 p := by\n  intro h \n  cases h with \n  | intro hp hq => constructor; exact hq; exact hp \n\n/- You can use cases and constructor with an existential quantifier: -/\n\nexample (p q : Nat \u2192 Prop) : (\u2203 x, p x) \u2192 \u2203 x, p x \u2228 q x := by\n  intro h\n  cases h with\n  | intro x px => constructor; apply Or.inl; exact px\n\n/- Here, the constructor tactic leaves the first component of the existential \nassertion, the value of x, implicit. It is represented by a metavariable, which \nshould be instantiated later on. In the previous example, the proper value of the\nmetavariable is determined by the tactic exact px, since px has type p x. If you \nwant to specify a witness to the existential quantifier explicitly, you can use \nthe *exists tactic* instead -/\n\nexample (p q : Nat \u2192 Prop) : (\u2203 x, p x) \u2192 \u2203 x, p x \u2228 q x := by\n  intro h\n  cases h with\n  | intro x px => exists x; apply Or.inl; exact px  \n\nexample (p q : Nat \u2192 Prop) : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, q x \u2227 p x := by\n  intro h\n  cases h with\n  | intro x hpq => \n    cases hpq with \n    | intro hp hq => exists x; exact And.intro hq hp\n  \nexample (p q : Nat \u2192 Prop) : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, q x \u2227 p x := by\n  intro h\n  cases h with\n  | intro x hpq =>\n    cases hpq with\n    | intro hp hq =>\n      exists x\n      constructor <;> assumption\n\n/- These tactics can be used on data just as well as propositions. In the next \ntwo examples, they are used to define functions which swap the components of the \nproduct and sum types: -/\n\ndef swap_pair : \u03b1 \u00d7 \u03b2 \u2192 \u03b2 \u00d7 \u03b1 := by\n  intro p\n  cases p \n  constructor <;> assumption\n\ndef swap_sum : Sum \u03b1 \u03b2 \u2192 Sum \u03b2 \u03b1 := by\n  intro p \n  cases p \n  . apply Sum.inr; assumption\n  . apply Sum.inl; assumption\n\n\n/- Note that up to the names we have chosen for the variables, the definitions \nare identical to the proofs of the analogous propositions for conjunction and \ndisjunction. The cases tactic will also do a case distinction on a natural number: -/\n\nopen Nat\nexample (P : Nat \u2192 Prop) (h\u2080 : P 0) (h\u2081 : \u2200 n, P (succ n)) (m : Nat) : P m := by\n  cases m with \n  | zero => exact h\u2080\n  | succ m' => exact h\u2081 m'\n\n/- The *contradiction* tactic searches for a contradiction among the hypotheses of \nthe current goal: -/\n\nexample (p q : Prop) : p \u2227 \u00ac p \u2192 q := by\n  intro h\n  cases h \n  contradiction  \n\n/- You can also use match in tactic blocks. -/\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by\n  apply Iff.intro \n  . intro\n  | \u27e8hp, Or.inl hq\u27e9 => exact Or.inl \u27e8hp, hq\u27e9\n  | \u27e8hp, Or.inr hr\u27e9 => exact Or.inr \u27e8hp, hr\u27e9\n  . intro \n  | Or.inl \u27e8hp, hq\u27e9 => exact \u27e8hp, Or.inl hq\u27e9\n  | Or.inr \u27e8hp, hr\u27e9 => exact \u27e8hp, Or.inr hr\u27e9    \n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by\n  apply Iff.intro\n  . intro\n     | \u27e8hp, Or.inl hq\u27e9 => apply Or.inl; constructor <;> assumption\n     | \u27e8hp, Or.inr hr\u27e9 => apply Or.inr; constructor <;> assumption\n  . intro\n     | Or.inl \u27e8hp, hq\u27e9 => constructor; assumption; apply Or.inl; assumption\n     | Or.inr \u27e8hp, hr\u27e9 => constructor; assumption; apply Or.inr; assumption\n\n---------------------------------\n-- *Structuring Tactic Proofs* --\n---------------------------------\n\n/- Tactics often provide an efficient way of building a proof, but long sequences \nof instructions can obscure the structure of the argument. In this section, we \ndescribe some means that help provide structure to a *tactic-style proof*, making \nsuch proofs more readable and robust. -/\n\n/- One thing that is nice about Lean's proof-writing syntax is that it is \npossible to *mix term-style and tactic-style proofs*, and pass between the two \nfreely. For example, the tactics apply and exact expect arbitrary terms, which \nyou can write using have, show, and so on. Conversely, when writing an arbitrary \nLean term, you can always invoke the tactic mode *by inserting a by block*. The \nfollowing is a somewhat toy example: -/\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) := by\n  intro h\n  exact\n    have hp : p := h.left\n    have hqr : q \u2228 r := h.right\n    show (p \u2227 q) \u2228 (p \u2227 r) by\n      cases hqr with\n      | inl hq => exact Or.inl \u27e8hp, hq\u27e9\n      | inr hr => exact Or.inr \u27e8hp, hr\u27e9\n\n-- The following is a more natural example:\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by\n  apply Iff.intro\n  . intro h\n    cases h.right with\n    | inl hq =>\n      show (p \u2227 q) \u2228 (p \u2227 r)\n      exact Or.inl \u27e8h.left, hq\u27e9\n    | inr hr =>\n      show (p \u2227 q) \u2228 (p \u2227 r)\n      exact Or.inr \u27e8h.left, hr\u27e9\n  . intro h\n    cases h with\n    | inl hpq =>\n      show p \u2227 (q \u2228 r)\n      exact \u27e8hpq.left, Or.inl hpq.right\u27e9\n    | inr hpr =>\n      show p \u2227 (q \u2228 r)\n      exact \u27e8hpr.left, Or.inr hpr.right\u27e9\n\n/- The show tactic can actually be used to rewrite a goal to something \ndefinitionally equivalent: -/\n\nexample (n : Nat) : n + 1 = Nat.succ n := by rfl\n\nexample (n : Nat) : n + 1 = Nat.succ n := by \n  show Nat.succ n = Nat.succ n \n  rfl\n\n/- There is also a *have tactic*, which introduces a new subgoal, just as when \nwriting proof terms: -/\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) := by\n  intro \u27e8hp, hqr\u27e9\n  show (p \u2227 q) \u2228 (p \u2227 r)\n  cases hqr with\n  | inl hq =>\n    have hpq : p \u2227 q := And.intro hp hq\n    apply Or.inl\n    exact hpq\n  | inr hr =>\n    have hpr : p \u2227 r := And.intro hp hr\n    apply Or.inr\n    exact hpr\n\n/- As with proof terms, you can omit the label in the have tactic, in which case,\nthe default label this is used: -/\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) := by\n  intro \u27e8hp, hqr\u27e9\n  show (p \u2227 q) \u2228 (p \u2227 r)\n  cases hqr with\n  | inl hq =>\n    have : p \u2227 q := And.intro hp hq\n    apply Or.inl\n    exact this\n  | inr hr =>\n    have : p \u2227 r := And.intro hp hr\n    apply Or.inr\n    exact this\n\n/- The types in a have tactic can be omitted, so you can write have \n*hp := h.left* and have *hqr := h.right*. In fact, with this notation, you can \neven omit both the type and the label, in which case the new fact is introduced \nwith the label this. -/\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) := by\n  intro \u27e8hp, hqr\u27e9\n  cases hqr with\n  | inl hq =>\n    have := And.intro hp hq\n    apply Or.inl; exact this\n  | inr hr => \n    have := And.intro hp hr \n    apply Or.inr; exact this\n\n/- Lean also has a *let* tactic, which is similar to the *have* tactic, but is \nused to introduce local definitions instead of auxiliary facts. It is the tactic \nanalogue of a let in a proof term. -/\n\nexample : \u2203 x, x + 2 = 8 := by \n  let a : Nat := 6\n  exists a\n  rfl\n\n/- We have used . to create nested tactic blocks. In a nested block, Lean focuses \non the first goal, and generates an error if it has not been fully solved at the \nend of the block. This can be helpful in indicating the separate proofs of \nmultiple subgoals introduced by a tactic. The notation . is whitespace sensitive \nand relies on the indentation to detect whether the tactic block ends. \nAlternatively, you can define tactic blocks usind curly braces and semicolons. -/\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by\n  apply Iff.intro\n  { intro h;\n    cases h.right;\n    { show (p \u2227 q) \u2228 (p \u2227 r);\n      exact Or.inl \u27e8h.left, \u2039q\u203a\u27e9 }\n    { show (p \u2227 q) \u2228 (p \u2227 r);\n      exact Or.inr \u27e8h.left, \u2039r\u203a\u27e9 } }\n  { intro h;\n    cases h;\n    { show p \u2227 (q \u2228 r);\n      rename_i hpq;\n      exact \u27e8hpq.left, Or.inl hpq.right\u27e9 }\n    { show p \u2227 (q \u2228 r);\n      rename_i hpr;\n      exact \u27e8hpr.left, Or.inr hpr.right\u27e9 } }\n\n--------------------------\n-- *Tactic Combinators* --\n--------------------------\n\n/- *Tactic combinators* are operations that form new tactics from old ones. \nA sequencing combinator is already implicit in the by block: -/\n\nexample (p q : Prop) (hp : p) : p \u2228 q := by\n  apply Or.inl; assumption\n\n/- Here, apply Or.inl; assumption is functionally *equivalent to a single tactic* \nwhich first applies apply Or.inl and then applies assumption.\n\n\nIn *t\u2081 <;> t\u2082*, the <;> operator provides a parallel version of the sequencing \noperation: *t\u2081 is applied to the current goal, and then t\u2082 is applied to all* \nthe resulting subgoals:\n-/\n\nexample (p q : Prop) (hp : p) (hq : q) : p \u2227 q :=\n  by constructor <;> assumption\n\n/- This is especially useful when the resulting goals can be finished off in a \nuniform way, or, at least, when it is possible to make progress on all of them \nuniformly. \n \nThe *first | t\u2081 | t\u2082 | ... | tn* applies each t\u1d62 until one succeeds, or else fails: -/\n\nexample (p q : Prop) (hp : p) : p \u2228 q := by\n  first | apply Or.inl; assumption | apply Or.inr; assumption \n\nexample (p q : Prop) (hp : p) : p \u2228 q := by\n  first | apply Or.inl; assumption \n\n/- In the first example, the left branch succeeds, whereas in the second one, it \nis the right one that succeeds. In the next three examples, the same compound \ntactic succeeds in each case. -/\n\nexample (p q r : Prop) (hp : p) : p \u2228 q \u2228 r :=\n  by repeat (first | apply Or.inl; assumption | apply Or.inr | assumption)\n\nexample (p q r : Prop) (hq : q) : p \u2228 q \u2228 r :=\n  by repeat (first | apply Or.inl; assumption | apply Or.inr | assumption)\n\nexample (p q r : Prop) (hr : r) : p \u2228 q \u2228 r :=\n  by repeat (first | apply Or.inl; assumption | apply Or.inr | assumption)\n\n-- *Be careful: repeat (try t) will loop forever, because the inner tactic never fails.*\n\n/- In a proof, there are often multiple goals outstanding. Parallel sequencing is \none way to arrange it so that a single tactic is applied to multiple goals, but \nthere are other ways to do this. For example, *all_goals t* applies t to all open \ngoals: -/\n\nexample (p q r : Prop) (hp : p) (hq : q) (hr : r) : p \u2227 q \u2227 r := by\n  constructor\n  all_goals (try constructor)\n  all_goals assumption\n\n/- In this case, the *any_goals* tactic provides a more robust solution. It is \nsimilar to all_goals, except it fails unless its argument succeeds on at \nleast one goal. -/\n\nexample (p q r : Prop) (hp : p) (hq : q) (hr : r) : p \u2227 q \u2227 r := by\n  constructor\n  any_goals constructor\n  any_goals assumption\n\n-- The first tactic in the by block below repeatedly splits conjunctions:\nexample (p q r : Prop) (hp : p) (hq : q) (hr : r) :\n    p \u2227 ((p \u2227 q) \u2227 r) \u2227 (q \u2227 r \u2227 p) := by\n  repeat (any_goals constructor)\n  all_goals assumption\n\n-- In fact, we can compress the full tactic down to one line:\nexample (p q r : Prop) (hp : p) (hq : q) (hr : r) :\n      p \u2227 ((p \u2227 q) \u2227 r) \u2227 (q \u2227 r \u2227 p) := by\n  repeat (any_goals (first | constructor | assumption))\n\n\n-----------------\n-- *Rewriting* --\n-----------------\n\n-- Here are some more examples with lists:\nopen List\n\nexample (xs : List Nat)\n        : reverse (xs ++ [1, 2, 3]) = [3, 2, 1] ++ reverse xs := by\n  simp\n\nexample (xs ys : List \u03b1)\n        : length (reverse (xs ++ ys)) = length xs + length ys := by\n  simp [Nat.add_comm]\n\nexample (xs ys : List \u03b1)\n        : length (reverse (xs ++ ys)) = length xs + length ys := by\n  simp\n  apply Nat.add_comm\n", "meta": {"author": "cristinaborza", "repo": "Logic-in-Lean", "sha": "53b0c76f8e8cab8a465f4a6621f623139c038dc7", "save_path": "github-repos/lean/cristinaborza-Logic-in-Lean", "path": "github-repos/lean/cristinaborza-Logic-in-Lean/Logic-in-Lean-53b0c76f8e8cab8a465f4a6621f623139c038dc7/tactics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7308222106145909}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\nimport data.list.perm\n\n/-!\n# Sorting algorithms on lists\n\nIn this file we define `list.sorted r l` to be an alias for `pairwise r l`. This alias is preferred\nin the case that `r` is a `<` or `\u2264`-like relation. Then we define two sorting algorithms:\n`list.insertion_sort` and `list.merge_sort`, and prove their correctness.\n-/\n\nopen list.perm\n\nuniverse uu\n\nnamespace list\n\n/-!\n### The predicate `list.sorted`\n-/\n\nsection sorted\n\nvariables {\u03b1 : Type uu} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {a : \u03b1} {l : list \u03b1}\n\n/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`\n  is a `<` or `\u2264`-like relation (transitive and antisymmetric or asymmetric) -/\ndef sorted := @pairwise\n\ninstance decidable_sorted [decidable_rel r] (l : list \u03b1) : decidable (sorted r l) :=\nlist.decidable_pairwise _\n\n@[simp] theorem sorted_nil : sorted r [] := pairwise.nil\n\nlemma sorted.of_cons : sorted r (a :: l) \u2192 sorted r l := pairwise.of_cons\n\ntheorem sorted.tail {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {l : list \u03b1} (h : sorted r l) : sorted r l.tail :=\nh.tail\n\ntheorem rel_of_sorted_cons {a : \u03b1} {l : list \u03b1} : sorted r (a :: l) \u2192\n  \u2200 b \u2208 l, r a b :=\nrel_of_pairwise_cons\n\n@[simp] theorem sorted_cons {a : \u03b1} {l : list \u03b1} :\n  sorted r (a :: l) \u2194 (\u2200 b \u2208 l, r a b) \u2227 sorted r l :=\npairwise_cons\n\nprotected theorem sorted.nodup {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_irrefl \u03b1 r] {l : list \u03b1} (h : sorted r l) :\n  nodup l :=\nh.nodup\n\ntheorem eq_of_perm_of_sorted [is_antisymm \u03b1 r]\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) (s\u2081 : sorted r l\u2081) (s\u2082 : sorted r l\u2082) : l\u2081 = l\u2082 :=\nbegin\n  induction s\u2081 with a l\u2081 h\u2081 s\u2081 IH generalizing l\u2082,\n  { exact p.nil_eq },\n  { have : a \u2208 l\u2082 := p.subset (mem_cons_self _ _),\n    rcases mem_split this with \u27e8u\u2082, v\u2082, rfl\u27e9,\n    have p' := (perm_cons a).1 (p.trans perm_middle),\n    have := IH p' (s\u2082.sublist $ by simp), subst l\u2081,\n    change a::u\u2082 ++ v\u2082 = u\u2082 ++ ([a] ++ v\u2082), rw \u2190 append_assoc, congr,\n    have : \u2200 (x : \u03b1) (h : x \u2208 u\u2082), x = a := \u03bb x m,\n      antisymm ((pairwise_append.1 s\u2082).2.2 _ m a (mem_cons_self _ _))\n        (h\u2081 _ (by simp [m])),\n    rw [(@eq_repeat _ a (length u\u2082 + 1) (a::u\u2082)).2,\n        (@eq_repeat _ a (length u\u2082 + 1) (u\u2082++[a])).2];\n    split; simp [iff_true_intro this, or_comm] }\nend\n\ntheorem sublist_of_subperm_of_sorted [is_antisymm \u03b1 r]\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 <+~ l\u2082) (s\u2081 : l\u2081.sorted r) (s\u2082 : l\u2082.sorted r) : l\u2081 <+ l\u2082 :=\nlet \u27e8_, h, h'\u27e9 := p in by rwa \u2190eq_of_perm_of_sorted h (s\u2082.sublist h') s\u2081\n\n@[simp] theorem sorted_singleton (a : \u03b1) : sorted r [a] := pairwise_singleton _ _\n\nlemma sorted.rel_nth_le_of_lt {l : list \u03b1}\n  (h : l.sorted r) {a b : \u2115} (ha : a < l.length) (hb : b < l.length) (hab : a < b) :\n  r (l.nth_le a ha) (l.nth_le b hb) :=\nlist.pairwise_iff_nth_le.1 h a b hb hab\n\nlemma sorted.rel_nth_le_of_le [is_refl \u03b1 r] {l : list \u03b1}\n  (h : l.sorted r) {a b : \u2115} (ha : a < l.length) (hb : b < l.length) (hab : a \u2264 b) :\n  r (l.nth_le a ha) (l.nth_le b hb) :=\nbegin\n  cases eq_or_lt_of_le hab with H H,\n  { subst H, exact refl _ },\n  { exact h.rel_nth_le_of_lt _ _ H }\nend\n\nlemma sorted.rel_of_mem_take_of_mem_drop {l : list \u03b1} (h : list.sorted r l)\n  {k : \u2115} {x y : \u03b1} (hx : x \u2208 list.take k l) (hy : y \u2208 list.drop k l) :\n  r x y :=\nbegin\n  obtain \u27e8iy, hiy, rfl\u27e9 := nth_le_of_mem hy,\n  obtain \u27e8ix, hix, rfl\u27e9 := nth_le_of_mem hx,\n  rw [nth_le_take', nth_le_drop'],\n  rw length_take at hix,\n  exact h.rel_nth_le_of_lt _ _ (ix.lt_add_right _ _ (lt_min_iff.mp hix).left)\nend\n\nend sorted\n\nsection sort\nvariables {\u03b1 : Type uu} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [decidable_rel r]\nlocal infix ` \u227c ` : 50 := r\n\n/-! ### Insertion sort -/\n\nsection insertion_sort\n\n/-- `ordered_insert a l` inserts `a` into `l` at such that\n  `ordered_insert a l` is sorted if `l` is. -/\n@[simp] def ordered_insert (a : \u03b1) : list \u03b1 \u2192 list \u03b1\n| []       := [a]\n| (b :: l) := if a \u227c b then a :: b :: l else b :: ordered_insert l\n\n/-- `insertion_sort l` returns `l` sorted using the insertion sort algorithm. -/\n@[simp] def insertion_sort : list \u03b1 \u2192 list \u03b1\n| []       := []\n| (b :: l) := ordered_insert r b (insertion_sort l)\n\n@[simp] lemma ordered_insert_nil (a : \u03b1) : [].ordered_insert r a = [a] := rfl\n\ntheorem ordered_insert_length : \u03a0 (L : list \u03b1) (a : \u03b1), (L.ordered_insert r a).length = L.length + 1\n| [] a := rfl\n| (hd :: tl) a := by { dsimp [ordered_insert], split_ifs; simp [ordered_insert_length], }\n\n/-- An alternative definition of `ordered_insert` using `take_while` and `drop_while`. -/\nlemma ordered_insert_eq_take_drop (a : \u03b1) : \u2200 l : list \u03b1,\n  l.ordered_insert r a = l.take_while (\u03bb b, \u00ac(a \u227c b)) ++ (a :: l.drop_while (\u03bb b, \u00ac(a \u227c b)))\n| [] := rfl\n| (b :: l) := by { dsimp only [ordered_insert], split_ifs; simp [take_while, drop_while, *] }\n\nlemma insertion_sort_cons_eq_take_drop (a : \u03b1) (l : list \u03b1) :\n  insertion_sort r (a :: l) = (insertion_sort r l).take_while (\u03bb b, \u00ac(a \u227c b)) ++\n    (a :: (insertion_sort r l).drop_while (\u03bb b, \u00ac(a \u227c b))) :=\nordered_insert_eq_take_drop r a _\n\nsection correctness\nopen perm\n\ntheorem perm_ordered_insert (a) : \u2200 l : list \u03b1, ordered_insert r a l ~ a :: l\n| []       := perm.refl _\n| (b :: l) := by by_cases a \u227c b; [simp [ordered_insert, h],\n  simpa [ordered_insert, h] using\n    ((perm_ordered_insert l).cons _).trans (perm.swap _ _ _)]\n\ntheorem ordered_insert_count [decidable_eq \u03b1] (L : list \u03b1) (a b : \u03b1) :\n  count a (L.ordered_insert r b) = count a L + if (a = b) then 1 else 0 :=\nbegin\n  rw [(L.perm_ordered_insert r b).count_eq, count_cons],\n  split_ifs; simp only [nat.succ_eq_add_one, add_zero],\nend\n\ntheorem perm_insertion_sort : \u2200 l : list \u03b1, insertion_sort r l ~ l\n| []       := perm.nil\n| (b :: l) := by simpa [insertion_sort] using\n  (perm_ordered_insert _ _ _).trans ((perm_insertion_sort l).cons b)\n\nvariable {r}\n\n/-- If `l` is already `list.sorted` with respect to `r`, then `insertion_sort` does not change\nit. -/\nlemma sorted.insertion_sort_eq : \u2200 {l : list \u03b1} (h : sorted r l), insertion_sort r l = l\n| [] _ := rfl\n| [a] _ := rfl\n| (a :: b :: l) h :=\n  begin\n    rw [insertion_sort, sorted.insertion_sort_eq, ordered_insert, if_pos],\n    exacts [rel_of_sorted_cons h _ (or.inl rfl), h.tail]\n  end\n\nsection total_and_transitive\nvariables [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted.ordered_insert (a : \u03b1) : \u2200 l, sorted r l \u2192 sorted r (ordered_insert r a l)\n| []       h := sorted_singleton a\n| (b :: l) h := begin\n  by_cases h' : a \u227c b,\n  { simpa [ordered_insert, h', h] using \u03bb b' bm, trans h' (rel_of_sorted_cons h _ bm) },\n  { suffices : \u2200 (b' : \u03b1), b' \u2208 ordered_insert r a l \u2192 r b b',\n    { simpa [ordered_insert, h', h.of_cons.ordered_insert l] },\n    intros b' bm,\n    cases (show b' = a \u2228 b' \u2208 l, by simpa using\n      (perm_ordered_insert _ _ _).subset bm) with be bm,\n    { subst b', exact (total_of r _ _).resolve_left h' },\n    { exact rel_of_sorted_cons h _ bm } }\nend\n\nvariable (r)\n\n/-- The list `list.insertion_sort r l` is `list.sorted` with respect to `r`. -/\ntheorem sorted_insertion_sort : \u2200 l, sorted r (insertion_sort r l)\n| []       := sorted_nil\n| (a :: l) := (sorted_insertion_sort l).ordered_insert a _\n\nend total_and_transitive\nend correctness\nend insertion_sort\n\n/-! ### Merge sort -/\n\nsection merge_sort\n\n-- TODO(Jeremy): observation: if instead we write (a :: (split l).1, b :: (split l).2), the\n-- equation compiler can't prove the third equation\n\n/-- Split `l` into two lists of approximately equal length.\n\n     split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) -/\n@[simp] def split : list \u03b1 \u2192 list \u03b1 \u00d7 list \u03b1\n| []       := ([], [])\n| (a :: l) := let (l\u2081, l\u2082) := split l in (a :: l\u2082, l\u2081)\n\ntheorem split_cons_of_eq (a : \u03b1) {l l\u2081 l\u2082 : list \u03b1} (h : split l = (l\u2081, l\u2082)) :\n  split (a :: l) = (a :: l\u2082, l\u2081) :=\nby rw [split, h]; refl\n\ntheorem length_split_le : \u2200 {l l\u2081 l\u2082 : list \u03b1},\n  split l = (l\u2081, l\u2082) \u2192 length l\u2081 \u2264 length l \u2227 length l\u2082 \u2264 length l\n| []     ._  ._  rfl := \u27e8nat.le_refl 0, nat.le_refl 0\u27e9\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ h\u2082, nat.le_succ_of_le h\u2081\u27e9\nend\n\ntheorem length_split_lt {a b} {l l\u2081 l\u2082 : list \u03b1} (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  length l\u2081 < length (a::b::l) \u2227 length l\u2082 < length (a::b::l) :=\nbegin\n  cases e : split l with l\u2081' l\u2082',\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l\u2081 l\u2082,\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ (nat.succ_le_succ h\u2081), nat.succ_le_succ (nat.succ_le_succ h\u2082)\u27e9\nend\n\ntheorem perm_split : \u2200 {l l\u2081 l\u2082 : list \u03b1}, split l = (l\u2081, l\u2082) \u2192 l ~ l\u2081 ++ l\u2082\n| []     ._  ._  rfl := perm.refl _\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  exact ((perm_split e).trans perm_append_comm).cons a,\nend\n\n/-- Merge two sorted lists into one in linear time.\n\n     merge [1, 2, 4, 5] [0, 1, 3, 4] = [0, 1, 1, 2, 3, 4, 4, 5] -/\ndef merge : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| []       l'        := l'\n| l        []        := l\n| (a :: l) (b :: l') := if a \u227c b then a :: merge l (b :: l') else b :: merge (a :: l) l'\n\ninclude r\n/-- Implementation of a merge sort algorithm to sort a list. -/\ndef merge_sort : list \u03b1 \u2192 list \u03b1\n| []        := []\n| [a]       := [a]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  exact merge r (merge_sort l\u2081) (merge_sort l\u2082)\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_cons_cons {a b} {l l\u2081 l\u2082 : list \u03b1}\n  (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  merge_sort r (a::b::l) = merge r (merge_sort r l\u2081) (merge_sort r l\u2082) :=\nbegin\n  suffices : \u2200 (L : list \u03b1) h1, @@and.rec\n    (\u03bb a a (_ : length l\u2081 < length l + 1 + 1 \u2227\n      length l\u2082 < length l + 1 + 1), L) h1 h1 = L,\n  { simp [merge_sort, h], apply this },\n  intros, cases h1, refl\nend\n\nsection correctness\n\ntheorem perm_merge : \u2200 (l l' : list \u03b1), merge r l l' ~ l ++ l'\n| []       []        := by simp [merge]\n| []       (b :: l') := by simp [merge]\n| (a :: l) []        := by simp [merge]\n| (a :: l) (b :: l') := begin\n  by_cases a \u227c b,\n  { simpa [merge, h] using perm_merge _ _ },\n  { suffices : b :: merge r (a :: l) l' ~ a :: (l ++ b :: l'), {simpa [merge, h]},\n    exact ((perm_merge _ _).cons _).trans ((swap _ _ _).trans (perm_middle.symm.cons _)) }\nend\n\ntheorem perm_merge_sort : \u2200 l : list \u03b1, merge_sort r l ~ l\n| []        := by simp [merge_sort]\n| [a]       := by simp [merge_sort]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  apply (perm_merge r _ _).trans,\n  exact ((perm_merge_sort l\u2081).append (perm_merge_sort l\u2082)).trans (perm_split e).symm\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\n@[simp] lemma length_merge_sort (l : list \u03b1) : (merge_sort r l).length = l.length :=\n(perm_merge_sort r _).length_eq\n\nsection total_and_transitive\nvariables {r} [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted.merge : \u2200 {l l' : list \u03b1}, sorted r l \u2192 sorted r l' \u2192 sorted r (merge r l l')\n| []       []        h\u2081 h\u2082 := by simp [merge]\n| []       (b :: l') h\u2081 h\u2082 := by simpa [merge] using h\u2082\n| (a :: l) []        h\u2081 h\u2082 := by simpa [merge] using h\u2081\n| (a :: l) (b :: l') h\u2081 h\u2082 := begin\n  by_cases a \u227c b,\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r l (b :: l')), r a b',\n    { simpa [merge, h, h\u2081.of_cons.merge h\u2082] },\n    intros b' bm,\n    rcases (show b' = b \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa [or.left_comm] using\n      (perm_merge _ _ _).subset bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact rel_of_sorted_cons h\u2081 _ bl },\n    { exact trans h (rel_of_sorted_cons h\u2082 _ bl') } },\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r (a :: l) l'), r b b',\n    { simpa [merge, h, h\u2081.merge h\u2082.of_cons] },\n    intros b' bm,\n    have ba : b \u227c a := (total_of r _ _).resolve_left h,\n    rcases (show b' = a \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa using\n      (perm_merge _ _ _).subset bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact trans ba (rel_of_sorted_cons h\u2081 _ bl) },\n    { exact rel_of_sorted_cons h\u2082 _ bl' } }\nend\n\nvariable (r)\n\ntheorem sorted_merge_sort : \u2200 l : list \u03b1, sorted r (merge_sort r l)\n| []        := by simp [merge_sort]\n| [a]       := by simp [merge_sort]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  exact (sorted_merge_sort l\u2081).merge (sorted_merge_sort l\u2082)\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_eq_self [is_antisymm \u03b1 r] {l : list \u03b1} : sorted r l \u2192 merge_sort r l = l :=\neq_of_perm_of_sorted (perm_merge_sort _ _) (sorted_merge_sort _ _)\n\ntheorem merge_sort_eq_insertion_sort [is_antisymm \u03b1 r] (l : list \u03b1) :\n  merge_sort r l = insertion_sort r l :=\neq_of_perm_of_sorted ((perm_merge_sort r l).trans (perm_insertion_sort r l).symm)\n  (sorted_merge_sort r l) (sorted_insertion_sort r l)\n\nend total_and_transitive\nend correctness\n\n@[simp] theorem merge_sort_nil : [].merge_sort r = [] :=\nby rw list.merge_sort\n\n@[simp] theorem merge_sort_singleton (a : \u03b1) : [a].merge_sort r = [a] :=\nby rw list.merge_sort\n\nend merge_sort\nend sort\n\n/- try them out! -/\n\n--#eval insertion_sort (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\n--#eval merge_sort     (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\nend list\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/list/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7308222043143}}
{"text": "/-\nCopyright (c) 2019 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann, Kyle Miller, Mario Carneiro\n-/\nimport data.nat.gcd\nimport logic.function.iterate\nimport data.finset.nat_antidiagonal\nimport algebra.big_operators.basic\nimport tactic.ring\nimport tactic.zify\n\n/-!\n# The Fibonacci Sequence\n\n## Summary\n\nDefinition of the Fibonacci sequence `F\u2080 = 0, F\u2081 = 1, F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081`.\n\n## Main Definitions\n\n- `nat.fib` returns the stream of Fibonacci numbers.\n\n## Main Statements\n\n- `nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.`.\n- `nat.fib_gcd`: `fib n` is a strong divisibility sequence.\n- `nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `nat.choose` along an antidiagonal.\n- `nat.fib_succ_eq_succ_sum`: shows that `F\u2080 + F\u2081 + \u22ef + F\u2099 = F\u2099\u208a\u2082 - 1`.\n- `nat.fib_two_mul` and `nat.fib_two_mul_add_one` are the basis for an efficient algorithm to\n  compute `fib` (see `nat.fast_fib`). There are `bit0`/`bit1` variants of these can be used to\n  simplify `fib` expressions: `simp only [nat.fib_bit0, nat.fib_bit1, nat.fib_bit0_succ,\n  nat.fib_bit1_succ, nat.fib_one, nat.fib_two]`.\n\n## Implementation Notes\n\nFor efficiency purposes, the sequence is defined using `stream.iterate`.\n\n## Tags\n\nfib, fibonacci\n-/\n\nopen_locale big_operators\n\nnamespace nat\n\n/--\nImplementation of the fibonacci sequence satisfying\n`fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`.\n\n*Note:* We use a stream iterator for better performance when compared to the naive recursive\nimplementation.\n-/\n@[pp_nodot]\ndef fib (n : \u2115) : \u2115 := ((\u03bb p : \u2115 \u00d7 \u2115, (p.snd, p.fst + p.snd))^[n] (0, 1)).fst\n\n@[simp] lemma fib_zero : fib 0 = 0 := rfl\n@[simp] lemma fib_one : fib 1 = 1 := rfl\n@[simp] lemma fib_two : fib 2 = 1 := rfl\n\n/-- Shows that `fib` indeed satisfies the Fibonacci recurrence `F\u2099\u208a\u2082 = F\u2099 + F\u2099\u208a\u2081.` -/\nlemma fib_add_two {n : \u2115} : fib (n + 2) = fib n + fib (n + 1) :=\nby simp only [fib, function.iterate_succ']\n\nlemma fib_le_fib_succ {n : \u2115} : fib n \u2264 fib (n + 1) := by { cases n; simp [fib_add_two] }\n\n@[mono] lemma fib_mono : monotone fib :=\nmonotone_nat_of_le_succ $ \u03bb _, fib_le_fib_succ\n\nlemma fib_pos {n : \u2115} (n_pos : 0 < n) : 0 < fib n :=\ncalc 0 < fib 1 : dec_trivial\n   ... \u2264 fib n : fib_mono n_pos\n\nlemma fib_add_two_sub_fib_add_one {n : \u2115} : fib (n + 2) - fib (n + 1) = fib n :=\nby rw [fib_add_two, add_tsub_cancel_right]\n\nlemma fib_lt_fib_succ {n : \u2115} (hn : 2 \u2264 n) : fib n < fib (n + 1) :=\nbegin\n  rcases le_iff_exists_add.1 hn with \u27e8n, rfl\u27e9,\n  rw [\u2190 tsub_pos_iff_lt, add_comm 2, fib_add_two_sub_fib_add_one],\n  apply fib_pos (succ_pos n),\nend\n\n/-- `fib (n + 2)` is strictly monotone. -/\nlemma fib_add_two_strict_mono : strict_mono (\u03bb n, fib (n + 2)) :=\nbegin\n  refine strict_mono_nat_of_lt_succ (\u03bb n, _),\n  rw add_right_comm,\n  exact fib_lt_fib_succ (self_le_add_left _ _)\nend\n\nlemma le_fib_self {n : \u2115} (five_le_n : 5 \u2264 n) : n \u2264 fib n :=\nbegin\n  induction five_le_n with n five_le_n IH,\n  { -- 5 \u2264 fib 5\n    refl },\n  { -- n + 1 \u2264 fib (n + 1) for 5 \u2264 n\n    rw succ_le_iff,\n    calc n \u2264 fib n       : IH\n       ... < fib (n + 1) : fib_lt_fib_succ (le_trans dec_trivial five_le_n) }\nend\n\n/-- Subsequent Fibonacci numbers are coprime,\n  see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/\nlemma fib_coprime_fib_succ (n : \u2115) : nat.coprime (fib n) (fib (n + 1)) :=\nbegin\n  induction n with n ih,\n  { simp },\n  { rw [fib_add_two, coprime_add_self_right],\n    exact ih.symm }\nend\n\n/-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/\nlemma fib_add (m n : \u2115) :\n  fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) :=\nbegin\n  induction n with n ih generalizing m,\n  { simp },\n  { intros,\n    specialize ih (m + 1),\n    rw [add_assoc m 1 n, add_comm 1 n] at ih,\n    simp only [fib_add_two, ih],\n    ring, }\nend\n\nlemma fib_two_mul (n : \u2115) : fib (2 * n) = fib n * (2 * fib (n + 1) - fib n) :=\nbegin\n  cases n,\n  { simp },\n  { rw [nat.succ_eq_add_one, two_mul, \u2190add_assoc, fib_add, fib_add_two, two_mul],\n    simp only [\u2190 add_assoc, add_tsub_cancel_right],\n    ring, },\nend\n\nlemma fib_two_mul_add_one (n : \u2115) : fib (2 * n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 :=\nby { rw [two_mul, fib_add], ring }\n\nlemma fib_bit0 (n : \u2115) : fib (bit0 n) = fib n * (2 * fib (n + 1) - fib n) :=\nby rw [bit0_eq_two_mul, fib_two_mul]\n\nlemma fib_bit1 (n : \u2115) : fib (bit1 n) = fib (n + 1) ^ 2 + fib n ^ 2 :=\nby rw [nat.bit1_eq_succ_bit0, bit0_eq_two_mul, fib_two_mul_add_one]\n\nlemma fib_bit0_succ (n : \u2115) : fib (bit0 n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 := fib_bit1 n\n\nlemma fib_bit1_succ (n : \u2115) : fib (bit1 n + 1) = fib (n + 1) * (2 * fib n + fib (n + 1)) :=\nbegin\n  rw [nat.bit1_eq_succ_bit0, fib_add_two, fib_bit0, fib_bit0_succ],\n  have : fib n \u2264 2 * fib (n + 1),\n  { rw two_mul,\n    exact le_add_left fib_le_fib_succ, },\n  zify,\n  ring,\nend\n\n/-- Computes `(nat.fib n, nat.fib (n + 1))` using the binary representation of `n`.\nSupports `nat.fast_fib`. -/\ndef fast_fib_aux : \u2115 \u2192 \u2115 \u00d7 \u2115 :=\nnat.binary_rec (fib 0, fib 1) (\u03bb b n p,\n  if b\n  then (p.2^2 + p.1^2, p.2 * (2 * p.1 + p.2))\n  else (p.1 * (2 * p.2 - p.1), p.2^2 + p.1^2))\n\n/-- Computes `nat.fib n` using the binary representation of `n`.\nProved to be equal to `nat.fib` in `nat.fast_fib_eq`. -/\ndef fast_fib (n : \u2115) : \u2115 := (fast_fib_aux n).1\n\nlemma fast_fib_aux_bit_ff (n : \u2115) :\n  fast_fib_aux (bit ff n) = let p := fast_fib_aux n in (p.1 * (2 * p.2 - p.1), p.2^2 + p.1^2) :=\nbegin\n  rw [fast_fib_aux, binary_rec_eq],\n  { refl },\n  { simp },\nend\n\nlemma fast_fib_aux_bit_tt (n : \u2115) :\n  fast_fib_aux (bit tt n) = let p := fast_fib_aux n in (p.2^2 + p.1^2, p.2 * (2 * p.1 + p.2)) :=\nbegin\n  rw [fast_fib_aux, binary_rec_eq],\n  { refl },\n  { simp },\nend\n\nlemma fast_fib_aux_eq (n : \u2115) :\n  fast_fib_aux n = (fib n, fib (n + 1)) :=\nbegin\n  apply nat.binary_rec _ (\u03bb b n' ih, _) n,\n  { simp [fast_fib_aux] },\n  { cases b; simp only [fast_fib_aux_bit_ff, fast_fib_aux_bit_tt,\n      congr_arg prod.fst ih, congr_arg prod.snd ih, prod.mk.inj_iff]; split;\n    simp [bit, fib_bit0, fib_bit1, fib_bit0_succ, fib_bit1_succ], },\nend\n\nlemma fast_fib_eq (n : \u2115) : fast_fib n = fib n :=\nby rw [fast_fib, fast_fib_aux_eq]\n\nlemma gcd_fib_add_self (m n : \u2115) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) :=\nbegin\n  cases nat.eq_zero_or_pos n,\n  { rw h, simp },\n  replace h := nat.succ_pred_eq_of_pos h, rw [\u2190 h, succ_eq_add_one],\n  calc gcd (fib m) (fib (n.pred + 1 + m))\n        = gcd (fib m) (fib (n.pred) * (fib m) + fib (n.pred + 1) * fib (m + 1)) :\n    by { rw \u2190 fib_add n.pred _, ring_nf }\n    ... = gcd (fib m) (fib (n.pred + 1) * fib (m + 1)) :\n    by rw [add_comm, gcd_add_mul_right_right (fib m) _ (fib (n.pred))]\n    ... = gcd (fib m) (fib (n.pred + 1)) :\n    coprime.gcd_mul_right_cancel_right\n      (fib (n.pred + 1)) (coprime.symm (fib_coprime_fib_succ m))\nend\n\nlemma gcd_fib_add_mul_self (m n : \u2115) : \u2200 k, gcd (fib m) (fib (n + k * m)) = gcd (fib m) (fib n)\n| 0     := by simp\n| (k+1) := by rw [\u2190 gcd_fib_add_mul_self k, add_mul, \u2190 add_assoc, one_mul, gcd_fib_add_self _ _]\n\n/-- `fib n` is a strong divisibility sequence,\n  see https://proofwiki.org/wiki/GCD_of_Fibonacci_Numbers -/\n\n\nlemma fib_dvd (m n : \u2115) (h : m \u2223 n) : fib m \u2223 fib n :=\nby rwa [gcd_eq_left_iff_dvd, \u2190 fib_gcd, gcd_eq_left_iff_dvd.mp]\n\nlemma fib_succ_eq_sum_choose :\n  \u2200 (n : \u2115), fib (n + 1) = \u2211 p in finset.nat.antidiagonal n, choose p.1 p.2 :=\ntwo_step_induction rfl rfl (\u03bb n h1 h2, by\n{ rw [fib_add_two, h1, h2, finset.nat.antidiagonal_succ_succ', finset.nat.antidiagonal_succ'],\n  simp [choose_succ_succ, finset.sum_add_distrib, add_left_comm] })\n\nlemma fib_succ_eq_succ_sum (n : \u2115):\n  fib (n + 1) = (\u2211 k in finset.range n, fib k) + 1 :=\nbegin\n  induction n with n ih,\n  { simp },\n  { calc fib (n + 2) = fib n + fib (n + 1)                        : fib_add_two\n                 ... = fib n + (\u2211 k in finset.range n, fib k) + 1 : by rw [ih, add_assoc]\n                 ... = (\u2211 k in finset.range (n + 1), fib k) + 1   : by simp [finset.range_add_one] }\nend\nend nat\n\nnamespace norm_num\nopen tactic nat\n\n/-! ### `norm_num` plugin for `fib`\n\nThe `norm_num` plugin uses a strategy parallel to that of `nat.fast_fib`, but it instead\nproduces proofs of what `nat.fib` evaluates to.\n-/\n\n/-- Auxiliary definition for `prove_fib` plugin. -/\ndef is_fib_aux (n a b : \u2115) := fib n = a \u2227 fib (n + 1) = b\n\nlemma is_fib_aux_one : is_fib_aux 1 1 1 := \u27e8fib_one, fib_two\u27e9\n\nlemma is_fib_aux_bit0 {n a b c a2 b2 a' b' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a + c = bit0 b) (h2 : a * c = a')\n  (h3 : a * a = a2) (h4 : b * b = b2) (h5 : a2 + b2 = b') :\n  is_fib_aux (bit0 n) a' b' :=\n\u27e8by rw [fib_bit0, H.1, H.2, \u2190 bit0_eq_two_mul,\n  show bit0 b-a=c, by rw [\u2190 h1, nat.add_sub_cancel_left], h2],\n by rw [fib_bit0_succ, H.1, H.2, pow_two, pow_two, h3, h4, add_comm, h5]\u27e9\n\nlemma is_fib_aux_bit1 {n a b c a2 b2 a' b' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a * a = a2) (h2 : b * b = b2) (h3 : a2 + b2 = a')\n  (h4 : bit0 a + b = c) (h5 : b * c = b') :\n  is_fib_aux (bit1 n) a' b' :=\n\u27e8by rw [fib_bit1, H.1, H.2, pow_two, pow_two, h1, h2, add_comm, h3],\n by rw [fib_bit1_succ, H.1, H.2, \u2190 bit0_eq_two_mul, h4, h5]\u27e9\n\nlemma is_fib_aux_bit0_done {n a b c a' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a + c = bit0 b) (h2 : a * c = a') : fib (bit0 n) = a' :=\n(is_fib_aux_bit0 H h1 h2 rfl rfl rfl).1\n\nlemma is_fib_aux_bit1_done {n a b a2 b2 a' : \u2115} (H : is_fib_aux n a b)\n  (h1 : a * a = a2) (h2 : b * b = b2) (h3 : a2 + b2 = a') : fib (bit1 n) = a' :=\n(is_fib_aux_bit1 H h1 h2 h3 rfl rfl).1\n\n/-- `prove_fib_aux ic n` returns `(ic', a, b, \u22a2 is_fib_aux n a b)`, where `n` is a numeral. -/\nmeta def prove_fib_aux (ic : instance_cache) :\n  expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr \u00d7 expr)\n| e :=\n  match match_numeral e with\n  | match_numeral_result.one := pure (ic, `(1:\u2115), `(1:\u2115), `(is_fib_aux_one))\n  | match_numeral_result.bit0 e := do\n    (ic, a, b, H) \u2190 prove_fib_aux e,\n    na \u2190 a.to_nat, nb \u2190 b.to_nat,\n    (ic, c) \u2190 ic.of_nat (2*nb - na),\n    (ic, h1) \u2190 prove_add_nat ic a c (`(bit0:\u2115\u2192\u2115).mk_app [b]),\n    (ic, a', h2) \u2190 prove_mul_nat ic a c,\n    (ic, a2, h3) \u2190 prove_mul_nat ic a a,\n    (ic, b2, h4) \u2190 prove_mul_nat ic b b,\n    (ic, b', h5) \u2190 prove_add_nat' ic a2 b2,\n    pure (ic, a', b', `(@is_fib_aux_bit0).mk_app\n      [e, a, b, c, a2, b2, a', b', H, h1, h2, h3, h4, h5])\n  | match_numeral_result.bit1 e := do\n    (ic, a, b, H) \u2190 prove_fib_aux e,\n    na \u2190 a.to_nat, nb \u2190 b.to_nat,\n    (ic, c) \u2190 ic.of_nat (2*na + nb),\n    (ic, a2, h1) \u2190 prove_mul_nat ic a a,\n    (ic, b2, h2) \u2190 prove_mul_nat ic b b,\n    (ic, a', h3) \u2190 prove_add_nat' ic a2 b2,\n    (ic, h4) \u2190 prove_add_nat ic (`(bit0:\u2115\u2192\u2115).mk_app [a]) b c,\n    (ic, b', h5) \u2190 prove_mul_nat ic b c,\n    pure (ic, a', b', `(@is_fib_aux_bit1).mk_app\n      [e, a, b, c, a2, b2, a', b', H, h1, h2, h3, h4, h5])\n  | _ := failed\n  end\n\n/-- A `norm_num` plugin for `fib n` when `n` is a numeral.\nUses the binary representation of `n` like `nat.fast_fib`. -/\nmeta def prove_fib (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\nmatch match_numeral e with\n| match_numeral_result.zero := pure (ic, `(0:\u2115), `(fib_zero))\n| match_numeral_result.one := pure (ic, `(1:\u2115), `(fib_one))\n| match_numeral_result.bit0 e := do\n  (ic, a, b, H) \u2190 prove_fib_aux ic e,\n  na \u2190 a.to_nat, nb \u2190 b.to_nat,\n  (ic, c) \u2190 ic.of_nat (2*nb - na),\n  (ic, h1) \u2190 prove_add_nat ic a c (`(bit0:\u2115\u2192\u2115).mk_app [b]),\n  (ic, a', h2) \u2190 prove_mul_nat ic a c,\n  pure (ic, a', `(@is_fib_aux_bit0_done).mk_app [e, a, b, c, a', H, h1, h2])\n| match_numeral_result.bit1 e := do\n  (ic, a, b, H) \u2190 prove_fib_aux ic e,\n  (ic, a2, h1) \u2190 prove_mul_nat ic a a,\n  (ic, b2, h2) \u2190 prove_mul_nat ic b b,\n  (ic, a', h3) \u2190 prove_add_nat' ic a2 b2,\n  pure (ic, a', `(@is_fib_aux_bit1_done).mk_app [e, a, b, a2, b2, a', H, h1, h2, h3])\n| _ := failed\nend\n\n/-- A `norm_num` plugin for `fib n` when `n` is a numeral.\nUses the binary representation of `n` like `nat.fast_fib`. -/\n@[norm_num] meta def eval_fib : expr \u2192 tactic (expr \u00d7 expr)\n| `(fib %%en) := do\n    n \u2190 en.to_nat,\n    match n with\n    | 0 := pure (`(0:\u2115), `(fib_zero))\n    | 1 := pure (`(1:\u2115), `(fib_one))\n    | 2 := pure (`(1:\u2115), `(fib_two))\n    | _ := do\n      c \u2190 mk_instance_cache `(\u2115),\n      prod.snd <$> prove_fib c en\n    end\n| _ := failed\n\nend norm_num\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/nat/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.730813466333541}}
{"text": "/-\nDefines an additional theorem over orders.\n-/\n\n/-- Show that for linear orders le is equivalent to not_gt.\n\nN.B. This is the inverse of lt_iff_not_ge.\n-/\nprotected lemma le_iff_not_gt  {\u03b1 : Type} [linear_order \u03b1] (x y : \u03b1)\n: (x \u2264 y) \u2194 \u00ac(x > y) :=\n  iff.intro not_lt_of_ge le_of_not_gt\n", "meta": {"author": "GaloisInc", "repo": "lean-protocol-support", "sha": "cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda", "save_path": "github-repos/lean/GaloisInc-lean-protocol-support", "path": "github-repos/lean/GaloisInc-lean-protocol-support/lean-protocol-support-cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda/galois/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7308134584846615}}
{"text": "/-\nCopyright (c) 2022 Jon Eugster. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jon Eugster\n\n! This file was ported from Lean 3 source module algebra.char_p.local_ring\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.CharP.Basic\nimport Mathbin.RingTheory.Ideal.LocalRing\nimport Mathbin.Algebra.IsPrimePow\nimport Mathbin.Data.Nat.Factorization.Basic\n\n/-!\n# Characteristics of local rings\n\n## Main result\n\n- `char_p_zero_or_prime_power`: In a commutative local ring the characteristics is either\n  zero or a prime power.\n\n-/\n\n\n/-- In a local ring the characteristics is either zero or a prime power. -/\ntheorem charP_zero_or_prime_power (R : Type _) [CommRing R] [LocalRing R] (q : \u2115)\n    [char_R_q : CharP R q] : q = 0 \u2228 IsPrimePow q :=\n  by\n  -- Assume `q := char(R)` is not zero.\n  apply or_iff_not_imp_left.2\n  intro q_pos\n  let K := LocalRing.ResidueField R\n  haveI RM_char := ringChar.charP K\n  let r := ringChar K\n  let n := q.factorization r\n  -- `r := char(R/m)` is either prime or zero:\n  cases' CharP.char_is_prime_or_zero K r with r_prime r_zero\n  \u00b7 let a := q / r ^ n\n    -- If `r` is prime, we can write it as `r = a * q^n` ...\n    have q_eq_a_mul_rn : q = r ^ n * a := by rw [Nat.mul_div_cancel' (Nat.ord_proj_dvd q r)]\n    have r_ne_dvd_a := Nat.not_dvd_ord_compl r_prime q_pos\n    have rn_dvd_q : r ^ n \u2223 q := \u27e8a, q_eq_a_mul_rn\u27e9\n    rw [mul_comm] at q_eq_a_mul_rn\n    have a_dvd_q : a \u2223 q := \u27e8r ^ n, q_eq_a_mul_rn\u27e9\n    -- ... where `a` is a unit.\n    have a_unit : IsUnit (a : R) := by\n      by_contra g\n      rw [\u2190 mem_nonunits_iff] at g\n      rw [\u2190 LocalRing.mem_maximalIdeal] at g\n      have a_cast_zero := Ideal.Quotient.eq_zero_iff_mem.2 g\n      rw [map_natCast] at a_cast_zero\n      have r_dvd_a := (ringChar.spec K a).1 a_cast_zero\n      exact absurd r_dvd_a r_ne_dvd_a\n    -- Let `b` be the inverse of `a`.\n    cases' a_unit.exists_left_inv with a_inv h_inv_mul_a\n    have rn_cast_zero : \u2191(r ^ n) = (0 : R) :=\n      by\n      rw [Nat.cast_pow, \u2190 @mul_one R _ (r ^ n), mul_comm, \u2190\n        Classical.choose_spec a_unit.exists_left_inv, mul_assoc, \u2190 Nat.cast_pow, \u2190 Nat.cast_mul, \u2190\n        q_eq_a_mul_rn, CharP.cast_eq_zero R q]\n      simp\n    have q_eq_rn := Nat.dvd_antisymm ((CharP.cast_eq_zero_iff R q (r ^ n)).mp rn_cast_zero) rn_dvd_q\n    have n_pos : n \u2260 0 := fun n_zero =>\n      absurd (by simpa [n_zero] using q_eq_rn) (CharP.char_ne_one R q)\n    -- Definition of prime power: `\u2203 r n, prime r \u2227 0 < n \u2227 r ^ n = q`.\n    exact \u27e8r, \u27e8n, \u27e8r_prime.prime, \u27e8pos_iff_ne_zero.mpr n_pos, q_eq_rn.symm\u27e9\u27e9\u27e9\u27e9\n  \u00b7 haveI K_char_p_0 := ringChar.of_eq r_zero\n    haveI K_char_zero : CharZero K := CharP.charP_to_charZero K\n    haveI R_char_zero := RingHom.charZero (LocalRing.residue R)\n    -- Finally, `r = 0` would lead to a contradiction:\n    have q_zero := CharP.eq R char_R_q (CharP.ofCharZero R)\n    exact absurd q_zero q_pos\n#align char_p_zero_or_prime_power charP_zero_or_prime_power\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/CharP/LocalRing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7307962561332778}}
{"text": "/-\nCopyright (c) 2022 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n-/\nimport set_theory.cardinal.ordinal\nimport ring_theory.artinian\n\n/-!\n# Cardinality of localizations\n\nIn this file, we establish the cardinality of localizations. In most cases, a localization has\ncardinality equal to the base ring. If there are zero-divisors, however, this is no longer true -\nfor example, `zmod 6` localized at `{2, 4}` is equal to `zmod 3`, and if you have zero in your\nsubmonoid, then your localization is trivial (see `is_localization.unique_of_zero_mem`).\n\n## Main statements\n\n* `is_localization.card_le`: A localization has cardinality no larger than the base ring.\n* `is_localization.card`: If you don't localize at zero-divisors, the localization of a ring has\n  cardinality equal to its base ring,\n\n-/\n\nopen_locale cardinal non_zero_divisors\n\nuniverses u v\n\nnamespace is_localization\n\nvariables {R : Type u} [comm_ring R] (S : submonoid R) {L : Type u} [comm_ring L]\n          [algebra R L] [is_localization S L]\ninclude S\n\n/-- A localization always has cardinality less than or equal to the base ring. -/\nlemma card_le : #L \u2264 #R :=\nbegin\n  classical,\n  casesI fintype_or_infinite R,\n  { exact cardinal.mk_le_of_surjective (is_artinian_ring.localization_surjective S _) },\n  erw [\u2190cardinal.mul_eq_self $ cardinal.aleph_0_le_mk R],\n  set f : R \u00d7 R \u2192 L := \u03bb aa, is_localization.mk' _ aa.1 (if h : aa.2 \u2208 S then \u27e8aa.2, h\u27e9 else 1),\n  refine @cardinal.mk_le_of_surjective _ _ f (\u03bb a, _),\n  obtain \u27e8x, y, h\u27e9 := is_localization.mk'_surjective S a,\n  use (x, y),\n  dsimp [f],\n  rwa [dif_pos $ show \u2191y \u2208 S, from y.2, set_like.eta]\nend\n\nvariables (L)\n\n/-- If you do not localize at any zero-divisors, localization preserves cardinality. -/\nlemma card (hS : S \u2264 R\u2070) : #R = #L :=\n(cardinal.mk_le_of_injective (is_localization.injective L hS)).antisymm (card_le S)\n\nend is_localization\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/localization/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7307779419075415}}
{"text": "import game.sets.sets_level03 -- hide\n\nnamespace xena -- hide\n\nopen_locale classical -- hide\n\nvariable X : Type --hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 4\n-/\n\n/- Axiom : ext_iff :\nA = B \u2194 \u2200 x : X, x \u2208 A \u2194 x \u2208 B\n-/\n\n/-\n\nTo prove that two sets are equal, one needs to use the axiom\nof extensionality: two sets are equal if and only if they have\nthe same elements.\n\nIn Lean's maths library this axiom is called `ext_iff`.\n\n```\nlemma ext_diff : A = B \u2194 \u2200 x : X, x \u2208 A \u2194 x \u2208 B\n```\n-/\n\n/- Hint: A word on coding style\n\nAfter a `split` statement, one goal turns into two. A good programming style\nwould be to use `{}` brackets to work on each goal individually, like this:\n```\nbegin\n  split,\n  { insert,\n    proof of,\n    first goal\n  },\n  { insert,\n    proof of,\n    second goal\n  }\nend\n```\n\nThis way you only ever have one goal to work on, and your code becomes\neasier to read. After `split` you might want to write \n```\n{ sorry},\n{ sorry}\n```\nso that your code has no errors while you're working on it.\n-/\n\n\n/- Hint : Stuck?\nTo prove the theorem below, remember that you can use `split` to \nchange the goal into two goals, corresponding to the left-right and\nright-left implication, respectively. For the first goal, after\n`intro h,` the equality of the two sets can be manipulated\nusing `rw ext_iff`.\n-/\n\n/- Hint: rewrite failures and the `simp_rw` tactic\n`rw` doesn't work \"under a binder\". In other words, if your goal is\n`\u22a2\t\u2200 (x : X), x \u2208 B \u2194 x \u2208 A \u222a B` then `rw mem_union_iff` won't work!\nIt's the `\u2200` which is blocking it. Either do `intro x` (and then\nthe `rw` will work), or use a more powerful rewrite tactic\ncalled `simp_rw`, which will work \n\n-/\n\n/- Lemma\nIf $A$ and $B$ are sets of any type $X$, then\n$$ A \\subseteq B \\iff A \\cup B = B.$$\n-/\ntheorem subset_iff_union_eq (A : set X) (B : set X) : A \u2286 B \u2194 B = A \u222a B := \nbegin\n  rw subset_iff,\n  split,\n  { intro h,\n    rw ext_iff,\n     -- can't rewrite under a binder\n    simp_rw mem_union_iff,\n    intro x,\n    specialize h x, -- or replace h := h x,\n    tauto! },\n  { intro h,\n    intros x hA,\n    rw h,\n    rw mem_union_iff,\n    tauto!\n  }\n\n\n\nend\n\n--begin hide\n-- theorem subset_iff_union_eq' (A : set X) (B : set X) : A \u2286 B \u2194 B = A \u222a B := \n-- begin\n--   rw subset_iff,\n--   rw ext_iff,\n--   apply forall_congr,\n--   intro x,\n--   rw mem_union_iff,\n--   tauto!,\n-- end\n--end hide\n\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sets/sets_level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7307278346774406}}
{"text": "/-\nThis file defines rational segments \ud835\udd4a,\nhere defined as a subtype of \u211a \u00d7 \u211a\nAlso defines relations on \ud835\udd4a, like \u2264, \u2291 and \u2248\n-/\n\nimport data.rat\nimport algebra.order\n\n\n/--\nRational segments \ud835\udd4a  \nEach s in \ud835\udd4a is a pair of rational numbers (p, q) such that p \u2264 q  \nRational segments can be interpreted as intervals, [p, q], with rational end points\n-/\ndef segment := {s : \u211a \u00d7 \u211a // s.fst \u2264 s.snd}\n\nnotation `\ud835\udd4a` := segment\n\nnamespace segment\n\ndef fst (s : \ud835\udd4a) : \u211a := (subtype.val s).fst\n\ndef snd (s : \ud835\udd4a) : \u211a := (subtype.val s).snd\n\ndef proper (s : \ud835\udd4a) : Prop := s.fst < s.snd\n\ndef contained (s t : \ud835\udd4a) : Prop := t.fst \u2264 s.fst \u2227 s.snd \u2264 t.snd\n\ninfix `\u2291`:50 := contained\n\ndef proper_contained (s t : \ud835\udd4a) : Prop := t.fst < s.fst \u2227 s.snd < t.snd\n\ninfix `\u228f`:50 := proper_contained\n\ndef lt (s t : \ud835\udd4a) : Prop := s.snd < t.fst\n\ninfix `<` := lt\n\ndef le (s t : \ud835\udd4a) : Prop := s.fst \u2264 t.snd\n\ninfix `\u2264` := le\n\ndef inclusion (q : \u211a) : \ud835\udd4a :=\n    subtype.mk (q, q)\n    begin\n        refl,\n    end\n\n@[instance] def has_zero : has_zero \ud835\udd4a := { zero := inclusion 0 }\n\ndef two_sided_inclusion (q : \u211a) (hq : q > 0) : \ud835\udd4a :=\n    subtype.mk (-q, q)\n    begin\n        simp,\n        rwa [neg_le_iff_add_nonneg, \u2190 two_mul],\n        apply rat.mul_nonneg,\n        {-- need to prove: 0 \u2264 2\n            exact rat.le_def'.mpr trivial\n        },\n        {-- need to prove: 0 \u2264 q\n            apply le_of_lt,\n            rw \u2190 gt_from_lt,\n            exact hq,\n        }\n    end\n\nlemma two_sided_inclusion_contained {q\u2081 q\u2082 : \u211a} {hq\u2081 : q\u2081 > 0} {hq\u2082 : q\u2082 > 0} (h : q\u2081 \u2264 q\u2082) :\n    two_sided_inclusion q\u2081 hq\u2081 \u2291 two_sided_inclusion q\u2082 hq\u2082 :=\nbegin\n    simp [two_sided_inclusion, contained, fst, snd, h],\nend\n\n@[trans] theorem contained_trans (s t v : \ud835\udd4a) (h\u2081 : s \u2291 t) (h\u2082 : t \u2291 v) : s \u2291 v :=\nbegin\n    split,\n    {-- need to prove: fst v \u2264 fst s\n        transitivity t.fst,\n        exact h\u2082.elim_left,\n        exact h\u2081.elim_left,\n    },\n    {-- need to prove: snd s \u2264 snd v\n        transitivity t.snd,\n        exact h\u2081.elim_right,\n        exact h\u2082.elim_right,\n    }\nend\n\n@[trans] theorem proper_contained_trans (s t v : \ud835\udd4a) (h\u2081 : s \u228f t) (h\u2082 : t \u228f v) : s \u228f v :=\nbegin\n    split,\n    {-- need to prove: fst v < fst s\n        transitivity t.fst,\n        exact h\u2082.elim_left,\n        exact h\u2081.elim_left,\n    },\n    {-- need to prove: snd s < snd v\n        transitivity t.snd,\n        exact h\u2081.elim_right,\n        exact h\u2082.elim_right,\n    }\nend\n\n@[refl] theorem contained_refl (s : \ud835\udd4a) : s \u2291 s :=\nbegin\n    split,\n    refl,\n    refl,\nend\n\n-- This lemma immediately follows from a similar statement about \u211a\nlemma le_iff_not_lt (s t : \ud835\udd4a) : s \u2264 t \u2194 \u00ac t < s :=\nbegin\n    split,\n    {-- need to prove: s \u2264 t \u2192 \u00ac t < s\n        intro h,\n        apply not_lt_of_le,\n        exact h,\n    },\n    {-- need to prove: \u00ac t < s \u2192 s \u2264 t\n        intro h,\n        apply le_of_not_lt,\n        exact h,\n    }\nend\n\nlemma lt_iff_not_le (s t : \ud835\udd4a) : s < t \u2194 \u00ac t \u2264 s :=\nbegin\n    split,\n    {-- need to prove: s < t \u2192 \u00ac t \u2264 s\n        intro h,\n        apply not_le_of_lt,\n        exact h,\n    },\n    {-- need to prove: \u00ac t \u2264 s \u2192 s < t\n        intro h,\n        apply lt_of_not_ge,\n        rw ge_iff_le,\n        exact h,\n    }\nend\n\n@[trans] theorem lt_trans (s t v : \ud835\udd4a) (h\u2081 : s < t) (h\u2082 : t < v) : s < v :=\nbegin\n    have ht := subtype.property t,\n    have h\u2083 : s.snd < t.snd := lt_of_lt_of_le h\u2081 ht,\n    rw segment.lt,\n    transitivity t.snd,\n    exact h\u2083,\n    exact h\u2082,\nend\n\n@[refl] theorem le_refl (s : \ud835\udd4a) : s \u2264 s :=\nbegin\n    exact (subtype.property s),\nend\n\n/--\nWe say that two rational segments 'touch' if they partially cover eachother\n-/\ndef touches (s t : \ud835\udd4a) : Prop := s \u2264 t \u2227 t \u2264 s\n\ninfix `\u2248` := touches\n\n@[refl] theorem touches_refl (s : \ud835\udd4a) : s \u2248 s :=\nbegin\n    split,\n    refl,\n    refl,\nend \n\n@[symm] theorem touches_symm (s t : \ud835\udd4a) : s \u2248 t \u2194 t \u2248 s :=\nbegin\n    exact and.comm,\nend\n\ndef add (s t : \ud835\udd4a) : \ud835\udd4a := subtype.mk (s.fst + t.fst, s.snd + t.snd)\n    begin\n        apply add_le_add,\n        exact subtype.property s,\n        exact subtype.property t,\n    end\n\ntheorem add_assoc (s t v : \ud835\udd4a) : add (add s t) v = add s (add t v) :=\nbegin\n    repeat {rw add},\n    rw subtype.mk_eq_mk,\n    rw prod.mk.inj_iff,\n    split,\n    {\n        repeat {rw fst},\n        rw add_assoc,\n        rw add_left_inj,\n        refl,\n    },\n    {\n        repeat {rw snd},\n        rw add_assoc,\n        rw add_left_inj,\n        refl,\n    }\nend\n\nlemma fst_add_comm {s t : \ud835\udd4a} : fst (add s t) = fst s + fst t := rfl\n\nlemma snd_add_comm {s t : \ud835\udd4a} : snd (add s t) = snd s + snd t := rfl\n\ntheorem add_comm (s t : \ud835\udd4a) : add s t = add t s :=\nbegin\n    apply subtype.eq,\n    simp [add],\n    split,\n        exact rat.add_comm (fst s) (fst t),\n        exact rat.add_comm (snd s) (snd t),\nend\n\n-- We use this lemma in proving that addition on \u211b is well-defined\nlemma contained_bounds_le (s t : \ud835\udd4a) (h : s \u2291 t) : s.snd - s.fst \u2264 t.snd - t.fst :=\nbegin\n    apply sub_le_sub,\n    exact h.elim_right,\n    exact h.elim_left,\nend\n\ninstance : add_comm_semigroup \ud835\udd4a :=\n{\n    add := segment.add, \n    add_assoc := segment.add_assoc,\n    add_comm := segment.add_comm,\n}\n\ndef neg (s : \ud835\udd4a) : \ud835\udd4a := subtype.mk (-s.snd, -s.fst)\n    begin\n        simp,\n        exact subtype.property s,\n    end\n\nend segment", "meta": {"author": "SCRK16", "repo": "Intuitionism", "sha": "a3d9920ae056b39a66e37d1d0e03d246bca1e961", "save_path": "github-repos/lean/SCRK16-Intuitionism", "path": "github-repos/lean/SCRK16-Intuitionism/Intuitionism-a3d9920ae056b39a66e37d1d0e03d246bca1e961/segment.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.73072782063813}}
{"text": "/-\nCopyright (c) 2022 David Loeffler. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Loeffler\n-/\nimport measure_theory.integral.interval_integral\nimport analysis.special_functions.exponential\nimport analysis.special_functions.integrals\nimport measure_theory.integral.integral_eq_improper\n\n/-!\n# Integrals with exponential decay at \u221e\n\nAs easy special cases of general theorems in the library, we prove the following test\nfor integrability:\n\n* `integrable_of_is_O_exp_neg`: If `f` is continuous on `[a,\u221e)`, for some `a \u2208 \u211d`, and there\n  exists `b > 0` such that `f(x) = O(exp(-b x))` as `x \u2192 \u221e`, then `f` is integrable on `(a, \u221e)`.\n-/\n\nnoncomputable theory\nopen real interval_integral measure_theory set filter\n\n/-- Integral of `exp (-b * x)` over `(a, X)` is bounded as `X \u2192 \u221e`. -/\nlemma integral_exp_neg_le {b : \u211d} (a X : \u211d) (h2 : 0 < b) :\n  (\u222b x in a .. X, exp (-b * x)) \u2264 exp (-b * a) / b :=\nbegin\n  rw integral_deriv_eq_sub' (\u03bb x, -exp (-b * x) / b),\n  -- goal 1/4: F(X) - F(a) is bounded\n  { simp only [tsub_le_iff_right],\n    rw [neg_div b (exp (-b * a)), neg_div b (exp (-b * X)), add_neg_self, neg_le, neg_zero],\n    exact (div_pos (exp_pos _) h2).le, },\n  -- goal 2/4: the derivative of F is exp(-b x)\n  { ext1, simp [h2.ne'] },\n  -- goal 3/4: F is differentiable\n  { intros x hx, simp [h2.ne'], },\n  -- goal 4/4: exp(-b x) is continuous\n  { apply continuous.continuous_on, continuity }\nend\n\n/-- `exp (-b * x)` is integrable on `(a, \u221e)`. -/\nlemma exp_neg_integrable_on_Ioi (a : \u211d) {b : \u211d} (h : 0 < b) :\n  integrable_on (\u03bb x : \u211d, exp (-b * x)) (Ioi a) :=\nbegin\n  have : \u2200 (X : \u211d), integrable_on (\u03bb x : \u211d, exp (-b * x) ) (Ioc a X),\n  { intro X, exact (continuous_const.mul continuous_id).exp.integrable_on_Ioc },\n  apply (integrable_on_Ioi_of_interval_integral_norm_bounded (exp (-b * a) / b) a this tendsto_id),\n  simp only [eventually_at_top, norm_of_nonneg (exp_pos _).le],\n  exact \u27e8a, \u03bb b2 hb2, integral_exp_neg_le a b2 h\u27e9,\nend\n\n/-- If `f` is continuous on `[a, \u221e)`, and is `O (exp (-b * x))` at `\u221e` for some `b > 0`, then\n`f` is integrable on `(a, \u221e)`. -/\nlemma integrable_of_is_O_exp_neg {f : \u211d \u2192 \u211d} {a b : \u211d} (h0 : 0 < b)\n  (h1 : continuous_on f (Ici a)) (h2 : asymptotics.is_O f (\u03bb x, exp (-b * x)) at_top) :\n  integrable_on f (Ioi a) :=\nbegin\n  cases h2.is_O_with with c h3,\n  rw [asymptotics.is_O_with_iff, eventually_at_top] at h3,\n  cases h3 with r bdr,\n  let v := max a r,\n  -- show integrable on `(a, v]` from continuity\n  have int_left : integrable_on f (Ioc a v),\n  { rw \u2190(interval_integrable_iff_integrable_Ioc_of_le (le_max_left a r)),\n    have u : Icc a v \u2286 Ici a := Icc_subset_Ici_self,\n    exact (h1.mono u).interval_integrable_of_Icc (le_max_left a r), },\n  suffices : integrable_on f (Ioi v),\n  { have t : integrable_on f (Ioc a v \u222a Ioi v) := integrable_on_union.mpr \u27e8int_left, this\u27e9,\n    simpa only [Ioc_union_Ioi_eq_Ioi, le_max_iff, le_refl, true_or] using t },\n  -- now show integrable on `(v, \u221e)` from asymptotic\n  split,\n  { exact (h1.mono $ Ioi_subset_Ici $ le_max_left a r).ae_strongly_measurable measurable_set_Ioi },\n  have : has_finite_integral (\u03bb x : \u211d, c * exp (-b * x)) (volume.restrict (Ioi v)),\n  { exact (exp_neg_integrable_on_Ioi v h0).has_finite_integral.const_mul c },\n  apply this.mono,\n  refine (ae_restrict_iff' measurable_set_Ioi).mpr _,\n  refine ae_of_all _ (\u03bb x h1x, _),\n  rw [norm_mul, norm_eq_abs],\n  rw [mem_Ioi] at h1x,\n  specialize bdr x ((le_max_right a r).trans h1x.le),\n  exact bdr.trans (mul_le_mul_of_nonneg_right (le_abs_self c) (norm_nonneg _))\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/measure_theory/integral/exp_decay.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7307278162794596}}
{"text": "/-\nCopyright (c) 2014 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Jeremy Avigad\n\n! This file was ported from Lean 3 source module data.nat.dist\n! leanprover-community/mathlib commit d50b12ae8e2bd910d08a94823976adae9825718b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Order.Basic\n\n/-!\n#  Distance function on \u2115\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines a simple distance function on naturals from truncated subtraction.\n-/\n\n\nnamespace Nat\n\n#print Nat.dist /-\n/-- Distance (absolute value of difference) between natural numbers. -/\ndef dist (n m : \u2115) :=\n  n - m + (m - n)\n#align nat.dist Nat.dist\n-/\n\n#print Nat.dist.def /-\ntheorem dist.def (n m : \u2115) : dist n m = n - m + (m - n) :=\n  rfl\n#align nat.dist.def Nat.dist.def\n-/\n\n#print Nat.dist_comm /-\ntheorem dist_comm (n m : \u2115) : dist n m = dist m n := by simp [dist.def, add_comm]\n#align nat.dist_comm Nat.dist_comm\n-/\n\n#print Nat.dist_self /-\n@[simp]\ntheorem dist_self (n : \u2115) : dist n n = 0 := by simp [dist.def, tsub_self]\n#align nat.dist_self Nat.dist_self\n-/\n\n#print Nat.eq_of_dist_eq_zero /-\ntheorem eq_of_dist_eq_zero {n m : \u2115} (h : dist n m = 0) : n = m :=\n  have : n - m = 0 := Nat.eq_zero_of_add_eq_zero_right h\n  have : n \u2264 m := tsub_eq_zero_iff_le.mp this\n  have : m - n = 0 := Nat.eq_zero_of_add_eq_zero_left h\n  have : m \u2264 n := tsub_eq_zero_iff_le.mp this\n  le_antisymm \u2039n \u2264 m\u203a \u2039m \u2264 n\u203a\n#align nat.eq_of_dist_eq_zero Nat.eq_of_dist_eq_zero\n-/\n\n#print Nat.dist_eq_zero /-\ntheorem dist_eq_zero {n m : \u2115} (h : n = m) : dist n m = 0 := by rw [h, dist_self]\n#align nat.dist_eq_zero Nat.dist_eq_zero\n-/\n\n#print Nat.dist_eq_sub_of_le /-\ntheorem dist_eq_sub_of_le {n m : \u2115} (h : n \u2264 m) : dist n m = m - n := by\n  rw [dist.def, tsub_eq_zero_iff_le.mpr h, zero_add]\n#align nat.dist_eq_sub_of_le Nat.dist_eq_sub_of_le\n-/\n\n#print Nat.dist_eq_sub_of_le_right /-\ntheorem dist_eq_sub_of_le_right {n m : \u2115} (h : m \u2264 n) : dist n m = n - m := by rw [dist_comm];\n  apply dist_eq_sub_of_le h\n#align nat.dist_eq_sub_of_le_right Nat.dist_eq_sub_of_le_right\n-/\n\n#print Nat.dist_tri_left /-\ntheorem dist_tri_left (n m : \u2115) : m \u2264 dist n m + n :=\n  le_trans le_tsub_add (add_le_add_right (Nat.le_add_left _ _) _)\n#align nat.dist_tri_left Nat.dist_tri_left\n-/\n\n#print Nat.dist_tri_right /-\ntheorem dist_tri_right (n m : \u2115) : m \u2264 n + dist n m := by rw [add_comm] <;> apply dist_tri_left\n#align nat.dist_tri_right Nat.dist_tri_right\n-/\n\n#print Nat.dist_tri_left' /-\ntheorem dist_tri_left' (n m : \u2115) : n \u2264 dist n m + m := by rw [dist_comm] <;> apply dist_tri_left\n#align nat.dist_tri_left' Nat.dist_tri_left'\n-/\n\n#print Nat.dist_tri_right' /-\ntheorem dist_tri_right' (n m : \u2115) : n \u2264 m + dist n m := by rw [dist_comm] <;> apply dist_tri_right\n#align nat.dist_tri_right' Nat.dist_tri_right'\n-/\n\n#print Nat.dist_zero_right /-\ntheorem dist_zero_right (n : \u2115) : dist n 0 = n :=\n  Eq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n)\n#align nat.dist_zero_right Nat.dist_zero_right\n-/\n\n#print Nat.dist_zero_left /-\ntheorem dist_zero_left (n : \u2115) : dist 0 n = n :=\n  Eq.trans (dist_eq_sub_of_le (zero_le n)) (tsub_zero n)\n#align nat.dist_zero_left Nat.dist_zero_left\n-/\n\n#print Nat.dist_add_add_right /-\ntheorem dist_add_add_right (n k m : \u2115) : dist (n + k) (m + k) = dist n m :=\n  calc\n    dist (n + k) (m + k) = n + k - (m + k) + (m + k - (n + k)) := rfl\n    _ = n - m + (m + k - (n + k)) := by rw [add_tsub_add_eq_tsub_right]\n    _ = n - m + (m - n) := by rw [add_tsub_add_eq_tsub_right]\n    \n#align nat.dist_add_add_right Nat.dist_add_add_right\n-/\n\n#print Nat.dist_add_add_left /-\ntheorem dist_add_add_left (k n m : \u2115) : dist (k + n) (k + m) = dist n m := by\n  rw [add_comm k n, add_comm k m]; apply dist_add_add_right\n#align nat.dist_add_add_left Nat.dist_add_add_left\n-/\n\n#print Nat.dist_eq_intro /-\ntheorem dist_eq_intro {n m k l : \u2115} (h : n + m = k + l) : dist n k = dist l m :=\n  calc\n    dist n k = dist (n + m) (k + m) := by rw [dist_add_add_right]\n    _ = dist (k + l) (k + m) := by rw [h]\n    _ = dist l m := by rw [dist_add_add_left]\n    \n#align nat.dist_eq_intro Nat.dist_eq_intro\n-/\n\n#print Nat.dist.triangle_inequality /-\ntheorem dist.triangle_inequality (n m k : \u2115) : dist n k \u2264 dist n m + dist m k :=\n  by\n  have : dist n m + dist m k = n - m + (m - k) + (k - m + (m - n)) := by\n    simp [dist.def, add_comm, add_left_comm]\n  rw [this, dist.def]\n  exact add_le_add tsub_le_tsub_add_tsub tsub_le_tsub_add_tsub\n#align nat.dist.triangle_inequality Nat.dist.triangle_inequality\n-/\n\n#print Nat.dist_mul_right /-\ntheorem dist_mul_right (n k m : \u2115) : dist (n * k) (m * k) = dist n m * k := by\n  rw [dist.def, dist.def, right_distrib, tsub_mul, tsub_mul]\n#align nat.dist_mul_right Nat.dist_mul_right\n-/\n\n#print Nat.dist_mul_left /-\ntheorem dist_mul_left (k n m : \u2115) : dist (k * n) (k * m) = k * dist n m := by\n  rw [mul_comm k n, mul_comm k m, dist_mul_right, mul_comm]\n#align nat.dist_mul_left Nat.dist_mul_left\n-/\n\n#print Nat.dist_succ_succ /-\n-- TODO(Jeremy): do when we have max and minx\n--theorem dist_eq_max_sub_min {i j : nat} : dist i j = (max i j) - min i j :=\n--sorry\n/-\nor.elim (lt_or_ge i j)\n  (assume : i < j,\n    by rw [max_eq_right_of_lt this, min_eq_left_of_lt this, dist_eq_sub_of_lt this])\n  (assume : i \u2265 j,\n    by rw [max_eq_left this , min_eq_right this, dist_eq_sub_of_le_right this])\n-/\ntheorem dist_succ_succ {i j : Nat} : dist (succ i) (succ j) = dist i j := by\n  simp [dist.def, succ_sub_succ]\n#align nat.dist_succ_succ Nat.dist_succ_succ\n-/\n\n#print Nat.dist_pos_of_ne /-\ntheorem dist_pos_of_ne {i j : Nat} : i \u2260 j \u2192 0 < dist i j := fun hne =>\n  Nat.ltByCases\n    (fun this : i < j => by rw [dist_eq_sub_of_le (le_of_lt this)]; apply tsub_pos_of_lt this)\n    (fun this : i = j => by contradiction) fun this : i > j => by\n    rw [dist_eq_sub_of_le_right (le_of_lt this)]; apply tsub_pos_of_lt this\n#align nat.dist_pos_of_ne Nat.dist_pos_of_ne\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7307278128840873}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis file defines Fibonacci numbers and their reductions mod `n`.\nIt was intended to make computation efficient, but does not\nsucceed very well.  Some better approaches were discussed on\nZulip by Mario and Kenny; they should be incorporated here.\n-/\n\nimport data.real.basic data.fintype.basic algebra.big_operators data.nat.modeq\nimport tactic.find tactic.squeeze tactic.norm_num tactic.ring\n\nnamespace combinatorics\n\n/- This is the basic definition of fibonacci numbers.  It \n   is not good for efficient evaluation.\n-/\n\ndef fibonacci : \u2115 \u2192 \u2115 \n| 0 := 0\n| 1 := 1\n| (n + 2) := (fibonacci n) + (fibonacci (n + 1))\n\n/- We now do a more efficient version, and prove that it is \n   consistent with the original one.\n-/\n\ndef fibonacci_step : \u2115 \u00d7 \u2115 \u2192 \u2115 \u00d7 \u2115 := \n \u03bb \u27e8a,b\u27e9, \u27e8b, a + b\u27e9\n\ndef fibonacci_pair : \u2115 \u2192 \u2115 \u00d7 \u2115 \n| 0 := \u27e80,1\u27e9 \n| (n + 1) := fibonacci_step (fibonacci_pair n)\n\nlemma fibonacci_pair_spec : \u2200 n , \n fibonacci_pair n = \u27e8fibonacci n,fibonacci n.succ\u27e9 \n| 0 := rfl\n| (nat.succ n) := begin\n rw[fibonacci_pair,fibonacci_pair_spec n,fibonacci_step,fibonacci],\n ext,refl,refl,\nend\n\nlemma fibonacci_from_pair (n : \u2115) : \n fibonacci n = (fibonacci_pair n).fst := \n  by rw[fibonacci_pair_spec n].\n\n/- We now prove a fact about the fibonacci numbers mod 2.\n   Later we will generalise this for an arbitrary modulus.\n-/\n\nlemma fibonacci_bodd_step (n : \u2115) : \n (fibonacci (n + 3)).bodd = (fibonacci n).bodd := \nbegin\n rw[fibonacci,fibonacci,nat.bodd_add,nat.bodd_add],\n cases (fibonacci (n + 1)).bodd;\n cases (fibonacci n).bodd;\n refl,\nend\n\nlemma fibonacci_bodd : \u2200 n, (fibonacci n).bodd = bnot (n % 3 = 0)\n| 0 := rfl\n| 1 := rfl\n| 2 := rfl\n| (n + 3) := begin\n rw[fibonacci_bodd_step n,fibonacci_bodd n,nat.add_mod_right]\nend\n\n/-\n We now do a more general theory of modular periodicity\n of fibonacci numbers.  For computational efficiency, we\n give an inductive definition of modular fibonacci numbers\n that does not require us to calculate the non-modular ones.\n We then prove that it is consistent with the original \n definition.\n-/\n\ndef pair_mod (p : \u2115) : \u2115 \u00d7 \u2115 \u2192 \u2115 \u00d7 \u2115 := \n \u03bb \u27e8a,b\u27e9, \u27e8a % p,b % p\u27e9 \n\nlemma pair_mod_mod (p : \u2115) : \u2200 (c : \u2115 \u00d7 \u2115), \n pair_mod p (pair_mod p c) = pair_mod p c := \n\u03bb \u27e8a,b\u27e9, by {simp[pair_mod,nat.mod_mod],}\n\ndef fibonacci_pair_mod (p : \u2115) : \u2115 \u2192 \u2115 \u00d7 \u2115 \n| 0 := pair_mod p \u27e80,1\u27e9 \n| (n + 1) := pair_mod p (fibonacci_step (fibonacci_pair_mod n))\n\nlemma fibonacci_pair_mod_mod (p : \u2115) : \u2200 n,\n pair_mod p (fibonacci_pair_mod p n) = fibonacci_pair_mod p n\n| 0 := by {rw[fibonacci_pair_mod,pair_mod_mod],} \n| (n + 1) := by {rw[fibonacci_pair_mod,pair_mod_mod],} \n\nlemma mod_step_mod (p : \u2115) : \u2200 (c : \u2115 \u00d7 \u2115), \n pair_mod p (fibonacci_step c) = \n  pair_mod p (fibonacci_step (pair_mod p c)) :=\n\u03bb \u27e8a,b\u27e9, begin\n change (\u27e8b % p,(a + b) % p\u27e9 : \u2115 \u00d7 \u2115) = \n  \u27e8b % p % p,(a % p + b % p) % p\u27e9,\n have e0 : b % p % p = b % p := nat.mod_mod b p,\n have e1 : (a % p + b % p) % p = (a + b) % p :=\n  nat.modeq.add (nat.mod_mod a p) (nat.mod_mod b p),\n rw[e0,e1],\nend\n\nlemma fibonacci_pair_mod_spec (p : \u2115) : \u2200 n, \n fibonacci_pair_mod p n = pair_mod p (fibonacci_pair n) \n| 0 := rfl\n| (n + 1) := begin\n rw[fibonacci_pair_mod,fibonacci_pair,fibonacci_pair_mod_spec n],\n rw[\u2190 mod_step_mod],\nend\n\nlemma fibonacci_mod_spec (p : \u2115) (n : \u2115) :\n (fibonacci_pair_mod p n).fst = (fibonacci n) % p := \nbegin\n rw[fibonacci_pair_mod_spec,fibonacci_pair_spec,pair_mod],\n refl,\nend\n\nlemma fibonacci_pair_period\u2080 {p : \u2115} {d : \u2115} \n (h : fibonacci_pair_mod p d = pair_mod p \u27e80,1\u27e9) :\n  \u2200 n, fibonacci_pair_mod p (n + d) = fibonacci_pair_mod p n\n| 0 := by {rw[zero_add,h,fibonacci_pair_mod],}\n| (n + 1) := by {\n  rw[add_assoc,add_comm 1 d,\u2190 add_assoc],\n  rw[fibonacci_pair_mod,fibonacci_pair_mod],\n  rw[fibonacci_pair_period\u2080 n],\n}\n\nlemma fibonacci_pair_period\u2081 {p : \u2115} {d : \u2115} \n (h : fibonacci_pair_mod p d = pair_mod p \u27e80,1\u27e9) (m : \u2115) :\n  \u2200 n, fibonacci_pair_mod p (m + d * n) = fibonacci_pair_mod p m\n| 0 := by {rw[mul_zero,add_zero]}\n| (n + 1) := by {\n  have : m + d * (n + 1) = (m + d * n) + d := by ring,\n  rw[this,fibonacci_pair_period\u2080 h,fibonacci_pair_period\u2081],\n}\n\nlemma fibonacci_pair_period {p : \u2115} {d : \u2115} \n (h : fibonacci_pair_mod p d = pair_mod p \u27e80,1\u27e9) (n : \u2115) : \n  fibonacci_pair_mod p n = fibonacci_pair_mod p (n % d) := \ncalc \n fibonacci_pair_mod p n = fibonacci_pair_mod p (n % d + d * (n / d)) :\n  congr_arg (fibonacci_pair_mod p) (nat.mod_add_div n d).symm\n  ... = fibonacci_pair_mod p (n % d) : fibonacci_pair_period\u2081 h (n % d) (n / d)\n\nlemma fibonacci_period  {p : \u2115} {d : \u2115} \n (h : fibonacci_pair_mod p d = pair_mod p \u27e80,1\u27e9) (n : \u2115) : \n  (fibonacci n) \u2261 (fibonacci (n % d)) [MOD p] := \nbegin\n rw[nat.modeq,\u2190 fibonacci_mod_spec,\u2190 fibonacci_mod_spec],\n rw[fibonacci_pair_period],\n exact h,\nend\n\n/-\n Prove the identity\n\n (fibonacci n) = (choose n 0) + (choose n-1 1) + (choose n-2 2) + ...\n-/\n\nend combinatorics", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/combinatorics/fibonacci.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7306968629301396}}
{"text": "import algebra.group\n\nvariable {G: Type*}\n\n-- mathlib's constructor for `group` asks only for a (two-sided) identity\n-- alongside a left inverse. This exercise shows it is possible to produce\n-- both of those things if given a right identity and a right inverse.\ntheorem Q_12 (G: Type*) (mul: G \u2192 G \u2192 G) (e: G) (y: G \u2192 G):\n  (\u2200 a b c: G, (mul (mul a b) c) = (mul a (mul b c))) \u2227\n  (\u2200 a: G, mul a e = a) \u2227\n  (\u2200 a: G, mul a (y a) = e)\n  \u2192 group G :=\n\u03bb \u27e8h1, \u27e8h2, h3\u27e9\u27e9, begin\n\n  -- the right inverse is also a left inverse\n  have h4: \u2200 a: G, mul (y a) a = e, from \u03bb a, calc\n  mul (y a) a\n    = mul (mul (y a) a) e                              : (h2 _).symm\n... = mul (mul (y a) a) (mul (y a) (y (y a))) : by rw \u2190h3\n... = mul (y a) (mul a (mul (y a) (y (y a)))) : h1 _ _ _\n... = mul (y a) (mul (mul a (y a)) (y (y a))) : by rw h1\n... = mul (y a) (mul e (y (y a)))                : by rw h3\n... = mul (mul (y a) e) (y (y a))                : by rw \u2190h1\n... = mul (y a) (y (y a))                        : by rw h2\n... = e                                                   : h3 _,\n\n  -- the right identity is also the left identity\n  have h5: \u2200 a: G, mul e a = a, from \u03bb a, calc\n  mul e a\n    = mul (mul a (y a)) a : by rw h3\n... = mul a (mul (y a) a) : h1 _ _ _\n... = mul a e                : by rw h4\n... = a                      : h2 _,\n\n  -- we have now shown everything we need to\n  -- synthesise an instance of group G:\n  exact {\n    mul := mul,\n    mul_assoc := h1,\n    one := e,\n    one_mul := h5,\n    mul_one := h2,\n    inv := y,\n    mul_left_inv := h4\n  },\nend\n\n\n", "meta": {"author": "group-study-group", "repo": "herstein", "sha": "f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66", "save_path": "github-repos/lean/group-study-group-herstein", "path": "github-repos/lean/group-study-group-herstein/herstein-f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66/src/herstein/ex2_3/Q_12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941718, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7306968428469874}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Yury Kudryashov, Ya\u00ebl Dillies\n-/\nimport order.synonym\n\n/-!\n# Minimal/maximal and bottom/top elements\n\nThis file defines predicates for elements to be minimal/maximal or bottom/top and typeclasses\nsaying that there are no such elements.\n\n## Predicates\n\n* `is_bot`: An element is *bottom* if all elements are greater than it.\n* `is_top`: An element is *top* if all elements are less than it.\n* `is_min`: An element is *minimal* if no element is strictly less than it.\n* `is_max`: An element is *maximal* if no element is strictly greater than it.\n\nSee also `is_bot_iff_is_min` and `is_top_iff_is_max` for the equivalences in a (co)directed order.\n\n## Typeclasses\n\n* `no_bot_order`: An order without bottom elements.\n* `no_top_order`: An order without top elements.\n* `no_min_order`: An order without minimal elements.\n* `no_max_order`: An order without maximal elements.\n-/\n\nopen order_dual\n\nvariables {\u03b1 \u03b2 : Type*}\n\n/-- Order without bottom elements. -/\nclass no_bot_order (\u03b1 : Type*) [has_le \u03b1] : Prop :=\n(exists_not_ge (a : \u03b1) : \u2203 b, \u00ac a \u2264 b)\n\n/-- Order without top elements. -/\nclass no_top_order (\u03b1 : Type*) [has_le \u03b1] : Prop :=\n(exists_not_le (a : \u03b1) : \u2203 b, \u00ac b \u2264 a)\n\n/-- Order without minimal elements. Sometimes called coinitial or dense. -/\nclass no_min_order (\u03b1 : Type*) [has_lt \u03b1] : Prop :=\n(exists_lt (a : \u03b1) : \u2203 b, b < a)\n\n/-- Order without maximal elements. Sometimes called cofinal. -/\nclass no_max_order (\u03b1 : Type*) [has_lt \u03b1] : Prop :=\n(exists_gt (a : \u03b1) : \u2203 b, a < b)\n\nexport no_bot_order (exists_not_ge)\nexport no_top_order (exists_not_le)\nexport no_min_order (exists_lt)\nexport no_max_order (exists_gt)\n\ninstance nonempty_lt [has_lt \u03b1] [no_min_order \u03b1] (a : \u03b1) : nonempty {x // x < a} :=\nnonempty_subtype.2 (exists_lt a)\n\ninstance nonempty_gt [has_lt \u03b1] [no_max_order \u03b1] (a : \u03b1) : nonempty {x // a < x} :=\nnonempty_subtype.2 (exists_gt a)\n\ninstance order_dual.no_bot_order (\u03b1 : Type*) [has_le \u03b1] [no_top_order \u03b1] : no_bot_order \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a, @exists_not_le \u03b1 _ _ a\u27e9\n\ninstance order_dual.no_top_order (\u03b1 : Type*) [has_le \u03b1] [no_bot_order \u03b1] : no_top_order \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a, @exists_not_ge \u03b1 _ _ a\u27e9\n\ninstance order_dual.no_min_order (\u03b1 : Type*) [has_lt \u03b1] [no_max_order \u03b1] : no_min_order \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a, @exists_gt \u03b1 _ _ a\u27e9\n\ninstance order_dual.no_max_order (\u03b1 : Type*) [has_lt \u03b1] [no_min_order \u03b1] : no_max_order \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a, @exists_lt \u03b1 _ _ a\u27e9\n\n@[priority 100] -- See note [lower instance priority]\ninstance no_min_order.to_no_bot_order (\u03b1 : Type*) [preorder \u03b1] [no_min_order \u03b1] : no_bot_order \u03b1 :=\n\u27e8\u03bb a, (exists_lt a).imp $ \u03bb _, not_le_of_lt\u27e9\n\n@[priority 100] -- See note [lower instance priority]\ninstance no_max_order.to_no_top_order (\u03b1 : Type*) [preorder \u03b1] [no_max_order \u03b1] : no_top_order \u03b1 :=\n\u27e8\u03bb a, (exists_gt a).imp $ \u03bb _, not_le_of_lt\u27e9\n\nsection has_le\nvariables [has_le \u03b1] {a b : \u03b1}\n\n/-- `a : \u03b1` is a bottom element of `\u03b1` if it is less than or equal to any other element of `\u03b1`.\nThis predicate is roughly an unbundled version of `order_bot`, except that a preorder may have\nseveral bottom elements. When `\u03b1` is linear, this is useful to make a case disjunction on\n`no_min_order \u03b1` within a proof. -/\ndef is_bot (a : \u03b1) : Prop := \u2200 b, a \u2264 b\n\n/-- `a : \u03b1` is a top element of `\u03b1` if it is greater than or equal to any other element of `\u03b1`.\nThis predicate is roughly an unbundled version of `order_bot`, except that a preorder may have\nseveral top elements. When `\u03b1` is linear, this is useful to make a case disjunction on\n`no_max_order \u03b1` within a proof. -/\ndef is_top (a : \u03b1) : Prop := \u2200 b, b \u2264 a\n\n/-- `a` is a minimal element of `\u03b1` if no element is strictly less than it. We spell it without `<`\nto avoid having to convert between `\u2264` and `<`. Instead, `is_min_iff_forall_not_lt` does the\nconversion. -/\ndef is_min (a : \u03b1) : Prop := \u2200 \u2983b\u2984, b \u2264 a \u2192 a \u2264 b\n\n/-- `a` is a maximal element of `\u03b1` if no element is strictly greater than it. We spell it without\n`<` to avoid having to convert between `\u2264` and `<`. Instead, `is_max_iff_forall_not_lt` does the\nconversion. -/\ndef is_max (a : \u03b1) : Prop := \u2200 \u2983b\u2984, a \u2264 b \u2192 b \u2264 a\n\n@[simp] lemma not_is_bot [no_bot_order \u03b1] (a : \u03b1) : \u00acis_bot a :=\n\u03bb h, let \u27e8b, hb\u27e9 := exists_not_ge a in hb $ h _\n\n@[simp] lemma not_is_top [no_top_order \u03b1] (a : \u03b1) : \u00acis_top a :=\n\u03bb h, let \u27e8b, hb\u27e9 := exists_not_le a in hb $ h _\n\nprotected lemma is_bot.is_min (h : is_bot a) : is_min a := \u03bb b _, h b\nprotected lemma is_top.is_max (h : is_top a) : is_max a := \u03bb b _, h b\n\n@[simp] lemma is_bot_to_dual_iff : is_bot (to_dual a) \u2194 is_top a := iff.rfl\n@[simp] lemma is_top_to_dual_iff : is_top (to_dual a) \u2194 is_bot a := iff.rfl\n@[simp] lemma is_min_to_dual_iff : is_min (to_dual a) \u2194 is_max a := iff.rfl\n@[simp] lemma is_max_to_dual_iff : is_max (to_dual a) \u2194 is_min a := iff.rfl\n@[simp] lemma is_bot_of_dual_iff {a : \u03b1\u1d52\u1d48} : is_bot (of_dual a) \u2194 is_top a := iff.rfl\n@[simp] lemma is_top_of_dual_iff {a : \u03b1\u1d52\u1d48} : is_top (of_dual a) \u2194 is_bot a := iff.rfl\n@[simp] lemma is_min_of_dual_iff {a : \u03b1\u1d52\u1d48} : is_min (of_dual a) \u2194 is_max a := iff.rfl\n@[simp] lemma is_max_of_dual_iff {a : \u03b1\u1d52\u1d48} : is_max (of_dual a) \u2194 is_min a := iff.rfl\n\nalias is_bot_to_dual_iff \u2194 _ is_top.to_dual\nalias is_top_to_dual_iff \u2194 _ is_bot.to_dual\nalias is_min_to_dual_iff \u2194 _ is_max.to_dual\nalias is_max_to_dual_iff \u2194 _ is_min.to_dual\nalias is_bot_of_dual_iff \u2194 _ is_top.of_dual\nalias is_top_of_dual_iff \u2194 _ is_bot.of_dual\nalias is_min_of_dual_iff \u2194 _ is_max.of_dual\nalias is_max_of_dual_iff \u2194 _ is_min.of_dual\n\nend has_le\n\nsection preorder\nvariables [preorder \u03b1] {a b : \u03b1}\n\nlemma is_bot.mono (ha : is_bot a) (h : b \u2264 a) : is_bot b := \u03bb c, h.trans $ ha _\nlemma is_top.mono (ha : is_top a) (h : a \u2264 b) : is_top b := \u03bb c, (ha _).trans h\nlemma is_min.mono (ha : is_min a) (h : b \u2264 a) : is_min b := \u03bb c hc, h.trans $ ha $ hc.trans h\nlemma is_max.mono (ha : is_max a) (h : a \u2264 b) : is_max b := \u03bb c hc, (ha $ h.trans hc).trans h\n\nlemma is_min.not_lt (h : is_min a) : \u00ac b < a := \u03bb hb, hb.not_le $ h hb.le\nlemma is_max.not_lt (h : is_max a) : \u00ac a < b := \u03bb hb, hb.not_le $ h hb.le\n@[simp] lemma not_is_min_of_lt (h : b < a) : \u00ac is_min a := \u03bb ha, ha.not_lt h\n@[simp] lemma not_is_max_of_lt (h : a < b) : \u00ac is_max a := \u03bb ha, ha.not_lt h\n\nalias not_is_min_of_lt \u2190 has_lt.lt.not_is_min\nalias not_is_max_of_lt \u2190 has_lt.lt.not_is_max\n\nlemma is_min_iff_forall_not_lt : is_min a \u2194 \u2200 b, \u00ac b < a :=\n\u27e8\u03bb h _, h.not_lt, \u03bb h b hba, of_not_not $ \u03bb hab, h _ $ hba.lt_of_not_le hab\u27e9\n\nlemma is_max_iff_forall_not_lt : is_max a \u2194 \u2200 b, \u00ac a < b :=\n\u27e8\u03bb h _, h.not_lt, \u03bb h b hba, of_not_not $ \u03bb hab, h _ $ hba.lt_of_not_le hab\u27e9\n\n@[simp] lemma not_is_min_iff : \u00ac is_min a \u2194 \u2203 b, b < a :=\nby simp_rw [lt_iff_le_not_le, is_min, not_forall, exists_prop]\n\n@[simp] lemma not_is_max_iff : \u00ac is_max a \u2194 \u2203 b, a < b :=\nby simp_rw [lt_iff_le_not_le, is_max, not_forall, exists_prop]\n\n@[simp] lemma not_is_min [no_min_order \u03b1] (a : \u03b1) : \u00ac is_min a := not_is_min_iff.2 $ exists_lt a\n@[simp] lemma not_is_max [no_max_order \u03b1] (a : \u03b1) : \u00ac is_max a := not_is_max_iff.2 $ exists_gt a\n\nnamespace subsingleton\nvariable [subsingleton \u03b1]\n\nprotected lemma is_bot (a : \u03b1) : is_bot a := \u03bb _, (subsingleton.elim _ _).le\nprotected lemma is_top (a : \u03b1) : is_top a := \u03bb _, (subsingleton.elim _ _).le\nprotected lemma is_min (a : \u03b1) : is_min a := (subsingleton.is_bot _).is_min\nprotected lemma is_max (a : \u03b1) : is_max a := (subsingleton.is_top _).is_max\n\nend subsingleton\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] {a b : \u03b1}\n\nprotected lemma is_min.eq_of_le (ha : is_min a) (h : b \u2264 a) : b = a := h.antisymm $ ha h\nprotected lemma is_min.eq_of_ge (ha : is_min a) (h : b \u2264 a) : a = b := h.antisymm' $ ha h\nprotected lemma is_max.eq_of_le (ha : is_max a) (h : a \u2264 b) : a = b := h.antisymm $ ha h\nprotected lemma is_max.eq_of_ge (ha : is_max a) (h : a \u2264 b) : b = a := h.antisymm' $ ha h\n\nend partial_order\n\nsection prod\nvariables [preorder \u03b1] [preorder \u03b2] {a a\u2081 a\u2082 : \u03b1} {b b\u2081 b\u2082 : \u03b2} {x y : \u03b1 \u00d7 \u03b2}\n\nlemma is_bot.prod_mk (ha : is_bot a) (hb : is_bot b) : is_bot (a, b) := \u03bb c, \u27e8ha _, hb _\u27e9\nlemma is_top.prod_mk (ha : is_top a) (hb : is_top b) : is_top (a, b) := \u03bb c, \u27e8ha _, hb _\u27e9\nlemma is_min.prod_mk (ha : is_min a) (hb : is_min b) : is_min (a, b) := \u03bb c hc, \u27e8ha hc.1, hb hc.2\u27e9\nlemma is_max.prod_mk (ha : is_max a) (hb : is_max b) : is_max (a, b) := \u03bb c hc, \u27e8ha hc.1, hb hc.2\u27e9\n\nlemma is_bot.fst (hx : is_bot x) : is_bot x.1 := \u03bb c, (hx (c, x.2)).1\nlemma is_bot.snd (hx : is_bot x) : is_bot x.2 := \u03bb c, (hx (x.1, c)).2\nlemma is_top.fst (hx : is_top x) : is_top x.1 := \u03bb c, (hx (c, x.2)).1\nlemma is_top.snd (hx : is_top x) : is_top x.2 := \u03bb c, (hx (x.1, c)).2\n\nlemma is_min.fst (hx : is_min x) : is_min x.1 :=\n\u03bb c hc, (hx $ show (c, x.2) \u2264 x, from (and_iff_left le_rfl).2 hc).1\n\nlemma is_min.snd (hx : is_min x) : is_min x.2 :=\n\u03bb c hc, (hx $ show (x.1, c) \u2264 x, from (and_iff_right le_rfl).2 hc).2\n\nlemma is_max.fst (hx : is_max x) : is_max x.1 :=\n\u03bb c hc, (hx $ show x \u2264 (c, x.2), from (and_iff_left le_rfl).2 hc).1\n\nlemma is_max.snd (hx : is_max x) : is_max x.2 :=\n\u03bb c hc, (hx $ show x \u2264 (x.1, c), from (and_iff_right le_rfl).2 hc).2\n\nlemma prod.is_bot_iff : is_bot x \u2194 is_bot x.1 \u2227 is_bot x.2 :=\n\u27e8\u03bb hx, \u27e8hx.fst, hx.snd\u27e9, \u03bb h, h.1.prod_mk h.2\u27e9\n\nlemma prod.is_top_iff : is_top x \u2194 is_top x.1 \u2227 is_top x.2 :=\n\u27e8\u03bb hx, \u27e8hx.fst, hx.snd\u27e9, \u03bb h, h.1.prod_mk h.2\u27e9\n\nlemma prod.is_min_iff : is_min x \u2194 is_min x.1 \u2227 is_min x.2 :=\n\u27e8\u03bb hx, \u27e8hx.fst, hx.snd\u27e9, \u03bb h, h.1.prod_mk h.2\u27e9\n\nlemma prod.is_max_iff : is_max x \u2194 is_max x.1 \u2227 is_max x.2 :=\n\u27e8\u03bb hx, \u27e8hx.fst, hx.snd\u27e9, \u03bb h, h.1.prod_mk h.2\u27e9\n\nend prod\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467801752451, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7306967362282322}}
{"text": "import number_theory.padics.padic_integers\n\n\n--OUTPUT 1\ntheorem p_adic_units (p : \u2115) (x : \u2115) (h : gcd x p = 1) : \u2203 y : \u2115, x * y = 1 :=\nbegin\n  have h1 : \u2200 x : \u2115, \u2203 y : \u2115, x * y = 1, from by auto [gcd_dvd_right],\n  have h2 : \u2200 x : \u2115, \u2203 y : \u2115, y * x = 1, from by auto [gcd_dvd_left],\n  have h3 : \u2200 x : \u2115, \u2203 y : \u2115, x * y = 1 \u2228 y * x = 1, from by auto [h1, h2],\n  have h4 : \u2200 x : \u2115, \u2203 y : \u2115, x * y = 1, from by auto [h3],\n  show \u2203 y : \u2115, x * y = 1, from by auto [h4, h],\nend\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],\n  have h2 : (A \u2229 B) \u2286 A, from by auto [set.inter_subset_left],\n  have h3 : (A \u2229 B) \u2286 S, from by auto [set.subset.trans],\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by auto [set.mem_powerset],\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]\n  ... = x*(x+y) + y*(x+y) : by auto [add_mul]\n  ... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]\n  ... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring]\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by auto using [use (a\u207b\u00b9 * b)],\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by auto using [use b * a\u207b\u00b9], \n\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from by auto [h1],\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from by auto [h2],\n\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one],\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul],\n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)],\nend\n\n/--`theorem`\np-adic units\nGiven a prime number $p$ and a natural number $x$, if $x$ is coprime to $p$, then $x$ is a unit in the $p$-adic integers.\n`proof`\nLet us prove the contrapositive, that is, is $x$ is not a unit of $\\mathbb{Z}_p$, then $x$ is not coprime to $p$. \nWe know that any element of $\\mathbb{Z}_p$ is a unit if and only if it has norm 1, thus $\\Vert x \\Vert \\neq 1$. Also, since every element of $\\mathbb{Z}_p$ must have norm less than or equal to 1, we conclude that $\\Vert x \\Vert < 1$. \nBut this must imply that $p | x$.\nThis completes our proof.\n\nQED\n-/\ntheorem \nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_auto-Natural-Language-Proof-Translation/lean_proof_auto-3_few_shot_temperature_0_max_tokens_2000_n_1/clean_files/p-adic units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7306967241148059}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n-/\nimport data.list.bag_inter\nimport data.list.erase_dup\nimport data.list.zip\nimport logic.relation\nimport data.nat.factorial\n\n/-!\n# List permutations\n-/\n\nopen_locale nat\n\nnamespace list\nuniverse variables uu vv\nvariables {\u03b1 : Type uu} {\u03b2 : Type vv}\n\n/-- `perm l\u2081 l\u2082` or `l\u2081 ~ l\u2082` asserts that `l\u2081` and `l\u2082` are permutations\n  of each other. This is defined by induction using pairwise swaps. -/\ninductive perm : list \u03b1 \u2192 list \u03b1 \u2192 Prop\n| nil   : perm [] []\n| cons  : \u03a0 (x : \u03b1) {l\u2081 l\u2082 : list \u03b1}, perm l\u2081 l\u2082 \u2192 perm (x::l\u2081) (x::l\u2082)\n| swap  : \u03a0 (x y : \u03b1) (l : list \u03b1), perm (y::x::l) (x::y::l)\n| trans : \u03a0 {l\u2081 l\u2082 l\u2083 : list \u03b1}, perm l\u2081 l\u2082 \u2192 perm l\u2082 l\u2083 \u2192 perm l\u2081 l\u2083\n\nopen perm (swap)\n\ninfix ~ := perm\n\n@[refl] protected theorem perm.refl : \u2200 (l : list \u03b1), l ~ l\n| []      := perm.nil\n| (x::xs) := (perm.refl xs).cons x\n\n@[symm] protected theorem perm.symm {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2082 ~ l\u2081 :=\nperm.rec_on p\n  perm.nil\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, r\u2081.cons x)\n  (\u03bb x y l, swap y x l)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, r\u2082.trans r\u2081)\n\ntheorem perm_comm {l\u2081 l\u2082 : list \u03b1} : l\u2081 ~ l\u2082 \u2194 l\u2082 ~ l\u2081 := \u27e8perm.symm, perm.symm\u27e9\n\ntheorem perm.swap'\n  (x y : \u03b1) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : y::x::l\u2081 ~ x::y::l\u2082 :=\n(swap _ _ _).trans ((p.cons _).cons _)\n\nattribute [trans] perm.trans\n\ntheorem perm.eqv (\u03b1) : equivalence (@perm \u03b1) :=\nmk_equivalence (@perm \u03b1) (@perm.refl \u03b1) (@perm.symm \u03b1) (@perm.trans \u03b1)\n\ninstance is_setoid (\u03b1) : setoid (list \u03b1) :=\nsetoid.mk (@perm \u03b1) (perm.eqv \u03b1)\n\ntheorem perm.subset {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 \u2286 l\u2082 :=\n\u03bb a, perm.rec_on p\n  (\u03bb h, h)\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081 i, or.elim i\n    (\u03bb ax, by simp [ax])\n    (\u03bb al\u2081, or.inr (r\u2081 al\u2081)))\n  (\u03bb x y l ayxl, or.elim ayxl\n    (\u03bb ay, by simp [ay])\n    (\u03bb axl, or.elim axl\n      (\u03bb ax, by simp [ax])\n      (\u03bb al, or.inr (or.inr al))))\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082 ainl\u2081, r\u2082 (r\u2081 ainl\u2081))\n\ntheorem perm.mem_iff {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} (h : l\u2081 ~ l\u2082) : a \u2208 l\u2081 \u2194 a \u2208 l\u2082 :=\niff.intro (\u03bb m, h.subset m) (\u03bb m, h.symm.subset m)\n\ntheorem perm.append_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b1) (p : l\u2081 ~ l\u2082) : l\u2081++t\u2081 ~ l\u2082++t\u2081 :=\nperm.rec_on p\n  (perm.refl ([] ++ t\u2081))\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, r\u2081.cons x)\n  (\u03bb x y l, swap x y _)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, r\u2081.trans r\u2082)\n\ntheorem perm.append_left {t\u2081 t\u2082 : list \u03b1} : \u2200 (l : list \u03b1), t\u2081 ~ t\u2082 \u2192 l++t\u2081 ~ l++t\u2082\n| []      p := p\n| (x::xs) p := (perm.append_left xs p).cons x\n\ntheorem perm.append {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081++t\u2081 ~ l\u2082++t\u2082 :=\n(p\u2081.append_right t\u2081).trans (p\u2082.append_left l\u2082)\n\ntheorem perm.append_cons (a : \u03b1) {h\u2081 h\u2082 t\u2081 t\u2082 : list \u03b1}\n  (p\u2081 : h\u2081 ~ h\u2082) (p\u2082 : t\u2081 ~ t\u2082) : h\u2081 ++ a::t\u2081 ~ h\u2082 ++ a::t\u2082 :=\np\u2081.append (p\u2082.cons a)\n\n@[simp] theorem perm_middle {a : \u03b1} : \u2200 {l\u2081 l\u2082 : list \u03b1}, l\u2081++a::l\u2082 ~ a::(l\u2081++l\u2082)\n| []      l\u2082 := perm.refl _\n| (b::l\u2081) l\u2082 := ((@perm_middle l\u2081 l\u2082).cons _).trans (swap a b _)\n\n@[simp] theorem perm_append_singleton (a : \u03b1) (l : list \u03b1) : l ++ [a] ~ a::l :=\nperm_middle.trans $ by rw [append_nil]\n\ntheorem perm_append_comm : \u2200 {l\u2081 l\u2082 : list \u03b1}, (l\u2081++l\u2082) ~ (l\u2082++l\u2081)\n| []     l\u2082 := by simp\n| (a::t) l\u2082 := (perm_append_comm.cons _).trans perm_middle.symm\n\ntheorem concat_perm (l : list \u03b1) (a : \u03b1) : concat l a ~ a :: l :=\nby simp\n\ntheorem perm.length_eq {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : length l\u2081 = length l\u2082 :=\nperm.rec_on p\n  rfl\n  (\u03bb x l\u2081 l\u2082 p r, by simp[r])\n  (\u03bb x y l, by simp)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, eq.trans r\u2081 r\u2082)\n\ntheorem perm.eq_nil {l : list \u03b1} (p : l ~ []) : l = [] :=\neq_nil_of_length_eq_zero p.length_eq\n\ntheorem perm.nil_eq {l : list \u03b1} (p : [] ~ l) : [] = l :=\np.symm.eq_nil.symm\n\ntheorem perm_nil {l\u2081 : list \u03b1} : l\u2081 ~ [] \u2194 l\u2081 = [] :=\n\u27e8\u03bb p, p.eq_nil, \u03bb e, e \u25b8 perm.refl _\u27e9\n\ntheorem not_perm_nil_cons (x : \u03b1) (l : list \u03b1) : \u00ac [] ~ x::l\n| p := by injection p.symm.eq_nil\n\n@[simp] theorem reverse_perm : \u2200 (l : list \u03b1), reverse l ~ l\n| []     := perm.nil\n| (a::l) := by { rw reverse_cons,\n  exact (perm_append_singleton _ _).trans ((reverse_perm l).cons a) }\n\ntheorem perm_cons_append_cons {l l\u2081 l\u2082 : list \u03b1} (a : \u03b1) (p : l ~ l\u2081++l\u2082) :\n  a::l ~ l\u2081++(a::l\u2082) :=\n(p.cons a).trans perm_middle.symm\n\n@[simp] theorem perm_repeat {a : \u03b1} {n : \u2115} {l : list \u03b1} : l ~ repeat a n \u2194 l = repeat a n :=\n\u27e8\u03bb p, (eq_repeat.2\n  \u27e8p.length_eq.trans $ length_repeat _ _,\n   \u03bb b m, eq_of_mem_repeat $ p.subset m\u27e9),\n \u03bb h, h \u25b8 perm.refl _\u27e9\n\n@[simp] theorem repeat_perm {a : \u03b1} {n : \u2115} {l : list \u03b1} : repeat a n ~ l \u2194 repeat a n = l :=\n(perm_comm.trans perm_repeat).trans eq_comm\n\n@[simp] theorem perm_singleton {a : \u03b1} {l : list \u03b1} : l ~ [a] \u2194 l = [a] :=\n@perm_repeat \u03b1 a 1 l\n\n@[simp] theorem singleton_perm {a : \u03b1} {l : list \u03b1} : [a] ~ l \u2194 [a] = l :=\n@repeat_perm \u03b1 a 1 l\n\ntheorem perm.eq_singleton {a : \u03b1} {l : list \u03b1} (p : l ~ [a]) : l = [a] :=\nperm_singleton.1 p\n\ntheorem perm.singleton_eq {a : \u03b1} {l : list \u03b1} (p : [a] ~ l) : [a] = l :=\np.symm.eq_singleton.symm\n\ntheorem singleton_perm_singleton {a b : \u03b1} : [a] ~ [b] \u2194 a = b :=\nby simp\n\ntheorem perm_cons_erase [decidable_eq \u03b1] {a : \u03b1} {l : list \u03b1} (h : a \u2208 l) :\n  l ~ a :: l.erase a :=\nlet \u27e8l\u2081, l\u2082, _, e\u2081, e\u2082\u27e9 := exists_erase_eq h in\ne\u2082.symm \u25b8 e\u2081.symm \u25b8 perm_middle\n\n@[elab_as_eliminator] theorem perm_induction_on\n    {P : list \u03b1 \u2192 list \u03b1 \u2192 Prop} {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082)\n    (h\u2081 : P [] [])\n    (h\u2082 : \u2200 x l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 P l\u2081 l\u2082 \u2192 P (x::l\u2081) (x::l\u2082))\n    (h\u2083 : \u2200 x y l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 P l\u2081 l\u2082 \u2192 P (y::x::l\u2081) (x::y::l\u2082))\n    (h\u2084 : \u2200 l\u2081 l\u2082 l\u2083, l\u2081 ~ l\u2082 \u2192 l\u2082 ~ l\u2083 \u2192 P l\u2081 l\u2082 \u2192 P l\u2082 l\u2083 \u2192 P l\u2081 l\u2083) :\n  P l\u2081 l\u2082 :=\nhave P_refl : \u2200 l, P l l, from\n  assume l,\n  list.rec_on l h\u2081 (\u03bb x xs ih, h\u2082 x xs xs (perm.refl xs) ih),\nperm.rec_on p h\u2081 h\u2082 (\u03bb x y l, h\u2083 x y l l (perm.refl l) (P_refl l)) h\u2084\n\n@[congr] theorem perm.filter_map (f : \u03b1 \u2192 option \u03b2) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  filter_map f l\u2081 ~ filter_map f l\u2082 :=\nbegin\n  induction p with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082,\n  { simp },\n  { simp only [filter_map], cases f x with a; simp [filter_map, IH, perm.cons] },\n  { simp only [filter_map], cases f x with a; cases f y with b; simp [filter_map, swap] },\n  { exact IH\u2081.trans IH\u2082 }\nend\n\n@[congr] theorem perm.map (f : \u03b1 \u2192 \u03b2) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  map f l\u2081 ~ map f l\u2082 :=\nfilter_map_eq_map f \u25b8 p.filter_map _\n\ntheorem perm.pmap {p : \u03b1 \u2192 Prop} (f : \u03a0 a, p a \u2192 \u03b2)\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) {H\u2081 H\u2082} : pmap f l\u2081 H\u2081 ~ pmap f l\u2082 H\u2082 :=\nbegin\n  induction p with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082,\n  { simp },\n  { simp [IH, perm.cons] },\n  { simp [swap] },\n  { refine IH\u2081.trans IH\u2082,\n    exact \u03bb a m, H\u2082 a (p\u2082.subset m) }\nend\n\ntheorem perm.filter (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  {l\u2081 l\u2082 : list \u03b1} (s : l\u2081 ~ l\u2082) : filter p l\u2081 ~ filter p l\u2082 :=\nby rw \u2190 filter_map_eq_filter; apply s.filter_map _\n\ntheorem exists_perm_sublist {l\u2081 l\u2082 l\u2082' : list \u03b1}\n  (s : l\u2081 <+ l\u2082) (p : l\u2082 ~ l\u2082') : \u2203 l\u2081' ~ l\u2081, l\u2081' <+ l\u2082' :=\nbegin\n  induction p with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082 generalizing l\u2081 s,\n  { exact \u27e8[], eq_nil_of_sublist_nil s \u25b8 perm.refl _, nil_sublist _\u27e9 },\n  { cases s with _ _ _ s l\u2081 _ _ s,\n    { exact let \u27e8l\u2081', p', s'\u27e9 := IH s in \u27e8l\u2081', p', s'.cons _ _ _\u27e9 },\n    { exact let \u27e8l\u2081', p', s'\u27e9 := IH s in \u27e8x::l\u2081', p'.cons x, s'.cons2 _ _ _\u27e9 } },\n  { cases s with _ _ _ s l\u2081 _ _ s; cases s with _ _ _ s l\u2081 _ _ s,\n    { exact \u27e8l\u2081, perm.refl _, (s.cons _ _ _).cons _ _ _\u27e9 },\n    { exact \u27e8x::l\u2081, perm.refl _, (s.cons _ _ _).cons2 _ _ _\u27e9 },\n    { exact \u27e8y::l\u2081, perm.refl _, (s.cons2 _ _ _).cons _ _ _\u27e9 },\n    { exact \u27e8x::y::l\u2081, perm.swap _ _ _, (s.cons2 _ _ _).cons2 _ _ _\u27e9 } },\n  { exact let \u27e8m\u2081, pm, sm\u27e9 := IH\u2081 s, \u27e8r\u2081, pr, sr\u27e9 := IH\u2082 sm in\n          \u27e8r\u2081, pr.trans pm, sr\u27e9 }\nend\n\ntheorem perm.sizeof_eq_sizeof [has_sizeof \u03b1] {l\u2081 l\u2082 : list \u03b1} (h : l\u2081 ~ l\u2082) :\n  l\u2081.sizeof = l\u2082.sizeof :=\nbegin\n  induction h with hd l\u2081 l\u2082 h\u2081\u2082 h_sz\u2081\u2082 a b l l\u2081 l\u2082 l\u2083 h\u2081\u2082 h\u2082\u2083 h_sz\u2081\u2082 h_sz\u2082\u2083,\n  { refl },\n  { simp only [list.sizeof, h_sz\u2081\u2082] },\n  { simp only [list.sizeof, add_left_comm] },\n  { simp only [h_sz\u2081\u2082, h_sz\u2082\u2083] }\nend\n\n\nsection rel\nopen relator\nvariables {\u03b3 : Type*} {\u03b4 : Type*} {r : \u03b1 \u2192 \u03b2 \u2192 Prop} {p : \u03b3 \u2192 \u03b4 \u2192 Prop}\n\nlocal infixr ` \u2218r ` : 80 := relation.comp\n\nlemma perm_comp_perm : (perm \u2218r perm : list \u03b1 \u2192 list \u03b1 \u2192 Prop) = perm :=\nbegin\n  funext a c, apply propext,\n  split,\n  { exact assume \u27e8b, hab, hba\u27e9, perm.trans hab hba },\n  { exact assume h, \u27e8a, perm.refl a, h\u27e9 }\nend\n\nlemma perm_comp_forall\u2082 {l u v} (hlu : perm l u) (huv : forall\u2082 r u v) : (forall\u2082 r \u2218r perm) l v :=\nbegin\n  induction hlu generalizing v,\n  case perm.nil { cases huv, exact \u27e8[], forall\u2082.nil, perm.nil\u27e9 },\n  case perm.cons : a l u hlu ih {\n    cases huv with _ b _ v hab huv',\n    rcases ih huv' with \u27e8l\u2082, h\u2081\u2082, h\u2082\u2083\u27e9,\n    exact \u27e8b::l\u2082, forall\u2082.cons hab h\u2081\u2082, h\u2082\u2083.cons _\u27e9\n  },\n  case perm.swap : a\u2081 a\u2082 l\u2081 l\u2082 h\u2082\u2083 {\n    cases h\u2082\u2083 with _ b\u2081 _ l\u2082 h\u2081 hr_\u2082\u2083,\n    cases hr_\u2082\u2083 with _ b\u2082 _ l\u2082 h\u2082 h\u2081\u2082,\n    exact \u27e8b\u2082::b\u2081::l\u2082, forall\u2082.cons h\u2082 (forall\u2082.cons h\u2081 h\u2081\u2082), perm.swap _ _ _\u27e9\n  },\n  case perm.trans : la\u2081 la\u2082 la\u2083 _ _ ih\u2081 ih\u2082 {\n    rcases ih\u2082 huv with \u27e8lb\u2082, hab\u2082, h\u2082\u2083\u27e9,\n    rcases ih\u2081 hab\u2082 with \u27e8lb\u2081, hab\u2081, h\u2081\u2082\u27e9,\n    exact \u27e8lb\u2081, hab\u2081, perm.trans h\u2081\u2082 h\u2082\u2083\u27e9\n  }\nend\n\nlemma forall\u2082_comp_perm_eq_perm_comp_forall\u2082 : forall\u2082 r \u2218r perm = perm \u2218r forall\u2082 r :=\nbegin\n  funext l\u2081 l\u2083, apply propext,\n  split,\n  { assume h, rcases h with \u27e8l\u2082, h\u2081\u2082, h\u2082\u2083\u27e9,\n    have : forall\u2082 (flip r) l\u2082 l\u2081, from h\u2081\u2082.flip ,\n    rcases perm_comp_forall\u2082 h\u2082\u2083.symm this with \u27e8l', h\u2081, h\u2082\u27e9,\n    exact \u27e8l', h\u2082.symm, h\u2081.flip\u27e9 },\n  { exact assume \u27e8l\u2082, h\u2081\u2082, h\u2082\u2083\u27e9, perm_comp_forall\u2082 h\u2081\u2082 h\u2082\u2083 }\nend\n\nlemma rel_perm_imp (hr : right_unique r) : (forall\u2082 r \u21d2 forall\u2082 r \u21d2 implies) perm perm :=\nassume a b h\u2081 c d h\u2082 h,\nhave (flip (forall\u2082 r) \u2218r (perm \u2218r forall\u2082 r)) b d, from \u27e8a, h\u2081, c, h, h\u2082\u27e9,\nhave ((flip (forall\u2082 r) \u2218r forall\u2082 r) \u2218r perm) b d,\n  by rwa [\u2190 forall\u2082_comp_perm_eq_perm_comp_forall\u2082, \u2190 relation.comp_assoc] at this,\nlet \u27e8b', \u27e8c', hbc, hcb\u27e9, hbd\u27e9 := this in\nhave b' = b, from right_unique_forall\u2082' hr hcb hbc,\nthis \u25b8 hbd\n\nlemma rel_perm (hr : bi_unique r) : (forall\u2082 r \u21d2 forall\u2082 r \u21d2 (\u2194)) perm perm :=\nassume a b hab c d hcd, iff.intro\n  (rel_perm_imp hr.2 hab hcd)\n  (rel_perm_imp (left_unique_flip hr.1) hab.flip hcd.flip)\n\nend rel\n\nsection subperm\n\n/-- `subperm l\u2081 l\u2082`, denoted `l\u2081 <+~ l\u2082`, means that `l\u2081` is a sublist of\n  a permutation of `l\u2082`. This is an analogue of `l\u2081 \u2286 l\u2082` which respects\n  multiplicities of elements, and is used for the `\u2264` relation on multisets. -/\ndef subperm (l\u2081 l\u2082 : list \u03b1) : Prop := \u2203 l ~ l\u2081, l <+ l\u2082\n\ninfix ` <+~ `:50 := subperm\n\ntheorem nil_subperm {l : list \u03b1} : [] <+~ l :=\n\u27e8[], perm.nil, by simp\u27e9\n\ntheorem perm.subperm_left {l l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l <+~ l\u2081 \u2194 l <+~ l\u2082 :=\nsuffices \u2200 {l\u2081 l\u2082 : list \u03b1}, l\u2081 ~ l\u2082 \u2192 l <+~ l\u2081 \u2192 l <+~ l\u2082,\nfrom \u27e8this p, this p.symm\u27e9,\n\u03bb l\u2081 l\u2082 p \u27e8u, pu, su\u27e9,\n  let \u27e8v, pv, sv\u27e9 := exists_perm_sublist su p in\n  \u27e8v, pv.trans pu, sv\u27e9\n\ntheorem perm.subperm_right {l\u2081 l\u2082 l : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 <+~ l \u2194 l\u2082 <+~ l :=\n\u27e8\u03bb \u27e8u, pu, su\u27e9, \u27e8u, pu.trans p, su\u27e9,\n \u03bb \u27e8u, pu, su\u27e9, \u27e8u, pu.trans p.symm, su\u27e9\u27e9\n\ntheorem sublist.subperm {l\u2081 l\u2082 : list \u03b1} (s : l\u2081 <+ l\u2082) : l\u2081 <+~ l\u2082 :=\n\u27e8l\u2081, perm.refl _, s\u27e9\n\ntheorem perm.subperm {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 <+~ l\u2082 :=\n\u27e8l\u2082, p.symm, sublist.refl _\u27e9\n\n@[refl] theorem subperm.refl (l : list \u03b1) : l <+~ l := (perm.refl _).subperm\n\n@[trans] theorem subperm.trans {l\u2081 l\u2082 l\u2083 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2082 <+~ l\u2083 \u2192 l\u2081 <+~ l\u2083\n| s \u27e8l\u2082', p\u2082, s\u2082\u27e9 :=\n  let \u27e8l\u2081', p\u2081, s\u2081\u27e9 := p\u2082.subperm_left.2 s in \u27e8l\u2081', p\u2081, s\u2081.trans s\u2082\u27e9\n\ntheorem subperm.length_le {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 length l\u2081 \u2264 length l\u2082\n| \u27e8l, p, s\u27e9 := p.length_eq \u25b8 length_le_of_sublist s\n\ntheorem subperm.perm_of_length_le {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 length l\u2082 \u2264 length l\u2081 \u2192 l\u2081 ~ l\u2082\n| \u27e8l, p, s\u27e9 h :=\n  suffices l = l\u2082, from this \u25b8 p.symm,\n  eq_of_sublist_of_length_le s $ p.symm.length_eq \u25b8 h\n\ntheorem subperm.antisymm {l\u2081 l\u2082 : list \u03b1} (h\u2081 : l\u2081 <+~ l\u2082) (h\u2082 : l\u2082 <+~ l\u2081) : l\u2081 ~ l\u2082 :=\nh\u2081.perm_of_length_le h\u2082.length_le\n\ntheorem subperm.subset {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2081 \u2286 l\u2082\n| \u27e8l, p, s\u27e9 := subset.trans p.symm.subset s.subset\n\nend subperm\n\ntheorem sublist.exists_perm_append : \u2200 {l\u2081 l\u2082 : list \u03b1}, l\u2081 <+ l\u2082 \u2192 \u2203 l, l\u2082 ~ l\u2081 ++ l\n| ._ ._ sublist.slnil            := \u27e8nil, perm.refl _\u27e9\n| ._ ._ (sublist.cons l\u2081 l\u2082 a s) :=\n  let \u27e8l, p\u27e9 := sublist.exists_perm_append s in\n  \u27e8a::l, (p.cons a).trans perm_middle.symm\u27e9\n| ._ ._ (sublist.cons2 l\u2081 l\u2082 a s) :=\n  let \u27e8l, p\u27e9 := sublist.exists_perm_append s in\n  \u27e8l, p.cons a\u27e9\n\ntheorem perm.countp_eq (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  {l\u2081 l\u2082 : list \u03b1} (s : l\u2081 ~ l\u2082) : countp p l\u2081 = countp p l\u2082 :=\nby rw [countp_eq_length_filter, countp_eq_length_filter];\n   exact (s.filter _).length_eq\n\ntheorem subperm.countp_le (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 countp p l\u2081 \u2264 countp p l\u2082\n| \u27e8l, p', s\u27e9 := p'.countp_eq p \u25b8 countp_le_of_sublist p s\n\ntheorem perm.count_eq [decidable_eq \u03b1] {l\u2081 l\u2082 : list \u03b1}\n  (p : l\u2081 ~ l\u2082) (a) : count a l\u2081 = count a l\u2082 :=\np.countp_eq _\n\ntheorem subperm.count_le [decidable_eq \u03b1] {l\u2081 l\u2082 : list \u03b1}\n  (s : l\u2081 <+~ l\u2082) (a) : count a l\u2081 \u2264 count a l\u2082 :=\ns.countp_le _\n\ntheorem perm.foldl_eq' {f : \u03b2 \u2192 \u03b1 \u2192 \u03b2} {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  (\u2200 (x \u2208 l\u2081) (y \u2208 l\u2081) z, f (f z x) y = f (f z y) x) \u2192 \u2200 b, foldl f b l\u2081 = foldl f b l\u2082 :=\nperm_induction_on p\n  (\u03bb H b, rfl)\n  (\u03bb x t\u2081 t\u2082 p r H b, r (\u03bb x hx y hy, H _ (or.inr hx) _ (or.inr hy)) _)\n  (\u03bb x y t\u2081 t\u2082 p r H b,\n    begin\n      simp only [foldl],\n      rw [H x (or.inr $ or.inl rfl) y (or.inl rfl)],\n      exact r (\u03bb x hx y hy, H _ (or.inr $ or.inr hx) _ (or.inr $ or.inr hy)) _\n    end)\n  (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 r\u2081 r\u2082 H b, eq.trans (r\u2081 H b)\n    (r\u2082 (\u03bb x hx y hy, H _ (p\u2081.symm.subset hx) _ (p\u2081.symm.subset hy)) b))\n\ntheorem perm.foldl_eq {f : \u03b2 \u2192 \u03b1 \u2192 \u03b2} {l\u2081 l\u2082 : list \u03b1} (rcomm : right_commutative f) (p : l\u2081 ~ l\u2082) :\n  \u2200 b, foldl f b l\u2081 = foldl f b l\u2082 :=\np.foldl_eq' $ \u03bb x hx y hy z, rcomm z x y\n\ntheorem perm.foldr_eq {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} {l\u2081 l\u2082 : list \u03b1} (lcomm : left_commutative f) (p : l\u2081 ~ l\u2082) :\n  \u2200 b, foldr f b l\u2081 = foldr f b l\u2082 :=\nperm_induction_on p\n  (\u03bb b, rfl)\n  (\u03bb x t\u2081 t\u2082 p r b, by simp; rw [r b])\n  (\u03bb x y t\u2081 t\u2082 p r b, by simp; rw [lcomm, r b])\n  (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 r\u2081 r\u2082 a, eq.trans (r\u2081 a) (r\u2082 a))\n\nlemma perm.rec_heq {\u03b2 : list \u03b1 \u2192 Sort*} {f : \u03a0a l, \u03b2 l \u2192 \u03b2 (a::l)} {b : \u03b2 []} {l l' : list \u03b1}\n  (hl : perm l l')\n  (f_congr : \u2200{a l l' b b'}, perm l l' \u2192 b == b' \u2192 f a l b == f a l' b')\n  (f_swap : \u2200{a a' l b}, f a (a'::l) (f a' l b) == f a' (a::l) (f a l b)) :\n  @list.rec \u03b1 \u03b2 b f l == @list.rec \u03b1 \u03b2 b f l' :=\nbegin\n  induction hl,\n  case list.perm.nil { refl },\n  case list.perm.cons : a l l' h ih { exact f_congr h ih },\n  case list.perm.swap : a a' l { exact f_swap },\n  case list.perm.trans : l\u2081 l\u2082 l\u2083 h\u2081 h\u2082 ih\u2081 ih\u2082 { exact heq.trans ih\u2081 ih\u2082 }\nend\n\nsection\nvariables {op : \u03b1 \u2192 \u03b1 \u2192 \u03b1} [is_associative \u03b1 op] [is_commutative \u03b1 op]\nlocal notation a * b := op a b\nlocal notation l <*> a := foldl op a l\n\nlemma perm.fold_op_eq {l\u2081 l\u2082 : list \u03b1} {a : \u03b1} (h : l\u2081 ~ l\u2082) : l\u2081 <*> a = l\u2082 <*> a :=\nh.foldl_eq (right_comm _ is_commutative.comm is_associative.assoc) _\nend\n\nsection comm_monoid\n\n/-- If elements of a list commute with each other, then their product does not\ndepend on the order of elements-/\n@[to_additive]\n\n\nvariable [comm_monoid \u03b1]\n\n@[to_additive]\nlemma perm.prod_eq {l\u2081 l\u2082 : list \u03b1} (h : perm l\u2081 l\u2082) : prod l\u2081 = prod l\u2082 :=\nh.fold_op_eq\n\n@[to_additive]\nlemma prod_reverse (l : list \u03b1) : prod l.reverse = prod l :=\n(reverse_perm l).prod_eq\n\nend comm_monoid\n\ntheorem perm_inv_core {a : \u03b1} {l\u2081 l\u2082 r\u2081 r\u2082 : list \u03b1} : l\u2081++a::r\u2081 ~ l\u2082++a::r\u2082 \u2192 l\u2081++r\u2081 ~ l\u2082++r\u2082 :=\nbegin\n  generalize e\u2081 : l\u2081++a::r\u2081 = s\u2081, generalize e\u2082 : l\u2082++a::r\u2082 = s\u2082,\n  intro p, revert l\u2081 l\u2082 r\u2081 r\u2082 e\u2081 e\u2082,\n  refine perm_induction_on p _ (\u03bb x t\u2081 t\u2082 p IH, _) (\u03bb x y t\u2081 t\u2082 p IH, _)\n    (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, _); intros l\u2081 l\u2082 r\u2081 r\u2082 e\u2081 e\u2082,\n  { apply (not_mem_nil a).elim, rw \u2190 e\u2081, simp },\n  { cases l\u2081 with y l\u2081; cases l\u2082 with z l\u2082;\n      dsimp at e\u2081 e\u2082; injections; subst x,\n    { substs t\u2081 t\u2082,     exact p },\n    { substs z t\u2081 t\u2082,   exact p.trans perm_middle },\n    { substs y t\u2081 t\u2082,   exact perm_middle.symm.trans p },\n    { substs z t\u2081 t\u2082,   exact (IH rfl rfl).cons y } },\n  { rcases l\u2081 with _|\u27e8y, _|\u27e8z, l\u2081\u27e9\u27e9; rcases l\u2082 with _|\u27e8u, _|\u27e8v, l\u2082\u27e9\u27e9;\n      dsimp at e\u2081 e\u2082; injections; substs x y,\n    { substs r\u2081 r\u2082,     exact p.cons a },\n    { substs r\u2081 r\u2082,     exact p.cons u },\n    { substs r\u2081 v t\u2082,   exact (p.trans perm_middle).cons u },\n    { substs r\u2081 r\u2082,     exact p.cons y },\n    { substs r\u2081 r\u2082 y u, exact p.cons a },\n    { substs r\u2081 u v t\u2082, exact ((p.trans perm_middle).cons y).trans (swap _ _ _) },\n    { substs r\u2082 z t\u2081,   exact (perm_middle.symm.trans p).cons y },\n    { substs r\u2082 y z t\u2081, exact (swap _ _ _).trans ((perm_middle.symm.trans p).cons u) },\n    { substs u v t\u2081 t\u2082, exact (IH rfl rfl).swap' _ _ } },\n  { substs t\u2081 t\u2083,\n    have : a \u2208 t\u2082 := p\u2081.subset (by simp),\n    rcases mem_split this with \u27e8l\u2082, r\u2082, e\u2082\u27e9,\n    subst t\u2082, exact (IH\u2081 rfl rfl).trans (IH\u2082 rfl rfl) }\nend\n\ntheorem perm.cons_inv {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 ~ a::l\u2082 \u2192 l\u2081 ~ l\u2082 :=\n@perm_inv_core _ _ [] [] _ _\n\n@[simp] theorem perm_cons (a : \u03b1) {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 ~ a::l\u2082 \u2194 l\u2081 ~ l\u2082 :=\n\u27e8perm.cons_inv, perm.cons a\u27e9\n\ntheorem perm_append_left_iff {l\u2081 l\u2082 : list \u03b1} : \u2200 l, l++l\u2081 ~ l++l\u2082 \u2194 l\u2081 ~ l\u2082\n| []     := iff.rfl\n| (a::l) := (perm_cons a).trans (perm_append_left_iff l)\n\ntheorem perm_append_right_iff {l\u2081 l\u2082 : list \u03b1} (l) : l\u2081++l ~ l\u2082++l \u2194 l\u2081 ~ l\u2082 :=\n\u27e8\u03bb p, (perm_append_left_iff _).1 $ perm_append_comm.trans $ p.trans perm_append_comm,\n perm.append_right _\u27e9\n\ntheorem perm_option_to_list {o\u2081 o\u2082 : option \u03b1} : o\u2081.to_list ~ o\u2082.to_list \u2194 o\u2081 = o\u2082 :=\nbegin\n  refine \u27e8\u03bb p, _, \u03bb e, e \u25b8 perm.refl _\u27e9,\n  cases o\u2081 with a; cases o\u2082 with b, {refl},\n  { cases p.length_eq },\n  { cases p.length_eq },\n  { exact option.mem_to_list.1 (p.symm.subset $ by simp) }\nend\n\ntheorem subperm_cons (a : \u03b1) {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 <+~ a::l\u2082 \u2194 l\u2081 <+~ l\u2082 :=\n\u27e8\u03bb \u27e8l, p, s\u27e9, begin\n  cases s with _ _ _ s' u _ _ s',\n  { exact (p.subperm_left.2 $ (sublist_cons _ _).subperm).trans s'.subperm },\n  { exact \u27e8u, p.cons_inv, s'\u27e9 }\nend, \u03bb \u27e8l, p, s\u27e9, \u27e8a::l, p.cons a, s.cons2 _ _ _\u27e9\u27e9\n\ntheorem cons_subperm_of_mem {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} (d\u2081 : nodup l\u2081) (h\u2081 : a \u2209 l\u2081) (h\u2082 : a \u2208 l\u2082)\n (s : l\u2081 <+~ l\u2082) : a :: l\u2081 <+~ l\u2082 :=\nbegin\n  rcases s with \u27e8l, p, s\u27e9,\n  induction s generalizing l\u2081,\n  case list.sublist.slnil { cases h\u2082 },\n  case list.sublist.cons : r\u2081 r\u2082 b s' ih {\n    simp at h\u2082,\n    cases h\u2082 with e m,\n    { subst b, exact \u27e8a::r\u2081, p.cons a, s'.cons2 _ _ _\u27e9 },\n    { rcases ih m d\u2081 h\u2081 p with \u27e8t, p', s'\u27e9, exact \u27e8t, p', s'.cons _ _ _\u27e9 } },\n  case list.sublist.cons2 : r\u2081 r\u2082 b s' ih {\n    have bm : b \u2208 l\u2081 := (p.subset $ mem_cons_self _ _),\n    have am : a \u2208 r\u2082 := h\u2082.resolve_left (\u03bb e, h\u2081 $ e.symm \u25b8 bm),\n    rcases mem_split bm with \u27e8t\u2081, t\u2082, rfl\u27e9,\n    have st : t\u2081 ++ t\u2082 <+ t\u2081 ++ b :: t\u2082 := by simp,\n    rcases ih am (nodup_of_sublist st d\u2081)\n      (mt (\u03bb x, st.subset x) h\u2081)\n      (perm.cons_inv $ p.trans perm_middle) with \u27e8t, p', s'\u27e9,\n    exact \u27e8b::t, (p'.cons b).trans $ (swap _ _ _).trans (perm_middle.symm.cons a), s'.cons2 _ _ _\u27e9 }\nend\n\ntheorem subperm_append_left {l\u2081 l\u2082 : list \u03b1} : \u2200 l, l++l\u2081 <+~ l++l\u2082 \u2194 l\u2081 <+~ l\u2082\n| []     := iff.rfl\n| (a::l) := (subperm_cons a).trans (subperm_append_left l)\n\ntheorem subperm_append_right {l\u2081 l\u2082 : list \u03b1} (l) : l\u2081++l <+~ l\u2082++l \u2194 l\u2081 <+~ l\u2082 :=\n(perm_append_comm.subperm_left.trans perm_append_comm.subperm_right).trans (subperm_append_left l)\n\ntheorem subperm.exists_of_length_lt {l\u2081 l\u2082 : list \u03b1} :\n  l\u2081 <+~ l\u2082 \u2192 length l\u2081 < length l\u2082 \u2192 \u2203 a, a :: l\u2081 <+~ l\u2082\n| \u27e8l, p, s\u27e9 h :=\n  suffices length l < length l\u2082 \u2192 \u2203 (a : \u03b1), a :: l <+~ l\u2082, from\n  (this $ p.symm.length_eq \u25b8 h).imp (\u03bb a, (p.cons a).subperm_right.1),\n  begin\n    clear subperm.exists_of_length_lt p h l\u2081, rename l\u2082 u,\n    induction s with l\u2081 l\u2082 a s IH _ _ b s IH; intro h,\n    { cases h },\n    { cases lt_or_eq_of_le (nat.le_of_lt_succ h : length l\u2081 \u2264 length l\u2082) with h h,\n      { exact (IH h).imp (\u03bb a s, s.trans (sublist_cons _ _).subperm) },\n      { exact \u27e8a, eq_of_sublist_of_length_eq s h \u25b8 subperm.refl _\u27e9 } },\n    { exact (IH $ nat.lt_of_succ_lt_succ h).imp\n        (\u03bb a s, (swap _ _ _).subperm_right.1 $ (subperm_cons _).2 s) }\n  end\n\ntheorem subperm_of_subset_nodup\n  {l\u2081 l\u2082 : list \u03b1} (d : nodup l\u2081) (H : l\u2081 \u2286 l\u2082) : l\u2081 <+~ l\u2082 :=\nbegin\n  induction d with a l\u2081' h d IH,\n  { exact \u27e8nil, perm.nil, nil_sublist _\u27e9 },\n  { cases forall_mem_cons.1 H with H\u2081 H\u2082,\n    simp at h,\n    exact cons_subperm_of_mem d h H\u2081 (IH H\u2082) }\nend\n\ntheorem perm_ext {l\u2081 l\u2082 : list \u03b1} (d\u2081 : nodup l\u2081) (d\u2082 : nodup l\u2082) :\n  l\u2081 ~ l\u2082 \u2194 \u2200a, a \u2208 l\u2081 \u2194 a \u2208 l\u2082 :=\n\u27e8\u03bb p a, p.mem_iff, \u03bb H, subperm.antisymm\n  (subperm_of_subset_nodup d\u2081 (\u03bb a, (H a).1))\n  (subperm_of_subset_nodup d\u2082 (\u03bb a, (H a).2))\u27e9\n\ntheorem nodup.sublist_ext {l\u2081 l\u2082 l : list \u03b1} (d : nodup l)\n  (s\u2081 : l\u2081 <+ l) (s\u2082 : l\u2082 <+ l) : l\u2081 ~ l\u2082 \u2194 l\u2081 = l\u2082 :=\n\u27e8\u03bb h, begin\n  induction s\u2082 with l\u2082 l a s\u2082 IH l\u2082 l a s\u2082 IH generalizing l\u2081,\n  { exact h.eq_nil },\n  { simp at d,\n    cases s\u2081 with _ _ _ s\u2081 l\u2081 _ _ s\u2081,\n    { exact IH d.2 s\u2081 h },\n    { apply d.1.elim,\n      exact subperm.subset \u27e8_, h.symm, s\u2082\u27e9 (mem_cons_self _ _) } },\n  { simp at d,\n    cases s\u2081 with _ _ _ s\u2081 l\u2081 _ _ s\u2081,\n    { apply d.1.elim,\n      exact subperm.subset \u27e8_, h, s\u2081\u27e9 (mem_cons_self _ _) },\n    { rw IH d.2 s\u2081 h.cons_inv } }\nend, \u03bb h, by rw h\u27e9\n\nsection\nvariable [decidable_eq \u03b1]\n\n-- attribute [congr]\ntheorem perm.erase (a : \u03b1) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  l\u2081.erase a ~ l\u2082.erase a :=\nif h\u2081 : a \u2208 l\u2081 then\nhave h\u2082 : a \u2208 l\u2082, from p.subset h\u2081,\nperm.cons_inv $ (perm_cons_erase h\u2081).symm.trans $ p.trans (perm_cons_erase h\u2082)\nelse\nhave h\u2082 : a \u2209 l\u2082, from mt p.mem_iff.2 h\u2081,\nby rw [erase_of_not_mem h\u2081, erase_of_not_mem h\u2082]; exact p\n\ntheorem subperm_cons_erase (a : \u03b1) (l : list \u03b1) : l <+~ a :: l.erase a :=\nbegin\n  by_cases h : a \u2208 l,\n  { exact (perm_cons_erase h).subperm },\n  { rw [erase_of_not_mem h],\n    exact (sublist_cons _ _).subperm }\nend\n\ntheorem erase_subperm (a : \u03b1) (l : list \u03b1) : l.erase a <+~ l :=\n(erase_sublist _ _).subperm\n\ntheorem subperm.erase {l\u2081 l\u2082 : list \u03b1} (a : \u03b1) (h : l\u2081 <+~ l\u2082) : l\u2081.erase a <+~ l\u2082.erase a :=\nlet \u27e8l, hp, hs\u27e9 := h in \u27e8l.erase a, hp.erase _, hs.erase _\u27e9\n\ntheorem perm.diff_right {l\u2081 l\u2082 : list \u03b1} (t : list \u03b1) (h : l\u2081 ~ l\u2082) : l\u2081.diff t ~ l\u2082.diff t :=\nby induction t generalizing l\u2081 l\u2082 h; simp [*, perm.erase]\n\ntheorem perm.diff_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (h : t\u2081 ~ t\u2082) : l.diff t\u2081 = l.diff t\u2082 :=\nby induction h generalizing l; simp [*, perm.erase, erase_comm]\n  <|> exact (ih_1 _).trans (ih_2 _)\n\ntheorem perm.diff {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (hl : l\u2081 ~ l\u2082) (ht : t\u2081 ~ t\u2082) :\n  l\u2081.diff t\u2081 ~ l\u2082.diff t\u2082 :=\nht.diff_left l\u2082 \u25b8 hl.diff_right _\n\ntheorem subperm.diff_right {l\u2081 l\u2082 : list \u03b1} (h : l\u2081 <+~ l\u2082) (t : list \u03b1) :\n  l\u2081.diff t <+~ l\u2082.diff t :=\nby induction t generalizing l\u2081 l\u2082 h; simp [*, subperm.erase]\n\ntheorem erase_cons_subperm_cons_erase (a b : \u03b1) (l : list \u03b1) :\n  (a :: l).erase b <+~ a :: l.erase b :=\nbegin\n  by_cases h : a = b,\n  { subst b,\n    rw [erase_cons_head],\n    apply subperm_cons_erase },\n  { rw [erase_cons_tail _ h] }\nend\n\ntheorem subperm_cons_diff {a : \u03b1} : \u2200 {l\u2081 l\u2082 : list \u03b1}, (a :: l\u2081).diff l\u2082 <+~ a :: l\u2081.diff l\u2082\n| l\u2081 []      := \u27e8a::l\u2081, by simp\u27e9\n| l\u2081 (b::l\u2082) :=\nbegin\n  simp only [diff_cons],\n  refine ((erase_cons_subperm_cons_erase a b l\u2081).diff_right l\u2082).trans _,\n  apply subperm_cons_diff\nend\n\ntheorem subset_cons_diff {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} : (a :: l\u2081).diff l\u2082 \u2286 a :: l\u2081.diff l\u2082 :=\nsubperm_cons_diff.subset\n\ntheorem perm.bag_inter_right {l\u2081 l\u2082 : list \u03b1} (t : list \u03b1) (h : l\u2081 ~ l\u2082) :\n  l\u2081.bag_inter t ~ l\u2082.bag_inter t :=\nbegin\n  induction h with x _ _ _ _ x y _ _ _ _ _ _ ih_1 ih_2 generalizing t, {simp},\n  { by_cases x \u2208 t; simp [*, perm.cons] },\n  { by_cases x = y, {simp [h]},\n    by_cases xt : x \u2208 t; by_cases yt : y \u2208 t,\n    { simp [xt, yt, mem_erase_of_ne h, mem_erase_of_ne (ne.symm h), erase_comm, swap] },\n    { simp [xt, yt, mt mem_of_mem_erase, perm.cons] },\n    { simp [xt, yt, mt mem_of_mem_erase, perm.cons] },\n    { simp [xt, yt] } },\n  { exact (ih_1 _).trans (ih_2 _) }\nend\n\ntheorem perm.bag_inter_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (p : t\u2081 ~ t\u2082) :\n  l.bag_inter t\u2081 = l.bag_inter t\u2082 :=\nbegin\n  induction l with a l IH generalizing t\u2081 t\u2082 p, {simp},\n  by_cases a \u2208 t\u2081,\n  { simp [h, p.subset h, IH (p.erase _)] },\n  { simp [h, mt p.mem_iff.2 h, IH p] }\nend\n\ntheorem perm.bag_inter {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (hl : l\u2081 ~ l\u2082) (ht : t\u2081 ~ t\u2082) :\n  l\u2081.bag_inter t\u2081 ~ l\u2082.bag_inter t\u2082 :=\nht.bag_inter_left l\u2082 \u25b8 hl.bag_inter_right _\n\ntheorem cons_perm_iff_perm_erase {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 ~ l\u2082 \u2194 a \u2208 l\u2082 \u2227 l\u2081 ~ l\u2082.erase a :=\n\u27e8\u03bb h, have a \u2208 l\u2082, from h.subset (mem_cons_self a l\u2081),\n      \u27e8this, (h.trans $ perm_cons_erase this).cons_inv\u27e9,\n \u03bb \u27e8m, h\u27e9, (h.cons a).trans (perm_cons_erase m).symm\u27e9\n\ntheorem perm_iff_count {l\u2081 l\u2082 : list \u03b1} : l\u2081 ~ l\u2082 \u2194 \u2200 a, count a l\u2081 = count a l\u2082 :=\n\u27e8perm.count_eq, \u03bb H, begin\n  induction l\u2081 with a l\u2081 IH generalizing l\u2082,\n  { cases l\u2082 with b l\u2082, {refl},\n    specialize H b, simp at H, contradiction },\n  { have : a \u2208 l\u2082 := count_pos.1 (by rw \u2190 H; simp; apply nat.succ_pos),\n    refine ((IH $ \u03bb b, _).cons a).trans (perm_cons_erase this).symm,\n    specialize H b,\n    rw (perm_cons_erase this).count_eq at H,\n    by_cases b = a; simp [h] at H \u22a2; assumption }\nend\u27e9\n\ninstance decidable_perm : \u2200 (l\u2081 l\u2082 : list \u03b1), decidable (l\u2081 ~ l\u2082)\n| []      []      := is_true $ perm.refl _\n| []      (b::l\u2082) := is_false $ \u03bb h, by have := h.nil_eq; contradiction\n| (a::l\u2081) l\u2082      := by haveI := decidable_perm l\u2081 (l\u2082.erase a);\n                        exact decidable_of_iff' _ cons_perm_iff_perm_erase\n\n-- @[congr]\ntheorem perm.erase_dup {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  erase_dup l\u2081 ~ erase_dup l\u2082 :=\nperm_iff_count.2 $ \u03bb a,\nif h : a \u2208 l\u2081\nthen by simp [nodup_erase_dup, h, p.subset h]\nelse by simp [h, mt p.mem_iff.2 h]\n\n-- attribute [congr]\ntheorem perm.insert (a : \u03b1)\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : insert a l\u2081 ~ insert a l\u2082 :=\nif h : a \u2208 l\u2081\nthen by simpa [h, p.subset h] using p\nelse by simpa [h, mt p.mem_iff.2 h] using p.cons a\n\ntheorem perm_insert_swap (x y : \u03b1) (l : list \u03b1) :\n  insert x (insert y l) ~ insert y (insert x l) :=\nbegin\n  by_cases xl : x \u2208 l; by_cases yl : y \u2208 l; simp [xl, yl],\n  by_cases xy : x = y, { simp [xy] },\n  simp [not_mem_cons_of_ne_of_not_mem xy xl,\n        not_mem_cons_of_ne_of_not_mem (ne.symm xy) yl],\n  constructor\nend\n\ntheorem perm_insert_nth {\u03b1} (x : \u03b1) (l : list \u03b1) {n} (h : n \u2264 l.length) :\n  insert_nth n x l ~ x :: l :=\nbegin\n  induction l generalizing n,\n  { cases n, refl, cases h },\n  cases n,\n  { simp [insert_nth] },\n  { simp only [insert_nth, modify_nth_tail],\n    transitivity,\n    { apply perm.cons, apply l_ih,\n      apply nat.le_of_succ_le_succ h },\n    { apply perm.swap } }\nend\n\ntheorem perm.union_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b1) (h : l\u2081 ~ l\u2082) : l\u2081 \u222a t\u2081 ~ l\u2082 \u222a t\u2081 :=\nbegin\n  induction h with a _ _ _ ih _ _ _ _ _ _ _ _ ih_1 ih_2; try {simp},\n  { exact ih.insert a },\n  { apply perm_insert_swap },\n  { exact ih_1.trans ih_2 }\nend\n\ntheorem perm.union_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (h : t\u2081 ~ t\u2082) : l \u222a t\u2081 ~ l \u222a t\u2082 :=\nby induction l; simp [*, perm.insert]\n\n-- @[congr]\ntheorem perm.union {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081 \u222a t\u2081 ~ l\u2082 \u222a t\u2082 :=\n(p\u2081.union_right t\u2081).trans (p\u2082.union_left l\u2082)\n\ntheorem perm.inter_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b1) : l\u2081 ~ l\u2082 \u2192 l\u2081 \u2229 t\u2081 ~ l\u2082 \u2229 t\u2081 :=\nperm.filter _\n\ntheorem perm.inter_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (p : t\u2081 ~ t\u2082) : l \u2229 t\u2081 = l \u2229 t\u2082 :=\nby { dsimp [(\u2229), list.inter], congr, funext a, rw [p.mem_iff] }\n\n-- @[congr]\ntheorem perm.inter {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081 \u2229 t\u2081 ~ l\u2082 \u2229 t\u2082 :=\np\u2082.inter_left l\u2082 \u25b8 p\u2081.inter_right t\u2081\n\ntheorem perm.inter_append {l t\u2081 t\u2082 : list \u03b1} (h : disjoint t\u2081 t\u2082) :\n  l \u2229 (t\u2081 ++ t\u2082) ~ l \u2229 t\u2081 ++ l \u2229 t\u2082 :=\nbegin\n  induction l,\n  case list.nil\n  { simp },\n  case list.cons : x xs l_ih\n  { by_cases h\u2081 : x \u2208 t\u2081,\n    { have h\u2082 : x \u2209 t\u2082 := h h\u2081,\n      simp * },\n    by_cases h\u2082 : x \u2208 t\u2082,\n    { simp only [*, inter_cons_of_not_mem, false_or, mem_append, inter_cons_of_mem, not_false_iff],\n      transitivity,\n      { apply perm.cons _ l_ih, },\n      change [x] ++ xs \u2229 t\u2081 ++ xs \u2229 t\u2082 ~ xs \u2229 t\u2081 ++ ([x] ++ xs \u2229 t\u2082),\n      rw [\u2190 list.append_assoc],\n      solve_by_elim [perm.append_right, perm_append_comm] },\n    { simp * } },\nend\n\nend\n\ntheorem perm.pairwise_iff {R : \u03b1 \u2192 \u03b1 \u2192 Prop} (S : symmetric R) :\n  \u2200 {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082), pairwise R l\u2081 \u2194 pairwise R l\u2082 :=\nsuffices \u2200 {l\u2081 l\u2082}, l\u2081 ~ l\u2082 \u2192 pairwise R l\u2081 \u2192 pairwise R l\u2082, from \u03bb l\u2081 l\u2082 p, \u27e8this p, this p.symm\u27e9,\n\u03bb l\u2081 l\u2082 p d, begin\n  induction d with a l\u2081 h d IH generalizing l\u2082,\n  { rw \u2190 p.nil_eq, constructor },\n  { have : a \u2208 l\u2082 := p.subset (mem_cons_self _ _),\n    rcases mem_split this with \u27e8s\u2082, t\u2082, rfl\u27e9,\n    have p' := (p.trans perm_middle).cons_inv,\n    refine (pairwise_middle S).2 (pairwise_cons.2 \u27e8\u03bb b m, _, IH _ p'\u27e9),\n    exact h _ (p'.symm.subset m) }\nend\n\ntheorem perm.nodup_iff {l\u2081 l\u2082 : list \u03b1} : l\u2081 ~ l\u2082 \u2192 (nodup l\u2081 \u2194 nodup l\u2082) :=\nperm.pairwise_iff $ @ne.symm \u03b1\n\ntheorem perm.bind_right {l\u2081 l\u2082 : list \u03b1} (f : \u03b1 \u2192 list \u03b2) (p : l\u2081 ~ l\u2082) :\n  l\u2081.bind f ~ l\u2082.bind f :=\nbegin\n  induction p with a l\u2081 l\u2082 p IH a b l l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, {simp},\n  { simp, exact IH.append_left _ },\n  { simp, rw [\u2190 append_assoc, \u2190 append_assoc], exact perm_append_comm.append_right _ },\n  { exact IH\u2081.trans IH\u2082 }\nend\n\ntheorem perm.bind_left (l : list \u03b1) {f g : \u03b1 \u2192 list \u03b2} (h : \u2200 a, f a ~ g a) :\n  l.bind f ~ l.bind g :=\nby induction l with a l IH; simp; exact (h a).append IH\n\ntheorem perm.product_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b2) (p : l\u2081 ~ l\u2082) :\n  product l\u2081 t\u2081 ~ product l\u2082 t\u2081 :=\np.bind_right _\n\ntheorem perm.product_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b2} (p : t\u2081 ~ t\u2082) :\n  product l t\u2081 ~ product l t\u2082 :=\nperm.bind_left _ $ \u03bb a, p.map _\n\n@[congr] theorem perm.product {l\u2081 l\u2082 : list \u03b1} {t\u2081 t\u2082 : list \u03b2}\n  (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : product l\u2081 t\u2081 ~ product l\u2082 t\u2082 :=\n(p\u2081.product_right t\u2081).trans (p\u2082.product_left l\u2082)\n\ntheorem sublists_cons_perm_append (a : \u03b1) (l : list \u03b1) :\n  sublists (a :: l) ~ sublists l ++ map (cons a) (sublists l) :=\nbegin\n  simp only [sublists, sublists_aux_cons_cons, cons_append, perm_cons],\n  refine (perm.cons _ _).trans perm_middle.symm,\n  induction sublists_aux l cons with b l IH; simp,\n  exact (IH.cons _).trans perm_middle.symm\nend\n\ntheorem sublists_perm_sublists' : \u2200 l : list \u03b1, sublists l ~ sublists' l\n| []     := perm.refl _\n| (a::l) := let IH := sublists_perm_sublists' l in\n  by rw sublists'_cons; exact\n  (sublists_cons_perm_append _ _).trans (IH.append (IH.map _))\n\ntheorem revzip_sublists (l : list \u03b1) :\n  \u2200 l\u2081 l\u2082, (l\u2081, l\u2082) \u2208 revzip l.sublists \u2192 l\u2081 ++ l\u2082 ~ l :=\nbegin\n  rw revzip,\n  apply list.reverse_rec_on l,\n  { intros l\u2081 l\u2082 h, simp at h, simp [h] },\n  { intros l a IH l\u2081 l\u2082 h,\n    rw [sublists_concat, reverse_append, zip_append, \u2190 map_reverse,\n        zip_map_right, zip_map_left] at h; [skip, {simp}],\n    simp only [prod.mk.inj_iff, mem_map, mem_append, prod.map_mk, prod.exists] at h,\n    rcases h with \u27e8l\u2081, l\u2082', h, rfl, rfl\u27e9 | \u27e8l\u2081', l\u2082, h, rfl, rfl\u27e9,\n    { rw \u2190 append_assoc,\n      exact (IH _ _ h).append_right _ },\n    { rw append_assoc,\n      apply (perm_append_comm.append_left _).trans,\n      rw \u2190 append_assoc,\n      exact (IH _ _ h).append_right _ } }\nend\n\ntheorem revzip_sublists' (l : list \u03b1) :\n  \u2200 l\u2081 l\u2082, (l\u2081, l\u2082) \u2208 revzip l.sublists' \u2192 l\u2081 ++ l\u2082 ~ l :=\nbegin\n  rw revzip,\n  induction l with a l IH; intros l\u2081 l\u2082 h,\n  { simp at h, simp [h] },\n  { rw [sublists'_cons, reverse_append, zip_append, \u2190 map_reverse,\n        zip_map_right, zip_map_left] at h; [simp at h, simp],\n    rcases h with \u27e8l\u2081, l\u2082', h, rfl, rfl\u27e9 | \u27e8l\u2081', h, rfl\u27e9,\n    { exact perm_middle.trans ((IH _ _ h).cons _) },\n    { exact (IH _ _ h).cons _ } }\nend\n\ntheorem perm_lookmap (f : \u03b1 \u2192 option \u03b1) {l\u2081 l\u2082 : list \u03b1}\n  (H : pairwise (\u03bb a b, \u2200 (c \u2208 f a) (d \u2208 f b), a = b \u2227 c = d) l\u2081)\n  (p : l\u2081 ~ l\u2082) : lookmap f l\u2081 ~ lookmap f l\u2082 :=\nbegin\n  let F := \u03bb a b, \u2200 (c \u2208 f a) (d \u2208 f b), a = b \u2227 c = d,\n  change pairwise F l\u2081 at H,\n  induction p with a l\u2081 l\u2082 p IH a b l l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, {simp},\n  { cases h : f a,\n    { simp [h], exact IH (pairwise_cons.1 H).2 },\n    { simp [lookmap_cons_some _ _ h, p] } },\n  { cases h\u2081 : f a with c; cases h\u2082 : f b with d,\n    { simp [h\u2081, h\u2082], apply swap },\n    { simp [h\u2081, lookmap_cons_some _ _ h\u2082], apply swap },\n    { simp [lookmap_cons_some _ _ h\u2081, h\u2082], apply swap },\n    { simp [lookmap_cons_some _ _ h\u2081, lookmap_cons_some _ _ h\u2082],\n      rcases (pairwise_cons.1 H).1 _ (or.inl rfl) _ h\u2082 _ h\u2081 with \u27e8rfl, rfl\u27e9,\n      refl } },\n  { refine (IH\u2081 H).trans (IH\u2082 ((p\u2081.pairwise_iff _).1 H)),\n    exact \u03bb a b h c h\u2081 d h\u2082, (h d h\u2082 c h\u2081).imp eq.symm eq.symm }\nend\n\ntheorem perm.erasep (f : \u03b1 \u2192 Prop) [decidable_pred f] {l\u2081 l\u2082 : list \u03b1}\n  (H : pairwise (\u03bb a b, f a \u2192 f b \u2192 false) l\u2081)\n  (p : l\u2081 ~ l\u2082) : erasep f l\u2081 ~ erasep f l\u2082 :=\nbegin\n  let F := \u03bb a b, f a \u2192 f b \u2192 false,\n  change pairwise F l\u2081 at H,\n  induction p with a l\u2081 l\u2082 p IH a b l l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, {simp},\n  { by_cases h : f a,\n    { simp [h, p] },\n    { simp [h], exact IH (pairwise_cons.1 H).2 } },\n  { by_cases h\u2081 : f a; by_cases h\u2082 : f b; simp [h\u2081, h\u2082],\n    { cases (pairwise_cons.1 H).1 _ (or.inl rfl) h\u2082 h\u2081 },\n    { apply swap } },\n  { refine (IH\u2081 H).trans (IH\u2082 ((p\u2081.pairwise_iff _).1 H)),\n    exact \u03bb a b h h\u2081 h\u2082, h h\u2082 h\u2081 }\nend\n\nlemma perm.take_inter {\u03b1} [decidable_eq \u03b1] {xs ys : list \u03b1} (n : \u2115)\n  (h : xs ~ ys) (h' : ys.nodup) :\n  xs.take n ~ ys.inter (xs.take n) :=\nbegin\n  simp only [list.inter] at *,\n  induction h generalizing n,\n  case list.perm.nil : n\n  { simp only [not_mem_nil, filter_false, take_nil] },\n  case list.perm.cons : h_x h_l\u2081 h_l\u2082 h_a h_ih n\n  { cases n; simp only [mem_cons_iff, true_or, eq_self_iff_true, filter_cons_of_pos,\n                        perm_cons, take, not_mem_nil, filter_false],\n    cases h' with _ _ h\u2081 h\u2082,\n    convert h_ih h\u2082 n using 1,\n    apply filter_congr,\n    introv h, simp only [(h\u2081 x h).symm, false_or], },\n  case list.perm.swap : h_x h_y h_l n\n  { cases h' with _ _ h\u2081 h\u2082,\n    cases h\u2082 with _ _ h\u2082 h\u2083,\n    have := h\u2081 _ (or.inl rfl),\n    cases n; simp only [mem_cons_iff, not_mem_nil, filter_false, take],\n    cases n; simp only [mem_cons_iff, false_or, true_or, filter, *, nat.nat_zero_eq_zero, if_true,\n                        not_mem_nil, eq_self_iff_true, or_false, if_false, perm_cons, take],\n    { rw filter_eq_nil.2, intros, solve_by_elim [ne.symm], },\n    { convert perm.swap _ _ _, rw @filter_congr _ _ (\u2208 take n h_l),\n      { clear h\u2081, induction n generalizing h_l; simp only [not_mem_nil, filter_false, take],\n        cases h_l; simp only [mem_cons_iff, true_or, eq_self_iff_true, filter_cons_of_pos,\n                              true_and, take, not_mem_nil, filter_false, take_nil],\n        cases h\u2083 with _ _ h\u2083 h\u2084,\n        rwa [@filter_congr _ _ (\u2208 take n_n h_l_tl), n_ih],\n        { introv h, apply h\u2082 _ (or.inr h), },\n        { introv h, simp only [(h\u2083 x h).symm, false_or], }, },\n      { introv h, simp only [(h\u2082 x h).symm, (h\u2081 x (or.inr h)).symm, false_or], } } },\n  case list.perm.trans : h_l\u2081 h_l\u2082 h_l\u2083 h\u2080 h\u2081 h_ih\u2080 h_ih\u2081 n\n  { transitivity,\n    { apply h_ih\u2080, rwa h\u2081.nodup_iff },\n    { apply perm.filter _ h\u2081, } },\nend\n\nlemma perm.drop_inter {\u03b1} [decidable_eq \u03b1] {xs ys : list \u03b1} (n : \u2115)\n  (h : xs ~ ys) (h' : ys.nodup) :\n  xs.drop n ~ ys.inter (xs.drop n) :=\nbegin\n  by_cases h'' : n \u2264 xs.length,\n  { let n' := xs.length - n,\n    have h\u2080 : n = xs.length - n',\n    { dsimp [n'], rwa nat.sub_sub_self, } ,\n    have h\u2081 : n' \u2264 xs.length,\n    { apply nat.sub_le_self },\n    have h\u2082 : xs.drop n = (xs.reverse.take n').reverse,\n    { rw [reverse_take _ h\u2081, h\u2080, reverse_reverse], },\n    rw [h\u2082],\n    apply (reverse_perm _).trans,\n    rw inter_reverse,\n    apply perm.take_inter _ _ h',\n    apply (reverse_perm _).trans; assumption, },\n  { have : drop n xs = [],\n    { apply eq_nil_of_length_eq_zero,\n      rw [length_drop, nat.sub_eq_zero_iff_le],\n      apply le_of_not_ge h'' },\n    simp [this, list.inter], }\nend\n\nlemma perm.slice_inter {\u03b1} [decidable_eq \u03b1] {xs ys : list \u03b1} (n m : \u2115)\n  (h : xs ~ ys) (h' : ys.nodup) :\n  list.slice n m xs ~ ys \u2229 (list.slice n m xs) :=\nbegin\n  simp only [slice_eq],\n  have : n \u2264 n + m := nat.le_add_right _ _,\n  have := h.nodup_iff.2 h',\n  apply perm.trans _ (perm.inter_append _).symm;\n  solve_by_elim [perm.append, perm.drop_inter, perm.take_inter, disjoint_take_drop, h, h']\n      { max_depth := 7 },\nend\n\n/- enumerating permutations -/\n\nsection permutations\n\ntheorem permutations_aux2_fst (t : \u03b1) (ts : list \u03b1) (r : list \u03b2) : \u2200 (ys : list \u03b1) (f : list \u03b1 \u2192 \u03b2),\n  (permutations_aux2 t ts r ys f).1 = ys ++ ts\n| []      f := rfl\n| (y::ys) f := match _, permutations_aux2_fst ys _ : \u2200 o : list \u03b1 \u00d7 list \u03b2, o.1 = ys ++ ts \u2192\n      (permutations_aux2._match_1 t y f o).1 = y :: ys ++ ts with\n  | \u27e8_, zs\u27e9, rfl := rfl\n  end\n\n@[simp] theorem permutations_aux2_snd_nil (t : \u03b1) (ts : list \u03b1) (r : list \u03b2) (f : list \u03b1 \u2192 \u03b2) :\n  (permutations_aux2 t ts r [] f).2 = r := rfl\n\n@[simp] theorem permutations_aux2_snd_cons (t : \u03b1) (ts : list \u03b1) (r : list \u03b2) (y : \u03b1) (ys : list \u03b1)\n  (f : list \u03b1 \u2192 \u03b2) :\n  (permutations_aux2 t ts r (y::ys) f).2 = f (t :: y :: ys ++ ts) ::\n    (permutations_aux2 t ts r ys (\u03bbx : list \u03b1, f (y::x))).2 :=\nmatch _, permutations_aux2_fst t ts r _ _ : \u2200 o : list \u03b1 \u00d7 list \u03b2, o.1 = ys ++ ts \u2192\n   (permutations_aux2._match_1 t y f o).2 = f (t :: y :: ys ++ ts) :: o.2 with\n| \u27e8_, zs\u27e9, rfl := rfl\nend\n\ntheorem permutations_aux2_append (t : \u03b1) (ts : list \u03b1) (r : list \u03b2) (ys : list \u03b1) (f : list \u03b1 \u2192 \u03b2) :\n  (permutations_aux2 t ts nil ys f).2 ++ r = (permutations_aux2 t ts r ys f).2 :=\nby induction ys generalizing f; simp *\n\ntheorem mem_permutations_aux2 {t : \u03b1} {ts : list \u03b1} {ys : list \u03b1} {l l' : list \u03b1} :\n    l' \u2208 (permutations_aux2 t ts [] ys (append l)).2 \u2194\n    \u2203 l\u2081 l\u2082, l\u2082 \u2260 [] \u2227 ys = l\u2081 ++ l\u2082 \u2227 l' = l ++ l\u2081 ++ t :: l\u2082 ++ ts :=\nbegin\n  induction ys with y ys ih generalizing l,\n  { simp {contextual := tt} },\n  { rw [permutations_aux2_snd_cons, show (\u03bb (x : list \u03b1), l ++ y :: x) = append (l ++ [y]),\n        by funext; simp, mem_cons_iff, ih], split; intro h,\n    { rcases h with e | \u27e8l\u2081, l\u2082, l0, ye, _\u27e9,\n      { subst l', exact \u27e8[], y::ys, by simp\u27e9 },\n      { substs l' ys, exact \u27e8y::l\u2081, l\u2082, l0, by simp\u27e9 } },\n    { rcases h with \u27e8_ | \u27e8y', l\u2081\u27e9, l\u2082, l0, ye, rfl\u27e9,\n      { simp [ye] },\n      { simp at ye, rcases ye with \u27e8rfl, rfl\u27e9,\n        exact or.inr \u27e8l\u2081, l\u2082, l0, by simp\u27e9 } } }\nend\n\ntheorem mem_permutations_aux2' {t : \u03b1} {ts : list \u03b1} {ys : list \u03b1} {l : list \u03b1} :\n    l \u2208 (permutations_aux2 t ts [] ys id).2 \u2194\n    \u2203 l\u2081 l\u2082, l\u2082 \u2260 [] \u2227 ys = l\u2081 ++ l\u2082 \u2227 l = l\u2081 ++ t :: l\u2082 ++ ts :=\nby rw [show @id (list \u03b1) = append nil, by funext; refl]; apply mem_permutations_aux2\n\ntheorem length_permutations_aux2 (t : \u03b1) (ts : list \u03b1) (ys : list \u03b1) (f : list \u03b1 \u2192 \u03b2) :\n  length (permutations_aux2 t ts [] ys f).2 = length ys :=\nby induction ys generalizing f; simp *\n\ntheorem foldr_permutations_aux2 (t : \u03b1) (ts : list \u03b1) (r L : list (list \u03b1)) :\n  foldr (\u03bby r, (permutations_aux2 t ts r y id).2) r L =\n    L.bind (\u03bb y, (permutations_aux2 t ts [] y id).2) ++ r :=\nby induction L with l L ih; [refl, {simp [ih], rw \u2190 permutations_aux2_append}]\n\ntheorem mem_foldr_permutations_aux2 {t : \u03b1} {ts : list \u03b1} {r L : list (list \u03b1)} {l' : list \u03b1} :\n  l' \u2208 foldr (\u03bby r, (permutations_aux2 t ts r y id).2) r L \u2194 l' \u2208 r \u2228\n  \u2203 l\u2081 l\u2082, l\u2081 ++ l\u2082 \u2208 L \u2227 l\u2082 \u2260 [] \u2227 l' = l\u2081 ++ t :: l\u2082 ++ ts :=\nhave (\u2203 (a : list \u03b1), a \u2208 L \u2227\n    \u2203 (l\u2081 l\u2082 : list \u03b1), \u00acl\u2082 = nil \u2227 a = l\u2081 ++ l\u2082 \u2227 l' = l\u2081 ++ t :: (l\u2082 ++ ts)) \u2194\n    \u2203 (l\u2081 l\u2082 : list \u03b1), \u00acl\u2082 = nil \u2227 l\u2081 ++ l\u2082 \u2208 L \u2227 l' = l\u2081 ++ t :: (l\u2082 ++ ts),\nfrom \u27e8\u03bb \u27e8a, aL, l\u2081, l\u2082, l0, e, h\u27e9, \u27e8l\u2081, l\u2082, l0, e \u25b8 aL, h\u27e9,\n      \u03bb \u27e8l\u2081, l\u2082, l0, aL, h\u27e9, \u27e8_, aL, l\u2081, l\u2082, l0, rfl, h\u27e9\u27e9,\nby rw foldr_permutations_aux2; simp [mem_permutations_aux2', this,\n  or.comm, or.left_comm, or.assoc, and.comm, and.left_comm, and.assoc]\n\ntheorem length_foldr_permutations_aux2 (t : \u03b1) (ts : list \u03b1) (r L : list (list \u03b1)) :\n  length (foldr (\u03bby r, (permutations_aux2 t ts r y id).2) r L) = sum (map length L) + length r :=\nby simp [foldr_permutations_aux2, (\u2218), length_permutations_aux2]\n\ntheorem length_foldr_permutations_aux2' (t : \u03b1) (ts : list \u03b1) (r L : list (list \u03b1))\n  (n) (H : \u2200 l \u2208 L, length l = n) :\n  length (foldr (\u03bby r, (permutations_aux2 t ts r y id).2) r L) = n * length L + length r :=\nbegin\n  rw [length_foldr_permutations_aux2, (_ : sum (map length L) = n * length L)],\n  induction L with l L ih, {simp},\n  have sum_map : sum (map length L) = n * length L :=\n    ih (\u03bb l m, H l (mem_cons_of_mem _ m)),\n  have length_l : length l = n := H _ (mem_cons_self _ _),\n  simp [sum_map, length_l, mul_add, add_comm]\nend\n\ntheorem perm_of_mem_permutations_aux :\n  \u2200 {ts is l : list \u03b1}, l \u2208 permutations_aux ts is \u2192 l ~ ts ++ is :=\nbegin\n  refine permutations_aux.rec (by simp) _,\n  introv IH1 IH2 m,\n  rw [permutations_aux_cons, permutations, mem_foldr_permutations_aux2] at m,\n  rcases m with m | \u27e8l\u2081, l\u2082, m, _, e\u27e9,\n  { exact (IH1 m).trans perm_middle },\n  { subst e,\n    have p : l\u2081 ++ l\u2082 ~ is,\n    { simp [permutations] at m,\n      cases m with e m, {simp [e]},\n      exact is.append_nil \u25b8 IH2 m },\n    exact ((perm_middle.trans (p.cons _)).append_right _).trans (perm_append_comm.cons _) }\nend\n\ntheorem perm_of_mem_permutations {l\u2081 l\u2082 : list \u03b1}\n  (h : l\u2081 \u2208 permutations l\u2082) : l\u2081 ~ l\u2082 :=\n(eq_or_mem_of_mem_cons h).elim (\u03bb e, e \u25b8 perm.refl _)\n  (\u03bb m, append_nil l\u2082 \u25b8 perm_of_mem_permutations_aux m)\n\ntheorem length_permutations_aux : \u2200 ts is : list \u03b1,\n  length (permutations_aux ts is) + is.length! = (length ts + length is)! :=\nbegin\n  refine permutations_aux.rec (by simp) _,\n  intros t ts is IH1 IH2,\n  have IH2 : length (permutations_aux is nil) + 1 = is.length!,\n  { simpa using IH2 },\n  simp [-add_comm, nat.factorial, nat.add_succ, mul_comm] at IH1,\n  rw [permutations_aux_cons,\n      length_foldr_permutations_aux2' _ _ _ _ _\n        (\u03bb l m, (perm_of_mem_permutations m).length_eq),\n      permutations, length, length, IH2,\n      nat.succ_add, nat.factorial_succ, mul_comm (nat.succ _), \u2190 IH1,\n      add_comm (_*_), add_assoc, nat.mul_succ, mul_comm]\nend\n\ntheorem length_permutations (l : list \u03b1) : length (permutations l) = (length l)! :=\nlength_permutations_aux l []\n\ntheorem mem_permutations_of_perm_lemma {is l : list \u03b1}\n  (H : l ~ [] ++ is \u2192 (\u2203 ts' ~ [], l = ts' ++ is) \u2228 l \u2208 permutations_aux is [])\n  : l ~ is \u2192 l \u2208 permutations is :=\nby simpa [permutations, perm_nil] using H\n\ntheorem mem_permutations_aux_of_perm :\n  \u2200 {ts is l : list \u03b1}, l ~ is ++ ts \u2192 (\u2203 is' ~ is, l = is' ++ ts) \u2228 l \u2208 permutations_aux ts is :=\nbegin\n  refine permutations_aux.rec (by simp) _,\n  intros t ts is IH1 IH2 l p,\n  rw [permutations_aux_cons, mem_foldr_permutations_aux2],\n  rcases IH1 (p.trans perm_middle) with \u27e8is', p', e\u27e9 | m,\n  { clear p, subst e,\n    rcases mem_split (p'.symm.subset (mem_cons_self _ _)) with \u27e8l\u2081, l\u2082, e\u27e9,\n    subst is',\n    have p := (perm_middle.symm.trans p').cons_inv,\n    cases l\u2082 with a l\u2082',\n    { exact or.inl \u27e8l\u2081, by simpa using p\u27e9 },\n    { exact or.inr (or.inr \u27e8l\u2081, a::l\u2082',\n        mem_permutations_of_perm_lemma IH2 p, by simp\u27e9) } },\n  { exact or.inr (or.inl m) }\nend\n\n@[simp] theorem mem_permutations (s t : list \u03b1) : s \u2208 permutations t \u2194 s ~ t :=\n\u27e8perm_of_mem_permutations, mem_permutations_of_perm_lemma mem_permutations_aux_of_perm\u27e9\n\nend permutations\n\nend list\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/list/perm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.7306967225467795}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module order.prop_instances\n! leanprover-community/mathlib commit 6623e6af705e97002a9054c1c05a980180276fc1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.Disjoint\nimport Mathbin.Order.WithBot\n\n/-!\n\n# The order on `Prop`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nInstances on `Prop` such as `distrib_lattice`, `bounded_order`, `linear_order`.\n\n-/\n\n\n#print Prop.distribLattice /-\n/-- Propositions form a distributive lattice. -/\ninstance Prop.distribLattice : DistribLattice Prop :=\n  { Prop.partialOrder with\n    sup := Or\n    le_sup_left := @Or.inl\n    le_sup_right := @Or.inr\n    sup_le := fun a b c => Or.ndrec\n    inf := And\n    inf_le_left := @And.left\n    inf_le_right := @And.right\n    le_inf := fun a b c Hab Hac Ha => And.intro (Hab Ha) (Hac Ha)\n    le_sup_inf := fun a b c => or_and_left.2 }\n#align Prop.distrib_lattice Prop.distribLattice\n-/\n\n#print Prop.boundedOrder /-\n/-- Propositions form a bounded order. -/\ninstance Prop.boundedOrder : BoundedOrder Prop\n    where\n  top := True\n  le_top a Ha := True.intro\n  bot := False\n  bot_le := @False.elim\n#align Prop.bounded_order Prop.boundedOrder\n-/\n\n/- warning: Prop.bot_eq_false -> Prop.bot_eq_false is a dubious translation:\nlean 3 declaration is\n  Eq.{1} Prop (Bot.bot.{0} Prop (OrderBot.toHasBot.{0} Prop Prop.le (BoundedOrder.toOrderBot.{0} Prop Prop.le Prop.boundedOrder))) False\nbut is expected to have type\n  Eq.{1} Prop (Bot.bot.{0} Prop (OrderBot.toBot.{0} Prop Prop.le (BoundedOrder.toOrderBot.{0} Prop Prop.le Prop.boundedOrder))) False\nCase conversion may be inaccurate. Consider using '#align Prop.bot_eq_false Prop.bot_eq_false\u2093'. -/\ntheorem Prop.bot_eq_false : (\u22a5 : Prop) = False :=\n  rfl\n#align Prop.bot_eq_false Prop.bot_eq_false\n\n/- warning: Prop.top_eq_true -> Prop.top_eq_true is a dubious translation:\nlean 3 declaration is\n  Eq.{1} Prop (Top.top.{0} Prop (OrderTop.toHasTop.{0} Prop Prop.le (BoundedOrder.toOrderTop.{0} Prop Prop.le Prop.boundedOrder))) True\nbut is expected to have type\n  Eq.{1} Prop (Top.top.{0} Prop (OrderTop.toTop.{0} Prop Prop.le (BoundedOrder.toOrderTop.{0} Prop Prop.le Prop.boundedOrder))) True\nCase conversion may be inaccurate. Consider using '#align Prop.top_eq_true Prop.top_eq_true\u2093'. -/\ntheorem Prop.top_eq_true : (\u22a4 : Prop) = True :=\n  rfl\n#align Prop.top_eq_true Prop.top_eq_true\n\n#print Prop.le_isTotal /-\ninstance Prop.le_isTotal : IsTotal Prop (\u00b7 \u2264 \u00b7) :=\n  \u27e8fun p q => by\n    change (p \u2192 q) \u2228 (q \u2192 p)\n    tauto\u27e9\n#align Prop.le_is_total Prop.le_isTotal\n-/\n\n#print Prop.linearOrder /-\nnoncomputable instance Prop.linearOrder : LinearOrder Prop := by\n  classical exact Lattice.toLinearOrder Prop\n#align Prop.linear_order Prop.linearOrder\n-/\n\n/- warning: sup_Prop_eq -> sup_Prop_eq is a dubious translation:\nlean 3 declaration is\n  Eq.{1} (Prop -> Prop -> Prop) (Sup.sup.{0} Prop (SemilatticeSup.toHasSup.{0} Prop (Lattice.toSemilatticeSup.{0} Prop (LinearOrder.toLattice.{0} Prop Prop.linearOrder)))) Or\nbut is expected to have type\n  Eq.{1} (Prop -> Prop -> Prop) (fun (x._@.Mathlib.Order.PropInstances._hyg.236 : Prop) (x._@.Mathlib.Order.PropInstances._hyg.238 : Prop) => Sup.sup.{0} Prop (SemilatticeSup.toSup.{0} Prop (Lattice.toSemilatticeSup.{0} Prop (DistribLattice.toLattice.{0} Prop Prop.distribLattice))) x._@.Mathlib.Order.PropInstances._hyg.236 x._@.Mathlib.Order.PropInstances._hyg.238) (fun (x._@.Mathlib.Order.PropInstances._hyg.251 : Prop) (x._@.Mathlib.Order.PropInstances._hyg.253 : Prop) => Or x._@.Mathlib.Order.PropInstances._hyg.251 x._@.Mathlib.Order.PropInstances._hyg.253)\nCase conversion may be inaccurate. Consider using '#align sup_Prop_eq sup_Prop_eq\u2093'. -/\n@[simp]\ntheorem sup_Prop_eq : (\u00b7 \u2294 \u00b7) = (\u00b7 \u2228 \u00b7) :=\n  rfl\n#align sup_Prop_eq sup_Prop_eq\n\n/- warning: inf_Prop_eq -> inf_Prop_eq is a dubious translation:\nlean 3 declaration is\n  Eq.{1} (Prop -> Prop -> Prop) (Inf.inf.{0} Prop (SemilatticeInf.toHasInf.{0} Prop (Lattice.toSemilatticeInf.{0} Prop (LinearOrder.toLattice.{0} Prop Prop.linearOrder)))) And\nbut is expected to have type\n  Eq.{1} (Prop -> Prop -> Prop) (fun (x._@.Mathlib.Order.PropInstances._hyg.272 : Prop) (x._@.Mathlib.Order.PropInstances._hyg.274 : Prop) => Inf.inf.{0} Prop (Lattice.toInf.{0} Prop (DistribLattice.toLattice.{0} Prop Prop.distribLattice)) x._@.Mathlib.Order.PropInstances._hyg.272 x._@.Mathlib.Order.PropInstances._hyg.274) (fun (x._@.Mathlib.Order.PropInstances._hyg.287 : Prop) (x._@.Mathlib.Order.PropInstances._hyg.289 : Prop) => And x._@.Mathlib.Order.PropInstances._hyg.287 x._@.Mathlib.Order.PropInstances._hyg.289)\nCase conversion may be inaccurate. Consider using '#align inf_Prop_eq inf_Prop_eq\u2093'. -/\n@[simp]\ntheorem inf_Prop_eq : (\u00b7 \u2293 \u00b7) = (\u00b7 \u2227 \u00b7) :=\n  rfl\n#align inf_Prop_eq inf_Prop_eq\n\nnamespace Pi\n\nvariable {\u03b9 : Type _} {\u03b1' : \u03b9 \u2192 Type _} [\u2200 i, PartialOrder (\u03b1' i)]\n\n#print Pi.disjoint_iff /-\ntheorem disjoint_iff [\u2200 i, OrderBot (\u03b1' i)] {f g : \u2200 i, \u03b1' i} :\n    Disjoint f g \u2194 \u2200 i, Disjoint (f i) (g i) :=\n  by\n  constructor\n  \u00b7 intro h i x hf hg\n    classical\n      refine'\n        (update_le_iff.mp <|-- this line doesn't work\n              h\n              (update_le_iff.mpr \u27e8hf, fun _ _ => _\u27e9) (update_le_iff.mpr \u27e8hg, fun _ _ => _\u27e9)).1\n      \u00b7 exact \u22a5\n      \u00b7 exact bot_le\n      \u00b7 exact bot_le\n  \u00b7 intro h x hf hg i\n    apply h i (hf i) (hg i)\n#align pi.disjoint_iff Pi.disjoint_iff\n-/\n\n#print Pi.codisjoint_iff /-\ntheorem codisjoint_iff [\u2200 i, OrderTop (\u03b1' i)] {f g : \u2200 i, \u03b1' i} :\n    Codisjoint f g \u2194 \u2200 i, Codisjoint (f i) (g i) :=\n  @disjoint_iff _ (fun i => (\u03b1' i)\u1d52\u1d48) _ _ _ _\n#align pi.codisjoint_iff Pi.codisjoint_iff\n-/\n\n#print Pi.isCompl_iff /-\ntheorem isCompl_iff [\u2200 i, BoundedOrder (\u03b1' i)] {f g : \u2200 i, \u03b1' i} :\n    IsCompl f g \u2194 \u2200 i, IsCompl (f i) (g i) := by\n  simp_rw [isCompl_iff, disjoint_iff, codisjoint_iff, forall_and]\n#align pi.is_compl_iff Pi.isCompl_iff\n-/\n\nend Pi\n\n#print Prop.disjoint_iff /-\n@[simp]\ntheorem Prop.disjoint_iff {P Q : Prop} : Disjoint P Q \u2194 \u00ac(P \u2227 Q) :=\n  disjoint_iff_inf_le\n#align Prop.disjoint_iff Prop.disjoint_iff\n-/\n\n#print Prop.codisjoint_iff /-\n@[simp]\ntheorem Prop.codisjoint_iff {P Q : Prop} : Codisjoint P Q \u2194 P \u2228 Q :=\n  codisjoint_iff_le_sup.trans <| forall_const _\n#align Prop.codisjoint_iff Prop.codisjoint_iff\n-/\n\n#print Prop.isCompl_iff /-\n@[simp]\ntheorem Prop.isCompl_iff {P Q : Prop} : IsCompl P Q \u2194 \u00ac(P \u2194 Q) :=\n  by\n  rw [isCompl_iff, Prop.disjoint_iff, Prop.codisjoint_iff, not_iff]\n  classical tauto\n#align Prop.is_compl_iff Prop.isCompl_iff\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/PropInstances.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8311430394931457, "lm_q1q2_score": 0.7306967191401996}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module data.countable.defs\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Finite.Defs\n\n/-!\n# Countable types\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define a typeclass saying that a given `Sort*` is countable. See also `encodable`\nfor a version that singles out a specific encoding of elements of `\u03b1` by natural numbers.\n\nThis file also provides a few instances of this typeclass. More instances can be found in other\nfiles.\n-/\n\n\nopen Function\n\nuniverse u v\n\nvariable {\u03b1 : Sort u} {\u03b2 : Sort v}\n\n/-!\n### Definition and basic properties\n-/\n\n\n#print Countable /-\n/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`exists_injective_nat] [] -/\n/-- A type `\u03b1` is countable if there exists an injective map `\u03b1 \u2192 \u2115`. -/\n@[mk_iff countable_iff_exists_injective]\nclass Countable (\u03b1 : Sort u) : Prop where\n  exists_injective_nat : \u2203 f : \u03b1 \u2192 \u2115, Injective f\n#align countable Countable\n-/\n\ninstance : Countable \u2115 :=\n  \u27e8\u27e8id, injective_id\u27e9\u27e9\n\nexport Countable (exists_injective_nat)\n\n#print Function.Injective.countable /-\nprotected theorem Function.Injective.countable [Countable \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Injective f) :\n    Countable \u03b1 :=\n  let \u27e8g, hg\u27e9 := exists_injective_nat \u03b2\n  \u27e8\u27e8g \u2218 f, hg.comp hf\u27e9\u27e9\n#align function.injective.countable Function.Injective.countable\n-/\n\n#print Function.Surjective.countable /-\nprotected theorem Function.Surjective.countable [Countable \u03b1] {f : \u03b1 \u2192 \u03b2} (hf : Surjective f) :\n    Countable \u03b2 :=\n  (injective_surjInv hf).Countable\n#align function.surjective.countable Function.Surjective.countable\n-/\n\n#print exists_surjective_nat /-\ntheorem exists_surjective_nat (\u03b1 : Sort u) [Nonempty \u03b1] [Countable \u03b1] : \u2203 f : \u2115 \u2192 \u03b1, Surjective f :=\n  let \u27e8f, hf\u27e9 := exists_injective_nat \u03b1\n  \u27e8invFun f, invFun_surjective hf\u27e9\n#align exists_surjective_nat exists_surjective_nat\n-/\n\n#print countable_iff_exists_surjective /-\ntheorem countable_iff_exists_surjective [Nonempty \u03b1] : Countable \u03b1 \u2194 \u2203 f : \u2115 \u2192 \u03b1, Surjective f :=\n  \u27e8@exists_surjective_nat _ _, fun \u27e8f, hf\u27e9 => hf.Countable\u27e9\n#align countable_iff_exists_surjective countable_iff_exists_surjective\n-/\n\n/- warning: countable.of_equiv -> Countable.of_equiv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b2 : Sort.{u1}} (\u03b1 : Sort.{u2}) [_inst_1 : Countable.{u2} \u03b1], (Equiv.{u2, u1} \u03b1 \u03b2) -> (Countable.{u1} \u03b2)\nbut is expected to have type\n  forall {\u03b2 : Sort.{u2}} (\u03b1 : Sort.{u1}) [_inst_1 : Countable.{u1} \u03b1], (Equiv.{u1, u2} \u03b1 \u03b2) -> (Countable.{u2} \u03b2)\nCase conversion may be inaccurate. Consider using '#align countable.of_equiv Countable.of_equiv\u2093'. -/\ntheorem Countable.of_equiv (\u03b1 : Sort _) [Countable \u03b1] (e : \u03b1 \u2243 \u03b2) : Countable \u03b2 :=\n  e.symm.Injective.Countable\n#align countable.of_equiv Countable.of_equiv\n\n#print Equiv.countable_iff /-\ntheorem Equiv.countable_iff (e : \u03b1 \u2243 \u03b2) : Countable \u03b1 \u2194 Countable \u03b2 :=\n  \u27e8fun h => @Countable.of_equiv _ _ h e, fun h => @Countable.of_equiv _ _ h e.symm\u27e9\n#align equiv.countable_iff Equiv.countable_iff\n-/\n\ninstance {\u03b2 : Type v} [Countable \u03b2] : Countable (ULift.{u} \u03b2) :=\n  Countable.of_equiv _ Equiv.ulift.symm\n\n/-!\n### Operations on `Sort*`s\n-/\n\n\ninstance [Countable \u03b1] : Countable (PLift \u03b1) :=\n  Equiv.plift.Injective.Countable\n\n#print Subsingleton.to_countable /-\ninstance (priority := 100) Subsingleton.to_countable [Subsingleton \u03b1] : Countable \u03b1 :=\n  \u27e8\u27e8fun _ => 0, fun x y h => Subsingleton.elim x y\u27e9\u27e9\n#align subsingleton.to_countable Subsingleton.to_countable\n-/\n\ninstance (priority := 500) [Countable \u03b1] {p : \u03b1 \u2192 Prop} : Countable { x // p x } :=\n  Subtype.val_injective.Countable\n\ninstance {n : \u2115} : Countable (Fin n) :=\n  Function.Injective.countable (@Fin.eq_of_veq n)\n\n#print Finite.to_countable /-\ninstance (priority := 100) Finite.to_countable [Finite \u03b1] : Countable \u03b1 :=\n  let \u27e8n, \u27e8e\u27e9\u27e9 := Finite.exists_equiv_fin \u03b1\n  Countable.of_equiv _ e.symm\n#align finite.to_countable Finite.to_countable\n-/\n\ninstance : Countable PUnit.{u} :=\n  Subsingleton.to_countable\n\n#print Prop.countable /-\n-- Since this always succeeds, there is no reason not to have this at normal priority.\n-- Perhaps the `instance_priority` linter could be clever enough to notice this itself.\n@[nolint instance_priority]\ninstance Prop.countable (p : Prop) : Countable p :=\n  Subsingleton.to_countable\n#align Prop.countable Prop.countable\n-/\n\n#print Bool.countable /-\ninstance Bool.countable : Countable Bool :=\n  \u27e8\u27e8fun b => cond b 0 1, Bool.injective_iff.2 Nat.one_ne_zero\u27e9\u27e9\n#align bool.countable Bool.countable\n-/\n\n#print Prop.countable' /-\ninstance Prop.countable' : Countable Prop :=\n  Countable.of_equiv Bool Equiv.propEquivBool.symm\n#align Prop.countable' Prop.countable'\n-/\n\ninstance (priority := 500) [Countable \u03b1] {r : \u03b1 \u2192 \u03b1 \u2192 Prop} : Countable (Quot r) :=\n  (surjective_quot_mk r).Countable\n\ninstance (priority := 500) [Countable \u03b1] {s : Setoid \u03b1} : Countable (Quotient s) :=\n  Quot.countable\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Countable/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7306955744793747}}
{"text": "/-\nCopyright (c) 2022 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n\n! This file was ported from Lean 3 source module topology.uniform_space.equicontinuity\n! leanprover-community/mathlib commit ee05e9ce1322178f0c12004eb93c00d2c8c00ed2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.UniformSpace.UniformConvergenceTopology\n\n/-!\n# Equicontinuity of a family of functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nLet `X` be a topological space and `\u03b1` a `uniform_space`. A family of functions `F : \u03b9 \u2192 X \u2192 \u03b1`\nis said to be *equicontinuous at a point `x\u2080 : X`* when, for any entourage `U` in `\u03b1`, there is a\nneighborhood `V` of `x\u2080` such that, for all `x \u2208 V`, and *for all `i`*, `F i x` is `U`-close to\n`F i x\u2080`. In other words, one has `\u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200 i, (F i x\u2080, F i x) \u2208 U`.\nFor maps between metric spaces, this corresponds to\n`\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, \u2200 i, dist x\u2080 x < \u03b4 \u2192 dist (F i x\u2080) (F i x) < \u03b5`.\n\n`F` is said to be *equicontinuous* if it is equicontinuous at each point.\n\nA closely related concept is that of ***uniform*** *equicontinuity* of a family of functions\n`F : \u03b9 \u2192 \u03b2 \u2192 \u03b1` between uniform spaces, which means that, for any entourage `U` in `\u03b1`, there is an\nentourage `V` in `\u03b2` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and\n`F i y` are `U`-close. In other words, one has\n`\u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 xy in \ud835\udce4 \u03b2, \u2200 i, (F i xy.1, F i xy.2) \u2208 U`.\nFor maps between metric spaces, this corresponds to\n`\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x y, \u2200 i, dist x y < \u03b4 \u2192 dist (F i x\u2080) (F i x) < \u03b5`.\n\n## Main definitions\n\n* `equicontinuous_at`: equicontinuity of a family of functions at a point\n* `equicontinuous`: equicontinuity of a family of functions on the whole domain\n* `uniform_equicontinuous`: uniform equicontinuity of a family of functions on the whole domain\n\n## Main statements\n\n* `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity\n  condition between well-chosen function spaces. This is really useful for building up the theory.\n* `equicontinuous.closure`: if a set of functions is equicontinuous, its closure\n  *for the topology of uniform convergence* is also equicontinuous.\n\n## Notations\n\nThroughout this file, we use :\n- `\u03b9`, `\u03ba` for indexing types\n- `X`, `Y`, `Z` for topological spaces\n- `\u03b1`, `\u03b2`, `\u03b3` for uniform spaces\n\n## Implementation details\n\nWe choose to express equicontinuity as a properties of indexed families of functions rather\nthan sets of functions for the following reasons:\n- it is really easy to express equicontinuity of `H : set (X \u2192 \u03b1)` using our setup: it is just\n  equicontinuity of the family `coe : \u21a5H \u2192 (X \u2192 \u03b1)`. On the other hand, going the other way around\n  would require working with the range of the family, which is always annoying because it\n  introduces useless existentials.\n- in most applications, one doesn't work with bare functions but with a more specific hom type\n  `hom`. Equicontinuity of a set `H : set hom` would then have to be expressed as equicontinuity\n  of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families,\n  because equicontinuity of a family `\ud835\udcd5 : \u03b9 \u2192 hom` would simply be expressed as equicontinuity\n  of `coe_fn \u2218 \ud835\udcd5`, which doesn't introduce any nasty existentials.\n\nTo simplify statements, we do provide abbreviations `set.equicontinuous_at`, `set.equicontinuous`\nand `set.uniform_equicontinuous` asserting the corresponding fact about the family\n`coe : \u21a5H \u2192 (X \u2192 \u03b1)` where `H : set (X \u2192 \u03b1)`. Note however that these won't work for sets of hom\ntypes, and in that case one should go back to the family definition rather than using `set.image`.\n\nSince we have no use case for it yet, we don't introduce any relative version\n(i.e no `equicontinuous_within_at` or `equicontinuous_on`), but this is more of a conservative\nposition than a design decision, so anyone needing relative versions should feel free to add them,\nand that should hopefully be a straightforward task.\n\n## References\n\n* [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966]\n\n## Tags\n\nequicontinuity, uniform convergence, ascoli\n-/\n\n\nsection\n\nopen UniformSpace Filter Set\n\nopen uniformity Topology UniformConvergence\n\nvariable {\u03b9 \u03ba X Y Z \u03b1 \u03b2 \u03b3 \ud835\udcd5 : Type _} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z]\n  [UniformSpace \u03b1] [UniformSpace \u03b2] [UniformSpace \u03b3]\n\n#print EquicontinuousAt /-\n/-- A family `F : \u03b9 \u2192 X \u2192 \u03b1` of functions from a topological space to a uniform space is\n*equicontinuous at `x\u2080 : X`* if, for all entourage `U \u2208 \ud835\udce4 \u03b1`, there is a neighborhood `V` of `x\u2080`\nsuch that, for all `x \u2208 V` and for all `i : \u03b9`, `F i x` is `U`-close to `F i x\u2080`. -/\ndef EquicontinuousAt (F : \u03b9 \u2192 X \u2192 \u03b1) (x\u2080 : X) : Prop :=\n  \u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200 i, (F i x\u2080, F i x) \u2208 U\n#align equicontinuous_at EquicontinuousAt\n-/\n\n#print Set.EquicontinuousAt /-\n/-- We say that a set `H : set (X \u2192 \u03b1)` of functions is equicontinuous at a point if the family\n`coe : \u21a5H \u2192 (X \u2192 \u03b1)` is equicontinuous at that point. -/\nprotected abbrev Set.EquicontinuousAt (H : Set <| X \u2192 \u03b1) (x\u2080 : X) : Prop :=\n  EquicontinuousAt (coe : H \u2192 X \u2192 \u03b1) x\u2080\n#align set.equicontinuous_at Set.EquicontinuousAt\n-/\n\n#print Equicontinuous /-\n/-- A family `F : \u03b9 \u2192 X \u2192 \u03b1` of functions from a topological space to a uniform space is\n*equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/\ndef Equicontinuous (F : \u03b9 \u2192 X \u2192 \u03b1) : Prop :=\n  \u2200 x\u2080, EquicontinuousAt F x\u2080\n#align equicontinuous Equicontinuous\n-/\n\n#print Set.Equicontinuous /-\n/-- We say that a set `H : set (X \u2192 \u03b1)` of functions is equicontinuous if the family\n`coe : \u21a5H \u2192 (X \u2192 \u03b1)` is equicontinuous. -/\nprotected abbrev Set.Equicontinuous (H : Set <| X \u2192 \u03b1) : Prop :=\n  Equicontinuous (coe : H \u2192 X \u2192 \u03b1)\n#align set.equicontinuous Set.Equicontinuous\n-/\n\n#print UniformEquicontinuous /-\n/-- A family `F : \u03b9 \u2192 \u03b2 \u2192 \u03b1` of functions between uniform spaces is *uniformly equicontinuous* if,\nfor all entourage `U \u2208 \ud835\udce4 \u03b1`, there is an entourage `V \u2208 \ud835\udce4 \u03b2` such that, whenever `x` and `y` are\n`V`-close, we have that, *for all `i : \u03b9`*, `F i x` is `U`-close to `F i x\u2080`. -/\ndef UniformEquicontinuous (F : \u03b9 \u2192 \u03b2 \u2192 \u03b1) : Prop :=\n  \u2200 U \u2208 \ud835\udce4 \u03b1, \u2200\u1da0 xy : \u03b2 \u00d7 \u03b2 in \ud835\udce4 \u03b2, \u2200 i, (F i xy.1, F i xy.2) \u2208 U\n#align uniform_equicontinuous UniformEquicontinuous\n-/\n\n#print Set.UniformEquicontinuous /-\n/-- We say that a set `H : set (X \u2192 \u03b1)` of functions is uniformly equicontinuous if the family\n`coe : \u21a5H \u2192 (X \u2192 \u03b1)` is uniformly equicontinuous. -/\nprotected abbrev Set.UniformEquicontinuous (H : Set <| \u03b2 \u2192 \u03b1) : Prop :=\n  UniformEquicontinuous (coe : H \u2192 \u03b2 \u2192 \u03b1)\n#align set.uniform_equicontinuous Set.UniformEquicontinuous\n-/\n\n/- warning: equicontinuous_at_iff_pair -> equicontinuousAt_iff_pair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, Iff (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (U : Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)), (Membership.Mem.{u3, u3} (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Filter.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Filter.hasMem.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) U (uniformity.{u3} \u03b1 _inst_4)) -> (Exists.{succ u2} (Set.{u2} X) (fun (V : Set.{u2} X) => Exists.{0} (Membership.Mem.{u2, u2} (Set.{u2} X) (Filter.{u2} X) (Filter.hasMem.{u2} X) V (nhds.{u2} X _inst_1 x\u2080)) (fun (H : Membership.Mem.{u2, u2} (Set.{u2} X) (Filter.{u2} X) (Filter.hasMem.{u2} X) V (nhds.{u2} X _inst_1 x\u2080)) => forall (x : X), (Membership.Mem.{u2, u2} X (Set.{u2} X) (Set.hasMem.{u2} X) x V) -> (forall (y : X), (Membership.Mem.{u2, u2} X (Set.{u2} X) (Set.hasMem.{u2} X) y V) -> (forall (i : \u03b9), Membership.Mem.{u3, u3} (Prod.{u3, u3} \u03b1 \u03b1) (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Set.hasMem.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Prod.mk.{u3, u3} \u03b1 \u03b1 (F i x) (F i y)) U))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, Iff (EquicontinuousAt.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (U : Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)), (Membership.mem.{u1, u1} (Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Filter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (instMembershipSetFilter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) U (uniformity.{u1} \u03b1 _inst_4)) -> (Exists.{succ u2} (Set.{u2} X) (fun (V : Set.{u2} X) => And (Membership.mem.{u2, u2} (Set.{u2} X) (Filter.{u2} X) (instMembershipSetFilter.{u2} X) V (nhds.{u2} X _inst_1 x\u2080)) (forall (x : X), (Membership.mem.{u2, u2} X (Set.{u2} X) (Set.instMembershipSet.{u2} X) x V) -> (forall (y : X), (Membership.mem.{u2, u2} X (Set.{u2} X) (Set.instMembershipSet.{u2} X) y V) -> (forall (i : \u03b9), Membership.mem.{u1, u1} (Prod.{u1, u1} \u03b1 \u03b1) (Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Set.instMembershipSet.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Prod.mk.{u1, u1} \u03b1 \u03b1 (F i x) (F i y)) U))))))\nCase conversion may be inaccurate. Consider using '#align equicontinuous_at_iff_pair equicontinuousAt_iff_pair\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (x y \u00abexpr \u2208 \u00bb V) -/\n/-- Reformulation of equicontinuity at `x\u2080` comparing two variables near `x\u2080` instead of comparing\nonly one with `x\u2080`. -/\ntheorem equicontinuousAt_iff_pair {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} :\n    EquicontinuousAt F x\u2080 \u2194\n      \u2200 U \u2208 \ud835\udce4 \u03b1, \u2203 V \u2208 \ud835\udcdd x\u2080, \u2200 (x) (_ : x \u2208 V) (y) (_ : y \u2208 V) (i), (F i x, F i y) \u2208 U :=\n  by\n  constructor <;> intro H U hU\n  \u00b7 rcases comp_symm_mem_uniformity_sets hU with \u27e8V, hV, hVsymm, hVU\u27e9\n    refine' \u27e8_, H V hV, fun x hx y hy i => hVU (prod_mk_mem_compRel _ (hy i))\u27e9\n    exact hVsymm.mk_mem_comm.mp (hx i)\n  \u00b7 rcases H U hU with \u27e8V, hV, hVU\u27e9\n    filter_upwards [hV]using fun x hx i => hVU x\u2080 (mem_of_mem_nhds hV) x hx i\n#align equicontinuous_at_iff_pair equicontinuousAt_iff_pair\n\n/- warning: uniform_equicontinuous.equicontinuous -> UniformEquicontinuous.equicontinuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (Equicontinuous.{u1, u3, u2} \u03b9 \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_5) _inst_4 F)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u3, u2, u1} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (Equicontinuous.{u3, u1, u2} \u03b9 \u03b2 \u03b1 (UniformSpace.toTopologicalSpace.{u1} \u03b2 _inst_5) _inst_4 F)\nCase conversion may be inaccurate. Consider using '#align uniform_equicontinuous.equicontinuous UniformEquicontinuous.equicontinuous\u2093'. -/\n/-- Uniform equicontinuity implies equicontinuity. -/\ntheorem UniformEquicontinuous.equicontinuous {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h : UniformEquicontinuous F) :\n    Equicontinuous F := fun x\u2080 U hU =>\n  mem_of_superset (ball_mem_nhds x\u2080 (h U hU)) fun x hx i => hx i\n#align uniform_equicontinuous.equicontinuous UniformEquicontinuous.equicontinuous\n\n/- warning: equicontinuous_at.continuous_at -> EquicontinuousAt.continuousAt is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) -> (forall (i : \u03b9), ContinuousAt.{u2, u3} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4) (F i) x\u2080)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (EquicontinuousAt.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) -> (forall (i : \u03b9), ContinuousAt.{u2, u1} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4) (F i) x\u2080)\nCase conversion may be inaccurate. Consider using '#align equicontinuous_at.continuous_at EquicontinuousAt.continuousAt\u2093'. -/\n/-- Each function of a family equicontinuous at `x\u2080` is continuous at `x\u2080`. -/\ntheorem EquicontinuousAt.continuousAt {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (h : EquicontinuousAt F x\u2080) (i : \u03b9) :\n    ContinuousAt (F i) x\u2080 := by\n  intro U hU\n  rw [UniformSpace.mem_nhds_iff] at hU\n  rcases hU with \u27e8V, hV\u2081, hV\u2082\u27e9\n  exact mem_map.mpr (mem_of_superset (h V hV\u2081) fun x hx => hV\u2082 (hx i))\n#align equicontinuous_at.continuous_at EquicontinuousAt.continuousAt\n\n/- warning: set.equicontinuous_at.continuous_at_of_mem -> Set.EquicontinuousAt.continuousAt_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u2} \u03b1] {H : Set.{max u1 u2} (X -> \u03b1)} {x\u2080 : X}, (Set.EquicontinuousAt.{u1, u2} X \u03b1 _inst_1 _inst_4 H x\u2080) -> (forall {f : X -> \u03b1}, (Membership.Mem.{max u1 u2, max u1 u2} (X -> \u03b1) (Set.{max u1 u2} (X -> \u03b1)) (Set.hasMem.{max u1 u2} (X -> \u03b1)) f H) -> (ContinuousAt.{u1, u2} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4) f x\u2080))\nbut is expected to have type\n  forall {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {H : Set.{max u2 u1} (X -> \u03b1)} {x\u2080 : X}, (Set.EquicontinuousAt.{u2, u1} X \u03b1 _inst_1 _inst_4 H x\u2080) -> (forall {f : X -> \u03b1}, (Membership.mem.{max u2 u1, max u2 u1} (X -> \u03b1) (Set.{max u2 u1} (X -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (X -> \u03b1)) f H) -> (ContinuousAt.{u2, u1} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4) f x\u2080))\nCase conversion may be inaccurate. Consider using '#align set.equicontinuous_at.continuous_at_of_mem Set.EquicontinuousAt.continuousAt_of_mem\u2093'. -/\nprotected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X \u2192 \u03b1} {x\u2080 : X}\n    (h : H.EquicontinuousAt x\u2080) {f : X \u2192 \u03b1} (hf : f \u2208 H) : ContinuousAt f x\u2080 :=\n  h.ContinuousAt \u27e8f, hf\u27e9\n#align set.equicontinuous_at.continuous_at_of_mem Set.EquicontinuousAt.continuousAt_of_mem\n\n/- warning: equicontinuous.continuous -> Equicontinuous.continuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {F : \u03b9 -> X -> \u03b1}, (Equicontinuous.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F) -> (forall (i : \u03b9), Continuous.{u2, u3} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4) (F i))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {F : \u03b9 -> X -> \u03b1}, (Equicontinuous.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F) -> (forall (i : \u03b9), Continuous.{u2, u1} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4) (F i))\nCase conversion may be inaccurate. Consider using '#align equicontinuous.continuous Equicontinuous.continuous\u2093'. -/\n/-- Each function of an equicontinuous family is continuous. -/\ntheorem Equicontinuous.continuous {F : \u03b9 \u2192 X \u2192 \u03b1} (h : Equicontinuous F) (i : \u03b9) :\n    Continuous (F i) :=\n  continuous_iff_continuousAt.mpr fun x => (h x).ContinuousAt i\n#align equicontinuous.continuous Equicontinuous.continuous\n\n/- warning: set.equicontinuous.continuous_of_mem -> Set.Equicontinuous.continuous_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u2} \u03b1] {H : Set.{max u1 u2} (X -> \u03b1)}, (Set.Equicontinuous.{u1, u2} X \u03b1 _inst_1 _inst_4 H) -> (forall {f : X -> \u03b1}, (Membership.Mem.{max u1 u2, max u1 u2} (X -> \u03b1) (Set.{max u1 u2} (X -> \u03b1)) (Set.hasMem.{max u1 u2} (X -> \u03b1)) f H) -> (Continuous.{u1, u2} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4) f))\nbut is expected to have type\n  forall {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {H : Set.{max u2 u1} (X -> \u03b1)}, (Set.Equicontinuous.{u2, u1} X \u03b1 _inst_1 _inst_4 H) -> (forall {f : X -> \u03b1}, (Membership.mem.{max u2 u1, max u2 u1} (X -> \u03b1) (Set.{max u2 u1} (X -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (X -> \u03b1)) f H) -> (Continuous.{u2, u1} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4) f))\nCase conversion may be inaccurate. Consider using '#align set.equicontinuous.continuous_of_mem Set.Equicontinuous.continuous_of_mem\u2093'. -/\nprotected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X \u2192 \u03b1} (h : H.Equicontinuous)\n    {f : X \u2192 \u03b1} (hf : f \u2208 H) : Continuous f :=\n  h.Continuous \u27e8f, hf\u27e9\n#align set.equicontinuous.continuous_of_mem Set.Equicontinuous.continuous_of_mem\n\n/- warning: uniform_equicontinuous.uniform_continuous -> UniformEquicontinuous.uniformContinuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (forall (i : \u03b9), UniformContinuous.{u3, u2} \u03b2 \u03b1 _inst_5 _inst_4 (F i))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u3, u2, u1} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (forall (i : \u03b9), UniformContinuous.{u1, u2} \u03b2 \u03b1 _inst_5 _inst_4 (F i))\nCase conversion may be inaccurate. Consider using '#align uniform_equicontinuous.uniform_continuous UniformEquicontinuous.uniformContinuous\u2093'. -/\n/-- Each function of a uniformly equicontinuous family is uniformly continuous. -/\ntheorem UniformEquicontinuous.uniformContinuous {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h : UniformEquicontinuous F)\n    (i : \u03b9) : UniformContinuous (F i) := fun U hU =>\n  mem_map.mpr (mem_of_superset (h U hU) fun xy hxy => hxy i)\n#align uniform_equicontinuous.uniform_continuous UniformEquicontinuous.uniformContinuous\n\n/- warning: set.uniform_equicontinuous.uniform_continuous_of_mem -> Set.UniformEquicontinuous.uniformContinuous_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : UniformSpace.{u1} \u03b1] [_inst_5 : UniformSpace.{u2} \u03b2] {H : Set.{max u2 u1} (\u03b2 -> \u03b1)}, (Set.UniformEquicontinuous.{u1, u2} \u03b1 \u03b2 _inst_4 _inst_5 H) -> (forall {f : \u03b2 -> \u03b1}, (Membership.Mem.{max u2 u1, max u2 u1} (\u03b2 -> \u03b1) (Set.{max u2 u1} (\u03b2 -> \u03b1)) (Set.hasMem.{max u2 u1} (\u03b2 -> \u03b1)) f H) -> (UniformContinuous.{u2, u1} \u03b2 \u03b1 _inst_5 _inst_4 f))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {H : Set.{max u2 u1} (\u03b2 -> \u03b1)}, (Set.UniformEquicontinuous.{u2, u1} \u03b1 \u03b2 _inst_4 _inst_5 H) -> (forall {f : \u03b2 -> \u03b1}, (Membership.mem.{max u2 u1, max u2 u1} (\u03b2 -> \u03b1) (Set.{max u2 u1} (\u03b2 -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (\u03b2 -> \u03b1)) f H) -> (UniformContinuous.{u1, u2} \u03b2 \u03b1 _inst_5 _inst_4 f))\nCase conversion may be inaccurate. Consider using '#align set.uniform_equicontinuous.uniform_continuous_of_mem Set.UniformEquicontinuous.uniformContinuous_of_mem\u2093'. -/\nprotected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| \u03b2 \u2192 \u03b1}\n    (h : H.UniformEquicontinuous) {f : \u03b2 \u2192 \u03b1} (hf : f \u2208 H) : UniformContinuous f :=\n  h.UniformContinuous \u27e8f, hf\u27e9\n#align set.uniform_equicontinuous.uniform_continuous_of_mem Set.UniformEquicontinuous.uniformContinuous_of_mem\n\n/- warning: equicontinuous_at.comp -> EquicontinuousAt.comp is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03ba : Type.{u2}} {X : Type.{u3}} {\u03b1 : Type.{u4}} [_inst_1 : TopologicalSpace.{u3} X] [_inst_4 : UniformSpace.{u4} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (EquicontinuousAt.{u1, u3, u4} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) -> (forall (u : \u03ba -> \u03b9), EquicontinuousAt.{u2, u3, u4} \u03ba X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u2, succ u1, max (succ u3) (succ u4)} \u03ba \u03b9 (X -> \u03b1) F u) x\u2080)\nbut is expected to have type\n  forall {\u03b9 : Type.{u4}} {\u03ba : Type.{u1}} {X : Type.{u3}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u3} X] [_inst_4 : UniformSpace.{u2} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (EquicontinuousAt.{u4, u3, u2} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) -> (forall (u : \u03ba -> \u03b9), EquicontinuousAt.{u1, u3, u2} \u03ba X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u1, succ u4, max (succ u2) (succ u3)} \u03ba \u03b9 (X -> \u03b1) F u) x\u2080)\nCase conversion may be inaccurate. Consider using '#align equicontinuous_at.comp EquicontinuousAt.comp\u2093'. -/\n/-- Taking sub-families preserves equicontinuity at a point. -/\ntheorem EquicontinuousAt.comp {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (h : EquicontinuousAt F x\u2080) (u : \u03ba \u2192 \u03b9) :\n    EquicontinuousAt (F \u2218 u) x\u2080 := fun U hU => (h U hU).mono fun x H k => H (u k)\n#align equicontinuous_at.comp EquicontinuousAt.comp\n\n/- warning: set.equicontinuous_at.mono -> Set.EquicontinuousAt.mono is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u2} \u03b1] {H : Set.{max u1 u2} (X -> \u03b1)} {H' : Set.{max u1 u2} (X -> \u03b1)} {x\u2080 : X}, (Set.EquicontinuousAt.{u1, u2} X \u03b1 _inst_1 _inst_4 H x\u2080) -> (HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (X -> \u03b1)) (Set.hasSubset.{max u1 u2} (X -> \u03b1)) H' H) -> (Set.EquicontinuousAt.{u1, u2} X \u03b1 _inst_1 _inst_4 H' x\u2080)\nbut is expected to have type\n  forall {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {H : Set.{max u2 u1} (X -> \u03b1)} {H' : Set.{max u2 u1} (X -> \u03b1)} {x\u2080 : X}, (Set.EquicontinuousAt.{u2, u1} X \u03b1 _inst_1 _inst_4 H x\u2080) -> (HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (X -> \u03b1)) (Set.instHasSubsetSet.{max u2 u1} (X -> \u03b1)) H' H) -> (Set.EquicontinuousAt.{u2, u1} X \u03b1 _inst_1 _inst_4 H' x\u2080)\nCase conversion may be inaccurate. Consider using '#align set.equicontinuous_at.mono Set.EquicontinuousAt.mono\u2093'. -/\nprotected theorem Set.EquicontinuousAt.mono {H H' : Set <| X \u2192 \u03b1} {x\u2080 : X}\n    (h : H.EquicontinuousAt x\u2080) (hH : H' \u2286 H) : H'.EquicontinuousAt x\u2080 :=\n  h.comp (inclusion hH)\n#align set.equicontinuous_at.mono Set.EquicontinuousAt.mono\n\n/- warning: equicontinuous.comp -> Equicontinuous.comp is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03ba : Type.{u2}} {X : Type.{u3}} {\u03b1 : Type.{u4}} [_inst_1 : TopologicalSpace.{u3} X] [_inst_4 : UniformSpace.{u4} \u03b1] {F : \u03b9 -> X -> \u03b1}, (Equicontinuous.{u1, u3, u4} \u03b9 X \u03b1 _inst_1 _inst_4 F) -> (forall (u : \u03ba -> \u03b9), Equicontinuous.{u2, u3, u4} \u03ba X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u2, succ u1, max (succ u3) (succ u4)} \u03ba \u03b9 (X -> \u03b1) F u))\nbut is expected to have type\n  forall {\u03b9 : Type.{u4}} {\u03ba : Type.{u1}} {X : Type.{u3}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u3} X] [_inst_4 : UniformSpace.{u2} \u03b1] {F : \u03b9 -> X -> \u03b1}, (Equicontinuous.{u4, u3, u2} \u03b9 X \u03b1 _inst_1 _inst_4 F) -> (forall (u : \u03ba -> \u03b9), Equicontinuous.{u1, u3, u2} \u03ba X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u1, succ u4, max (succ u2) (succ u3)} \u03ba \u03b9 (X -> \u03b1) F u))\nCase conversion may be inaccurate. Consider using '#align equicontinuous.comp Equicontinuous.comp\u2093'. -/\n/-- Taking sub-families preserves equicontinuity. -/\ntheorem Equicontinuous.comp {F : \u03b9 \u2192 X \u2192 \u03b1} (h : Equicontinuous F) (u : \u03ba \u2192 \u03b9) :\n    Equicontinuous (F \u2218 u) := fun x => (h x).comp u\n#align equicontinuous.comp Equicontinuous.comp\n\n/- warning: set.equicontinuous.mono -> Set.Equicontinuous.mono is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u2} \u03b1] {H : Set.{max u1 u2} (X -> \u03b1)} {H' : Set.{max u1 u2} (X -> \u03b1)}, (Set.Equicontinuous.{u1, u2} X \u03b1 _inst_1 _inst_4 H) -> (HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (X -> \u03b1)) (Set.hasSubset.{max u1 u2} (X -> \u03b1)) H' H) -> (Set.Equicontinuous.{u1, u2} X \u03b1 _inst_1 _inst_4 H')\nbut is expected to have type\n  forall {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {H : Set.{max u2 u1} (X -> \u03b1)} {H' : Set.{max u2 u1} (X -> \u03b1)}, (Set.Equicontinuous.{u2, u1} X \u03b1 _inst_1 _inst_4 H) -> (HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (X -> \u03b1)) (Set.instHasSubsetSet.{max u2 u1} (X -> \u03b1)) H' H) -> (Set.Equicontinuous.{u2, u1} X \u03b1 _inst_1 _inst_4 H')\nCase conversion may be inaccurate. Consider using '#align set.equicontinuous.mono Set.Equicontinuous.mono\u2093'. -/\nprotected theorem Set.Equicontinuous.mono {H H' : Set <| X \u2192 \u03b1} (h : H.Equicontinuous)\n    (hH : H' \u2286 H) : H'.Equicontinuous :=\n  h.comp (inclusion hH)\n#align set.equicontinuous.mono Set.Equicontinuous.mono\n\n/- warning: uniform_equicontinuous.comp -> UniformEquicontinuous.comp is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03ba : Type.{u2}} {\u03b1 : Type.{u3}} {\u03b2 : Type.{u4}} [_inst_4 : UniformSpace.{u3} \u03b1] [_inst_5 : UniformSpace.{u4} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u1, u3, u4} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (forall (u : \u03ba -> \u03b9), UniformEquicontinuous.{u2, u3, u4} \u03ba \u03b1 \u03b2 _inst_4 _inst_5 (Function.comp.{succ u2, succ u1, max (succ u4) (succ u3)} \u03ba \u03b9 (\u03b2 -> \u03b1) F u))\nbut is expected to have type\n  forall {\u03b9 : Type.{u4}} {\u03ba : Type.{u1}} {\u03b1 : Type.{u3}} {\u03b2 : Type.{u2}} [_inst_4 : UniformSpace.{u3} \u03b1] [_inst_5 : UniformSpace.{u2} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u4, u3, u2} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (forall (u : \u03ba -> \u03b9), UniformEquicontinuous.{u1, u3, u2} \u03ba \u03b1 \u03b2 _inst_4 _inst_5 (Function.comp.{succ u1, succ u4, max (succ u2) (succ u3)} \u03ba \u03b9 (\u03b2 -> \u03b1) F u))\nCase conversion may be inaccurate. Consider using '#align uniform_equicontinuous.comp UniformEquicontinuous.comp\u2093'. -/\n/-- Taking sub-families preserves uniform equicontinuity. -/\ntheorem UniformEquicontinuous.comp {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h : UniformEquicontinuous F) (u : \u03ba \u2192 \u03b9) :\n    UniformEquicontinuous (F \u2218 u) := fun U hU => (h U hU).mono fun x H k => H (u k)\n#align uniform_equicontinuous.comp UniformEquicontinuous.comp\n\n/- warning: set.uniform_equicontinuous.mono -> Set.UniformEquicontinuous.mono is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : UniformSpace.{u1} \u03b1] [_inst_5 : UniformSpace.{u2} \u03b2] {H : Set.{max u2 u1} (\u03b2 -> \u03b1)} {H' : Set.{max u2 u1} (\u03b2 -> \u03b1)}, (Set.UniformEquicontinuous.{u1, u2} \u03b1 \u03b2 _inst_4 _inst_5 H) -> (HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (\u03b2 -> \u03b1)) (Set.hasSubset.{max u2 u1} (\u03b2 -> \u03b1)) H' H) -> (Set.UniformEquicontinuous.{u1, u2} \u03b1 \u03b2 _inst_4 _inst_5 H')\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {H : Set.{max u2 u1} (\u03b2 -> \u03b1)} {H' : Set.{max u2 u1} (\u03b2 -> \u03b1)}, (Set.UniformEquicontinuous.{u2, u1} \u03b1 \u03b2 _inst_4 _inst_5 H) -> (HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (\u03b2 -> \u03b1)) (Set.instHasSubsetSet.{max u2 u1} (\u03b2 -> \u03b1)) H' H) -> (Set.UniformEquicontinuous.{u2, u1} \u03b1 \u03b2 _inst_4 _inst_5 H')\nCase conversion may be inaccurate. Consider using '#align set.uniform_equicontinuous.mono Set.UniformEquicontinuous.mono\u2093'. -/\nprotected theorem Set.UniformEquicontinuous.mono {H H' : Set <| \u03b2 \u2192 \u03b1} (h : H.UniformEquicontinuous)\n    (hH : H' \u2286 H) : H'.UniformEquicontinuous :=\n  h.comp (inclusion hH)\n#align set.uniform_equicontinuous.mono Set.UniformEquicontinuous.mono\n\n/- warning: equicontinuous_at_iff_range -> equicontinuousAt_iff_range is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, Iff (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (EquicontinuousAt.{max u2 u3, u2, u3} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) X \u03b1 _inst_1 _inst_4 ((fun (a : Type.{max u2 u3}) (b : Sort.{max (succ u2) (succ u3)}) [self : HasLiftT.{succ (max u2 u3), max (succ u2) (succ u3)} a b] => self.0) (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (HasLiftT.mk.{succ (max u2 u3), max (succ u2) (succ u3)} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (CoeTC\u2093.coe.{succ (max u2 u3), max (succ u2) (succ u3)} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (coeBase.{succ (max u2 u3), max (succ u2) (succ u3)} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (coeSubtype.{max (succ u2) (succ u3)} (X -> \u03b1) (fun (x : X -> \u03b1) => Membership.Mem.{max u2 u3, max u2 u3} (X -> \u03b1) (Set.{max u2 u3} (X -> \u03b1)) (Set.hasMem.{max u2 u3} (X -> \u03b1)) x (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F))))))) x\u2080)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, Iff (EquicontinuousAt.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (EquicontinuousAt.{max u2 u1, u2, u1} (Subtype.{succ (max u2 u1)} (X -> \u03b1) (fun (x : X -> \u03b1) => Membership.mem.{max u2 u1, max u2 u1} (X -> \u03b1) (Set.{max u2 u1} (X -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (X -> \u03b1)) x (Set.range.{max u2 u1, succ u3} (X -> \u03b1) \u03b9 F))) X \u03b1 _inst_1 _inst_4 (Subtype.val.{succ (max u2 u1)} (X -> \u03b1) (fun (x : X -> \u03b1) => Membership.mem.{max u2 u1, max u2 u1} (X -> \u03b1) (Set.{max u2 u1} (X -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (X -> \u03b1)) x (Set.range.{max u2 u1, succ u3} (X -> \u03b1) \u03b9 F))) x\u2080)\nCase conversion may be inaccurate. Consider using '#align equicontinuous_at_iff_range equicontinuousAt_iff_range\u2093'. -/\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous at `x\u2080` iff `range \ud835\udcd5` is equicontinuous at `x\u2080`,\ni.e the family `coe : range F \u2192 X \u2192 \u03b1` is equicontinuous at `x\u2080`. -/\ntheorem equicontinuousAt_iff_range {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} :\n    EquicontinuousAt F x\u2080 \u2194 EquicontinuousAt (coe : range F \u2192 X \u2192 \u03b1) x\u2080 :=\n  \u27e8fun h => by rw [\u2190 comp_range_splitting F] <;> exact h.comp _, fun h =>\n    h.comp (rangeFactorization F)\u27e9\n#align equicontinuous_at_iff_range equicontinuousAt_iff_range\n\n/- warning: equicontinuous_iff_range -> equicontinuous_iff_range is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {F : \u03b9 -> X -> \u03b1}, Iff (Equicontinuous.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F) (Equicontinuous.{max u2 u3, u2, u3} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) X \u03b1 _inst_1 _inst_4 ((fun (a : Type.{max u2 u3}) (b : Sort.{max (succ u2) (succ u3)}) [self : HasLiftT.{succ (max u2 u3), max (succ u2) (succ u3)} a b] => self.0) (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (HasLiftT.mk.{succ (max u2 u3), max (succ u2) (succ u3)} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (CoeTC\u2093.coe.{succ (max u2 u3), max (succ u2) (succ u3)} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (coeBase.{succ (max u2 u3), max (succ u2) (succ u3)} (coeSort.{succ (max u2 u3), succ (succ (max u2 u3))} (Set.{max u2 u3} (X -> \u03b1)) Type.{max u2 u3} (Set.hasCoeToSort.{max u2 u3} (X -> \u03b1)) (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F)) (X -> \u03b1) (coeSubtype.{max (succ u2) (succ u3)} (X -> \u03b1) (fun (x : X -> \u03b1) => Membership.Mem.{max u2 u3, max u2 u3} (X -> \u03b1) (Set.{max u2 u3} (X -> \u03b1)) (Set.hasMem.{max u2 u3} (X -> \u03b1)) x (Set.range.{max u2 u3, succ u1} (X -> \u03b1) \u03b9 F))))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {F : \u03b9 -> X -> \u03b1}, Iff (Equicontinuous.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F) (Equicontinuous.{max u2 u1, u2, u1} (Subtype.{succ (max u2 u1)} (X -> \u03b1) (fun (x : X -> \u03b1) => Membership.mem.{max u2 u1, max u2 u1} (X -> \u03b1) (Set.{max u2 u1} (X -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (X -> \u03b1)) x (Set.range.{max u2 u1, succ u3} (X -> \u03b1) \u03b9 F))) X \u03b1 _inst_1 _inst_4 (Subtype.val.{succ (max u2 u1)} (X -> \u03b1) (fun (x : X -> \u03b1) => Membership.mem.{max u2 u1, max u2 u1} (X -> \u03b1) (Set.{max u2 u1} (X -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (X -> \u03b1)) x (Set.range.{max u2 u1, succ u3} (X -> \u03b1) \u03b9 F))))\nCase conversion may be inaccurate. Consider using '#align equicontinuous_iff_range equicontinuous_iff_range\u2093'. -/\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous iff `range \ud835\udcd5` is equicontinuous,\ni.e the family `coe : range F \u2192 X \u2192 \u03b1` is equicontinuous. -/\ntheorem equicontinuous_iff_range {F : \u03b9 \u2192 X \u2192 \u03b1} :\n    Equicontinuous F \u2194 Equicontinuous (coe : range F \u2192 X \u2192 \u03b1) :=\n  forall_congr' fun x\u2080 => equicontinuousAt_iff_range\n#align equicontinuous_iff_range equicontinuous_iff_range\n\n/- warning: uniform_equicontinuous_at_iff_range -> uniformEquicontinuous_at_iff_range is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, Iff (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (UniformEquicontinuous.{max u3 u2, u2, u3} (coeSort.{succ (max u3 u2), succ (succ (max u3 u2))} (Set.{max u3 u2} (\u03b2 -> \u03b1)) Type.{max u3 u2} (Set.hasCoeToSort.{max u3 u2} (\u03b2 -> \u03b1)) (Set.range.{max u3 u2, succ u1} (\u03b2 -> \u03b1) \u03b9 F)) \u03b1 \u03b2 _inst_4 _inst_5 ((fun (a : Type.{max u3 u2}) (b : Sort.{max (succ u3) (succ u2)}) [self : HasLiftT.{succ (max u3 u2), max (succ u3) (succ u2)} a b] => self.0) (coeSort.{succ (max u3 u2), succ (succ (max u3 u2))} (Set.{max u3 u2} (\u03b2 -> \u03b1)) Type.{max u3 u2} (Set.hasCoeToSort.{max u3 u2} (\u03b2 -> \u03b1)) (Set.range.{max u3 u2, succ u1} (\u03b2 -> \u03b1) \u03b9 F)) (\u03b2 -> \u03b1) (HasLiftT.mk.{succ (max u3 u2), max (succ u3) (succ u2)} (coeSort.{succ (max u3 u2), succ (succ (max u3 u2))} (Set.{max u3 u2} (\u03b2 -> \u03b1)) Type.{max u3 u2} (Set.hasCoeToSort.{max u3 u2} (\u03b2 -> \u03b1)) (Set.range.{max u3 u2, succ u1} (\u03b2 -> \u03b1) \u03b9 F)) (\u03b2 -> \u03b1) (CoeTC\u2093.coe.{succ (max u3 u2), max (succ u3) (succ u2)} (coeSort.{succ (max u3 u2), succ (succ (max u3 u2))} (Set.{max u3 u2} (\u03b2 -> \u03b1)) Type.{max u3 u2} (Set.hasCoeToSort.{max u3 u2} (\u03b2 -> \u03b1)) (Set.range.{max u3 u2, succ u1} (\u03b2 -> \u03b1) \u03b9 F)) (\u03b2 -> \u03b1) (coeBase.{succ (max u3 u2), max (succ u3) (succ u2)} (coeSort.{succ (max u3 u2), succ (succ (max u3 u2))} (Set.{max u3 u2} (\u03b2 -> \u03b1)) Type.{max u3 u2} (Set.hasCoeToSort.{max u3 u2} (\u03b2 -> \u03b1)) (Set.range.{max u3 u2, succ u1} (\u03b2 -> \u03b1) \u03b9 F)) (\u03b2 -> \u03b1) (coeSubtype.{max (succ u3) (succ u2)} (\u03b2 -> \u03b1) (fun (x : \u03b2 -> \u03b1) => Membership.Mem.{max u3 u2, max u3 u2} (\u03b2 -> \u03b1) (Set.{max u3 u2} (\u03b2 -> \u03b1)) (Set.hasMem.{max u3 u2} (\u03b2 -> \u03b1)) x (Set.range.{max u3 u2, succ u1} (\u03b2 -> \u03b1) \u03b9 F))))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, Iff (UniformEquicontinuous.{u3, u2, u1} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (UniformEquicontinuous.{max u2 u1, u2, u1} (Subtype.{succ (max u2 u1)} (\u03b2 -> \u03b1) (fun (x : \u03b2 -> \u03b1) => Membership.mem.{max u2 u1, max u2 u1} (\u03b2 -> \u03b1) (Set.{max u2 u1} (\u03b2 -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (\u03b2 -> \u03b1)) x (Set.range.{max u2 u1, succ u3} (\u03b2 -> \u03b1) \u03b9 F))) \u03b1 \u03b2 _inst_4 _inst_5 (Subtype.val.{succ (max u2 u1)} (\u03b2 -> \u03b1) (fun (x : \u03b2 -> \u03b1) => Membership.mem.{max u2 u1, max u2 u1} (\u03b2 -> \u03b1) (Set.{max u2 u1} (\u03b2 -> \u03b1)) (Set.instMembershipSet.{max u2 u1} (\u03b2 -> \u03b1)) x (Set.range.{max u2 u1, succ u3} (\u03b2 -> \u03b1) \u03b9 F))))\nCase conversion may be inaccurate. Consider using '#align uniform_equicontinuous_at_iff_range uniformEquicontinuous_at_iff_range\u2093'. -/\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous iff `range \ud835\udcd5` is uniformly equicontinuous,\ni.e the family `coe : range F \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous. -/\ntheorem uniformEquicontinuous_at_iff_range {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} :\n    UniformEquicontinuous F \u2194 UniformEquicontinuous (coe : range F \u2192 \u03b2 \u2192 \u03b1) :=\n  \u27e8fun h => by rw [\u2190 comp_range_splitting F] <;> exact h.comp _, fun h =>\n    h.comp (rangeFactorization F)\u27e9\n#align uniform_equicontinuous_at_iff_range uniformEquicontinuous_at_iff_range\n\nsection\n\nopen UniformFun\n\n/- warning: equicontinuous_at_iff_continuous_at -> equicontinuousAt_iff_continuousAt is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, Iff (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (ContinuousAt.{u2, max u1 u3} X (UniformFun.{u1, u3} \u03b9 \u03b1) _inst_1 (UniformFun.topologicalSpace.{u1, u3} \u03b9 \u03b1 _inst_4) (Function.comp.{succ u2, max (succ u1) (succ u3), max (succ u1) (succ u3)} X (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1) (coeFn.{max 1 (succ u1) (succ u3), max (succ u1) (succ u3)} (Equiv.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1)) (fun (_x : Equiv.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1)) => (\u03b9 -> \u03b1) -> (UniformFun.{u1, u3} \u03b9 \u03b1)) (Equiv.hasCoeToFun.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1)) (UniformFun.ofFun.{u1, u3} \u03b9 \u03b1)) (Function.swap.{succ u1, succ u2, succ u3} \u03b9 X (fun (\u1fb0 : \u03b9) (\u1fb0 : X) => \u03b1) F)) x\u2080)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, Iff (EquicontinuousAt.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (ContinuousAt.{u2, max u3 u1} X (UniformFun.{u3, u1} \u03b9 \u03b1) _inst_1 (UniformFun.topologicalSpace.{u3, u1} \u03b9 \u03b1 _inst_4) (Function.comp.{succ u2, max (succ u1) (succ u3), max (succ u3) (succ u1)} X (\u03b9 -> \u03b1) (UniformFun.{u3, u1} \u03b9 \u03b1) (FunLike.coe.{max (succ u1) (succ u3), max (succ u1) (succ u3), max (succ u1) (succ u3)} (Equiv.{max (succ u3) (succ u1), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u3, u1} \u03b9 \u03b1)) (\u03b9 -> \u03b1) (fun (_x : \u03b9 -> \u03b1) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : \u03b9 -> \u03b1) => UniformFun.{u3, u1} \u03b9 \u03b1) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u3, u1} \u03b9 \u03b1)) (UniformFun.ofFun.{u3, u1} \u03b9 \u03b1)) (Function.swap.{succ u3, succ u2, succ u1} \u03b9 X (fun (\u1fb0 : \u03b9) (\u1fb0 : X) => \u03b1) F)) x\u2080)\nCase conversion may be inaccurate. Consider using '#align equicontinuous_at_iff_continuous_at equicontinuousAt_iff_continuousAt\u2093'. -/\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous at `x\u2080` iff the function `swap \ud835\udcd5 : X \u2192 \u03b9 \u2192 \u03b1` is\ncontinuous at `x\u2080` *when `\u03b9 \u2192 \u03b1` is equipped with the topology of uniform convergence*. This is\nvery useful for developping the equicontinuity API, but it should not be used directly for other\npurposes. -/\ntheorem equicontinuousAt_iff_continuousAt {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} :\n    EquicontinuousAt F x\u2080 \u2194 ContinuousAt (ofFun \u2218 Function.swap F : X \u2192 \u03b9 \u2192\u1d64 \u03b1) x\u2080 := by\n  rw [ContinuousAt, (UniformFun.hasBasis_nhds \u03b9 \u03b1 _).tendsto_right_iff] <;> rfl\n#align equicontinuous_at_iff_continuous_at equicontinuousAt_iff_continuousAt\n\n/- warning: equicontinuous_iff_continuous -> equicontinuous_iff_continuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {F : \u03b9 -> X -> \u03b1}, Iff (Equicontinuous.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F) (Continuous.{u2, max u1 u3} X (UniformFun.{u1, u3} \u03b9 \u03b1) _inst_1 (UniformFun.topologicalSpace.{u1, u3} \u03b9 \u03b1 _inst_4) (Function.comp.{succ u2, max (succ u1) (succ u3), max (succ u1) (succ u3)} X (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1) (coeFn.{max 1 (succ u1) (succ u3), max (succ u1) (succ u3)} (Equiv.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1)) (fun (_x : Equiv.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1)) => (\u03b9 -> \u03b1) -> (UniformFun.{u1, u3} \u03b9 \u03b1)) (Equiv.hasCoeToFun.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u1, u3} \u03b9 \u03b1)) (UniformFun.ofFun.{u1, u3} \u03b9 \u03b1)) (Function.swap.{succ u1, succ u2, succ u3} \u03b9 X (fun (\u1fb0 : \u03b9) (\u1fb0 : X) => \u03b1) F)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {F : \u03b9 -> X -> \u03b1}, Iff (Equicontinuous.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F) (Continuous.{u2, max u3 u1} X (UniformFun.{u3, u1} \u03b9 \u03b1) _inst_1 (UniformFun.topologicalSpace.{u3, u1} \u03b9 \u03b1 _inst_4) (Function.comp.{succ u2, max (succ u1) (succ u3), max (succ u3) (succ u1)} X (\u03b9 -> \u03b1) (UniformFun.{u3, u1} \u03b9 \u03b1) (FunLike.coe.{max (succ u1) (succ u3), max (succ u1) (succ u3), max (succ u1) (succ u3)} (Equiv.{max (succ u3) (succ u1), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u3, u1} \u03b9 \u03b1)) (\u03b9 -> \u03b1) (fun (_x : \u03b9 -> \u03b1) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : \u03b9 -> \u03b1) => UniformFun.{u3, u1} \u03b9 \u03b1) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u3, u1} \u03b9 \u03b1)) (UniformFun.ofFun.{u3, u1} \u03b9 \u03b1)) (Function.swap.{succ u3, succ u2, succ u1} \u03b9 X (fun (\u1fb0 : \u03b9) (\u1fb0 : X) => \u03b1) F)))\nCase conversion may be inaccurate. Consider using '#align equicontinuous_iff_continuous equicontinuous_iff_continuous\u2093'. -/\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous iff the function `swap \ud835\udcd5 : X \u2192 \u03b9 \u2192 \u03b1` is\ncontinuous *when `\u03b9 \u2192 \u03b1` is equipped with the topology of uniform convergence*. This is\nvery useful for developping the equicontinuity API, but it should not be used directly for other\npurposes. -/\ntheorem equicontinuous_iff_continuous {F : \u03b9 \u2192 X \u2192 \u03b1} :\n    Equicontinuous F \u2194 Continuous (ofFun \u2218 Function.swap F : X \u2192 \u03b9 \u2192\u1d64 \u03b1) := by\n  simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt]\n#align equicontinuous_iff_continuous equicontinuous_iff_continuous\n\n/- warning: uniform_equicontinuous_iff_uniform_continuous -> uniformEquicontinuous_iff_uniformContinuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, Iff (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (UniformContinuous.{u3, max u1 u2} \u03b2 (UniformFun.{u1, u2} \u03b9 \u03b1) _inst_5 (UniformFun.uniformSpace.{u1, u2} \u03b9 \u03b1 _inst_4) (Function.comp.{succ u3, max (succ u1) (succ u2), max (succ u1) (succ u2)} \u03b2 (\u03b9 -> \u03b1) (UniformFun.{u1, u2} \u03b9 \u03b1) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (\u03b9 -> \u03b1) (UniformFun.{u1, u2} \u03b9 \u03b1)) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (\u03b9 -> \u03b1) (UniformFun.{u1, u2} \u03b9 \u03b1)) => (\u03b9 -> \u03b1) -> (UniformFun.{u1, u2} \u03b9 \u03b1)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (\u03b9 -> \u03b1) (UniformFun.{u1, u2} \u03b9 \u03b1)) (UniformFun.ofFun.{u1, u2} \u03b9 \u03b1)) (Function.swap.{succ u1, succ u3, succ u2} \u03b9 \u03b2 (fun (\u1fb0 : \u03b9) (\u1fb0 : \u03b2) => \u03b1) F)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {F : \u03b9 -> \u03b2 -> \u03b1}, Iff (UniformEquicontinuous.{u3, u2, u1} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (UniformContinuous.{u1, max u3 u2} \u03b2 (UniformFun.{u3, u2} \u03b9 \u03b1) _inst_5 (UniformFun.uniformSpace.{u3, u2} \u03b9 \u03b1 _inst_4) (Function.comp.{succ u1, max (succ u2) (succ u3), max (succ u3) (succ u2)} \u03b2 (\u03b9 -> \u03b1) (UniformFun.{u3, u2} \u03b9 \u03b1) (FunLike.coe.{max (succ u2) (succ u3), max (succ u2) (succ u3), max (succ u2) (succ u3)} (Equiv.{max (succ u3) (succ u2), max (succ u2) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u3, u2} \u03b9 \u03b1)) (\u03b9 -> \u03b1) (fun (_x : \u03b9 -> \u03b1) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : \u03b9 -> \u03b1) => UniformFun.{u3, u2} \u03b9 \u03b1) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u3), max (succ u2) (succ u3)} (\u03b9 -> \u03b1) (UniformFun.{u3, u2} \u03b9 \u03b1)) (UniformFun.ofFun.{u3, u2} \u03b9 \u03b1)) (Function.swap.{succ u3, succ u1, succ u2} \u03b9 \u03b2 (fun (\u1fb0 : \u03b9) (\u1fb0 : \u03b2) => \u03b1) F)))\nCase conversion may be inaccurate. Consider using '#align uniform_equicontinuous_iff_uniform_continuous uniformEquicontinuous_iff_uniformContinuous\u2093'. -/\n/-- A family `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous iff the function `swap \ud835\udcd5 : \u03b2 \u2192 \u03b9 \u2192 \u03b1` is\nuniformly continuous *when `\u03b9 \u2192 \u03b1` is equipped with the uniform structure of uniform convergence*.\nThis is very useful for developping the equicontinuity API, but it should not be used directly\nfor other purposes. -/\ntheorem uniformEquicontinuous_iff_uniformContinuous {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} :\n    UniformEquicontinuous F \u2194 UniformContinuous (ofFun \u2218 Function.swap F : \u03b2 \u2192 \u03b9 \u2192\u1d64 \u03b1) := by\n  rw [UniformContinuous, (UniformFun.hasBasis_uniformity \u03b9 \u03b1).tendsto_right_iff] <;> rfl\n#align uniform_equicontinuous_iff_uniform_continuous uniformEquicontinuous_iff_uniformContinuous\n\n/- warning: filter.has_basis.equicontinuous_at_iff_left -> Filter.HasBasis.equicontinuousAt_iff_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u2} X)} {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (Filter.HasBasis.{u2, succ u4} X \u03ba (nhds.{u2} X _inst_1 x\u2080) p s) -> (Iff (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (U : Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)), (Membership.Mem.{u3, u3} (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Filter.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Filter.hasMem.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) U (uniformity.{u3} \u03b1 _inst_4)) -> (Exists.{succ u4} \u03ba (fun (k : \u03ba) => Exists.{0} (p k) (fun (_x : p k) => forall (x : X), (Membership.Mem.{u2, u2} X (Set.{u2} X) (Set.hasMem.{u2} X) x (s k)) -> (forall (i : \u03b9), Membership.Mem.{u3, u3} (Prod.{u3, u3} \u03b1 \u03b1) (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Set.hasMem.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Prod.mk.{u3, u3} \u03b1 \u03b1 (F i x\u2080) (F i x)) U))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {X : Type.{u3}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u3} X] [_inst_4 : UniformSpace.{u1} \u03b1] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u3} X)} {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (Filter.HasBasis.{u3, succ u4} X \u03ba (nhds.{u3} X _inst_1 x\u2080) p s) -> (Iff (EquicontinuousAt.{u2, u3, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (U : Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)), (Membership.mem.{u1, u1} (Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Filter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (instMembershipSetFilter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) U (uniformity.{u1} \u03b1 _inst_4)) -> (Exists.{succ u4} \u03ba (fun (k : \u03ba) => And (p k) (forall (x : X), (Membership.mem.{u3, u3} X (Set.{u3} X) (Set.instMembershipSet.{u3} X) x (s k)) -> (forall (i : \u03b9), Membership.mem.{u1, u1} (Prod.{u1, u1} \u03b1 \u03b1) (Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Set.instMembershipSet.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Prod.mk.{u1, u1} \u03b1 \u03b1 (F i x\u2080) (F i x)) U))))))\nCase conversion may be inaccurate. Consider using '#align filter.has_basis.equicontinuous_at_iff_left Filter.HasBasis.equicontinuousAt_iff_left\u2093'. -/\ntheorem Filter.HasBasis.equicontinuousAt_iff_left {\u03ba : Type _} {p : \u03ba \u2192 Prop} {s : \u03ba \u2192 Set X}\n    {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (hX : (\ud835\udcdd x\u2080).HasBasis p s) :\n    EquicontinuousAt F x\u2080 \u2194 \u2200 U \u2208 \ud835\udce4 \u03b1, \u2203 (k : _)(_ : p k), \u2200 x \u2208 s k, \u2200 i, (F i x\u2080, F i x) \u2208 U :=\n  by\n  rw [equicontinuousAt_iff_continuousAt, ContinuousAt,\n    hX.tendsto_iff (UniformFun.hasBasis_nhds \u03b9 \u03b1 _)]\n  rfl\n#align filter.has_basis.equicontinuous_at_iff_left Filter.HasBasis.equicontinuousAt_iff_left\n\n/- warning: filter.has_basis.equicontinuous_at_iff_right -> Filter.HasBasis.equicontinuousAt_iff_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1))} {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (Filter.HasBasis.{u3, succ u4} (Prod.{u3, u3} \u03b1 \u03b1) \u03ba (uniformity.{u3} \u03b1 _inst_4) p s) -> (Iff (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (k : \u03ba), (p k) -> (Filter.Eventually.{u2} X (fun (x : X) => forall (i : \u03b9), Membership.Mem.{u3, u3} (Prod.{u3, u3} \u03b1 \u03b1) (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Set.hasMem.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Prod.mk.{u3, u3} \u03b1 \u03b1 (F i x\u2080) (F i x)) (s k)) (nhds.{u2} X _inst_1 x\u2080))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {X : Type.{u1}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u3} \u03b1] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1))} {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (Filter.HasBasis.{u3, succ u4} (Prod.{u3, u3} \u03b1 \u03b1) \u03ba (uniformity.{u3} \u03b1 _inst_4) p s) -> (Iff (EquicontinuousAt.{u2, u1, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (k : \u03ba), (p k) -> (Filter.Eventually.{u1} X (fun (x : X) => forall (i : \u03b9), Membership.mem.{u3, u3} (Prod.{u3, u3} \u03b1 \u03b1) (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Set.instMembershipSet.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Prod.mk.{u3, u3} \u03b1 \u03b1 (F i x\u2080) (F i x)) (s k)) (nhds.{u1} X _inst_1 x\u2080))))\nCase conversion may be inaccurate. Consider using '#align filter.has_basis.equicontinuous_at_iff_right Filter.HasBasis.equicontinuousAt_iff_right\u2093'. -/\ntheorem Filter.HasBasis.equicontinuousAt_iff_right {\u03ba : Type _} {p : \u03ba \u2192 Prop} {s : \u03ba \u2192 Set (\u03b1 \u00d7 \u03b1)}\n    {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p s) :\n    EquicontinuousAt F x\u2080 \u2194 \u2200 k, p k \u2192 \u2200\u1da0 x in \ud835\udcdd x\u2080, \u2200 i, (F i x\u2080, F i x) \u2208 s k :=\n  by\n  rw [equicontinuousAt_iff_continuousAt, ContinuousAt,\n    (UniformFun.hasBasis_nhds_of_basis \u03b9 \u03b1 _ h\u03b1).tendsto_right_iff]\n  rfl\n#align filter.has_basis.equicontinuous_at_iff_right Filter.HasBasis.equicontinuousAt_iff_right\n\n/- warning: filter.has_basis.equicontinuous_at_iff -> Filter.HasBasis.equicontinuousAt_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {\u03ba\u2081 : Type.{u4}} {\u03ba\u2082 : Type.{u5}} {p\u2081 : \u03ba\u2081 -> Prop} {s\u2081 : \u03ba\u2081 -> (Set.{u2} X)} {p\u2082 : \u03ba\u2082 -> Prop} {s\u2082 : \u03ba\u2082 -> (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1))} {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (Filter.HasBasis.{u2, succ u4} X \u03ba\u2081 (nhds.{u2} X _inst_1 x\u2080) p\u2081 s\u2081) -> (Filter.HasBasis.{u3, succ u5} (Prod.{u3, u3} \u03b1 \u03b1) \u03ba\u2082 (uniformity.{u3} \u03b1 _inst_4) p\u2082 s\u2082) -> (Iff (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (k\u2082 : \u03ba\u2082), (p\u2082 k\u2082) -> (Exists.{succ u4} \u03ba\u2081 (fun (k\u2081 : \u03ba\u2081) => Exists.{0} (p\u2081 k\u2081) (fun (_x : p\u2081 k\u2081) => forall (x : X), (Membership.Mem.{u2, u2} X (Set.{u2} X) (Set.hasMem.{u2} X) x (s\u2081 k\u2081)) -> (forall (i : \u03b9), Membership.Mem.{u3, u3} (Prod.{u3, u3} \u03b1 \u03b1) (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Set.hasMem.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Prod.mk.{u3, u3} \u03b1 \u03b1 (F i x\u2080) (F i x)) (s\u2082 k\u2082)))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {X : Type.{u3}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u3} X] [_inst_4 : UniformSpace.{u2} \u03b1] {\u03ba\u2081 : Type.{u5}} {\u03ba\u2082 : Type.{u4}} {p\u2081 : \u03ba\u2081 -> Prop} {s\u2081 : \u03ba\u2081 -> (Set.{u3} X)} {p\u2082 : \u03ba\u2082 -> Prop} {s\u2082 : \u03ba\u2082 -> (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1))} {F : \u03b9 -> X -> \u03b1} {x\u2080 : X}, (Filter.HasBasis.{u3, succ u5} X \u03ba\u2081 (nhds.{u3} X _inst_1 x\u2080) p\u2081 s\u2081) -> (Filter.HasBasis.{u2, succ u4} (Prod.{u2, u2} \u03b1 \u03b1) \u03ba\u2082 (uniformity.{u2} \u03b1 _inst_4) p\u2082 s\u2082) -> (Iff (EquicontinuousAt.{u1, u3, u2} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (forall (k\u2082 : \u03ba\u2082), (p\u2082 k\u2082) -> (Exists.{succ u5} \u03ba\u2081 (fun (k\u2081 : \u03ba\u2081) => And (p\u2081 k\u2081) (forall (x : X), (Membership.mem.{u3, u3} X (Set.{u3} X) (Set.instMembershipSet.{u3} X) x (s\u2081 k\u2081)) -> (forall (i : \u03b9), Membership.mem.{u2, u2} (Prod.{u2, u2} \u03b1 \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Set.instMembershipSet.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Prod.mk.{u2, u2} \u03b1 \u03b1 (F i x\u2080) (F i x)) (s\u2082 k\u2082)))))))\nCase conversion may be inaccurate. Consider using '#align filter.has_basis.equicontinuous_at_iff Filter.HasBasis.equicontinuousAt_iff\u2093'. -/\ntheorem Filter.HasBasis.equicontinuousAt_iff {\u03ba\u2081 \u03ba\u2082 : Type _} {p\u2081 : \u03ba\u2081 \u2192 Prop} {s\u2081 : \u03ba\u2081 \u2192 Set X}\n    {p\u2082 : \u03ba\u2082 \u2192 Prop} {s\u2082 : \u03ba\u2082 \u2192 Set (\u03b1 \u00d7 \u03b1)} {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} (hX : (\ud835\udcdd x\u2080).HasBasis p\u2081 s\u2081)\n    (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p\u2082 s\u2082) :\n    EquicontinuousAt F x\u2080 \u2194\n      \u2200 k\u2082, p\u2082 k\u2082 \u2192 \u2203 (k\u2081 : _)(_ : p\u2081 k\u2081), \u2200 x \u2208 s\u2081 k\u2081, \u2200 i, (F i x\u2080, F i x) \u2208 s\u2082 k\u2082 :=\n  by\n  rw [equicontinuousAt_iff_continuousAt, ContinuousAt,\n    hX.tendsto_iff (UniformFun.hasBasis_nhds_of_basis \u03b9 \u03b1 _ h\u03b1)]\n  rfl\n#align filter.has_basis.equicontinuous_at_iff Filter.HasBasis.equicontinuousAt_iff\n\n/- warning: filter.has_basis.uniform_equicontinuous_iff_left -> Filter.HasBasis.uniformEquicontinuous_iff_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2))} {F : \u03b9 -> \u03b2 -> \u03b1}, (Filter.HasBasis.{u3, succ u4} (Prod.{u3, u3} \u03b2 \u03b2) \u03ba (uniformity.{u3} \u03b2 _inst_5) p s) -> (Iff (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (forall (U : Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1)), (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Filter.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) U (uniformity.{u2} \u03b1 _inst_4)) -> (Exists.{succ u4} \u03ba (fun (k : \u03ba) => Exists.{0} (p k) (fun (_x : p k) => forall (x : \u03b2) (y : \u03b2), (Membership.Mem.{u3, u3} (Prod.{u3, u3} \u03b2 \u03b2) (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Set.hasMem.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Prod.mk.{u3, u3} \u03b2 \u03b2 x y) (s k)) -> (forall (i : \u03b9), Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b1 \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Prod.mk.{u2, u2} \u03b1 \u03b1 (F i x) (F i y)) U))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b1 : Type.{u1}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u1} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2))} {F : \u03b9 -> \u03b2 -> \u03b1}, (Filter.HasBasis.{u3, succ u4} (Prod.{u3, u3} \u03b2 \u03b2) \u03ba (uniformity.{u3} \u03b2 _inst_5) p s) -> (Iff (UniformEquicontinuous.{u2, u1, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (forall (U : Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)), (Membership.mem.{u1, u1} (Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Filter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (instMembershipSetFilter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) U (uniformity.{u1} \u03b1 _inst_4)) -> (Exists.{succ u4} \u03ba (fun (k : \u03ba) => And (p k) (forall (x : \u03b2) (y : \u03b2), (Membership.mem.{u3, u3} (Prod.{u3, u3} \u03b2 \u03b2) (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Set.instMembershipSet.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Prod.mk.{u3, u3} \u03b2 \u03b2 x y) (s k)) -> (forall (i : \u03b9), Membership.mem.{u1, u1} (Prod.{u1, u1} \u03b1 \u03b1) (Set.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Set.instMembershipSet.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Prod.mk.{u1, u1} \u03b1 \u03b1 (F i x) (F i y)) U))))))\nCase conversion may be inaccurate. Consider using '#align filter.has_basis.uniform_equicontinuous_iff_left Filter.HasBasis.uniformEquicontinuous_iff_left\u2093'. -/\ntheorem Filter.HasBasis.uniformEquicontinuous_iff_left {\u03ba : Type _} {p : \u03ba \u2192 Prop}\n    {s : \u03ba \u2192 Set (\u03b2 \u00d7 \u03b2)} {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h\u03b2 : (\ud835\udce4 \u03b2).HasBasis p s) :\n    UniformEquicontinuous F \u2194\n      \u2200 U \u2208 \ud835\udce4 \u03b1, \u2203 (k : _)(_ : p k), \u2200 x y, (x, y) \u2208 s k \u2192 \u2200 i, (F i x, F i y) \u2208 U :=\n  by\n  rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous,\n    h\u03b2.tendsto_iff (UniformFun.hasBasis_uniformity \u03b9 \u03b1)]\n  simp_rw [Prod.forall]\n  rfl\n#align filter.has_basis.uniform_equicontinuous_iff_left Filter.HasBasis.uniformEquicontinuous_iff_left\n\n/- warning: filter.has_basis.uniform_equicontinuous_iff_right -> Filter.HasBasis.uniformEquicontinuous_iff_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1))} {F : \u03b9 -> \u03b2 -> \u03b1}, (Filter.HasBasis.{u2, succ u4} (Prod.{u2, u2} \u03b1 \u03b1) \u03ba (uniformity.{u2} \u03b1 _inst_4) p s) -> (Iff (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (forall (k : \u03ba), (p k) -> (Filter.Eventually.{u3} (Prod.{u3, u3} \u03b2 \u03b2) (fun (xy : Prod.{u3, u3} \u03b2 \u03b2) => forall (i : \u03b9), Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b1 \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Prod.mk.{u2, u2} \u03b1 \u03b1 (F i (Prod.fst.{u3, u3} \u03b2 \u03b2 xy)) (F i (Prod.snd.{u3, u3} \u03b2 \u03b2 xy))) (s k)) (uniformity.{u3} \u03b2 _inst_5))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b1 : Type.{u3}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u3} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {\u03ba : Type.{u4}} {p : \u03ba -> Prop} {s : \u03ba -> (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1))} {F : \u03b9 -> \u03b2 -> \u03b1}, (Filter.HasBasis.{u3, succ u4} (Prod.{u3, u3} \u03b1 \u03b1) \u03ba (uniformity.{u3} \u03b1 _inst_4) p s) -> (Iff (UniformEquicontinuous.{u2, u3, u1} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (forall (k : \u03ba), (p k) -> (Filter.Eventually.{u1} (Prod.{u1, u1} \u03b2 \u03b2) (fun (xy : Prod.{u1, u1} \u03b2 \u03b2) => forall (i : \u03b9), Membership.mem.{u3, u3} (Prod.{u3, u3} \u03b1 \u03b1) (Set.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Set.instMembershipSet.{u3} (Prod.{u3, u3} \u03b1 \u03b1)) (Prod.mk.{u3, u3} \u03b1 \u03b1 (F i (Prod.fst.{u1, u1} \u03b2 \u03b2 xy)) (F i (Prod.snd.{u1, u1} \u03b2 \u03b2 xy))) (s k)) (uniformity.{u1} \u03b2 _inst_5))))\nCase conversion may be inaccurate. Consider using '#align filter.has_basis.uniform_equicontinuous_iff_right Filter.HasBasis.uniformEquicontinuous_iff_right\u2093'. -/\ntheorem Filter.HasBasis.uniformEquicontinuous_iff_right {\u03ba : Type _} {p : \u03ba \u2192 Prop}\n    {s : \u03ba \u2192 Set (\u03b1 \u00d7 \u03b1)} {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p s) :\n    UniformEquicontinuous F \u2194 \u2200 k, p k \u2192 \u2200\u1da0 xy : \u03b2 \u00d7 \u03b2 in \ud835\udce4 \u03b2, \u2200 i, (F i xy.1, F i xy.2) \u2208 s k :=\n  by\n  rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous,\n    (UniformFun.hasBasis_uniformity_of_basis \u03b9 \u03b1 h\u03b1).tendsto_right_iff]\n  rfl\n#align filter.has_basis.uniform_equicontinuous_iff_right Filter.HasBasis.uniformEquicontinuous_iff_right\n\n/- warning: filter.has_basis.uniform_equicontinuous_iff -> Filter.HasBasis.uniformEquicontinuous_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {\u03ba\u2081 : Type.{u4}} {\u03ba\u2082 : Type.{u5}} {p\u2081 : \u03ba\u2081 -> Prop} {s\u2081 : \u03ba\u2081 -> (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2))} {p\u2082 : \u03ba\u2082 -> Prop} {s\u2082 : \u03ba\u2082 -> (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1))} {F : \u03b9 -> \u03b2 -> \u03b1}, (Filter.HasBasis.{u3, succ u4} (Prod.{u3, u3} \u03b2 \u03b2) \u03ba\u2081 (uniformity.{u3} \u03b2 _inst_5) p\u2081 s\u2081) -> (Filter.HasBasis.{u2, succ u5} (Prod.{u2, u2} \u03b1 \u03b1) \u03ba\u2082 (uniformity.{u2} \u03b1 _inst_4) p\u2082 s\u2082) -> (Iff (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (forall (k\u2082 : \u03ba\u2082), (p\u2082 k\u2082) -> (Exists.{succ u4} \u03ba\u2081 (fun (k\u2081 : \u03ba\u2081) => Exists.{0} (p\u2081 k\u2081) (fun (_x : p\u2081 k\u2081) => forall (x : \u03b2) (y : \u03b2), (Membership.Mem.{u3, u3} (Prod.{u3, u3} \u03b2 \u03b2) (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Set.hasMem.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Prod.mk.{u3, u3} \u03b2 \u03b2 x y) (s\u2081 k\u2081)) -> (forall (i : \u03b9), Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b1 \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Prod.mk.{u2, u2} \u03b1 \u03b1 (F i x) (F i y)) (s\u2082 k\u2082)))))))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {\u03ba\u2081 : Type.{u5}} {\u03ba\u2082 : Type.{u4}} {p\u2081 : \u03ba\u2081 -> Prop} {s\u2081 : \u03ba\u2081 -> (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2))} {p\u2082 : \u03ba\u2082 -> Prop} {s\u2082 : \u03ba\u2082 -> (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1))} {F : \u03b9 -> \u03b2 -> \u03b1}, (Filter.HasBasis.{u3, succ u5} (Prod.{u3, u3} \u03b2 \u03b2) \u03ba\u2081 (uniformity.{u3} \u03b2 _inst_5) p\u2081 s\u2081) -> (Filter.HasBasis.{u2, succ u4} (Prod.{u2, u2} \u03b1 \u03b1) \u03ba\u2082 (uniformity.{u2} \u03b1 _inst_4) p\u2082 s\u2082) -> (Iff (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (forall (k\u2082 : \u03ba\u2082), (p\u2082 k\u2082) -> (Exists.{succ u5} \u03ba\u2081 (fun (k\u2081 : \u03ba\u2081) => And (p\u2081 k\u2081) (forall (x : \u03b2) (y : \u03b2), (Membership.mem.{u3, u3} (Prod.{u3, u3} \u03b2 \u03b2) (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Set.instMembershipSet.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Prod.mk.{u3, u3} \u03b2 \u03b2 x y) (s\u2081 k\u2081)) -> (forall (i : \u03b9), Membership.mem.{u2, u2} (Prod.{u2, u2} \u03b1 \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Set.instMembershipSet.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Prod.mk.{u2, u2} \u03b1 \u03b1 (F i x) (F i y)) (s\u2082 k\u2082)))))))\nCase conversion may be inaccurate. Consider using '#align filter.has_basis.uniform_equicontinuous_iff Filter.HasBasis.uniformEquicontinuous_iff\u2093'. -/\ntheorem Filter.HasBasis.uniformEquicontinuous_iff {\u03ba\u2081 \u03ba\u2082 : Type _} {p\u2081 : \u03ba\u2081 \u2192 Prop}\n    {s\u2081 : \u03ba\u2081 \u2192 Set (\u03b2 \u00d7 \u03b2)} {p\u2082 : \u03ba\u2082 \u2192 Prop} {s\u2082 : \u03ba\u2082 \u2192 Set (\u03b1 \u00d7 \u03b1)} {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1}\n    (h\u03b2 : (\ud835\udce4 \u03b2).HasBasis p\u2081 s\u2081) (h\u03b1 : (\ud835\udce4 \u03b1).HasBasis p\u2082 s\u2082) :\n    UniformEquicontinuous F \u2194\n      \u2200 k\u2082, p\u2082 k\u2082 \u2192 \u2203 (k\u2081 : _)(_ : p\u2081 k\u2081), \u2200 x y, (x, y) \u2208 s\u2081 k\u2081 \u2192 \u2200 i, (F i x, F i y) \u2208 s\u2082 k\u2082 :=\n  by\n  rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous,\n    h\u03b2.tendsto_iff (UniformFun.hasBasis_uniformity_of_basis \u03b9 \u03b1 h\u03b1)]\n  simp_rw [Prod.forall]\n  rfl\n#align filter.has_basis.uniform_equicontinuous_iff Filter.HasBasis.uniformEquicontinuous_iff\n\n/- warning: uniform_inducing.equicontinuous_at_iff -> UniformInducing.equicontinuousAt_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} {\u03b2 : Type.{u4}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] [_inst_5 : UniformSpace.{u4} \u03b2] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X} {u : \u03b1 -> \u03b2}, (UniformInducing.{u3, u4} \u03b1 \u03b2 _inst_4 _inst_5 u) -> (Iff (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (EquicontinuousAt.{u1, u2, u4} \u03b9 X \u03b2 _inst_1 _inst_5 (Function.comp.{succ u1, max (succ u2) (succ u3), max (succ u2) (succ u4)} \u03b9 (X -> \u03b1) (X -> \u03b2) (Function.comp.{succ u2, succ u3, succ u4} X \u03b1 \u03b2 u) F) x\u2080))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {X : Type.{u1}} {\u03b1 : Type.{u4}} {\u03b2 : Type.{u3}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u4} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {F : \u03b9 -> X -> \u03b1} {x\u2080 : X} {u : \u03b1 -> \u03b2}, (UniformInducing.{u4, u3} \u03b1 \u03b2 _inst_4 _inst_5 u) -> (Iff (EquicontinuousAt.{u2, u1, u4} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) (EquicontinuousAt.{u2, u1, u3} \u03b9 X \u03b2 _inst_1 _inst_5 (Function.comp.{succ u2, max (succ u4) (succ u1), max (succ u3) (succ u1)} \u03b9 (X -> \u03b1) (X -> \u03b2) ((fun (x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3103 : \u03b1 -> \u03b2) (x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3105 : X -> \u03b1) => Function.comp.{succ u1, succ u4, succ u3} X \u03b1 \u03b2 x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3103 x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3105) u) F) x\u2080))\nCase conversion may be inaccurate. Consider using '#align uniform_inducing.equicontinuous_at_iff UniformInducing.equicontinuousAt_iff\u2093'. -/\n/-- Given `u : \u03b1 \u2192 \u03b2` a uniform inducing map, a family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous at a point\n`x\u2080 : X` iff the family `\ud835\udcd5'`, obtained by precomposing each function of `\ud835\udcd5` by `u`, is\nequicontinuous at `x\u2080`. -/\ntheorem UniformInducing.equicontinuousAt_iff {F : \u03b9 \u2192 X \u2192 \u03b1} {x\u2080 : X} {u : \u03b1 \u2192 \u03b2}\n    (hu : UniformInducing u) : EquicontinuousAt F x\u2080 \u2194 EquicontinuousAt ((\u00b7 \u2218 \u00b7) u \u2218 F) x\u2080 :=\n  by\n  have := (UniformFun.postcomp_uniformInducing hu).Inducing\n  rw [equicontinuousAt_iff_continuousAt, equicontinuousAt_iff_continuousAt, this.continuous_at_iff]\n  rfl\n#align uniform_inducing.equicontinuous_at_iff UniformInducing.equicontinuousAt_iff\n\n/- warning: uniform_inducing.equicontinuous_iff -> UniformInducing.equicontinuous_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} {\u03b2 : Type.{u4}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] [_inst_5 : UniformSpace.{u4} \u03b2] {F : \u03b9 -> X -> \u03b1} {u : \u03b1 -> \u03b2}, (UniformInducing.{u3, u4} \u03b1 \u03b2 _inst_4 _inst_5 u) -> (Iff (Equicontinuous.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F) (Equicontinuous.{u1, u2, u4} \u03b9 X \u03b2 _inst_1 _inst_5 (Function.comp.{succ u1, max (succ u2) (succ u3), max (succ u2) (succ u4)} \u03b9 (X -> \u03b1) (X -> \u03b2) (Function.comp.{succ u2, succ u3, succ u4} X \u03b1 \u03b2 u) F)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {X : Type.{u1}} {\u03b1 : Type.{u4}} {\u03b2 : Type.{u3}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u4} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {F : \u03b9 -> X -> \u03b1} {u : \u03b1 -> \u03b2}, (UniformInducing.{u4, u3} \u03b1 \u03b2 _inst_4 _inst_5 u) -> (Iff (Equicontinuous.{u2, u1, u4} \u03b9 X \u03b1 _inst_1 _inst_4 F) (Equicontinuous.{u2, u1, u3} \u03b9 X \u03b2 _inst_1 _inst_5 (Function.comp.{succ u2, max (succ u4) (succ u1), max (succ u3) (succ u1)} \u03b9 (X -> \u03b1) (X -> \u03b2) ((fun (x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3239 : \u03b1 -> \u03b2) (x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3241 : X -> \u03b1) => Function.comp.{succ u1, succ u4, succ u3} X \u03b1 \u03b2 x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3239 x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3241) u) F)))\nCase conversion may be inaccurate. Consider using '#align uniform_inducing.equicontinuous_iff UniformInducing.equicontinuous_iff\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:73:14: unsupported tactic `congrm #[[expr \u2200 x, (_ : exprProp())]] -/\n/-- Given `u : \u03b1 \u2192 \u03b2` a uniform inducing map, a family `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` is equicontinuous iff the\nfamily `\ud835\udcd5'`, obtained by precomposing each function of `\ud835\udcd5` by `u`, is equicontinuous. -/\ntheorem UniformInducing.equicontinuous_iff {F : \u03b9 \u2192 X \u2192 \u03b1} {u : \u03b1 \u2192 \u03b2} (hu : UniformInducing u) :\n    Equicontinuous F \u2194 Equicontinuous ((\u00b7 \u2218 \u00b7) u \u2218 F) :=\n  by\n  trace\n    \"./././Mathport/Syntax/Translate/Tactic/Builtin.lean:73:14: unsupported tactic `congrm #[[expr \u2200 x, (_ : exprProp())]]\"\n  rw [hu.equicontinuous_at_iff]\n#align uniform_inducing.equicontinuous_iff UniformInducing.equicontinuous_iff\n\n/- warning: uniform_inducing.uniform_equicontinuous_iff -> UniformInducing.uniformEquicontinuous_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} {\u03b3 : Type.{u4}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] [_inst_6 : UniformSpace.{u4} \u03b3] {F : \u03b9 -> \u03b2 -> \u03b1} {u : \u03b1 -> \u03b3}, (UniformInducing.{u2, u4} \u03b1 \u03b3 _inst_4 _inst_6 u) -> (Iff (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (UniformEquicontinuous.{u1, u4, u3} \u03b9 \u03b3 \u03b2 _inst_6 _inst_5 (Function.comp.{succ u1, max (succ u3) (succ u2), max (succ u3) (succ u4)} \u03b9 (\u03b2 -> \u03b1) (\u03b2 -> \u03b3) (Function.comp.{succ u3, succ u2, succ u4} \u03b2 \u03b1 \u03b3 u) F)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b1 : Type.{u4}} {\u03b2 : Type.{u1}} {\u03b3 : Type.{u3}} [_inst_4 : UniformSpace.{u4} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] [_inst_6 : UniformSpace.{u3} \u03b3] {F : \u03b9 -> \u03b2 -> \u03b1} {u : \u03b1 -> \u03b3}, (UniformInducing.{u4, u3} \u03b1 \u03b3 _inst_4 _inst_6 u) -> (Iff (UniformEquicontinuous.{u2, u4, u1} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) (UniformEquicontinuous.{u2, u3, u1} \u03b9 \u03b3 \u03b2 _inst_6 _inst_5 (Function.comp.{succ u2, max (succ u4) (succ u1), max (succ u1) (succ u3)} \u03b9 (\u03b2 -> \u03b1) (\u03b2 -> \u03b3) ((fun (x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3426 : \u03b1 -> \u03b3) (x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3428 : \u03b2 -> \u03b1) => Function.comp.{succ u1, succ u4, succ u3} \u03b2 \u03b1 \u03b3 x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3426 x._@.Mathlib.Topology.UniformSpace.Equicontinuity._hyg.3428) u) F)))\nCase conversion may be inaccurate. Consider using '#align uniform_inducing.uniform_equicontinuous_iff UniformInducing.uniformEquicontinuous_iff\u2093'. -/\n/-- Given `u : \u03b1 \u2192 \u03b3` a uniform inducing map, a family `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` is uniformly equicontinuous\niff the family `\ud835\udcd5'`, obtained by precomposing each function of `\ud835\udcd5` by `u`, is uniformly\nequicontinuous. -/\ntheorem UniformInducing.uniformEquicontinuous_iff {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} {u : \u03b1 \u2192 \u03b3}\n    (hu : UniformInducing u) : UniformEquicontinuous F \u2194 UniformEquicontinuous ((\u00b7 \u2218 \u00b7) u \u2218 F) :=\n  by\n  have := UniformFun.postcomp_uniformInducing hu\n  rw [uniformEquicontinuous_iff_uniformContinuous, uniformEquicontinuous_iff_uniformContinuous,\n    this.uniform_continuous_iff]\n  rfl\n#align uniform_inducing.uniform_equicontinuous_iff UniformInducing.uniformEquicontinuous_iff\n\n/- warning: equicontinuous_at.closure' -> EquicontinuousAt.closure' is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {Y : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : TopologicalSpace.{u2} Y] [_inst_4 : UniformSpace.{u3} \u03b1] {A : Set.{u2} Y} {u : Y -> X -> \u03b1} {x\u2080 : X}, (EquicontinuousAt.{u2, u1, u3} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u2, succ u2, max (succ u1) (succ u3)} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (X -> \u03b1) u ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (CoeTC\u2093.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (coeSubtype.{succ u2} Y (fun (x : Y) => Membership.Mem.{u2, u2} Y (Set.{u2} Y) (Set.hasMem.{u2} Y) x A))))))) x\u2080) -> (Continuous.{u2, max u1 u3} Y (X -> \u03b1) _inst_2 (Pi.topologicalSpace.{u1, u3} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4)) u) -> (EquicontinuousAt.{u2, u1, u3} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u2, succ u2, max (succ u1) (succ u3)} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (X -> \u03b1) u ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (CoeTC\u2093.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (coeSubtype.{succ u2} Y (fun (x : Y) => Membership.Mem.{u2, u2} Y (Set.{u2} Y) (Set.hasMem.{u2} Y) x (closure.{u2} Y _inst_2 A)))))))) x\u2080)\nbut is expected to have type\n  forall {X : Type.{u2}} {Y : Type.{u3}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_2 : TopologicalSpace.{u3} Y] [_inst_4 : UniformSpace.{u1} \u03b1] {A : Set.{u3} Y} {u : Y -> X -> \u03b1} {x\u2080 : X}, (EquicontinuousAt.{u3, u2, u1} (Set.Elem.{u3} Y A) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u3, succ u3, max (succ u2) (succ u1)} (Set.Elem.{u3} Y A) Y (X -> \u03b1) u (Subtype.val.{succ u3} Y (fun (x : Y) => Membership.mem.{u3, u3} Y (Set.{u3} Y) (Set.instMembershipSet.{u3} Y) x A))) x\u2080) -> (Continuous.{u3, max u2 u1} Y (X -> \u03b1) _inst_2 (Pi.topologicalSpace.{u2, u1} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4)) u) -> (EquicontinuousAt.{u3, u2, u1} (Set.Elem.{u3} Y (closure.{u3} Y _inst_2 A)) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u3, succ u3, max (succ u2) (succ u1)} (Set.Elem.{u3} Y (closure.{u3} Y _inst_2 A)) Y (X -> \u03b1) u (Subtype.val.{succ u3} Y (fun (x : Y) => Membership.mem.{u3, u3} Y (Set.{u3} Y) (Set.instMembershipSet.{u3} Y) x (closure.{u3} Y _inst_2 A)))) x\u2080)\nCase conversion may be inaccurate. Consider using '#align equicontinuous_at.closure' EquicontinuousAt.closure'\u2093'. -/\n/-- A version of `equicontinuous_at.closure` applicable to subsets of types which embed continuously\ninto `X \u2192 \u03b1` with the product topology. It turns out we don't need any other condition on the\nembedding than continuity, but in practice this will mostly be applied to `fun_like` types where\nthe coercion is injective. -/\ntheorem EquicontinuousAt.closure' {A : Set Y} {u : Y \u2192 X \u2192 \u03b1} {x\u2080 : X}\n    (hA : EquicontinuousAt (u \u2218 coe : A \u2192 X \u2192 \u03b1) x\u2080) (hu : Continuous u) :\n    EquicontinuousAt (u \u2218 coe : closure A \u2192 X \u2192 \u03b1) x\u2080 :=\n  by\n  intro U hU\n  rcases mem_uniformity_isClosed hU with \u27e8V, hV, hVclosed, hVU\u27e9\n  filter_upwards [hA V hV]with x hx\n  rw [SetCoe.forall] at *\n  change A \u2286 (fun f => (u f x\u2080, u f x)) \u207b\u00b9' V at hx\n  refine' (closure_minimal hx <| hVclosed.preimage <| _).trans (preimage_mono hVU)\n  exact Continuous.prod_mk ((continuous_apply x\u2080).comp hu) ((continuous_apply x).comp hu)\n#align equicontinuous_at.closure' EquicontinuousAt.closure'\n\n/- warning: equicontinuous_at.closure -> EquicontinuousAt.closure is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u2} \u03b1] {A : Set.{max u1 u2} (X -> \u03b1)} {x\u2080 : X}, (Set.EquicontinuousAt.{u1, u2} X \u03b1 _inst_1 _inst_4 A x\u2080) -> (Set.EquicontinuousAt.{u1, u2} X \u03b1 _inst_1 _inst_4 (closure.{max u1 u2} (X -> \u03b1) (Pi.topologicalSpace.{u1, u2} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4)) A) x\u2080)\nbut is expected to have type\n  forall {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {A : Set.{max u2 u1} (X -> \u03b1)} {x\u2080 : X}, (Set.EquicontinuousAt.{u2, u1} X \u03b1 _inst_1 _inst_4 A x\u2080) -> (Set.EquicontinuousAt.{u2, u1} X \u03b1 _inst_1 _inst_4 (closure.{max u2 u1} (X -> \u03b1) (Pi.topologicalSpace.{u2, u1} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4)) A) x\u2080)\nCase conversion may be inaccurate. Consider using '#align equicontinuous_at.closure EquicontinuousAt.closure\u2093'. -/\n/-- If a set of functions is equicontinuous at some `x\u2080`, its closure for the product topology is\nalso equicontinuous at `x\u2080`. -/\ntheorem EquicontinuousAt.closure {A : Set <| X \u2192 \u03b1} {x\u2080 : X} (hA : A.EquicontinuousAt x\u2080) :\n    (closure A).EquicontinuousAt x\u2080 :=\n  @EquicontinuousAt.closure' _ _ _ _ _ _ _ id _ hA continuous_id\n#align equicontinuous_at.closure EquicontinuousAt.closure\n\n/- warning: filter.tendsto.continuous_at_of_equicontinuous_at -> Filter.Tendsto.continuousAt_of_equicontinuousAt is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {l : Filter.{u1} \u03b9} [_inst_7 : Filter.NeBot.{u1} \u03b9 l] {F : \u03b9 -> X -> \u03b1} {f : X -> \u03b1} {x\u2080 : X}, (Filter.Tendsto.{u1, max u2 u3} \u03b9 (X -> \u03b1) F l (nhds.{max u2 u3} (X -> \u03b1) (Pi.topologicalSpace.{u2, u3} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4)) f)) -> (EquicontinuousAt.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) -> (ContinuousAt.{u2, u3} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4) f x\u2080)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {l : Filter.{u3} \u03b9} [_inst_7 : Filter.NeBot.{u3} \u03b9 l] {F : \u03b9 -> X -> \u03b1} {f : X -> \u03b1} {x\u2080 : X}, (Filter.Tendsto.{u3, max u2 u1} \u03b9 (X -> \u03b1) F l (nhds.{max u2 u1} (X -> \u03b1) (Pi.topologicalSpace.{u2, u1} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4)) f)) -> (EquicontinuousAt.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F x\u2080) -> (ContinuousAt.{u2, u1} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4) f x\u2080)\nCase conversion may be inaccurate. Consider using '#align filter.tendsto.continuous_at_of_equicontinuous_at Filter.Tendsto.continuousAt_of_equicontinuousAt\u2093'. -/\n/-- If `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` tends to `f : X \u2192 \u03b1` *pointwise* along some nontrivial filter, and if the\nfamily `\ud835\udcd5` is equicontinuous at some `x\u2080 : X`, then the limit is continuous at `x\u2080`. -/\ntheorem Filter.Tendsto.continuousAt_of_equicontinuousAt {l : Filter \u03b9} [l.ne_bot] {F : \u03b9 \u2192 X \u2192 \u03b1}\n    {f : X \u2192 \u03b1} {x\u2080 : X} (h\u2081 : Tendsto F l (\ud835\udcdd f)) (h\u2082 : EquicontinuousAt F x\u2080) :\n    ContinuousAt f x\u2080 :=\n  (equicontinuousAt_iff_range.mp h\u2082).closure.ContinuousAt\n    \u27e8f, mem_closure_of_tendsto h\u2081 <| eventually_of_forall mem_range_self\u27e9\n#align filter.tendsto.continuous_at_of_equicontinuous_at Filter.Tendsto.continuousAt_of_equicontinuousAt\n\n/- warning: equicontinuous.closure' -> Equicontinuous.closure' is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {Y : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : TopologicalSpace.{u2} Y] [_inst_4 : UniformSpace.{u3} \u03b1] {A : Set.{u2} Y} {u : Y -> X -> \u03b1}, (Equicontinuous.{u2, u1, u3} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u2, succ u2, max (succ u1) (succ u3)} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (X -> \u03b1) u ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (CoeTC\u2093.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) A) Y (coeSubtype.{succ u2} Y (fun (x : Y) => Membership.Mem.{u2, u2} Y (Set.{u2} Y) (Set.hasMem.{u2} Y) x A)))))))) -> (Continuous.{u2, max u1 u3} Y (X -> \u03b1) _inst_2 (Pi.topologicalSpace.{u1, u3} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4)) u) -> (Equicontinuous.{u2, u1, u3} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u2, succ u2, max (succ u1) (succ u3)} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (X -> \u03b1) u ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (CoeTC\u2093.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} Y) Type.{u2} (Set.hasCoeToSort.{u2} Y) (closure.{u2} Y _inst_2 A)) Y (coeSubtype.{succ u2} Y (fun (x : Y) => Membership.Mem.{u2, u2} Y (Set.{u2} Y) (Set.hasMem.{u2} Y) x (closure.{u2} Y _inst_2 A)))))))))\nbut is expected to have type\n  forall {X : Type.{u2}} {Y : Type.{u3}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_2 : TopologicalSpace.{u3} Y] [_inst_4 : UniformSpace.{u1} \u03b1] {A : Set.{u3} Y} {u : Y -> X -> \u03b1}, (Equicontinuous.{u3, u2, u1} (Set.Elem.{u3} Y A) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u3, succ u3, max (succ u2) (succ u1)} (Set.Elem.{u3} Y A) Y (X -> \u03b1) u (Subtype.val.{succ u3} Y (fun (x : Y) => Membership.mem.{u3, u3} Y (Set.{u3} Y) (Set.instMembershipSet.{u3} Y) x A)))) -> (Continuous.{u3, max u2 u1} Y (X -> \u03b1) _inst_2 (Pi.topologicalSpace.{u2, u1} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4)) u) -> (Equicontinuous.{u3, u2, u1} (Set.Elem.{u3} Y (closure.{u3} Y _inst_2 A)) X \u03b1 _inst_1 _inst_4 (Function.comp.{succ u3, succ u3, max (succ u2) (succ u1)} (Set.Elem.{u3} Y (closure.{u3} Y _inst_2 A)) Y (X -> \u03b1) u (Subtype.val.{succ u3} Y (fun (x : Y) => Membership.mem.{u3, u3} Y (Set.{u3} Y) (Set.instMembershipSet.{u3} Y) x (closure.{u3} Y _inst_2 A)))))\nCase conversion may be inaccurate. Consider using '#align equicontinuous.closure' Equicontinuous.closure'\u2093'. -/\n/-- A version of `equicontinuous.closure` applicable to subsets of types which embed continuously\ninto `X \u2192 \u03b1` with the product topology. It turns out we don't need any other condition on the\nembedding than continuity, but in practice this will mostly be applied to `fun_like` types where\nthe coercion is injective. -/\ntheorem Equicontinuous.closure' {A : Set Y} {u : Y \u2192 X \u2192 \u03b1}\n    (hA : Equicontinuous (u \u2218 coe : A \u2192 X \u2192 \u03b1)) (hu : Continuous u) :\n    Equicontinuous (u \u2218 coe : closure A \u2192 X \u2192 \u03b1) := fun x => (hA x).closure' hu\n#align equicontinuous.closure' Equicontinuous.closure'\n\n/- warning: equicontinuous.closure -> Equicontinuous.closure is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_4 : UniformSpace.{u2} \u03b1] {A : Set.{max u1 u2} (X -> \u03b1)}, (Set.Equicontinuous.{u1, u2} X \u03b1 _inst_1 _inst_4 A) -> (Set.Equicontinuous.{u1, u2} X \u03b1 _inst_1 _inst_4 (closure.{max u1 u2} (X -> \u03b1) (Pi.topologicalSpace.{u1, u2} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4)) A))\nbut is expected to have type\n  forall {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {A : Set.{max u2 u1} (X -> \u03b1)}, (Set.Equicontinuous.{u2, u1} X \u03b1 _inst_1 _inst_4 A) -> (Set.Equicontinuous.{u2, u1} X \u03b1 _inst_1 _inst_4 (closure.{max u2 u1} (X -> \u03b1) (Pi.topologicalSpace.{u2, u1} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4)) A))\nCase conversion may be inaccurate. Consider using '#align equicontinuous.closure Equicontinuous.closure\u2093'. -/\n/-- If a set of functions is equicontinuous, its closure for the product topology is also\nequicontinuous. -/\ntheorem Equicontinuous.closure {A : Set <| X \u2192 \u03b1} (hA : A.Equicontinuous) :\n    (closure A).Equicontinuous := fun x => (hA x).closure\n#align equicontinuous.closure Equicontinuous.closure\n\n/- warning: filter.tendsto.continuous_of_equicontinuous_at -> Filter.Tendsto.continuous_of_equicontinuous_at is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {X : Type.{u2}} {\u03b1 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u3} \u03b1] {l : Filter.{u1} \u03b9} [_inst_7 : Filter.NeBot.{u1} \u03b9 l] {F : \u03b9 -> X -> \u03b1} {f : X -> \u03b1}, (Filter.Tendsto.{u1, max u2 u3} \u03b9 (X -> \u03b1) F l (nhds.{max u2 u3} (X -> \u03b1) (Pi.topologicalSpace.{u2, u3} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4)) f)) -> (Equicontinuous.{u1, u2, u3} \u03b9 X \u03b1 _inst_1 _inst_4 F) -> (Continuous.{u2, u3} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b1 _inst_4) f)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {X : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} X] [_inst_4 : UniformSpace.{u1} \u03b1] {l : Filter.{u3} \u03b9} [_inst_7 : Filter.NeBot.{u3} \u03b9 l] {F : \u03b9 -> X -> \u03b1} {f : X -> \u03b1}, (Filter.Tendsto.{u3, max u2 u1} \u03b9 (X -> \u03b1) F l (nhds.{max u2 u1} (X -> \u03b1) (Pi.topologicalSpace.{u2, u1} X (fun (\u1fb0 : X) => \u03b1) (fun (a : X) => UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4)) f)) -> (Equicontinuous.{u3, u2, u1} \u03b9 X \u03b1 _inst_1 _inst_4 F) -> (Continuous.{u2, u1} X \u03b1 _inst_1 (UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4) f)\nCase conversion may be inaccurate. Consider using '#align filter.tendsto.continuous_of_equicontinuous_at Filter.Tendsto.continuous_of_equicontinuous_at\u2093'. -/\n/-- If `\ud835\udcd5 : \u03b9 \u2192 X \u2192 \u03b1` tends to `f : X \u2192 \u03b1` *pointwise* along some nontrivial filter, and if the\nfamily `\ud835\udcd5` is equicontinuous, then the limit is continuous. -/\ntheorem Filter.Tendsto.continuous_of_equicontinuous_at {l : Filter \u03b9} [l.ne_bot] {F : \u03b9 \u2192 X \u2192 \u03b1}\n    {f : X \u2192 \u03b1} (h\u2081 : Tendsto F l (\ud835\udcdd f)) (h\u2082 : Equicontinuous F) : Continuous f :=\n  continuous_iff_continuousAt.mpr fun x => h\u2081.continuousAt_of_equicontinuousAt (h\u2082 x)\n#align filter.tendsto.continuous_of_equicontinuous_at Filter.Tendsto.continuous_of_equicontinuous_at\n\n/- warning: uniform_equicontinuous.closure' -> UniformEquicontinuous.closure' is a dubious translation:\nlean 3 declaration is\n  forall {Y : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_2 : TopologicalSpace.{u1} Y] [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {A : Set.{u1} Y} {u : Y -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u1, u2, u3} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) A) \u03b1 \u03b2 _inst_4 _inst_5 (Function.comp.{succ u1, succ u1, max (succ u3) (succ u2)} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) A) Y (\u03b2 -> \u03b1) u ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) A) Y (HasLiftT.mk.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) A) Y (CoeTC\u2093.coe.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) A) Y (coeBase.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) A) Y (coeSubtype.{succ u1} Y (fun (x : Y) => Membership.Mem.{u1, u1} Y (Set.{u1} Y) (Set.hasMem.{u1} Y) x A)))))))) -> (Continuous.{u1, max u3 u2} Y (\u03b2 -> \u03b1) _inst_2 (Pi.topologicalSpace.{u3, u2} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) (fun (a : \u03b2) => UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4)) u) -> (UniformEquicontinuous.{u1, u2, u3} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) (closure.{u1} Y _inst_2 A)) \u03b1 \u03b2 _inst_4 _inst_5 (Function.comp.{succ u1, succ u1, max (succ u3) (succ u2)} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) (closure.{u1} Y _inst_2 A)) Y (\u03b2 -> \u03b1) u ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) (closure.{u1} Y _inst_2 A)) Y (HasLiftT.mk.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) (closure.{u1} Y _inst_2 A)) Y (CoeTC\u2093.coe.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) (closure.{u1} Y _inst_2 A)) Y (coeBase.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} Y) Type.{u1} (Set.hasCoeToSort.{u1} Y) (closure.{u1} Y _inst_2 A)) Y (coeSubtype.{succ u1} Y (fun (x : Y) => Membership.Mem.{u1, u1} Y (Set.{u1} Y) (Set.hasMem.{u1} Y) x (closure.{u1} Y _inst_2 A)))))))))\nbut is expected to have type\n  forall {Y : Type.{u3}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_2 : TopologicalSpace.{u3} Y] [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {A : Set.{u3} Y} {u : Y -> \u03b2 -> \u03b1}, (UniformEquicontinuous.{u3, u2, u1} (Set.Elem.{u3} Y A) \u03b1 \u03b2 _inst_4 _inst_5 (Function.comp.{succ u3, succ u3, max (succ u2) (succ u1)} (Set.Elem.{u3} Y A) Y (\u03b2 -> \u03b1) u (Subtype.val.{succ u3} Y (fun (x : Y) => Membership.mem.{u3, u3} Y (Set.{u3} Y) (Set.instMembershipSet.{u3} Y) x A)))) -> (Continuous.{u3, max u2 u1} Y (\u03b2 -> \u03b1) _inst_2 (Pi.topologicalSpace.{u1, u2} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) (fun (a : \u03b2) => UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4)) u) -> (UniformEquicontinuous.{u3, u2, u1} (Set.Elem.{u3} Y (closure.{u3} Y _inst_2 A)) \u03b1 \u03b2 _inst_4 _inst_5 (Function.comp.{succ u3, succ u3, max (succ u2) (succ u1)} (Set.Elem.{u3} Y (closure.{u3} Y _inst_2 A)) Y (\u03b2 -> \u03b1) u (Subtype.val.{succ u3} Y (fun (x : Y) => Membership.mem.{u3, u3} Y (Set.{u3} Y) (Set.instMembershipSet.{u3} Y) x (closure.{u3} Y _inst_2 A)))))\nCase conversion may be inaccurate. Consider using '#align uniform_equicontinuous.closure' UniformEquicontinuous.closure'\u2093'. -/\n/-- A version of `uniform_equicontinuous.closure` applicable to subsets of types which embed\ncontinuously into `\u03b2 \u2192 \u03b1` with the product topology. It turns out we don't need any other condition\non the embedding than continuity, but in practice this will mostly be applied to `fun_like` types\nwhere the coercion is injective. -/\ntheorem UniformEquicontinuous.closure' {A : Set Y} {u : Y \u2192 \u03b2 \u2192 \u03b1}\n    (hA : UniformEquicontinuous (u \u2218 coe : A \u2192 \u03b2 \u2192 \u03b1)) (hu : Continuous u) :\n    UniformEquicontinuous (u \u2218 coe : closure A \u2192 \u03b2 \u2192 \u03b1) :=\n  by\n  intro U hU\n  rcases mem_uniformity_isClosed hU with \u27e8V, hV, hVclosed, hVU\u27e9\n  filter_upwards [hA V hV]\n  rintro \u27e8x, y\u27e9 hxy\n  rw [SetCoe.forall] at *\n  change A \u2286 (fun f => (u f x, u f y)) \u207b\u00b9' V at hxy\n  refine' (closure_minimal hxy <| hVclosed.preimage <| _).trans (preimage_mono hVU)\n  exact Continuous.prod_mk ((continuous_apply x).comp hu) ((continuous_apply y).comp hu)\n#align uniform_equicontinuous.closure' UniformEquicontinuous.closure'\n\n/- warning: uniform_equicontinuous.closure -> UniformEquicontinuous.closure is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : UniformSpace.{u1} \u03b1] [_inst_5 : UniformSpace.{u2} \u03b2] {A : Set.{max u2 u1} (\u03b2 -> \u03b1)}, (Set.UniformEquicontinuous.{u1, u2} \u03b1 \u03b2 _inst_4 _inst_5 A) -> (Set.UniformEquicontinuous.{u1, u2} \u03b1 \u03b2 _inst_4 _inst_5 (closure.{max u2 u1} (\u03b2 -> \u03b1) (Pi.topologicalSpace.{u2, u1} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) (fun (a : \u03b2) => UniformSpace.toTopologicalSpace.{u1} \u03b1 _inst_4)) A))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {A : Set.{max u2 u1} (\u03b2 -> \u03b1)}, (Set.UniformEquicontinuous.{u2, u1} \u03b1 \u03b2 _inst_4 _inst_5 A) -> (Set.UniformEquicontinuous.{u2, u1} \u03b1 \u03b2 _inst_4 _inst_5 (closure.{max u2 u1} (\u03b2 -> \u03b1) (Pi.topologicalSpace.{u1, u2} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) (fun (a : \u03b2) => UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4)) A))\nCase conversion may be inaccurate. Consider using '#align uniform_equicontinuous.closure UniformEquicontinuous.closure\u2093'. -/\n/-- If a set of functions is uniformly equicontinuous, its closure for the product topology is also\nuniformly equicontinuous. -/\ntheorem UniformEquicontinuous.closure {A : Set <| \u03b2 \u2192 \u03b1} (hA : A.UniformEquicontinuous) :\n    (closure A).UniformEquicontinuous :=\n  @UniformEquicontinuous.closure' _ _ _ _ _ _ _ id hA continuous_id\n#align uniform_equicontinuous.closure UniformEquicontinuous.closure\n\n/- warning: filter.tendsto.uniform_continuous_of_uniform_equicontinuous -> Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u3} \u03b2] {l : Filter.{u1} \u03b9} [_inst_7 : Filter.NeBot.{u1} \u03b9 l] {F : \u03b9 -> \u03b2 -> \u03b1} {f : \u03b2 -> \u03b1}, (Filter.Tendsto.{u1, max u3 u2} \u03b9 (\u03b2 -> \u03b1) F l (nhds.{max u3 u2} (\u03b2 -> \u03b1) (Pi.topologicalSpace.{u3, u2} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) (fun (a : \u03b2) => UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4)) f)) -> (UniformEquicontinuous.{u1, u2, u3} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (UniformContinuous.{u3, u2} \u03b2 \u03b1 _inst_5 _inst_4 f)\nbut is expected to have type\n  forall {\u03b9 : Type.{u3}} {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : UniformSpace.{u2} \u03b1] [_inst_5 : UniformSpace.{u1} \u03b2] {l : Filter.{u3} \u03b9} [_inst_7 : Filter.NeBot.{u3} \u03b9 l] {F : \u03b9 -> \u03b2 -> \u03b1} {f : \u03b2 -> \u03b1}, (Filter.Tendsto.{u3, max u2 u1} \u03b9 (\u03b2 -> \u03b1) F l (nhds.{max u2 u1} (\u03b2 -> \u03b1) (Pi.topologicalSpace.{u1, u2} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) (fun (a : \u03b2) => UniformSpace.toTopologicalSpace.{u2} \u03b1 _inst_4)) f)) -> (UniformEquicontinuous.{u3, u2, u1} \u03b9 \u03b1 \u03b2 _inst_4 _inst_5 F) -> (UniformContinuous.{u1, u2} \u03b2 \u03b1 _inst_5 _inst_4 f)\nCase conversion may be inaccurate. Consider using '#align filter.tendsto.uniform_continuous_of_uniform_equicontinuous Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous\u2093'. -/\n/-- If `\ud835\udcd5 : \u03b9 \u2192 \u03b2 \u2192 \u03b1` tends to `f : \u03b2 \u2192 \u03b1` *pointwise* along some nontrivial filter, and if the\nfamily `\ud835\udcd5` is uniformly equicontinuous, then the limit is uniformly continuous. -/\ntheorem Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous {l : Filter \u03b9} [l.ne_bot]\n    {F : \u03b9 \u2192 \u03b2 \u2192 \u03b1} {f : \u03b2 \u2192 \u03b1} (h\u2081 : Tendsto F l (\ud835\udcdd f)) (h\u2082 : UniformEquicontinuous F) :\n    UniformContinuous f :=\n  (uniformEquicontinuous_at_iff_range.mp h\u2082).closure.UniformContinuous\n    \u27e8f, mem_closure_of_tendsto h\u2081 <| eventually_of_forall mem_range_self\u27e9\n#align filter.tendsto.uniform_continuous_of_uniform_equicontinuous Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous\n\nend\n\nend\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/UniformSpace/Equicontinuity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782094, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7306955706877677}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n-/\nimport data.list.sort\nimport data.nat.gcd\nimport data.nat.sqrt\nimport tactic.norm_num\nimport tactic.wlog\n\n/-!\n# Prime numbers\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\nAll the following declarations exist in the namespace `nat`.\n\n- `prime`: the predicate that expresses that a natural number `p` is prime\n- `primes`: the subtype of natural numbers that are prime\n- `min_fac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers\n- `factors n`: the prime factorization of `n`\n- `factors_unique`: uniqueness of the prime factorisation\n\n-/\n\nopen bool subtype\nopen_locale nat\n\nnamespace nat\n\n/-- `prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\n@[pp_nodot]\ndef prime (p : \u2115) := 2 \u2264 p \u2227 \u2200 m \u2223 p, m = 1 \u2228 m = p\n\ntheorem prime.two_le {p : \u2115} : prime p \u2192 2 \u2264 p := and.left\n\ntheorem prime.one_lt {p : \u2115} : prime p \u2192 1 < p := prime.two_le\n\ninstance prime.one_lt' (p : \u2115) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := \u27e8hp.1.one_lt\u27e9\n\nlemma prime.ne_one {p : \u2115} (hp : p.prime) : p \u2260 1 :=\nne.symm $ ne_of_lt hp.one_lt\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\nand_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h l d, (h d).resolve_right (ne_of_lt l),\n \u03bb h d, (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left (\u03bb l, h l d)\u27e9\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00ac m \u2223 p :=\nprime_def_lt.trans $ and_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h m2 l d, not_lt_of_ge m2 ((h l d).symm \u25b8 dec_trivial),\n\u03bb h l d, begin\n  rcases m with _|_|m,\n  { rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },\n  { refl },\n  { exact (h dec_trivial l).elim d }\nend\u27e9\n\ntheorem prime_def_le_sqrt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227\n  \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac m \u2223 p :=\nprime_def_lt'.trans $ and_congr_right $ \u03bb p2,\n\u27e8\u03bb a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,\n \u03bb a, have \u2200 {m k}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k, from\n  \u03bb m k mk m1 e, a m m1\n    (le_sqrt.2 (e.symm \u25b8 nat.mul_le_mul_left m mk)) \u27e8k, e\u27e9,\n  \u03bb m m2 l \u27e8k, e\u27e9, begin\n    cases (le_total m k) with mk km,\n    { exact this mk m2 e },\n    { rw [mul_comm] at e,\n      refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,\n      rwa [one_mul, \u2190 e] }\n  end\u27e9\n\ntheorem prime_of_coprime (n : \u2115) (h1 : 1 < n) (h : \u2200 m < n, m \u2260 0 \u2192 n.coprime m) : prime n :=\nbegin\n  refine prime_def_lt.mpr \u27e8h1, \u03bb m mlt mdvd, _\u27e9,\n  have hm : m \u2260 0,\n  { rintro rfl,\n    rw zero_dvd_iff at mdvd,\n    exact mlt.ne' mdvd },\n  exact (h m mlt hm).symm.eq_one_of_dvd mdvd,\nend\n\nsection\n\n/--\n  This instance is slower than the instance `decidable_prime` defined below,\n  but has the advantage that it works in the kernel for small values.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\nlocal attribute [instance]\ndef decidable_prime_1 (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_lt'\n\nlemma prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 :=\nby { rintro rfl, revert h, dec_trivial }\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : 0 < p :=\nlt_of_succ_lt pp.one_lt\n\ntheorem not_prime_zero : \u00ac prime 0 := by simp [prime]\n\ntheorem not_prime_one : \u00ac prime 1 := by simp [prime]\n\ntheorem prime_two : prime 2 := dec_trivial\n\nend\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : 0 < pred p :=\nlt_pred_iff.2 pp.one_lt\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : succ (pred p) = p :=\nsucc_pred_eq_of_pos pp.pos\n\ntheorem dvd_prime {p m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n\u27e8\u03bb d, pp.2 m d, \u03bb h, h.elim (\u03bb e, e.symm \u25b8 one_dvd _) (\u03bb e, e.symm \u25b8 dvd_rfl)\u27e9\n\ntheorem dvd_prime_two_le {p m : \u2115} (pp : prime p) (H : 2 \u2264 m) : m \u2223 p \u2194 m = p :=\n(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H\n\ntheorem prime_dvd_prime_iff_eq {p q : \u2115} (pp : p.prime) (qp : q.prime) : p \u2223 q \u2194 p = q :=\ndvd_prime_two_le qp (prime.two_le pp)\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00ac p \u2223 1\n| d := (not_le_of_gt pp.one_lt) $ le_of_dvd dec_trivial d\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00ac prime (a * b) :=\n\u03bb h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $\nby simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)\n\nlemma not_prime_mul' {a b n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) : \u00ac prime n :=\nby { rw \u2190 h, exact not_prime_mul h\u2081 h\u2082 }\n\nsection min_fac\n\nprivate lemma min_fac_lemma (n k : \u2115) (h : \u00ac n < k * k) :\n  sqrt n - k < sqrt n + 2 - k :=\n(tsub_lt_tsub_iff_right $ le_sqrt.2 $ le_of_not_gt h).2 $\nnat.lt_add_of_pos_right dec_trivial\n\n/-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.\n  Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.\n  If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/\ndef min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115 | k :=\nif h : n < k * k then n else\nif k \u2223 n then k else\nhave _, from min_fac_lemma n k h,\nmin_fac_aux (k + 2)\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n/-- Returns the smallest prime factor of `n \u2260 1`. -/\ndef min_fac : \u2115 \u2192 \u2115\n| 0 := 2\n| 1 := 1\n| (n+2) := if 2 \u2223 n then 2 else min_fac_aux (n + 2) 3\n\n@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl\n@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\ntheorem min_fac_eq : \u2200 n, min_fac n = if 2 \u2223 n then 2 else min_fac_aux n 3\n| 0     := by simp\n| 1     := by simp [show 2\u22601, from dec_trivial]; rw min_fac_aux; refl\n| (n+2) :=\n  have 2 \u2223 n + 2 \u2194 2 \u2223 n, from\n    (nat.dvd_add_iff_left (by refl)).symm,\n  by simp [min_fac, this]; congr\n\nprivate def min_fac_prop (n k : \u2115) :=\n  2 \u2264 k \u2227 k \u2223 n \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m\n\ntheorem min_fac_aux_has_prop {n : \u2115} (n2 : 2 \u2264 n) (nd2 : \u00ac 2 \u2223 n) :\n  \u2200 k i, k = 2*i+3 \u2192 (\u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k)\n| k := \u03bb i e a, begin\n  rw min_fac_aux,\n  by_cases h : n < k*k; simp [h],\n  { have pp : prime n :=\n      prime_def_le_sqrt.2 \u27e8n2, \u03bb m m2 l d,\n        not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9,\n    from \u27e8n2, dvd_rfl, \u03bb m m2 d, le_of_eq\n      ((dvd_prime_two_le pp m2).1 d).symm\u27e9 },\n  have k2 : 2 \u2264 k, { subst e, exact dec_trivial },\n  by_cases dk : k \u2223 n; simp [dk],\n  { exact \u27e8k2, dk, a\u27e9 },\n  { refine have _, from min_fac_lemma n k h,\n      min_fac_aux_has_prop (k+2) (i+1)\n        (by simp [e, left_distrib]) (\u03bb m m2 d, _),\n    cases nat.eq_or_lt_of_le (a m m2 d) with me ml,\n    { subst me, contradiction },\n    apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,\n    rw [\u2190 me, e] at d, change 2 * (i + 2) \u2223 n at d,\n    have := dvd_of_mul_right_dvd d, contradiction }\nend\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\ntheorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) :\n  min_fac_prop n (min_fac n) :=\nbegin\n  by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},\n  have n2 : 2 \u2264 n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },\n  simp [min_fac_eq],\n  by_cases d2 : 2 \u2223 n; simp [d2],\n  { exact \u27e8le_refl _, d2, \u03bb k k2 d, k2\u27e9 },\n  { refine min_fac_aux_has_prop n2 d2 3 0 rfl\n      (\u03bb m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),\n    exact \u03bb e, e.symm \u25b8 d }\nend\n\ntheorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\nif n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1\n\ntheorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) :=\nlet \u27e8f2, fd, a\u27e9 := min_fac_has_prop n1 in\nprime_def_lt'.2 \u27e8f2, \u03bb m m2 l d, not_le_of_gt l (a m m2 (d.trans fd))\u27e9\n\ntheorem min_fac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, 2 \u2264 m \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\nby by_cases n1 : n = 1;\n  [exact \u03bb m m2 d, n1.symm \u25b8 le_trans dec_trivial m2,\n    exact (min_fac_has_prop n1).2.2]\n\ntheorem min_fac_pos (n : \u2115) : 0 < min_fac n :=\nby by_cases n1 : n = 1;\n    [exact n1.symm \u25b8 dec_trivial, exact (min_fac_prime n1).pos]\n\ntheorem min_fac_le {n : \u2115} (H : 0 < n) : min_fac n \u2264 n :=\nle_of_dvd H (min_fac_dvd n)\n\ntheorem le_min_fac {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, prime p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p pp d, h.elim\n  (by rintro rfl; cases pp.not_dvd_one d)\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp.two_le d),\n  \u03bb H, or_iff_not_imp_left.2 $ \u03bb n1, H _ (min_fac_prime n1) (min_fac_dvd _)\u27e9\n\ntheorem le_min_fac' {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, 2 \u2264 p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p (pp:1<p) d, h.elim\n  (by rintro rfl; cases not_le_of_lt pp (le_of_dvd dec_trivial d))\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp d),\n  \u03bb H, le_min_fac.2 (\u03bb p pp d, H p pp.two_le d)\u27e9\n\ntheorem prime_def_min_fac {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 min_fac p = p :=\n\u27e8\u03bb pp, \u27e8pp.two_le,\n  let \u27e8f2, fd, a\u27e9 := min_fac_has_prop $ ne_of_gt pp.one_lt in\n  ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n  \u03bb \u27e8p2, e\u27e9, e \u25b8 min_fac_prime (ne_of_gt p2)\u27e9\n\n/--\nThis instance is faster in the virtual machine than `decidable_prime_1`,\nbut slower in the kernel.\n\nIf you need to prove that a particular number is prime, in any case\nyou should not use `dec_trivial`, but rather `by norm_num`, which is\nmuch faster.\n-/\ninstance decidable_prime (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_min_fac\n\ntheorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : 2 \u2264 n) : \u00ac prime n \u2194 min_fac n < n :=\n(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $\n  (lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm\n\nlemma min_fac_le_div {n : \u2115} (pos : 0 < n) (np : \u00ac prime n) : min_fac n \u2264 n / min_fac n :=\nmatch min_fac_dvd n with\n| \u27e80, h0\u27e9     := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial\n| \u27e81, h1\u27e9     :=\n  begin\n    rw mul_one at h1,\n    rw [prime_def_min_fac, not_and_distrib, \u2190 h1, eq_self_iff_true, not_true, or_false,\n      not_le] at np,\n    rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]\n  end\n| \u27e8(x+2), hx\u27e9 :=\n  begin\n    conv_rhs { congr, rw hx },\n    rw [nat.mul_div_cancel_left _ (min_fac_pos _)],\n    exact min_fac_le_of_dvd dec_trivial \u27e8min_fac n, by rwa mul_comm\u27e9\n  end\nend\n\n/--\nThe square of the smallest prime factor of a composite number `n` is at most `n`.\n-/\nlemma min_fac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00ac prime n) : (min_fac n)^2 \u2264 n :=\nhave t : (min_fac n) \u2264 (n/min_fac n) := min_fac_le_div w h,\ncalc\n(min_fac n)^2 = (min_fac n) * (min_fac n)   : sq (min_fac n)\n          ... \u2264 (n/min_fac n) * (min_fac n) : nat.mul_le_mul_right (min_fac n) t\n          ... \u2264 n                           : div_mul_le_self n (min_fac n)\n\n@[simp]\nlemma min_fac_eq_one_iff {n : \u2115} : min_fac n = 1 \u2194 n = 1 :=\nbegin\n  split,\n  { intro h,\n    by_contradiction hn,\n    have := min_fac_prime hn,\n    rw h at this,\n    exact not_prime_one this, },\n  { rintro rfl, refl, }\nend\n\n@[simp]\nlemma min_fac_eq_two_iff (n : \u2115) : min_fac n = 2 \u2194 2 \u2223 n :=\nbegin\n  split,\n  { intro h,\n    convert min_fac_dvd _,\n    rw h, },\n  { intro h,\n    have ub := min_fac_le_of_dvd (le_refl 2) h,\n    have lb := min_fac_pos n,\n    apply ub.eq_or_lt.resolve_right (\u03bb h', _),\n    have := le_antisymm (nat.succ_le_of_lt lb) (lt_succ_iff.mp h'),\n    rw [eq_comm, nat.min_fac_eq_one_iff] at this,\n    subst this,\n    exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two }\nend\n\nend min_fac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n\u27e8min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,\n  ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 2 \u2264 m \u2227 m < n :=\n\u27e8min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,\n  (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_prime_and_dvd {n : \u2115} (n2 : 2 \u2264 n) : \u2203 p, prime p \u2227 p \u2223 n :=\n\u27e8min_fac n, min_fac_prime (ne_of_gt n2), min_fac_dvd _\u27e9\n\n/-- Euclid's theorem on the **infinitude of primes**.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, n \u2264 p \u2227 prime p :=\nlet p := min_fac (n! + 1) in\nhave f1 : n! + 1 \u2260 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,\nhave pp : prime p, from min_fac_prime f1,\nhave np : n \u2264 p, from le_of_not_ge $ \u03bb h,\n  have h\u2081 : p \u2223 n!, from dvd_factorial (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  pp.not_dvd_one h\u2082,\n\u27e8p, np, pp\u27e9\n\nlemma prime.eq_two_or_odd {p : \u2115} (hp : prime p) : p = 2 \u2228 p % 2 = 1 :=\np.mod_two_eq_zero_or_one.imp_left\n  (\u03bb h, ((hp.2 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)\n\ntheorem coprime_of_dvd {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 \u00ac k \u2223 n) : coprime m n :=\nbegin\n  have g1 : 1 \u2264 gcd m n,\n  { refine nat.succ_le_of_lt (pos_iff_ne_zero.mpr (\u03bb g0, _)),\n    rw [eq_zero_of_gcd_eq_zero_left g0, eq_zero_of_gcd_eq_zero_right g0] at H,\n    exact H 2 prime_two (dvd_zero _) (dvd_zero _) },\n  rw [coprime_iff_gcd_eq_one, eq_comm],\n  refine g1.lt_or_eq.resolve_left (\u03bb g2, _),\n  obtain \u27e8p, hp, hpdvd\u27e9 := exists_prime_and_dvd (succ_le_of_lt g2),\n  apply H p hp; apply dvd_trans hpdvd,\n  { exact gcd_dvd_left _ _ },\n  { exact gcd_dvd_right _ _ }\nend\n\ntheorem coprime_of_dvd' {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) : coprime m n :=\ncoprime_of_dvd $ \u03bbk kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn\n\ntheorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=\ndiv_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 list \u2115\n| 0 := []\n| 1 := []\n| n@(k+2) :=\n  let m := min_fac n in have n / m < n := factors_lemma,\n  m :: factors (n / m)\n\n@[simp] lemma factors_zero : factors 0 = [] := by rw factors\n@[simp] lemma factors_one : factors 1 = [] := by rw factors\n\nlemma prime_of_mem_factors : \u2200 {n p}, p \u2208 factors n \u2192 prime p\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb p h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  have h\u2081 : p = m \u2228 p \u2208 (factors (n / m)) :=\n    (list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),\n  or.cases_on h\u2081 (\u03bb h\u2082, h\u2082.symm \u25b8 min_fac_prime dec_trivial)\n    prime_of_mem_factors\n\nlemma prod_factors : \u2200 {n}, 0 < n \u2192 list.prod (factors n) = n\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  show (factors n).prod = n, from\n  have h\u2081 : 0 < n / m :=\n    nat.pos_of_ne_zero $ \u03bb h,\n    have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,\n    by rw zero_mul at this; exact (show k + 2 \u2260 0, from dec_trivial) this,\n  by rw [factors, list.prod_cons, prod_factors h\u2081, nat.mul_div_cancel' (min_fac_dvd _)]\n\nlemma factors_prime {p : \u2115} (hp : nat.prime p) : p.factors = [p] :=\nbegin\n  have : p = (p - 2) + 2 := (tsub_eq_iff_eq_add_of_le hp.1).mp rfl,\n  rw [this, nat.factors],\n  simp only [eq.symm this],\n  have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,\n  split,\n  { exact this, },\n  { simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },\nend\n\nlemma factors_chain : \u2200 {n a}, (\u2200 p, prime p \u2192 p \u2223 n \u2192 a \u2264 p) \u2192 list.chain (\u2264) a (factors n)\n| 0       := \u03bb a h, by simp\n| 1       := \u03bb a h, by simp\n| n@(k+2) := \u03bb a h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  begin\n    rw factors,\n    refine list.chain.cons ((le_min_fac.2 h).resolve_left dec_trivial) (factors_chain _),\n    exact \u03bb p pp d, min_fac_le_of_dvd pp.two_le (d.trans $ div_dvd_of_dvd $ min_fac_dvd _),\n  end\n\nlemma factors_chain_2 (n) : list.chain (\u2264) 2 (factors n) := factors_chain $ \u03bb p pp _, pp.two_le\n\nlemma factors_chain' (n) : list.chain' (\u2264) (factors n) :=\n@list.chain'.tail _ _ (_::_) (factors_chain_2 _)\n\nlemma factors_sorted (n : \u2115) : list.sorted (\u2264) (factors n) :=\n(list.chain'_iff_pairwise (@le_trans _ _)).1 (factors_chain' _)\n\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\nlemma factors_add_two (n : \u2115) :\n  factors (n+2) = min_fac (n+2) :: factors ((n+2) / min_fac (n+2)) :=\nby rw factors\n\n@[simp]\nlemma factors_eq_nil (n : \u2115) : n.factors = [] \u2194 n = 0 \u2228 n = 1 :=\nbegin\n  split; intro h,\n  { rcases n with (_ | _ | n),\n    { exact or.inl rfl },\n    { exact or.inr rfl },\n    { rw factors at h, injection h }, },\n  { rcases h with (rfl | rfl),\n    { exact factors_zero },\n    { exact factors_one }, }\nend\n\nlemma eq_of_perm_factors {a b : \u2115} (ha : 0 < a) (hb : 0 < b) (h : a.factors ~ b.factors) : a = b :=\nby simpa [prod_factors ha, prod_factors hb] using list.perm.prod_eq h\n\nlemma eq_of_count_factors_eq {a b : \u2115} (ha : 0 < a) (hb : 0 < b)\n  (h : \u2200 p : \u2115, list.count p a.factors = list.count p b.factors) : a = b :=\neq_of_perm_factors ha hb (list.perm_iff_count.mpr h)\n\ntheorem prime.coprime_iff_not_dvd {p n : \u2115} (pp : prime p) : coprime p n \u2194 \u00ac p \u2223 n :=\n\u27e8\u03bb co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),\n \u03bb nd, coprime_of_dvd $ \u03bb m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm \u25b8 nd\u27e9\n\ntheorem prime.dvd_iff_not_coprime {p n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00ac coprime p n :=\niff_not_comm.2 pp.coprime_iff_not_dvd\n\ntheorem prime.not_coprime_iff_dvd {m n : \u2115} :\n  \u00ac coprime m n \u2194 \u2203p, prime p \u2227 p \u2223 m \u2227 p \u2223 n :=\nbegin\n  apply iff.intro,\n  { intro h,\n    exact \u27e8min_fac (gcd m n), min_fac_prime h,\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_left m n)),\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_right m n))\u27e9 },\n  { intro h,\n    cases h with p hp,\n    apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }\nend\n\ntheorem prime.dvd_mul {p m n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n\u27e8\u03bb H, or_iff_not_imp_left.2 $ \u03bb h,\n  (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n or.rec (\u03bb h : p \u2223 m, h.mul_right _) (\u03bb h : p \u2223 n, h.mul_left _)\u27e9\n\ntheorem prime.not_dvd_mul {p m n : \u2115} (pp : prime p)\n  (Hm : \u00ac p \u2223 m) (Hn : \u00ac p \u2223 n) : \u00ac p \u2223 m * n :=\nmt pp.dvd_mul.1 $ by simp [Hm, Hn]\n\ntheorem prime.dvd_of_dvd_pow {p m n : \u2115} (pp : prime p) (h : p \u2223 m^n) : p \u2223 m :=\nbegin\n  induction n with n IH,\n  { exact pp.not_dvd_one.elim h },\n  { rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH }\nend\n\nlemma prime.pow_dvd_of_dvd_mul_right {p n a b : \u2115} (hp : p.prime) (h : p ^ n \u2223 a * b)\n  (hpb : \u00ac p \u2223 b) : p ^ n \u2223 a :=\nbegin\n  induction n with n ih,\n  { simp only [one_dvd, pow_zero] },\n  { rw [pow_succ'] at *,\n    rcases ih ((dvd_mul_right _ _).trans h) with \u27e8c, rfl\u27e9,\n    rw [mul_assoc] at h,\n    rcases hp.dvd_mul.1 (nat.dvd_of_mul_dvd_mul_left (pow_pos hp.pos _) h)\n      with \u27e8d, rfl\u27e9|\u27e8d, rfl\u27e9,\n    { rw [\u2190 mul_assoc],\n      exact dvd_mul_right _ _ },\n    { exact (hpb (dvd_mul_right _ _)).elim } }\nend\n\nlemma prime.pow_dvd_of_dvd_mul_left {p n a b : \u2115} (hp : p.prime) (h : p ^ n \u2223 a * b)\n  (hpb : \u00ac p \u2223 a) : p ^ n \u2223 b :=\nby rw [mul_comm] at h; exact hp.pow_dvd_of_dvd_mul_right h hpb\n\nlemma prime.pow_not_prime {x n : \u2115} (hn : 2 \u2264 n) : \u00ac (x ^ n).prime :=\n\u03bb hp, (hp.2 x $ dvd_trans \u27e8x, sq _\u27e9 (pow_dvd_pow _ hn)).elim\n  (\u03bb hx1, hp.ne_one $ hx1.symm \u25b8 one_pow _)\n  (\u03bb hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm\n     ... < x ^ n : nat.pow_right_strict_mono (hxn.symm \u25b8 hp.two_le) hn\n     ... = x : hxn.symm)\n\nlemma prime.pow_not_prime' {x : \u2115} : \u2200 {n : \u2115}, n \u2260 1 \u2192 \u00ac (x ^ n).prime\n| 0     := \u03bb _, not_prime_one\n| 1     := \u03bb h, (h rfl).elim\n| (n+2) := \u03bb _, prime.pow_not_prime le_add_self\n\nlemma prime.eq_one_of_pow {x n : \u2115} (h : (x ^ n).prime) : n = 1 :=\nnot_imp_not.mp prime.pow_not_prime' h\n\nlemma prime.pow_eq_iff {p a k : \u2115} (hp : p.prime) : a ^ k = p \u2194 a = p \u2227 k = 1 :=\nbegin\n  refine \u27e8_, \u03bb h, by rw [h.1, h.2, pow_one]\u27e9,\n  rintro rfl,\n  rw [hp.eq_one_of_pow, eq_self_iff_true, and_true, pow_one],\nend\n\nlemma prime.mul_eq_prime_sq_iff {x y p : \u2115} (hp : p.prime) (hx : x \u2260 1) (hy : y \u2260 1) :\n  x * y = p ^ 2 \u2194 x = p \u2227 y = p :=\n\u27e8\u03bb h, have pdvdxy : p \u2223 x * y, by rw h; simp [sq],\nbegin\n  wlog := hp.dvd_mul.1 pdvdxy using x y,\n  cases case with a ha,\n  have hap : a \u2223 p, from \u27e8y, by rwa [ha, sq,\n        mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at h\u27e9,\n  exact ((nat.dvd_prime hp).1 hap).elim\n    (\u03bb _, by clear_aux_decl; simp [*, sq, nat.mul_right_inj hp.pos] at *\n      {contextual := tt})\n    (\u03bb _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,\n      nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *\n      {contextual := tt})\nend,\n\u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.symm \u25b8 h\u2082.symm \u25b8 (sq _).symm\u27e9\n\nlemma prime.dvd_factorial : \u2200 {n p : \u2115} (hp : prime p), p \u2223 n! \u2194 p \u2264 n\n| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)\n| (n+1) p hp := begin\n  rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],\n  exact \u27e8\u03bb h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,\n    \u03bb h, (_root_.lt_or_eq_of_le h).elim (or.inr \u2218 le_of_lt_succ)\n      (\u03bb h, or.inl $ by rw h)\u27e9\nend\n\ntheorem prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : prime p) (h : \u00ac p \u2223 a) : coprime a (p^m) :=\n(pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n\ntheorem coprime_primes {p q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\npp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : prime p) (pq : prime q) (h : p \u2260 q) :\n  coprime (p^n) (q^m) :=\n((coprime_primes pp pq).2 h).pow _ _\n\ntheorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\nby rw [pp.dvd_iff_not_coprime]; apply em\n\nlemma coprime_of_lt_prime {n p} (n_pos : 0 < n) (hlt : n < p) (pp : prime p) :\n  coprime p n :=\n(coprime_or_dvd_of_prime pp n).resolve_right $ \u03bb h, lt_le_antisymm hlt (le_of_dvd n_pos h)\n\nlemma eq_or_coprime_of_le_prime {n p} (n_pos : 0 < n) (hle : n \u2264 p) (pp : prime p) :\n  p = n \u2228 coprime p n :=\nhle.eq_or_lt.imp eq.symm (\u03bb h, coprime_of_lt_prime n_pos h pp)\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m i : \u2115} : i \u2223 (p^m) \u2194 \u2203 k \u2264 m, i = p^k :=\nbegin\n  induction m with m IH generalizing i, { simp },\n  by_cases p \u2223 i,\n  { cases h with a e, subst e,\n    rw [pow_succ, nat.mul_dvd_mul_iff_left pp.pos, IH],\n    split; intro h; rcases h with \u27e8k, h, e\u27e9,\n    { exact \u27e8succ k, succ_le_succ h, by rw [e, pow_succ]; refl\u27e9 },\n    cases k with k,\n    { apply pp.not_dvd_one.elim,\n      rw [\u2190 pow_zero, \u2190 e], apply dvd_mul_right },\n    { refine \u27e8k, le_of_succ_le_succ h, _\u27e9,\n      rwa [mul_comm, pow_succ', nat.mul_left_inj pp.pos] at e } },\n  { split; intro d,\n    { rw (pp.coprime_pow_of_not_dvd h).eq_one_of_dvd d,\n      exact \u27e80, zero_le _, (pow_zero p).symm\u27e9 },\n    { rcases d with \u27e8k, l, rfl\u27e9,\n      exact pow_dvd_pow _ l } }\nend\n\n/--\nIf `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\nlemma eq_prime_pow_of_dvd_least_prime_pow\n  {a p k : \u2115} (pp : prime p) (h\u2081 : \u00ac(a \u2223 p^k)) (h\u2082 : a \u2223 p^(k+1)) :\n  a = p^(k+1) :=\nbegin\n  obtain \u27e8l, \u27e8h, rfl\u27e9\u27e9 := (dvd_prime_pow pp).1 h\u2082,\n  congr,\n  exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h\u2081)),\nend\n\nlemma ne_one_iff_exists_prime_dvd : \u2200 {n}, n \u2260 1 \u2194 \u2203 p : \u2115, p.prime \u2227 p \u2223 n\n| 0 := by simpa using (Exists.intro 2 nat.prime_two)\n| 1 := by simp [nat.not_prime_one]\n| (n+2) :=\nlet a := n+2 in\nlet ha : a \u2260 1 := nat.succ_succ_ne_one n in\nbegin\n  simp only [true_iff, ne.def, not_false_iff, ha],\n  exact \u27e8a.min_fac, nat.min_fac_prime ha, a.min_fac_dvd\u27e9,\nend\n\nlemma eq_one_iff_not_exists_prime_dvd {n : \u2115} : n = 1 \u2194 \u2200 p : \u2115, p.prime \u2192 \u00acp \u2223 n :=\nby simpa using not_iff_not.mpr ne_one_iff_exists_prime_dvd\n\nsection\nopen list\n\nlemma mem_list_primes_of_dvd_prod {p : \u2115} (hp : prime p) :\n  \u2200 {l : list \u2115}, (\u2200 p \u2208 l, prime p) \u2192 p \u2223 prod l \u2192 p \u2208 l\n| []       := \u03bb h\u2081 h\u2082, absurd h\u2082 (prime.not_dvd_one hp)\n| (q :: l) := \u03bb h\u2081 h\u2082,\n  have h\u2083 : p \u2223 q * prod l := @prod_cons _ _ l q \u25b8 h\u2082,\n  have hq : prime q := h\u2081 q (mem_cons_self _ _),\n  or.cases_on ((prime.dvd_mul hp).1 h\u2083)\n    (\u03bb h, by rw [prime.dvd_iff_not_coprime hp, coprime_primes hp hq, ne.def, not_not] at h;\n      exact h \u25b8 mem_cons_self _ _)\n    (\u03bb h, have hl : \u2200 p \u2208 l, prime p := \u03bb p hlp, h\u2081 p ((mem_cons_iff _ _ _).2 (or.inr hlp)),\n    (mem_cons_iff _ _ _).2 (or.inr (mem_list_primes_of_dvd_prod hl h)))\n\nlemma mem_factors_iff_dvd {n p : \u2115} (hn : 0 < n) (hp : prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n\u27e8\u03bb h, prod_factors hn \u25b8 list.dvd_prod h,\n \u03bb h, mem_list_primes_of_dvd_prod hp (@prime_of_mem_factors n) ((prod_factors hn).symm \u25b8 h)\u27e9\n\nlemma dvd_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2223 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { exact dvd_zero p },\n  { rwa \u2190mem_factors_iff_dvd hn (prime_of_mem_factors h) }\nend\n\nlemma mem_factors {n p} (hn : 0 < n) : p \u2208 factors n \u2194 prime p \u2227 p \u2223 n :=\n\u27e8\u03bb h, \u27e8prime_of_mem_factors h, (mem_factors_iff_dvd hn $ prime_of_mem_factors h).mp h\u27e9,\n \u03bb \u27e8hprime, hdvd\u27e9, (mem_factors_iff_dvd hn hprime).mpr hdvd\u27e9\n\nlemma factors_subset_right {n k : \u2115} (h : k \u2260 0) : n.factors \u2286 (n * k).factors :=\nbegin\n  cases n,\n  { rw zero_mul, refl },\n  cases n,\n  { rw factors_one, apply list.nil_subset },\n  intros p hp,\n  rw mem_factors succ_pos' at hp,\n  rw mem_factors (nat.mul_pos succ_pos' (nat.pos_of_ne_zero h)),\n  exact \u27e8hp.1, hp.2.mul_right k\u27e9,\nend\n\nlemma factors_subset_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors \u2286 k.factors :=\nbegin\n  obtain \u27e8a, rfl\u27e9 := h,\n  exact factors_subset_right (right_ne_zero_of_mul h'),\nend\n\nlemma perm_of_prod_eq_prod : \u2200 {l\u2081 l\u2082 : list \u2115}, prod l\u2081 = prod l\u2082 \u2192\n  (\u2200 p \u2208 l\u2081, prime p) \u2192 (\u2200 p \u2208 l\u2082, prime p) \u2192 l\u2081 ~ l\u2082\n| []        []        _  _  _  := perm.nil\n| []        (a :: l)  h\u2081 h\u2082 h\u2083 :=\n  have ha : a \u2223 1 := @prod_nil \u2115 _ \u25b8 h\u2081.symm \u25b8 (@prod_cons _ _ l a).symm \u25b8 dvd_mul_right _ _,\n  absurd ha (prime.not_dvd_one (h\u2083 a (mem_cons_self _ _)))\n| (a :: l)  []        h\u2081 h\u2082 h\u2083 :=\n  have ha : a \u2223 1 := @prod_nil \u2115 _ \u25b8 h\u2081 \u25b8 (@prod_cons _ _ l a).symm \u25b8 dvd_mul_right _ _,\n  absurd ha (prime.not_dvd_one (h\u2082 a (mem_cons_self _ _)))\n| (a :: l\u2081) (b :: l\u2082) h hl\u2081 hl\u2082 :=\n  have hl\u2081' : \u2200 p \u2208 l\u2081, prime p := \u03bb p hp, hl\u2081 p (mem_cons_of_mem _ hp),\n  have hl\u2082' : \u2200 p \u2208 (b :: l\u2082).erase a, prime p := \u03bb p hp, hl\u2082 p (mem_of_mem_erase hp),\n  have ha : a \u2208 (b :: l\u2082) := mem_list_primes_of_dvd_prod (hl\u2081 a (mem_cons_self _ _)) hl\u2082\n    (h \u25b8 by rw prod_cons; exact dvd_mul_right _ _),\n  have hb : b :: l\u2082 ~ a :: (b :: l\u2082).erase a := perm_cons_erase ha,\n  have hl : prod l\u2081 = prod ((b :: l\u2082).erase a) :=\n  (nat.mul_right_inj (prime.pos (hl\u2081 a (mem_cons_self _ _)))).1 $\n    by rwa [\u2190 prod_cons, \u2190 prod_cons, \u2190 hb.prod_eq],\n  perm.trans ((perm_of_prod_eq_prod hl hl\u2081' hl\u2082').cons _) hb.symm\n\n/-- **Fundamental theorem of arithmetic**-/\nlemma factors_unique {n : \u2115} {l : list \u2115} (h\u2081 : prod l = n) (h\u2082 : \u2200 p \u2208 l, prime p) :\n  l ~ factors n :=\nbegin\n  refine perm_of_prod_eq_prod _ h\u2082 (\u03bb p, prime_of_mem_factors),\n  rw h\u2081,\n  refine (prod_factors (nat.pos_of_ne_zero _)).symm,\n  rintro rfl,\n  rw prod_eq_zero_iff at h\u2081,\n  exact prime.ne_zero (h\u2082 0 h\u2081) rfl,\nend\n\nlemma prime.factors_pow {p : \u2115} (hp : p.prime) (n : \u2115) :\n  (p ^ n).factors = list.repeat p n :=\nbegin\n  symmetry,\n  rw \u2190 list.repeat_perm,\n  apply nat.factors_unique (list.prod_repeat p n),\n  intros q hq,\n  rwa eq_of_mem_repeat hq,\nend\n\n/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul_of_pos {a b : \u2115} (ha : 0 < a) (hb : 0 < b) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  refine (factors_unique _ _).symm,\n  { rw [list.prod_append, prod_factors ha, prod_factors hb] },\n  { intros p hp,\n    rw list.mem_append at hp,\n    cases hp;\n    exact prime_of_mem_factors hp },\nend\n\n/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  exact perm_factors_mul_of_pos ha hb,\nend\n\n/-- For positive `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\nlemma count_factors_mul_of_pos {p a b : \u2115} (ha : 0 < a) (hb : 0 < b) :\n  list.count p (a * b).factors = list.count p a.factors + list.count p b.factors :=\nby rw [perm_iff_count.mp (perm_factors_mul_of_pos ha hb) p, count_append]\n\n/-- For coprime `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\nlemma count_factors_mul_of_coprime {p a b : \u2115} (hab : coprime a b)  :\n  list.count p (a * b).factors = list.count p a.factors + list.count p b.factors :=\nby rw [perm_iff_count.mp (perm_factors_mul_of_coprime hab) p, count_append]\n\n/-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/\nlemma factors_count_pow {n k p : \u2115} : count p (n ^ k).factors = k * count p n.factors :=\nbegin\n  induction k with k IH, { simp },\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { simp [zero_pow (succ_pos k), count_nil, factors_zero, mul_zero] },\n  rw [pow_succ n k, perm_iff_count.mp (perm_factors_mul_of_pos hn (pow_pos hn k)) p],\n  rw [list.count_append, IH, add_comm, mul_comm, \u2190mul_succ (count p n.factors) k, mul_comm],\nend\n\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m n k l : \u2115}\n      (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k+l+1) \u2223 m*n) :\n      p ^ (k+1) \u2223 m \u2228 p ^ (l+1) \u2223 n :=\nhave hpd : p^(k+l)*p \u2223 m*n, by rwa pow_succ' at hpmn,\nhave hpd2 : p \u2223 (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,\nhave hpd3 : p \u2223 (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,\nhave hpd4 : p \u2223 (m / p^k) * (n / p^l), by simpa [nat.div_mul_div hpm hpn] using hpd3,\nhave hpd5 : p \u2223 (m / p^k) \u2228 p \u2223 (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,\nsuffices p^k*p \u2223 m \u2228 p^l*p \u2223 n, by rwa [pow_succ', pow_succ'],\n  hpd5.elim\n    (assume : p \u2223 m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)\n    (assume : p \u2223 n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)\n\n/-- The type of prime numbers -/\ndef primes := {p : \u2115 // p.prime}\n\nnamespace primes\n\ninstance : has_repr nat.primes := \u27e8\u03bb p, repr p.val\u27e9\ninstance inhabited_primes : inhabited primes := \u27e8\u27e82, prime_two\u27e9\u27e9\n\ninstance coe_nat : has_coe nat.primes \u2115 := \u27e8subtype.val\u27e9\n\ntheorem coe_nat_inj (p q : nat.primes) : (p : \u2115) = (q : \u2115) \u2192 p = q :=\n\u03bb h, subtype.eq h\n\nend primes\n\ninstance monoid.prime_pow {\u03b1 : Type*} [monoid \u03b1] : has_pow \u03b1 primes := \u27e8\u03bb x p, x^p.val\u27e9\n\nend nat\n\n/-! ### Primality prover -/\n\nopen norm_num\n\nnamespace tactic\nnamespace norm_num\n\nlemma is_prime_helper (n : \u2115)\n  (h\u2081 : 1 < n) (h\u2082 : nat.min_fac n = n) : nat.prime n :=\nnat.prime_def_min_fac.2 \u27e8h\u2081, h\u2082\u27e9\n\nlemma min_fac_bit0 (n : \u2115) : nat.min_fac (bit0 n) = 2 :=\nby simp [nat.min_fac_eq, show 2 \u2223 bit0 n, by simp [bit0_eq_two_mul n]]\n\n/-- A predicate representing partial progress in a proof of `min_fac`. -/\ndef min_fac_helper (n k : \u2115) : Prop :=\n0 < k \u2227 bit1 k \u2264 nat.min_fac (bit1 n)\n\ntheorem min_fac_helper.n_pos {n k : \u2115} (h : min_fac_helper n k) : 0 < n :=\npos_iff_ne_zero.2 $ \u03bb e,\nby rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2\n\nlemma min_fac_ne_bit0 {n k : \u2115} : nat.min_fac (bit1 n) \u2260 bit0 k :=\nbegin\n  rw bit0_eq_two_mul,\n  refine (\u03bb e, absurd ((nat.dvd_add_iff_right _).2\n    (dvd_trans \u27e8_, e\u27e9 (nat.min_fac_dvd _))) _); simp\nend\n\nlemma min_fac_helper_0 (n : \u2115) (h : 0 < n) : min_fac_helper n 1 :=\nbegin\n  refine \u27e8zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symm\u27e9,\n  rw nat.succ_le_iff,\n  refine lt_of_le_of_ne (nat.min_fac_pos _) (\u03bb e, nat.not_prime_one _),\n  rw e,\n  exact nat.min_fac_prime (nat.bit1_lt h).ne',\nend\n\nlemma min_fac_helper_1 {n k k' : \u2115} (e : k + 1 = k')\n  (np : nat.min_fac (bit1 n) \u2260 bit1 k)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  rw \u2190 e,\n  refine \u27e8nat.succ_pos _,\n    (lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)\n      min_fac_ne_bit0.symm : bit0 (k+1) < _)\u27e9,\n  { rw add_right_comm, exact h.2 },\n  { rw add_right_comm, exact np.symm }\nend\n\nlemma min_fac_helper_2 (n k k' : \u2115) (e : k + 1 = k')\n  (np : \u00ac nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  intro e\u2081, rw \u2190 e\u2081 at np,\n  exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)\nend\n\nlemma min_fac_helper_3 (n k k' c : \u2115) (e : k + 1 = k')\n  (nc : bit1 n % bit1 k = c) (c0 : 0 < c)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  refine mt _ (ne_of_gt c0), intro e\u2081,\n  rw [\u2190 nc, \u2190 nat.dvd_iff_mod_eq_zero, \u2190 e\u2081],\n  apply nat.min_fac_dvd\nend\n\nlemma min_fac_helper_4 (n k : \u2115) (hd : bit1 n % bit1 k = 0)\n  (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=\nby { rw \u2190 nat.dvd_iff_mod_eq_zero at hd,\n  exact le_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2 }\n\nlemma min_fac_helper_5 (n k k' : \u2115) (e : bit1 k * bit1 k = k')\n  (hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=\nbegin\n  refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2\n    \u27e8nat.bit1_lt h.n_pos, _\u27e9)).2,\n  rw \u2190 e at hd,\n  intros m m2 hm md,\n  have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),\n  rw nat.le_sqrt at this,\n  exact not_le_of_lt hd this\nend\n\n/-- Given `e` a natural numeral and `d : nat` a factor of it, return `\u22a2 \u00ac prime e`. -/\nmeta def prove_non_prime (e : expr) (n d\u2081 : \u2115) : tactic expr :=\ndo let e\u2081 := reflect d\u2081,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n  let d\u2082 := n / d\u2081, let e\u2082 := reflect d\u2082,\n  (c, e', p) \u2190 prove_mul_nat c e\u2081 e\u2082,\n  guard (e' =\u2090 e),\n  (c, p\u2082) \u2190 prove_lt_nat c `(1) e\u2082,\n  return $ `(@nat.not_prime_mul').mk_app [e\u2081, e\u2082, e, p, p\u2081, p\u2082]\n\n/-- Given `a`,`a1 := bit1 a`, `n1` the value of `a1`, `b` and `p : min_fac_helper a b`,\n  returns `(c, \u22a2 min_fac a1 = c)`. -/\nmeta def prove_min_fac_aux (a a1 : expr) (n1 : \u2115) :\n  instance_cache \u2192 expr \u2192 expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| ic b p := do\n  k \u2190 b.to_nat,\n  let k1 := bit1 k,\n  let b1 := `(bit1:\u2115\u2192\u2115).mk_app [b],\n  if n1 < k1*k1 then do\n    (ic, e', p\u2081) \u2190 prove_mul_nat ic b1 b1,\n    (ic, p\u2082) \u2190 prove_lt_nat ic a1 e',\n    return (ic, a1, `(min_fac_helper_5).mk_app [a, b, e', p\u2081, p\u2082, p])\n  else let d := k1.min_fac in\n  if to_bool (d < k1) then do\n    let k' := k+1, let e' := reflect k',\n    (ic, p\u2081) \u2190 prove_succ ic b e',\n    p\u2082 \u2190 prove_non_prime b1 k1 d,\n    prove_min_fac_aux ic e' $ `(min_fac_helper_2).mk_app [a, b, e', p\u2081, p\u2082, p]\n  else do\n    let nc := n1 % k1,\n    (ic, c, pc) \u2190 prove_div_mod ic a1 b1 tt,\n    if nc = 0 then\n      return (ic, b1, `(min_fac_helper_4).mk_app [a, b, pc, p])\n    else do\n      (ic, p\u2080) \u2190 prove_pos ic c,\n      let k' := k+1, let e' := reflect k',\n      (ic, p\u2081) \u2190 prove_succ ic b e',\n      prove_min_fac_aux ic e' $ `(min_fac_helper_3).mk_app [a, b, e', c, p\u2081, pc, p\u2080, p]\n\n/-- Given `a` a natural numeral, returns `(b, \u22a2 min_fac a = b)`. -/\nmeta def prove_min_fac (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\nmatch match_numeral e with\n| match_numeral_result.zero := return (ic, `(2:\u2115), `(nat.min_fac_zero))\n| match_numeral_result.one := return (ic, `(1:\u2115), `(nat.min_fac_one))\n| match_numeral_result.bit0 e := return (ic, `(2), `(min_fac_bit0).mk_app [e])\n| match_numeral_result.bit1 e := do\n  n \u2190 e.to_nat,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p) \u2190 prove_pos c e,\n  let a1 := `(bit1:\u2115\u2192\u2115).mk_app [e],\n  prove_min_fac_aux e a1 (bit1 n) c `(1) (`(min_fac_helper_0).mk_app [e, p])\n| _ := failed\nend\n\n/-- A partial proof of `factors`. Asserts that `l` is a sorted list of primes, lower bounded by a\nprime `p`, which multiplies to `n`. -/\ndef factors_helper (n p : \u2115) (l : list \u2115) : Prop :=\np.prime \u2192 list.chain (\u2264) p l \u2227 (\u2200 a \u2208 l, nat.prime a) \u2227 list.prod l = n\n\nlemma factors_helper_nil (a : \u2115) : factors_helper 1 a [] :=\n\u03bb pa, \u27e8list.chain.nil, by rintro _ \u27e8\u27e9, list.prod_nil\u27e9\n\nlemma factors_helper_cons' (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a \u2264 b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\n\u03bb pa,\n  have pb : b.prime, from nat.prime_def_min_fac.2 \u27e8le_trans pa.two_le h\u2082, h\u2083\u27e9,\n  let \u27e8f\u2081, f\u2082, f\u2083\u27e9 := H pb in\n  \u27e8list.chain.cons h\u2082 f\u2081, \u03bb c h, h.elim (\u03bb e, e.symm \u25b8 pb) (f\u2082 _),\n   by rw [list.prod_cons, f\u2083, h\u2081]\u27e9\n\nlemma factors_helper_cons (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a < b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\nfactors_helper_cons' _ _ _ _ _ h\u2081 h\u2082.le h\u2083 H\n\nlemma factors_helper_sn (n a : \u2115) (h\u2081 : a < n) (h\u2082 : nat.min_fac n = n) : factors_helper n a [n] :=\nfactors_helper_cons _ _ _ _ _ (mul_one _) h\u2081 h\u2082 (factors_helper_nil _)\n\nlemma factors_helper_same (n m a : \u2115) (l : list \u2115) (h : a * m = n)\n  (H : factors_helper m a l) : factors_helper n a (a :: l) :=\n\u03bb pa, factors_helper_cons' _ _ _ _ _ h (le_refl _) (nat.prime_def_min_fac.1 pa).2 H pa\n\nlemma factors_helper_same_sn (a : \u2115) : factors_helper a a [a] :=\nfactors_helper_same _ _ _ _ (mul_one _) (factors_helper_nil _)\n\nlemma factors_helper_end (n : \u2115) (l : list \u2115) (H : factors_helper n 2 l) : nat.factors n = l :=\nlet \u27e8h\u2081, h\u2082, h\u2083\u27e9 := H nat.prime_two in\nhave _, from (list.chain'_iff_pairwise (@le_trans _ _)).1 (@list.chain'.tail _ _ (_::_) h\u2081),\n(list.eq_of_perm_of_sorted (nat.factors_unique h\u2083 h\u2082) this (nat.factors_sorted _)).symm\n\n/-- Given `n` and `a` natural numerals, returns `(l, \u22a2 factors_helper n a l)`. -/\nmeta def prove_factors_aux :\n  instance_cache \u2192 expr \u2192 expr \u2192 \u2115 \u2192 \u2115 \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| c en ea n a :=\n  let b := n.min_fac in\n  if b < n then do\n    let m := n / b,\n    (c, em) \u2190 c.of_nat m,\n    if b = a then do\n      (c, _, p\u2081) \u2190 prove_mul_nat c ea em,\n      (c, l, p\u2082) \u2190 prove_factors_aux c em ea m a,\n      pure (c, `(%%ea::%%l:list \u2115), `(factors_helper_same).mk_app [en, em, ea, l, p\u2081, p\u2082])\n    else do\n      (c, eb) \u2190 c.of_nat b,\n      (c, _, p\u2081) \u2190 prove_mul_nat c eb em,\n      (c, p\u2082) \u2190 prove_lt_nat c ea eb,\n      (c, _, p\u2083) \u2190 prove_min_fac c eb,\n      (c, l, p\u2084) \u2190 prove_factors_aux c em eb m b,\n      pure (c, `(%%eb::%%l : list \u2115),\n        `(factors_helper_cons).mk_app [en, em, ea, eb, l, p\u2081, p\u2082, p\u2083, p\u2084])\n  else if b = a then\n    pure (c, `([%%ea] : list \u2115), `(factors_helper_same_sn).mk_app [ea])\n  else do\n    (c, p\u2081) \u2190 prove_lt_nat c ea en,\n    (c, _, p\u2082) \u2190 prove_min_fac c en,\n    pure (c, `([%%en] : list \u2115), `(factors_helper_sn).mk_app [en, ea, p\u2081, p\u2082])\n\n/-- Evaluates the `prime` and `min_fac` functions. -/\n@[norm_num] meta def eval_prime : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.prime %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := false_intro `(nat.not_prime_zero)\n  | 1 := false_intro `(nat.not_prime_one)\n  | _ := let d\u2081 := n.min_fac in\n    if d\u2081 < n then prove_non_prime e n d\u2081 >>= false_intro\n    else do\n      let e\u2081 := reflect d\u2081,\n      c \u2190 mk_instance_cache `(\u2115),\n      (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n      (c, e\u2081, p) \u2190 prove_min_fac c e,\n      true_intro $ `(is_prime_helper).mk_app [e, p\u2081, p]\n  end\n| `(nat.min_fac %%e) := do\n  ic \u2190 mk_instance_cache `(\u2115),\n  prod.snd <$> prove_min_fac ic e\n| `(nat.factors %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := pure (`(@list.nil \u2115), `(nat.factors_zero))\n  | 1 := pure (`(@list.nil \u2115), `(nat.factors_one))\n  | _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, l, p) \u2190 prove_factors_aux c e `(2) n 2,\n    pure (l, `(factors_helper_end).mk_app [e, l, p])\n  end\n| _ := failed\n\nend norm_num\nend tactic\n\nnamespace nat\n\ntheorem prime_three : prime 3 := by norm_num\n\n/-- See note [fact non-instances].-/\nlemma fact_prime_two : fact (prime 2) := \u27e8prime_two\u27e9\n\n/-- See note [fact non-instances].-/\nlemma fact_prime_three : fact (prime 3) := \u27e8prime_three\u27e9\n\nend nat\n\n\nnamespace nat\n\n/-- The only prime divisor of positive prime power `p^k` is `p` itself -/\nlemma prime_pow_prime_divisor {p k : \u2115} (hk : 0 < k) (hp: prime p) :\n  (p^k).factors.to_finset = {p} :=\nby rw [hp.factors_pow, list.to_finset_repeat_of_ne_zero hk.ne']\n\nlemma mem_factors_mul_of_pos {a b : \u2115} (ha : 0 < a) (hb : 0 < b) (p : \u2115) :\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u2228 p \u2208 b.factors :=\nbegin\n  rw [mem_factors (mul_pos ha hb), mem_factors ha, mem_factors hb, \u2190and_or_distrib_left],\n  simpa only [and.congr_right_iff] using prime.dvd_mul\nend\n\n/-- If `a`,`b` are positive the prime divisors of `(a * b)` are the union of those of `a` and `b` -/\nlemma factors_mul_of_pos {a b : \u2115} (ha : 0 < a) (hb : 0 < b) :\n  (a * b).factors.to_finset = a.factors.to_finset \u222a b.factors.to_finset :=\nby { ext p, simp only [finset.mem_union, list.mem_to_finset, mem_factors_mul_of_pos ha hb p] }\n\n/-- The sets of factors of coprime `a` and `b` are disjoint -/\nlemma coprime_factors_disjoint {a b : \u2115} (hab: a.coprime b) : list.disjoint a.factors b.factors :=\nbegin\n  intros q hqa hqb,\n  apply not_prime_one,\n  rw \u2190(eq_one_of_dvd_coprimes hab (dvd_of_mem_factors hqa) (dvd_of_mem_factors hqb)),\n  exact prime_of_mem_factors hqa\nend\n\nlemma factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) (p:\u2115):\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u222a b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  rw [mem_factors_mul_of_pos ha hb p, list.mem_union]\nend\n\n\nopen list\n\n/-- For `b > 0`, the power of `p` in `a * b` is at least that in `a` -/\nlemma le_factors_count_mul_left {p a b : \u2115} (hb : 0 < b) :\n  list.count p a.factors \u2264 list.count p (a * b).factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp },\n  { rw [perm.count_eq (perm_factors_mul_of_pos ha hb) p, count_append p], simp },\nend\n\n/-- For `a > 0`, the power of `p` in `a * b` is at least that in `b` -/\nlemma le_factors_count_mul_right {p a b : \u2115} (ha : 0 < a) :\n  list.count p b.factors \u2264 list.count p (a * b).factors :=\nby { rw mul_comm, apply le_factors_count_mul_left ha }\n\n/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/\nlemma mem_factors_mul_left {p a b : \u2115} (hpa : p \u2208 a.factors) (hb : 0 < b) : p \u2208 (a*b).factors :=\nby { rw \u2190list.count_pos, exact gt_of_ge_of_gt (le_factors_count_mul_left hb) (count_pos.mpr hpa) }\n\n/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/\nlemma mem_factors_mul_right {p a b : \u2115} (hpb : p \u2208 b.factors) (ha : 0 < a) : p \u2208 (a*b).factors :=\nby { rw mul_comm, exact mem_factors_mul_left hpb ha }\n\n/-- If `p` is a prime factor of `a` then the power of `p` in `a` is the same that in `a * b`,\nfor any `b` coprime to `a`. -/\nlemma factors_count_eq_of_coprime_left {p a b : \u2115} (hab : coprime a b) (hpa : p \u2208 a.factors) :\n  list.count p (a * b).factors = list.count p a.factors :=\nbegin\n  rw count_factors_mul_of_coprime hab,\n  simpa only [count_eq_zero_of_not_mem (coprime_factors_disjoint hab hpa)],\nend\n\n/-- If `p` is a prime factor of `b` then the power of `p` in `b` is the same that in `a * b`,\nfor any `a` coprime to `b`. -/\nlemma factors_count_eq_of_coprime_right {p a b : \u2115} (hab : coprime a b) (hpb : p \u2208 b.factors) :\n  list.count p (a * b).factors = list.count p b.factors :=\nby { rw mul_comm, exact factors_count_eq_of_coprime_left (coprime_comm.mp hab) hpb }\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7306955658843706}}
{"text": "variables (\u03b1 : Type) (p q : \u03b1 -> Prop)\n\nexample : (\u2200 x : \u03b1 , p x \u2227 q x) -> (\u2200 y : \u03b1, p y) :=\nassume h : (\u2200 x : \u03b1, p x \u2227  q x),\nassume z : \u03b1,\nshow p z, from and.elim_left(h z)\n\nvariables (x y z : \u03b1) (r : \u03b1 -> \u03b1 -> Prop)\nvariable trans_r : \u2200 x y z, r x y -> r y z -> r x z\n\nvariables a b c : \u03b1 \nvariables (hab : r a b) (hbc : r b c)\n\n#check trans_r\n#check trans_r a b c\n#check trans_r a b c hab\n#check trans_r a b c hab hbc\n\nvariables (\u03b1' : Type) (r' : \u03b1' -> \u03b1' -> Prop)\nvariable refl_r' : \u2200 x, r' x x\nvariable symm_r' : \u2200 {x y}, r' x y -> r' y x\nvariable trans_r' : \u2200 {x y z}, r' x y -> r' y z -> r' x z\nexample (a b c d : \u03b1') (hab' : r' a b) (hcb' : r' c b) (hcd : r' c d): r' a d :=\ntrans_r' (trans_r' hab' (symm_r' hcb')) hcd\n\n#check eq.refl\n#check eq.trans\n#check eq.symm\n\nopen eq\nvariables (\u03b1'' : Type) (a'' b'' c'' d'' : \u03b1'')\nexample (hab'' : a'' = b'') (hcb'' : c'' = b'') (hcd'' : c'' = d'') :\na'' = d'' :=\ntrans (trans hab'' (symm hcb'')) hcd''\n\nexample : 2 + 3 = 5 :=\nrfl\n\nvariable \u03b11 : Type\nvariables a1 a2 : \u03b11\nvariables f g : \u03b11 -> \u2115\nvariable h1 : a1 = a2\nvariable h2 : f = g\n\nexample : f a1 = f a2 := congr_arg f h1\nexample : f a1 = g a1 := congr_fun h2 a1\nexample : f a1 = g a2 := congr h2 h1\n\nvariables w1 x1 y1 z1 : \u2124\nexample : w1 + 0 = w1 := add_zero w1\nexample : 0 + w1 = w1 := zero_add w1\nexample : w1 * 1 = w1 := mul_one w1 \nexample : 1 * w1 = w1 := one_mul w1\nexample : -w1 + w1 = 0 := neg_add_self w1\nexample : w1 + -w1 = 0 := add_neg_self w1\nexample : w1 - w1 = 0 := sub_self w1\nexample : w1 + x1 = x1 + w1 := add_comm w1 x1\nexample : w1 + x1 + y1 = w1 + (x1 + y1) := add_assoc w1 x1 y1\nexample : w1 * x1 = x1 * w1 := mul_comm w1 x1\nexample : w1 * (x1 + y1) = w1 * x1 + w1 * y1 := mul_add w1 x1 y1\nexample : w1 * (x1 + y1) = w1 * x1 + w1 * y1 := left_distrib w1 x1 y1\nexample : (x1 + y1) * w1 = x1 * w1 + y1 * w1 := add_mul x1 y1 w1\nexample : (x1 + y1) * w1 = x1 * w1 + y1 * w1 := right_distrib x1 y1 w1\nexample : w1 * (x1 - y1) = w1 * x1 - w1 * y1 := mul_sub w1 x1 y1\n\nvariables x' y' z' : \u2124\nexample (x' y' z' : \u2115) : x' * (y' + z') = x' * y' + x' * z':= mul_add x' y' z'\nexample (x' y' z' : \u2115) : (x' + y') * z' = x' * z' + y' * z' := add_mul x' y' z'\nexample (x' y' z' : \u2115) : x' + y' + z' = x' + (y' + z') := add_assoc x' y' z'\nexample  (x' y' : \u2115) :\n(x' + y') * (x' + y') = x' * x' + y' * x' + x' * y' + y' * y' :=\nhave h1 : (x' + y') * (x' + y') = (x' + y') * x' + (x' + y') * y', \nfrom mul_add (x' + y') x' y',\nhave h2 : (x' + y') * (x' + y') = x' * x' + y' * x' + (x' * y' + y' * y'),\nfrom (add_mul x' y' x') \u25b8 (add_mul x' y' y') \u25b8 h1,\nh2.trans (add_assoc (x' * x'+ y' * x') (x' * y') (y' * y')).symm\n\nnamespace hide \nvariables (a' b' c' d' e' : \u2115)\nvariable h : a' = b'\nvariable hb : b' = c' + 1\nvariable hd : c' = d'\nvariable he : e' = 1 + d'\ninclude h hb hd he\ntheorem T : a' = e' :=\ncalc \na' = b' : by rw h\n... = c' + 1 : by rw hb\n... = d' + 1 : by rw hd\n... = 1 + d' : by rw add_comm\n... = e' : by rw he\n\n--theorem T : a' = e' :=\n--calc \n--a' = b' : h\n--... = c' + 1 : hb\n--... = d' + 1 : congr_arg _ hd\n--... = 1 + d' : add_comm d' (1 : \u2115)\n--... = e' : symm he\n\n--theorem T' (a'' b'' c'' d'' : \u2115) \n--(h1' : a'' = b'') (h2' : b'' \u2264 c'') (h3' : c'' + 1 < d'') : a'' < d'' :=\n--calc\n  -- a'' = b'' : h1'\n   --... \u2264 b'' + 1 : nat.lt_succ_self b''\n   -- ... \u2264 c'' + 1 : nat.succ_le_succ h2'\n   -- ... < d'' : h3'\n\nexample (s p : \u2115) :\n(s + p) * (s + p) = s * s + p * s + s * p + p * p :=\nby simp [mul_add, add_mul]\n--calc \n--(s + p) * (s + p) = (s + p) * s + (s + p) * p : by rw mul_add\n--... = s * s + p * s  + (s + p) * p : by rw add_mul\n--... = s * s + p * s + (s * p + p * p) : by rw add_mul\n-- ... = s * s + p * s + s * p + p * p  : by rw \u2190add_assoc\n\n\n-- Existential Quantifier \nopen nat\nexample : \u2203 x : \u2115 , x > 0 :=\nhave h1 : 1 > 0 , from zero_lt_succ 0,\nexists.intro 1 h1\n\nexample (x : \u2115) (h : x > 0) : \u2203 y, y < x :=\nexists.intro 0 h\n\nexample (x y z : \u2115) (hxy : x < y) (hyz : y < z) :\n\u2203 w, x < w \u2227 w < z :=\nexists.intro y (and.intro hxy hyz)\n\ndef is_even (a : nat) := \u2203 b, a = 2*b \n\nopen classical\nvariables (\u03b111 : Type) (p1 q1 : \u03b111 -> Prop)\nvariable \u03b2 : \u03b111\nvariable r11 : Prop \n\nexample : (\u2203 x : \u03b111, r11) -> r11 :=\nbegin\nexists.intro,\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n", "meta": {"author": "swarnpriya", "repo": "Lean", "sha": "a0a9978fd058041eb1a09aec0e2dd7d19a7436a7", "save_path": "github-repos/lean/swarnpriya-Lean", "path": "github-repos/lean/swarnpriya-Lean/Lean-a0a9978fd058041eb1a09aec0e2dd7d19a7436a7/quantifiers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7306894197037019}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\n\nimport data.int.basic data.nat.modeq\n\nnamespace int\n\ndef modeq (n a b : \u2124) := a % n = b % n\n\nnotation a ` \u2261 `:50 b ` [ZMOD `:50 n `]`:0 := modeq n a b\n\nnamespace modeq\nvariables {n m a b c d : \u2124}\n\n@[refl] protected theorem refl (a : \u2124) : a \u2261 a [ZMOD n] := @rfl _ _\n\n@[symm] protected theorem symm : a \u2261 b [ZMOD n] \u2192 b \u2261 a [ZMOD n] := eq.symm\n\n@[trans] protected theorem trans : a \u2261 b [ZMOD n] \u2192 b \u2261 c [ZMOD n] \u2192 a \u2261 c [ZMOD n] := eq.trans\n\nlemma coe_nat_modeq_iff (a b n : \u2115) : a \u2261 b [ZMOD n] \u2194 a \u2261 b [MOD n] :=\nby unfold modeq nat.modeq; rw \u2190 int.coe_nat_eq_coe_nat_iff; simp [int.coe_nat_mod]\n\ninstance : decidable (a \u2261 b [ZMOD n]) := by unfold modeq; apply_instance\n\ntheorem modeq_zero_iff : a \u2261 0 [ZMOD n] \u2194 n \u2223 a :=\nby rw [modeq, zero_mod, dvd_iff_mod_eq_zero]\n\ntheorem modeq_iff_dvd : a \u2261 b [ZMOD n] \u2194 (n:\u2124) \u2223 b - a :=\nby rw [modeq, eq_comm];\n   simp [int.mod_eq_mod_iff_mod_sub_eq_zero, int.dvd_iff_mod_eq_zero]\n\ntheorem modeq_of_dvd_of_modeq (d : m \u2223 n) (h : a \u2261 b [ZMOD n]) : a \u2261 b [ZMOD m] :=\nmodeq_iff_dvd.2 $ dvd_trans d (modeq_iff_dvd.1 h)\n\ntheorem modeq_mul_left' (hc : 0 \u2264 c) (h : a \u2261 b [ZMOD n]) : c * a \u2261 c * b [ZMOD (c * n)] :=\nor.cases_on (lt_or_eq_of_le hc) (\u03bb hc, \n  by unfold modeq;\n  simp [mul_mod_mul_of_pos _ _ hc, (show _ = _, from h)] ) \n(\u03bb hc, by simp [hc.symm])\n\ntheorem modeq_mul_right' (hc : 0 \u2264 c) (h : a \u2261 b [ZMOD n]) : a * c \u2261 b * c [ZMOD (n * c)] :=\nby rw [mul_comm a, mul_comm b, mul_comm n]; exact modeq_mul_left' hc h\n\ntheorem modeq_add (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : c \u2261 d [ZMOD n]) : a + c \u2261 b + d [ZMOD n] :=\nmodeq_iff_dvd.2 $ by simpa using dvd_add (modeq_iff_dvd.1 h\u2081) (modeq_iff_dvd.1 h\u2082)\n\ntheorem modeq_add_cancel_left (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : a + c \u2261 b + d [ZMOD n]) : c \u2261 d [ZMOD n] :=\nhave (n:\u2124) \u2223 a + (-a + (d + -c)),\nby simpa using dvd_sub (modeq_iff_dvd.1 h\u2082) (modeq_iff_dvd.1 h\u2081),\nmodeq_iff_dvd.2 $ by rwa add_neg_cancel_left at this\n\ntheorem modeq_add_cancel_right (h\u2081 : c \u2261 d [ZMOD n]) (h\u2082 : a + c \u2261 b + d [ZMOD n]) : a \u2261 b [ZMOD n] :=\nby rw [add_comm a, add_comm b] at h\u2082; exact modeq_add_cancel_left h\u2081 h\u2082\n\ntheorem modeq_neg (h : a \u2261 b [ZMOD n]) : -a \u2261 -b [ZMOD n] := \nmodeq_add_cancel_left h (by simp)\n\ntheorem modeq_sub (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : c \u2261 d [ZMOD n]) : a - c \u2261 b - d [ZMOD n] :=\nby rw [sub_eq_add_neg, sub_eq_add_neg]; exact modeq_add h\u2081 (modeq_neg h\u2082)\n\ntheorem modeq_mul_left (c : \u2124) (h : a \u2261 b [ZMOD n]) : c * a \u2261 c * b [ZMOD n] :=\nor.cases_on (le_total 0 c) \n(\u03bb hc, modeq_of_dvd_of_modeq (dvd_mul_left _ _) (modeq_mul_left' hc h))\n(\u03bb hc, by rw [\u2190 neg_neg c, \u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul _ b];\n    exact modeq_neg (modeq_of_dvd_of_modeq (dvd_mul_left _ _) \n    (modeq_mul_left' (neg_nonneg.2 hc) h)))\n\ntheorem modeq_mul_right (c : \u2124) (h : a \u2261 b [ZMOD n]) : a * c \u2261 b * c [ZMOD n] :=\nby rw [mul_comm a, mul_comm b]; exact modeq_mul_left c h\n\ntheorem modeq_mul (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : c \u2261 d [ZMOD n]) : a * c \u2261 b * d [ZMOD n] :=\n(modeq_mul_left _ h\u2082).trans (modeq_mul_right _ h\u2081)\n\nend modeq\nend int\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/modeq_int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.730689419492634}}
{"text": "/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport algebra.order.module\nimport linear_algebra.affine_space.affine_map\nimport tactic.field_simp\n\n/-!\n# Slope of a function\n\nIn this file we define the slope of a function `f : k \u2192 PE` taking values in an affine space over\n`k` and prove some basic theorems about `slope`. The `slope` function naturally appears in the Mean\nValue Theorem, and in the proof of the fact that a function with nonnegative second derivative on an\ninterval is convex on this interval.\n\n## Tags\n\naffine space, slope\n-/\n\nopen affine_map\nvariables {k E PE : Type*} [field k] [add_comm_group E] [module k E] [add_torsor E PE]\n\ninclude E\n\n/-- `slope f a b = (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a)` is the slope of a function `f` on the interval\n`[a, b]`. Note that `slope f a a = 0`, not the derivative of `f` at `a`. -/\ndef slope (f : k \u2192 PE) (a b : k) : E := (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a)\n\nlemma slope_fun_def (f : k \u2192 PE) : slope f = \u03bb a b, (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a) := rfl\n\nomit E\n\nlemma slope_def_field (f : k \u2192 k) (a b : k) : slope f a b = (f b - f a) / (b - a) :=\ndiv_eq_inv_mul.symm\n\n@[simp] lemma slope_same (f : k \u2192 PE) (a : k) : (slope f a a : E) = 0 :=\nby rw [slope, sub_self, inv_zero, zero_smul]\n\ninclude E\n\nlemma slope_def_module (f : k \u2192 E) (a b : k) : slope f a b = (b - a)\u207b\u00b9 \u2022 (f b - f a) := rfl\n\n@[simp] lemma sub_smul_slope (f : k \u2192 PE) (a b : k) : (b - a) \u2022 slope f a b = f b -\u1d65 f a :=\nbegin\n  rcases eq_or_ne a b with rfl | hne,\n  { rw [sub_self, zero_smul, vsub_self] },\n  { rw [slope, smul_inv_smul\u2080 (sub_ne_zero.2 hne.symm)] }\nend\n\nlemma sub_smul_slope_vadd (f : k \u2192 PE) (a b : k) : (b - a) \u2022 slope f a b +\u1d65 f a = f b :=\nby rw [sub_smul_slope, vsub_vadd]\n\n@[simp] lemma slope_vadd_const (f : k \u2192 E) (c : PE) :\n  slope (\u03bb x, f x +\u1d65 c) = slope f :=\nbegin\n  ext a b,\n  simp only [slope, vadd_vsub_vadd_cancel_right, vsub_eq_sub]\nend\n\n@[simp] lemma slope_sub_smul (f : k \u2192 E) {a b : k} (h : a \u2260 b):\n  slope (\u03bb x, (x - a) \u2022 f x) a b = f b :=\nby simp [slope, inv_smul_smul\u2080 (sub_ne_zero.2 h.symm)]\n\nlemma eq_of_slope_eq_zero {f : k \u2192 PE} {a b : k} (h : slope f a b = (0:E)) : f a = f b :=\nby rw [\u2190 sub_smul_slope_vadd f a b, h, smul_zero, zero_vadd]\n\nlemma slope_comm (f : k \u2192 PE) (a b : k) : slope f a b = slope f b a :=\nby rw [slope, slope, \u2190 neg_vsub_eq_vsub_rev, smul_neg, \u2190 neg_smul, neg_inv, neg_sub]\n\n/-- `slope f a c` is a linear combination of `slope f a b` and `slope f b c`. This version\nexplicitly provides coefficients. If `a \u2260 c`, then the sum of the coefficients is `1`, so it is\nactually an affine combination, see `line_map_slope_slope_sub_div_sub`. -/\nlemma sub_div_sub_smul_slope_add_sub_div_sub_smul_slope (f : k \u2192 PE) (a b c : k) :\n  ((b - a) / (c - a)) \u2022 slope f a b + ((c - b) / (c - a)) \u2022 slope f b c = slope f a c :=\nbegin\n  by_cases hab : a = b,\n  { subst hab,\n    rw [sub_self, zero_div, zero_smul, zero_add],\n    by_cases hac : a = c,\n    { simp [hac] },\n    { rw [div_self (sub_ne_zero.2 $ ne.symm hac), one_smul] } },\n  by_cases hbc : b = c, { subst hbc, simp [sub_ne_zero.2 (ne.symm hab)] },\n  rw [add_comm],\n  simp_rw [slope, div_eq_inv_mul, mul_smul, \u2190 smul_add,\n    smul_inv_smul\u2080 (sub_ne_zero.2 $ ne.symm hab), smul_inv_smul\u2080 (sub_ne_zero.2 $ ne.symm hbc),\n    vsub_add_vsub_cancel],\nend\n\n/-- `slope f a c` is an affine combination of `slope f a b` and `slope f b c`. This version uses\n`line_map` to express this property. -/\nlemma line_map_slope_slope_sub_div_sub (f : k \u2192 PE) (a b c : k) (h : a \u2260 c) :\n  line_map (slope f a b) (slope f b c) ((c - b) / (c - a)) = slope f a c :=\nby  field_simp [sub_ne_zero.2 h.symm, \u2190 sub_div_sub_smul_slope_add_sub_div_sub_smul_slope f a b c,\n  line_map_apply_module]\n\n/-- `slope f a b` is an affine combination of `slope f a (line_map a b r)` and\n`slope f (line_map a b r) b`. We use `line_map` to express this property. -/\nlemma line_map_slope_line_map_slope_line_map (f : k \u2192 PE) (a b r : k) :\n  line_map (slope f (line_map a b r) b) (slope f a (line_map a b r)) r = slope f a b :=\nbegin\n  obtain (rfl|hab) : a = b \u2228 a \u2260 b := classical.em _, { simp },\n  rw [slope_comm _ a, slope_comm _ a, slope_comm _ _ b],\n  convert line_map_slope_slope_sub_div_sub f b (line_map a b r) a hab.symm using 2,\n  rw [line_map_apply_ring, eq_div_iff (sub_ne_zero.2 hab), sub_mul, one_mul, mul_sub, \u2190 sub_sub,\n    sub_sub_cancel]\nend\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/linear_algebra/affine_space/slope.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7306532485581699}}
{"text": "/-\nDO NOT READ THE FIRST 120 LINES OF THIS FILE IF YOU ARE A BEGINNER.\nThere is 120 lines of boilerplate. The lecture starts at line 121.\nCurrently the file takes something like a minute to compile! I'm looking into it.\nYou can just read it while it's compiling anyway.\n-/\n\nimport data.mv_polynomial\n\n/-!\n# Affine algebraic sets\n\nThis file defines affine algebraic subsets of affine n-space and proves basic properties\nabout them.\n\n## Important definitions\n\n* `affine_algebraic_set k n` -- the type of affine algebraic subsets of k\u207f.\n\n## References\n\nMartin Orr's lecture notes https://homepages.warwick.ac.uk/staff/Martin.Orr/2017-8/alg-geom/\n\n## Tags\n\nalgebraic geometry, algebraic variety\n-/\n\n-- In Lean, the multivariable polynomial ring k[X\u2081, X\u2082, ..., X\u2099] is\n-- denoted `mv_polynomial (fin n) k`. We could use better notation.\n-- The set k\u207f is denoted `fin n \u2192 k` (which means maps from {0,1,2,...,(n-1)} to k).\n\n-- We now make some definitions which we'll need in the course.\n\nnamespace mv_polynomial -- means \"multivariable polynomial\"\n\n-- let k be a commutative ring\nvariables {k : Type*} [comm_ring k]\n\n-- and let n be a natural number\nvariable {n : \u2115}\n\n/-- The set of zeros in k\u207f of a function f \u2208 k[X\u2081, X\u2082, ..., X\u2099] -/\ndef zeros (f : mv_polynomial (fin n) k) : set (fin n \u2192 k) :=\n{x | f.eval x = 0} -- I just want to write f(x) = 0 really\n\n/-- x is in the zeros of f iff f(x) = 0 -/\n@[simp] lemma mem_zeros (f : mv_polynomial (fin n) k) (x : fin n \u2192 k) :\n  x \u2208 f.zeros \u2194 f.eval x = 0 := iff.rfl\n\n-- note that the next result needs that k is a field. \n\n/-- The zeros of f * g are the union of the zeros of f and of g -/\nlemma zeros_mul {k : Type*} [discrete_field k] (f g : mv_polynomial (fin n) k) :\n  zeros (f * g) = zeros f \u222a zeros g :=\nbegin\n  -- two sets are equal if they have the same elements\n  ext,\n  -- and now it's not hard to prove using `mem_zeros` and other\n  -- equalities known to Lean's simplifier.\n  simp, -- TODO -- should I give the full proof here?\nend\n\nend mv_polynomial\n\nopen mv_polynomial\n\n/-- An affine algebraic subset of k\u207f is the common zeros of a set of polynomials -/\nstructure affine_algebraic_set (k : Type*) [comm_ring k] (n : \u2115) := \n-- a subset of the set of maps {0,1,2,...,n-1} \u2192 k (called \"carrier\")\n(carrier : set (fin n \u2192 k)) \n-- ...such that there's a set of polynomials such that the carrier is equal to the \n-- intersection of the zeros of the polynomials in the set.\n(is_algebraic' : \u2203 S : set (mv_polynomial (fin n) k), carrier = \u22c2 f \u2208 S, zeros f) -- ...such that\n\nnamespace affine_algebraic_set\n\n-- let k be a commutative ring\nvariables {k : Type*} [comm_ring k]\n\n-- and let n be a natural number\nvariable {n : \u2115}\n\n-- this is invisible notation so mathematicians don't need to understand the definition\ninstance : has_coe_to_fun (affine_algebraic_set k n) :=\n{ F := \u03bb _, _,\n  coe := carrier\n}\n\n-- use `is_algebraic'` not `is_alegbraic` because the notation's right -- no \"carrier\".\ndef is_algebraic (V : affine_algebraic_set k n) :\n  \u2203 S : set (mv_polynomial (fin n) k), (V : set _) = \u22c2 f \u2208 S, zeros f :=\naffine_algebraic_set.is_algebraic' V\n\n-- Now some basic facts about affine algebraic subsets. \n\n/-- Two affine algebraic subsets with the same carrier are equal! -/\nlemma ext (V W : affine_algebraic_set k n) : (V : set _) = W \u2192 V = W :=\nbegin\n  intro h,\n  cases V,\n  cases W,\n  simpa, -- TODO -- why no debugging output?\nend\n\n-- Do I want this instance?\n-- /-- We can talk about elements of affine algebraic subsets of k\u207f  -/\n-- instance : has_mem (fin n \u2192 k) (affine_algebraic_set k n) :=\n-- \u27e8\u03bb x V, x \u2208 V.carrier\u27e9\n\n-- Computer scientists insist on using \u2264 for any order relation such as \u2286 .\n-- It is some sort of problem with notation I think. \ninstance : has_le (affine_algebraic_set k n) :=\n\u27e8\u03bb V W, (V : set (fin n \u2192 k)) \u2286 W\u27e9\n/-- Mathematicians want to talk about affine algebraic subsets of k\u207f\n    as being subsets of one another -/\ninstance : has_subset (affine_algebraic_set k n) := \u27e8affine_algebraic_set.has_le.le\u27e9\n\nend affine_algebraic_set\n\n-- lecture 1 starts here \n\n/-\nAlgebraic geometry lecture 1:\n\nThe union of two algebraic sets is an algebraic set.\n\nKevin Buzzard\n-/\n\n\n/-\n# The union of two affine algebraic sets is an affine algebraic set.\n\nLet k be a field and let n be a natural number. We prove the following\ntheorem in this file:\n\nTheorem. If V and W are two affine algebraic subsets of k\u207f\nthen their union V \u222a W is also an affine algebraic subset of k\u207f.\n\nMaths proof: if V is cut out by the set S \u2286 k[X_1,X_2,\u2026,X_n]\nand W is cut out by T, then we claim V \u222a W is cut out by the set ST := { s*t | s \u2208 S and t \u2208 T}.\nTo prove that the set cut out by ST equals V \u222a W, we prove both inclusions separately.\n\nOne inclusion is very easy. If x \u2208 V \u222a W then either every element of S vanishes at x or every\nelement of T vanishes on x, and either way every element of ST vanishes at x.\n\nConversely, if x vanishes at every element of ST, then we want to prove that x \u2208 V \u222a W. If x is\nin V then we're done. If not, then this means that there exists some s \u2208 S with s(x) \u2260 0. \nThen for every t \u2208 T, we have s(x)t(x)=st(x)=0, and hence t(x)=0, which implies that x is in W.\n\nIn Lean the type of `union` is this:\n\n`def union (V W : affine_algebraic_set k n) : affine_algebraic_set k n`\n\n## Implementation notes\n\nI defined an affine algebraic set to be the zeros of an arbitrary\nset of functions, as opposed to just a finite set. We will see later\non that these definitions are equivalent.\n\nIf V is an affine algebraic set, then V is a pair. The first\nelement of the pair is a subset V.carrier \u2286 k\u207f, but we will call this set V as well (there is\na coercion from affine algebraic sets to subsets of k\u207f).\nThe second element of the pair is the proof that there exists a subset S of k[X_1,X_2,...,X_n]\nsuch that V is cut out by S, by which I mean that V is the set of x \u2208 k^n which vanish\nat each element of S.\n\n## References\n\nMartin Orr's lecture notes at https://homepages.warwick.ac.uk/staff/Martin.Orr/2017-8/alg-geom/\n\n## Tags\n\nalgebraic geometry, algebraic variety\n-/\n\n-- end of docs; code starts here. \n\n-- We're proving theorems about affine algebraic sets so the names of the theorems\n-- should start with \"affine_algebraic_set\".\nnamespace affine_algebraic_set\n\n-- let k now be a field (an integral domain would work just as well)\nvariables {k : Type*} [discrete_field k]\n\n-- and let n be a natural number\nvariable {n : \u2115}\n\n-- We're working with multivariable polynomials, so let's get access to their notation\nopen mv_polynomial\n\n-- Now here's a basic fact about affine algebraic sets.\n\n/-- The union of two algebraic subsets of k\u207f is an algebraic subset-/\ndef union (V W : affine_algebraic_set k n) : affine_algebraic_set k n :=\n{ carrier := V \u222a W, -- the underlying set is the union of the two sets defining V and W\n  is_algebraic' :=\n  -- We now need to prove that the union of V and W is cut out by some set of polynomials.\n  begin\n    -- Now here's the bad news. \n\n    -- Lean notation for k\u207f is `fin n \u2192 k`.\n    -- Lean notation for k[X\u2081, X\u2082, ..., X\u2099] is `mv_polynomial (fin n) k`.\n    -- Lean notation for the subsets of X is `set X`\n\n    -- Let's state what we're trying to prove, using Lean's notation.\n    show \n    \u2203 (U : set (mv_polynomial (fin n) k)),\n      -- such that\n      (V : set _) \u222a W = \u22c2 f \u2208 U, zeros f,\n    -- say S is the set that defines V\n    cases V.is_algebraic with S hS,\n    -- and T is the set that defines W\n    -- (slightly fancier way)\n    rcases W.is_algebraic with \u27e8T, hT\u27e9,\n    -- Now reduce to an unwieldy precise statement about zeros of polynomials\n    rw [hS, hT],\n    -- Our goal is now to come up with a set U such that\n    -- the zeros of U are exactly the union of the zeros of S and of T.\n    -- Here's how to do it.\n    use {u | \u2203 (s \u2208 S) (t \u2208 T), u = s * t},\n    -- To prove that the affine algebraic set cut out by this collection of polynomials\n    -- is precisely the set V \u222a W, we check both inclusions.\n    apply set.subset.antisymm,\n    { -- Here's the easier of the two inclusions.\n      -- say x \u2208 V \u222a W,\n      intros x hx,\n      -- it's either in V or W.\n      cases hx with hxV hxW,\n      { -- Say x \u2208 V\n        -- We know that x vanishes at every element of S.\n        rw set.mem_Inter at hxV,\n        -- We want to prove x vanishes at every polynomial of the form s * t\n        -- with s \u2208 S and t \u2208 T.\n        rw set.mem_Inter,\n        -- so let's take an element u of the form s * t\n        rintro u,\n        -- Let's now notice that the goal has got completely out of hand, and\n        -- simplify it back to \u2200 s \u2208 S and \u2200 t \u2208 T, (s * t)(x) = 0.\n        suffices : \u2200 s \u2208 S, \u2200 t \u2208 T, u = s * t \u2192 u.eval x = 0,\n        {rw [set.mem_Inter], rintros \u27e8s, hsS, t, htT, rfl\u27e9, exact this s hsS t htT rfl},\n        rintro s hs t ht rfl,\n        -- we need to show st(x)=0.\n        -- Because x \u2208 V, we have s(x)=0. \n        have hx := set.mem_Inter.1 (hxV s) hs,\n        change s.eval x = 0 at hx,\n        -- It suffices to show s(x)*t(x)=0\n        rw eval_mul,\n        -- but s(x) = 0,\n        rw hx,\n        -- and now it's obvious\n        apply zero_mul,\n      },\n      { -- This is the case x \u2208 W and it's essentially completely the same as the x \u2208 V argument so I won't\n        -- comment it. Some sort of argument with the `wlog` tactic might be able to do this.\n        rw set.mem_Inter at hxW \u22a2,\n        rintro u,\n          suffices : \u2200 s \u2208 S, \u2200 t \u2208 T, u = s * t \u2192 u.eval x = 0,\n          {rw [set.mem_Inter], rintros \u27e8s, hsS, t, htT, rfl\u27e9, exact this s hsS t htT rfl},\n        rintro s hs t ht rfl,\n        have hx := hxW t,\n        rw set.mem_Inter at hx,\n        replace hx : eval x t = 0 := hx ht,\n        rw eval_mul,\n        rw hx, simp,\n      }\n    },\n    { -- This is the harder way; we need to check that if x vanishes on every element of S*T, \n      -- then x \u2208 V or x \u2208 W.\n      intros x hx,\n      have hx' : \u2200 u s : mv_polynomial (fin n) k, s \u2208 S \u2192 \u2200 t \u2208 T, u = s * t \u2192 u.eval x = 0,\n        simpa using hx,\n      classical, -- We now proudly assume the law of the excluded middle.\n      -- If x \u2208 V then the result is easy...\n      by_cases hx2 : x \u2208 (V : set _),\n        left, rwa \u2190hS,\n      -- ...so we can assume assume x \u2209 V,\n      -- and hence that there's s \u2208 S such that s(x) \u2260 0\n      rw [hS, set.mem_Inter, not_forall] at hx2,\n      cases hx2 with s hs,\n      have hs2 : s \u2208 S \u2227 \u00aceval x s = 0,\n        simpa using hs,\n      cases hs2 with hsS hns,\n      -- we now show x \u2208 W\n      right,\n      rw set.mem_Inter,\n      -- Say t \u2208 T\n      intro t,\n      -- We want to prove that t(x) = 0.\n      suffices : t \u2208 T \u2192 eval x t = 0,\n        simpa,\n      intro ht,\n      -- Now by assumption, x vanishes on s * t. \n      replace hx' := hx' (s * t) s hsS t ht rfl,\n      -- so s(x) * t(x) = 0\n      rw eval_mul at hx',\n      -- so either s(x) or t(x) = 0, but we chose s such that s(x) \u2260 0.\n      cases mul_eq_zero.1 hx' with hxs hxt,\n        -- So the case s(x) = 0 is a contradiction\n        contradiction,\n      -- and t(x) = 0 is what we wanted to prove\n      assumption\n    }\n  end\n}\nend affine_algebraic_set\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M4P33/union_full.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7306532447822991}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon, Ya\u00ebl Dillies\nPorted by: R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module data.nat.log\n! leanprover-community/mathlib commit 3e00d81bdcbf77c8188bbd18f5524ddc3ed8cac6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Pow\nimport Mathlib.Tactic.ByContra\n\n/-!\n# Natural number logarithms\n\nThis file defines two `\u2115`-valued analogs of the logarithm of `n` with base `b`:\n* `log b n`: Lower logarithm, or floor **log**. Greatest `k` such that `b^k \u2264 n`.\n* `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n \u2264 b^k`.\n\nThese are interesting because, for `1 < b`, `Nat.log b` and `Nat.clog b` are respectively right and\nleft adjoints of `Nat.pow b`. See `pow_le_iff_le_log` and `le_pow_iff_clog_le`.\n-/\n\n\nnamespace Nat\n\n/-! ### Floor logarithm -/\n\n\n/-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : \u2115`\nsuch that `b^k \u2264 n`, so if `b^k = n`, it returns exactly `k`. -/\n--@[pp_nodot] porting note: unknown attribute\ndef log (b : \u2115) : \u2115 \u2192 \u2115\n  | n =>\n    if h : b \u2264 n \u2227 1 < b then\n      have : n / b < n := div_lt_self ((zero_lt_one.trans h.2).trans_le h.1) h.2\n      log b (n / b) + 1\n    else 0\n#align nat.log Nat.log\n\n@[simp]\ntheorem log_eq_zero_iff {b n : \u2115} : log b n = 0 \u2194 n < b \u2228 b \u2264 1 := by\n  rw [log, dite_eq_right_iff]\n  simp only [Nat.succ_ne_zero, imp_false, not_and_or, not_le, not_lt]\n#align nat.log_eq_zero_iff Nat.log_eq_zero_iff\n\ntheorem log_of_lt {b n : \u2115} (hb : n < b) : log b n = 0 :=\n  log_eq_zero_iff.2 (Or.inl hb)\n#align nat.log_of_lt Nat.log_of_lt\n\ntheorem log_of_left_le_one {b : \u2115} (hb : b \u2264 1) (n) : log b n = 0 :=\n  log_eq_zero_iff.2 (Or.inr hb)\n#align nat.log_of_left_le_one Nat.log_of_left_le_one\n\n@[simp]\ntheorem log_pos_iff {b n : \u2115} : 0 < log b n \u2194 b \u2264 n \u2227 1 < b := by\n  rw [pos_iff_ne_zero, Ne.def, log_eq_zero_iff, not_or, not_lt, not_le]\n#align nat.log_pos_iff Nat.log_pos_iff\n\ntheorem log_pos {b n : \u2115} (hb : 1 < b) (hbn : b \u2264 n) : 0 < log b n :=\n  log_pos_iff.2 \u27e8hbn, hb\u27e9\n#align nat.log_pos Nat.log_pos\n\ntheorem log_of_one_lt_of_le {b n : \u2115} (h : 1 < b) (hn : b \u2264 n) : log b n = log b (n / b) + 1 := by\n  rw [log]\n  exact if_pos \u27e8hn, h\u27e9\n#align nat.log_of_one_lt_of_le Nat.log_of_one_lt_of_le\n\n@[simp]\ntheorem log_zero_left : \u2200 n, log 0 n = 0 :=\n  log_of_left_le_one zero_le_one\n#align nat.log_zero_left Nat.log_zero_left\n\n@[simp]\ntheorem log_zero_right (b : \u2115) : log b 0 = 0 :=\n  log_eq_zero_iff.2 (le_total 1 b)\n#align nat.log_zero_right Nat.log_zero_right\n\n@[simp]\ntheorem log_one_left : \u2200 n, log 1 n = 0 :=\n  log_of_left_le_one le_rfl\n#align nat.log_one_left Nat.log_one_left\n\n@[simp]\ntheorem log_one_right (b : \u2115) : log b 1 = 0 :=\n  log_eq_zero_iff.2 (lt_or_le _ _)\n#align nat.log_one_right Nat.log_one_right\n\n/-- `pow b` and `log b` (almost) form a Galois connection. See also `Nat.pow_le_of_le_log` and\n`Nat.le_log_of_pow_le` for individual implications under weaker assumptions. -/\ntheorem pow_le_iff_le_log {b : \u2115} (hb : 1 < b) {x y : \u2115} (hy : y \u2260 0) :\n    b ^ x \u2264 y \u2194 x \u2264 log b y := by\n  induction' y using Nat.strong_induction_on with y ih generalizing x\n  cases x with\n  | zero => exact iff_of_true hy.bot_lt (zero_le _)\n  | succ x =>\n    rw [log]; split_ifs with h\n    \u00b7 have b_pos : 0 < b := zero_le_one.trans_lt hb\n      rw [succ_eq_add_one, add_le_add_iff_right, \u2190\n        ih (y / b) (div_lt_self hy.bot_lt hb) (Nat.div_pos h.1 b_pos).ne', le_div_iff_mul_le b_pos,\n        pow_succ', mul_comm]\n    \u00b7 exact iff_of_false (fun hby => h \u27e8(le_self_pow x.succ_ne_zero _).trans hby, hb\u27e9)\n        (not_succ_le_zero _)\n#align nat.pow_le_iff_le_log Nat.pow_le_iff_le_log\n\ntheorem lt_pow_iff_log_lt {b : \u2115} (hb : 1 < b) {x y : \u2115} (hy : y \u2260 0) : y < b ^ x \u2194 log b y < x :=\n  lt_iff_lt_of_le_iff_le (pow_le_iff_le_log hb hy)\n#align nat.lt_pow_iff_log_lt Nat.lt_pow_iff_log_lt\n\ntheorem pow_le_of_le_log {b x y : \u2115} (hy : y \u2260 0) (h : x \u2264 log b y) : b ^ x \u2264 y := by\n  refine' (le_or_lt b 1).elim (fun hb => _) fun hb => (pow_le_iff_le_log hb hy).2 h\n  rw [log_of_left_le_one hb, nonpos_iff_eq_zero] at h\n  rwa [h, pow_zero, one_le_iff_ne_zero]\n#align nat.pow_le_of_le_log Nat.pow_le_of_le_log\n\ntheorem le_log_of_pow_le {b x y : \u2115} (hb : 1 < b) (h : b ^ x \u2264 y) : x \u2264 log b y := by\n  rcases ne_or_eq y 0 with (hy | rfl)\n  exacts[(pow_le_iff_le_log hb hy).1 h, (h.not_lt (pow_pos (zero_lt_one.trans hb) _)).elim]\n#align nat.le_log_of_pow_le Nat.le_log_of_pow_le\n\ntheorem pow_log_le_self (b : \u2115) {x : \u2115} (hx : x \u2260 0) : b ^ log b x \u2264 x :=\n  pow_le_of_le_log hx le_rfl\n#align nat.pow_log_le_self Nat.pow_log_le_self\n\ntheorem log_lt_of_lt_pow {b x y : \u2115} (hy : y \u2260 0) : y < b ^ x \u2192 log b y < x :=\n  lt_imp_lt_of_le_imp_le (pow_le_of_le_log hy)\n#align nat.log_lt_of_lt_pow Nat.log_lt_of_lt_pow\n\ntheorem lt_pow_of_log_lt {b x y : \u2115} (hb : 1 < b) : log b y < x \u2192 y < b ^ x :=\n  lt_imp_lt_of_le_imp_le (le_log_of_pow_le hb)\n#align nat.lt_pow_of_log_lt Nat.lt_pow_of_log_lt\n\ntheorem lt_pow_succ_log_self {b : \u2115} (hb : 1 < b) (x : \u2115) : x < b ^ (log b x).succ :=\n  lt_pow_of_log_lt hb (lt_succ_self _)\n#align nat.lt_pow_succ_log_self Nat.lt_pow_succ_log_self\n\ntheorem log_eq_iff {b m n : \u2115} (h : m \u2260 0 \u2228 1 < b \u2227 n \u2260 0) :\n    log b n = m \u2194 b ^ m \u2264 n \u2227 n < b ^ (m + 1) := by\n  rcases em (1 < b \u2227 n \u2260 0) with (\u27e8hb, hn\u27e9 | hbn)\n  \u00b7 rw [le_antisymm_iff, \u2190 lt_succ_iff, \u2190 pow_le_iff_le_log, \u2190 lt_pow_iff_log_lt, and_comm] <;>\n      assumption\n  \u00b7 have hm : m \u2260 0 := h.resolve_right hbn\n    rw [not_and_or, not_lt, Ne.def, not_not] at hbn\n    rcases hbn with (hb | rfl)\n    \u00b7 simpa only [log_of_left_le_one hb, hm.symm, false_iff_iff, not_and, not_lt] using\n        le_trans (pow_le_pow_of_le_one' hb m.le_succ)\n    \u00b7 simpa only [log_zero_right, hm.symm, nonpos_iff_eq_zero, false_iff, not_and, not_lt,\n        add_pos_iff, or_true, pow_eq_zero_iff] using pow_eq_zero\n#align nat.log_eq_iff Nat.log_eq_iff\n\ntheorem log_eq_of_pow_le_of_lt_pow {b m n : \u2115} (h\u2081 : b ^ m \u2264 n) (h\u2082 : n < b ^ (m + 1)) :\n    log b n = m := by\n  rcases eq_or_ne m 0 with (rfl | hm)\n  \u00b7 rw [pow_one] at h\u2082\n    exact log_of_lt h\u2082\n  \u00b7 exact (log_eq_iff (Or.inl hm)).2 \u27e8h\u2081, h\u2082\u27e9\n#align nat.log_eq_of_pow_le_of_lt_pow Nat.log_eq_of_pow_le_of_lt_pow\n\ntheorem log_pow {b : \u2115} (hb : 1 < b) (x : \u2115) : log b (b ^ x) = x :=\n  log_eq_of_pow_le_of_lt_pow le_rfl (pow_lt_pow hb x.lt_succ_self)\n#align nat.log_pow Nat.log_pow\n\ntheorem log_eq_one_iff' {b n : \u2115} : log b n = 1 \u2194 b \u2264 n \u2227 n < b * b := by\n  rw [log_eq_iff (Or.inl one_ne_zero), pow_add, pow_one]\n#align nat.log_eq_one_iff' Nat.log_eq_one_iff'\n\ntheorem log_eq_one_iff {b n : \u2115} : log b n = 1 \u2194 n < b * b \u2227 1 < b \u2227 b \u2264 n :=\n  log_eq_one_iff'.trans\n    \u27e8fun h => \u27e8h.2, lt_mul_self_iff.1 (h.1.trans_lt h.2), h.1\u27e9, fun h => \u27e8h.2.2, h.1\u27e9\u27e9\n#align nat.log_eq_one_iff Nat.log_eq_one_iff\n\ntheorem log_mul_base {b n : \u2115} (hb : 1 < b) (hn : n \u2260 0) : log b (n * b) = log b n + 1 := by\n  apply log_eq_of_pow_le_of_lt_pow <;> rw [pow_succ', mul_comm b]\n  exacts [mul_le_mul_right' (pow_log_le_self _ hn) _,\n    (mul_lt_mul_right (zero_lt_one.trans hb)).2 (lt_pow_succ_log_self hb _)]\n#align nat.log_mul_base Nat.log_mul_base\n\ntheorem pow_log_le_add_one (b : \u2115) : \u2200 x, b ^ log b x \u2264 x + 1\n  | 0 => by rw [log_zero_right, pow_zero]\n  | x + 1 => (pow_log_le_self b x.succ_ne_zero).trans (x + 1).le_succ\n#align nat.pow_log_le_add_one Nat.pow_log_le_add_one\n\ntheorem log_monotone {b : \u2115} : Monotone (log b) := by\n  refine' monotone_nat_of_le_succ fun n => _\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [log_of_left_le_one hb]\n    exact zero_le _\n  \u00b7 exact le_log_of_pow_le hb (pow_log_le_add_one _ _)\n#align nat.log_monotone Nat.log_monotone\n\n@[mono]\ntheorem log_mono_right {b n m : \u2115} (h : n \u2264 m) : log b n \u2264 log b m :=\n  log_monotone h\n#align nat.log_mono_right Nat.log_mono_right\n\n@[mono]\ntheorem log_anti_left {b c n : \u2115} (hc : 1 < c) (hb : c \u2264 b) : log b n \u2264 log c n := by\n  rcases eq_or_ne n 0 with (rfl | hn); \u00b7 rw [log_zero_right, log_zero_right]\n  apply le_log_of_pow_le hc\n  calc\n    c ^ log b n \u2264 b ^ log b n := pow_le_pow_of_le_left' hb _\n    _ \u2264 n := pow_log_le_self _ hn\n\n#align nat.log_anti_left Nat.log_anti_left\n\ntheorem log_antitone_left {n : \u2115} : AntitoneOn (fun b => log b n) (Set.Ioi 1) := fun _ hc _ _ hb =>\n  log_anti_left (Set.mem_Iio.1 hc) hb\n#align nat.log_antitone_left Nat.log_antitone_left\n\n@[simp]\ntheorem log_div_base (b n : \u2115) : log b (n / b) = log b n - 1 := by\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [log_of_left_le_one hb, log_of_left_le_one hb, Nat.zero_sub]\n  cases' lt_or_le n b with h h\n  \u00b7 rw [div_eq_of_lt h, log_of_lt h, log_zero_right]\n  rw [log_of_one_lt_of_le hb h, add_tsub_cancel_right]\n#align nat.log_div_base Nat.log_div_base\n\n@[simp]\n\n\ntheorem add_pred_div_lt {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) : (n + b - 1) / b < n := by\n  rw [div_lt_iff_lt_mul (zero_lt_one.trans hb), \u2190 succ_le_iff, \u2190 pred_eq_sub_one,\n    succ_pred_eq_of_pos (add_pos (zero_lt_one.trans hn) (zero_lt_one.trans hb))]\n  exact add_le_mul hn hb\n-- Porting note: Was private in mathlib 3\n-- #align nat.add_pred_div_lt Nat.add_pred_div_lt\n\n/-! ### Ceil logarithm -/\n\n\n/-- `clog b n`, is the upper logarithm of natural number `n` in base `b`. It returns the smallest\n`k : \u2115` such that `n \u2264 b^k`, so if `b^k = n`, it returns exactly `k`. -/\n--@[pp_nodot]\ndef clog (b : \u2115) : \u2115 \u2192 \u2115\n  | n =>\n    if h : 1 < b \u2227 1 < n then\n      have : (n + b - 1) / b < n := add_pred_div_lt h.1 h.2\n      clog b ((n + b - 1) / b) + 1\n    else 0\n#align nat.clog Nat.clog\n\ntheorem clog_of_left_le_one {b : \u2115} (hb : b \u2264 1) (n : \u2115) : clog b n = 0 := by\n  rw [clog, dif_neg fun h : 1 < b \u2227 1 < n => h.1.not_le hb]\n#align nat.clog_of_left_le_one Nat.clog_of_left_le_one\n\ntheorem clog_of_right_le_one {n : \u2115} (hn : n \u2264 1) (b : \u2115) : clog b n = 0 := by\n  rw [clog, dif_neg fun h : 1 < b \u2227 1 < n => h.2.not_le hn]\n#align nat.clog_of_right_le_one Nat.clog_of_right_le_one\n\n@[simp]\ntheorem clog_zero_left (n : \u2115) : clog 0 n = 0 :=\n  clog_of_left_le_one zero_le_one _\n#align nat.clog_zero_left Nat.clog_zero_left\n\n@[simp]\ntheorem clog_zero_right (b : \u2115) : clog b 0 = 0 :=\n  clog_of_right_le_one zero_le_one _\n#align nat.clog_zero_right Nat.clog_zero_right\n\n@[simp]\ntheorem clog_one_left (n : \u2115) : clog 1 n = 0 :=\n  clog_of_left_le_one le_rfl _\n#align nat.clog_one_left Nat.clog_one_left\n\n@[simp]\ntheorem clog_one_right (b : \u2115) : clog b 1 = 0 :=\n  clog_of_right_le_one le_rfl _\n#align nat.clog_one_right Nat.clog_one_right\n\ntheorem clog_of_two_le {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) :\n    clog b n = clog b ((n + b - 1) / b) + 1 := by rw [clog, dif_pos (\u27e8hb, hn\u27e9 : 1 < b \u2227 1 < n)]\n#align nat.clog_of_two_le Nat.clog_of_two_le\n\ntheorem clog_pos {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) : 0 < clog b n := by\n  rw [clog_of_two_le hb hn]\n  exact zero_lt_succ _\n#align nat.clog_pos Nat.clog_pos\n\ntheorem clog_eq_one {b n : \u2115} (hn : 2 \u2264 n) (h : n \u2264 b) : clog b n = 1 := by\n  rw [clog_of_two_le (hn.trans h) hn, clog_of_right_le_one]\n  have n_pos : 0 < n := (zero_lt_two' \u2115).trans_le hn\n  rw [\u2190 lt_succ_iff, Nat.div_lt_iff_lt_mul (n_pos.trans_le h), \u2190 succ_le_iff, \u2190 pred_eq_sub_one,\n    succ_pred_eq_of_pos (add_pos n_pos (n_pos.trans_le h)), succ_mul, one_mul]\n  exact add_le_add_right h _\n#align nat.clog_eq_one Nat.clog_eq_one\n\n/-- `clog b` and `pow b` form a Galois connection. -/\ntheorem le_pow_iff_clog_le {b : \u2115} (hb : 1 < b) {x y : \u2115} : x \u2264 b ^ y \u2194 clog b x \u2264 y := by\n  induction' x using Nat.strong_induction_on with x ih generalizing y\n  cases y\n  \u00b7 rw [pow_zero]\n    refine' \u27e8fun h => (clog_of_right_le_one h b).le, _\u27e9\n    simp_rw [\u2190 not_lt]\n    contrapose!\n    exact clog_pos hb\n  have b_pos : 0 < b := (zero_lt_one' \u2115).trans hb\n  rw [clog]; split_ifs with h\n  \u00b7 rw [succ_eq_add_one, add_le_add_iff_right, \u2190 ih ((x + b - 1) / b) (add_pred_div_lt hb h.2),\n      Nat.div_le_iff_le_mul_add_pred b_pos, mul_comm b, \u2190 pow_succ,\n      add_tsub_assoc_of_le (Nat.succ_le_of_lt b_pos), add_le_add_iff_right]\n  \u00b7 exact iff_of_true ((not_lt.1 (not_and.1 h hb)).trans <| succ_le_of_lt <| pow_pos b_pos _)\n      (zero_le _)\n#align nat.le_pow_iff_clog_le Nat.le_pow_iff_clog_le\n\ntheorem pow_lt_iff_lt_clog {b : \u2115} (hb : 1 < b) {x y : \u2115} : b ^ y < x \u2194 y < clog b x :=\n  lt_iff_lt_of_le_iff_le (le_pow_iff_clog_le hb)\n#align nat.pow_lt_iff_lt_clog Nat.pow_lt_iff_lt_clog\n\ntheorem clog_pow (b x : \u2115) (hb : 1 < b) : clog b (b ^ x) = x :=\n  eq_of_forall_ge_iff fun z => by\n    rw [\u2190 le_pow_iff_clog_le hb]\n    exact (pow_right_strictMono hb).le_iff_le\n#align nat.clog_pow Nat.clog_pow\n\ntheorem pow_pred_clog_lt_self {b : \u2115} (hb : 1 < b) {x : \u2115} (hx : 1 < x) :\n  b ^ (clog b x).pred < x := by\n  rw [\u2190 not_le, le_pow_iff_clog_le hb, not_le]\n  exact pred_lt (clog_pos hb hx).ne'\n#align nat.pow_pred_clog_lt_self Nat.pow_pred_clog_lt_self\n\ntheorem le_pow_clog {b : \u2115} (hb : 1 < b) (x : \u2115) : x \u2264 b ^ clog b x :=\n  (le_pow_iff_clog_le hb).2 le_rfl\n#align nat.le_pow_clog Nat.le_pow_clog\n\n@[mono]\ntheorem clog_mono_right (b : \u2115) {n m : \u2115} (h : n \u2264 m) : clog b n \u2264 clog b m := by\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [clog_of_left_le_one hb]\n    exact zero_le _\n  \u00b7 rw [\u2190 le_pow_iff_clog_le hb]\n    exact h.trans (le_pow_clog hb _)\n#align nat.clog_mono_right Nat.clog_mono_right\n\n@[mono]\ntheorem clog_anti_left {b c n : \u2115} (hc : 1 < c) (hb : c \u2264 b) : clog b n \u2264 clog c n := by\n  rw [\u2190 le_pow_iff_clog_le (lt_of_lt_of_le hc hb)]\n  calc\n    n \u2264 c ^ clog c n := le_pow_clog hc _\n    _ \u2264 b ^ clog c n := pow_le_pow_of_le_left hb _\n\n#align nat.clog_anti_left Nat.clog_anti_left\n\ntheorem clog_monotone (b : \u2115) : Monotone (clog b) := fun _ _ => clog_mono_right _\n#align nat.clog_monotone Nat.clog_monotone\n\ntheorem clog_antitone_left {n : \u2115} : AntitoneOn (fun b : \u2115 => clog b n) (Set.Ioi 1) :=\n  fun _ hc _ _ hb => clog_anti_left (Set.mem_Iio.1 hc) hb\n#align nat.clog_antitone_left Nat.clog_antitone_left\n\ntheorem log_le_clog (b n : \u2115) : log b n \u2264 clog b n := by\n  obtain hb | hb := le_or_lt b 1\n  \u00b7 rw [log_of_left_le_one hb]\n    exact zero_le _\n  cases n with\n  | zero =>\n    rw [log_zero_right]\n    exact zero_le _\n  | succ n =>\n    exact (pow_right_strictMono hb).le_iff_le.1\n      ((pow_log_le_self b n.succ_ne_zero).trans <| le_pow_clog hb _)\n#align nat.log_le_clog Nat.log_le_clog\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7306532354982541}}
{"text": "/-\nCopyright (c) 2018 Guy Leroy. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport data.nat.gcd.basic\nimport tactic.norm_num\n\n/-!\n# Extended GCD and divisibility over \u2124\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\n* Given `x y : \u2115`, `xgcd x y` computes the pair of integers `(a, b)` such that\n  `gcd x y = x * a + y * b`. `gcd_a x y` and `gcd_b x y` are defined to be `a` and `b`,\n  respectively.\n\n## Main statements\n\n* `gcd_eq_gcd_ab`: B\u00e9zout's lemma, given `x y : \u2115`, `gcd x y = x * gcd_a x y + y * gcd_b x y`.\n\n## Tags\n\nB\u00e9zout's lemma, Bezout's lemma\n-/\n\n/-! ### Extended Euclidean algorithm -/\nnamespace nat\n\n/-- Helper function for the extended GCD algorithm (`nat.xgcd`). -/\ndef xgcd_aux : \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u00d7 \u2124 \u00d7 \u2124\n| 0          s t r' s' t' := (r', s', t')\n| r@(succ _) s t r' s' t' :=\n  have r' % r < r, from mod_lt _ $ succ_pos _,\n  let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t\n\n@[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=\nby simp [xgcd_aux]\n\ntheorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) :\n  xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=\nby cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}]\n\n/-- Use the extended GCD algorithm to generate the `a` and `b` values\n  satisfying `gcd x y = x * a + y * b`. -/\ndef xgcd (x y : \u2115) : \u2124 \u00d7 \u2124 := (xgcd_aux x 1 0 y 0 1).2\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a (x y : \u2115) : \u2124 := (xgcd x y).1\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b (x y : \u2115) : \u2124 := (xgcd x y).2\n\n@[simp] theorem gcd_a_zero_left {s : \u2115} : gcd_a 0 s = 0 :=\nby { unfold gcd_a, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_b_zero_left {s : \u2115} : gcd_b 0 s = 1 :=\nby { unfold gcd_b, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_a_zero_right {s : \u2115} (h : s \u2260 0) : gcd_a s 0 = 1 :=\nbegin\n  unfold gcd_a xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem gcd_b_zero_right {s : \u2115} (h : s \u2260 0) : gcd_b s 0 = 0 :=\nbegin\n  unfold gcd_b xgcd,\n  induction s,\n  { exact absurd rfl h, },\n  { simp [xgcd_aux], }\nend\n\n@[simp] theorem xgcd_aux_fst (x y) : \u2200 s t s' t',\n  (xgcd_aux x s t y s' t').1 = gcd x y :=\ngcd.induction x y (by simp) (\u03bb x y h IH s t s' t', by simp [xgcd_aux_rec, h, IH]; rw \u2190 gcd_rec)\n\ntheorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=\nby rw [xgcd, \u2190 xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl\n\ntheorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nby unfold gcd_a gcd_b; cases xgcd x y; refl\n\nsection\nparameters (x y : \u2115)\n\nprivate def P : \u2115 \u00d7 \u2124 \u00d7 \u2124 \u2192 Prop\n| (r, s, t) := (r : \u2124) = x * s + y * t\n\ntheorem xgcd_aux_P {r r'} : \u2200 {s t s' t'}, P (r, s, t) \u2192 P (r', s', t') \u2192\n  P (xgcd_aux r s t r' s' t') :=\ngcd.induction r r' (by simp) $ \u03bb a b h IH s t s' t' p p', begin\n  rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *,\n  rw [int.mod_def], generalize : (b / a : \u2124) = k,\n  rw [p, p'],\n  simp [mul_add, mul_comm, mul_left_comm, add_comm, add_left_comm, sub_eq_neg_add, mul_assoc]\nend\n\n/-- **B\u00e9zout's lemma**: given `x y : \u2115`, `gcd x y = x * a + y * b`, where `a = gcd_a x y` and\n`b = gcd_b x y` are computed by the extended Euclidean algorithm.\n-/\ntheorem gcd_eq_gcd_ab : (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y :=\nby have := @xgcd_aux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P]);\n   rwa [xgcd_aux_val, xgcd_val] at this\nend\n\nlemma exists_mul_mod_eq_gcd {k n : \u2115} (hk : gcd n k < k) :\n  \u2203 m, n * m % k = gcd n k :=\nbegin\n  have hk' := int.coe_nat_ne_zero.mpr (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk)),\n  have key := congr_arg (\u03bb m, int.nat_mod m k) (gcd_eq_gcd_ab n k),\n  simp_rw int.nat_mod at key,\n  rw [int.add_mul_mod_self_left, \u2190int.coe_nat_mod, int.to_nat_coe_nat, mod_eq_of_lt hk] at key,\n  refine \u27e8(n.gcd_a k % k).to_nat, eq.trans (int.coe_nat_inj _) key.symm\u27e9,\n  rw [int.coe_nat_mod, int.coe_nat_mul, int.to_nat_of_nonneg (int.mod_nonneg _ hk'),\n      int.to_nat_of_nonneg (int.mod_nonneg _ hk'), int.mul_mod, int.mod_mod, \u2190int.mul_mod],\nend\n\nlemma exists_mul_mod_eq_one_of_coprime {k n : \u2115} (hkn : coprime n k) (hk : 1 < k) :\n  \u2203 m, n * m % k = 1 :=\nExists.cases_on (exists_mul_mod_eq_gcd (lt_of_le_of_lt (le_of_eq hkn) hk))\n  (\u03bb m hm, \u27e8m, hm.trans hkn\u27e9)\n\nend nat\n\n/-! ### Divisibility over \u2124 -/\nnamespace int\n\nprotected lemma coe_nat_gcd (m n : \u2115) : int.gcd \u2191m \u2191n = nat.gcd m n := rfl\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a : \u2124 \u2192 \u2124 \u2192 \u2124\n| (of_nat m) n := m.gcd_a n.nat_abs\n| -[1+ m]    n := -m.succ.gcd_a n.nat_abs\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b : \u2124 \u2192 \u2124 \u2192 \u2124\n| m (of_nat n) := m.nat_abs.gcd_b n\n| m -[1+ n]    := -m.nat_abs.gcd_b n.succ\n\n/-- **B\u00e9zout's lemma** -/\ntheorem gcd_eq_gcd_ab : \u2200 x y : \u2124, (gcd x y : \u2124) = x * gcd_a x y + y * gcd_b x y\n| (m : \u2115) (n : \u2115) := nat.gcd_eq_gcd_ab _ _\n| (m : \u2115) -[1+ n] := show (_ : \u2124) = _ + -(n+1) * -_, by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] (n : \u2115) := show (_ : \u2124) = -(m+1) * -_ + _ , by rw neg_mul_neg; apply nat.gcd_eq_gcd_ab\n| -[1+ m] -[1+ n] := show (_ : \u2124) = -(m+1) * -_ + -(n+1) * -_,\n  by { rw [neg_mul_neg, neg_mul_neg], apply nat.gcd_eq_gcd_ab }\n\ntheorem nat_abs_div (a b : \u2124) (H : b \u2223 a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) :=\nbegin\n  cases (nat.eq_zero_or_pos (nat_abs b)),\n  {rw eq_zero_of_nat_abs_eq_zero h, simp [int.div_zero]},\n  calc\n  nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one\n    ... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h\n    ... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ dvd_rfl)\n    ... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b)\n    ... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H,\nend\n\ntheorem dvd_of_mul_dvd_mul_left {i j k : \u2124} (k_non_zero : k \u2260 0) (H : k * i \u2223 k * j) : i \u2223 j :=\ndvd.elim H (\u03bbl H1, by rw mul_assoc at H1; exact \u27e8_, mul_left_cancel\u2080 k_non_zero H1\u27e9)\n\ntheorem dvd_of_mul_dvd_mul_right {i j k : \u2124} (k_non_zero : k \u2260 0) (H : i * k \u2223 j * k) : i \u2223 j :=\nby rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H\n\n/-- \u2124 specific version of least common multiple. -/\ndef lcm (i j : \u2124) : \u2115 := nat.lcm (nat_abs i) (nat_abs j)\n\ntheorem lcm_def (i j : \u2124) : lcm i j = nat.lcm (nat_abs i) (nat_abs j) := rfl\n\nprotected lemma coe_nat_lcm (m n : \u2115) : int.lcm \u2191m \u2191n = nat.lcm m n := rfl\n\ntheorem gcd_dvd_left (i j : \u2124) : (gcd i j : \u2124) \u2223 i :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_left _ _\n\ntheorem gcd_dvd_right (i j : \u2124) : (gcd i j : \u2124) \u2223 j :=\ndvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_right _ _\n\ntheorem dvd_gcd {i j k : \u2124} (h1 : k \u2223 i) (h2 : k \u2223 j) : k \u2223 gcd i j :=\nnat_abs_dvd.1 $ coe_nat_dvd.2 $ nat.dvd_gcd (nat_abs_dvd_iff_dvd.2 h1) (nat_abs_dvd_iff_dvd.2 h2)\n\ntheorem gcd_mul_lcm (i j : \u2124) : gcd i j * lcm i j = nat_abs (i * j) :=\nby rw [int.gcd, int.lcm, nat.gcd_mul_lcm, nat_abs_mul]\n\ntheorem gcd_comm (i j : \u2124) : gcd i j = gcd j i := nat.gcd_comm _ _\n\ntheorem gcd_assoc (i j k : \u2124) : gcd (gcd i j) k = gcd i (gcd j k) := nat.gcd_assoc _ _ _\n\n@[simp] theorem gcd_self (i : \u2124) : gcd i i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_left (i : \u2124) : gcd 0 i = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_zero_right (i : \u2124) : gcd i 0 = nat_abs i := by simp [gcd]\n\n@[simp] theorem gcd_one_left (i : \u2124) : gcd 1 i = 1 := nat.gcd_one_left _\n\n@[simp] theorem gcd_one_right (i : \u2124) : gcd i 1 = 1 := nat.gcd_one_right _\n\n@[simp] lemma gcd_neg_right {x y : \u2124} : gcd x (-y) = gcd x y :=\nby rw [int.gcd, int.gcd, nat_abs_neg]\n\n@[simp] lemma gcd_neg_left {x y : \u2124} : gcd (-x) y = gcd x y :=\nby rw [int.gcd, int.gcd, nat_abs_neg]\n\ntheorem gcd_mul_left (i j k : \u2124) : gcd (i * j) (i * k) = nat_abs i * gcd j k :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_left }\n\ntheorem gcd_mul_right (i j k : \u2124) : gcd (i * j) (k * j) = gcd i k * nat_abs j :=\nby { rw [int.gcd, int.gcd, nat_abs_mul, nat_abs_mul], apply nat.gcd_mul_right }\n\ntheorem gcd_pos_of_non_zero_left {i : \u2124} (j : \u2124) (i_non_zero : i \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_left (nat_abs j) (nat_abs_pos_of_ne_zero i_non_zero)\n\ntheorem gcd_pos_of_non_zero_right (i : \u2124) {j : \u2124} (j_non_zero : j \u2260 0) : 0 < gcd i j :=\nnat.gcd_pos_of_pos_right (nat_abs i) (nat_abs_pos_of_ne_zero j_non_zero)\n\ntheorem gcd_eq_zero_iff {i j : \u2124} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 :=\nbegin\n  rw int.gcd,\n  split,\n  { intro h,\n    exact \u27e8nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_left h),\n      nat_abs_eq_zero.mp (nat.eq_zero_of_gcd_eq_zero_right h)\u27e9 },\n  { intro h, rw [nat_abs_eq_zero.mpr h.left, nat_abs_eq_zero.mpr h.right],\n    apply nat.gcd_zero_left }\nend\n\ntheorem gcd_pos_iff {i j : \u2124} : 0 < gcd i j \u2194 i \u2260 0 \u2228 j \u2260 0 :=\npos_iff_ne_zero.trans $ gcd_eq_zero_iff.not.trans not_and_distrib\n\ntheorem gcd_div {i j k : \u2124} (H1 : k \u2223 i) (H2 : k \u2223 j) :\n  gcd (i / k) (j / k) = gcd i j / nat_abs k :=\nby rw [gcd, nat_abs_div i k H1, nat_abs_div j k H2];\nexact nat.gcd_div (nat_abs_dvd_iff_dvd.mpr H1) (nat_abs_dvd_iff_dvd.mpr H2)\n\ntheorem gcd_div_gcd_div_gcd {i j : \u2124} (H : 0 < gcd i j) :\n  gcd (i / gcd i j) (j / gcd i j) = 1 :=\nbegin\n  rw [gcd_div (gcd_dvd_left i j) (gcd_dvd_right i j)],\n  rw [nat_abs_of_nat, nat.div_self H]\nend\n\ntheorem gcd_dvd_gcd_of_dvd_left {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd i j \u2223 gcd k j :=\nint.coe_nat_dvd.1 $ dvd_gcd ((gcd_dvd_left i j).trans H) (gcd_dvd_right i j)\n\ntheorem gcd_dvd_gcd_of_dvd_right {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd j i \u2223 gcd j k :=\nint.coe_nat_dvd.1 $ dvd_gcd (gcd_dvd_left j i) ((gcd_dvd_right j i).trans H)\n\ntheorem gcd_dvd_gcd_mul_left (i j k : \u2124) : gcd i j \u2223 gcd (k * i) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (i j k : \u2124) : gcd i j \u2223 gcd (i * k) j :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (i j k : \u2124) : gcd i j \u2223 gcd i (k * j) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (i j k : \u2124) : gcd i j \u2223 gcd i (j * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {i j : \u2124} (H : i \u2223 j) : gcd i j = nat_abs i :=\nnat.dvd_antisymm (by unfold gcd; exact nat.gcd_dvd_left _ _)\n                 (by unfold gcd; exact nat.dvd_gcd dvd_rfl (nat_abs_dvd_iff_dvd.mpr H))\n\ntheorem gcd_eq_right {i j : \u2124} (H : j \u2223 i) : gcd i j = nat_abs j :=\nby rw [gcd_comm, gcd_eq_left H]\n\ntheorem ne_zero_of_gcd {x y : \u2124}\n  (hc : gcd x y \u2260 0) : x \u2260 0 \u2228 y \u2260 0 :=\nbegin\n  contrapose! hc,\n  rw [hc.left, hc.right, gcd_zero_right, nat_abs_zero]\nend\n\ntheorem exists_gcd_one {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (m' n' : \u2124), gcd m' n' = 1 \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n\u27e8_, _, gcd_div_gcd_div_gcd H,\n  (int.div_mul_cancel (gcd_dvd_left m n)).symm,\n  (int.div_mul_cancel (gcd_dvd_right m n)).symm\u27e9\n\ntheorem exists_gcd_one' {m n : \u2124} (H : 0 < gcd m n) :\n  \u2203 (g : \u2115) (m' n' : \u2124), 0 < g \u2227 gcd m' n' = 1 \u2227 m = m' * g \u2227 n = n' * g :=\nlet \u27e8m', n', h\u27e9 := exists_gcd_one H in \u27e8_, m', n', H, h\u27e9\n\ntheorem pow_dvd_pow_iff {m n : \u2124} {k : \u2115} (k0 : 0 < k) : m ^ k \u2223 n ^ k \u2194 m \u2223 n :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, pow_dvd_pow_of_dvd h _\u27e9,\n  apply int.nat_abs_dvd_iff_dvd.mp,\n  apply (nat.pow_dvd_pow_iff k0).mp,\n  rw [\u2190 int.nat_abs_pow, \u2190 int.nat_abs_pow],\n  exact int.nat_abs_dvd_iff_dvd.mpr h\nend\n\nlemma gcd_dvd_iff {a b : \u2124} {n : \u2115} : gcd a b \u2223 n \u2194 \u2203 x y : \u2124, \u2191n = a * x + b * y :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190 nat.mul_div_cancel' h, int.coe_nat_mul, gcd_eq_gcd_ab, add_mul, mul_assoc, mul_assoc],\n    refine \u27e8_, _, rfl\u27e9, },\n  { rintro \u27e8x, y, h\u27e9,\n    rw [\u2190int.coe_nat_dvd, h],\n    exact dvd_add (dvd_mul_of_dvd_left (gcd_dvd_left a b) _)\n      (dvd_mul_of_dvd_left (gcd_dvd_right a b) y) }\nend\n\nlemma gcd_greatest {a b d : \u2124} (hd_pos : 0 \u2264 d) (hda : d \u2223 a) (hdb : d \u2223 b)\n  (hd : \u2200 e : \u2124, e \u2223 a \u2192 e \u2223 b \u2192 e \u2223 d) : d = gcd a b :=\ndvd_antisymm hd_pos\n  (coe_zero_le (gcd a b)) (dvd_gcd hda hdb) (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b))\n\n/-- Euclid's lemma: if `a \u2223 b * c` and `gcd a c = 1` then `a \u2223 b`.\nCompare with `is_coprime.dvd_of_dvd_mul_left` and\n`unique_factorization_monoid.dvd_of_dvd_mul_left_of_no_prime_factors` -/\nlemma dvd_of_dvd_mul_left_of_gcd_one {a b c : \u2124} (habc : a \u2223 b * c) (hab : gcd a c = 1) : a \u2223 b :=\nbegin\n  have := gcd_eq_gcd_ab a c,\n  simp only [hab, int.coe_nat_zero, int.coe_nat_succ, zero_add] at this,\n  have : b * a * gcd_a a c + b * c * gcd_b a c = b, { simp [mul_assoc, \u2190mul_add, \u2190this] },\n  rw \u2190this,\n  exact dvd_add (dvd_mul_of_dvd_left (dvd_mul_left a b) _) (dvd_mul_of_dvd_left habc _),\nend\n\n/-- Euclid's lemma: if `a \u2223 b * c` and `gcd a b = 1` then `a \u2223 c`.\nCompare with `is_coprime.dvd_of_dvd_mul_right` and\n`unique_factorization_monoid.dvd_of_dvd_mul_right_of_no_prime_factors` -/\nlemma dvd_of_dvd_mul_right_of_gcd_one {a b c : \u2124} (habc : a \u2223 b * c) (hab : gcd a b = 1) : a \u2223 c :=\nby { rw mul_comm at habc, exact dvd_of_dvd_mul_left_of_gcd_one habc hab }\n\n/-- For nonzero integers `a` and `b`, `gcd a b` is the smallest positive natural number that can be\nwritten in the form `a * x + b * y` for some pair of integers `x` and `y` -/\ntheorem gcd_least_linear {a b : \u2124} (ha : a \u2260 0) :\n  is_least { n : \u2115 | 0 < n \u2227 \u2203 x y : \u2124, \u2191n = a * x + b * y } (a.gcd b) :=\nbegin\n  simp_rw \u2190gcd_dvd_iff,\n  split,\n  { simpa [and_true, dvd_refl, set.mem_set_of_eq] using gcd_pos_of_non_zero_left b ha },\n  { simp only [lower_bounds, and_imp, set.mem_set_of_eq],\n    exact \u03bb n hn_pos hn, nat.le_of_dvd hn_pos hn },\nend\n\n/-! ### lcm -/\n\ntheorem lcm_comm (i j : \u2124) : lcm i j = lcm j i :=\nby { rw [int.lcm, int.lcm], exact nat.lcm_comm _ _ }\n\ntheorem lcm_assoc (i j k : \u2124) : lcm (lcm i j) k = lcm i (lcm j k) :=\nby { rw [int.lcm, int.lcm, int.lcm, int.lcm, nat_abs_of_nat, nat_abs_of_nat], apply nat.lcm_assoc }\n\n@[simp] theorem lcm_zero_left (i : \u2124) : lcm 0 i = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_left }\n\n@[simp] theorem lcm_zero_right (i : \u2124) : lcm i 0 = 0 :=\nby { rw [int.lcm], apply nat.lcm_zero_right }\n\n@[simp] theorem lcm_one_left (i : \u2124) : lcm 1 i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_left }\n\n@[simp] theorem lcm_one_right (i : \u2124) : lcm i 1 = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_one_right }\n\n@[simp] theorem lcm_self (i : \u2124) : lcm i i = nat_abs i :=\nby { rw int.lcm, apply nat.lcm_self }\n\ntheorem dvd_lcm_left (i j : \u2124) : i \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_left }\n\ntheorem dvd_lcm_right (i j : \u2124) : j \u2223 lcm i j :=\nby { rw int.lcm, apply coe_nat_dvd_right.mpr, apply nat.dvd_lcm_right }\n\ntheorem lcm_dvd {i j k : \u2124}  : i \u2223 k \u2192 j \u2223 k \u2192 (lcm i j : \u2124) \u2223 k :=\nbegin\n  rw int.lcm,\n  intros hi hj,\n  exact coe_nat_dvd_left.mpr\n    (nat.lcm_dvd (nat_abs_dvd_iff_dvd.mpr hi) (nat_abs_dvd_iff_dvd.mpr hj))\nend\n\nend int\n\nlemma pow_gcd_eq_one {M : Type*} [monoid M] (x : M) {m n : \u2115} (hm : x ^ m = 1) (hn : x ^ n = 1) :\n  x ^ m.gcd n = 1 :=\nbegin\n  cases m, { simp only [hn, nat.gcd_zero_left] },\n  lift x to M\u02e3 using is_unit_of_pow_eq_one hm m.succ_ne_zero,\n  simp only [\u2190 units.coe_pow] at *,\n  rw [\u2190 units.coe_one, \u2190 zpow_coe_nat, \u2190 units.ext_iff] at *,\n  simp only [nat.gcd_eq_gcd_ab, zpow_add, zpow_mul, hm, hn, one_zpow, one_mul]\nend\n\nlemma gcd_nsmul_eq_zero {M : Type*} [add_monoid M] (x : M) {m n : \u2115} (hm : m \u2022 x = 0)\n  (hn : n \u2022 x = 0) : (m.gcd n) \u2022 x = 0 :=\nbegin\n  apply multiplicative.of_add.injective,\n  rw [of_add_nsmul, of_add_zero, pow_gcd_eq_one];\n  rwa [\u2190of_add_nsmul, \u2190of_add_zero, equiv.apply_eq_iff_eq]\nend\n\nattribute [to_additive gcd_nsmul_eq_zero] pow_gcd_eq_one\n\n/-! ### GCD prover -/\nopen norm_num\n\nnamespace tactic\nnamespace norm_num\n\nlemma int_gcd_helper' {d : \u2115} {x y a b : \u2124} (h\u2081 : (d:\u2124) \u2223 x) (h\u2082 : (d:\u2124) \u2223 y)\n  (h\u2083 : x * a + y * b = d) : int.gcd x y = d :=\nbegin\n  refine nat.dvd_antisymm _ (int.coe_nat_dvd.1 (int.dvd_gcd h\u2081 h\u2082)),\n  rw [\u2190 int.coe_nat_dvd, \u2190 h\u2083],\n  apply dvd_add,\n  { exact (int.gcd_dvd_left _ _).mul_right _ },\n  { exact (int.gcd_dvd_right _ _).mul_right _ }\nend\n\nlemma nat_gcd_helper_dvd_left (x y a : \u2115) (h : x * a = y) : nat.gcd x y = x :=\nnat.gcd_eq_left \u27e8a, h.symm\u27e9\n\nlemma nat_gcd_helper_dvd_right (x y a : \u2115) (h : y * a = x) : nat.gcd x y = y :=\nnat.gcd_eq_right \u27e8a, h.symm\u27e9\n\nlemma nat_gcd_helper_2 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (hx : x * a = tx) (hy : y * b = ty) (h : ty + d = tx) : nat.gcd x y = d :=\nbegin\n  rw \u2190 int.coe_nat_gcd, apply @int_gcd_helper' _ _ _ a (-b)\n    (int.coe_nat_dvd.2 \u27e8_, hu.symm\u27e9) (int.coe_nat_dvd.2 \u27e8_, hv.symm\u27e9),\n  rw [mul_neg, \u2190 sub_eq_add_neg, sub_eq_iff_eq_add'],\n  norm_cast, rw [hx, hy, h]\nend\n\nlemma nat_gcd_helper_1 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (hx : x * a = tx) (hy : y * b = ty) (h : tx + d = ty) : nat.gcd x y = d :=\n(nat.gcd_comm _ _).trans $ nat_gcd_helper_2 _ _ _ _ _ _ _ _ _ hv hu hy hx h\n\nlemma nat_lcm_helper (x y d m n : \u2115) (hd : nat.gcd x y = d) (d0 : 0 < d)\n  (xy : x * y = n) (dm : d * m = n) : nat.lcm x y = m :=\nmul_right_injective\u2080 d0.ne' $ by rw [dm, \u2190 xy, \u2190 hd, nat.gcd_mul_lcm]\n\nlemma nat_coprime_helper_zero_left (x : \u2115) (h : 1 < x) : \u00ac nat.coprime 0 x :=\nmt (nat.coprime_zero_left _).1 $ ne_of_gt h\n\nlemma nat_coprime_helper_zero_right (x : \u2115) (h : 1 < x) : \u00ac nat.coprime x 0 :=\nmt (nat.coprime_zero_right _).1 $ ne_of_gt h\n\n\n\nlemma nat_coprime_helper_2 (x y a b tx ty : \u2115)\n  (hx : x * a = tx) (hy : y * b = ty) (h : ty + 1 = tx) : nat.coprime x y :=\nnat_gcd_helper_2 _ _ _ _ _ _ _ _ _ (one_mul _) (one_mul _) hx hy h\n\nlemma nat_not_coprime_helper (d x y u v : \u2115) (hu : d * u = x) (hv : d * v = y)\n  (h : 1 < d) : \u00ac nat.coprime x y :=\nnat.not_coprime_of_dvd_of_dvd h \u27e8_, hu.symm\u27e9 \u27e8_, hv.symm\u27e9\n\nlemma int_gcd_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx:\u2124) = x) (hy : (ny:\u2124) = y)\n  (h : nat.gcd nx ny = d) : int.gcd x y = d :=\nby rwa [\u2190 hx, \u2190 hy, int.coe_nat_gcd]\n\nlemma int_gcd_helper_neg_left (x y : \u2124) (d : \u2115) (h : int.gcd x y = d) : int.gcd (-x) y = d :=\nby rw int.gcd at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_gcd_helper_neg_right (x y : \u2124) (d : \u2115) (h : int.gcd x y = d) : int.gcd x (-y) = d :=\nby rw int.gcd at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_lcm_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx:\u2124) = x) (hy : (ny:\u2124) = y)\n  (h : nat.lcm nx ny = d) : int.lcm x y = d :=\nby rwa [\u2190 hx, \u2190 hy, int.coe_nat_lcm]\n\nlemma int_lcm_helper_neg_left (x y : \u2124) (d : \u2115) (h : int.lcm x y = d) : int.lcm (-x) y = d :=\nby rw int.lcm at h \u22a2; rwa int.nat_abs_neg\n\nlemma int_lcm_helper_neg_right (x y : \u2124) (d : \u2115) (h : int.lcm x y = d) : int.lcm x (-y) = d :=\nby rw int.lcm at h \u22a2; rwa int.nat_abs_neg\n\n/-- Evaluates the `nat.gcd` function. -/\nmeta def prove_gcd_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 0, _ := pure (c, ey, `(nat.gcd_zero_left).mk_app [ey])\n  | _, 0 := pure (c, ex, `(nat.gcd_zero_right).mk_app [ex])\n  | 1, _ := pure (c, `(1:\u2115), `(nat.gcd_one_left).mk_app [ey])\n  | _, 1 := pure (c, `(1:\u2115), `(nat.gcd_one_right).mk_app [ex])\n  | _, _ := do\n    let (d, a, b) := nat.xgcd_aux x 1 0 y 0 1,\n    if d = x then do\n      (c, ea) \u2190 c.of_nat (y / x),\n      (c, _, p) \u2190 prove_mul_nat c ex ea,\n      pure (c, ex, `(nat_gcd_helper_dvd_left).mk_app [ex, ey, ea, p])\n    else if d = y then do\n      (c, ea) \u2190 c.of_nat (x / y),\n      (c, _, p) \u2190 prove_mul_nat c ey ea,\n      pure (c, ey, `(nat_gcd_helper_dvd_right).mk_app [ex, ey, ea, p])\n    else do\n      (c, ed) \u2190 c.of_nat d,\n      (c, ea) \u2190 c.of_nat a.nat_abs,\n      (c, eb) \u2190 c.of_nat b.nat_abs,\n      (c, eu) \u2190 c.of_nat (x / d),\n      (c, ev) \u2190 c.of_nat (y / d),\n      (c, _, pu) \u2190 prove_mul_nat c ed eu,\n      (c, _, pv) \u2190 prove_mul_nat c ed ev,\n      (c, etx, px) \u2190 prove_mul_nat c ex ea,\n      (c, ety, py) \u2190 prove_mul_nat c ey eb,\n      (c, p) \u2190 if a \u2265 0 then prove_add_nat c ety ed etx else prove_add_nat c etx ed ety,\n      let pf : expr := if a \u2265 0 then `(nat_gcd_helper_2) else `(nat_gcd_helper_1),\n      pure (c, ed, pf.mk_app [ed, ex, ey, ea, eb, eu, ev, etx, ety, pu, pv, px, py, p])\n  end\n\n/-- Evaluates the `nat.lcm` function. -/\nmeta def prove_lcm_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 0, _ := pure (c, `(0:\u2115), `(nat.lcm_zero_left).mk_app [ey])\n  | _, 0 := pure (c, `(0:\u2115), `(nat.lcm_zero_right).mk_app [ex])\n  | 1, _ := pure (c, ey, `(nat.lcm_one_left).mk_app [ey])\n  | _, 1 := pure (c, ex, `(nat.lcm_one_right).mk_app [ex])\n  | _, _ := do\n    (c, ed, pd) \u2190 prove_gcd_nat c ex ey,\n    (c, p0) \u2190 prove_pos c ed,\n    (c, en, xy) \u2190 prove_mul_nat c ex ey,\n    d \u2190 ed.to_nat,\n    (c, em) \u2190 c.of_nat ((x * y) / d),\n    (c, _, dm) \u2190 prove_mul_nat c ed em,\n    pure (c, em, `(nat_lcm_helper).mk_app [ex, ey, ed, em, en, pd, p0, xy, dm])\n  end\n\n/-- Evaluates the `int.gcd` function. -/\nmeta def prove_gcd_int (zc nc : instance_cache) : expr \u2192 expr \u2192\n  tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| x y := match match_neg x with\n  | some x := do\n    (zc, nc, d, p) \u2190 prove_gcd_int x y,\n    pure (zc, nc, d, `(int_gcd_helper_neg_left).mk_app [x, y, d, p])\n  | none := match match_neg y with\n    | some y := do\n      (zc, nc, d, p) \u2190 prove_gcd_int x y,\n      pure (zc, nc, d, `(int_gcd_helper_neg_right).mk_app [x, y, d, p])\n    | none := do\n      (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x,\n      (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y,\n      (nc, d, p) \u2190 prove_gcd_nat nc nx ny,\n      pure (zc, nc, d, `(int_gcd_helper).mk_app [x, y, nx, ny, d, px, py, p])\n    end\n  end\n\n/-- Evaluates the `int.lcm` function. -/\nmeta def prove_lcm_int (zc nc : instance_cache) : expr \u2192 expr \u2192\n  tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| x y := match match_neg x with\n  | some x := do\n    (zc, nc, d, p) \u2190 prove_lcm_int x y,\n    pure (zc, nc, d, `(int_lcm_helper_neg_left).mk_app [x, y, d, p])\n  | none := match match_neg y with\n    | some y := do\n      (zc, nc, d, p) \u2190 prove_lcm_int x y,\n      pure (zc, nc, d, `(int_lcm_helper_neg_right).mk_app [x, y, d, p])\n    | none := do\n      (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x,\n      (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y,\n      (nc, d, p) \u2190 prove_lcm_nat nc nx ny,\n      pure (zc, nc, d, `(int_lcm_helper).mk_app [x, y, nx, ny, d, px, py, p])\n    end\n  end\n\n/-- Evaluates the `nat.coprime` function. -/\nmeta def prove_coprime_nat (c : instance_cache) (ex ey : expr) :\n  tactic (instance_cache \u00d7 (expr \u2295 expr)) := do\n  x \u2190 ex.to_nat,\n  y \u2190 ey.to_nat,\n  match x, y with\n  | 1, _ := pure (c, sum.inl $ `(nat.coprime_one_left).mk_app [ey])\n  | _, 1 := pure (c, sum.inl $ `(nat.coprime_one_right).mk_app [ex])\n  | 0, 0 := pure (c, sum.inr `(nat.not_coprime_zero_zero))\n  | 0, _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, p) \u2190 prove_lt_nat c `(1) ey,\n    pure (c, sum.inr $ `(nat_coprime_helper_zero_left).mk_app [ey, p])\n  | _, 0 := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, p) \u2190 prove_lt_nat c `(1) ex,\n    pure (c, sum.inr $ `(nat_coprime_helper_zero_right).mk_app [ex, p])\n  | _, _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    let (d, a, b) := nat.xgcd_aux x 1 0 y 0 1,\n    if d = 1 then do\n      (c, ea) \u2190 c.of_nat a.nat_abs,\n      (c, eb) \u2190 c.of_nat b.nat_abs,\n      (c, etx, px) \u2190 prove_mul_nat c ex ea,\n      (c, ety, py) \u2190 prove_mul_nat c ey eb,\n      (c, p) \u2190 if a \u2265 0 then prove_add_nat c ety `(1) etx else prove_add_nat c etx `(1) ety,\n      let pf : expr := if a \u2265 0 then `(nat_coprime_helper_2) else `(nat_coprime_helper_1),\n      pure (c, sum.inl $ pf.mk_app [ex, ey, ea, eb, etx, ety, px, py, p])\n    else do\n      (c, ed) \u2190 c.of_nat d,\n      (c, eu) \u2190 c.of_nat (x / d),\n      (c, ev) \u2190 c.of_nat (y / d),\n      (c, _, pu) \u2190 prove_mul_nat c ed eu,\n      (c, _, pv) \u2190 prove_mul_nat c ed ev,\n      (c, p) \u2190 prove_lt_nat c `(1) ed,\n      pure (c, sum.inr $ `(nat_not_coprime_helper).mk_app [ed, ex, ey, eu, ev, pu, pv, p])\n  end\n\n/-- Evaluates the `gcd`, `lcm`, and `coprime` functions. -/\n@[norm_num] meta def eval_gcd : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.gcd %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prod.snd <$> prove_gcd_nat c ex ey\n| `(nat.lcm %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prod.snd <$> prove_lcm_nat c ex ey\n| `(nat.coprime %%ex %%ey) := do\n    c \u2190 mk_instance_cache `(\u2115),\n    prove_coprime_nat c ex ey >>= sum.elim true_intro false_intro \u2218 prod.snd\n| `(int.gcd %%ex %%ey) := do\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> prove_gcd_int zc nc ex ey\n| `(int.lcm %%ex %%ey) := do\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> prove_lcm_int zc nc ex ey\n| _ := failed\n\nend norm_num\nend tactic\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7306532339815268}}
{"text": "import data.real.basic\n\nvariables a b c d : \u211d \n\n#check add_mul\n#check add_mul c a b\n#check add_sub\n#check add_sub c b a\n#check sub_zero\n#check sub_self\n#check sub_add\n#check sub_sub\n#check mul_comm d c \n#check mul_sub a b c\n#check pow_two d\n\n\n-- BEGIN\nexample (a b : \u211d) : (a + b) * (a - b) = a^2 - b^2 :=\nbegin\n  rw [add_mul, mul_sub, mul_sub],\n  rw [add_sub, mul_comm b a, sub_add, sub_self, sub_zero],\n  rw [\u2190 pow_two a, \u2190 pow_two b],\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/1_rw/ex16_rw_diff of sqr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7305945286504498}}
{"text": "/-\nif R is a ring and S is a multiplicative subset of R then S\u22121R is the zero ring if and only if S contains 0, \n\n[proof omitted]\n-/\n\nimport ring_theory.localization group_theory.submonoid\n\nuniverse u\n\nvariables {\u03b1 : Type u} [comm_ring \u03b1] (S : set \u03b1) [is_submonoid S]\n\ntheorem localization.subsingleton_iff_zero_mem : subsingleton (localization.loc \u03b1 S) \u2194 (0:\u03b1) \u2208 S :=\n\u27e8\u03bb \u27e8h\u27e9, let \u27e8w, H, hw\u27e9 := quotient.exact (h 0 1) in by simp at hw; rwa hw at H,\n \u03bb h, \u27e8\u03bb x y, quotient.induction_on\u2082 x y $ \u03bb \u27e8m\u2081, m\u2082, hm\u27e9 \u27e8n\u2081, n\u2082, hn\u27e9, quotient.sound $ \u27e80, h, by simp\u27e9\u27e9\u27e9", "meta": {"author": "kbuzzard", "repo": "lean-stacks-project", "sha": "b57be17aa917f1c3a23c59db5ee37b1aa21112c2", "save_path": "github-repos/lean/kbuzzard-lean-stacks-project", "path": "github-repos/lean/kbuzzard-lean-stacks-project/lean-stacks-project-b57be17aa917f1c3a23c59db5ee37b1aa21112c2/src/tag00C6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7305945111028167}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.free_module.basic\nimport linear_algebra.matrix.to_lin\nimport ring_theory.finiteness\n\n/-!\n# Finite and free modules\n\nWe provide some instances for finite and free modules.\n\n## Main results\n\n* `module.free.choose_basis_index.fintype` : If a free module is finite, then any basis is\n  finite.\n* `module.free.linear_map.free ` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N` is free.\n* `module.finite.of_basis` : A free module with a basis indexed by a `fintype` is finite.\n* `module.free.linear_map.module.finite` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N`\n  is finite.\n-/\n\nuniverses u v w\n\nvariables (R : Type u) (M : Type v) (N : Type w)\n\nnamespace module.free\n\nsection ring\n\nvariables [ring R] [add_comm_group M] [module R M] [module.free R M]\n\n/-- If a free module is finite, then any basis is finite. -/\nnoncomputable\ninstance [nontrivial R] [module.finite R M] :\n  fintype (module.free.choose_basis_index R M) :=\nbegin\n  obtain \u27e8h\u27e9 := id \u2039module.finite R M\u203a,\n  choose s hs using h,\n  exact basis_fintype_of_finite_spans \u2191s hs (choose_basis _ _),\nend\n\nend ring\n\nsection comm_ring\n\nvariables [comm_ring R] [add_comm_group M] [module R M] [module.free R M]\nvariables [add_comm_group N] [module R N] [module.free R N]\n\ninstance [nontrivial R] [module.finite R M] [module.finite R N] : module.free R (M \u2192\u2097[R] N) :=\nbegin\n  classical,\n  exact of_equiv\n    (linear_map.to_matrix (module.free.choose_basis R M) (module.free.choose_basis R N)).symm,\nend\n\nvariables {R M}\n\n/-- A free module with a basis indexed by a `fintype` is finite. -/\nlemma _root_.module.finite.of_basis {R : Type*} {M : Type*} {\u03b9 : Type*} [comm_ring R]\n  [add_comm_group M] [module R M] [fintype \u03b9] (b : basis \u03b9 R M) : module.finite R M :=\nbegin\n  classical,\n  refine \u27e8\u27e8finset.univ.image b, _\u27e9\u27e9,\n  simp only [set.image_univ, finset.coe_univ, finset.coe_image, basis.span_eq],\nend\n\ninstance _root_.module.finite.matrix {\u03b9\u2081 : Type*} [fintype \u03b9\u2081] {\u03b9\u2082 : Type*} [fintype \u03b9\u2082] :\n  module.finite R (matrix \u03b9\u2081 \u03b9\u2082 R) :=\nmodule.finite.of_basis $ pi.basis $ \u03bb i, pi.basis_fun R _\n\ninstance [nontrivial R] [module.finite R M] [module.finite R N] :\n  module.finite R (M \u2192\u2097[R] N) :=\nbegin\n  classical,\n  have f := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)).symm,\n  exact module.finite.of_surjective f.to_linear_map (linear_equiv.surjective f),\nend\n\nend comm_ring\n\nsection integer\n\nvariables [add_comm_group M] [module.finite \u2124 M] [module.free \u2124 M]\nvariables [add_comm_group N] [module.finite \u2124 N] [module.free \u2124 N]\n\ninstance : module.finite \u2124 (M \u2192+ N) :=\nmodule.finite.equiv (add_monoid_hom_lequiv_int \u2124).symm\n\ninstance : module.free \u2124 (M \u2192+ N) :=\nmodule.free.of_equiv (add_monoid_hom_lequiv_int \u2124).symm\n\nend integer\n\nend module.free\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/free_module/finite/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.730580344269612}}
{"text": "/-\nAn exhaustive description of all possible moves in the game.\n\nMoves of the form `move__nil` are to towers that are empty, while moves of the form\n`move__cons` are to towers having at least one disc. The condition of the larger discs being below the\nsmaller ones is enforced in the latter case.\n-/\ninductive TowersOfHanoi (n : Nat) : List Nat \u2192 List Nat \u2192 List Nat \u2192 Type _\n\n  | move\u2081\u2082nil {a : Nat} {as cs : List Nat} :\n    TowersOfHanoi n (a :: as) [] cs \u2192 TowersOfHanoi n as [a] cs\n\n  | move\u2081\u2082cons {a b : Nat} {as bs cs : List Nat} :\n    (a < b) \u2192 TowersOfHanoi n (a :: as) (b :: bs) cs \u2192 TowersOfHanoi n as (a :: b :: bs) cs\n\n  | move\u2081\u2083nil {a : Nat} {as bs : List Nat} :\n    TowersOfHanoi n (a :: as) bs [] \u2192 TowersOfHanoi n as bs [a]\n\n  | move\u2081\u2083cons {a b : Nat} {as bs cs : List Nat} :\n    (a < c) \u2192 TowersOfHanoi n (a :: as) bs (c :: cs) \u2192 TowersOfHanoi n as bs (a :: c :: cs)\n\n  | move\u2082\u2083nil {b : Nat} {as bs : List Nat} :\n    TowersOfHanoi n as (b :: bs) [] \u2192 TowersOfHanoi n as bs [b]\n\n  | move\u2082\u2083cons {b c : Nat} {as bs cs : List Nat} :\n    (b < c) \u2192 TowersOfHanoi n as (b :: bs) cs \u2192 TowersOfHanoi n as bs (b :: c :: cs)\n\n  | move\u2083\u2082nil {c : Nat} {as cs : List Nat} :\n    TowersOfHanoi n as [] (c :: cs) \u2192 TowersOfHanoi n as [c] cs\n\n  | move\u2083\u2082cons {b c : Nat} {as bs cs : List Nat} :\n    (c < b) \u2192 TowersOfHanoi n as (b :: bs) (c :: cs) \u2192 TowersOfHanoi n as (c :: b :: bs) cs\n\n  | move\u2082\u2081nil {b : Nat} {bs cs : List Nat} :\n    TowersOfHanoi n [] (b :: bs) cs \u2192 TowersOfHanoi n [b] bs cs\n\n  | move\u2082\u2081cons {a b : Nat} {as bs cs : List Nat} :\n    (b < a) \u2192 TowersOfHanoi n (a :: as) (b :: bs) cs \u2192 TowersOfHanoi n (b :: a :: as) bs cs\n\n  | move\u2083\u2081nil {c : Nat} {bs cs : List Nat} :\n    TowersOfHanoi n [] bs (c :: cs) \u2192 TowersOfHanoi n [c] bs cs\n\n  | move\u2083\u2081cons {a c : Nat} {as bs cs : List Nat} :\n    (c < a) \u2192 TowersOfHanoi n (a :: as) bs  (c :: cs) \u2192 TowersOfHanoi n (c :: a :: as) bs cs\n\n\nopen TowersOfHanoi\n\n/-\nCustom tactics for playing the game.\n\nThe `moveXY` tactic invokes the built-in `apply` tactic\nwhich uses a function `f : \u03b1 \u2192 \u03b2` to convert a goal `\u22a2 \u03b2` to `\u22a2 \u03b1`.\n\nThis is the reason the constructors of the form `moveYX`` are applied.\n-/\n\nsection movetactics\n\nmacro \"moveAB\" : tactic => `(first\n                               | apply move\u2082\u2081cons ; simp\n                               | apply move\u2082\u2081nil)\n\nmacro \"moveAC\" : tactic => `(first\n                               | apply move\u2083\u2081cons ; simp\n                               | apply move\u2083\u2081nil)\n\nmacro \"moveBA\" : tactic => `(first\n                               | apply move\u2081\u2082cons ; simp\n                               | apply move\u2081\u2082nil)\n\nmacro \"moveBC\" : tactic => `(first\n                               | apply move\u2083\u2082cons ; simp\n                               | apply move\u2083\u2082nil)\n\nmacro \"moveCA\" : tactic => `(first\n                               | apply move\u2081\u2083cons ; simp\n                               | apply move\u2081\u2083nil)\n\nmacro \"moveCB\" : tactic => `(first\n                               | apply move\u2082\u2083cons ; simp\n                               | apply move\u2082\u2083nil)\n\nmacro \"done\" : tactic => `(assumption)\n\nend movetactics\n\n\n-- an example of the game in action\nexample (goal : TowersOfHanoi 2 [] [] [0, 1]) : TowersOfHanoi 2 [0, 1] [] [] := by\n  moveAC\n  moveAB\n  moveCA\n  moveBC\n  moveAC\n  done\n\ntheorem moveStack {n : Nat} {as bs cs as' bs' cs' : List Nat} (\u03b1s \u03b2s \u03b3s : List Nat)\n  (init : TowersOfHanoi n as bs cs) (final : TowersOfHanoi n as' bs' cs') :\n  (TowersOfHanoi n (as ++ \u03b1s) (bs ++ \u03b2s) (cs ++ \u03b3s)) \u2192 (TowersOfHanoi n (as' ++ \u03b1s) (bs' ++ \u03b2s) (cs' ++ \u03b3s)) := by\n  intro moves\n  sorry\n", "meta": {"author": "crabbo-rave", "repo": "leandiscord-weekly", "sha": "e66366d9d6e896d0e86607bd1de791811d1c0043", "save_path": "github-repos/lean/crabbo-rave-leandiscord-weekly", "path": "github-repos/lean/crabbo-rave-leandiscord-weekly/leandiscord-weekly-e66366d9d6e896d0e86607bd1de791811d1c0043/Week 2/art-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7305803361170278}}
{"text": "import probability_density\n\nnoncomputable theory\nopen_locale classical measure_theory nnreal ennreal\n\nnamespace measure_theory\n\nopen measure_theory measure_theory.measure topological_space real\n\nvariables {\u03b1 \u03b2 : Type*} [measurable_space \u03b1] [measurable_space \u03b2] \nvariables {E : Type*} [inner_product_space \u211d E] [measurable_space E] \n  [second_countable_topology E] [complete_space E] [borel_space E] \n  \nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \u211d E _ x y\n\n/-- The Laplace transform of a measure on some set. -/\ndef laplace_transform (\u03bc : measure E) (support : set E) : E \u2192 \u211d := \n\u03bb s, \u222b x in support, exp (-\u27eas, x\u27eb) \u2202\u03bc\n\n-- make it localized \nnotation `\ud835\udcdb ` \u03bc:75 := laplace_transform \u03bc set.univ\nnotation `\ud835\udcdb ` \u03bc ` on ` support:75 := laplace_transform \u03bc support\n\n@[measurability]\nlemma measurable_inner_right (x : E) : measurable (\u03bb y, \u27eax, y\u27eb) :=\n(inner_right x).continuous.measurable\n\n/-- If `S` is a region of the domain such that for all `s \u2208 S`, `x \u2208 support` we have \n`\u27eas, x\u27eb \u22650`, then the Laplace transformation exists in `S`. This is mostly useful for \nproving properties of the Laplace transform with the support being [0, \u221e). -/\nlemma integrable_on_exp_neg_inner {\u03bc : measure E} {support S : set E} \n  (hsupport : \u03bc support < \u221e) (hS : \u2200 \u2983s x\u2984, s \u2208 S \u2192 x \u2208 support \u2192 0 \u2264 \u27eas, x\u27eb)\n  {s : E} (hs : s \u2208 S) : integrable_on (\u03bb x, exp (-\u27eas, x\u27eb)) support \u03bc :=\nbegin\n  refine \u27e8by measurability, _\u27e9,\n  refine lt_of_le_of_lt (set_lintegral_mono_on _ (@measurable_const _ _ _ _ 1) _) _,\n  { measurability },\n  { intros x hx,\n    specialize hS hs hx,\n    rw [ennreal.coe_le_one_iff, nnnorm_of_nonneg (le_of_lt (exp_pos _))],\n    change _ \u2264 (\u27e81, zero_le_one\u27e9 : \u211d\u22650),\n    simp [hS] },\n  { rwa [set_lintegral_const, one_mul] }\nend\n\nsection\n\nvariables {\u03bc \u03bd : measure E} {support : set E}\n\nlemma laplace_transform_add {s : E} \n  (h\u03bcs : integrable_on (\u03bb x, exp (-\u27eas, x\u27eb)) support \u03bc)\n  (h\u03bds : integrable_on (\u03bb x, exp (-\u27eas, x\u27eb)) support \u03bd) : \n  (\ud835\udcdb (\u03bc + \u03bd) on support) s = (\ud835\udcdb \u03bc on support) s + (\ud835\udcdb \u03bd on support) s :=\nbegin\n  simp only [laplace_transform, restrict_add, pi.add_apply],\n  rw [integral_add_measure h\u03bcs h\u03bds]\nend\n\nlemma laplace_transform_smul {s : E} {c : \u211d\u22650} : \n  (\ud835\udcdb (c \u2022 \u03bc) on support) s = c \u2022 (\ud835\udcdb \u03bc on support) s := \nbegin\n  simp only [laplace_transform],\n  erw [restrict_smul, integral_smul_measure],\n  refl\nend\n\n/-- The Laplace transform of `\u03bc.with_density f` on the set `S` equals \n`\u222b x in S, exp (-\u27eas, x\u27eb) * f x \u2202\u03bc`. \n\nThe latter integral is the more commonly seen definition for the Laplace transformation \nof a function. With this lemma, if `X` is a random variable and `\u2119` is a probability measure, \n`\ud835\udcdb (map X \u2119) s = \u222b exp(-sx) * pdf X \u2202\u03bb = \ud835\udd3c[exp(-s X)]` where `\u03bb` is the Lebesgue measure. -/\nlemma laplace_transform_with_density (hsupp : measurable_set support)\n  {f : E \u2192 \u211d\u22650\u221e} (hf : measurable f) (hf' : \u2200\u1d50 x \u2202\u03bc, x \u2208 support \u2192 f x < \u221e) {s : E} :\n  (\ud835\udcdb (\u03bc.with_density f) on support) s = \u222b x in support, exp (-\u27eas, x\u27eb) * (f x).to_real \u2202\u03bc :=\nbegin\n  simp only [laplace_transform],\n  rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae],\n  { rw [set_lintegral_with_density_eq_set_lintegral_mul _ hf \n        (measurable_const.inner measurable_id').neg.exp.ennreal_of_real hsupp],\n    congr' 1,\n    refine set_lintegral_congr_fun hsupp \n      (filter.eventually.mp hf' (ae_of_all _ (\u03bb x hx hmem, _))),\n    rw [ennreal.of_real_mul (le_of_lt (exp_pos _)), \n        ennreal.of_real_to_real (hx hmem).ne, mul_comm], \n    refl },\n  all_goals { try { measurability } },\n  { exact ae_of_all _ (\u03bb x, mul_nonneg (le_of_lt (exp_pos _)) ennreal.to_real_nonneg) },\n  { refine ae_of_all _ (\u03bb x, le_of_lt (exp_pos _)) },\nend\n\nlemma laplace_transform_map (hsupp : measurable_set support) \n  {f : E \u2192 E} (hf : measurable f) {s : E} : \n  (\ud835\udcdb (map f \u03bc) on support) s = \u222b x in f \u207b\u00b9' support, exp (-\u27eas, f x\u27eb) \u2202\u03bc :=\nbegin\n  simp only [laplace_transform],\n  rw set_integral_map hsupp _ hf,\n  measurability,\nend\n\n/-- Given a measure `\u03bc`, the Laplace transform of `\u03bc.with_density (x \u21a6 exp(-\u27eat, x\u27eb))` at `s` \nequals the Laplace transform of `\u03bc` at `s + t`. -/\nlemma laplace_transform_with_density_add (hsupp : measurable_set support) {s t : E} :\n  (\ud835\udcdb (\u03bc.with_density (\u03bb x, ennreal.of_real (exp (-\u27eat, x\u27eb)))) on support) s = \n  (\ud835\udcdb \u03bc on support) (s + t) :=\nbegin\n  rw laplace_transform_with_density hsupp,\n  { have : \u2200 x, (ennreal.of_real (exp (-\u27eat, x\u27eb))).to_real = exp (-\u27eat, x\u27eb),\n    { intro x, rw ennreal.to_real_of_real (le_of_lt (exp_pos _)) },\n    simp_rw [this, \u2190 exp_add, \u2190 neg_add, \u2190 inner_add_left],\n    refl },\n  { measurability },\n  { exact (ae_of_all _ (\u03bb x hx, ennreal.of_real_lt_top)) },\nend\n\nlemma laplace_transform_with_density_smul \n  (hsupp : measurable_set support) {s : E} {c : \u211d} :\n  (\ud835\udcdb (map (\u03bb x, c \u2022 x) \u03bc) on support) s = (\ud835\udcdb \u03bc on ((\u03bb x, c \u2022 x) \u207b\u00b9' support)) (c \u2022 s) :=\nbegin\n  rw laplace_transform_map hsupp (measurable_id'.const_smul' c),\n  simp only [laplace_transform, inner_smul_left, inner_smul_right, is_R_or_C.conj_to_real]\nend\n\nend\n\nend measure_theory", "meta": {"author": "JasonKYi", "repo": "probability_theory", "sha": "01aa0e1372cb0311c90be59ea18944c5ef5f2293", "save_path": "github-repos/lean/JasonKYi-probability_theory", "path": "github-repos/lean/JasonKYi-probability_theory/probability_theory-01aa0e1372cb0311c90be59ea18944c5ef5f2293/archive/laplace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7305803347369785}}
{"text": "-- Complementario de un conjunto: Pruebas de A \\ B \u2286 B\u1d9c\n-- ====================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    A \\ B \u2286 B\u1d9c\n-- ----------------------------------------------------\n\nimport data.set\n\nvariable  {U : Type}\nvariables A B : set U\nvariable  x : U\n\nopen set\n\n-- #reduce x \u2208 B\u1d9c\n-- #reduce B\u1d9c\n\n-- 1\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\nbegin\n  intros x h,\n  simp at *,\n  exact h.right,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\nbegin\n  intros x h,\n  exact h.right,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\nassume x,\nassume h1 : x \u2208 A \\ B,\nhave h2 : x \u2209 B, from and.right h1,\nshow x \u2208 B\u1d9c,     from h2\n\n-- 4\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\nassume x,\nassume h1 : x \u2208 A \\ B,\nshow x \u2208 B\u1d9c, from and.right h1\n\n-- 5\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\nassume x,\n\u03bb h1, and.right h1\n\n-- 6\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\nassume x, \nand.right\n\n-- 7\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\n\u03bb _, and.right \n\n-- 8\u00aa demostraci\u00f3n\nexample : A \\ B \u2286 B\u1d9c :=\n\u03bb _, not_mem_of_mem_diff \n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Pruebas_de_diff(A,B)\u2286B\u1d9c.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7305803344737398}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module data.polynomial.laurent\n! leanprover-community/mathlib commit 831c494092374cfe9f50591ed0ac81a25efc5b86\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Polynomial.AlgebraMap\nimport Mathbin.RingTheory.Localization.Basic\n\n/-!  # Laurent polynomials\n\nWe introduce Laurent polynomials over a semiring `R`.  Mathematically, they are expressions of the\nform\n$$\n\\sum_{i \\in \\mathbb{Z}} a_i T ^ i\n$$\nwhere the sum extends over a finite subset of `\u2124`.  Thus, negative exponents are allowed.  The\ncoefficients come from the semiring `R` and the variable `T` commutes with everything.\n\nSince we are going to convert back and forth between polynomials and Laurent polynomials, we\ndecided to maintain some distinction by using the symbol `T`, rather than `X`, as the variable for\nLaurent polynomials\n\n## Notation\nThe symbol `R[T;T\u207b\u00b9]` stands for `laurent_polynomial R`.  We also define\n\n* `C : R \u2192+* R[T;T\u207b\u00b9]` the inclusion of constant polynomials, analogous to the one for `R[X]`;\n* `T : \u2124 \u2192 R[T;T\u207b\u00b9]` the sequence of powers of the variable `T`.\n\n## Implementation notes\n\nWe define Laurent polynomials as `add_monoid_algebra R \u2124`.\nThus, they are essentially `finsupp`s `\u2124 \u2192\u2080 R`.\nThis choice differs from the current irreducible design of `polynomial`, that instead shields away\nthe implementation via `finsupp`s.  It is closer to the original definition of polynomials.\n\nAs a consequence, `laurent_polynomial` plays well with polynomials, but there is a little roughness\nin establishing the API, since the `finsupp` implementation of `R[X]` is well-shielded.\n\nUnlike the case of polynomials, I felt that the exponent notation was not too easy to use, as only\nnatural exponents would be allowed.  Moreover, in the end, it seems likely that we should aim to\nperform computations on exponents in `\u2124` anyway and separating this via the symbol `T` seems\nconvenient.\n\nI made a *heavy* use of `simp` lemmas, aiming to bring Laurent polynomials to the form `C a * T n`.\nAny comments or suggestions for improvements is greatly appreciated!\n\n##  Future work\nLots is missing!\n-- (Riccardo) add inclusion into Laurent series.\n-- (Riccardo) giving a morphism (as `R`-alg, so in the commutative case)\n  from `R[T,T\u207b\u00b9]` to `S` is the same as choosing a unit of `S`.\n-- A \"better\" definition of `trunc` would be as an `R`-linear map.  This works:\n--  ```\n--  def trunc : R[T;T\u207b\u00b9] \u2192[R] R[X] :=\n--  begin\n--    refine (_ : add_monoid_algebra R \u2115 \u2192[R] R[X]).comp _,\n--    { exact \u27e8(to_finsupp_iso R).symm, by simp\u27e9 },\n--    { refine \u27e8\u03bb r, comap_domain _ r (set.inj_on_of_injective (\u03bb a b ab, int.of_nat.inj ab) _), _\u27e9,\n--      exact \u03bb r f, comap_domain_smul _ _ _ }\n--  end\n--  ```\n--  but it would make sense to bundle the maps better, for a smoother user experience.\n--  I (DT) did not have the strength to embark on this (possibly short!) journey, after getting to\n--  this stage of the Laurent process!\n--  This would likely involve adding a `comap_domain` analogue of\n--  `add_monoid_algebra.map_domain_alg_hom` and an `R`-linear version of\n--  `polynomial.to_finsupp_iso`.\n-- Add `degree, int_degree, int_trailing_degree, leading_coeff, trailing_coeff,...`.\n-/\n\n\nopen Polynomial BigOperators\n\nopen Polynomial AddMonoidAlgebra Finsupp\n\nnoncomputable section\n\nvariable {R : Type _}\n\n/-- The semiring of Laurent polynomials with coefficients in the semiring `R`.\nWe denote it by `R[T;T\u207b\u00b9]`.\nThe ring homomorphism `C : R \u2192+* R[T;T\u207b\u00b9]` includes `R` as the constant polynomials. -/\nabbrev LaurentPolynomial (R : Type _) [Semiring R] :=\n  AddMonoidAlgebra R \u2124\n#align laurent_polynomial LaurentPolynomial\n\n-- mathport name: \u00abexpr [T;T\u207b\u00b9]\u00bb\nlocal notation:9000 R \"[T;T\u207b\u00b9]\" => LaurentPolynomial R\n\n/-- The ring homomorphism, taking a polynomial with coefficients in `R` to a Laurent polynomial\nwith coefficients in `R`. -/\ndef Polynomial.toLaurent [Semiring R] : R[X] \u2192+* R[T;T\u207b\u00b9] :=\n  (mapDomainRingHom R Int.ofNatHom).comp (toFinsuppIso R)\n#align polynomial.to_laurent Polynomial.toLaurent\n\n/-- This is not a simp lemma, as it is usually preferable to use the lemmas about `C` and `X`\ninstead. -/\ntheorem Polynomial.toLaurent_apply [Semiring R] (p : R[X]) :\n    p.toLaurent = p.toFinsupp.mapDomain coe :=\n  rfl\n#align polynomial.to_laurent_apply Polynomial.toLaurent_apply\n\n/-- The `R`-algebra map, taking a polynomial with coefficients in `R` to a Laurent polynomial\nwith coefficients in `R`. -/\ndef Polynomial.toLaurentAlg [CommSemiring R] : R[X] \u2192\u2090[R] R[T;T\u207b\u00b9] :=\n  by\n  refine' AlgHom.comp _ (to_finsupp_iso_alg R).toAlgHom\n  exact map_domain_alg_hom R R Int.ofNatHom\n#align polynomial.to_laurent_alg Polynomial.toLaurentAlg\n\n@[simp]\ntheorem Polynomial.toLaurentAlg_apply [CommSemiring R] (f : R[X]) : f.toLaurentAlg = f.toLaurent :=\n  rfl\n#align polynomial.to_laurent_alg_apply Polynomial.toLaurentAlg_apply\n\nnamespace LaurentPolynomial\n\nsection Semiring\n\nvariable [Semiring R]\n\ntheorem single_zero_one_eq_one : (single 0 1 : R[T;T\u207b\u00b9]) = (1 : R[T;T\u207b\u00b9]) :=\n  rfl\n#align laurent_polynomial.single_zero_one_eq_one LaurentPolynomial.single_zero_one_eq_one\n\n/-!  ### The functions `C` and `T`. -/\n\n\n/-- The ring homomorphism `C`, including `R` into the ring of Laurent polynomials over `R` as\nthe constant Laurent polynomials. -/\ndef c : R \u2192+* R[T;T\u207b\u00b9] :=\n  singleZeroRingHom\n#align laurent_polynomial.C LaurentPolynomial.c\n\ntheorem algebraMap_apply {R A : Type _} [CommSemiring R] [Semiring A] [Algebra R A] (r : R) :\n    algebraMap R (LaurentPolynomial A) r = c (algebraMap R A r) :=\n  rfl\n#align laurent_polynomial.algebra_map_apply LaurentPolynomial.algebraMap_apply\n\n/-- When we have `[comm_semiring R]`, the function `C` is the same as `algebra_map R R[T;T\u207b\u00b9]`.\n(But note that `C` is defined when `R` is not necessarily commutative, in which case\n`algebra_map` is not available.)\n-/\ntheorem c_eq_algebraMap {R : Type _} [CommSemiring R] (r : R) : c r = algebraMap R R[T;T\u207b\u00b9] r :=\n  rfl\n#align laurent_polynomial.C_eq_algebra_map LaurentPolynomial.c_eq_algebraMap\n\ntheorem single_eq_c (r : R) : single 0 r = c r :=\n  rfl\n#align laurent_polynomial.single_eq_C LaurentPolynomial.single_eq_c\n\n/-- The function `n \u21a6 T ^ n`, implemented as a sequence `\u2124 \u2192 R[T;T\u207b\u00b9]`.\n\nUsing directly `T ^ n` does not work, since we want the exponents to be of Type `\u2124` and there\nis no `\u2124`-power defined on `R[T;T\u207b\u00b9]`.  Using that `T` is a unit introduces extra coercions.\nFor these reasons, the definition of `T` is as a sequence. -/\ndef t (n : \u2124) : R[T;T\u207b\u00b9] :=\n  single n 1\n#align laurent_polynomial.T LaurentPolynomial.t\n\n@[simp]\ntheorem t_zero : (t 0 : R[T;T\u207b\u00b9]) = 1 :=\n  rfl\n#align laurent_polynomial.T_zero LaurentPolynomial.t_zero\n\ntheorem t_add (m n : \u2124) : (t (m + n) : R[T;T\u207b\u00b9]) = t m * t n :=\n  by\n  convert single_mul_single.symm\n  simp [T]\n#align laurent_polynomial.T_add LaurentPolynomial.t_add\n\ntheorem t_sub (m n : \u2124) : (t (m - n) : R[T;T\u207b\u00b9]) = t m * t (-n) := by rw [\u2190 T_add, sub_eq_add_neg]\n#align laurent_polynomial.T_sub LaurentPolynomial.t_sub\n\n@[simp]\ntheorem t_pow (m : \u2124) (n : \u2115) : (t m ^ n : R[T;T\u207b\u00b9]) = t (n * m) := by\n  rw [T, T, single_pow n, one_pow, nsmul_eq_mul]\n#align laurent_polynomial.T_pow LaurentPolynomial.t_pow\n\n/-- The `simp` version of `mul_assoc`, in the presence of `T`'s. -/\n@[simp]\ntheorem mul_t_assoc (f : R[T;T\u207b\u00b9]) (m n : \u2124) : f * t m * t n = f * t (m + n) := by\n  simp [\u2190 T_add, mul_assoc]\n#align laurent_polynomial.mul_T_assoc LaurentPolynomial.mul_t_assoc\n\n@[simp]\ntheorem single_eq_c_mul_t (r : R) (n : \u2124) : (single n r : R[T;T\u207b\u00b9]) = (c r * t n : R[T;T\u207b\u00b9]) := by\n  convert single_mul_single.symm <;> simp\n#align laurent_polynomial.single_eq_C_mul_T LaurentPolynomial.single_eq_c_mul_t\n\n-- This lemma locks in the right changes and is what Lean proved directly.\n-- The actual `simp`-normal form of a Laurent monomial is `C a * T n`, whenever it can be reached.\n@[simp]\ntheorem Polynomial.toLaurent_c_mul_t (n : \u2115) (r : R) :\n    ((Polynomial.monomial n r).toLaurent : R[T;T\u207b\u00b9]) = c r * t n :=\n  show mapDomain coe (monomial n r).toFinsupp = (c r * t n : R[T;T\u207b\u00b9]) by\n    rw [to_finsupp_monomial, map_domain_single, single_eq_C_mul_T]\n#align polynomial.to_laurent_C_mul_T Polynomial.toLaurent_c_mul_t\n\n@[simp]\ntheorem Polynomial.toLaurent_c (r : R) : (Polynomial.C r).toLaurent = c r :=\n  by\n  convert Polynomial.toLaurent_c_mul_t 0 r\n  simp only [Int.ofNat_zero, T_zero, mul_one]\n#align polynomial.to_laurent_C Polynomial.toLaurent_c\n\n@[simp]\ntheorem Polynomial.toLaurent_x : (Polynomial.X.toLaurent : R[T;T\u207b\u00b9]) = t 1 :=\n  by\n  have : (Polynomial.X : R[X]) = monomial 1 1 := by simp [\u2190 C_mul_X_pow_eq_monomial]\n  simp [this, Polynomial.toLaurent_c_mul_t]\n#align polynomial.to_laurent_X Polynomial.toLaurent_x\n\n@[simp]\ntheorem Polynomial.toLaurent_one : (Polynomial.toLaurent : R[X] \u2192 R[T;T\u207b\u00b9]) 1 = 1 :=\n  map_one Polynomial.toLaurent\n#align polynomial.to_laurent_one Polynomial.toLaurent_one\n\n@[simp]\ntheorem Polynomial.toLaurent_c_mul_eq (r : R) (f : R[X]) :\n    (Polynomial.C r * f).toLaurent = c r * f.toLaurent := by\n  simp only [_root_.map_mul, Polynomial.toLaurent_c]\n#align polynomial.to_laurent_C_mul_eq Polynomial.toLaurent_c_mul_eq\n\n@[simp]\ntheorem Polynomial.toLaurent_x_pow (n : \u2115) : (X ^ n : R[X]).toLaurent = t n := by\n  simp only [map_pow, Polynomial.toLaurent_x, T_pow, mul_one]\n#align polynomial.to_laurent_X_pow Polynomial.toLaurent_x_pow\n\n@[simp]\ntheorem Polynomial.toLaurent_c_mul_x_pow (n : \u2115) (r : R) :\n    (Polynomial.C r * X ^ n).toLaurent = c r * t n := by\n  simp only [_root_.map_mul, Polynomial.toLaurent_c, Polynomial.toLaurent_x_pow]\n#align polynomial.to_laurent_C_mul_X_pow Polynomial.toLaurent_c_mul_x_pow\n\ninstance invertibleT (n : \u2124) : Invertible (t n : R[T;T\u207b\u00b9])\n    where\n  invOf := t (-n)\n  invOf_mul_self := by rw [\u2190 T_add, add_left_neg, T_zero]\n  mul_invOf_self := by rw [\u2190 T_add, add_right_neg, T_zero]\n#align laurent_polynomial.invertible_T LaurentPolynomial.invertibleT\n\n@[simp]\ntheorem invOf_t (n : \u2124) : \u215f (t n : R[T;T\u207b\u00b9]) = t (-n) :=\n  rfl\n#align laurent_polynomial.inv_of_T LaurentPolynomial.invOf_t\n\ntheorem isUnit_t (n : \u2124) : IsUnit (t n : R[T;T\u207b\u00b9]) :=\n  isUnit_of_invertible _\n#align laurent_polynomial.is_unit_T LaurentPolynomial.isUnit_t\n\n@[elab_as_elim]\nprotected theorem induction_on {M : R[T;T\u207b\u00b9] \u2192 Prop} (p : R[T;T\u207b\u00b9]) (h_C : \u2200 a, M (c a))\n    (h_add : \u2200 {p q}, M p \u2192 M q \u2192 M (p + q))\n    (h_C_mul_T : \u2200 (n : \u2115) (a : R), M (c a * t n) \u2192 M (c a * t (n + 1)))\n    (h_C_mul_T_Z : \u2200 (n : \u2115) (a : R), M (c a * t (-n)) \u2192 M (c a * t (-n - 1))) : M p :=\n  by\n  have A : \u2200 {n : \u2124} {a : R}, M (C a * T n) :=\n    by\n    intro n a\n    apply n.induction_on\n    \u00b7 simpa only [T_zero, mul_one] using h_C a\n    \u00b7 exact fun m => h_C_mul_T m a\n    \u00b7 exact fun m => h_C_mul_T_Z m a\n  have B : \u2200 s : Finset \u2124, M (s.Sum fun n : \u2124 => C (p.to_fun n) * T n) :=\n    by\n    apply Finset.induction\n    \u00b7 convert h_C 0\n      simp only [Finset.sum_empty, _root_.map_zero]\n    \u00b7 intro n s ns ih\n      rw [Finset.sum_insert ns]\n      exact h_add A ih\n  convert B p.support\n  ext a\n  simp_rw [\u2190 single_eq_C_mul_T, Finset.sum_apply', single_apply, Finset.sum_ite_eq']\n  split_ifs with h h\n  \u00b7 rfl\n  \u00b7 exact finsupp.not_mem_support_iff.mp h\n#align laurent_polynomial.induction_on LaurentPolynomial.induction_on\n\n/-- To prove something about Laurent polynomials, it suffices to show that\n* the condition is closed under taking sums, and\n* it holds for monomials.\n-/\n@[elab_as_elim]\nprotected theorem induction_on' {M : R[T;T\u207b\u00b9] \u2192 Prop} (p : R[T;T\u207b\u00b9])\n    (h_add : \u2200 p q, M p \u2192 M q \u2192 M (p + q)) (h_C_mul_T : \u2200 (n : \u2124) (a : R), M (c a * t n)) : M p :=\n  by\n  refine' p.induction_on (fun a => _) h_add _ _ <;> try exact fun n f _ => h_C_mul_T _ f\n  convert h_C_mul_T 0 a\n  exact (mul_one _).symm\n#align laurent_polynomial.induction_on' LaurentPolynomial.induction_on'\n\ntheorem commute_t (n : \u2124) (f : R[T;T\u207b\u00b9]) : Commute (t n) f :=\n  f.inductionOn' (fun p q Tp Tq => Commute.add_right Tp Tq) fun m a =>\n    show t n * _ = _\n      by\n      rw [T, T, \u2190 single_eq_C, single_mul_single, single_mul_single, single_mul_single]\n      simp [add_comm]\n#align laurent_polynomial.commute_T LaurentPolynomial.commute_t\n\n@[simp]\ntheorem t_mul (n : \u2124) (f : R[T;T\u207b\u00b9]) : t n * f = f * t n :=\n  (commute_t n f).Eq\n#align laurent_polynomial.T_mul LaurentPolynomial.t_mul\n\n/-- `trunc : R[T;T\u207b\u00b9] \u2192+ R[X]` maps a Laurent polynomial `f` to the polynomial whose terms of\nnonnegative degree coincide with the ones of `f`.  The terms of negative degree of `f` \"vanish\".\n`trunc` is a left-inverse to `polynomial.to_laurent`. -/\ndef trunc : R[T;T\u207b\u00b9] \u2192+ R[X] :=\n  (toFinsuppIso R).symm.toAddMonoidHom.comp <| comapDomain.addMonoidHom fun a b => Int.ofNat.inj\n#align laurent_polynomial.trunc LaurentPolynomial.trunc\n\n@[simp]\ntheorem trunc_c_mul_t (n : \u2124) (r : R) : trunc (c r * t n) = ite (0 \u2264 n) (monomial n.toNat r) 0 :=\n  by\n  apply (to_finsupp_iso R).Injective\n  rw [\u2190 single_eq_C_mul_T, Trunc, AddMonoidHom.coe_comp, Function.comp_apply,\n    comap_domain.add_monoid_hom_apply, to_finsupp_iso_apply]\n  by_cases n0 : 0 \u2264 n\n  \u00b7 lift n to \u2115 using n0\n    erw [comap_domain_single, to_finsupp_iso_symm_apply]\n    simp only [Int.coe_nat_nonneg, Int.toNat_coe_nat, if_true, to_finsupp_iso_apply,\n      to_finsupp_monomial]\n  \u00b7 lift -n to \u2115 using (neg_pos.mpr (not_le.mp n0)).le with m\n    rw [to_finsupp_iso_apply, to_finsupp_inj, if_neg n0]\n    erw [to_finsupp_iso_symm_apply]\n    ext a\n    have := ((not_le.mp n0).trans_le (Int.ofNat_zero_le a)).ne'\n    simp only [coeff, comap_domain_apply, Int.ofNat_eq_coe, coeff_zero, single_apply_eq_zero, this,\n      IsEmpty.forall_iff]\n#align laurent_polynomial.trunc_C_mul_T LaurentPolynomial.trunc_c_mul_t\n\n@[simp]\ntheorem leftInverse_trunc_toLaurent :\n    Function.LeftInverse (trunc : R[T;T\u207b\u00b9] \u2192 R[X]) Polynomial.toLaurent :=\n  by\n  refine' fun f => f.inductionOn' _ _\n  \u00b7 exact fun f g hf hg => by simp only [hf, hg, _root_.map_add]\n  \u00b7\n    exact fun n r => by\n      simp only [Polynomial.toLaurent_c_mul_t, trunc_C_mul_T, Int.coe_nat_nonneg, Int.toNat_coe_nat,\n        if_true]\n#align laurent_polynomial.left_inverse_trunc_to_laurent LaurentPolynomial.leftInverse_trunc_toLaurent\n\n@[simp]\ntheorem Polynomial.trunc_toLaurent (f : R[X]) : trunc f.toLaurent = f :=\n  leftInverse_trunc_toLaurent _\n#align polynomial.trunc_to_laurent Polynomial.trunc_toLaurent\n\ntheorem Polynomial.toLaurent_injective :\n    Function.Injective (Polynomial.toLaurent : R[X] \u2192 R[T;T\u207b\u00b9]) :=\n  leftInverse_trunc_toLaurent.Injective\n#align polynomial.to_laurent_injective Polynomial.toLaurent_injective\n\n@[simp]\ntheorem Polynomial.toLaurent_inj (f g : R[X]) : f.toLaurent = g.toLaurent \u2194 f = g :=\n  \u27e8fun h => Polynomial.toLaurent_injective h, congr_arg _\u27e9\n#align polynomial.to_laurent_inj Polynomial.toLaurent_inj\n\ntheorem Polynomial.toLaurent_ne_zero {f : R[X]} : f \u2260 0 \u2194 f.toLaurent \u2260 0 :=\n  (map_ne_zero_iff _ Polynomial.toLaurent_injective).symm\n#align polynomial.to_laurent_ne_zero Polynomial.toLaurent_ne_zero\n\ntheorem exists_t_pow (f : R[T;T\u207b\u00b9]) : \u2203 (n : \u2115)(f' : R[X]), f'.toLaurent = f * t n :=\n  by\n  apply f.induction_on' _ fun n a => _ <;> clear f\n  \u00b7 rintro f g \u27e8m, fn, hf\u27e9 \u27e8n, gn, hg\u27e9\n    refine' \u27e8m + n, fn * X ^ n + gn * X ^ m, _\u27e9\n    simp only [hf, hg, add_mul, add_comm (n : \u2124), map_add, map_mul, Polynomial.toLaurent_x_pow,\n      mul_T_assoc, Int.ofNat_add]\n  \u00b7 cases' n with n n\n    \u00b7 exact \u27e80, Polynomial.C a * X ^ n, by simp\u27e9\n    \u00b7 refine' \u27e8n + 1, Polynomial.C a, _\u27e9\n      simp only [Int.negSucc_eq, Polynomial.toLaurent_c, Int.ofNat_succ, mul_T_assoc, add_left_neg,\n        T_zero, mul_one]\n#align laurent_polynomial.exists_T_pow LaurentPolynomial.exists_t_pow\n\n/-- This is a version of `exists_T_pow` stated as an induction principle. -/\n@[elab_as_elim]\ntheorem induction_on_mul_t {Q : R[T;T\u207b\u00b9] \u2192 Prop} (f : R[T;T\u207b\u00b9])\n    (Qf : \u2200 {f : R[X]} {n : \u2115}, Q (f.toLaurent * t (-n))) : Q f :=\n  by\n  rcases f.exists_T_pow with \u27e8n, f', hf\u27e9\n  rw [\u2190 mul_one f, \u2190 T_zero, \u2190 Nat.cast_zero, \u2190 Nat.sub_self n, Nat.cast_sub rfl.le, T_sub, \u2190\n    mul_assoc, \u2190 hf]\n  exact Qf\n#align laurent_polynomial.induction_on_mul_T LaurentPolynomial.induction_on_mul_t\n\n/-- Suppose that `Q` is a statement about Laurent polynomials such that\n* `Q` is true on *ordinary* polynomials;\n* `Q (f * T)` implies `Q f`;\nit follow that `Q` is true on all Laurent polynomials. -/\ntheorem reduce_to_polynomial_of_mul_t (f : R[T;T\u207b\u00b9]) {Q : R[T;T\u207b\u00b9] \u2192 Prop}\n    (Qf : \u2200 f : R[X], Q f.toLaurent) (QT : \u2200 f, Q (f * t 1) \u2192 Q f) : Q f :=\n  by\n  induction' f using LaurentPolynomial.induction_on_mul_t with f n\n  induction' n with n hn\n  \u00b7 simpa only [Int.ofNat_zero, neg_zero, T_zero, mul_one] using Qf _\n  \u00b7 convert QT _ _\n    simpa using hn\n#align laurent_polynomial.reduce_to_polynomial_of_mul_T LaurentPolynomial.reduce_to_polynomial_of_mul_t\n\nsection Support\n\ntheorem support_c_mul_t (a : R) (n : \u2124) : (c a * t n).support \u2286 {n} := by\n  simpa only [\u2190 single_eq_C_mul_T] using support_single_subset\n#align laurent_polynomial.support_C_mul_T LaurentPolynomial.support_c_mul_t\n\ntheorem support_c_mul_t_of_ne_zero {a : R} (a0 : a \u2260 0) (n : \u2124) : (c a * t n).support = {n} :=\n  by\n  rw [\u2190 single_eq_C_mul_T]\n  exact support_single_ne_zero _ a0\n#align laurent_polynomial.support_C_mul_T_of_ne_zero LaurentPolynomial.support_c_mul_t_of_ne_zero\n\n/-- The support of a polynomial `f` is a finset in `\u2115`.  The lemma `to_laurent_support f`\nshows that the support of `f.to_laurent` is the same finset, but viewed in `\u2124` under the natural\ninclusion `\u2115 \u21aa \u2124`. -/\ntheorem toLaurent_support (f : R[X]) : f.toLaurent.support = f.support.map Nat.castEmbedding :=\n  by\n  generalize hd : f.support = s\n  revert f\n  refine' Finset.induction_on s _ _ <;> clear s\n  \u00b7\n    simp (config := { contextual := true }) only [Polynomial.support_eq_empty, map_zero,\n      Finsupp.support_zero, eq_self_iff_true, imp_true_iff, Finset.map_empty]\n  \u00b7 intro a s as hf f fs\n    have : (erase a f).toLaurent.support = s.map Nat.castEmbedding :=\n      hf (f.erase a)\n        (by\n          simp only [fs, Finset.erase_eq_of_not_mem as, Polynomial.support_erase,\n            Finset.erase_insert_eq_erase])\n    rw [\u2190 monomial_add_erase f a, Finset.map_insert, \u2190 this, map_add, Polynomial.toLaurent_c_mul_t,\n      support_add_eq, Finset.insert_eq]\n    \u00b7 congr\n      exact support_C_mul_T_of_ne_zero (polynomial.mem_support_iff.mp (by simp [fs])) _\n    \u00b7 rw [this]\n      exact Disjoint.mono_left (support_C_mul_T _ _) (by simpa)\n#align laurent_polynomial.to_laurent_support LaurentPolynomial.toLaurent_support\n\nend Support\n\nsection Degrees\n\n/-- The degree of a Laurent polynomial takes values in `with_bot \u2124`.\nIf `f : R[T;T\u207b\u00b9]` is a Laurent polynomial, then `f.degree` is the maximum of its support of `f`,\nor `\u22a5`, if `f = 0`. -/\ndef degree (f : R[T;T\u207b\u00b9]) : WithBot \u2124 :=\n  f.support.max\n#align laurent_polynomial.degree LaurentPolynomial.degree\n\n@[simp]\ntheorem degree_zero : degree (0 : R[T;T\u207b\u00b9]) = \u22a5 :=\n  rfl\n#align laurent_polynomial.degree_zero LaurentPolynomial.degree_zero\n\n@[simp]\ntheorem degree_eq_bot_iff {f : R[T;T\u207b\u00b9]} : f.degree = \u22a5 \u2194 f = 0 :=\n  by\n  refine' \u27e8fun h => _, fun h => by rw [h, degree_zero]\u27e9\n  rw [degree, Finset.max_eq_sup_withBot] at h\n  ext n\n  refine' not_not.mp fun f0 => _\n  simp_rw [Finset.sup_eq_bot_iff, Finsupp.mem_support_iff, Ne.def, WithBot.coe_ne_bot] at h\n  exact h n f0\n#align laurent_polynomial.degree_eq_bot_iff LaurentPolynomial.degree_eq_bot_iff\n\nsection ExactDegrees\n\nopen Classical\n\n@[simp]\ntheorem degree_c_mul_t (n : \u2124) (a : R) (a0 : a \u2260 0) : (c a * t n).degree = n :=\n  by\n  rw [degree]\n  convert Finset.max_singleton\n  refine' support_eq_singleton.mpr _\n  simp only [\u2190 single_eq_C_mul_T, single_eq_same, a0, Ne.def, not_false_iff, eq_self_iff_true,\n    and_self_iff]\n#align laurent_polynomial.degree_C_mul_T LaurentPolynomial.degree_c_mul_t\n\ntheorem degree_c_mul_t_ite (n : \u2124) (a : R) : (c a * t n).degree = ite (a = 0) \u22a5 n := by\n  split_ifs with h h <;>\n    simp only [h, map_zero, MulZeroClass.zero_mul, degree_zero, degree_C_mul_T, Ne.def,\n      not_false_iff]\n#align laurent_polynomial.degree_C_mul_T_ite LaurentPolynomial.degree_c_mul_t_ite\n\n@[simp]\ntheorem degree_t [Nontrivial R] (n : \u2124) : (t n : R[T;T\u207b\u00b9]).degree = n :=\n  by\n  rw [\u2190 one_mul (T n), \u2190 map_one C]\n  exact degree_C_mul_T n 1 (one_ne_zero : (1 : R) \u2260 0)\n#align laurent_polynomial.degree_T LaurentPolynomial.degree_t\n\ntheorem degree_c {a : R} (a0 : a \u2260 0) : (c a).degree = 0 :=\n  by\n  rw [\u2190 mul_one (C a), \u2190 T_zero]\n  exact degree_C_mul_T 0 a a0\n#align laurent_polynomial.degree_C LaurentPolynomial.degree_c\n\ntheorem degree_c_ite (a : R) : (c a).degree = ite (a = 0) \u22a5 0 := by\n  split_ifs with h h <;> simp only [h, map_zero, degree_zero, degree_C, Ne.def, not_false_iff]\n#align laurent_polynomial.degree_C_ite LaurentPolynomial.degree_c_ite\n\nend ExactDegrees\n\nsection DegreeBounds\n\ntheorem degree_c_mul_t_le (n : \u2124) (a : R) : (c a * t n).degree \u2264 n :=\n  by\n  by_cases a0 : a = 0\n  \u00b7 simp only [a0, map_zero, MulZeroClass.zero_mul, degree_zero, bot_le]\n  \u00b7 exact (degree_C_mul_T n a a0).le\n#align laurent_polynomial.degree_C_mul_T_le LaurentPolynomial.degree_c_mul_t_le\n\ntheorem degree_t_le (n : \u2124) : (t n : R[T;T\u207b\u00b9]).degree \u2264 n :=\n  (le_of_eq (by rw [map_one, one_mul])).trans (degree_c_mul_t_le n (1 : R))\n#align laurent_polynomial.degree_T_le LaurentPolynomial.degree_t_le\n\ntheorem degree_c_le (a : R) : (c a).degree \u2264 0 :=\n  (le_of_eq (by rw [T_zero, mul_one])).trans (degree_c_mul_t_le 0 a)\n#align laurent_polynomial.degree_C_le LaurentPolynomial.degree_c_le\n\nend DegreeBounds\n\nend Degrees\n\ninstance : Module R[X] R[T;T\u207b\u00b9] :=\n  Module.compHom _ Polynomial.toLaurent\n\ninstance (R : Type _) [Semiring R] : IsScalarTower R[X] R[X] R[T;T\u207b\u00b9]\n    where smul_assoc x y z := by simp only [SMul.smul, SMul.comp.smul, map_mul, mul_assoc]\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ninstance algebraPolynomial (R : Type _) [CommSemiring R] : Algebra R[X] R[T;T\u207b\u00b9] :=\n  { Polynomial.toLaurent with\n    commutes' := fun f l => by simp [mul_comm]\n    smul_def' := fun f l => rfl }\n#align laurent_polynomial.algebra_polynomial LaurentPolynomial.algebraPolynomial\n\ntheorem algebraMap_x_pow (n : \u2115) : algebraMap R[X] R[T;T\u207b\u00b9] (X ^ n) = t n :=\n  Polynomial.toLaurent_x_pow n\n#align laurent_polynomial.algebra_map_X_pow LaurentPolynomial.algebraMap_x_pow\n\n@[simp]\ntheorem algebraMap_eq_toLaurent (f : R[X]) : algebraMap R[X] R[T;T\u207b\u00b9] f = f.toLaurent :=\n  rfl\n#align laurent_polynomial.algebra_map_eq_to_laurent LaurentPolynomial.algebraMap_eq_toLaurent\n\ntheorem isLocalization : IsLocalization (Submonoid.closure ({X} : Set R[X])) R[T;T\u207b\u00b9] :=\n  { map_units := fun t => by\n      cases' t with t ht\n      rcases submonoid.mem_closure_singleton.mp ht with \u27e8n, rfl\u27e9\n      simp only [is_unit_T n, [anonymous], algebra_map_eq_to_laurent, Polynomial.toLaurent_x_pow]\n    surj := fun f =>\n      by\n      induction' f using LaurentPolynomial.induction_on_mul_t with f n\n      have := (Submonoid.closure ({X} : Set R[X])).pow_mem Submonoid.mem_closure_singleton_self n\n      refine' \u27e8(f, \u27e8_, this\u27e9), _\u27e9\n      simp only [[anonymous], algebra_map_eq_to_laurent, Polynomial.toLaurent_x_pow, mul_T_assoc,\n        add_left_neg, T_zero, mul_one]\n    eq_iff_exists := fun f g =>\n      by\n      rw [algebra_map_eq_to_laurent, algebra_map_eq_to_laurent, Polynomial.toLaurent_inj]\n      refine' \u27e8_, _\u27e9\n      \u00b7 rintro rfl\n        exact \u27e81, rfl\u27e9\n      \u00b7 rintro \u27e8\u27e8h, hX\u27e9, h\u27e9\n        rcases submonoid.mem_closure_singleton.mp hX with \u27e8n, rfl\u27e9\n        exact mul_X_pow_injective n h }\n#align laurent_polynomial.is_localization LaurentPolynomial.isLocalization\n\nend CommSemiring\n\nend LaurentPolynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Polynomial/Laurent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.7905303186696748, "lm_q1q2_score": 0.7305621257921613}}
{"text": "import tactic\n\nnamespace vilnius\n\n\n/- ### implication -/\n\nexample (P Q : Prop) : P \u2192 Q \u2192 P :=\nbegin\n  intro hP,\n  intro h,\n  exact hP,\nend\n\n/- ### not -/\n\nexample (P Q : Prop) : (P \u2192 \u00ac Q) \u2192 (Q \u2192 \u00ac P) :=\nbegin\n  intros h1 h2 h3,\n  apply h1,\n  exact h3,\n  exact h2,\nend\n\n\n/- ### and -/\n\nexample (P Q : Prop) : P \u2227 Q \u2192 Q :=\nbegin\n  intro h,\n  cases h,\n  exact h_right,\nend\n\nexample (P Q : Prop) : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  intros h1 h2,\n  split,\n  exact h1,\n  exact h2,\nend\n\n\nexample (P Q : Prop) : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  intro h,\n  split,\n  cases h,\n  exact h_right,\n  cases h,\n  exact h_left,\nend\n\n\nexample (P : Prop) : P \u2227 \u00ac P \u2192 false :=\nbegin\n  intro h,\n  cases h,\n  apply h_right,\n  exact h_left,\nend\n\n\n/- ## Or -/\n\n\nexample (P Q : Prop) : \u00ac P \u2228 Q \u2192 P \u2192 Q :=\nbegin\n  intros h1 h2,\n  cases h1,\n  by_contradiction,\n  apply h1,\n  exact h2,\n  exact h1,\nend\n\n\nexample (P Q R : Prop) : P \u2228 (Q \u2227 R) \u2192 \u00ac P \u2192 \u00ac Q \u2192 false :=\nbegin\n  intros h1 h2 h3,\n  cases h1,\n  apply h2,\n  exact h1,\n  cases h1,\n  apply h3,\n  exact h1_left,\nend\n\n\nend vilnius\n\n", "meta": {"author": "faenuccio", "repo": "May22_Vilnius", "sha": "2ff937dc7568e6118473b1e7f479ccb2a5fa9767", "save_path": "github-repos/lean/faenuccio-May22_Vilnius", "path": "github-repos/lean/faenuccio-May22_Vilnius/May22_Vilnius-2ff937dc7568e6118473b1e7f479ccb2a5fa9767/src/A_Logic/fae_solutions/Exercices.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7305621224889245}}
{"text": "import Math.Data.Function\nimport Math.Order.Basic\n\nopen Order\n\nnamespace SetTheory\n\n/-- The type of sets of terms of type `\u03b1`. -/\ndef Set (\u03b1 : Type u) := \u03b1 \u2192 Prop\n\nclass Inter (\u03b1 : Type u) where\n  inter : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n\ninfixr:80 \" \u2229 \" => Inter.inter\n\nclass Union (\u03b1 : Type u) where\n  union : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n\ninfixr:60 \" \u222a \" => Union.union\n\nclass Subset (\u03b1 : Type u) where\n  subset : \u03b1 \u2192 \u03b1 \u2192 Prop\n\ninfixl:51 \" \u2286 \" => Subset.subset\n\ninstance (\u03b1 : Type u) : Membership \u03b1 (Set \u03b1) where\n  mem x A := A x\n\nnamespace Set\n\n/-- The empty set. -/\ndef empty (\u03b1 : Type u) : Set \u03b1 := \u03bb _ => False\n\n/-- The set containing all  -/\ndef univ (\u03b1 : Type u) : Set \u03b1 := \u03bb _ => True\n\n/-- The set containing only `x`. -/\ndef singleton (x : \u03b1) := \u03bb y => y = x\n\n/-- The complement of `A`. -/\ndef compl (A : Set \u03b1) : Set \u03b1 := \u03bb x => \u00ac A x\n\n/-- The intersection of `A` and `B`. -/\ndef inter (A B : Set \u03b1) : Set \u03b1 := \u03bb x => A x \u2227 B x\n\n/-- The union of `A` and `B`. -/\ndef union (A B : Set \u03b1) : Set \u03b1 := \u03bb x => A x \u2228 B x\n\n/-- The difference of `A` and `B`. -/\ndef diff (A B : Set \u03b1) : Set \u03b1 := \u03bb x => A x \u2228 \u00ac B x\n\n/-- The proposition `A \u2286 B`. -/\ndef subset (A B : Set \u03b1) := \u2200 {x}, A x \u2192 B x\n\n/-- The powerset of `A`. -/\ndef powerset (A : Set \u03b1) : Set (Set \u03b1) := \u03bb B => A.subset B\n\n/-- The union of a set of sets. -/\ndef set_union (A : Set (Set \u03b1)) : Set \u03b1 := \u03bb x => \u2203 B, B \u2208 A \u2227 x \u2208 B\n\ninstance : Inter (Set \u03b1) where inter := inter\ninstance : Union (Set \u03b1) where union := union\ninstance : Compl (Set \u03b1) where compl := compl\ninstance (\u03b1 : Type u) : EmptyCollection (Set \u03b1) where emptyCollection := empty \u03b1\ninstance : Subset (Set \u03b1) where subset := subset\n\ntheorem ext {A B : Set \u03b1} (h : \u2200 x, x \u2208 A \u2194 x \u2208 B) : A = B :=\n  funext (\u03bb x => propext (h x))\n\n@[simp]\ntheorem compl_union (A B : Set \u03b1) : (A \u222a B)\u1d9c = A\u1d9c \u2229 B\u1d9c := by {\n  apply ext;\n  intro x;\n  constructor;\n  exact \u03bb hx => \u27e8\u03bb ha => hx (Or.inl ha), \u03bb hb => hx (Or.inr hb)\u27e9;\n  intro hx hab;\n  cases hab with\n  | inl hab => apply hx.1 hab;\n  | inr hab => apply hx.2 hab;\n}\n\n@[simp]\ntheorem compl_inter (A B : Set \u03b1) : (A \u2229 B)\u1d9c = A\u1d9c \u222a B\u1d9c := by {\n  apply ext;\n  intro x;\n  constructor;\n  intro hx;\n  by_cases A x;\n  exact Or.inr $ \u03bb bx => hx \u27e8by assumption, bx\u27e9;\n  exact Or.inl $ by assumption;\n  intro hx hab;\n  cases hx with\n  | inl hx => exact hx hab.1;\n  | inr hx => exact hx hab.2;\n}\n\n@[simp]\ntheorem compl_univ : (univ \u03b1)\u1d9c = \u2205 := by {\n  apply ext;\n  intro x;\n  constructor;\n  intro h;\n  apply h;\n  trivial;\n  intro h;\n  intro _;\n  exact h;\n}\n\n@[simp]\ntheorem compl_empty : \u2205\u1d9c = univ \u03b1 := by {\n  apply Set.ext;\n  intro x;\n  constructor;\n  intro _;\n  trivial;\n  intro _;\n  exact id;\n}\n\ntheorem cantor (f : \u03b1 \u2192 Set \u03b1) : \u00ac Function.surjective f := by {\n  intro hf;\n  let S : Set \u03b1 := \u03bb x => x \u2209 f x;\n  cases hf S with\n  | intro x hx => {\n    by_cases h : x \u2208 f x;\n    -- Case x \u2208 f x\n    have q := h;\n    rw [hx] at q;\n    exact q h;\n    -- Case x \u2209 f x\n    have q := h;\n    rw [hx] at h;\n    exact h q;\n  }\n}\n\ndef subset_self (A : Set \u03b1) : A \u2286 A := id\n\ndef subset_asymm {A B : Set \u03b1} : A \u2286 B \u2192 B \u2286 A \u2192 A = B := \u03bb h\u2081 h\u2082 => ext (\u03bb _ => \u27e8h\u2081, h\u2082\u27e9)\n\ndef subset_trans {A B C : Set \u03b1} : A \u2286 B \u2192 B \u2286 C \u2192 A \u2286 C := \u03bb h\u2081 h\u2082 => \u03bb hx => h\u2082 (h\u2081 hx)\n\ndef subset_union_left (A B : Set \u03b1) : A \u2286 A \u222a B := Or.inl\n\ndef subset_union_right (A B : Set \u03b1) : B \u2286 A \u222a B := Or.inr\n\ndef union_subset {A B C : Set \u03b1} : A \u2286 C \u2192 B \u2286 C \u2192 A \u222a B \u2286 C := \u03bb h\u2081 h\u2082 x hx => by {\n  cases hx;\n  apply h\u2081; assumption;\n  apply h\u2082; assumption;\n}\n\ndef inter_subset_left (A B : Set \u03b1) : A \u2229 B \u2286 A := And.left\n\ndef inter_subset_right (A B : Set \u03b1) : A \u2229 B \u2286 B := And.right\n\ndef subset_inter {A B C : Set \u03b1} : A \u2286 B \u2192 A \u2286 C \u2192 A \u2286 B \u2229 C := \u03bb h\u2081 h\u2082 _ hx => \u27e8h\u2081 hx, h\u2082 hx\u27e9\n\nend Set\n\nend SetTheory\n", "meta": {"author": "jessetvogel", "repo": "Math4", "sha": "1d6a30589c7b3b3c70e968985d0c1f6f9f242938", "save_path": "github-repos/lean/jessetvogel-Math4", "path": "github-repos/lean/jessetvogel-Math4/Math4-1d6a30589c7b3b3c70e968985d0c1f6f9f242938/Math/SetTheory/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7305566315969244}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n-/\nimport data.list.erase_dup\nimport data.list.lattice\nimport data.list.permutation\nimport data.list.zip\nimport logic.relation\n\n/-!\n# List Permutations\n\nThis file introduces the `list.perm` relation, which is true if two lists are permutations of one\nanother.\n\n## Notation\n\nThe notation `~` is used for permutation equivalence.\n-/\n\nopen_locale nat\n\nuniverses uu vv\n\nnamespace list\nvariables {\u03b1 : Type uu} {\u03b2 : Type vv}\n\n/-- `perm l\u2081 l\u2082` or `l\u2081 ~ l\u2082` asserts that `l\u2081` and `l\u2082` are permutations\n  of each other. This is defined by induction using pairwise swaps. -/\ninductive perm : list \u03b1 \u2192 list \u03b1 \u2192 Prop\n| nil   : perm [] []\n| cons  : \u03a0 (x : \u03b1) {l\u2081 l\u2082 : list \u03b1}, perm l\u2081 l\u2082 \u2192 perm (x::l\u2081) (x::l\u2082)\n| swap  : \u03a0 (x y : \u03b1) (l : list \u03b1), perm (y::x::l) (x::y::l)\n| trans : \u03a0 {l\u2081 l\u2082 l\u2083 : list \u03b1}, perm l\u2081 l\u2082 \u2192 perm l\u2082 l\u2083 \u2192 perm l\u2081 l\u2083\n\nopen perm (swap)\n\ninfix ` ~ `:50 := perm\n\n@[refl] protected theorem perm.refl : \u2200 (l : list \u03b1), l ~ l\n| []      := perm.nil\n| (x::xs) := (perm.refl xs).cons x\n\n@[symm] protected theorem perm.symm {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2082 ~ l\u2081 :=\nperm.rec_on p\n  perm.nil\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, r\u2081.cons x)\n  (\u03bb x y l, swap y x l)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, r\u2082.trans r\u2081)\n\ntheorem perm_comm {l\u2081 l\u2082 : list \u03b1} : l\u2081 ~ l\u2082 \u2194 l\u2082 ~ l\u2081 := \u27e8perm.symm, perm.symm\u27e9\n\ntheorem perm.swap'\n  (x y : \u03b1) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : y::x::l\u2081 ~ x::y::l\u2082 :=\n(swap _ _ _).trans ((p.cons _).cons _)\n\nattribute [trans] perm.trans\n\ntheorem perm.eqv (\u03b1) : equivalence (@perm \u03b1) :=\nmk_equivalence (@perm \u03b1) (@perm.refl \u03b1) (@perm.symm \u03b1) (@perm.trans \u03b1)\n\ninstance is_setoid (\u03b1) : setoid (list \u03b1) :=\nsetoid.mk (@perm \u03b1) (perm.eqv \u03b1)\n\ntheorem perm.subset {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 \u2286 l\u2082 :=\n\u03bb a, perm.rec_on p\n  (\u03bb h, h)\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081 i, or.elim i\n    (\u03bb ax, by simp [ax])\n    (\u03bb al\u2081, or.inr (r\u2081 al\u2081)))\n  (\u03bb x y l ayxl, or.elim ayxl\n    (\u03bb ay, by simp [ay])\n    (\u03bb axl, or.elim axl\n      (\u03bb ax, by simp [ax])\n      (\u03bb al, or.inr (or.inr al))))\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082 ainl\u2081, r\u2082 (r\u2081 ainl\u2081))\n\ntheorem perm.mem_iff {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} (h : l\u2081 ~ l\u2082) : a \u2208 l\u2081 \u2194 a \u2208 l\u2082 :=\niff.intro (\u03bb m, h.subset m) (\u03bb m, h.symm.subset m)\n\ntheorem perm.append_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b1) (p : l\u2081 ~ l\u2082) : l\u2081++t\u2081 ~ l\u2082++t\u2081 :=\nperm.rec_on p\n  (perm.refl ([] ++ t\u2081))\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, r\u2081.cons x)\n  (\u03bb x y l, swap x y _)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, r\u2081.trans r\u2082)\n\ntheorem perm.append_left {t\u2081 t\u2082 : list \u03b1} : \u2200 (l : list \u03b1), t\u2081 ~ t\u2082 \u2192 l++t\u2081 ~ l++t\u2082\n| []      p := p\n| (x::xs) p := (perm.append_left xs p).cons x\n\ntheorem perm.append {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081++t\u2081 ~ l\u2082++t\u2082 :=\n(p\u2081.append_right t\u2081).trans (p\u2082.append_left l\u2082)\n\ntheorem perm.append_cons (a : \u03b1) {h\u2081 h\u2082 t\u2081 t\u2082 : list \u03b1}\n  (p\u2081 : h\u2081 ~ h\u2082) (p\u2082 : t\u2081 ~ t\u2082) : h\u2081 ++ a::t\u2081 ~ h\u2082 ++ a::t\u2082 :=\np\u2081.append (p\u2082.cons a)\n\n@[simp] theorem perm_middle {a : \u03b1} : \u2200 {l\u2081 l\u2082 : list \u03b1}, l\u2081++a::l\u2082 ~ a::(l\u2081++l\u2082)\n| []      l\u2082 := perm.refl _\n| (b::l\u2081) l\u2082 := ((@perm_middle l\u2081 l\u2082).cons _).trans (swap a b _)\n\n@[simp] theorem perm_append_singleton (a : \u03b1) (l : list \u03b1) : l ++ [a] ~ a::l :=\nperm_middle.trans $ by rw [append_nil]\n\ntheorem perm_append_comm : \u2200 {l\u2081 l\u2082 : list \u03b1}, (l\u2081++l\u2082) ~ (l\u2082++l\u2081)\n| []     l\u2082 := by simp\n| (a::t) l\u2082 := (perm_append_comm.cons _).trans perm_middle.symm\n\ntheorem concat_perm (l : list \u03b1) (a : \u03b1) : concat l a ~ a :: l :=\nby simp\n\ntheorem perm.length_eq {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : length l\u2081 = length l\u2082 :=\nperm.rec_on p\n  rfl\n  (\u03bb x l\u2081 l\u2082 p r, by simp[r])\n  (\u03bb x y l, by simp)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, eq.trans r\u2081 r\u2082)\n\ntheorem perm.eq_nil {l : list \u03b1} (p : l ~ []) : l = [] :=\neq_nil_of_length_eq_zero p.length_eq\n\ntheorem perm.nil_eq {l : list \u03b1} (p : [] ~ l) : [] = l :=\np.symm.eq_nil.symm\n\n@[simp]\ntheorem perm_nil {l\u2081 : list \u03b1} : l\u2081 ~ [] \u2194 l\u2081 = [] :=\n\u27e8\u03bb p, p.eq_nil, \u03bb e, e \u25b8 perm.refl _\u27e9\n\n@[simp]\ntheorem nil_perm {l\u2081 : list \u03b1} : [] ~ l\u2081 \u2194 l\u2081 = [] :=\nperm_comm.trans perm_nil\n\ntheorem not_perm_nil_cons (x : \u03b1) (l : list \u03b1) : \u00ac [] ~ x::l\n| p := by injection p.symm.eq_nil\n\n@[simp] theorem reverse_perm : \u2200 (l : list \u03b1), reverse l ~ l\n| []     := perm.nil\n| (a::l) := by { rw reverse_cons,\n  exact (perm_append_singleton _ _).trans ((reverse_perm l).cons a) }\n\ntheorem perm_cons_append_cons {l l\u2081 l\u2082 : list \u03b1} (a : \u03b1) (p : l ~ l\u2081++l\u2082) :\n  a::l ~ l\u2081++(a::l\u2082) :=\n(p.cons a).trans perm_middle.symm\n\n@[simp] theorem perm_repeat {a : \u03b1} {n : \u2115} {l : list \u03b1} : l ~ repeat a n \u2194 l = repeat a n :=\n\u27e8\u03bb p, (eq_repeat.2\n  \u27e8p.length_eq.trans $ length_repeat _ _,\n   \u03bb b m, eq_of_mem_repeat $ p.subset m\u27e9),\n \u03bb h, h \u25b8 perm.refl _\u27e9\n\n@[simp] theorem repeat_perm {a : \u03b1} {n : \u2115} {l : list \u03b1} : repeat a n ~ l \u2194 repeat a n = l :=\n(perm_comm.trans perm_repeat).trans eq_comm\n\n@[simp] theorem perm_singleton {a : \u03b1} {l : list \u03b1} : l ~ [a] \u2194 l = [a] :=\n@perm_repeat \u03b1 a 1 l\n\n@[simp] theorem singleton_perm {a : \u03b1} {l : list \u03b1} : [a] ~ l \u2194 [a] = l :=\n@repeat_perm \u03b1 a 1 l\n\ntheorem perm.eq_singleton {a : \u03b1} {l : list \u03b1} (p : l ~ [a]) : l = [a] :=\nperm_singleton.1 p\n\ntheorem perm.singleton_eq {a : \u03b1} {l : list \u03b1} (p : [a] ~ l) : [a] = l :=\np.symm.eq_singleton.symm\n\ntheorem singleton_perm_singleton {a b : \u03b1} : [a] ~ [b] \u2194 a = b :=\nby simp\n\ntheorem perm_cons_erase [decidable_eq \u03b1] {a : \u03b1} {l : list \u03b1} (h : a \u2208 l) :\n  l ~ a :: l.erase a :=\nlet \u27e8l\u2081, l\u2082, _, e\u2081, e\u2082\u27e9 := exists_erase_eq h in\ne\u2082.symm \u25b8 e\u2081.symm \u25b8 perm_middle\n\n@[elab_as_eliminator] theorem perm_induction_on\n    {P : list \u03b1 \u2192 list \u03b1 \u2192 Prop} {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082)\n    (h\u2081 : P [] [])\n    (h\u2082 : \u2200 x l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 P l\u2081 l\u2082 \u2192 P (x::l\u2081) (x::l\u2082))\n    (h\u2083 : \u2200 x y l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 P l\u2081 l\u2082 \u2192 P (y::x::l\u2081) (x::y::l\u2082))\n    (h\u2084 : \u2200 l\u2081 l\u2082 l\u2083, l\u2081 ~ l\u2082 \u2192 l\u2082 ~ l\u2083 \u2192 P l\u2081 l\u2082 \u2192 P l\u2082 l\u2083 \u2192 P l\u2081 l\u2083) :\n  P l\u2081 l\u2082 :=\nhave P_refl : \u2200 l, P l l, from\n  assume l,\n  list.rec_on l h\u2081 (\u03bb x xs ih, h\u2082 x xs xs (perm.refl xs) ih),\nperm.rec_on p h\u2081 h\u2082 (\u03bb x y l, h\u2083 x y l l (perm.refl l) (P_refl l)) h\u2084\n\n@[congr] theorem perm.filter_map (f : \u03b1 \u2192 option \u03b2) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  filter_map f l\u2081 ~ filter_map f l\u2082 :=\nbegin\n  induction p with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082,\n  { simp },\n  { simp only [filter_map], cases f x with a; simp [filter_map, IH, perm.cons] },\n  { simp only [filter_map], cases f x with a; cases f y with b; simp [filter_map, swap] },\n  { exact IH\u2081.trans IH\u2082 }\nend\n\n@[congr] theorem perm.map (f : \u03b1 \u2192 \u03b2) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  map f l\u2081 ~ map f l\u2082 :=\nfilter_map_eq_map f \u25b8 p.filter_map _\n\ntheorem perm.pmap {p : \u03b1 \u2192 Prop} (f : \u03a0 a, p a \u2192 \u03b2)\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) {H\u2081 H\u2082} : pmap f l\u2081 H\u2081 ~ pmap f l\u2082 H\u2082 :=\nbegin\n  induction p with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082,\n  { simp },\n  { simp [IH, perm.cons] },\n  { simp [swap] },\n  { refine IH\u2081.trans IH\u2082,\n    exact \u03bb a m, H\u2082 a (p\u2082.subset m) }\nend\n\ntheorem perm.filter (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  {l\u2081 l\u2082 : list \u03b1} (s : l\u2081 ~ l\u2082) : filter p l\u2081 ~ filter p l\u2082 :=\nby rw \u2190 filter_map_eq_filter; apply s.filter_map _\n\ntheorem exists_perm_sublist {l\u2081 l\u2082 l\u2082' : list \u03b1}\n  (s : l\u2081 <+ l\u2082) (p : l\u2082 ~ l\u2082') : \u2203 l\u2081' ~ l\u2081, l\u2081' <+ l\u2082' :=\nbegin\n  induction p with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082 generalizing l\u2081 s,\n  { exact \u27e8[], eq_nil_of_sublist_nil s \u25b8 perm.refl _, nil_sublist _\u27e9 },\n  { cases s with _ _ _ s l\u2081 _ _ s,\n    { exact let \u27e8l\u2081', p', s'\u27e9 := IH s in \u27e8l\u2081', p', s'.cons _ _ _\u27e9 },\n    { exact let \u27e8l\u2081', p', s'\u27e9 := IH s in \u27e8x::l\u2081', p'.cons x, s'.cons2 _ _ _\u27e9 } },\n  { cases s with _ _ _ s l\u2081 _ _ s; cases s with _ _ _ s l\u2081 _ _ s,\n    { exact \u27e8l\u2081, perm.refl _, (s.cons _ _ _).cons _ _ _\u27e9 },\n    { exact \u27e8x::l\u2081, perm.refl _, (s.cons _ _ _).cons2 _ _ _\u27e9 },\n    { exact \u27e8y::l\u2081, perm.refl _, (s.cons2 _ _ _).cons _ _ _\u27e9 },\n    { exact \u27e8x::y::l\u2081, perm.swap _ _ _, (s.cons2 _ _ _).cons2 _ _ _\u27e9 } },\n  { exact let \u27e8m\u2081, pm, sm\u27e9 := IH\u2081 s, \u27e8r\u2081, pr, sr\u27e9 := IH\u2082 sm in\n          \u27e8r\u2081, pr.trans pm, sr\u27e9 }\nend\n\ntheorem perm.sizeof_eq_sizeof [has_sizeof \u03b1] {l\u2081 l\u2082 : list \u03b1} (h : l\u2081 ~ l\u2082) :\n  l\u2081.sizeof = l\u2082.sizeof :=\nbegin\n  induction h with hd l\u2081 l\u2082 h\u2081\u2082 h_sz\u2081\u2082 a b l l\u2081 l\u2082 l\u2083 h\u2081\u2082 h\u2082\u2083 h_sz\u2081\u2082 h_sz\u2082\u2083,\n  { refl },\n  { simp only [list.sizeof, h_sz\u2081\u2082] },\n  { simp only [list.sizeof, add_left_comm] },\n  { simp only [h_sz\u2081\u2082, h_sz\u2082\u2083] }\nend\n\n\nsection rel\nopen relator\nvariables {\u03b3 : Type*} {\u03b4 : Type*} {r : \u03b1 \u2192 \u03b2 \u2192 Prop} {p : \u03b3 \u2192 \u03b4 \u2192 Prop}\n\nlocal infixr ` \u2218r ` : 80 := relation.comp\n\nlemma perm_comp_perm : (perm \u2218r perm : list \u03b1 \u2192 list \u03b1 \u2192 Prop) = perm :=\nbegin\n  funext a c, apply propext,\n  split,\n  { exact assume \u27e8b, hab, hba\u27e9, perm.trans hab hba },\n  { exact assume h, \u27e8a, perm.refl a, h\u27e9 }\nend\n\nlemma perm_comp_forall\u2082 {l u v} (hlu : perm l u) (huv : forall\u2082 r u v) : (forall\u2082 r \u2218r perm) l v :=\nbegin\n  induction hlu generalizing v,\n  case perm.nil { cases huv, exact \u27e8[], forall\u2082.nil, perm.nil\u27e9 },\n  case perm.cons : a l u hlu ih\n  { cases huv with _ b _ v hab huv',\n    rcases ih huv' with \u27e8l\u2082, h\u2081\u2082, h\u2082\u2083\u27e9,\n    exact \u27e8b::l\u2082, forall\u2082.cons hab h\u2081\u2082, h\u2082\u2083.cons _\u27e9 },\n  case perm.swap : a\u2081 a\u2082 l\u2081 l\u2082 h\u2082\u2083\n  { cases h\u2082\u2083 with _ b\u2081 _ l\u2082 h\u2081 hr_\u2082\u2083,\n    cases hr_\u2082\u2083 with _ b\u2082 _ l\u2082 h\u2082 h\u2081\u2082,\n    exact \u27e8b\u2082::b\u2081::l\u2082, forall\u2082.cons h\u2082 (forall\u2082.cons h\u2081 h\u2081\u2082), perm.swap _ _ _\u27e9 },\n  case perm.trans : la\u2081 la\u2082 la\u2083 _ _ ih\u2081 ih\u2082\n  { rcases ih\u2082 huv with \u27e8lb\u2082, hab\u2082, h\u2082\u2083\u27e9,\n    rcases ih\u2081 hab\u2082 with \u27e8lb\u2081, hab\u2081, h\u2081\u2082\u27e9,\n    exact \u27e8lb\u2081, hab\u2081, perm.trans h\u2081\u2082 h\u2082\u2083\u27e9 }\nend\n\nlemma forall\u2082_comp_perm_eq_perm_comp_forall\u2082 : forall\u2082 r \u2218r perm = perm \u2218r forall\u2082 r :=\nbegin\n  funext l\u2081 l\u2083, apply propext,\n  split,\n  { assume h, rcases h with \u27e8l\u2082, h\u2081\u2082, h\u2082\u2083\u27e9,\n    have : forall\u2082 (flip r) l\u2082 l\u2081, from h\u2081\u2082.flip ,\n    rcases perm_comp_forall\u2082 h\u2082\u2083.symm this with \u27e8l', h\u2081, h\u2082\u27e9,\n    exact \u27e8l', h\u2082.symm, h\u2081.flip\u27e9 },\n  { exact assume \u27e8l\u2082, h\u2081\u2082, h\u2082\u2083\u27e9, perm_comp_forall\u2082 h\u2081\u2082 h\u2082\u2083 }\nend\n\nlemma rel_perm_imp (hr : right_unique r) : (forall\u2082 r \u21d2 forall\u2082 r \u21d2 implies) perm perm :=\nassume a b h\u2081 c d h\u2082 h,\nhave (flip (forall\u2082 r) \u2218r (perm \u2218r forall\u2082 r)) b d, from \u27e8a, h\u2081, c, h, h\u2082\u27e9,\nhave ((flip (forall\u2082 r) \u2218r forall\u2082 r) \u2218r perm) b d,\n  by rwa [\u2190 forall\u2082_comp_perm_eq_perm_comp_forall\u2082, \u2190 relation.comp_assoc] at this,\nlet \u27e8b', \u27e8c', hbc, hcb\u27e9, hbd\u27e9 := this in\nhave b' = b, from right_unique_forall\u2082' hr hcb hbc,\nthis \u25b8 hbd\n\nlemma rel_perm (hr : bi_unique r) : (forall\u2082 r \u21d2 forall\u2082 r \u21d2 (\u2194)) perm perm :=\nassume a b hab c d hcd, iff.intro\n  (rel_perm_imp hr.2 hab hcd)\n  (rel_perm_imp hr.left.flip hab.flip hcd.flip)\n\nend rel\n\nsection subperm\n\n/-- `subperm l\u2081 l\u2082`, denoted `l\u2081 <+~ l\u2082`, means that `l\u2081` is a sublist of\n  a permutation of `l\u2082`. This is an analogue of `l\u2081 \u2286 l\u2082` which respects\n  multiplicities of elements, and is used for the `\u2264` relation on multisets. -/\ndef subperm (l\u2081 l\u2082 : list \u03b1) : Prop := \u2203 l ~ l\u2081, l <+ l\u2082\n\ninfix ` <+~ `:50 := subperm\n\ntheorem nil_subperm {l : list \u03b1} : [] <+~ l :=\n\u27e8[], perm.nil, by simp\u27e9\n\ntheorem perm.subperm_left {l l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l <+~ l\u2081 \u2194 l <+~ l\u2082 :=\nsuffices \u2200 {l\u2081 l\u2082 : list \u03b1}, l\u2081 ~ l\u2082 \u2192 l <+~ l\u2081 \u2192 l <+~ l\u2082,\nfrom \u27e8this p, this p.symm\u27e9,\n\u03bb l\u2081 l\u2082 p \u27e8u, pu, su\u27e9,\n  let \u27e8v, pv, sv\u27e9 := exists_perm_sublist su p in\n  \u27e8v, pv.trans pu, sv\u27e9\n\ntheorem perm.subperm_right {l\u2081 l\u2082 l : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 <+~ l \u2194 l\u2082 <+~ l :=\n\u27e8\u03bb \u27e8u, pu, su\u27e9, \u27e8u, pu.trans p, su\u27e9,\n \u03bb \u27e8u, pu, su\u27e9, \u27e8u, pu.trans p.symm, su\u27e9\u27e9\n\ntheorem sublist.subperm {l\u2081 l\u2082 : list \u03b1} (s : l\u2081 <+ l\u2082) : l\u2081 <+~ l\u2082 :=\n\u27e8l\u2081, perm.refl _, s\u27e9\n\ntheorem perm.subperm {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 <+~ l\u2082 :=\n\u27e8l\u2082, p.symm, sublist.refl _\u27e9\n\n@[refl] theorem subperm.refl (l : list \u03b1) : l <+~ l := (perm.refl _).subperm\n\n@[trans] theorem subperm.trans {l\u2081 l\u2082 l\u2083 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2082 <+~ l\u2083 \u2192 l\u2081 <+~ l\u2083\n| s \u27e8l\u2082', p\u2082, s\u2082\u27e9 :=\n  let \u27e8l\u2081', p\u2081, s\u2081\u27e9 := p\u2082.subperm_left.2 s in \u27e8l\u2081', p\u2081, s\u2081.trans s\u2082\u27e9\n\ntheorem subperm.length_le {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 length l\u2081 \u2264 length l\u2082\n| \u27e8l, p, s\u27e9 := p.length_eq \u25b8 length_le_of_sublist s\n\ntheorem subperm.perm_of_length_le {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 length l\u2082 \u2264 length l\u2081 \u2192 l\u2081 ~ l\u2082\n| \u27e8l, p, s\u27e9 h :=\n  suffices l = l\u2082, from this \u25b8 p.symm,\n  eq_of_sublist_of_length_le s $ p.symm.length_eq \u25b8 h\n\ntheorem subperm.antisymm {l\u2081 l\u2082 : list \u03b1} (h\u2081 : l\u2081 <+~ l\u2082) (h\u2082 : l\u2082 <+~ l\u2081) : l\u2081 ~ l\u2082 :=\nh\u2081.perm_of_length_le h\u2082.length_le\n\ntheorem subperm.subset {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2081 \u2286 l\u2082\n| \u27e8l, p, s\u27e9 := subset.trans p.symm.subset s.subset\n\nlemma subperm.filter (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  \u2983l l' : list \u03b1\u2984 (h : l <+~ l') : filter p l <+~ filter p l' :=\nbegin\n  obtain \u27e8xs, hp, h\u27e9 := h,\n  exact \u27e8_, hp.filter p, h.filter p\u27e9\nend\n\nend subperm\n\ntheorem sublist.exists_perm_append : \u2200 {l\u2081 l\u2082 : list \u03b1}, l\u2081 <+ l\u2082 \u2192 \u2203 l, l\u2082 ~ l\u2081 ++ l\n| ._ ._ sublist.slnil            := \u27e8nil, perm.refl _\u27e9\n| ._ ._ (sublist.cons l\u2081 l\u2082 a s) :=\n  let \u27e8l, p\u27e9 := sublist.exists_perm_append s in\n  \u27e8a::l, (p.cons a).trans perm_middle.symm\u27e9\n| ._ ._ (sublist.cons2 l\u2081 l\u2082 a s) :=\n  let \u27e8l, p\u27e9 := sublist.exists_perm_append s in\n  \u27e8l, p.cons a\u27e9\n\ntheorem perm.countp_eq (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  {l\u2081 l\u2082 : list \u03b1} (s : l\u2081 ~ l\u2082) : countp p l\u2081 = countp p l\u2082 :=\nby rw [countp_eq_length_filter, countp_eq_length_filter];\n   exact (s.filter _).length_eq\n\ntheorem subperm.countp_le (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  {l\u2081 l\u2082 : list \u03b1} : l\u2081 <+~ l\u2082 \u2192 countp p l\u2081 \u2264 countp p l\u2082\n| \u27e8l, p', s\u27e9 := p'.countp_eq p \u25b8 s.countp_le p\n\ntheorem perm.count_eq [decidable_eq \u03b1] {l\u2081 l\u2082 : list \u03b1}\n  (p : l\u2081 ~ l\u2082) (a) : count a l\u2081 = count a l\u2082 :=\np.countp_eq _\n\ntheorem subperm.count_le [decidable_eq \u03b1] {l\u2081 l\u2082 : list \u03b1}\n  (s : l\u2081 <+~ l\u2082) (a) : count a l\u2081 \u2264 count a l\u2082 :=\ns.countp_le _\n\ntheorem perm.foldl_eq' {f : \u03b2 \u2192 \u03b1 \u2192 \u03b2} {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  (\u2200 (x \u2208 l\u2081) (y \u2208 l\u2081) z, f (f z x) y = f (f z y) x) \u2192 \u2200 b, foldl f b l\u2081 = foldl f b l\u2082 :=\nperm_induction_on p\n  (\u03bb H b, rfl)\n  (\u03bb x t\u2081 t\u2082 p r H b, r (\u03bb x hx y hy, H _ (or.inr hx) _ (or.inr hy)) _)\n  (\u03bb x y t\u2081 t\u2082 p r H b,\n    begin\n      simp only [foldl],\n      rw [H x (or.inr $ or.inl rfl) y (or.inl rfl)],\n      exact r (\u03bb x hx y hy, H _ (or.inr $ or.inr hx) _ (or.inr $ or.inr hy)) _\n    end)\n  (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 r\u2081 r\u2082 H b, eq.trans (r\u2081 H b)\n    (r\u2082 (\u03bb x hx y hy, H _ (p\u2081.symm.subset hx) _ (p\u2081.symm.subset hy)) b))\n\ntheorem perm.foldl_eq {f : \u03b2 \u2192 \u03b1 \u2192 \u03b2} {l\u2081 l\u2082 : list \u03b1} (rcomm : right_commutative f) (p : l\u2081 ~ l\u2082) :\n  \u2200 b, foldl f b l\u2081 = foldl f b l\u2082 :=\np.foldl_eq' $ \u03bb x hx y hy z, rcomm z x y\n\ntheorem perm.foldr_eq {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} {l\u2081 l\u2082 : list \u03b1} (lcomm : left_commutative f) (p : l\u2081 ~ l\u2082) :\n  \u2200 b, foldr f b l\u2081 = foldr f b l\u2082 :=\nperm_induction_on p\n  (\u03bb b, rfl)\n  (\u03bb x t\u2081 t\u2082 p r b, by simp; rw [r b])\n  (\u03bb x y t\u2081 t\u2082 p r b, by simp; rw [lcomm, r b])\n  (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 r\u2081 r\u2082 a, eq.trans (r\u2081 a) (r\u2082 a))\n\nlemma perm.rec_heq {\u03b2 : list \u03b1 \u2192 Sort*} {f : \u03a0a l, \u03b2 l \u2192 \u03b2 (a::l)} {b : \u03b2 []} {l l' : list \u03b1}\n  (hl : perm l l')\n  (f_congr : \u2200{a l l' b b'}, perm l l' \u2192 b == b' \u2192 f a l b == f a l' b')\n  (f_swap : \u2200{a a' l b}, f a (a'::l) (f a' l b) == f a' (a::l) (f a l b)) :\n  @list.rec \u03b1 \u03b2 b f l == @list.rec \u03b1 \u03b2 b f l' :=\nbegin\n  induction hl,\n  case list.perm.nil { refl },\n  case list.perm.cons : a l l' h ih { exact f_congr h ih },\n  case list.perm.swap : a a' l { exact f_swap },\n  case list.perm.trans : l\u2081 l\u2082 l\u2083 h\u2081 h\u2082 ih\u2081 ih\u2082 { exact heq.trans ih\u2081 ih\u2082 }\nend\n\nsection\nvariables {op : \u03b1 \u2192 \u03b1 \u2192 \u03b1} [is_associative \u03b1 op] [is_commutative \u03b1 op]\nlocal notation a * b := op a b\nlocal notation l <*> a := foldl op a l\n\nlemma perm.fold_op_eq {l\u2081 l\u2082 : list \u03b1} {a : \u03b1} (h : l\u2081 ~ l\u2082) : l\u2081 <*> a = l\u2082 <*> a :=\nh.foldl_eq (right_comm _ is_commutative.comm is_associative.assoc) _\nend\n\nsection comm_monoid\n\n/-- If elements of a list commute with each other, then their product does not\ndepend on the order of elements-/\n@[to_additive]\n\n\nvariable [comm_monoid \u03b1]\n\n@[to_additive]\nlemma perm.prod_eq {l\u2081 l\u2082 : list \u03b1} (h : perm l\u2081 l\u2082) : prod l\u2081 = prod l\u2082 :=\nh.fold_op_eq\n\n@[to_additive]\nlemma prod_reverse (l : list \u03b1) : prod l.reverse = prod l :=\n(reverse_perm l).prod_eq\n\nend comm_monoid\n\ntheorem perm_inv_core {a : \u03b1} {l\u2081 l\u2082 r\u2081 r\u2082 : list \u03b1} : l\u2081++a::r\u2081 ~ l\u2082++a::r\u2082 \u2192 l\u2081++r\u2081 ~ l\u2082++r\u2082 :=\nbegin\n  generalize e\u2081 : l\u2081++a::r\u2081 = s\u2081, generalize e\u2082 : l\u2082++a::r\u2082 = s\u2082,\n  intro p, revert l\u2081 l\u2082 r\u2081 r\u2082 e\u2081 e\u2082,\n  refine perm_induction_on p _ (\u03bb x t\u2081 t\u2082 p IH, _) (\u03bb x y t\u2081 t\u2082 p IH, _)\n    (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, _); intros l\u2081 l\u2082 r\u2081 r\u2082 e\u2081 e\u2082,\n  { apply (not_mem_nil a).elim, rw \u2190 e\u2081, simp },\n  { cases l\u2081 with y l\u2081; cases l\u2082 with z l\u2082;\n      dsimp at e\u2081 e\u2082; injections; subst x,\n    { substs t\u2081 t\u2082,     exact p },\n    { substs z t\u2081 t\u2082,   exact p.trans perm_middle },\n    { substs y t\u2081 t\u2082,   exact perm_middle.symm.trans p },\n    { substs z t\u2081 t\u2082,   exact (IH rfl rfl).cons y } },\n  { rcases l\u2081 with _|\u27e8y, _|\u27e8z, l\u2081\u27e9\u27e9; rcases l\u2082 with _|\u27e8u, _|\u27e8v, l\u2082\u27e9\u27e9;\n      dsimp at e\u2081 e\u2082; injections; substs x y,\n    { substs r\u2081 r\u2082,     exact p.cons a },\n    { substs r\u2081 r\u2082,     exact p.cons u },\n    { substs r\u2081 v t\u2082,   exact (p.trans perm_middle).cons u },\n    { substs r\u2081 r\u2082,     exact p.cons y },\n    { substs r\u2081 r\u2082 y u, exact p.cons a },\n    { substs r\u2081 u v t\u2082, exact ((p.trans perm_middle).cons y).trans (swap _ _ _) },\n    { substs r\u2082 z t\u2081,   exact (perm_middle.symm.trans p).cons y },\n    { substs r\u2082 y z t\u2081, exact (swap _ _ _).trans ((perm_middle.symm.trans p).cons u) },\n    { substs u v t\u2081 t\u2082, exact (IH rfl rfl).swap' _ _ } },\n  { substs t\u2081 t\u2083,\n    have : a \u2208 t\u2082 := p\u2081.subset (by simp),\n    rcases mem_split this with \u27e8l\u2082, r\u2082, e\u2082\u27e9,\n    subst t\u2082, exact (IH\u2081 rfl rfl).trans (IH\u2082 rfl rfl) }\nend\n\ntheorem perm.cons_inv {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 ~ a::l\u2082 \u2192 l\u2081 ~ l\u2082 :=\n@perm_inv_core _ _ [] [] _ _\n\n@[simp] theorem perm_cons (a : \u03b1) {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 ~ a::l\u2082 \u2194 l\u2081 ~ l\u2082 :=\n\u27e8perm.cons_inv, perm.cons a\u27e9\n\ntheorem perm_append_left_iff {l\u2081 l\u2082 : list \u03b1} : \u2200 l, l++l\u2081 ~ l++l\u2082 \u2194 l\u2081 ~ l\u2082\n| []     := iff.rfl\n| (a::l) := (perm_cons a).trans (perm_append_left_iff l)\n\ntheorem perm_append_right_iff {l\u2081 l\u2082 : list \u03b1} (l) : l\u2081++l ~ l\u2082++l \u2194 l\u2081 ~ l\u2082 :=\n\u27e8\u03bb p, (perm_append_left_iff _).1 $ perm_append_comm.trans $ p.trans perm_append_comm,\n perm.append_right _\u27e9\n\ntheorem perm_option_to_list {o\u2081 o\u2082 : option \u03b1} : o\u2081.to_list ~ o\u2082.to_list \u2194 o\u2081 = o\u2082 :=\nbegin\n  refine \u27e8\u03bb p, _, \u03bb e, e \u25b8 perm.refl _\u27e9,\n  cases o\u2081 with a; cases o\u2082 with b, {refl},\n  { cases p.length_eq },\n  { cases p.length_eq },\n  { exact option.mem_to_list.1 (p.symm.subset $ by simp) }\nend\n\ntheorem subperm_cons (a : \u03b1) {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 <+~ a::l\u2082 \u2194 l\u2081 <+~ l\u2082 :=\n\u27e8\u03bb \u27e8l, p, s\u27e9, begin\n  cases s with _ _ _ s' u _ _ s',\n  { exact (p.subperm_left.2 $ (sublist_cons _ _).subperm).trans s'.subperm },\n  { exact \u27e8u, p.cons_inv, s'\u27e9 }\nend, \u03bb \u27e8l, p, s\u27e9, \u27e8a::l, p.cons a, s.cons2 _ _ _\u27e9\u27e9\n\ntheorem cons_subperm_of_mem {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} (d\u2081 : nodup l\u2081) (h\u2081 : a \u2209 l\u2081) (h\u2082 : a \u2208 l\u2082)\n (s : l\u2081 <+~ l\u2082) : a :: l\u2081 <+~ l\u2082 :=\nbegin\n  rcases s with \u27e8l, p, s\u27e9,\n  induction s generalizing l\u2081,\n  case list.sublist.slnil { cases h\u2082 },\n  case list.sublist.cons : r\u2081 r\u2082 b s' ih\n  { simp at h\u2082,\n    cases h\u2082 with e m,\n    { subst b, exact \u27e8a::r\u2081, p.cons a, s'.cons2 _ _ _\u27e9 },\n    { rcases ih m d\u2081 h\u2081 p with \u27e8t, p', s'\u27e9, exact \u27e8t, p', s'.cons _ _ _\u27e9 } },\n  case list.sublist.cons2 : r\u2081 r\u2082 b s' ih\n  { have bm : b \u2208 l\u2081 := (p.subset $ mem_cons_self _ _),\n    have am : a \u2208 r\u2082 := h\u2082.resolve_left (\u03bb e, h\u2081 $ e.symm \u25b8 bm),\n    rcases mem_split bm with \u27e8t\u2081, t\u2082, rfl\u27e9,\n    have st : t\u2081 ++ t\u2082 <+ t\u2081 ++ b :: t\u2082 := by simp,\n    rcases ih am (nodup_of_sublist st d\u2081)\n      (mt (\u03bb x, st.subset x) h\u2081)\n      (perm.cons_inv $ p.trans perm_middle) with \u27e8t, p', s'\u27e9,\n    exact \u27e8b::t, (p'.cons b).trans $ (swap _ _ _).trans (perm_middle.symm.cons a), s'.cons2 _ _ _\u27e9 }\nend\n\ntheorem subperm_append_left {l\u2081 l\u2082 : list \u03b1} : \u2200 l, l++l\u2081 <+~ l++l\u2082 \u2194 l\u2081 <+~ l\u2082\n| []     := iff.rfl\n| (a::l) := (subperm_cons a).trans (subperm_append_left l)\n\ntheorem subperm_append_right {l\u2081 l\u2082 : list \u03b1} (l) : l\u2081++l <+~ l\u2082++l \u2194 l\u2081 <+~ l\u2082 :=\n(perm_append_comm.subperm_left.trans perm_append_comm.subperm_right).trans (subperm_append_left l)\n\ntheorem subperm.exists_of_length_lt {l\u2081 l\u2082 : list \u03b1} :\n  l\u2081 <+~ l\u2082 \u2192 length l\u2081 < length l\u2082 \u2192 \u2203 a, a :: l\u2081 <+~ l\u2082\n| \u27e8l, p, s\u27e9 h :=\n  suffices length l < length l\u2082 \u2192 \u2203 (a : \u03b1), a :: l <+~ l\u2082, from\n  (this $ p.symm.length_eq \u25b8 h).imp (\u03bb a, (p.cons a).subperm_right.1),\n  begin\n    clear subperm.exists_of_length_lt p h l\u2081, rename l\u2082 u,\n    induction s with l\u2081 l\u2082 a s IH _ _ b s IH; intro h,\n    { cases h },\n    { cases lt_or_eq_of_le (nat.le_of_lt_succ h : length l\u2081 \u2264 length l\u2082) with h h,\n      { exact (IH h).imp (\u03bb a s, s.trans (sublist_cons _ _).subperm) },\n      { exact \u27e8a, eq_of_sublist_of_length_eq s h \u25b8 subperm.refl _\u27e9 } },\n    { exact (IH $ nat.lt_of_succ_lt_succ h).imp\n        (\u03bb a s, (swap _ _ _).subperm_right.1 $ (subperm_cons _).2 s) }\n  end\n\ntheorem subperm_of_subset_nodup\n  {l\u2081 l\u2082 : list \u03b1} (d : nodup l\u2081) (H : l\u2081 \u2286 l\u2082) : l\u2081 <+~ l\u2082 :=\nbegin\n  induction d with a l\u2081' h d IH,\n  { exact \u27e8nil, perm.nil, nil_sublist _\u27e9 },\n  { cases forall_mem_cons.1 H with H\u2081 H\u2082,\n    simp at h,\n    exact cons_subperm_of_mem d h H\u2081 (IH H\u2082) }\nend\n\ntheorem perm_ext {l\u2081 l\u2082 : list \u03b1} (d\u2081 : nodup l\u2081) (d\u2082 : nodup l\u2082) :\n  l\u2081 ~ l\u2082 \u2194 \u2200a, a \u2208 l\u2081 \u2194 a \u2208 l\u2082 :=\n\u27e8\u03bb p a, p.mem_iff, \u03bb H, subperm.antisymm\n  (subperm_of_subset_nodup d\u2081 (\u03bb a, (H a).1))\n  (subperm_of_subset_nodup d\u2082 (\u03bb a, (H a).2))\u27e9\n\ntheorem nodup.sublist_ext {l\u2081 l\u2082 l : list \u03b1} (d : nodup l)\n  (s\u2081 : l\u2081 <+ l) (s\u2082 : l\u2082 <+ l) : l\u2081 ~ l\u2082 \u2194 l\u2081 = l\u2082 :=\n\u27e8\u03bb h, begin\n  induction s\u2082 with l\u2082 l a s\u2082 IH l\u2082 l a s\u2082 IH generalizing l\u2081,\n  { exact h.eq_nil },\n  { simp at d,\n    cases s\u2081 with _ _ _ s\u2081 l\u2081 _ _ s\u2081,\n    { exact IH d.2 s\u2081 h },\n    { apply d.1.elim,\n      exact subperm.subset \u27e8_, h.symm, s\u2082\u27e9 (mem_cons_self _ _) } },\n  { simp at d,\n    cases s\u2081 with _ _ _ s\u2081 l\u2081 _ _ s\u2081,\n    { apply d.1.elim,\n      exact subperm.subset \u27e8_, h, s\u2081\u27e9 (mem_cons_self _ _) },\n    { rw IH d.2 s\u2081 h.cons_inv } }\nend, \u03bb h, by rw h\u27e9\n\nsection\nvariable [decidable_eq \u03b1]\n\n-- attribute [congr]\ntheorem perm.erase (a : \u03b1) {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  l\u2081.erase a ~ l\u2082.erase a :=\nif h\u2081 : a \u2208 l\u2081 then\nhave h\u2082 : a \u2208 l\u2082, from p.subset h\u2081,\nperm.cons_inv $ (perm_cons_erase h\u2081).symm.trans $ p.trans (perm_cons_erase h\u2082)\nelse\nhave h\u2082 : a \u2209 l\u2082, from mt p.mem_iff.2 h\u2081,\nby rw [erase_of_not_mem h\u2081, erase_of_not_mem h\u2082]; exact p\n\ntheorem subperm_cons_erase (a : \u03b1) (l : list \u03b1) : l <+~ a :: l.erase a :=\nbegin\n  by_cases h : a \u2208 l,\n  { exact (perm_cons_erase h).subperm },\n  { rw [erase_of_not_mem h],\n    exact (sublist_cons _ _).subperm }\nend\n\ntheorem erase_subperm (a : \u03b1) (l : list \u03b1) : l.erase a <+~ l :=\n(erase_sublist _ _).subperm\n\ntheorem subperm.erase {l\u2081 l\u2082 : list \u03b1} (a : \u03b1) (h : l\u2081 <+~ l\u2082) : l\u2081.erase a <+~ l\u2082.erase a :=\nlet \u27e8l, hp, hs\u27e9 := h in \u27e8l.erase a, hp.erase _, hs.erase _\u27e9\n\ntheorem perm.diff_right {l\u2081 l\u2082 : list \u03b1} (t : list \u03b1) (h : l\u2081 ~ l\u2082) : l\u2081.diff t ~ l\u2082.diff t :=\nby induction t generalizing l\u2081 l\u2082 h; simp [*, perm.erase]\n\ntheorem perm.diff_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (h : t\u2081 ~ t\u2082) : l.diff t\u2081 = l.diff t\u2082 :=\nby induction h generalizing l; simp [*, perm.erase, erase_comm]\n  <|> exact (ih_1 _).trans (ih_2 _)\n\ntheorem perm.diff {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (hl : l\u2081 ~ l\u2082) (ht : t\u2081 ~ t\u2082) :\n  l\u2081.diff t\u2081 ~ l\u2082.diff t\u2082 :=\nht.diff_left l\u2082 \u25b8 hl.diff_right _\n\ntheorem subperm.diff_right {l\u2081 l\u2082 : list \u03b1} (h : l\u2081 <+~ l\u2082) (t : list \u03b1) :\n  l\u2081.diff t <+~ l\u2082.diff t :=\nby induction t generalizing l\u2081 l\u2082 h; simp [*, subperm.erase]\n\ntheorem erase_cons_subperm_cons_erase (a b : \u03b1) (l : list \u03b1) :\n  (a :: l).erase b <+~ a :: l.erase b :=\nbegin\n  by_cases h : a = b,\n  { subst b,\n    rw [erase_cons_head],\n    apply subperm_cons_erase },\n  { rw [erase_cons_tail _ h] }\nend\n\ntheorem subperm_cons_diff {a : \u03b1} : \u2200 {l\u2081 l\u2082 : list \u03b1}, (a :: l\u2081).diff l\u2082 <+~ a :: l\u2081.diff l\u2082\n| l\u2081 []      := \u27e8a::l\u2081, by simp\u27e9\n| l\u2081 (b::l\u2082) :=\nbegin\n  simp only [diff_cons],\n  refine ((erase_cons_subperm_cons_erase a b l\u2081).diff_right l\u2082).trans _,\n  apply subperm_cons_diff\nend\n\ntheorem subset_cons_diff {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} : (a :: l\u2081).diff l\u2082 \u2286 a :: l\u2081.diff l\u2082 :=\nsubperm_cons_diff.subset\n\ntheorem perm.bag_inter_right {l\u2081 l\u2082 : list \u03b1} (t : list \u03b1) (h : l\u2081 ~ l\u2082) :\n  l\u2081.bag_inter t ~ l\u2082.bag_inter t :=\nbegin\n  induction h with x _ _ _ _ x y _ _ _ _ _ _ ih_1 ih_2 generalizing t, {simp},\n  { by_cases x \u2208 t; simp [*, perm.cons] },\n  { by_cases x = y, {simp [h]},\n    by_cases xt : x \u2208 t; by_cases yt : y \u2208 t,\n    { simp [xt, yt, mem_erase_of_ne h, mem_erase_of_ne (ne.symm h), erase_comm, swap] },\n    { simp [xt, yt, mt mem_of_mem_erase, perm.cons] },\n    { simp [xt, yt, mt mem_of_mem_erase, perm.cons] },\n    { simp [xt, yt] } },\n  { exact (ih_1 _).trans (ih_2 _) }\nend\n\ntheorem perm.bag_inter_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (p : t\u2081 ~ t\u2082) :\n  l.bag_inter t\u2081 = l.bag_inter t\u2082 :=\nbegin\n  induction l with a l IH generalizing t\u2081 t\u2082 p, {simp},\n  by_cases a \u2208 t\u2081,\n  { simp [h, p.subset h, IH (p.erase _)] },\n  { simp [h, mt p.mem_iff.2 h, IH p] }\nend\n\ntheorem perm.bag_inter {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (hl : l\u2081 ~ l\u2082) (ht : t\u2081 ~ t\u2082) :\n  l\u2081.bag_inter t\u2081 ~ l\u2082.bag_inter t\u2082 :=\nht.bag_inter_left l\u2082 \u25b8 hl.bag_inter_right _\n\ntheorem cons_perm_iff_perm_erase {a : \u03b1} {l\u2081 l\u2082 : list \u03b1} : a::l\u2081 ~ l\u2082 \u2194 a \u2208 l\u2082 \u2227 l\u2081 ~ l\u2082.erase a :=\n\u27e8\u03bb h, have a \u2208 l\u2082, from h.subset (mem_cons_self a l\u2081),\n      \u27e8this, (h.trans $ perm_cons_erase this).cons_inv\u27e9,\n \u03bb \u27e8m, h\u27e9, (h.cons a).trans (perm_cons_erase m).symm\u27e9\n\ntheorem perm_iff_count {l\u2081 l\u2082 : list \u03b1} : l\u2081 ~ l\u2082 \u2194 \u2200 a, count a l\u2081 = count a l\u2082 :=\n\u27e8perm.count_eq, \u03bb H, begin\n  induction l\u2081 with a l\u2081 IH generalizing l\u2082,\n  { cases l\u2082 with b l\u2082, {refl},\n    specialize H b, simp at H, contradiction },\n  { have : a \u2208 l\u2082 := count_pos.1 (by rw \u2190 H; simp; apply nat.succ_pos),\n    refine ((IH $ \u03bb b, _).cons a).trans (perm_cons_erase this).symm,\n    specialize H b,\n    rw (perm_cons_erase this).count_eq at H,\n    by_cases b = a; simp [h] at H \u22a2; assumption }\nend\u27e9\n\nlemma subperm.cons_right {\u03b1 : Type*} {l l' : list \u03b1} (x : \u03b1) (h : l <+~ l') : l <+~ x :: l' :=\nh.trans (sublist_cons x l').subperm\n\n/-- The list version of `add_tsub_cancel_of_le` for multisets. -/\nlemma subperm_append_diff_self_of_count_le {l\u2081 l\u2082 : list \u03b1}\n  (h : \u2200 x \u2208 l\u2081, count x l\u2081 \u2264 count x l\u2082) : l\u2081 ++ l\u2082.diff l\u2081 ~ l\u2082 :=\nbegin\n  induction l\u2081 with hd tl IH generalizing l\u2082,\n  { simp },\n  { have : hd \u2208 l\u2082,\n    { rw \u2190count_pos,\n      exact lt_of_lt_of_le (count_pos.mpr (mem_cons_self _ _)) (h hd (mem_cons_self _ _)) },\n    replace this : l\u2082 ~ hd :: l\u2082.erase hd := perm_cons_erase this,\n    refine perm.trans _ this.symm,\n    rw [cons_append, diff_cons, perm_cons],\n    refine IH (\u03bb x hx, _),\n    specialize h x (mem_cons_of_mem _ hx),\n    rw (perm_iff_count.mp this) at h,\n    by_cases hx : x = hd,\n    { subst hd,\n      simpa [nat.succ_le_succ_iff] using h },\n    { simpa [hx] using h } },\nend\n\n/-- The list version of `multiset.le_iff_count`. -/\nlemma subperm_ext_iff {l\u2081 l\u2082 : list \u03b1} :\n  l\u2081 <+~ l\u2082 \u2194 \u2200 x \u2208 l\u2081, count x l\u2081 \u2264 count x l\u2082 :=\nbegin\n  refine \u27e8\u03bb h x hx, subperm.count_le h x, \u03bb h, _\u27e9,\n  suffices : l\u2081 <+~ (l\u2082.diff l\u2081 ++ l\u2081),\n  { refine this.trans (perm.subperm _),\n    exact perm_append_comm.trans (subperm_append_diff_self_of_count_le h) },\n  convert (subperm_append_right _).mpr nil_subperm using 1\nend\n\nlemma subperm.cons_left {l\u2081 l\u2082 : list \u03b1} (h : l\u2081 <+~ l\u2082)\n  (x : \u03b1) (hx : count x l\u2081 < count x l\u2082) :\n  x :: l\u2081 <+~ l\u2082  :=\nbegin\n  rw subperm_ext_iff at h \u22a2,\n  intros y hy,\n  by_cases hy' : y = x,\n  { subst x,\n    simpa using nat.succ_le_of_lt hx },\n  { rw count_cons_of_ne hy',\n    refine h y _,\n    simpa [hy'] using hy }\nend\n\ninstance decidable_perm : \u2200 (l\u2081 l\u2082 : list \u03b1), decidable (l\u2081 ~ l\u2082)\n| []      []      := is_true $ perm.refl _\n| []      (b::l\u2082) := is_false $ \u03bb h, by have := h.nil_eq; contradiction\n| (a::l\u2081) l\u2082      := by haveI := decidable_perm l\u2081 (l\u2082.erase a);\n                        exact decidable_of_iff' _ cons_perm_iff_perm_erase\n\n-- @[congr]\ntheorem perm.erase_dup {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) :\n  erase_dup l\u2081 ~ erase_dup l\u2082 :=\nperm_iff_count.2 $ \u03bb a,\nif h : a \u2208 l\u2081\nthen by simp [nodup_erase_dup, h, p.subset h]\nelse by simp [h, mt p.mem_iff.2 h]\n\n-- attribute [congr]\ntheorem perm.insert (a : \u03b1)\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) : insert a l\u2081 ~ insert a l\u2082 :=\nif h : a \u2208 l\u2081\nthen by simpa [h, p.subset h] using p\nelse by simpa [h, mt p.mem_iff.2 h] using p.cons a\n\ntheorem perm_insert_swap (x y : \u03b1) (l : list \u03b1) :\n  insert x (insert y l) ~ insert y (insert x l) :=\nbegin\n  by_cases xl : x \u2208 l; by_cases yl : y \u2208 l; simp [xl, yl],\n  by_cases xy : x = y, { simp [xy] },\n  simp [not_mem_cons_of_ne_of_not_mem xy xl,\n        not_mem_cons_of_ne_of_not_mem (ne.symm xy) yl],\n  constructor\nend\n\ntheorem perm_insert_nth {\u03b1} (x : \u03b1) (l : list \u03b1) {n} (h : n \u2264 l.length) :\n  insert_nth n x l ~ x :: l :=\nbegin\n  induction l generalizing n,\n  { cases n, refl, cases h },\n  cases n,\n  { simp [insert_nth] },\n  { simp only [insert_nth, modify_nth_tail],\n    transitivity,\n    { apply perm.cons, apply l_ih,\n      apply nat.le_of_succ_le_succ h },\n    { apply perm.swap } }\nend\n\ntheorem perm.union_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b1) (h : l\u2081 ~ l\u2082) : l\u2081 \u222a t\u2081 ~ l\u2082 \u222a t\u2081 :=\nbegin\n  induction h with a _ _ _ ih _ _ _ _ _ _ _ _ ih_1 ih_2; try {simp},\n  { exact ih.insert a },\n  { apply perm_insert_swap },\n  { exact ih_1.trans ih_2 }\nend\n\ntheorem perm.union_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (h : t\u2081 ~ t\u2082) : l \u222a t\u2081 ~ l \u222a t\u2082 :=\nby induction l; simp [*, perm.insert]\n\n-- @[congr]\ntheorem perm.union {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081 \u222a t\u2081 ~ l\u2082 \u222a t\u2082 :=\n(p\u2081.union_right t\u2081).trans (p\u2082.union_left l\u2082)\n\ntheorem perm.inter_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b1) : l\u2081 ~ l\u2082 \u2192 l\u2081 \u2229 t\u2081 ~ l\u2082 \u2229 t\u2081 :=\nperm.filter _\n\ntheorem perm.inter_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b1} (p : t\u2081 ~ t\u2082) : l \u2229 t\u2081 = l \u2229 t\u2082 :=\nby { dsimp [(\u2229), list.inter], congr, funext a, rw [p.mem_iff] }\n\n-- @[congr]\ntheorem perm.inter {l\u2081 l\u2082 t\u2081 t\u2082 : list \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081 \u2229 t\u2081 ~ l\u2082 \u2229 t\u2082 :=\np\u2082.inter_left l\u2082 \u25b8 p\u2081.inter_right t\u2081\n\ntheorem perm.inter_append {l t\u2081 t\u2082 : list \u03b1} (h : disjoint t\u2081 t\u2082) :\n  l \u2229 (t\u2081 ++ t\u2082) ~ l \u2229 t\u2081 ++ l \u2229 t\u2082 :=\nbegin\n  induction l,\n  case list.nil\n  { simp },\n  case list.cons : x xs l_ih\n  { by_cases h\u2081 : x \u2208 t\u2081,\n    { have h\u2082 : x \u2209 t\u2082 := h h\u2081,\n      simp * },\n    by_cases h\u2082 : x \u2208 t\u2082,\n    { simp only [*, inter_cons_of_not_mem, false_or, mem_append, inter_cons_of_mem, not_false_iff],\n      transitivity,\n      { apply perm.cons _ l_ih, },\n      change [x] ++ xs \u2229 t\u2081 ++ xs \u2229 t\u2082 ~ xs \u2229 t\u2081 ++ ([x] ++ xs \u2229 t\u2082),\n      rw [\u2190 list.append_assoc],\n      solve_by_elim [perm.append_right, perm_append_comm] },\n    { simp * } },\nend\n\nend\n\ntheorem perm.pairwise_iff {R : \u03b1 \u2192 \u03b1 \u2192 Prop} (S : symmetric R) :\n  \u2200 {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082), pairwise R l\u2081 \u2194 pairwise R l\u2082 :=\nsuffices \u2200 {l\u2081 l\u2082}, l\u2081 ~ l\u2082 \u2192 pairwise R l\u2081 \u2192 pairwise R l\u2082, from \u03bb l\u2081 l\u2082 p, \u27e8this p, this p.symm\u27e9,\n\u03bb l\u2081 l\u2082 p d, begin\n  induction d with a l\u2081 h d IH generalizing l\u2082,\n  { rw \u2190 p.nil_eq, constructor },\n  { have : a \u2208 l\u2082 := p.subset (mem_cons_self _ _),\n    rcases mem_split this with \u27e8s\u2082, t\u2082, rfl\u27e9,\n    have p' := (p.trans perm_middle).cons_inv,\n    refine (pairwise_middle S).2 (pairwise_cons.2 \u27e8\u03bb b m, _, IH _ p'\u27e9),\n    exact h _ (p'.symm.subset m) }\nend\n\ntheorem perm.nodup_iff {l\u2081 l\u2082 : list \u03b1} : l\u2081 ~ l\u2082 \u2192 (nodup l\u2081 \u2194 nodup l\u2082) :=\nperm.pairwise_iff $ @ne.symm \u03b1\n\ntheorem perm.bind_right {l\u2081 l\u2082 : list \u03b1} (f : \u03b1 \u2192 list \u03b2) (p : l\u2081 ~ l\u2082) :\n  l\u2081.bind f ~ l\u2082.bind f :=\nbegin\n  induction p with a l\u2081 l\u2082 p IH a b l l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, {simp},\n  { simp, exact IH.append_left _ },\n  { simp, rw [\u2190 append_assoc, \u2190 append_assoc], exact perm_append_comm.append_right _ },\n  { exact IH\u2081.trans IH\u2082 }\nend\n\ntheorem perm.bind_left (l : list \u03b1) {f g : \u03b1 \u2192 list \u03b2} (h : \u2200 a, f a ~ g a) :\n  l.bind f ~ l.bind g :=\nby induction l with a l IH; simp; exact (h a).append IH\n\ntheorem bind_append_perm (l : list \u03b1) (f g : \u03b1 \u2192 list \u03b2) :\n  l.bind f ++ l.bind g ~ l.bind (\u03bb x, f x ++ g x) :=\nbegin\n  induction l with a l IH; simp,\n  refine (perm.trans _ (IH.append_left _)).append_left _,\n  rw [\u2190 append_assoc, \u2190 append_assoc],\n  exact perm_append_comm.append_right _\nend\n\ntheorem perm.product_right {l\u2081 l\u2082 : list \u03b1} (t\u2081 : list \u03b2) (p : l\u2081 ~ l\u2082) :\n  product l\u2081 t\u2081 ~ product l\u2082 t\u2081 :=\np.bind_right _\n\ntheorem perm.product_left (l : list \u03b1) {t\u2081 t\u2082 : list \u03b2} (p : t\u2081 ~ t\u2082) :\n  product l t\u2081 ~ product l t\u2082 :=\nperm.bind_left _ $ \u03bb a, p.map _\n\n@[congr] theorem perm.product {l\u2081 l\u2082 : list \u03b1} {t\u2081 t\u2082 : list \u03b2}\n  (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : product l\u2081 t\u2081 ~ product l\u2082 t\u2082 :=\n(p\u2081.product_right t\u2081).trans (p\u2082.product_left l\u2082)\n\ntheorem sublists_cons_perm_append (a : \u03b1) (l : list \u03b1) :\n  sublists (a :: l) ~ sublists l ++ map (cons a) (sublists l) :=\nbegin\n  simp only [sublists, sublists_aux_cons_cons, cons_append, perm_cons],\n  refine (perm.cons _ _).trans perm_middle.symm,\n  induction sublists_aux l cons with b l IH; simp,\n  exact (IH.cons _).trans perm_middle.symm\nend\n\ntheorem sublists_perm_sublists' : \u2200 l : list \u03b1, sublists l ~ sublists' l\n| []     := perm.refl _\n| (a::l) := let IH := sublists_perm_sublists' l in\n  by rw sublists'_cons; exact\n  (sublists_cons_perm_append _ _).trans (IH.append (IH.map _))\n\ntheorem revzip_sublists (l : list \u03b1) :\n  \u2200 l\u2081 l\u2082, (l\u2081, l\u2082) \u2208 revzip l.sublists \u2192 l\u2081 ++ l\u2082 ~ l :=\nbegin\n  rw revzip,\n  apply list.reverse_rec_on l,\n  { intros l\u2081 l\u2082 h, simp at h, simp [h] },\n  { intros l a IH l\u2081 l\u2082 h,\n    rw [sublists_concat, reverse_append, zip_append, \u2190 map_reverse,\n        zip_map_right, zip_map_left] at h; [skip, {simp}],\n    simp only [prod.mk.inj_iff, mem_map, mem_append, prod.map_mk, prod.exists] at h,\n    rcases h with \u27e8l\u2081, l\u2082', h, rfl, rfl\u27e9 | \u27e8l\u2081', l\u2082, h, rfl, rfl\u27e9,\n    { rw \u2190 append_assoc,\n      exact (IH _ _ h).append_right _ },\n    { rw append_assoc,\n      apply (perm_append_comm.append_left _).trans,\n      rw \u2190 append_assoc,\n      exact (IH _ _ h).append_right _ } }\nend\n\ntheorem revzip_sublists' (l : list \u03b1) :\n  \u2200 l\u2081 l\u2082, (l\u2081, l\u2082) \u2208 revzip l.sublists' \u2192 l\u2081 ++ l\u2082 ~ l :=\nbegin\n  rw revzip,\n  induction l with a l IH; intros l\u2081 l\u2082 h,\n  { simp at h, simp [h] },\n  { rw [sublists'_cons, reverse_append, zip_append, \u2190 map_reverse,\n        zip_map_right, zip_map_left] at h; [simp at h, simp],\n    rcases h with \u27e8l\u2081, l\u2082', h, rfl, rfl\u27e9 | \u27e8l\u2081', h, rfl\u27e9,\n    { exact perm_middle.trans ((IH _ _ h).cons _) },\n    { exact (IH _ _ h).cons _ } }\nend\n\ntheorem perm_lookmap (f : \u03b1 \u2192 option \u03b1) {l\u2081 l\u2082 : list \u03b1}\n  (H : pairwise (\u03bb a b, \u2200 (c \u2208 f a) (d \u2208 f b), a = b \u2227 c = d) l\u2081)\n  (p : l\u2081 ~ l\u2082) : lookmap f l\u2081 ~ lookmap f l\u2082 :=\nbegin\n  let F := \u03bb a b, \u2200 (c \u2208 f a) (d \u2208 f b), a = b \u2227 c = d,\n  change pairwise F l\u2081 at H,\n  induction p with a l\u2081 l\u2082 p IH a b l l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, {simp},\n  { cases h : f a,\n    { simp [h], exact IH (pairwise_cons.1 H).2 },\n    { simp [lookmap_cons_some _ _ h, p] } },\n  { cases h\u2081 : f a with c; cases h\u2082 : f b with d,\n    { simp [h\u2081, h\u2082], apply swap },\n    { simp [h\u2081, lookmap_cons_some _ _ h\u2082], apply swap },\n    { simp [lookmap_cons_some _ _ h\u2081, h\u2082], apply swap },\n    { simp [lookmap_cons_some _ _ h\u2081, lookmap_cons_some _ _ h\u2082],\n      rcases (pairwise_cons.1 H).1 _ (or.inl rfl) _ h\u2082 _ h\u2081 with \u27e8rfl, rfl\u27e9,\n      refl } },\n  { refine (IH\u2081 H).trans (IH\u2082 ((p\u2081.pairwise_iff _).1 H)),\n    exact \u03bb a b h c h\u2081 d h\u2082, (h d h\u2082 c h\u2081).imp eq.symm eq.symm }\nend\n\ntheorem perm.erasep (f : \u03b1 \u2192 Prop) [decidable_pred f] {l\u2081 l\u2082 : list \u03b1}\n  (H : pairwise (\u03bb a b, f a \u2192 f b \u2192 false) l\u2081)\n  (p : l\u2081 ~ l\u2082) : erasep f l\u2081 ~ erasep f l\u2082 :=\nbegin\n  let F := \u03bb a b, f a \u2192 f b \u2192 false,\n  change pairwise F l\u2081 at H,\n  induction p with a l\u2081 l\u2082 p IH a b l l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 IH\u2081 IH\u2082, {simp},\n  { by_cases h : f a,\n    { simp [h, p] },\n    { simp [h], exact IH (pairwise_cons.1 H).2 } },\n  { by_cases h\u2081 : f a; by_cases h\u2082 : f b; simp [h\u2081, h\u2082],\n    { cases (pairwise_cons.1 H).1 _ (or.inl rfl) h\u2082 h\u2081 },\n    { apply swap } },\n  { refine (IH\u2081 H).trans (IH\u2082 ((p\u2081.pairwise_iff _).1 H)),\n    exact \u03bb a b h h\u2081 h\u2082, h h\u2082 h\u2081 }\nend\n\nlemma perm.take_inter {\u03b1} [decidable_eq \u03b1] {xs ys : list \u03b1} (n : \u2115)\n  (h : xs ~ ys) (h' : ys.nodup) :\n  xs.take n ~ ys.inter (xs.take n) :=\nbegin\n  simp only [list.inter] at *,\n  induction h generalizing n,\n  case list.perm.nil : n\n  { simp only [not_mem_nil, filter_false, take_nil] },\n  case list.perm.cons : h_x h_l\u2081 h_l\u2082 h_a h_ih n\n  { cases n; simp only [mem_cons_iff, true_or, eq_self_iff_true, filter_cons_of_pos,\n                        perm_cons, take, not_mem_nil, filter_false],\n    cases h' with _ _ h\u2081 h\u2082,\n    convert h_ih h\u2082 n using 1,\n    apply filter_congr,\n    introv h, simp only [(h\u2081 x h).symm, false_or], },\n  case list.perm.swap : h_x h_y h_l n\n  { cases h' with _ _ h\u2081 h\u2082,\n    cases h\u2082 with _ _ h\u2082 h\u2083,\n    have := h\u2081 _ (or.inl rfl),\n    cases n; simp only [mem_cons_iff, not_mem_nil, filter_false, take],\n    cases n; simp only [mem_cons_iff, false_or, true_or, filter, *, nat.nat_zero_eq_zero, if_true,\n                        not_mem_nil, eq_self_iff_true, or_false, if_false, perm_cons, take],\n    { rw filter_eq_nil.2, intros, solve_by_elim [ne.symm], },\n    { convert perm.swap _ _ _, rw @filter_congr _ _ (\u2208 take n h_l),\n      { clear h\u2081, induction n generalizing h_l; simp only [not_mem_nil, filter_false, take],\n        cases h_l; simp only [mem_cons_iff, true_or, eq_self_iff_true, filter_cons_of_pos,\n                              true_and, take, not_mem_nil, filter_false, take_nil],\n        cases h\u2083 with _ _ h\u2083 h\u2084,\n        rwa [@filter_congr _ _ (\u2208 take n_n h_l_tl), n_ih],\n        { introv h, apply h\u2082 _ (or.inr h), },\n        { introv h, simp only [(h\u2083 x h).symm, false_or], }, },\n      { introv h, simp only [(h\u2082 x h).symm, (h\u2081 x (or.inr h)).symm, false_or], } } },\n  case list.perm.trans : h_l\u2081 h_l\u2082 h_l\u2083 h\u2080 h\u2081 h_ih\u2080 h_ih\u2081 n\n  { transitivity,\n    { apply h_ih\u2080, rwa h\u2081.nodup_iff },\n    { apply perm.filter _ h\u2081, } },\nend\n\nlemma perm.drop_inter {\u03b1} [decidable_eq \u03b1] {xs ys : list \u03b1} (n : \u2115)\n  (h : xs ~ ys) (h' : ys.nodup) :\n  xs.drop n ~ ys.inter (xs.drop n) :=\nbegin\n  by_cases h'' : n \u2264 xs.length,\n  { let n' := xs.length - n,\n    have h\u2080 : n = xs.length - n',\n    { dsimp [n'], rwa tsub_tsub_cancel_of_le, } ,\n    have h\u2081 : n' \u2264 xs.length,\n    { apply tsub_le_self },\n    have h\u2082 : xs.drop n = (xs.reverse.take n').reverse,\n    { rw [reverse_take _ h\u2081, h\u2080, reverse_reverse], },\n    rw [h\u2082],\n    apply (reverse_perm _).trans,\n    rw inter_reverse,\n    apply perm.take_inter _ _ h',\n    apply (reverse_perm _).trans; assumption, },\n  { have : drop n xs = [],\n    { apply eq_nil_of_length_eq_zero,\n      rw [length_drop, tsub_eq_zero_iff_le],\n      apply le_of_not_ge h'' },\n    simp [this, list.inter], }\nend\n\nlemma perm.slice_inter {\u03b1} [decidable_eq \u03b1] {xs ys : list \u03b1} (n m : \u2115)\n  (h : xs ~ ys) (h' : ys.nodup) :\n  list.slice n m xs ~ ys \u2229 (list.slice n m xs) :=\nbegin\n  simp only [slice_eq],\n  have : n \u2264 n + m := nat.le_add_right _ _,\n  have := h.nodup_iff.2 h',\n  apply perm.trans _ (perm.inter_append _).symm;\n  solve_by_elim [perm.append, perm.drop_inter, perm.take_inter, disjoint_take_drop, h, h']\n      { max_depth := 7 },\nend\n\n/- enumerating permutations -/\n\nsection permutations\n\ntheorem perm_of_mem_permutations_aux :\n  \u2200 {ts is l : list \u03b1}, l \u2208 permutations_aux ts is \u2192 l ~ ts ++ is :=\nbegin\n  refine permutations_aux.rec (by simp) _,\n  introv IH1 IH2 m,\n  rw [permutations_aux_cons, permutations, mem_foldr_permutations_aux2] at m,\n  rcases m with m | \u27e8l\u2081, l\u2082, m, _, e\u27e9,\n  { exact (IH1 m).trans perm_middle },\n  { subst e,\n    have p : l\u2081 ++ l\u2082 ~ is,\n    { simp [permutations] at m,\n      cases m with e m, {simp [e]},\n      exact is.append_nil \u25b8 IH2 m },\n    exact ((perm_middle.trans (p.cons _)).append_right _).trans (perm_append_comm.cons _) }\nend\n\ntheorem perm_of_mem_permutations {l\u2081 l\u2082 : list \u03b1}\n  (h : l\u2081 \u2208 permutations l\u2082) : l\u2081 ~ l\u2082 :=\n(eq_or_mem_of_mem_cons h).elim (\u03bb e, e \u25b8 perm.refl _)\n  (\u03bb m, append_nil l\u2082 \u25b8 perm_of_mem_permutations_aux m)\n\ntheorem length_permutations_aux : \u2200 ts is : list \u03b1,\n  length (permutations_aux ts is) + is.length! = (length ts + length is)! :=\nbegin\n  refine permutations_aux.rec (by simp) _,\n  intros t ts is IH1 IH2,\n  have IH2 : length (permutations_aux is nil) + 1 = is.length!,\n  { simpa using IH2 },\n  simp [-add_comm, nat.factorial, nat.add_succ, mul_comm] at IH1,\n  rw [permutations_aux_cons,\n      length_foldr_permutations_aux2' _ _ _ _ _\n        (\u03bb l m, (perm_of_mem_permutations m).length_eq),\n      permutations, length, length, IH2,\n      nat.succ_add, nat.factorial_succ, mul_comm (nat.succ _), \u2190 IH1,\n      add_comm (_*_), add_assoc, nat.mul_succ, mul_comm]\nend\n\ntheorem length_permutations (l : list \u03b1) : length (permutations l) = (length l)! :=\nlength_permutations_aux l []\n\ntheorem mem_permutations_of_perm_lemma {is l : list \u03b1}\n  (H : l ~ [] ++ is \u2192 (\u2203 ts' ~ [], l = ts' ++ is) \u2228 l \u2208 permutations_aux is [])\n  : l ~ is \u2192 l \u2208 permutations is :=\nby simpa [permutations, perm_nil] using H\n\ntheorem mem_permutations_aux_of_perm :\n  \u2200 {ts is l : list \u03b1}, l ~ is ++ ts \u2192 (\u2203 is' ~ is, l = is' ++ ts) \u2228 l \u2208 permutations_aux ts is :=\nbegin\n  refine permutations_aux.rec (by simp) _,\n  intros t ts is IH1 IH2 l p,\n  rw [permutations_aux_cons, mem_foldr_permutations_aux2],\n  rcases IH1 (p.trans perm_middle) with \u27e8is', p', e\u27e9 | m,\n  { clear p, subst e,\n    rcases mem_split (p'.symm.subset (mem_cons_self _ _)) with \u27e8l\u2081, l\u2082, e\u27e9,\n    subst is',\n    have p := (perm_middle.symm.trans p').cons_inv,\n    cases l\u2082 with a l\u2082',\n    { exact or.inl \u27e8l\u2081, by simpa using p\u27e9 },\n    { exact or.inr (or.inr \u27e8l\u2081, a::l\u2082',\n        mem_permutations_of_perm_lemma IH2 p, by simp\u27e9) } },\n  { exact or.inr (or.inl m) }\nend\n\n@[simp] theorem mem_permutations {s t : list \u03b1} : s \u2208 permutations t \u2194 s ~ t :=\n\u27e8perm_of_mem_permutations, mem_permutations_of_perm_lemma mem_permutations_aux_of_perm\u27e9\n\ntheorem perm_permutations'_aux_comm (a b : \u03b1) (l : list \u03b1) :\n  (permutations'_aux a l).bind (permutations'_aux b) ~\n  (permutations'_aux b l).bind (permutations'_aux a) :=\nbegin\n  induction l with c l ih, {simp [swap]},\n  simp [permutations'_aux], apply perm.swap',\n  have : \u2200 a b,\n    (map (cons c) (permutations'_aux a l)).bind (permutations'_aux b) ~\n    map (cons b \u2218 cons c) (permutations'_aux a l) ++\n    map (cons c) ((permutations'_aux a l).bind (permutations'_aux b)),\n  { intros,\n    simp only [map_bind, permutations'_aux],\n    refine (bind_append_perm _ (\u03bb x, [_]) _).symm.trans _,\n    rw [\u2190 map_eq_bind, \u2190 bind_map] },\n  refine (((this _ _).append_left _).trans _).trans ((this _ _).append_left _).symm,\n  rw [\u2190 append_assoc, \u2190 append_assoc],\n  exact perm_append_comm.append (ih.map _),\nend\n\ntheorem perm.permutations' {s t : list \u03b1} (p : s ~ t) :\n  permutations' s ~ permutations' t :=\nbegin\n  induction p with a s t p IH a b l s t u p\u2081 p\u2082 IH\u2081 IH\u2082, {simp},\n  { simp only [permutations'], exact IH.bind_right _ },\n  { simp only [permutations'],\n    rw [bind_assoc, bind_assoc], apply perm.bind_left, apply perm_permutations'_aux_comm },\n  { exact IH\u2081.trans IH\u2082 }\nend\n\ntheorem permutations_perm_permutations' (ts : list \u03b1) : ts.permutations ~ ts.permutations' :=\nbegin\n  obtain \u27e8n, h\u27e9 : \u2203 n, length ts < n := \u27e8_, nat.lt_succ_self _\u27e9,\n  induction n with n IH generalizing ts, {cases h},\n  refine list.reverse_rec_on ts (\u03bb h, _) (\u03bb ts t _ h, _) h, {simp [permutations]},\n  rw [\u2190 concat_eq_append, length_concat, nat.succ_lt_succ_iff] at h,\n  have IH\u2082 := (IH ts.reverse (by rwa [length_reverse])).trans (reverse_perm _).permutations',\n  simp only [permutations_append, foldr_permutations_aux2,\n    permutations_aux_nil, permutations_aux_cons, append_nil],\n  refine (perm_append_comm.trans ((IH\u2082.bind_right _).append ((IH _ h).map _))).trans\n    (perm.trans _ perm_append_comm.permutations'),\n  rw [map_eq_bind, singleton_append, permutations'],\n  convert bind_append_perm _ _ _, funext ys,\n  rw [permutations'_aux_eq_permutations_aux2, permutations_aux2_append]\nend\n\n@[simp] theorem mem_permutations' {s t : list \u03b1} : s \u2208 permutations' t \u2194 s ~ t :=\n(permutations_perm_permutations' _).symm.mem_iff.trans mem_permutations\n\ntheorem perm.permutations {s t : list \u03b1} (h : s ~ t) : permutations s ~ permutations t :=\n(permutations_perm_permutations' _).trans $ h.permutations'.trans\n(permutations_perm_permutations' _).symm\n\n@[simp] theorem perm_permutations_iff {s t : list \u03b1} : permutations s ~ permutations t \u2194 s ~ t :=\n\u27e8\u03bb h, mem_permutations.1 $ h.mem_iff.1 $ mem_permutations.2 (perm.refl _), perm.permutations\u27e9\n\n@[simp] theorem perm_permutations'_iff {s t : list \u03b1} : permutations' s ~ permutations' t \u2194 s ~ t :=\n\u27e8\u03bb h, mem_permutations'.1 $ h.mem_iff.1 $ mem_permutations'.2 (perm.refl _), perm.permutations'\u27e9\n\nlemma nth_le_permutations'_aux (s : list \u03b1) (x : \u03b1) (n : \u2115)\n  (hn : n < length (permutations'_aux x s)) :\n  (permutations'_aux x s).nth_le n hn = s.insert_nth n x :=\nbegin\n  induction s with y s IH generalizing n,\n  { simp only [length, permutations'_aux, nat.lt_one_iff] at hn,\n    simp [hn] },\n  { cases n,\n    { simp },\n    { simpa using IH _ _ } }\nend\n\nlemma count_permutations'_aux_self [decidable_eq \u03b1] (l : list \u03b1) (x : \u03b1) :\n  count (x :: l) (permutations'_aux x l) = length (take_while ((=) x) l) + 1 :=\nbegin\n  induction l with y l IH generalizing x,\n  { simp [take_while], },\n  { rw [permutations'_aux, count_cons_self],\n    by_cases hx : x = y,\n    { subst hx,\n      simpa [take_while, nat.succ_inj'] using IH _ },\n    { rw take_while,\n      rw if_neg hx,\n      cases permutations'_aux x l with a as,\n      { simp },\n      { rw [count_eq_zero_of_not_mem, length, zero_add],\n        simp [hx, ne.symm hx] } } }\nend\n\n@[simp] lemma length_permutations'_aux (s : list \u03b1) (x : \u03b1) :\n  length (permutations'_aux x s) = length s + 1 :=\nbegin\n  induction s with y s IH,\n  { simp },\n  { simpa using IH }\nend\n\n@[simp] lemma permutations'_aux_nth_le_zero (s : list \u03b1) (x : \u03b1)\n  (hn : 0 < length (permutations'_aux x s) := by simp) :\n  (permutations'_aux x s).nth_le 0 hn = x :: s :=\nnth_le_permutations'_aux _ _ _ _\n\nlemma injective_permutations'_aux (x : \u03b1) : function.injective (permutations'_aux x) :=\nbegin\n  intros s t h,\n  apply insert_nth_injective s.length x,\n  have hl : s.length = t.length := by simpa using congr_arg length h,\n  rw [\u2190nth_le_permutations'_aux s x s.length (by simp),\n      \u2190nth_le_permutations'_aux t x s.length (by simp [hl])],\n  simp [h, hl]\nend\n\nlemma nodup_permutations'_aux_of_not_mem (s : list \u03b1) (x : \u03b1) (hx : x \u2209 s) :\n  nodup (permutations'_aux x s) :=\nbegin\n  induction s with y s IH,\n  { simp },\n  { simp only [not_or_distrib, mem_cons_iff] at hx,\n    simp only [not_and, exists_eq_right_right, mem_map, permutations'_aux, nodup_cons],\n    refine \u27e8\u03bb _, ne.symm hx.left, _\u27e9,\n    rw nodup_map_iff,\n    { exact IH hx.right },\n    { simp } }\nend\n\nlemma nodup_permutations'_aux_iff {s : list \u03b1} {x : \u03b1} :\n  nodup (permutations'_aux x s) \u2194 x \u2209 s :=\nbegin\n  refine \u27e8\u03bb h, _, nodup_permutations'_aux_of_not_mem _ _\u27e9,\n  intro H,\n  obtain \u27e8k, hk, hk'\u27e9 := nth_le_of_mem H,\n  rw nodup_iff_nth_le_inj at h,\n  suffices : k = k + 1,\n  { simpa using this },\n  refine h k (k + 1) _ _ _,\n  { simpa [nat.lt_succ_iff] using hk.le },\n  { simpa using hk },\n  rw [nth_le_permutations'_aux, nth_le_permutations'_aux],\n  have hl : length (insert_nth k x s) = length (insert_nth (k + 1) x s),\n  { rw [length_insert_nth _ _ hk.le, length_insert_nth _ _ (nat.succ_le_of_lt hk)] },\n  refine ext_le hl (\u03bb n hn hn', _),\n  rcases lt_trichotomy n k with H|rfl|H,\n  { rw [nth_le_insert_nth_of_lt _ _ _ _ H (H.trans hk),\n        nth_le_insert_nth_of_lt _ _ _ _ (H.trans (nat.lt_succ_self _))] },\n  { rw [nth_le_insert_nth_self _ _ _ hk.le,\n        nth_le_insert_nth_of_lt _ _ _ _ (nat.lt_succ_self _) hk, hk'] },\n  { rcases (nat.succ_le_of_lt H).eq_or_lt with rfl|H',\n    { rw [nth_le_insert_nth_self _ _ _ (nat.succ_le_of_lt hk)],\n      convert hk' using 1,\n      convert nth_le_insert_nth_add_succ _ _ _ 0 _,\n      simpa using hk },\n    { obtain \u27e8m, rfl\u27e9 := nat.exists_eq_add_of_lt H',\n      rw [length_insert_nth _ _ hk.le, nat.succ_lt_succ_iff, nat.succ_add] at hn,\n      rw nth_le_insert_nth_add_succ,\n      convert nth_le_insert_nth_add_succ s x k m.succ _ using 2,\n      { simp [nat.add_succ, nat.succ_add] },\n      { simp [add_left_comm, add_comm] },\n      { simpa [nat.add_succ] using hn },\n      { simpa [nat.succ_add] using hn } } }\nend\n\nlemma nodup_permutations (s : list \u03b1) (hs : nodup s) :\n  nodup s.permutations :=\nbegin\n  rw (permutations_perm_permutations' s).nodup_iff,\n  induction hs with x l h h' IH,\n  { simp },\n  { rw [permutations'],\n    rw nodup_bind,\n    split,\n    { intros ys hy,\n      rw mem_permutations' at hy,\n      rw [nodup_permutations'_aux_iff, hy.mem_iff],\n      exact \u03bb H, h x H rfl },\n    { refine IH.pairwise_of_forall_ne (\u03bb as ha bs hb H, _),\n      rw disjoint_iff_ne,\n      rintro a ha' b hb' rfl,\n      obtain \u27e8n, hn, hn'\u27e9 := nth_le_of_mem ha',\n      obtain \u27e8m, hm, hm'\u27e9 := nth_le_of_mem hb',\n      rw mem_permutations' at ha hb,\n      have hl : as.length = bs.length := (ha.trans hb.symm).length_eq,\n      simp only [nat.lt_succ_iff, length_permutations'_aux] at hn hm,\n      rw nth_le_permutations'_aux at hn' hm',\n      have hx : nth_le (insert_nth n x as) m\n        (by rwa [length_insert_nth _ _ hn, nat.lt_succ_iff, hl]) = x,\n      { simp [hn', \u2190hm', hm] },\n      have hx' : nth_le (insert_nth m x bs) n\n        (by rwa [length_insert_nth _ _ hm, nat.lt_succ_iff, \u2190hl]) = x,\n      { simp [hm', \u2190hn', hn] },\n      rcases lt_trichotomy n m with ht|ht|ht,\n      { suffices : x \u2208 bs,\n        { exact h x (hb.subset this) rfl },\n        rw [\u2190hx', nth_le_insert_nth_of_lt _ _ _ _ ht (ht.trans_le hm)],\n        exact nth_le_mem _ _ _ },\n      { simp only [ht] at hm' hn',\n        rw \u2190hm' at hn',\n        exact H (insert_nth_injective _ _ hn') },\n      { suffices : x \u2208 as,\n        { exact h x (ha.subset this) rfl },\n        rw [\u2190hx, nth_le_insert_nth_of_lt _ _ _ _ ht (ht.trans_le hn)],\n        exact nth_le_mem _ _ _ } } }\nend\n\n-- TODO: `nodup s.permutations \u2194 nodup s`\n-- TODO: `count s s.permutations = (zip_with count s s.tails).prod`\n\nend permutations\n\nend list\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/list/perm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198947, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.7305566214889112}}
{"text": "/-\nCopyright (c) 2022 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport algebra.star.basic\nimport group_theory.submonoid.membership\n\n/-!\n# Unitary elements of a star monoid\n\nThis file defines `unitary R`, where `R` is a star monoid, as the submonoid made of the elements\nthat satisfy `star U * U = 1` and `U * star U = 1`, and these form a group.\nThis includes, for instance, unitary operators on Hilbert spaces.\n\nSee also `matrix.unitary_group` for specializations to `unitary (matrix n n R)`.\n\n## Tags\n\nunitary\n-/\n\n/--\nIn a `star_monoid R`, `unitary R` is the submonoid consisting of all the elements `U` of\n`R` such that `star U * U = 1` and `U * star U = 1`.\n-/\ndef unitary (R : Type*) [monoid R] [star_monoid R] : submonoid R :=\n{ carrier := {U | star U * U = 1 \u2227 U * star U = 1},\n  one_mem' := by simp only [mul_one, and_self, set.mem_set_of_eq, star_one],\n  mul_mem' := \u03bb U B \u27e8hA\u2081, hA\u2082\u27e9 \u27e8hB\u2081, hB\u2082\u27e9,\n  begin\n    refine \u27e8_, _\u27e9,\n    { calc star (U * B) * (U * B) = star B * star U * U * B     : by simp only [mul_assoc, star_mul]\n                            ...   = star B * (star U * U) * B   : by rw [\u2190mul_assoc]\n                            ...   = 1                           : by rw [hA\u2081, mul_one, hB\u2081] },\n    { calc U * B * star (U * B) = U * B * (star B * star U)     : by rw [star_mul]\n                            ... = U * (B * star B) * star U     : by simp_rw [\u2190mul_assoc]\n                            ... = 1                             : by rw [hB\u2082, mul_one, hA\u2082] }\n  end }\n\nvariables {R : Type*}\n\nnamespace unitary\n\nsection monoid\nvariables [monoid R] [star_monoid R]\n\nlemma mem_iff {U : R} : U \u2208 unitary R \u2194 star U * U = 1 \u2227 U * star U = 1 := iff.rfl\n@[simp] lemma star_mul_self_of_mem {U : R} (hU : U \u2208 unitary R) : star U * U = 1 := hU.1\n@[simp] lemma mul_star_self_of_mem {U : R} (hU : U \u2208 unitary R) : U * star U = 1 := hU.2\n\nlemma star_mem {U : R} (hU : U \u2208 unitary R) : star U \u2208 unitary R :=\n\u27e8by rw [star_star, mul_star_self_of_mem hU], by rw [star_star, star_mul_self_of_mem hU]\u27e9\n\n@[simp] lemma star_mem_iff {U : R} : star U \u2208 unitary R \u2194 U \u2208 unitary R :=\n\u27e8\u03bb h, star_star U \u25b8 star_mem h, star_mem\u27e9\n\ninstance : has_star (unitary R) := \u27e8\u03bb U, \u27e8star U, star_mem U.prop\u27e9\u27e9\n\n@[simp, norm_cast] lemma coe_star {U : unitary R} : \u2191(star U) = (star U : R) := rfl\n\nlemma coe_star_mul_self (U : unitary R) : (star U : R) * U = 1 := star_mul_self_of_mem U.prop\nlemma coe_mul_star_self (U : unitary R) :  (U : R) * star U = 1 := mul_star_self_of_mem U.prop\n\n@[simp] lemma star_mul_self (U : unitary R) : star U * U = 1 := subtype.ext $ coe_star_mul_self U\n@[simp] lemma mul_star_self (U : unitary R) : U * star U = 1 := subtype.ext $ coe_mul_star_self U\n\ninstance : group (unitary R) :=\n{ inv := star,\n  mul_left_inv := star_mul_self,\n  ..submonoid.to_monoid _ }\n\ninstance : has_involutive_star (unitary R) :=\n\u27e8\u03bb _, by { ext, simp only [coe_star, star_star] }\u27e9\n\ninstance : star_monoid (unitary R) :=\n\u27e8\u03bb _ _, by { ext, simp only [coe_star, submonoid.coe_mul, star_mul] }\u27e9\n\ninstance : inhabited (unitary R) := \u27e81\u27e9\n\nlemma star_eq_inv (U : unitary R) : star U = U\u207b\u00b9 := rfl\n\nlemma star_eq_inv' : (star : unitary R \u2192 unitary R) = has_inv.inv := rfl\n\n/-- The unitary elements embed into the units. -/\n@[simps]\ndef to_units : unitary R \u2192* R\u02e3 :=\n{ to_fun := \u03bb x, \u27e8x, \u2191(x\u207b\u00b9), coe_mul_star_self x, coe_star_mul_self x\u27e9,\n  map_one' := units.ext rfl,\n  map_mul' := \u03bb x y, units.ext rfl }\n\nlemma to_units_injective : function.injective (to_units : unitary R \u2192 R\u02e3) :=\n\u03bb x y h, subtype.ext $ units.ext_iff.mp h\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid R] [star_monoid R]\n\ninstance : comm_group (unitary R) :=\n{ ..unitary.group,\n  ..submonoid.to_comm_monoid _ }\n\nlemma mem_iff_star_mul_self {U : R} : U \u2208 unitary R \u2194 star U * U = 1 :=\nmem_iff.trans $ and_iff_left_of_imp $ \u03bb h, mul_comm (star U) U \u25b8 h\n\nlemma mem_iff_self_mul_star {U : R} : U \u2208 unitary R \u2194 U * star U = 1 :=\nmem_iff.trans $ and_iff_right_of_imp $ \u03bb h, mul_comm U (star U) \u25b8 h\n\nend comm_monoid\n\nsection group_with_zero\nvariables [group_with_zero R] [star_monoid R]\n\n@[norm_cast] lemma coe_inv (U : unitary R) : \u2191(U\u207b\u00b9) = (U\u207b\u00b9 : R) :=\neq_inv_of_mul_right_eq_one (coe_mul_star_self _)\n\n@[norm_cast] lemma coe_div (U\u2081 U\u2082 : unitary R) : \u2191(U\u2081 / U\u2082) = (U\u2081 / U\u2082 : R) :=\nby simp only [div_eq_mul_inv, coe_inv, submonoid.coe_mul]\n\n@[norm_cast] lemma coe_zpow (U : unitary R) (z : \u2124) : \u2191(U ^ z) = (U ^ z : R) :=\nbegin\n  induction z,\n  { simp [submonoid.coe_pow], },\n  { simp [coe_inv] },\nend\n\nend group_with_zero\n\nend unitary\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/star/unitary.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656671, "lm_q2_score": 0.8479677526147222, "lm_q1q2_score": 0.7305566101990586}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Kenny Lau, Robert Y. Lewis\n-/\nimport algebra.group.defs\n\n/-!\n# Eckmann-Hilton argument\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe Eckmann-Hilton argument says that if a type carries two monoid structures that distribute\nover one another, then they are equal, and in addition commutative.\nThe main application lies in proving that higher homotopy groups (`\u03c0\u2099` for `n \u2265 2`) are commutative.\n\n## Main declarations\n\n* `eckmann_hilton.comm_monoid`: If a type carries a unital magma structure that distributes\n  over a unital binary operation, then the magma is a commutative monoid.\n* `eckmann_hilton.comm_group`: If a type carries a group structure that distributes\n  over a unital binary operation, then the group is commutative.\n\n-/\n\n\nuniverse u\n\nnamespace eckmann_hilton\nvariables {X : Type u}\n\nlocal notation a ` <`m`> ` b := m a b\n\n/-- `is_unital m e` expresses that `e : X` is a left and right unit\nfor the binary operation `m : X \u2192 X \u2192 X`. -/\nstructure is_unital (m : X \u2192 X \u2192 X) (e : X) extends is_left_id _ m e, is_right_id _ m e : Prop.\n\n@[to_additive eckmann_hilton.add_zero_class.is_unital]\nlemma mul_one_class.is_unital [G : mul_one_class X] : is_unital (*) (1 : X) :=\nis_unital.mk (by apply_instance) (by apply_instance)\n\nvariables {m\u2081 m\u2082 : X \u2192 X \u2192 X} {e\u2081 e\u2082 : X}\nvariables (h\u2081 : is_unital m\u2081 e\u2081) (h\u2082 : is_unital m\u2082 e\u2082)\nvariables (distrib : \u2200 a b c d, ((a <m\u2082> b) <m\u2081> (c <m\u2082> d)) = ((a <m\u2081> c) <m\u2082> (b <m\u2081> d)))\ninclude h\u2081 h\u2082 distrib\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen they have the same unit elements.\n\nIn fact, the two operations are the same, and give a commutative monoid structure,\nsee `eckmann_hilton.comm_monoid`. -/\nlemma one : e\u2081 = e\u2082 :=\nby simpa only [h\u2081.left_id, h\u2081.right_id, h\u2082.left_id, h\u2082.right_id] using distrib e\u2082 e\u2081 e\u2081 e\u2082\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen these operations are equal.\n\nIn fact, they give a commutative monoid structure, see `eckmann_hilton.comm_monoid`. -/\nlemma mul : m\u2081 = m\u2082 :=\nbegin\n  funext a b,\n  calc m\u2081 a b = m\u2081 (m\u2082 a e\u2081) (m\u2082 e\u2081 b) :\n    by simp only [one h\u2081 h\u2082 distrib, h\u2081.left_id, h\u2081.right_id, h\u2082.left_id, h\u2082.right_id]\n          ... = m\u2082 a b :\n    by simp only [distrib, h\u2081.left_id, h\u2081.right_id, h\u2082.left_id, h\u2082.right_id]\nend\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen these operations are commutative.\n\nIn fact, they give a commutative monoid structure, see `eckmann_hilton.comm_monoid`. -/\nlemma mul_comm : is_commutative _ m\u2082 :=\n\u27e8\u03bb a b, by simpa [mul h\u2081 h\u2082 distrib, h\u2082.left_id, h\u2082.right_id] using distrib e\u2082 a b e\u2082\u27e9\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen these operations are associative.\n\nIn fact, they give a commutative monoid structure, see `eckmann_hilton.comm_monoid`. -/\nlemma mul_assoc : is_associative _ m\u2082 :=\n\u27e8\u03bb a b c, by simpa [mul h\u2081 h\u2082 distrib, h\u2082.left_id, h\u2082.right_id] using distrib a b e\u2082 c\u27e9\n\nomit h\u2081 h\u2082 distrib\n\n/-- If a type carries a unital magma structure that distributes over a unital binary\noperations, then the magma structure is a commutative monoid. -/\n@[reducible, to_additive \"If a type carries a unital additive magma structure that distributes over\na unital binary operations, then the additive magma structure is a commutative additive monoid.\"]\ndef comm_monoid [h : mul_one_class X]\n  (distrib : \u2200 a b c d, ((a * b) <m\u2081> (c * d)) = ((a <m\u2081> c) * (b <m\u2081> d))) : comm_monoid X :=\n{ mul := (*),\n  one := 1,\n  mul_comm := (mul_comm h\u2081 mul_one_class.is_unital distrib).comm,\n  mul_assoc := (mul_assoc h\u2081 mul_one_class.is_unital distrib).assoc,\n  ..h }\n\n/-- If a type carries a group structure that distributes over a unital binary operation,\nthen the group is commutative. -/\n@[reducible, to_additive \"If a type carries an additive group structure that\ndistributes over a unital binary operation, then the additive group is commutative.\"]\ndef comm_group [G : group X]\n  (distrib : \u2200 a b c d, ((a * b) <m\u2081> (c * d)) = ((a <m\u2081> c) * (b <m\u2081> d))) : comm_group X :=\n{ ..(eckmann_hilton.comm_monoid h\u2081 distrib),\n  ..G }\n\nend eckmann_hilton\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/eckmann_hilton.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8633916222765629, "lm_q1q2_score": 0.7303796200071324}}
{"text": "/-\nCopyright (c) 2019 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport data.list.range\nimport data.list.bag_inter\n\nopen nat\n\nnamespace list\n/--\n`Ico n m` is the list of natural numbers `n \u2264 x < m`.\n(Ico stands for \"interval, closed-open\".)\n\nSee also `data/set/intervals.lean` for `set.Ico`, modelling intervals in general preorders, and\n`multiset.Ico` and `finset.Ico` for `n \u2264 x < m` as a multiset or as a finset.\n\n@TODO (anyone): Define `Ioo` and `Icc`, state basic lemmas about them.\n@TODO (anyone): Also do the versions for integers?\n@TODO (anyone): One could generalise even further, defining\n'locally finite partial orders', for which `set.Ico a b` is `[finite]`, and\n'locally finite total orders', for which there is a list model.\n -/\ndef Ico (n m : \u2115) : list \u2115 := range' n (m - n)\n\nnamespace Ico\n\ntheorem zero_bot (n : \u2115) : Ico 0 n = range n :=\nby rw [Ico, nat.sub_zero, range_eq_range']\n\n@[simp] theorem length (n m : \u2115) : length (Ico n m) = m - n :=\nby dsimp [Ico]; simp only [length_range']\n\ntheorem pairwise_lt (n m : \u2115) : pairwise (<) (Ico n m) :=\nby dsimp [Ico]; simp only [pairwise_lt_range']\n\ntheorem nodup (n m : \u2115) : nodup (Ico n m) :=\nby dsimp [Ico]; simp only [nodup_range']\n\n@[simp] theorem mem {n m l : \u2115} : l \u2208 Ico n m \u2194 n \u2264 l \u2227 l < m :=\nsuffices n \u2264 l \u2227 l < n + (m - n) \u2194 n \u2264 l \u2227 l < m, by simp [Ico, this],\nbegin\n  cases le_total n m with hnm hmn,\n  { rw [nat.add_sub_of_le hnm] },\n  { rw [nat.sub_eq_zero_of_le hmn, add_zero],\n    exact and_congr_right (assume hnl, iff.intro\n      (assume hln, (not_le_of_gt hln hnl).elim)\n      (assume hlm, lt_of_lt_of_le hlm hmn)) }\nend\n\ntheorem eq_nil_of_le {n m : \u2115} (h : m \u2264 n) : Ico n m = [] :=\nby simp [Ico, nat.sub_eq_zero_of_le h]\n\ntheorem map_add (n m k : \u2115) : (Ico n m).map ((+) k) = Ico (n + k) (m + k) :=\nby rw [Ico, Ico, map_add_range', nat.add_sub_add_right, add_comm n k]\n\ntheorem map_sub (n m k : \u2115) (h\u2081 : k \u2264 n) : (Ico n m).map (\u03bb x, x - k) = Ico (n - k) (m - k) :=\nbegin\n  by_cases h\u2082 : n < m,\n  { rw [Ico, Ico],\n    rw nat.sub_sub_sub_cancel_right h\u2081,\n    rw [map_sub_range' _ _ _ h\u2081] },\n  { simp at h\u2082,\n    rw [eq_nil_of_le h\u2082],\n    rw [eq_nil_of_le (nat.sub_le_sub_right h\u2082 _)],\n    refl }\nend\n\n@[simp] theorem self_empty {n : \u2115} : Ico n n = [] :=\neq_nil_of_le (le_refl n)\n\n@[simp] theorem eq_empty_iff {n m : \u2115} : Ico n m = [] \u2194 m \u2264 n :=\niff.intro (assume h, nat.le_of_sub_eq_zero $ by rw [\u2190 length, h]; refl) eq_nil_of_le\n\nlemma append_consecutive {n m l : \u2115} (hnm : n \u2264 m) (hml : m \u2264 l) :\n  Ico n m ++ Ico m l = Ico n l :=\nbegin\n  dunfold Ico,\n  convert range'_append _ _ _,\n  { exact (nat.add_sub_of_le hnm).symm },\n  { rwa [\u2190 nat.add_sub_assoc hnm, nat.sub_add_cancel] }\nend\n\n@[simp] lemma inter_consecutive (n m l : \u2115) : Ico n m \u2229 Ico m l = [] :=\nbegin\n  apply eq_nil_iff_forall_not_mem.2,\n  intro a,\n  simp only [and_imp, not_and, not_lt, list.mem_inter, list.Ico.mem],\n  intros h\u2081 h\u2082 h\u2083,\n  exfalso,\n  exact not_lt_of_ge h\u2083 h\u2082\nend\n\n@[simp] lemma bag_inter_consecutive (n m l : \u2115) : list.bag_inter (Ico n m) (Ico m l) = [] :=\n(bag_inter_nil_iff_inter_nil _ _).2 (inter_consecutive n m l)\n\n@[simp] theorem succ_singleton {n : \u2115} : Ico n (n+1) = [n] :=\nby dsimp [Ico]; simp [nat.add_sub_cancel_left]\n\ntheorem succ_top {n m : \u2115} (h : n \u2264 m) : Ico n (m + 1) = Ico n m ++ [m] :=\nby rwa [\u2190 succ_singleton, append_consecutive]; exact nat.le_succ _\n\ntheorem eq_cons {n m : \u2115} (h : n < m) : Ico n m = n :: Ico (n + 1) m :=\nby rw [\u2190 append_consecutive (nat.le_succ n) h, succ_singleton]; refl\n\n@[simp] theorem pred_singleton {m : \u2115} (h : 0 < m) : Ico (m - 1) m = [m - 1] :=\nby dsimp [Ico]; rw nat.sub_sub_self h; simp\n\ntheorem chain'_succ (n m : \u2115) : chain' (\u03bba b, b = succ a) (Ico n m) :=\nbegin\n  by_cases n < m,\n  { rw [eq_cons h], exact chain_succ_range' _ _ },\n  { rw [eq_nil_of_le (le_of_not_gt h)], trivial }\nend\n\n@[simp] theorem not_mem_top {n m : \u2115} : m \u2209 Ico n m :=\nby simp; intros; refl\n\nlemma filter_lt_of_top_le {n m l : \u2115} (hml : m \u2264 l) : (Ico n m).filter (\u03bb x, x < l) = Ico n m :=\nfilter_eq_self.2 $ assume k hk, lt_of_lt_of_le (mem.1 hk).2 hml\n\n\n\nlemma filter_lt_of_ge {n m l : \u2115} (hlm : l \u2264 m) : (Ico n m).filter (\u03bb x, x < l) = Ico n l :=\nbegin\n  cases le_total n l with hnl hln,\n  { rw [\u2190 append_consecutive hnl hlm, filter_append,\n      filter_lt_of_top_le (le_refl l), filter_lt_of_le_bot (le_refl l), append_nil] },\n  { rw [eq_nil_of_le hln, filter_lt_of_le_bot hln] }\nend\n\n@[simp] lemma filter_lt (n m l : \u2115) : (Ico n m).filter (\u03bb x, x < l) = Ico n (min m l) :=\nbegin\n  cases le_total m l with hml hlm,\n  { rw [min_eq_left hml, filter_lt_of_top_le hml] },\n  { rw [min_eq_right hlm, filter_lt_of_ge hlm] }\nend\n\nlemma filter_le_of_le_bot {n m l : \u2115} (hln : l \u2264 n) : (Ico n m).filter (\u03bb x, l \u2264 x) = Ico n m :=\nfilter_eq_self.2 $ assume k hk, le_trans hln (mem.1 hk).1\n\nlemma filter_le_of_top_le {n m l : \u2115} (hml : m \u2264 l) : (Ico n m).filter (\u03bb x, l \u2264 x) = [] :=\nfilter_eq_nil.2 $ assume k hk, not_le_of_gt (lt_of_lt_of_le (mem.1 hk).2 hml)\n\nlemma filter_le_of_le {n m l : \u2115} (hnl : n \u2264 l) : (Ico n m).filter (\u03bb x, l \u2264 x) = Ico l m :=\nbegin\n  cases le_total l m with hlm hml,\n  { rw [\u2190 append_consecutive hnl hlm, filter_append,\n      filter_le_of_top_le (le_refl l), filter_le_of_le_bot (le_refl l), nil_append] },\n  { rw [eq_nil_of_le hml, filter_le_of_top_le hml] }\nend\n\n@[simp] lemma filter_le (n m l : \u2115) : (Ico n m).filter (\u03bb x, l \u2264 x) = Ico (_root_.max n l) m :=\nbegin\n  cases le_total n l with hnl hln,\n  { rw [max_eq_right hnl, filter_le_of_le hnl] },\n  { rw [max_eq_left hln, filter_le_of_le_bot hln] }\nend\n\nlemma filter_lt_of_succ_bot {n m : \u2115} (hnm : n < m) : (Ico n m).filter (\u03bb x, x < n + 1) = [n] :=\nbegin\n  have r : min m (n + 1) = n + 1 := (@inf_eq_right _ _ m (n + 1)).mpr hnm,\n  simp [filter_lt n m (n + 1), r],\nend\n\n@[simp] lemma filter_le_of_bot {n m : \u2115} (hnm : n < m) : (Ico n m).filter (\u03bb x, x \u2264 n) = [n] :=\nbegin\n  rw \u2190filter_lt_of_succ_bot hnm,\n  exact filter_congr (\u03bb _ _, lt_succ_iff.symm),\nend\n\n/--\nFor any natural numbers n, a, and b, one of the following holds:\n1. n < a\n2. n \u2265 b\n3. n \u2208 Ico a b\n-/\nlemma trichotomy (n a b : \u2115) : n < a \u2228 b \u2264 n \u2228 n \u2208 Ico a b :=\nbegin\n  by_cases h\u2081 : n < a,\n  { left, exact h\u2081 },\n  { right,\n    by_cases h\u2082 : n \u2208 Ico a b,\n    { right, exact h\u2082 },\n    { left,  simp only [Ico.mem, not_and, not_lt] at *, exact h\u2082 h\u2081 }}\nend\n\nend Ico\nend list\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/list/intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7303796129530589}}
{"text": "import data.real.basic\n\n\nstructure group\u2081 (\u03b1 : Type*) := \n  (mul : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n  (one: \u03b1)\n  (inv : \u03b1 \u2192 \u03b1)\n  (mul_assoc : \u2200 x y z : \u03b1, mul (mul x y) z = mul x (mul y z))\n  (mul_one : \u2200 x : \u03b1, mul x one = x)\n  (one_mul : \u2200 x : \u03b1, mul one x = x)\n  (mul_left_inv : \u2200 x : \u03b1, mul (inv x) x = one)\n\n#print group \n\nstructure Group\u2081 :=\n  (\u03b1 : Type*)\n  (str : group\u2081 \u03b1)\n\n\nsection\nvariables (\u03b1 \u03b2 \u03b3 : Type*)\nvariables (f : \u03b1 \u2243 \u03b2) (g : \u03b2 \u2243 \u03b3) -- ~-\n\n#check equiv \u03b1 \u03b2\n#check (f.to_fun : \u03b1 \u2192 \u03b2)\n#check (f.inv_fun : \u03b2 \u2192 \u03b1)\n#check (f.right_inv: \u2200 x : \u03b2, f (f.inv_fun x) = x)\n#check (f.left_inv: \u2200 x : \u03b1, f.inv_fun (f x) = x)\n\n#check (equiv.refl \u03b1 : \u03b1 \u2243 \u03b1)\n#check (f.symm : \u03b2 \u2243 \u03b1)\n#check (f.trans g : \u03b1 \u2243 \u03b3)\n\n\nexample (x : \u03b1) : (f.trans g).to_fun x = g.to_fun (f.to_fun x) := rfl\n\nexample (x : \u03b1) : (f.trans g) x = g (f x) := rfl\n\nexample : (f.trans g : \u03b1 \u2192 \u03b3) = g \u2218 f := rfl\n\nend\n\n\nexample (\u03b1 : Type*) : equiv.perm \u03b1 = (\u03b1 \u2243 \u03b1) := rfl\n\n\n\ndef perm_group {\u03b1 : Type*} : group\u2081 (equiv.perm \u03b1) :=\n{\n  mul := \u03bb f g, equiv.trans g f,\n  one := equiv.refl \u03b1, \n  inv := equiv.symm,\n  mul_assoc := \u03bb f g h, (equiv.trans_assoc _ _ _).symm,\n  one_mul := equiv.trans_refl,\n  mul_one := equiv.refl_trans,\n  mul_left_inv := equiv.self_trans_symm,\n}\n\n\nstructure add_group\u2081 (\u03b1 : Type*) :=\n  (add : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n  (zero : \u03b1)\n  (neg : \u03b1 \u2192 \u03b1)\n  (add_assoc : \u2200 x y z : \u03b1, add (add x y) z = add x (add y z))\n  (add_zero : \u2200 x : \u03b1, add x zero = x)\n  (zero_add : \u2200 x : \u03b1, add zero x = x)\n  (add_left_neg : \u2200 x : \u03b1, add (neg x) x = zero)\n\n@[ext] structure point := (x : \u211d) (y : \u211d) (z : \u211d)\n\nnamespace point\n\ndef add (a b : point) : point := \u27e8a.x + b.x, a.y + b.y, a.z + b.z\u27e9\n\ndef neg (a : point) : point := \n  \u27e8-a.x, -a.y, -a.z\u27e9\n\ndef zero : point := \n  \u27e80, 0, 0\u27e9\n\ndef add_group_point : add_group\u2081 point := \n{\n  add := add,\n  zero := zero,\n  neg := neg,\n  add_assoc := by { intros, ext; simp [add, add_assoc],},\n  add_zero := by { intros, ext; simp [add, add_zero, zero],},\n  zero_add := by { intros, ext; simp [add, zero_add, zero]},\n  add_left_neg := by { intros, ext; simp [add, neg, zero]},\n}\n\nend point\n\n\nsection \nvariables {\u03b1 : Type*} (f g : equiv.perm \u03b1) (n : \u2115)\n\n#check f * g\n#check mul_assoc f g g\u207b\u00b9\n\n-- group power, defined for any group\n#check g^n\n\nexample : f * g * (g\u207b\u00b9) = f :=\nby { rw [mul_assoc, mul_right_inv, mul_one] }\n\nexample : f * g * (g\u207b\u00b9) = f := mul_inv_cancel_right f g\n\nexample {\u03b1 : Type*} (f g : equiv.perm \u03b1) : g.symm.trans (g.trans f) = f :=\nmul_inv_cancel_right f g\n\nend\n\n\nclass group\u2082 (\u03b1 : Type*) :=\n(mul: \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(one: \u03b1)\n(inv: \u03b1 \u2192 \u03b1)\n(mul_assoc : \u2200 x y z : \u03b1, mul (mul x y) z = mul x (mul y z))\n(mul_one: \u2200 x : \u03b1, mul x one = x)\n(one_mul: \u2200 x : \u03b1, mul one x = x)\n(mul_left_inv : \u2200 x : \u03b1, mul (inv x) x = one)\n\ninstance {\u03b1 : Type*} : group\u2082 (equiv.perm \u03b1) :=\n{ mul          := \u03bb f g, equiv.trans g f,\n  one          := equiv.refl \u03b1,\n  inv          := equiv.symm,\n  mul_assoc    := \u03bb f g h, (equiv.trans_assoc _ _ _).symm,\n  one_mul      := equiv.trans_refl,\n  mul_one      := equiv.refl_trans,\n  mul_left_inv := equiv.self_trans_symm }\n\n\n#check @group\u2082.mul\n\ndef my_square {\u03b1 : Type*} [group\u2082 \u03b1] (x : \u03b1) := group\u2082.mul x x\n\n#check @my_square\n\nsection\nvariables {\u03b2 : Type*} (f g : equiv.perm \u03b2)\n\nexample : group\u2082.mul f g = g.trans f := rfl\n\nexample : my_square f = f.trans f := rfl\n\nend\n\ninstance : inhabited point := { default := \u27e80, 0, 0\u27e9 }\n\n#check (default : point)\n\nexample : ([] : list point).head = default := rfl\n\n\ninstance : has_add point := { add := point.add }\n\nsection\nvariables x y : point\n\n#check x + y\n\nexample : x + y = point.add x y := rfl\n\nend\n\ninstance has_mul_group\u2082 {\u03b1 : Type*} [group\u2082 \u03b1] : has_mul \u03b1 := \u27e8group\u2082.mul\u27e9\n\ninstance has_one_group\u2082 {\u03b1 : Type*} [group\u2082 \u03b1] : has_one \u03b1 := \u27e8group\u2082.one\u27e9\n\ninstance has_inv_group\u2082 {\u03b1 : Type*} [group\u2082 \u03b1] : has_inv \u03b1 := \u27e8group\u2082.inv\u27e9\n\n\nsection\nvariables {\u03b1 : Type*} (f g : equiv.perm \u03b1)\n\n#check f * 1 * g\u207b\u00b9\n\nexample : f * 1 * g\u207b\u00b9 = g.symm.trans ((equiv.refl \u03b1).trans f) := rfl\n\nend", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/06_Abstract_Algebra/02_Algebraic_Structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7303796088400543}}
{"text": "-- Pertenencia_a_bloques_de_una_particion_con_elementos_comunes.lean\n-- Pertenencia a bloques de una partici\u00f3n con elementos comunes\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 1 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Este ejercicio es el 2\u00ba de una serie, que comenz\u00f3 con el [ejercicio\n-- del 30 de septiembre](https://bit.ly/2YfsvBZ), cuyo objetivo es\n-- demostrar que el tipo de las particiones de un conjunto `X` es\n-- isomorfo al tipo de las relaciones de equivalencia sobre `X`.\n--\n-- El ejercicio consiste en demostrar que si dos bloques de una\n-- partici\u00f3n tienen elementos comunes, entonces los elementos de uno\n-- tambi\u00e9n pertenecen al otro.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n@[ext] structure particion (A : Type) :=\n(Bloques    : set (set A))\n(Hno_vacios : \u2200 X \u2208 Bloques, (X : set A).nonempty)\n(Hrecubren  : \u2200 a, \u2203 X \u2208 Bloques, a \u2208 X)\n(Hdisjuntos : \u2200 X Y \u2208 Bloques, (X \u2229 Y : set A).nonempty \u2192 X = Y)\n\nnamespace particion\n\nvariable  {A : Type}\nvariable  {P : particion A}\nvariables {X Y : set A}\n\nlemma iguales_si_comun\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  : X = Y :=\nHdisjuntos P X hX Y  hY \u27e8a, haX, haY\u27e9\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a b : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  (hbX : b \u2208 X)\n  : b \u2208 Y :=\nbegin\n  convert hbX,\n  apply iguales_si_comun hY hX haY,\n  exact haX,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a b : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  (hbX : b \u2208 X)\n  : b \u2208 Y :=\nbegin\n  have hXY : X = Y := iguales_si_comun hX hY haX haY,\n  rw \u2190 hXY,\n  exact hbX,\nend\n\n-- 3\u00aa demostraci\u00f3n\nlemma pertenece_si_pertenece\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a b : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  (hbX : b \u2208 X)\n  : b \u2208 Y :=\nbegin\n  convert hbX,\n  exact iguales_si_comun hY hX haY haX,\nend\n\nend particion\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Pertenencia_a_bloques_de_una_particion_con_elementos_comunes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406087, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.7303796006465315}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.complex.arg\nimport analysis.special_functions.log.basic\n\n/-!\n# The complex `log` function\n\nBasic properties, relationship with `exp`.\n-/\n\nnoncomputable theory\n\nnamespace complex\n\nopen set filter\n\nopen_locale real topology complex_conjugate\n\n/-- Inverse of the `exp` function. Returns values such that `(log x).im > - \u03c0` and `(log x).im \u2264 \u03c0`.\n  `log 0 = 0`-/\n@[pp_nodot] noncomputable def log (x : \u2102) : \u2102 := x.abs.log + arg x * I\n\nlemma log_re (x : \u2102) : x.log.re = x.abs.log := by simp [log]\n\nlemma log_im (x : \u2102) : x.log.im = x.arg := by simp [log]\n\nlemma neg_pi_lt_log_im (x : \u2102) : -\u03c0 < (log x).im := by simp only [log_im, neg_pi_lt_arg]\nlemma log_im_le_pi (x : \u2102) : (log x).im \u2264 \u03c0 := by simp only [log_im, arg_le_pi]\n\nlemma exp_log {x : \u2102} (hx : x \u2260 0) : exp (log x) = x :=\nby rw [log, exp_add_mul_I, \u2190 of_real_sin, sin_arg, \u2190 of_real_cos, cos_arg hx,\n  \u2190 of_real_exp, real.exp_log (abs.pos hx), mul_add, of_real_div, of_real_div,\n  mul_div_cancel' _ (of_real_ne_zero.2 $ abs.ne_zero hx), \u2190 mul_assoc,\n  mul_div_cancel' _ (of_real_ne_zero.2 $ abs.ne_zero hx), re_add_im]\n\n@[simp] lemma range_exp : range exp = {0}\u1d9c :=\nset.ext $ \u03bb x, \u27e8by { rintro \u27e8x, rfl\u27e9, exact exp_ne_zero x }, \u03bb hx, \u27e8log x, exp_log hx\u27e9\u27e9\n\nlemma log_exp {x : \u2102} (hx\u2081 : -\u03c0 < x.im) (hx\u2082: x.im \u2264 \u03c0) : log (exp x) = x :=\nby rw [log, abs_exp, real.log_exp, exp_eq_exp_re_mul_sin_add_cos, \u2190 of_real_exp,\n  arg_mul_cos_add_sin_mul_I (real.exp_pos _) \u27e8hx\u2081, hx\u2082\u27e9, re_add_im]\n\n\n\nlemma of_real_log {x : \u211d} (hx : 0 \u2264 x) : (x.log : \u2102) = log x :=\ncomplex.ext\n  (by rw [log_re, of_real_re, abs_of_nonneg hx])\n  (by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])\n\nlemma log_of_real_re (x : \u211d) : (log (x : \u2102)).re = real.log x := by simp [log_re]\n\nlemma log_of_real_mul {r : \u211d} (hr : 0 < r) {x : \u2102} (hx : x \u2260 0) :\n  log (r * x) = real.log r + log x :=\nbegin\n  replace hx := complex.abs.ne_zero_iff.mpr hx,\n  simp_rw [log, map_mul, abs_of_real, arg_real_mul _ hr, abs_of_pos hr, real.log_mul hr.ne' hx,\n    of_real_add, add_assoc],\nend\n\nlemma log_mul_of_real (r : \u211d) (hr : 0 < r) (x : \u2102) (hx : x \u2260 0) :\n  log (x * r) = real.log r + log x :=\nby rw [mul_comm, log_of_real_mul hr hx, add_comm]\n\n@[simp] lemma log_zero : log 0 = 0 := by simp [log]\n\n@[simp] lemma log_one : log 1 = 0 := by simp [log]\n\nlemma log_neg_one : log (-1) = \u03c0 * I := by simp [log]\n\nlemma log_I : log I = \u03c0 / 2 * I := by simp [log]\n\nlemma log_neg_I : log (-I) = -(\u03c0 / 2) * I := by simp [log]\n\nlemma log_conj_eq_ite (x : \u2102) :\n  log (conj x) = if x.arg = \u03c0 then log x else conj (log x) :=\nbegin\n  simp_rw [log, abs_conj, arg_conj, map_add, map_mul, conj_of_real],\n  split_ifs with hx,\n  { rw hx },\n  simp_rw [of_real_neg, conj_I, mul_neg, neg_mul]\nend\n\nlemma log_conj (x : \u2102) (h : x.arg \u2260 \u03c0) : log (conj x) = conj (log x) :=\nby rw [log_conj_eq_ite, if_neg h]\n\nlemma log_inv_eq_ite (x : \u2102) : log (x\u207b\u00b9) = if x.arg = \u03c0 then -conj (log x) else -log x :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx] },\n  rw [inv_def, log_mul_of_real, real.log_inv, of_real_neg, \u2190sub_eq_neg_add, log_conj_eq_ite],\n  { simp_rw [log, map_add, map_mul, conj_of_real, conj_I, norm_sq_eq_abs, real.log_pow,\n      nat.cast_two, of_real_mul, of_real_bit0, of_real_one, neg_add, mul_neg, two_mul, neg_neg],\n    split_ifs,\n    { rw [add_sub_right_comm, sub_add_cancel'] },\n    { rw [add_sub_right_comm, sub_add_cancel'] } },\n  { rwa [inv_pos, complex.norm_sq_pos] },\n  { rwa map_ne_zero },\nend\n\nlemma log_inv (x : \u2102) (hx : x.arg \u2260 \u03c0) : log (x\u207b\u00b9) = -log x :=\nby rw [log_inv_eq_ite, if_neg hx]\n\nlemma two_pi_I_ne_zero : (2 * \u03c0 * I : \u2102) \u2260 0 :=\nby norm_num [real.pi_ne_zero, I_ne_zero]\n\nlemma exp_eq_one_iff {x : \u2102} : exp x = 1 \u2194 \u2203 n : \u2124, x = n * ((2 * \u03c0) * I) :=\nbegin\n  split,\n  { intro h,\n    rcases exists_unique_add_zsmul_mem_Ioc real.two_pi_pos x.im (-\u03c0) with \u27e8n, hn, -\u27e9,\n    use -n,\n    rw [int.cast_neg, neg_mul, eq_neg_iff_add_eq_zero],\n    have : (x + n * (2 * \u03c0 * I)).im \u2208 Ioc (-\u03c0) \u03c0, by simpa [two_mul, mul_add] using hn,\n    rw [\u2190 log_exp this.1 this.2, exp_periodic.int_mul n, h, log_one] },\n  { rintro \u27e8n, rfl\u27e9, exact (exp_periodic.int_mul n).eq.trans exp_zero }\nend\n\nlemma exp_eq_exp_iff_exp_sub_eq_one {x y : \u2102} : exp x = exp y \u2194 exp (x - y) = 1 :=\nby rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]\n\nlemma exp_eq_exp_iff_exists_int {x y : \u2102} : exp x = exp y \u2194 \u2203 n : \u2124, x = y + n * ((2 * \u03c0) * I) :=\nby simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']\n\n@[simp] lemma countable_preimage_exp {s : set \u2102} : (exp \u207b\u00b9' s).countable \u2194 s.countable :=\nbegin\n  refine \u27e8\u03bb hs, _, \u03bb hs, _\u27e9,\n  { refine ((hs.image exp).insert 0).mono _,\n    rw [image_preimage_eq_inter_range, range_exp, \u2190 diff_eq, \u2190 union_singleton, diff_union_self],\n    exact subset_union_left _ _ },\n  { rw \u2190 bUnion_preimage_singleton,\n    refine hs.bUnion (\u03bb z hz, _),\n    rcases em (\u2203 w, exp w = z) with \u27e8w, rfl\u27e9|hne,\n    { simp only [preimage, mem_singleton_iff, exp_eq_exp_iff_exists_int, set_of_exists],\n      exact countable_Union (\u03bb m, countable_singleton _) },\n    { push_neg at hne, simp [preimage, hne] } }\nend\n\nalias countable_preimage_exp \u2194 _ _root_.set.countable.preimage_cexp\n\nlemma tendsto_log_nhds_within_im_neg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto log (\ud835\udcdd[{z : \u2102 | z.im < 0}] z) (\ud835\udcdd $ real.log (abs z) - \u03c0 * I) :=\nbegin\n  have := (continuous_of_real.continuous_at.comp_continuous_within_at\n    (continuous_abs.continuous_within_at.log _)).tendsto.add\n    (((continuous_of_real.tendsto _).comp $\n    tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),\n  convert this,\n  { simp [sub_eq_add_neg] },\n  { lift z to \u211d using him, simpa using hre.ne }\nend\n\nlemma continuous_within_at_log_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  continuous_within_at log {z : \u2102 | 0 \u2264 z.im} z :=\nbegin\n  have := (continuous_of_real.continuous_at.comp_continuous_within_at\n    (continuous_abs.continuous_within_at.log _)).tendsto.add\n    ((continuous_of_real.continuous_at.comp_continuous_within_at $\n    continuous_within_at_arg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),\n  convert this,\n  { lift z to \u211d using him, simpa using hre.ne }\nend\n\nlemma tendsto_log_nhds_within_im_nonneg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto log (\ud835\udcdd[{z : \u2102 | 0 \u2264 z.im}] z) (\ud835\udcdd $ real.log (abs z) + \u03c0 * I) :=\nby simpa only [log, arg_eq_pi_iff.2 \u27e8hre, him\u27e9]\n  using (continuous_within_at_log_of_re_neg_of_im_zero hre him).tendsto\n\n@[simp] lemma map_exp_comap_re_at_bot : map exp (comap re at_bot) = \ud835\udcdd[\u2260] 0 :=\nby rw [\u2190 comap_exp_nhds_zero, map_comap, range_exp, nhds_within]\n\n@[simp] lemma map_exp_comap_re_at_top : map exp (comap re at_top) = comap abs at_top :=\nbegin\n  rw [\u2190 comap_exp_comap_abs_at_top, map_comap, range_exp, inf_eq_left, le_principal_iff],\n  exact eventually_ne_of_tendsto_norm_at_top tendsto_comap 0\nend\n\nend complex\n\nsection log_deriv\n\nopen complex filter\nopen_locale topology\n\nvariables {\u03b1 : Type*}\n\nlemma continuous_at_clog {x : \u2102} (h : 0 < x.re \u2228 x.im \u2260 0) :\n  continuous_at log x :=\nbegin\n  refine continuous_at.add _ _,\n  { refine continuous_of_real.continuous_at.comp _,\n    refine (real.continuous_at_log _).comp complex.continuous_abs.continuous_at,\n    rw complex.abs.ne_zero_iff,\n    rintro rfl,\n    simpa using h },\n  { have h_cont_mul : continuous (\u03bb x : \u2102, x * I), from continuous_id'.mul continuous_const,\n    refine h_cont_mul.continuous_at.comp (continuous_of_real.continuous_at.comp _),\n    exact continuous_at_arg h, },\nend\n\nlemma filter.tendsto.clog {l : filter \u03b1} {f : \u03b1 \u2192 \u2102} {x : \u2102} (h : tendsto f l (\ud835\udcdd x))\n  (hx : 0 < x.re \u2228 x.im \u2260 0) :\n  tendsto (\u03bb t, log (f t)) l (\ud835\udcdd $ log x) :=\n(continuous_at_clog hx).tendsto.comp h\n\nvariables [topological_space \u03b1]\n\nlemma continuous_at.clog {f : \u03b1 \u2192 \u2102} {x : \u03b1} (h\u2081 : continuous_at f x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_at (\u03bb t, log (f t)) x :=\nh\u2081.clog h\u2082\n\nlemma continuous_within_at.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} {x : \u03b1} (h\u2081 : continuous_within_at f s x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_within_at (\u03bb t, log (f t)) s x :=\nh\u2081.clog h\u2082\n\nlemma continuous_on.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} (h\u2081 : continuous_on f s)\n  (h\u2082 : \u2200 x \u2208 s, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_on (\u03bb t, log (f t)) s :=\n\u03bb x hx, (h\u2081 x hx).clog (h\u2082 x hx)\n\nlemma continuous.clog {f : \u03b1 \u2192 \u2102} (h\u2081 : continuous f) (h\u2082 : \u2200 x, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous (\u03bb t, log (f t)) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, h\u2081.continuous_at.clog (h\u2082 x)\n\nend log_deriv\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/complex/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7303469783488822}}
{"text": "-- * Level 1\nimport mynat.le\n\nlemma one_add_le_self (x : mynat) : x \u2264 1 + x :=\n\nbegin\n\nuse 1,\nrw add_comm,\n\nend\n\n-- * Level 2\nlemma le_refl (x : mynat) : x \u2264 x :=\n\nbegin\n\n\nuse 0,\nrefl\n\nend\n-- * Level 3\n\ntheorem le_succ (a b : mynat) : a \u2264 b \u2192 a \u2264 (succ b) :=\n\nbegin\n\nintro h,\nrw le_iff_exists_add at h \u22a2,\ncases h with c hc,\nuse c+1,\nrw succ_eq_add_one,\nrw hc,\nrefl,\n\nend\n\n-- * Level 4\n\nlemma zero_le (a : mynat) : 0 \u2264 a :=\n\nbegin\n\nrw le_iff_exists_add,\nuse a,\nrw zero_add,\nrefl,\n\n\nend\n\n-- * Level 5\ntheorem le_trans (a b c : mynat) (hab : a \u2264 b) (hbc : b \u2264 c) : a \u2264 c :=\nbegin\n\nrw le_iff_exists_add at hab hbc,\ncases hbc,\ncases hab,\nrw hab_h at hbc_h,\nuse hab_w + hbc_w,\nrw add_assoc at hbc_h,\napply hbc_h,\nend\n\n\n-- * Level 6\ntheorem le_antisymm (a b : mynat) (hab : a \u2264 b) (hba : b \u2264 a) : a = b :=\n\nbegin\n\ncases hab,\ncases hba,\nrw hab_h at hba_h,\nrw add_assoc at hba_h,\nsymmetry at hba_h,\nhave h := eq_zero_of_add_right_eq_self hba_h,\nhave g := add_right_eq_zero(h),\nrw g at hab_h,\nrw add_zero at hab_h,\nsymmetry at hab_h,\nexact hab_h,\n\n\nend\n\n-- * Level 7\nlemma le_zero (a : mynat) (h : a \u2264 0) : a = 0 :=\n\n\nbegin\n\ncases h,\nsymmetry at h_h,\nexact add_right_eq_zero(h_h),\n\nend\n-- * Level 8\nlemma succ_le_succ (a b : mynat) (h : a \u2264 b) : succ a \u2264 succ b :=\nbegin\nrw le_iff_exists_add at h,\ncases h,\nrepeat {rw succ_eq_add_one},\nrw h_h,\nrw add_right_comm,\nrw le_iff_exists_add,\nuse h_w,\nrefl,\nend\n-- * Level 9\n-- couldnt do it\ntheorem le_total (a b : mynat) : a \u2264 b \u2228 b \u2264 a :=\nbegin\nsorry\nend\n\n-- * Level 10\nlemma le_succ_self (a : mynat) : a \u2264 succ a :=\n\n\nbegin\napply le_succ,\nexact le_refl a,\nend\n\n-- * Level 11\n\ntheorem add_le_add_right {a b : mynat} : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) :=\n\n\nbegin\nintro h,\nintro t,\nrw le_iff_exists_add ,\nrw le_iff_exists_add at h,\ncases h,\nuse h_w,\nrw h_h,\nrw add_right_comm,\nrefl,\nend\n\n-- * Level 12\ntheorem le_of_succ_le_succ (a b : mynat) : succ a \u2264 succ b \u2192 a \u2264 b :=\nbegin\nintro h,\nrw le_iff_exists_add at h,\ncases h,\nrw le_iff_exists_add,\nuse h_w,\nrw succ_add at h_h,\nhave foo:= succ_inj(h_h),\nexact foo,\nend\n\n-- * Level 13\ntheorem not_succ_le_self (a : mynat) : \u00ac (succ a \u2264 a) :=\n\n\nbegin\n\nintro h,\nrw le_iff_exists_add at h,\ncases h,\ninduction a,\nrw succ_add at h_h,\nrw zero_add at h_h,\nsymmetry at h_h,\nhave foo :=  succ_ne_zero h_w,\nexact foo h_h,\nrw succ_add at h_h,\nhave foo2 := succ_inj(h_h),\nexact a_ih(foo2),\n\n\nend\n\n-- * Level 14\n\ntheorem add_le_add_left {a b : mynat} (h : a \u2264 b) (t : mynat) :\n  t + a \u2264 t + b :=\n\n\nbegin\n\ncases h,\nuse h_w,\nrw h_h,\nrw add_assoc,\nrefl,\n\nend\n\n-- * Level 15\nlemma lt_aux_one (a b : mynat) : a \u2264 b \u2227 \u00ac (b \u2264 a) \u2192 succ a \u2264 b :=\n\n\nbegin\n\nintro h,\ncases h with r l,\ncases r with f1 f2,\ncases f1,\nrw add_zero at f2,\nexfalso,\napply l,\nrw f2,\n\napply le_refl a,\nrw le_iff_exists_add,\nrw add_succ at  f2,\nuse f1,\nrw succ_add,\napply f2,\n\nend\n\n-- * Level 16\nlemma lt_aux_two (a b : mynat) : succ a \u2264 b \u2192 a \u2264 b \u2227 \u00ac (b \u2264 a) :=\n\n\nbegin\n\nintro h,\nsplit,\nrw le_iff_exists_add at h,\nrw le_iff_exists_add,\ncases h,\nrw \u2190 add_one_eq_succ at h_h,\nrw add_assoc at h_h,\nuse (1 + h_w),\nexact h_h,\nby_contra h2,\nhave foo3 := le_trans (succ a) b a h h2,\nhave foo4 := not_succ_le_self a,\nexact foo4(foo3),\n\nend\n-- * Level 17\n\nlemma lt_iff_succ_le (a b : mynat) : a < b \u2194 succ a \u2264 b :=\nbegin\n\nsplit,\nexact lt_aux_one a b,\nexact lt_aux_two a b,\n\n\nend\n", "meta": {"author": "marcelovmaciel", "repo": "learning_lean", "sha": "0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4", "save_path": "github-repos/lean/marcelovmaciel-learning_lean", "path": "github-repos/lean/marcelovmaciel-learning_lean/learning_lean-0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4/nngame/inequality_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.730346961455487}}
{"text": "import data.rat\n\ndef is_regular_sequence(seq: \u2115 \u2192 \u211a) :=\n  \u2200 {m n: \u2115}, (0 < m) \u2192 (0 < n) \u2192 |seq m - seq n| \u2264 (m : \u211a)\u207b\u00b9 + (n : \u211a)\u207b\u00b9\n\ndef regular_sequence := {f: \u2115 \u2192 \u211a // is_regular_sequence f}\n\nnamespace regular_sequence\n\ninstance : has_coe_to_fun regular_sequence (\u03bb _, \u2115 \u2192 \u211a) :=\n  \u27e8subtype.val\u27e9\n \n@[simp] theorem mk_to_fun (f) (hf : is_regular_sequence f) :\n  @coe_fn regular_sequence _ _ \u27e8f, \u03bb x y, hf\u27e9 = f := rfl\n\n@[simp] lemma fn_apply (a: regular_sequence) (n) : a n = a.val n := rfl\n\ntheorem ext {f g : regular_sequence} (h : \u2200 i, f i = g i) : f = g :=\n  subtype.eq (funext h)\n \ntheorem is_reg_seq (f : regular_sequence) : is_regular_sequence f.val := f.property\n\n/-The constant regular sequence-/\ndef const(x: \u211a): regular_sequence :=\n  { val := \u03bb n, x,\n    property := \u03bb m n m_pos n_pos, let h1 := (@inv_pos _ _ (m : \u211a)).2 (nat.cast_pos.2 m_pos), \n        h2 := (@inv_pos _ _ (n : \u211a)).2 (nat.cast_pos.2 n_pos), \n        h := le_of_lt (add_pos h1 h2) in by rwa [sub_self, abs_zero] }\n\ninstance : has_zero regular_sequence :=\n  \u27e8const 0\u27e9\n\ninstance : has_one regular_sequence :=\n  \u27e8const 1\u27e9\n\ninstance : inhabited regular_sequence :=\n  \u27e80\u27e9\n\ndef equivalent(a b: regular_sequence) :=\n  \u2200 {n : \u2115}, 0 < n \u2192 |a n - b n| \u2264 2 * (n : \u211a)\u207b\u00b9\n\nlemma equivalent_refl: reflexive equivalent :=\n  \u03bb n h_n, by {simp,}\n\n/-- `lim_zero f` holds when `f` approaches 0. -/\ndef lim_zero (f : regular_sequence) := (\u2200 (j: \u2115), 0 < j \u2192 \u2203 N, \u2200 n \u2265 N, | f n | \u2264 (j: \u211a)\u207b\u00b9)\n\nlemma equivalent_symm : symmetric regular_sequence.equivalent :=\n  \u03bb _ _ h_eq _ h_n, let h := h_eq h_n in by rwa [\u2190abs_neg, neg_sub]\n\nlemma equivalent_iff' {a b: regular_sequence}: \n    (equivalent a b) \u2194 (\u2200 j: \u2115, 0 < j \u2192 \u2203 Nj, \u2200 n \u2265 Nj, |a n - b n| \u2264 (j : \u211a)\u207b\u00b9) :=\n  begin\n    split,\n    { intros h_eq j j_pos,\n      use 2 * j,\n      intros n n_ge_two_j,\n      have j_le_2j: j \u2264 2 * j := (le_mul_iff_one_le_left j_pos).2 one_le_two,\n      have n_pos := gt_of_ge_of_gt n_ge_two_j (gt_of_ge_of_gt j_le_2j j_pos),\n      have hn2n : n \u2264 2 * n,\n      {\n        obtain h := mul_le_mul one_le_two rfl.ge (zero_le n) (zero_le 2),\n        rwa one_mul at h,\n      },\n      have n2_pos := gt_of_ge_of_gt hn2n n_pos,\n      specialize h_eq n_pos,\n      have n_inv_pos: 0 < (n : \u211a)\u207b\u00b9, by rwa [inv_pos, nat.cast_pos],\n      haveI := rat.nontrivial,\n      have ninv_lt_2jinv : (n : \u211a)\u207b\u00b9 \u2264 (2*j)\u207b\u00b9,\n      {\n        rw inv_le_inv,\n        norm_cast,\n        exact n_ge_two_j,\n        exact nat.cast_pos.2 n_pos,\n        exact (@zero_lt_mul_left _ _  (j : \u211a) 2 zero_lt_two).2 (nat.cast_pos.2 j_pos),\n      },\n      calc |a n - b n | \u2264 2*(\u2191n)\u207b\u00b9 : h_eq\n                   ... \u2264 2*(2*j)\u207b\u00b9 : by rwa @mul_le_mul_left _ _ (n : \u211a)\u207b\u00b9 (2*j)\u207b\u00b9 2 zero_lt_two\n                   ... = (\u2191j)\u207b\u00b9 :  by { rw [mul_inv\u2080], ring}\n    },\n    { \n      intros h_eq n n_pos,\n      have key: \u2200 j: \u2115, 0 < j \u2192 |a n - b n| \u2264 2*(n: \u211a)\u207b\u00b9 + 3 * (j: \u211a)\u207b\u00b9,\n      {\n        intros j j_pos,\n        obtain \u27e8Nj, h_Nj\u27e9  := h_eq j j_pos,\n        set m := max j Nj with hm,\n        have m_pos := gt_of_ge_of_gt (le_max_left j Nj) j_pos,\n        have inv_m_leq_inv_j : 2*(m : \u211a)\u207b\u00b9 \u2264 2*(j : \u211a)\u207b\u00b9,\n        {\n          simp only [mul_le_mul_left, nat.cast_max, zero_lt_bit0, zero_lt_one],\n          obtain m_rat_pos := @lt_max_of_lt_left _ _ 0 (j : \u211a) (Nj : \u211a) (nat.cast_pos.mpr j_pos),\n          rw inv_le_inv m_rat_pos (nat.cast_pos.mpr j_pos),\n          norm_cast,\n          exact le_max_left j Nj,\n        },\n        calc |a n - b n| = |(a n - a m) + ((a m - b m) + (b m - b n))| : by ring_nf\n                     ... \u2264 |a n - a m| + |(a m - b m) + (b m - b n)| : abs_add _ _\n                     ... \u2264 |a n - a m| + (|a m - b m| + |b m - b n|) : add_le_add_left (abs_add _ _) _\n                     ... \u2264 ((n: \u211a)\u207b\u00b9 + (m: \u211a)\u207b\u00b9) + ((j: \u211a)\u207b\u00b9 + ((m: \u211a)\u207b\u00b9 + (n: \u211a)\u207b\u00b9) ): by exact add_le_add (a.property n_pos m_pos) \n                                                                  (add_le_add (h_Nj m (le_max_right j Nj)) (b.property m_pos n_pos))\n                     ... = 2*(\u2191n)\u207b\u00b9 + 2 * (\u2191m)\u207b\u00b9 + (\u2191j)\u207b\u00b9 : by ring_nf\n                     ... \u2264 2*(\u2191n)\u207b\u00b9 + 2 * (\u2191j)\u207b\u00b9 + (\u2191j)\u207b\u00b9 : by exact add_le_add_right (add_le_add_left inv_m_leq_inv_j (2 * (\u2191n)\u207b\u00b9)) (\u2191j)\u207b\u00b9\n                     ... = 2*(\u2191n)\u207b\u00b9 + 3*(\u2191j)\u207b\u00b9: by ring_nf\n      },\n      apply le_of_forall_pos_le_add,\n      intros \u03b5 \u03b5_pos,\n      have h1: \u2191(int.floor ((3:\u211a)/\u03b5))+1 > 3/\u03b5,\n      {\n        obtain h := rat.num_lt_succ_floor_mul_denom ((3:\u211a)/\u03b5),\n        apply rat.lt_def.2,\n        norm_cast,\n        simp[h],\n      },\n      have hh1 := nat.lt_succ_floor (3 / \u03b5),\n      have h2 : (\u2191(int.to_nat (int.floor ((3:\u211a)/\u03b5)))+1)\u207b\u00b9 < (3/\u03b5)\u207b\u00b9,\n      {        \n        exact (@inv_lt_inv \u211a _ _ _ (\u230a3 / \u03b5\u230b.to_nat.cast_add_one_pos) \n            (div_pos zero_lt_three \u03b5_pos)).2 hh1,\n      },\n      apply le_of_lt,\n      have : \u2203 j: \u2115, 0 < j \u2227 3*(j: \u211a)\u207b\u00b9 < \u03b5,\n      {\n        use  int.to_nat (int.floor ((3/\u03b5)))+1,\n        split,\n        {\n          exact fin.last_pos,\n        },\n        {\n          calc 3 * (\u2191(int.to_nat (rat.floor ((3:\u211a)/\u03b5)))+1)\u207b\u00b9 < 3* (3/\u03b5)\u207b\u00b9 : mul_lt_mul_of_pos_left h2 zero_lt_three\n              ... = 3 * (\u03b5/3) : by rw inv_div \n              ... = \u03b5 : by ring_nf\n        }\n      },\n      obtain \u27e8j, j_pos, j_lt_\u03b5\u27e9 := this,\n      specialize key j j_pos,\n      calc |a n - b n| \u2264 2 * (\u2191n)\u207b\u00b9 + 3 * (\u2191j)\u207b\u00b9 : key\n                   ... < 2 * (\u2191n)\u207b\u00b9 + \u03b5 : add_lt_add_left j_lt_\u03b5 _\n    },\n  end\n\nlemma lim_zero_of_equiv{a b : regular_sequence}(hab: equivalent a b)(a_lim_zero: lim_zero a): lim_zero b :=\nbegin\n  rw equivalent_iff' at *,\n  unfold lim_zero at *,\n  intros j hj,\n  obtain h2j_pos := nat.succ_mul_pos 1 hj,\n  obtain \u27e8N\u2081, hN\u2081\u27e9 := a_lim_zero (2*j) h2j_pos,\n  obtain \u27e8N\u2082, hN\u2082\u27e9 := hab (2*j) h2j_pos,\n  use max N\u2081 N\u2082,\n  intros n hn,  \n  specialize hN\u2081 n (le_of_max_le_left hn),\n  specialize hN\u2082 n (le_of_max_le_right hn),\n  have h2jNQ : (\u2191(2 * j))\u207b\u00b9 = (((2 : \u211a) * \u2191j))\u207b\u00b9 := by rw [nat.cast_mul, nat.cast_two],\n  calc |b n| = |b n - a n + a n| : by ring_nf\n  ... \u2264 |b n - a n| + |a n| : abs_add _ _\n  ... = |a n - b n| + |a n| : by  rw [\u2190abs_neg, neg_sub]\n  ... \u2264 (2 * j)\u207b\u00b9 + (2 * j)\u207b\u00b9: add_le_add (by rwa \u2190 h2jNQ) (by rwa \u2190 h2jNQ)\n  ... = (\u2191j)\u207b\u00b9 : by {ring_nf, rw mul_inv\u2080, simp,},\nend\n\nlemma equivalent_trans: transitive regular_sequence.equivalent :=\n  begin\n    intros a b c h_eq_ab h_eq_bc,\n    rw regular_sequence.equivalent_iff' at *,\n    intros j j_pos,\n    have two_j_pos: 2 * j > 0,\n      { exact nat.succ_mul_pos 1 j_pos },\n    specialize h_eq_ab (2*j) two_j_pos,\n    specialize h_eq_bc (2*j) two_j_pos,\n    obtain \u27e8N, h_N\u27e9 := h_eq_ab,\n    obtain \u27e8M, h_M\u27e9 := h_eq_bc,\n    use max N M,\n    intros n n_ge_max,\n    have n_ge_N: n \u2265 N,\n      { exact le_of_max_le_left n_ge_max },\n    have n_ge_M: n \u2265 M,\n      { exact le_of_max_le_right n_ge_max },\n\n    specialize h_N n n_ge_N, \n    specialize h_M n n_ge_M, \n\n    calc |a n - c n| \u2264 |(a n - b n) + (b n - c n)| : by simp\n                 ... \u2264 |a n - b n| + |b n - c n| : abs_add _ _\n                 ... \u2264 (\u2191(2*j))\u207b\u00b9 + (\u2191(2*j))\u207b\u00b9 : add_le_add h_N h_M\n                 ... = (j: \u211a)\u207b\u00b9 : by { push_cast, rw mul_inv\u2080, ring}\n  end\n\ninstance equiv: setoid regular_sequence :=\n  setoid.mk equivalent \u27e8equivalent_refl, equivalent_symm, equivalent_trans\u27e9\n\n\nlemma equivalent_iff {a b: regular_sequence}: \n    (a \u2248 b) \u2194 (\u2200 j: \u2115, 0 < j \u2192 \u2203 Nj, \u2200 n \u2265 Nj, |a n - b n| \u2264 (j : \u211a)\u207b\u00b9) :=\n  equivalent_iff'\n\n\nend regular_sequence", "meta": {"author": "Eloitor", "repo": "Constructive-Analysis-in-Lean", "sha": "5aab8143b2d6b3d7e190de91a55fed3faf596bf7", "save_path": "github-repos/lean/Eloitor-Constructive-Analysis-in-Lean", "path": "github-repos/lean/Eloitor-Constructive-Analysis-in-Lean/Constructive-Analysis-in-Lean-5aab8143b2d6b3d7e190de91a55fed3faf596bf7/src/regular_sequence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7303469591332558}}
{"text": "import combinatorics.quiver.basic\nimport combinatorics.quiver.path\nimport order.category.FinPartialOrder\nimport order.cover\n\nimport finite\n\nnamespace hasse\n\nuniverse u\n\n-- 1.1.2 (Hasse diagram)\ninstance hasse (P : FinPartialOrder) : quiver P := { hom := \u03bb y x, x \u22d6 y }\n\nopen quiver\n\nvariable {P : FinPartialOrder}\n\nlemma eq_of_between_cov_right {x y z : P} (hcov : x \u22d6 y) (hlt : x < z) (hle : z \u2264 y) : z = y :=\nbegin\n  cases covby.eq_or_eq hcov (le_of_lt hlt) (hle),\n  { rw h at hlt, \n    exfalso,\n    apply lt_irrefl x hlt },\n  { exact h } \nend\n\nlemma eq_of_between_cov_left {x y z : P} (hcov : x \u22d6 y) (hlt : z < y) (hle : x \u2264 z) : x = z :=\nbegin\n  by_contra' h,\n  apply hcov.right (lt_of_le_of_ne hle h) hlt \nend\n\nlemma covby_of_eq {x y : P} (hlt : x < y) (h : \u2200 z, x < z \u2192 z \u2264 y \u2192 z = y) : x \u22d6 y :=\nbegin\n  apply covby_of_eq_or_eq hlt,\n  intros z hx hy,\n  rw le_iff_lt_or_eq at hx,\n  cases hx,\n  { right,\n    apply h z hx hy },\n  { left, exact hx.symm }\nend\n\ninstance subsingleton_hom_set (x y : P) : subsingleton (x \u27f6 y) :=\nbegin\n  apply subsingleton.intro, intros e e',\n  refl\nend\n\ndef hom_of_cov {x y : P} (hcov : y \u22d6 x) : x \u27f6 y := hcov\ndef path_of_cov {x y : P} (hcov : y \u22d6 x) : path x y := hom.to_path (hom_of_cov hcov)\ndef cov_of_hom {x y : P} (f : x \u27f6 y) : y \u22d6 x := f\n\nlemma le_of_path {x y : P} (p : path y x) : x \u2264 y :=\nbegin\n  induction p with w z p h h1,\n  { refl },\n  { apply le_of_lt, \n    apply has_lt.lt.trans_le (covby.lt (cov_of_hom h)) h1  }\nend\n\nlemma lt_of_path {x y : P} (hneq : x \u2260 y) (p : path y x) : x < y :=\nbegin \n  rw lt_iff_le_and_ne,\n  exact and.intro (le_of_path p) hneq\nend\n\nlemma covby_of_length_one  {x y : P} (p : path y x) (hl : p.length = 1) : x \u22d6 y :=\nbegin\n  cases p with w _ p q,\n  { rw path.length_nil at hl, linarith },\n  { rw [path.length_cons, add_left_eq_self] at hl,  \n    rw path.eq_of_length_zero p hl,\n    exact cov_of_hom q }\nend\n\n-- Two lemmas, if we have two elements one smaller than the other,\n-- we can consider an element in between that either cover the smaller\n-- or is covered by the larger\nlemma exists_right_cov_of_lt {x x' : P} (hle : x < x') : \u2203 y, x \u22d6 y \u2227 y \u2264 x' :=\nbegin\n  rw \u2190finite.greater_iff_in_greater at hle,\n  exact finite.exists_cov_of_greater hle \nend\n\nlemma exists_left_cov_of_lt {x x' : P} (hle : x < x') : \u2203 y, x \u2264 y \u2227 y \u22d6 x' :=\nbegin\n  rw \u2190finite.smaller_iff_in_smaller at hle,\n  exact finite.exists_cov_of_smaller hle \nend\n\nlemma nil_of_path_to_self {x : P} (p : quiver.path x x) : p = path.nil :=\nbegin \n  cases p with y hp q e,\n  { refl },\n  { have lt := covby.lt e,\n    rw lt_iff_le_not_le at lt,\n    exfalso, exact lt.right (le_of_path q) }\nend\n\n-- Auxiliary results to prove that if x < y, then we have a path from y to x\nnamespace path_of_lt\nvariables {x y : P} \n\nnoncomputable\ndef next (xn : P) (hpath : \u2200 z : P, path z x \u2192 \u00acz = y) (hlt : xn < y) (p : path xn x) : \n  { x // xn \u22d6 x \u2227 x < y } :=\nbegin\n  let k := classical.indefinite_description _ (exists_right_cov_of_lt hlt),\n  use k.val,\n  apply and.intro k.prop.left,\n  by_cases heq : k.val = y,\n  { exfalso,\n    have hcov : xn \u22d6 y := \n    begin\n      rw \u2190heq, exact k.prop.left\n    end,\n    apply hpath _ (path.comp (path_of_cov hcov) p), \n    refl },\n    { rw lt_iff_le_and_ne,\n      exact and.intro k.prop.right heq }\nend\n\n-- A cool use of \u03a3-types\nnoncomputable\ndef path_seq (hpath : \u2200 z : P, path z x \u2192 \u00acz = y) (hlt : x < y) : \n  \u2115 \u2192 \u03a3 (w : P), { p : path w x // w < y }  \n| 0       := \u27e8x, \u27e8path.nil, hlt\u27e9\u27e9\n| (n + 1) := let v := (next (path_seq n).1 hpath (path_seq n).2.prop (path_seq n).2.val) in\n             \u27e8v.val, \u27e8path.comp (path_of_cov v.prop.left) (path_seq n).2.val, v.prop.right\u27e9\u27e9\n\n-- Now we forget some of the structure of the previous sequence \nnoncomputable\ndef path_seq_forget (hpath : \u2200 z : P, path z x \u2192 \u00acz = y) (hlt : x < y) : \n  \u2115 \u2192 P := \u03bb n, (path_seq hpath hlt n).1\n\n-- Tis sequence is increasing\nlemma path_seq_forget_cov_increasing (hpath : \u2200 z : P, path z x \u2192 \u00acz = y) (hlt : x < y) :\n  \u2200 n, path_seq_forget hpath hlt n \u22d6 path_seq_forget hpath hlt (n + 1) :=\nbegin\n  intro n,\n  unfold path_seq_forget path_seq, simp,\n  exact (next _ hpath (path_seq hpath hlt n).2.prop (path_seq hpath hlt n).2.val).prop.left\nend\n\nlemma path_seq_forget_increasing (hpath : \u2200 z : P, path z x \u2192 \u00acz = y) (hlt : x < y) :\n  \u2200 n, path_seq_forget hpath hlt n < path_seq_forget hpath hlt (n + 1) :=\nbegin\n  intro n,\n  apply covby.lt,\n  apply path_seq_forget_cov_increasing\nend\n\ndef path_of_lt {x y : P} (hlt : x < y) : \u2203 (z : P) (p : path z x), z = y :=\nbegin\n  by_contra' h,\n  apply finite.no_infinite_increasing_seq (path_of_lt.path_seq_forget h hlt),\n  apply path_of_lt.path_seq_forget_increasing\nend\n\nend path_of_lt\n\n-- This is the result,\n-- Highly nonconstructible\nnoncomputable\ndef path_of_lt {x y : P} (hlt : x < y) : path y x :=\nbegin\n  have p := classical.indefinite_description _ (path_of_lt.path_of_lt hlt),\n  simp at p,\n  have q := classical.indefinite_description _ p.prop,\n  rw \u2190q.prop,\n  exact q.val\nend\n\n\nlemma eq_of_double_covby {x y z : P} (h1 : x \u22d6 y) (h2 : x \u22d6 z) (hle : y \u2264 z) : y = z :=\neq_of_le_of_not_lt hle (h2.right h1.left)\n\nlemma eq_of_length_zero_int {x y : P} (p : path x y) (hzero : int.of_nat p.length = 0) : x = y :=\nbegin\n  apply path.eq_of_length_zero p,\n  rw int.coe_nat_inj hzero,\nend\n\nend hasse", "meta": {"author": "cchanavat", "repo": "diag-sets", "sha": "517db2372d001e00796f167eeb6b7080bd2a7d09", "save_path": "github-repos/lean/cchanavat-diag-sets", "path": "github-repos/lean/cchanavat-diag-sets/diag-sets-517db2372d001e00796f167eeb6b7080bd2a7d09/src/hasse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7302837784923326}}
{"text": "-- import .options\n\nset_option trace.simplify.rewrite true\n\ninductive palindrome {\u03b1 : Type} : list \u03b1 \u2192 Prop\n| nil : palindrome []\n| single (x : \u03b1) : palindrome [x]\n| sandwich (x : \u03b1) (xs : list \u03b1) (hxs : palindrome xs) :\n  palindrome ([x] ++ xs ++ [x])\n\nopen list\nvariable \u03b1 : Type\n\nlemma rev_core_nil {ys : list \u03b1} : reverse_core ys nil = reverse ys := by rw reverse\n\nset_option pp.generalized_field_notation false\n\nnamespace example_for_rev_append_cons\ndef ys := [1,2,3,4]\nconstant y : \u2115\nexample : reverse (y :: ys) = reverse ys ++ [y] := rfl\n-- GOAL: \u22a2 reverse (x :: xs ++ ys) = reverse ys ++ reverse (x :: xs)\nend example_for_rev_append_cons\n-- we have positive example means this lemma is potentially provable, and we can safely use sorry keyword\n\nlemma rev_append_cons (y : \u03b1) (ys : list \u03b1) : \n  reverse (y :: ys) = reverse ys ++ [y] :=\nbegin\n  induction ys,\n  case nil {\n    simp only [reverse, reverse_core, nil_append],\n    split; refl,\n  },\n  case cons : x ys ih {\n    sorry,\n  },\nend\n\n\nlemma reverse_append {xs ys : list \u03b1} :\n  reverse (xs ++ ys) = reverse ys ++ reverse xs :=\nbegin\n  induction xs,\n  case nil {\n    rw [nil_append, reverse]; simp,\n    rw [reverse_core, append_nil],\n  },\n  case cons : x xs ih {\n    rw cons_append,\n    iterate 2 { rw rev_append_cons },\n    rw [\u2190append_assoc, ih],\n  },\nend\n\nlemma reverse_palindrome (xs : list \u03b1)\n    (hxs : palindrome xs) :\n  palindrome (reverse xs) :=\nbegin\n  induction hxs,\n  case palindrome.nil { exact palindrome.nil },\n  case palindrome.single { exact palindrome.single hxs },\n  case palindrome.sandwich : x xs hxs ih {\n    simp only [reverse, reverse_append],\n    -- type_check palindrome.sandwich _ (reverse xs) ih, -- palindrome ([?m_1] ++ reverse xs ++ [?m_1])\n    exact palindrome.sandwich x (reverse xs) ih,\n  },\nend", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/palindromes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7302771475189163}}
{"text": "-- p q r s are used in all the examples so they are defined only here\nvariables p q r s : Prop\n\n-- Conjunction\n-- Prove p, q -> p \u2227 q\nexample (hp : p) (hq : q): p \u2227 q := and.intro hp hq\n-- Prove p \u2227 q -> q\nexample (h : p \u2227 q) : p := and.elim_left h\n-- Prove p \u2227 q -> p\nexample (h : p \u2227 q) : q := and.elim_right h\n\n-- Some examples of type assignment\nvariables (h : p) (i : q)\n#check and.elim_left \u27e8h, i\u27e9  \n#reduce and.elim_left \u27e8h, i\u27e9  \n#check and.elim_right \u27e8h, i\u27e9  \n#reduce and.elim_right \u27e8h, i\u27e9  \n\n#check (\u27e8h, i\u27e9 : p \u2227 q)  \n#reduce (\u27e8h, i\u27e9 : p \u2227 q)  \n\n\n-- Prove q \u2227 p \u2192 p \u2227 q\nexample (h : p \u2227 q) : q \u2227 p :=\nand.intro (and.elim_right h) (and.elim_left h)\n-- Lean allows us to use anonymous constructor notation \u27e8arg1, arg2, ...\u27e9\n-- In situations like these, when the relevant type is an inductive type and can be inferred from the context.\n-- In particular, we can often write \u27e8hp, hq\u27e9 instead of and.intro hp hq:\nexample (h : p \u2227 q) : q \u2227 p :=\n\u27e8and.elim_right h, and.elim_left h\u27e9\n\n-- More examples of using the constructor notation\nexample (h : p \u2227 q) : q \u2227 p \u2227 q:=\n\u27e8h.right, \u27e8h.left, h.right\u27e9\u27e9\n\nexample (h : p \u2227 q) : q \u2227 p \u2227 q:=\n\u27e8h.right, h.left, h.right\u27e9\n\n-- Disjunction\n-- \u2228 introduction left\nexample (hp : p): p \u2228 q := or.intro_left q hp\n-- \u2228 introduction right\nexample (hq : q): p \u2228 q := or.intro_right p hq\n\n-- Prove p \u2228 p \u2192 p\nexample (h: p \u2228 p): p :=\nor.elim h\n(assume hpr : p, show p, from hpr)\n(assume hpl : p, show p, from hpl)\n\n-- Prove p \u2228 p \u2192 p, simplified notation\nexample (h: p \u2228 p): p :=\nor.elim h\n(assume hpr : p, hpr)\n(assume hpl : p, hpl)\n\n-- Prove  p \u2228 q, p \u2192 r, q -> r, -> r\nexample (h : p \u2228 q) (i : p \u2192 r) (j : q -> r) : r :=\nor.elim h \n(assume hp : p, show r, from i hp)\n(assume hq : q, show r, from j hq)\n\n-- Prove p \u2228 q \u2192 q \u2228 p\nexample (h : p \u2228 q) : q \u2228 p :=\nor.elim h\n(assume hp : p, show q \u2228 p, from or.intro_right q hp)\n(assume hq : q, show q \u2228 p, from or.intro_left p hq)\n\n-- Modus tollens, deriving a contradiction from p to obtain false.\n-- Everything follows from false, in this case \u00acp\n-- order of propositions matters when using absurd\nexample (hpq : p \u2192 q) (hnq : \u00acq) : \u00acp :=\nassume hp : p, show false, from  hnq (hpq hp)\n\n-- Equivalent to the previous one\nexample (hpq : p \u2192 q) (hnq : \u00acq) : \u00acp :=\nassume hp : p, show false, from  false.elim (hnq (hpq hp))\n-- Equivalent to the previous one\nexample (hpq : p \u2192 q) (hnq : \u00acq) : \u00acp :=\nassume hp : p, show false, from  (hnq (hpq hp))\n\n-- More examples of false and absurd use\nexample (hp : p) (hnp : \u00acp) : q := false.elim (hnp hp)\n-- order of propositions matters when using absurd\nexample (hp : p) (hnp : \u00acp) : q := absurd hp hnp\n\n-- Prove \u00acp \u2192 q \u2192 (q \u2192 p) \u2192 r, premise \u00acp must be added\nexample (hnp : \u00acp) (hq : q) (hqp : q \u2192 p): r := \nfalse.elim (hnp (hqp hq))\n-- equivalent proove as the above \nexample (hnp : \u00acp) (hq : q) (hqp : q \u2192 p): r := \nabsurd (hqp hq) hnp\n\n-- Other variant from the above\n-- Prove \u00acp \u2192 q \u2192 (q \u2192 p) \u2192 r, premise \u00acp must be added\nexample (hnp : \u00ac p) (hnpq : \u00acp \u2192 q) (hqp : q \u2192 p): r := \nabsurd (hqp (hnpq hnp)) hnp\n\nexample (hnp : \u00ac p) (hnpq : \u00acp \u2192 q) (hqp : q \u2192 p): r := \nfalse.elim (hnp (hqp (hnpq hnp))) \n\n-- Prove p \u2227 q \u2194 q \u2227 p\nexample : (p \u2227 q) \u2194 (q \u2227 p) :=\niff.intro\n  (assume h : p \u2227 q,\n    show q \u2227 p,\n    from and.intro (and.elim_right h) (and.elim_left h))\n  (assume h : q \u2227 p,\n    show p \u2227 q,\n    from and.intro (and.elim_right h) (and.elim_left h))\n\n -- Derive q \u2227 p from p \u2227 q\n example (h : p \u2227 q) : (q \u2227 p) :=\n and.intro (and.elim_right h) (and.elim_left h)\n \n -- Define a theorem and use the anomimous constructor to prove p \u2227 q \u2194 q \u2227 p \n theorem and_swap : p \u2227 q \u2194 q \u2227 p :=\n\u27e8 \u03bb h, \u27e8h.right, h.left\u27e9, \u03bb h, \u27e8h.right, h.left\u27e9 \u27e9\n-- Prove, using and_swap theorem that p \u2227 q \u2192 q \u2227 p\nexample (h : p \u2227 q) : q \u2227 p := (and_swap p q).mp h\n\n-- Introducing auxiliary subgoals with `have`\nexample (h : p \u2227 q) : q \u2227 p :=\nhave hp : p, from and.left h,\nhave hq : q, from and.right h,\nshow q \u2227 p, from and.intro hq hp\n\n-- Introducing auxiliary subgoals with `suffices`\nexample (h : p \u2227 q) : q \u2227 p :=\nhave hp : p, from and.left h,\nsuffices hq : q, from and.intro hq hp,\nshow q, from and.right h\n\n\n-- Classical logic\n-- Prove double negation\n-- To use `em` we can invoke it using classical namespace like so: `classical.em`\n-- or import the classical module with 'open classical' and just use 'em' directly,\n-- no need to prefix it with namespace name\ntheorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\n  or.elim (classical.em p)\n    (assume hp : p, show p, from hp)\n    (assume hnp : \u00acp, show p, from absurd hnp h)\n\n-- Prove double negation, p is defined at the top of the file as p : Prop,\n-- so no need to add {p : Prop} to the premises\nexample (h : \u00ac\u00acp) : p :=\nor.elim (classical.em p)\n  (assume hp : p, show p, from hp)\n  (assume hnp : \u00acp, show p, from absurd hnp h)\n\n-- Proof by cases\nexample (h : \u00ac\u00acp) : p :=\nclassical.by_cases\n(assume h1 : p, h1)\n(assume h1 : \u00acp, absurd h1 h)\n\n-- Proof by contradiction\nexample (h : \u00ac\u00acp) : p :=\nclassical.by_contradiction\n(assume h1 : \u00acp, absurd h1 h)\n\nexample (h : \u00ac\u00acp) : p :=\nclassical.by_contradiction\n(assume h1 : \u00acp, show false, from h h1)\n\n-- Prove \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq\nexample (h : \u00ac(p \u2227 q)) : \u00acp \u2228 \u00acq :=\nor.elim (classical.em p)\n(assume hp : p,\n  or.inr (show \u00acq, from\n          assume hq : q,\n          h \u27e8hp, hq\u27e9))\n(assume hnp : \u00acp, show \u00acp \u2228 \u00acq, from or.inl hnp)\n\n-- Prove p \u2227 q \u2192 (p \u2192 q) :=\nexample : p \u2227 q \u2192 (p \u2192 q) :=\nassume hpq : p \u2227 q,\nassume hp : p, show q, from and.elim_right hpq\n\n-- Prove p \u2192 q \u2192 (p \u2227 q) :=\nexample : p \u2192 q \u2192 (p \u2227 q) :=\nassume hp : p,\nassume hq : q, show  p \u2227 q, from and.intro hp hq\n\n\n-- 3.6. Examples of Propositional Validities\n\n-- commutativity of \u2227 and \u2228\n\n-- Prove p \u2228 q \u2194 q \u2228 p\nexample : p \u2228 q \u2194 q \u2228 p :=\niff.intro\n(assume h : p \u2228 q, show q \u2228 p,\n  from or.elim h\n    (assume hp : p, show q \u2228 p, from or.intro_right q hp)\n    (assume hq : q, show q \u2228 p, from or.intro_left p hq))\n(assume h : q \u2228 p, show p \u2228 q,\n  from or.elim h\n    (assume hq : q, show p \u2228 q, from or.intro_right p hq)\n    (assume hp : p, show p \u2228 q, from or.intro_left q hp))\n\n-- Associativity of \u2227 and \u2228 --\n-- Prove (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r)\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\niff.intro\n  (assume hpqr : (p \u2227 q) \u2227 r, show p \u2227 (q \u2227 r), from\n    \u27e8hpqr.left.left, \u27e8hpqr.left.right, hpqr.right\u27e9\u27e9)\n  (assume hpqr : p \u2227 (q \u2227 r), show (p \u2227 q) \u2227 r, from\n    \u27e8\u27e8hpqr.left, hpqr.right.left\u27e9, hpqr.right.right\u27e9)\n\n-- Prove (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r)\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\niff.intro\n  (assume hpqr : (p \u2228 q) \u2228 r, show p \u2228 (q \u2228 r), from\n    or.elim hpqr\n      (assume hpq : p \u2228 q, show p \u2228 (q \u2228 r), from\n        or.elim hpq\n        (assume hp : p, show p \u2228 (q \u2228 r), from or.inl hp)\n        (assume hq : q, show p \u2228 (q \u2228 r), from or.inr (or.inl hq)))\n      (assume hr : r, show p \u2228 (q \u2228 r), from or.inr (or.inr hr)))\n  (assume hpqr : p \u2228 (q \u2228 r), show (p \u2228 q) \u2228 r, from\n    or.elim hpqr\n    (assume hp : p, show (p \u2228 q) \u2228 r, from or.inl (or.inl hp))\n    (assume hqr : q \u2228 r, show (p \u2228 q) \u2228 r, from or.elim hqr\n      (assume hq: q, show (p \u2228 q) \u2228 r, from or.inl (or.inr hq ))\n      (assume hr : r, show (p \u2228 q) \u2228 r, from or.inr hr)))\n\n-- Distributivity --\n-- Prove p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r)\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\niff.intro\n  (assume h : p \u2227 (q \u2228 r),\n    have hp : p, from h.left,\n    or.elim (h.right)\n      (assume hq : q,\n        show (p \u2227 q) \u2228 (p \u2227 r), from or.inl \u27e8hp, hq\u27e9)\n      (assume hr : r,\n        show (p \u2227 q) \u2228 (p \u2227 r), from or.inr \u27e8hp, hr\u27e9))\n  (assume h : (p \u2227 q) \u2228 (p \u2227 r),\n   or.elim h\n   (assume hpq : (p \u2227 q),\n     show p \u2227 (q \u2228 r), from and.intro hpq.left (or.inl hpq.right))\n   (assume hpr : (p \u2227 r),\n      show p \u2227 (q \u2228 r), from and.intro hpr.left (or.inr hpr.right)))\n\n-- Prove p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := sorry\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := \niff.intro\n(assume h: p \u2228 (q \u2227 r),\n  show (p \u2228 q) \u2227 (p \u2228 r), \n  from or.elim h\n  (assume hp: p, show (p \u2228 q) \u2227 (p \u2228 r), from \u27e8or.inl hp, or.inl hp\u27e9)\n  (assume hqr: (q \u2227 r), show (p \u2228 q) \u2227 (p \u2228 r), from \u27e8or.inr hqr.left, or.inr hqr.right\u27e9))\n(assume h: (p \u2228 q) \u2227 (p \u2228 r),\n  show p \u2228 (q \u2227 r), \n  from  or.elim (h.left)\n  (assume hp : p, show p \u2228 (q \u2227 r), from or.inl hp)\n  (assume hq : q, show p \u2228 (q \u2227 r), from or.elim h.right\n    (assume hp : p, show p \u2228 (q \u2227 r), from or.inl hp)\n    (assume hr : r, show p \u2228 (q \u2227 r), from or.inr \u27e8hq, hr\u27e9)\n   ))\n\n-- Other properties\n-- Prove (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r)\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\niff.intro\n(assume hpqr : p \u2192 (q \u2192 r), show p \u2227 q \u2192 r, from\n  (assume hpq : p \u2227 q,\n    have hp : p, from hpq.left,\n    have hq : q, from hpq.right,\n    show r, from (hpqr hp) hq))\n(assume hpqr : (p \u2227 q \u2192 r), show (p \u2192 (q \u2192 r)), from\n  (assume hp : p, show q \u2192 r, from\n    (assume hq, show r, from (hpqr \u27e8hp, hq\u27e9))))\n\n-- Prove ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r)\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := \niff.intro\n(assume hpqr : (p \u2228 q) \u2192 r, show (p \u2192 r) \u2227 (q \u2192 r), from \n  \u27e8(assume hp : p, show r, from hpqr(or.inl hp)), \n   (assume hq : q, show r, from hpqr(or.inr hq))\u27e9) \n(assume hprqr : (p \u2192 r) \u2227 (q \u2192 r), show (p \u2228 q) \u2192 r, from\n  (assume hpq : p \u2228 q, show r, from\n    or.elim hpq\n    (assume hp : p, show r, from hprqr.left hp)\n    (assume hq : q, show r, from hprqr.right hq)\n  )\n)\n\n-- Prove \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := sorry\nexample (p q : Prop) : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n\u27e8\u03bb h, \u27e8\u03bb hp, h (or.inl hp), \u03bb hq, h (or.inr hq)\u27e9, \n  \u03bb hn h, or.elim h hn.1 hn.2\u27e9\n\n-- Another proof for \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := sorry\nexample (p q : Prop) : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\niff.intro\n(assume hnpq : \u00ac(p \u2228 q), show \u00acp \u2227 \u00acq, from\n  and.intro\n  (assume hp : p, show false, from hnpq (or.inl hp))\n  (assume hq : q, show false, from hnpq (or.inr hq))) \n(assume (hnpnq : \u00acp \u2227 \u00acq),\n show \u00ac(p \u2228 q), from\n  assume hnpq : p \u2228 q, show false, from\n   or.elim hnpq (and.left hnpnq) (and.right hnpnq))\n\n-- Prove \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := sorry\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n(assume hnpnq : \u00acp \u2228 \u00acq,\n assume hpq : p \u2227 q,\n  show false, from\n  (or.elim hnpnq\n    (assume hnp : \u00acp, show false, from hnp (and.left hpq))\n    (assume hnq : \u00acq, show false, from hnq (and.right hpq))\n  )\n)\n\n-- Prove \u00ac(p \u2227 \u00acp) := sorry\nexample : \u00ac(p \u2227 \u00acp) :=\nassume h : p \u2227 \u00acp,\nshow false, from h.right h.left\n\nexample : \u00ac(p \u2227 \u00acp) :=\nassume h,\nabsurd h.left h.right\n\n-- Prove p \u2227 \u00acq \u2192 \u00ac(p \u2192 q)\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\nassume hpnq : p \u2227 \u00ac q,\nassume hpq : p \u2192 q,\nabsurd (hpq hpnq.left) hpnq.right\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\nassume hpnq : p \u2227 \u00ac q,\nassume hpq : p \u2192 q,\nshow false, from hpnq.right (hpq hpnq.left)\n\n-- Prove \u00acp \u2192 (p \u2192 q) := sorry\nexample : \u00acp \u2192 (p \u2192 q) :=\nassume hnp,\nassume hp,\nabsurd hp hnp\n\nexample : \u00acp \u2192 (p \u2192 q) :=\nassume hnp,\nassume hp,\nshow q , from absurd hp hnp\n\nexample : \u00acp \u2192 (p \u2192 q) :=\nassume hp,\nassume hnp,\nshow q , from false.elim(hp hnp)\n\n-- Prove (\u00acp \u2228 q) \u2192 (p \u2192 q)\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := \n(assume hnpq : \u00acp \u2228 q,\nor.elim hnpq\n(assume hnp : \u00acp, \n assume hp : p,\n show q, from absurd hp hnp)\n(assume hq : q, \n assume hp : p,\n show q, from hq))\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := \n(assume hnpq : \u00acp \u2228 q,\nor.elim hnpq\n(assume hnp : \u00acp, \n assume hp : p,\n show q, from false.elim (hnp hp))\n(assume hq : q, \n assume hp : p,\n show q, from hq))\n\n-- Prove p \u2228 false \u2194 p\nexample : p \u2228 false \u2194 p :=\niff.intro\n(assume hpf,\nor.elim hpf \n  (assume hp, show p, from hp)\n  (assume false, show p, from false.elim))\n(assume hp, \n show p \u2228 false, from or.inl hp)\n\n -- Prove p \u2227 false \u2194 false\nexample : p \u2227 false \u2194 false :=\niff.intro\n(assume hpf,\nshow false, from hpf.right)\n(assume hf,\nshow p \u2227 false, from and.intro (show p, from hf.elim) hf)\n\n-- Prove \u00ac(p \u2194 \u00acp)\nexample : \u00ac(p \u2194 \u00acp) :=\nassume hpnp,\nhave hnp : \u00ac p, from\n  assume hp : p, show false, from (hpnp.elim_left hp) hp,\nshow false, from hnp (hpnp.elim_right hnp)\n\n-- Prove (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp)\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\nassume hpq,\nassume hnq,\nassume hp, show false, from hnq (hpq hp)\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\nassume hpq,\nassume hnq,\nassume hp, absurd (hpq hp) hnq\n\n-- these require classical reasoning\nopen classical\n-- Prove (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s))\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n(assume hprs, show (p \u2192 r) \u2228 (p \u2192 s), from sorry)\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n(assume hprs, assume hp, show (p \u2192 r) \u2228 (p \u2192 s), from sorry)\n\nexample (h : \u00ac\u00acp) : p :=\nby_cases\n  (assume h1 : p, h1)\n  (assume h1 : \u00acp, absurd h1 h)\n\nexample (h : \u00ac\u00acp) : p :=\nby_contradiction\n  (assume h1 : \u00acp,\n    show false, from h h1)\n\nexample (h : \u00ac(p \u2227 q)) : \u00acp \u2228 \u00acq :=\nor.elim (em p)\n  (assume hp : p,\n    or.inr\n      (show \u00acq, from\n        assume hq : q,\n        h \u27e8hp, hq\u27e9))\n  (assume hp : \u00acp,\n    or.inl hp)\n\n-- Prove \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\nassume hnpq,\nor.elim (em p)\n(assume hp, show \u00acp \u2228 \u00acq, from or.inr (assume hq, hnpq (and.intro hp hq)))\n(assume hnp, show \u00acp \u2228 \u00acq, from or.inl hnp)\n\n-- Prove: \u00ac(p \u2227 \u00acq) \u2192 (p \u2192 q)\nexample : \u00ac(p \u2227 \u00acq) \u2192 (p \u2192 q) :=\nassume hnpnq :  \u00ac(p \u2227 \u00acq), show p \u2192 q, from (assume hp: p, show q, from\n  by_contradiction (assume hnq: \u00acq, show false,\n    from hnpnq (and.intro hp hnq)))\n\n-- Prove \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := \nassume hnpq : \u00ac(p \u2192 q),\nshow p \u2227 \u00acq, from by_contradiction (\n  assume hnpnq : \u00ac(p \u2227 \u00acq), show false, from\n    hnpq\n    (assume hp: p, show q, from\n      by_contradiction (assume hnq: \u00acq, show false,\n        from hnpnq (and.intro hp hnq))\n    )\n)\n\n-- Prove (p \u2192 q) \u2192 (\u00acp \u2228 q)\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\nassume hpq : p \u2192 q,\nshow \u00acp \u2228 q, from\nor.elim (em p)\n  (assume hp, show \u00acp \u2228 q, from or.inr(hpq hp))\n  (assume hnp, show \u00acp \u2228 q, from or.inl hnp)\n\n-- Prove (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q)\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\nassume hnpnq : \u00acq \u2192 \u00acp,\nshow p \u2192 q, from (\n  assume hp: p, show q, from by_contradiction (\n    assume hnq: \u00acq, show false, from (hnpnq hnq) hp\n  )\n)\n\n-- Prove p \u2228 \u00acp\nexample : p \u2228 \u00acp :=\nby_contradiction(assume hnpnp: \u00ac(p \u2228 \u00acp), show false, from\n  or.elim (em p)\n  (assume hp : p, show false, from\n    false.elim(hnpnp (or.inl hp)))\n  (assume hnp : \u00acp, show false, from\n    false.elim(hnpnp (or.inr hnp)))\n)\n\n-- Prove (((p \u2192 q) \u2192 p) \u2192 p)\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\nassume hpqp : (p \u2192 q) \u2192 p, show p, from\n  by_contradiction(\n      assume hnp : \u00acp, show false, from\n      false.elim(\n        hnp\n        (hpqp (assume hp : p,\n          show q, from false.elim(hnp hp)))\n      )\n  )\n", "meta": {"author": "JoseBalado", "repo": "lean-notes", "sha": "0b579f83988cc844ac1ff0592d885061959a852e", "save_path": "github-repos/lean/JoseBalado-lean-notes", "path": "github-repos/lean/JoseBalado-lean-notes/lean-notes-0b579f83988cc844ac1ff0592d885061959a852e/theorem_proving_in_lean/3.Propositions_and_Proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7302771456182908}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport analysis.complex.basic\nimport data.complex.exponential\nimport data.polynomial.algebra_map\nimport ring_theory.polynomial.chebyshev\n\n/-!\n# Multiple angle formulas in terms of Chebyshev polynomials\n\nThis file gives the trigonometric characterizations of Chebyshev polynomials, for both the real\n(`real.cos`) and complex (`complex.cos`) cosine.\n-/\n\nnamespace polynomial.chebyshev\nopen polynomial\n\nvariables {R A : Type*} [comm_ring R] [comm_ring A] [algebra R A]\n\n@[simp] lemma aeval_T (x : A) (n : \u2115) : aeval x (T R n) = (T A n).eval x :=\nby rw [aeval_def, eval\u2082_eq_eval_map, map_T]\n\n@[simp] lemma aeval_U (x : A) (n : \u2115) : aeval x (U R n) = (U A n).eval x :=\nby rw [aeval_def, eval\u2082_eq_eval_map, map_U]\n\n@[simp] lemma algebra_map_eval_T (x : R) (n : \u2115) :\n  algebra_map R A ((T R n).eval x) = (T A n).eval (algebra_map R A x) :=\nby rw [\u2190aeval_algebra_map_apply_eq_algebra_map_eval, aeval_T]\n\n@[simp] lemma algebra_map_eval_U (x : R) (n : \u2115) :\n  algebra_map R A ((U R n).eval x) = (U A n).eval (algebra_map R A x) :=\nby rw [\u2190aeval_algebra_map_apply_eq_algebra_map_eval, aeval_U]\n\n@[simp, norm_cast] \n\n@[simp, norm_cast] lemma complex_of_real_eval_U : \u2200 x n, ((U \u211d n).eval x : \u2102) = (U \u2102 n).eval x :=\n@algebra_map_eval_U \u211d \u2102 _ _ _\n\n/-! ### Complex versions -/\n\nsection complex\nopen complex\n\nvariable (\u03b8 : \u2102)\n\n/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos \u03b8` to the\nvalue `cos (n * \u03b8)`. -/\n@[simp] lemma T_complex_cos : \u2200 n, (T \u2102 n).eval (cos \u03b8) = cos (n * \u03b8)\n| 0       := by simp only [T_zero, eval_one, nat.cast_zero, zero_mul, cos_zero]\n| 1       := by simp only [eval_X, one_mul, T_one, nat.cast_one]\n| (n + 2) :=\nbegin\n  simp only [eval_X, eval_one, T_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul],\n  rw [T_complex_cos (n + 1), T_complex_cos n],\n  have aux : sin \u03b8 * sin \u03b8 = 1 - cos \u03b8 * cos \u03b8,\n  { rw \u2190 sin_sq_add_cos_sq \u03b8, ring, },\n  simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux],\n  ring,\nend\n\n/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos \u03b8` to the\nvalue `sin ((n + 1) * \u03b8) / sin \u03b8`. -/\n@[simp] lemma U_complex_cos (n : \u2115) : (U \u2102 n).eval (cos \u03b8) * sin \u03b8 = sin ((n + 1) * \u03b8) :=\nbegin\n  induction n with d hd,\n  { simp only [U_zero, nat.cast_zero, eval_one, mul_one, zero_add, one_mul] },\n  { rw U_eq_X_mul_U_add_T,\n    simp only [eval_add, eval_mul, eval_X, T_complex_cos, add_mul, mul_assoc, hd, one_mul],\n    conv_rhs { rw [sin_add, mul_comm] },\n    push_cast,\n    simp only [add_mul, one_mul] }\nend\n\nend complex\n\n/- ### Real versions -/\n\nsection real\nopen real\n\nvariables (\u03b8 : \u211d) (n : \u2115)\n\n/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos \u03b8` to the\nvalue `cos (n * \u03b8)`. -/\n@[simp] lemma T_real_cos : (T \u211d n).eval (cos \u03b8) = cos (n * \u03b8) :=\nby exact_mod_cast T_complex_cos \u03b8 n\n\n/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos \u03b8` to the\nvalue `sin ((n + 1) * \u03b8) / sin \u03b8`. -/\n@[simp] lemma U_real_cos : (U \u211d n).eval (cos \u03b8) * sin \u03b8 = sin ((n + 1) * \u03b8) :=\nby exact_mod_cast U_complex_cos \u03b8 n\n\nend real\n\nend polynomial.chebyshev\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/trigonometric/chebyshev.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450968, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7302771410874492}}
{"text": "-- Imagen_inversa_de_la_interseccion.lean\n-- Imagen inversa de la intersecci\u00f3n.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 30-abril-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, la imagen inversa de un conjunto s (de elementos de tipo \u03b2)\n-- por la funci\u00f3n f (de tipo \u03b1 \u2192 \u03b2) es el conjunto `f \u207b\u00b9' s` de\n-- elementos x (de tipo \u03b1) tales que `f x \u2208 s`.\n--\n-- Demostrar que\n--    f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables u v : set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    split,\n    { apply mem_preimage.mpr,\n      rw mem_preimage at h,\n      exact mem_of_mem_inter_left h, },\n    { apply mem_preimage.mpr,\n      rw mem_preimage at h,\n      exact mem_of_mem_inter_right h, }},\n  { intro h,\n    apply mem_preimage.mpr,\n    split,\n    { apply mem_preimage.mp,\n      exact mem_of_mem_inter_left h,},\n    { apply mem_preimage.mp,\n      exact mem_of_mem_inter_right h, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    split,\n    { simp at *,\n      exact h.1, },\n    { simp at *,\n      exact h.2, }},\n  { intro h,\n    simp at *,\n    exact h, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\n-- by hint\nby finish\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\n-- by library_search\npreimage_inter\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nrfl\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Imagen_inversa_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7302771337056682}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport group_theory.subgroup.basic -- import Lean's subgroups\n\n/-\n\n# Group homomorphisms\n\nmathlib has group homomorphisms. The type of group homomorphisms from `G` to `H` is called\n`monoid_hom G H`, but we hardly ever use that name; instead we use the notation, which\nis `G \u2192* H`, i.e. \"`*`-preserving map between groups\". Note in particular that we do *not* \nwrite `f : G \u2192 H` for a group homomorphism and then have some\nfunction `is_group_hom : (G \u2192 H) \u2192 Prop` saying that it's a group homomorphism, we just have a\ncompletely new type, whose terms are pairs consisting of the function and the axiom\nthat `f(g\u2081g\u2082)=f(g\u2081)f(g\u2082)` for all g\u2081 and g\u2082.\n-/\n\n-- Let `G` and `H` be groups.\nvariables {G H : Type} [group G] [group H]\n\n-- let `\u03c6 : G \u2192 H` be a group homomorphism\nvariable (\u03c6 : G \u2192* H)\n\n-- Even though `\u03c6` is not technically a function (it's a pair consisting of a function and\n-- a proof), we can still evaluate `\u03c6` at a term of type `G` and get a term of type `H`.\n\n-- let `a` be an element of G\nvariable (a : G)\n\n-- let's make the element `\u03c6(a)` of `H`\nexample : H := \u03c6 a\n\n-- If you use this in a proof, you'll see that actually this is denoted `\u21d1\u03c6 g`; what this\n-- means is that `\u03c6` is not itself a function, but there is a coercion from `G \u2192* H`\n-- to `G \u2192 H` sending `\u03c6` to the underlying function from `G` to `H` (so, it forgets the\n-- fact that \u03c6 is a group homomorphism and just remembers the function bit.\n\n-- Here's the basic API for group homomorphisms\n\nexample (a b : G) : \u03c6 (a * b) = \u03c6 a * \u03c6 b := \u03c6.map_mul a b\nexample : \u03c6 1 = 1 := \u03c6.map_one\nexample (a : G) : \u03c6 (a\u207b\u00b9) = (\u03c6 a)\u207b\u00b9 := \u03c6.map_inv a\n\n-- The identity group homomorphism from `G` to `G` is called `monoid_hom.id G`\n\nexample : monoid_hom.id G a = a :=\nbegin\n  refl, -- true by definition\nend\n\n-- Let K be a third group.\nvariables (K : Type) [group K]\n\n-- Let `\u03c8 : H \u2192* K` be another group homomorphism\nvariable (\u03c8 : H \u2192* K)\n\n-- The composite of \u03c8 and \u03c6 can't be written `\u03c8 \u2218 \u03c6` in Lean, because `\u2218` is notation\n-- for function composition, and `\u03c6` and `\u03c8` aren't functions, they're collections of\n-- data containing a function and some other things. So we use `monoid_hom.comp` to\n-- compose functions. We can use dot notation for this.\n\nexample : G \u2192* K := \u03c8.comp \u03c6\n\n-- When are two group homomorphisms equal? When they agree on all inputs. The `ext` tactic\n-- knows this. \n\n-- The next three lemmas are pretty standard, but they are also in fact\n-- the axioms that show that groups form a category.\n\nlemma comp_id : \u03c6.comp (monoid_hom.id G) = \u03c6 :=\nbegin\n  ext x,\n  refl,\nend\n\nlemma id_comp : (monoid_hom.id H).comp \u03c6 = \u03c6 :=\nbegin\n  ext x,\n  refl,\nend\n\nlemma comp_assoc {L : Type} [group L] (\u03c1 : K \u2192* L) :\n  (\u03c1.comp \u03c8).comp \u03c6 = \u03c1.comp (\u03c8.comp \u03c6) :=\nbegin\n  refl,\nend\n\n-- The kernel of a group homomorphism `\u03c6` is a subgroup of the source group.\n-- The elements of the kernel are *defined* to be `{x | \u03c6 x = 1}`.\n-- Note the use of dot notation to save us having to write `monoid_hom.ker`.\n-- `\u03c6.ker` *means* `monoid_hom.ker \u03c6` because `\u03c6` has type `monoid_hom [something]`\n\nexample (\u03c6 : G \u2192* H) : subgroup G := \u03c6.ker -- or `monoid_hom.ker \u03c6`\n\nexample (\u03c6 : G \u2192* H)  (x : G) : x \u2208 \u03c6.ker \u2194 \u03c6 x = 1 :=\nbegin\n  refl -- true by definition\nend\n\n-- Similarly the image is defined in the obvious way, with `monoid_hom.range`\n\nexample (\u03c6 : G \u2192* H) : subgroup H := \u03c6.range\n\nexample (\u03c6 : G \u2192* H) (y : H) : y \u2208 \u03c6.range \u2194 \u2203 x : G, \u03c6 x = y :=\nbegin\n  refl -- true by definition\nend\n\n-- `subgroup.map` is used for the image of a subgroup under a group hom\n\nexample (\u03c6 : G \u2192* H) (S : subgroup G) : subgroup H := S.map \u03c6\n\nexample (\u03c6 : G \u2192* H) (S : subgroup G) (y : H) : y \u2208 S.map \u03c6 \u2194 \u2203 x, x \u2208 S \u2227 \u03c6 x = y :=\nbegin\n  refl,\nend\n\n-- and `subgroup.comap` is used for the preimage of a subgroup under a group hom.\n\nexample (\u03c6 : G \u2192* H) (S : subgroup H) : subgroup G := S.comap \u03c6\n\nexample (\u03c6 : G \u2192* H) (T : subgroup H) (x : G) : x \u2208 T.comap \u03c6 \u2194 \u03c6 x \u2208 T :=\nbegin\n  refl,\nend\n\n-- Here are some basic facts about these constructions.\n\n-- Preimage of a subgroup along the identity map is the same subgroup\nexample (S : subgroup G) : S.comap (monoid_hom.id G) = S :=\nbegin\n  ext x,\n  refl,\nend\n\n-- Image of a subgroup along the identity map is the same subgroup\nexample (S : subgroup G) : S.map (monoid_hom.id G) = S :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8y, hy, rfl\u27e9,\n    exact hy, },\n  { intro hx,\n    exact \u27e8x, hx, rfl\u27e9, },\nend\n\n-- preimage preserves `\u2264` (i.e. if `S \u2264 T` are subgroups of `H` then `\u03c6\u207b\u00b9(S) \u2264 \u03c6\u207b\u00b9(T)`)\nexample (\u03c6 : G \u2192* H) (S T : subgroup H) (hST : S \u2264 T) : S.comap \u03c6 \u2264 T.comap \u03c6 :=\nbegin\n  intros g hg,\n  apply hST,\n  exact hg,\nend\n\n-- image preserves `\u2264` (i.e. if `S \u2264 T` are subgroups of `G` then `\u03c6(S) \u2264 \u03c6(T)`)\nexample (\u03c6 : G \u2192* H) (S T : subgroup G) (hST : S \u2264 T) : S.map \u03c6 \u2264 T.map \u03c6 :=\nbegin\n  rintros h \u27e8g, hg, rfl\u27e9,\n  refine \u27e8g, _, rfl\u27e9,\n  exact hST hg,\nend\n\n-- Pulling a subgroup back along one homomorphism and then another, is equal\n-- to pulling it back along the composite of the homomorphisms.\nexample (\u03c6 : G \u2192* H) (\u03c8 : H \u2192* K) (U : subgroup K) :\n  U.comap (\u03c8.comp \u03c6) = (U.comap \u03c8).comap \u03c6 := \nbegin\n  refl,\nend\n\n-- Pushing a subgroup along one homomorphism and then another is equal to\n--  pushing it forward along the composite of the homomorphisms.\nexample (\u03c6 : G \u2192* H) (\u03c8 : H \u2192* K) (S : subgroup G) :\n  S.map (\u03c8.comp \u03c6) = (S.map \u03c6).map \u03c8 := \nbegin\n  ext c,\n  split,\n  { rintro \u27e8a, ha, rfl\u27e9,\n    refine \u27e8\u03c6 a, _, rfl\u27e9,\n    exact \u27e8a, ha, rfl\u27e9, }, \n  { rintro \u27e8b, \u27e8a, ha, rfl\u27e9, rfl\u27e9,\n    exact \u27e8a, ha, rfl\u27e9, },\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section07subgroups_and_homomorphisms/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7302771329760783}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Robert Y. Lewis\n\n! This file was ported from Lean 3 source module ring_theory.witt_vector.defs\n! leanprover-community/mathlib commit f1944b30c97c5eb626e498307dec8b022a05bd0a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.RingTheory.WittVector.StructurePolynomial\n\n/-!\n# Witt vectors\n\nIn this file we define the type of `p`-typical Witt vectors and ring operations on it.\nThe ring axioms are verified in `ring_theory/witt_vector/basic.lean`.\n\nFor a fixed commutative ring `R` and prime `p`,\na Witt vector `x : \ud835\udd4e R` is an infinite sequence `\u2115 \u2192 R` of elements of `R`.\nHowever, the ring operations `+` and `*` are not defined in the obvious component-wise way.\nInstead, these operations are defined via certain polynomials\nusing the machinery in `structure_polynomial.lean`.\nThe `n`th value of the sum of two Witt vectors can depend on the `0`-th through `n`th values\nof the summands. This effectively simulates a \u201ccarrying\u201d operation.\n\n## Main definitions\n\n* `witt_vector p R`: the type of `p`-typical Witt vectors with coefficients in `R`.\n* `witt_vector.coeff x n`: projects the `n`th value of the Witt vector `x`.\n\n## Notation\n\nWe use notation `\ud835\udd4e R`, entered `\\bbW`, for the Witt vectors over `R`.\n\n## References\n\n* [Hazewinkel, *Witt Vectors*][Haze09]\n\n* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]\n-/\n\n\nnoncomputable section\n\n/- ./././Mathport/Syntax/Translate/Command.lean:424:34: infer kinds are unsupported in Lean 4: mk [] -/\n/-- `witt_vector p R` is the ring of `p`-typical Witt vectors over the commutative ring `R`,\nwhere `p` is a prime number.\n\nIf `p` is invertible in `R`, this ring is isomorphic to `\u2115 \u2192 R` (the product of `\u2115` copies of `R`).\nIf `R` is a ring of characteristic `p`, then `witt_vector p R` is a ring of characteristic `0`.\nThe canonical example is `witt_vector p (zmod p)`,\nwhich is isomorphic to the `p`-adic integers `\u2124_[p]`. -/\nstructure WittVector (p : \u2115) (R : Type _) where mk ::\n  coeff : \u2115 \u2192 R\n#align witt_vector WittVector\n\nvariable {p : \u2115}\n\n-- mathport name: expr\ud835\udd4e\n/- We cannot make this `localized` notation, because the `p` on the RHS doesn't occur on the left\nHiding the `p` in the notation is very convenient, so we opt for repeating the `local notation`\nin other files that use Witt vectors. -/\nlocal notation \"\ud835\udd4e\" => WittVector p\n\n-- type as `\\bbW`\nnamespace WittVector\n\nvariable (p) {R : Type _}\n\n/-- Construct a Witt vector `mk p x : \ud835\udd4e R` from a sequence `x` of elements of `R`. -/\nadd_decl_doc WittVector.mk\n\n/-- `x.coeff n` is the `n`th coefficient of the Witt vector `x`.\n\nThis concept does not have a standard name in the literature.\n-/\nadd_decl_doc WittVector.coeff\n\n@[ext]\ntheorem ext {x y : \ud835\udd4e R} (h : \u2200 n, x.coeff n = y.coeff n) : x = y :=\n  by\n  cases x\n  cases y\n  simp only at h\n  simp [Function.funext_iff, h]\n#align witt_vector.ext WittVector.ext\n\ntheorem ext_iff {x y : \ud835\udd4e R} : x = y \u2194 \u2200 n, x.coeff n = y.coeff n :=\n  \u27e8fun h n => by rw [h], ext\u27e9\n#align witt_vector.ext_iff WittVector.ext_iff\n\ntheorem coeff_mk (x : \u2115 \u2192 R) : (mk p x).coeff = x :=\n  rfl\n#align witt_vector.coeff_mk WittVector.coeff_mk\n\n/- These instances are not needed for the rest of the development,\nbut it is interesting to establish early on that `witt_vector p` is a lawful functor. -/\ninstance : Functor (WittVector p)\n    where\n  map \u03b1 \u03b2 f v := mk p (f \u2218 v.coeff)\n  mapConst \u03b1 \u03b2 a v := mk p fun _ => a\n\ninstance : LawfulFunctor (WittVector p)\n    where\n  mapConst_eq \u03b1 \u03b2 := rfl\n  id_map := fun \u03b1 \u27e8v, _\u27e9 => rfl\n  comp_map \u03b1 \u03b2 \u03b3 f g v := rfl\n\nvariable (p) [hp : Fact p.Prime] [CommRing R]\n\ninclude hp\n\nopen MvPolynomial\n\nsection RingOperations\n\n/-- The polynomials used for defining the element `0` of the ring of Witt vectors. -/\ndef wittZero : \u2115 \u2192 MvPolynomial (Fin 0 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p 0\n#align witt_vector.witt_zero WittVector.wittZero\n\n/-- The polynomials used for defining the element `1` of the ring of Witt vectors. -/\ndef wittOne : \u2115 \u2192 MvPolynomial (Fin 0 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p 1\n#align witt_vector.witt_one WittVector.wittOne\n\n/-- The polynomials used for defining the addition of the ring of Witt vectors. -/\ndef wittAdd : \u2115 \u2192 MvPolynomial (Fin 2 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p (X 0 + X 1)\n#align witt_vector.witt_add WittVector.wittAdd\n\n/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/\ndef wittNsmul (n : \u2115) : \u2115 \u2192 MvPolynomial (Fin 1 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p (n \u2022 X 0)\n#align witt_vector.witt_nsmul WittVector.wittNsmul\n\n/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/\ndef wittZsmul (n : \u2124) : \u2115 \u2192 MvPolynomial (Fin 1 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p (n \u2022 X 0)\n#align witt_vector.witt_zsmul WittVector.wittZsmul\n\n/-- The polynomials used for describing the subtraction of the ring of Witt vectors. -/\ndef wittSub : \u2115 \u2192 MvPolynomial (Fin 2 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p (X 0 - X 1)\n#align witt_vector.witt_sub WittVector.wittSub\n\n/-- The polynomials used for defining the multiplication of the ring of Witt vectors. -/\ndef wittMul : \u2115 \u2192 MvPolynomial (Fin 2 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p (X 0 * X 1)\n#align witt_vector.witt_mul WittVector.wittMul\n\n/-- The polynomials used for defining the negation of the ring of Witt vectors. -/\ndef wittNeg : \u2115 \u2192 MvPolynomial (Fin 1 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p (-X 0)\n#align witt_vector.witt_neg WittVector.wittNeg\n\n/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/\ndef wittPow (n : \u2115) : \u2115 \u2192 MvPolynomial (Fin 1 \u00d7 \u2115) \u2124 :=\n  wittStructureInt p (X 0 ^ n)\n#align witt_vector.witt_pow WittVector.wittPow\n\nvariable {p}\n\nomit hp\n\n/-- An auxiliary definition used in `witt_vector.eval`.\nEvaluates a polynomial whose variables come from the disjoint union of `k` copies of `\u2115`,\nwith a curried evaluation `x`.\nThis can be defined more generally but we use only a specific instance here. -/\ndef peval {k : \u2115} (\u03c6 : MvPolynomial (Fin k \u00d7 \u2115) \u2124) (x : Fin k \u2192 \u2115 \u2192 R) : R :=\n  aeval (Function.uncurry x) \u03c6\n#align witt_vector.peval WittVector.peval\n\n/-- Let `\u03c6` be a family of polynomials, indexed by natural numbers, whose variables come from the\ndisjoint union of `k` copies of `\u2115`, and let `x\u1d62` be a Witt vector for `0 \u2264 i < k`.\n\n`eval \u03c6 x` evaluates `\u03c6` mapping the variable `X_(i, n)` to the `n`th coefficient of `x\u1d62`.\n\nInstantiating `\u03c6` with certain polynomials defined in `structure_polynomial.lean` establishes the\nring operations on `\ud835\udd4e R`. For example, `witt_vector.witt_add` is such a `\u03c6` with `k = 2`;\nevaluating this at `(x\u2080, x\u2081)` gives us the sum of two Witt vectors `x\u2080 + x\u2081`.\n-/\ndef eval {k : \u2115} (\u03c6 : \u2115 \u2192 MvPolynomial (Fin k \u00d7 \u2115) \u2124) (x : Fin k \u2192 \ud835\udd4e R) : \ud835\udd4e R :=\n  mk p fun n => peval (\u03c6 n) fun i => (x i).coeff\n#align witt_vector.eval WittVector.eval\n\nvariable (R) [Fact p.Prime]\n\ninstance : Zero (\ud835\udd4e R) :=\n  \u27e8eval (wittZero p) ![]\u27e9\n\ninstance : Inhabited (\ud835\udd4e R) :=\n  \u27e80\u27e9\n\ninstance : One (\ud835\udd4e R) :=\n  \u27e8eval (wittOne p) ![]\u27e9\n\ninstance : Add (\ud835\udd4e R) :=\n  \u27e8fun x y => eval (wittAdd p) ![x, y]\u27e9\n\ninstance : Sub (\ud835\udd4e R) :=\n  \u27e8fun x y => eval (wittSub p) ![x, y]\u27e9\n\ninstance hasNatScalar : SMul \u2115 (\ud835\udd4e R) :=\n  \u27e8fun n x => eval (wittNsmul p n) ![x]\u27e9\n#align witt_vector.has_nat_scalar WittVector.hasNatScalar\n\ninstance hasIntScalar : SMul \u2124 (\ud835\udd4e R) :=\n  \u27e8fun n x => eval (wittZsmul p n) ![x]\u27e9\n#align witt_vector.has_int_scalar WittVector.hasIntScalar\n\ninstance : Mul (\ud835\udd4e R) :=\n  \u27e8fun x y => eval (wittMul p) ![x, y]\u27e9\n\ninstance : Neg (\ud835\udd4e R) :=\n  \u27e8fun x => eval (wittNeg p) ![x]\u27e9\n\ninstance hasNatPow : Pow (\ud835\udd4e R) \u2115 :=\n  \u27e8fun x n => eval (wittPow p n) ![x]\u27e9\n#align witt_vector.has_nat_pow WittVector.hasNatPow\n\ninstance : NatCast (\ud835\udd4e R) :=\n  \u27e8Nat.unaryCast\u27e9\n\ninstance : IntCast (\ud835\udd4e R) :=\n  \u27e8Int.castDef\u27e9\n\nend RingOperations\n\nsection WittStructureSimplifications\n\n@[simp]\ntheorem wittZero_eq_zero (n : \u2115) : wittZero p n = 0 :=\n  by\n  apply MvPolynomial.map_injective (Int.castRingHom \u211a) Int.cast_injective\n  simp only [witt_zero, wittStructureRat, bind\u2081, aeval_zero', constantCoeff_xInTermsOfW,\n    RingHom.map_zero, AlgHom.map_zero, map_wittStructureInt]\n#align witt_vector.witt_zero_eq_zero WittVector.wittZero_eq_zero\n\n@[simp]\ntheorem wittOne_zero_eq_one : wittOne p 0 = 1 :=\n  by\n  apply MvPolynomial.map_injective (Int.castRingHom \u211a) Int.cast_injective\n  simp only [witt_one, wittStructureRat, xInTermsOfW_zero, AlgHom.map_one, RingHom.map_one,\n    bind\u2081_X_right, map_wittStructureInt]\n#align witt_vector.witt_one_zero_eq_one WittVector.wittOne_zero_eq_one\n\n@[simp]\ntheorem wittOne_pos_eq_zero (n : \u2115) (hn : 0 < n) : wittOne p n = 0 :=\n  by\n  apply MvPolynomial.map_injective (Int.castRingHom \u211a) Int.cast_injective\n  simp only [witt_one, wittStructureRat, RingHom.map_zero, AlgHom.map_one, RingHom.map_one,\n    map_wittStructureInt]\n  revert hn; apply Nat.strong_induction_on n; clear n\n  intro n IH hn\n  rw [xInTermsOfW_eq]\n  simp only [AlgHom.map_mul, AlgHom.map_sub, AlgHom.map_sum, AlgHom.map_pow, bind\u2081_X_right,\n    bind\u2081_C_right]\n  rw [sub_mul, one_mul]\n  rw [Finset.sum_eq_single 0]\n  \u00b7 simp only [invOf_eq_inv, one_mul, inv_pow, tsub_zero, RingHom.map_one, pow_zero]\n    simp only [one_pow, one_mul, xInTermsOfW_zero, sub_self, bind\u2081_X_right]\n  \u00b7 intro i hin hi0\n    rw [Finset.mem_range] at hin\n    rw [IH _ hin (Nat.pos_of_ne_zero hi0), zero_pow (pow_pos hp.1.Pos _), MulZeroClass.mul_zero]\n  \u00b7 rw [Finset.mem_range]\n    intro\n    contradiction\n#align witt_vector.witt_one_pos_eq_zero WittVector.wittOne_pos_eq_zero\n\n@[simp]\ntheorem wittAdd_zero : wittAdd p 0 = X (0, 0) + X (1, 0) :=\n  by\n  apply MvPolynomial.map_injective (Int.castRingHom \u211a) Int.cast_injective\n  simp only [witt_add, wittStructureRat, AlgHom.map_add, RingHom.map_add, rename_X,\n    xInTermsOfW_zero, map_X, wittPolynomial_zero, bind\u2081_X_right, map_wittStructureInt]\n#align witt_vector.witt_add_zero WittVector.wittAdd_zero\n\n@[simp]\ntheorem wittSub_zero : wittSub p 0 = X (0, 0) - X (1, 0) :=\n  by\n  apply MvPolynomial.map_injective (Int.castRingHom \u211a) Int.cast_injective\n  simp only [witt_sub, wittStructureRat, AlgHom.map_sub, RingHom.map_sub, rename_X,\n    xInTermsOfW_zero, map_X, wittPolynomial_zero, bind\u2081_X_right, map_wittStructureInt]\n#align witt_vector.witt_sub_zero WittVector.wittSub_zero\n\n@[simp]\ntheorem wittMul_zero : wittMul p 0 = X (0, 0) * X (1, 0) :=\n  by\n  apply MvPolynomial.map_injective (Int.castRingHom \u211a) Int.cast_injective\n  simp only [witt_mul, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero,\n    RingHom.map_mul, bind\u2081_X_right, AlgHom.map_mul, map_wittStructureInt]\n#align witt_vector.witt_mul_zero WittVector.wittMul_zero\n\n@[simp]\ntheorem wittNeg_zero : wittNeg p 0 = -X (0, 0) :=\n  by\n  apply MvPolynomial.map_injective (Int.castRingHom \u211a) Int.cast_injective\n  simp only [witt_neg, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero,\n    RingHom.map_neg, AlgHom.map_neg, bind\u2081_X_right, map_wittStructureInt]\n#align witt_vector.witt_neg_zero WittVector.wittNeg_zero\n\n@[simp]\ntheorem constantCoeff_wittAdd (n : \u2115) : constantCoeff (wittAdd p n) = 0 :=\n  by\n  apply constantCoeff_wittStructureInt p _ _ n\n  simp only [add_zero, RingHom.map_add, constant_coeff_X]\n#align witt_vector.constant_coeff_witt_add WittVector.constantCoeff_wittAdd\n\n@[simp]\ntheorem constantCoeff_wittSub (n : \u2115) : constantCoeff (wittSub p n) = 0 :=\n  by\n  apply constantCoeff_wittStructureInt p _ _ n\n  simp only [sub_zero, RingHom.map_sub, constant_coeff_X]\n#align witt_vector.constant_coeff_witt_sub WittVector.constantCoeff_wittSub\n\n@[simp]\ntheorem constantCoeff_wittMul (n : \u2115) : constantCoeff (wittMul p n) = 0 :=\n  by\n  apply constantCoeff_wittStructureInt p _ _ n\n  simp only [MulZeroClass.mul_zero, RingHom.map_mul, constant_coeff_X]\n#align witt_vector.constant_coeff_witt_mul WittVector.constantCoeff_wittMul\n\n@[simp]\ntheorem constantCoeff_wittNeg (n : \u2115) : constantCoeff (wittNeg p n) = 0 :=\n  by\n  apply constantCoeff_wittStructureInt p _ _ n\n  simp only [neg_zero, RingHom.map_neg, constant_coeff_X]\n#align witt_vector.constant_coeff_witt_neg WittVector.constantCoeff_wittNeg\n\n@[simp]\ntheorem constantCoeff_wittNsmul (m : \u2115) (n : \u2115) : constantCoeff (wittNsmul p m n) = 0 :=\n  by\n  apply constantCoeff_wittStructureInt p _ _ n\n  simp only [smul_zero, map_nsmul, constant_coeff_X]\n#align witt_vector.constant_coeff_witt_nsmul WittVector.constantCoeff_wittNsmul\n\n@[simp]\ntheorem constantCoeff_wittZsmul (z : \u2124) (n : \u2115) : constantCoeff (wittZsmul p z n) = 0 :=\n  by\n  apply constantCoeff_wittStructureInt p _ _ n\n  simp only [smul_zero, map_zsmul, constant_coeff_X]\n#align witt_vector.constant_coeff_witt_zsmul WittVector.constantCoeff_wittZsmul\n\nend WittStructureSimplifications\n\nsection Coeff\n\nvariable (p R)\n\n@[simp]\ntheorem zero_coeff (n : \u2115) : (0 : \ud835\udd4e R).coeff n = 0 :=\n  show (aeval _ (wittZero p n) : R) = 0 by simp only [witt_zero_eq_zero, AlgHom.map_zero]\n#align witt_vector.zero_coeff WittVector.zero_coeff\n\n@[simp]\ntheorem one_coeff_zero : (1 : \ud835\udd4e R).coeff 0 = 1 :=\n  show (aeval _ (wittOne p 0) : R) = 1 by simp only [witt_one_zero_eq_one, AlgHom.map_one]\n#align witt_vector.one_coeff_zero WittVector.one_coeff_zero\n\n@[simp]\ntheorem one_coeff_eq_of_pos (n : \u2115) (hn : 0 < n) : coeff (1 : \ud835\udd4e R) n = 0 :=\n  show (aeval _ (wittOne p n) : R) = 0 by simp only [hn, witt_one_pos_eq_zero, AlgHom.map_zero]\n#align witt_vector.one_coeff_eq_of_pos WittVector.one_coeff_eq_of_pos\n\nvariable {p R}\n\nomit hp\n\n@[simp]\ntheorem v2_coeff {p' R'} (x y : WittVector p' R') (i : Fin 2) :\n    (![x, y] i).coeff = ![x.coeff, y.coeff] i := by fin_cases i <;> simp\n#align witt_vector.v2_coeff WittVector.v2_coeff\n\ninclude hp\n\ntheorem add_coeff (x y : \ud835\udd4e R) (n : \u2115) : (x + y).coeff n = peval (wittAdd p n) ![x.coeff, y.coeff] :=\n  by simp [(\u00b7 + \u00b7), eval]\n#align witt_vector.add_coeff WittVector.add_coeff\n\ntheorem sub_coeff (x y : \ud835\udd4e R) (n : \u2115) : (x - y).coeff n = peval (wittSub p n) ![x.coeff, y.coeff] :=\n  by simp [Sub.sub, eval]\n#align witt_vector.sub_coeff WittVector.sub_coeff\n\ntheorem mul_coeff (x y : \ud835\udd4e R) (n : \u2115) : (x * y).coeff n = peval (wittMul p n) ![x.coeff, y.coeff] :=\n  by simp [(\u00b7 * \u00b7), eval]\n#align witt_vector.mul_coeff WittVector.mul_coeff\n\ntheorem neg_coeff (x : \ud835\udd4e R) (n : \u2115) : (-x).coeff n = peval (wittNeg p n) ![x.coeff] := by\n  simp [Neg.neg, eval, Matrix.cons_fin_one]\n#align witt_vector.neg_coeff WittVector.neg_coeff\n\ntheorem nsmul_coeff (m : \u2115) (x : \ud835\udd4e R) (n : \u2115) :\n    (m \u2022 x).coeff n = peval (wittNsmul p m n) ![x.coeff] := by\n  simp [SMul.smul, eval, Matrix.cons_fin_one]\n#align witt_vector.nsmul_coeff WittVector.nsmul_coeff\n\ntheorem zsmul_coeff (m : \u2124) (x : \ud835\udd4e R) (n : \u2115) :\n    (m \u2022 x).coeff n = peval (wittZsmul p m n) ![x.coeff] := by\n  simp [SMul.smul, eval, Matrix.cons_fin_one]\n#align witt_vector.zsmul_coeff WittVector.zsmul_coeff\n\ntheorem pow_coeff (m : \u2115) (x : \ud835\udd4e R) (n : \u2115) : (x ^ m).coeff n = peval (wittPow p m n) ![x.coeff] :=\n  by simp [Pow.pow, eval, Matrix.cons_fin_one]\n#align witt_vector.pow_coeff WittVector.pow_coeff\n\ntheorem add_coeff_zero (x y : \ud835\udd4e R) : (x + y).coeff 0 = x.coeff 0 + y.coeff 0 := by\n  simp [add_coeff, peval]\n#align witt_vector.add_coeff_zero WittVector.add_coeff_zero\n\ntheorem mul_coeff_zero (x y : \ud835\udd4e R) : (x * y).coeff 0 = x.coeff 0 * y.coeff 0 := by\n  simp [mul_coeff, peval]\n#align witt_vector.mul_coeff_zero WittVector.mul_coeff_zero\n\nend Coeff\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem wittAdd_vars (n : \u2115) : (wittAdd p n).vars \u2286 Finset.univ \u00d7\u02e2 Finset.range (n + 1) :=\n  wittStructureInt_vars _ _ _\n#align witt_vector.witt_add_vars WittVector.wittAdd_vars\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem wittSub_vars (n : \u2115) : (wittSub p n).vars \u2286 Finset.univ \u00d7\u02e2 Finset.range (n + 1) :=\n  wittStructureInt_vars _ _ _\n#align witt_vector.witt_sub_vars WittVector.wittSub_vars\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem wittMul_vars (n : \u2115) : (wittMul p n).vars \u2286 Finset.univ \u00d7\u02e2 Finset.range (n + 1) :=\n  wittStructureInt_vars _ _ _\n#align witt_vector.witt_mul_vars WittVector.wittMul_vars\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem wittNeg_vars (n : \u2115) : (wittNeg p n).vars \u2286 Finset.univ \u00d7\u02e2 Finset.range (n + 1) :=\n  wittStructureInt_vars _ _ _\n#align witt_vector.witt_neg_vars WittVector.wittNeg_vars\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem wittNsmul_vars (m : \u2115) (n : \u2115) :\n    (wittNsmul p m n).vars \u2286 Finset.univ \u00d7\u02e2 Finset.range (n + 1) :=\n  wittStructureInt_vars _ _ _\n#align witt_vector.witt_nsmul_vars WittVector.wittNsmul_vars\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem wittZsmul_vars (m : \u2124) (n : \u2115) :\n    (wittZsmul p m n).vars \u2286 Finset.univ \u00d7\u02e2 Finset.range (n + 1) :=\n  wittStructureInt_vars _ _ _\n#align witt_vector.witt_zsmul_vars WittVector.wittZsmul_vars\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem wittPow_vars (m : \u2115) (n : \u2115) : (wittPow p m n).vars \u2286 Finset.univ \u00d7\u02e2 Finset.range (n + 1) :=\n  wittStructureInt_vars _ _ _\n#align witt_vector.witt_pow_vars WittVector.wittPow_vars\n\nend WittVector\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RingTheory/WittVector/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320035, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7302618352684276}}
{"text": "-- Estudante: Lucas Emanuel Resck Domingues\n\n-- Exercise 1\n\nsection\n    parameters {A : Type} {R : A \u2192 A \u2192 Prop}\n    parameter (irreflR : irreflexive R)\n    parameter (transR : transitive R)\n\n    local infix < := R\n\n    def R' (a b : A) : Prop := R a b \u2228 a = b\n    local infix \u2264 := R'\n\n    theorem reflR' (a : A) : a \u2264 a :=\n        show a < a \u2228 a = a, from or.inr rfl\n\n    theorem transR' {a b c : A} (h1 : a \u2264 b) (h2 : b \u2264 c):\n        a \u2264 c :=\n                have h3 : a < b \u2228 a = b, from h1,\n                have h4 : b < c \u2228 b = c, from h2,\n            show a < c \u2228 a = c, from or.elim h3\n                (assume h5 : a < b,\n                or.elim h4\n                    (assume h6 : b < c,\n                        have h7 : a < c, from transR h5 h6,\n                    or.inl h7)\n                    (assume h6 : b = c,\n                        have h7 : a < c, from eq.subst h6 h5,\n                    or.inl h7))\n                (assume h5 : a = b,\n                or.elim h4\n                    (assume h6 : b < c,\n                        have h7 : a < c, from eq.substr h5 h6,\n                    or.inl h7)\n                    (assume h6 : b = c,\n                        have h7 : a = c, from eq.substr h5 h6,\n                    or.inr h7))     \n\n    include irreflR\n    include transR\n\n    theorem antisymmR' {a b : A} (h1 : a \u2264 b) (h2 : b \u2264 a) :\n    a = b :=\n        begin\n            cases h1,\n                cases h2,\n                    have h3, from transR h1 h2,\n                    have h4, from irreflR a,\n                    contradiction,\n                apply eq.symm,\n                assumption,\n            assumption\n        end\nend\n\n-- Exercise 2\n\nsection\n    parameters {A : Type} {R : A \u2192 A \u2192 Prop}\n    parameter (reflR : reflexive R)\n    parameter (transR : transitive R)\n\n    def S (a b : A) : Prop := R a b \u2227 R b a\n\n    include transR\n\n    example : transitive S :=\n        begin\n            intros a b c h1 h2,\n            cases h1 with h3 h4,\n            cases h2 with h5 h6,\n            apply and.intro,\n                have h7, from transR h3 h5,\n                assumption,\n            exact transR h6 h4\n        end\nend\n\n--Exercise 3\n\nsection\n    parameters {A : Type} {a b c : A} {R : A \u2192 A \u2192 Prop}\n    parameter (Rab : R a b)\n    parameter (Rbc : R b c)\n    parameter (nRac : \u00ac R a c)\n\n    -- Prove one of the following two theorems:\n\n    theorem R_is_strict_partial_order :\n    irreflexive R \u2227 transitive R :=\n    sorry\n\n    -- Because nRac, R is not transitive, that is, it's not strict partial order.\n\n    include Rab\n    include Rbc\n    include nRac\n\n    theorem R_is_not_strict_partial_order :\n    \u00ac(irreflexive R \u2227 transitive R) :=\n        begin\n            intro h1,\n            cases h1 with h2 h3,\n            have Rac, from h3 Rab Rbc,\n            contradiction\n        end\nend\n\n-- Exercise 4\n\nsection\n    open nat\n\n    example : 1 \u2264 4 :=\n        calc\n            1 \u2264 1 : le_refl 1\n          ... \u2264 2 : le_succ 1\n          ... \u2264 3 : le_succ 2\n          ... \u2264 4 : le_succ 3\nend", "meta": {"author": "lucasresck", "repo": "Discrete-Mathematics", "sha": "0a08081c5f393e5765259d3f1253c3a6dd043dac", "save_path": "github-repos/lean/lucasresck-Discrete-Mathematics", "path": "github-repos/lean/lucasresck-Discrete-Mathematics/Discrete-Mathematics-0a08081c5f393e5765259d3f1253c3a6dd043dac/Lists of exercises/List 7/cap14-LucasDomingues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7301694340314332}}
{"text": "/-\nCopyright (c) 2023 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module algebra.monoid_algebra.ideal\n! leanprover-community/mathlib commit 72c366d0475675f1309d3027d3d7d47ee4423951\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.MonoidAlgebra.Division\nimport Mathbin.RingTheory.Ideal.Basic\n\n/-!\n# Lemmas about ideals of `monoid_algebra` and `add_monoid_algebra`\n-/\n\n\nvariable {k A G : Type _}\n\n/-- If `x` belongs to the ideal generated by generators in `s`, then every element of the support of\n`x` factors through an element of `s`.\n\nWe could spell `\u2203 d, m = d * m` as `mul_opposite.op m' \u2223 mul_opposite.op m` but this would be worse.\n-/\ntheorem MonoidAlgebra.mem_ideal_span_of_image [Monoid G] [Semiring k] {s : Set G}\n    {x : MonoidAlgebra k G} :\n    x \u2208 Ideal.span (MonoidAlgebra.of k G '' s) \u2194 \u2200 m \u2208 x.support, \u2203 m' \u2208 s, \u2203 d, m = d * m' :=\n  by\n  let RHS : Ideal (MonoidAlgebra k G) :=\n    { carrier := { p | \u2200 m : G, m \u2208 p.support \u2192 \u2203 m' \u2208 s, \u2203 d, m = d * m' }\n      add_mem' := fun x y hx hy m hm => by\n        classical exact (Finset.mem_union.1 <| Finsupp.support_add hm).elim (hx m) (hy m)\n      zero_mem' := fun m hm => by cases hm\n      smul_mem' := fun x y hy m hm =>\n        by\n        replace hm := finset.mem_bUnion.mp (Finsupp.support_sum hm)\n        obtain \u27e8xm, hxm, hm\u27e9 := hm\n        replace hm := finset.mem_bUnion.mp (Finsupp.support_sum hm)\n        obtain \u27e8ym, hym, hm\u27e9 := hm\n        replace hm := finset.mem_singleton.mp (Finsupp.support_single_subset hm)\n        obtain rfl := hm\n        refine' (hy _ hym).imp fun sm => Exists.imp fun hsm => _\n        rintro \u27e8d, rfl\u27e9\n        exact \u27e8xm * d, (mul_assoc _ _ _).symm\u27e9 }\n  change _ \u2194 x \u2208 RHS\n  constructor\n  \u00b7 revert x\n    refine' Ideal.span_le.2 _\n    rintro _ \u27e8i, hi, rfl\u27e9 m hm\n    refine' \u27e8_, hi, 1, _\u27e9\n    obtain rfl := finset.mem_singleton.mp (Finsupp.support_single_subset hm)\n    exact (one_mul _).symm\n  \u00b7 intro hx\n    rw [\u2190 Finsupp.sum_single x]\n    apply Ideal.sum_mem _ fun i hi => _\n    obtain \u27e8d, hd, d2, rfl\u27e9 := hx _ hi\n    convert Ideal.mul_mem_left _ (id <| Finsupp.single d2 <| x (d2 * d) : MonoidAlgebra k G) _\n    pick_goal 3\n    refine' Ideal.subset_span \u27e8_, hd, rfl\u27e9\n    rw [id.def, MonoidAlgebra.of_apply, MonoidAlgebra.single_mul_single, mul_one]\n#align monoid_algebra.mem_ideal_span_of_image MonoidAlgebra.mem_ideal_span_of_image\n\n/-- If `x` belongs to the ideal generated by generators in `s`, then every element of the support of\n`x` factors additively through an element of `s`.\n-/\ntheorem AddMonoidAlgebra.mem_ideal_span_of'_image [AddMonoid A] [Semiring k] {s : Set A}\n    {x : AddMonoidAlgebra k A} :\n    x \u2208 Ideal.span (AddMonoidAlgebra.of' k A '' s) \u2194 \u2200 m \u2208 x.support, \u2203 m' \u2208 s, \u2203 d, m = d + m' :=\n  @MonoidAlgebra.mem_ideal_span_of_image k (Multiplicative A) _ _ _ _\n#align add_monoid_algebra.mem_ideal_span_of'_image AddMonoidAlgebra.mem_ideal_span_of'_image\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/MonoidAlgebra/Ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.730169419098967}}
{"text": "-- sums over sets\nimport algebra.big_operators\n\n-- positive naturals\nimport data.pnat \n\nnamespace nat\n\nopen list\n\n/-- returns the finset of divisors of a positive natural -/\ndefinition factors (d : \u2115+) : list \u2115 := \n  filter (\u03bb e, e \u2223 d) (range (d+1))\n\n#eval factors 6 -- [1, 2, 3, 6]\n\nlemma mem_factors_iff_divides (d : \u2115+) (e : \u2115) : e \u2208 factors d \u2194 e \u2223 d :=\nby simp [factors, -add_comm, nat.lt_succ_iff];\n   exact and_iff_right_of_imp (le_of_dvd d.2)\n\nlemma nodup_factors (d : \u2115+) : nodup (factors d) :=\nnodup_filter _ (nodup_range (d+1) : nodup (range (d+1)))\n\n/-- returns the sum of f(e) as e ranges over the divisors of d (positive nat) -/\ndefinition divisor_sum \n  {\u03b2 : Type*} [add_comm_monoid \u03b2] (f : \u2115 \u2192 \u03b2) (d : \u2115+) : \u03b2 := \nfinset.sum (\u27e8quotient.mk (factors d),nodup_factors d\u27e9) f\n\nend nat \n\nopen nat\n\n#eval divisor_sum (id) (6) -- it's a perfect number!", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M3P14/sum_over_divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846919, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7300500493585224}}
{"text": "import algebra.group_power tactic.norm_num algebra.big_operators\n\n\ntheorem Q2 (n : \u2115) : n \u2265 2 \u2192 nat.pow 4 n > nat.pow 3 n + nat.pow 2 n :=\nbegin\nintro H_n_ge_2,\ncases n with n1,\n  exfalso,revert H_n_ge_2, exact dec_trivial,\ncases n1 with n2,\n  exfalso,revert H_n_ge_2, exact dec_trivial,\nclear H_n_ge_2,\ninduction n2 with d Hd,\n  exact dec_trivial,\nlet e := nat.succ (nat.succ d),\nshow nat.pow 4 e*4>nat.pow 3 e*3+nat.pow 2 e*2,\nchange nat.pow 4 (nat.succ (nat.succ d)) > nat.pow 3 (nat.succ (nat.succ d)) + nat.pow 2 (nat.succ (nat.succ d))\nwith nat.pow 4 e>nat.pow 3 e+nat.pow 2 e at Hd,\nexact calc\nnat.pow 4 e * 4 > (nat.pow 3 e + nat.pow 2 e) * 4 : mul_lt_mul_of_pos_right Hd (dec_trivial)\n... = nat.pow 3 e*4+nat.pow 2 e*4 : add_mul _ _ _\n... \u2265 nat.pow 3 e*3+nat.pow 2 e*4 : add_le_add_right (nat.mul_le_mul_left _ (dec_trivial)) _\n... \u2265 nat.pow 3 e*3+nat.pow 2 e*2 : add_le_add_left (nat.mul_le_mul_left _ (dec_trivial)) _,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1F/problem_bank/0502/S0502.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012762876286, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7300105603867291}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.subobject.types\n! leanprover-community/mathlib commit 610955826b3be3caaab5170fef04ecd5458521bf\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.CategoryTheory.Subobject.WellPowered\nimport Mathbin.CategoryTheory.Types\n\n/-!\n# `Type u` is well-powered\n\nBy building a categorical equivalence `mono_over \u03b1 \u224c set \u03b1` for any `\u03b1 : Type u`,\nwe deduce that `subobject \u03b1 \u2243o set \u03b1` and that `Type u` is well-powered.\n\nOne would hope that for a particular concrete category `C` (`AddCommGroup`, etc)\nit's viable to prove `[well_powered C]` without explicitly aligning `subobject X`\nwith the \"hand-rolled\" definition of subobjects.\n\nThis may be possible using Lawvere theories,\nbut it remains to be seen whether this just pushes lumps around in the carpet.\n-/\n\n\nuniverse u\n\nopen CategoryTheory\n\nopen CategoryTheory.Subobject\n\nopen CategoryTheory.Type\n\ntheorem subtype_val_mono {\u03b1 : Type u} (s : Set \u03b1) : Mono (\u21be(Subtype.val : s \u2192 \u03b1)) :=\n  (mono_iff_injective _).mpr Subtype.val_injective\n#align subtype_val_mono subtype_val_mono\n\nattribute [local instance] subtype_val_mono\n\n/-- The category of `mono_over \u03b1`, for `\u03b1 : Type u`, is equivalent to the partial order `set \u03b1`.\n-/\n@[simps]\nnoncomputable def Types.monoOverEquivalenceSet (\u03b1 : Type u) : MonoOver \u03b1 \u224c Set \u03b1\n    where\n  Functor :=\n    { obj := fun f => Set.range f.1.Hom\n      map := fun f g t =>\n        homOfLE\n          (by\n            rintro a \u27e8x, rfl\u27e9\n            exact \u27e8t.1 x, congr_fun t.w x\u27e9) }\n  inverse :=\n    { obj := fun s => MonoOver.mk' (Subtype.val : s \u2192 \u03b1)\n      map := fun s t b =>\n        MonoOver.homMk (fun w => \u27e8w.1, Set.mem_of_mem_of_subset w.2 b.le\u27e9)\n          (by\n            ext\n            simp) }\n  unitIso :=\n    NatIso.ofComponents\n      (fun f =>\n        MonoOver.isoMk (Equiv.ofInjective f.1.Hom ((mono_iff_injective _).mp f.2)).toIso (by tidy))\n      (by tidy)\n  counitIso := NatIso.ofComponents (fun s => eqToIso Subtype.range_val) (by tidy)\n#align types.mono_over_equivalence_set Types.monoOverEquivalenceSet\n\ninstance : WellPowered (Type u) :=\n  wellPowered_of_essentiallySmall_monoOver fun \u03b1 =>\n    EssentiallySmall.mk' (Types.monoOverEquivalenceSet \u03b1)\n\n/-- For `\u03b1 : Type u`, `subobject \u03b1` is order isomorphic to `set \u03b1`.\n-/\nnoncomputable def Types.subobjectEquivSet (\u03b1 : Type u) : Subobject \u03b1 \u2243o Set \u03b1 :=\n  (Types.monoOverEquivalenceSet \u03b1).thinSkeletonOrderIso\n#align types.subobject_equiv_set Types.subobjectEquivSet\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/CategoryTheory/Subobject/Types.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7299463116909076}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.star.basic\nimport analysis.normed_space.spectrum\nimport algebra.star.module\nimport analysis.normed_space.star.exponential\n\n/-! # Spectral properties in C\u22c6-algebras\nIn this file, we establish various propreties related to the spectrum of elements in C\u22c6-algebras.\n-/\n\nlocal postfix `\u22c6`:std.prec.max_plus := star\n\nopen_locale topological_space ennreal\nopen filter ennreal spectrum cstar_ring\n\nsection unitary_spectrum\n\nvariables\n{\ud835\udd5c : Type*} [normed_field \ud835\udd5c]\n{E : Type*} [normed_ring E] [star_ring E] [cstar_ring E]\n[normed_algebra \ud835\udd5c E] [complete_space E] [nontrivial E]\n\nlemma unitary.spectrum_subset_circle (u : unitary E) :\n  spectrum \ud835\udd5c (u : E) \u2286 metric.sphere 0 1 :=\nbegin\n  refine \u03bb k hk, mem_sphere_zero_iff_norm.mpr (le_antisymm _ _),\n  { simpa only [cstar_ring.norm_coe_unitary u] using norm_le_norm_of_mem hk },\n  { rw \u2190unitary.coe_to_units_apply u at hk,\n    have hnk := ne_zero_of_mem_of_unit hk,\n    rw [\u2190inv_inv (unitary.to_units u), \u2190spectrum.map_inv, set.mem_inv] at hk,\n    have : \u2225k\u2225\u207b\u00b9 \u2264 \u2225\u2191((unitary.to_units u)\u207b\u00b9)\u2225, simpa only [norm_inv] using norm_le_norm_of_mem hk,\n    simpa using inv_le_of_inv_le (norm_pos_iff.mpr hnk) this }\nend\n\nlemma spectrum.subset_circle_of_unitary {u : E} (h : u \u2208 unitary E) :\n  spectrum \ud835\udd5c u \u2286 metric.sphere 0 1 :=\nunitary.spectrum_subset_circle \u27e8u, h\u27e9\n\nend unitary_spectrum\n\nsection complex_scalars\n\nopen complex\n\nvariables {A : Type*}\n[normed_ring A] [normed_algebra \u2102 A] [complete_space A] [star_ring A] [cstar_ring A]\n\nlocal notation `\u2191\u2090` := algebra_map \u2102 A\n\nlemma spectral_radius_eq_nnnorm_of_self_adjoint {a : A} (ha : a \u2208 self_adjoint A) :\n  spectral_radius \u2102 a = \u2225a\u2225\u208a :=\nbegin\n  have hconst : tendsto (\u03bb n : \u2115, (\u2225a\u2225\u208a : \u211d\u22650\u221e)) at_top _ := tendsto_const_nhds,\n  refine tendsto_nhds_unique _ hconst,\n  convert (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a : A)).comp\n      (nat.tendsto_pow_at_top_at_top_of_one_lt (by linarith : 1 < 2)),\n  refine funext (\u03bb n, _),\n  rw [function.comp_app, nnnorm_pow_two_pow_of_self_adjoint ha, ennreal.coe_pow, \u2190rpow_nat_cast,\n    \u2190rpow_mul],\n  simp,\nend\n\nlemma spectral_radius_eq_nnnorm_of_star_normal (a : A) [is_star_normal a] :\n  spectral_radius \u2102 a = \u2225a\u2225\u208a :=\nbegin\n  refine (ennreal.pow_strict_mono (by linarith : 2 \u2260 0)).injective _,\n  have ha : a\u22c6 * a \u2208 self_adjoint A,\n    from self_adjoint.mem_iff.mpr (by simpa only [star_star] using (star_mul a\u22c6 a)),\n  have heq : (\u03bb n : \u2115, ((\u2225(a\u22c6 * a) ^ n\u2225\u208a ^ (1 / n : \u211d)) : \u211d\u22650\u221e))\n    = (\u03bb x, x ^ 2) \u2218 (\u03bb n : \u2115, ((\u2225a ^ n\u2225\u208a ^ (1 / n : \u211d)) : \u211d\u22650\u221e)),\n  { funext,\n    rw [function.comp_apply, \u2190rpow_nat_cast, \u2190rpow_mul, mul_comm, rpow_mul, rpow_nat_cast,\n      \u2190coe_pow, sq, \u2190nnnorm_star_mul_self, commute.mul_pow (star_comm_self' a), star_pow], },\n  have h\u2082 := ((ennreal.continuous_pow 2).tendsto (spectral_radius \u2102 a)).comp\n    (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius a),\n  rw \u2190heq at h\u2082,\n  convert tendsto_nhds_unique h\u2082 (pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a\u22c6 * a)),\n  rw [spectral_radius_eq_nnnorm_of_self_adjoint ha, sq, nnnorm_star_mul_self, coe_mul],\nend\n\n/-- Any element of the spectrum of a selfadjoint is real. -/\ntheorem self_adjoint.mem_spectrum_eq_re [star_module \u2102 A] [nontrivial A] {a : A}\n  (ha : a \u2208 self_adjoint A) {z : \u2102} (hz : z \u2208 spectrum \u2102 a) : z = z.re :=\nbegin\n  let Iu := units.mk0 I I_ne_zero,\n  have : exp \u2102 \u2102 (I \u2022 z) \u2208 spectrum \u2102 (exp \u2102 A (I \u2022 a)),\n    by simpa only [units.smul_def, units.coe_mk0]\n      using spectrum.exp_mem_exp (Iu \u2022 a) (smul_mem_smul_iff.mpr hz),\n  exact complex.ext (of_real_re _)\n    (by simpa only [\u2190complex.exp_eq_exp_\u2102_\u2102, mem_sphere_zero_iff_norm, norm_eq_abs, abs_exp,\n      real.exp_eq_one_iff, smul_eq_mul, I_mul, neg_eq_zero]\n      using spectrum.subset_circle_of_unitary (self_adjoint.exp_i_smul_unitary ha) this),\nend\n\n/-- Any element of the spectrum of a selfadjoint is real. -/\ntheorem self_adjoint.mem_spectrum_eq_re' [star_module \u2102 A] [nontrivial A]\n  (a : self_adjoint A) {z : \u2102} (hz : z \u2208 spectrum \u2102 (a : A)) : z = z.re :=\nself_adjoint.mem_spectrum_eq_re a.property hz\n\n/-- The spectrum of a selfadjoint is real -/\ntheorem self_adjoint.coe_re_map_spectrum [star_module \u2102 A] [nontrivial A] {a : A}\n  (ha : a \u2208 self_adjoint A) : spectrum \u2102 a = (coe \u2218 re '' (spectrum \u2102 a) : set \u2102) :=\nle_antisymm (\u03bb z hz, \u27e8z, hz, (self_adjoint.mem_spectrum_eq_re ha hz).symm\u27e9) (\u03bb z, by\n  { rintros \u27e8z, hz, rfl\u27e9,\n    simpa only [(self_adjoint.mem_spectrum_eq_re ha hz).symm, function.comp_app] using hz })\n\n/-- The spectrum of a selfadjoint is real -/\ntheorem self_adjoint.coe_re_map_spectrum' [star_module \u2102 A] [nontrivial A] (a : self_adjoint A) :\n  spectrum \u2102 (a : A) = (coe \u2218 re '' (spectrum \u2102 (a : A)) : set \u2102) :=\nself_adjoint.coe_re_map_spectrum a.property\n\nend complex_scalars\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/normed_space/star/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7299463064902868}}
{"text": "--                            |   Premisa  |\nlemma Example_1 (A B : Prop) : A \u2227 (A \u2192 B) \u2192 B :=\nbegin\n    -- Declaramos nuestra premisa, correspondiente a A \u2227 (A \u2192 B)\n    -- Notemos que buscamos concluir B\n    intro h,\n    -- h contiene dos partes claves, su lado derecho tiene el camino para llegar a B\n    -- Entonces lo tomamos.\n    apply and.right h,\n    -- Pero para concluir B, requerimos que A sea valido, mas el lado izquierdo de h nos permite aseverarlo.\n    apply and.left h\n    -- Ganamos :D\nend\n--                                |         Premisas          |\nlemma Example_2 (A B C D : Prop) : (A \u2228 B) \u2192 (A \u2192 C) \u2192 (B \u2192 D) \u2192 C \u2228 D :=\nbegin\n    -- Declaramos nuestras premisas\n    intros h1 h2 h3,\n    -- Notando que h2 y h3 son las implicancias que nos acercan a C y D, respectivamente, necesitamos hacer\n    -- validas las proposiciones necesarias. Para ello, hacemos un analisis por caso en base a h1.\n    apply or.elim h1,\n        -- Declaramos temporalmente a A como hipotesis.\n        intro ha,\n            -- Partimos demostrando el lado izquierdo de la conclusion, C.\n            apply or.inl,\n            -- Como tenemos h2, (A \u2192 C), y ha, A, podemos utilizar la eliminacion del implica, lo que nos demuestra C.\n            apply h2,\n            apply ha,\n            -- Y ganamos por el lado izquierdo :D\n        -- Ahora declaramos B como una hipotesis temporal, recordemos que es el segundo caso. Noten que ahora buscamos\n        -- demostrar el lado derecho de nuestra conclusion, D, cuyos pasos son analogos a lo que hicimos para demostrar C.\n        intro hb,\n            -- Ojo que aqui declaramos la introduccion del or por la derecha, es decir, generar la patita derecha que nos falta\n            -- de la conclusion, D.\n            apply or.inr,\n            apply h3,\n            apply hb\n    -- Y ganamoooos c:\nend\n--                            |  Premisa |\nlemma Example_3 (A B : Prop) : \u00ac (A \u2227 B) \u2192 (A \u2192 \u00ac B) :=\nbegin\n    -- Declaramos nuestra premisa\n    intro h,\n    -- Lo que haremos es introducir el implica, donde asumimos A temporalmente.\n    intro ha,\n    -- De esta forma, debemos demostrar \u00ac B, pero recordemos que esto es equivalente a decir B \u2192 false. Entonces nuevamente\n    -- introducimos el implica, asumiento temporalmente B.\n    intro hb,\n    -- Asi, lo que buscamos es demostrar false. Para ello utilizaremos h, que es analogo a decir (A \u2227 B) \u2192 false.\n    apply h,\n    -- Pero para cerrar, ahora necesitamos demostrar que tenemos (A \u2227 B). Mas, notemos que somos personas bknes y ya tenemos las\n    -- piezas necesarias, ha y hb. De tal forma que introducimos el and.\n    apply and.intro,\n    -- Entregando A\n    apply ha,\n    -- Entregando B\n    apply hb\n    -- Y asi demostramos que tenemos (A \u2227 B), GANAMOS :DDDD\nend", "meta": {"author": "ahevia", "repo": "CC3101_2021", "sha": "178392747409383f39e357b0dde919553d214aeb", "save_path": "github-repos/lean/ahevia-CC3101_2021", "path": "github-repos/lean/ahevia-CC3101_2021/CC3101_2021-178392747409383f39e357b0dde919553d214aeb/ClasesAuxiliares/Auxiliar1/Pauta_Auxiliar_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7299463058138213}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.nat.choose.cast\n! leanprover-community/mathlib commit bb168510ef455e9280a152e7f31673cabd3d7496\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Cast\n\n/-!\n# Cast of binomial coefficients\n\nThis file allows calculating the binomial coefficient `a.choose b` as an element of a division ring\nof characteristic `0`.\n-/\n\n\nopen Nat\n\nvariable (K : Type _) [DivisionRing K] [CharZero K]\n\nnamespace Nat\n\ntheorem cast_choose {a b : \u2115} (h : a \u2264 b) : (b.choose a : K) = b ! / (a ! * (b - a)!) := by\n  have : \u2200 {n : \u2115}, (n ! : K) \u2260 0 := Nat.cast_ne_zero.2 (factorial_ne_zero _)\n  rw [eq_div_iff_mul_eq (mul_ne_zero this this)]\n  rw_mod_cast [\u2190 mul_assoc, choose_mul_factorial_mul_factorial h]\n#align nat.cast_choose Nat.cast_choose\n\ntheorem cast_add_choose {a b : \u2115} : ((a + b).choose a : K) = (a + b)! / (a ! * b !) := by\n  rw [cast_choose K (_root_.le_add_right le_rfl), add_tsub_cancel_left]\n#align nat.cast_add_choose Nat.cast_add_choose\n\ntheorem cast_choose_eq_pochhammer_div (a b : \u2115) :\n    (a.choose b : K) = (pochhammer K b).eval \u2191(a - (b - 1)) / b ! := by\n  rw [eq_div_iff_mul_eq (cast_ne_zero.2 b.factorial_ne_zero : (b ! : K) \u2260 0), \u2190 cast_mul,\n    mul_comm, \u2190 descFactorial_eq_factorial_mul_choose, \u2190 cast_descFactorial]\n#align nat.cast_choose_eq_pochhammer_div Nat.cast_choose_eq_pochhammer_div\n\ntheorem cast_choose_two (a : \u2115) : (a.choose 2 : K) = a * (a - 1) / 2 := by\n  rw [\u2190 cast_descFactorial_two, descFactorial_eq_factorial_mul_choose, factorial_two, mul_comm,\n    cast_mul, cast_two, eq_div_iff_mul_eq (two_ne_zero : (2 : K) \u2260 0)]\n#align nat.cast_choose_two Nat.cast_choose_two\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Choose/Cast.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7299463045312581}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Yury Kudryashov\n-/\nimport analysis.normed_space.basic\nimport topology.local_homeomorph\nimport topology.algebra.ordered.liminf_limsup\n\n/-!\n# Asymptotics\n\nWe introduce these relations:\n\n* `is_O_with c f g l` : \"f is big O of g along l with constant c\";\n* `is_O f g l` : \"f is big O of g along l\";\n* `is_o f g l` : \"f is little o of g along l\".\n\nHere `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains\nof `f` and `g` do not need to be the same; all that is needed that there is a norm associated with\nthese types, and it is the norm that is compared asymptotically.\n\nThe relation `is_O_with c` is introduced to factor out common algebraic arguments in the proofs of\nsimilar properties of `is_O` and `is_o`. Usually proofs outside of this file should use `is_O`\ninstead.\n\nOften the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute\nvalue. In general, we have\n\n  `is_O f g l \u2194 is_O (\u03bb x, \u2225f x\u2225) (\u03bb x, \u2225g x\u2225) l`,\n\nand similarly for `is_o`. But our setup allows us to use the notions e.g. with functions\nto the integers, rationals, complex numbers, or any normed vector space without mentioning the\nnorm explicitly.\n\nIf `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always\nnonzero, we have\n\n  `is_o f g l \u2194 tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0)`.\n\nIn fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction\nit suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining\nthe Fr\u00e9chet derivative.)\n-/\n\nopen filter set\nopen_locale topological_space big_operators classical filter nnreal\n\nnamespace asymptotics\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {E : Type*} {F : Type*} {G : Type*}\n  {E' : Type*} {F' : Type*} {G' : Type*} {R : Type*} {R' : Type*} {\ud835\udd5c : Type*} {\ud835\udd5c' : Type*}\n\nvariables [has_norm E] [has_norm F] [has_norm G] [normed_group E'] [normed_group F']\n  [normed_group G'] [normed_ring R] [normed_ring R'] [normed_field \ud835\udd5c] [normed_field \ud835\udd5c']\n  {c c' : \u211d} {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {k : \u03b1 \u2192 G} {f' : \u03b1 \u2192 E'} {g' : \u03b1 \u2192 F'} {k' : \u03b1 \u2192 G'}\n  {l l' : filter \u03b1}\n\nsection defs\n\n/-! ### Definitions -/\n\n/-- This version of the Landau notation `is_O_with C f g l` where `f` and `g` are two functions on\na type `\u03b1` and `l` is a filter on `\u03b1`, means that eventually for `l`, `\u2225f\u2225` is bounded by `C * \u2225g\u2225`.\nIn other words, `\u2225f\u2225 / \u2225g\u2225` is eventually bounded by `C`, modulo division by zero issues that are\navoided by this definition. Probably you want to use `is_O` instead of this relation. -/\n@[irreducible]\ndef is_O_with (c : \u211d) (f : \u03b1 \u2192 E) (g : \u03b1 \u2192 F) (l : filter \u03b1) : Prop :=\n\u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225\n\n/-- Definition of `is_O_with`. We record it in a lemma as we will set `is_O_with` to be irreducible\nat the end of this file. -/\nlemma is_O_with_iff {c : \u211d} {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O_with c f g l \u2194 \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 := by rw is_O_with\n\nalias is_O_with_iff \u2194 asymptotics.is_O_with.bound asymptotics.is_O_with.of_bound\n\n/-- The Landau notation `is_O f g l` where `f` and `g` are two functions on a type `\u03b1` and `l` is\na filter on `\u03b1`, means that eventually for `l`, `\u2225f\u2225` is bounded by a constant multiple of `\u2225g\u2225`.\nIn other words, `\u2225f\u2225 / \u2225g\u2225` is eventually bounded, modulo division by zero issues that are avoided\nby this definition. -/\n@[irreducible]\ndef is_O (f : \u03b1 \u2192 E) (g : \u03b1 \u2192 F) (l : filter \u03b1) : Prop := \u2203 c : \u211d, is_O_with c f g l\n\n/-- Definition of `is_O` in terms of `is_O_with`. We record it in a lemma as we will set\n`is_O` to be irreducible at the end of this file. -/\nlemma is_O_iff_is_O_with {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2194 \u2203 c : \u211d, is_O_with c f g l := by rw is_O\n\n/-- Definition of `is_O` in terms of filters. We record it in a lemma as we will set\n`is_O` to be irreducible at the end of this file. -/\nlemma is_O_iff {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2194 \u2203 c : \u211d, \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 := by simp [is_O, is_O_with]\n\nlemma is_O.of_bound (c : \u211d) {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1}\n  (h : \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225) : is_O f g l := is_O_iff.2 \u27e8c, h\u27e9\n\nlemma is_O.bound {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2192 \u2203 c : \u211d, \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 := is_O_iff.1\n\n/-- The Landau notation `is_o f g l` where `f` and `g` are two functions on a type `\u03b1` and `l` is\na filter on `\u03b1`, means that eventually for `l`, `\u2225f\u2225` is bounded by an arbitrarily small constant\nmultiple of `\u2225g\u2225`. In other words, `\u2225f\u2225 / \u2225g\u2225` tends to `0` along `l`, modulo division by zero\nissues that are avoided by this definition. -/\n@[irreducible]\ndef is_o (f : \u03b1 \u2192 E) (g : \u03b1 \u2192 F) (l : filter \u03b1) : Prop := \u2200 \u2983c : \u211d\u2984, 0 < c \u2192 is_O_with c f g l\n\n/-- Definition of `is_o` in terms of `is_O_with`. We record it in a lemma as we will set\n`is_o` to be irreducible at the end of this file. -/\nlemma is_o_iff_forall_is_O_with {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_o f g l \u2194 \u2200 \u2983c : \u211d\u2984, 0 < c \u2192 is_O_with c f g l := by rw is_o\n\nalias is_o_iff_forall_is_O_with \u2194 asymptotics.is_o.forall_is_O_with asymptotics.is_o.of_is_O_with\n\n/-- Definition of `is_o` in terms of filters. We record it in a lemma as we will set\n`is_o` to be irreducible at the end of this file. -/\nlemma is_o_iff {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_o f g l \u2194 \u2200 \u2983c : \u211d\u2984, 0 < c \u2192 \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 :=\nby simp only [is_o, is_O_with]\n\nalias is_o_iff \u2194 asymptotics.is_o.bound asymptotics.is_o.of_bound\n\nlemma is_o.def {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} (h : is_o f g l) {c : \u211d} (hc : 0 < c) :\n  \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 :=\nis_o_iff.1 h hc\n\nlemma is_o.def' {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} (h : is_o f g l) {c : \u211d} (hc : 0 < c) :\n  is_O_with c f g l :=\nis_O_with_iff.2 $ is_o_iff.1 h hc\n\nend defs\n\n/-! ### Conversions -/\n\ntheorem is_O_with.is_O (h : is_O_with c f g l) : is_O f g l := by rw is_O; exact \u27e8c, h\u27e9\n\ntheorem is_o.is_O_with (hgf : is_o f g l) : is_O_with 1 f g l := hgf.def' zero_lt_one\n\ntheorem is_o.is_O (hgf : is_o f g l) : is_O f g l := hgf.is_O_with.is_O\n\nlemma is_O.is_O_with {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2192 \u2203 c : \u211d, is_O_with c f g l := is_O_iff_is_O_with.1\n\ntheorem is_O_with.weaken (h : is_O_with c f g' l) (hc : c \u2264 c') : is_O_with c' f g' l :=\nis_O_with.of_bound $ mem_of_superset h.bound $ \u03bb x hx,\ncalc \u2225f x\u2225 \u2264 c * \u2225g' x\u2225 : hx\n... \u2264 _ : mul_le_mul_of_nonneg_right hc (norm_nonneg _)\n\ntheorem is_O_with.exists_pos (h : is_O_with c f g' l) :\n  \u2203 c' (H : 0 < c'), is_O_with c' f g' l :=\n\u27e8max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken $ le_max_left c 1\u27e9\n\ntheorem is_O.exists_pos (h : is_O f g' l) : \u2203 c (H : 0 < c), is_O_with c f g' l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in hc.exists_pos\n\ntheorem is_O_with.exists_nonneg (h : is_O_with c f g' l) :\n  \u2203 c' (H : 0 \u2264 c'), is_O_with c' f g' l :=\nlet \u27e8c, cpos, hc\u27e9 := h.exists_pos in \u27e8c, le_of_lt cpos, hc\u27e9\n\ntheorem is_O.exists_nonneg (h : is_O f g' l) :\n  \u2203 c (H : 0 \u2264 c), is_O_with c f g' l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in hc.exists_nonneg\n\n/-- `f = O(g)` if and only if `is_O_with c f g` for all sufficiently large `c`. -/\nlemma is_O_iff_eventually_is_O_with : is_O f g' l \u2194 \u2200\u1da0 c in at_top, is_O_with c f g' l :=\nis_O_iff_is_O_with.trans\n  \u27e8\u03bb \u27e8c, hc\u27e9, mem_at_top_sets.2 \u27e8c, \u03bb c' hc', hc.weaken hc'\u27e9, \u03bb h, h.exists\u27e9\n\n/-- `f = O(g)` if and only if `\u2200\u1da0 x in l, \u2225f x\u2225 \u2264 c * \u2225g x\u2225` for all sufficiently large `c`. -/\nlemma is_O_iff_eventually : is_O f g' l \u2194 \u2200\u1da0 c in at_top, \u2200\u1da0 x in l, \u2225f x\u2225 \u2264 c * \u2225g' x\u2225 :=\nis_O_iff_eventually_is_O_with.trans $ by simp only [is_O_with]\n\n/-! ### Subsingleton -/\n\n@[nontriviality] lemma is_o_of_subsingleton [subsingleton E'] : is_o f' g' l :=\nis_o.of_bound $ \u03bb c hc, by simp [subsingleton.elim (f' _) 0, mul_nonneg hc.le]\n\n@[nontriviality] lemma is_O_of_subsingleton [subsingleton E'] : is_O f' g' l :=\nis_o_of_subsingleton.is_O\n\n/-! ### Congruence -/\n\ntheorem is_O_with_congr {c\u2081 c\u2082} {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n  (hc : c\u2081 = c\u2082) (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O_with c\u2081 f\u2081 g\u2081 l \u2194 is_O_with c\u2082 f\u2082 g\u2082 l :=\nbegin\n  unfold is_O_with,\n  subst c\u2082,\n  apply filter.eventually_congr,\n  filter_upwards [hf, hg] with _ e\u2081 e\u2082,\n  rw [e\u2081, e\u2082],\nend\n\ntheorem is_O_with.congr' {c\u2081 c\u2082} {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n  (hc : c\u2081 = c\u2082) (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O_with c\u2081 f\u2081 g\u2081 l \u2192 is_O_with c\u2082 f\u2082 g\u2082 l :=\n(is_O_with_congr hc hf hg).mp\n\ntheorem is_O_with.congr {c\u2081 c\u2082} {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n  (hc : c\u2081 = c\u2082) (hf : \u2200 x, f\u2081 x = f\u2082 x) (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O_with c\u2081 f\u2081 g\u2081 l \u2192 is_O_with c\u2082 f\u2082 g\u2082 l :=\n\u03bb h, h.congr' hc (univ_mem' hf) (univ_mem' hg)\n\ntheorem is_O_with.congr_left {f\u2081 f\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hf : \u2200 x, f\u2081 x = f\u2082 x) :\n  is_O_with c f\u2081 g l \u2192 is_O_with c f\u2082 g l :=\nis_O_with.congr rfl hf (\u03bb _, rfl)\n\ntheorem is_O_with.congr_right {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1} (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O_with c f g\u2081 l \u2192 is_O_with c f g\u2082 l :=\nis_O_with.congr rfl (\u03bb _, rfl) hg\n\ntheorem is_O_with.congr_const {c\u2081 c\u2082} {l : filter \u03b1} (hc : c\u2081 = c\u2082) :\n  is_O_with c\u2081 f g l \u2192 is_O_with c\u2082 f g l :=\nis_O_with.congr hc (\u03bb _, rfl) (\u03bb _, rfl)\n\ntheorem is_O_congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O f\u2081 g\u2081 l \u2194 is_O f\u2082 g\u2082 l :=\nby { unfold is_O, exact exists_congr (\u03bb c, is_O_with_congr rfl hf hg) }\n\ntheorem is_O.congr' {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O f\u2081 g\u2081 l \u2192 is_O f\u2082 g\u2082 l :=\n(is_O_congr hf hg).mp\n\ntheorem is_O.congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : \u2200 x, f\u2081 x = f\u2082 x) (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O f\u2081 g\u2081 l \u2192 is_O f\u2082 g\u2082 l :=\n\u03bb h, h.congr' (univ_mem' hf) (univ_mem' hg)\n\ntheorem is_O.congr_left {f\u2081 f\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hf : \u2200 x, f\u2081 x = f\u2082 x) :\n  is_O f\u2081 g l \u2192 is_O f\u2082 g l :=\nis_O.congr hf (\u03bb _, rfl)\n\ntheorem is_O.congr_right {g\u2081 g\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O f g\u2081 l \u2192 is_O f g\u2082 l :=\nis_O.congr (\u03bb _, rfl) hg\n\ntheorem is_o_congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_o f\u2081 g\u2081 l \u2194 is_o f\u2082 g\u2082 l :=\nby { unfold is_o, exact ball_congr (\u03bb c hc, is_O_with_congr (eq.refl c) hf hg) }\n\ntheorem is_o.congr' {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_o f\u2081 g\u2081 l \u2192 is_o f\u2082 g\u2082 l :=\n(is_o_congr hf hg).mp\n\ntheorem is_o.congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : \u2200 x, f\u2081 x = f\u2082 x) (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_o f\u2081 g\u2081 l \u2192 is_o f\u2082 g\u2082 l :=\n\u03bb h, h.congr' (univ_mem' hf) (univ_mem' hg)\n\ntheorem is_o.congr_left {f\u2081 f\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hf : \u2200 x, f\u2081 x = f\u2082 x) :\n  is_o f\u2081 g l \u2192 is_o f\u2082 g l :=\nis_o.congr hf (\u03bb _, rfl)\n\ntheorem is_o.congr_right {g\u2081 g\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_o f g\u2081 l \u2192 is_o f g\u2082 l :=\nis_o.congr (\u03bb _, rfl) hg\n\n/-! ### Filter operations and transitivity -/\n\ntheorem is_O_with.comp_tendsto (hcfg : is_O_with c f g l)\n  {k : \u03b2 \u2192 \u03b1} {l' : filter \u03b2} (hk : tendsto k l' l):\n  is_O_with c (f \u2218 k) (g \u2218 k) l' :=\nis_O_with.of_bound $ hk hcfg.bound\n\ntheorem is_O.comp_tendsto (hfg : is_O f g l) {k : \u03b2 \u2192 \u03b1} {l' : filter \u03b2} (hk : tendsto k l' l) :\n  is_O (f \u2218 k) (g \u2218 k) l' :=\nis_O_iff_is_O_with.2 $ hfg.is_O_with.imp (\u03bb c h, h.comp_tendsto hk)\n\ntheorem is_o.comp_tendsto (hfg : is_o f g l) {k : \u03b2 \u2192 \u03b1} {l' : filter \u03b2} (hk : tendsto k l' l) :\n  is_o (f \u2218 k) (g \u2218 k) l' :=\nis_o.of_is_O_with $ \u03bb c cpos, (hfg.forall_is_O_with cpos).comp_tendsto hk\n\n@[simp] theorem is_O_with_map {k : \u03b2 \u2192 \u03b1} {l : filter \u03b2} :\n  is_O_with c f g (map k l) \u2194 is_O_with c (f \u2218 k) (g \u2218 k) l :=\nby { unfold is_O_with, exact mem_map }\n\n@[simp] theorem is_O_map {k : \u03b2 \u2192 \u03b1} {l : filter \u03b2} :\n  is_O f g (map k l) \u2194 is_O (f \u2218 k) (g \u2218 k) l :=\nby simp only [is_O, is_O_with_map]\n\n@[simp] theorem is_o_map {k : \u03b2 \u2192 \u03b1} {l : filter \u03b2} :\n  is_o f g (map k l) \u2194 is_o (f \u2218 k) (g \u2218 k) l :=\nby simp only [is_o, is_O_with_map]\n\ntheorem is_O_with.mono (h : is_O_with c f g l') (hl : l \u2264 l') : is_O_with c f g l :=\nis_O_with.of_bound $ hl h.bound\n\ntheorem is_O.mono (h : is_O f g l') (hl : l \u2264 l') : is_O f g l :=\nis_O_iff_is_O_with.2 $ h.is_O_with.imp (\u03bb c h, h.mono hl)\n\ntheorem is_o.mono (h : is_o f g l') (hl : l \u2264 l') : is_o f g l :=\nis_o.of_is_O_with $ \u03bb c cpos, (h.forall_is_O_with cpos).mono hl\n\ntheorem is_O_with.trans (hfg : is_O_with c f g l) (hgk : is_O_with c' g k l) (hc : 0 \u2264 c) :\n  is_O_with (c * c') f k l :=\nbegin\n  unfold is_O_with at *,\n  filter_upwards [hfg, hgk] with x hx hx',\n  calc \u2225f x\u2225 \u2264 c * \u2225g x\u2225 : hx\n  ... \u2264 c * (c' * \u2225k x\u2225) : mul_le_mul_of_nonneg_left hx' hc\n  ... = c * c' * \u2225k x\u2225 : (mul_assoc _ _ _).symm\nend\n\ntheorem is_O.trans (hfg : is_O f g' l) (hgk : is_O g' k l) : is_O f k l :=\nlet \u27e8c, cnonneg, hc\u27e9 := hfg.exists_nonneg, \u27e8c', hc'\u27e9 := hgk.is_O_with in\n(hc.trans hc' cnonneg).is_O\n\ntheorem is_o.trans_is_O_with (hfg : is_o f g l) (hgk : is_O_with c g k l) (hc : 0 < c) :\n  is_o f k l :=\nbegin\n  unfold is_o at *,\n  intros c' c'pos,\n  have : 0 < c' / c, from div_pos c'pos hc,\n  exact ((hfg this).trans hgk (le_of_lt this)).congr_const (div_mul_cancel _ (ne_of_gt hc))\nend\n\ntheorem is_o.trans_is_O (hfg : is_o f g l) (hgk : is_O g k' l) : is_o f k' l :=\nlet \u27e8c, cpos, hc\u27e9 := hgk.exists_pos in hfg.trans_is_O_with hc cpos\n\ntheorem is_O_with.trans_is_o (hfg : is_O_with c f g l) (hgk : is_o g k l) (hc : 0 < c) :\n  is_o f k l :=\nbegin\n  unfold is_o at *,\n  intros c' c'pos,\n  have : 0 < c' / c, from div_pos c'pos hc,\n  exact (hfg.trans (hgk this) (le_of_lt hc)).congr_const (mul_div_cancel' _ (ne_of_gt hc))\nend\n\ntheorem is_O.trans_is_o (hfg : is_O f g' l) (hgk : is_o g' k l) : is_o f k l :=\nlet \u27e8c, cpos, hc\u27e9 := hfg.exists_pos in hc.trans_is_o hgk cpos\n\ntheorem is_o.trans (hfg : is_o f g l) (hgk : is_o g k' l) : is_o f k' l :=\nhfg.trans_is_O hgk.is_O\n\ntheorem is_o.trans' (hfg : is_o f g' l) (hgk : is_o g' k l) : is_o f k l :=\nhfg.is_O.trans_is_o hgk\n\nsection\n\nvariable (l)\n\ntheorem is_O_with_of_le' (hfg : \u2200 x, \u2225f x\u2225 \u2264 c * \u2225g x\u2225) : is_O_with c f g l :=\nis_O_with.of_bound $ univ_mem' hfg\n\ntheorem is_O_with_of_le (hfg : \u2200 x, \u2225f x\u2225 \u2264 \u2225g x\u2225) : is_O_with 1 f g l :=\nis_O_with_of_le' l $ \u03bb x, by { rw one_mul, exact hfg x }\n\ntheorem is_O_of_le' (hfg : \u2200 x, \u2225f x\u2225 \u2264 c * \u2225g x\u2225) : is_O f g l :=\n(is_O_with_of_le' l hfg).is_O\n\ntheorem is_O_of_le (hfg : \u2200 x, \u2225f x\u2225 \u2264 \u2225g x\u2225) : is_O f g l :=\n(is_O_with_of_le l hfg).is_O\n\nend\n\ntheorem is_O_with_refl (f : \u03b1 \u2192 E) (l : filter \u03b1) : is_O_with 1 f f l :=\nis_O_with_of_le l $ \u03bb _, le_rfl\n\ntheorem is_O_refl (f : \u03b1 \u2192 E) (l : filter \u03b1) : is_O f f l := (is_O_with_refl f l).is_O\n\ntheorem is_O_with.trans_le (hfg : is_O_with c f g l) (hgk : \u2200 x, \u2225g x\u2225 \u2264 \u2225k x\u2225) (hc : 0 \u2264 c) :\n  is_O_with c f k l :=\n(hfg.trans (is_O_with_of_le l hgk) hc).congr_const $ mul_one c\n\ntheorem is_O.trans_le (hfg : is_O f g' l) (hgk : \u2200 x, \u2225g' x\u2225 \u2264 \u2225k x\u2225) :\n  is_O f k l :=\nhfg.trans (is_O_of_le l hgk)\n\ntheorem is_o.trans_le (hfg : is_o f g l) (hgk : \u2200 x, \u2225g x\u2225 \u2264 \u2225k x\u2225) :\n  is_o f k l :=\nhfg.trans_is_O_with (is_O_with_of_le _ hgk) zero_lt_one\n\nsection bot\n\nvariables (c f g)\n\n@[simp] theorem is_O_with_bot : is_O_with c f g \u22a5 := is_O_with.of_bound $ trivial\n\n@[simp] theorem is_O_bot : is_O f g \u22a5 := (is_O_with_bot 1 f g).is_O\n\n@[simp] theorem is_o_bot : is_o f g \u22a5 := is_o.of_is_O_with $ \u03bb c _, is_O_with_bot c f g\n\nend bot\n\ntheorem is_O_with.join (h : is_O_with c f g l) (h' : is_O_with c f g l') :\n  is_O_with c f g (l \u2294 l') :=\nis_O_with.of_bound $ mem_sup.2 \u27e8h.bound, h'.bound\u27e9\n\ntheorem is_O_with.join' (h : is_O_with c f g' l) (h' : is_O_with c' f g' l') :\n  is_O_with (max c c') f g' (l \u2294 l') :=\nis_O_with.of_bound $\nmem_sup.2 \u27e8(h.weaken $ le_max_left c c').bound, (h'.weaken $ le_max_right c c').bound\u27e9\n\ntheorem is_O.join (h : is_O f g' l) (h' : is_O f g' l') : is_O f g' (l \u2294 l') :=\nlet \u27e8c, hc\u27e9 := h.is_O_with, \u27e8c', hc'\u27e9 := h'.is_O_with in (hc.join' hc').is_O\n\ntheorem is_o.join (h : is_o f g l) (h' : is_o f g l') :\n  is_o f g (l \u2294 l') :=\nis_o.of_is_O_with $\n\u03bb c cpos, (h.forall_is_O_with cpos).join (h'.forall_is_O_with cpos)\n\n/-! ### Simplification : norm -/\n\n@[simp] theorem is_O_with_norm_right : is_O_with c f (\u03bb x, \u2225g' x\u2225) l \u2194 is_O_with c f g' l :=\nby simp only [is_O_with, norm_norm]\n\nalias is_O_with_norm_right \u2194 asymptotics.is_O_with.of_norm_right asymptotics.is_O_with.norm_right\n\n@[simp] theorem is_O_norm_right : is_O f (\u03bb x, \u2225g' x\u2225) l \u2194 is_O f g' l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_norm_right) }\n\nalias is_O_norm_right \u2194 asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right\n\n@[simp] theorem is_o_norm_right : is_o f (\u03bb x, \u2225g' x\u2225) l \u2194 is_o f g' l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_norm_right) }\n\nalias is_o_norm_right \u2194 asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right\n\n@[simp] theorem is_O_with_norm_left : is_O_with c (\u03bb x, \u2225f' x\u2225) g l \u2194 is_O_with c f' g l :=\nby simp only [is_O_with, norm_norm]\n\nalias is_O_with_norm_left \u2194 asymptotics.is_O_with.of_norm_left asymptotics.is_O_with.norm_left\n\n@[simp] theorem is_O_norm_left : is_O (\u03bb x, \u2225f' x\u2225) g l \u2194 is_O f' g l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_norm_left) }\n\nalias is_O_norm_left \u2194 asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left\n\n@[simp] theorem is_o_norm_left : is_o (\u03bb x, \u2225f' x\u2225) g l \u2194 is_o f' g l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_norm_left) }\n\nalias is_o_norm_left \u2194 asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left\n\ntheorem is_O_with_norm_norm :\n  is_O_with c (\u03bb x, \u2225f' x\u2225) (\u03bb x, \u2225g' x\u2225) l \u2194 is_O_with c f' g' l :=\nis_O_with_norm_left.trans is_O_with_norm_right\n\nalias is_O_with_norm_norm \u2194 asymptotics.is_O_with.of_norm_norm asymptotics.is_O_with.norm_norm\n\ntheorem is_O_norm_norm :\n  is_O (\u03bb x, \u2225f' x\u2225) (\u03bb x, \u2225g' x\u2225) l \u2194 is_O f' g' l :=\nis_O_norm_left.trans is_O_norm_right\n\nalias is_O_norm_norm \u2194 asymptotics.is_O.of_norm_norm asymptotics.is_O.norm_norm\n\ntheorem is_o_norm_norm :\n  is_o (\u03bb x, \u2225f' x\u2225) (\u03bb x, \u2225g' x\u2225) l \u2194 is_o f' g' l :=\nis_o_norm_left.trans is_o_norm_right\n\nalias is_o_norm_norm \u2194 asymptotics.is_o.of_norm_norm asymptotics.is_o.norm_norm\n\n/-! ### Simplification: negate -/\n\n@[simp] theorem is_O_with_neg_right : is_O_with c f (\u03bb x, -(g' x)) l \u2194 is_O_with c f g' l :=\nby simp only [is_O_with, norm_neg]\n\nalias is_O_with_neg_right \u2194 asymptotics.is_O_with.of_neg_right asymptotics.is_O_with.neg_right\n\n@[simp] theorem is_O_neg_right : is_O f (\u03bb x, -(g' x)) l \u2194 is_O f g' l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_neg_right) }\n\nalias is_O_neg_right \u2194 asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right\n\n@[simp] theorem is_o_neg_right : is_o f (\u03bb x, -(g' x)) l \u2194 is_o f g' l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_neg_right) }\n\nalias is_o_neg_right \u2194 asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right\n\n@[simp] theorem is_O_with_neg_left : is_O_with c (\u03bb x, -(f' x)) g l \u2194 is_O_with c f' g l :=\nby simp only [is_O_with, norm_neg]\n\nalias is_O_with_neg_left \u2194 asymptotics.is_O_with.of_neg_left asymptotics.is_O_with.neg_left\n\n@[simp] theorem is_O_neg_left : is_O (\u03bb x, -(f' x)) g l \u2194 is_O f' g l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_neg_left) }\n\nalias is_O_neg_left \u2194 asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left\n\n@[simp] theorem is_o_neg_left : is_o (\u03bb x, -(f' x)) g l \u2194 is_o f' g l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_neg_left) }\n\nalias is_o_neg_left \u2194 asymptotics.is_o.of_neg_right asymptotics.is_o.neg_left\n\n/-! ### Product of functions (right) -/\n\nlemma is_O_with_fst_prod : is_O_with 1 f' (\u03bb x, (f' x, g' x)) l :=\nis_O_with_of_le l $ \u03bb x, le_max_left _ _\n\nlemma is_O_with_snd_prod : is_O_with 1 g' (\u03bb x, (f' x, g' x)) l :=\nis_O_with_of_le l $ \u03bb x, le_max_right _ _\n\nlemma is_O_fst_prod : is_O f' (\u03bb x, (f' x, g' x)) l := is_O_with_fst_prod.is_O\n\nlemma is_O_snd_prod : is_O g' (\u03bb x, (f' x, g' x)) l := is_O_with_snd_prod.is_O\n\nlemma is_O_fst_prod' {f' : \u03b1 \u2192 E' \u00d7 F'} : is_O (\u03bb x, (f' x).1) f' l :=\nby simpa [is_O, is_O_with] using is_O_fst_prod\n\nlemma is_O_snd_prod' {f' : \u03b1 \u2192 E' \u00d7 F'} : is_O (\u03bb x, (f' x).2) f' l :=\nby simpa [is_O, is_O_with] using is_O_snd_prod\n\nsection\n\nvariables (f' k')\n\n\n\nlemma is_O.prod_rightl (h : is_O f g' l) : is_O f (\u03bbx, (g' x, k' x)) l :=\nlet \u27e8c, cnonneg, hc\u27e9 := h.exists_nonneg in (hc.prod_rightl k' cnonneg).is_O\n\nlemma is_o.prod_rightl (h : is_o f g' l) : is_o f (\u03bb x, (g' x, k' x)) l :=\nis_o.of_is_O_with $\n\u03bb c cpos, (h.forall_is_O_with cpos).prod_rightl k' (le_of_lt cpos)\n\nlemma is_O_with.prod_rightr (h : is_O_with c f g' l) (hc : 0 \u2264 c) :\n  is_O_with c f (\u03bb x, (f' x, g' x)) l :=\n(h.trans is_O_with_snd_prod hc).congr_const (mul_one c)\n\nlemma is_O.prod_rightr (h : is_O f g' l) : is_O f (\u03bbx, (f' x, g' x)) l :=\nlet \u27e8c, cnonneg, hc\u27e9 := h.exists_nonneg in (hc.prod_rightr f' cnonneg).is_O\n\nlemma is_o.prod_rightr (h : is_o f g' l) : is_o f (\u03bbx, (f' x, g' x)) l :=\nis_o.of_is_O_with $\n\u03bb c cpos, (h.forall_is_O_with cpos).prod_rightr f' (le_of_lt cpos)\n\nend\n\nlemma is_O_with.prod_left_same (hf : is_O_with c f' k' l) (hg : is_O_with c g' k' l) :\n  is_O_with c (\u03bb x, (f' x, g' x)) k' l :=\nby rw is_O_with_iff at *; filter_upwards [hf, hg] with x using max_le\n\nlemma is_O_with.prod_left (hf : is_O_with c f' k' l) (hg : is_O_with c' g' k' l) :\n  is_O_with (max c c') (\u03bb x, (f' x, g' x)) k' l :=\n(hf.weaken $ le_max_left c c').prod_left_same (hg.weaken $ le_max_right c c')\n\nlemma is_O_with.prod_left_fst (h : is_O_with c (\u03bb x, (f' x, g' x)) k' l) :\n  is_O_with c f' k' l :=\n(is_O_with_fst_prod.trans h zero_le_one).congr_const $ one_mul c\n\nlemma is_O_with.prod_left_snd (h : is_O_with c (\u03bb x, (f' x, g' x)) k' l) :\n  is_O_with c g' k' l :=\n(is_O_with_snd_prod.trans h zero_le_one).congr_const $ one_mul c\n\nlemma is_O_with_prod_left :\n   is_O_with c (\u03bb x, (f' x, g' x)) k' l \u2194 is_O_with c f' k' l \u2227 is_O_with c g' k' l :=\n\u27e8\u03bb h, \u27e8h.prod_left_fst, h.prod_left_snd\u27e9, \u03bb h, h.1.prod_left_same h.2\u27e9\n\nlemma is_O.prod_left (hf : is_O f' k' l) (hg : is_O g' k' l) : is_O (\u03bb x, (f' x, g' x)) k' l :=\nlet \u27e8c, hf\u27e9 := hf.is_O_with, \u27e8c', hg\u27e9 := hg.is_O_with in (hf.prod_left hg).is_O\n\nlemma is_O.prod_left_fst (h : is_O (\u03bb x, (f' x, g' x)) k' l) : is_O f' k' l :=\nis_O_fst_prod.trans h\n\nlemma is_O.prod_left_snd (h : is_O (\u03bb x, (f' x, g' x)) k' l) : is_O g' k' l :=\nis_O_snd_prod.trans h\n\n@[simp] lemma is_O_prod_left :\n  is_O (\u03bb x, (f' x, g' x)) k' l \u2194 is_O f' k' l \u2227 is_O g' k' l :=\n\u27e8\u03bb h, \u27e8h.prod_left_fst, h.prod_left_snd\u27e9, \u03bb h, h.1.prod_left h.2\u27e9\n\nlemma is_o.prod_left (hf : is_o f' k' l) (hg : is_o g' k' l) : is_o (\u03bb x, (f' x, g' x)) k' l :=\nis_o.of_is_O_with $\n\u03bb c hc, (hf.forall_is_O_with hc).prod_left_same (hg.forall_is_O_with hc)\n\nlemma is_o.prod_left_fst (h : is_o (\u03bb x, (f' x, g' x)) k' l) : is_o f' k' l :=\nis_O_fst_prod.trans_is_o h\n\nlemma is_o.prod_left_snd (h : is_o (\u03bb x, (f' x, g' x)) k' l) : is_o g' k' l :=\nis_O_snd_prod.trans_is_o h\n\n@[simp] lemma is_o_prod_left :\n  is_o (\u03bb x, (f' x, g' x)) k' l \u2194 is_o f' k' l \u2227 is_o g' k' l :=\n\u27e8\u03bb h, \u27e8h.prod_left_fst, h.prod_left_snd\u27e9, \u03bb h, h.1.prod_left h.2\u27e9\n\nlemma is_O_with.eq_zero_imp (h : is_O_with c f' g' l) : \u2200\u1da0 x in l, g' x = 0 \u2192 f' x = 0 :=\neventually.mono h.bound $ \u03bb x hx hg, norm_le_zero_iff.1 $ by simpa [hg] using hx\n\nlemma is_O.eq_zero_imp (h : is_O f' g' l) : \u2200\u1da0 x in l, g' x = 0 \u2192 f' x = 0 :=\nlet \u27e8C, hC\u27e9 := h.is_O_with in hC.eq_zero_imp\n\n/-! ### Addition and subtraction -/\n\nsection add_sub\n\nvariables {c\u2081 c\u2082 : \u211d} {f\u2081 f\u2082 : \u03b1 \u2192 E'}\n\ntheorem is_O_with.add (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_O_with c\u2082 f\u2082 g l) :\n  is_O_with (c\u2081 + c\u2082) (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nby rw is_O_with at *; filter_upwards [h\u2081, h\u2082] with x hx\u2081 hx\u2082 using\ncalc \u2225f\u2081 x + f\u2082 x\u2225 \u2264 c\u2081 * \u2225g x\u2225 + c\u2082 * \u2225g x\u2225 : norm_add_le_of_le hx\u2081 hx\u2082\n               ... = (c\u2081 + c\u2082) * \u2225g x\u2225       : (add_mul _ _ _).symm\n\ntheorem is_O.add (h\u2081 : is_O f\u2081 g l) (h\u2082 : is_O f\u2082 g l) : is_O (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nlet \u27e8c\u2081, hc\u2081\u27e9 := h\u2081.is_O_with, \u27e8c\u2082, hc\u2082\u27e9 := h\u2082.is_O_with in (hc\u2081.add hc\u2082).is_O\n\ntheorem is_o.add (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_o f\u2082 g l) : is_o (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nis_o.of_is_O_with $ \u03bb c cpos, ((h\u2081.forall_is_O_with $ half_pos cpos).add\n  (h\u2082.forall_is_O_with $ half_pos cpos)).congr_const (add_halves c)\n\ntheorem is_o.add_add {g\u2081 g\u2082 : \u03b1 \u2192 F'} (h\u2081 : is_o f\u2081 g\u2081 l) (h\u2082 : is_o f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x + f\u2082 x) (\u03bb x, \u2225g\u2081 x\u2225 + \u2225g\u2082 x\u2225) l :=\nby refine (h\u2081.trans_le $ \u03bb x, _).add (h\u2082.trans_le _);\n  simp [real.norm_eq_abs, abs_of_nonneg, add_nonneg]\n\ntheorem is_O.add_is_o (h\u2081 : is_O f\u2081 g l) (h\u2082 : is_o f\u2082 g l) : is_O (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nh\u2081.add h\u2082.is_O\n\ntheorem is_o.add_is_O (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_O f\u2082 g l) : is_O (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nh\u2081.is_O.add h\u2082\n\ntheorem is_O_with.add_is_o (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_o f\u2082 g l) (hc : c\u2081 < c\u2082) :\n  is_O_with c\u2082 (\u03bbx, f\u2081 x + f\u2082 x) g l :=\n(h\u2081.add (h\u2082.forall_is_O_with (sub_pos.2 hc))).congr_const (add_sub_cancel'_right _ _)\n\ntheorem is_o.add_is_O_with (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_O_with c\u2081 f\u2082 g l) (hc : c\u2081 < c\u2082) :\n  is_O_with c\u2082 (\u03bbx, f\u2081 x + f\u2082 x) g l :=\n(h\u2082.add_is_o h\u2081 hc).congr_left $ \u03bb _, add_comm _ _\n\ntheorem is_O_with.sub (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_O_with c\u2082 f\u2082 g l) :\n  is_O_with (c\u2081 + c\u2082) (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add h\u2082.neg_left\n\ntheorem is_O_with.sub_is_o (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_o f\u2082 g l) (hc : c\u2081 < c\u2082) :\n  is_O_with c\u2082 (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add_is_o h\u2082.neg_left hc\n\ntheorem is_O.sub (h\u2081 : is_O f\u2081 g l) (h\u2082 : is_O f\u2082 g l) : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add h\u2082.neg_left\n\ntheorem is_o.sub (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_o f\u2082 g l) : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add h\u2082.neg_left\n\nend add_sub\n\n/-! ### Lemmas about `is_O (f\u2081 - f\u2082) g l` / `is_o (f\u2081 - f\u2082) g l` treated as a binary relation -/\n\nsection is_oO_as_rel\n\nvariables {f\u2081 f\u2082 f\u2083 : \u03b1 \u2192 E'}\n\ntheorem is_O_with.symm (h : is_O_with c (\u03bb x, f\u2081 x - f\u2082 x) g l) :\n  is_O_with c (\u03bb x, f\u2082 x - f\u2081 x) g l :=\nh.neg_left.congr_left $ \u03bb x, neg_sub _ _\n\ntheorem is_O_with_comm :\n  is_O_with c (\u03bb x, f\u2081 x - f\u2082 x) g l \u2194 is_O_with c (\u03bb x, f\u2082 x - f\u2081 x) g l :=\n\u27e8is_O_with.symm, is_O_with.symm\u27e9\n\ntheorem is_O.symm (h : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l) : is_O (\u03bb x, f\u2082 x - f\u2081 x) g l :=\nh.neg_left.congr_left $ \u03bb x, neg_sub _ _\n\ntheorem is_O_comm : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l \u2194 is_O (\u03bb x, f\u2082 x - f\u2081 x) g l :=\n\u27e8is_O.symm, is_O.symm\u27e9\n\ntheorem is_o.symm (h : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l) : is_o (\u03bb x, f\u2082 x - f\u2081 x) g l :=\nby simpa only [neg_sub] using h.neg_left\n\ntheorem is_o_comm : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l \u2194 is_o (\u03bb x, f\u2082 x - f\u2081 x) g l :=\n\u27e8is_o.symm, is_o.symm\u27e9\n\ntheorem is_O_with.triangle (h\u2081 : is_O_with c (\u03bb x, f\u2081 x - f\u2082 x) g l)\n  (h\u2082 : is_O_with c' (\u03bb x, f\u2082 x - f\u2083 x) g l) :\n  is_O_with (c + c') (\u03bb x, f\u2081 x - f\u2083 x) g l :=\n(h\u2081.add h\u2082).congr_left $ \u03bb x, sub_add_sub_cancel _ _ _\n\ntheorem is_O.triangle (h\u2081 : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l) (h\u2082 : is_O (\u03bb x, f\u2082 x - f\u2083 x) g l) :\n  is_O (\u03bb x, f\u2081 x - f\u2083 x) g l :=\n(h\u2081.add h\u2082).congr_left $ \u03bb x, sub_add_sub_cancel _ _ _\n\ntheorem is_o.triangle (h\u2081 : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l) (h\u2082 : is_o (\u03bb x, f\u2082 x - f\u2083 x) g l) :\n  is_o (\u03bb x, f\u2081 x - f\u2083 x) g l :=\n(h\u2081.add h\u2082).congr_left $ \u03bb x, sub_add_sub_cancel _ _ _\n\ntheorem is_O.congr_of_sub (h : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l) :\n  is_O f\u2081 g l \u2194 is_O f\u2082 g l :=\n\u27e8\u03bb h', (h'.sub h).congr_left (\u03bb x, sub_sub_cancel _ _),\n \u03bb h', (h.add h').congr_left (\u03bb x, sub_add_cancel _ _)\u27e9\n\ntheorem is_o.congr_of_sub (h : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l) :\n  is_o f\u2081 g l \u2194 is_o f\u2082 g l :=\n\u27e8\u03bb h', (h'.sub h).congr_left (\u03bb x, sub_sub_cancel _ _),\n \u03bb h', (h.add h').congr_left (\u03bb x, sub_add_cancel _ _)\u27e9\n\nend is_oO_as_rel\n\n/-! ### Zero, one, and other constants -/\n\nsection zero_const\n\nvariables (g g' l)\n\ntheorem is_o_zero : is_o (\u03bb x, (0 : E')) g' l :=\nis_o.of_bound $ \u03bb c hc, univ_mem' $ \u03bb x,\nby simpa using mul_nonneg hc.le (norm_nonneg $ g' x)\n\ntheorem is_O_with_zero (hc : 0 \u2264 c) : is_O_with c (\u03bb x, (0 : E')) g' l :=\nis_O_with.of_bound $ univ_mem' $ \u03bb x, by simpa using mul_nonneg hc (norm_nonneg $ g' x)\n\ntheorem is_O_with_zero' : is_O_with 0 (\u03bb x, (0 : E')) g l :=\nis_O_with.of_bound $ univ_mem' $ \u03bb x, by simp\n\ntheorem is_O_zero : is_O (\u03bb x, (0 : E')) g l :=\nis_O_iff_is_O_with.2 \u27e80, is_O_with_zero' _ _\u27e9\n\ntheorem is_O_refl_left : is_O (\u03bb x, f' x - f' x) g' l :=\n(is_O_zero g' l).congr_left $ \u03bb x, (sub_self _).symm\n\ntheorem is_o_refl_left : is_o (\u03bb x, f' x - f' x) g' l :=\n(is_o_zero g' l).congr_left $ \u03bb x, (sub_self _).symm\n\nvariables {g g' l}\n\n@[simp] theorem is_O_with_zero_right_iff :\n  is_O_with c f' (\u03bb x, (0 : F')) l \u2194 \u2200\u1da0 x in l, f' x = 0 :=\nby simp only [is_O_with, exists_prop, true_and, norm_zero, mul_zero, norm_le_zero_iff]\n\n@[simp] theorem is_O_zero_right_iff : is_O f' (\u03bb x, (0 : F')) l \u2194 \u2200\u1da0 x in l, f' x = 0 :=\n\u27e8\u03bb h, let \u27e8c, hc\u27e9 := h.is_O_with in is_O_with_zero_right_iff.1 hc,\n  \u03bb h, (is_O_with_zero_right_iff.2 h : is_O_with 1 _ _ _).is_O\u27e9\n\n@[simp] theorem is_o_zero_right_iff :\n  is_o f' (\u03bb x, (0 : F')) l \u2194 \u2200\u1da0 x in l, f' x = 0 :=\n\u27e8\u03bb h, is_O_zero_right_iff.1 h.is_O,\n  \u03bb h, is_o.of_is_O_with $ \u03bb c hc, is_O_with_zero_right_iff.2 h\u27e9\n\ntheorem is_O_with_const_const (c : E) {c' : F'} (hc' : c' \u2260 0) (l : filter \u03b1) :\n  is_O_with (\u2225c\u2225 / \u2225c'\u2225) (\u03bb x : \u03b1, c) (\u03bb x, c') l :=\nbegin\n  unfold is_O_with,\n  apply univ_mem',\n  intro x,\n  rw [mem_set_of_eq, div_mul_cancel],\n  rwa [ne.def, norm_eq_zero]\nend\n\ntheorem is_O_const_const (c : E) {c' : F'} (hc' : c' \u2260 0) (l : filter \u03b1) :\n  is_O (\u03bb x : \u03b1, c) (\u03bb x, c') l :=\n(is_O_with_const_const c hc' l).is_O\n\nend zero_const\n\n@[simp] lemma is_O_with_top : is_O_with c f g \u22a4 \u2194 \u2200 x, \u2225f x\u2225 \u2264 c * \u2225g x\u2225 := by rw is_O_with; refl\n\n@[simp] lemma is_O_top : is_O f g \u22a4 \u2194 \u2203 C, \u2200 x, \u2225f x\u2225 \u2264 C * \u2225g x\u2225 := by rw is_O_iff; refl\n\n@[simp] lemma is_o_top : is_o f' g' \u22a4 \u2194 \u2200 x, f' x = 0 :=\nbegin\n  refine \u27e8_, \u03bb h, (is_o_zero g' \u22a4).congr (\u03bb x, (h x).symm) (\u03bb x, rfl)\u27e9,\n  simp only [is_o_iff, eventually_top],\n  refine \u03bb h x, norm_le_zero_iff.1 _,\n  have : tendsto (\u03bb c : \u211d, c * \u2225g' x\u2225) (\ud835\udcdd[>] 0) (\ud835\udcdd 0) :=\n    ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left,\n  exact le_of_tendsto_of_tendsto tendsto_const_nhds this\n    (eventually_nhds_within_iff.2 $ eventually_of_forall $ \u03bb c hc, h hc x)\nend\n\n@[simp] lemma is_O_with_principal {s : set \u03b1} :\n  is_O_with c f g (\ud835\udcdf s) \u2194 \u2200 x \u2208 s, \u2225f x\u2225 \u2264 c * \u2225g x\u2225 :=\nby rw is_O_with; refl\n\nlemma is_O_principal {s : set \u03b1} :\n  is_O f g (\ud835\udcdf s) \u2194 \u2203 c, \u2200 x \u2208 s, \u2225f x\u2225 \u2264 c * \u2225g x\u2225 :=\nby rw is_O_iff; refl\n\ntheorem is_O_with_const_one (c : E) (l : filter \u03b1) : is_O_with \u2225c\u2225 (\u03bb x : \u03b1, c) (\u03bb x, (1 : \ud835\udd5c)) l :=\nbegin\n  refine (is_O_with_const_const c _ l).congr_const _,\n  { rw [norm_one, div_one] },\n  { exact one_ne_zero }\nend\n\ntheorem is_O_const_one (c : E) (l : filter \u03b1) : is_O (\u03bb x : \u03b1, c) (\u03bb x, (1 : \ud835\udd5c)) l :=\n(is_O_with_const_one c l).is_O\n\nsection\n\nvariable (\ud835\udd5c)\n\ntheorem is_o_const_iff_is_o_one {c : F'} (hc : c \u2260 0) :\n  is_o f (\u03bb x, c) l \u2194 is_o f (\u03bb x, (1:\ud835\udd5c)) l :=\n\u27e8\u03bb h, h.trans_is_O $ is_O_const_one c l, \u03bb h, h.trans_is_O $ is_O_const_const _ hc _\u27e9\n\nend\n\ntheorem is_o_const_iff {c : F'} (hc : c \u2260 0) :\n  is_o f' (\u03bb x, c) l \u2194 tendsto f' l (\ud835\udcdd 0) :=\n(is_o_const_iff_is_o_one \u211d hc).trans\nbegin\n  clear hc c,\n  simp only [is_o, is_O_with, norm_one, mul_one, metric.nhds_basis_closed_ball.tendsto_right_iff,\n    metric.mem_closed_ball, dist_zero_right]\nend\n\ntheorem is_o_const_const_iff [ne_bot l] {d : E'} {c : F'} (hc : c \u2260 0) :\n  is_o (\u03bb x, d) (\u03bb x, c) l \u2194 d = 0 :=\nbegin\n  rw is_o_const_iff hc,\n  refine \u27e8\u03bb h, tendsto_nhds_unique tendsto_const_nhds h, _\u27e9,\n  rintros rfl,\n  exact tendsto_const_nhds,\nend\n\nlemma is_o_id_const {c : F'} (hc : c \u2260 0) :\n  is_o (\u03bb (x : E'), x) (\u03bb x, c) (\ud835\udcdd 0) :=\n(is_o_const_iff hc).mpr (continuous_id.tendsto 0)\n\ntheorem _root_.filter.is_bounded_under.is_O_const (h : is_bounded_under (\u2264) l (norm \u2218 f))\n  {c : F'} (hc : c \u2260 0) : is_O f (\u03bb x, c) l :=\nbegin\n  rcases h with \u27e8C, hC\u27e9,\n  refine (is_O.of_bound 1 _).trans (is_O_const_const C hc l),\n  refine (eventually_map.1 hC).mono (\u03bb x h, _),\n  calc \u2225f x\u2225 \u2264 C : h\n  ... \u2264 abs C : le_abs_self C\n  ... = 1 * \u2225C\u2225 : (one_mul _).symm\nend\n\ntheorem is_O_const_of_tendsto {y : E'} (h : tendsto f' l (\ud835\udcdd y)) {c : F'} (hc : c \u2260 0) :\n  is_O f' (\u03bb x, c) l :=\nh.norm.is_bounded_under_le.is_O_const hc\n\nsection\n\nvariable (\ud835\udd5c)\n\ntheorem is_o_one_iff : is_o f' (\u03bb x, (1 : \ud835\udd5c)) l \u2194 tendsto f' l (\ud835\udcdd 0) :=\nis_o_const_iff one_ne_zero\n\ntheorem is_O_one_of_tendsto {y : E'} (h : tendsto f' l (\ud835\udcdd y)) :\n  is_O f' (\u03bb x, (1:\ud835\udd5c)) l :=\nis_O_const_of_tendsto h one_ne_zero\n\ntheorem is_O.trans_tendsto_nhds (hfg : is_O f g' l) {y : F'} (hg : tendsto g' l (\ud835\udcdd y)) :\n  is_O f (\u03bb x, (1:\ud835\udd5c)) l :=\nhfg.trans $ is_O_one_of_tendsto \ud835\udd5c hg\n\nend\n\ntheorem is_O.trans_tendsto (hfg : is_O f' g' l) (hg : tendsto g' l (\ud835\udcdd 0)) :\n  tendsto f' l (\ud835\udcdd 0) :=\n(is_o_one_iff \u211d).1 $ hfg.trans_is_o $ (is_o_one_iff \u211d).2 hg\n\ntheorem is_o.trans_tendsto (hfg : is_o f' g' l) (hg : tendsto g' l (\ud835\udcdd 0)) :\n  tendsto f' l (\ud835\udcdd 0) :=\nhfg.is_O.trans_tendsto hg\n\n/-! ### Multiplication by a constant -/\n\ntheorem is_O_with_const_mul_self (c : R) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O_with \u2225c\u2225 (\u03bb x, c * f x) f l :=\nis_O_with_of_le' _ $ \u03bb x, norm_mul_le _ _\n\ntheorem is_O_const_mul_self (c : R) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O (\u03bb x, c * f x) f l :=\n(is_O_with_const_mul_self c f l).is_O\n\ntheorem is_O_with.const_mul_left {f : \u03b1 \u2192 R} (h : is_O_with c f g l) (c' : R) :\n  is_O_with (\u2225c'\u2225 * c) (\u03bb x, c' * f x) g l :=\n(is_O_with_const_mul_self c' f l).trans h (norm_nonneg c')\n\ntheorem is_O.const_mul_left {f : \u03b1 \u2192 R} (h : is_O f g l) (c' : R) :\n  is_O (\u03bb x, c' * f x) g l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in (hc.const_mul_left c').is_O\n\ntheorem is_O_with_self_const_mul' (u : R\u02e3) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O_with \u2225(\u2191u\u207b\u00b9:R)\u2225 f (\u03bb x, \u2191u * f x) l :=\n(is_O_with_const_mul_self \u2191u\u207b\u00b9 _ l).congr_left $ \u03bb x, u.inv_mul_cancel_left (f x)\n\ntheorem is_O_with_self_const_mul (c : \ud835\udd5c) (hc : c \u2260 0) (f : \u03b1 \u2192 \ud835\udd5c) (l : filter \u03b1) :\n  is_O_with \u2225c\u2225\u207b\u00b9 f (\u03bb x, c * f x) l :=\n(is_O_with_self_const_mul' (units.mk0 c hc) f l).congr_const $\n  normed_field.norm_inv c\n\ntheorem is_O_self_const_mul' {c : R} (hc : is_unit c) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O f (\u03bb x, c * f x) l :=\nlet \u27e8u, hu\u27e9 := hc in hu \u25b8 (is_O_with_self_const_mul' u f l).is_O\n\ntheorem is_O_self_const_mul (c : \ud835\udd5c) (hc : c \u2260 0) (f : \u03b1 \u2192 \ud835\udd5c) (l : filter \u03b1) :\n  is_O f (\u03bb x, c * f x) l :=\nis_O_self_const_mul' (is_unit.mk0 c hc) f l\n\ntheorem is_O_const_mul_left_iff' {f : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_O (\u03bb x, c * f x) g l \u2194 is_O f g l :=\n\u27e8(is_O_self_const_mul' hc f l).trans, \u03bb h, h.const_mul_left c\u27e9\n\ntheorem is_O_const_mul_left_iff {f : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O (\u03bb x, c * f x) g l \u2194 is_O f g l :=\nis_O_const_mul_left_iff' $ is_unit.mk0 c hc\n\ntheorem is_o.const_mul_left {f : \u03b1 \u2192 R} (h : is_o f g l) (c : R) :\n  is_o (\u03bb x, c * f x) g l :=\n(is_O_const_mul_self c f l).trans_is_o h\n\ntheorem is_o_const_mul_left_iff' {f : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_o (\u03bb x, c * f x) g l \u2194 is_o f g l :=\n\u27e8(is_O_self_const_mul' hc f l).trans_is_o, \u03bb h, h.const_mul_left c\u27e9\n\ntheorem is_o_const_mul_left_iff {f : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o (\u03bb x, c * f x) g l \u2194 is_o f g l :=\nis_o_const_mul_left_iff' $ is_unit.mk0 c hc\n\ntheorem is_O_with.of_const_mul_right {g : \u03b1 \u2192 R} {c : R} (hc' : 0 \u2264 c')\n  (h : is_O_with c' f (\u03bb x, c * g x) l) :\n  is_O_with (c' * \u2225c\u2225) f g l :=\nh.trans (is_O_with_const_mul_self c g l) hc'\n\ntheorem is_O.of_const_mul_right {g : \u03b1 \u2192 R} {c : R}\n  (h : is_O f (\u03bb x, c * g x) l) :\n  is_O f g l :=\nlet \u27e8c, cnonneg, hc\u27e9 := h.exists_nonneg in (hc.of_const_mul_right cnonneg).is_O\n\ntheorem is_O_with.const_mul_right' {g : \u03b1 \u2192 R} {u : R\u02e3} {c' : \u211d} (hc' : 0 \u2264 c')\n  (h : is_O_with c' f g l) :\n  is_O_with (c' * \u2225(\u2191u\u207b\u00b9:R)\u2225) f (\u03bb x, \u2191u * g x) l :=\nh.trans (is_O_with_self_const_mul' _ _ _) hc'\n\ntheorem is_O_with.const_mul_right {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0)\n  {c' : \u211d} (hc' : 0 \u2264 c') (h : is_O_with c' f g l) :\n  is_O_with (c' * \u2225c\u2225\u207b\u00b9) f (\u03bb x, c * g x) l :=\nh.trans (is_O_with_self_const_mul c hc g l) hc'\n\ntheorem is_O.const_mul_right' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) (h : is_O f g l) :\n  is_O f (\u03bb x, c * g x) l :=\nh.trans (is_O_self_const_mul' hc g l)\n\ntheorem is_O.const_mul_right {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) (h : is_O f g l) :\n  is_O f (\u03bb x, c * g x) l :=\nh.const_mul_right' $ is_unit.mk0 c hc\n\ntheorem is_O_const_mul_right_iff' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_O f (\u03bb x, c * g x) l \u2194 is_O f g l :=\n\u27e8\u03bb h, h.of_const_mul_right, \u03bb h, h.const_mul_right' hc\u27e9\n\ntheorem is_O_const_mul_right_iff {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O f (\u03bb x, c * g x) l \u2194 is_O f g l :=\nis_O_const_mul_right_iff' $ is_unit.mk0 c hc\n\ntheorem is_o.of_const_mul_right {g : \u03b1 \u2192 R} {c : R} (h : is_o f (\u03bb x, c * g x) l) :\n  is_o f g l :=\nh.trans_is_O (is_O_const_mul_self c g l)\n\ntheorem is_o.const_mul_right' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) (h : is_o f g l) :\n  is_o f (\u03bb x, c * g x) l :=\nh.trans_is_O (is_O_self_const_mul' hc g l)\n\ntheorem is_o.const_mul_right {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) (h : is_o f g l) :\n  is_o f (\u03bb x, c * g x) l :=\nh.const_mul_right' $ is_unit.mk0 c hc\n\ntheorem is_o_const_mul_right_iff' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_o f (\u03bb x, c * g x) l \u2194 is_o f g l :=\n\u27e8\u03bb h, h.of_const_mul_right, \u03bb h, h.const_mul_right' hc\u27e9\n\ntheorem is_o_const_mul_right_iff {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o f (\u03bb x, c * g x) l \u2194 is_o f g l :=\nis_o_const_mul_right_iff' $ is_unit.mk0 c hc\n\n/-! ### Multiplication -/\n\ntheorem is_O_with.mul {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c} {c\u2081 c\u2082 : \u211d}\n  (h\u2081 : is_O_with c\u2081 f\u2081 g\u2081 l) (h\u2082 : is_O_with c\u2082 f\u2082 g\u2082 l) :\n  is_O_with (c\u2081 * c\u2082) (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nbegin\n  unfold is_O_with at *,\n  filter_upwards [h\u2081, h\u2082] with _ hx\u2081 hx\u2082,\n  apply le_trans (norm_mul_le _ _),\n  convert mul_le_mul hx\u2081 hx\u2082 (norm_nonneg _) (le_trans (norm_nonneg _) hx\u2081) using 1,\n  rw normed_field.norm_mul,\n  ac_refl\nend\n\ntheorem is_O.mul {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c}\n  (h\u2081 : is_O f\u2081 g\u2081 l) (h\u2082 : is_O f\u2082 g\u2082 l) :\n  is_O (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nlet \u27e8c, hc\u27e9 := h\u2081.is_O_with, \u27e8c', hc'\u27e9 := h\u2082.is_O_with in (hc.mul hc').is_O\n\ntheorem is_O.mul_is_o {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c}\n  (h\u2081 : is_O f\u2081 g\u2081 l) (h\u2082 : is_o f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nbegin\n  unfold is_o at *,\n  intros c cpos,\n  rcases h\u2081.exists_pos with \u27e8c', c'pos, hc'\u27e9,\n  exact (hc'.mul (h\u2082 (div_pos cpos c'pos))).congr_const (mul_div_cancel' _ (ne_of_gt c'pos))\nend\n\ntheorem is_o.mul_is_O {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c}\n  (h\u2081 : is_o f\u2081 g\u2081 l) (h\u2082 : is_O f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nbegin\n  unfold is_o at *,\n  intros c cpos,\n  rcases h\u2082.exists_pos with \u27e8c', c'pos, hc'\u27e9,\n  exact ((h\u2081 (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel _ (ne_of_gt c'pos))\nend\n\ntheorem is_o.mul {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_o f\u2081 g\u2081 l) (h\u2082 : is_o f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nh\u2081.mul_is_O h\u2082.is_O\n\ntheorem is_O_with.pow' {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_O_with c f g l) :\n  \u2200 n : \u2115, is_O_with (nat.cases_on n \u2225(1 : R)\u2225 (\u03bb n, c ^ (n + 1))) (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l\n| 0 := by simpa using is_O_with_const_const (1 : R) (@one_ne_zero \ud835\udd5c _ _) l\n| 1 := by simpa\n| (n + 2) := by simpa [pow_succ] using h.mul (is_O_with.pow' (n + 1))\n\ntheorem is_O_with.pow [norm_one_class R] {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_O_with c f g l) :\n  \u2200 n : \u2115, is_O_with (c ^ n) (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l\n| 0 := by simpa using h.pow' 0\n| (n + 1) := h.pow' (n + 1)\n\ntheorem is_O.pow {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_O f g l) (n : \u2115) :\n  is_O (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l :=\nlet \u27e8C, hC\u27e9 := h.is_O_with in is_O_iff_is_O_with.2 \u27e8_, hC.pow' n\u27e9\n\ntheorem is_o.pow {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_o f g l) {n : \u2115} (hn : 0 < n) :\n  is_o (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l :=\nbegin\n  cases n, exact hn.false.elim, clear hn,\n  induction n with n ihn, { simpa only [pow_one] },\n  convert h.mul ihn; simp [pow_succ]\nend\n\n/-! ### Inverse -/\n\ntheorem is_O_with.inv_rev {f : \u03b1 \u2192 \ud835\udd5c} {g : \u03b1 \u2192 \ud835\udd5c'} (h : is_O_with c f g l)\n  (h\u2080 : \u2200\u1da0 x in l, f x \u2260 0) : is_O_with c (\u03bb x, (g x)\u207b\u00b9) (\u03bb x, (f x)\u207b\u00b9) l :=\nbegin\n  refine is_O_with.of_bound (h.bound.mp (h\u2080.mono $ \u03bb x h\u2080 hle, _)),\n  cases le_or_lt c 0 with hc hc,\n  { refine (h\u2080 $ norm_le_zero_iff.1 _).elim,\n    exact hle.trans (mul_nonpos_of_nonpos_of_nonneg hc $ norm_nonneg _) },\n  { replace hle := inv_le_inv_of_le (norm_pos_iff.2 h\u2080) hle,\n    simpa only [normed_field.norm_inv, mul_inv\u2080, \u2190 div_eq_inv_mul, div_le_iff hc] using hle }\nend\n\ntheorem is_O.inv_rev {f : \u03b1 \u2192 \ud835\udd5c} {g : \u03b1 \u2192 \ud835\udd5c'} (h : is_O f g l)\n  (h\u2080 : \u2200\u1da0 x in l, f x \u2260 0) : is_O (\u03bb x, (g x)\u207b\u00b9) (\u03bb x, (f x)\u207b\u00b9) l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in (hc.inv_rev h\u2080).is_O\n\ntheorem is_o.inv_rev {f : \u03b1 \u2192 \ud835\udd5c} {g : \u03b1 \u2192 \ud835\udd5c'} (h : is_o f g l)\n  (h\u2080 : \u2200\u1da0 x in l, f x \u2260 0) : is_o (\u03bb x, (g x)\u207b\u00b9) (\u03bb x, (f x)\u207b\u00b9) l :=\nis_o.of_is_O_with $ \u03bb c hc, (h.def' hc).inv_rev h\u2080\n\n/-! ### Scalar multiplication -/\n\nsection smul_const\nvariables [normed_space \ud835\udd5c E']\n\ntheorem is_O_with.const_smul_left (h : is_O_with c f' g l) (c' : \ud835\udd5c) :\n  is_O_with (\u2225c'\u2225 * c) (\u03bb x, c' \u2022 f' x) g l :=\nby refine ((h.norm_left.const_mul_left (\u2225c'\u2225)).congr _ _ (\u03bb _, rfl)).of_norm_left;\n    intros; simp only [norm_norm, norm_smul]\n\ntheorem is_O_const_smul_left_iff {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O (\u03bb x, c \u2022 f' x) g l \u2194 is_O f' g l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_O_norm_left], simp only [norm_smul],\n  rw [is_O_const_mul_left_iff cne0, is_O_norm_left],\nend\n\ntheorem is_o_const_smul_left (h : is_o f' g l) (c : \ud835\udd5c) :\n  is_o (\u03bb x, c \u2022 f' x) g l :=\nbegin\n  refine ((h.norm_left.const_mul_left (\u2225c\u2225)).congr_left _).of_norm_left,\n  exact \u03bb x, (norm_smul _ _).symm\nend\n\ntheorem is_o_const_smul_left_iff {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o (\u03bb x, c \u2022 f' x) g l \u2194 is_o f' g l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_o_norm_left], simp only [norm_smul],\n  rw [is_o_const_mul_left_iff cne0, is_o_norm_left]\nend\n\ntheorem is_O_const_smul_right {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O f (\u03bb x, c \u2022 f' x) l \u2194 is_O f f' l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_O_norm_right], simp only [norm_smul],\n  rw [is_O_const_mul_right_iff cne0, is_O_norm_right]\nend\n\ntheorem is_o_const_smul_right {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o f (\u03bb x, c \u2022 f' x) l \u2194 is_o f f' l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_o_norm_right], simp only [norm_smul],\n  rw [is_o_const_mul_right_iff cne0, is_o_norm_right]\nend\n\nend smul_const\n\nsection smul\n\nvariables [normed_space \ud835\udd5c E'] [normed_space \ud835\udd5c F']\n\ntheorem is_O_with.smul {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_O_with c k\u2081 k\u2082 l) (h\u2082 : is_O_with c' f' g' l) :\n  is_O_with (c * c') (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul h\u2082.norm_norm).congr rfl _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_O.smul {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_O k\u2081 k\u2082 l) (h\u2082 : is_O f' g' l) :\n  is_O (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_O.smul_is_o {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_O k\u2081 k\u2082 l) (h\u2082 : is_o f' g' l) :\n  is_o (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul_is_o h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_o.smul_is_O {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_o k\u2081 k\u2082 l) (h\u2082 : is_O f' g' l) :\n  is_o (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul_is_O h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_o.smul {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_o k\u2081 k\u2082 l) (h\u2082 : is_o f' g' l) :\n  is_o (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\nend smul\n\n/-! ### Sum -/\n\nsection sum\n\nvariables {\u03b9 : Type*} {A : \u03b9 \u2192 \u03b1 \u2192 E'} {C : \u03b9 \u2192 \u211d} {s : finset \u03b9}\n\ntheorem is_O_with.sum (h : \u2200 i \u2208 s, is_O_with (C i) (A i) g l) :\n  is_O_with (\u2211 i in s, C i) (\u03bb x, \u2211 i in s, A i x) g l :=\nbegin\n  induction s using finset.induction_on with i s is IH,\n  { simp only [is_O_with_zero', finset.sum_empty, forall_true_iff] },\n  { simp only [is, finset.sum_insert, not_false_iff],\n    exact (h _ (finset.mem_insert_self i s)).add (IH (\u03bb j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\ntheorem is_O.sum (h : \u2200 i \u2208 s, is_O (A i) g l) :\n  is_O (\u03bb x, \u2211 i in s, A i x) g l :=\nbegin\n  induction s using finset.induction_on with i s is IH,\n  { simp only [is_O_zero, finset.sum_empty, forall_true_iff] },\n  { simp only [is, finset.sum_insert, not_false_iff],\n    exact (h _ (finset.mem_insert_self i s)).add (IH (\u03bb j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\ntheorem is_o.sum (h : \u2200 i \u2208 s, is_o (A i) g' l) :\n  is_o (\u03bb x, \u2211 i in s, A i x) g' l :=\nbegin\n  induction s using finset.induction_on with i s is IH,\n  { simp only [is_o_zero, finset.sum_empty, forall_true_iff] },\n  { simp only [is, finset.sum_insert, not_false_iff],\n    exact (h _ (finset.mem_insert_self i s)).add (IH (\u03bb j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\nend sum\n\n/-! ### Relation between `f = o(g)` and `f / g \u2192 0` -/\n\ntheorem is_o.tendsto_div_nhds_zero {f g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1} (h : is_o f g l) :\n  tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0) :=\nhave eq\u2081 : is_o (\u03bb x, f x / g x) (\u03bb x, g x / g x) l,\n  by simpa only [div_eq_mul_inv] using h.mul_is_O (is_O_refl _ _),\nhave eq\u2082 : is_O (\u03bb x, g x / g x) (\u03bb x, (1 : \ud835\udd5c)) l,\n  from is_O_of_le _ (\u03bb x, by simp [div_self_le_one]),\n(is_o_one_iff \ud835\udd5c).mp (eq\u2081.trans_is_O eq\u2082)\n\ntheorem is_o.tendsto_inv_smul_nhds_zero [normed_space \ud835\udd5c E'] {f : \u03b1 \u2192 E'} {g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n  (h : is_o f g l) : tendsto (\u03bb x, (g x)\u207b\u00b9 \u2022 f x) l (\ud835\udcdd 0) :=\nby simpa only [div_eq_inv_mul, \u2190 normed_field.norm_inv, \u2190 norm_smul,\n  \u2190 tendsto_zero_iff_norm_tendsto_zero] using h.norm_norm.tendsto_div_nhds_zero\n\ntheorem is_o_iff_tendsto' {f g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n    (hgf : \u2200\u1da0 x in l, g x = 0 \u2192 f x = 0) :\n  is_o f g l \u2194 tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0) :=\niff.intro is_o.tendsto_div_nhds_zero $ \u03bb h,\n  (((is_o_one_iff _).mpr h).mul_is_O (is_O_refl g l)).congr'\n    (hgf.mono $ \u03bb x, div_mul_cancel_of_imp) (eventually_of_forall $ \u03bb x, one_mul _)\n\ntheorem is_o_iff_tendsto {f g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n    (hgf : \u2200 x, g x = 0 \u2192 f x = 0) :\n  is_o f g l \u2194 tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h, h.tendsto_div_nhds_zero, (is_o_iff_tendsto' (eventually_of_forall hgf)).2\u27e9\n\nalias is_o_iff_tendsto' \u2194 _ asymptotics.is_o_of_tendsto'\nalias is_o_iff_tendsto \u2194 _ asymptotics.is_o_of_tendsto\n\nlemma is_o_const_left_of_ne {c : E'} (hc : c \u2260 0) :\n  is_o (\u03bb x, c) g l \u2194 tendsto (norm \u2218 g) l at_top :=\nbegin\n  split; intro h,\n  { refine (at_top_basis' 1).tendsto_right_iff.2 (\u03bb C hC, _),\n    replace hC : 0 < C := zero_lt_one.trans_le hC,\n    replace h : is_o (\u03bb _, 1 : \u03b1 \u2192 \u211d) g l := (is_O_const_const _ hc _).trans_is_o h,\n    refine (h.def $ inv_pos.2 hC).mono (\u03bb x hx, _),\n    rwa [norm_one, \u2190 div_eq_inv_mul, one_le_div hC] at hx },\n  { suffices : is_o (\u03bb _, 1 : \u03b1 \u2192 \u211d) g l,\n      from (is_O_const_const c (@one_ne_zero \u211d _ _) _).trans_is_o this,\n    refine is_o_iff.2 (\u03bb \u03b5 \u03b50, (tendsto_at_top.1 h \u03b5\u207b\u00b9).mono (\u03bb x hx, _)),\n    rwa [norm_one, \u2190 inv_inv\u2080 \u03b5, \u2190 div_eq_inv_mul, one_le_div (inv_pos.2 \u03b50)] }\nend\n\n@[simp] lemma is_o_const_left {c : E'} :\n  is_o (\u03bb x, c) g' l \u2194 c = 0 \u2228 tendsto (norm \u2218 g') l at_top :=\nbegin\n  rcases eq_or_ne c 0 with rfl | hc,\n  { simp only [is_o_zero, eq_self_iff_true, true_or] },\n  { simp only [hc, false_or, is_o_const_left_of_ne hc] }\nend\n\n/-!\n### Eventually (u / v) * v = u\n\nIf `u` and `v` are linked by an `is_O_with` relation, then we\neventually have `(u / v) * v = u`, even if `v` vanishes.\n-/\n\nsection eventually_mul_div_cancel\n\nvariables {u v : \u03b1 \u2192 \ud835\udd5c}\n\nlemma is_O_with.eventually_mul_div_cancel (h : is_O_with c u v l) :\n  (u / v) * v =\u1da0[l] u :=\neventually.mono h.bound (\u03bb y hy, div_mul_cancel_of_imp $ \u03bb hv, by simpa [hv] using hy)\n\n/-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/\nlemma is_O.eventually_mul_div_cancel (h : is_O u v l) :  (u / v) * v =\u1da0[l] u :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in hc.eventually_mul_div_cancel\n\n/-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/\nlemma is_o.eventually_mul_div_cancel (h : is_o u v l) : (u / v) * v =\u1da0[l] u :=\n(h.forall_is_O_with zero_lt_one).eventually_mul_div_cancel\n\nend eventually_mul_div_cancel\n\n/-! ### Equivalent definitions of the form `\u2203 \u03c6, u =\u1da0[l] \u03c6 * v` in a `normed_field`. -/\n\nsection exists_mul_eq\n\nvariables {u v : \u03b1 \u2192 \ud835\udd5c}\n\n/-- If `\u2225\u03c6\u2225` is eventually bounded by `c`, and `u =\u1da0[l] \u03c6 * v`, then we have `is_O_with c u v l`.\n    This does not require any assumptions on `c`, which is why we keep this version along with\n    `is_O_with_iff_exists_eq_mul`. -/\nlemma is_O_with_of_eq_mul (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : \u2200\u1da0 x in l, \u2225\u03c6 x\u2225 \u2264 c) (h : u =\u1da0[l] \u03c6 * v) :\n  is_O_with c u v l :=\nbegin\n  unfold is_O_with,\n  refine h.symm.rw (\u03bb x a, \u2225a\u2225 \u2264 c * \u2225v x\u2225) (h\u03c6.mono $ \u03bb x hx, _),\n  simp only [normed_field.norm_mul, pi.mul_apply],\n  exact mul_le_mul_of_nonneg_right hx (norm_nonneg _)\nend\n\nlemma is_O_with_iff_exists_eq_mul (hc : 0 \u2264 c) :\n  is_O_with c u v l \u2194 \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : \u2200\u1da0 x in l, \u2225\u03c6 x\u2225 \u2264 c), u =\u1da0[l] \u03c6 * v :=\nbegin\n  split,\n  { intro h,\n    use (\u03bb x, u x / v x),\n    refine \u27e8eventually.mono h.bound (\u03bb y hy, _), h.eventually_mul_div_cancel.symm\u27e9,\n    simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy },\n  { rintros \u27e8\u03c6, h\u03c6, h\u27e9,\n    exact is_O_with_of_eq_mul \u03c6 h\u03c6 h }\nend\n\nlemma is_O_with.exists_eq_mul (h : is_O_with c u v l) (hc : 0 \u2264 c) :\n  \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : \u2200\u1da0 x in l, \u2225\u03c6 x\u2225 \u2264 c), u =\u1da0[l] \u03c6 * v :=\n(is_O_with_iff_exists_eq_mul hc).mp h\n\nlemma is_O_iff_exists_eq_mul :\n  is_O u v l \u2194 \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : l.is_bounded_under (\u2264) (norm \u2218 \u03c6)), u =\u1da0[l] \u03c6 * v :=\nbegin\n  split,\n  { rintros h,\n    rcases h.exists_nonneg with \u27e8c, hnnc, hc\u27e9,\n    rcases hc.exists_eq_mul hnnc with \u27e8\u03c6, h\u03c6, huv\u03c6\u27e9,\n    exact \u27e8\u03c6, \u27e8c, h\u03c6\u27e9, huv\u03c6\u27e9 },\n  { rintros \u27e8\u03c6, \u27e8c, h\u03c6\u27e9, huv\u03c6\u27e9,\n    exact is_O_iff_is_O_with.2 \u27e8c, is_O_with_of_eq_mul \u03c6 h\u03c6 huv\u03c6\u27e9 }\nend\n\nalias is_O_iff_exists_eq_mul \u2194 asymptotics.is_O.exists_eq_mul _\n\nlemma is_o_iff_exists_eq_mul :\n  is_o u v l \u2194 \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : tendsto \u03c6 l (\ud835\udcdd 0)), u =\u1da0[l] \u03c6 * v :=\nbegin\n  split,\n  { exact \u03bb h, \u27e8\u03bb x, u x / v x, h.tendsto_div_nhds_zero, h.eventually_mul_div_cancel.symm\u27e9 },\n  { unfold is_o, rintros \u27e8\u03c6, h\u03c6, huv\u03c6\u27e9 c hpos,\n    rw normed_group.tendsto_nhds_zero at h\u03c6,\n    exact is_O_with_of_eq_mul _ ((h\u03c6 c hpos).mono $ \u03bb x, le_of_lt)  huv\u03c6 }\nend\n\nalias is_o_iff_exists_eq_mul \u2194 asymptotics.is_o.exists_eq_mul _\n\nend exists_mul_eq\n\n/-! ### Miscellanous lemmas -/\n\ntheorem div_is_bounded_under_of_is_O {\u03b1 : Type*} {l : filter \u03b1}\n  {f g : \u03b1 \u2192 \ud835\udd5c} (h : is_O f g l) :\n  is_bounded_under (\u2264) l (\u03bb x, \u2225f x / g x\u2225) :=\nbegin\n  obtain \u27e8c, hc\u27e9 := is_O_iff.mp h,\n  refine \u27e8max c 0, eventually_map.2 (filter.mem_of_superset hc (\u03bb x hx, _))\u27e9,\n  simp only [mem_set_of_eq, normed_field.norm_div] at \u22a2 hx,\n  by_cases hgx : g x = 0,\n  { rw [hgx, norm_zero, div_zero, le_max_iff],\n    exact or.inr le_rfl },\n  { exact le_max_iff.2 (or.inl ((div_le_iff (norm_pos_iff.2 hgx)).2 hx)) }\nend\n\ntheorem is_O_iff_div_is_bounded_under {\u03b1 : Type*} {l : filter \u03b1}\n  {f g : \u03b1 \u2192 \ud835\udd5c} (hgf : \u2200\u1da0 x in l, g x = 0 \u2192 f x = 0) :\n  is_O f g l \u2194 is_bounded_under (\u2264) l (\u03bb x, \u2225f x / g x\u2225) :=\nbegin\n  refine \u27e8div_is_bounded_under_of_is_O, \u03bb h, _\u27e9,\n  obtain \u27e8c, hc\u27e9 := h,\n  rw filter.eventually_iff at hgf hc,\n  simp only [mem_set_of_eq, mem_map, normed_field.norm_div] at hc,\n  refine is_O_iff.2 \u27e8c, filter.eventually_of_mem (inter_mem hgf hc) (\u03bb x hx, _)\u27e9,\n  by_cases hgx : g x = 0,\n  { simp [hx.1 hgx, hgx] },\n  { refine (div_le_iff (norm_pos_iff.2 hgx)).mp hx.2 },\nend\n\ntheorem is_O_of_div_tendsto_nhds {\u03b1 : Type*} {l : filter \u03b1}\n  {f g : \u03b1 \u2192 \ud835\udd5c} (hgf : \u2200\u1da0 x in l, g x = 0 \u2192 f x = 0)\n  (c : \ud835\udd5c) (H : filter.tendsto (f / g) l (\ud835\udcdd c)) :\n  is_O f g l :=\n(is_O_iff_div_is_bounded_under hgf).2 $ is_bounded_under_of_tendsto H\n\nlemma is_o.tendsto_zero_of_tendsto {\u03b1 E \ud835\udd5c : Type*} [normed_group E] [normed_field \ud835\udd5c] {u : \u03b1 \u2192 E}\n  {v : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1} {y : \ud835\udd5c} (huv : is_o u v l) (hv : tendsto v l (\ud835\udcdd y)) :\n  tendsto u l (\ud835\udcdd 0) :=\nbegin\n  suffices h : is_o u (\u03bb x, (1 : \ud835\udd5c)) l,\n  { rwa is_o_one_iff at h },\n  exact huv.trans_is_O (is_O_one_of_tendsto \ud835\udd5c hv),\nend\n\ntheorem is_o_pow_pow {m n : \u2115} (h : m < n) :\n  is_o (\u03bb(x : \ud835\udd5c), x^n) (\u03bbx, x^m) (\ud835\udcdd 0) :=\nbegin\n  let p := n - m,\n  have nmp : n = m + p := (add_tsub_cancel_of_le (le_of_lt h)).symm,\n  have : (\u03bb(x : \ud835\udd5c), x^m) = (\u03bbx, x^m * 1), by simp only [mul_one],\n  simp only [this, pow_add, nmp],\n  refine is_O.mul_is_o (is_O_refl _ _) ((is_o_one_iff _).2 _),\n  convert (continuous_pow p).tendsto (0 : \ud835\udd5c),\n  exact (zero_pow (tsub_pos_of_lt h)).symm\nend\n\ntheorem is_o_norm_pow_norm_pow {m n : \u2115} (h : m < n) :\n  is_o (\u03bb(x : E'), \u2225x\u2225^n) (\u03bbx, \u2225x\u2225^m) (\ud835\udcdd (0 : E')) :=\n(is_o_pow_pow h).comp_tendsto tendsto_norm_zero\n\ntheorem is_o_pow_id {n : \u2115} (h : 1 < n) :\n  is_o (\u03bb(x : \ud835\udd5c), x^n) (\u03bbx, x) (\ud835\udcdd 0) :=\nby { convert is_o_pow_pow h, simp only [pow_one] }\n\ntheorem is_o_norm_pow_id {n : \u2115} (h : 1 < n) :\n  is_o (\u03bb(x : E'), \u2225x\u2225^n) (\u03bbx, x) (\ud835\udcdd 0) :=\nby simpa only [pow_one, is_o_norm_right] using @is_o_norm_pow_norm_pow E' _ _ _ h\n\ntheorem is_O_with.right_le_sub_of_lt_1 {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_O_with c f\u2081 f\u2082 l) (hc : c < 1) :\n  is_O_with (1 / (1 - c)) f\u2082 (\u03bbx, f\u2082 x - f\u2081 x) l :=\nis_O_with.of_bound $ mem_of_superset h.bound $ \u03bb x hx,\nbegin\n  simp only [mem_set_of_eq] at hx \u22a2,\n  rw [mul_comm, one_div, \u2190 div_eq_mul_inv, le_div_iff, mul_sub, mul_one, mul_comm],\n  { exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) },\n  { exact sub_pos.2 hc }\nend\n\ntheorem is_O_with.right_le_add_of_lt_1 {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_O_with c f\u2081 f\u2082 l) (hc : c < 1) :\n  is_O_with (1 / (1 - c)) f\u2082 (\u03bbx, f\u2081 x + f\u2082 x) l :=\n(h.neg_right.right_le_sub_of_lt_1 hc).neg_right.of_neg_left.congr rfl (\u03bb x, rfl)\n  (\u03bb x, by rw [neg_sub, sub_neg_eq_add])\n\ntheorem is_o.right_is_O_sub {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_o f\u2081 f\u2082 l) :\n  is_O f\u2082 (\u03bbx, f\u2082 x - f\u2081 x) l :=\n((h.def' one_half_pos).right_le_sub_of_lt_1 one_half_lt_one).is_O\n\ntheorem is_o.right_is_O_add {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_o f\u2081 f\u2082 l) :\n  is_O f\u2082 (\u03bbx, f\u2081 x + f\u2082 x) l :=\n((h.def' one_half_pos).right_le_add_of_lt_1 one_half_lt_one).is_O\n\n/-- If `f x = O(g x)` along `cofinite`, then there exists a positive constant `C` such that\n`\u2225f x\u2225 \u2264 C * \u2225g x\u2225` whenever `g x \u2260 0`. -/\ntheorem bound_of_is_O_cofinite (h : is_O f g' cofinite) :\n  \u2203 C > 0, \u2200 \u2983x\u2984, g' x \u2260 0 \u2192 \u2225f x\u2225 \u2264 C * \u2225g' x\u2225 :=\nbegin\n  rcases h.exists_pos with \u27e8C, C\u2080, hC\u27e9,\n  rw [is_O_with, eventually_cofinite] at hC,\n  rcases (hC.to_finset.image (\u03bb x, \u2225f x\u2225 / \u2225g' x\u2225)).exists_le with \u27e8C', hC'\u27e9,\n  have : \u2200 x, C * \u2225g' x\u2225 < \u2225f x\u2225 \u2192 \u2225f x\u2225 / \u2225g' x\u2225 \u2264 C', by simpa using hC',\n  refine \u27e8max C C', lt_max_iff.2 (or.inl C\u2080), \u03bb x h\u2080, _\u27e9,\n  rw [max_mul_of_nonneg _ _ (norm_nonneg _), le_max_iff, or_iff_not_imp_left, not_le],\n  exact \u03bb hx, (div_le_iff (norm_pos_iff.2 h\u2080)).1 (this _ hx)\nend\n\ntheorem is_O_cofinite_iff (h : \u2200 x, g' x = 0 \u2192 f' x = 0) :\n  is_O f' g' cofinite \u2194 \u2203 C, \u2200 x, \u2225f' x\u2225 \u2264 C * \u2225g' x\u2225 :=\n\u27e8\u03bb h', let \u27e8C, C\u2080, hC\u27e9 := bound_of_is_O_cofinite h' in\n  \u27e8C, \u03bb x, if hx : g' x = 0 then by simp [h _ hx, hx] else hC hx\u27e9,\n  \u03bb h, (is_O_top.2 h).mono le_top\u27e9\n\ntheorem bound_of_is_O_nat_at_top {f : \u2115 \u2192 E} {g' : \u2115 \u2192 E'} (h : is_O f g' at_top) :\n  \u2203 C > 0, \u2200 \u2983x\u2984, g' x \u2260 0 \u2192 \u2225f x\u2225 \u2264 C * \u2225g' x\u2225 :=\nbound_of_is_O_cofinite $ by rwa nat.cofinite_eq_at_top\n\ntheorem is_O_nat_at_top_iff {f : \u2115 \u2192 E'} {g : \u2115 \u2192 F'} (h : \u2200 x, g x = 0 \u2192 f x = 0) :\n  is_O f g at_top \u2194 \u2203 C, \u2200 x, \u2225f x\u2225 \u2264 C * \u2225g x\u2225 :=\nby rw [\u2190 nat.cofinite_eq_at_top, is_O_cofinite_iff h]\n\ntheorem is_O_one_nat_at_top_iff {f : \u2115 \u2192 E'} :\n  is_O f (\u03bb n, 1 : \u2115 \u2192 \u211d) at_top \u2194 \u2203 C, \u2200 n, \u2225f n\u2225 \u2264 C :=\niff.trans (is_O_nat_at_top_iff (\u03bb n h, (one_ne_zero h).elim)) $\n  by simp only [norm_one, mul_one]\n\ntheorem is_O_with_pi {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (E' i)]\n  {f : \u03b1 \u2192 \u03a0 i, E' i} {C : \u211d} (hC : 0 \u2264 C) :\n  is_O_with C f g' l \u2194 \u2200 i, is_O_with C (\u03bb x, f x i) g' l :=\nhave \u2200 x, 0 \u2264 C * \u2225g' x\u2225, from \u03bb x, mul_nonneg hC (norm_nonneg _),\nby simp only [is_O_with_iff, pi_norm_le_iff (this _), eventually_all]\n\n@[simp] theorem is_O_pi {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (E' i)]\n  {f : \u03b1 \u2192 \u03a0 i, E' i} :\n  is_O f g' l \u2194 \u2200 i, is_O (\u03bb x, f x i) g' l :=\nbegin\n  simp only [is_O_iff_eventually_is_O_with, \u2190 eventually_all],\n  exact eventually_congr (eventually_at_top.2 \u27e80, \u03bb c, is_O_with_pi\u27e9)\nend\n\n@[simp] theorem is_o_pi {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (E' i)]\n  {f : \u03b1 \u2192 \u03a0 i, E' i} :\n  is_o f g' l \u2194 \u2200 i, is_o (\u03bb x, f x i) g' l :=\nbegin\n  simp only [is_o, is_O_with_pi, le_of_lt] { contextual := tt },\n  exact \u27e8\u03bb h i c hc, h hc i, \u03bb h c hc i, h i hc\u27e9\nend\n\nend asymptotics\n\nopen asymptotics\n\nlemma summable_of_is_O {\u03b9 E} [normed_group E] [complete_space E] {f : \u03b9 \u2192 E} {g : \u03b9 \u2192 \u211d}\n  (hg : summable g) (h : is_O f g cofinite) : summable f :=\nlet \u27e8C, hC\u27e9 := h.is_O_with in\nsummable_of_norm_bounded_eventually (\u03bb x, C * \u2225g x\u2225) (hg.abs.mul_left _) hC.bound\n\nlemma summable_of_is_O_nat {E} [normed_group E] [complete_space E] {f : \u2115 \u2192 E} {g : \u2115 \u2192 \u211d}\n  (hg : summable g) (h : is_O f g at_top) : summable f :=\nsummable_of_is_O hg $ nat.cofinite_eq_at_top.symm \u25b8 h\n\nnamespace local_homeomorph\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n\nvariables {E : Type*} [has_norm E] {F : Type*} [has_norm F]\n\n/-- Transfer `is_O_with` over a `local_homeomorph`. -/\nlemma is_O_with_congr (e : local_homeomorph \u03b1 \u03b2) {b : \u03b2} (hb : b \u2208 e.target)\n  {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} {C : \u211d} :\n  is_O_with C f g (\ud835\udcdd b) \u2194 is_O_with C (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\n\u27e8\u03bb h, h.comp_tendsto $\n  by { convert e.continuous_at (e.map_target hb), exact (e.right_inv hb).symm },\n  \u03bb h, (h.comp_tendsto (e.continuous_at_symm hb)).congr' rfl\n    ((e.eventually_right_inverse hb).mono $ \u03bb x hx, congr_arg f hx)\n    ((e.eventually_right_inverse hb).mono $ \u03bb x hx, congr_arg g hx)\u27e9\n\n/-- Transfer `is_O` over a `local_homeomorph`. -/\nlemma is_O_congr (e : local_homeomorph \u03b1 \u03b2) {b : \u03b2} (hb : b \u2208 e.target) {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_O f g (\ud835\udcdd b) \u2194 is_O (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_O, exact exists_congr (\u03bb C, e.is_O_with_congr hb) }\n\n/-- Transfer `is_o` over a `local_homeomorph`. -/\nlemma is_o_congr (e : local_homeomorph \u03b1 \u03b2) {b : \u03b2} (hb : b \u2208 e.target) {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_o f g (\ud835\udcdd b) \u2194 is_o (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb c hc, e.is_O_with_congr hb) }\n\nend local_homeomorph\n\nnamespace homeomorph\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n\nvariables {E : Type*} [has_norm E] {F : Type*} [has_norm F]\n\nopen asymptotics\n\n/-- Transfer `is_O_with` over a `homeomorph`. -/\nlemma is_O_with_congr (e : \u03b1 \u2243\u209c \u03b2) {b : \u03b2} {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} {C : \u211d} :\n  is_O_with C f g (\ud835\udcdd b) \u2194 is_O_with C (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\ne.to_local_homeomorph.is_O_with_congr trivial\n\n/-- Transfer `is_O` over a `homeomorph`. -/\nlemma is_O_congr (e : \u03b1 \u2243\u209c \u03b2) {b : \u03b2} {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_O f g (\ud835\udcdd b) \u2194 is_O (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_O, exact exists_congr (\u03bb C, e.is_O_with_congr) }\n\n/-- Transfer `is_o` over a `homeomorph`. -/\nlemma is_o_congr (e : \u03b1 \u2243\u209c \u03b2) {b : \u03b2} {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_o f g (\ud835\udcdd b) \u2194 is_o (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb c hc, e.is_O_with_congr) }\n\nend homeomorph\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/asymptotics/asymptotics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7299463025722294}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport geometry.euclidean.circumcenter\n\n/-!\n# Monge point and orthocenter\n\nThis file defines the orthocenter of a triangle, via its n-dimensional\ngeneralization, the Monge point of a simplex.\n\n## Main definitions\n\n* `monge_point` is the Monge point of a simplex, defined in terms of\n  its position on the Euler line and then shown to be the point of\n  concurrence of the Monge planes.\n\n* `monge_plane` is a Monge plane of an (n+2)-simplex, which is the\n  (n+1)-dimensional affine subspace of the subspace spanned by the\n  simplex that passes through the centroid of an n-dimensional face\n  and is orthogonal to the opposite edge (in 2 dimensions, this is the\n  same as an altitude).\n\n* `altitude` is the line that passes through a vertex of a simplex and\n  is orthogonal to the opposite face.\n\n* `orthocenter` is defined, for the case of a triangle, to be the same\n  as its Monge point, then shown to be the point of concurrence of the\n  altitudes.\n\n* `orthocentric_system` is a predicate on sets of points that says\n  whether they are four points, one of which is the orthocenter of the\n  other three (in which case various other properties hold, including\n  that each is the orthocenter of the other three).\n\n## References\n\n* <https://en.wikipedia.org/wiki/Altitude_(triangle)>\n* <https://en.wikipedia.org/wiki/Monge_point>\n* <https://en.wikipedia.org/wiki/Orthocentric_system>\n* Ma\u0142gorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point\n  Sphere of an\n  n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf)\n\n-/\n\nnoncomputable theory\nopen_locale big_operators\nopen_locale classical\nopen_locale real\nopen_locale real_inner_product_space\n\nnamespace affine\n\nnamespace simplex\n\nopen finset affine_subspace euclidean_geometry points_with_circumcenter_index\n\nvariables {V : Type*} {P : Type*} [inner_product_space \u211d V] [metric_space P]\n    [normed_add_torsor V P]\ninclude V\n\n/-- The Monge point of a simplex (in 2 or more dimensions) is a\ngeneralization of the orthocenter of a triangle.  It is defined to be\nthe intersection of the Monge planes, where a Monge plane is the\n(n-1)-dimensional affine subspace of the subspace spanned by the\nsimplex that passes through the centroid of an (n-2)-dimensional face\nand is orthogonal to the opposite edge (in 2 dimensions, this is the\nsame as an altitude).  The circumcenter O, centroid G and Monge point\nM are collinear in that order on the Euler line, with OG : GM = (n-1)\n: 2.  Here, we use that ratio to define the Monge point (so resulting\nin a point that equals the centroid in 0 or 1 dimensions), and then\nshow in subsequent lemmas that the point so defined lies in the Monge\nplanes and is their unique point of intersection. -/\ndef monge_point {n : \u2115} (s : simplex \u211d P n) : P :=\n(((n + 1 : \u2115) : \u211d) / (((n - 1) : \u2115) : \u211d)) \u2022\n  ((univ : finset (fin (n + 1))).centroid \u211d s.points -\u1d65 s.circumcenter) +\u1d65\n  s.circumcenter\n\n/-- The position of the Monge point in relation to the circumcenter\nand centroid. -/\nlemma monge_point_eq_smul_vsub_vadd_circumcenter {n : \u2115} (s : simplex \u211d P n) :\n  s.monge_point = (((n + 1 : \u2115) : \u211d) / (((n - 1) : \u2115) : \u211d)) \u2022\n    ((univ : finset (fin (n + 1))).centroid \u211d s.points -\u1d65 s.circumcenter) +\u1d65\n    s.circumcenter :=\nrfl\n\n/-- The Monge point lies in the affine span. -/\nlemma monge_point_mem_affine_span {n : \u2115} (s : simplex \u211d P n) :\n  s.monge_point \u2208 affine_span \u211d (set.range s.points) :=\nsmul_vsub_vadd_mem _ _\n  (centroid_mem_affine_span_of_card_eq_add_one \u211d _ (card_fin (n + 1)))\n  s.circumcenter_mem_affine_span\n  s.circumcenter_mem_affine_span\n\n/-- Two simplices with the same points have the same Monge point. -/\nlemma monge_point_eq_of_range_eq {n : \u2115} {s\u2081 s\u2082 : simplex \u211d P n}\n  (h : set.range s\u2081.points = set.range s\u2082.points) : s\u2081.monge_point = s\u2082.monge_point :=\nby simp_rw [monge_point_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h,\n            circumcenter_eq_of_range_eq h]\n\nomit V\n\n/-- The weights for the Monge point of an (n+2)-simplex, in terms of\n`points_with_circumcenter`. -/\ndef monge_point_weights_with_circumcenter (n : \u2115) : points_with_circumcenter_index (n + 2) \u2192 \u211d\n| (point_index i) := (((n + 1) : \u2115) : \u211d)\u207b\u00b9\n| circumcenter_index := (-2 / (((n + 1) : \u2115) : \u211d))\n\n/-- `monge_point_weights_with_circumcenter` sums to 1. -/\n@[simp] lemma sum_monge_point_weights_with_circumcenter (n : \u2115) :\n  \u2211 i, monge_point_weights_with_circumcenter n i = 1 :=\nbegin\n  simp_rw [sum_points_with_circumcenter, monge_point_weights_with_circumcenter, sum_const,\n           card_fin, nsmul_eq_mul],\n  have hn1 : (n + 1 : \u211d) \u2260 0,\n  { exact_mod_cast nat.succ_ne_zero _ },\n  field_simp [hn1],\n  ring\nend\n\ninclude V\n\n/-- The Monge point of an (n+2)-simplex, in terms of\n`points_with_circumcenter`. -/\nlemma monge_point_eq_affine_combination_of_points_with_circumcenter {n : \u2115}\n  (s : simplex \u211d P (n + 2)) :\n  s.monge_point = (univ : finset (points_with_circumcenter_index (n + 2))).affine_combination\n    s.points_with_circumcenter (monge_point_weights_with_circumcenter n) :=\nbegin\n  rw [monge_point_eq_smul_vsub_vadd_circumcenter,\n      centroid_eq_affine_combination_of_points_with_circumcenter,\n      circumcenter_eq_affine_combination_of_points_with_circumcenter,\n      affine_combination_vsub, \u2190linear_map.map_smul,\n      weighted_vsub_vadd_affine_combination],\n  congr' with i,\n  rw [pi.add_apply, pi.smul_apply, smul_eq_mul, pi.sub_apply],\n  have hn1 : (n + 1 : \u211d) \u2260 0,\n  { exact_mod_cast nat.succ_ne_zero _ },\n  cases i;\n    simp_rw [centroid_weights_with_circumcenter, circumcenter_weights_with_circumcenter,\n             monge_point_weights_with_circumcenter];\n    rw [nat.add_sub_assoc (dec_trivial : 1 \u2264 2), (dec_trivial : 2 - 1 = 1)],\n  { rw [if_pos (mem_univ _), sub_zero, add_zero, card_fin],\n    have hn3 : (n + 2 + 1 : \u211d) \u2260 0,\n    { exact_mod_cast nat.succ_ne_zero _ },\n    field_simp [hn1, hn3, mul_comm] },\n  { field_simp [hn1],\n    ring }\nend\n\nomit V\n\n/-- The weights for the Monge point of an (n+2)-simplex, minus the\ncentroid of an n-dimensional face, in terms of\n`points_with_circumcenter`.  This definition is only valid when `i\u2081 \u2260 i\u2082`. -/\ndef monge_point_vsub_face_centroid_weights_with_circumcenter {n : \u2115} (i\u2081 i\u2082 : fin (n + 3)) :\n  points_with_circumcenter_index (n + 2) \u2192 \u211d\n| (point_index i) := if i = i\u2081 \u2228 i = i\u2082 then (((n + 1) : \u2115) : \u211d)\u207b\u00b9 else 0\n| circumcenter_index := (-2 / (((n + 1) : \u2115) : \u211d))\n\n/-- `monge_point_vsub_face_centroid_weights_with_circumcenter` is the\nresult of subtracting `centroid_weights_with_circumcenter` from\n`monge_point_weights_with_circumcenter`. -/\nlemma monge_point_vsub_face_centroid_weights_with_circumcenter_eq_sub {n : \u2115}\n  {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  monge_point_vsub_face_centroid_weights_with_circumcenter i\u2081 i\u2082 =\n    monge_point_weights_with_circumcenter n -\n      centroid_weights_with_circumcenter ({i\u2081, i\u2082}\u1d9c) :=\nbegin\n  ext i,\n  cases i,\n  { rw [pi.sub_apply, monge_point_weights_with_circumcenter, centroid_weights_with_circumcenter,\n        monge_point_vsub_face_centroid_weights_with_circumcenter],\n    have hu : card ({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))) = n + 1,\n    { simp [card_compl, fintype.card_fin, h] },\n    rw hu,\n    by_cases hi : i = i\u2081 \u2228 i = i\u2082;\n      simp [compl_eq_univ_sdiff, hi] },\n  { simp [monge_point_weights_with_circumcenter, centroid_weights_with_circumcenter,\n          monge_point_vsub_face_centroid_weights_with_circumcenter] }\nend\n\n/-- `monge_point_vsub_face_centroid_weights_with_circumcenter` sums to 0. -/\n@[simp] lemma sum_monge_point_vsub_face_centroid_weights_with_circumcenter {n : \u2115}\n  {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  \u2211 i, monge_point_vsub_face_centroid_weights_with_circumcenter i\u2081 i\u2082 i = 0 :=\nbegin\n  rw monge_point_vsub_face_centroid_weights_with_circumcenter_eq_sub h,\n  simp_rw [pi.sub_apply, sum_sub_distrib, sum_monge_point_weights_with_circumcenter],\n  rw [sum_centroid_weights_with_circumcenter, sub_self],\n  simp [\u2190card_pos, card_compl, h]\nend\n\ninclude V\n\n/-- The Monge point of an (n+2)-simplex, minus the centroid of an\nn-dimensional face, in terms of `points_with_circumcenter`. -/\nlemma monge_point_vsub_face_centroid_eq_weighted_vsub_of_points_with_circumcenter {n : \u2115}\n  (s : simplex \u211d P (n + 2)) {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  s.monge_point -\u1d65 ({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points =\n    (univ : finset (points_with_circumcenter_index (n + 2))).weighted_vsub\n      s.points_with_circumcenter (monge_point_vsub_face_centroid_weights_with_circumcenter i\u2081 i\u2082) :=\nby simp_rw [monge_point_eq_affine_combination_of_points_with_circumcenter,\n            centroid_eq_affine_combination_of_points_with_circumcenter,\n            affine_combination_vsub,\n            monge_point_vsub_face_centroid_weights_with_circumcenter_eq_sub h]\n\n/-- The Monge point of an (n+2)-simplex, minus the centroid of an\nn-dimensional face, is orthogonal to the difference of the two\nvertices not in that face. -/\nlemma inner_monge_point_vsub_face_centroid_vsub {n : \u2115} (s : simplex \u211d P (n + 2))\n  {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  \u27eas.monge_point -\u1d65 ({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points,\n        s.points i\u2081 -\u1d65 s.points i\u2082\u27eb = 0 :=\nbegin\n  simp_rw [monge_point_vsub_face_centroid_eq_weighted_vsub_of_points_with_circumcenter s h,\n           point_eq_affine_combination_of_points_with_circumcenter,\n           affine_combination_vsub],\n  have hs : \u2211 i, (point_weights_with_circumcenter i\u2081 - point_weights_with_circumcenter i\u2082) i = 0,\n  { simp },\n  rw [inner_weighted_vsub _ (sum_monge_point_vsub_face_centroid_weights_with_circumcenter h) _ hs,\n      sum_points_with_circumcenter, points_with_circumcenter_eq_circumcenter],\n  simp only [monge_point_vsub_face_centroid_weights_with_circumcenter,\n             points_with_circumcenter_point],\n  let fs : finset (fin (n + 3)) := {i\u2081, i\u2082},\n  have hfs : \u2200 i : fin (n + 3),\n    i \u2209 fs \u2192 (i \u2260 i\u2081 \u2227 i \u2260 i\u2082),\n  { intros i hi,\n    split ; { intro hj, simpa [\u2190hj] using hi } },\n  rw \u2190sum_subset fs.subset_univ _,\n  { simp_rw [sum_points_with_circumcenter, points_with_circumcenter_eq_circumcenter,\n             points_with_circumcenter_point, pi.sub_apply, point_weights_with_circumcenter],\n    rw [\u2190sum_subset fs.subset_univ _],\n    { simp_rw [sum_insert (not_mem_singleton.2 h), sum_singleton],\n      repeat { rw \u2190sum_subset fs.subset_univ _ },\n      { simp_rw [sum_insert (not_mem_singleton.2 h), sum_singleton],\n        simp [h, h.symm, dist_comm (s.points i\u2081)] },\n      all_goals { intros i hu hi, simp [hfs i hi] } },\n    { intros i hu hi,\n      simp [hfs i hi, point_weights_with_circumcenter] } },\n  { intros i hu hi,\n    simp [hfs i hi] }\nend\n\n/-- A Monge plane of an (n+2)-simplex is the (n+1)-dimensional affine\nsubspace of the subspace spanned by the simplex that passes through\nthe centroid of an n-dimensional face and is orthogonal to the\nopposite edge (in 2 dimensions, this is the same as an altitude).\nThis definition is only intended to be used when `i\u2081 \u2260 i\u2082`. -/\ndef monge_plane {n : \u2115} (s : simplex \u211d P (n + 2)) (i\u2081 i\u2082 : fin (n + 3)) :\n  affine_subspace \u211d P :=\nmk' (({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points)\n  (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293\n    affine_span \u211d (set.range s.points)\n\n/-- The definition of a Monge plane. -/\nlemma monge_plane_def {n : \u2115} (s : simplex \u211d P (n + 2)) (i\u2081 i\u2082 : fin (n + 3)) :\n  s.monge_plane i\u2081 i\u2082 = mk' (({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points)\n                            (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293\n                          affine_span \u211d (set.range s.points) :=\nrfl\n\n/-- The Monge plane associated with vertices `i\u2081` and `i\u2082` equals that\nassociated with `i\u2082` and `i\u2081`. -/\nlemma monge_plane_comm {n : \u2115} (s : simplex \u211d P (n + 2)) (i\u2081 i\u2082 : fin (n + 3)) :\n  s.monge_plane i\u2081 i\u2082 = s.monge_plane i\u2082 i\u2081 :=\nbegin\n  simp_rw monge_plane_def,\n  congr' 3,\n  { congr' 1,\n    exact insert_singleton_comm _ _ },\n  { ext,\n    simp_rw submodule.mem_span_singleton,\n    split,\n    all_goals { rintros \u27e8r, rfl\u27e9, use -r, rw [neg_smul, \u2190smul_neg, neg_vsub_eq_vsub_rev] } }\nend\n\n/-- The Monge point lies in the Monge planes. -/\nlemma monge_point_mem_monge_plane {n : \u2115} (s : simplex \u211d P (n + 2)) {i\u2081 i\u2082 : fin (n + 3)}\n    (h : i\u2081 \u2260 i\u2082) : s.monge_point \u2208 s.monge_plane i\u2081 i\u2082 :=\nbegin\n  rw [monge_plane_def, mem_inf_iff, \u2190vsub_right_mem_direction_iff_mem (self_mem_mk' _ _),\n      direction_mk', submodule.mem_orthogonal'],\n  refine \u27e8_, s.monge_point_mem_affine_span\u27e9,\n  intros v hv,\n  rcases submodule.mem_span_singleton.mp hv with \u27e8r, rfl\u27e9,\n  rw [inner_smul_right, s.inner_monge_point_vsub_face_centroid_vsub h, mul_zero]\nend\n\n-- This doesn't actually need the `i\u2081 \u2260 i\u2082` hypothesis, but it's\n-- convenient for the proof and `monge_plane` isn't intended to be\n-- useful without that hypothesis.\n/-- The direction of a Monge plane. -/\nlemma direction_monge_plane {n : \u2115} (s : simplex \u211d P (n + 2)) {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  (s.monge_plane i\u2081 i\u2082).direction = (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293\n    vector_span \u211d (set.range s.points) :=\nby rw [monge_plane_def, direction_inf_of_mem_inf (s.monge_point_mem_monge_plane h), direction_mk',\n       direction_affine_span]\n\n/-- The Monge point is the only point in all the Monge planes from any\none vertex. -/\nlemma eq_monge_point_of_forall_mem_monge_plane {n : \u2115} {s : simplex \u211d P (n + 2)}\n  {i\u2081 : fin (n + 3)} {p : P} (h : \u2200 i\u2082, i\u2081 \u2260 i\u2082 \u2192 p \u2208 s.monge_plane i\u2081 i\u2082) :\n  p = s.monge_point :=\nbegin\n  rw \u2190@vsub_eq_zero_iff_eq V,\n  have h' : \u2200 i\u2082, i\u2081 \u2260 i\u2082 \u2192 p -\u1d65 s.monge_point \u2208\n    (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293 vector_span \u211d (set.range s.points),\n  { intros i\u2082 hne,\n    rw [\u2190s.direction_monge_plane hne,\n        vsub_right_mem_direction_iff_mem (s.monge_point_mem_monge_plane hne)],\n    exact h i\u2082 hne },\n  have hi : p -\u1d65 s.monge_point \u2208 \u2a05 (i\u2082 : {i // i\u2081 \u2260 i}),\n    (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee,\n  { rw submodule.mem_infi,\n    exact \u03bb i, (submodule.mem_inf.1 (h' i i.property)).1 },\n  rw [submodule.infi_orthogonal, \u2190submodule.span_Union] at hi,\n  have hu : (\u22c3 (i : {i // i\u2081 \u2260 i}), ({s.points i\u2081 -\u1d65 s.points i} : set V)) =\n    (-\u1d65) (s.points i\u2081) '' (s.points '' (set.univ \\ {i\u2081})),\n  { rw [set.image_image],\n    ext x,\n    simp_rw [set.mem_Union, set.mem_image, set.mem_singleton_iff, set.mem_diff_singleton],\n    split,\n    { rintros \u27e8i, rfl\u27e9,\n      use [i, \u27e8set.mem_univ _, i.property.symm\u27e9] },\n    { rintros \u27e8i, \u27e8hiu, hi\u27e9, rfl\u27e9,\n      use [\u27e8i, hi.symm\u27e9, rfl] } },\n  rw [hu, \u2190vector_span_image_eq_span_vsub_set_left_ne \u211d _ (set.mem_univ _),\n      set.image_univ] at hi,\n  have hv : p -\u1d65 s.monge_point \u2208 vector_span \u211d (set.range s.points),\n  { let s\u2081 : finset (fin (n + 3)) := univ.erase i\u2081,\n    obtain \u27e8i\u2082, h\u2082\u27e9 :=\n      card_pos.1 (show 0 < card s\u2081, by simp [card_erase_of_mem]),\n    have h\u2081\u2082 : i\u2081 \u2260 i\u2082 := (ne_of_mem_erase h\u2082).symm,\n    exact (submodule.mem_inf.1 (h' i\u2082 h\u2081\u2082)).2 },\n  exact submodule.disjoint_def.1 ((vector_span \u211d (set.range s.points)).orthogonal_disjoint)\n    _ hv hi,\nend\n\n/-- An altitude of a simplex is the line that passes through a vertex\nand is orthogonal to the opposite face. -/\ndef altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) : affine_subspace \u211d P :=\nmk' (s.points i) (affine_span \u211d (s.points '' \u2191(univ.erase i))).direction\u15ee \u2293\n  affine_span \u211d (set.range s.points)\n\n/-- The definition of an altitude. -/\nlemma altitude_def {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  s.altitude i = mk' (s.points i)\n                     (affine_span \u211d (s.points '' \u2191(univ.erase i))).direction\u15ee \u2293\n    affine_span \u211d (set.range s.points) :=\nrfl\n\n/-- A vertex lies in the corresponding altitude. -/\nlemma mem_altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  s.points i \u2208 s.altitude i :=\n(mem_inf_iff _ _ _).2 \u27e8self_mem_mk' _ _, mem_affine_span \u211d (set.mem_range_self _)\u27e9\n\n/-- The direction of an altitude. -/\nlemma direction_altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  (s.altitude i).direction = (vector_span \u211d (s.points '' \u2191(finset.univ.erase i)))\u15ee \u2293\n    vector_span \u211d (set.range s.points) :=\nby rw [altitude_def,\n       direction_inf_of_mem (self_mem_mk' (s.points i) _)\n         (mem_affine_span \u211d (set.mem_range_self _)), direction_mk', direction_affine_span,\n       direction_affine_span]\n\n/-- The vector span of the opposite face lies in the direction\northogonal to an altitude. -/\nlemma vector_span_le_altitude_direction_orthogonal  {n : \u2115} (s : simplex \u211d P (n + 1))\n    (i : fin (n + 2)) :\n  vector_span \u211d (s.points '' \u2191(finset.univ.erase i)) \u2264 (s.altitude i).direction\u15ee :=\nbegin\n  rw direction_altitude,\n  exact le_trans\n    (vector_span \u211d (s.points '' \u2191(finset.univ.erase i))).le_orthogonal_orthogonal\n    (submodule.orthogonal_le inf_le_left)\nend\n\nopen finite_dimensional\n\n/-- An altitude is finite-dimensional. -/\ninstance finite_dimensional_direction_altitude {n : \u2115} (s : simplex \u211d P (n + 1))\n  (i : fin (n + 2)) : finite_dimensional \u211d ((s.altitude i).direction) :=\nbegin\n  rw direction_altitude,\n  apply_instance\nend\n\n/-- An altitude is one-dimensional (i.e., a line). -/\n@[simp] lemma finrank_direction_altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  finrank \u211d ((s.altitude i).direction) = 1 :=\nbegin\n  rw direction_altitude,\n  have h := submodule.finrank_add_inf_finrank_orthogonal\n    (vector_span_mono \u211d (set.image_subset_range s.points \u2191(univ.erase i))),\n  have hc : card (univ.erase i) = n + 1, { rw card_erase_of_mem (mem_univ _), simp },\n  rw [finrank_vector_span_of_affine_independent s.independent (fintype.card_fin _),\n      finrank_vector_span_image_finset_of_affine_independent s.independent hc] at h,\n  simpa using h\nend\n\n/-- A line through a vertex is the altitude through that vertex if and\nonly if it is orthogonal to the opposite face. -/\nlemma affine_span_insert_singleton_eq_altitude_iff {n : \u2115} (s : simplex \u211d P (n + 1))\n    (i : fin (n + 2)) (p : P) :\n  affine_span \u211d {p, s.points i} = s.altitude i \u2194 (p \u2260 s.points i \u2227\n    p \u2208 affine_span \u211d (set.range s.points) \u2227\n    p -\u1d65 s.points i \u2208 (affine_span \u211d (s.points '' \u2191(finset.univ.erase i))).direction\u15ee) :=\nbegin\n  rw [eq_iff_direction_eq_of_mem\n        (mem_affine_span \u211d (set.mem_insert_of_mem _ (set.mem_singleton _))) (s.mem_altitude _),\n      \u2190vsub_right_mem_direction_iff_mem (mem_affine_span \u211d (set.mem_range_self i)) p,\n      direction_affine_span, direction_affine_span, direction_affine_span],\n  split,\n  { intro h,\n    split,\n    { intro heq,\n      rw [heq, set.pair_eq_singleton, vector_span_singleton] at h,\n      have hd : finrank \u211d (s.altitude i).direction = 0,\n      { rw [\u2190h, finrank_bot] },\n      simpa using hd },\n    { rw [\u2190submodule.mem_inf, inf_comm, \u2190direction_altitude, \u2190h],\n      exact vsub_mem_vector_span \u211d (set.mem_insert _ _)\n                                   (set.mem_insert_of_mem _ (set.mem_singleton _)) } },\n  { rintro \u27e8hne, h\u27e9,\n    rw [\u2190submodule.mem_inf, inf_comm, \u2190direction_altitude] at h,\n    rw [vector_span_eq_span_vsub_set_left_ne \u211d (set.mem_insert _ _),\n        set.insert_diff_of_mem _ (set.mem_singleton _),\n        set.diff_singleton_eq_self (\u03bb h, hne (set.mem_singleton_iff.1 h)), set.image_singleton],\n    refine eq_of_le_of_finrank_eq _ _,\n    { rw submodule.span_le,\n      simpa using h },\n    { rw [finrank_direction_altitude, finrank_span_set_eq_card],\n      { simp },\n      { refine linear_independent_singleton _,\n        simpa using hne } } }\nend\n\nend simplex\n\nnamespace triangle\n\nopen euclidean_geometry finset simplex affine_subspace finite_dimensional\n\nvariables {V : Type*} {P : Type*} [inner_product_space \u211d V] [metric_space P]\n    [normed_add_torsor V P]\ninclude V\n\n/-- The orthocenter of a triangle is the intersection of its\naltitudes.  It is defined here as the 2-dimensional case of the\nMonge point. -/\ndef orthocenter (t : triangle \u211d P) : P := t.monge_point\n\n/-- The orthocenter equals the Monge point. -/\nlemma orthocenter_eq_monge_point (t : triangle \u211d P) : t.orthocenter = t.monge_point := rfl\n\n/-- The position of the orthocenter in relation to the circumcenter\nand centroid. -/\nlemma orthocenter_eq_smul_vsub_vadd_circumcenter (t : triangle \u211d P) :\n  t.orthocenter = (3 : \u211d) \u2022\n    ((univ : finset (fin 3)).centroid \u211d t.points -\u1d65 t.circumcenter : V) +\u1d65 t.circumcenter :=\nbegin\n  rw [orthocenter_eq_monge_point, monge_point_eq_smul_vsub_vadd_circumcenter],\n  norm_num\nend\n\n/-- The orthocenter lies in the affine span. -/\nlemma orthocenter_mem_affine_span (t : triangle \u211d P) :\n  t.orthocenter \u2208 affine_span \u211d (set.range t.points) :=\nt.monge_point_mem_affine_span\n\n/-- Two triangles with the same points have the same orthocenter. -/\nlemma orthocenter_eq_of_range_eq {t\u2081 t\u2082 : triangle \u211d P}\n  (h : set.range t\u2081.points = set.range t\u2082.points) : t\u2081.orthocenter = t\u2082.orthocenter :=\nmonge_point_eq_of_range_eq h\n\n/-- In the case of a triangle, altitudes are the same thing as Monge\nplanes. -/\nlemma altitude_eq_monge_plane (t : triangle \u211d P) {i\u2081 i\u2082 i\u2083 : fin 3} (h\u2081\u2082 : i\u2081 \u2260 i\u2082)\n  (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083) : t.altitude i\u2081 = t.monge_plane i\u2082 i\u2083 :=\nbegin\n  have hs : ({i\u2082, i\u2083}\u1d9c : finset (fin 3)) = {i\u2081}, by dec_trivial!,\n  have he : univ.erase i\u2081 = {i\u2082, i\u2083}, by dec_trivial!,\n  rw [monge_plane_def, altitude_def, direction_affine_span, hs, he, centroid_singleton,\n      coe_insert, coe_singleton,\n      vector_span_image_eq_span_vsub_set_left_ne \u211d _ (set.mem_insert i\u2082 _)],\n  simp [h\u2082\u2083, submodule.span_insert_eq_span]\nend\n\n/-- The orthocenter lies in the altitudes. -/\nlemma orthocenter_mem_altitude (t : triangle \u211d P) {i\u2081 : fin 3} :\n  t.orthocenter \u2208 t.altitude i\u2081 :=\nbegin\n  obtain \u27e8i\u2082, i\u2083, h\u2081\u2082, h\u2082\u2083, h\u2081\u2083\u27e9 : \u2203 i\u2082 i\u2083, i\u2081 \u2260 i\u2082 \u2227 i\u2082 \u2260 i\u2083 \u2227 i\u2081 \u2260 i\u2083, by dec_trivial!,\n  rw [orthocenter_eq_monge_point, t.altitude_eq_monge_plane h\u2081\u2082 h\u2081\u2083 h\u2082\u2083],\n  exact t.monge_point_mem_monge_plane h\u2082\u2083\nend\n\n/-- The orthocenter is the only point lying in any two of the\naltitudes. -/\nlemma eq_orthocenter_of_forall_mem_altitude {t : triangle \u211d P} {i\u2081 i\u2082 : fin 3} {p : P}\n  (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081 : p \u2208 t.altitude i\u2081) (h\u2082 : p \u2208 t.altitude i\u2082) : p = t.orthocenter :=\nbegin\n  obtain \u27e8i\u2083, h\u2082\u2083, h\u2081\u2083\u27e9 : \u2203 i\u2083, i\u2082 \u2260 i\u2083 \u2227 i\u2081 \u2260 i\u2083, { clear h\u2081 h\u2082, dec_trivial! },\n  rw t.altitude_eq_monge_plane h\u2081\u2083 h\u2081\u2082 h\u2082\u2083.symm at h\u2081,\n  rw t.altitude_eq_monge_plane h\u2082\u2083 h\u2081\u2082.symm h\u2081\u2083.symm at h\u2082,\n  rw orthocenter_eq_monge_point,\n  have ha : \u2200 i, i\u2083 \u2260 i \u2192 p \u2208 t.monge_plane i\u2083 i,\n  { intros i hi,\n    have hi\u2081\u2082 : i\u2081 = i \u2228 i\u2082 = i, { clear h\u2081 h\u2082, dec_trivial! },\n    cases hi\u2081\u2082,\n    { exact hi\u2081\u2082 \u25b8 h\u2082 },\n    { exact hi\u2081\u2082 \u25b8 h\u2081 } },\n  exact eq_monge_point_of_forall_mem_monge_plane ha\nend\n\n/-- The distance from the orthocenter to the reflection of the\ncircumcenter in a side equals the circumradius. -/\n\n\n/-- The distance from the orthocenter to the reflection of the\ncircumcenter in a side equals the circumradius, variant using a\n`finset`. -/\nlemma dist_orthocenter_reflection_circumcenter_finset (t : triangle \u211d P) {i\u2081 i\u2082 : fin 3}\n  (h : i\u2081 \u2260 i\u2082) :\n  dist t.orthocenter (reflection (affine_span \u211d (t.points '' \u2191({i\u2081, i\u2082} : finset (fin 3))))\n                                 t.circumcenter) =\n    t.circumradius :=\nby { convert dist_orthocenter_reflection_circumcenter _ h, simp }\n\n/-- The affine span of the orthocenter and a vertex is contained in\nthe altitude. -/\nlemma affine_span_orthocenter_point_le_altitude (t : triangle \u211d P) (i : fin 3) :\n  affine_span \u211d {t.orthocenter, t.points i} \u2264 t.altitude i :=\nbegin\n  refine span_points_subset_coe_of_subset_coe _,\n  rw [set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8t.orthocenter_mem_altitude, t.mem_altitude i\u27e9\nend\n\n/-- Suppose we are given a triangle `t\u2081`, and replace one of its\nvertices by its orthocenter, yielding triangle `t\u2082` (with vertices not\nnecessarily listed in the same order).  Then an altitude of `t\u2082` from\na vertex that was not replaced is the corresponding side of `t\u2081`. -/\nlemma altitude_replace_orthocenter_eq_affine_span {t\u2081 t\u2082 : triangle \u211d P} {i\u2081 i\u2082 i\u2083 j\u2081 j\u2082 j\u2083 : fin 3}\n    (hi\u2081\u2082 : i\u2081 \u2260 i\u2082) (hi\u2081\u2083 : i\u2081 \u2260 i\u2083) (hi\u2082\u2083 : i\u2082 \u2260 i\u2083) (hj\u2081\u2082 : j\u2081 \u2260 j\u2082) (hj\u2081\u2083 : j\u2081 \u2260 j\u2083)\n    (hj\u2082\u2083 : j\u2082 \u2260 j\u2083) (h\u2081 : t\u2082.points j\u2081 = t\u2081.orthocenter) (h\u2082 : t\u2082.points j\u2082 = t\u2081.points i\u2082)\n    (h\u2083 : t\u2082.points j\u2083 = t\u2081.points i\u2083) :\n  t\u2082.altitude j\u2082 = affine_span \u211d {t\u2081.points i\u2081, t\u2081.points i\u2082} :=\nbegin\n  symmetry,\n  rw [\u2190h\u2082, t\u2082.affine_span_insert_singleton_eq_altitude_iff],\n  rw [h\u2082],\n  use (injective_of_affine_independent t\u2081.independent).ne hi\u2081\u2082,\n  have he : affine_span \u211d (set.range t\u2082.points) = affine_span \u211d (set.range t\u2081.points),\n  { refine ext_of_direction_eq _\n      \u27e8t\u2081.points i\u2083, mem_affine_span \u211d \u27e8j\u2083, h\u2083\u27e9, mem_affine_span \u211d (set.mem_range_self _)\u27e9,\n    refine eq_of_le_of_finrank_eq (direction_le (span_points_subset_coe_of_subset_coe _)) _,\n    { have hu : (finset.univ : finset (fin 3)) = {j\u2081, j\u2082, j\u2083}, { clear h\u2081 h\u2082 h\u2083, dec_trivial! },\n      rw [\u2190set.image_univ, \u2190finset.coe_univ, hu, finset.coe_insert, finset.coe_insert,\n          finset.coe_singleton, set.image_insert_eq, set.image_insert_eq, set.image_singleton,\n          h\u2081, h\u2082, h\u2083, set.insert_subset, set.insert_subset, set.singleton_subset_iff],\n      exact \u27e8t\u2081.orthocenter_mem_affine_span,\n             mem_affine_span \u211d (set.mem_range_self _),\n             mem_affine_span \u211d (set.mem_range_self _)\u27e9 },\n    { rw [direction_affine_span, direction_affine_span,\n          finrank_vector_span_of_affine_independent t\u2081.independent (fintype.card_fin _),\n          finrank_vector_span_of_affine_independent t\u2082.independent (fintype.card_fin _)] } },\n  rw he,\n  use mem_affine_span \u211d (set.mem_range_self _),\n  have hu : finset.univ.erase j\u2082 = {j\u2081, j\u2083}, { clear h\u2081 h\u2082 h\u2083, dec_trivial! },\n  rw [hu, finset.coe_insert, finset.coe_singleton, set.image_insert_eq, set.image_singleton,\n      h\u2081, h\u2083],\n  have hle : (t\u2081.altitude i\u2083).direction\u15ee \u2264\n    (affine_span \u211d ({t\u2081.orthocenter, t\u2081.points i\u2083} : set P)).direction\u15ee :=\n      submodule.orthogonal_le (direction_le (affine_span_orthocenter_point_le_altitude _ _)),\n  refine hle ((t\u2081.vector_span_le_altitude_direction_orthogonal i\u2083) _),\n  have hui : finset.univ.erase i\u2083 = {i\u2081, i\u2082}, { clear hle h\u2082 h\u2083, dec_trivial! },\n  rw [hui, finset.coe_insert, finset.coe_singleton, set.image_insert_eq, set.image_singleton],\n  refine vsub_mem_vector_span \u211d (set.mem_insert _ _)\n    (set.mem_insert_of_mem _ (set.mem_singleton _))\nend\n\n/-- Suppose we are given a triangle `t\u2081`, and replace one of its\nvertices by its orthocenter, yielding triangle `t\u2082` (with vertices not\nnecessarily listed in the same order).  Then the orthocenter of `t\u2082`\nis the vertex of `t\u2081` that was replaced. -/\nlemma orthocenter_replace_orthocenter_eq_point {t\u2081 t\u2082 : triangle \u211d P} {i\u2081 i\u2082 i\u2083 j\u2081 j\u2082 j\u2083 : fin 3}\n    (hi\u2081\u2082 : i\u2081 \u2260 i\u2082) (hi\u2081\u2083 : i\u2081 \u2260 i\u2083) (hi\u2082\u2083 : i\u2082 \u2260 i\u2083) (hj\u2081\u2082 : j\u2081 \u2260 j\u2082) (hj\u2081\u2083 : j\u2081 \u2260 j\u2083)\n    (hj\u2082\u2083 : j\u2082 \u2260 j\u2083) (h\u2081 : t\u2082.points j\u2081 = t\u2081.orthocenter) (h\u2082 : t\u2082.points j\u2082 = t\u2081.points i\u2082)\n    (h\u2083 : t\u2082.points j\u2083 = t\u2081.points i\u2083) :\n  t\u2082.orthocenter = t\u2081.points i\u2081 :=\nbegin\n  refine (triangle.eq_orthocenter_of_forall_mem_altitude hj\u2082\u2083 _ _).symm,\n  { rw altitude_replace_orthocenter_eq_affine_span hi\u2081\u2082 hi\u2081\u2083 hi\u2082\u2083 hj\u2081\u2082 hj\u2081\u2083 hj\u2082\u2083 h\u2081 h\u2082 h\u2083,\n    exact mem_affine_span \u211d (set.mem_insert _ _) },\n  { rw altitude_replace_orthocenter_eq_affine_span hi\u2081\u2083 hi\u2081\u2082 hi\u2082\u2083.symm hj\u2081\u2083 hj\u2081\u2082 hj\u2082\u2083.symm h\u2081 h\u2083 h\u2082,\n    exact mem_affine_span \u211d (set.mem_insert _ _) }\nend\n\nend triangle\n\nend affine\n\nnamespace euclidean_geometry\n\nopen affine affine_subspace finite_dimensional\n\nvariables {V : Type*} {P : Type*} [inner_product_space \u211d V] [metric_space P]\n    [normed_add_torsor V P]\n\ninclude V\n\n/-- Four points form an orthocentric system if they consist of the\nvertices of a triangle and its orthocenter. -/\ndef orthocentric_system (s : set P) : Prop :=\n\u2203 t : triangle \u211d P,\n  t.orthocenter \u2209 set.range t.points \u2227 s = insert t.orthocenter (set.range t.points)\n\n/-- This is an auxiliary lemma giving information about the relation\nof two triangles in an orthocentric system; it abstracts some\nreasoning, with no geometric content, that is common to some other\nlemmas.  Suppose the orthocentric system is generated by triangle `t`,\nand we are given three points `p` in the orthocentric system.  Then\neither we can find indices `i\u2081`, `i\u2082` and `i\u2083` for `p` such that `p\ni\u2081` is the orthocenter of `t` and `p i\u2082` and `p i\u2083` are points `j\u2082`\nand `j\u2083` of `t`, or `p` has the same points as `t`. -/\nlemma exists_of_range_subset_orthocentric_system {t : triangle \u211d P}\n  (ho : t.orthocenter \u2209 set.range t.points) {p : fin 3 \u2192 P}\n  (hps : set.range p \u2286 insert t.orthocenter (set.range t.points)) (hpi : function.injective p) :\n  (\u2203 (i\u2081 i\u2082 i\u2083 j\u2082 j\u2083 : fin 3), i\u2081 \u2260 i\u2082 \u2227 i\u2081 \u2260 i\u2083 \u2227 i\u2082 \u2260 i\u2083 \u2227\n    (\u2200 i : fin 3, i = i\u2081 \u2228 i = i\u2082 \u2228 i = i\u2083) \u2227 p i\u2081 = t.orthocenter \u2227 j\u2082 \u2260 j\u2083 \u2227\n    t.points j\u2082 = p i\u2082 \u2227 t.points j\u2083 = p i\u2083) \u2228 set.range p = set.range t.points :=\nbegin\n  by_cases h : t.orthocenter \u2208 set.range p,\n  { left,\n    rcases h with \u27e8i\u2081, h\u2081\u27e9,\n    obtain \u27e8i\u2082, i\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083\u27e9 :\n      \u2203 (i\u2082 i\u2083 : fin 3), i\u2081 \u2260 i\u2082 \u2227 i\u2081 \u2260 i\u2083 \u2227 i\u2082 \u2260 i\u2083 \u2227 \u2200 i : fin 3, i = i\u2081 \u2228 i = i\u2082 \u2228 i = i\u2083,\n    { clear h\u2081, dec_trivial! },\n    have h : \u2200 i, i\u2081 \u2260 i \u2192 \u2203 (j : fin 3), t.points j = p i,\n    { intros i hi,\n      replace hps := set.mem_of_mem_insert_of_ne\n        (set.mem_of_mem_of_subset (set.mem_range_self i) hps) (h\u2081 \u25b8 hpi.ne hi.symm),\n      exact hps },\n    rcases h i\u2082 h\u2081\u2082 with \u27e8j\u2082, h\u2082\u27e9,\n    rcases h i\u2083 h\u2081\u2083 with \u27e8j\u2083, h\u2083\u27e9,\n    have hj\u2082\u2083 : j\u2082 \u2260 j\u2083,\n    { intro he,\n      rw [he, h\u2083] at h\u2082,\n      exact h\u2082\u2083.symm (hpi h\u2082) },\n    exact \u27e8i\u2081, i\u2082, i\u2083, j\u2082, j\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083, h\u2081, hj\u2082\u2083, h\u2082, h\u2083\u27e9 },\n  { right,\n    have hs := set.subset_diff_singleton hps h,\n    rw set.insert_diff_self_of_not_mem ho at hs,\n    refine set.eq_of_subset_of_card_le hs _,\n    rw [set.card_range_of_injective hpi,\n        set.card_range_of_injective (injective_of_affine_independent t.independent)] }\nend\n\n/-- For any three points in an orthocentric system generated by\ntriangle `t`, there is a point in the subspace spanned by the triangle\nfrom which the distance of all those three points equals the circumradius. -/\nlemma exists_dist_eq_circumradius_of_subset_insert_orthocenter {t : triangle \u211d P}\n  (ho : t.orthocenter \u2209 set.range t.points) {p : fin 3 \u2192 P}\n  (hps : set.range p \u2286 insert t.orthocenter (set.range t.points)) (hpi : function.injective p) :\n  \u2203 c \u2208 affine_span \u211d (set.range t.points), \u2200 p\u2081 \u2208 set.range p, dist p\u2081 c = t.circumradius :=\nbegin\n  rcases exists_of_range_subset_orthocentric_system ho hps hpi with\n    \u27e8i\u2081, i\u2082, i\u2083, j\u2082, j\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083, h\u2081, hj\u2082\u2083, h\u2082, h\u2083\u27e9 | hs,\n  { use [reflection (affine_span \u211d (t.points '' {j\u2082, j\u2083})) t.circumcenter,\n         reflection_mem_of_le_of_mem (affine_span_mono \u211d (set.image_subset_range _ _))\n                                     t.circumcenter_mem_affine_span],\n    intros p\u2081 hp\u2081,\n    rcases hp\u2081 with \u27e8i, rfl\u27e9,\n    replace h\u2081\u2082\u2083 := h\u2081\u2082\u2083 i,\n    repeat { cases h\u2081\u2082\u2083 },\n    { rw h\u2081,\n      exact triangle.dist_orthocenter_reflection_circumcenter t hj\u2082\u2083 },\n    { rw [\u2190h\u2082,\n          dist_reflection_eq_of_mem _\n            (mem_affine_span \u211d (set.mem_image_of_mem _ (set.mem_insert _ _)))],\n      exact t.dist_circumcenter_eq_circumradius _ },\n    { rw [\u2190h\u2083,\n          dist_reflection_eq_of_mem _\n            (mem_affine_span \u211d (set.mem_image_of_mem _\n              (set.mem_insert_of_mem _ (set.mem_singleton _))))],\n      exact t.dist_circumcenter_eq_circumradius _ } },\n  { use [t.circumcenter, t.circumcenter_mem_affine_span],\n    intros p\u2081 hp\u2081,\n    rw hs at hp\u2081,\n    rcases hp\u2081 with \u27e8i, rfl\u27e9,\n    exact t.dist_circumcenter_eq_circumradius _ }\nend\n\n/-- Any three points in an orthocentric system are affinely independent. -/\nlemma orthocentric_system.affine_independent {s : set P} (ho : orthocentric_system s)\n    {p : fin 3 \u2192 P} (hps : set.range p \u2286 s) (hpi : function.injective p) :\n  affine_independent \u211d p :=\nbegin\n  rcases ho with \u27e8t, hto, hst\u27e9,\n  rw hst at hps,\n  rcases exists_dist_eq_circumradius_of_subset_insert_orthocenter hto hps hpi with \u27e8c, hcs, hc\u27e9,\n  exact cospherical.affine_independent \u27e8c, t.circumradius, hc\u27e9 set.subset.rfl hpi\nend\n\n/-- Any three points in an orthocentric system span the same subspace\nas the whole orthocentric system. -/\nlemma affine_span_of_orthocentric_system {s : set P} (ho : orthocentric_system s)\n    {p : fin 3 \u2192 P} (hps : set.range p \u2286 s) (hpi : function.injective p) :\n  affine_span \u211d (set.range p) = affine_span \u211d s :=\nbegin\n  have ha := ho.affine_independent hps hpi,\n  rcases ho with \u27e8t, hto, hts\u27e9,\n  have hs : affine_span \u211d s = affine_span \u211d (set.range t.points),\n  { rw [hts, affine_span_insert_eq_affine_span \u211d t.orthocenter_mem_affine_span] },\n  refine ext_of_direction_eq _\n    \u27e8p 0, mem_affine_span \u211d (set.mem_range_self _), mem_affine_span \u211d (hps (set.mem_range_self _))\u27e9,\n  have hfd : finite_dimensional \u211d (affine_span \u211d s).direction, { rw hs, apply_instance },\n  haveI := hfd,\n  refine eq_of_le_of_finrank_eq (direction_le (affine_span_mono \u211d hps)) _,\n  rw [hs, direction_affine_span, direction_affine_span,\n      finrank_vector_span_of_affine_independent ha (fintype.card_fin _),\n      finrank_vector_span_of_affine_independent t.independent (fintype.card_fin _)]\nend\n\n/-- All triangles in an orthocentric system have the same circumradius. -/\nlemma orthocentric_system.exists_circumradius_eq {s : set P} (ho : orthocentric_system s) :\n  \u2203 r : \u211d, \u2200 t : triangle \u211d P, set.range t.points \u2286 s \u2192 t.circumradius = r :=\nbegin\n  rcases ho with \u27e8t, hto, hts\u27e9,\n  use t.circumradius,\n  intros t\u2082 ht\u2082,\n  have ht\u2082s := ht\u2082,\n  rw hts at ht\u2082,\n  rcases exists_dist_eq_circumradius_of_subset_insert_orthocenter hto ht\u2082\n    (injective_of_affine_independent t\u2082.independent) with \u27e8c, hc, h\u27e9,\n  rw set.forall_range_iff at h,\n  have hs : set.range t.points \u2286 s,\n  { rw hts,\n    exact set.subset_insert _ _ },\n  rw [affine_span_of_orthocentric_system \u27e8t, hto, hts\u27e9 hs\n        (injective_of_affine_independent t.independent),\n      \u2190affine_span_of_orthocentric_system \u27e8t, hto, hts\u27e9 ht\u2082s\n        (injective_of_affine_independent t\u2082.independent)] at hc,\n  exact (t\u2082.eq_circumradius_of_dist_eq hc h).symm\nend\n\n/-- Given any triangle in an orthocentric system, the fourth point is\nits orthocenter. -/\nlemma orthocentric_system.eq_insert_orthocenter {s : set P} (ho : orthocentric_system s)\n    {t : triangle \u211d P} (ht : set.range t.points \u2286 s) :\n  s = insert t.orthocenter (set.range t.points) :=\nbegin\n  rcases ho with \u27e8t\u2080, ht\u2080o, ht\u2080s\u27e9,\n  rw ht\u2080s at ht,\n  rcases exists_of_range_subset_orthocentric_system ht\u2080o ht\n    (injective_of_affine_independent t.independent) with\n    \u27e8i\u2081, i\u2082, i\u2083, j\u2082, j\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083, h\u2081, hj\u2082\u2083, h\u2082, h\u2083\u27e9 | hs,\n  { obtain \u27e8j\u2081, hj\u2081\u2082, hj\u2081\u2083, hj\u2081\u2082\u2083\u27e9 :\n      \u2203 j\u2081 : fin 3, j\u2081 \u2260 j\u2082 \u2227 j\u2081 \u2260 j\u2083 \u2227 \u2200 j : fin 3, j = j\u2081 \u2228 j = j\u2082 \u2228 j = j\u2083,\n    { clear h\u2082 h\u2083, dec_trivial! },\n    suffices h : t\u2080.points j\u2081 = t.orthocenter,\n    { have hui : (set.univ : set (fin 3)) = {i\u2081, i\u2082, i\u2083}, { ext x, simpa using h\u2081\u2082\u2083 x },\n      have huj : (set.univ : set (fin 3)) = {j\u2081, j\u2082, j\u2083}, { ext x, simpa using hj\u2081\u2082\u2083 x },\n      rw [\u2190h, ht\u2080s, \u2190set.image_univ, huj, \u2190set.image_univ, hui],\n      simp_rw [set.image_insert_eq, set.image_singleton, h\u2081, \u2190h\u2082, \u2190h\u2083],\n      rw set.insert_comm },\n    exact (triangle.orthocenter_replace_orthocenter_eq_point\n      hj\u2081\u2082 hj\u2081\u2083 hj\u2082\u2083 h\u2081\u2082 h\u2081\u2083 h\u2082\u2083 h\u2081 h\u2082.symm h\u2083.symm).symm },\n  { rw hs,\n    convert ht\u2080s using 2,\n    exact triangle.orthocenter_eq_of_range_eq hs }\nend\n\nend euclidean_geometry\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/geometry/euclidean/monge_point.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.729946299509214}}
{"text": "/-\nCopyright (c) 2022 Christopher Hoskin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Christopher Hoskin\n\n! This file was ported from Lean 3 source module algebra.ring.idempotents\n! leanprover-community/mathlib commit 655994e298904d7e5bbd1e18c95defd7b543eb94\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Basic\nimport Mathlib.Algebra.GroupPower.Basic\nimport Mathlib.Algebra.Ring.Defs\n\n/-!\n# Idempotents\n\nThis file defines idempotents for an arbitary multiplication and proves some basic results,\nincluding:\n\n* `IsIdempotentElem.mul_of_commute`: In a semigroup, the product of two commuting idempotents is\n  an idempotent;\n* `IsIdempotentElem.one_sub_iff`: In a (non-associative) ring, `p` is an idempotent if and only if\n  `1-p` is an idempotent.\n* `IsIdempotentElem.pow_succ_eq`: In a monoid `p ^ (n+1) = p` for `p` an idempotent and `n` a\n  natural number.\n\n## Tags\n\nprojection, idempotent\n-/\n\n\nvariable {M N S M\u2080 M\u2081 R G G\u2080 : Type _}\n\nvariable [Mul M] [Monoid N] [Semigroup S] [MulZeroClass M\u2080] [MulOneClass M\u2081] [NonAssocRing R]\n  [Group G] [CancelMonoidWithZero G\u2080]\n\n/-- An element `p` is said to be idempotent if `p * p = p`\n-/\ndef IsIdempotentElem (p : M) : Prop :=\n  p * p = p\n#align is_idempotent_elem IsIdempotentElem\n\nnamespace IsIdempotentElem\n\ntheorem of_isIdempotent [IsIdempotent M (\u00b7 * \u00b7)] (a : M) : IsIdempotentElem a :=\n  IsIdempotent.idempotent a\n#align is_idempotent_elem.of_is_idempotent IsIdempotentElem.of_isIdempotent\n\ntheorem eq {p : M} (h : IsIdempotentElem p) : p * p = p :=\n  h\n#align is_idempotent_elem.eq IsIdempotentElem.eq\n\ntheorem mul_of_commute {p q : S} (h : Commute p q) (h\u2081 : IsIdempotentElem p)\n    (h\u2082 : IsIdempotentElem q) : IsIdempotentElem (p * q) := by\n  rw [IsIdempotentElem, mul_assoc, \u2190 mul_assoc q, \u2190 h.eq, mul_assoc p, h\u2082.eq, \u2190 mul_assoc, h\u2081.eq]\n#align is_idempotent_elem.mul_of_commute IsIdempotentElem.mul_of_commute\n\ntheorem zero : IsIdempotentElem (0 : M\u2080) :=\n  mul_zero _\n#align is_idempotent_elem.zero IsIdempotentElem.zero\n\ntheorem one : IsIdempotentElem (1 : M\u2081) :=\n  mul_one _\n#align is_idempotent_elem.one IsIdempotentElem.one\n\ntheorem one_sub {p : R} (h : IsIdempotentElem p) : IsIdempotentElem (1 - p) := by\n  rw [IsIdempotentElem, mul_sub, mul_one, sub_mul, one_mul, h.eq, sub_self, sub_zero]\n#align is_idempotent_elem.one_sub IsIdempotentElem.one_sub\n\n@[simp]\ntheorem one_sub_iff {p : R} : IsIdempotentElem (1 - p) \u2194 IsIdempotentElem p :=\n  \u27e8fun h => sub_sub_cancel 1 p \u25b8 h.one_sub, IsIdempotentElem.one_sub\u27e9\n#align is_idempotent_elem.one_sub_iff IsIdempotentElem.one_sub_iff\n\n\n\ntheorem pow_succ_eq {p : N} (n : \u2115) (h : IsIdempotentElem p) : p ^ (n + 1) = p :=\n  Nat.recOn n ((Nat.zero_add 1).symm \u25b8 pow_one p) fun n ih => by rw [pow_succ, ih, h.eq]\n#align is_idempotent_elem.pow_succ_eq IsIdempotentElem.pow_succ_eq\n\n@[simp]\ntheorem iff_eq_one {p : G} : IsIdempotentElem p \u2194 p = 1 :=\n  Iff.intro (fun h => mul_left_cancel ((mul_one p).symm \u25b8 h.eq : p * p = p * 1)) fun h =>\n    h.symm \u25b8 one\n#align is_idempotent_elem.iff_eq_one IsIdempotentElem.iff_eq_one\n\n@[simp]\ntheorem iff_eq_zero_or_one {p : G\u2080} : IsIdempotentElem p \u2194 p = 0 \u2228 p = 1 := by\n  refine'\n    Iff.intro (fun h => or_iff_not_imp_left.mpr fun hp => _) fun h =>\n      h.elim (fun hp => hp.symm \u25b8 zero) fun hp => hp.symm \u25b8 one\n  exact mul_left_cancel\u2080 hp (h.trans (mul_one p).symm)\n#align is_idempotent_elem.iff_eq_zero_or_one IsIdempotentElem.iff_eq_zero_or_one\n\n/-! ### Instances on `Subtype IsIdempotentElem` -/\n\n\nsection Instances\n\ninstance : Zero { p : M\u2080 // IsIdempotentElem p } where zero := \u27e80, zero\u27e9\n\n@[simp]\ntheorem coe_zero : \u2191(0 : { p : M\u2080 // IsIdempotentElem p }) = (0 : M\u2080) :=\n  rfl\n#align is_idempotent_elem.coe_zero IsIdempotentElem.coe_zero\n\ninstance : One { p : M\u2081 // IsIdempotentElem p } where one := \u27e81, one\u27e9\n\n@[simp]\ntheorem coe_one : \u2191(1 : { p : M\u2081 // IsIdempotentElem p }) = (1 : M\u2081) :=\n  rfl\n#align is_idempotent_elem.coe_one IsIdempotentElem.coe_one\n\ninstance : HasCompl { p : R // IsIdempotentElem p } :=\n  \u27e8fun p => \u27e81 - p, p.prop.one_sub\u27e9\u27e9\n\n@[simp]\ntheorem coe_compl (p : { p : R // IsIdempotentElem p }) : \u2191(p\u1d9c) = (1 : R) - \u2191p :=\n  rfl\n#align is_idempotent_elem.coe_compl IsIdempotentElem.coe_compl\n\n@[simp]\ntheorem compl_compl (p : { p : R // IsIdempotentElem p }) : p\u1d9c\u1d9c = p :=\n  Subtype.ext <| sub_sub_cancel _ _\n#align is_idempotent_elem.compl_compl IsIdempotentElem.compl_compl\n\n@[simp]\ntheorem zero_compl : (0 : { p : R // IsIdempotentElem p })\u1d9c = 1 :=\n  Subtype.ext <| sub_zero _\n#align is_idempotent_elem.zero_compl IsIdempotentElem.zero_compl\n\n@[simp]\ntheorem one_compl : (1 : { p : R // IsIdempotentElem p })\u1d9c = 0 :=\n  Subtype.ext <| sub_self _\n#align is_idempotent_elem.one_compl IsIdempotentElem.one_compl\n\nend Instances\n\nend IsIdempotentElem\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Ring/Idempotents.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7299224326134722}}
{"text": "/- \n\n# Advanced proposition world. \n\n## Level 5: `iff_trans` easter eggs.\n\nLet's try `iff_trans` again. Try proving it in other ways.\n\n### A trick.\n\nInstead of using `cases` on `h : P \u2194 Q` you can just access the proofs of `P \u2192 Q` and `Q \u2192 P`\ndirectly with `h.1` and `h.2`. So you can solve this level with\n\n```\nintros hpq hqr, \nsplit,\nintro p,\napply hqr.1,\n...\n```\n\n### Another trick\n\nInstead of using `cases` on `h : P \u2194 Q`, you can just `rw h`, and this will change all `P`s to `Q`s\nin the goal. You can use this to create a much shorter proof. Note that\nthis is an argument for *not* running the `cases` tactic on an iff statement;\nyou cannot rewrite one-way implications, but you can rewrite two-way implications.\n\n### Another trick\n\n`cc` works on this sort of goal too.\n-/\n\n/- Lemma : no-side-bar\nIf $P$, $Q$ and $R$ are true/false statements, then `P \u2194 Q` and `Q \u2194 R` together imply `P \u2194 R`.\n-/\nlemma iff_trans (P Q R : Prop) : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intros hpq hqr,\n  split,\n  intro p,\n  apply hqr.1,\n  apply hpq.1,\n  assumption,\n  intro r,\n  apply hpq.2,\n  apply hqr.2,\n  assumption,\n\n\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world7/level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7299224284382848}}
{"text": "/-\nCopyright (c) 2021 Sara D\u00edaz Real. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sara D\u00edaz Real\n-/\nimport data.int.basic\nimport algebra.associated\nimport tactic.linarith\nimport tactic.ring\n\n/-!\n# IMO 2001 Q6\nLet $a$, $b$, $c$, $d$ be integers with $a > b > c > d > 0$. Suppose that\n\n$$ a*c + b*d = (a + b - c + d) * (-a + b + c + d). $$\n\nProve that $a*b + c*d$ is not prime.\n\n-/\n\nvariables {a b c d : \u2124}\n\ntheorem imo2001_q6 (hd : 0 < d) (hdc : d < c) (hcb : c < b) (hba : b < a)\n  (h : a*c + b*d = (a + b - c + d) * (-a + b + c + d)) :\n  \u00ac prime (a*b + c*d) :=\nbegin\n  assume h0 : prime (a*b + c*d),\n  have ha : 0 < a, { linarith },\n  have hb : 0 < b, { linarith },\n  have hc : 0 < c, { linarith },\n  -- the key step is to show that `a*c + b*d` divides the product `(a*b + c*d) * (a*d + b*c)`\n  have dvd_mul : a*c + b*d \u2223 (a*b + c*d) * (a*d + b*c),\n  { use b^2 + b*d + d^2,\n    have equivalent_sums : a^2 - a*c + c^2 = b^2 + b*d + d^2,\n    { ring_nf at h, nlinarith only [h], },\n    calc  (a * b + c * d) * (a * d + b * c)\n        = a*c * (b^2 + b*d + d^2) + b*d * (a^2 - a*c + c^2) : by ring\n    ... = a*c * (b^2 + b*d + d^2) + b*d * (b^2 + b*d + d^2) : by rw equivalent_sums\n    ... = (a * c + b * d) * (b ^ 2 + b * d + d ^ 2)         : by ring, },\n  -- since `a*b + c*d` is prime (by assumption), it must divide `a*c + b*d` or `a*d + b*c`\n  obtain (h1 : a*b + c*d \u2223 a*c + b*d) | (h2 : a*c + b*d \u2223 a*d + b*c) :=\n    h0.left_dvd_or_dvd_right_of_dvd_mul dvd_mul,\n  -- in both cases, we derive a contradiction\n  { have aux : 0 < a*c + b*d,         { nlinarith only [ha, hb, hc, hd] },\n    have : a*b + c*d \u2264 a*c + b*d,     { from int.le_of_dvd aux h1 },\n    have : \u00ac (a*b + c*d \u2264 a*c + b*d), { nlinarith only [hba, hcb, hdc, h] },\n    contradiction, },\n  { have aux : 0 < a*d + b*c,         { nlinarith only [ha, hb, hc, hd] },\n    have : a*c + b*d \u2264 a*d + b*c,     { from int.le_of_dvd aux h2 },\n    have : \u00ac (a*c + b*d \u2264 a*d + b*c), { nlinarith only [hba, hdc, h] },\n    contradiction, },\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/archive/imo/imo2001_q6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7298975276076168}}
{"text": "\nsection \n\n-- Questao 62 Logica proposicional : LCP-62 \u00acA \u2192 B, \u00acB \u22a2 A\n\nvariables A B: Prop\n\nopen classical\n\nexample (h1: \u00ac A \u2192 B) (h2: \u00ac B) : A :=\n    by_contradiction(\n        assume h3: \u00ac A,\n        have h4: B,\n            from h1 h3,\n        show false,\n            from h2 h4) \n\nend\n\nsection\n\n-- Questao 65 Logica proposicional : LCP-65  \u00ac(A\u2227B), B \u22a2 \u00acA\n\nvariables A B: Prop\n\n\nexample (h1: \u00ac (A \u2227 B)) (h2:  B) : \u00ac A :=\n        assume h3: A,\n        have h4: A \u2227 B,\n            from and.intro h3 h2,\n        show false,\n            from h1 h4\n\nend\n\nsection \n\n-- Questao 35 Logica proposicional : LCP\u00ad35: (A\u2192B) \u22a2 ((C\u2228A)\u2192(B\u2228C))\n\nvariables A B C : Prop\n\nexample (h1: A \u2192 B) : ((C\u2228A)\u2192(B\u2228C)) :=\n    assume h2: (C\u2228A),\n    show (B\u2228C), from or.elim h2\n        (assume h3: C,\n        show B \u2228 C, from or.inr h3)\n        (assume h4: A,\n        show B \u2228 C, from or.inl (h1 h4))\n\nend \n\n\nsection \n\n-- Questao 99 Logica proposicional : LCP-99 \u00ac(\u00acA\u2227B\u2227\u00acC), B \u22a2 (A\u2228C)\n\nopen classical\nvariables {A B C : Prop}\n\nlemma step1 (h1 : \u00ac (A \u2228 B)) (h2 : \u00ac A) : \u00ac A \u2227 \u00ac B :=\nhave h5: \u00ac B, from (\nassume h3: B, \nhave h4: A \u2228 B, \nfrom or.inr h3,\nshow false,\nfrom h1 h4),\nshow \u00ac A \u2227 \u00ac B, from and.intro h2 h5\n\nlemma step2 (h\u2081 : \u00ac (A \u2228 B)) (h2 : \u00ac (\u00ac A \u2227 \u00ac B)) : false :=\nhave h3: A, from\n  (by_contradiction (assume h5: \u00ac A,\n    have h6: \u00ac A \u2227 \u00ac B, from step1 h\u2081 h5,\n    show false, from h2 h6)),\nhave h7: A \u2228 B, from or.inl h3,\nshow false, from h\u2081 h7\n\ntheorem step3 (h : \u00ac (A \u2228 B)) : \u00ac A \u2227 \u00ac B :=\nby_contradiction\n  (assume h' : \u00ac (\u00ac A \u2227 \u00ac B),\n    show false, from step2 h h')\n\n\nexample (h1: \u00ac(\u00acA \u2227 B \u2227 \u00acC)) (h2:  B) : A \u2228 C :=\n    by_contradiction(\n        assume h3: \u00ac (A \u2228 C),\n        have h5: \u00ac A \u2227 \u00ac C , \n        from step3 h3, \n        have h7: \u00ac A, from and.left h5,\n        have h8: \u00ac C, from and.right h5,\n        have h11: B \u2227 \u00ac C , from and.intro h2 h8,\n        have h4: \u00ac A \u2227 B \u2227 \u00ac C , from and.intro h7 h11, \n        show false,\n        from h1 h4\n    )\n\nend\n\nsection\n\n-- Questao 28 Logica de primeira ordem  :  \u2200x,(R(x)\u2194S(x)) \u22a2 \u2203y,R(y)\u2194\u2203z,S(z)\n\nvariable U : Type\nvariable R : U \u2192 Prop\nvariable S : U \u2192 Prop\n\nexample (h1: \u2200 x, (R x  \u2194 S x)) : (\u2203y,R y) \u2194 (\u2203z,S z) :=\n\nshow (\u2203y,R y) \u2194 (\u2203z, S z), from iff.intro\n  (assume h : \u2203y,R y,\n    show \u2203z ,S z, from exists.elim h (\n    assume (x : U) (hy: R x), \n    have h3: (R x  \u2194 S x), from h1 x,\n    have h4: S x, from iff.elim_left h3 hy,\n    show \u2203z ,S z, from exists.intro x h4))\n  (assume h : \u2203z,S z ,\n    show \u2203y,R y , from exists.elim h (\n    assume (x : U) (hy: S x), \n    have h3: (R x  \u2194 S x), from h1 x,\n    have h4: R x, from iff.elim_right h3 hy,\n    show \u2203z ,R z, from exists.intro x h4))\n\nend \n\nsection\n\n-- Questao 47 Logica de primeira ordem  :  \u2200x.(\u2203y.P(y)\u2192P(x)) \u22a2 \u2200x.\u2200y.(P(y)\u2192P(x))\n   \n    variable U : Type\n    variable P : U \u2192 Prop\n\n    example (h1 : \u2200 x,((\u2203 y, P y) \u2192 P x)) : \u2200 x, \u2200 y,( P y \u2192 P x) :=\n    assume a,\n    assume b, \n    assume h2: P b,\n    have h3: (\u2203 b, P b) \u2192 P a, from h1 a ,\n    have h4: \u2203 b, P b, from exists.intro b h2,\n    have h5: P a, from h3 h4 , \n    show P a, from h5\n  \nend\n\nsection\n\n-- Questao 13 Logica de primeira ordem  :   \u2200x.(P(x)\u2194Q) \u22a2 (\u2200x.P(x))\u2194Q\n\nvariables U Q: Prop\nvariable P : U \u2192 Prop\nvariable x: U\n\n\nexample (h1: (\u2200 x,(P x \u2194 Q))) : (\u2200 x,P x )\u2194 Q :=\nshow (\u2200 x,P x ) \u2194 Q, from iff.intro\n  (assume h : \u2200 x,P x ,\n    have h3: P x \u2194 Q, from h1 x,\n    have h4 : P x, from h x,\n    show Q, from iff.elim_left h3 h4)\n  (assume h : Q ,\n    assume y,\n    have h3: P x \u2194 Q, from h1 x,\n    have h4: P x, from iff.elim_right h3 h,\n    show P y  , from h4)\n\nend\n\nsection\n\n-- Questao 13 Logica de primeira ordem : LCPO31   P(i) \u22a2 \u00ac\u2200x.\u00acP(x)\n\nvariable U: Prop\nvariable P : U \u2192 Prop\nvariables i x: U\n\n\n-- BEGIN\n\n  example  h1: P i  : \u00ac\u2200 x,\u00ac P x :=\n  assume h : \u2200 x,\u00ac P x ,\n  show false, from (\n    have hi : \u00ac P i, from h i,\n    show false, from hi h1)\n\n-- END\n\n\n\nend\n\nsection\n\n-- Questao 773 dos desafios : \u22a2 (((A \u2192 B) \u2192 ((\u22a5 \u2192 C) \u2192 D)) \u2192 ((D \u2192 A) \u2192 (E \u2192 (F \u2192 A))))\n\nopen classical\n\nvariables A B C D E F: Prop\n\nexample: ((A \u2192 B) \u2192 ((false \u2192 C) \u2192 D)) \u2192 ((D \u2192 A) \u2192 (E \u2192 (F \u2192 A)))  :=\n    show (((A \u2192 B) \u2192 ((false \u2192 C) \u2192 D)) \u2192 ((D \u2192 A) \u2192 (E \u2192 (F \u2192 A)))), from \n    (\n        assume h1: (A \u2192 B) \u2192 ((false \u2192 C) \u2192 D),\n        show (D \u2192 A) \u2192 (E \u2192 (F \u2192 A)), from (\n            assume h2: (D \u2192 A), show  (E \u2192 (F \u2192 A)), from (\n                assume h3: E, show (F \u2192 A), from (\n                    assume h4: F,\n                    \n                    have hfalcd : (false \u2192 C) \u2192 D, from (\n                        have hab : A \u2192 B, from (\n                            assume ha : A,\n                            show B, from sorry\n                        ),\n                        show (false \u2192 C) \u2192 D, from h1 hab\n                    ),\n                    \n                    have hfalc : false \u2192 C, from (\n                        assume hfal : false,\n                        show C, from by_contradiction (\n                            assume hnc : \u00ac C,\n                            show false, from hfal\n                        )\n                    ),\n                    \n                    have hd : D, from hfalcd hfalc,\n\n                    show A, from h2 hd\n                )\n            )\n        )\n    )\nend\n\nsection\n\n-- Questao 386 dos desafios : ((A \u2192 B) \u2227 (C \u2192 D)), ((B \u2228 D) \u2192 E), (\u00acE) \u22a2 \u00ac(A \u2228 C)\n\nvariables A B C D E: Prop\n\nexample (h1: (A \u2192 B) \u2227 (C \u2192 D)) (h2: (B \u2228 D) \u2192 E) (h4: \u00acE ): \u00ac(A \u2228 C) :=\n    show \u00ac(A \u2228 C), from \n    (assume h: A \u2228 C, show false, from or.elim h \n        (assume p1 : A, show false, from \n            (have p2 : A \u2192 B, from and.left h1,\n             have p3 : B, from p2 p1,\n             have p4 : B \u2228 D, from or.inl p3,\n             have p5 : E, from h2 p4,\n             show false, from h4 p5\n            )\n        ) \n        (assume p1 : C, show false, from \n            (have p2 : C \u2192 D, from and.right h1,\n             have p3 : D, from p2 p1,\n             have p4 : B \u2228 D, from or.inr p3,\n             have p5 : E, from h2 p4,\n             show false, from h4 p5\n            )\n        )\n    )\n\nend\n\n", "meta": {"author": "IreneGinani", "repo": "Logica-Lean", "sha": "4b50a896da0c8953972effa749c3dbe111a25e7d", "save_path": "github-repos/lean/IreneGinani-Logica-Lean", "path": "github-repos/lean/IreneGinani-Logica-Lean/Logica-Lean-4b50a896da0c8953972effa749c3dbe111a25e7d/quest\u00f5es-logica.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7298945664182312}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.multiset.powerset\nimport Mathlib.PostPort\n\nuniverses u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# The antidiagonal on a multiset.\n\nThe antidiagonal of a multiset `s` consists of all pairs `(t\u2081, t\u2082)`\nsuch that `t\u2081 + t\u2082 = s`. These pairs are counted with multiplicities.\n-/\n\nnamespace multiset\n\n\n/-- The antidiagonal of a multiset `s` consists of all pairs `(t\u2081, t\u2082)`\n    such that `t\u2081 + t\u2082 = s`. These pairs are counted with multiplicities. -/\ndef antidiagonal {\u03b1 : Type u_1} (s : multiset \u03b1) : multiset (multiset \u03b1 \u00d7 multiset \u03b1) :=\n  quot.lift_on s (fun (l : List \u03b1) => \u2191(list.revzip (powerset_aux l))) sorry\n\ntheorem antidiagonal_coe {\u03b1 : Type u_1} (l : List \u03b1) : antidiagonal \u2191l = \u2191(list.revzip (powerset_aux l)) :=\n  rfl\n\n@[simp] theorem antidiagonal_coe' {\u03b1 : Type u_1} (l : List \u03b1) : antidiagonal \u2191l = \u2191(list.revzip (powerset_aux' l)) :=\n  quot.sound revzip_powerset_aux_perm_aux'\n\n/-- A pair `(t\u2081, t\u2082)` of multisets is contained in `antidiagonal s`\n    if and only if `t\u2081 + t\u2082 = s`. -/\n@[simp] theorem mem_antidiagonal {\u03b1 : Type u_1} {s : multiset \u03b1} {x : multiset \u03b1 \u00d7 multiset \u03b1} : x \u2208 antidiagonal s \u2194 prod.fst x + prod.snd x = s := sorry\n\n@[simp] theorem antidiagonal_map_fst {\u03b1 : Type u_1} (s : multiset \u03b1) : map prod.fst (antidiagonal s) = powerset s := sorry\n\n@[simp] theorem antidiagonal_map_snd {\u03b1 : Type u_1} (s : multiset \u03b1) : map prod.snd (antidiagonal s) = powerset s := sorry\n\n@[simp] theorem antidiagonal_zero {\u03b1 : Type u_1} : antidiagonal 0 = (0, 0) ::\u2098 0 :=\n  rfl\n\n@[simp] theorem antidiagonal_cons {\u03b1 : Type u_1} (a : \u03b1) (s : multiset \u03b1) : antidiagonal (a ::\u2098 s) = map (prod.map id (cons a)) (antidiagonal s) + map (prod.map (cons a) id) (antidiagonal s) := sorry\n\n@[simp] theorem card_antidiagonal {\u03b1 : Type u_1} (s : multiset \u03b1) : coe_fn card (antidiagonal s) = bit0 1 ^ coe_fn card s := sorry\n\ntheorem prod_map_add {\u03b1 : Type u_1} {\u03b2 : Type u_2} [comm_semiring \u03b2] {s : multiset \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} : prod (map (fun (a : \u03b1) => f a + g a) s) =\n  sum\n    (map (fun (p : multiset \u03b1 \u00d7 multiset \u03b1) => prod (map f (prod.fst p)) * prod (map g (prod.snd p))) (antidiagonal s)) := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/multiset/antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7298945496443199}}
{"text": "-- Interseccion_de_los_primos_y_los_mayores_que_dos.lean\n-- Intersecci\u00f3n de los primos y los mayores que dos\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 1 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Los n\u00fameros primos, los mayores que 2 y los impares se definen por\n--    def primos      : set \u2115 := {n | prime n}\n--    def mayoresQue2 : set \u2115 := {n | n > 2}\n--    def impares     : set \u2115 := {n | \u00ac even n}\n--\n-- Demostrar que\n--    primos \u2229 mayoresQue2 \u2286 impares\n-- ----------------------------------------------------------------------\n\nimport data.nat.parity\nimport data.nat.prime\nimport tactic\n\nopen nat\n\ndef primos      : set \u2115 := {n | nat.prime n}\ndef mayoresQue2 : set \u2115 := {n | n > 2}\ndef impares     : set \u2115 := {n | \u00ac even n}\n\nexample : primos \u2229 mayoresQue2 \u2286 impares :=\nbegin\n  unfold primos mayoresQue2 impares,\n  intro n,\n  simp,\n  intro hn,\n  cases prime.eq_two_or_odd hn with h h,\n  { rw h,\n    intro,\n    linarith, },\n  { rw even_iff,\n    rw h,\n    norm_num },\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Interseccion_de_los_primos_y_los_mayores_que_dos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.729894547668395}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,\nNeil Strickland, Aaron Anderson\n-/\n\nimport algebra.group_with_zero.basic\n\n/-!\n# Divisibility\n\nThis file defines the basics of the divisibility relation in the context of `(comm_)` `monoid`s\n`(_with_zero)`.\n\n## Main definitions\n\n * `monoid.has_dvd`\n\n## Implementation notes\n\nThe divisibility relation is defined for all monoids, and as such, depends on the order of\n  multiplication if the monoid is not commutative. There are two possible conventions for\n  divisibility in the noncommutative context, and this relation follows the convention for ordinals,\n  so `a | b` is defined as `\u2203 c, b = a * c`.\n\n## Tags\n\ndivisibility, divides\n-/\n\nvariables {\u03b1 : Type*}\n\nsection monoid\n\nvariables [monoid \u03b1] {a b c : \u03b1}\n\n/-- There are two possible conventions for divisibility, which coincide in a `comm_monoid`.\n    This matches the convention for ordinals. -/\n@[priority 100]\ninstance monoid_has_dvd : has_dvd \u03b1 :=\nhas_dvd.mk (\u03bb a b, \u2203 c, b = a * c)\n\n-- TODO: this used to not have `c` explicit, but that seems to be important\n--       for use with tactics, similar to `exists.intro`\ntheorem dvd.intro (c : \u03b1) (h : a * c = b) : a \u2223 b :=\nexists.intro c h^.symm\n\nalias dvd.intro \u2190 dvd_of_mul_right_eq\n\ntheorem exists_eq_mul_right_of_dvd (h : a \u2223 b) : \u2203 c, b = a * c := h\n\ntheorem dvd.elim {P : Prop} {a b : \u03b1} (H\u2081 : a \u2223 b) (H\u2082 : \u2200 c, b = a * c \u2192 P) : P :=\nexists.elim H\u2081 H\u2082\n\n@[refl, simp] theorem dvd_refl (a : \u03b1) : a \u2223 a :=\ndvd.intro 1 (mul_one _)\n\nlemma dvd_rfl {a : \u03b1} : a \u2223 a :=\ndvd_refl a\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\n@[trans] theorem dvd_trans (h\u2081 : a \u2223 b) (h\u2082 : b \u2223 c) : a \u2223 c :=\nmatch h\u2081, h\u2082 with\n| \u27e8d, (h\u2083 : b = a * d)\u27e9, \u27e8e, (h\u2084 : c = b * e)\u27e9 :=\n  \u27e8d * e, show c = a * (d * e), by simp [h\u2083, h\u2084]\u27e9\nend\n\nalias dvd_trans \u2190 has_dvd.dvd.trans\n\ntheorem one_dvd (a : \u03b1) : 1 \u2223 a := dvd.intro a (one_mul _)\n\n@[simp] theorem dvd_mul_right (a b : \u03b1) : a \u2223 a * b := dvd.intro b rfl\n\ntheorem dvd_mul_of_dvd_left (h : a \u2223 b) (c : \u03b1) : a \u2223 b * c :=\nh.trans (dvd_mul_right b c)\n\nalias dvd_mul_of_dvd_left \u2190 has_dvd.dvd.mul_right\n\ntheorem dvd_of_mul_right_dvd (h : a * b \u2223 c) : a \u2223 c :=\n(dvd_mul_right a b).trans h\n\nsection map_dvd\n\nvariables {M N : Type*}\n\nlemma mul_hom.map_dvd [monoid M] [monoid N] (f : mul_hom M N) {a b} : a \u2223 b \u2192 f a \u2223 f b\n| \u27e8c, h\u27e9 := \u27e8f c, h.symm \u25b8 f.map_mul a c\u27e9\n\nlemma monoid_hom.map_dvd [monoid M] [monoid N] (f : M \u2192* N) {a b} : a \u2223 b \u2192 f a \u2223 f b :=\nf.to_mul_hom.map_dvd\n\nend map_dvd\n\nend monoid\n\nsection comm_monoid\n\nvariables [comm_monoid \u03b1] {a b c : \u03b1}\n\ntheorem dvd.intro_left (c : \u03b1) (h : c * a = b) : a \u2223 b :=\ndvd.intro _ (begin rewrite mul_comm at h, apply h end)\n\nalias dvd.intro_left \u2190 dvd_of_mul_left_eq\n\ntheorem exists_eq_mul_left_of_dvd (h : a \u2223 b) : \u2203 c, b = c * a :=\ndvd.elim h (assume c, assume H1 : b = a * c, exists.intro c (eq.trans H1 (mul_comm a c)))\n\nlemma dvd_iff_exists_eq_mul_left : a \u2223 b \u2194 \u2203 c, b = c * a :=\n\u27e8exists_eq_mul_left_of_dvd, by { rintro \u27e8c, rfl\u27e9, exact \u27e8c, mul_comm _ _\u27e9, }\u27e9\n\ntheorem dvd.elim_left {P : Prop} (h\u2081 : a \u2223 b) (h\u2082 : \u2200 c, b = c * a \u2192 P) : P :=\nexists.elim (exists_eq_mul_left_of_dvd h\u2081) (assume c, assume h\u2083 : b = c * a, h\u2082 c h\u2083)\n\n@[simp] theorem dvd_mul_left (a b : \u03b1) : a \u2223 b * a := dvd.intro b (mul_comm a b)\n\ntheorem dvd_mul_of_dvd_right (h : a \u2223 b) (c : \u03b1) : a \u2223 c * b :=\nbegin rw mul_comm, exact h.mul_right _ end\n\nalias dvd_mul_of_dvd_right \u2190 has_dvd.dvd.mul_left\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\ntheorem mul_dvd_mul : \u2200 {a b c d : \u03b1}, a \u2223 b \u2192 c \u2223 d \u2192 a * c \u2223 b * d\n| a ._ c ._ \u27e8e, rfl\u27e9 \u27e8f, rfl\u27e9 := \u27e8e * f, by simp\u27e9\n\ntheorem mul_dvd_mul_left (a : \u03b1) {b c : \u03b1} (h : b \u2223 c) : a * b \u2223 a * c :=\nmul_dvd_mul (dvd_refl a) h\n\ntheorem mul_dvd_mul_right (h : a \u2223 b) (c : \u03b1) : a * c \u2223 b * c :=\nmul_dvd_mul h (dvd_refl c)\n\ntheorem dvd_of_mul_left_dvd (h : a * b \u2223 c) : b \u2223 c :=\ndvd.elim h (\u03bb d ceq, dvd.intro (a * d) (by simp [ceq]))\n\nend comm_monoid\n\nsection monoid_with_zero\n\nvariables [monoid_with_zero \u03b1] {a : \u03b1}\n\ntheorem eq_zero_of_zero_dvd (h : 0 \u2223 a) : a = 0 :=\ndvd.elim h (assume c, assume H' : a = 0 * c, eq.trans H' (zero_mul c))\n\n/-- Given an element `a` of a commutative monoid with zero, there exists another element whose\n    product with zero equals `a` iff `a` equals zero. -/\n@[simp] lemma zero_dvd_iff : 0 \u2223 a \u2194 a = 0 :=\n\u27e8eq_zero_of_zero_dvd, \u03bb h, by rw h\u27e9\n\n@[simp] theorem dvd_zero (a : \u03b1) : a \u2223 0 := dvd.intro 0 (by simp)\n\nend monoid_with_zero\n\n/-- Given two elements `b`, `c` of a `cancel_monoid_with_zero` and a nonzero element `a`,\n `a*b` divides `a*c` iff `b` divides `c`. -/\ntheorem mul_dvd_mul_iff_left [cancel_monoid_with_zero \u03b1] {a b c : \u03b1}\n  (ha : a \u2260 0) : a * b \u2223 a * c \u2194 b \u2223 c :=\nexists_congr $ \u03bb d, by rw [mul_assoc, mul_right_inj' ha]\n\n/-- Given two elements `a`, `b` of a commutative `cancel_monoid_with_zero` and a nonzero\n  element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/\ntheorem mul_dvd_mul_iff_right [comm_cancel_monoid_with_zero \u03b1] {a b c : \u03b1} (hc : c \u2260 0) :\n  a * c \u2223 b * c \u2194 a \u2223 b :=\nexists_congr $ \u03bb d, by rw [mul_right_comm, mul_left_inj' hc]\n\n/-!\n### Units in various monoids\n-/\n\nnamespace units\n\nsection monoid\nvariables [monoid \u03b1] {a b : \u03b1} {u : units \u03b1}\n\n/-- Elements of the unit group of a monoid represented as elements of the monoid\n    divide any element of the monoid. -/\nlemma coe_dvd : \u2191u \u2223 a := \u27e8\u2191u\u207b\u00b9 * a, by simp\u27e9\n\n/-- In a monoid, an element `a` divides an element `b` iff `a` divides all\n    associates of `b`. -/\nlemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\niff.intro\n  (assume \u27e8c, eq\u27e9, \u27e8c * \u2191u\u207b\u00b9, by rw [\u2190 mul_assoc, \u2190 eq, units.mul_inv_cancel_right]\u27e9)\n  (assume \u27e8c, eq\u27e9, eq.symm \u25b8 (dvd_mul_right _ _).mul_right _)\n\n/-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/\nlemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\niff.intro\n  (\u03bb \u27e8c, eq\u27e9, \u27e8\u2191u * c, eq.trans (mul_assoc _ _ _)\u27e9)\n  (\u03bb h, dvd_trans (dvd.intro \u2191u\u207b\u00b9 (by rw [mul_assoc, u.mul_inv, mul_one])) h)\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] {a b : \u03b1} {u : units \u03b1}\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\nlemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b := by { rw mul_comm, apply dvd_mul_right }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\nlemma mul_left_dvd : \u2191u * a \u2223 b \u2194 a \u2223 b :=\nby { rw mul_comm, apply mul_right_dvd }\n\nend comm_monoid\n\nend units\n\nnamespace is_unit\n\nsection monoid\n\nvariables [monoid \u03b1] {a b u : \u03b1} (hu : is_unit u)\ninclude hu\n\n/-- Units of a monoid divide any element of the monoid. -/\n@[simp] lemma dvd : u \u2223 a := by { rcases hu with \u27e8u, rfl\u27e9, apply units.coe_dvd, }\n\n@[simp] lemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_right, }\n\n/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/\n@[simp] lemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_right_dvd, }\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] (a b u : \u03b1) (hu : is_unit u)\ninclude hu\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\n@[simp] lemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_left, }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\n@[simp] lemma mul_left_dvd : u * a \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_left_dvd, }\n\nend comm_monoid\n\nend is_unit\n\nsection comm_monoid_with_zero\n\nvariable [comm_monoid_with_zero \u03b1]\n\n/-- `dvd_not_unit a b` expresses that `a` divides `b` \"strictly\", i.e. that `b` divided by `a`\nis not a unit. -/\ndef dvd_not_unit (a b : \u03b1) : Prop := a \u2260 0 \u2227 \u2203 x, \u00acis_unit x \u2227 b = a * x\n\nlemma dvd_not_unit_of_dvd_of_not_dvd {a b : \u03b1} (hd : a \u2223 b) (hnd : \u00ac b \u2223 a) :\n  dvd_not_unit a b :=\nbegin\n  split,\n  { rintro rfl, exact hnd (dvd_zero _) },\n  { rcases hd with \u27e8c, rfl\u27e9,\n    refine \u27e8c, _, rfl\u27e9,\n    rintro \u27e8u, rfl\u27e9,\n    simpa using hnd }\nend\n\nend comm_monoid_with_zero\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.729892946642289}}
{"text": "import data.set classical algebra.order data.nat\nopen set eq.ops\n\nnamespace relations\n\nvariable {T : Type}\n\n/- [KS]\nGiven a set S, a partition of S is a set X \u2286 \u2118(S) (that is, a set of subsets of S) with the following properties:\n1. The union of all sets in X is equal to S.\n2. For any S1, S2 \u2208 X with S1 \u2260 S2, we have that S1 \u2229 S2 = \u00d8 (S1 and S2 are disjoint)\n3. \u00d8 \u2209 X.\n-/\n\ndefinition pairwise_disjoint (Xs : set (set T)) := \u2200 \u2983 X1 X2 : set T \u2984, X1 \u2208 Xs \u2192 X2 \u2208 Xs \u2192 X1 \u2260 X2 \u2192 X1 \u2229 X2 = \u2205\n\ndefinition big_union (Xs : set (set T)) : set T := \u03bb x, \u2203 xs, xs \u2208 Xs \u2227 x \u2208 xs\ndefinition powerset (xs : set T) : set (set T) := \u03bb ys, ys \u2286 xs\n\nstructure partition (xs : set T) (Xs : set (set T)) :=\n  mk :: (in_powerset : Xs \u2286 powerset xs)\n        (spans : big_union Xs = xs)\n        (pdisjoint : pairwise_disjoint Xs)\n        (ncempty : \u00ac \u2205 \u2208 Xs)\n\nopen partition\n\n-- Choice functions (not the end of the world)\n-- (if we go down this road, we would hide the definitions from students, and just give them (1), (3) and (4))\n\ndefinition cover {xs : set T} {Xs : set (set T)} (p : partition xs Xs) (x : T) : set T := epsilon (\u03bb ys, ys \u2208 Xs \u2227 x \u2208 ys)\n\ndefinition cover_exists {xs : set T} {Xs : set (set T)} (p : partition xs Xs) (x : T) (x_in_xs : x \u2208 xs) : \u2203 ys, ys \u2208 Xs \u2227 x \u2208 ys := \n  (spans p)\u207b\u00b9 \u25b8 x_in_xs\n\nlemma x_in_cover_x {xs : set T} {Xs : set (set T)} (p : partition xs Xs) (x : T) (x_in_xs : x \u2208 xs) : x \u2208 cover p x := \n  and.right (epsilon_spec (cover_exists p x x_in_xs))\n\nlemma cover_x_in_Xs {xs : set T} {Xs : set (set T)} (p : partition xs Xs) (x : T) (x_in_xs : x \u2208 xs) : cover p x \u2208 Xs := \n  and.left (epsilon_spec (cover_exists p x x_in_xs))\n\n/- [KS]\nLemma: Let S be a set and X a partition of S. Then every element u \u2208 S belongs to exactly one set\nY \u2208 X\nProof: Let S be a set and X a partition of S. We will show that every element u \u2208 S belongs to at least\none set Y \u2208 X and to at most one set Y \u2208 X.\nTo see that every element u \u2208 S belongs to at least one set Y \u2208 X, note that since X is a partition of S,\nthe union of all the sets in S must be equal to S. Consequently, there must be at least one set Y \u2208 X\nsuch that u \u2208 Y, since otherwise the union of all sets contained in X would not be equal to S.\nTo see that every element u \u2208 S belongs to at most one set Y \u2208 X, suppose for the sake of contradiction\nthat u belongs to two sets Y1, Y2 \u2208 X with Y1 \u2260 Y2. But then x \u2208 Y1 \u2229 Y2, meaning that\nY1 \u2229 Y2 \u2260 \u00d8, a contradiction. We have reached a contradiction, so our assumption must have been\nwrong.\nThus every element u \u2208 S belongs to at most one set Y \u2208 X. \u25a0\n-/\n\ndefinition exactly_one [reducible] {T : Type} (P : T \u2192 Prop) := (\u2203 (u : T), P u) \u2227 (\u2200 u v : T, P u \u2192 P v \u2192 u = v)\n\n-- Lemma: Let S be a set and X a partition of S. Then every element u \u2208 S belongs to exactly one set Y \u2208 X.\ndefinition unique_set : \u2200 {S : set T} {X : set (set T)}, partition S X \u2192 \u2200 (u : T), u \u2208 S \u2192 exactly_one (\u03bb (Y : set T), Y \u2208 X \u2227 u \u2208 Y) :=\n  -- Proof: Let S be a set and X a partition of S. \n  assume (S : set T) (X : set (set T)) (p : partition S X) (u : T) (u_in_S : u \u2208 S),\n  -- We will show that every element u \u2208 S belongs to at least one set Y \u2208 X and to at most one set Y \u2208 X.\n  show (\u2203 (Y : set T), Y \u2208 X \u2227 u \u2208 Y) \u2227 (\u2200 (Y1 Y2 : set T), (Y1 \u2208 X \u2227 u \u2208 Y1) \u2192 (Y2 \u2208 X \u2227 u \u2208 Y2) \u2192 Y1 = Y2), from\n  -- To see that every element u \u2208 S belongs to at least one set Y \u2208 X, \n  have exists_Y : \u2203 (Y : set T), Y \u2208 X \u2227 u \u2208 Y, from\n    -- note that since X is a partition of S, the union of all the sets in S must be equal to S. \n    -- Consequently, there must be at least one set Y \u2208 X such that u \u2208 Y, \n    -- since otherwise the union of all sets contained in X would not be equal to S.\n    have u_in_bigX : u \u2208 big_union X, from (spans p)\u207b\u00b9 \u25b8 u_in_S,\n    u_in_bigX,\n  -- To see that every element u \u2208 S belongs to at most one set Y \u2208 X, \n  have unique : (\u2200 (Y1 Y2 : set T), (Y1 \u2208 X \u2227 u \u2208 Y1) \u2192 (Y2 \u2208 X \u2227 u \u2208 Y2) \u2192 Y1 = Y2), from\n    -- suppose for the sake of contradiction that u belongs to two sets Y1, Y2 \u2208 X with Y1 \u2260 Y2. \n    assume (Y1 Y2 : set T) (HY1 : Y1 \u2208 X \u2227 u \u2208 Y1) (HY2 : Y2 \u2208 X \u2227 u \u2208 Y2),\n    by_contradiction\n      (assume Y1_neq_Y2 : Y1 \u2260 Y2, \n       show false, from\n       -- But then u \u2208 Y1 \u2229 Y2,\n       have u_in_Y1capY2 : u \u2208 Y1 \u2229 Y2, from and.intro (and.right HY1) (and.right HY2),\n       -- meaning that Y1 \u2229 Y2 \u2260 \u00d8, a contradiction. \n       have Y1capY2_nempty : Y1 \u2229 Y2 \u2260 \u2205, from \n         assume Y1capY2_empty : Y1 \u2229 Y2 = \u2205, \n         have u_in_emptyset : u \u2208 \u2205, from Y1capY2_empty \u25b8 u_in_Y1capY2,\n         show false, from u_in_emptyset,\n       -- We have reached a contradiction, so our assumption must have been wrong.\n       absurd (pdisjoint p (and.left HY1) (and.left HY2) Y1_neq_Y2) Y1capY2_nempty),\n  -- Thus every element u \u2208 S belongs to at most one set Y \u2208 X. \n  show exactly_one (\u03bb (Y : set T), Y \u2208 X \u2227 u \u2208 Y), from and.intro exists_Y unique\n  -- \u25a0\n\ndefinition set_of_sets (f : T \u2192 set T) : set (set T) := \u03bb (s : set T), \u2203 (u : T), s = f u\ndefinition bigcup (Xs : set (set T)) : set T := \u03bb (v: T), \u2203 (X : set T), X \u2208 Xs \u2227 v \u2208 X\n\nlemma equiv_spans : \u2200 {R : T \u2192 T \u2192 Prop}, equivalence R \u2192 \u2200 v, v \u2208 bigcup (set_of_sets R) :=\n  assume (R : T \u2192 T \u2192 Prop) (R_equiv : equivalence R) (v : T),\n  show \u2203 (X : set T), X \u2208 (set_of_sets R) \u2227 v \u2208 X, from\n  let X := R v in\n  have X_in_ssR : X \u2208 set_of_sets R, from exists.intro v rfl,\n  have v_in_X : v \u2208 X, from and.left R_equiv v,\n  exists.intro X (and.intro X_in_ssR v_in_X)\n\nend relations\n\n", "meta": {"author": "dselsam", "repo": "cs103", "sha": "31ab9784a6f65f226efb702a0da52f907c616a71", "save_path": "github-repos/lean/dselsam-cs103", "path": "github-repos/lean/dselsam-cs103/cs103-31ab9784a6f65f226efb702a0da52f907c616a71/rel_set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7298929367934124}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n\n! This file was ported from Lean 3 source module algebra.invertible\n! leanprover-community/mathlib commit 10b4e499f43088dd3bb7b5796184ad5216648ab1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Units\nimport Mathlib.Algebra.GroupWithZero.Units.Lemmas\nimport Mathlib.Algebra.Ring.Defs\n/-!\n# Invertible elements\n\nThis file defines a typeclass `Invertible a` for elements `a` with a two-sided\nmultiplicative inverse.\n\nThe intent of the typeclass is to provide a way to write e.g. `\u215f2` in a ring\nlike `\u2124[1/2]` where some inverses exist but there is no general `\u207b\u00b9` operator;\nor to specify that a field has characteristic `\u2260 2`.\nIt is the `Type`-valued analogue to the `Prop`-valued `IsUnit`.\n\nFor constructions of the invertible element given a characteristic, see\n`Algebra/Char_P/Invertible` and other lemmas in that file.\n\n## Notation\n\n * `\u215fa` is `Invertible.invOf a`, the inverse of `a`\n\n## Implementation notes\n\nThe `Invertible` class lives in `Type`, not `Prop`, to make computation easier.\nIf multiplication is associative, `Invertible` is a subsingleton anyway.\n\nThe `simp` normal form tries to normalize `\u215fa` to `a \u207b\u00b9`. Otherwise, it pushes\n`\u215f` inside the expression as much as possible.\n\nSince `Invertible a` is not a `Prop` (but it is a `Subsingleton`), we have to be careful about\ncoherence issues: we should avoid having multiple non-defeq instances for `Invertible a` in the\nsame context.  This file plays it safe and uses `def` rather than `instance` for most definitions,\nusers can choose which instances to use at the point of use.\n\nFor example, here's how you can use an `Invertible 1` instance:\n```lean\nvariables {\u03b1 : Type _} [monoid \u03b1]\n\ndef something_that_needs_inverses (x : \u03b1) [Invertible x] := sorry\n\nsection\nlocal attribute [instance] invertibleOne\ndef something_one := something_that_needs_inverses 1\nend\n```\n\n## Tags\n\ninvertible, inverse element, invOf, a half, one half, a third, one third, \u00bd, \u2153\n\n-/\n\n\nuniverse u\n\nvariable {\u03b1 : Type u}\n\n/-- `Invertible a` gives a two-sided multiplicative inverse of `a`. -/\nclass Invertible [Mul \u03b1] [One \u03b1] (a : \u03b1) : Type u where\n  /-- The inverse of an `Invertible` element -/\n  invOf : \u03b1\n  /-- `invOf a` is a left inverse of `a` -/\n  invOf_mul_self : invOf * a = 1\n  /-- `invOf a` is a right inverse of `a` -/\n  mul_invOf_self : a * invOf = 1\n#align invertible Invertible\n\n/-- The inverse of an `Invertible` element -/\nprefix:max\n  \"\u215f\" =>-- This notation has the same precedence as `Inv.inv`.\n  Invertible.invOf\n\n@[simp]\ntheorem invOf_mul_self [Mul \u03b1] [One \u03b1] (a : \u03b1) [Invertible a] : \u215f a * a = 1 :=\n  Invertible.invOf_mul_self\n#align inv_of_mul_self invOf_mul_self\n\n@[simp]\ntheorem mul_invOf_self [Mul \u03b1] [One \u03b1] (a : \u03b1) [Invertible a] : a * \u215f a = 1 :=\n  Invertible.mul_invOf_self\n#align mul_inv_of_self mul_invOf_self\n\n@[simp]\ntheorem invOf_mul_self_assoc [Monoid \u03b1] (a b : \u03b1) [Invertible a] : \u215f a * (a * b) = b := by\n  rw [\u2190 mul_assoc, invOf_mul_self, one_mul]\n#align inv_of_mul_self_assoc invOf_mul_self_assoc\n\n@[simp]\ntheorem mul_invOf_self_assoc [Monoid \u03b1] (a b : \u03b1) [Invertible a] : a * (\u215f a * b) = b := by\n  rw [\u2190 mul_assoc, mul_invOf_self, one_mul]\n#align mul_inv_of_self_assoc mul_invOf_self_assoc\n\n@[simp]\ntheorem mul_invOf_mul_self_cancel [Monoid \u03b1] (a b : \u03b1) [Invertible b] : a * \u215f b * b = a := by\n  simp [mul_assoc]\n#align mul_inv_of_mul_self_cancel mul_invOf_mul_self_cancel\n\n@[simp]\ntheorem mul_mul_invOf_self_cancel [Monoid \u03b1] (a b : \u03b1) [Invertible b] : a * b * \u215f b = a := by\n  simp [mul_assoc]\n#align mul_mul_inv_of_self_cancel mul_mul_invOf_self_cancel\n\ntheorem invOf_eq_right_inv [Monoid \u03b1] {a b : \u03b1} [Invertible a] (hac : a * b = 1) : \u215f a = b :=\n  left_inv_eq_right_inv (invOf_mul_self _) hac\n#align inv_of_eq_right_inv invOf_eq_right_inv\n\ntheorem invOf_eq_left_inv [Monoid \u03b1] {a b : \u03b1} [Invertible a] (hac : b * a = 1) : \u215f a = b :=\n  (left_inv_eq_right_inv hac (mul_invOf_self _)).symm\n#align inv_of_eq_left_inv invOf_eq_left_inv\n\ntheorem invertible_unique {\u03b1 : Type u} [Monoid \u03b1] (a b : \u03b1) [Invertible a] [Invertible b]\n    (h : a = b) : \u215f a = \u215f b := by\n  apply invOf_eq_right_inv\n  rw [h, mul_invOf_self]\n#align invertible_unique invertible_unique\n\ninstance [Monoid \u03b1] (a : \u03b1) : Subsingleton (Invertible a) :=\n  \u27e8fun \u27e8b, hba, hab\u27e9 \u27e8c, _, hac\u27e9 => by\n    congr\n    exact left_inv_eq_right_inv hba hac\u27e9\n\n/-- If `r` is invertible and `s = r`, then `s` is invertible. -/\ndef Invertible.copy [MulOneClass \u03b1] {r : \u03b1} (hr : Invertible r) (s : \u03b1) (hs : s = r) :\n    Invertible s where\n  invOf := \u215f r\n  invOf_mul_self := by rw [hs, invOf_mul_self]\n  mul_invOf_self := by rw [hs, mul_invOf_self]\n#align invertible.copy Invertible.copy\n\n/-- If `a` is invertible and `a = b`, then `\u215fa = \u215fb`. -/\n@[congr]\ntheorem Invertible.congr [Ring \u03b1] (a b : \u03b1) [Invertible a] [Invertible b] (h : a = b) :\n  \u215fa = \u215fb := by subst h; congr; apply Subsingleton.allEq\n\n/-- An `invertible` element is a unit. -/\n@[simps]\ndef unitOfInvertible [Monoid \u03b1] (a : \u03b1) [Invertible a] :\n    \u03b1\u02e3 where\n  val := a\n  inv := \u215f a\n  val_inv := by simp\n  inv_val := by simp\n#align unit_of_invertible unitOfInvertible\n\ntheorem isUnit_of_invertible [Monoid \u03b1] (a : \u03b1) [Invertible a] : IsUnit a :=\n  \u27e8unitOfInvertible a, rfl\u27e9\n#align is_unit_of_invertible isUnit_of_invertible\n\n/-- Units are invertible in their associated monoid. -/\ndef Units.invertible [Monoid \u03b1] (u : \u03b1\u02e3) :\n    Invertible (u : \u03b1) where\n  invOf := \u2191u\u207b\u00b9\n  invOf_mul_self := u.inv_mul\n  mul_invOf_self := u.mul_inv\n#align units.invertible Units.invertible\n\n@[simp]\ntheorem invOf_units [Monoid \u03b1] (u : \u03b1\u02e3) [Invertible (u : \u03b1)] : \u215f (u : \u03b1) = \u2191u\u207b\u00b9 :=\n  invOf_eq_right_inv u.mul_inv\n#align inv_of_units invOf_units\n\ntheorem IsUnit.nonempty_invertible [Monoid \u03b1] {a : \u03b1} (h : IsUnit a) : Nonempty (Invertible a) :=\n  let \u27e8x, hx\u27e9 := h\n  \u27e8x.invertible.copy _ hx.symm\u27e9\n#align is_unit.nonempty_invertible IsUnit.nonempty_invertible\n\n/-- Convert `IsUnit` to `Invertible` using `Classical.choice`.\n\nPrefer `casesI h.nonempty_invertible` over `letI := h.invertible` if you want to avoid choice. -/\nnoncomputable def IsUnit.invertible [Monoid \u03b1] {a : \u03b1} (h : IsUnit a) : Invertible a :=\n  Classical.choice h.nonempty_invertible\n#align is_unit.invertible IsUnit.invertible\n\n@[simp]\ntheorem nonempty_invertible_iff_isUnit [Monoid \u03b1] (a : \u03b1) : Nonempty (Invertible a) \u2194 IsUnit a :=\n  \u27e8Nonempty.rec <| @isUnit_of_invertible _ _ _, IsUnit.nonempty_invertible\u27e9\n#align nonempty_invertible_iff_is_unit nonempty_invertible_iff_isUnit\n\n/-- Each element of a group is invertible. -/\ndef invertibleOfGroup [Group \u03b1] (a : \u03b1) : Invertible a :=\n  \u27e8a\u207b\u00b9, inv_mul_self a, mul_inv_self a\u27e9\n#align invertible_of_group invertibleOfGroup\n\n@[simp]\ntheorem invOf_eq_group_inv [Group \u03b1] (a : \u03b1) [Invertible a] : \u215f a = a\u207b\u00b9 :=\n  invOf_eq_right_inv (mul_inv_self a)\n#align inv_of_eq_group_inv invOf_eq_group_inv\n\n/-- `1` is the inverse of itself -/\ndef invertibleOne [Monoid \u03b1] : Invertible (1 : \u03b1) :=\n  \u27e81, mul_one _, one_mul _\u27e9\n#align invertible_one invertibleOne\n\n@[simp]\ntheorem invOf_one' [Monoid \u03b1] {_ : Invertible (1 : \u03b1)} : \u215f (1 : \u03b1) = 1 :=\n  invOf_eq_right_inv (mul_one _)\n\ntheorem invOf_one [Monoid \u03b1] [Invertible (1 : \u03b1)] : \u215f (1 : \u03b1) = 1 :=\n  invOf_eq_right_inv (mul_one _)\n#align inv_of_one invOf_one\n\n/-- `-\u215fa` is the inverse of `-a` -/\ndef invertibleNeg [Mul \u03b1] [One \u03b1] [HasDistribNeg \u03b1] (a : \u03b1) [Invertible a] : Invertible (-a) :=\n  \u27e8-\u215f a, by simp, by simp\u27e9\n#align invertible_neg invertibleNeg\n\n@[simp]\ntheorem invOf_neg [Monoid \u03b1] [HasDistribNeg \u03b1] (a : \u03b1) [Invertible a] [Invertible (-a)] :\n    \u215f (-a) = -\u215f a :=\n  invOf_eq_right_inv (by simp)\n#align inv_of_neg invOf_neg\n\n@[simp]\ntheorem one_sub_invOf_two [Ring \u03b1] [Invertible (2 : \u03b1)] : 1 - (\u215f 2 : \u03b1) = \u215f 2 :=\n  (isUnit_of_invertible (2 : \u03b1)).mul_right_inj.1 <| by\n    rw [mul_sub, mul_invOf_self, mul_one, \u2190 one_add_one_eq_two, add_sub_cancel]\n#align one_sub_inv_of_two one_sub_invOf_two\n\n@[simp]\ntheorem invOf_two_add_invOf_two [NonAssocSemiring \u03b1] [Invertible (2 : \u03b1)] :\n    (\u215f 2 : \u03b1) + (\u215f 2 : \u03b1) = 1 := by rw [\u2190 two_mul, mul_invOf_self]\n#align inv_of_two_add_inv_of_two invOf_two_add_invOf_two\n\n/-- `a` is the inverse of `\u215fa`. -/\ninstance invertibleInvOf [One \u03b1] [Mul \u03b1] {a : \u03b1} [Invertible a] : Invertible (\u215f a) :=\n  \u27e8a, mul_invOf_self a, invOf_mul_self a\u27e9\n#align invertible_inv_of invertibleInvOf\n\n@[simp]\ntheorem invOf_invOf [Monoid \u03b1] (a : \u03b1) [Invertible a] [Invertible (\u215f a)] : \u215f (\u215f a) = a :=\n  invOf_eq_right_inv (invOf_mul_self _)\n#align inv_of_inv_of invOf_invOf\n\n@[simp]\ntheorem invOf_inj [Monoid \u03b1] {a b : \u03b1} [Invertible a] [Invertible b] : \u215f a = \u215f b \u2194 a = b :=\n  \u27e8invertible_unique _ _, invertible_unique _ _\u27e9\n#align inv_of_inj invOf_inj\n\n/-- `\u215fb * \u215fa` is the inverse of `a * b` -/\ndef invertibleMul [Monoid \u03b1] (a b : \u03b1) [Invertible a] [Invertible b] : Invertible (a * b) :=\n  \u27e8\u215f b * \u215f a, by simp [\u2190 mul_assoc], by simp [\u2190 mul_assoc]\u27e9\n#align invertible_mul invertibleMul\n\n@[simp]\ntheorem invOf_mul [Monoid \u03b1] (a b : \u03b1) [Invertible a] [Invertible b] [Invertible (a * b)] :\n    \u215f (a * b) = \u215f b * \u215f a :=\n  invOf_eq_right_inv (by simp [\u2190 mul_assoc])\n#align inv_of_mul invOf_mul\n\ntheorem mul_right_inj_of_invertible [Monoid \u03b1] (c : \u03b1) [Invertible c] :\n    a * c = b * c \u2194 a = b :=\n  \u27e8fun h => by simpa using congr_arg (\u00b7 * \u215fc) h, congr_arg (\u00b7 * _)\u27e9\n\ntheorem mul_left_inj_of_invertible [Monoid \u03b1] (c : \u03b1) [Invertible c] :\n    c * a = c * b \u2194 a = b :=\n  \u27e8fun h => by simpa using congr_arg (\u215fc * \u00b7) h, congr_arg (_ * \u00b7)\u27e9\n\ntheorem invOf_mul_eq_iff_eq_mul_left [Monoid \u03b1] [Invertible (c : \u03b1)] :\n    \u215fc * a = b \u2194 a = c * b := by\n  rw [\u2190 mul_left_inj_of_invertible (c := c), mul_invOf_self_assoc]\n\ntheorem mul_left_eq_iff_eq_invOf_mul [Monoid \u03b1] [Invertible (c : \u03b1)] :\n    c * a = b \u2194 a = \u215fc * b := by\n  rw [\u2190 mul_left_inj_of_invertible (c := \u215fc), invOf_mul_self_assoc]\n\ntheorem mul_invOf_eq_iff_eq_mul_right [Monoid \u03b1] [Invertible (c : \u03b1)] :\n    a * \u215fc = b \u2194 a = b * c := by\n  rw [\u2190 mul_right_inj_of_invertible (c := c), mul_invOf_mul_self_cancel]\n\ntheorem mul_right_eq_iff_eq_mul_invOf [Monoid \u03b1] [Invertible (c : \u03b1)] :\n    a * c = b \u2194 a = b * \u215fc := by\n  rw [\u2190 mul_right_inj_of_invertible (c := \u215fc), mul_mul_invOf_self_cancel]\n\ntheorem Commute.invOf_right [Monoid \u03b1] {a b : \u03b1} [Invertible b] (h : Commute a b) :\n    Commute a (\u215f b) :=\n  calc\n    a * \u215f b = \u215f b * (b * a * \u215f b) := by simp [mul_assoc]\n    _ = \u215f b * (a * b * \u215f b) := by rw [h.eq]\n    _ = \u215f b * a := by simp [mul_assoc]\n\n#align commute.inv_of_right Commute.invOf_right\n\ntheorem Commute.invOf_left [Monoid \u03b1] {a b : \u03b1} [Invertible b] (h : Commute b a) :\n    Commute (\u215f b) a :=\n  calc\n    \u215f b * a = \u215f b * (a * b * \u215f b) := by simp [mul_assoc]\n    _ = \u215f b * (b * a * \u215f b) := by rw [h.eq]\n    _ = a * \u215f b := by simp [mul_assoc]\n\n#align commute.inv_of_left Commute.invOf_left\n\ntheorem commute_invOf {M : Type _} [One M] [Mul M] (m : M) [Invertible m] : Commute m (\u215f m) :=\n  calc\n    m * \u215f m = 1 := mul_invOf_self m\n    _ = \u215f m * m := (invOf_mul_self m).symm\n\n#align commute_inv_of commute_invOf\n\ntheorem nonzero_of_invertible [MulZeroOneClass \u03b1] (a : \u03b1) [Nontrivial \u03b1] [Invertible a] : a \u2260 0 :=\n  fun ha =>\n  zero_ne_one <|\n    calc\n      0 = \u215f a * a := by simp [ha]\n      _ = 1 := invOf_mul_self a\n\n#align nonzero_of_invertible nonzero_of_invertible\n\ntheorem pos_of_invertible_cast [Semiring \u03b1] [Nontrivial \u03b1] (n : \u2115) [Invertible (n : \u03b1)] : 0 < n :=\n  Nat.zero_lt_of_ne_zero fun h => nonzero_of_invertible (n : \u03b1) (h \u25b8 Nat.cast_zero)\n\ninstance (priority := 100) Invertible.ne_zero [MulZeroOneClass \u03b1] [Nontrivial \u03b1] (a : \u03b1)\n    [Invertible a] : NeZero a :=\n  \u27e8nonzero_of_invertible a\u27e9\n#align invertible.ne_zero Invertible.ne_zero\n\nsection MonoidWithZero\n\nvariable [MonoidWithZero \u03b1]\n\n/-- A variant of `Ring.inverse_unit`. -/\n@[simp]\ntheorem Ring.inverse_invertible (x : \u03b1) [Invertible x] : Ring.inverse x = \u215f x :=\n  Ring.inverse_unit (unitOfInvertible _)\n#align ring.inverse_invertible Ring.inverse_invertible\n\nend MonoidWithZero\n\nsection GroupWithZero\n\nvariable [GroupWithZero \u03b1]\n\n/-- `a\u207b\u00b9` is an inverse of `a` if `a \u2260 0` -/\ndef invertibleOfNonzero {a : \u03b1} (h : a \u2260 0) : Invertible a :=\n  \u27e8a\u207b\u00b9, inv_mul_cancel h, mul_inv_cancel h\u27e9\n#align invertible_of_nonzero invertibleOfNonzero\n\n@[simp]\ntheorem invOf_eq_inv (a : \u03b1) [Invertible a] : \u215f a = a\u207b\u00b9 :=\n  invOf_eq_right_inv (mul_inv_cancel (nonzero_of_invertible a))\n#align inv_of_eq_inv invOf_eq_inv\n\n@[simp]\ntheorem inv_mul_cancel_of_invertible (a : \u03b1) [Invertible a] : a\u207b\u00b9 * a = 1 :=\n  inv_mul_cancel (nonzero_of_invertible a)\n#align inv_mul_cancel_of_invertible inv_mul_cancel_of_invertible\n\n@[simp]\ntheorem mul_inv_cancel_of_invertible (a : \u03b1) [Invertible a] : a * a\u207b\u00b9 = 1 :=\n  mul_inv_cancel (nonzero_of_invertible a)\n#align mul_inv_cancel_of_invertible mul_inv_cancel_of_invertible\n\n@[simp]\ntheorem div_mul_cancel_of_invertible (a b : \u03b1) [Invertible b] : a / b * b = a :=\n  div_mul_cancel a (nonzero_of_invertible b)\n#align div_mul_cancel_of_invertible div_mul_cancel_of_invertible\n\n@[simp]\ntheorem mul_div_cancel_of_invertible (a b : \u03b1) [Invertible b] : a * b / b = a :=\n  mul_div_cancel a (nonzero_of_invertible b)\n#align mul_div_cancel_of_invertible mul_div_cancel_of_invertible\n\n@[simp]\ntheorem div_self_of_invertible (a : \u03b1) [Invertible a] : a / a = 1 :=\n  div_self (nonzero_of_invertible a)\n#align div_self_of_invertible div_self_of_invertible\n\n/-- `b / a` is the inverse of `a / b` -/\ndef invertibleDiv (a b : \u03b1) [Invertible a] [Invertible b] : Invertible (a / b) :=\n  \u27e8b / a, by simp [\u2190 mul_div_assoc], by simp [\u2190 mul_div_assoc]\u27e9\n#align invertible_div invertibleDiv\n\n-- Porting note: removed `simp` attibute as `simp` can prove it\ntheorem invOf_div (a b : \u03b1) [Invertible a] [Invertible b] [Invertible (a / b)] :\n    \u215f (a / b) = b / a :=\n  invOf_eq_right_inv (by simp [\u2190 mul_div_assoc])\n#align inv_of_div invOf_div\n\n/-- `a` is the inverse of `a\u207b\u00b9` -/\ndef invertibleInv {a : \u03b1} [Invertible a] : Invertible a\u207b\u00b9 :=\n  \u27e8a, by simp, by simp\u27e9\n#align invertible_inv invertibleInv\n\nend GroupWithZero\n\n/-- Monoid homs preserve invertibility. -/\ndef Invertible.map {R : Type _} {S : Type _} {F : Type _} [MulOneClass R] [MulOneClass S]\n    [MonoidHomClass F R S] (f : F) (r : R) [Invertible r] :\n    Invertible (f r) where\n  invOf := f (\u215f r)\n  invOf_mul_self := by rw [\u2190 map_mul, invOf_mul_self, map_one]\n  mul_invOf_self := by rw [\u2190 map_mul, mul_invOf_self, map_one]\n#align invertible.map Invertible.map\n\n/-- Note that the `invertible (f r)` argument can be satisfied by using `letI := invertible.map f r`\nbefore applying this lemma. -/\ntheorem map_invOf {R : Type _} {S : Type _} {F : Type _} [MulOneClass R] [Monoid S]\n    [MonoidHomClass F R S] (f : F) (r : R) [Invertible r] [ifr : Invertible (f r)] :\n    f (\u215f r) = \u215f (f r) :=\n  have h : ifr = Invertible.map f r := Subsingleton.elim _ _\n  by subst h ; rfl\n\n#align map_inv_of map_invOf\n\n/-- If a function `f : R \u2192 S` has a left-inverse that is a monoid hom,\n  then `r : R` is invertible if `f r` is.\n\nThe inverse is computed as `g (\u215f(f r))` -/\n@[simps! (config := .lemmasOnly)]\ndef Invertible.ofLeftInverse {R : Type _} {S : Type _} {G : Type _} [MulOneClass R] [MulOneClass S]\n    [MonoidHomClass G S R] (f : R \u2192 S) (g : G) (r : R) (h : Function.LeftInverse g f)\n    [Invertible (f r)] : Invertible r :=\n  (Invertible.map g (f r)).copy _ (h r).symm\n#align invertible.of_left_inverse Invertible.ofLeftInverse\n#align invertible.of_left_inverse_inv_of Invertible.ofLeftInverse_invOf\n\n/-- Invertibility on either side of a monoid hom with a left-inverse is equivalent. -/\n@[simps]\ndef invertibleEquivOfLeftInverse {R : Type _} {S : Type _} {F G : Type _} [Monoid R] [Monoid S]\n    [MonoidHomClass F R S] [MonoidHomClass G S R] (f : F) (g : G) (r : R)\n    (h : Function.LeftInverse g f) :\n    Invertible (f r) \u2243\n      Invertible r where\n  toFun _ := Invertible.ofLeftInverse f _ _ h\n  invFun _ := Invertible.map f _\n  left_inv _ := Subsingleton.elim _ _\n  right_inv _ := Subsingleton.elim _ _\n#align invertible_equiv_of_left_inverse invertibleEquivOfLeftInverse\n#align invertible_equiv_of_left_inverse_symm_apply invertibleEquivOfLeftInverse_symm_apply\n#align invertible_equiv_of_left_inverse_apply invertibleEquivOfLeftInverse_apply\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8418256393148981, "lm_q1q2_score": 0.7298929299120355}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.complex\nimport analysis.special_functions.trigonometric.deriv\n\n/-!\n# Complex trigonometric functions\n\nBasic facts and derivatives for the complex trigonometric functions.\n-/\n\nnoncomputable theory\n\nnamespace complex\n\nopen set filter\nopen_locale real\n\nlemma has_strict_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_strict_deriv_at tan (1 / (cos x)^2) x :=\nbegin\n  convert (has_strict_deriv_at_sin x).div (has_strict_deriv_at_cos x) h,\n  rw \u2190 sin_sq_add_cos_sq x,\n  ring,\nend\n\nlemma has_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_deriv_at tan (1 / (cos x)^2) x :=\n(has_strict_deriv_at_tan h).has_deriv_at\n\nopen_locale topology\n\nlemma tendsto_abs_tan_of_cos_eq_zero {x : \u2102} (hx : cos x = 0) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[\u2260] x) at_top :=\nbegin\n  simp only [tan_eq_sin_div_cos, \u2190 norm_eq_abs, norm_div],\n  have A : sin x \u2260 0 := \u03bb h, by simpa [*, sq] using sin_sq_add_cos_sq x,\n  have B : tendsto cos (\ud835\udcdd[\u2260] (x)) (\ud835\udcdd[\u2260] 0),\n    from hx \u25b8 (has_deriv_at_cos x).tendsto_punctured_nhds (neg_ne_zero.2 A),\n  exact continuous_sin.continuous_within_at.norm.mul_at_top (norm_pos_iff.2 A)\n    (tendsto_norm_nhds_within_zero.comp B).inv_tendsto_zero,\nend\n\nlemma tendsto_abs_tan_at_top (k : \u2124) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[\u2260] ((2 * k + 1) * \u03c0 / 2)) at_top :=\ntendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 \u27e8k, rfl\u27e9\n\n@[simp] lemma continuous_at_tan {x : \u2102} : continuous_at tan x \u2194 cos x \u2260 0 :=\nbegin\n  refine \u27e8\u03bb hc h\u2080, _, \u03bb h, (has_deriv_at_tan h).continuous_at\u27e9,\n  exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h\u2080) _\n    (hc.norm.tendsto.mono_left inf_le_left)\nend\n\n@[simp] lemma differentiable_at_tan {x : \u2102} : differentiable_at \u2102 tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at, \u03bb h, (has_deriv_at_tan h).differentiable_at\u27e9\n\n@[simp] lemma deriv_tan (x : \u2102) : deriv tan x = 1 / (cos x)^2 :=\nif h : cos x = 0 then\n  have \u00acdifferentiable_at \u2102 tan x := mt differentiable_at_tan.1 (not_not.2 h),\n  by simp [deriv_zero_of_not_differentiable_at this, h, sq]\nelse (has_deriv_at_tan h).deriv\n\n@[simp] lemma cont_diff_at_tan {x : \u2102} {n : \u2115\u221e} :\n  cont_diff_at \u2102 n tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at,\n  cont_diff_sin.cont_diff_at.div cont_diff_cos.cont_diff_at\u27e9\n\nend complex\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/trigonometric/complex_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7298604131160296}}
{"text": "import algebra.order.positive.field number_theory.padics.padic_val data.nat.factorization.basic\n\n/-!\n# Correspondence between `\u211a+` and `nat.primes \u2192 \u2124`\n\nWe construct an explicit homomorphism `(additive) \u211a+ \u2192+ nat.primes \u2192 \u2124` and prove injectivity.\n\nTODO:\n1. Construct a `finsupp` version and prove bijectivity.\n2. See if we can add MUCH more results!\nNo priority on either as of writing.\n-/\n\nnamespace IMOSL\nnamespace extra\n\ndef pos_rat_factor_hom : additive {x : \u211a // 0 < x} \u2192+ nat.primes \u2192 \u2124 :=\n{ to_fun := \u03bb q, (\u03bb p, padic_val_rat p q.1),\n  map_zero' := funext (\u03bb p, padic_val_rat.one),\n  map_add' := \u03bb q r, funext (\u03bb p, by haveI : fact (p : \u2115).prime := \u27e8p.2\u27e9;\n    exact padic_val_rat.mul (ne_of_gt q.2) (ne_of_gt r.2)) }\n\nnamespace pos_rat_factor_hom\n\nlemma apply (q : {x : \u211a // 0 < x}) (p : nat.primes) :\n  pos_rat_factor_hom q p = padic_val_rat p q.1 := rfl\n\nlemma apply' {q : \u211a} (h : 0 < q) (p : nat.primes) :\n  pos_rat_factor_hom \u27e8q, h\u27e9 p = padic_val_rat p q := rfl\n\ntheorem inj : function.injective pos_rat_factor_hom :=\nbegin\n  ---- Setup\n  rw injective_iff_map_eq_zero,\n  rintros \u27e8q, h\u27e9 h0,\n  suffices : q = 1,\n    simp_rw this; refl,\n  simp_rw [function.funext_iff, pi.zero_apply, apply] at h0,\n  replace h0 : \u2200 p : \u2115, p.prime \u2192 padic_val_rat p q = 0 := \u03bb p hp, h0 \u27e8p, hp\u27e9,\n  \n  ---- Now prove that `\u03bd_p(q) = 0` for all `p` prime iff `q = 1`, assuming `q > 0`\n  rcases q with \u27e8n, d, h1, h2\u27e9,\n  rw \u2190 rat.num_pos_iff_pos at h,\n  lift n to \u2115 using le_of_lt h; rw nat.cast_pos at h,\n  simp_rw [padic_val_rat, sub_eq_zero, nat.cast_inj, padic_val_int.of_nat,\n    \u2190 nat.eq_iff_prime_padic_val_nat_eq n d (ne_of_gt h) (ne_of_gt h1)] at h0,\n  simp_rw [rat.eq_iff_mul_eq_mul, h0, rat.num_one, rat.denom_one, nat.cast_one],\n  exact mul_comm _ 1\nend\n\nend pos_rat_factor_hom\n\nend extra\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/extra/number_theory/pos_rat_primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529791457032, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7298604087887702}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport data.polynomial.erase_lead\nimport data.polynomial.eval\n\n/-!\n# Denominators of evaluation of polynomials at ratios\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nLet `i : R \u2192 K` be a homomorphism of semirings.  Assume that `K` is commutative.  If `a` and\n`b` are elements of `R` such that `i b \u2208 K` is invertible, then for any polynomial\n`f \u2208 R[X]` the \"mathematical\" expression `b ^ f.nat_degree * f (a / b) \u2208 K` is in\nthe image of the homomorphism `i`.\n-/\n\nopen polynomial finset\nopen_locale polynomial\n\nsection denoms_clearable\n\nvariables {R K : Type*} [semiring R] [comm_semiring K] {i : R \u2192+* K}\nvariables {a b : R} {bi : K}\n-- TODO: use hypothesis (ub : is_unit (i b)) to work with localizations.\n\n/-- `denoms_clearable` formalizes the property that `b ^ N * f (a / b)`\ndoes not have denominators, if the inequality `f.nat_degree \u2264 N` holds.\n\nThe definition asserts the existence of an element `D` of `R` and an\nelement `bi = 1 / i b` of `K` such that clearing the denominators of\nthe fraction equals `i D`.\n-/\ndef denoms_clearable (a b : R) (N : \u2115) (f : R[X]) (i : R \u2192+* K) : Prop :=\n  \u2203 (D : R) (bi : K), bi * i b = 1 \u2227 i D = i b ^ N * eval (i a * bi) (f.map i)\n\nlemma denoms_clearable_zero (N : \u2115) (a : R) (bu : bi * i b = 1) :\n  denoms_clearable a b N 0 i :=\n\u27e80, bi, bu, by simp only [eval_zero, ring_hom.map_zero, mul_zero, polynomial.map_zero]\u27e9\n\nlemma denoms_clearable_C_mul_X_pow {N : \u2115} (a : R) (bu : bi * i b = 1) {n : \u2115} (r : R)\n  (nN : n \u2264 N) : denoms_clearable a b N (C r * X ^ n) i :=\nbegin\n  refine \u27e8r * a ^ n * b ^ (N - n), bi, bu, _\u27e9,\n  rw [C_mul_X_pow_eq_monomial, map_monomial, \u2190 C_mul_X_pow_eq_monomial, eval_mul, eval_pow, eval_C],\n  rw [ring_hom.map_mul, ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_pow, eval_X, mul_comm],\n  rw [\u2190 tsub_add_cancel_of_le nN] {occs := occurrences.pos [2]},\n  rw [pow_add, mul_assoc, mul_comm (i b ^ n), mul_pow, mul_assoc, mul_assoc (i a ^ n), \u2190 mul_pow],\n  rw [bu, one_pow, mul_one],\nend\n\nlemma denoms_clearable.add {N : \u2115} {f g : R[X]} :\n  denoms_clearable a b N f i \u2192 denoms_clearable a b N g i \u2192 denoms_clearable a b N (f + g) i :=\n\u03bb \u27e8Df, bf, bfu, Hf\u27e9 \u27e8Dg, bg, bgu, Hg\u27e9, \u27e8Df + Dg, bf, bfu,\n  begin\n    rw [ring_hom.map_add, polynomial.map_add, eval_add, mul_add, Hf, Hg],\n    congr,\n    refine @inv_unique K _ (i b) bg bf _ _;\n    rwa mul_comm,\n  end \u27e9\n\nlemma denoms_clearable_of_nat_degree_le (N : \u2115) (a : R) (bu : bi * i b = 1) :\n  \u2200 (f : R[X]), f.nat_degree \u2264 N \u2192 denoms_clearable a b N f i :=\ninduction_with_nat_degree_le _ N\n  (denoms_clearable_zero N a bu)\n  (\u03bb N_1 r r0, denoms_clearable_C_mul_X_pow a bu r)\n  (\u03bb f g fg gN df dg, df.add dg)\n\n/-- If `i : R \u2192 K` is a ring homomorphism, `f` is a polynomial with coefficients in `R`,\n`a, b` are elements of `R`, with `i b` invertible, then there is a `D \u2208 R` such that\n`b ^ f.nat_degree * f (a / b)` equals `i D`. -/\ntheorem denoms_clearable_nat_degree\n  (i : R \u2192+* K) (f : R[X]) (a : R) (bu : bi * i b = 1) :\n  denoms_clearable a b f.nat_degree f i :=\ndenoms_clearable_of_nat_degree_le f.nat_degree a bu f le_rfl\n\nend denoms_clearable\n\nopen ring_hom\n\n/--  Evaluating a polynomial with integer coefficients at a rational number and clearing\ndenominators, yields a number greater than or equal to one.  The target can be any\n`linear_ordered_field K`.\nThe assumption on `K` could be weakened to `linear_ordered_comm_ring` assuming that the\nimage of the denominator is invertible in `K`. -/\nlemma one_le_pow_mul_abs_eval_div {K : Type*} [linear_ordered_field K] {f : \u2124[X]}\n  {a b : \u2124} (b0 : 0 < b) (fab : eval ((a : K) / b) (f.map (algebra_map \u2124 K)) \u2260 0) :\n  (1 : K) \u2264 b ^ f.nat_degree * |eval ((a : K) / b) (f.map (algebra_map \u2124 K))| :=\nbegin\n  obtain \u27e8ev, bi, bu, hF\u27e9 := @denoms_clearable_nat_degree _ _ _ _ b _ (algebra_map \u2124 K)\n    f a (by { rw [eq_int_cast, one_div_mul_cancel], rw [int.cast_ne_zero], exact (b0.ne.symm) }),\n  obtain Fa := congr_arg abs hF,\n  rw [eq_one_div_of_mul_eq_one_left bu, eq_int_cast, eq_int_cast, abs_mul] at Fa,\n  rw [abs_of_pos (pow_pos (int.cast_pos.mpr b0) _ : 0 < (b : K) ^ _), one_div, eq_int_cast] at Fa,\n  rw [div_eq_mul_inv, \u2190 Fa, \u2190 int.cast_abs, \u2190 int.cast_one, int.cast_le],\n  refine int.le_of_lt_add_one ((lt_add_iff_pos_left 1).mpr (abs_pos.mpr (\u03bb F0, fab _))),\n  rw [eq_one_div_of_mul_eq_one_left bu, F0, one_div, eq_int_cast, int.cast_zero, zero_eq_mul] at hF,\n  cases hF with hF hF,\n  { exact (not_le.mpr b0 (le_of_eq (int.cast_eq_zero.mp (pow_eq_zero hF)))).elim },\n  { rwa div_eq_mul_inv }\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/denoms_clearable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7298603917870591}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n-/\n\nimport algebra.associated\nimport algebra.parity\nimport data.int.dvd.basic\nimport data.int.units\nimport data.nat.factorial.basic\nimport data.nat.gcd.basic\nimport data.nat.sqrt\nimport order.bounds.basic\nimport tactic.by_contra\n\n/-!\n# Prime numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\n- `nat.prime`: the predicate that expresses that a natural number `p` is prime\n- `nat.primes`: the subtype of natural numbers that are prime\n- `nat.min_fac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers.\n  This also appears as `nat.not_bdd_above_set_of_prime` and `nat.infinite_set_of_prime` (the latter\n  in `data.nat.prime_fin`).\n- `nat.prime_iff`: `nat.prime` coincides with the general definition of `prime`\n- `nat.irreducible_iff_prime`: a non-unit natural number is only divisible by `1` iff it is prime\n\n-/\n\nopen bool subtype\nopen_locale nat\n\nnamespace nat\n\n/-- `nat.prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\n@[pp_nodot]\ndef prime (p : \u2115) := _root_.irreducible p\n\ntheorem _root_.irreducible_iff_nat_prime (a : \u2115) : irreducible a \u2194 nat.prime a := iff.rfl\n\ntheorem not_prime_zero : \u00ac prime 0\n| h := h.ne_zero rfl\n\ntheorem not_prime_one : \u00ac prime 1\n| h := h.ne_one rfl\n\ntheorem prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 := irreducible.ne_zero h\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : 0 < p := nat.pos_of_ne_zero pp.ne_zero\n\ntheorem prime.two_le : \u2200 {p : \u2115}, prime p \u2192 2 \u2264 p\n| 0 h := (not_prime_zero h).elim\n| 1 h := (not_prime_one h).elim\n| (n+2) _ := le_add_self\n\ntheorem prime.one_lt {p : \u2115} : prime p \u2192 1 < p := prime.two_le\n\ninstance prime.one_lt' (p : \u2115) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := \u27e8hp.1.one_lt\u27e9\n\nlemma prime.ne_one {p : \u2115} (hp : p.prime) : p \u2260 1 :=\nhp.one_lt.ne'\n\nlemma prime.eq_one_or_self_of_dvd {p : \u2115} (pp : p.prime) (m : \u2115) (hm : m \u2223 p) : m = 1 \u2228 m = p :=\nbegin\n  obtain \u27e8n, hn\u27e9 := hm,\n  have := pp.is_unit_or_is_unit hn,\n  rw [nat.is_unit_iff, nat.is_unit_iff] at this,\n  apply or.imp_right _ this,\n  rintro rfl,\n  rw [hn, mul_one]\nend\n\ntheorem prime_def_lt'' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m \u2223 p, m = 1 \u2228 m = p :=\nbegin\n  refine \u27e8\u03bb h, \u27e8h.two_le, h.eq_one_or_self_of_dvd\u27e9, \u03bb h, _\u27e9,\n  have h1 := one_lt_two.trans_le h.1,\n  refine \u27e8mt nat.is_unit_iff.mp h1.ne', \u03bb a b hab, _\u27e9,\n  simp only [nat.is_unit_iff],\n  apply or.imp_right _ (h.2 a _),\n  { rintro rfl,\n    rw [\u2190 mul_right_inj' (pos_of_gt h1).ne', \u2190hab, mul_one] },\n  { rw hab,\n    exact dvd_mul_right _ _ }\nend\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\nprime_def_lt''.trans $\nand_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h l d, (h d).resolve_right (ne_of_lt l),\n \u03bb h d, (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left (\u03bb l, h l d)\u27e9\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00ac m \u2223 p :=\nprime_def_lt.trans $ and_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h m2 l d, not_lt_of_ge m2 ((h l d).symm \u25b8 dec_trivial),\n\u03bb h l d, begin\n  rcases m with _|_|m,\n  { rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },\n  { refl },\n  { exact (h dec_trivial l).elim d }\nend\u27e9\n\ntheorem prime_def_le_sqrt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227\n  \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac m \u2223 p :=\nprime_def_lt'.trans $ and_congr_right $ \u03bb p2,\n\u27e8\u03bb a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,\n \u03bb a, have \u2200 {m k}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k, from\n  \u03bb m k mk m1 e, a m m1\n    (le_sqrt.2 (e.symm \u25b8 nat.mul_le_mul_left m mk)) \u27e8k, e\u27e9,\n  \u03bb m m2 l \u27e8k, e\u27e9, begin\n    cases (le_total m k) with mk km,\n    { exact this mk m2 e },\n    { rw [mul_comm] at e,\n      refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,\n      rwa [one_mul, \u2190 e] }\n  end\u27e9\n\ntheorem prime_of_coprime (n : \u2115) (h1 : 1 < n) (h : \u2200 m < n, m \u2260 0 \u2192 n.coprime m) : prime n :=\nbegin\n  refine prime_def_lt.mpr \u27e8h1, \u03bb m mlt mdvd, _\u27e9,\n  have hm : m \u2260 0,\n  { rintro rfl,\n    rw zero_dvd_iff at mdvd,\n    exact mlt.ne' mdvd },\n  exact (h m mlt hm).symm.eq_one_of_dvd mdvd,\nend\n\nsection\n\n/--\n  This instance is slower than the instance `decidable_prime` defined below,\n  but has the advantage that it works in the kernel for small values.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\nlocal attribute [instance]\ndef decidable_prime_1 (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_lt'\n\ntheorem prime_two : prime 2 := dec_trivial\ntheorem prime_three : prime 3 := dec_trivial\n\nlemma prime.five_le_of_ne_two_of_ne_three {p : \u2115} (hp : p.prime) (h_two : p \u2260 2) (h_three : p \u2260 3) :\n  5 \u2264 p :=\nbegin\n  by_contra' h,\n  revert h_two h_three hp,\n  dec_trivial!\nend\n\nend\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : 0 < pred p :=\nlt_pred_iff.2 pp.one_lt\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : succ (pred p) = p :=\nsucc_pred_eq_of_pos pp.pos\n\ntheorem dvd_prime {p m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n\u27e8\u03bb d, pp.eq_one_or_self_of_dvd m d, \u03bb h, h.elim (\u03bb e, e.symm \u25b8 one_dvd _) (\u03bb e, e.symm \u25b8 dvd_rfl)\u27e9\n\ntheorem dvd_prime_two_le {p m : \u2115} (pp : prime p) (H : 2 \u2264 m) : m \u2223 p \u2194 m = p :=\n(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H\n\ntheorem prime_dvd_prime_iff_eq {p q : \u2115} (pp : p.prime) (qp : q.prime) : p \u2223 q \u2194 p = q :=\ndvd_prime_two_le qp (prime.two_le pp)\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00ac p \u2223 1 :=\npp.not_dvd_one\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00ac prime (a * b) :=\n\u03bb h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $\nby simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)\n\nlemma not_prime_mul' {a b n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) : \u00ac prime n :=\nby { rw \u2190 h, exact not_prime_mul h\u2081 h\u2082 }\n\nlemma prime_mul_iff {a b : \u2115} :\n  nat.prime (a * b) \u2194 (a.prime \u2227 b = 1) \u2228 (b.prime \u2227 a = 1) :=\nby simp only [iff_self, irreducible_mul_iff, \u2190irreducible_iff_nat_prime, nat.is_unit_iff]\n\nlemma prime.dvd_iff_eq {p a : \u2115} (hp : p.prime) (a1 : a \u2260 1) : a \u2223 p \u2194 p = a :=\nbegin\n  refine \u27e8_, by { rintro rfl, refl }\u27e9,\n  -- rintro \u27e8j, rfl\u27e9 does not work, due to `nat.prime` depending on the class `irreducible`\n  rintro \u27e8j, hj\u27e9,\n  rw hj at hp \u22a2,\n  rcases prime_mul_iff.mp hp with \u27e8h, rfl\u27e9 | \u27e8h, rfl\u27e9,\n  { exact mul_one _ },\n  { exact (a1 rfl).elim }\nend\n\nsection min_fac\n\nlemma min_fac_lemma (n k : \u2115) (h : \u00ac n < k * k) :\n  sqrt n - k < sqrt n + 2 - k :=\n(tsub_lt_tsub_iff_right $ le_sqrt.2 $ le_of_not_gt h).2 $\nnat.lt_add_of_pos_right dec_trivial\n\n/-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.\n  Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.\n  If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/\ndef min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115\n| k :=\n  if h : n < k * k then n else\n  if k \u2223 n then k else\n  have _, from min_fac_lemma n k h,\n  min_fac_aux (k + 2)\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n/-- Returns the smallest prime factor of `n \u2260 1`. -/\ndef min_fac : \u2115 \u2192 \u2115\n| 0 := 2\n| 1 := 1\n| (n+2) := if 2 \u2223 n then 2 else min_fac_aux (n + 2) 3\n\n@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl\n@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\ntheorem min_fac_eq : \u2200 n, min_fac n = if 2 \u2223 n then 2 else min_fac_aux n 3\n| 0     := by simp\n| 1     := by simp [show 2\u22601, from dec_trivial]; rw min_fac_aux; refl\n| (n+2) :=\n  have 2 \u2223 n + 2 \u2194 2 \u2223 n, from\n    (nat.dvd_add_iff_left (by refl)).symm,\n  by simp [min_fac, this]; congr\n\nprivate def min_fac_prop (n k : \u2115) :=\n  2 \u2264 k \u2227 k \u2223 n \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m\n\ntheorem min_fac_aux_has_prop {n : \u2115} (n2 : 2 \u2264 n) :\n  \u2200 k i, k = 2*i+3 \u2192 (\u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k)\n| k := \u03bb i e a, begin\n  rw min_fac_aux,\n  by_cases h : n < k*k; simp [h],\n  { have pp : prime n :=\n      prime_def_le_sqrt.2 \u27e8n2, \u03bb m m2 l d,\n        not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9,\n    from \u27e8n2, dvd_rfl, \u03bb m m2 d, le_of_eq\n      ((dvd_prime_two_le pp m2).1 d).symm\u27e9 },\n  have k2 : 2 \u2264 k, { subst e, exact dec_trivial },\n  by_cases dk : k \u2223 n; simp [dk],\n  { exact \u27e8k2, dk, a\u27e9 },\n  { refine have _, from min_fac_lemma n k h,\n      min_fac_aux_has_prop (k+2) (i+1)\n        (by simp [e, left_distrib]) (\u03bb m m2 d, _),\n    cases nat.eq_or_lt_of_le (a m m2 d) with me ml,\n    { subst me, contradiction },\n    apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,\n    rw [\u2190 me, e] at d, change 2 * (i + 2) \u2223 n at d,\n    have := a _ le_rfl (dvd_of_mul_right_dvd d),\n    rw e at this, exact absurd this dec_trivial }\nend\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\ntheorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) :\n  min_fac_prop n (min_fac n) :=\nbegin\n  by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},\n  have n2 : 2 \u2264 n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },\n  simp [min_fac_eq],\n  by_cases d2 : 2 \u2223 n; simp [d2],\n  { exact \u27e8le_rfl, d2, \u03bb k k2 d, k2\u27e9 },\n  { refine min_fac_aux_has_prop n2 3 0 rfl\n      (\u03bb m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),\n    exact \u03bb e, e.symm \u25b8 d }\nend\n\ntheorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\nif n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1\n\ntheorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) :=\nlet \u27e8f2, fd, a\u27e9 := min_fac_has_prop n1 in\nprime_def_lt'.2 \u27e8f2, \u03bb m m2 l d, not_le_of_gt l (a m m2 (d.trans fd))\u27e9\n\ntheorem min_fac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, 2 \u2264 m \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\nby by_cases n1 : n = 1;\n  [exact \u03bb m m2 d, n1.symm \u25b8 le_trans dec_trivial m2,\n    exact (min_fac_has_prop n1).2.2]\n\ntheorem min_fac_pos (n : \u2115) : 0 < min_fac n :=\nby by_cases n1 : n = 1;\n    [exact n1.symm \u25b8 dec_trivial, exact (min_fac_prime n1).pos]\n\ntheorem min_fac_le {n : \u2115} (H : 0 < n) : min_fac n \u2264 n :=\nle_of_dvd H (min_fac_dvd n)\n\ntheorem le_min_fac {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, prime p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p pp d, h.elim\n  (by rintro rfl; cases pp.not_dvd_one d)\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp.two_le d),\n  \u03bb H, or_iff_not_imp_left.2 $ \u03bb n1, H _ (min_fac_prime n1) (min_fac_dvd _)\u27e9\n\ntheorem le_min_fac' {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, 2 \u2264 p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p (pp:1<p) d, h.elim\n  (by rintro rfl; cases not_le_of_lt pp (le_of_dvd dec_trivial d))\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp d),\n  \u03bb H, le_min_fac.2 (\u03bb p pp d, H p pp.two_le d)\u27e9\n\ntheorem prime_def_min_fac {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 min_fac p = p :=\n\u27e8\u03bb pp, \u27e8pp.two_le,\n  let \u27e8f2, fd, a\u27e9 := min_fac_has_prop $ ne_of_gt pp.one_lt in\n  ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n  \u03bb \u27e8p2, e\u27e9, e \u25b8 min_fac_prime (ne_of_gt p2)\u27e9\n\n@[simp] lemma prime.min_fac_eq {p : \u2115} (hp : prime p) : min_fac p = p :=\n(prime_def_min_fac.1 hp).2\n\n/--\nThis instance is faster in the virtual machine than `decidable_prime_1`,\nbut slower in the kernel.\n\nIf you need to prove that a particular number is prime, in any case\nyou should not use `dec_trivial`, but rather `by norm_num`, which is\nmuch faster.\n-/\ninstance decidable_prime (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_min_fac\n\ntheorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : 2 \u2264 n) : \u00ac prime n \u2194 min_fac n < n :=\n(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $\n  (lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm\n\nlemma min_fac_le_div {n : \u2115} (pos : 0 < n) (np : \u00ac prime n) : min_fac n \u2264 n / min_fac n :=\nmatch min_fac_dvd n with\n| \u27e80, h0\u27e9     := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial\n| \u27e81, h1\u27e9     :=\n  begin\n    rw mul_one at h1,\n    rw [prime_def_min_fac, not_and_distrib, \u2190 h1, eq_self_iff_true, not_true, or_false,\n      not_le] at np,\n    rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]\n  end\n| \u27e8(x+2), hx\u27e9 :=\n  begin\n    conv_rhs { congr, rw hx },\n    rw [nat.mul_div_cancel_left _ (min_fac_pos _)],\n    exact min_fac_le_of_dvd dec_trivial \u27e8min_fac n, by rwa mul_comm\u27e9\n  end\nend\n\n/--\nThe square of the smallest prime factor of a composite number `n` is at most `n`.\n-/\nlemma min_fac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00ac prime n) : (min_fac n)^2 \u2264 n :=\nhave t : (min_fac n) \u2264 (n/min_fac n) := min_fac_le_div w h,\ncalc\n(min_fac n)^2 = (min_fac n) * (min_fac n)   : sq (min_fac n)\n          ... \u2264 (n/min_fac n) * (min_fac n) : nat.mul_le_mul_right (min_fac n) t\n          ... \u2264 n                           : div_mul_le_self n (min_fac n)\n\n@[simp]\nlemma min_fac_eq_one_iff {n : \u2115} : min_fac n = 1 \u2194 n = 1 :=\nbegin\n  split,\n  { intro h,\n    by_contradiction hn,\n    have := min_fac_prime hn,\n    rw h at this,\n    exact not_prime_one this, },\n  { rintro rfl, refl, }\nend\n\n@[simp]\nlemma min_fac_eq_two_iff (n : \u2115) : min_fac n = 2 \u2194 2 \u2223 n :=\nbegin\n  split,\n  { intro h,\n    convert min_fac_dvd _,\n    rw h, },\n  { intro h,\n    have ub := min_fac_le_of_dvd (le_refl 2) h,\n    have lb := min_fac_pos n,\n    apply ub.eq_or_lt.resolve_right (\u03bb h', _),\n    have := le_antisymm (nat.succ_le_of_lt lb) (lt_succ_iff.mp h'),\n    rw [eq_comm, nat.min_fac_eq_one_iff] at this,\n    subst this,\n    exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two }\nend\n\nend min_fac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n\u27e8min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,\n  ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 2 \u2264 m \u2227 m < n :=\n\u27e8min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,\n  (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_prime_and_dvd {n : \u2115} (hn : n \u2260 1) : \u2203 p, prime p \u2227 p \u2223 n :=\n\u27e8min_fac n, min_fac_prime hn, min_fac_dvd _\u27e9\n\ntheorem dvd_of_forall_prime_mul_dvd {a b : \u2115}\n  (hdvd : \u2200 p : \u2115, p.prime \u2192 p \u2223 a \u2192 p * a \u2223 b) : a \u2223 b :=\nbegin\n  obtain rfl | ha := eq_or_ne a 1, { apply one_dvd },\n  obtain \u27e8p, hp\u27e9 := exists_prime_and_dvd ha,\n  exact trans (dvd_mul_left a p) (hdvd p hp.1 hp.2),\nend\n\n/-- Euclid's theorem on the **infinitude of primes**.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, n \u2264 p \u2227 prime p :=\nlet p := min_fac (n! + 1) in\nhave f1 : n! + 1 \u2260 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,\nhave pp : prime p, from min_fac_prime f1,\nhave np : n \u2264 p, from le_of_not_ge $ \u03bb h,\n  have h\u2081 : p \u2223 n!, from dvd_factorial (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  pp.not_dvd_one h\u2082,\n\u27e8p, np, pp\u27e9\n\n/-- A version of `nat.exists_infinite_primes` using the `bdd_above` predicate. -/\nlemma not_bdd_above_set_of_prime : \u00ac bdd_above {p | prime p} :=\nbegin\n  rw not_bdd_above_iff,\n  intro n,\n  obtain \u27e8p, hi, hp\u27e9 := exists_infinite_primes n.succ,\n  exact \u27e8p, hp, hi\u27e9,\nend\n\nlemma prime.eq_two_or_odd {p : \u2115} (hp : prime p) : p = 2 \u2228 p % 2 = 1 :=\np.mod_two_eq_zero_or_one.imp_left\n  (\u03bb h, ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)\n\nlemma prime.eq_two_or_odd' {p : \u2115} (hp : prime p) : p = 2 \u2228 odd p :=\nor.imp_right (\u03bb h, \u27e8p / 2, (div_add_mod p 2).symm.trans (congr_arg _ h)\u27e9) hp.eq_two_or_odd\n\nlemma prime.even_iff {p : \u2115} (hp : prime p) : even p \u2194 p = 2 :=\nby rw [even_iff_two_dvd, prime_dvd_prime_iff_eq prime_two hp, eq_comm]\n\nlemma prime.odd_of_ne_two {p : \u2115} (hp : p.prime) (h_two : p \u2260 2) : odd p :=\nhp.eq_two_or_odd'.resolve_left h_two\n\nlemma prime.even_sub_one {p : \u2115} (hp : p.prime) (h2 : p \u2260 2) : even (p - 1) :=\nlet \u27e8n, hn\u27e9 := hp.odd_of_ne_two h2 in \u27e8n, by rw [hn, nat.add_sub_cancel, two_mul]\u27e9\n\n/-- A prime `p` satisfies `p % 2 = 1` if and only if `p \u2260 2`. -/\nlemma prime.mod_two_eq_one_iff_ne_two {p : \u2115} [fact p.prime] : p % 2 = 1 \u2194 p \u2260 2 :=\nbegin\n  refine \u27e8\u03bb h hf, _, (nat.prime.eq_two_or_odd $ fact.out p.prime).resolve_left\u27e9,\n  rw hf at h,\n  simpa using h,\nend\n\ntheorem coprime_of_dvd {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 \u00ac k \u2223 n) : coprime m n :=\nbegin\n  rw [coprime_iff_gcd_eq_one],\n  by_contra g2,\n  obtain \u27e8p, hp, hpdvd\u27e9 := exists_prime_and_dvd g2,\n  apply H p hp; apply dvd_trans hpdvd,\n  { exact gcd_dvd_left _ _ },\n  { exact gcd_dvd_right _ _ }\nend\n\ntheorem coprime_of_dvd' {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) : coprime m n :=\ncoprime_of_dvd $ \u03bbk kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn\n\ntheorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=\ndiv_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt\n\ntheorem prime.coprime_iff_not_dvd {p n : \u2115} (pp : prime p) : coprime p n \u2194 \u00ac p \u2223 n :=\n\u27e8\u03bb co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),\n \u03bb nd, coprime_of_dvd $ \u03bb m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm \u25b8 nd\u27e9\n\ntheorem prime.dvd_iff_not_coprime {p n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00ac coprime p n :=\niff_not_comm.2 pp.coprime_iff_not_dvd\n\ntheorem prime.not_coprime_iff_dvd {m n : \u2115} :\n  \u00ac coprime m n \u2194 \u2203p, prime p \u2227 p \u2223 m \u2227 p \u2223 n :=\nbegin\n  apply iff.intro,\n  { intro h,\n    exact \u27e8min_fac (gcd m n), min_fac_prime h,\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_left m n)),\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_right m n))\u27e9 },\n  { intro h,\n    cases h with p hp,\n    apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }\nend\n\ntheorem prime.dvd_mul {p m n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n\u27e8\u03bb H, or_iff_not_imp_left.2 $ \u03bb h,\n  (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n or.rec (\u03bb h : p \u2223 m, h.mul_right _) (\u03bb h : p \u2223 n, h.mul_left _)\u27e9\n\ntheorem prime.not_dvd_mul {p m n : \u2115} (pp : prime p)\n  (Hm : \u00ac p \u2223 m) (Hn : \u00ac p \u2223 n) : \u00ac p \u2223 m * n :=\nmt pp.dvd_mul.1 $ by simp [Hm, Hn]\n\ntheorem prime_iff {p : \u2115} : p.prime \u2194 _root_.prime p :=\n\u27e8\u03bb h, \u27e8h.ne_zero, h.not_unit, \u03bb a b, h.dvd_mul.mp\u27e9, prime.irreducible\u27e9\n\nalias prime_iff \u2194 prime.prime _root_.prime.nat_prime\nattribute [protected, nolint dup_namespace] prime.prime\n\ntheorem irreducible_iff_prime {p : \u2115} : irreducible p \u2194 _root_.prime p := prime_iff\n\ntheorem prime.dvd_of_dvd_pow {p m n : \u2115} (pp : prime p) (h : p \u2223 m^n) : p \u2223 m :=\nbegin\n  induction n with n IH,\n  { exact pp.not_dvd_one.elim h },\n  { rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH }\nend\n\nlemma prime.pow_not_prime {x n : \u2115} (hn : 2 \u2264 n) : \u00ac (x ^ n).prime :=\n\u03bb hp, (hp.eq_one_or_self_of_dvd x $ dvd_trans \u27e8x, sq _\u27e9 (pow_dvd_pow _ hn)).elim\n  (\u03bb hx1, hp.ne_one $ hx1.symm \u25b8 one_pow _)\n  (\u03bb hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm\n     ... < x ^ n : nat.pow_right_strict_mono (hxn.symm \u25b8 hp.two_le) hn\n     ... = x : hxn.symm)\n\nlemma prime.pow_not_prime' {x : \u2115} : \u2200 {n : \u2115}, n \u2260 1 \u2192 \u00ac (x ^ n).prime\n| 0     := \u03bb _, not_prime_one\n| 1     := \u03bb h, (h rfl).elim\n| (n+2) := \u03bb _, prime.pow_not_prime le_add_self\n\nlemma prime.eq_one_of_pow {x n : \u2115} (h : (x ^ n).prime) : n = 1 :=\nnot_imp_not.mp prime.pow_not_prime' h\n\nlemma prime.pow_eq_iff {p a k : \u2115} (hp : p.prime) : a ^ k = p \u2194 a = p \u2227 k = 1 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, by rw [h.1, h.2, pow_one]\u27e9,\n  rw \u2190h at hp,\n  rw [\u2190h, hp.eq_one_of_pow, eq_self_iff_true, and_true, pow_one],\nend\n\nlemma pow_min_fac {n k : \u2115} (hk : k \u2260 0) : (n^k).min_fac = n.min_fac :=\nbegin\n  rcases eq_or_ne n 1 with rfl | hn,\n  { simp },\n  have hnk : n ^ k \u2260 1 := \u03bb hk', hn ((pow_eq_one_iff hk).1 hk'),\n  apply (min_fac_le_of_dvd (min_fac_prime hn).two_le ((min_fac_dvd n).pow hk)).antisymm,\n  apply min_fac_le_of_dvd (min_fac_prime hnk).two_le\n    ((min_fac_prime hnk).dvd_of_dvd_pow (min_fac_dvd _)),\nend\n\nlemma prime.pow_min_fac {p k : \u2115} (hp : p.prime) (hk : k \u2260 0) : (p^k).min_fac = p :=\nby rw [pow_min_fac hk, hp.min_fac_eq]\n\nlemma prime.mul_eq_prime_sq_iff {x y p : \u2115} (hp : p.prime) (hx : x \u2260 1) (hy : y \u2260 1) :\n  x * y = p ^ 2 \u2194 x = p \u2227 y = p :=\n\u27e8\u03bb h, have pdvdxy : p \u2223 x * y, by rw h; simp [sq],\nbegin\n  -- Could be `wlog := hp.dvd_mul.1 pdvdxy using x y`, but that imports more than we want.\n  suffices : \u2200 (x' y' : \u2115), x' \u2260 1 \u2192 y' \u2260 1 \u2192 x' * y' = p ^ 2 \u2192 p \u2223 x' \u2192 x' = p \u2227 y' = p,\n  { obtain hx|hy := hp.dvd_mul.1 pdvdxy;\n      [skip, rw and_comm];\n      [skip, rw mul_comm at h pdvdxy];\n      apply this;\n      assumption },\n  clear_dependent x y,\n  rintros x y hx hy h \u27e8a, ha\u27e9,\n  have hap : a \u2223 p, from \u27e8y, by rwa [ha, sq,\n        mul_assoc, mul_right_inj' hp.ne_zero, eq_comm] at h\u27e9,\n  exact ((nat.dvd_prime hp).1 hap).elim\n    (\u03bb _, by clear_aux_decl; simp [*, sq, mul_right_inj' hp.ne_zero] at *\n      {contextual := tt})\n    (\u03bb _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,\n      mul_right_inj' hp.ne_zero, nat.mul_right_eq_self_iff hp.pos] at *\n      {contextual := tt})\nend,\n\u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.symm \u25b8 h\u2082.symm \u25b8 (sq _).symm\u27e9\n\nlemma prime.dvd_factorial : \u2200 {n p : \u2115} (hp : prime p), p \u2223 n! \u2194 p \u2264 n\n| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)\n| (n+1) p hp := begin\n  rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],\n  exact \u27e8\u03bb h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,\n    \u03bb h, (_root_.lt_or_eq_of_le h).elim (or.inr \u2218 le_of_lt_succ)\n      (\u03bb h, or.inl $ by rw h)\u27e9\nend\n\ntheorem prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : prime p) (h : \u00ac p \u2223 a) : coprime a (p^m) :=\n(pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n\ntheorem coprime_primes {p q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\npp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : prime p) (pq : prime q) (h : p \u2260 q) :\n  coprime (p^n) (q^m) :=\n((coprime_primes pp pq).2 h).pow _ _\n\ntheorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\nby rw [pp.dvd_iff_not_coprime]; apply em\n\nlemma coprime_of_lt_prime {n p} (n_pos : 0 < n) (hlt : n < p) (pp : prime p) :\n  coprime p n :=\n(coprime_or_dvd_of_prime pp n).resolve_right $ \u03bb h, lt_le_antisymm hlt (le_of_dvd n_pos h)\n\nlemma eq_or_coprime_of_le_prime {n p} (n_pos : 0 < n) (hle : n \u2264 p) (pp : prime p) :\n  p = n \u2228 coprime p n :=\nhle.eq_or_lt.imp eq.symm (\u03bb h, coprime_of_lt_prime n_pos h pp)\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m i : \u2115} : i \u2223 (p^m) \u2194 \u2203 k \u2264 m, i = p^k :=\nby simp_rw [dvd_prime_pow (prime_iff.mp pp) m, associated_eq_eq]\n\nlemma prime.dvd_mul_of_dvd_ne {p1 p2 n : \u2115} (h_neq : p1 \u2260 p2) (pp1 : prime p1) (pp2 : prime p2)\n  (h1 : p1 \u2223 n) (h2 : p2 \u2223 n) : (p1 * p2 \u2223 n) :=\ncoprime.mul_dvd_of_dvd_of_dvd ((coprime_primes pp1 pp2).mpr h_neq) h1 h2\n\n/--\nIf `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\nlemma eq_prime_pow_of_dvd_least_prime_pow\n  {a p k : \u2115} (pp : prime p) (h\u2081 : \u00ac(a \u2223 p^k)) (h\u2082 : a \u2223 p^(k+1)) :\n  a = p^(k+1) :=\nbegin\n  obtain \u27e8l, \u27e8h, rfl\u27e9\u27e9 := (dvd_prime_pow pp).1 h\u2082,\n  congr,\n  exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h\u2081)),\nend\n\nlemma ne_one_iff_exists_prime_dvd : \u2200 {n}, n \u2260 1 \u2194 \u2203 p : \u2115, p.prime \u2227 p \u2223 n\n| 0 := by simpa using (Exists.intro 2 nat.prime_two)\n| 1 := by simp [nat.not_prime_one]\n| (n+2) :=\nlet a := n+2 in\nlet ha : a \u2260 1 := nat.succ_succ_ne_one n in\nbegin\n  simp only [true_iff, ne.def, not_false_iff, ha],\n  exact \u27e8a.min_fac, nat.min_fac_prime ha, a.min_fac_dvd\u27e9,\nend\n\nlemma eq_one_iff_not_exists_prime_dvd {n : \u2115} : n = 1 \u2194 \u2200 p : \u2115, p.prime \u2192 \u00acp \u2223 n :=\nby simpa using not_iff_not.mpr ne_one_iff_exists_prime_dvd\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m n k l : \u2115}\n      (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k+l+1) \u2223 m*n) :\n      p ^ (k+1) \u2223 m \u2228 p ^ (l+1) \u2223 n :=\nhave hpd : p^(k+l)*p \u2223 m*n, by rwa pow_succ' at hpmn,\nhave hpd2 : p \u2223 (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,\nhave hpd3 : p \u2223 (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,\nhave hpd4 : p \u2223 (m / p^k) * (n / p^l), by simpa [nat.div_mul_div_comm hpm hpn] using hpd3,\nhave hpd5 : p \u2223 (m / p^k) \u2228 p \u2223 (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,\nsuffices p^k*p \u2223 m \u2228 p^l*p \u2223 n, by rwa [pow_succ', pow_succ'],\n  hpd5.elim\n    (assume : p \u2223 m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)\n    (assume : p \u2223 n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)\n\nlemma prime_iff_prime_int {p : \u2115} : p.prime \u2194 _root_.prime (p : \u2124) :=\n\u27e8\u03bb hp, \u27e8int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt int.is_unit_iff_nat_abs_eq.1 hp.ne_one,\n  \u03bb a b h, by rw [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;\n    rwa [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, \u2190 int.dvd_nat_abs, int.coe_nat_dvd]\u27e9,\n  \u03bb hp, nat.prime_iff.2 \u27e8int.coe_nat_ne_zero.1 hp.1,\n      mt nat.is_unit_iff.1 $ \u03bb h, by simpa [h, not_prime_one] using hp,\n    \u03bb a b, by simpa only [int.coe_nat_dvd, (int.coe_nat_mul _ _).symm] using hp.2.2 a b\u27e9\u27e9\n\n/-- The type of prime numbers -/\ndef primes := {p : \u2115 // p.prime}\n\nnamespace primes\n\ninstance : has_repr nat.primes := \u27e8\u03bb p, repr p.val\u27e9\ninstance inhabited_primes : inhabited primes := \u27e8\u27e82, prime_two\u27e9\u27e9\n\ninstance coe_nat : has_coe nat.primes \u2115 := \u27e8subtype.val\u27e9\n\ntheorem coe_nat_injective : function.injective (coe : nat.primes \u2192 \u2115) :=\nsubtype.coe_injective\n\ntheorem coe_nat_inj (p q : nat.primes) : (p : \u2115) = (q : \u2115) \u2194 p = q :=\nsubtype.ext_iff.symm\n\nend primes\n\ninstance monoid.prime_pow {\u03b1 : Type*} [monoid \u03b1] : has_pow \u03b1 primes := \u27e8\u03bb x p, x^(p : \u2115)\u27e9\n\nend nat\n\nnamespace nat\n\ninstance fact_prime_two : fact (prime 2) := \u27e8prime_two\u27e9\n\ninstance fact_prime_three : fact (prime 3) := \u27e8prime_three\u27e9\n\nend nat\n\nnamespace int\nlemma prime_two : prime (2 : \u2124) := nat.prime_iff_prime_int.mp nat.prime_two\nlemma prime_three : prime (3 : \u2124) := nat.prime_iff_prime_int.mp nat.prime_three\nend int\n\nassert_not_exists multiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7298603898283144}}
{"text": "/- In this file we demonstrate examples and constructions of various types. Key\ndefinitions can be found in the model.lean file.-/\n\nimport model\n\n\n/-- We now define some example languages. We start with the simplest\npossible language, the language of pure sets. This language has no\nfunctions, relations or constants.-/\ndef set_lang: lang := {F := function.const \u2115+ empty,\n                       R := function.const \u2115+ empty,\n                       C := empty}\n\n\n/-- The language of ordered sets is the language or sets with a binary\n  ordering relation {<}.-/\ndef ordered_set_lang: lang := {R := \u03bb n : \u2115+, if n=2 then unit else empty,\n                               ..set_lang}\n\n/-- A magma is a {\u00d7}-structure. So this has 1 function, 0 relations and\n0 constants.-/\ndef magma_lang : lang := {F := \u03bb n : \u2115+, if n=2 then unit else empty,\n                          ..set_lang}\n\n\n/-- A semigroup is a {\u00d7}-structure which satisfies the identity\n  u \u00d7 (v \u00d7 w) = (u \u00d7 v) \u00d7 w.  Note that identities are not relations!-/\ndef semigroup_lang : lang := magma_lang\n\n/-- A monoid is a {\u00d7, 1}-structure which satisfies the identities\n   1. u \u00d7 (v \u00d7 w) = (u \u00d7 v) \u00d7 w\n   2. u \u00d7 1 = u\n   3. 1 \u00d7 u = u. -/\ndef monoid_lang : lang := {F := \u03bb n : \u2115+,\n                                if n=2 then unit else empty, -- one binary op.,\n                           C := unit,                        -- one constant\n                           R := function.const \u2115+ empty}\n\n/-- A group is a {\u00d7, \u207b\u00b9, 1}-structure which satisfies the identities\n 1. u \u00d7 (v \u00d7 w) = (u \u00d7 v) \u00d7 w\n 2. u \u00d7 1 = u\n 3. 1 \u00d7 u = u\n 4. u \u00d7 u\u22121 = 1\n 5. u\u22121 \u00d7 u = 1 -/\ndef group_lang : lang := {F := \u03bb n : \u2115+,\n                               if n=1 then unit else        -- one unary op.\n                               if n=2 then unit else empty, -- one binary op.\n                          C := unit,                        -- one constant\n                          ..set_lang}\n\n/-- A semiring is a {\u00d7, +, 0, 1}-structure which satisfies the identities\n  1. u + (v + w) = (u + v) + w\n  2. u + v = v + u\n  3. u + 0 = u\n  5. u \u00d7 (v \u00d7 w) = (u \u00d7 v) \u00d7 w\n  6. u \u00d7 1 = u, 1 \u00d7 u = u\n  7. u \u00d7 (v + w) = (u \u00d7 v) + (u \u00d7 w)\n  8. (v + w) \u00d7 u = (v \u00d7 u) + (w \u00d7 u)-/\ndef semiring_lang : lang := {F := \u03bb n : \u2115+,\n                                  if n = 2 then fin 2 else empty, -- two binary ops.\n                             C := fin 2,                     -- two constants\n                             ..magma_lang}\n\n\n/-- A ring is a {\u00d7,+,\u2212,0,1}-structure which satisfies the identities\n   1. u + (v + w) = (u + v) + w\n   2. u + v = v + u\n   3. u + 0 = u\n   4. u + (\u2212u) = 0\n   5. u \u00d7 (v \u00d7 w) = (u \u00d7 v) \u00d7 w\n   6. u \u00d7 1 = u, 1 \u00d7 u = u\n   7. u \u00d7 (v + w) = (u \u00d7 v) + (u \u00d7 w)\n   8. (v + w) \u00d7 u = (v \u00d7 u) + (w \u00d7 u)-/\ndef ring_lang : lang := {F := \u03bb n : \u2115+,\n                              if n = 1 then fin 1 else        -- one unary op.\n                              if n = 2 then fin 2 else empty, -- two binary ops.\n                         C := fin 2,                          -- two constants\n                         ..magma_lang}\n\n/-- An ordered ring is a ring along with a binary ordering relation {<}.-/\ndef ordered_ring_lang : lang := {R := \u03bb n : \u2115+,\n                                if n = 2 then unit else empty,  -- one binary rel.\n                                ..ring_lang}\n\n\n/-- An inhabited type is a structure of the set language-/\ndef type_is_struc_of_set_lang {A : Type} [inhabited A] : struc (set_lang) :=\n {univ := A,\n  F := \u03bb _, empty.elim,\n  R := \u03bb _, empty.elim,\n  C := empty.elim}\n\n\n/-- Type is a structure of the ordered set language-/\ndef type_is_struc_of_ordered_set_lang {A : Type} [has_lt A] [inhabited A]:\n  struc (ordered_set_lang) :=\n  {univ := A,\n   F := \u03bb _, empty.elim,\n   R := \u03bb n r v, by {repeat {cases n <|> unfold_coes at v <|> linarith\n                             <|> cases r <|> cases n_val},\n                     exact (v.nth 0 < v.nth 1)},\n   C := empty.elim}\n\n\n\n/-- We need to define a magma, because it looks like it is not defined\n  in Mathlib.-/\nclass magma (\u03b1 : Type) :=\n(mul : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n\n\ndef free_magma_is_struc_of_magma_lang {A : Type} [magma A] [inhabited A] :\n  struc (magma_lang) :=\n  {univ := A,\n   F := \u03bb n f, by {repeat {cases n with n_val _ <|> unfold_coes <|> cases f\n                    <|> linarith <|> cases n_val},\n                   exact magma.mul}, -- if n=2\n   R := \u03bb _, empty.elim,\n   C := empty.elim}\n\n\ndef semigroup_is_struc_of_semigroup_lang {A : Type} [semigroup A] [inhabited A] :\n  struc (semigroup_lang) :=\n  {univ := A,\n   F := \u03bb n f, by {repeat {cases n <|> linarith <|> cases f <|> cases n_val},\n                   exact semigroup.mul},\n   R := \u03bb _, empty.elim,\n   C := empty.elim}\n\n\n/-- Monoid is a structure of the language of monoids-/\ndef monoid_is_struc_of_monoid_lang {A : Type} [monoid A] :\n  struc (monoid_lang) :=\n  {univ := A,\n   F := \u03bb n f, by {repeat {cases n <|> cases f <|> linarith <|> cases n_val},\n                   exact monoid.mul},\n   R := \u03bb _, empty.elim,\n   C := 1,\n   univ_inhabited := \u27e81\u27e9}\n\n/-- Group is a structure of the group language-/\ndef group_is_struc_of_group_lang {A : Type} [group A] :\n  struc (group_lang) :=\n  {univ := A,\n   F := \u03bb n f, by {repeat {cases n <|> linarith <|> cases f <|> cases n_val},\n                   exact group.inv,\n                   exact group.mul},\n   ..monoid_is_struc_of_monoid_lang}\n\n\n/-- Semiring is a structure of the language of semirings-/\ndef semiring_is_struc_of_semiring_lang {A : Type} [semiring A] :\n  struc (semiring_lang) :=\n  {univ := A,\n   F := \u03bb n f, by {cases n, cases n_val,\n                     {linarith},\n                   cases n_val, cases f,\n                   cases n_val, cases f,\n                     {cases f_val,\n                      exact (+),\n                      exact (*)},\n                   cases f},\n   R := \u03bb _, empty.elim,\n   C := \u03bb c, by {cases c, cases c_val, exact 0, exact 1},\n   univ_inhabited := \u27e80\u27e9}\n\n\n/-- Ring is a structure of the language of rings-/\ndef ring_is_struc_of_ring_lang {A : Type} [ring A] :\n  struc (ring_lang) :=\n  {univ := A,\n   F := \u03bb n f, by {cases n, cases n_val,\n                     {linarith},\n                   cases n_val,\n                     {exact ring.neg},\n                   cases n_val, cases f,\n                     {cases f_val,\n                      exact (+),\n                      exact (*)},\n                   cases f},\n   ..semiring_is_struc_of_semiring_lang}\n\n\n/-- Ordered ring is a structure of the language of ordered rings-/\ndef ordered_ring_is_struc_of_ordered_ring_lang {A : Type} [ordered_ring A]\n  : struc(ordered_ring_lang) :=\n  {univ := A,\n   R := \u03bb n r v, by {cases n, cases n_val,\n                       {linarith},\n                     cases n_val, cases r,\n                       {unfold_coes at v,\n                        exact v.nth 0 < v.nth 1}},\n   ..ring_is_struc_of_ring_lang}\n\n\n/-- A type with linear order is a structure on dense-linear-order language.-/\ndef LO_is_struc_of_DLO_lang {A : Type} [linear_order A] [inhabited A]\n : struc (lang.DLO_lang) :=\n  {univ := A,\n   R := \u03bb n r v, by {cases n, cases n_val,\n                       {linarith},\n                     cases n_val, cases r,\n                       {unfold_coes at v,\n                        exact (v.nth 0 < v.nth 1)}},\n   .. type_is_struc_of_set_lang}\n\n\n/- TODO: Fix this proof.\nlemma ordered_ring_is_struc_of_ordered_ring_lang {A : Type} [ordered_ring A] :\n  struc (ordered_ring_lang) :=\nbegin\n  fconstructor,\n  { exact A},\n  {\n    intros n f,\n    cases n,\n     cases f,                                              -- n=0: f n = empty\n    cases n,\n     exact ordered_ring.neg (v.nth 0),                     -- n=1: f n = {-}\n    cases n,\n     cases f,                                              -- n=2: f n = {\u00d7, +}\n     { exact ordered_ring.mul (v.nth 0) (v.nth 1)},        -- \u00d7\n     { exact ordered_ring.add (v.nth 0) (v.nth 1)},        -- +\n     cases f,                                              -- n>2: f n = empty\n  },\n  {\n    intros n r v,\n    iterate 2 {cases n, cases r},                          -- n<2: r n = empty\n    cases n,\n     exact ordered_ring.lt (v.nth 0) (v.nth 1),            -- n=2: r n = {<}\n     cases r,                                              -- n>2: r n = empty\n  },\n  {\n    intro c,\n    cases c,     --C = {0, 1}\n    { exact 0},\n    { exact 1}\n  }\nend-/\n\n\n/-! 4.1 Examples of Terms\n    ---------------------\nThe following example is taken from [Marker2002]. -/\n\nnamespace example_terms\n  /-- The language L has:\n  - one unary function f,\n  - one binary function g,\n  - and one constant symbol c.-/\n\n  def L1 : lang := {F := \u03bb (n : \u2115+),\n                         if n=1 then unit else        -- one unary op.\n                         if n=2 then unit else empty, -- one binrary op.\n                    R := function.const \u2115+ empty,\n                    C := unit}\n  /-- f is a unary operation in L1. -/\n  def f : L1.F 1 := unit.star\n  /-- g is a binary operation in L1. -/\n  def g : L1.F 2 := unit.star\n  /-- c is a constant in L1. -/\n  def c : L1.C := unit.star\n\n  /-- M1 is a structure on L1. -/\n  def M1 : struc L1 :=\n  {univ := \u2115,\n   F := \u03bb n f, by {cases n, cases n_val,\n                     { linarith},\n                   cases n_val,\n                     { exact \u03bb x : \u2115, 100*x}, -- if n=1\n                   cases n_val,\n                     { exact (+)},             -- if n=2\n                   cases f},                   -- if n>2\n   R := \u03bb _, empty.elim,\n   C := \u03bb c, 1,\n   }\n\n\n  open term\n\n  /-- t = f(g(c, f(v\u2085))) is a term on language L1.-/\n  def t\u2081 : term L1 0 := app (func f) (var 5)            -- f(c)\n  def t\u2082 : term L1 0 := app (app (func g) (con c)) t\u2081   -- g(c)(t\u2081)\n  def t\u2083 : term L1 0 := app (func f) t\u2082                 -- f(t\u2082)\n  def t : term L1 0 := app (func f)\n                           $ app (app (func g) (con c))\n                                 $ app (func f) (con c)\n  def va : \u2115 \u2192 M1.univ := function.const \u2115 (M1.C c)\n\n  #reduce term_interpretation va (func f)  -- f is interpreted as x \u21a6 100x\n  #reduce term_interpretation va (func g)  -- g is interpreted (x, y) \u21a6 x+y\n  #reduce term_interpretation va (con c)   -- c is interpreted as (1 : \u2115)\n  #reduce term_interpretation va t\u2081          -- f(c) is interpreted as 100\n  #reduce term_interpretation va t\u2082          -- g(c, t\u2081) is interpreted as 101\n  #reduce term_interpretation va t\u2083          -- f(g(c, f(c))) is interpreted as 10100\n  #reduce term_interpretation va t           -- same as t\u2083\n\n\n  def t\u2084 : term L1 0 := app (func f) (var 5) -- f(v\u2085)\n  def t\u2085 : term L1 0 := app (app (func g) (con c)) (var 4) -- g(c, v\u2084)\n  #reduce term_sub t\u2085 0 t\u2084 -- f(g(c, v\u2084))\n  #reduce term_sub (var 3) 0 t\u2084 -- f(v\u2083)\n  #reduce term_sub_for_var (var 3) 4 0 t\u2084 -- f(v\u2085)\n  #reduce term_sub_for_var (var 3) 5 0 t\u2084 -- f(v\u2083)\n\n\n  open example_terms\n  def \u03c8\u2081 : formula L1 := t\u2081 =' (var 5) -- f(c) = v\u2085\n  def \u03c8\u2082 : formula L1 := \u00ac' (var 4 =' t\u2083 ) -- g(c, t\u2081) =/= v\u2084\n  def \u03c8\u2083 : formula L1 := \u2203' 3 \u03c8\u2081 -- \u2203v\u2083  f(v\u2085) = v\u2085\n  def \u03c8\u2084 : formula L1 := \u2200' 4 (\u2200' 5 \u03c8\u2082) -- \u2200v\u2084\u2200v\u2085 g(c, f(v\u2084)) =/= v\u2085\n\n  example : \u00ac (formula.var_occurs_freely 5 \u03c8\u2084) :=\n  begin\n    rw \u03c8\u2084,\n    unfold formula.var_occurs_freely,\n    rw \u03c8\u2082,\n    simp,\n  end\n\n  def phi : formula (lang.DLO_lang) :=\n  \u00ac'(\u2200' 2 \u22a4') \u2227' ((var 1) =' (var 4)) \u2227' (\u2203' 3 (var 2 =' var 3))\n\n  example :   formula.var_occurs_freely 1 phi :=\n    by norm_num [phi, formula.var_occurs_freely]\n  example :   formula.var_occurs_freely 2 phi :=\n    by norm_num [phi, formula.var_occurs_freely]\n  example : \u00ac formula.var_occurs_freely 3 phi :=\n    by norm_num [phi, formula.var_occurs_freely]\n  example :   formula.var_occurs_freely 4 phi :=\n    by norm_num [phi, formula.var_occurs_freely]\n  example : \u00ac formula.var_occurs_freely 5 phi :=\n    by norm_num [phi, formula.var_occurs_freely]\n\n\nend example_terms\n\n\n\nnamespace DLO_Model\n\n@[reducible] def Q_struc : struc lang.DLO_lang :=\n { univ := \u211a,\n   R := \u03bb n f, by { cases n, cases n_val,\n                      {linarith},\n                    cases n_val,\n                      {exact \u2205},\n                    cases n_val,\n                      {exact {v : vector \u211a 2 | v.nth 0 < v.nth 1}},\n                    exact \u2205},\n  F := \u03bb _, empty.elim,\n  C := empty.elim\n }\nnotation `<'` : 110 := @formula.rel lang.DLO_lang 2 ()\n\n/- A dense linear ordering without endpoints is a language containg a\n    single binary relation symbol < satisfying the following sentences:\n-- 1. \u2200x x < x;\n-- 2. \u2200x \u2200y \u2200z (x < y \u2192 (y < z \u2192 x < z));\n-- 3. \u2200x \u2200y (x < y \u2228 x = y \u2228 y < x);\n-- 4. \u2200x \u2203y x < y;\n-- 5. \u2200x \u2203y y < x;\n-- 6. \u2200x \u2200y (x < y \u2192 \u2203z (x < z \u2227 z < y)). -/\n\nopen term\n@[reducible] def mk_vec (v\u2081 v\u2082 : \u2115) : vector (term lang.DLO_lang 0) 2 := \u27e8[var v\u2081, var v\u2082], rfl\u27e9\n@[reducible] def \u03c6\u2081 : formula lang.DLO_lang := <' $ mk_vec 1 2 -- x < y\n@[reducible] def \u03c6\u2082 : formula lang.DLO_lang := <' $ mk_vec 2 1 -- y < x\n@[reducible] def \u03c6\u2083 : formula lang.DLO_lang := <' $ mk_vec 2 3 -- y < z\n@[reducible] def \u03c6\u2084 : formula lang.DLO_lang := <' $ mk_vec 3 2 -- z < y\n@[reducible] def \u03c6\u2085 : formula lang.DLO_lang := <' $ mk_vec 1 3 -- x < z\n@[reducible] def \u03c6\u2086 : formula lang.DLO_lang := <' $ mk_vec 1 1 -- x < x\n\ndef DLO_axioms : set (formula lang.DLO_lang) :=\n { \u2200'1 (\u00ac' \u03c6\u2086),\n   \u2200'1 (\u2200'2 (\u2200'3 (\u03c6\u2081 \u2192' (\u03c6\u2083 \u2192' \u03c6\u2085)))),\n   \u2200'1 (\u2200'2 ((\u03c6\u2081 \u2228' \u03c6\u2082) \u2228' (var 1 =' var 2))),\n   \u2200'1 (\u2203'2 (\u03c6\u2081)),\n   \u2200'1 (\u2203'2 (\u03c6\u2082)),\n   \u2200'1 (\u2200'2 (\u03c6\u2081 \u2192' \u2203'3(\u03c6\u2085 \u2227' \u03c6\u2084)))}\n\n\ndef DLO_theory : set (sentence lang.DLO_lang) :=\n { \u27e8\u2200'1 (\u00ac' \u03c6\u2086), by {finish [formula.var_occurs_freely]}\u27e9,\n   \u27e8\u2200'1 (\u2200'2 (\u2200'3 (\u03c6\u2081 \u2192' (\u03c6\u2083 \u2192' \u03c6\u2085)))),\n     by {push_neg,\n         rintros _ _ _ _ (\u27e8_ | _ | _\u27e9 | \u27e8_ | _ | _\u27e9 | _ | _ | _);\n         tauto}\u27e9,\n   \u27e8\u2200'1 (\u2200'2 (\u2200' 3 ((\u03c6\u2081 \u2228' \u03c6\u2082) \u2228' (var 1 =' var 2)))),\n     by {push_neg,\n         rintro (_ | _ | _ | _ | _ | _) _ _ _;\n         exact dec_trivial <|> tauto}\u27e9,\n   \u27e8\u2200'1 (\u2203'2 (\u03c6\u2081)),\n     by {push_neg,\n         rintros _ _ _ (_ | _ | _);\n         tauto}\u27e9,\n   \u27e8\u2200'1 (\u2203'2 (\u03c6\u2082)),\n        by {push_neg,\n            rintros _ _ _ (_ | _ | _);\n            tauto}\u27e9,\n   \u27e8\u2200'1 (\u2200'2 (\u03c6\u2081 \u2192' \u2203'3(\u03c6\u2085 \u2227' \u03c6\u2084))),\n        by {push_neg,\n            rintros _ _ _ (\u27e8_ | _ | _\u27e9 | \u27e8_, \u27e8_ | _ | _\u27e9 | _ | _ | _\u27e9);\n            tauto}\u27e9,\n  }\n\n\ndef Q_Model_DLO : Model (DLO_theory) :=\n { M := Q_struc,\n   satis :=\n   begin\n     rintros \u03c3 (\u27e8_, _\u27e9 | x | _ | \u27e8_, _\u27e9 | \u27e8_, _\u27e9 | H);\n     use function.const \u2115 (42 : \u211a), -- 42 is just an arbitrary value\n     { rintros _ _ \u27e8_, _\u27e9, tauto},\n     { sorry },\n     { sorry },\n     { intros x,\n       use x+1,\n       split;\n         simp only [vector.map, list.map, vector.nth, vector.head,\n                    fin.val_one, term_interpretation, rat.le,\n                    function.update_same, list.nth_le];\n         norm_num;\n         try {ring};\n         dec_trivial},\n     { intros x,\n       use x-1,\n       split;\n         simp only [vector.map, list.map, vector.nth, vector.head,\n                    fin.val_one, term_interpretation, rat.le,\n                    function.update_same, list.nth_le];\n         norm_num;\n         try {ring};\n         dec_trivial},\n     repeat {sorry},\nend\n\n\n\n#exit\n\n\n\n/-- DLO is complete by using Vaught's test. This will include the\n    back-and-forth argument (Lou) which includes construct a sequence of\n    partial isomorphisms and then stitch it together to create a big\n    isomoprhism by zig-zagging back and forth over countable models of\n    DLO.-/\ntheorem DLO_is_complete : complete_theory DLO_theory := sorry\n\n\nend DLO_Model\n", "meta": {"author": "vaibhavkarve", "repo": "igl2020", "sha": "891c3c429f3b1ba85cf612940bff60738160787d", "save_path": "github-repos/lean/vaibhavkarve-igl2020", "path": "github-repos/lean/vaibhavkarve-igl2020/igl2020-891c3c429f3b1ba85cf612940bff60738160787d/src/examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7298603835423095}}
{"text": "/-\nLean's type hierarchy\n-/\n\nnamespace hidden1\n\nstructure box (\u03b1 : Type) : Type :=\n(val : \u03b1)\n\ndef b3 : box nat := box.mk 3  \n\n/-\nEvery term has a type. \nTypes are terms, too.\n\nThe type of 3 is \u2115.\n\u2115 is a type, so it has a type.\nThe type of \u2115 (#check) is Type.\n\nSo here's a picture so far.\n\n     Type (aka Type 0)        \n      /  |  \\ ..... \\\n  bool  nat string (box nat) ...\n  / \\    |    |        |  \n  tt ff  3   \"Hi!\" (box.mk 3)\n\nWe can pass 3 to box'.mk because\nits type, nat, \"belongs to\" Type.\n\nCan we pass nat to box'.mk?\n-/\n\ndef bn := box.mk nat    -- No!\n\n/-\nA picture tells us what went wrong.\n\n         ???\n          |\n        Type 0        (\u03b1 := Type : ???)\n        /  |  \\\n    bool nat string   (a := nat : Type)\n    / \\   |    |\n    tt ff  3   \"Hi!\"  \n\nAbove Type 0 is an infinite stack of \nhigher type universes, Type 1, Type 2,\netc. \n-/\n\n#check Type 0\n#check Type 1\n#check Type 2\n-- etc\n\n/-\nHere's the key idea. If a term \ncontains, or is parameterized by, \na value in Type u, where u is any \nnatural number, then it must live\n(at least) in Type (u+1).\n\n\nIn the our example, (a := nat : Type),\nso (\u03b1 := Type : Type 1)\n-/\n\nend hidden1\n\n\n/-\nWe've defined our identity functions \nto take (1) any type, \u03b1, of type Type,\nand (2) any value, a, of the type give \nas the value of \u03b1, and to return that \nsame value, a. \n\nKnowing that types are terms, too, \nthe clever student will try to apply\nour id functions to type-valued terms,\nsuch as nat or bool. Alas, that won't\nwork. \n-/\n\n#eval id6 nat       -- Nope!\n\n/-\nWhy? Let's analyze it. That's easier \nif we make the implicit type argument \nexplicit using an _. We'll use our id2 \nversion, which requires that the first, \ntype, argument (a value of type, Type)\nbe given explicitly. Let's start with\nan example that works.  \n-/\n\n#eval id2 nat 5\n\n/-\nHere 3 is value of type nat, and \nnat is a value of type Type. The \ntype argument to box has to be a\nvalue of type, Type (a shorthand\nfor Type 0), so nat will do fine, \nas would bool, string, box nat, etc.\n\n        Type 0 (Type)       \n        /  |  \\\n    bool nat string  (nat : Type) \n    / \\   |    |\n    tt ff  3   \"Hi!\"  (3 : nat)\n\nWhat does the picture look like with a = nat?\n\n          ???\n          |\n        Type 0        (\u03b1 := Type : ???)\n        /  |  \\\n    bool nat string  (a := nat : Type)\n    / \\   |    |\n    tt ff  3   \"Hi!\"  \n-/\n\n/-\n              ad inf\n                |\n              Type 2\n                |\n              Type 1\n                |\n              Type 0       (\u03b1 := Type : ???)\n             /  |  \\\n          bool nat string  (a := nat : Type)\n          / \\   |    |\n         tt ff  3   \"Hi!\"\n-/\n-- A \"sad\" solution is to change to (\u03b1 : Type 1)\n\ndef id7 {\u03b1 : Type 1} (a : \u03b1) : \u03b1 := a\n\n\n-- Okay, it works when applied to types in Type 0\n#reduce id7 nat   -- careful: nat is second argument!\n#eval id bool\n#eval id string\n\n-- But now it's broken for *values* of these types\n\n#eval id7 nat 5     -- hope for 5\n\n-- And for values in the next \"type universe\" up\n\n#eval id7 Type      -- hope for Type\n\n/-\nHere's the general picture.\n\n               ... ad inf.      -- Type 2 is type of Type 1, etc\n                |\n             Type 1             -- Type of Type 0\n                |\n              Type 0            -- Type of usual types\n             /  |  \\\n      ... bool nat string ...   -- usual types\n          / \\   |    |\n         tt ff  5   \"Hi!\"  ...  -- values of these types\n-/ \n\n/-\nSolution is to make definition \"polymorphic\" in \ntype universes.\n-/\n\n\n\nuniverse u   -- let u be an arbitrary universe level (0, 1, 2, etc)\n\n-- And let Lean infer u from context\n\ndef id {\u03b1 : Type u} (a : \u03b1) : \u03b1 := a\n\n#reduce id 5      -- 5    belongs to nat,     nat     belongs to Type\n#reduce id nat    -- nat  belongs to Type,    Type    belongs to Type 1\n#reduce id Type   -- Type belongs to Type 1,  Type 1  belongs to Type 2\n#reduce id (Type 10)  -- etc, ad infinitum\n\n-- Yay!\n\n/-\nWhy such complexity? It avoids certain inconsistencies.\n\nRussell's Paradox.\n\nConsider the set of all sets that do not contain themselves.\n\nDoes it contain itself?\nIf it doesn't contain itself then it must contain itself.\nIf it does contain itself then it mustn't contain itself.\nEither assumption leads to a contradiction, and inconsistency.\nRussell introduced stratified types to avoid this problem in set theory.\nThe hierarchy prevents any type from containing itself as a value.\n\nThe very concept of sets containing or not containing themselves\nhas to be excluded from consideration. Types that contain only \n\"lower\" types and never themselves solves the problem. Bertrand\nRussell is thus a great-great-granddaddy of this aspect of type\ntheory.\n\nWhat belongs in higher type universes in practice? It's pretty\nstraightforward. If an object *contains a value* of type, Type u, \nthen that object lives in (at least) Type u+1. Details later on.\n-/\n\n/-\nThis material about type universes is quite abstract, so please\ndon't worry if it's going over your head at this point. Graduate\nstudents should work hard to grasp it. For the most part I will\navoid defining types in full generality w.r.t. universe levels.\n-/\n\nend hidden", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/zzz_junk/03_typeUniverses.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160258, "lm_q2_score": 0.8333245973817159, "lm_q1q2_score": 0.7298148530137887}}
{"text": "import data.nat.gcd\n\nvariables x y z : \u2115\n\n#check dvd_mul_left\n#check dvd_mul_right\n#check @dvd_mul_of_dvd_left\n#check @dvd_mul_of_dvd_right\n\nexample (h\u2080 : x \u2223 y) (h\u2081 : y \u2223 z) : x \u2223 z :=\ndvd_trans h\u2080 h\u2081\n\nexample : x \u2223 y * x * z :=\nbegin\n  apply dvd_mul_of_dvd_left,\n  apply dvd_mul_left,\nend\n\nexample : x \u2223 x^2 :=\nby apply dvd_mul_right", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.1_apply/ex6_apply_dvd_trans_mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7298148439507393}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot, Casper Putz, Anne Baanen\n-/\nimport data.matrix.basic\nimport linear_algebra.finite_dimensional\n\n/-!\n# The finite-dimensional space of matrices\n\nThis file shows that `m` by `n` matrices form a finite-dimensional space,\nand proves the `finrank` of that space is equal to `card m * card n`.\n\n## Main definitions\n\n * `matrix.finite_dimensional`: matrices form a finite dimensional vector space over a field `K`\n * `matrix.finrank_matrix`: the `finrank` of `matrix m n R` is `card m * card n`\n\n## Tags\n\nmatrix, finite dimensional, findim, finrank\n\n-/\n\nuniverses u v\n\nnamespace matrix\n\nsection finite_dimensional\n\nvariables {m n : Type*} {R : Type v} [field R]\n\ninstance [finite m] [finite n] : finite_dimensional R (matrix m n R) :=\nlinear_equiv.finite_dimensional (linear_equiv.curry R m n)\n\n/--\nThe dimension of the space of finite dimensional matrices\nis the product of the number of rows and columns.\n-/\n@[simp] lemma finrank_matrix [fintype m] [fintype n] :\n  finite_dimensional.finrank R (matrix m n R) = fintype.card m * fintype.card n :=\nby rw [@linear_equiv.finrank_eq R (matrix m n R) _ _ _ _ _ _ (linear_equiv.curry R m n).symm,\n       finite_dimensional.finrank_fintype_fun_eq_card, fintype.card_prod]\n\nend finite_dimensional\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/finite_dimensional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479465, "lm_q2_score": 0.8333245973817159, "lm_q1q2_score": 0.7298148422071692}}
{"text": "import .love01_definitions_and_statements_demo\n\n\n/- # LoVe Demo 3: Forward Proofs\n\nWhen developing a proof, often it makes sense to work __forward__: to start with\nwhat we already know and proceed step by step towards our goal. Lean's\nstructured proofs and raw proof terms are two style that support forward\nreasoning. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace forward_proofs\n\n\n/- ## Structured Constructs\n\nStructured proofs are syntactic sugar sprinkled on top of Lean's\n__proof terms__.\n\nThe simplest kind of structured proof is the name of a lemma, possibly with\narguments. -/\n\nlemma add_comm (m n : \u2115) :\n  add m n = add n m :=\nsorry\n\nlemma add_comm_zero_left (n : \u2115) :\n  add 0 n = add n 0 :=\nadd_comm 0 n\n\nlemma add_comm_zero_left\u2082 (n : \u2115) :\n  add 0 n = add n 0 :=\nby exact add_comm 0 n\n\n/- `fix` and `assume` move `\u2200`-quantified variables and assumptions from the\ngoal into the local context. They can be seen as structured versions of the\n`intros` tactic.\n\n`show` repeats the goal to prove. It is useful as documentation or to rephrase\nthe goal (up to computation). -/\n\nlemma fst_of_two_props :\n  \u2200a b : Prop, a \u2192 b \u2192 a :=\nfix a b : Prop,\nassume ha : a,\nassume hb : b,\nshow a, from\n  ha\n\nlemma fst_of_two_props\u2082 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nshow a, from\n  begin\n    exact ha\n  end\n\nlemma fst_of_two_props\u2083 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nha\n\n/- `have` proves an intermediate lemma, which can refer to the local context. -/\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nhave hb : b :=\n  hab ha,\nhave hc : c :=\n  hbc hb,\nshow c, from\n  hc\n\nlemma prop_comp\u2082 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nshow c, from\n  hbc (hab ha)\n\n\n/- ## Forward Reasoning about Connectives and Quantifiers -/\n\nlemma and_swap (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nassume hab : a \u2227 b,\nhave ha : a :=\n  and.elim_left hab,\nhave hb : b :=\n  and.elim_right hab,\nshow b \u2227 a, from\n  and.intro hb ha\n\nlemma or_swap (a b : Prop) :\n  a \u2228 b \u2192 b \u2228 a :=\nassume hab : a \u2228 b,\nshow b \u2228 a, from\n  or.elim hab\n    (assume ha : a,\n     show b \u2228 a, from\n       or.intro_right b ha)\n    (assume hb : b,\n     show b \u2228 a, from\n       or.intro_left a hb)\n\ndef double (n : \u2115) : \u2115 :=\nn + n\n\nlemma nat_exists_double_iden :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0\n  (show double 0 = 0, from\n     by refl)\n\nlemma nat_exists_double_iden\u2082 :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0 (by refl)\n\nlemma modus_ponens (a b : Prop) :\n  (a \u2192 b) \u2192 a \u2192 b :=\nassume hab : a \u2192 b,\nassume ha : a,\nshow b, from\n  hab ha\n\nlemma not_not_intro (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nassume ha : a,\nassume hna : \u00ac a,\nshow false, from\n  hna ha\n\nlemma forall.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2200x, x = t \u2192 p x) \u2194 p t :=\niff.intro\n  (assume hall : \u2200x, x = t \u2192 p x,\n   show p t, from\n     begin\n       apply hall t,\n       refl\n     end)\n  (assume hp : p t,\n   fix x,\n   assume heq : x = t,\n   show p x, from\n     begin\n       rw heq,\n       exact hp\n     end)\n\nlemma beast_666 (beast : \u2115) :\n  (\u2200n, n = 666 \u2192 beast \u2265 n) \u2194 beast \u2265 666 :=\nforall.one_point _ _\n\n#print beast_666\n\nlemma exists.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2203x : \u03b1, x = t \u2227 p x) \u2194 p t :=\niff.intro\n  (assume hex : \u2203x, x = t \u2227 p x,\n   show p t, from\n     exists.elim hex\n       (fix x,\n        assume hand : x = t \u2227 p x,\n        show p t, from\n          by cc))\n  (assume hp : p t,\n   show \u2203x : \u03b1, x = t \u2227 p x, from\n     exists.intro t\n       (show t = t \u2227 p t, from\n          by cc))\n\n\n/- ## Calculational Proofs\n\nIn informal mathematics, we often use transitive chains of equalities,\ninequalities, or equivalences (e.g., `a \u2265 b \u2265 c`). In Lean, such calculational\nproofs are supported by `calc`.\n\nSyntax:\n\n    calc      _term\u2080_\n        _op\u2081_ _term\u2081_ :\n      _proof\u2081_\n    ... _op\u2082_ _term\u2082_ :\n      _proof\u2082_\n     \u22ee\n    ... _opN_ _termN_ :\n      _proofN_ -/\n\nlemma two_mul_example (m n : \u2115) :\n  2 * m + n = m + n + m :=\ncalc  2 * m + n\n    = (m + m) + n :\n  by rw two_mul\n... = m + n + m :\n  by cc\n\n/- `calc` saves some repetition, some `have` labels, and some transitive\nreasoning: -/\n\nlemma two_mul_example\u2082 (m n : \u2115) :\n  2 * m + n = m + n + m :=\nhave h\u2081 : 2 * m + n = (m + m) + n :=\n  by rw two_mul,\nhave h\u2082 : (m + m) + n = m + n + m :=\n  by cc,\nshow _, from\n  eq.trans h\u2081 h\u2082\n\n\n/- ## Forward Reasoning with Tactics\n\nThe `have`, `let`, and `calc` structured proof commands are also available as a\ntactic. Even in tactic mode, it can be useful to state intermediate results and\ndefinitions in a forward fashion.\n\nObserve that the syntax for the tactic `let` is slightly different than for the\nstructured proof command `let`, with `,` instead of `in`. -/\n\nlemma prop_comp\u2083 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  have hb : b :=\n    hab ha,\n  let c' := c,\n  have hc : c' :=\n    hbc hb,\n  exact hc\nend\n\n\n/- ## Dependent Types\n\nDependent types are the defining feature of the dependent type theory family of\nlogics.\n\nConsider a function `pick` that take a number `n : \u2115` and that returns a number\nbetween 0 and `n`. Conceptually, `pick` has a dependent type, namely\n\n    `(n : \u2115) \u2192 {i : \u2115 // i \u2264 n}`\n\nWe can think of this type as a `\u2115`-indexed family, where each member's type may\ndepend on the index:\n\n    `pick n : {i : \u2115 // i \u2264 n}`\n\nBut a type may also depend on another type, e.g., `list` (or `\u03bb\u03b1, list \u03b1`) and\n`\u03bb\u03b1, \u03b1 \u2192 \u03b1`.\n\nA term may depend on a type, e.g., `\u03bb\u03b1, \u03bbx : \u03b1, x` (a polymorphic identity\nfunction).\n\nOf course, a term may also depend on a term.\n\nUnless otherwise specified, a __dependent type__ means a type depending on a\nterm. This is what we mean when we say that simple type theory does not support\ndependent types.\n\nIn summary, there are four cases for `\u03bbx, t` in the calculus of inductive\nconstructions (cf. Barendregt's `\u03bb`-cube):\n\nBody (`t`) |              | Argument (`x`) | Description\n---------- | ------------ | -------------- | ------------------------------\nA term     | depending on | a term         | Simply typed `\u03bb`-expression\nA type     | depending on | a term         | Dependent type (strictly speaking)\nA term     | depending on | a type         | Polymorphic term\nA type     | depending on | a type         | Type constructor\n\nRevised typing rules:\n\n    C \u22a2 t : (x : \u03c3) \u2192 \u03c4[x]    C \u22a2 u : \u03c3\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    C \u22a2 t u : \u03c4[u]\n\n    C, x : \u03c3 \u22a2 t : \u03c4[x]\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    C \u22a2 (\u03bbx : \u03c3, t) : (x : \u03c3) \u2192 \u03c4[x]\n\nThese two rules degenerate to `App` and `Lam` if `x` does not occur in `\u03c4[x]`\n\nExample of `App'`:\n\n    \u22a2 pick : (x : \u2115) \u2192 {y : \u2115 // y \u2264 x}    \u22a2 5 : \u2115\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    \u22a2 pick 5 : {y : \u2115 // y \u2264 5}\n\nExample of `Lam'`:\n\n    \u03b1 : Type, x : \u03b1 \u22a2 x : \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam or Lam'\n    \u03b1 : Type \u22a2 (\u03bbx : \u03b1, x) : \u03b1 \u2192 \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    \u22a2 (\u03bb\u03b1 : Type, \u03bbx : \u03b1, x) : (\u03b1 : Type) \u2192 \u03b1 \u2192 \u03b1\n\nRegrettably, the intuitive syntax `(x : \u03c3) \u2192 \u03c4` is not available in Lean.\nInstead, we must write `\u2200x : \u03c3, \u03c4` to specify a dependent type.\n\nAliases:\n\n    `\u03c3 \u2192 \u03c4` := `\u2200_ : \u03c3, \u03c4`\n    `\u03a0`     := `\u2200`\n\n\n## The Curry\u2013Howard Correspondence\n\n`\u2192` is used both as the implication symbol and as the type constructor of\nfunctions. Similarly, `\u2200` is used both as a quantifier and in dependent types.\n\nThe two pairs of concepts not only look the same, they are the same, by the PAT\nprinciple:\n\n* PAT = propositions as types;\n* PAT = proofs as terms.\n\nThis is also called the Curry\u2013Howard correspondence.\n\nTypes:\n\n* `\u03c3 \u2192 \u03c4` is the type of total functions from `\u03c3` to `\u03c4`;\n* `\u2200x : \u03c3, \u03c4[x]` is the dependent function type from `x : \u03c3` to `\u03c4[x]`.\n\nPropositions:\n\n* `P \u2192 Q` can be read as \"`P` implies `Q`\", or as the type of functions mapping\n  proofs of `P` to proofs of `Q`.\n* `\u2200x : \u03c3, Q[x]` can be read as \"for all `x`, `Q[x]`\", or as the type of\n  functions mapping values `x` of type `\u03c3` to proofs of `Q[x]`.\n\nTerms:\n\n* A constant is a term.\n* A variable is a term.\n* `t u` is the application of function `t` to value `u`.\n* `\u03bbx, t[x]` is a function mapping `x` to `t[x]`.\n\nProofs:\n\n* A lemma or hypothesis name is a proof.\n* `H t`, which instantiates the leading parameter or quantifier of proof `H`'\n  statement with term `t`, is a proof.\n* `H G`, which discharges the leading assumption of `H`'s statement with\n  proof `G`, is a proof.\n* `\u03bbh : P, H[h]` is a proof of `P \u2192 Q`, assuming `H[h]` is a proof of `Q`\n  for `h : P`.\n* `\u03bbx : \u03c3, H[x]` is a proof of `\u2200x : \u03c3, Q[x]`, assuming `H[x]` is a proof of\n  `Q[x]` for `x : \u03c3`. -/\n\nlemma and_swap\u2083 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\n\u03bbhab : a \u2227 b, and.intro (and.elim_right hab) (and.elim_left hab)\n\nlemma and_swap\u2084 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intro hab,\n  apply and.intro,\n  apply and.elim_right,\n  exact hab,\n  apply and.elim_left,\n  exact hab\nend\n\n/- Tactical proofs are reduced to proof terms. -/\n\n#print and_swap\u2083\n#print and_swap\u2084\n\nend forward_proofs\n\n\n/- ## Induction by Pattern Matching\n\nBy the Curry\u2013Howard correspondence, a proof by induction is the same as a\nrecursively specified proof term. Thus, as alternative to the `induction'`\ntactic, induction can also be done by pattern matching:\n\n * the induction hypothesis is then available under the name of the lemma we are\n   proving;\n\n * well-foundedness of the argument is often proved automatically. -/\n\n#check reverse\n\nlemma reverse_append {\u03b1 : Type} :\n  \u2200xs ys : list \u03b1, reverse (xs ++ ys) = reverse ys ++ reverse xs\n| []        ys := by simp [reverse]\n| (x :: xs) ys := by simp [reverse, reverse_append xs]\n\nlemma reverse_append\u2082 {\u03b1 : Type} (xs ys : list \u03b1) :\n  reverse (xs ++ ys) = reverse ys ++ reverse xs :=\nbegin\n  induction' xs,\n  { simp [reverse] },\n  { simp [reverse, ih] }\nend\n\nlemma reverse_reverse {\u03b1 : Type} :\n  \u2200xs : list \u03b1, reverse (reverse xs) = xs\n| []        := by refl\n| (x :: xs) :=\n  by simp [reverse, reverse_append, reverse_reverse xs]\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love03_forward_proofs_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7298148421726495}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# Finite sets\n\nRemember that mathematicians use \"set\" in two different ways. There is\nthe generic \"collection of stuff\" usage, as in \"A group is a set equipped with\na multiplication and satisfying these axioms...\", for which Lean uses types.\nAnd there's the concept of a *subset*, so we have the collection of stuff\nalready and want to consider the elements which have some other properties,\nfor example the subset {1,2,3,4,...,37} of the natural numbers, or the\nsubset of prime numbers or even numbers or whatever.\n\nSomeone on the Discord asked if I would do something about \"finite sets\",\nand because there are two uses of the idea of a set in mathematics, the\nfirst question on my mind is \"which kind of finite set?\". It seems to me\nthat the student is interested in finite *subsets* of the naturals and\nthe reals, so let's talk first about finite subsets.\n\n## Two ways to do finite subsets of a type `X`\n\n### First way: a subset of `X`, which is finite\n\nLet `X` be a type. We've already seen the type `set X` of subsets of `X`,\nso one way to let `S` be a finite subset of `X` would be to make a term\n`S : set X` and then to have a hypothesis that `S` is finite. \nIn Lean the predicate which says a set is finite is `set.finite`. So here\nis one way of saying \"let `S` be a finite subset of `X`\":\n\n-/\n\n-- \"Let X be a type, let `S` be a subset of `X`, and assume `S` is finite.\n-- Then S = S\"\nexample (X : Type) (S : set X) (T : set X)\n  (hs : set.finite S) (ht : T.finite) : (S \u222a T).finite := \nbegin \n  exact hs.union ht, -- set.finite.union\nend\n\n/-\n\nBut Lean has another way. \n\n### Second way: the type of all finite subsets of X\n\nLean has a dedicated type whose terms are finite subsets of `X`. It's called `finset X`.\n\nClearly, for a general infinite type `X`, `set X` and `finset X` are not \"the same\".\nIn type theory, *distinct types are disjoint*. That means if we have a term `S : finset X`\nthen *`S` does not have type `set X`*. A finset is not *equal to* a set. This is the\nsame phenomenon which says that a natural number in Lean is not *equal to* a real number. \nThere is a *map* from the natural numbers to the real numbers, and it's a map which\nmathematicians don't notice and so it's called a *coercion* and is represented by a little\nup-arrow. The same is true here.\n\nIf `S : finset X` then you can coerce `S` to `set X`, and this coerced term will be \ndisplayed as `\u2191S` in Lean, with this arrow meaning \"the obvious map from `finset X` to `set X`\".\n\n-/\n\n-- let X be a type\nvariable (X : Type)\n\nexample (S : finset X) : (S : set X) = (S : set X) :=\nbegin\n  -- \u22a2 \u2191S = \u2191S\n  refl,\nend\n\n-- Lean has the theorem that if you start with a finset, then the coerced set is finite.\nexample (S : finset X) : set.finite (S : set X) :=\nbegin\n  exact set.to_finite S,\nend\n\n/-\n\n# Why?\n\nFinite sets are really important in computer science, and they also play a special role in\nmathematics: for example you can sum over a finite set in huge generality, whereas if you\nwant to sum over a general set then you need some metric or topology on the target to make\nsense of the notion of convergence. Also finite sets can be handled in constructive mathematics\nand the theory is much easier to make computable than a general theory of sets. I'm not\nparticularly interested in making mathematics more constructive and computable, but other\npeople are, and this is why we've ended up with a dedicated type for finite sets.\n\nLet's see how to do finite sums in Lean. In mathematics we often sum from 1 to n, but\ncomputer scientists seem to prefer to sum from 0 to n-1. The finset `{0,1,2,...,n-1} : finset \u2115`\nhas got a name; it's called `finset.range n`. Let's see it in action by proving that\nthe sum of i^2 from i=0 to n-1 is (some random cubic with 6 in the denominator).\n\n-/\n\nopen_locale big_operators -- enable \u2211 notation\n\nexample (n : \u2115) : \u2211 i in finset.range n, \n  (i : \u211a)^2 = n * (n - 1) * (2 * n - 1) / 6 :=\nbegin\n  induction n with d hd,\n  { -- base case n = 0 will follow by rewriting lemmas such as `\u2211 i in finset.range 0 f(i) = 0`\n    -- and `0 * x = 0` etc, and the simplifier knows all these things.\n    simp },\n  { -- inductive step\n    -- We're summing to `finset.range succ(d)`, and so we next use the lemma saying\n    -- that equals the sum over `finset.range d`, plus the last term.\n    rw finset.sum_range_succ,\n    -- Now we have a sum over finset.range d, which we know the answer to by induction\n    rw hd,\n    -- Now tidy up (e.g. replace all the `succ d` with `d + 1`)\n    simp,\n    -- and now it must be an identity in algebra.\n    ring,\n  }\nend\n\n-- If you look through the proof you'll see some \u2191; this is because we can't do the\n-- algebra calculation in the naturals because subtraction and division are involved,\n-- and the definitions of subtraction and division on the naturals in Lean are *pathological*\n-- (for example 4 - 5 = 0 and 5 / 2 = 2, because they have to return naturals, so they have to\n-- return the wrong answer). So we coerce everything to the rationals first, and then the\n-- problem goes away.\n\n-- See if you can can sum the first n cubes. \nexample (n : \u2115) : \u2211 i in finset.range n, (i : \u211a)^3 = n^2 * (n - 1)^2 / 4 :=\nbegin\n  -- same proof works\n  induction n with d hd,\n  { simp },\n  { simp [finset.sum_range_succ, hd],\n    ring, },\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section08finiteness/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7298148385474298}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.group.defs\nimport Mathlib.logic.nontrivial\nimport Mathlib.PostPort\n\nuniverses u_4 l u_1 u \n\nnamespace Mathlib\n\n/-!\n# Typeclasses for groups with an adjoined zero element\n\nThis file provides just the typeclass definitions, and the projection lemmas that expose their\nmembers.\n\n## Main definitions\n\n* `group_with_zero`\n* `comm_group_with_zero`\n-/\n\n-- We have to fix the universe of `G\u2080` here, since the default argument to\n\n-- `group_with_zero.div'` cannot contain a universe metavariable.\n\n/-- Typeclass for expressing that a type `M\u2080` with multiplication and a zero satisfies\n`0 * a = 0` and `a * 0 = 0` for all `a : M\u2080`. -/\nclass mul_zero_class (M\u2080 : Type u_4) \nextends Mul M\u2080, HasZero M\u2080\nwhere\n  zero_mul : \u2200 (a : M\u2080), 0 * a = 0\n  mul_zero : \u2200 (a : M\u2080), a * 0 = 0\n\n@[simp] theorem zero_mul {M\u2080 : Type u_1} [mul_zero_class M\u2080] (a : M\u2080) : 0 * a = 0 :=\n  mul_zero_class.zero_mul a\n\n@[simp] theorem mul_zero {M\u2080 : Type u_1} [mul_zero_class M\u2080] (a : M\u2080) : a * 0 = 0 :=\n  mul_zero_class.mul_zero a\n\n/-- Predicate typeclass for expressing that `a * b = 0` implies `a = 0` or `b = 0`\nfor all `a` and `b` of type `G\u2080`. -/\nclass no_zero_divisors (M\u2080 : Type u_4) [Mul M\u2080] [HasZero M\u2080] \nwhere\n  eq_zero_or_eq_zero_of_mul_eq_zero : \u2200 {a b : M\u2080}, a * b = 0 \u2192 a = 0 \u2228 b = 0\n\n/-- A type `M` is a \u201cmonoid with zero\u201d if it is a monoid with zero element, and `0` is left\nand right absorbing. -/\nclass monoid_with_zero (M\u2080 : Type u_4) \nextends mul_zero_class M\u2080, monoid M\u2080\nwhere\n\n/-- A type `M` is a `cancel_monoid_with_zero` if it is a monoid with zero element, `0` is left\nand right absorbing, and left/right multiplication by a non-zero element is injective. -/\nclass cancel_monoid_with_zero (M\u2080 : Type u_4) \nextends monoid_with_zero M\u2080\nwhere\n  mul_left_cancel_of_ne_zero : \u2200 {a b c : M\u2080}, a \u2260 0 \u2192 a * b = a * c \u2192 b = c\n  mul_right_cancel_of_ne_zero : \u2200 {a b c : M\u2080}, b \u2260 0 \u2192 a * b = c * b \u2192 a = c\n\ntheorem mul_left_cancel' {M\u2080 : Type u_1} [cancel_monoid_with_zero M\u2080] {a : M\u2080} {b : M\u2080} {c : M\u2080} (ha : a \u2260 0) (h : a * b = a * c) : b = c :=\n  cancel_monoid_with_zero.mul_left_cancel_of_ne_zero ha h\n\ntheorem mul_right_cancel' {M\u2080 : Type u_1} [cancel_monoid_with_zero M\u2080] {a : M\u2080} {b : M\u2080} {c : M\u2080} (hb : b \u2260 0) (h : a * b = c * b) : a = c :=\n  cancel_monoid_with_zero.mul_right_cancel_of_ne_zero hb h\n\n/-- A type `M` is a commutative \u201cmonoid with zero\u201d if it is a commutative monoid with zero\nelement, and `0` is left and right absorbing. -/\nclass comm_monoid_with_zero (M\u2080 : Type u_4) \nextends comm_monoid M\u2080, monoid_with_zero M\u2080\nwhere\n\n/-- A type `M` is a `comm_cancel_monoid_with_zero` if it is a commutative monoid with zero element,\n `0` is left and right absorbing,\n  and left/right multiplication by a non-zero element is injective. -/\nclass comm_cancel_monoid_with_zero (M\u2080 : Type u_4) \nextends comm_monoid_with_zero M\u2080, cancel_monoid_with_zero M\u2080\nwhere\n\n/-- A type `G\u2080` is a \u201cgroup with zero\u201d if it is a monoid with zero element (distinct from `1`)\nsuch that every nonzero element is invertible.\nThe type is required to come with an \u201cinverse\u201d function, and the inverse of `0` must be `0`.\n\nExamples include division rings and the ordered monoids that are the\ntarget of valuations in general valuation theory.-/\nclass group_with_zero (G\u2080 : Type u) \nextends div_inv_monoid G\u2080, nontrivial G\u2080, monoid_with_zero G\u2080\nwhere\n  inv_zero : 0\u207b\u00b9 = 0\n  mul_inv_cancel : \u2200 (a : G\u2080), a \u2260 0 \u2192 a * (a\u207b\u00b9) = 1\n\n@[simp] theorem inv_zero {G\u2080 : Type u} [group_with_zero G\u2080] : 0\u207b\u00b9 = 0 :=\n  group_with_zero.inv_zero\n\n@[simp] theorem mul_inv_cancel {G\u2080 : Type u} [group_with_zero G\u2080] {a : G\u2080} (h : a \u2260 0) : a * (a\u207b\u00b9) = 1 :=\n  group_with_zero.mul_inv_cancel a h\n\n/-- A type `G\u2080` is a commutative \u201cgroup with zero\u201d\nif it is a commutative monoid with zero element (distinct from `1`)\nsuch that every nonzero element is invertible.\nThe type is required to come with an \u201cinverse\u201d function, and the inverse of `0` must be `0`. -/\nclass comm_group_with_zero (G\u2080 : Type u_4) \nextends comm_monoid_with_zero G\u2080, group_with_zero G\u2080\nwhere\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/group_with_zero/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8333245953120234, "lm_q1q2_score": 0.7298148376929046}}
{"text": "namespace inner\n  constant and   : Prop \u2192 Prop \u2192 Prop\n  constant or    : Prop \u2192 Prop \u2192 Prop\n  constant not   : Prop \u2192 Prop\n  constant implies : Prop \u2192 Prop \u2192 Prop\n\n  variables p q r : Prop\n  -- #check and p q -- Prop\n  -- #check or (and p q) r -- Prop\n  -- #check implies (and p q) (and q p) -- Prop\n\n  constant Proof : Prop \u2192 Type\n  constant and_comm : \u03a0 p q : Prop,\n    Proof (implies (and p q) (and q p))\n\n  -- #check and_comm p q -- Proof (implies (and p q) (and q p))\n  constant modus_ponens :\n    \u03a0 p q : Prop, Proof (implies p q) \u2192 Proof p \u2192 Proof q\n  constant implies_intro :\n    \u03a0 p q : Prop, (Proof p \u2192 Proof q) \u2192 Proof (implies p q)\n\nend inner\n\nconstants p q : Prop\n\n-- theorem t1 : p \u2192 q \u2192 p := \n-- assume hp : p,\n-- assume hq : q,\n-- show p, from hp\n\ntheorem t1' (hp : p) (hq : q) : p := hp\n\naxiom hp : p\n-- theorem t2 : q \u2192 p := t1 hp\n\ntheorem t1 : \u2200 (p q : Prop), p \u2192 q \u2192 p :=\n\u03bb (p q : Prop) (hp : p) (hq : q), hp\n\nvariables p q r s : Prop\n-- variable h : r \u2192 s\n\ntheorem t2 (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q) : p \u2192 r :=\nassume h\u2083 : p,\nshow r, from h\u2081 (h\u2082 h\u2083)\n\n#check p \u2192 q \u2192 p \u2227 q\n#check \u00acp \u2192 p \u2194 false\n#check p \u2228 q \u2192 q \u2228 p\n\nexample (hp : p) (hq : q) : p \u2227 q := and.intro hp hq\n\n#check assume (hp : p) (hq : q), and.intro hp hq\nexample (h : p \u2227 q) : p := and.elim_left h\nexample (h : p \u2227 q) : q := and.elim_right h\n\nexample (h : p \u2227 q) : q \u2227 p := and.intro (and.right h) (and.left h)\n\nexample (h : p \u2227 q) : q \u2227 p := \u27e8h.right, h.left\u27e9\n\nexample (hp : p) : p \u2228 q := or.intro_left q hp\nexample (hq : q) : p \u2228 q := or.intro_right p hq\n\nexample (h : p \u2228 q) : q \u2228 p :=\nh.elim\n(assume hp : p, or.inr hp)\n(assume hq : q, or.inl hq)\n\nexample (hpq : p \u2192 q) (hnq : \u00acq) : \u00acp :=\n  assume hp : p,\n  show false, from hnq (hpq hp)\n\nexample (hp : p) (hnp : \u00acp) : q := false.elim (hnp hp)\nexample (hp : p) (hnp : \u00acp) : q := absurd hp hnp\n\nexample (hnp : \u00acp) (hq : q) (hqp : q \u2192 p) : r := absurd (hqp hq) hnp\n\ntheorem and_swap : p \u2227 q \u2194 q \u2227 p :=\niff.intro\n  (assume h : p \u2227 q,\n    show q \u2227 p, from and.intro (and.right h) (and.left h))\n  (assume h : q \u2227 p,\n    show p \u2227 q, from and.intro (and.right h) (and.left h))\n\nvariable h : p \u2227 q\nexample : q \u2227 p := iff.mp (and_swap p q) h\n\ntheorem and_swap' : p \u2227 q \u2194 q \u2227 p :=\n  \u27e8 \u03bb h, \u27e8h.right, h.left\u27e9, \u03bb h, \u27e8h.right, h.left\u27e9 \u27e9\n  \n#check and_swap'", "meta": {"author": "esclear", "repo": "Learning-Lean", "sha": "d81d5c4743b94c96d8f1bb135e1f13a1d99b3154", "save_path": "github-repos/lean/esclear-Learning-Lean", "path": "github-repos/lean/esclear-Learning-Lean/Learning-Lean-d81d5c4743b94c96d8f1bb135e1f13a1d99b3154/chapter_3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.72977809794806}}
{"text": "/-\n0. Read the class notes through Section \n3.7, Implication. It is important that \nyou do this before classes next week, as\nwe will move somewhat quickly through a\nfew of these chapters.\n\nTo complete the rest of this homework,\nsolve the problems given as specified,\nthen save and submit this file.\n-/\n\n\n/-\n1. \n\nShow that if you're given proofs\nof a = b and c = b you can construct\na proof of a = c. Do it by completing\nthe following function. Note that we\ncan use parenthesis to enclose terms \nthat appear within larger terms. This\nis often necessary to make sure that\nLean understands how you want to group\nthings. \n-/\n\ntheorem eq_snart { T : Type}\n             { a b c: T }\n             (ab: a = b)\n             (cb: c = b) : \n             a = c :=\neq.trans\n    ab\n    (_)\n\n/-\nNow, given the following assumptions, apply\nyour newly proved inference rule, eq.snart,\nto show that Harry = Bob. Yes: Once you've\nproved a theorem, you can apply it as if it\nwere a function, to arguments of the right\ntypes, to get a proof that you need. Try it.\n-/\n\naxiom Person : Type\naxioms Harry Bob Jose: Person\naxioms (hj : Harry = Bob) (jb : Jose = Bob)\nexample : Harry = Jose := _\n\n/-\n2. Use example to assert and then prove that if\na, b, c, and d are nats, and if you have proofs\nof a = b, b = c, and c = d, you can construct a\nproof of a = d. Put the proof in the placeholder\nbelow.\n\nHint: Equality propositions are types. Think of\nthe problem here as one of producing a function\nof the specific type. Use lambdas. We've gotten\nyou started. The first lambda \"assumes\" that a,\nb, c, and d are natural numbers. What's left to\ndo is to prove a function (yes, start with lambda)\nthat takes three arguments of the specified kinds \n(use lambda to give them names) and that finally\nproduces a result of the type at the end of the \nchain.\n-/\n\ntheorem transit : \n\u2200 a b c d : \u2115, \n    (a = b) \u2192 (b = c) \u2192 (c = d) \u2192 (a = d) \n:= \n    \u03bb a b c d,\n        _\n\n/-\n3. In the context of the axioms in the following\nnamespace, write an exact proof term to prove \nthat Yuanfang is friendly. Hint #1: Just apply \nthe relevant inference rule as a function to the\nright arguments. Hint #2: The direction in which\nan equality is written matters. If, for example,\nyou have a proof of x = y and you want to apply \nan inference rule that requires a proof of y = x,\nthen you need to find a way to get what you need\nfrom what you have to work with in your context.\n-/\n\naxioms Mary Yuanfang : Person\naxiom Friendly : Person \u2192 Prop\naxiom mf : Friendly Mary\naxiom yeqm : Yuanfang = Mary\nexample : Friendly Yuanfang :=\n    _\n\n\n/-\n4. The subtitution rule for equality lets\nyou rewrite proof goals by substituting one \nterm for another, in a goal, as long as you \nalready have a proof that the two  terms \nare equal. The reasoning is that replacing \none term with another makes no difference to \nthe truth of a proposition if the two terms\nare equal. \n\nSuppose for example that you have a proof, \nh, of y = x (yes we can and do give names \nto proofs, as we consider them to be values), \nand a proof, y1, of y = 1, and that your \ngoal is to prove (x = 1). You can justify \nrewriting this goal as (y = 1), for which \nyou already have a proof, because you know \nthat y = x; so making this substitution \ndoesn't change the truth of the proposition. \n\nIn the tactic scripting libraries that Lean\nprovides, there is a tactic for rewriting a \ngoal in this way. If h is a proof of x = y,\nthen the tactic, \"rw h\" (\"rw\" is short for \n\"rewrite\") replaces all occurrences of x (the \nleft side of h) with y (it's right side).\n\nHere's an example.\n-/\n\ndef foo (x y : \u2115) (y1 : y = 1) (h: x = y) : (x = 1) :=\nbegin\nrewrite h,\nexact y1,\nend\n\n\n/-\nUse what you just learned to state and prove \nthe proposition that for any type, T, and for \nany objects, a, b, and c, of this type, if \n(a = b) and (b = c) then (c = a). Do this by\nfinishing off the tactic script that follows.  \nNote that to apply an inference rule within a\ntactic script you use the \"apply\" tactic. Read \nthe further explanation and hint that follow \nbefore attempting to solve this problem.\n-/\n\ndef ac (T : Type) (a b c : T) \n       (ab : a = b) (bc : b = c) \n    : (c = a) := \nbegin\n_\nend\n\n/-\nNote that the \"foralls\" in the natural language \nstatement are represented in this code *not* by \nusing  \u2200 but by declaring them to be arguments \nto our function. If you can write a function of \nthe specified type then you have in effect proven\nthat for *any* T and any a, b, c, of type T, if \nif you also have a proof of a=b and a proof of \nb=c, then a value of type c=a can be constructed \nand returned. The reason this is true is that in\nLean all functions are total, as you now recall!\n\nKey hint: The tactic application \"rw h\" changes\nall occurrences of the left side of the equality\nh, in the goal, into what's on its right side. \nIf you want the rewriting to go from right to \nleft, use \"rw<-h\". When you're just about done, \ndon't be surprised if the rewrite tactic applies \nrfl automatically.\n-/", "meta": {"author": "kevinsullivan", "repo": "uva-cs-dm-s19", "sha": "3e7177682acdb56a2d16914e0344c10335583dcf", "save_path": "github-repos/lean/kevinsullivan-uva-cs-dm-s19", "path": "github-repos/lean/kevinsullivan-uva-cs-dm-s19/uva-cs-dm-s19-3e7177682acdb56a2d16914e0344c10335583dcf/hw/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.8031738057795402, "lm_q1q2_score": 0.7297780883165111}}
{"text": "import Sudoku.Utils\nnamespace Sudoku\n\n\n/-\nHeight and width\n-/\nvariable {h w : Nat}\n\n/-\nA Sudoku board not validated\n-/\ndef Board (h w : Nat) (ax : h \u2265 1 \u2227 w \u2265 1) : Type :=\n  let size := h * w\n  { arr : Array (Option $ BNat 1 size (one_le_size ax)) // arr.size = size * size }\n\n@[simp] theorem board_size {ax : h \u2265 1 \u2227 w \u2265 1} (b : Board h w ax) : b.val.size = h * h * w * w := by\n  rw [b.property, Nat.mul_assoc, Nat.mul_comm w (h * w), \u2190Nat.mul_assoc, \u2190Nat.mul_assoc]\n\n\n@[simp] theorem board_size_ge_one {ax : h \u2265 1 \u2227 w \u2265 1} (b : Board h w ax) : b.val.size \u2265 1 := by\n  rw [board_size];\n  have hh := mul_ge_one_of_ge_one ax.1 ax.1\n  have ww := mul_ge_one_of_ge_one ax.2 ax.2\n  rw [Nat.mul_assoc]\n  exact mul_ge_one_of_ge_one hh ww\n\n/-\nGet an element in a matrix 1-indexed manner. E.g. the upper left corner is (1,1)\nand the rest of the corners are lower left (h * w, 1), upper\n-/\ndef get {ax : h \u2265 1 \u2227 w \u2265 1} (b : Board h w ax) (i j : BNat 1 b.val.size (board_size_ge_one b)) : Option $ BNat 1 b.val.size (board_size_ge_one b) :=\n  let size := h * w\n  b.val.get \u27e8(i.val - 1) * size + j.val - 1, by\n    simp\n    decide\n    --rw [Nat.mul_comm]\n    apply i.property\n    apply j.property\n  \u27e9\n\ndef getCell {ax : h \u2265 1 \u2227 w \u2265 1} (b : Board h w ax) (i : BNat 1 w (by apply ax.right)) (j : BNat 1 h (by apply ax.left)) : Slices <| Option <| Element h w :=\n  slice b.val #[(\u27e8(i.val-1)*h, by simp\u27e9, \u27e8(j.val-1)*w, by simp; rw [Nat.add_mul j.val 1 w, Nat.sub_le]; apply j.isLe\u27e9)] \n\ndef getRow {ax : h \u2265 1 \u2227 w \u2265 1} (b : Board h w ax) (r : BNat 1 (w*h) (by apply ax.right)) : Slices <| Option <| Element h w :=\n  slice b.val #[(\u27e8(i.val-1)*h, by simp\u27e9, \u27e8(j.val-1)*w, by simp; rw [Nat.add_mul j.val 1 w, Nat.sub_le]; apply j.isLe\u27e9)] \n--#eval ([1:3])\n\ndef validate {ax : h \u2265 1 \u2227 w \u2265 1} (s : Board h w ax) : Except String Unit := do\n  -- cells\n  for r in 1 h do\n    for c in [1:w] do\n      let cell := getCell b r c\n      if not (unique cell) then\n        error s!\"not unique\"\n  -- rows\n  for r in [1:h*w] do\n    let row := getRow b r\n    if not (unique row) then\n      error s!\"not unique\"\n  -- columns\n  for c in [1:h*w] do\n    let col := getColumn b c\n    if not (unique col) then\n      error s!\"not unique\"\n\n", "meta": {"author": "lurk-lab", "repo": "Sudoku.lean", "sha": "6295c13e70037e2bfa939c35fd072d2a98c0d23a", "save_path": "github-repos/lean/lurk-lab-Sudoku.lean", "path": "github-repos/lean/lurk-lab-Sudoku.lean/Sudoku.lean-6295c13e70037e2bfa939c35fd072d2a98c0d23a/src/Sudoku.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.7297780814365745}}
{"text": "-- This is an example of how to construct the natural numbers in lean,\n-- and how to build up results on them from the most basic of logical\n-- postulates.\n--\n-- As part of lean's built in logic engine I have access to the following\n-- operations and axioms:\n--\n-- Propositions:\n--   any proposition has type Prop,\n--   any proposiyion p is itself a type\n--   a member of the type p is a proof of p\n--\n-- Implication:\n--   given propositions p and q, (p \u2192 q) is also a proposition\n--   given a proof hp: p, and a proof hpq: p \u2192 q then (hpq hp) is a proof\n--   of q\n--\n-- Or:\n--   given propositions p,q, (p \u2228 q) is also a proposition\n--   given a proof hp of p, (or.intro_left q hp) is a proof of (p \u2228 q)\n--   given a proof hq of q, (or.intro_right p hq) is a proof of (p \u2228 q)\n--   given a proof hpq of (p \u2228 q), a proof hpr of (p \u2192 r) and a proof hqr\n--     of (q \u2192 r) then (or.elim hpq hpr hqr) is a proof of ((p \u2228 q) \u2192 r)\n--\n-- And:\n--   given propositions p,q, (p \u2227 q) is also a proposition\n--   given a proof hp of p, and a proof hq or q, (and.intro hp hq) is a proof\n--     of (p \u2227 q)\n--   given a proof hpq of (p \u2227 q), (and.elim_left hpq) is a proof of p\n--   given a proof hpq of (p \u2227 q), (and.elim_right hpq) is a proof of q\n--\n-- Not:\n--   given a proposition p, \u00acp is shorthand for the proposition (p \u2192 false)\n--   given a proof hp of p and a proof hnp of \u00acp, (absurd hp hnp) is a proof of any proposition\n--   given propositions p and q and a proof h of p \u2192 q, (mt h) is a proof of \u00acq \u2192 \u00acp\n--\n-- Exists:\n--   given a type \u03b1, and a function p: \u03b1 \u2192 Prop, (\u2203 x : \u03b1, p x) is a proposition\n--   given an entity x of type \u03b1 and a proof hpx of p x, \u27e8x, hpx\u27e9 is a proof of\n--     (\u2203 x : \u03b1, p x)\n--   given a proof hxp of (\u2203 x : \u03b1, p x) we can bind hxp to get x:\u03b1 and a proof of p x\n--\n-- Forall:\n--   given a type \u03b1 and a function p: \u03b1 \u2192 Prop, (\u2200 x : \u03b1, p x) is a proposition\n--   a proof of (\u2200 x : \u03b1, p x) is a function hxpx: (\u03b1 \u2192 p x) (ie. a function that\n--     maps any element x of \u03b1 to a proof of p x)\n--\n-- Assume:\n--   given propositions p, q, (assume hp:p, hq) is a proof of p \u2192 q provided that hq is a\n--     proof of q, which may include references to hp in its definition.\n--\n-- inductive:\n--   We can define a type inductively by definining a number of specific constructors that\n--     may or may not themselves take parameters. Any instance of the type must have been\n--     constructed using one of the constructors, and if the comnstructor takes parameters\n--     then the unique combination of constructor and parameter values is considered to define\n--     the element\n--   All inductive constructors are injective, so given a proof h: con x = con y we then\n--     injection h is a proof that x = y\n--   Given any inductive type \u03b1 and a proof h that two elements constructed using different\n--     constructors are equal (\u03b1.no_confusion h) is a proof of false\n--\n-- rec_on:\n--   given any inductive type \u03b1 we may use the function \u03b1.rec_on which takes a number of\n--     parameters one greater than the number of constructors \u03b1 has. The first parameter\n--     is of type \u03b1, the remaining are each of the same type as the constructor they correspond\n--     to in order (eg. if a constructor takes no pareters then its corresponding parameter here\n--     is of type \u03b1, whilst if it takes one then it is a function returnimng \u03b1, etc ...)\n--     the value of a call to rec_on is then the same as a call to the parameter corresponding to\n--     the constructor that constructed the input value with the same parameters as were passed\n--     to the constructor.\n--\n-- equality:\n--   for any type \u03b1 the operator = is already defined, and (a = b) is a proposition.axioms\n--   for any type \u03b1 and any element x : \u03b1, rfl is a proof of (x = x).\n--   for any type \u03b1 and any elements x, y: \u03b1, eq.sym is a proof of (x = y \u2192 y = x)\n--   for any type \u03b1, elements x y : \u03b1, and function p : \u03b1 \u2192 Prop if hxy is a proof that x = y,\n--     and hpx is a proof of p x then (eq.subst hxy hpx) is a proof of p y\n--   for any type \u03b1, elements x y : \u03b1, and function p : \u03b1 \u2192 Prop if hxy is a proof that x = y,\n--     then (congr.arg p hxy) is a proof that (p x = p y)\n\n\n-- We begin by defining a new type, natural. (nat is the builtin type, so we want a different\n-- name)\ninductive natural : Type\n| zero : natural\n| succ : natural \u2192 natural\n\nnotation `\ud835\udc0d` := natural\n\nnamespace natural\n\nopen natural\n\ninstance natural_has_zero : has_zero \ud835\udc0d := \u27e8zero\u27e9\ninstance natural_has_one : has_one \ud835\udc0d := \u27e8succ zero\u27e9\n\n-- equality is already defined for all types, and includes some of the properties we want for\n-- peano's axioms, so I'll quickly prove them.\nlemma eq_refl (n : \ud835\udc0d): n = n := rfl\nlemma eq_sym (x y : \ud835\udc0d): x = y \u2192 y = x := eq.symm\nlemma eq_trans (x y z : \ud835\udc0d) (h1: x = y) (h2: y = z): (x = z) := eq.trans \u2039x = y\u203a \u2039y = z\u203a\n-- Peano's 5th is implicit in how = is defined\n\nlemma succ_inj {x y : \ud835\udc0d}: x = y \u2194 succ x = succ y :=\n    iff.intro (\n        assume :x = y,\n        congr_arg succ \u2039x = y\u203a\n    ) (\n        assume h: succ x = succ y,\n        show x = y, by injection h\n    )\n\nlemma zero_not_succ  (x : \ud835\udc0d):  (succ x \u2260 0) :=\n    assume h,\n    natural.no_confusion h\n\n\n-- Now we define addition\n-- I originally defined addition the other way round with the first\n-- parameter as 0 or succ a, but this is unfortunate. If you do it\n-- this way round then (a + 1) = a + succ 0 = succ a + 0 = succ a is\n-- definitional, and so can be used in unfolding future definitions\ndef add : \ud835\udc0d \u2192 \ud835\udc0d \u2192 \ud835\udc0d\n    | a  0        := a\n    | a  (succ b) := succ (add a b)\n\ninstance natural_has_add : has_add \ud835\udc0d := \u27e8add\u27e9\n\n-- And prove some standard additive properties\nlemma zero_add_ (x : \ud835\udc0d): 0 + x = x :=\n    natural.rec_on x (\n        show (0 : \ud835\udc0d) + 0 = 0, by refl\n    ) (\n        assume n: \ud835\udc0d,\n        assume h: 0 + n = n,\n        calc\n            0 + succ n = succ (0 + n) : by refl\n            ...        = succ n       : by rw h\n    )\nlemma add_zero_ (x : \ud835\udc0d): x + 0 = x := by refl\n\nlemma one_add (x : \ud835\udc0d): 1 + x = succ x :=\n    natural.rec_on x (\n        show 1 + 0 = succ 0, by refl\n    ) (\n        assume n : \ud835\udc0d,\n        assume h : 1 + n = succ n,\n        calc\n            1 + (succ n) = succ (1 + n)  : by refl\n            ...          = succ (succ n) : by rw h\n    )\nlemma add_one (x : \ud835\udc0d): x + 1 = succ x := by refl\n\nlemma add_asoc (x y z : \ud835\udc0d): (x + y) + z = x + (y + z) :=\n    natural.rec_on z (\n        show (x + y) + 0 = x + (y + 0), by refl\n    ) (\n        assume n : \ud835\udc0d,\n        assume h : (x + y) + n = x + (y + n),\n        calc\n            (x + y) + succ n = succ ((x + y) + n)   : by refl\n            ...              = succ (x + (y + n))   : by rw h\n            ...              = x + succ (y + n)     : by refl\n    )\nlemma add_com (x y : \ud835\udc0d): x + y = y + x :=\n    natural.rec_on y (\n        show x + 0 = 0 + x, by rwa [add_zero_, zero_add_]\n    ) (\n        assume n: \ud835\udc0d,\n        assume h : x + n = n + x,\n        calc\n            x + succ n = x + (n + 1)    : by rw add_one\n            ...        = (x + n) + 1    : by rw add_asoc\n            ...        = (n + x) + 1    : by rw h\n            ...        = n + (x + 1)    : by rw add_asoc\n            ...        = n + (1 + x)    : by rw [add_one, one_add]\n            ...        = (n + 1) + x    : by rw add_asoc\n            ...        = (succ n) + x   : by rw add_one\n    )\n\n@[simp]\nlemma add_rearrange (x y z : \ud835\udc0d): (x + y) + z = (x + z) + y := (\n    calc\n        (x + y) + z = x + (y + z)   : by rw add_asoc\n        ...         = x + (z + y)   : by rw add_com y\n        ...         = (x + z) + y   : by rw add_asoc\n)\n\nlemma zero_sum {x y : \ud835\udc0d}: x + y = 0 \u2192 x = 0 :=\n    match y with\n    | 0 := assume h, show x=0, by rw [\u2190add_zero_ x, h]\n    | (a+1) := assume h, (\n        have (x + a) + 1 = 0, by rw [add_asoc, h],\n        absurd this (zero_not_succ (x+a))\n    )\n    end\n\nlemma add_unchanged_implies_zero {x y : \ud835\udc0d}: x + y = y \u2192 x = 0 :=\n    natural.rec_on y (\n        assume h : x + 0 = 0,\n        show x = 0, by rw [\u2190add_zero_ x, h]\n    ) (\n        assume a : \ud835\udc0d,\n        assume hr: x + a = a \u2192 x = 0,\n        assume h: x + (a+1) = a+1,\n        have (x + a)+1 = a+1, by rw [add_asoc x a 1, h],\n        have x + a = a, from iff.elim_right succ_inj this,\n        show x = 0, from hr this\n    )\n\n-- Now define multiplication\ndef mult : \ud835\udc0d \u2192 \ud835\udc0d \u2192 \ud835\udc0d\n    | a 0       := 0\n    | a (b + 1) := a + (mult a b)\n\ninstance natural_has_mult : has_mul \ud835\udc0d := \u27e8mult\u27e9\n\n\n-- And prove some useful results about multiplication\nlemma mult_zero (x : \ud835\udc0d): x * 0 = 0 := by refl\n\nlemma zero_mult (x : \ud835\udc0d): 0 * x = 0 :=\n    natural.rec_on x (\n        show (0 : \ud835\udc0d) * 0 = 0, by refl\n    ) (\n        assume n : \ud835\udc0d,\n        assume h : 0 * n = 0,\n        calc\n            0 * (n + 1) = 0 + 0 * n : by refl\n            ...         = 0 + 0     : by rw h\n            ...         = 0         : by refl\n    )\n\n\nlemma mult_one (x : \ud835\udc0d): x * 1 = x := by refl\n\nlemma one_mult (x : \ud835\udc0d): 1 * x = x :=\n    natural.rec_on x (\n        show (1 : \ud835\udc0d) * 0 = 0, by refl\n    ) (\n        assume n : \ud835\udc0d,\n        assume h : 1 * n = n,\n        calc\n            1 * (n + 1) = 1 + (1 * n)  : by refl\n            ...         = 1 + n        : by rw h\n            ...         = n + 1        : by rw add_com\n    )\n\nlemma add_dist_mult (x y z : \ud835\udc0d): (x + y) * z = (x * z) + (y * z) :=\n    natural.rec_on z (\n        show (x + y) * 0 = (x * 0) + (y * 0), by refl\n    ) (\n        assume n: \ud835\udc0d,\n        assume h: (x + y) * n = (x * n) + (y * n),\n        calc\n            (x + y) * (n + 1) = (x + y) + ((x + y) * n)        : by refl\n            ...               = (x + y) + ((x * n) + (y * n))  : by rw h\n            ...               = (x + (x * n)) + (y + (y * n))  : by rw [\u2190add_asoc (x + y) (x * n), add_asoc x y, add_com y (x * n), \u2190add_asoc, add_asoc]\n    )\n\nlemma mult_dist_add (x y z : \ud835\udc0d): x * (y + z) = (x * y) + (x * z) :=\n    natural.rec_on z (\n        show x * (y + 0) = (x * y) + (x * 0), by refl\n    ) (\n        assume n: \ud835\udc0d,\n        assume h: x * (y + n) = (x * y) + (x * n),\n        calc\n            x * (y + (n + 1)) = x * ((y + n) + 1)        : by rw add_asoc\n            ...               = x + (x * (y + n))        : by refl\n            ...               = (x * y) + x + (x * n)    : by rw [h, \u2190add_asoc, add_com (x*y)]\n            ...               = (x * y) + (x + (x * n))  : by rw add_asoc\n            ...               = (x * y) + (x * (n + 1))  : by refl\n    )\n\nlemma mult_asoc (x y z : \ud835\udc0d): (x * y) * z = x * (y * z) :=\n    natural.rec_on z (\n        calc\n            (x * y) * 0 = x * (y * 0)  : by refl\n    ) (\n        assume n: \ud835\udc0d,\n        assume h: (x * y) * n = x * (y * n),\n        calc\n            (x * y) * (n + 1) = (x * y) + ((x * y) * n)    : by refl\n            ...               = x * (y + (y * n))          : by rw [h, mult_dist_add]\n            ...               = x * (y * (n + 1))          : by refl\n    )\n\nlemma mult_com (x y : \ud835\udc0d): x * y = y * x :=\n    natural.rec_on x (\n        show 0 * y = y * 0, by rw [zero_mult, mult_zero]\n    ) (\n        assume n : \ud835\udc0d,\n        assume h : n * y = y * n,\n        calc\n            (n + 1) * y = (y * n) + (y * 1)   : by rw [add_dist_mult, one_mult, h, mult_one]\n            ...         = y * (n + 1)         : by rw mult_dist_add\n    )\n\n-- equality is decidable\nlemma succ_ne_zero (n : \ud835\udc0d): (n + 1) \u2260 0 :=\n    assume h : succ n = 0,\n    natural.no_confusion h\n\nlemma zero_ne_succ (n : \ud835\udc0d): 0 \u2260 (n + 1) :=\n    assume h :  0 = succ n,\n    natural.no_confusion h\n\n@[reducible]\ninstance natural_decidable_eq: decidable_eq \ud835\udc0d\n| 0       0       := is_true (by refl)\n| (x + 1) 0       := is_false (succ_ne_zero x)\n| 0       (y + 1) := is_false (zero_ne_succ y)\n| (x + 1) (y + 1) :=\n    match natural_decidable_eq x y with\n    | is_true h  := is_true (by rw h)\n    | is_false _ := is_false (assume h: succ x = succ y, have x = y, by injection h, absurd \u2039x = y\u203a \u2039x \u2260 y\u203a)\n    end\n\n-- This is needed to allow us to represent natural numbers sensibly\n-- in messages. It's primarily a convenience for the programmer.\n-- This is based on what's done for \u2115 in the lean core library\n\ndef digit_char (n: \ud835\udc0d) : char :=\nif n = 0 then '0' else\nif n = 1 then '1' else\nif n = 2 then '2' else\nif n = 3 then '3' else\nif n = 4 then '4' else\nif n = 5 then '5' else\nif n = 6 then '6' else\nif n = 7 then '7' else\nif n = 8 then '8' else\nif n = 9 then '9' else\nif n = 0xa then 'a' else\nif n = 0xb then 'b' else\nif n = 0xc then 'c' else\nif n = 0xd then 'd' else\nif n = 0xe then 'e' else\nif n = 0xf then 'f' else\n'*'\n\ndef digit_succ (b : \ud835\udc0d): list \ud835\udc0d \u2192 list \ud835\udc0d\n| [] := [1]\n| (d::ds) :=\n    if (d+1) = b then\n        0 :: digit_succ ds\n    else\n        (d+1) :: ds\n\ndef to_digits (b : \ud835\udc0d): \ud835\udc0d \u2192 list \ud835\udc0d\n| 0     := [0]\n| (n+1) := digit_succ b (to_digits n)\n\ndef repr (n: \ud835\udc0d): string :=\n    ((to_digits 10 n).map digit_char).reverse.as_string\n\ninstance natural_has_repr: has_repr \ud835\udc0d := \u27e8repr\u27e9\n\n-- inequalities\ndef le (x y : \ud835\udc0d): Prop := \u2203 z : \ud835\udc0d, z + x = y\ninstance natural_has_le: has_le \ud835\udc0d := \u27e8le\u27e9\n\ndef lt (x y : \ud835\udc0d): Prop := (x \u2264 y) \u2227 (x \u2260 y)\ninstance natural_has_lt: has_lt \ud835\udc0d := \u27e8lt\u27e9\n\nlemma succ_le_succ {x y : \ud835\udc0d}: x \u2264 y \u2192 (x + 1) \u2264 (y + 1) :=\n    assume \u27e8z, (h: z + x = y)\u27e9,\n    suffices z + (x + 1) = y + 1, from \u27e8z, this\u27e9,\n    show z + (x + 1) = y + 1, by rw [\u2190add_asoc z x 1, h]\n\ninstance le_decidable: \u2200 a b : \ud835\udc0d, decidable (a \u2264 b)\n| 0       y        := is_true \u27e8y, by refl\u27e9\n| (x + 1) 0        := is_false (\n    assume \u27e8z, h\u27e9,\n    have (z + x) + 1 = 0, by rw [add_asoc, h],\n    have (z + x) + 1 \u2260 0, from succ_ne_zero (z + x),\n    absurd \u2039(z + x) + 1 = 0\u203a \u2039(z + x) + 1 \u2260 0\u203a\n)\n|  (x+1) (y+1)    :=\n    match le_decidable x y with\n        | is_true xley := is_true (succ_le_succ xley)\n        | is_false xgty := is_false (\n            assume \u27e8z, (h: z + x + 1 = y + 1)\u27e9,\n            have x \u2264 y, from \u27e8z, by injection h\u27e9,\n            absurd \u2039x \u2264 y\u203a xgty\n        )\n    end\n\ninstance lt_decidable: \u2200 a b : \ud835\udc0d, decidable (a < b) :=\nassume a b,\nmatch natural.natural_decidable_eq a b with\n| is_true h  := is_false (assume :a < b, absurd h this.right)\n| is_false h := (\n    match natural.le_decidable a b with\n    | is_true hle  := is_true \u27e8hle, h\u27e9\n    | is_false hle := is_false (assume :a < b, absurd this.left hle)\n    end\n)\nend\n\n\nlemma le_zero {x: \ud835\udc0d}: x \u2264 0 \u2192 x = 0 :=\n    match x with\n    | 0     := assume h, by refl\n    | (a+1) := (\n        assume \u27e8y, h\u27e9,\n        suffices y + (a+1) \u2260 0, from absurd h this,\n        calc\n             y + (a+1) = (y + a) + 1 :by rw add_asoc\n             ...       \u2260 0           :by apply succ_ne_zero\n    )\n    end\n\nlemma zero_le (x:\ud835\udc0d): 0 \u2264 x :=\n    match x with\n    | 0 := \u27e80, by refl\u27e9\n    | (a+1) := \u27e8a+1, add_zero_ (a+1)\u27e9\n    end\n\nlemma le_refl (x: \ud835\udc0d): x \u2264 x := \u27e80, zero_add_ x\u27e9\n\nlemma le_trans {x y z: \ud835\udc0d}: x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z :=\n    assume \u27e8a, _\u27e9,\n    assume \u27e8b, _\u27e9,\n    \u27e8b+a, show b + a + x = z, by rw [add_asoc, \u2039a + x = y\u203a, \u2039b + y = z\u203a]\u27e9\n\nlemma lt_trans {x y z: \ud835\udc0d}: x < y \u2192 y < z \u2192 x < z :=\n    assume hxy: x < y,\n    assume hyz: y < z,\n    suffices x \u2260 z, from \u27e8le_trans hxy.left hyz.left, this\u27e9,\n    assume h: x = z,\n    suffices z = y, from absurd (eq.symm this) hyz.right,\n    let \u27e8a, (_: a+x=y)\u27e9 := hxy.left in (\n        let \u27e8b, (_: b+y=z)\u27e9 := hyz.left in (\n            suffices b = 0, from (\n                calc\n                    z   = b + y  : by rw \u2039b+y=z\u203a\n                    ... = 0 + y  : by rw this\n                    ... = y      : by rw zero_add_\n            ),\n            suffices (b + a) = 0, from zero_sum this,\n            suffices  x = (b + a) + x, from  add_unchanged_implies_zero (eq.symm this),\n            calc\n                x   = z            : by assumption\n                ... = b + y        : by rw \u2039b + y = z\u203a\n                ... = b + (a + x)  : by rw \u2039a + x = y\u203a\n                ... = (b + a) + x  : by rw add_asoc\n        )\n    )\n\nlemma le_sym_implies_eq {x y :\ud835\udc0d}: x \u2264 y \u2192 y \u2264 x \u2192 x = y :=\n    assume \u27e8a, _\u27e9,\n    assume \u27e8b, _\u27e9,\n    suffices a = 0, from (\n    calc\n        x          = 0 + x          : by rw zero_add_\n        ...        = a + x          : by rw this\n        ...        = y              : by rw [\u2039a + x = y\u203a]\n    ),\n    suffices a + b = 0, from (zero_sum this),\n    suffices (a + b) + x = x, from add_unchanged_implies_zero this,\n    calc\n        (a + b) + x = (b + a) + x   : by rw add_com a b\n        ...         = b + (a + x)   : by rw add_asoc\n        ...         = b + y         : by rw [\u2039a+x = y\u203a]\n        ...         = x             : by rw [\u2039b+y = x\u203a]\n\nlemma le_implies_not_succ {x y : \ud835\udc0d}: x \u2264 y \u2192 x \u2260 y+1 :=\n    assume h: x \u2264 y,\n    assume :x = y + 1,\n    have y+1 \u2264 y, from \u2039x = y+1\u203a \u25b8 \u2039x \u2264 y\u203a,\n    let \u27e8z, (_: z + (y + 1) = y)\u27e9 := this in (\n        have (z + 1) + y = y, by rw [add_com, \u2190add_asoc, add_com y, add_asoc, \u2039z + (y+1) = y\u203a],\n        have z+1 = 0, from add_unchanged_implies_zero this,\n        have z+1 \u2260 0, from succ_ne_zero z,\n        absurd \u2039z+1 = 0\u203a \u2039z+1 \u2260 0\u203a\n    )\n\nlemma nz_implies_succ {x : \ud835\udc0d}: x \u2260 0 \u2192 \u2203 y: \ud835\udc0d, x = y+1 :=\n    match x with\n    | 0     := assume :0 \u2260 0, absurd (eq.refl 0) this\n    | n + 1 := assume :n + 1 \u2260 0, \u27e8n, eq.refl (n+1)\u27e9\n    end\n\nlemma le_implies_lt_succ {x y: \ud835\udc0d}: x \u2264 y \u2192 x < y + 1 :=\n    assume \u27e8z, (h: z + x = y)\u27e9,\n    suffices z + 1 + x = y + 1, from \u27e8\u27e8z+1, this\u27e9, le_implies_not_succ \u2039x \u2264 y\u203a\u27e9,\n    suffices (z + x) + 1 = y + 1, by rw [add_asoc, add_com 1 x, \u2190add_asoc z x 1, this],\n    show (z + x) + 1 = y + 1, from iff.elim_left succ_inj \u2039z + x = y\u203a\n\nlemma lt_succ_implies_le {x y: \ud835\udc0d}: x < y+1 \u2192 x \u2264 y :=\n    assume \u27e8(hle: x \u2264 y+1), hne\u27e9,\n    let \u27e8z, (h: z + x = y + 1)\u27e9 := hle in\n        if hz: z = 0 then\n            have x = y + 1, by rw [\u2190zero_add_ x, \u2190hz, h],\n            absurd this hne\n        else\n            let \u27e8n, (_: z = n+1)\u27e9 := nz_implies_succ hz in (\n                suffices n + x = y, from \u27e8n, this\u27e9,\n                suffices n + x + 1 = y + 1, from iff.elim_right succ_inj this,\n                calc\n                    n + x + 1 = (n + 1) + x   : by simp\n                    ...       = y + 1         : by rwa \u2190\u2039z = n+1\u203a\n            )\n\nlemma gt_implies_succ_gt {x y: \ud835\udc0d}: x > y \u2192 x+1 > y :=\n    assume \u27e8(_: y \u2264 x), (_: y \u2260 x)\u27e9,\n    if h: y = (x+1)\n    then\n        absurd \u2039y = x+1\u203a (le_implies_lt_succ \u2039y \u2264 x\u203a).right\n    else\n        \u27e8(le_implies_lt_succ \u2039y \u2264 x\u203a).left, \u2039y \u2260 x + 1\u203a\u27e9\n\nlemma ne_succ (x: \ud835\udc0d): x \u2260 x+1 :=\n    natural.rec_on x (\n        assume h: 0 = 1,\n        natural.no_confusion h\n    ) (\n        assume n: \ud835\udc0d,\n        assume h: n \u2260 n + 1,\n        assume : (n+1) = (n+1) + 1,\n        have n = n + 1, from (iff.elim_right succ_inj) this,\n        absurd \u2039n = n +1\u203a \u2039n \u2260 n + 1\u203a\n    )\n\nlemma lt_implies_succ_le {x y: \ud835\udc0d}: x < y \u2192 (x+1) \u2264 y :=\n    assume \u27e8\u27e8z,(_:z+x=y)\u27e9,(_:x\u2260y)\u27e9,\n    if h:z = 0 then\n        have x = y, by rwa [\u2190zero_add_ x, \u2190h],\n        absurd \u2039x = y\u203a \u2039x \u2260 y\u203a\n    else\n        let \u27e8n, (_: z=n+1)\u27e9 := (nz_implies_succ h) in (\n            have n + 1 + x = y, from \u2039z=n+1\u203a \u25b8 \u2039z+x=y\u203a,\n            suffices n + (x + 1) = y, from \u27e8n, this\u27e9,\n            show n + (x + 1) = y, by rwa [add_com x, \u2190add_asoc n 1 x]\n        )\n\nlemma succ_gt (x : \ud835\udc0d): (x+1) > x := \u27e8\u27e81, add_com 1 x\u27e9, ne_succ x\u27e9\n\nlemma lt_succ (x : \ud835\udc0d): x < (x+1) := succ_gt x\n\nlemma le_iff_not_gt {x y: \ud835\udc0d}: x \u2264 y \u2194 \u00ac (x > y) :=\n    iff.intro (\n        assume : x\u2264y,\n        assume \u27e8(_:y \u2264 x), (_: y \u2260 x)\u27e9,\n        suffices y = x, from absurd this \u2039y\u2260x\u203a,\n        show y = x, from le_sym_implies_eq \u2039y \u2264 x\u203a \u2039x \u2264 y\u203a\n    ) (\n        natural.rec_on x (\n            assume h: \u00ac(0 > y),\n            show 0 \u2264 y, from zero_le y\n        ) (\n            assume n: \ud835\udc0d,\n            assume h: (\u00acn > y \u2192 n \u2264 y),\n            assume :\u00ac(n+1 > y),\n            suffices (n+1)\u2264y, from (add_one n) \u25b8 this,\n            have \u00acn > y, from mt (gt_implies_succ_gt) this,\n            have n \u2264 y, from h this,\n            have n \u2260 y, from (\n                assume :n = y,\n                have n+1 > y, from this \u25b8 (succ_gt n),\n                absurd this \u2039\u00acn+1 > y\u203a\n            ),\n            lt_implies_succ_le \u27e8\u2039n \u2264 y\u203a, \u2039n \u2260 y\u203a\u27e9\n        )\n    )\n\n\n-- subtraction, of a sort\ndef pred: \ud835\udc0d \u2192 \ud835\udc0d\n| 0       := 0\n| (a + 1) := a\n\ndef sub:  \ud835\udc0d \u2192 \ud835\udc0d \u2192 \ud835\udc0d\n| a 0       := a\n| a (b + 1) := pred (sub a b)\n\ninstance natural_has_sub: has_sub \ud835\udc0d := \u27e8sub\u27e9\n\nlemma sub_zero (x: \ud835\udc0d): x - 0 = x := by refl\n\nlemma zero_sub (x: \ud835\udc0d): 0 - x = 0 :=\n    natural.rec_on x (\n        by refl\n    ) (\n        assume n: \ud835\udc0d,\n        assume h: 0 - n = 0,\n        calc\n            0 - (n+1) = pred (0 - n)  : by refl\n            ...       = pred 0        : by rw h\n            ...       = 0             : by refl\n    )\n\nlemma succ_sub_one (x: \ud835\udc0d): (x+1) - 1 = x :=\ncalc\n    (x+1) - 1 = (x+1) - (0+1)     : by rw zero_add_\n    ...       = pred ((x+1) - 0)  : by refl\n    ...       = pred (x+1)        : by refl\n    ...       = x                 : by refl\n\nlemma pred_zero {x : \ud835\udc0d}: pred x = 0 \u2192 x \u2260 0 \u2192 x = 1 :=\n    assume h: pred x = 0,\n    assume hz: x \u2260 0,\n    if hh: x = 0 then\n        absurd hh hz\n    else\n        let \u27e8n, (_: x = n + 1)\u27e9 := nz_implies_succ hz in (\n            calc\n                x   = n + 1             : by assumption\n                ... = (pred (n+1)) + 1  : by refl\n                ... = (pred x) + 1      : by rw \u2039x = n+1\u203a\n                ... = 0 + 1             : by rw h\n                ... = 1                 : by rw zero_add_\n        )\n\nlemma succ_pred {x: \ud835\udc0d}: x \u2260 0 \u2192 (pred x) + 1 = x :=\n    assume h,\n    let \u27e8a, h\u27e9 := nz_implies_succ h in calc\n        (pred x) + 1 = (pred (a+1)) + 1   : by rw h\n        ...          = a + 1              : by refl\n        ...          = x                  : by rw h\n\nlemma pred_add {x y: \ud835\udc0d}: x \u2260 0 \u2192 (pred x) + y = pred (x + y) :=\n    assume h: x \u2260 0,\n    let \u27e8a, (h: x = a+1)\u27e9 := nz_implies_succ h in (\n        calc\n            pred x + y = pred (a+1) + y   : by rw h\n            ...        = a + y            : by refl\n            ...        = pred (a + y + 1) : by refl\n            ...        = pred ((a+1) + y) : by simp\n            ...        = pred (x + y)     : by rw h\n    )\n\nlemma eq_implies_le {x y: \ud835\udc0d}: x = y \u2192 x \u2264 y := assume h, \u27e80, h \u25b8 (zero_add_ x)\u27e9\n\nlemma not_le {x y: \ud835\udc0d}: \u00ac(x \u2264 y) \u2194 (y < x) :=\n    iff.intro (\n        natural.rec_on y (\n            assume h,\n            have x \u2260 0, from assume :x=0, absurd (eq_implies_le this) h,\n            suffices 0 \u2264 x, from \u27e8this, ne.symm \u2039x\u22600\u203a\u27e9,\n            zero_le x\n        ) (\n            assume a: \ud835\udc0d,\n            assume hr: \u00acx \u2264 a \u2192 a < x,\n            assume : \u00acx \u2264 a+1,\n            have x \u2260 a+1, from assume :x=a+1, absurd (eq_implies_le this) \u2039\u00acx \u2264 a+1\u203a,\n            suffices a+1 \u2264 x, from \u27e8this, ne.symm \u2039x\u2260a+1\u203a\u27e9,\n            have x \u2264 a \u2192 x \u2264 a+1, from assume :x\u2264 a, (le_implies_lt_succ this).left,\n            have a < x, from hr (mt \u2039x \u2264 a \u2192 x \u2264 a+1\u203a \u2039\u00ac(x \u2264 a+1)\u203a),\n            lt_implies_succ_le \u2039a < x\u203a\n        )\n    ) (\n        assume \u27e8\u27e8a, (_: a+y=x)\u27e9, (_: y \u2260 x)\u27e9,\n        assume \u27e8b, (_: b+x=y)\u27e9,\n        suffices y=x, from absurd this \u2039y\u2260x\u203a,\n        suffices b=0, by rw [\u2190\u2039b+x=y\u203a, this, zero_add_ x],\n        suffices b+a=0, from zero_sum this,\n        suffices y = b+a+y, from  add_unchanged_implies_zero (eq.symm this),\n        calc\n            y   = b+x     : by rw \u2039b+x=y\u203a\n            ... = b+(a+y) : by rw \u2039a+y=x\u203a\n            ... = b+a+y   : by rw add_asoc b a y\n    )\n\nlemma not_lt {x y: \ud835\udc0d}: \u00ac(x < y) \u2194 (y \u2264 x) := iff.trans (iff.symm (not_congr (@not_le y x))) (decidable.not_not_iff (y \u2264 x))\n\nlemma succ_le_implies_lt {x y: \ud835\udc0d}:  (x+1) \u2264 y \u2192 x < y :=\n    assume \u27e8z, (h: z + (x+1) = y)\u27e9,\n    have (z + 1) + x = y, by rw [add_asoc z, add_com 1, h],\n    suffices x \u2260 y, from \u27e8\u27e8(z+1), \u2039(z + 1) + x = y\u203a\u27e9, this\u27e9,\n    assume hc: x = y,\n    have y < x+1, from hc \u25b8 lt_succ x,\n    absurd \u2039x+1 \u2264 y\u203a (iff.elim_right not_le \u2039y < x+1\u203a)\n\nlemma diff_zero_can_cancel {x y : \ud835\udc0d}: x - y \u2260 0 \u2192 (x - y) + y = x :=\n    natural.rec_on y (\n        assume h: x \u2260 0,\n        by refl\n    ) (\n        assume a: \ud835\udc0d,\n        assume hr: x - a \u2260 0 \u2192 x - a + a = x,\n        assume h: x - (a+1) \u2260 0,\n        have x - (a+1) = pred (x - a), by refl,\n        if hxa: x - a = 0 then\n            suffices x - (a+1) = 0, from absurd this h,\n            calc\n                x - (a+1)  = pred (x - a)  : by refl\n                ...        = pred 0        : by rw hxa\n                ...        = 0             : by refl\n        else\n            have hr: x - a + a = x, from hr hxa,\n            calc\n                x - (a+1) + (a+1) = (pred (x - a)) + (a + 1) : by refl\n                ...               = (pred (x - a)) + (1 + a) : by rw add_com a\n                ...               = (pred (x - a) + 1) + a   : by rw add_asoc\n                ...               = x - a + a                : by rw succ_pred hxa\n                ...               = x                        : by assumption\n    )\n\nlemma pred_nz {x: \ud835\udc0d}: pred x \u2260 0 \u2192 x \u2260 0 :=\n    assume h: pred x \u2260 0,\n    assume hc: x = 0,\n    suffices pred x = 0, from absurd this h,\n    calc\n        pred x = pred 0  : by rw hc\n        ...    = 0       : by refl\n\nlemma diff_nz_succ_sub {x y: \ud835\udc0d}: x - y \u2260 0 \u2192 (x+1) - y = (x - y) + 1 :=\n    natural.rec_on y (\n        assume :x \u2260 0,\n        by refl\n    ) (\n        assume b,\n        assume hr: x - b \u2260 0 \u2192 x + 1 - b = x - b + 1,\n        assume h: pred (x - b) \u2260 0,\n        have h: x - b \u2260 0, from pred_nz h,\n        have hr: (x+1) - b = (x - b) + 1, from hr h,\n        calc\n            (x+1) - (b+1) = pred ((x+1) - b)    : by refl\n            ...           = pred ((x - b) + 1)  : by rw hr\n            ...           = x - b               : by refl\n            ...           = (pred (x - b)) + 1  : by rw succ_pred h\n            ...           = (x - (b+1)) + 1     : by refl\n    )\n\nlemma diff_zero_of_successors {x y : \ud835\udc0d}: (x+1) - (y+1) = 0 \u2192 x - y = 0 :=\n    assume h: pred ((x+1) - y) = 0,\n    if hxy: x - y = 0 then\n        hxy\n    else\n        have hx1: (x+1) - y = (x - y) + 1, from diff_nz_succ_sub hxy,\n        suffices pred ((x+1) - y) = x - y, from absurd h ((eq.symm this) \u25b8 hxy),\n        calc\n            pred ((x+1) - y) = pred ((x - y) + 1)  : by rw hx1\n            ...              = x - y               : by refl\n\nlemma both_diffs_zero_implies_equal {x : \ud835\udc0d}: (\u2200 y : \ud835\udc0d, x - y = 0 \u2192 y - x = 0 \u2192 x = y) :=\n    natural.rec_on x (\n        assume y: \ud835\udc0d,\n        assume h1: 0-y=0,\n        assume h2: y=0,\n        eq.symm h2\n    ) (\n        assume a: \ud835\udc0d,\n        assume hr: \u2200 (y : \ud835\udc0d), a - y = 0 \u2192 y - a = 0 \u2192 a = y,\n        assume y: \ud835\udc0d,\n        assume h1: (a+1) - y = 0,\n        assume h2: y - (a+1) = 0,\n        if hyz: y = 0 then\n            suffices a+1 = 0, from absurd this (succ_ne_zero a),\n            calc\n                a+1 = (a+1) - 0   : by refl\n                ... = (a+1) - y   : by rw hyz\n                ... = 0           : by rw h1\n        else\n            let \u27e8b, (_:y=b+1)\u27e9 := nz_implies_succ hyz in (\n                suffices (a+1) = (b+1), from (eq.symm \u2039y=b+1\u203a) \u25b8 this,\n                suffices a = b, from congr_arg succ this,\n                have h1: (a+1) - (b+1) = 0, from \u2039y=b+1\u203a \u25b8 h1,\n                have h2: (b+1) - (a+1) = 0, from \u2039y=b+1\u203a \u25b8 h2,\n                have h1: a - b = 0, from diff_zero_of_successors h1,\n                have h2: b - a = 0, from diff_zero_of_successors h2,\n                hr b h1 h2\n            )\n    )\n\nlemma diff_zero {x y : \ud835\udc0d}: x - y = 0 \u2192 x \u2264 y :=\n    assume h: x - y = 0,\n    if hi: y - x = 0 then\n        have x = y, from both_diffs_zero_implies_equal y h hi,\n        eq_implies_le \u2039x = y\u203a\n    else\n        suffices (y - x) + x = y, from \u27e8y-x, this\u27e9,\n        diff_zero_can_cancel hi\n\n\nlemma lt_sub_nz {x y: \ud835\udc0d}: x < y \u2192 y - x \u2260 0 :=\n    assume h: x < y,\n    assume hc: y - x = 0,\n    suffices y \u2264 x, from absurd this (iff.elim_right not_le h),\n    diff_zero hc\n\n\nlemma sub_cancel_same {x y : \ud835\udc0d}: y \u2264 x \u2192 (x-y)+y = x :=\n    natural.rec_on y (\n        assume h: 0 \u2264 x,\n        by refl\n    ) (\n        assume n: \ud835\udc0d,\n        assume hr: n \u2264 x \u2192 x - n + n = x,\n        assume h: n+1 \u2264 x,\n        have x\u22600, from assume :x=0,\n            have n+1=0, from le_zero (\u2039x=0\u203a \u25b8 h),\n            absurd \u2039n+1=0\u203a (succ_ne_zero n),\n        have n < x, from succ_le_implies_lt h,\n        calc\n            (x - (n+1)) + (n+1) = (x - (n+1) + n) + 1       : by refl\n            ...                 = ((pred (x - n)) + n) + 1  : by refl\n            ...                 = (pred ((x - n) + n)) + 1  : by rw pred_add (lt_sub_nz \u2039n<x\u203a)\n            ...                 = (pred x) + 1              : by rw hr \u2039n<x\u203a.left\n            ...                 = x                         : by rw succ_pred \u2039x\u22600\u203a\n    )\n\nlemma lt_anti_sym {x y: \ud835\udc0d}: x < y \u2194 y > x :=\n    iff.intro (assume \u27e8h,g\u27e9, \u27e8h,g\u27e9) (assume \u27e8h,g\u27e9, \u27e8h,g\u27e9)\n\nlemma succ_sub {x y: \ud835\udc0d}: y \u2264 x \u2192 (x+1) - y = (x - y) + 1 :=\n    natural.rec_on y (\n        assume h,\n        show (x+1) - 0 = x + 1, by refl\n    ) (\n        assume a: \ud835\udc0d,\n        assume h: a \u2264 x \u2192 (x + 1) - a = (x - a) + 1,\n        assume \u27e8z,(_:z + (a+1) = x)\u27e9,\n        have a \u2264 x, from \u27e8z+1, by rwa [add_asoc, add_com 1]\u27e9,\n        have \u00ac a > x, from (iff.elim_left le_iff_not_gt) \u2039a \u2264 x\u203a,\n        have \u00ac x < a, from mt (iff.elim_left lt_anti_sym) \u2039\u00aca > x\u203a,\n        have x \u2260 a, from (\n            assume :x = a,\n            suffices z+1 = 0, from absurd this (succ_ne_zero z),\n            suffices (z+1) + a = a, from add_unchanged_implies_zero this,\n            calc\n                (z+1) + a = z + (1+a)  : by rw add_asoc\n                ...       = z + (a+1)  : by rw add_com 1\n                ...       = x          : by assumption\n                ...       = a          : by assumption\n        ),\n        have \u00ac x \u2264 a, from (\n            assume :x \u2264 a,\n            suffices x < a, from absurd this \u2039\u00acx < a\u203a,\n            \u27e8\u2039x \u2264 a\u203a, \u2039x \u2260 a\u203a\u27e9\n        ),\n        have x - a \u2260 0, from (mt diff_zero) \u2039\u00acx \u2264 a\u203a,\n        have h: (x + 1) - a = (x - a) + 1, from h \u2039a \u2264 x\u203a,\n        have (x + 1) - (a + 1) = x - a, from\n        (\n            calc\n                (x + 1) - (a + 1) = pred ((x+1) - a)    : by refl\n                ...               = pred ((x - a) + 1)  : by rw h\n                ...               = x - a               : by refl\n        ),\n        suffices (x - (a + 1)) + 1 = x - a, from (eq.symm this) \u25b8 \u2039(x + 1) - (a + 1) = x - a\u203a,\n        calc\n            (x - (a + 1)) + 1 = pred(x - a) + 1   : by refl\n            ...               = x - a             : by rw (succ_pred \u2039x-a \u2260 0\u203a)\n    )\n\nlemma sub_self_zero (x: \ud835\udc0d): x - x = 0 :=\n    natural.rec_on x (\n        by refl\n    ) (\n        assume n: \ud835\udc0d,\n        assume h: n - n = 0,\n        have n \u2264 n, from le_refl n,\n        calc\n            (n+1) - (n+1) = pred ((n+1) - n)   : by refl\n            ...           = pred ((n - n) + 1) : by rw (succ_sub \u2039n \u2264 n\u203a)\n            ...           = pred (0 + 1)       : by rw h\n            ...           = pred 1             : by rw zero_add_\n            ...           = 0                  : by refl\n    )\n\nlemma le_sub_zero {x y: \ud835\udc0d}: x \u2264 y \u2192 x - y = 0 :=\n    natural.rec_on y (\n        assume h,\n        have x - 0 = x, by refl,\n        suffices x = 0, from \u2039x = 0\u203a \u25b8 \u2039x-0=x\u203a,\n        le_zero h\n    ) (\n        assume n: \ud835\udc0d,\n        assume hr: x \u2264 n \u2192 x - n = 0,\n        assume h: x \u2264 n+1,\n        if hh: x=n+1 then\n            have (n+1) - (n+1) = 0, from sub_self_zero (n+1),\n            show x - (n+1) = 0, from (eq.symm hh) \u25b8 this\n        else\n            have h: x \u2264 n, from lt_succ_implies_le \u27e8h, hh\u27e9,\n            have hr: x - n = 0, from hr h,\n            calc\n                x - (n+1) = pred (x - n)   : by refl\n                ...       = pred 0         : by rw hr\n                ...       = 0              : by refl\n    )\n\nlemma diff_nz {x y : \ud835\udc0d}: x - y \u2260 0 \u2192 y < x :=\n    assume h: x - y \u2260 0,\n    if hle: x \u2264 y then\n        absurd (le_sub_zero hle) h\n    else\n        iff.elim_left not_le hle\n\nlemma succ_sub_self_one (x : \ud835\udc0d): (x+1) - x = 1 :=\n    calc\n        (x+1) - x = (x - x) + 1  : by rw succ_sub (eq_implies_le (eq.refl x))\n        ...       = 0 + 1        : by rw sub_self_zero\n        ...       = 1            : by rw zero_add_\n\nlemma sub_nz_implies_anti_sum_zero {x y : \ud835\udc0d}: x - y \u2260 0 \u2192 y - x = 0 :=\n    assume h: x - y \u2260 0,\n    le_sub_zero (diff_nz h).left\n\nlemma le_implies_le_sum {x y z: \ud835\udc0d}: x \u2264 y \u2192 x \u2264 z + y :=\n    assume \u27e8a, (h: a+x = y)\u27e9,\n    suffices z+a+x = z + y, from \u27e8z+a, this\u27e9,\n    calc\n        z + a + x = z + (a + x)  : by rw add_asoc\n        ...       = z + y        : by rw h\n\nlemma add_sub_asoc {x y z : \ud835\udc0d}: natural.sub z y = 0 \u2192 x + (y - z) = (x + y) - z :=\n    assume h: z - y = 0,\n    natural.rec_on x (\n        calc\n            0 + (y - z) = y - z       : by rw zero_add_\n            ...         = (0 + y) - z : by rw zero_add_\n    ) (\n        assume a: \ud835\udc0d,\n        assume hr: a + (y-z) = (a+y) - z,\n        have z \u2264 y, from diff_zero h,\n        have z \u2264 a+y, from le_implies_le_sum \u2039z \u2264 y\u203a,\n        calc\n            (a+1) + (y-z) = (a + (y-z)) + 1  : by simp\n            ...           = ((a+y) - z) + 1  : by rw hr\n            ...           = ((a+y)+1) - z    : by rw succ_sub \u2039z \u2264 a+y\u203a\n            ...           = ((a+1)+y) - z    : by simp\n    )\n\nlemma add_cancel_right {x y z : \ud835\udc0d}: x + y = z + y \u2192 x = z :=\n    natural.rec_on y (\n        assume h, by assumption\n    ) (\n        assume b: \ud835\udc0d,\n        assume hr: x + b = z + b \u2192 x = z,\n        assume h: x + (b+1) = z + (b+1),\n        have h: (x + b) + 1 = (z + b) + 1, by rw [add_asoc x b 1, h, \u2190add_asoc z b 1],\n        have h: x + b = z + b, from iff.elim_right succ_inj h,\n        show x = z, from hr h\n    )\n\nlemma add_cancel_left {x y z: \ud835\udc0d}: x + y = x + z \u2192 y = z :=\n    assume h: x + y = x + z,\n    have h: y + x = z + x, by rw [\u2190add_com x y, h, add_com x z],\n    show y = z, from add_cancel_right h\n\nlemma le_add_cancel_left {x y z: \ud835\udc0d}:  x + y \u2264 x + z \u2194 y \u2264 z :=\n    iff.intro (\n        assume \u27e8a, (h: a + (x + y) = x + z)\u27e9,\n        suffices a+y = z, from \u27e8a, this\u27e9,\n        suffices a+y+x = z+x, from add_cancel_right this,\n        show a + y + x = z + x, by rw [add_asoc, \u2190add_com x y, h, add_com x z]\n    ) (\n        assume \u27e8a, (h: a + y = z)\u27e9,\n        suffices a + (x + y) = (x + z), from \u27e8a, this\u27e9,\n        show a + (x + y) = x + z, by rw [add_com x y, \u2190add_asoc a y x, h, add_com z x]\n    )\n\nlemma le_add_cancel_right {x y z: \ud835\udc0d}:  x + y \u2264 z + y \u2194 x \u2264 z :=\n    iff.intro (\n        assume h: x + y \u2264 z + y,\n        have h: y + x \u2264 y + z, from (add_com z y) \u25b8 (add_com x y) \u25b8 h,\n        iff.elim_left le_add_cancel_left h\n    ) (\n        assume h: x \u2264 z,\n        (add_com y z) \u25b8 (add_com y x) \u25b8 (iff.elim_right le_add_cancel_left h)\n    )\n\nlemma lt_add_cancel_left {x y z: \ud835\udc0d}:  x + y < x + z \u2194 y < z :=\n    iff.intro (\n        assume h: x + y < x + z,\n        suffices y \u2260 z, from \u27e8iff.elim_left le_add_cancel_left h.left, this\u27e9,\n        assume hc: y = z,\n        suffices x + y = x + z, from absurd this h.right,\n        show x + y = x + z, by rw hc\n    ) (\n        assume h: y < z,\n        suffices x + y \u2260 x + z, from \u27e8iff.elim_right le_add_cancel_left h.left, this\u27e9,\n        assume hc: x + y = x + z,\n        suffices y = z, from absurd this h.right,\n        add_cancel_left hc\n    )\n\nlemma lt_add_cancel_right {x y z: \ud835\udc0d}:  x + y < z + y \u2194 x < z :=\n    iff.intro (\n        assume h: x + y < z + y,\n        have h: y + x < y + z, from (add_com z y) \u25b8 (add_com x y) \u25b8 h,\n        iff.elim_left lt_add_cancel_left h\n    ) (\n        assume h: x < z,\n        (add_com y z) \u25b8 (add_com y x) \u25b8 (iff.elim_right lt_add_cancel_left h)\n    )\n\nlemma sub_cancel_right (x y z: \ud835\udc0d): (x+z) - (y+z) = x - y :=\n    if hxy: x - y = 0 then\n        have h: x \u2264 y, from diff_zero hxy,\n        have h: x+z \u2264 y+z, from iff.elim_right le_add_cancel_right h,\n        show (x+z) - (y+z) = x - y, by rw [le_sub_zero h, hxy]\n    else\n        natural.rec_on z (\n            by refl\n        ) (\n            assume c: \ud835\udc0d,\n            assume hr: (x + c) - (y + c) = x - y,\n            have y < x, from diff_nz hxy,\n            have y+c < x+c, from iff.elim_right lt_add_cancel_right \u2039y < x\u203a,\n            have (x+c) - (y+c) \u2260 0, from lt_sub_nz \u2039y+c < x+c\u203a,\n            calc\n                (x + (c+1)) - (y + (c+1)) = ((x+c) + 1) - ((y+c) + 1)   : by refl\n                ...                       = pred (((x+c) + 1) - (y+c))  : by refl\n                ...                       = pred (((x+c) - (y+c)) + 1)  : by rw diff_nz_succ_sub \u2039(x+c)-(y+c)\u22600\u203a\n                ...                       = (x+c) - (y+c)               : by refl\n                ...                       = x - y                       : by assumption\n        )\n\nlemma sub_of_sub (x y z: \ud835\udc0d): (x-y)-z = x-(y+z) :=\n    natural.rec_on z (\n        by refl\n    ) (\n        assume c: \ud835\udc0d,\n        assume hr: x - y - c = x - (y + c),\n        calc\n            (x - y) - (c+1) = pred ((x - y) - c)  : by refl\n            ...             = pred (x - (y + c))  : by rw hr\n            ...             = x - (y+c+1)         : by refl\n    )\n\n\nlemma mult_nz {x y: \ud835\udc0d}: x\u22600 \u2192 y\u22600 \u2192 (x*y)\u22600 :=\n    natural.rec_on y (\n        assume hx,\n        assume hy,\n        absurd (eq.refl 0) hy\n    ) (\n        assume b: \ud835\udc0d,\n        assume hr: x \u2260 0 \u2192 b \u2260 0 \u2192 x * b \u2260 0,\n        assume hx: x \u2260 0,\n        assume hy: b+1 \u2260 0,\n        assume hc: x*(b+1) = 0,\n        absurd (zero_sum hc) hx\n    )\n\nlemma mult_nz_eq_z_imp_z {x y : \ud835\udc0d}: x*y = 0 \u2192 y \u2260 0 \u2192 x = 0 :=\n    assume h: x*y = 0,\n    assume hy: y \u2260 0,\n    if hx: x = 0 then\n        hx\n    else\n        let \u27e8a, hx\u27e9 := nz_implies_succ hx in (\n            let \u27e8b, hy\u27e9 := nz_implies_succ hy in (\n                have h: (a+1)*(b+1) = 0, from hx \u25b8 hy \u25b8 h,\n                have h: (a+1) + ((a+1)*b) = 0, from h,\n                have h: ((a+1)*b + a) + 1 = 0, by rw [add_asoc, \u2190add_com (a+1), h],\n                natural.no_confusion h\n            )\n        )\n\nlemma mult_elim_right {x y z: \ud835\udc0d}: y \u2260 0 \u2192 x*y = z*y \u2192 x = z :=\n    assume hy: y \u2260 0,\n    suffices \u2200 w: \ud835\udc0d, x*y = w*y \u2192 x = w, from this z,\n    natural.rec_on x (\n        assume w: \ud835\udc0d,\n        assume h: 0*y = w*y,\n        have h: w*y = 0, by rw [\u2190h, zero_mult],\n        eq.symm (mult_nz_eq_z_imp_z h hy)\n    ) (\n        assume a: \ud835\udc0d,\n        assume hr: \u2200 (w : \ud835\udc0d), a * y = w * y \u2192 a = w,\n        assume v: \ud835\udc0d,\n        assume h: (a+1)*y = v*y,\n        if hv: v=0 then\n            have h: (a+1)*y = 0*y, from hv \u25b8 h,\n            have h: (a+1)*y = 0, by rw [h, zero_mult],\n            have h: (a+1) = 0, from mult_nz_eq_z_imp_z h hy,\n            absurd h (succ_ne_zero a)\n        else\n            let \u27e8b, hv\u27e9 := nz_implies_succ hv in (\n                have h: (a+1) * y = (b+1) * y, from hv \u25b8 h,\n                have h: y*(a+1) = y*(b+1), by rw [mult_com, h, mult_com],\n                have h: y + y*a = y + (y*b), from h,\n                have h: y*a = y*b, from add_cancel_left h,\n                have h: a*y = b*y, by rw [mult_com, h, mult_com],\n                have h: a = b, from hr b h,\n                show a+1 = v, by rw [h, hv]\n            )\n    )\n\nlemma ne_implies_lt_or_gt {x y: \ud835\udc0d}: x \u2260 y \u2192 x < y \u2228 y < x :=\n    assume hnz: x \u2260 y,\n    if hle: x \u2264 y then\n        or.intro_left _ \u27e8hle, hnz\u27e9\n    else\n        or.intro_right _ (iff.elim_left not_le hle)\n\nlemma le_mult_cancel_right__forward {x y z: \ud835\udc0d}: x \u2264 y \u2192 x*z \u2264 y*z :=\n    assume \u27e8a, (h: a+x = y)\u27e9,\n    suffices a*z + x*z = y*z, from \u27e8a*z, this\u27e9,\n    calc\n        a*z + x*z = (a + x)*z  : by rw add_dist_mult\n        ...       = y*z        : by rw h\n\nlemma mult_cancel_right {x y z: \ud835\udc0d}: z \u2260 0 \u2192 x*z = y*z \u2192 x = y :=\n    assume hz: z \u2260 0,\n    suffices \u2200 b: \ud835\udc0d, x*z = b*z \u2192 x = b, from this y,\n    natural.rec_on x (\n        assume y : \ud835\udc0d,\n        assume h: 0*z = y*z,\n        have h: y*z = 0, by rw [\u2190h, zero_mult z],\n        eq.symm (mult_nz_eq_z_imp_z h hz)\n    ) (\n        assume a: \ud835\udc0d,\n        assume hr:  \u2200 (b : \ud835\udc0d), a * z = b * z \u2192 a = b,\n        assume y: \ud835\udc0d,\n        assume h: (a+1) * z = y * z,\n        if hy: y=0 then\n            have h: (a+1) * z = 0, by rw [h, hy, zero_mult],\n            have h: (a+1) = 0, from mult_nz_eq_z_imp_z h hz,\n            absurd h (succ_ne_zero a)\n        else\n            let \u27e8b, hy\u27e9 := nz_implies_succ hy in (\n                have h: (a+1)*z = (b+1)*z, from hy \u25b8 h,\n                suffices a = b, from show a + 1 = y, by rw [this, hy],\n                suffices z + a*z = z + b*z, from hr b (add_cancel_left this),\n                calc\n                    z + a*z = z + z*a  : by rw mult_com\n                    ...     = z*(a+1)  : by refl\n                    ...     = (a+1)*z  : by rw mult_com\n                    ...     = (b+1)*z  : by assumption\n                    ...     = z*(b+1)  : by rw mult_com\n                    ...     = z + z*b  : by refl\n                    ...     = z + b*z  : by rw mult_com\n            )\n    )\n\nlemma lt_mult_cancel_right__forward {x y z: \ud835\udc0d}: z \u2260 0 \u2192 x < y \u2192 x*z < y*z :=\n    assume hz: z \u2260 0,\n    assume \u27e8hle, hne\u27e9,\n    suffices x*z \u2260 y*z, from \u27e8le_mult_cancel_right__forward hle, this\u27e9,\n    assume hc: x*z = y*z,\n    absurd (mult_cancel_right hz hc) hne\n\nlemma le_mult_cancel_right {x y z: \ud835\udc0d}: (x \u2264 y \u2228 z = 0) \u2194 x*z \u2264 y*z :=\n    iff.intro (\n        assume h,\n        or.elim h (\n            le_mult_cancel_right__forward\n        ) (\n            assume hz: z = 0,\n            suffices x*z = y*z, from eq_implies_le this,\n            calc\n                x * z = x * 0   : by rw hz\n                ...   = 0       : by refl\n                ...   = y * 0   : by refl\n                ...   = y * z   : by rw hz\n        )\n    ) (\n        assume h: x*z \u2264 y*z,\n        if hc: x \u2264 y then\n            or.intro_left _ hc\n        else\n            if hz: z = 0 then\n                or.intro_right _ hz\n            else\n                have hc: y < x, from iff.elim_left not_le hc,\n                have hc: y*z < x*z, from lt_mult_cancel_right__forward hz hc,\n                absurd h (iff.elim_right not_le hc)\n    )\n\nlemma lt_mult_cancel_right {x y z: \ud835\udc0d}: (x<y \u2227 z\u22600) \u2194 x*z < y*z :=\n    iff.intro (\n        assume \u27e8hlt, hz\u27e9,\n        lt_mult_cancel_right__forward hz hlt\n    ) (\n        assume h: x*z < y*z,\n        have z \u2260 0, from (\n            assume hc: z=0,\n            have hc: x*0 < y*0, from hc \u25b8 h,\n            absurd (show x*0 = y*0, by rw [mult_zero, mult_zero]) hc.right\n        ),\n        if hc: x < y then\n            \u27e8hc, \u2039z\u22600\u203a\u27e9\n        else\n            have hc: y \u2264 x, from iff.elim_left not_lt hc,\n            have hc: y*z \u2264 x*z, from le_mult_cancel_right__forward hc,\n            have hc: \u00ac(x*z < y*z), from iff.elim_right not_lt hc,\n            absurd h hc\n    )\n\nlemma sub_dist_mult {x y z: \ud835\udc0d}: y \u2264 x \u2192 (x - y)*z = x*z - y*z :=\n    assume h: y \u2264 x,\n    natural.rec_on z (by refl) (\n        assume c: \ud835\udc0d,\n        assume hr: (x - y) * c = x * c - y * c,\n        have y - x = 0, from le_sub_zero h,\n        have y*c \u2264 x*c, from iff.elim_left le_mult_cancel_right (or.intro_left _ h),\n        have y*c - x*c = 0, from le_sub_zero \u2039y*c \u2264 x*c\u203a,\n        calc\n            (x - y) * (c+1) =  (x - y) + (x - y)*c    : by refl\n            ...             =  (x - y) + (x*c - y*c)  : by rw hr\n            ...             =  (x - y) + x*c - y*c    : by rw add_sub_asoc \u2039(y*c) - (x*c) = 0\u203a\n            ...             =  x*c + (x - y) - y*c    : by rw add_com\n            ...             =  (x*c + x) - y - y*c    : by rw add_sub_asoc \u2039y - x = 0\u203a\n            ...             =  (x*c + x) - (y + y*c)  : by rw sub_of_sub\n            ...             =  (x + x*c) - (y + y*c)  : by rw add_com\n            ...             =  (x*(c+1)) - (y*(c+1))  : by refl\n    )\n\n-- And essentially that's the natural numbers\n\nend natural\n", "meta": {"author": "jamespbarrett", "repo": "basicmaths", "sha": "4f5ac79b14d1139cb1fb31ca455a15f37f5967f2", "save_path": "github-repos/lean/jamespbarrett-basicmaths", "path": "github-repos/lean/jamespbarrett-basicmaths/basicmaths-4f5ac79b14d1139cb1fb31ca455a15f37f5967f2/natural.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7297780756270615}}
{"text": "-- L\u00edmites mediante filtros\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Importar las teor\u00edas\n-- + Limites_de_sucesiones\n-- + topology.instances.real\n-- ---------------------------------------------------------------------\n\nimport .Limites_de_sucesiones\nimport topology.instances.real\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir el espacio de nombres `filter`.\n-- ---------------------------------------------------------------------\n\nopen filter\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir el contexto `topological_space`\n-- ---------------------------------------------------------------------\n\nopen_locale topological_space\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Iniciar el espacio de nombres `oculto`-\n-- ---------------------------------------------------------------------\n\nnamespace oculto\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar\n-- ---------------------------------------------------------------------\n\nlemma is_limit_iff_tendsto\n  (a : \u2115 \u2192 \u211d)\n  (l : \u211d)\n  : is_limit a l \u2194 tendsto a at_top (\ud835\udcdd l) :=\nbegin\n  rw metric.tendsto_at_top,\n  congr',\nend\n\n-- this is `is_limit_add`\n\nexample\n  (a b : \u2115 \u2192 \u211d)\n  (l m : \u211d)\n  : is_limit a l \u2192 is_limit b m \u2192 is_limit (a + b) (l + m) :=\nbegin\n  repeat {rw is_limit_iff_tendsto},\n  exact tendsto.add,\nend\n\n-- this is `is_limit_mul`\n\nexample\n  (a b : \u2115 \u2192 \u211d)\n  (l m : \u211d)\n  : is_limit a l \u2192 is_limit b m \u2192 is_limit (a * b) (l * m) :=\nbegin\n  repeat {rw is_limit_iff_tendsto},\n  exact tendsto.mul,\nend\n\nend oculto\n", "meta": {"author": "jaalonso", "repo": "Formalizacion_de_las_matematicas_en_Lean", "sha": "52bf9748d17a22d819cac19502fca9bc7340f7ae", "save_path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean/Formalizacion_de_las_matematicas_en_Lean-52bf9748d17a22d819cac19502fca9bc7340f7ae/src/3_Limites/Limites_mediante_filtros.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7297780711933547}}
{"text": "import tactic\n/--------------------------------------------------------------------------\n\nRecall that\n  ``\u00ac P`` is ``P \u2192 false``,\n  ``\u00ac (\u00ac P)`` is ``(P \u2192 false) \u2192 false``, and so on.\n\nDelete the ``sorry,`` below and replace them with a legitimate proof.\n\n--------------------------------------------------------------------------/\n\ntheorem self_imp_not_not_self (P : Prop) : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  sorry,\nend\n\ntheorem contrapositive (P Q : Prop) : (P \u2192 Q) \u2192 (\u00acQ \u2192 \u00acP) :=\nbegin\n  sorry,\nend\n\nexample (P : Prop) : \u00ac (\u00ac (\u00ac P)) \u2192 \u00ac P :=\nbegin\n  sorry,\nend", "meta": {"author": "awainverse", "repo": "mc2022-lean-examples", "sha": "91d4db1f785dbaa806831f3cdd8846ca45e2891e", "save_path": "github-repos/lean/awainverse-mc2022-lean-examples", "path": "github-repos/lean/awainverse-mc2022-lean-examples/mc2022-lean-examples-91d4db1f785dbaa806831f3cdd8846ca45e2891e/src/day1/negation_examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7297071772995531}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.int.gcd\nimport tactic.abel\nimport data.list.rotate\n\n/-!\n# Congruences modulo a natural number\n\nThis file defines the equivalence relation `a \u2261 b [MOD n]` on the natural numbers,\nand proves basic properties about it such as the Chinese Remainder Theorem\n`modeq_and_modeq_iff_modeq_mul`.\n\n## Notations\n\n`a \u2261 b [MOD n]` is notation for `modeq n a b`, which is defined to mean `a % n = b % n`.\n\n## Tags\n\nmodeq, congruence, mod, MOD, modulo\n-/\n\nnamespace nat\n\n/-- Modular equality. `modeq n a b`, or `a \u2261 b [MOD n]`, means\n  that `a - b` is a multiple of `n`. -/\n@[derive decidable]\ndef modeq (n a b : \u2115) := a % n = b % n\n\nnotation a ` \u2261 `:50 b ` [MOD `:50 n `]`:0 := modeq n a b\n\nnamespace modeq\nvariables {n m a b c d : \u2115}\n\n@[refl] protected theorem refl (a : \u2115) : a \u2261 a [MOD n] := @rfl _ _\n\n@[symm] protected theorem symm : a \u2261 b [MOD n] \u2192 b \u2261 a [MOD n] := eq.symm\n\n@[trans] protected theorem trans : a \u2261 b [MOD n] \u2192 b \u2261 c [MOD n] \u2192 a \u2261 c [MOD n] := eq.trans\n\nprotected theorem comm : a \u2261 b [MOD n] \u2194 b \u2261 a [MOD n] := \u27e8nat.modeq.symm, nat.modeq.symm\u27e9\n\ntheorem modeq_zero_iff : a \u2261 0 [MOD n] \u2194 n \u2223 a :=\nby rw [modeq, zero_mod, dvd_iff_mod_eq_zero]\n\ntheorem modeq_iff_dvd : a \u2261 b [MOD n] \u2194 (n:\u2124) \u2223 b - a :=\nby rw [modeq, eq_comm, \u2190 int.coe_nat_inj', int.coe_nat_mod, int.coe_nat_mod,\n   int.mod_eq_mod_iff_mod_sub_eq_zero, int.dvd_iff_mod_eq_zero]\n\ntheorem modeq_of_dvd : (n:\u2124) \u2223 b - a \u2192 a \u2261 b [MOD n] := modeq_iff_dvd.2\ntheorem dvd_of_modeq : a \u2261 b [MOD n] \u2192 (n:\u2124) \u2223 b - a := modeq_iff_dvd.1\n\n/-- A variant of `modeq_iff_dvd` with `nat` divisibility -/\ntheorem modeq_iff_dvd' (h : a \u2264 b) : a \u2261 b [MOD n] \u2194 n \u2223 b - a :=\nby rw [modeq_iff_dvd, \u2190int.coe_nat_dvd, int.coe_nat_sub h]\n\ntheorem mod_modeq (a n) : a % n \u2261 a [MOD n] := nat.mod_mod _ _\n\ntheorem modeq_of_dvd_of_modeq (d : m \u2223 n) (h : a \u2261 b [MOD n]) : a \u2261 b [MOD m] :=\nmodeq_of_dvd $ dvd_trans (int.coe_nat_dvd.2 d) (dvd_of_modeq h)\n\ntheorem modeq_mul_left' (c : \u2115) (h : a \u2261 b [MOD n]) : c * a \u2261 c * b [MOD (c * n)] :=\nby unfold modeq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h]\n\ntheorem modeq_mul_left (c : \u2115) (h : a \u2261 b [MOD n]) : c * a \u2261 c * b [MOD n] :=\nmodeq_of_dvd_of_modeq (dvd_mul_left _ _) $ modeq_mul_left' _ h\n\ntheorem modeq_mul_right' (c : \u2115) (h : a \u2261 b [MOD n]) : a * c \u2261 b * c [MOD (n * c)] :=\nby rw [mul_comm a, mul_comm b, mul_comm n]; exact modeq_mul_left' c h\n\ntheorem modeq_mul_right (c : \u2115) (h : a \u2261 b [MOD n]) : a * c \u2261 b * c [MOD n] :=\nby rw [mul_comm a, mul_comm b]; exact modeq_mul_left c h\n\ntheorem modeq_mul (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : c \u2261 d [MOD n]) : a * c \u2261 b * d [MOD n] :=\n(modeq_mul_left _ h\u2082).trans (modeq_mul_right _ h\u2081)\n\ntheorem modeq_pow (m : \u2115) (h : a \u2261 b [MOD n]) : a ^ m \u2261 b ^ m [MOD n] :=\nbegin\n  induction m with d hd, {refl},\n  rw [pow_succ, pow_succ],\n  exact modeq_mul h hd,\nend\n\ntheorem modeq_add (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : c \u2261 d [MOD n]) : a + c \u2261 b + d [MOD n] :=\nmodeq_of_dvd begin\n  convert dvd_add (dvd_of_modeq h\u2081) (dvd_of_modeq h\u2082) using 1,\n  simp [sub_eq_add_neg, add_left_comm, add_comm],\nend\n\ntheorem modeq_add_cancel_left (h\u2081 : a \u2261 b [MOD n]) (h\u2082 : a + c \u2261 b + d [MOD n]) : c \u2261 d [MOD n] :=\nbegin\n  simp only [modeq_iff_dvd] at *,\n  convert _root_.dvd_sub h\u2082 h\u2081 using 1,\n  simp [sub_eq_add_neg],\n  abel\nend\n\ntheorem modeq_add_cancel_right (h\u2081 : c \u2261 d [MOD n]) (h\u2082 : a + c \u2261 b + d [MOD n]) : a \u2261 b [MOD n] :=\nby rw [add_comm a, add_comm b] at h\u2082; exact modeq_add_cancel_left h\u2081 h\u2082\n\ntheorem modeq_of_modeq_mul_left (m : \u2115) (h : a \u2261 b [MOD m * n]) : a \u2261 b [MOD n] :=\nby rw [modeq_iff_dvd] at *; exact dvd.trans (dvd_mul_left (n : \u2124) (m : \u2124)) h\n\ntheorem modeq_of_modeq_mul_right (m : \u2115) : a \u2261 b [MOD n * m] \u2192 a \u2261 b [MOD n] :=\nmul_comm m n \u25b8 modeq_of_modeq_mul_left _\n\ntheorem modeq_one : a \u2261 b [MOD 1] := modeq_of_dvd $ one_dvd _\n\nlocal attribute [semireducible] int.nonneg\n\n/-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/\ndef chinese_remainder' (h : a \u2261 b [MOD gcd n m]) : {k // k \u2261 a [MOD n] \u2227 k \u2261 b [MOD m]} :=\nif hn : n = 0 then \u27e8a, begin rw [hn, gcd_zero_left] at h, split, refl, exact h end\u27e9 else\nif hm : m = 0 then \u27e8b, begin rw [hm, gcd_zero_right] at h, split, exact h.symm, refl end\u27e9 else\n\u27e8let (c, d) := xgcd n m in int.to_nat (((n * c * b + m * d * a) / gcd n m) % lcm n m), begin\n  rw xgcd_val,\n  dsimp [chinese_remainder'._match_1],\n  rw [modeq_iff_dvd, modeq_iff_dvd,\n    int.to_nat_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero.2 (lcm_ne_zero hn hm)))],\n  have hnonzero : (gcd n m : \u2124) \u2260 0 := begin\n    norm_cast,\n    rw [nat.gcd_eq_zero_iff, not_and],\n    exact \u03bb _, hm,\n  end,\n  have hcoedvd : \u2200 t, (gcd n m : \u2124) \u2223 t * (b - a) := \u03bb t, dvd_mul_of_dvd_right h.dvd_of_modeq _,\n  have := gcd_eq_gcd_ab n m,\n  split; rw [int.mod_def, \u2190 sub_add]; refine dvd_add _ (dvd_mul_of_dvd_left _ _); try {norm_cast},\n  { rw \u2190 sub_eq_iff_eq_add' at this,\n    rw [\u2190 this, sub_mul, \u2190 add_sub_assoc, add_comm, add_sub_assoc, \u2190 mul_sub,\n      int.add_div_of_dvd_left, int.mul_div_cancel_left _ hnonzero,\n      int.mul_div_assoc _ h.dvd_of_modeq, \u2190 sub_sub, sub_self, zero_sub, dvd_neg, mul_assoc],\n    exact dvd_mul_right _ _,\n    norm_cast, exact dvd_mul_right _ _, },\n  { exact dvd_lcm_left n m, },\n  { rw \u2190 sub_eq_iff_eq_add at this,\n    rw [\u2190 this, sub_mul, sub_add, \u2190 mul_sub, int.sub_div_of_dvd, int.mul_div_cancel_left _ hnonzero,\n      int.mul_div_assoc _ h.dvd_of_modeq, \u2190 sub_add, sub_self, zero_add, mul_assoc],\n    exact dvd_mul_right _ _,\n    exact hcoedvd _ },\n  { exact dvd_lcm_right n m, },\nend\u27e9\n\n/-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/\ndef chinese_remainder (co : coprime n m) (a b : \u2115) : {k // k \u2261 a [MOD n] \u2227 k \u2261 b [MOD m]} :=\nchinese_remainder' (by convert modeq_one)\n\nlemma modeq_and_modeq_iff_modeq_mul {a b m n : \u2115} (hmn : coprime m n) :\n  a \u2261 b [MOD m] \u2227 a \u2261 b [MOD n] \u2194 (a \u2261 b [MOD m * n]) :=\n\u27e8\u03bb h, begin\n    rw [nat.modeq.modeq_iff_dvd, nat.modeq.modeq_iff_dvd, \u2190 int.dvd_nat_abs,\n      int.coe_nat_dvd, \u2190 int.dvd_nat_abs, int.coe_nat_dvd] at h,\n    rw [nat.modeq.modeq_iff_dvd, \u2190 int.dvd_nat_abs, int.coe_nat_dvd],\n    exact hmn.mul_dvd_of_dvd_of_dvd h.1 h.2\n  end,\n\u03bb h, \u27e8nat.modeq.modeq_of_modeq_mul_right _ h, nat.modeq.modeq_of_modeq_mul_left _ h\u27e9\u27e9\n\nlemma coprime_of_mul_modeq_one (b : \u2115) {a n : \u2115} (h : a * b \u2261 1 [MOD n]) : coprime a n :=\nnat.coprime_of_dvd' (\u03bb k kp \u27e8ka, hka\u27e9 \u27e8kb, hkb\u27e9, int.coe_nat_dvd.1 begin\n  rw [hka, hkb, modeq_iff_dvd] at h,\n  cases h with z hz,\n  rw [sub_eq_iff_eq_add] at hz,\n  rw [hz, int.coe_nat_mul, mul_assoc, mul_assoc, int.coe_nat_mul, \u2190 mul_add],\n  exact dvd_mul_right _ _,\nend)\n\nend modeq\n\n@[simp] lemma mod_mul_right_mod (a b c : \u2115) : a % (b * c) % b = a % b :=\nmodeq.modeq_of_modeq_mul_right _ (modeq.mod_modeq _ _)\n\n@[simp] lemma mod_mul_left_mod (a b c : \u2115) : a % (b * c) % c = a % c :=\nmodeq.modeq_of_modeq_mul_left _ (modeq.mod_modeq _ _)\n\nlemma div_mod_eq_mod_mul_div (a b c : \u2115) : a / b % c = a % (b * c) / b :=\nif hb0 : b = 0 then by simp [hb0]\nelse by rw [\u2190 @add_right_cancel_iff _ _ (c * (a / b / c)), mod_add_div, nat.div_div_eq_div_mul,\n  \u2190 nat.mul_right_inj (nat.pos_of_ne_zero hb0),\u2190 @add_left_cancel_iff _ _ (a % b), mod_add_div,\n  mul_add, \u2190 @add_left_cancel_iff _ _ (a % (b * c) % b), add_left_comm,\n  \u2190 add_assoc (a % (b * c) % b), mod_add_div, \u2190 mul_assoc, mod_add_div, mod_mul_right_mod]\n\nlemma add_mod_add_ite (a b c : \u2115) :\n  (a + b) % c + (if c \u2264 a % c + b % c then c else 0) = a % c + b % c :=\nhave (a + b) % c = (a % c + b % c) % c,\n  from nat.modeq.modeq_add (nat.modeq.mod_modeq _ _).symm (nat.modeq.mod_modeq _ _).symm,\nif hc0 : c = 0 then by simp [hc0]\nelse\n  begin\n    rw this,\n    split_ifs,\n    { have h2 : (a % c + b % c) / c < 2,\n        from nat.div_lt_of_lt_mul (by rw mul_two;\n          exact add_lt_add (nat.mod_lt _ (nat.pos_of_ne_zero hc0))\n            (nat.mod_lt _ (nat.pos_of_ne_zero hc0))),\n      have h0 : 0 <  (a % c + b % c) / c, from nat.div_pos h (nat.pos_of_ne_zero hc0),\n      rw [\u2190 @add_right_cancel_iff _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc,\n        mod_add_div, le_antisymm (le_of_lt_succ h2) h0, mul_one, add_comm] },\n    { rw [nat.mod_eq_of_lt (lt_of_not_ge h), add_zero] }\n  end\n\nlemma add_mod_of_add_mod_lt {a b c : \u2115} (hc : a % c + b % c < c) :\n  (a + b) % c = a % c + b % c :=\n by rw [\u2190 add_mod_add_ite, if_neg (not_le_of_lt hc), add_zero]\n\nlemma add_mod_add_of_le_add_mod {a b c : \u2115} (hc : c \u2264 a % c + b % c) :\n  (a + b) % c + c = a % c + b % c :=\nby rw [\u2190 add_mod_add_ite, if_pos hc]\n\nlemma add_div {a b c : \u2115} (hc0 : 0 < c) : (a + b) / c = a / c + b / c +\n  if c \u2264 a % c + b % c then 1 else 0 :=\nbegin\n  rw [\u2190 nat.mul_right_inj hc0, \u2190 @add_left_cancel_iff _ _ ((a + b) % c + a % c + b % c)],\n  suffices : (a + b) % c + c * ((a + b) / c) + a % c + b % c =\n    a % c + c * (a / c) + (b % c + c * (b / c)) + c * (if c \u2264 a % c + b % c then 1 else 0) +\n      (a + b) % c,\n  { simpa only [mul_add, add_comm, add_left_comm, add_assoc] },\n  rw [mod_add_div, mod_add_div, mod_add_div, mul_ite, add_assoc, add_assoc],\n  conv_lhs { rw \u2190 add_mod_add_ite },\n  simp, ac_refl\nend\n\nlemma add_div_eq_of_add_mod_lt {a b c : \u2115} (hc : a % c + b % c < c) :\n  (a + b) / c = a / c + b / c :=\nif hc0 : c = 0 then by simp [hc0]\nelse by rw [add_div (nat.pos_of_ne_zero hc0), if_neg (not_le_of_lt hc), add_zero]\n\nprotected lemma add_div_of_dvd_right {a b c : \u2115} (hca : c \u2223 a) :\n  (a + b) / c = a / c + b / c :=\nif h : c = 0 then by simp [h] else add_div_eq_of_add_mod_lt begin\n  rw [nat.mod_eq_zero_of_dvd hca, zero_add],\n  exact nat.mod_lt _ (pos_iff_ne_zero.mpr h),\nend\n\nprotected lemma add_div_of_dvd_left {a b c : \u2115} (hca : c \u2223 b) :\n  (a + b) / c = a / c + b / c :=\nby rwa [add_comm, nat.add_div_of_dvd_right, add_comm]\n\nlemma add_div_eq_of_le_mod_add_mod {a b c : \u2115} (hc : c \u2264 a % c + b % c) (hc0 : 0 < c) :\n  (a + b) / c = a / c + b / c + 1 :=\nby rw [add_div hc0, if_pos hc]\n\nlemma add_div_le_add_div (a b c : \u2115) : a / c + b / c \u2264 (a + b) / c :=\nif hc0 : c = 0 then by simp [hc0]\nelse by rw [nat.add_div (nat.pos_of_ne_zero hc0)]; exact le_add_right _ _\n\nlemma le_mod_add_mod_of_dvd_add_of_not_dvd {a b c : \u2115} (h : c \u2223 a + b) (ha : \u00ac c \u2223 a) :\n  c \u2264 a % c + b % c :=\nby_contradiction $ \u03bb hc,\n  have (a + b) % c = a % c + b % c, from add_mod_of_add_mod_lt (lt_of_not_ge hc),\n  by simp [dvd_iff_mod_eq_zero, *] at *\n\nlemma odd_mul_odd {n m : \u2115} : n % 2 = 1 \u2192 m % 2 = 1 \u2192 (n * m) % 2 = 1 :=\nby simpa [nat.modeq] using @nat.modeq.modeq_mul 2 n 1 m 1\n\nlemma odd_mul_odd_div_two {m n : \u2115} (hm1 : m % 2 = 1) (hn1 : n % 2 = 1) :\n  (m * n) / 2 = m * (n / 2) + m / 2 :=\nhave hm0 : 0 < m := nat.pos_of_ne_zero (\u03bb h, by simp * at *),\nhave hn0 : 0 < n := nat.pos_of_ne_zero (\u03bb h, by simp * at *),\n(nat.mul_right_inj (show 0 < 2, from dec_trivial)).1 $\nby rw [mul_add, two_mul_odd_div_two hm1, mul_left_comm, two_mul_odd_div_two hn1,\n  two_mul_odd_div_two (nat.odd_mul_odd hm1 hn1), nat.mul_sub_left_distrib, mul_one,\n  \u2190 nat.add_sub_assoc hm0, nat.sub_add_cancel (le_mul_of_one_le_right (nat.zero_le _) hn0)]\n\nlemma odd_of_mod_four_eq_one {n : \u2115} : n % 4 = 1 \u2192 n % 2 = 1 :=\nby simpa [modeq, show 2 * 2 = 4, by norm_num] using @modeq.modeq_of_modeq_mul_left 2 n 1 2\n\nlemma odd_of_mod_four_eq_three {n : \u2115} : n % 4 = 3 \u2192 n % 2 = 1 :=\nby simpa [modeq, show 2 * 2 = 4, by norm_num, show 3 % 4 = 3, by norm_num]\n  using @modeq.modeq_of_modeq_mul_left 2 n 3 2\n\nend nat\n\nnamespace list\nvariable {\u03b1 : Type*}\n\nlemma nth_rotate : \u2200 {l : list \u03b1} {n m : \u2115} (hml : m < l.length),\n  (l.rotate n).nth m = l.nth ((m + n) % l.length)\n| []     n     m hml := (nat.not_lt_zero _ hml).elim\n| l      0     m hml := by simp [nat.mod_eq_of_lt hml]\n| (a::l) (n+1) m hml :=\nhave h\u2083 : m < list.length (l ++ [a]), by simpa using hml,\n(lt_or_eq_of_le (nat.le_of_lt_succ $ nat.mod_lt (m + n)\n  (lt_of_le_of_lt (nat.zero_le _) hml))).elim\n(\u03bb hml',\n  have h\u2081 : (m + (n + 1)) % ((a :: l : list \u03b1).length) =\n      (m + n) % ((a :: l : list \u03b1).length) + 1,\n    from calc (m + (n + 1)) % (l.length + 1) =\n      ((m + n) % (l.length + 1) + 1) % (l.length + 1) :\n      add_assoc m n 1 \u25b8 nat.modeq.modeq_add (nat.mod_mod _ _).symm rfl\n    ... = (m + n) % (l.length + 1) + 1 : nat.mod_eq_of_lt (nat.succ_lt_succ hml'),\n  have h\u2082 : (m + n) % (l ++ [a]).length < l.length, by simpa [nat.add_one] using hml',\n  by rw [list.rotate_cons_succ, nth_rotate h\u2083, list.nth_append h\u2082, h\u2081, list.nth]; simp)\n(\u03bb hml',\n  have h\u2081 : (m + (n + 1)) % (l.length + 1) = 0,\n    from calc (m + (n + 1)) % (l.length + 1) = (l.length + 1) % (l.length + 1) :\n      add_assoc m n 1 \u25b8 nat.modeq.modeq_add\n        (hml'.trans (nat.mod_eq_of_lt (nat.lt_succ_self _)).symm) rfl\n    ... = 0 : by simp,\n  by rw [list.length, list.rotate_cons_succ, nth_rotate h\u2083, list.length_append,\n    list.length_cons, list.length, zero_add, hml', h\u2081, list.nth_concat_length]; refl)\n\nlemma rotate_eq_self_iff_eq_repeat [h\u03b1 : nonempty \u03b1] : \u2200 {l : list \u03b1},\n  (\u2200 n, l.rotate n = l) \u2194 \u2203 a, l = list.repeat a l.length\n| []     := \u27e8\u03bb h, nonempty.elim h\u03b1 (\u03bb a, \u27e8a, by simp\u27e9), by simp\u27e9\n| (a::l) :=\n\u27e8\u03bb h, \u27e8a, list.ext_le (by simp) $ \u03bb n hn h\u2081,\n  begin\n    rw [\u2190 option.some_inj, \u2190 list.nth_le_nth],\n    conv {to_lhs, rw \u2190 h ((list.length (a :: l)) - n)},\n    rw [nth_rotate hn, nat.add_sub_cancel' (le_of_lt hn),\n      nat.mod_self, nth_le_repeat], refl\n  end\u27e9,\n  \u03bb \u27e8a, ha\u27e9 n, ha.symm \u25b8 list.ext_le (by simp)\n    (\u03bb m hm h,\n      have hm' : (m + n) % (list.repeat a (list.length (a :: l))).length < list.length (a :: l),\n        by rw list.length_repeat; exact nat.mod_lt _ (nat.succ_pos _),\n      by rw [nth_le_repeat, \u2190 option.some_inj, \u2190 list.nth_le_nth, nth_rotate h, list.nth_le_nth,\n        nth_le_repeat]; simp * at *)\u27e9\n\nend list\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.729707175074736}}
{"text": "import ring_theory.polynomial.cyclotomic.basic\nimport ring_theory.polynomial.cyclotomic.eval\nimport algebra\nimport tactic\nimport cyclotomic\nimport data.fintype.units\nimport number_theory.multiplicity\n\nvariables {a n : \u2115}\n\nlemma order_of_units_le_totient [ne_zero n] (h_coprime : a.coprime n) : \norder_of (zmod.unit_of_coprime a h_coprime) \u2264 n.totient :=\nbegin\n  rw \u2190zmod.card_units_eq_totient,\n  exact order_of_le_card_univ,\nend\n\nlemma order_of_units_pos [ne_zero n] (h_coprime : a.coprime n) : \n0 < order_of (zmod.unit_of_coprime a h_coprime) :=\nbegin\n  apply order_of_pos,\nend\n\nlemma nat_dvd_mul_pow_of_one_le (a b c : \u2115) : 1 \u2264 c \u2192 a \u2223 b * a ^ c :=\nbegin\n  intro h_le,\n  use b * a ^ (c - 1),\n  rw [mul_comm a _, mul_assoc, mul_eq_mul_left_iff],\n  left,\n  rw [\u2190 nat.sub_add_cancel h_le, pow_add, pow_one, nat.sub_add_cancel h_le],\nend\n\nlemma mul_pow_dvd_eq_mul_pow_sub (a b c : \u2115) (h_pos : 0 < b) : 1 \u2264 c \n\u2192 a * b ^ c / b = a * b ^ (c - 1) := \nbegin\n  intro hc,\n  have h_pow_sub_add : b ^ (c - 1) * b = b ^ c,\n  {\n    nth_rewrite 1 \u2190 pow_one b,\n    rw [ \u2190 pow_add, nat.sub_add_cancel hc],\n  },\n  have h_dvd : b \u2223 b ^ c,\n  {\n    use b ^ (c - 1),\n    rw [\u2190 h_pow_sub_add, mul_comm],\n  },\n  rw [nat.mul_div_assoc a h_dvd, mul_eq_mul_left_iff],\n  left,\n  rw [\u2190 h_pow_sub_add, nat.mul_div_cancel],\n  exact h_pos,\nend\n\nlemma dvd_pow_order_mul_sub_one (a b c : \u2115) (h_coprime : a.coprime b) (ha : 1 \u2264 a) :\nb \u2223 a ^ (order_of (zmod.unit_of_coprime a h_coprime) * c) - 1 :=\nbegin\n  have h_a_pos : 0 < a := by linarith,\n  have h_order_dvd : order_of (zmod.unit_of_coprime a h_coprime) \u2223 \n  order_of (zmod.unit_of_coprime a h_coprime) * c := by { use c, },\n  rw [order_of_dvd_iff_pow_eq_one, \u2190 units.eq_iff, \u2190 sub_eq_zero, units.coe_pow,\n  zmod.coe_unit_of_coprime, units.coe_one, \u2190 nat.cast_one, \u2190 nat.cast_pow,\n  \u2190 nat.cast_sub \n  (nat.one_le_pow (order_of (zmod.unit_of_coprime a h_coprime) * c) a h_a_pos), \n  \u2190 int.cast_coe_nat, zmod.int_coe_zmod_eq_zero_iff_dvd,\n  int.coe_nat_dvd] at h_order_dvd,\n  exact h_order_dvd,\nend\n\nlemma four_dvd_pow_sub_one_of_two_dvd (h_coprime : a.coprime 2) :\n2 \u2223 n \u2192 4 \u2223 a ^ n - 1 :=\nbegin\n  intro h_dvd,\n  cases h_dvd with k hk,\n  subst hk,\n  cases em (k = 0) with h_k_eq_zero h_k_ne_zero,\n  {\n    subst h_k_eq_zero,\n    simp only [mul_zero, pow_zero, dvd_zero],\n  },\n  {\n    rw [mul_comm, pow_mul],\n    set b := a ^ k with hb,\n    have h_odd : odd b,\n    {\n      rw [hb, nat.odd_iff_not_even, nat.even_pow' h_k_ne_zero],\n      intro h_even,\n      cases h_even with a' ha',\n      rw \u2190 two_mul at ha',\n      rw ha' at h_coprime,\n      apply nat.not_coprime_of_dvd_of_dvd one_lt_two _ _ h_coprime,\n      { use a', },\n      { refl, }\n    },\n    cases h_odd with b' hb',\n    use ((b - 1) / 2) * ((b + 1) / 2),\n    rw [hb', add_assoc, one_add_one_eq_two],\n    nth_rewrite 6 \u2190 mul_one 2,\n    simp only [nat.add_succ_sub_one, add_zero, nat.mul_div_right, \n    zero_lt_bit0, nat.lt_one_iff, \u2190 mul_add],\n    ring_nf,\n  }\nend\n\nlemma nat_multiplicity_self (a : \u2115) : 2 \u2264 a \u2192 multiplicity a a = 1 :=\nbegin\n  intro ha,\n  apply multiplicity.multiplicity_self,\n  {\n    rw nat.is_unit_iff,\n    linarith,\n  },\n  { linarith, }\nend\n\nlemma sub_one_mul_lt_pow_sub_one (a b : \u2115) (hb : 1 < b) : \n1 < a \u2192 (a - 1) * b < a ^ b - 1 :=\nbegin\n  intro ha,\n  have hpos : 0 < a := by linarith,\n  rw \u2190 int.coe_nat_lt,\n  simp only [algebra_map.coe_one, coe_pow, int.coe_nat_mul, \n  int.coe_nat_sub (le_of_lt ha), int.coe_nat_sub (nat.one_le_pow b a hpos)],\n  rw [\u2190 int.coe_nat_lt, int.coe_nat_one] at ha,\n  rw \u2190 mul_geom_sum,\n  apply int.mul_lt_mul_of_pos_left,\n  {\n    have h_b_eq_sum : (b : \u2124) = (finset.range b).sum (\u03bb (i : \u2115), 1) := by {\n      simp only [finset.sum_const, finset.card_range, nat.smul_one_eq_coe],\n    },\n    rw h_b_eq_sum,\n    apply finset.sum_lt_sum,\n    {\n      intros i hi,\n      rw [\u2190 int.coe_nat_pow, \u2190 nat.cast_one, int.coe_nat_le],\n      exact nat.one_le_pow i a hpos,\n    },\n    {\n      use 1,\n      rw [finset.mem_range, pow_one],\n      split,\n      { exact hb, },\n      { exact ha }\n    }\n  },\n  { linarith, }\nend\n\nlemma nat_pow_le_one_iff (a b : \u2115) : a ^ b \u2264 1 \u2194 a \u2264 1 \u2228 b = 0 :=\nbegin\n  split,\n  {\n    intro h_le_one,\n    cases em (b = 0) with hb hb,\n    {\n      right,\n      exact hb,\n    },\n    {\n      left,\n      have h_one_le_b : 1 \u2264 b,\n      {\n        cases b,\n        {\n          exfalso,\n          apply hb,\n          refl,\n        },\n        {\n          rw nat.succ_eq_add_one,\n          linarith,\n        }\n      },\n      rw [\u2190 one_pow b, nat.pow_le_iff_le_left h_one_le_b] at h_le_one,\n      exact h_le_one,\n    }\n  },\n  {\n    intro h_or,\n    cases h_or,\n    {\n      rw \u2190 one_pow b,\n      apply nat.pow_le_pow_of_le_left h_or,\n    },\n    {\n      rw [h_or, pow_zero],\n    }\n  }\nend\n\nlemma order_of_two_mod_three_eq_two (h_coprime : (2 : \u2115).coprime 3) : \norder_of (zmod.unit_of_coprime 2 h_coprime) = 2 :=\nbegin\n  haveI : nat.prime 2,\n  { exact nat.prime_two, },\n  apply order_of_eq_prime,\n  {\n    rw [\u2190 units.eq_iff, units.coe_pow, zmod.coe_unit_of_coprime, \n    units.coe_one, nat.cast_two],\n    ring,\n  },\n  {\n    intro h,\n    rw [\u2190 units.eq_iff, zmod.coe_unit_of_coprime, \n    units.coe_one, nat.cast_two, \u2190 sub_eq_zero] at h,\n    norm_num at h,\n  }\nend\n\nlemma order_of_eq_one_in_units_two (h_coprime : a.coprime 2) :\norder_of (zmod.unit_of_coprime a h_coprime) = 1 :=\nbegin\n  simp only [order_of_eq_one_iff, eq_iff_true_of_subsingleton],\nend\n\nlemma three_mul_le_pow_sub (x : \u2115) : (2 + 1) * ((x + 5) : \u2124) \u2264 2 ^ (x + 5) - 1 := \nbegin\n  induction x with x hi,\n  {\n    norm_num,\n  },\n  {\n    transitivity (2 ^ (x + 5) - 1 + ((2 : \u2124) + 1)),\n    {\n      rw [nat.cast_succ, add_assoc],\n      nth_rewrite 2 add_comm,\n      rw [\u2190 add_assoc, mul_add, mul_one],\n      exact int.add_le_add_right hi _,\n    },\n    {\n      rw [sub_add_add_cancel, nat.succ_eq_add_one],\n      nth_rewrite 3 add_comm,\n      rw [add_assoc],\n      repeat { rw pow_add, },\n      set two_pow := (2 : \u2124) ^ x with h_pow,\n      have h_pow_nonneg: 1 \u2264 two_pow,\n      {\n        rw [h_pow, \u2190 nat.cast_one, \u2190 nat.cast_bit0, \u2190 nat.cast_pow,\n        nat.cast_le],\n        apply nat.one_le_pow,\n        linarith,\n      },\n      norm_num,\n      linarith,\n    }\n  }\nend\n\nlemma two_mul_le_pow_sub_one (x : \u2124) (a : \u2115) (hx : 2 < x) (ha : 2 \u2264 a) : \n2 * (x - 1) * (a : \u2124) \u2264 x ^ a - 1 :=\nbegin\n  nth_rewrite 1 mul_comm,\n  rw [mul_assoc, \u2190 mul_geom_sum, mul_le_mul_left],\n  {\n    cases a,\n    {\n      linarith,\n    },\n    {\n      rw nat.succ_eq_add_one at ha,\n      rw nat.succ_eq_add_one,\n      have h_one_le_a : 1 \u2264 a + 1 := by linarith,\n      rw [finset.range_eq_Ico, \u2190 finset.Ico_union_Ico_eq_Ico zero_le_one h_one_le_a,\n      finset.sum_union (finset.Ico_disjoint_Ico_consecutive 0 1 (a + 1)), \n      nat.cast_succ, nat.Ico_succ_singleton, finset.sum_singleton, pow_zero],\n      transitivity 1 + 3 * (a : \u2124),\n      { linarith, },\n      {\n        apply int.add_le_add_left _ 1,\n        have h_mul_a_eq_sum : 3 * (a : \u2124) = (finset.Ico 1 (a + 1)).sum (\u03bb (i : \u2115), 3),\n        {\n          simp only [finset.sum_const, nat.card_Ico, nat.add_succ_sub_one, \n          add_zero, nsmul_eq_mul, mul_comm],\n        },\n        rw h_mul_a_eq_sum,\n        apply finset.sum_le_sum,\n        intros i hi,\n        transitivity x,\n        { linarith, },\n        {\n          nth_rewrite 0 \u2190 pow_one x,\n          apply pow_le_pow,\n          { linarith, },\n          {\n            rw finset.mem_Ico at hi,\n            exact hi.left,\n          }\n        }\n      }\n    }\n  },\n  { linarith, }\nend\n\nlemma part_enat_add_le_add_iff_left {x y z : part_enat} (hz : z \u2260 \u22a4) :\nz + x \u2264 z + y \u2194 x \u2264 y := \nbegin\n  repeat {rw le_iff_lt_or_eq},\n  rw [part_enat.add_lt_add_iff_left hz, part_enat.add_left_cancel_iff hz],\nend\n\nlemma int_char_zero : char_zero \u2124 :=\nbegin\n  apply char_zero_of_inj_zero,\n  intros n hn,\n  rw \u2190 nat.cast_zero at hn,\n  exact int.coe_nat_inj hn,\nend\n\nlemma le_of_order_mul_pow_eq_order_mul_pow (p q t\u2081 t\u2082 : \u2115) \n(h_p_prime : p.prime) (h_q_prime : q.prime) \n(h_p_coprime : a.coprime p) (h_q_coprime : a.coprime q)\n(h_one_le_first : 1 \u2264 t\u2081) (h_one_le_second : 1 \u2264 t\u2082) :\norder_of (zmod.unit_of_coprime a h_p_coprime) * p ^ t\u2081 \n= order_of (zmod.unit_of_coprime a h_q_coprime) * q ^ t\u2082 \u2192 p \u2264 q :=\nbegin\n  intro h,\n  cases em (p = q) with h_eq h_ne,\n  { rw h_eq, },\n  {\n    have h_p_dvd_mul : p \u2223 order_of (zmod.unit_of_coprime a h_q_coprime) * q ^ t\u2082,\n    {\n      use order_of (zmod.unit_of_coprime a h_p_coprime) * p ^ (t\u2081 - 1),\n      rw [\u2190 h, \u2190 mul_assoc, mul_comm p _, mul_assoc, mul_eq_mul_left_iff],\n      left,\n      rw [\u2190 nat.sub_add_cancel h_one_le_first, pow_add, mul_comm,\n      pow_one, nat.add_succ_sub_one, add_zero],\n    },\n    rw nat.prime.dvd_mul h_p_prime at h_p_dvd_mul,\n    cases h_p_dvd_mul with h_dvd h_dvd,\n    swap,\n    {\n      exfalso,\n      apply h_ne,\n      rw \u2190 nat.prime_dvd_prime_iff_eq h_p_prime h_q_prime,\n      exact nat.prime.dvd_of_dvd_pow h_p_prime h_dvd,\n    },\n    {\n      haveI : ne_zero q := \u27e8 nat.prime.ne_zero h_q_prime, \u27e9, \n      transitivity order_of (zmod.unit_of_coprime a h_q_coprime),\n      { exact nat.le_of_dvd (order_of_units_pos h_q_coprime) h_dvd, },\n      {\n        transitivity q - 1,\n        {\n          rw \u2190 nat.totient_prime h_q_prime,\n          exact order_of_units_le_totient h_q_coprime,\n        },\n        {\n          exact tsub_le_self,\n        }\n      }\n    }\n  }\nend\n\n\ntheorem exists_prime_of_order (hn : 1 < n) (ha : 1 < a) \n(h_exception_1 : \u00ac(n = 2 \u2227 (\u2203 (s : \u2115), a = 2 ^ s - 1))) \n(h_exception_2 : \u00ac(n = 6 \u2227 a = 2)) : \u2203 (p : \u2115) (h_coprime : (a.coprime p)), \n(nat.prime p) \u2227 order_of(zmod.unit_of_coprime a h_coprime) = n :=\nbegin\n  by_contra,\n  simp only [not_exists, not_and] at h,\n  have hpos_n : 0 < n := by {transitivity 1, exact zero_lt_one, exact hn, },\n  set \u03a6 := (polynomial.eval \u2191a (polynomial.cyclotomic n \u2124)).to_nat with h_Phi_def,\n  have h_one_le_a_int : 1 \u2264 (a : \u2124) := by linarith,\n  have h_Phi : 1 < \u03a6,\n  {\n    simp only [int.lt_to_nat, nat.cast_one],\n    set a' := (a : \u2124),\n    have h_one_lt_a' : 1 < a' := by linarith,\n    have h_one_le : 1 \u2264 (a' - 1) ^ (n.totient),\n    {\n      apply one_le_pow_of_one_le,\n      linarith,\n    },\n    exact lt_of_le_of_lt h_one_le (X_sub_one_pow_lt_cyclotomic hn h_one_lt_a'),\n  },\n  have h_one_le : \u2200 (k : \u2115), 1 \u2264 a ^ k,\n  { \n    intro k,\n    apply nat.one_le_pow,\n    apply nat.pos_of_ne_zero,\n    intro h,\n    subst h,\n    linarith,\n  },\n  have h_one_lt : \u2200 (k : \u2115), 0 < k \u2192 1 < a ^ k,\n  { \n    intros k hk,\n    exact nat.one_lt_pow k a hk ha,\n  },\n  have h_one_lt_int : \u2200 (k : \u2115), 0 < k \u2192 1 < (a : \u2124) ^ k,\n  {\n    intros k hk,\n    rw [\u2190 int.coe_nat_pow, \u2190 nat.cast_one, int.coe_nat_lt],\n    exact h_one_lt k hk,\n  },\n  cases h_primes : \u03a6.factors with p others,\n  { rw nat.factors_eq_nil at h_primes, cases h_primes, linarith, linarith, },\n  have h_p_in_factors : p \u2208 \u03a6.factors := by { rw h_primes, exact list.mem_cons_self p _},\n  have h_p_prime : p.prime := by exact nat.prime_of_mem_factors h_p_in_factors,\n  have h_p_prime_fact : fact (p.prime) := by { rw fact_iff, exact h_p_prime },\n  have h_coprime : \u2200 (d : \u2115) (h_dvd : d \u2223 \u03a6), a.coprime d,\n  {\n    intros d h_dvd,\n    have h_dvd' : d \u2223 a ^ n - 1,\n    {\n      apply nat.dvd_trans h_dvd _,\n      rw \u2190 int.coe_nat_dvd,\n      have h_one_le_pow : 1 \u2264 a ^ n := \n      by exact one_le_pow_of_one_le (le_of_lt ha) n,\n      have h_one_lt_coe_a : 1 < (a : \u2124) := by linarith,\n      have h_eq_eval : (a : \u2124) ^ n - 1 = polynomial.eval (a : \u2124) (polynomial.X ^ n - 1) :=\n      by simp only [polynomial.eval_sub, polynomial.eval_pow, \n      polynomial.eval_X, polynomial.eval_one],\n      rw [int.coe_nat_sub h_one_le_pow, int.coe_nat_pow, nat.cast_one,\n      int.to_nat_of_nonneg (polynomial.cyclotomic_nonneg n (le_of_lt h_one_lt_coe_a)),\n      h_eq_eval],\n      exact polynomial.eval_dvd (polynomial.cyclotomic.dvd_X_pow_sub_one n \u2124),\n    },\n    cases h_dvd' with t h_dvd',\n    have h_pos_t : 0 < t,\n    {\n      apply nat.pos_of_ne_zero,\n      intro h,\n      subst h,\n      simp only [mul_zero, tsub_eq_zero_iff_le, \n      pow_le_one_iff (nat_ne_zero_of_pos hpos_n)] at h_dvd',\n      linarith,\n    },\n    have h_dvd_t : t \u2223 a ^ n - 1 := by { rw h_dvd', exact dvd_mul_left t d },\n    have h_div : (a ^ n - 1) / t = d := by exact nat.div_eq_of_eq_mul_left h_pos_t h_dvd',\n    rw \u2190 h_div,\n    apply nat.coprime.coprime_div_right _ h_dvd_t,\n    have h_a_pow_sub_one_eq : a ^ n - 1 = (a ^ (n - 1) - 1) * a + (a - 1),\n    {\n      apply int.coe_nat_inj,\n      rw [int.coe_nat_sub (h_one_le n), int.coe_nat_add, int.coe_nat_mul,\n      int.coe_nat_sub (h_one_le (n - 1)), int.coe_nat_sub (le_of_lt ha),\n      int.coe_nat_pow, int.coe_nat_pow, int.coe_nat_one, sub_mul,\n      one_mul, sub_add_sub_cancel, sub_left_inj, \u2190 nat.sub_add_cancel (le_of_lt hn),\n      pow_add, pow_one, nat.add_succ_sub_one, add_zero],\n    },\n    have h_a_eq : a - 1 + 1 = a := by exact nat.sub_add_cancel (le_of_lt ha),\n    have h_cancel : a - 1 + 1 - 1 = a - 1 := \n    by rw [nat.add_succ_sub_one, add_zero],\n    rw [h_a_pow_sub_one_eq, \n    nat.coprime_mul_right_add_right a (a - 1) (a ^ (n - 1) - 1),\n    nat.coprime_comm, \u2190 h_a_eq, h_cancel, \n    nat.coprime_self_add_right],\n    exact nat.coprime_one_right (a - 1),\n  },\n  have h_a_coprime_p : a.coprime p := by exact h_coprime p (nat.dvd_of_mem_factors h_p_in_factors),\n  have h_order_ne_n : \u2200 (p' : \u2115) (h_in_factors : p' \u2208 \u03a6.factors), \u00acorder_of \n  (zmod.unit_of_coprime a (h_coprime p' (nat.dvd_of_mem_factors h_in_factors))) = n :=\n  by { intros p' h_in_factors, \n  exact h p' (h_coprime p' (nat.dvd_of_mem_factors h_in_factors)) \n  (nat.prime_of_mem_factors h_in_factors), },\n  have h_p_dvd : \u2200 (p' : \u2115) (h_in_factors : p' \u2208 \u03a6.factors), p' \u2223 n,\n  {\n    intros p' h_in_factors,\n    by_contra h_not_dvd,\n    apply h_order_ne_n,\n    have h_p'_dvd_int : \u2191p' \u2223 polynomial.eval \u2191a (polynomial.cyclotomic n \u2124),\n    {\n      cases nat.dvd_of_mem_factors h_in_factors with t h_phi_eq,\n      use \u2191t,\n      rw [\u2190 int.coe_nat_mul, \u2190 h_phi_eq, \n      int.to_nat_of_nonneg (polynomial.cyclotomic_nonneg n h_one_le_a_int)],\n    },\n    have h_p'_prime_fact : fact (p'.prime) := \n    by { rw fact_iff, exact nat.prime_of_mem_factors h_in_factors, },\n    have h_order_is_n' : \u2203 (h_coprime : a.coprime p'),\n    order_of(zmod.unit_of_coprime a h_coprime) = n := \n    by exact order_of_eq_iff_is_root_of_cyclotomic \n    h_p'_prime_fact h_not_dvd hpos_n (ne_of_lt ha) h_p'_dvd_int,\n    cases h_order_is_n',\n    exact h_order_is_n'_h,\n    exact h_in_factors,\n  },\n  set ord := order_of (zmod.unit_of_coprime a \n  h_a_coprime_p) with h_ord_def,\n  have h_n_eq_ord_mul_pow : \u2200 (p' : \u2115) (h_in_factors : p' \u2208 \u03a6.factors),\n   \u2203 (t : \u2115), n = order_of (zmod.unit_of_coprime a \n  (h_coprime p' (nat.dvd_of_mem_factors h_in_factors))) * p' ^ t \u2227 1 \u2264 t,\n  {\n    intros p' h_in_factors,\n    set a_unit := zmod.unit_of_coprime a \n    (h_coprime p' (nat.dvd_of_mem_factors h_in_factors)) with h_a_def,\n    have h_root : (polynomial.cyclotomic n (zmod p')).is_root a_unit,\n    {\n      simp only [zmod.coe_unit_of_coprime, polynomial.is_root.def],\n      rw [\u2190 polynomial.map_cyclotomic_int, polynomial.eval_nat_cast_map,\n      eq_int_cast, zmod.int_coe_zmod_eq_zero_iff_dvd, \n      \u2190 int.to_nat_of_nonneg (polynomial.cyclotomic_nonneg n h_one_le_a_int),\n      int.coe_nat_dvd, \u2190 h_Phi_def],\n      exact nat.dvd_of_mem_factors h_in_factors,\n    },\n    have h_p'_prime_fact : fact (p'.prime) := \n    by { rw fact_iff, exact nat.prime_of_mem_factors h_in_factors, },\n    cases prime_dvd_cyclotomic hpos_n h_p'_prime_fact h_root with t ht,\n    use t,\n    split,\n    { exact ht, },\n    { \n      by_contra,\n      simp only [not_le, nat.lt_one_iff] at h,\n      subst h,\n      simp only [pow_zero, mul_one] at ht,\n      haveI : ne_zero p' := \u27e8 nat.prime.ne_zero (nat.prime_of_mem_factors h_in_factors) \u27e9,\n      have h_order_lt_p' : order_of (zmod.unit_of_coprime a \n      (h_coprime p' (nat.dvd_of_mem_factors h_in_factors))) < p',\n      {\n        have h_p'_sub_one_lt : p' - 1 < p' := by exact nat.sub_lt \n        (nat.prime.pos (nat.prime_of_mem_factors h_in_factors)) zero_lt_one,\n        have h_order_le_p'_sub_one : \n        order_of (zmod.unit_of_coprime a (h_coprime p' \n        (nat.dvd_of_mem_factors h_in_factors))) \u2264 p' - 1 := by {\n          rw \u2190 nat.totient_prime (nat.prime_of_mem_factors h_in_factors),\n          exact order_of_units_le_totient (h_coprime p' \n          (nat.dvd_of_mem_factors h_in_factors)),\n        },\n        exact lt_of_le_of_lt h_order_le_p'_sub_one h_p'_sub_one_lt,\n      },\n      apply nat.not_dvd_of_pos_of_lt \n      (order_of_units_pos (h_coprime p' (nat.dvd_of_mem_factors h_in_factors))) h_order_lt_p',\n      rw \u2190 ht,\n      exact h_p_dvd p' h_in_factors,\n    }\n  },\n  have h_eq_prime_pow : \u03a6 = p ^ \u03a6.factors.length,\n  {\n    have h_Phi_pos : \u03a6 \u2260 0 := by linarith,\n    apply nat.eq_prime_pow_of_unique_prime_dvd h_Phi_pos,\n    intros q h_q_prime h_q_dvd_Phi,\n    have h_q_in_factors : q \u2208 \u03a6.factors,\n    {\n      rw nat.mem_factors,\n      split,\n      { exact h_q_prime, },\n      { exact h_q_dvd_Phi, },\n      { linarith, }\n    },\n    cases h_n_eq_ord_mul_pow p h_p_in_factors with t\u2081 h_n_eq\u2081,\n    cases h_n_eq\u2081 with h_n_eq\u2081 h_one_le_t\u2081,\n    cases h_n_eq_ord_mul_pow q h_q_in_factors with t\u2082 h_n_eq\u2082,\n    cases h_n_eq\u2082 with h_n_eq\u2082 h_one_le_t\u2082,\n    rw h_n_eq\u2081 at h_n_eq\u2082,\n    have h_p_le_q : p \u2264 q := by\n    exact le_of_order_mul_pow_eq_order_mul_pow p q t\u2081 t\u2082\n    h_p_prime h_q_prime\n    h_a_coprime_p\n    (h_coprime q h_q_dvd_Phi)\n    h_one_le_t\u2081 h_one_le_t\u2082 h_n_eq\u2082,\n    symmetry' at h_n_eq\u2082,\n    have h_q_le_p : q \u2264 p := by\n    exact le_of_order_mul_pow_eq_order_mul_pow q p t\u2082 t\u2081\n    h_q_prime h_p_prime\n    (h_coprime q h_q_dvd_Phi)\n    h_a_coprime_p\n    h_one_le_t\u2082 h_one_le_t\u2081 h_n_eq\u2082,\n    exact has_le.le.antisymm h_q_le_p h_p_le_q,\n  },\n  have h_prime_square_not_dvd : p ^ 2 \u2223 \u03a6 \u2192 (p = 2 \u2227 n = 2),\n  {\n    intro h_square_dvd,\n    have h_Phi_mul_pow_sub_one_dvd : \u03a6 * (a ^ (n / p) - 1) \u2223 \n    (a ^ n - 1),\n    {\n      have h_one_lt_coe_a : 1 < (a : \u2124) := by linarith,\n      have h_eq_eval : (a : \u2124) ^ n - 1 = polynomial.eval (a : \u2124) (polynomial.X ^ n - 1) :=\n      by simp only [polynomial.eval_sub, polynomial.eval_pow, \n      polynomial.eval_X, polynomial.eval_one],\n      have h_eq_eval' : (a : \u2124) ^ (n / p) - 1 = \n      polynomial.eval (a : \u2124) (polynomial.X ^ (n / p) - 1) :=\n      by simp only [polynomial.eval_sub, polynomial.eval_pow, \n      polynomial.eval_X, polynomial.eval_one],\n      rw [\u2190 int.coe_nat_dvd, h_Phi_def, nat.cast_mul, \n      int.coe_nat_sub (one_le_pow_of_one_le (le_of_lt ha) n), \n      int.coe_nat_pow, nat.cast_one,\n      int.to_nat_of_nonneg (polynomial.cyclotomic_nonneg n (le_of_lt h_one_lt_coe_a)),\n      h_eq_eval, int.coe_nat_sub (one_le_pow_of_one_le (le_of_lt ha) (n / p)), \n      int.coe_nat_pow, nat.cast_one, h_eq_eval', \u2190 polynomial.eval_mul],\n      apply polynomial.eval_dvd,\n      have h_n_div_p_dvd_n : n / p \u2223 n,\n      {\n        use p,\n        symmetry,\n        apply nat.div_mul_cancel,\n        cases h_n_eq_ord_mul_pow p h_p_in_factors with t ht,\n        rw ht.left,\n        exact nat_dvd_mul_pow_of_one_le p (order_of (zmod.unit_of_coprime a _)) t ht.right,\n      },\n      have h_n_div_p_ne_n : n / p \u2260 n,\n      {\n        intro h_eq,\n        rw nat.div_eq_self at h_eq,\n        cases h_eq,\n        { subst h_eq,\n        linarith, },\n        have h_prime' : prime p := by { rw \u2190 nat.prime_iff, exact h_p_prime },\n        { exact prime.ne_one h_prime' h_eq, }\n      },\n      exact cyclotomic_dvd_X_pow_sub_one_frac \u2124 h_n_div_p_dvd_n \n      (nat_ne_zero_of_pos hpos_n) h_n_div_p_ne_n,\n    },\n    cases h_n_eq_ord_mul_pow p h_p_in_factors with t ht,\n    by_contra h_not_exception,\n    rw decidable.not_and_distrib at h_not_exception,\n    have h_p_dvd_pow_sub_one : (p \u2223 a ^ (n / p) - 1) \u2227 \n    (p = 2 \u2192 4 \u2223 a ^ (n / p) - 1),\n    {\n      split,\n      {\n        rw [ht.left, mul_pow_dvd_eq_mul_pow_sub _ p t (nat.prime.pos h_p_prime) ht.right],\n        exact dvd_pow_order_mul_sub_one _ _ _ _ (le_of_lt ha),\n      },\n      {\n        intro h_p_eq_two,\n        cases h_not_exception with h_not_p_eq h_not_n_eq,\n        {\n          exfalso,\n          exact h_not_p_eq h_p_eq_two,\n        },\n        {\n          subst h_p_eq_two,\n          have h_order_eq_one : order_of (zmod.unit_of_coprime a _) = 1 := \n          by exact order_of_eq_one_in_units_two h_a_coprime_p,\n          cases ht with h_n_eq ht,\n          rw h_order_eq_one at h_n_eq,\n          cases em (1 = t) with h_t_eq_one h_t_ne_one,\n          {\n            symmetry' at h_t_eq_one,\n            subst h_t_eq_one,\n            exfalso,\n            simp only [pow_one, one_mul] at h_n_eq,\n            exact h_not_n_eq h_n_eq,\n          },\n          {\n            have h_two_dvd_n_div : 2 \u2223 n / 2,\n            {\n              use 2 ^ (t - 2),\n              rw [h_n_eq, one_mul],\n              transitivity 2 ^ (t - 1),\n              {\n                rw \u2190 nat.pow_div ht zero_lt_two,\n                rw pow_one,\n              },\n              {\n                rw [\u2190 nat.sub_add_cancel \n                (nat.le_pred_of_lt (nat.lt_of_le_and_ne ht h_t_ne_one)),\n                nat.sub_sub, one_add_one_eq_two, pow_add, pow_one, mul_comm],\n              }\n            },\n            exact four_dvd_pow_sub_one_of_two_dvd h_a_coprime_p h_two_dvd_n_div,\n          }\n        }\n      }\n    },\n    have h_multiplicities : \n    multiplicity p \u03a6 + multiplicity p (a ^ (n / p) - 1 ^ (n / p)) \u2264 \n    multiplicity p (a ^ n - 1 ^ n),\n    {\n      rw [\u2190 multiplicity.mul \n      (nat.prime.prime (nat.prime_of_mem_factors h_p_in_factors)), one_pow, one_pow],\n      exact multiplicity.multiplicity_le_multiplicity_of_dvd_right \n      h_Phi_mul_pow_sub_one_dvd,\n    },\n    have h_multiplicities' :\n    multiplicity (p : \u2124) (\u03a6 : \u2124) + \n    multiplicity (p : \u2124) ((a : \u2124) ^ (n / p) - 1 ^ (n / p)) \u2264 \n    multiplicity (p : \u2124) ((a : \u2124) ^ n - 1 ^ n),\n    {\n      rw [one_pow, one_pow] at h_multiplicities,\n      rw [one_pow, one_pow, \u2190 nat.cast_one, \u2190 int.coe_nat_pow,\n      \u2190 int.coe_nat_pow,\n      \u2190 int.coe_nat_sub (h_one_le (n / p)),\n      \u2190 int.coe_nat_sub (h_one_le n)],\n      repeat { rw multiplicity.int.coe_nat_multiplicity, },\n      exact h_multiplicities,\n    },\n    have h_p_dvd_n : p \u2223 n,\n    {\n      rw ht.left,\n      exact nat_dvd_mul_pow_of_one_le p \n      (order_of (zmod.unit_of_coprime a _)) t ht.right,\n    },\n    nth_rewrite 2 \u2190 nat.div_mul_cancel h_p_dvd_n at h_multiplicities',\n    nth_rewrite 3 \u2190 nat.div_mul_cancel h_p_dvd_n at h_multiplicities',\n    rw [pow_mul, pow_mul] at h_multiplicities',\n    have h_p_not_dvd_a_pow : \u00ac(p : \u2124) \u2223 (a : \u2124) ^ (n / p),\n    {\n      intro h_p_dvd_pow,\n      have h_p_coprime_a : (p : \u2115).coprime a := \n      by { exact nat.coprime.symm h_a_coprime_p },\n      rw nat.prime.coprime_iff_not_dvd h_p_prime at h_p_coprime_a,\n      apply h_p_coprime_a,\n      rw \u2190 int.coe_nat_dvd,\n      exact int.prime.dvd_pow' h_p_prime h_p_dvd_pow,\n    },\n    have h_ne_top : multiplicity \u2191p ((a : \u2124) ^ (n / p) - 1 ^ (n / p)) \u2260 has_top.top,\n    {\n      rw [multiplicity.ne_top_iff_finite, multiplicity.finite_int_iff],\n      split,\n      {\n        exact nat.prime.ne_one h_p_prime,\n      },\n      {\n        rw [one_pow, ne.def, sub_eq_zero, nat.cast_pow_eq_one a (n / p)],\n        { linarith, },\n        {\n          apply nat_ne_zero_of_pos,\n          apply nat.div_pos,\n          {\n            apply nat.le_of_dvd _ h_p_dvd_n,\n            linarith,\n          },\n          {\n            exact nat.prime.pos h_p_prime,\n          },\n        },\n        { exact int_char_zero, }\n      }\n    },\n    cases nat.prime.eq_two_or_odd' h_p_prime with h_p_eq_two h_p_odd,\n    {\n      subst h_p_eq_two,\n      have h_four_dvd : 4 \u2223 (a : \u2124) ^ (n / 2) - 1 ^ (n / 2),\n      {\n        rw [one_pow, \u2190 nat.cast_one, \u2190 int.coe_nat_pow,\n        \u2190 int.coe_nat_sub (h_one_le (n / 2)), \u2190 coe_bit0, \u2190 coe_bit0,\n        int.coe_nat_dvd],\n        apply h_p_dvd_pow_sub_one.right,\n        refl,\n      },\n      rw [nat.cast_two, \n      int.two_pow_sub_pow' 2 h_four_dvd _, add_comm] at h_multiplicities',\n      nth_rewrite 7 \u2190 nat.cast_two at h_multiplicities',\n      rw [multiplicity.int.coe_nat_multiplicity, \n      nat_multiplicity_self 2 (le_refl 2)] at h_multiplicities',\n      rw [multiplicity.pow_dvd_iff_le_multiplicity,\n      \u2190 multiplicity.int.coe_nat_multiplicity, nat.cast_two,\n      nat.cast_two] at h_square_dvd,\n      {\n        rw [\u2190 nat.cast_two, part_enat_add_le_add_iff_left h_ne_top,\n        nat.cast_two] at h_multiplicities',\n        convert le_trans h_square_dvd h_multiplicities',\n        simp only [eq_iff_iff, false_iff, not_le],\n        rw [\u2190 nat.cast_two, \u2190 nat.cast_one, part_enat.coe_lt_coe],\n        exact one_lt_two,\n      },\n      {\n        rw nat.cast_two at h_p_not_dvd_a_pow,\n        exact h_p_not_dvd_a_pow,\n      }\n    },\n    {\n      have h_p_dvd_pow_sub_pow : (p : \u2124) \u2223 (a : \u2124) ^ (n / p) - 1 ^ (n / p),\n      {\n        rw [one_pow, \u2190 nat.cast_one, \u2190 int.coe_nat_pow,\n        \u2190 int.coe_nat_sub (h_one_le (n / p)), int.coe_nat_dvd],\n        exact h_p_dvd_pow_sub_one.left,\n      },\n      rw [multiplicity.int.pow_sub_pow h_p_prime h_p_odd \n      h_p_dvd_pow_sub_pow h_p_not_dvd_a_pow p,\n      nat_multiplicity_self p (nat.prime.two_le h_p_prime), add_comm]\n      at h_multiplicities',\n      rw [multiplicity.pow_dvd_iff_le_multiplicity,\n      \u2190 multiplicity.int.coe_nat_multiplicity, nat.cast_two] at h_square_dvd,\n      rw part_enat_add_le_add_iff_left h_ne_top at h_multiplicities',\n      convert le_trans h_square_dvd h_multiplicities',\n      simp only [eq_iff_iff, false_iff, not_le],\n      rw [\u2190 nat.cast_two, \u2190 nat.cast_one, part_enat.coe_lt_coe],\n      exact one_lt_two,\n    }\n  },\n  cases em (p = 2 \u2227 n = 2) with h_exception h_not_exception_1,\n  {\n    cases h_exception,\n    subst h_exception_right,\n    subst h_exception_left,\n    simp only [polynomial.cyclotomic_two, polynomial.eval_add, \n    polynomial.eval_X, polynomial.eval_one, \n    int.to_nat_coe_nat_add_one] at h_Phi_def,\n    apply h_exception_1,\n    split,\n    { refl, },\n    {\n      use \u03a6.factors.length,\n      rw h_eq_prime_pow at h_Phi_def,\n      rw h_Phi_def,\n      simp only [nat.add_succ_sub_one, add_zero],\n    }\n  },\n  {\n    have h_square_not_dvd : \u00ac p ^ 2 \u2223 \u03a6 := \n    by { intro h_dvd, exact h_not_exception_1 (h_prime_square_not_dvd h_dvd), },\n    have h_factors_length_eq_one : \u03a6.factors.length = 1,\n    {\n      cases others with p' others' h_primes',\n      {\n        rw [h_primes, list.length_singleton],\n      },\n      {\n        exfalso,\n        apply h_square_not_dvd,\n        rw h_eq_prime_pow, \n        apply pow_dvd_pow p,\n        rw h_primes,\n        simp only [list.length],\n        rw [add_assoc, one_add_one_eq_two],\n        exact nat.le_add_left 2 others'.length,\n      }\n    },\n    rw [h_factors_length_eq_one, pow_one, h_Phi_def,\n    \u2190 int.coe_nat_eq_coe_nat_iff, int.to_nat_of_nonneg \n    (polynomial.cyclotomic_nonneg n h_one_le_a_int)] at h_eq_prime_pow,\n    cases h_n_eq_ord_mul_pow p h_p_in_factors with t ht,\n    rw [mul_comm, \u2190 h_ord_def] at ht,\n    rw ht.left at h_eq_prime_pow,\n    have h_p_not_dvd_ord : \u00ac p \u2223 ord,\n    {\n      rw h_ord_def,\n      apply nat.not_dvd_of_pos_of_lt (order_of_units_pos _),\n      haveI : ne_zero p := \u27e8 nat.prime.ne_zero h_p_prime \u27e9,\n      have h_ord_le_p_sub_one : order_of (zmod.unit_of_coprime a _) \u2264 p - 1 := \n      by { rw \u2190 nat.totient_prime h_p_prime, \n      exact order_of_units_le_totient h_a_coprime_p, },\n      have h_p_sub_one_lt_p : p - 1 < p,\n      {\n        rw \u2190 nat.sub_zero (p - 1),\n        exact nat.sub_one_sub_lt (nat.prime.pos h_p_prime),\n      },\n      exact lt_of_le_of_lt h_ord_le_p_sub_one h_p_sub_one_lt_p,\n      rw ne_zero_iff,\n      exact nat.prime.ne_zero h_p_prime,\n    },\n    have h_expand_eq_expand_mul_p : \n    polynomial.eval \u2191a ((polynomial.expand \u2124 (p ^ t)) \n    (polynomial.cyclotomic ord \u2124)) =\n    polynomial.eval \u2191a ((polynomial.expand \u2124 (p ^ (t - 1))) \n    (polynomial.cyclotomic ord \u2124)) * \u2191p,\n    {\n      rw [cyclotomic_expand_pow_eq_cyclotomic_mul h_p_prime _ h_p_not_dvd_ord,\n      polynomial.eval_mul, h_eq_prime_pow, mul_comm],\n      linarith,\n    },\n    simp only [polynomial.expand_eval] at h_expand_eq_expand_mul_p,\n    apply eq.not_gt h_expand_eq_expand_mul_p,\n    cases em (ord = 1) with h_ord_eq_one h_ord_ne_one,\n    {\n      simp only [h_ord_eq_one, polynomial.cyclotomic_one, \n      polynomial.eval_sub, polynomial.eval_X, \n      polynomial.eval_one],\n      nth_rewrite 1 \u2190 nat.sub_add_cancel ht.right,\n      nth_rewrite 1 \u2190 nat.cast_one,\n      nth_rewrite 4 \u2190 nat.cast_one,\n      rw [\u2190 int.coe_nat_pow,\n      \u2190 int.coe_nat_pow,\n      \u2190 int.coe_nat_sub (h_one_le (p ^ (t - 1))),\n      \u2190 int.coe_nat_sub (h_one_le (p ^ (t - 1 + 1))), pow_add,\n      pow_mul, pow_one, \u2190 int.coe_nat_mul, int.coe_nat_lt],\n      apply sub_one_mul_lt_pow_sub_one \n      (a ^ p ^ (t - 1)) p (nat.prime.one_lt h_p_prime),\n      apply h_one_lt (p ^ (t - 1)),\n      exact pow_pos (nat.prime.pos h_p_prime) (t - 1),\n    },\n    {\n      haveI : ne_zero p := \u27e8 nat.prime.ne_zero h_p_prime \u27e9, \n      have h_ord_pos : 0 < ord := by { rw h_ord_def, \n      exact order_of_units_pos h_a_coprime_p, },\n      have h_one_lt_ord : 1 < ord,\n      {\n        rw nat.one_lt_iff_ne_zero_and_ne_one,\n        split,\n        { exact nat_ne_zero_of_pos h_ord_pos, },\n        { exact h_ord_ne_one, }\n      },\n      have h_le : ((a : \u2124) ^ p ^ (t - 1) + 1) ^ ord.totient * \u2191p \u2264 \n      ((a : \u2124) ^ p ^ t - 1) ^ ord.totient,\n      {\n        nth_rewrite 1 \u2190 nat.sub_add_cancel ht.right,\n        set b := (a : \u2124) ^ p ^ (t - 1) with h_b_def,\n        rw [pow_add, pow_mul, pow_one, \u2190 h_b_def],\n        have h_b_nonneg : 0 \u2264 b,\n        {\n          rw h_b_def,\n          apply pow_nonneg,\n          linarith,\n        },\n        transitivity ((b + 1) * \u2191p) ^ ord.totient,\n        {\n          rw mul_pow,\n          apply int.mul_le_mul_of_nonneg_left,\n          {\n            apply le_self_pow _ (nat_ne_zero_of_pos (nat.totient_pos h_ord_pos)),\n            rw [\u2190 nat.cast_one, int.coe_nat_le],\n            exact le_of_lt (nat.prime.one_lt h_p_prime),\n          },\n          {\n            apply pow_nonneg,\n            apply add_nonneg h_b_nonneg,\n            linarith,\n          }\n        },\n        {\n          apply pow_le_pow_of_le_left,\n          {\n            apply mul_nonneg,\n            {\n              apply add_nonneg h_b_nonneg,\n              linarith,\n            },\n            {\n              linarith,\n            }\n          },\n          {\n            cases em (b \u2264 2) with h_b_le_two h_two_lt_b,\n            {\n              have h_pow_le_two : 2 ^ (p ^ (t - 1)) \u2264 (2 : \u2124),\n              {\n                transitivity (\u2191a ^ p ^ (t - 1)),\n                {\n                  apply pow_le_pow_of_le_left,\n                  { linarith, },\n                  {\n                    rw [\u2190 nat.cast_two, int.coe_nat_le],\n                    linarith,\n                  }\n                },\n                {\n                  rw \u2190 h_b_def,\n                  exact h_b_le_two,\n                }\n              },\n              nth_rewrite 1 \u2190 pow_one (2 : \u2124) at h_pow_le_two,\n              rw [pow_le_pow_iff _] at h_pow_le_two,\n              {\n                cases em (t - 1 = 0) with h_t_le_one h_t_ne_one,\n                {\n                  rw nat.sub_eq_zero_iff_le at h_t_le_one,\n                  have h_t_eq_one : t = 1 := by exact le_antisymm h_t_le_one ht.right,\n                  subst h_t_eq_one,\n                  simp only [pow_zero, pow_one] at h_b_def,\n                  rw [h_b_def, \u2190 nat.cast_two, int.coe_nat_le] at h_b_le_two,\n                  have h_a_eq_two : a = 2 := by linarith,\n                  subst h_a_eq_two,\n                  have h_p_ne_two : p \u2260 2,\n                  {\n                    intro h_p_eq_two,\n                    rw [h_p_eq_two, nat.coprime_self] at h_a_coprime_p,\n                    linarith,\n                  },\n                  cases em (p = 3) with h_p_eq_three h_p_ne_three,\n                  {\n                    rw h_p_eq_three at h_a_coprime_p,\n                    have h_ord_eq_two : ord = 2,\n                    {\n                      rw h_ord_def,\n                      convert order_of_two_mod_three_eq_two h_a_coprime_p,\n                    },\n                    rw h_p_eq_three at ht,\n                    exfalso,\n                    apply h_exception_2,\n                    rw [eq_self_iff_true, and_true, ht.left, pow_one, h_ord_eq_two],\n                    norm_num,\n                  },\n                  {\n                    rw [h_b_def, coe_bit0, algebra_map.coe_one],\n                    have h_five_le_p : 5 \u2264 p := by exact \n                    nat.prime.five_le_of_ne_two_of_ne_three h_p_prime h_p_ne_two h_p_ne_three,\n                    convert three_mul_le_pow_sub (p - 5),\n                    norm_num,\n                    symmetry, \n                    exact nat.sub_add_cancel h_five_le_p,\n                    symmetry, \n                    exact nat.sub_add_cancel h_five_le_p,\n                  }\n                },\n                {\n                  exfalso,\n                  rw nat_pow_le_one_iff at h_pow_le_two,\n                  cases h_pow_le_two,\n                  { exact not_lt_of_le h_pow_le_two (nat.prime.one_lt h_p_prime), },\n                  { exact h_t_ne_one h_pow_le_two, }\n                }\n              },\n              {\n                linarith,\n              }\n            },\n            {\n              transitivity 2 * (b - 1) * \u2191p,\n              {\n                apply int.mul_le_mul_of_nonneg_right,\n                { linarith, },\n                { linarith, }\n              },\n              {\n                apply two_mul_le_pow_sub_one b p,\n                { linarith, },\n                { exact nat.prime.two_le h_p_prime, }\n              }\n            }\n          }\n        }\n      },\n      exact lt_of_le_of_lt \n      (le_trans (int.mul_le_mul_of_nonneg_right (cyclotomic_le_X_add_one_pow h_ord_pos \n      (h_one_lt_int (p ^ (t - 1)) \n      (pow_pos (nat.prime.pos h_p_prime) (t - 1)))) (int.coe_nat_nonneg p)) h_le)\n      (X_sub_one_pow_lt_cyclotomic h_one_lt_ord \n      (h_one_lt_int (p ^ t) (pow_pos (nat.prime.pos h_p_prime) t))),\n    }\n  }\nend", "meta": {"author": "sovesti", "repo": "zsigmondy", "sha": "c24a906a3ff7ad598bcbf47232a8bad02e6cec56", "save_path": "github-repos/lean/sovesti-zsigmondy", "path": "github-repos/lean/sovesti-zsigmondy/zsigmondy-c24a906a3ff7ad598bcbf47232a8bad02e6cec56/src/zsygmondy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7297071728499189}}
{"text": "\n---\n\nsection\nparameters {A : Type} {R : A \u2192 A \u2192 Prop}\nparameter (irreflR : irreflexive R)\nparameter (transR : transitive R)\n\nlocal infix < := R\n\ndef R' (a b : A) : Prop := R a b \u2228 a = b\nlocal infix \u2264 := R'\n\ntheorem reflR' (a : A) : a \u2264 a := or.inr (refl a)\n\ntheorem transR' {a b c : A} (h1 : a \u2264 b) (h2 : b \u2264 c):\n  a \u2264 c :=\n  or.elim h1\n    (assume : a < b,\n      show a \u2264 c, from\n        or.elim h2\n          (assume : b < c, or.inl (transR \u2039 a < b \u203a \u2039 b < c \u203a))\n          (assume : b = c, or.inl (eq.subst \u2039 b = c \u203a \u2039 a < b \u203a)))\n    (assume : a = b,\n      show a \u2264 c, from\n        or.elim h2\n          (assume : b < c, or.inl (eq.symm \u2039 a = b \u203a  \u25b8 \u2039 b < c \u203a))\n          (assume : b = c, or.inr (\u2039 b = c \u203a \u25b8 \u2039 a = b \u203a)))\n\ntheorem antisymmR' {a b : A} (h1 : a \u2264 b) (h2 : b \u2264 a) :\n  a = b :=\n    or.elim h1\n      (assume : a < b,\n        or.elim h2\n          (assume : b < a, have false, from (irreflR a) (transR \u2039 a < b \u203a \u2039 b < a \u203a), \u2039 false \u203a.elim)\n          (assume : b = a, eq.symm this)\n      )\n      (assume : a = b, eq.symm (eq.symm this))\nend\n\n---\n\nsection\nparameters {A : Type} {R : A \u2192 A \u2192 Prop}\nparameter (reflR : reflexive R)\nparameter (transR : transitive R)\n\ndef S (a b : A) : Prop := R a b \u2227 R b a\n\nexample : transitive S :=\nassume a b c,\nassume h1 h2,\n\u27e8 transR h1.left h2.left , transR h2.right h1.right \u27e9\n\nend\n\n---\n\nsection\n  parameters {A : Type} {a b c : A} {R : A \u2192 A \u2192 Prop}\n  parameter (Rab : R a b)\n  parameter (Rbc : R b c)\n  parameter (nRac : \u00ac R a c)\n\n  -- Prove one of the following two theorems:\n\n  theorem R_is_strict_partial_order :\n    irreflexive R \u2227 transitive R :=\n  sorry\n\n  theorem R_is_not_strict_partial_order :\n    \u00ac(irreflexive R \u2227 transitive R) :=\n  assume h : irreflexive R \u2227 transitive R,\n  show false, from\n    nRac (h.right Rab Rbc)\nend\n\n---\n\nopen nat\n\nexample : 1 \u2264 4 :=\nle_succ_of_le $ le_succ_of_le $ le_succ 1", "meta": {"author": "kaychaks", "repo": "logic_proof", "sha": "90f3bf0acbabf558ba2f82dee968255d8bfe2de1", "save_path": "github-repos/lean/kaychaks-logic_proof", "path": "github-repos/lean/kaychaks-logic_proof/logic_proof-90f3bf0acbabf558ba2f82dee968255d8bfe2de1/src/ch14.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.729707164710782}}
{"text": "import algebra.associated\nimport algebra.group_power\nimport ring_theory.ideal_operations\nimport ring_theory.ideals\n\nuniverse u\n\nvariables {\u03b1 : Type*}\n\nopen_locale classical\n\n/- An element a of a ring \u03b1 is a zero divisor if there exists a b \u2208 \u03b1\n   such that b \u2260 0 and ab = 0. -/\ndef is_zero_divisor [comm_ring \u03b1] (a : \u03b1) := \u2203 b : \u03b1, b \u2260 0 \u2227 a * b = 0\n\n/- An element a of a ring \u03b1 is nilpotent if there exists a n \u2208 \u2115 such\n   that a^n = 0. -/\ndef is_nilpotent [comm_ring \u03b1] (a : \u03b1) := \u2203 n : \u2115, a ^ n = 0\n\n/- 0 is nilpotent. -/\ntheorem zero_is_nilpotent [comm_ring \u03b1] : is_nilpotent (0 : \u03b1) :=\n  exists.intro 1 (by simp)\n\ntheorem exists_min_pow_zero_of_nilpotent [comm_ring \u03b1] :\n  \u2200 a : \u03b1, is_nilpotent a \u2192 \u2203 m : \u2115, a^m = 0 \u2227 \u2200 n : \u2115, n < m \u2192 a^n \u2260 0\n:=\nbegin\n  rintros a hna,\n  use nat.find hna,\n  split,\n  { exact nat.find_spec hna},\n  { intro n,\n    exact nat.find_min hna}\nend\n\ntheorem eq_mul [comm_ring \u03b1] (a : \u03b1) (ha : (1 : \u03b1) = 0) : a = 0\n:=\nbegin\n  have h : (a * 1 = a * 0) := eq.subst ha rfl,\n  simp at h,\n  exact h\nend\n\n/- All nonzero nilpotents are zerodivisors. -/\ntheorem nz_nilpotent_is_zerodivisor [comm_ring \u03b1] :\n  \u2200 a : \u03b1, is_nilpotent a \u2192 a \u2260 0 \u2192 is_zero_divisor a\n:=\nbegin\n  intros a ha ha',\n  unfold is_zero_divisor,\n  unfold is_nilpotent at ha,\n  have h := exists_min_pow_zero_of_nilpotent a ha,\n  cases h with m hm,\n  cases m with,\n  { rw pow_zero at hm,\n    have haz := eq_mul a hm.left,\n    contradiction },\n  { cases m with,\n    { simp at hm,\n      have haz := hm.left,\n      contradiction },\n    { let n := m + 1,\n      use a ^ n,\n      rw nat.succ_eq_add_one at hm,\n      rw nat.succ_eq_add_one at hm,\n      simp at hm,\n      split,\n      { have hn : n < m + 2,\n        simp,\n        exact hm.right n hn },\n      { rw <- pow_succ,\n        exact hm.left, },\n    }\n  }\nend\n\n/- Zero is a zero divisor in a nonzero ring. -/\ntheorem zero_zero_divisor_in_nz_ring [nonzero_comm_ring \u03b1]\n  : is_zero_divisor (0 : \u03b1) :=\nexists.intro 1 \u27e8one_ne_zero, by simp\u27e9\n\n/- All nilpotents are zero divisors in a nonzero ring. -/\ntheorem nonzero_ring_nilpotent_is_zerodivisor [nonzero_comm_ring \u03b1]\n  : \u2200 a : \u03b1, is_nilpotent a \u2192 is_zero_divisor a\n:= assume a : \u03b1,\n   assume ha : is_nilpotent a,\n   classical.by_cases (assume hz  : a = 0, by simp[hz, zero_zero_divisor_in_nz_ring])\n                      (assume hnz : a \u2260 0, nz_nilpotent_is_zerodivisor a ha hnz)\n\nopen ideal\n\n/- The nilradical of a ring \u03b1 is the radical of (0). -/\ndef nilradical [comm_ring \u03b1] := radical (span ({ 0 } : set \u03b1))\n\n/- The elements of the nilradical are precisely the nilpotents of \u03b1 -/\ntheorem elem_nilradical_nilpotent [comm_ring \u03b1] :\n  \u2200 a : \u03b1, a \u2208 (@nilradical \u03b1).carrier \u2194 is_nilpotent a\n:= sorry\n\n/- A ring is reduced if its nilradical is the trivial ideal (0) -/\nclass reduced_ring (\u03b1 : Type u) extends comm_ring \u03b1 :=\n  (is_reduced : nilradical = span ({ 0 } : set \u03b1))\n\n/- The zero ideal is prime in an integral domain. -/\ntheorem zero_is_prime_in_id [integral_domain \u03b1] : (span ({0} : set \u03b1)).is_prime\n  :=\nbegin\n-- Our strategy is to show that the kernel of the identity \u03b1 \u2192 \u03b1 is\n-- (0) and then apply the ker_is_prime theorem.\nlet id_hom := @id \u03b1,\nhave ker_of_id_is_prime := ring_hom.ker_is_prime id_hom,\nend\n\n/- All integral domains are reduced. -/\ntheorem integral_domains_are_reduced [integral_domain \u03b1] : reduced_ring \u03b1\n  := is_reduced = is_prime.radical zero_is_prime_in_id\n", "meta": {"author": "anrddh", "repo": "commutative-algebra-playground", "sha": "4f4d1701e2c21f13bba50cf1bda44ec7a125a91e", "save_path": "github-repos/lean/anrddh-commutative-algebra-playground", "path": "github-repos/lean/anrddh-commutative-algebra-playground/commutative-algebra-playground-4f4d1701e2c21f13bba50cf1bda44ec7a125a91e/src/zero_divisors_and_nilpotents.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7296904526042898}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport number_theory.zsqrtd.basic\nimport data.complex.basic\nimport ring_theory.principal_ideal_domain\nimport number_theory.legendre_symbol.quadratic_reciprocity\n/-!\n# Gaussian integers\n\nThe Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both\nintegers.\n\n## Main definitions\n\nThe Euclidean domain structure on `\u2124[i]` is defined in this file.\n\nThe homomorphism `to_complex` into the complex numbers is also defined in this file.\n\n## Main statements\n\n`prime_iff_mod_four_eq_three_of_nat_prime`\nA prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4`\n\n## Notations\n\nThis file uses the local notation `\u2124[i]` for `gaussian_int`\n\n## Implementation notes\n\nGaussian integers are implemented using the more general definition `zsqrtd`, the type of integers\nadjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties\nand definitions about `zsqrtd` can easily be used.\n-/\n\nopen zsqrtd complex\nopen_locale complex_conjugate\n\n/-- The Gaussian integers, defined as `\u2124\u221a(-1)`. -/\n@[reducible] def gaussian_int : Type := zsqrtd (-1)\n\nlocal notation `\u2124[i]` := gaussian_int\n\nnamespace gaussian_int\n\ninstance : has_repr \u2124[i] := \u27e8\u03bb x, \"\u27e8\" ++ repr x.re ++ \", \" ++ repr x.im ++ \"\u27e9\"\u27e9\n\ninstance : comm_ring \u2124[i] := zsqrtd.comm_ring\n\nsection\nlocal attribute [-instance] complex.field -- Avoid making things noncomputable unnecessarily.\n\n/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/\ndef to_complex : \u2124[i] \u2192+* \u2102 :=\nzsqrtd.lift \u27e8I, by simp\u27e9\nend\n\ninstance : has_coe (\u2124[i]) \u2102 := \u27e8to_complex\u27e9\n\nlemma to_complex_def (x : \u2124[i]) : (x : \u2102) = x.re + x.im * I := rfl\n\nlemma to_complex_def' (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102) = x + y * I := by simp [to_complex_def]\n\nlemma to_complex_def\u2082 (x : \u2124[i]) : (x : \u2102) = \u27e8x.re, x.im\u27e9 :=\nby apply complex.ext; simp [to_complex_def]\n\n@[simp] lemma to_real_re (x : \u2124[i]) : ((x.re : \u2124) : \u211d) = (x : \u2102).re := by simp [to_complex_def]\n@[simp] lemma to_real_im (x : \u2124[i]) : ((x.im : \u2124) : \u211d) = (x : \u2102).im := by simp [to_complex_def]\n@[simp] lemma to_complex_re (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).re = x := by simp [to_complex_def]\n@[simp] lemma to_complex_im (x y : \u2124) : ((\u27e8x, y\u27e9 : \u2124[i]) : \u2102).im = y := by simp [to_complex_def]\n@[simp] lemma to_complex_add (x y : \u2124[i]) : ((x + y : \u2124[i]) : \u2102) = x + y := to_complex.map_add _ _\n@[simp] lemma to_complex_mul (x y : \u2124[i]) : ((x * y : \u2124[i]) : \u2102) = x * y := to_complex.map_mul _ _\n@[simp] lemma to_complex_one : ((1 : \u2124[i]) : \u2102) = 1 := to_complex.map_one\n@[simp] lemma to_complex_zero : ((0 : \u2124[i]) : \u2102) = 0 := to_complex.map_zero\n@[simp] lemma to_complex_neg (x : \u2124[i]) : ((-x : \u2124[i]) : \u2102) = -x := to_complex.map_neg _\n@[simp] lemma to_complex_sub (x y : \u2124[i]) : ((x - y : \u2124[i]) : \u2102) = x - y := to_complex.map_sub _ _\n@[simp] lemma to_complex_star (x : \u2124[i]) : ((star x : \u2124[i]) : \u2102) = conj (x : \u2102) :=\nbegin\n  rw [to_complex_def\u2082, to_complex_def\u2082],\n  exact congr_arg2 _ rfl (int.cast_neg _),\nend\n\n@[simp] lemma to_complex_inj {x y : \u2124[i]} : (x : \u2102) = y \u2194 x = y :=\nby cases x; cases y; simp [to_complex_def\u2082]\n\n@[simp] lemma to_complex_eq_zero {x : \u2124[i]} : (x : \u2102) = 0 \u2194 x = 0 :=\nby rw [\u2190 to_complex_zero, to_complex_inj]\n\n@[simp] lemma nat_cast_real_norm (x : \u2124[i]) : (x.norm : \u211d) = (x : \u2102).norm_sq :=\nby rw [zsqrtd.norm, norm_sq]; simp\n\n@[simp] lemma nat_cast_complex_norm (x : \u2124[i]) : (x.norm : \u2102) = (x : \u2102).norm_sq :=\nby cases x; rw [zsqrtd.norm, norm_sq]; simp\n\nlemma norm_nonneg (x : \u2124[i]) : 0 \u2264 norm x := norm_nonneg (by norm_num) _\n\n@[simp] lemma norm_eq_zero {x : \u2124[i]} : norm x = 0 \u2194 x = 0 :=\nby rw [\u2190 @int.cast_inj \u211d _ _ _]; simp\n\nlemma norm_pos {x : \u2124[i]} : 0 < norm x \u2194 x \u2260 0 :=\nby rw [lt_iff_le_and_ne, ne.def, eq_comm, norm_eq_zero]; simp [norm_nonneg]\n\nlemma abs_coe_nat_norm (x : \u2124[i]) : (x.norm.nat_abs : \u2124) = x.norm :=\nint.nat_abs_of_nonneg (norm_nonneg _)\n\n@[simp] lemma nat_cast_nat_abs_norm {\u03b1 : Type*} [ring \u03b1]\n  (x : \u2124[i]) : (x.norm.nat_abs : \u03b1) = x.norm :=\nby rw [\u2190 int.cast_coe_nat, abs_coe_nat_norm]\n\nlemma nat_abs_norm_eq (x : \u2124[i]) : x.norm.nat_abs =\n  x.re.nat_abs * x.re.nat_abs + x.im.nat_abs * x.im.nat_abs :=\nint.coe_nat_inj $ begin simp, simp [zsqrtd.norm] end\n\ninstance : has_div \u2124[i] :=\n\u27e8\u03bb x y, let n := (norm y : \u211a)\u207b\u00b9, c := star y in\n  \u27e8round ((x * c).re * n : \u211a), round ((x * c).im * n : \u211a)\u27e9\u27e9\n\nlemma div_def (x y : \u2124[i]) : x / y = \u27e8round ((x * star y).re / norm y : \u211a),\n  round ((x * star y).im / norm y : \u211a)\u27e9 :=\nshow zsqrtd.mk _ _ = _, by simp [div_eq_mul_inv]\n\nlemma to_complex_div_re (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).re = round ((x / y : \u2102).re) :=\nby rw [div_def, \u2190 @rat.round_cast \u211d _ _];\n  simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlemma to_complex_div_im (x y : \u2124[i]) : ((x / y : \u2124[i]) : \u2102).im = round ((x / y : \u2102).im) :=\nby rw [div_def, \u2190 @rat.round_cast \u211d _ _, \u2190 @rat.round_cast \u211d _ _];\n  simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]\n\nlemma norm_sq_le_norm_sq_of_re_le_of_im_le {x y : \u2102} (hre : |x.re| \u2264 |y.re|)\n  (him : |x.im| \u2264 |y.im|) : x.norm_sq \u2264 y.norm_sq :=\nby rw [norm_sq_apply, norm_sq_apply, \u2190 _root_.abs_mul_self, _root_.abs_mul,\n  \u2190 _root_.abs_mul_self y.re, _root_.abs_mul y.re,\n  \u2190 _root_.abs_mul_self x.im, _root_.abs_mul x.im,\n  \u2190 _root_.abs_mul_self y.im, _root_.abs_mul y.im]; exact\n(add_le_add (mul_self_le_mul_self (abs_nonneg _) hre)\n  (mul_self_le_mul_self (abs_nonneg _) him))\n\nlemma norm_sq_div_sub_div_lt_one (x y : \u2124[i]) :\n  ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq < 1 :=\ncalc ((x / y : \u2102) - ((x / y : \u2124[i]) : \u2102)).norm_sq =\n    ((x / y : \u2102).re - ((x / y : \u2124[i]) : \u2102).re +\n    ((x / y : \u2102).im - ((x / y : \u2124[i]) : \u2102).im) * I : \u2102).norm_sq :\n      congr_arg _ $ by apply complex.ext; simp\n  ... \u2264 (1 / 2 + 1 / 2 * I).norm_sq :\n  have |(2\u207b\u00b9 : \u211d)| = 2\u207b\u00b9, from _root_.abs_of_nonneg (by norm_num),\n  norm_sq_le_norm_sq_of_re_le_of_im_le\n    (by rw [to_complex_div_re]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).re)\n    (by rw [to_complex_div_im]; simp [norm_sq, this];\n      simpa using abs_sub_round (x / y : \u2102).im)\n  ... < 1 : by simp [norm_sq]; norm_num\n\ninstance : has_mod \u2124[i] := \u27e8\u03bb x y, x - y * (x / y)\u27e9\n\nlemma mod_def (x y : \u2124[i]) : x % y = x - y * (x / y) := rfl\n\nlemma norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) : (x % y).norm < y.norm :=\nhave (y : \u2102) \u2260 0, by rwa [ne.def, \u2190 to_complex_zero, to_complex_inj],\n(@int.cast_lt \u211d _ _ _ _).1 $\n  calc \u2191(zsqrtd.norm (x % y)) = (x - y * (x / y : \u2124[i]) : \u2102).norm_sq : by simp [mod_def]\n  ... = (y : \u2102).norm_sq * (((x / y) - (x / y : \u2124[i])) : \u2102).norm_sq :\n    by rw [\u2190 norm_sq_mul, mul_sub, mul_div_cancel' _ this]\n  ... < (y : \u2102).norm_sq * 1 : mul_lt_mul_of_pos_left (norm_sq_div_sub_div_lt_one _ _)\n    (norm_sq_pos.2 this)\n  ... = zsqrtd.norm y : by simp\n\nlemma nat_abs_norm_mod_lt (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (x % y).norm.nat_abs < y.norm.nat_abs :=\nint.coe_nat_lt.1 (by simp [-int.coe_nat_lt, norm_mod_lt x hy])\n\nlemma norm_le_norm_mul_left (x : \u2124[i]) {y : \u2124[i]} (hy : y \u2260 0) :\n  (norm x).nat_abs \u2264 (norm (x * y)).nat_abs :=\nby rw [zsqrtd.norm_mul, int.nat_abs_mul];\n  exact le_mul_of_one_le_right (nat.zero_le _)\n    (int.coe_nat_le.1 (by rw [abs_coe_nat_norm]; exact int.add_one_le_of_lt (norm_pos.2 hy)))\n\ninstance : nontrivial \u2124[i] :=\n\u27e8\u27e80, 1, dec_trivial\u27e9\u27e9\n\ninstance : euclidean_domain \u2124[i] :=\n{ quotient := (/),\n  remainder := (%),\n  quotient_zero := by { simp [div_def], refl },\n  quotient_mul_add_remainder_eq := \u03bb _ _, by simp [mod_def],\n  r := _,\n  r_well_founded := measure_wf (int.nat_abs \u2218 norm),\n  remainder_lt := nat_abs_norm_mod_lt,\n  mul_left_not_lt := \u03bb a b hb0, not_lt_of_ge $ norm_le_norm_mul_left a hb0,\n  .. gaussian_int.comm_ring,\n  .. gaussian_int.nontrivial }\n\nopen principal_ideal_ring\n\nlemma mod_four_eq_three_of_nat_prime_of_prime (p : \u2115) [hp : fact p.prime] (hpi : prime (p : \u2124[i])) :\n  p % 4 = 3 :=\nhp.1.eq_two_or_odd.elim\n  (\u03bb hp2, absurd hpi (mt irreducible_iff_prime.2 $\n    \u03bb \u27e8hu, h\u27e9, begin\n      have := h \u27e81, 1\u27e9 \u27e81, -1\u27e9 (hp2.symm \u25b8 rfl),\n      rw [\u2190 norm_eq_one_iff, \u2190 norm_eq_one_iff] at this,\n      exact absurd this dec_trivial\n    end))\n  (\u03bb hp1, by_contradiction $ \u03bb hp3 : p % 4 \u2260 3,\n    have hp41 : p % 4 = 1,\n      begin\n        rw [\u2190 nat.mod_mul_left_mod p 2 2, show 2 * 2 = 4, from rfl] at hp1,\n        have := nat.mod_lt p (show 0 < 4, from dec_trivial),\n        revert this hp3 hp1,\n        generalize : p % 4 = m, dec_trivial!,\n      end,\n    let \u27e8k, hk\u27e9 := zmod.exists_sq_eq_neg_one_iff.2 $\n      by rw hp41; exact dec_trivial in\n    begin\n      obtain \u27e8k, k_lt_p, rfl\u27e9 : \u2203 (k' : \u2115) (h : k' < p), (k' : zmod p) = k,\n      { refine \u27e8k.val, k.val_lt, zmod.nat_cast_zmod_val k\u27e9 },\n      have hpk : p \u2223 k ^ 2 + 1,\n        by { rw [pow_two, \u2190 char_p.cast_eq_zero_iff (zmod p) p, nat.cast_add, nat.cast_mul,\n                 nat.cast_one, \u2190 hk, add_left_neg], },\n      have hkmul : (k ^ 2 + 1 : \u2124[i]) = \u27e8k, 1\u27e9 * \u27e8k, -1\u27e9 :=\n        by simp [sq, zsqrtd.ext],\n      have hpne1 : p \u2260 1 := ne_of_gt hp.1.one_lt,\n      have hkltp : 1 + k * k < p * p,\n        from calc 1 + k * k \u2264 k + k * k :\n          add_le_add_right (nat.pos_of_ne_zero\n            (\u03bb hk0, by clear_aux_decl; simp [*, pow_succ'] at *)) _\n        ... = k * (k + 1) : by simp [add_comm, mul_add]\n        ... < p * p : mul_lt_mul k_lt_p k_lt_p (nat.succ_pos _) (nat.zero_le _),\n      have hpk\u2081 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, -1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (zsqrtd.norm \u27e8k, -1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, zsqrtd.norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (-1 : \u2124) \u2260 0, from dec_trivial) $\n              by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpk\u2082 : \u00ac (p : \u2124[i]) \u2223 \u27e8k, 1\u27e9 :=\n        \u03bb \u27e8x, hx\u27e9, lt_irrefl (p * x : \u2124[i]).norm.nat_abs $\n          calc (norm (p * x : \u2124[i])).nat_abs = (zsqrtd.norm \u27e8k, 1\u27e9).nat_abs : by rw hx\n          ... < (norm (p : \u2124[i])).nat_abs : by simpa [add_comm, zsqrtd.norm] using hkltp\n          ... \u2264 (norm (p * x : \u2124[i])).nat_abs : norm_le_norm_mul_left _\n            (\u03bb hx0, (show (1 : \u2124) \u2260 0, from dec_trivial) $\n                by simpa [hx0] using congr_arg zsqrtd.im hx),\n      have hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2\n        (by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n        exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1),\n      obtain \u27e8y, hy\u27e9 := hpk,\n      have := hpi.2.2 \u27e8k, 1\u27e9 \u27e8k, -1\u27e9 \u27e8y, by rw [\u2190 hkmul, \u2190 nat.cast_mul p, \u2190 hy]; simp\u27e9,\n      clear_aux_decl, tauto\n    end)\n\nlemma sq_add_sq_of_nat_prime_of_not_irreducible (p : \u2115) [hp : fact p.prime]\n  (hpi : \u00acirreducible (p : \u2124[i])) : \u2203 a b, a^2 + b^2 = p :=\nhave hpu : \u00ac is_unit (p : \u2124[i]), from mt norm_eq_one_iff.2 $\n  by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];\n    exact \u03bb h, (ne_of_lt hp.1.one_lt).symm h.1,\nhave hab : \u2203 a b, (p : \u2124[i]) = a * b \u2227 \u00ac is_unit a \u2227 \u00ac is_unit b,\n  by simpa [irreducible_iff, hpu, not_forall, not_or_distrib] using hpi,\nlet \u27e8a, b, hpab, hau, hbu\u27e9 := hab in\nhave hnap : (norm a).nat_abs = p, from ((hp.1.mul_eq_prime_sq_iff\n    (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 $\n  by rw [\u2190 int.coe_nat_inj', int.coe_nat_pow, sq,\n    \u2190 @norm_nat_cast (-1), hpab];\n    simp).1,\n\u27e8a.re.nat_abs, a.im.nat_abs, by simpa [nat_abs_norm_eq, sq] using hnap\u27e9\n\nlemma prime_of_nat_prime_of_mod_four_eq_three (p : \u2115) [hp : fact p.prime] (hp3 : p % 4 = 3) :\n  prime (p : \u2124[i]) :=\nirreducible_iff_prime.1 $ classical.by_contradiction $ \u03bb hpi,\n  let \u27e8a, b, hab\u27e9 := sq_add_sq_of_nat_prime_of_not_irreducible p hpi in\nhave \u2200 a b : zmod 4, a^2 + b^2 \u2260 p, by erw [\u2190 zmod.nat_cast_mod p 4, hp3]; exact dec_trivial,\nthis a b (hab \u25b8 by simp)\n\n/-- A prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4` -/\nlemma prime_iff_mod_four_eq_three_of_nat_prime (p : \u2115) [hp : fact p.prime] :\n  prime (p : \u2124[i]) \u2194 p % 4 = 3 :=\n\u27e8mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p\u27e9\n\nend gaussian_int\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/zsqrtd/gaussian_int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7295833680714878}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n-- 1. Importar la teor\u00eda de los n\u00fameros reales.\n-- 2. Declarar f como una variable sobre las funciones de \u211d en \u211d.  \n-- ----------------------------------------------------------------------\n\nimport data.real.basic   -- 1\nvariable {f : \u211d \u2192 \u211d}     -- 2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que f es no mon\u00f3tona syss existen x e y tales\n-- que x \u2264 y y f(x) > f(y).\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ================\n\nexample :\n  \u00ac monotone f \u2194 \u2203 x y, x \u2264 y \u2227 f x > f y :=\nbegin \n  rw [monotone], \n  push_neg,\nend\n\n-- Prueba\n-- ======\n\n/-\nf : \u211d \u2192 \u211d\n\u22a2 \u00acmonotone f \u2194 \u2203 (x y : \u211d), x \u2264 y \u2227 f x > f y\n  >> rw [monotone], \n\u22a2 (\u00ac\u2200 \u2983a b : \u211d\u2984, a \u2264 b \u2192 f a \u2264 f b) \u2194 \u2203 (x y : \u211d), x \u2264 y \u2227 f x > f y\n  >> push_neg,\nno goals\n-/\n\n-- Comentario: Se ha usado la definici\u00f3n\n-- + monotone: \u2200 \u2983a b : \u211d\u2984, a \u2264 b \u2192 f a \u2264 f b\n\n-- 2\u00aa demostraci\u00f3n\n-- ================\n\nlemma not_monotone_iff :\n  \u00ac monotone f \u2194 \u2203 x y, x \u2264 y \u2227 f x > f y :=\nby { rw [monotone], push_neg }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que la funci\u00f3n opuesta no es mon\u00f3tona.\n-- ----------------------------------------------------------------------\n\nexample : \u00ac monotone (\u03bb x : \u211d, -x) :=\nbegin\n  apply not_monotone_iff.mpr,\n  use [2, 3],\n  norm_num,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u22a2 \u00acmonotone (\u03bb (x : \u211d), -x)\n  >> apply not_monotone_iff.mpr,\n\u22a2 \u2203 (x y : \u211d), x \u2264 y \u2227 -x > -y\n  >> use [2, 3],\n\u22a2 2 \u2264 3 \u2227 -2 > -3\n  >> norm_num,\nno goals\n-/\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Funciones_no_monotonas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8688267745399465, "lm_q1q2_score": 0.7295833546043033}}
{"text": "\nimport sequence -- Imports sequences and their properties (convergent, bounded, monotone, etc.).\n\nnamespace my_analysis\n\n  section subindex\n\n    /-- A subindex is a strictly increasing map from \u2115 to itself. -/\n    structure subindex :=\n      (\u03c6 : \u2115 \u2192 \u2115)\n      (mono : strict_mono \u03c6)\n\n    instance subindex_fun : has_coe_to_fun subindex (\u03bb _, \u2115 \u2192 \u2115) := \u27e8subindex.\u03c6\u27e9\n    @[simp] theorem subindex_fun_eq (si : subindex) (n : \u2115) : si n = si.\u03c6 n := rfl\n\n    /-- The strictly increasing property of subindex follows inductively from the\n      function having strictly increasing consecutive terms. -/\n    def subindex_mk (f : \u2115 \u2192 \u2115) (h : \u2200 n, f n < f n.succ) : subindex :=\n      \u27e8f, begin\n        intros a b hab,\n        have : \u2200 n, n > 0 \u2192 f a < f (a + n),\n          intro n,\n          induction n with n ih,\n          { intro h', exact absurd h' (irrefl 0) },\n          { intro h', rw [nat.add_succ],\n            by_cases hn : n > 0,\n            { exact lt_trans (ih hn) (h (a + n)) },\n            { have : n = 0, from nat.eq_zero_of_le_zero (not_lt.mp hn),\n              rw [this, add_zero], exact h a } },\n        rw [\u2190 nat.add_sub_of_le (le_of_lt hab)],\n        exact this (b - a) (tsub_pos_of_lt hab)\n      end\u27e9\n\n    /-- A function used for defining subindex structures, such that each\n      index is `f` applied to the previous index, beginning with `f 0`. -/\n    def subindex_recursive (f : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115\n    | 0     := f 0\n    | (k+1) := f (subindex_recursive k)\n\n    /-- A subindex formed by moving every index up by `n`. -/\n    def subindex.add (si : subindex) (n : \u2115) : subindex :=\n      \u27e8\u03bb k, si k + n, \u03bb a b hab, (add_lt_add_iff_right n).mpr (si.mono hab)\u27e9\n\n    /-- The `m`-th entry of a subindex is at least `m`, or in other words\n      it will never fall behind the original sequence. -/\n    theorem subindex.unbounded (si : subindex) : \u2200 m, m \u2264 si m\n    | 0     := zero_le _\n    | (k+1) := nat.succ_le_of_lt $ lt_of_le_of_lt (subindex.unbounded k) $ si.mono (lt_add_one k)\n\n  end subindex\n\n  section subseq\n\n    /-- A sub-sequence, formed by composing a sequence and a subindex. -/\n    def seq.subseq (s : seq) (si : subindex) : seq := s \u2218 si\n\n    /-- A sub-sequence inherits any upper bounds from the original sequence. -/\n    theorem subseq_bounded_above {s : seq} (hb : s.bounded_above) (si : subindex) :\n      (s.subseq si).bounded_above :=\n    begin\n      cases hb with M hM, use M,\n      intro n, exact hM (si n)\n    end\n\n    /-- A sub-sequence inherits any lower bounds from the original sequence. -/\n    theorem subseq_bounded_below {s : seq} (hb : s.bounded_below) (si : subindex) :\n      (s.subseq si).bounded_below :=\n    begin\n      cases hb with m hm, use m,\n      intro n, exact hm (si n)\n    end\n\n  end subseq\n\n  /-- Every sequence has a monotone sub-sequence. -/\n  theorem peak_point_lemma (s : seq) : \u2203 si : subindex, (s.subseq si).monotone :=\n  begin\n    by_cases h : \u2200 N, \u2203 m, m > N \u2227 \u2200 n, n > N \u2192  s m \u2264 s n,\n    -- Increasing case.\n    { let sir := subindex_recursive (\u03bb n, classical.some (h n)),\n      let si := subindex_mk sir (\u03bb n, (classical.some_spec (h (sir n))).left),\n      use si, apply or.inl,\n      intros a b hab,\n      have : \u2200 n, s.subseq si a \u2264 s.subseq si (a + n),\n        intro n,\n        induction n with n ih,\n        { rw [add_zero] },\n        { apply ih.trans,\n          rw [nat.add_succ],\n          by_cases han : a + n = 0,\n          { rw [han],\n            cases classical.some_spec (h 0) with h\u2081 h\u2082,\n            exact h\u2082 (classical.some (h (sir 0)))\n              (lt_trans h\u2081 (classical.some_spec (h (sir 0))).left) },\n          { cases nat.exists_eq_succ_of_ne_zero han with k hk,\n            rw [hk],\n            cases classical.some_spec (h (sir k)) with h\u2081 h\u2082,\n            exact h\u2082 (classical.some (h (sir k.succ)))\n              (lt_trans h\u2081 (classical.some_spec (h (sir k.succ))).left) } },\n      rw [\u2190 nat.add_sub_of_le hab],\n      exact this (b - a) },\n    -- Decreasing case.\n    { simp only [not_forall, not_exists, not_and, not_le, gt_iff_lt, exists_prop] at h,\n      cases h with N hN,\n      have h : \u2200 x, \u2203 y, x < y \u2227 s.shift N.succ y < s.shift N.succ x,\n        intro x,\n        by_contradiction h,\n        simp only [not_exists, not_and, not_lt] at h,\n        cases finite_prefix_min (s.shift N.succ) (nat.succ_ne_zero x) with M hM,\n        cases hN (M + N.succ) (nat.lt_add_left N N.succ M (lt_add_one N)) with y hy,\n        by_cases hxy : x < y - N.succ,\n        { have := lt_of_lt_of_le hy.right (hM.right x (lt_add_one x)),\n          rw [\u2190 shift_ge s hy.left] at this,\n          exact absurd (h (y - N.succ) hxy) (not_le_of_lt this) },\n        { have := hM.right (y - N.succ) (nat.lt_succ_of_le (le_of_not_lt hxy)),\n          rw [shift_ge s hy.left] at this,\n          exact absurd this (not_le_of_lt hy.right) },\n      let sir := subindex_recursive (\u03bb n, classical.some (h n)),\n      let si := (subindex_mk sir (\u03bb n, (classical.some_spec (h (sir n))).left)).add N.succ,\n      use si, apply or.inr,\n      intros a b hab,\n      have : \u2200 n, s.subseq si (a + n) \u2264 s.subseq si a,\n        intro n,\n        induction n with n ih,\n        { rw [add_zero] },\n        { refine le_trans _ ih,\n          rw [nat.add_succ],\n          exact le_of_lt (classical.some_spec (h (sir (a + n)))).right },\n      rw [\u2190 nat.add_sub_of_le hab],\n      exact this (b - a) }\n  end\n\n  /-- Every bounded sequence has a convergent subsequence. -/\n  theorem bolzano_weierstrass {s : seq} (hb : s.bounded) :\n    \u2203 si : subindex, (s.subseq si).convergent :=\n  begin\n    cases peak_point_lemma s with si hm,\n    cases hm with inc dec,\n    { exact \u27e8si, convergent_of_bounded_above_increasing (subseq_bounded_above\n      (bounded_iff_above_below.mp hb).left si) inc\u27e9 },\n    { exact \u27e8si, convergent_of_bounded_below_decreasing (subseq_bounded_below\n      (bounded_iff_above_below.mp hb).right si) dec\u27e9 }\n  end\n\nend my_analysis\n", "meta": {"author": "Hop311", "repo": "project1", "sha": "92bbb9fc1506b0e7d090f209674e2d4dae6e5c63", "save_path": "github-repos/lean/Hop311-project1", "path": "github-repos/lean/Hop311-project1/project1-92bbb9fc1506b0e7d090f209674e2d4dae6e5c63/src/subsequence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7295743079742392}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport analysis.inner_product_space.orientation\nimport analysis.inner_product_space.pi_L2\nimport analysis.special_functions.complex.circle\n\n/-!\n# Oriented angles.\n\nThis file defines oriented angles in real inner product spaces.\n\n## Main definitions\n\n* `orientation.oangle` is the oriented angle between two vectors with respect to an orientation.\n\n* `orientation.rotation` is the rotation by an oriented angle with respect to an orientation.\n\n## Implementation notes\n\nThe definitions here use the `real.angle` type, angles modulo `2 * \u03c0`. For some purposes,\nangles modulo `\u03c0` are more convenient, because results are true for such angles with less\nconfiguration dependence. Results that are only equalities modulo `\u03c0` can be represented\nmodulo `2 * \u03c0` as equalities of `(2 : \u2124) \u2022 \u03b8`.\n\nDefinitions and results in the `orthonormal` namespace, with respect to a particular choice\nof orthonormal basis, are mainly for use in setting up the API and proving that certain\ndefinitions do not depend on the choice of basis for a given orientation. Applications should\ngenerally use the definitions and results in the `orientation` namespace instead.\n\n## References\n\n* Evan Chen, Euclidean Geometry in Mathematical Olympiads.\n\n-/\n\nnoncomputable theory\n\nopen_locale real\n\nnamespace orthonormal\n\nvariables {V : Type*} [inner_product_space \u211d V]\nvariables {b : basis (fin 2) \u211d V} (hb : orthonormal \u211d b)\ninclude hb\n\n/-- The oriented angle from `x` to `y`, modulo `2 * \u03c0`. If either vector is 0, this is 0. -/\ndef oangle (x y : V) : real.angle :=\ncomplex.arg ((complex.isometry_of_orthonormal hb).symm y /\n  (complex.isometry_of_orthonormal hb).symm x)\n\n/-- If the first vector passed to `oangle` is 0, the result is 0. -/\n@[simp] lemma oangle_zero_left (x : V) : hb.oangle 0 x = 0 :=\nby simp [oangle]\n\n/-- If the second vector passed to `oangle` is 0, the result is 0. -/\n@[simp] lemma oangle_zero_right (x : V) : hb.oangle x 0 = 0 :=\nby simp [oangle]\n\n/-- If the two vectors passed to `oangle` are the same, the result is 0. -/\n@[simp] lemma oangle_self (x : V) : hb.oangle x x = 0 :=\nbegin\n  by_cases h : x = 0;\n    simp [oangle, h]\nend\n\n/-- Swapping the two vectors passed to `oangle` negates the angle. -/\nlemma oangle_rev (x y : V) : hb.oangle y x = -hb.oangle x y :=\nbegin\n  simp only [oangle],\n  convert complex.arg_inv_coe_angle _,\n  exact inv_div.symm\nend\n\n/-- Adding the angles between two vectors in each order results in 0. -/\n@[simp] lemma oangle_add_oangle_rev (x y : V) : hb.oangle x y + hb.oangle y x = 0 :=\nby simp [hb.oangle_rev y x]\n\n/-- Negating the first vector passed to `oangle` adds `\u03c0` to the angle. -/\nlemma oangle_neg_left {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  hb.oangle (-x) y = hb.oangle x y + \u03c0 :=\nbegin\n  simp only [oangle, div_neg_eq_neg_div, map_neg],\n  refine complex.arg_neg_coe_angle _,\n  simp [hx, hy]\nend\n\n/-- Negating the second vector passed to `oangle` adds `\u03c0` to the angle. -/\nlemma oangle_neg_right {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  hb.oangle x (-y) = hb.oangle x y + \u03c0 :=\nbegin\n  simp only [oangle, neg_div, map_neg],\n  refine complex.arg_neg_coe_angle _,\n  simp [hx, hy]\nend\n\n/-- Negating the first vector passed to `oangle` does not change twice the angle. -/\n@[simp] lemma two_zsmul_oangle_neg_left (x y : V) :\n  (2 : \u2124) \u2022 hb.oangle (-x) y = (2 : \u2124) \u2022 hb.oangle x y :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx] },\n  { by_cases hy : y = 0,\n    { simp [hy] },\n    { simp [hb.oangle_neg_left hx hy] } }\nend\n\n/-- Negating the second vector passed to `oangle` does not change twice the angle. -/\n@[simp] lemma two_zsmul_oangle_neg_right (x y : V) :\n  (2 : \u2124) \u2022 hb.oangle x (-y) = (2 : \u2124) \u2022 hb.oangle x y :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx] },\n  { by_cases hy : y = 0,\n    { simp [hy] },\n    { simp [hb.oangle_neg_right hx hy] } }\nend\n\n/-- Negating both vectors passed to `oangle` does not change the angle. -/\n@[simp] lemma oangle_neg_neg (x y : V) : hb.oangle (-x) (-y) = hb.oangle x y :=\nby simp [oangle, neg_div_neg_eq]\n\n/-- Negating the first vector produces the same angle as negating the second vector. -/\nlemma oangle_neg_left_eq_neg_right (x y : V) : hb.oangle (-x) y = hb.oangle x (-y) :=\nby rw [\u2190neg_neg y, oangle_neg_neg, neg_neg]\n\n/-- The angle between the negation of a nonzero vector and that vector is `\u03c0`. -/\n@[simp] lemma oangle_neg_self_left {x : V} (hx : x \u2260 0) : hb.oangle (-x) x = \u03c0 :=\nby simp [oangle_neg_left, hx]\n\n/-- The angle between a nonzero vector and its negation is `\u03c0`. -/\n@[simp] lemma oangle_neg_self_right {x : V} (hx : x \u2260 0) : hb.oangle x (-x) = \u03c0 :=\nby simp [oangle_neg_right, hx]\n\n/-- Twice the angle between the negation of a vector and that vector is 0. -/\n@[simp] lemma two_zsmul_oangle_neg_self_left (x : V) : (2 : \u2124) \u2022 hb.oangle (-x) x = 0 :=\nbegin\n  by_cases hx : x = 0;\n    simp [hx]\nend\n\n/-- Twice the angle between a vector and its negation is 0. -/\n@[simp] lemma two_zsmul_oangle_neg_self_right (x : V) : (2 : \u2124) \u2022 hb.oangle x (-x) = 0 :=\nbegin\n  by_cases hx : x = 0;\n    simp [hx]\nend\n\n/-- Adding the angles between two vectors in each order, with the first vector in each angle\nnegated, results in 0. -/\n@[simp] lemma oangle_add_oangle_rev_neg_left (x y : V) :\n  hb.oangle (-x) y + hb.oangle (-y) x = 0 :=\nby rw [oangle_neg_left_eq_neg_right, oangle_rev, add_left_neg]\n\n/-- Adding the angles between two vectors in each order, with the second vector in each angle\nnegated, results in 0. -/\n@[simp] lemma oangle_add_oangle_rev_neg_right (x y : V) :\n  hb.oangle x (-y) + hb.oangle y (-x) = 0 :=\nby rw [hb.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_self]\n\n/-- Multiplying the first vector passed to `oangle` by a positive real does not change the\nangle. -/\n@[simp] lemma oangle_smul_left_of_pos (x y : V) {r : \u211d} (hr : 0 < r) :\n  hb.oangle (r \u2022 x) y = hb.oangle x y :=\nbegin\n  simp only [oangle, linear_isometry_equiv.map_smul, complex.real_smul],\n  rw [mul_comm, div_mul_eq_div_mul_one_div, one_div, mul_comm, \u2190complex.of_real_inv],\n  congr' 1,\n  exact complex.arg_real_mul _ (inv_pos.2 hr)\nend\n\n/-- Multiplying the second vector passed to `oangle` by a positive real does not change the\nangle. -/\n@[simp] lemma oangle_smul_right_of_pos (x y : V) {r : \u211d} (hr : 0 < r) :\n  hb.oangle x (r \u2022 y) = hb.oangle x y :=\nbegin\n  simp only [oangle, linear_isometry_equiv.map_smul, complex.real_smul],\n  congr' 1,\n  rw mul_div_assoc,\n  exact complex.arg_real_mul _ hr\nend\n\n/-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle\nas negating that vector. -/\n@[simp] lemma oangle_smul_left_of_neg (x y : V) {r : \u211d} (hr : r < 0) :\n  hb.oangle (r \u2022 x) y = hb.oangle (-x) y :=\nby rw [\u2190neg_neg r, neg_smul, \u2190smul_neg, hb.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)]\n\n/-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle\nas negating that vector. -/\n@[simp] lemma oangle_smul_right_of_neg (x y : V) {r : \u211d} (hr : r < 0) :\n  hb.oangle x (r \u2022 y) = hb.oangle x (-y) :=\nby rw [\u2190neg_neg r, neg_smul, \u2190smul_neg, hb.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)]\n\n/-- The angle between a nonnegative multiple of a vector and that vector is 0. -/\n@[simp] lemma oangle_smul_left_self_of_nonneg (x : V) {r : \u211d} (hr : 0 \u2264 r) :\n  hb.oangle (r \u2022 x) x = 0 :=\nbegin\n  rcases hr.lt_or_eq with (h|h),\n  { simp [h] },\n  { simp [h.symm] }\nend\n\n/-- The angle between a vector and a nonnegative multiple of that vector is 0. -/\n@[simp] lemma oangle_smul_right_self_of_nonneg (x : V) {r : \u211d} (hr : 0 \u2264 r) :\n  hb.oangle x (r \u2022 x) = 0 :=\nbegin\n  rcases hr.lt_or_eq with (h|h),\n  { simp [h] },\n  { simp [h.symm] }\nend\n\n/-- The angle between two nonnegative multiples of the same vector is 0. -/\n@[simp] lemma oangle_smul_smul_self_of_nonneg (x : V) {r\u2081 r\u2082 : \u211d} (hr\u2081 : 0 \u2264 r\u2081) (hr\u2082 : 0 \u2264 r\u2082) :\n  hb.oangle (r\u2081 \u2022 x) (r\u2082 \u2022 x) = 0 :=\nbegin\n  rcases hr\u2081.lt_or_eq with (h|h),\n  { simp [h, hr\u2082] },\n  { simp [h.symm] }\nend\n\n/-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the\nangle. -/\n@[simp] lemma two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : \u211d} (hr : r \u2260 0) :\n  (2 : \u2124) \u2022 hb.oangle (r \u2022 x) y = (2 : \u2124) \u2022 hb.oangle x y :=\nbegin\n  rcases hr.lt_or_lt with (h|h);\n    simp [h]\nend\n\n/-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the\nangle. -/\n@[simp] lemma two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : \u211d} (hr : r \u2260 0) :\n  (2 : \u2124) \u2022 hb.oangle x (r \u2022 y) = (2 : \u2124) \u2022 hb.oangle x y :=\nbegin\n  rcases hr.lt_or_lt with (h|h);\n    simp [h]\nend\n\n/-- Twice the angle between a multiple of a vector and that vector is 0. -/\n@[simp] lemma two_zsmul_oangle_smul_left_self (x : V) {r : \u211d} :\n  (2 : \u2124) \u2022 hb.oangle (r \u2022 x) x = 0 :=\nbegin\n  rcases lt_or_le r 0 with (h|h);\n    simp [h]\nend\n\n/-- Twice the angle between a vector and a multiple of that vector is 0. -/\n@[simp] lemma two_zsmul_oangle_smul_right_self (x : V) {r : \u211d} :\n  (2 : \u2124) \u2022 hb.oangle x (r \u2022 x) = 0 :=\nbegin\n  rcases lt_or_le r 0 with (h|h);\n    simp [h]\nend\n\n/-- Twice the angle between two multiples of a vector is 0. -/\n@[simp] lemma two_zsmul_oangle_smul_smul_self (x : V) {r\u2081 r\u2082 : \u211d} :\n  (2 : \u2124) \u2022 hb.oangle (r\u2081 \u2022 x) (r\u2082 \u2022 x) = 0 :=\nbegin\n  by_cases h : r\u2081 = 0;\n    simp [h]\nend\n\n/-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/\nlemma eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y \u2194 \u2225x\u2225 = \u2225y\u2225 \u2227 hb.oangle x y = 0 :=\nbegin\n  split,\n  { intro h,\n    simp [h] },\n  { rintro \u27e8hn, ha\u27e9,\n    rw [oangle] at ha,\n    by_cases hy0 : y = 0,\n    { simpa [hy0] using hn },\n    { have hx0 : x \u2260 0 := norm_ne_zero_iff.1 (hn.symm \u25b8 norm_ne_zero_iff.2 hy0),\n      have hx0' : (complex.isometry_of_orthonormal hb).symm x \u2260 0,\n      { simp [hx0] },\n      have hy0' : (complex.isometry_of_orthonormal hb).symm y \u2260 0,\n      { simp [hy0] },\n      rw [complex.arg_div_coe_angle hy0' hx0', sub_eq_zero, complex.arg_coe_angle_eq_iff,\n          complex.arg_eq_arg_iff hy0' hx0', \u2190complex.norm_eq_abs, \u2190complex.norm_eq_abs,\n          linear_isometry_equiv.norm_map, linear_isometry_equiv.norm_map, hn,\n          \u2190complex.of_real_div, div_self (norm_ne_zero_iff.2 hy0), complex.of_real_one,\n          one_mul, linear_isometry_equiv.map_eq_iff] at ha,\n      exact ha.symm } }\nend\n\n/-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/\nlemma eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : \u2225x\u2225 = \u2225y\u2225) : x = y \u2194 hb.oangle x y = 0 :=\n\u27e8\u03bb he, ((hb.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2,\n \u03bb ha, (hb.eq_iff_norm_eq_and_oangle_eq_zero x y).2 \u27e8h, ha\u27e9\u27e9\n\n/-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/\nlemma eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : hb.oangle x y = 0) : x = y \u2194 \u2225x\u2225 = \u2225y\u2225 :=\n\u27e8\u03bb he, ((hb.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1,\n \u03bb hn, (hb.eq_iff_norm_eq_and_oangle_eq_zero x y).2 \u27e8hn, h\u27e9\u27e9\n\n/-- Given three nonzero vectors, the angle between the first and the second plus the angle\nbetween the second and the third equals the angle between the first and the third. -/\n@[simp] lemma oangle_add {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  hb.oangle x y + hb.oangle y z = hb.oangle x z :=\nbegin\n  simp_rw [oangle],\n  rw \u2190complex.arg_mul_coe_angle,\n  { rw [mul_comm, div_mul_div_cancel],\n    simp [hy] },\n  { simp [hx, hy] },\n  { simp [hy, hz] }\nend\n\n/-- Given three nonzero vectors, the angle between the second and the third plus the angle\nbetween the first and the second equals the angle between the first and the third. -/\n@[simp] lemma oangle_add_swap {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n   hb.oangle y z + hb.oangle x y = hb.oangle x z :=\nby rw [add_comm, hb.oangle_add hx hy hz]\n\n/-- Given three nonzero vectors, the angle between the first and the third minus the angle\nbetween the first and the second equals the angle between the second and the third. -/\n@[simp] lemma oangle_sub_left {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  hb.oangle x z - hb.oangle x y = hb.oangle y z :=\nby rw [sub_eq_iff_eq_add, hb.oangle_add_swap hx hy hz]\n\n/-- Given three nonzero vectors, the angle between the first and the third minus the angle\nbetween the second and the third equals the angle between the first and the second. -/\n@[simp] lemma oangle_sub_right {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  hb.oangle x z - hb.oangle y z = hb.oangle x y :=\nby rw [sub_eq_iff_eq_add, hb.oangle_add hx hy hz]\n\n/-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/\n@[simp] lemma oangle_add_cyc3 {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  hb.oangle x y + hb.oangle y z + hb.oangle z x = 0 :=\nby simp [hx, hy, hz]\n\n/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first\nvector in each angle negated, results in \u03c0. If the vectors add to 0, this is a version of the\nsum of the angles of a triangle. -/\n@[simp] lemma oangle_add_cyc3_neg_left {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  hb.oangle (-x) y + hb.oangle (-y) z + hb.oangle (-z) x = \u03c0 :=\nby rw [hb.oangle_neg_left hx hy, hb.oangle_neg_left hy hz, hb.oangle_neg_left hz hx,\n       (show hb.oangle x y + \u03c0 + (hb.oangle y z + \u03c0) + (hb.oangle z x + \u03c0) =\n         hb.oangle x y + hb.oangle y z + hb.oangle z x + (\u03c0 + \u03c0 + \u03c0 : real.angle), by abel),\n       hb.oangle_add_cyc3 hx hy hz, real.angle.coe_pi_add_coe_pi, zero_add, zero_add]\n\n/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second\nvector in each angle negated, results in \u03c0. If the vectors add to 0, this is a version of the\nsum of the angles of a triangle. -/\n@[simp] lemma oangle_add_cyc3_neg_right {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  hb.oangle x (-y) + hb.oangle y (-z) + hb.oangle z (-x) = \u03c0 :=\nby simp_rw [\u2190oangle_neg_left_eq_neg_right, hb.oangle_add_cyc3_neg_left hx hy hz]\n\n/-- Pons asinorum, oriented vector angle form. -/\nlemma oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : \u2225x\u2225 = \u2225y\u2225) :\n  hb.oangle x (x - y) = hb.oangle (y - x) y :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx] },\n  { have hy : y \u2260 0 := norm_ne_zero_iff.1 (h \u25b8 norm_ne_zero_iff.2 hx),\n    simp_rw [hb.oangle_rev y, oangle, linear_isometry_equiv.map_sub,\n             \u2190complex.arg_conj_coe_angle, sub_div,\n             div_self (((complex.isometry_of_orthonormal hb).symm.map_eq_zero_iff).not.2 hx),\n             div_self (((complex.isometry_of_orthonormal hb).symm.map_eq_zero_iff).not.2 hy),\n             map_sub, map_one],\n    rw \u2190inv_div,\n    simp_rw [complex.inv_def, complex.norm_sq_div, \u2190complex.sq_abs, \u2190complex.norm_eq_abs,\n             linear_isometry_equiv.norm_map, h],\n    simp [hy] }\nend\n\n/-- The angle at the apex of an isosceles triangle is `\u03c0` minus twice a base angle, oriented\nvector angle form. -/\nlemma oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x \u2260 y) (h : \u2225x\u2225 = \u2225y\u2225) :\n  hb.oangle y x = \u03c0 - (2 : \u2124) \u2022 hb.oangle (y - x) y :=\nbegin\n  rw two_zsmul,\n  rw [\u2190hb.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] { occs := occurrences.pos [1] },\n  rw [eq_sub_iff_add_eq, \u2190oangle_neg_neg, \u2190add_assoc],\n  have hy : y \u2260 0,\n  { rintro rfl,\n    rw [norm_zero, norm_eq_zero] at h,\n    exact hn h },\n  have hx : x \u2260 0 := norm_ne_zero_iff.1 (h.symm \u25b8 norm_ne_zero_iff.2 hy),\n  convert hb.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm);\n    simp\nend\n\n/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle\nform. -/\nlemma oangle_eq_two_zsmul_oangle_sub_of_norm_eq {x y z : V} (hxyne : x \u2260 y) (hxzne : x \u2260 z)\n  (hxy : \u2225x\u2225 = \u2225y\u2225) (hxz : \u2225x\u2225 = \u2225z\u2225) : hb.oangle y z = (2 : \u2124) \u2022 hb.oangle (y - x) (z - x) :=\nbegin\n  have hy : y \u2260 0,\n  { rintro rfl,\n    rw [norm_zero, norm_eq_zero] at hxy,\n    exact hxyne hxy },\n  have hx : x \u2260 0 := norm_ne_zero_iff.1 (hxy.symm \u25b8 norm_ne_zero_iff.2 hy),\n  have hz : z \u2260 0 := norm_ne_zero_iff.1 (hxz \u25b8 norm_ne_zero_iff.2 hx),\n  calc hb.oangle y z = hb.oangle x z - hb.oangle x y : (hb.oangle_sub_left hx hy hz).symm\n       ...           = (\u03c0 - (2 : \u2124) \u2022 hb.oangle (x - z) x) -\n                       (\u03c0 - (2 : \u2124) \u2022 hb.oangle (x - y) x) :\n         by rw [hb.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxzne.symm hxz.symm,\n                hb.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxyne.symm hxy.symm]\n       ...           = (2 : \u2124) \u2022 (hb.oangle (x - y) x - hb.oangle (x - z) x) : by abel\n       ...           = (2 : \u2124) \u2022 hb.oangle (x - y) (x - z) :\n         by rw hb.oangle_sub_right (sub_ne_zero_of_ne hxyne) (sub_ne_zero_of_ne hxzne) hx\n       ...           = (2 : \u2124) \u2022 hb.oangle (y - x) (z - x) :\n         by rw [\u2190oangle_neg_neg, neg_sub, neg_sub]\nend\n\n/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle\nform with radius specified. -/\nlemma oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real {x y z : V} (hxyne : x \u2260 y) (hxzne : x \u2260 z)\n  {r : \u211d} (hx : \u2225x\u2225 = r) (hy : \u2225y\u2225 = r) (hz : \u2225z\u2225 = r) :\n  hb.oangle y z = (2 : \u2124) \u2022 hb.oangle (y - x) (z - x) :=\nhb.oangle_eq_two_zsmul_oangle_sub_of_norm_eq hxyne hxzne (hy.symm \u25b8 hx) (hz.symm \u25b8 hx)\n\n/-- Oriented vector angle version of \"angles in same segment are equal\" and \"opposite angles of\na cyclic quadrilateral add to \u03c0\", for oriented angles mod \u03c0 (for which those are the same\nresult), represented here as equality of twice the angles. -/\nlemma two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq {x\u2081 x\u2082 y z : V} (hx\u2081yne : x\u2081 \u2260 y)\n  (hx\u2081zne : x\u2081 \u2260 z) (hx\u2082yne : x\u2082 \u2260 y) (hx\u2082zne : x\u2082 \u2260 z) {r : \u211d} (hx\u2081 : \u2225x\u2081\u2225 = r) (hx\u2082 : \u2225x\u2082\u2225 = r)\n  (hy : \u2225y\u2225 = r) (hz : \u2225z\u2225 = r) :\n  (2 : \u2124) \u2022 hb.oangle (y - x\u2081) (z - x\u2081) = (2 : \u2124) \u2022 hb.oangle (y - x\u2082) (z - x\u2082) :=\nhb.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx\u2081yne hx\u2081zne hx\u2081 hy hz \u25b8\n  hb.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx\u2082yne hx\u2082zne hx\u2082 hy hz\n\n/-- A rotation by the oriented angle `\u03b8`. -/\ndef rotation (\u03b8 : real.angle) : V \u2243\u2097\u1d62[\u211d] V :=\n((complex.isometry_of_orthonormal hb).symm.trans (rotation (real.angle.exp_map_circle \u03b8))).trans\n  (complex.isometry_of_orthonormal hb)\n\n/-- The determinant of `rotation` (as a linear map) is equal to `1`. -/\n@[simp] lemma det_rotation (\u03b8 : real.angle) :\n  ((hb.rotation \u03b8).to_linear_equiv : V \u2192\u2097[\u211d] V).det = 1 :=\nby simp [rotation, \u2190linear_isometry_equiv.to_linear_equiv_symm, \u2190linear_equiv.comp_coe]\n\n/-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/\n@[simp] lemma linear_equiv_det_rotation (\u03b8 : real.angle) :\n  (hb.rotation \u03b8).to_linear_equiv.det = 1 :=\nby simp [rotation, \u2190linear_isometry_equiv.to_linear_equiv_symm]\n\n/-- The inverse of `rotation` is rotation by the negation of the angle. -/\n@[simp] lemma rotation_symm (\u03b8 : real.angle) : (hb.rotation \u03b8).symm = hb.rotation (-\u03b8) :=\nby simp [rotation, linear_isometry_equiv.trans_assoc]\n\n/-- Rotation by 0 is the identity. -/\n@[simp] lemma rotation_zero : hb.rotation 0 = linear_isometry_equiv.refl \u211d V :=\nby simp [rotation]\n\n/-- Rotation by \u03c0 is negation. -/\nlemma rotation_pi : hb.rotation \u03c0 = linear_isometry_equiv.neg \u211d :=\nbegin\n  ext x,\n  simp [rotation]\nend\n\n/-- Rotating twice is equivalent to rotating by the sum of the angles. -/\n@[simp] lemma rotation_trans (\u03b8\u2081 \u03b8\u2082 : real.angle) :\n  (hb.rotation \u03b8\u2081).trans (hb.rotation \u03b8\u2082) = hb.rotation (\u03b8\u2082 + \u03b8\u2081) :=\nbegin\n  simp only [rotation, \u2190linear_isometry_equiv.trans_assoc],\n  ext1 x,\n  simp\nend\n\n/-- Rotating the first vector by `\u03b8` subtracts `\u03b8` from the angle between two vectors. -/\n@[simp] lemma oangle_rotation_left {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) (\u03b8 : real.angle) :\n  hb.oangle (hb.rotation \u03b8 x) y = hb.oangle x y - \u03b8 :=\nbegin\n  simp [oangle, rotation, complex.arg_div_coe_angle, complex.arg_mul_coe_angle, hx, hy,\n        ne_zero_of_mem_circle],\n  abel\nend\n\n/-- Rotating the second vector by `\u03b8` adds `\u03b8` to the angle between two vectors. -/\n@[simp] lemma oangle_rotation_right {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) (\u03b8 : real.angle) :\n  hb.oangle x (hb.rotation \u03b8 y) = hb.oangle x y + \u03b8 :=\nbegin\n  simp [oangle, rotation, complex.arg_div_coe_angle, complex.arg_mul_coe_angle, hx, hy,\n        ne_zero_of_mem_circle],\n  abel\nend\n\n/-- The rotation of a vector by `\u03b8` has an angle of `-\u03b8` from that vector. -/\n@[simp] lemma oangle_rotation_self_left {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  hb.oangle (hb.rotation \u03b8 x) x = -\u03b8 :=\nby simp [hx]\n\n/-- A vector has an angle of `\u03b8` from the rotation of that vector by `\u03b8`. -/\n@[simp] lemma oangle_rotation_self_right {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  hb.oangle x (hb.rotation \u03b8 x) = \u03b8 :=\nby simp [hx]\n\n/-- Rotating the first vector by the angle between the two vectors results an an angle of 0. -/\n@[simp] lemma oangle_rotation_oangle_left (x y : V) :\n  hb.oangle (hb.rotation (hb.oangle x y) x) y = 0 :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx] },\n  { by_cases hy : y = 0,\n    { simp [hy] },\n    { simp [hx, hy] } }\nend\n\n/-- Rotating the first vector by the angle between the two vectors and swapping the vectors\nresults an an angle of 0. -/\n@[simp] lemma oangle_rotation_oangle_right (x y : V) :\n  hb.oangle y (hb.rotation (hb.oangle x y) x) = 0 :=\nbegin\n  rw [oangle_rev],\n  simp\nend\n\n/-- Rotating both vectors by the same angle does not change the angle between those vectors. -/\n@[simp] lemma oangle_rotation (x y : V) (\u03b8 : real.angle) :\n  hb.oangle (hb.rotation \u03b8 x) (hb.rotation \u03b8 y) = hb.oangle x y :=\nbegin\n  by_cases hx : x = 0; by_cases hy : y = 0;\n    simp [hx, hy]\nend\n\n/-- A rotation of a nonzero vector equals that vector if and only if the angle is zero. -/\n@[simp] lemma rotation_eq_self_iff_angle_eq_zero {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  hb.rotation \u03b8 x = x \u2194 \u03b8 = 0 :=\nbegin\n  split,\n  { intro h,\n    rw eq_comm,\n    simpa [hx, h] using hb.oangle_rotation_right hx hx \u03b8 },\n  { intro h,\n    simp [h] }\nend\n\n/-- A nonzero vector equals a rotation of that vector if and only if the angle is zero. -/\n@[simp] lemma eq_rotation_self_iff_angle_eq_zero {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  x = hb.rotation \u03b8 x \u2194 \u03b8 = 0 :=\nby rw [\u2190hb.rotation_eq_self_iff_angle_eq_zero hx, eq_comm]\n\n/-- A rotation of a vector equals that vector if and only if the vector or the angle is zero. -/\nlemma rotation_eq_self_iff (x : V) (\u03b8 : real.angle) :\n  hb.rotation \u03b8 x = x \u2194 x = 0 \u2228 \u03b8 = 0 :=\nbegin\n  by_cases h : x = 0;\n    simp [h]\nend\n\n/-- A vector equals a rotation of that vector if and only if the vector or the angle is zero. -/\nlemma eq_rotation_self_iff (x : V) (\u03b8 : real.angle) :\n  x = hb.rotation \u03b8 x \u2194 x = 0 \u2228 \u03b8 = 0 :=\nby rw [\u2190rotation_eq_self_iff, eq_comm]\n\n/-- Rotating a vector by the angle to another vector gives the second vector if and only if the\nnorms are equal. -/\n@[simp] lemma rotation_oangle_eq_iff_norm_eq (x y : V) :\n  hb.rotation (hb.oangle x y) x = y \u2194 \u2225x\u2225 = \u2225y\u2225 :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190h, linear_isometry_equiv.norm_map] },\n  { intro h,\n    rw hb.eq_iff_oangle_eq_zero_of_norm_eq;\n      simp [h] }\nend\n\n/-- The angle between two nonzero vectors is `\u03b8` if and only if the second vector is the first\nrotated by `\u03b8` and scaled by the ratio of the norms. -/\nlemma oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0)\n  (\u03b8 : real.angle) : hb.oangle x y = \u03b8 \u2194 y = (\u2225y\u2225 / \u2225x\u2225) \u2022 hb.rotation \u03b8 x :=\nbegin\n  have hp := div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx),\n  split,\n  { rintro rfl,\n    rw [\u2190linear_isometry_equiv.map_smul, \u2190hb.oangle_smul_left_of_pos x y hp,\n        eq_comm, rotation_oangle_eq_iff_norm_eq, norm_smul, real.norm_of_nonneg hp.le,\n        div_mul_cancel _ (norm_ne_zero_iff.2 hx)] },\n  { intro hye,\n    rw [hye, hb.oangle_smul_right_of_pos _ _ hp, hb.oangle_rotation_self_right hx] }\nend\n\n/-- The angle between two nonzero vectors is `\u03b8` if and only if the second vector is the first\nrotated by `\u03b8` and scaled by a positive real. -/\nlemma oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0)\n  (\u03b8 : real.angle) : hb.oangle x y = \u03b8 \u2194 \u2203 r : \u211d, 0 < r \u2227 y = r \u2022 hb.rotation \u03b8 x :=\nbegin\n  split,\n  { intro h,\n    rw hb.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy at h,\n    exact \u27e8\u2225y\u2225 / \u2225x\u2225, div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx), h\u27e9 },\n  { rintro \u27e8r, hr, rfl\u27e9,\n    rw [hb.oangle_smul_right_of_pos _ _ hr, hb.oangle_rotation_self_right hx] }\nend\n\n/-- The angle between two vectors is `\u03b8` if and only if they are nonzero and the second vector\nis the first rotated by `\u03b8` and scaled by the ratio of the norms, or `\u03b8` and at least one of the\nvectors are zero. -/\nlemma oangle_eq_iff_eq_norm_div_norm_smul_rotation_or_eq_zero {x y : V} (\u03b8 : real.angle) :\n  hb.oangle x y = \u03b8 \u2194\n    (x \u2260 0 \u2227 y \u2260 0 \u2227 y = (\u2225y\u2225 / \u2225x\u2225) \u2022 hb.rotation \u03b8 x) \u2228 (\u03b8 = 0 \u2227 (x = 0 \u2228 y = 0)) :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx, eq_comm] },\n  { by_cases hy : y = 0,\n    { simp [hy, eq_comm] },\n    { rw hb.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy,\n      simp [hx, hy] } }\nend\n\n/-- The angle between two vectors is `\u03b8` if and only if they are nonzero and the second vector\nis the first rotated by `\u03b8` and scaled by a positive real, or `\u03b8` and at least one of the\nvectors are zero. -/\nlemma oangle_eq_iff_eq_pos_smul_rotation_or_eq_zero {x y : V} (\u03b8 : real.angle) :\n  hb.oangle x y = \u03b8 \u2194\n    (x \u2260 0 \u2227 y \u2260 0 \u2227 \u2203 r : \u211d, 0 < r \u2227 y = r \u2022 hb.rotation \u03b8 x) \u2228 (\u03b8 = 0 \u2227 (x = 0 \u2228 y = 0)) :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx, eq_comm] },\n  { by_cases hy : y = 0,\n    { simp [hy, eq_comm] },\n    { rw hb.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero hx hy,\n      simp [hx, hy] } }\nend\n\n/-- Complex conjugation as a linear isometric equivalence in `V`. Note that this definition\ndepends on the choice of basis, not just on its orientation; for most geometrical purposes,\nthe `reflection` definitions should be preferred instead. -/\ndef conj_lie : V \u2243\u2097\u1d62[\u211d] V :=\n((complex.isometry_of_orthonormal hb).symm.trans complex.conj_lie).trans\n  (complex.isometry_of_orthonormal hb)\n\n/-- The determinant of `conj_lie` (as a linear map) is equal to `-1`. -/\n@[simp] lemma det_conj_lie : (hb.conj_lie.to_linear_equiv : V \u2192\u2097[\u211d] V).det = -1 :=\nby simp [conj_lie, \u2190linear_isometry_equiv.to_linear_equiv_symm, \u2190linear_equiv.comp_coe]\n\n/-- The determinant of `conj_lie` (as a linear equiv) is equal to `-1`. -/\n@[simp] lemma linear_equiv_det_conj_lie : hb.conj_lie.to_linear_equiv.det = -1 :=\nby simp [conj_lie, \u2190linear_isometry_equiv.to_linear_equiv_symm]\n\n/-- `conj_lie` is its own inverse. -/\n@[simp] lemma conj_lie_symm : hb.conj_lie.symm = hb.conj_lie :=\nrfl\n\n/-- Applying `conj_lie` to both vectors negates the angle between those vectors. -/\n@[simp] lemma oangle_conj_lie (x y : V) :\n  hb.oangle (hb.conj_lie x) (hb.conj_lie y) = -hb.oangle x y :=\nby simp only [orthonormal.conj_lie, linear_isometry_equiv.symm_apply_apply, orthonormal.oangle,\n  eq_self_iff_true, function.comp_app, complex.arg_coe_angle_eq_iff,\n  linear_isometry_equiv.coe_trans, neg_inj, complex.conj_lie_apply, complex.arg_conj_coe_angle,\n  \u2190(star_ring_end \u2102).map_div]\n\n/-- Any linear isometric equivalence in `V` is `rotation` or `conj_lie` composed with\n`rotation`. -/\nlemma exists_linear_isometry_equiv_eq (f : V \u2243\u2097\u1d62[\u211d] V) :\n  \u2203 \u03b8 : real.angle, f = hb.rotation \u03b8 \u2228 f = hb.conj_lie.trans (hb.rotation \u03b8) :=\nbegin\n  cases linear_isometry_complex (((complex.isometry_of_orthonormal hb).trans f).trans\n    (complex.isometry_of_orthonormal hb).symm) with a ha,\n  use complex.arg a,\n  rcases ha with (ha|ha),\n  { left,\n    simp only [rotation, \u2190ha, linear_isometry_equiv.trans_assoc, linear_isometry_equiv.refl_trans,\n               linear_isometry_equiv.symm_trans_self, real.angle.exp_map_circle_coe,\n               exp_map_circle_arg],\n    simp [\u2190linear_isometry_equiv.trans_assoc] },\n  { right,\n    simp only [rotation, conj_lie, linear_isometry_equiv.trans_assoc,\n               real.angle.exp_map_circle_coe, exp_map_circle_arg],\n    simp only [\u2190linear_isometry_equiv.trans_assoc, linear_isometry_equiv.self_trans_symm,\n               linear_isometry_equiv.trans_refl],\n    simp_rw [linear_isometry_equiv.trans_assoc complex.conj_lie, \u2190ha],\n    simp only [linear_isometry_equiv.trans_assoc, linear_isometry_equiv.refl_trans,\n               linear_isometry_equiv.symm_trans_self],\n    simp [\u2190linear_isometry_equiv.trans_assoc] }\nend\n\n/-- Any linear isometric equivalence in `V` with positive determinant is `rotation`. -/\nlemma exists_linear_isometry_equiv_eq_of_det_pos {f : V \u2243\u2097\u1d62[\u211d] V}\n  (hd : 0 < (f.to_linear_equiv : V \u2192\u2097[\u211d] V).det) : \u2203 \u03b8 : real.angle, f = hb.rotation \u03b8 :=\nbegin\n  rcases hb.exists_linear_isometry_equiv_eq f with \u27e8\u03b8, (hf|hf)\u27e9,\n  { exact \u27e8\u03b8, hf\u27e9 },\n  { simp [hf, \u2190linear_equiv.coe_det] at hd,\n    norm_num at hd }\nend\n\n/-- Any linear isometric equivalence in `V` with negative determinant is `conj_lie` composed\nwith `rotation`. -/\nlemma exists_linear_isometry_equiv_eq_of_det_neg {f : V \u2243\u2097\u1d62[\u211d] V}\n  (hd : (f.to_linear_equiv : V \u2192\u2097[\u211d] V).det < 0) :\n  \u2203 \u03b8 : real.angle, f = hb.conj_lie.trans (hb.rotation \u03b8) :=\nbegin\n  rcases hb.exists_linear_isometry_equiv_eq f with \u27e8\u03b8, (hf|hf)\u27e9,\n  { simp [hf, \u2190linear_equiv.coe_det] at hd,\n    norm_num at hd },\n  { exact \u27e8\u03b8, hf\u27e9 }\nend\n\n/-- Two bases with the same orientation are related by a `rotation`. -/\nlemma exists_linear_isometry_equiv_map_eq_of_orientation_eq {b\u2082 : basis (fin 2) \u211d V}\n  (hb\u2082 : orthonormal \u211d b\u2082) (ho : b.orientation = b\u2082.orientation) :\n  \u2203 \u03b8 : real.angle, b\u2082 = b.map (hb.rotation \u03b8).to_linear_equiv :=\nbegin\n  have h : b\u2082 = b.map (hb.equiv hb\u2082 (equiv.refl _)).to_linear_equiv,\n  { rw hb.map_equiv, simp },\n  rw [eq_comm, h, b.orientation_comp_linear_equiv_eq_iff_det_pos] at ho,\n  cases hb.exists_linear_isometry_equiv_eq_of_det_pos ho with \u03b8 h\u03b8,\n  rw h\u03b8 at h,\n  exact \u27e8\u03b8, h\u27e9\nend\n\n/-- Two bases with opposite orientations are related by `conj_lie` composed with a `rotation`. -/\nlemma exists_linear_isometry_equiv_map_eq_of_orientation_eq_neg {b\u2082 : basis (fin 2) \u211d V}\n  (hb\u2082 : orthonormal \u211d b\u2082) (ho : b.orientation = -b\u2082.orientation) :\n  \u2203 \u03b8 : real.angle, b\u2082 = b.map (hb.conj_lie.trans (hb.rotation \u03b8)).to_linear_equiv :=\nbegin\n  have h : b\u2082 = b.map (hb.equiv hb\u2082 (equiv.refl _)).to_linear_equiv,\n  { rw hb.map_equiv, simp },\n  rw [eq_neg_iff_eq_neg, h, b.orientation_comp_linear_equiv_eq_neg_iff_det_neg] at ho,\n  cases hb.exists_linear_isometry_equiv_eq_of_det_neg ho with \u03b8 h\u03b8,\n  rw h\u03b8 at h,\n  exact \u27e8\u03b8, h\u27e9\nend\n\n/-- The angle between two vectors, with respect to a basis given by `basis.map` with a linear\nisometric equivalence, equals the angle between those two vectors, transformed by the inverse of\nthat equivalence, with respect to the original basis. -/\n@[simp] lemma oangle_map (x y : V) (f : V \u2243\u2097\u1d62[\u211d] V) :\n  (hb.map_linear_isometry_equiv f).oangle x y = hb.oangle (f.symm x) (f.symm y) :=\nby simp [oangle]\n\n/-- The value of `oangle` does not depend on the choice of basis for a given orientation. -/\nlemma oangle_eq_of_orientation_eq {b\u2082 : basis (fin 2) \u211d V} (hb\u2082 : orthonormal \u211d b\u2082)\n  (ho : b.orientation = b\u2082.orientation) (x y : V) : hb.oangle x y = hb\u2082.oangle x y :=\nbegin\n  obtain \u27e8\u03b8, rfl\u27e9 := hb.exists_linear_isometry_equiv_map_eq_of_orientation_eq hb\u2082 ho,\n  simp [hb]\nend\n\n/-- Negating the orientation negates the value of `oangle`. -/\nlemma oangle_eq_neg_of_orientation_eq_neg {b\u2082 : basis (fin 2) \u211d V} (hb\u2082 : orthonormal \u211d b\u2082)\n  (ho : b.orientation = -b\u2082.orientation) (x y : V) : hb.oangle x y = -hb\u2082.oangle x y :=\nbegin\n  obtain \u27e8\u03b8, rfl\u27e9 := hb.exists_linear_isometry_equiv_map_eq_of_orientation_eq_neg hb\u2082 ho,\n  rw hb.oangle_map,\n  simp [hb]\nend\n\n/-- `rotation` does not depend on the choice of basis for a given orientation. -/\nlemma rotation_eq_of_orientation_eq {b\u2082 : basis (fin 2) \u211d V} (hb\u2082 : orthonormal \u211d b\u2082)\n  (ho : b.orientation = b\u2082.orientation) (\u03b8 : real.angle) : hb.rotation \u03b8 = hb\u2082.rotation \u03b8 :=\nbegin\n  obtain \u27e8\u03b8\u2082, rfl\u27e9 := hb.exists_linear_isometry_equiv_map_eq_of_orientation_eq hb\u2082 ho,\n  simp_rw [rotation, complex.map_isometry_of_orthonormal hb],\n  simp only [linear_isometry_equiv.trans_assoc, linear_isometry_equiv.self_trans_symm,\n             linear_isometry_equiv.refl_trans, linear_isometry_equiv.symm_trans],\n  simp only [\u2190linear_isometry_equiv.trans_assoc, _root_.rotation_symm, _root_.rotation_trans,\n             mul_comm (real.angle.exp_map_circle \u03b8), \u2190mul_assoc, mul_right_inv, one_mul]\nend\n\n/-- Negating the orientation negates the angle in `rotation`. -/\nlemma rotation_eq_rotation_neg_of_orientation_eq_neg {b\u2082 : basis (fin 2) \u211d V}\n  (hb\u2082 : orthonormal \u211d b\u2082) (ho : b.orientation = -b\u2082.orientation) (\u03b8 : real.angle) :\n  hb.rotation \u03b8 = hb\u2082.rotation (-\u03b8) :=\nbegin\n  obtain \u27e8\u03b8\u2082, rfl\u27e9 := hb.exists_linear_isometry_equiv_map_eq_of_orientation_eq_neg hb\u2082 ho,\n  simp_rw [rotation, complex.map_isometry_of_orthonormal hb, conj_lie],\n  simp only [linear_isometry_equiv.trans_assoc, linear_isometry_equiv.self_trans_symm,\n             linear_isometry_equiv.refl_trans, linear_isometry_equiv.symm_trans],\n  congr' 1,\n  simp only [\u2190linear_isometry_equiv.trans_assoc, _root_.rotation_symm,\n             linear_isometry_equiv.symm_symm, linear_isometry_equiv.self_trans_symm,\n             linear_isometry_equiv.trans_refl, complex.conj_lie_symm],\n  congr' 1,\n  ext1 x,\n  simp only [linear_isometry_equiv.coe_trans, function.comp_app, rotation_apply,\n             complex.conj_lie_apply, map_mul, star_ring_end_self_apply, \u2190coe_inv_circle_eq_conj,\n             inv_inv, real.angle.exp_map_circle_neg, \u2190mul_assoc],\n  congr' 1,\n  simp only [mul_comm (real.angle.exp_map_circle \u03b8\u2082 : \u2102), mul_assoc],\n  rw [\u2190submonoid.coe_mul, mul_left_inv, submonoid.coe_one, mul_one]\nend\n\nend orthonormal\n\nnamespace orientation\n\nopen finite_dimensional\n\nvariables {V : Type*} [inner_product_space \u211d V]\nvariables [hd2 : fact (finrank \u211d V = 2)] (o : orientation \u211d V (fin 2))\ninclude hd2 o\n\nlocal notation `ob` := o.fin_orthonormal_basis_orthonormal dec_trivial hd2.out\n\n/-- The oriented angle from `x` to `y`, modulo `2 * \u03c0`. If either vector is 0, this is 0.\nSee `inner_product_geometry.angle` for the corresponding unoriented angle definition. -/\ndef oangle (x y : V) : real.angle :=\n(ob).oangle x y\n\n/-- If the first vector passed to `oangle` is 0, the result is 0. -/\n@[simp] lemma oangle_zero_left (x : V) : o.oangle 0 x = 0 :=\n(ob).oangle_zero_left x\n\n/-- If the second vector passed to `oangle` is 0, the result is 0. -/\n@[simp] lemma oangle_zero_right (x : V) : o.oangle x 0 = 0 :=\n(ob).oangle_zero_right x\n\n/-- If the two vectors passed to `oangle` are the same, the result is 0. -/\n@[simp] lemma oangle_self (x : V) : o.oangle x x = 0 :=\n(ob).oangle_self x\n\n/-- Swapping the two vectors passed to `oangle` negates the angle. -/\nlemma oangle_rev (x y : V) : o.oangle y x = -o.oangle x y :=\n(ob).oangle_rev x y\n\n/-- Adding the angles between two vectors in each order results in 0. -/\n@[simp] lemma oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 :=\n(ob).oangle_add_oangle_rev x y\n\n/-- Negating the first vector passed to `oangle` adds `\u03c0` to the angle. -/\nlemma oangle_neg_left {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  o.oangle (-x) y = o.oangle x y + \u03c0 :=\n(ob).oangle_neg_left hx hy\n\n/-- Negating the second vector passed to `oangle` adds `\u03c0` to the angle. -/\nlemma oangle_neg_right {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  o.oangle x (-y) = o.oangle x y + \u03c0 :=\n(ob).oangle_neg_right hx hy\n\n/-- Negating the first vector passed to `oangle` does not change twice the angle. -/\n@[simp] lemma two_zsmul_oangle_neg_left (x y : V) :\n  (2 : \u2124) \u2022 o.oangle (-x) y = (2 : \u2124) \u2022 o.oangle x y :=\n(ob).two_zsmul_oangle_neg_left x y\n\n/-- Negating the second vector passed to `oangle` does not change twice the angle. -/\n@[simp] lemma two_zsmul_oangle_neg_right (x y : V) :\n  (2 : \u2124) \u2022 o.oangle x (-y) = (2 : \u2124) \u2022 o.oangle x y :=\n(ob).two_zsmul_oangle_neg_right x y\n\n/-- Negating both vectors passed to `oangle` does not change the angle. -/\n@[simp] lemma oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y :=\n(ob).oangle_neg_neg x y\n\n/-- Negating the first vector produces the same angle as negating the second vector. -/\nlemma oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) :=\n(ob).oangle_neg_left_eq_neg_right x y\n\n/-- The angle between the negation of a nonzero vector and that vector is `\u03c0`. -/\n@[simp] lemma oangle_neg_self_left {x : V} (hx : x \u2260 0) : o.oangle (-x) x = \u03c0 :=\n(ob).oangle_neg_self_left hx\n\n/-- The angle between a nonzero vector and its negation is `\u03c0`. -/\n@[simp] lemma oangle_neg_self_right {x : V} (hx : x \u2260 0) : o.oangle x (-x) = \u03c0 :=\n(ob).oangle_neg_self_right hx\n\n/-- Twice the angle between the negation of a vector and that vector is 0. -/\n@[simp] lemma two_zsmul_oangle_neg_self_left (x : V) : (2 : \u2124) \u2022 o.oangle (-x) x = 0 :=\n(ob).two_zsmul_oangle_neg_self_left x\n\n/-- Twice the angle between a vector and its negation is 0. -/\n@[simp] lemma two_zsmul_oangle_neg_self_right (x : V) : (2 : \u2124) \u2022 o.oangle x (-x) = 0 :=\n(ob).two_zsmul_oangle_neg_self_right x\n\n/-- Adding the angles between two vectors in each order, with the first vector in each angle\nnegated, results in 0. -/\n@[simp] lemma oangle_add_oangle_rev_neg_left (x y : V) :\n  o.oangle (-x) y + o.oangle (-y) x = 0 :=\n(ob).oangle_add_oangle_rev_neg_left x y\n\n/-- Adding the angles between two vectors in each order, with the second vector in each angle\nnegated, results in 0. -/\n@[simp] lemma oangle_add_oangle_rev_neg_right (x y : V) :\n  o.oangle x (-y) + o.oangle y (-x) = 0 :=\n(ob).oangle_add_oangle_rev_neg_right x y\n\n/-- Multiplying the first vector passed to `oangle` by a positive real does not change the\nangle. -/\n@[simp] lemma oangle_smul_left_of_pos (x y : V) {r : \u211d} (hr : 0 < r) :\n  o.oangle (r \u2022 x) y = o.oangle x y :=\n(ob).oangle_smul_left_of_pos x y hr\n\n/-- Multiplying the second vector passed to `oangle` by a positive real does not change the\nangle. -/\n@[simp] lemma oangle_smul_right_of_pos (x y : V) {r : \u211d} (hr : 0 < r) :\n  o.oangle x (r \u2022 y) = o.oangle x y :=\n(ob).oangle_smul_right_of_pos x y hr\n\n/-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle\nas negating that vector. -/\n@[simp] lemma oangle_smul_left_of_neg (x y : V) {r : \u211d} (hr : r < 0) :\n  o.oangle (r \u2022 x) y = o.oangle (-x) y :=\n(ob).oangle_smul_left_of_neg x y hr\n\n/-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle\nas negating that vector. -/\n@[simp] lemma oangle_smul_right_of_neg (x y : V) {r : \u211d} (hr : r < 0) :\n  o.oangle x (r \u2022 y) = o.oangle x (-y) :=\n(ob).oangle_smul_right_of_neg x y hr\n\n/-- The angle between a nonnegative multiple of a vector and that vector is 0. -/\n@[simp] lemma oangle_smul_left_self_of_nonneg (x : V) {r : \u211d} (hr : 0 \u2264 r) :\n  o.oangle (r \u2022 x) x = 0 :=\n(ob).oangle_smul_left_self_of_nonneg x hr\n\n/-- The angle between a vector and a nonnegative multiple of that vector is 0. -/\n@[simp] lemma oangle_smul_right_self_of_nonneg (x : V) {r : \u211d} (hr : 0 \u2264 r) :\n  o.oangle x (r \u2022 x) = 0 :=\n(ob).oangle_smul_right_self_of_nonneg x hr\n\n/-- The angle between two nonnegative multiples of the same vector is 0. -/\n@[simp] lemma oangle_smul_smul_self_of_nonneg (x : V) {r\u2081 r\u2082 : \u211d} (hr\u2081 : 0 \u2264 r\u2081) (hr\u2082 : 0 \u2264 r\u2082) :\n  o.oangle (r\u2081 \u2022 x) (r\u2082 \u2022 x) = 0 :=\n(ob).oangle_smul_smul_self_of_nonneg x hr\u2081 hr\u2082\n\n/-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the\nangle. -/\n@[simp] lemma two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : \u211d} (hr : r \u2260 0) :\n  (2 : \u2124) \u2022 o.oangle (r \u2022 x) y = (2 : \u2124) \u2022 o.oangle x y :=\n(ob).two_zsmul_oangle_smul_left_of_ne_zero x y hr\n\n/-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the\nangle. -/\n@[simp] lemma two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : \u211d} (hr : r \u2260 0) :\n  (2 : \u2124) \u2022 o.oangle x (r \u2022 y) = (2 : \u2124) \u2022 o.oangle x y :=\n(ob).two_zsmul_oangle_smul_right_of_ne_zero x y hr\n\n/-- Twice the angle between a multiple of a vector and that vector is 0. -/\n@[simp] lemma two_zsmul_oangle_smul_left_self (x : V) {r : \u211d} :\n  (2 : \u2124) \u2022 o.oangle (r \u2022 x) x = 0 :=\n(ob).two_zsmul_oangle_smul_left_self x\n\n/-- Twice the angle between a vector and a multiple of that vector is 0. -/\n@[simp] lemma two_zsmul_oangle_smul_right_self (x : V) {r : \u211d} :\n  (2 : \u2124) \u2022 o.oangle x (r \u2022 x) = 0 :=\n(ob).two_zsmul_oangle_smul_right_self x\n\n/-- Twice the angle between two multiples of a vector is 0. -/\n@[simp] lemma two_zsmul_oangle_smul_smul_self (x : V) {r\u2081 r\u2082 : \u211d} :\n  (2 : \u2124) \u2022 o.oangle (r\u2081 \u2022 x) (r\u2082 \u2022 x) = 0 :=\n(ob).two_zsmul_oangle_smul_smul_self x\n\n/-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/\nlemma eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y \u2194 \u2225x\u2225 = \u2225y\u2225 \u2227 o.oangle x y = 0 :=\n(ob).eq_iff_norm_eq_and_oangle_eq_zero x y\n\n/-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/\nlemma eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : \u2225x\u2225 = \u2225y\u2225) : x = y \u2194 o.oangle x y = 0 :=\n(ob).eq_iff_oangle_eq_zero_of_norm_eq h\n\n/-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/\nlemma eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y \u2194 \u2225x\u2225 = \u2225y\u2225 :=\n(ob).eq_iff_norm_eq_of_oangle_eq_zero h\n\n/-- Given three nonzero vectors, the angle between the first and the second plus the angle\nbetween the second and the third equals the angle between the first and the third. -/\n@[simp] lemma oangle_add {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  o.oangle x y + o.oangle y z = o.oangle x z :=\n(ob).oangle_add hx hy hz\n\n/-- Given three nonzero vectors, the angle between the second and the third plus the angle\nbetween the first and the second equals the angle between the first and the third. -/\n@[simp] lemma oangle_add_swap {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n   o.oangle y z + o.oangle x y = o.oangle x z :=\n(ob).oangle_add_swap hx hy hz\n\n/-- Given three nonzero vectors, the angle between the first and the third minus the angle\nbetween the first and the second equals the angle between the second and the third. -/\n@[simp] lemma oangle_sub_left {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  o.oangle x z - o.oangle x y = o.oangle y z :=\n(ob).oangle_sub_left hx hy hz\n\n/-- Given three nonzero vectors, the angle between the first and the third minus the angle\nbetween the second and the third equals the angle between the first and the second. -/\n@[simp] lemma oangle_sub_right {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  o.oangle x z - o.oangle y z = o.oangle x y :=\n(ob).oangle_sub_right hx hy hz\n\n/-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/\n@[simp] lemma oangle_add_cyc3 {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  o.oangle x y + o.oangle y z + o.oangle z x = 0 :=\n(ob).oangle_add_cyc3 hx hy hz\n\n/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first\nvector in each angle negated, results in \u03c0. If the vectors add to 0, this is a version of the\nsum of the angles of a triangle. -/\n@[simp] lemma oangle_add_cyc3_neg_left {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = \u03c0 :=\n(ob).oangle_add_cyc3_neg_left hx hy hz\n\n/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second\nvector in each angle negated, results in \u03c0. If the vectors add to 0, this is a version of the\nsum of the angles of a triangle. -/\n@[simp] lemma oangle_add_cyc3_neg_right {x y z : V} (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = \u03c0 :=\n(ob).oangle_add_cyc3_neg_right hx hy hz\n\n/-- Pons asinorum, oriented vector angle form. -/\nlemma oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : \u2225x\u2225 = \u2225y\u2225) :\n  o.oangle x (x - y) = o.oangle (y - x) y :=\n(ob).oangle_sub_eq_oangle_sub_rev_of_norm_eq h\n\n/-- The angle at the apex of an isosceles triangle is `\u03c0` minus twice a base angle, oriented\nvector angle form. -/\nlemma oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x \u2260 y) (h : \u2225x\u2225 = \u2225y\u2225) :\n  o.oangle y x = \u03c0 - (2 : \u2124) \u2022 o.oangle (y - x) y :=\n(ob).oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hn h\n\n/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle\nform. -/\nlemma oangle_eq_two_zsmul_oangle_sub_of_norm_eq {x y z : V} (hxyne : x \u2260 y) (hxzne : x \u2260 z)\n  (hxy : \u2225x\u2225 = \u2225y\u2225) (hxz : \u2225x\u2225 = \u2225z\u2225) : o.oangle y z = (2 : \u2124) \u2022 o.oangle (y - x) (z - x) :=\n(ob).oangle_eq_two_zsmul_oangle_sub_of_norm_eq hxyne hxzne hxy hxz\n\n/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle\nform with radius specified. -/\nlemma oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real {x y z : V} (hxyne : x \u2260 y) (hxzne : x \u2260 z)\n  {r : \u211d} (hx : \u2225x\u2225 = r) (hy : \u2225y\u2225 = r) (hz : \u2225z\u2225 = r) :\n  o.oangle y z = (2 : \u2124) \u2022 o.oangle (y - x) (z - x) :=\n(ob).oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hxyne hxzne hx hy hz\n\n/-- Oriented vector angle version of \"angles in same segment are equal\" and \"opposite angles of\na cyclic quadrilateral add to \u03c0\", for oriented angles mod \u03c0 (for which those are the same\nresult), represented here as equality of twice the angles. -/\nlemma two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq {x\u2081 x\u2082 y z : V} (hx\u2081yne : x\u2081 \u2260 y)\n  (hx\u2081zne : x\u2081 \u2260 z) (hx\u2082yne : x\u2082 \u2260 y) (hx\u2082zne : x\u2082 \u2260 z) {r : \u211d} (hx\u2081 : \u2225x\u2081\u2225 = r) (hx\u2082 : \u2225x\u2082\u2225 = r)\n  (hy : \u2225y\u2225 = r) (hz : \u2225z\u2225 = r) :\n  (2 : \u2124) \u2022 o.oangle (y - x\u2081) (z - x\u2081) = (2 : \u2124) \u2022 o.oangle (y - x\u2082) (z - x\u2082) :=\n(ob).two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq hx\u2081yne hx\u2081zne hx\u2082yne hx\u2082zne hx\u2081 hx\u2082\n  hy hz\n\n/-- A rotation by the oriented angle `\u03b8`. -/\ndef rotation (\u03b8 : real.angle) : V \u2243\u2097\u1d62[\u211d] V :=\n(ob).rotation \u03b8\n\n/-- The determinant of `rotation` (as a linear map) is equal to `1`. -/\n@[simp] lemma det_rotation (\u03b8 : real.angle) :\n  ((o.rotation \u03b8).to_linear_equiv : V \u2192\u2097[\u211d] V).det = 1 :=\n(ob).det_rotation \u03b8\n\n/-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/\n@[simp] lemma linear_equiv_det_rotation (\u03b8 : real.angle) :\n  (o.rotation \u03b8).to_linear_equiv.det = 1 :=\n(ob).linear_equiv_det_rotation \u03b8\n\n/-- The inverse of `rotation` is rotation by the negation of the angle. -/\n@[simp] lemma rotation_symm (\u03b8 : real.angle) : (o.rotation \u03b8).symm = o.rotation (-\u03b8) :=\n(ob).rotation_symm \u03b8\n\n/-- Rotation by 0 is the identity. -/\n@[simp] lemma rotation_zero : o.rotation 0 = linear_isometry_equiv.refl \u211d V :=\n(ob).rotation_zero\n\n/-- Rotation by \u03c0 is negation. -/\nlemma rotation_pi : o.rotation \u03c0 = linear_isometry_equiv.neg \u211d :=\n(ob).rotation_pi\n\n/-- Rotating twice is equivalent to rotating by the sum of the angles. -/\n@[simp] lemma rotation_trans (\u03b8\u2081 \u03b8\u2082 : real.angle) :\n  (o.rotation \u03b8\u2081).trans (o.rotation \u03b8\u2082) = o.rotation (\u03b8\u2082 + \u03b8\u2081) :=\n(ob).rotation_trans \u03b8\u2081 \u03b8\u2082\n\n/-- Rotating the first vector by `\u03b8` subtracts `\u03b8` from the angle between two vectors. -/\n@[simp] lemma oangle_rotation_left {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) (\u03b8 : real.angle) :\n  o.oangle (o.rotation \u03b8 x) y = o.oangle x y - \u03b8 :=\n(ob).oangle_rotation_left hx hy \u03b8\n\n/-- Rotating the second vector by `\u03b8` adds `\u03b8` to the angle between two vectors. -/\n@[simp] lemma oangle_rotation_right {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) (\u03b8 : real.angle) :\n  o.oangle x (o.rotation \u03b8 y) = o.oangle x y + \u03b8 :=\n(ob).oangle_rotation_right hx hy \u03b8\n\n/-- The rotation of a vector by `\u03b8` has an angle of `-\u03b8` from that vector. -/\n@[simp] lemma oangle_rotation_self_left {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  o.oangle (o.rotation \u03b8 x) x = -\u03b8 :=\n(ob).oangle_rotation_self_left hx \u03b8\n\n/-- A vector has an angle of `\u03b8` from the rotation of that vector by `\u03b8`. -/\n@[simp] lemma oangle_rotation_self_right {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  o.oangle x (o.rotation \u03b8 x) = \u03b8 :=\n(ob).oangle_rotation_self_right hx \u03b8\n\n/-- Rotating the first vector by the angle between the two vectors results an an angle of 0. -/\n@[simp] lemma oangle_rotation_oangle_left (x y : V) :\n  o.oangle (o.rotation (o.oangle x y) x) y = 0 :=\n(ob).oangle_rotation_oangle_left x y\n\n/-- Rotating the first vector by the angle between the two vectors and swapping the vectors\nresults an an angle of 0. -/\n@[simp] lemma oangle_rotation_oangle_right (x y : V) :\n  o.oangle y (o.rotation (o.oangle x y) x) = 0 :=\n(ob).oangle_rotation_oangle_right x y\n\n/-- Rotating both vectors by the same angle does not change the angle between those vectors. -/\n@[simp] lemma oangle_rotation (x y : V) (\u03b8 : real.angle) :\n  o.oangle (o.rotation \u03b8 x) (o.rotation \u03b8 y) = o.oangle x y :=\n(ob).oangle_rotation x y \u03b8\n\n/-- A rotation of a nonzero vector equals that vector if and only if the angle is zero. -/\n@[simp] lemma rotation_eq_self_iff_angle_eq_zero {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  o.rotation \u03b8 x = x \u2194 \u03b8 = 0 :=\n(ob).rotation_eq_self_iff_angle_eq_zero hx \u03b8\n\n/-- A nonzero vector equals a rotation of that vector if and only if the angle is zero. -/\n@[simp] lemma eq_rotation_self_iff_angle_eq_zero {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  x = o.rotation \u03b8 x \u2194 \u03b8 = 0 :=\n(ob).eq_rotation_self_iff_angle_eq_zero hx \u03b8\n\n/-- A rotation of a vector equals that vector if and only if the vector or the angle is zero. -/\nlemma rotation_eq_self_iff (x : V) (\u03b8 : real.angle) :\n  o.rotation \u03b8 x = x \u2194 x = 0 \u2228 \u03b8 = 0 :=\n(ob).rotation_eq_self_iff x \u03b8\n\n/-- A vector equals a rotation of that vector if and only if the vector or the angle is zero. -/\nlemma eq_rotation_self_iff (x : V) (\u03b8 : real.angle) :\n  x = o.rotation \u03b8 x \u2194 x = 0 \u2228 \u03b8 = 0 :=\n(ob).eq_rotation_self_iff x \u03b8\n\n/-- Rotating a vector by the angle to another vector gives the second vector if and only if the\nnorms are equal. -/\n@[simp] lemma rotation_oangle_eq_iff_norm_eq (x y : V) :\n  o.rotation (o.oangle x y) x = y \u2194 \u2225x\u2225 = \u2225y\u2225 :=\n(ob).rotation_oangle_eq_iff_norm_eq x y\n\n/-- The angle between two nonzero vectors is `\u03b8` if and only if the second vector is the first\nrotated by `\u03b8` and scaled by the ratio of the norms. -/\nlemma oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0)\n  (\u03b8 : real.angle) : o.oangle x y = \u03b8 \u2194 y = (\u2225y\u2225 / \u2225x\u2225) \u2022 o.rotation \u03b8 x :=\n(ob).oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy \u03b8\n\n/-- The angle between two nonzero vectors is `\u03b8` if and only if the second vector is the first\nrotated by `\u03b8` and scaled by a positive real. -/\nlemma oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0)\n  (\u03b8 : real.angle) : o.oangle x y = \u03b8 \u2194 \u2203 r : \u211d, 0 < r \u2227 y = r \u2022 o.rotation \u03b8 x :=\n(ob).oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero hx hy \u03b8\n\n/-- The angle between two vectors is `\u03b8` if and only if they are nonzero and the second vector\nis the first rotated by `\u03b8` and scaled by the ratio of the norms, or `\u03b8` and at least one of the\nvectors are zero. -/\nlemma oangle_eq_iff_eq_norm_div_norm_smul_rotation_or_eq_zero {x y : V} (\u03b8 : real.angle) :\n  o.oangle x y = \u03b8 \u2194\n    (x \u2260 0 \u2227 y \u2260 0 \u2227 y = (\u2225y\u2225 / \u2225x\u2225) \u2022 o.rotation \u03b8 x) \u2228 (\u03b8 = 0 \u2227 (x = 0 \u2228 y = 0)) :=\n(ob).oangle_eq_iff_eq_norm_div_norm_smul_rotation_or_eq_zero \u03b8\n\n/-- The angle between two vectors is `\u03b8` if and only if they are nonzero and the second vector\nis the first rotated by `\u03b8` and scaled by a positive real, or `\u03b8` and at least one of the\nvectors are zero. -/\nlemma oangle_eq_iff_eq_pos_smul_rotation_or_eq_zero {x y : V} (\u03b8 : real.angle) :\n  o.oangle x y = \u03b8 \u2194\n    (x \u2260 0 \u2227 y \u2260 0 \u2227 \u2203 r : \u211d, 0 < r \u2227 y = r \u2022 o.rotation \u03b8 x) \u2228 (\u03b8 = 0 \u2227 (x = 0 \u2228 y = 0)) :=\n(ob).oangle_eq_iff_eq_pos_smul_rotation_or_eq_zero \u03b8\n\n/-- Any linear isometric equivalence in `V` with positive determinant is `rotation`. -/\nlemma exists_linear_isometry_equiv_eq_of_det_pos {f : V \u2243\u2097\u1d62[\u211d] V}\n  (hd : 0 < (f.to_linear_equiv : V \u2192\u2097[\u211d] V).det) : \u2203 \u03b8 : real.angle, f = o.rotation \u03b8 :=\n(ob).exists_linear_isometry_equiv_eq_of_det_pos hd\n\n/-- The angle between two vectors, with respect to an orientation given by `orientation.map`\nwith a linear isometric equivalence, equals the angle between those two vectors, transformed by\nthe inverse of that equivalence, with respect to the original orientation. -/\n@[simp] lemma oangle_map (x y : V) (f : V \u2243\u2097\u1d62[\u211d] V) :\n  (orientation.map (fin 2) f.to_linear_equiv o).oangle x y = o.oangle (f.symm x) (f.symm y) :=\nbegin\n  convert (ob).oangle_map x y f using 1,\n  refine orthonormal.oangle_eq_of_orientation_eq _ _ _ _ _,\n  simp_rw [basis.orientation_map, orientation.fin_orthonormal_basis_orientation]\nend\n\n/-- `orientation.oangle` equals `orthonormal.oangle` for any orthonormal basis with that\norientation. -/\nlemma oangle_eq_basis_oangle {b : basis (fin 2) \u211d V} (hb : orthonormal \u211d b)\n  (h : b.orientation = o) (x y : V) : o.oangle x y = hb.oangle x y :=\nbegin\n  rw oangle,\n  refine orthonormal.oangle_eq_of_orientation_eq _ _ _ _ _,\n  simp [h]\nend\n\n/-- Negating the orientation negates the value of `oangle`. -/\nlemma oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -(o.oangle x y) :=\nbegin\n  simp_rw oangle,\n  refine orthonormal.oangle_eq_neg_of_orientation_eq_neg _ _ _ _ _,\n  simp_rw orientation.fin_orthonormal_basis_orientation\nend\n\n/-- `orientation.rotation` equals `orthonormal.rotation` for any orthonormal basis with that\norientation. -/\nlemma rotation_eq_basis_rotation {b : basis (fin 2) \u211d V} (hb : orthonormal \u211d b)\n  (h : b.orientation = o) (\u03b8 : \u211d) : o.rotation \u03b8 = hb.rotation \u03b8 :=\nbegin\n  rw rotation,\n  refine orthonormal.rotation_eq_of_orientation_eq _ _ _ _,\n  simp [h]\nend\n\n/-- Negating the orientation negates the angle in `rotation`. -/\nlemma rotation_neg_orientation_eq_neg (\u03b8 : real.angle) :\n  (-o).rotation \u03b8 = o.rotation (-\u03b8) :=\nbegin\n  simp_rw rotation,\n  refine orthonormal.rotation_eq_rotation_neg_of_orientation_eq_neg _ _ _ _,\n  simp_rw orientation.fin_orthonormal_basis_orientation\nend\n\nend orientation\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/geometry/euclidean/oriented_angle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7295742956802449}}
{"text": "import data.real.basic\n\nvariables a b c : \u211d\n\n#check pow_two_nonneg\n#check pow_two_nonneg b\n#check @add_le_add\n\n-- BEGIN\nexample {z : \u211d} (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1) :\n  z \u2265 0 :=\nbegin\n  cases h with a ha,\n  cases ha with b hb,\n  have ha2 : a ^ 2 \u2265 0,\n    from pow_two_nonneg a,\n  have hb2 : b ^ 2 \u2265 0,\n    from pow_two_nonneg b,\n  have ha2b2 := add_nonneg ha2 hb2,\n  cases hb,\n  { rw hb, exact ha2b2 },\n  { rw hb, exact add_nonneg ha2b2 zero_le_one },\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.1_cases_exist/ex11_cases_pow_two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7295636487660999}}
{"text": "import binary_nat\nimport data.nat.basic\nimport data.nat.pow\nimport tactic.suggest\nimport tactic.linarith\n\nopen binary_nat\nopen costed_binary_nat\nopen complexity\n\nuniverse u\nvariables {\u03b1 : Type u}\n\nlemma zero_lt_two_pow {n : \u2115} : 0 < (2 ^ n) :=\nnat.lt_of_lt_of_le (by simp) (nat.one_le_two_pow _)\n\nlemma pow_two_pow_square {n m : \u2115} : n ^ 2 ^ (m + 1) = n ^ 2 ^ m * n ^ 2 ^ m :=\nby  rw [pow_succ, mul_comm 2, pow_mul, pow_succ, pow_one] \n\nlemma one_lt_two_two_pow : \u2200 n : \u2115, 1 < (2 ^ 2 ^ n)\n| 0 := by simp\n| (n+1) := begin\n  rw [pow_two_pow_square],\n  apply lt_mul_of_lt_of_one_le,\n  apply one_lt_two_two_pow,\n  apply le_of_lt,\n  apply one_lt_two_two_pow,\nend\n\nlemma mod_cancel {x y: \u2115} (z : \u2115) (H: x = y): x % z = y % z := by simp[H]\n\ntheorem toNat_bound : \u03a0 {n}, \u2200 x : binary_nat n, toNat x < 2 ^ 2 ^ n\n| 0 := begin\n  intro x,\n  cases x,\n  all_goals { simp[toNat] },\nend\n| (n+1) := begin\n  intro x,\n  cases x with _ xu xl,\n  simp [toNat],\n  apply @nat.lt_of_lt_of_le _ (2 ^ 2 ^ n * xu.toNat + 2 ^ 2 ^ n),\n  apply add_lt_add_left,\n  apply toNat_bound,\n  rw [\u2190 nat.mul_succ, pow_two_pow_square],\n  apply nat.mul_le_mul_left,\n  apply nat.le_of_lt_succ,\n  apply nat.succ_lt_succ,\n  apply toNat_bound,\nend\n\ntheorem toNat_cancel : \u03a0 {n}, \u2200 x y : binary_nat n,\n  toNat x = toNat y \u2194 x = y \n| 0 := begin\n  intros x y,\n  cases x,\n  all_goals {cases y},\n  all_goals {simp [toNat]},\nend\n| (n+1) := begin\n  intros x y,\n  split,\n  cases x with _ xu xl,\n  cases y with _ yu yl,\n  simp [toNat, nat.mul_comm (2^2^n)],\n  intro p,\n  have q := mod_cancel (2^2^n) p,\n  simp [nat.mul_add_mod, nat.mod_eq_of_lt (toNat_bound _)] at q,\n  rw [toNat_cancel] at q,\n  simp [q, toNat_cancel] at p,\n  exact \u27e8p, q\u27e9,\n  intro p,\n  simp [p],\nend\n\ntheorem zero_value : \u03a0 (n), toNat (cost.value_of (zero n)) = 0\n| 0 := by simp [zero, toNat]\n| (n+1) := begin\n  simp [zero, zero_value, toNat],\nend\n\nlemma nat_mul_add_div_left (y z : \u2115) {x : \u2115} (H: 0 < x) : (x * y + z) / x = y + z / x :=\nby simp [add_comm, nat.add_mul_div_left _ _ H]\n\nlemma mod_absorb {x y z : \u2115} (H: 0 < x) : x * (y % x) + (z % x) = (x * y + (z % x)) % (x ^ 2) :=\nbegin\n  have g := show (x * (y % x) + (z % x) < x ^ 2),\n  begin\n    apply @nat.lt_of_lt_of_le _ (x * (y % x) + x),\n    apply add_lt_add_left,\n    apply nat.mod_lt _ H,\n    rw [\u2190 nat.mul_succ, pow_succ, pow_one],\n    apply nat.mul_le_mul_left,\n    apply nat.le_of_lt_succ,\n    apply nat.succ_lt_succ,\n    apply nat.mod_lt _ H,\n  end,\n  rw [\u2190 nat.mod_eq_of_lt g],\n  rw [\u2190 nat.mul_mod_mul_left],\n  rw [pow_succ, pow_one],\n  rw [nat.mod_add_mod],\nend\n\nlemma mul_lt_div {a b c : \u2115} : a < c \u2192 b < c \u2192 a * b / c < c :=\nbegin\n  intros p q,\n  apply @lt_of_mul_lt_mul_left _ c,\n  apply @nat.lt_of_add_lt_add_right _ (a*b%c),\n  rw [nat.div_add_mod],\n  apply nat.lt_add_right,\n  cases a,\n  simp,\n  assumption,\n  apply @nat.lt_trans _ (a.succ*c),\n  apply nat.mul_lt_mul_of_pos_left,\n  assumption,\n  apply nat.zero_lt_succ,\n  apply nat.mul_lt_mul_of_pos_right,\n  assumption,\n  apply pos_of_gt,\n  assumption,\n  apply nat.zero_le _,\nend\n\nlemma add_mul_lt_div {a b c d e : \u2115} : (a < b) \u2192 (c < b) \u2192 (d + b < e) \u2192 (d + a*c/b < e) :=\nbegin\n  intros p q r,\n  apply nat.lt_trans _ r,\n  rw add_lt_add_iff_left,\n  exact mul_lt_div p q,\nend\n\ntheorem add_with_carry_value : \u03a0 {n}, \u2200 x y : binary_nat n, \u2200 z : binary_nat 0,\n  (toNat (cost.value_of (add_with_carry x y z)).fst = (toNat x + toNat y + toNat z) / 2 ^ 2 ^ n) \u2227\n  (toNat (cost.value_of (add_with_carry x y z)).snd = (toNat x + toNat y + toNat z) % 2 ^ 2 ^ n)\n| 0 := begin\n  intros x y z,\n  cases x,\n  all_goals { cases y },\n  all_goals { cases z },\n  all_goals { simp [add_with_carry, toNat] },\n  all_goals { ring },\nend\n| (n+1) := begin\n  intros x y z,\n  cases x with binary_nat.intro xu xl,\n  cases y with binary_nat.intro yu yl,\n  simp [add_with_carry, toNat,\n      (add_with_carry_value _ _ _).left,\n      (add_with_carry_value _ _ _).right],\n  split,\n  ring_nf,\n  rw [pow_two_pow_square],\n  rw [\u2190 nat.div_div_eq_div_mul,\n      nat_mul_add_div_left _ _ zero_lt_two_pow,\n      nat_mul_add_div_left _ _ zero_lt_two_pow],\n  rw [mod_absorb zero_lt_two_pow],\n  rw [\u2190 pow_mul, nat.mul_comm _ 2, \u2190 pow_succ],\n  apply mod_cancel,\n  simp [mul_add, nat.add_assoc],\n  rw [nat.div_add_mod],\n  ring,\nend\n\ntheorem add_value { n : \u2115 } {x y : binary_nat n } :\n    toNat (cost.value_of (add x y)) = (toNat x + toNat y) % 2 ^ 2 ^ n :=\nby simp[add, toNat, add_with_carry_value x y bit_false]\n\ntheorem traditional_multiply_value : \u03a0 {n}, \u2200 {x y : binary_nat n },\n    toNat (cost.value_of (traditional_multiply x y)) = (toNat x * toNat y)\n| 0 := begin\n  intros x y,\n  cases x,\n  all_goals {cases y},\n  all_goals {simp [traditional_multiply, toNat]},\nend\n| (n+1) := begin\n  intros x y,\n  cases x with binary_nat.intro xu xl,\n  cases y with binary_nat.intro yu yl,\n  simp [traditional_multiply, toNat,\n      zero_value, add_value, traditional_multiply_value],\n  cases h : (cost.value_of (traditional_multiply xu yl)) with _ ulu ull,\n  cases g : (cost.value_of (traditional_multiply xl yu)) with _ luu lul,\n  simp [split, toNat],\n  rw [\u2190 toNat_cancel] at h,\n  rw [\u2190 toNat_cancel] at g,\n  have H : (\u2200 {n x y z : \u2115}, x = 2^2^n * y + z \u2192 2^2^ n * x = 2^2^(n + 1) * y + 2^2^n * z),\n  { intros n x y z p,\n    rw [pow_two_pow_square, p],\n    ring },\n  simp [traditional_multiply_value, toNat] at h,\n  simp [traditional_multiply_value, toNat] at g,\n  rw [\u2190 H h, \u2190 H g, nat.mod_eq_of_lt],\n  simp [mul_add, add_mul, pow_two_pow_square],\n  ring,\n  simp [pow_two_pow_square],\n  simp [\u2190 nat.add_assoc],\n  have reduce : \u2200 {a b c d e: \u2115 }, a < c \u2192 b < c \u2192 e + c*c + 1 < d + 2*c \u2192 \n  e + a*b < d,\n  { intros a b c d e p q r,\n    rw [\u2190 add_lt_add_iff_right (2*c)],\n    apply nat.lt_of_le_of_lt _ r,\n    simp [nat.add_assoc],\n    cases c,\n    linarith,\n    simp [nat.succ_eq_add_one, mul_add, add_mul],\n    ring_nf,\n    simp [\u2190 nat.add_assoc, add_mul],\n    apply nat.mul_le_mul,\n    apply nat.le_of_lt_succ q,\n    apply nat.le_of_lt_succ p, },\n  apply reduce (toNat_bound _) (toNat_bound _),\n  apply @nat.lt_of_div_lt_div _ _ (2^2^n),\n  simp [nat.add_assoc, nat.mul_assoc,\n    nat_mul_add_div_left _ _ zero_lt_two_pow, nat.div_eq_zero (one_lt_two_two_pow _)],\n  simp [\u2190 nat.add_assoc, nat.add_comm _ (2^2^n)],\n  apply reduce (toNat_bound _) (toNat_bound _),\n  simp [nat.add_right_comm _ (xu.toNat * yl.toNat)],\n  apply reduce (toNat_bound _) (toNat_bound _),\n  simp [\u2190 nat.add_assoc, nat.add_right_comm _ 1],\n  apply @nat.lt_of_div_lt_div _ _ (2^2^n),\n  simp [nat.add_assoc, nat.mul_assoc,\n        nat_mul_add_div_left _ _ zero_lt_two_pow,\n        nat.div_eq_zero (one_lt_two_two_pow _),\n        nat.add_mul_div_right],\n  rw [nat.add_comm, \u2190 nat.succ_add, nat.succ_eq_add_one],\n  apply reduce (toNat_bound _) (toNat_bound _),\n  linarith,\nend", "meta": {"author": "calcu16", "repo": "lean_complexity", "sha": "0dcb73bde8d1d4237f782f4790166365ac3209fe", "save_path": "github-repos/lean/calcu16-lean_complexity", "path": "github-repos/lean/calcu16-lean_complexity/lean_complexity-0dcb73bde8d1d4237f782f4790166365ac3209fe/src/binary_nat_value.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7295636245752752}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Demostrar que hay alg\u00fan n\u00famero real entre 2 y 3.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\nbegin\n  have h : 2 < (5 : \u211d) / 2 \u2227 (5 : \u211d) / 2 < 3,\n    by norm_num,\n  show \u2203 x : \u211d, 2 < x \u2227 x < 3,\n    by exact Exists.intro (5 / 2) h,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\nbegin\n  have h : 2 < (5 : \u211d) / 2 \u2227 (5 : \u211d) / 2 < 3,\n    by norm_num,\n  show \u2203 x : \u211d, 2 < x \u2227 x < 3,\n    by exact \u27e85 / 2, h\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\nbegin\n  use 5 / 2,\n  norm_num\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\n\u27e85 / 2, by norm_num\u27e9\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Existencia_de_valor_intermedio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7294499891099487}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport measure_theory.constructions.prod\nimport measure_theory.group.measure\n\n/-!\n# Measure theory in the product of groups\nIn this file we show properties about measure theory in products of measurable groups\nand properties of iterated integrals in measurable groups.\n\nThese lemmas show the uniqueness of left invariant measures on measurable groups, up to\nscaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos.\n\nThe idea of the proof is to use the translation invariance of measures to prove `\u03bc(t) = c * \u03bc(s)`\nfor two sets `s` and `t`, where `c` is a constant that does not depend on `\u03bc`. Let `e` and `f` be\nthe characteristic functions of `s` and `t`.\nAssume that `\u03bc` and `\u03bd` are left-invariant measures. Then the map `(x, y) \u21a6 (y * x, x\u207b\u00b9)`\npreserves the measure `\u03bc \u00d7 \u03bd`, which means that\n```\n  \u222b x, \u222b y, h x y \u2202\u03bd \u2202\u03bc = \u222b x, \u222b y, h (y * x) x\u207b\u00b9 \u2202\u03bd \u2202\u03bc\n```\nIf we apply this to `h x y := e x * f y\u207b\u00b9 / \u03bd ((\u03bb h, h * y\u207b\u00b9) \u207b\u00b9' s)`, we can rewrite the RHS to\n`\u03bc(t)`, and the LHS to `c * \u03bc(s)`, where `c = c(\u03bd)` does not depend on `\u03bc`.\nApplying this to `\u03bc` and to `\u03bd` gives `\u03bc (t) / \u03bc (s) = \u03bd (t) / \u03bd (s)`, which is the uniqueness up to\nscalar multiplication.\n\nThe proof in [Halmos] seems to contain an omission in \u00a760 Th. A, see\n`measure_theory.measure_lintegral_div_measure`.\n\n-/\n\nnoncomputable theory\nopen set (hiding prod_eq) function measure_theory filter (hiding map)\nopen_locale classical ennreal pointwise measure_theory\n\nvariables (G : Type*) [measurable_space G]\nvariables [group G] [has_measurable_mul\u2082 G]\nvariables (\u03bc \u03bd : measure G) [sigma_finite \u03bd] [sigma_finite \u03bc] {s : set G}\n\n/-- The map `(x, y) \u21a6 (x, xy)` as a `measurable_equiv`. -/\n@[to_additive \"The map `(x, y) \u21a6 (x, x + y)` as a `measurable_equiv`.\"]\nprotected def measurable_equiv.shear_mul_right [has_measurable_inv G] : G \u00d7 G \u2243\u1d50 G \u00d7 G :=\n{ measurable_to_fun  := measurable_fst.prod_mk measurable_mul,\n  measurable_inv_fun := measurable_fst.prod_mk $ measurable_fst.inv.mul measurable_snd,\n  .. equiv.prod_shear (equiv.refl _) equiv.mul_left }\n\n/-- The map `(x, y) \u21a6 (x, y / x)` as a `measurable_equiv` with as inverse `(x, y) \u21a6 (x, yx)` -/\n@[to_additive\n  \"The map `(x, y) \u21a6 (x, y - x)` as a `measurable_equiv` with as inverse `(x, y) \u21a6 (x, y + x)`.\"]\nprotected def measurable_equiv.shear_div_right [has_measurable_inv G] : G \u00d7 G \u2243\u1d50 G \u00d7 G :=\n{ measurable_to_fun  := measurable_fst.prod_mk $ measurable_snd.div measurable_fst,\n  measurable_inv_fun := measurable_fst.prod_mk $ measurable_snd.mul measurable_fst,\n  .. equiv.prod_shear (equiv.refl _) (equiv.div_right) }\n\nvariables {G}\n\nnamespace measure_theory\n\nopen measure\n\nsection left_invariant\n\n/-- The multiplicative shear mapping `(x, y) \u21a6 (x, xy)` preserves the measure `\u03bc \u00d7 \u03bd`.\nThis condition is part of the definition of a measurable group in [Halmos, \u00a759].\nThere, the map in this lemma is called `S`. -/\n@[to_additive measure_preserving_prod_add\n  /-\" The shear mapping `(x, y) \u21a6 (x, x + y)` preserves the measure `\u03bc \u00d7 \u03bd`. \"-/]\nlemma measure_preserving_prod_mul [is_mul_left_invariant \u03bd] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.1, z.1 * z.2)) (\u03bc.prod \u03bd) (\u03bc.prod \u03bd) :=\n(measure_preserving.id \u03bc).skew_product measurable_mul $\n  filter.eventually_of_forall $ map_mul_left_eq_self \u03bd\n\n/-- The map `(x, y) \u21a6 (y, yx)` sends the measure `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`.\nThis is the map `SR` in [Halmos, \u00a759].\n`S` is the map `(x, y) \u21a6 (x, xy)` and `R` is `prod.swap`. -/\n@[to_additive measure_preserving_prod_add_swap\n  /-\" The map `(x, y) \u21a6 (y, y + x)` sends the measure `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`. \"-/]\nlemma measure_preserving_prod_mul_swap [is_mul_left_invariant \u03bc] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.2, z.2 * z.1)) (\u03bc.prod \u03bd) (\u03bd.prod \u03bc) :=\n(measure_preserving_prod_mul \u03bd \u03bc).comp measure_preserving_swap\n\n@[to_additive]\nlemma measurable_measure_mul_right (hs : measurable_set s) :\n  measurable (\u03bb x, \u03bc ((\u03bb y, y * x) \u207b\u00b9' s)) :=\nbegin\n  suffices : measurable (\u03bb y,\n    \u03bc ((\u03bb x, (x, y)) \u207b\u00b9' ((\u03bb z : G \u00d7 G, ((1 : G), z.1 * z.2)) \u207b\u00b9' (univ \u00d7\u02e2 s)))),\n  { convert this, ext1 x, congr' 1 with y : 1, simp },\n  apply measurable_measure_prod_mk_right,\n  exact measurable_const.prod_mk measurable_mul (measurable_set.univ.prod hs)\nend\n\nvariables [has_measurable_inv G]\n\n/-- The map `(x, y) \u21a6 (x, x\u207b\u00b9y)` is measure-preserving.\nThis is the function `S\u207b\u00b9` in [Halmos, \u00a759],\nwhere `S` is the map `(x, y) \u21a6 (x, xy)`. -/\n@[to_additive measure_preserving_prod_neg_add\n  \"The map `(x, y) \u21a6 (x, - x + y)` is measure-preserving.\"]\nlemma measure_preserving_prod_inv_mul [is_mul_left_invariant \u03bd] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.1, z.1\u207b\u00b9 * z.2)) (\u03bc.prod \u03bd) (\u03bc.prod \u03bd) :=\n(measure_preserving_prod_mul \u03bc \u03bd).symm $ measurable_equiv.shear_mul_right G\n\nvariables [is_mul_left_invariant \u03bc]\n\n/-- The map `(x, y) \u21a6 (y, y\u207b\u00b9x)` sends `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`.\nThis is the function `S\u207b\u00b9R` in [Halmos, \u00a759],\nwhere `S` is the map `(x, y) \u21a6 (x, xy)` and `R` is `prod.swap`. -/\n@[to_additive measure_preserving_prod_neg_add_swap\n  \"The map `(x, y) \u21a6 (y, - y + x)` sends `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`.\"]\nlemma measure_preserving_prod_inv_mul_swap :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.2, z.2\u207b\u00b9 * z.1)) (\u03bc.prod \u03bd) (\u03bd.prod \u03bc) :=\n(measure_preserving_prod_inv_mul \u03bd \u03bc).comp measure_preserving_swap\n\n/-- The map `(x, y) \u21a6 (yx, x\u207b\u00b9)` is measure-preserving.\nThis is the function `S\u207b\u00b9RSR` in [Halmos, \u00a759],\nwhere `S` is the map `(x, y) \u21a6 (x, xy)` and `R` is `prod.swap`. -/\n@[to_additive measure_preserving_add_prod_neg\n  \"The map `(x, y) \u21a6 (y + x, - x)` is measure-preserving.\"]\nlemma measure_preserving_mul_prod_inv [is_mul_left_invariant \u03bd] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) (\u03bc.prod \u03bd) (\u03bc.prod \u03bd) :=\nbegin\n  convert (measure_preserving_prod_inv_mul_swap \u03bd \u03bc).comp\n    (measure_preserving_prod_mul_swap \u03bc \u03bd),\n  ext1 \u27e8x, y\u27e9,\n  simp_rw [function.comp_apply, mul_inv_rev, inv_mul_cancel_right]\nend\n\n@[to_additive] lemma quasi_measure_preserving_inv :\n  quasi_measure_preserving (has_inv.inv : G \u2192 G) \u03bc \u03bc :=\nbegin\n  refine \u27e8measurable_inv, absolutely_continuous.mk $ \u03bb s hsm h\u03bcs, _\u27e9,\n  rw [map_apply measurable_inv hsm, inv_preimage],\n  have hf : measurable (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) :=\n    (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  suffices : map (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) (\u03bc.prod \u03bc) (s\u207b\u00b9 \u00d7\u02e2 s\u207b\u00b9) = 0,\n  { simpa only [(measure_preserving_mul_prod_inv \u03bc \u03bc).map_eq,\n      prod_prod, mul_eq_zero, or_self] using this },\n  have hsm' : measurable_set (s\u207b\u00b9 \u00d7\u02e2 s\u207b\u00b9) := hsm.inv.prod hsm.inv,\n  simp_rw [map_apply hf hsm', prod_apply_symm (hf hsm'), preimage_preimage, mk_preimage_prod,\n    inv_preimage, inv_inv, measure_mono_null (inter_subset_right _ _) h\u03bcs, lintegral_zero]\nend\n\n@[to_additive]\nlemma measure_inv_null : \u03bc s\u207b\u00b9 = 0 \u2194 \u03bc s = 0 :=\nbegin\n  refine \u27e8\u03bb hs, _, (quasi_measure_preserving_inv \u03bc).preimage_null\u27e9,\n  rw [\u2190 inv_inv s],\n  exact (quasi_measure_preserving_inv \u03bc).preimage_null hs\nend\n\n@[to_additive]\nlemma inv_absolutely_continuous : \u03bc.inv \u226a \u03bc :=\n(quasi_measure_preserving_inv \u03bc).absolutely_continuous\n\n@[to_additive]\nlemma absolutely_continuous_inv : \u03bc \u226a \u03bc.inv :=\nbegin\n  refine absolutely_continuous.mk (\u03bb s hs, _),\n  simp_rw [inv_apply \u03bc s, measure_inv_null, imp_self]\nend\n\n@[to_additive]\nlemma lintegral_lintegral_mul_inv [is_mul_left_invariant \u03bd]\n  (f : G \u2192 G \u2192 \u211d\u22650\u221e) (hf : ae_measurable (uncurry f) (\u03bc.prod \u03bd)) :\n  \u222b\u207b x, \u222b\u207b y, f (y * x) x\u207b\u00b9 \u2202\u03bd \u2202\u03bc = \u222b\u207b x, \u222b\u207b y, f x y \u2202\u03bd \u2202\u03bc :=\nbegin\n  have h : measurable (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) :=\n  (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  have h2f : ae_measurable (uncurry $ \u03bb x y, f (y * x) x\u207b\u00b9) (\u03bc.prod \u03bd) :=\n    hf.comp_quasi_measure_preserving (measure_preserving_mul_prod_inv \u03bc \u03bd).quasi_measure_preserving,\n  simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf],\n  conv_rhs { rw [\u2190 (measure_preserving_mul_prod_inv \u03bc \u03bd).map_eq] },\n  symmetry,\n  exact lintegral_map' (hf.mono' (measure_preserving_mul_prod_inv \u03bc \u03bd).map_eq.absolutely_continuous)\n    h.ae_measurable,\nend\n\n@[to_additive]\nlemma measure_mul_right_null (y : G) :\n  \u03bc ((\u03bb x, x * y) \u207b\u00b9' s) = 0 \u2194 \u03bc s = 0 :=\ncalc \u03bc ((\u03bb x, x * y) \u207b\u00b9' s) = 0 \u2194 \u03bc ((\u03bb x, y\u207b\u00b9 * x) \u207b\u00b9' s\u207b\u00b9)\u207b\u00b9 = 0 :\n  by simp_rw [\u2190 inv_preimage, preimage_preimage, mul_inv_rev, inv_inv]\n... \u2194 \u03bc s = 0 : by simp only [measure_inv_null \u03bc, measure_preimage_mul]\n\n@[to_additive]\nlemma measure_mul_right_ne_zero\n  (h2s : \u03bc s \u2260 0) (y : G) : \u03bc ((\u03bb x, x * y) \u207b\u00b9' s) \u2260 0 :=\n(not_iff_not_of_iff (measure_mul_right_null \u03bc y)).mpr h2s\n\n@[to_additive]\nlemma absolutely_continuous_map_mul_right (g : G) : \u03bc \u226a map (* g) \u03bc :=\nbegin\n  refine absolutely_continuous.mk (\u03bb s hs, _),\n  rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null], exact id\nend\n\n@[to_additive]\nlemma absolutely_continuous_map_div_left (g : G) : \u03bc \u226a map (\u03bb h, g / h) \u03bc :=\nbegin\n  simp_rw [div_eq_mul_inv],\n  rw [\u2190 map_map (measurable_const_mul g) measurable_inv],\n  conv_lhs { rw [\u2190 map_mul_left_eq_self \u03bc g] },\n  exact (absolutely_continuous_inv \u03bc).map (measurable_const_mul g)\nend\n\n/-- This is the computation performed in the proof of [Halmos, \u00a760 Th. A]. -/\n@[to_additive \"This is the computation performed in the proof of [Halmos, \u00a760 Th. A].\"]\nlemma measure_mul_lintegral_eq\n  [is_mul_left_invariant \u03bd] (sm : measurable_set s) (f : G \u2192 \u211d\u22650\u221e) (hf : measurable f) :\n  \u03bc s * \u222b\u207b y, f y \u2202\u03bd = \u222b\u207b x, \u03bd ((\u03bb z, z * x) \u207b\u00b9' s) * f (x\u207b\u00b9) \u2202\u03bc :=\nbegin\n  rw [\u2190 set_lintegral_one, \u2190 lintegral_indicator _ sm,\n    \u2190 lintegral_lintegral_mul (measurable_const.indicator sm).ae_measurable hf.ae_measurable,\n    \u2190 lintegral_lintegral_mul_inv \u03bc \u03bd],\n  swap, { exact (((measurable_const.indicator sm).comp measurable_fst).mul\n      (hf.comp measurable_snd)).ae_measurable },\n  have ms : \u2200 x : G, measurable (\u03bb y, ((\u03bb z, z * x) \u207b\u00b9' s).indicator (\u03bb z, (1 : \u211d\u22650\u221e)) y) :=\n  \u03bb x, measurable_const.indicator (measurable_mul_const _ sm),\n  have : \u2200 x y, s.indicator (\u03bb (z : G), (1 : \u211d\u22650\u221e)) (y * x) =\n    ((\u03bb z, z * x) \u207b\u00b9' s).indicator (\u03bb (b : G), 1) y,\n  { intros x y, symmetry, convert indicator_comp_right (\u03bb y, y * x), ext1 z, refl },\n  simp_rw [this, lintegral_mul_const _ (ms _), lintegral_indicator _ (measurable_mul_const _ sm),\n    set_lintegral_one],\nend\n\n/-- Any two nonzero left-invariant measures are absolutely continuous w.r.t. each other. -/\n@[to_additive /-\" Any two nonzero left-invariant measures are absolutely continuous w.r.t. each\nother. \"-/]\nlemma absolutely_continuous_of_is_mul_left_invariant [is_mul_left_invariant \u03bd] (h\u03bd : \u03bd \u2260 0) :\n  \u03bc \u226a \u03bd :=\nbegin\n  refine absolutely_continuous.mk (\u03bb s sm h\u03bds, _),\n  have h1 := measure_mul_lintegral_eq \u03bc \u03bd sm 1 measurable_one,\n  simp_rw [pi.one_apply, lintegral_one, mul_one, (measure_mul_right_null \u03bd _).mpr h\u03bds,\n    lintegral_zero, mul_eq_zero, measure_univ_eq_zero.not.mpr h\u03bd, or_false] at h1,\n  exact h1\nend\n\n@[to_additive]\nlemma ae_measure_preimage_mul_right_lt_top [is_mul_left_invariant \u03bd]\n  (sm : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u2200\u1d50 x \u2202\u03bc, \u03bd ((\u03bb y, y * x) \u207b\u00b9' s) < \u221e :=\nbegin\n  refine ae_of_forall_measure_lt_top_ae_restrict' \u03bd.inv _ _,\n  intros A hA h2A h3A,\n  simp only [\u03bd.inv_apply] at h3A,\n  apply ae_lt_top (measurable_measure_mul_right \u03bd sm),\n  have h1 := measure_mul_lintegral_eq \u03bc \u03bd sm (A\u207b\u00b9.indicator 1) (measurable_one.indicator hA.inv),\n  rw [lintegral_indicator _ hA.inv] at h1,\n  simp_rw [pi.one_apply, set_lintegral_one, \u2190 image_inv, indicator_image inv_injective, image_inv,\n    \u2190 indicator_mul_right _ (\u03bb x, \u03bd ((\u03bb y, y * x) \u207b\u00b9' s)), function.comp, pi.one_apply,\n    mul_one] at h1,\n  rw [\u2190 lintegral_indicator _ hA, \u2190 h1],\n  exact ennreal.mul_ne_top h\u03bcs h3A.ne,\nend\n\n@[to_additive]\nlemma ae_measure_preimage_mul_right_lt_top_of_ne_zero [is_mul_left_invariant \u03bd]\n  (sm : measurable_set s) (h2s : \u03bd s \u2260 0) (h3s : \u03bd s \u2260 \u221e) :\n  \u2200\u1d50 x \u2202\u03bc, \u03bd ((\u03bb y, y * x) \u207b\u00b9' s) < \u221e :=\nbegin\n  refine (ae_measure_preimage_mul_right_lt_top \u03bd \u03bd sm h3s).filter_mono _,\n  refine (absolutely_continuous_of_is_mul_left_invariant \u03bc \u03bd _).ae_le,\n  refine mt _ h2s,\n  intro h\u03bd,\n  rw [h\u03bd, measure.coe_zero, pi.zero_apply]\nend\n\n/-- A technical lemma relating two different measures. This is basically [Halmos, \u00a760 Th. A].\n  Note that if `f` is the characteristic function of a measurable set `t` this states that\n  `\u03bc t = c * \u03bc s` for a constant `c` that does not depend on `\u03bc`.\n\n  Note: There is a gap in the last step of the proof in [Halmos].\n  In the last line, the equality `g(x\u207b\u00b9)\u03bd(sx\u207b\u00b9) = f(x)` holds if we can prove that\n  `0 < \u03bd(sx\u207b\u00b9) < \u221e`. The first inequality follows from \u00a759, Th. D, but the second inequality is\n  not justified. We prove this inequality for almost all `x` in\n  `measure_theory.ae_measure_preimage_mul_right_lt_top_of_ne_zero`. -/\n@[to_additive \"A technical lemma relating two different measures. This is basically\n[Halmos, \u00a760 Th. A]. Note that if `f` is the characteristic function of a measurable set `t` this\nstates that `\u03bc t = c * \u03bc s` for a constant `c` that does not depend on `\u03bc`.\n\nNote: There is a gap in the last step of the proof in [Halmos]. In the last line, the equality\n`g(-x) + \u03bd(s - x) = f(x)` holds if we can prove that `0 < \u03bd(s - x) < \u221e`. The first inequality\nfollows from \u00a759, Th. D, but the second inequality is not justified. We prove this inequality for\nalmost all `x` in `measure_theory.ae_measure_preimage_add_right_lt_top_of_ne_zero`.\"]\nlemma measure_lintegral_div_measure [is_mul_left_invariant \u03bd]\n  (sm : measurable_set s) (h2s : \u03bd s \u2260 0) (h3s : \u03bd s \u2260 \u221e)\n  (f : G \u2192 \u211d\u22650\u221e) (hf : measurable f) :\n  \u03bc s * \u222b\u207b y, f y\u207b\u00b9 / \u03bd ((\u03bb x, x * y\u207b\u00b9) \u207b\u00b9' s) \u2202\u03bd = \u222b\u207b x, f x \u2202\u03bc :=\nbegin\n  set g := \u03bb y, f y\u207b\u00b9 / \u03bd ((\u03bb x, x * y\u207b\u00b9) \u207b\u00b9' s),\n  have hg : measurable g := (hf.comp measurable_inv).div\n    ((measurable_measure_mul_right \u03bd sm).comp measurable_inv),\n  simp_rw [measure_mul_lintegral_eq \u03bc \u03bd sm g hg, g, inv_inv],\n  refine lintegral_congr_ae _,\n  refine (ae_measure_preimage_mul_right_lt_top_of_ne_zero \u03bc \u03bd sm h2s h3s).mono (\u03bb x hx , _),\n  simp_rw [ennreal.mul_div_cancel' (measure_mul_right_ne_zero \u03bd h2s _) hx.ne]\nend\n\n@[to_additive]\nlemma measure_mul_measure_eq [is_mul_left_invariant \u03bd] {s t : set G}\n  (hs : measurable_set s) (ht : measurable_set t) (h2s : \u03bd s \u2260 0) (h3s : \u03bd s \u2260 \u221e) :\n    \u03bc s * \u03bd t = \u03bd s * \u03bc t :=\nbegin\n  have h1 := measure_lintegral_div_measure \u03bd \u03bd hs h2s h3s (t.indicator (\u03bb x, 1))\n    (measurable_const.indicator ht),\n  have h2 := measure_lintegral_div_measure \u03bc \u03bd hs h2s h3s (t.indicator (\u03bb x, 1))\n    (measurable_const.indicator ht),\n  rw [lintegral_indicator _ ht, set_lintegral_one] at h1 h2,\n  rw [\u2190 h1, mul_left_comm, h2],\nend\n\n/-- Left invariant Borel measures on a measurable group are unique (up to a scalar). -/\n@[to_additive /-\" Left invariant Borel measures on an additive measurable group are unique\n  (up to a scalar). \"-/]\nlemma measure_eq_div_smul [is_mul_left_invariant \u03bd]\n  (hs : measurable_set s) (h2s : \u03bd s \u2260 0) (h3s : \u03bd s \u2260 \u221e) : \u03bc = (\u03bc s / \u03bd s) \u2022 \u03bd :=\nbegin\n  ext1 t ht,\n  rw [smul_apply, smul_eq_mul, mul_comm, \u2190 mul_div_assoc, mul_comm,\n    measure_mul_measure_eq \u03bc \u03bd hs ht h2s h3s, mul_div_assoc, ennreal.mul_div_cancel' h2s h3s]\nend\n\nend left_invariant\n\nsection right_invariant\n\n@[to_additive measure_preserving_prod_add_right]\nlemma measure_preserving_prod_mul_right [is_mul_right_invariant \u03bd] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.1, z.2 * z.1)) (\u03bc.prod \u03bd) (\u03bc.prod \u03bd) :=\n(measure_preserving.id \u03bc).skew_product (by exact measurable_snd.mul measurable_fst) $\n  filter.eventually_of_forall $ map_mul_right_eq_self \u03bd\n\n/-- The map `(x, y) \u21a6 (y, xy)` sends the measure `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`. -/\n@[to_additive measure_preserving_prod_add_swap_right\n  /-\" The map `(x, y) \u21a6 (y, x + y)` sends the measure `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`. \"-/]\nlemma measure_preserving_prod_mul_swap_right [is_mul_right_invariant \u03bc] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.2, z.1 * z.2)) (\u03bc.prod \u03bd) (\u03bd.prod \u03bc) :=\n(measure_preserving_prod_mul_right \u03bd \u03bc).comp measure_preserving_swap\n\n/-- The map `(x, y) \u21a6 (xy, y)` preserves the measure `\u03bc \u00d7 \u03bd`. -/\n@[to_additive measure_preserving_add_prod\n  /-\" The map `(x, y) \u21a6 (x + y, y)` preserves the measure `\u03bc \u00d7 \u03bd`. \"-/]\nlemma measure_preserving_mul_prod [is_mul_right_invariant \u03bc] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.1 * z.2, z.2)) (\u03bc.prod \u03bd) (\u03bc.prod \u03bd) :=\nmeasure_preserving_swap.comp $ by apply measure_preserving_prod_mul_swap_right \u03bc \u03bd\n\nvariables [has_measurable_inv G]\n\n/-- The map `(x, y) \u21a6 (x, y / x)` is measure-preserving. -/\n@[to_additive measure_preserving_prod_sub\n  \"The map `(x, y) \u21a6 (x, y - x)` is measure-preserving.\"]\n\n\n/-- The map `(x, y) \u21a6 (y, x / y)` sends `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`. -/\n@[to_additive measure_preserving_prod_sub_swap\n  \"The map `(x, y) \u21a6 (y, x - y)` sends `\u03bc \u00d7 \u03bd` to `\u03bd \u00d7 \u03bc`.\"]\nlemma measure_preserving_prod_div_swap [is_mul_right_invariant \u03bc] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.2, z.1 / z.2)) (\u03bc.prod \u03bd) (\u03bd.prod \u03bc) :=\n(measure_preserving_prod_div \u03bd \u03bc).comp measure_preserving_swap\n\n/-- The map `(x, y) \u21a6 (x / y, y)` preserves the measure `\u03bc \u00d7 \u03bd`. -/\n@[to_additive measure_preserving_sub_prod\n  /-\" The map `(x, y) \u21a6 (x - y, y)` preserves the measure `\u03bc \u00d7 \u03bd`. \"-/]\nlemma measure_preserving_div_prod [is_mul_right_invariant \u03bc] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.1 / z.2, z.2)) (\u03bc.prod \u03bd) (\u03bc.prod \u03bd) :=\nmeasure_preserving_swap.comp $ by apply measure_preserving_prod_div_swap \u03bc \u03bd\n\n/-- The map `(x, y) \u21a6 (xy, x\u207b\u00b9)` is measure-preserving. -/\n@[to_additive measure_preserving_add_prod_neg_right\n  \"The map `(x, y) \u21a6 (x + y, - x)` is measure-preserving.\"]\nlemma measure_preserving_mul_prod_inv_right [is_mul_right_invariant \u03bc] [is_mul_right_invariant \u03bd] :\n  measure_preserving (\u03bb z : G \u00d7 G, (z.1 * z.2, z.1\u207b\u00b9)) (\u03bc.prod \u03bd) (\u03bc.prod \u03bd) :=\nbegin\n  convert (measure_preserving_prod_div_swap \u03bd \u03bc).comp\n    (measure_preserving_prod_mul_swap_right \u03bc \u03bd),\n  ext1 \u27e8x, y\u27e9,\n  simp_rw [function.comp_apply, div_mul_eq_div_div_swap, div_self', one_div]\nend\n\nend right_invariant\n\nsection quasi_measure_preserving\n\nvariables [has_measurable_inv G]\n\n@[to_additive]\nlemma quasi_measure_preserving_inv_of_right_invariant [is_mul_right_invariant \u03bc] :\n  quasi_measure_preserving (has_inv.inv : G \u2192 G) \u03bc \u03bc :=\nbegin\n  rw [\u2190 \u03bc.inv_inv],\n  exact (quasi_measure_preserving_inv \u03bc.inv).mono\n    (inv_absolutely_continuous \u03bc.inv) (absolutely_continuous_inv \u03bc.inv)\nend\n\n@[to_additive]\nlemma quasi_measure_preserving_div_left [is_mul_left_invariant \u03bc] (g : G) :\n  quasi_measure_preserving (\u03bb h : G, g / h) \u03bc \u03bc :=\nbegin\n  simp_rw [div_eq_mul_inv],\n  exact (measure_preserving_mul_left \u03bc g).quasi_measure_preserving.comp\n    (quasi_measure_preserving_inv \u03bc)\nend\n\n@[to_additive]\nlemma quasi_measure_preserving_div_left_of_right_invariant [is_mul_right_invariant \u03bc] (g : G) :\n  quasi_measure_preserving (\u03bb h : G, g / h) \u03bc \u03bc :=\nbegin\n  rw [\u2190 \u03bc.inv_inv],\n  exact (quasi_measure_preserving_div_left \u03bc.inv g).mono\n    (inv_absolutely_continuous \u03bc.inv) (absolutely_continuous_inv \u03bc.inv)\nend\n\n@[to_additive]\nlemma quasi_measure_preserving_div_of_right_invariant [is_mul_right_invariant \u03bc] :\n  quasi_measure_preserving (\u03bb (p : G \u00d7 G), p.1 / p.2) (\u03bc.prod \u03bd) \u03bc :=\nbegin\n  refine quasi_measure_preserving.prod_of_left measurable_div (eventually_of_forall $ \u03bb y, _),\n  exact (measure_preserving_div_right \u03bc y).quasi_measure_preserving\nend\n\n@[to_additive]\nlemma quasi_measure_preserving_div [is_mul_left_invariant \u03bc] :\n  quasi_measure_preserving (\u03bb (p : G \u00d7 G), p.1 / p.2) (\u03bc.prod \u03bd) \u03bc :=\n(quasi_measure_preserving_div_of_right_invariant \u03bc.inv \u03bd).mono\n  ((absolutely_continuous_inv \u03bc).prod absolutely_continuous.rfl)\n  (inv_absolutely_continuous \u03bc)\n\n/-- A *left*-invariant measure is quasi-preserved by *right*-multiplication.\nThis should not be confused with `(measure_preserving_mul_right \u03bc g).quasi_measure_preserving`. -/\n@[to_additive /-\"A *left*-invariant measure is quasi-preserved by *right*-addition.\nThis should not be confused with `(measure_preserving_add_right \u03bc g).quasi_measure_preserving`. \"-/]\nlemma quasi_measure_preserving_mul_right [is_mul_left_invariant \u03bc] (g : G) :\n  quasi_measure_preserving (\u03bb h : G, h * g) \u03bc \u03bc :=\nbegin\n  refine \u27e8measurable_mul_const g, absolutely_continuous.mk $ \u03bb s hs, _\u27e9,\n  rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null], exact id,\nend\n\n/-- A *right*-invariant measure is quasi-preserved by *left*-multiplication.\nThis should not be confused with `(measure_preserving_mul_left \u03bc g).quasi_measure_preserving`. -/\n@[to_additive /-\"A *right*-invariant measure is quasi-preserved by *left*-addition.\nThis should not be confused with `(measure_preserving_add_left \u03bc g).quasi_measure_preserving`. \"-/]\nlemma quasi_measure_preserving_mul_left [is_mul_right_invariant \u03bc] (g : G) :\n  quasi_measure_preserving (\u03bb h : G, g * h) \u03bc \u03bc :=\nbegin\n  have := (quasi_measure_preserving_mul_right \u03bc.inv g\u207b\u00b9).mono\n    (inv_absolutely_continuous \u03bc.inv) (absolutely_continuous_inv \u03bc.inv),\n  rw [\u03bc.inv_inv] at this,\n  have := (quasi_measure_preserving_inv_of_right_invariant \u03bc).comp\n    (this.comp (quasi_measure_preserving_inv_of_right_invariant \u03bc)),\n  simp_rw [function.comp, mul_inv_rev, inv_inv] at this,\n  exact this\nend\n\nend quasi_measure_preserving\n\nend measure_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/group/prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7294499743973877}}
{"text": "-- import utils\nvariable b : bool\n#check b.rec_on\n#check nat.add\ninductive fin' : \u2115 \u2192 Type\n| zero : fin' 0\n| succ : \u03a0 {n : \u2115}, fin' n \u2192 fin' (n +1)\n\n-- example : \u2200 (n : \u2115) (i : fin n), i.cast_succ = (\u2191i : fin (n +1)) :=\n\n-- def foo (n : \u2115) : fin n \u2192 bool\n-- | 0      := false\n-- | (i +1) := true\n\n-- def fin_cycle : \u03a0 n : \u2115, fin n \u2192 fin n\n-- | (n +1) \u27e80,    _\u27e9 := fin.last n\n-- | (n +1) \u27e8i +1, p\u27e9 := let fin_i : fin n := \u27e8i, nat.pred_le_pred p\u27e9\n--                        in {! !} --fin.succ (fin.succ (fin_double n fin_i))\n\ndef fin_is_even : \u03a0 n : \u2115, fin n \u2192 bool\n| 0      i                        := i.elim0\n| (n +1) \u27e80,    _\u27e9                := true\n| (n +1) \u27e8i_val +1, succ_i_is_lt\u27e9 :=\n     let i : fin n := \u27e8i_val, nat.pred_le_pred succ_i_is_lt\u27e9\n      in bnot (fin_is_even n i)\n\n@[pattern]\ndef fin.zero {n : \u2115} : fin (n +1) := \u27e80, nat.zero_lt_succ n\u27e9\n\nattribute [pattern] fin.succ\n\ndef fin_is_even' : \u03a0 n : \u2115, fin n \u2192 bool\n| 0      i            := i.elim0\n| (n +1) fin.zero     := true\n| (n +1) (fin.succ i) := bnot (fin_is_even' n i)\n\nI still have another question regarding `fin`.  Sometimes, I want to use pattern matching on `i : fin n` in the same way as one will do in `\u2115` but since the inductive part is in `i.val` so I need to do as follows:\n\n```lean\ndef fin_is_even : \u03a0 n : \u2115, fin n \u2192 bool\n| 0      i                        := i.elim0\n| (n +1) \u27e80,    _\u27e9                := true\n| (n +1) \u27e8i_val +1, succ_i_is_lt\u27e9 :=hwere\n      in bnot (fin_is_even n i)\n```\n\nOk, it works but in practice, I find it quite annoying to write `let i : fin n := \u27e8i_val, nat.pred_le_pred succ_i_is_lt\u27e9` every time whereas `i` should be obtained directly from something like `fin.succ i`. Therefore, I try to use `@[pattern]` to help me with this as follows:\n\n```lean\n@[pattern]\ndef fin.zero {n : \u2115} : fin (n +1) := \u27e80, nat.zero_lt_succ n\u27e9\n\nattribute [pattern] fin.succ\n\ndef fin_is_even' : \u03a0 n : \u2115, fin n \u2192 bool\n| 0      i            := i.elim0\n| (n +1) fin.zero     := true\n| (n +1) (fin.succ i) := bnot (fin_is_even n i)\n```\n\nHowever I get an error, what is wrong with my code?  Did I misunderstand anything about `@[pattern]`?\n\nsection\n@[pattern]\ndef fin_zero {n : \u2115} : fin (n +1) := \u27e80, nat.zero_lt_succ n\u27e9\n\n@[pattern]\ndef fin_succ {n : \u2115} : fin n \u2192 fin n.succ\n| \u27e8a, h\u27e9 := \u27e8a.succ, nat.succ_lt_succ h\u27e9\n\ndef fin_is_zero (n : \u2115) : fin n \u2192 bool\n| fin_zero     := false\n| (fin_succ i) := true\nend\n", "meta": {"author": "gunpinyo", "repo": "twisted_cube_formalisation", "sha": "f78206ac495e84bd43a9b820fa10b6c94722e0ec", "save_path": "github-repos/lean/gunpinyo-twisted_cube_formalisation", "path": "github-repos/lean/gunpinyo-twisted_cube_formalisation/twisted_cube_formalisation-f78206ac495e84bd43a9b820fa10b6c94722e0ec/src/old/playground.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7294499735033483}}
{"text": "/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport linear_algebra.affine_space.affine_map\nimport tactic.field_simp\n\n/-!\n# Slope of a function\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define the slope of a function `f : k \u2192 PE` taking values in an affine space over\n`k` and prove some basic theorems about `slope`. The `slope` function naturally appears in the Mean\nValue Theorem, and in the proof of the fact that a function with nonnegative second derivative on an\ninterval is convex on this interval.\n\n## Tags\n\naffine space, slope\n-/\n\nopen affine_map\nvariables {k E PE : Type*} [field k] [add_comm_group E] [module k E] [add_torsor E PE]\n\ninclude E\n\n/-- `slope f a b = (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a)` is the slope of a function `f` on the interval\n`[a, b]`. Note that `slope f a a = 0`, not the derivative of `f` at `a`. -/\ndef slope (f : k \u2192 PE) (a b : k) : E := (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a)\n\nlemma slope_fun_def (f : k \u2192 PE) : slope f = \u03bb a b, (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a) := rfl\n\nomit E\n\nlemma slope_def_field (f : k \u2192 k) (a b : k) : slope f a b = (f b - f a) / (b - a) :=\n(div_eq_inv_mul _ _).symm\n\nlemma slope_fun_def_field (f : k \u2192 k) (a : k) : slope f a = \u03bb b, (f b - f a) / (b - a) :=\n(div_eq_inv_mul _ _).symm\n\n@[simp] lemma slope_same (f : k \u2192 PE) (a : k) : (slope f a a : E) = 0 :=\nby rw [slope, sub_self, inv_zero, zero_smul]\n\ninclude E\n\nlemma slope_def_module (f : k \u2192 E) (a b : k) : slope f a b = (b - a)\u207b\u00b9 \u2022 (f b - f a) := rfl\n\n@[simp] lemma sub_smul_slope (f : k \u2192 PE) (a b : k) : (b - a) \u2022 slope f a b = f b -\u1d65 f a :=\nbegin\n  rcases eq_or_ne a b with rfl | hne,\n  { rw [sub_self, zero_smul, vsub_self] },\n  { rw [slope, smul_inv_smul\u2080 (sub_ne_zero.2 hne.symm)] }\nend\n\nlemma sub_smul_slope_vadd (f : k \u2192 PE) (a b : k) : (b - a) \u2022 slope f a b +\u1d65 f a = f b :=\nby rw [sub_smul_slope, vsub_vadd]\n\n@[simp] lemma slope_vadd_const (f : k \u2192 E) (c : PE) :\n  slope (\u03bb x, f x +\u1d65 c) = slope f :=\nbegin\n  ext a b,\n  simp only [slope, vadd_vsub_vadd_cancel_right, vsub_eq_sub]\nend\n\n@[simp] lemma slope_sub_smul (f : k \u2192 E) {a b : k} (h : a \u2260 b):\n  slope (\u03bb x, (x - a) \u2022 f x) a b = f b :=\nby simp [slope, inv_smul_smul\u2080 (sub_ne_zero.2 h.symm)]\n\nlemma eq_of_slope_eq_zero {f : k \u2192 PE} {a b : k} (h : slope f a b = (0:E)) : f a = f b :=\nby rw [\u2190 sub_smul_slope_vadd f a b, h, smul_zero, zero_vadd]\n\nlemma affine_map.slope_comp {F PF : Type*} [add_comm_group F] [module k F] [add_torsor F PF]\n  (f : PE \u2192\u1d43[k] PF) (g : k \u2192 PE) (a b : k) :\n  slope (f \u2218 g) a b = f.linear (slope g a b) :=\nby simp only [slope, (\u2218), f.linear.map_smul, f.linear_map_vsub]\n\nlemma linear_map.slope_comp {F : Type*} [add_comm_group F] [module k F]\n  (f : E \u2192\u2097[k] F) (g : k \u2192 E) (a b : k) :\n  slope (f \u2218 g) a b = f (slope g a b) :=\nf.to_affine_map.slope_comp g a b\n\nlemma slope_comm (f : k \u2192 PE) (a b : k) : slope f a b = slope f b a :=\nby rw [slope, slope, \u2190 neg_vsub_eq_vsub_rev, smul_neg, \u2190 neg_smul, neg_inv, neg_sub]\n\n/-- `slope f a c` is a linear combination of `slope f a b` and `slope f b c`. This version\nexplicitly provides coefficients. If `a \u2260 c`, then the sum of the coefficients is `1`, so it is\nactually an affine combination, see `line_map_slope_slope_sub_div_sub`. -/\nlemma sub_div_sub_smul_slope_add_sub_div_sub_smul_slope (f : k \u2192 PE) (a b c : k) :\n  ((b - a) / (c - a)) \u2022 slope f a b + ((c - b) / (c - a)) \u2022 slope f b c = slope f a c :=\nbegin\n  by_cases hab : a = b,\n  { subst hab,\n    rw [sub_self, zero_div, zero_smul, zero_add],\n    by_cases hac : a = c,\n    { simp [hac] },\n    { rw [div_self (sub_ne_zero.2 $ ne.symm hac), one_smul] } },\n  by_cases hbc : b = c, { subst hbc, simp [sub_ne_zero.2 (ne.symm hab)] },\n  rw [add_comm],\n  simp_rw [slope, div_eq_inv_mul, mul_smul, \u2190 smul_add,\n    smul_inv_smul\u2080 (sub_ne_zero.2 $ ne.symm hab), smul_inv_smul\u2080 (sub_ne_zero.2 $ ne.symm hbc),\n    vsub_add_vsub_cancel],\nend\n\n/-- `slope f a c` is an affine combination of `slope f a b` and `slope f b c`. This version uses\n`line_map` to express this property. -/\nlemma line_map_slope_slope_sub_div_sub (f : k \u2192 PE) (a b c : k) (h : a \u2260 c) :\n  line_map (slope f a b) (slope f b c) ((c - b) / (c - a)) = slope f a c :=\nby  field_simp [sub_ne_zero.2 h.symm, \u2190 sub_div_sub_smul_slope_add_sub_div_sub_smul_slope f a b c,\n  line_map_apply_module]\n\n/-- `slope f a b` is an affine combination of `slope f a (line_map a b r)` and\n`slope f (line_map a b r) b`. We use `line_map` to express this property. -/\nlemma line_map_slope_line_map_slope_line_map (f : k \u2192 PE) (a b r : k) :\n  line_map (slope f (line_map a b r) b) (slope f a (line_map a b r)) r = slope f a b :=\nbegin\n  obtain (rfl|hab) : a = b \u2228 a \u2260 b := classical.em _, { simp },\n  rw [slope_comm _ a, slope_comm _ a, slope_comm _ _ b],\n  convert line_map_slope_slope_sub_div_sub f b (line_map a b r) a hab.symm using 2,\n  rw [line_map_apply_ring, eq_div_iff (sub_ne_zero.2 hab), sub_mul, one_mul, mul_sub, \u2190 sub_sub,\n    sub_sub_cancel]\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/affine_space/slope.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7294499685991611}}
{"text": "import tactic.interactive\n\nnamespace xnat\n\nopen nat\n\ndefinition le1 : nat \u2192 nat \u2192 Prop\n| zero zero := true\n| (succ m) zero := false\n| zero (succ p) := true\n| (succ m) (succ p) := le1 m p\n\nlemma zero_le1 (b : \u2115) : le1 0 b :=\nbegin\n  cases b,\n    trivial,\n    trivial\nend\n\ninductive le2 : \u2115 \u2192 \u2115 \u2192 Prop\n| refl (a : \u2115) : le2 a a\n| succ (a b : \u2115) : le2 a b \u2192 le2 a (succ b)\n\nlemma zero_le2 (b : \u2115) : le2 0 b :=\nbegin\n  induction b with c hc,\n    exact le2.refl 0,\n    exact le2.succ 0 c hc\nend\n\ndef le3 (a b : \u2115) : Prop := \u2203 c, a + c = b\n\nlemma zero_le3 (b : \u2115) : le3 0 b :=\nbegin\n  exact \u27e8b, nat.zero_add b\u27e9,\nend\n\nlemma succ_le_succ1 (a b : \u2115) : le1 a b \u2192 le1 (a + 1) (b + 1) := id\n\nlemma succ_le_succ3 (a b : \u2115) : le3 a b \u2192 le3 (a + 1) (b + 1) :=\nbegin\n  intro h,\n  cases h with c hc,\n  use c,\n  rw \u2190hc,\n  simp, -- probably wouldn't work for xnat\nend\n\nlemma h23 (a b : \u2115) : le2 a b \u2192 le3 a b :=\nbegin\n  induction b with d hd,\n  intro h,\n  cases h with _ _ b h2,\n    use 0,\n  intro h,\n  cases h with _ _ _ h,\n    use 0,\n  cases hd h with w hw,\n  use succ w,\n  rw \u2190hw,\nend\n\nlemma h31 (a b : \u2115) : le3 a b \u2192 le1 a b :=\nbegin\n  revert a,\n  induction b with c hc,\n  { intros a h,\n    cases h with c h,\n    cases a, trivial,\n    exfalso,\n    revert h,\n    show succ a + c \u2260 0,\n    suffices : succ a + c = succ (a + c),\n      rw this, exact dec_trivial,\n    show (a + 1) + c = (a + c) + 1,\n    simp,\n  },\n  intros a h,\n  cases a, trivial,\n  show le1 a c,\n  apply hc,\n  cases h with d hd,\n  use d,\n  apply succ_inj, -- wouldn't work for xnat\n  rw \u2190hd,\n  show (a + d) + 1 = (a + 1) + d,\n  simp, -- woudn't work for xnat\nend\n\ntheorem h21 (a b : \u2115) : le2 a b \u2192 le1 a b :=\nbegin\n  intro h,\n  apply h31 a b,\n  exact h23 a b h\nend\n\ntheorem h13 (a b : \u2115) : le1 a b \u2192 le3 a b :=\nbegin\n  revert b,\n  induction a with a ha,\n    intros b hb, exact zero_le3 _,\n  intros b hb,\n  cases b with b,\n    cases hb,\n  cases ha b hb with c hc,\n  use c,\n  rw \u2190hc,\n  show (a + 1) + c = (a + c) + 1,\n  simp,\nend\n\ntheorem h32 (a b : \u2115) : le3 a b \u2192 le2 a b :=\nbegin\n  induction b with b hb,\n  { intro h,\n    cases a with a,\n      exact le2.refl _,\n    exfalso,\n    cases h with c hc,\n    revert hc,\n    show succ a + c \u2260 0,\n    suffices : succ a + c = succ (a + c),\n      rw this, exact dec_trivial,\n    show (a + 1) + c = (a + c) + 1,\n    simp,\n  },\n  intro h,\n  cases h with c hc,\n  cases c,\n    rw \u2190hc, exact le2.refl _,\n  apply le2.succ,\n  apply hb,\n  use c,\n  apply succ_inj,\n  rw \u2190hc,\nend\n\nlemma h12 (a b : \u2115) : le1 a b \u2192 le2 a b :=\nbegin\n  intro h,\n  apply h32,\n  apply h13,\n  assumption,\nend\n\nlemma e12 (a b : \u2115) : le1 a b \u2194 le2 a b :=\nbegin\n  split,\n    exact h12 a b,\n    exact h21 a b\nend\n\nlemma e13 (a b : \u2115) : le1 a b \u2194 le3 a b :=\nbegin\n  split,\n    exact h13 a b,\n    exact h31 a b\nend\n\nlemma succ_le_succ2 (a b : \u2115) : le2 a b \u2192 le2 (a + 1) (b + 1) :=\nbegin\n  rw \u2190e12,\n  rw \u2190e12,\n  exact succ_le_succ1 a b,\nend\n\ntheorem inequality_A11 (a b t : nat) : le1 a b \u2192 le1 (a + t) (b + t) :=\nbegin\n  intro h,\n  induction t with e he,\n    exact h,\n  show le1 (succ (a + e)) (succ (b + e)),\n  exact he\nend\n\ntheorem inequality_A13 (a b t : nat) : le3 a b \u2192 le3 (a + t) (b + t) :=\nbegin\n  intro h,\n  cases h with c hc,\n  use c,\n  rw \u2190hc,\n  simp,\nend\n\ntheorem inequality_A23 (a b c : nat) : le3 a b \u2192 le3 b c \u2192 le3 a c :=\nbegin\n  intros hab hbc,\n  cases hab with d hd,\n  cases hbc with e he,\n  use d + e,\n  rw \u2190he,\n  rw \u2190hd,\n  simp,\nend\n\ntheorem inequality_A3a3 (a b : \u2115) : le3 a b \u2228 le3 b a :=\nbegin\n  revert a,\n  induction b with b hb,\n    intro a, right, exact zero_le3 a,\n  intro a,\n  cases a, left, exact zero_le3 _,\n  cases hb a,\n  { left,\n    cases h with c hc,\n    use c,\n    rw \u2190hc,\n    show (a + 1) + c = (a + c) + 1,\n    simp },\n  { right,\n    cases h with c hc,\n    use c,\n    rw \u2190hc,\n    show (b + 1) + c = (b + c) + 1,\n    simp,\n  },\nend\n\nlemma zero_of_add_eq (a b : \u2115) : a + b = a \u2192 b = 0 :=\nbegin\n  intro h,\n  induction a with a ha,\n    rw zero_add at h, assumption,\n  apply ha,\n  apply succ_inj,\n  rw \u2190h,\n  simp,\nend\n\ntheorem inequality_A3b3 (a b : \u2115) : le3 a b \u2227 le3 b a \u2192 a = b :=\nbegin\n  intro h,\n  cases h with h1 h2,\n  cases h1 with c hc,\n  cases h2 with d hd,\n  rw \u2190hc at hd,\n  rw add_assoc at hd,\n  have hcd : c + d = 0 := zero_of_add_eq _ _ hd,\n  cases c,\n    exact hc,\n  exfalso,\n  suffices : succ c + d = succ (c + d),\n    rw this at hcd,\n    cases hcd,\n  simp,\nend\n\ntheorem A4_thing (a b : \u2115) : a \u2260 0 \u2192 b \u2260 0 \u2192 a * b \u2260 0 :=\nbegin\n  intro ha,\n  intro hb,\n  cases a,\n    exfalso, apply ha, refl,\n  cases b,\n    exfalso, apply hb, refl,\n  show succ _ \u2260 0,\n  exact dec_trivial\nend\n\n\n\n\nend xnat\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/le_experiments.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7294499598294893}}
{"text": "import Mathlib.Algebra.Ring.Basic\nimport Mathlib.Data.Rat.Basic\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Ring\n\n/-!\n## `field_simp` tests.\n-/\n\n/-\nCheck that `field_simp` works for units of a ring.\n-/\n\nvariable {R : Type _} [CommRing R] (a b c d e f g : R) (u\u2081 u\u2082 : R\u02e3)\n\n/--\nCheck that `divp_add_divp_same` takes priority over `divp_add_divp`.\n-/\nexample : a /\u209a u\u2081 + b /\u209a u\u2081 = (a + b) /\u209a u\u2081 :=\nby field_simp\n\n/--\nCheck that `divp_sub_divp_same` takes priority over `divp_sub_divp`.\n-/\nexample : a /\u209a u\u2081 - b /\u209a u\u2081 = (a - b) /\u209a u\u2081 :=\nby field_simp\n\n/-\nCombining `eq_divp_iff_mul_eq` and `divp_eq_iff_mul_eq`.\n\nThis example is currently commented out because it is weirdly slow.\nSee https://github.com/leanprover/lean4/issues/2055.\n\nIt works with `set_option maxHeartbeats 300000`.\n-/\n--example : a /\u209a u\u2081 = b /\u209a u\u2082 \u2194 a * u\u2082 = b * u\u2081 :=\n--by field_simp\n\n/--\nMaking sure inverses of units are rewritten properly.\n-/\nexample : \u2191u\u2081\u207b\u00b9 = 1 /\u209a u\u2081 := by field_simp\n\n/--\nChecking arithmetic expressions.\n-/\nexample : (f - (e + c * -(a /\u209a u\u2081) * b + d) - g) =\n  (f * u\u2081 - (e * u\u2081 + c * (-a) * b + d * u\u2081) - g * u\u2081) /\u209a u\u2081 :=\nby field_simp\n\n/--\nDivision of units.\n-/\nexample : a /\u209a (u\u2081 / u\u2082) = a * u\u2082 /\u209a u\u2081 :=\nby field_simp\n\nexample : a /\u209a u\u2081 /\u209a u\u2082 = a /\u209a (u\u2082 * u\u2081) :=\nby field_simp\n\n/--\nTest that the discharger can clear nontrivial denominators in \u211a.\n-/\nexample (x : \u211a) (h\u2080 : x \u2260 0) :\n    (4 / x)\u207b\u00b9 * ((3 * x^3) / x)^2 * ((1 / (2 * x))\u207b\u00b9)^3 = 18 * x^8 := by\n  field_simp\n  ring\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/test/FieldSimp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7293739629334318}}
{"text": "/-\nCopyright (c) 2018 Mitchell Rowett. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mitchell Rowett, Scott Morrison\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.group_theory.subgroup\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-- The left coset `a*s` corresponding to an element `a : \u03b1` and a subset `s : set \u03b1` -/\ndef left_coset {\u03b1 : Type u_1} [Mul \u03b1] (a : \u03b1) (s : set \u03b1) : set \u03b1 :=\n  (fun (x : \u03b1) => a * x) '' s\n\n/-- The right coset `s*a` corresponding to an element `a : \u03b1` and a subset `s : set \u03b1` -/\ndef right_coset {\u03b1 : Type u_1} [Mul \u03b1] (s : set \u03b1) (a : \u03b1) : set \u03b1 :=\n  (fun (x : \u03b1) => x * a) '' s\n\ntheorem mem_left_coset {\u03b1 : Type u_1} [Mul \u03b1] {s : set \u03b1} {x : \u03b1} (a : \u03b1) (hxS : x \u2208 s) : a * x \u2208 left_coset a s :=\n  set.mem_image_of_mem (fun (b : \u03b1) => a * b) hxS\n\ntheorem mem_right_coset {\u03b1 : Type u_1} [Mul \u03b1] {s : set \u03b1} {x : \u03b1} (a : \u03b1) (hxS : x \u2208 s) : x * a \u2208 right_coset s a :=\n  set.mem_image_of_mem (fun (b : \u03b1) => b * a) hxS\n\n/-- Equality of two left cosets `a*s` and `b*s` -/\ndef left_coset_equiv {\u03b1 : Type u_1} [Mul \u03b1] (s : set \u03b1) (a : \u03b1) (b : \u03b1) :=\n  left_coset a s = left_coset b s\n\ntheorem left_add_coset_equiv_rel {\u03b1 : Type u_1} [Add \u03b1] (s : set \u03b1) : equivalence (left_add_coset_equiv s) :=\n  mk_equivalence (left_add_coset_equiv s) (fun (a : \u03b1) => rfl) (fun (a b : \u03b1) => Eq.symm) fun (a b c : \u03b1) => Eq.trans\n\n@[simp] theorem left_coset_assoc {\u03b1 : Type u_1} [semigroup \u03b1] (s : set \u03b1) (a : \u03b1) (b : \u03b1) : left_coset a (left_coset b s) = left_coset (a * b) s := sorry\n\n@[simp] theorem left_add_coset_assoc {\u03b1 : Type u_1} [add_semigroup \u03b1] (s : set \u03b1) (a : \u03b1) (b : \u03b1) : left_add_coset a (left_add_coset b s) = left_add_coset (a + b) s := sorry\n\n@[simp] theorem right_coset_assoc {\u03b1 : Type u_1} [semigroup \u03b1] (s : set \u03b1) (a : \u03b1) (b : \u03b1) : right_coset (right_coset s a) b = right_coset s (a * b) := sorry\n\n@[simp] theorem right_add_coset_assoc {\u03b1 : Type u_1} [add_semigroup \u03b1] (s : set \u03b1) (a : \u03b1) (b : \u03b1) : right_add_coset (right_add_coset s a) b = right_add_coset s (a + b) := sorry\n\ntheorem left_add_coset_right_add_coset {\u03b1 : Type u_1} [add_semigroup \u03b1] (s : set \u03b1) (a : \u03b1) (b : \u03b1) : right_add_coset (left_add_coset a s) b = left_add_coset a (right_add_coset s b) := sorry\n\n@[simp] theorem one_left_coset {\u03b1 : Type u_1} [monoid \u03b1] (s : set \u03b1) : left_coset 1 s = s := sorry\n\n@[simp] theorem zero_left_add_coset {\u03b1 : Type u_1} [add_monoid \u03b1] (s : set \u03b1) : left_add_coset 0 s = s := sorry\n\n@[simp] theorem right_coset_one {\u03b1 : Type u_1} [monoid \u03b1] (s : set \u03b1) : right_coset s 1 = s := sorry\n\n@[simp] theorem right_add_coset_zero {\u03b1 : Type u_1} [add_monoid \u03b1] (s : set \u03b1) : right_add_coset s 0 = s := sorry\n\ntheorem mem_own_left_coset {\u03b1 : Type u_1} [monoid \u03b1] (s : submonoid \u03b1) (a : \u03b1) : a \u2208 left_coset a \u2191s := sorry\n\ntheorem mem_own_right_add_coset {\u03b1 : Type u_1} [add_monoid \u03b1] (s : add_submonoid \u03b1) (a : \u03b1) : a \u2208 right_add_coset (\u2191s) a := sorry\n\ntheorem mem_left_coset_left_coset {\u03b1 : Type u_1} [monoid \u03b1] (s : submonoid \u03b1) {a : \u03b1} (ha : left_coset a \u2191s = \u2191s) : a \u2208 s :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 s)) (Eq.symm (propext submonoid.mem_coe))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 \u2191s)) (Eq.symm ha))) (mem_own_left_coset s a))\n\ntheorem mem_right_add_coset_right_add_coset {\u03b1 : Type u_1} [add_monoid \u03b1] (s : add_submonoid \u03b1) {a : \u03b1} (ha : right_add_coset (\u2191s) a = \u2191s) : a \u2208 s :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 s)) (Eq.symm (propext add_submonoid.mem_coe))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2208 \u2191s)) (Eq.symm ha))) (mem_own_right_add_coset s a))\n\ntheorem mem_left_coset_iff {\u03b1 : Type u_1} [group \u03b1] {s : set \u03b1} {x : \u03b1} (a : \u03b1) : x \u2208 left_coset a s \u2194 a\u207b\u00b9 * x \u2208 s := sorry\n\ntheorem mem_right_coset_iff {\u03b1 : Type u_1} [group \u03b1] {s : set \u03b1} {x : \u03b1} (a : \u03b1) : x \u2208 right_coset s a \u2194 x * (a\u207b\u00b9) \u2208 s := sorry\n\ntheorem left_coset_mem_left_coset {\u03b1 : Type u_1} [group \u03b1] (s : subgroup \u03b1) {a : \u03b1} (ha : a \u2208 s) : left_coset a \u2191s = \u2191s := sorry\n\ntheorem right_add_coset_mem_right_add_coset {\u03b1 : Type u_1} [add_group \u03b1] (s : add_subgroup \u03b1) {a : \u03b1} (ha : a \u2208 s) : right_add_coset (\u2191s) a = \u2191s := sorry\n\ntheorem normal_of_eq_cosets {\u03b1 : Type u_1} [group \u03b1] (s : subgroup \u03b1) (N : subgroup.normal s) (g : \u03b1) : left_coset g \u2191s = right_coset (\u2191s) g := sorry\n\ntheorem eq_cosets_of_normal {\u03b1 : Type u_1} [group \u03b1] (s : subgroup \u03b1) (h : \u2200 (g : \u03b1), left_coset g \u2191s = right_coset (\u2191s) g) : subgroup.normal s := sorry\n\ntheorem normal_iff_eq_add_cosets {\u03b1 : Type u_1} [add_group \u03b1] (s : add_subgroup \u03b1) : add_subgroup.normal s \u2194 \u2200 (g : \u03b1), left_add_coset g \u2191s = right_add_coset (\u2191s) g :=\n  { mp := normal_of_eq_add_cosets s, mpr := eq_add_cosets_of_normal s }\n\nnamespace quotient_group\n\n\n/-- The equivalence relation corresponding to the partition of a group by left cosets\nof a subgroup.-/\ndef Mathlib.quotient_add_group.left_rel {\u03b1 : Type u_1} [add_group \u03b1] (s : add_subgroup \u03b1) : setoid \u03b1 :=\n  setoid.mk (fun (x y : \u03b1) => -x + y \u2208 s) sorry\n\nprotected instance left_rel_decidable {\u03b1 : Type u_1} [group \u03b1] (s : subgroup \u03b1) [d : decidable_pred fun (a : \u03b1) => a \u2208 s] : DecidableRel setoid.r :=\n  fun (_x _x_1 : \u03b1) => d (_x\u207b\u00b9 * _x_1)\n\n/-- `quotient s` is the quotient type representing the left cosets of `s`.\n  If `s` is a normal subgroup, `quotient s` is a group -/\ndef quotient {\u03b1 : Type u_1} [group \u03b1] (s : subgroup \u03b1) :=\n  quotient (left_rel s)\n\nend quotient_group\n\n\nnamespace quotient_add_group\n\n\n/-- `quotient s` is the quotient type representing the left cosets of `s`.\n  If `s` is a normal subgroup, `quotient s` is a group -/\ndef quotient {\u03b1 : Type u_1} [add_group \u03b1] (s : add_subgroup \u03b1) :=\n  quotient (left_rel s)\n\nend quotient_add_group\n\n\nnamespace quotient_group\n\n\nprotected instance Mathlib.quotient_add_group.fintype {\u03b1 : Type u_1} [add_group \u03b1] [fintype \u03b1] (s : add_subgroup \u03b1) [DecidableRel setoid.r] : fintype (quotient_add_group.quotient s) :=\n  quotient.fintype (quotient_add_group.left_rel s)\n\n/-- The canonical map from a group `\u03b1` to the quotient `\u03b1/s`. -/\ndef Mathlib.quotient_add_group.mk {\u03b1 : Type u_1} [add_group \u03b1] {s : add_subgroup \u03b1} (a : \u03b1) : quotient_add_group.quotient s :=\n  quotient.mk' a\n\ntheorem induction_on {\u03b1 : Type u_1} [group \u03b1] {s : subgroup \u03b1} {C : quotient s \u2192 Prop} (x : quotient s) (H : \u2200 (z : \u03b1), C (mk z)) : C x :=\n  quotient.induction_on' x H\n\nprotected instance quotient.has_coe_t {\u03b1 : Type u_1} [group \u03b1] {s : subgroup \u03b1} : has_coe_t \u03b1 (quotient s) :=\n  has_coe_t.mk mk\n\ntheorem induction_on' {\u03b1 : Type u_1} [group \u03b1] {s : subgroup \u03b1} {C : quotient s \u2192 Prop} (x : quotient s) (H : \u2200 (z : \u03b1), C \u2191z) : C x :=\n  quotient.induction_on' x H\n\nprotected instance quotient.inhabited {\u03b1 : Type u_1} [group \u03b1] (s : subgroup \u03b1) : Inhabited (quotient s) :=\n  { default := \u21911 }\n\nprotected theorem eq {\u03b1 : Type u_1} [group \u03b1] {s : subgroup \u03b1} {a : \u03b1} {b : \u03b1} : \u2191a = \u2191b \u2194 a\u207b\u00b9 * b \u2208 s :=\n  quotient.eq'\n\ntheorem Mathlib.quotient_add_group.eq_class_eq_left_coset {\u03b1 : Type u_1} [add_group \u03b1] (s : add_subgroup \u03b1) (g : \u03b1) : (set_of fun (x : \u03b1) => \u2191x = \u2191g) = left_add_coset g \u2191s := sorry\n\ntheorem preimage_image_coe {\u03b1 : Type u_1} [group \u03b1] (N : subgroup \u03b1) (s : set \u03b1) : coe \u207b\u00b9' (coe '' s) = set.Union fun (x : \u21a5N) => (fun (y : \u03b1) => y * \u2191x) '' s := sorry\n\nend quotient_group\n\n\nnamespace subgroup\n\n\n/-- The natural bijection between the cosets `g*s` and `s` -/\ndef Mathlib.add_subgroup.left_coset_equiv_add_subgroup {\u03b1 : Type u_1} [add_group \u03b1] {s : add_subgroup \u03b1} (g : \u03b1) : \u21a5(left_add_coset g \u2191s) \u2243 \u21a5s :=\n  equiv.mk (fun (x : \u21a5(left_add_coset g \u2191s)) => { val := -g + subtype.val x, property := sorry })\n    (fun (x : \u21a5s) => { val := g + subtype.val x, property := sorry }) sorry sorry\n\n/-- A (non-canonical) bijection between a group `\u03b1` and the product `(\u03b1/s) \u00d7 s` -/\ndef Mathlib.add_subgroup.add_group_equiv_quotient_times_add_subgroup {\u03b1 : Type u_1} [add_group \u03b1] {s : add_subgroup \u03b1} : \u03b1 \u2243 quotient_add_group.quotient s \u00d7 \u21a5s :=\n  equiv.trans\n    (equiv.trans\n      (equiv.trans (equiv.symm (equiv.sigma_preimage_equiv quotient_add_group.mk))\n        (equiv.sigma_congr_right\n          fun (L : quotient_add_group.quotient s) =>\n            eq.mpr sorry (id (eq.mpr sorry (equiv.refl (Subtype fun (x : \u03b1) => quotient.mk' x = L))))))\n      (equiv.sigma_congr_right\n        fun (L : quotient_add_group.quotient s) => add_subgroup.left_coset_equiv_add_subgroup (quotient.out' L)))\n    (equiv.sigma_equiv_prod (quotient_add_group.quotient s) \u21a5s)\n\nend subgroup\n\n\nnamespace quotient_group\n\n\n-- FIXME -- why is there no `to_additive`?\n\n/-- If `s` is a subgroup of the group `\u03b1`, and `t` is a subset of `\u03b1/s`, then\nthere is a (typically non-canonical) bijection between the preimage of `t` in\n`\u03b1` and the product `s \u00d7 t`. -/\ndef preimage_mk_equiv_subgroup_times_set {\u03b1 : Type u_1} [group \u03b1] (s : subgroup \u03b1) (t : set (quotient s)) : \u21a5(mk \u207b\u00b9' t) \u2243 \u21a5s \u00d7 \u21a5t :=\n  (fun\n      (h :\n      \u2200 {x : quotient s} {a : \u03b1}, x \u2208 t \u2192 a \u2208 s \u2192 quotient.mk' (quotient.out' x * a) = quotient.mk' (quotient.out' x)) =>\n      equiv.mk (fun (_x : \u21a5(mk \u207b\u00b9' t)) => sorry) (fun (_x : \u21a5s \u00d7 \u21a5t) => sorry) sorry sorry)\n    sorry\n\nend quotient_group\n\n\n/--\nWe use the class `has_coe_t` instead of `has_coe` if the first argument is a variable,\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/group_theory/coset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7293087385546735}}
{"text": "/-\nCopyright (c) 2023 Tian Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tian Chen\n-/\n\nimport ineq.majorize\nimport data.fin.tuple.sort\n\nopen_locale big_operators\n\nopen finset\n\nvariables {\u03b1 : Type*}\n  [linear_ordered_add_comm_monoid \u03b1]\n  [decidable_rel ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n\nsection\n\nvariables {n : \u2115} {a b : fin n \u2192 \u03b1}\n\nlemma monotone.sort_eq_of_fn (ha : monotone a) :\n  (univ.val.map a).sort (\u2264) = list.of_fn a :=\nbegin\n  apply list.eq_of_perm_of_sorted _ (multiset.sort_sorted _ _) (list.monotone.of_fn_sorted ha),\n  rw [\u2190 multiset.coe_eq_coe, multiset.sort_eq],\n  show multiset.map _ \u2191(list.fin_range n) = _,\n  rw multiset.coe_map,\n  congr,\n  apply list.ext_le,\n  { rw [list.length_map, list.length_fin_range, list.length_of_fn] },\n  intros,\n  rw [list.nth_le_of_fn', list.nth_le_map', list.nth_le_fin_range]\nend\n\nlemma antitone.sort_eq_of_fn (ha : antitone a) :\n  (univ.val.map a).sort (\u2265) = list.of_fn a :=\nmonotone.sort_eq_of_fn ha.dual_right\n\nlemma antitone.majorize (ha : antitone a) (hb : antitone b) :\n  majorize a b \u2194\n    (\u2200 i, ((list.of_fn a).take i).sum \u2264 ((list.of_fn b).take i).sum)\n    \u2227 \u2211 i, a i = \u2211 i, b i :=\nbegin\n  simp_rw [\u2190 ha.sort_eq_of_fn, \u2190 hb.sort_eq_of_fn],\n  refl\nend\n\nend\n\nvariables {\u03b9 : Type*} [fintype \u03b9] (l : \u03b9 \u2192 \u03b1)\n\n/-- Sort a vector. -/\ndef sort_desc : fin (fintype.card \u03b9) \u2192 \u03b1 :=\n  \u03bb i, list.nth_le ((univ.val.map l).sort (\u2265)) i $\n    by rw [multiset.length_sort, multiset.card_map]; exact i.2\n\nlemma sort_desc_antitone : antitone (sort_desc l) :=\nbegin\n  intros i j h,\n  have : fintype.card \u03b9 = ((univ.val.map ((@order_dual.to_dual \u03b1) \u2218 l)).sort (\u2264)).length,\n  { rw [multiset.length_sort, multiset.card_map], refl },\n  let f := fin.cast this,\n  rw sort_desc,\n  exact ((univ.val.map ((@order_dual.to_dual \u03b1) \u2218 l)).sort_sorted (\u2264)).nth_le_mono\n    (show f i \u2264 f j, from h)\nend\n\nlemma of_fn_sort_desc : list.of_fn (sort_desc l) = (univ.val.map l).sort (\u2265) :=\nbegin\n  rw sort_desc,\n  apply list.ext_le,\n  { rw [list.length_of_fn, multiset.length_sort, multiset.card_map], refl },\n  intros,\n  apply list.nth_le_of_fn'\nend\n\nlemma map_sort_desc : univ.val.map (sort_desc l) = univ.val.map l :=\nbegin\n  show multiset.map _ \u2191(list.fin_range _) = _,\n  rw multiset.coe_map,\n  rw \u2190 multiset.sort_eq (\u2265) (univ.val.map l),\n  congr,\n  apply list.ext_le,\n  { rw [list.length_map, list.length_fin_range, multiset.length_sort, multiset.card_map], refl },\n  intros,\n  rw [list.nth_le_map', list.nth_le_fin_range],\n  refl\nend\n\nlemma sum_sort_desc : \u2211 i, sort_desc l i = \u2211 i, l i :=\nbegin\n  rw [finset.sum_eq_multiset_sum, finset.sum_eq_multiset_sum, map_sort_desc]\nend\n\ntheorem sort_desc_majorize_iff (a b : \u03b9 \u2192 \u03b1) :\n  majorize (sort_desc a) (sort_desc b) \u2194 majorize a b :=\nbegin\n  rw [majorize_def, majorize_def,\n    \u2190 of_fn_sort_desc a, \u2190 of_fn_sort_desc b,\n    antitone.sort_eq_of_fn (sort_desc_antitone a),\n    antitone.sort_eq_of_fn (sort_desc_antitone b),\n    sum_sort_desc,\n    sum_sort_desc]\nend\n", "meta": {"author": "peakpoint", "repo": "muirhead", "sha": "f6cbdafa9e9c1626d37378493fce68cc68eeea97", "save_path": "github-repos/lean/peakpoint-muirhead", "path": "github-repos/lean/peakpoint-muirhead/muirhead-f6cbdafa9e9c1626d37378493fce68cc68eeea97/src/ineq/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859265, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7293087324005744}}
{"text": "import group.definitions -- definition of a group and a comm_group\n\n/-\nclass group (G : Type) extends has_group_notation G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\nand `comm_group G` has the extra axiom\n\n`mul_comm : \u2200 (x y : G), x * y = y * x`\n\nYou access these axioms with `group.mul_assoc`, `group.one_mul` etc.\n-/\n\n-- This entire project takes place in the mygroup namespace\nnamespace mygroup\n\n/- Our goal is to prove the following theorems (in the order\n  listed) :\n\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n`eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9`\n`mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1`\n`eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9`\n`inv_inv (a : G) : a \u207b\u00b9 \u207b\u00b9 = a`\n`inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b`\n\nand possibly more to come if we run into stuff we need.\n\nWe start with only `mul_assoc`, `one_mul` and `mul_left_inv`. \n\nmul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c)\none_mul : \u2200 (a : G), 1 * a = a\nmul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1\n\n-/\nnamespace group\n\nvariables {G : Type} [group G]  \n\nlemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c := \nbegin\n  -- We want to prove b = c.\n  -- the left hand side is 1 * b\n  rw \u2190one_mul b,\n  -- which is (a\u207b\u00b9 * a) * b\n  rw \u2190mul_left_inv a,\n  -- which is a\u207b\u00b9 * (a * b) by associativity\n  rw mul_assoc,\n  -- which is a\u207b\u00b9 * (a * c) by our hypothesis\n  rw Habac,\n  -- and now we do the same but bakwards\n  rw [\u2190mul_assoc, mul_left_inv, one_mul],\nend\n\n-- chance to use rwa\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rwa [\u2190mul_assoc, mul_left_inv, one_mul],\nend\n\n\n\ntheorem mul_one (a : G) : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_left_inv,\nend\n\ntheorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\n-- new\nlemma eq_inv_mul_iff_mul_eq {a x y : G} : x = a\u207b\u00b9 * y \u2194 a * x = y :=\nbegin\n  split,\n    exact mul_eq_of_eq_inv_mul,\n  intro h,\n  apply mul_left_cancel a,\n  rwa [\u2190mul_assoc, mul_right_inv, one_mul],\nend\n\n-- new\nlemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y := \nbegin\n  apply_fun (\u03bb t, t * a\u207b\u00b9) at Habac,\n  rwa [mul_assoc, mul_assoc, mul_right_inv, mul_one, mul_one] at Habac,\nend\n\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nbegin\n  apply mul_right_cancel c,\n  rw h, simp [mul_assoc, mul_left_inv, mul_one],\nend\n\n--new\nlemma eq_mul_inv_iff_mul_eq {a b c : G} : a = b * c\u207b\u00b9 \u2194 a * c = b :=\nbegin\n  split,\n    intro h,\n    apply mul_right_cancel c\u207b\u00b9,\n    rw [mul_assoc, mul_right_inv, mul_one, h],\n  exact eq_mul_inv_of_mul_eq,\nend\n\n--new\nlemma eq_mul_of_inv_mul_eq {a x y : G} (h : a\u207b\u00b9 * x = y) : x = a * y :=\nbegin\n  rw [\u2190h, \u2190mul_assoc, mul_right_inv, one_mul]\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1 :=\nbegin\n  rw \u2190eq_mul_inv_iff_mul_eq,\n  rw mul_right_inv,\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9 :=\nbegin\n  rwa [\u2190eq_mul_inv_iff_mul_eq, one_mul] at h,\nend\n\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b :=\nbegin\n  apply mul_left_cancel a,\n  rw [mul_right_inv, h]\nend\n\nlemma inv_inv (a : G) : a \u207b\u00b9 \u207b\u00b9 = a :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rw [mul_left_inv, mul_right_inv]\nend\n\nend group\n\nend mygroup", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/levels/level01experiment.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7293087272535425}}
{"text": "theorem and_commutative (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\nassume hpq : p \u2227 q,\nhave hp : p, from and.left hpq,\nhave hq : q, from and.right hpq,\nshow q \u2227 p, from and.intro hq hp\n ", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/01-Introduction/example-1.3-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7292845301347877}}
{"text": "/-\n# Orders\n\nGroups, rings, fields, modules etc are in the \"algebra hierarchy\".\n\nMetric and topological spaces are in the \"topology hierarchy\".\n\nThe other important hierarchy is the \"order hierarchy\".\n\nIt starts with partially ordered sets, and then goes on to lattices.\n\nBecause I like algebra, let's demonstrate the order hierarchy by\nmaking an algebraic type, namely the type of subgroups of a group G,\nand then working up the order hierarchy with it. Subgroups of a group\nare ordered by inclusion, and this is where we shall start. We will\nthen define infs and sups, and bot and top, and go on from there.\n\n-/\nimport tactic\n\n-- We will be using all of the theory of subsets of a type\n-- without further comment (e.g. `inter_subset_left A B : A \u2229 B \u2286 A`)\n-- so let's open the `set` namespace.\n\nopen set\n\n-- The type of subgroups of a group G is called `subgroup G` in Lean.\n-- It already has a lattice structure in Lean.\n\n-- So let's just redo the entire theory and call it `my_subgroup G`.\n\n/-- The type of subgroups of a group `G`. -/\nstructure my_subgroup (G : Type) [group G] :=\n-- A subgroup of G is a sub*set* of G, called `carrier`\n(carrier : set G)\n-- and then axioms saying it's closed under the group structure (i.e. *, 1, \u207b\u00b9)\n(mul_mem {a b : G} : a \u2208 carrier \u2192 b \u2208 carrier \u2192 a * b \u2208 carrier)\n(one_mem : (1 : G) \u2208 carrier)\n(inv_mem {a : G} : a \u2208 carrier \u2192 a\u207b\u00b9 \u2208 carrier)\n\nnamespace my_subgroup\n\n/-\nNote in particular that we have a function `my_subgroup.carrier : my_subgroup G \u2192 set G`,\nsending a subgroup of `G` to the underlying subset (`set G` is the type\nof subsets of G).\n-/\n\n-- Let G be a group, let H,J,K be subgroups of G, and let a,b,c be elements of G.\nvariables {G : Type} [group G] (H J K : my_subgroup G) (a b c : G)\n\n/- # Extensionality\n\nOne of the first things you should consider proving about a newly-defined\ntype is an extensionality lemma: a sensible criterion to check that\ntwo terms are equal. When are two subgroups of `G` equal? A subgroup\nis defined by four things: a subset, and three proofs. But two proofs\nof a proposition `P` are equal by definition in Lean, so two subgroups\nof `G` are equal iff their underlying subsets are equal, which is\ntrue iff their underlying subsets have the same elements. Let's give\nnames to these basic results because they'll show up everywhere.\n\nLet's start by showing that two subgroups are equal if their\nunderlying subsets are equal. This is precisely the statement that\n`\u2200 H J : my_subgroup G, H.carrier = J.carrier \u2192 H = J`, and a good name\nfor this would be `carrier_injective`. We adopt the Lean tradition\nof putting as many things to the left of the `:` as we can; it\ndoesn't change the statement of the theorem.\n-/\n\nlemma carrier_injective (H J : my_subgroup G) (h : H.carrier = J.carrier) : H = J :=\nbegin\n  -- take H and J apart\n  cases H, cases J,\n  -- and note that they are the same set, and then a bunch of proofs\n  -- which are equal by definition, so it's obvious\n  simp * at *,\nend\n\n-- Now let's prove that two subgroups are equal iff they have the same elements.\n-- This is the most useful \"extensionality lemma\" so we tag it `@[ext]`.\n@[ext] theorem ext {H J : my_subgroup G} (h : \u2200 (x : G), x \u2208 H.carrier \u2194 x \u2208 J.carrier) :\n  H = J :=\nbegin\n  -- it suffices to prove the subsets are equal\n  apply carrier_injective,\n  -- Now let's use extensionality for subsets\n  ext x,\n  exact h x,\nend\n\n-- We also want the `iff` version of this.\ntheorem ext_iff {H J : my_subgroup G} : H = J \u2194 \u2200 (x : G), x \u2208 H.carrier \u2194 x \u2208 J.carrier :=\nbegin\n  sorry\nend\n\n/-\n\n## Partial orders\n\n-/\n\n-- These are familiar to most mathematicians. We will put a partial order\n-- structure on `my_subgroup G`. In other words, we will create a term of\n-- type `partial_order (my_subgroup G)`.\n\n-- Let's define `H \u2264 J` to mean `H.carrier \u2286 J.carrier`, using the `has_le` notation typeclass\ninstance : has_le (my_subgroup G) := \u27e8\u03bb H J, H.carrier \u2286 J.carrier\u27e9\n\n-- \"tidy\" is a one-size-fits-all tactic which solves certain kinds of \"follow your nose\" goals.\ninstance : partial_order (my_subgroup G) :=\n{ le := (\u2264),\n  le_refl := by tidy,\n  le_trans := by tidy,\n  le_antisymm := by tidy }\n\n/- Here is a second proof. If X \u2192 Y is injective, and Y is partially ordered,\nthen X inherits a partial order. This construction (it's not a theorem, because\nit involves data) is called `partial_order.lift`. Applying it to the injection\n`my_subgroup.carrier` and the fact that Lean already knows that `set G` is partially\nordered, turns into this second construction,  (which I won't call an `instance`\nbecause if I did then I would have committed the sin of making two terms of\ntype `partial_order (my_subgroup G)`, and `partial_order (my_subgroup G)` is a class so\nshould have at most one instance):\n-/\n\n-- partial_order.lift is the function which pulls a partial order back along an injection.\nexample : partial_order (my_subgroup G) := partial_order.lift my_subgroup.carrier carrier_injective\n\n/- Note that we magically just inherited `<` notatation, because\n   `#check partial_order` tells you that `partial_order` extends `preorder`,\n   which extends `has_lt`, which is a notation typeclass. In other words,\n   `#check (H < J)` makes sense, and is a `Prop`. In fact `H < J` is\n  defined to mean `H \u2264 J \u2227 \u00ac (J \u2264 H)`.\n\n# From partial orders to lattices.\n\nLet's now prove that `my_subgroup G` is a `semilattice_inf_top`. This is a class\nwhich extends `partial_order` -- it is a partial order equipped with a top element,\nand a function `inf : my_subgroup G \u2192 my_subgroup G \u2192 my_subgroup G` (called \"inf\" or \"meet\"\n  or \"greatest lower bound\", satisfying some axioms. In our case, `top`\n  will be the subgroup `G` of `G` (or more precisely `univ`), and `inf` will\n  just be intersection. The work we need to do is to check that these are\n  subgroups, and to prove the axioms for a `semilattice_inf_top`, which\n  we'll come to later.\n\nFirst let's define `top` -- the biggest subgroup. The underlying carrier\nis `univ : set G`, i.e. the subset `G` of `G`. I'll leave it to you to prove\nthat the subgroup axioms hold!\n\nThe useful piece of interface for `univ` you'll need is `mem_univ g : g \u2208 univ`.\n\n-/\ndef top : my_subgroup G :=\n{ carrier := set.univ,\n  mul_mem := begin\n    sorry\n  end,\n  one_mem := begin\n    sorry\n  end,\n  inv_mem := begin\n    sorry\n  end }\n\n-- Add the `\u22a4` notation (typed with `\\top`) for this subgroup:\ninstance : has_top (my_subgroup G) := \u27e8top\u27e9\n\n-- Now `#check (\u22a4 : my_subgroup G)` works\n\n/-\n  We'll now prove the theorem that the intersection of\n  two subgroups is a subgroup. This is a *definition* in Lean,\n  indeed it is a construction which given two subgroups `H` and `K` of `G`\n  produces a third subgroup `H \u2293 K` (Lean's notation for `inf H K`).\n\n  The part of the interface for `\u2229` you'll need is that `a \u2208 B \u2229 C` is\n  definitionally equal to `a \u2208 B \u2227 a \u2208 C`, so you can use `split`\n  if you have a goal `\u22a2 a \u2208 B \u2229 C`, and you can use `cases h` if you\n  have a hypothesis `h : a \u2208 B \u2229 C`. Don't forget `mul_mem H`, `one_mem H`\n  and `inv_mem H`, the axioms for `H` if `H : my_subgroup G`.\n-/\n\n/-- \"Theorem\" : intersection of two my_subgroups is a my_subgroup -/\ndefinition inf (H K : my_subgroup G) : my_subgroup G :=\n{ carrier := H.carrier \u2229 K.carrier,\n  mul_mem := begin\n    sorry\n  end,\n  one_mem := begin\n    sorry\n  end,\n  inv_mem := begin\n    sorry\n  end }\n\n-- Add the `\u2293` notation (type with `\\inf`) for the intersection (inf) of two subgroups:\ninstance : has_inf (my_subgroup G) := \u27e8inf\u27e9\n\n-- We now check the four axioms for a semilattice_inf_top.\n-- They are called `le_top`, `inf_le_left`, `inf_le_right` and `le_inf`.\n-- You might be able to guess the statementss of the axioms\n-- from their names.\n\nlemma le_top (H : my_subgroup G) : H \u2264 \u22a4 :=\nbegin\n  sorry\nend\n\nlemma inf_le_left (H K : my_subgroup G) : H \u2293 K \u2264 H :=\nbegin\n  -- by definition this says `H.carrier \u2229 K.carrier \u2286 H.carrier`\n  change H.carrier \u2229 K.carrier \u2286 H.carrier,\n  -- now try `library_search`, to find that this is called `inter_subset_left\n  apply inter_subset_left,\nend\n\nlemma inf_le_right (H K : my_subgroup G) : H \u2293 K \u2264 K :=\nbegin\n  sorry\nend\n\n-- Can you use `library_search`, or other methods, to find the name of the\n-- statement that if `A B C : set G` then `A \u2286 B \u2192 A \u2286 C \u2192 A \u2286 (B \u2229 C)`?\nlemma le_inf (H J K : my_subgroup G) (h1 : H \u2264 J) (h2 : H \u2264 K) : H \u2264 J \u2293 K :=\nbegin\n  sorry\nend\n\n-- Now we're ready to make the instance.\ninstance : semilattice_inf_top (my_subgroup G) :=\n{ top := top,\n  le_top := le_top,\n  inf := inf,\n  inf_le_left := inf_le_left,\n  inf_le_right := inf_le_right,\n  le_inf := le_inf,\n  .. my_subgroup.partial_order } -- don't forget to inlude the partial order\n\n/- The logic behind `semilattice_inf_top` is that it is the simplest class\nwhich is closed under all finite \"meet\"s. The meet of 0 subgroups\nis `top`, the meet of one subgroup is the subgroup, the meet of two\nsubgroups is their inf, and for three or more you proceed by induction.\n\nWe could now go on to make a `semilattice_sup_bot` structure, and then\na lattice structure. But let's jump straight to the strongest type\nin the order hierarchy -- a `complete_lattice`. This has arbitrary `Inf` and `Sup`s.\n\nSo let's first note that we can do better than finite intersections -- we can take\narbitrary intersections! Let's now define the `Inf` of an arbitrary\nset of subgroups of `G`.\n\nThe part of the interface for sets you'll need to know here is that if `S` is a\nset of subsets of `G`, then `\u22c2\u2080 S` is notation for their intersection, and\nto work with it you'll need to know\n`set.mem_sInter : g \u2208 \u22c2\u2080 S \u2194 \u2200 (U : set G), U \u2208 S \u2192 g \u2208 U`.\n-/\n\ndef Inf (S : set (my_subgroup G)) : my_subgroup G :=\n{ carrier := Inf (my_subgroup.carrier '' S),\n  mul_mem :=  begin\n    sorry\n  end,\n  one_mem := begin\n    sorry\n  end,\n  inv_mem := begin\n    sorry\n  end }\n\n-- We now equip `my_subgroup G` with an Inf. I think the notation is `\u2a05`, or `\\Inf`,\n-- but I find it hard to use, and `#print notation \u2a05` returns garbage.\ninstance : has_Inf (my_subgroup G) := \u27e8Inf\u27e9\n\n/- # Complete lattices\n\nLet's jump straight from `semilattice_inf_bot` to `complete_lattice`.\nA complete lattice has arbitrary Infs and arbitrary Sups, and satisfies\nsome other axioms which you can probably imagine. Our next goal\nis to make `my_subgroup G` into a complete lattice. We will do it in two ways.\nThe first way is to show that if our `Inf` satisfies\n`(\u2200 (S : set (my_subgroup G)), is_glb S (Inf S))` then we can build a complete\nlattice from this, using `complete_lattice_of_Inf`.\n-/\n\ninstance : complete_lattice (my_subgroup G) := complete_lattice_of_Inf _ begin\n-- \u22a2 \u2200 (s : set (my_subgroup G)), is_glb s (has_Inf.Inf s)\n--  See if you can figure out what this says, and how to prove it.\n-- You might find the function `is_glb.of_image` useful.\n  sorry\nend\n\n/- Now let me show you another way to do this.\n\n# Galois connections\n\nA Galois conection is a pair of adjoint functors between two\npartially ordered sets, considered as categories whose hom sets Hom(H,J) have\nsize 1 if H \u2264 J and size 0 otherwise. In other words, a Galois\nconnection between two partial orders \u03b1 and \u03b2 is a pair of monotone functions\n`l : \u03b1 \u2192 \u03b2` and `u : \u03b2 \u2192 \u03b1` such that `\u2200 (a : \u03b1) (b : \u03b2), l a \u2264 b \u2194 a \u2264 u b`.\n\nThere is an example coming from Galois theory (between subfields and subgroups),\nand an example coming from classical algebraic geometry (between affine\nvarieties and ideals); note that in both cases you have to use the opposite\npartial order on one side to make everything covariant.\n\nThe examples we want to keep in mind here are:\n1) \u03b1 = subsets of G, \u03b2 = subgroups of G, l = \"subgroup generated by\", u = `carrier`\n2) X : Type, \u03b1 := set (set X), \u03b2 := topologies on X,\n  l = topology generated by a collection of open sets, u = the open sets regarded as subsets.\n\nAs you can imagine, there are a bunch of abstract theorems with simple proofs\nproved for Galois connections. You can see them by `#check galois_connection`,\njumping to the definition, and reading the next 150 lines of the mathlib file\nafter the definition. Examples of theorems you might recognise from contexts\nwhere you have seen this before:\n\nlemma le_u_l (a : \u03b1) : a \u2264 u (l a) := ...\n\nlemma l_u_le (b : \u03b2) : l (u b) \u2264 b := ...\n\nlemma u_l_u_eq_u : u \u2218 l \u2218 u = u := ...\n\nlemma l_u_l_eq_l : l \u2218 u \u2218 l = l := ...\n\n# Galois insertions\n\nA particularly cool kind of Galois connection is a Galois insertion, which\nis a Galois connection such that `l \u2218 u = id`. This is true for both\nthe examples we're keeping in mind (the subgroup of `G` generated\nby a subgroup is the same subgroup; the topology on `X` generated by a\ntopology is the same topology).\n\nOur new goal: let's make subgroups of a group into a complete lattice,\nusing the fact that `carrier` is part of a Galois insertion.\n\n-/\n\n\n\n-- The adjoint functor to the `carrier` functor is the `span` functor\n-- from subsets to my_subgroups. Here we will CHEAT by using `Inf` to\n-- define `span`. We could have built `span` directly with\n-- an inductive definition.\ndef span (S : set G) : my_subgroup G := Inf {H : my_subgroup G | S \u2286 H.carrier}\n\n-- Here are some theorems about it.\nlemma monotone_carrier : monotone (my_subgroup.carrier : my_subgroup G \u2192 set G) :=\nbegin\n  sorry\nend\n\nlemma monotone_span : monotone (span : set G \u2192 my_subgroup G) :=\nbegin\n  sorry\nend\n\nlemma subset_span (S : set G) : S \u2264 (span S).carrier :=\nbegin\n  sorry\nend\n\nlemma span_my_subgroup (H : my_subgroup G) : span H.carrier = H :=\nbegin\n  sorry\nend\n\n-- We have proved all the things we need to show that `span` and `carrier`\n-- form a Galois insertion, using `galois_insertion.monotone_intro`.\ndef gi_my_subgroup : galois_insertion (span : set G \u2192 my_subgroup G) (my_subgroup.carrier : my_subgroup G \u2192 set G) :=\ngalois_insertion.monotone_intro monotone_carrier monotone_span subset_span span_my_subgroup\n\n-- Note that `set G` is already a complete lattice:\nexample : complete_lattice (set G) := by apply_instance\n\n-- and now `my_subgroup G` can also be made into a complete lattice, by\n-- a theorem about Galois insertions. Again, I don't use `instance`\n-- because we already made the instance above.\n\nexample : complete_lattice (my_subgroup G) := galois_insertion.lift_complete_lattice gi_my_subgroup\n\nend my_subgroup\n\n-- Because Alex defined the topology generated by a collection of subsets\n-- yesterday, I'll show you how you can use Galois insertions to prove\n-- that if `X : Type` then the type of topological space structures on `X`\n-- is a complete lattice. We use the topology generated by a collection\n-- of subsets, which is a functor adjoint to the forgetful functor.\n\n-- We start by literally copying some stuff from Alex' talk.\n\nopen set\n\n@[ext]\nclass topological_space (X : Type) :=\n  (is_open : set X \u2192 Prop) -- why set X \u2192 Prop not set (set X)? former plays\n                           -- nicer with typeclasses later\n  (univ_mem : is_open univ)\n  (union : \u2200 (B : set (set X)) (h : \u2200 b \u2208 B, is_open b), is_open (\u22c3\u2080 B))\n  (inter : \u2200 (A B : set X) (hA : is_open A) (hB : is_open B), is_open (A \u2229 B))\n\nnamespace topological_space\n\ndef forget {X : Type} : topological_space X \u2192 set (set X) := @is_open X\n\n/-- The open sets of the least topology containing a collection of basic sets. -/\ninductive generated_open (X : Type) (g : set (set X)) : set X \u2192 Prop\n| basic  : \u2200 s \u2208 g, generated_open s\n| univ   : generated_open univ\n| inter  : \u2200s t, generated_open s \u2192 generated_open t \u2192 generated_open (s \u2229 t)\n| sUnion : \u2200k, (\u2200 s \u2208  k, generated_open s) \u2192 generated_open (\u22c3\u2080 k)\n\n/-- The smallest topological space containing the collection `g` of basic sets -/\ndef generate_from {X : Type} (g : set (set X)) : topological_space X :=\n{ is_open   := generated_open X g,\n  univ_mem  := sorry,\n  inter     := sorry,\n  union     := sorry }\n\n-- Recall that `topological_space X` is the type of topological space structures\n-- on `X`. Our Galois insertion will use the adjoint functors\n-- `generate_from` and `is_open`.\n\n-- We'd better start by giving the collection of topological space structures on X\n-- a partial order:\n\ninstance (X : Type) : partial_order (topological_space X) :=\npartial_order.lift (forget)\nbegin\n  -- need to show that a top space is determined by its open sets\n  intros \u03c4\u2081 \u03c4\u2082 h,\n  cases \u03c4\u2081, cases \u03c4\u2082,\n  simp [forget, *] at *,\nend\n\n\n-- Exercise (LONG): First, show that we have a Galois insertion.\n\nlemma monotone_is_open {X : Type} :\n  monotone (forget : topological_space X \u2192 set (set X)) :=\nbegin\n  sorry\nend\n\nlemma monotone_span {X : Type} :\n  monotone (generate_from : set (set X) \u2192 topological_space X) :=\nbegin\n  sorry\nend\n\nlemma subset_forget {X : Type} (Us : set (set X)) :\n  Us \u2264 forget (generate_from Us) :=\nbegin\n  sorry\nend\n\nlemma generate_forget {X : Type} (\u03c4 : topological_space X) :\n  generate_from (forget \u03c4) = \u03c4 :=\nbegin\n  sorry\nend\n\ndef gi_top (X : Type) :\n  galois_insertion (generate_from : set (set X) \u2192 topological_space X)\n    (forget : topological_space X \u2192 set (set X)) :=\ngalois_insertion.monotone_intro monotone_is_open monotone_span subset_forget generate_forget\n\n/-\nThen deduce that the type of topological space structures on X\nis a complete lattice, i.e. that there is a good definition of\narbitrary Infs and Sups of topological space structures on a type, and\nthey satisfy all the correct properties of Infs and Sups. In\nother words,\n-/\n\nexample (X : Type) : complete_lattice (topological_space X) :=\n  galois_insertion.lift_complete_lattice (gi_top X)\n\nend topological_space\n", "meta": {"author": "fpvandoorn", "repo": "Harvard-tutoring", "sha": "a8846c08e32cdc7b91a7e28adfa5d9b2810088b0", "save_path": "github-repos/lean/fpvandoorn-Harvard-tutoring", "path": "github-repos/lean/fpvandoorn-Harvard-tutoring/Harvard-tutoring-a8846c08e32cdc7b91a7e28adfa5d9b2810088b0/src/exercises/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7292845204368997}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\nIrrationality of real numbers.\n-/\nimport data.real.basic data.nat.prime\n\nopen real rat\n\ndef irrational (x : \u211d) := \u00ac \u2203 q : \u211a, x = q\n\ntheorem sqrt_two_irrational : irrational (sqrt 2)\n| \u27e8\u27e8n, d, h, c\u27e9, e\u27e9 := begin\n  simp [num_denom', mk_eq_div] at e,\n  have := mul_self_sqrt (le_of_lt two_pos),\n  have d0 : (0:\u211d) < d := nat.cast_pos.2 h,\n  rw [e, div_mul_div, div_eq_iff_mul_eq (ne_of_gt $ mul_pos d0 d0),\n      \u2190 int.cast_mul, \u2190 int.nat_abs_mul_self] at this,\n  revert c this, generalize : n.nat_abs = a, intros,\n  have E : 2 * (d * d) = a * a := (@nat.cast_inj \u211d _ _ _ _ _).1 (by simpa),\n  have ae : 2 \u2223 a,\n  { refine (or_self _).1 (nat.prime_two.dvd_mul.1 _),\n    rw \u2190 E, apply dvd_mul_right },\n  have de : 2 \u2223 d,\n  { have := mul_dvd_mul ae ae,\n    refine (or_self _).1 (nat.prime_two.dvd_mul.1 _),\n    rwa [\u2190 E, nat.mul_dvd_mul_iff_left (nat.succ_pos 1)] at this },\n  exact nat.not_coprime_of_dvd_of_dvd (nat.lt_succ_self _) ae de c\nend\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/real/irrational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.72928451509975}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport field_theory.finite.basic\n\n/-!\n# The Chevalley\u2013Warning theorem\n\nThis file contains a proof of the Chevalley\u2013Warning theorem.\nThroughout most of this file, `K` denotes a finite field\nand `q` is notation for the cardinality of `K`.\n\n## Main results\n\n1. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : \u03c3`)\n   such that the total degree of `f` is less than `(q-1)` times the cardinality of `\u03c3`.\n   Then the evaluation of `f` on all points of `\u03c3 \u2192 K` (aka `K^\u03c3`) sums to `0`.\n   (`sum_mv_polynomial_eq_zero`)\n2. The Chevalley\u2013Warning theorem (`char_dvd_card_solutions`).\n   Let `f i` be a finite family of multivariate polynomials\n   in finitely many variables (`X s`, `s : \u03c3`) such that\n   the sum of the total degrees of the `f i` is less than the cardinality of `\u03c3`.\n   Then the number of common solutions of the `f i`\n   is divisible by the characteristic of `K`.\n\n## Notation\n\n- `K` is a finite field\n- `q` is notation for the cardinality of `K`\n- `\u03c3` is the indexing type for the variables of a multivariate polynomial ring over `K`\n\n-/\n\nuniverses u v\n\nopen_locale big_operators\n\nsection finite_field\nopen mv_polynomial function (hiding eval) finset finite_field\n\nvariables {K : Type*} {\u03c3 : Type*} [fintype K] [field K] [fintype \u03c3]\nlocal notation `q` := fintype.card K\n\nlemma mv_polynomial.sum_mv_polynomial_eq_zero [decidable_eq \u03c3] (f : mv_polynomial \u03c3 K)\n  (h : f.total_degree < (q - 1) * fintype.card \u03c3) :\n  (\u2211 x, eval x f) = 0 :=\nbegin\n  haveI : decidable_eq K := classical.dec_eq K,\n  calc (\u2211 x, eval x f)\n        = \u2211 x : \u03c3 \u2192 K, \u2211 d in f.support, f.coeff d * \u220f i, x i ^ d i : by simp only [eval_eq']\n    ... = \u2211 d in f.support, \u2211 x : \u03c3 \u2192 K, f.coeff d * \u220f i, x i ^ d i : sum_comm\n    ... = 0 : sum_eq_zero _,\n  intros d hd,\n  obtain \u27e8i, hi\u27e9 : \u2203 i, d i < q - 1, from f.exists_degree_lt (q - 1) h hd,\n  calc (\u2211 x : \u03c3 \u2192 K, f.coeff d * \u220f i, x i ^ d i)\n        = f.coeff d * (\u2211 x : \u03c3 \u2192 K, \u220f i, x i ^ d i) : mul_sum.symm\n    ... = 0                                         : (mul_eq_zero.mpr \u2218 or.inr) _,\n  calc (\u2211 x : \u03c3 \u2192 K, \u220f i, x i ^ d i)\n        = \u2211 (x\u2080 : {j // j \u2260 i} \u2192 K) (x : {x : \u03c3 \u2192 K // x \u2218 coe = x\u2080}), \u220f j, (x : \u03c3 \u2192 K) j ^ d j :\n              (fintype.sum_fiberwise _ _).symm\n    ... = 0 : fintype.sum_eq_zero _ _,\n  intros x\u2080,\n  let e : K \u2243 {x // x \u2218 coe = x\u2080} := (equiv.subtype_equiv_codomain _).symm,\n  calc (\u2211 x : {x : \u03c3 \u2192 K // x \u2218 coe = x\u2080}, \u220f j, (x : \u03c3 \u2192 K) j ^ d j)\n        = \u2211 a : K, \u220f j : \u03c3, (e a : \u03c3 \u2192 K) j ^ d j : (e.sum_comp _).symm\n    ... = \u2211 a : K, (\u220f j, x\u2080 j ^ d j) * a ^ d i    : fintype.sum_congr _ _ _\n    ... = (\u220f j, x\u2080 j ^ d j) * \u2211 a : K, a ^ d i    : by rw mul_sum\n    ... = 0                                       : by rw [sum_pow_lt_card_sub_one _ hi, mul_zero],\n  intros a,\n  let e' : {j // j = i} \u2295 {j // j \u2260 i} \u2243 \u03c3 := equiv.sum_compl _,\n  letI : unique {j // j = i} :=\n  { default := \u27e8i, rfl\u27e9, uniq := \u03bb \u27e8j, h\u27e9, subtype.val_injective h },\n  calc (\u220f j : \u03c3, (e a : \u03c3 \u2192 K) j ^ d j)\n        = (e a : \u03c3 \u2192 K) i ^ d i * (\u220f (j : {j // j \u2260 i}), (e a : \u03c3 \u2192 K) j ^ d j) :\n        by { rw [\u2190 e'.prod_comp, fintype.prod_sum_type, univ_unique, prod_singleton], refl }\n    ... = a ^ d i * (\u220f (j : {j // j \u2260 i}), (e a : \u03c3 \u2192 K) j ^ d j) :\n        by rw equiv.subtype_equiv_codomain_symm_apply_eq\n    ... = a ^ d i * (\u220f j, x\u2080 j ^ d j) : congr_arg _ (fintype.prod_congr _ _ _) -- see below\n    ... = (\u220f j, x\u2080 j ^ d j) * a ^ d i : mul_comm _ _,\n  { -- the remaining step of the calculation above\n    rintros \u27e8j, hj\u27e9,\n    show (e a : \u03c3 \u2192 K) j ^ d j = x\u2080 \u27e8j, hj\u27e9 ^ d j,\n    rw equiv.subtype_equiv_codomain_symm_apply_ne, }\nend\n\nvariables [decidable_eq K] [decidable_eq \u03c3]\n\n/-- The Chevalley\u2013Warning theorem.\nLet `(f i)` be a finite family of multivariate polynomials\nin finitely many variables (`X s`, `s : \u03c3`) over a finite field of characteristic `p`.\nAssume that the sum of the total degrees of the `f i` is less than the cardinality of `\u03c3`.\nThen the number of common solutions of the `f i` is divisible by `p`. -/\ntheorem char_dvd_card_solutions_family (p : \u2115) [char_p K p]\n  {\u03b9 : Type*} {s : finset \u03b9} {f : \u03b9 \u2192 mv_polynomial \u03c3 K}\n  (h : (\u2211 i in s, (f i).total_degree) < fintype.card \u03c3) :\n  p \u2223 fintype.card {x : \u03c3 \u2192 K // \u2200 i \u2208 s, eval x (f i) = 0} :=\nbegin\n  have hq : 0 < q - 1, { rw [\u2190 fintype.card_units, fintype.card_pos_iff], exact \u27e81\u27e9 },\n  let S : finset (\u03c3 \u2192 K) := { x \u2208 univ | \u2200 i \u2208 s, eval x (f i) = 0 },\n  have hS : \u2200 (x : \u03c3 \u2192 K), x \u2208 S \u2194 \u2200 (i : \u03b9), i \u2208 s \u2192 eval x (f i) = 0,\n  { intros x, simp only [S, true_and, sep_def, mem_filter, mem_univ], },\n  /- The polynomial `F = \u220f i in s, (1 - (f i)^(q - 1))` has the nice property\n  that it takes the value `1` on elements of `{x : \u03c3 \u2192 K // \u2200 i \u2208 s, (f i).eval x = 0}`\n  while it is `0` outside that locus.\n  Hence the sum of its values is equal to the cardinality of\n  `{x : \u03c3 \u2192 K // \u2200 i \u2208 s, (f i).eval x = 0}` modulo `p`. -/\n  let F : mv_polynomial \u03c3 K := \u220f i in s, (1 - (f i)^(q - 1)),\n  have hF : \u2200 x, eval x F = if x \u2208 S then 1 else 0,\n  { intro x,\n    calc eval x F = \u220f i in s, eval x (1 - f i ^ (q - 1)) : eval_prod s _ x\n              ... = if x \u2208 S then 1 else 0 : _,\n    simp only [(eval x).map_sub, (eval x).map_pow, (eval x).map_one],\n    split_ifs with hx hx,\n    { apply finset.prod_eq_one,\n      intros i hi,\n      rw hS at hx,\n      rw [hx i hi, zero_pow hq, sub_zero], },\n    { obtain \u27e8i, hi, hx\u27e9 : \u2203 (i : \u03b9), i \u2208 s \u2227 eval x (f i) \u2260 0,\n      { simpa only [hS, not_forall, not_imp] using hx },\n      apply finset.prod_eq_zero hi,\n      rw [pow_card_sub_one_eq_one (eval x (f i)) hx, sub_self], } },\n  -- In particular, we can now show:\n  have key : \u2211 x, eval x F = fintype.card {x : \u03c3 \u2192 K // \u2200 i \u2208 s, eval x (f i) = 0},\n  rw [fintype.card_of_subtype S hS, card_eq_sum_ones, nat.cast_sum, nat.cast_one,\n      \u2190 fintype.sum_extend_by_zero S, sum_congr rfl (\u03bb x hx, hF x)],\n  -- With these preparations under our belt, we will approach the main goal.\n  show p \u2223 fintype.card {x // \u2200 (i : \u03b9), i \u2208 s \u2192 eval x (f i) = 0},\n  rw [\u2190 char_p.cast_eq_zero_iff K, \u2190 key],\n  show \u2211 x, eval x F = 0,\n  -- We are now ready to apply the main machine, proven before.\n  apply F.sum_mv_polynomial_eq_zero,\n  -- It remains to verify the crucial assumption of this machine\n  show F.total_degree < (q - 1) * fintype.card \u03c3,\n  calc F.total_degree \u2264 \u2211 i in s, (1 - (f i)^(q - 1)).total_degree : total_degree_finset_prod s _\n                  ... \u2264 \u2211 i in s, (q - 1) * (f i).total_degree     : sum_le_sum $ \u03bb i hi, _ -- see \u2193\n                  ... = (q - 1) * (\u2211 i in s, (f i).total_degree)   : mul_sum.symm\n                  ... < (q - 1) * (fintype.card \u03c3)                 : by rwa mul_lt_mul_left hq,\n  -- Now we prove the remaining step from the preceding calculation\n  show (1 - f i ^ (q - 1)).total_degree \u2264 (q - 1) * (f i).total_degree,\n  calc (1 - f i ^ (q - 1)).total_degree\n        \u2264 max (1 : mv_polynomial \u03c3 K).total_degree (f i ^ (q - 1)).total_degree :\n        total_degree_sub _ _\n    ... \u2264 (f i ^ (q - 1)).total_degree : by simp only [max_eq_right, nat.zero_le, total_degree_one]\n    ... \u2264 (q - 1) * (f i).total_degree : total_degree_pow _ _\nend\n\n/-- The Chevalley\u2013Warning theorem.\nLet `f` be a multivariate polynomial in finitely many variables (`X s`, `s : \u03c3`)\nover a finite field of characteristic `p`.\nAssume that the total degree of `f` is less than the cardinality of `\u03c3`.\nThen the number of solutions of `f` is divisible by `p`.\nSee `char_dvd_card_solutions_family` for a version that takes a family of polynomials `f i`. -/\ntheorem char_dvd_card_solutions (p : \u2115) [char_p K p]\n  {f : mv_polynomial \u03c3 K} (h : f.total_degree < fintype.card \u03c3) :\n  p \u2223 fintype.card {x : \u03c3 \u2192 K // eval x f = 0} :=\nbegin\n  let F : unit \u2192 mv_polynomial \u03c3 K := \u03bb _, f,\n  have : \u2211 i : unit, (F i).total_degree < fintype.card \u03c3,\n  { simpa only [fintype.univ_punit, sum_singleton] using h, },\n  have key := char_dvd_card_solutions_family p this,\n  simp only [F, fintype.univ_punit, forall_eq, mem_singleton] at key,\n  convert key,\nend\n\nend finite_field\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/field_theory/chevalley_warning.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7292845135405188}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n-/\nimport data.real.sqrt\n\n/-!\n# The complex numbers\n\nThe complex numbers are modelled as \u211d^2 in the obvious way and it is shown that they form a field\nof characteristic zero. The result that the complex numbers are algebraically closed, see\n`field_theory.algebraic_closure`.\n-/\n\nopen_locale big_operators\n\n/-! ### Definition and basic arithmmetic -/\n\n/-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\nnoncomputable instance : decidable_eq \u2102 := classical.dec_eq _\n\n/-- The equivalence between the complex numbers and `\u211d \u00d7 \u211d`. -/\ndef equiv_real_prod : \u2102 \u2243 (\u211d \u00d7 \u211d) :=\n{ to_fun := \u03bb z, \u27e8z.re, z.im\u27e9,\n  inv_fun := \u03bb p, \u27e8p.1, p.2\u27e9,\n  left_inv := \u03bb \u27e8x, y\u27e9, rfl,\n  right_inv := \u03bb \u27e8x, y\u27e9, rfl }\n\n@[simp] theorem equiv_real_prod_apply (z : \u2102) : equiv_real_prod z = (z.re, z.im) := rfl\ntheorem equiv_real_prod_symm_re (x y : \u211d) : (equiv_real_prod.symm (x, y)).re = x := rfl\ntheorem equiv_real_prod_symm_im (x y : \u211d) : (equiv_real_prod.symm (x, y)).im = y := rfl\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8a, b\u27e9 := rfl\n\n@[ext]\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\ninstance : has_coe \u211d \u2102 := \u27e8\u03bb r, \u27e8r, 0\u27e9\u27e9\n\n@[simp, norm_cast] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\nlemma of_real_def (r : \u211d) : (r : \u2102) = \u27e8r, 0\u27e9 := rfl\n\n@[simp, norm_cast] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\ninstance : has_zero \u2102 := \u27e8(0 : \u211d)\u27e9\ninstance : inhabited \u2102 := \u27e80\u27e9\n\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\ninstance : has_one \u2102 := \u27e8(1 : \u211d)\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n\n@[simp] lemma bit0_re (z : \u2102) : (bit0 z).re = bit0 z.re := rfl\n@[simp] lemma bit1_re (z : \u2102) : (bit1 z).re = bit1 z.re := rfl\n@[simp] lemma bit0_im (z : \u2102) : (bit0 z).im = bit0 z.im := eq.refl _\n@[simp] lemma bit1_im (z : \u2102) : (bit1 z).im = bit0 z.im := add_zero _\n\n@[simp, norm_cast] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s :=\next_iff.2 $ by simp\n\n@[simp, norm_cast] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r :=\next_iff.2 $ by simp [bit0]\n\n@[simp, norm_cast] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r :=\next_iff.2 $ by simp [bit1]\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n@[simp, norm_cast] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\ninstance : has_sub \u2102 := \u27e8\u03bb z w, \u27e8z.re - w.re, z.im - w.im\u27e9\u27e9\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp, norm_cast] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\nlemma of_real_mul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp\nlemma of_real_mul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp\nlemma of_real_mul' (r : \u211d) (z : \u2102) : (\u2191r * z) = \u27e8r * z.re, r * z.im\u27e9 :=\next (of_real_mul_re _ _) (of_real_mul_im _ _)\n\n/-! ### The imaginary unit, `I` -/\n\n/-- The imaginary unit. -/\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := rfl\n@[simp] lemma I_im : I.im = 1 := rfl\n\n@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp\nlemma I_mul (z : \u2102) : I * z = \u27e8-z.im, z.re\u27e9 :=\next_iff.2 $ by simp\n\nlemma I_ne_zero : (I : \u2102) \u2260 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\next_iff.2 $ by simp\n\n/-! ### Commutative ring instance and lemmas -/\n\ninstance : comm_ring \u2102 :=\nby refine_struct { zero := (0 : \u2102), add := (+), neg := has_neg.neg, sub := has_sub.sub, one := 1,\n  mul := (*), nsmul := @nsmul_rec _ \u27e8(0)\u27e9 \u27e8(+)\u27e9, npow := @npow_rec _ \u27e8(1)\u27e9 \u27e8(*)\u27e9,\n  gsmul := @gsmul_rec _ \u27e8(0)\u27e9 \u27e8(+)\u27e9 \u27e8has_neg.neg\u27e9 };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\ninstance re.is_add_group_hom : is_add_group_hom complex.re :=\n{ map_add := complex.add_re }\n\ninstance im.is_add_group_hom : is_add_group_hom complex.im :=\n{ map_add := complex.add_im }\n\n@[simp] lemma I_pow_bit0 (n : \u2115) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [pow_bit0', I_mul_I]\n\n@[simp] lemma I_pow_bit1 (n : \u2115) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [pow_bit1', I_mul_I]\n\n/-! ### Complex conjugation -/\n\n/-- The complex conjugate. -/\ndef conj : \u2102 \u2192+* \u2102 :=\nbegin\n  refine_struct { to_fun := \u03bb z : \u2102, (\u27e8z.re, -z.im\u27e9 : \u2102), .. };\n  { intros, ext; simp [add_comm], },\nend\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := rfl\n\n@[simp] lemma conj_of_real (r : \u211d) : conj r = r := ext_iff.2 $ by simp [conj]\n\n@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp\n\n@[simp] lemma conj_bit0 (z : \u2102) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]\n@[simp] lemma conj_bit1 (z : \u2102) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0]\n\n@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp\n\n@[simp] lemma conj_conj (z : \u2102) : conj (conj z) = z :=\next_iff.2 $ by simp\n\nlemma conj_involutive : function.involutive conj := conj_conj\n\nlemma conj_bijective : function.bijective conj := conj_involutive.bijective\n\nlemma conj_inj {z w : \u2102} : conj z = conj w \u2194 z = w :=\nconj_bijective.1.eq_iff\n\n@[simp] lemma conj_eq_zero {z : \u2102} : conj z = 0 \u2194 z = 0 :=\nby simpa using @conj_inj z 0\n\nlemma eq_conj_iff_real {z : \u2102} : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n\u27e8\u03bb h, \u27e8z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)\u27e9,\n \u03bb \u27e8h, e\u27e9, by rw [e, conj_of_real]\u27e9\n\nlemma eq_conj_iff_re {z : \u2102} : conj z = z \u2194 (z.re : \u2102) = z :=\neq_conj_iff_real.trans \u27e8by rintro \u27e8r, rfl\u27e9; simp, \u03bb h, \u27e8_, h.symm\u27e9\u27e9\n\nlemma eq_conj_iff_im {z : \u2102} : conj z = z \u2194 z.im = 0 :=\n\u27e8\u03bb h, add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)),\n  \u03bb h, ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))\u27e9\n\ninstance : star_ring \u2102 :=\n{ star := \u03bb z, conj z,\n  star_involutive := \u03bb z, by simp,\n  star_mul := \u03bb r s, by { ext; simp [mul_comm], },\n  star_add := by simp, }\n\n/-! ### Norm squared -/\n\n/-- The norm squared function. -/\n@[pp_nodot] def norm_sq : monoid_with_zero_hom \u2102 \u211d :=\n{ to_fun := \u03bb z, z.re * z.re + z.im * z.im,\n  map_zero' := by simp,\n  map_one' := by simp,\n  map_mul' := \u03bb z w, by { dsimp, ring } }\n\nlemma norm_sq_apply (z : \u2102) : norm_sq z = z.re * z.re + z.im * z.im := rfl\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nby simp [norm_sq]\n\nlemma norm_sq_eq_conj_mul_self {z : \u2102} : (norm_sq z : \u2102) = conj z * z :=\nby { ext; simp [norm_sq, mul_comm], }\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := norm_sq.map_zero\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := norm_sq.map_one\n@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\nlemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\n\u27e8\u03bb h, ext\n  (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n  (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),\n \u03bb h, h.symm \u25b8 norm_sq_zero\u27e9\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\n(norm_sq_nonneg z).lt_iff_ne.trans $ not_congr (eq_comm.trans norm_sq_eq_zero)\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\nlemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nnorm_sq.map_mul z w\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nby dsimp [norm_sq]; ring\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\next_iff.2 $ by simp [two_mul]\n\n/-- The coercion `\u211d \u2192 \u2102` as a `ring_hom`. -/\ndef of_real : \u211d \u2192+* \u2102 := \u27e8coe, of_real_one, of_real_mul, of_real_zero, of_real_add\u27e9\n\n@[simp] lemma of_real_eq_coe (r : \u211d) : of_real r = r := rfl\n\n@[simp] lemma I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]\n\n@[simp] lemma sub_re (z w : \u2102) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : \u2102) : (z - w).im = z.im - w.im := rfl\n@[simp, norm_cast] lemma of_real_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s := ext_iff.2 $ by simp\n@[simp, norm_cast] lemma of_real_pow (r : \u211d) (n : \u2115) : ((r ^ n : \u211d) : \u2102) = r ^ n :=\nby induction n; simp [*, of_real_mul, pow_succ]\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\next_iff.2 $ by simp [two_mul, sub_eq_add_neg]\n\nlemma norm_sq_sub (z w : \u2102) : norm_sq (z - w) =\n  norm_sq z + norm_sq w - 2 * (z * conj w).re :=\nby rw [sub_eq_add_neg, norm_sq_add]; simp [-mul_re, add_comm, add_left_comm, sub_eq_add_neg]\n\n/-! ### Inversion -/\n\nnoncomputable instance : has_inv \u2102 := \u27e8\u03bb z, conj z * ((norm_sq z)\u207b\u00b9:\u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((norm_sq z)\u207b\u00b9:\u211d) := rfl\n@[simp] lemma inv_re (z : \u2102) : (z\u207b\u00b9).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : \u2102) : (z\u207b\u00b9).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\n@[simp, norm_cast] lemma of_real_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = r\u207b\u00b9 :=\next_iff.2 $ by simp\n\nprotected \n\nprotected theorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nby rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 of_real_mul,\n  mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]\n\n/-! ### Field instance and lemmas -/\n\nnoncomputable instance : field \u2102 :=\n{ inv := has_inv.inv,\n  exists_pair_ne := \u27e80, 1, mt (congr_arg re) zero_ne_one\u27e9,\n  mul_inv_cancel := @complex.mul_inv_cancel,\n  inv_zero := complex.inv_zero,\n  ..complex.comm_ring }\n\n@[simp] lemma I_fpow_bit0 (n : \u2124) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [fpow_bit0', I_mul_I]\n\n@[simp] lemma I_fpow_bit1 (n : \u2124) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [fpow_bit1', I_mul_I]\n\nlemma div_re (z w : \u2102) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]\nlemma div_im (z w : \u2102) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]\n\n@[simp, norm_cast] lemma of_real_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\nof_real.map_div r s\n\n@[simp, norm_cast] lemma of_real_fpow (r : \u211d) (n : \u2124) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n :=\nof_real.map_fpow r n\n\n@[simp] lemma div_I (z : \u2102) : z / I = -(z * I) :=\n(div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc]\n\n@[simp] lemma inv_I : I\u207b\u00b9 = -I :=\nby simp [inv_eq_one_div]\n\n@[simp] lemma norm_sq_inv (z : \u2102) : norm_sq z\u207b\u00b9 = (norm_sq z)\u207b\u00b9 :=\nnorm_sq.map_inv' z\n\n@[simp] lemma norm_sq_div (z w : \u2102) : norm_sq (z / w) = norm_sq z / norm_sq w :=\nnorm_sq.map_div z w\n\n/-! ### Cast lemmas -/\n\n@[simp, norm_cast] theorem of_real_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\nof_real.map_nat_cast n\n\n@[simp, norm_cast] lemma nat_cast_re (n : \u2115) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_nat_cast, of_real_re]\n\n@[simp, norm_cast] lemma nat_cast_im (n : \u2115) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_nat_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_int_cast (n : \u2124) : ((n : \u211d) : \u2102) = n :=\nof_real.map_int_cast n\n\n@[simp, norm_cast] lemma int_cast_re (n : \u2124) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_int_cast, of_real_re]\n\n@[simp, norm_cast] lemma int_cast_im (n : \u2124) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_int_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_rat_cast (n : \u211a) : ((n : \u211d) : \u2102) = n :=\nof_real.map_rat_cast n\n\n@[simp, norm_cast] lemma rat_cast_re (q : \u211a) : (q : \u2102).re = q :=\nby rw [\u2190 of_real_rat_cast, of_real_re]\n\n@[simp, norm_cast] lemma rat_cast_im (q : \u211a) : (q : \u2102).im = 0 :=\nby rw [\u2190 of_real_rat_cast, of_real_im]\n\n/-! ### Characteristic zero -/\n\ninstance char_zero_complex : char_zero \u2102 :=\nchar_zero_of_inj_zero $ \u03bb n h,\nby rwa [\u2190 of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h\n\n/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 :=\nby simp only [add_conj, of_real_mul, of_real_one, of_real_bit0,\n     mul_div_cancel_left (z.re:\u2102) two_ne_zero']\n\n/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/\ntheorem im_eq_sub_conj (z : \u2102) : (z.im : \u2102) = (z - conj(z))/(2 * I) :=\nby simp only [sub_conj, of_real_mul, of_real_one, of_real_bit0, mul_right_comm,\n     mul_div_cancel_left _ (mul_ne_zero two_ne_zero' I_ne_zero : 2 * I \u2260 0)]\n\n/-! ### Absolute value -/\n\n/-- The complex absolute value function, defined as the square root of the norm squared. -/\n@[pp_nodot] noncomputable def abs (z : \u2102) : \u211d := (norm_sq z).sqrt\n\nlocal notation `abs'` := _root_.abs\n\n@[simp, norm_cast] lemma abs_of_real (r : \u211d) : abs r = abs' r :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\nlemma abs_of_nat (n : \u2115) : complex.abs n = n :=\ncalc complex.abs n = complex.abs (n:\u211d) : by rw [of_real_nat_cast]\n  ... = _ : abs_of_nonneg (nat.cast_nonneg n)\n\nlemma mul_self_abs (z : \u2102) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]\n@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]\n@[simp] lemma abs_I : abs I = 1 := by simp [abs]\n\n@[simp] lemma abs_two : abs 2 = 2 :=\ncalc abs 2 = abs (2 : \u211d) : by rw [of_real_bit0, of_real_one]\n... = (2 : \u211d) : abs_of_nonneg (by norm_num)\n\nlemma abs_nonneg (z : \u2102) : 0 \u2264 abs z :=\nreal.sqrt_nonneg _\n\n@[simp] lemma abs_eq_zero {z : \u2102} : abs z = 0 \u2194 z = 0 :=\n(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero\n\nlemma abs_ne_zero {z : \u2102} : abs z \u2260 0 \u2194 z \u2260 0 :=\nnot_congr abs_eq_zero\n\n@[simp] lemma abs_conj (z : \u2102) : abs (conj z) = abs z :=\nby simp [abs]\n\n@[simp] lemma abs_mul (z w : \u2102) : abs (z * w) = abs z * abs w :=\nby rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl\n\nlemma abs_re_le_abs (z : \u2102) : abs' z.re \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply re_sq_le_norm_sq\n\nlemma abs_im_le_abs (z : \u2102) : abs' z.im \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply im_sq_le_norm_sq\n\nlemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : \u2102) : z.im \u2264 abs z :=\n(abs_le.1 (abs_im_le_abs _)).2\n\nlemma abs_add (z w : \u2102) : abs (z + w) \u2264 abs z + abs w :=\n(mul_self_le_mul_self_iff (abs_nonneg _)\n  (add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $\nbegin\n  rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,\n      add_right_comm, norm_sq_add, add_le_add_iff_left,\n      mul_assoc, mul_le_mul_left (@zero_lt_two \u211d _ _)],\n  simpa [-mul_re] using re_le_abs (z * conj w)\nend\n\ninstance : is_absolute_value abs :=\n{ abv_nonneg  := abs_nonneg,\n  abv_eq_zero := \u03bb _, abs_eq_zero,\n  abv_add     := abs_add,\n  abv_mul     := abs_mul }\nopen is_absolute_value\n\n@[simp] lemma abs_abs (z : \u2102) : abs' (abs z) = abs z :=\n_root_.abs_of_nonneg (abs_nonneg _)\n\n@[simp] lemma abs_pos {z : \u2102} : 0 < abs z \u2194 z \u2260 0 := abv_pos abs\n@[simp] lemma abs_neg : \u2200 z, abs (-z) = abs z := abv_neg abs\nlemma abs_sub : \u2200 z w, abs (z - w) = abs (w - z) := abv_sub abs\nlemma abs_sub_le : \u2200 a b c, abs (a - c) \u2264 abs (a - b) + abs (b - c) := abv_sub_le abs\n@[simp] theorem abs_inv : \u2200 z, abs z\u207b\u00b9 = (abs z)\u207b\u00b9 := abv_inv abs\n@[simp] theorem abs_div : \u2200 z w, abs (z / w) = abs z / abs w := abv_div abs\n\nlemma abs_abs_sub_le_abs_sub : \u2200 z w, abs' (abs z - abs w) \u2264 abs (z - w) :=\nabs_abv_sub_le_abv_sub abs\n\nlemma abs_le_abs_re_add_abs_im (z : \u2102) : abs z \u2264 abs' z.re + abs' z.im :=\nby simpa [re_add_im] using abs_add z.re (z.im * I)\n\nlemma abs_re_div_abs_le_one (z : \u2102) : abs' (z.re / z.abs) \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }\n\nlemma abs_im_div_abs_le_one (z : \u2102) : abs' (z.im / z.abs) \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }\n\n@[simp, norm_cast] lemma abs_cast_nat (n : \u2115) : abs (n : \u2102) = n :=\nby rw [\u2190 of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]\n\n@[simp, norm_cast] lemma int_cast_abs (n : \u2124) : \u2191(abs' n) = abs n :=\nby rw [\u2190 of_real_int_cast, abs_of_real, int.cast_abs]\n\nlemma norm_sq_eq_abs (x : \u2102) : norm_sq x = abs x ^ 2 :=\nby rw [abs, sq, real.mul_self_sqrt (norm_sq_nonneg _)]\n\n/--\nWe put a partial order on \u2102 so that `z \u2264 w` exactly if `w - z` is real and nonnegative.\nComplex numbers with different imaginary parts are incomparable.\n-/\ndef complex_order : partial_order \u2102 :=\n{ le := \u03bb z w, \u2203 x : \u211d, 0 \u2264 x \u2227 w = z + x,\n  le_refl := \u03bb x, \u27e80, by simp\u27e9,\n  le_trans := \u03bb x y z h\u2081 h\u2082,\n  begin\n    obtain \u27e8w\u2081, l\u2081, rfl\u27e9 := h\u2081,\n    obtain \u27e8w\u2082, l\u2082, rfl\u27e9 := h\u2082,\n    refine \u27e8w\u2081 + w\u2082, _, _\u27e9,\n    { linarith, },\n    { simp [add_assoc], },\n  end,\n  le_antisymm := \u03bb z w h\u2081 h\u2082,\n  begin\n    obtain \u27e8w\u2081, l\u2081, rfl\u27e9 := h\u2081,\n    obtain \u27e8w\u2082, l\u2082, e\u27e9 := h\u2082,\n    have h\u2083 : w\u2081 + w\u2082 = 0,\n    { symmetry,\n      rw add_assoc at e,\n      apply of_real_inj.mp,\n      apply add_left_cancel,\n      convert e; simp, },\n    have h\u2084 : w\u2081 = 0, linarith,\n    simp [h\u2084],\n  end, }\n\nlocalized \"attribute [instance] complex_order\" in complex_order\n\nsection complex_order\nopen_locale complex_order\n\nlemma le_def {z w : \u2102} : z \u2264 w \u2194 \u2203 x : \u211d, 0 \u2264 x \u2227 w = z + x := iff.refl _\nlemma lt_def {z w : \u2102} : z < w \u2194 \u2203 x : \u211d, 0 < x \u2227 w = z + x :=\nbegin\n  rw [lt_iff_le_not_le],\n  fsplit,\n  { rintro \u27e8\u27e8x, l, rfl\u27e9, h\u27e9,\n    by_cases hx : x = 0,\n    { simp [hx] at h, exfalso, exact h (le_refl _), },\n    { replace l : 0 < x := l.lt_of_ne (ne.symm hx),\n      exact \u27e8x, l, rfl\u27e9, } },\n  { rintro \u27e8x, l, rfl\u27e9,\n    fsplit,\n    { exact \u27e8x, l.le, rfl\u27e9, },\n    { rintro \u27e8x', l', e\u27e9,\n      rw [add_assoc] at e,\n      replace e := add_left_cancel (by { convert e, simp }),\n      norm_cast at e,\n      linarith, } }\nend\n\n@[simp, norm_cast] lemma real_le_real {x y : \u211d} : (x : \u2102) \u2264 (y : \u2102) \u2194 x \u2264 y :=\nbegin\n  rw [le_def],\n  fsplit,\n  { rintro \u27e8r, l, e\u27e9,\n    norm_cast at e,\n    subst e,\n    exact le_add_of_nonneg_right l, },\n  { intro h,\n    exact \u27e8y - x, sub_nonneg.mpr h, (by simp)\u27e9, },\nend\n@[simp, norm_cast] lemma real_lt_real {x y : \u211d} : (x : \u2102) < (y : \u2102) \u2194 x < y :=\nbegin\n  rw [lt_def],\n  fsplit,\n  { rintro \u27e8r, l, e\u27e9,\n    norm_cast at e,\n    subst e,\n    exact lt_add_of_pos_right x l, },\n  { intro h,\n    exact \u27e8y - x, sub_pos.mpr h, (by simp)\u27e9, },\nend\n@[simp, norm_cast] lemma zero_le_real {x : \u211d} : (0 : \u2102) \u2264 (x : \u2102) \u2194 0 \u2264 x := real_le_real\n@[simp, norm_cast] lemma zero_lt_real {x : \u211d} : (0 : \u2102) < (x : \u2102) \u2194 0 < x := real_lt_real\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is an ordered ring.\n-/\ndef complex_ordered_comm_ring : ordered_comm_ring \u2102 :=\n{ zero_le_one := \u27e81, zero_le_one, by simp\u27e9,\n  add_le_add_left := \u03bb w z h y,\n  begin\n    obtain \u27e8x, l, rfl\u27e9 := h,\n    exact \u27e8x, l, by simp [add_assoc]\u27e9,\n  end,\n  mul_pos := \u03bb z w hz hw,\n  begin\n    obtain \u27e8zx, lz, rfl\u27e9 := lt_def.mp hz,\n    obtain \u27e8wx, lw, rfl\u27e9 := lt_def.mp hw,\n    norm_cast,\n    simp only [mul_pos, lz, lw, zero_add],\n  end,\n  le_of_add_le_add_left := \u03bb u v z h,\n  begin\n    obtain \u27e8x, l, e\u27e9 := h,\n    rw add_assoc at e,\n    exact \u27e8x, l, add_left_cancel e\u27e9,\n  end,\n  mul_lt_mul_of_pos_left := \u03bb u v z h\u2081 h\u2082,\n  begin\n    obtain \u27e8x\u2081, l\u2081, rfl\u27e9 := lt_def.mp h\u2081,\n    obtain \u27e8x\u2082, l\u2082, rfl\u27e9 := lt_def.mp h\u2082,\n    simp only [mul_add, zero_add],\n    exact lt_def.mpr \u27e8x\u2082 * x\u2081, mul_pos l\u2082 l\u2081, (by norm_cast)\u27e9,\n  end,\n  mul_lt_mul_of_pos_right := \u03bb u v z h\u2081 h\u2082,\n  begin\n    obtain \u27e8x\u2081, l\u2081, rfl\u27e9 := lt_def.mp h\u2081,\n    obtain \u27e8x\u2082, l\u2082, rfl\u27e9 := lt_def.mp h\u2082,\n    simp only [add_mul, zero_add],\n    exact lt_def.mpr \u27e8x\u2081 * x\u2082, mul_pos l\u2081 l\u2082, (by norm_cast)\u27e9,\n  end,\n-- we need more instances here because comm_ring doesn't have zero_add et al as fields,\n-- they are derived as lemmas\n  ..(by apply_instance : partial_order \u2102),\n  ..(by apply_instance : comm_ring \u2102),\n  ..(by apply_instance : comm_semiring \u2102),\n  ..(by apply_instance : add_cancel_monoid \u2102) }\n\nlocalized \"attribute [instance] complex_ordered_comm_ring\" in complex_order\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a star ordered ring.\n(That is, an ordered ring in which every element of the form `star z * z` is nonnegative.)\n\nIn fact, the nonnegative elements are precisely those of this form.\nThis hold in any `C^*`-algebra, e.g. `\u2102`,\nbut we don't yet have `C^*`-algebras in mathlib.\n-/\ndef complex_star_ordered_ring : star_ordered_ring \u2102 :=\n{ star_mul_self_nonneg := \u03bb z,\n  begin\n    refine \u27e8z.abs^2, pow_nonneg (abs_nonneg z) 2, _\u27e9,\n    simp only [has_star.star, of_real_pow, zero_add],\n    norm_cast,\n    rw [\u2190norm_sq_eq_abs, norm_sq_eq_conj_mul_self],\n  end, }\n\nlocalized \"attribute [instance] complex_star_ordered_ring\" in complex_order\n\nend complex_order\n\n/-! ### Cauchy sequences -/\n\ntheorem is_cau_seq_re (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).re) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n\ntheorem is_cau_seq_im (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).im) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n\n/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_re (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_re f\u27e9\n\n/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_im (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_im f\u27e9\n\nlemma is_cau_seq_abs {f : \u2115 \u2192 \u2102} (hf : is_cau_seq abs f) :\n  is_cau_seq abs' (abs \u2218 f) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := hf \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9\n\n/-- The limit of a Cauchy sequence of complex numbers. -/\nnoncomputable def lim_aux (f : cau_seq \u2102 abs) : \u2102 :=\n\u27e8cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)\u27e9\n\ntheorem equiv_lim_aux (f : cau_seq \u2102 abs) : f \u2248 cau_seq.const abs (lim_aux f) :=\n\u03bb \u03b5 \u03b50, (exists_forall_ge_and\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_re f\u27e9 _ (half_pos \u03b50))\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_im f\u27e9 _ (half_pos \u03b50))).imp $\n\u03bb i H j ij, begin\n  cases H _ ij with H\u2081 H\u2082,\n  apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),\n  dsimp [lim_aux] at *,\n  have := add_lt_add H\u2081 H\u2082,\n  rwa add_halves at this,\nend\n\nnoncomputable instance : cau_seq.is_complete \u2102 abs :=\n\u27e8\u03bb f, \u27e8lim_aux f, equiv_lim_aux f\u27e9\u27e9\n\nopen cau_seq\n\nlemma lim_eq_lim_im_add_lim_re (f : cau_seq \u2102 abs) : lim f =\n  \u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I :=\nlim_eq_of_equiv_const $\ncalc f \u2248 _ : equiv_lim_aux f\n... = cau_seq.const abs (\u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I) :\n  cau_seq.ext (\u03bb _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))\n\nlemma lim_re (f : cau_seq \u2102 abs) : lim (cau_seq_re f) = (lim f).re :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma lim_im (f : cau_seq \u2102 abs) : lim (cau_seq_im f) = (lim f).im :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma is_cau_seq_conj (f : cau_seq \u2102 abs) : is_cau_seq abs (\u03bb n, conj (f n)) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := f.2 \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, by rw [\u2190 conj.map_sub, abs_conj]; exact hi j hj\u27e9\n\n/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/\nnoncomputable def cau_seq_conj (f : cau_seq \u2102 abs) : cau_seq \u2102 abs :=\n\u27e8_, is_cau_seq_conj f\u27e9\n\nlemma lim_conj (f : cau_seq \u2102 abs) : lim (cau_seq_conj f) = conj (lim f) :=\ncomplex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])\n  (by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)\n\n/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_abs (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_abs f.2\u27e9\n\nlemma lim_abs (f : cau_seq \u2102 abs) : lim (cau_seq_abs f) = abs (lim f) :=\nlim_eq_of_equiv_const (\u03bb \u03b5 \u03b50,\nlet \u27e8i, hi\u27e9 := equiv_lim f \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9)\n\n@[simp, norm_cast] lemma of_real_prod {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) :\n  ((\u220f i in s, f i : \u211d) : \u2102) = \u220f i in s, (f i : \u2102) :=\nring_hom.map_prod of_real _ _\n\n@[simp, norm_cast] lemma of_real_sum {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) :\n  ((\u2211 i in s, f i : \u211d) : \u2102) = \u2211 i in s, (f i : \u2102) :=\nring_hom.map_sum of_real _ _\n\nend complex\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.870597271765821, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7292296566190299}}
{"text": "import data.nat.prime\nimport data.real.basic\nimport topology.basic -- for namespace fiddling\n\n/-\n  Some experiments based on LFTCM20\n-/\n\nnamespace nat -- in place of 'open'\n\ntheorem infinitude_of_primes : \u2200 N, \u2203p \u2265 N, prime p:=\nbegin\n  intro N,\n\n  let M := factorial N + 1,\n  let p := min_fac M,\n\n  have pp: prime p := \n  begin\n    refine min_fac_prime _,\n    refine ne_of_gt _,\n    have : factorial N > 0 := factorial_pos N,\n    exact succ_lt_succ this,\n    /-\n    otherwise \"import tactic.linarith\" at the beginning and\n    put \"linarith,\" here.\n    -/\n  end,\n  \n  use p,\n  split,\n  { by_contradiction, \n    have h\u2081 : p \u2223 factorial N + 1:= min_fac_dvd M, -- divides is '\\|' \n    have h\u2082 : p \u2223 factorial N := \n    begin\n      show_term { refine dvd_factorial _ _,\n      exact prime.pos pp,\n      exact le_of_not_ge h, }\n    end,\n    -- I can leave \"by library search,\" below\n    have h : p \u2223 1 := iff.mp (nat.dvd_add_right h\u2082) h\u2081,\n    -- 'iff' in place of 'Iff'\n    -- hint here: use 'library_search,' with nothing after it\n    exact prime.not_dvd_one pp h, },\n  { exact pp },\nend\n\nend nat\n\nlemma mylemma: \u2200x:\u2115, 0 \u2264 x :=\nbegin\n  intro,\n  exact zero_le x\nend\n\n#check `[exact \u03bb (x : \u2115), zero_le x]\n\nopen nat\n\nexample (m n: \u2115) (h : m \u2264 n): (m:\u211d) \u2264 n :=\nbegin\n  exact cast_le.2 h,\nend\n\n#check cast_lt.2\n\nlemma real_not_nat : \u2203 (x : \u211d), \u2200 (n : \u2115), x \u2260 n :=\nbegin\n  use -1,\n  intro,\n  have : (-1:\u211d) < (0:\u2115) := by norm_num,\n  have : \u2200 (n : \u2115), (0 : \u211d) \u2264 n := cast_nonneg,\n  have : \u2200 (n : \u2115), (0 : \u211d) < n +1 :=\n  begin\n    intro m,\n    exact cast_add_one_pos m\n  end,\n  have : \u2200 (n : \u2115), (-1 : \u211d) < n :=\n  begin\n    intro n,\n    exact neg_lt_iff_pos_add.mpr (this n)\n  end,\n  exact ne_of_lt (this n),\nend\n\nexample (P R : Prop) (p: P) (q: \u00acP) : R := absurd p q\n\nexample (P R : Prop) (p: P) (q: \u00acP) : R := false.rec R (q p)\n\n-- Playing around classically. \nlemma exists_of_nonempty {\u03b1 : Type}  [nonempty \u03b1] : (\u2203 x : \u03b1, true) :=\nbegin\n  by_contradiction,\n  push_neg at h,\n  apply nonempty.elim, \n  assumption,\n  intro alp,\n  apply h alp trivial,\nend\n\n-- Experimenting with namespaces and `_root_`.\nnamespace is_open\n\n#check and                -- topology lemma\n#check _root_.is_open.and -- same as above\n#check _root_.and         -- logical `and` at the root namespace\n\nend is_open\n\n-- Example using `constructor`\nexample {\u03b1 : Type*} (P Q : \u03b1 \u2192 Prop) : (\u2200 x, P x \u2227 Q x) \u2192 (\u2200x, P x \u2228 Q x) :=\nbegin\n  intros h x,\n  constructor, -- Chooses the lhs, first constructor that matches.\n  exact (h x).left\nend\n\nsection including_omitting\n\nclass cls := (val : \u2115) -- From the Reference Manual, Sect. 3.2\n\nvariables (x : \u211d) [c : cls]\n\ndef ex2b : \u2115 := 5\n\n#check ex2b       -- ex2b : \u2115\n#check @ex2b      -- ex2b : \u2115\n\ninclude c\n\ndef ex2c : \u2115 := 5\n\n#check ex2c       -- ex2c : \u2115\n#check @ex2c      -- ex2c : \u03a0 [c : cls], \u2115\n\nexample : ex2c = (5 : \u2115) := rfl -- Here the `5` is just natural\n\nomit c\ninclude x\n\ndef ex2d : \u2115 := 5\n\n#check ex2d       -- ex2d : \u211d \u2192 \u2115\n#check @ex2d      -- ex2d : \u211d \u2192 \u2115\n\nexample : ex2d = (5 : \u2115) := rfl -- Here the `5` is coerced to `\u211d \u2192 \u2115` \n\nend including_omitting\n\nexample : ex2d = (5 : \u2115) := rfl -- Here too\n\n-- Useful tracing for turning non-terminal `simp`s into `simp only`s:\nset_option trace.simplify.rewrite true\nset_option trace.simplify.failure false\nset_option trace.simplify.rewrite_failure false\n-- Accompanying terminal (xD) script. End input with Ctrl-D.\n/-\necho [`sed  -e \"s/.*\\\\[simplify.rewrite\\\\] \\\\[\\([^[]*\\)]:.*/\\\\1/g\" -e \"s/set\\\\.//g\" -e \"s/^  .*//g\"  | grep -v \"^$\" | sort | uniq | tr '\\\\n' ',' && printf \\\\\\\\b`]\n-/\n-- ... though it seems to be already done in lean :facepalm:\n", "meta": {"author": "sterraf", "repo": "mylearninglean", "sha": "a8911234b2a4e15a48ec2c0f05d744e58f798ca7", "save_path": "github-repos/lean/sterraf-mylearninglean", "path": "github-repos/lean/sterraf-mylearninglean/mylearninglean-a8911234b2a4e15a48ec2c0f05d744e58f798ca7/src/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8376199673867853, "lm_q1q2_score": 0.7292296527589601}}
{"text": "/-\nCopyright (c) 2021 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n\n! This file was ported from Lean 3 source module topology.uniform_space.compact_convergence\n! leanprover-community/mathlib commit 1ead22342e1a078bd44744ace999f85756555d35\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.CompactOpen\nimport Mathbin.Topology.UniformSpace.UniformConvergence\n\n/-!\n# Compact convergence (uniform convergence on compact sets)\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGiven a topological space `\u03b1` and a uniform space `\u03b2` (e.g., a metric space or a topological group),\nthe space of continuous maps `C(\u03b1, \u03b2)` carries a natural uniform space structure. We define this\nuniform space structure in this file and also prove the following properties of the topology it\ninduces on `C(\u03b1, \u03b2)`:\n\n 1. Given a sequence of continuous functions `F\u2099 : \u03b1 \u2192 \u03b2` together with some continuous `f : \u03b1 \u2192 \u03b2`,\n    then `F\u2099` converges to `f` as a sequence in `C(\u03b1, \u03b2)` iff `F\u2099` converges to `f` uniformly on\n    each compact subset `K` of `\u03b1`.\n 2. Given `F\u2099` and `f` as above and suppose `\u03b1` is locally compact, then `F\u2099` converges to `f` iff\n    `F\u2099` converges to `f` locally uniformly.\n 3. The topology coincides with the compact-open topology.\n\nProperty 1 is essentially true by definition, 2 follows from basic results about uniform\nconvergence, but 3 requires a little work and uses the Lebesgue number lemma.\n\n## The uniform space structure\n\nGiven subsets `K \u2286 \u03b1` and `V \u2286 \u03b2 \u00d7 \u03b2`, let `E(K, V) \u2286 C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)` be the set of pairs of\ncontinuous functions `\u03b1 \u2192 \u03b2` which are `V`-close on `K`:\n$$\n  E(K, V) = \\{ (f, g) | \u2200 (x \u2208 K), (f x, g x) \u2208 V \\}.\n$$\nFixing some `f \u2208 C(\u03b1, \u03b2)`, let `N(K, V, f) \u2286 C(\u03b1, \u03b2)` be the set of continuous functions `\u03b1 \u2192 \u03b2`\nwhich are `V`-close to `f` on `K`:\n$$\n  N(K, V, f) = \\{ g | \u2200 (x \u2208 K), (f x, g x) \u2208 V \\}.\n$$\nUsing this notation we can describe the uniform space structure and the topology it induces.\nSpecifically:\n *  A subset `X \u2286 C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)` is an entourage for the uniform space structure on `C(\u03b1, \u03b2)`\n    iff there exists a compact `K` and entourage `V` such that `E(K, V) \u2286 X`.\n *  A subset `Y \u2286 C(\u03b1, \u03b2)` is a neighbourhood of `f` iff there exists a compact `K` and entourage\n    `V` such that `N(K, V, f) \u2286 Y`.\n\nThe topology on `C(\u03b1, \u03b2)` thus has a natural subbasis (the compact-open subbasis) and a natural\nneighbourhood basis (the compact-convergence neighbourhood basis).\n\n## Main definitions / results\n\n * `compact_open_eq_compact_convergence`: the compact-open topology is equal to the\n   compact-convergence topology.\n * `compact_convergence_uniform_space`: the uniform space structure on `C(\u03b1, \u03b2)`.\n * `mem_compact_convergence_entourage_iff`: a characterisation of the entourages of `C(\u03b1, \u03b2)`.\n * `tendsto_iff_forall_compact_tendsto_uniformly_on`: a sequence of functions `F\u2099` in `C(\u03b1, \u03b2)`\n   converges to some `f` iff `F\u2099` converges to `f` uniformly on each compact subset `K` of `\u03b1`.\n * `tendsto_iff_tendsto_locally_uniformly`: on a locally compact space, a sequence of functions\n   `F\u2099` in `C(\u03b1, \u03b2)` converges to some `f` iff `F\u2099` converges to `f` locally uniformly.\n * `tendsto_iff_tendsto_uniformly`: on a compact space, a sequence of functions `F\u2099` in `C(\u03b1, \u03b2)`\n   converges to some `f` iff `F\u2099` converges to `f` uniformly.\n\n## Implementation details\n\nWe use the forgetful inheritance pattern (see Note [forgetful inheritance]) to make the topology\nof the uniform space structure on `C(\u03b1, \u03b2)` definitionally equal to the compact-open topology.\n\n## TODO\n\n * When `\u03b2` is a metric space, there is natural basis for the compact-convergence topology\n   parameterised by triples `(K, \u03b5, f)` for a real number `\u03b5 > 0`.\n * When `\u03b1` is compact and `\u03b2` is a metric space, the compact-convergence topology (and thus also\n   the compact-open topology) is metrisable.\n * Results about uniformly continuous functions `\u03b3 \u2192 C(\u03b1, \u03b2)` and uniform limits of sequences\n   `\u03b9 \u2192 \u03b3 \u2192 C(\u03b1, \u03b2)`.\n-/\n\n\nuniverse u\u2081 u\u2082 u\u2083\n\nopen Filter uniformity Topology\n\nopen UniformSpace Set Filter\n\nvariable {\u03b1 : Type u\u2081} {\u03b2 : Type u\u2082} [TopologicalSpace \u03b1] [UniformSpace \u03b2]\n\nvariable (K : Set \u03b1) (V : Set (\u03b2 \u00d7 \u03b2)) (f : C(\u03b1, \u03b2))\n\nnamespace ContinuousMap\n\n#print ContinuousMap.compactConvNhd /-\n/-- Given `K \u2286 \u03b1`, `V \u2286 \u03b2 \u00d7 \u03b2`, and `f : C(\u03b1, \u03b2)`, we define `compact_conv_nhd K V f` to be the set\nof `g : C(\u03b1, \u03b2)` that are `V`-close to `f` on `K`. -/\ndef compactConvNhd : Set C(\u03b1, \u03b2) :=\n  { g | \u2200 x \u2208 K, (f x, g x) \u2208 V }\n#align continuous_map.compact_conv_nhd ContinuousMap.compactConvNhd\n-/\n\nvariable {K V}\n\n#print ContinuousMap.self_mem_compactConvNhd /-\ntheorem self_mem_compactConvNhd (hV : V \u2208 \ud835\udce4 \u03b2) : f \u2208 compactConvNhd K V f := fun x hx =>\n  refl_mem_uniformity hV\n#align continuous_map.self_mem_compact_conv_nhd ContinuousMap.self_mem_compactConvNhd\n-/\n\n#print ContinuousMap.compactConvNhd_mono /-\n@[mono]\ntheorem compactConvNhd_mono {V' : Set (\u03b2 \u00d7 \u03b2)} (hV' : V' \u2286 V) :\n    compactConvNhd K V' f \u2286 compactConvNhd K V f := fun x hx a ha => hV' (hx a ha)\n#align continuous_map.compact_conv_nhd_mono ContinuousMap.compactConvNhd_mono\n-/\n\n#print ContinuousMap.compactConvNhd_mem_comp /-\ntheorem compactConvNhd_mem_comp {g\u2081 g\u2082 : C(\u03b1, \u03b2)} {V' : Set (\u03b2 \u00d7 \u03b2)}\n    (hg\u2081 : g\u2081 \u2208 compactConvNhd K V f) (hg\u2082 : g\u2082 \u2208 compactConvNhd K V' g\u2081) :\n    g\u2082 \u2208 compactConvNhd K (V \u25cb V') f := fun x hx => \u27e8g\u2081 x, hg\u2081 x hx, hg\u2082 x hx\u27e9\n#align continuous_map.compact_conv_nhd_mem_comp ContinuousMap.compactConvNhd_mem_comp\n-/\n\n/- warning: continuous_map.compact_conv_nhd_nhd_basis -> ContinuousMap.compactConvNhd_nhd_basis is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {K : Set.{u1} \u03b1} {V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)} (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)), (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) -> (Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V' : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Exists.{0} (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V' (uniformity.{u2} \u03b2 _inst_2)) (fun (H : Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V' (uniformity.{u2} \u03b2 _inst_2)) => And (HasSubset.Subset.{u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasSubset.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V' V) (forall (g : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)), (Membership.Mem.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Set.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.hasMem.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) g (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V' f)) -> (HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.hasSubset.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V' g) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V f))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {K : Set.{u1} \u03b1} {V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)} (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)), (Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) -> (Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V' : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => And (Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V' (uniformity.{u2} \u03b2 _inst_2)) (And (HasSubset.Subset.{u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.instHasSubsetSet.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V' V) (forall (g : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)), (Membership.mem.{max u1 u2, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Set.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.instMembershipSet.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) g (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V' f)) -> (HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.instHasSubsetSet.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V' g) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V f))))))\nCase conversion may be inaccurate. Consider using '#align continuous_map.compact_conv_nhd_nhd_basis ContinuousMap.compactConvNhd_nhd_basis\u2093'. -/\n/-- A key property of `compact_conv_nhd`. It allows us to apply\n`topological_space.nhds_mk_of_nhds_filter_basis` below. -/\ntheorem compactConvNhd_nhd_basis (hV : V \u2208 \ud835\udce4 \u03b2) :\n    \u2203 V' \u2208 \ud835\udce4 \u03b2,\n      V' \u2286 V \u2227 \u2200 g \u2208 compactConvNhd K V' f, compactConvNhd K V' g \u2286 compactConvNhd K V f :=\n  by\n  obtain \u27e8V', h\u2081, h\u2082\u27e9 := comp_mem_uniformity_sets hV\n  exact\n    \u27e8V', h\u2081, subset.trans (subset_comp_self_of_mem_uniformity h\u2081) h\u2082, fun g hg g' hg' =>\n      compact_conv_nhd_mono f h\u2082 (compact_conv_nhd_mem_comp f hg hg')\u27e9\n#align continuous_map.compact_conv_nhd_nhd_basis ContinuousMap.compactConvNhd_nhd_basis\n\n/- warning: continuous_map.compact_conv_nhd_subset_inter -> ContinuousMap.compactConvNhd_subset_inter is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (K\u2081 : Set.{u1} \u03b1) (K\u2082 : Set.{u1} \u03b1) (V\u2081 : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (V\u2082 : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)), HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.hasSubset.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) K\u2081 K\u2082) (Inter.inter.{u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasInter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V\u2081 V\u2082) f) (Inter.inter.{max u1 u2} (Set.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.hasInter.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K\u2081 V\u2081 f) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K\u2082 V\u2082 f))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (K\u2081 : Set.{u1} \u03b1) (K\u2082 : Set.{u1} \u03b1) (V\u2081 : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (V\u2082 : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)), HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.instHasSubsetSet.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) K\u2081 K\u2082) (Inter.inter.{u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.instInterSet.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V\u2081 V\u2082) f) (Inter.inter.{max u1 u2} (Set.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.instInterSet.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K\u2081 V\u2081 f) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K\u2082 V\u2082 f))\nCase conversion may be inaccurate. Consider using '#align continuous_map.compact_conv_nhd_subset_inter ContinuousMap.compactConvNhd_subset_inter\u2093'. -/\ntheorem compactConvNhd_subset_inter (K\u2081 K\u2082 : Set \u03b1) (V\u2081 V\u2082 : Set (\u03b2 \u00d7 \u03b2)) :\n    compactConvNhd (K\u2081 \u222a K\u2082) (V\u2081 \u2229 V\u2082) f \u2286 compactConvNhd K\u2081 V\u2081 f \u2229 compactConvNhd K\u2082 V\u2082 f :=\n  fun g hg =>\n  \u27e8fun x hx => mem_of_mem_inter_left (hg x (mem_union_left K\u2082 hx)), fun x hx =>\n    mem_of_mem_inter_right (hg x (mem_union_right K\u2081 hx))\u27e9\n#align continuous_map.compact_conv_nhd_subset_inter ContinuousMap.compactConvNhd_subset_inter\n\n#print ContinuousMap.compactConvNhd_compact_entourage_nonempty /-\ntheorem compactConvNhd_compact_entourage_nonempty :\n    { KV : Set \u03b1 \u00d7 Set (\u03b2 \u00d7 \u03b2) | IsCompact KV.1 \u2227 KV.2 \u2208 \ud835\udce4 \u03b2 }.Nonempty :=\n  \u27e8\u27e8\u2205, univ\u27e9, isCompact_empty, Filter.univ_mem\u27e9\n#align continuous_map.compact_conv_nhd_compact_entourage_nonempty ContinuousMap.compactConvNhd_compact_entourage_nonempty\n-/\n\n#print ContinuousMap.compactConvNhd_filter_isBasis /-\ntheorem compactConvNhd_filter_isBasis :\n    Filter.IsBasis (fun KV : Set \u03b1 \u00d7 Set (\u03b2 \u00d7 \u03b2) => IsCompact KV.1 \u2227 KV.2 \u2208 \ud835\udce4 \u03b2) fun KV =>\n      compactConvNhd KV.1 KV.2 f :=\n  { Nonempty := compactConvNhd_compact_entourage_nonempty\n    inter := by\n      rintro \u27e8K\u2081, V\u2081\u27e9 \u27e8K\u2082, V\u2082\u27e9 \u27e8hK\u2081, hV\u2081\u27e9 \u27e8hK\u2082, hV\u2082\u27e9\n      exact\n        \u27e8\u27e8K\u2081 \u222a K\u2082, V\u2081 \u2229 V\u2082\u27e9, \u27e8hK\u2081.union hK\u2082, Filter.inter_mem hV\u2081 hV\u2082\u27e9,\n          compact_conv_nhd_subset_inter f K\u2081 K\u2082 V\u2081 V\u2082\u27e9 }\n#align continuous_map.compact_conv_nhd_filter_is_basis ContinuousMap.compactConvNhd_filter_isBasis\n-/\n\n#print ContinuousMap.compactConvergenceFilterBasis /-\n/-- A filter basis for the neighbourhood filter of a point in the compact-convergence topology. -/\ndef compactConvergenceFilterBasis (f : C(\u03b1, \u03b2)) : FilterBasis C(\u03b1, \u03b2) :=\n  (compactConvNhd_filter_isBasis f).FilterBasis\n#align continuous_map.compact_convergence_filter_basis ContinuousMap.compactConvergenceFilterBasis\n-/\n\n#print ContinuousMap.mem_compactConvergence_nhd_filter /-\ntheorem mem_compactConvergence_nhd_filter (Y : Set C(\u03b1, \u03b2)) :\n    Y \u2208 (compactConvergenceFilterBasis f).filter\u2093 \u2194\n      \u2203 (K : Set \u03b1)(V : Set (\u03b2 \u00d7 \u03b2))(hK : IsCompact K)(hV : V \u2208 \ud835\udce4 \u03b2), compactConvNhd K V f \u2286 Y :=\n  by\n  constructor\n  \u00b7 rintro \u27e8X, \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9, hY\u27e9\n    exact \u27e8K, V, hK, hV, hY\u27e9\n  \u00b7 rintro \u27e8K, V, hK, hV, hY\u27e9\n    exact \u27e8compact_conv_nhd K V f, \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9, hY\u27e9\n#align continuous_map.mem_compact_convergence_nhd_filter ContinuousMap.mem_compactConvergence_nhd_filter\n-/\n\n#print ContinuousMap.compactConvergenceTopology /-\n/-- The compact-convergence topology. In fact, see `compact_open_eq_compact_convergence` this is\nthe same as the compact-open topology. This definition is thus an auxiliary convenience definition\nand is unlikely to be of direct use. -/\ndef compactConvergenceTopology : TopologicalSpace C(\u03b1, \u03b2) :=\n  TopologicalSpace.mkOfNhds fun f => (compactConvergenceFilterBasis f).filter\u2093\n#align continuous_map.compact_convergence_topology ContinuousMap.compactConvergenceTopology\n-/\n\n#print ContinuousMap.nhds_compactConvergence /-\ntheorem nhds_compactConvergence :\n    @nhds _ compactConvergenceTopology f = (compactConvergenceFilterBasis f).filter\u2093 :=\n  by\n  rw [TopologicalSpace.nhds_mkOfNhds_filterBasis] <;> rintro g - \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9\n  \u00b7 exact self_mem_compact_conv_nhd g hV\n  \u00b7 obtain \u27e8V', hV', h\u2081, h\u2082\u27e9 := compact_conv_nhd_nhd_basis g hV\n    exact\n      \u27e8compact_conv_nhd K V' g, \u27e8\u27e8K, V'\u27e9, \u27e8hK, hV'\u27e9, rfl\u27e9, compact_conv_nhd_mono g h\u2081, fun g' hg' =>\n        \u27e8compact_conv_nhd K V' g', \u27e8\u27e8K, V'\u27e9, \u27e8hK, hV'\u27e9, rfl\u27e9, h\u2082 g' hg'\u27e9\u27e9\n#align continuous_map.nhds_compact_convergence ContinuousMap.nhds_compactConvergence\n-/\n\n#print ContinuousMap.hasBasis_nhds_compactConvergence /-\ntheorem hasBasis_nhds_compactConvergence :\n    HasBasis (@nhds _ compactConvergenceTopology f)\n      (fun p : Set \u03b1 \u00d7 Set (\u03b2 \u00d7 \u03b2) => IsCompact p.1 \u2227 p.2 \u2208 \ud835\udce4 \u03b2) fun p =>\n      compactConvNhd p.1 p.2 f :=\n  (nhds_compactConvergence f).symm \u25b8 (compactConvNhd_filter_isBasis f).HasBasis\n#align continuous_map.has_basis_nhds_compact_convergence ContinuousMap.hasBasis_nhds_compactConvergence\n-/\n\n/- warning: continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on' -> ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceTopology.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) f)) (forall (K : Set.{u1} \u03b1), (IsCompact.{u1} \u03b1 _inst_1 K) -> (TendstoUniformlyOn.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 (fun (i : \u03b9) (a : \u03b1) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (F i) a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f) p K))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceTopology.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) f)) (forall (K : Set.{u1} \u03b1), (IsCompact.{u1} \u03b1 _inst_1 K) -> (TendstoUniformlyOn.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 (fun (i : \u03b9) (a : \u03b1) => FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (F i) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f) p K))\nCase conversion may be inaccurate. Consider using '#align continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on' ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn'\u2093'. -/\n/-- This is an auxiliary lemma and is unlikely to be of direct use outside of this file. See\n`tendsto_iff_forall_compact_tendsto_uniformly_on` below for the useful version where the topology\nis picked up via typeclass inference. -/\ntheorem tendsto_iff_forall_compact_tendstoUniformlyOn' {\u03b9 : Type u\u2083} {p : Filter \u03b9}\n    {F : \u03b9 \u2192 C(\u03b1, \u03b2)} :\n    Filter.Tendsto F p (@nhds _ compactConvergenceTopology f) \u2194\n      \u2200 K, IsCompact K \u2192 TendstoUniformlyOn (fun i a => F i a) f p K :=\n  by\n  simp only [(has_basis_nhds_compact_convergence f).tendsto_right_iff, TendstoUniformlyOn, and_imp,\n    Prod.forall]\n  refine' forall_congr' fun K => _\n  rw [forall_swap]\n  exact forall\u2083_congr fun hK V hV => Iff.rfl\n#align continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on' ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn'\n\n/- warning: continuous_map.compact_conv_nhd_subset_compact_open -> ContinuousMap.compactConvNhd_subset_compactOpen is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {K : Set.{u1} \u03b1} (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)), (IsCompact.{u1} \u03b1 _inst_1 K) -> (forall {U : Set.{u2} \u03b2}, (IsOpen.{u2} \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) U) -> (Membership.Mem.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Set.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.hasMem.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f (ContinuousMap.CompactOpen.gen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) K U)) -> (Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Exists.{0} (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (fun (H : Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) => And (IsOpen.{u2} (Prod.{u2, u2} \u03b2 \u03b2) (Prod.topologicalSpace.{u2, u2} \u03b2 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) V) (HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.hasSubset.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V f) (ContinuousMap.CompactOpen.gen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) K U))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {K : Set.{u1} \u03b1} (f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)), (IsCompact.{u1} \u03b1 _inst_1 K) -> (forall {U : Set.{u2} \u03b2}, (IsOpen.{u2} \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) U) -> (Membership.mem.{max u1 u2, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Set.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.instMembershipSet.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f (ContinuousMap.CompactOpen.gen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) K U)) -> (Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => And (Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (And (IsOpen.{u2} (Prod.{u2, u2} \u03b2 \u03b2) (instTopologicalSpaceProd.{u2, u2} \u03b2 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) V) (HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.instHasSubsetSet.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (ContinuousMap.compactConvNhd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K V f) (ContinuousMap.CompactOpen.gen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) K U))))))\nCase conversion may be inaccurate. Consider using '#align continuous_map.compact_conv_nhd_subset_compact_open ContinuousMap.compactConvNhd_subset_compactOpen\u2093'. -/\n/-- Any point of `compact_open.gen K U` is also an interior point wrt the topology of compact\nconvergence.\n\nThe topology of compact convergence is thus at least as fine as the compact-open topology. -/\ntheorem compactConvNhd_subset_compactOpen (hK : IsCompact K) {U : Set \u03b2} (hU : IsOpen U)\n    (hf : f \u2208 CompactOpen.gen K U) :\n    \u2203 V \u2208 \ud835\udce4 \u03b2, IsOpen V \u2227 compactConvNhd K V f \u2286 CompactOpen.gen K U :=\n  by\n  obtain \u27e8V, hV\u2081, hV\u2082, hV\u2083\u27e9 := lebesgue_number_of_compact_open (hK.image f.continuous) hU hf\n  refine' \u27e8V, hV\u2081, hV\u2082, _\u27e9\n  rintro g hg _ \u27e8x, hx, rfl\u27e9\n  exact hV\u2083 (f x) \u27e8x, hx, rfl\u27e9 (hg x hx)\n#align continuous_map.compact_conv_nhd_subset_compact_open ContinuousMap.compactConvNhd_subset_compactOpen\n\n#print ContinuousMap.inter\u1d62_compactOpen_gen_subset_compactConvNhd /-\n/-- The point `f` in `compact_conv_nhd K V f` is also an interior point wrt the compact-open\ntopology.\n\nSince `compact_conv_nhd K V f` are a neighbourhood basis at `f` for each `f`, it follows that\nthe compact-open topology is at least as fine as the topology of compact convergence. -/\ntheorem inter\u1d62_compactOpen_gen_subset_compactConvNhd (hK : IsCompact K) (hV : V \u2208 \ud835\udce4 \u03b2) :\n    \u2203 (\u03b9 : Sort (u\u2081 + 1))(_ : Fintype \u03b9)(C : \u03b9 \u2192 Set \u03b1)(hC : \u2200 i, IsCompact (C i))(U :\n      \u03b9 \u2192 Set \u03b2)(hU : \u2200 i, IsOpen (U i)),\n      (f \u2208 \u22c2 i, CompactOpen.gen (C i) (U i)) \u2227\n        (\u22c2 i, CompactOpen.gen (C i) (U i)) \u2286 compactConvNhd K V f :=\n  by\n  obtain \u27e8W, hW\u2081, hW\u2084, hW\u2082, hW\u2083\u27e9 := comp_open_symm_mem_uniformity_sets hV\n  obtain \u27e8Z, hZ\u2081, hZ\u2084, hZ\u2082, hZ\u2083\u27e9 := comp_open_symm_mem_uniformity_sets hW\u2081\n  let U : \u03b1 \u2192 Set \u03b1 := fun x => f \u207b\u00b9' ball (f x) Z\n  have hU : \u2200 x, IsOpen (U x) := fun x => f.continuous.is_open_preimage _ (is_open_ball _ hZ\u2084)\n  have hUK : K \u2286 \u22c3 x : K, U (x : K) := by\n    intro x hx\n    simp only [exists_prop, mem_Union, Union_coe_set, mem_preimage]\n    exact \u27e8(\u27e8x, hx\u27e9 : K), by simp [hx, mem_ball_self (f x) hZ\u2081]\u27e9\n  obtain \u27e8t, ht\u27e9 := hK.elim_finite_subcover _ (fun x : K => hU x.val) hUK\n  let C : t \u2192 Set \u03b1 := fun i => K \u2229 closure (U ((i : K) : \u03b1))\n  have hC : K \u2286 \u22c3 i, C i := by\n    rw [\u2190 K.inter_Union, subset_inter_iff]\n    refine' \u27e8subset.rfl, ht.trans _\u27e9\n    simp only [SetCoe.forall, Subtype.coe_mk, Union_subset_iff]\n    exact fun x hx\u2081 hx\u2082 => subset_Union_of_subset (\u27e8_, hx\u2082\u27e9 : t) (by simp [subset_closure])\n  have hfC : \u2200 i : t, C i \u2286 f \u207b\u00b9' ball (f ((i : K) : \u03b1)) W :=\n    by\n    simp only [\u2190 image_subset_iff, \u2190 mem_preimage]\n    rintro \u27e8\u27e8x, hx\u2081\u27e9, hx\u2082\u27e9\n    have hZW : closure (ball (f x) Z) \u2286 ball (f x) W :=\n      by\n      intro y hy\n      obtain \u27e8z, hz\u2081, hz\u2082\u27e9 := uniform_space.mem_closure_iff_ball.mp hy hZ\u2081\n      exact ball_mono hZ\u2083 _ (mem_ball_comp hz\u2082 ((mem_ball_symmetry hZ\u2082).mp hz\u2081))\n    calc\n      f '' (K \u2229 closure (U x)) \u2286 f '' closure (U x) := image_subset _ (inter_subset_right _ _)\n      _ \u2286 closure (f '' U x) := f.continuous.continuous_on.image_closure\n      _ \u2286 closure (ball (f x) Z) := by\n        apply closure_mono\n        simp\n      _ \u2286 ball (f x) W := hZW\n      \n  refine'\n    \u27e8t, t.fintype_coe_sort, C, fun i => hK.inter_right isClosed_closure, fun i =>\n      ball (f ((i : K) : \u03b1)) W, fun i => is_open_ball _ hW\u2084, by simp [compact_open.gen, hfC],\n      fun g hg x hx => hW\u2083 (mem_comp_rel.mpr _)\u27e9\n  simp only [mem_Inter, compact_open.gen, mem_set_of_eq, image_subset_iff] at hg\n  obtain \u27e8y, hy\u27e9 := mem_Union.mp (hC hx)\n  exact \u27e8f y, (mem_ball_symmetry hW\u2082).mp (hfC y hy), mem_preimage.mp (hg y hy)\u27e9\n#align continuous_map.Inter_compact_open_gen_subset_compact_conv_nhd ContinuousMap.inter\u1d62_compactOpen_gen_subset_compactConvNhd\n-/\n\n#print ContinuousMap.compactOpen_eq_compactConvergence /-\n/-- The compact-open topology is equal to the compact-convergence topology. -/\ntheorem compactOpen_eq_compactConvergence :\n    ContinuousMap.compactOpen = (compactConvergenceTopology : TopologicalSpace C(\u03b1, \u03b2)) :=\n  by\n  rw [compact_convergence_topology, ContinuousMap.compactOpen]\n  refine' le_antisymm _ _\n  \u00b7 refine' fun X hX => is_open_iff_forall_mem_open.mpr fun f hf => _\n    have hXf : X \u2208 (compact_convergence_filter_basis f).filter\u2093 :=\n      by\n      rw [\u2190 nhds_compact_convergence]\n      exact @IsOpen.mem_nhds C(\u03b1, \u03b2) compact_convergence_topology _ _ hX hf\n    obtain \u27e8-, \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9, hXf\u27e9 := hXf\n    obtain \u27e8\u03b9, h\u03b9, C, hC, U, hU, h\u2081, h\u2082\u27e9 := Inter_compact_open_gen_subset_compact_conv_nhd f hK hV\n    haveI := h\u03b9\n    exact\n      \u27e8\u22c2 i, compact_open.gen (C i) (U i), h\u2082.trans hXf,\n        isOpen_inter\u1d62 fun i => ContinuousMap.isOpen_gen (hC i) (hU i), h\u2081\u27e9\n  \u00b7 simp only [TopologicalSpace.le_generateFrom_iff_subset_isOpen, and_imp, exists_prop,\n      forall_exists_index, set_of_subset_set_of]\n    rintro - K hK U hU rfl f hf\n    obtain \u27e8V, hV, hV', hVf\u27e9 := compact_conv_nhd_subset_compact_open f hK hU hf\n    exact Filter.mem_of_superset (FilterBasis.mem_filter_of_mem _ \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9) hVf\n#align continuous_map.compact_open_eq_compact_convergence ContinuousMap.compactOpen_eq_compactConvergence\n-/\n\n#print ContinuousMap.compactConvergenceUniformity /-\n/-- The filter on `C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)` which underlies the uniform space structure on `C(\u03b1, \u03b2)`. -/\ndef compactConvergenceUniformity : Filter (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)) :=\n  \u2a05 KV \u2208 { KV : Set \u03b1 \u00d7 Set (\u03b2 \u00d7 \u03b2) | IsCompact KV.1 \u2227 KV.2 \u2208 \ud835\udce4 \u03b2 },\n    \ud835\udcdf { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x : \u03b1, x \u2208 KV.1 \u2192 (fg.1 x, fg.2 x) \u2208 KV.2 }\n#align continuous_map.compact_convergence_uniformity ContinuousMap.compactConvergenceUniformity\n-/\n\n/- warning: continuous_map.has_basis_compact_convergence_uniformity_aux -> ContinuousMap.hasBasis_compactConvergenceUniformity_aux is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2], Filter.HasBasis.{max u1 u2, max (succ u1) (succ u2)} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) (ContinuousMap.compactConvergenceUniformity.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => And (IsCompact.{u1} \u03b1 _inst_1 (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p) (uniformity.{u2} \u03b2 _inst_2))) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => setOf.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) -> (Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b2 \u03b2) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} \u03b2 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2], Filter.HasBasis.{max u1 u2, max (succ u1) (succ u2)} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) (ContinuousMap.compactConvergenceUniformity.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => And (IsCompact.{u1} \u03b1 _inst_1 (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) (Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p) (uniformity.{u2} \u03b2 _inst_2))) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => setOf.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) -> (Membership.mem.{u2, u2} (Prod.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x)) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.instMembershipSet.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p))))\nCase conversion may be inaccurate. Consider using '#align continuous_map.has_basis_compact_convergence_uniformity_aux ContinuousMap.hasBasis_compactConvergenceUniformity_aux\u2093'. -/\ntheorem hasBasis_compactConvergenceUniformity_aux :\n    HasBasis (@compactConvergenceUniformity \u03b1 \u03b2 _ _)\n      (fun p : Set \u03b1 \u00d7 Set (\u03b2 \u00d7 \u03b2) => IsCompact p.1 \u2227 p.2 \u2208 \ud835\udce4 \u03b2) fun p =>\n      { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 p.1, (fg.1 x, fg.2 x) \u2208 p.2 } :=\n  by\n  refine' Filter.hasBasis_binf\u1d62_principal _ compact_conv_nhd_compact_entourage_nonempty\n  rintro \u27e8K\u2081, V\u2081\u27e9 \u27e8hK\u2081, hV\u2081\u27e9 \u27e8K\u2082, V\u2082\u27e9 \u27e8hK\u2082, hV\u2082\u27e9\n  refine' \u27e8\u27e8K\u2081 \u222a K\u2082, V\u2081 \u2229 V\u2082\u27e9, \u27e8hK\u2081.union hK\u2082, Filter.inter_mem hV\u2081 hV\u2082\u27e9, _\u27e9\n  simp only [le_eq_subset, Prod.forall, set_of_subset_set_of, ge_iff_le, Order.Preimage, \u2190\n    forall_and, mem_inter_iff, mem_union]\n  exact fun f g => forall_imp fun x => by tauto\n#align continuous_map.has_basis_compact_convergence_uniformity_aux ContinuousMap.hasBasis_compactConvergenceUniformity_aux\n\n/- warning: continuous_map.mem_compact_convergence_uniformity -> ContinuousMap.mem_compactConvergenceUniformity is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (X : Set.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))), Iff (Membership.Mem.{max u1 u2, max u1 u2} (Set.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Filter.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Filter.hasMem.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) X (ContinuousMap.compactConvergenceUniformity.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Exists.{succ u1} (Set.{u1} \u03b1) (fun (K : Set.{u1} \u03b1) => Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Exists.{0} (IsCompact.{u1} \u03b1 _inst_1 K) (fun (hK : IsCompact.{u1} \u03b1 _inst_1 K) => Exists.{0} (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (fun (hV : Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) => HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Set.hasSubset.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (setOf.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x K) -> (Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b2 \u03b2) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} \u03b2 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) V))) X)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (X : Set.{max u2 u1} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))), Iff (Membership.mem.{max u1 u2, max u1 u2} (Set.{max u2 u1} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Filter.{max u2 u1} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (instMembershipSetFilter.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) X (ContinuousMap.compactConvergenceUniformity.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (Exists.{succ u1} (Set.{u1} \u03b1) (fun (K : Set.{u1} \u03b1) => Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Exists.{0} (IsCompact.{u1} \u03b1 _inst_1 K) (fun (hK : IsCompact.{u1} \u03b1 _inst_1 K) => Exists.{0} (Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (fun (hV : Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) => HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Set.instHasSubsetSet.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (setOf.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x K) -> (Membership.mem.{u2, u2} (Prod.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x)) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.instMembershipSet.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) V))) X)))))\nCase conversion may be inaccurate. Consider using '#align continuous_map.mem_compact_convergence_uniformity ContinuousMap.mem_compactConvergenceUniformity\u2093'. -/\n/-- An intermediate lemma. Usually `mem_compact_convergence_entourage_iff` is more useful. -/\ntheorem mem_compactConvergenceUniformity (X : Set (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2))) :\n    X \u2208 @compactConvergenceUniformity \u03b1 \u03b2 _ _ \u2194\n      \u2203 (K : Set \u03b1)(V : Set (\u03b2 \u00d7 \u03b2))(hK : IsCompact K)(hV : V \u2208 \ud835\udce4 \u03b2),\n        { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 K, (fg.1 x, fg.2 x) \u2208 V } \u2286 X :=\n  by\n  simp only [has_basis_compact_convergence_uniformity_aux.mem_iff, exists_prop, Prod.exists,\n    and_assoc']\n#align continuous_map.mem_compact_convergence_uniformity ContinuousMap.mem_compactConvergenceUniformity\n\n#print ContinuousMap.compactConvergenceUniformSpace /-\n/-- Note that we ensure the induced topology is definitionally the compact-open topology. -/\ninstance compactConvergenceUniformSpace : UniformSpace C(\u03b1, \u03b2)\n    where\n  uniformity := compactConvergenceUniformity\n  refl :=\n    by\n    simp only [compact_convergence_uniformity, and_imp, Filter.le_principal_iff, Prod.forall,\n      Filter.mem_principal, mem_set_of_eq, le_inf\u1d62_iff, idRel_subset]\n    exact fun K V hK hV f x hx => refl_mem_uniformity hV\n  symm :=\n    by\n    simp only [compact_convergence_uniformity, and_imp, Prod.forall, mem_set_of_eq, Prod.fst_swap,\n      Filter.tendsto_principal, Prod.snd_swap, Filter.tendsto_inf\u1d62]\n    intro K V hK hV\n    obtain \u27e8V', hV', hsymm, hsub\u27e9 := symm_of_uniformity hV\n    let X := { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x : \u03b1, x \u2208 K \u2192 (fg.1 x, fg.2 x) \u2208 V' }\n    have hX : X \u2208 compact_convergence_uniformity :=\n      (mem_compact_convergence_uniformity X).mpr \u27e8K, V', hK, hV', by simp\u27e9\n    exact Filter.eventually_of_mem hX fun fg hfg x hx => hsub (hsymm _ _ (hfg x hx))\n  comp X hX :=\n    by\n    obtain \u27e8K, V, hK, hV, hX\u27e9 := (mem_compact_convergence_uniformity X).mp hX\n    obtain \u27e8V', hV', hcomp\u27e9 := comp_mem_uniformity_sets hV\n    let h := fun s : Set (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)) => s \u25cb s\n    suffices\n      h { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 K, (fg.1 x, fg.2 x) \u2208 V' } \u2208\n        compact_convergence_uniformity.lift' h\n      by\n      apply Filter.mem_of_superset this\n      rintro \u27e8f, g\u27e9 \u27e8z, hz\u2081, hz\u2082\u27e9\n      refine' hX fun x hx => hcomp _\n      exact \u27e8z x, hz\u2081 x hx, hz\u2082 x hx\u27e9\n    apply Filter.mem_lift'\n    exact (mem_compact_convergence_uniformity _).mpr \u27e8K, V', hK, hV', subset.refl _\u27e9\n  isOpen_uniformity := by\n    rw [compact_open_eq_compact_convergence]\n    refine' fun Y => forall\u2082_congr fun f hf => _\n    simp only [mem_compact_convergence_nhd_filter, mem_compact_convergence_uniformity, Prod.forall,\n      set_of_subset_set_of, compact_conv_nhd]\n    refine' exists\u2084_congr fun K V hK hV => \u27e8_, fun hY g hg => hY f g hg rfl\u27e9\n    rintro hY g\u2081 g\u2082 hg\u2081 rfl\n    exact hY hg\u2081\n#align continuous_map.compact_convergence_uniform_space ContinuousMap.compactConvergenceUniformSpace\n-/\n\n/- warning: continuous_map.mem_compact_convergence_entourage_iff -> ContinuousMap.mem_compactConvergence_entourage_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (X : Set.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))), Iff (Membership.Mem.{max u1 u2, max u1 u2} (Set.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Filter.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Filter.hasMem.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) X (uniformity.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) (Exists.{succ u1} (Set.{u1} \u03b1) (fun (K : Set.{u1} \u03b1) => Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Exists.{0} (IsCompact.{u1} \u03b1 _inst_1 K) (fun (hK : IsCompact.{u1} \u03b1 _inst_1 K) => Exists.{0} (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (fun (hV : Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) => HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Set.hasSubset.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (setOf.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x K) -> (Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b2 \u03b2) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} \u03b2 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) V))) X)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] (X : Set.{max u2 u1} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))), Iff (Membership.mem.{max u1 u2, max u1 u2} (Set.{max u2 u1} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Filter.{max u2 u1} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (instMembershipSetFilter.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) X (uniformity.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2))) (Exists.{succ u1} (Set.{u1} \u03b1) (fun (K : Set.{u1} \u03b1) => Exists.{succ u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Exists.{0} (IsCompact.{u1} \u03b1 _inst_1 K) (fun (hK : IsCompact.{u1} \u03b1 _inst_1 K) => Exists.{0} (Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (fun (hV : Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) => HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (Set.instHasSubsetSet.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)))) (setOf.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x K) -> (Membership.mem.{u2, u2} (Prod.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x)) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.instMembershipSet.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) V))) X)))))\nCase conversion may be inaccurate. Consider using '#align continuous_map.mem_compact_convergence_entourage_iff ContinuousMap.mem_compactConvergence_entourage_iff\u2093'. -/\ntheorem mem_compactConvergence_entourage_iff (X : Set (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2))) :\n    X \u2208 \ud835\udce4 C(\u03b1, \u03b2) \u2194\n      \u2203 (K : Set \u03b1)(V : Set (\u03b2 \u00d7 \u03b2))(hK : IsCompact K)(hV : V \u2208 \ud835\udce4 \u03b2),\n        { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 K, (fg.1 x, fg.2 x) \u2208 V } \u2286 X :=\n  mem_compactConvergenceUniformity X\n#align continuous_map.mem_compact_convergence_entourage_iff ContinuousMap.mem_compactConvergence_entourage_iff\n\n/- warning: continuous_map.has_basis_compact_convergence_uniformity -> ContinuousMap.hasBasis_compactConvergenceUniformity is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2], Filter.HasBasis.{max u1 u2, max (succ u1) (succ u2)} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) (uniformity.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => And (IsCompact.{u1} \u03b1 _inst_1 (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) (Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p) (uniformity.{u2} \u03b2 _inst_2))) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => setOf.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) -> (Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b2 \u03b2) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} \u03b2 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2], Filter.HasBasis.{max u1 u2, max (succ u1) (succ u2)} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) (uniformity.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => And (IsCompact.{u1} \u03b1 _inst_1 (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) (Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p) (uniformity.{u2} \u03b2 _inst_2))) (fun (p : Prod.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))) => setOf.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x (Prod.fst.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p)) -> (Membership.mem.{u2, u2} (Prod.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x)) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.instMembershipSet.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) (Prod.snd.{u1, u2} (Set.{u1} \u03b1) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) p))))\nCase conversion may be inaccurate. Consider using '#align continuous_map.has_basis_compact_convergence_uniformity ContinuousMap.hasBasis_compactConvergenceUniformity\u2093'. -/\ntheorem hasBasis_compactConvergenceUniformity :\n    HasBasis (\ud835\udce4 C(\u03b1, \u03b2)) (fun p : Set \u03b1 \u00d7 Set (\u03b2 \u00d7 \u03b2) => IsCompact p.1 \u2227 p.2 \u2208 \ud835\udce4 \u03b2) fun p =>\n      { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 p.1, (fg.1 x, fg.2 x) \u2208 p.2 } :=\n  hasBasis_compactConvergenceUniformity_aux\n#align continuous_map.has_basis_compact_convergence_uniformity ContinuousMap.hasBasis_compactConvergenceUniformity\n\n/- warning: filter.has_basis.compact_convergence_uniformity -> Filter.HasBasis.compactConvergenceUniformity is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {\u03b9 : Type.{u3}} {pi : \u03b9 -> Prop} {s : \u03b9 -> (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2))}, (Filter.HasBasis.{u2, succ u3} (Prod.{u2, u2} \u03b2 \u03b2) \u03b9 (uniformity.{u2} \u03b2 _inst_2) pi s) -> (Filter.HasBasis.{max u1 u2, max (succ u1) (succ u3)} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.{u1, u3} (Set.{u1} \u03b1) \u03b9) (uniformity.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (fun (p : Prod.{u1, u3} (Set.{u1} \u03b1) \u03b9) => And (IsCompact.{u1} \u03b1 _inst_1 (Prod.fst.{u1, u3} (Set.{u1} \u03b1) \u03b9 p)) (pi (Prod.snd.{u1, u3} (Set.{u1} \u03b1) \u03b9 p))) (fun (p : Prod.{u1, u3} (Set.{u1} \u03b1) \u03b9) => setOf.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Prod.fst.{u1, u3} (Set.{u1} \u03b1) \u03b9 p)) -> (Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b2 \u03b2) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} \u03b2 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) (s (Prod.snd.{u1, u3} (Set.{u1} \u03b1) \u03b9 p))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u3}} [_inst_1 : TopologicalSpace.{u2} \u03b1] [_inst_2 : UniformSpace.{u3} \u03b2] {\u03b9 : Type.{u1}} {pi : \u03b9 -> Prop} {s : \u03b9 -> (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2))}, (Filter.HasBasis.{u3, succ u1} (Prod.{u3, u3} \u03b2 \u03b2) \u03b9 (uniformity.{u3} \u03b2 _inst_2) pi s) -> (Filter.HasBasis.{max u2 u3, max (succ u2) (succ u1)} (Prod.{max u3 u2, max u3 u2} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2))) (Prod.{u2, u1} (Set.{u2} \u03b1) \u03b9) (uniformity.{max u3 u2} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u2, u3} \u03b1 \u03b2 _inst_1 _inst_2)) (fun (p : Prod.{u2, u1} (Set.{u2} \u03b1) \u03b9) => And (IsCompact.{u2} \u03b1 _inst_1 (Prod.fst.{u2, u1} (Set.{u2} \u03b1) \u03b9 p)) (pi (Prod.snd.{u2, u1} (Set.{u2} \u03b1) \u03b9 p))) (fun (p : Prod.{u2, u1} (Set.{u2} \u03b1) \u03b9) => setOf.{max u2 u3} (Prod.{max u3 u2, max u3 u2} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2))) (fun (fg : Prod.{max u3 u2, max u3 u2} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2))) => forall (x : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x (Prod.fst.{u2, u1} (Set.{u2} \u03b1) \u03b9 p)) -> (Membership.mem.{u3, u3} (Prod.{u3, u3} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x)) (Set.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Set.instMembershipSet.{u3} (Prod.{u3, u3} \u03b2 \u03b2)) (Prod.mk.{u3, u3} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u2) (succ u3), succ u2, succ u3} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u2 u3, u2, u3} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2))) (Prod.fst.{max u2 u3, max u2 u3} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) fg) x) (FunLike.coe.{max (succ u2) (succ u3), succ u2, succ u3} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u2 u3, u2, u3} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2))) (Prod.snd.{max u2 u3, max u2 u3} (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) (ContinuousMap.{u2, u3} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u3} \u03b2 _inst_2)) fg) x)) (s (Prod.snd.{u2, u1} (Set.{u2} \u03b1) \u03b9 p))))))\nCase conversion may be inaccurate. Consider using '#align filter.has_basis.compact_convergence_uniformity Filter.HasBasis.compactConvergenceUniformity\u2093'. -/\ntheorem Filter.HasBasis.compactConvergenceUniformity {\u03b9 : Type _} {pi : \u03b9 \u2192 Prop}\n    {s : \u03b9 \u2192 Set (\u03b2 \u00d7 \u03b2)} (h : (\ud835\udce4 \u03b2).HasBasis pi s) :\n    HasBasis (\ud835\udce4 C(\u03b1, \u03b2)) (fun p : Set \u03b1 \u00d7 \u03b9 => IsCompact p.1 \u2227 pi p.2) fun p =>\n      { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 p.1, (fg.1 x, fg.2 x) \u2208 s p.2 } :=\n  by\n  refine' has_basis_compact_convergence_uniformity.to_has_basis _ _\n  \u00b7 rintro \u27e8t\u2081, t\u2082\u27e9 \u27e8h\u2081, h\u2082\u27e9\n    rcases h.mem_iff.1 h\u2082 with \u27e8i, hpi, hi\u27e9\n    exact \u27e8(t\u2081, i), \u27e8h\u2081, hpi\u27e9, fun fg hfg x hx => hi (hfg _ hx)\u27e9\n  \u00b7 rintro \u27e8t, i\u27e9 \u27e8ht, hi\u27e9\n    exact \u27e8(t, s i), \u27e8ht, h.mem_of_mem hi\u27e9, subset.rfl\u27e9\n#align filter.has_basis.compact_convergence_uniformity Filter.HasBasis.compactConvergenceUniformity\n\nvariable {\u03b9 : Type u\u2083} {p : Filter \u03b9} {F : \u03b9 \u2192 C(\u03b1, \u03b2)} {f}\n\n/- warning: continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on -> ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) (forall (K : Set.{u1} \u03b1), (IsCompact.{u1} \u03b1 _inst_1 K) -> (TendstoUniformlyOn.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 (fun (i : \u03b9) (a : \u03b1) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (F i) a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f) p K))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) (forall (K : Set.{u1} \u03b1), (IsCompact.{u1} \u03b1 _inst_1 K) -> (TendstoUniformlyOn.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 (fun (i : \u03b9) (a : \u03b1) => FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (F i) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f) p K))\nCase conversion may be inaccurate. Consider using '#align continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn\u2093'. -/\ntheorem tendsto_iff_forall_compact_tendstoUniformlyOn :\n    Tendsto F p (\ud835\udcdd f) \u2194 \u2200 K, IsCompact K \u2192 TendstoUniformlyOn (fun i a => F i a) f p K := by\n  rw [compact_open_eq_compact_convergence, tendsto_iff_forall_compact_tendsto_uniformly_on']\n#align continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn\n\n/- warning: continuous_map.tendsto_of_tendsto_locally_uniformly -> ContinuousMap.tendsto_of_tendstoLocallyUniformly is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, (TendstoLocallyUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 _inst_1 (fun (i : \u03b9) (a : \u03b1) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (F i) a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f) p) -> (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, (TendstoLocallyUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 _inst_1 (fun (i : \u03b9) (a : \u03b1) => FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (F i) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f) p) -> (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f))\nCase conversion may be inaccurate. Consider using '#align continuous_map.tendsto_of_tendsto_locally_uniformly ContinuousMap.tendsto_of_tendstoLocallyUniformly\u2093'. -/\n/-- Locally uniform convergence implies convergence in the compact-open topology. -/\ntheorem tendsto_of_tendstoLocallyUniformly (h : TendstoLocallyUniformly (fun i a => F i a) f p) :\n    Tendsto F p (\ud835\udcdd f) :=\n  by\n  rw [tendsto_iff_forall_compact_tendsto_uniformly_on]\n  intro K hK\n  rw [\u2190 tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK]\n  exact h.tendsto_locally_uniformly_on\n#align continuous_map.tendsto_of_tendsto_locally_uniformly ContinuousMap.tendsto_of_tendstoLocallyUniformly\n\n/- warning: continuous_map.tendsto_locally_uniformly_of_tendsto -> ContinuousMap.tendstoLocallyUniformly_of_tendsto is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, (forall (x : \u03b1), Exists.{succ u1} (Set.{u1} \u03b1) (fun (n : Set.{u1} \u03b1) => And (IsCompact.{u1} \u03b1 _inst_1 n) (Membership.Mem.{u1, u1} (Set.{u1} \u03b1) (Filter.{u1} \u03b1) (Filter.hasMem.{u1} \u03b1) n (nhds.{u1} \u03b1 _inst_1 x)))) -> (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) -> (TendstoLocallyUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 _inst_1 (fun (i : \u03b9) (a : \u03b1) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (F i) a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f) p)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))}, (forall (x : \u03b1), Exists.{succ u1} (Set.{u1} \u03b1) (fun (n : Set.{u1} \u03b1) => And (IsCompact.{u1} \u03b1 _inst_1 n) (Membership.mem.{u1, u1} (Set.{u1} \u03b1) (Filter.{u1} \u03b1) (instMembershipSetFilter.{u1} \u03b1) n (nhds.{u1} \u03b1 _inst_1 x)))) -> (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) -> (TendstoLocallyUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 _inst_1 (fun (i : \u03b9) (a : \u03b1) => FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (F i) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f) p)\nCase conversion may be inaccurate. Consider using '#align continuous_map.tendsto_locally_uniformly_of_tendsto ContinuousMap.tendstoLocallyUniformly_of_tendsto\u2093'. -/\n/-- If every point has a compact neighbourhood, then convergence in the compact-open topology\nimplies locally uniform convergence.\n\nSee also `tendsto_iff_tendsto_locally_uniformly`, especially for T2 spaces. -/\ntheorem tendstoLocallyUniformly_of_tendsto (h\u03b1 : \u2200 x : \u03b1, \u2203 n, IsCompact n \u2227 n \u2208 \ud835\udcdd x)\n    (h : Tendsto F p (\ud835\udcdd f)) : TendstoLocallyUniformly (fun i a => F i a) f p :=\n  by\n  rw [tendsto_iff_forall_compact_tendsto_uniformly_on] at h\n  intro V hV x\n  obtain \u27e8n, hn\u2081, hn\u2082\u27e9 := h\u03b1 x\n  exact \u27e8n, hn\u2082, h n hn\u2081 V hV\u27e9\n#align continuous_map.tendsto_locally_uniformly_of_tendsto ContinuousMap.tendstoLocallyUniformly_of_tendsto\n\n/- warning: continuous_map.tendsto_iff_tendsto_locally_uniformly -> ContinuousMap.tendsto_iff_tendstoLocallyUniformly is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))} [_inst_3 : LocallyCompactSpace.{u1} \u03b1 _inst_1], Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) (TendstoLocallyUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 _inst_1 (fun (i : \u03b9) (a : \u03b1) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (F i) a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f) p)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))} [_inst_3 : LocallyCompactSpace.{u1} \u03b1 _inst_1], Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) (TendstoLocallyUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 _inst_1 (fun (i : \u03b9) (a : \u03b1) => FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (F i) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f) p)\nCase conversion may be inaccurate. Consider using '#align continuous_map.tendsto_iff_tendsto_locally_uniformly ContinuousMap.tendsto_iff_tendstoLocallyUniformly\u2093'. -/\n/-- Convergence in the compact-open topology is the same as locally uniform convergence on a locally\ncompact space.\n\nFor non-T2 spaces, the assumption `locally_compact_space \u03b1` is stronger than we need and in fact\nthe `\u2190` direction is true unconditionally. See `tendsto_locally_uniformly_of_tendsto` and\n`tendsto_of_tendsto_locally_uniformly` for versions requiring weaker hypotheses. -/\ntheorem tendsto_iff_tendstoLocallyUniformly [LocallyCompactSpace \u03b1] :\n    Tendsto F p (\ud835\udcdd f) \u2194 TendstoLocallyUniformly (fun i a => F i a) f p :=\n  \u27e8tendstoLocallyUniformly_of_tendsto exists_compact_mem_nhds, tendsto_of_tendstoLocallyUniformly\u27e9\n#align continuous_map.tendsto_iff_tendsto_locally_uniformly ContinuousMap.tendsto_iff_tendstoLocallyUniformly\n\nsection CompactDomain\n\nvariable [CompactSpace \u03b1]\n\n/- warning: continuous_map.has_basis_compact_convergence_uniformity_of_compact -> ContinuousMap.hasBasis_compactConvergenceUniformity_of_compact is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] [_inst_3 : CompactSpace.{u1} \u03b1 _inst_1], Filter.HasBasis.{max u1 u2, succ u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (uniformity.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Membership.Mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => setOf.{max u1 u2} (Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), Membership.Mem.{u2, u2} (Prod.{u2, u2} \u03b2 \u03b2) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.hasMem.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} \u03b2 \u03b2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) V))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] [_inst_3 : CompactSpace.{u1} \u03b1 _inst_1], Filter.HasBasis.{max u1 u2, succ u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (uniformity.{max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactConvergenceUniformSpace.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => Membership.mem.{u2, u2} (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Filter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (instMembershipSetFilter.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) V (uniformity.{u2} \u03b2 _inst_2)) (fun (V : Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) => setOf.{max u1 u2} (Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (fun (fg : Prod.{max u2 u1, max u2 u1} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) => forall (x : \u03b1), Membership.mem.{u2, u2} (Prod.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x)) (Set.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Set.instMembershipSet.{u2} (Prod.{u2, u2} \u03b2 \u03b2)) (Prod.mk.{u2, u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.fst.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (Prod.snd.{max u1 u2, max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) fg) x)) V))\nCase conversion may be inaccurate. Consider using '#align continuous_map.has_basis_compact_convergence_uniformity_of_compact ContinuousMap.hasBasis_compactConvergenceUniformity_of_compact\u2093'. -/\ntheorem hasBasis_compactConvergenceUniformity_of_compact :\n    HasBasis (\ud835\udce4 C(\u03b1, \u03b2)) (fun V : Set (\u03b2 \u00d7 \u03b2) => V \u2208 \ud835\udce4 \u03b2) fun V =>\n      { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x, (fg.1 x, fg.2 x) \u2208 V } :=\n  hasBasis_compactConvergenceUniformity.to_hasBasis\n    (fun p hp => \u27e8p.2, hp.2, fun fg hfg x hx => hfg x\u27e9) fun V hV =>\n    \u27e8\u27e8univ, V\u27e9, \u27e8isCompact_univ, hV\u27e9, fun fg hfg x => hfg x (mem_univ x)\u27e9\n#align continuous_map.has_basis_compact_convergence_uniformity_of_compact ContinuousMap.hasBasis_compactConvergenceUniformity_of_compact\n\n/- warning: continuous_map.tendsto_iff_tendsto_uniformly -> ContinuousMap.tendsto_iff_tendstoUniformly is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))} [_inst_3 : CompactSpace.{u1} \u03b1 _inst_1], Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) (TendstoUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 (fun (i : \u03b9) (a : \u03b1) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (F i) a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (fun (_x : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) => \u03b1 -> \u03b2) (ContinuousMap.hasCoeToFun.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f) p)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_2 : UniformSpace.{u2} \u03b2] {f : ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)} {\u03b9 : Type.{u3}} {p : Filter.{u3} \u03b9} {F : \u03b9 -> (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))} [_inst_3 : CompactSpace.{u1} \u03b1 _inst_1], Iff (Filter.Tendsto.{u3, max u1 u2} \u03b9 (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) F p (nhds.{max u1 u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) (ContinuousMap.compactOpen.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) f)) (TendstoUniformly.{u1, u2, u3} \u03b1 \u03b2 \u03b9 _inst_2 (fun (i : \u03b9) (a : \u03b1) => FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) (F i) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : \u03b1) => \u03b2) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2)) \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2) (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} \u03b1 \u03b2 _inst_1 (UniformSpace.toTopologicalSpace.{u2} \u03b2 _inst_2))) f) p)\nCase conversion may be inaccurate. Consider using '#align continuous_map.tendsto_iff_tendsto_uniformly ContinuousMap.tendsto_iff_tendstoUniformly\u2093'. -/\n/-- Convergence in the compact-open topology is the same as uniform convergence for sequences of\ncontinuous functions on a compact space. -/\ntheorem tendsto_iff_tendstoUniformly :\n    Tendsto F p (\ud835\udcdd f) \u2194 TendstoUniformly (fun i a => F i a) f p :=\n  by\n  rw [tendsto_iff_forall_compact_tendsto_uniformly_on, \u2190 tendstoUniformlyOn_univ]\n  exact \u27e8fun h => h univ isCompact_univ, fun h K hK => h.mono (subset_univ K)\u27e9\n#align continuous_map.tendsto_iff_tendsto_uniformly ContinuousMap.tendsto_iff_tendstoUniformly\n\nend CompactDomain\n\nend ContinuousMap\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/UniformSpace/CompactConvergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7292296372642075}}
{"text": "import .love05_inductive_predicates_demo\nimport .love13_rational_and_real_numbers_demo\n\n\n/-! # LoVe Exercise 13: Rational and Real Numbers -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Rationals\n\n1.1. Prove the following lemma.\n\nHint: The lemma `fraction.mk.inj_eq` might be useful. -/\n\n#check fraction.mk.inj_eq\n\nlemma fraction.ext (a b : fraction) (hnum : fraction.num a = fraction.num b)\n    (hdenom : fraction.denom a = fraction.denom b) :\n  a = b :=\nbegin\n  cases' a,\n  cases' b,\n  rw fraction.mk.inj_eq,\n  exact and.intro hnum hdenom\nend\n\n/-! 1.2. Extending the `fraction.has_mul` instance from the lecture, declare\n`fraction` as an instance of `semigroup`.\n\nHint: Use the lemma `fraction.ext` above, and possibly `fraction.mul_num`, and\n`fraction.mul_denom`. -/\n\n#check fraction.ext\n#check fraction.mul_num\n#check fraction.mul_denom\n\n@[instance] def fraction.semigroup : semigroup fraction :=\n{ mul_assoc :=\n    begin\n      intros,\n      apply fraction.ext,\n      repeat {\n        simp [fraction.mul_num, fraction.mul_denom],\n        cc }\n    end,\n  ..fraction.has_mul }\n\n/-! 1.3. Extending the `rat.has_mul` instance from the lecture, declare `rat` as\nan instance of `semigroup`. -/\n\n@[instance] def rat.semigroup : semigroup rat :=\n{ mul_assoc :=\n    begin\n      intros x y z,\n      apply quotient.induction_on x,\n      apply quotient.induction_on y,\n      apply quotient.induction_on z,\n      intros a b c,\n      apply quotient.sound,\n      rw mul_assoc\n    end,\n  ..rat.has_mul }\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/exercises/love13_rational_and_real_numbers_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7291669737805433}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module analysis.convex.contractible\n! leanprover-community/mathlib commit 3339976e2bcae9f1c81e620836d1eb736e3c4700\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Convex.Star\nimport Mathbin.Topology.Homotopy.Contractible\n\n/-!\n# A convex set is contractible\n\nIn this file we prove that a (star) convex set in a real topological vector space is a contractible\ntopological space.\n-/\n\n\nvariable {E : Type _} [AddCommGroup E] [Module \u211d E] [TopologicalSpace E] [ContinuousAdd E]\n  [ContinuousSMul \u211d E] {s : Set E} {x : E}\n\n/-- A non-empty star convex set is a contractible space. -/\nprotected theorem StarConvex.contractibleSpace (h : StarConvex \u211d x s) (hne : s.Nonempty) :\n    ContractibleSpace s :=\n  by\n  refine'\n    (contractible_iff_id_nullhomotopic _).2\n      \u27e8\u27e8x, h.mem hne\u27e9, \u27e8\u27e8\u27e8fun p => \u27e8p.1.1 \u2022 x + (1 - p.1.1) \u2022 p.2, _\u27e9, _\u27e9, fun x => _, fun x => _\u27e9\u27e9\u27e9\n  \u00b7 exact h p.2.2 p.1.2.1 (sub_nonneg.2 p.1.2.2) (add_sub_cancel'_right _ _)\n  \u00b7\n    exact\n      ((continuous_subtype_val.fst'.smul continuous_const).add\n            ((continuous_const.sub continuous_subtype_val.fst').smul\n              continuous_subtype_val.snd')).subtype_mk\n        _\n  \u00b7 ext1\n    simp\n  \u00b7 ext1\n    simp\n#align star_convex.contractible_space StarConvex.contractibleSpace\n\n/-- A non-empty convex set is a contractible space. -/\nprotected theorem Convex.contractibleSpace (hs : Convex \u211d s) (hne : s.Nonempty) :\n    ContractibleSpace s :=\n  let \u27e8x, hx\u27e9 := hne\n  (hs.StarConvex hx).ContractibleSpace hne\n#align convex.contractible_space Convex.contractibleSpace\n\ninstance (priority := 100) RealTopologicalVectorSpace.contractibleSpace : ContractibleSpace E :=\n  (Homeomorph.Set.univ E).contractibleSpace_iff.mp <|\n    convex_univ.ContractibleSpace Set.univ_nonempty\n#align real_topological_vector_space.contractible_space RealTopologicalVectorSpace.contractibleSpace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/Convex/Contractible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451416, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7291447939440301}}
{"text": "/-\nWe just restarted Lean behind the scenes,\nso let's re-import the natural numbers, but this time without\naddition and multiplication.\n-/\n\nimport mynat.definition -- import Peano's definition of the natural numbers {0,1,2,3,4,...}\nnamespace mynat -- hide\n\n/-\n\n# Tutorial world\n\n## Level 3: Peano's axioms.\n\nThe import above gives us the type `mynat` of natural numbers. But it\nalso gives us some other things, which we'll take a look at now:\n\n  * a term `0 : mynat`, interpreted as the number zero.\n  * a function `succ : mynat \u2192 mynat`, with `succ n` interpreted as \"the number after $n$\".\n  * The principle of mathematical induction.\n\nThese axioms are essentially the axioms isolated by Peano which uniquely characterise\nthe natural numbers (we also need recursion, but we can ignore it for now).\nThe first axiom says that $0$ is a natural number. The second says that there\nis a `succ` function which eats a number and spits out the number after it,\nso $\\operatorname{succ}(0)=1$, $\\operatorname{succ}(1)=2$ and so on.\n\nPeano's last axiom is the principle of mathematical induction. This is a deeper\nfact. It says that if we have infinitely many true/false statements $P(0)$, $P(1)$,\n$P(2)$ and so on, and if $P(0)$ is true, and if for every natural number $d$\nwe know that $P(d)$ implies $P(\\operatorname{succ}(d))$, then $P(n)$ must be true for every\nnatural number $n$. It's like saying that if you have a long line of dominoes, and if\nyou knock the first one down, and if you know that if a domino falls down then the one\nafter it will fall down too, then you can deduce that all the dominos will fall down.\nOne can also think of it as saying that every natural number\ncan be built by starting at `0` and then applying `succ` a finite number of times.\n\nPeano's insights were firstly that these axioms completely characterise\nthe natural numbers, and secondly that these axioms alone can be used to build\na whole bunch of other structure on the natural numbers, for example\naddition, multiplication and so on.\n\nThis game is all about seeing how far these axioms of Peano can take us.\n\nLet's practice our use of the `rw` tactic in the following example.\nOur hypothesis `h` is a proof that `succ(a) = b` and we want to prove that\n`succ(succ(a))=succ(b)`. In words, we're going to prove that if\n`b` is the number after `a` then `succ(b)` is the number after `succ(a)`. \nNow here's a tricky question. If our goal is `\u22a2 succ (succ a) = succ b`,\nand our hypothesis is `h : succ a = b`, then what will the goal change\nto when we type\n\n`rw h,`\n\nand hit enter whilst not forgetting the comma? Remember that `rw h` will\nlook for the *left* hand side of `h` in the goal, and will replace it with\nthe *right* hand side. Try and figure out how the goal will change, and\nthen try it.\n\nThe answer: Lean changed `succ a` into `b`, so the goal became `succ b = succ b`.\nThat goal is of the form `X = X`, so you can prove this new goal with\n\n`refl,`\n\non the line after `rw h,`. Don't forget the commas!\n\n**Important note** : the tactic `rw` expects\na proof afterwards (e.g. `rw h1`). But `refl` is just `refl`.\nNote also that the system sometimes drops brackets when they're not\nnecessary, and `succ b` just means `succ(b)`. \n\nYou may be wondering whether we could have just substituted in the definition of `b`\nand proved the goal that way. To do that, we would want to replace the right hand\nside of `h` with the left hand side. You do this in Lean by writing `rw \u2190 h`. You get the\nleft-arrow by typing `\\l` and then a space; note that this is a small letter L,\nnot a number 1. You can just edit your proof and try it. \n\nYou may also be wondering why we keep writing `succ(b)` instead of `b+1`. This\nis because we haven't defined addition yet! On the next level, the final level\nof Tutorial World, we will introduce addition, and then\nwe'll be ready to enter Addition World.\n-/\n\n/- Lemma : no-side-bar\nIf $\\operatorname{succ}(a) = b$, then\n$$\\operatorname{succ}(\\operatorname{succ}(a)) = \\operatorname{succ}(b).$$\n-/\nlemma example3 (a b : mynat) (h : succ a = b) : succ(succ(a)) = succ(b) :=\nbegin [nat_num_game]\n  rw h,\n  refl,\n\n\n\nend\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world1/level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7291219510574004}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n\n! This file was ported from Lean 3 source module number_theory.legendre_symbol.jacobi_symbol\n! leanprover-community/mathlib commit 8631e2d5ea77f6c13054d9151d82b83069680cb1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.NumberTheory.LegendreSymbol.QuadraticReciprocity\n\n/-!\n# The Jacobi Symbol\n\nWe define the Jacobi symbol and prove its main properties.\n\n## Main definitions\n\nWe define the Jacobi symbol, `jacobi_sym a b`, for integers `a` and natural numbers `b`\nas the product over the prime factors `p` of `b` of the Legendre symbols `legendre_sym p a`.\nThis agrees with the mathematical definition when `b` is odd.\n\nThe prime factors are obtained via `nat.factors`. Since `nat.factors 0 = []`,\nthis implies in particular that `jacobi_sym a 0 = 1` for all `a`.\n\n## Main statements\n\nWe prove the main properties of the Jacobi symbol, including the following.\n\n* Multiplicativity in both arguments (`jacobi_sym.mul_left`, `jacobi_sym.mul_right`)\n\n* The value of the symbol is `1` or `-1` when the arguments are coprime\n  (`jacobi_sym.eq_one_or_neg_one`)\n\n* The symbol vanishes if and only if `b \u2260 0` and the arguments are not coprime\n  (`jacobi_sym.eq_zero_iff`)\n\n* If the symbol has the value `-1`, then `a : zmod b` is not a square\n  (`zmod.nonsquare_of_jacobi_sym_eq_neg_one`); the converse holds when `b = p` is a prime\n  (`zmod.nonsquare_iff_jacobi_sym_eq_neg_one`); in particular, in this case `a` is a\n  square mod `p` when the symbol has the value `1` (`zmod.is_square_of_jacobi_sym_eq_one`).\n\n* Quadratic reciprocity (`jacobi_sym.quadratic_reciprocity`,\n  `jacobi_sym.quadratic_reciprocity_one_mod_four`,\n  `jacobi_sym.quadratic_reciprocity_three_mod_four`)\n\n* The supplementary laws for `a = -1`, `a = 2`, `a = -2` (`jacobi_sym.at_neg_one`,\n  `jacobi_sym.at_two`, `jacobi_sym.at_neg_two`)\n\n* The symbol depends on `a` only via its residue class mod `b` (`jacobi_sym.mod_left`)\n  and on `b` only via its residue class mod `4*a` (`jacobi_sym.mod_right`)\n\n## Notations\n\nWe define the notation `J(a | b)` for `jacobi_sym a b`, localized to `number_theory_symbols`.\n\n## Tags\nJacobi symbol, quadratic reciprocity\n-/\n\n\nsection Jacobi\n\n/-!\n### Definition of the Jacobi symbol\n\nWe define the Jacobi symbol $\\Bigl(\\frac{a}{b}\\Bigr)$ for integers `a` and natural numbers `b`\nas the product of the Legendre symbols $\\Bigl(\\frac{a}{p}\\Bigr)$, where `p` runs through the\nprime divisors (with multiplicity) of `b`, as provided by `b.factors`. This agrees with the\nJacobi symbol when `b` is odd and gives less meaningful values when it is not (e.g., the symbol\nis `1` when `b = 0`). This is called `jacobi_sym a b`.\n\nWe define localized notation (locale `number_theory_symbols`) `J(a | b)` for the Jacobi\nsymbol `jacobi_sym a b`.\n-/\n\n\nopen Nat ZMod\n\n-- Since we need the fact that the factors are prime, we use `list.pmap`.\n/-- The Jacobi symbol of `a` and `b` -/\ndef jacobiSym (a : \u2124) (b : \u2115) : \u2124 :=\n  (b.factors.pmap (fun p pp => @legendreSym p \u27e8pp\u27e9 a) fun p pf => prime_of_mem_factors pf).Prod\n#align jacobi_sym jacobiSym\n\n-- mathport name: \u00abexprJ( | )\u00bb\n-- Notation for the Jacobi symbol.\nscoped[NumberTheorySymbols] notation \"J(\" a \" | \" b \")\" => jacobiSym a b\n\n/-!\n### Properties of the Jacobi symbol\n-/\n\n\nnamespace jacobiSym\n\n/-- The symbol `J(a | 0)` has the value `1`. -/\n@[simp]\ntheorem zero_right (a : \u2124) : J(a | 0) = 1 := by\n  simp only [jacobiSym, factors_zero, List.prod_nil, List.pmap]\n#align jacobi_sym.zero_right jacobiSym.zero_right\n\n/-- The symbol `J(a | 1)` has the value `1`. -/\n@[simp]\ntheorem one_right (a : \u2124) : J(a | 1) = 1 := by\n  simp only [jacobiSym, factors_one, List.prod_nil, List.pmap]\n#align jacobi_sym.one_right jacobiSym.one_right\n\n/-- The Legendre symbol `legendre_sym p a` with an integer `a` and a prime number `p`\nis the same as the Jacobi symbol `J(a | p)`. -/\ntheorem legendreSym.to_jacobiSym (p : \u2115) [fp : Fact p.Prime] (a : \u2124) : legendreSym p a = J(a | p) :=\n  by simp only [jacobiSym, factors_prime fp.1, List.prod_cons, List.prod_nil, mul_one, List.pmap]\n#align legendre_sym.to_jacobi_sym legendreSym.to_jacobiSym\n\n/-- The Jacobi symbol is multiplicative in its second argument. -/\ntheorem mul_right' (a : \u2124) {b\u2081 b\u2082 : \u2115} (hb\u2081 : b\u2081 \u2260 0) (hb\u2082 : b\u2082 \u2260 0) :\n    J(a | b\u2081 * b\u2082) = J(a | b\u2081) * J(a | b\u2082) :=\n  by\n  rw [jacobiSym, ((perm_factors_mul hb\u2081 hb\u2082).pmap _).prod_eq, List.pmap_append, List.prod_append]\n  exacts[rfl, fun p hp => (list.mem_append.mp hp).elim prime_of_mem_factors prime_of_mem_factors]\n#align jacobi_sym.mul_right' jacobiSym.mul_right'\n\n/-- The Jacobi symbol is multiplicative in its second argument. -/\ntheorem mul_right (a : \u2124) (b\u2081 b\u2082 : \u2115) [NeZero b\u2081] [NeZero b\u2082] :\n    J(a | b\u2081 * b\u2082) = J(a | b\u2081) * J(a | b\u2082) :=\n  mul_right' a (NeZero.ne b\u2081) (NeZero.ne b\u2082)\n#align jacobi_sym.mul_right jacobiSym.mul_right\n\n/-- The Jacobi symbol takes only the values `0`, `1` and `-1`. -/\ntheorem trichotomy (a : \u2124) (b : \u2115) : J(a | b) = 0 \u2228 J(a | b) = 1 \u2228 J(a | b) = -1 :=\n  ((@SignType.castHom \u2124 _ _).toMonoidHom.mrange.copy {0, 1, -1} <|\n        by\n        rw [Set.pair_comm]\n        exact (SignType.range_eq SignType.castHom).symm).list_prod_mem\n    (by\n      intro _ ha'\n      rcases list.mem_pmap.mp ha' with \u27e8p, hp, rfl\u27e9\n      haveI : Fact p.prime := \u27e8prime_of_mem_factors hp\u27e9\n      exact quadraticChar_isQuadratic (ZMod p) a)\n#align jacobi_sym.trichotomy jacobiSym.trichotomy\n\n/-- The symbol `J(1 | b)` has the value `1`. -/\n@[simp]\ntheorem one_left (b : \u2115) : J(1 | b) = 1 :=\n  List.prod_eq_one fun z hz => by\n    let \u27e8p, hp, he\u27e9 := List.mem_pmap.1 hz\n    rw [\u2190 he, legendreSym.at_one]\n#align jacobi_sym.one_left jacobiSym.one_left\n\n/-- The Jacobi symbol is multiplicative in its first argument. -/\ntheorem mul_left (a\u2081 a\u2082 : \u2124) (b : \u2115) : J(a\u2081 * a\u2082 | b) = J(a\u2081 | b) * J(a\u2082 | b) :=\n  by\n  simp_rw [jacobiSym, List.pmap_eq_map_attach, legendreSym.mul]\n  exact List.prod_map_mul\n#align jacobi_sym.mul_left jacobiSym.mul_left\n\n/-- The symbol `J(a | b)` vanishes iff `a` and `b` are not coprime (assuming `b \u2260 0`). -/\ntheorem eq_zero_iff_not_coprime {a : \u2124} {b : \u2115} [NeZero b] : J(a | b) = 0 \u2194 a.gcd b \u2260 1 :=\n  List.prod_eq_zero_iff.trans\n    (by\n      rw [List.mem_pmap, Int.gcd_eq_natAbs, Ne, prime.not_coprime_iff_dvd]\n      simp_rw [legendreSym.eq_zero_iff, int_coe_zmod_eq_zero_iff_dvd, mem_factors (NeZero.ne b), \u2190\n        Int.coe_nat_dvd_left, Int.coe_nat_dvd, exists_prop, and_assoc', and_comm'])\n#align jacobi_sym.eq_zero_iff_not_coprime jacobiSym.eq_zero_iff_not_coprime\n\n/-- The symbol `J(a | b)` is nonzero when `a` and `b` are coprime. -/\nprotected theorem ne_zero {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a | b) \u2260 0 :=\n  by\n  cases' eq_zero_or_neZero b with hb\n  \u00b7 rw [hb, zero_right]\n    exact one_ne_zero\n  \u00b7 contrapose! h\n    exact eq_zero_iff_not_coprime.1 h\n#align jacobi_sym.ne_zero jacobiSym.ne_zero\n\n/-- The symbol `J(a | b)` vanishes if and only if `b \u2260 0` and `a` and `b` are not coprime. -/\ntheorem eq_zero_iff {a : \u2124} {b : \u2115} : J(a | b) = 0 \u2194 b \u2260 0 \u2227 a.gcd b \u2260 1 :=\n  \u27e8fun h => by\n    cases' eq_or_ne b 0 with hb hb\n    \u00b7 rw [hb, zero_right] at h\n      cases h\n    exact \u27e8hb, mt jacobiSym.ne_zero <| Classical.not_not.2 h\u27e9, fun \u27e8hb, h\u27e9 =>\n    by\n    rw [\u2190 neZero_iff] at hb\n    exact eq_zero_iff_not_coprime.2 h\u27e9\n#align jacobi_sym.eq_zero_iff jacobiSym.eq_zero_iff\n\n/-- The symbol `J(0 | b)` vanishes when `b > 1`. -/\ntheorem zero_left {b : \u2115} (hb : 1 < b) : J(0 | b) = 0 :=\n  (@eq_zero_iff_not_coprime 0 b \u27e8ne_zero_of_lt hb\u27e9).mpr <|\n    by\n    rw [Int.gcd_zero_left, Int.natAbs_ofNat]\n    exact hb.ne'\n#align jacobi_sym.zero_left jacobiSym.zero_left\n\n/-- The symbol `J(a | b)` takes the value `1` or `-1` if `a` and `b` are coprime. -/\ntheorem eq_one_or_neg_one {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a | b) = 1 \u2228 J(a | b) = -1 :=\n  (trichotomy a b).resolve_left <| jacobiSym.ne_zero h\n#align jacobi_sym.eq_one_or_neg_one jacobiSym.eq_one_or_neg_one\n\n/-- We have that `J(a^e | b) = J(a | b)^e`. -/\ntheorem pow_left (a : \u2124) (e b : \u2115) : J(a ^ e | b) = J(a | b) ^ e :=\n  Nat.recOn e (by rw [pow_zero, pow_zero, one_left]) fun _ ih => by\n    rw [pow_succ, pow_succ, mul_left, ih]\n#align jacobi_sym.pow_left jacobiSym.pow_left\n\n/-- We have that `J(a | b^e) = J(a | b)^e`. -/\ntheorem pow_right (a : \u2124) (b e : \u2115) : J(a | b ^ e) = J(a | b) ^ e :=\n  by\n  induction' e with e ih\n  \u00b7 rw [pow_zero, pow_zero, one_right]\n  \u00b7 cases' eq_zero_or_neZero b with hb\n    \u00b7 rw [hb, zero_pow (succ_pos e), zero_right, one_pow]\n    \u00b7 rw [pow_succ, pow_succ, mul_right, ih]\n#align jacobi_sym.pow_right jacobiSym.pow_right\n\n/-- The square of `J(a | b)` is `1` when `a` and `b` are coprime. -/\ntheorem sq_one {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a | b) ^ 2 = 1 := by\n  cases' eq_one_or_neg_one h with h\u2081 h\u2081 <;> rw [h\u2081] <;> rfl\n#align jacobi_sym.sq_one jacobiSym.sq_one\n\n/-- The symbol `J(a^2 | b)` is `1` when `a` and `b` are coprime. -/\ntheorem sq_one' {a : \u2124} {b : \u2115} (h : a.gcd b = 1) : J(a ^ 2 | b) = 1 := by rw [pow_left, sq_one h]\n#align jacobi_sym.sq_one' jacobiSym.sq_one'\n\n/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/\ntheorem mod_left (a : \u2124) (b : \u2115) : J(a | b) = J(a % b | b) :=\n  congr_arg List.prod <|\n    List.pmap_congr _\n      (by\n        rintro p hp _ _\n        conv_rhs =>\n          rw [legendreSym.mod, Int.emod_emod_of_dvd _ (Int.coe_nat_dvd.2 <| dvd_of_mem_factors hp),\n            \u2190 legendreSym.mod])\n#align jacobi_sym.mod_left jacobiSym.mod_left\n\n/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/\ntheorem mod_left' {a\u2081 a\u2082 : \u2124} {b : \u2115} (h : a\u2081 % b = a\u2082 % b) : J(a\u2081 | b) = J(a\u2082 | b) := by\n  rw [mod_left, h, \u2190 mod_left]\n#align jacobi_sym.mod_left' jacobiSym.mod_left'\n\nend jacobiSym\n\nnamespace ZMod\n\nopen jacobiSym\n\n/-- If `J(a | b)` is `-1`, then `a` is not a square modulo `b`. -/\ntheorem nonsquare_of_jacobiSym_eq_neg_one {a : \u2124} {b : \u2115} (h : J(a | b) = -1) :\n    \u00acIsSquare (a : ZMod b) := fun \u27e8r, ha\u27e9 =>\n  by\n  rw [\u2190 r.coe_val_min_abs, \u2190 Int.cast_mul, int_coe_eq_int_coe_iff', \u2190 sq] at ha\n  apply (by norm_num : \u00ac(0 : \u2124) \u2264 -1)\n  rw [\u2190 h, mod_left, ha, \u2190 mod_left, pow_left]\n  apply sq_nonneg\n#align zmod.nonsquare_of_jacobi_sym_eq_neg_one ZMod.nonsquare_of_jacobiSym_eq_neg_one\n\n/-- If `p` is prime, then `J(a | p)` is `-1` iff `a` is not a square modulo `p`. -/\ntheorem nonsquare_iff_jacobiSym_eq_neg_one {a : \u2124} {p : \u2115} [Fact p.Prime] :\n    J(a | p) = -1 \u2194 \u00acIsSquare (a : ZMod p) :=\n  by\n  rw [\u2190 legendreSym.to_jacobiSym]\n  exact legendreSym.eq_neg_one_iff p\n#align zmod.nonsquare_iff_jacobi_sym_eq_neg_one ZMod.nonsquare_iff_jacobiSym_eq_neg_one\n\n/-- If `p` is prime and `J(a | p) = 1`, then `a` is q square mod `p`. -/\ntheorem isSquare_of_jacobiSym_eq_one {a : \u2124} {p : \u2115} [Fact p.Prime] (h : J(a | p) = 1) :\n    IsSquare (a : ZMod p) :=\n  Classical.not_not.mp <| by\n    rw [\u2190 nonsquare_iff_jacobi_sym_eq_neg_one, h]\n    decide\n#align zmod.is_square_of_jacobi_sym_eq_one ZMod.isSquare_of_jacobiSym_eq_one\n\nend ZMod\n\n/-!\n### Values at `-1`, `2` and `-2`\n-/\n\n\nnamespace jacobiSym\n\n/-- If `\u03c7` is a multiplicative function such that `J(a | p) = \u03c7 p` for all odd primes `p`,\nthen `J(a | b)` equals `\u03c7 b` for all odd natural numbers `b`. -/\ntheorem value_at (a : \u2124) {R : Type _} [CommSemiring R] (\u03c7 : R \u2192* \u2124)\n    (hp : \u2200 (p : \u2115) (pp : p.Prime) (h2 : p \u2260 2), @legendreSym p \u27e8pp\u27e9 a = \u03c7 p) {b : \u2115} (hb : Odd b) :\n    J(a | b) = \u03c7 b :=\n  by\n  conv_rhs => rw [\u2190 prod_factors hb.pos.ne', cast_list_prod, \u03c7.map_list_prod]\n  rw [jacobiSym, List.map_map, \u2190 List.pmap_eq_map Nat.Prime _ _ fun _ => prime_of_mem_factors]\n  congr 1; apply List.pmap_congr\n  exact fun p h pp _ => hp p pp (hb.ne_two_of_dvd_nat <| dvd_of_mem_factors h)\n#align jacobi_sym.value_at jacobiSym.value_at\n\n/-- If `b` is odd, then `J(-1 | b)` is given by `\u03c7\u2084 b`. -/\ntheorem at_neg_one {b : \u2115} (hb : Odd b) : J(-1 | b) = \u03c7\u2084 b :=\n  value_at (-1) \u03c7\u2084 (fun p pp => @legendreSym.at_neg_one p \u27e8pp\u27e9) hb\n#align jacobi_sym.at_neg_one jacobiSym.at_neg_one\n\n/-- If `b` is odd, then `J(-a | b) = \u03c7\u2084 b * J(a | b)`. -/\nprotected theorem neg (a : \u2124) {b : \u2115} (hb : Odd b) : J(-a | b) = \u03c7\u2084 b * J(a | b) := by\n  rw [neg_eq_neg_one_mul, mul_left, at_neg_one hb]\n#align jacobi_sym.neg jacobiSym.neg\n\n/-- If `b` is odd, then `J(2 | b)` is given by `\u03c7\u2088 b`. -/\ntheorem at_two {b : \u2115} (hb : Odd b) : J(2 | b) = \u03c7\u2088 b :=\n  value_at 2 \u03c7\u2088 (fun p pp => @legendreSym.at_two p \u27e8pp\u27e9) hb\n#align jacobi_sym.at_two jacobiSym.at_two\n\n/-- If `b` is odd, then `J(-2 | b)` is given by `\u03c7\u2088' b`. -/\ntheorem at_neg_two {b : \u2115} (hb : Odd b) : J(-2 | b) = \u03c7\u2088' b :=\n  value_at (-2) \u03c7\u2088' (fun p pp => @legendreSym.at_neg_two p \u27e8pp\u27e9) hb\n#align jacobi_sym.at_neg_two jacobiSym.at_neg_two\n\nend jacobiSym\n\n/-!\n### Quadratic Reciprocity\n-/\n\n\n/-- The bi-multiplicative map giving the sign in the Law of Quadratic Reciprocity -/\ndef qrSign (m n : \u2115) : \u2124 :=\n  J(\u03c7\u2084 m | n)\n#align qr_sign qrSign\n\nnamespace qrSign\n\n/-- We can express `qr_sign m n` as a power of `-1` when `m` and `n` are odd. -/\ntheorem neg_one_pow {m n : \u2115} (hm : Odd m) (hn : Odd n) : qrSign m n = (-1) ^ (m / 2 * (n / 2)) :=\n  by\n  rw [qrSign, pow_mul, \u2190 \u03c7\u2084_eq_neg_one_pow (odd_iff.mp hm)]\n  cases' odd_mod_four_iff.mp (odd_iff.mp hm) with h h\n  \u00b7 rw [\u03c7\u2084_nat_one_mod_four h, jacobiSym.one_left, one_pow]\n  \u00b7 rw [\u03c7\u2084_nat_three_mod_four h, \u2190 \u03c7\u2084_eq_neg_one_pow (odd_iff.mp hn), jacobiSym.at_neg_one hn]\n#align qr_sign.neg_one_pow qrSign.neg_one_pow\n\n/-- When `m` and `n` are odd, then the square of `qr_sign m n` is `1`. -/\ntheorem sq_eq_one {m n : \u2115} (hm : Odd m) (hn : Odd n) : qrSign m n ^ 2 = 1 := by\n  rw [neg_one_pow hm hn, \u2190 pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]\n#align qr_sign.sq_eq_one qrSign.sq_eq_one\n\n/-- `qr_sign` is multiplicative in the first argument. -/\ntheorem mul_left (m\u2081 m\u2082 n : \u2115) : qrSign (m\u2081 * m\u2082) n = qrSign m\u2081 n * qrSign m\u2082 n := by\n  simp_rw [qrSign, Nat.cast_mul, map_mul, jacobiSym.mul_left]\n#align qr_sign.mul_left qrSign.mul_left\n\n/-- `qr_sign` is multiplicative in the second argument. -/\ntheorem mul_right (m n\u2081 n\u2082 : \u2115) [NeZero n\u2081] [NeZero n\u2082] :\n    qrSign m (n\u2081 * n\u2082) = qrSign m n\u2081 * qrSign m n\u2082 :=\n  jacobiSym.mul_right (\u03c7\u2084 m) n\u2081 n\u2082\n#align qr_sign.mul_right qrSign.mul_right\n\n/-- `qr_sign` is symmetric when both arguments are odd. -/\nprotected theorem symm {m n : \u2115} (hm : Odd m) (hn : Odd n) : qrSign m n = qrSign n m := by\n  rw [neg_one_pow hm hn, neg_one_pow hn hm, mul_comm (m / 2)]\n#align qr_sign.symm qrSign.symm\n\n/-- We can move `qr_sign m n` from one side of an equality to the other when `m` and `n` are odd. -/\ntheorem eq_iff_eq {m n : \u2115} (hm : Odd m) (hn : Odd n) (x y : \u2124) :\n    qrSign m n * x = y \u2194 x = qrSign m n * y := by\n  refine'\n      \u27e8fun h' =>\n        let h := h'.symm\n        _,\n        fun h => _\u27e9 <;>\n    rw [h, \u2190 mul_assoc, \u2190 pow_two, sq_eq_one hm hn, one_mul]\n#align qr_sign.eq_iff_eq qrSign.eq_iff_eq\n\nend qrSign\n\nnamespace jacobiSym\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol, version with `qr_sign` -/\ntheorem quadratic_reciprocity' {a b : \u2115} (ha : Odd a) (hb : Odd b) :\n    J(a | b) = qrSign b a * J(b | a) :=\n  by\n  -- define the right hand side for fixed `a` as a `\u2115 \u2192* \u2124`\n  let rhs : \u2115 \u2192 \u2115 \u2192* \u2124 := fun a =>\n    { toFun := fun x => qrSign x a * J(x | a)\n      map_one' := by\n        convert\u2190 mul_one _\n        symm\n        all_goals apply one_left\n      map_mul' := fun x y => by rw [qrSign.mul_left, Nat.cast_mul, mul_left, mul_mul_mul_comm] }\n  have rhs_apply : \u2200 a b : \u2115, rhs a b = qrSign b a * J(b | a) := fun a b => rfl\n  refine' value_at a (rhs a) (fun p pp hp => Eq.symm _) hb\n  have hpo := pp.eq_two_or_odd'.resolve_left hp\n  rw [@legendreSym.to_jacobiSym p \u27e8pp\u27e9, rhs_apply, Nat.cast_id, qrSign.eq_iff_eq hpo ha,\n    qrSign.symm hpo ha]\n  refine' value_at p (rhs p) (fun q pq hq => _) ha\n  have hqo := pq.eq_two_or_odd'.resolve_left hq\n  rw [rhs_apply, Nat.cast_id, \u2190 @legendreSym.to_jacobiSym p \u27e8pp\u27e9, qrSign.symm hqo hpo,\n    qrSign.neg_one_pow hpo hqo, @legendreSym.quadratic_reciprocity' p q \u27e8pp\u27e9 \u27e8pq\u27e9 hp hq]\n#align jacobi_sym.quadratic_reciprocity' jacobiSym.quadratic_reciprocity'\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol -/\ntheorem quadratic_reciprocity {a b : \u2115} (ha : Odd a) (hb : Odd b) :\n    J(a | b) = (-1) ^ (a / 2 * (b / 2)) * J(b | a) := by\n  rw [\u2190 qrSign.neg_one_pow ha hb, qrSign.symm ha hb, quadratic_reciprocity' ha hb]\n#align jacobi_sym.quadratic_reciprocity jacobiSym.quadratic_reciprocity\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers\nwith `a % 4 = 1` and `b` odd, then `J(a | b) = J(b | a)`. -/\ntheorem quadratic_reciprocity_one_mod_four {a b : \u2115} (ha : a % 4 = 1) (hb : Odd b) :\n    J(a | b) = J(b | a) := by\n  rw [quadratic_reciprocity (odd_iff.mpr (odd_of_mod_four_eq_one ha)) hb, pow_mul,\n    neg_one_pow_div_two_of_one_mod_four ha, one_pow, one_mul]\n#align jacobi_sym.quadratic_reciprocity_one_mod_four jacobiSym.quadratic_reciprocity_one_mod_four\n\n/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers\nwith `a` odd and `b % 4 = 1`, then `J(a | b) = J(b | a)`. -/\ntheorem quadratic_reciprocity_one_mod_four' {a b : \u2115} (ha : Odd a) (hb : b % 4 = 1) :\n    J(a | b) = J(b | a) :=\n  (quadratic_reciprocity_one_mod_four hb ha).symm\n#align jacobi_sym.quadratic_reciprocity_one_mod_four' jacobiSym.quadratic_reciprocity_one_mod_four'\n\n/-- The Law of Quadratic Reciprocityfor the Jacobi symbol: if `a` and `b` are natural numbers\nboth congruent to `3` mod `4`, then `J(a | b) = -J(b | a)`. -/\ntheorem quadratic_reciprocity_three_mod_four {a b : \u2115} (ha : a % 4 = 3) (hb : b % 4 = 3) :\n    J(a | b) = -J(b | a) :=\n  by\n  let nop := @neg_one_pow_div_two_of_three_mod_four\n  rw [quadratic_reciprocity, pow_mul, nop ha, nop hb, neg_one_mul] <;>\n    rwa [odd_iff, odd_of_mod_four_eq_three]\n#align jacobi_sym.quadratic_reciprocity_three_mod_four jacobiSym.quadratic_reciprocity_three_mod_four\n\n/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a` (version for `a : \u2115`). -/\ntheorem mod_right' (a : \u2115) {b : \u2115} (hb : Odd b) : J(a | b) = J(a | b % (4 * a)) :=\n  by\n  rcases eq_or_ne a 0 with (rfl | ha\u2080)\n  \u00b7 rw [MulZeroClass.mul_zero, mod_zero]\n  have hb' : Odd (b % (4 * a)) := hb.mod_even (Even.mul_right (by norm_num) _)\n  rcases exists_eq_pow_mul_and_not_dvd ha\u2080 2 (by norm_num) with \u27e8e, a', ha\u2081', ha\u2082\u27e9\n  have ha\u2081 := odd_iff.mpr (two_dvd_ne_zero.mp ha\u2081')\n  nth_rw 2 [ha\u2082]; nth_rw 1 [ha\u2082]\n  rw [Nat.cast_mul, mul_left, mul_left, quadratic_reciprocity' ha\u2081 hb,\n    quadratic_reciprocity' ha\u2081 hb', Nat.cast_pow, pow_left, pow_left, Nat.cast_two, at_two hb,\n    at_two hb']\n  congr 1; swap; congr 1\n  \u00b7 simp_rw [qrSign]\n    rw [\u03c7\u2084_nat_mod_four, \u03c7\u2084_nat_mod_four (b % (4 * a)), mod_mod_of_dvd b (dvd_mul_right 4 a)]\n  \u00b7 rw [mod_left \u2191(b % _), mod_left b, Int.coe_nat_mod, Int.emod_emod_of_dvd b]\n    simp only [ha\u2082, Nat.cast_mul, \u2190 mul_assoc]\n    exact dvd_mul_left a' _\n  cases e; \u00b7 rfl\n  \u00b7 rw [\u03c7\u2088_nat_mod_eight, \u03c7\u2088_nat_mod_eight (b % (4 * a)), mod_mod_of_dvd b]\n    use 2 ^ e * a'\n    rw [ha\u2082, pow_succ]\n    ring\n#align jacobi_sym.mod_right' jacobiSym.mod_right'\n\n/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a`. -/\ntheorem mod_right (a : \u2124) {b : \u2115} (hb : Odd b) : J(a | b) = J(a | b % (4 * a.natAbs)) :=\n  by\n  cases' Int.natAbs_eq a with ha ha <;> nth_rw 2 [ha] <;> nth_rw 1 [ha]\n  \u00b7 exact mod_right' a.nat_abs hb\n  \u00b7 have hb' : Odd (b % (4 * a.nat_abs)) := hb.mod_even (Even.mul_right (by norm_num) _)\n    rw [jacobiSym.neg _ hb, jacobiSym.neg _ hb', mod_right' _ hb, \u03c7\u2084_nat_mod_four,\n      \u03c7\u2084_nat_mod_four (b % (4 * _)), mod_mod_of_dvd b (dvd_mul_right 4 _)]\n#align jacobi_sym.mod_right jacobiSym.mod_right\n\nend jacobiSym\n\nend Jacobi\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/LegendreSymbol/JacobiSymbol.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7291219492129768}}
{"text": "/- \nHomeowork 10  \nSina Hazratpour\nIntroduction to Proof  \nMATH 301, Johns Hopkins University, Fall 2022   \n-/\n\n\nimport ..prooflab\nimport lectures.lec10_surj_inj_fact\nimport lectures.lec11_type_classes\nimport lectures.lec12_gaussian_integers\nimport lectures.lec13_structures_on_gaussian_int\n\n\n\nopen PROOFS \nopen PROOFS.STR \n\n\n\n\nvariables {L M N : Type} [mult_monoid_str L] [mult_monoid_str M] [mult_monoid_str N]\n\n\n\n/-! ## Question 1 (20 pts) \nFirst, show that monoid morphisms are closed under composition, i.e. the composition of two monoid morphisms is again a monoid morphism. \n\nThen, show that for any monoid `M`, the type of monoid endomorphism `M \u2192\u2098* M` itself admits a monoid structure. Note that the latter is very different than the type of endofunctions `M \u2192 M`. we showed before that whereas there is only one constant endomorphism `\u2124 \u2192\u2098* \u2124` there are \u2124-mnay endofunctions `\u2124 \u2192 \u2124`. \n-/\n\n@[simp]\ndef mult_monoid.morphism.comp (g : M \u2192\u2098* N) (f : L \u2192\u2098* M)  : L \u2192\u2098* N := \n{ to_fun := g \u2218 f,\n  resp_one := sorry,\n  resp_mul := sorry, } \n\n\ninfixr  ` \u2218* ` : 90  := mult_monoid.morphism.comp\n\ndef mult_monoid.morphism.id : M \u2192\u2098* M := \n{\n  to_fun := id, \n  resp_one := by {simp}, \n  resp_mul := by {simp},\n}\n\n#check M \u2192\u2098* M\n\n\n\ninstance : mult_monoid_str (M \u2192\u2098* M) := \n{ \n  mul := (\u2218*),\n  mul_assoc := sorry,\n  one := mult_monoid.morphism.id,\n  mul_one := sorry,\n  one_mul := sorry, \n}\n\n\n\n\n\n/-! ## Question 2 (20 pts) \nConstruct the cartesian products of monoids, and show that the two projection are monoid morphisms .  \n-/\n\ninstance mult_monoid_str.product {M N : Type} [mult_monoid_str M] [mult_monoid_str  N] :\n  mult_monoid_str (M \u00d7 N) :=\n{ \n  mul := \u03bb x, \u03bb y, \u27e8x.1 * y.1, x.2 * y.2\u27e9,\n  mul_assoc := sorry,\n  one := sorry,\n  mul_one := sorry,\n  one_mul := sorry, \n}\n\n\ninstance mon_fst : M \u00d7 N \u2192\u2098* M := \nsorry \n\n\ninstance snd_fst : M \u00d7 N \u2192\u2098* N := \nsorry \n\n\n\n\n\n/-! ## Question 3 (20 pts) \nConstruct an equivalence of types of gaussian integers \u2124[i] and the cartesian product \u2124 \u00d7 \u2124.   \n-/\ninfix ` \u2245 `:15 := fun_equiv\n\ndef gausssian_int_cartesian_product :  \n  \u2124[i] \u2245 \u2124 \u00d7 \u2124 :=  \n{ to_fun := sorry,\n  inv_fun := sorry,\n  left_inv := sorry,\n  right_inv := sorry, }  \n\n\n/- Is this equivalence a monoid isomorphism? If yes, prove it in below, if no, explain why it is not. -/\n\n\ndef gausssian_int_cartesian_product_monoid_isomorphism : \u2124[i] \u2245\u2098* \u2124 \u00d7 \u2124 := \nsorry \n\n\n\n\n\n\n/-! ## Question 4 (20 pts) \nShow that the type of functions `X \u2192 M` has a monoid structure if the codomain `M` has a monoid structure. The multiplication on `X \u2192 M` is given by pointwise multiplication, i.e. the multiplication of two functions \n`f g : X \u2192 M` should be a function `f * g : X \u2192 M` where \n`f * g (x) = (f x) * (g x)`. \n-/\n\n@[instance] \ndef mult_monoid_str.function (X M : Type)  [mult_monoid_str  M] :\n  mult_monoid_str (X \u2192 M) :=\n{ \n  mul := sorry,\n  mul_assoc := sorry,\n  one := sorry,\n  mul_one := sorry,\n  one_mul := sorry,  \n}\n\n\n\n\n\n\n\n/-! ## Question 5 (20 pts) \nShow that `Prop` admit multiplicative and additive monoid structures. -/ \n\ninstance : comm_mult_monoid_str Prop := \n{ \n  mul := (\u2227),\n  mul_assoc := sorry,\n  one := sorry,\n  mul_one := by sorry,\n  one_mul := by sorry, \n  mul_comm := sorry,\n}\n\n\ninstance or_additive : comm_additive_monoid_str Prop := \n{ \n  add := (\u2228),\n  add_assoc := sorry,\n  zero := sorry,\n  add_zero := by sorry,\n  zero_add := by sorry, \n  add_comm := sorry,\n}\n\n\ninstance xor_additive : comm_additive_monoid_str Prop := \n{ \n  add := \u03bb P Q, (P \u2228 Q) \u2227 \u00ac (P \u2227 Q),\n  add_assoc := by {intros P Q R, ext, split, intro h, simp, split, simp at h, cases h with h\u2081 h\u2082, cases h\u2081 with hpq hr,  sorry, sorry, sorry, sorry, },\n  zero := false,\n  add_zero := by {intro P, ext, split, intro h, cases h with h\u2081 h\u2082, simp at h\u2081, exact h\u2081, intro hp, split, left, exact hp, simp,  },\n  zero_add := by {intro P, ext, split, intro h, cases h with h\u2081 h\u2082, simp at h\u2081, exact h\u2081, intro hp, split, right, exact hp, simp,  }, \n  add_comm := by {intros P Q, simp, rw or_comm P Q, congr',  ext, split, intro h, intro hq, intro hp, apply h, exact hp, exact hq, intro h, intro hp, intro hq, apply h, assumption', },\n}\n\nlemma xor_no_ident :\n\u00ac(\u2203 b\u2081 : bool, \u2200 b\u2082 : bool, (b\u2081 || b\u2082) && switch (b\u2081 && b\u2082) = b\u2081) :=\nbegin\n  intro h\u2081,\n  cases h\u2081 with b\u2081 hb\u2081,\n  have h\u2082 : \u00ac(tt = ff), by {\n    simp,\n  },\n  cases b\u2081,\n  {\n    apply h\u2082,\n    rw \u2190 hb\u2081 tt,\n    refl,\n  },\n  {\n    apply h\u2082,\n    rw \u2190 hb\u2081 tt,\n    refl,\n  },\nend\n\n\nlemma xor_no_ident :\n(\u2203 b\u2081 : bool, \u2200 b\u2082 : bool, (b\u2081 || b\u2082) && switch (b\u2081 && b\u2082) = b\u2082) :=\nbegin\n  use ff, \n  intro b, \nend\n\n\n\n\n\n/-! ## Question 6 (20 pts) \nFor a type `X`, the type `set X` in Lean is defined as the function type `X \u2192 Prop`. Given a set `A : set X` \n(i.e. a function `A : X \u2192 Prop` and a term `x : X` we write `x \u2208 A` as a shorthand for the proposition `A x`. \n\n  set X       X \u2192 Prop\n----------|------------\n    A     |   A : X \u2192 Prop\n  x \u2208 A   |   A x\n-/\n\n#check set\n\n/- Show that the __convolution__ multiplication defined a semigroup structure on `set M` when `M` is a monoid.  -/\n\ninstance monoid_convolution_alt {M : Type} [mult_monoid_str M] :\n  mult_semigroup_str (set M) := \n{ \n  mul := \u03bb A B, \u03bb m, \u2203 x y : M, (m = x * y) \u2227 (A x) \u2227 (B y),  -- { (x * y) | (x \u2208 A) (y \u2208 B) }\n  mul_assoc := sorry, \n}  \n\n\n\n\n\n/- ## Question 7 (20 pts) \nIn this problem we define the structure of __join semilattice__ in terms of commutative idempotent monoids. You then show that every join semilattice is in fact a preorder. \n-/\n\n/-\nA monoid is __idempotent__ if each of its elements is idempotent. \n-/\n\n@[simp]\ndef idemp (e : M) := (e * e = e)\n\ndef mon_idemp (M : Type) [mult_monoid_str M] : Prop := \n\u2200 e : M, idemp e \n\n\n/- A __(join) semilattice__ is a commutative and idempotent additive monoid.  -/\n\n@[class]\nstructure jslat_str (X : Type) extends comm_mult_monoid_str X := \n(idemp : mon_idemp X) \n\n\n/- \nMathlib defines the notions of __preorder__ as a type class and it defined the structure of  __partial order__ as an extension of __preorder__ structure. Go ahead and examine this definitions by click&command in below. \n-/\n\n#check preorder\n\n\n\ndef preorder_of_jslat (X : Type) [jslat_str X] : \npreorder X := \n{ le := \u03bb x, \u03bb y, (x * y = y),\n  lt := \u03bb x, \u03bb y, (x * y = y) \u2227 \u00ac (y * x = x),\n  le_refl := by {intro x, simp, exact (jslat_str.idemp x), },\n  le_trans := by {intros x y z, intros h h', simp at *, rw \u2190 h', rw \u2190 mult_mon_assoc, rw h,  },\n  lt_iff_le_not_le := by {intros a b, split; intro h; dsimp, exact h, split, exact h.1, exact h.2,  }, }\n\n\n\n\n\n\n/-! ## Question 8 (20 pts) \nShow that for any monoid morphism `f : M \u2192\u2098* N` the image of the underlying function `f : M \u2192 N` inherits a monoid structure from `N`.  \n-/\n\n\nstructure mult_monoid_image_fact (f : M \u2192\u2098* N) := \n(node : Type)\n(mon_node : mult_monoid_str node) \n(left_mor : M \u2192\u2098* node)\n(right_mor : node \u2192\u2098* N) \n(fun_eq : right_mor \u2218* left_mor = f)\n\n\nlocal notation `im` :15 :=  fun_image \n\ninstance mult_monoid_str.fun_image (f : M \u2192\u2098* N) : mult_monoid_str (im f) := \n{ \n  mul :=  sorry,\n  mul_assoc := sorry,\n  one := sorry,\n  mul_one := sorry,\n  one_mul := sorry, \n}\n\n\n\n\n\n\n/-! ## Question 9 (20 pts) \nIn this problem, you are asked to construct image factorization for monoids using what you already did in the previous problem. You will show that for any monoid morphism `f : M \u2192\u2098*  N` we can factor `f` into two monoid morphisms `p` and `m` such that `f = m \u2218 p`, and `p` is surjective and `m` is injective.   \n-/ \n\ndef mon_mor_img_embedding (f : M \u2192\u2098* N) : (im f) \u2192\u2098* N := \n{ \n  to_fun := fun_image.embedding f, \n  resp_one := sorry,\n  resp_mul := sorry,\n}\n\n\ndef mon_mor_img_cover (f : M \u2192\u2098* N) : M \u2192\u2098* (im f) := \n{ \n  to_fun := fun_image.cover f,\n  resp_one := sorry,\n  resp_mul := sorry, \n}\n\n\n\ndef canonical_mult_monoid_image_fact (f : M \u2192\u2098* N) : mult_monoid_image_fact (f : M \u2192\u2098* N)  := \n{ \n  node := im f,\n  mon_node := mult_monoid_str.fun_image f,\n  left_mor := mon_mor_img_cover f,\n  right_mor := mon_mor_img_embedding f,\n  fun_eq := sorry,\n}\n\n\n\n\n", "meta": {"author": "sinhp", "repo": "ProofLab", "sha": "f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2", "save_path": "github-repos/lean/sinhp-ProofLab", "path": "github-repos/lean/sinhp-ProofLab/ProofLab-f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2/src/homework/hw10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7291219423915902}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport data.finsupp.basic\n\n/-!\n# Lattice structure on finsupps\n\nThis file provides instances of ordered structures on finsupps.\n\n-/\n\nopen_locale classical\nnoncomputable theory\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [has_zero \u03b2] {\u03bc : Type*} [canonically_ordered_add_monoid \u03bc]\nvariables {\u03b3 : Type*} [canonically_linear_ordered_add_monoid \u03b3]\n\nnamespace finsupp\n\ninstance [semilattice_inf \u03b2] : semilattice_inf (\u03b1 \u2192\u2080 \u03b2) :=\n{ inf := zip_with (\u2293) inf_idem,\n  inf_le_left := \u03bb a b c, inf_le_left,\n  inf_le_right := \u03bb a b c, inf_le_right,\n  le_inf := \u03bb a b c h1 h2 s, le_inf (h1 s) (h2 s),\n  ..finsupp.partial_order, }\n\n@[simp]\nlemma inf_apply [semilattice_inf \u03b2] {a : \u03b1} {f g : \u03b1 \u2192\u2080 \u03b2} : (f \u2293 g) a = f a \u2293 g a := rfl\n\n@[simp]\nlemma support_inf {f g : \u03b1 \u2192\u2080 \u03b3} : (f \u2293 g).support = f.support \u2229 g.support :=\nbegin\n  ext, simp only [inf_apply, mem_support_iff,  ne.def,\n    finset.mem_union, finset.mem_filter, finset.mem_inter],\n  simp only [inf_eq_min, \u2190 nonpos_iff_eq_zero, min_le_iff, not_or_distrib]\nend\n\ninstance [semilattice_sup \u03b2] : semilattice_sup (\u03b1 \u2192\u2080 \u03b2) :=\n{ sup := zip_with (\u2294) sup_idem,\n  le_sup_left := \u03bb a b c, le_sup_left,\n  le_sup_right := \u03bb a b c, le_sup_right,\n  sup_le := \u03bb a b c h1 h2 s, sup_le (h1 s) (h2 s),\n  ..finsupp.partial_order, }\n\n@[simp]\nlemma sup_apply [semilattice_sup \u03b2] {a : \u03b1} {f g : \u03b1 \u2192\u2080 \u03b2} : (f \u2294 g) a = f a \u2294 g a := rfl\n\n@[simp]\nlemma support_sup {f g : \u03b1 \u2192\u2080 \u03b3} : (f \u2294 g).support = f.support \u222a g.support :=\nbegin\n  ext, simp only [finset.mem_union, mem_support_iff, sup_apply, ne.def, \u2190 bot_eq_zero],\n  rw sup_eq_bot_iff, tauto,\nend\n\ninstance lattice [lattice \u03b2] : lattice (\u03b1 \u2192\u2080 \u03b2) :=\n{ .. finsupp.semilattice_inf, .. finsupp.semilattice_sup}\n\nlemma bot_eq_zero : (\u22a5 : \u03b1 \u2192\u2080 \u03b3) = 0 := rfl\n\nlemma disjoint_iff {x y : \u03b1 \u2192\u2080 \u03b3} : disjoint x y \u2194 disjoint x.support y.support :=\nbegin\n  unfold disjoint, repeat {rw le_bot_iff},\n  rw [finsupp.bot_eq_zero, \u2190 finsupp.support_eq_empty, finsupp.support_inf], refl,\nend\n\nvariable [partial_order \u03b2]\n\n/-- The order on `finsupp`s over a partial order embeds into the order on functions -/\ndef order_embedding_to_fun :\n  (\u03b1 \u2192\u2080 \u03b2) \u21aao (\u03b1 \u2192 \u03b2) :=\n\u27e8\u27e8\u03bb (f : \u03b1 \u2192\u2080 \u03b2) (a : \u03b1), f a,  \u03bb f g h, finsupp.ext (\u03bb a, by { dsimp at h, rw h,} )\u27e9,\n  \u03bb a b, (@le_def _ _ _ _ a b).symm\u27e9\n\n@[simp] lemma order_embedding_to_fun_apply {f : \u03b1 \u2192\u2080 \u03b2} {a : \u03b1} :\n  order_embedding_to_fun f a = f a := rfl\n\nlemma monotone_to_fun : monotone (finsupp.to_fun : (\u03b1 \u2192\u2080 \u03b2) \u2192 (\u03b1 \u2192 \u03b2)) := \u03bb f g h a, le_def.1 h a\n\nend finsupp\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/finsupp/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7291219369520311}}
{"text": "inductive aexp : Type\n| ANum   : nat  -> aexp   \n| APlus  : aexp -> aexp -> aexp\n| AMinus : aexp -> aexp -> aexp\n| AMult  : aexp -> aexp -> aexp\n\ninductive bexp : Type\n| BTrue : bexp\n| BFalse : bexp\n| BEq : aexp -> aexp -> bexp\n| BLe : aexp -> aexp -> bexp\n| BNot : bexp -> bexp\n| BAnd : bexp -> bexp -> bexp.\n\nopen aexp bexp\n\ndef aeval : aexp -> nat\n|(ANum n)      :=  n\n|(APlus a1 a2) := (aeval a1) + (aeval a2)\n|(AMinus a1 a2):= (aeval a1) - (aeval a2)\n|(AMult a1 a2) := (aeval a1) * (aeval a2)\n\nexample : aeval (APlus (ANum 2) (ANum 2)) = 4 := rfl\n\ndef beval : bexp -> bool\n| BTrue       := true\n| BFalse      := false\n|(BEq  a1 a2) := (aeval a1) = (aeval a2)\n|(BLe  a1 a2) := (aeval a1) <= (aeval a2)\n|(BNot b1)    := bnot $ beval b1\n|(BAnd b1 b2) := (beval b1) && (beval b2)\n\nexample : beval (BEq (APlus (ANum 2) (ANum 3)) (ANum 5)) = true := rfl\n\n\n", "meta": {"author": "akuhlens", "repo": "lemur", "sha": "deea493aa6bcf3ad4f4fa1d27f325d0b75ba9e79", "save_path": "github-repos/lean/akuhlens-lemur", "path": "github-repos/lean/akuhlens-lemur/lemur-deea493aa6bcf3ad4f4fa1d27f325d0b75ba9e79/imp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.7290873953154431}}
{"text": "import vec_space\n\nuniverses u v w\n\nnamespace vector_space\n\n-- 1.) Prove that -(-v) = v for every v \u2208 V\nlemma neg_neg' (F : Type u) (\u03b1 : Type v) [field F] [add_comm_group \u03b1] [vector_space F \u03b1] : \n    \u2200 v : \u03b1, - (- v) = v :=\nbegin\n    intro v,\n    apply @add_right_cancel _ _ _ (-v),\n    rw add_neg_self,\n    rw neg_add_self,\nend\n\n-- 2.) Suppose a \u2208 F, v \u2208 V, and a \u2022 v = 0. Prove that a = 0 or v = 0.\nlemma zero_or_zero (F : Type u) (\u03b1 : Type v) [field F] [add_comm_group \u03b1] [vector_space F \u03b1] : \n    \u2200 a : F, \u2200 v : \u03b1, a \u2022 v = 0 \u2192 (a = 0) \u2228 (v = 0) :=\nbegin\n    intros a v hyp,\n    sorry,\nend\n\n-- 3.) Suppose v, w \u2208 V. Explain why there exists a unique x \u2208 V such that v + 3x = w.\n\n-- 4.) maybe skip this one\n\n-- 5.) Show that in the definition of a vector space, the additive inverse condition can be replaced with the condition that 0v = 0 for all v \u2208 V.\n\n-- maybe replace add_comm_group with something else? idk\n-- this works in just commutative groups, not just vector spaces.\n-- simplify maybe? make it an instance of add_comm_group?\nlemma zero_smul_zero_iff_add_inv (F : Type u) (\u03b1 : Type v) [field F] [add_comm_group \u03b1] [vector_space F \u03b1] :\n    (\u2200 v : \u03b1, (0 : F) \u2022 v = 0) \u2194 (\u2200 x : \u03b1, \u2203 y : \u03b1, x + y = 0) :=\nbegin \n    split,\n    intro hyp,\n    intro v,\n    specialize hyp v,\n    rw \u2190 add_neg_self (1 : F) at hyp,\n    rw add_smul at hyp,\n    rw one_smul at hyp,\n    rw \u2190 hyp,\n    use (((-1) : F) \u2022 v),\n    sorry,\nend\n\nend vector_space", "meta": {"author": "agusakov", "repo": "vector_spaces", "sha": "b23954c19b357a689e2a73e07fcf6c9e4a74713a", "save_path": "github-repos/lean/agusakov-vector_spaces", "path": "github-repos/lean/agusakov-vector_spaces/vector_spaces-b23954c19b357a689e2a73e07fcf6c9e4a74713a/src/exercises/chapter_1/section_B.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7290873945385512}}
{"text": "import separation_world.definition -- hide\n\n/- Axiom : A topological space is a T\u2080 space if, from any two points in the topology, there exist and open set that contains one point and not the other\nt0 : \u2200 (x y : X) (h : y \u2260 x) , \u2203 (U : set X) (hU : is_open U), ((x \u2208 U) \u2227 (y \u2209 U)) \u2228 ((x \u2209 U) \u2227 (y \u2208 U))\n-/\n\n/- Axiom : A topological space is a T\u2081 space if, from any two points in the topology, there exist and open set that contains the first point and not the second\nt1 : \u2200 (x y : X) (h : y \u2260 x), \u2203 (U : set X) (hU : is_open U), (x \u2208 U) \u2227 (y \u2209 U)\n-/\n\n/-\n\n# Level 1: Every Frechet space is a T\u2080 space\n\n-/\nvariables {X : Type} -- hide\nvariables [topological_space X] -- hide\n\nnamespace topological_space -- hide\n\n/- Lemma\nLet \u03c4 be a topological space. If \u03c4 is a frechet space is also a T\u2080.\n-/\nlemma T1_is_T0: T1_space X \u2192 T0_space X :=\nbegin\n  introI t1,\n  fconstructor,\n  intros x y hxy,\n  obtain \u27e8U, hU, hh\u27e9:= T1_space.t1 x y hxy,\n  exact \u27e8U, hU, or.inl hh\u27e9,\n\n\n\n\n\n\n\n\n\nend\n\nend topological_space -- hide\n", "meta": {"author": "joan-ferrer", "repo": "topologygameprova", "sha": "b0c0a320d52b77abeed145052bac15fa710b94be", "save_path": "github-repos/lean/joan-ferrer-topologygameprova", "path": "github-repos/lean/joan-ferrer-topologygameprova/topologygameprova-b0c0a320d52b77abeed145052bac15fa710b94be/src/separation_world/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129327, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7290873883162742}}
{"text": "/-\nFill in the sorry\u2019s below, to prove the barber paradox.\n\nopen classical   -- not needed, but you can use it\n\n-- This is an exercise from Chapter 4. Use it as an axiom here.\naxiom not_iff_not_self (P : Prop) : \u00ac (P \u2194 \u00ac P)\n\nexample (Q : Prop) : \u00ac (Q \u2194 \u00ac Q) :=\nnot_iff_not_self Q\n\nsection\n  variable Person : Type\n  variable shaves : Person \u2192 Person \u2192 Prop\n  variable barber : Person\n  variable h : \u2200 x, shaves barber x \u2194 \u00ac shaves x x\n\n  -- Show the following:\n  example : false :=\n  sorry\nend\n-/\n\nopen classical   -- not needed, but you can use it\n\n-- This is an exercise from Chapter 4. Use it as an axiom here.\naxiom not_iff_not_self (P : Prop) : \u00ac (P \u2194 \u00ac P)\n\nexample (Q : Prop) : \u00ac (Q \u2194 \u00ac Q) :=\nnot_iff_not_self Q\n\n-- style 1, prove using excluded middle from classical\nsection\n  variable Person : Type\n  variable shaves : Person \u2192 Person \u2192 Prop\n  variable barber : Person\n  variable h : \u2200 x, shaves barber x \u2194 \u00ac shaves x x\n\n  example : false :=\n  have hBarberInverse: shaves barber barber \u2194 \u00ac shaves barber barber,\n  from h(barber),\n  or.elim(em(shaves(barber)(barber)))(\n    \u03bb hBarberShavesSelf: shaves(barber)(barber), \n    have hBarberDoesntShaveSelf: \u00ac shaves barber barber,\n    from iff.mp(hBarberInverse)(hBarberShavesSelf),\n    show false, from hBarberDoesntShaveSelf(hBarberShavesSelf)\n  )(\n    \u03bb hBarberDoesntShaveSelf: \u00ac shaves(barber)(barber),\n    have hBarberShavesSelf: shaves barber barber,\n    from iff.mpr(hBarberInverse)(hBarberDoesntShaveSelf),\n    show false, from hBarberDoesntShaveSelf(hBarberShavesSelf)\n  )\nend\n\n-- style 2, prove using the not_iff_not_self axiom\nsection\n  variable Person : Type\n  variable shaves : Person \u2192 Person \u2192 Prop\n  variable barber : Person\n  variable h : \u2200 x, shaves barber x \u2194 \u00ac shaves x x\n\n  example : false :=\n  have hBarberInverse: shaves barber barber \u2194 \u00ac shaves barber barber,\n  from h(barber),\n  have hNotBarberInverse: \u00ac (shaves barber barber \u2194 \u00ac shaves barber barber),\n  from not_iff_not_self(shaves barber barber),\n  show false, from hNotBarberInverse(hBarberInverse)\nend", "meta": {"author": "chanind", "repo": "logic-and-proof-exercises", "sha": "8d797d400d937cb4f21954b1d7a5092ceb4f6dd7", "save_path": "github-repos/lean/chanind-logic-and-proof-exercises", "path": "github-repos/lean/chanind-logic-and-proof-exercises/logic-and-proof-exercises-8d797d400d937cb4f21954b1d7a5092ceb4f6dd7/chapters/chapter9/ex4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681086260461, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7290781726202443}}
{"text": "/-\nCopyright (c) 2020 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport ring_theory.polynomial.cyclotomic\nimport topology.algebra.polynomial\nimport field_theory.finite.basic\n\n/-!\n# Primes congruent to one\n\nWe prove that, for any positive `k : \u2115`, there are infinitely many primes `p` such that\n`p \u2261 1 [MOD k]`.\n-/\n\nnamespace nat\n\nopen polynomial nat filter\n\n/-- For any positive `k : \u2115` there are infinitely many primes `p` such that `p \u2261 1 [MOD k]`. -/\nlemma exists_prime_ge_modeq_one (k n : \u2115) (hpos : 0 < k) :\n  \u2203 (p : \u2115), nat.prime p \u2227 n \u2264 p \u2227 p \u2261 1 [MOD k] :=\nbegin\n  have hli : tendsto (abs \u2218 (\u03bb (a : \u2115), |(a : \u211a)|)) at_top at_top,\n  { simp only [(\u2218), abs_cast],\n    exact nat.strict_mono_cast.monotone.tendsto_at_top_at_top exists_nat_ge },\n  have hcff : int.cast_ring_hom \u211a (cyclotomic k \u2124).leading_coeff \u2260 0,\n  { simp only [cyclotomic.monic, ring_hom.eq_int_cast, monic.leading_coeff, int.cast_one, ne.def,\n     not_false_iff, one_ne_zero] },\n  obtain \u27e8a, ha\u27e9 := tendsto_at_top_at_top.1 (tendsto_abv_eval\u2082_at_top (int.cast_ring_hom \u211a)\n    abs (cyclotomic k \u2124) (degree_cyclotomic_pos k \u2124 hpos) hcff hli) 2,\n  let b := a * (k * n.factorial),\n  have hgt : 1 < (eval \u2191(a * (k * n.factorial)) (cyclotomic k \u2124)).nat_abs,\n  { suffices hgtabs : 1 < |eval \u2191b (cyclotomic k \u2124)|,\n    { rw [int.abs_eq_nat_abs] at hgtabs,\n      exact_mod_cast hgtabs },\n    suffices hgtrat : 1 < |eval \u2191b (cyclotomic k \u211a)|,\n    { rw [\u2190 map_cyclotomic_int k \u211a, \u2190 int.cast_coe_nat, \u2190 int.coe_cast_ring_hom, eval_map,\n        eval\u2082_hom, int.coe_cast_ring_hom] at hgtrat,\n      assumption_mod_cast },\n    suffices hleab : a \u2264 b,\n    { replace ha := lt_of_lt_of_le one_lt_two (ha b hleab),\n      rwa [\u2190 eval_map, map_cyclotomic_int k \u211a, abs_cast] at ha },\n    exact le_mul_of_pos_right (mul_pos hpos (factorial_pos n)) },\n  let p := min_fac (eval \u2191b (cyclotomic k \u2124)).nat_abs,\n  haveI hprime : fact p.prime := \u27e8min_fac_prime (ne_of_lt hgt).symm\u27e9,\n  have hroot : is_root (cyclotomic k (zmod p)) (cast_ring_hom (zmod p) b),\n  { rw [is_root.def, \u2190 map_cyclotomic_int k (zmod p), eval_map, coe_cast_ring_hom,\n    \u2190 int.cast_coe_nat, \u2190 int.coe_cast_ring_hom, eval\u2082_hom, int.coe_cast_ring_hom,\n      zmod.int_coe_zmod_eq_zero_iff_dvd _ _],\n    apply int.dvd_nat_abs.1,\n    exact_mod_cast min_fac_dvd (eval \u2191b (cyclotomic k \u2124)).nat_abs },\n  refine \u27e8p, hprime.1, _, _\u27e9,\n  { by_contra habs,\n    exact (prime.dvd_iff_not_coprime hprime.1).1\n      (dvd_factorial (min_fac_pos _) (le_of_not_ge habs))\n      (coprime_of_root_cyclotomic hpos hroot).symm.coprime_mul_left_right.coprime_mul_left_right },\n  { have hdiv := order_of_dvd_of_pow_eq_one (zmod.units_pow_card_sub_one_eq_one p\n      (zmod.unit_of_coprime b (coprime_of_root_cyclotomic hpos hroot))),\n    have : \u00acp \u2223 k := hprime.1.coprime_iff_not_dvd.1\n      (coprime_of_root_cyclotomic hpos hroot).symm.coprime_mul_left_right.coprime_mul_right_right,\n    have := (not_iff_not.mpr $ zmod.nat_coe_zmod_eq_zero_iff_dvd k p).mpr this,\n    have : k = order_of (b : zmod p) := ((is_root_cyclotomic_iff this).mp hroot).eq_order_of,\n    rw [\u2190order_of_units, zmod.coe_unit_of_coprime, \u2190this] at hdiv,\n    exact ((modeq_iff_dvd' hprime.1.pos).2 hdiv).symm }\nend\n\nlemma frequently_at_top_modeq_one (k : \u2115) (hpos : 0 < k) :\n  \u2203\u1da0 p in at_top, nat.prime p \u2227 p \u2261 1 [MOD k] :=\nbegin\n  refine frequently_at_top.2 (\u03bb n, _),\n  obtain \u27e8p, hp\u27e9 := exists_prime_ge_modeq_one k n hpos,\n  exact \u27e8p, \u27e8hp.2.1, hp.1, hp.2.2\u27e9\u27e9\nend\n\nlemma infinite_set_of_prime_modeq_one (k : \u2115) (hpos : 0 < k) :\n  set.infinite {p : \u2115 | nat.prime p \u2227 p \u2261 1 [MOD k]} :=\nfrequently_at_top_iff_infinite.1 (frequently_at_top_modeq_one k hpos)\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/primes_congruent_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7290781553686695}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n-/\nimport data.nat.basic\n\n/-!\n# `nat.upto`\n\n`nat.upto p`, with `p` a predicate on `\u2115`, is a subtype of elements `n : \u2115` such that no value\n(strictly) below `n` satisfies `p`.\n\nThis type has the property that `>` is well-founded when `\u2203 i, p i`, which allows us to implement\nsearches on `\u2115`, starting at `0` and with an unknown upper-bound.\n\nIt is similar to the well founded relation constructed to define `nat.find` with\nthe difference that, in `nat.upto p`, `p` does not need to be decidable. In fact,\n`nat.find` could be slightly altered to factor decidability out of its\nwell founded relation and would then fulfill the same purpose as this file.\n-/\n\nnamespace nat\n\n/-- The subtype of natural numbers `i` which have the property that\nno `j` less than `i` satisfies `p`. This is an initial segment of the\nnatural numbers, up to and including the first value satisfying `p`.\n\nWe will be particularly interested in the case where there exists a value\nsatisfying `p`, because in this case the `>` relation is well-founded.  -/\n@[reducible]\ndef upto (p : \u2115 \u2192 Prop) : Type := {i : \u2115 // \u2200 j < i, \u00ac p j}\n\nnamespace upto\n\nvariable {p : \u2115 \u2192 Prop}\n\n/-- Lift the \"greater than\" relation on natural numbers to `nat.upto`. -/\nprotected def gt (p) (x y : upto p) : Prop := x.1 > y.1\n\ninstance : has_lt (upto p) := \u27e8\u03bb x y, x.1 < y.1\u27e9\n\n/-- The \"greater than\" relation on `upto p` is well founded if (and only if) there exists a value\nsatisfying `p`. -/\nprotected lemma wf : (\u2203 x, p x) \u2192 well_founded (upto.gt p)\n| \u27e8x, h\u27e9 := begin\n  suffices : upto.gt p = measure (\u03bb y : nat.upto p, x - y.val),\n  { rw this, apply measure_wf },\n  ext \u27e8a, ha\u27e9 \u27e8b, _\u27e9,\n  dsimp [measure, inv_image, upto.gt],\n  rw tsub_lt_tsub_iff_left_of_le,\n  exact le_of_not_lt (\u03bb h', ha _ h' h),\nend\n\n/-- Zero is always a member of `nat.upto p` because it has no predecessors. -/\ndef zero : nat.upto p := \u27e80, \u03bb j h, false.elim (nat.not_lt_zero _ h)\u27e9\n\n/-- The successor of `n` is in `nat.upto p` provided that `n` doesn't satisfy `p`. -/\ndef succ (x : nat.upto p) (h : \u00ac p x.val) : nat.upto p :=\n\u27e8x.val.succ, \u03bb j h', begin\n  rcases nat.lt_succ_iff_lt_or_eq.1 h' with h' | rfl;\n  [exact x.2 _ h', exact h]\nend\u27e9\n\nend upto\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/upto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8499711680567799, "lm_q1q2_score": 0.7290781519393964}}
{"text": "import .src_real_field\nimport .src_ordered_field_lemmas\nimport data.set.basic\nimport tactic\n\nnamespace mth1001\n\nnamespace myreal\n\nopen myreal_field myordered_field classical\n\nopen_locale classical\n\nvariables {R : Type} [myreal_field R]\n\ndef has_upper_bound (S : set R) := \u2203 u : R, upper_bound u S\n\ndef has_lower_bound (S : set R) := \u2203 v : R, lower_bound v S\n\nlemma sup_is_sup {S : set R} (h\u2081 : has_upper_bound S) (h\u2082 : S \u2260 \u2205) : is_sup (sup S) S :=\nbegin\n  have h\u2083 : \u2203 x : R, is_sup x S, from completeness h\u2082 h\u2081,\n  have h\u2084 : sup S = some h\u2083, from dif_pos h\u2083,\n  rw h\u2084,\n  exact some_spec h\u2083,\nend\n\ntheorem sup_monotone (S T : set R) (h\u2081 : has_upper_bound S) (h\u2082 : has_upper_bound T)\n(h\u2083 : S \u2260 \u2205) (h\u2084 : T \u2260 \u2205) : S \u2286 T \u2192 sup S \u2264 sup T :=\nbegin\n  have h\u2085 : \u2200 (v : R), upper_bound v S \u2192 sup S \u2264 v, from (sup_is_sup h\u2081 h\u2083).right,\n  have h\u2086 : upper_bound (sup T) T, from (sup_is_sup h\u2082 h\u2084).left,\n  intro k,\n  apply h\u2085 (sup T),\n  intros s hs,\n  have ht : s \u2208 T, from k hs,\n  exact h\u2086 s ht,\nend\n\ntheorem archimedean : \u2200 x : R, \u2203 n : \u2115, x < n :=\nbegin\n  by_contra h,\n  push_neg at h,\n  cases h with x hx,\n  let S := {m : R | \u2203 n : \u2115, (m = n) \u2227 (x \u2265 n)},\n  have h\u2081 : \u21911 \u2208 S, from \u27e81, \u27e8rfl, hx 1\u27e9\u27e9,\n  have h\u2082 : S \u2260 \u2205,\n  { intro h, rw h at h\u2081, exact h\u2081, },\n  have h\u2083 : has_upper_bound S, from \u27e8x, \u03bb s \u27e8n,hs,hn\u27e9, hs.symm \u25b8 hn\u27e9,\n  have h\u2084 : is_sup (sup S) S, from sup_is_sup h\u2083 h\u2082,\n  suffices k : upper_bound (sup S +- 1) S,\n  { have k\u2082, from add_le_add (h\u2084.right (sup S + - 1) k) (le_refl (1 +- sup S)),\n    have k\u2083 : sup S + (1 + -sup S) = 1, rw [add_comm 1 (-sup S), \u2190add_assoc, add_neg', zero_add],\n    have k\u2084 : sup S +-1 + (1 + -sup S) = 0,\n    { rw [add_assoc,  \u2190add_assoc (-1) 1 (-sup S), neg_add, zero_add, add_neg'], },\n    rw [k\u2083, k\u2084, \u2190not_lt_iff_le] at k\u2082,\n    apply k\u2082,\n    rw [lt_iff_pos_neg, neg_zero, add_zero], exact pos_one, },\n  rintros _ \u27e8m, rfl, xgem\u27e9,\n  have h\u2086 : \u2191(m + 1) \u2208 S, from  \u27e8m+1, rfl, hx (m+1)\u27e9,\n  convert (add_le_add (h\u2084.left (\u2191m + 1) h\u2086) (le_refl (-1))),\n  rw [add_assoc,add_neg',add_zero],\nend\n\ntheorem inv_lt_of_pos (\u03b5 : R) (h : 0 < \u03b5) : \u2203 n : \u2115, n \u2260 0 \u2227 (\u2191n)\u207b\u00b9 < \u03b5 :=\nbegin\n  cases archimedean \u03b5\u207b\u00b9 with n hn,\n  use n,\n  have h\u2081 : \u03b5 \u2260 0, from ne_of_gt h,\n  have h\u2082 : 0 <  \u03b5\u207b\u00b9, from (inv_pos h\u2081).mpr h,\n  rw \u2190inv_inv' \u03b5 h\u2081 ,\n  have h\u2083 : (0 : R) < \u2191n, from lt_trans h\u2082 hn,\n  rw (inv_lt_inv h\u2083 h\u2082),\n  split,\n  { intro heq0,\n    rw heq0 at h\u2083,\n    exact lt_irrefl h\u2083, },\n  { exact hn, },\nend\n\nlemma zero_of_non_neg_of_lt_pos (a : R) (h : 0 \u2264 a) (h\u2082 : \u2200 \u03b5 > 0, a < \u03b5) : a = 0 :=\nbegin\n  rw le_iff_lt_or_eq at h,\n  cases h with hpos heq0,\n  { rcases inv_lt_of_pos a hpos with \u27e8n, hn0, hn\u27e9,\n    have hnpos : pos (n : R), from pos_nat n hn0,\n    have h\u2083 : (n : R) \u2260 0,\n    { intro k, rw [k, \u2190add_neg' (0 : R), \u2190lt_iff_pos_neg] at hnpos,\n      exact lt_irrefl hnpos, },\n    have hninvpos : (0 : R) < (n : R)\u207b\u00b9,\n    { rwa [(inv_pos h\u2083), lt_iff_pos_sub, sub_zero], },\n    have h\u2084 : a < n\u207b\u00b9, from h\u2082 _ hninvpos,\n    exfalso,\n    exact lt_irrefl (lt_trans h\u2084 hn), },\n  { exact heq0.symm, }\nend\n\ntheorem bounded_iff_abs_lt (S : set R) : bounded S \u2194 \u2203 m : \u2115, \u2200 s \u2208 S, abs s < \u2191m :=\nbegin\n  split,\n  { rintro \u27e8\u27e8ub, hub\u27e9, lb, hlb\u27e9,\n    rcases archimedean (max (abs ub) (abs lb)) with \u27e8n, hn\u27e9,\n    use n,\n    intros s hs,\n    unfold abs,\n    cases max_choice s (-s) with hms hmns,\n    { rw hms,\n      have h\u2082 : s \u2264 ub, from hub s hs,\n      have h\u2083 : ub \u2264 abs ub, from le_abs_self ub,\n      have h\u2084 : abs ub \u2264 max (abs ub) (abs lb), from le_max_left _ _,\n      apply lt_of_le_of_lt,\n      { exact le_trans _ _ _ h\u2082 (le_trans _ _ _ h\u2083 h\u2084)},\n      { exact hn, }, },\n    { rw hmns,\n      have h\u2082 : -s \u2264 -lb, from neg_le_neg_iff.mpr (hlb s hs),\n      have h\u2083 : -lb \u2264 abs lb, from neg_le_abs lb,\n      have h\u2084 : abs lb \u2264 max (abs ub) (abs lb), from le_max_right _ _,\n      apply lt_of_le_of_lt,\n      { exact le_trans _ _ _ h\u2082 (le_trans _ _ _ h\u2083 h\u2084) },\n      { exact hn, }, }, },\n  { rintro \u27e8m, hm\u27e9,\n    split,\n    { use m,\n      intros s hs,\n      apply le_trans,\n      { exact le_abs_self s, },\n      { exact le_iff_lt_or_eq.mpr (or.inl (hm s hs)) }, },\n    { use (-m),\n      intros s hs,\n      rw [\u2190neg_le_neg_iff, neg_neg],\n      apply le_trans,\n      { exact neg_le_abs s, },\n      { exact le_iff_lt_or_eq.mpr (or.inl (hm s hs)), }, }, },\nend\n\nend myreal\n\nend mth1001", "meta": {"author": "gihanmarasingha", "repo": "ems_reals", "sha": "9df527742db69d0a389add44b506538fdb4d0800", "save_path": "github-repos/lean/gihanmarasingha-ems_reals", "path": "github-repos/lean/gihanmarasingha-ems_reals/ems_reals-9df527742db69d0a389add44b506538fdb4d0800/src/library/src_real_field_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7290207532662198}}
{"text": "import game.max.level05 -- hide\n\nopen_locale classical -- hide\n\nnoncomputable theory -- hide\n\nnamespace xena -- hide\n\n/-\n# Chapter 4 : Max and abs\n\n## Level 6\n\nIn fact `max_le` can be beefed up to an iff statement.\n-/\n\n/- Hint : Tip : using `le_trans` \nIf your goal is `x \u2264 z` and you have a hypothesis `h : y \u2264 z`\nthen of course it will suffice to prove `x \u2264 y` and then you\ncan use transitivity. Instead of `have hxy : x \u2264 y,`, opening\na new goal and adding a new hypothesis to our list, you can\ndo \n\n```\napply le_trans _ h\n```\n\nor\n\n```\nrefine le_trans _ h\n```\n\nand this just reduces the goal to proving `x \u2264 y` immediately. \n\n-/\n\n/- Lemma\nIf $a$, $b$, $c$ are real numbers,\nthen ($a\\leq c$ and $b\\leq c$) iff $\\max(a,b)\\leq c.$\n-/\n\ntheorem max_le_iff {a b c : \u211d} : a \u2264 c \u2227 b \u2264 c \u2194 max a b \u2264 c :=\nbegin\n  split,\n  intro h,\n  cases h with t ht,\n  exact max_le t ht,\n  intro j,\n  split,\n  apply le_trans _ j,\n  apply le_max_left,\n  apply le_trans _ j,\n  apply le_max_right,\n\nend\n\nend xena --hide\n\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/max/level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303292, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.729017544711669}}
{"text": "def GrahamSum (p : Nat) : Nat :=\n  match p with \n    | 0 => 0\n    | n + 1 => GrahamSum n + (2*(n+1)-1)\n\nexample : \u2200 x : Nat, GrahamSum x = x*x :=\n  \u03bb(a : Nat) =>\n    Nat.recOn a (rfl) (\u03bb(n : Nat) =>\n      \u03bb(h1 : GrahamSum n = n*n) =>\n        calc\n          GrahamSum (n+1) = GrahamSum n + 2*(n+1) - 1              := rfl\n          _ = (n * n) + 2*n + 2 - 1                                := by simp[*, Nat.left_distrib, Nat.add_assoc]\n          _ = (n * n) + 2*n + 1                                    := rfl\n          _ = (n + 1)*(n + 1)                                      := by simp[Nat.add_assoc, Nat.mul_comm, <-Nat.left_distrib, Nat.left_distrib, <-Nat.right_distrib]\n    )\n\n", "meta": {"author": "cmloura", "repo": "LeanPractice2023", "sha": "6819825e67228bfe5e69aa309f8d2bd37ef48ce3", "save_path": "github-repos/lean/cmloura-LeanPractice2023", "path": "github-repos/lean/cmloura-LeanPractice2023/LeanPractice2023-6819825e67228bfe5e69aa309f8d2bd37ef48ce3/march21.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7290175361759413}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport data.set.function\nimport logic.function.iterate\nimport group_theory.perm.basic\n\n/-!\n# Fixed points of a self-map\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define\n\n* the predicate `is_fixed_pt f x := f x = x`;\n* the set `fixed_points f` of fixed points of a self-map `f`.\n\nWe also prove some simple lemmas about `is_fixed_pt` and `\u2218`, `iterate`, and `semiconj`.\n\n## Tags\n\nfixed point\n-/\n\nopen equiv\n\nuniverses u v\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {f fa g : \u03b1 \u2192 \u03b1} {x y : \u03b1} {fb : \u03b2 \u2192 \u03b2} {m n k : \u2115} {e : perm \u03b1}\n\nnamespace function\n\n/-- A point `x` is a fixed point of `f : \u03b1 \u2192 \u03b1` if `f x = x`. -/\ndef is_fixed_pt (f : \u03b1 \u2192 \u03b1) (x : \u03b1) := f x = x\n\n/-- Every point is a fixed point of `id`. -/\nlemma is_fixed_pt_id (x : \u03b1) : is_fixed_pt id x := (rfl : _)\n\nnamespace is_fixed_pt\n\ninstance [h : decidable_eq \u03b1] {f : \u03b1 \u2192 \u03b1} {x : \u03b1} : decidable (is_fixed_pt f x) :=\nh (f x) x\n\n/-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`.-/\nprotected \n\n/-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f \u2218 g`. -/\nprotected lemma comp (hf : is_fixed_pt f x) (hg : is_fixed_pt g x) : is_fixed_pt (f \u2218 g) x :=\ncalc f (g x) = f x : congr_arg f hg\n         ... = x   : hf\n\n/-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/\nprotected lemma iterate (hf : is_fixed_pt f x) (n : \u2115) : is_fixed_pt (f^[n]) x :=\niterate_fixed hf n\n\n/-- If `x` is a fixed point of `f \u2218 g` and `g`, then it is a fixed point of `f`. -/\nlemma left_of_comp (hfg : is_fixed_pt (f \u2218 g) x) (hg : is_fixed_pt g x) : is_fixed_pt f x :=\ncalc f x = f (g x) : congr_arg f hg.symm\n     ... = x       : hfg\n\n/-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed\npoint of `g`. -/\nlemma to_left_inverse (hf : is_fixed_pt f x) (h : left_inverse g f) : is_fixed_pt g x :=\ncalc g x = g (f x) : congr_arg g hf.symm\n     ... = x       : h x\n\n/-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\nprotected lemma map {x : \u03b1} (hx : is_fixed_pt fa x) {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) :\n  is_fixed_pt fb (g x) :=\ncalc fb (g x) = g (fa x) : (h.eq x).symm\n          ... = g x      : congr_arg g hx\n\nprotected lemma apply {x : \u03b1} (hx : is_fixed_pt f x) : is_fixed_pt f (f x) :=\nby convert hx\n\nlemma preimage_iterate {s : set \u03b1} (h : is_fixed_pt (set.preimage f) s) (n : \u2115) :\n  is_fixed_pt (set.preimage (f^[n])) s :=\nby { rw set.preimage_iterate_eq, exact h.iterate n, }\n\nprotected lemma equiv_symm (h : is_fixed_pt e x) : is_fixed_pt e.symm x :=\nh.to_left_inverse e.left_inverse_symm\n\nprotected lemma perm_inv (h : is_fixed_pt e x) : is_fixed_pt \u21d1(e\u207b\u00b9) x := h.equiv_symm\n\nprotected lemma perm_pow (h : is_fixed_pt e x) (n : \u2115) : is_fixed_pt \u21d1(e ^ n) x :=\nby { rw equiv.perm.coe_pow, exact h.iterate _ }\n\nprotected lemma perm_zpow (h : is_fixed_pt e x) : \u2200 n : \u2124, is_fixed_pt \u21d1(e ^ n) x\n| (int.of_nat n) := h.perm_pow _\n| (int.neg_succ_of_nat n) := (h.perm_pow $ n + 1).perm_inv\n\nend is_fixed_pt\n\n@[simp] lemma injective.is_fixed_pt_apply_iff (hf : injective f) {x : \u03b1} :\n  is_fixed_pt f (f x) \u2194 is_fixed_pt f x :=\n\u27e8\u03bb h, hf h.eq, is_fixed_pt.apply\u27e9\n\n/-- The set of fixed points of a map `f : \u03b1 \u2192 \u03b1`. -/\ndef fixed_points (f : \u03b1 \u2192 \u03b1) : set \u03b1 := {x : \u03b1 | is_fixed_pt f x}\n\ninstance fixed_points.decidable [decidable_eq \u03b1] (f : \u03b1 \u2192 \u03b1) (x : \u03b1) :\n  decidable (x \u2208 fixed_points f) :=\nis_fixed_pt.decidable\n\n@[simp] lemma mem_fixed_points : x \u2208 fixed_points f \u2194 is_fixed_pt f x := iff.rfl\n\nlemma mem_fixed_points_iff {\u03b1 : Type*} {f : \u03b1 \u2192 \u03b1} {x : \u03b1} :\n  x \u2208 fixed_points f \u2194 f x = x :=\nby refl\n\n@[simp] lemma fixed_points_id : fixed_points (@id \u03b1) = set.univ :=\nset.ext $ \u03bb _, by simpa using is_fixed_pt_id _\n\nlemma fixed_points_subset_range : fixed_points f \u2286 set.range f :=\n\u03bb x hx, \u27e8x, hx\u27e9\n\n/-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\nlemma semiconj.maps_to_fixed_pts {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) :\n  set.maps_to g (fixed_points fa) (fixed_points fb) :=\n\u03bb x hx, hx.map h\n\n/-- Any two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1` are inverse of each other on the sets of fixed points\nof `f \u2218 g` and `g \u2218 f`, respectively. -/\nlemma inv_on_fixed_pts_comp (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n  set.inv_on f g (fixed_points $ f \u2218 g) (fixed_points $ g \u2218 f) :=\n\u27e8\u03bb x, id, \u03bb x, id\u27e9\n\n/-- Any map `f` sends fixed points of `g \u2218 f` to fixed points of `f \u2218 g`. -/\nlemma maps_to_fixed_pts_comp (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n  set.maps_to f (fixed_points $ g \u2218 f) (fixed_points $ f \u2218 g) :=\n\u03bb x hx, hx.map $ \u03bb x, rfl\n\n/-- Given two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1`, `g` is a bijective map between the fixed points\nof `f \u2218 g` and the fixed points of `g \u2218 f`. The inverse map is `f`, see `inv_on_fixed_pts_comp`. -/\nlemma bij_on_fixed_pts_comp (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n  set.bij_on g (fixed_points $ f \u2218 g) (fixed_points $ g \u2218 f) :=\n(inv_on_fixed_pts_comp f g).bij_on (maps_to_fixed_pts_comp g f) (maps_to_fixed_pts_comp f g)\n\n/-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points\nof `f \u2218 g`. This is a particular case of `function.inv_on_fixed_pts_comp`. -/\nlemma commute.inv_on_fixed_pts_comp (h : commute f g) :\n  set.inv_on f g (fixed_points $ f \u2218 g) (fixed_points $ f \u2218 g) :=\nby simpa only [h.comp_eq] using inv_on_fixed_pts_comp f g\n\n/-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\nlemma commute.left_bij_on_fixed_pts_comp (h : commute f g) :\n  set.bij_on f (fixed_points $ f \u2218 g) (fixed_points $ f \u2218 g) :=\nby simpa only [h.comp_eq] using bij_on_fixed_pts_comp g f\n\n/-- If self-maps `f` and `g` commute, then `g` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\nlemma commute.right_bij_on_fixed_pts_comp (h : commute f g) :\n  set.bij_on g (fixed_points $ f \u2218 g) (fixed_points $ f \u2218 g) :=\nby simpa only [h.comp_eq] using bij_on_fixed_pts_comp f g\n\nend function\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/dynamics/fixed_points/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7289671575792781}}
{"text": "/-\nCopyright (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n-/\nprelude\n\nimport init.algebra.order init.meta\n\nuniverse u\n\nexport linear_order (min max)\n\nsection\nopen decidable tactic\nvariables {\u03b1 : Type u} [linear_order \u03b1]\n\nlemma min_def (a b : \u03b1) : min a b = if a \u2264 b then a else b :=\nby rw [congr_fun linear_order.min_def a, min_default]\nlemma max_def (a b : \u03b1) : max a b = if b \u2264 a then a else b :=\nby rw [congr_fun linear_order.max_def a, max_default]\n\nprivate meta def min_tac_step : tactic unit :=\nsolve1 $ intros\n>> `[simp only [min_def, max_def]]\n>> try `[simp [*, if_pos, if_neg]]\n>> try `[apply le_refl]\n>> try `[apply le_of_not_le, assumption]\n\nmeta def tactic.interactive.min_tac (a b : interactive.parse lean.parser.pexpr) : tactic unit :=\ninteractive.by_cases (none, ``(%%a \u2264 %%b)); min_tac_step\n\nlemma min_le_left (a b : \u03b1) : min a b \u2264 a :=\nby min_tac a b\n\nlemma min_le_right (a b : \u03b1) : min a b \u2264 b :=\nby min_tac a b\n\nlemma le_min {a b c : \u03b1} (h\u2081 : c \u2264 a) (h\u2082 : c \u2264 b) : c \u2264 min a b :=\nby min_tac a b\n\nlemma le_max_left (a b : \u03b1) : a \u2264 max a b :=\nby min_tac b a\n\nlemma le_max_right (a b : \u03b1) : b \u2264 max a b :=\nby min_tac b a\n\nlemma max_le {a b c : \u03b1} (h\u2081 : a \u2264 c) (h\u2082 : b \u2264 c) : max a b \u2264 c :=\nby min_tac b a\n\nlemma eq_min {a b c : \u03b1} (h\u2081 : c \u2264 a) (h\u2082 : c \u2264 b) (h\u2083 : \u2200{d}, d \u2264 a \u2192 d \u2264 b \u2192 d \u2264 c) :\n  c = min a b :=\nle_antisymm (le_min h\u2081 h\u2082) (h\u2083 (min_le_left a b) (min_le_right a b))\n\nlemma min_comm (a b : \u03b1) : min a b = min b a :=\neq_min (min_le_right a b) (min_le_left a b) (\u03bb c h\u2081 h\u2082, le_min h\u2082 h\u2081)\n\nlemma min_assoc (a b c : \u03b1) : min (min a b) c = min a (min b c) :=\nbegin\n  apply eq_min,\n  { apply le_trans, apply min_le_left, apply min_le_left },\n  { apply le_min, apply le_trans, apply min_le_left, apply min_le_right, apply min_le_right },\n  { intros d h\u2081 h\u2082, apply le_min, apply le_min h\u2081, apply le_trans h\u2082, apply min_le_left,\n    apply le_trans h\u2082, apply min_le_right }\nend\n\nlemma min_left_comm : \u2200 (a b c : \u03b1), min a (min b c) = min b (min a c) :=\nleft_comm (@min \u03b1 _) (@min_comm \u03b1 _) (@min_assoc \u03b1 _)\n\n@[simp]\nlemma min_self (a : \u03b1) : min a a = a :=\nby min_tac a a\n\n@[ematch]\nlemma min_eq_left {a b : \u03b1} (h : a \u2264 b) : min a b = a :=\nbegin apply eq.symm, apply eq_min (le_refl _) h, intros, assumption end\n\n@[ematch]\nlemma min_eq_right {a b : \u03b1} (h : b \u2264 a) : min a b = b :=\neq.subst (min_comm b a) (min_eq_left h)\n\nlemma eq_max {a b c : \u03b1} (h\u2081 : a \u2264 c) (h\u2082 : b \u2264 c) (h\u2083 : \u2200{d}, a \u2264 d \u2192 b \u2264 d \u2192 c \u2264 d) : c = max a b :=\nle_antisymm (h\u2083 (le_max_left a b) (le_max_right a b)) (max_le h\u2081 h\u2082)\n\nlemma max_comm (a b : \u03b1) : max a b = max b a :=\neq_max (le_max_right a b) (le_max_left a b) (\u03bb c h\u2081 h\u2082, max_le h\u2082 h\u2081)\n\nlemma max_assoc (a b c : \u03b1) : max (max a b) c = max a (max b c) :=\nbegin\n  apply eq_max,\n  { apply le_trans, apply le_max_left a b, apply le_max_left },\n  { apply max_le, apply le_trans, apply le_max_right a b, apply le_max_left, apply le_max_right },\n  { intros d h\u2081 h\u2082, apply max_le, apply max_le h\u2081, apply le_trans (le_max_left _ _) h\u2082,\n    apply le_trans (le_max_right _ _) h\u2082}\nend\n\nlemma max_left_comm : \u2200 (a b c : \u03b1), max a (max b c) = max b (max a c) :=\nleft_comm (@max \u03b1 _) (@max_comm \u03b1 _) (@max_assoc \u03b1 _)\n\n@[simp]\nlemma max_self (a : \u03b1) : max a a = a :=\nby min_tac a a\n\nlemma max_eq_left {a b : \u03b1} (h : b \u2264 a) : max a b = a :=\nbegin apply eq.symm, apply eq_max (le_refl _) h, intros, assumption end\n\nlemma max_eq_right {a b : \u03b1} (h : a \u2264 b) : max a b = b :=\neq.subst (max_comm b a) (max_eq_left h)\n\n/- these rely on lt_of_lt -/\n\nlemma min_eq_left_of_lt {a b : \u03b1} (h : a < b) : min a b = a :=\nmin_eq_left (le_of_lt h)\n\nlemma min_eq_right_of_lt {a b : \u03b1} (h : b < a) : min a b = b :=\nmin_eq_right (le_of_lt h)\n\nlemma max_eq_left_of_lt {a b : \u03b1} (h : b < a) : max a b = a :=\nmax_eq_left (le_of_lt h)\n\nlemma max_eq_right_of_lt {a b : \u03b1} (h : a < b) : max a b = b :=\nmax_eq_right (le_of_lt h)\n\n/- these use the fact that it is a linear ordering -/\n\nlemma lt_min {a b c : \u03b1} (h\u2081 : a < b) (h\u2082 : a < c) : a < min b c :=\nor.elim (le_or_gt b c)\n  (assume h : b \u2264 c, by min_tac b c)\n  (assume h : b > c, by min_tac b c)\n\nlemma max_lt {a b c : \u03b1} (h\u2081 : a < c) (h\u2082 : b < c) : max a b < c :=\nor.elim (le_or_gt a b)\n  (assume h : a \u2264 b, by min_tac b a)\n  (assume h : a > b, by min_tac b a)\nend\n", "meta": {"author": "subfish-zhou", "repo": "N2Lean", "sha": "8e858cc5b01f1ad921094dc355db3cb9473a42fd", "save_path": "github-repos/lean/subfish-zhou-N2Lean", "path": "github-repos/lean/subfish-zhou-N2Lean/N2Lean-8e858cc5b01f1ad921094dc355db3cb9473a42fd/library/init/algebra/functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7289671545304852}}
{"text": "/-\nCollection of congruence lemmas\nAuthor: Adri\u00e1n Do\u00f1a Mateo\n-/\n\nimport data.nat.modeq\nimport data.zmod.basic\n\nnamespace nat\nnamespace modeq\n\ntheorem not_modeq_of_lt {a b n : \u2115} (hb : b < n) :\n\ta < b \u2192 \u00ac a \u2261 b [MOD n] :=\nbegin\n\tintro ha,\n\trw modeq_iff_dvd' (le_of_lt ha),\n\tintro hdvd,\n\tapply not_le_of_gt hb,\n\tcalc n\n\t\t\t\u2264 b - a : le_of_dvd (nat.sub_pos_of_lt ha) hdvd\n\t... \u2264 b     : sub_le b a,\nend\n\ntheorem modeq_lt_iff {a b n : \u2115} (ha : a < n) (hb : b < n) :\n\ta \u2261 b [MOD n] \u2194 a = b :=\nbegin\n\tsplit, swap,\n\t{ intro h, rw h },\n\tby_cases h : a < b,\n\t{ intro hab,\n\t\texfalso,\n\t\texact not_modeq_of_lt hb h hab },\n\tintro hab,\n\tsymmetry,\n\tby_contradiction hne,\n\tapply not_modeq_of_lt ha _ (modeq.symm hab),\n\texact lt_of_le_of_ne (le_of_not_lt h) hne,\nend\n\ntheorem not_modeq_lt_iff {a b n : \u2115} (ha : a < n) (hb : b < n) :\n\t\u00ac a \u2261 b [MOD n] \u2194 a \u2260 b :=\nnot_iff_not.mpr (modeq_lt_iff ha hb)\n\ntheorem not_modeq_of_modeq {a b c n : \u2115} (hb : b < n) (hc : c < n) (ha : a \u2261 b [MOD n]) :\n\tb \u2260 c \u2192 \u00ac a \u2261 c [MOD n] :=\n\u03bb hbc hac, (not_modeq_lt_iff hb hc).mpr hbc (modeq.trans (modeq.symm ha) hac)\n\nlemma modeq_add_mul_mod {a n : \u2115} (k : \u2115) : a \u2261 a + n * k [MOD n] := by simp [modeq]\n\nlemma add_mul_mod_of_modeq {a b n : \u2115} (hab : a \u2264 b) (h : a \u2261 b [MOD n]) :\n\t\u2203 k, a + n * k = b :=\nbegin\n\trw modeq.modeq_iff_dvd' hab at h,\n\tcases h with k hk, use k,\n\trw [\u2190 hk, nat.add_sub_cancel' hab],\nend\n\nend modeq\nend nat\n\nnamespace zmod\n\ntheorem one_or_two_of_sq_eq_one {a : zmod 3} (h : a * a = \u21911) : a = 1 \u2228 a = 2 := by dec_trivial!\n\nend zmod", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/imo/modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7289100357894857}}
{"text": "/-\nCopyright (c) 2018 Jan-David Salchow. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jan-David Salchow, Patrick Massot\n-/\nimport topology.subset_properties\nimport topology.metric_space.basic\n\n/-!\n# Sequences in topological spaces\n\nIn this file we define sequences in topological spaces and show how they are related to\nfilters and the topology. In particular, we\n* define the sequential closure of a set and prove that it's contained in the closure,\n* define a type class \"sequential_space\" in which closure and sequential closure agree,\n* define sequential continuity and show that it coincides with continuity in sequential spaces,\n* provide an instance that shows that every first-countable (and in particular metric) space is\n  a sequential space.\n* define sequential compactness, prove that compactness implies sequential compactness in first\n  countable spaces, and prove they are equivalent for uniform spaces having a countable uniformity\n  basis (in particular metric spaces).\n-/\n\nopen set filter\nopen_locale topological_space\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n\nlocal notation f ` \u27f6 ` limit := tendsto f at_top (\ud835\udcdd limit)\n\n/-! ### Sequential closures, sequential continuity, and sequential spaces. -/\nsection topological_space\nvariables [topological_space \u03b1] [topological_space \u03b2]\n\n/-- A sequence converges in the sence of topological spaces iff the associated statement for filter\nholds. -/\nlemma topological_space.seq_tendsto_iff {x : \u2115 \u2192 \u03b1} {limit : \u03b1} :\n  tendsto x at_top (\ud835\udcdd limit) \u2194\n    \u2200 U : set \u03b1, limit \u2208 U \u2192 is_open U \u2192 \u2203 N, \u2200 n \u2265 N, (x n) \u2208 U :=\n(at_top_basis.tendsto_iff (nhds_basis_opens limit)).trans $\n  by simp only [and_imp, exists_prop, true_and, set.mem_Ici, ge_iff_le, id]\n\n/-- The sequential closure of a subset M \u2286 \u03b1 of a topological space \u03b1 is\nthe set of all p \u2208 \u03b1 which arise as limit of sequences in M. -/\ndef sequential_closure (M : set \u03b1) : set \u03b1 :=\n{p | \u2203 x : \u2115 \u2192 \u03b1, (\u2200 n : \u2115, x n \u2208 M) \u2227 (x \u27f6 p)}\n\nlemma subset_sequential_closure (M : set \u03b1) : M \u2286 sequential_closure M :=\nassume p (_ : p \u2208 M), show p \u2208 sequential_closure M, from\n  \u27e8\u03bb n, p, assume n, \u2039p \u2208 M\u203a, tendsto_const_nhds\u27e9\n\n/-- A set `s` is sequentially closed if for any converging sequence `x n` of elements of `s`,\nthe limit belongs to `s` as well. -/\ndef is_seq_closed (s : set \u03b1) : Prop := s = sequential_closure s\n\n/-- A convenience lemma for showing that a set is sequentially closed. -/\nlemma is_seq_closed_of_def {A : set \u03b1}\n  (h : \u2200(x : \u2115 \u2192 \u03b1) (p : \u03b1), (\u2200 n : \u2115, x n \u2208 A) \u2192 (x \u27f6 p) \u2192 p \u2208 A) : is_seq_closed A :=\nshow A = sequential_closure A, from subset.antisymm\n  (subset_sequential_closure A)\n  (show \u2200 p, p \u2208 sequential_closure A \u2192 p \u2208 A, from\n    (assume p \u27e8x, _, _\u27e9, show p \u2208 A, from h x p \u2039\u2200 n : \u2115, ((x n) \u2208 A)\u203a \u2039(x \u27f6 p)\u203a))\n\n/-- The sequential closure of a set is contained in the closure of that set.\nThe converse is not true. -/\nlemma sequential_closure_subset_closure (M : set \u03b1) : sequential_closure M \u2286 closure M :=\nassume p \u27e8x, xM, xp\u27e9,\nmem_closure_of_tendsto xp (univ_mem' xM)\n\n/-- A set is sequentially closed if it is closed. -/\nlemma is_seq_closed_of_is_closed (M : set \u03b1) (_ : is_closed M) : is_seq_closed M :=\nsuffices sequential_closure M \u2286 M, from\n  set.eq_of_subset_of_subset (subset_sequential_closure M) this,\ncalc sequential_closure M \u2286 closure M : sequential_closure_subset_closure M\n  ... = M : is_closed.closure_eq \u2039is_closed M\u203a\n\n/-- The limit of a convergent sequence in a sequentially closed set is in that set.-/\nlemma mem_of_is_seq_closed {A : set \u03b1} (_ : is_seq_closed A) {x : \u2115 \u2192 \u03b1}\n  (_ : \u2200 n, x n \u2208 A) {limit : \u03b1} (_ : (x \u27f6 limit)) : limit \u2208 A :=\nhave limit \u2208 sequential_closure A, from\n  show \u2203 x : \u2115 \u2192 \u03b1, (\u2200 n : \u2115, x n \u2208 A) \u2227 (x \u27f6 limit), from \u27e8x, \u2039\u2200 n, x n \u2208 A\u203a, \u2039(x \u27f6 limit)\u203a\u27e9,\neq.subst (eq.symm \u2039is_seq_closed A\u203a) \u2039limit \u2208 sequential_closure A\u203a\n\n/-- The limit of a convergent sequence in a closed set is in that set.-/\nlemma mem_of_is_closed_sequential {A : set \u03b1} (_ : is_closed A) {x : \u2115 \u2192 \u03b1}\n  (_ : \u2200 n, x n \u2208 A) {limit : \u03b1} (_ : x \u27f6 limit) : limit \u2208 A :=\nmem_of_is_seq_closed (is_seq_closed_of_is_closed A \u2039is_closed A\u203a) \u2039\u2200 n, x n \u2208 A\u203a \u2039(x \u27f6 limit)\u203a\n\n/-- A sequential space is a space in which 'sequences are enough to probe the topology'. This can be\n formalised by demanding that the sequential closure and the closure coincide. The following\n statements show that other topological properties can be deduced from sequences in sequential\n spaces. -/\nclass sequential_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(sequential_closure_eq_closure : \u2200 M : set \u03b1, sequential_closure M = closure M)\n\n/-- In a sequential space, a set is closed iff it's sequentially closed. -/\nlemma is_seq_closed_iff_is_closed [sequential_space \u03b1] {M : set \u03b1} :\n  is_seq_closed M \u2194 is_closed M :=\niff.intro\n  (assume _, closure_eq_iff_is_closed.mp (eq.symm\n    (calc M = sequential_closure M : by assumption\n        ... = closure M            : sequential_space.sequential_closure_eq_closure M)))\n  (is_seq_closed_of_is_closed M)\n\n/-- In a sequential space, a point belongs to the closure of a set iff it is a limit of a sequence\ntaking values in this set. -/\nlemma mem_closure_iff_seq_limit [sequential_space \u03b1] {s : set \u03b1} {a : \u03b1} :\n  a \u2208 closure s \u2194 \u2203 x : \u2115 \u2192 \u03b1, (\u2200 n : \u2115, x n \u2208 s) \u2227 (x \u27f6 a) :=\nby { rw \u2190 sequential_space.sequential_closure_eq_closure, exact iff.rfl }\n\n/-- A function between topological spaces is sequentially continuous if it commutes with limit of\n convergent sequences. -/\ndef sequentially_continuous (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 (x : \u2115 \u2192 \u03b1), \u2200 {limit : \u03b1}, (x \u27f6 limit) \u2192 (f\u2218x \u27f6 f limit)\n\n/- A continuous function is sequentially continuous. -/\nlemma continuous.to_sequentially_continuous {f : \u03b1 \u2192 \u03b2} (_ : continuous f) :\n  sequentially_continuous f :=\nassume x limit (_ : x \u27f6 limit),\nhave tendsto f (\ud835\udcdd limit) (\ud835\udcdd (f limit)), from continuous.tendsto \u2039continuous f\u203a limit,\nshow (f \u2218 x) \u27f6 (f limit), from tendsto.comp this \u2039(x \u27f6 limit)\u203a\n\n/-- In a sequential space, continuity and sequential continuity coincide. -/\nlemma continuous_iff_sequentially_continuous {f : \u03b1 \u2192 \u03b2} [sequential_space \u03b1] :\n  continuous f \u2194 sequentially_continuous f :=\niff.intro\n  (assume _, \u2039continuous f\u203a.to_sequentially_continuous)\n  (assume : sequentially_continuous f, show continuous f, from\n    suffices h : \u2200 {A : set \u03b2}, is_closed A \u2192 is_seq_closed (f \u207b\u00b9' A), from\n      continuous_iff_is_closed.mpr (assume A _, is_seq_closed_iff_is_closed.mp $ h \u2039is_closed A\u203a),\n    assume A (_ : is_closed A),\n      is_seq_closed_of_def $\n        assume (x : \u2115 \u2192 \u03b1) p (_ : \u2200 n, f (x n) \u2208 A) (_ : x \u27f6 p),\n        have (f \u2218 x) \u27f6 (f p), from \u2039sequentially_continuous f\u203a x \u2039(x \u27f6 p)\u203a,\n        show f p \u2208 A, from\n          mem_of_is_closed_sequential \u2039is_closed A\u203a \u2039\u2200 n, f (x n) \u2208 A\u203a \u2039(f\u2218x \u27f6 f p)\u203a)\n\nend topological_space\n\nnamespace topological_space\n\nnamespace first_countable_topology\n\nvariables [topological_space \u03b1] [first_countable_topology \u03b1]\n\n/-- Every first-countable space is sequential. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance : sequential_space \u03b1 :=\n\u27e8show \u2200 M, sequential_closure M = closure M, from assume M,\n  suffices closure M \u2286 sequential_closure M,\n    from set.subset.antisymm (sequential_closure_subset_closure M) this,\n  -- For every p \u2208 closure M, we need to construct a sequence x in M that converges to p:\n  assume (p : \u03b1) (hp : p \u2208 closure M),\n  -- Since we are in a first-countable space, the neighborhood filter around `p` has a decreasing\n  -- basis `U` indexed by `\u2115`.\n  let \u27e8U, hU\u27e9 := (\ud835\udcdd p).exists_antitone_basis in\n  -- Since `p \u2208 closure M`, there is an element in each `M \u2229 U i`\n  have hp : \u2200 (i : \u2115), \u2203 (y : \u03b1), y \u2208 M \u2227 y \u2208 U i,\n    by simpa using (mem_closure_iff_nhds_basis hU.1).mp hp,\n  begin\n    -- The axiom of (countable) choice builds our sequence from the later fact\n    choose u hu using hp,\n    rw forall_and_distrib at hu,\n    -- It clearly takes values in `M`\n    use [u, hu.1],\n    -- and converges to `p` because the basis is decreasing.\n    apply hU.tendsto hu.2,\n  end\u27e9\n\n\nend first_countable_topology\n\nend topological_space\n\nsection seq_compact\nopen topological_space topological_space.first_countable_topology\nvariables [topological_space \u03b1]\n\n/-- A set `s` is sequentially compact if every sequence taking values in `s` has a\nconverging subsequence. -/\ndef is_seq_compact (s : set \u03b1) :=\n  \u2200 \u2983u : \u2115 \u2192 \u03b1\u2984, (\u2200 n, u n \u2208 s) \u2192\n    \u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x)\n\n/-- A space `\u03b1` is sequentially compact if every sequence in `\u03b1` has a\nconverging subsequence. -/\nclass seq_compact_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(seq_compact_univ : is_seq_compact (univ : set \u03b1))\n\nlemma is_seq_compact.subseq_of_frequently_in {s : set \u03b1} (hs : is_seq_compact s) {u : \u2115 \u2192 \u03b1}\n  (hu : \u2203\u1da0 n in at_top, u n \u2208 s) :\n  \u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nlet \u27e8\u03c8, h\u03c8, hu\u03c8\u27e9 := extraction_of_frequently_at_top hu, \u27e8x, x_in, \u03c6, h\u03c6, h\u27e9 := hs hu\u03c8 in\n\u27e8x, x_in, \u03c8 \u2218 \u03c6, h\u03c8.comp h\u03c6, h\u27e9\n\nlemma seq_compact_space.tendsto_subseq [seq_compact_space \u03b1] (u : \u2115 \u2192 \u03b1) :\n  \u2203 x (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nlet \u27e8x, _, \u03c6, mono, h\u27e9 := seq_compact_space.seq_compact_univ (by simp : \u2200 n, u n \u2208 univ) in\n\u27e8x, \u03c6, mono, h\u27e9\n\nsection first_countable_topology\nvariables [first_countable_topology \u03b1]\nopen topological_space.first_countable_topology\n\nlemma is_compact.is_seq_compact {s : set \u03b1} (hs : is_compact s) : is_seq_compact s :=\n\u03bb u u_in,\nlet \u27e8x, x_in, hx\u27e9 := @hs (map u at_top) _\n  (le_principal_iff.mpr (univ_mem' u_in : _)) in \u27e8x, x_in, tendsto_subseq hx\u27e9\n\nlemma is_compact.tendsto_subseq' {s : set \u03b1} {u : \u2115 \u2192 \u03b1} (hs : is_compact s)\n  (hu : \u2203\u1da0 n in at_top, u n \u2208 s) :\n\u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nhs.is_seq_compact.subseq_of_frequently_in hu\n\nlemma is_compact.tendsto_subseq {s : set \u03b1} {u : \u2115 \u2192 \u03b1} (hs : is_compact s) (hu : \u2200 n, u n \u2208 s) :\n\u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nhs.is_seq_compact hu\n\n@[priority 100] -- see Note [lower instance priority]\ninstance first_countable_topology.seq_compact_of_compact [compact_space \u03b1] : seq_compact_space \u03b1 :=\n\u27e8compact_univ.is_seq_compact\u27e9\n\nlemma compact_space.tendsto_subseq [compact_space \u03b1] (u : \u2115 \u2192 \u03b1) :\n  \u2203 x (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nseq_compact_space.tendsto_subseq u\n\nend first_countable_topology\nend seq_compact\n\nsection uniform_space_seq_compact\n\nopen_locale uniformity\nopen uniform_space prod\n\nvariables [uniform_space \u03b2] {s : set \u03b2}\n\nlemma lebesgue_number_lemma_seq {\u03b9 : Type*} [is_countably_generated (\ud835\udce4 \u03b2)] {c : \u03b9 \u2192 set \u03b2}\n  (hs : is_seq_compact s) (hc\u2081 : \u2200 i, is_open (c i)) (hc\u2082 : s \u2286 \u22c3 i, c i) :\n  \u2203 V \u2208 \ud835\udce4 \u03b2, symmetric_rel V \u2227 \u2200 x \u2208 s, \u2203 i, ball x V \u2286 c i :=\nbegin\n  classical,\n  obtain \u27e8V, hV, Vsymm\u27e9 :\n    \u2203 V : \u2115 \u2192 set (\u03b2 \u00d7 \u03b2), (\ud835\udce4 \u03b2).has_antitone_basis V \u2227 \u2200 n, swap \u207b\u00b9' V n = V n,\n      from uniform_space.has_seq_basis \u03b2,\n  suffices : \u2203 n, \u2200 x \u2208 s, \u2203 i, ball x (V n) \u2286 c i,\n  { cases this with n hn,\n    exact \u27e8V n, hV.to_has_basis.mem_of_mem trivial, Vsymm n, hn\u27e9 },\n  by_contradiction H,\n  obtain \u27e8x, x_in, hx\u27e9 : \u2203 x : \u2115 \u2192 \u03b2, (\u2200 n, x n \u2208 s) \u2227 \u2200 n i, \u00ac ball (x n) (V n) \u2286 c i,\n  { push_neg at H,\n    choose x hx using H,\n    exact \u27e8x, forall_and_distrib.mp hx\u27e9 }, clear H,\n  obtain \u27e8x\u2080, x\u2080_in, \u03c6, \u03c6_mono, hlim\u27e9 : \u2203 (x\u2080 \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 x\u2080),\n    from hs x_in, clear hs,\n  obtain \u27e8i\u2080, x\u2080_in\u27e9 : \u2203 i\u2080, x\u2080 \u2208 c i\u2080,\n  { rcases hc\u2082 x\u2080_in with \u27e8_, \u27e8i\u2080, rfl\u27e9, x\u2080_in_c\u27e9,\n    exact \u27e8i\u2080, x\u2080_in_c\u27e9 }, clear hc\u2082,\n  obtain \u27e8n\u2080, hn\u2080\u27e9 : \u2203 n\u2080, ball x\u2080 (V n\u2080) \u2286 c i\u2080,\n  { rcases (nhds_basis_uniformity hV.to_has_basis).mem_iff.mp\n      (is_open_iff_mem_nhds.mp (hc\u2081 i\u2080) _ x\u2080_in) with \u27e8n\u2080, _, h\u27e9,\n    use n\u2080,\n    rwa \u2190 ball_eq_of_symmetry (Vsymm n\u2080) at h }, clear hc\u2081,\n  obtain \u27e8W, W_in, hWW\u27e9 : \u2203 W \u2208 \ud835\udce4 \u03b2, W \u25cb W \u2286 V n\u2080,\n    from comp_mem_uniformity_sets (hV.to_has_basis.mem_of_mem trivial),\n  obtain \u27e8N, x_\u03c6_N_in, hVNW\u27e9 : \u2203 N, x (\u03c6 N) \u2208 ball x\u2080 W \u2227 V (\u03c6 N) \u2286 W,\n  { obtain \u27e8N\u2081, h\u2081\u27e9 : \u2203 N\u2081, \u2200 n \u2265 N\u2081, x (\u03c6 n) \u2208 ball x\u2080 W,\n      from tendsto_at_top'.mp hlim _ (mem_nhds_left x\u2080 W_in),\n    obtain \u27e8N\u2082, h\u2082\u27e9 : \u2203 N\u2082, V (\u03c6 N\u2082) \u2286 W,\n    { rcases hV.to_has_basis.mem_iff.mp W_in with \u27e8N, _, hN\u27e9,\n      use N,\n      exact subset.trans (hV.antitone $ \u03c6_mono.id_le _) hN },\n    have : \u03c6 N\u2082 \u2264 \u03c6 (max N\u2081 N\u2082),\n      from \u03c6_mono.le_iff_le.mpr (le_max_right _ _),\n    exact \u27e8max N\u2081 N\u2082, h\u2081 _ (le_max_left _ _), trans (hV.antitone this) h\u2082\u27e9 },\n  suffices : ball (x (\u03c6 N)) (V (\u03c6 N)) \u2286 c i\u2080,\n    from hx (\u03c6 N) i\u2080 this,\n  calc\n    ball (x $ \u03c6 N) (V $ \u03c6 N) \u2286 ball (x $ \u03c6 N) W : preimage_mono hVNW\n                         ... \u2286 ball x\u2080 (V n\u2080)   : ball_subset_of_comp_subset x_\u03c6_N_in hWW\n                         ... \u2286 c i\u2080             : hn\u2080,\nend\n\nlemma is_seq_compact.totally_bounded (h : is_seq_compact s) : totally_bounded s :=\nbegin\n  classical,\n  apply totally_bounded_of_forall_symm,\n  unfold is_seq_compact at h,\n  contrapose! h,\n  rcases h with \u27e8V, V_in, V_symm, h\u27e9,\n  simp_rw [not_subset] at h,\n  have : \u2200 (t : set \u03b2), finite t \u2192 \u2203 a, a \u2208 s \u2227 a \u2209 \u22c3 y \u2208 t, ball y V,\n  { intros t ht,\n    obtain \u27e8a, a_in, H\u27e9 : \u2203 a \u2208 s, \u2200 (x : \u03b2), x \u2208 t \u2192 (x, a) \u2209 V,\n      by simpa [ht] using h t,\n    use [a, a_in],\n    intro H',\n    obtain \u27e8x, x_in, hx\u27e9 := mem_bUnion_iff.mp H',\n    exact H x x_in hx },\n  cases seq_of_forall_finite_exists this with u hu, clear h this,\n  simp [forall_and_distrib] at hu,\n  cases hu with u_in hu,\n  use [u, u_in], clear u_in,\n  intros x x_in \u03c6,\n  intros h\u03c6 hu\u03c6,\n  obtain \u27e8N, hN\u27e9 : \u2203 N, \u2200 p q, p \u2265 N \u2192 q \u2265 N \u2192 (u (\u03c6 p), u (\u03c6 q)) \u2208 V,\n    from hu\u03c6.cauchy_seq.mem_entourage V_in,\n  specialize hN N (N+1) (le_refl N) (nat.le_succ N),\n  specialize hu (\u03c6 $ N+1) (\u03c6 N) (h\u03c6 $ lt_add_one N),\n  exact hu hN,\nend\n\nprotected lemma is_seq_compact.is_compact [is_countably_generated $ \ud835\udce4 \u03b2] (hs : is_seq_compact s) :\n  is_compact s :=\nbegin\n  classical,\n  rw is_compact_iff_finite_subcover,\n  intros \u03b9 U Uop s_sub,\n  rcases lebesgue_number_lemma_seq hs Uop s_sub with \u27e8V, V_in, Vsymm, H\u27e9,\n  rcases totally_bounded_iff_subset.mp hs.totally_bounded V V_in with \u27e8t,t_sub, tfin,  ht\u27e9,\n  have : \u2200 x : t, \u2203 (i : \u03b9), ball x.val V \u2286 U i,\n  { rintros \u27e8x, x_in\u27e9,\n    exact H x (t_sub x_in) },\n  choose i hi using this,\n  haveI : fintype t := tfin.fintype,\n  use finset.image i finset.univ,\n  transitivity \u22c3 y \u2208 t, ball y V,\n  { intros x x_in,\n    specialize ht x_in,\n    rw mem_bUnion_iff at *,\n    simp_rw ball_eq_of_symmetry Vsymm,\n    exact ht },\n  { apply bUnion_subset_bUnion,\n    intros x x_in,\n    exact \u27e8i \u27e8x, x_in\u27e9, finset.mem_image_of_mem _ (finset.mem_univ _), hi \u27e8x, x_in\u27e9\u27e9 },\nend\n\n/-- A version of Bolzano-Weistrass: in a uniform space with countably generated uniformity filter\n(e.g., in a metric space), a set is compact if and only if it is sequentially compact. -/\nprotected lemma uniform_space.compact_iff_seq_compact [is_countably_generated $ \ud835\udce4 \u03b2] :\n is_compact s \u2194 is_seq_compact s :=\n\u27e8\u03bb H, H.is_seq_compact, \u03bb H, H.is_compact\u27e9\n\nlemma uniform_space.compact_space_iff_seq_compact_space [is_countably_generated $ \ud835\udce4 \u03b2] :\n  compact_space \u03b2 \u2194 seq_compact_space \u03b2 :=\nhave key : is_compact (univ : set \u03b2) \u2194 is_seq_compact univ := uniform_space.compact_iff_seq_compact,\n\u27e8\u03bb \u27e8h\u27e9, \u27e8key.mp h\u27e9, \u03bb \u27e8h\u27e9, \u27e8key.mpr h\u27e9\u27e9\n\nend uniform_space_seq_compact\n\nsection metric_seq_compact\n\nvariables [metric_space \u03b2] {s : set \u03b2}\nopen metric\n\n/-- A version of Bolzano-Weistrass: in a proper metric space (eg. $\u211d^n$),\nevery bounded sequence has a converging subsequence. This version assumes only\nthat the sequence is frequently in some bounded set. -/\nlemma tendsto_subseq_of_frequently_bounded [proper_space \u03b2] (hs : bounded s)\n  {u : \u2115 \u2192 \u03b2} (hu : \u2203\u1da0 n in at_top, u n \u2208 s) :\n  \u2203 b \u2208 closure s, \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd b) :=\nbegin\n  have hcs : is_compact (closure s) :=\n    compact_iff_closed_bounded.mpr \u27e8is_closed_closure, bounded_closure_of_bounded hs\u27e9,\n  replace hcs : is_seq_compact (closure s),\n    from uniform_space.compact_iff_seq_compact.mp hcs,\n  have hu' : \u2203\u1da0 n in at_top, u n \u2208 closure s,\n  { apply frequently.mono hu,\n    intro n,\n    apply subset_closure },\n  exact hcs.subseq_of_frequently_in hu',\nend\n\n/-- A version of Bolzano-Weistrass: in a proper metric space (eg. $\u211d^n$),\nevery bounded sequence has a converging subsequence. -/\nlemma tendsto_subseq_of_bounded [proper_space \u03b2] (hs : bounded s)\n  {u : \u2115 \u2192 \u03b2} (hu : \u2200 n, u n \u2208 s) :\n\u2203 b \u2208 closure s, \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd b) :=\ntendsto_subseq_of_frequently_bounded hs $ frequently_of_forall hu\n\nlemma seq_compact.lebesgue_number_lemma_of_metric\n  {\u03b9 : Type*} {c : \u03b9 \u2192 set \u03b2} (hs : is_seq_compact s)\n  (hc\u2081 : \u2200 i, is_open (c i)) (hc\u2082 : s \u2286 \u22c3 i, c i) :\n  \u2203 \u03b4 > 0, \u2200 x \u2208 s, \u2203 i, ball x \u03b4 \u2286 c i :=\nbegin\n  rcases lebesgue_number_lemma_seq hs hc\u2081 hc\u2082 with \u27e8V, V_in, _, hV\u27e9,\n  rcases uniformity_basis_dist.mem_iff.mp V_in with \u27e8\u03b4, \u03b4_pos, h\u27e9,\n  use [\u03b4, \u03b4_pos],\n  intros x x_in,\n  rcases hV x x_in with \u27e8i, hi\u27e9,\n  use i,\n  have := ball_mono h x,\n  rw ball_eq_ball' at this,\n  exact subset.trans this hi,\nend\n\nend metric_seq_compact\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7288567374592073}}
{"text": "/-\nCopyright (c) 2018 Louis Carlin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Louis Carlin, Mario Carneiro\n-/\nimport logic.nontrivial\nimport algebra.divisibility.basic\nimport algebra.group.basic\nimport algebra.ring.defs\n\n/-!\n# Euclidean domains\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file introduces Euclidean domains and provides the extended Euclidean algorithm. To be precise,\na slightly more general version is provided which is sometimes called a transfinite Euclidean domain\nand differs in the fact that the degree function need not take values in `\u2115` but can take values in\nany well-ordered set. Transfinite Euclidean domains were introduced by Motzkin and examples which\ndon't satisfy the classical notion were provided independently by Hiblot and Nagata.\n\n## Main definitions\n\n* `euclidean_domain`: Defines Euclidean domain with functions `quotient` and `remainder`. Instances\n  of `has_div` and `has_mod` are provided, so that one can write `a = b * (a / b) + a % b`.\n* `gcd`: defines the greatest common divisors of two elements of a Euclidean domain.\n* `xgcd`: given two elements `a b : R`, `xgcd a b` defines the pair `(x, y)` such that\n  `x * a + y * b = gcd a b`.\n* `lcm`: defines the lowest common multiple of two elements `a` and `b` of a Euclidean domain as\n  `a * b / (gcd a b)`\n\n## Main statements\n\nSee `algebra.euclidean_domain.basic` for most of the theorems about Eucliean domains,\nincluding B\u00e9zout's lemma.\n\nSee `algebra.euclidean_domain.instances` for that facts that `\u2124` is a Euclidean domain,\nas is any field.\n\n## Notation\n\n`\u227a` denotes the well founded relation on the Euclidean domain, e.g. in the example of the polynomial\nring over a field, `p \u227a q` for polynomials `p` and `q` if and only if the degree of `p` is less than\nthe degree of `q`.\n\n## Implementation details\n\nInstead of working with a valuation, `euclidean_domain` is implemented with the existence of a well\nfounded relation `r` on the integral domain `R`, which in the example of `\u2124` would correspond to\nsetting `i \u227a j` for integers `i` and `j` if the absolute value of `i` is smaller than the absolute\nvalue of `j`.\n\n## References\n\n* [Th. Motzkin, *The Euclidean algorithm*][MR32592]\n* [J.-J. Hiblot, *Des anneaux euclidiens dont le plus petit algorithme n'est pas \u00e0 valeurs finies*]\n  [MR399081]\n* [M. Nagata, *On Euclid algorithm*][MR541021]\n\n\n## Tags\n\nEuclidean domain, transfinite Euclidean domain, B\u00e9zout's lemma\n-/\n\nuniverse u\n\n/-- A `euclidean_domain` is an non-trivial commutative ring with a division and a remainder,\n  satisfying `b * (a / b) + a % b = a`.\n  The definition of a euclidean domain usually includes a valuation function `R \u2192 \u2115`.\n  This definition is slightly generalised to include a well founded relation\n  `r` with the property that `r (a % b) b`, instead of a valuation.  -/\n@[protect_proj without mul_left_not_lt r_well_founded]\nclass euclidean_domain (R : Type u) extends comm_ring R, nontrivial R :=\n(quotient : R \u2192 R \u2192 R)\n(quotient_zero : \u2200 a, quotient a 0 = 0)\n(remainder : R \u2192 R \u2192 R)\n(quotient_mul_add_remainder_eq : \u2200 a b, b * quotient a b + remainder a b = a)\n(r : R \u2192 R \u2192 Prop)\n(r_well_founded : well_founded r)\n(remainder_lt : \u2200 a {b}, b \u2260 0 \u2192 r (remainder a b) b)\n(mul_left_not_lt : \u2200 a {b}, b \u2260 0 \u2192 \u00acr (a * b) a)\n\nnamespace euclidean_domain\nvariable {R : Type u}\nvariables [euclidean_domain R]\n\nlocal infix ` \u227a `:50 := euclidean_domain.r\n\n@[priority 70] -- see Note [lower instance priority]\ninstance : has_div R := \u27e8euclidean_domain.quotient\u27e9\n\n@[priority 70] -- see Note [lower instance priority]\ninstance : has_mod R := \u27e8euclidean_domain.remainder\u27e9\n\ntheorem div_add_mod (a b : R) : b * (a / b) + a % b = a :=\neuclidean_domain.quotient_mul_add_remainder_eq _ _\n\nlemma mod_add_div (a b : R) : a % b + b * (a / b) = a :=\n(add_comm _ _).trans (div_add_mod _ _)\n\nlemma mod_add_div' (m k : R) : m % k + (m / k) * k = m :=\nby { rw mul_comm, exact mod_add_div _ _ }\n\nlemma div_add_mod' (m k : R) : (m / k) * k + m % k = m :=\nby { rw mul_comm, exact div_add_mod _ _ }\n\nlemma mod_eq_sub_mul_div {R : Type*} [euclidean_domain R] (a b : R) :\n  a % b = a - b * (a / b) :=\ncalc a % b = b * (a / b) + a % b - b * (a / b) : (add_sub_cancel' _ _).symm\n... = a - b * (a / b) : by rw div_add_mod\n\ntheorem mod_lt : \u2200 a {b : R}, b \u2260 0 \u2192 (a % b) \u227a b :=\neuclidean_domain.remainder_lt\n\ntheorem mul_right_not_lt {a : R} (b) (h : a \u2260 0) : \u00ac(a * b) \u227a b :=\nby { rw mul_comm, exact mul_left_not_lt b h }\n\n@[simp] lemma mod_zero (a : R) : a % 0 = a :=\nby simpa only [zero_mul, zero_add] using div_add_mod a 0\n\nlemma lt_one (a : R) : a \u227a (1:R) \u2192 a = 0 :=\nby { haveI := classical.dec, exact\n  not_imp_not.1 (\u03bb h, by simpa only [one_mul] using mul_left_not_lt 1 h) }\n\n\n\n@[simp, priority 900] lemma div_zero (a : R) : a / 0 = 0 :=\neuclidean_domain.quotient_zero a\n\nsection\nopen_locale classical\n\n@[elab_as_eliminator]\ntheorem gcd.induction {P : R \u2192 R \u2192 Prop} : \u2200 a b : R,\n  (\u2200 x, P 0 x) \u2192\n  (\u2200 a b, a \u2260 0 \u2192 P (b % a) a \u2192 P a b) \u2192\n  P a b\n| a := \u03bb b H0 H1, if a0 : a = 0 then a0.symm \u25b8 H0 _ else\n  have h:_ := mod_lt b a0,\n  H1 _ _ a0 (gcd.induction (b%a) a H0 H1)\nusing_well_founded {dec_tac := tactic.assumption,\n  rel_tac := \u03bb _ _, `[exact \u27e8_, r_well_founded\u27e9]}\n\nend\n\nsection gcd\nvariable [decidable_eq R]\n\n/-- `gcd a b` is a (non-unique) element such that `gcd a b \u2223 a` `gcd a b \u2223 b`, and for\n  any element `c` such that `c \u2223 a` and `c \u2223 b`, then `c \u2223 gcd a b` -/\ndef gcd : R \u2192 R \u2192 R\n| a := \u03bb b, if a0 : a = 0 then b else\n  have h:_ := mod_lt b a0,\n  gcd (b%a) a\nusing_well_founded {dec_tac := tactic.assumption,\n  rel_tac := \u03bb _ _, `[exact \u27e8_, r_well_founded\u27e9]}\n\n@[simp] theorem gcd_zero_left (a : R) : gcd 0 a = a :=\nby { rw gcd, exact if_pos rfl }\n\n/--\nAn implementation of the extended GCD algorithm.\nAt each step we are computing a triple `(r, s, t)`, where `r` is the next value of the GCD\nalgorithm, to compute the greatest common divisor of the input (say `x` and `y`), and `s` and `t`\nare the coefficients in front of `x` and `y` to obtain `r` (i.e. `r = s * x + t * y`).\nThe function `xgcd_aux` takes in two triples, and from these recursively computes the next triple:\n```\nxgcd_aux (r, s, t) (r', s', t') = xgcd_aux (r' % r, s' - (r' / r) * s, t' - (r' / r) * t) (r, s, t)\n```\n-/\ndef xgcd_aux : R \u2192 R \u2192 R \u2192 R \u2192 R \u2192 R \u2192 R \u00d7 R \u00d7 R\n| r := \u03bb s t r' s' t',\nif hr : r = 0 then (r', s', t')\n  else\n  have r' % r \u227a r, from mod_lt _ hr,\n  let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t\nusing_well_founded {dec_tac := tactic.assumption,\n  rel_tac := \u03bb _ _, `[exact \u27e8_, r_well_founded\u27e9]}\n\n@[simp] theorem xgcd_zero_left {s t r' s' t' : R} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=\nby { unfold xgcd_aux, exact if_pos rfl }\n\ntheorem xgcd_aux_rec {r s t r' s' t' : R} (h : r \u2260 0) :\n  xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=\nby { conv {to_lhs, rw [xgcd_aux]}, exact if_neg h}\n\n/-- Use the extended GCD algorithm to generate the `a` and `b` values\n  satisfying `gcd x y = x * a + y * b`. -/\ndef xgcd (x y : R) : R \u00d7 R := (xgcd_aux x 1 0 y 0 1).2\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a (x y : R) : R := (xgcd x y).1\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b (x y : R) : R := (xgcd x y).2\n\n@[simp] theorem gcd_a_zero_left {s : R} : gcd_a 0 s = 0 :=\nby { unfold gcd_a, rw [xgcd, xgcd_zero_left] }\n\n@[simp] theorem gcd_b_zero_left {s : R} : gcd_b 0 s = 1 :=\nby { unfold gcd_b, rw [xgcd, xgcd_zero_left] }\n\ntheorem xgcd_val (x y : R) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nprod.mk.eta.symm\n\nend gcd\n\nsection lcm\nvariables [decidable_eq R]\n\n/-- `lcm a b` is a (non-unique) element such that `a \u2223 lcm a b` `b \u2223 lcm a b`, and for\n  any element `c` such that `a \u2223 c` and `b \u2223 c`, then `lcm a b \u2223 c` -/\ndef lcm (x y : R) : R :=\nx * y / gcd x y\n\nend lcm\n\nend euclidean_domain\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/euclidean_domain/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.728856736846838}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module analysis.complex.roots_of_unity\n! leanprover-community/mathlib commit 17ef379e997badd73e5eabb4d38f11919ab3c4b3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.SpecialFunctions.Complex.Log\nimport Mathbin.RingTheory.RootsOfUnity\n\n/-!\n# Complex roots of unity\n\nIn this file we show that the `n`-th complex roots of unity\nare exactly the complex numbers `e ^ (2 * real.pi * complex.I * (i / n))` for `i \u2208 finset.range n`.\n\n## Main declarations\n\n* `complex.mem_roots_of_unity`: the complex `n`-th roots of unity are exactly the\n  complex numbers of the form `e ^ (2 * real.pi * complex.I * (i / n))` for some `i < n`.\n* `complex.card_roots_of_unity`: the number of `n`-th roots of unity is exactly `n`.\n\n-/\n\n\nnamespace Complex\n\nopen Polynomial Real\n\nopen Nat Real\n\ntheorem isPrimitiveRoot_exp_of_coprime (i n : \u2115) (h0 : n \u2260 0) (hi : i.coprime n) :\n    IsPrimitiveRoot (exp (2 * \u03c0 * I * (i / n))) n :=\n  by\n  rw [IsPrimitiveRoot.iff_def]\n  simp only [\u2190 exp_nat_mul, exp_eq_one_iff]\n  have hn0 : (n : \u2102) \u2260 0 := by exact_mod_cast h0\n  constructor\n  \u00b7 use i\n    field_simp [hn0, mul_comm (i : \u2102), mul_comm (n : \u2102)]\n  \u00b7 simp only [hn0, mul_right_comm _ _ \u2191n, mul_left_inj' two_pi_I_ne_zero, Ne.def, not_false_iff,\n      mul_comm _ (i : \u2102), \u2190 mul_assoc _ (i : \u2102), exists_imp, field_simps]\n    norm_cast\n    rintro l k hk\n    have : n \u2223 i * l := by\n      rw [\u2190 Int.coe_nat_dvd, hk]\n      apply dvd_mul_left\n    exact hi.symm.dvd_of_dvd_mul_left this\n#align complex.is_primitive_root_exp_of_coprime Complex.isPrimitiveRoot_exp_of_coprime\n\ntheorem isPrimitiveRoot_exp (n : \u2115) (h0 : n \u2260 0) : IsPrimitiveRoot (exp (2 * \u03c0 * I / n)) n := by\n  simpa only [Nat.cast_one, one_div] using\n    is_primitive_root_exp_of_coprime 1 n h0 n.coprime_one_left\n#align complex.is_primitive_root_exp Complex.isPrimitiveRoot_exp\n\ntheorem isPrimitiveRoot_iff (\u03b6 : \u2102) (n : \u2115) (hn : n \u2260 0) :\n    IsPrimitiveRoot \u03b6 n \u2194 \u2203 i < (n : \u2115), \u2203 hi : i.coprime n, exp (2 * \u03c0 * I * (i / n)) = \u03b6 :=\n  by\n  have hn0 : (n : \u2102) \u2260 0 := by exact_mod_cast hn\n  constructor; swap\n  \u00b7 rintro \u27e8i, -, hi, rfl\u27e9\n    exact is_primitive_root_exp_of_coprime i n hn hi\n  intro h\n  obtain \u27e8i, hi, rfl\u27e9 :=\n    (is_primitive_root_exp n hn).eq_pow_of_pow_eq_one h.pow_eq_one (Nat.pos_of_ne_zero hn)\n  refine' \u27e8i, hi, ((is_primitive_root_exp n hn).pow_iff_coprime (Nat.pos_of_ne_zero hn) i).mp h, _\u27e9\n  rw [\u2190 exp_nat_mul]\n  congr 1\n  field_simp [hn0, mul_comm (i : \u2102)]\n#align complex.is_primitive_root_iff Complex.isPrimitiveRoot_iff\n\n/-- The complex `n`-th roots of unity are exactly the\ncomplex numbers of the form `e ^ (2 * real.pi * complex.I * (i / n))` for some `i < n`. -/\ntheorem mem_rootsOfUnity (n : \u2115+) (x : Units \u2102) :\n    x \u2208 rootsOfUnity n \u2102 \u2194 \u2203 i < (n : \u2115), exp (2 * \u03c0 * I * (i / n)) = x :=\n  by\n  rw [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one]\n  have hn0 : (n : \u2102) \u2260 0 := by exact_mod_cast n.ne_zero\n  constructor\n  \u00b7 intro h\n    obtain \u27e8i, hi, H\u27e9 : \u2203 i < (n : \u2115), exp (2 * \u03c0 * I / n) ^ i = x := by\n      simpa only using (is_primitive_root_exp n n.ne_zero).eq_pow_of_pow_eq_one h n.pos\n    refine' \u27e8i, hi, _\u27e9\n    rw [\u2190 H, \u2190 exp_nat_mul]\n    congr 1\n    field_simp [hn0, mul_comm (i : \u2102)]\n  \u00b7 rintro \u27e8i, hi, H\u27e9\n    rw [\u2190 H, \u2190 exp_nat_mul, exp_eq_one_iff]\n    use i\n    field_simp [hn0, mul_comm ((n : \u2115) : \u2102), mul_comm (i : \u2102)]\n#align complex.mem_roots_of_unity Complex.mem_rootsOfUnity\n\ntheorem card_rootsOfUnity (n : \u2115+) : Fintype.card (rootsOfUnity n \u2102) = n :=\n  (isPrimitiveRoot_exp n n.NeZero).card_rootsOfUnity\n#align complex.card_roots_of_unity Complex.card_rootsOfUnity\n\ntheorem card_primitiveRoots (k : \u2115) : (primitiveRoots k \u2102).card = \u03c6 k :=\n  by\n  by_cases h : k = 0\n  \u00b7 simp [h]\n  exact (is_primitive_root_exp k h).card_primitiveRoots\n#align complex.card_primitive_roots Complex.card_primitiveRoots\n\nend Complex\n\ntheorem IsPrimitiveRoot.norm'_eq_one {\u03b6 : \u2102} {n : \u2115} (h : IsPrimitiveRoot \u03b6 n) (hn : n \u2260 0) :\n    \u2016\u03b6\u2016 = 1 :=\n  Complex.norm_eq_one_of_pow_eq_one h.pow_eq_one hn\n#align is_primitive_root.norm'_eq_one IsPrimitiveRoot.norm'_eq_one\n\ntheorem IsPrimitiveRoot.nnnorm_eq_one {\u03b6 : \u2102} {n : \u2115} (h : IsPrimitiveRoot \u03b6 n) (hn : n \u2260 0) :\n    \u2016\u03b6\u2016\u208a = 1 :=\n  Subtype.ext <| h.norm'_eq_one hn\n#align is_primitive_root.nnnorm_eq_one IsPrimitiveRoot.nnnorm_eq_one\n\ntheorem IsPrimitiveRoot.arg_ext {n m : \u2115} {\u03b6 \u03bc : \u2102} (h\u03b6 : IsPrimitiveRoot \u03b6 n)\n    (h\u03bc : IsPrimitiveRoot \u03bc m) (hn : n \u2260 0) (hm : m \u2260 0) (h : \u03b6.arg = \u03bc.arg) : \u03b6 = \u03bc :=\n  Complex.ext_abs_arg ((h\u03b6.norm'_eq_one hn).trans (h\u03bc.norm'_eq_one hm).symm) h\n#align is_primitive_root.arg_ext IsPrimitiveRoot.arg_ext\n\ntheorem IsPrimitiveRoot.arg_eq_zero_iff {n : \u2115} {\u03b6 : \u2102} (h\u03b6 : IsPrimitiveRoot \u03b6 n) (hn : n \u2260 0) :\n    \u03b6.arg = 0 \u2194 \u03b6 = 1 :=\n  \u27e8fun h => h\u03b6.arg_ext IsPrimitiveRoot.one hn one_ne_zero (h.trans Complex.arg_one.symm), fun h =>\n    h.symm \u25b8 Complex.arg_one\u27e9\n#align is_primitive_root.arg_eq_zero_iff IsPrimitiveRoot.arg_eq_zero_iff\n\ntheorem IsPrimitiveRoot.arg_eq_pi_iff {n : \u2115} {\u03b6 : \u2102} (h\u03b6 : IsPrimitiveRoot \u03b6 n) (hn : n \u2260 0) :\n    \u03b6.arg = Real.pi \u2194 \u03b6 = -1 :=\n  \u27e8fun h =>\n    h\u03b6.arg_ext (IsPrimitiveRoot.neg_one 0 two_ne_zero.symm) hn two_ne_zero\n      (h.trans Complex.arg_neg_one.symm),\n    fun h => h.symm \u25b8 Complex.arg_neg_one\u27e9\n#align is_primitive_root.arg_eq_pi_iff IsPrimitiveRoot.arg_eq_pi_iff\n\ntheorem IsPrimitiveRoot.arg {n : \u2115} {\u03b6 : \u2102} (h : IsPrimitiveRoot \u03b6 n) (hn : n \u2260 0) :\n    \u2203 i : \u2124, \u03b6.arg = i / n * (2 * Real.pi) \u2227 IsCoprime i n \u2227 i.natAbs < n :=\n  by\n  rw [Complex.isPrimitiveRoot_iff _ _ hn] at h\n  obtain \u27e8i, h, hin, rfl\u27e9 := h\n  rw [mul_comm, \u2190 mul_assoc, Complex.exp_mul_I]\n  refine' \u27e8if i * 2 \u2264 n then i else i - n, _, _, _\u27e9\n  on_goal 2 =>\n    replace hin := nat.is_coprime_iff_coprime.mpr hin\n    split_ifs with _\n    \u00b7 exact hin\n    \u00b7 convert hin.add_mul_left_left (-1)\n      rw [mul_neg_one, sub_eq_add_neg]\n  on_goal 2 =>\n    split_ifs with h\u2082\n    \u00b7 exact_mod_cast h\n    suffices (i - n : \u2124).natAbs = n - i by\n      rw [this]\n      apply tsub_lt_self hn.bot_lt\n      contrapose! h\u2082\n      rw [Nat.eq_zero_of_le_zero h\u2082, MulZeroClass.zero_mul]\n      exact zero_le _\n    rw [\u2190 Int.natAbs_neg, neg_sub, Int.natAbs_eq_iff]\n    exact Or.inl (Int.ofNat_sub h.le).symm\n  split_ifs with h\u2082\n  \u00b7 convert Complex.arg_cos_add_sin_mul_i _\n    \u00b7 push_cast\n    \u00b7 push_cast\n    field_simp [hn]\n    refine' \u27e8(neg_lt_neg Real.pi_pos).trans_le _, _\u27e9\n    \u00b7 rw [neg_zero]\n      exact mul_nonneg (mul_nonneg i.cast_nonneg <| by simp [real.pi_pos.le]) (by simp)\n    rw [\u2190 mul_rotate', mul_div_assoc]\n    rw [\u2190 mul_one n] at h\u2082\n    exact\n      mul_le_of_le_one_right real.pi_pos.le\n        ((div_le_iff' <| by exact_mod_cast pos_of_gt h).mpr <| by exact_mod_cast h\u2082)\n  rw [\u2190 Complex.cos_sub_two_pi, \u2190 Complex.sin_sub_two_pi]\n  convert Complex.arg_cos_add_sin_mul_i _\n  \u00b7 push_cast\n    rw [\u2190 sub_one_mul, sub_div, div_self]\n    exact_mod_cast hn\n  \u00b7 push_cast\n    rw [\u2190 sub_one_mul, sub_div, div_self]\n    exact_mod_cast hn\n  field_simp [hn]\n  refine' \u27e8_, le_trans _ real.pi_pos.le\u27e9\n  on_goal 2 =>\n    rw [mul_div_assoc]\n    exact\n      mul_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr <| by exact_mod_cast h.le)\n        (div_nonneg (by simp [real.pi_pos.le]) <| by simp)\n  rw [\u2190 mul_rotate', mul_div_assoc, neg_lt, \u2190 mul_neg, mul_lt_iff_lt_one_right Real.pi_pos, \u2190\n    neg_div, \u2190 neg_mul, neg_sub, div_lt_iff, one_mul, sub_mul, sub_lt_comm, \u2190 mul_sub_one]\n  norm_num\n  exact_mod_cast not_le.mp h\u2082\n  \u00b7 exact nat.cast_pos.mpr hn.bot_lt\n#align is_primitive_root.arg IsPrimitiveRoot.arg\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/Complex/RootsOfUnity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7288567311273803}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot, Casper Putz, Anne Baanen\n-/\nimport linear_algebra.matrix.to_lin\n\n/-!\n# Diagonal matrices\n\nThis file contains some results on the linear map corresponding to a\ndiagonal matrix (`range`, `ker` and `rank`).\n\n## Tags\n\nmatrix, diagonal, linear_map\n-/\n\nnoncomputable theory\n\nopen linear_map matrix set submodule\nopen_locale big_operators\nopen_locale matrix\n\nuniverses u v w\n\nnamespace matrix\n\nsection comm_ring\n\nvariables {n : Type*} [fintype n] [decidable_eq n] {R : Type v} [comm_ring R]\n\nlemma proj_diagonal (i : n) (w : n \u2192 R) :\n  (proj i).comp (to_lin' (diagonal w)) = (w i) \u2022 proj i :=\nlinear_map.ext $ \u03bb j, mul_vec_diagonal _ _ _\n\nlemma diagonal_comp_std_basis (w : n \u2192 R) (i : n) :\n  (diagonal w).to_lin'.comp (linear_map.std_basis R (\u03bb_:n, R) i) =\n  (w i) \u2022 linear_map.std_basis R (\u03bb_:n, R) i :=\nlinear_map.ext $ \u03bb x, (diagonal_mul_vec_single w _ _).trans (pi.single_smul' i (w i) x)\n\nlemma diagonal_to_lin' (w : n \u2192 R) :\n  (diagonal w).to_lin' = linear_map.pi (\u03bbi, w i \u2022 linear_map.proj i) :=\nlinear_map.ext $ \u03bb v, funext $ \u03bb i, mul_vec_diagonal _ _ _\n\nend comm_ring\n\nsection field\n\nvariables {m n : Type*} [fintype m] [fintype n]\nvariables {K : Type u} [field K] -- maybe try to relax the universe constraint\n\nlemma ker_diagonal_to_lin' [decidable_eq m] (w : m \u2192 K) :\n  ker (diagonal w).to_lin' = (\u2a06i\u2208{i | w i = 0 }, range (linear_map.std_basis K (\u03bbi, K) i)) :=\nbegin\n  rw [\u2190 comap_bot, \u2190 infi_ker_proj, comap_infi],\n  have := \u03bb i : m, ker_comp (to_lin' (diagonal w)) (proj i),\n  simp only [comap_infi, \u2190 this, proj_diagonal, ker_smul'],\n  have : univ \u2286 {i : m | w i = 0} \u222a {i : m | w i = 0}\u1d9c, { rw set.union_compl_self },\n  exact (supr_range_std_basis_eq_infi_ker_proj K (\u03bbi:m, K)\n    disjoint_compl_right this (set.to_finite _)).symm\nend\n\nlemma range_diagonal [decidable_eq m] (w : m \u2192 K) :\n  (diagonal w).to_lin'.range = (\u2a06 i \u2208 {i | w i \u2260 0}, (linear_map.std_basis K (\u03bbi, K) i).range) :=\nbegin\n  dsimp only [mem_set_of_eq],\n  rw [\u2190 submodule.map_top, \u2190 supr_range_std_basis, submodule.map_supr],\n  congr, funext i,\n  rw [\u2190 linear_map.range_comp, diagonal_comp_std_basis, \u2190 range_smul']\nend\n\nlemma rank_diagonal [decidable_eq m] [decidable_eq K] (w : m \u2192 K) :\n  rank (diagonal w).to_lin' = fintype.card { i // w i \u2260 0 } :=\nbegin\n  have hu : univ \u2286 {i : m | w i = 0}\u1d9c \u222a {i : m | w i = 0}, { rw set.compl_union_self },\n  have hd : disjoint {i : m | w i \u2260 0} {i : m | w i = 0} := disjoint_compl_left,\n  have B\u2081 := supr_range_std_basis_eq_infi_ker_proj K (\u03bbi:m, K) hd hu (set.to_finite _),\n  have B\u2082 := @infi_ker_proj_equiv K _ _ (\u03bbi:m, K) _ _ _ _ (by simp; apply_instance) hd hu,\n  rw [rank, range_diagonal, B\u2081, \u2190@dim_fun' K],\n  apply linear_equiv.dim_eq,\n  apply B\u2082,\nend\n\nend field\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/diagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7288567305150112}}
{"text": "/-\nCopyright (c) 2022 David Loeffler. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Loeffler\n-/\nimport analysis.special_functions.trigonometric.basic\nimport analysis.special_functions.trigonometric.arctan_deriv\n/-!\n# Polynomial bounds for trigonometric functions\n\n## Main statements\n\nThis file contains upper and lower bounds for real trigonometric functions in terms\nof polynomials. See `trigonometric.basic` for more elementary inequalities, establishing\nthe ranges of these functions, and their monotonicity in suitable intervals.\n\nHere we prove the following:\n\n* `sin_lt`: for `x > 0` we have `sin x < x`.\n* `sin_gt_sub_cube`: For `0 < x \u2264 1` we have `x - x ^ 3 / 4 < sin x`.\n* `lt_tan`: for `0 < x < \u03c0/2` we have `x < tan x`.\n* `cos_le_one_div_sqrt_sq_add_one` and `cos_lt_one_div_sqrt_sq_add_one`: for\n  `-3 * \u03c0 / 2 \u2264 x \u2264 3 * \u03c0 / 2`, we have `cos x \u2264 1 / sqrt (x ^ 2 + 1)`, with strict inequality if\n  `x \u2260 0`. (This bound is not quite optimal, but not far off)\n\n## Tags\n\nsin, cos, tan, angle\n-/\n\nnoncomputable theory\nopen set\n\nnamespace real\nopen_locale real\n\n/-- For 0 < x, we have sin x < x. -/\nlemma sin_lt {x : \u211d} (h : 0 < x) : sin x < x :=\nbegin\n  cases lt_or_le 1 x with h' h',\n  { exact (sin_le_one x).trans_lt h' },\n  have hx : |x| = x := abs_of_nonneg h.le,\n  have := le_of_abs_le (sin_bound $ show |x| \u2264 1, by rwa [hx]),\n  rw [sub_le_iff_le_add', hx] at this,\n  apply this.trans_lt,\n  rw [sub_add, sub_lt_self_iff, sub_pos, div_eq_mul_inv (x ^ 3)],\n  refine mul_lt_mul' _ (by norm_num) (by norm_num) (pow_pos h 3),\n  apply pow_le_pow_of_le_one h.le h',\n  norm_num\nend\n\n/-- For 0 < x \u2264 1 we have x - x ^ 3 / 4 < sin x.\n\nThis is also true for x > 1, but it's nontrivial for x just above 1. This inequality is not\ntight; the tighter inequality is sin x > x - x ^ 3 / 6 for all x > 0, but this inequality has\na simpler proof. -/\nlemma sin_gt_sub_cube {x : \u211d} (h : 0 < x) (h' : x \u2264 1) : x - x ^ 3 / 4 < sin x :=\nbegin\n  have hx : |x| = x := abs_of_nonneg h.le,\n  have := neg_le_of_abs_le (sin_bound $ show |x| \u2264 1, by rwa [hx]),\n  rw [le_sub_iff_add_le, hx] at this,\n  refine lt_of_lt_of_le _ this,\n  have : x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12\u207b\u00b9 := by norm_num [div_eq_mul_inv, \u2190 mul_sub],\n  rw [add_comm, sub_add, sub_neg_eq_add, sub_lt_sub_iff_left, \u2190lt_sub_iff_add_lt', this],\n  refine mul_lt_mul' _ (by norm_num) (by norm_num) (pow_pos h 3),\n  apply pow_le_pow_of_le_one h.le h',\n  norm_num\nend\n\n\n/-- The derivative of `tan x - x` is `1/(cos x)^2 - 1` away from the zeroes of cos. -/\nlemma deriv_tan_sub_id (x : \u211d) (h : cos x \u2260 0) :\n    deriv (\u03bb y : \u211d, tan y - y) x = 1 / cos x ^ 2 - 1 :=\nhas_deriv_at.deriv $ by simpa using (has_deriv_at_tan h).add (has_deriv_at_id x).neg\n\n/-- For all `0 < x < \u03c0/2` we have `x < tan x`.\n\nThis is proved by checking that the function `tan x - x` vanishes\nat zero and has non-negative derivative. -/\ntheorem lt_tan {x : \u211d} (h1 : 0 < x) (h2 : x < \u03c0 / 2) : x < tan x :=\nbegin\n  let U := Ico 0 (\u03c0 / 2),\n\n  have intU : interior U = Ioo 0 (\u03c0 / 2) := interior_Ico,\n\n  have half_pi_pos : 0 < \u03c0 / 2 := div_pos pi_pos two_pos,\n\n  have cos_pos : \u2200 {y : \u211d}, y \u2208 U \u2192 0 < cos y,\n  { intros y hy,\n    exact cos_pos_of_mem_Ioo (Ico_subset_Ioo_left (neg_lt_zero.mpr half_pi_pos) hy) },\n\n  have sin_pos : \u2200 {y : \u211d}, y \u2208 interior U \u2192 0 < sin y,\n  { intros y hy,\n    rw intU at hy,\n    exact sin_pos_of_mem_Ioo (Ioo_subset_Ioo_right (div_le_self pi_pos.le one_le_two) hy) },\n\n  have tan_cts_U : continuous_on tan U,\n  { apply continuous_on.mono continuous_on_tan,\n    intros z hz,\n    simp only [mem_set_of_eq],\n    exact (cos_pos hz).ne' },\n\n  have tan_minus_id_cts : continuous_on (\u03bb y : \u211d, tan y - y) U :=\n    tan_cts_U.sub continuous_on_id,\n\n  have deriv_pos : \u2200 y : \u211d, y \u2208 interior U \u2192 0 < deriv (\u03bb y' : \u211d, tan y' - y') y,\n  { intros y hy,\n    have := cos_pos (interior_subset hy),\n    simp only [deriv_tan_sub_id y this.ne', one_div, gt_iff_lt, sub_pos],\n    have bd2 : cos y ^ 2 < 1,\n    { apply lt_of_le_of_ne y.cos_sq_le_one,\n      rw cos_sq',\n      simpa only [ne.def, sub_eq_self, pow_eq_zero_iff, nat.succ_pos']\n        using (sin_pos hy).ne' },\n    rwa [lt_inv, inv_one],\n    { exact zero_lt_one },\n    simpa only [sq, mul_self_pos] using this.ne' },\n\n  have mono := convex.strict_mono_on_of_deriv_pos (convex_Ico 0 (\u03c0 / 2)) tan_minus_id_cts deriv_pos,\n  have zero_in_U : (0 : \u211d) \u2208 U,\n  { rwa left_mem_Ico },\n  have x_in_U : x \u2208 U := \u27e8h1.le, h2\u27e9,\n  simpa only [tan_zero, sub_zero, sub_pos] using mono zero_in_U x_in_U h1\nend\n\nlemma le_tan {x : \u211d} (h1 : 0 \u2264 x) (h2 : x < \u03c0 / 2) : x \u2264 tan x :=\nbegin\n  rcases eq_or_lt_of_le h1 with rfl | h1',\n  { rw tan_zero },\n  { exact le_of_lt (lt_tan h1' h2) }\nend\n\nlemma cos_lt_one_div_sqrt_sq_add_one {x : \u211d}\n  (hx1 : -(3 * \u03c0 / 2) \u2264 x) (hx2 : x \u2264 3 * \u03c0 / 2) (hx3 : x \u2260 0) :\n  cos x < 1 / sqrt (x ^ 2 + 1) :=\nbegin\n  suffices : \u2200 {y : \u211d} (hy1 : 0 < y) (hy2 : y \u2264 3 * \u03c0 / 2), cos y < 1 / sqrt (y ^ 2 + 1),\n  { rcases lt_or_lt_iff_ne.mpr hx3.symm,\n    { exact this h hx2 },\n    { convert this (by linarith : 0 < -x) (by linarith) using 1,\n      { rw cos_neg }, { rw neg_sq } } },\n  intros y hy1 hy2,\n  have hy3 : 0 < y ^ 2 + 1, by linarith [sq_nonneg y],\n  rcases lt_or_le y (\u03c0 / 2) with hy2' | hy1',\n  { -- Main case : `0 < y < \u03c0 / 2`\n    have hy4 : 0 < cos y := cos_pos_of_mem_Ioo \u27e8by linarith, hy2'\u27e9,\n    rw [\u2190abs_of_nonneg (cos_nonneg_of_mem_Icc \u27e8by linarith, hy2'.le\u27e9),\n      \u2190abs_of_nonneg (one_div_nonneg.mpr (sqrt_nonneg _)),  \u2190sq_lt_sq, div_pow, one_pow,\n      sq_sqrt hy3.le, lt_one_div (pow_pos hy4 _) hy3, \u2190inv_one_add_tan_sq hy4.ne', one_div, inv_inv,\n      add_comm, add_lt_add_iff_left, sq_lt_sq, abs_of_pos hy1,\n      abs_of_nonneg (tan_nonneg_of_nonneg_of_le_pi_div_two hy1.le hy2'.le)],\n    exact real.lt_tan hy1 hy2' },\n  { -- Easy case : `\u03c0 / 2 \u2264 y \u2264 3 * \u03c0 / 2`\n    refine lt_of_le_of_lt _ (one_div_pos.mpr $ sqrt_pos_of_pos hy3),\n    exact cos_nonpos_of_pi_div_two_le_of_le hy1' (by linarith [pi_pos]) }\nend\n\nlemma cos_le_one_div_sqrt_sq_add_one {x : \u211d} (hx1 : -(3 * \u03c0 / 2) \u2264 x) (hx2 : x \u2264 3 * \u03c0 / 2) :\n  cos x \u2264 1 / sqrt (x ^ 2 + 1) :=\nbegin\n  rcases eq_or_ne x 0 with rfl | hx3,\n  { simp },\n  { exact (cos_lt_one_div_sqrt_sq_add_one hx1 hx2 hx3).le }\nend\n\nend real\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/trigonometric/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7288318682070346}}
{"text": "/-\nCopyright (c) 2021 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\nimport combinatorics.simple_graph.basic\nimport combinatorics.simple_graph.subgraph\nimport data.list\n/-!\n\n# Graph connectivity\n\nIn a simple graph,\n\n* A *walk* is a finite sequence of adjacent vertices, and can be\n  thought of equally well as a sequence of directed edges.\n\n* A *trail* is a walk whose edges each appear no more than once.\n\n* A *path* is a trail whose vertices appear no more than once.\n\n* A *cycle* is a nonempty trail whose first and last vertices are the\n  same and whose vertices except for the first appear no more than once.\n\n**Warning:** graph theorists mean something different by \"path\" than\ndo homotopy theorists.  A \"walk\" in graph theory is a \"path\" in\nhomotopy theory.  Another warning: some graph theorists use \"path\" and\n\"simple path\" for \"walk\" and \"path.\"\n\nSome definitions and theorems have inspiration from multigraph\ncounterparts in [Chou1994].\n\n## Main definitions\n\n* `simple_graph.walk` (with accompanying pattern definitions\n  `simple_graph.walk.nil'` and `simple_graph.walk.cons'`)\n\n* `simple_graph.walk.is_trail`, `simple_graph.walk.is_path`, and `simple_graph.walk.is_cycle`.\n\n* `simple_graph.path`\n\n* `simple_graph.walk.map` and `simple_graph.path.map` for the induced map on walks,\n  given an (injective) graph homomorphism.\n\n* `simple_graph.reachable` for the relation of whether there exists\n  a walk between a given pair of vertices\n\n* `simple_graph.preconnected` and `simple_graph.connected` are predicates\n  on simple graphs for whether every vertex can be reached from every other,\n  and in the latter case, whether the vertex type is nonempty.\n\n* `simple_graph.subgraph.connected` gives subgraphs the connectivity\n  predicate via `simple_graph.subgraph.coe`.\n\n* `simple_graph.connected_component` is the type of connected components of\n  a given graph.\n\n## Tags\nwalks, trails, paths, circuits, cycles\n\n-/\n\nopen function\n\nuniverses u v\n\nnamespace simple_graph\nvariables {V : Type u} {V' : Type v} (G : simple_graph V) (G' : simple_graph V')\n\n/-- A walk is a sequence of adjacent vertices.  For vertices `u v : V`,\nthe type `walk u v` consists of all walks starting at `u` and ending at `v`.\n\nWe say that a walk *visits* the vertices it contains.  The set of vertices a\nwalk visits is `simple_graph.walk.support`.\n\nSee `simple_graph.walk.nil'` and `simple_graph.walk.cons'` for patterns that\ncan be useful in definitions since they make the vertices explicit. -/\n@[derive decidable_eq]\ninductive walk : V \u2192 V \u2192 Type u\n| nil {u : V} : walk u u\n| cons {u v w: V} (h : G.adj u v) (p : walk v w) : walk u w\n\nattribute [refl] walk.nil\n\ninstance walk.inhabited (v : V) : inhabited (G.walk v v) := \u27e8by refl\u27e9\n\nnamespace walk\nvariables {G}\n\n/-- Pattern to get `walk.nil` with the vertex as an explicit argument. -/\n@[pattern] abbreviation nil' (u : V) : G.walk u u := walk.nil\n\n/-- Pattern to get `walk.cons` with the vertices as explicit arguments. -/\n@[pattern] abbreviation cons' (u v w : V) (h : G.adj u v) (p : G.walk v w) : G.walk u w :=\nwalk.cons h p\n\nlemma exists_eq_cons_of_ne : \u03a0 {u v : V} (hne : u \u2260 v) (p : G.walk u v),\n  \u2203 (w : V) (h : G.adj u w) (p' : G.walk w v), p = cons h p'\n| _ _ hne nil := (hne rfl).elim\n| _ _ _ (cons h p') := \u27e8_, h, p', rfl\u27e9\n\n/-- The length of a walk is the number of edges/darts along it. -/\ndef length : \u03a0 {u v : V}, G.walk u v \u2192 \u2115\n| _ _ nil := 0\n| _ _ (cons _ q) := q.length.succ\n\n/-- The concatenation of two compatible walks. -/\n@[trans]\ndef append : \u03a0 {u v w : V}, G.walk u v \u2192 G.walk v w \u2192 G.walk u w\n| _ _ _ nil q := q\n| _ _ _ (cons h p) q := cons h (p.append q)\n\n/-- The concatenation of the reverse of the first walk with the second walk. -/\nprotected def reverse_aux : \u03a0 {u v w : V}, G.walk u v \u2192 G.walk u w \u2192 G.walk v w\n| _ _ _ nil q := q\n| _ _ _ (cons h p) q := reverse_aux p (cons (G.symm h) q)\n\n/-- The walk in reverse. -/\n@[symm]\ndef reverse {u v : V} (w : G.walk u v) : G.walk v u := w.reverse_aux nil\n\n/-- Get the `n`th vertex from a walk, where `n` is generally expected to be\nbetween `0` and `p.length`, inclusive.\nIf `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/\ndef get_vert : \u03a0 {u v : V} (p : G.walk u v) (n : \u2115), V\n| u v nil _ := u\n| u v (cons _ _) 0 := u\n| u v (cons _ q) (n+1) := q.get_vert n\n\n@[simp] lemma get_vert_zero {u v} (w : G.walk u v) : w.get_vert 0 = u :=\nby { cases w; refl }\n\nlemma get_vert_of_length_le {u v} (w : G.walk u v) {i : \u2115} (hi : w.length \u2264 i) :\n  w.get_vert i = v :=\nbegin\n  induction w with _ x y z hxy wyz IH generalizing i,\n  { refl },\n  { cases i,\n    { cases hi, },\n    { exact IH (nat.succ_le_succ_iff.1 hi) } }\nend\n\n@[simp] lemma get_vert_length {u v} (w : G.walk u v) : w.get_vert w.length = v :=\nw.get_vert_of_length_le rfl.le\n\nlemma adj_get_vert_succ {u v} (w : G.walk u v) {i : \u2115} (hi : i < w.length) :\n  G.adj (w.get_vert i) (w.get_vert (i+1)) :=\nbegin\n  induction w with _ x y z hxy wyz IH generalizing i,\n  { cases hi, },\n  { cases i,\n    { simp [get_vert, hxy] },\n    { exact IH (nat.succ_lt_succ_iff.1 hi) } },\nend\n\n@[simp] lemma cons_append {u v w x : V} (h : G.adj u v) (p : G.walk v w) (q : G.walk w x) :\n  (cons h p).append q = cons h (p.append q) := rfl\n\n@[simp] lemma cons_nil_append {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h nil).append p = cons h p := rfl\n\n@[simp] lemma append_nil : \u03a0 {u v : V} (p : G.walk u v), p.append nil = p\n| _ _ nil := rfl\n| _ _ (cons h p) := by rw [cons_append, append_nil]\n\n@[simp] lemma nil_append {u v : V} (p : G.walk u v) : nil.append p = p := rfl\n\nlemma append_assoc : \u03a0 {u v w x : V} (p : G.walk u v) (q : G.walk v w) (r : G.walk w x),\n  p.append (q.append r) = (p.append q).append r\n| _ _ _ _ nil _ _ := rfl\n| _ _ _ _ (cons h p') q r := by { dunfold append, rw append_assoc, }\n\n@[simp] lemma reverse_nil {u : V} : (nil : G.walk u u).reverse = nil := rfl\n\nlemma reverse_singleton {u v : V} (h : G.adj u v) :\n  (cons h nil).reverse = cons (G.symm h) nil := rfl\n\n@[simp] lemma cons_reverse_aux {u v w x : V} (p : G.walk u v) (q : G.walk w x) (h : G.adj w u) :\n  (cons h p).reverse_aux q = p.reverse_aux (cons (G.symm h) q) := rfl\n\n@[simp] protected lemma append_reverse_aux : \u03a0 {u v w x : V}\n  (p : G.walk u v) (q : G.walk v w) (r : G.walk u x),\n  (p.append q).reverse_aux r = q.reverse_aux (p.reverse_aux r)\n| _ _ _ _ nil _ _ := rfl\n| _ _ _ _ (cons h p') q r := append_reverse_aux p' q (cons (G.symm h) r)\n\n@[simp] protected lemma reverse_aux_append : \u03a0 {u v w x : V}\n  (p : G.walk u v) (q : G.walk u w) (r : G.walk w x),\n  (p.reverse_aux q).append r = p.reverse_aux (q.append r)\n| _ _ _ _ nil _ _ := rfl\n| _ _ _ _ (cons h p') q r := by simp [reverse_aux_append p' (cons (G.symm h) q) r]\n\nprotected lemma reverse_aux_eq_reverse_append {u v w : V} (p : G.walk u v) (q : G.walk u w) :\n  p.reverse_aux q = p.reverse.append q :=\nby simp [reverse]\n\n@[simp] lemma reverse_cons {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) :=\nby simp [reverse]\n\n@[simp] lemma reverse_append {u v w : V} (p : G.walk u v) (q : G.walk v w) :\n  (p.append q).reverse = q.reverse.append p.reverse :=\nby simp [reverse]\n\n@[simp] lemma reverse_reverse : \u03a0 {u v : V} (p : G.walk u v), p.reverse.reverse = p\n| _ _ nil := rfl\n| _ _ (cons h p) := by simp [reverse_reverse]\n\n@[simp] lemma length_nil {u : V} : (nil : G.walk u u).length = 0 := rfl\n\n@[simp] lemma length_cons {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h p).length = p.length + 1 := rfl\n\n@[simp] lemma length_append : \u03a0 {u v w : V} (p : G.walk u v) (q : G.walk v w),\n  (p.append q).length = p.length + q.length\n| _ _ _ nil _ := by simp\n| _ _ _ (cons _ _) _ := by simp [length_append, add_left_comm, add_comm]\n\n@[simp] protected lemma length_reverse_aux : \u03a0 {u v w : V} (p : G.walk u v) (q : G.walk u w),\n  (p.reverse_aux q).length = p.length + q.length\n| _ _ _ nil _ := by simp!\n| _ _ _ (cons _ _) _ := by simp [length_reverse_aux, nat.add_succ, nat.succ_add]\n\n@[simp] lemma length_reverse {u v : V} (p : G.walk u v) : p.reverse.length = p.length :=\nby simp [reverse]\n\nlemma eq_of_length_eq_zero : \u03a0 {u v : V} {p : G.walk u v}, p.length = 0 \u2192 u = v\n| _ _ nil _ := rfl\n\n@[simp] lemma exists_length_eq_zero_iff {u v : V} : (\u2203 (p : G.walk u v), p.length = 0) \u2194 u = v :=\nbegin\n  split,\n  { rintro \u27e8p, hp\u27e9,\n    exact eq_of_length_eq_zero hp, },\n  { rintro rfl,\n    exact \u27e8nil, rfl\u27e9, },\nend\n\n@[simp] lemma length_eq_zero_iff {u : V} {p : G.walk u u} : p.length = 0 \u2194 p = nil :=\nby cases p; simp\n\n/-- The `support` of a walk is the list of vertices it visits in order. -/\ndef support : \u03a0 {u v : V}, G.walk u v \u2192 list V\n| u v nil := [u]\n| u v (cons h p) := u :: p.support\n\n/-- The `darts` of a walk is the list of darts it visits in order. -/\ndef darts : \u03a0 {u v : V}, G.walk u v \u2192 list G.dart\n| u v nil := []\n| u v (cons h p) := \u27e8(u, _), h\u27e9 :: p.darts\n\n/-- The `edges` of a walk is the list of edges it visits in order.\nThis is defined to be the list of edges underlying `simple_graph.walk.darts`. -/\ndef edges {u v : V} (p : G.walk u v) : list (sym2 V) := p.darts.map dart.edge\n\n@[simp] lemma support_nil {u : V} : (nil : G.walk u u).support = [u] := rfl\n\n@[simp] lemma support_cons {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h p).support = u :: p.support := rfl\n\nlemma support_append {u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  (p.append p').support = p.support ++ p'.support.tail :=\nby induction p; cases p'; simp [*]\n\n@[simp]\nlemma support_reverse {u v : V} (p : G.walk u v) : p.reverse.support = p.support.reverse :=\nby induction p; simp [support_append, *]\n\nlemma support_ne_nil {u v : V} (p : G.walk u v) : p.support \u2260 [] :=\nby cases p; simp\n\nlemma tail_support_append {u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  (p.append p').support.tail = p.support.tail ++ p'.support.tail :=\nby rw [support_append, list.tail_append_of_ne_nil _ _ (support_ne_nil _)]\n\nlemma support_eq_cons {u v : V} (p : G.walk u v) : p.support = u :: p.support.tail :=\nby cases p; simp\n\n@[simp] lemma start_mem_support {u v : V} (p : G.walk u v) : u \u2208 p.support :=\nby cases p; simp\n\n@[simp] lemma end_mem_support {u v : V} (p : G.walk u v) : v \u2208 p.support :=\nby induction p; simp [*]\n\nlemma mem_support_iff {u v w : V} (p : G.walk u v) :\n  w \u2208 p.support \u2194 w = u \u2228 w \u2208 p.support.tail :=\nby cases p; simp\n\nlemma mem_support_nil_iff {u v : V} : u \u2208 (nil : G.walk v v).support \u2194 u = v := by simp\n\n@[simp]\nlemma mem_tail_support_append_iff {t u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  t \u2208 (p.append p').support.tail \u2194 t \u2208 p.support.tail \u2228 t \u2208 p'.support.tail :=\nby rw [tail_support_append, list.mem_append]\n\n@[simp] lemma end_mem_tail_support_of_ne {u v : V} (h : u \u2260 v) (p : G.walk u v) :\n  v \u2208 p.support.tail :=\nby { obtain \u27e8_, _, _, rfl\u27e9 := exists_eq_cons_of_ne h p, simp }\n\n@[simp]\nlemma mem_support_append_iff {t u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  t \u2208 (p.append p').support \u2194 t \u2208 p.support \u2228 t \u2208 p'.support :=\nbegin\n  simp only [mem_support_iff, mem_tail_support_append_iff],\n  by_cases h : t = v; by_cases h' : t = u;\n  subst_vars;\n  try { have := ne.symm h' };\n  simp [*],\nend\n\nlemma coe_support {u v : V} (p : G.walk u v) :\n  (p.support : multiset V) = {u} + p.support.tail :=\nby cases p; refl\n\nlemma coe_support_append {u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  ((p.append p').support : multiset V) = {u} + p.support.tail + p'.support.tail :=\nby rw [support_append, \u2190multiset.coe_add, coe_support]\n\nlemma coe_support_append' [decidable_eq V] {u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  ((p.append p').support : multiset V) = p.support + p'.support - {v} :=\nbegin\n  rw [support_append, \u2190multiset.coe_add],\n  simp only [coe_support],\n  rw add_comm {v},\n  simp only [\u2190 add_assoc, add_tsub_cancel_right],\nend\n\nlemma chain_adj_support : \u03a0 {u v w : V} (h : G.adj u v) (p : G.walk v w),\n  list.chain G.adj u p.support\n| _ _ _ h nil := list.chain.cons h list.chain.nil\n| _ _ _ h (cons h' p) := list.chain.cons h (chain_adj_support h' p)\n\nlemma chain'_adj_support : \u03a0 {u v : V} (p : G.walk u v), list.chain' G.adj p.support\n| _ _ nil := list.chain.nil\n| _ _ (cons h p) := chain_adj_support h p\n\nlemma chain_dart_adj_darts : \u03a0 {d : G.dart} {v w : V} (h : d.snd = v) (p : G.walk v w),\n  list.chain G.dart_adj d p.darts\n| _ _ _ h nil := list.chain.nil\n| _ _ _ h (cons h' p) := list.chain.cons h (chain_dart_adj_darts (by exact rfl) p)\n\nlemma chain'_dart_adj_darts : \u03a0 {u v : V} (p : G.walk u v), list.chain' G.dart_adj p.darts\n| _ _ nil := trivial\n| _ _ (cons h p) := chain_dart_adj_darts rfl p\n\n/-- Every edge in a walk's edge list is an edge of the graph.\nIt is written in this form (rather than using `\u2286`) to avoid unsightly coercions. -/\nlemma edges_subset_edge_set : \u03a0 {u v : V} (p : G.walk u v) \u2983e : sym2 V\u2984\n  (h : e \u2208 p.edges), e \u2208 G.edge_set\n| _ _ (cons h' p') e h := by rcases h with \u27e8rfl, h\u27e9; solve_by_elim\n\n@[simp] lemma darts_nil {u : V} : (nil : G.walk u u).darts = [] := rfl\n\n@[simp] lemma darts_cons {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h p).darts = \u27e8(u, v), h\u27e9 :: p.darts := rfl\n\n@[simp] lemma darts_append {u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  (p.append p').darts = p.darts ++ p'.darts :=\nby induction p; simp [*]\n\n@[simp] lemma darts_reverse {u v : V} (p : G.walk u v) :\n  p.reverse.darts = (p.darts.map dart.symm).reverse :=\nby induction p; simp [*, sym2.eq_swap]\n\nlemma cons_map_snd_darts {u v : V} (p : G.walk u v) :\n  u :: p.darts.map dart.snd = p.support :=\nby induction p; simp! [*]\n\nlemma map_snd_darts {u v : V} (p : G.walk u v) :\n  p.darts.map dart.snd = p.support.tail :=\nby simpa using congr_arg list.tail (cons_map_snd_darts p)\n\nlemma map_fst_darts_append {u v : V} (p : G.walk u v) :\n  p.darts.map dart.fst ++ [v] = p.support :=\nby induction p; simp! [*]\n\nlemma map_fst_darts {u v : V} (p : G.walk u v) :\n  p.darts.map dart.fst = p.support.init :=\nby simpa! using congr_arg list.init (map_fst_darts_append p)\n\n@[simp] lemma edges_nil {u : V} : (nil : G.walk u u).edges = [] := rfl\n\n@[simp] lemma edges_cons {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h p).edges = \u27e6(u, v)\u27e7 :: p.edges := rfl\n\n@[simp] lemma edges_append {u v w : V} (p : G.walk u v) (p' : G.walk v w) :\n  (p.append p').edges = p.edges ++ p'.edges :=\nby simp [edges]\n\n@[simp] lemma edges_reverse {u v : V} (p : G.walk u v) : p.reverse.edges = p.edges.reverse :=\nby simp [edges]\n\n@[simp] lemma length_support {u v : V} (p : G.walk u v) : p.support.length = p.length + 1 :=\nby induction p; simp *\n\n@[simp] lemma length_darts {u v : V} (p : G.walk u v) : p.darts.length = p.length :=\nby induction p; simp *\n\n@[simp] lemma length_edges {u v : V} (p : G.walk u v) : p.edges.length = p.length :=\nby simp [edges]\n\nlemma dart_fst_mem_support_of_mem_darts :\n  \u03a0 {u v : V} (p : G.walk u v) {d : G.dart}, d \u2208 p.darts \u2192 d.fst \u2208 p.support\n| u v (cons h p') d hd := begin\n  simp only [support_cons, darts_cons, list.mem_cons_iff] at hd \u22a2,\n  rcases hd with (rfl|hd),\n  { exact or.inl rfl, },\n  { exact or.inr (dart_fst_mem_support_of_mem_darts _ hd), },\nend\n\nlemma dart_snd_mem_support_of_mem_darts :\n  \u03a0 {u v : V} (p : G.walk u v) {d : G.dart}, d \u2208 p.darts \u2192 d.snd \u2208 p.support\n| u v (cons h p') d hd := begin\n  simp only [support_cons, darts_cons, list.mem_cons_iff] at hd \u22a2,\n  rcases hd with (rfl|hd),\n  { simp },\n  { exact or.inr (dart_snd_mem_support_of_mem_darts _ hd), },\nend\n\nlemma mem_support_of_mem_edges {t u v w : V} (p : G.walk v w) (he : \u27e6(t, u)\u27e7 \u2208 p.edges) :\n  t \u2208 p.support :=\nbegin\n  obtain \u27e8d, hd, he\u27e9 := list.mem_map.mp he,\n  rw dart_edge_eq_mk_iff' at he,\n  rcases he with \u27e8rfl, rfl\u27e9 | \u27e8rfl, rfl\u27e9,\n  { exact dart_fst_mem_support_of_mem_darts _ hd, },\n  { exact dart_snd_mem_support_of_mem_darts _ hd, },\nend\n\nlemma darts_nodup_of_support_nodup {u v : V} {p : G.walk u v} (h : p.support.nodup) :\n  p.darts.nodup :=\nbegin\n  induction p,\n  { simp, },\n  { simp only [darts_cons, support_cons, list.nodup_cons] at h \u22a2,\n    refine \u27e8\u03bb h', h.1 (dart_fst_mem_support_of_mem_darts p_p h'), p_ih h.2\u27e9, }\nend\n\nlemma edges_nodup_of_support_nodup {u v : V} {p : G.walk u v} (h : p.support.nodup) :\n  p.edges.nodup :=\nbegin\n  induction p,\n  { simp, },\n  { simp only [edges_cons, support_cons, list.nodup_cons] at h \u22a2,\n    exact \u27e8\u03bb h', h.1 (mem_support_of_mem_edges p_p h'), p_ih h.2\u27e9, }\nend\n\n/-! ### Trails, paths, circuits, cycles -/\n\n/-- A *trail* is a walk with no repeating edges. -/\nstructure is_trail {u v : V} (p : G.walk u v) : Prop :=\n(edges_nodup : p.edges.nodup)\n\n/-- A *path* is a walk with no repeating vertices.\nUse `simple_graph.walk.is_path.mk'` for a simpler constructor. -/\nstructure is_path {u v : V} (p : G.walk u v) extends to_trail : is_trail p : Prop :=\n(support_nodup : p.support.nodup)\n\n/-- A *circuit* at `u : V` is a nonempty trail beginning and ending at `u`. -/\nstructure is_circuit {u : V} (p : G.walk u u) extends to_trail : is_trail p : Prop :=\n(ne_nil : p \u2260 nil)\n\n/-- A *cycle* at `u : V` is a circuit at `u` whose only repeating vertex\nis `u` (which appears exactly twice). -/\nstructure is_cycle {u : V} (p : G.walk u u)\n  extends to_circuit : is_circuit p : Prop :=\n(support_nodup : p.support.tail.nodup)\n\nlemma is_trail_def {u v : V} (p : G.walk u v) : p.is_trail \u2194 p.edges.nodup :=\n\u27e8is_trail.edges_nodup, \u03bb h, \u27e8h\u27e9\u27e9\n\nlemma is_path.mk' {u v : V} {p : G.walk u v} (h : p.support.nodup) : is_path p :=\n\u27e8\u27e8edges_nodup_of_support_nodup h\u27e9, h\u27e9\n\nlemma is_path_def {u v : V} (p : G.walk u v) : p.is_path \u2194 p.support.nodup :=\n\u27e8is_path.support_nodup, is_path.mk'\u27e9\n\nlemma is_cycle_def {u : V} (p : G.walk u u) :\n  p.is_cycle \u2194 is_trail p \u2227 p \u2260 nil \u2227 p.support.tail.nodup :=\niff.intro (\u03bb h, \u27e8h.1.1, h.1.2, h.2\u27e9) (\u03bb h, \u27e8\u27e8h.1, h.2.1\u27e9, h.2.2\u27e9)\n\n@[simp] lemma is_trail.nil {u : V} : (nil : G.walk u u).is_trail :=\n\u27e8by simp [edges]\u27e9\n\nlemma is_trail.of_cons {u v w : V} {h : G.adj u v} {p : G.walk v w} :\n  (cons h p).is_trail \u2192 p.is_trail :=\nby simp [is_trail_def]\n\n@[simp] lemma cons_is_trail_iff {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h p).is_trail \u2194 p.is_trail \u2227 \u27e6(u, v)\u27e7 \u2209 p.edges :=\nby simp [is_trail_def, and_comm]\n\nlemma is_trail.reverse {u v : V} (p : G.walk u v) (h : p.is_trail) : p.reverse.is_trail :=\nby simpa [is_trail_def] using h\n\n@[simp] lemma reverse_is_trail_iff {u v : V} (p : G.walk u v) : p.reverse.is_trail \u2194 p.is_trail :=\nby split; { intro h, convert h.reverse _, try { rw reverse_reverse } }\n\nlemma is_trail.of_append_left {u v w : V} {p : G.walk u v} {q : G.walk v w}\n  (h : (p.append q).is_trail) : p.is_trail :=\nby { rw [is_trail_def, edges_append, list.nodup_append] at h, exact \u27e8h.1\u27e9 }\n\nlemma is_trail.of_append_right {u v w : V} {p : G.walk u v} {q : G.walk v w}\n  (h : (p.append q).is_trail) : q.is_trail :=\nby { rw [is_trail_def, edges_append, list.nodup_append] at h, exact \u27e8h.2.1\u27e9 }\n\nlemma is_trail.count_edges_le_one [decidable_eq V] {u v : V}\n  {p : G.walk u v} (h : p.is_trail) (e : sym2 V) : p.edges.count e \u2264 1 :=\nlist.nodup_iff_count_le_one.mp h.edges_nodup e\n\nlemma is_trail.count_edges_eq_one [decidable_eq V] {u v : V}\n  {p : G.walk u v} (h : p.is_trail) {e : sym2 V} (he : e \u2208 p.edges) :\n  p.edges.count e = 1 :=\nlist.count_eq_one_of_mem h.edges_nodup he\n\n@[simp] lemma is_path.nil {u : V} : (nil : G.walk u u).is_path :=\nby { fsplit; simp }\n\nlemma is_path.of_cons {u v w : V} {h : G.adj u v} {p : G.walk v w} :\n  (cons h p).is_path \u2192 p.is_path :=\nby simp [is_path_def]\n\n@[simp] lemma cons_is_path_iff {u v w : V} (h : G.adj u v) (p : G.walk v w) :\n  (cons h p).is_path \u2194 p.is_path \u2227 u \u2209 p.support :=\nby split; simp [is_path_def] { contextual := tt }\n\nlemma is_path.reverse {u v : V} {p : G.walk u v} (h : p.is_path) : p.reverse.is_path :=\nby simpa [is_path_def] using h\n\n@[simp] lemma is_path_reverse_iff {u v : V} (p : G.walk u v) : p.reverse.is_path \u2194 p.is_path :=\nby split; intro h; convert h.reverse; simp\n\nlemma is_path.of_append_left {u v w : V} {p : G.walk u v} {q : G.walk v w} :\n  (p.append q).is_path \u2192 p.is_path :=\nby { simp only [is_path_def, support_append], exact list.nodup.of_append_left }\n\nlemma is_path.of_append_right {u v w : V} {p : G.walk u v} {q : G.walk v w}\n  (h : (p.append q).is_path) : q.is_path :=\nbegin\n  rw \u2190is_path_reverse_iff at h \u22a2,\n  rw reverse_append at h,\n  apply h.of_append_left,\nend\n\n/-! ### Walk decompositions -/\n\nsection walk_decomp\nvariables [decidable_eq V]\n\n/-- Given a vertex in the support of a path, give the path up until (and including) that vertex. -/\ndef take_until : \u03a0 {v w : V} (p : G.walk v w) (u : V) (h : u \u2208 p.support), G.walk v u\n| v w nil u h := by rw mem_support_nil_iff.mp h\n| v w (cons r p) u h :=\n  if hx : v = u\n  then by subst u\n  else cons r (take_until p _ $ h.cases_on (\u03bb h', (hx h'.symm).elim) id)\n\n/-- Given a vertex in the support of a path, give the path from (and including) that vertex to\nthe end. In other words, drop vertices from the front of a path until (and not including)\nthat vertex. -/\ndef drop_until : \u03a0 {v w : V} (p : G.walk v w) (u : V) (h : u \u2208 p.support), G.walk u w\n| v w nil u h := by rw mem_support_nil_iff.mp h\n| v w (cons r p) u h :=\n  if hx : v = u\n  then by { subst u, exact cons r p }\n  else drop_until p _ $ h.cases_on (\u03bb h', (hx h'.symm).elim) id\n\n/-- The `take_until` and `drop_until` functions split a walk into two pieces.\nThe lemma `count_support_take_until_eq_one` specifies where this split occurs. -/\n@[simp]\nlemma take_spec {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.take_until u h).append (p.drop_until u h) = p :=\nbegin\n  induction p,\n  { rw mem_support_nil_iff at h,\n    subst u,\n    refl, },\n  { obtain (rfl|h) := h,\n    { simp! },\n    { simp! only,\n      split_ifs with h'; subst_vars; simp [*], } },\nend\n\n@[simp]\nlemma count_support_take_until_eq_one {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.take_until u h).support.count u = 1 :=\nbegin\n  induction p,\n  { rw mem_support_nil_iff at h,\n    subst u,\n    simp!, },\n  { obtain (rfl|h) := h,\n    { simp! },\n    { simp! only,\n      split_ifs with h'; rw eq_comm at h'; subst_vars; simp! [*, list.count_cons], } },\nend\n\nlemma count_edges_take_until_le_one {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) (x : V) :\n  (p.take_until u h).edges.count \u27e6(u, x)\u27e7 \u2264 1 :=\nbegin\n  induction p with u' u' v' w' ha p' ih,\n  { rw mem_support_nil_iff at h,\n    subst u,\n    simp!, },\n  { obtain (rfl|h) := h,\n    { simp!, },\n    { simp! only,\n      split_ifs with h',\n      { subst h',\n        simp, },\n      { rw [edges_cons, list.count_cons],\n        split_ifs with h'',\n        { rw sym2.eq_iff at h'',\n          obtain (\u27e8rfl,rfl\u27e9|\u27e8rfl,rfl\u27e9) := h'',\n          { exact (h' rfl).elim },\n          { cases p'; simp! } },\n        { apply ih, } } } },\nend\n\nlemma support_take_until_subset {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.take_until u h).support \u2286 p.support :=\n\u03bb x hx, by { rw [\u2190 take_spec p h, mem_support_append_iff], exact or.inl hx }\n\nlemma support_drop_until_subset {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.drop_until u h).support \u2286 p.support :=\n\u03bb x hx, by { rw [\u2190 take_spec p h, mem_support_append_iff], exact or.inr hx }\n\nlemma darts_take_until_subset {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.take_until u h).darts \u2286 p.darts :=\n\u03bb x hx, by { rw [\u2190 take_spec p h, darts_append, list.mem_append], exact or.inl hx }\n\nlemma darts_drop_until_subset {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.drop_until u h).darts \u2286 p.darts :=\n\u03bb x hx, by { rw [\u2190 take_spec p h, darts_append, list.mem_append], exact or.inr hx }\n\nlemma edges_take_until_subset {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.take_until u h).edges \u2286 p.edges :=\nlist.map_subset _ (p.darts_take_until_subset h)\n\nlemma edges_drop_until_subset {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.drop_until u h).edges \u2286 p.edges :=\nlist.map_subset _ (p.darts_drop_until_subset h)\n\nlemma length_take_until_le {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.take_until u h).length \u2264 p.length :=\nbegin\n  have := congr_arg walk.length (p.take_spec h),\n  rw [length_append] at this,\n  exact nat.le.intro this,\nend\n\nlemma length_drop_until_le {u v w : V} (p : G.walk v w) (h : u \u2208 p.support) :\n  (p.drop_until u h).length \u2264 p.length :=\nbegin\n  have := congr_arg walk.length (p.take_spec h),\n  rw [length_append, add_comm] at this,\n  exact nat.le.intro this,\nend\n\nprotected\nlemma is_trail.take_until {u v w : V} {p : G.walk v w} (hc : p.is_trail) (h : u \u2208 p.support) :\n  (p.take_until u h).is_trail :=\nis_trail.of_append_left (by rwa \u2190 take_spec _ h at hc)\n\nprotected\nlemma is_trail.drop_until {u v w : V} {p : G.walk v w} (hc : p.is_trail) (h : u \u2208 p.support) :\n  (p.drop_until u h).is_trail :=\nis_trail.of_append_right (by rwa \u2190 take_spec _ h at hc)\n\nprotected\nlemma is_path.take_until {u v w : V} {p : G.walk v w} (hc : p.is_path) (h : u \u2208 p.support) :\n  (p.take_until u h).is_path :=\nis_path.of_append_left (by rwa \u2190 take_spec _ h at hc)\n\nprotected\nlemma is_path.drop_until {u v w : V} (p : G.walk v w) (hc : p.is_path) (h : u \u2208 p.support) :\n  (p.drop_until u h).is_path :=\nis_path.of_append_right (by rwa \u2190 take_spec _ h at hc)\n\n/-- Rotate a loop walk such that it is centered at the given vertex. -/\ndef rotate {u v : V} (c : G.walk v v) (h : u \u2208 c.support) : G.walk u u :=\n(c.drop_until u h).append (c.take_until u h)\n\n@[simp]\nlemma support_rotate {u v : V} (c : G.walk v v) (h : u \u2208 c.support) :\n  (c.rotate h).support.tail ~r c.support.tail :=\nbegin\n  simp only [rotate, tail_support_append],\n  apply list.is_rotated.trans list.is_rotated_append,\n  rw [\u2190tail_support_append, take_spec],\nend\n\nlemma rotate_darts {u v : V} (c : G.walk v v) (h : u \u2208 c.support) :\n  (c.rotate h).darts ~r c.darts :=\nbegin\n  simp only [rotate, darts_append],\n  apply list.is_rotated.trans list.is_rotated_append,\n  rw [\u2190darts_append, take_spec],\nend\n\nlemma rotate_edges {u v : V} (c : G.walk v v) (h : u \u2208 c.support) :\n  (c.rotate h).edges ~r c.edges :=\n(rotate_darts c h).map _\n\nprotected\nlemma is_trail.rotate {u v : V} {c : G.walk v v} (hc : c.is_trail) (h : u \u2208 c.support) :\n  (c.rotate h).is_trail :=\nbegin\n  rw [is_trail_def, (c.rotate_edges h).perm.nodup_iff],\n  exact hc.edges_nodup,\nend\n\nprotected\nlemma is_circuit.rotate {u v : V} {c : G.walk v v} (hc : c.is_circuit) (h : u \u2208 c.support) :\n  (c.rotate h).is_circuit :=\nbegin\n  refine \u27e8hc.to_trail.rotate _, _\u27e9,\n  cases c,\n  { exact (hc.ne_nil rfl).elim, },\n  { intro hn,\n    have hn' := congr_arg length hn,\n    rw [rotate, length_append, add_comm, \u2190 length_append, take_spec] at hn',\n    simpa using hn', },\nend\n\nprotected\nlemma is_cycle.rotate {u v : V} {c : G.walk v v} (hc : c.is_cycle) (h : u \u2208 c.support) :\n  (c.rotate h).is_cycle :=\nbegin\n  refine \u27e8hc.to_circuit.rotate _, _\u27e9,\n  rw list.is_rotated.nodup_iff (support_rotate _ _),\n  exact hc.support_nodup,\nend\n\nend walk_decomp\n\nend walk\n\n/-! ### Walks to paths -/\n\n/-- The type for paths between two vertices. -/\nabbreviation path (u v : V) := {p : G.walk u v // p.is_path}\n\nnamespace walk\nvariables {G} [decidable_eq V]\n\n/-- Given a walk, produces a walk from it by bypassing subwalks between repeated vertices.\nThe result is a path, as shown in `simple_graph.walk.bypass_is_path`.\nThis is packaged up in `simple_graph.walk.to_path`. -/\ndef bypass : \u03a0 {u v : V}, G.walk u v \u2192 G.walk u v\n| u v nil := nil\n| u v (cons ha p) :=\n  let p' := p.bypass\n  in if hs : u \u2208 p'.support\n     then p'.drop_until u hs\n     else cons ha p'\n\nlemma bypass_is_path {u v : V} (p : G.walk u v) : p.bypass.is_path :=\nbegin\n  induction p,\n  { simp!, },\n  { simp only [bypass],\n    split_ifs,\n    { apply is_path.drop_until,\n      assumption, },\n    { simp [*, cons_is_path_iff], } },\nend\n\nlemma length_bypass_le {u v : V} (p : G.walk u v) : p.bypass.length \u2264 p.length :=\nbegin\n  induction p,\n  { refl },\n  { simp only [bypass],\n    split_ifs,\n    { transitivity,\n      apply length_drop_until_le,\n      rw [length_cons],\n      exact le_add_right p_ih, },\n    { rw [length_cons, length_cons],\n      exact add_le_add_right p_ih 1, } },\nend\n\n/-- Given a walk, produces a path with the same endpoints using `simple_graph.walk.bypass`. -/\ndef to_path {u v : V} (p : G.walk u v) : G.path u v := \u27e8p.bypass, p.bypass_is_path\u27e9\n\nlemma support_bypass_subset {u v : V} (p : G.walk u v) : p.bypass.support \u2286 p.support :=\nbegin\n  induction p,\n  { simp!, },\n  { simp! only,\n    split_ifs,\n    { apply list.subset.trans (support_drop_until_subset _ _),\n      apply list.subset_cons_of_subset,\n      assumption, },\n    { rw support_cons,\n      apply list.cons_subset_cons,\n      assumption, }, },\nend\n\nlemma support_to_path_subset {u v : V} (p : G.walk u v) :\n  (p.to_path : G.walk u v).support \u2286 p.support :=\nsupport_bypass_subset _\n\nlemma darts_bypass_subset {u v : V} (p : G.walk u v) : p.bypass.darts \u2286 p.darts :=\nbegin\n  induction p,\n  { simp!, },\n  { simp! only,\n    split_ifs,\n    { apply list.subset.trans (darts_drop_until_subset _ _),\n      apply list.subset_cons_of_subset _ p_ih, },\n    { rw darts_cons,\n      exact list.cons_subset_cons _ p_ih, }, },\nend\n\nlemma edges_bypass_subset {u v : V} (p : G.walk u v) : p.bypass.edges \u2286 p.edges :=\nlist.map_subset _ p.darts_bypass_subset\n\nlemma darts_to_path_subset {u v : V} (p : G.walk u v) :\n  (p.to_path : G.walk u v).darts \u2286 p.darts :=\ndarts_bypass_subset _\n\nlemma edges_to_path_subset {u v : V} (p : G.walk u v) :\n  (p.to_path : G.walk u v).edges \u2286 p.edges :=\nedges_bypass_subset _\n\nend walk\n\n/-! ## Mapping paths -/\n\nnamespace walk\nvariables {G G'}\n\n/-- Given a graph homomorphism, map walks to walks. -/\nprotected def map (f : G \u2192g G') : \u03a0 {u v : V}, G.walk u v \u2192 G'.walk (f u) (f v)\n| _ _ nil := nil\n| _ _ (cons h p) := cons (f.map_adj h) (map p)\n\nvariables (f : G \u2192g G') {u v : V} (p : G.walk u v)\n\n@[simp] lemma map_nil : (nil : G.walk u u).map f = nil := rfl\n\n@[simp] lemma map_cons {w : V} (h : G.adj w u) :\n  (cons h p).map f = cons (f.map_adj h) (p.map f) := rfl\n\n@[simp] lemma length_map : (p.map f).length = p.length :=\nby induction p; simp [*]\n\nlemma map_append {u v w : V} (p : G.walk u v) (q : G.walk v w) :\n  (p.append q).map f = (p.map f).append (q.map f) :=\nby induction p; simp [*]\n\n@[simp] lemma reverse_map : (p.map f).reverse = p.reverse.map f :=\nby induction p; simp [map_append, *]\n\n@[simp] lemma support_map : (p.map f).support = p.support.map f :=\nby induction p; simp [*]\n\n@[simp] lemma darts_map : (p.map f).darts = p.darts.map f.map_dart :=\nby induction p; simp [*]\n\n@[simp] lemma edges_map : (p.map f).edges = p.edges.map (sym2.map f) :=\nby induction p; simp [*]\n\nvariables {p f}\n\nlemma map_is_path_of_injective (hinj : function.injective f) (hp : p.is_path) :\n  (p.map f).is_path :=\nbegin\n  induction p with w u v w huv hvw ih,\n  { simp, },\n  { rw walk.cons_is_path_iff at hp,\n    simp [ih hp.1],\n    intros x hx hf,\n    cases hinj hf,\n    exact hp.2 hx, },\nend\n\nprotected lemma is_path.of_map {f : G \u2192g G'} (hp : (p.map f).is_path) : p.is_path :=\nbegin\n  induction p with w u v w huv hvw ih,\n  { simp },\n  { rw [map_cons, walk.cons_is_path_iff, support_map] at hp,\n    rw walk.cons_is_path_iff,\n    cases hp with hp1 hp2,\n    refine \u27e8ih hp1, _\u27e9,\n    contrapose! hp2,\n    exact list.mem_map_of_mem f hp2, }\nend\n\nlemma map_is_path_iff_of_injective (hinj : function.injective f) :\n  (p.map f).is_path \u2194 p.is_path :=\n\u27e8is_path.of_map, map_is_path_of_injective hinj\u27e9\n\nvariables (p f)\n\nlemma map_injective_of_injective {f : G \u2192g G'} (hinj : function.injective f) (u v : V) :\n  function.injective (walk.map f : G.walk u v \u2192 G'.walk (f u) (f v)) :=\nbegin\n  intros p p' h,\n  induction p with _ _ _ _ _ _ ih generalizing p',\n  { cases p',\n    { refl },\n    simpa using h, },\n  { induction p',\n    { simpa using h, },\n    { simp only [map_cons] at h,\n      cases hinj h.1,\n      simp only [eq_self_iff_true, heq_iff_eq, true_and],\n      apply ih,\n      simpa using h.2, } },\nend\n\nend walk\n\nnamespace path\nvariables {G G'}\n\n/-- Given an injective graph homomorphism, map paths to paths. -/\n@[simps] protected def map (f : G \u2192g G') (hinj : function.injective f) {u v : V} (p : G.path u v) :\n  G'.path (f u) (f v) :=\n\u27e8walk.map f p, walk.map_is_path_of_injective hinj p.2\u27e9\n\nlemma map_injective {f : G \u2192g G'} (hinj : function.injective f) (u v : V) :\n  function.injective (path.map f hinj : G.path u v \u2192 G'.path (f u) (f v)) :=\nbegin\n  rintros \u27e8p, hp\u27e9 \u27e8p', hp'\u27e9 h,\n  simp only [path.map, subtype.coe_mk] at h,\n  simp [walk.map_injective_of_injective hinj u v h],\nend\n\n/-- Given a graph embedding, map paths to paths. -/\n@[simps] protected def map_embedding (f : G \u21aag G') {u v : V} (p : G.path u v) :\n  G'.path (f u) (f v) :=\npath.map f.to_hom f.injective p\n\nlemma map_embedding_injective (f : G \u21aag G') (u v : V) :\n  function.injective (path.map_embedding f : G.path u v \u2192 G'.path (f u) (f v)) :=\nmap_injective f.injective u v\n\nend path\n\n/-! ## Deleting edges -/\n\nnamespace walk\nvariables {G}\n\n/-- Given a walk that avoids a set of edges, produce a walk in the graph\nwith those edges deleted. -/\n@[simp]\ndef to_delete_edges (s : set (sym2 V)) :\n  \u03a0 {v w : V} (p : G.walk v w) (hp : \u2200 e, e \u2208 p.edges \u2192 \u00ac e \u2208 s), (G.delete_edges s).walk v w\n| _ _ nil _ := nil\n| _ _ (cons' u v w huv p) hp := cons ((G.delete_edges_adj _ _ _).mpr \u27e8huv, hp \u27e6(u, v)\u27e7 (by simp)\u27e9)\n                                (p.to_delete_edges (\u03bb e he, hp e (by simp [he])))\n\n/-- Given a walk that avoids an edge, create a walk in the subgraph with that edge deleted.\nThis is an abbreviation for `simple_graph.walk.to_delete_edges`. -/\nabbreviation to_delete_edge {v w : V} (e : sym2 V) (p : G.walk v w) (hp : e \u2209 p.edges) :\n  (G.delete_edges {e}).walk v w :=\np.to_delete_edges {e} (\u03bb e', by { contrapose!, simp [hp] { contextual := tt } })\n\n@[simp]\nlemma map_to_delete_edges_eq (s : set (sym2 V)) {v w : V} {p : G.walk v w} (hp) :\n  walk.map (hom.map_spanning_subgraphs (G.delete_edges_le s)) (p.to_delete_edges s hp) = p :=\nby induction p; simp [*]\n\nlemma is_path.to_delete_edges (s : set (sym2 V))\n  {v w : V} {p : G.walk v w} (h : p.is_path) (hp) :\n  (p.to_delete_edges s hp).is_path :=\nby { rw \u2190 map_to_delete_edges_eq s hp at h, exact h.of_map }\n\nend walk\n\n/-! ## `reachable` and `connected` -/\n\n/-- Two vertices are *reachable* if there is a walk between them.\nThis is equivalent to `relation.refl_trans_gen` of `G.adj`.\nSee `simple_graph.reachable_iff_refl_trans_gen`. -/\ndef reachable (u v : V) : Prop := nonempty (G.walk u v)\n\nvariables {G}\n\nlemma reachable_iff_nonempty_univ {u v : V} :\n  G.reachable u v \u2194 (set.univ : set (G.walk u v)).nonempty :=\nset.nonempty_iff_univ_nonempty\n\nprotected lemma reachable.elim {p : Prop} {u v : V}\n  (h : G.reachable u v) (hp : G.walk u v \u2192 p) : p :=\nnonempty.elim h hp\n\nprotected lemma reachable.elim_path {p : Prop} {u v : V}\n  (h : G.reachable u v) (hp : G.path u v \u2192 p) : p :=\nbegin\n  classical,\n  exact h.elim (\u03bb q, hp q.to_path),\nend\n\n@[refl] protected lemma reachable.refl (u : V) : G.reachable u u := by { fsplit, refl }\nprotected lemma reachable.rfl {u : V} : G.reachable u u := reachable.refl _\n\n@[symm] protected lemma reachable.symm {u v : V} (huv : G.reachable u v) : G.reachable v u :=\nhuv.elim (\u03bb p, \u27e8p.reverse\u27e9)\n\n@[trans] protected lemma reachable.trans {u v w : V}\n  (huv : G.reachable u v) (hvw : G.reachable v w) :\n  G.reachable u w :=\nhuv.elim (\u03bb puv, hvw.elim (\u03bb pvw, \u27e8puv.append pvw\u27e9))\n\nlemma reachable_iff_refl_trans_gen (u v : V) :\n  G.reachable u v \u2194 relation.refl_trans_gen G.adj u v :=\nbegin\n  split,\n  { rintro \u27e8h\u27e9,\n    induction h,\n    { refl, },\n    { exact (relation.refl_trans_gen.single h_h).trans h_ih, }, },\n  { intro h,\n    induction h with _ _ _ ha hr,\n    { refl, },\n    { exact reachable.trans hr \u27e8walk.cons ha walk.nil\u27e9, }, },\nend\n\nvariables (G)\n\nlemma reachable_is_equivalence : equivalence G.reachable :=\nmk_equivalence _ (@reachable.refl _ G) (@reachable.symm _ G) (@reachable.trans _ G)\n\n/-- The equivalence relation on vertices given by `simple_graph.reachable`. -/\ndef reachable_setoid : setoid V := setoid.mk _ G.reachable_is_equivalence\n\n/-- A graph is preconnected if every pair of vertices is reachable from one another. -/\ndef preconnected : Prop := \u2200 (u v : V), G.reachable u v\n\nlemma preconnected.map {G : simple_graph V} {H : simple_graph V'} (f : G \u2192g H) (hf : surjective f)\n  (hG : G.preconnected) : H.preconnected :=\nhf.forall\u2082.2 $ \u03bb a b, (hG _ _).map $ walk.map _\n\nlemma iso.preconnected_iff {G : simple_graph V} {H : simple_graph V'} (e : G \u2243g H) :\n  G.preconnected \u2194 H.preconnected :=\n\u27e8preconnected.map e.to_hom e.to_equiv.surjective,\n  preconnected.map e.symm.to_hom e.symm.to_equiv.surjective\u27e9\n\n/-- A graph is connected if it's preconnected and contains at least one vertex.\nThis follows the convention observed by mathlib that something is connected iff it has\nexactly one connected component.\n\nThere is a `has_coe_to_fun` instance so that `h u v` can be used instead\nof `h.preconnected u v`. -/\n@[protect_proj]\nstructure connected : Prop :=\n(preconnected : G.preconnected)\n[nonempty : nonempty V]\n\ninstance : has_coe_to_fun G.connected (\u03bb _, \u03a0 (u v : V), G.reachable u v) :=\n\u27e8\u03bb h, h.preconnected\u27e9\n\nlemma connected.map {G : simple_graph V} {H : simple_graph V'} (f : G \u2192g H) (hf : surjective f)\n  (hG : G.connected) : H.connected :=\nby { haveI := hG.nonempty.map f, exact \u27e8hG.preconnected.map f hf\u27e9 }\n\nlemma iso.connected_iff {G : simple_graph V} {H : simple_graph V'} (e : G \u2243g H) :\n  G.connected \u2194 H.connected :=\n\u27e8connected.map e.to_hom e.to_equiv.surjective,\n  connected.map e.symm.to_hom e.symm.to_equiv.surjective\u27e9\n\n/-- The quotient of `V` by the `simple_graph.reachable` relation gives the connected\ncomponents of a graph. -/\ndef connected_component := quot G.reachable\n\n/-- Gives the connected component containing a particular vertex. -/\ndef connected_component_mk (v : V) : G.connected_component := quot.mk G.reachable v\n\ninstance connected_component.inhabited [inhabited V] : inhabited G.connected_component :=\n\u27e8G.connected_component_mk default\u27e9\n\nsection connected_component\nvariables {G}\n\n@[elab_as_eliminator]\nprotected lemma connected_component.ind {\u03b2 : G.connected_component \u2192 Prop}\n  (h : \u2200 (v : V), \u03b2 (G.connected_component_mk v)) (c : G.connected_component) : \u03b2 c :=\nquot.ind h c\n\n@[elab_as_eliminator]\nprotected lemma connected_component.ind\u2082 {\u03b2 : G.connected_component \u2192 G.connected_component \u2192 Prop}\n  (h : \u2200 (v w : V), \u03b2 (G.connected_component_mk v) (G.connected_component_mk w))\n  (c d : G.connected_component) : \u03b2 c d :=\nquot.induction_on\u2082 c d h\n\nprotected lemma connected_component.sound {v w : V} :\n  G.reachable v w \u2192 G.connected_component_mk v = G.connected_component_mk w := quot.sound\n\nprotected lemma connected_component.exact {v w : V} :\n  G.connected_component_mk v = G.connected_component_mk w \u2192 G.reachable v w :=\n@quotient.exact _ G.reachable_setoid _ _\n\n@[simp] protected lemma connected_component.eq {v w : V} :\n  G.connected_component_mk v = G.connected_component_mk w \u2194 G.reachable v w :=\n@quotient.eq _ G.reachable_setoid _ _\n\n/-- The `connected_component` specialization of `quot.lift`. Provides the stronger\nassumption that the vertices are connected by a path. -/\nprotected def connected_component.lift {\u03b2 : Sort*} (f : V \u2192 \u03b2)\n  (h : \u2200 (v w : V) (p : G.walk v w), p.is_path \u2192 f v = f w) : G.connected_component \u2192 \u03b2 :=\nquot.lift f (\u03bb v w (h' : G.reachable v w), h'.elim_path (\u03bb hp, h v w hp hp.2))\n\n@[simp] protected lemma connected_component.lift_mk {\u03b2 : Sort*} {f : V \u2192 \u03b2}\n  {h : \u2200 (v w : V) (p : G.walk v w), p.is_path \u2192 f v = f w} {v : V} :\n  connected_component.lift f h (G.connected_component_mk v) = f v := rfl\n\nprotected lemma connected_component.\u00abexists\u00bb {p : G.connected_component \u2192 Prop} :\n  (\u2203 (c : G.connected_component), p c) \u2194 \u2203 v, p (G.connected_component_mk v) :=\n(surjective_quot_mk G.reachable).exists\n\nprotected lemma connected_component.\u00abforall\u00bb {p : G.connected_component \u2192 Prop} :\n  (\u2200 (c : G.connected_component), p c) \u2194 \u2200 v, p (G.connected_component_mk v) :=\n(surjective_quot_mk G.reachable).forall\n\nlemma preconnected.subsingleton_connected_component (h : G.preconnected) :\n  subsingleton G.connected_component :=\n\u27e8connected_component.ind\u2082 (\u03bb v w, connected_component.sound (h v w))\u27e9\n\nend connected_component\n\nvariables {G}\n\n/-- A subgraph is connected if it is connected as a simple graph. -/\nabbreviation subgraph.connected (H : G.subgraph) : Prop := H.coe.connected\n\nlemma preconnected.set_univ_walk_nonempty (hconn : G.preconnected) (u v : V) :\n  (set.univ : set (G.walk u v)).nonempty :=\nby { rw \u2190 set.nonempty_iff_univ_nonempty, exact hconn u v }\n\nlemma connected.set_univ_walk_nonempty (hconn : G.connected) (u v : V) :\n  (set.univ : set (G.walk u v)).nonempty := hconn.preconnected.set_univ_walk_nonempty u v\n\n/-! ### Walks of a given length -/\n\nsection walk_counting\n\nlemma set_walk_self_length_zero_eq (u : V) :\n  {p : G.walk u u | p.length = 0} = {walk.nil} :=\nby { ext p, simp }\n\nlemma set_walk_length_zero_eq_of_ne {u v : V} (h : u \u2260 v) :\n  {p : G.walk u v | p.length = 0} = \u2205 :=\nbegin\n  ext p,\n  simp only [set.mem_set_of_eq, set.mem_empty_eq, iff_false],\n  exact \u03bb h', absurd (walk.eq_of_length_eq_zero h') h,\nend\n\nlemma set_walk_length_succ_eq (u v : V) (n : \u2115) :\n  {p : G.walk u v | p.length = n.succ} =\n    \u22c3 (w : V) (h : G.adj u w), walk.cons h '' {p' : G.walk w v | p'.length = n} :=\nbegin\n  ext p,\n  cases p with _ _ w _ huw pwv,\n  { simp [eq_comm], },\n  { simp only [nat.succ_eq_add_one, set.mem_set_of_eq, walk.length_cons, add_left_inj,\n      set.mem_Union, set.mem_image, exists_prop],\n    split,\n    { rintro rfl,\n      exact \u27e8w, huw, pwv, rfl, rfl, heq.rfl\u27e9, },\n    { rintro \u27e8w, huw, pwv, rfl, rfl, rfl\u27e9,\n      refl, } },\nend\n\nvariables (G) [fintype V] [decidable_rel G.adj] [decidable_eq V]\n\n/-- The `finset` of length-`n` walks from `u` to `v`.\nThis is used to give `{p : G.walk u v | p.length = n}` a `fintype` instance, and it\ncan also be useful as a recursive description of this set when `V` is finite.\n\nSee `simple_graph.coe_finset_walk_length_eq` for the relationship between this `finset` and\nthe set of length-`n` walks. -/\ndef finset_walk_length : \u03a0 (n : \u2115) (u v : V), finset (G.walk u v)\n| 0 u v := if h : u = v\n           then by { subst u, exact {walk.nil} }\n           else \u2205\n| (n+1) u v := finset.univ.bUnion (\u03bb (w : V),\n                 if h : G.adj u w\n                 then (finset_walk_length n w v).map \u27e8\u03bb p, walk.cons h p, \u03bb p q, by simp\u27e9\n                 else \u2205)\n\nlemma coe_finset_walk_length_eq (n : \u2115) (u v : V) :\n  (G.finset_walk_length n u v : set (G.walk u v)) = {p : G.walk u v | p.length = n} :=\nbegin\n  induction n with n ih generalizing u v,\n  { obtain rfl | huv := eq_or_ne u v;\n    simp [finset_walk_length, set_walk_length_zero_eq_of_ne, *], },\n  { simp only [finset_walk_length, set_walk_length_succ_eq,\n      finset.coe_bUnion, finset.mem_coe, finset.mem_univ, set.Union_true],\n    ext p,\n    simp only [set.mem_Union, finset.mem_coe, set.mem_image, set.mem_set_of_eq],\n    congr' 2,\n    ext w,\n    simp only [set.ext_iff, finset.mem_coe, set.mem_set_of_eq] at ih,\n    split_ifs with huw; simp [huw, ih], },\nend\n\nvariables {G}\n\nlemma walk.length_eq_of_mem_finset_walk_length {n : \u2115} {u v : V} (p : G.walk u v) :\n  p \u2208 G.finset_walk_length n u v \u2192 p.length = n :=\n(set.ext_iff.mp (G.coe_finset_walk_length_eq n u v) p).mp\n\nvariables (G)\n\ninstance fintype_set_walk_length (u v : V) (n : \u2115) : fintype {p : G.walk u v | p.length = n} :=\nfintype.subtype (G.finset_walk_length n u v) $ \u03bb p,\nby rw [\u2190finset.mem_coe, coe_finset_walk_length_eq]\n\nlemma set_walk_length_to_finset_eq (n : \u2115) (u v : V) :\n  {p : G.walk u v | p.length = n}.to_finset = G.finset_walk_length n u v :=\nby { ext p, simp [\u2190coe_finset_walk_length_eq] }\n\n/- See `simple_graph.adj_matrix_pow_apply_eq_card_walk` for the cardinality in terms of the `n`th\npower of the adjacency matrix. -/\nlemma card_set_walk_length_eq (u v : V) (n : \u2115) :\n  fintype.card {p : G.walk u v | p.length = n} = (G.finset_walk_length n u v).card :=\nfintype.card_of_subtype (G.finset_walk_length n u v) $ \u03bb p,\nby rw [\u2190finset.mem_coe, coe_finset_walk_length_eq]\n\nend walk_counting\n\nend simple_graph\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/combinatorics/simple_graph/connectivity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7288155970694788}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport data.polynomial.erase_lead\nimport data.polynomial.degree\n\n/-!\n# Reverse of a univariate polynomial\n\nThe main definition is `reverse`.  Applying `reverse` to a polynomial `f : polynomial R` produces\nthe polynomial with a reversed list of coefficients, equivalent to `X^f.nat_degree * f(1/X)`.\n\nThe main result is that `reverse (f * g) = reverse (f) * reverse (g)`, provided the leading\ncoefficients of `f` and `g` do not multiply to zero.\n-/\n\nnamespace polynomial\n\nopen polynomial finsupp finset\nopen_locale classical\n\nsection semiring\n\nvariables {R : Type*} [semiring R] {f : polynomial R}\n\n/-- If `i \u2264 N`, then `rev_at_fun N i` returns `N - i`, otherwise it returns `i`.\nThis is the map used by the embedding `rev_at`.\n-/\ndef rev_at_fun (N i : \u2115) : \u2115 := ite (i \u2264 N) (N-i) i\n\nlemma rev_at_fun_invol {N i : \u2115} : rev_at_fun N (rev_at_fun N i) = i :=\nbegin\n  unfold rev_at_fun,\n  split_ifs with h j,\n  { exact nat.sub_sub_self h, },\n  { exfalso,\n    apply j,\n    exact nat.sub_le N i, },\n  { refl, },\nend\n\nlemma rev_at_fun_inj {N : \u2115} : function.injective (rev_at_fun N) :=\nbegin\n  intros a b hab,\n  rw [\u2190 @rev_at_fun_invol N a, hab, rev_at_fun_invol],\nend\n\n/-- If `i \u2264 N`, then `rev_at N i` returns `N - i`, otherwise it returns `i`.\nEssentially, this embedding is only used for `i \u2264 N`.\nThe advantage of `rev_at N i` over `N - i` is that `rev_at` is an involution.\n-/\ndef rev_at (N : \u2115) : function.embedding \u2115 \u2115 :=\n{ to_fun := \u03bb i , (ite (i \u2264 N) (N-i) i),\n  inj' := rev_at_fun_inj }\n\n/-- We prefer to use the bundled `rev_at` over unbundled `rev_at_fun`. -/\n@[simp] lemma rev_at_fun_eq (N i : \u2115) : rev_at_fun N i = rev_at N i := rfl\n\n@[simp] lemma rev_at_invol {N i : \u2115} : (rev_at N) (rev_at N i) = i :=\nrev_at_fun_invol\n\n@[simp] lemma rev_at_le {N i : \u2115} (H : i \u2264 N) : rev_at N i = N - i :=\nif_pos H\n\nlemma rev_at_add {N O n o : \u2115} (hn : n \u2264 N) (ho : o \u2264 O) :\n  rev_at (N + O) (n + o) = rev_at N n + rev_at O o :=\nbegin\n  rcases nat.le.dest hn with \u27e8n', rfl\u27e9,\n  rcases nat.le.dest ho with \u27e8o', rfl\u27e9,\n  repeat { rw rev_at_le (le_add_right rfl.le) },\n  rw [add_assoc, add_left_comm n' o, \u2190 add_assoc, rev_at_le (le_add_right rfl.le)],\n  repeat {rw nat.add_sub_cancel_left},\nend\n\n/-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (rev_at N i)`.\nIn other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`.\n\nIn practice, `reflect` is only used when `N` is at least as large as the degree of `f`.\n\nEventually, it will be used with `N` exactly equal to the degree of `f`.  -/\nnoncomputable def reflect (N : \u2115) (f : polynomial R) : polynomial R :=\nfinsupp.emb_domain (rev_at N) f\n\nlemma reflect_support (N : \u2115) (f : polynomial R) :\n  (reflect N f).support = image (rev_at N) f.support :=\nbegin\n  ext1,\n  rw [reflect, mem_image, support, support, support_emb_domain, mem_map],\nend\n\n@[simp] lemma coeff_reflect (N : \u2115) (f : polynomial R) (i : \u2115) :\n  coeff (reflect N f) i = f.coeff (rev_at N i) :=\ncalc finsupp.emb_domain (rev_at N) f i\n    = finsupp.emb_domain (rev_at N) f (rev_at N (rev_at N i)) : by rw rev_at_invol\n... = f.coeff (rev_at N i) : finsupp.emb_domain_apply _ _ _\n\n@[simp] lemma reflect_zero {N : \u2115} : reflect N (0 : polynomial R) = 0 := rfl\n\n@[simp] lemma reflect_eq_zero_iff {N : \u2115} {f : polynomial R} :\n  reflect N (f : polynomial R) = 0 \u2194 f = 0 :=\nby simp [reflect]\n\n@[simp] lemma reflect_add (f g : polynomial R) (N : \u2115) :\n  reflect N (f + g) = reflect N f + reflect N g :=\nby { ext, simp only [coeff_add, coeff_reflect], }\n\n@[simp] lemma reflect_C_mul (f : polynomial R) (r : R) (N : \u2115) :\n  reflect N (C r * f) = C r * (reflect N f) :=\nby { ext, simp only [coeff_reflect, coeff_C_mul], }\n\n@[simp] lemma reflect_C_mul_X_pow (N n : \u2115) {c : R} :\n  reflect N (C c * X ^ n) = C c * X ^ (rev_at N n) :=\nbegin\n  ext,\n  rw [reflect_C_mul, coeff_C_mul, coeff_C_mul, coeff_X_pow, coeff_reflect],\n  split_ifs with h j,\n  { rw [h, rev_at_invol, coeff_X_pow_self], },\n  { rw [not_mem_support_iff.mp],\n    intro a,\n    rw [\u2190 one_mul (X ^ n), \u2190 C_1] at a,\n    apply h,\n    rw [\u2190 (mem_support_C_mul_X_pow a), rev_at_invol], },\nend\n\n@[simp] lemma reflect_monomial (N n : \u2115) : reflect N ((X : polynomial R) ^ n) = X ^ (rev_at N n) :=\nby rw [\u2190 one_mul (X ^ n), \u2190 one_mul (X ^ (rev_at N n)), \u2190 C_1, reflect_C_mul_X_pow]\n\nlemma reflect_mul_induction (cf cg : \u2115) :\n  \u2200 N O : \u2115, \u2200 f g : polynomial R,\n  f.support.card \u2264 cf.succ \u2192 g.support.card \u2264 cg.succ \u2192 f.nat_degree \u2264 N \u2192 g.nat_degree \u2264 O \u2192\n  (reflect (N + O) (f * g)) = (reflect N f) * (reflect O g) :=\nbegin\n  induction cf with cf hcf,\n  --first induction (left): base case\n  { induction cg with cg hcg,\n    -- second induction (right): base case\n    { intros N O f g Cf Cg Nf Og,\n      rw [\u2190 C_mul_X_pow_eq_self Cf, \u2190 C_mul_X_pow_eq_self Cg],\n      simp only [mul_assoc, X_pow_mul, \u2190 pow_add X, reflect_C_mul, reflect_monomial,\n                 add_comm, rev_at_add Nf Og] },\n    -- second induction (right): induction step\n    { intros N O f g Cf Cg Nf Og,\n      by_cases g0 : g = 0,\n      { rw [g0, reflect_zero, mul_zero, mul_zero, reflect_zero], },\n\n      rw [\u2190 erase_lead_add_C_mul_X_pow g, mul_add, reflect_add, reflect_add, mul_add, hcg, hcg];\n        try { assumption },\n      { exact le_add_left card_support_C_mul_X_pow_le_one },\n      { exact (le_trans (nat_degree_C_mul_X_pow_le g.leading_coeff g.nat_degree) Og) },\n      { exact nat.lt_succ_iff.mp (gt_of_ge_of_gt Cg (erase_lead_support_card_lt g0)) },\n      { exact le_trans erase_lead_nat_degree_le Og } } },\n  --first induction (left): induction step\n  { intros N O f g Cf Cg Nf Og,\n    by_cases f0 : f = 0,\n    { rw [f0, reflect_zero, zero_mul, zero_mul, reflect_zero], },\n\n    rw [\u2190 erase_lead_add_C_mul_X_pow f, add_mul, reflect_add, reflect_add, add_mul, hcf, hcf];\n       try { assumption },\n    { exact le_add_left card_support_C_mul_X_pow_le_one },\n    { exact (le_trans (nat_degree_C_mul_X_pow_le f.leading_coeff f.nat_degree) Nf) },\n    { exact nat.lt_succ_iff.mp (gt_of_ge_of_gt Cf (erase_lead_support_card_lt f0)) },\n    { exact (le_trans erase_lead_nat_degree_le Nf) } },\nend\n\n@[simp] theorem reflect_mul\n  (f g : polynomial R) {F G : \u2115} (Ff : f.nat_degree \u2264 F) (Gg : g.nat_degree \u2264 G) :\n  reflect (F + G) (f * g) = reflect F f * reflect G g :=\nreflect_mul_induction _ _ F G f g f.support.card.le_succ g.support.card.le_succ Ff Gg\n\n/-- The reverse of a polynomial f is the polynomial obtained by \"reading f backwards\".\nEven though this is not the actual definition, reverse f = f (1/X) * X ^ f.nat_degree. -/\nnoncomputable def reverse (f : polynomial R) : polynomial R := reflect f.nat_degree f\n\nlemma coeff_reverse (f : polynomial R) (n : \u2115) :\n  f.reverse.coeff n = f.coeff (rev_at f.nat_degree n) :=\nby rw [reverse, coeff_reflect]\n\n@[simp] lemma coeff_zero_reverse (f : polynomial R) : coeff (reverse f) 0 = leading_coeff f :=\nby rw [coeff_reverse, rev_at_le (zero_le f.nat_degree), nat.sub_zero, leading_coeff]\n\n@[simp] lemma reverse_zero : reverse (0 : polynomial R) = 0 := rfl\n\n@[simp] lemma reverse_eq_zero : f.reverse = 0 \u2194 f = 0 :=\nbegin\n  split,\n  { rw [polynomial.ext_iff, polynomial.ext_iff],\n    intros h n,\n    specialize h (rev_at f.nat_degree n),\n    rwa [coeff_zero, coeff_reverse, rev_at_invol] at h },\n  { intro h,\n    rw [h, reverse_zero] },\nend\n\nlemma reverse_nat_degree_le (f : polynomial R) : f.reverse.nat_degree \u2264 f.nat_degree :=\nbegin\n  rw [nat_degree_le_iff_degree_le, degree_le_iff_coeff_zero],\n  intros n hn,\n  rw with_bot.coe_lt_coe at hn,\n  rw [coeff_reverse, rev_at, function.embedding.coe_fn_mk,\n      if_neg (not_le_of_gt hn), coeff_eq_zero_of_nat_degree_lt hn],\nend\n\nlemma nat_degree_eq_reverse_nat_degree_add_nat_trailing_degree (f : polynomial R) :\n  f.nat_degree = f.reverse.nat_degree + f.nat_trailing_degree :=\nbegin\n  by_cases hf : f = 0,\n  { rw [hf, reverse_zero, nat_degree_zero, nat_trailing_degree_zero] },\n  apply le_antisymm,\n  { apply nat.le_add_of_sub_le_right,\n    apply le_nat_degree_of_ne_zero,\n    rw [reverse, coeff_reflect, \u2190rev_at_le f.nat_trailing_degree_le_nat_degree, rev_at_invol],\n    exact trailing_coeff_nonzero_iff_nonzero.mpr hf },\n  { rw \u2190 nat.le_sub_left_iff_add_le f.reverse_nat_degree_le,\n    apply nat_trailing_degree_le_of_ne_zero,\n    have key := mt leading_coeff_eq_zero.mp (mt reverse_eq_zero.mp hf),\n    rwa [leading_coeff, coeff_reverse, rev_at_le f.reverse_nat_degree_le] at key },\nend\n\nlemma reverse_nat_degree (f : polynomial R) :\n  f.reverse.nat_degree = f.nat_degree - f.nat_trailing_degree :=\nby rw [f.nat_degree_eq_reverse_nat_degree_add_nat_trailing_degree, nat.add_sub_cancel]\n\nlemma reverse_leading_coeff (f : polynomial R) : f.reverse.leading_coeff = f.trailing_coeff :=\nby rw [leading_coeff, reverse_nat_degree, \u2190rev_at_le f.nat_trailing_degree_le_nat_degree,\n  coeff_reverse, rev_at_invol, trailing_coeff]\n\nlemma reverse_nat_trailing_degree  (f : polynomial R) : f.reverse.nat_trailing_degree = 0 :=\nbegin\n  by_cases hf : f = 0,\n  { rw [hf, reverse_zero, nat_trailing_degree_zero] },\n  { rw \u2190 nat.le_zero_iff,\n    apply nat_trailing_degree_le_of_ne_zero,\n    rw [coeff_zero_reverse],\n    exact mt leading_coeff_eq_zero.mp hf },\nend\n\n\n\ntheorem reverse_mul {f g : polynomial R} (fg : f.leading_coeff * g.leading_coeff \u2260 0) :\n reverse (f * g) = reverse f * reverse g :=\nbegin\n  unfold reverse,\n  rw [nat_degree_mul' fg, reflect_mul  f g rfl.le rfl.le],\nend\n\n@[simp] lemma reverse_mul_of_domain {R : Type*} [domain R] (f g : polynomial R) :\n  reverse (f * g) = reverse f * reverse g :=\nbegin\n  by_cases f0 : f=0,\n  { simp only [f0, zero_mul, reverse_zero], },\n  by_cases g0 : g=0,\n  { rw [g0, mul_zero, reverse_zero, mul_zero], },\n  simp [reverse_mul, *],\nend\n\nlemma trailing_coeff_mul {R : Type*} [integral_domain R] (p q : polynomial R) :\n  (p * q).trailing_coeff = p.trailing_coeff * q.trailing_coeff :=\nby rw [\u2190reverse_leading_coeff, reverse_mul_of_domain, leading_coeff_mul,\n  reverse_leading_coeff, reverse_leading_coeff]\n\n@[simp] lemma coeff_one_reverse (f : polynomial R) : coeff (reverse f) 1 = next_coeff f :=\nbegin\n  rw [coeff_reverse, next_coeff],\n  split_ifs with hf,\n  { have : coeff f 1 = 0 := coeff_eq_zero_of_nat_degree_lt (by simp only [hf, zero_lt_one]),\n    simp [*, rev_at] },\n  { rw rev_at_le,\n    exact nat.succ_le_iff.2 (pos_iff_ne_zero.2 hf) }\nend\n\nend semiring\n\nsection ring\n\nvariables {R : Type*} [ring R]\n\n@[simp] lemma reflect_neg (f : polynomial R) (N : \u2115) :\n  reflect N (- f) = - reflect N f :=\nby rw [neg_eq_neg_one_mul, \u2190C_1, \u2190C_neg, reflect_C_mul, C_neg, C_1, \u2190neg_eq_neg_one_mul]\n\n@[simp] lemma reflect_sub (f g : polynomial R) (N : \u2115) :\n  reflect N (f - g) = reflect N f - reflect N g :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, reflect_add, reflect_neg]\n\n@[simp] lemma reverse_neg (f : polynomial R) :\n  reverse (- f) = - reverse f :=\nby rw [reverse, reverse, reflect_neg, nat_degree_neg]\n\nend ring\n\nend polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/polynomial/reverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7288155950382956}}
{"text": "import data.real.basic\n\nvariables a b c : \u211d\n\n#check lt_trans\n#check lt_of_le_of_lt\n\n-- BEGIN\nexample (a b c d e : \u211d) (h\u2080 : a \u2264 b) (h\u2081 : b < c) (h\u2082 : c \u2264 d)\n    (h\u2083 : d < e) : a < e :=\nbegin\n  apply lt_of_le_of_lt h\u2080,\n  apply lt_trans h\u2081,\n  apply lt_of_le_of_lt h\u2082,\n  exact h\u2083,\nend \n\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.1_apply/ex2_apply_lt_trans.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505376715774, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7288155865948034}}
{"text": "--import tactic.finish\n-- This is an example as per the instructions \n-- in the introduction. The follwing means: let \n-- there be an example such that P, Q, and R are \n-- Prop(ositions), where there is a hypothesis HP\n-- that refers to the proposition P, and there is\n-- a hypothesis HQ that refers to the proposition \n-- Q, and P is the variable to find the truth value\n-- of. As such, we begin the proof, give a valid\n-- proof of HP, which means that P has a truth value.\n-- Then end not being underlined in red or green \n-- shows that the proof is a valid one to be able to\n-- arrive at the conclusion that P is defined. \nexample (P Q R : Prop) (HP : P) (HQ : Q) : P :=\nbegin\n  exact HP,\nend\n\n-- proof of P \u2192 Q, and then proving P, to prove Q \ntheorem easy (P Q : Prop) (HP :P) (HPQ : P \u2192 Q) : Q :=\nbegin\n  exact HPQ HP,\nend\n\n-- proving P \u2192 q is the idea that we should assume we \n-- already have a proof of P, and then somehow deduce\n-- a proof of Q. This can be done in Lean by the\n-- intro tactic.\n\ntheorem Q_implies_P_impliesQ (P Q : Prop) (HQ : Q) : P \u2192 Q :=\n-- propositions p and q given such that hq is a proof of q, \n-- and hence define p \u2192 q.\nbegin\n  intro HP, \n  exact HQ,\nend\n\n-- the intro tactic is a cons for p \u2192 q\n-- if the goal is p \u2192 q then we can type intro hp and then lean proves our goal, modulo some other simpler things (proof of q)\n\ntheorem P_implies_P (P : Prop) : P \u2192 P :=\nbegin\n  intro HP,\n  exact HP,\nend\n\nexample (P Q : Prop) : P \u2227 (P \u2192 Q) \u2192 Q :=\nbegin\n    intro HPnPQ,\n    cases HPnPQ with HP HPQ,\n    exact HPQ HP,\nend\n\ntheorem and_comm1 (P Q : Prop) : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n    assume HPQ : P \u2227 Q,\n    have HP : P, from and.left HPQ,\n    have HQ : Q, from and.right HPQ,\n    show Q \u2227 P, from and.intro HQ HP, \nend\n\nconstant m : nat \nconstant n : nat\nconstants b1 b2 : bool\n\n#check m\n#check n \n#check n + 0\n#check m * (n + 0) \n#check b1\n#check b1 && b2\n#check b1 || b2 \n#check tt\n\n/-Text inbetween these symbols is ignored.\naka. Mass commentating tool!!-/\n\n\n\n\n-- theorem comm_1 (A B C : Prop) : (A \u2227 B) \u2227 C \u2194 A \u2227 (B \u2227 C) :=\n-- begin\n--     split,\n--     {\n--         intro HAnBnC,\n--         cases HAnBnC with HAnB HC,\n--         cases HAnB with HA HB,\n--         split,\n--         {\n--             exact HA,\n\n--         },\n--         {\n--             split,\n--             {\n--                 exact HB,\n--             },\n--             {\n--                 exact HC,\n--             },\n--         },\n\n--     },\n    \n-- end\n\ntheorem needs_intros (P Q R :Prop) (HR : R) : P \u2192 (Q \u2192 R) :=\nbegin \n    intro HP, \n    intro HQ,\n    exact HR,\nend\n\ntheorem very_easy : true :=\nbegin \n    exact trivial,\nend\n\ntheorem very_hard: false := \nbegin\n    sorry,\nend\n\ntheorem false_implies_false : false \u2192 false :=\nbegin \n    intro Hfalse,\n    exact Hfalse,\nend\n\ntheorem not_not (P : Prop) : P \u2192 \u00ac (\u00ac P) :=\nbegin\n    intro HP,\n    intro HnP,\n    apply HnP, -- to reduce goal from false to P. \n    exact HP,\nend\n\ntheorem contrapos (P Q : Prop) (HPQ : P \u2192 Q) : \u00ac Q \u2192 \u00ac P :=\nbegin\n    intro HnQ,\n    intro HP,\n    apply HnQ,\n    apply HPQ,\n    apply HP,\nend\n\ntheorem P_implies_P_or_Q (P Q :Prop) (HP : P) : P \u2228 Q :=\nbegin\n    left,\n    exact HP,\nend\n\ntheorem Q_implies_P_or_Q (P Q : Prop) (HQ : Q) : P \u2228 Q :=\nbegin \n    right,\n    exact HQ,\nend\n\ntheorem dont_get_lost (P Q : Prop) (HQ : Q) : P \u2228 Q :=\nbegin\n    left,\n        -- goal no longer provable; as there is nothing left to deduce to be able to prove P.\n    sorry,\nend\n\ntheorem or_symmetry (P Q :Prop) : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n    intro HPQ,\n    cases HPQ with HP HQ,\n    {\n        right,\n        exact HP,\n    },\n    {\n        left,\n        exact HQ,\n    },\nend\n\ntheorem or_experiment (P Q R :Prop) (HPQR : P \u2228 Q \u2228 R) : true :=\nbegin\n    cases HPQR with HP HQR,\n    sorry,\n    sorry,\nend\n\ntheorem or_associativity (P Q R : Prop) : P \u2228 (Q \u2228 R) \u2192 (P \u2228 Q) \u2228 R :=\nbegin \n    intro HPQR,\n    cases HPQR with HP HQR,\n    {\n        left,\n        left,\n        exact HP,\n    },\n    {\n        cases HQR with HQ HR,\n        {\n            left,\n            right,\n            exact HQ,\n        },\n        {\n            right,\n            exact HR,\n        },\n    },\nend\n\ntheorem and_definition (P Q : Prop) (HP : P) (HQ : Q) : P \u2227 Q :=\nbegin\n    split,\n    {exact HP,},\n    {exact HQ,},\nend\n\ntheorem and_symmetry (P Q : Prop) (HP :P) (HQ : Q) : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n    intro HPQ,\n    split,\n    cases HPQ with HP HQ,\n    {exact HQ,},\n    {exact HP,},\nend\n\ntheorem and_transitivity (P Q R : Prop) : (P \u2227 Q) \u2227 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n    intro HPQR,\n    cases HPQR with HPQ HQR,\n    split,\n        cases HPQ with HP HQ,\n        exact HP,\n        cases HQR with HQ HR,\n        exact HR, \nend\n\ntheorem iff_symmetric (P Q : Prop) : (P \u2194 Q) \u2194 (Q \u2194 P) :=\nbegin\n    split,\n    intro HPiffQ,\n    cases HPiffQ with HPtoQ HQtoP,\n    split,\n        exact HQtoP,\n        exact HPtoQ,\n    \n    intro HQiffP,\n    cases HQiffP with HQtoP HPtoQ,\n    split,\n        exact HPtoQ,\n        exact HQtoP,\nend\n\ntheorem iff_transitive (P Q R : Prop) : (P \u2194 Q) \u2227 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n    intro H,\n    cases H with HPiffQ HQiffR,\n    rw HPiffQ,\n    exact HQiffR,\nend\n\ntheorem not_not_1 (P : Prop) : \u00ac (\u00ac P) \u2192 P :=\nbegin\n    cases (classical.em P) with HP HnP,\n    {\n        intro HnnP,\n        exact HP,\n    },\n    {\n        intro HnnP,\n        exfalso,\n        apply HnnP,\n        exact HnP,\n    }, \nend\n\ntheorem contra (P Q : Prop) : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n    intro HnQnP,\n    intro HP,\n\n    cases (classical.em Q) with HQ HnQ,\n    {\n        exact HQ,\n    },\n    {\n        exfalso,\n        apply HnQnP,\n        exact HnQ,\n        exact HP,\n    },\nend\n\ntheorem name1 (A B : Prop) : (\u00ac (A \u2227 B)) \u2194 (\u00ac A \u2228 \u00ac B) :=\nbegin\n    cases classical.em A with HA HnA,\n    {\n        cases classical.em B with HB HnB,\n        {\n            have HAB := and_definition A B HA HB,\n            split,\n            {\n                intro H,\n                exfalso,\n                exact H HAB,\n            },\n            {\n                intro H,\n                cases H with H1 H2,\n                {\n                    exfalso,\n                    contradiction,\n                },\n                {\n                    exfalso,\n                    contradiction,\n                }\n            }\n        },\n        {\n            split,\n            {\n                intro H,\n                right,\n                exact HnB,\n            },\n            {\n                intro H,\n                cases H with H1 H2,\n                {\n                    exfalso,\n                    exact H1 HA,\n                },\n                {\n                    intro HAB,\n                    cases HAB with _ HB,\n                    exact HnB HB,\n                },\n            },\n        },\n    },\n    {\n        cases classical.em B with HB HnB,\n        {\n            split,\n            intro _,\n            left,\n            exact HnA,\n            intro _,\n            intro H,\n            cases H with HA _,\n            exact HnA HA,\n        },\n        {\n            split,\n            intro _,\n            left,\n            exact HnA,\n            intro _,\n            intro H,\n            cases H with HA _,\n            exact HnA HA,\n        }\n    }\n    -- intro HnAaB,\n    -- right,\n    -- intro HB,\n    -- apply HnAaB,\n    -- split,\n    -- sorry,\n    -- sorry,\n\n    -- intro HnAnB,\n    -- cases HnAnB with HnA HnB,\n    --     {\n    --         intro HAaB,\n    --         sorry,\n    --     }\n    -- sorry,\n\nend\n\ntheorem name2 (P Q : Prop) (HP : P) (HQ : Q) : P \u2227 Q :=\nbegin\n    split,\n    exact HP,\n    exact HQ,\nend\n\n", "meta": {"author": "AHassan1024", "repo": "Lean_Playground", "sha": "a00b004c3a2eb9e3e863c361aa2b115260472414", "save_path": "github-repos/lean/AHassan1024-Lean_Playground", "path": "github-repos/lean/AHassan1024-Lean_Playground/Lean_Playground-a00b004c3a2eb9e3e863c361aa2b115260472414/src/Amy_Lean_Try/_del.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7288155845237753}}
{"text": "import tactic  -- imports all the tactics \nimport data.real.basic\nvariables (A B C D E F: Type) \nopen nat\n/-\nEverything in green or orange text is a `comment`. \n\nThis means that Lean ignores it.\n\nA single line comment starts with --\n\nA multi-line comment starts with /- and ends with -/\n\nComments are our way of explaining what our code does.\n\n# What is Lean?   \n\nLean is at least three things: \n\n1) A programming language in which we can write proofs (and more);\n\n2) A kernel that can verify the correctness of proofs written in this language;\n\n3) A set of tools that help us to write proofs (automation).\n\nWe will gradually introduce the Lean language and we will rely on its kernel to check \nour code/proofs. The different tools for automation will also become apparent as we progress.\n\n# Infoview\n\nOne of the most helpful tools that Lean has is the Infoview.\n\nOpen the `Infoview` panel by pressing `Ctrl + Shift + Enter`\n\nYou should now have a split-window with this Lean code file\non the left and the `Lean Infoview` on the right.\n\nBefore we start to introduce the Lean syntax and tactics,\nlets first see what information this Lean Infoview provides.\n\nAs you move your cursor through the lines of text below, watch how\nthe Infoview updates. -/\n\n-- 01\nexample  (x : A) : A := \nbegin \n/-\nIf you place your cursor anywhere within this comment \nthe Infoview should display:\n1 goal\nA : Type\nx : A\n\u22a2 A\n-/\n  exact x,\n-- place your cursor here to see `goals accomplished`\nend\n\n/-\n  # Type theory vs Set theory\n\nLean is based on type theory.\n\nWhile mathematicians usually talk about `sets` and `elements`, in Lean\nwe have `types` and `terms`. \n\nIn our example above we told Lean that:\n\n`x` is a term a of type A `(x : A)` we can think of this as saying `x \u2208 A` \n\nThe final line of the Infoview is our goal: `\u22a2 A` which tells us the type of the \nterm that Lean is expecting us to produce. \n\nThis is the `return type` of the function and is determined by the `: A` after the hypotheses in our example.\n\nThe `:=` tells Lean we are going to define the body of this function.\n\nThe function body begins with `begin` and ends with `end`. This tells Lean\nwe are entering `tactic-mode`. \n\n(There are other `modes`, in particular `term-mode` but we will mainly focus on tactics.)\n\nThe only line of code inside the body is `exact x`. This is a tactic that says\n`x` is `exactly` a term of the type required by the goal. (Because `x` is a term of type `A`.) \n\n\nOur next tactic is `sorry`. This is a magic tactic that will accomplish any goal. \n\nUnfortunately this is cheating (notice the example below has a yellow wavy-line under it to \nwarn us that something is wrong and `sorry` is in bright red).\n\nThroughout this course you will encounter Lean code containing `sorry` that you will need to \nedit, replacing the `sorry` with an actual proof of the required goal.\n\nCan you replace the `sorry` with something that will actually accomplish the goal? -/\n\n-- 02\nexample  (x : A) (y : B) (z : C) : B :=\nbegin\n/- \n1 goal\nA B C : Type\nx : A\ny : B\nz : C\n\u22a2 B\n-/\n  sorry,\nend\n\n/-\nIf A and B are types,  then `A \u2192 B` is the type of functions from A to B. \n\n(Note that if you hover over any symbol Lean will tell you how to write it,\nfor example `\u2192` is `\\to`.)  \n\nIf `f : A \u2192 B` and `a : A` then `f a` is Lean for `f(a)`. \nThis may look strange, but will actually make our proofs easier to read.\n-/\n\n-- 03\nexample  (f : A \u2192 B) (a : A) : B :=\nbegin\n/-\n1 goal\nA B : Type\nf : A \u2192 B\na : A\n\u22a2 B\n-/\n  exact f a, -- Note that `exact f(a)` or `exact (f a)` or `exact (f(a))` will also work.\nend\n\n-- A different way to achieve the same goal is to use the `apply` tactic\n-- 04\nexample (f : A \u2192 B) (a : A) : B :=\nbegin\n/-\n1 goal\nA B : Type\nf : A \u2192 B\na : A\n\u22a2 B\n-/\n  apply f, \n/-\nNotice that our goal has changed from `\u22a2 B` to `\u22a2 A`. \n  \nThink of this as saying if we have a function `f: A \u2192 B`\nand our goal is `\u22a2 B` then we can `apply f` and this reduces our goal to supplying \nan input to the function `f`, namely a term of type A. \n-/ \n  exact a,  -- since our goal is now `\u22a2 A` we can close it with `a` since this is a term of type `A`.\nend\n\n-- 05\nexample  (f : A  \u2192 B) (g : B \u2192 C) (a : A) : C :=\nbegin\n-- goal `\u22a2 C`\n  apply g, -- goal changes from `\u22a2 C` to `\u22a2 B` \n  apply f, -- goal changes from `\u22a2 B` to `\u22a2 A`\n  exact a, -- done!\nend\n\n/-\nSee how many different ways you can find to complete the next example \nusing `exact` and/or `apply` -/\n\n-- 06\nexample  (f : A  \u2192 B) (g : B \u2192 C) (h : C \u2192 D) (a : A): D :=\nbegin\n  sorry, \nend\n\n-- 07\nexample (f :A \u2192 B) (g: B \u2192 C) (h: D \u2192 E) (i : C \u2192 E) (x : A) : E:=\nbegin\n  sorry,\nend\n\n-- 08 Can you work out what `f: A \u2192 B \u2192 C` means and complete this example?\nexample (f : A \u2192 B \u2192 C)  (x : A) (y : B): C:=\nbegin\n  sorry,\nend\n\n/- Mathematicians and Computer Scientists have slightly different ideas of how to \n   write functions of more than one variable. \n\nMath: `f : A \u00d7 B \u2192 C`    Comp Sci: `g : A \u2192 B \u2192 C` \n\nBoth of these can be defined in Lean, however the CS version (which is known as a\n`curried` function) turns out to be extremely useful.\n\nBut what do we mean by `A \u2192 B \u2192 C` ? We need to know where the brackets should go.\n\nWe need to know whether  `A \u2192 B \u2192 C` is `A \u2192 (B \u2192 C)` or `(A \u2192 B) \u2192 C`\n\nLets see how we can use Lean's `#check`  command to work this out.  -/\n\nvariable (f : A \u2192 (B \u2192 C))\nvariable (g : (A \u2192 B) \u2192 C) \n--#check f  -- f : A \u2192 B \u2192 C    Lean has removed our unnecessary brackets from f.\n--#check g  -- g : (A \u2192 B) \u2192 C  The brackets in g are required!\n\n-- 09  What is f?\nexample (f : A \u2192 B \u2192 C \u2192 D) (g : A \u2192 B) (x : A)(z : C): D :=\nbegin\n  sorry,\nend\n\n/- So far all our examples have involved applying functions to obtain new terms,\n but what if our goal is to construct a function itself?\n\n  In order to define functions we need a new tactic: `intro`    -/\n\n-- 10 \nexample : A \u2192 A :=\nbegin\n/-\n1 goal\nA : Type\n\u22a2 A \u2192 A \n-/\n  intro x, -- Now we have a `x : A`, a term x of type A and our goal is now `\u22a2 A`\n/-\n1 goal\nA : Type\nx : A\n\u22a2 A\n-/\n  exact x,  \nend\n\n-- 11 \nexample (b : B) : A \u2192 B :=\nbegin\n  sorry,\nend\n\n-- 12 [Tip: Rather than `intro a, intro b` you can just use `intros a b`]\nexample (c : C) : A \u2192 B \u2192 C \u2192 A \u2192 B \u2192  C \u2192 A :=\nbegin \n  sorry,\nend\n\n-- 13 \nexample (f : (A \u2192 B) \u2192 (C \u2192 D) \u2192 E) (b : B) (d : D) : E :=\nbegin\n  sorry,\nend\n\n-- 14   \nexample (f : (A \u2192 B \u2192 C) \u2192 D \u2192 (E \u2192 C) \u2192 B) (g : B \u2192 A \u2192 C) (h : (B \u2192 C) \u2192 D) (c : C): A \u2192 B:=\nbegin\n  sorry,\nend\n\n-- 15 Can you find a two line proof of this? (Hint: first find a longer proof and then shorten it)\nexample : ((A \u2192 D) \u2192 ((B \u2192 E) \u2192 (C \u2192 F))) \u2192 (((A \u2192 D) \u2192 (B \u2192 E)) \u2192 ((A \u2192 D) \u2192 (C \u2192 F))) :=\nbegin\n  sorry,\nend\n\n\n", "meta": {"author": "jt496", "repo": "Lean_Club", "sha": "391289884977a76dff5a0549f74742ca3d533fbb", "save_path": "github-repos/lean/jt496-Lean_Club", "path": "github-repos/lean/jt496-Lean_Club/Lean_Club-391289884977a76dff5a0549f74742ca3d533fbb/src/1_types_functions/functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7288125321894742}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport group_theory.free_abelian_group\nimport group_theory.is_free_group\nimport data.finsupp.basic\nimport data.equiv.module\nimport linear_algebra.dimension\n\n/-!\n# Isomorphism between `free_abelian_group X` and `X \u2192\u2080 \u2124`\n\nIn this file we construct the canonical isomorphism between `free_abelian_group X` and `X \u2192\u2080 \u2124`.\nWe use this to transport the notion of `support` from `finsupp` to `free_abelian_group`.\n\n## Main declarations\n\n- `free_abelian_group.equiv_finsupp`: group isomorphism between `free_abelian_group X` and `X \u2192\u2080 \u2124`\n- `free_abelian_group.coeff`: the multiplicity of `x : X` in `a : free_abelian_group X`\n- `free_abelian_group.support`: the finset of `x : X` that occur in `a : free_abelian_group X`\n\n-/\n\nnoncomputable theory\n\nopen_locale big_operators\n\nvariables {X : Type*}\n\n/-- The group homomorphism `free_abelian_group X \u2192+ (X \u2192\u2080 \u2124)`. -/\ndef free_abelian_group.to_finsupp : free_abelian_group X \u2192+ (X \u2192\u2080 \u2124) :=\nfree_abelian_group.lift $ \u03bb x, finsupp.single x (1 : \u2124)\n\n/-- The group homomorphism `(X \u2192\u2080 \u2124) \u2192+ free_abelian_group X`. -/\ndef finsupp.to_free_abelian_group : (X \u2192\u2080 \u2124) \u2192+ free_abelian_group X :=\nfinsupp.lift_add_hom $ \u03bb x, (smul_add_hom \u2124 (free_abelian_group X)).flip (free_abelian_group.of x)\n\nopen finsupp free_abelian_group\n\n@[simp] lemma finsupp.to_free_abelian_group_comp_single_add_hom (x : X) :\n  finsupp.to_free_abelian_group.comp (finsupp.single_add_hom x) =\n    (smul_add_hom \u2124 (free_abelian_group X)).flip (of x) :=\nbegin\n  ext,\n  simp only [add_monoid_hom.coe_comp, finsupp.single_add_hom_apply, function.comp_app,\n    one_smul, to_free_abelian_group, finsupp.lift_add_hom_apply_single]\nend\n\n@[simp] lemma free_abelian_group.to_finsupp_comp_to_free_abelian_group :\n  to_finsupp.comp to_free_abelian_group = add_monoid_hom.id (X \u2192\u2080 \u2124) :=\nbegin\n  ext x y, simp only [add_monoid_hom.id_comp],\n  rw [add_monoid_hom.comp_assoc, finsupp.to_free_abelian_group_comp_single_add_hom],\n  simp only [to_finsupp, add_monoid_hom.coe_comp, finsupp.single_add_hom_apply,\n    function.comp_app, one_smul, lift.of, add_monoid_hom.flip_apply,\n    smul_add_hom_apply, add_monoid_hom.id_apply],\nend\n\n@[simp] lemma finsupp.to_free_abelian_group_comp_to_finsupp :\n  to_free_abelian_group.comp to_finsupp = add_monoid_hom.id (free_abelian_group X) :=\nbegin\n  ext,\n  rw [to_free_abelian_group, to_finsupp, add_monoid_hom.comp_apply, lift.of,\n    lift_add_hom_apply_single, add_monoid_hom.flip_apply, smul_add_hom_apply, one_smul,\n    add_monoid_hom.id_apply],\nend\n\n@[simp] lemma finsupp.to_free_abelian_group_to_finsupp {X} (x : free_abelian_group X) :\n  x.to_finsupp.to_free_abelian_group = x :=\nby rw [\u2190 add_monoid_hom.comp_apply, finsupp.to_free_abelian_group_comp_to_finsupp,\n  add_monoid_hom.id_apply]\n\nnamespace free_abelian_group\nopen finsupp\n\nvariable {X}\n\n@[simp] \n\n@[simp] lemma to_finsupp_to_free_abelian_group (f : X \u2192\u2080 \u2124) :\n  f.to_free_abelian_group.to_finsupp = f :=\nby rw [\u2190 add_monoid_hom.comp_apply, to_finsupp_comp_to_free_abelian_group, add_monoid_hom.id_apply]\n\nvariable (X)\n\n/-- The additive equivalence between `free_abelian_group X` and `(X \u2192\u2080 \u2124)`. -/\n@[simps]\ndef equiv_finsupp : free_abelian_group X \u2243+ (X \u2192\u2080 \u2124) :=\n{ to_fun := to_finsupp,\n  inv_fun := to_free_abelian_group,\n  left_inv := to_free_abelian_group_to_finsupp,\n  right_inv := to_finsupp_to_free_abelian_group,\n  map_add' := to_finsupp.map_add }\n\n/-- `A` is a basis of the \u2124-module `free_abelian_group A`. -/\nnoncomputable def basis (\u03b1 : Type*) :\n  basis \u03b1 \u2124 (free_abelian_group \u03b1) :=\n\u27e8(free_abelian_group.equiv_finsupp \u03b1).to_int_linear_equiv \u27e9\n\n/-- Isomorphic free ablian groups (as modules) have equivalent bases. -/\ndef equiv.of_free_abelian_group_linear_equiv {\u03b1 \u03b2 : Type*}\n  (e : free_abelian_group \u03b1 \u2243\u2097[\u2124] free_abelian_group \u03b2) :\n  \u03b1 \u2243 \u03b2 :=\nlet t : _root_.basis \u03b1 \u2124 (free_abelian_group \u03b2) := (free_abelian_group.basis \u03b1).map e\n  in t.index_equiv $ free_abelian_group.basis _\n\n/-- Isomorphic free abelian groups (as additive groups) have equivalent bases. -/\ndef equiv.of_free_abelian_group_equiv {\u03b1 \u03b2 : Type*}\n  (e : free_abelian_group \u03b1 \u2243+ free_abelian_group \u03b2) :\n  \u03b1 \u2243 \u03b2 :=\nequiv.of_free_abelian_group_linear_equiv e.to_int_linear_equiv\n\n/-- Isomorphic free groups have equivalent bases. -/\ndef equiv.of_free_group_equiv {\u03b1 \u03b2 : Type*}\n  (e : free_group \u03b1 \u2243* free_group \u03b2) :\n  \u03b1 \u2243 \u03b2 :=\nequiv.of_free_abelian_group_equiv e.abelianization_congr.to_additive\n\nopen is_free_group\n/-- Isomorphic free groups have equivalent bases (`is_free_group` variant`). -/\ndef equiv.of_is_free_group_equiv {G H : Type*}\n  [group G] [group H] [is_free_group G] [is_free_group H]\n  (e : G \u2243* H) :\n  generators G \u2243 generators H :=\nequiv.of_free_group_equiv $\n  mul_equiv.trans ((to_free_group G).symm) $\n  mul_equiv.trans e $\n  to_free_group H\n\nvariable {X}\n\n/-- `coeff x` is the additive group homomorphism `free_abelian_group X \u2192+ \u2124`\nthat sends `a` to the multiplicity of `x : X` in `a`. -/\ndef coeff (x : X) : free_abelian_group X \u2192+ \u2124 :=\n(finsupp.apply_add_hom x).comp to_finsupp\n\n/-- `support a` for `a : free_abelian_group X` is the finite set of `x : X`\nthat occur in the formal sum `a`. -/\ndef support (a : free_abelian_group X) : finset X :=\na.to_finsupp.support\n\nlemma mem_support_iff (x : X) (a : free_abelian_group X) :\n  x \u2208 a.support \u2194 coeff x a \u2260 0 :=\nby { rw [support, finsupp.mem_support_iff], exact iff.rfl }\n\nlemma not_mem_support_iff (x : X) (a : free_abelian_group X) :\n  x \u2209 a.support \u2194 coeff x a = 0 :=\nby { rw [support, finsupp.not_mem_support_iff], exact iff.rfl }\n\n@[simp] lemma support_zero : support (0 : free_abelian_group X) = \u2205 :=\nby simp only [support, finsupp.support_zero, add_monoid_hom.map_zero]\n\n@[simp] lemma support_of (x : X) : support (of x) = {x} :=\nby simp only [support, to_finsupp_of, finsupp.support_single_ne_zero (one_ne_zero)]\n\n@[simp] lemma support_neg (a : free_abelian_group X) : support (-a) = support a :=\nby simp only [support, add_monoid_hom.map_neg, finsupp.support_neg]\n\n@[simp] lemma support_zsmul (k : \u2124) (h : k \u2260 0) (a : free_abelian_group X) :\n  support (k \u2022 a) = support a :=\nbegin\n  ext x,\n  simp only [mem_support_iff, add_monoid_hom.map_zsmul],\n  simp only [h, zsmul_int_int, false_or, ne.def, mul_eq_zero]\nend\n\n@[simp] lemma support_nsmul (k : \u2115) (h : k \u2260 0) (a : free_abelian_group X) :\n  support (k \u2022 a) = support a :=\nby { apply support_zsmul k _ a, exact_mod_cast h }\n\nopen_locale classical\n\nlemma support_add (a b : free_abelian_group X) : (support (a + b)) \u2286 a.support \u222a b.support :=\nbegin\n  simp only [support, add_monoid_hom.map_add],\n  apply finsupp.support_add\nend\n\nend free_abelian_group\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/group_theory/free_abelian_group_finsupp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7288125320976873}}
{"text": "-- Implementation of Game of Life.\n\n-- Cell states 'cellT' are represented as constructors 'A' and 'D' for alive / dead state respecitlvely.\n-- The definition 'mk_gol' builds an instance of Life CA\n-- from an initial configuration of cell states.\n\nimport cell_automaton utils data.nat.basic \n\nopen utils\n\nnamespace gol\n \nsection gol\n\nopen list function\n\n-- (A)live / (D)ead\n@[derive decidable_eq]\ninductive cellT | A | D\n\nopen cellT\n\ndef cellT_str : cellT \u2192 string\n  | A := \"X\"\n  | D := \" \"\n\ninstance cellT_to_str : has_to_string cellT := \u27e8cellT_str\u27e9\n\ninstance cellT_repr : has_repr cellT := \u27e8cellT_str\u27e9\n\ninstance : has_coe cellT bool := \u27e8\u03bbx, x = A\u27e9\n\ninstance coe_back : has_coe bool cellT := \u27e8\u03bbx, if x then A else D\u27e9\n\ndef step (cell : cellT) (alive_neighbours : \u2115) : cellT :=\n  if cell then\n    if alive_neighbours < 2 then D else\n    if bor (alive_neighbours = 2) (alive_neighbours = 3) then A\n    else D\n  else\n    if alive_neighbours = 3 then A\n    else D\n\ndef gol_step (cell : cellT) (neigh : list cellT) :=\n  step cell (count_at_single neigh A)\n\nend gol\n\nopen cellT\n\nattribute [reducible]\ndef gol := cell_automaton cellT\n\ndef mk_gol (g : vec_grid\u2080 cellT) : gol :=\n  \u27e8g, D, cell_automatons.moore, gol_step, cell_automatons.ext_one\u27e9\n\ndef empty := fgrid\u2080.mk 2 2 dec_trivial \u27e80, 1\u27e9 (\u03bbx y, D)\n\ndef empty_g :=\n  vec_grid\u2080.mk \u27e82, 2, dec_trivial, \u27e8[D, D, D, D], rfl\u27e9\u27e9 \u27e80, 1\u27e9 \n\ndef empty_aut : gol := mk_gol empty\n\ndef empty_aut_g : gol := mk_gol empty_g\n\ndef row := fgrid\u2080.mk 1 3 dec_trivial \u27e80, 0\u27e9 (\u03bbx y, A)\n\ndef row_gol : gol := mk_gol row\n\ndef col := vec_grid\u2080.mk \u27e83, 1, dec_trivial, \u27e8[A, A, A], rfl\u27e9\u27e9 \u27e81, -1\u27e9\n\ndef col_gol : gol := mk_gol col\n\ndef box := fgrid\u2080.mk 2 2 dec_trivial \u27e80, 1\u27e9 (\u03bbx y, A)\n\ndef box_gol : gol := mk_gol box\n\ndef dies := vec_grid\u2080.mk \u27e83, 2, dec_trivial, \u27e8[A, D, A, D, D, A], rfl\u27e9\u27e9 \u27e80, 1\u27e9\n\ndef dies_gol : gol := mk_gol dies\n\n\nprivate lemma col_even {n} (h : n % 2 = 0) {a} {g} \n  (h\u2082 : a = mk_gol g)\n  (h\u2083 : a = col_gol) : step_n a n = a :=\nbegin\n  unfold step_n,\n  rw @periode_cycle _ _ _ _ 2,\n    {rw [h, iterate_zero]},\n    {rw h\u2082, subst h\u2083, rw \u2190 h\u2082, refl}\nend\n\nlemma col_gol_even {n} (h : n % 2 = 0) : step_n col_gol n = col_gol :=\n  col_even h rfl rfl\n\nprivate lemma col_row {n} (h : n % 2 = 1) {a} {g} \n  (h\u2082 : a = mk_gol g)\n  (h\u2083 : a = col_gol) : step_n a n = row_gol :=\nbegin\n  unfold step_n,\n  rw @periode_cycle _ _ _ _ 2,\n    {\n      rw [\n        h, iterate_one, iterate_zero, h\u2083\n      ]; try { by simp [col_gol, row_gol, mk_gol] },\n      refl\n    },\n    {rw h\u2083, refl}\nend\n\nlemma col_row_odd {n} (h : n % 2 = 1) : step_n col_gol n = row_gol :=\n  col_row h rfl rfl\n\nopen list prod\n\ndef find_period (max : \u2115) (a : gol) : option \u2115 :=\n  let incr_iota := list.reverse $ list.iota max in\n  prod.snd <$> list.find ((=tt) \u2218 prod.fst) (\n    list.zip (list.map ((=a.g) \u2218 cell_automaton.g \u2218 (step_n a)) incr_iota) incr_iota\n  ) \n\nmeta def solve_periodic_gol_n (n : \u2115) : tactic unit :=\n  do {\n    `(periodic %%a) \u2190 tactic.target,\n    t \u2190 tactic.infer_type a,\n    aut \u2190 tactic.eval_expr (cell_automaton _) a,\n    let val := find_period n aut in do\n      v \u2190 val,\n      tactic.existsi `(v),\n      tactic.split,\n      tactic.exact_dec_trivial,\n      tactic.reflexivity\n  } <|> tactic.fail\n        \"Unable to discover periodicity. Try to increase the depth of search.\"\n\nmeta def periodic_aut : tactic unit := solve_periodic_gol_n 16\n\nexample : periodic col_gol := \u27e82, \u27e8dec_trivial, rfl\u27e9\u27e9\n\nexample : periodic col_gol := by periodic_aut\n\nend gol", "meta": {"author": "FerdoSil", "repo": "LatticesAndCellularAutomata", "sha": "2a69d2e74a231addf0e446dca86ef90d50d60218", "save_path": "github-repos/lean/FerdoSil-LatticesAndCellularAutomata", "path": "github-repos/lean/FerdoSil-LatticesAndCellularAutomata/LatticesAndCellularAutomata-2a69d2e74a231addf0e446dca86ef90d50d60218/src/gol.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7288125299673743}}
{"text": "import Mynat.AddAdv\nimport Mynat.Mul\n\nnamespace mynat\n\ntheorem mul_pos (a b : mynat) : a \u2260 0 \u2192 b \u2260 0 \u2192 a * b \u2260 0 := by\n  intro h1\n  intro h2\n  cases a\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [zero_mul]\n    exact h1\n  case succ a' =>\n    cases b\n    case zero =>\n      rw [mynat_zero_eq_zero]\n      rw [mul_zero]\n      exact h2\n    case succ b' =>\n      rw [mul_succ]\n      rw [succ_mul]\n      rw [add_succ]\n      exact succ_ne_zero _\n\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero (a b : mynat) (h : a * b = 0) :\n  a = 0 \u2228 b = 0 := by\n  cases a\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    apply Or.intro_left\n    rfl\n  case succ a' =>\n    cases b\n    case zero =>\n      rw [mynat_zero_eq_zero]\n      apply Or.intro_right\n      rfl\n    case succ b' =>\n      apply False.elim\n      have samtz := succ_ne_zero a'\n      have sbmtz := succ_ne_zero b'\n      have hfalse := (mul_pos (succ a') (succ b')) samtz sbmtz\n      exact hfalse h\n\ntheorem mul_eq_zero_iff (a b : mynat): a * b = 0 \u2194 a = 0 \u2228 b = 0 := by\n  apply Iff.intro\n  . intro H\n    exact eq_zero_or_eq_zero_of_mul_eq_zero a b H\n  . intro h\n    apply Or.elim h\n    . intro hz\n      rw [hz]\n      rw [zero_mul]\n    . intro hz\n      rw [hz]\n      rw [mul_zero]\n\ntheorem mul_left_cancel (a b c : mynat) (ha : a \u2260 0) : a * b = a * c \u2192 b = c := by\n  induction c generalizing b\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [mul_zero]\n    intro h\n    have aorb := (mul_eq_zero_iff a b).mp h\n    cases aorb\n    case inl hh =>\n      apply False.elim\n      exact ha hh\n    case inr hh =>\n      exact hh\n  case succ c' hc =>\n    rw [mul_succ]\n    cases b\n    case zero =>\n      rw [mynat_zero_eq_zero]\n      rw [mul_zero]\n      intro h'\n      have h'' := (calc\n        a * c' + a = 0 := by rw[h']\n      )\n      have haz := add_left_eq_zero h''\n      apply False.elim\n      exact ha haz\n    case succ b' =>\n      rw [mul_succ]\n      intro hhh\n      have bec := (add_right_cancel (a * b') a (a * c')) hhh\n      rw [succ_eq_succ_iff b' c']\n      exact hc b' bec\n\n\nend mynat", "meta": {"author": "plumsirawit", "repo": "mynat", "sha": "0a6529078322c76f7460ef6dafba8367608a5163", "save_path": "github-repos/lean/plumsirawit-mynat", "path": "github-repos/lean/plumsirawit-mynat/mynat-0a6529078322c76f7460ef6dafba8367608a5163/Mynat/MulAdv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7288125237600095}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport combinatorics.simple_graph.basic\nimport data.finset.pairwise\n\n/-!\n# Graph cliques\n\nThis file defines cliques in simple graphs. A clique is a set of vertices that are pairwise\nadjacent.\n\n## Main declarations\n\n* `simple_graph.is_clique`: Predicate for a set of vertices to be a clique.\n* `simple_graph.is_n_clique`: Predicate for a set of vertices to be a `n`-clique.\n* `simple_graph.clique_finset`: Finset of `n`-cliques of a graph.\n* `simple_graph.clique_free`: Predicate for a graph to have no `n`-cliques.\n\n## TODO\n\n* Clique numbers\n* Going back and forth between cliques and complete subgraphs or embeddings of complete graphs.\n* Do we need `clique_set`, a version of `clique_finset` for infinite graphs?\n-/\n\nopen finset fintype\n\nnamespace simple_graph\nvariables {\u03b1 : Type*} (G H : simple_graph \u03b1)\n\n/-! ### Cliques -/\n\nsection clique\nvariables {s t : set \u03b1}\n\n/-- A clique in a graph is a set of vertices that are pairwise adjacent. -/\nabbreviation is_clique (s : set \u03b1) : Prop := s.pairwise G.adj\n\nlemma is_clique_iff : G.is_clique s \u2194 s.pairwise G.adj := iff.rfl\n\ninstance [decidable_eq \u03b1] [decidable_rel G.adj] {s : finset \u03b1} : decidable (G.is_clique s) :=\ndecidable_of_iff' _ G.is_clique_iff\n\nvariables {G H}\n\nlemma is_clique.mono (h : G \u2264 H) : G.is_clique s \u2192 H.is_clique s :=\nby { simp_rw is_clique_iff, exact set.pairwise.mono' h }\n\nlemma is_clique.subset (h : t \u2286 s) : G.is_clique s \u2192 G.is_clique t :=\nby { simp_rw is_clique_iff, exact set.pairwise.mono h }\n\n@[simp] lemma is_clique_bot_iff : (\u22a5 : simple_graph \u03b1).is_clique s \u2194 (s : set \u03b1).subsingleton :=\nset.pairwise_bot_iff\n\nalias is_clique_bot_iff \u2194 is_clique.subsingleton _\n\nend clique\n\n/-! ### `n`-cliques -/\n\nsection n_clique\nvariables {n : \u2115} {s : finset \u03b1}\n\n/-- A `n`-clique in a graph is a set of `n` vertices which are pairwise connected. -/\nstructure is_n_clique (n : \u2115) (s : finset \u03b1) : Prop :=\n(clique : G.is_clique s)\n(card_eq : s.card = n)\n\nlemma is_n_clique_iff : G.is_n_clique n s \u2194 G.is_clique s \u2227 s.card = n :=\n\u27e8\u03bb h, \u27e8h.1, h.2\u27e9, \u03bb h, \u27e8h.1, h.2\u27e9\u27e9\n\ninstance [decidable_eq \u03b1] [decidable_rel G.adj] {n : \u2115} {s : finset \u03b1} :\n  decidable (G.is_n_clique n s) :=\ndecidable_of_iff' _ G.is_n_clique_iff\n\nvariables {G H}\n\nlemma is_n_clique.mono (h : G \u2264 H) : G.is_n_clique n s \u2192 H.is_n_clique n s :=\nby { simp_rw is_n_clique_iff, exact and.imp_left (is_clique.mono h) }\n\n@[simp] lemma is_n_clique_bot_iff : (\u22a5 : simple_graph \u03b1).is_n_clique n s \u2194 n \u2264 1 \u2227 s.card = n :=\nbegin\n  rw [is_n_clique_iff, is_clique_bot_iff],\n  refine and_congr_left _,\n  rintro rfl,\n  exact card_le_one.symm,\nend\n\nvariables [decidable_eq \u03b1] {a b c : \u03b1}\n\nlemma is_3_clique_triple_iff : G.is_n_clique 3 {a, b, c} \u2194 G.adj a b \u2227 G.adj a c \u2227 G.adj b c :=\nbegin\n  simp only [is_n_clique_iff, is_clique_iff, set.pairwise_insert_of_symmetric G.symm, coe_insert],\n  have : \u00ac 1 + 1 = 3 := by norm_num,\n  by_cases hab : a = b; by_cases hbc : b = c; by_cases hac : a = c;\n  subst_vars; simp [G.ne_of_adj, and_rotate, *],\nend\n\nlemma is_3_clique_iff :\n  G.is_n_clique 3 s \u2194 \u2203 a b c, G.adj a b \u2227 G.adj a c \u2227 G.adj b c \u2227 s = {a, b, c} :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { obtain \u27e8a, b, c, -, -, -, rfl\u27e9 := card_eq_three.1 h.card_eq,\n    refine \u27e8a, b, c, _\u27e9,\n    rw is_3_clique_triple_iff at h,\n    tauto },\n  { rintro \u27e8a, b, c, hab, hbc, hca, rfl\u27e9,\n    exact is_3_clique_triple_iff.2 \u27e8hab, hbc, hca\u27e9 }\nend\n\nend n_clique\n\n/-! ### Graphs without cliques -/\n\nsection clique_free\nvariables {m n : \u2115}\n\n/-- `G.clique_free n` means that `G` has no `n`-cliques. -/\ndef clique_free (n : \u2115) : Prop := \u2200 t, \u00ac G.is_n_clique n t\n\nvariables {G H}\n\nlemma clique_free_bot (h : 2 \u2264 n) : (\u22a5 : simple_graph \u03b1).clique_free n :=\nbegin\n  rintro t ht,\n  rw is_n_clique_bot_iff at ht,\n  linarith,\nend\n\nlemma clique_free.mono (h : m \u2264 n) : G.clique_free m \u2192 G.clique_free n :=\nbegin\n  rintro hG s hs,\n  obtain \u27e8t, hts, ht\u27e9 := s.exists_smaller_set _ (h.trans hs.card_eq.ge),\n  exact hG _ \u27e8hs.clique.subset hts, ht\u27e9,\nend\n\nlemma clique_free.anti (h : G \u2264 H) : H.clique_free n \u2192 G.clique_free n :=\nforall_imp $ \u03bb s, mt $ is_n_clique.mono h\n\nend clique_free\n\n/-! ### Set of cliques -/\n\nsection clique_set\nvariables (G) {n : \u2115} {a b c : \u03b1} {s : finset \u03b1}\n\n/-- The `n`-cliques in a graph as a set. -/\ndef clique_set (n : \u2115) : set (finset \u03b1) := {s | G.is_n_clique n s}\n\nlemma mem_clique_set_iff : s \u2208 G.clique_set n \u2194 G.is_n_clique n s := iff.rfl\n\n@[simp] lemma clique_set_eq_empty_iff : G.clique_set n = \u2205 \u2194 G.clique_free n :=\nby simp_rw [clique_free, set.eq_empty_iff_forall_not_mem, mem_clique_set_iff]\n\nalias clique_set_eq_empty_iff \u2194 _ clique_free.clique_set\n\nattribute [protected] clique_free.clique_set\n\nvariables {G H}\n\n@[mono] lemma clique_set_mono (h : G \u2264 H) : G.clique_set n \u2286 H.clique_set n :=\n\u03bb _, is_n_clique.mono h\n\nlemma clique_set_mono' (h : G \u2264 H) : G.clique_set \u2264 H.clique_set := \u03bb _, clique_set_mono h\n\nend clique_set\n\n/-! ### Finset of cliques -/\n\nsection clique_finset\nvariables (G) [fintype \u03b1] [decidable_eq \u03b1] [decidable_rel G.adj] {n : \u2115} {a b c : \u03b1} {s : finset \u03b1}\n\n/-- The `n`-cliques in a graph as a finset. -/\ndef clique_finset (n : \u2115) : finset (finset \u03b1) := univ.filter $ G.is_n_clique n\n\nlemma mem_clique_finset_iff : s \u2208 G.clique_finset n \u2194 G.is_n_clique n s :=\nmem_filter.trans $ and_iff_right $ mem_univ _\n\n@[simp] lemma coe_clique_finset (n : \u2115) : (G.clique_finset n : set (finset \u03b1)) = G.clique_set n :=\nset.ext $ \u03bb _, mem_clique_finset_iff _\n\n@[simp] lemma clique_finset_eq_empty_iff : G.clique_finset n = \u2205 \u2194 G.clique_free n :=\nby simp_rw [clique_free, eq_empty_iff_forall_not_mem, mem_clique_finset_iff]\n\nalias clique_finset_eq_empty_iff \u2194 _ _root_.simple_graph.clique_free.clique_finset\n\nattribute [protected] clique_free.clique_finset\n\nvariables {G} [decidable_rel H.adj]\n\n@[mono] lemma clique_finset_mono (h : G \u2264 H) : G.clique_finset n \u2286 H.clique_finset n :=\nmonotone_filter_right _ $ \u03bb _, is_n_clique.mono h\n\nend clique_finset\nend simple_graph\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/combinatorics/simple_graph/clique.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.72881251945349}}
{"text": "-- CS2102 F19 Exam #1 \n--Derek Johnson dej3tc\n--10/10/19\n/-\n#1 [10 points]\n\nComplete the following definitions to give examples of \nliteral values of specified types. Use lambda expressions \nto complete the questions involving function types. Make\nfunctions (lambda expressions) simple: we don't care what \nthe functions do, just that they are of the right types.\n-/\nopen nat\ndef x := \u03bb (n:\u2115), n\ndef n : \u2115 := 1\ndef s : string := \"CS\"\ndef b : bool := tt\ndef f1 : \u2115 \u2192 bool := \u03bb (n: \u2115), tt \ndef f2 : (\u2115 \u2192 \u2115) \u2192 bool := \u03bb x,tt\ndef f3 : (\u2115 \u2192 \u2115) \u2192 (\u2115 \u2192 \u2115) := \u03bb x,x\ndef t1 : Type := nat\ndef t2 : Type \u2192 Type := \u03bb (\u03b1 : Type), \u03b1\n\n/-\n#2 [10 points]\n\nComplete the following recursive function definition\nso that the function computes the sum of the natural\nnumbers from 0 to (and including) a given value, n.\n-/\n\ndef sumto : \u2115 \u2192 \u2115\n| 0 := 0\n| (nat.succ n') := nat.succ n' + sumto(n')\n/-\n#3. [5 points]\n\nWe have seen that we can write function *specifications*\nin the language of predicate logic, and specifically in \nthe language of pure functional programming. We also know\nwe can, and generally do, write *implementations* in the \nlanguage of imperative programming (e.g., in Python or in\nJava). Complete the following sentence by filling in the \nblanks to explain the esssential tradeoff between function \nspecifications, in the langugae of predicate logic, and \nfunction implementations written in imperative programming\nlanguages, respectively.\n\nSpecifications are generally understandable but less efficient \nwhile implementations are generally the opposite: less\nunderstandable but more efficient.\n\n-/\n\n\n/-\n# 4. [10 points]\n\nNatural languages, such as English and Mandarin, are very\npowerful, but they have some fundamental weaknesses when it\ncomes to writing and verifying precise specifications and\nclaims about properties of algorithms and programs. It is \nfor this reason that computer scientists often prefer to \nwrite express such things using mathematical logic instead\nof natural language.\n\nName three fundamental weaknesses of natural language when \nit comes to carrying out such tasks. You may given one-word\nanswers if you wish.\n\nA. Ambiguous \nB. Not Machine Checkable\nC. Too Verbose (in some situations)\n\n-/\n\n\n/-\n#5. [10 points]\n\nWhat logical proposition expresses the claim that a given\nimplementation, I, of a function of type \u2115 \u2192 \u2115, is correct \nwith respect to a specification, S, of the same function?\n\nAnswer: For all natural numbers, implementation I will \nhold to / be true for specification S.\n-/\n\n/-\n#6. [10 points]\n\nWhat Boolean functions do the following definitions define?\n-/\n\ndef mystery1 : bool \u2192 bool \u2192 bool\n| tt tt := ff\n| ff ff := ff\n| _ _ := tt\n\n/-\nAnswer: Not Equal To\n-/\n\ndef mystery2 : bool \u2192 bool \u2192 bool\n| tt ff := ff\n| _ _ := tt\n\n/-\nAnswer: Not (a, not b)\n-/\n\n/-\n#7. [10 points]\n\nDefine a function that takes a string, s, and a natural \nnumber, n, and that returns value of type (list string)\nin which s is repeated n times. Give you answer by\ncompleting the following definition: fill in underscores\nwith the answers that are needed. Note that the list\nnamespace is not open by default, so prefix constructor\nnames with \"list.\" as we do for the first (base) case.\n-/\n\ndef repeat : string \u2192 \u2115 \u2192 list string\n| s nat.zero := list.nil\n| s (nat.succ n') := list.cons s (repeat s n')\n\n#eval repeat \"hello\" 3\n/-\n#8. [10 points]\n\nDefinea a polymorphic function that takes (1) a type, \u03b1, \n(2) a value, s : \u03b1, and (3) a natural number, n, and that \nreturns a list in which the value, a, is repeated n times. \nMake the type argument to this function implicit. Replace\nunderscores as necessary to give a complete answer. Note\nagain that the list namespace is not open, so use \"fully\nqualified\" constructor names.\n-/\n\ndef poly_repeat {\u03b1 : Type} : \u03b1 \u2192 \u2115 \u2192 list \u03b1 \n| s nat.zero := list.nil \n| s (nat.succ n') := list.cons s (poly_repeat s n')\n\n#eval poly_repeat \"hello\" 3\n/-\n#9. [10 points]\n\nDefine a data type, an enumerated type, friend_or_foe,\nwith just two terms, one called friend, one called foe.\nThen define a function called eval that takes two terms,\nF1 and F2, of this type and returns a term of this type, \nwhere the function implements the following table:\n\nF1      F2      result\nfriend  friend  friend \nfriend  foe     foe\nfoe     friend  foe\nfoe     foe     friend\n-/\n\n-- Answer here\ninductive friend_or_foe : Type  \n | friend : friend_or_foe\n | foe : friend_or_foe\n\nopen friend_or_foe\ndef eval : friend_or_foe \u2192 friend_or_foe \u2192 friend_or_foe\n| friend friend := friend\n| friend foe := foe\n| foe friend := foe\n| foe foe := friend\n\n/-\n#10. [10 points]\n\nWe studied the higher-order function, map. In particular,\nwe implemented a version of it, which we called mmap, for\nfunctions of type \u2115 \u2192 \u2115, and for lists of type (list \u2115). \nThe function is reproduced next for your reference. Read\nand recall how the function works, then continue on to the\nquestions that follow.\n-/\n\ndef mmap : (\u2115 \u2192 \u2115) \u2192 list \u2115 \u2192 list \u2115 \n| f [] := []\n| f (list.cons h t) := list.cons (f h) (mmap f t)\n\n-- An example application of this function\n#eval mmap (\u03bb n, n + 1) [1, 2, 3, 4, 5]\n\n/-\nA. Write a polymorphic version of this function, called\npmap, that takes (1) two type arguments, \u03b1 and \u03b2, (2) a \nfunction of type \u03b1 \u2192 \u03b2, and (3) a list of values of type\n\u03b1, and that returns the list of values obtained by \napplying the given function to each value in the given\nlist. Make \u03b1 and \u03b2 implicit arguments.\n-/\n\n-- Answer here\ndef pmap {\u03b1 \u03b2 : Type} : (\u03b1 \u2192 \u03b2) \u2192 list \u03b1 \u2192 list \u03b2\n| f [] := []\n| f (list.cons h t) := list.cons (f h) (pmap f t)\n\n/-\nB. \n\nUse #eval to evaluate an application of pmap to a function\nof type \u2115 to bool and a non-empty list of natural numbers. \nUse a lambda abstraction to give the function argument. It\ndoes not matter to us what value the function returns. \n-/\n\n-- Answer here\ndef tttt:= \u03bb (n:\u2115), tt\n\ndef list1 := [1,2,3,4,5]\n\n#eval pmap (\u03bb (n:\u2115), tt) [1,2,3,4,5]\n\n/-\n#11. [10 points]\n\nDefine a data type, prod3_nat, with one constructor, \ntriple, that takes three natural numbers as arguments,\nyielding a term of type prod3_nat. Then write three\n\"projection functions\", prod3_nat_fst, prod3_nat_snd, \nand prod3_nat_thd, each of which takes a prod3_nat value \nand returns its corresponding component element. Hint: \nlook to see how we defined the prod type, its pair\nconstructor, and its two projection functions.\n-/\ninductive prod3_nat : Type\n| triple (a :\u2115 ) (b:\u2115 ) (c : \u2115 ) : prod3_nat \n\ndef prod3_nat_fst : prod3_nat \u2192 \u2115 \n| (prod3_nat.triple a b c) := a\n\ndef prod3_nat_snd : prod3_nat \u2192 \u2115 \n| (prod3_nat.triple a b c) := b\n\ndef prod3_nat_thd : prod3_nat \u2192 \u2115 \n| (prod3_nat.triple a b c) := c\n\ndef ss := prod3_nat.triple 2 3 4\n#eval prod3_nat_fst ss\n\n/- \nExtra credit. Define prod3 as a version\nof prod3_nat that is polymorphic in each of\nits three components; define polymorphic\nprojection functions; and then use them to\ndefine a function, rotate_right, that takes\na triple, (a, b, c), and returns the triple\n(c, a, b).  (Call your type arguments \u03b1, \n\u03b2, and \u03b3 - alpha, beta, and gamma). \n-/\n\ninductive prod3 (\u03b1 \u03b2 \u03b3 : Type) : Type\n| triple (a : \u03b1) (b : \u03b2) (y : \u03b3) : prod3\n\ndef prod3_fst {\u03b1 \u03b2 \u03b3 : Type}: prod3 \u03b1 \u03b2 \u03b3 \u2192 \u03b1\n| (prod3.triple a b c) := a\n\ndef prod3_snd {\u03b1 \u03b2 \u03b3 : Type} : prod3 \u03b1 \u03b2 \u03b3 \u2192 \u03b2\n| (prod3.triple a b c) := b\n\ndef prod3_thd {\u03b1 \u03b2 \u03b3 : Type} : prod3 \u03b1 \u03b2 \u03b3 \u2192 \u03b3\n| (prod3.triple a b c) := c\n\ndef rotate_right {\u03b1 \u03b2 \u03b3 : Type} : prod3 \u03b1 \u03b2 \u03b3 \u2192 prod3 \u03b3 \u03b1 \u03b2\n| (prod3.triple a b c) := prod3.triple c a b\n\n", "meta": {"author": "derekjohnsonva", "repo": "CS2102", "sha": "b3f507d4be824a2511838a1054d04fc9aef3304c", "save_path": "github-repos/lean/derekjohnsonva-CS2102", "path": "github-repos/lean/derekjohnsonva-CS2102/CS2102-b3f507d4be824a2511838a1054d04fc9aef3304c/Exams/exam_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7288117307086722}}
{"text": "/-\nThe goal of this demo is to serve as an extended example to show the process of working with\nand extending mathematical structures in Lean. A lot of this file is taken from Floris van Doorn's \ndemo in LFTCM2020.\n\nWe first import a few modules we want from later to connect with later in the document.\n-/\nimport algebra.group.defs\nimport category_theory.category.basic\n\n\n/-\nThis is a long file, so we'll want to section off parts of the document to keep the local variables,\nnotation, and more isolated.\n-/\nsection basic_definitions\n\n/-\nStructures are defined in the following format: \n\n\nstructure structure_name :=\n(field1 : ...)\n(field2 : ...)\n...\n(fieldn : ...)\n\n\nThis is very similar to the inductive datatypes that we've seen before. For this demo we'll be\nfocusing on a simple structure called a _Pointed type_. The structure is simply some type, together\nwith a particular instance of said type. We can think of them as pairs of a type `T` and some \n`p : T`. \n-/\nstructure pointed_type :=\n(type : Type*)\n(point : type)\n\n/-\nLean now recognizes this as a new type. We could have provided the type ascription to \n`pointed_type : Type (u + 1)`, but Lean does it for us.\n-/\n#check pointed_type\n\n/-\nLean now recognizes this type as something we can refer to, and construct new types out of.\n-/\n#check \u2115 \u2192 pointed_type \n#check \u2115 \u00d7 pointed_type\n#check list pointed_type\n\n\n/-\nWe can even provide instances of this structure. For example the natural numbers `\u2115` could be \nconsidered a pointed type by considering the pair `(\u2115, 0)`. The method to do this is to use\n`name.mk`:\n-/\ndef pointed_nat : pointed_type := pointed_type.mk \u2115 0\ndef pointed_int : pointed_type := pointed_type.mk \u2124 0\n\n-- You can also use an \"anonymous constructor\" by using angle brackets `\\< \\>`.\ndef pointed_nat_with_1 : pointed_type := \u27e8\u2115, 1\u27e9\n\n-- We can `#check` to see if Lean recognizes them.\n#check pointed_nat\n\n/-\nWe can even ask Lean to `#reduce` them. This is similar to evaluation, but essentially asks Lean to \nrewrite the expression in simplest terms.\n-/\n#reduce pointed_nat\n\n/-\nIn fact, using the `structure` keyword means that Lean has generated a ton of useful functions \nassociated with our new type. \n-/\n#print prefix pointed_type\n\n/-\nSome highlights are: \n* `pointed_type.mk : \u03a0 (carrier : Type u), carrier \u2192 pointed_type`\nThis is the `make` function. We saw above, the `\u03a0` symbol can basically be thought of as a `\u03bb`, so\nthe above type takes in a `carrier`, a `point` of the carrier, and returns a `pointed_type`. This is\nexactly how we've been using it\n\n* It also automatically provides `pointed_type.carrier` and `pointed_type.point` to\nextract the components of \n-/\n\nopen pointed_type\n\n#check type\n#check point\n\n#reduce type pointed_nat \n#reduce type pointed_int\n\n/-\nLean also lets you use the usual `.` notation you may be familiar with in OOP. Because \n`pointed_nat_with_1` is a `pointed_type`, then we can call `pointed_type.point` by just typing:\n-/\n#reduce pointed_nat_with_1.point\n\n/-\n* Another useful function that is constructed when dealing with a structure is `pointed_type.rec`, \n`pointed_type.rec_on`, `pointed_type.cases_on` (a synonym). The exact type signature is not super\nimportant, but the key takeaway is that it allows us to define things on `pointed_types` by \n-/\n#print prefix pointed_type\n\n#print pointed_type.rec\n#check pointed_type.cases_on  \n\n/-\nLets do a few more constructions of pointed types. In fact, any non-empty type is a pointed type\nif we just choose some instance!\n-/\nnoncomputable def from_nonempty {X : Type} (h : nonempty X) : pointed_type := { type := X,\n  point := classical.choice h }\n\n#check classical.choice\n-- We see here we need to make this a noncomputable definition, becuase we're using choice.\n\n/-\nActually this gives us an idea that maybe we could show that any pointed type is nonempty! Though \nwhen we look at the type of nonempty we see that it's expecting something in the usual `Sort` \nhierarchy. \n\nWe can get around this by offering a **coercion** from . This is just like the coercion we have to\nspecficy when we want to consider `3` as an integer: `(3 : \u2124)`\n-/\ninstance : has_coe_to_sort pointed_type (Type*) := \u27e8pointed_type.type\u27e9\n\n#check pointed_nat\n#check (pointed_nat : Type)\n\n\n/- \nNow we can prove the lemma that `pointed_type`s are nonempty by providing a witness!\n-/\nnamespace pointed_type\n\nlemma nonempty (X : pointed_type) : nonempty X := nonempty.intro X.point\n\n/-\nFinally, a large class of pointed types can be generated in the following way:\n-/\ndef from_has_one (X : Type) [has_one X] : pointed_type := \u27e8X, 1\u27e9\n\n#reduce from_has_one \u2124\n\nvariables (G : Type) [group G] \n\n#reduce from_has_one G\n\n/-\nWe can even define the product of pointed types.\n-/\n@[simps point]\ndef prod (A B : pointed_type) : pointed_type :=\n{ type := A \u00d7 B,\n  point := (A.point, B.point) }\n\n/-\nFinally, a small command that I learned which is nice to remind yourself of what variables are in \nscope\n-/\n#where\n\nend pointed_type\nend basic_definitions\n\nsection pointed_maps\n\n/-\nUnfortunately pointed types are not super interesting to reason about, but one thing we can do is \ndefine maps between them! Intuitively, a good notion of a map between pointed types is one which\nrespects the point. This can also be encoded as a structure!\n-/\nstructure pointed_map (A B : pointed_type) :=\n(to_fun : A \u2192 B) -- The actual function\n(to_fun_point : to_fun A.point = B.point) -- The property that the function respects the points\n\n-- Just a quick example of how we can reason about this!\ndef pointed_coe' : pointed_map pointed_nat pointed_int := sorry\n\n/-\nActually on second though, this is all getting a little annoying to write out all the time! Lets \ngive ourselves some nice notation to work with\n-/\n\nnotation `\u2115\u2b1d` := pointed_nat\nnotation `\u2124\u2b1d` := pointed_int\ninfix ` \u2192\u2b1d `:25 := pointed_map\n\n#check \u2124\n\n#check \u2115.\n\n-- Now the definition looks a lot nicer!\ndef pointed_coe : \u2115\u2b1d \u2192\u2b1d \u2124\u2b1d := { to_fun := int.of_nat,\n  to_fun_point := \n  begin\n    -- Sometimes when it's not entirely clear what we're trying to prove, `dunfold` and `unfold` \n    -- can be your friend! (though it also feels sometimes that definitions aren't unfolding when\n    -- they should.)\n    sorry\n  end }\n\n\nnamespace pointed_map\nvariables {A B C D : pointed_type}\nvariables {g : B \u2192\u2b1d C} {f f\u2081 f\u2082 : A \u2192\u2b1d B} {h : C \u2192\u2b1d D}\nvariable (a : A)\n\n/-\nYou would hope something like this would work\n-/\n-- #check f a\n/-\nBut Lean rightfully complains that `f` is a `pointed_map` and not a function! In order to \"apply\" it \nto anything, we need to remember that one of its fields is `to_fun`\n-/\n#check f.to_fun a\n\n/-\nBut this is annoying, so we can do better and coerce it into a function type using `has_coe_to_fun`!\n-/\ninstance : has_coe_to_fun (A \u2192\u2b1d B) (\u03bb (h : A \u2192\u2b1d B ), A \u2192 B) := \u27e8pointed_map.to_fun\u27e9\n\n-- And now it works\n#check f a\n\n/-\nIt's usually a good idea to provide a couple `simp` lemmas to help Lean unfold definitions along\nthe way\n-/\n@[simp] lemma coe_mk {f : A \u2192 B} {hf : f A.point = B.point} {x : A} :\n  { pointed_map . to_fun := f, to_fun_point := hf } x = f x := by refl\n\n@[simp] lemma coe_point : f A.point = B.point := f.to_fun_point\n\n/-\nAnd also prove an extensionality lemma that when two pointed maps are the same:\n-/\n@[ext] protected lemma ext (hf\u2081\u2082 : \u2200 x, f\u2081 x = f\u2082 x) : f\u2081 = f\u2082 :=\nbegin\n  -- It probably pays for the first step to be splitting up `f\u2081` and `f\u2082` into their constituent\n  -- parts with `cases f\u2081`\n  sorry\nend\n\n/-\nWe can now start prove basic things about pointed maps\n-/\ndef comp (g : B \u2192\u2b1d C) (f : A \u2192\u2b1d B) : A \u2192\u2b1d C :=\nsorry\n\ndef id : A \u2192\u2b1d A :=\nsorry\n\nlemma comp_assoc : h.comp (g.comp f) = (h.comp g).comp f :=\nsorry\n\nlemma id_comp : f.comp id = f :=\nsorry\n\nlemma comp_id : id.comp f = f :=\nsorry\n\n/-\nWe can define a few maps into and out of products of pointed types, and then prove properties about\nthem as well!\n-/\ndef fst : A.prod B \u2192\u2b1d A :=\nsorry\n\ndef snd : A.prod B \u2192\u2b1d B :=\nsorry\n\ndef pair (f : C \u2192\u2b1d A) (g : C \u2192\u2b1d B) : C \u2192\u2b1d A.prod B :=\nsorry\n\nlemma fst_pair (f : C \u2192\u2b1d A) (g : C \u2192\u2b1d B) : fst.comp (f.pair g) = f :=\nsorry\n\nlemma snd_pair (f : C \u2192\u2b1d A) (g : C \u2192\u2b1d B) : snd.comp (f.pair g) = g :=\nsorry\n\nlemma pair_unique (f : C \u2192\u2b1d A) (g : C \u2192\u2b1d B) (u : C\u2192\u2b1d A.prod B) (h1u : fst.comp u = f)\n  (h2u : snd.comp u = g) : u = f.pair g :=\nbegin\n  sorry\nend\n\nend pointed_map\nend pointed_maps", "meta": {"author": "mpenciak", "repo": "Lean-Seminar-Sp2022", "sha": "49437bb35643bf43e90afddb2e7702a749a725e4", "save_path": "github-repos/lean/mpenciak-Lean-Seminar-Sp2022", "path": "github-repos/lean/mpenciak-Lean-Seminar-Sp2022/Lean-Seminar-Sp2022-49437bb35643bf43e90afddb2e7702a749a725e4/src/week5/demo5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7288117277012431}}
{"text": "import data.real.basic --hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 8\n-/\n\n\n/- \nThis is a very basic example of working with intervals of real numbers in Lean.\nAn interval that is closed at both endpoints $a$ and $b$ can be \nconstructed using `set.Icc a b`. For an open-closed interval, the notation\nis `set.Ioc a b`, etc. The usual closed-interval notation, using square\nbrackets, is used here as a wrapper around these definitions.\nAfter `intro hx,` the `split` tactic will showcase the conditions for \nmembership. The inequality goals can be met with the `linarith` tactic.\nThe latter is very useful when dealing with goals that don't involve any\nnonlinearity in the involved variables, in particular with inequalities.\n-/\n\nnotation `[` a `,` b `]`  := set.Icc a b\n\n/- Lemma\nIf $x = 2$ then $x \u2208 [0,5]$\n-/\nlemma in_closed_interval (x:\u211d) : x = 2 \u2192 x \u2208 [(0:\u211d), 5] := \nbegin\n    intro hx,\n    split, linarith, linarith, done\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/kb_solns/sets_level08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7288071568088855}}
{"text": "import data.vect.basic\nimport tactic.csimp\n\nuniverse u\n\n--- Check whether a given vector is monotonic with respect to a given binary relation.\ndefinition is_monotonic {\u03b1 : Type*} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : \u2200 {n : \u2115}, vect \u03b1 n \u2192 Prop\n| _ vect.nil := true\n| _ (vect.cons _ vect.nil) := true\n| _ (vect.cons x (vect.cons y ys)) := r x y \u2227 is_monotonic (vect.cons y ys)\n\ninductive based_chain {\u03b1 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : \u03b1 \u2192 \u2115 \u2192 Type u\n| base (x : \u03b1) : based_chain x 1\n| cons {n : \u2115} (x : \u03b1) {y : \u03b1} (_ : r x y) (xs : based_chain y n) : based_chain x (n+1)\n\nnamespace based_chain\n\ndefinition to_vect {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} : \u03a0 {x : \u03b1} {n : \u2115}, based_chain r x n \u2192 vect \u03b1 n\n| x _ (base _) := vect.cons x vect.nil\n| x _ (cons _ h xs) := vect.cons x (to_vect xs)\n\nlemma to_vect_is_monotonic {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} : \u03a0 {x : \u03b1} {n : \u2115} (ch : based_chain r x n), is_monotonic r ch.to_vect\n| _ _ (base x) := by csimp [to_vect,is_monotonic]\n| _ _ (cons x h (base y)) := by csimp [to_vect,is_monotonic]; exact \u27e8h,true.intro\u27e9\n| _ _ (cons x hxy (cons y h ch)) :=\n  begin\n    have h_ind : is_monotonic r (cons y h ch).to_vect,\n      from to_vect_is_monotonic (cons y h ch),\n    csimp [to_vect,is_monotonic] at *,\n    split,\n    show r x y, from hxy,\n    show is_monotonic r (vect.cons y ch.to_vect), from h_ind\n  end\n\ndefinition from_vect {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} : \u03a0 {n : \u2115} (xs : vect \u03b1 (n+1)) (hmono : is_monotonic r xs), based_chain r xs.head (n+1)\n| _ (vect.cons x vect.nil) hmono := based_chain.base x\n| n (vect.cons x (vect.cons y ys)) hmono :=\n  let tail := from_vect (vect.cons y ys) hmono.right\n  in cons x hmono.left tail\n\ndefinition from_vect' {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {n : \u2115} (xs : vect \u03b1 (n+1)) (hmono : is_monotonic r xs) : \u03a3 x, based_chain r x (n+1) :=\n  \u27e8xs.head, from_vect xs hmono\u27e9\n\nlemma tail_heq {\u03b1 : Type _} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} (x : \u03b1) {n : \u2115} : \u03a0 {y\u2081 y\u2082 : \u03b1} (hxy\u2081 : r x y\u2081) (hxy\u2082 : r x y\u2082) {ys\u2081 : based_chain r y\u2081 n} {ys\u2082 : based_chain r y\u2082 n}, (y\u2081 = y\u2082) \u2192 ys\u2081 == ys\u2082 \u2192 cons x hxy\u2081 ys\u2081 = cons x hxy\u2082 ys\u2082 :=\n  begin\n    intros _ _ _ _ _ _ hy hys,\n    cases hy, cases hy,\n    have : ys\u2081 = ys\u2082 := eq_of_heq hys,\n    rw [this]\n  end\n\nlemma to_vect_of_from {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} : \u03a0 {n : \u2115} (xs : vect \u03b1 (n+1)) (hmono : is_monotonic r xs), (from_vect xs hmono).to_vect = xs\n| _ (vect.cons x vect.nil) hmono := by dsimp [from_vect,to_vect,vect.head]; refl\n| _ (vect.cons x (vect.cons y ys)) hmono :=\n  begin\n    dsimp only [from_vect,to_vect],\n    unfold vect.head,\n    let h_ind := to_vect_of_from (vect.cons y ys) hmono.right,\n    rw [h_ind]\n  end\n\nattribute [simp,reducible]\nlemma head_of_to_vect {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} : \u03a0 {x : \u03b1} {n : \u2115} (ch : based_chain r x (n+1)), ch.to_vect.head = x\n| _ _ (base x) := rfl\n| _ _ (cons x h ys) := rfl\n\nlemma from_vect_of_to {\u03b1 : Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} : \u03a0 {x : \u03b1} {n : \u2115} (ch : based_chain r x (n+1)), (from_vect' ch.to_vect (to_vect_is_monotonic ch)) = \u27e8x,ch\u27e9\n| _ _ (base x) := rfl\n| _ _ (cons x h (base y)) := rfl\n| _ _ (cons x hxy (cons y h ys)) :=\n  begin\n    let h_ind := from_vect_of_to (cons y h ys),\n    unfold to_vect at *,\n    unfold from_vect' at *,\n    apply sigma.eq; try {unfold sigma.fst at *}; try {unfold sigma.snd at *},\n    dsimp [from_vect],\n    refine tail_heq x _ hxy _ _; try {refl},\n    exact (sigma.mk.inj h_ind).right\n  end\n\nend based_chain\n", "meta": {"author": "Junology", "repo": "groth-lean", "sha": "5aa1ba624cd0f5145f63fa86130f99b85bbbcac2", "save_path": "github-repos/lean/Junology-groth-lean", "path": "github-repos/lean/Junology-groth-lean/groth-lean-5aa1ba624cd0f5145f63fa86130f99b85bbbcac2/src/data/vect/chain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7287588704070358}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.inverse\n\n/-!\n# The argument of a complex number.\n\nWe define `arg : \u2102 \u2192 \u211d`, returing a real number in the range (-\u03c0, \u03c0],\nsuch that for `x \u2260 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,\nwhile `arg 0` defaults to `0`\n-/\n\nnoncomputable theory\n\nnamespace complex\n\nopen_locale real topological_space\nopen filter set\n\n/-- `arg` returns values in the range (-\u03c0, \u03c0], such that for `x \u2260 0`,\n  `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,\n  `arg 0` defaults to `0` -/\nnoncomputable def arg (x : \u2102) : \u211d :=\nif 0 \u2264 x.re\nthen real.arcsin (x.im / x.abs)\nelse if 0 \u2264 x.im\nthen real.arcsin ((-x).im / x.abs) + \u03c0\nelse real.arcsin ((-x).im / x.abs) - \u03c0\n\nlemma sin_arg (x : \u2102) : real.sin (arg x) = x.im / x.abs :=\nby unfold arg; split_ifs;\n  simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1\n    (abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg,\n    real.sin_neg]\n\nlemma cos_arg {x : \u2102} (hx : x \u2260 0) : real.cos (arg x) = x.re / x.abs :=\nbegin\n  have habs : 0 < abs x := abs_pos.2 hx,\n  have him : |im x / abs x| \u2264 1,\n  { rw [_root_.abs_div, abs_abs], exact div_le_one_of_le x.abs_im_le_abs x.abs_nonneg },\n  rw abs_le at him,\n  rw arg, split_ifs with h\u2081 h\u2082 h\u2082,\n  { rw [real.cos_arcsin]; field_simp [real.sqrt_sq, habs.le, *] },\n  { rw [real.cos_add_pi, real.cos_arcsin],\n    { field_simp [real.sqrt_div (sq_nonneg _), real.sqrt_sq_eq_abs,\n        _root_.abs_of_neg (not_le.1 h\u2081), *] },\n    { simpa [neg_div] using him.2 },\n    { simpa [neg_div, neg_le] using him.1 } },\n  { rw [real.cos_sub_pi, real.cos_arcsin],\n    { field_simp [real.sqrt_div (sq_nonneg _), real.sqrt_sq_eq_abs,\n        _root_.abs_of_neg (not_le.1 h\u2081), *] },\n    { simpa [neg_div] using him.2 },\n    { simpa [neg_div, neg_le] using him.1 } }\nend\n\n@[simp] lemma abs_mul_exp_arg_mul_I (x : \u2102) : \u2191(abs x) * exp (arg x * I) = x :=\nbegin\n  rcases eq_or_ne x 0 with (rfl|hx),\n  { simp },\n  { have : abs x \u2260 0 := abs_ne_zero.2 hx,\n    ext; field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)] }\nend\n\n@[simp] lemma abs_mul_cos_add_sin_mul_I (x : \u2102) :\n  (abs x * (cos (arg x) + sin (arg x) * I) : \u2102) = x :=\nby rw [\u2190 exp_mul_I, abs_mul_exp_arg_mul_I]\n\nlemma arg_mul_cos_add_sin_mul_I {r : \u211d} (hr : 0 < r) {\u03b8 : \u211d} (h\u03b8 : \u03b8 \u2208 Ioc (-\u03c0) \u03c0) :\n  arg (r * (cos \u03b8 + sin \u03b8 * I)) = \u03b8 :=\nbegin\n  have h\u03c0 := real.pi_pos,\n  simp only [arg, abs_mul, abs_cos_add_sin_mul_I, abs_of_nonneg hr.le, mul_one],\n  simp only [of_real_mul_re, of_real_mul_im, neg_im, \u2190 of_real_cos, \u2190 of_real_sin,\n    \u2190 mk_eq_add_mul_I, neg_div, mul_div_cancel_left _ hr.ne',\n    mul_nonneg_iff_right_nonneg_of_pos hr],\n  by_cases h\u2081 : \u03b8 \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2),\n  { rw if_pos, exacts [real.arcsin_sin' h\u2081, real.cos_nonneg_of_mem_Icc h\u2081] },\n  { rw [mem_Icc, not_and_distrib, not_le, not_le] at h\u2081, cases h\u2081,\n    { replace h\u03b8 := h\u03b8.1,\n      have hcos : real.cos \u03b8 < 0,\n      { rw [\u2190 neg_pos, \u2190 real.cos_add_pi], refine real.cos_pos_of_mem_Ioo \u27e8_, _\u27e9; linarith },\n      have hsin : real.sin \u03b8 < 0 := real.sin_neg_of_neg_of_neg_pi_lt (by linarith) h\u03b8,\n      rw [if_neg, if_neg, \u2190 real.sin_add_pi, real.arcsin_sin, add_sub_cancel];\n        [linarith, linarith, exact hsin.not_le, exact hcos.not_le] },\n    { replace h\u03b8 := h\u03b8.2,\n      have hcos : real.cos \u03b8 < 0 := real.cos_neg_of_pi_div_two_lt_of_lt h\u2081 (by linarith),\n      have hsin : 0 \u2264 real.sin \u03b8 := real.sin_nonneg_of_mem_Icc \u27e8by linarith, h\u03b8\u27e9,\n      rw [if_neg, if_pos, \u2190 real.sin_sub_pi, real.arcsin_sin, sub_add_cancel];\n        [linarith, linarith, exact hsin, exact hcos.not_le] } }\nend\n\nlemma arg_cos_add_sin_mul_I {\u03b8 : \u211d} (h\u03b8 : \u03b8 \u2208 Ioc (-\u03c0) \u03c0) :\n  arg (cos \u03b8 + sin \u03b8 * I) = \u03b8 :=\nby rw [\u2190 one_mul (_ + _), \u2190 of_real_one, arg_mul_cos_add_sin_mul_I zero_lt_one h\u03b8]\n\n@[simp] lemma arg_zero : arg 0 = 0 := by simp [arg, le_refl]\n\nlemma ext_abs_arg {x y : \u2102} (h\u2081 : x.abs = y.abs) (h\u2082 : x.arg = y.arg) : x = y :=\nby rw [\u2190 abs_mul_exp_arg_mul_I x, \u2190 abs_mul_exp_arg_mul_I y, h\u2081, h\u2082]\n\nlemma ext_abs_arg_iff {x y : \u2102} : x = y \u2194 abs x = abs y \u2227 arg x = arg y :=\n\u27e8\u03bb h, h \u25b8 \u27e8rfl, rfl\u27e9, and_imp.2 ext_abs_arg\u27e9\n\nlemma arg_mem_Ioc (z : \u2102) : arg z \u2208 Ioc (-\u03c0) \u03c0 :=\nbegin\n  have h\u03c0 : 0 < \u03c0 := real.pi_pos,\n  rcases eq_or_ne z 0 with (rfl|hz), simp [h\u03c0, h\u03c0.le],\n  rcases exists_unique_add_zsmul_mem_Ioc real.two_pi_pos (arg z) (-\u03c0) with \u27e8N, hN, -\u27e9,\n  rw [two_mul, neg_add_cancel_left, \u2190 two_mul, zsmul_eq_mul] at hN,\n  rw [\u2190 abs_mul_cos_add_sin_mul_I z, \u2190 cos_add_int_mul_two_pi _ N,\n    \u2190 sin_add_int_mul_two_pi _ N],\n  simp only [\u2190 of_real_one, \u2190 of_real_bit0, \u2190 of_real_mul, \u2190 of_real_add, \u2190 of_real_int_cast],\n  rwa [arg_mul_cos_add_sin_mul_I (abs_pos.2 hz) hN]\nend\n\n@[simp] lemma range_arg : range arg = Ioc (-\u03c0) \u03c0 :=\n(range_subset_iff.2 arg_mem_Ioc).antisymm (\u03bb x hx, \u27e8_, arg_cos_add_sin_mul_I hx\u27e9)\n\nlemma arg_le_pi (x : \u2102) : arg x \u2264 \u03c0 :=\n(arg_mem_Ioc x).2\n\nlemma neg_pi_lt_arg (x : \u2102) : -\u03c0 < arg x :=\n(arg_mem_Ioc x).1\n\n@[simp] lemma arg_nonneg_iff {z : \u2102} : 0 \u2264 arg z \u2194 0 \u2264 z.im :=\nbegin\n  rcases eq_or_ne z 0 with (rfl|h\u2080), { simp },\n  calc 0 \u2264 arg z \u2194 0 \u2264 real.sin (arg z) :\n    \u27e8\u03bb h, real.sin_nonneg_of_mem_Icc \u27e8h, arg_le_pi z\u27e9,\n      by { contrapose!, intro h, exact real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _) }\u27e9\n  ... \u2194 _ : by rw [sin_arg, le_div_iff (abs_pos.2 h\u2080), zero_mul]\nend\n\n@[simp] lemma arg_neg_iff {z : \u2102} : arg z < 0 \u2194 z.im < 0 :=\nlt_iff_lt_of_le_iff_le arg_nonneg_iff\n\nlemma arg_real_mul (x : \u2102) {r : \u211d} (hr : 0 < r) : arg (r * x) = arg x :=\nbegin\n  rcases eq_or_ne x 0 with (rfl|hx), { rw mul_zero },\n  conv_lhs { rw [\u2190 abs_mul_cos_add_sin_mul_I x, \u2190 mul_assoc, \u2190 of_real_mul,\n    arg_mul_cos_add_sin_mul_I (mul_pos hr (abs_pos.2 hx)) x.arg_mem_Ioc] }\nend\n\nlemma arg_eq_arg_iff {x y : \u2102} (hx : x \u2260 0) (hy : y \u2260 0) :\n  arg x = arg y \u2194 (abs y / abs x : \u2102) * x = y :=\nbegin\n  simp only [ext_abs_arg_iff, abs_mul, abs_div, abs_of_real, abs_abs,\n    div_mul_cancel _ (abs_ne_zero.2 hx), eq_self_iff_true, true_and],\n  rw [\u2190 of_real_div, arg_real_mul],\n  exact div_pos (abs_pos.2 hy) (abs_pos.2 hx)\nend\n\nlemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : \u2102} (hxr : x.re < 0) (hxi : 0 \u2264 x.im) :\n  arg x = arg (-x) + \u03c0 :=\nhave 0 \u2264 (-x).re, from le_of_lt $ by simpa [neg_pos],\nby rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg]\n\nlemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : \u2102} (hxr : x.re < 0) (hxi : x.im < 0) :\n  arg x = arg (-x) - \u03c0 :=\nhave 0 \u2264 (-x).re, from le_of_lt $ by simpa [neg_pos],\nby rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg]\n\n@[simp] lemma arg_one : arg 1 = 0 :=\nby simp [arg, zero_le_one]\n\n@[simp] lemma arg_neg_one : arg (-1) = \u03c0 :=\nby simp [arg, le_refl, not_le.2 (@zero_lt_one \u211d _ _)]\n\n@[simp] lemma arg_I : arg I = \u03c0 / 2 :=\nby simp [arg, le_refl]\n\n@[simp] lemma arg_neg_I : arg (-I) = -(\u03c0 / 2) :=\nby simp [arg, le_refl]\n\n@[simp] lemma tan_arg (x : \u2102) : real.tan (arg x) = x.im / x.re :=\nbegin\n  by_cases h : x = 0,\n  { simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },\n  rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,\n      div_div_div_cancel_right _ (abs_ne_zero.2 h)]\nend\n\nlemma arg_of_real_of_nonneg {x : \u211d} (hx : 0 \u2264 x) : arg x = 0 :=\nby simp [arg, hx]\n\nlemma arg_eq_pi_iff {z : \u2102} : arg z = \u03c0 \u2194 z.re < 0 \u2227 z.im = 0 :=\nbegin\n  by_cases h\u2080 : z = 0, { simp [h\u2080, lt_irrefl, real.pi_ne_zero.symm] },\n  split,\n  { intro h, rw [\u2190 abs_mul_cos_add_sin_mul_I z, h], simp [h\u2080] },\n  { cases z with x y, rintro \u27e8h : x < 0, rfl : y = 0\u27e9,\n    rw [\u2190 arg_neg_one, \u2190 arg_real_mul (-1) (neg_pos.2 h)], simp [\u2190 of_real_def] }\nend\n\nlemma arg_of_real_of_neg {x : \u211d} (hx : x < 0) : arg x = \u03c0 :=\narg_eq_pi_iff.2 \u27e8hx, rfl\u27e9\n\nlemma arg_eq_pi_div_two_iff {z : \u2102} : arg z = \u03c0 / 2 \u2194 z.re = 0 \u2227 0 < z.im :=\nbegin\n  by_cases h\u2080 : z = 0, { simp [h\u2080, lt_irrefl, real.pi_div_two_pos.ne] },\n  split,\n  { intro h, rw [\u2190 abs_mul_cos_add_sin_mul_I z, h], simp [h\u2080] },\n  { cases z with x y, rintro \u27e8rfl : x = 0, hy : 0 < y\u27e9,\n    rw [\u2190 arg_I, \u2190 arg_real_mul I hy, of_real_mul', I_re, I_im, mul_zero, mul_one] }\nend\n\nlemma arg_eq_neg_pi_div_two_iff {z : \u2102} : arg z = - (\u03c0 / 2) \u2194 z.re = 0 \u2227 z.im < 0 :=\nbegin\n  by_cases h\u2080 : z = 0, { simp [h\u2080, lt_irrefl, real.pi_ne_zero] },\n  split,\n  { intro h, rw [\u2190 abs_mul_cos_add_sin_mul_I z, h], simp [h\u2080] },\n  { cases z with x y, rintro \u27e8rfl : x = 0, hy : y < 0\u27e9,\n    rw [\u2190 arg_neg_I, \u2190 arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I],\n    simp }\nend\n\nlemma arg_of_re_nonneg {x : \u2102} (hx : 0 \u2264 x.re) : arg x = real.arcsin (x.im / x.abs) :=\nif_pos hx\n\nlemma arg_of_re_neg_of_im_nonneg {x : \u2102} (hx_re : x.re < 0) (hx_im : 0 \u2264 x.im) :\n  arg x = real.arcsin ((-x).im / x.abs) + \u03c0 :=\nby simp only [arg, hx_re.not_le, hx_im, if_true, if_false]\n\nlemma arg_of_re_neg_of_im_neg {x : \u2102} (hx_re : x.re < 0) (hx_im : x.im < 0) :\n  arg x = real.arcsin ((-x).im / x.abs) - \u03c0 :=\nby simp only [arg, hx_re.not_le, hx_im.not_le, if_false]\n\nlemma arg_of_im_nonneg_of_ne_zero {z : \u2102} (h\u2081 : 0 \u2264 z.im) (h\u2082 : z \u2260 0) :\n  arg z = real.arccos (z.re / abs z) :=\nby rw [\u2190 cos_arg h\u2082, real.arccos_cos (arg_nonneg_iff.2 h\u2081) (arg_le_pi _)]\n\nlemma arg_of_im_pos {z : \u2102} (hz : 0 < z.im) : arg z = real.arccos (z.re / abs z) :=\narg_of_im_nonneg_of_ne_zero hz.le (\u03bb h, hz.ne' $ h.symm \u25b8 rfl)\n\nlemma arg_of_im_neg {z : \u2102} (hz : z.im < 0) : arg z = -real.arccos (z.re / abs z) :=\nbegin\n  have h\u2080 : z \u2260 0, from mt (congr_arg im) hz.ne,\n  rw [\u2190 cos_arg h\u2080, \u2190 real.cos_neg, real.arccos_cos, neg_neg],\n  exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le]\nend\n\nsection continuity\n\nvariables {x z : \u2102}\n\nlemma arg_eq_nhds_of_re_pos (hx : 0 < x.re) : arg =\u1da0[\ud835\udcdd x] \u03bb x, real.arcsin (x.im / x.abs) :=\n((continuous_re.tendsto _).eventually (lt_mem_nhds hx)).mono $ \u03bb y hy, arg_of_re_nonneg hy.le\n\nlemma arg_eq_nhds_of_re_neg_of_im_pos (hx_re : x.re < 0) (hx_im : 0 < x.im) :\n  arg =\u1da0[\ud835\udcdd x] \u03bb x, real.arcsin ((-x).im / x.abs) + \u03c0 :=\nbegin\n  suffices h_forall_nhds : \u2200\u1da0 (y : \u2102) in (\ud835\udcdd x), y.re < 0 \u2227 0 < y.im,\n    from h_forall_nhds.mono (\u03bb y hy, arg_of_re_neg_of_im_nonneg hy.1 hy.2.le),\n  refine is_open.eventually_mem _ (\u27e8hx_re, hx_im\u27e9 : x.re < 0 \u2227 0 < x.im),\n  exact is_open.and (is_open_lt continuous_re continuous_zero)\n    (is_open_lt continuous_zero continuous_im),\nend\n\nlemma arg_eq_nhds_of_re_neg_of_im_neg (hx_re : x.re < 0) (hx_im : x.im < 0) :\n  arg =\u1da0[\ud835\udcdd x] \u03bb x, real.arcsin ((-x).im / x.abs) - \u03c0 :=\nbegin\n  suffices h_forall_nhds : \u2200\u1da0 (y : \u2102) in (\ud835\udcdd x), y.re < 0 \u2227 y.im < 0,\n    from h_forall_nhds.mono (\u03bb y hy, arg_of_re_neg_of_im_neg hy.1 hy.2),\n  refine is_open.eventually_mem _ (\u27e8hx_re, hx_im\u27e9 : x.re < 0 \u2227 x.im < 0),\n  exact is_open.and (is_open_lt continuous_re continuous_zero)\n    (is_open_lt continuous_im continuous_zero),\nend\n\n\n\nlemma arg_eq_nhds_of_im_neg (hz : im z < 0) :\n  arg =\u1da0[\ud835\udcdd z] \u03bb x, -real.arccos (x.re / abs x) :=\n((continuous_im.tendsto _).eventually (gt_mem_nhds hz)).mono $ \u03bb x, arg_of_im_neg\n\nlemma continuous_at_arg (h : 0 < x.re \u2228 x.im \u2260 0) : continuous_at arg x :=\nbegin\n  have h\u2080 : abs x \u2260 0, { rw abs_ne_zero, rintro rfl, simpa using h },\n  rw [\u2190 lt_or_lt_iff_ne] at h,\n  rcases h with (hx_re|hx_im|hx_im),\n  exacts [(real.continuous_at_arcsin.comp (continuous_im.continuous_at.div\n    continuous_abs.continuous_at h\u2080)).congr (arg_eq_nhds_of_re_pos hx_re).symm,\n    (real.continuous_arccos.continuous_at.comp (continuous_re.continuous_at.div\n      continuous_abs.continuous_at h\u2080)).neg.congr (arg_eq_nhds_of_im_neg hx_im).symm,\n    (real.continuous_arccos.continuous_at.comp (continuous_re.continuous_at.div\n      continuous_abs.continuous_at h\u2080)).congr (arg_eq_nhds_of_im_pos hx_im).symm]\nend\n\nlemma tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto arg (\ud835\udcdd[{z : \u2102 | z.im < 0}] z) (\ud835\udcdd (-\u03c0)) :=\nbegin\n  suffices H :\n    tendsto (\u03bb x : \u2102, real.arcsin ((-x).im / x.abs) - \u03c0) (\ud835\udcdd[{z : \u2102 | z.im < 0}] z) (\ud835\udcdd (-\u03c0)),\n  { refine H.congr' _,\n    have : \u2200\u1da0 x : \u2102 in \ud835\udcdd z, x.re < 0, from continuous_re.tendsto z (gt_mem_nhds hre),\n    filter_upwards [self_mem_nhds_within, mem_nhds_within_of_mem_nhds this],\n    intros w him hre,\n    rw [arg, if_neg hre.not_le, if_neg him.not_le] },\n  convert (real.continuous_at_arcsin.comp_continuous_within_at\n    ((continuous_im.continuous_at.comp_continuous_within_at continuous_within_at_neg).div\n      continuous_abs.continuous_within_at _)).sub tendsto_const_nhds,\n  { simp [him] },\n  { lift z to \u211d using him, simpa using hre.ne }\nend\n\nlemma continuous_within_at_arg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  continuous_within_at arg {z : \u2102 | 0 \u2264 z.im} z :=\nbegin\n  have : arg =\u1da0[\ud835\udcdd[{z : \u2102 | 0 \u2264 z.im}] z] \u03bb x, real.arcsin ((-x).im / x.abs) + \u03c0,\n  { have : \u2200\u1da0 x : \u2102 in \ud835\udcdd z, x.re < 0, from continuous_re.tendsto z (gt_mem_nhds hre),\n    filter_upwards [self_mem_nhds_within, mem_nhds_within_of_mem_nhds this],\n    intros w him hre,\n    rw [arg, if_neg hre.not_le, if_pos him] },\n  refine continuous_within_at.congr_of_eventually_eq _ this _,\n  { refine (real.continuous_at_arcsin.comp_continuous_within_at\n      ((continuous_im.continuous_at.comp_continuous_within_at continuous_within_at_neg).div\n        continuous_abs.continuous_within_at _)).add tendsto_const_nhds,\n    lift z to \u211d using him, simpa using hre.ne },\n  { rw [arg, if_neg hre.not_le, if_pos him.ge] }\nend\n\nlemma tendsto_arg_nhds_within_im_nonneg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto arg (\ud835\udcdd[{z : \u2102 | 0 \u2264 z.im}] z) (\ud835\udcdd \u03c0) :=\nby simpa only [arg_eq_pi_iff.2 \u27e8hre, him\u27e9]\n  using (continuous_within_at_arg_of_re_neg_of_im_zero hre him).tendsto\n\nend continuity\n\nend complex\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/special_functions/complex/arg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7287588659246458}}
{"text": "variables (men : Type) (barber : men)\nvariable  (shaves : men \u2192 men \u2192 Prop)\n\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : false :=\n  have \u00ac shaves barber barber, from (\n    assume barber_shaves_self: shaves barber barber,\n    have \u00ac shaves barber barber, from (h barber).mp barber_shaves_self,\n    absurd barber_shaves_self \u2039 \u00ac shaves barber barber \u203a\n  ),\n  have shaves barber barber, from (h barber).mpr \u2039 \u00ac shaves barber barber \u203a,\n  absurd this \u2039 \u00ac  shaves barber barber \u203a\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/chap4_exercise3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7287567717501754}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Aaron Anderson.\n-/\n\nimport data.nat.totient\nimport number_theory.quadratic_reciprocity\nimport number_theory.lucas_lehmer\nimport multiplicity_vectors\n\n\n/-\n# Perfect Numbers\n\n## Notations\n\n## Implementation Notes\nI have used pnats in this version most of the time.\n\n## References \nhttps://en.wikipedia.org/wiki/Euclid%E2%80%93Euler_theorem\n-/\n\nopen_locale classical\nopen_locale big_operators\n\nsection definitions\n\nvariable (n : \u2115+)\n\n/--\nThe finset of (positive) divisors of n\n-/\ndef divisors : finset \u2115+ := (pnat.Ico 1 (n + 1)).filter (\u03bb x : \u2115+, x \u2223 n)\n\n/--\nThe finset of proper (positive) divisors of n\n-/\ndef proper_divisors : finset \u2115+ := (pnat.Ico 1 n).filter (\u03bb x : \u2115+, x \u2223 n)\n\nlemma not_proper_self : \u00ac n \u2208 proper_divisors n := by simp [proper_divisors]\n\nvariable {n}\nlemma pnat.le_of_dvd {m : \u2115+} : m \u2223 n \u2192 m \u2264 n :=\nby { rw pnat.dvd_iff', intro h, rw \u2190 h, apply (pnat.mod_le n m).left }\n\n@[simp]\nlemma mem_divisors {m : \u2115+} : m \u2208 divisors n \u2194 m \u2223 n :=\nbegin\n  rw divisors,\n  simp only [true_and, pnat.one_le, pnat.Ico.mem, finset.mem_filter],\n  split, intro hyp, exact hyp.right,\n  intro hyp, split, swap, exact hyp,\n  rw pnat.lt_add_one_iff, apply pnat.le_of_dvd hyp\nend\n\nlemma divisor_le {m : \u2115+}:\nm \u2208 divisors n \u2192 m \u2264 n := by {rw mem_divisors, exact pnat.le_of_dvd}\n\n@[simp]\nlemma mem_proper_divisors {m : \u2115+} : m \u2208 proper_divisors n \u2194 m \u2223 n \u2227 m \u2260 n :=\nbegin\n  rw proper_divisors,\n  simp only [true_and, pnat.one_le, ne.def, pnat.Ico.mem, finset.mem_filter],\n  split, intro hyp, split, exact hyp.right, \n  { intro contra, rw contra at hyp, apply lt_irrefl n hyp.left },\n  { intro hyp, split, swap, exact hyp.left, apply lt_of_le_of_ne,\n    apply pnat.le_of_dvd hyp.left, apply hyp.right }\nend\n\nvariable (n)\n\n----pnat.dvd_refl should be a simp lemma!\nlemma divisors_eq_proper_divisors_insert_self :\n  divisors n = has_insert.insert n (proper_divisors n) :=\nbegin\n  ext, rw [finset.mem_insert, mem_divisors, mem_proper_divisors], split,\n  { intro hdvd, by_cases a = n, left, exact h,\n    right, split, exact hdvd, exact h },\n  { intro hyp, cases hyp, rw hyp, apply pnat.dvd_refl, apply hyp.left }\nend\n\ndef sum_divisors : \u2115 := \u2211 i in divisors n, i\n\ndef sum_proper_divisors : \u2115 := \u2211 i in proper_divisors n, i\n\nlemma sum_divisors_eq_sum_proper_divisors_add_self :\n  sum_divisors n = sum_proper_divisors n + n :=\nbegin\n  rw sum_divisors,\n  rw sum_proper_divisors,\n  rw divisors_eq_proper_divisors_insert_self,\n  rw finset.sum_insert, rw add_comm,\n  apply not_proper_self\nend\n\n/--\nA perfect number is one that is equal to the sum of its proper divisors\n-/\ndef perfect : Prop := sum_proper_divisors n = n\n\nend definitions\n\nsection basic_lemmas\n\n---- should two_mul be a simp lemma?\nlemma perfect_iff_sum_divisors_twice {n : \u2115+} : perfect n \u2194 sum_divisors n = 2 * n :=\nbegin\n  rw sum_divisors_eq_sum_proper_divisors_add_self,\n  rw perfect, rw two_mul, simp\nend\n\n@[simp] \nlemma divisors_one : divisors 1 = ({1} : finset \u2115+) :=\nby { ext, rw mem_divisors, simp [pnat.dvd_one_iff] } ---  pnat.dvd_one_iff should be a simp lemma\n\n@[simp]\nlemma mem_one_divisors {n : \u2115+}: (1 : \u2115+) \u2208 divisors n :=\nby { rw mem_divisors, apply pnat.one_dvd }\n\nlemma mem_self_divisors {n : \u2115+} : n \u2208 divisors n :=\nby { rw mem_divisors, apply pnat.dvd_refl }\n\nlemma pos_sum_divisors {n : \u2115+} : 0 < sum_divisors n :=\nbegin\n  unfold sum_divisors,\n  have h : \u2211 i in divisors n, 0 = 0, rw finset.sum_eq_zero_iff, simp,\n  rw \u2190 h,\n  apply finset.sum_lt_sum, simp,\n  existsi (1 : \u2115+), simp only [nat.succ_pos', exists_prop, and_true],\n  simp\nend\n\n@[simp]\nlemma divisors_pow_prime {p : \u2115+} (pp : p.prime) (k : \u2115)  {x : \u2115+} :\n  x \u2208 divisors (p ^ k) \u2194  \u2203 (j : \u2115) (H : j \u2264 k), x = p ^ j :=\nbegin\n  rw mem_divisors,\n  rw pnat.dvd_iff, simp only [pnat.pow_coe],\n  --rw nat.primes.coe_pnat_nat, -- simp this?\n  --change \u2191x \u2223 p.val ^ k \u2194 \u2203 (j : \u2115) (H : j \u2264 k), x = p ^ j, --changing \u2191 to .val is a pain\n  rw nat.dvd_prime_pow pp,\n  split; intro h; cases h; cases h_h; existsi h_w; existsi h_h_w,\n  { apply pnat.eq, rw h_h_h, simp only [nat.primes.coe_pnat_nat, pnat.pow_coe] },   --- pnat.eq? not coe_inj?\n  { rw h_h_h, simp only [nat.primes.coe_pnat_nat, pnat.pow_coe] }\nend\n\nlemma divisors_pow_prime_insert {p : \u2115+} (pp : p.prime) (k : \u2115)  :\n  divisors (p ^ (k + 1)) = has_insert.insert (p ^ (k + 1)) (divisors (p ^ k)) :=\nbegin\n  ext,\n  simp [divisors_pow_prime pp],\n  split,\n  { intro h, cases h, cases h_h, \n    by_cases h_w = k + 1,\n    { left, rw h at h_h_right, exact h_h_right },\n    { right, existsi h_w, split, omega, exact h_h_right }\n  },\n  { intro h, cases h, existsi k + 1, tauto,\n    cases h, existsi h_w, split, linarith, exact h_h.right }\nend\n\n@[simp]\nlemma add_one_sub_one_prime {p : \u2115+} (pp : p.prime): (p : \u2115) - 1 + 1 = p :=\nby { apply nat.succ_pred_prime pp }\n\nlemma pnat.mul_lt_mul_left (a : \u2115+) {b c : \u2115+}: b < c \u2192 a * b < a * c :=\nbegin\n  intro bc,\n  apply nat.mul_lt_mul_of_pos_left, apply bc, apply a.property,\nend\n\nlemma pnat.mul_lt_mul_right (a : \u2115+) {b c : \u2115+}: b < c \u2192 b * a < c * a :=\nbegin\n  intro bc,\n  apply nat.mul_lt_mul_of_pos_right, apply bc, apply a.property,\nend\n\nlemma pnat.prime.one_lt {p : \u2115+} : p.prime \u2192 1 < p := nat.prime.one_lt\n\nlemma sum_divisors_pow_prime {p : \u2115+} (pp : p.prime) (k : \u2115)  :\n  sum_divisors (p ^ k) * (p - 1)= (p ^ (k + 1) - 1) :=\nbegin\n  rw sum_divisors,\n  induction k, simp,\n  rw divisors_pow_prime_insert pp,\n  rw finset.sum_insert, \n  { rw add_mul, rw k_ih,\n    rw nat.pow_succ p (k_n.succ), rw nat.succ_eq_add_one,\n    rw \u2190 nat.add_sub_assoc,\n    { refine congr (congr rfl _) rfl,\n    have h := add_one_sub_one_prime pp,\n    conv_rhs {rw \u2190 h, rw mul_add, rw h}, simp },\n    { rw \u2190 pnat.one_coe, rw \u2190 pnat.pow_coe, rw pnat.coe_le_coe, apply pnat.one_le }\n  },\n  { intro contra, have h := divisor_le contra,\n    have g1 :=  pnat.mul_lt_mul_right (p ^ k_n) (pnat.prime.one_lt pp),\n    rw pow_succ at h, rw one_mul at g1, apply not_lt_of_ge h g1, -- linarith for nats\n  }\nend\n\nlemma sum_divisors_prime {p : \u2115+} (pp : p.prime) : sum_divisors p = p + 1 :=\nbegin\n  have h1 := sum_divisors_pow_prime pp 1,\n  rw pow_one at h1, --- had to switch which pow, lol\n  have h2 : ((p + 1) * (p - 1) : \u2115) = p ^ 2 - 1, -- have to make type declarations\n  { rw nat.mul_sub_left_distrib, repeat {rw add_mul},\n    rw nat.pow_two, simp only [mul_one, one_mul],\n    rw add_comm, rw nat.add_sub_add_left },\n  rw \u2190 h2 at h1,\n  apply nat.eq_of_mul_eq_mul_right _ h1,\n  apply nat.prime.pred_pos pp\nend\n\nlemma pnat.prime_two : (2 : \u2115+).prime := nat.prime_two\n\nlemma sum_divisors_pow_two (k : \u2115) : sum_divisors (2 ^ k) = (2 ^ (k + 1) - 1) :=\nbegin\n  have h := sum_divisors_pow_prime pnat.prime_two k,\n  change sum_divisors (2 ^ k) * (2 - 1) = 2 ^ (k + 1) - 1 at h, -- couldn't find anything to do but change\n  rw mul_one at h,\n  apply h,\nend\n\nlemma odd_sum_divisors_pow_two (k : \u2115) : \u00ac has_dvd.dvd 2 (sum_divisors (2 ^ k)) :=\nbegin\n  rw sum_divisors_pow_two k,\n  intro contra,\n  have h : 2 \u2223 2 ^ (k + 1) - 1 + 1,\n  { existsi 2 ^ k,\n    rw [\u2190 nat.pred_eq_sub_one, \u2190 nat.succ_eq_add_one, nat.succ_pred_eq_of_pos _],\n    { rw [mul_comm, nat.pow_succ] },\n    apply nat.pos_pow_of_pos, omega,\n  },\n  rw \u2190 nat.dvd_add_iff_right contra at h,\n  have h:= nat.le_of_dvd _ h; linarith,\nend\n\n@[simp]\nlemma pnat.coe_eq_one_iff {m : \u2115+} :\n(m : \u2115) = 1 \u2194 m = 1 := by { split; intro h; try { apply pnat.eq}; rw h; simp }\n\n@[simp]\nlemma pnat.eq_iff {m n : \u2115+} :\n(m : \u2115) = \u2191n \u2194 m = n := by { split, apply pnat.eq, intro h, rw h }\n\n\nlemma pnat.dvd_prime {p m : \u2115+} (pp : p.prime) :\n(m \u2223 p \u2194 m = 1 \u2228 m = p) := by { rw pnat.dvd_iff, rw nat.dvd_prime pp, simp }\n\nlemma divisors_prime {p : \u2115+} (pp : p.prime) : divisors p = {p, 1} :=\nbegin\n  ext,\n  simp only [mem_divisors, ne.def, finset.mem_insert, finset.mem_singleton],\n  split; intro h, rw pnat.dvd_prime pp at h, apply h.symm,\n  cases h; rw h, apply pnat.dvd_refl, apply pnat.one_dvd\nend\n\nlemma card_pair_eq_two {\u03b1 : Type} {x y : \u03b1} (neq : x \u2260 y) : ({x, y} : finset \u03b1).card = 2 :=\nbegin\n  rw finset.card_insert_of_not_mem, rw finset.card_singleton, rw finset.mem_singleton, apply neq,\nend\n\n----why can't I use the above????\nlemma pnat.card_pair_eq_two {x y : \u2115+} (neq : x \u2260 y) : ({x, y} : finset \u2115+).card = 2 := \nbegin\n  rw finset.card_insert_of_not_mem, rw finset.card_singleton, rw finset.mem_singleton, apply neq,\nend\n\nlemma pnat.prime.ne_one {p : \u2115+} : p.prime \u2192 p \u2260 1 :=\nby { intro pp, intro contra, apply nat.prime.ne_one pp, rw pnat.coe_eq_one_iff, apply contra }\n\nlemma pnat.eq_one_of_lt_two {n : \u2115+} : n < 2 \u2192 n = 1 := \nbegin\n  intro h, apply le_antisymm, swap, apply pnat.one_le,\n  change n < 1 + 1 at h, rw pnat.lt_add_one_iff at h, apply h\nend\n\n@[simp]\nlemma pnat.one_val : (1 : \u2115+).val = 1 := rfl\n\n@[simp]\nlemma pnat.not_prime_one : \u00ac (1: \u2115+).prime :=  nat.not_prime_one\n\nlemma pnat.prime.not_dvd_one {p : \u2115+} :\np.prime \u2192  \u00ac p \u2223 1 := \u03bb pp : p.prime, nat.prime.not_dvd_one pp\n\nlemma pnat.exists_prime_and_dvd {n : \u2115+} : 2 \u2264 n \u2192 (\u2203 (p : \u2115+), p.prime \u2227 p \u2223 n) := \nbegin\n  intro h, cases nat.exists_prime_and_dvd h with p hp,\n  existsi (\u27e8p, nat.prime.pos hp.left\u27e9 : \u2115+), apply hp\nend\n\nlemma prime_iff_two_divisors {n : \u2115+} : n.prime \u2194 (divisors n).card = 2 :=\nbegin\n  split,\n  { intro np, rw divisors_prime np, apply pnat.card_pair_eq_two (pnat.prime.ne_one np),},\n  { intro h,\n    have ge2 : 2 \u2264 n,\n    { contrapose h, simp at h, have  h' := pnat.eq_one_of_lt_two h, rw h',\n      simp only [divisors_one, finset.card_singleton], omega },\n    have ex := pnat.exists_prime_and_dvd ge2, cases ex with p hp,\n    have subs : {n, (1 : \u2115+)} \u2286 divisors n,\n    { rw finset.subset_iff, intro x, simp only [finset.mem_insert, finset.mem_singleton],\n      intro h, cases h; rw h_1, apply mem_self_divisors, apply mem_one_divisors },\n    have seteq : {n, (1 : \u2115+)} = divisors n,\n    { apply finset.eq_of_subset_of_card_le subs _, rw h, rw pnat.card_pair_eq_two _, \n      contrapose hp, simp only [classical.not_not] at hp, rw hp,\n      simp only [not_and], apply pnat.prime.not_dvd_one },\n    have pdvd : p \u2208 divisors n, rw mem_divisors, apply hp.right,\n    rw \u2190 seteq at pdvd, simp only [finset.mem_insert, finset.mem_singleton] at pdvd,\n    cases pdvd, rw \u2190 pdvd, apply hp.left,\n    exfalso, rw pdvd at hp, apply nat.not_prime_one hp.left\n  }\nend\n\nlemma subset_eq_divisors_of_sum_eq_sum {n : \u2115+} {s : finset \u2115+} (hsub: \u2200 (x : \u2115+), x \u2208 s \u2192 x \u2223 n) :\n  \u2211 i in s, \u2191i = sum_divisors n \u2192 s = divisors n :=\nbegin\n  have subs : s \u2286 divisors n,\n  { rw finset.subset_iff, intros x hx, rw mem_divisors, apply (hsub x hx) },\n  intro h,\n  apply finset.subset.antisymm subs _,\n  contrapose h, rw finset.subset_iff at h, simp only [classical.not_forall, classical.not_imp] at h,\n  intro contra, apply nat.lt_irrefl (s.sum (coe : \u2115+ \u2192 \u2115)),\n  cases h with x hx, rw mem_divisors at hx,\n  --have posx : 0 < id x,\n  --{ rw id.def, apply nat.pos_of_ne_zero, intro contra, apply nonzero,\n  --  rw contra at hx, apply nat.eq_zero_of_zero_dvd,\n  --  rw mem_divisors at hx, apply hx.left.left },\n  have h : s.sum coe < (divisors n).sum coe := \n    (finset.sum_lt_sum_of_subset subs) (by simpa) (pnat.pos x) (by simp),\n    rw sum_divisors at contra, simp only [id.def] at h, rw \u2190 contra at h, apply h,\nend\n\n\nlemma prime_and_one_of_sum_two_divisors_eq_sum_divisors {x y : \u2115+} (hneq : x \u2260 y) (hdvd : y \u2223 x) (hsum : \u2191(x + y) = sum_divisors x) :\n  x.prime \u2227 y = 1 :=\nbegin\n  have hdivs : {x, y} = divisors x,\n  { apply subset_eq_divisors_of_sum_eq_sum,\n    { intro z, simp only [finset.mem_insert, finset.mem_singleton], intro h,\n      cases h; rw h, refl, apply hdvd },\n    { rw \u2190 hsum, apply finset.sum_pair hneq } },\n  have card2 := pnat.card_pair_eq_two hneq, rw hdivs at card2, rw \u2190 prime_iff_two_divisors at card2,\n  split, apply card2,\n  rw divisors_prime card2 at hdivs,\n  have memy : y \u2208 ({x, y} : finset \u2115+), simp,\n  rw hdivs at memy, simp only [finset.mem_insert, finset.mem_singleton] at memy,\n  cases memy, exfalso, apply hneq, symmetry, apply memy,\n  apply memy\nend\n\n--def pnat.coprime (m n : \u2115+) : Prop := m.gcd n = 1\n\n@[simp]\ndef pnat.coprime_coe {m n : \u2115+} : nat.coprime \u2191m \u2191n \u2194 m.coprime n :=\nby { unfold pnat.coprime, unfold nat.coprime, rw \u2190 pnat.eq_iff, simp }\n\nlemma pnat.gcd_eq_left_iff_dvd {m n : \u2115+} : m \u2223 n \u2194 m.gcd n = m :=\nby { rw pnat.dvd_iff, rw nat.gcd_eq_left_iff_dvd, rw \u2190 pnat.eq_iff, simp }\n\nlemma pnat.coprime.gcd_mul_right_cancel (m : \u2115+) {n k : \u2115+} :\n  k.coprime n \u2192 (m * k).gcd n = m.gcd n :=\nbegin\n  intro h, apply pnat.eq, simp only [pnat.gcd_coe, pnat.mul_coe],\n  apply nat.coprime.gcd_mul_right_cancel, simpa\nend\n\nlemma pnat.gcd_comm {m n : \u2115+} : m.gcd n = n.gcd m :=\nby { apply pnat.eq, simp only [pnat.gcd_coe], apply nat.gcd_comm }\n\nlemma pnat.coprime.symm {m n : \u2115+} : m.coprime n \u2192 n.coprime m :=\nby { unfold pnat.coprime, rw pnat.gcd_comm, simp }\n\nlemma pnat.coprime.coprime_dvd_left {m k n : \u2115+} :\n  m \u2223 k \u2192 k.coprime n \u2192 m.coprime n :=\nby { rw pnat.dvd_iff, repeat {rw \u2190 pnat.coprime_coe}, apply nat.coprime.coprime_dvd_left }\n\nlemma coprime_factor_eq_gcd_left {a b m n : \u2115+} (cop : m.coprime n) (am : a \u2223 m) (bn : b \u2223 n):\n  a = (a * b).gcd m :=\nbegin\n  rw pnat.gcd_eq_left_iff_dvd at am,\n  conv_lhs {rw \u2190 am}, symmetry,\n  apply pnat.coprime.gcd_mul_right_cancel a,\n  apply pnat.coprime.coprime_dvd_left bn cop.symm,\nend\n\nlemma pnat.coprime.gcd_mul (k : \u2115+) {m n : \u2115+} (h: m.coprime n) :\n  k.gcd (m * n) = k.gcd m * k.gcd n :=\nbegin\n  rw \u2190 pnat.coprime_coe at h, apply pnat.eq,\n  simp only [pnat.gcd_coe, pnat.mul_coe], apply nat.coprime.gcd_mul k h\nend\n\nlemma pnat.gcd_eq_left {m n : \u2115+} : m \u2223 n \u2192 m.gcd n = m :=\nby { rw pnat.dvd_iff, intro h, apply pnat.eq, simp only [pnat.gcd_coe], apply nat.gcd_eq_left h }\n\nlemma sum_divisors_multiplicative (m n : \u2115+) :\n  m.coprime n \u2192 sum_divisors (m * n) = (sum_divisors m) * (sum_divisors n) :=\nbegin\n  intro cop,\n  repeat {rw sum_divisors},\n  rw finset.sum_mul_sum,\n  symmetry,\n  apply finset.sum_bij (\u03bb x : \u2115+ \u00d7 \u2115+, \u03bb (h : x \u2208 _), x.fst * x.snd),\n  { simp only [prod.forall], intros a b hab, dsimp, simp only [finset.mem_product] at hab,\n    repeat {rw mem_divisors at hab}, rw mem_divisors,\n    apply mul_dvd_mul hab.left hab.right },\n  { simp only [prod.forall], intros a b hab, dsimp, simp only [finset.mem_product] at hab },\n  { simp only [prod.forall], intros a b c hab h1 h2, \n    dsimp at *, rw finset.mem_product at *, repeat {rw mem_divisors at *},\n    ext; dsimp,\n    { transitivity (a * b).gcd m,\n      { apply coprime_factor_eq_gcd_left cop hab.left hab.right },\n      { rw h2, symmetry, apply coprime_factor_eq_gcd_left cop h1.left h1.right } },\n    { transitivity (b * a).gcd n,\n      { apply coprime_factor_eq_gcd_left cop.symm hab.right hab.left },\n      { rw mul_comm, rw h2, rw mul_comm, symmetry,\n      apply coprime_factor_eq_gcd_left cop.symm h1.right h1.left } } },\n  { simp only [exists_prop, prod.exists, finset.mem_product],\n    intros c hc,\n    existsi c.gcd m, existsi c.gcd n, split,\n    { split; rw mem_divisors; apply nat.gcd_dvd_right _, },\n    { rw \u2190 pnat.coprime.gcd_mul c cop,\n      symmetry, apply pnat.gcd_eq_left,\n      rw mem_divisors at hc, apply hc } }\nend\n\nend basic_lemmas\n\nsection mersenne_to_perfect\n\n/--\nA version of ``mersenne'' from number_theory/lucas_lehmer for pnats\n-/\ndef pmersenne (p : \u2115+) : \u2115+ := \u27e8 mersenne p, mersenne_pos p.pos \u27e9\n\ndef nat.mersenne_succ (n : \u2115) : \u2115+ := \u27e8mersenne (n + 1), mersenne_pos n.succ_pos\u27e9\n\n@[simp]\nlemma pmersenne_val (p : \u2115+) : \u2191(pmersenne p) = mersenne (\u2191 p) := rfl\n\n/-\ntheorem two_le_exponent_of_prime_mersenne {p : \u2115+} : nat.prime (pmersenne p) \u2192 2 \u2264 p :=\nbegin\n  intro np,\n  cases p, cases p_val, exfalso, apply lt_irrefl 0 p_property,\n  cases p_val,\n  { exfalso, simp only [mersenne, pnat.mk_one, nat.succ_sub_succ_eq_sub,\n    pmersenne_val, pnat.one_coe, nat.sub_zero, nat.pow_one] at np,\n    apply nat.not_prime_one np },\n  { rw \u2190 pnat.coe_le_coe, simp only [pnat.mk_coe, pnat.coe_bit0, pnat.one_coe],\n    apply nat.succ_le_succ, apply nat.succ_le_succ, apply nat.zero_le }\nend\n-/\n\ntheorem two_le_exponent_of_prime_mersenne {p : \u2115} : nat.prime (2 ^ p - 1) \u2192 2 \u2264 p :=\nbegin\n  intro np, -- rw mersenne at np,\n  cases p, exfalso, apply nat.not_prime_zero np,\n  cases p, exfalso, apply nat.not_prime_one np,\n  omega\nend\n\n/--\nEuclid's theorem that Mersenne primes induce perfect numbers\n-/\ntheorem mersenne_to_perfect (p : \u2115+) :\n  (pmersenne p).prime \u2192 perfect ((2 ^ (\u2191p - 1)) * (pmersenne p)) :=\nbegin\n  intro mp,\n  have hp : 2 \u2264 p := two_le_exponent_of_prime_mersenne mp,\n  rw [perfect_iff_sum_divisors_twice, sum_divisors_multiplicative],\n  { rw [sum_divisors_pow_two, sum_divisors_prime mp],\n    repeat {rw \u2190 nat.pred_eq_sub_one},\n    repeat {rw \u2190 nat.succ_eq_add_one},\n    have pps : (p : \u2115).pred.succ = p := nat.succ_pred_eq_of_pos p.property,\n    rw pps, simp only [pnat.coe_bit0, pnat.mul_coe, pmersenne_val, pnat.one_coe, pnat.pow_coe],\n    rw [\u2190 mul_assoc, mul_comm],\n    refine congr (congr rfl _) rfl,\n    rw [\u2190 pps, mersenne, nat.pred_succ, nat.pow_succ, mul_comm,\n      \u2190 nat.pred_eq_sub_one, nat.succ_pred_eq_of_pos ],\n    apply nat.mul_pos, omega, apply nat.pow_pos, omega },\n  { have h := pow_one (pmersenne p),\n    rw [\u2190 h, \u2190 pnat.coprime_coe, pnat.pow_coe, pnat.pow_coe],\n    apply nat.coprime_pow_primes _ _ nat.prime_two mp _,\n    apply ne_of_lt,\n    simp only [pmersenne_val, mersenne],\n    rw [\u2190 nat.pred_eq_sub_one, \u2190 nat.pred_succ 2],\n    apply nat.pred_lt_pred, omega,\n    rw nat.pred_succ 2,\n    change 2 ^ 2 \u2264 2 ^ \u2191p,\n    apply nat.pow_le_pow_of_le_right, omega, apply hp }\nend\n\nend mersenne_to_perfect\n\n\nsection perfect_to_mersenne\n\n\n/--\n  Euler's proof that all even perfect numbers come from Mersenne primes\n-/\ntheorem even_perfect_to_mersenne {n : \u2115+} (even : 2 \u2223 n) (perf : perfect n):\n  \u2203 (k : \u2115), n = (2 ^ k) * k.mersenne_succ \u2227 k.mersenne_succ.prime :=\nbegin\n  let k := (factorisation n) two_prime, existsi k,\n  let x := odd_part n,\n  have hxk : x * 2 ^ k = n := (pow_mult_odd_part_eq_self n),\n  --change  at hxk,\n  have posk : 0 < k, rw \u2190 prime_dvd_iff_factorisation_pos, apply even,\n  \n  have hiff : n = 2 ^ k * k.mersenne_succ \u2194 2 * n = 2 * (2 ^ k * k.mersenne_succ),\n  { split; intro h, rw h, apply mul_left_cancel h },\n  rw [hiff, \u2190 mul_assoc, \u2190 pow_succ (2 : \u2115+)],\n  \n  rw perfect_iff_sum_divisors_twice at perf,\n  rw \u2190 pnat.eq_iff, simp only [pnat.coe_bit0, pnat.mul_coe, pnat.one_coe, pnat.pow_coe],\n  rw \u2190 perf,\n  rw \u2190 hxk at perf,\n  change sum_divisors (x * 2 ^ k) = 2 * \u2191(x * 2 ^ k) at perf,\n  rw sum_divisors_multiplicative at perf, swap, apply pnat.coprime.symm (coprime_pow_odd_part posk),\n  symmetry' at perf,\n\n  rw hxk at perf,\n  have dvd2n : sum_divisors (2 ^ k) \u2223 2 * n, {existsi (sum_divisors x), rw perf, rw mul_comm},\n  have dvdn : sum_divisors (2 ^ k) \u2223 n, \n  { apply nat.coprime.dvd_of_dvd_mul_left (nat.coprime.symm _) dvd2n,\n    rw nat.prime.coprime_iff_not_dvd nat.prime_two, apply odd_sum_divisors_pow_two k },\n  have dvdx : sum_divisors (2 ^ k) \u2223 x := dvd_odd_part_of_odd_dvd dvdn (odd_sum_divisors_pow_two k),\n  let y := x / sum_divisors (2 ^ k),\n  have ysdpow : y * sum_divisors (2 ^ k) = x := pnat.mul_div_exact dvdx,\n\n  rw \u2190 hxk at perf,\n  change 2 * (x * 2 ^ k) = sum_divisors x * sum_divisors (2 ^ k) at perf,\n  rw mul_comm at perf,\n  rw mul_assoc at perf,\n  rw \u2190 nat.pow_succ 2 k at perf,\n  rw \u2190 ysdpow at perf,\n  rw mul_comm at perf,\n  rw \u2190 mul_assoc at perf,\n  have h := pnat.mul_right_cancel perf,\n  rw ysdpow at *,\n\n  have xneqy : x \u2260 y,\n  { symmetry, rw \u2190 ysdpow, rw sum_divisors_pow_two, rw \u2190 mul_one y, rw mul_assoc, rw one_mul,\n    intro contra, have h := nat.eq_of_mul_eq_mul_left _ contra,\n    { have h'' := nat.le_succ_of_pred_le (nat.le_of_eq h.symm),\n      have h' := nat.pow_lt_pow_of_lt_right (by omega : 2 > 1) posk,\n      change 2 ^ k * 2 \u2264 2 * 1 at h'', rw mul_comm at h'',\n      have h3 :=  nat.le_of_mul_le_mul_left h'' (nat.prime.pos nat.prime_two),\n      rw nat.pow_zero at h', linarith },\n    { by_cases y = 0, swap, apply nat.pos_of_ne_zero h,\n      rw h at ysdpow, rw zero_mul at ysdpow, rw \u2190 ysdpow at hxk, rw zero_mul at hxk,\n      exfalso, rw hxk at posn, linarith } },\n  have hxy : x.prime \u2227 y = 1,\n  { apply prime_and_one_of_sum_two_divisors_eq_sum_divisors xnonzero xneqy _, swap,\n    { existsi sum_divisors (2 ^ k), rw ysdpow },\n    rw [\u2190 h, \u2190 ysdpow, sum_divisors_pow_two],\n    have powpos : 2 ^ k.succ > 0, apply nat.pos_pow_of_pos, linarith,\n    symmetry, rw \u2190 nat.succ_pred_eq_of_pos powpos, rw nat.succ_eq_add_one, rw add_mul,\n    simp only [nat.add_succ_sub_one, add_zero, one_mul, add_left_inj], rw mul_comm },\n\n  have xeq : x = sum_divisors (2 ^ k), rw \u2190 ysdpow, rw hxy.right, simp,\n  have xp : x.prime := hxy.left,\n\n  split, swap, rw sum_divisors_pow_two at xeq, rw \u2190 xeq, apply xp,\n  rw \u2190 (pow_fin_mult_coprime_part_eq_self nat.prime_two posn),\n  rw sum_divisors_multiplicative, swap,\n  { apply nat.prime.coprime_pow_of_not_dvd nat.prime_two (not_dvd_coprime_part nat.prime_two posn)},\n  rw [sum_divisors_prime xp, xeq, sum_divisors_pow_two],\n  refine congr (congr rfl _) rfl,\n  apply nat.succ_pred_eq_of_pos, simp only [nat.nat_zero_eq_zero, gt_iff_lt],\n  apply nat.pos_pow_of_pos (k + 1) (nat.prime.pos nat.prime_two)\nend\n\nend perfect_to_mersenne\n\nsection perfect_iff_mersenne\n\n/--\nThe Euclid-Euler Theorem, characterizing perfect numbers in terms of Mersenne primes\n-/\ntheorem even_perfect_iff_mersenne {n : \u2115+}:\n  2 \u2223 n \u2227 perfect n \u2194 \u2203 (p : \u2115+), n = (2 ^ (\u2191p - 1)) * (pmersenne p) \u2227 (pmersenne p).prime :=\nbegin\n  split, intro even_perf, exact even_perfect_to_mersenne even_perf.left even_perf.right,\n  intro h, cases h with p hp, rw hp.left, split, swap, apply mersenne_to_perfect p hp.right,\n  rw nat.prime.dvd_mul nat.prime_two, left,\n  rw nat.dvd_prime_pow nat.prime_two, existsi 1,\n  simp only [exists_prop, and_true, eq_self_iff_true, nat.pow_one],\n  have gt2 := two_le_exponent_of_prime_mersenne hp.right, omega\nend\n\nend perfect_iff_mersenne", "meta": {"author": "awainverse", "repo": "perfect_number", "sha": "3d5504b4529fbccd4ab69c8816731096c50402be", "save_path": "github-repos/lean/awainverse-perfect_number", "path": "github-repos/lean/awainverse-perfect_number/perfect_number-3d5504b4529fbccd4ab69c8816731096c50402be/src/perfect.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.728729409611818}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.game.ordinal\nimport set_theory.ordinal.natural_ops\n\n/-!\n# Birthdays of games\n\nThe birthday of a game is an ordinal that represents at which \"step\" the game was constructed. We\ndefine it recursively as the least ordinal larger than the birthdays of its left and right games. We\nprove the basic properties about these.\n\n# Main declarations\n\n- `pgame.birthday`: The birthday of a pre-game.\n\n# Todo\n\n- Define the birthdays of `game`s and `surreal`s.\n- Characterize the birthdays of basic arithmetical operations.\n-/\n\nuniverse u\n\nopen ordinal\n\nopen_locale natural_ops pgame\n\nnamespace pgame\n\n/-- The birthday of a pre-game is inductively defined as the least strict upper bound of the\nbirthdays of its left and right games. It may be thought as the \"step\" in which a certain game is\nconstructed. -/\nnoncomputable def birthday : pgame.{u} \u2192 ordinal.{u}\n| \u27e8xl, xr, xL, xR\u27e9 :=\n    max (lsub.{u u} $ \u03bb i, birthday (xL i)) (lsub.{u u} $ \u03bb i, birthday (xR i))\n\ntheorem birthday_def (x : pgame) : birthday x = max\n  (lsub.{u u} (\u03bb i, birthday (x.move_left i)))\n  (lsub.{u u} (\u03bb i, birthday (x.move_right i))) :=\nby { cases x, rw birthday, refl }\n\ntheorem birthday_move_left_lt {x : pgame} (i : x.left_moves) :\n  (x.move_left i).birthday < x.birthday :=\nby { cases x, rw birthday, exact lt_max_of_lt_left (lt_lsub _ i) }\n\ntheorem birthday_move_right_lt {x : pgame} (i : x.right_moves) :\n  (x.move_right i).birthday < x.birthday :=\nby { cases x, rw birthday, exact lt_max_of_lt_right (lt_lsub _ i) }\n\ntheorem lt_birthday_iff {x : pgame} {o : ordinal} : o < x.birthday \u2194\n  (\u2203 i : x.left_moves, o \u2264 (x.move_left i).birthday) \u2228\n  (\u2203 i : x.right_moves, o \u2264 (x.move_right i).birthday) :=\nbegin\n  split,\n  { rw birthday_def,\n    intro h,\n    cases lt_max_iff.1 h with h' h',\n    { left,\n      rwa lt_lsub_iff at h' },\n    { right,\n      rwa lt_lsub_iff at h' } },\n  { rintro (\u27e8i, hi\u27e9 | \u27e8i, hi\u27e9),\n    { exact hi.trans_lt (birthday_move_left_lt i) },\n    { exact hi.trans_lt (birthday_move_right_lt i) } }\nend\n\ntheorem relabelling.birthday_congr : \u2200 {x y : pgame.{u}}, x \u2261r y \u2192 birthday x = birthday y\n| \u27e8xl, xr, xL, xR\u27e9 \u27e8yl, yr, yL, yR\u27e9 r := begin\n  unfold birthday,\n  congr' 1,\n  all_goals\n  { apply lsub_eq_of_range_eq.{u u u},\n    ext i, split },\n  all_goals { rintro \u27e8j, rfl\u27e9 },\n  { exact \u27e8_, (r.move_left j).birthday_congr.symm\u27e9 },\n  { exact \u27e8_, (r.move_left_symm j).birthday_congr\u27e9 },\n  { exact \u27e8_, (r.move_right j).birthday_congr.symm\u27e9 },\n  { exact \u27e8_, (r.move_right_symm j).birthday_congr\u27e9 }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\n@[simp] theorem birthday_eq_zero {x : pgame} :\n  birthday x = 0 \u2194 is_empty x.left_moves \u2227 is_empty x.right_moves :=\nby rw [birthday_def, max_eq_zero, lsub_eq_zero_iff, lsub_eq_zero_iff]\n\n@[simp] theorem birthday_zero : birthday 0 = 0 :=\nby simp [pempty.is_empty]\n\n@[simp] theorem birthday_one : birthday 1 = 1 :=\nby { rw birthday_def, simp }\n\n@[simp] theorem birthday_star : birthday star = 1 :=\nby { rw birthday_def, simp }\n\n@[simp] theorem neg_birthday : \u2200 x : pgame, (-x).birthday = x.birthday\n| \u27e8xl, xr, xL, xR\u27e9 := begin\n  rw [birthday_def, birthday_def, max_comm],\n  congr; funext; apply neg_birthday\nend\n\n@[simp] \n\ntheorem le_birthday : \u2200 x : pgame, x \u2264 x.birthday.to_pgame\n| \u27e8xl, _, xL, _\u27e9 :=\nle_def.2 \u27e8\u03bb i, or.inl \u27e8to_left_moves_to_pgame \u27e8_, birthday_move_left_lt i\u27e9,\n  by simp [le_birthday (xL i)]\u27e9, is_empty_elim\u27e9\n\nvariables (a b x : pgame.{u})\n\ntheorem neg_birthday_le : -x.birthday.to_pgame \u2264 x :=\nby simpa only [neg_birthday, \u2190neg_le_iff] using le_birthday (-x)\n\n@[simp] theorem birthday_add : \u2200 x y : pgame.{u}, (x + y).birthday = x.birthday \u266f y.birthday\n| \u27e8xl, xr, xL, xR\u27e9 \u27e8yl, yr, yL, yR\u27e9 := begin\n  rw [birthday_def, nadd_def],\n  simp only [birthday_add, lsub_sum, mk_add_move_left_inl, move_left_mk, mk_add_move_left_inr,\n    mk_add_move_right_inl, move_right_mk, mk_add_move_right_inr],\n  rw max_max_max_comm,\n  congr; apply le_antisymm,\n  any_goals\n  { exact max_le_iff.2 \u27e8lsub_le_iff.2 (\u03bb i, lt_blsub _ _ (birthday_move_left_lt i)),\n      lsub_le_iff.2 (\u03bb i, lt_blsub _ _ (birthday_move_right_lt i))\u27e9 },\n  all_goals\n  { apply blsub_le_iff.2 (\u03bb i hi, _),\n    rcases lt_birthday_iff.1 hi with \u27e8j, hj\u27e9 | \u27e8j, hj\u27e9 },\n  { exact lt_max_of_lt_left ((nadd_le_nadd_right hj _).trans_lt (lt_lsub _ _)) },\n  { exact lt_max_of_lt_right ((nadd_le_nadd_right hj _).trans_lt (lt_lsub _ _)) },\n  { exact lt_max_of_lt_left ((nadd_le_nadd_left hj _).trans_lt (lt_lsub _ _)) },\n  { exact lt_max_of_lt_right ((nadd_le_nadd_left hj _).trans_lt (lt_lsub _ _)) }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ntheorem birthday_add_zero : (a + 0).birthday = a.birthday := by simp\ntheorem birthday_zero_add : (0 + a).birthday = a.birthday := by simp\ntheorem birthday_add_one  : (a + 1).birthday = order.succ a.birthday := by simp\ntheorem birthday_one_add  : (1 + a).birthday = order.succ a.birthday := by simp\n\n@[simp] theorem birthday_nat_cast : \u2200 n : \u2115, birthday n = n\n| 0 := birthday_zero\n| (n + 1) := by simp [birthday_nat_cast]\n\ntheorem birthday_add_nat (n : \u2115) : (a + n).birthday = a.birthday + n := by simp\ntheorem birthday_nat_add (n : \u2115) : (\u2191n + a).birthday = a.birthday + n := by simp\n\nend pgame\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/set_theory/game/birthday.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7287294053371802}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : a + b + c > 0, from sorry,\n  have h2 : a + b + c = 3 * (a + b + c) / 2, from sorry,\n  have h3 : a + b + c = 3 * (a + b + c) / 2, from sorry,\n  have h4 : a + b + c = 3 * (a + b + c) / 2, from sorry,\n  have h5 : a + b + c = 3 * (a + b + c) / 2, from sorry,\n  have h6 : a + b + c = 3 * (a + b + c) / 2, from sorry,\n  have h7 : a + b + c = 3 * (a + b + c) / 2, from sorry,\n\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) : sorry,\nend\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265\n    (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by sorry\n  ... = 9 / 2 : by sorry\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry\n  ... \u2265 3 / ((b + c) + (a + c) + (a + b)) : by sorry\n  ... \u2265 3 / 2 : by sorry,\nend\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)), from sorry,\n  have h2 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) \u2265 ((9 * (a + b + c)) / ((b + c) + (a + c) + (a + b))), from sorry,\n  have h3 : ((9 * (a + b + c)) / ((b + c) + (a + c) + (a + b))) \u2265 (((1 / (b + c)) + (1 / (a + c)) + (1 / (a + b))) / 3), from sorry,\n  have h4 : (((1 / (b + c)) + (1 / (a + c)) + (1 / (a + b))) / 3) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from sorry,\n  have h5 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) \u2265 3, from sorry,\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from sorry,\nend\n\n--OUTPUT 4\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 9 / 2, from sorry,\n  have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 * (a + b + c)) / ((b + c) + (a + c) + (a + b)), from sorry,\n  have h3 : ((1 / (b + c)) + (1 / (a + c)) + (1 / (a + b))) / 3 \u2265 (3 / ((b + c) + (a + c) + (a + b))), from sorry,\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from sorry,\nend\n\n--OUTPUT 5\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) : by {\n    have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b), from sorry,\n    have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2) * ((a + b + c) / ((b + c) + (a + c) + (a + b))), from sorry,\n    have h3 : (a + b + c) / ((b + c) + (a + c) + (a + b)) = (1 / 2), from sorry,\n    show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from sorry,\n  },\nend\n\n--OUTPUT 6\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nby {\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b))\n    \u2265 ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) : sorry\n    ... \u2265 (9 / 2) : sorry\n    ... \u2265 (3 / 2) : sorry,\n}\n\n/--`theorem`\nReal Multiplication Distributes over Addition\nLet $a$, $b$ and $c$ be real numbers.\n\nThen:\n:$a \\cdot \\paren {b + c} = a \\cdot b + a \\cdot c$\n`proof`\n{{begin-eqn}}\n{{eqn | l = a \\cdot \\paren {b + c}\n      | o = =\n      | r = a \\cdot b + a \\cdot c\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = a \\cdot b + a \\cdot c\n      | o = =\n      | r = a \\cdot \\paren {b + c}\n      | c = by commutativity of multiplication\n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem real_multiplication_distributes_over_addition (a b c : \u211d) : a * (b + c) = a * b + a * c :=\nbegin\n  calc a * (b + c) = a * (c + b) : by sorry\n  ... = a * c + a * b : by sorry\n  ... = a * b + a * c : by sorry,\nend\n\n--OUTPUT 7\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b), from sorry,\n  have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 * (a + b + c)) / ( (b + c) + (a + c) + (a + b)), from sorry,\n  have h3 : (9 * (a + b + c)) / ( (b + c) + (a + c) + (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from sorry,\n  have h4 : (3 / ((b + c) + (a + c) + (a + b))) \u2265 (3 / 2), from sorry,\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from sorry,\nend\n\n--OUTPUT 8\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 9 / 2,\n  begin\n    calc (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b)\n    = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by sorry\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by sorry\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by sorry\n    ... \u2265 3 / 2 : by sorry,\n  end,\n\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2),\n  begin\n    calc (a / (b + c)) + (b / (a + c)) + (c / (a + b))\n    = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by sorry\n    ... \u2265 (9 * (a + b + c)) / (2 * (b + c + a + c + a + b)) : by sorry\n    ... \u2265 (9 * (a + b + c)) / (2 * (3 * (a + b + c))) : by sorry\n    ... \u2265 (3 / 2) : by sorry,\n  end,\nend\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from sorry,\n  have h2 : (A \u2229 B) \u2286 A, from sorry,\n  have h3 : (A \u2229 B) \u2286 S, from sorry,\n  show (A \u2229 B) \u2208  \ud835\udcab S, from sorry,\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  calc (x + y)^2 = (x+y)*(x+y) : by sorry\n  ... = x*(x+y) + y*(x+y) : by sorry\n  ... = x*x + x*y + y*x + y*y : by sorry\n  ... = x^2 + 2*x*y + y^2 : by sorry,\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from sorry,\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from sorry,\n\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from sorry,\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from sorry,\n\n  have h5 : \u2200 a : G, classical.some (h3 a) = (1 : G), from sorry,\n  have h6 : \u2200 a : G, classical.some (h4 a) = (1 : G), from sorry,\n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by {\n    use (1 : G),\n    have h7 : \u2200 e : G, (\u2200 a : G, e * a = a \u2227 a * e = a) \u2192 e = 1, from by {\n      assume (e : G) (h7 : \u2200 a : G, e * a = a \u2227 a * e = a),\n      have h8 : \u2200 a : G, e = classical.some (h3 a), from sorry,\n      have h9 : \u2200 a : G, e = classical.some (h4 a), from sorry,\n      show e = (1 : G), from sorry,     \n    },\n    sorry,\n  }\nend\n\n/--`theorem`\nNesbitt's inequality\nLet $a$, $b$ and $c$ be positive real numbers.\n\nThen:\n:$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n\n`proof`\n{{begin-eqn}}\n{{eqn | l = \\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}\n      | o = \\ge\n      | r = \\dfrac 3 2\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac 9 2\n      | c = by adding $3$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3\n      | o = \\ge\n      | r = \\frac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = dividing by $3 \\paren {a + b + c}$\n}}\n{{end-eqn}}\nThese are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n\nFrom Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n\nThus Nesbitt's Inequality holds.\n{{qed}}\n\n-/\ntheorem  nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_outline-Natural-Language-Proof-Translation/Correct_statement-lean_proof_outline-3_few_shot_temperature_0.6_max_tokens_2000_n_8/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417881, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.728729403821569}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nWe prove the orbit counting lemma traditionally attributed to\nBurnside: if a finite group G acts on a finite set X, then \n|G| \u00d7 |X/G| is the sum over `t \u2208 G` of `|X\u1d57|`, where \n`X\u1d57 = { x : t \u2022 x = x }`.  (The normal statement involves \ndividing the above statement by `|G|`, but we avoid that so \nthat we can work everywhere in `\u2115`.)       \n-/\n\nimport data.fintype.basic group_theory.group_action \n algebra.group_power algebra.big_operators.basic data.zmod.basic\nimport tactic.ring\n\nnamespace group_theory\nsection burnside_count\n\nvariables {G : Type*} [group G] [fintype G] [decidable_eq G]\nvariables {X : Type*} [fintype X] [decidable_eq X] [mul_action G X]\n\ninstance : decidable_rel (mul_action.orbit_rel G X).r := \n begin\n  dsimp[mul_action.orbit_rel],\n  intros x y, simp only [],\n  rw [mul_action.mem_orbit_iff],\n  apply_instance\n end \n\nvariables (G X)\ndef orbits := quotient (mul_action.orbit_rel G X)\nvariables {G X}\n\ndef orbit (x : X) : (orbits G X) :=\n @quotient.mk X (mul_action.orbit_rel G X) x\n\nlemma orbit_act : \u2200 (g : G) (x : X), orbit (g \u2022 x) = @orbit G _ _ _ X _ _ _ x := \n \u03bb g x, (@quotient.eq X (mul_action.orbit_rel G X) (g \u2022 x) x).mpr \u27e8g,rfl\u27e9 \n\ninstance : fintype (orbits G X) :=\n by { dsimp[orbits], apply_instance }\n\ninstance : decidable_eq (orbits G X) :=\n by { dsimp[orbits], apply_instance }\n\nvariables (G X)\nstructure transversal := \n(rep : (orbits G X) \u2192 X)\n(actor : X \u2192 G)\n(actor_prop : \u2200 x, (actor x) \u2022 x = rep (orbit x))\nvariables {G X}\n\nlemma orbit_rep (t : transversal G X) (y : orbits G X) :  \n  orbit (t.rep y) = y := \nbegin\n letI s := (mul_action.orbit_rel G X),\n rcases quotient.exists_rep y with \u27e8x,e\u27e9,\n rw[\u2190 e],\n exact calc\n  orbit (t.rep (orbit x)) = orbit ((t.actor x) \u2022 x)\n   : by rw[\u2190 t.actor_prop]\n  ... = orbit x : orbit_act (t.actor x) x,\nend\n\nvariables (G X)\nlemma transversal_exists : nonempty (transversal G X) := \nbegin\n letI s := (mul_action.orbit_rel G X),\n let rep : (orbits G X) \u2192 X := quotient.out,\n have exists_actor : \n  \u2200 x, \u2203 g, g \u2022 x = rep (orbit x) := \n   \u03bb x,quotient.eq.mp (quotient.out_eq (orbit x)),\n rcases (classical.skolem.mp exists_actor) with \u27e8actor,actor_prop\u27e9,\n exact \u27e8\u27e8rep,actor,actor_prop\u27e9\u27e9\nend\nvariables {G X}\n\nvariable (X)\n\ndef el_fixed_points (g : G) : finset X := \n finset.univ.filter (\u03bb x,g \u2022 x = x)\n\nvariable {X}\n\nlemma burnside_count :\n (fintype.card G) * (fintype.card (orbits G X)) = \n  (@finset.univ G _).sum (\u03bb g, finset.card (el_fixed_points X g)) := \nbegin \n rcases (transversal_exists G X) with \u27e8t\u27e9,\n let V : G \u2192 Type* := \u03bb g, { x : X // g \u2022 x = x },\n have V_mem : \u2200 (g : G) (x : X), (x \u2208 el_fixed_points X g) \u2194 g \u2022 x = x := \n  \u03bb g x,by {simp[el_fixed_points]},\n have V_card : \u2200 (g : G), fintype.card (V g) = finset.card (el_fixed_points X g) := \n  \u03bb g, by {apply fintype.subtype_card,},\n let U := \u03a3 g, (V g),\n have U_eq : \u2200 u\u2080 u\u2081 : U, u\u2080.fst = u\u2081.fst \u2192 u\u2080.snd.val = u\u2081.snd.val \u2192 u\u2080 = u\u2081 := \n  \u03bb \u27e8h\u2080,\u27e8x\u2080,e\u2080\u27e9\u27e9 \u27e8h\u2081,\u27e8x\u2081,e\u2081\u27e9\u27e9 hh hx, \n   begin \n    replace hh : h\u2080 = h\u2081 := hh,\n    replace hx : x\u2080 = x\u2081 := hx,\n    rcases hh, congr, assumption,\n   end,\n let p : G \u00d7 (orbits G X) \u2192 U := \n  \u03bb \u27e8g,y\u27e9,\u27e8g * (t.actor (g \u2022 (t.rep y))),\u27e8g \u2022 (t.rep y),begin\n   change (g * (t.actor (g \u2022 (t.rep y)))) \u2022 (g \u2022 (t.rep y)) = g \u2022 (t.rep y),\n   rw[mul_smul g _ (g \u2022 (t.rep y))],\n   rw[t.actor_prop,orbit_act,orbit_rep t],\n  end\u27e9\u27e9,\n let q : U \u2192 G \u00d7 (orbits G X) := \n  \u03bb \u27e8h,\u27e8x,e\u27e9\u27e9,\u27e8h * (t.actor x)\u207b\u00b9,orbit x\u27e9,\n have pq : \u2200 u, p (q u) = u := \n   \u03bb \u27e8h,\u27e8x,e\u27e9\u27e9, begin\n   let a := t.actor x,\n   let g := h * a\u207b\u00b9,\n   let y := orbit x,\n   let x' := g \u2022 (t.rep y),\n   have ex : x' = x := calc\n    x' = (h * a\u207b\u00b9) \u2022 (t.rep (orbit x)) : rfl\n     ... = (h * a\u207b\u00b9) \u2022 (a \u2022 x) : by rw[\u2190 t.actor_prop x]\n     ... = h \u2022 x : by rw[\u2190 mul_smul,mul_assoc,mul_left_inv,mul_one]\n     ... = x : e, \n   have eh : g * (t.actor x') = h := \n    by {rw[ex,mul_assoc,mul_left_inv a,mul_one],},\n   apply U_eq,exact eh,exact ex,\n  end,\n have qp : \u2200 v : G \u00d7 (orbits G X), q (p v) = v :=\n   \u03bb \u27e8g,y\u27e9, begin\n    let x := t.rep y,\n    let x' := g \u2022 x,\n    let a := t.actor x',\n    change (prod.mk ((g * a) * a\u207b\u00b9) (orbit x')) = (prod.mk g y),\n    have : orbit x' = y := by { rw[orbit_act,orbit_rep],},\n    rw[this,mul_assoc,mul_right_inv,mul_one],\n   end,\n exact calc\n  (fintype.card G) * (fintype.card (orbits G X)) \n   = fintype.card (G \u00d7 (orbits G X)) : (fintype.card_prod _ _).symm\n   ... = fintype.card U : fintype.card_congr \u27e8p,q,qp,pq\u27e9\n   ... = (@finset.univ G _).sum (\u03bb g, fintype.card (V g)) : \n          fintype.card_sigma V\n   ... = (@finset.univ G _).sum (\u03bb g, finset.card (el_fixed_points X g)) : \n          finset.sum_congr rfl (\u03bb g _, V_card g),\nend\n\nend burnside_count\nend group_theory\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/group_theory/burnside_count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7287294016842502}}
{"text": "/-\nCopyright (c) 2021 Paula Neeley. All rights reserved.\nAuthor: Paula Neeley\n-/\n\nimport data.list data.set.basic\n\nvariable {\u03b1 : Type*}\n\n\ndef path (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : \u03b1 \u2192 list \u03b1 \u2192 Prop\n| x []      := true\n| x (y::ys) := R x y \u2227 path y ys\n\n\ndef last (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : \u03b1 \u2192 list \u03b1 \u2192 \u03b1\n| x []      := x\n| x (y::ys) := last y ys\n\n\ndef reachable (R : \u03b1 \u2192 \u03b1 \u2192 Prop) (x y : \u03b1) : Prop := \u2203 l : list \u03b1, path R x l \u2227 last R x l = y\n\n\n---------------------- Lemmas about R* ----------------------\n\nlemma reach_right : \u2200 x y z : \u03b1, \u2200 R : \u03b1 \u2192 \u03b1 \u2192 Prop, \n  reachable R x y \u2227 R y z \u2192 reachable R x z :=\nbegin\nintros x y z R h1, cases h1 with h1 h2,\ncases h1 with l h1,\nrevert x, induction l, \n{intros x h, cases h\nwith h1 h3, rw last at h3, existsi ([z] : list \u03b1),\nsplit, split, apply eq.subst h3.symm, exact h2,\ntrivial, repeat {rw last}}, \n{intros x h1, cases h1 with h1 h3,\ncases h1 with h1 h4,\nhave h5 := l_ih l_hd (and.intro h4 h3), \ncases h5 with l h5,\nexistsi (l_hd::l : list \u03b1), split, \nexact and.intro h1 h5.left,\nexact h5.right} \nend\n\n\nlemma ref_close : \u2200 x : \u03b1, \u2200 R : \u03b1 \u2192 \u03b1 \u2192 Prop, reachable R x x :=\nbegin\nintros x R,\nexistsi ([] : list \u03b1),\nsplit,\ntrivial, \nrw last\nend\n\n\nlemma trans_close : \u2200 x y z : \u03b1, \u2200 R : \u03b1 \u2192 \u03b1 \u2192 Prop, \n  reachable R x y \u2227 reachable R y z \u2192 reachable R x z :=\nbegin\nintros x y z R h,\ncases h with h1 h2,\ncases h1 with l1 h1,\ncases h2 with l2 h2,\nrevert x y z,\ninduction l1, \n{intros x y z h1 h2, cases h1 with h1 h3, cases h2 with h2 h4,\nrw last at h3, existsi (l2 : list \u03b1), split, apply eq.subst h3.symm,\nexact h2, apply eq.subst h3.symm, exact h4},\n{intros x y z h1 h2, cases h1 with h1 h3, cases h2 with h2 h4,\ncases h1 with h1 h5,\nhave h6 := l1_ih l1_hd y z (and.intro h5 h3) (and.intro h2 h4), \ncases h6 with l h6,\nexistsi (l1_hd::l : list \u03b1), split, split, \nexact h1, exact h6.left, exact h6.right}\nend\n\n\nlemma containsR : \u2200 x y : \u03b1, \u2200 R : \u03b1 \u2192 \u03b1 \u2192 Prop, R x y \u2192 reachable R x y :=\nbegin\nintros x y R h,\nexistsi ([y] : list \u03b1),\nsplit, split,\nexact h, trivial,\nrepeat {rw last}\nend\n\n\nopen set\n\n\nlemma smallest (R S : \u03b1 \u2192 \u03b1 \u2192 Prop) (reflS : reflexive S) (transS : transitive S) : \n  (\u2200 x y : \u03b1, R x y \u2192 S x y) \u2192 (\u2200 x y : \u03b1, reachable R x y \u2192 S x y) :=\nbegin\nintros h1 x z h2,\ncases h2 with l h2, \ncases h2 with h2 h3, \nrevert x z, induction l, \n{intros x z h2 h3,\napply eq.subst h3, exact reflS x},\n{intros x z h2 h3, cases h2 with h2 h4, \nexact (transS ((h1 x) l_hd h2)) (l_ih l_hd z h4 h3)}\nend\n\n\n\n\n\n", "meta": {"author": "paulaneeley", "repo": "modal", "sha": "ee5d149d4ecb337005b850bddf4453e56a5daf04", "save_path": "github-repos/lean/paulaneeley-modal", "path": "github-repos/lean/paulaneeley-modal/modal-ee5d149d4ecb337005b850bddf4453e56a5daf04/src/basicmodal/paths.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7287294013112258}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Floris van Doorn, Violeta Hern\u00e1ndez Palacios\n-/\nimport set_theory.ordinal.basic\nimport tactic.by_contra\n\n/-!\n# Ordinal arithmetic\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nOrdinals have an addition (corresponding to disjoint union) that turns them into an additive\nmonoid, and a multiplication (corresponding to the lexicographic order on the product) that turns\nthem into a monoid. One can also define correspondingly a subtraction, a division, a successor\nfunction, a power function and a logarithm function.\n\nWe also define limit ordinals and prove the basic induction principle on ordinals separating\nsuccessor ordinals and limit ordinals, in `limit_rec_on`.\n\n## Main definitions and results\n\n* `o\u2081 + o\u2082` is the order on the disjoint union of `o\u2081` and `o\u2082` obtained by declaring that\n  every element of `o\u2081` is smaller than every element of `o\u2082`.\n* `o\u2081 - o\u2082` is the unique ordinal `o` such that `o\u2082 + o = o\u2081`, when `o\u2082 \u2264 o\u2081`.\n* `o\u2081 * o\u2082` is the lexicographic order on `o\u2082 \u00d7 o\u2081`.\n* `o\u2081 / o\u2082` is the ordinal `o` such that `o\u2081 = o\u2082 * o + o'` with `o' < o\u2082`. We also define the\n  divisibility predicate, and a modulo operation.\n* `order.succ o = o + 1` is the successor of `o`.\n* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.\n\nWe discuss the properties of casts of natural numbers of and of `\u03c9` with respect to these\noperations.\n\nSome properties of the operations are also used to discuss general tools on ordinals:\n\n* `is_limit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.\n* `limit_rec_on` is the main induction principle of ordinals: if one can prove a property by\n  induction at successor ordinals and at limit ordinals, then it holds for all ordinals.\n* `is_normal`: a function `f : ordinal \u2192 ordinal` satisfies `is_normal` if it is strictly increasing\n  and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for\n  `a < o`.\n* `enum_ord`: enumerates an unbounded set of ordinals by the ordinals themselves.\n* `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in\n  `Type u`, as an ordinal in `Type u`.\n* `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals\n  less than a given ordinal `o`.\n\nVarious other basic arithmetic results are given in `principal.lean` instead.\n-/\n\nnoncomputable theory\n\nopen function cardinal set equiv order\nopen_locale classical cardinal ordinal\n\nuniverses u v w\n\nnamespace ordinal\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\n  {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop} {t : \u03b3 \u2192 \u03b3 \u2192 Prop}\n\n/-! ### Further properties of addition on ordinals -/\n\n@[simp] theorem lift_add (a b) : lift (a + b) = lift a + lift b :=\nquotient.induction_on\u2082 a b $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9,\nquotient.sound \u27e8(rel_iso.preimage equiv.ulift _).trans\n (rel_iso.sum_lex_congr (rel_iso.preimage equiv.ulift _)\n   (rel_iso.preimage equiv.ulift _)).symm\u27e9\n\n@[simp] theorem lift_succ (a) : lift (succ a) = succ (lift a) :=\nby { rw [\u2190add_one_eq_succ, lift_add, lift_one], refl }\n\ninstance add_contravariant_class_le : contravariant_class ordinal.{u} ordinal.{u} (+) (\u2264) :=\n\u27e8\u03bb a b c, induction_on a $ \u03bb \u03b1 r hr, induction_on b $ \u03bb \u03b2\u2081 s\u2081 hs\u2081, induction_on c $ \u03bb \u03b2\u2082 s\u2082 hs\u2082 \u27e8f\u27e9,\n  \u27e8have fl : \u2200 a, f (sum.inl a) = sum.inl a := \u03bb a,\n    by simpa only [initial_seg.trans_apply, initial_seg.le_add_apply]\n      using @initial_seg.eq _ _ _ _ (@sum.lex.is_well_order _ _ _ _ hr hs\u2082)\n        ((initial_seg.le_add r s\u2081).trans f) (initial_seg.le_add r s\u2082) a,\n  have \u2200 b, {b' // f (sum.inr b) = sum.inr b'}, begin\n    intro b, cases e : f (sum.inr b),\n    { rw \u2190 fl at e, have := f.inj' e, contradiction },\n    { exact \u27e8_, rfl\u27e9 }\n  end,\n  let g (b) := (this b).1 in\n  have fr : \u2200 b, f (sum.inr b) = sum.inr (g b), from \u03bb b, (this b).2,\n  \u27e8\u27e8\u27e8g, \u03bb x y h, by injection f.inj'\n    (by rw [fr, fr, h] : f (sum.inr x) = f (sum.inr y))\u27e9,\n    \u03bb a b, by simpa only [sum.lex_inr_inr, fr, rel_embedding.coe_fn_to_embedding,\n        initial_seg.coe_fn_to_rel_embedding, embedding.coe_fn_mk]\n      using @rel_embedding.map_rel_iff _ _ _ _ f.to_rel_embedding (sum.inr a) (sum.inr b)\u27e9,\n    \u03bb a b H, begin\n      rcases f.init (by rw fr; exact sum.lex_inr_inr.2 H) with \u27e8a'|a', h\u27e9,\n      { rw fl at h, cases h },\n      { rw fr at h, exact \u27e8a', sum.inr.inj h\u27e9 }\n    end\u27e9\u27e9\u27e9\n\ntheorem add_left_cancel (a) {b c : ordinal} : a + b = a + c \u2194 b = c :=\nby simp only [le_antisymm_iff, add_le_add_iff_left]\n\nprivate theorem add_lt_add_iff_left' (a) {b c : ordinal} : a + b < a + c \u2194 b < c :=\nby rw [\u2190 not_le, \u2190 not_le, add_le_add_iff_left]\n\ninstance add_covariant_class_lt : covariant_class ordinal.{u} ordinal.{u} (+) (<) :=\n\u27e8\u03bb a b c, (add_lt_add_iff_left' a).2\u27e9\n\ninstance add_contravariant_class_lt : contravariant_class ordinal.{u} ordinal.{u} (+) (<) :=\n\u27e8\u03bb a b c, (add_lt_add_iff_left' a).1\u27e9\n\ninstance add_swap_contravariant_class_lt :\n  contravariant_class ordinal.{u} ordinal.{u} (swap (+)) (<) :=\n\u27e8\u03bb a b c, lt_imp_lt_of_le_imp_le (\u03bb h, add_le_add_right h _)\u27e9\n\ntheorem add_le_add_iff_right {a b : ordinal} : \u2200 n : \u2115, a + n \u2264 b + n \u2194 a \u2264 b\n| 0     := by simp\n| (n+1) := by rw [nat_cast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]\n\ntheorem add_right_cancel {a b : ordinal} (n : \u2115) : a + n = b + n \u2194 a = b :=\nby simp only [le_antisymm_iff, add_le_add_iff_right]\n\ntheorem add_eq_zero_iff {a b : ordinal} : a + b = 0 \u2194 (a = 0 \u2227 b = 0) :=\ninduction_on a $ \u03bb \u03b1 r _, induction_on b $ \u03bb \u03b2 s _, begin\n  simp_rw [\u2190type_sum_lex, type_eq_zero_iff_is_empty],\n  exact is_empty_sum\nend\n\ntheorem left_eq_zero_of_add_eq_zero {a b : ordinal} (h : a + b = 0) : a = 0 :=\n(add_eq_zero_iff.1 h).1\n\ntheorem right_eq_zero_of_add_eq_zero {a b : ordinal} (h : a + b = 0) : b = 0 :=\n(add_eq_zero_iff.1 h).2\n\n/-! ### The predecessor of an ordinal -/\n\n/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,\n  and `o` otherwise. -/\ndef pred (o : ordinal) : ordinal :=\nif h : \u2203 a, o = succ a then classical.some h else o\n\n@[simp] theorem pred_succ (o) : pred (succ o) = o :=\nby have h : \u2203 a, succ o = succ a := \u27e8_, rfl\u27e9;\n   simpa only [pred, dif_pos h] using (succ_injective $ classical.some_spec h).symm\n\ntheorem pred_le_self (o) : pred o \u2264 o :=\nif h : \u2203 a, o = succ a then let \u27e8a, e\u27e9 := h in\nby rw [e, pred_succ]; exact le_succ a\nelse by rw [pred, dif_neg h]\n\ntheorem pred_eq_iff_not_succ {o} : pred o = o \u2194 \u00ac \u2203 a, o = succ a :=\n\u27e8\u03bb e \u27e8a, e'\u27e9, by rw [e', pred_succ] at e; exact (lt_succ a).ne e,\n \u03bb h, dif_neg h\u27e9\n\ntheorem pred_eq_iff_not_succ' {o} : pred o = o \u2194 \u2200 a, o \u2260 succ a :=\nby simpa using pred_eq_iff_not_succ\n\ntheorem pred_lt_iff_is_succ {o} : pred o < o \u2194 \u2203 a, o = succ a :=\niff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le])\n  (iff_not_comm.1 pred_eq_iff_not_succ).symm\n\n@[simp] theorem pred_zero : pred 0 = 0 :=\npred_eq_iff_not_succ'.2 $ \u03bb a, (succ_ne_zero a).symm\n\ntheorem succ_pred_iff_is_succ {o} : succ (pred o) = o \u2194 \u2203 a, o = succ a :=\n\u27e8\u03bb e, \u27e8_, e.symm\u27e9, \u03bb \u27e8a, e\u27e9, by simp only [e, pred_succ]\u27e9\n\ntheorem succ_lt_of_not_succ {o b : ordinal} (h : \u00ac \u2203 a, o = succ a) : succ b < o \u2194 b < o :=\n\u27e8(lt_succ b).trans, \u03bb l, lt_of_le_of_ne (succ_le_of_lt l) (\u03bb e, h \u27e8_, e.symm\u27e9)\u27e9\n\ntheorem lt_pred {a b} : a < pred b \u2194 succ a < b :=\nif h : \u2203 a, b = succ a then let \u27e8c, e\u27e9 := h in\nby rw [e, pred_succ, succ_lt_succ_iff]\nelse by simp only [pred, dif_neg h, succ_lt_of_not_succ h]\n\ntheorem pred_le {a b} : pred a \u2264 b \u2194 a \u2264 succ b :=\nle_iff_le_iff_lt_iff_lt.2 lt_pred\n\n@[simp] theorem lift_is_succ {o} : (\u2203 a, lift o = succ a) \u2194 (\u2203 a, o = succ a) :=\n\u27e8\u03bb \u27e8a, h\u27e9,\n  let \u27e8b, e\u27e9 := lift_down $ show a \u2264 lift o, from le_of_lt $\n    h.symm \u25b8 lt_succ a in\n  \u27e8b, lift_inj.1 $ by rw [h, \u2190 e, lift_succ]\u27e9,\n \u03bb \u27e8a, h\u27e9, \u27e8lift a, by simp only [h, lift_succ]\u27e9\u27e9\n\n@[simp] theorem lift_pred (o) : lift (pred o) = pred (lift o) :=\nif h : \u2203 a, o = succ a then\nby cases h with a e; simp only [e, pred_succ, lift_succ]\nelse by rw [pred_eq_iff_not_succ.2 h,\n            pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]\n\n/-! ### Limit ordinals -/\n\n/-- A limit ordinal is an ordinal which is not zero and not a successor. -/\ndef is_limit (o : ordinal) : Prop := o \u2260 0 \u2227 \u2200 a < o, succ a < o\n\ntheorem is_limit.succ_lt {o a : ordinal} (h : is_limit o) : a < o \u2192 succ a < o :=\nh.2 a\n\ntheorem not_zero_is_limit : \u00ac is_limit 0\n| \u27e8h, _\u27e9 := h rfl\n\ntheorem not_succ_is_limit (o) : \u00ac is_limit (succ o)\n| \u27e8_, h\u27e9 := lt_irrefl _ (h _ (lt_succ o))\n\ntheorem not_succ_of_is_limit {o} (h : is_limit o) : \u00ac \u2203 a, o = succ a\n| \u27e8a, e\u27e9 := not_succ_is_limit a (e \u25b8 h)\n\ntheorem succ_lt_of_is_limit {o a : ordinal} (h : is_limit o) : succ a < o \u2194 a < o :=\n\u27e8(lt_succ a).trans, h.2 _\u27e9\n\ntheorem le_succ_of_is_limit {o} (h : is_limit o) {a} : o \u2264 succ a \u2194 o \u2264 a :=\nle_iff_le_iff_lt_iff_lt.2 $ succ_lt_of_is_limit h\n\ntheorem limit_le {o} (h : is_limit o) {a} : o \u2264 a \u2194 \u2200 x < o, x \u2264 a :=\n\u27e8\u03bb h x l, l.le.trans h,\n \u03bb H, (le_succ_of_is_limit h).1 $ le_of_not_lt $ \u03bb hn,\n  not_lt_of_le (H _ hn) (lt_succ a)\u27e9\n\ntheorem lt_limit {o} (h : is_limit o) {a} : a < o \u2194 \u2203 x < o, a < x :=\nby simpa only [not_ball, not_le] using not_congr (@limit_le _ h a)\n\n@[simp] theorem lift_is_limit (o) : is_limit (lift o) \u2194 is_limit o :=\nand_congr (not_congr $ by simpa only [lift_zero] using @lift_inj o 0)\n\u27e8\u03bb H a h, lift_lt.1 $ by simpa only [lift_succ] using H _ (lift_lt.2 h),\n \u03bb H a h, begin\n   obtain \u27e8a', rfl\u27e9 := lift_down h.le,\n   rw [\u2190lift_succ, lift_lt],\n   exact H a' (lift_lt.1 h)\n end\u27e9\n\ntheorem is_limit.pos {o : ordinal} (h : is_limit o) : 0 < o :=\nlt_of_le_of_ne (ordinal.zero_le _) h.1.symm\n\ntheorem is_limit.one_lt {o : ordinal} (h : is_limit o) : 1 < o :=\nby simpa only [succ_zero] using h.2 _ h.pos\n\n\n\ntheorem zero_or_succ_or_limit (o : ordinal) :\n  o = 0 \u2228 (\u2203 a, o = succ a) \u2228 is_limit o :=\nif o0 : o = 0 then or.inl o0 else\nif h : \u2203 a, o = succ a then or.inr (or.inl h) else\nor.inr $ or.inr \u27e8o0, \u03bb a, (succ_lt_of_not_succ h).2\u27e9\n\n/-- Main induction principle of ordinals: if one can prove a property by\n  induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/\n@[elab_as_eliminator] def limit_rec_on {C : ordinal \u2192 Sort*}\n  (o : ordinal) (H\u2081 : C 0) (H\u2082 : \u2200 o, C o \u2192 C (succ o))\n  (H\u2083 : \u2200 o, is_limit o \u2192 (\u2200 o' < o, C o') \u2192 C o) : C o :=\nlt_wf.fix (\u03bb o IH,\n  if o0 : o = 0 then by rw o0; exact H\u2081 else\n  if h : \u2203 a, o = succ a then\n    by rw \u2190 succ_pred_iff_is_succ.2 h; exact\n    H\u2082 _ (IH _ $ pred_lt_iff_is_succ.2 h)\n  else H\u2083 _ \u27e8o0, \u03bb a, (succ_lt_of_not_succ h).2\u27e9 IH) o\n\n@[simp] theorem limit_rec_on_zero {C} (H\u2081 H\u2082 H\u2083) : @limit_rec_on C 0 H\u2081 H\u2082 H\u2083 = H\u2081 :=\nby rw [limit_rec_on, lt_wf.fix_eq, dif_pos rfl]; refl\n\n@[simp] theorem limit_rec_on_succ {C} (o H\u2081 H\u2082 H\u2083) :\n  @limit_rec_on C (succ o) H\u2081 H\u2082 H\u2083 = H\u2082 o (@limit_rec_on C o H\u2081 H\u2082 H\u2083) :=\nbegin\n  have h : \u2203 a, succ o = succ a := \u27e8_, rfl\u27e9,\n  rw [limit_rec_on, lt_wf.fix_eq, dif_neg (succ_ne_zero o), dif_pos h],\n  generalize : limit_rec_on._proof_2 (succ o) h = h\u2082,\n  generalize : limit_rec_on._proof_3 (succ o) h = h\u2083,\n  revert h\u2082 h\u2083, generalize e : pred (succ o) = o', intros,\n  rw pred_succ at e, subst o', refl\nend\n\n@[simp] theorem limit_rec_on_limit {C} (o H\u2081 H\u2082 H\u2083 h) :\n  @limit_rec_on C o H\u2081 H\u2082 H\u2083 = H\u2083 o h (\u03bb x h, @limit_rec_on C x H\u2081 H\u2082 H\u2083) :=\nby rw [limit_rec_on, lt_wf.fix_eq, dif_neg h.1, dif_neg (not_succ_of_is_limit h)]; refl\n\ninstance order_top_out_succ (o : ordinal) : order_top (succ o).out.\u03b1 :=\n\u27e8_, le_enum_succ\u27e9\n\ntheorem enum_succ_eq_top {o : ordinal} :\n  enum (<) o (by { rw type_lt, exact lt_succ o }) = (\u22a4 : (succ o).out.\u03b1) :=\nrfl\n\nlemma has_succ_of_type_succ_lt {\u03b1} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [wo : is_well_order \u03b1 r]\n  (h : \u2200 a < type r, succ a < type r) (x : \u03b1) : \u2203 y, r x y :=\nbegin\n  use enum r (succ (typein r x)) (h _ (typein_lt_type r x)),\n  convert (enum_lt_enum (typein_lt_type r x) _).mpr (lt_succ _), rw [enum_typein]\nend\n\ntheorem out_no_max_of_succ_lt {o : ordinal} (ho : \u2200 a < o, succ a < o) : no_max_order o.out.\u03b1 :=\n\u27e8has_succ_of_type_succ_lt (by rwa type_lt)\u27e9\n\nlemma bounded_singleton {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_well_order \u03b1 r] (hr : (type r).is_limit) (x) :\n  bounded r {x} :=\nbegin\n  refine \u27e8enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), _\u27e9,\n  intros b hb,\n  rw mem_singleton_iff.1 hb,\n  nth_rewrite 0 \u2190enum_typein r x,\n  rw @enum_lt_enum _ r,\n  apply lt_succ\nend\n\nlemma type_subrel_lt (o : ordinal.{u}) :\n  type (subrel (<) {o' : ordinal | o' < o}) = ordinal.lift.{u+1} o :=\nbegin\n  refine quotient.induction_on o _,\n  rintro \u27e8\u03b1, r, wo\u27e9, resetI, apply quotient.sound,\n  constructor, symmetry, refine (rel_iso.preimage equiv.ulift r).trans (enum_iso r).symm\nend\n\nlemma mk_initial_seg (o : ordinal.{u}) :\n  #{o' : ordinal | o' < o} = cardinal.lift.{u+1} o.card :=\nby rw [lift_card, \u2190type_subrel_lt, card_type]\n\n/-! ### Normal ordinal functions -/\n\n/-- A normal ordinal function is a strictly increasing function which is\n  order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for\n  `a < o`.  -/\ndef is_normal (f : ordinal \u2192 ordinal) : Prop :=\n(\u2200 o, f o < f (succ o)) \u2227 \u2200 o, is_limit o \u2192 \u2200 a, f o \u2264 a \u2194 \u2200 b < o, f b \u2264 a\n\ntheorem is_normal.limit_le {f} (H : is_normal f) : \u2200 {o}, is_limit o \u2192\n  \u2200 {a}, f o \u2264 a \u2194 \u2200 b < o, f b \u2264 a := H.2\n\ntheorem is_normal.limit_lt {f} (H : is_normal f) {o} (h : is_limit o) {a} :\n  a < f o \u2194 \u2203 b < o, a < f b :=\nnot_iff_not.1 $ by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a\n\ntheorem is_normal.strict_mono {f} (H : is_normal f) : strict_mono f :=\n\u03bb a b, limit_rec_on b (not.elim (not_lt_of_le $ ordinal.zero_le _))\n  (\u03bb b IH h, (lt_or_eq_of_le (le_of_lt_succ h)).elim\n    (\u03bb h, (IH h).trans (H.1 _))\n    (\u03bb e, e \u25b8 H.1 _))\n  (\u03bb b l IH h, lt_of_lt_of_le (H.1 a)\n    ((H.2 _ l _).1 le_rfl _ (l.2 _ h)))\n\ntheorem is_normal.monotone {f} (H : is_normal f) : monotone f :=\nH.strict_mono.monotone\n\ntheorem is_normal_iff_strict_mono_limit (f : ordinal \u2192 ordinal) :\n  is_normal f \u2194 (strict_mono f \u2227 \u2200 o, is_limit o \u2192 \u2200 a, (\u2200 b < o, f b \u2264 a) \u2192 f o \u2264 a) :=\n\u27e8\u03bb hf, \u27e8hf.strict_mono, \u03bb a ha c, (hf.2 a ha c).2\u27e9, \u03bb \u27e8hs, hl\u27e9, \u27e8\u03bb a, hs (lt_succ a),\n  \u03bb a ha c, \u27e8\u03bb hac b hba, ((hs hba).trans_le hac).le, hl a ha c\u27e9\u27e9\u27e9\n\ntheorem is_normal.lt_iff {f} (H : is_normal f) {a b} : f a < f b \u2194 a < b :=\nstrict_mono.lt_iff_lt $ H.strict_mono\n\ntheorem is_normal.le_iff {f} (H : is_normal f) {a b} : f a \u2264 f b \u2194 a \u2264 b :=\nle_iff_le_iff_lt_iff_lt.2 H.lt_iff\n\ntheorem is_normal.inj {f} (H : is_normal f) {a b} : f a = f b \u2194 a = b :=\nby simp only [le_antisymm_iff, H.le_iff]\n\ntheorem is_normal.self_le {f} (H : is_normal f) (a) : a \u2264 f a :=\nlt_wf.self_le_of_strict_mono H.strict_mono a\n\ntheorem is_normal.le_set {f o} (H : is_normal f) (p : set ordinal) (p0 : p.nonempty) (b)\n  (H\u2082 : \u2200 o, b \u2264 o \u2194 \u2200 a \u2208 p, a \u2264 o) : f b \u2264 o \u2194 \u2200 a \u2208 p, f a \u2264 o :=\n\u27e8\u03bb h a pa, (H.le_iff.2 ((H\u2082 _).1 le_rfl _ pa)).trans h,\n\u03bb h, begin\n  revert H\u2082, refine limit_rec_on b (\u03bb H\u2082, _) (\u03bb S _ H\u2082, _) (\u03bb S L _ H\u2082, (H.2 _ L _).2 (\u03bb a h', _)),\n  { cases p0 with x px,\n    have := ordinal.le_zero.1 ((H\u2082 _).1 (ordinal.zero_le _) _ px),\n    rw this at px, exact h _ px },\n  { rcases not_ball.1 (mt (H\u2082 S).2 $ (lt_succ S).not_le) with \u27e8a, h\u2081, h\u2082\u27e9,\n    exact (H.le_iff.2 $ succ_le_of_lt $ not_le.1 h\u2082).trans (h _ h\u2081) },\n  { rcases not_ball.1 (mt (H\u2082 a).2 h'.not_le) with \u27e8b, h\u2081, h\u2082\u27e9,\n    exact (H.le_iff.2 $ (not_le.1 h\u2082).le).trans (h _ h\u2081) }\nend\u27e9\n\ntheorem is_normal.le_set' {f o} (H : is_normal f) (p : set \u03b1) (p0 : p.nonempty) (g : \u03b1 \u2192 ordinal)\n  (b) (H\u2082 : \u2200 o, b \u2264 o \u2194 \u2200 a \u2208 p, g a \u2264 o) : f b \u2264 o \u2194 \u2200 a \u2208 p, f (g a) \u2264 o :=\nby simpa [H\u2082] using H.le_set (g '' p) (p0.image g) b\n\ntheorem is_normal.refl : is_normal id := \u27e8lt_succ, \u03bb o l a, limit_le l\u27e9\n\ntheorem is_normal.trans {f g} (H\u2081 : is_normal f) (H\u2082 : is_normal g) : is_normal (f \u2218 g) :=\n\u27e8\u03bb x, H\u2081.lt_iff.2 (H\u2082.1 _), \u03bb o l a, H\u2081.le_set' (< o) \u27e8_, l.pos\u27e9 g _ (\u03bb c, H\u2082.2 _ l _)\u27e9\n\ntheorem is_normal.is_limit {f} (H : is_normal f) {o} (l : is_limit o) : is_limit (f o) :=\n\u27e8ne_of_gt $ (ordinal.zero_le _).trans_lt $ H.lt_iff.2 l.pos,\n\u03bb a h, let \u27e8b, h\u2081, h\u2082\u27e9 := (H.limit_lt l).1 h in\n  (succ_le_of_lt h\u2082).trans_lt (H.lt_iff.2 h\u2081)\u27e9\n\ntheorem is_normal.le_iff_eq {f} (H : is_normal f) {a} : f a \u2264 a \u2194 f a = a := (H.self_le a).le_iff_eq\n\ntheorem add_le_of_limit {a b c : ordinal} (h : is_limit b) : a + b \u2264 c \u2194 \u2200 b' < b, a + b' \u2264 c :=\n\u27e8\u03bb h b' l, (add_le_add_left l.le _).trans h,\n\u03bb H, le_of_not_lt $\ninduction_on a (\u03bb \u03b1 r _, induction_on b $ \u03bb \u03b2 s _ h H l, begin\n  resetI,\n  suffices : \u2200 x : \u03b2, sum.lex r s (sum.inr x) (enum _ _ l),\n  { cases enum _ _ l with x x,\n    { cases this (enum s 0 h.pos) },\n    { exact irrefl _ (this _) } },\n  intros x,\n  rw [\u2190typein_lt_typein (sum.lex r s), typein_enum],\n  have := H _ (h.2 _ (typein_lt_type s x)),\n  rw [add_succ, succ_le_iff] at this,\n  refine (rel_embedding.of_monotone (\u03bb a, _) (\u03bb a b, _)).ordinal_type_le.trans_lt this,\n  { rcases a with \u27e8a | b, h\u27e9,\n    { exact sum.inl a },\n    { exact sum.inr \u27e8b, by cases h; assumption\u27e9 } },\n  { rcases a with \u27e8a | a, h\u2081\u27e9; rcases b with \u27e8b | b, h\u2082\u27e9; cases h\u2081; cases h\u2082;\n      rintro \u27e8\u27e9; constructor; assumption }\nend) h H\u27e9\n\ntheorem add_is_normal (a : ordinal) : is_normal ((+) a) :=\n\u27e8\u03bb b, (add_lt_add_iff_left a).2 (lt_succ b),\n \u03bb b l c, add_le_of_limit l\u27e9\n\ntheorem add_is_limit (a) {b} : is_limit b \u2192 is_limit (a + b) :=\n(add_is_normal a).is_limit\n\nalias add_is_limit \u2190 is_limit.add\n\n/-! ### Subtraction on ordinals-/\n\n/-- The set in the definition of subtraction is nonempty. -/\ntheorem sub_nonempty {a b : ordinal} : {o | a \u2264 b + o}.nonempty :=\n\u27e8a, le_add_left _ _\u27e9\n\n/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b \u2264 a`. -/\ninstance : has_sub ordinal := \u27e8\u03bb a b, Inf {o | a \u2264 b + o}\u27e9\n\ntheorem le_add_sub (a b : ordinal) : a \u2264 b + (a - b) :=\nInf_mem sub_nonempty\n\ntheorem sub_le {a b c : ordinal} : a - b \u2264 c \u2194 a \u2264 b + c :=\n\u27e8\u03bb h, (le_add_sub a b).trans (add_le_add_left h _), \u03bb h, cInf_le' h\u27e9\n\ntheorem lt_sub {a b c : ordinal} : a < b - c \u2194 c + a < b :=\nlt_iff_lt_of_le_iff_le sub_le\n\ntheorem add_sub_cancel (a b : ordinal) : a + b - a = b :=\nle_antisymm (sub_le.2 $ le_rfl)\n  ((add_le_add_iff_left a).1 $ le_add_sub _ _)\n\ntheorem sub_eq_of_add_eq {a b c : ordinal} (h : a + b = c) : c - a = b :=\nh \u25b8 add_sub_cancel _ _\n\ntheorem sub_le_self (a b : ordinal) : a - b \u2264 a :=\nsub_le.2 $ le_add_left _ _\n\nprotected theorem add_sub_cancel_of_le {a b : ordinal} (h : b \u2264 a) : b + (a - b) = a :=\n(le_add_sub a b).antisymm' begin\n  rcases zero_or_succ_or_limit (a-b) with e|\u27e8c,e\u27e9|l,\n  { simp only [e, add_zero, h] },\n  { rw [e, add_succ, succ_le_iff, \u2190 lt_sub, e], exact lt_succ c },\n  { exact (add_le_of_limit l).2 (\u03bb c l, (lt_sub.1 l).le) }\nend\n\ntheorem le_sub_of_le {a b c : ordinal} (h : b \u2264 a) : c \u2264 a - b \u2194 b + c \u2264 a :=\nby rw [\u2190add_le_add_iff_left b, ordinal.add_sub_cancel_of_le h]\n\ntheorem sub_lt_of_le {a b c : ordinal} (h : b \u2264 a) : a - b < c \u2194 a < b + c :=\nlt_iff_lt_of_le_iff_le (le_sub_of_le h)\n\ninstance : has_exists_add_of_le ordinal :=\n\u27e8\u03bb a b h, \u27e8_, (ordinal.add_sub_cancel_of_le h).symm\u27e9\u27e9\n\n@[simp] theorem sub_zero (a : ordinal) : a - 0 = a :=\nby simpa only [zero_add] using add_sub_cancel 0 a\n\n@[simp] theorem zero_sub (a : ordinal) : 0 - a = 0 :=\nby rw \u2190 ordinal.le_zero; apply sub_le_self\n\n@[simp] theorem sub_self (a : ordinal) : a - a = 0 :=\nby simpa only [add_zero] using add_sub_cancel a 0\n\nprotected theorem sub_eq_zero_iff_le {a b : ordinal} : a - b = 0 \u2194 a \u2264 b :=\n\u27e8\u03bb h, by simpa only [h, add_zero] using le_add_sub a b,\n \u03bb h, by rwa [\u2190 ordinal.le_zero, sub_le, add_zero]\u27e9\n\ntheorem sub_sub (a b c : ordinal) : a - b - c = a - (b + c) :=\neq_of_forall_ge_iff $ \u03bb d, by rw [sub_le, sub_le, sub_le, add_assoc]\n\n@[simp] theorem add_sub_add_cancel (a b c : ordinal) : a + b - (a + c) = b - c :=\nby rw [\u2190 sub_sub, add_sub_cancel]\n\ntheorem sub_is_limit {a b} (l : is_limit a) (h : b < a) : is_limit (a - b) :=\n\u27e8ne_of_gt $ lt_sub.2 $ by rwa add_zero,\n \u03bb c h, by rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)\u27e9\n\n@[simp] theorem one_add_omega : 1 + \u03c9 = \u03c9 :=\nbegin\n  refine le_antisymm _ (le_add_left _ _),\n  rw [omega, \u2190 lift_one.{0}, \u2190 lift_add, lift_le, \u2190 type_unit, \u2190 type_sum_lex],\n  refine \u27e8rel_embedding.collapse (rel_embedding.of_monotone _ _)\u27e9,\n  { apply sum.rec, exact \u03bb _, 0, exact nat.succ },\n  { intros a b, cases a; cases b; intro H; cases H with _ _ H _ _ H;\n    [cases H, exact nat.succ_pos _, exact nat.succ_lt_succ H] }\nend\n\n@[simp, priority 990]\ntheorem one_add_of_omega_le {o} (h : \u03c9 \u2264 o) : 1 + o = o :=\nby rw [\u2190 ordinal.add_sub_cancel_of_le h, \u2190 add_assoc, one_add_omega]\n\n/-! ### Multiplication of ordinals-/\n\n/-- The multiplication of ordinals `o\u2081` and `o\u2082` is the (well founded) lexicographic order on\n`o\u2082 \u00d7 o\u2081`. -/\ninstance : monoid ordinal.{u} :=\n{ mul := \u03bb a b, quotient.lift_on\u2082 a b\n      (\u03bb \u27e8\u03b1, r, wo\u27e9 \u27e8\u03b2, s, wo'\u27e9, \u27e6\u27e8\u03b2 \u00d7 \u03b1, prod.lex s r, by exactI prod.lex.is_well_order\u27e9\u27e7\n        : Well_order \u2192 Well_order \u2192 ordinal) $\n    \u03bb \u27e8\u03b1\u2081, r\u2081, o\u2081\u27e9 \u27e8\u03b1\u2082, r\u2082, o\u2082\u27e9 \u27e8\u03b2\u2081, s\u2081, p\u2081\u27e9 \u27e8\u03b2\u2082, s\u2082, p\u2082\u27e9 \u27e8f\u27e9 \u27e8g\u27e9,\n    quot.sound \u27e8rel_iso.prod_lex_congr g f\u27e9,\n  one := 1,\n  mul_assoc := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9,\n    eq.symm $ quotient.sound \u27e8\u27e8prod_assoc _ _ _, \u03bb a b, begin\n      rcases a with \u27e8\u27e8a\u2081, a\u2082\u27e9, a\u2083\u27e9,\n      rcases b with \u27e8\u27e8b\u2081, b\u2082\u27e9, b\u2083\u27e9,\n      simp [prod.lex_def, and_or_distrib_left, or_assoc, and_assoc]\n    end\u27e9\u27e9,\n  mul_one := \u03bb a, induction_on a $ \u03bb \u03b1 r _, quotient.sound\n    \u27e8\u27e8punit_prod _, \u03bb a b, by rcases a with \u27e8\u27e8\u27e8\u27e9\u27e9, a\u27e9; rcases b with \u27e8\u27e8\u27e8\u27e9\u27e9, b\u27e9;\n    simp only [prod.lex_def, empty_relation, false_or];\n    simp only [eq_self_iff_true, true_and]; refl\u27e9\u27e9,\n  one_mul := \u03bb a, induction_on a $ \u03bb \u03b1 r _, quotient.sound\n    \u27e8\u27e8prod_punit _, \u03bb a b, by rcases a with \u27e8a, \u27e8\u27e8\u27e9\u27e9\u27e9; rcases b with \u27e8b, \u27e8\u27e8\u27e9\u27e9\u27e9;\n    simp only [prod.lex_def, empty_relation, and_false, or_false]; refl\u27e9\u27e9 }\n\n@[simp] theorem type_prod_lex {\u03b1 \u03b2 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : \u03b2 \u2192 \u03b2 \u2192 Prop)\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] : type (prod.lex s r) = type r * type s := rfl\n\nprivate theorem mul_eq_zero' {a b : ordinal} : a * b = 0 \u2194 a = 0 \u2228 b = 0 :=\ninduction_on a $ \u03bb \u03b1 _ _, induction_on b $ \u03bb \u03b2 _ _, begin\n  simp_rw [\u2190type_prod_lex, type_eq_zero_iff_is_empty],\n  rw or_comm,\n  exact is_empty_prod\nend\n\ninstance : monoid_with_zero ordinal :=\n{ zero := 0,\n  mul_zero := \u03bb a, mul_eq_zero'.2 $ or.inr rfl,\n  zero_mul := \u03bb a, mul_eq_zero'.2 $ or.inl rfl,\n  ..ordinal.monoid }\n\ninstance : no_zero_divisors ordinal :=\n\u27e8\u03bb a b, mul_eq_zero'.1\u27e9\n\n@[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b :=\nquotient.induction_on\u2082 a b $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9,\nquotient.sound \u27e8(rel_iso.preimage equiv.ulift _).trans\n (rel_iso.prod_lex_congr (rel_iso.preimage equiv.ulift _)\n   (rel_iso.preimage equiv.ulift _)).symm\u27e9\n\n@[simp] theorem card_mul (a b) : card (a * b) = card a * card b :=\nquotient.induction_on\u2082 a b $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9,\nmul_comm (mk \u03b2) (mk \u03b1)\n\ninstance : left_distrib_class ordinal.{u} :=\n\u27e8\u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9,\nquotient.sound \u27e8\u27e8sum_prod_distrib _ _ _, begin\n  rintro \u27e8a\u2081|a\u2081, a\u2082\u27e9 \u27e8b\u2081|b\u2081, b\u2082\u27e9;\n  simp only [prod.lex_def,\n    sum.lex_inl_inl, sum.lex.sep, sum.lex_inr_inl, sum.lex_inr_inr,\n    sum_prod_distrib_apply_left, sum_prod_distrib_apply_right];\n  simp only [sum.inl.inj_iff, true_or, false_and, false_or]\nend\u27e9\u27e9\u27e9\n\ntheorem mul_succ (a b : ordinal) : a * succ b = a * b + a := mul_add_one a b\n\ninstance mul_covariant_class_le : covariant_class ordinal.{u} ordinal.{u} (*) (\u2264) :=\n\u27e8\u03bb c a b, quotient.induction_on\u2083 a b c $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9 \u27e8f\u27e9, begin\n  resetI,\n  refine (rel_embedding.of_monotone (\u03bb a : \u03b1 \u00d7 \u03b3, (f a.1, a.2)) (\u03bb a b h, _)).ordinal_type_le,\n  clear_,\n  cases h with a\u2081 b\u2081 a\u2082 b\u2082 h' a b\u2081 b\u2082 h',\n  { exact prod.lex.left _ _ (f.to_rel_embedding.map_rel_iff.2 h') },\n  { exact prod.lex.right _ h' }\nend\u27e9\n\ninstance mul_swap_covariant_class_le : covariant_class ordinal.{u} ordinal.{u} (swap (*)) (\u2264) :=\n\u27e8\u03bb c a b, quotient.induction_on\u2083 a b c $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9 \u27e8f\u27e9, begin\n  resetI,\n  refine (rel_embedding.of_monotone (\u03bb a : \u03b3 \u00d7 \u03b1, (a.1, f a.2)) (\u03bb a b h, _)).ordinal_type_le,\n  cases h with a\u2081 b\u2081 a\u2082 b\u2082 h' a b\u2081 b\u2082 h',\n  { exact prod.lex.left _ _ h' },\n  { exact prod.lex.right _ (f.to_rel_embedding.map_rel_iff.2 h') }\nend\u27e9\n\ntheorem le_mul_left (a : ordinal) {b : ordinal} (hb : 0 < b) : a \u2264 a * b :=\nby { convert mul_le_mul_left' (one_le_iff_pos.2 hb) a, rw mul_one a }\n\ntheorem le_mul_right (a : ordinal) {b : ordinal} (hb : 0 < b) : a \u2264 b * a :=\nby { convert mul_le_mul_right' (one_le_iff_pos.2 hb) a, rw one_mul a }\n\nprivate lemma mul_le_of_limit_aux {\u03b1 \u03b2 r s} [is_well_order \u03b1 r] [is_well_order \u03b2 s]\n  {c} (h : is_limit (type s)) (H : \u2200 b' < type s, type r * b' \u2264 c)\n  (l : c < type r * type s) : false :=\nbegin\n  suffices : \u2200 a b, prod.lex s r (b, a) (enum _ _ l),\n  { cases enum _ _ l with b a, exact irrefl _ (this _ _) },\n  intros a b,\n  rw [\u2190typein_lt_typein (prod.lex s r), typein_enum],\n  have := H _ (h.2 _ (typein_lt_type s b)),\n  rw mul_succ at this,\n  have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this,\n  refine (rel_embedding.of_monotone (\u03bb a, _) (\u03bb a b, _)).ordinal_type_le.trans_lt this,\n  { rcases a with \u27e8\u27e8b', a'\u27e9, h\u27e9,\n    by_cases e : b = b',\n    { refine sum.inr \u27e8a', _\u27e9,\n      subst e, cases h with _ _ _ _ h _ _ _ h,\n      { exact (irrefl _ h).elim },\n      { exact h } },\n    { refine sum.inl (\u27e8b', _\u27e9, a'),\n      cases h with _ _ _ _ h _ _ _ h,\n      { exact h }, { exact (e rfl).elim } } },\n  { rcases a with \u27e8\u27e8b\u2081, a\u2081\u27e9, h\u2081\u27e9,\n    rcases b with \u27e8\u27e8b\u2082, a\u2082\u27e9, h\u2082\u27e9,\n    intro h, by_cases e\u2081 : b = b\u2081; by_cases e\u2082 : b = b\u2082,\n    { substs b\u2081 b\u2082,\n      simpa only [subrel_val, prod.lex_def, @irrefl _ s _ b, true_and, false_or, eq_self_iff_true,\n        dif_pos, sum.lex_inr_inr] using h },\n    { subst b\u2081,\n      simp only [subrel_val, prod.lex_def, e\u2082, prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,\n        or_false, dif_neg, not_false_iff, sum.lex_inr_inl, false_and] at h \u22a2,\n      cases h\u2082; [exact asymm h h\u2082_h, exact e\u2082 rfl] },\n    { simp [e\u2082, dif_neg e\u2081, show b\u2082 \u2260 b\u2081, by cc] },\n    { simpa only [dif_neg e\u2081, dif_neg e\u2082, prod.lex_def, subrel_val, subtype.mk_eq_mk,\n        sum.lex_inl_inl] using h } }\nend\n\ntheorem mul_le_of_limit {a b c : ordinal} (h : is_limit b) : a * b \u2264 c \u2194 \u2200 b' < b, a * b' \u2264 c :=\n\u27e8\u03bb h b' l, (mul_le_mul_left' l.le _).trans h,\n\u03bb H, le_of_not_lt $ induction_on a (\u03bb \u03b1 r _, induction_on b $ \u03bb \u03b2 s _,\n  by exactI mul_le_of_limit_aux) h H\u27e9\n\ntheorem mul_is_normal {a : ordinal} (h : 0 < a) : is_normal ((*) a) :=\n\u27e8\u03bb b, by rw mul_succ; simpa only [add_zero] using (add_lt_add_iff_left (a*b)).2 h,\n \u03bb b l c, mul_le_of_limit l\u27e9\n\ntheorem lt_mul_of_limit {a b c : ordinal}\n  (h : is_limit c) : a < b * c \u2194 \u2203 c' < c, a < b * c' :=\nby simpa only [not_ball, not_le] using not_congr (@mul_le_of_limit b c a h)\n\ntheorem mul_lt_mul_iff_left {a b c : ordinal} (a0 : 0 < a) : a * b < a * c \u2194 b < c :=\n(mul_is_normal a0).lt_iff\n\ntheorem mul_le_mul_iff_left {a b c : ordinal} (a0 : 0 < a) : a * b \u2264 a * c \u2194 b \u2264 c :=\n(mul_is_normal a0).le_iff\n\ntheorem mul_lt_mul_of_pos_left {a b c : ordinal}\n  (h : a < b) (c0 : 0 < c) : c * a < c * b :=\n(mul_lt_mul_iff_left c0).2 h\n\ntheorem mul_pos {a b : ordinal} (h\u2081 : 0 < a) (h\u2082 : 0 < b) : 0 < a * b :=\nby simpa only [mul_zero] using mul_lt_mul_of_pos_left h\u2082 h\u2081\n\ntheorem mul_ne_zero {a b : ordinal} : a \u2260 0 \u2192 b \u2260 0 \u2192 a * b \u2260 0 :=\nby simpa only [ordinal.pos_iff_ne_zero] using mul_pos\n\ntheorem le_of_mul_le_mul_left {a b c : ordinal}\n  (h : c * a \u2264 c * b) (h0 : 0 < c) : a \u2264 b :=\nle_imp_le_of_lt_imp_lt (\u03bb h', mul_lt_mul_of_pos_left h' h0) h\n\ntheorem mul_right_inj {a b c : ordinal} (a0 : 0 < a) : a * b = a * c \u2194 b = c :=\n(mul_is_normal a0).inj\n\ntheorem mul_is_limit {a b : ordinal}\n  (a0 : 0 < a) : is_limit b \u2192 is_limit (a * b) :=\n(mul_is_normal a0).is_limit\n\ntheorem mul_is_limit_left {a b : ordinal}\n  (l : is_limit a) (b0 : 0 < b) : is_limit (a * b) :=\nbegin\n  rcases zero_or_succ_or_limit b with rfl|\u27e8b,rfl\u27e9|lb,\n  { exact b0.false.elim },\n  { rw mul_succ, exact add_is_limit _ l },\n  { exact mul_is_limit l.pos lb }\nend\n\ntheorem smul_eq_mul : \u2200 (n : \u2115) (a : ordinal), n \u2022 a = a * n\n| 0       a := by rw [zero_smul, nat.cast_zero, mul_zero]\n| (n + 1) a := by rw [succ_nsmul', nat.cast_add, mul_add, nat.cast_one, mul_one, smul_eq_mul]\n\n/-! ### Division on ordinals -/\n\n/-- The set in the definition of division is nonempty. -/\ntheorem div_nonempty {a b : ordinal} (h : b \u2260 0) : {o | a < b * succ o}.nonempty :=\n\u27e8a, succ_le_iff.1 $\n  by simpa only [succ_zero, one_mul]\n    using mul_le_mul_right' (succ_le_of_lt (ordinal.pos_iff_ne_zero.2 h)) (succ a)\u27e9\n\n/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/\ninstance : has_div ordinal := \u27e8\u03bb a b, if h : b = 0 then 0 else Inf {o | a < b * succ o}\u27e9\n\n@[simp] theorem div_zero (a : ordinal) : a / 0 = 0 :=\ndif_pos rfl\n\nlemma div_def (a) {b : ordinal} (h : b \u2260 0) : a / b = Inf {o | a < b * succ o} :=\ndif_neg h\n\ntheorem lt_mul_succ_div (a) {b : ordinal} (h : b \u2260 0) : a < b * succ (a / b) :=\nby rw div_def a h; exact Inf_mem (div_nonempty h)\n\ntheorem lt_mul_div_add (a) {b : ordinal} (h : b \u2260 0) : a < b * (a / b) + b :=\nby simpa only [mul_succ] using lt_mul_succ_div a h\n\ntheorem div_le {a b c : ordinal} (b0 : b \u2260 0) : a / b \u2264 c \u2194 a < b * succ c :=\n\u27e8\u03bb h, (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _),\n \u03bb h, by rw div_def a b0; exact cInf_le' h\u27e9\n\ntheorem lt_div {a b c : ordinal} (h : c \u2260 0) : a < b / c \u2194 c * succ a \u2264 b :=\nby rw [\u2190 not_le, div_le h, not_lt]\n\ntheorem div_pos {b c : ordinal} (h : c \u2260 0) : 0 < b / c \u2194 c \u2264 b := by simp [lt_div h]\n\ntheorem le_div {a b c : ordinal} (c0 : c \u2260 0) :\n  a \u2264 b / c \u2194 c * a \u2264 b :=\nbegin\n  apply limit_rec_on a,\n  { simp only [mul_zero, ordinal.zero_le] },\n  { intros, rw [succ_le_iff, lt_div c0] },\n  { simp only [mul_le_of_limit, limit_le, iff_self, forall_true_iff] {contextual := tt} }\nend\n\ntheorem div_lt {a b c : ordinal} (b0 : b \u2260 0) :\n  a / b < c \u2194 a < b * c :=\nlt_iff_lt_of_le_iff_le $ le_div b0\n\ntheorem div_le_of_le_mul {a b c : ordinal} (h : a \u2264 b * c) : a / b \u2264 c :=\nif b0 : b = 0 then by simp only [b0, div_zero, ordinal.zero_le] else\n(div_le b0).2 $ h.trans_lt $ mul_lt_mul_of_pos_left (lt_succ c) (ordinal.pos_iff_ne_zero.2 b0)\n\ntheorem mul_lt_of_lt_div {a b c : ordinal} : a < b / c \u2192 c * a < b :=\nlt_imp_lt_of_le_imp_le div_le_of_le_mul\n\n@[simp] theorem zero_div (a : ordinal) : 0 / a = 0 :=\nordinal.le_zero.1 $ div_le_of_le_mul $ ordinal.zero_le _\n\ntheorem mul_div_le (a b : ordinal) : b * (a / b) \u2264 a :=\nif b0 : b = 0 then by simp only [b0, zero_mul, ordinal.zero_le] else (le_div b0).1 le_rfl\n\ntheorem mul_add_div (a) {b : ordinal} (b0 : b \u2260 0) (c) : (b * a + c) / b = a + c / b :=\nbegin\n  apply le_antisymm,\n  { apply (div_le b0).2,\n    rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left],\n    apply lt_mul_div_add _ b0 },\n  { rw [le_div b0, mul_add, add_le_add_iff_left],\n    apply mul_div_le }\nend\n\ntheorem div_eq_zero_of_lt {a b : ordinal} (h : a < b) : a / b = 0 :=\nbegin\n  rw [\u2190ordinal.le_zero, div_le $ ordinal.pos_iff_ne_zero.1 $ (ordinal.zero_le _).trans_lt h],\n  simpa only [succ_zero, mul_one] using h\nend\n\n@[simp] theorem mul_div_cancel (a) {b : ordinal} (b0 : b \u2260 0) : b * a / b = a :=\nby simpa only [add_zero, zero_div] using mul_add_div a b0 0\n\n@[simp] theorem div_one (a : ordinal) : a / 1 = a :=\nby simpa only [one_mul] using mul_div_cancel a ordinal.one_ne_zero\n\n@[simp] theorem div_self {a : ordinal} (h : a \u2260 0) : a / a = 1 :=\nby simpa only [mul_one] using mul_div_cancel 1 h\n\ntheorem mul_sub (a b c : ordinal) : a * (b - c) = a * b - a * c :=\nif a0 : a = 0 then by simp only [a0, zero_mul, sub_self] else\neq_of_forall_ge_iff $ \u03bb d,\nby rw [sub_le, \u2190 le_div a0, sub_le, \u2190 le_div a0, mul_add_div _ a0]\n\ntheorem is_limit_add_iff {a b} : is_limit (a + b) \u2194 is_limit b \u2228 (b = 0 \u2227 is_limit a) :=\nbegin\n  split; intro h,\n  { by_cases h' : b = 0,\n    { rw [h', add_zero] at h, right, exact \u27e8h', h\u27e9 },\n      left, rw [\u2190add_sub_cancel a b], apply sub_is_limit h,\n      suffices : a + 0 < a + b, simpa only [add_zero],\n      rwa [add_lt_add_iff_left, ordinal.pos_iff_ne_zero] },\n  rcases h with h|\u27e8rfl, h\u27e9, exact add_is_limit a h, simpa only [add_zero]\nend\n\ntheorem dvd_add_iff : \u2200 {a b c : ordinal}, a \u2223 b \u2192 (a \u2223 b + c \u2194 a \u2223 c)\n| a _ c \u27e8b, rfl\u27e9 :=\n \u27e8\u03bb \u27e8d, e\u27e9, \u27e8d - b, by rw [mul_sub, \u2190 e, add_sub_cancel]\u27e9,\n  \u03bb \u27e8d, e\u27e9, by { rw [e, \u2190 mul_add], apply dvd_mul_right }\u27e9\n\ntheorem div_mul_cancel : \u2200 {a b : ordinal}, a \u2260 0 \u2192 a \u2223 b \u2192 a * (b / a) = b\n| a _ a0 \u27e8b, rfl\u27e9 := by rw [mul_div_cancel _ a0]\n\ntheorem le_of_dvd : \u2200 {a b : ordinal}, b \u2260 0 \u2192 a \u2223 b \u2192 a \u2264 b\n| a _ b0 \u27e8b, rfl\u27e9 := by simpa only [mul_one] using mul_le_mul_left'\n  (one_le_iff_ne_zero.2 (\u03bb h : b = 0, by simpa only [h, mul_zero] using b0)) a\n\ntheorem dvd_antisymm {a b : ordinal} (h\u2081 : a \u2223 b) (h\u2082 : b \u2223 a) : a = b :=\nif a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h\u2081).symm else\nif b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h\u2082 else\n(le_of_dvd b0 h\u2081).antisymm (le_of_dvd a0 h\u2082)\n\ninstance : is_antisymm ordinal (\u2223) := \u27e8@dvd_antisymm\u27e9\n\n/-- `a % b` is the unique ordinal `o'` satisfying\n  `a = b * o + o'` with `o' < b`. -/\ninstance : has_mod ordinal := \u27e8\u03bb a b, a - b * (a / b)\u27e9\n\ntheorem mod_def (a b : ordinal) : a % b = a - b * (a / b) := rfl\n\ntheorem mod_le (a b : ordinal) : a % b \u2264 a := sub_le_self a _\n\n@[simp] theorem mod_zero (a : ordinal) : a % 0 = a :=\nby simp only [mod_def, div_zero, zero_mul, sub_zero]\n\ntheorem mod_eq_of_lt {a b : ordinal} (h : a < b) : a % b = a :=\nby simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero]\n\n@[simp] theorem zero_mod (b : ordinal) : 0 % b = 0 :=\nby simp only [mod_def, zero_div, mul_zero, sub_self]\n\ntheorem div_add_mod (a b : ordinal) : b * (a / b) + a % b = a :=\nordinal.add_sub_cancel_of_le $ mul_div_le _ _\n\ntheorem mod_lt (a) {b : ordinal} (h : b \u2260 0) : a % b < b :=\n(add_lt_add_iff_left (b * (a / b))).1 $\nby rw div_add_mod; exact lt_mul_div_add a h\n\n@[simp] theorem mod_self (a : ordinal) : a % a = 0 :=\nif a0 : a = 0 then by simp only [a0, zero_mod] else\nby simp only [mod_def, div_self a0, mul_one, sub_self]\n\n@[simp] theorem mod_one (a : ordinal) : a % 1 = 0 :=\nby simp only [mod_def, div_one, one_mul, sub_self]\n\ntheorem dvd_of_mod_eq_zero {a b : ordinal} (H : a % b = 0) : b \u2223 a :=\n\u27e8a / b, by simpa [H] using (div_add_mod a b).symm\u27e9\n\ntheorem mod_eq_zero_of_dvd {a b : ordinal} (H : b \u2223 a) : a % b = 0 :=\nbegin\n  rcases H with \u27e8c, rfl\u27e9,\n  rcases eq_or_ne b 0 with rfl | hb,\n  { simp },\n  { simp [mod_def, hb] }\nend\n\ntheorem dvd_iff_mod_eq_zero {a b : ordinal} : b \u2223 a \u2194 a % b = 0 :=\n\u27e8mod_eq_zero_of_dvd, dvd_of_mod_eq_zero\u27e9\n\n@[simp] theorem mul_add_mod_self (x y z : ordinal) : (x * y + z) % x = z % x :=\nbegin\n  rcases eq_or_ne x 0 with rfl | hx,\n  { simp },\n  { rwa [mod_def, mul_add_div, mul_add, \u2190sub_sub, add_sub_cancel, mod_def] }\nend\n\n@[simp] theorem mul_mod (x y : ordinal) : x * y % x = 0 := by simpa using mul_add_mod_self x y 0\n\ntheorem mod_mod_of_dvd (a : ordinal) {b c : ordinal} (h : c \u2223 b) : a % b % c = a % c :=\nbegin\n  nth_rewrite_rhs 0 \u2190div_add_mod a b,\n  rcases h with \u27e8d, rfl\u27e9,\n  rw [mul_assoc, mul_add_mod_self]\nend\n\n@[simp] theorem mod_mod (a b : ordinal) : a % b % b = a % b := mod_mod_of_dvd a dvd_rfl\n\n/-! ### Families of ordinals\n\nThere are two kinds of indexed families that naturally arise when dealing with ordinals: those\nindexed by some type in the appropriate universe, and those indexed by ordinals less than another.\nThe following API allows one to convert from one kind of family to the other.\n\nIn many cases, this makes it easy to prove claims about one kind of family via the corresponding\nclaim on the other. -/\n\n/-- Converts a family indexed by a `Type u` to one indexed by an `ordinal.{u}` using a specified\nwell-ordering. -/\ndef bfamily_of_family' {\u03b9 : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] (f : \u03b9 \u2192 \u03b1) :\n  \u03a0 a < type r, \u03b1 :=\n\u03bb a ha, f (enum r a ha)\n\n/-- Converts a family indexed by a `Type u` to one indexed by an `ordinal.{u}` using a well-ordering\ngiven by the axiom of choice. -/\ndef bfamily_of_family {\u03b9 : Type u} : (\u03b9 \u2192 \u03b1) \u2192 \u03a0 a < type (@well_ordering_rel \u03b9), \u03b1 :=\nbfamily_of_family' well_ordering_rel\n\n/-- Converts a family indexed by an `ordinal.{u}` to one indexed by an `Type u` using a specified\nwell-ordering. -/\ndef family_of_bfamily' {\u03b9 : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] {o} (ho : type r = o)\n  (f : \u03a0 a < o, \u03b1) : \u03b9 \u2192 \u03b1 :=\n\u03bb i, f (typein r i) (by { rw \u2190ho, exact typein_lt_type r i })\n\n/-- Converts a family indexed by an `ordinal.{u}` to one indexed by a `Type u` using a well-ordering\ngiven by the axiom of choice. -/\ndef family_of_bfamily (o : ordinal) (f : \u03a0 a < o, \u03b1) : o.out.\u03b1 \u2192 \u03b1 :=\nfamily_of_bfamily' (<) (type_lt o) f\n\n@[simp] theorem bfamily_of_family'_typein {\u03b9} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] (f : \u03b9 \u2192 \u03b1)\n  (i) : bfamily_of_family' r f (typein r i) (typein_lt_type r i) = f i :=\nby simp only [bfamily_of_family', enum_typein]\n\n@[simp] theorem bfamily_of_family_typein {\u03b9} (f : \u03b9 \u2192 \u03b1) (i) :\n  bfamily_of_family f (typein _ i) (typein_lt_type _ i) = f i :=\nbfamily_of_family'_typein  _ f i\n\n@[simp] theorem family_of_bfamily'_enum {\u03b9 : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] {o}\n  (ho : type r = o) (f : \u03a0 a < o, \u03b1) (i hi) :\n  family_of_bfamily' r ho f (enum r i (by rwa ho)) = f i hi :=\nby simp only [family_of_bfamily', typein_enum]\n\n@[simp] theorem family_of_bfamily_enum (o : ordinal) (f : \u03a0 a < o, \u03b1) (i hi) :\n  family_of_bfamily o f (enum (<) i (by { convert hi, exact type_lt _ })) = f i hi :=\nfamily_of_bfamily'_enum _ (type_lt o) f _ _\n\n/-- The range of a family indexed by ordinals. -/\ndef brange (o : ordinal) (f : \u03a0 a < o, \u03b1) : set \u03b1 :=\n{a | \u2203 i hi, f i hi = a}\n\ntheorem mem_brange {o : ordinal} {f : \u03a0 a < o, \u03b1} {a} : a \u2208 brange o f \u2194 \u2203 i hi, f i hi = a :=\niff.rfl\n\ntheorem mem_brange_self {o} (f : \u03a0 a < o, \u03b1) (i hi) : f i hi \u2208 brange o f :=\n\u27e8i, hi, rfl\u27e9\n\n@[simp] theorem range_family_of_bfamily' {\u03b9 : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] {o}\n  (ho : type r = o) (f : \u03a0 a < o, \u03b1) : range (family_of_bfamily' r ho f) = brange o f :=\nbegin\n  refine set.ext (\u03bb a, \u27e8_, _\u27e9),\n  { rintro \u27e8b, rfl\u27e9,\n    apply mem_brange_self },\n  { rintro \u27e8i, hi, rfl\u27e9,\n    exact \u27e8_, family_of_bfamily'_enum _ _ _ _ _\u27e9 }\nend\n\n@[simp] theorem range_family_of_bfamily {o} (f : \u03a0 a < o, \u03b1) :\n  range (family_of_bfamily o f) = brange o f :=\nrange_family_of_bfamily' _ _ f\n\n@[simp] theorem brange_bfamily_of_family' {\u03b9 : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r]\n  (f : \u03b9 \u2192 \u03b1) : brange _ (bfamily_of_family' r f) = range f :=\nbegin\n  refine set.ext (\u03bb a, \u27e8_, _\u27e9),\n  { rintro \u27e8i, hi, rfl\u27e9,\n    apply mem_range_self },\n  { rintro \u27e8b, rfl\u27e9,\n    exact \u27e8_, _, bfamily_of_family'_typein _ _ _\u27e9 },\nend\n\n@[simp] theorem brange_bfamily_of_family {\u03b9 : Type u} (f : \u03b9 \u2192 \u03b1) :\n  brange _ (bfamily_of_family f) = range f :=\nbrange_bfamily_of_family' _ _\n\n@[simp] theorem brange_const {o : ordinal} (ho : o \u2260 0) {c : \u03b1} : brange o (\u03bb _ _, c) = {c} :=\nbegin\n  rw \u2190range_family_of_bfamily,\n  exact @set.range_const _ o.out.\u03b1 (out_nonempty_iff_ne_zero.2 ho) c\nend\n\ntheorem comp_bfamily_of_family' {\u03b9 : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] (f : \u03b9 \u2192 \u03b1)\n  (g : \u03b1 \u2192 \u03b2) : (\u03bb i hi, g (bfamily_of_family' r f i hi)) = bfamily_of_family' r (g \u2218 f) :=\nrfl\n\ntheorem comp_bfamily_of_family {\u03b9 : Type u} (f : \u03b9 \u2192 \u03b1) (g : \u03b1 \u2192 \u03b2) :\n  (\u03bb i hi, g (bfamily_of_family f i hi)) = bfamily_of_family (g \u2218 f) :=\nrfl\n\ntheorem comp_family_of_bfamily' {\u03b9 : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] {o}\n  (ho : type r = o) (f : \u03a0 a < o, \u03b1) (g : \u03b1 \u2192 \u03b2) :\n  g \u2218 (family_of_bfamily' r ho f) = family_of_bfamily' r ho (\u03bb i hi, g (f i hi)) :=\nrfl\n\ntheorem comp_family_of_bfamily {o} (f : \u03a0 a < o, \u03b1) (g : \u03b1 \u2192 \u03b2) :\n  g \u2218 (family_of_bfamily o f) = family_of_bfamily o (\u03bb i hi, g (f i hi)) :=\nrfl\n\n/-! ### Supremum of a family of ordinals -/\n\n/-- The supremum of a family of ordinals -/\ndef sup {\u03b9 : Type u} (f : \u03b9 \u2192 ordinal.{max u v}) : ordinal.{max u v} :=\nsupr f\n\n@[simp] theorem Sup_eq_sup {\u03b9 : Type u} (f : \u03b9 \u2192 ordinal.{max u v}) : Sup (set.range f) = sup f :=\nrfl\n\n/-- The range of an indexed ordinal function, whose outputs live in a higher universe than the\n    inputs, is always bounded above. See `ordinal.lsub` for an explicit bound. -/\ntheorem bdd_above_range {\u03b9 : Type u} (f : \u03b9 \u2192 ordinal.{max u v}) : bdd_above (set.range f) :=\n\u27e8(supr (succ \u2218 card \u2218 f)).ord, begin\n  rintros a \u27e8i, rfl\u27e9,\n  exact le_of_lt (cardinal.lt_ord.2 ((lt_succ _).trans_le (le_csupr (bdd_above_range _) _)))\nend\u27e9\n\ntheorem le_sup {\u03b9} (f : \u03b9 \u2192 ordinal) : \u2200 i, f i \u2264 sup f :=\n\u03bb i, le_cSup (bdd_above_range f) (mem_range_self i)\n\ntheorem sup_le_iff {\u03b9} {f : \u03b9 \u2192 ordinal} {a} : sup f \u2264 a \u2194 \u2200 i, f i \u2264 a :=\n(cSup_le_iff' (bdd_above_range f)).trans (by simp)\n\ntheorem sup_le {\u03b9} {f : \u03b9 \u2192 ordinal} {a} : (\u2200 i, f i \u2264 a) \u2192 sup f \u2264 a :=\nsup_le_iff.2\n\ntheorem lt_sup {\u03b9} {f : \u03b9 \u2192 ordinal} {a} : a < sup f \u2194 \u2203 i, a < f i :=\nby simpa only [not_forall, not_le] using not_congr (@sup_le_iff _ f a)\n\ntheorem ne_sup_iff_lt_sup {\u03b9} {f : \u03b9 \u2192 ordinal} : (\u2200 i, f i \u2260 sup f) \u2194 \u2200 i, f i < sup f :=\n\u27e8\u03bb hf _, lt_of_le_of_ne (le_sup _ _) (hf _), \u03bb hf _, ne_of_lt (hf _)\u27e9\n\ntheorem sup_not_succ_of_ne_sup {\u03b9} {f : \u03b9 \u2192 ordinal} (hf : \u2200 i, f i \u2260 sup f) {a}\n  (hao : a < sup f) : succ a < sup f :=\nbegin\n  by_contra' hoa,\n  exact hao.not_le (sup_le $ \u03bb i, le_of_lt_succ $\n    (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa)\nend\n\n@[simp] theorem sup_eq_zero_iff {\u03b9} {f : \u03b9 \u2192 ordinal} : sup f = 0 \u2194 \u2200 i, f i = 0 :=\nbegin\n  refine \u27e8\u03bb h i, _, \u03bb h, le_antisymm\n    (sup_le (\u03bb i, ordinal.le_zero.2 (h i))) (ordinal.zero_le _)\u27e9,\n  rw [\u2190ordinal.le_zero, \u2190h],\n  exact le_sup f i\nend\n\ntheorem is_normal.sup {f} (H : is_normal f) {\u03b9} (g : \u03b9 \u2192 ordinal) [nonempty \u03b9] :\n  f (sup g) = sup (f \u2218 g) :=\neq_of_forall_ge_iff $ \u03bb a,\nby rw [sup_le_iff, comp, H.le_set' set.univ set.univ_nonempty g]; simp [sup_le_iff]\n\n@[simp] theorem sup_empty {\u03b9} [is_empty \u03b9] (f : \u03b9 \u2192 ordinal) : sup f = 0 :=\ncsupr_of_empty f\n\n@[simp] theorem sup_const {\u03b9} [h\u03b9 : nonempty \u03b9] (o : ordinal) : sup (\u03bb _ : \u03b9, o) = o :=\ncsupr_const\n\n@[simp] theorem sup_unique {\u03b9} [unique \u03b9] (f : \u03b9 \u2192 ordinal) : sup f = f default :=\nsupr_unique\n\ntheorem sup_le_of_range_subset {\u03b9 \u03b9'} {f : \u03b9 \u2192 ordinal} {g : \u03b9' \u2192 ordinal}\n  (h : set.range f \u2286 set.range g) : sup.{u (max v w)} f \u2264 sup.{v (max u w)} g :=\nsup_le $ \u03bb i, match h (mem_range_self i) with \u27e8j, hj\u27e9 := hj \u25b8 le_sup _ _ end\n\ntheorem sup_eq_of_range_eq {\u03b9 \u03b9'} {f : \u03b9 \u2192 ordinal} {g : \u03b9' \u2192 ordinal}\n  (h : set.range f = set.range g) : sup.{u (max v w)} f = sup.{v (max u w)} g :=\n(sup_le_of_range_subset h.le).antisymm (sup_le_of_range_subset.{v u w} h.ge)\n\n@[simp] theorem sup_sum {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2295 \u03b2 \u2192 ordinal) : sup.{(max u v) w} f =\n  max (sup.{u (max v w)} (\u03bb a, f (sum.inl a))) (sup.{v (max u w)} (\u03bb b, f (sum.inr b))) :=\nbegin\n  apply (sup_le_iff.2 _).antisymm (max_le_iff.2 \u27e8_, _\u27e9),\n  { rintro (i|i),\n    { exact le_max_of_le_left (le_sup _ i) },\n    { exact le_max_of_le_right (le_sup _ i) } },\n  all_goals\n  { apply sup_le_of_range_subset.{_ (max u v) w},\n    rintros i \u27e8a, rfl\u27e9,\n    apply mem_range_self }\nend\n\nlemma unbounded_range_of_sup_ge {\u03b1 \u03b2 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (f : \u03b2 \u2192 \u03b1)\n  (h : type r \u2264 sup.{u u} (typein r \u2218 f)) : unbounded r (range f) :=\n(not_bounded_iff _).1 $ \u03bb \u27e8x, hx\u27e9, not_lt_of_le h $ lt_of_le_of_lt\n  (sup_le $ \u03bb y, le_of_lt $ (typein_lt_typein r).2 $ hx _ $ mem_range_self y)\n  (typein_lt_type r x)\n\ntheorem le_sup_shrink_equiv {s : set ordinal.{u}} (hs : small.{u} s) (a) (ha : a \u2208 s) :\n  a \u2264 sup.{u u} (\u03bb x, ((@equiv_shrink s hs).symm x).val) :=\nby { convert le_sup.{u u} _ ((@equiv_shrink s hs) \u27e8a, ha\u27e9), rw symm_apply_apply }\n\ninstance small_Iio (o : ordinal.{u}) : small.{u} (set.Iio o) :=\nlet f : o.out.\u03b1 \u2192 set.Iio o := \u03bb x, \u27e8typein (<) x, typein_lt_self x\u27e9 in\nlet hf : surjective f := \u03bb b, \u27e8enum (<) b.val (by { rw type_lt, exact b.prop }),\n  subtype.ext (typein_enum _ _)\u27e9 in\nsmall_of_surjective hf\n\ninstance small_Iic (o : ordinal.{u}) : small.{u} (set.Iic o) :=\nby { rw \u2190Iio_succ, apply_instance }\n\ntheorem bdd_above_iff_small {s : set ordinal.{u}} : bdd_above s \u2194 small.{u} s :=\n\u27e8\u03bb \u27e8a, h\u27e9, small_subset $ show s \u2286 Iic a, from \u03bb x hx, h hx,\n\u03bb h, \u27e8sup.{u u} (\u03bb x, ((@equiv_shrink s h).symm x).val), le_sup_shrink_equiv h\u27e9\u27e9\n\ntheorem bdd_above_of_small (s : set ordinal.{u}) [h : small.{u} s] : bdd_above s :=\nbdd_above_iff_small.2 h\n\ntheorem sup_eq_Sup {s : set ordinal.{u}} (hs : small.{u} s) :\n  sup.{u u} (\u03bb x, (@equiv_shrink s hs).symm x) = Sup s :=\nlet hs' := bdd_above_iff_small.2 hs in\n  ((cSup_le_iff' hs').2 (le_sup_shrink_equiv hs)).antisymm'\n  (sup_le (\u03bb x, le_cSup hs' (subtype.mem _)))\n\ntheorem Sup_ord {s : set cardinal.{u}} (hs : bdd_above s) : (Sup s).ord = Sup (ord '' s) :=\neq_of_forall_ge_iff $ \u03bb a, begin\n  rw [cSup_le_iff' (bdd_above_iff_small.2 (@small_image _ _ _ s\n    (cardinal.bdd_above_iff_small.1 hs))), ord_le, cSup_le_iff' hs],\n  simp [ord_le]\nend\n\ntheorem supr_ord {\u03b9} {f : \u03b9 \u2192 cardinal} (hf : bdd_above (range f)) :\n  (supr f).ord = \u2a06 i, (f i).ord :=\nby { unfold supr, convert Sup_ord hf, rw range_comp }\n\nprivate theorem sup_le_sup {\u03b9 \u03b9' : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) (r' : \u03b9' \u2192 \u03b9' \u2192 Prop)\n  [is_well_order \u03b9 r] [is_well_order \u03b9' r'] {o} (ho : type r = o) (ho' : type r' = o)\n  (f : \u03a0 a < o, ordinal) : sup (family_of_bfamily' r ho f) \u2264 sup (family_of_bfamily' r' ho' f) :=\nsup_le $ \u03bb i, begin\n  cases typein_surj r' (by { rw [ho', \u2190ho], exact typein_lt_type r i }) with j hj,\n  simp_rw [family_of_bfamily', \u2190hj],\n  apply le_sup\nend\n\ntheorem sup_eq_sup {\u03b9 \u03b9' : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) (r' : \u03b9' \u2192 \u03b9' \u2192 Prop) [is_well_order \u03b9 r]\n  [is_well_order \u03b9' r'] {o : ordinal.{u}} (ho : type r = o) (ho' : type r' = o)\n  (f : \u03a0 a < o, ordinal.{max u v}) :\n  sup (family_of_bfamily' r ho f) = sup (family_of_bfamily' r' ho' f) :=\nsup_eq_of_range_eq.{u u v} (by simp)\n\n/-- The supremum of a family of ordinals indexed by the set of ordinals less than some\n    `o : ordinal.{u}`. This is a special case of `sup` over the family provided by\n    `family_of_bfamily`. -/\ndef bsup (o : ordinal.{u}) (f : \u03a0 a < o, ordinal.{max u v}) : ordinal.{max u v} :=\nsup (family_of_bfamily o f)\n\n@[simp] theorem sup_eq_bsup {o} (f : \u03a0 a < o, ordinal) : sup (family_of_bfamily o f) = bsup o f :=\nrfl\n\n@[simp] theorem sup_eq_bsup' {o \u03b9} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] (ho : type r = o) (f) :\n  sup (family_of_bfamily' r ho f) = bsup o f :=\nsup_eq_sup r _ ho _ f\n\n@[simp] theorem Sup_eq_bsup {o} (f : \u03a0 a < o, ordinal) : Sup (brange o f) = bsup o f :=\nby { congr, rw range_family_of_bfamily }\n\n@[simp] theorem bsup_eq_sup' {\u03b9} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] (f : \u03b9 \u2192 ordinal) :\n  bsup _ (bfamily_of_family' r f) = sup f :=\nby simp only [\u2190sup_eq_bsup' r, enum_typein, family_of_bfamily', bfamily_of_family']\n\ntheorem bsup_eq_bsup {\u03b9 : Type u} (r r' : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] [is_well_order \u03b9 r']\n  (f : \u03b9 \u2192 ordinal) : bsup _ (bfamily_of_family' r f) = bsup _ (bfamily_of_family' r' f) :=\nby rw [bsup_eq_sup', bsup_eq_sup']\n\n@[simp] theorem bsup_eq_sup {\u03b9} (f : \u03b9 \u2192 ordinal) : bsup _ (bfamily_of_family f) = sup f :=\nbsup_eq_sup' _ f\n\n@[congr] lemma bsup_congr {o\u2081 o\u2082 : ordinal} (f : \u03a0 a < o\u2081, ordinal) (ho : o\u2081 = o\u2082) :\n  bsup o\u2081 f = bsup o\u2082 (\u03bb a h, f a (h.trans_eq ho.symm)) :=\nby subst ho\n\ntheorem bsup_le_iff {o f a} : bsup.{u v} o f \u2264 a \u2194 \u2200 i h, f i h \u2264 a :=\nsup_le_iff.trans \u27e8\u03bb h i hi, by { rw \u2190family_of_bfamily_enum o f, exact h _ }, \u03bb h i, h _ _\u27e9\n\ntheorem bsup_le {o : ordinal} {f : \u03a0 b < o, ordinal} {a} :\n  (\u2200 i h, f i h \u2264 a) \u2192 bsup.{u v} o f \u2264 a :=\nbsup_le_iff.2\n\ntheorem le_bsup {o} (f : \u03a0 a < o, ordinal) (i h) : f i h \u2264 bsup o f :=\nbsup_le_iff.1 le_rfl _ _\n\ntheorem lt_bsup {o} (f : \u03a0 a < o, ordinal) {a} : a < bsup o f \u2194 \u2203 i hi, a < f i hi :=\nby simpa only [not_forall, not_le] using not_congr (@bsup_le_iff _ f a)\n\ntheorem is_normal.bsup {f} (H : is_normal f) {o} :\n  \u2200 (g : \u03a0 a < o, ordinal) (h : o \u2260 0), f (bsup o g) = bsup o (\u03bb a h, f (g a h)) :=\ninduction_on o $ \u03bb \u03b1 r _ g h, begin\n  resetI,\n  haveI := type_ne_zero_iff_nonempty.1 h,\n  rw [\u2190sup_eq_bsup' r, H.sup, \u2190sup_eq_bsup' r];\n  refl\nend\n\ntheorem lt_bsup_of_ne_bsup {o : ordinal} {f : \u03a0 a < o, ordinal} :\n  (\u2200 i h, f i h \u2260 o.bsup f) \u2194 \u2200 i h, f i h < o.bsup f :=\n\u27e8\u03bb hf _ _, lt_of_le_of_ne (le_bsup _ _ _) (hf _ _), \u03bb hf _ _, ne_of_lt (hf _ _)\u27e9\n\ntheorem bsup_not_succ_of_ne_bsup {o} {f : \u03a0 a < o, ordinal}\n  (hf : \u2200 {i : ordinal} (h : i < o), f i h \u2260 o.bsup f) (a) :\n  a < bsup o f \u2192 succ a < bsup o f :=\nby { rw \u2190sup_eq_bsup at *, exact sup_not_succ_of_ne_sup (\u03bb i, hf _) }\n\n@[simp] theorem bsup_eq_zero_iff {o} {f : \u03a0 a < o, ordinal} : bsup o f = 0 \u2194 \u2200 i hi, f i hi = 0 :=\nbegin\n  refine \u27e8\u03bb h i hi, _, \u03bb h, le_antisymm\n    (bsup_le (\u03bb i hi, ordinal.le_zero.2 (h i hi))) (ordinal.zero_le _)\u27e9,\n  rw [\u2190ordinal.le_zero, \u2190h],\n  exact le_bsup f i hi,\nend\n\ntheorem lt_bsup_of_limit {o : ordinal} {f : \u03a0 a < o, ordinal}\n  (hf : \u2200 {a a'} (ha : a < o) (ha' : a' < o), a < a' \u2192 f a ha < f a' ha')\n  (ho : \u2200 a < o, succ a < o) (i h) : f i h < bsup o f :=\n(hf _ _ $ lt_succ i).trans_le (le_bsup f (succ i) $ ho _ h)\n\ntheorem bsup_succ_of_mono {o : ordinal} {f : \u03a0 a < succ o, ordinal}\n  (hf : \u2200 {i j} hi hj, i \u2264 j \u2192 f i hi \u2264 f j hj) : bsup _ f = f o (lt_succ o) :=\nle_antisymm (bsup_le $ \u03bb i hi, hf _ _ $ le_of_lt_succ hi) (le_bsup _ _ _)\n\n@[simp] theorem bsup_zero (f : \u03a0 a < (0 : ordinal), ordinal) : bsup 0 f = 0 :=\nbsup_eq_zero_iff.2 (\u03bb i hi, (ordinal.not_lt_zero i hi).elim)\n\ntheorem bsup_const {o : ordinal} (ho : o \u2260 0) (a : ordinal) : bsup o (\u03bb _ _, a) = a :=\nle_antisymm (bsup_le (\u03bb _ _, le_rfl)) (le_bsup _ 0 (ordinal.pos_iff_ne_zero.2 ho))\n\n@[simp] theorem bsup_one (f : \u03a0 a < (1 : ordinal), ordinal) : bsup 1 f = f 0 zero_lt_one :=\nby simp_rw [\u2190sup_eq_bsup, sup_unique, family_of_bfamily, family_of_bfamily', typein_one_out]\n\ntheorem bsup_le_of_brange_subset {o o'} {f : \u03a0 a < o, ordinal} {g : \u03a0 a < o', ordinal}\n  (h : brange o f \u2286 brange o' g) : bsup.{u (max v w)} o f \u2264 bsup.{v (max u w)} o' g :=\nbsup_le $ \u03bb i hi, begin\n  obtain \u27e8j, hj, hj'\u27e9 := h \u27e8i, hi, rfl\u27e9,\n  rw \u2190hj',\n  apply le_bsup\nend\n\ntheorem bsup_eq_of_brange_eq {o o'} {f : \u03a0 a < o, ordinal} {g : \u03a0 a < o', ordinal}\n  (h : brange o f = brange o' g) : bsup.{u (max v w)} o f = bsup.{v (max u w)} o' g :=\n(bsup_le_of_brange_subset h.le).antisymm (bsup_le_of_brange_subset.{v u w} h.ge)\n\n/-- The least strict upper bound of a family of ordinals. -/\ndef lsub {\u03b9} (f : \u03b9 \u2192 ordinal) : ordinal := sup (succ \u2218 f)\n\n@[simp] theorem sup_eq_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) : sup (succ \u2218 f) = lsub f := rfl\n\ntheorem lsub_le_iff {\u03b9} {f : \u03b9 \u2192 ordinal} {a} : lsub f \u2264 a \u2194 \u2200 i, f i < a :=\nby { convert sup_le_iff, simp only [succ_le_iff] }\n\ntheorem lsub_le {\u03b9} {f : \u03b9 \u2192 ordinal} {a} : (\u2200 i, f i < a) \u2192 lsub f \u2264 a :=\nlsub_le_iff.2\n\ntheorem lt_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) (i) : f i < lsub f :=\nsucc_le_iff.1 (le_sup _ i)\n\ntheorem lt_lsub_iff {\u03b9} {f : \u03b9 \u2192 ordinal} {a} : a < lsub f \u2194 \u2203 i, a \u2264 f i :=\nby simpa only [not_forall, not_lt, not_le] using not_congr (@lsub_le_iff _ f a)\n\ntheorem sup_le_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) : sup f \u2264 lsub f :=\nsup_le $ \u03bb i, (lt_lsub f i).le\n\ntheorem lsub_le_sup_succ {\u03b9} (f : \u03b9 \u2192 ordinal) : lsub f \u2264 succ (sup f) :=\nlsub_le $ \u03bb i, lt_succ_iff.2 (le_sup f i)\n\ntheorem sup_eq_lsub_or_sup_succ_eq_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) :\n  sup f = lsub f \u2228 succ (sup f) = lsub f :=\nbegin\n  cases eq_or_lt_of_le (sup_le_lsub f),\n  { exact or.inl h },\n  { exact or.inr ((succ_le_of_lt h).antisymm (lsub_le_sup_succ f)) }\nend\n\ntheorem sup_succ_le_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) : succ (sup f) \u2264 lsub f \u2194 \u2203 i, f i = sup f :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { by_contra' hf,\n    exact (succ_le_iff.1 h).ne ((sup_le_lsub f).antisymm\n      (lsub_le (ne_sup_iff_lt_sup.1 hf))) },\n  rintro \u27e8_, hf\u27e9,\n  rw [succ_le_iff, \u2190hf],\n  exact lt_lsub _ _\nend\n\ntheorem sup_succ_eq_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) : succ (sup f) = lsub f \u2194 \u2203 i, f i = sup f :=\n(lsub_le_sup_succ f).le_iff_eq.symm.trans (sup_succ_le_lsub f)\n\ntheorem sup_eq_lsub_iff_succ {\u03b9} (f : \u03b9 \u2192 ordinal) :\n  sup f = lsub f \u2194 \u2200 a < lsub f, succ a < lsub f :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb hf, le_antisymm (sup_le_lsub f) (lsub_le (\u03bb i, _))\u27e9,\n  { rw \u2190h,\n    exact \u03bb a, sup_not_succ_of_ne_sup (\u03bb i, (lsub_le_iff.1 (le_of_eq h.symm) i).ne) },\n  by_contra' hle,\n  have heq := (sup_succ_eq_lsub f).2 \u27e8i, le_antisymm (le_sup _ _) hle\u27e9,\n  have := hf _ (by { rw \u2190heq, exact lt_succ (sup f) }),\n  rw heq at this,\n  exact this.false\nend\n\ntheorem sup_eq_lsub_iff_lt_sup {\u03b9} (f : \u03b9 \u2192 ordinal) : sup f = lsub f \u2194 \u2200 i, f i < sup f :=\n\u27e8\u03bb h i, (by { rw h, apply lt_lsub }), \u03bb h, le_antisymm (sup_le_lsub f) (lsub_le h)\u27e9\n\n@[simp] lemma lsub_empty {\u03b9} [h : is_empty \u03b9] (f : \u03b9 \u2192 ordinal) : lsub f = 0 :=\nby { rw [\u2190ordinal.le_zero, lsub_le_iff], exact h.elim }\n\nlemma lsub_pos {\u03b9} [h : nonempty \u03b9] (f : \u03b9 \u2192 ordinal) : 0 < lsub f :=\nh.elim $ \u03bb i, (ordinal.zero_le _).trans_lt (lt_lsub f i)\n\n@[simp] theorem lsub_eq_zero_iff {\u03b9} {f : \u03b9 \u2192 ordinal} : lsub f = 0 \u2194 is_empty \u03b9 :=\nbegin\n  refine \u27e8\u03bb h, \u27e8\u03bb i, _\u27e9, \u03bb h, @lsub_empty _ h _\u27e9,\n  have := @lsub_pos _ \u27e8i\u27e9 f,\n  rw h at this,\n  exact this.false\nend\n\n@[simp] theorem lsub_const {\u03b9} [h\u03b9 : nonempty \u03b9] (o : ordinal) : lsub (\u03bb _ : \u03b9, o) = succ o :=\nsup_const (succ o)\n\n@[simp] theorem lsub_unique {\u03b9} [h\u03b9 : unique \u03b9] (f : \u03b9 \u2192 ordinal) : lsub f = succ (f default) :=\nsup_unique _\n\ntheorem lsub_le_of_range_subset {\u03b9 \u03b9'} {f : \u03b9 \u2192 ordinal} {g : \u03b9' \u2192 ordinal}\n  (h : set.range f \u2286 set.range g) : lsub.{u (max v w)} f \u2264 lsub.{v (max u w)} g :=\nsup_le_of_range_subset (by convert set.image_subset _ h; apply set.range_comp)\n\ntheorem lsub_eq_of_range_eq {\u03b9 \u03b9'} {f : \u03b9 \u2192 ordinal} {g : \u03b9' \u2192 ordinal}\n  (h : set.range f = set.range g) : lsub.{u (max v w)} f = lsub.{v (max u w)} g :=\n(lsub_le_of_range_subset h.le).antisymm (lsub_le_of_range_subset.{v u w} h.ge)\n\n@[simp] theorem lsub_sum {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2295 \u03b2 \u2192 ordinal) : lsub.{(max u v) w} f =\n  max (lsub.{u (max v w)} (\u03bb a, f (sum.inl a))) (lsub.{v (max u w)} (\u03bb b, f (sum.inr b))) :=\nsup_sum _\n\ntheorem lsub_not_mem_range {\u03b9} (f : \u03b9 \u2192 ordinal) : lsub f \u2209 set.range f :=\n\u03bb \u27e8i, h\u27e9, h.not_lt (lt_lsub f i)\n\ntheorem nonempty_compl_range {\u03b9 : Type u} (f : \u03b9 \u2192 ordinal.{max u v}) : (set.range f)\u1d9c.nonempty :=\n\u27e8_, lsub_not_mem_range f\u27e9\n\n@[simp] theorem lsub_typein (o : ordinal) :\n  lsub.{u u} (typein ((<) : o.out.\u03b1 \u2192 o.out.\u03b1 \u2192 Prop)) = o :=\n(lsub_le.{u u} typein_lt_self).antisymm begin\n  by_contra' h,\n  nth_rewrite 0 \u2190type_lt o at h,\n  simpa [typein_enum] using lt_lsub.{u u} (typein (<)) (enum (<) _ h)\nend\n\ntheorem sup_typein_limit {o : ordinal} (ho : \u2200 a, a < o \u2192 succ a < o) :\n  sup.{u u} (typein ((<) : o.out.\u03b1 \u2192 o.out.\u03b1 \u2192 Prop)) = o :=\nby rw (sup_eq_lsub_iff_succ.{u u} (typein (<))).2; rwa lsub_typein o\n\n@[simp] theorem sup_typein_succ {o : ordinal} :\n  sup.{u u} (typein ((<) : (succ o).out.\u03b1 \u2192 (succ o).out.\u03b1 \u2192 Prop)) = o :=\nbegin\n  cases sup_eq_lsub_or_sup_succ_eq_lsub.{u u}\n    (typein ((<) : (succ o).out.\u03b1 \u2192 (succ o).out.\u03b1 \u2192 Prop)) with h h,\n  { rw sup_eq_lsub_iff_succ at h,\n    simp only [lsub_typein] at h,\n    exact (h o (lt_succ o)).false.elim },\n  rw [\u2190succ_eq_succ_iff, h],\n  apply lsub_typein\nend\n\n/-- The least strict upper bound of a family of ordinals indexed by the set of ordinals less than\n    some `o : ordinal.{u}`.\n\n    This is to `lsub` as `bsup` is to `sup`. -/\ndef blsub (o : ordinal.{u}) (f : \u03a0 a < o, ordinal.{max u v}) : ordinal.{max u v} :=\no.bsup (\u03bb a ha, succ (f a ha))\n\n@[simp] theorem bsup_eq_blsub (o : ordinal) (f : \u03a0 a < o, ordinal) :\n  bsup o (\u03bb a ha, succ (f a ha)) = blsub o f :=\nrfl\n\ntheorem lsub_eq_blsub' {\u03b9} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] {o} (ho : type r = o) (f) :\n  lsub (family_of_bfamily' r ho f) = blsub o f :=\nsup_eq_bsup' r ho (\u03bb a ha, succ (f a ha))\n\ntheorem lsub_eq_lsub {\u03b9 \u03b9' : Type u} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) (r' : \u03b9' \u2192 \u03b9' \u2192 Prop)\n  [is_well_order \u03b9 r] [is_well_order \u03b9' r'] {o} (ho : type r = o) (ho' : type r' = o)\n  (f : \u03a0 a < o, ordinal) : lsub (family_of_bfamily' r ho f) = lsub (family_of_bfamily' r' ho' f) :=\nby rw [lsub_eq_blsub', lsub_eq_blsub']\n\n@[simp] theorem lsub_eq_blsub {o} (f : \u03a0 a < o, ordinal) :\n  lsub (family_of_bfamily o f) = blsub o f :=\nlsub_eq_blsub' _ _ _\n\n@[simp] theorem blsub_eq_lsub' {\u03b9} (r : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] (f : \u03b9 \u2192 ordinal) :\n  blsub _ (bfamily_of_family' r f) = lsub f :=\nbsup_eq_sup' r (succ \u2218 f)\n\ntheorem blsub_eq_blsub {\u03b9 : Type u} (r r' : \u03b9 \u2192 \u03b9 \u2192 Prop) [is_well_order \u03b9 r] [is_well_order \u03b9 r']\n  (f : \u03b9 \u2192 ordinal) : blsub _ (bfamily_of_family' r f) = blsub _ (bfamily_of_family' r' f) :=\nby rw [blsub_eq_lsub', blsub_eq_lsub']\n\n@[simp] theorem blsub_eq_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) : blsub _ (bfamily_of_family f) = lsub f :=\nblsub_eq_lsub' _ _\n\n@[congr] lemma blsub_congr {o\u2081 o\u2082 : ordinal} (f : \u03a0 a < o\u2081, ordinal) (ho : o\u2081 = o\u2082) :\n  blsub o\u2081 f = blsub o\u2082 (\u03bb a h, f a (h.trans_eq ho.symm)) :=\nby subst ho\n\ntheorem blsub_le_iff {o f a} : blsub o f \u2264 a \u2194 \u2200 i h, f i h < a :=\nby { convert bsup_le_iff, simp [succ_le_iff] }\n\ntheorem blsub_le {o : ordinal} {f : \u03a0 b < o, ordinal} {a} : (\u2200 i h, f i h < a) \u2192 blsub o f \u2264 a :=\nblsub_le_iff.2\n\ntheorem lt_blsub {o} (f : \u03a0 a < o, ordinal) (i h) : f i h < blsub o f :=\nblsub_le_iff.1 le_rfl _ _\n\ntheorem lt_blsub_iff {o f a} : a < blsub o f \u2194 \u2203 i hi, a \u2264 f i hi :=\nby simpa only [not_forall, not_lt, not_le] using not_congr (@blsub_le_iff _ f a)\n\ntheorem bsup_le_blsub {o} (f : \u03a0 a < o, ordinal) : bsup o f \u2264 blsub o f :=\nbsup_le (\u03bb i h, (lt_blsub f i h).le)\n\ntheorem blsub_le_bsup_succ {o} (f : \u03a0 a < o, ordinal) : blsub o f \u2264 succ (bsup o f) :=\nblsub_le (\u03bb i h, lt_succ_iff.2 (le_bsup f i h))\n\ntheorem bsup_eq_blsub_or_succ_bsup_eq_blsub {o} (f : \u03a0 a < o, ordinal) :\n  bsup o f = blsub o f \u2228 succ (bsup o f) = blsub o f :=\nby { rw [\u2190sup_eq_bsup, \u2190lsub_eq_blsub], exact sup_eq_lsub_or_sup_succ_eq_lsub _ }\n\ntheorem bsup_succ_le_blsub {o} (f : \u03a0 a < o, ordinal) :\n  succ (bsup o f) \u2264 blsub o f \u2194 \u2203 i hi, f i hi = bsup o f :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { by_contra' hf,\n    exact ne_of_lt (succ_le_iff.1 h) (le_antisymm (bsup_le_blsub f)\n      (blsub_le (lt_bsup_of_ne_bsup.1 hf))) },\n  rintro \u27e8_, _, hf\u27e9,\n  rw [succ_le_iff, \u2190hf],\n  exact lt_blsub _ _ _\nend\n\ntheorem bsup_succ_eq_blsub {o} (f : \u03a0 a < o, ordinal) :\n  succ (bsup o f) = blsub o f \u2194 \u2203 i hi, f i hi = bsup o f :=\n(blsub_le_bsup_succ f).le_iff_eq.symm.trans (bsup_succ_le_blsub f)\n\ntheorem bsup_eq_blsub_iff_succ {o} (f : \u03a0 a < o, ordinal) :\n  bsup o f = blsub o f \u2194 \u2200 a < blsub o f, succ a < blsub o f :=\nby { rw [\u2190sup_eq_bsup, \u2190lsub_eq_blsub], apply sup_eq_lsub_iff_succ }\n\ntheorem bsup_eq_blsub_iff_lt_bsup {o} (f : \u03a0 a < o, ordinal) :\n  bsup o f = blsub o f \u2194 \u2200 i hi, f i hi < bsup o f :=\n\u27e8\u03bb h i, (by { rw h, apply lt_blsub }), \u03bb h, le_antisymm (bsup_le_blsub f) (blsub_le h)\u27e9\n\ntheorem bsup_eq_blsub_of_lt_succ_limit {o} (ho : is_limit o) {f : \u03a0 a < o, ordinal}\n  (hf : \u2200 a ha, f a ha < f (succ a) (ho.2 a ha)) : bsup o f = blsub o f :=\nbegin\n  rw bsup_eq_blsub_iff_lt_bsup,\n  exact \u03bb i hi, (hf i hi).trans_le (le_bsup f _ _)\nend\n\ntheorem blsub_succ_of_mono {o : ordinal} {f : \u03a0 a < succ o, ordinal}\n  (hf : \u2200 {i j} hi hj, i \u2264 j \u2192 f i hi \u2264 f j hj) : blsub _ f = succ (f o (lt_succ o)) :=\nbsup_succ_of_mono $ \u03bb i j hi hj h, succ_le_succ (hf hi hj h)\n\n@[simp] theorem blsub_eq_zero_iff {o} {f : \u03a0 a < o, ordinal} : blsub o f = 0 \u2194 o = 0 :=\nby { rw [\u2190lsub_eq_blsub, lsub_eq_zero_iff], exact out_empty_iff_eq_zero }\n\n@[simp] lemma blsub_zero (f : \u03a0 a < (0 : ordinal), ordinal) : blsub 0 f = 0 :=\nby rwa blsub_eq_zero_iff\n\nlemma blsub_pos {o : ordinal} (ho : 0 < o) (f : \u03a0 a < o, ordinal) : 0 < blsub o f :=\n(ordinal.zero_le _).trans_lt (lt_blsub f 0 ho)\n\ntheorem blsub_type (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (f) :\n  blsub (type r) f = lsub (\u03bb a, f (typein r a) (typein_lt_type _ _)) :=\neq_of_forall_ge_iff $ \u03bb o,\nby rw [blsub_le_iff, lsub_le_iff]; exact\n  \u27e8\u03bb H b, H _ _, \u03bb H i h, by simpa only [typein_enum] using H (enum r i h)\u27e9\n\ntheorem blsub_const {o : ordinal} (ho : o \u2260 0) (a : ordinal) : blsub.{u v} o (\u03bb _ _, a) = succ a :=\nbsup_const.{u v} ho (succ a)\n\n@[simp] theorem blsub_one (f : \u03a0 a < (1 : ordinal), ordinal) : blsub 1 f = succ (f 0 zero_lt_one) :=\nbsup_one _\n\n@[simp] theorem blsub_id : \u2200 o, blsub.{u u} o (\u03bb x _, x) = o :=\nlsub_typein\n\ntheorem bsup_id_limit {o : ordinal} : (\u2200 a < o, succ a < o) \u2192 bsup.{u u} o (\u03bb x _, x) = o :=\nsup_typein_limit\n\n@[simp] theorem bsup_id_succ (o) : bsup.{u u} (succ o) (\u03bb x _, x) = o :=\nsup_typein_succ\n\ntheorem blsub_le_of_brange_subset {o o'} {f : \u03a0 a < o, ordinal} {g : \u03a0 a < o', ordinal}\n  (h : brange o f \u2286 brange o' g) : blsub.{u (max v w)} o f \u2264 blsub.{v (max u w)} o' g :=\nbsup_le_of_brange_subset $ \u03bb a \u27e8b, hb, hb'\u27e9, begin\n  obtain \u27e8c, hc, hc'\u27e9 := h \u27e8b, hb, rfl\u27e9,\n  simp_rw \u2190hc' at hb',\n  exact \u27e8c, hc, hb'\u27e9\nend\n\ntheorem blsub_eq_of_brange_eq {o o'} {f : \u03a0 a < o, ordinal} {g : \u03a0 a < o', ordinal}\n  (h : {o | \u2203 i hi, f i hi = o} = {o | \u2203 i hi, g i hi = o}) :\n  blsub.{u (max v w)} o f = blsub.{v (max u w)} o' g :=\n(blsub_le_of_brange_subset h.le).antisymm (blsub_le_of_brange_subset.{v u w} h.ge)\n\ntheorem bsup_comp {o o' : ordinal} {f : \u03a0 a < o, ordinal}\n  (hf : \u2200 {i j} (hi) (hj), i \u2264 j \u2192 f i hi \u2264 f j hj) {g : \u03a0 a < o', ordinal} (hg : blsub o' g = o) :\n  bsup o' (\u03bb a ha, f (g a ha) (by { rw \u2190hg, apply lt_blsub })) = bsup o f :=\nbegin\n  apply le_antisymm;\n  refine bsup_le (\u03bb i hi, _),\n  { apply le_bsup },\n  { rw [\u2190hg, lt_blsub_iff] at hi,\n    rcases hi with \u27e8j, hj, hj'\u27e9,\n    exact (hf _ _ hj').trans (le_bsup _ _ _) }\nend\n\ntheorem blsub_comp {o o' : ordinal} {f : \u03a0 a < o, ordinal}\n  (hf : \u2200 {i j} (hi) (hj), i \u2264 j \u2192 f i hi \u2264 f j hj) {g : \u03a0 a < o', ordinal} (hg : blsub o' g = o) :\n  blsub o' (\u03bb a ha, f (g a ha) (by { rw \u2190hg, apply lt_blsub })) = blsub o f :=\n@bsup_comp o _ (\u03bb a ha, succ (f a ha)) (\u03bb i j _ _ h, succ_le_succ_iff.2 (hf _ _ h)) g hg\n\ntheorem is_normal.bsup_eq {f} (H : is_normal f) {o : ordinal} (h : is_limit o) :\n  bsup.{u} o (\u03bb x _, f x) = f o :=\nby { rw [\u2190is_normal.bsup.{u u} H (\u03bb x _, x) h.1, bsup_id_limit h.2] }\n\ntheorem is_normal.blsub_eq {f} (H : is_normal f) {o : ordinal} (h : is_limit o) :\n  blsub.{u} o (\u03bb x _, f x) = f o :=\nby { rw [\u2190H.bsup_eq h, bsup_eq_blsub_of_lt_succ_limit h], exact (\u03bb a _, H.1 a) }\n\ntheorem is_normal_iff_lt_succ_and_bsup_eq {f} :\n  is_normal f \u2194 (\u2200 a, f a < f (succ a)) \u2227 \u2200 o, is_limit o \u2192 bsup o (\u03bb x _, f x) = f o :=\n\u27e8\u03bb h, \u27e8h.1, @is_normal.bsup_eq f h\u27e9, \u03bb \u27e8h\u2081, h\u2082\u27e9, \u27e8h\u2081, \u03bb o ho a,\n  (by {rw \u2190h\u2082 o ho, exact bsup_le_iff})\u27e9\u27e9\n\ntheorem is_normal_iff_lt_succ_and_blsub_eq {f} :\n  is_normal f \u2194 (\u2200 a, f a < f (succ a)) \u2227 \u2200 o, is_limit o \u2192 blsub o (\u03bb x _, f x) = f o :=\nbegin\n  rw [is_normal_iff_lt_succ_and_bsup_eq, and.congr_right_iff],\n  intro h,\n  split;\n  intros H o ho;\n  have := H o ho;\n  rwa \u2190bsup_eq_blsub_of_lt_succ_limit ho (\u03bb a _, h a) at *\nend\n\ntheorem is_normal.eq_iff_zero_and_succ {f g : ordinal.{u} \u2192 ordinal.{u}} (hf : is_normal f)\n  (hg : is_normal g) : f = g \u2194 f 0 = g 0 \u2227 \u2200 a, f a = g a \u2192 f (succ a) = g (succ a) :=\n\u27e8\u03bb h, by simp [h], \u03bb \u27e8h\u2081, h\u2082\u27e9, funext (\u03bb a, begin\n  apply a.limit_rec_on,\n  assumption',\n  intros o ho H,\n  rw [\u2190is_normal.bsup_eq.{u u} hf ho, \u2190is_normal.bsup_eq.{u u} hg ho],\n  congr,\n  ext b hb,\n  exact H b hb\nend)\u27e9\n\n/-! ### Minimum excluded ordinals -/\n\n/-- The minimum excluded ordinal in a family of ordinals. -/\ndef mex {\u03b9 : Type u} (f : \u03b9 \u2192 ordinal.{max u v}) : ordinal :=\nInf (set.range f)\u1d9c\n\ntheorem mex_not_mem_range {\u03b9 : Type u} (f : \u03b9 \u2192 ordinal.{max u v}) : mex f \u2209 set.range f :=\nInf_mem (nonempty_compl_range f)\n\ntheorem le_mex_of_forall {\u03b9 : Type u} {f : \u03b9 \u2192 ordinal.{max u v}} {a : ordinal}\n  (H : \u2200 b < a, \u2203 i, f i = b) : a \u2264 mex f :=\nby { by_contra' h, exact mex_not_mem_range f (H _ h) }\n\ntheorem ne_mex {\u03b9} (f : \u03b9 \u2192 ordinal) : \u2200 i, f i \u2260 mex f :=\nby simpa using mex_not_mem_range f\n\ntheorem mex_le_of_ne {\u03b9} {f : \u03b9 \u2192 ordinal} {a} (ha : \u2200 i, f i \u2260 a) : mex f \u2264 a :=\ncInf_le' (by simp [ha])\n\ntheorem exists_of_lt_mex {\u03b9} {f : \u03b9 \u2192 ordinal} {a} (ha : a < mex f) : \u2203 i, f i = a :=\nby { by_contra' ha', exact ha.not_le (mex_le_of_ne ha') }\n\ntheorem mex_le_lsub {\u03b9} (f : \u03b9 \u2192 ordinal) : mex f \u2264 lsub f :=\ncInf_le' (lsub_not_mem_range f)\n\ntheorem mex_monotone {\u03b1 \u03b2} {f : \u03b1 \u2192 ordinal} {g : \u03b2 \u2192 ordinal} (h : set.range f \u2286 set.range g) :\n  mex f \u2264 mex g :=\nbegin\n  refine mex_le_of_ne (\u03bb i hi, _),\n  cases h \u27e8i, rfl\u27e9 with j hj,\n  rw \u2190hj at hi,\n  exact ne_mex g j hi\nend\n\ntheorem mex_lt_ord_succ_mk {\u03b9} (f : \u03b9 \u2192 ordinal) : mex f < (succ (#\u03b9)).ord :=\nbegin\n  by_contra' h,\n  apply (lt_succ (#\u03b9)).not_le,\n  have H := \u03bb a, exists_of_lt_mex ((typein_lt_self a).trans_le h),\n  let g : (succ (#\u03b9)).ord.out.\u03b1 \u2192 \u03b9 := \u03bb a, classical.some (H a),\n  have hg : injective g := \u03bb a b h', begin\n    have Hf : \u2200 x, f (g x) = typein (<) x := \u03bb a, classical.some_spec (H a),\n    apply_fun f at h',\n    rwa [Hf, Hf, typein_inj] at h'\n  end,\n  convert cardinal.mk_le_of_injective hg,\n  rw cardinal.mk_ord_out\nend\n\n/-- The minimum excluded ordinal of a family of ordinals indexed by the set of ordinals less than\n    some `o : ordinal.{u}`. This is a special case of `mex` over the family provided by\n    `family_of_bfamily`.\n\n    This is to `mex` as `bsup` is to `sup`. -/\ndef bmex (o : ordinal) (f : \u03a0 a < o, ordinal) : ordinal :=\nmex (family_of_bfamily o f)\n\ntheorem bmex_not_mem_brange {o : ordinal} (f : \u03a0 a < o, ordinal) : bmex o f \u2209 brange o f :=\nby { rw \u2190range_family_of_bfamily, apply mex_not_mem_range }\n\ntheorem le_bmex_of_forall {o : ordinal} (f : \u03a0 a < o, ordinal) {a : ordinal}\n  (H : \u2200 b < a, \u2203 i hi, f i hi = b) : a \u2264 bmex o f :=\nby { by_contra' h, exact bmex_not_mem_brange f (H _ h) }\n\ntheorem ne_bmex {o : ordinal} (f : \u03a0 a < o, ordinal) {i} (hi) : f i hi \u2260 bmex o f :=\nbegin\n  convert ne_mex _ (enum (<) i (by rwa type_lt)),\n  rw family_of_bfamily_enum\nend\n\ntheorem bmex_le_of_ne {o : ordinal} {f : \u03a0 a < o, ordinal} {a} (ha : \u2200 i hi, f i hi \u2260 a) :\n  bmex o f \u2264 a :=\nmex_le_of_ne (\u03bb i, ha _ _)\n\ntheorem exists_of_lt_bmex {o : ordinal} {f : \u03a0 a < o, ordinal} {a} (ha : a < bmex o f) :\n  \u2203 i hi, f i hi = a :=\nbegin\n  cases exists_of_lt_mex ha with i hi,\n  exact \u27e8_, typein_lt_self i, hi\u27e9\nend\n\ntheorem bmex_le_blsub {o : ordinal} (f : \u03a0 a < o, ordinal) : bmex o f \u2264 blsub o f :=\nmex_le_lsub _\n\ntheorem bmex_monotone {o o' : ordinal} {f : \u03a0 a < o, ordinal} {g : \u03a0 a < o', ordinal}\n  (h : brange o f \u2286 brange o' g) : bmex o f \u2264 bmex o' g :=\nmex_monotone (by rwa [range_family_of_bfamily, range_family_of_bfamily])\n\ntheorem bmex_lt_ord_succ_card {o : ordinal} (f : \u03a0 a < o, ordinal) :\n  bmex o f < (succ o.card).ord :=\nby { rw \u2190mk_ordinal_out, exact (mex_lt_ord_succ_mk (family_of_bfamily o f)) }\n\nend ordinal\n\n/-! ### Results about injectivity and surjectivity -/\n\nlemma not_surjective_of_ordinal {\u03b1 : Type u} (f : \u03b1 \u2192 ordinal.{u}) : \u00ac surjective f :=\n\u03bb h, ordinal.lsub_not_mem_range.{u u} f (h _)\n\nlemma not_injective_of_ordinal {\u03b1 : Type u} (f : ordinal.{u} \u2192 \u03b1) : \u00ac injective f :=\n\u03bb h, not_surjective_of_ordinal _ (inv_fun_surjective h)\n\nlemma not_surjective_of_ordinal_of_small {\u03b1 : Type v} [small.{u} \u03b1] (f : \u03b1 \u2192 ordinal.{u}) :\n  \u00ac surjective f :=\n\u03bb h, not_surjective_of_ordinal _ (h.comp (equiv_shrink _).symm.surjective)\n\nlemma not_injective_of_ordinal_of_small {\u03b1 : Type v} [small.{u} \u03b1] (f : ordinal.{u} \u2192 \u03b1) :\n  \u00ac injective f :=\n\u03bb h, not_injective_of_ordinal _ ((equiv_shrink _).injective.comp h)\n\n/-- The type of ordinals in universe `u` is not `small.{u}`. This is the type-theoretic analog of\nthe Burali-Forti paradox. -/\ntheorem not_small_ordinal : \u00ac small.{u} ordinal.{max u v} :=\n\u03bb h, @not_injective_of_ordinal_of_small _ h _ (\u03bb a b, ordinal.lift_inj.1)\n\n/-! ### Enumerating unbounded sets of ordinals with ordinals -/\n\nnamespace ordinal\n\nsection\n\n/-- Enumerator function for an unbounded set of ordinals. -/\ndef enum_ord (S : set ordinal.{u}) : ordinal \u2192 ordinal :=\nlt_wf.fix (\u03bb o f, Inf (S \u2229 set.Ici (blsub.{u u} o f)))\n\nvariables {S : set ordinal.{u}}\n\n/-- The equation that characterizes `enum_ord` definitionally. This isn't the nicest expression to\n    work with, so consider using `enum_ord_def` instead. -/\ntheorem enum_ord_def' (o) :\n  enum_ord S o = Inf (S \u2229 set.Ici (blsub.{u u} o (\u03bb a _, enum_ord S a))) :=\nlt_wf.fix_eq _ _\n\n/-- The set in `enum_ord_def'` is nonempty. -/\ntheorem enum_ord_def'_nonempty (hS : unbounded (<) S) (a) : (S \u2229 set.Ici a).nonempty :=\nlet \u27e8b, hb, hb'\u27e9 := hS a in \u27e8b, hb, le_of_not_gt hb'\u27e9\n\nprivate theorem enum_ord_mem_aux (hS : unbounded (<) S) (o) :\n  (enum_ord S o) \u2208 S \u2229 set.Ici (blsub.{u u} o (\u03bb c _, enum_ord S c)) :=\nby { rw enum_ord_def', exact Inf_mem (enum_ord_def'_nonempty hS _) }\n\ntheorem enum_ord_mem (hS : unbounded (<) S) (o) : enum_ord S o \u2208 S :=\n(enum_ord_mem_aux hS o).left\n\ntheorem blsub_le_enum_ord (hS : unbounded (<) S) (o) :\n  blsub.{u u} o (\u03bb c _, enum_ord S c) \u2264 enum_ord S o :=\n(enum_ord_mem_aux hS o).right\n\ntheorem enum_ord_strict_mono (hS : unbounded (<) S) : strict_mono (enum_ord S) :=\n\u03bb _ _ h, (lt_blsub.{u u} _ _ h).trans_le (blsub_le_enum_ord hS _)\n\n/-- A more workable definition for `enum_ord`. -/\ntheorem enum_ord_def (o) :\n  enum_ord S o = Inf (S \u2229 {b | \u2200 c, c < o \u2192 enum_ord S c < b}) :=\nbegin\n  rw enum_ord_def',\n  congr, ext,\n  exact \u27e8\u03bb h a hao, (lt_blsub.{u u} _ _ hao).trans_le h, blsub_le\u27e9\nend\n\n/-- The set in `enum_ord_def` is nonempty. -/\nlemma enum_ord_def_nonempty (hS : unbounded (<) S) {o} :\n  {x | x \u2208 S \u2227 \u2200 c, c < o \u2192 enum_ord S c < x}.nonempty :=\n(\u27e8_, enum_ord_mem hS o, \u03bb _ b, enum_ord_strict_mono hS b\u27e9)\n\n@[simp] theorem enum_ord_range {f : ordinal \u2192 ordinal} (hf : strict_mono f) :\n  enum_ord (range f) = f :=\nfunext (\u03bb o, begin\n  apply ordinal.induction o,\n  intros a H,\n  rw enum_ord_def a,\n  have Hfa : f a \u2208 range f \u2229 {b | \u2200 c, c < a \u2192 enum_ord (range f) c < b} :=\n    \u27e8mem_range_self a, \u03bb b hb, (by {rw H b hb, exact hf hb})\u27e9,\n  refine (cInf_le' Hfa).antisymm ((le_cInf_iff'' \u27e8_, Hfa\u27e9).2 _),\n  rintros _ \u27e8\u27e8c, rfl\u27e9, hc : \u2200 b < a, enum_ord (range f) b < f c\u27e9,\n  rw hf.le_iff_le,\n  contrapose! hc,\n  exact \u27e8c, hc, (H c hc).ge\u27e9,\nend)\n\n@[simp] theorem enum_ord_univ : enum_ord set.univ = id :=\nby { rw \u2190range_id, exact enum_ord_range strict_mono_id }\n\n@[simp] theorem enum_ord_zero : enum_ord S 0 = Inf S :=\nby { rw enum_ord_def, simp [ordinal.not_lt_zero] }\n\ntheorem enum_ord_succ_le {a b} (hS : unbounded (<) S) (ha : a \u2208 S) (hb : enum_ord S b < a) :\n  enum_ord S (succ b) \u2264 a :=\nbegin\n  rw enum_ord_def,\n  exact cInf_le' \u27e8ha, \u03bb c hc, ((enum_ord_strict_mono hS).monotone (le_of_lt_succ hc)).trans_lt hb\u27e9\nend\n\ntheorem enum_ord_le_of_subset {S T : set ordinal} (hS : unbounded (<) S) (hST : S \u2286 T) (a) :\n  enum_ord T a \u2264 enum_ord S a :=\nbegin\n  apply ordinal.induction a,\n  intros b H,\n  rw enum_ord_def,\n  exact cInf_le' \u27e8hST (enum_ord_mem hS b), \u03bb c h, (H c h).trans_lt (enum_ord_strict_mono hS h)\u27e9\nend\n\ntheorem enum_ord_surjective (hS : unbounded (<) S) : \u2200 s \u2208 S, \u2203 a, enum_ord S a = s :=\n\u03bb s hs, \u27e8Sup {a | enum_ord S a \u2264 s}, begin\n  apply le_antisymm,\n  { rw enum_ord_def,\n    refine cInf_le' \u27e8hs, \u03bb a ha, _\u27e9,\n    have : enum_ord S 0 \u2264 s := by { rw enum_ord_zero, exact cInf_le' hs },\n    rcases exists_lt_of_lt_cSup (by exact \u27e80, this\u27e9) ha with \u27e8b, hb, hab\u27e9,\n    exact (enum_ord_strict_mono hS hab).trans_le hb },\n  { by_contra' h,\n    exact (le_cSup \u27e8s, \u03bb a,\n      (lt_wf.self_le_of_strict_mono (enum_ord_strict_mono hS) a).trans\u27e9\n      (enum_ord_succ_le hS hs h)).not_lt (lt_succ _) }\nend\u27e9\n\n/-- An order isomorphism between an unbounded set of ordinals and the ordinals. -/\ndef enum_ord_order_iso (hS : unbounded (<) S) : ordinal \u2243o S :=\nstrict_mono.order_iso_of_surjective (\u03bb o, \u27e8_, enum_ord_mem hS o\u27e9) (enum_ord_strict_mono hS)\n  (\u03bb s, let \u27e8a, ha\u27e9 := enum_ord_surjective hS s s.prop in \u27e8a, subtype.eq ha\u27e9)\n\ntheorem range_enum_ord (hS : unbounded (<) S) : range (enum_ord S) = S :=\nby { rw range_eq_iff, exact \u27e8enum_ord_mem hS, enum_ord_surjective hS\u27e9 }\n\n/-- A characterization of `enum_ord`: it is the unique strict monotonic function with range `S`. -/\ntheorem eq_enum_ord (f : ordinal \u2192 ordinal) (hS : unbounded (<) S) :\n  strict_mono f \u2227 range f = S \u2194 f = enum_ord S :=\nbegin\n  split,\n  { rintro \u27e8h\u2081, h\u2082\u27e9,\n    rwa [\u2190lt_wf.eq_strict_mono_iff_eq_range h\u2081 (enum_ord_strict_mono hS), range_enum_ord hS] },\n  { rintro rfl,\n    exact \u27e8enum_ord_strict_mono hS, range_enum_ord hS\u27e9 }\nend\n\nend\n\n\n/-! ### Casting naturals into ordinals, compatibility with operations -/\n\n@[simp] theorem one_add_nat_cast (m : \u2115) : 1 + (m : ordinal) = succ m :=\nby { rw [\u2190nat.cast_one, \u2190nat.cast_add, add_comm], refl }\n\n@[simp, norm_cast] theorem nat_cast_mul (m : \u2115) : \u2200 n : \u2115, ((m * n : \u2115) : ordinal) = m * n\n| 0     := by simp\n| (n+1) := by rw [nat.mul_succ, nat.cast_add, nat_cast_mul, nat.cast_succ, mul_add_one]\n\n@[simp, norm_cast] theorem nat_cast_le {m n : \u2115} : (m : ordinal) \u2264 n \u2194 m \u2264 n :=\nby rw [\u2190cardinal.ord_nat, \u2190cardinal.ord_nat, cardinal.ord_le_ord, cardinal.nat_cast_le]\n\n@[simp, norm_cast] theorem nat_cast_lt {m n : \u2115} : (m : ordinal) < n \u2194 m < n :=\nby simp only [lt_iff_le_not_le, nat_cast_le]\n\n@[simp, norm_cast] theorem nat_cast_inj {m n : \u2115} : (m : ordinal) = n \u2194 m = n :=\nby simp only [le_antisymm_iff, nat_cast_le]\n\n@[simp, norm_cast] theorem nat_cast_eq_zero {n : \u2115} : (n : ordinal) = 0 \u2194 n = 0 :=\n@nat_cast_inj n 0\n\ntheorem nat_cast_ne_zero {n : \u2115} : (n : ordinal) \u2260 0 \u2194 n \u2260 0 :=\nnot_congr nat_cast_eq_zero\n\n@[simp, norm_cast] theorem nat_cast_pos {n : \u2115} : (0 : ordinal) < n \u2194 0 < n :=\n@nat_cast_lt 0 n\n\n@[simp, norm_cast] theorem nat_cast_sub (m n : \u2115) : ((m - n : \u2115) : ordinal) = m - n :=\nbegin\n  cases le_total m n with h h,\n  { rw [tsub_eq_zero_iff_le.2 h, ordinal.sub_eq_zero_iff_le.2 (nat_cast_le.2 h)],\n    refl },\n  { apply (add_left_cancel n).1,\n    rw [\u2190nat.cast_add, add_tsub_cancel_of_le h, ordinal.add_sub_cancel_of_le (nat_cast_le.2 h)] }\nend\n\n@[simp, norm_cast] theorem nat_cast_div (m n : \u2115) : ((m / n : \u2115) : ordinal) = m / n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  { have hn' := nat_cast_ne_zero.2 hn,\n    apply le_antisymm,\n    { rw [le_div hn', \u2190nat_cast_mul, nat_cast_le, mul_comm],\n      apply nat.div_mul_le_self },\n    { rw [div_le hn', \u2190add_one_eq_succ, \u2190nat.cast_succ, \u2190nat_cast_mul, nat_cast_lt, mul_comm,\n        \u2190nat.div_lt_iff_lt_mul (nat.pos_of_ne_zero hn)],\n      apply nat.lt_succ_self } }\nend\n\n@[simp, norm_cast] theorem nat_cast_mod (m n : \u2115) : ((m % n : \u2115) : ordinal) = m % n :=\nby rw [\u2190add_left_cancel, div_add_mod, \u2190nat_cast_div, \u2190nat_cast_mul, \u2190nat.cast_add, nat.div_add_mod]\n\n@[simp] theorem lift_nat_cast : \u2200 n : \u2115, lift.{u v} n = n\n| 0     := by simp\n| (n+1) := by simp [lift_nat_cast n]\n\nend ordinal\n\n/-! ### Properties of `omega` -/\n\nnamespace cardinal\nopen ordinal\n\n@[simp] theorem ord_aleph_0 : ord.{u} \u2135\u2080 = \u03c9 :=\nle_antisymm (ord_le.2 $ le_rfl) $\nle_of_forall_lt $ \u03bb o h, begin\n  rcases ordinal.lt_lift_iff.1 h with \u27e8o, rfl, h'\u27e9,\n  rw [lt_ord, \u2190lift_card, \u2190lift_aleph_0.{0 u}, lift_lt, \u2190typein_enum (<) h'],\n  exact lt_aleph_0_iff_fintype.2 \u27e8set.fintype_lt_nat _\u27e9\nend\n\n@[simp] theorem add_one_of_aleph_0_le {c} (h : \u2135\u2080 \u2264 c) : c + 1 = c :=\nbegin\n  rw [add_comm, \u2190card_ord c, \u2190card_one, \u2190card_add, one_add_of_omega_le],\n  rwa [\u2190ord_aleph_0, ord_le_ord]\nend\n\nend cardinal\n\nnamespace ordinal\n\ntheorem lt_add_of_limit {a b c : ordinal.{u}}\n  (h : is_limit c) : a < b + c \u2194 \u2203 c' < c, a < b + c' :=\nby rw [\u2190is_normal.bsup_eq.{u u} (add_is_normal b) h, lt_bsup]\n\ntheorem lt_omega {o : ordinal} : o < \u03c9 \u2194 \u2203 n : \u2115, o = n :=\nby simp_rw [\u2190cardinal.ord_aleph_0, cardinal.lt_ord, lt_aleph_0, card_eq_nat]\n\ntheorem nat_lt_omega (n : \u2115) : \u2191n < \u03c9 :=\nlt_omega.2 \u27e8_, rfl\u27e9\n\ntheorem omega_pos : 0 < \u03c9 := nat_lt_omega 0\n\ntheorem omega_ne_zero : \u03c9 \u2260 0 := omega_pos.ne'\n\ntheorem one_lt_omega : 1 < \u03c9 := by simpa only [nat.cast_one] using nat_lt_omega 1\n\ntheorem omega_is_limit : is_limit \u03c9 :=\n\u27e8omega_ne_zero, \u03bb o h,\n  let \u27e8n, e\u27e9 := lt_omega.1 h in\n  by rw [e]; exact nat_lt_omega (n+1)\u27e9\n\ntheorem omega_le {o : ordinal} : \u03c9 \u2264 o \u2194 \u2200 n : \u2115, \u2191n \u2264 o :=\n\u27e8\u03bb h n, (nat_lt_omega _).le.trans h,\n \u03bb H, le_of_forall_lt $ \u03bb a h,\n   let \u27e8n, e\u27e9 := lt_omega.1 h in\n   by rw [e, \u2190succ_le_iff]; exact H (n+1)\u27e9\n\n@[simp] theorem sup_nat_cast : sup nat.cast = \u03c9 :=\n(sup_le $ \u03bb n, (nat_lt_omega n).le).antisymm $ omega_le.2 $ le_sup _\n\ntheorem nat_lt_limit {o} (h : is_limit o) : \u2200 n : \u2115, \u2191n < o\n| 0     := lt_of_le_of_ne (ordinal.zero_le o) h.1.symm\n| (n+1) := h.2 _ (nat_lt_limit n)\n\ntheorem omega_le_of_is_limit {o} (h : is_limit o) : \u03c9 \u2264 o :=\nomega_le.2 $ \u03bb n, le_of_lt $ nat_lt_limit h n\n\ntheorem is_limit_iff_omega_dvd {a : ordinal} : is_limit a \u2194 a \u2260 0 \u2227 \u03c9 \u2223 a :=\nbegin\n  refine \u27e8\u03bb l, \u27e8l.1, \u27e8a / \u03c9, le_antisymm _ (mul_div_le _ _)\u27e9\u27e9, \u03bb h, _\u27e9,\n  { refine (limit_le l).2 (\u03bb x hx, le_of_lt _),\n    rw [\u2190div_lt omega_ne_zero, \u2190succ_le_iff, le_div omega_ne_zero, mul_succ,\n      add_le_of_limit omega_is_limit],\n    intros b hb,\n    rcases lt_omega.1 hb with \u27e8n, rfl\u27e9,\n    exact (add_le_add_right (mul_div_le _ _) _).trans\n      (lt_sub.1 $ nat_lt_limit (sub_is_limit l hx) _).le },\n  { rcases h with \u27e8a0, b, rfl\u27e9,\n    refine mul_is_limit_left omega_is_limit (ordinal.pos_iff_ne_zero.2 $ mt _ a0),\n    intro e, simp only [e, mul_zero] }\nend\n\ntheorem add_mul_limit_aux {a b c : ordinal} (ba : b + a = a)\n  (l : is_limit c)\n  (IH : \u2200 c' < c, (a + b) * succ c' = a * succ c' + b) :\n  (a + b) * c = a * c :=\nle_antisymm\n  ((mul_le_of_limit l).2 $ \u03bb c' h, begin\n    apply (mul_le_mul_left' (le_succ c') _).trans,\n    rw IH _ h,\n    apply (add_le_add_left _ _).trans,\n    { rw \u2190 mul_succ, exact mul_le_mul_left' (succ_le_of_lt $ l.2 _ h) _ },\n    { apply_instance },\n    { rw \u2190 ba, exact le_add_right _ _ }\n  end)\n  (mul_le_mul_right' (le_add_right _ _) _)\n\ntheorem add_mul_succ {a b : ordinal} (c) (ba : b + a = a) :\n  (a + b) * succ c = a * succ c + b :=\nbegin\n  apply limit_rec_on c,\n  { simp only [succ_zero, mul_one] },\n  { intros c IH,\n    rw [mul_succ, IH, \u2190 add_assoc, add_assoc _ b, ba, \u2190 mul_succ] },\n  { intros c l IH,\n    have := add_mul_limit_aux ba l IH,\n    rw [mul_succ, add_mul_limit_aux ba l IH, mul_succ, add_assoc] }\nend\n\ntheorem add_mul_limit {a b c : ordinal} (ba : b + a = a)\n  (l : is_limit c) : (a + b) * c = a * c :=\nadd_mul_limit_aux ba l (\u03bb c' _, add_mul_succ c' ba)\n\ntheorem add_le_of_forall_add_lt {a b c : ordinal} (hb : 0 < b) (h : \u2200 d < b, a + d < c) :\n  a + b \u2264 c :=\nbegin\n  have H : a + (c - a) = c := ordinal.add_sub_cancel_of_le (by {rw \u2190add_zero a, exact (h _ hb).le}),\n  rw \u2190H,\n  apply add_le_add_left _ a,\n  by_contra' hb,\n  exact (h _ hb).ne H\nend\n\ntheorem is_normal.apply_omega {f : ordinal.{u} \u2192 ordinal.{u}} (hf : is_normal f) :\n  sup.{0 u} (f \u2218 nat.cast) = f \u03c9 :=\nby rw [\u2190sup_nat_cast, is_normal.sup.{0 u u} hf]\n\n@[simp] theorem sup_add_nat (o : ordinal) : sup (\u03bb n : \u2115, o + n) = o + \u03c9 :=\n(add_is_normal o).apply_omega\n\n@[simp] theorem sup_mul_nat (o : ordinal) : sup (\u03bb n : \u2115, o * n) = o * \u03c9 :=\nbegin\n  rcases eq_zero_or_pos o with rfl | ho,\n  { rw zero_mul, exact sup_eq_zero_iff.2 (\u03bb n, zero_mul n) },\n  { exact (mul_is_normal ho).apply_omega }\nend\n\nend ordinal\n\n\nvariables {\u03b1 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {a b : \u03b1}\n\nnamespace acc\n\n/-- The rank of an element `a` accessible under a relation `r` is defined inductively as the\nsmallest ordinal greater than the ranks of all elements below it (i.e. elements `b` such that\n`r b a`). -/\nnoncomputable def rank (h : acc r a) : ordinal.{u} :=\nacc.rec_on h $ \u03bb a h ih, ordinal.sup.{u u} $ \u03bb b : {b // r b a}, order.succ $ ih b b.2\n\nlemma rank_eq (h : acc r a) :\n  h.rank = ordinal.sup.{u u} (\u03bb b : {b // r b a}, order.succ (h.inv b.2).rank) :=\nby { change (acc.intro a $ \u03bb _, h.inv).rank = _, refl }\n\n/-- if `r a b` then the rank of `a` is less than the rank of `b`. -/\nlemma rank_lt_of_rel (hb : acc r b) (h : r a b) : (hb.inv h).rank < hb.rank :=\n(order.lt_succ _).trans_le $ by { rw hb.rank_eq, refine le_trans _ (ordinal.le_sup _ \u27e8a, h\u27e9), refl }\n\nend acc\n\nnamespace well_founded\nvariables (hwf : well_founded r)\ninclude hwf\n\n/-- The rank of an element `a` under a well-founded relation `r` is defined inductively as the\nsmallest ordinal greater than the ranks of all elements below it (i.e. elements `b` such that\n`r b a`). -/\nnoncomputable def rank (a : \u03b1) : ordinal.{u} := (hwf.apply a).rank\n\nlemma rank_eq : hwf.rank a = ordinal.sup.{u u} (\u03bb b : {b // r b a}, order.succ $ hwf.rank b) :=\nby { rw [rank, acc.rank_eq], refl }\n\nlemma rank_lt_of_rel (h : r a b) : hwf.rank a < hwf.rank b := acc.rank_lt_of_rel _ h\n\nomit hwf\n\nlemma rank_strict_mono [preorder \u03b1] [well_founded_lt \u03b1] :\n  strict_mono (rank $ @is_well_founded.wf \u03b1 (<) _) :=\n\u03bb _ _, rank_lt_of_rel _\n\nlemma rank_strict_anti [preorder \u03b1] [well_founded_gt \u03b1] :\n  strict_anti (rank $ @is_well_founded.wf \u03b1 (>) _) :=\n\u03bb _ _, rank_lt_of_rel $ @is_well_founded.wf \u03b1 (>) _\n\nend well_founded\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/set_theory/ordinal/arithmetic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7287293967879045}}
{"text": "/-\nTheorems/Examples from Fuichi, Uchida \"Shugo to Iso\" (2020).\n-/\n\nuniverses u v\n-- What's the difference between:\n-- Sort, Sort*, Type, Type* ?\nvariables {A B C W X Y Z \u03b1 \u03b2: Sort*}\n\n--def injective {X Y} (f : X \u2192 Y) : Prop :=\n--  \u2200 \u2983 x\u2081 x\u2082 \u2984, f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082 \n\ndef injective (f: X \u2192 Y) : Prop :=\n \u2200 \u2983 x\u2081 x\u2082 \u2984 , f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082\n\n--@[reducible] def injective (f : \u03b1 \u2192 \u03b2) : Prop := \n--\u2200 \u2983a\u2081 a\u2082\u2984, f a\u2081 = f a\u2082 \u2192 a\u2081 = a\u2082\n\ndef surjective (f: X \u2192 Y) : Prop :=\n \u2200 y, \u2203 x, f x = y\n\ntheorem injective_id : injective(@id X) :=\nassume x\u2081 x\u2082,\nassume h1: id x\u2081 = id x\u2082,\nshow x\u2081 = x\u2082, from h1\n\n--theorem injective_comp {f: X \u2192 Y} {g: Y\u2192 Z}\n--(hg: injective f) (hg: injective g) :\n--injective (g \u2218 f) :=\n--sorry\n\n/--\n Theorem 6.1: \n  Let f: A \u2192 B, g : B \u2192 A,\n  f \u2218 g = id B \u2192 surgective f \u2227 injective g. \n-/\ntheorem id_comp_surj\n  {f: A \u2192 B} {g: B \u2192 A} : \n  f \u2218 g = @id B \u2192  surjective f  :=\nassume h1: f \u2218 g = @id B,\nassume b\u2081 : B,\n-- congr_fun is a congruence rule for the simplifier, see:\n-- https://leanprover.github.io/theorem_proving_in_lean/quantifiers_and_equality.html#equality\nhave h2: f (g b\u2081) = id b\u2081, from congr_fun h1 b\u2081,\nlet a := g b\u2081 in\nshow \u2203 a, f(a) = b\u2081, from exists.intro a h2\n/-\nlet a := g b\u2081 in\nshow \u2203 a, f(a) = b\u2081, from exists.intro a h2\n-/\n\n\ntheorem id_comp_injective\n{f: A \u2192 B} {g: B \u2192 A} :\nf \u2218 g = @id B \u2192 injective g :=\nassume h1: f \u2218 g = @id B,\nassume b\u2081 b\u2082 : B,\nassume h2: g b\u2081 = g b\u2082,\nhave h3: f (g b\u2081) = f (g b\u2082), from congr_arg f h2,\nhave h4: f (g b\u2081) = id b\u2081, from congr_fun h1 b\u2081,\nhave h5: f (g b\u2082) = id b\u2082, from congr_fun h1 b\u2082,\nhave h6: id b\u2081 = f (g b\u2082), from eq.subst h4 h3,\nhave h7: id b\u2081 = id b\u2082, from eq.subst h5 h6,\nshow b\u2081 = b\u2082, from h7\n--have id b\u2081 = f (g b\u2082), by rw [\u2190h3, h4],\n--by rw [\u2190h3,h4,\u2190h5],\n--show b\u2081 = b\u2082, by rewrite [h5,h4,h3]\n\n/-\nExercise 6.2\nLet f: A\u2192B, g: B\u2192C\n(1) If g \u2218 f is injective, f is injective\n(2) If g \u2218 f is surjective, g is surjective\n-/\n\n-- (1)\ntheorem comp_injective_1st \n{f: A \u2192 B} {g: B \u2192 C} :\ninjective (g \u2218 f) \u2192 injective f :=\nassume h1: injective (g \u2218 f),\nassume a\u2081 a\u2082 : A,\nassume h4: f a\u2081 = f a\u2082,\n-- We can not say the following equality on the image of the function g\n-- unless using congr_arg.\n-- have h5: g (f a\u2081) = g (f a\u2082), from  h4,\nhave h5: g (f a\u2081) = g (f a\u2082), from congr_arg g h4,\nshow a\u2081 = a\u2082, from h1 h5 \n\n\n--(2) can not prove with this\ntheorem can_not_prove_comp_surjective_2nd\n{f: A \u2192 B} {g: B \u2192 C} :\nsurjective(g \u2218 f) \u2192 surjective g :=\nassume h1: surjective (g \u2218 f),\nhave h2: \u2200c:C, \u2203a:A, g (f a) = c, from h1,\nassume a : A,\nlet  b := f a in\nshow \u2200c:C, \u2203b:B, g (b) = c, from exists.intro b h2\n\n--(2)\ntheorem comp_surjective_2nd\n{f: A \u2192 B} {g: B \u2192 C} :\nsurjective(g \u2218 f) \u2192 surjective g :=\nassume h1: surjective (g \u2218 f),\n-- can not exists.elim for\n-- \u2200c:C,\u2203a:A, g(f a) = c, from h1\nassume c:C,\nhave h2: \u2203a:A, g (f a) = c, from h1 c,\n-- exists.elim for \u2203a:A\nexists.elim h2 (\n  assume a\u2081: A,\n  assume h: g (f a\u2081) = c,\n  let b := f a\u2081 in\n  show \u2203b:B, g(b) = c, from exists.intro b h\n)\n--show \u2200c:C, \u2203b:B, g(b) = c, from h3\n-- have h3: \u2200c:C,\n--have h3: \u2200a:A, \u2203b:B, f(a) = b, by rfl, \n--assume a : A,\n--let b := f a in\n--show \u2200c:C, \u2203b:B, g (b) = c, from exists.intro b h2\n/-\nexists.elim h2\n(assume a\u2081,\n assume ha: \u2200c, g (f a\u2081) = c,\n let b := f a\u2081 in\n show \u2200c, \u2203b, g (b) = c, from exists.intro b ha)\n-/\n\n", "meta": {"author": "kmdtty", "repo": "lean_exercise", "sha": "467cce72c5f2c218e50c1d8cac57de3b805e7356", "save_path": "github-repos/lean/kmdtty-lean_exercise", "path": "github-repos/lean/kmdtty-lean_exercise/lean_exercise-467cce72c5f2c218e50c1d8cac57de3b805e7356/function_uchida.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7287189189186614}}
{"text": "import tactic.interactive algebra.order data.finset\n\nuniverses u v\n\nsection monotone\n\ndef increasing {\u03b1 : Type u} [has_le \u03b1] {\u03b2 : Type v} [has_le \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 x y, x \u2264 y \u2192 f x \u2264 f y\n\ndef decreasing {\u03b1 : Type u} [has_le \u03b1] {\u03b2 : Type v} [has_le \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 x y, x \u2264 y \u2192 f y \u2264 f x\n\ndef strictly_increasing {\u03b1 : Type u} [has_lt \u03b1] {\u03b2 : Type v} [has_lt \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 x y, x < y \u2192 f x < f y\n\ndef strictly_decreasing {\u03b1 : Type u} [has_lt \u03b1] {\u03b2 : Type v} [has_lt \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 x y, x < y \u2192 f y < f x\n\ntheorem increasing_of_strictly_increasing {\u03b1 : Type u} [partial_order \u03b1] {\u03b2 : Type v} [preorder \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : strictly_increasing f) : increasing f :=\n\u03bb x y hxy, or.cases_on (lt_or_eq_of_le hxy) (\u03bb hxy, le_of_lt $ hf x y hxy) (\u03bb hxy, hxy \u25b8 le_refl _)\n\ntheorem decreasing_of_strictly_decreasing {\u03b1 : Type u} [partial_order \u03b1] {\u03b2 : Type v} [preorder \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : strictly_decreasing f) : decreasing f :=\n\u03bb x y hxy, or.cases_on (lt_or_eq_of_le hxy) (\u03bb hxy, le_of_lt $ hf x y hxy) (\u03bb hxy, hxy \u25b8 le_refl _)\n\ntheorem increasing_of_nat {\u03b1 : Type u} [preorder \u03b1] (f : \u2115 \u2192 \u03b1) (hf : \u2200 n, f n \u2264 f (n + 1)) : increasing f :=\n\u03bb x y hxy, nat.less_than_or_equal.rec_on hxy (le_refl _) $ \u03bb n hn ih, le_trans ih $ hf n\n\ntheorem strictly_increasing_of_nat {\u03b1 : Type u} [preorder \u03b1] (f : \u2115 \u2192 \u03b1) (hf : \u2200 n, f n < f (n + 1)) : strictly_increasing f :=\n\u03bb x y hxy, nat.less_than_or_equal.rec_on hxy (hf x) $ \u03bb n hn ih, lt_trans ih $ hf n\n\ntheorem decreasing_of_nat {\u03b1 : Type u} [preorder \u03b1] (f : \u2115 \u2192 \u03b1) (hf : \u2200 n, f (n + 1) \u2264 f n) : decreasing f :=\n\u03bb x y hxy, nat.less_than_or_equal.rec_on hxy (le_refl _) $ \u03bb n hn ih, le_trans (hf n) ih\n\ntheorem strictly_decreasing_of_nat {\u03b1 : Type u} [preorder \u03b1] (f : \u2115 \u2192 \u03b1) (hf : \u2200 n, f (n + 1) < f n) : strictly_decreasing f :=\n\u03bb x y hxy, nat.less_than_or_equal.rec_on hxy (hf x) $ \u03bb n hn ih, lt_trans (hf n) ih\n\ntheorem nat.le_of_strictly_increasing (f : \u2115 \u2192 \u2115) (hf : strictly_increasing f) (n : \u2115) : n \u2264 f n :=\nnat.rec_on n (f 0).zero_le $ \u03bb n hn, le_trans (nat.succ_le_succ hn) (hf n (n+1) n.lt_succ_self)\n\nend monotone\n\nvariables {\u03b1 : Type u} [decidable_linear_order \u03b1]\n\ntheorem exists_monotone (f : \u2115 \u2192 \u03b1) :\n  \u2203 s : \u2115 \u2192 \u2115, strictly_increasing s \u2227 (strictly_increasing (f \u2218 s) \u2228 decreasing (f \u2218 s)) :=\nbegin\n  classical,\n  by_cases h1 : \u2203 s : \u2115 \u2192 \u2115, strictly_increasing s \u2227 strictly_increasing (f \u2218 s),\n  { rcases h1 with \u27e8s, hs1, hs2\u27e9, exact \u27e8s, hs1, or.inl $ hs2\u27e9 },\n  simp only [not_exists, not_and] at h1,\n  suffices : \u2200 N, \u2203 n, \u2203 H : N \u2264 n, \u2200 m, N \u2264 m \u2192 f m \u2264 f n,\n  { choose g hg1 hg2 using this,\n    refine \u27e8\u03bb n, nat.rec_on n (g 0) (\u03bb n ih, g (ih + 1)), _, _\u27e9,\n    { apply strictly_increasing_of_nat, intros n, exact hg1 _ },\n    right, apply decreasing_of_nat, intros n,\n    change f (g (nat.rec _ _ n + 1)) \u2264 f (nat.rec _ _ n),\n    cases n with n, { apply hg2, exact nat.zero_le _ },\n    apply hg2, exact le_trans (nat.le_succ_of_le $ hg1 _) (hg1 _) },\n  intros N,\n  suffices : \u2203 n, \u2200 m, f (N + m) \u2264 f (N + n),\n  { cases this with n hn, exact \u27e8N + n, nat.le_add_right _ _, \u03bb m hm, nat.add_sub_of_le hm \u25b8 hn _\u27e9 },\n  by_contra h2, simp only [not_exists, not_forall, not_le] at h2,\n  suffices : \u2200 n, \u2203 m, \u2203 H : n < m, f (N + n) < f (N + m),\n  { choose g hg1 hg2 using this,\n    refine h1 (\u03bb n, N + nat.rec_on n (g 0) (\u03bb n ih, g ih)) _ _,\n    { apply strictly_increasing_of_nat, intros n, exact add_lt_add_left (hg1 _) _ },\n    apply strictly_increasing_of_nat, intros n, exact hg2 _ },\n  intros n, by_contra h3, simp only [not_exists] at h3,\n  have : f N \u2208 (finset.range $ n + 1).image (\u03bb n, f (N + n)) := finset.mem_image_of_mem _ (finset.mem_range.2 n.succ_pos),\n  cases finset.max_of_mem this with fm hfm,\n  rcases finset.mem_image.1 (finset.mem_of_max hfm) with \u27e8m, hm, rfl\u27e9,\n  rw finset.mem_range at hm,\n  cases h2 m with s hs,\n  have hfnm : f (N + n) \u2264 f (N + m),\n  { refine finset.le_max_of_mem _ hfm,\n    exact finset.mem_image_of_mem (\u03bb n, f (N + n)) (finset.mem_range.2 n.lt_succ_self) },\n  have hsn : s < n + 1 := nat.lt_succ_of_le (le_of_not_lt (\u03bb hns, h3 s hns $ lt_of_le_of_lt hfnm hs)),\n  have hfsm : f (N + s) \u2264 f (N + m),\n  { refine finset.le_max_of_mem _ hfm,\n    exact finset.mem_image_of_mem (\u03bb n, f (N + n)) (finset.mem_range.2 hsn) },\n  exact not_le_of_lt hs hfsm\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1P1-lean", "sha": "3723468cc50f8bebd00a9811caf25224a578de17", "save_path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean", "path": "github-repos/lean/ImperialCollegeLondon-M1P1-lean/M1P1-lean-3723468cc50f8bebd00a9811caf25224a578de17/src/monotone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7287189187857919}}
{"text": "/-\nCopyright (c) 2021 Martin Zinkevich. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Martin Zinkevich\n-/\nimport measure_theory.measurable_space\nimport data.equiv.encodable.lattice\n\n/-!\n# Induction principles for measurable sets, related to \u03c0-systems and \u03bb-systems.\n\n## Main statements\n\n* The main theorem of this file is Dynkin's \u03c0-\u03bb theorem, which appears\n  here as an induction principle `induction_on_inter`. Suppose `s` is a\n  collection of subsets of `\u03b1` such that the intersection of two members\n  of `s` belongs to `s` whenever it is nonempty. Let `m` be the \u03c3-algebra\n  generated by `s`. In order to check that a predicate `C` holds on every\n  member of `m`, it suffices to check that `C` holds on the members of `s` and\n  that `C` is preserved by complementation and *disjoint* countable\n  unions.\n\n* The proof of this theorem relies on the notion of `is_pi_system`, i.e., a collection of sets\n  which is closed under binary non-empty intersections. Note that this is a small variation around\n  the usual notion in the literature, which often requires that a \u03c0-system is non-empty, and closed\n  also under disjoint intersections. This variation turns out to be convenient for the\n  formalization.\n\n* The proof of Dynkin's \u03c0-\u03bb theorem also requires the notion of `dynkin_system`, i.e., a collection\n  of sets which contains the empty set, is closed under complementation and under countable union\n  of pairwise disjoint sets. The disjointness condition is the only difference with `\u03c3`-algebras.\n\n* `generate_pi_system g` gives the minimal \u03c0-system containing `g`.\n  This can be considered a Galois insertion into both measurable spaces and sets.\n\n* `generate_from_generate_pi_system_eq` proves that if you start from a collection of sets `g`,\n  take the generated \u03c0-system, and then the generated \u03c3-algebra, you get the same result as\n  the \u03c3-algebra generated from `g`. This is useful because there are connections between\n  independent sets that are \u03c0-systems and the generated independent spaces.\n\n* `mem_generate_pi_system_Union_elim` and `mem_generate_pi_system_Union_elim'` show that any\n  element of the \u03c0-system generated from the union of a set of \u03c0-systems can be\n  represented as the intersection of a finite number of elements from these sets.\n\n## Implementation details\n\n* `is_pi_system` is a predicate, not a type. Thus, we don't explicitly define the galois\n  insertion, nor do we define a complete lattice. In theory, we could define a complete\n  lattice and galois insertion on the subtype corresponding to `is_pi_system`.\n-/\n\nopen measurable_space set\nopen_locale classical\n\n/-- A \u03c0-system is a collection of subsets of `\u03b1` that is closed under binary intersection of\n  non-disjoint sets. Usually it is also required that the collection is nonempty, but we don't do\n  that here. -/\ndef is_pi_system {\u03b1} (C : set (set \u03b1)) : Prop :=\n\u2200 s t \u2208 C, (s \u2229 t : set \u03b1).nonempty \u2192 s \u2229 t \u2208 C\n\nnamespace measurable_space\n\nlemma is_pi_system_measurable_set {\u03b1:Type*} [measurable_space \u03b1] :\n  is_pi_system {s : set \u03b1 | measurable_set s} :=\n\u03bb s t hs ht _, hs.inter ht\n\nend measurable_space\n\nlemma is_pi_system.singleton {\u03b1} (S : set \u03b1) : is_pi_system ({S} : set (set \u03b1)) :=\nbegin\n  intros s t h_s h_t h_ne,\n  rw [set.mem_singleton_iff.1 h_s, set.mem_singleton_iff.1 h_t, set.inter_self,\n      set.mem_singleton_iff],\nend\n\n/-- Given a collection `S` of subsets of `\u03b1`, then `generate_pi_system S` is the smallest\n\u03c0-system containing `S`. -/\ninductive generate_pi_system {\u03b1} (S : set (set \u03b1)) : set (set \u03b1)\n| base {s : set \u03b1} (h_s : s \u2208 S) : generate_pi_system s\n| inter {s t : set \u03b1} (h_s : generate_pi_system s) (h_t : generate_pi_system t)\n  (h_nonempty : (s \u2229 t).nonempty) : generate_pi_system (s \u2229 t)\n\nlemma is_pi_system_generate_pi_system {\u03b1} (S : set (set \u03b1)) :\n  is_pi_system (generate_pi_system S) :=\n\u03bb s t h_s h_t h_nonempty, generate_pi_system.inter h_s h_t h_nonempty\n\nlemma subset_generate_pi_system_self {\u03b1} (S : set (set \u03b1)) : S \u2286 generate_pi_system S :=\n\u03bb s, generate_pi_system.base\n\nlemma generate_pi_system_subset_self {\u03b1} {S : set (set \u03b1)} (h_S : is_pi_system S) :\n  generate_pi_system S \u2286 S :=\nbegin\n  intros x h,\n  induction h with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,\n  { exact h_s, },\n  { exact h_S _ _ h_s h_u h_nonempty, },\nend\n\nlemma generate_pi_system_eq {\u03b1} {S : set (set \u03b1)} (h_pi : is_pi_system S) :\n  generate_pi_system S = S :=\nset.subset.antisymm (generate_pi_system_subset_self h_pi) (subset_generate_pi_system_self S)\n\nlemma generate_pi_system_mono {\u03b1} {S T : set (set \u03b1)} (hST : S \u2286 T) :\n  generate_pi_system S \u2286 generate_pi_system T :=\nbegin\n  intros t ht,\n  induction ht with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,\n  { exact generate_pi_system.base (set.mem_of_subset_of_mem hST h_s),},\n  { exact is_pi_system_generate_pi_system T _ _ h_s h_u h_nonempty, },\nend\n\nlemma generate_pi_system_measurable_set {\u03b1} [M : measurable_space \u03b1] {S : set (set \u03b1)}\n  (h_meas_S : \u2200 s \u2208 S, measurable_set s) (t : set \u03b1)\n  (h_in_pi : t \u2208 generate_pi_system S) : measurable_set t :=\nbegin\n  induction h_in_pi with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,\n  { apply h_meas_S _ h_s, },\n  { apply measurable_set.inter h_s h_u, },\nend\n\nlemma generate_from_measurable_set_of_generate_pi_system {\u03b1} {g : set (set \u03b1)} (t : set \u03b1)\n  (ht : t \u2208 generate_pi_system g) :\n  (generate_from g).measurable_set' t :=\n@generate_pi_system_measurable_set \u03b1 (generate_from g) g\n  (\u03bb s h_s_in_g, measurable_set_generate_from h_s_in_g) t ht\n\nlemma generate_from_generate_pi_system_eq {\u03b1} {g : set (set \u03b1)} :\n  generate_from (generate_pi_system g) = generate_from g :=\nbegin\n  apply le_antisymm; apply generate_from_le,\n  { exact \u03bb t h_t, generate_from_measurable_set_of_generate_pi_system t h_t, },\n  { exact \u03bb t h_t, measurable_set_generate_from (generate_pi_system.base h_t), },\nend\n\n/- Every element of the \u03c0-system generated by the union of a family of \u03c0-systems\nis a finite intersection of elements from the \u03c0-systems.\nFor an indexed union version, see `mem_generate_pi_system_Union_elim'`. -/\nlemma mem_generate_pi_system_Union_elim {\u03b1 \u03b2} {g : \u03b2 \u2192 set (set \u03b1)}\n  (h_pi : \u2200 b, is_pi_system (g b)) (t : set \u03b1) (h_t : t \u2208 generate_pi_system (\u22c3 b, g b)) :\n  \u2203 (T : finset \u03b2) (f : \u03b2 \u2192 set \u03b1), (t = \u22c2 b \u2208 T, f b) \u2227 (\u2200 b \u2208 T, f b \u2208 g b) :=\nbegin\n  induction h_t with s h_s s t' h_gen_s h_gen_t' h_nonempty h_s h_t',\n  { rcases h_s with \u27e8t', \u27e8\u27e8b, rfl\u27e9, h_s_in_t'\u27e9\u27e9,\n    refine \u27e8{b}, (\u03bb _, s), _\u27e9,\n    simpa using h_s_in_t', },\n  { rcases h_t' with \u27e8T_t', \u27e8f_t', \u27e8rfl, h_t'\u27e9\u27e9\u27e9,\n    rcases h_s with \u27e8T_s, \u27e8f_s, \u27e8rfl, h_s\u27e9 \u27e9 \u27e9,\n    use [(T_s \u222a T_t'), (\u03bb (b:\u03b2),\n      if (b \u2208 T_s) then (if (b \u2208 T_t') then (f_s b \u2229 (f_t' b)) else (f_s b))\n      else (if (b \u2208 T_t') then (f_t' b) else (\u2205 : set \u03b1)))],\n    split,\n    { ext a,\n      simp_rw [set.mem_inter_iff, set.mem_Inter, finset.mem_union, or_imp_distrib],\n      rw \u2190 forall_and_distrib,\n      split; intros h1 b; by_cases hbs : b \u2208 T_s; by_cases hbt : b \u2208 T_t'; specialize h1 b;\n        simp only [hbs, hbt, if_true, if_false, true_implies_iff, and_self, false_implies_iff,\n          and_true, true_and] at h1 \u22a2,\n      all_goals { exact h1, }, },\n    intros b h_b,\n    split_ifs with hbs hbt hbt,\n    { refine h_pi b (f_s b) (f_t' b) (h_s b hbs) (h_t' b hbt) (set.nonempty.mono _ h_nonempty),\n      exact set.inter_subset_inter (set.bInter_subset_of_mem hbs) (set.bInter_subset_of_mem hbt), },\n    { exact h_s b hbs, },\n    { exact h_t' b hbt, },\n    { rw finset.mem_union at h_b,\n      apply false.elim (h_b.elim hbs hbt), }, },\nend\n\n/- Every element of the \u03c0-system generated by an indexed union of a family of \u03c0-systems\nis a finite intersection of elements from the \u03c0-systems.\nFor a total union version, see `mem_generate_pi_system_Union_elim`. -/\nlemma mem_generate_pi_system_Union_elim' {\u03b1 \u03b2} {g : \u03b2 \u2192 set (set \u03b1)} {s: set \u03b2}\n  (h_pi : \u2200 b \u2208 s, is_pi_system (g b)) (t : set \u03b1) (h_t : t \u2208 generate_pi_system (\u22c3 b \u2208 s, g b)) :\n  \u2203 (T : finset \u03b2) (f : \u03b2 \u2192 set \u03b1), (\u2191T \u2286 s) \u2227 (t = \u22c2 b \u2208 T, f b) \u2227 (\u2200 b \u2208 T, f b \u2208 g b) :=\nbegin\n  have : t \u2208 generate_pi_system (\u22c3 (b : subtype s), (g \u2218 subtype.val) b),\n  { suffices h1 : (\u22c3 (b : subtype s), (g \u2218 subtype.val) b) = (\u22c3 b (H : b \u2208 s), g b), by rwa h1,\n    ext x,\n    simp only [exists_prop, set.mem_Union, function.comp_app, subtype.exists, subtype.coe_mk],\n    refl },\n  rcases @mem_generate_pi_system_Union_elim \u03b1 (subtype s) (g \u2218 subtype.val)\n    (\u03bb b, h_pi b.val b.property) t this with \u27e8T, \u27e8f,\u27e8 rfl, h_t'\u27e9\u27e9\u27e9,\n  refine \u27e8T.image subtype.val, function.extend subtype.val f (\u03bb (b:\u03b2), (\u2205 : set \u03b1)), by simp, _, _\u27e9,\n  { ext a, split;\n    { simp only [set.mem_Inter, subtype.forall, finset.set_bInter_finset_image],\n      intros h1 b h_b h_b_in_T,\n      have h2 := h1 b h_b h_b_in_T,\n      revert h2,\n      rw function.extend_apply subtype.val_injective,\n      apply id } },\n  { intros b h_b,\n    simp_rw [finset.mem_image, exists_prop, subtype.exists,\n             exists_and_distrib_right, exists_eq_right] at h_b,\n    cases h_b,\n    have h_b_alt : b = (subtype.mk b h_b_w).val := rfl,\n    rw [h_b_alt, function.extend_apply subtype.val_injective],\n    apply h_t',\n    apply h_b_h },\nend\n\nnamespace measurable_space\nvariable {\u03b1 : Type*}\n\n/-- A Dynkin system is a collection of subsets of a type `\u03b1` that contains the empty set,\n  is closed under complementation and under countable union of pairwise disjoint sets.\n  The disjointness condition is the only difference with `\u03c3`-algebras.\n\n  The main purpose of Dynkin systems is to provide a powerful induction rule for \u03c3-algebras\n  generated by a collection of sets which is stable under intersection.\n\n  A Dynkin system is also known as a \"\u03bb-system\" or a \"d-system\".\n-/\nstructure dynkin_system (\u03b1 : Type*) :=\n(has : set \u03b1 \u2192 Prop)\n(has_empty : has \u2205)\n(has_compl : \u2200 {a}, has a \u2192 has a\u1d9c)\n(has_Union_nat : \u2200 {f : \u2115 \u2192 set \u03b1}, pairwise (disjoint on f) \u2192 (\u2200 i, has (f i)) \u2192 has (\u22c3 i, f i))\n\nnamespace dynkin_system\n\n@[ext] lemma ext : \u2200 {d\u2081 d\u2082 : dynkin_system \u03b1}, (\u2200 s : set \u03b1, d\u2081.has s \u2194 d\u2082.has s) \u2192 d\u2081 = d\u2082\n| \u27e8s\u2081, _, _, _\u27e9 \u27e8s\u2082, _, _, _\u27e9 h := have s\u2081 = s\u2082, from funext $ assume x, propext $ h x,\n  by subst this\n\nvariable (d : dynkin_system \u03b1)\n\nlemma has_compl_iff {a} : d.has a\u1d9c \u2194 d.has a :=\n\u27e8\u03bb h, by simpa using d.has_compl h, \u03bb h, d.has_compl h\u27e9\n\nlemma has_univ : d.has univ :=\nby simpa using d.has_compl d.has_empty\n\ntheorem has_Union {\u03b2} [encodable \u03b2] {f : \u03b2 \u2192 set \u03b1}\n  (hd : pairwise (disjoint on f)) (h : \u2200 i, d.has (f i)) : d.has (\u22c3 i, f i) :=\nby { rw \u2190 encodable.Union_decode2, exact\n  d.has_Union_nat (encodable.Union_decode2_disjoint_on hd)\n    (\u03bb n, encodable.Union_decode2_cases d.has_empty h) }\n\ntheorem has_union {s\u2081 s\u2082 : set \u03b1}\n  (h\u2081 : d.has s\u2081) (h\u2082 : d.has s\u2082) (h : s\u2081 \u2229 s\u2082 \u2286 \u2205) : d.has (s\u2081 \u222a s\u2082) :=\nby { rw union_eq_Union, exact\n  d.has_Union (pairwise_disjoint_on_bool.2 h) (bool.forall_bool.2 \u27e8h\u2082, h\u2081\u27e9) }\n\nlemma has_diff {s\u2081 s\u2082 : set \u03b1} (h\u2081 : d.has s\u2081) (h\u2082 : d.has s\u2082) (h : s\u2082 \u2286 s\u2081) : d.has (s\u2081 \\ s\u2082) :=\nbegin\n  apply d.has_compl_iff.1,\n  simp [diff_eq, compl_inter],\n  exact d.has_union (d.has_compl h\u2081) h\u2082 (\u03bb x \u27e8h\u2081, h\u2082\u27e9, h\u2081 (h h\u2082)),\nend\n\ninstance : partial_order (dynkin_system \u03b1) :=\n{ le          := \u03bb m\u2081 m\u2082, m\u2081.has \u2264 m\u2082.has,\n  le_refl     := assume a b, le_refl _,\n  le_trans    := assume a b c, le_trans,\n  le_antisymm := assume a b h\u2081 h\u2082, ext $ assume s, \u27e8h\u2081 s, h\u2082 s\u27e9 }\n\n/-- Every measurable space (\u03c3-algebra) forms a Dynkin system -/\ndef of_measurable_space (m : measurable_space \u03b1) : dynkin_system \u03b1 :=\n{ has       := m.measurable_set',\n  has_empty := m.measurable_set_empty,\n  has_compl := m.measurable_set_compl,\n  has_Union_nat := assume f _ hf, m.measurable_set_Union f hf }\n\nlemma of_measurable_space_le_of_measurable_space_iff {m\u2081 m\u2082 : measurable_space \u03b1} :\n  of_measurable_space m\u2081 \u2264 of_measurable_space m\u2082 \u2194 m\u2081 \u2264 m\u2082 :=\niff.rfl\n\n/-- The least Dynkin system containing a collection of basic sets.\n  This inductive type gives the underlying collection of sets. -/\ninductive generate_has (s : set (set \u03b1)) : set \u03b1 \u2192 Prop\n| basic : \u2200 t \u2208 s, generate_has t\n| empty : generate_has \u2205\n| compl : \u2200 {a}, generate_has a \u2192 generate_has a\u1d9c\n| Union : \u2200 {f : \u2115 \u2192 set \u03b1}, pairwise (disjoint on f) \u2192\n    (\u2200 i, generate_has (f i)) \u2192 generate_has (\u22c3 i, f i)\n\nlemma generate_has_compl {C : set (set \u03b1)} {s : set \u03b1} : generate_has C s\u1d9c \u2194 generate_has C s :=\nby { refine \u27e8_, generate_has.compl\u27e9, intro h, convert generate_has.compl h, simp }\n\n/-- The least Dynkin system containing a collection of basic sets. -/\ndef generate (s : set (set \u03b1)) : dynkin_system \u03b1 :=\n{ has := generate_has s,\n  has_empty := generate_has.empty,\n  has_compl := assume a, generate_has.compl,\n  has_Union_nat := assume f, generate_has.Union }\n\nlemma generate_has_def {C : set (set \u03b1)} : (generate C).has = generate_has C := rfl\n\ninstance : inhabited (dynkin_system \u03b1) := \u27e8generate univ\u27e9\n\n/-- If a Dynkin system is closed under binary intersection, then it forms a `\u03c3`-algebra. -/\ndef to_measurable_space (h_inter : \u2200 s\u2081 s\u2082, d.has s\u2081 \u2192 d.has s\u2082 \u2192 d.has (s\u2081 \u2229 s\u2082)) :=\n{ measurable_space .\n  measurable_set'      := d.has,\n  measurable_set_empty := d.has_empty,\n  measurable_set_compl := assume s h, d.has_compl h,\n  measurable_set_Union := assume f hf,\n    have \u2200 n, d.has (disjointed f n),\n      from assume n, disjointed_induct (hf n)\n        (assume t i h, h_inter _ _ h $ d.has_compl $ hf i),\n    have d.has (\u22c3 n, disjointed f n), from d.has_Union disjoint_disjointed this,\n    by rwa [Union_disjointed] at this }\n\nlemma of_measurable_space_to_measurable_space\n  (h_inter : \u2200 s\u2081 s\u2082, d.has s\u2081 \u2192 d.has s\u2082 \u2192 d.has (s\u2081 \u2229 s\u2082)) :\n  of_measurable_space (d.to_measurable_space h_inter) = d :=\next $ assume s, iff.rfl\n\n/-- If `s` is in a Dynkin system `d`, we can form the new Dynkin system `{s \u2229 t | t \u2208 d}`. -/\ndef restrict_on {s : set \u03b1} (h : d.has s) : dynkin_system \u03b1 :=\n{ has       := \u03bb t, d.has (t \u2229 s),\n  has_empty := by simp [d.has_empty],\n  has_compl := assume t hts,\n    have t\u1d9c \u2229 s = ((t \u2229 s)\u1d9c) \\ s\u1d9c,\n      from set.ext $ assume x, by { by_cases x \u2208 s; simp [h] },\n    by { rw [this], exact d.has_diff (d.has_compl hts) (d.has_compl h)\n      (compl_subset_compl.mpr $ inter_subset_right _ _) },\n  has_Union_nat := assume f hd hf,\n    begin\n      rw [inter_comm, inter_Union],\n      apply d.has_Union_nat,\n      { exact \u03bb i j h x \u27e8\u27e8_, h\u2081\u27e9, _, h\u2082\u27e9, hd i j h \u27e8h\u2081, h\u2082\u27e9 },\n      { simpa [inter_comm] using hf },\n    end }\n\nlemma generate_le {s : set (set \u03b1)} (h : \u2200 t \u2208 s, d.has t) : generate s \u2264 d :=\n\u03bb t ht, ht.rec_on h d.has_empty\n  (assume a _ h, d.has_compl h)\n  (assume f hd _ hf, d.has_Union hd hf)\n\nlemma generate_has_subset_generate_measurable {C : set (set \u03b1)} {s : set \u03b1}\n  (hs : (generate C).has s) : (generate_from C).measurable_set' s :=\ngenerate_le (of_measurable_space (generate_from C)) (\u03bb t, measurable_set_generate_from) s hs\n\nlemma generate_inter {s : set (set \u03b1)}\n  (hs : is_pi_system s) {t\u2081 t\u2082 : set \u03b1}\n  (ht\u2081 : (generate s).has t\u2081) (ht\u2082 : (generate s).has t\u2082) : (generate s).has (t\u2081 \u2229 t\u2082) :=\nhave generate s \u2264 (generate s).restrict_on ht\u2082,\n  from generate_le _ $ assume s\u2081 hs\u2081,\n  have (generate s).has s\u2081, from generate_has.basic s\u2081 hs\u2081,\n  have generate s \u2264 (generate s).restrict_on this,\n    from generate_le _ $ assume s\u2082 hs\u2082,\n      show (generate s).has (s\u2082 \u2229 s\u2081), from\n        (s\u2082 \u2229 s\u2081).eq_empty_or_nonempty.elim\n        (\u03bb h,  h.symm \u25b8 generate_has.empty)\n        (\u03bb h, generate_has.basic _ (hs _ _ hs\u2082 hs\u2081 h)),\n  have (generate s).has (t\u2082 \u2229 s\u2081), from this _ ht\u2082,\n  show (generate s).has (s\u2081 \u2229 t\u2082), by rwa [inter_comm],\nthis _ ht\u2081\n\n/--\n  Given a collection of sets closed under binary intersections, then the Dynkin system it\n  generates is equal to the \u03c3-algebra it generates.\n  This result is known as the \u03c0-\u03bb theorem.\n  A collection of sets closed under binary intersection is called a \u03c0-system (often requiring\n  additionnally that is is non-empty, but we drop this condition in the formalization).\n-/\nlemma generate_from_eq {s : set (set \u03b1)} (hs : is_pi_system s) :\n  generate_from s = (generate s).to_measurable_space (\u03bb t\u2081 t\u2082, generate_inter hs) :=\nle_antisymm\n  (generate_from_le $ assume t ht, generate_has.basic t ht)\n  (of_measurable_space_le_of_measurable_space_iff.mp $\n    by { rw [of_measurable_space_to_measurable_space],\n    exact (generate_le _ $ assume t ht, measurable_set_generate_from ht) })\n\nend dynkin_system\n\ntheorem induction_on_inter {C : set \u03b1 \u2192 Prop} {s : set (set \u03b1)} [m : measurable_space \u03b1]\n  (h_eq : m = generate_from s) (h_inter : is_pi_system s)\n  (h_empty : C \u2205) (h_basic : \u2200 t \u2208 s, C t) (h_compl : \u2200 t, measurable_set t \u2192 C t \u2192 C t\u1d9c)\n  (h_union : \u2200 f : \u2115 \u2192 set \u03b1, pairwise (disjoint on f) \u2192\n    (\u2200 i, measurable_set (f i)) \u2192 (\u2200 i, C (f i)) \u2192 C (\u22c3 i, f i)) :\n  \u2200 \u2983t\u2984, measurable_set t \u2192 C t :=\nhave eq : measurable_set = dynkin_system.generate_has s,\n  by { rw [h_eq, dynkin_system.generate_from_eq h_inter], refl },\nassume t ht,\nhave dynkin_system.generate_has s t, by rwa [eq] at ht,\nthis.rec_on h_basic h_empty\n  (assume t ht, h_compl t $ by { rw [eq], exact ht })\n  (assume f hf ht, h_union f hf $ assume i, by { rw [eq], exact ht _ })\n\nend measurable_space\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/measure_theory/pi_system.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.728718913010509}}
{"text": "/-\n  Induced map from Spec(B) to Spec(A).\n\n  https://stacks.math.columbia.edu/tag/00E2\n-/\n\nimport topology.basic\nimport ring_theory.ideal_operations\nimport spectrum_of_a_ring.zariski_topology\n\nopen lattice\n\nuniverses u v\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [comm_ring \u03b1] [comm_ring \u03b2]\nvariables (f : \u03b1 \u2192 \u03b2) [is_ring_hom f]\n\n-- Given \u03c6 : A \u2192 B, we have Spec(\u03c6) : Spec(B) \u2192 Spec(A), \ud835\udd2d\u2032\u27fc\u03c6\u207b\u00b9(\ud835\udd2d\u2032).\n\ndef Zariski.induced : Spec \u03b2 \u2192 Spec \u03b1 :=\n\u03bb x, \u27e8ideal.comap f x.1, @ideal.is_prime.comap _ _ _ _ f _ x.1 x.2\u27e9\n\n-- This induced map is continuous.\n\nlemma Zariski.induced.continuous : continuous (Zariski.induced f) :=\nbegin\n  rintros U \u27e8E, HE\u27e9,\n  use [f '' E],\n  apply set.ext,\n  rintros \u27e8I, PI\u27e9,\n  split,\n  { intros HI HC,\n    suffices HfI : Zariski.induced f \u27e8I, PI\u27e9 \u2208 Spec.V E,\n      rw HE at HfI,\n      apply HfI,\n      exact HC,\n    intros x Hx,\n    simp [Zariski.induced] at *,\n    have HfE : f '' E \u2286 I := HI,\n    have Hfx : f x \u2208 f '' E := set.mem_image_of_mem f Hx,\n    exact (HfE Hfx), },\n  { rintros HI x \u27e8y, \u27e8Hy, Hfy\u27e9\u27e9,\n    suffices HfI : Zariski.induced f \u27e8I, PI\u27e9 \u2208 Spec.V E,\n      rw \u2190Hfy,\n      exact (HfI Hy),\n    intros z Hz,\n    simp [Zariski.induced] at *,\n    replace HI : _ \u2208 -U := HI,\n    rw \u2190HE at HI,\n    exact (HI Hz), }\nend\n\ntheorem Zariski.induced.preimage_D (x : \u03b1)\n: Zariski.induced f \u207b\u00b9' (Spec.D' x) = Spec.D' (f x) :=\nset.ext $ \u03bb \u27e8P, HP\u27e9,\nby simp [Spec.D', Spec.V', Zariski.induced]\n", "meta": {"author": "ramonfmir", "repo": "lean-scheme", "sha": "6d3ec18fecfd174b79d0ce5c85a783f326dd50f6", "save_path": "github-repos/lean/ramonfmir-lean-scheme", "path": "github-repos/lean/ramonfmir-lean-scheme/lean-scheme-6d3ec18fecfd174b79d0ce5c85a783f326dd50f6/src/spectrum_of_a_ring/induced_continuous_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7286874246731768}}
{"text": "-- Razonamiento ecuacional sobre la inversa de listas unitarias\n-- ============================================================\n\nimport data.list.basic\nopen list\n\nvariable  {\u03b1 : Type*}\nvariable  x : \u03b1\nvariables (xs : list \u03b1)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir, por recursi\u00f3n, la funci\u00f3n\n--    inversa :: list \u03b1 \u2192 list \u03b1\n-- tal que (inversa xs) es la lista obtenida\n-- invirtiendo el orden de los elementos de xs.\n-- Por ejemplo,\n--    inversa [3,2,5] = [5,2,3]\n-- ----------------------------------------------------\n\ndef inversa : list \u03b1 \u2192 list \u03b1\n| []        := []\n| (x :: xs) := inversa xs ++ [x]\n\n-- #eval inversa [3,2,5]\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar los siguientes lemas\n-- + inversa_nil :\n--     inversa ([] : list \u03b1) = []\n-- + inversa_cons :\n--     inversa (x :: xs) = inversa xs ++ [x]\n-- ----------------------------------------------------\n\n@[simp]\nlemma inversa_nil :\n  inversa ([] : list \u03b1) = [] :=\nrfl\n\n@[simp]\nlemma inversa_cons :\n  inversa (x :: xs) = inversa xs ++ [x] :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 3. (p. 9) Demostrar que\n--    inversa [x] = [x]\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\ncalc inversa [x]\n         = inversa ([] : list \u03b1) ++ [x] : by rw inversa_cons\n     ... = ([] : list \u03b1) ++ [x]         : by rw inversa_nil\n     ... = [x]                          : by rw nil_append\n\n\n-- 2\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\ncalc inversa [x]\n         = inversa ([] : list \u03b1) ++ [x] : by simp\n     ... = ([] : list \u03b1) ++ [x]         : by simp\n     ... = [x]                          : by simp\n\n-- 3\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\nby simp\n\n-- 4\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\nbegin\n  rw inversa_cons,\n  rw inversa_nil,\n  rw nil_append,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\nby rw [inversa_cons,\n       inversa_nil,\n       nil_append]\n\n-- 6\u00aa demostraci\u00f3n\nexample : inversa [x] = [x] :=\nrfl\n\n-- Comentarios sobre la funci\u00f3n reverse:\n-- + Es equivalente a la funci\u00f3n inversa\n-- + Para usarla hay que importar la librer\u00eda\n--   data.list.basic y abrir el espacio de nombre\n--   list escribiendo al principio del fichero\n--      import data.list.basic\n--      open list\n-- + Se puede evaluar. Por ejemplo,\n--      #eval reverse  [3,2,5]\n-- + Se puede demostrar. Por ejemplo,\n--      example : reverse [x] = [x] :=\n--      -- by library_search\n--      reverse_singleton x\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/7_Programas/Razonamiento_ecuacional_sobre_la_inversa_de_listas_unitarias.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893340314393, "lm_q2_score": 0.8887587993853654, "lm_q1q2_score": 0.7286874207618768}}
{"text": "import tactic\nimport topology.basic\nimport topology.subset_properties\n/-\nProve connectedness theorems in topology, basic goal to aim for is that if connected spaces share a point, the union is connected. More advanced is goal is closed intervals of the real line are connected.\n-/\n\n--use top theorems\nopen set function topological_space relation\nopen_locale classical topological_space\n\n-- some vars we can work with\nuniverses u v\nvariables {\u03b1 : Type u} [topological_space \u03b1] {s t u v : set \u03b1}\n\n/- definition of connectivity we use (from mathlibs def of is_preconnected),-/\ndef connected (s : set \u03b1) : Prop :=\n\u2200 (u v : set \u03b1), is_open u \u2192 is_open v \u2192 s \u2286 u \u222a v \u2192 (s \u2229 u).nonempty \u2192 (s \u2229 v).nonempty \u2192 (s \u2229 (u \u2229 v)).nonempty\n\n--a theorem I found from other sources to be a nice precursor for other connectivity theorems.\n-- if for each point in a set, we can find a connected set contain both that point and a given fixed point (x), then the whole set must be connected.\n--Most of the proof as I wrote it is unwrapping definitions\ntheorem fixedpoint_connected_is_connected {s : set \u03b1} (x : \u03b1)\n  (H : \u2200 y \u2208 s, \u2203 t \u2286 s, x \u2208 t \u2227 y \u2208 t \u2227 connected t) :\n  connected s :=\nbegin\n -- Decompose hypothesis to extract sets we can work with\n  intros u v hu hv hs hy hz,\n  cases hy with y hy,\n  cases hy with ys yv,\n  cases hz with z hz,\n  cases hz with zs zv,\n  have xs : x \u2208 s, {\n    cases H y ys with t h,\n    cases h with ts h,\n    cases h with xt h,\n    cases h with yt con_t,\n    exact ts xt,\n  },\n  --wlog gets around the fact that we would otherwise have to do cases on u,v, but they are identical.\n  wlog xu : x \u2208 u := hs xs using [u v z y, v u y z],\n  specialize H z zs,\n  rcases H with \u27e8t, ts, xt, zt, ht\u27e9,\n  --use connectivity of t to finish\n  specialize ht u v,\n  specialize ht hu hv,\n  specialize ht (subset.trans ts hs),\n  -- x proves t \u2229 u nonempty, z proves t \u2229 v nonempty\n  have h1 : x \u2208 t \u2229 u, {\n  split,\n  exact xt,\n  exact xu,\n  },\n  have h2 : (t \u2229 u).nonempty, {\n    use x,\n    exact h1,\n  },\n   specialize ht h2,\n  have h3 : z \u2208 t \u2229 v, {\n    split,\n    exact zt,\n    exact zv,\n  },\n  have h4 : (t \u2229 v).nonempty, {\n    use z,\n    exact h3,\n  },\n  specialize ht h4,\n  cases ht with e ht_e,\n  cases ht_e with et euv,\n  use e,\n  split,\n  exact ts et,\n  exact euv,\nend", "meta": {"author": "raymondpg", "repo": "XLL", "sha": "f97237922687d0edfa3fdab4c9cb831b39284e49", "save_path": "github-repos/lean/raymondpg-XLL", "path": "github-repos/lean/raymondpg-XLL/XLL-f97237922687d0edfa3fdab4c9cb831b39284e49/src/Griffin/top_thms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7286874163904483}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport tactic.abel\nimport data.polynomial.eval\n\n/-!\n# The Pochhammer polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define and prove some basic relations about\n`pochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)`\nwhich is also known as the rising factorial. A version of this definition\nthat is focused on `nat` can be found in `data.nat.factorial` as `nat.asc_factorial`.\n\n## Implementation\n\nAs with many other families of polynomials, even though the coefficients are always in `\u2115`,\nwe define the polynomial with coefficients in any `[semiring S]`.\n\n## TODO\n\nThere is lots more in this direction:\n* q-factorials, q-binomials, q-Pochhammer.\n-/\n\nuniverses u v\n\nopen polynomial\nopen_locale polynomial\n\nsection semiring\nvariables (S : Type u) [semiring S]\n\n/--\n`pochhammer S n` is the polynomial `X * (X+1) * ... * (X + n - 1)`,\nwith coefficients in the semiring `S`.\n-/\nnoncomputable def pochhammer : \u2115 \u2192 S[X]\n| 0 := 1\n| (n+1) := X * (pochhammer n).comp (X + 1)\n\n@[simp] lemma pochhammer_zero : pochhammer S 0 = 1 := rfl\n@[simp] lemma pochhammer_one : pochhammer S 1 = X := by simp [pochhammer]\n\nlemma pochhammer_succ_left (n : \u2115) : pochhammer S (n+1) = X * (pochhammer S n).comp (X+1) :=\nby rw pochhammer\n\nsection\nvariables {S} {T : Type v} [semiring T]\n@[simp] lemma pochhammer_map (f : S \u2192+* T) (n : \u2115) : (pochhammer S n).map f = pochhammer T n :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih, pochhammer_succ_left, map_comp], },\nend\n\nend\n\n@[simp, norm_cast] lemma pochhammer_eval_cast (n k : \u2115) :\n  ((pochhammer \u2115 n).eval k : S) = (pochhammer S n).eval k :=\nbegin\n  rw [\u2190pochhammer_map (algebra_map \u2115 S), eval_map, \u2190eq_nat_cast (algebra_map \u2115 S),\n    eval\u2082_at_nat_cast, nat.cast_id, eq_nat_cast],\nend\n\nlemma pochhammer_eval_zero {n : \u2115} : (pochhammer S n).eval 0 = if n = 0 then 1 else 0 :=\nbegin\n  cases n,\n  { simp, },\n  { simp [X_mul, nat.succ_ne_zero, pochhammer_succ_left], }\nend\n\nlemma pochhammer_zero_eval_zero : (pochhammer S 0).eval 0 = 1 :=\nby simp\n\n@[simp] lemma pochhammer_ne_zero_eval_zero {n : \u2115} (h : n \u2260 0) : (pochhammer S n).eval 0 = 0 :=\nby simp [pochhammer_eval_zero, h]\n\nlemma pochhammer_succ_right (n : \u2115) : pochhammer S (n+1) = pochhammer S n * (X + n) :=\nbegin\n  suffices h : pochhammer \u2115 (n+1) = pochhammer \u2115 n * (X + n),\n  { apply_fun polynomial.map (algebra_map \u2115 S) at h,\n    simpa only [pochhammer_map, polynomial.map_mul, polynomial.map_add,\n                map_X, polynomial.map_nat_cast] using h },\n  induction n with n ih,\n  { simp, },\n  { conv_lhs\n  { rw [pochhammer_succ_left, ih, mul_comp, \u2190mul_assoc, \u2190pochhammer_succ_left, add_comp, X_comp,\n      nat_cast_comp, add_assoc, add_comm (1 : \u2115[X]), \u2190 nat.cast_succ] } },\nend\n\nlemma pochhammer_succ_eval {S : Type*} [semiring S] (n : \u2115) (k : S) :\n  (pochhammer S (n + 1)).eval k = (pochhammer S n).eval k * (k + n) :=\nby rw [pochhammer_succ_right, mul_add, eval_add, eval_mul_X, \u2190 nat.cast_comm, \u2190 C_eq_nat_cast,\n    eval_C_mul, nat.cast_comm, \u2190 mul_add]\n\nlemma pochhammer_succ_comp_X_add_one (n : \u2115) :\n  (pochhammer S (n + 1)).comp (X + 1) =\n    pochhammer S (n + 1) + (n + 1) \u2022 (pochhammer S n).comp (X + 1) :=\nbegin\n  suffices : (pochhammer \u2115 (n + 1)).comp (X + 1) =\n              pochhammer \u2115 (n + 1) + (n + 1) * (pochhammer \u2115 n).comp (X + 1),\n  { simpa [map_comp] using congr_arg (polynomial.map (nat.cast_ring_hom S)) this },\n  nth_rewrite 1 pochhammer_succ_left,\n  rw [\u2190 add_mul, pochhammer_succ_right \u2115 n, mul_comp, mul_comm, add_comp, X_comp,\n      nat_cast_comp, add_comm \u2191n, \u2190 add_assoc]\nend\n\nlemma polynomial.mul_X_add_nat_cast_comp {p q : S[X]} {n : \u2115} :\n  (p * (X + n)).comp q = (p.comp q) * (q + n) :=\nby rw [mul_add, add_comp, mul_X_comp, \u2190nat.cast_comm, nat_cast_mul_comp, nat.cast_comm, mul_add]\n\nlemma pochhammer_mul (n m : \u2115) :\n  pochhammer S n * (pochhammer S m).comp (X + n) = pochhammer S (n + m) :=\nbegin\n  induction m with m ih,\n  { simp, },\n  { rw [pochhammer_succ_right, polynomial.mul_X_add_nat_cast_comp, \u2190mul_assoc, ih,\n      nat.succ_eq_add_one, \u2190add_assoc, pochhammer_succ_right, nat.cast_add, add_assoc], }\nend\n\nlemma pochhammer_nat_eq_asc_factorial (n : \u2115) :\n  \u2200 k, (pochhammer \u2115 k).eval (n + 1) = n.asc_factorial k\n| 0 := by erw [eval_one]; refl\n| (t + 1) := begin\n  rw [pochhammer_succ_right, eval_mul, pochhammer_nat_eq_asc_factorial t],\n  suffices : n.asc_factorial t * (n + 1 + t) = n.asc_factorial (t + 1), by simpa,\n  rw [nat.asc_factorial_succ, add_right_comm, mul_comm]\nend\n\nlemma pochhammer_nat_eq_desc_factorial (a b : \u2115) :\n  (pochhammer \u2115 b).eval a = (a + b - 1).desc_factorial b :=\nbegin\n  cases b,\n  { rw [nat.desc_factorial_zero, pochhammer_zero, polynomial.eval_one] },\n  rw [nat.add_succ, nat.succ_sub_succ, tsub_zero],\n  cases a,\n  { rw [pochhammer_ne_zero_eval_zero _ b.succ_ne_zero, zero_add,\n    nat.desc_factorial_of_lt b.lt_succ_self] },\n  { rw [nat.succ_add, \u2190nat.add_succ, nat.add_desc_factorial_eq_asc_factorial,\n      pochhammer_nat_eq_asc_factorial] }\nend\n\nend semiring\n\nsection strict_ordered_semiring\nvariables {S : Type*} [strict_ordered_semiring S]\n\nlemma pochhammer_pos (n : \u2115) (s : S) (h : 0 < s) : 0 < (pochhammer S n).eval s :=\nbegin\n  induction n with n ih,\n  { simp only [nat.nat_zero_eq_zero, pochhammer_zero, eval_one], exact zero_lt_one, },\n  { rw [pochhammer_succ_right, mul_add, eval_add, \u2190nat.cast_comm, eval_nat_cast_mul, eval_mul_X,\n      nat.cast_comm, \u2190mul_add],\n    exact mul_pos ih\n      (lt_of_lt_of_le h ((le_add_iff_nonneg_right _).mpr (nat.cast_nonneg n))), }\nend\n\nend strict_ordered_semiring\n\nsection factorial\n\nopen_locale nat\n\nvariables (S : Type*) [semiring S] (r n : \u2115)\n\n@[simp]\nlemma pochhammer_eval_one (S : Type*) [semiring S] (n : \u2115) :\n  (pochhammer S n).eval (1 : S) = (n! : S) :=\nby rw_mod_cast [pochhammer_nat_eq_asc_factorial, nat.zero_asc_factorial]\n\nlemma factorial_mul_pochhammer (S : Type*) [semiring S] (r n : \u2115) :\n  (r! : S) * (pochhammer S n).eval (r + 1) = (r + n)! :=\nby rw_mod_cast [pochhammer_nat_eq_asc_factorial, nat.factorial_mul_asc_factorial]\n\nlemma pochhammer_nat_eval_succ (r : \u2115) :\n  \u2200 n : \u2115, n * (pochhammer \u2115 r).eval (n + 1) = (n + r) * (pochhammer \u2115 r).eval n\n| 0 := begin\n  by_cases h : r = 0,\n  { simp only [h, zero_mul, zero_add], },\n  { simp only [pochhammer_eval_zero, zero_mul, if_neg h, mul_zero], }\nend\n| (k + 1) := by simp only [pochhammer_nat_eq_asc_factorial, nat.succ_asc_factorial, add_right_comm]\n\nlemma pochhammer_eval_succ (r n : \u2115) :\n  (n : S) * (pochhammer S r).eval (n + 1 : S) = (n + r) * (pochhammer S r).eval n :=\nby exact_mod_cast congr_arg nat.cast (pochhammer_nat_eval_succ r n)\n\nend factorial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/polynomial/pochhammer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7286874091431135}}
{"text": "local attribute [instance] decidable_inhabited prop_decidable\n\ninductive xnat\n| zero : xnat\n| succ : xnat \u2192 xnat\nopen xnat\ndefinition one := succ zero\ndefinition two := succ one\ndefinition add :xnat \u2192 xnat \u2192 xnat\n| n zero := n\n| n (succ p) := succ (add n p)\nnotation a + b := add a b\ntheorem one_add_one_equals_two : one + one = two :=\n    begin\n    unfold two,\n    unfold one,\n    unfold add,\n    end\ntheorem add_zerox (n:xnat): n+zero=n:=\n    begin\n    unfold add,\n    end\ntheorem zero_addx (n:xnat):zero+n=n:=\n    begin\n    induction n with k H,\n    unfold add,\n    unfold add,\n    rw[H],\n    end\ntheorem add_assocx (a b c:xnat):(a+b)+c=a+(b+c):=\n    begin\n    induction c with k H,\n    unfold add,\n    unfold add,\n    rw[H],\n    end\ntheorem zero_add_eq_ad_zerox (n:xnat) : zero+n=n+zero:=\n    begin \n    rw[zero_addx,add_zerox],\n    end\ntheorem add_one_eq_succx (n:xnat) : n + one = succ n:=\n    begin\n    unfold one add,\n    end\ntheorem one_add_eq_succx (n : xnat) : one+n=succ n:=\n    begin\n    induction n with k H,\n    unfold one add,\n    unfold one add,\n    rw[\u2190H],\n    unfold one,\n    end\ntheorem add_commx (a b:xnat) : a+b = b+a:=\n    begin\n    induction b with k H,\n    rw[zero_add_eq_ad_zerox],\n    unfold add,\n    rw[H,\u2190add_one_eq_succx,\u2190add_one_eq_succx,add_assocx,add_assocx,add_one_eq_succx,one_add_eq_succx],\n    end\ntheorem eq_iff_succ_eq_succ (a b : xnat) : succ a = succ b \u2194 a = b :=\n    begin\n    split,\n    exact succ.inj,\n    assume H : a = b,\n    rw [H],\n    end\ntheorem add_cancel_right (a b t : xnat) :  a = b \u2194 a+t = b+t :=\n    begin\n    split,\n    assume H,\n    rw[H],\n    induction t with k H,\n    rw[add_zerox,add_zerox],\n    assume H1,\n    exact H1,\n    unfold add,\n    rw[eq_iff_succ_eq_succ (a+k) (b+k)],\n    exact H,\n    end\ndefinition mul:xnat\u2192xnat\u2192xnat\n| n zero:=zero\n| n (succ p):= mul n p + n\nnotation a * b := mul a b\ntheorem mul_zerox (a : xnat) : a * zero = zero :=\n    begin\n    trivial,\n    end\ntheorem zero_mulx (a : xnat) : zero * a = zero :=\n    begin\n    induction a with k H,\n    unfold mul,\n    unfold mul add,\n    rw[H],\n    end\ntheorem mul_onex (a : xnat) : a * one = a :=\n    begin\n    unfold one mul,\n    rw[zero_addx],\n    end\ntheorem one_mulx (a : xnat) : one * a = a :=\n    begin\n    induction a with k H,\n    unfold mul,\n    unfold mul,\n    rw[add_one_eq_succx, H],\n    end\ntheorem right_distribx (a b c : xnat) : a * (b + c) = a* b + a * c :=\n    begin\n    induction c with k H,\n    rw[mul_zerox,add_zerox,add_zerox],\n    unfold add mul,\n    rw[H, add_assocx],\n    end\ntheorem left_distribx (a b c : xnat) : (a + b) * c = a * c + b * c :=\n    begin\n    induction c with n Hn,\n    unfold mul,\n    refl,\n    rw [\u2190add_one_eq_succx,right_distribx,Hn,right_distribx,right_distribx],\n    rw [mul_onex,mul_onex,mul_onex],\n    rw [add_assocx,\u2190add_assocx (b*n),add_commx (b*n),\u2190add_assocx,\u2190add_assocx,\u2190add_assocx],\n    end\ntheorem mul_assocx (a b c : xnat) : (a * b) * c = a * (b * c) :=\n    begin\n    induction c with k H,\n    rw[mul_zerox,mul_zerox,mul_zerox],\n    unfold mul,\n    rw[right_distribx,H]\n    end\ntheorem mul_commx (a b : xnat) : a * b = b * a :=\n    begin\n    induction b with k H,\n    rw[mul_zerox,zero_mulx],\n    unfold mul,\n    rw[H],\n    exact calc k * a + a = k * a + one * a: by rw[one_mulx]\n    ...=(k + one) * a: by rw[left_distribx]\n    ...=succ k * a: by rw[add_one_eq_succx],\n    end\ndefinition lt : xnat \u2192 xnat \u2192 Prop \n    | zero zero := false\n    | (succ m) zero := false\n    | zero (succ p) := true\n    | (succ m) (succ p) := lt m p\n\nnotation a < b := lt a b\ntheorem subtraction (a b:xnat) (Hab:a<b): \u2203(c:xnat), succ c+a=b:=begin\n    revert a,\n    induction b with b1 Hib,    \n    assume a1 H1,exfalso,revert H1,\n    cases a1 with a2,\n        unfold lt,trivial,\n\n        unfold lt,trivial,   \n\n    assume a1,\n        cases a1 with a2,\n            assume H1,existsi b1,unfold add,\n\n            unfold lt,\n            have H1:\u2200d:xnat,succ d+a2=b1\u2192\u2203c,succ c+succ a2=succ b1:=begin\n                unfold add,assume d H1,existsi d,\n                rw H1,    \n            end,\n            assume H2,\n            exact exists.elim (Hib a2 H2) H1,        \nend\ntheorem not_lt_itself (x:xnat):\u00acx<x:=begin\n    induction x with k H,\n    unfold lt, assume H,trivial,\n    unfold lt, exact H,\nend\ntheorem inequality_A1 (a b t : xnat) : a < b \u2194 a + t < b + t :=\n    begin\n    apply iff.intro,\n    induction t with k H,\n    rw[add_zerox,add_zerox],\n    assume H1,exact H1,\n    unfold add,unfold lt,exact H,\n    induction t with n H,\n    rw[add_zerox,add_zerox],\n    assume H1,\n    exact H1,\n    unfold add lt, exact H,\n    end\n    theorem inequality_A2 (a b c:xnat):a<b\u2192b<c\u2192a<c:=begin\n    revert a b,\n    induction c with c1 Hic,\n        assume a b,\n        cases b with b1,\n            unfold lt,assume H,trivial,\n\n            unfold lt,assume H,trivial,\n        \n        assume a b,\n        cases a with a1,\n            unfold lt,assume H1 H2,trivial,\n\n            cases b with b1,\n                unfold lt,trivial,\n\n                unfold lt,exact Hic a1 b1,\nend\ntheorem inequality_A3 (g b : xnat) : (g < b \u2228 g = b \u2228 b < g) \u2227 (g < b \u2192 \u00ac (g = b))  \u2227 (g < b \u2192 \u00ac (b < g))\u2227 ((g = b) \u2192 \u00ac (b < g)):=begin\n    apply and.intro,\n    tactic.swap,\n    apply and.intro,\n    have H1:\u2200c,succ c+g=b\u2192\u00acg=b:=begin\n        assume c H1,\n        rw \u2190H1,\n        have H4:\u00aczero=succ c:=begin assume H, have H1:zero<zero:= by cc,revert H1,unfold lt, trivial, end,\n        revert H4,\n        rw[add_cancel_right],tactic.swap,exact g,\n        rw zero_addx,assume H3,assumption,\n    end,\n    assume H2,\n    exact exists.elim (subtraction g b H2) H1,\n    apply and.intro,\n    tactic.swap,\n    assume H1, rw H1, exact not_lt_itself b,\n    assume H1,\n    have H2:\u2200c,succ c+g=b\u2192\u00acb < g:=begin\n        assume c1 H2,rw \u2190H2,\n        have H3:\u00acsucc c1 < zero:=begin\n            unfold lt,assume H3,assumption,\n        end,assume H4,revert H3,rw[inequality_A1 (succ c1) zero g,zero_addx],\n        assume H5,exact H5 H4,     \n    end,\n    exact exists.elim (subtraction g b H1) H2,\n\n    have H1:\u2200 x y:xnat, \u00acx<y\u2192\u00acy<x\u2192x=y:=begin\n        assume x y H1 H2,revert y,\n        induction x with x1 H,\n        assume y1 H1 H2,clear H2,\n        cases y1 with y1,\n        trivial,\n        exfalso, have H2:zero<succ y1:= by unfold lt, exact H1 H2,\n        assume y1,\n        cases y1 with y1,\n        assume H1 H2,exfalso,have H3:zero<succ x1:=by unfold lt,\n        exact H2 H3,\n        unfold lt,rw eq_iff_succ_eq_succ,\n        exact H y1,     \n    end,\n    rw [or.comm,or.assoc],\n    have H2:\u00acg < b \u2192 \u00acb < g \u2192 g = b:=H1 g b,clear H1,\n    cases classical.em (g<b) with A B,\n    right,right,assumption,\n    have H:\u00acb < g \u2192 g = b:= H2 B,clear H2 B,\n    cases classical.em (b<g) with A B,\n    right,left,assumption,left, exact H B,\nend\ntheorem inequality_A4 (g b : xnat) : zero<g \u2192 zero<b \u2192 zero<g*b :=begin\n    cases g with g1,\n    assume H1,exfalso,revert H1, unfold lt,trivial,\n    cases b with b1,\n    assume H1 H2,exfalso,revert H2, unfold lt,trivial,\n    assume H1 H2,\n    rw[\u2190one_add_eq_succx,\u2190one_add_eq_succx, right_distribx, left_distribx,left_distribx],\n    have H3:one*one=one:=begin unfold one,unfold mul,rw zero_addx, end,\n    rw[H3, add_assocx, one_add_eq_succx],unfold lt,\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/student_contributions/Chris_Hughes_xnat_exercise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7286874067273351}}
{"text": "/-\nWhat I present in M40001 is in some sense the mathematics\nof true-false statements.\n-/\nimport tactic\n\nopen bool\n\n/-\n#print notation \u2227\n#print and\n-- This is one idea of a proposition.\n-- ff and tt are the only two terms of type `bool`\n-- functions band, bor, bnot\n#check ff \u2227 tt\n#eval band ff tt \n#eval tt\n-/\nexample : \u2200 p q r : bool,\n  p && (q || r) = (p && q) || (p && r)\n:=\nbegin\n  intros,\n  cases p;\n  cases q;\n  cases r;\n  refl\nend\n\n#find bool \u2192 bool \u2192 bool\n-- afterwards change an and to an or,\n-- note that it breaks.\n\n/-\nVery boring proofs.\n\nBut there is always something very weird about\nthe definition of \u2192. Should it really be the case\nthat we say \"p implies q\" if p is completely\nirrelevant to the proof of q? \nBut there is actually a much more profound definition\nof a Proposition. A Proposition in Lean is a type `P`, \nwhere `P : Prop`. \n\nYou can make pretty much all of the material in\nthe pure part of Imperial's undergraduate degree\nin Lean now, because of its maths library `mathlib`.\nMany Imperial students have contributed to \nmathlib, but it's now getting harder for beginners\nto help out.  \n\n\nThis definition looks intimidating\nbut it is not. A term `p : P` (that is,\na term `p` of type `P`)\nis a proof of `P`. In this model of the idea of a\nproposition, implication `P \u21d2 Q` is a function,\nwhich takes as input a proof of `P` and outputs a\nproof of `Q`. In other words, a function\nwhich takes as input a term of type `P` and outputs\na term of type `Q`. In other words, it's\na function `P \u2192 Q` between the types `P` and `Q`.\n\nImportant thing: any two proofs of `P` are equal.\nIf `p : P` and `q : P` then `p = q`. This model\nof the word \"proposition\" cannot distinguish\nbetween proofs. Internally a proof knows how\nmuch work it was to construct though.\n-/\n\n/-\nLet's do some constructive logic.\nLet's play with the idea of `P \u2192 Q`.\n-/\n\nnamespace xena\n\nvariables (P Q R : Prop)\n\n/-- The theorem that P \u21d2 P -/\ntheorem id : P \u2192 P :=\nbegin\n  -- `\u22a2 X` on the right means \"you've got to prove X\"\n  -- so we've got to prove P \u2192 P\n  -- assume that `P` is true. \n  -- call this hypotheis `hP`\n  intro hP,\n  -- now we've got to prove `P`\n  exact hP,\n  -- we never mentioned `P`\n  -- we just talked about hypotheses\nend\n\nexample : P \u2192 (Q \u2192 P) :=\nbegin\n  intro hP,\n  intro hQ,\n  exact hP\nend\n-- then remove bracket at the top\n\nlemma modus_ponens : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  intro hP,\n  intro hPQ,\n  apply hPQ, clear hPQ,\n  exact hP,\nend\n\n-- `a<b` and `b<c` implies `a<c`\n-- `a>b` and `b>c` implies `a>c`.\n\nlemma trans : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  intros hPQ hQR hP,\n  apply hQR,\n  apply hPQ,\n  exact hP\nend\n\nlemma trans' : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\n\u03bb hPQ hQR hP, hQR $ hPQ hP\n\n\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  intro hPQR,\n  intro hPQ,\n  intro hP,\n  apply hPQR,\n    exact hP,\n  exact hPQ(hP),\nend\n-- todo -- search for why I don't get multicoloured tada\n\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  cc,-- \"congruence closure\"\nend\n\n-- `not P`, with notation `\u00ac P`, is \n-- *DEFINED TO MEAN* `P \u2192 false`\n\nexample : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  intro hP,\n  change (\u00ac P) \u2192 false,\n  intro hnP,\n  change P \u2192 false at hnP,\n  apply hnP,\n  exact hP,\nend\n\nlemma imp_not_not : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  change P \u2192 (P \u2192 false) \u2192 false,\n  apply modus_ponens\nend\n\nexample : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  -- cc kills it\n  intro hPQ,\n  intro hnQ,\n  intro hP,\n  change Q \u2192 false at hnQ,-- only change uses P,Q\n  apply hnQ,\n  apply hPQ,\n  exact hP,\n\nend\n\n#print axioms imp_not_not\n\nlemma not_not : \u00ac (\u00ac P) \u2192 P :=\nbegin\n  intro hnnP,\n  change (P \u2192 false) \u2192 false at hnnP,\n  finish,\nend\n\n\n\n#print axioms not_not\n\n\n\n\nend xena\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/logic/logic_lecture_ad_lib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7286873984446064}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sea f una funci\u00f3n de \u211d en \u211d. Demostrar que si f no tiene\n-- cota superior, entonces para cada a existe un x tal que f(x) > a.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\ndef fn_ub (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, f x \u2264 a\ndef fn_has_ub (f : \u211d \u2192 \u211d) := \u2203 a, fn_ub f a\n\nopen_locale classical\n\nvariable (f : \u211d \u2192 \u211d)\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h : \u00ac fn_has_ub f) \n  : \u2200 a, \u2203 x, f x > a :=\nbegin\n  intro a,\n  by_contradiction h1,\n  apply h,\n  use a,\n  intro x,\n  apply le_of_not_gt,\n  intro h2,\n  apply h1,\n  use x,\n  exact h2,\nend\n\n-- Prueba\n-- ======\n\n/-\nf : \u211d \u2192 \u211d,\nh : \u00acfn_has_ub f\n\u22a2 \u2200 (a : \u211d), \u2203 (x : \u211d), f x > a\n  >> intro a,\na : \u211d\n\u22a2 \u2203 (x : \u211d), f x > a\n  >> by_contradiction h1,\nh1 : \u00ac\u2203 (x : \u211d), f x > a\n\u22a2 false\n  >> apply h,\n\u22a2 fn_has_ub f\n  >> use a,\n\u22a2 fn_ub f a\n  >> intro x,\nx : \u211d\n\u22a2 f x \u2264 a\n  >> apply le_of_not_gt,\n\u22a2 \u00acf x > a\n  >> intro h2,\nh2 : f x > a\n\u22a2 false\n  >> apply h1,\n\u22a2 \u2203 (x : \u211d), f x > a\n  >> use x,\n\u22a2 f x > a\n  >> exact h2,\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\nexample \n  (h : \u00ac fn_has_ub f) : \n  \u2200 a, \u2203 x, f x > a :=\nbegin\n  contrapose! h,\n  exact h,\nend\n\n-- Prueba\n-- ======\n\n/-\nf : \u211d \u2192 \u211d,\nh : \u00acfn_has_ub f\n\u22a2 \u2200 (a : \u211d), \u2203 (x : \u211d), f x > a\n  >> contrapose! h,\nh : \u2203 (a : \u211d), \u2200 (x : \u211d), f x \u2264 a\n\u22a2 fn_has_ub f\n  >> exact h,\nno goals\n-/\n\n-- Comentario: La t\u00e1ctica (contrapose! h) aplica el contrapositivo entre\n-- la hip\u00f3tesis h y el objetivo; es decir, si (h : P) y el objetivo es Q\n-- entonces cambia la hip\u00f3tesis a (h : \u00acQ) el objetivo a \u00acP aplicando\n-- simplificaciones en ambos. \n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/CN_no_acotada_superiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7286119622608435}}
{"text": "namespace hidden\n\ndef divides (m n : \u2115) : Prop := \u2203 k, m * k = n\n\ninstance : has_dvd nat := \u27e8divides\u27e9\n\ndef even (n : \u2115) : Prop := 2 \u2223 n\n\nsection user_def\ndef pow : \u2115 \u2192 \u2115 \u2192 \u2115-- [\u00ac (m = 0 \u2227 n = 0)] \n| 0 0 := sorry\n| _ 0 := 1\n| m (nat.succ n) := m * pow m n\nend user_def\n\n-- BEGIN\ndef prime (n : \u2115) : Prop := \nn > 1 \u2227 (\u2200 m : \u2115, 1 < m \u2227 m < n \u2192 \u00ac divides n m)\n\ndef infinitely_many_primes : Prop := \n\u2200 n : \u2115, prime n \u2192 \u2203 m : \u2115, m > n \u2227 prime m\n\ndef Fermat_prime (n : \u2115) : Prop := \n\u2203 m : \u2115, n = pow 2 (pow 2 m) + 1\n\ndef infinitely_many_Fermat_primes : Prop := \n\u2200 n : \u2115, Fermat_prime n \u2192 \u2203 m : \u2115, m > n \u2227 Fermat_prime m\n\ndef goldbach_conjecture : Prop := \n\u2200 n : \u2115, even n \u2227 n > 2 \u2192 \u2203 p1 p2 : \u2115, prime p1 \u2227 prime p2 \u2227 n = p1 + p2\n\ndef Goldbach's_weak_conjecture : Prop :=\n\u2200 n : \u2115, \u00ac even n \u2227 n > 5 \u2192 \u2203 p1 p2 p3 : \u2115, prime p1 \u2227 prime p2 \u2227 prime p3 \u2227 n = p1 + p2 + p3\n\ndef Fermat's_last_theorem : Prop := \n\u2200 n : \u2115, n > 2 \u2192 \u00ac \u2203 a b c : \u2115, pow a n + pow b n = pow c n\n-- END\n\nend hidden\n\nsection\nvariables (real : Type) [ordered_ring real]\nvariables (log exp : real \u2192 real)\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y := \ncalc log (x * y) \n        = log (exp (log x) * y) : by rw [exp_log_eq hx]\n    ... = log (exp (log x) * exp (log y)) : by rw [exp_log_eq hy]\n    ... = log (exp (log x + log y)) : by rw [exp_add]\n    ... = log x + log y : by rw [log_exp_eq]\n    \nend\n\nsection\nexample (x : \u2124) : x * 0 = 0 :=\ncalc x * 0\n        = x * (x - x) : by rw [sub_self]\n    ... = x * x - x * x : by rw [mul_sub]\n    ... = 0 : by rw [sub_self]\nend", "meta": {"author": "hieule3004", "repo": "Imperial", "sha": "829d0d96603ff3e68ede818873db4931b8d854da", "save_path": "github-repos/lean/hieule3004-Imperial", "path": "github-repos/lean/hieule3004-Imperial/Imperial-829d0d96603ff3e68ede818873db4931b8d854da/Imperial/def_ex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7285552669208375}}
{"text": "import Proofs.Isomorphism\n\nuniverse u \n\n-- And \n\nstructure Pair (a b : Type u) where\n  proj\u2081 : a \n  proj\u2082 : b\n\ninfixl:65   \" \u00d7\u00b4 \" => Pair\nnotation:max \"\u27e8\" e \",\" f \"\u27e9\u00b4\" => Pair.mk e f\n\nexample : Int \u00d7\u00b4 Int := \u27e82, 3\u27e9\u00b4\n\ntheorem Pair.comm : (a \u00d7\u00b4 b) \u2245 (b \u00d7\u00b4 a) := \n  { To   := \u03bb\u27e8a, b\u27e9\u00b4 => \u27e8b, a\u27e9\u00b4\n  , From := \u03bb\u27e8b, a\u27e9\u00b4 => \u27e8a, b\u27e9\u00b4\n  , FromTo := \u03bbx => rfl \n  , ToFrom := \u03bbx => rfl }\n\ntheorem Pair.eta : \u2200 {m n : Type}, (v : m \u00d7\u00b4 n) \u2192 \u27e8Pair.proj\u2081 v, Pair.proj\u2082 v\u27e9\u00b4 = v \n  | _, _, _ => rfl\n\n-- Bottom and Top types\n\ninductive T : Type \n  | t : T \n\ninductive F : Type \n\nnotation:65 \"\u22a4\" => T\nnotation:65 \"\u22a5\" => F\n\nnotation:66 \"\u00ac\" e \"\u00b4\" => (e \u2192 F)\n\ntheorem T.id\u2097 : \u2200 {a : Type}, (\u22a4 \u00d7\u00b4 a) \u2245 a \n  := { To     := \u03bb\u27e8a, b\u27e9\u00b4 => b\n     , From   := \u03bbb       => \u27e8T.t, b\u27e9\u00b4 \n     , FromTo := \u03bbx => rfl\n     , ToFrom := \u03bbx => rfl  }\n\ntheorem F.elim (h : \u22a5) : a := F.rec (fun _ => a) h\n\ntheorem Not.elim (e : a) (h : \u00aca\u00b4) : \u22a5 := h e\n\ndef Imp.contraposition : \u2200 {a b : Type}, (a \u2192 b) \u2192 (\u00acb\u00b4 \u2192 \u00aca\u00b4)\n  | _, _, f, nb, na => nb (f na)  \n\n\nnotation:60 a \"\u2262\" b => \u00ac(a = b)\n\nexample : 2 \u2262 3 := \u03bbx => nomatch x\n\n-- Or\n\ninductive Prod' (a: Type) (b: Type) : Type \n  | inj\u2081 : a \u2192 Prod' a b\n  | inj\u2082 : b \u2192 Prod' a b\n\ninfixl:65 \" \u228e \" => Prod'\n\ndef Prod'.case : \u2200 {a b c : Type}, (a \u2192 c) \u2192 (b \u2192 c) \u2192 a \u228e b \u2192 c \n  | _, _, _, h1, h2, Prod'.inj\u2081 a => h1 a\n  | _, _, _, h1, h2, Prod'.inj\u2082 b => h2 b\n\ntheorem Prod'.comm : \u2200 {a b : Type}, a \u228e b \u2245 b \u228e a \n  | a, b => { To     := Prod'.case Prod'.inj\u2082 Prod'.inj\u2081,   \n              From   := Prod'.case Prod'.inj\u2082 Prod'.inj\u2081\n              FromTo := fun | Prod'.inj\u2081 a => rfl\n                            | Prod'.inj\u2082 b => rfl,\n              ToFrom := fun | Prod'.inj\u2081 a => rfl\n                            | Prod'.inj\u2082 b => rfl,\n            }\n    \n", "meta": {"author": "algebraic-sofia", "repo": "books", "sha": "adb282081975c81716f8835c56e97dff0fda2748", "save_path": "github-repos/lean/algebraic-sofia-books", "path": "github-repos/lean/algebraic-sofia-books/books-adb282081975c81716f8835c56e97dff0fda2748/plfa/Proofs/Conectives.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7285552645494917}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_numbertheory_412\n  (x y : \u2115)\n  (h\u2080 : x % 19 = 4)\n  (h\u2081 : y % 19 = 7) :\n  ((x + 1)^2 * (y + 5)^3) % 19 = 13 :=\nbegin\n  norm_num [h\u2080, h\u2081, nat.mul_mod, nat.add_mod, pow_succ],\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/numbertheory/p412.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7285552584734271}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport data.finset.fold\nimport data.multiset.gcd\n\n/-!\n# GCD and LCM operations on finsets\n\n## Main definitions\n\n- `finset.gcd` - the greatest common denominator of a `finset` of elements of a `gcd_monoid`\n- `finset.lcm` - the least common multiple of a `finset` of elements of a `gcd_monoid`\n\n## Implementation notes\n\nMany of the proofs use the lemmas `gcd.def` and `lcm.def`, which relate `finset.gcd`\nand `finset.lcm` to `multiset.gcd` and `multiset.lcm`.\n\nTODO: simplify with a tactic and `data.finset.lattice`\n\n## Tags\n\nfinset, gcd\n-/\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\nnamespace finset\nopen multiset\n\nvariables [comm_cancel_monoid_with_zero \u03b1] [nontrivial \u03b1] [gcd_monoid \u03b1]\n\n/-! ### lcm -/\nsection lcm\n\n/-- Least common multiple of a finite set -/\ndef lcm (s : finset \u03b2) (f : \u03b2 \u2192 \u03b1) : \u03b1 := s.fold gcd_monoid.lcm 1 f\n\nvariables {s s\u2081 s\u2082 : finset \u03b2} {f : \u03b2 \u2192 \u03b1}\n\nlemma lcm_def : s.lcm f = (s.1.map f).lcm := rfl\n\n@[simp] lemma lcm_empty : (\u2205 : finset \u03b2).lcm f = 1 :=\nfold_empty\n\n@[simp] lemma lcm_dvd_iff {a : \u03b1} : s.lcm f \u2223 a \u2194 (\u2200b \u2208 s, f b \u2223 a) :=\nbegin\n  apply iff.trans multiset.lcm_dvd,\n  simp only [multiset.mem_map, and_imp, exists_imp_distrib],\n  exact \u27e8\u03bb k b hb, k _ _ hb rfl, \u03bb k a' b hb h, h \u25b8 k _ hb\u27e9,\nend\n\nlemma lcm_dvd {a : \u03b1} : (\u2200b \u2208 s, f b \u2223 a) \u2192 s.lcm f \u2223 a :=\nlcm_dvd_iff.2\n\nlemma dvd_lcm {b : \u03b2} (hb : b \u2208 s) : f b \u2223 s.lcm f :=\nlcm_dvd_iff.1 (dvd_refl _) _ hb\n\n@[simp] lemma lcm_insert [decidable_eq \u03b2] {b : \u03b2} :\n  (insert b s : finset \u03b2).lcm f = gcd_monoid.lcm (f b) (s.lcm f) :=\nbegin\n  by_cases h : b \u2208 s,\n  { rw [insert_eq_of_mem h,\n        (lcm_eq_right_iff (f b) (s.lcm f) (multiset.normalize_lcm (s.1.map f))).2 (dvd_lcm h)] },\n  apply fold_insert h,\nend\n\n@[simp] lemma lcm_singleton {b : \u03b2} : ({b} : finset \u03b2).lcm f = normalize (f b) :=\nmultiset.lcm_singleton\n\n@[simp] lemma normalize_lcm : normalize (s.lcm f) = s.lcm f := by simp [lcm_def]\n\nlemma lcm_union [decidable_eq \u03b2] : (s\u2081 \u222a s\u2082).lcm f = gcd_monoid.lcm (s\u2081.lcm f) (s\u2082.lcm f) :=\nfinset.induction_on s\u2081 (by rw [empty_union, lcm_empty, lcm_one_left, normalize_lcm]) $ \u03bb a s has ih,\n  by rw [insert_union, lcm_insert, lcm_insert, ih, lcm_assoc]\n\ntheorem lcm_congr {f g : \u03b2 \u2192 \u03b1} (hs : s\u2081 = s\u2082) (hfg : \u2200a \u2208 s\u2082, f a = g a) :\n  s\u2081.lcm f = s\u2082.lcm g :=\nby { subst hs, exact finset.fold_congr hfg }\n\nlemma lcm_mono_fun {g : \u03b2 \u2192 \u03b1} (h : \u2200 b \u2208 s, f b \u2223 g b) : s.lcm f \u2223 s.lcm g :=\nlcm_dvd (\u03bb b hb, dvd_trans (h b hb) (dvd_lcm hb))\n\nlemma lcm_mono (h : s\u2081 \u2286 s\u2082) : s\u2081.lcm f \u2223 s\u2082.lcm f :=\nlcm_dvd $ assume b hb, dvd_lcm (h hb)\n\nend lcm\n\n/-! ### gcd -/\nsection gcd\n\n/-- Greatest common divisor of a finite set -/\ndef gcd (s : finset \u03b2) (f : \u03b2 \u2192 \u03b1) : \u03b1 := s.fold gcd_monoid.gcd 0 f\n\nvariables {s s\u2081 s\u2082 : finset \u03b2} {f : \u03b2 \u2192 \u03b1}\n\nlemma gcd_def : s.gcd f = (s.1.map f).gcd := rfl\n\n@[simp] lemma gcd_empty : (\u2205 : finset \u03b2).gcd f = 0 :=\nfold_empty\n\nlemma dvd_gcd_iff {a : \u03b1} : a \u2223 s.gcd f \u2194 \u2200b \u2208 s, a \u2223 f b :=\nbegin\n  apply iff.trans multiset.dvd_gcd,\n  simp only [multiset.mem_map, and_imp, exists_imp_distrib],\n  exact \u27e8\u03bb k b hb, k _ _ hb rfl, \u03bb k a' b hb h, h \u25b8 k _ hb\u27e9,\nend\n\nlemma gcd_dvd {b : \u03b2} (hb : b \u2208 s) : s.gcd f \u2223 f b :=\ndvd_gcd_iff.1 (dvd_refl _) _ hb\n\nlemma dvd_gcd {a : \u03b1} : (\u2200b \u2208 s, a \u2223 f b) \u2192 a \u2223 s.gcd f :=\ndvd_gcd_iff.2\n\n@[simp] lemma gcd_insert [decidable_eq \u03b2] {b : \u03b2} :\n  (insert b s : finset \u03b2).gcd f = gcd_monoid.gcd (f b) (s.gcd f) :=\nbegin\n  by_cases h : b \u2208 s,\n  { rw [insert_eq_of_mem h,\n    (gcd_eq_right_iff (f b) (s.gcd f) (multiset.normalize_gcd (s.1.map f))).2 (gcd_dvd h)] ,},\n  apply fold_insert h,\nend\n\n@[simp] lemma gcd_singleton {b : \u03b2} : ({b} : finset \u03b2).gcd f = normalize (f b) :=\nmultiset.gcd_singleton\n\n@[simp] lemma normalize_gcd : normalize (s.gcd f) = s.gcd f := by simp [gcd_def]\n\nlemma gcd_union [decidable_eq \u03b2] : (s\u2081 \u222a s\u2082).gcd f = gcd_monoid.gcd (s\u2081.gcd f) (s\u2082.gcd f) :=\nfinset.induction_on s\u2081 (by rw [empty_union, gcd_empty, gcd_zero_left, normalize_gcd]) $\n  \u03bb a s has ih, by rw [insert_union, gcd_insert, gcd_insert, ih, gcd_assoc]\n\ntheorem gcd_congr {f g : \u03b2 \u2192 \u03b1} (hs : s\u2081 = s\u2082) (hfg : \u2200a \u2208 s\u2082, f a = g a) :\n  s\u2081.gcd f = s\u2082.gcd g :=\nby { subst hs, exact finset.fold_congr hfg }\n\nlemma gcd_mono_fun {g : \u03b2 \u2192 \u03b1} (h : \u2200 b \u2208 s, f b \u2223 g b) : s.gcd f \u2223 s.gcd g :=\ndvd_gcd (\u03bb b hb, dvd_trans (gcd_dvd hb) (h b hb))\n\nlemma gcd_mono (h : s\u2081 \u2286 s\u2082) : s\u2082.gcd f \u2223 s\u2081.gcd f :=\ndvd_gcd $ assume b hb, gcd_dvd (h hb)\n\n\ntheorem gcd_eq_zero_iff : s.gcd f = 0 \u2194 \u2200 (x : \u03b2), x \u2208 s \u2192 f x = 0 :=\nbegin\n  rw [gcd_def, multiset.gcd_eq_zero_iff],\n  split; intro h,\n  { intros b bs,\n    apply h (f b),\n    simp only [multiset.mem_map, mem_def.1 bs],\n    use b,\n    simp [mem_def.1 bs] },\n  { intros a as,\n    rw multiset.mem_map at as,\n    rcases as with \u27e8b, \u27e8bs, rfl\u27e9\u27e9,\n    apply h b (mem_def.1 bs) }\nend\n\nlemma gcd_eq_gcd_filter_ne_zero [decidable_pred (\u03bb (x : \u03b2), f x = 0)] :\n  s.gcd f = (s.filter (\u03bb x, f x \u2260 0)).gcd f :=\nbegin\n  classical,\n  transitivity ((s.filter (\u03bb x, f x = 0)) \u222a (s.filter (\u03bb x, f x \u2260 0))).gcd f,\n  { rw filter_union_filter_neg_eq },\n  rw gcd_union,\n  transitivity gcd_monoid.gcd (0 : \u03b1) _,\n  { refine congr (congr rfl _) rfl,\n    apply s.induction_on, { simp },\n    intros a s has h,\n    rw filter_insert,\n    split_ifs with h1; simp [h, h1], },\n  simp [gcd_zero_left, normalize_gcd],\nend\n\nlemma gcd_mul_left {a : \u03b1} : s.gcd (\u03bb x, a * f x) = normalize a * s.gcd f :=\nbegin\n  classical,\n  apply s.induction_on,\n  { simp },\n  intros b t hbt h,\n  rw [gcd_insert, gcd_insert, h, \u2190 gcd_mul_left],\n  apply gcd_eq_of_associated_right,\n  apply associated_mul_mul _ (associated.refl _),\n  apply normalize_associated,\nend\n\nlemma gcd_mul_right {a : \u03b1} : s.gcd (\u03bb x, f x * a) = s.gcd f * normalize a :=\nbegin\n  classical,\n  apply s.induction_on,\n  { simp },\n  intros b t hbt h,\n  rw [gcd_insert, gcd_insert, h, \u2190 gcd_mul_right],\n  apply gcd_eq_of_associated_right,\n  apply associated_mul_mul (associated.refl _),\n  apply normalize_associated,\nend\n\nend gcd\nend finset\n\nnamespace finset\nsection integral_domain\n\nvariables [nontrivial \u03b2] [integral_domain \u03b1] [gcd_monoid \u03b1]\n\nlemma gcd_eq_of_dvd_sub {s : finset \u03b2} {f g : \u03b2 \u2192 \u03b1} {a : \u03b1}\n  (h : \u2200 x : \u03b2, x \u2208 s \u2192 a \u2223 f x - g x) :\n  gcd_monoid.gcd a (s.gcd f) = gcd_monoid.gcd a (s.gcd g) :=\nbegin\n  classical,\n  revert h,\n  apply s.induction_on,\n  { simp },\n  intros b s bs hi h,\n  rw [gcd_insert, gcd_insert, gcd_comm (f b), \u2190 gcd_assoc, hi (\u03bb x hx, h _ (mem_insert_of_mem hx)),\n      gcd_comm a, gcd_assoc, gcd_comm a (gcd_monoid.gcd _ _),\n      gcd_comm (g b), gcd_assoc _ _ a, gcd_comm _ a],\n  refine congr rfl _,\n  apply gcd_eq_of_dvd_sub_right (h _ (mem_insert_self _ _)),\nend\n\nend integral_domain\n\nend finset\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/finset/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7285334565451349}}
{"text": "/-\nCopyright (c) 2019 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\nimport algebra.order.absolute_value\nimport topology.uniform_space.basic\n\n/-!\n# Uniform structure induced by an absolute value\n\nWe build a uniform space structure on a commutative ring `R` equipped with an absolute value into\na linear ordered field `\ud835\udd5c`. Of course in the case `R` is `\u211a`, `\u211d` or `\u2102` and\n`\ud835\udd5c = \u211d`, we get the same thing as the metric space construction, and the general construction\nfollows exactly the same path.\n\n## Implementation details\n\nNote that we import `data.real.cau_seq` because this is where absolute values are defined, but\nthe current file does not depend on real numbers. TODO: extract absolute values from that\n`data.real` folder.\n\n## References\n\n* [N. Bourbaki, *Topologie g\u00e9n\u00e9rale*][bourbaki1966]\n\n## Tags\n\nabsolute value, uniform spaces\n-/\n\nopen set function filter uniform_space\nopen_locale filter\n\nnamespace is_absolute_value\nvariables {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c]\nvariables {R : Type*} [comm_ring R] (abv : R \u2192 \ud835\udd5c) [is_absolute_value abv]\n\n/-- The uniformity coming from an absolute value. -/\ndef uniform_space_core : uniform_space.core R :=\n{ uniformity := (\u2a05 \u03b5>0, \ud835\udcdf {p:R\u00d7R | abv (p.2 - p.1) < \u03b5}),\n  refl := le_infi $ assume \u03b5, le_infi $ assume \u03b5_pos, principal_mono.2\n    (\u03bb \u27e8x, y\u27e9 h, by simpa [show x = y, from h, abv_zero abv]),\n  symm := tendsto_infi.2 $ assume \u03b5, tendsto_infi.2 $ assume h,\n    tendsto_infi' \u03b5 $ tendsto_infi' h $ tendsto_principal_principal.2 $ \u03bb \u27e8x, y\u27e9 h,\n      have h : abv (y - x) < \u03b5, by simpa [-sub_eq_add_neg] using h,\n      by rwa abv_sub abv at h,\n  comp := le_infi $ assume \u03b5, le_infi $ assume h, lift'_le\n    (mem_infi_of_mem (\u03b5 / 2) $ mem_infi_of_mem (div_pos h zero_lt_two) (subset.refl _)) $\n    have \u2200 (a b c : R), abv (c-a) < \u03b5 / 2 \u2192 abv (b-c) < \u03b5 / 2 \u2192 abv (b-a) < \u03b5,\n      from assume a b c hac hcb,\n       calc abv (b - a) \u2264 _ : abv_sub_le abv b c a\n        ... = abv (c - a) + abv (b - c) : add_comm _ _\n        ... < \u03b5 / 2 + \u03b5 / 2 : add_lt_add hac hcb\n        ... = \u03b5 : by rw [div_add_div_same, add_self_div_two],\n    by simpa [comp_rel] }\n\n/-- The uniform structure coming from an absolute value. -/\ndef uniform_space : uniform_space R :=\nuniform_space.of_core (uniform_space_core abv)\n\ntheorem mem_uniformity {s : set (R\u00d7R)} :\n  s \u2208 (uniform_space_core abv).uniformity \u2194\n  (\u2203\u03b5>0, \u2200{a b:R}, abv (b - a) < \u03b5 \u2192 (a, b) \u2208 s) :=\nbegin\n  suffices : s \u2208 (\u2a05 \u03b5: {\u03b5 : \ud835\udd5c // \u03b5 > 0}, \ud835\udcdf {p:R\u00d7R | abv (p.2 - p.1) < \u03b5.val}) \u2194 _,\n  { rw infi_subtype at this,\n    exact this },\n  rw mem_infi_of_directed,\n  { simp [subset_def] },\n  { rintros \u27e8r, hr\u27e9 \u27e8p, hp\u27e9,\n    exact \u27e8\u27e8min r p, lt_min hr hp\u27e9, by simp [lt_min_iff, (\u2265)] {contextual := tt}\u27e9, },\nend\n\nend is_absolute_value\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/uniform_space/absolute_value.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7285334459454231}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport ring_theory.matrix_algebra\nimport data.polynomial.algebra_map\nimport data.matrix.basis\nimport data.matrix.dmatrix\n\n/-!\n# Algebra isomorphism between matrices of polynomials and polynomials of matrices\n\nGiven `[comm_ring R] [ring A] [algebra R A]`\nwe show `A[X] \u2243\u2090[R] (A \u2297[R] R[X])`.\nCombining this with the isomorphism `matrix n n A \u2243\u2090[R] (A \u2297[R] matrix n n R)` proved earlier\nin `ring_theory.matrix_algebra`, we obtain the algebra isomorphism\n```\ndef mat_poly_equiv :\n  matrix n n R[X] \u2243\u2090[R] (matrix n n R)[X]\n```\nwhich is characterized by\n```\ncoeff (mat_poly_equiv m) k i j = coeff (m i j) k\n```\n\nWe will use this algebra isomorphism to prove the Cayley-Hamilton theorem.\n-/\n\nuniverses u v w\n\nopen_locale polynomial tensor_product\n\nopen polynomial\nopen tensor_product\nopen algebra.tensor_product (alg_hom_of_linear_map_tensor_product include_left)\n\nnoncomputable theory\n\nvariables (R A : Type*)\nvariables [comm_semiring R]\nvariables [semiring A] [algebra R A]\n\nnamespace poly_equiv_tensor\n\n/--\n(Implementation detail).\nThe function underlying `A \u2297[R] R[X] \u2192\u2090[R] A[X]`,\nas a bilinear function of two arguments.\n-/\n@[simps apply_apply]\ndef to_fun_bilinear : A \u2192\u2097[A] R[X] \u2192\u2097[R] A[X] :=\nlinear_map.to_span_singleton A _ (aeval (polynomial.X : A[X])).to_linear_map\n\nlemma to_fun_bilinear_apply_eq_sum (a : A) (p : R[X]) :\n  to_fun_bilinear R A a p = p.sum (\u03bb n r, monomial n (a * algebra_map R A r)) :=\nbegin\n  simp only [to_fun_bilinear_apply_apply, aeval_def, eval\u2082_eq_sum, polynomial.sum, finset.smul_sum],\n  congr' with i : 1,\n  rw [\u2190 algebra.smul_def, \u2190C_mul', mul_smul_comm, C_mul_X_pow_eq_monomial, \u2190algebra.commutes,\n      \u2190 algebra.smul_def, smul_monomial],\nend\n\n/--\n(Implementation detail).\nThe function underlying `A \u2297[R] R[X] \u2192\u2090[R] A[X]`,\nas a linear map.\n-/\ndef to_fun_linear : A \u2297[R] R[X] \u2192\u2097[R] A[X] :=\ntensor_product.lift (to_fun_bilinear R A)\n\n@[simp]\nlemma to_fun_linear_tmul_apply (a : A) (p : R[X]) :\n  to_fun_linear R A (a \u2297\u209c[R] p) = to_fun_bilinear R A a p := rfl\n\n-- We apparently need to provide the decidable instance here\n-- in order to successfully rewrite by this lemma.\nlemma to_fun_linear_mul_tmul_mul_aux_1\n  (p : R[X]) (k : \u2115) (h : decidable (\u00acp.coeff k = 0)) (a : A) :\n  ite (\u00accoeff p k = 0) (a * (algebra_map R A) (coeff p k)) 0 = a * (algebra_map R A) (coeff p k) :=\nby { classical, split_ifs; simp *, }\n\nlemma to_fun_linear_mul_tmul_mul_aux_2 (k : \u2115) (a\u2081 a\u2082 : A) (p\u2081 p\u2082 : R[X]) :\n  a\u2081 * a\u2082 * (algebra_map R A) ((p\u2081 * p\u2082).coeff k) =\n    (finset.nat.antidiagonal k).sum\n      (\u03bb x, a\u2081 * (algebra_map R A) (coeff p\u2081 x.1) * (a\u2082 * (algebra_map R A) (coeff p\u2082 x.2))) :=\nbegin\n  simp_rw [mul_assoc, algebra.commutes, \u2190finset.mul_sum, mul_assoc, \u2190finset.mul_sum],\n  congr,\n  simp_rw [algebra.commutes (coeff p\u2082 _), coeff_mul, ring_hom.map_sum, ring_hom.map_mul],\nend\n\nlemma to_fun_linear_mul_tmul_mul (a\u2081 a\u2082 : A) (p\u2081 p\u2082 : R[X]) :\n  (to_fun_linear R A) ((a\u2081 * a\u2082) \u2297\u209c[R] (p\u2081 * p\u2082)) =\n    (to_fun_linear R A) (a\u2081 \u2297\u209c[R] p\u2081) * (to_fun_linear R A) (a\u2082 \u2297\u209c[R] p\u2082) :=\nbegin\n  classical,\n  simp only [to_fun_linear_tmul_apply, to_fun_bilinear_apply_eq_sum],\n  ext k,\n  simp_rw [coeff_sum, coeff_monomial, sum_def, finset.sum_ite_eq', mem_support_iff, ne.def],\n  conv_rhs { rw [coeff_mul] },\n  simp_rw [finset_sum_coeff, coeff_monomial,\n    finset.sum_ite_eq', mem_support_iff, ne.def,\n    mul_ite, mul_zero, ite_mul, zero_mul],\n  simp_rw [ite_mul_zero_left (\u00accoeff p\u2081 _ = 0) (a\u2081 * (algebra_map R A) (coeff p\u2081 _))],\n  simp_rw [ite_mul_zero_right (\u00accoeff p\u2082 _ = 0) _ (_ * _)],\n  simp_rw [to_fun_linear_mul_tmul_mul_aux_1, to_fun_linear_mul_tmul_mul_aux_2],\nend\n\nlemma to_fun_linear_algebra_map_tmul_one (r : R) :\n  (to_fun_linear R A) ((algebra_map R A) r \u2297\u209c[R] 1) = (algebra_map R A[X]) r :=\nby rw [to_fun_linear_tmul_apply, to_fun_bilinear_apply_apply, polynomial.aeval_one,\n  algebra_map_smul, algebra.algebra_map_eq_smul_one]\n\n/--\n(Implementation detail).\nThe algebra homomorphism `A \u2297[R] R[X] \u2192\u2090[R] A[X]`.\n-/\ndef to_fun_alg_hom : A \u2297[R] R[X] \u2192\u2090[R] A[X] :=\nalg_hom_of_linear_map_tensor_product\n  (to_fun_linear R A)\n  (to_fun_linear_mul_tmul_mul R A)\n  (to_fun_linear_algebra_map_tmul_one R A)\n\n@[simp] lemma to_fun_alg_hom_apply_tmul (a : A) (p : R[X]) :\n  to_fun_alg_hom R A (a \u2297\u209c[R] p) = p.sum (\u03bb n r, monomial n (a * (algebra_map R A) r)) :=\nto_fun_bilinear_apply_eq_sum R A _ _\n\n/--\n(Implementation detail.)\n\nThe bare function `A[X] \u2192 A \u2297[R] R[X]`.\n(We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.)\n-/\ndef inv_fun (p : A[X]) : A \u2297[R] R[X] :=\np.eval\u2082\n  (include_left : A \u2192\u2090[R] A \u2297[R] R[X])\n  ((1 : A) \u2297\u209c[R] (X : R[X]))\n\n@[simp]\nlemma inv_fun_add {p q} : inv_fun R A (p + q) = inv_fun R A p + inv_fun R A q :=\nby simp only [inv_fun, eval\u2082_add]\n\nlemma inv_fun_monomial (n : \u2115) (a : A) :\n  inv_fun R A (monomial n a) = include_left a * ((1 : A) \u2297\u209c[R] (X : R[X])) ^ n :=\neval\u2082_monomial _ _\n\nlemma left_inv (x : A \u2297 R[X]) :\n  inv_fun R A ((to_fun_alg_hom R A) x) = x :=\nbegin\n  apply tensor_product.induction_on x,\n  { simp [inv_fun], },\n  { intros a p, dsimp only [inv_fun],\n    rw [to_fun_alg_hom_apply_tmul, eval\u2082_sum],\n    simp_rw [eval\u2082_monomial, alg_hom.coe_to_ring_hom, algebra.tensor_product.tmul_pow, one_pow,\n      algebra.tensor_product.include_left_apply, algebra.tensor_product.tmul_mul_tmul,\n      mul_one, one_mul, \u2190algebra.commutes, \u2190algebra.smul_def, smul_tmul, sum_def, \u2190tmul_sum],\n    conv_rhs { rw [\u2190sum_C_mul_X_pow_eq p], },\n    simp only [algebra.smul_def],\n    refl, },\n  { intros p q hp hq,\n    simp only [alg_hom.map_add, inv_fun_add, hp, hq], },\nend\n\nlemma right_inv (x : A[X]) :\n  (to_fun_alg_hom R A) (inv_fun R A x) = x :=\nbegin\n  apply polynomial.induction_on' x,\n  { intros p q hp hq, simp only [inv_fun_add, alg_hom.map_add, hp, hq], },\n  { intros n a,\n    rw [inv_fun_monomial, algebra.tensor_product.include_left_apply,\n      algebra.tensor_product.tmul_pow, one_pow, algebra.tensor_product.tmul_mul_tmul,\n      mul_one, one_mul, to_fun_alg_hom_apply_tmul, X_pow_eq_monomial, sum_monomial_index];\n    simp, }\nend\n\n/--\n(Implementation detail)\n\nThe equivalence, ignoring the algebra structure, `(A \u2297[R] R[X]) \u2243 A[X]`.\n-/\ndef equiv : (A \u2297[R] R[X]) \u2243 A[X] :=\n{ to_fun := to_fun_alg_hom R A,\n  inv_fun := inv_fun R A,\n  left_inv := left_inv R A,\n  right_inv := right_inv R A, }\n\nend poly_equiv_tensor\n\nopen poly_equiv_tensor\n\n/--\nThe `R`-algebra isomorphism `A[X] \u2243\u2090[R] (A \u2297[R] R[X])`.\n-/\ndef poly_equiv_tensor : A[X] \u2243\u2090[R] (A \u2297[R] R[X]) :=\nalg_equiv.symm\n{ ..(poly_equiv_tensor.to_fun_alg_hom R A), ..(poly_equiv_tensor.equiv R A) }\n\n@[simp]\nlemma poly_equiv_tensor_apply (p : A[X]) :\n  poly_equiv_tensor R A p =\n    p.eval\u2082 (include_left : A \u2192\u2090[R] A \u2297[R] R[X]) ((1 : A) \u2297\u209c[R] (X : R[X])) :=\nrfl\n\n@[simp]\nlemma poly_equiv_tensor_symm_apply_tmul (a : A) (p : R[X]) :\n  (poly_equiv_tensor R A).symm (a \u2297\u209c p) = p.sum (\u03bb n r, monomial n (a * algebra_map R A r)) :=\nto_fun_alg_hom_apply_tmul _ _ _ _\n\nopen dmatrix matrix\nopen_locale big_operators\n\nvariables {R}\nvariables {n : Type w} [decidable_eq n] [fintype n]\n\n/--\nThe algebra isomorphism stating \"matrices of polynomials are the same as polynomials of matrices\".\n\n(You probably shouldn't attempt to use this underlying definition ---\nit's an algebra equivalence, and characterised extensionally by the lemma\n`mat_poly_equiv_coeff_apply` below.)\n-/\nnoncomputable def mat_poly_equiv :\n  matrix n n R[X] \u2243\u2090[R] (matrix n n R)[X] :=\n(((matrix_equiv_tensor R R[X] n)).trans\n  (algebra.tensor_product.comm R _ _)).trans\n  (poly_equiv_tensor R (matrix n n R)).symm\n\nopen finset\n\nlemma mat_poly_equiv_coeff_apply_aux_1 (i j : n) (k : \u2115) (x : R) :\n  mat_poly_equiv (std_basis_matrix i j $ monomial k x) =\n    monomial k (std_basis_matrix i j x) :=\nbegin\n  simp only [mat_poly_equiv, alg_equiv.trans_apply,\n    matrix_equiv_tensor_apply_std_basis],\n  apply (poly_equiv_tensor R (matrix n n R)).injective,\n  simp only [alg_equiv.apply_symm_apply],\n  convert algebra.tensor_product.comm_tmul _ _ _ _ _,\n  simp only [poly_equiv_tensor_apply],\n  convert eval\u2082_monomial _ _,\n  simp only [algebra.tensor_product.tmul_mul_tmul, one_pow, one_mul, matrix.mul_one,\n    algebra.tensor_product.tmul_pow, algebra.tensor_product.include_left_apply, mul_eq_mul],\n  rw [\u2190 smul_X_eq_monomial, \u2190 tensor_product.smul_tmul],\n  congr' with i' j'; simp\nend\n\nlemma mat_poly_equiv_coeff_apply_aux_2\n  (i j : n) (p : R[X]) (k : \u2115) :\n  coeff (mat_poly_equiv (std_basis_matrix i j p)) k =\n    std_basis_matrix i j (coeff p k) :=\nbegin\n  apply polynomial.induction_on' p,\n  { intros p q hp hq, ext,\n    simp [hp, hq, coeff_add, add_apply, std_basis_matrix_add], },\n  { intros k x,\n    simp only [mat_poly_equiv_coeff_apply_aux_1, coeff_monomial],\n    split_ifs; { funext, simp, }, }\nend\n\n@[simp] lemma mat_poly_equiv_coeff_apply\n  (m : matrix n n R[X]) (k : \u2115) (i j : n) :\n  coeff (mat_poly_equiv m) k i j = coeff (m i j) k :=\nbegin\n  apply matrix.induction_on' m,\n  { simp, },\n  { intros p q hp hq, simp [hp, hq], },\n  { intros i' j' x,\n    erw mat_poly_equiv_coeff_apply_aux_2,\n    dsimp [std_basis_matrix],\n    split_ifs,\n    { rcases h with \u27e8rfl, rfl\u27e9, simp [std_basis_matrix], },\n    { simp [std_basis_matrix, h], }, },\nend\n\n@[simp] lemma mat_poly_equiv_symm_apply_coeff\n  (p : (matrix n n R)[X]) (i j : n) (k : \u2115) :\n  coeff (mat_poly_equiv.symm p i j) k = coeff p k i j :=\nbegin\n  have t : p = mat_poly_equiv\n    (mat_poly_equiv.symm p) := by simp,\n  conv_rhs { rw t, },\n  simp only [mat_poly_equiv_coeff_apply],\nend\n\nlemma mat_poly_equiv_smul_one (p : R[X]) :\n  mat_poly_equiv (p \u2022 1) = p.map (algebra_map R (matrix n n R)) :=\nbegin\n  ext m i j,\n  simp only [coeff_map, one_apply, algebra_map_matrix_apply, mul_boole,\n    pi.smul_apply, mat_poly_equiv_coeff_apply],\n  split_ifs; simp,\nend\n\nlemma support_subset_support_mat_poly_equiv\n  (m : matrix n n R[X]) (i j : n) :\n  support (m i j) \u2286 support (mat_poly_equiv m) :=\nbegin\n  assume k,\n  contrapose,\n  simp only [not_mem_support_iff],\n  assume hk,\n  rw [\u2190 mat_poly_equiv_coeff_apply, hk],\n  refl\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/polynomial_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.728493825610343}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport data.real.basic -- imports the real numbers\n\n/-!\n\n# Doing algebra in the real numbers\n\nThe `ring` tactic will prove algebraic identities like\n(x + y) ^ 2 = x ^ 2 + 2 * x * y + y ^ 2 in rings, and Lean\nknows that the real numbers are a ring. See if you can use\n`ring` to prove these theorems.\n\n## New tactics you will need\n\n* `ring`\n* `intro` (new functionality: use on a goal of type `\u22a2 \u2200 x, ...`)\n\n-/\n\nexample (x y : \u211d) : (x + y) ^ 2  = x ^ 2 + 2 * x * y + y ^ 2 :=\nbegin\n  ring,\nend\n\nexample : \u2200 (a b : \u211d), \u2203 x, \n  (a + b) ^ 3 = a ^ 3 + x * a ^ 2 * b + 3 * a * b ^ 2 + b ^ 3 :=\nbegin\n  intros a b,\n  use 3,\n  ring,\nend\n\nexample : \u2203 (x : \u211d), \u2200 y, y + y = x * y :=\nbegin\n  use 2,\n  intro y,\n  ring,\nend\n\nexample : \u2200 (x : \u211d), \u2203 y, x + y = 2 :=\nbegin\n  intro x,\n  use 2 - x,\n  norm_num,\n  -- ring, -- also does the job\nend\n\nexample : \u2200 (x : \u211d), \u2203 y, x + y \u2260 2 :=\nbegin\n  intro x,\n  use 1 - x,\n  norm_num,\nend\n", "meta": {"author": "ineswright", "repo": "formalising-maths-2023", "sha": "d29dee07d9d55e96bcfd3d783d6f56943d61d8b6", "save_path": "github-repos/lean/ineswright-formalising-maths-2023", "path": "github-repos/lean/ineswright-formalising-maths-2023/formalising-maths-2023-d29dee07d9d55e96bcfd3d783d6f56943d61d8b6/src/section02reals/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7284938097421388}}
{"text": "-- Prueba de la reflexividad de la inclusi\u00f3n de conjuntos\n-- ======================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    A \u2286 A\n-- ----------------------------------------------------\n\nimport data.set\nvariable  U : Type\nvariable  x : U\nvariables A B C : set U\n\n-- #reduce x \u2208 A\n-- #reduce B \u2286 C\n\n-- 1\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nbegin\n  intros x h,\n  exact h,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nassume x, \nassume h : x \u2208 A,\nshow x \u2208 A, from h\n\n-- 3\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nassume x, \nassume h : x \u2208 A,\nh\n\n-- 4\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nassume x, \n\u03bb h : x \u2208 A, h\n\n-- 5\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nassume x, \nid\n\n-- 6\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\n\u03bb x, id\n\n-- 7\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\n-- by library_search\nset.subset.rfl\n\nopen set\n\n-- 8\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nsubset.rfl\n\n-- 9\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\n-- by hint\nby tauto\n\n-- 10\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nby finish\n\n-- 11\u00aa demostraci\u00f3n\nexample : A \u2286 A :=\nby refl \n\n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Prueba_de_la_reflexividad_de_la_inclusion_de_conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7283900491403041}}
{"text": "import data.int.basic\n\nnamespace utils \n\nopen int nat list\n\nlemma gt_both_of_mult {m n : \u2115} (h : m * n > 0) : m > 0 \u2227 n > 0 :=\nand.intro\n  begin\n    cases m,\n      {rw zero_mul at h, cases h},\n      {apply nat.zero_lt_succ}\n  end\n  begin\n    cases n, \n      {cases h},\n      {apply nat.zero_lt_succ}\n  end\n\nlemma gt_mult_of_both {m n : \u2115} (h : m > 0) (h\u2081 : n > 0) : m * n > 0 :=\nbegin\n  suffices h\u2082 : 0 * n < m * n,\n    rw zero_mul at h\u2082, exact h\u2082,\n  apply mul_lt_mul_of_pos_right; assumption\nend\n\nlemma lt_of_coe_lt_gt_zero {x : \u2124} {y : \u2115} (h : y > 0) : x < x + \u2191y :=\nbegin\n  apply lt_add_of_pos_right,\n  simp [(>)] at *,\n  exact h\nend\n\nlemma lt_of_add {m n k : \u2115} (h : m + n < k) : m < k :=\nbegin\n  induction n with n ih,\n    {exact h},\n    {\n      apply ih,\n      rw [add_comm, nat.succ_add] at h,\n      have h : n + m < k,\n        from nat.lt_of_succ_lt h,\n      rw add_comm,\n      exact h\n    }\nend\n\nlemma nat_le_dest : \u2200 {n m : \u2115}, n < m \u2192 \u2203 k, nat.succ n + k = m\n  | n ._ (less_than_or_equal.refl ._)  := \u27e80, rfl\u27e9\n  | n ._ (@less_than_or_equal.step ._ m h) :=\n    match le.dest h with\n      | \u27e8w, hw\u27e9 := \u27e8succ w, hw \u25b8 rfl\u27e9\n    end\n\nlemma zip_nil_right {\u03b1 \u03b2 : Type} {l : list \u03b1} : zip l ([] : list \u03b2) = [] :=\n  by cases l; refl\n\nlemma zip_nil_iff {\u03b1 \u03b2 : Type} (l\u2081 : list \u03b1) (l\u2082 : list \u03b2) :\n  list.zip l\u2081 l\u2082 = [] \u2194 l\u2081 = [] \u2228 l\u2082 = [] :=\niff.intro (\u03bbh, by cases l\u2081; cases l\u2082; finish)\n          (\u03bbh, begin cases h with h\u2081 h\u2081; rw h\u2081;\n                     unfold zip zip_with,\n                     exact zip_nil_right end)\n\nlemma zip_with_len_l {\u03b1 \u03b2 \u03b3 : Type*} {l\u2081 : list \u03b1} {l\u2082 : list \u03b2} {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3}\n  (h : length l\u2081 = length l\u2082) : length (zip_with f l\u2081 l\u2082) = length l\u2081 :=\nbegin\n  induction l\u2081 with x xs ih generalizing l\u2082,\n    {simp [zip_with]},\n    {\n      cases l\u2082 with y ys,\n        {injection h},\n        {\n          simp only [zip_with, length],\n          rw ih, injection h\n        }\n    }\nend\n\nlemma zip_with_len_r {\u03b1 \u03b2 \u03b3 : Type*} {l\u2081 : list \u03b1} {l\u2082 : list \u03b2} {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3}\n  (h : length l\u2081 = length l\u2082) : length (zip_with f l\u2081 l\u2082) = length l\u2082 :=\nbegin\n  induction l\u2081 with x xs ih generalizing l\u2082,\n    {rw \u2190 h, simp [zip_with]},\n    {\n      cases l\u2082 with y ys,\n        {injection h},\n        {\n          simp only [zip_with, length],\n          rw ih, injection h\n        }\n    }\nend\n\nlemma repeat_nil {\u03b1 : Type} (x : \u03b1) (n : \u2115) : list.repeat x n = [] \u2194 n = 0 :=\niff.intro (\u03bbh, begin\n                 cases n,\n                   refl,\n                 unfold list.repeat at h,\n                 cases h\n               end)\n          (\u03bbh, by rw h; refl)\n\nlemma nat_abs_zero_iff (a b : \u2124) : nat_abs (a - b) = 0 \u2194 a = b :=\niff.intro begin generalize h : a - b = c, intros,\n                cases c; dsimp at a_1, rw a_1 at h,\n                  apply eq_of_sub_eq_zero,\n                  rw of_nat_zero at h,\n                  exact h,\n                cases a_1\n          end\n          begin generalize h : a - b = c, intros,\n                rw a_1 at h, rw sub_self at h,\n                rw \u2190 h, refl\n          end\n\nlemma join_empty_of_all_empty {\u03b1 : Type*} (xs : list (list \u03b1)) \n  (h : (\u2200x, x \u2208 xs \u2192 x = [])) : join xs = [] :=\nbegin\n  induction xs with x xs ih,\n    {refl},\n    {\n      unfold join,\n      have h\u2081 : x = [], from h _ (by left; refl),\n      rw h\u2081, rw nil_append,\n      apply ih, intros x\u2081,\n      specialize h x\u2081, intros h\u2082,\n      apply h, right, exact h\u2082\n    }\nend\n\nlemma repeat_more {\u03b1 : Type} (x : \u03b1) (n : \u2115) (h : n \u2265 1) :\n  repeat x n = x :: repeat x (n - 1) :=\nbegin\n  cases n, cases h,\n  dsimp, apply congr_arg, rw sub_one,\n  refl\nend\n\nlemma one_le_succ (a : \u2115) : 1 \u2264 nat.succ a :=\nbegin\n  induction a,\n    exact le_refl _,\n  constructor, exact a_ih\nend\n\nlemma nat_abs_of_lt {a b : \u2124} (h : a < b) : nat_abs (b - a) \u2265 1 :=\nhave h\u2081 : b - a > 0, from sub_pos_of_lt h,\nbegin\n  simp only [(\u2265)],\n  rw [\u2190 coe_nat_le, nat_abs_of_nonneg (int.le_of_lt h\u2081), int.coe_nat_one],\n  conv { to_lhs, rw \u2190 zero_add (1 : \u2124) },\n  apply add_one_le_of_lt,\n  exact h\u2081\nend\n\nlemma neg_lt_of_succ (n : \u2115) (a : \u2124) (h : a \u2265 0) : -\u2191n < a + (1 : \u2124) :=\nhave h\u2081 : -\u2191n \u2264 (0 : \u2124), {rw neg_le, rw neg_zero, trivial},\nhave h\u2082 : 0 < a + 1, {rw lt_add_one_iff, exact h},\nlt_of_le_of_lt h\u2081 h\u2082\n\nsection bounded\n\nvariables {\u03b1 : Type} [decidable_linear_order \u03b1]\n\ndef bounded (a b : \u03b1) :=\n  {x : \u03b1 // a \u2264 x \u2227 x < b}\n\ndef is_bounded (a b : \u03b1) (y : \u03b1) :=\n  a \u2264 y \u2227 y < b\n\nlemma is_bounded_of_bounds {a b y : \u03b1} (h : a \u2264 y) (h\u2081 : y < b) :\n  is_bounded a b y := and.intro h h\u2081\n\ninstance is_bounded_dec (a b y : \u03b1) : decidable (is_bounded a b y) :=\n  by simp [is_bounded]; apply_instance\n\ndef make_bounded {a b : \u03b1} {x : \u03b1} (h : is_bounded a b x) : bounded a b :=\n  \u27e8x, h\u27e9\n\ndef z_of_bounded {a b : \u03b1} (b : bounded a b) :=\n  match b with \u27e8z, _\u27e9 := z end\n\ndef bounded_to_str [\u03c6 : has_to_string \u03b1] {a b : \u03b1} :\n  bounded a b \u2192 string := to_string \u2218 z_of_bounded\n\ninstance bounded_repr {a b : \u03b1} [has_to_string \u03b1] :\n  has_repr (bounded a b) := \u27e8bounded_to_str\u27e9\n\ninstance bounded_str (a b : \u03b1) [has_to_string \u03b1] :\n  has_to_string (bounded a b) := \u27e8bounded_to_str\u27e9\n\ninstance bounded_to_carrier_coe (a b : \u03b1) : has_coe (bounded a b) \u03b1 :=\n  \u27e8z_of_bounded\u27e9\n\ninstance zbound_dec_eq {a b : \u03b1} : decidable_eq (bounded a b)\n  | \u27e8x, _\u27e9 \u27e8y, _\u27e9 := by apply_instance\n\ninstance coe_bounded {\u03b1 : Type} {a b : \u03b1} [decidable_linear_order \u03b1] :\n  has_coe (@bounded \u03b1 _ a b) \u03b1 := \u27e8z_of_bounded\u27e9\n\nlemma coe_is_z_of_bounded {\u03b1 : Type} {a b : \u03b1} [decidable_linear_order \u03b1]\n  (x : bounded a b) : z_of_bounded x = \u2191x := rfl\n\nlemma positive_bounded {x : \u2115} (a : bounded 0 x) : \u2191a \u2265 0 :=\nlet \u27e8a, \u27e8l, r\u27e9\u27e9 := a in by rw \u2190 coe_is_z_of_bounded; simpa [z_of_bounded]\n\nlemma bounded_lt {x : \u2115} (a : bounded 0 x) : \u2191a < x :=\nlet \u27e8a, \u27e8l, r\u27e9\u27e9 := a in by rw \u2190 coe_is_z_of_bounded; simpa [z_of_bounded]\n\nend bounded\n\nstructure point := (x : \u2124) (y : \u2124)\n\nprivate def point_rep : point \u2192 string\n  | \u27e8x, y\u27e9 := \"[\" ++ to_string x ++ \", \" ++ to_string y ++ \"]\"\n\ndef point_eq (p\u2081 p\u2082 : point) := p\u2081.x = p\u2082.x \u2227 p\u2081.y = p\u2082.y\n\ninstance dec_eq_p {p\u2081 p\u2082} : decidable (point_eq p\u2081 p\u2082) :=\n  by simp [point_eq]; apply_instance\n\ninstance dec_eq_point : decidable_eq point :=\n  \u03bb\u27e8x\u2081, y\u2081\u27e9 \u27e8x\u2082, y\u2082\u27e9,\n  begin\n    by_cases h\u2081 : x\u2081 = x\u2082;\n    by_cases h\u2082 : y\u2081 = y\u2082,\n      {\n        apply is_true,\n          rw h\u2081, rw h\u2082\n      },\n      {\n        apply is_false,\n          rw h\u2081, intros contra,\n          injection contra, contradiction\n      },\n      {\n        apply is_false,\n          rw h\u2082, intros contra,\n          injection contra, contradiction\n      },\n      {\n        apply is_false,\n          intros contra, injection contra,\n          contradiction\n      } \n  end\n\ninstance : has_to_string point := \u27e8point_rep\u27e9\n\ninstance : has_repr point := \u27e8point_rep\u27e9\n\ndef grid_sorted : point \u2192 point \u2192 Prop\n  | \u27e8x, y\u27e9 \u27e8x\u2081, y\u2081\u27e9 := x < x\u2081 \u2227 y\u2081 < y\n\ninfix `\u2197` : 50 := grid_sorted\n\ninstance {a b : point} : decidable (a \u2197 b) :=\n  let \u27e8x, y\u27e9 := a in\n  let \u27e8x\u2081, y\u2081\u27e9 := b in by simp [(\u2197)]; apply_instance\n\ninstance {a b : point} : is_irrefl point grid_sorted := {\n  irrefl := \u03bb\u27e8x, y\u27e9, begin\n                      simp [(\u2197)], intros contra,\n                      refl\n                    end\n}\n\ninstance {a b : point} : is_trans point grid_sorted := {\n  trans := \u03bb\u27e8x, y\u27e9 \u27e8x\u2081, y\u2081\u27e9 \u27e8x\u2082, y\u2082\u27e9 \u27e8h, h\u2081\u27e9 \u27e8h\u2082, h\u2083\u27e9,\n             begin\n               simp [(\u2197)] at *,\n               exact and.intro (lt_trans h h\u2082) (lt_trans h\u2083 h\u2081)\n             end\n}\n\ninstance {a b : point}\n         [c : is_irrefl point grid_sorted]\n         [c\u2081 : is_trans point grid_sorted] :\n         is_strict_order point grid_sorted := by constructor; assumption\n\ndef le_of_add_le_left (a b c : \u2124) (h\u2081 : 0 \u2264 b) (h\u2082 : a + b \u2264 c) : a \u2264 c :=\nbegin\n  apply (@le_of_add_le_add_right _ _ a b c),\n  apply le_add_of_le_of_nonneg; assumption\nend\n\nlemma grid_bounded_iff {p\u2081 p\u2082 : point} : p\u2081\u2197p\u2082 \u2194 (p\u2081.x < p\u2082.x \u2227 p\u2082.y < p\u2081.y) :=\n  by cases p\u2081; cases p\u2082; simp [(\u2197)]\n\nlemma length_zip_left {\u03b1 \u03b2 : Type*} {l\u2081 : list \u03b1} {l\u2082 : list \u03b2}\n  (h : length l\u2081 = length l\u2082) : length (zip l\u2081 l\u2082) = length l\u2081 :=\nbegin\n  induction l\u2081 generalizing l\u2082; cases l\u2082,\n    refl, \n    cases h,\n    cases h,\n  unfold zip zip_with,\n  dsimp,\n  repeat {rw add_one},\n  apply congr_arg,\n  apply l\u2081_ih,\n  dsimp at h, injection h\nend\n\nlemma not_grid_bounded_iff {p\u2081 p\u2082 : point} :\n  \u00acp\u2081\u2197p\u2082 \u2194 (p\u2082.x \u2264 p\u2081.x \u2228 p\u2081.y \u2264 p\u2082.y) :=\nbegin\n  cases p\u2081; cases p\u2082,\n  unfold point.x point.y,\n  simp [(\u2197)],\n  split; intros h,\n  {\n    by_cases h\u2081 : p\u2081_x < p\u2082_x,\n    have h := h h\u2081,\n    right, exact h,\n    rw not_lt_iff_eq_or_lt at h\u2081,\n    cases h\u2081, rw h\u2081, left, refl,\n    left, apply int.le_of_lt, assumption\n  },\n  {\n    intros h\u2081,\n    cases h,\n    have contra : p\u2081_x < p\u2081_x, from lt_of_lt_of_le h\u2081 h,\n    have contra\u2081 : \u00acp\u2081_x < p\u2081_x, from lt_irrefl _,\n    contradiction,\n    exact h\n  }\nend\n\nlemma abs_nat_lt : \u2200n m : \u2124, (0 \u2264 n) \u2192 n < m \u2192 nat_abs n < nat_abs m\n  | (of_nat n\u2081) (of_nat n\u2082) zlen nltm :=\n  begin\n    dsimp,\n    revert n\u2081, induction n\u2082; intros; cases n\u2081,\n    {cases nltm},\n    {cases nltm},\n    {apply zero_lt_succ},\n    {apply succ_lt_succ,\n     apply n\u2082_ih,\n       {cases n\u2081, apply le_refl,\n        rewrite of_nat_succ, rewrite add_comm,\n        unfold has_le.le},\n       {rewrite of_nat_succ at nltm,\n        rewrite of_nat_succ at nltm,\n        apply lt_of_add_lt_add_right nltm}\n       }\n  end\n\ndef range_weaken_lower_any {a b c : \u2124} (h : c \u2264 a) : bounded a b \u2192 bounded c b\n  | \u27e8i, \u27e8lbound, rbound\u27e9\u27e9 :=\n    \u27e8i, and.intro\n          (le_trans h lbound)\n          rbound\u27e9\n\ndef range_weaken_upper_any {a b c : \u2124} (h : b \u2264 c) : bounded a b \u2192 bounded a c\n  | \u27e8i, \u27e8lbound, rbound\u27e9\u27e9 :=\n    \u27e8i, and.intro\n          lbound\n          (have h : b < c \u2228 b = c, from lt_or_eq_of_le h,\n           or.elim h\n            (assume h, lt_trans rbound h)\n            (by cc))\u27e9\n\ndef range_weaken {a b : \u2124} (h : bounded (a + 1) b) : bounded a b\n  := range_weaken_lower_any\n       (le_of_add_le_left _ 1 _ dec_trivial (le_refl _)) h\n\ndef range : \u2200(a b : \u2124), list (bounded a b) \n  | fro to := if h : fro < to\n              then \u27e8fro, and.intro (le_refl _) h\u27e9\n                   :: list.map range_weaken (range (fro + 1) to)\n              else []\n  using_well_founded {\n    rel_tac := \u03bbf args,\n      `[exact \u27e8\n          measure (\u03bb\u27e8fro, to\u27e9, nat_abs (to - fro)),\n          measure_wf _\n        \u27e9],\n    dec_tac := `[apply abs_nat_lt,\n                   {rewrite \u2190 sub_sub,\n                    have h\u2081 : 0 < to - fro,\n                      apply sub_pos_of_lt, exact h,\n                    have h\u2082 : 0 + 1 < (to - fro) + 1,\n                      apply add_lt_add_of_lt_of_le,\n                      exact h\u2081, reflexivity,\n                    have h\u2083 : (0 + 1 : \u2124) = 1,\n                      exact dec_trivial,\n                    rw h\u2083 at h\u2082,\n                    have h\u2084 : (0 + 1 \u2264 to - fro - 1 + 1) \u2192 0 \u2264 to - fro - 1,\n                      exact le_of_add_le_add_right,\n                    apply h\u2084, rw h\u2083,\n                    rewrite sub_eq_add_neg,\n                    rewrite sub_eq_add_neg,\n                    rewrite add_assoc,\n                    have h\u2085 : (-1 + 1 : \u2124) = 0,\n                      exact dec_trivial,\n                    rewrite h\u2085,\n                    rewrite add_assoc,\n                    rewrite add_comm,\n                    rewrite add_zero,\n                    rewrite add_comm,\n                    have h\u2086 : to + -fro = to - fro,\n                      refl,\n                    rewrite h\u2086,\n                    unfold has_lt.lt int.lt at h\u2081,\n                    rewrite h\u2083 at h\u2081,\n                    exact h\u2081},\n                   {rewrite \u2190 sub_sub,\n                    apply lt_of_le_sub_one,\n                    reflexivity}]\n  }\n\ndef range_pure : \u2124 \u2192 \u2124 \u2192 list \u2124\n  | fro to :=  if h : fro < to\n               then fro :: range_pure (fro + 1) to else []\n  using_well_founded {\n    rel_tac := \u03bbf args,\n      `[exact \u27e8\n          measure (\u03bb\u27e8a, b\u27e9, nat_abs (b - a)),\n          measure_wf _\n        \u27e9],\n    dec_tac := `[\n      apply abs_nat_lt,\n                   {\n                     rewrite \u2190 sub_sub,\n                    have h\u2081 : 0 < to - fro,\n                      apply sub_pos_of_lt, exact h,\n                    have h\u2082 : 0 + 1 < (to - fro) + 1,\n                      apply add_lt_add_of_lt_of_le,\n                      exact h\u2081, reflexivity,\n                    have h\u2083 : (0 + 1 : \u2124) = 1,\n                      exact dec_trivial,\n                    rw h\u2083 at h\u2082,\n                    have h\u2084 : (0 + 1 \u2264 to - fro - 1 + 1) \u2192 0 \u2264 to - fro - 1,\n                      exact le_of_add_le_add_right,\n                    apply h\u2084, rw h\u2083,\n                    rewrite sub_eq_add_neg,\n                    rewrite sub_eq_add_neg,\n                    rewrite add_assoc,\n                    have h\u2085 : (-1 + 1 : \u2124) = 0,\n                      exact dec_trivial,\n                    rewrite h\u2085,\n                    rewrite add_assoc,\n                    rewrite add_comm,\n                    rewrite add_zero,\n                    rewrite add_comm,\n                    have h\u2086 : to + -fro = to - fro,\n                      refl,\n                    rewrite h\u2086,\n                    unfold has_lt.lt int.lt at h\u2081,\n                    rewrite h\u2083 at h\u2081,\n                    exact h\u2081\n                    },\n                   {\n                     rewrite \u2190 sub_sub,\n                    apply lt_of_le_sub_one,\n                    reflexivity\n                    }\n                    ]\n  }          \n\nlemma range_pure_cons {a b} {x xs} (h : range_pure a b = x :: xs) :\n  range_pure (a + 1) b = xs :=\nbegin\n  have h\u2081 : a < b,\n    {\n      by_cases h\u2082 : a < b,\n        {exact h\u2082},\n        {\n          unfold1 range_pure at h,\n          rw if_neg h\u2082 at h,\n          cases h\n        },\n    },\n  unfold1 range_pure at h,\n  rw if_pos h\u2081 at h,\n  injection h\nend\n\nlemma range_pure_bounded {a b : \u2124} :\n  \u2200{c}, c \u2208 range_pure a b \u2192 is_bounded a b c :=\nassume c,\nbegin\n  generalize h : range_pure a b = l,\n  induction l with x xs ih generalizing a b; intros h\u2081,\n    {\n      cases h\u2081\n    },\n    {\n      rw mem_cons_iff at h\u2081,\n      cases h\u2081 with h\u2081,\n        {\n          subst h\u2081,\n          unfold1 range_pure at h,\n          by_cases h\u2082 : a < b; simp [h\u2082] at h,\n            {\n              cases h with hl hr, subst hl,\n              split, refl, exact h\u2082\n            },\n            {\n              cases h\n            }\n        },\n        {\n          have h\u2082 : a < b,\n            {\n              by_cases eq : a < b,\n                {exact eq},\n                {\n                  unfold1 range_pure at h,\n                  rw if_neg eq at h,\n                  cases h\n                },\n            },\n          unfold1 range_pure at h,\n          rw if_pos h\u2082 at h,\n          injection h with hl hr,\n          have ih\u2081 := @ih (a + 1) b hr h\u2081,\n          cases ih\u2081 with lb ub,\n          split,\n            {\n              have lb := lt_of_add_one_le lb,\n              exact int.le_of_lt lb\n            },\n            {\n              exact ub\n            }\n        }\n    }\nend\n\ndef range_pure_m (a b : \u2124) : list \u2124 := map z_of_bounded (range a b)\n\nlemma range_empty_iff (a b : \u2124) : range a b = [] \u2194 (b \u2264 a) :=\nbegin\n  split; intros h,\n  {\n    unfold1 range at h,\n    by_cases h\u2081 : a < b; simp [h\u2081] at h,\n      {contradiction},\n      {finish},\n  },\n  {\n    unfold1 range,\n    by_cases h\u2081 : a < b; simp [h\u2081],\n    have contra : \u00acb \u2264 a, from not_le_of_gt h\u2081,\n    contradiction\n  }\nend\n\nlemma range_length_same (a : \u2124) : length (range a a) = 0 :=\nbegin\n  unfold1 range,\n  have h : \u00aca < a, from lt_irrefl _,\n  simp [h]\nend\n\nlemma range_length_one (a : \u2124) : length (range a (a + 1)) = 1 :=\nbegin\n  unfold1 range,\n  have h : a < a + 1, from lt_add_succ _ _,\n  simp [h],\n  rw range_length_same\nend\n\nlemma range_pure_length_same (a : \u2124) : length (range_pure a a) = 0 :=\nbegin\n  unfold1 range_pure,\n  have h : \u00aca < a, from lt_irrefl _,\n  simp [h]\nend\n\nlemma range_pure_length_one (a : \u2124) : length (range_pure a (a + 1)) = 1 :=\nbegin\n  unfold1 range_pure,\n  have h : a < a + 1, from lt_add_succ _ _,\n  simp [h],\n  rw range_pure_length_same\nend\n\nlemma range_length {a b : \u2124} (h : a \u2264 b) :\n  length (range a b) = nat_abs (b - a) :=\nbegin\n  generalize h\u2081 : nat_abs (b - a) = n,\n  induction n with n ih generalizing a b,\n    {\n      rw nat_abs_zero_iff at h\u2081,\n      rw h\u2081,\n      exact range_length_same _\n    },\n    {\n      have h\u2082 : a < b,\n        begin\n          rw le_iff_eq_or_lt at h,\n          cases h,\n            {\n              have h : b = a, by cc,\n              rw \u2190 nat_abs_zero_iff at h,\n              rw h at h\u2081, cases h\u2081\n            },\n            {exact h}\n        end,\n      clear h,\n      have h\u2083 : a + 1 \u2264 b, from add_one_le_of_lt h\u2082,\n      have h\u2084 : nat_abs (b - (a + 1)) = n,\n        begin\n          rw \u2190 sub_sub,\n          rw \u2190 int.coe_nat_eq_coe_nat_iff,\n          have h\u2085 : b - a - 1 \u2265 (0 : \u2124),\n            {\n              simp [(\u2265)],\n              rw \u2190 add_le_add_iff_right (1 : \u2124),\n              rw zero_add, rw \u2190 sub_eq_add_neg,\n              rw add_sub, rw \u2190 sub_eq_add_neg, \n              rw sub_add_cancel,\n              rw \u2190 add_le_add_iff_right a,\n              rw sub_add_cancel, rw add_comm,\n              exact h\u2083\n            },\n          rw nat_abs_of_nonneg h\u2085,\n          rw \u2190 add_right_cancel_iff, any_goals {exact (1 : \u2124)},\n          rw sub_add_cancel,\n          have h\u2086 : b - a \u2265 (0 : \u2124),\n            {\n              simp [(\u2265)],\n              rw \u2190 sub_lt_sub_iff_right a at h\u2082,\n              rw sub_self at h\u2082,\n              apply int.le_of_lt,\n              exact h\u2082\n            },\n          rw \u2190 int.coe_nat_eq_coe_nat_iff at h\u2081,\n          rw nat_abs_of_nonneg h\u2086 at h\u2081,\n          exact h\u2081\n        end,\n      have ih := ih h\u2083 h\u2084,\n      unfold1 range at ih,\n      rw le_iff_eq_or_lt at h\u2083,\n      cases h\u2083,\n        {\n          have h\u2087 : \u00aca + 1 < b, rw \u2190 h\u2083, intros contra,\n            have h\u2088 : \u00aca + 1 < a + 1, from lt_irrefl _,\n            contradiction,\n          simp [h\u2087] at ih,\n          rw \u2190 ih, rw \u2190 h\u2083, rw range_length_one\n        },\n        {\n          simp [h\u2083] at ih,\n          unfold1 range,\n          simp [h\u2082],\n          unfold1 range,\n          simp [h\u2083],\n          rw \u2190 ih,\n          rw \u2190 one_add\n        }\n    }\nend\n\nlemma range_length_pure {a b : \u2124} (h : a \u2264 b) :\n  length (range_pure a b) = nat_abs (b - a) := \nbegin\n    generalize h\u2081 : nat_abs (b - a) = n,\n  induction n with n ih generalizing a b,\n    {\n      rw nat_abs_zero_iff at h\u2081,\n      rw h\u2081,\n      exact range_pure_length_same _\n    },\n    {\n      have h\u2082 : a < b,\n        begin\n          rw le_iff_eq_or_lt at h,\n          cases h,\n            {\n              have h : b = a, by cc,\n              rw \u2190 nat_abs_zero_iff at h,\n              rw h at h\u2081, cases h\u2081\n            },\n            {exact h}\n        end,\n      clear h,\n      have h\u2083 : a + 1 \u2264 b, from add_one_le_of_lt h\u2082,\n      have h\u2084 : nat_abs (b - (a + 1)) = n,\n        begin\n          rw \u2190 sub_sub,\n          rw \u2190 int.coe_nat_eq_coe_nat_iff,\n          have h\u2085 : b - a - 1 \u2265 (0 : \u2124),\n            {\n              simp [(\u2265)],\n              rw \u2190 add_le_add_iff_right (1 : \u2124),\n              rw zero_add, rw \u2190 sub_eq_add_neg,\n              rw add_sub, rw \u2190 sub_eq_add_neg, \n              rw sub_add_cancel,\n              rw \u2190 add_le_add_iff_right a,\n              rw sub_add_cancel, rw add_comm,\n              exact h\u2083\n            },\n          rw nat_abs_of_nonneg h\u2085,\n          rw \u2190 add_right_cancel_iff, any_goals {exact (1 : \u2124)},\n          rw sub_add_cancel,\n          have h\u2086 : b - a \u2265 (0 : \u2124),\n            {\n              simp [(\u2265)],\n              rw \u2190 sub_lt_sub_iff_right a at h\u2082,\n              rw sub_self at h\u2082,\n              apply int.le_of_lt,\n              exact h\u2082\n            },\n          rw \u2190 int.coe_nat_eq_coe_nat_iff at h\u2081,\n          rw nat_abs_of_nonneg h\u2086 at h\u2081,\n          exact h\u2081\n        end,\n      have ih := ih h\u2083 h\u2084,\n      unfold1 range_pure at ih,\n      rw le_iff_eq_or_lt at h\u2083,\n      cases h\u2083,\n        {\n          have h\u2087 : \u00aca + 1 < b, rw \u2190 h\u2083, intros contra,\n            have h\u2088 : \u00aca + 1 < a + 1, from lt_irrefl _,\n            contradiction,\n          simp [h\u2087] at ih,\n          rw \u2190 ih, rw \u2190 h\u2083, rw range_pure_length_one\n        },\n        {\n          simp [h\u2083] at ih,\n          unfold1 range_pure,\n          simp [h\u2082],\n          unfold1 range_pure,\n          simp [h\u2083],\n          rw \u2190 ih,\n          rw \u2190 one_add\n        }\n    }\nend\n\nopen list function\n\ndef empty_list {\u03b1 : Type} (l : list \u03b1) := [] = l\n\nlemma not_empty_of_len {\u03b1 : Type} {l : list \u03b1}\n  (h : length l > 0) : \u00acempty_list l :=\nbegin\n  simp [empty_list],\n  cases l,\n    {\n      cases h\n    },\n    {\n      trivial\n    }\nend\n\nlemma empty_list_eq_ex {\u03b1 : Type} {l : list \u03b1} (h : \u00acempty_list l) :\n  \u2203(x : \u03b1) (xs : list \u03b1), l = x :: xs :=\nbegin\n  cases l,\n    unfold empty_list at h, contradiction,\n  existsi l_hd, existsi l_tl,\n  refl\nend\n\ninstance decidable_empty_list {\u03b1 : Type} : \u2200l : list \u03b1,\n  decidable (empty_list l)\n  | [] := is_true rfl\n  | (x :: _) := is_false (by simp [empty_list])\n\ntheorem unempty_nil_eq_false {\u03b1 : Type} : \u00ac(empty_list (@nil \u03b1)) \u2194 false :=\n  begin\n    simp [empty_list]\n  end\n\ndef head1 {\u03b1 : Type} (l : list \u03b1) (h : \u00acempty_list l) :=\n  match l, h with\n    | [], p := by rw unempty_nil_eq_false at p; contradiction\n    | (x :: _), _ := x\n  end\n\ndef foldr1 {\u03b1 : Type} (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (l : list \u03b1) (h : \u00acempty_list l) : \u03b1 :=\n  match l, h with\n    | [], p := by rw unempty_nil_eq_false at p; contradiction\n    | (x :: xs), _ := foldr f x xs\n  end\n\nlemma foldr1_unempty_eq_foldr {\u03b1 : Type} (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (l : list \u03b1)\n  (h : \u00acempty_list l) : foldr1 f l h = list.foldr f (head1 l h) (tail l) :=\nbegin\n  cases l,\n    rw unempty_nil_eq_false at h, contradiction,\n  unfold foldr1 head1 tail\nend\n\ndef min_element {\u03b1 : Type} [decidable_linear_order \u03b1]\n  (l : list \u03b1) (h : \u00acempty_list l) := foldr1 min l h\n\ndef max_element {\u03b1 : Type} [decidable_linear_order \u03b1]\n  (l : list \u03b1) (h : \u00acempty_list l) := foldr1 max l h\n\nlemma foldr_swap {\u03b1 : Type*}\n  (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) (h : is_commutative _ f) (h\u2081 : is_associative _ f)\n  {x y : \u03b1} {xs : list \u03b1} :\n  foldr f x (y :: xs) = foldr f y (x :: xs) :=\nhave comm : \u2200a b, f a b = f b a, by finish,\nhave assoc : \u2200a b c, f a (f b c) = f (f a b) c, by finish,\nlist.rec_on xs\n  (comm _ _) \n  (assume x\u2081 xs\u2081 ih,\n   by dsimp at *;\n      rw [assoc, comm y, \u2190 assoc, ih, assoc, comm x\u2081, \u2190 assoc])\n\nlemma le_min_elem_all {\u03b1 : Type*} [decidable_linear_order \u03b1]\n  (l : list \u03b1) (b : \u03b1) (h : \u00acempty_list l) :\n  (\u2200x, x \u2208 l \u2192 b \u2264 x) \u2192 b \u2264 min_element l h :=\nassume h\u2081,\nbegin\n  induction l with y ys ih,\n    {\n      unfold empty_list at h, contradiction\n    },\n    {\n      unfold min_element foldr1,\n      cases ys,\n        {\n          dsimp, apply h\u2081, left, refl\n        },\n        {\n          have ih := ih _ _,\n          unfold min_element foldr1 at ih,\n          rw foldr_swap min \u27e8min_comm\u27e9 \u27e8min_assoc\u27e9,\n          dsimp at *,\n          rw le_min_iff,\n          split,\n            {\n              apply h\u2081, left, refl\n            },\n            {\n              exact ih_1\n            },\n          unfold empty_list, intros ok, cases ok,\n          intros, apply h\u2081, right, simp [(\u2208)] at a, exact a\n        }\n    }\nend\n\nlemma max_le_elem_all {\u03b1 : Type*} [decidable_linear_order \u03b1]\n  (l : list \u03b1) (b : \u03b1) (h : \u00acempty_list l) :\n  (\u2200x, x \u2208 l \u2192 x \u2264 b) \u2192 max_element l h \u2264 b :=\nassume h\u2081,\nbegin\ninduction l with y ys ih,\n    {\n      unfold empty_list at h, contradiction\n    },\n    {\n      unfold max_element foldr1,\n      cases ys,\n        {\n          dsimp, apply h\u2081, left, refl\n        },\n        {\n          have ih := ih _ _,\n          unfold max_element foldr1 at ih,\n          rw foldr_swap max \u27e8max_comm\u27e9 \u27e8max_assoc\u27e9,\n          dsimp at *,\n          rw max_le_iff,\n          split,\n            {\n              apply h\u2081, left, refl\n            },\n            {\n              exact ih_1\n            },\n          unfold empty_list, intros ok, cases ok,\n          intros, apply h\u2081, right, simp [(\u2208)] at a, exact a\n        }\n    }\nend\n\nlemma min_le_max {\u03b1 : Type*} [decidable_linear_order \u03b1] (a : \u03b1) {b c : \u03b1}\n  (H : b \u2264 c) : min a b \u2264 max a c :=\nbegin\n  unfold min max,\n  by_cases h : a \u2264 b; simp [h];\n    by_cases h\u2081 : a \u2264 c; simp [h\u2081],\n  exact H, rw not_le at h, exact le_of_lt h\nend\n\nlemma min_elem_le_max_elem {\u03b1 : Type*} [decidable_linear_order \u03b1] (l : list \u03b1)\n  (h : \u00acempty_list l) : min_element l h \u2264 max_element l h :=\nbegin\n  unfold min_element max_element,\n  cases l with x xs, unfold empty_list at h, contradiction,\n  unfold foldr1,\n  induction xs with y ys,\n    {dsimp, refl},\n    {\n      dsimp, \n      have h\u2081 : \u00acempty_list (x :: ys),\n        by unfold empty_list; intros; contradiction,\n      have ih := xs_ih h\u2081,\n      exact min_le_max y ih\n    }\nend\n\nlemma map_empty_iff_l_empty {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) (l : list \u03b1) :\n  empty_list (map f l) \u2194 empty_list l :=\nbegin\n  split; intros h; cases l; try {finish <|> simp [empty_list]}\nend\n\nlemma unzip_one {\u03b1 \u03b2 : Type} (l : \u03b1) (r : \u03b2) (xs : list (\u03b1 \u00d7 \u03b2)) :\n  unzip ((l, r) :: xs) = ((l :: (unzip xs).fst), r :: (unzip xs).snd) :=\nbegin\n  simp [unzip],\n  cases (unzip xs),\n  simp [unzip]\nend\n\nlemma unzip_fst_empty_iff_l_empty {\u03b1 \u03b2 : Type} (l : list (\u03b1 \u00d7 \u03b2)) :\n  empty_list ((unzip l).fst) \u2194 empty_list l :=\nbegin\n  split; intros h; cases l; try {finish};\n  simp [empty_list, unzip] at *,\n  cases l_hd,\n  rw unzip_one at h,\n  contradiction\nend\n\nlemma unzip_snd_empty_iff_l_empty {\u03b1 \u03b2 : Type} (l : list (\u03b1 \u00d7 \u03b2)) :\n  empty_list ((unzip l).snd) \u2194 empty_list l :=\nbegin\n  split; intros h; cases l; try {finish};\n  simp [empty_list, unzip] at *,\n  cases l_hd,\n  rw unzip_one at h,\n  contradiction\nend\n\nlemma pair_in_zip_l {\u03b1 \u03b2} {a b} {l\u2081 : list \u03b1} {l\u2082 : list \u03b2}\n  (h : (a, b) \u2208 zip l\u2081 l\u2082) : a \u2208 l\u2081 :=\nbegin\n  induction l\u2081 with x xs ih generalizing l\u2082,\n    {\n      simp [zip, zip_with] at h, contradiction\n    },\n    {\n      cases l\u2082 with y ys,\n        {\n          simp [zip, zip_with] at h,\n          contradiction\n        },\n        {\n          unfold1 zip at h,\n          unfold1 zip_with at h,\n          rw mem_cons_iff at h,\n          cases h, injection h with hl hr,\n          subst hl, subst hr,\n          left, refl, rw mem_cons_eq,\n          right, apply ih, \n          unfold zip, exact h\n        }\n    }\nend\n\nlemma pair_in_zip_r {\u03b1 \u03b2} {a b} {l\u2081 : list \u03b1} {l\u2082 : list \u03b2}\n  (h : (a, b) \u2208 zip l\u2081 l\u2082) : b \u2208 l\u2082 :=\nbegin\n  induction l\u2081 with x xs ih generalizing l\u2082,\n    {\n      simp [zip, zip_with] at h, contradiction\n    },\n    {\n      cases l\u2082 with y ys,\n        {\n          simp [zip, zip_with] at h,\n          contradiction\n        },\n        {\n          unfold1 zip at h,\n          unfold1 zip_with at h,\n          rw mem_cons_iff at h,\n          cases h, injection h with hl hr,\n          subst hl, subst hr,\n          left, refl, rw mem_cons_eq,\n          right, apply ih, \n          unfold zip, exact h\n        }\n    }\nend\n\ndef decidable_uncurry {\u03b1 \u03b2 : Type*} {f : \u03b1 \u2192 \u03b2 \u2192 Prop} {x : \u03b1 \u00d7 \u03b2}\n  (h : decidable (f x.fst x.snd)) : decidable (uncurry f x) :=\nbegin\n  resetI,\n  cases x, unfold_projs at *,\n  simp [uncurry],\n  exact h\nend\n\nlemma filter_forall {\u03b1 : Type*} {P : \u03b1 \u2192 Prop} [decidable_pred P] (xs : list \u03b1)\n  (x : \u03b1) (h\u2081 : x \u2208 filter P xs) : P x :=\nbegin\n  induction xs with x\u2081 xs\u2081 ih; simp [filter] at h\u2081,\n    {\n      contradiction\n    },\n    {\n      by_cases h\u2082 : (P x\u2081); simp [h\u2082] at h\u2081,\n        {cases h\u2081,\n           {cc},\n           {exact ih h\u2081}},\n        {exact ih h\u2081}\n    }\nend\n\nlemma unempty_filter_ex {\u03b1 : Type*} {xs : list \u03b1} {p : \u03b1 \u2192 Prop}\n  [decidable_pred p] (h : \u00acempty_list (filter p xs)) :\n  \u2203x, x \u2208 xs \u2227 p x :=\nbegin\n  induction xs with x\u2081 xs\u2081 ih,\n    {\n      dsimp at h, unfold empty_list at h, contradiction\n    },\n    {\n      by_cases h\u2081 : p x\u2081,\n        {\n          existsi x\u2081, finish\n        },\n        {\n          unfold empty_list at *,\n          unfold filter at h,\n          simp [h\u2081] at h,\n          have ih := ih h,\n          cases ih with x\u2082 px\u2082,\n          existsi x\u2082,\n          simp [(\u2208), list.mem] at *,\n          split, right, exact px\u2082.left,\n          exact px\u2082.right\n        }\n    }\nend\n\ndef conv {\u03b1 : Type*} (f : \u03b1 \u2192 Type*) {a b : \u03b1} : a = b \u2192 f a \u2192 f b :=\n  assume h\u2081 h\u2082, by rw \u2190 h\u2081; exact h\u2082\n\ndef list_iso {\u03b1 : Type*} [decidable_eq \u03b1] : list \u03b1 \u2192 list \u03b1 \u2192 bool\n  | []        []        := tt\n  | (x :: xs) (y :: ys) := band (x = y) (list_iso xs ys)\n  | _         _         := ff\n\nlemma list_iso_refl {\u03b1 : Type*} [decidable_eq \u03b1] (l : list \u03b1) :\n  list_iso l l :=\nbegin\n  induction l; simp [list_iso], assumption\nend\n\nlemma list_iso_nil_l {\u03b1 : Type*} [decidable_eq \u03b1] (l : list \u03b1)\n  : list_iso nil l \u2194 l = nil :=\n  iff.intro\n    (\u03bbh, begin cases l with x xs, refl, simp [list_iso] at h, contradiction end)\n    (\u03bbh, begin cases l with x xs, exact list_iso_refl _, cases h end)\n\nlemma list_iso_nil_r {\u03b1 : Type*} [decidable_eq \u03b1] (l : list \u03b1)\n  : list_iso l nil \u2194 l = nil :=\n  iff.intro\n    (\u03bbh, begin cases l with x xs, refl, simp [list_iso] at h, contradiction end)\n    (\u03bbh, begin cases l with x xs, exact list_iso_refl _, cases h end)\n\nlemma list_iso_symm {\u03b1 : Type*} [decidable_eq \u03b1] {l\u2081 l\u2082 : list \u03b1}\n  (h : list_iso l\u2081 l\u2082) : list_iso l\u2082 l\u2081 :=\nbegin\n  induction l\u2081 with x xs generalizing l\u2082; cases l\u2082 with y ys; try {assumption},\n  simp [list_iso], simp [list_iso] at h,\n  cases h with h\u2081 h\u2082,\n  rw and_iff_left, exact eq.symm h\u2081,\n  apply l\u2081_ih, exact h\u2082\nend\n\nlemma list_iso_trans {\u03b1 : Type*} [decidable_eq \u03b1] {l\u2081 l\u2082 l\u2083 : list \u03b1}\n  (h : list_iso l\u2081 l\u2082) (h\u2081 : list_iso l\u2082 l\u2083) : list_iso l\u2081 l\u2083 :=\nbegin\n  induction l\u2081 with x xs ih generalizing l\u2082 l\u2083; cases l\u2083 with y ys,\n    {exact list_iso_refl _},\n    {\n      rw list_iso_nil_l at h, rw h at h\u2081,\n      rw list_iso_nil_l at h\u2081, cases h\u2081\n    },\n    {\n      rw list_iso_nil_r at h\u2081, rw h\u2081 at h,\n      exact h\n    },\n    {\n      simp [list_iso],\n      cases l\u2082 with z zs,\n        {\n          rw list_iso_nil_r at h, cases h\n        },\n        {\n          simp [list_iso] at h h\u2081,\n          cases h\u2081, cases h, split, cc,\n          apply ih, exact h_right, exact h\u2081_right\n        }\n    }\nend\n\nlemma list_iso_hd {\u03b1 : Type*} [decidable_eq \u03b1] {x} {y} {xs ys : list \u03b1}\n  (h : list_iso (x :: xs) (y :: ys)) : x = y :=\nbegin\n  simp [list_iso] at h,\n  exact h.left\nend\n\nlemma list_iso_tl {\u03b1 : Type*} [decidable_eq \u03b1] {x} {y} {xs ys : list \u03b1}\n  (h : list_iso (x :: xs) (y :: ys)) : list_iso xs ys :=\nbegin\n  simp [list_iso] at h,\n  exact h.right\nend\n\nlemma list_iso_iff {\u03b1 : Type*} [decidable_eq \u03b1] {l\u2081 l\u2082 : list \u03b1} :\n  list_iso l\u2081 l\u2082 \u2194 l\u2081 = l\u2082 :=\nbegin\n  split; intros h,\n    {\n      induction l\u2081 with x xs ih generalizing l\u2082,\n        {\n          cases l\u2082 with y ys,\n            {refl},\n            {rw list_iso_nil_l at h, cases h}\n        },\n        {\n          cases l\u2082 with y ys, \n            {rw list_iso_nil_r at h, cases h},\n            {\n              have h\u2081 : x = y, from list_iso_hd h,\n              congr, exact h\u2081, apply ih,\n              apply list_iso_tl h\n            }\n        }\n    },\n    {\n      rw h, exact list_iso_refl _\n    }\nend\n\ndef mod_self {n : \u2115} : n % n = 0 :=\nbegin\n  induction n with n ih, refl,\n  rw nat.mod_def,\n  rw if_pos,\n  rw nat.sub_self,\n  rw nat.zero_mod,\n  split, rw succ_eq_add_one, rw add_comm,\n  exact zero_lt_one_add _, refl\nend\n\nlemma repeat_bounded {\u03b1 : Type*} {a : \u03b1} {b} :\n  \u2200{x}, x \u2208 list.repeat a b \u2192 x = a :=\nassume x h,\nbegin\n  induction b with b ih,\n    {\n      cases h\n    },\n    {\n      simp at h, cases h, assumption,\n      exact ih h\n    }\nend\n\nend utils", "meta": {"author": "Leangrids", "repo": "grids", "sha": "7ccc15b3051465c9cceedfbc57a3e06ddb1c8209", "save_path": "github-repos/lean/Leangrids-grids", "path": "github-repos/lean/Leangrids-grids/grids-7ccc15b3051465c9cceedfbc57a3e06ddb1c8209/utils.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8652240964782011, "lm_q1q2_score": 0.728367835035415}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.exp_log\nimport data.set.intervals.infinite\nimport algebra.quadratic_discriminant\nimport ring_theory.polynomial.chebyshev\nimport analysis.calculus.times_cont_diff\n\n/-!\n# Trigonometric functions\n\n## Main definitions\n\nThis file contains the following definitions:\n* \u03c0, arcsin, arccos, arctan\n* argument of a complex number\n* logarithm on complex numbers\n\n## Main statements\n\nMany basic inequalities on trigonometric functions are established.\n\nThe continuity and differentiability of the usual trigonometric functions are proved, and their\nderivatives are computed.\n\n* `polynomial.chebyshev.T_complex_cos`: the `n`-th Chebyshev polynomial evaluates on `complex.cos \u03b8`\n  to the value `n * complex.cos \u03b8`.\n\n## Tags\n\nlog, sin, cos, tan, arcsin, arccos, arctan, angle, argument\n-/\n\nnoncomputable theory\nopen_locale classical topological_space filter\nopen set filter\n\nnamespace complex\n\n/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/\nlemma has_strict_deriv_at_sin (x : \u2102) : has_strict_deriv_at sin (cos x) x :=\nbegin\n  simp only [cos, div_eq_mul_inv],\n  convert ((((has_strict_deriv_at_id x).neg.mul_const I).cexp.sub\n    ((has_strict_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:\u2102)\u207b\u00b9,\n  simp only [function.comp, id],\n  rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,\n      I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]\nend\n\n/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/\nlemma has_deriv_at_sin (x : \u2102) : has_deriv_at sin (cos x) x :=\n(has_strict_deriv_at_sin x).has_deriv_at\n\nlemma times_cont_diff_sin {n} : times_cont_diff \u2102 n sin :=\n(((times_cont_diff_neg.mul times_cont_diff_const).cexp.sub\n  (times_cont_diff_id.mul times_cont_diff_const).cexp).mul times_cont_diff_const).div_const\n\nlemma differentiable_sin : differentiable \u2102 sin :=\n\u03bbx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin {x : \u2102} : differentiable_at \u2102 sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ \u03bb x, (has_deriv_at_sin x).deriv\n\n@[continuity]\nlemma continuous_sin : continuous sin :=\ndifferentiable_sin.continuous\n\nlemma continuous_on_sin {s : set \u2102} : continuous_on sin s := continuous_sin.continuous_on\n\nlemma measurable_sin : measurable sin := continuous_sin.measurable\n\n/-- The complex cosine function is everywhere strictly differentiable, with the derivative\n`-sin x`. -/\nlemma has_strict_deriv_at_cos (x : \u2102) : has_strict_deriv_at cos (-sin x) x :=\nbegin\n  simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],\n  convert (((has_strict_deriv_at_id x).mul_const I).cexp.add\n    ((has_strict_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:\u2102)\u207b\u00b9,\n  simp only [function.comp, id],\n  ring\nend\n\n/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/\nlemma has_deriv_at_cos (x : \u2102) : has_deriv_at cos (-sin x) x :=\n(has_strict_deriv_at_cos x).has_deriv_at\n\nlemma times_cont_diff_cos {n} : times_cont_diff \u2102 n cos :=\n((times_cont_diff_id.mul times_cont_diff_const).cexp.add\n  (times_cont_diff_neg.mul times_cont_diff_const).cexp).div_const\n\nlemma differentiable_cos : differentiable \u2102 cos :=\n\u03bbx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos {x : \u2102} : differentiable_at \u2102 cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos {x : \u2102} : deriv cos x = -sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (\u03bb x, -sin x) :=\nfunext $ \u03bb x, deriv_cos\n\n@[continuity]\nlemma continuous_cos : continuous cos :=\ndifferentiable_cos.continuous\n\nlemma continuous_on_cos {s : set \u2102} : continuous_on cos s := continuous_cos.continuous_on\n\nlemma measurable_cos : measurable cos := continuous_cos.measurable\n\n/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative\n`cosh x`. -/\nlemma has_strict_deriv_at_sinh (x : \u2102) : has_strict_deriv_at sinh (cosh x) x :=\nbegin\n  simp only [cosh, div_eq_mul_inv],\n  convert ((has_strict_deriv_at_exp x).sub (has_strict_deriv_at_id x).neg.cexp).mul_const (2:\u2102)\u207b\u00b9,\n  rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]\nend\n\n/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative\n`cosh x`. -/\nlemma has_deriv_at_sinh (x : \u2102) : has_deriv_at sinh (cosh x) x :=\n(has_strict_deriv_at_sinh x).has_deriv_at\n\nlemma times_cont_diff_sinh {n} : times_cont_diff \u2102 n sinh :=\n(times_cont_diff_exp.sub times_cont_diff_neg.cexp).div_const\n\nlemma differentiable_sinh : differentiable \u2102 sinh :=\n\u03bbx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh {x : \u2102} : differentiable_at \u2102 sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ \u03bb x, (has_deriv_at_sinh x).deriv\n\n@[continuity]\nlemma continuous_sinh : continuous sinh :=\ndifferentiable_sinh.continuous\n\nlemma measurable_sinh : measurable sinh := continuous_sinh.measurable\n\n/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the\nderivative `sinh x`. -/\nlemma has_strict_deriv_at_cosh (x : \u2102) : has_strict_deriv_at cosh (sinh x) x :=\nbegin\n  simp only [sinh, div_eq_mul_inv],\n  convert ((has_strict_deriv_at_exp x).add (has_strict_deriv_at_id x).neg.cexp).mul_const (2:\u2102)\u207b\u00b9,\n  rw [id, mul_neg_one, sub_eq_add_neg]\nend\n\n/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative\n`sinh x`. -/\nlemma has_deriv_at_cosh (x : \u2102) : has_deriv_at cosh (sinh x) x :=\n(has_strict_deriv_at_cosh x).has_deriv_at\n\nlemma times_cont_diff_cosh {n} : times_cont_diff \u2102 n cosh :=\n(times_cont_diff_exp.add times_cont_diff_neg.cexp).div_const\n\nlemma differentiable_cosh : differentiable \u2102 cosh :=\n\u03bbx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh {x : \u2102} : differentiable_at \u2102 cos x :=\ndifferentiable_cos x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ \u03bb x, (has_deriv_at_cosh x).deriv\n\n@[continuity]\nlemma continuous_cosh : continuous cosh :=\ndifferentiable_cosh.continuous\n\nlemma measurable_cosh : measurable cosh := continuous_cosh.measurable\n\nend complex\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, complex.cos (f x)` etc., `f : \u2102 \u2192 \u2102` -/\n\nvariables {f : \u2102 \u2192 \u2102} {f' x : \u2102} {s : set \u2102}\n\n/-! #### `complex.cos` -/\n\nlemma measurable.ccos {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u2102} (hf : measurable f) :\n  measurable (\u03bb x, complex.cos (f x)) :=\ncomplex.measurable_cos.comp hf\n\nlemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') x :=\n(complex.has_strict_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') x :=\n(complex.has_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=\n(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_ccos (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.ccos.deriv_within hxs\n\n@[simp] lemma deriv_ccos (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=\nhc.has_deriv_at.ccos.deriv\n\n/-! #### `complex.sin` -/\n\nlemma measurable.csin {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u2102} (hf : measurable f) :\n  measurable (\u03bb x, complex.sin (f x)) :=\ncomplex.measurable_sin.comp hf\n\nlemma has_strict_deriv_at.csin (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') x :=\n(complex.has_strict_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_at.csin (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') x :=\n(complex.has_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) * f') s x :=\n(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_csin (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.csin.deriv_within hxs\n\n@[simp] lemma deriv_csin (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=\nhc.has_deriv_at.csin.deriv\n\n/-! #### `complex.cosh` -/\n\nlemma measurable.ccosh {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u2102} (hf : measurable f) :\n  measurable (\u03bb x, complex.cosh (f x)) :=\ncomplex.measurable_cosh.comp hf\n\nlemma has_strict_deriv_at.ccosh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=\n(complex.has_strict_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=\n(complex.has_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_ccosh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.ccosh.deriv_within hxs\n\n@[simp] lemma deriv_ccosh (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=\nhc.has_deriv_at.ccosh.deriv\n\n/-! #### `complex.sinh` -/\n\nlemma measurable.csinh {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u2102} (hf : measurable f) :\n  measurable (\u03bb x, complex.sinh (f x)) :=\ncomplex.measurable_sinh.comp hf\n\nlemma has_strict_deriv_at.csinh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=\n(complex.has_strict_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=\n(complex.has_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_csinh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  deriv_within (\u03bbx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.csinh.deriv_within hxs\n\n@[simp] lemma deriv_csinh (hc : differentiable_at \u2102 f x) :\n  deriv (\u03bbx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=\nhc.has_deriv_at.csinh.deriv\n\nend\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, complex.cos (f x)` etc., `f : E \u2192 \u2102` -/\n\nvariables {E : Type*} [normed_group E] [normed_space \u2102 E] {f : E \u2192 \u2102} {f' : E \u2192L[\u2102] \u2102}\n  {x : E} {s : set E}\n\n/-! #### `complex.cos` -/\n\nlemma has_strict_fderiv_at.ccos (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') x :=\n(complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.cos (f x)) (- complex.sin (f x) \u2022 f') s x :=\n(complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.ccos (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.cos (f x)) s x :=\nhf.has_fderiv_within_at.ccos.differentiable_within_at\n\n@[simp] lemma differentiable_at.ccos (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.cos (f x)) x :=\nhc.has_fderiv_at.ccos.differentiable_at\n\nlemma differentiable_on.ccos (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.cos (f x)) s :=\n\u03bbx h, (hc x h).ccos\n\n@[simp] lemma differentiable.ccos (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.cos (f x)) :=\n\u03bbx, (hc x).ccos\n\nlemma fderiv_within_ccos (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.cos (f x)) s x = - complex.sin (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.ccos.fderiv_within hxs\n\n@[simp] lemma fderiv_ccos (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.cos (f x)) x = - complex.sin (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.ccos.fderiv\n\nlemma times_cont_diff.ccos {n} (h : times_cont_diff \u2102 n f) :\n  times_cont_diff \u2102 n (\u03bb x, complex.cos (f x)) :=\ncomplex.times_cont_diff_cos.comp h\n\nlemma times_cont_diff_at.ccos {n} (hf : times_cont_diff_at \u2102 n f x) :\n  times_cont_diff_at \u2102 n (\u03bb x, complex.cos (f x)) x :=\ncomplex.times_cont_diff_cos.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.ccos {n} (hf : times_cont_diff_on \u2102 n f s) :\n  times_cont_diff_on \u2102 n (\u03bb x, complex.cos (f x)) s :=\ncomplex.times_cont_diff_cos.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.ccos {n} (hf : times_cont_diff_within_at \u2102 n f s x) :\n  times_cont_diff_within_at \u2102 n (\u03bb x, complex.cos (f x)) s x :=\ncomplex.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\n/-! #### `complex.sin` -/\n\nlemma has_strict_fderiv_at.csin (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') x :=\n(complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.sin (f x)) (complex.cos (f x) \u2022 f') s x :=\n(complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.csin (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.sin (f x)) s x :=\nhf.has_fderiv_within_at.csin.differentiable_within_at\n\n@[simp] lemma differentiable_at.csin (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.sin (f x)) x :=\nhc.has_fderiv_at.csin.differentiable_at\n\nlemma differentiable_on.csin (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.sin (f x)) s :=\n\u03bbx h, (hc x h).csin\n\n@[simp] lemma differentiable.csin (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.sin (f x)) :=\n\u03bbx, (hc x).csin\n\nlemma fderiv_within_csin (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.sin (f x)) s x = complex.cos (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.csin.fderiv_within hxs\n\n@[simp] lemma fderiv_csin (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.sin (f x)) x = complex.cos (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.csin.fderiv\n\nlemma times_cont_diff.csin {n} (h : times_cont_diff \u2102 n f) :\n  times_cont_diff \u2102 n (\u03bb x, complex.sin (f x)) :=\ncomplex.times_cont_diff_sin.comp h\n\nlemma times_cont_diff_at.csin {n} (hf : times_cont_diff_at \u2102 n f x) :\n  times_cont_diff_at \u2102 n (\u03bb x, complex.sin (f x)) x :=\ncomplex.times_cont_diff_sin.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.csin {n} (hf : times_cont_diff_on \u2102 n f s) :\n  times_cont_diff_on \u2102 n (\u03bb x, complex.sin (f x)) s :=\ncomplex.times_cont_diff_sin.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.csin {n} (hf : times_cont_diff_within_at \u2102 n f s x) :\n  times_cont_diff_within_at \u2102 n (\u03bb x, complex.sin (f x)) s x :=\ncomplex.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\n/-! #### `complex.cosh` -/\n\nlemma has_strict_fderiv_at.ccosh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.cosh (f x)) (complex.sinh (f x) \u2022 f') s x :=\n(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.ccosh (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.cosh (f x)) s x :=\nhf.has_fderiv_within_at.ccosh.differentiable_within_at\n\n@[simp] lemma differentiable_at.ccosh (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.cosh (f x)) x :=\nhc.has_fderiv_at.ccosh.differentiable_at\n\nlemma differentiable_on.ccosh (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.cosh (f x)) s :=\n\u03bbx h, (hc x h).ccosh\n\n@[simp] lemma differentiable.ccosh (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.cosh (f x)) :=\n\u03bbx, (hc x).ccosh\n\nlemma fderiv_within_ccosh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.cosh (f x)) s x = complex.sinh (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.ccosh.fderiv_within hxs\n\n@[simp] lemma fderiv_ccosh (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.cosh (f x)) x = complex.sinh (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.ccosh.fderiv\n\nlemma times_cont_diff.ccosh {n} (h : times_cont_diff \u2102 n f) :\n  times_cont_diff \u2102 n (\u03bb x, complex.cosh (f x)) :=\ncomplex.times_cont_diff_cosh.comp h\n\nlemma times_cont_diff_at.ccosh {n} (hf : times_cont_diff_at \u2102 n f x) :\n  times_cont_diff_at \u2102 n (\u03bb x, complex.cosh (f x)) x :=\ncomplex.times_cont_diff_cosh.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.ccosh {n} (hf : times_cont_diff_on \u2102 n f s) :\n  times_cont_diff_on \u2102 n (\u03bb x, complex.cosh (f x)) s :=\ncomplex.times_cont_diff_cosh.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.ccosh {n} (hf : times_cont_diff_within_at \u2102 n f s x) :\n  times_cont_diff_within_at \u2102 n (\u03bb x, complex.cosh (f x)) s x :=\ncomplex.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\n/-! #### `complex.sinh` -/\n\nlemma has_strict_fderiv_at.csinh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') x :=\n(complex.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, complex.sinh (f x)) (complex.cosh (f x) \u2022 f') s x :=\n(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.csinh (hf : differentiable_within_at \u2102 f s x) :\n  differentiable_within_at \u2102 (\u03bb x, complex.sinh (f x)) s x :=\nhf.has_fderiv_within_at.csinh.differentiable_within_at\n\n@[simp] lemma differentiable_at.csinh (hc : differentiable_at \u2102 f x) :\n  differentiable_at \u2102 (\u03bbx, complex.sinh (f x)) x :=\nhc.has_fderiv_at.csinh.differentiable_at\n\nlemma differentiable_on.csinh (hc : differentiable_on \u2102 f s) :\n  differentiable_on \u2102 (\u03bbx, complex.sinh (f x)) s :=\n\u03bbx h, (hc x h).csinh\n\n@[simp] lemma differentiable.csinh (hc : differentiable \u2102 f) :\n  differentiable \u2102 (\u03bbx, complex.sinh (f x)) :=\n\u03bbx, (hc x).csinh\n\nlemma fderiv_within_csinh (hf : differentiable_within_at \u2102 f s x)\n  (hxs : unique_diff_within_at \u2102 s x) :\n  fderiv_within \u2102 (\u03bbx, complex.sinh (f x)) s x = complex.cosh (f x) \u2022 (fderiv_within \u2102 f s x) :=\nhf.has_fderiv_within_at.csinh.fderiv_within hxs\n\n@[simp] lemma fderiv_csinh (hc : differentiable_at \u2102 f x) :\n  fderiv \u2102 (\u03bbx, complex.sinh (f x)) x = complex.cosh (f x) \u2022 (fderiv \u2102 f x) :=\nhc.has_fderiv_at.csinh.fderiv\n\nlemma times_cont_diff.csinh {n} (h : times_cont_diff \u2102 n f) :\n  times_cont_diff \u2102 n (\u03bb x, complex.sinh (f x)) :=\ncomplex.times_cont_diff_sinh.comp h\n\nlemma times_cont_diff_at.csinh {n} (hf : times_cont_diff_at \u2102 n f x) :\n  times_cont_diff_at \u2102 n (\u03bb x, complex.sinh (f x)) x :=\ncomplex.times_cont_diff_sinh.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.csinh {n} (hf : times_cont_diff_on \u2102 n f s) :\n  times_cont_diff_on \u2102 n (\u03bb x, complex.sinh (f x)) s :=\ncomplex.times_cont_diff_sinh.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.csinh {n} (hf : times_cont_diff_within_at \u2102 n f s x) :\n  times_cont_diff_within_at \u2102 n (\u03bb x, complex.sinh (f x)) s x :=\ncomplex.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\nend\n\nnamespace real\n\nvariables {x y z : \u211d}\n\nlemma has_strict_deriv_at_sin (x : \u211d) : has_strict_deriv_at sin (cos x) x :=\n(complex.has_strict_deriv_at_sin x).real_of_complex\n\nlemma has_deriv_at_sin (x : \u211d) : has_deriv_at sin (cos x) x :=\n(has_strict_deriv_at_sin x).has_deriv_at\n\nlemma times_cont_diff_sin {n} : times_cont_diff \u211d n sin :=\ncomplex.times_cont_diff_sin.real_of_complex\n\nlemma differentiable_sin : differentiable \u211d sin :=\n\u03bbx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin : differentiable_at \u211d sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ \u03bb x, (has_deriv_at_sin x).deriv\n\n@[continuity]\nlemma continuous_sin : continuous sin :=\ndifferentiable_sin.continuous\n\nlemma continuous_on_sin {s} : continuous_on sin s :=\ncontinuous_sin.continuous_on\n\nlemma measurable_sin : measurable sin := continuous_sin.measurable\n\nlemma has_strict_deriv_at_cos (x : \u211d) : has_strict_deriv_at cos (-sin x) x :=\n(complex.has_strict_deriv_at_cos x).real_of_complex\n\nlemma has_deriv_at_cos (x : \u211d) : has_deriv_at cos (-sin x) x :=\n(complex.has_deriv_at_cos x).real_of_complex\n\nlemma times_cont_diff_cos {n} : times_cont_diff \u211d n cos :=\ncomplex.times_cont_diff_cos.real_of_complex\n\nlemma differentiable_cos : differentiable \u211d cos :=\n\u03bbx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos : differentiable_at \u211d cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos : deriv cos x = - sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (\u03bb x, - sin x) :=\nfunext $ \u03bb _, deriv_cos\n\n@[continuity]\nlemma continuous_cos : continuous cos :=\ndifferentiable_cos.continuous\n\nlemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on\n\nlemma measurable_cos : measurable cos := continuous_cos.measurable\n\nlemma has_strict_deriv_at_sinh (x : \u211d) : has_strict_deriv_at sinh (cosh x) x :=\n(complex.has_strict_deriv_at_sinh x).real_of_complex\n\nlemma has_deriv_at_sinh (x : \u211d) : has_deriv_at sinh (cosh x) x :=\n(complex.has_deriv_at_sinh x).real_of_complex\n\nlemma times_cont_diff_sinh {n} : times_cont_diff \u211d n sinh :=\ncomplex.times_cont_diff_sinh.real_of_complex\n\nlemma differentiable_sinh : differentiable \u211d sinh :=\n\u03bbx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh : differentiable_at \u211d sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ \u03bb x, (has_deriv_at_sinh x).deriv\n\n@[continuity]\nlemma continuous_sinh : continuous sinh :=\ndifferentiable_sinh.continuous\n\nlemma measurable_sinh : measurable sinh := continuous_sinh.measurable\n\nlemma has_strict_deriv_at_cosh (x : \u211d) : has_strict_deriv_at cosh (sinh x) x :=\n(complex.has_strict_deriv_at_cosh x).real_of_complex\n\nlemma has_deriv_at_cosh (x : \u211d) : has_deriv_at cosh (sinh x) x :=\n(complex.has_deriv_at_cosh x).real_of_complex\n\nlemma times_cont_diff_cosh {n} : times_cont_diff \u211d n cosh :=\ncomplex.times_cont_diff_cosh.real_of_complex\n\nlemma differentiable_cosh : differentiable \u211d cosh :=\n\u03bbx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh : differentiable_at \u211d cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ \u03bb x, (has_deriv_at_cosh x).deriv\n\n@[continuity]\nlemma continuous_cosh : continuous cosh :=\ndifferentiable_cosh.continuous\n\nlemma measurable_cosh : measurable cosh := continuous_cosh.measurable\n\n/-- `sinh` is strictly monotone. -/\nlemma sinh_strict_mono : strict_mono sinh :=\nstrict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos })\n\nend real\n\nsection\n/-! ### Simp lemmas for derivatives of `\u03bb x, real.cos (f x)` etc., `f : \u211d \u2192 \u211d` -/\n\nvariables {f : \u211d \u2192 \u211d} {f' x : \u211d} {s : set \u211d}\n\n/-! #### `real.cos` -/\n\nlemma measurable.cos {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d}  (hf : measurable f) :\n  measurable (\u03bb x, real.cos (f x)) :=\nreal.measurable_cos.comp hf\n\nlemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') x :=\n(real.has_strict_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_at.cos (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') x :=\n(real.has_deriv_at_cos (f x)).comp x hf\n\nlemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.cos (f x)) (- real.sin (f x) * f') s x :=\n(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_cos (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.cos.deriv_within hxs\n\n@[simp] lemma deriv_cos (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=\nhc.has_deriv_at.cos.deriv\n\n/-! #### `real.sin` -/\n\nlemma measurable.sin {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d}  (hf : measurable f) :\n  measurable (\u03bb x, real.sin (f x)) :=\nreal.measurable_sin.comp hf\n\nlemma has_strict_deriv_at.sin (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') x :=\n(real.has_strict_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_at.sin (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') x :=\n(real.has_deriv_at_sin (f x)).comp x hf\n\nlemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.sin (f x)) (real.cos (f x) * f') s x :=\n(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_sin (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.sin.deriv_within hxs\n\n@[simp] lemma deriv_sin (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=\nhc.has_deriv_at.sin.deriv\n\n/-! #### `real.cosh` -/\n\nlemma measurable.cosh {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d}  (hf : measurable f) :\n  measurable (\u03bb x, real.cosh (f x)) :=\nreal.measurable_cosh.comp hf\n\nlemma has_strict_deriv_at.cosh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') x :=\n(real.has_strict_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') x :=\n(real.has_deriv_at_cosh (f x)).comp x hf\n\nlemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) * f') s x :=\n(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_cosh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.cosh.deriv_within hxs\n\n@[simp] lemma deriv_cosh (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=\nhc.has_deriv_at.cosh.deriv\n\n/-! #### `real.sinh` -/\n\nlemma measurable.sinh {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d}  (hf : measurable f) :\n  measurable (\u03bb x, real.sinh (f x)) :=\nreal.measurable_sinh.comp hf\n\nlemma has_strict_deriv_at.sinh (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') x :=\n(real.has_strict_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') x :=\n(real.has_deriv_at_sinh (f x)).comp x hf\n\nlemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) * f') s x :=\n(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_sinh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bbx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=\nhf.has_deriv_within_at.sinh.deriv_within hxs\n\n@[simp] lemma deriv_sinh (hc : differentiable_at \u211d f x) :\n  deriv (\u03bbx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=\nhc.has_deriv_at.sinh.deriv\n\nend\n\nsection\n\n/-! ### Simp lemmas for derivatives of `\u03bb x, real.cos (f x)` etc., `f : E \u2192 \u211d` -/\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E] {f : E \u2192 \u211d} {f' : E \u2192L[\u211d] \u211d}\n  {x : E} {s : set E}\n\n/-! #### `real.cos` -/\n\nlemma has_strict_fderiv_at.cos (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') x :=\n(real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.cos (f x)) (- real.sin (f x) \u2022 f') s x :=\n(real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.cos (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.cos (f x)) s x :=\nhf.has_fderiv_within_at.cos.differentiable_within_at\n\n@[simp] lemma differentiable_at.cos (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.cos (f x)) x :=\nhc.has_fderiv_at.cos.differentiable_at\n\nlemma differentiable_on.cos (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.cos (f x)) s :=\n\u03bbx h, (hc x h).cos\n\n@[simp] lemma differentiable.cos (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.cos (f x)) :=\n\u03bbx, (hc x).cos\n\nlemma fderiv_within_cos (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.cos (f x)) s x = - real.sin (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.cos.fderiv_within hxs\n\n@[simp] lemma fderiv_cos (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.cos (f x)) x = - real.sin (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.cos.fderiv\n\nlemma times_cont_diff.cos {n} (h : times_cont_diff \u211d n f) :\n  times_cont_diff \u211d n (\u03bb x, real.cos (f x)) :=\nreal.times_cont_diff_cos.comp h\n\nlemma times_cont_diff_at.cos {n} (hf : times_cont_diff_at \u211d n f x) :\n  times_cont_diff_at \u211d n (\u03bb x, real.cos (f x)) x :=\nreal.times_cont_diff_cos.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.cos {n} (hf : times_cont_diff_on \u211d n f s) :\n  times_cont_diff_on \u211d n (\u03bb x, real.cos (f x)) s :=\nreal.times_cont_diff_cos.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.cos {n} (hf : times_cont_diff_within_at \u211d n f s x) :\n  times_cont_diff_within_at \u211d n (\u03bb x, real.cos (f x)) s x :=\nreal.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\n/-! #### `real.sin` -/\n\nlemma has_strict_fderiv_at.sin (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') x :=\n(real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.sin (f x)) (real.cos (f x) \u2022 f') s x :=\n(real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.sin (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.sin (f x)) s x :=\nhf.has_fderiv_within_at.sin.differentiable_within_at\n\n@[simp] lemma differentiable_at.sin (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.sin (f x)) x :=\nhc.has_fderiv_at.sin.differentiable_at\n\nlemma differentiable_on.sin (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.sin (f x)) s :=\n\u03bbx h, (hc x h).sin\n\n@[simp] lemma differentiable.sin (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.sin (f x)) :=\n\u03bbx, (hc x).sin\n\nlemma fderiv_within_sin (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.sin (f x)) s x = real.cos (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.sin.fderiv_within hxs\n\n@[simp] lemma fderiv_sin (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.sin (f x)) x = real.cos (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.sin.fderiv\n\nlemma times_cont_diff.sin {n} (h : times_cont_diff \u211d n f) :\n  times_cont_diff \u211d n (\u03bb x, real.sin (f x)) :=\nreal.times_cont_diff_sin.comp h\n\nlemma times_cont_diff_at.sin {n} (hf : times_cont_diff_at \u211d n f x) :\n  times_cont_diff_at \u211d n (\u03bb x, real.sin (f x)) x :=\nreal.times_cont_diff_sin.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.sin {n} (hf : times_cont_diff_on \u211d n f s) :\n  times_cont_diff_on \u211d n (\u03bb x, real.sin (f x)) s :=\nreal.times_cont_diff_sin.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.sin {n} (hf : times_cont_diff_within_at \u211d n f s x) :\n  times_cont_diff_within_at \u211d n (\u03bb x, real.sin (f x)) s x :=\nreal.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\n/-! #### `real.cosh` -/\n\nlemma has_strict_fderiv_at.cosh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') x :=\n(real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.cosh (f x)) (real.sinh (f x) \u2022 f') s x :=\n(real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.cosh (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.cosh (f x)) s x :=\nhf.has_fderiv_within_at.cosh.differentiable_within_at\n\n@[simp] lemma differentiable_at.cosh (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.cosh (f x)) x :=\nhc.has_fderiv_at.cosh.differentiable_at\n\nlemma differentiable_on.cosh (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.cosh (f x)) s :=\n\u03bbx h, (hc x h).cosh\n\n@[simp] lemma differentiable.cosh (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.cosh (f x)) :=\n\u03bbx, (hc x).cosh\n\nlemma fderiv_within_cosh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.cosh (f x)) s x = real.sinh (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.cosh.fderiv_within hxs\n\n@[simp] lemma fderiv_cosh (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.cosh (f x)) x = real.sinh (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.cosh.fderiv\n\nlemma times_cont_diff.cosh {n} (h : times_cont_diff \u211d n f) :\n  times_cont_diff \u211d n (\u03bb x, real.cosh (f x)) :=\nreal.times_cont_diff_cosh.comp h\n\nlemma times_cont_diff_at.cosh {n} (hf : times_cont_diff_at \u211d n f x) :\n  times_cont_diff_at \u211d n (\u03bb x, real.cosh (f x)) x :=\nreal.times_cont_diff_cosh.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.cosh {n} (hf : times_cont_diff_on \u211d n f s) :\n  times_cont_diff_on \u211d n (\u03bb x, real.cosh (f x)) s :=\nreal.times_cont_diff_cosh.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.cosh {n} (hf : times_cont_diff_within_at \u211d n f s x) :\n  times_cont_diff_within_at \u211d n (\u03bb x, real.cosh (f x)) s x :=\nreal.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\n/-! #### `real.sinh` -/\n\nlemma has_strict_fderiv_at.sinh (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') x :=\n(real.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') x :=\n(real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, real.sinh (f x)) (real.cosh (f x) \u2022 f') s x :=\n(real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf\n\nlemma differentiable_within_at.sinh (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.sinh (f x)) s x :=\nhf.has_fderiv_within_at.sinh.differentiable_within_at\n\n@[simp] lemma differentiable_at.sinh (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bbx, real.sinh (f x)) x :=\nhc.has_fderiv_at.sinh.differentiable_at\n\nlemma differentiable_on.sinh (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bbx, real.sinh (f x)) s :=\n\u03bbx h, (hc x h).sinh\n\n@[simp] lemma differentiable.sinh (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bbx, real.sinh (f x)) :=\n\u03bbx, (hc x).sinh\n\nlemma fderiv_within_sinh (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bbx, real.sinh (f x)) s x = real.cosh (f x) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.sinh.fderiv_within hxs\n\n@[simp] lemma fderiv_sinh (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bbx, real.sinh (f x)) x = real.cosh (f x) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.sinh.fderiv\n\nlemma times_cont_diff.sinh {n} (h : times_cont_diff \u211d n f) :\n  times_cont_diff \u211d n (\u03bb x, real.sinh (f x)) :=\nreal.times_cont_diff_sinh.comp h\n\nlemma times_cont_diff_at.sinh {n} (hf : times_cont_diff_at \u211d n f x) :\n  times_cont_diff_at \u211d n (\u03bb x, real.sinh (f x)) x :=\nreal.times_cont_diff_sinh.times_cont_diff_at.comp x hf\n\nlemma times_cont_diff_on.sinh {n} (hf : times_cont_diff_on \u211d n f s) :\n  times_cont_diff_on \u211d n (\u03bb x, real.sinh (f x)) s :=\nreal.times_cont_diff_sinh.comp_times_cont_diff_on  hf\n\nlemma times_cont_diff_within_at.sinh {n} (hf : times_cont_diff_within_at \u211d n f s x) :\n  times_cont_diff_within_at \u211d n (\u03bb x, real.sinh (f x)) s x :=\nreal.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf\n\nend\n\nnamespace real\n\nlemma exists_cos_eq_zero : 0 \u2208 cos '' Icc (1:\u211d) 2 :=\nintermediate_value_Icc' (by norm_num) continuous_on_cos\n  \u27e8le_of_lt cos_two_neg, le_of_lt cos_one_pos\u27e9\n\n/-- The number \u03c0 = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from\nwhich one can derive all its properties. For explicit bounds on \u03c0, see `data.real.pi`. -/\nprotected noncomputable def pi : \u211d := 2 * classical.some exists_cos_eq_zero\n\nlocalized \"notation `\u03c0` := real.pi\" in real\n\n@[simp] lemma cos_pi_div_two : cos (\u03c0 / 2) = 0 :=\nby rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' \u211d _ _ _)];\n  exact (classical.some_spec exists_cos_eq_zero).2\n\nlemma one_le_pi_div_two : (1 : \u211d) \u2264 \u03c0 / 2 :=\nby rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' \u211d _ _ _)];\n  exact (classical.some_spec exists_cos_eq_zero).1.1\n\nlemma pi_div_two_le_two : \u03c0 / 2 \u2264 2 :=\nby rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' \u211d _ _ _)];\n  exact (classical.some_spec exists_cos_eq_zero).1.2\n\nlemma two_le_pi : (2 : \u211d) \u2264 \u03c0 :=\n(div_le_div_right (show (0 : \u211d) < 2, by norm_num)).1\n  (by rw div_self (@two_ne_zero' \u211d _ _ _); exact one_le_pi_div_two)\n\nlemma pi_le_four : \u03c0 \u2264 4 :=\n(div_le_div_right (show (0 : \u211d) < 2, by norm_num)).1\n  (calc \u03c0 / 2 \u2264 2 : pi_div_two_le_two\n    ... = 4 / 2 : by norm_num)\n\nlemma pi_pos : 0 < \u03c0 :=\nlt_of_lt_of_le (by norm_num) two_le_pi\n\nlemma pi_ne_zero : \u03c0 \u2260 0 :=\nne_of_gt pi_pos\n\nlemma pi_div_two_pos : 0 < \u03c0 / 2 :=\nhalf_pos pi_pos\n\nlemma two_pi_pos : 0 < 2 * \u03c0 :=\nby linarith [pi_pos]\n\nend real\n\nnamespace nnreal\nopen real\nopen_locale real nnreal\n\n/-- `\u03c0` considered as a nonnegative real. -/\nnoncomputable def pi : \u211d\u22650 := \u27e8\u03c0, real.pi_pos.le\u27e9\n\n@[simp] lemma coe_real_pi : (pi : \u211d) = \u03c0 := rfl\n\nlemma pi_pos : 0 < pi := by exact_mod_cast real.pi_pos\n\nlemma pi_ne_zero : pi \u2260 0 := pi_pos.ne'\n\nend nnreal\n\nnamespace real\nopen_locale real\n\n@[simp] lemma sin_pi : sin \u03c0 = 0 :=\nby rw [\u2190 mul_div_cancel_left \u03c0 (@two_ne_zero \u211d _ _), two_mul, add_div,\n    sin_add, cos_pi_div_two]; simp\n\n@[simp] lemma cos_pi : cos \u03c0 = -1 :=\nby rw [\u2190 mul_div_cancel_left \u03c0 (@two_ne_zero \u211d _ _), mul_div_assoc,\n    cos_two_mul, cos_pi_div_two];\n  simp [bit0, pow_add]\n\n@[simp] lemma sin_two_pi : sin (2 * \u03c0) = 0 :=\nby simp [two_mul, sin_add]\n\n@[simp] lemma cos_two_pi : cos (2 * \u03c0) = 1 :=\nby simp [two_mul, cos_add]\n\nlemma sin_nat_mul_pi (n : \u2115) : sin (n * \u03c0) = 0 :=\nby induction n; simp [add_mul, sin_add, *]\n\nlemma sin_int_mul_pi (n : \u2124) : sin (n * \u03c0) = 0 :=\nby cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]\n\nlemma cos_nat_mul_two_pi (n : \u2115) : cos (n * (2 * \u03c0)) = 1 :=\nby induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]\n\nlemma cos_int_mul_two_pi (n : \u2124) : cos (n * (2 * \u03c0)) = 1 :=\nby cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe,\n                      int.cast_coe_nat, int.cast_neg, \u2190 neg_mul_eq_neg_mul, cos_neg]\n\nlemma sin_add_pi (x : \u211d) : sin (x + \u03c0) = -sin x :=\nby simp [sin_add]\n\nlemma sin_add_int_mul_two_pi (x : \u211d) (n : \u2124) : sin (x + n * (2 * \u03c0)) = sin x :=\nbegin\n  rw [sin_add, cos_int_mul_two_pi, \u2190 mul_assoc],\n  rw_mod_cast sin_int_mul_pi (n*2),\n  simp,\nend\n\nlemma sin_sub_int_mul_two_pi (x : \u211d) (n : \u2124) : sin (x - n * (2 * \u03c0)) = sin x :=\nby simpa using sin_add_int_mul_two_pi x (-n)\n\nlemma sin_add_nat_mul_two_pi (x : \u211d) (n : \u2115) : sin (x + n * (2 * \u03c0)) = sin x :=\nby convert sin_add_int_mul_two_pi x n\n\nlemma sin_sub_nat_mul_two_pi (x : \u211d) (n : \u2115) : sin (x - n * (2 * \u03c0)) = sin x :=\nby convert sin_sub_int_mul_two_pi x n\n\nlemma sin_add_two_pi (x : \u211d) : sin (x + 2 * \u03c0) = sin x :=\nby simp [sin_add]\n\nlemma sin_sub_two_pi (x : \u211d) : sin (x - 2 * \u03c0) = sin x :=\nby simp [sin_sub]\n\nlemma cos_add_int_mul_two_pi (x : \u211d) (n : \u2124) : cos (x + n * (2 * \u03c0)) = cos x :=\nbegin\n  rw [cos_add, cos_int_mul_two_pi, \u2190 mul_assoc],\n  rw_mod_cast sin_int_mul_pi (n*2),\n  simp,\nend\n\nlemma cos_sub_int_mul_two_pi (x : \u211d) (n : \u2124) : cos (x - n * (2 * \u03c0)) = cos x :=\nby simpa using cos_add_int_mul_two_pi x (-n)\n\nlemma cos_add_nat_mul_two_pi (x : \u211d) (n : \u2115) : cos (x + n * (2 * \u03c0)) = cos x :=\nby convert cos_add_int_mul_two_pi x n\n\nlemma cos_sub_nat_mul_two_pi (x : \u211d) (n : \u2115) : cos (x - n * (2 * \u03c0)) = cos x :=\nby convert cos_sub_int_mul_two_pi x n\n\nlemma cos_int_mul_two_pi_add_pi (n : \u2124) : cos (n * (2 * \u03c0) + \u03c0) = -1 :=\nby simp [add_comm, cos_add_int_mul_two_pi]\n\nlemma cos_int_mul_two_pi_sub_pi (n : \u2124) : cos (n * (2 * \u03c0) - \u03c0) = -1 :=\nby simp [sub_eq_neg_add, cos_add_int_mul_two_pi]\n\nlemma cos_nat_mul_two_pi_add_pi (n : \u2115) : cos (n * (2 * \u03c0) + \u03c0) = -1 :=\nby convert cos_int_mul_two_pi_add_pi n\n\nlemma cos_nat_mul_two_pi_sub_pi (n : \u2115) : cos (n * (2 * \u03c0) - \u03c0) = -1 :=\nby convert cos_int_mul_two_pi_sub_pi n\n\nlemma cos_add_two_pi (x : \u211d) : cos (x + 2 * \u03c0) = cos x :=\nby simp [cos_add]\n\nlemma cos_sub_two_pi (x : \u211d) : cos (x - 2 * \u03c0) = cos x :=\nby simp [cos_sub]\n\nlemma sin_pi_sub (x : \u211d) : sin (\u03c0 - x) = sin x :=\nby simp [sub_eq_add_neg, sin_add]\n\nlemma cos_add_pi (x : \u211d) : cos (x + \u03c0) = -cos x :=\nby simp [cos_add]\n\nlemma cos_sub_pi (x : \u211d) : cos (x - \u03c0) = -cos x :=\nby simp [cos_sub]\n\nlemma cos_pi_sub (x : \u211d) : cos (\u03c0 - x) = -cos x :=\nby simp [cos_sub]\n\nlemma sin_pos_of_pos_of_lt_pi {x : \u211d} (h0x : 0 < x) (hxp : x < \u03c0) : 0 < sin x :=\nif hx2 : x \u2264 2 then sin_pos_of_pos_of_le_two h0x hx2\nelse\n  have (2 : \u211d) + 2 = 4, from rfl,\n  have \u03c0 - x \u2264 2, from sub_le_iff_le_add.2\n    (le_trans pi_le_four (this \u25b8 add_le_add_left (le_of_not_ge hx2) _)),\n  sin_pi_sub x \u25b8 sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this\n\nlemma sin_pos_of_mem_Ioo {x : \u211d} (hx : x \u2208 Ioo 0 \u03c0) : 0 < sin x :=\nsin_pos_of_pos_of_lt_pi hx.1 hx.2\n\nlemma sin_nonneg_of_mem_Icc {x : \u211d} (hx : x \u2208 Icc 0 \u03c0) : 0 \u2264 sin x :=\nbegin\n  rw \u2190 closure_Ioo pi_pos at hx,\n  exact closure_lt_subset_le continuous_const continuous_sin\n    (closure_mono (\u03bb y, sin_pos_of_mem_Ioo) hx)\nend\n\nlemma sin_nonneg_of_nonneg_of_le_pi {x : \u211d} (h0x : 0 \u2264 x) (hxp : x \u2264 \u03c0) : 0 \u2264 sin x :=\nsin_nonneg_of_mem_Icc \u27e8h0x, hxp\u27e9\n\nlemma sin_neg_of_neg_of_neg_pi_lt {x : \u211d} (hx0 : x < 0) (hpx : -\u03c0 < x) : sin x < 0 :=\nneg_pos.1 $ sin_neg x \u25b8 sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)\n\nlemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : \u211d} (hx0 : x \u2264 0) (hpx : -\u03c0 \u2264 x) : sin x \u2264 0 :=\nneg_nonneg.1 $ sin_neg x \u25b8 sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)\n\n@[simp] lemma sin_pi_div_two : sin (\u03c0 / 2) = 1 :=\nhave sin (\u03c0 / 2) = 1 \u2228 sin (\u03c0 / 2) = -1 :=\nby simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (\u03c0 / 2),\nthis.resolve_right\n  (\u03bb h, (show \u00ac(0 : \u211d) < -1, by norm_num) $\n    h \u25b8 sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))\n\nlemma sin_add_pi_div_two (x : \u211d) : sin (x + \u03c0 / 2) = cos x :=\nby simp [sin_add]\n\nlemma sin_sub_pi_div_two (x : \u211d) : sin (x - \u03c0 / 2) = -cos x :=\nby simp [sub_eq_add_neg, sin_add]\n\nlemma sin_pi_div_two_sub (x : \u211d) : sin (\u03c0 / 2 - x) = cos x :=\nby simp [sub_eq_add_neg, sin_add]\n\nlemma cos_add_pi_div_two (x : \u211d) : cos (x + \u03c0 / 2) = -sin x :=\nby simp [cos_add]\n\nlemma cos_sub_pi_div_two (x : \u211d) : cos (x - \u03c0 / 2) = sin x :=\nby simp [sub_eq_add_neg, cos_add]\n\nlemma cos_pi_div_two_sub (x : \u211d) : cos (\u03c0 / 2 - x) = sin x :=\nby rw [\u2190 cos_neg, neg_sub, cos_sub_pi_div_two]\n\nlemma cos_pos_of_mem_Ioo {x : \u211d} (hx : x \u2208 Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) : 0 < cos x :=\nsin_add_pi_div_two x \u25b8 sin_pos_of_mem_Ioo \u27e8by linarith [hx.1], by linarith [hx.2]\u27e9\n\nlemma cos_nonneg_of_mem_Icc {x : \u211d} (hx : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) : 0 \u2264 cos x :=\nsin_add_pi_div_two x \u25b8 sin_nonneg_of_mem_Icc \u27e8by linarith [hx.1], by linarith [hx.2]\u27e9\n\nlemma cos_nonneg_of_neg_pi_div_two_le_of_le {x : \u211d} (hl : -(\u03c0 / 2) \u2264 x) (hu : x \u2264 \u03c0 / 2) :\n  0 \u2264 cos x :=\ncos_nonneg_of_mem_Icc \u27e8hl, hu\u27e9\n\nlemma cos_neg_of_pi_div_two_lt_of_lt {x : \u211d} (hx\u2081 : \u03c0 / 2 < x) (hx\u2082 : x < \u03c0 + \u03c0 / 2) : cos x < 0 :=\nneg_pos.1 $ cos_pi_sub x \u25b8 cos_pos_of_mem_Ioo \u27e8by linarith, by linarith\u27e9\n\nlemma cos_nonpos_of_pi_div_two_le_of_le {x : \u211d} (hx\u2081 : \u03c0 / 2 \u2264 x) (hx\u2082 : x \u2264 \u03c0 + \u03c0 / 2) :\n  cos x \u2264 0 :=\nneg_nonneg.1 $ cos_pi_sub x \u25b8 cos_nonneg_of_mem_Icc \u27e8by linarith, by linarith\u27e9\n\nlemma sin_eq_sqrt_one_sub_cos_sq {x : \u211d} (hl : 0 \u2264 x) (hu : x \u2264 \u03c0) :\n  sin x = sqrt (1 - cos x ^ 2) :=\nby rw [\u2190 abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]\n\nlemma cos_eq_sqrt_one_sub_sin_sq {x : \u211d} (hl : -(\u03c0 / 2) \u2264 x) (hu : x \u2264 \u03c0 / 2) :\n  cos x = sqrt (1 - sin x ^ 2) :=\nby rw [\u2190 abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc \u27e8hl, hu\u27e9)]\n\nlemma sin_eq_zero_iff_of_lt_of_lt {x : \u211d} (hx\u2081 : -\u03c0 < x) (hx\u2082 : x < \u03c0) :\n  sin x = 0 \u2194 x = 0 :=\n\u27e8\u03bb h, le_antisymm\n    (le_of_not_gt (\u03bb h0, lt_irrefl (0 : \u211d) $\n      calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx\u2082\n        ... = 0 : h))\n    (le_of_not_gt (\u03bb h0, lt_irrefl (0 : \u211d) $\n      calc 0 = sin x : h.symm\n        ... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx\u2081)),\n  \u03bb h, by simp [h]\u27e9\n\nlemma sin_eq_zero_iff {x : \u211d} : sin x = 0 \u2194 \u2203 n : \u2124, (n : \u211d) * \u03c0 = x :=\n\u27e8\u03bb h, \u27e8\u230ax / \u03c0\u230b, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos))\n  (sub_nonpos.1 $ le_of_not_gt $ \u03bb h\u2083,\n    (sin_pos_of_pos_of_lt_pi h\u2083 (sub_floor_div_mul_lt _ pi_pos)).ne\n    (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))\u27e9,\n  \u03bb \u27e8n, hn\u27e9, hn \u25b8 sin_int_mul_pi _\u27e9\n\nlemma sin_ne_zero_iff {x : \u211d} : sin x \u2260 0 \u2194 \u2200 n : \u2124, (n : \u211d) * \u03c0 \u2260 x :=\nby rw [\u2190 not_exists, not_iff_not, sin_eq_zero_iff]\n\nlemma sin_eq_zero_iff_cos_eq {x : \u211d} : sin x = 0 \u2194 cos x = 1 \u2228 cos x = -1 :=\nby rw [\u2190 mul_self_eq_one_iff, \u2190 sin_sq_add_cos_sq x,\n    sq, sq, \u2190 sub_eq_iff_eq_add, sub_self];\n  exact \u27e8\u03bb h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero \u2218 eq.symm\u27e9\n\nlemma cos_eq_one_iff (x : \u211d) : cos x = 1 \u2194 \u2203 n : \u2124, (n : \u211d) * (2 * \u03c0) = x :=\n\u27e8\u03bb h, let \u27e8n, hn\u27e9 := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in\n    \u27e8n / 2, (int.mod_two_eq_zero_or_one n).elim\n      (\u03bb hn0, by rwa [\u2190 mul_assoc, \u2190 @int.cast_two \u211d, \u2190 int.cast_mul, int.div_mul_cancel\n        ((int.dvd_iff_mod_eq_zero _ _).2 hn0)])\n      (\u03bb hn1, by rw [\u2190 int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,\n          one_mul, add_comm, mul_comm (2 : \u2124), int.cast_mul, mul_assoc, int.cast_two] at hn;\n        rw [\u2190 hn, cos_int_mul_two_pi_add_pi] at h;\n        exact absurd h (by norm_num))\u27e9,\n  \u03bb \u27e8n, hn\u27e9, hn \u25b8 cos_int_mul_two_pi _\u27e9\n\nlemma cos_eq_one_iff_of_lt_of_lt {x : \u211d} (hx\u2081 : -(2 * \u03c0) < x) (hx\u2082 : x < 2 * \u03c0) :\n  cos x = 1 \u2194 x = 0 :=\n\u27e8\u03bb h,\n    begin\n      rcases (cos_eq_one_iff _).1 h with \u27e8n, rfl\u27e9,\n      rw [mul_lt_iff_lt_one_left two_pi_pos] at hx\u2082,\n      rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx\u2081,\n      norm_cast at hx\u2081 hx\u2082,\n      obtain rfl : n = 0 := le_antisymm (by linarith) (by linarith),\n      simp\n    end,\n  \u03bb h, by simp [h]\u27e9\n\nlemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : \u211d} (hx\u2081 : 0 \u2264 x) (hy\u2082 : y \u2264 \u03c0 / 2)\n  (hxy : x < y) :\n  cos y < cos x :=\nbegin\n  rw [\u2190 sub_lt_zero, cos_sub_cos],\n  have : 0 < sin ((y + x) / 2),\n  { refine sin_pos_of_pos_of_lt_pi _ _; linarith },\n  have : 0 < sin ((y - x) / 2),\n  { refine sin_pos_of_pos_of_lt_pi _ _; linarith },\n  nlinarith,\nend\n\nlemma cos_lt_cos_of_nonneg_of_le_pi {x y : \u211d} (hx\u2081 : 0 \u2264 x) (hy\u2082 : y \u2264 \u03c0) (hxy : x < y) :\n  cos y < cos x :=\nmatch (le_total x (\u03c0 / 2) : x \u2264 \u03c0 / 2 \u2228 \u03c0 / 2 \u2264 x), le_total y (\u03c0 / 2) with\n| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx\u2081 hy hxy\n| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim\n  (\u03bb hx, calc cos y \u2264 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])\n    ... < cos x : cos_pos_of_mem_Ioo \u27e8by linarith, hx\u27e9)\n  (\u03bb hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])\n    ... = cos x : by rw [hx, cos_pi_div_two])\n| or.inr hx, or.inl hy := by linarith\n| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [\u2190 cos_pi_sub, \u2190 cos_pi_sub];\n  apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)\nend\n\nlemma strict_mono_decr_on_cos : strict_mono_decr_on cos (Icc 0 \u03c0) :=\n\u03bb x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy\n\nlemma cos_le_cos_of_nonneg_of_le_pi {x y : \u211d} (hx\u2081 : 0 \u2264 x) (hy\u2082 : y \u2264 \u03c0) (hxy : x \u2264 y) :\n  cos y \u2264 cos x :=\n(strict_mono_decr_on_cos.le_iff_le \u27e8hx\u2081.trans hxy, hy\u2082\u27e9 \u27e8hx\u2081, hxy.trans hy\u2082\u27e9).2 hxy\n\nlemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : \u211d} (hx\u2081 : -(\u03c0 / 2) \u2264 x)\n  (hy\u2082 : y \u2264 \u03c0 / 2) (hxy : x < y) : sin x < sin y :=\nby rw [\u2190 cos_sub_pi_div_two, \u2190 cos_sub_pi_div_two, \u2190 cos_neg (x - _), \u2190 cos_neg (y - _)];\n  apply cos_lt_cos_of_nonneg_of_le_pi; linarith\n\nlemma strict_mono_incr_on_sin : strict_mono_incr_on sin (Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :=\n\u03bb x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy\n\nlemma sin_le_sin_of_le_of_le_pi_div_two {x y : \u211d} (hx\u2081 : -(\u03c0 / 2) \u2264 x)\n  (hy\u2082 : y \u2264 \u03c0 / 2) (hxy : x \u2264 y) : sin x \u2264 sin y :=\n(strict_mono_incr_on_sin.le_iff_le \u27e8hx\u2081, hxy.trans hy\u2082\u27e9 \u27e8hx\u2081.trans hxy, hy\u2082\u27e9).2 hxy\n\nlemma inj_on_sin : inj_on sin (Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :=\nstrict_mono_incr_on_sin.inj_on\n\nlemma inj_on_cos : inj_on cos (Icc 0 \u03c0) := strict_mono_decr_on_cos.inj_on\n\nlemma surj_on_sin : surj_on sin (Icc (-(\u03c0 / 2)) (\u03c0 / 2)) (Icc (-1) 1) :=\nby simpa only [sin_neg, sin_pi_div_two]\n  using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on\n\nlemma surj_on_cos : surj_on cos (Icc 0 \u03c0) (Icc (-1) 1) :=\nby simpa only [cos_zero, cos_pi]\n  using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on\n\nlemma sin_mem_Icc (x : \u211d) : sin x \u2208 Icc (-1 : \u211d) 1 := \u27e8neg_one_le_sin x, sin_le_one x\u27e9\n\nlemma cos_mem_Icc (x : \u211d) : cos x \u2208 Icc (-1 : \u211d) 1 := \u27e8neg_one_le_cos x, cos_le_one x\u27e9\n\nlemma maps_to_sin (s : set \u211d) : maps_to sin s (Icc (-1 : \u211d) 1) := \u03bb x _, sin_mem_Icc x\n\nlemma maps_to_cos (s : set \u211d) : maps_to cos s (Icc (-1 : \u211d) 1) := \u03bb x _, cos_mem_Icc x\n\nlemma bij_on_sin : bij_on sin (Icc (-(\u03c0 / 2)) (\u03c0 / 2)) (Icc (-1) 1) :=\n\u27e8maps_to_sin _, inj_on_sin, surj_on_sin\u27e9\n\nlemma bij_on_cos : bij_on cos (Icc 0 \u03c0) (Icc (-1) 1) :=\n\u27e8maps_to_cos _, inj_on_cos, surj_on_cos\u27e9\n\n@[simp] lemma range_cos : range cos = (Icc (-1) 1 : set \u211d) :=\nsubset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range\n\n@[simp] lemma range_sin : range sin = (Icc (-1) 1 : set \u211d) :=\nsubset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range\n\nlemma range_cos_infinite : (range real.cos).infinite :=\nby { rw real.range_cos, exact Icc.infinite (by norm_num) }\n\nlemma range_sin_infinite : (range real.sin).infinite :=\nby { rw real.range_sin, exact Icc.infinite (by norm_num) }\n\nlemma sin_lt {x : \u211d} (h : 0 < x) : sin x < x :=\nbegin\n  cases le_or_gt x 1 with h' h',\n  { have hx : abs x = x := abs_of_nonneg (le_of_lt h),\n    have : abs x \u2264 1, rwa [hx],\n    have := sin_bound this, rw [abs_le] at this,\n    have := this.2, rw [sub_le_iff_le_add', hx] at this,\n    apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),\n    apply sub_lt_sub_left, rw [sub_pos, div_eq_mul_inv (x ^ 3)], apply mul_lt_mul',\n    { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),\n      rw mul_le_mul_right, exact h', apply pow_pos h },\n    norm_num, norm_num, apply pow_pos h },\n  exact lt_of_le_of_lt (sin_le_one x) h'\nend\n\n/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.\n   note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/\nlemma sin_gt_sub_cube {x : \u211d} (h : 0 < x) (h' : x \u2264 1) : x - x ^ 3 / 4 < sin x :=\nbegin\n  have hx : abs x = x := abs_of_nonneg (le_of_lt h),\n  have : abs x \u2264 1, rwa [hx],\n  have := sin_bound this, rw [abs_le] at this,\n  have := this.1, rw [le_sub_iff_add_le, hx] at this,\n  refine lt_of_lt_of_le _ this,\n  rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,\n  apply add_lt_of_lt_sub_left,\n  rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12\u207b\u00b9,\n    by simp [div_eq_mul_inv, \u2190 mul_sub]; norm_num),\n  apply mul_lt_mul',\n  { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),\n    rw mul_le_mul_right, exact h', apply pow_pos h },\n  norm_num, norm_num, apply pow_pos h\nend\n\nsection cos_div_sq\n\nvariable (x : \u211d)\n\n/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,\n  starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`\n-/\n@[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : \u211d) : \u2115 \u2192 \u211d\n| 0     := x\n| (n+1) := sqrt (2 + sqrt_two_add_series n)\n\nlemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp\nlemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp\nlemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp\n\nlemma sqrt_two_add_series_zero_nonneg : \u2200(n : \u2115), 0 \u2264 sqrt_two_add_series 0 n\n| 0     := le_refl 0\n| (n+1) := sqrt_nonneg _\n\nlemma sqrt_two_add_series_nonneg {x : \u211d} (h : 0 \u2264 x) : \u2200(n : \u2115), 0 \u2264 sqrt_two_add_series x n\n| 0     := h\n| (n+1) := sqrt_nonneg _\n\nlemma sqrt_two_add_series_lt_two : \u2200(n : \u2115), sqrt_two_add_series 0 n < 2\n| 0     := by norm_num\n| (n+1) :=\n  begin\n    refine lt_of_lt_of_le _ (le_of_eq $ sqrt_sq $ le_of_lt zero_lt_two),\n    rw [sqrt_two_add_series, sqrt_lt, \u2190 lt_sub_iff_add_lt'],\n    { refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num },\n    { exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) }\n  end\n\nlemma sqrt_two_add_series_succ (x : \u211d) :\n  \u2200(n : \u2115), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n\n| 0     := rfl\n| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]\n\nlemma sqrt_two_add_series_monotone_left {x y : \u211d} (h : x \u2264 y) :\n  \u2200(n : \u2115), sqrt_two_add_series x n \u2264 sqrt_two_add_series y n\n| 0     := h\n| (n+1) :=\n  begin\n    rw [sqrt_two_add_series, sqrt_two_add_series],\n    exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _)\n  end\n\n@[simp] lemma cos_pi_over_two_pow : \u2200(n : \u2115), cos (\u03c0 / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2\n| 0     := by simp\n| (n+1) :=\n  begin\n    have : (2 : \u211d) \u2260 0 := two_ne_zero,\n    symmetry, rw [div_eq_iff_mul_eq this], symmetry,\n    rw [sqrt_two_add_series, sqrt_eq_iff_sq_eq, mul_pow, cos_sq, \u2190mul_div_assoc,\n      nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul],\n    congr, { norm_num },\n    rw [mul_comm, sq, mul_assoc, \u2190mul_div_assoc, mul_div_cancel_left, \u2190mul_div_assoc,\n        mul_div_cancel_left]; try { exact this },\n    apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,\n    apply le_of_lt, apply cos_pos_of_mem_Ioo \u27e8_, _\u27e9,\n    { transitivity (0 : \u211d), rw neg_lt_zero, apply pi_div_two_pos,\n      apply div_pos pi_pos, apply pow_pos, norm_num },\n    apply div_lt_div' (le_refl \u03c0) _ pi_pos _,\n    refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,\n    apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}\n  end\n\nlemma sin_sq_pi_over_two_pow (n : \u2115) :\n  sin (\u03c0 / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=\nby rw [sin_sq, cos_pi_over_two_pow]\n\nlemma sin_sq_pi_over_two_pow_succ (n : \u2115) :\n  sin (\u03c0 / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=\nbegin\n  rw [sin_sq_pi_over_two_pow, sqrt_two_add_series, div_pow, sq_sqrt, add_div, \u2190sub_sub],\n  congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,\nend\n\n@[simp] lemma sin_pi_over_two_pow_succ (n : \u2115) :\n  sin (\u03c0 / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=\nbegin\n  symmetry, rw [div_eq_iff_mul_eq], symmetry,\n  rw [sqrt_eq_iff_sq_eq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul],\n  { congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },\n  { rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },\n  apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,\n  { apply div_pos pi_pos, apply pow_pos, norm_num },\n  refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],\n  refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,\n  apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,\n  apply pow_pos, all_goals {norm_num}\nend\n\n@[simp] lemma cos_pi_div_four : cos (\u03c0 / 4) = sqrt 2 / 2 :=\nby { transitivity cos (\u03c0 / 2 ^ 2), congr, norm_num, simp }\n\n@[simp] lemma sin_pi_div_four : sin (\u03c0 / 4) = sqrt 2 / 2 :=\nby { transitivity sin (\u03c0 / 2 ^ 2), congr, norm_num, simp }\n\n@[simp] lemma cos_pi_div_eight : cos (\u03c0 / 8) = sqrt (2 + sqrt 2) / 2 :=\nby { transitivity cos (\u03c0 / 2 ^ 3), congr, norm_num, simp }\n\n@[simp] lemma sin_pi_div_eight : sin (\u03c0 / 8) = sqrt (2 - sqrt 2) / 2 :=\nby { transitivity sin (\u03c0 / 2 ^ 3), congr, norm_num, simp }\n\n@[simp] lemma cos_pi_div_sixteen : cos (\u03c0 / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=\nby { transitivity cos (\u03c0 / 2 ^ 4), congr, norm_num, simp }\n\n@[simp] lemma sin_pi_div_sixteen : sin (\u03c0 / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=\nby { transitivity sin (\u03c0 / 2 ^ 4), congr, norm_num, simp }\n\n@[simp] lemma cos_pi_div_thirty_two : cos (\u03c0 / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=\nby { transitivity cos (\u03c0 / 2 ^ 5), congr, norm_num, simp }\n\n@[simp] lemma sin_pi_div_thirty_two : sin (\u03c0 / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=\nby { transitivity sin (\u03c0 / 2 ^ 5), congr, norm_num, simp }\n\n-- This section is also a convenient location for other explicit values of `sin` and `cos`.\n\n/-- The cosine of `\u03c0 / 3` is `1 / 2`. -/\n@[simp] lemma cos_pi_div_three : cos (\u03c0 / 3) = 1 / 2 :=\nbegin\n  have h\u2081 : (2 * cos (\u03c0 / 3) - 1) ^ 2 * (2 * cos (\u03c0 / 3) + 2) = 0,\n  { have : cos (3 * (\u03c0 / 3)) = cos \u03c0 := by { congr' 1, ring },\n    linarith [cos_pi, cos_three_mul (\u03c0 / 3)] },\n  cases mul_eq_zero.mp h\u2081 with h h,\n  { linarith [pow_eq_zero h] },\n  { have : cos \u03c0 < cos (\u03c0 / 3),\n    { refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _;\n      linarith [pi_pos] },\n    linarith [cos_pi] }\nend\n\n/-- The square of the cosine of `\u03c0 / 6` is `3 / 4` (this is sometimes more convenient than the\nresult for cosine itself). -/\nlemma sq_cos_pi_div_six : cos (\u03c0 / 6) ^ 2 = 3 / 4 :=\nbegin\n  have h1 : cos (\u03c0 / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,\n  { convert cos_sq (\u03c0 / 6),\n    have h2 : 2 * (\u03c0 / 6) = \u03c0 / 3 := by cancel_denoms,\n    rw [h2, cos_pi_div_three] },\n  rw \u2190 sub_eq_zero at h1 \u22a2,\n  convert h1 using 1,\n  ring\nend\n\n/-- The cosine of `\u03c0 / 6` is `\u221a3 / 2`. -/\n@[simp] lemma cos_pi_div_six : cos (\u03c0 / 6) = (sqrt 3) / 2 :=\nbegin\n  suffices : sqrt 3 = cos (\u03c0 / 6) * 2,\n  { field_simp [(by norm_num : 0 \u2260 2)], exact this.symm },\n  rw sqrt_eq_iff_sq_eq,\n  { have h1 := (mul_right_inj' (by norm_num : (4:\u211d) \u2260 0)).mpr sq_cos_pi_div_six,\n    rw \u2190 sub_eq_zero at h1 \u22a2,\n    convert h1 using 1,\n    ring },\n  { norm_num },\n  { have : 0 < cos (\u03c0 / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] },\n    linarith },\nend\n\n/-- The sine of `\u03c0 / 6` is `1 / 2`. -/\n@[simp] lemma sin_pi_div_six : sin (\u03c0 / 6) = 1 / 2 :=\nbegin\n  rw [\u2190 cos_pi_div_two_sub, \u2190 cos_pi_div_three],\n  congr,\n  ring\nend\n\n/-- The square of the sine of `\u03c0 / 3` is `3 / 4` (this is sometimes more convenient than the\nresult for cosine itself). -/\nlemma sq_sin_pi_div_three : sin (\u03c0 / 3) ^ 2 = 3 / 4 :=\nbegin\n  rw [\u2190 cos_pi_div_two_sub, \u2190 sq_cos_pi_div_six],\n  congr,\n  ring\nend\n\n/-- The sine of `\u03c0 / 3` is `\u221a3 / 2`. -/\n@[simp] lemma sin_pi_div_three : sin (\u03c0 / 3) = (sqrt 3) / 2 :=\nbegin\n  rw [\u2190 cos_pi_div_two_sub, \u2190 cos_pi_div_six],\n  congr,\n  ring\nend\n\nend cos_div_sq\n\n/-- The type of angles -/\ndef angle : Type :=\nquotient_add_group.quotient (add_subgroup.gmultiples (2 * \u03c0))\n\nnamespace angle\n\ninstance angle.add_comm_group : add_comm_group angle :=\nquotient_add_group.add_comm_group _\n\ninstance : inhabited angle := \u27e80\u27e9\n\ninstance angle.has_coe : has_coe \u211d angle :=\n\u27e8quotient.mk'\u27e9\n\n@[simp] lemma coe_zero : \u2191(0 : \u211d) = (0 : angle) := rfl\n@[simp] lemma coe_add (x y : \u211d) : \u2191(x + y : \u211d) = (\u2191x + \u2191y : angle) := rfl\n@[simp] lemma coe_neg (x : \u211d) : \u2191(-x : \u211d) = -(\u2191x : angle) := rfl\n@[simp] lemma coe_sub (x y : \u211d) : \u2191(x - y : \u211d) = (\u2191x - \u2191y : angle) :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, coe_add, coe_neg]\n\n@[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : \u211d) (n : \u2115) :\n  \u2191((n : \u211d) * x) = n \u2022 (\u2191x : angle) :=\nby simpa using add_monoid_hom.map_nsmul \u27e8coe, coe_zero, coe_add\u27e9 _ _\n@[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : \u211d) (n : \u2124) :\n  \u2191((n : \u211d) * x : \u211d) = n \u2022 (\u2191x : angle) :=\nby simpa using add_monoid_hom.map_gsmul \u27e8coe, coe_zero, coe_add\u27e9 _ _\n\n@[simp] lemma coe_two_pi : \u2191(2 * \u03c0 : \u211d) = (0 : angle) :=\nquotient.sound' \u27e8-1, show (-1 : \u2124) \u2022 (2 * \u03c0) = _, by rw [neg_one_gsmul, add_zero]\u27e9\n\nlemma angle_eq_iff_two_pi_dvd_sub {\u03c8 \u03b8 : \u211d} : (\u03b8 : angle) = \u03c8 \u2194 \u2203 k : \u2124, \u03b8 - \u03c8 = 2 * \u03c0 * k :=\nby simp only [quotient_add_group.eq, add_subgroup.gmultiples_eq_closure,\n  add_subgroup.mem_closure_singleton, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]\n\ntheorem cos_eq_iff_eq_or_eq_neg {\u03b8 \u03c8 : \u211d} : cos \u03b8 = cos \u03c8 \u2194 (\u03b8 : angle) = \u03c8 \u2228 (\u03b8 : angle) = -\u03c8 :=\nbegin\n  split,\n  { intro Hcos,\n    rw [\u2190 sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,\n        eq_false_intro two_ne_zero, false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos,\n    rcases Hcos with \u27e8n, hn\u27e9 | \u27e8n, hn\u27e9,\n    { right,\n      rw [eq_div_iff_mul_eq (@two_ne_zero \u211d _ _), \u2190 sub_eq_iff_eq_add] at hn,\n      rw [\u2190 hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc,\n          coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] },\n    { left,\n      rw [eq_div_iff_mul_eq (@two_ne_zero \u211d _ _), eq_sub_iff_add_eq] at hn,\n      rw [\u2190 hn, coe_add, mul_assoc,\n          coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] },\n    apply_instance, },\n  { rw [angle_eq_iff_two_pi_dvd_sub, \u2190 coe_neg, angle_eq_iff_two_pi_dvd_sub],\n    rintro (\u27e8k, H\u27e9 | \u27e8k, H\u27e9),\n    rw [\u2190 sub_eq_zero, cos_sub_cos, H, mul_assoc 2 \u03c0 k,\n        mul_div_cancel_left _ (@two_ne_zero \u211d _ _), mul_comm \u03c0 _, sin_int_mul_pi, mul_zero],\n    rw [\u2190 sub_eq_zero, cos_sub_cos, \u2190 sub_neg_eq_add, H, mul_assoc 2 \u03c0 k,\n        mul_div_cancel_left _ (@two_ne_zero \u211d _ _), mul_comm \u03c0 _, sin_int_mul_pi, mul_zero,\n        zero_mul] }\nend\n\ntheorem sin_eq_iff_eq_or_add_eq_pi {\u03b8 \u03c8 : \u211d} :\n  sin \u03b8 = sin \u03c8 \u2194 (\u03b8 : angle) = \u03c8 \u2228 (\u03b8 : angle) + \u03c8 = \u03c0 :=\nbegin\n  split,\n  { intro Hsin, rw [\u2190 cos_pi_div_two_sub, \u2190 cos_pi_div_two_sub] at Hsin,\n    cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h,\n    { left, rw [coe_sub, coe_sub] at h, exact sub_right_inj.1 h },\n      right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub,\n      sub_add_eq_add_sub, \u2190 coe_add, add_halves, sub_sub, sub_eq_zero] at h,\n    exact h.symm },\n  { rw [angle_eq_iff_two_pi_dvd_sub, \u2190eq_sub_iff_add_eq, \u2190coe_sub, angle_eq_iff_two_pi_dvd_sub],\n    rintro (\u27e8k, H\u27e9 | \u27e8k, H\u27e9),\n    rw [\u2190 sub_eq_zero, sin_sub_sin, H, mul_assoc 2 \u03c0 k,\n         mul_div_cancel_left _ (@two_ne_zero \u211d _ _), mul_comm \u03c0 _, sin_int_mul_pi, mul_zero,\n         zero_mul],\n    have H' : \u03b8 + \u03c8 = (2 * k) * \u03c0 + \u03c0 := by rwa [\u2190sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add,\n      mul_assoc, mul_comm \u03c0 _, \u2190mul_assoc] at H,\n    rw [\u2190 sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ \u03c0,\n        mul_div_cancel_left _ (@two_ne_zero \u211d _ _), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,\n        mul_zero] }\nend\n\ntheorem cos_sin_inj {\u03b8 \u03c8 : \u211d} (Hcos : cos \u03b8 = cos \u03c8) (Hsin : sin \u03b8 = sin \u03c8) : (\u03b8 : angle) = \u03c8 :=\nbegin\n  cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc },\n  cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs },\n  rw [eq_neg_iff_add_eq_zero, hs] at hc,\n  cases quotient.exact' hc with n hn, change n \u2022 _ = _ at hn,\n  rw [\u2190 neg_one_mul, add_zero, \u2190 sub_eq_zero, gsmul_eq_mul, \u2190 mul_assoc, \u2190 sub_mul,\n      mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add,\n      \u2190 int.cast_zero, \u2190 int.cast_one, \u2190 int.cast_bit0, \u2190 int.cast_mul, \u2190 int.cast_add,\n      int.cast_inj] at hn,\n  have : (n * 2 + 1) % (2:\u2124) = 0 % (2:\u2124) := congr_arg (%(2:\u2124)) hn,\n  rw [add_comm, int.add_mul_mod_self] at this,\n  exact absurd this one_ne_zero\nend\n\nend angle\n\n/-- `real.sin` as an `order_iso` between `[-(\u03c0 / 2), \u03c0 / 2]` and `[-1, 1]`. -/\ndef sin_order_iso : Icc (-(\u03c0 / 2)) (\u03c0 / 2) \u2243o Icc (-1:\u211d) 1 :=\n(strict_mono_incr_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq\n\n@[simp] lemma coe_sin_order_iso_apply (x : Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  (sin_order_iso x : \u211d) = sin x := rfl\n\nlemma sin_order_iso_apply (x : Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  sin_order_iso x = \u27e8sin x, sin_mem_Icc x\u27e9 := rfl\n\n/-- Inverse of the `sin` function, returns values in the range `-\u03c0 / 2 \u2264 arcsin x \u2264 \u03c0 / 2`.\nIt defaults to `-\u03c0 / 2` on `(-\u221e, -1)` and to `\u03c0 / 2` to `(1, \u221e)`. -/\n@[pp_nodot] noncomputable def arcsin : \u211d \u2192 \u211d :=\ncoe \u2218 Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm\n\nlemma arcsin_mem_Icc (x : \u211d) : arcsin x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2) := subtype.coe_prop _\n\n@[simp] lemma range_arcsin : range arcsin = Icc (-(\u03c0 / 2)) (\u03c0 / 2) :=\nby { rw [arcsin, range_comp coe], simp [Icc] }\n\nlemma arcsin_le_pi_div_two (x : \u211d) : arcsin x \u2264 \u03c0 / 2 := (arcsin_mem_Icc x).2\n\nlemma neg_pi_div_two_le_arcsin (x : \u211d) : -(\u03c0 / 2) \u2264 arcsin x := (arcsin_mem_Icc x).1\n\nlemma arcsin_proj_Icc (x : \u211d) :\n  arcsin (proj_Icc (-1) 1 (neg_le_self $ @zero_le_one \u211d _) x) = arcsin x :=\nby rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend]\n\nlemma sin_arcsin' {x : \u211d} (hx : x \u2208 Icc (-1 : \u211d) 1) : sin (arcsin x) = x :=\nby simpa [arcsin, Icc_extend_of_mem _ _ hx, -order_iso.apply_symm_apply]\n  using subtype.ext_iff.1 (sin_order_iso.apply_symm_apply \u27e8x, hx\u27e9)\n\nlemma sin_arcsin {x : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) : sin (arcsin x) = x :=\nsin_arcsin' \u27e8hx\u2081, hx\u2082\u27e9\n\nlemma arcsin_sin' {x : \u211d} (hx : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) : arcsin (sin x) = x :=\ninj_on_sin (arcsin_mem_Icc _) hx $ by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]\n\nlemma arcsin_sin {x : \u211d} (hx\u2081 : -(\u03c0 / 2) \u2264 x) (hx\u2082 : x \u2264 \u03c0 / 2) : arcsin (sin x) = x :=\narcsin_sin' \u27e8hx\u2081, hx\u2082\u27e9\n\nlemma strict_mono_incr_on_arcsin : strict_mono_incr_on arcsin (Icc (-1) 1) :=\n(subtype.strict_mono_coe _).comp_strict_mono_incr_on $\n  sin_order_iso.symm.strict_mono.strict_mono_incr_on_Icc_extend _\n\nlemma monotone_arcsin : monotone arcsin :=\n(subtype.mono_coe _).comp $ sin_order_iso.symm.monotone.Icc_extend _\n\nlemma inj_on_arcsin : inj_on arcsin (Icc (-1) 1) := strict_mono_incr_on_arcsin.inj_on\n\nlemma arcsin_inj {x y : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) (hy\u2081 : -1 \u2264 y) (hy\u2082 : y \u2264 1) :\n  arcsin x = arcsin y \u2194 x = y :=\ninj_on_arcsin.eq_iff \u27e8hx\u2081, hx\u2082\u27e9 \u27e8hy\u2081, hy\u2082\u27e9\n\n@[continuity]\nlemma continuous_arcsin : continuous arcsin :=\ncontinuous_subtype_coe.comp sin_order_iso.symm.continuous.Icc_extend\n\nlemma continuous_at_arcsin {x : \u211d} : continuous_at arcsin x :=\ncontinuous_arcsin.continuous_at\n\nlemma arcsin_eq_of_sin_eq {x y : \u211d} (h\u2081 : sin x = y) (h\u2082 : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  arcsin y = x :=\nbegin\n  subst y,\n  exact inj_on_sin (arcsin_mem_Icc _) h\u2082 (sin_arcsin' (sin_mem_Icc x))\nend\n\n@[simp] lemma arcsin_zero : arcsin 0 = 0 :=\narcsin_eq_of_sin_eq sin_zero \u27e8neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le\u27e9\n\n@[simp] lemma arcsin_one : arcsin 1 = \u03c0 / 2 :=\narcsin_eq_of_sin_eq sin_pi_div_two $ right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)\n\nlemma arcsin_of_one_le {x : \u211d} (hx : 1 \u2264 x) : arcsin x = \u03c0 / 2 :=\nby rw [\u2190 arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one]\n\nlemma arcsin_neg_one : arcsin (-1) = -(\u03c0 / 2) :=\narcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) $\n  left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)\n\nlemma arcsin_of_le_neg_one {x : \u211d} (hx : x \u2264 -1) : arcsin x = -(\u03c0 / 2) :=\nby rw [\u2190 arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one]\n\n@[simp] lemma arcsin_neg (x : \u211d) : arcsin (-x) = -arcsin x :=\nbegin\n  cases le_total x (-1) with hx\u2081 hx\u2081,\n  { rw [arcsin_of_le_neg_one hx\u2081, neg_neg, arcsin_of_one_le (le_neg.2 hx\u2081)] },\n  cases le_total 1 x with hx\u2082 hx\u2082,\n  { rw [arcsin_of_one_le hx\u2082, arcsin_of_le_neg_one (neg_le_neg hx\u2082)] },\n  refine arcsin_eq_of_sin_eq _ _,\n  { rw [sin_neg, sin_arcsin hx\u2081 hx\u2082] },\n  { exact \u27e8neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)\u27e9 }\nend\n\nlemma arcsin_le_iff_le_sin {x y : \u211d} (hx : x \u2208 Icc (-1 : \u211d) 1) (hy : y \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  arcsin x \u2264 y \u2194 x \u2264 sin y :=\nby rw [\u2190 arcsin_sin' hy, strict_mono_incr_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]\n\nlemma arcsin_le_iff_le_sin' {x y : \u211d} (hy : y \u2208 Ico (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  arcsin x \u2264 y \u2194 x \u2264 sin y :=\nbegin\n  cases le_total x (-1) with hx\u2081 hx\u2081,\n  { simp [arcsin_of_le_neg_one hx\u2081, hy.1, hx\u2081.trans (neg_one_le_sin _)] },\n  cases lt_or_le 1 x with hx\u2082 hx\u2082,\n  { simp [arcsin_of_one_le hx\u2082.le, hy.2.not_le, (sin_le_one y).trans_lt hx\u2082] },\n  exact arcsin_le_iff_le_sin \u27e8hx\u2081, hx\u2082\u27e9 (mem_Icc_of_Ico hy)\nend\n\nlemma le_arcsin_iff_sin_le {x y : \u211d} (hx : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) (hy : y \u2208 Icc (-1 : \u211d) 1) :\n  x \u2264 arcsin y \u2194 sin x \u2264 y :=\nby rw [\u2190 neg_le_neg_iff, \u2190 arcsin_neg,\n  arcsin_le_iff_le_sin \u27e8neg_le_neg hy.2, neg_le.2 hy.1\u27e9 \u27e8neg_le_neg hx.2, neg_le.2 hx.1\u27e9,\n  sin_neg, neg_le_neg_iff]\n\nlemma le_arcsin_iff_sin_le' {x y : \u211d} (hx : x \u2208 Ioc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  x \u2264 arcsin y \u2194 sin x \u2264 y :=\nby rw [\u2190 neg_le_neg_iff, \u2190 arcsin_neg, arcsin_le_iff_le_sin' \u27e8neg_le_neg hx.2, neg_lt.2 hx.1\u27e9,\n  sin_neg, neg_le_neg_iff]\n\nlemma arcsin_lt_iff_lt_sin {x y : \u211d} (hx : x \u2208 Icc (-1 : \u211d) 1) (hy : y \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  arcsin x < y \u2194 x < sin y :=\nnot_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le hy hx).trans not_le\n\nlemma arcsin_lt_iff_lt_sin' {x y : \u211d} (hy : y \u2208 Ioc (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  arcsin x < y \u2194 x < sin y :=\nnot_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le' hy).trans not_le\n\nlemma lt_arcsin_iff_sin_lt {x y : \u211d} (hx : x \u2208 Icc (-(\u03c0 / 2)) (\u03c0 / 2)) (hy : y \u2208 Icc (-1 : \u211d) 1) :\n  x < arcsin y \u2194 sin x < y :=\nnot_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin hy hx).trans not_le\n\nlemma lt_arcsin_iff_sin_lt' {x y : \u211d} (hx : x \u2208 Ico (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  x < arcsin y \u2194 sin x < y :=\nnot_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin' hx).trans not_le\n\nlemma arcsin_eq_iff_eq_sin {x y : \u211d} (hy : y \u2208 Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  arcsin x = y \u2194 x = sin y :=\nby simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),\n  le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]\n\n@[simp] lemma arcsin_nonneg {x : \u211d} : 0 \u2264 arcsin x \u2194 0 \u2264 x :=\n(le_arcsin_iff_sin_le' \u27e8neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le\u27e9).trans $ by rw [sin_zero]\n\n@[simp] lemma arcsin_nonpos {x : \u211d} : arcsin x \u2264 0 \u2194 x \u2264 0 :=\nneg_nonneg.symm.trans $ arcsin_neg x \u25b8 arcsin_nonneg.trans neg_nonneg\n\n@[simp] lemma arcsin_eq_zero_iff {x : \u211d} : arcsin x = 0 \u2194 x = 0 :=\nby simp [le_antisymm_iff]\n\n@[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x \u2194 x = 0 :=\neq_comm.trans arcsin_eq_zero_iff\n\n@[simp] lemma arcsin_pos {x : \u211d} : 0 < arcsin x \u2194 0 < x :=\nlt_iff_lt_of_le_iff_le arcsin_nonpos\n\n@[simp] lemma arcsin_lt_zero {x : \u211d} : arcsin x < 0 \u2194 x < 0 :=\nlt_iff_lt_of_le_iff_le arcsin_nonneg\n\n@[simp] lemma arcsin_lt_pi_div_two {x : \u211d} : arcsin x < \u03c0 / 2 \u2194 x < 1 :=\n(arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 $ neg_lt_self pi_div_two_pos)).trans $\n  by rw sin_pi_div_two\n\n@[simp] lemma neg_pi_div_two_lt_arcsin {x : \u211d} : -(\u03c0 / 2) < arcsin x \u2194 -1 < x :=\n(lt_arcsin_iff_sin_lt' $ left_mem_Ico.2 $ neg_lt_self pi_div_two_pos).trans $\n  by rw [sin_neg, sin_pi_div_two]\n\n@[simp] lemma arcsin_eq_pi_div_two {x : \u211d} : arcsin x = \u03c0 / 2 \u2194 1 \u2264 x :=\n\u27e8\u03bb h, not_lt.1 $ \u03bb h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le\u27e9\n\n@[simp] lemma pi_div_two_eq_arcsin {x} : \u03c0 / 2 = arcsin x \u2194 1 \u2264 x :=\neq_comm.trans arcsin_eq_pi_div_two\n\n@[simp] lemma pi_div_two_le_arcsin {x} : \u03c0 / 2 \u2264 arcsin x \u2194 1 \u2264 x :=\n(arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin\n\n@[simp] lemma arcsin_eq_neg_pi_div_two {x : \u211d} : arcsin x = -(\u03c0 / 2) \u2194 x \u2264 -1 :=\n\u27e8\u03bb h, not_lt.1 $ \u03bb h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one\u27e9\n\n@[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(\u03c0 / 2) = arcsin x \u2194 x \u2264 -1 :=\neq_comm.trans arcsin_eq_neg_pi_div_two\n\n@[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x \u2264 -(\u03c0 / 2) \u2194 x \u2264 -1 :=\n(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two\n\nlemma maps_to_sin_Ioo : maps_to sin (Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) (Ioo (-1) 1) :=\n\u03bb x h, by rwa [mem_Ioo, \u2190 arcsin_lt_pi_div_two, \u2190 neg_pi_div_two_lt_arcsin,\n  arcsin_sin h.1.le h.2.le]\n\n/-- `real.sin` as a `local_homeomorph` between `(-\u03c0 / 2, \u03c0 / 2)` and `(-1, 1)`. -/\n@[simp] def sin_local_homeomorph : local_homeomorph \u211d \u211d :=\n{ to_fun := sin,\n  inv_fun := arcsin,\n  source := Ioo (-(\u03c0 / 2)) (\u03c0 / 2),\n  target := Ioo (-1) 1,\n  map_source' := maps_to_sin_Ioo,\n  map_target' := \u03bb y hy, \u27e8neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2\u27e9,\n  left_inv' := \u03bb x hx, arcsin_sin hx.1.le hx.2.le,\n  right_inv' := \u03bb y hy, sin_arcsin hy.1.le hy.2.le,\n  open_source := is_open_Ioo,\n  open_target := is_open_Ioo,\n  continuous_to_fun := continuous_sin.continuous_on,\n  continuous_inv_fun := continuous_arcsin.continuous_on }\n\nlemma cos_arcsin_nonneg (x : \u211d) : 0 \u2264 cos (arcsin x) :=\ncos_nonneg_of_mem_Icc \u27e8neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _\u27e9\n\nlemma cos_arcsin {x : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) : cos (arcsin x) = sqrt (1 - x ^ 2) :=\nhave sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x),\nbegin\n  rw [\u2190 eq_sub_iff_add_eq', \u2190 sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))),\n    sq, sqrt_mul_self (cos_arcsin_nonneg _)] at this,\n  rw [this, sin_arcsin hx\u2081 hx\u2082],\nend\n\nlemma deriv_arcsin_aux {x : \u211d} (h\u2081 : x \u2260 -1) (h\u2082 : x \u2260 1) :\n  has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x \u2227 times_cont_diff_at \u211d \u22a4 arcsin x :=\nbegin\n  cases h\u2081.lt_or_lt with h\u2081 h\u2081,\n  { have : 1 - x ^ 2 < 0, by nlinarith [h\u2081],\n    rw [sqrt_eq_zero'.2 this.le, div_zero],\n    have : arcsin =\u1da0[\ud835\udcdd x] \u03bb _, -(\u03c0 / 2) :=\n      (gt_mem_nhds h\u2081).mono (\u03bb y hy, arcsin_of_le_neg_one hy.le),\n    exact \u27e8(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,\n      times_cont_diff_at_const.congr_of_eventually_eq this\u27e9 },\n  cases h\u2082.lt_or_lt with h\u2082 h\u2082,\n  { have : 0 < sqrt (1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h\u2081, h\u2082]),\n    simp only [\u2190 cos_arcsin h\u2081.le h\u2082.le, one_div] at this \u22a2,\n    exact \u27e8sin_local_homeomorph.has_strict_deriv_at_symm \u27e8h\u2081, h\u2082\u27e9 this.ne'\n      (has_strict_deriv_at_sin _),\n      sin_local_homeomorph.times_cont_diff_at_symm_deriv this.ne' \u27e8h\u2081, h\u2082\u27e9\n        (has_deriv_at_sin _) times_cont_diff_sin.times_cont_diff_at\u27e9 },\n  { have : 1 - x ^ 2 < 0, by nlinarith [h\u2082],\n    rw [sqrt_eq_zero'.2 this.le, div_zero],\n    have : arcsin =\u1da0[\ud835\udcdd x] \u03bb _, \u03c0 / 2 := (lt_mem_nhds h\u2082).mono (\u03bb y hy, arcsin_of_one_le hy.le),\n    exact \u27e8(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,\n      times_cont_diff_at_const.congr_of_eventually_eq this\u27e9 }\nend\n\nlemma has_strict_deriv_at_arcsin {x : \u211d} (h\u2081 : x \u2260 -1) (h\u2082 : x \u2260 1) :\n  has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=\n(deriv_arcsin_aux h\u2081 h\u2082).1\n\nlemma has_deriv_at_arcsin {x : \u211d} (h\u2081 : x \u2260 -1) (h\u2082 : x \u2260 1) :\n  has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=\n(has_strict_deriv_at_arcsin h\u2081 h\u2082).has_deriv_at\n\nlemma times_cont_diff_at_arcsin {x : \u211d} (h\u2081 : x \u2260 -1) (h\u2082 : x \u2260 1) {n : with_top \u2115} :\n  times_cont_diff_at \u211d n arcsin x :=\n(deriv_arcsin_aux h\u2081 h\u2082).2.of_le le_top\n\nlemma has_deriv_within_at_arcsin_Ici {x : \u211d} (h : x \u2260 -1) :\n  has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Ici x) x :=\nbegin\n  rcases em (x = 1) with (rfl|h'),\n  { convert (has_deriv_within_at_const _ _ (\u03c0 / 2)).congr _ _;\n      simp [arcsin_of_one_le] { contextual := tt } },\n  { exact (has_deriv_at_arcsin h h').has_deriv_within_at }\nend\n\nlemma has_deriv_within_at_arcsin_Iic {x : \u211d} (h : x \u2260 1) :\n  has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Iic x) x :=\nbegin\n  rcases em (x = -1) with (rfl|h'),\n  { convert (has_deriv_within_at_const _ _ (-(\u03c0 / 2))).congr _ _;\n      simp [arcsin_of_le_neg_one] { contextual := tt } },\n  { exact (has_deriv_at_arcsin h' h).has_deriv_within_at }\nend\n\nlemma differentiable_within_at_arcsin_Ici {x : \u211d} :\n  differentiable_within_at \u211d arcsin (Ici x) x \u2194 x \u2260 -1 :=\nbegin\n  refine \u27e8_, \u03bb h, (has_deriv_within_at_arcsin_Ici h).differentiable_within_at\u27e9,\n  rintro h rfl,\n  have : sin \u2218 arcsin =\u1da0[\ud835\udcdd[Ici (-1:\u211d)] (-1)] id,\n  { filter_upwards [Icc_mem_nhds_within_Ici \u27e8le_rfl, neg_lt_self (@zero_lt_one \u211d _ _)\u27e9],\n    exact \u03bb x, sin_arcsin' },\n  have := h.has_deriv_within_at.sin.congr_of_eventually_eq this.symm (by simp),\n  simpa using (unique_diff_on_Ici _ _ left_mem_Ici).eq_deriv _ this (has_deriv_within_at_id _ _)\nend\n\nlemma differentiable_within_at_arcsin_Iic {x : \u211d} :\n  differentiable_within_at \u211d arcsin (Iic x) x \u2194 x \u2260 1 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, (has_deriv_within_at_arcsin_Iic h).differentiable_within_at\u27e9,\n  rw [\u2190 neg_neg x, \u2190 image_neg_Ici] at h,\n  have := (h.comp (-x) differentiable_within_at_id.neg (maps_to_image _ _)).neg,\n  simpa [(\u2218), differentiable_within_at_arcsin_Ici] using this\nend\n\nlemma differentiable_at_arcsin {x : \u211d} :\n  differentiable_at \u211d arcsin x \u2194 x \u2260 -1 \u2227 x \u2260 1 :=\n\u27e8\u03bb h, \u27e8differentiable_within_at_arcsin_Ici.1 h.differentiable_within_at,\n  differentiable_within_at_arcsin_Iic.1 h.differentiable_within_at\u27e9,\n  \u03bb h, (has_deriv_at_arcsin h.1 h.2).differentiable_at\u27e9\n\n@[simp] lemma deriv_arcsin : deriv arcsin = \u03bb x, 1 / sqrt (1 - x ^ 2) :=\nbegin\n  funext x,\n  by_cases h : x \u2260 -1 \u2227 x \u2260 1,\n  { exact (has_deriv_at_arcsin h.1 h.2).deriv },\n  { rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_arcsin.1 h)],\n    simp only [not_and_distrib, ne.def, not_not] at h,\n    rcases h with (rfl|rfl); simp }\nend\n\nlemma differentiable_on_arcsin : differentiable_on \u211d arcsin {-1, 1}\u1d9c :=\n\u03bb x hx, (differentiable_at_arcsin.2\n  \u27e8\u03bb h, hx (or.inl h), \u03bb h, hx (or.inr h)\u27e9).differentiable_within_at\n\nlemma times_cont_diff_on_arcsin {n : with_top \u2115} :\n  times_cont_diff_on \u211d n arcsin {-1, 1}\u1d9c :=\n\u03bb x hx, (times_cont_diff_at_arcsin (mt or.inl hx) (mt or.inr hx)).times_cont_diff_within_at\n\nlemma times_cont_diff_at_arcsin_iff {x : \u211d} {n : with_top \u2115} :\n  times_cont_diff_at \u211d n arcsin x \u2194 n = 0 \u2228 (x \u2260 -1 \u2227 x \u2260 1) :=\n\u27e8\u03bb h, or_iff_not_imp_left.2 $ \u03bb hn, differentiable_at_arcsin.1 $ h.differentiable_at $\n  with_top.one_le_iff_pos.2 (pos_iff_ne_zero.2 hn),\n  \u03bb h, h.elim (\u03bb hn, hn.symm \u25b8 (times_cont_diff_zero.2 continuous_arcsin).times_cont_diff_at) $\n    \u03bb hx, times_cont_diff_at_arcsin hx.1 hx.2\u27e9\n\nlemma measurable_arcsin : measurable arcsin := continuous_arcsin.measurable\n\n/-- Inverse of the `cos` function, returns values in the range `0 \u2264 arccos x` and `arccos x \u2264 \u03c0`.\n  If the argument is not between `-1` and `1` it defaults to `\u03c0 / 2` -/\n@[pp_nodot] noncomputable def arccos (x : \u211d) : \u211d :=\n\u03c0 / 2 - arcsin x\n\nlemma arccos_eq_pi_div_two_sub_arcsin (x : \u211d) : arccos x = \u03c0 / 2 - arcsin x := rfl\n\nlemma arcsin_eq_pi_div_two_sub_arccos (x : \u211d) : arcsin x = \u03c0 / 2 - arccos x :=\nby simp [arccos]\n\nlemma arccos_le_pi (x : \u211d) : arccos x \u2264 \u03c0 :=\nby unfold arccos; linarith [neg_pi_div_two_le_arcsin x]\n\nlemma arccos_nonneg (x : \u211d) : 0 \u2264 arccos x :=\nby unfold arccos; linarith [arcsin_le_pi_div_two x]\n\nlemma cos_arccos {x : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) : cos (arccos x) = x :=\nby rw [arccos, cos_pi_div_two_sub, sin_arcsin hx\u2081 hx\u2082]\n\nlemma arccos_cos {x : \u211d} (hx\u2081 : 0 \u2264 x) (hx\u2082 : x \u2264 \u03c0) : arccos (cos x) = x :=\nby rw [arccos, \u2190 sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith\n\nlemma strict_mono_decr_on_arccos : strict_mono_decr_on arccos (Icc (-1) 1) :=\n\u03bb x hx y hy h, sub_lt_sub_left (strict_mono_incr_on_arcsin hx hy h) _\n\nlemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_mono_decr_on_arccos.inj_on\n\nlemma arccos_inj {x y : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) (hy\u2081 : -1 \u2264 y) (hy\u2082 : y \u2264 1) :\n  arccos x = arccos y \u2194 x = y :=\narccos_inj_on.eq_iff \u27e8hx\u2081, hx\u2082\u27e9 \u27e8hy\u2081, hy\u2082\u27e9\n\n@[simp] lemma arccos_zero : arccos 0 = \u03c0 / 2 := by simp [arccos]\n\n@[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos]\n\n@[simp] lemma arccos_neg_one : arccos (-1) = \u03c0 := by simp [arccos, add_halves]\n\n@[simp] lemma arccos_eq_zero {x} : arccos x = 0 \u2194 1 \u2264 x :=\nby simp [arccos, sub_eq_zero]\n\n@[simp] lemma arccos_eq_pi_div_two {x} : arccos x = \u03c0 / 2 \u2194 x = 0 :=\nby simp [arccos, sub_eq_iff_eq_add]\n\n@[simp] lemma arccos_eq_pi {x} : arccos x = \u03c0 \u2194 x \u2264 -1 :=\nby rw [arccos, sub_eq_iff_eq_add, \u2190 sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]\n\nlemma arccos_neg (x : \u211d) : arccos (-x) = \u03c0 - arccos x :=\nby rw [\u2190 add_halves \u03c0, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]\n\nlemma sin_arccos {x : \u211d} (hx\u2081 : -1 \u2264 x) (hx\u2082 : x \u2264 1) : sin (arccos x) = sqrt (1 - x ^ 2) :=\nby rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx\u2081 hx\u2082]\n\n@[continuity]\nlemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin\n\nlemma has_strict_deriv_at_arccos {x : \u211d} (h\u2081 : x \u2260 -1) (h\u2082 : x \u2260 1) :\n  has_strict_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=\n(has_strict_deriv_at_arcsin h\u2081 h\u2082).const_sub (\u03c0 / 2)\n\nlemma has_deriv_at_arccos {x : \u211d} (h\u2081 : x \u2260 -1) (h\u2082 : x \u2260 1) :\n  has_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=\n(has_deriv_at_arcsin h\u2081 h\u2082).const_sub (\u03c0 / 2)\n\nlemma times_cont_diff_at_arccos {x : \u211d} (h\u2081 : x \u2260 -1) (h\u2082 : x \u2260 1) {n : with_top \u2115} :\n  times_cont_diff_at \u211d n arccos x :=\ntimes_cont_diff_at_const.sub (times_cont_diff_at_arcsin h\u2081 h\u2082)\n\nlemma has_deriv_within_at_arccos_Ici {x : \u211d} (h : x \u2260 -1) :\n  has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Ici x) x :=\n(has_deriv_within_at_arcsin_Ici h).const_sub _\n\nlemma has_deriv_within_at_arccos_Iic {x : \u211d} (h : x \u2260 1) :\n  has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Iic x) x :=\n(has_deriv_within_at_arcsin_Iic h).const_sub _\n\nlemma differentiable_within_at_arccos_Ici {x : \u211d} :\n  differentiable_within_at \u211d arccos (Ici x) x \u2194 x \u2260 -1 :=\n(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Ici\n\nlemma differentiable_within_at_arccos_Iic {x : \u211d} :\n  differentiable_within_at \u211d arccos (Iic x) x \u2194 x \u2260 1 :=\n(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Iic\n\nlemma differentiable_at_arccos {x : \u211d} :\n  differentiable_at \u211d arccos x \u2194 x \u2260 -1 \u2227 x \u2260 1 :=\n(differentiable_at_const_sub_iff _).trans differentiable_at_arcsin\n\n@[simp] lemma deriv_arccos : deriv arccos = \u03bb x, -(1 / sqrt (1 - x ^ 2)) :=\nfunext $ \u03bb x, (deriv_const_sub _).trans $ by simp only [deriv_arcsin]\n\nlemma differentiable_on_arccos : differentiable_on \u211d arccos {-1, 1}\u1d9c :=\ndifferentiable_on_arcsin.const_sub _\n\nlemma times_cont_diff_on_arccos {n : with_top \u2115} :\n  times_cont_diff_on \u211d n arccos {-1, 1}\u1d9c :=\ntimes_cont_diff_on_const.sub times_cont_diff_on_arcsin\n\nlemma times_cont_diff_at_arccos_iff {x : \u211d} {n : with_top \u2115} :\n  times_cont_diff_at \u211d n arccos x \u2194 n = 0 \u2228 (x \u2260 -1 \u2227 x \u2260 1) :=\nby refine iff.trans \u27e8\u03bb h, _, \u03bb h, _\u27e9 times_cont_diff_at_arcsin_iff;\n  simpa [arccos] using (@times_cont_diff_at_const _ _ _ _ _ _ _ _ _ _ (\u03c0 / 2)).sub h\n\nlemma measurable_arccos : measurable arccos := continuous_arccos.measurable\n\n@[simp] lemma tan_pi_div_four : tan (\u03c0 / 4) = 1 :=\nbegin\n  rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four],\n  have h : (sqrt 2) / 2 > 0 := by cancel_denoms,\n  exact div_self (ne_of_gt h),\nend\n\n@[simp] lemma tan_pi_div_two : tan (\u03c0 / 2) = 0 := by simp [tan_eq_sin_div_cos]\n\nlemma tan_pos_of_pos_of_lt_pi_div_two {x : \u211d} (h0x : 0 < x) (hxp : x < \u03c0 / 2) : 0 < tan x :=\nby rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))\n  (cos_pos_of_mem_Ioo \u27e8by linarith, hxp\u27e9)\n\nlemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : \u211d} (h0x : 0 \u2264 x) (hxp : x \u2264 \u03c0 / 2) : 0 \u2264 tan x :=\nmatch lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with\n| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)\n| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]\n| or.inr hx0, _          := by simp [hx0.symm]\nend\n\nlemma tan_neg_of_neg_of_pi_div_two_lt {x : \u211d} (hx0 : x < 0) (hpx : -(\u03c0 / 2) < x) : tan x < 0 :=\nneg_pos.1 (tan_neg x \u25b8 tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))\n\nlemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : \u211d} (hx0 : x \u2264 0) (hpx : -(\u03c0 / 2) \u2264 x) :\n  tan x \u2264 0 :=\nneg_nonneg.1 (tan_neg x \u25b8 tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))\n\nlemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : \u211d}\n  (hx\u2081 : 0 \u2264 x) (hy\u2082 : y < \u03c0 / 2) (hxy : x < y) :\n  tan x < tan y :=\nbegin\n  rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],\n  exact div_lt_div\n    (sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy\u2082) hxy)\n    (cos_le_cos_of_nonneg_of_le_pi hx\u2081 (by linarith) (le_of_lt hxy))\n    (sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))\n    (cos_pos_of_mem_Ioo \u27e8by linarith, hy\u2082\u27e9)\nend\n\nlemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : \u211d} (hx\u2081 : -(\u03c0 / 2) < x)\n (hy\u2082 : y < \u03c0 / 2) (hxy : x < y) : tan x < tan y :=\nmatch le_total x 0, le_total y 0 with\n| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [\u2190 tan_neg, \u2190 tan_neg]; exact\n  tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0)\n    (neg_lt.2 hx\u2081) (neg_lt_neg hxy)\n| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim\n  (\u03bb hy0, calc tan x \u2264 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx\u2081)\n    ... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy\u2082)\n  (\u03bb hy0, by rw [\u2190 hy0, tan_zero]; exact\n    tan_neg_of_neg_of_pi_div_two_lt (hy0.symm \u25b8 hxy) hx\u2081)\n| or.inr hx0, or.inl hy0 := by linarith\n| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy\u2082 hxy\nend\n\nlemma strict_mono_incr_on_tan : strict_mono_incr_on tan (Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) :=\n\u03bb x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2\n\nlemma inj_on_tan : inj_on tan (Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) :=\nstrict_mono_incr_on_tan.inj_on\n\nlemma tan_inj_of_lt_of_lt_pi_div_two {x y : \u211d} (hx\u2081 : -(\u03c0 / 2) < x) (hx\u2082 : x < \u03c0 / 2)\n  (hy\u2081 : -(\u03c0 / 2) < y) (hy\u2082 : y < \u03c0 / 2) (hxy : tan x = tan y) : x = y :=\ninj_on_tan \u27e8hx\u2081, hx\u2082\u27e9 \u27e8hy\u2081, hy\u2082\u27e9 hxy\n\nend real\n\nnamespace complex\n\nopen_locale real\n\n/-- `arg` returns values in the range (-\u03c0, \u03c0], such that for `x \u2260 0`,\n  `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,\n  `arg 0` defaults to `0` -/\nnoncomputable def arg (x : \u2102) : \u211d :=\nif 0 \u2264 x.re\nthen real.arcsin (x.im / x.abs)\nelse if 0 \u2264 x.im\nthen real.arcsin ((-x).im / x.abs) + \u03c0\nelse real.arcsin ((-x).im / x.abs) - \u03c0\n\nlemma measurable_arg : measurable arg :=\nhave A : measurable (\u03bb x : \u2102, real.arcsin (x.im / x.abs)),\n  from real.measurable_arcsin.comp (measurable_im.div measurable_norm),\nhave B : measurable (\u03bb x : \u2102, real.arcsin ((-x).im / x.abs)),\n  from real.measurable_arcsin.comp ((measurable_im.comp measurable_neg).div measurable_norm),\nmeasurable.ite (is_closed_le continuous_const continuous_re).measurable_set A $\n  measurable.ite (is_closed_le continuous_const continuous_im).measurable_set\n    (B.add_const _) (B.sub_const _)\n\nlemma arg_le_pi (x : \u2102) : arg x \u2264 \u03c0 :=\nif hx\u2081 : 0 \u2264 x.re\nthen by rw [arg, if_pos hx\u2081];\n  exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos))\nelse\n  if hx\u2082 : 0 \u2264 x.im\n  then by rw [arg, if_neg hx\u2081, if_pos hx\u2082, \u2190 le_sub_iff_add_le, sub_self, real.arcsin_nonpos,\n    neg_im, neg_div, neg_nonpos];\n        exact div_nonneg hx\u2082 (abs_nonneg _)\n  else by rw [arg, if_neg hx\u2081, if_neg hx\u2082];\n      exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _)\n        (by linarith [real.pi_pos]))\n\nlemma neg_pi_lt_arg (x : \u2102) : -\u03c0 < arg x :=\nif hx\u2081 : 0 \u2264 x.re\nthen by rw [arg, if_pos hx\u2081];\n  exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _)\nelse\n  have hx : x \u2260 0, from \u03bb h, by simpa [h, lt_irrefl] using hx\u2081,\n  if hx\u2082 : 0 \u2264 x.im\n  then by rw [arg, if_neg hx\u2081, if_pos hx\u2082, \u2190 sub_lt_iff_lt_add];\n    exact (lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _))\n  else by rw [arg, if_neg hx\u2081, if_neg hx\u2082, lt_sub_iff_add_lt, neg_add_self, real.arcsin_pos,\n    neg_im];\n      exact div_pos (neg_pos.2 (lt_of_not_ge hx\u2082)) (abs_pos.2 hx)\n\nlemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : \u2102} (hxr : x.re < 0) (hxi : 0 \u2264 x.im) :\n  arg x = arg (-x) + \u03c0 :=\nhave 0 \u2264 (-x).re, from le_of_lt $ by simpa [neg_pos],\nby rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg]\n\nlemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : \u2102} (hxr : x.re < 0) (hxi : x.im < 0) :\n  arg x = arg (-x) - \u03c0 :=\nhave 0 \u2264 (-x).re, from le_of_lt $ by simpa [neg_pos],\nby rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg]\n\n@[simp] lemma arg_zero : arg 0 = 0 :=\nby simp [arg, le_refl]\n\n@[simp] lemma arg_one : arg 1 = 0 :=\nby simp [arg, zero_le_one]\n\n@[simp] lemma arg_neg_one : arg (-1) = \u03c0 :=\nby simp [arg, le_refl, not_le.2 (@zero_lt_one \u211d _ _)]\n\n@[simp] lemma arg_I : arg I = \u03c0 / 2 :=\nby simp [arg, le_refl]\n\n@[simp] lemma arg_neg_I : arg (-I) = -(\u03c0 / 2) :=\nby simp [arg, le_refl]\n\nlemma sin_arg (x : \u2102) : real.sin (arg x) = x.im / x.abs :=\nby unfold arg; split_ifs;\n  simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1\n    (abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg,\n    real.sin_neg]\n\nprivate lemma cos_arg_of_re_nonneg {x : \u2102} (hx : x \u2260 0) (hxr : 0 \u2264 x.re) :\n  real.cos (arg x) = x.re / x.abs :=\nhave 0 \u2264 1 - (x.im / abs x) ^ 2,\n  from sub_nonneg.2 $ by rw [sq, \u2190 _root_.abs_mul_self, _root_.abs_mul, \u2190 sq];\n  exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _),\nby rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), \u2190 real.mul_self_sqrt (abs_nonneg x),\n    arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1\n    (abs_le.1 (abs_im_div_abs_le_one x)).2, \u2190 real.sqrt_mul (abs_nonneg _), \u2190 real.sqrt_mul this,\n    sub_mul, div_pow, \u2190 sq, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)),\n    one_mul, sq, mul_self_abs, norm_sq_apply, sq, add_sub_cancel, real.sqrt_mul_self hxr]\n\nlemma cos_arg {x : \u2102} (hx : x \u2260 0) : real.cos (arg x) = x.re / x.abs :=\nif hxr : 0 \u2264 x.re then cos_arg_of_re_nonneg hx hxr\nelse\n  have 0 \u2264 (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,\n  if hxi : 0 \u2264 x.im\n  then have 0 \u2264 (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,\n    by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi,\n        cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this];\n      simp [neg_div]\n  else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)];\n    simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]\n\nlemma tan_arg {x : \u2102} : real.tan (arg x) = x.im / x.re :=\nbegin\n  by_cases h : x = 0,\n  { simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },\n  rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,\n      div_div_div_cancel_right _ (mt abs_eq_zero.1 h)]\nend\n\nlemma arg_cos_add_sin_mul_I {x : \u211d} (hx\u2081 : -\u03c0 < x) (hx\u2082 : x \u2264 \u03c0) :\n  arg (cos x + sin x * I) = x :=\nif hx\u2083 : -(\u03c0 / 2) \u2264 x \u2227 x \u2264 \u03c0 / 2\nthen\n  have hx\u2084 : 0 \u2264 (cos x + sin x * I).re,\n    by simp; exact real.cos_nonneg_of_mem_Icc hx\u2083,\n  by rw [arg, if_pos hx\u2084];\n    simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx\u2083.1 hx\u2083.2]\nelse if hx\u2084 : x < -(\u03c0 / 2)\nthen\n  have hx\u2085 : \u00ac0 \u2264 (cos x + sin x * I).re :=\n    suffices \u00ac 0 \u2264 real.cos x, by simpa,\n    not_le.2 $ by rw \u2190 real.cos_neg;\n      apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,\n  have hx\u2086 : \u00ac0 \u2264 (cos \u2191x + sin \u2191x * I).im :=\n    suffices real.sin x < 0, by simpa,\n    by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith,\n  suffices -\u03c0 + -real.arcsin (real.sin x) = x,\n    by rw [arg, if_neg hx\u2085, if_neg hx\u2086];\n    simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],\n  by rw [\u2190 real.arcsin_neg, \u2190 real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]};\n    linarith\nelse\n  have hx\u2085 : \u03c0 / 2 < x, by cases not_and_distrib.1 hx\u2083; linarith,\n  have hx\u2086 : \u00ac0 \u2264 (cos x + sin x * I).re :=\n    suffices \u00ac0 \u2264 real.cos x, by simpa,\n    not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,\n  have hx\u2087 : 0 \u2264 (cos x + sin x * I).im :=\n    suffices 0 \u2264 real.sin x, by simpa,\n    by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith,\n  suffices \u03c0 - real.arcsin (real.sin x) = x,\n    by rw [arg, if_neg hx\u2086, if_pos hx\u2087];\n      simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],\n  by rw [\u2190 real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith\n\nlemma arg_eq_arg_iff {x y : \u2102} (hx : x \u2260 0) (hy : y \u2260 0) :\n  arg x = arg y \u2194 (abs y / abs x : \u2102) * x = y :=\nhave hax : abs x \u2260 0, from (mt abs_eq_zero.1 hx),\nhave hay : abs y \u2260 0, from (mt abs_eq_zero.1 hy),\n\u27e8\u03bb h,\n  begin\n    have hcos := congr_arg real.cos h,\n    rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos,\n    have hsin := congr_arg real.sin h,\n    rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin,\n    apply complex.ext,\n    { rw [mul_re, \u2190 of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm,\n        \u2190 mul_div_assoc, hcos, mul_div_cancel _ hax] },\n    { rw [mul_im, \u2190 of_real_div, of_real_re, of_real_im, zero_mul, add_zero,\n        mul_comm, \u2190 mul_div_assoc, hsin, mul_div_cancel _ hax] }\n  end,\n\u03bb h,\n  have hre : abs (y / x) * x.re = y.re,\n    by rw \u2190 of_real_div at h;\n      simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg re h,\n  have hre' : abs (x / y) * y.re = x.re,\n    by rw [\u2190 hre, abs_div, abs_div, \u2190 mul_assoc, div_mul_div,\n      mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],\n  have him : abs (y / x) * x.im = y.im,\n    by rw \u2190 of_real_div at h;\n      simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg im h,\n  have him' : abs (x / y) * y.im = x.im,\n    by rw [\u2190 him, abs_div, abs_div, \u2190 mul_assoc, div_mul_div,\n      mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],\n  have hxya : x.im / abs x = y.im / abs y,\n    by rw [\u2190 him, abs_div, mul_comm, \u2190 mul_div_comm, mul_div_cancel_left _ hay],\n  have hnxya : (-x).im / abs x = (-y).im / abs y,\n    by rw [neg_im, neg_im, neg_div, neg_div, hxya],\n  if hxr : 0 \u2264 x.re\n  then\n    have hyr : 0 \u2264 y.re, from hre \u25b8 mul_nonneg (abs_nonneg _) hxr,\n    by simp [arg, *] at *\n  else\n    have hyr : \u00ac 0 \u2264 y.re, from \u03bb hyr, hxr $ hre' \u25b8 mul_nonneg (abs_nonneg _) hyr,\n    if hxi : 0 \u2264 x.im\n    then\n      have hyi : 0 \u2264 y.im, from him \u25b8 mul_nonneg (abs_nonneg _) hxi,\n      by simp [arg, *] at *\n    else\n      have hyi : \u00ac 0 \u2264 y.im, from \u03bb hyi, hxi $ him' \u25b8 mul_nonneg (abs_nonneg _) hyi,\n      by simp [arg, *] at *\u27e9\n\nlemma arg_real_mul (x : \u2102) {r : \u211d} (hr : 0 < r) : arg (r * x) = arg x :=\nif hx : x = 0 then by simp [hx]\nelse (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $\n  by rw [abs_mul, abs_of_nonneg (le_of_lt hr), \u2190 mul_assoc,\n    of_real_mul, mul_comm (r : \u2102), \u2190 div_div_eq_div_mul,\n    div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm),\n    div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul]\n\nlemma ext_abs_arg {x y : \u2102} (h\u2081 : x.abs = y.abs) (h\u2082 : x.arg = y.arg) : x = y :=\nif hy : y = 0 then by simp * at *\nelse have hx : x \u2260 0, from \u03bb hx, by simp [*, eq_comm] at *,\n  by rwa [arg_eq_arg_iff hx hy, h\u2081, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul]\n    at h\u2082\n\nlemma arg_of_real_of_nonneg {x : \u211d} (hx : 0 \u2264 x) : arg x = 0 :=\nby simp [arg, hx]\n\nlemma arg_eq_pi_iff {z : \u2102} : arg z = \u03c0 \u2194 z.re < 0 \u2227 z.im = 0 :=\nbegin\n  by_cases h\u2080 : z = 0, { simp [h\u2080, lt_irrefl, real.pi_ne_zero.symm] },\n  have h\u2080' : (abs z : \u2102) \u2260 0, by simpa,\n  rw [\u2190 arg_neg_one, arg_eq_arg_iff h\u2080 (neg_ne_zero.2 one_ne_zero), abs_neg, abs_one,\n    of_real_one, one_div, \u2190 div_eq_inv_mul, div_eq_iff_mul_eq h\u2080', neg_one_mul,\n    ext_iff, neg_im, of_real_im, neg_zero, @eq_comm _ z.im, and.congr_left_iff],\n  rcases z with \u27e8x, y\u27e9, simp only,\n  rintro rfl,\n  simp only [\u2190 of_real_def, of_real_eq_zero] at *,\n  simp [\u2190 ne.le_iff_lt h\u2080, @neg_eq_iff_neg_eq _ _ _ x, @eq_comm _ (-x)]\nend\n\nlemma arg_of_real_of_neg {x : \u211d} (hx : x < 0) : arg x = \u03c0 :=\narg_eq_pi_iff.2 \u27e8hx, rfl\u27e9\n\n/-- Inverse of the `exp` function. Returns values such that `(log x).im > - \u03c0` and `(log x).im \u2264 \u03c0`.\n  `log 0 = 0`-/\n@[pp_nodot] noncomputable def log (x : \u2102) : \u2102 := x.abs.log + arg x * I\n\nlemma measurable_log : measurable log :=\n(measurable_of_real.comp $ real.measurable_log.comp measurable_norm).add $\n  (measurable_of_real.comp measurable_arg).mul_const I\n\nlemma log_re (x : \u2102) : x.log.re = x.abs.log := by simp [log]\n\nlemma log_im (x : \u2102) : x.log.im = x.arg := by simp [log]\n\nlemma neg_pi_lt_log_im (x : \u2102) : -\u03c0 < (log x).im := by simp only [log_im, neg_pi_lt_arg]\nlemma log_im_le_pi (x : \u2102) : (log x).im \u2264 \u03c0 := by simp only [log_im, arg_le_pi]\n\nlemma exp_log {x : \u2102} (hx : x \u2260 0) : exp (log x) = x :=\nby rw [log, exp_add_mul_I, \u2190 of_real_sin, sin_arg, \u2190 of_real_cos, cos_arg hx,\n  \u2190 of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,\n  mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), \u2190 mul_assoc,\n  mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]\n\nlemma range_exp : range exp = {x | x \u2260 0} :=\nset.ext $ \u03bb x, \u27e8by { rintro \u27e8x, rfl\u27e9, exact exp_ne_zero x }, \u03bb hx, \u27e8log x, exp_log hx\u27e9\u27e9\n\nlemma exp_inj_of_neg_pi_lt_of_le_pi {x y : \u2102} (hx\u2081 : -\u03c0 < x.im) (hx\u2082 : x.im \u2264 \u03c0)\n  (hy\u2081 : - \u03c0 < y.im) (hy\u2082 : y.im \u2264 \u03c0) (hxy : exp x = exp y) : x = y :=\nby rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy;\n  exact complex.ext\n    (real.exp_injective $\n      by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy)\n    (by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _),\n      arg_cos_add_sin_mul_I hx\u2081 hx\u2082, arg_cos_add_sin_mul_I hy\u2081 hy\u2082] using congr_arg arg hxy)\n\nlemma log_exp {x : \u2102} (hx\u2081 : -\u03c0 < x.im) (hx\u2082: x.im \u2264 \u03c0) : log (exp x) = x :=\nexp_inj_of_neg_pi_lt_of_le_pi\n  (by rw log_im; exact neg_pi_lt_arg _)\n  (by rw log_im; exact arg_le_pi _)\n  hx\u2081 hx\u2082 (by rw [exp_log (exp_ne_zero _)])\n\nlemma of_real_log {x : \u211d} (hx : 0 \u2264 x) : (x.log : \u2102) = log x :=\ncomplex.ext\n  (by rw [log_re, of_real_re, abs_of_nonneg hx])\n  (by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])\n\nlemma log_of_real_re (x : \u211d) : (log (x : \u2102)).re = real.log x := by simp [log_re]\n\n@[simp] lemma log_zero : log 0 = 0 := by simp [log]\n\n@[simp] lemma log_one : log 1 = 0 := by simp [log]\n\nlemma log_neg_one : log (-1) = \u03c0 * I := by simp [log]\n\nlemma log_I : log I = \u03c0 / 2 * I := by simp [log]\n\nlemma log_neg_I : log (-I) = -(\u03c0 / 2) * I := by simp [log]\n\nlemma exists_pow_nat_eq (x : \u2102) {n : \u2115} (hn : 0 < n) : \u2203 z, z ^ n = x :=\nbegin\n  by_cases hx : x = 0,\n  { use 0, simp only [hx, zero_pow_eq_zero, hn] },\n  { use exp (log x / n),\n    rw [\u2190 exp_nat_mul, mul_div_cancel', exp_log hx],\n    exact_mod_cast (pos_iff_ne_zero.mp hn) }\nend\n\nlemma exists_eq_mul_self (x : \u2102) : \u2203 z, x = z * z :=\nbegin\n  obtain \u27e8z, rfl\u27e9 := exists_pow_nat_eq x zero_lt_two,\n  exact \u27e8z, sq z\u27e9\nend\n\nlemma two_pi_I_ne_zero : (2 * \u03c0 * I : \u2102) \u2260 0 :=\nby norm_num [real.pi_ne_zero, I_ne_zero]\n\nlemma exp_eq_one_iff {x : \u2102} : exp x = 1 \u2194 \u2203 n : \u2124, x = n * ((2 * \u03c0) * I) :=\nhave real.exp (x.re) * real.cos (x.im) = 1 \u2192 real.cos x.im \u2260 -1,\n  from \u03bb h\u2081 h\u2082, begin\n    rw [h\u2082, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h\u2081,\n    have := real.exp_pos x.re,\n    rw \u2190 h\u2081 at this,\n    exact absurd this (by norm_num)\n  end,\ncalc exp x = 1 \u2194 (exp x).re = 1 \u2227 (exp x).im = 0 : by simp [complex.ext_iff]\n  ... \u2194 real.cos x.im = 1 \u2227 real.sin x.im = 0 \u2227 x.re = 0 :\n    begin\n      rw exp_eq_exp_re_mul_sin_add_cos,\n      simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re,\n        real.exp_ne_zero],\n      split; finish [real.sin_eq_zero_iff_cos_eq]\n    end\n  ... \u2194 (\u2203 n : \u2124, \u2191n * (2 * \u03c0) = x.im) \u2227 (\u2203 n : \u2124, \u2191n * \u03c0 = x.im) \u2227 x.re = 0 :\n    by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff]\n  ... \u2194 \u2203 n : \u2124, x = n * ((2 * \u03c0) * I) :\n    \u27e8\u03bb \u27e8\u27e8n, hn\u27e9, \u27e8m, hm\u27e9, h\u27e9, \u27e8n, by simp [complex.ext_iff, hn.symm, h]\u27e9,\n      \u03bb \u27e8n, hn\u27e9, \u27e8\u27e8n, by simp [hn]\u27e9, \u27e82 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]\u27e9,\n        by simp [hn]\u27e9\u27e9\n\nlemma exp_eq_exp_iff_exp_sub_eq_one {x y : \u2102} : exp x = exp y \u2194 exp (x - y) = 1 :=\nby rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]\n\nlemma exp_eq_exp_iff_exists_int {x y : \u2102} : exp x = exp y \u2194 \u2203 n : \u2124, x = y + n * ((2 * \u03c0) * I) :=\nby simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']\n\n/-- `complex.exp` as a `local_homeomorph` with `source = {z | -\u03c0 < im z < \u03c0}` and\n`target = {z | 0 < re z} \u222a {z | im z \u2260 0}`. This definition is used to prove that `complex.log`\nis complex differentiable at all points but the negative real semi-axis. -/\ndef exp_local_homeomorph : local_homeomorph \u2102 \u2102 :=\nlocal_homeomorph.of_continuous_open\n{ to_fun := exp,\n  inv_fun := log,\n  source := {z : \u2102 | z.im \u2208 Ioo (- \u03c0) \u03c0},\n  target := {z : \u2102 | 0 < z.re} \u222a {z : \u2102 | z.im \u2260 0},\n  map_source' :=\n    begin\n      rintro \u27e8x, y\u27e9 \u27e8h\u2081 : -\u03c0 < y, h\u2082 : y < \u03c0\u27e9,\n      refine (not_or_of_imp $ \u03bb hz, _).symm,\n      obtain rfl : y = 0,\n      { rw exp_im at hz,\n        simpa [(real.exp_pos _).ne', real.sin_eq_zero_iff_of_lt_of_lt h\u2081 h\u2082] using hz },\n      rw [mem_set_of_eq, \u2190 of_real_def, exp_of_real_re],\n      exact real.exp_pos x\n    end,\n  map_target' := \u03bb z h,\n    suffices 0 \u2264 z.re \u2228 z.im \u2260 0,\n      by simpa [log_im, neg_pi_lt_arg, (arg_le_pi _).lt_iff_ne, arg_eq_pi_iff, not_and_distrib],\n    h.imp (\u03bb h, le_of_lt h) id,\n  left_inv' := \u03bb x hx, log_exp hx.1 (le_of_lt hx.2),\n  right_inv' := \u03bb x hx, exp_log $ by { rintro rfl, simpa [lt_irrefl] using hx } }\ncontinuous_exp.continuous_on is_open_map_exp (is_open_Ioo.preimage continuous_im)\n\nlemma has_strict_deriv_at_log {x : \u2102} (h : 0 < x.re \u2228 x.im \u2260 0) :\n  has_strict_deriv_at log x\u207b\u00b9 x :=\nhave h0 :  x \u2260 0, by { rintro rfl, simpa [lt_irrefl] using h },\nexp_local_homeomorph.has_strict_deriv_at_symm h h0 $\n  by simpa [exp_log h0] using has_strict_deriv_at_exp (log x)\n\nlemma times_cont_diff_at_log {x : \u2102} (h : 0 < x.re \u2228 x.im \u2260 0) {n : with_top \u2115} :\n  times_cont_diff_at \u2102 n log x :=\nexp_local_homeomorph.times_cont_diff_at_symm_deriv (exp_ne_zero $ log x) h\n  (has_deriv_at_exp _) times_cont_diff_exp.times_cont_diff_at\n\n@[simp] lemma cos_pi_div_two : cos (\u03c0 / 2) = 0 :=\ncalc cos (\u03c0 / 2) = real.cos (\u03c0 / 2) : by rw [of_real_cos]; simp\n... = 0 : by simp\n\n@[simp] lemma sin_pi_div_two : sin (\u03c0 / 2) = 1 :=\ncalc sin (\u03c0 / 2) = real.sin (\u03c0 / 2) : by rw [of_real_sin]; simp\n... = 1 : by simp\n\n@[simp] lemma sin_pi : sin \u03c0 = 0 :=\nby rw [\u2190 of_real_sin, real.sin_pi]; simp\n\n@[simp] lemma cos_pi : cos \u03c0 = -1 :=\nby rw [\u2190 of_real_cos, real.cos_pi]; simp\n\n@[simp] lemma sin_two_pi : sin (2 * \u03c0) = 0 :=\nby simp [two_mul, sin_add]\n\n@[simp] lemma cos_two_pi : cos (2 * \u03c0) = 1 :=\nby simp [two_mul, cos_add]\n\nlemma sin_add_pi (x : \u2102) : sin (x + \u03c0) = -sin x :=\nby simp [sin_add]\n\nlemma sin_add_two_pi (x : \u2102) : sin (x + 2 * \u03c0) = sin x :=\nby simp [sin_add]\n\nlemma cos_add_two_pi (x : \u2102) : cos (x + 2 * \u03c0) = cos x :=\nby simp [cos_add]\n\nlemma sin_pi_sub (x : \u2102) : sin (\u03c0 - x) = sin x :=\nby simp [sub_eq_add_neg, sin_add]\n\nlemma cos_add_pi (x : \u2102) : cos (x + \u03c0) = -cos x :=\nby simp [cos_add]\n\nlemma cos_pi_sub (x : \u2102) : cos (\u03c0 - x) = -cos x :=\nby simp [sub_eq_add_neg, cos_add]\n\nlemma sin_add_pi_div_two (x : \u2102) : sin (x + \u03c0 / 2) = cos x :=\nby simp [sin_add]\n\nlemma sin_sub_pi_div_two (x : \u2102) : sin (x - \u03c0 / 2) = -cos x :=\nby simp [sub_eq_add_neg, sin_add]\n\nlemma sin_pi_div_two_sub (x : \u2102) : sin (\u03c0 / 2 - x) = cos x :=\nby simp [sub_eq_add_neg, sin_add]\n\nlemma cos_add_pi_div_two (x : \u2102) : cos (x + \u03c0 / 2) = -sin x :=\nby simp [cos_add]\n\nlemma cos_sub_pi_div_two (x : \u2102) : cos (x - \u03c0 / 2) = sin x :=\nby simp [sub_eq_add_neg, cos_add]\n\nlemma cos_pi_div_two_sub (x : \u2102) : cos (\u03c0 / 2 - x) = sin x :=\nby rw [\u2190 cos_neg, neg_sub, cos_sub_pi_div_two]\n\nlemma sin_nat_mul_pi (n : \u2115) : sin (n * \u03c0) = 0 :=\nby induction n; simp [add_mul, sin_add, *]\n\nlemma sin_int_mul_pi (n : \u2124) : sin (n * \u03c0) = 0 :=\nby cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]\n\nlemma cos_nat_mul_two_pi (n : \u2115) : cos (n * (2 * \u03c0)) = 1 :=\nby induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]\n\nlemma cos_int_mul_two_pi (n : \u2124) : cos (n * (2 * \u03c0)) = 1 :=\nby cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,\n  int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,\n  (neg_mul_eq_neg_mul _ _).symm, cos_neg]\n\nlemma cos_int_mul_two_pi_add_pi (n : \u2124) : cos (n * (2 * \u03c0) + \u03c0) = -1 :=\nby simp [cos_add, sin_add, cos_int_mul_two_pi]\n\nlemma exp_pi_mul_I : exp (\u03c0 * I) = -1 :=\nby rw exp_mul_I; simp\n\ntheorem cos_eq_zero_iff {\u03b8 : \u2102} : cos \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = (2 * k + 1) * \u03c0 / 2 :=\nbegin\n  have h : (exp (\u03b8 * I) + exp (-\u03b8 * I)) / 2 = 0 \u2194 exp (2 * \u03b8 * I) = -1,\n  { rw [@div_eq_iff _ _ (exp (\u03b8 * I) + exp (-\u03b8 * I)) 2 0 two_ne_zero', zero_mul,\n      add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, \u2190 div_eq_iff (exp_ne_zero _), \u2190 exp_sub],\n    field_simp only, congr' 3, ring },\n  rw [cos, h, \u2190 exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm],\n  refine exists_congr (\u03bb x, _),\n  refine (iff_of_eq $ congr_arg _ _).trans (mul_right_inj' $ mul_ne_zero two_ne_zero' I_ne_zero),\n  ring,\nend\n\ntheorem cos_ne_zero_iff {\u03b8 : \u2102} : cos \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 (2 * k + 1) * \u03c0 / 2 :=\nby rw [\u2190 not_exists, not_iff_not, cos_eq_zero_iff]\n\ntheorem sin_eq_zero_iff {\u03b8 : \u2102} : sin \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = k * \u03c0 :=\nbegin\n  rw [\u2190 complex.cos_sub_pi_div_two, cos_eq_zero_iff],\n  split,\n  { rintros \u27e8k, hk\u27e9,\n    use k + 1,\n    field_simp [eq_add_of_sub_eq hk],\n    ring },\n  { rintros \u27e8k, rfl\u27e9,\n    use k - 1,\n    field_simp,\n    ring }\nend\n\ntheorem sin_ne_zero_iff {\u03b8 : \u2102} : sin \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 k * \u03c0 :=\nby rw [\u2190 not_exists, not_iff_not, sin_eq_zero_iff]\n\nlemma sin_eq_zero_iff_cos_eq {z : \u2102} : sin z = 0 \u2194 cos z = 1 \u2228 cos z = -1 :=\nby rw [\u2190 mul_self_eq_one_iff, \u2190 sin_sq_add_cos_sq, sq, sq, \u2190 sub_eq_iff_eq_add, sub_self];\n  exact \u27e8\u03bb h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero \u2218 eq.symm\u27e9\n\nlemma tan_eq_zero_iff {\u03b8 : \u2102} : tan \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = k * \u03c0 / 2 :=\nbegin\n  have h := (sin_two_mul \u03b8).symm,\n  rw mul_assoc at h,\n  rw [tan, div_eq_zero_iff, \u2190 mul_eq_zero, \u2190 zero_mul ((1/2):\u2102), mul_one_div,\n      cancel_factors.cancel_factors_eq_div h two_ne_zero', mul_comm],\n  simpa only [zero_div, zero_mul, ne.def, not_false_iff] with field_simps using sin_eq_zero_iff,\nend\n\nlemma tan_ne_zero_iff {\u03b8 : \u2102} : tan \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 k * \u03c0 / 2 :=\nby rw [\u2190 not_exists, not_iff_not, tan_eq_zero_iff]\n\nlemma tan_int_mul_pi_div_two (n : \u2124) : tan (n * \u03c0/2) = 0 :=\ntan_eq_zero_iff.mpr (by use n)\n\nlemma tan_int_mul_pi (n : \u2124) : tan (n * \u03c0) = 0 :=\nby simp [tan, add_mul, sin_add, sin_int_mul_pi]\n\nlemma cos_eq_cos_iff {x y : \u2102} :\n  cos x = cos y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = 2 * k * \u03c0 - x :=\ncalc cos x = cos y \u2194 cos x - cos y = 0 : sub_eq_zero.symm\n... \u2194 -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos\n... \u2194 sin((x + y)/2) = 0 \u2228 sin((x - y)/2) = 0 : by simp [(by norm_num : (2:\u2102) \u2260 0)]\n... \u2194 sin((x - y)/2) = 0 \u2228 sin((x + y)/2) = 0 : or.comm\n... \u2194 (\u2203 k : \u2124, y = 2 * k * \u03c0 + x) \u2228 (\u2203 k :\u2124, y = 2 * k * \u03c0 - x) :\nbegin\n  apply or_congr;\n    field_simp [sin_eq_zero_iff, (by norm_num : -(2:\u2102) \u2260 0), eq_sub_iff_add_eq',\n      sub_eq_iff_eq_add, mul_comm (2:\u2102), mul_right_comm _ (2:\u2102)],\n  split; { rintros \u27e8k, rfl\u27e9, use -k, simp, },\nend\n... \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = 2 * k * \u03c0 - x : exists_or_distrib.symm\n\nlemma sin_eq_sin_iff {x y : \u2102} :\n  sin x = sin y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = (2 * k + 1) * \u03c0 - x :=\nbegin\n  simp only [\u2190 complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add],\n  refine exists_congr (\u03bb k, or_congr _ _); refine eq.congr rfl _; field_simp; ring\nend\n\nlemma tan_add {x y : \u2102}\n  (h : ((\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y \u2260 (2 * l + 1) * \u03c0 / 2)\n     \u2228 ((\u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 2) \u2227 \u2203 l : \u2124, y = (2 * l + 1) * \u03c0 / 2)) :\n  tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=\nbegin\n  rcases h with \u27e8h1, h2\u27e9 | \u27e8\u27e8k, rfl\u27e9, \u27e8l, rfl\u27e9\u27e9,\n  { rw [tan, sin_add, cos_add,\n        \u2190 div_div_div_cancel_right (sin x * cos y + cos x * sin y)\n            (mul_ne_zero (cos_ne_zero_iff.mpr h1) (cos_ne_zero_iff.mpr h2)),\n        add_div, sub_div],\n    simp only [\u2190div_mul_div, \u2190tan, mul_one, one_mul,\n              div_self (cos_ne_zero_iff.mpr h1), div_self (cos_ne_zero_iff.mpr h2)] },\n  { obtain \u27e8t, hx, hy, hxy\u27e9 := \u27e8tan_int_mul_pi_div_two, t (2*k+1), t (2*l+1), t (2*k+1+(2*l+1))\u27e9,\n    simp only [int.cast_add, int.cast_bit0, int.cast_mul, int.cast_one, hx, hy] at hx hy hxy,\n    rw [hx, hy, add_zero, zero_div,\n        mul_div_assoc, mul_div_assoc, \u2190 add_mul (2*(k:\u2102)+1) (2*l+1) (\u03c0/2), \u2190 mul_div_assoc, hxy] },\nend\n\nlemma tan_add' {x y : \u2102}\n  (h : ((\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y \u2260 (2 * l + 1) * \u03c0 / 2)) :\n  tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=\ntan_add (or.inl h)\n\nlemma tan_two_mul {z : \u2102} : tan (2 * z) = 2 * tan z / (1 - tan z ^ 2) :=\nbegin\n  by_cases h : \u2200 k : \u2124, z \u2260 (2 * k + 1) * \u03c0 / 2,\n  { rw [two_mul, two_mul, sq, tan_add (or.inl \u27e8h, h\u27e9)] },\n  { rw not_forall_not at h,\n    rw [two_mul, two_mul, sq, tan_add (or.inr \u27e8h, h\u27e9)] },\nend\n\nlemma tan_add_mul_I {x y : \u2102}\n  (h : ((\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y * I \u2260 (2 * l + 1) * \u03c0 / 2)\n     \u2228 ((\u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 2) \u2227 \u2203 l : \u2124, y * I = (2 * l + 1) * \u03c0 / 2)) :\n  tan (x + y*I) = (tan x + tanh y * I) / (1 - tan x * tanh y * I) :=\nby rw [tan_add h, tan_mul_I, mul_assoc]\n\nlemma tan_eq {z : \u2102}\n  (h : ((\u2200 k : \u2124, (z.re:\u2102) \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, (z.im:\u2102) * I \u2260 (2 * l + 1) * \u03c0 / 2)\n     \u2228 ((\u2203 k : \u2124, (z.re:\u2102) = (2 * k + 1) * \u03c0 / 2) \u2227 \u2203 l : \u2124, (z.im:\u2102) * I = (2 * l + 1) * \u03c0 / 2)) :\n  tan z = (tan z.re + tanh z.im * I) / (1 - tan z.re * tanh z.im * I) :=\nby convert tan_add_mul_I h; exact (re_add_im z).symm\n\nlemma has_strict_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_strict_deriv_at tan (1 / (cos x)^2) x :=\nbegin\n  convert (has_strict_deriv_at_sin x).div (has_strict_deriv_at_cos x) h,\n  rw \u2190 sin_sq_add_cos_sq x,\n  ring,\nend\n\nlemma has_deriv_at_tan {x : \u2102} (h : cos x \u2260 0) :\n  has_deriv_at tan (1 / (cos x)^2) x :=\n(has_strict_deriv_at_tan h).has_deriv_at\n\nlemma tendsto_abs_tan_of_cos_eq_zero {x : \u2102} (hx : cos x = 0) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[{x}\u1d9c] x) at_top :=\nbegin\n  simp only [tan_eq_sin_div_cos, \u2190 norm_eq_abs, normed_field.norm_div],\n  have A : sin x \u2260 0 := \u03bb h, by simpa [*, sq] using sin_sq_add_cos_sq x,\n  have B : tendsto cos (\ud835\udcdd[{x}\u1d9c] (x)) (\ud835\udcdd[{0}\u1d9c] 0),\n  { refine tendsto_inf.2 \u27e8tendsto.mono_left _ inf_le_left, tendsto_principal.2 _\u27e9,\n    exacts [continuous_cos.tendsto' x 0 hx,\n      hx \u25b8 (has_deriv_at_cos _).eventually_ne (neg_ne_zero.2 A)] },\n  exact continuous_sin.continuous_within_at.norm.mul_at_top (norm_pos_iff.2 A)\n    (tendsto_norm_nhds_within_zero.comp B).inv_tendsto_zero,\nend\n\nlemma tendsto_abs_tan_at_top (k : \u2124) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[{(2 * k + 1) * \u03c0 / 2}\u1d9c] ((2 * k + 1) * \u03c0 / 2)) at_top :=\ntendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 \u27e8k, rfl\u27e9\n\n@[simp] lemma continuous_at_tan {x : \u2102} : continuous_at tan x \u2194 cos x \u2260 0 :=\nbegin\n  refine \u27e8\u03bb hc h\u2080, _, \u03bb h, (has_deriv_at_tan h).continuous_at\u27e9,\n  exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h\u2080) _\n    (hc.norm.tendsto.mono_left inf_le_left)\nend\n\n@[simp] lemma differentiable_at_tan {x : \u2102} : differentiable_at \u2102 tan x \u2194 cos x \u2260 0:=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at, \u03bb h, (has_deriv_at_tan h).differentiable_at\u27e9\n\n@[simp] lemma deriv_tan (x : \u2102) : deriv tan x = 1 / (cos x)^2 :=\nif h : cos x = 0 then\n  have \u00acdifferentiable_at \u2102 tan x := mt differentiable_at_tan.1 (not_not.2 h),\n  by simp [deriv_zero_of_not_differentiable_at this, h, sq]\nelse (has_deriv_at_tan h).deriv\n\nlemma continuous_on_tan : continuous_on tan {x | cos x \u2260 0} :=\ncontinuous_on_sin.div continuous_on_cos $ \u03bb x, id\n\n@[continuity]\nlemma continuous_tan : continuous (\u03bb x : {x | cos x \u2260 0}, tan x) :=\ncontinuous_on_iff_continuous_restrict.1 continuous_on_tan\n\n@[simp] lemma times_cont_diff_at_tan {x : \u2102} {n : with_top \u2115} :\n  times_cont_diff_at \u2102 n tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at,\n  times_cont_diff_sin.times_cont_diff_at.div times_cont_diff_cos.times_cont_diff_at\u27e9\n\nlemma cos_eq_iff_quadratic {z w : \u2102} :\n  cos z = w \u2194 (exp (z * I)) ^ 2 - 2 * w * exp (z * I) + 1 = 0 :=\nbegin\n  rw \u2190 sub_eq_zero,\n  field_simp [cos, exp_neg, exp_ne_zero],\n  refine eq.congr _ rfl,\n  ring\nend\n\nlemma cos_surjective : function.surjective cos :=\nbegin\n  intro x,\n  obtain \u27e8w, w\u2080, hw\u27e9 : \u2203 w \u2260 0, 1 * w * w + (-2 * x) * w + 1 = 0,\n  { rcases exists_quadratic_eq_zero one_ne_zero (exists_eq_mul_self _) with \u27e8w, hw\u27e9,\n    refine \u27e8w, _, hw\u27e9,\n    rintro rfl,\n    simpa only [zero_add, one_ne_zero, mul_zero] using hw },\n  refine \u27e8log w / I, cos_eq_iff_quadratic.2 _\u27e9,\n  rw [div_mul_cancel _ I_ne_zero, exp_log w\u2080],\n  convert hw,\n  ring\nend\n\n@[simp] lemma range_cos : range cos = set.univ :=\ncos_surjective.range_eq\n\nlemma sin_surjective : function.surjective sin :=\nbegin\n  intro x,\n  rcases cos_surjective x with \u27e8z, rfl\u27e9,\n  exact \u27e8z + \u03c0 / 2, sin_add_pi_div_two z\u27e9\nend\n\n@[simp] lemma range_sin : range sin = set.univ :=\nsin_surjective.range_eq\n\nend complex\n\nsection log_deriv\n\nopen complex\n\nvariables {\u03b1 : Type*}\n\nlemma measurable.carg [measurable_space \u03b1] {f : \u03b1 \u2192 \u2102} (h : measurable f) :\n  measurable (\u03bb x, arg (f x)) :=\nmeasurable_arg.comp h\n\nlemma measurable.clog [measurable_space \u03b1] {f : \u03b1 \u2192 \u2102} (h : measurable f) :\n  measurable (\u03bb x, log (f x)) :=\nmeasurable_log.comp h\n\nlemma filter.tendsto.clog {l : filter \u03b1} {f : \u03b1 \u2192 \u2102} {x : \u2102} (h : tendsto f l (\ud835\udcdd x))\n  (hx : 0 < x.re \u2228 x.im \u2260 0) :\n  tendsto (\u03bb t, log (f t)) l (\ud835\udcdd $ log x) :=\n(has_strict_deriv_at_log hx).continuous_at.tendsto.comp h\n\nvariables [topological_space \u03b1]\n\nlemma continuous_at.clog {f : \u03b1 \u2192 \u2102} {x : \u03b1} (h\u2081 : continuous_at f x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_at (\u03bb t, log (f t)) x :=\nh\u2081.clog h\u2082\n\nlemma continuous_within_at.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} {x : \u03b1} (h\u2081 : continuous_within_at f s x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_within_at (\u03bb t, log (f t)) s x :=\nh\u2081.clog h\u2082\n\nlemma continuous_on.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} (h\u2081 : continuous_on f s)\n  (h\u2082 : \u2200 x \u2208 s, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_on (\u03bb t, log (f t)) s :=\n\u03bb x hx, (h\u2081 x hx).clog (h\u2082 x hx)\n\nlemma continuous.clog {f : \u03b1 \u2192 \u2102} (h\u2081 : continuous f) (h\u2082 : \u2200 x, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous (\u03bb t, log (f t)) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, h\u2081.continuous_at.clog (h\u2082 x)\n\nvariables {E : Type*} [normed_group E] [normed_space \u2102 E]\n\nlemma has_strict_fderiv_at.clog {f : E \u2192 \u2102} {f' : E \u2192L[\u2102] \u2102} {x : E}\n  (h\u2081 : has_strict_fderiv_at f f' x) (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  has_strict_fderiv_at (\u03bb t, log (f t)) ((f x)\u207b\u00b9 \u2022 f') x :=\n(has_strict_deriv_at_log h\u2082).comp_has_strict_fderiv_at x h\u2081\n\nlemma has_strict_deriv_at.clog {f : \u2102 \u2192 \u2102} {f' x : \u2102} (h\u2081 : has_strict_deriv_at f f' x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  has_strict_deriv_at (\u03bb t, log (f t)) (f' / f x) x :=\nby { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h\u2082).comp x h\u2081 }\n\nlemma has_fderiv_at.clog {f : E \u2192 \u2102} {f' : E \u2192L[\u2102] \u2102} {x : E}\n  (h\u2081 : has_fderiv_at f f' x) (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  has_fderiv_at (\u03bb t, log (f t)) ((f x)\u207b\u00b9 \u2022 f') x :=\n(has_strict_deriv_at_log h\u2082).has_deriv_at.comp_has_fderiv_at x h\u2081\n\nlemma has_deriv_at.clog {f : \u2102 \u2192 \u2102} {f' x : \u2102} (h\u2081 : has_deriv_at f f' x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  has_deriv_at (\u03bb t, log (f t)) (f' / f x) x :=\nby { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h\u2082).has_deriv_at.comp x h\u2081 }\n\nlemma differentiable_at.clog {f : E \u2192 \u2102} {x : E} (h\u2081 : differentiable_at \u2102 f x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  differentiable_at \u2102 (\u03bb t, log (f t)) x :=\n(h\u2081.has_fderiv_at.clog h\u2082).differentiable_at\n\nlemma has_fderiv_within_at.clog {f : E \u2192 \u2102} {f' : E \u2192L[\u2102] \u2102} {s : set E} {x : E}\n  (h\u2081 : has_fderiv_within_at f f' s x) (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  has_fderiv_within_at (\u03bb t, log (f t)) ((f x)\u207b\u00b9 \u2022 f') s x :=\n(has_strict_deriv_at_log h\u2082).has_deriv_at.comp_has_fderiv_within_at x h\u2081\n\nlemma has_deriv_within_at.clog {f : \u2102 \u2192 \u2102} {f' x : \u2102} {s : set \u2102}\n  (h\u2081 : has_deriv_within_at f f' s x) (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  has_deriv_within_at (\u03bb t, log (f t)) (f' / f x) s x :=\nby { rw div_eq_inv_mul,\n     exact (has_strict_deriv_at_log h\u2082).has_deriv_at.comp_has_deriv_within_at x h\u2081 }\n\nlemma differentiable_within_at.clog {f : E \u2192 \u2102} {s : set E} {x : E}\n  (h\u2081 : differentiable_within_at \u2102 f s x) (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  differentiable_within_at \u2102 (\u03bb t, log (f t)) s x :=\n(h\u2081.has_fderiv_within_at.clog h\u2082).differentiable_within_at\n\nlemma differentiable_on.clog {f : E \u2192 \u2102} {s : set E}\n  (h\u2081 : differentiable_on \u2102 f s) (h\u2082 : \u2200 x \u2208 s, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  differentiable_on \u2102 (\u03bb t, log (f t)) s :=\n\u03bb x hx, (h\u2081 x hx).clog (h\u2082 x hx)\n\nlemma differentiable.clog {f : E \u2192 \u2102} (h\u2081 : differentiable \u2102 f)\n  (h\u2082 : \u2200 x, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  differentiable \u2102 (\u03bb t, log (f t)) :=\n\u03bb x, (h\u2081 x).clog (h\u2082 x)\n\nend log_deriv\n\nnamespace polynomial.chebyshev\n\nopen polynomial complex\n\n/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos \u03b8` to the\nvalue `cos (n * \u03b8)`. -/\nlemma T_complex_cos (\u03b8 : \u2102) :\n  \u2200 n, (T \u2102 n).eval (cos \u03b8) = cos (n * \u03b8)\n| 0       := by simp only [T_zero, eval_one, nat.cast_zero, zero_mul, cos_zero]\n| 1       := by simp only [eval_X, one_mul, T_one, nat.cast_one]\n| (n + 2) :=\nbegin\n  simp only [eval_X, eval_one, T_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul],\n  rw [T_complex_cos (n + 1), T_complex_cos n],\n  have aux : sin \u03b8 * sin \u03b8 = 1 - cos \u03b8 * cos \u03b8,\n  { rw \u2190 sin_sq_add_cos_sq \u03b8, ring, },\n  simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux],\n  ring,\nend\n\n/-- `cos (n * \u03b8)` is equal to the `n`-th Chebyshev polynomial of the first kind evaluated\non `cos \u03b8`. -/\nlemma cos_nat_mul (n : \u2115) (\u03b8 : \u2102) :\n  cos (n * \u03b8) = (T \u2102 n).eval (cos \u03b8) :=\n(T_complex_cos \u03b8 n).symm\n\n/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos \u03b8` to the\nvalue `sin ((n+1) * \u03b8) / sin \u03b8`. -/\nlemma U_complex_cos (\u03b8 : \u2102) (n : \u2115) :\n  (U \u2102 n).eval (cos \u03b8) * sin \u03b8 = sin ((n+1) * \u03b8) :=\nbegin\n  induction n with d hd,\n  { simp only [U_zero, nat.cast_zero, eval_one, mul_one, zero_add, one_mul] },\n  { rw U_eq_X_mul_U_add_T,\n    simp only [eval_add, eval_mul, eval_X, T_complex_cos, add_mul, mul_assoc, hd, one_mul],\n    conv_rhs { rw [sin_add, mul_comm] },\n    push_cast,\n    simp only [add_mul, one_mul] }\nend\n\n/-- `sin ((n + 1) * \u03b8)` is equal to `sin \u03b8` multiplied with the `n`-th Chebyshev polynomial of the\nsecond kind evaluated on `cos \u03b8`. -/\nlemma sin_nat_succ_mul (n : \u2115) (\u03b8 : \u2102) :\n  sin ((n + 1) * \u03b8) = (U \u2102 n).eval (cos \u03b8) * sin \u03b8 :=\n(U_complex_cos \u03b8 n).symm\n\nend polynomial.chebyshev\n\nnamespace real\nopen_locale real\n\nlemma tan_add {x y : \u211d}\n  (h : ((\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y \u2260 (2 * l + 1) * \u03c0 / 2)\n     \u2228 ((\u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 2) \u2227 \u2203 l : \u2124, y = (2 * l + 1) * \u03c0 / 2)) :\n  tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=\nby simpa only [\u2190 complex.of_real_inj, complex.of_real_sub, complex.of_real_add, complex.of_real_div,\n              complex.of_real_mul, complex.of_real_tan]\n    using @complex.tan_add (x:\u2102) (y:\u2102) (by convert h; norm_cast)\n\nlemma tan_add' {x y : \u211d}\n  (h : ((\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y \u2260 (2 * l + 1) * \u03c0 / 2)) :\n  tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=\ntan_add (or.inl h)\n\nlemma tan_two_mul {x:\u211d} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) :=\nby simpa only [\u2190 complex.of_real_inj, complex.of_real_sub, complex.of_real_div, complex.of_real_pow,\n              complex.of_real_mul, complex.of_real_tan, complex.of_real_bit0, complex.of_real_one]\n    using complex.tan_two_mul\n\ntheorem cos_eq_zero_iff {\u03b8 : \u211d} : cos \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = (2 * k + 1) * \u03c0 / 2 :=\nby exact_mod_cast @complex.cos_eq_zero_iff \u03b8\n\ntheorem cos_ne_zero_iff {\u03b8 : \u211d} : cos \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 (2 * k + 1) * \u03c0 / 2 :=\nby rw [\u2190 not_exists, not_iff_not, cos_eq_zero_iff]\n\nlemma tan_ne_zero_iff {\u03b8 : \u211d} : tan \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 k * \u03c0 / 2 :=\nby rw [\u2190 complex.of_real_ne_zero, complex.of_real_tan, complex.tan_ne_zero_iff]; norm_cast\n\nlemma tan_eq_zero_iff {\u03b8 : \u211d} : tan \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = k * \u03c0 / 2 :=\nby rw [\u2190 not_iff_not, not_exists, \u2190 ne, tan_ne_zero_iff]\n\nlemma tan_int_mul_pi_div_two (n : \u2124) : tan (n * \u03c0/2) = 0 :=\ntan_eq_zero_iff.mpr (by use n)\n\nlemma tan_int_mul_pi (n : \u2124) : tan (n * \u03c0) = 0 :=\nby rw tan_eq_zero_iff; use (2*n); field_simp [mul_comm ((n:\u211d)*(\u03c0:\u211d)) 2, \u2190 mul_assoc]\n\nlemma cos_eq_cos_iff {x y : \u211d} :\n  cos x = cos y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = 2 * k * \u03c0 - x :=\nby exact_mod_cast @complex.cos_eq_cos_iff x y\n\nlemma sin_eq_sin_iff {x y : \u211d} :\n  sin x = sin y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = (2 * k + 1) * \u03c0 - x :=\nby exact_mod_cast @complex.sin_eq_sin_iff x y\n\nlemma has_strict_deriv_at_tan {x : \u211d} (h : cos x \u2260 0) :\n  has_strict_deriv_at tan (1 / (cos x)^2) x :=\nby exact_mod_cast (complex.has_strict_deriv_at_tan (by exact_mod_cast h)).real_of_complex\n\nlemma has_deriv_at_tan {x : \u211d} (h : cos x \u2260 0) :\n  has_deriv_at tan (1 / (cos x)^2) x :=\nby exact_mod_cast (complex.has_deriv_at_tan (by exact_mod_cast h)).real_of_complex\n\nlemma tendsto_abs_tan_of_cos_eq_zero {x : \u211d} (hx : cos x = 0) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[{x}\u1d9c] x) at_top :=\nbegin\n  have hx : complex.cos x = 0, by exact_mod_cast hx,\n  simp only [\u2190 complex.abs_of_real, complex.of_real_tan],\n  refine (complex.tendsto_abs_tan_of_cos_eq_zero hx).comp _,\n  refine tendsto.inf complex.continuous_of_real.continuous_at _,\n  exact tendsto_principal_principal.2 (\u03bb y, mt complex.of_real_inj.1)\nend\n\nlemma tendsto_abs_tan_at_top (k : \u2124) :\n  tendsto (\u03bb x, abs (tan x)) (\ud835\udcdd[{(2 * k + 1) * \u03c0 / 2}\u1d9c] ((2 * k + 1) * \u03c0 / 2)) at_top :=\ntendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 \u27e8k, rfl\u27e9\n\nlemma continuous_at_tan {x : \u211d} : continuous_at tan x \u2194 cos x \u2260 0 :=\nbegin\n  refine \u27e8\u03bb hc h\u2080, _, \u03bb h, (has_deriv_at_tan h).continuous_at\u27e9,\n  exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h\u2080) _\n    (hc.norm.tendsto.mono_left inf_le_left)\nend\n\nlemma differentiable_at_tan {x : \u211d} : differentiable_at \u211d tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at, \u03bb h, (has_deriv_at_tan h).differentiable_at\u27e9\n\n@[simp] lemma deriv_tan (x : \u211d) : deriv tan x = 1 / (cos x)^2 :=\nif h : cos x = 0 then\n  have \u00acdifferentiable_at \u211d tan x := mt differentiable_at_tan.1 (not_not.2 h),\n  by simp [deriv_zero_of_not_differentiable_at this, h, sq]\nelse (has_deriv_at_tan h).deriv\n\n@[simp] lemma times_cont_diff_at_tan {n x} : times_cont_diff_at \u211d n tan x \u2194 cos x \u2260 0 :=\n\u27e8\u03bb h, continuous_at_tan.1 h.continuous_at,\n  \u03bb h, (complex.times_cont_diff_at_tan.2 $ by exact_mod_cast h).real_of_complex\u27e9\n\nlemma continuous_on_tan : continuous_on tan {x | cos x \u2260 0} :=\n\u03bb x hx, (continuous_at_tan.2 hx).continuous_within_at\n\n@[continuity]\nlemma continuous_tan : continuous (\u03bb x : {x | cos x \u2260 0}, tan x) :=\ncontinuous_on_iff_continuous_restrict.1 continuous_on_tan\n\nlemma has_deriv_at_tan_of_mem_Ioo {x : \u211d} (h : x \u2208 Ioo (-(\u03c0/2):\u211d) (\u03c0/2)) :\n  has_deriv_at tan (1 / (cos x)^2) x :=\nhas_deriv_at_tan (cos_pos_of_mem_Ioo h).ne'\n\nlemma differentiable_at_tan_of_mem_Ioo {x : \u211d} (h : x \u2208 Ioo (-(\u03c0/2):\u211d) (\u03c0/2)) :\n  differentiable_at \u211d tan x :=\n(has_deriv_at_tan_of_mem_Ioo h).differentiable_at\n\nlemma continuous_on_tan_Ioo : continuous_on tan (Ioo (-(\u03c0/2)) (\u03c0/2)) :=\n\u03bb x hx, (differentiable_at_tan_of_mem_Ioo hx).continuous_at.continuous_within_at\n\nlemma tendsto_sin_pi_div_two : tendsto sin (\ud835\udcdd[Iio (\u03c0/2)] (\u03c0/2)) (\ud835\udcdd 1) :=\nby { convert continuous_sin.continuous_within_at, simp }\n\nlemma tendsto_cos_pi_div_two : tendsto cos (\ud835\udcdd[Iio (\u03c0/2)] (\u03c0/2)) (\ud835\udcdd[Ioi 0] 0) :=\nbegin\n  apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,\n  { convert continuous_cos.continuous_within_at, simp },\n  { filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (norm_num.lt_neg_pos\n      _ _ pi_div_two_pos pi_div_two_pos))] \u03bb x hx, cos_pos_of_mem_Ioo hx },\nend\n\nlemma tendsto_tan_pi_div_two : tendsto tan (\ud835\udcdd[Iio (\u03c0/2)] (\u03c0/2)) at_top :=\nbegin\n  convert tendsto_cos_pi_div_two.inv_tendsto_zero.at_top_mul zero_lt_one\n            tendsto_sin_pi_div_two,\n  simp only [pi.inv_apply, \u2190 div_eq_inv_mul, \u2190 tan_eq_sin_div_cos]\nend\n\nlemma tendsto_sin_neg_pi_div_two : tendsto sin (\ud835\udcdd[Ioi (-(\u03c0/2))] (-(\u03c0/2))) (\ud835\udcdd (-1)) :=\nby { convert continuous_sin.continuous_within_at, simp }\n\nlemma tendsto_cos_neg_pi_div_two : tendsto cos (\ud835\udcdd[Ioi (-(\u03c0/2))] (-(\u03c0/2))) (\ud835\udcdd[Ioi 0] 0) :=\nbegin\n  apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,\n  { convert continuous_cos.continuous_within_at, simp },\n  { filter_upwards [Ioo_mem_nhds_within_Ioi (left_mem_Ico.mpr (norm_num.lt_neg_pos\n      _ _ pi_div_two_pos pi_div_two_pos))] \u03bb x hx, cos_pos_of_mem_Ioo hx },\nend\n\nlemma tendsto_tan_neg_pi_div_two : tendsto tan (\ud835\udcdd[Ioi (-(\u03c0/2))] (-(\u03c0/2))) at_bot :=\nbegin\n  convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.at_top_mul_neg (by norm_num)\n            tendsto_sin_neg_pi_div_two,\n  simp only [pi.inv_apply, \u2190 div_eq_inv_mul, \u2190 tan_eq_sin_div_cos]\nend\n\nlemma surj_on_tan : surj_on tan (Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) univ :=\nhave _ := neg_lt_self pi_div_two_pos,\ncontinuous_on_tan_Ioo.surj_on_of_tendsto (nonempty_Ioo.2 this)\n  (by simp [tendsto_tan_neg_pi_div_two, this]) (by simp [tendsto_tan_pi_div_two, this])\n\nlemma tan_surjective : function.surjective tan :=\n\u03bb x, surj_on_tan.subset_range trivial\n\nlemma image_tan_Ioo : tan '' (Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) = univ :=\nuniv_subset_iff.1 surj_on_tan\n\n/-- `real.tan` as an `order_iso` between `(-(\u03c0 / 2), \u03c0 / 2)` and `\u211d`. -/\ndef tan_order_iso : Ioo (-(\u03c0 / 2)) (\u03c0 / 2) \u2243o \u211d :=\n(strict_mono_incr_on_tan.order_iso _ _).trans $ (order_iso.set_congr _ _ image_tan_Ioo).trans\n  order_iso.set.univ\n\n/-- Inverse of the `tan` function, returns values in the range `-\u03c0 / 2 < arctan x` and\n`arctan x < \u03c0 / 2` -/\n@[pp_nodot] noncomputable def arctan (x : \u211d) : \u211d :=\ntan_order_iso.symm x\n\n@[simp] lemma tan_arctan (x : \u211d) : tan (arctan x) = x :=\ntan_order_iso.apply_symm_apply x\n\nlemma arctan_mem_Ioo (x : \u211d) : arctan x \u2208 Ioo (-(\u03c0 / 2)) (\u03c0 / 2) :=\nsubtype.coe_prop _\n\nlemma arctan_tan {x : \u211d} (hx\u2081 : -(\u03c0 / 2) < x) (hx\u2082 : x < \u03c0 / 2) : arctan (tan x) = x :=\nsubtype.ext_iff.1 $ tan_order_iso.symm_apply_apply \u27e8x, hx\u2081, hx\u2082\u27e9\n\nlemma cos_arctan_pos (x : \u211d) : 0 < cos (arctan x) :=\ncos_pos_of_mem_Ioo $ arctan_mem_Ioo x\n\nlemma cos_sq_arctan (x : \u211d) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) :=\nby rw [one_div, \u2190 inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan]\n\nlemma sin_arctan (x : \u211d) : sin (arctan x) = x / sqrt (1 + x ^ 2) :=\nby rw [\u2190 tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]\n\nlemma cos_arctan (x : \u211d) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) :=\nby rw [one_div, \u2190 inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]\n\nlemma arctan_lt_pi_div_two (x : \u211d) : arctan x < \u03c0 / 2 :=\n(arctan_mem_Ioo x).2\n\nlemma neg_pi_div_two_lt_arctan (x : \u211d) : -(\u03c0 / 2) < arctan x :=\n(arctan_mem_Ioo x).1\n\nlemma arctan_eq_arcsin (x : \u211d) : arctan x = arcsin (x / sqrt (1 + x ^ 2)) :=\neq.symm $ arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo $ arctan_mem_Ioo x)\n\nlemma arcsin_eq_arctan {x : \u211d} (h : x \u2208 Ioo (-(1:\u211d)) 1) :\n  arcsin x = arctan (x / sqrt (1 - x ^ 2)) :=\nbegin\n  rw [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div_eq_div_mul,\n      \u2190 sqrt_mul, mul_div_cancel', sub_add_cancel, sqrt_one, div_one];\n  nlinarith [h.1, h.2],\nend\n\n@[simp] lemma arctan_zero : arctan 0 = 0 :=\nby simp [arctan_eq_arcsin]\n\nlemma arctan_eq_of_tan_eq {x y : \u211d} (h : tan x = y) (hx : x \u2208 Ioo (-(\u03c0 / 2)) (\u03c0 / 2)) :\n  arctan y = x :=\ninj_on_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h])\n\n@[simp] lemma arctan_one : arctan 1 = \u03c0 / 4 :=\narctan_eq_of_tan_eq tan_pi_div_four $ by split; linarith [pi_pos]\n\n@[simp] lemma arctan_neg (x : \u211d) : arctan (-x) = - arctan x :=\nby simp [arctan_eq_arcsin, neg_div]\n\n@[continuity]\nlemma continuous_arctan : continuous arctan :=\ncontinuous_subtype_coe.comp tan_order_iso.to_homeomorph.continuous_inv_fun\n\nlemma continuous_at_arctan {x : \u211d} : continuous_at arctan x := continuous_arctan.continuous_at\n\n/-- `real.tan` as a `local_homeomorph` between `(-(\u03c0 / 2), \u03c0 / 2)` and the whole line. -/\ndef tan_local_homeomorph : local_homeomorph \u211d \u211d :=\n{ to_fun := tan,\n  inv_fun := arctan,\n  source := Ioo (-(\u03c0 / 2)) (\u03c0 / 2),\n  target := univ,\n  map_source' := maps_to_univ _ _,\n  map_target' := \u03bb y hy, arctan_mem_Ioo y,\n  left_inv' := \u03bb x hx, arctan_tan hx.1 hx.2,\n  right_inv' := \u03bb y hy, tan_arctan y,\n  open_source := is_open_Ioo,\n  open_target := is_open_univ,\n  continuous_to_fun := continuous_on_tan_Ioo,\n  continuous_inv_fun := continuous_arctan.continuous_on }\n\n@[simp] lemma coe_tan_local_homeomorph : \u21d1tan_local_homeomorph = tan := rfl\n@[simp] lemma coe_tan_local_homeomorph_symm : \u21d1tan_local_homeomorph.symm = arctan := rfl\n\nlemma has_strict_deriv_at_arctan (x : \u211d) : has_strict_deriv_at arctan (1 / (1 + x^2)) x :=\nhave A : cos (arctan x) \u2260 0 := (cos_arctan_pos x).ne',\nby simpa [cos_sq_arctan]\n  using tan_local_homeomorph.has_strict_deriv_at_symm trivial (by simpa) (has_strict_deriv_at_tan A)\n\nlemma has_deriv_at_arctan (x : \u211d) : has_deriv_at arctan (1 / (1 + x^2)) x :=\n(has_strict_deriv_at_arctan x).has_deriv_at\n\nlemma differentiable_at_arctan (x : \u211d) : differentiable_at \u211d arctan x :=\n(has_deriv_at_arctan x).differentiable_at\n\nlemma differentiable_arctan : differentiable \u211d arctan := differentiable_at_arctan\n\n@[simp] lemma deriv_arctan : deriv arctan = (\u03bb x, 1 / (1 + x^2)) :=\nfunext $ \u03bb x, (has_deriv_at_arctan x).deriv\n\nlemma times_cont_diff_arctan {n : with_top \u2115} : times_cont_diff \u211d n arctan :=\ntimes_cont_diff_iff_times_cont_diff_at.2 $ \u03bb x,\nhave cos (arctan x) \u2260 0 := (cos_arctan_pos x).ne',\ntan_local_homeomorph.times_cont_diff_at_symm_deriv (by simpa) trivial (has_deriv_at_tan this)\n  (times_cont_diff_at_tan.2 this)\n\nlemma measurable_arctan : measurable arctan := continuous_arctan.measurable\n\nend real\n\nsection\n/-!\n### Lemmas for derivatives of the composition of `real.arctan` with a differentiable function\n\nIn this section we register lemmas for the derivatives of the composition of `real.arctan` with a\ndifferentiable function, for standalone use and use with `simp`. -/\n\nopen real\n\nlemma measurable.arctan {\u03b1 : Type*} [measurable_space \u03b1] {f : \u03b1 \u2192 \u211d} (hf : measurable f) :\n  measurable (\u03bb x, arctan (f x)) :=\nmeasurable_arctan.comp hf\n\nsection deriv\n\nvariables {f : \u211d \u2192 \u211d} {f' x : \u211d} {s : set \u211d}\n\nlemma has_strict_deriv_at.arctan (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=\n(real.has_strict_deriv_at_arctan (f x)).comp x hf\n\nlemma has_deriv_at.arctan (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=\n(real.has_deriv_at_arctan (f x)).comp x hf\n\nlemma has_deriv_within_at.arctan (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') s x :=\n(real.has_deriv_at_arctan (f x)).comp_has_deriv_within_at x hf\n\nlemma deriv_within_arctan (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  deriv_within (\u03bb x, arctan (f x)) s x = (1 / (1 + (f x)^2)) * (deriv_within f s x) :=\nhf.has_deriv_within_at.arctan.deriv_within hxs\n\n@[simp] lemma deriv_arctan (hc : differentiable_at \u211d f x) :\n  deriv (\u03bb x, arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) :=\nhc.has_deriv_at.arctan.deriv\n\nend deriv\n\nsection fderiv\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E] {f : E \u2192 \u211d} {f' : E \u2192L[\u211d] \u211d} {x : E}\n  {s : set E} {n : with_top \u2115}\n\nlemma has_strict_fderiv_at.arctan (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (\u03bb x, arctan (f x)) ((1 / (1 + (f x)^2)) \u2022 f') x :=\n(has_strict_deriv_at_arctan (f x)).comp_has_strict_fderiv_at x hf\n\nlemma has_fderiv_at.arctan (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (\u03bb x, arctan (f x)) ((1 / (1 + (f x)^2)) \u2022 f') x :=\n(has_deriv_at_arctan (f x)).comp_has_fderiv_at x hf\n\nlemma has_fderiv_within_at.arctan (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (\u03bb x, arctan (f x)) ((1 / (1 + (f x)^2)) \u2022 f') s x :=\n(has_deriv_at_arctan (f x)).comp_has_fderiv_within_at x hf\n\nlemma fderiv_within_arctan (hf : differentiable_within_at \u211d f s x)\n  (hxs : unique_diff_within_at \u211d s x) :\n  fderiv_within \u211d (\u03bb x, arctan (f x)) s x = (1 / (1 + (f x)^2)) \u2022 (fderiv_within \u211d f s x) :=\nhf.has_fderiv_within_at.arctan.fderiv_within hxs\n\n@[simp] lemma fderiv_arctan (hc : differentiable_at \u211d f x) :\n  fderiv \u211d (\u03bb x, arctan (f x)) x = (1 / (1 + (f x)^2)) \u2022 (fderiv \u211d f x) :=\nhc.has_fderiv_at.arctan.fderiv\n\nlemma differentiable_within_at.arctan (hf : differentiable_within_at \u211d f s x) :\n  differentiable_within_at \u211d (\u03bb x, real.arctan (f x)) s x :=\nhf.has_fderiv_within_at.arctan.differentiable_within_at\n\n@[simp] lemma differentiable_at.arctan (hc : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bb x, arctan (f x)) x :=\nhc.has_fderiv_at.arctan.differentiable_at\n\nlemma differentiable_on.arctan (hc : differentiable_on \u211d f s) :\n  differentiable_on \u211d (\u03bb x, arctan (f x)) s :=\n\u03bb x h, (hc x h).arctan\n\n@[simp] lemma differentiable.arctan (hc : differentiable \u211d f) :\n  differentiable \u211d (\u03bb x, arctan (f x)) :=\n\u03bb x, (hc x).arctan\n\nlemma times_cont_diff_at.arctan (h : times_cont_diff_at \u211d n f x) :\n  times_cont_diff_at \u211d n (\u03bb x, arctan (f x)) x :=\ntimes_cont_diff_arctan.times_cont_diff_at.comp x h\n\nlemma times_cont_diff.arctan (h : times_cont_diff \u211d n f) :\n  times_cont_diff \u211d n (\u03bb x, arctan (f x)) :=\ntimes_cont_diff_arctan.comp h\n\nlemma times_cont_diff_within_at.arctan (h : times_cont_diff_within_at \u211d n f s x) :\n  times_cont_diff_within_at \u211d n (\u03bb x, arctan (f x)) s x :=\ntimes_cont_diff_arctan.comp_times_cont_diff_within_at h\n\nlemma times_cont_diff_on.arctan (h : times_cont_diff_on \u211d n f s) :\n  times_cont_diff_on \u211d n (\u03bb x, arctan (f x)) s :=\ntimes_cont_diff_arctan.comp_times_cont_diff_on h\n\nend fderiv\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/special_functions/trigonometric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7283678228251527}}
{"text": "-- Inverso_del_producto.lean\n-- Si G es un grupo y a, b \u2208 G entonces (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 19-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si G un grupo y a, b \u2208 G, entonces\n--    (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9\n-- ---------------------------------------------------------------------\n\nimport algebra.group\nvariables {G : Type*} [group G]\nvariables a b : G\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_eq_one_iff_inv_eq.mp,\n  calc a * b * (b\u207b\u00b9 * a\u207b\u00b9)\n       = ((a * b) * b\u207b\u00b9) * a\u207b\u00b9 : (mul_assoc _ _ _).symm\n   ... = (a * (b * b\u207b\u00b9)) * a\u207b\u00b9 : congr_arg (* a\u207b\u00b9) (mul_assoc a _ _)\n   ... = (a * 1) * a\u207b\u00b9         : congr_arg2 _ (congr_arg _ (mul_inv_self b)) rfl\n   ... = a * a\u207b\u00b9               : congr_arg (* a\u207b\u00b9) (mul_one a)\n   ... = 1                     : mul_inv_self a\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_eq_one_iff_inv_eq.mp,\n  calc a * b * (b\u207b\u00b9 * a\u207b\u00b9)\n       = ((a * b) * b\u207b\u00b9) * a\u207b\u00b9 : by simp only [mul_assoc]\n   ... = (a * (b * b\u207b\u00b9)) * a\u207b\u00b9 : by simp only [mul_assoc]\n   ... = (a * 1) * a\u207b\u00b9         : by simp only [mul_inv_self]\n   ... = a * a\u207b\u00b9               : by simp only [mul_one]\n   ... = 1                     : by simp only [mul_inv_self]\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_eq_one_iff_inv_eq.mp,\n  calc a * b * (b\u207b\u00b9 * a\u207b\u00b9)\n       = ((a * b) * b\u207b\u00b9) * a\u207b\u00b9 : by simp [mul_assoc]\n   ... = (a * (b * b\u207b\u00b9)) * a\u207b\u00b9 : by simp\n   ... = (a * 1) * a\u207b\u00b9         : by simp\n   ... = a * a\u207b\u00b9               : by simp\n   ... = 1                     : by simp,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\n-- by library_search\nmul_inv_rev a b\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Inverso_del_producto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7283678162730491}}
{"text": "/-\nCopyright (c) 2021 Jon Eugster. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jon Eugster, Eric Wieser\n-/\nimport algebra.char_p.basic\nimport ring_theory.localization.fraction_ring\nimport algebra.free_algebra\n\n\n/-!\n# Characteristics of algebras\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we describe the characteristic of `R`-algebras.\n\nIn particular we are interested in the characteristic of free algebras over `R`\nand the fraction field `fraction_ring R`.\n\n\n## Main results\n\n- `char_p_of_injective_algebra_map` If `R \u2192+* A` is an injective algebra map\n  then `A` has the same characteristic as `R`.\n\nInstances constructed from this result:\n- Any `free_algebra R X` has the same characteristic as `R`.\n- The `fraction_ring R` of an integral domain `R` has the same characteristic as `R`.\n\n-/\n\n\n/-- If the algebra map `R \u2192+* A` is injective then `A` has the same characteristic as `R`. -/\nlemma char_p_of_injective_algebra_map {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]\n  (h : function.injective (algebra_map R A)) (p : \u2115) [char_p R p] : char_p A p :=\n{ cast_eq_zero_iff := \u03bbx,\n  begin\n    rw \u2190char_p.cast_eq_zero_iff R p x,\n    change algebra_map \u2115 A x = 0 \u2194 algebra_map \u2115 R x = 0,\n    rw is_scalar_tower.algebra_map_apply \u2115 R A x,\n    refine iff.trans _ h.eq_iff,\n    rw ring_hom.map_zero,\n  end }\n\nlemma char_p_of_injective_algebra_map' (R A : Type*) [field R] [semiring A] [algebra R A]\n  [nontrivial A] (p : \u2115) [char_p R p] : char_p A p :=\nchar_p_of_injective_algebra_map (algebra_map R A).injective p\n\n/-- If the algebra map `R \u2192+* A` is injective and `R` has characteristic zero then so does `A`. -/\nlemma char_zero_of_injective_algebra_map {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]\n  (h : function.injective (algebra_map R A)) [char_zero R] : char_zero A :=\n{ cast_injective := \u03bb x y hxy,\n  begin\n    change algebra_map \u2115 A x = algebra_map \u2115 A y at hxy,\n    rw is_scalar_tower.algebra_map_apply \u2115 R A x at hxy,\n    rw is_scalar_tower.algebra_map_apply \u2115 R A y at hxy,\n    exact char_zero.cast_injective (h hxy),\n  end }\n-- `char_p.char_p_to_char_zero A _ (char_p_of_injective_algebra_map h 0)` does not work\n-- here as it would require `ring A`.\n\n/-!\nAs an application, a `\u211a`-algebra has characteristic zero.\n-/\nsection Q_algebra\n\nvariables (R : Type*) [nontrivial R]\n\n/-- A nontrivial `\u211a`-algebra has `char_p` equal to zero.\n\nThis cannot be a (local) instance because it would immediately form a loop with the\ninstance `algebra_rat`. It's probably easier to go the other way: prove `char_zero R` and\nautomatically receive an `algebra \u211a R` instance.\n-/\nlemma algebra_rat.char_p_zero [semiring R] [algebra \u211a R] : char_p R 0 :=\nchar_p_of_injective_algebra_map (algebra_map \u211a R).injective 0\n\n/-- A nontrivial `\u211a`-algebra has characteristic zero.\n\nThis cannot be a (local) instance because it would immediately form a loop with the\ninstance `algebra_rat`. It's probably easier to go the other way: prove `char_zero R` and\nautomatically receive an `algebra \u211a R` instance.\n-/\nlemma algebra_rat.char_zero [ring R] [algebra \u211a R] : char_zero R :=\n@char_p.char_p_to_char_zero R _ (algebra_rat.char_p_zero R)\n\nend Q_algebra\n\n/-!\nAn algebra over a field has the same characteristic as the field.\n-/\nsection\n\nvariables (K L : Type*) [field K] [comm_semiring L] [nontrivial L] [algebra K L]\n\nlemma algebra.char_p_iff (p : \u2115) : char_p K p \u2194 char_p L p :=\n(algebra_map K L).char_p_iff_char_p p\n\nlemma algebra.ring_char_eq : ring_char K = ring_char L :=\nby { rw [ring_char.eq_iff, algebra.char_p_iff K L], apply ring_char.char_p }\n\nend\n\nnamespace free_algebra\n\nvariables {R X : Type*} [comm_semiring R] (p : \u2115)\n\n/-- If `R` has characteristic `p`, then so does `free_algebra R X`. -/\ninstance char_p [char_p R p] : char_p (free_algebra R X) p :=\nchar_p_of_injective_algebra_map free_algebra.algebra_map_left_inverse.injective p\n\n/-- If `R` has characteristic `0`, then so does `free_algebra R X`. -/\ninstance char_zero [char_zero R] : char_zero (free_algebra R X) :=\nchar_zero_of_injective_algebra_map free_algebra.algebra_map_left_inverse.injective\n\nend free_algebra\n\nnamespace is_fraction_ring\n\nvariables (R : Type*) {K : Type*} [comm_ring R]\n  [field K] [algebra R K] [is_fraction_ring R K]\nvariables (p : \u2115)\n\n/-- If `R` has characteristic `p`, then so does Frac(R). -/\n\n\n/-- If `R` has characteristic `0`, then so does Frac(R). -/\nlemma char_zero_of_is_fraction_ring [char_zero R] : char_zero K :=\n@char_p.char_p_to_char_zero K _ (char_p_of_is_fraction_ring R 0)\n\nvariables [is_domain R]\n\n/-- If `R` has characteristic `p`, then so does `fraction_ring R`. -/\ninstance char_p [char_p R p] : char_p (fraction_ring R) p :=\nchar_p_of_is_fraction_ring R p\n\n/-- If `R` has characteristic `0`, then so does `fraction_ring R`. -/\ninstance char_zero [char_zero R] : char_zero (fraction_ring R) :=\nchar_zero_of_is_fraction_ring R\n\nend is_fraction_ring\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/char_p/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7283678152572273}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module data.countable.defs\n! leanprover-community/mathlib commit 70d50ecfd4900dd6d328da39ab7ebd516abe4025\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finite.Defs\nimport Mathlib.Tactic.MkIffOfInductiveProp\n\n/-!\n# Countable types\n\nIn this file we define a typeclass saying that a given `Sort _` is countable. See also `Encodable`\nfor a version that singles out a specific encoding of elements of `\u03b1` by natural numbers.\n\nThis file also provides a few instances of this typeclass. More instances can be found in other\nfiles.\n-/\n\n\nopen Function\n\nuniverse u v\n\nvariable {\u03b1 : Sort u} {\u03b2 : Sort v}\n\n/-!\n### Definition and basic properties\n-/\n\n/-- A type `\u03b1` is countable if there exists an injective map `\u03b1 \u2192 \u2115`. -/\n@[mk_iff countable_iff_exists_injective]\nclass Countable (\u03b1 : Sort u) : Prop where\n  /-- A type `\u03b1` is countable if there exists an injective map `\u03b1 \u2192 \u2115`. -/\n  exists_injective_nat' : \u2203 f : \u03b1 \u2192 \u2115, Injective f\n#align countable Countable\n#align countable_iff_exists_injective countable_iff_exists_injective\n\nlemma Countable.exists_injective_nat (\u03b1 : Sort u) [Countable \u03b1] :\n  \u2203 f : \u03b1 \u2192 \u2115, Injective f :=\nCountable.exists_injective_nat'\n\ninstance : Countable \u2115 :=\n  \u27e8\u27e8id, injective_id\u27e9\u27e9\n\nexport Countable (exists_injective_nat)\n\nprotected theorem Function.Injective.countable [Countable \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Injective f) :\n  Countable \u03b1 :=\n  let \u27e8g, hg\u27e9 := exists_injective_nat \u03b2\n  \u27e8\u27e8g \u2218 f, hg.comp hf\u27e9\u27e9\n#align function.injective.countable Function.Injective.countable\n\nprotected theorem Function.Surjective.countable [Countable \u03b1] {f : \u03b1 \u2192 \u03b2} (hf : Surjective f) :\n  Countable \u03b2 :=\n  (injective_surjInv hf).countable\n#align function.surjective.countable Function.Surjective.countable\n\ntheorem exists_surjective_nat (\u03b1 : Sort u) [Nonempty \u03b1] [Countable \u03b1] : \u2203 f : \u2115 \u2192 \u03b1, Surjective f :=\n  let \u27e8f, hf\u27e9 := exists_injective_nat \u03b1\n  \u27e8invFun f, invFun_surjective hf\u27e9\n#align exists_surjective_nat exists_surjective_nat\n\ntheorem countable_iff_exists_surjective [Nonempty \u03b1] : Countable \u03b1 \u2194 \u2203 f : \u2115 \u2192 \u03b1, Surjective f :=\n  \u27e8@exists_surjective_nat _ _, fun \u27e8_, hf\u27e9 \u21a6 hf.countable\u27e9\n#align countable_iff_exists_surjective countable_iff_exists_surjective\n\ntheorem Countable.of_equiv (\u03b1 : Sort _) [Countable \u03b1] (e : \u03b1 \u2243 \u03b2) : Countable \u03b2 :=\n  e.symm.injective.countable\n#align countable.of_equiv Countable.of_equiv\n\ntheorem Equiv.countable_iff (e : \u03b1 \u2243 \u03b2) : Countable \u03b1 \u2194 Countable \u03b2 :=\n  \u27e8fun h => @Countable.of_equiv _ _ h e, fun h => @Countable.of_equiv _ _ h e.symm\u27e9\n#align equiv.countable_iff Equiv.countable_iff\n\ninstance {\u03b2 : Type v} [Countable \u03b2] : Countable (ULift.{u} \u03b2) :=\n  Countable.of_equiv _ Equiv.ulift.symm\n\n/-!\n### Operations on `Sort _`s\n-/\n\n\ninstance [Countable \u03b1] : Countable (PLift \u03b1) :=\n  Equiv.plift.injective.countable\n\ninstance (priority := 100) Subsingleton.to_countable [Subsingleton \u03b1] : Countable \u03b1 :=\n  \u27e8\u27e8fun _ => 0, fun x y _ => Subsingleton.elim x y\u27e9\u27e9\n\ninstance (priority := 500) Subtype.countable [Countable \u03b1] {p : \u03b1 \u2192 Prop} :\n    Countable { x // p x } :=\n  Subtype.val_injective.countable\n\ninstance {n : \u2115} : Countable (Fin n) :=\n  Function.Injective.countable (@Fin.eq_of_veq n)\n\ninstance (priority := 100) Finite.to_countable [Finite \u03b1] : Countable \u03b1 :=\n  let \u27e8_, \u27e8e\u27e9\u27e9 := Finite.exists_equiv_fin \u03b1\n  Countable.of_equiv _ e.symm\n\ninstance : Countable PUnit.{u} :=\n  Subsingleton.to_countable\n\ninstance (priority := 100) Prop.countable (p : Prop) : Countable p :=\n  Subsingleton.to_countable\n\ninstance Bool.countable : Countable Bool :=\n  \u27e8\u27e8fun b => cond b 0 1, Bool.injective_iff.2 Nat.one_ne_zero\u27e9\u27e9\n\ninstance Prop.countable' : Countable Prop :=\n  Countable.of_equiv Bool Equiv.propEquivBool.symm\n\ninstance (priority := 500) Quotient.countable [Countable \u03b1] {r : \u03b1 \u2192 \u03b1 \u2192 Prop} :\n    Countable (Quot r) :=\n  (surjective_quot_mk r).countable\n\ninstance (priority := 500) [Countable \u03b1] {s : Setoid \u03b1} : Countable (Quotient s) :=\n  (inferInstance : Countable (@Quot \u03b1 _))\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Countable/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782277, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.728367813987449}}
{"text": "/-\nCopyright (c) 2021 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n-/\nimport data.fintype.card_embedding\n\n/-!\n# Birthday Problem\n\nThis file proves Theorem 93 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).\n\nAs opposed to the standard probabilistic statement, we instead state the birthday problem\nin terms of injective functions. The general result about `fintype.card (\u03b1 \u21aa \u03b2)` which this proof\nuses is `fintype.card_embedding_eq`.\n-/\n\nlocal notation `\u2016` x `\u2016` := fintype.card x\n\n/-- **Birthday Problem** -/\ntheorem birthday :\n  2 * \u2016fin 23 \u21aa fin 365\u2016 < \u2016fin 23 \u2192 fin 365\u2016 \u2227 2 * \u2016fin 22 \u21aa fin 365\u2016 > \u2016fin 22 \u2192 fin 365\u2016 :=\nbegin\n  simp only [nat.desc_factorial, fintype.card_fin, fintype.card_embedding_eq, fintype.card_fun],\n  norm_num\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/archive/100-theorems-list/93_birthday_problem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361700013355, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7282944929969408}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport geometry.euclidean.angle.oriented.right_angle\nimport geometry.euclidean.circumcenter\n\n/-!\n# Angles in circles and sphere.\n\nThis file proves results about angles in circles and spheres.\n\n-/\n\nnoncomputable theory\n\nopen finite_dimensional complex\nopen_locale euclidean_geometry real real_inner_product_space complex_conjugate\n\nnamespace orientation\n\nvariables {V : Type*} [normed_add_comm_group V] [inner_product_space \u211d V]\nvariables [fact (finrank \u211d V = 2)] (o : orientation \u211d V (fin 2))\n\n/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle\nform. -/\nlemma oangle_eq_two_zsmul_oangle_sub_of_norm_eq {x y z : V} (hxyne : x \u2260 y) (hxzne : x \u2260 z)\n  (hxy : \u2016x\u2016 = \u2016y\u2016) (hxz : \u2016x\u2016 = \u2016z\u2016) : o.oangle y z = (2 : \u2124) \u2022 o.oangle (y - x) (z - x) :=\nbegin\n  have hy : y \u2260 0,\n  { rintro rfl,\n    rw [norm_zero, norm_eq_zero] at hxy,\n    exact hxyne hxy },\n  have hx : x \u2260 0 := norm_ne_zero_iff.1 (hxy.symm \u25b8 norm_ne_zero_iff.2 hy),\n  have hz : z \u2260 0 := norm_ne_zero_iff.1 (hxz \u25b8 norm_ne_zero_iff.2 hx),\n  calc o.oangle y z = o.oangle x z - o.oangle x y : (o.oangle_sub_left hx hy hz).symm\n       ...           = (\u03c0 - (2 : \u2124) \u2022 o.oangle (x - z) x) -\n                       (\u03c0 - (2 : \u2124) \u2022 o.oangle (x - y) x) :\n         by rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxzne.symm hxz.symm,\n                o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxyne.symm hxy.symm]\n       ...           = (2 : \u2124) \u2022 (o.oangle (x - y) x - o.oangle (x - z) x) : by abel\n       ...           = (2 : \u2124) \u2022 o.oangle (x - y) (x - z) :\n         by rw o.oangle_sub_right (sub_ne_zero_of_ne hxyne) (sub_ne_zero_of_ne hxzne) hx\n       ...           = (2 : \u2124) \u2022 o.oangle (y - x) (z - x) :\n         by rw [\u2190oangle_neg_neg, neg_sub, neg_sub]\nend\n\n/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle\nform with radius specified. -/\nlemma oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real {x y z : V} (hxyne : x \u2260 y) (hxzne : x \u2260 z)\n  {r : \u211d} (hx : \u2016x\u2016 = r) (hy : \u2016y\u2016 = r) (hz : \u2016z\u2016 = r) :\n  o.oangle y z = (2 : \u2124) \u2022 o.oangle (y - x) (z - x) :=\no.oangle_eq_two_zsmul_oangle_sub_of_norm_eq hxyne hxzne (hy.symm \u25b8 hx) (hz.symm \u25b8 hx)\n\n/-- Oriented vector angle version of \"angles in same segment are equal\" and \"opposite angles of\na cyclic quadrilateral add to \u03c0\", for oriented angles mod \u03c0 (for which those are the same\nresult), represented here as equality of twice the angles. -/\nlemma two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq {x\u2081 x\u2082 y z : V} (hx\u2081yne : x\u2081 \u2260 y)\n  (hx\u2081zne : x\u2081 \u2260 z) (hx\u2082yne : x\u2082 \u2260 y) (hx\u2082zne : x\u2082 \u2260 z) {r : \u211d} (hx\u2081 : \u2016x\u2081\u2016 = r) (hx\u2082 : \u2016x\u2082\u2016 = r)\n  (hy : \u2016y\u2016 = r) (hz : \u2016z\u2016 = r) :\n  (2 : \u2124) \u2022 o.oangle (y - x\u2081) (z - x\u2081) = (2 : \u2124) \u2022 o.oangle (y - x\u2082) (z - x\u2082) :=\no.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx\u2081yne hx\u2081zne hx\u2081 hy hz \u25b8\n  o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx\u2082yne hx\u2082zne hx\u2082 hy hz\n\nend orientation\n\nnamespace euclidean_geometry\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\n  [hd2 : fact (finrank \u211d V = 2)] [module.oriented \u211d V (fin 2)]\ninclude hd2\n\nlocal notation `o` := module.oriented.positive_orientation\n\nnamespace sphere\n\n/-- Angle at center of a circle equals twice angle at circumference, oriented angle version. -/\nlemma oangle_center_eq_two_zsmul_oangle {s : sphere P} {p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) (hp\u2083 : p\u2083 \u2208 s) (hp\u2082p\u2081 : p\u2082 \u2260 p\u2081) (hp\u2082p\u2083 : p\u2082 \u2260 p\u2083) :\n  \u2221 p\u2081 s.center p\u2083 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 :=\nbegin\n  rw [mem_sphere, @dist_eq_norm_vsub V] at hp\u2081 hp\u2082 hp\u2083,\n  rw [oangle, oangle, (o).oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real _ _ hp\u2082 hp\u2081 hp\u2083];\n    simp [hp\u2082p\u2081, hp\u2082p\u2083]\nend\n\n/-- Oriented angle version of \"angles in same segment are equal\" and \"opposite angles of a\ncyclic quadrilateral add to \u03c0\", for oriented angles mod \u03c0 (for which those are the same result),\nrepresented here as equality of twice the angles. -/\nlemma two_zsmul_oangle_eq {s : sphere P} {p\u2081 p\u2082 p\u2083 p\u2084 : P} (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2208 s)\n  (hp\u2083 : p\u2083 \u2208 s) (hp\u2084 : p\u2084 \u2208 s) (hp\u2082p\u2081 : p\u2082 \u2260 p\u2081) (hp\u2082p\u2084 : p\u2082 \u2260 p\u2084) (hp\u2083p\u2081 : p\u2083 \u2260 p\u2081)\n  (hp\u2083p\u2084 : p\u2083 \u2260 p\u2084) : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2084 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2083 p\u2084 :=\nbegin\n  rw [mem_sphere, @dist_eq_norm_vsub V] at hp\u2081 hp\u2082 hp\u2083 hp\u2084,\n  rw [oangle, oangle, \u2190vsub_sub_vsub_cancel_right p\u2081 p\u2082 s.center,\n      \u2190vsub_sub_vsub_cancel_right p\u2084 p\u2082 s.center,\n      (o).two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq _ _ _ _ hp\u2082 hp\u2083 hp\u2081 hp\u2084];\n    simp [hp\u2082p\u2081, hp\u2082p\u2084, hp\u2083p\u2081, hp\u2083p\u2084]\nend\n\nend sphere\n\n/-- Oriented angle version of \"angles in same segment are equal\" and \"opposite angles of a\ncyclic quadrilateral add to \u03c0\", for oriented angles mod \u03c0 (for which those are the same result),\nrepresented here as equality of twice the angles. -/\nlemma cospherical.two_zsmul_oangle_eq {p\u2081 p\u2082 p\u2083 p\u2084 : P}\n  (h : cospherical ({p\u2081, p\u2082, p\u2083, p\u2084} : set P)) (hp\u2082p\u2081 : p\u2082 \u2260 p\u2081) (hp\u2082p\u2084 : p\u2082 \u2260 p\u2084)\n  (hp\u2083p\u2081 : p\u2083 \u2260 p\u2081) (hp\u2083p\u2084 : p\u2083 \u2260 p\u2084) : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2084 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2083 p\u2084 :=\nbegin\n  obtain \u27e8s, hs\u27e9 := cospherical_iff_exists_sphere.1 h,\n  simp_rw [set.insert_subset, set.singleton_subset_iff, sphere.mem_coe] at hs,\n  exact sphere.two_zsmul_oangle_eq hs.1 hs.2.1 hs.2.2.1 hs.2.2.2 hp\u2082p\u2081 hp\u2082p\u2084 hp\u2083p\u2081 hp\u2083p\u2084\nend\n\nnamespace sphere\n\n/-- The angle at the apex of an isosceles triangle is `\u03c0` minus twice a base angle, oriented\nangle-at-point form where the apex is given as the center of a circle. -/\nlemma oangle_eq_pi_sub_two_zsmul_oangle_center_left {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) (h : p\u2081 \u2260 p\u2082) : \u2221 p\u2081 s.center p\u2082 = \u03c0 - (2 : \u2124) \u2022 \u2221 s.center p\u2082 p\u2081 :=\nby rw [oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq h.symm\n  (dist_center_eq_dist_center_of_mem_sphere' hp\u2082 hp\u2081)]\n\n/-- The angle at the apex of an isosceles triangle is `\u03c0` minus twice a base angle, oriented\nangle-at-point form where the apex is given as the center of a circle. -/\nlemma oangle_eq_pi_sub_two_zsmul_oangle_center_right {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) (h : p\u2081 \u2260 p\u2082) : \u2221 p\u2081 s.center p\u2082 = \u03c0 - (2 : \u2124) \u2022 \u2221 p\u2082 p\u2081 s.center :=\nby rw [oangle_eq_pi_sub_two_zsmul_oangle_center_left hp\u2081 hp\u2082 h,\n       oangle_eq_oangle_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere' hp\u2082 hp\u2081)]\n\n/-- Twice a base angle of an isosceles triangle with apex at the center of a circle, plus twice\nthe angle at the apex of a triangle with the same base but apex on the circle, equals `\u03c0`. -/\nlemma two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi {s : sphere P} {p\u2081 p\u2082 p\u2083 : P}\n  (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2208 s) (hp\u2083 : p\u2083 \u2208 s) (hp\u2082p\u2081 : p\u2082 \u2260 p\u2081) (hp\u2082p\u2083 : p\u2082 \u2260 p\u2083)\n  (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) : (2 : \u2124) \u2022 \u2221 p\u2083 p\u2081 s.center + (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 = \u03c0 :=\nby rw [\u2190oangle_center_eq_two_zsmul_oangle hp\u2081 hp\u2082 hp\u2083 hp\u2082p\u2081 hp\u2082p\u2083,\n       oangle_eq_pi_sub_two_zsmul_oangle_center_right hp\u2081 hp\u2083 hp\u2081p\u2083, add_sub_cancel'_right]\n\n/-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/\nlemma abs_oangle_center_left_to_real_lt_pi_div_two {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) : |(\u2221 s.center p\u2082 p\u2081).to_real| < \u03c0 / 2 :=\nabs_oangle_right_to_real_lt_pi_div_two_of_dist_eq\n  (dist_center_eq_dist_center_of_mem_sphere' hp\u2082 hp\u2081)\n\n/-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/\nlemma abs_oangle_center_right_to_real_lt_pi_div_two {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) : |(\u2221 p\u2082 p\u2081 s.center).to_real| < \u03c0 / 2 :=\nabs_oangle_left_to_real_lt_pi_div_two_of_dist_eq\n  (dist_center_eq_dist_center_of_mem_sphere' hp\u2082 hp\u2081)\n\n/-- Given two points on a circle, the center of that circle may be expressed explicitly as a\nmultiple (by half the tangent of the angle between the chord and the radius at one of those\npoints) of a `\u03c0 / 2` rotation of the vector between those points, plus the midpoint of those\npoints. -/\nlemma tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center {s : sphere P} {p\u2081 p\u2082 : P}\n  (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2208 s) (h : p\u2081 \u2260 p\u2082) :\n  (real.angle.tan (\u2221 p\u2082 p\u2081 s.center) / 2) \u2022 ((o).rotation (\u03c0 / 2 : \u211d) (p\u2082 -\u1d65 p\u2081)) +\u1d65\n    midpoint \u211d p\u2081 p\u2082 = s.center :=\nbegin\n  obtain \u27e8r, hr\u27e9 := (dist_eq_iff_eq_smul_rotation_pi_div_two_vadd_midpoint h).1\n    (dist_center_eq_dist_center_of_mem_sphere hp\u2081 hp\u2082),\n  rw [\u2190hr, \u2190oangle_midpoint_rev_left, oangle, vadd_vsub_assoc],\n  nth_rewrite 0 (show p\u2082 -\u1d65 p\u2081 = (2 : \u211d) \u2022 (midpoint \u211d p\u2081 p\u2082 -\u1d65 p\u2081), by simp),\n  rw [map_smul, smul_smul, add_comm, (o).tan_oangle_add_right_smul_rotation_pi_div_two,\n      mul_div_cancel _ (two_ne_zero' \u211d)],\n  simpa using h.symm\nend\n\n/-- Given three points on a circle, the center of that circle may be expressed explicitly as a\nmultiple (by half the inverse of the tangent of the angle at one of those points) of a `\u03c0 / 2`\nrotation of the vector between the other two points, plus the midpoint of those points. -/\nlemma inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center {s : sphere P}\n  {p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2208 s) (hp\u2083 : p\u2083 \u2208 s) (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083)\n  (hp\u2082p\u2083 : p\u2082 \u2260 p\u2083) :\n  ((real.angle.tan (\u2221 p\u2081 p\u2082 p\u2083))\u207b\u00b9 / 2) \u2022 ((o).rotation (\u03c0 / 2 : \u211d) (p\u2083 -\u1d65 p\u2081)) +\u1d65\n    midpoint \u211d p\u2081 p\u2083 = s.center :=\nbegin\n  convert tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center hp\u2081 hp\u2083 hp\u2081p\u2083,\n  convert (real.angle.tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi _).symm,\n  rw [add_comm,\n      two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi hp\u2081 hp\u2082 hp\u2083 hp\u2081p\u2082.symm hp\u2082p\u2083 hp\u2081p\u2083]\nend\n\n/-- Given two points on a circle, the radius of that circle may be expressed explicitly as half\nthe distance between those two points divided by the cosine of the angle between the chord and\nthe radius at one of those points. -/\nlemma dist_div_cos_oangle_center_div_two_eq_radius {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) (h : p\u2081 \u2260 p\u2082) : dist p\u2081 p\u2082 / real.angle.cos (\u2221 p\u2082 p\u2081 s.center) / 2 = s.radius :=\nbegin\n  rw [div_right_comm, div_eq_mul_inv _ (2 : \u211d), mul_comm,\n      (show (2 : \u211d)\u207b\u00b9 * dist p\u2081 p\u2082 = dist p\u2081 (midpoint \u211d p\u2081 p\u2082), by simp), \u2190mem_sphere.1 hp\u2081,\n      \u2190tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center hp\u2081 hp\u2082 h,\n      \u2190oangle_midpoint_rev_left, oangle, vadd_vsub_assoc,\n      (show p\u2082 -\u1d65 p\u2081 = (2 : \u211d) \u2022 (midpoint \u211d p\u2081 p\u2082 -\u1d65 p\u2081), by simp), map_smul, smul_smul,\n      div_mul_cancel _ (two_ne_zero' \u211d), @dist_eq_norm_vsub' V, @dist_eq_norm_vsub' V,\n      vadd_vsub_assoc, add_comm, (o).oangle_add_right_smul_rotation_pi_div_two,\n      real.angle.cos_coe, real.cos_arctan, one_div, div_inv_eq_mul,\n      \u2190mul_self_inj (mul_nonneg (norm_nonneg _) (real.sqrt_nonneg _)) (norm_nonneg _),\n      norm_add_sq_eq_norm_sq_add_norm_sq_real ((o).inner_smul_rotation_pi_div_two_right _ _),\n      \u2190mul_assoc, mul_comm, mul_comm _ (real.sqrt _), \u2190mul_assoc, \u2190mul_assoc,\n      real.mul_self_sqrt (add_nonneg zero_le_one (sq_nonneg _)), norm_smul,\n      linear_isometry_equiv.norm_map],\n  swap, { simpa using h.symm },\n  conv_rhs { rw [\u2190mul_assoc, mul_comm _ \u2016real.angle.tan _\u2016, \u2190mul_assoc, real.norm_eq_abs,\n                 abs_mul_abs_self] },\n  ring\nend\n\n/-- Given two points on a circle, twice the radius of that circle may be expressed explicitly as\nthe distance between those two points divided by the cosine of the angle between the chord and\nthe radius at one of those points. -/\nlemma dist_div_cos_oangle_center_eq_two_mul_radius {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) (h : p\u2081 \u2260 p\u2082) : dist p\u2081 p\u2082 / real.angle.cos (\u2221 p\u2082 p\u2081 s.center) = 2 * s.radius :=\nby rw [\u2190dist_div_cos_oangle_center_div_two_eq_radius hp\u2081 hp\u2082 h,\n       mul_div_cancel' _ (two_ne_zero' \u211d)]\n\n/-- Given three points on a circle, the radius of that circle may be expressed explicitly as half\nthe distance between two of those points divided by the absolute value of the sine of the angle\nat the third point (a version of the law of sines or sine rule). -/\nlemma dist_div_sin_oangle_div_two_eq_radius {s : sphere P} {p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) (hp\u2083 : p\u2083 \u2208 s) (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) (hp\u2082p\u2083 : p\u2082 \u2260 p\u2083) :\n  dist p\u2081 p\u2083 / |real.angle.sin (\u2221 p\u2081 p\u2082 p\u2083)| / 2 = s.radius :=\nbegin\n  convert dist_div_cos_oangle_center_div_two_eq_radius hp\u2081 hp\u2083 hp\u2081p\u2083,\n  rw [\u2190real.angle.abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi\n        (two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi\n          hp\u2081 hp\u2082 hp\u2083 hp\u2081p\u2082.symm hp\u2082p\u2083 hp\u2081p\u2083),\n      _root_.abs_of_nonneg (real.angle.cos_nonneg_iff_abs_to_real_le_pi_div_two.2 _)],\n  exact (abs_oangle_center_right_to_real_lt_pi_div_two hp\u2081 hp\u2083).le\nend\n\n/-- Given three points on a circle, twice the radius of that circle may be expressed explicitly as\nthe distance between two of those points divided by the absolute value of the sine of the angle\nat the third point (a version of the law of sines or sine rule). -/\nlemma dist_div_sin_oangle_eq_two_mul_radius {s : sphere P} {p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) (hp\u2083 : p\u2083 \u2208 s) (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) (hp\u2082p\u2083 : p\u2082 \u2260 p\u2083) :\n  dist p\u2081 p\u2083 / |real.angle.sin (\u2221 p\u2081 p\u2082 p\u2083)| = 2 * s.radius :=\nby rw [\u2190dist_div_sin_oangle_div_two_eq_radius hp\u2081 hp\u2082 hp\u2083 hp\u2081p\u2082 hp\u2081p\u2083 hp\u2082p\u2083,\n       mul_div_cancel' _ (two_ne_zero' \u211d)]\n\nend sphere\n\nend euclidean_geometry\n\nnamespace affine\nnamespace triangle\n\nopen euclidean_geometry\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\n  [hd2 : fact (finrank \u211d V = 2)] [module.oriented \u211d V (fin 2)]\ninclude hd2\n\nlocal notation `o` := module.oriented.positive_orientation\n\n/-- The circumcenter of a triangle may be expressed explicitly as a multiple (by half the inverse\nof the tangent of the angle at one of the vertices) of a `\u03c0 / 2` rotation of the vector between\nthe other two vertices, plus the midpoint of those vertices. -/\nlemma inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_circumcenter (t : triangle \u211d P)\n  {i\u2081 i\u2082 i\u2083 : fin 3} (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083) :\n  ((real.angle.tan (\u2221 (t.points i\u2081) (t.points i\u2082) (t.points i\u2083)))\u207b\u00b9 / 2) \u2022\n    ((o).rotation (\u03c0 / 2 : \u211d) (t.points i\u2083 -\u1d65 t.points i\u2081)) +\u1d65\n    midpoint \u211d (t.points i\u2081) (t.points i\u2083) = t.circumcenter :=\nsphere.inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center\n  (t.mem_circumsphere _) (t.mem_circumsphere _) (t.mem_circumsphere _)\n  (t.independent.injective.ne h\u2081\u2082) (t.independent.injective.ne h\u2081\u2083) (t.independent.injective.ne h\u2082\u2083)\n\n/-- The circumradius of a triangle may be expressed explicitly as half the length of a side\ndivided by the absolute value of the sine of the angle at the third point (a version of the law\nof sines or sine rule). -/\nlemma dist_div_sin_oangle_div_two_eq_circumradius (t : triangle \u211d P) {i\u2081 i\u2082 i\u2083 : fin 3}\n  (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083) :\n  dist (t.points i\u2081) (t.points i\u2083) /\n    |real.angle.sin (\u2221 (t.points i\u2081) (t.points i\u2082) (t.points i\u2083))| / 2 = t.circumradius :=\nsphere.dist_div_sin_oangle_div_two_eq_radius (t.mem_circumsphere _) (t.mem_circumsphere _)\n  (t.mem_circumsphere _) (t.independent.injective.ne h\u2081\u2082) (t.independent.injective.ne h\u2081\u2083)\n  (t.independent.injective.ne h\u2082\u2083)\n\n/-- Twice the circumradius of a triangle may be expressed explicitly as the length of a side\ndivided by the absolute value of the sine of the angle at the third point (a version of the law\nof sines or sine rule). -/\nlemma dist_div_sin_oangle_eq_two_mul_circumradius (t : triangle \u211d P) {i\u2081 i\u2082 i\u2083 : fin 3}\n  (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083) :\n  dist (t.points i\u2081) (t.points i\u2083) /\n    |real.angle.sin (\u2221 (t.points i\u2081) (t.points i\u2082) (t.points i\u2083))| = 2 * t.circumradius :=\nsphere.dist_div_sin_oangle_eq_two_mul_radius (t.mem_circumsphere _) (t.mem_circumsphere _)\n  (t.mem_circumsphere _) (t.independent.injective.ne h\u2081\u2082) (t.independent.injective.ne h\u2081\u2083)\n  (t.independent.injective.ne h\u2082\u2083)\n\n/-- The circumsphere of a triangle may be expressed explicitly in terms of two points and the\nangle at the third point. -/\nlemma circumsphere_eq_of_dist_of_oangle (t : triangle \u211d P) {i\u2081 i\u2082 i\u2083 : fin 3} (h\u2081\u2082 : i\u2081 \u2260 i\u2082)\n  (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083) :\n  t.circumsphere = \u27e8((real.angle.tan (\u2221 (t.points i\u2081) (t.points i\u2082) (t.points i\u2083)))\u207b\u00b9 / 2) \u2022\n      ((o).rotation (\u03c0 / 2 : \u211d) (t.points i\u2083 -\u1d65 t.points i\u2081)) +\u1d65\n      midpoint \u211d (t.points i\u2081) (t.points i\u2083),\n    dist (t.points i\u2081) (t.points i\u2083) /\n      |real.angle.sin (\u2221 (t.points i\u2081) (t.points i\u2082) (t.points i\u2083))| / 2\u27e9 :=\nt.circumsphere.ext _\n  (t.inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_circumcenter h\u2081\u2082 h\u2081\u2083 h\u2082\u2083).symm\n  (t.dist_div_sin_oangle_div_two_eq_circumradius h\u2081\u2082 h\u2081\u2083 h\u2082\u2083).symm\n\n/-- If two triangles have two points the same, and twice the angle at the third point the same,\nthey have the same circumsphere. -/\nlemma circumsphere_eq_circumsphere_of_eq_of_eq_of_two_zsmul_oangle_eq {t\u2081 t\u2082 : triangle \u211d P}\n  {i\u2081 i\u2082 i\u2083 : fin 3} (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083)\n  (h\u2081 : t\u2081.points i\u2081 = t\u2082.points i\u2081) (h\u2083 : t\u2081.points i\u2083 = t\u2082.points i\u2083)\n  (h\u2082 : (2 : \u2124) \u2022 \u2221 (t\u2081.points i\u2081) (t\u2081.points i\u2082) (t\u2081.points i\u2083) =\n    (2 : \u2124) \u2022 \u2221 (t\u2082.points i\u2081) (t\u2082.points i\u2082) (t\u2082.points i\u2083)) :\n  t\u2081.circumsphere = t\u2082.circumsphere :=\nbegin\n  rw [t\u2081.circumsphere_eq_of_dist_of_oangle h\u2081\u2082 h\u2081\u2083 h\u2082\u2083,\n      t\u2082.circumsphere_eq_of_dist_of_oangle h\u2081\u2082 h\u2081\u2083 h\u2082\u2083],\n  congrm \u27e8((_ : \u211d)\u207b\u00b9 / 2) \u2022 _ +\u1d65 _, _ / _ / 2\u27e9,\n  { exact real.angle.tan_eq_of_two_zsmul_eq h\u2082 },\n  { rw [h\u2081, h\u2083] },\n  { rw [h\u2081, h\u2083] },\n  { rw [h\u2081, h\u2083] },\n  { exact real.angle.abs_sin_eq_of_two_zsmul_eq h\u2082 }\nend\n\n/-- Given a triangle, and a fourth point such that twice the angle between two points of the\ntriangle at that fourth point equals twice the third angle of the triangle, the fourth point\nlies in the circumsphere of the triangle. -/\nlemma mem_circumsphere_of_two_zsmul_oangle_eq {t : triangle \u211d P} {p : P} {i\u2081 i\u2082 i\u2083 : fin 3}\n  (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083)\n  (h : (2 : \u2124) \u2022 \u2221 (t.points i\u2081) p (t.points i\u2083) =\n    (2 : \u2124) \u2022 \u2221 (t.points i\u2081) (t.points i\u2082) (t.points i\u2083)) : p \u2208 t.circumsphere :=\nbegin\n  let t'p : fin 3 \u2192 P := function.update t.points i\u2082 p,\n  have h\u2081 : t'p i\u2081 = t.points i\u2081, { simp [t'p, h\u2081\u2082] },\n  have h\u2082 : t'p i\u2082 = p, { simp [t'p] },\n  have h\u2083 : t'p i\u2083 = t.points i\u2083, { simp [t'p, h\u2082\u2083.symm] },\n  have ha : affine_independent \u211d t'p,\n  { rw [affine_independent_iff_not_collinear_of_ne h\u2081\u2082 h\u2081\u2083 h\u2082\u2083, h\u2081, h\u2082, h\u2083,\n        collinear_iff_of_two_zsmul_oangle_eq h,\n        \u2190affine_independent_iff_not_collinear_of_ne h\u2081\u2082 h\u2081\u2083 h\u2082\u2083],\n    exact t.independent },\n  let t' : triangle \u211d P := \u27e8t'p, ha\u27e9,\n  have h\u2081' : t'.points i\u2081 = t.points i\u2081 := h\u2081,\n  have h\u2082' : t'.points i\u2082 = p := h\u2082,\n  have h\u2083' : t'.points i\u2083 = t.points i\u2083 := h\u2083,\n  have h' : (2 : \u2124) \u2022 \u2221 (t'.points i\u2081) (t'.points i\u2082) (t'.points i\u2083) =\n    (2 : \u2124) \u2022 \u2221 (t.points i\u2081) (t.points i\u2082) (t.points i\u2083), { rwa [h\u2081', h\u2082', h\u2083'] },\n  rw [\u2190circumsphere_eq_circumsphere_of_eq_of_eq_of_two_zsmul_oangle_eq h\u2081\u2082 h\u2081\u2083 h\u2082\u2083 h\u2081' h\u2083' h',\n      \u2190h\u2082'],\n  exact simplex.mem_circumsphere _ _\nend\n\nend triangle\nend affine\n\nnamespace euclidean_geometry\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\n  [hd2 : fact (finrank \u211d V = 2)] [module.oriented \u211d V (fin 2)]\ninclude hd2\n\nlocal notation `o` := module.oriented.positive_orientation\n\n/-- Converse of \"angles in same segment are equal\" and \"opposite angles of a cyclic quadrilateral\nadd to \u03c0\", for oriented angles mod \u03c0. -/\nlemma cospherical_of_two_zsmul_oangle_eq_of_not_collinear {p\u2081 p\u2082 p\u2083 p\u2084 : P}\n  (h : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2084 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2083 p\u2084) (hn : \u00accollinear \u211d ({p\u2081, p\u2082, p\u2084} : set P)) :\n  cospherical ({p\u2081, p\u2082, p\u2083, p\u2084} : set P) :=\nbegin\n  have hn' : \u00accollinear \u211d ({p\u2081, p\u2083, p\u2084} : set P), { rwa \u2190collinear_iff_of_two_zsmul_oangle_eq h },\n  let t\u2081 : affine.triangle \u211d P := \u27e8![p\u2081, p\u2082, p\u2084], affine_independent_iff_not_collinear_set.2 hn\u27e9,\n  let t\u2082 : affine.triangle \u211d P := \u27e8![p\u2081, p\u2083, p\u2084], affine_independent_iff_not_collinear_set.2 hn'\u27e9,\n  rw cospherical_iff_exists_sphere,\n  refine \u27e8t\u2082.circumsphere, _\u27e9,\n  simp_rw [set.insert_subset, set.singleton_subset_iff],\n  refine \u27e8t\u2082.mem_circumsphere 0, _, t\u2082.mem_circumsphere 1, t\u2082.mem_circumsphere 2\u27e9,\n  rw affine.triangle.circumsphere_eq_circumsphere_of_eq_of_eq_of_two_zsmul_oangle_eq\n    (dec_trivial : (0 : fin 3) \u2260 1) (dec_trivial: (0 : fin 3) \u2260 2) dec_trivial\n    (show t\u2082.points 0 = t\u2081.points 0, from rfl) rfl h.symm,\n  exact t\u2081.mem_circumsphere 1\nend\n\n/-- Converse of \"angles in same segment are equal\" and \"opposite angles of a cyclic quadrilateral\nadd to \u03c0\", for oriented angles mod \u03c0, with a \"concyclic\" conclusion. -/\nlemma concyclic_of_two_zsmul_oangle_eq_of_not_collinear {p\u2081 p\u2082 p\u2083 p\u2084 : P}\n  (h : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2084 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2083 p\u2084) (hn : \u00accollinear \u211d ({p\u2081, p\u2082, p\u2084} : set P)) :\n  concyclic ({p\u2081, p\u2082, p\u2083, p\u2084} : set P) :=\n\u27e8cospherical_of_two_zsmul_oangle_eq_of_not_collinear h hn, coplanar_of_fact_finrank_eq_two _\u27e9\n\n/-- Converse of \"angles in same segment are equal\" and \"opposite angles of a cyclic quadrilateral\nadd to \u03c0\", for oriented angles mod \u03c0, with a \"cospherical or collinear\" conclusion. -/\nlemma cospherical_or_collinear_of_two_zsmul_oangle_eq {p\u2081 p\u2082 p\u2083 p\u2084 : P}\n  (h : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2084 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2083 p\u2084) :\n  cospherical ({p\u2081, p\u2082, p\u2083, p\u2084} : set P) \u2228 collinear \u211d ({p\u2081, p\u2082, p\u2083, p\u2084} : set P) :=\nbegin\n  by_cases hc : collinear \u211d ({p\u2081, p\u2082, p\u2084} : set P),\n  { by_cases he : p\u2081 = p\u2084,\n    { rw [he, set.insert_eq_self.2 (set.mem_insert_of_mem _ (set.mem_insert_of_mem _\n            (set.mem_singleton _)))],\n      by_cases hl : collinear \u211d ({p\u2082, p\u2083, p\u2084} : set P), { exact or.inr hl },\n      rw or_iff_left hl,\n      let t : affine.triangle \u211d P := \u27e8![p\u2082, p\u2083, p\u2084], affine_independent_iff_not_collinear_set.2 hl\u27e9,\n      rw cospherical_iff_exists_sphere,\n      refine \u27e8t.circumsphere, _\u27e9,\n      simp_rw [set.insert_subset, set.singleton_subset_iff],\n      exact \u27e8t.mem_circumsphere 0, t.mem_circumsphere 1, t.mem_circumsphere 2\u27e9 },\n    have hc' : collinear \u211d ({p\u2081, p\u2083, p\u2084} : set P),\n    { rwa [\u2190collinear_iff_of_two_zsmul_oangle_eq h] },\n    refine or.inr _,\n    rw set.insert_comm p\u2081 p\u2082 at hc,\n    rwa [set.insert_comm p\u2081 p\u2082, hc'.collinear_insert_iff_of_ne (set.mem_insert _ _)\n           (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_singleton _))) he] },\n  { exact or.inl (cospherical_of_two_zsmul_oangle_eq_of_not_collinear h hc) }\nend\n\n/-- Converse of \"angles in same segment are equal\" and \"opposite angles of a cyclic quadrilateral\nadd to \u03c0\", for oriented angles mod \u03c0, with a \"concyclic or collinear\" conclusion. -/\nlemma concyclic_or_collinear_of_two_zsmul_oangle_eq {p\u2081 p\u2082 p\u2083 p\u2084 : P}\n  (h : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2084 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2083 p\u2084) :\n  concyclic ({p\u2081, p\u2082, p\u2083, p\u2084} : set P) \u2228 collinear \u211d ({p\u2081, p\u2082, p\u2083, p\u2084} : set P) :=\nbegin\n  rcases cospherical_or_collinear_of_two_zsmul_oangle_eq h with hc | hc,\n  { exact or.inl \u27e8hc, coplanar_of_fact_finrank_eq_two _\u27e9 },\n  { exact or.inr hc }\nend\n\nend euclidean_geometry\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/angle/sphere.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7282944832045307}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.lp_space\nimport analysis.normed_space.pi_Lp\nimport topology.continuous_function.bounded\n\n/-!\n# Equivalences among $L^p$ spaces\n\nIn this file we collect a variety of equivalences among various $L^p$ spaces.  In particular,\nwhen `\u03b1` is a `fintype`, given `E : \u03b1 \u2192 Type u` and `p : \u211d\u22650\u221e`, there is a natural linear isometric\nequivalence `lp_pi_Lp\u2097\u1d62 : lp E p \u2243\u2097\u1d62 pi_Lp p E`. In addition, when `\u03b1` is a discrete topological\nspace, the bounded continuous functions `\u03b1 \u2192\u1d47 \u03b2` correspond exactly to `lp (\u03bb _, \u03b2) \u221e`. Here there\ncan be more structure, including ring and algebra structures, and we implement these equivalences\naccordingly as well.\n\nWe keep this as a separate file so that the various $L^p$ space files don't import the others.\n\nRecall that `pi_Lp` is just a type synonym for `\u03a0 i, E i` but given a different metric and norm\nstructure, although the topological, uniform and bornological structures coincide definitionally.\nThese structures are only defined on `pi_Lp` for `fintype \u03b1`, so there are no issues of convergence\nto consider.\n\nWhile `pre_lp` is also a type synonym for `\u03a0 i, E i`, it allows for infinite index types. On this\ntype there is a predicate `mem_\u2113p` which says that the relevant `p`-norm is finite and `lp E p` is\nthe subtype of `pre_lp` satisfying `mem_\u2113p`.\n\n## TODO\n\n* Equivalence between `lp` and `measure_theory.Lp`, for `f : \u03b1 \u2192 E` (i.e., functions rather than\n  pi-types) and the counting measure on `\u03b1`\n\n-/\n\nopen_locale ennreal\n\nsection lp_pi_Lp\n\nvariables {\u03b1 : Type*} {E : \u03b1 \u2192 Type*} [\u03a0 i, normed_add_comm_group (E i)] {p : \u211d\u22650\u221e}\n\n/-- When `\u03b1` is `finite`, every `f : pre_lp E p` satisfies `mem_\u2113p f p`. -/\nlemma mem_\u2113p.all [finite \u03b1] (f : \u03a0 i, E i) : mem_\u2113p f p :=\nbegin\n  rcases p.trichotomy with (rfl | rfl | h),\n  { exact mem_\u2113p_zero_iff.mpr {i : \u03b1 | f i \u2260 0}.to_finite, },\n  { exact mem_\u2113p_infty_iff.mpr (set.finite.bdd_above (set.range (\u03bb (i : \u03b1), \u2016f i\u2016)).to_finite) },\n  { casesI nonempty_fintype \u03b1, exact mem_\u2113p_gen \u27e8finset.univ.sum _, has_sum_fintype _\u27e9 }\nend\n\nvariables [fintype \u03b1]\n\n/-- The canonical `equiv` between `lp E p \u2243 pi_Lp p E` when `E : \u03b1 \u2192 Type u` with `[fintype \u03b1]`. -/\ndef equiv.lp_pi_Lp : lp E p \u2243 pi_Lp p E :=\n{ to_fun := \u03bb f, f,\n  inv_fun := \u03bb f, \u27e8f, mem_\u2113p.all f\u27e9,\n  left_inv := \u03bb f, lp.ext $ funext $ \u03bb x, rfl,\n  right_inv := \u03bb f, funext $ \u03bb x, rfl }\n\nlemma coe_equiv_lp_pi_Lp (f : lp E p) : equiv.lp_pi_Lp f = f := rfl\nlemma coe_equiv_lp_pi_Lp_symm (f : pi_Lp p E) : (equiv.lp_pi_Lp.symm f : \u03a0 i, E i) = f :=  rfl\n\nlemma equiv_lp_pi_Lp_norm (f : lp E p) : \u2016equiv.lp_pi_Lp f\u2016 = \u2016f\u2016 :=\nbegin\n  unfreezingI { rcases p.trichotomy with (rfl | rfl | h) },\n  { rw [pi_Lp.norm_eq_card, lp.norm_eq_card_dsupport], refl },\n  { rw [pi_Lp.norm_eq_csupr, lp.norm_eq_csupr], refl },\n  { rw [pi_Lp.norm_eq_sum h, lp.norm_eq_tsum_rpow h, tsum_fintype], refl },\nend\n\n/-- The canonical `add_equiv` between `lp E p` and `pi_Lp p E` when `E : \u03b1 \u2192 Type u` with\n`[fintype \u03b1]` and `[fact (1 \u2264 p)]`. -/\ndef add_equiv.lp_pi_Lp [fact (1 \u2264 p)] : lp E p \u2243+ pi_Lp p E :=\n{ map_add' := \u03bb f g, rfl,\n  .. equiv.lp_pi_Lp }\n\nlemma coe_add_equiv_lp_pi_Lp [fact (1 \u2264 p)] (f : lp E p) :\n  add_equiv.lp_pi_Lp f = f := rfl\nlemma coe_add_equiv_lp_pi_Lp_symm [fact (1 \u2264 p)] (f : pi_Lp p E) :\n  (add_equiv.lp_pi_Lp.symm f : \u03a0 i, E i) = f :=  rfl\n\nsection equiv\u2097\u1d62\nvariables (\ud835\udd5c : Type*) [nontrivially_normed_field \ud835\udd5c] [\u03a0 i, normed_space \ud835\udd5c (E i)]\n\n/-- The canonical `linear_isometry_equiv` between `lp E p` and `pi_Lp p E` when `E : \u03b1 \u2192 Type u`\nwith `[fintype \u03b1]` and `[fact (1 \u2264 p)]`. -/\nnoncomputable def lp_pi_Lp\u2097\u1d62 [fact (1 \u2264 p)] : lp E p \u2243\u2097\u1d62[\ud835\udd5c] pi_Lp p E :=\n{ map_smul' := \u03bb k f, rfl,\n  norm_map' := equiv_lp_pi_Lp_norm,\n  .. add_equiv.lp_pi_Lp }\n\nvariables {\ud835\udd5c}\n\nlemma coe_lp_pi_Lp\u2097\u1d62 [fact (1 \u2264 p)] (f : lp E p) :\n  lp_pi_Lp\u2097\u1d62 \ud835\udd5c f = f := rfl\nlemma coe_lp_pi_Lp\u2097\u1d62_symm [fact (1 \u2264 p)] (f : pi_Lp p E) :\n  ((lp_pi_Lp\u2097\u1d62 \ud835\udd5c).symm f : \u03a0 i, E i) = f :=  rfl\n\nend equiv\u2097\u1d62\n\nend lp_pi_Lp\n\nsection lp_bcf\n\nopen_locale bounded_continuous_function\nopen bounded_continuous_function\n\n-- note: `R` and `A` are explicit because otherwise Lean has elaboration problems\nvariables {\u03b1 E : Type*} (R A \ud835\udd5c : Type*) [topological_space \u03b1] [discrete_topology \u03b1]\nvariables [normed_ring A] [norm_one_class A] [nontrivially_normed_field \ud835\udd5c] [normed_algebra \ud835\udd5c A]\nvariables [normed_add_comm_group E] [normed_space \ud835\udd5c E] [non_unital_normed_ring R]\n\n\nsection normed_add_comm_group\n\n/-- The canonical map between `lp (\u03bb (_ : \u03b1), E) \u221e` and `\u03b1 \u2192\u1d47 E` as an `add_equiv`. -/\nnoncomputable def add_equiv.lp_bcf :\n  lp (\u03bb (_ : \u03b1), E) \u221e \u2243+ (\u03b1 \u2192\u1d47 E) :=\n{ to_fun := \u03bb f, of_normed_add_comm_group_discrete f (\u2016f\u2016) $ le_csupr (mem_\u2113p_infty_iff.mp f.prop),\n  inv_fun := \u03bb f, \u27e8f, f.bdd_above_range_norm_comp\u27e9,\n  left_inv := \u03bb f, lp.ext rfl,\n  right_inv := \u03bb f, ext $ \u03bb x, rfl,\n  map_add' := \u03bb f g, ext $ \u03bb x, rfl }\n\nlemma coe_add_equiv_lp_bcf (f : lp (\u03bb (_ : \u03b1), E) \u221e) :\n  (add_equiv.lp_bcf f : \u03b1 \u2192 E) = f := rfl\nlemma coe_add_equiv_lp_bcf_symm (f : \u03b1 \u2192\u1d47 E) : (add_equiv.lp_bcf.symm f : \u03b1 \u2192 E) = f := rfl\n\n/-- The canonical map between `lp (\u03bb (_ : \u03b1), E) \u221e` and `\u03b1 \u2192\u1d47 E` as a `linear_isometry_equiv`. -/\nnoncomputable def lp_bcf\u2097\u1d62 : lp (\u03bb (_ : \u03b1), E) \u221e \u2243\u2097\u1d62[\ud835\udd5c] (\u03b1 \u2192\u1d47 E) :=\n{ map_smul' := \u03bb k f, rfl,\n  norm_map' := \u03bb f, by { simp only [norm_eq_supr_norm, lp.norm_eq_csupr], refl },\n  .. add_equiv.lp_bcf }\n\nvariables {\ud835\udd5c}\n\nlemma coe_lp_bcf\u2097\u1d62 (f : lp (\u03bb (_ : \u03b1), E) \u221e) : (lp_bcf\u2097\u1d62 \ud835\udd5c f : \u03b1 \u2192 E) = f := rfl\nlemma coe_lp_bcf\u2097\u1d62_symm (f : \u03b1 \u2192\u1d47 E) : ((lp_bcf\u2097\u1d62 \ud835\udd5c).symm f : \u03b1 \u2192 E) = f :=  rfl\n\nend normed_add_comm_group\n\nsection ring_algebra\n\n/-- The canonical map between `lp (\u03bb (_ : \u03b1), R) \u221e` and `\u03b1 \u2192\u1d47 R` as a `ring_equiv`. -/\nnoncomputable def ring_equiv.lp_bcf : lp (\u03bb (_ : \u03b1), R) \u221e \u2243+* (\u03b1 \u2192\u1d47 R) :=\n{ map_mul' := \u03bb f g, ext $ \u03bb x, rfl, .. @add_equiv.lp_bcf _ R _ _ _ }\n\nvariables {R}\nlemma coe_ring_equiv_lp_bcf (f : lp (\u03bb (_ : \u03b1), R) \u221e) :\n  (ring_equiv.lp_bcf R f : \u03b1 \u2192 R) = f := rfl\nlemma coe_ring_equiv_lp_bcf_symm (f : \u03b1 \u2192\u1d47 R) :\n  ((ring_equiv.lp_bcf R).symm f : \u03b1 \u2192 R) = f := rfl\n\nvariables (\u03b1) -- even `\u03b1` needs to be explicit here for elaboration\n\n-- the `norm_one_class A` shouldn't really be necessary, but currently it is for\n-- `one_mem_\u2113p_infty` to get the `ring` instance on `lp`.\n/-- The canonical map between `lp (\u03bb (_ : \u03b1), A) \u221e` and `\u03b1 \u2192\u1d47 A` as an `alg_equiv`. -/\nnoncomputable def alg_equiv.lp_bcf : lp (\u03bb (_ : \u03b1), A) \u221e \u2243\u2090[\ud835\udd5c] (\u03b1 \u2192\u1d47 A) :=\n{ commutes' := \u03bb k, rfl, .. ring_equiv.lp_bcf A }\n\nvariables {\u03b1 A \ud835\udd5c}\nlemma coe_alg_equiv_lp_bcf (f : lp (\u03bb (_ : \u03b1), A) \u221e) :\n  (alg_equiv.lp_bcf \u03b1 A \ud835\udd5c f : \u03b1 \u2192 A) = f := rfl\nlemma coe_alg_equiv_lp_bcf_symm (f : \u03b1 \u2192\u1d47 A) :\n  ((alg_equiv.lp_bcf \u03b1 A \ud835\udd5c).symm f : \u03b1 \u2192 A) = f := rfl\n\nend ring_algebra\n\nend lp_bcf\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/lp_equiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7282944769236402}}
{"text": "import MyNat.Definition\nimport MyNat.Addition -- add_succ\nimport MyNat.Multiplication -- mul_succ\nimport AdvancedAdditionWorld.Level9 -- succ_ne_zero\nimport Mathlib.Tactic.LeftRight\nnamespace MyNat\nopen MyNat\n\n/-!\n# Advanced Multiplication World\n\n## Level 2: `eq_zero_or_eq_zero_of_mul_eq_zero`\n\nA variant on the previous level.\n\n## Theorem\nIf `ab = 0`, then at least one of `a` or `b` is equal to zero.\n-/\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero (a b : MyNat) (h : a * b = 0) :\n  a = 0 \u2228 b = 0 := by\n  cases a with\n  | zero =>\n    left\n    rfl\n  | succ a' =>\n    cases b with\n    | zero =>\n      right\n      rfl\n    | succ b' =>\n      exfalso\n      rw [mul_succ] at h\n      rw [add_succ] at h\n      exact succ_ne_zero _ h\n/-!\n\nNext up [Level 3](./Level3.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedMultiplicationWorld/Level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7282938878538081}}
{"text": "import xenalib.nat_stuff\nimport chris_hughes_various.zmod\n\n/- Here is my memory of the situation Clara and Jason were faced with -/\n--set_option pp.all true\n--set_option pp.notation false\nexample (a : \u2115) (p : \u2115) [pos_nat p] (Hodd : 2 \u2223 (p - 1)) (x : \u2124) \n  (H1 : \u2191(a ^ (p - 1)) - 1 \u2261 0 [ZMOD \u2191p]) \n  (H2 : x \u2261 (\u2191a)^2 [ZMOD \u2191p]) :\nx ^ ((p-1) / 2) \u2261 1 [ZMOD \u2191p] :=\n-- A mathematician would just say \"substitute x = a^2 and we're done\"\n-- Lean says \"naturals aren't integers, and congruence is not equality, so no\"\n-- I say \"that's OK, we just explain to Lean exactly why things which are\n-- \"obviously equal\" are equal\"\nbegin\n  rw nat.cast_pow' a 2 at H2,\n  rw \u2190zmod.eq_iff_modeq_int at H2,\n  -- H2 now an equality in the ring Z/pZ\n  rw \u2190zmod.eq_iff_modeq_int,\n  rw \u2190int.cast_pow,\n  -- we can finally rewrite!\n  rw H2,\n  -- we now have to convince Lean that this is just H1\n  rw int.cast_pow,\n  rw nat.cast_pow',\n  rw nat.pow_pow,\n  rw nat.mul_div (show 2 \u2260 0, from dec_trivial) Hodd,\n  apply eq_of_sub_eq_zero,\n  rw \u2190int.cast_sub,\n  rw \u2190zmod.eq_iff_modeq_int at H1,\n  exact H1\nend \n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M3P14/pow_example.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7282663582615265}}
{"text": "/-\nCopyright (c) 2021 Adri\u00e1n Do\u00f1a Mateo. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Adri\u00e1n Do\u00f1a Mateo\n-/\n\nimport data.real.basic\nimport data.real.sqrt\n\n/-!\n# IMO 2017 Q2\n\nLet `\u211d` be the set of real numbers. Determine all functions `f : \u211d \u2192 \u211d` such that, for\nall real numbers `x` and `y`,\n\n  `f (f x * f y) + f (x + y) = f (x * y)`.\n\nThis solution is a translation of the official solution, which may be found as the\nsolution to problem A6 [here](https://www.imo-official.org/problems/IMO2017SL.pdf).\n-/\n\nopen real\n\n/-- A predicate defining what it means for a function to be a solution. -/\ndef sol (f : \u211d \u2192 \u211d) : Prop := \u2200 x y, f (f x * f y) + f (x + y) = f (x * y)\n\n/-- The negation of a function. -/\ndef neg (f : \u211d \u2192 \u211d) : \u211d \u2192 \u211d := \u03bb x, - f x\n\nlemma neg_neg_f (f : \u211d \u2192 \u211d) : neg (neg f) = f := by simp [neg]\n\n/-- The negation of a solution is also a solution. -/\ntheorem sol_of_neg_sol {f : \u211d \u2192 \u211d} (h : sol f) : sol (neg f) :=\n\u03bb x y,\ncalc - f ((- f x) * (- f y)) + (- f (x + y))\n    = - (f (f x * f y) + f (x + y)) : by rw [neg_mul_neg, neg_add]\n... = - f (x * y)                   : by rw h\n\nlemma sol_mul_eq_zero {f : \u211d \u2192 \u211d} (hf : sol f) (x : \u211d) (hx : x \u2260 1) :\n  f (f x * f (x / (x - 1))) = 0 :=\nhave hxy : x + x / (x - 1) = x * (x / (x - 1)) :=\n  calc x + x / (x - 1)\n      = (x * (x - 1) + x) / (x - 1) : by { rw add_div', intro h,\n                                        rw sub_eq_zero.mp h at hx, contradiction }\n  ... = (x * x) / (x - 1)           : by ring\n  ... = x * (x / (x - 1))           : by rw mul_div_assoc,\nby rw [\u2190 add_sub_cancel (f _) (f (x + x / (x - 1))), hf, hxy, sub_self]\n\n\n/-- A solution has a root at `(f 0)\u00b2`. -/\ntheorem sol_has_zero {f : \u211d \u2192 \u211d} (hf : sol f) : f (f 0 ^ 2) = 0 :=\nby { convert sol_mul_eq_zero hf 0 (by norm_num), simp [pow_two] }\n\ntheorem zero_of_zero_at_zero {f : \u211d \u2192 \u211d} (hf : sol f) (h0 : f 0 = 0) : f = \u03bb _, 0 :=\nfunext $ \u03bb x,\n  calc f x\n      = f (f x * f 0) + f (x + 0) : by simp [h0]\n  ... = f 0                       : by rw [hf, mul_zero]\n  ... = 0                         : h0\n\n/- \nFrom here on, we work on the consequences of assuming that `f 0 < 0`.\nThis is enough, because if `f` is a solution and `f 0 > 0`, then `g = neg f` is a solution with `g 0 < 0`.\n-/\n\n/-- If a solution `f` is negative at `0`, it has a unique root at `1` and `f 0 = -1`. -/\ntheorem of_neg_at_zero {f : \u211d \u2192 \u211d} (hf : sol f) (h0 : f 0 < 0) :\n  f 1 = 0 \u2227 (\u2200 a, f a = 0 \u2192 a = 1) \u2227 f 0 = -1 :=\nbegin\n  have ha : \u2200 a, f a = 0 \u2192 a = 1,\n  { intros a ha, by_contradiction,\n    apply ne_of_lt h0,\n    convert sol_mul_eq_zero hf a h,\n    rw [ha, zero_mul] },\n  have hf02 : f 0 ^ 2 = 1 := ha _ (sol_has_zero hf),\n  use [by rw [\u2190 hf02, sol_has_zero hf], ha],\n  rw [pow_two, mul_self_eq_one_iff] at hf02,\n  cases hf02 with h1 hn1,\n  { linarith },\n  { assumption },\nend\n\n/-- If a solution `f` is negative at `0`, for each integer `n` it satisfies the equation\n  `f (x + n) = f x + n`. -/\ntheorem sol_at_add_n {f : \u211d \u2192 \u211d} (hf : sol f) (h0 : f 0 < 0) : \u2200 x (n : \u2124), f (x + n) = f x + n :=\nbegin\n  rcases of_neg_at_zero hf h0 with \u27e8hf1, _, hf0\u27e9,\n  have hadd1 : \u2200 x, f (x + 1) = f x + 1 :=\n    \u03bb x,\n    calc f (x + 1)\n        = f (f x * f 1) + f (x + 1) + 1 : by simp [hf0, hf1]\n    ... = f x + 1                       : by rw [hf, mul_one],\n  have haddn : \u2200 x (n : \u2115), f (x + n) = f x + n,\n  { intros x n, induction n with n ih, { simp },\n    simp, rw [\u2190 add_assoc, hadd1, ih, add_assoc] },\n  intros x n,\n  cases n with n n,\n  {\texact haddn x n },\n  dsimp,\n  rw [\u2190 sub_eq_add_neg, \u2190 sub_eq_add_neg, eq_sub_iff_add_eq],\n  convert (haddn _ (n + 1)).symm, simp,\nend\n\n/-- This lemma is equivalent to saying that a polynomial `x\u00b2 + ax + b` has roots `x` and `y`\n  whenever `0 \u2264 a\u00b2 - 4b`. -/\nlemma root_of_nonneg_disc {a b : \u211d} (h : 0 \u2264 a * a - 4 * b) :\n  \u2203 x y, x + y = a \u2227 x * y = b :=\nbegin\n  let d := a * a - 4 * b,\n  use [(a + sqrt d) / 2, (a - sqrt d) / 2],\n  split, { ring },\n  rw div_mul_div,\n  calc (a + sqrt d) * (a - sqrt d) / (2 * 2)\n      = (a * a - (sqrt d) * (sqrt d)) / 4 : by ring\n  ... = (a * a - (a * a - 4 * b)) / 4     : by rw [mul_self_sqrt h]\n  ... = b                                 : by ring,\nend\n\n/-- If a solution `f` is negative at `0`, it must be injective. -/\ntheorem f_injective {f : \u211d \u2192 \u211d} (hf : sol f) (h0 : f 0 < 0) : function.injective f :=\nbegin\n  intros a b hfab, by_contradiction,\n  have haddN : \u2200 N : \u2124, f (a + N + 1) = f (b + N) + 1 := \u03bb N,\n    calc f (a + N + 1) \n        = f (a + N + \u2191(1 : \u2124)) : by rw int.cast_one\n    ...\t= f (a + \u2191(N + 1))     : by rw [add_assoc, int.cast_add]\n    ... = f a + \u2191(N + 1)       : by rw sol_at_add_n hf h0\n    ... = f b + \u2191(N + 1)       : by rw hfab\n    ... = f b + N + 1          : by { rw [int.cast_add, \u2190 add_assoc], norm_cast }\n    ... = f (b + N) + 1        : by rw \u2190 sol_at_add_n hf h0,\n  let N := \u2308-b - 1\u2309,\n  have hN : \u2191N < -b := by { simp [N], convert ceil_lt_add_one (-b - 1), ring },\n  have habN : 0 \u2264 (a + N + 1) * (a + N + 1) - 4 * (b + N),\n  {\trw sub_eq_add_neg, apply add_nonneg,\n    {\texact mul_self_nonneg _ }, linarith },\n  rcases root_of_nonneg_disc habN with \u27e8x, y, hxy1, hxy2\u27e9,\n  have hfxy : f x * f y = 0,\n  { rw [\u2190 add_sub_cancel (f x * f y) 1, sub_eq_zero],\n    apply (of_neg_at_zero hf h0).2.1,\n    have : _ :=\n    calc f (f x * f y + \u2191(1 : \u2124))\n        = f (f x * f y) + 1                           : by { rw sol_at_add_n hf h0 _ 1, simp }\n    ... = (f (f x * f y) + f (x + y) - f (x + y)) + 1 : by rw add_sub_cancel\n    ... = (f (x * y) - f (x + y)) + 1                 : by rw hf\n    ... = f (x * y) + 1 - f (x + y)                   : by ring\n    ... = f (b + N) + 1 - f (a + N + 1)               : by rw [hxy1, hxy2]\n    ... = f (a + N + 1) - f (a + N + 1)               : by rw haddN N\n    ... = 0                                           : by rw sub_self,\n    convert this, norm_cast },\n  have hx1 : x \u2260 1,\n  {\tintro hx, rw [hx, one_mul] at hxy2, rw [hx, hxy2] at hxy1,\n    have : a = b := by linarith, exact h this },\n  have hy1 : y \u2260 1,\n  { intro hy, rw [hy, mul_one] at hxy2, rw [hy, hxy2] at hxy1,\n    have : a = b := by linarith, exact h this },\n  cases mul_eq_zero.mp hfxy with hx0 hy0,\n  {\texact hx1 ((of_neg_at_zero hf h0).2.1 _ hx0) },\n  {\texact hy1 ((of_neg_at_zero hf h0).2.1 _ hy0) },\nend\n\nlemma mul_sol_at_neg {f : \u211d \u2192 \u211d} (hf : sol f) (h0 : f 0 < 0) :\n  \u2200 t, f t * f (-t) = -t * t + 1 :=\n\u03bb t, f_injective hf h0 $\n    calc f (f t * f (-t))\n        = f (f t * f (-t)) + f 0 + 1        : by simp [(of_neg_at_zero hf h0).2.2]\n    ... = f (f t * f (-t)) + f (t + -t) + 1 : by rw add_neg_self\n    ... = f (t * -t) + 1                    : by rw hf\n    ... = f (-t * t) + (1 : \u2124)              : by rw [mul_comm, int.cast_one]\n    ... = f (-t * t + 1)                    : by rw [\u2190 sol_at_add_n hf h0 _ 1, int.cast_one]\n\n\nlemma mul_sol_at_one_sub {f : \u211d \u2192 \u211d} (hf : sol f) (h0 : f 0 < 0) :\n  \u2200 t, f t * f (1 - t) = t * (1 - t) :=\n\u03bb t, f_injective hf h0 $\n  calc f (f t * f (1 - t))\n      = f (f t * f (1 - t)) + 0               : by rw add_zero\n  ... = f (f t * f (1 - t)) + f 1             : by rw (of_neg_at_zero hf h0).1\n  ... = f (f t * f (1 - t)) + f (t + (1 - t)) : by rw add_sub_cancel'_right\n  ... = f (t * (1 - t))                       : by rw hf\n\ntheorem sol_of_neg_at_zero {f : \u211d \u2192 \u211d} (hf : sol f) (h0 : f 0 < 0) :\n  f = \u03bb t, t - 1 :=\nfunext $ \u03bb t,\n  calc f t\n      = f t + (-t * t + 1) - (-t * t + 1)        : by rw add_sub_cancel\n  ... = f t + f t * f (-t) - (-t * t + 1)        : by rw mul_sol_at_neg hf h0\n  ... = f t * (1 + f (-t)) - (-t * t + 1)        : by ring\n  ... = f t * (f (-t) + \u2191(1 : \u2124)) - (-t * t + 1) : by simp [add_comm]\n  ... = f t * f (-t + \u2191(1 : \u2124)) - (-t * t + 1)   : by rw \u2190 sol_at_add_n hf h0 _ 1\n  ... = f t * f (1 - t) - (-t * t + 1)           : by simp [add_comm, \u2190 sub_eq_add_neg]\n  ... = t * (1 - t) - (-t * t + 1)               : by rw mul_sol_at_one_sub hf h0\n  ... = t - 1                                    : by ring\n\n/-- We have now found all solutions: \n  1. \u03bb x, 0,      2. \u03bb x, x - 1,     and      3. \u03bb x, 1 - x. -/\ntheorem imo2017_q2 (f : \u211d \u2192 \u211d) : sol f \u2194 f = (\u03bb _, 0) \u2228 f = (\u03bb x, x - 1) \u2228 f = (\u03bb x, 1 - x) :=\nbegin\n  split, swap,\n  {\tintro h, rcases h with rfl | rfl | rfl;\n    {\tintros x y, simp, try { ring } } },\n  rcases lt_trichotomy (f 0) 0 with hneg | h0 | hpos,\n  {\tintro hf, right, left, exact sol_of_neg_at_zero hf hneg },\n  {\tintro hf, left, exact zero_of_zero_at_zero hf h0 },\n  { intro hf, right, right,\n    have hnegf : sol (neg f) := sol_of_neg_sol hf,\n    have hnegf0 : neg f 0 < 0 := by simpa [neg],\n    have : neg f = \u03bb x, x - 1 := sol_of_neg_at_zero hnegf hnegf0,\n    rw [\u2190 neg_neg_f f, this], simp [neg] },\nend", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/imo/imo2017_q2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.7282548591900264}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport measure_theory.group.action\nimport measure_theory.integral.set_integral\n\n/-!\n# Fundamental domain of a group action\n\nA set `s` is said to be a *fundamental domain* of an action of a group `G` on a measurable space `\u03b1`\nwith respect to a measure `\u03bc` if\n\n* `s` is a measurable set;\n\n* the sets `g \u2022 s` over all `g : G` cover almost all points of the whole space;\n\n* the sets `g \u2022 s`, are pairwise a.e. disjoint, i.e., `\u03bc (g\u2081 \u2022 s \u2229 g\u2082 \u2022 s) = 0` whenever `g\u2081 \u2260 g\u2082`;\n  we require this for `g\u2082 = 1` in the definition, then deduce it for any two `g\u2081 \u2260 g\u2082`.\n\nIn this file we prove that in case of a countable group `G` and a measure preserving action, any two\nfundamental domains have the same measure, and for a `G`-invariant function, its integrals over any\ntwo fundamental domains are equal to each other.\n\nWe also generate additive versions of all theorems in this file using the `to_additive` attribute.\n\n## Main declarations\n\n* `measure_theory.is_fundamental_domain`: Predicate for a set to be a fundamental domain of the\n  action of a group\n* `measure_theory.fundamental_frontier`: Fundamental frontier of a set under the action of a group.\n  Elements of `s` that belong to some other translate of `s`.\n* `measure_theory.fundamental_interior`: Fundamental interior of a set under the action of a group.\n  Elements of `s` that do not belong to any other translate of `s`.\n-/\n\nopen_locale ennreal pointwise topology nnreal ennreal measure_theory\nopen measure_theory measure_theory.measure set function topological_space filter\n\nnamespace measure_theory\n\n/-- A measurable set `s` is a *fundamental domain* for an additive action of an additive group `G`\non a measurable space `\u03b1` with respect to a measure `\u03b1` if the sets `g +\u1d65 s`, `g : G`, are pairwise\na.e. disjoint and cover the whole space. -/\n@[protect_proj] structure is_add_fundamental_domain (G : Type*) {\u03b1 : Type*} [has_zero G]\n  [has_vadd G \u03b1] [measurable_space \u03b1] (s : set \u03b1) (\u03bc : measure \u03b1 . volume_tac) : Prop :=\n(null_measurable_set : null_measurable_set s \u03bc)\n(ae_covers : \u2200\u1d50 x \u2202\u03bc, \u2203 g : G, g +\u1d65 x \u2208 s)\n(ae_disjoint : pairwise $ ae_disjoint \u03bc on \u03bb g : G, g +\u1d65 s)\n\n/-- A measurable set `s` is a *fundamental domain* for an action of a group `G` on a measurable\nspace `\u03b1` with respect to a measure `\u03b1` if the sets `g \u2022 s`, `g : G`, are pairwise a.e. disjoint and\ncover the whole space. -/\n@[protect_proj, to_additive is_add_fundamental_domain]\nstructure is_fundamental_domain (G : Type*) {\u03b1 : Type*} [has_one G] [has_smul G \u03b1]\n  [measurable_space \u03b1] (s : set \u03b1) (\u03bc : measure \u03b1 . volume_tac) : Prop :=\n(null_measurable_set : null_measurable_set s \u03bc)\n(ae_covers : \u2200\u1d50 x \u2202\u03bc, \u2203 g : G, g \u2022 x \u2208 s)\n(ae_disjoint : pairwise $ ae_disjoint \u03bc on \u03bb g : G, g \u2022 s)\n\nvariables {G H \u03b1 \u03b2 E : Type*}\n\nnamespace is_fundamental_domain\nvariables [group G] [group H] [mul_action G \u03b1] [measurable_space \u03b1] [mul_action H \u03b2]\n  [measurable_space \u03b2] [normed_add_comm_group E] {s t : set \u03b1} {\u03bc : measure \u03b1}\n\n/-- If for each `x : \u03b1`, exactly one of `g \u2022 x`, `g : G`, belongs to a measurable set `s`, then `s`\nis a fundamental domain for the action of `G` on `\u03b1`. -/\n@[to_additive \"If for each `x : \u03b1`, exactly one of `g +\u1d65 x`, `g : G`, belongs to a measurable set\n`s`, then `s` is a fundamental domain for the additive action of `G` on `\u03b1`.\"]\nlemma mk' (h_meas : null_measurable_set s \u03bc) (h_exists : \u2200 x : \u03b1, \u2203! g : G, g \u2022 x \u2208 s) :\n  is_fundamental_domain G s \u03bc :=\n{ null_measurable_set := h_meas,\n  ae_covers := eventually_of_forall $ \u03bb x, (h_exists x).exists,\n  ae_disjoint := \u03bb a b hab, disjoint.ae_disjoint $ disjoint_left.2 $ \u03bb x hxa hxb,\n    begin\n      rw mem_smul_set_iff_inv_smul_mem at hxa hxb,\n      exact hab (inv_injective $ (h_exists x).unique hxa hxb),\n    end }\n\n/-- For `s` to be a fundamental domain, it's enough to check `ae_disjoint (g \u2022 s) s` for `g \u2260 1`. -/\n@[to_additive \"For `s` to be a fundamental domain, it's enough to check `ae_disjoint (g +\u1d65 s) s` for\n`g \u2260 0`.\"]\nlemma mk'' (h_meas : null_measurable_set s \u03bc) (h_ae_covers : \u2200\u1d50 x \u2202\u03bc, \u2203 g : G, g \u2022 x \u2208 s)\n  (h_ae_disjoint : \u2200 g \u2260 (1 : G), ae_disjoint \u03bc (g \u2022 s) s)\n  (h_qmp : \u2200 (g : G), quasi_measure_preserving ((\u2022) g : \u03b1 \u2192 \u03b1) \u03bc \u03bc) :\n  is_fundamental_domain G s \u03bc :=\n{ null_measurable_set := h_meas,\n  ae_covers := h_ae_covers,\n  ae_disjoint := pairwise_ae_disjoint_of_ae_disjoint_forall_ne_one h_ae_disjoint h_qmp }\n\n/-- If a measurable space has a finite measure `\u03bc` and a countable group `G` acts\nquasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient\nto check that its translates `g \u2022 s` are (almost) disjoint and that the sum `\u2211' g, \u03bc (g \u2022 s)` is\nsufficiently large. -/\n@[to_additive measure_theory.is_add_fundamental_domain.mk_of_measure_univ_le \"\nIf a measurable space has a finite measure `\u03bc` and a countable additive group `G` acts\nquasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient\nto check that its translates `g +\u1d65 s` are (almost) disjoint and that the sum `\u2211' g, \u03bc (g +\u1d65 s)` is\nsufficiently large.\"]\nlemma mk_of_measure_univ_le [is_finite_measure \u03bc] [countable G]\n  (h_meas : null_measurable_set s \u03bc)\n  (h_ae_disjoint : \u2200 g \u2260 (1 : G), ae_disjoint \u03bc (g \u2022 s) s)\n  (h_qmp : \u2200 (g : G), quasi_measure_preserving ((\u2022) g : \u03b1 \u2192 \u03b1) \u03bc \u03bc)\n  (h_measure_univ_le : \u03bc (univ : set \u03b1) \u2264 \u2211' (g : G), \u03bc (g \u2022 s)) :\n  is_fundamental_domain G s \u03bc :=\nhave ae_disjoint : pairwise (ae_disjoint \u03bc on (\u03bb (g : G), g \u2022 s)) :=\n  pairwise_ae_disjoint_of_ae_disjoint_forall_ne_one h_ae_disjoint h_qmp,\n{ null_measurable_set := h_meas,\n  ae_disjoint := ae_disjoint,\n  ae_covers :=\n  begin\n    replace h_meas : \u2200 (g : G), null_measurable_set (g \u2022 s) \u03bc :=\n      \u03bb g, by { rw [\u2190 inv_inv g, \u2190 preimage_smul], exact h_meas.preimage (h_qmp g\u207b\u00b9), },\n    have h_meas' : null_measurable_set {a | \u2203 (g : G), g \u2022 a \u2208 s} \u03bc,\n    { rw \u2190 Union_smul_eq_set_of_exists, exact null_measurable_set.Union h_meas, },\n    rw [ae_iff_measure_eq h_meas', \u2190 Union_smul_eq_set_of_exists],\n    refine le_antisymm (measure_mono $ subset_univ _) _,\n    rw measure_Union\u2080 ae_disjoint h_meas,\n    exact h_measure_univ_le,\n  end }\n\n@[to_additive] lemma Union_smul_ae_eq (h : is_fundamental_domain G s \u03bc) :\n  (\u22c3 g : G, g \u2022 s) =\u1d50[\u03bc] univ :=\neventually_eq_univ.2 $ h.ae_covers.mono $ \u03bb x \u27e8g, hg\u27e9, mem_Union.2 \u27e8g\u207b\u00b9, _, hg, inv_smul_smul _ _\u27e9\n\n@[to_additive] lemma mono (h : is_fundamental_domain G s \u03bc) {\u03bd : measure \u03b1} (hle : \u03bd \u226a \u03bc) :\n  is_fundamental_domain G s \u03bd :=\n\u27e8h.1.mono_ac hle, hle h.2, h.ae_disjoint.mono $ \u03bb a b hab, hle hab\u27e9\n\n@[to_additive] lemma preimage_of_equiv {\u03bd : measure \u03b2} (h : is_fundamental_domain G s \u03bc) {f : \u03b2 \u2192 \u03b1}\n  (hf : quasi_measure_preserving f \u03bd \u03bc) {e : G \u2192 H} (he : bijective e)\n  (hef : \u2200 g, semiconj f ((\u2022) (e g)) ((\u2022) g)) :\n  is_fundamental_domain H (f \u207b\u00b9' s) \u03bd :=\n{ null_measurable_set := h.null_measurable_set.preimage hf,\n  ae_covers := (hf.ae h.ae_covers).mono $ \u03bb x \u27e8g, hg\u27e9, \u27e8e g, by rwa [mem_preimage, hef g x]\u27e9,\n  ae_disjoint := \u03bb a b hab,\n    begin\n      lift e to G \u2243 H using he,\n      have : (e.symm a\u207b\u00b9)\u207b\u00b9 \u2260 (e.symm b\u207b\u00b9)\u207b\u00b9, by simp [hab],\n      convert (h.ae_disjoint this).preimage hf using 1,\n      simp only [\u2190preimage_smul_inv, preimage_preimage, \u2190hef _ _, e.apply_symm_apply, inv_inv],\n    end }\n\n@[to_additive] lemma image_of_equiv {\u03bd : measure \u03b2} (h : is_fundamental_domain G s \u03bc)\n  (f : \u03b1 \u2243 \u03b2) (hf : quasi_measure_preserving f.symm \u03bd \u03bc)\n  (e : H \u2243 G) (hef : \u2200 g, semiconj f ((\u2022) (e g)) ((\u2022) g)) :\n  is_fundamental_domain H (f '' s) \u03bd :=\nbegin\n  rw f.image_eq_preimage,\n  refine h.preimage_of_equiv hf e.symm.bijective (\u03bb g x, _),\n  rcases f.surjective x with \u27e8x, rfl\u27e9,\n  rw [\u2190 hef _ _, f.symm_apply_apply, f.symm_apply_apply, e.apply_symm_apply]\nend\n\n@[to_additive] lemma pairwise_ae_disjoint_of_ac {\u03bd} (h : is_fundamental_domain G s \u03bc) (h\u03bd : \u03bd \u226a \u03bc) :\n  pairwise (\u03bb g\u2081 g\u2082 : G, ae_disjoint \u03bd (g\u2081 \u2022 s) (g\u2082 \u2022 s)) :=\nh.ae_disjoint.mono $ \u03bb g\u2081 g\u2082 H, h\u03bd H\n\n@[to_additive] lemma smul_of_comm {G' : Type*} [group G'] [mul_action G' \u03b1] [measurable_space G']\n  [has_measurable_smul G' \u03b1] [smul_invariant_measure G' \u03b1 \u03bc] [smul_comm_class G' G \u03b1]\n  (h : is_fundamental_domain G s \u03bc) (g : G') :\n  is_fundamental_domain G (g \u2022 s) \u03bc :=\nh.image_of_equiv (mul_action.to_perm g) (measure_preserving_smul _ _).quasi_measure_preserving\n  (equiv.refl _) $ smul_comm g\n\nvariables [measurable_space G] [has_measurable_smul G \u03b1] [smul_invariant_measure G \u03b1 \u03bc]\n\n@[to_additive] lemma null_measurable_set_smul (h : is_fundamental_domain G s \u03bc) (g : G) :\n  null_measurable_set (g \u2022 s) \u03bc :=\nh.null_measurable_set.smul g\n\n@[to_additive] lemma restrict_restrict (h : is_fundamental_domain G s \u03bc) (g : G) (t : set \u03b1) :\n  (\u03bc.restrict t).restrict (g \u2022 s) = \u03bc.restrict (g \u2022 s \u2229 t) :=\nrestrict_restrict\u2080 ((h.null_measurable_set_smul g).mono restrict_le_self)\n\n@[to_additive] lemma smul (h : is_fundamental_domain G s \u03bc) (g : G) :\n  is_fundamental_domain G (g \u2022 s) \u03bc :=\nh.image_of_equiv (mul_action.to_perm g) (measure_preserving_smul _ _).quasi_measure_preserving\n  \u27e8\u03bb g', g\u207b\u00b9 * g' * g, \u03bb g', g * g' * g\u207b\u00b9, \u03bb g', by simp [mul_assoc], \u03bb g', by simp [mul_assoc]\u27e9 $\n  \u03bb g' x, by simp [smul_smul, mul_assoc]\n\nvariables [countable G] {\u03bd : measure \u03b1}\n\n@[to_additive] lemma sum_restrict_of_ac (h : is_fundamental_domain G s \u03bc) (h\u03bd : \u03bd \u226a \u03bc) :\n  sum (\u03bb g : G, \u03bd.restrict (g \u2022 s)) = \u03bd :=\nby rw [\u2190 restrict_Union_ae (h.ae_disjoint.mono $ \u03bb i j h, h\u03bd h)\n    (\u03bb g, (h.null_measurable_set_smul g).mono_ac h\u03bd),\n  restrict_congr_set (h\u03bd h.Union_smul_ae_eq), restrict_univ]\n\n@[to_additive] lemma lintegral_eq_tsum_of_ac (h : is_fundamental_domain G s \u03bc) (h\u03bd : \u03bd \u226a \u03bc)\n  (f : \u03b1 \u2192 \u211d\u22650\u221e) : \u222b\u207b x, f x \u2202\u03bd = \u2211' g : G, \u222b\u207b x in g \u2022 s, f x \u2202\u03bd :=\nby rw [\u2190 lintegral_sum_measure, h.sum_restrict_of_ac h\u03bd]\n\n@[to_additive] lemma sum_restrict (h : is_fundamental_domain G s \u03bc) :\n  sum (\u03bb g : G, \u03bc.restrict (g \u2022 s)) = \u03bc :=\nh.sum_restrict_of_ac (refl _)\n\n@[to_additive] lemma lintegral_eq_tsum (h : is_fundamental_domain G s \u03bc) (f : \u03b1 \u2192 \u211d\u22650\u221e) :\n  \u222b\u207b x, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in g \u2022 s, f x \u2202\u03bc :=\nh.lintegral_eq_tsum_of_ac (refl _) f\n\n@[to_additive] lemma lintegral_eq_tsum' (h : is_fundamental_domain G s \u03bc) (f : \u03b1 \u2192 \u211d\u22650\u221e) :\n  \u222b\u207b x, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :=\ncalc \u222b\u207b x, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in g \u2022 s, f x \u2202\u03bc : h.lintegral_eq_tsum f\n... = \u2211' g : G, \u222b\u207b x in g\u207b\u00b9 \u2022 s, f x \u2202\u03bc : ((equiv.inv G).tsum_eq _).symm\n... = \u2211' g : G, \u222b\u207b x in s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :\n  tsum_congr $ \u03bb g, ((measure_preserving_smul g\u207b\u00b9 \u03bc).set_lintegral_comp_emb\n    (measurable_embedding_const_smul _) _ _).symm\n\n@[to_additive] lemma set_lintegral_eq_tsum (h : is_fundamental_domain G s \u03bc) (f : \u03b1 \u2192 \u211d\u22650\u221e)\n  (t : set \u03b1) : \u222b\u207b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in t \u2229 g \u2022 s, f x \u2202\u03bc :=\ncalc \u222b\u207b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in g \u2022 s, f x \u2202(\u03bc.restrict t) :\n  h.lintegral_eq_tsum_of_ac restrict_le_self.absolutely_continuous _\n... = \u2211' g : G, \u222b\u207b x in t \u2229 g \u2022 s, f x \u2202\u03bc :\n  by simp only [h.restrict_restrict, inter_comm]\n\n@[to_additive] lemma set_lintegral_eq_tsum' (h : is_fundamental_domain G s \u03bc) (f : \u03b1 \u2192 \u211d\u22650\u221e)\n  (t : set \u03b1) :\n  \u222b\u207b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in g \u2022 t \u2229 s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :=\ncalc \u222b\u207b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in t \u2229 g \u2022 s, f x \u2202\u03bc :\n  h.set_lintegral_eq_tsum f t\n... = \u2211' g : G, \u222b\u207b x in t \u2229 g\u207b\u00b9 \u2022 s, f x \u2202\u03bc : ((equiv.inv G).tsum_eq _).symm\n... = \u2211' g : G, \u222b\u207b x in g\u207b\u00b9 \u2022 (g \u2022 t \u2229 s), f (x) \u2202\u03bc :\n  by simp only [smul_set_inter, inv_smul_smul]\n... = \u2211' g : G, \u222b\u207b x in g \u2022 t \u2229 s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :\n  tsum_congr $ \u03bb g, ((measure_preserving_smul g\u207b\u00b9 \u03bc).set_lintegral_comp_emb\n    (measurable_embedding_const_smul _) _ _).symm\n\n@[to_additive] lemma measure_eq_tsum_of_ac (h : is_fundamental_domain G s \u03bc) (h\u03bd : \u03bd \u226a \u03bc)\n  (t : set \u03b1) :\n  \u03bd t = \u2211' g : G, \u03bd (t \u2229 g \u2022 s) :=\nhave H : \u03bd.restrict t \u226a \u03bc, from measure.restrict_le_self.absolutely_continuous.trans h\u03bd,\nby simpa only [set_lintegral_one, pi.one_def,\n    measure.restrict_apply\u2080 ((h.null_measurable_set_smul _).mono_ac H), inter_comm]\n  using h.lintegral_eq_tsum_of_ac H 1\n\n@[to_additive] lemma measure_eq_tsum' (h : is_fundamental_domain G s \u03bc) (t : set \u03b1) :\n  \u03bc t = \u2211' g : G, \u03bc (t \u2229 g \u2022 s) :=\nh.measure_eq_tsum_of_ac absolutely_continuous.rfl t\n\n@[to_additive] lemma measure_eq_tsum (h : is_fundamental_domain G s \u03bc) (t : set \u03b1) :\n  \u03bc t = \u2211' g : G, \u03bc (g \u2022 t \u2229 s) :=\nby simpa only [set_lintegral_one] using h.set_lintegral_eq_tsum' (\u03bb _, 1) t\n\n@[to_additive] lemma measure_zero_of_invariant (h : is_fundamental_domain G s \u03bc) (t : set \u03b1)\n  (ht : \u2200 g : G, g \u2022 t = t) (hts : \u03bc (t \u2229 s) = 0) :\n  \u03bc t = 0 :=\nby simp [measure_eq_tsum h, ht, hts]\n\n/-- Given a measure space with an action of a finite group `G`, the measure of any `G`-invariant set\nis determined by the measure of its intersection with a fundamental domain for the action of `G`. -/\n@[to_additive measure_eq_card_smul_of_vadd_ae_eq_self \"Given a measure space with an action of a\nfinite additive group `G`, the measure of any `G`-invariant set is determined by the measure of its\nintersection with a fundamental domain for the action of `G`.\"]\nlemma measure_eq_card_smul_of_smul_ae_eq_self [finite G]\n  (h : is_fundamental_domain G s \u03bc) (t : set \u03b1) (ht : \u2200 g : G, (g \u2022 t : set \u03b1) =\u1d50[\u03bc] t) :\n  \u03bc t = nat.card G \u2022 \u03bc (t \u2229 s) :=\nbegin\n  haveI : fintype G := fintype.of_finite G,\n  rw h.measure_eq_tsum,\n  replace ht : \u2200 g : G, ((g \u2022 t) \u2229 s : set \u03b1) =\u1d50[\u03bc] (t \u2229 s : set \u03b1) :=\n    \u03bb g, ae_eq_set_inter (ht g) (ae_eq_refl s),\n  simp_rw [measure_congr (ht _), tsum_fintype, finset.sum_const, nat.card_eq_fintype_card,\n    finset.card_univ],\nend\n\n@[to_additive] protected lemma set_lintegral_eq (hs : is_fundamental_domain G s \u03bc)\n  (ht : is_fundamental_domain G t \u03bc) (f : \u03b1 \u2192 \u211d\u22650\u221e) (hf : \u2200 (g : G) x, f (g \u2022 x) = f x) :\n  \u222b\u207b x in s, f x \u2202\u03bc = \u222b\u207b x in t, f x \u2202\u03bc :=\ncalc \u222b\u207b x in s, f x \u2202\u03bc = \u2211' g : G, \u222b\u207b x in s \u2229 g \u2022 t, f x \u2202\u03bc : ht.set_lintegral_eq_tsum _ _\n... = \u2211' g : G, \u222b\u207b x in g \u2022 t \u2229 s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc            : by simp only [hf, inter_comm]\n... = \u222b\u207b x in t, f x \u2202\u03bc                                      : (hs.set_lintegral_eq_tsum' _ _).symm\n\n@[to_additive] lemma measure_set_eq (hs : is_fundamental_domain G s \u03bc)\n  (ht : is_fundamental_domain G t \u03bc) {A : set \u03b1} (hA\u2080 : measurable_set A)\n  (hA : \u2200 (g : G), (\u03bb x, g \u2022 x) \u207b\u00b9' A = A) :\n  \u03bc (A \u2229 s) = \u03bc (A \u2229 t) :=\nbegin\n  have : \u222b\u207b x in s, A.indicator 1 x \u2202\u03bc = \u222b\u207b x in t, A.indicator 1 x \u2202\u03bc,\n  { refine hs.set_lintegral_eq ht (set.indicator A (\u03bb _, 1)) _,\n    intros g x,\n    convert (set.indicator_comp_right (\u03bb x : \u03b1, g \u2022 x)).symm,\n    rw hA g },\n  simpa [measure.restrict_apply hA\u2080, lintegral_indicator _ hA\u2080] using this\nend\n\n/-- If `s` and `t` are two fundamental domains of the same action, then their measures are equal. -/\n@[to_additive \"If `s` and `t` are two fundamental domains of the same action, then their measures\nare equal.\"]\nprotected lemma measure_eq (hs : is_fundamental_domain G s \u03bc)\n  (ht : is_fundamental_domain G t \u03bc) : \u03bc s = \u03bc t :=\nby simpa only [set_lintegral_one] using hs.set_lintegral_eq ht (\u03bb _, 1) (\u03bb _ _, rfl)\n\n@[to_additive] protected lemma ae_strongly_measurable_on_iff\n  {\u03b2 : Type*} [topological_space \u03b2] [pseudo_metrizable_space \u03b2]\n  (hs : is_fundamental_domain G s \u03bc) (ht : is_fundamental_domain G t \u03bc) {f : \u03b1 \u2192 \u03b2}\n  (hf : \u2200 (g : G) x, f (g \u2022 x) = f x) :\n  ae_strongly_measurable f (\u03bc.restrict s) \u2194 ae_strongly_measurable f (\u03bc.restrict t) :=\ncalc ae_strongly_measurable f (\u03bc.restrict s)\n    \u2194 ae_strongly_measurable f (measure.sum $ \u03bb g : G, (\u03bc.restrict (g \u2022 t \u2229 s))) :\n  by simp only [\u2190 ht.restrict_restrict,\n    ht.sum_restrict_of_ac restrict_le_self.absolutely_continuous]\n... \u2194 \u2200 g : G, ae_strongly_measurable f (\u03bc.restrict (g \u2022 (g\u207b\u00b9 \u2022 s \u2229 t))) :\n  by simp only [smul_set_inter, inter_comm, smul_inv_smul, ae_strongly_measurable_sum_measure_iff]\n... \u2194 \u2200 g : G, ae_strongly_measurable f (\u03bc.restrict (g\u207b\u00b9 \u2022 (g\u207b\u00b9\u207b\u00b9 \u2022 s \u2229 t))) : inv_surjective.forall\n... \u2194 \u2200 g : G, ae_strongly_measurable f (\u03bc.restrict (g\u207b\u00b9 \u2022 (g \u2022 s \u2229 t))) : by simp only [inv_inv]\n... \u2194 \u2200 g : G, ae_strongly_measurable f (\u03bc.restrict (g \u2022 s \u2229 t)) :\n  begin\n    refine forall_congr (\u03bb g, _),\n    have he : measurable_embedding ((\u2022) g\u207b\u00b9 : \u03b1 \u2192 \u03b1) := measurable_embedding_const_smul _,\n    rw [\u2190 image_smul,\n    \u2190 ((measure_preserving_smul g\u207b\u00b9 \u03bc).restrict_image_emb he _).ae_strongly_measurable_comp_iff he],\n    simp only [(\u2218), hf]\n  end\n... \u2194 ae_strongly_measurable f (\u03bc.restrict t) :\n  by simp only [\u2190 ae_strongly_measurable_sum_measure_iff, \u2190 hs.restrict_restrict,\n    hs.sum_restrict_of_ac restrict_le_self.absolutely_continuous]\n\n@[to_additive] protected lemma has_finite_integral_on_iff (hs : is_fundamental_domain G s \u03bc)\n  (ht : is_fundamental_domain G t \u03bc) {f : \u03b1 \u2192 E} (hf : \u2200 (g : G) x, f (g \u2022 x) = f x) :\n  has_finite_integral f (\u03bc.restrict s) \u2194 has_finite_integral f (\u03bc.restrict t) :=\nbegin\n  dunfold has_finite_integral,\n  rw hs.set_lintegral_eq ht,\n  intros g x, rw hf\nend\n\n@[to_additive] protected lemma integrable_on_iff (hs : is_fundamental_domain G s \u03bc)\n  (ht : is_fundamental_domain G t \u03bc) {f : \u03b1 \u2192 E} (hf : \u2200 (g : G) x, f (g \u2022 x) = f x) :\n  integrable_on f s \u03bc \u2194 integrable_on f t \u03bc :=\nand_congr (hs.ae_strongly_measurable_on_iff ht hf) (hs.has_finite_integral_on_iff ht hf)\n\nvariables [normed_space \u211d E] [complete_space E]\n\n@[to_additive] lemma integral_eq_tsum_of_ac (h : is_fundamental_domain G s \u03bc) (h\u03bd : \u03bd \u226a \u03bc)\n  (f : \u03b1 \u2192 E) (hf : integrable f \u03bd) : \u222b x, f x \u2202\u03bd = \u2211' g : G, \u222b x in g \u2022 s, f x \u2202\u03bd :=\nbegin\n  rw [\u2190 measure_theory.integral_sum_measure, h.sum_restrict_of_ac h\u03bd],\n  rw h.sum_restrict_of_ac h\u03bd, -- Weirdly, these rewrites seem not to be combinable\n  exact hf,\nend\n\n@[to_additive] lemma integral_eq_tsum (h : is_fundamental_domain G s \u03bc)\n  (f : \u03b1 \u2192 E) (hf : integrable f \u03bc) : \u222b x, f x \u2202\u03bc = \u2211' g : G, \u222b x in g \u2022 s, f x \u2202\u03bc :=\nintegral_eq_tsum_of_ac h (by refl) f hf\n\n@[to_additive] lemma integral_eq_tsum' (h : is_fundamental_domain G s \u03bc)\n  (f : \u03b1 \u2192 E) (hf : integrable f \u03bc) : \u222b x, f x \u2202\u03bc = \u2211' g : G, \u222b x in s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :=\ncalc \u222b x, f x \u2202\u03bc = \u2211' g : G, \u222b x in g \u2022 s, f x \u2202\u03bc : h.integral_eq_tsum f hf\n... = \u2211' g : G, \u222b x in g\u207b\u00b9 \u2022 s, f x \u2202\u03bc : ((equiv.inv G).tsum_eq _).symm\n... = \u2211' g : G, \u222b x in s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :\n  tsum_congr $ \u03bb g, (measure_preserving_smul g\u207b\u00b9 \u03bc).set_integral_image_emb\n    (measurable_embedding_const_smul _) _ _\n\n@[to_additive] lemma set_integral_eq_tsum (h : is_fundamental_domain G s \u03bc) {f : \u03b1 \u2192 E}\n  {t : set \u03b1} (hf : integrable_on f t \u03bc) :\n  \u222b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b x in t \u2229 g \u2022 s, f x \u2202\u03bc :=\ncalc \u222b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b x in g \u2022 s, f x \u2202(\u03bc.restrict t) :\n  h.integral_eq_tsum_of_ac restrict_le_self.absolutely_continuous f hf\n... = \u2211' g : G, \u222b x in t \u2229 g \u2022 s, f x \u2202\u03bc :\n  by simp only [h.restrict_restrict, measure_smul, inter_comm]\n\n@[to_additive] lemma set_integral_eq_tsum' (h : is_fundamental_domain G s \u03bc) {f : \u03b1 \u2192 E}\n  {t : set \u03b1} (hf : integrable_on f t \u03bc) :\n  \u222b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b x in g \u2022 t \u2229 s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :=\ncalc \u222b x in t, f x \u2202\u03bc = \u2211' g : G, \u222b x in t \u2229 g \u2022 s, f x \u2202\u03bc :\n  h.set_integral_eq_tsum hf\n... = \u2211' g : G, \u222b x in t \u2229 g\u207b\u00b9 \u2022 s, f x \u2202\u03bc : ((equiv.inv G).tsum_eq _).symm\n... = \u2211' g : G, \u222b x in g\u207b\u00b9 \u2022 (g \u2022 t \u2229 s), f (x) \u2202\u03bc :\n  by simp only [smul_set_inter, inv_smul_smul]\n... = \u2211' g : G, \u222b x in g \u2022 t \u2229 s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc :\n  tsum_congr $ \u03bb g, (measure_preserving_smul g\u207b\u00b9 \u03bc).set_integral_image_emb\n    (measurable_embedding_const_smul _) _ _\n\n@[to_additive] protected lemma set_integral_eq (hs : is_fundamental_domain G s \u03bc)\n  (ht : is_fundamental_domain G t \u03bc) {f : \u03b1 \u2192 E} (hf : \u2200 (g : G) x, f (g \u2022 x) = f x) :\n  \u222b x in s, f x \u2202\u03bc = \u222b x in t, f x \u2202\u03bc :=\nbegin\n  by_cases hfs : integrable_on f s \u03bc,\n  { have hft : integrable_on f t \u03bc, by rwa ht.integrable_on_iff hs hf,\n    calc \u222b x in s, f x \u2202\u03bc = \u2211' g : G, \u222b x in s \u2229 g \u2022 t, f x \u2202\u03bc : ht.set_integral_eq_tsum hfs\n    ... = \u2211' g : G, \u222b x in g \u2022 t \u2229 s, f (g\u207b\u00b9 \u2022 x) \u2202\u03bc : by simp only [hf, inter_comm]\n    ... = \u222b x in t, f x \u2202\u03bc : (hs.set_integral_eq_tsum' hft).symm, },\n  { rw [integral_undef hfs, integral_undef],\n    rwa [hs.integrable_on_iff ht hf] at hfs }\nend\n\n/-- If the action of a countable group `G` admits an invariant measure `\u03bc` with a fundamental domain\n`s`, then every null-measurable set `t` such that the sets `g \u2022 t \u2229 s` are pairwise a.e.-disjoint\nhas measure at most `\u03bc s`. -/\n@[to_additive \"If the additive action of a countable group `G` admits an invariant measure `\u03bc` with\na fundamental domain `s`, then every null-measurable set `t` such that the sets `g +\u1d65 t \u2229 s` are\npairwise a.e.-disjoint has measure at most `\u03bc s`.\"]\n lemma measure_le_of_pairwise_disjoint (hs : is_fundamental_domain G s \u03bc)\n  (ht : null_measurable_set t \u03bc) (hd : pairwise (ae_disjoint \u03bc on (\u03bb g : G, g \u2022 t \u2229 s))) :\n  \u03bc t \u2264 \u03bc s :=\ncalc \u03bc t = \u2211' g : G, \u03bc (g \u2022 t \u2229 s) : hs.measure_eq_tsum t\n... = \u03bc (\u22c3 g : G, g \u2022 t \u2229 s) : eq.symm $ measure_Union\u2080 hd $\n  \u03bb g, (ht.smul _).inter hs.null_measurable_set\n... \u2264 \u03bc s : measure_mono (Union_subset $ \u03bb g, inter_subset_right _ _)\n\n/-- If the action of a countable group `G` admits an invariant measure `\u03bc` with a fundamental domain\n`s`, then every null-measurable set `t` of measure strictly greater than `\u03bc s` contains two\npoints `x y` such that `g \u2022 x = y` for some `g \u2260 1`. -/\n@[to_additive \"If the additive action of a countable group `G` admits an invariant measure `\u03bc` with\na fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `\u03bc s`\ncontains two points `x y` such that `g +\u1d65 x = y` for some `g \u2260 0`.\"]\nlemma exists_ne_one_smul_eq (hs : is_fundamental_domain G s \u03bc) (htm : null_measurable_set t \u03bc)\n  (ht : \u03bc s < \u03bc t) : \u2203 (x y \u2208 t) (g \u2260 (1 : G)), g \u2022 x = y :=\nbegin\n  contrapose! ht,\n  refine hs.measure_le_of_pairwise_disjoint htm (pairwise.ae_disjoint $ \u03bb g\u2081 g\u2082 hne, _),\n  dsimp [function.on_fun],\n  refine (disjoint.inf_left _ _).inf_right _,\n  rw set.disjoint_left,\n  rintro _ \u27e8x, hx, rfl\u27e9 \u27e8y, hy, hxy\u27e9,\n  refine ht x hx y hy (g\u2082\u207b\u00b9 * g\u2081) (mt inv_mul_eq_one.1 hne.symm) _,\n  rw [mul_smul, \u2190 hxy, inv_smul_smul]\nend\n\n/-- If `f` is invariant under the action of a countable group `G`, and `\u03bc` is a `G`-invariant\n  measure with a fundamental domain `s`, then the `ess_sup` of `f` restricted to `s` is the same as\n  that of `f` on all of its domain. -/\n@[to_additive \"If `f` is invariant under the action of a countable additive group `G`, and `\u03bc` is a\n`G`-invariant measure with a fundamental domain `s`, then the `ess_sup` of `f` restricted to `s` is\nthe same as that of `f` on all of its domain.\"]\nlemma ess_sup_measure_restrict (hs : is_fundamental_domain G s \u03bc)\n  {f : \u03b1 \u2192 \u211d\u22650\u221e} (hf : \u2200 \u03b3 : G, \u2200 x: \u03b1, f (\u03b3 \u2022 x) =  f x) :\n  ess_sup f (\u03bc.restrict s) = ess_sup f \u03bc :=\nbegin\n  refine le_antisymm (ess_sup_mono_measure' measure.restrict_le_self) _,\n  rw [ess_sup_eq_Inf (\u03bc.restrict s) f, ess_sup_eq_Inf \u03bc f],\n  refine Inf_le_Inf _,\n  rintro a (ha : (\u03bc.restrict s) {x : \u03b1 | a < f x} = 0),\n  rw measure.restrict_apply\u2080' hs.null_measurable_set at ha,\n  refine measure_zero_of_invariant hs _ _ ha,\n  intros \u03b3,\n  ext x,\n  rw mem_smul_set_iff_inv_smul_mem,\n  simp only [mem_set_of_eq, hf (\u03b3\u207b\u00b9) x],\nend\n\nend is_fundamental_domain\n\n/-! ### Interior/frontier of a fundamental domain -/\n\nsection measurable_space\nvariables (G) [group G] [mul_action G \u03b1] (s : set \u03b1) {x : \u03b1}\n\n/-- The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial\ntranslate. -/\n@[to_additive measure_theory.add_fundamental_frontier \"The boundary of a fundamental domain, those\npoints of the domain that also lie in a nontrivial translate.\"]\ndef fundamental_frontier : set \u03b1 := s \u2229 \u22c3 (g : G) (hg : g \u2260 1), g \u2022 s\n\n/-- The interior of a fundamental domain, those points of the domain not lying in any translate. -/\n@[to_additive measure_theory.add_fundamental_interior \"The interior of a fundamental domain, those\npoints of the domain not lying in any translate.\"]\ndef fundamental_interior : set \u03b1 := s \\ \u22c3 (g : G) (hg : g \u2260 1), g \u2022 s\n\nvariables {G s}\n\n@[simp, to_additive measure_theory.mem_add_fundamental_frontier]\nlemma mem_fundamental_frontier :\n  x \u2208 fundamental_frontier G s \u2194 x \u2208 s \u2227 \u2203 (g : G) (hg : g \u2260 1), x \u2208 g \u2022 s :=\nby simp [fundamental_frontier]\n\n@[simp, to_additive measure_theory.mem_add_fundamental_interior]\nlemma mem_fundamental_interior :\n  x \u2208 fundamental_interior G s \u2194 x \u2208 s \u2227 \u2200 (g : G) (hg : g \u2260 1), x \u2209 g \u2022 s :=\nby simp [fundamental_interior]\n\n@[to_additive measure_theory.add_fundamental_frontier_subset]\nlemma fundamental_frontier_subset : fundamental_frontier G s \u2286 s := inter_subset_left _ _\n\n@[to_additive measure_theory.add_fundamental_interior_subset]\nlemma fundamental_interior_subset : fundamental_interior G s \u2286 s := diff_subset _ _\n\nvariables (G s)\n\n@[to_additive measure_theory.disjoint_add_fundamental_interior_add_fundamental_frontier]\nlemma disjoint_fundamental_interior_fundamental_frontier :\n  disjoint (fundamental_interior G s) (fundamental_frontier G s) :=\ndisjoint_sdiff_self_left.mono_right inf_le_right\n\n@[simp, to_additive measure_theory.add_fundamental_interior_union_add_fundamental_frontier]\nlemma fundamental_interior_union_fundamental_frontier :\n  fundamental_interior G s \u222a fundamental_frontier G s = s :=\ndiff_union_inter _ _\n\n@[simp, to_additive measure_theory.add_fundamental_interior_union_add_fundamental_frontier]\nlemma fundamental_frontier_union_fundamental_interior :\n  fundamental_frontier G s \u222a fundamental_interior G s = s :=\ninter_union_diff _ _\n\n@[simp, to_additive measure_theory.sdiff_add_fundamental_interior]\nlemma sdiff_fundamental_interior : s \\ fundamental_interior G s = fundamental_frontier G s :=\nsdiff_sdiff_right_self\n\n@[simp, to_additive measure_theory.sdiff_add_fundamental_frontier]\nlemma sdiff_fundamental_frontier : s \\ fundamental_frontier G s = fundamental_interior G s :=\ndiff_self_inter\n\n@[simp, to_additive measure_theory.add_fundamental_frontier_vadd]\nlemma fundamental_frontier_smul [group H] [mul_action H \u03b1] [smul_comm_class H G \u03b1] (g : H) :\n  fundamental_frontier G (g \u2022 s) = g \u2022 fundamental_frontier G s :=\nby simp_rw [fundamental_frontier, smul_set_inter, smul_set_Union, smul_comm g]\n\n@[simp, to_additive measure_theory.add_fundamental_interior_vadd]\nlemma fundamental_interior_smul [group H] [mul_action H \u03b1] [smul_comm_class H G \u03b1] (g : H) :\n  fundamental_interior G (g \u2022 s) = g \u2022 fundamental_interior G s :=\nby simp_rw [fundamental_interior, smul_set_sdiff, smul_set_Union, smul_comm g]\n\n@[to_additive measure_theory.pairwise_disjoint_add_fundamental_interior]\nlemma pairwise_disjoint_fundamental_interior :\n  pairwise (disjoint on \u03bb g : G, g \u2022 fundamental_interior G s) :=\nbegin\n  refine \u03bb a b hab, disjoint_left.2 _,\n  rintro _ \u27e8x, hx, rfl\u27e9 \u27e8y, hy, hxy\u27e9,\n  rw mem_fundamental_interior at hx hy,\n  refine hx.2 (a\u207b\u00b9 * b) _ _,\n  rwa [ne.def, inv_mul_eq_iff_eq_mul, mul_one, eq_comm],\n  simpa [mul_smul, \u2190hxy, mem_inv_smul_set_iff] using hy.1,\nend\n\nvariables [countable G] [measurable_space G] [measurable_space \u03b1] [has_measurable_smul G \u03b1]\n  {\u03bc : measure \u03b1} [smul_invariant_measure G \u03b1 \u03bc]\n\n@[to_additive measure_theory.null_measurable_set.add_fundamental_frontier]\nprotected lemma null_measurable_set.fundamental_frontier (hs : null_measurable_set s \u03bc) :\n  null_measurable_set (fundamental_frontier G s) \u03bc :=\nhs.inter $ null_measurable_set.Union $ \u03bb g, null_measurable_set.Union $ \u03bb hg, hs.smul _\n\n@[to_additive measure_theory.null_measurable_set.add_fundamental_interior]\nprotected lemma null_measurable_set.fundamental_interior (hs : null_measurable_set s \u03bc) :\n  null_measurable_set (fundamental_interior G s) \u03bc :=\nhs.diff $ null_measurable_set.Union $ \u03bb g, null_measurable_set.Union $ \u03bb hg, hs.smul _\n\nend measurable_space\n\nnamespace is_fundamental_domain\nsection group\nvariables [countable G] [group G] [mul_action G \u03b1] [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n  (hs : is_fundamental_domain G s \u03bc)\ninclude hs\n\n@[to_additive measure_theory.is_add_fundamental_domain.measure_add_fundamental_frontier]\nlemma measure_fundamental_frontier : \u03bc (fundamental_frontier G s) = 0 :=\nby simpa only [fundamental_frontier, Union\u2082_inter, measure_Union_null_iff', one_smul,\n  measure_Union_null_iff, inter_comm s, function.on_fun] using \u03bb g (hg : g \u2260 1), hs.ae_disjoint hg\n\n@[to_additive measure_theory.is_add_fundamental_domain.measure_add_fundamental_interior]\nlemma measure_fundamental_interior : \u03bc (fundamental_interior G s) = \u03bc s :=\nmeasure_diff_null' hs.measure_fundamental_frontier\n\nend group\n\nvariables [countable G] [group G] [mul_action G \u03b1] [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n  (hs : is_fundamental_domain G s \u03bc) [measurable_space G] [has_measurable_smul G \u03b1]\n  [smul_invariant_measure G \u03b1 \u03bc]\ninclude hs\n\nprotected lemma fundamental_interior : is_fundamental_domain G (fundamental_interior G s) \u03bc :=\n{ null_measurable_set := hs.null_measurable_set.fundamental_interior _ _,\n  ae_covers := begin\n    simp_rw [ae_iff, not_exists, \u2190mem_inv_smul_set_iff, set_of_forall, \u2190compl_set_of, set_of_mem_eq,\n      \u2190compl_Union],\n    have : (\u22c3 g : G, g\u207b\u00b9 \u2022 s) \\ (\u22c3 g : G, g\u207b\u00b9 \u2022 fundamental_frontier G s) \u2286\n      \u22c3 g : G, g\u207b\u00b9 \u2022 fundamental_interior G s,\n    { simp_rw [diff_subset_iff, \u2190Union_union_distrib, \u2190smul_set_union,\n        fundamental_frontier_union_fundamental_interior] },\n    refine eq_bot_mono (\u03bc.mono $ compl_subset_compl.2 this) _,\n    simp only [Union_inv_smul, outer_measure.measure_of_eq_coe, coe_to_outer_measure, compl_sdiff,\n      ennreal.bot_eq_zero, himp_eq, sup_eq_union, @Union_smul_eq_set_of_exists _ _ _ _ s],\n    exact measure_union_null\n      (measure_Union_null $ \u03bb _, measure_smul_null hs.measure_fundamental_frontier _) hs.ae_covers,\n  end,\n  ae_disjoint := (pairwise_disjoint_fundamental_interior _ _).mono $ \u03bb _ _, disjoint.ae_disjoint }\n\nend is_fundamental_domain\nend measure_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/group/fundamental_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7282548581164914}}
{"text": "import interior_world.definition -- hide\n\n/- Axiom : A set A is the neighborhood of a point x if there is an open U such that $x \\in U \\subseteq A$.\nis_neighborhood : \u2203 U, is_open U \u2227 x \u2208 U \u2227 U \u2286 A\n-/\n\n/- Axiom : A point x is an interior point of A if A is a neighborhood of x.\nis_interior_point : is_neighborhood x A\n-/\n\n/- Axiom : The interior of a set A is the set of all its interior points. \ninterior : { x : X | is_interior_point x A }\n-/\n\n/-\nIn this world we will end up having three alternative definitions of the interior of a set. \nThis will be very useful, because at any point we will be able to choose the one that better fits our needs.\n\nFirst of all we need to figure out what properties does the interior of an arbitrary set have... So we start with an easy one:\n\n# Level 1: The interior is contained in the original set\n\n-/\nvariables {X : Type} -- hide\nvariables [topological_space X] (x : X)  (A : set X) -- hide\n\nnamespace topological_space -- hide\n\n@[simp]  -- hide\n/- Lemma\nThe interior of any set A is contained in the set A.\n-/\nlemma interior_is_subset: interior A \u2286 A :=\nbegin\n  rintros x \u27e8_, _\u27e9,\n  tauto,\n\n\n\n\n\n\n\n\n\nend\n\nend topological_space -- hide\n", "meta": {"author": "joan-ferrer", "repo": "topologygameprova", "sha": "b0c0a320d52b77abeed145052bac15fa710b94be", "save_path": "github-repos/lean/joan-ferrer-topologygameprova", "path": "github-repos/lean/joan-ferrer-topologygameprova/topologygameprova-b0c0a320d52b77abeed145052bac15fa710b94be/src/interior_world/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8152324915965391, "lm_q1q2_score": 0.7282548528643112}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdvancedAdditionWorld.Level11 -- add_right_eq_zero\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 8: `succ_le_succ`\n\nAnother straightforward one.\n\n## Lemma : succ_le_succ\nFor all naturals `a` and `b`, if `a \u2264 b`, then `succ a \u2264 succ b`.\n-/\nlemma succ_le_succ (a b : MyNat) (h : a \u2264 b) : succ a \u2264 succ b := by\n  cases h with\n  | _ c hc =>\n    use c\n    rw [hc]\n    rw [succ_add]\n\n\n/-!\nNext up [Level 9](./Level9.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7282347708443763}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module data.set.enumerate\n! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Order.Basic\nimport Mathlib.Data.Set.Basic\nimport Mathlib.Tactic.SwapVar\n\n/-!\n# Set enumeration\nThis file allows enumeration of sets given a choice function.\nThe definition does not assume `sel` actually is a choice function, i.e. `sel s \u2208 s` and\n`sel s = none \u2194 s = \u2205`. These assumptions are added to the lemmas needing them.\n-/\n\n\nnoncomputable section\n\nopen Function\n\nnamespace Set\n\nsection Enumerate\n\n/- porting note : The original used parameters -/\nvariable {\u03b1 : Type _} (sel : Set \u03b1 \u2192 Option \u03b1)\n\n/-- Given a choice function `sel`, enumerates the elements of a set in the order\n`a 0 = sel s`, `a 1 = sel (s \\ {a 0})`, `a 2 = sel (s \\ {a 0, a 1})`, ... and stops when\n`sel (s \\ {a 0, ..., a n}) = none`. Note that we don't require `sel` to be a choice function. -/\ndef enumerate : Set \u03b1 \u2192 \u2115 \u2192 Option \u03b1\n  | s, 0 => sel s\n  | s, n + 1 => do\n    let a \u2190 sel s\n    enumerate (s \\ {a}) n\n#align set.enumerate Set.enumerate\n\ntheorem enumerate_eq_none_of_sel {s : Set \u03b1} (h : sel s = none) : \u2200 {n}, enumerate sel s n = none\n  | 0 => by simp [h, enumerate]\n  | n + 1 => by simp [h, enumerate]; rfl\n#align set.enumerate_eq_none_of_sel Set.enumerate_eq_none_of_sel\n\ntheorem enumerate_eq_none :\n    \u2200 {s n\u2081 n\u2082}, enumerate sel s n\u2081 = none \u2192 n\u2081 \u2264 n\u2082 \u2192 enumerate sel s n\u2082 = none\n  | s, 0, m => fun h _ \u21a6 enumerate_eq_none_of_sel sel h\n  | s, n + 1, m => fun h hm \u21a6 by\n    cases hs : sel s\n    \u00b7 exact enumerate_eq_none_of_sel sel hs\n    \u00b7 cases m\n      case zero =>\n        contradiction\n      case succ m' =>\n        simp [hs, enumerate] at h \u22a2\n        have hm : n \u2264 m' := Nat.le_of_succ_le_succ hm\n        exact enumerate_eq_none h hm\n#align set.enumerate_eq_none Set.enumerate_eq_none\n\ntheorem enumerate_mem (h_sel : \u2200 s a, sel s = some a \u2192 a \u2208 s) :\n    \u2200 {s n a}, enumerate sel s n = some a \u2192 a \u2208 s\n  | s, 0, a => h_sel s a\n  | s, n + 1, a => by\n    cases h : sel s\n    case none => simp [enumerate_eq_none_of_sel, h]\n    case some a' =>\n      simp [enumerate, h]\n      exact fun h' : enumerate sel (s \\ {a'}) n = some a \u21a6\n        have : a \u2208 s \\ {a'} := enumerate_mem h_sel h'\n        this.left\n#align set.enumerate_mem Set.enumerate_mem\n\ntheorem enumerate_inj {n\u2081 n\u2082 : \u2115} {a : \u03b1} {s : Set \u03b1} (h_sel : \u2200 s a, sel s = some a \u2192 a \u2208 s)\n    (h\u2081 : enumerate sel s n\u2081 = some a) (h\u2082 : enumerate sel s n\u2082 = some a) : n\u2081 = n\u2082 := by\n  /- porting note : The `rcase, on_goal, all_goals` has been used instead of\n     the not-yet-ported `wlog` -/\n  rcases le_total n\u2081 n\u2082 with (hn|hn)\n  on_goal 2 => swap_var n\u2081 \u2194 n\u2082, h\u2081 \u2194 h\u2082\n  all_goals\n    rcases Nat.le.dest hn with \u27e8m, rfl\u27e9\n    clear hn\n    induction n\u2081 generalizing s\n    case zero =>\n      cases m\n      case zero => rfl\n      case succ m =>\n        have h' : enumerate sel (s \\ {a}) m = some a := by\n          simp_all only [enumerate, Nat.zero_eq, Nat.add_eq, zero_add]; exact h\u2082\n        have : a \u2208 s \\ {a} := enumerate_mem sel h_sel h'\n        simp_all [Set.mem_diff_singleton]\n    case succ k ih =>\n      cases h : sel s\n      /- porting note : The original covered both goals with just `simp_all <;> tauto` -/\n      case none =>\n        simp_all only [add_comm, self_eq_add_left, Nat.add_succ, enumerate_eq_none_of_sel _ h]\n      case some _ =>\n        simp_all only [add_comm, self_eq_add_left, enumerate, Option.some.injEq,\n                       Nat.add_succ, enumerate._eq_2, Nat.succ.injEq]\n        exact ih h\u2081 h\u2082\n#align set.enumerate_inj Set.enumerate_inj\n\nend Enumerate\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Enumerate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7281653370143919}}
{"text": "/-\nCopyright (c) 2020 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n-/\n\nimport ..todo\nimport topology.subset_properties\nimport topology.separation\nimport topology.metric_space.basic\n\n/-!\nA formal roadmap for basic properties of paracompact spaces.\n\nIt contains the statements that compact spaces and metric spaces are paracompact,\nand that paracompact t2 spaces are normal, as well as partially formalised proofs.\n\nAny contributor should feel welcome to contribute complete proofs. When this happens,\nwe should also consider preserving the current file as an exemplar of a formal roadmap.\n-/\n\nopen set filter\n\nuniverse u\n\nnamespace roadmap\n\nclass paracompact_space (X : Type u) [topological_space X] : Prop :=\n(locally_finite_refinement :\n  \u2200 {\u03b1 : Type u} (u : \u03b1 \u2192 set X) (uo : \u2200 a, is_open (u a)) (uc : Union u = univ),\n  \u2203 {\u03b2 : Type u} (v : \u03b2 \u2192 set X) (vo : \u2200 b, is_open (v b)) (vc : Union v = univ),\n  locally_finite v \u2227 \u2200 b, \u2203 a, v b \u2286 u a)\n\n/-- Any open cover of a paracompact space has a locally finite *precise* refinement, that is,\n one indexed on the same type with each open set contained in the corresponding original one. -/\nlemma paracompact_space.precise_refinement {X : Type u} [topological_space X] [paracompact_space X]\n  {\u03b1 : Type u} (u : \u03b1 \u2192 set X) (uo : \u2200 a, is_open (u a)) (uc : Union u = univ) :\n  \u2203 v : \u03b1 \u2192 set X, (\u2200 a, is_open (v a)) \u2227 Union v = univ \u2227 locally_finite v \u2227 (\u2200 a, v a \u2286 u a) :=\nbegin\n  obtain \u27e8\u03b2, w, wo, wc, lfw, wr\u27e9 := paracompact_space.locally_finite_refinement u uo uc,\n  choose f hf using wr,\n  refine \u27e8\u03bb a, \u22c3\u2080 {s | \u2203 b, f b = a \u2227 s = w b}, \u03bb a, _, _, _, \u03bb a, _\u27e9,\n  { apply is_open_sUnion _,\n    rintros t \u27e8b, rfl, rfl\u27e9,\n    apply wo },\n  { todo },\n  { todo },\n  { apply sUnion_subset,\n    rintros t \u27e8b, rfl, rfl\u27e9,\n    apply hf }\nend\n\nlemma paracompact_of_compact {X : Type u} [topological_space X] [compact_space X] :\n  paracompact_space X :=\nbegin\n  refine \u27e8\u03bb \u03b1 u uo uc, _\u27e9,\n  obtain \u27e8s, _, sf, sc\u27e9 :=\n    is_compact_univ.elim_finite_subcover_image (\u03bb a _, uo a) (by rwa [univ_subset_iff, bUnion_univ]),\n  refine \u27e8s, \u03bb b, u b.val, \u03bb b, uo b.val, _, _, \u03bb b, \u27e8b.val, subset.refl _\u27e9\u27e9,\n  { todo },\n  { intro x,\n    refine \u27e8univ, univ_mem, _\u27e9,\n    todo },\nend\n\nlemma normal_of_paracompact_t2 {X : Type u} [topological_space X] [t2_space X]\n  [paracompact_space X] : normal_space X :=\ntodo\n/-\nSimilar to the proof of `generalized_tube_lemma`, but different enough not to merge them.\nLemma: if `s : set X` is closed and can be separated from any point by open sets,\nthen `s` can also be separated from any closed set by open sets. Apply twice.\n\nSee\n* Bourbaki, General Topology, Chapter IX, \u00a74.4\n* https://ncatlab.org/nlab/show/paracompact+Hausdorff+spaces+are+normal\n-/\n\nlemma paracompact_of_metric {X : Type u} [metric_space X] : paracompact_space X :=\ntodo\n/-\nSee Mary Ellen Rudin, A new proof that metric spaces are paracompact.\nhttps://www.ams.org/journals/proc/1969-020-02/S0002-9939-1969-0236876-3/S0002-9939-1969-0236876-3.pdf\n-/\nend roadmap\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/roadmap/topology/paracompact.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7281653287867715}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.filter.extr\nimport Mathlib.topology.continuous_on\nimport Mathlib.PostPort\n\nuniverses u v w x \n\nnamespace Mathlib\n\n/-!\n# Local extrema of functions on topological spaces\n\n## Main definitions\n\nThis file defines special versions of `is_*_filter f a l`, `*=min/max/extr`,\nfrom `order/filter/extr` for two kinds of filters: `nhds_within` and `nhds`.\nThese versions are called `is_local_*_on` and `is_local_*`, respectively.\n\n## Main statements\n\nMany lemmas in this file restate those from `order/filter/extr`, and you can find\na detailed documentation there. These convenience lemmas are provided only to make the dot notation\nreturn propositions of expected types, not just `is_*_filter`.\n\nHere is the list of statements specific to these two types of filters:\n\n* `is_local_*.on`, `is_local_*_on.on_subset`: restrict to a subset;\n* `is_local_*_on.inter` : intersect the set with another one;\n* `is_*_on.localize` : a global extremum is a local extremum too.\n* `is_[local_]*_on.is_local_*` : if we have `is_local_*_on f s a` and `s \u2208 \ud835\udcdd a`,\n  then we have `is_local_* f a`.\n\n-/\n\n/-- `is_local_min_on f s a` means that `f a \u2264 f x` for all `x \u2208 s` in some neighborhood of `a`. -/\ndef is_local_min_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (a : \u03b1) :=\n  is_min_filter f (nhds_within a s) a\n\n/-- `is_local_max_on f s a` means that `f x \u2264 f a` for all `x \u2208 s` in some neighborhood of `a`. -/\ndef is_local_max_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (a : \u03b1) :=\n  is_max_filter f (nhds_within a s) a\n\n/-- `is_local_extr_on f s a` means `is_local_min_on f s a \u2228 is_local_max_on f s a`. -/\ndef is_local_extr_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (a : \u03b1) :=\n  is_extr_filter f (nhds_within a s) a\n\n/-- `is_local_min f a` means that `f a \u2264 f x` for all `x` in some neighborhood of `a`. -/\ndef is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :=\n  is_min_filter f (nhds a) a\n\n/-- `is_local_max f a` means that `f x \u2264 f a` for all `x \u2208 s` in some neighborhood of `a`. -/\ndef is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :=\n  is_max_filter f (nhds a) a\n\n/-- `is_local_extr_on f s a` means `is_local_min_on f s a \u2228 is_local_max_on f s a`. -/\ndef is_local_extr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :=\n  is_extr_filter f (nhds a) a\n\ntheorem is_local_extr_on.elim {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {p : Prop} : is_local_extr_on f s a \u2192 (is_local_min_on f s a \u2192 p) \u2192 (is_local_max_on f s a \u2192 p) \u2192 p :=\n  or.elim\n\ntheorem is_local_extr.elim {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {p : Prop} : is_local_extr f a \u2192 (is_local_min f a \u2192 p) \u2192 (is_local_max f a \u2192 p) \u2192 p :=\n  or.elim\n\n/-! ### Restriction to (sub)sets -/\n\ntheorem is_local_min.on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_min f a) (s : set \u03b1) : is_local_min_on f s a :=\n  is_min_filter.filter_inf h (filter.principal s)\n\ntheorem is_local_max.on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_max f a) (s : set \u03b1) : is_local_max_on f s a :=\n  is_max_filter.filter_inf h (filter.principal s)\n\ntheorem is_local_extr.on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_extr f a) (s : set \u03b1) : is_local_extr_on f s a :=\n  is_extr_filter.filter_inf h (filter.principal s)\n\ntheorem is_local_min_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_local_min_on f t a) (h : s \u2286 t) : is_local_min_on f s a :=\n  is_min_filter.filter_mono hf (nhds_within_mono a h)\n\ntheorem is_local_max_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_local_max_on f t a) (h : s \u2286 t) : is_local_max_on f s a :=\n  is_max_filter.filter_mono hf (nhds_within_mono a h)\n\ntheorem is_local_extr_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_local_extr_on f t a) (h : s \u2286 t) : is_local_extr_on f s a :=\n  is_extr_filter.filter_mono hf (nhds_within_mono a h)\n\ntheorem is_local_min_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a) (t : set \u03b1) : is_local_min_on f (s \u2229 t) a :=\n  is_local_min_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_local_max_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a) (t : set \u03b1) : is_local_max_on f (s \u2229 t) a :=\n  is_local_max_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_local_extr_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a) (t : set \u03b1) : is_local_extr_on f (s \u2229 t) a :=\n  is_local_extr_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_min_on.localize {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_min_on f s a) : is_local_min_on f s a :=\n  is_min_filter.filter_mono hf inf_le_right\n\ntheorem is_max_on.localize {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_max_on f s a) : is_local_max_on f s a :=\n  is_max_filter.filter_mono hf inf_le_right\n\ntheorem is_extr_on.localize {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_extr_on f s a) : is_local_extr_on f s a :=\n  is_extr_filter.filter_mono hf inf_le_right\n\ntheorem is_local_min_on.is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a) (hs : s \u2208 nhds a) : is_local_min f a :=\n  (fun (this : nhds a \u2264 filter.principal s) => is_min_filter.filter_mono hf (le_inf (le_refl (nhds a)) this))\n    (iff.mpr filter.le_principal_iff hs)\n\ntheorem is_local_max_on.is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a) (hs : s \u2208 nhds a) : is_local_max f a :=\n  (fun (this : nhds a \u2264 filter.principal s) => is_max_filter.filter_mono hf (le_inf (le_refl (nhds a)) this))\n    (iff.mpr filter.le_principal_iff hs)\n\ntheorem is_local_extr_on.is_local_extr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a) (hs : s \u2208 nhds a) : is_local_extr f a :=\n  is_local_extr_on.elim hf\n    (fun (hf : is_local_min_on f s a) => is_min_filter.is_extr (is_local_min_on.is_local_min hf hs))\n    fun (hf : is_local_max_on f s a) => is_max_filter.is_extr (is_local_max_on.is_local_max hf hs)\n\ntheorem is_min_on.is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_min_on f s a) (hs : s \u2208 nhds a) : is_local_min f a :=\n  is_local_min_on.is_local_min (is_min_on.localize hf) hs\n\ntheorem is_max_on.is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_max_on f s a) (hs : s \u2208 nhds a) : is_local_max f a :=\n  is_local_max_on.is_local_max (is_max_on.localize hf) hs\n\ntheorem is_extr_on.is_local_extr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_extr_on f s a) (hs : s \u2208 nhds a) : is_local_extr f a :=\n  is_local_extr_on.is_local_extr (is_extr_on.localize hf) hs\n\n/-! ### Constant -/\n\ntheorem is_local_min_on_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_local_min_on (fun (_x : \u03b1) => b) s a :=\n  is_min_filter_const\n\ntheorem is_local_max_on_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_local_max_on (fun (_x : \u03b1) => b) s a :=\n  is_max_filter_const\n\ntheorem is_local_extr_on_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_local_extr_on (fun (_x : \u03b1) => b) s a :=\n  is_extr_filter_const\n\ntheorem is_local_min_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {a : \u03b1} {b : \u03b2} : is_local_min (fun (_x : \u03b1) => b) a :=\n  is_min_filter_const\n\ntheorem is_local_max_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {a : \u03b1} {b : \u03b2} : is_local_max (fun (_x : \u03b1) => b) a :=\n  is_max_filter_const\n\ntheorem is_local_extr_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {a : \u03b1} {b : \u03b2} : is_local_extr (fun (_x : \u03b1) => b) a :=\n  is_extr_filter_const\n\n/-! ### Composition with (anti)monotone functions -/\n\ntheorem is_local_min.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_min (g \u2218 f) a :=\n  is_min_filter.comp_mono hf hg\n\ntheorem is_local_max.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_max (g \u2218 f) a :=\n  is_max_filter.comp_mono hf hg\n\ntheorem is_local_extr.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_extr f a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_extr (g \u2218 f) a :=\n  is_extr_filter.comp_mono hf hg\n\ntheorem is_local_min.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_max (g \u2218 f) a :=\n  is_min_filter.comp_antimono hf hg\n\ntheorem is_local_max.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_min (g \u2218 f) a :=\n  is_max_filter.comp_antimono hf hg\n\ntheorem is_local_extr.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_extr f a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_extr (g \u2218 f) a :=\n  is_extr_filter.comp_antimono hf hg\n\ntheorem is_local_min_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_min_on (g \u2218 f) s a :=\n  is_min_filter.comp_mono hf hg\n\ntheorem is_local_max_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_max_on (g \u2218 f) s a :=\n  is_max_filter.comp_mono hf hg\n\ntheorem is_local_extr_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_extr_on (g \u2218 f) s a :=\n  is_extr_filter.comp_mono hf hg\n\ntheorem is_local_min_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_max_on (g \u2218 f) s a :=\n  is_min_filter.comp_antimono hf hg\n\ntheorem is_local_max_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_min_on (g \u2218 f) s a :=\n  is_max_filter.comp_antimono hf hg\n\ntheorem is_local_extr_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_extr_on (g \u2218 f) s a :=\n  is_extr_filter.comp_antimono hf hg\n\ntheorem is_local_min.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_local_min f a) {g : \u03b1 \u2192 \u03b3} (hg : is_local_min g a) : is_local_min (fun (x : \u03b1) => op (f x) (g x)) a :=\n  is_min_filter.bicomp_mono hop hf hg\n\ntheorem is_local_max.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_local_max f a) {g : \u03b1 \u2192 \u03b3} (hg : is_local_max g a) : is_local_max (fun (x : \u03b1) => op (f x) (g x)) a :=\n  is_max_filter.bicomp_mono hop hf hg\n\n-- No `extr` version because we need `hf` and `hg` to be of the same kind\n\ntheorem is_local_min_on.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_local_min_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => op (f x) (g x)) s a :=\n  is_min_filter.bicomp_mono hop hf hg\n\ntheorem is_local_max_on.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_local_max_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => op (f x) (g x)) s a :=\n  is_max_filter.bicomp_mono hop hf hg\n\n/-! ### Composition with `continuous_at` -/\n\ntheorem is_local_min.comp_continuous {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_min f (g b)) (hg : continuous_at g b) : is_local_min (f \u2218 g) b :=\n  hg hf\n\ntheorem is_local_max.comp_continuous {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_max f (g b)) (hg : continuous_at g b) : is_local_max (f \u2218 g) b :=\n  hg hf\n\ntheorem is_local_extr.comp_continuous {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_extr f (g b)) (hg : continuous_at g b) : is_local_extr (f \u2218 g) b :=\n  is_extr_filter.comp_tendsto hf hg\n\ntheorem is_local_min.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {s : set \u03b4} {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_min f (g b)) (hg : continuous_on g s) (hb : b \u2208 s) : is_local_min_on (f \u2218 g) s b :=\n  is_min_filter.comp_tendsto hf (hg b hb)\n\ntheorem is_local_max.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {s : set \u03b4} {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_max f (g b)) (hg : continuous_on g s) (hb : b \u2208 s) : is_local_max_on (f \u2218 g) s b :=\n  is_max_filter.comp_tendsto hf (hg b hb)\n\ntheorem is_local_extr.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {s : set \u03b4} (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_local_extr f (g b)) (hg : continuous_on g s) (hb : b \u2208 s) : is_local_extr_on (f \u2218 g) s b :=\n  is_local_extr.elim hf\n    (fun (hf : is_local_min f (g b)) => is_min_filter.is_extr (is_local_min.comp_continuous_on hf hg hb))\n    fun (hf : is_local_max f (g b)) => is_max_filter.is_extr (is_local_max.comp_continuous_on hf hg hb)\n\ntheorem is_local_min_on.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {t : set \u03b1} {s : set \u03b4} {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_min_on f t (g b)) (hst : s \u2286 g \u207b\u00b9' t) (hg : continuous_on g s) (hb : b \u2208 s) : is_local_min_on (f \u2218 g) s b :=\n  is_min_filter.comp_tendsto hf\n    (tendsto_nhds_within_mono_right (iff.mpr set.image_subset_iff hst)\n      (continuous_within_at.tendsto_nhds_within_image (hg b hb)))\n\ntheorem is_local_max_on.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {t : set \u03b1} {s : set \u03b4} {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_max_on f t (g b)) (hst : s \u2286 g \u207b\u00b9' t) (hg : continuous_on g s) (hb : b \u2208 s) : is_local_max_on (f \u2218 g) s b :=\n  is_max_filter.comp_tendsto hf\n    (tendsto_nhds_within_mono_right (iff.mpr set.image_subset_iff hst)\n      (continuous_within_at.tendsto_nhds_within_image (hg b hb)))\n\ntheorem is_local_extr_on.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {t : set \u03b1} {s : set \u03b4} (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_local_extr_on f t (g b)) (hst : s \u2286 g \u207b\u00b9' t) (hg : continuous_on g s) (hb : b \u2208 s) : is_local_extr_on (f \u2218 g) s b :=\n  is_local_extr_on.elim hf\n    (fun (hf : is_local_min_on f t (g b)) => is_min_filter.is_extr (is_local_min_on.comp_continuous_on hf hst hg hb))\n    fun (hf : is_local_max_on f t (g b)) => is_max_filter.is_extr (is_local_max_on.comp_continuous_on hf hst hg hb)\n\n/-! ### Pointwise addition -/\n\ntheorem is_local_min.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) : is_local_min (fun (x : \u03b1) => f x + g x) a :=\n  is_min_filter.add hf hg\n\ntheorem is_local_max.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) : is_local_max (fun (x : \u03b1) => f x + g x) a :=\n  is_max_filter.add hf hg\n\ntheorem is_local_min_on.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => f x + g x) s a :=\n  is_min_filter.add hf hg\n\ntheorem is_local_max_on.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => f x + g x) s a :=\n  is_max_filter.add hf hg\n\n/-! ### Pointwise negation and subtraction -/\n\ntheorem is_local_min.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) : is_local_max (fun (x : \u03b1) => -f x) a :=\n  is_min_filter.neg hf\n\ntheorem is_local_max.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) : is_local_min (fun (x : \u03b1) => -f x) a :=\n  is_max_filter.neg hf\n\ntheorem is_local_extr.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_extr f a) : is_local_extr (fun (x : \u03b1) => -f x) a :=\n  is_extr_filter.neg hf\n\ntheorem is_local_min_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) : is_local_max_on (fun (x : \u03b1) => -f x) s a :=\n  is_min_filter.neg hf\n\ntheorem is_local_max_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) : is_local_min_on (fun (x : \u03b1) => -f x) s a :=\n  is_max_filter.neg hf\n\ntheorem is_local_extr_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_extr_on f s a) : is_local_extr_on (fun (x : \u03b1) => -f x) s a :=\n  is_extr_filter.neg hf\n\ntheorem is_local_min.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_max g a) : is_local_min (fun (x : \u03b1) => f x - g x) a :=\n  is_min_filter.sub hf hg\n\ntheorem is_local_max.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_min g a) : is_local_max (fun (x : \u03b1) => f x - g x) a :=\n  is_max_filter.sub hf hg\n\ntheorem is_local_min_on.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) (hg : is_local_max_on g s a) : is_local_min_on (fun (x : \u03b1) => f x - g x) s a :=\n  is_min_filter.sub hf hg\n\ntheorem is_local_max_on.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) (hg : is_local_min_on g s a) : is_local_max_on (fun (x : \u03b1) => f x - g x) s a :=\n  is_max_filter.sub hf hg\n\n/-! ### Pointwise `sup`/`inf` -/\n\ntheorem is_local_min.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) : is_local_min (fun (x : \u03b1) => f x \u2294 g x) a :=\n  is_min_filter.sup hf hg\n\ntheorem is_local_max.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) : is_local_max (fun (x : \u03b1) => f x \u2294 g x) a :=\n  is_max_filter.sup hf hg\n\ntheorem is_local_min_on.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => f x \u2294 g x) s a :=\n  is_min_filter.sup hf hg\n\ntheorem is_local_max_on.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => f x \u2294 g x) s a :=\n  is_max_filter.sup hf hg\n\ntheorem is_local_min.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) : is_local_min (fun (x : \u03b1) => f x \u2293 g x) a :=\n  is_min_filter.inf hf hg\n\ntheorem is_local_max.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) : is_local_max (fun (x : \u03b1) => f x \u2293 g x) a :=\n  is_max_filter.inf hf hg\n\ntheorem is_local_min_on.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => f x \u2293 g x) s a :=\n  is_min_filter.inf hf hg\n\ntheorem is_local_max_on.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => f x \u2293 g x) s a :=\n  is_max_filter.inf hf hg\n\n/-! ### Pointwise `min`/`max` -/\n\ntheorem is_local_min.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) : is_local_min (fun (x : \u03b1) => min (f x) (g x)) a :=\n  is_min_filter.min hf hg\n\ntheorem is_local_max.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) : is_local_max (fun (x : \u03b1) => min (f x) (g x)) a :=\n  is_max_filter.min hf hg\n\ntheorem is_local_min_on.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => min (f x) (g x)) s a :=\n  is_min_filter.min hf hg\n\ntheorem is_local_max_on.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => min (f x) (g x)) s a :=\n  is_max_filter.min hf hg\n\ntheorem is_local_min.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) : is_local_min (fun (x : \u03b1) => max (f x) (g x)) a :=\n  is_min_filter.max hf hg\n\ntheorem is_local_max.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) : is_local_max (fun (x : \u03b1) => max (f x) (g x)) a :=\n  is_max_filter.max hf hg\n\ntheorem is_local_min_on.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => max (f x) (g x)) s a :=\n  is_min_filter.max hf hg\n\ntheorem is_local_max_on.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => max (f x) (g x)) s a :=\n  is_max_filter.max hf hg\n\n/-! ### Relation with `eventually` comparisons of two functions -/\n\ntheorem filter.eventually_le.is_local_max_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hle : filter.eventually_le (nhds_within a s) g f) (hfga : f a = g a) (h : is_local_max_on f s a) : is_local_max_on g s a :=\n  filter.eventually_le.is_max_filter hle hfga h\n\ntheorem is_local_max_on.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_max_on f s a) (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_max_on g s a :=\n  is_max_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_eq.is_local_max_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_max_on f s a \u2194 is_local_max_on g s a :=\n  filter.eventually_eq.is_max_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_le.is_local_min_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hle : filter.eventually_le (nhds_within a s) f g) (hfga : f a = g a) (h : is_local_min_on f s a) : is_local_min_on g s a :=\n  filter.eventually_le.is_min_filter hle hfga h\n\ntheorem is_local_min_on.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_min_on f s a) (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_min_on g s a :=\n  is_min_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_eq.is_local_min_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_min_on f s a \u2194 is_local_min_on g s a :=\n  filter.eventually_eq.is_min_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem is_local_extr_on.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_extr_on f s a) (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_extr_on g s a :=\n  is_extr_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_eq.is_local_extr_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_extr_on f s a \u2194 is_local_extr_on g s a :=\n  filter.eventually_eq.is_extr_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_le.is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hle : filter.eventually_le (nhds a) g f) (hfga : f a = g a) (h : is_local_max f a) : is_local_max g a :=\n  filter.eventually_le.is_max_filter hle hfga h\n\ntheorem is_local_max.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_max f a) (heq : filter.eventually_eq (nhds a) f g) : is_local_max g a :=\n  is_max_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_eq.is_local_max_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds a) f g) : is_local_max f a \u2194 is_local_max g a :=\n  filter.eventually_eq.is_max_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_le.is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hle : filter.eventually_le (nhds a) f g) (hfga : f a = g a) (h : is_local_min f a) : is_local_min g a :=\n  filter.eventually_le.is_min_filter hle hfga h\n\ntheorem is_local_min.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_min f a) (heq : filter.eventually_eq (nhds a) f g) : is_local_min g a :=\n  is_min_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_eq.is_local_min_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds a) f g) : is_local_min f a \u2194 is_local_min g a :=\n  filter.eventually_eq.is_min_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem is_local_extr.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_extr f a) (heq : filter.eventually_eq (nhds a) f g) : is_local_extr g a :=\n  is_extr_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_eq.is_local_extr_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds a) f g) : is_local_extr f a \u2194 is_local_extr g a :=\n  filter.eventually_eq.is_extr_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/topology/local_extr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7281653236131219}}
{"text": "import mynat.definition\nimport mynat.add\nimport world8.level4\n\nnamespace mynat\n\ntheorem ne_succ_self (n : mynat) : n \u2260 succ(n) :=\nbegin [nat_num_game]\n    induction n with d hd,\n    {\n        exact zero_ne_succ 0,\n    },\n    {\n        intro h,\n        apply hd,\n        apply succ_inj,\n        exact h,\n    },\nend\n\n-- theorem ne_succ_self (n : mynat) : n \u2260 succ(n) :=\n-- begin [nat_num_game]\n--     induction n with d hd,\n--     {\n--         exact zero_ne_succ 0,\n--     },\n--     {\n--         rw ne_from_not_eq at hd,\n--         rw \u2190 eq_iff_succ_eq_succ at hd,\n--         rw \u2190 ne_from_not_eq at hd,\n--         exact hd,\n--     },\n-- end\n\nend mynat\n", "meta": {"author": "nomoid", "repo": "lean-proofs", "sha": "b9f03a24623d1a1d111d6c2bbf53c617e2596d6a", "save_path": "github-repos/lean/nomoid-lean-proofs", "path": "github-repos/lean/nomoid-lean-proofs/lean-proofs-b9f03a24623d1a1d111d6c2bbf53c617e2596d6a/src/world8/level13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7281601787001025}}
{"text": "import data.real.irrational\n\ntheorem t001 : irrational (real.sqrt 2) :=\nirr_sqrt_two\n\n#print t001\n", "meta": {"author": "AtnNn", "repo": "lean-sandbox", "sha": "8c68afbdc09213173aef1be195da7a9a86060a97", "save_path": "github-repos/lean/AtnNn-lean-sandbox", "path": "github-repos/lean/AtnNn-lean-sandbox/lean-sandbox-8c68afbdc09213173aef1be195da7a9a86060a97/src/100_theorems/t001.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7281601777087647}}
{"text": "/- \n\n# Advanced proposition world. \n\n## Level 4: `iff_trans`.\n\nThe mathematical statement $P\\iff Q$ is equivalent to $(P\\implies Q)\\land(Q\\implies P)$. The `cases`\nand `split` tactics work on hypotheses and goals (respectively) of the form `P \u2194 Q`. If you need\nto write an `\u2194` arrow you can do so by typing `\\iff`, but you shouldn't need to. After an initial\n`intro h,` you can type `cases h with hpq hqp` to break `h : P \u2194 Q` into its constituent parts.\n-/\n\n/- Lemma\nIf $P$, $Q$ and $R$ are true/false statements, then\n$P\\iff Q$ and $Q\\iff R$ together imply $P\\iff R$.\n-/\nlemma iff_trans (P Q R : Prop) : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intro hpq,\n  intro hqr,\n  cases hpq with hpq hqp,\n  cases hqr with hqr hrq,\n  split,\n  cc,cc,\n\n\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world7/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7281601714605005}}
{"text": "/-\nCopyright (c) 2020 Hanting Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hanting Zhang\n-/\nimport ring_theory.polynomial.basic\nimport ring_theory.polynomial.symmetric\n\n/-!\n# Vieta's Formula\n\nThe main result is `vieta.prod_X_add_C_eq_sum_esymm`, which shows that the product of linear terms\n`\u03bb + X i` is equal to a linear combination of the symmetric polynomials `esymm \u03c3 R j`.\n\n## Implementation Notes:\n\nWe first take the viewpoint where the \"roots\" `X i` are variables. This means we work over\n`polynomial (mv_polynomial \u03c3 R)`, which enables us to talk about linear combinations of\n`esymm \u03c3 R j`. We then derive Vieta's formula in `polynomial R` by giving a\nvaluation from each `X i` to `r i`.\n\n-/\n\nuniverses u\nopen_locale big_operators\n\nopen finset polynomial fintype\n\nnamespace mv_polynomial\n\nvariables {R : Type u} [comm_semiring R]\nvariables (\u03c3 : Type u) [fintype \u03c3]\n\n/-- A sum version of Vieta's formula. Viewing `X i` as variables,\nthe product of linear terms `\u03bb + X i` is equal to a linear combination of\nthe symmetric polynomials `esymm \u03c3 R j`. -/\nlemma prod_X_add_C_eq_sum_esymm :\n  (\u220f i : \u03c3, (polynomial.C (X i) + polynomial.X) : polynomial (mv_polynomial \u03c3 R) )=\n  \u2211 j in range (card \u03c3 + 1),\n    (polynomial.C (esymm \u03c3 R j) * polynomial.X ^ (card \u03c3 - j)) :=\nbegin\n  classical,\n  rw [prod_add, sum_powerset],\n  refine sum_congr begin congr end (\u03bb j hj, _),\n  rw [esymm, polynomial.C.map_sum, sum_mul],\n  refine sum_congr rfl (\u03bb t ht, _),\n  have h : (univ \\ t).card = card \u03c3 - j :=\n  by { rw card_sdiff (mem_powerset_len.mp ht).1, congr, exact (mem_powerset_len.mp ht).2 },\n  rw [(polynomial.C : mv_polynomial \u03c3 R \u2192+* polynomial _).map_prod, prod_const, \u2190 h],\n  congr,\nend\n\n/-- A fully expanded sum version of Vieta's formula, evaluated at the roots.\nThe product of linear terms `X + r i` is equal to `\u2211 j in range (n + 1), e_j * X ^ (n - j)`,\nwhere `e_j` is the `j`th symmetric polynomial of the constant terms `r i`. -/\nlemma prod_X_add_C_eval (r : \u03c3 \u2192 R) : \u220f i : \u03c3, (polynomial.C (r i) + polynomial.X) =\n  \u2211 i in range (card \u03c3 + 1), (\u2211 t in powerset_len i (univ : finset \u03c3),\n    \u220f i in t, polynomial.C (r i)) * polynomial.X ^ (card \u03c3 - i) :=\nbegin\n  classical,\n  have h := @prod_X_add_C_eq_sum_esymm _ _ \u03c3 _,\n  apply_fun (polynomial.map (eval r)) at h,\n  rw [map_prod, map_sum] at h,\n  convert h,\n  simp only [eval_X, polynomial.map_add, polynomial.map_C, polynomial.map_X, eq_self_iff_true],\n  funext,\n  simp only [function.funext_iff, esymm, polynomial.map_C, map_sum, polynomial.C.map_sum,\n    polynomial.map_C, map_pow, polynomial.map_X, polynomial.map_mul],\n  congr,\n  funext,\n  simp only [eval_prod, eval_X, (polynomial.C : R \u2192+* polynomial R).map_prod],\nend\n\nlemma esymm_to_sum (r : \u03c3 \u2192 R) (j : \u2115) : polynomial.C (eval r (esymm \u03c3 R j)) =\n  \u2211 t in powerset_len j (univ : finset \u03c3), \u220f i in t, polynomial.C (r i) :=\nby simp only [esymm, eval_sum, eval_prod, eval_X, polynomial.C.map_sum,\n  (polynomial.C : R \u2192+* polynomial _).map_prod]\n\n/-- Vieta's formula for the coefficients of the product of linear terms `X + r i`,\nThe `k`th coefficient is `\u2211 t in powerset_len (card \u03c3 - k) (univ : finset \u03c3), \u220f i in t, r i`,\ni.e. the symmetric polynomial `esymm \u03c3 R (card \u03c3 - k)` of the constant terms `r i`. -/\n\n\nend mv_polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/polynomial/vieta.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7281601688229741}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.category.Module.abelian\nimport category_theory.limits.shapes.images\n\n/-!\n# The category of R-modules has images.\n\nNote that we don't need to register any of the constructions here as instances, because we get them\nfrom the fact that `Module R` is an abelian category.\n-/\n\nopen category_theory\nopen category_theory.limits\n\nuniverses u v\n\nnamespace Module\n\nvariables {R : Type u} [comm_ring R]\n\nvariables {G H : Module.{v} R} (f : G \u27f6 H)\n\nlocal attribute [ext] subtype.ext_val\n\nsection -- implementation details of `has_image` for Module; use the API, not these\n/-- The image of a morphism in `Module R` is just the bundling of `linear_map.range f` -/\ndef image : Module R := Module.of R (linear_map.range f)\n\n/-- The inclusion of `image f` into the target -/\ndef image.\u03b9 : image f \u27f6 H := f.range.subtype\n\ninstance : mono (image.\u03b9 f) := concrete_category.mono_of_injective (image.\u03b9 f) subtype.val_injective\n\n/-- The corestriction map to the image -/\ndef factor_thru_image : G \u27f6 image f := f.range_restrict\n\nlemma image.fac : factor_thru_image f \u226b image.\u03b9 f = f :=\nby { ext, refl, }\n\nlocal attribute [simp] image.fac\n\nvariables {f}\n/-- The universal property for the image factorisation -/\nnoncomputable def image.lift (F' : mono_factorisation f) : image f \u27f6 F'.I :=\n{ to_fun :=\n  (\u03bb x, F'.e (classical.indefinite_description _ x.2).1 : image f \u2192 F'.I),\n  map_add' :=\n  begin\n    intros x y,\n    haveI := F'.m_mono,\n    apply (mono_iff_injective F'.m).1, apply_instance,\n    rw [linear_map.map_add],\n    change (F'.e \u226b F'.m) _ = (F'.e \u226b F'.m) _ + (F'.e \u226b F'.m) _,\n    rw [F'.fac],\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    refl,\n  end,\n  map_smul' := \u03bb c x,\n  begin\n    haveI := F'.m_mono,\n    apply (mono_iff_injective F'.m).1, apply_instance,\n    rw [linear_map.map_smul],\n    change (F'.e \u226b F'.m) _ = _ \u2022 (F'.e \u226b F'.m) _,\n    rw [F'.fac],\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    rw (classical.indefinite_description (\u03bb z, f z = _) _).2,\n    refl,\n  end }\n\nlemma image.lift_fac (F' : mono_factorisation f) : image.lift F' \u226b F'.m = image.\u03b9 f :=\nbegin\n  ext x,\n  change (F'.e \u226b F'.m) _ = _,\n  rw [F'.fac, (classical.indefinite_description _ x.2).2],\n  refl,\nend\nend\n\n/-- The factorisation of any morphism in `Module R` through a mono. -/\ndef mono_factorisation : mono_factorisation f :=\n{ I := image f,\n  m := image.\u03b9 f,\n  e := factor_thru_image f }\n\n/-- The factorisation of any morphism in `Module R` through a mono has the universal property of\nthe image. -/\nnoncomputable def is_image : is_image (mono_factorisation f) :=\n{ lift := image.lift,\n  lift_fac' := image.lift_fac }\n\n/--\nThe categorical image of a morphism in `Module R`\nagrees with the linear algebraic range.\n-/\nnoncomputable def image_iso_range {G H : Module.{v} R} (f : G \u27f6 H) :\n  limits.image f \u2245 Module.of R f.range :=\nis_image.iso_ext (image.is_image f) (is_image f)\n\n@[simp, reassoc, elementwise]\nlemma image_iso_range_inv_image_\u03b9 {G H : Module.{v} R} (f : G \u27f6 H) :\n  (image_iso_range f).inv \u226b limits.image.\u03b9 f = Module.of_hom f.range.subtype :=\nis_image.iso_ext_inv_m _ _\n\n@[simp, reassoc, elementwise]\nlemma image_iso_range_hom_subtype {G H : Module.{v} R} (f : G \u27f6 H) :\n  (image_iso_range f).hom \u226b Module.of_hom f.range.subtype = limits.image.\u03b9 f :=\nby erw [\u2190image_iso_range_inv_image_\u03b9 f, iso.hom_inv_id_assoc]\n\nend Module\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/category/Module/images.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7281565700447021}}
{"text": "/-\nThis file contains a formal computer proof of O(1/k) convergence of gradient descent with \nconstant stepsize for convex functions of scalar-valued inputs. It is self-contained \nother than using properties of real and natural numbers defined in mathlib.  \nI define the properties of convexity and Lipschitz continuous gradient here\nand do not rely on the mathlib-defined gradient. This means that a user \nwould have to ensure that their function is convex and the gradient is correct.\nWhile not ideal, this simplified the proofs. \n\nWe closely follow the proof of\nhttp://www.seas.ucla.edu/~vandenbe/236C/lectures/gradient.pdf\n-/\n\nimport data.real.basic \n\n-- The method under study \n-- This is a polymorphic definition in that it works for any Type \u03b1 that has\n-- a subtraction operation and a multiplication operation.\n-- This allows us to reason about behavior for the case \u03b1 = \u211d but also \n-- run it when \u03b1 = float. We will only prove theorems for \u03b1 = \u211d. \ndef grad_descent {\u03b1 : Type}\n            [has_sub \u03b1]\n            [has_mul \u03b1]\n            (\u03b7 : \u03b1) (x0 : \u03b1) (gradf : \u03b1 \u2192 \u03b1): (\u2115 \u2192 \u03b1) \n| 0      := x0 \n| (n+1)  := grad_descent(n) - \u03b7*gradf(grad_descent(n))\n \n-- Definition of a convex function and it's gradient. \ndef is_convex (f: \u211d \u2192 \u211d) (gradf : \u211d \u2192 \u211d) : Prop := \n  \u2200 (x y : \u211d), f(y) \u2265  f(x) + gradf(x)*(y-x)\n\n-- (Working) Definition of Lipschitz-continuous gradient\ndef is_lip_grad (f: \u211d \u2192 \u211d) (gradf : \u211d \u2192 \u211d) (L : \u211d) : Prop :=\n  \u2200 (x y : \u211d), f(y) \u2264 f(x) + gradf(x)*(y-x) + 0.5*L*(y-x)^2 \n\n-- A basic descent lemma for gradient descent \nlemma basic_grad_step (x : \u211d) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hlip : is_lip_grad f gradf L)\n                      :\n  f(x-\u03b7*gradf x) \u2264 f(x) - \u03b7*(1-L*\u03b7/2)*(gradf x)^2 \n  :=\nbegin\n  have hLip := hlip x (x-\u03b7*gradf x),\n    \n  rw mul_comm \u03b7 (gradf x) at hLip,\n  \n  have h1 : x - gradf x * \u03b7 - x = - gradf x * \u03b7 := by linarith,\n  rw h1 at hLip,\n  have h2 : 1 / 2 * L * (-gradf x * \u03b7) ^ 2 = 1 / 2 * L * (gradf x)^2 * \u03b7^2 \n  := by ring,\n  rw h2 at hLip,\n  have h3 : gradf x * (-gradf x * \u03b7) = - \u03b7*(gradf x)^2 := by ring,\n  rw h3 at hLip,\n  have h4 : 1 / 2 * L * gradf x ^ 2 * \u03b7 ^ 2 = (1 / 2)*(\u03b7 ^ 2) * L * gradf x^2\n  := by ring,\n  rw h4 at hLip,\n  have h5 :f x + -\u03b7 * gradf x ^ 2 + 1 / 2 * \u03b7 ^ 2 * L * gradf x ^ 2 \n            = f x -\u03b7*(1 -  \u03b7 * L/2) * gradf x^2\n            := by linarith,\n  \n  rw h5 at hLip,\n  rw mul_comm (gradf x) \u03b7 at hLip,\n  rw mul_comm \u03b7 L at hLip,\n  exact hLip,\n  \nend \n\n-- an algebraic manipulation lemma \nlemma complete_square (a b t : \u211d) (ht : t > 0): \n  a*b - (t/2)*a^2 = (1/(2*t))*(b^2 - (b-t*a)^2)\n  :=\nbegin\n  have h1 : (b-t*a)^2 = b^2 - 2*b*t*a + (t*a)^2,\n  {\n    rw sub_sq,\n    ring,\n  },\n  rw h1,\n  have h2 :b ^ 2 - (b ^ 2 - 2 * b * t * a + (t * a) ^ 2) = \n      2 * b * t * a - (t * a) ^ 2 := by linarith,\n  rw h2,\n  have h3 : 1 / (2 * t) * (2 * b * t * a - (t * a) ^ 2) = \n            1 / (2 * t) * 2 * b * t * a - 1 / (2 * t)*(t * a) ^ 2\n          := by ring,\n  rw h3,\n  simp,\n  have h4 : (2*t)\u207b\u00b9 = 2\u207b\u00b9*t\u207b\u00b9 := mul_inv\u2080,\n  rw h4,\n  rw pow_two (t*a),\n  have h5 :  2\u207b\u00b9 * t\u207b\u00b9 * (t * a * (t * a)) = 2\u207b\u00b9 * (t\u207b\u00b9 * t) * a * (t * a) \n    := by ring,\n  rw h5,\n  have ht2 : t \u2260 0 := by linarith,\n  rw mul_comm t\u207b\u00b9 t,\n\n  rw mul_inv_cancel ht2,\n  rw mul_one,\n\n  have h6 : 2\u207b\u00b9 * t\u207b\u00b9 * 2 * b * t * a = 2\u207b\u00b9 * 2 * (t\u207b\u00b9 * t) * b  * a := by ring,\n  rw h6,\n  rw mul_comm t\u207b\u00b9 t,\n  rw mul_inv_cancel ht2,\n  rw mul_one,\n  have h7 : 2\u207b\u00b9 * 2 * b * a = b*a := by ring,\n  rw h7,\n  \n  have h8 : 2\u207b\u00b9 * a * (t * a) = 2\u207b\u00b9 * t * a * a := by ring,\n  rw h8,\n  rw div_eq_inv_mul,\n  ring,\n \nend \n\n-- a stepsize technicality \nlemma stepsz_upper (t L : \u211d) (hL : L \u2265 0) (h : t\u22641/L): t*L \u2264 1 :=\nbegin \n  \n  cases lt_or_ge 0 L,\n\n  exact (le_div_iff h_1).mp h,\n\n  have h2 : L=0 := by linarith,\n  rw h2,\n  linarith,\n  \nend \n\n-- further refinement of the descent properties of the algorithm \nlemma basic_grad_step_v2 (x : \u211d) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 \u2265 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      :\n    f(x-\u03b7*gradf x) \u2264 f(x) -(\u03b7/2)*(gradf x)^2 \n  :=\n  begin\n    have hbas := basic_grad_step x \u03b7 L f gradf hlip,\n    have hgradPos : gradf x ^2 \u2265 0 := by exact sq_nonneg (gradf x),\n\n    have hCoefPos : \u03b7*(1-L*\u03b7/2) \u2265 \u03b7/2,\n    {\n\n      have h3 : \u03b7*L \u2264 1 := by exact stepsz_upper \u03b7 L hL h\u03b72,\n\n      have h4 : L*\u03b7\u2264 1 := by linarith,\n      have h5 : L*\u03b7/2 \u2264 1/2 := by linarith,\n      have h6 : -L*\u03b7/2 \u2265  -1/2 := by linarith,\n      have h7 : 1-L*\u03b7/2 \u2265  1/2 := by linarith,\n      have h8 : \u03b7*(1-L*\u03b7/2) \u2265  \u03b7*(1/2) \n              := by exact mul_le_mul_of_nonneg_left h7 h\u03b7_low,\n      linarith,\n    },\n    \n    have h9 : \u03b7*(1-L*\u03b7/2)*(gradf x)^2 \u2265 (\u03b7/2)*(gradf x)^2 :=\n      mul_mono_nonneg hgradPos hCoefPos,\n    \n    linarith,\n    \n  end \n\n-- formally stating that the algorithm decreases function values \nlemma descent (x : \u211d) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 \u2265 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      :\n    f(x-\u03b7*gradf x) \u2264 f(x) \n  :=\nbegin\n  have hbas := basic_grad_step_v2 x \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip,\n  have hgradPos : gradf x ^2 \u2265 0 := by exact sq_nonneg (gradf x),\n  have h2 : \u03b7 / 2 \u2265 0 := by linarith,\n  have h3 : (\u03b7 / 2)*(gradf x)^2 \u2265 0 := mul_nonneg h2 hgradPos,\n  linarith,\nend \n\nlemma prepare_to_telescope (x y: \u211d) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    f(x-\u03b7*gradf x) - f y \u2264 (1/(2*\u03b7))*((x-y)^2 - (x-\u03b7*gradf x - y)^2)\n    :=\nbegin \n  \n  have h\u03b7_low2 : \u03b7 \u2265 0 := by linarith,\n\n  have h1 := basic_grad_step_v2  x \u03b7 L f gradf hL h\u03b7_low2 h\u03b72 hlip,\n  \n  have h2 :  f (x - \u03b7 * gradf x) -f y \u2264 f x - f y - \u03b7 / 2 * gradf x ^ 2 \n    := by linarith,\n\n  have h3 := hconv x y,\n\n  have h4 :  f x - f y \u2264 - gradf x * (y - x) := by linarith,\n  have h5 : - gradf x * (y - x) = gradf x * (x - y) := by linarith,\n  rw h5 at h4,\n  have h6 : f (x - \u03b7 * gradf x) - f y \u2264 \n    gradf x * (x - y)- \u03b7 / 2 * gradf x ^ 2 := by linarith,\n\n  have h7 : gradf x * (x - y) - \u03b7 / 2 * gradf x ^ 2\n    = (1/(2*\u03b7))*((x-y)^2 - (x-y - \u03b7*gradf x)^2)\n    := by exact complete_square  (gradf x) (x-y) (\u03b7) (h\u03b7_low), \n  \n  rw h7 at h6,\n  linarith,\n    \nend \n\n-- rewrite the telescoping more favorably \nlemma prepare_to_telescope2 (x0 y: \u211d) (n : \u2115) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    f(grad_descent \u03b7 x0 gradf (n+1)) - f y \u2264 \n    (1/(2*\u03b7))*((grad_descent \u03b7 x0 gradf n-y)^2 - (grad_descent \u03b7 x0 gradf (n+1) - y)^2)\n    :=\nbegin \n\n  have h1 : grad_descent \u03b7 x0 gradf (n+1) = \n            grad_descent \u03b7 x0 gradf (n) - \u03b7*gradf(grad_descent \u03b7 x0 gradf (n))\n          := by refl,\n  rw h1,\n\n  exact prepare_to_telescope (grad_descent \u03b7 x0 gradf (n)) y \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip hconv,\n\nend \n\n-- sum_f is just the sum of function values evaluated at the points \n-- generated by the algorithm (again defined recursively)\ndef sum_f (y x0 : \u211d) (f : \u211d \u2192 \u211d) (\u03b7 : \u211d) (gradf : \u211d \u2192 \u211d): (\u2115 \u2192 \u211d)\n| 0      := 0\n| (n+1)  := sum_f(n) + f(grad_descent \u03b7 x0 gradf (n+1)) - f y\n\n\n-- the all important telescoping result \nlemma telescope (x0 y: \u211d) (n : \u2115) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    sum_f y x0 f \u03b7 gradf (n) \u2264 (1/(2*\u03b7))*((x0-y)^2 - (grad_descent \u03b7 x0 gradf n  - y)^2)\n    :=\nbegin \n  induction n with k hk,\n\n  have h1 : grad_descent \u03b7 x0 gradf 0 = x0 := by refl,\n  rw h1,\n\n  have h2 : 1 / (2 * \u03b7) * ((x0 - y) ^ 2 - (x0 - y) ^ 2) = 0 := by linarith,\n  rw h2,\n  refl,\n  \n  have h3 : sum_f y x0 f \u03b7 gradf k.succ = sum_f y x0 f \u03b7 gradf k +\n       f(grad_descent \u03b7 x0 gradf (k+1)) - f y := by refl,\n  rw h3,\n  \n  have h4 := prepare_to_telescope2 x0 y k \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip hconv, \n\n  linarith,\n  \nend \n\n-- a simple upper bound derived from telescoping \nlemma from_telescope (x0 y: \u211d) (n : \u2115) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    sum_f y x0 f \u03b7 gradf (n) \u2264 (1/(2*\u03b7))*(x0-y)^2 \n    :=\nbegin \n  have h := telescope x0 y n \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip hconv,\n\n  have h1 : (grad_descent \u03b7 x0 gradf n - y) ^ 2 \u2265 0 \n    := sq_nonneg (grad_descent \u03b7 x0 gradf n - y),\n  \n  have h2 : 1 / (2 * \u03b7) * ((x0 - y) ^ 2 - (grad_descent \u03b7 x0 gradf n - y) ^ 2)\n          =  1 / (2 * \u03b7)*(x0 - y) ^ 2 - 1 / (2 * \u03b7) *(grad_descent \u03b7 x0 gradf n - y) ^ 2\n    := mul_sub (1 / (2 * \u03b7)) ((x0 - y) ^ 2) ((grad_descent \u03b7 x0 gradf n - y) ^ 2),\n  \n  rw h2 at h,\n\n  have h3 : 1 / (2 * \u03b7) \u2265 0,\n  {\n    have h4 : 2 * \u03b7 \u2265 0 := by linarith,\n    exact one_div_nonneg.mpr h4,\n  },\n  have h5 : 1 / (2 * \u03b7) * (grad_descent \u03b7 x0 gradf n - y) ^ 2 \u2265 0\n    := mul_nonneg h3 h1,\n  linarith,\nend \n\n-- since func values are decreasing, the sum of func vals provides \n-- a bound on the last function value as follows\nlemma last_less_than_av (x0 y: \u211d) (n : \u2115) (\u03b7 L : \u211d) (f gradf : \u211d \u2192 \u211d) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    sum_f y x0 f \u03b7 gradf (n) \u2265 n*(f(grad_descent \u03b7 x0 gradf n) - f y)\n    :=\nbegin \n  induction n with k hk,\n  have h : \u21910 = (0:\u211d):= nat.cast_zero,\n  rw h,\n  rw zero_mul,\n  have h1 : sum_f y x0 f \u03b7 gradf 0 = 0 := by refl,\n  rw h1,\n  exact rfl.ge,\n\n  have h2 : sum_f y x0 f \u03b7 gradf k.succ = sum_f y x0 f \u03b7 gradf (k) + f(grad_descent \u03b7 x0 gradf (k+1)) - f y\n    := by refl,\n\n  rw h2,\n\n\n  rw nat.succ_eq_add_one,\n  have h3 : \u2191(k+1) = (k+1 : \u211d):= nat.cast_succ k,\n  rw h3,\n  have h4 : (\u2191k + 1) * (f (grad_descent \u03b7 x0 gradf (k + 1)) - f y)\n            = \u2191k*(f (grad_descent \u03b7 x0 gradf (k + 1)) - f y) \n              + f (grad_descent \u03b7 x0 gradf (k + 1)) - f y\n          := by linarith,\n  rw h4,\n\n\n  have h\u03b7_low2 : \u03b7 \u2265 0 := by linarith,\n\n  have hdesc := descent (grad_descent \u03b7 x0 gradf k) \u03b7 L f gradf hL h\u03b7_low2 h\u03b72 hlip, \n\n  have h5 : grad_descent \u03b7 x0 gradf (k+1) = \n        grad_descent \u03b7 x0 gradf k - \u03b7 * gradf (grad_descent \u03b7 x0 gradf k)\n    := by refl,\n  \n  rw \u2190 h5 at hdesc,\n\n  \n  have h6 : \u2191k * f (grad_descent \u03b7 x0 gradf (k + 1)) \u2264 \u2191k * f (grad_descent \u03b7 x0 gradf k),\n  {\n    have hupk : (0:\u211d) \u2264 (\u2191k)  := nat.cast_nonneg k,\n\n    exact mul_le_mul_of_nonneg_left hdesc hupk,\n\n  },\n\n  linarith,\n\nend \n\n-- Main convergence rate result \n-- Note that y is an arbitrary point but it is customarily taken to \n-- be one of the minimizers (assuming minimizers exist)\ntheorem grad_descent_convergence_rate (n : \u2115) (\u03b7 L : \u211d) (x0 y : \u211d) (f gradf : \u211d \u2192 \u211d)\n                        (hn : n \u2265 1)\n                        (h\u03b7_low : \u03b7 > 0) \n                        (h\u03b7_up : \u03b7 \u2264 1/L) \n                        (hL : L \u2265 0)\n                        (hconv : is_convex f gradf)\n                        (hlip : is_lip_grad f gradf L)\n                        :\n      f(grad_descent \u03b7 x0 gradf n) - f(y)\u2264 (1/(2*\u03b7*n))*(x0-y)^2\n   :=\nbegin\n  \n  have h0 := from_telescope x0 y n \u03b7 L f gradf hL h\u03b7_low h\u03b7_up hlip hconv,\n  \n  have h1 := last_less_than_av x0 y n \u03b7 L f gradf hL h\u03b7_low h\u03b7_up hlip hconv,\n\n  have h2 : \u2191n * (f (grad_descent \u03b7 x0 gradf n) - f y) \u2264 1 / (2 * \u03b7) * (x0 - y) ^ 2\n   := by linarith,\n\n  have h3 :  (f (grad_descent \u03b7 x0 gradf n) - f y) \u2264 1 / (2 * \u03b7) * (x0 - y) ^ 2 / \u2191n,\n  {\n    have h4 : \u2191n\u2265 (1:\u211d) := nat.one_le_cast.mpr hn,\n    \n    have h5 : \u2191n > (0:\u211d) := by linarith,\n\n    exact (le_div_iff' h5).mpr h2,\n  },\n   \n  have h6 : 1 / (2 * \u03b7) * (x0 - y) ^ 2 / \u2191n = (1/\u2191n)*1 / (2 * \u03b7) * (x0 - y) ^ 2\n    := by ring,\n  \n  have h7 : (1/\u2191n)*1 / (2 * \u03b7) \n            = 1 / (2 * \u03b7 * \u2191n),\n  {\n    ring,\n    exact mul_inv\u2080.symm,\n  },\n  rw h6 at h3,\n  rw h7 at h3,\n  exact h3,\n\nend   \n  \n  \n\n\n\n", "meta": {"author": "1austrartsua1", "repo": "FormalConvexOpt", "sha": "4114be9dbd8353da32dc3299405397f11d858f77", "save_path": "github-repos/lean/1austrartsua1-FormalConvexOpt", "path": "github-repos/lean/1austrartsua1-FormalConvexOpt/FormalConvexOpt-4114be9dbd8353da32dc3299405397f11d858f77/src/old_scalr_proofs/GD_const_step.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7281565697637437}}
{"text": "def List.foldl_wf [SizeOf \u03b2] (bs : List \u03b2) (init : \u03b1) (f : \u03b1 \u2192 (b : \u03b2) \u2192 sizeOf b < sizeOf bs \u2192 \u03b1) : \u03b1 :=\n  go init bs (Nat.le_refl ..)\nwhere\n  go (a : \u03b1) (cs : List \u03b2) (h : sizeOf cs \u2264 sizeOf bs) : \u03b1 :=\n    match cs with\n    | [] => a\n    | c :: cs =>\n      have : sizeOf c < sizeOf (c :: cs) := by simp_arith\n      -- TODO: simplify using linarith\n      have h\u2081 : sizeOf c < sizeOf bs := Nat.lt_of_lt_of_le this h\n      have : sizeOf cs + (sizeOf c + 1) = sizeOf c + sizeOf cs + 1 := by simp_arith\n      have : sizeOf cs \u2264 sizeOf c + sizeOf cs + 1 := by rw [\u2190 this]; apply Nat.le_add_right\n      have h\u2082 : sizeOf cs \u2264 sizeOf bs := by simp_arith at h; apply Nat.le_trans this h\n      go (f a c h\u2081) cs h\u2082\n\ntheorem List.foldl_wf_eq [SizeOf \u03b2] (bs : List \u03b2) (init : \u03b1) (f : \u03b1 \u2192 \u03b2 \u2192 \u03b1) : bs.foldl_wf init (fun a b _ => f a b) = bs.foldl f init := by\n  simp [List.foldl_wf]\n  have : (a : \u03b1) \u2192 (cs : List \u03b2) \u2192 (h : sizeOf cs \u2264 sizeOf bs) \u2192 foldl_wf.go bs (fun a b _ => f a b) a cs h = cs.foldl f a := by\n    intro a cs h\n    induction cs generalizing a with simp [List.foldl_wf.go, List.foldl]\n    | cons c cs ih => simp [ih]\n  exact this init bs (Nat.le_refl ..)\n\ninductive Expr where\n  | app (f : String) (args : List Expr)\n  | var (n : String)\n\n-- TODO: `WF.lean` should replace `List.foldl` with `List.foldl_wf`, and then apply `List.foldl_wf_eq` when proving equation theorems.\n@[simp] def Expr.numVars : Expr \u2192 Nat\n  | app f args => args.foldl_wf 0 fun sum arg h =>\n    -- TODO: linarith should prove the following proposition\n    -- TODO: decreasing_tactic should invoke `linarith`\n    have : sizeOf arg < 1 + sizeOf f + sizeOf args := Nat.lt_of_lt_of_le h (Nat.le_add_left ..)\n    sum + numVars arg\n  | var _ => 1\n\n/-\n  TODO: we should have a new attribute for registering theorems such as `List.foldl_wf_eq` and `List.map_foldl_wf_eq`\n  Here is the steps missing in the `WF` module.\n  1- Replace functions such as `List.foldl` with their `_wf` version. Note that the new hypothesis is unused.\n  2- Use the current `WF` implementation. The `decreasing_tactic` must invoke `linarith` to be able to discharge the goals.\n  3- When generating equation lemmas, we first prove that the defined function is equal to the RHS containing the `_wf` function,\n     and then apply `_wf_eq` simp theorem to simplify.\n-/\n\n-- Example for step 3\ntheorem Expr.numVars_app_eq (f : String) (args : List Expr) : (Expr.app f args).numVars = args.foldl (fun sum arg => sum + arg.numVars) 0 := by\n  simp [numVars, List.foldl_wf_eq]\n\n#eval Expr.app \"f\" [Expr.var \"a\", Expr.app \"g\" [Expr.var \"b\", Expr.var \"c\"]] |>.numVars\n\ndef List.map_wf [SizeOf \u03b1] (as : List \u03b1) (f : (a : \u03b1) \u2192 sizeOf a < sizeOf as \u2192 \u03b2) : List \u03b2 :=\n  go as (Nat.le_refl ..)\nwhere\n  go (cs : List \u03b1) (h : sizeOf cs \u2264 sizeOf as) : List \u03b2 :=\n    match cs with\n    | [] => []\n    | c :: cs =>\n      have : sizeOf c < sizeOf (c :: cs) := by simp_arith\n      -- TODO: simplify using linarith\n      have h\u2081 : sizeOf c < sizeOf as := Nat.lt_of_lt_of_le this h\n      have : sizeOf cs + (sizeOf c + 1) = sizeOf c + sizeOf cs + 1 := by simp_arith\n      have : sizeOf cs \u2264 sizeOf c + sizeOf cs + 1 := by rw [\u2190 this]; apply Nat.le_add_right\n      have h\u2082 : sizeOf cs \u2264 sizeOf as := by simp_arith at h; apply Nat.le_trans this h\n      f c h\u2081 :: go cs h\u2082\n\ntheorem List.map_wf_eq [SizeOf \u03b1] (as : List \u03b1) (f : \u03b1 \u2192 \u03b2) : as.map_wf (fun a _ => f a) = as.map f := by\n  simp [List.map_wf]\n  have : (cs : List \u03b1) \u2192 (h : sizeOf cs \u2264 sizeOf as) \u2192 map_wf.go as (fun a _ => f a) cs h = cs.map f := by\n    intro cs h\n    induction cs with simp [List.map_wf.go, List.map]\n    | cons c cs ih => simp [ih]\n  exact this as (Nat.le_refl ..)\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/combinatorsAndWF.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7281565631516197}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport order.lattice\n\n/-!\n# `max` and `min`\n\nThis file proves basic properties about maxima and minima on a `linear_order`.\n\n## Tags\n\nmin, max\n-/\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\n\nattribute [simp] max_eq_left max_eq_right min_eq_left min_eq_right\n\nsection\nvariables [linear_order \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a b c d : \u03b1}\n\n-- translate from lattices to linear orders (sup \u2192 max, inf \u2192 min)\n@[simp] lemma le_min_iff : c \u2264 min a b \u2194 c \u2264 a \u2227 c \u2264 b := le_inf_iff\n@[simp] lemma le_max_iff : a \u2264 max b c \u2194 a \u2264 b \u2228 a \u2264 c := le_sup_iff\n@[simp] lemma min_le_iff : min a b \u2264 c \u2194 a \u2264 c \u2228 b \u2264 c := inf_le_iff\n@[simp] lemma max_le_iff : max a b \u2264 c \u2194 a \u2264 c \u2227 b \u2264 c := sup_le_iff\n@[simp] lemma lt_min_iff : a < min b c \u2194 a < b \u2227 a < c := lt_inf_iff\n@[simp] lemma lt_max_iff : a < max b c \u2194 a < b \u2228 a < c := lt_sup_iff\n@[simp] lemma min_lt_iff : min a b < c \u2194 a < c \u2228 b < c := inf_lt_iff\n@[simp] lemma max_lt_iff : max a b < c \u2194 a < c \u2227 b < c := sup_lt_iff\nlemma max_le_max : a \u2264 c \u2192 b \u2264 d \u2192 max a b \u2264 max c d := sup_le_sup\nlemma min_le_min : a \u2264 c \u2192 b \u2264 d \u2192 min a b \u2264 min c d := inf_le_inf\nlemma le_max_of_le_left : a \u2264 b \u2192 a \u2264 max b c := le_sup_of_le_left\nlemma le_max_of_le_right : a \u2264 c \u2192 a \u2264 max b c := le_sup_of_le_right\nlemma lt_max_of_lt_left (h : a < b) : a < max b c := h.trans_le (le_max_left b c)\nlemma lt_max_of_lt_right (h : a < c) : a < max b c := h.trans_le (le_max_right b c)\nlemma min_le_of_left_le : a \u2264 c \u2192 min a b \u2264 c := inf_le_of_left_le\nlemma min_le_of_right_le : b \u2264 c \u2192 min a b \u2264 c := inf_le_of_right_le\nlemma min_lt_of_left_lt (h : a < c) : min a b < c := (min_le_left a b).trans_lt h\nlemma min_lt_of_right_lt (h : b < c) : min a b < c := (min_le_right a b).trans_lt h\nlemma max_min_distrib_left : max a (min b c) = min (max a b) (max a c) := sup_inf_left\nlemma max_min_distrib_right : max (min a b) c = min (max a c) (max b c) := sup_inf_right\nlemma min_max_distrib_left : min a (max b c) = max (min a b) (min a c) := inf_sup_left\nlemma min_max_distrib_right : min (max a b) c = max (min a c) (min b c) := inf_sup_right\nlemma min_le_max : min a b \u2264 max a b := le_trans (min_le_left a b) (le_max_left a b)\n\n@[simp] lemma min_eq_left_iff : min a b = a \u2194 a \u2264 b := inf_eq_left\n@[simp] lemma min_eq_right_iff : min a b = b \u2194 b \u2264 a := inf_eq_right\n@[simp] lemma max_eq_left_iff : max a b = a \u2194 b \u2264 a := sup_eq_left\n@[simp] lemma max_eq_right_iff : max a b = b \u2194 a \u2264 b := sup_eq_right\n\n/-- For elements `a` and `b` of a linear order, either `min a b = a` and `a \u2264 b`,\n    or `min a b = b` and `b < a`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma min_cases (a b : \u03b1) : min a b = a \u2227 a \u2264 b \u2228 min a b = b \u2227 b < a :=\nbegin\n  by_cases a \u2264 b,\n  { left,\n    exact \u27e8min_eq_left h, h\u27e9 },\n  { right,\n    exact \u27e8min_eq_right (le_of_lt (not_le.mp h)), (not_le.mp h)\u27e9 }\nend\n\n/-- For elements `a` and `b` of a linear order, either `max a b = a` and `b \u2264 a`,\n    or `max a b = b` and `a < b`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma max_cases (a b : \u03b1) : max a b = a \u2227 b \u2264 a \u2228 max a b = b \u2227 a < b := @min_cases \u03b1\u1d52\u1d48 _ a b\n\nlemma min_eq_iff : min a b = c \u2194 a = c \u2227 a \u2264 b \u2228 b = c \u2227 b \u2264 a :=\nbegin\n  split,\n  { intro h,\n    refine or.imp (\u03bb h', _) (\u03bb h', _) (le_total a b);\n    exact \u27e8by simpa [h'] using h, h'\u27e9 },\n  { rintro (\u27e8rfl, h\u27e9|\u27e8rfl, h\u27e9);\n    simp [h] }\nend\n\nlemma max_eq_iff : max a b = c \u2194 a = c \u2227 b \u2264 a \u2228 b = c \u2227 a \u2264 b := @min_eq_iff \u03b1\u1d52\u1d48 _ a b c\n\nlemma min_lt_min_left_iff : min a c < min b c \u2194 a < b \u2227 a < c :=\nby { simp_rw [lt_min_iff, min_lt_iff, or_iff_left (lt_irrefl _)],\n  exact and_congr_left (\u03bb h, or_iff_left_of_imp h.trans) }\n\nlemma min_lt_min_right_iff : min a b < min a c \u2194 b < c \u2227 b < a :=\nby simp_rw [min_comm a, min_lt_min_left_iff]\n\nlemma max_lt_max_left_iff : max a c < max b c \u2194 a < b \u2227 c < b := @min_lt_min_left_iff \u03b1\u1d52\u1d48 _ _ _ _\nlemma max_lt_max_right_iff : max a b < max a c \u2194 b < c \u2227 a < c := @min_lt_min_right_iff \u03b1\u1d52\u1d48 _ _ _ _\n\n/-- An instance asserting that `max a a = a` -/\ninstance max_idem : is_idempotent \u03b1 max := by apply_instance -- short-circuit type class inference\n\n/-- An instance asserting that `min a a = a` -/\ninstance min_idem : is_idempotent \u03b1 min := by apply_instance -- short-circuit type class inference\n\nlemma min_lt_max : min a b < max a b \u2194 a \u2260 b := inf_lt_sup\n\nlemma max_lt_max (h\u2081 : a < c) (h\u2082 : b < d) : max a b < max c d :=\nby simp [lt_max_iff, max_lt_iff, *]\n\nlemma min_lt_min (h\u2081 : a < c) (h\u2082 : b < d) : min a b < min c d := @max_lt_max \u03b1\u1d52\u1d48 _ _ _ _ _ h\u2081 h\u2082\n\ntheorem min_right_comm (a b c : \u03b1) : min (min a b) c = min (min a c) b :=\nright_comm min min_comm min_assoc a b c\n\ntheorem max.left_comm (a b c : \u03b1) : max a (max b c) = max b (max a c) :=\nleft_comm max max_comm max_assoc a b c\n\ntheorem max.right_comm (a b c : \u03b1) : max (max a b) c = max (max a c) b :=\nright_comm max max_comm max_assoc a b c\n\nlemma monotone_on.map_max (hf : monotone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (max a b) = max (f a) (f b) :=\nby cases le_total a b; simp only [max_eq_right, max_eq_left, hf ha hb, hf hb ha, h]\n\nlemma monotone_on.map_min (hf : monotone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (min a b) = min (f a) (f b) :=\nhf.dual.map_max ha hb\n\nlemma antitone_on.map_max (hf : antitone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (max a b) = min (f a) (f b) :=\nhf.dual_right.map_max ha hb\n\nlemma antitone_on.map_min (hf : antitone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (min a b) = max (f a) (f b) :=\nhf.dual.map_max ha hb\n\nlemma monotone.map_max (hf : monotone f) : f (max a b) = max (f a) (f b) :=\nby cases le_total a b; simp [h, hf h]\n\nlemma monotone.map_min (hf : monotone f) : f (min a b) = min (f a) (f b) :=\nhf.dual.map_max\n\nlemma antitone.map_max (hf : antitone f) : f (max a b) = min (f a) (f b) :=\nby cases le_total a b; simp [h, hf h]\n\nlemma antitone.map_min (hf : antitone f) : f (min a b) = max (f a) (f b) :=\nhf.dual.map_max\n\nlemma min_rec {p : \u03b1 \u2192 Prop} {x y : \u03b1} (hx : x \u2264 y \u2192 p x) (hy : y \u2264 x \u2192 p y) : p (min x y) :=\n(le_total x y).rec (\u03bb h, (min_eq_left h).symm.subst (hx h))\n  (\u03bb h, (min_eq_right h).symm.subst (hy h))\n\nlemma max_rec {p : \u03b1 \u2192 Prop} {x y : \u03b1} (hx : y \u2264 x \u2192 p x) (hy : x \u2264 y \u2192 p y) : p (max x y) :=\n@min_rec \u03b1\u1d52\u1d48 _ _ _ _ hx hy\n\nlemma min_rec' (p : \u03b1 \u2192 Prop) {x y : \u03b1} (hx : p x) (hy : p y) : p (min x y) :=\nmin_rec (\u03bb _, hx) (\u03bb _, hy)\n\nlemma max_rec' (p : \u03b1 \u2192 Prop) {x y : \u03b1} (hx : p x) (hy : p y) : p (max x y) :=\nmax_rec (\u03bb _, hx) (\u03bb _, hy)\n\ntheorem min_choice (a b : \u03b1) : min a b = a \u2228 min a b = b :=\nby cases le_total a b; simp *\n\ntheorem max_choice (a b : \u03b1) : max a b = a \u2228 max a b = b :=\n@min_choice \u03b1\u1d52\u1d48 _ a b\n\nlemma le_of_max_le_left {a b c : \u03b1} (h : max a b \u2264 c) : a \u2264 c :=\nle_trans (le_max_left _ _) h\n\nlemma le_of_max_le_right {a b c : \u03b1} (h : max a b \u2264 c) : b \u2264 c :=\nle_trans (le_max_right _ _) h\n\nlemma max_commutative : commutative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_comm\n\nlemma max_associative : associative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_assoc\n\nlemma max_left_commutative : left_commutative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_left_comm\n\nlemma min_commutative : commutative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_comm\n\nlemma min_associative : associative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_assoc\n\nlemma min_left_commutative : left_commutative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_left_comm\n\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/min_max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339716830606, "lm_q2_score": 0.8670357735451835, "lm_q1q2_score": 0.7280793937103917}}
{"text": "-- Interseccion_con_su_union.lean\n-- Intersecci\u00f3n con su uni\u00f3n\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 26 de abril de 2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    s \u2229 (s \u222a t) = s\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    dsimp at h,\n    exact h.1, },\n  { intro xs,\n    dsimp,\n    split,\n    { exact xs, },\n    { left,\n      exact xs, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    exact h.1, },\n  { intro xs,\n    split,\n    { exact xs, },\n    { left,\n      exact xs, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    exact h.1, },\n  { intro xs,\n    split,\n    { exact xs, },\n    { exact (or.inl xs), }},\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext,\n  exact \u27e8\u03bb h, h.1,\n         \u03bb xs, \u27e8xs, or.inl xs\u27e9\u27e9,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext,\n  exact \u27e8and.left,\n         \u03bb xs, \u27e8xs, or.inl xs\u27e9\u27e9,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { rintros \u27e8xs, _\u27e9,\n    exact xs },\n  { intro xs,\n    use xs,\n    left,\n    exact xs },\nend\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  apply subset_antisymm,\n  { rintros x \u27e8hxs,-\u27e9,\n    exact hxs, },\n  { intros x hxs,\n    exact \u27e8hxs, or.inl hxs\u27e9, },\nend\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\n-- by suggest\ninf_sup_self\n\n-- 9\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\n-- by hint\nby finish\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Interseccion_con_su_union.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7280793925640358}}
{"text": "import data.finset\nimport data.fintype.basic\nimport data.set.finite\nimport tactic.derive_fintype\n\n\nsection intro\n\nvariable {\u03b1 : Type*}\n-- \u041a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u044c \u0442\u0438\u043f\u0430 \u0438\u043b\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 mathlib \u0442\u0440\u0435\u043c\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438: `A : finset \u03b1`, `fintype A` \u0438 `finite A`\n\n-- 1. finset - \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\n-- `finset` = `multiset` + `nodup`\n-- `multiset` = \u043a\u043b\u0430\u0441\u0441\u044b \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 `list` \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \"a - \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 b\"\n-- \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435/\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435/...), \u043d\u0443\u0436\u0435\u043d \u0438\u043d\u0441\u0442\u0430\u043d\u0441 `decidable_eq \u03b1`: \u043d\u0443\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043c\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b (\u0447\u0442\u043e\u0431\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u043d\u0430\u0442\u044c `card`)\n\nvariable (A : finset \u03b1)\n\n#check A.card\n#reduce ({0,1,2,3} : finset \u2115).card\n#check @finset.card_insert_of_mem\n\n\n-- 2. fintype \u03b1 - \u043a\u043b\u0430\u0441\u0441, \u0433\u043e\u0432\u043e\u0440\u044f\u0449\u0438\u0439 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u03b1 - \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0442\u0438\u043f\n-- fintype \u03b1 = (elems [] : finset \u03b1) (complete : \u2200 x : \u03b1, x \u2208 elems)\n-- \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c @[derive fintype], \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 `inductive`\n-- https://github.com/leanprover-community/mathlib/pull/3772\n\nvariable [fintype \u03b1]\n\nexample : fintype bool := by show_term {apply_instance}\nexample : fintype (fin 10) := by show_term {apply_instance}\n\n#check @finset.univ\n\n@[derive fintype]\ninductive test (\u03b1 : Type) [fintype \u03b1] : Type\n| c1 : bool \u2192 test\n| c2 : (fin 2) \u2192 (fin 3) \u2192 test\n| c3 : \u03b1 \u00d7 \u03b1 \u2192 test\n\n-- 3. finite B - \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 B\n-- def finite (s : set \u03b1) : Prop := nonempty (fintype s)\n-- `nonempty (fintype s)` - Prop-\u0432\u0435\u0440\u0441\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 `fintype s`\n-- `fintype s` - \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e `fintype {x : \u03b1 // x \u2208 s}` \u0438\u043b\u0438 `fintype (subtype s)` - \u043f\u043e\u0434\u0442\u0438\u043f `\u03b1` \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u043f\u0430\u0440 `\u27e8x, h : x \u2208 s\u27e9`\n-- \u0423\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432 API `finset` \u043d\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438, \u0430 \u0432 `set` \u0435\u0441\u0442\u044c\n\nopen set\n\nvariables (\u03b2 : Type) (B : set \u03b2) (hB : finite B)\n\n#check @finite.of_fintype\nend intro \n\n-- \u0414\u043e\u043a\u0430\u0436\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u043c\u043c \u043f\u0440\u043e `finset`\nnamespace finset\n\nvariables {\u03b1 : Type} {A B : finset \u03b1} [decidable_eq \u03b1]\n\nlemma card_erase_of_mem' {x} (h : x \u2208 A) : (A.erase x).card + 1 = A.card :=\nbegin\n  sorry,\nend\n\nend finset", "meta": {"author": "VArtem", "repo": "lean-itmo", "sha": "dc44cd06f9f5b984d051831b3aaa7364e64c2dc4", "save_path": "github-repos/lean/VArtem-lean-itmo", "path": "github-repos/lean/VArtem-lean-itmo/lean-itmo-dc44cd06f9f5b984d051831b3aaa7364e64c2dc4/src/week05/e00_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7280793827238661}}
{"text": "/-\nCopyright (c) 2023 Mark Andrew Gerads. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mark Andrew Gerads, Junyan Xu, Eric Wieser\n\n! This file was ported from Lean 3 source module data.nat.hyperoperation\n! leanprover-community/mathlib commit fac369018417f980cec5fcdafc766a69f88d8cfe\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Tactic.Ring\nimport Mathbin.Data.Nat.Parity\n\n/-!\n# Hyperoperation sequence\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the Hyperoperation sequence.\n`hyperoperation 0 m k = k + 1`\n`hyperoperation 1 m k = m + k`\n`hyperoperation 2 m k = m * k`\n`hyperoperation 3 m k = m ^ k`\n`hyperoperation (n + 3) m 0 = 1`\n`hyperoperation (n + 1) m (k + 1) = hyperoperation n m (hyperoperation (n + 1) m k)`\n\n## References\n\n* <https://en.wikipedia.org/wiki/Hyperoperation>\n\n## Tags\n\nhyperoperation\n-/\n\n\n#print hyperoperation /-\n/-- Implementation of the hyperoperation sequence\nwhere `hyperoperation n m k` is the `n`th hyperoperation between `m` and `k`.\n-/\ndef hyperoperation : \u2115 \u2192 \u2115 \u2192 \u2115 \u2192 \u2115\n  | 0, _, k => k + 1\n  | 1, m, 0 => m\n  | 2, _, 0 => 0\n  | n + 3, _, 0 => 1\n  | n + 1, m, k + 1 => hyperoperation n m (hyperoperation (n + 1) m k)\n#align hyperoperation hyperoperation\n-/\n\n#print hyperoperation_zero /-\n-- Basic hyperoperation lemmas\n@[simp]\ntheorem hyperoperation_zero (m : \u2115) : hyperoperation 0 m = Nat.succ :=\n  funext fun k => by rw [hyperoperation, Nat.succ_eq_add_one]\n#align hyperoperation_zero hyperoperation_zero\n-/\n\n#print hyperoperation_ge_three_eq_one /-\ntheorem hyperoperation_ge_three_eq_one (n m : \u2115) : hyperoperation (n + 3) m 0 = 1 := by\n  rw [hyperoperation]\n#align hyperoperation_ge_three_eq_one hyperoperation_ge_three_eq_one\n-/\n\n#print hyperoperation_recursion /-\ntheorem hyperoperation_recursion (n m k : \u2115) :\n    hyperoperation (n + 1) m (k + 1) = hyperoperation n m (hyperoperation (n + 1) m k) := by\n  obtain _ | _ | _ := n <;> rw [hyperoperation]\n#align hyperoperation_recursion hyperoperation_recursion\n-/\n\n#print hyperoperation_one /-\n-- Interesting hyperoperation lemmas\n@[simp]\ntheorem hyperoperation_one : hyperoperation 1 = (\u00b7 + \u00b7) :=\n  by\n  ext (m k)\n  induction' k with bn bih\n  \u00b7 rw [Nat.add_zero m, hyperoperation]\n  \u00b7 rw [hyperoperation_recursion, bih, hyperoperation_zero]\n    exact Nat.add_assoc m bn 1\n#align hyperoperation_one hyperoperation_one\n-/\n\n#print hyperoperation_two /-\n@[simp]\ntheorem hyperoperation_two : hyperoperation 2 = (\u00b7 * \u00b7) :=\n  by\n  ext (m k)\n  induction' k with bn bih\n  \u00b7 rw [hyperoperation]\n    exact (Nat.mul_zero m).symm\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_one, bih]\n    ring\n#align hyperoperation_two hyperoperation_two\n-/\n\n#print hyperoperation_three /-\n@[simp]\ntheorem hyperoperation_three : hyperoperation 3 = (\u00b7 ^ \u00b7) :=\n  by\n  ext (m k)\n  induction' k with bn bih\n  \u00b7 rw [hyperoperation_ge_three_eq_one]\n    exact (pow_zero m).symm\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_two, bih]\n    exact (pow_succ m bn).symm\n#align hyperoperation_three hyperoperation_three\n-/\n\n#print hyperoperation_ge_two_eq_self /-\ntheorem hyperoperation_ge_two_eq_self (n m : \u2115) : hyperoperation (n + 2) m 1 = m :=\n  by\n  induction' n with nn nih\n  \u00b7 rw [hyperoperation_two]\n    ring\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_ge_three_eq_one, nih]\n#align hyperoperation_ge_two_eq_self hyperoperation_ge_two_eq_self\n-/\n\n#print hyperoperation_two_two_eq_four /-\ntheorem hyperoperation_two_two_eq_four (n : \u2115) : hyperoperation (n + 1) 2 2 = 4 :=\n  by\n  induction' n with nn nih\n  \u00b7 rw [hyperoperation_one]\n  \u00b7 rw [hyperoperation_recursion, hyperoperation_ge_two_eq_self, nih]\n#align hyperoperation_two_two_eq_four hyperoperation_two_two_eq_four\n-/\n\n#print hyperoperation_ge_three_one /-\ntheorem hyperoperation_ge_three_one (n : \u2115) : \u2200 k : \u2115, hyperoperation (n + 3) 1 k = 1 :=\n  by\n  induction' n with nn nih\n  \u00b7 intro k\n    rw [hyperoperation_three, one_pow]\n  \u00b7 intro k\n    cases k\n    \u00b7 rw [hyperoperation_ge_three_eq_one]\n    \u00b7 rw [hyperoperation_recursion, nih]\n#align hyperoperation_ge_three_one hyperoperation_ge_three_one\n-/\n\n/- warning: hyperoperation_ge_four_zero -> hyperoperation_ge_four_zero is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (k : Nat), Eq.{1} Nat (hyperoperation (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 4 (OfNat.mk.{0} Nat 4 (bit0.{0} Nat Nat.hasAdd (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne)))))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) k) (ite.{1} Nat (Even.{0} Nat Nat.hasAdd k) (Nat.Even.decidablePred k) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))))\nbut is expected to have type\n  forall (n : Nat) (k : Nat), Eq.{1} Nat (hyperoperation (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 4 (instOfNatNat 4))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) k) (ite.{1} Nat (Even.{0} Nat instAddNat k) (Nat.instDecidablePredNatEvenInstAddNat k) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))\nCase conversion may be inaccurate. Consider using '#align hyperoperation_ge_four_zero hyperoperation_ge_four_zero\u2093'. -/\ntheorem hyperoperation_ge_four_zero (n k : \u2115) :\n    hyperoperation (n + 4) 0 k = if Even k then 1 else 0 :=\n  by\n  induction' k with kk kih\n  \u00b7 rw [hyperoperation_ge_three_eq_one]\n    simp only [even_zero, if_true]\n  \u00b7 rw [hyperoperation_recursion]\n    rw [kih]\n    simp_rw [Nat.even_add_one]\n    split_ifs\n    \u00b7 exact hyperoperation_ge_two_eq_self (n + 1) 0\n    \u00b7 exact hyperoperation_ge_three_eq_one n 0\n#align hyperoperation_ge_four_zero hyperoperation_ge_four_zero\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Hyperoperation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7280793700370349}}
{"text": "import tactic.ring\nimport data.real.basic\n\nexample (x y : \u2115) : x + y = y + x := by ring\nexample (x y : \u2115) : x + y + y = 2 * y + x := by ring\nexample (x y : \u2115) : x + id y = y + id x := by ring!\nexample {\u03b1} [comm_ring \u03b1] (x y : \u03b1) : x + y + y - x = 2 * y := by ring\nexample (x y : \u211a) : x / 2 + x / 2 = x := by ring\nexample (x y : \u211a) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring\nexample (x y : \u211d) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring\nexample {\u03b1} [comm_semiring \u03b1] (x : \u03b1) : (x + 1) ^ 6 = (1 + x) ^ 6 := by try_for 15000 {ring}\nexample (n : \u2115) : (n / 2) + (n / 2) = 2 * (n / 2) := by ring\nexample {\u03b1} [field \u03b1] [char_zero \u03b1] (a : \u03b1) : a / 2 = a / 2 := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  a * (-c / b) * (-c / b) + -c + c = a * (c / b * (c / b)) := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring\nexample (x : \u211a) : x ^ (2 + 2) = x^4 := by ring_nf -- TODO: ring should work?\nexample {\u03b1} [comm_ring \u03b1] (x : \u03b1) : x ^ 2 = x * x := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring\nexample {\u03b1} [linear_ordered_field \u03b1] (a b c : \u03b1) :\n  b ^ 2 - 4 * a * c = 4 * a * 0 + b * b - 4 * a * c := by ring\nexample {\u03b1} [comm_semiring \u03b1] (x y z : \u03b1) (n : \u2115) :\n  (x + y) * (z * (y * y) + (x * x ^ n + (1 + \u2191n) * x ^ n * y)) =\n    x * (x * x ^ n) + ((2 + \u2191n) * (x * x ^ n) * y + (x * z + (z * y + (1 + \u2191n) * x ^ n)) * (y * y)) := by ring\nexample {\u03b1} [comm_ring \u03b1] (a b c d e : \u03b1) :\n  (-(a * b) + c + d) * e = (c + (d + -a * b)) * e := by ring\nexample (a n s: \u2115) : a * (n - s) = (n - s) * a := by ring\n\nexample (x y z : \u211a) (hx : x \u2260 0) (hy : y \u2260 0) (hz : z \u2260 0) :\n  x / (y / z) + y \u207b\u00b9 + 1 / (y * -x) = -1/ (x * y) + (x * z + 1) / y :=\nbegin\n  field_simp,\n  ring\nend\n\nexample (a b c d x y : \u211a) (hx : x \u2260 0) (hy : y \u2260 0) :\n  a + b / x - c / x^2 + d / x^3 = a + x\u207b\u00b9 * (y * b / y + (d / x - c) / x) :=\nbegin\n  field_simp,\n  ring\nend\n\nexample : (876544 : \u2124) * -1 + (1000000 - 123456) = 0 := by ring\n\nexample (x y : \u211d) (hx : x \u2260 0) (hy : y \u2260 0) :\n  2 * x ^ 3 * 2 / (24 * x) = x ^ 2 / 6 :=\nbegin\n  field_simp,\n  ring\nend\n\n-- this proof style is not recommended practice\nexample (A B : \u2115) (H : B * A = 2) : A * B = 2 := by {ring_nf, exact H}\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/test/ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.7279483600287854}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.ordered_group\nimport Mathlib.data.set.intervals.basic\nimport Mathlib.PostPort\n\nuniverses u l u_1 \n\nnamespace Mathlib\n\n/-- An `ordered_semiring \u03b1` is a semiring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\nclass ordered_semiring (\u03b1 : Type u) \nextends ordered_cancel_add_comm_monoid \u03b1, semiring \u03b1\nwhere\n  zero_le_one : 0 \u2264 1\n  mul_lt_mul_of_pos_left : \u2200 (a b c : \u03b1), a < b \u2192 0 < c \u2192 c * a < c * b\n  mul_lt_mul_of_pos_right : \u2200 (a b c : \u03b1), a < b \u2192 0 < c \u2192 a * c < b * c\n\ntheorem zero_le_one {\u03b1 : Type u} [ordered_semiring \u03b1] : 0 \u2264 1 :=\n  ordered_semiring.zero_le_one\n\ntheorem zero_le_two {\u03b1 : Type u} [ordered_semiring \u03b1] : 0 \u2264 bit0 1 :=\n  add_nonneg zero_le_one zero_le_one\n\ntheorem zero_lt_one {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] : 0 < 1 :=\n  lt_of_le_of_ne zero_le_one zero_ne_one\n\ntheorem zero_lt_two {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] : 0 < bit0 1 :=\n  add_pos zero_lt_one zero_lt_one\n\ntheorem two_ne_zero {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] : bit0 1 \u2260 0 :=\n  ne.symm (ne_of_lt zero_lt_two)\n\ntheorem one_lt_two {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] : 1 < bit0 1 :=\n  trans_rel_left gt (trans_rel_right gt one_add_one_eq_two (add_lt_add_left zero_lt_one 1)) (add_zero 1)\n\ntheorem one_le_two {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] : 1 \u2264 bit0 1 :=\n  has_lt.lt.le one_lt_two\n\ntheorem zero_lt_three {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] : 0 < bit1 1 :=\n  add_pos zero_lt_two zero_lt_one\n\ntheorem zero_lt_four {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] : 0 < bit0 (bit0 1) :=\n  add_pos zero_lt_two zero_lt_two\n\ntheorem mul_lt_mul_of_pos_left {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a < b) (h\u2082 : 0 < c) : c * a < c * b :=\n  ordered_semiring.mul_lt_mul_of_pos_left a b c h\u2081 h\u2082\n\ntheorem mul_lt_mul_of_pos_right {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a < b) (h\u2082 : 0 < c) : a * c < b * c :=\n  ordered_semiring.mul_lt_mul_of_pos_right a b c h\u2081 h\u2082\n\ntheorem mul_le_mul_of_nonneg_left {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c * a \u2264 c * b := sorry\n\ntheorem mul_le_mul_of_nonneg_right {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : a * c \u2264 b * c := sorry\n\n-- TODO: there are four variations, depending on which variables we assume to be nonneg\n\ntheorem mul_le_mul {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hac : a \u2264 c) (hbd : b \u2264 d) (nn_b : 0 \u2264 b) (nn_c : 0 \u2264 c) : a * b \u2264 c * d :=\n  le_trans (mul_le_mul_of_nonneg_right hac nn_b) (mul_le_mul_of_nonneg_left hbd nn_c)\n\ntheorem mul_nonneg {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a * b :=\n  (fun (h : 0 * b \u2264 a * b) => eq.mp (Eq._oldrec (Eq.refl (0 * b \u2264 a * b)) (zero_mul b)) h)\n    (mul_le_mul_of_nonneg_right ha hb)\n\ntheorem mul_nonpos_of_nonneg_of_nonpos {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 \u2264 a) (hb : b \u2264 0) : a * b \u2264 0 :=\n  (fun (h : a * b \u2264 a * 0) => eq.mp (Eq._oldrec (Eq.refl (a * b \u2264 a * 0)) (mul_zero a)) h)\n    (mul_le_mul_of_nonneg_left hb ha)\n\ntheorem mul_nonpos_of_nonpos_of_nonneg {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : a \u2264 0) (hb : 0 \u2264 b) : a * b \u2264 0 :=\n  (fun (h : a * b \u2264 0 * b) => eq.mp (Eq._oldrec (Eq.refl (a * b \u2264 0 * b)) (zero_mul b)) h)\n    (mul_le_mul_of_nonneg_right ha hb)\n\ntheorem mul_lt_mul {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hac : a < c) (hbd : b \u2264 d) (pos_b : 0 < b) (nn_c : 0 \u2264 c) : a * b < c * d :=\n  lt_of_lt_of_le (mul_lt_mul_of_pos_right hac pos_b) (mul_le_mul_of_nonneg_left hbd nn_c)\n\ntheorem mul_lt_mul' {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (h1 : a \u2264 c) (h2 : b < d) (h3 : 0 \u2264 b) (h4 : 0 < c) : a * b < c * d :=\n  lt_of_le_of_lt (mul_le_mul_of_nonneg_right h1 h3) (mul_lt_mul_of_pos_left h2 h4)\n\ntheorem mul_pos {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=\n  (fun (h : 0 * b < a * b) => eq.mp (Eq._oldrec (Eq.refl (0 * b < a * b)) (zero_mul b)) h) (mul_lt_mul_of_pos_right ha hb)\n\ntheorem mul_neg_of_pos_of_neg {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : b < 0) : a * b < 0 :=\n  (fun (h : a * b < a * 0) => eq.mp (Eq._oldrec (Eq.refl (a * b < a * 0)) (mul_zero a)) h) (mul_lt_mul_of_pos_left hb ha)\n\ntheorem mul_neg_of_neg_of_pos {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : 0 < b) : a * b < 0 :=\n  (fun (h : a * b < 0 * b) => eq.mp (Eq._oldrec (Eq.refl (a * b < 0 * b)) (zero_mul b)) h) (mul_lt_mul_of_pos_right ha hb)\n\ntheorem mul_self_lt_mul_self {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h1 : 0 \u2264 a) (h2 : a < b) : a * a < b * b :=\n  mul_lt_mul' (has_lt.lt.le h2) h2 h1 (has_le.le.trans_lt h1 h2)\n\ntheorem strict_mono_incr_on_mul_self {\u03b1 : Type u} [ordered_semiring \u03b1] : strict_mono_incr_on (fun (x : \u03b1) => x * x) (set.Ici 0) :=\n  fun (x : \u03b1) (hx : x \u2208 set.Ici 0) (y : \u03b1) (hy : y \u2208 set.Ici 0) (hxy : x < y) => mul_self_lt_mul_self hx hxy\n\ntheorem mul_self_le_mul_self {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h1 : 0 \u2264 a) (h2 : a \u2264 b) : a * a \u2264 b * b :=\n  mul_le_mul h2 h2 h1 (has_le.le.trans h1 h2)\n\ntheorem mul_lt_mul'' {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (h1 : a < c) (h2 : b < d) (h3 : 0 \u2264 a) (h4 : 0 \u2264 b) : a * b < c * d := sorry\n\ntheorem le_mul_of_one_le_right {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 \u2264 b) (h : 1 \u2264 a) : b \u2264 b * a :=\n  (fun (this : b * 1 \u2264 b * a) => eq.mp (Eq._oldrec (Eq.refl (b * 1 \u2264 b * a)) (mul_one b)) this)\n    (mul_le_mul_of_nonneg_left h hb)\n\ntheorem le_mul_of_one_le_left {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 \u2264 b) (h : 1 \u2264 a) : b \u2264 a * b :=\n  (fun (this : 1 * b \u2264 a * b) => eq.mp (Eq._oldrec (Eq.refl (1 * b \u2264 a * b)) (one_mul b)) this)\n    (mul_le_mul_of_nonneg_right h hb)\n\ntheorem bit1_pos {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} [nontrivial \u03b1] (h : 0 \u2264 a) : 0 < bit1 a :=\n  lt_add_of_le_of_pos (add_nonneg h h) zero_lt_one\n\ntheorem lt_add_one {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] (a : \u03b1) : a < a + 1 :=\n  lt_add_of_le_of_pos le_rfl zero_lt_one\n\ntheorem lt_one_add {\u03b1 : Type u} [ordered_semiring \u03b1] [nontrivial \u03b1] (a : \u03b1) : a < 1 + a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a < 1 + a)) (add_comm 1 a))) (lt_add_one a)\n\ntheorem bit1_pos' {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} (h : 0 < a) : 0 < bit1 a :=\n  bit1_pos (has_lt.lt.le h)\n\ntheorem one_lt_mul {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\n  one_mul 1 \u25b8 mul_lt_mul' ha hb zero_le_one (has_lt.lt.trans_le zero_lt_one ha)\n\ntheorem mul_le_one {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : a \u2264 1) (hb' : 0 \u2264 b) (hb : b \u2264 1) : a * b \u2264 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b \u2264 1)) (Eq.symm (one_mul 1)))) (mul_le_mul ha hb hb' zero_le_one)\n\ntheorem one_lt_mul_of_le_of_lt {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\n  trans_rel_right Less (eq.mpr (id (Eq._oldrec (Eq.refl (1 = 1 * 1)) (one_mul 1))) (Eq.refl 1))\n    (mul_lt_mul' ha hb zero_le_one (has_lt.lt.trans_le zero_lt_one ha))\n\ntheorem one_lt_mul_of_lt_of_le {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 1 < a) (hb : 1 \u2264 b) : 1 < a * b :=\n  trans_rel_right Less (eq.mpr (id (Eq._oldrec (Eq.refl (1 = 1 * 1)) (one_mul 1))) (Eq.refl 1))\n    (mul_lt_mul ha hb zero_lt_one (has_le.le.trans zero_le_one (has_lt.lt.le ha)))\n\ntheorem mul_le_of_le_one_right {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 \u2264 a) (hb1 : b \u2264 1) : a * b \u2264 a :=\n  trans_rel_left LessEq (mul_le_mul_of_nonneg_left hb1 ha) (mul_one a)\n\ntheorem mul_le_of_le_one_left {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 \u2264 b) (ha1 : a \u2264 1) : a * b \u2264 b :=\n  trans_rel_left LessEq (mul_le_mul ha1 le_rfl hb zero_le_one) (one_mul b)\n\ntheorem mul_lt_one_of_nonneg_of_lt_one_left {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha0 : 0 \u2264 a) (ha : a < 1) (hb : b \u2264 1) : a * b < 1 :=\n  lt_of_le_of_lt (mul_le_of_le_one_right ha0 hb) ha\n\ntheorem mul_lt_one_of_nonneg_of_lt_one_right {\u03b1 : Type u} [ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (ha : a \u2264 1) (hb0 : 0 \u2264 b) (hb : b < 1) : a * b < 1 :=\n  lt_of_le_of_lt (mul_le_of_le_one_left hb0 ha) hb\n\n/-- An `ordered_comm_semiring \u03b1` is a commutative semiring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\nclass ordered_comm_semiring (\u03b1 : Type u) \nextends comm_semiring \u03b1, ordered_semiring \u03b1\nwhere\n\n/--\nA `linear_ordered_semiring \u03b1` is a nontrivial semiring `\u03b1` with a linear order\nsuch that multiplication with a positive number and addition are monotone.\n-/\n-- It's not entirely clear we should assume `nontrivial` at this point;\n\n-- it would be reasonable to explore changing this,\n\n-- but be warned that the instances involving `domain` may cause\n\n-- typeclass search loops.\n\nclass linear_ordered_semiring (\u03b1 : Type u) \nextends ordered_semiring \u03b1, nontrivial \u03b1, linear_order \u03b1\nwhere\n\n-- `norm_num` expects the lemma stating `0 < 1` to have a single typeclass argument\n\n-- (see `norm_num.prove_pos_nat`).\n\n-- Rather than working out how to relax that assumption,\n\n-- we provide a synonym for `zero_lt_one` (which needs both `ordered_semiring \u03b1` and `nontrivial \u03b1`)\n\n-- with only a `linear_ordered_semiring` typeclass argument.\n\ntheorem zero_lt_one' {\u03b1 : Type u} [linear_ordered_semiring \u03b1] : 0 < 1 :=\n  zero_lt_one\n\ntheorem lt_of_mul_lt_mul_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : c * a < c * b) (hc : 0 \u2264 c) : a < b :=\n  lt_of_not_ge fun (h1 : b \u2264 a) => (fun (h2 : c * b \u2264 c * a) => has_le.le.not_lt h2 h) (mul_le_mul_of_nonneg_left h1 hc)\n\ntheorem lt_of_mul_lt_mul_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : a * c < b * c) (hc : 0 \u2264 c) : a < b :=\n  lt_of_not_ge fun (h1 : b \u2264 a) => (fun (h2 : b * c \u2264 a * c) => has_le.le.not_lt h2 h) (mul_le_mul_of_nonneg_right h1 hc)\n\ntheorem le_of_mul_le_mul_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : c * a \u2264 c * b) (hc : 0 < c) : a \u2264 b :=\n  le_of_not_gt fun (h1 : b < a) => (fun (h2 : c * b < c * a) => has_lt.lt.not_le h2 h) (mul_lt_mul_of_pos_left h1 hc)\n\ntheorem le_of_mul_le_mul_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : a * c \u2264 b * c) (hc : 0 < c) : a \u2264 b :=\n  le_of_not_gt fun (h1 : b < a) => (fun (h2 : b * c < a * c) => has_lt.lt.not_le h2 h) (mul_lt_mul_of_pos_right h1 hc)\n\ntheorem pos_and_pos_or_neg_and_neg_of_mul_pos {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hab : 0 < a * b) : 0 < a \u2227 0 < b \u2228 a < 0 \u2227 b < 0 := sorry\n\ntheorem nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hab : 0 \u2264 a * b) : 0 \u2264 a \u2227 0 \u2264 b \u2228 a \u2264 0 \u2227 b \u2264 0 := sorry\n\ntheorem pos_of_mul_pos_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 < a * b) (ha : 0 \u2264 a) : 0 < b :=\n  and.right\n    (or.resolve_right (pos_and_pos_or_neg_and_neg_of_mul_pos h)\n      fun (h : a < 0 \u2227 b < 0) => has_lt.lt.not_le (and.left h) ha)\n\ntheorem pos_of_mul_pos_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 < a * b) (hb : 0 \u2264 b) : 0 < a :=\n  and.left\n    (or.resolve_right (pos_and_pos_or_neg_and_neg_of_mul_pos h)\n      fun (h : a < 0 \u2227 b < 0) => has_lt.lt.not_le (and.right h) hb)\n\ntheorem nonneg_of_mul_nonneg_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 \u2264 a * b) (h1 : 0 < a) : 0 \u2264 b :=\n  le_of_not_gt fun (h2 : b < 0) => has_lt.lt.not_le (mul_neg_of_pos_of_neg h1 h2) h\n\ntheorem nonneg_of_mul_nonneg_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 \u2264 a * b) (h1 : 0 < b) : 0 \u2264 a :=\n  le_of_not_gt fun (h2 : a < 0) => has_lt.lt.not_le (mul_neg_of_neg_of_pos h2 h1) h\n\ntheorem neg_of_mul_neg_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b < 0) (h1 : 0 \u2264 a) : b < 0 :=\n  lt_of_not_ge fun (h2 : b \u2265 0) => has_le.le.not_lt (mul_nonneg h1 h2) h\n\ntheorem neg_of_mul_neg_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b < 0) (h1 : 0 \u2264 b) : a < 0 :=\n  lt_of_not_ge fun (h2 : a \u2265 0) => has_le.le.not_lt (mul_nonneg h2 h1) h\n\ntheorem nonpos_of_mul_nonpos_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b \u2264 0) (h1 : 0 < a) : b \u2264 0 :=\n  le_of_not_gt fun (h2 : b > 0) => has_lt.lt.not_le (mul_pos h1 h2) h\n\ntheorem nonpos_of_mul_nonpos_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b \u2264 0) (h1 : 0 < b) : a \u2264 0 :=\n  le_of_not_gt fun (h2 : a > 0) => has_lt.lt.not_le (mul_pos h2 h1) h\n\n@[simp] theorem mul_le_mul_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < c) : c * a \u2264 c * b \u2194 a \u2264 b :=\n  { mp := fun (h' : c * a \u2264 c * b) => le_of_mul_le_mul_left h' h,\n    mpr := fun (h' : a \u2264 b) => mul_le_mul_of_nonneg_left h' (has_lt.lt.le h) }\n\n@[simp] theorem mul_le_mul_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < c) : a * c \u2264 b * c \u2194 a \u2264 b :=\n  { mp := fun (h' : a * c \u2264 b * c) => le_of_mul_le_mul_right h' h,\n    mpr := fun (h' : a \u2264 b) => mul_le_mul_of_nonneg_right h' (has_lt.lt.le h) }\n\n@[simp] theorem mul_lt_mul_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < c) : c * a < c * b \u2194 a < b :=\n  { mp := lt_imp_lt_of_le_imp_le fun (h' : b \u2264 a) => mul_le_mul_of_nonneg_left h' (has_lt.lt.le h),\n    mpr := fun (h' : a < b) => mul_lt_mul_of_pos_left h' h }\n\n@[simp] theorem mul_lt_mul_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < c) : a * c < b * c \u2194 a < b :=\n  { mp := lt_imp_lt_of_le_imp_le fun (h' : b \u2264 a) => mul_le_mul_of_nonneg_right h' (has_lt.lt.le h),\n    mpr := fun (h' : a < b) => mul_lt_mul_of_pos_right h' h }\n\n@[simp] theorem zero_le_mul_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {b : \u03b1} {c : \u03b1} (h : 0 < c) : 0 \u2264 c * b \u2194 0 \u2264 b := sorry\n\n@[simp] theorem zero_le_mul_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {b : \u03b1} {c : \u03b1} (h : 0 < c) : 0 \u2264 b * c \u2194 0 \u2264 b := sorry\n\n@[simp] theorem zero_lt_mul_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {b : \u03b1} {c : \u03b1} (h : 0 < c) : 0 < c * b \u2194 0 < b := sorry\n\n@[simp] theorem zero_lt_mul_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {b : \u03b1} {c : \u03b1} (h : 0 < c) : 0 < b * c \u2194 0 < b := sorry\n\n@[simp] theorem bit0_le_bit0 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} [nontrivial \u03b1] : bit0 a \u2264 bit0 b \u2194 a \u2264 b := sorry\n\n@[simp] theorem bit0_lt_bit0 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} [nontrivial \u03b1] : bit0 a < bit0 b \u2194 a < b := sorry\n\n@[simp] theorem bit1_le_bit1 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} [nontrivial \u03b1] : bit1 a \u2264 bit1 b \u2194 a \u2264 b :=\n  iff.trans (add_le_add_iff_right 1) bit0_le_bit0\n\n@[simp] theorem bit1_lt_bit1 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} [nontrivial \u03b1] : bit1 a < bit1 b \u2194 a < b :=\n  iff.trans (add_lt_add_iff_right 1) bit0_lt_bit0\n\n@[simp] theorem one_le_bit1 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} [nontrivial \u03b1] : 1 \u2264 bit1 a \u2194 0 \u2264 a := sorry\n\n@[simp] theorem one_lt_bit1 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} [nontrivial \u03b1] : 1 < bit1 a \u2194 0 < a := sorry\n\n@[simp] theorem zero_le_bit0 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} [nontrivial \u03b1] : 0 \u2264 bit0 a \u2194 0 \u2264 a := sorry\n\n@[simp] theorem zero_lt_bit0 {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} [nontrivial \u03b1] : 0 < bit0 a \u2194 0 < a := sorry\n\ntheorem le_mul_iff_one_le_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : b \u2264 a * b \u2194 1 \u2264 a :=\n  (fun (this : 1 * b \u2264 a * b \u2194 1 \u2264 a) => eq.mp (Eq._oldrec (Eq.refl (1 * b \u2264 a * b \u2194 1 \u2264 a)) (one_mul b)) this)\n    (mul_le_mul_right hb)\n\ntheorem lt_mul_iff_one_lt_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : b < a * b \u2194 1 < a :=\n  (fun (this : 1 * b < a * b \u2194 1 < a) => eq.mp (Eq._oldrec (Eq.refl (1 * b < a * b \u2194 1 < a)) (one_mul b)) this)\n    (mul_lt_mul_right hb)\n\ntheorem le_mul_iff_one_le_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : b \u2264 b * a \u2194 1 \u2264 a :=\n  (fun (this : b * 1 \u2264 b * a \u2194 1 \u2264 a) => eq.mp (Eq._oldrec (Eq.refl (b * 1 \u2264 b * a \u2194 1 \u2264 a)) (mul_one b)) this)\n    (mul_le_mul_left hb)\n\ntheorem lt_mul_iff_one_lt_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : b < b * a \u2194 1 < a :=\n  (fun (this : b * 1 < b * a \u2194 1 < a) => eq.mp (Eq._oldrec (Eq.refl (b * 1 < b * a \u2194 1 < a)) (mul_one b)) this)\n    (mul_lt_mul_left hb)\n\ntheorem lt_mul_of_one_lt_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : 1 < a \u2192 b < b * a :=\n  iff.mpr (lt_mul_iff_one_lt_right hb)\n\ntheorem mul_nonneg_iff_right_nonneg_of_pos {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 < a) : 0 \u2264 b * a \u2194 0 \u2264 b :=\n  { mp := fun (this : 0 \u2264 b * a) => nonneg_of_mul_nonneg_right this h,\n    mpr := fun (this : 0 \u2264 b) => mul_nonneg this (has_lt.lt.le h) }\n\ntheorem mul_le_iff_le_one_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : a * b \u2264 b \u2194 a \u2264 1 :=\n  { mp := fun (h : a * b \u2264 b) => le_of_not_lt (mt (iff.mpr (lt_mul_iff_one_lt_left hb)) (has_le.le.not_lt h)),\n    mpr := fun (h : a \u2264 1) => le_of_not_lt (mt (iff.mp (lt_mul_iff_one_lt_left hb)) (has_le.le.not_lt h)) }\n\ntheorem mul_lt_iff_lt_one_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : a * b < b \u2194 a < 1 :=\n  { mp := fun (h : a * b < b) => lt_of_not_ge (mt (iff.mpr (le_mul_iff_one_le_left hb)) (has_lt.lt.not_le h)),\n    mpr := fun (h : a < 1) => lt_of_not_ge (mt (iff.mp (le_mul_iff_one_le_left hb)) (has_lt.lt.not_le h)) }\n\ntheorem mul_le_iff_le_one_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : b * a \u2264 b \u2194 a \u2264 1 :=\n  { mp := fun (h : b * a \u2264 b) => le_of_not_lt (mt (iff.mpr (lt_mul_iff_one_lt_right hb)) (has_le.le.not_lt h)),\n    mpr := fun (h : a \u2264 1) => le_of_not_lt (mt (iff.mp (lt_mul_iff_one_lt_right hb)) (has_le.le.not_lt h)) }\n\ntheorem mul_lt_iff_lt_one_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : b * a < b \u2194 a < 1 :=\n  { mp := fun (h : b * a < b) => lt_of_not_ge (mt (iff.mpr (le_mul_iff_one_le_right hb)) (has_lt.lt.not_le h)),\n    mpr := fun (h : a < 1) => lt_of_not_ge (mt (iff.mp (le_mul_iff_one_le_right hb)) (has_lt.lt.not_le h)) }\n\ntheorem nonpos_of_mul_nonneg_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 \u2264 a * b) (hb : b < 0) : a \u2264 0 :=\n  le_of_not_gt fun (ha : a > 0) => absurd h (has_lt.lt.not_le (mul_neg_of_pos_of_neg ha hb))\n\ntheorem nonpos_of_mul_nonneg_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 \u2264 a * b) (ha : a < 0) : b \u2264 0 :=\n  le_of_not_gt fun (hb : b > 0) => absurd h (has_lt.lt.not_le (mul_neg_of_neg_of_pos ha hb))\n\ntheorem neg_of_mul_pos_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 < a * b) (hb : b \u2264 0) : a < 0 :=\n  lt_of_not_ge fun (ha : a \u2265 0) => absurd h (has_le.le.not_lt (mul_nonpos_of_nonneg_of_nonpos ha hb))\n\ntheorem neg_of_mul_pos_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} (h : 0 < a * b) (ha : a \u2264 0) : b < 0 :=\n  lt_of_not_ge fun (hb : b \u2265 0) => absurd h (has_le.le.not_lt (mul_nonpos_of_nonpos_of_nonneg ha hb))\n\nprotected instance linear_ordered_semiring.to_no_top_order {\u03b1 : Type u_1} [linear_ordered_semiring \u03b1] : no_top_order \u03b1 :=\n  no_top_order.mk fun (a : \u03b1) => Exists.intro (a + 1) (lt_add_of_pos_right a zero_lt_one)\n\ntheorem monotone_mul_left_of_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} (ha : 0 \u2264 a) : monotone fun (x : \u03b1) => a * x :=\n  fun (b c : \u03b1) (b_le_c : b \u2264 c) => mul_le_mul_of_nonneg_left b_le_c ha\n\ntheorem monotone_mul_right_of_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} (ha : 0 \u2264 a) : monotone fun (x : \u03b1) => x * a :=\n  fun (b c : \u03b1) (b_le_c : b \u2264 c) => mul_le_mul_of_nonneg_right b_le_c ha\n\ntheorem monotone.mul_const {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f) (ha : 0 \u2264 a) : monotone fun (x : \u03b2) => f x * a :=\n  monotone.comp (monotone_mul_right_of_nonneg ha) hf\n\ntheorem monotone.const_mul {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : monotone f) (ha : 0 \u2264 a) : monotone fun (x : \u03b2) => a * f x :=\n  monotone.comp (monotone_mul_left_of_nonneg ha) hf\n\ntheorem monotone.mul {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : monotone f) (hg : monotone g) (hf0 : \u2200 (x : \u03b2), 0 \u2264 f x) (hg0 : \u2200 (x : \u03b2), 0 \u2264 g x) : monotone fun (x : \u03b2) => f x * g x :=\n  fun (x y : \u03b2) (h : x \u2264 y) => mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)\n\ntheorem strict_mono_mul_left_of_pos {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} (ha : 0 < a) : strict_mono fun (x : \u03b1) => a * x :=\n  fun (b c : \u03b1) (b_lt_c : b < c) => iff.mpr (mul_lt_mul_left ha) b_lt_c\n\ntheorem strict_mono_mul_right_of_pos {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} (ha : 0 < a) : strict_mono fun (x : \u03b1) => x * a :=\n  fun (b c : \u03b1) (b_lt_c : b < c) => iff.mpr (mul_lt_mul_right ha) b_lt_c\n\ntheorem strict_mono.mul_const {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : strict_mono f) (ha : 0 < a) : strict_mono fun (x : \u03b2) => f x * a :=\n  strict_mono.comp (strict_mono_mul_right_of_pos ha) hf\n\ntheorem strict_mono.const_mul {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : strict_mono f) (ha : 0 < a) : strict_mono fun (x : \u03b2) => a * f x :=\n  strict_mono.comp (strict_mono_mul_left_of_pos ha) hf\n\ntheorem strict_mono.mul_monotone {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : strict_mono f) (hg : monotone g) (hf0 : \u2200 (x : \u03b2), 0 \u2264 f x) (hg0 : \u2200 (x : \u03b2), 0 < g x) : strict_mono fun (x : \u03b2) => f x * g x :=\n  fun (x y : \u03b2) (h : x < y) => mul_lt_mul (hf h) (hg (has_lt.lt.le h)) (hg0 x) (hf0 y)\n\ntheorem monotone.mul_strict_mono {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : monotone f) (hg : strict_mono g) (hf0 : \u2200 (x : \u03b2), 0 < f x) (hg0 : \u2200 (x : \u03b2), 0 \u2264 g x) : strict_mono fun (x : \u03b2) => f x * g x :=\n  fun (x y : \u03b2) (h : x < y) => mul_lt_mul' (hf (has_lt.lt.le h)) (hg h) (hg0 x) (hf0 y)\n\ntheorem strict_mono.mul {\u03b1 : Type u} {\u03b2 : Type u_1} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : strict_mono f) (hg : strict_mono g) (hf0 : \u2200 (x : \u03b2), 0 \u2264 f x) (hg0 : \u2200 (x : \u03b2), 0 \u2264 g x) : strict_mono fun (x : \u03b2) => f x * g x :=\n  fun (x y : \u03b2) (h : x < y) => mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)\n\n@[simp] theorem decidable.mul_le_mul_left {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < c) : c * a \u2264 c * b \u2194 a \u2264 b :=\n  iff.mpr decidable.le_iff_le_iff_lt_iff_lt (mul_lt_mul_left h)\n\n@[simp] theorem decidable.mul_le_mul_right {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < c) : a * c \u2264 b * c \u2194 a \u2264 b :=\n  iff.mpr decidable.le_iff_le_iff_lt_iff_lt (mul_lt_mul_right h)\n\ntheorem mul_max_of_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} (b : \u03b1) (c : \u03b1) (ha : 0 \u2264 a) : a * max b c = max (a * b) (a * c) :=\n  monotone.map_max (monotone_mul_left_of_nonneg ha)\n\ntheorem mul_min_of_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {a : \u03b1} (b : \u03b1) (c : \u03b1) (ha : 0 \u2264 a) : a * min b c = min (a * b) (a * c) :=\n  monotone.map_min (monotone_mul_left_of_nonneg ha)\n\ntheorem max_mul_of_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {c : \u03b1} (a : \u03b1) (b : \u03b1) (hc : 0 \u2264 c) : max a b * c = max (a * c) (b * c) :=\n  monotone.map_max (monotone_mul_right_of_nonneg hc)\n\ntheorem min_mul_of_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {c : \u03b1} (a : \u03b1) (b : \u03b1) (hc : 0 \u2264 c) : min a b * c = min (a * c) (b * c) :=\n  monotone.map_min (monotone_mul_right_of_nonneg hc)\n\n/-- An `ordered_ring \u03b1` is a ring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\nclass ordered_ring (\u03b1 : Type u) \nextends ring \u03b1, ordered_add_comm_group \u03b1\nwhere\n  zero_le_one : 0 \u2264 1\n  mul_pos : \u2200 (a b : \u03b1), 0 < a \u2192 0 < b \u2192 0 < a * b\n\ntheorem ordered_ring.mul_nonneg {\u03b1 : Type u} [ordered_ring \u03b1] (a : \u03b1) (b : \u03b1) (h\u2081 : 0 \u2264 a) (h\u2082 : 0 \u2264 b) : 0 \u2264 a * b := sorry\n\ntheorem ordered_ring.mul_le_mul_of_nonneg_left {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c * a \u2264 c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (c * a \u2264 c * b)) (Eq.symm (propext sub_nonneg))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 c * b - c * a)) (Eq.symm (mul_sub c b a))))\n      (ordered_ring.mul_nonneg c (b - a) h\u2082 (iff.mpr sub_nonneg h\u2081)))\n\ntheorem ordered_ring.mul_le_mul_of_nonneg_right {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : a * c \u2264 b * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * c \u2264 b * c)) (Eq.symm (propext sub_nonneg))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 b * c - a * c)) (Eq.symm (sub_mul b a c))))\n      (ordered_ring.mul_nonneg (b - a) c (iff.mpr sub_nonneg h\u2081) h\u2082))\n\ntheorem ordered_ring.mul_lt_mul_of_pos_left {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a < b) (h\u2082 : 0 < c) : c * a < c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (c * a < c * b)) (Eq.symm (propext sub_pos))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 < c * b - c * a)) (Eq.symm (mul_sub c b a))))\n      (ordered_ring.mul_pos c (b - a) h\u2082 (iff.mpr sub_pos h\u2081)))\n\ntheorem ordered_ring.mul_lt_mul_of_pos_right {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h\u2081 : a < b) (h\u2082 : 0 < c) : a * c < b * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * c < b * c)) (Eq.symm (propext sub_pos))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 < b * c - a * c)) (Eq.symm (sub_mul b a c))))\n      (ordered_ring.mul_pos (b - a) c (iff.mpr sub_pos h\u2081) h\u2082))\n\nprotected instance ordered_ring.to_ordered_semiring {\u03b1 : Type u} [ordered_ring \u03b1] : ordered_semiring \u03b1 :=\n  ordered_semiring.mk ordered_ring.add ordered_ring.add_assoc ordered_ring.zero ordered_ring.zero_add\n    ordered_ring.add_zero ordered_ring.add_comm ordered_ring.mul ordered_ring.mul_assoc ordered_ring.one\n    ordered_ring.one_mul ordered_ring.mul_one sorry sorry ordered_ring.left_distrib ordered_ring.right_distrib sorry sorry\n    ordered_ring.le ordered_ring.lt ordered_ring.le_refl ordered_ring.le_trans ordered_ring.le_antisymm\n    ordered_ring.add_le_add_left sorry ordered_ring.zero_le_one ordered_ring.mul_lt_mul_of_pos_left\n    ordered_ring.mul_lt_mul_of_pos_right\n\ntheorem mul_le_mul_of_nonpos_left {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : b \u2264 a) (hc : c \u2264 0) : c * a \u2264 c * b := sorry\n\ntheorem mul_le_mul_of_nonpos_right {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : b \u2264 a) (hc : c \u2264 0) : a * c \u2264 b * c := sorry\n\ntheorem mul_nonneg_of_nonpos_of_nonpos {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (ha : a \u2264 0) (hb : b \u2264 0) : 0 \u2264 a * b :=\n  (fun (this : 0 * b \u2264 a * b) => eq.mp (Eq._oldrec (Eq.refl (0 * b \u2264 a * b)) (zero_mul b)) this)\n    (mul_le_mul_of_nonpos_right ha hb)\n\ntheorem mul_lt_mul_of_neg_left {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : b < a) (hc : c < 0) : c * a < c * b := sorry\n\ntheorem mul_lt_mul_of_neg_right {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : b < a) (hc : c < 0) : a * c < b * c := sorry\n\ntheorem mul_pos_of_neg_of_neg {\u03b1 : Type u} [ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : 0 < a * b :=\n  (fun (this : 0 * b < a * b) => eq.mp (Eq._oldrec (Eq.refl (0 * b < a * b)) (zero_mul b)) this)\n    (mul_lt_mul_of_neg_right ha hb)\n\n/-- An `ordered_comm_ring \u03b1` is a commutative ring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\nclass ordered_comm_ring (\u03b1 : Type u) \nextends ordered_ring \u03b1, comm_ring \u03b1, ordered_comm_semiring \u03b1\nwhere\n\n/-- A `linear_ordered_ring \u03b1` is a ring `\u03b1` with a linear order such that\nmultiplication with a positive number and addition are monotone. -/\nclass linear_ordered_ring (\u03b1 : Type u) \nextends nontrivial \u03b1, linear_order \u03b1, ordered_ring \u03b1\nwhere\n\nprotected instance linear_ordered_ring.to_linear_ordered_add_comm_group {\u03b1 : Type u} [s : linear_ordered_ring \u03b1] : linear_ordered_add_comm_group \u03b1 :=\n  linear_ordered_add_comm_group.mk linear_ordered_ring.add linear_ordered_ring.add_assoc linear_ordered_ring.zero\n    linear_ordered_ring.zero_add linear_ordered_ring.add_zero linear_ordered_ring.neg linear_ordered_ring.sub\n    linear_ordered_ring.add_left_neg linear_ordered_ring.add_comm linear_ordered_ring.le linear_ordered_ring.lt\n    linear_ordered_ring.le_refl linear_ordered_ring.le_trans linear_ordered_ring.le_antisymm linear_ordered_ring.le_total\n    linear_ordered_ring.decidable_le linear_ordered_ring.decidable_eq linear_ordered_ring.decidable_lt\n    linear_ordered_ring.add_le_add_left\n\nprotected instance linear_ordered_ring.to_linear_ordered_semiring {\u03b1 : Type u} [linear_ordered_ring \u03b1] : linear_ordered_semiring \u03b1 :=\n  linear_ordered_semiring.mk linear_ordered_ring.add linear_ordered_ring.add_assoc linear_ordered_ring.zero\n    linear_ordered_ring.zero_add linear_ordered_ring.add_zero linear_ordered_ring.add_comm linear_ordered_ring.mul\n    linear_ordered_ring.mul_assoc linear_ordered_ring.one linear_ordered_ring.one_mul linear_ordered_ring.mul_one sorry\n    sorry linear_ordered_ring.left_distrib linear_ordered_ring.right_distrib sorry sorry linear_ordered_ring.le\n    linear_ordered_ring.lt linear_ordered_ring.le_refl linear_ordered_ring.le_trans linear_ordered_ring.le_antisymm\n    linear_ordered_ring.add_le_add_left sorry linear_ordered_ring.zero_le_one sorry sorry linear_ordered_ring.le_total\n    linear_ordered_ring.decidable_le linear_ordered_ring.decidable_eq linear_ordered_ring.decidable_lt\n    linear_ordered_ring.exists_pair_ne\n\nprotected instance linear_ordered_ring.to_domain {\u03b1 : Type u} [linear_ordered_ring \u03b1] : domain \u03b1 :=\n  domain.mk linear_ordered_ring.add linear_ordered_ring.add_assoc linear_ordered_ring.zero linear_ordered_ring.zero_add\n    linear_ordered_ring.add_zero linear_ordered_ring.neg linear_ordered_ring.sub linear_ordered_ring.add_left_neg\n    linear_ordered_ring.add_comm linear_ordered_ring.mul linear_ordered_ring.mul_assoc linear_ordered_ring.one\n    linear_ordered_ring.one_mul linear_ordered_ring.mul_one linear_ordered_ring.left_distrib\n    linear_ordered_ring.right_distrib linear_ordered_ring.exists_pair_ne sorry\n\n@[simp] theorem abs_one {\u03b1 : Type u} [linear_ordered_ring \u03b1] : abs 1 = 1 :=\n  abs_of_pos zero_lt_one\n\n@[simp] theorem abs_two {\u03b1 : Type u} [linear_ordered_ring \u03b1] : abs (bit0 1) = bit0 1 :=\n  abs_of_pos zero_lt_two\n\ntheorem abs_mul {\u03b1 : Type u} [linear_ordered_ring \u03b1] (a : \u03b1) (b : \u03b1) : abs (a * b) = abs a * abs b := sorry\n\n/-- `abs` as a `monoid_with_zero_hom`. -/\ndef abs_hom {\u03b1 : Type u} [linear_ordered_ring \u03b1] : monoid_with_zero_hom \u03b1 \u03b1 :=\n  monoid_with_zero_hom.mk abs sorry abs_one abs_mul\n\n@[simp] theorem abs_mul_abs_self {\u03b1 : Type u} [linear_ordered_ring \u03b1] (a : \u03b1) : abs a * abs a = a * a :=\n  abs_by_cases (fun (x : \u03b1) => x * x = a * a) rfl (neg_mul_neg a a)\n\n@[simp] theorem abs_mul_self {\u03b1 : Type u} [linear_ordered_ring \u03b1] (a : \u03b1) : abs (a * a) = a * a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (abs (a * a) = a * a)) (abs_mul a a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (abs a * abs a = a * a)) (abs_mul_abs_self a))) (Eq.refl (a * a)))\n\ntheorem mul_pos_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} : 0 < a * b \u2194 0 < a \u2227 0 < b \u2228 a < 0 \u2227 b < 0 := sorry\n\ntheorem mul_neg_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} : a * b < 0 \u2194 0 < a \u2227 b < 0 \u2228 a < 0 \u2227 0 < b := sorry\n\ntheorem mul_nonneg_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} : 0 \u2264 a * b \u2194 0 \u2264 a \u2227 0 \u2264 b \u2228 a \u2264 0 \u2227 b \u2264 0 := sorry\n\ntheorem mul_nonpos_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} : a * b \u2264 0 \u2194 0 \u2264 a \u2227 b \u2264 0 \u2228 a \u2264 0 \u2227 0 \u2264 b := sorry\n\ntheorem mul_self_nonneg {\u03b1 : Type u} [linear_ordered_ring \u03b1] (a : \u03b1) : 0 \u2264 a * a :=\n  abs_mul_self a \u25b8 abs_nonneg (a * a)\n\n@[simp] theorem neg_le_self_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} : -a \u2264 a \u2194 0 \u2264 a := sorry\n\n@[simp] theorem neg_lt_self_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} : -a < a \u2194 0 < a := sorry\n\n@[simp] theorem le_neg_self_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} : a \u2264 -a \u2194 a \u2264 0 :=\n  iff.trans\n    (iff.trans (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 -a \u2194 --a \u2264 -a)) (neg_neg a))) (iff.refl (a \u2264 -a))) neg_le_self_iff)\n    neg_nonneg\n\n@[simp] theorem lt_neg_self_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} : a < -a \u2194 a < 0 :=\n  iff.trans\n    (iff.trans (eq.mpr (id (Eq._oldrec (Eq.refl (a < -a \u2194 --a < -a)) (neg_neg a))) (iff.refl (a < -a))) neg_lt_self_iff)\n    neg_pos\n\n@[simp] theorem abs_eq_self {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} : abs a = a \u2194 0 \u2264 a := sorry\n\n@[simp] theorem abs_eq_neg_self {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} : abs a = -a \u2194 a \u2264 0 := sorry\n\ntheorem gt_of_mul_lt_mul_neg_left {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : c * a < c * b) (hc : c \u2264 0) : b < a := sorry\n\ntheorem neg_one_lt_zero {\u03b1 : Type u} [linear_ordered_ring \u03b1] : -1 < 0 :=\n  iff.mpr neg_lt_zero zero_lt_one\n\ntheorem le_of_mul_le_of_one_le {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : a * c \u2264 b) (hb : 0 \u2264 b) (hc : 1 \u2264 c) : a \u2264 b :=\n  (fun (h' : a * c \u2264 b * c) => le_of_mul_le_mul_right h' (has_lt.lt.trans_le zero_lt_one hc))\n    (le_trans (trans_rel_left LessEq h (eq.mpr (id (Eq._oldrec (Eq.refl (b = b * 1)) (mul_one b))) (Eq.refl b)))\n      (mul_le_mul_of_nonneg_left hc hb))\n\ntheorem nonneg_le_nonneg_of_squares_le {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 \u2264 b) (h : a * a \u2264 b * b) : a \u2264 b :=\n  le_of_not_gt fun (hab : a > b) => has_lt.lt.not_le (mul_self_lt_mul_self hb hab) h\n\ntheorem mul_self_le_mul_self_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a \u2264 b \u2194 a * a \u2264 b * b :=\n  { mp := mul_self_le_mul_self h1, mpr := nonneg_le_nonneg_of_squares_le h2 }\n\ntheorem mul_self_lt_mul_self_iff {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a < b \u2194 a * a < b * b :=\n  iff.symm (strict_mono_incr_on.lt_iff_lt strict_mono_incr_on_mul_self h1 h2)\n\ntheorem mul_self_inj {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a * a = b * b \u2194 a = b :=\n  set.inj_on.eq_iff (strict_mono_incr_on.inj_on strict_mono_incr_on_mul_self) h1 h2\n\n@[simp] theorem mul_le_mul_left_of_neg {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : c < 0) : c * a \u2264 c * b \u2194 b \u2264 a :=\n  { mp := le_imp_le_of_lt_imp_lt fun (h' : a < b) => mul_lt_mul_of_neg_left h' h,\n    mpr := fun (h' : b \u2264 a) => mul_le_mul_of_nonpos_left h' (has_lt.lt.le h) }\n\n@[simp] theorem mul_le_mul_right_of_neg {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : c < 0) : a * c \u2264 b * c \u2194 b \u2264 a :=\n  { mp := le_imp_le_of_lt_imp_lt fun (h' : a < b) => mul_lt_mul_of_neg_right h' h,\n    mpr := fun (h' : b \u2264 a) => mul_le_mul_of_nonpos_right h' (has_lt.lt.le h) }\n\n@[simp] theorem mul_lt_mul_left_of_neg {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : c < 0) : c * a < c * b \u2194 b < a :=\n  lt_iff_lt_of_le_iff_le (mul_le_mul_left_of_neg h)\n\n@[simp] theorem mul_lt_mul_right_of_neg {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : c < 0) : a * c < b * c \u2194 b < a :=\n  lt_iff_lt_of_le_iff_le (mul_le_mul_right_of_neg h)\n\ntheorem sub_one_lt {\u03b1 : Type u} [linear_ordered_ring \u03b1] (a : \u03b1) : a - 1 < a :=\n  iff.mpr sub_lt_iff_lt_add (lt_add_one a)\n\ntheorem mul_self_pos {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} (ha : a \u2260 0) : 0 < a * a :=\n  or.dcases_on (lt_trichotomy a 0) (fun (h : a < 0) => mul_pos_of_neg_of_neg h h)\n    fun (h : a = 0 \u2228 0 < a) => or.dcases_on h (fun (h : a = 0) => false.elim (ha h)) fun (h : 0 < a) => mul_pos h h\n\ntheorem mul_self_le_mul_self_of_le_of_neg_le {\u03b1 : Type u} [linear_ordered_ring \u03b1] {x : \u03b1} {y : \u03b1} (h\u2081 : x \u2264 y) (h\u2082 : -x \u2264 y) : x * x \u2264 y * y :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (x * x \u2264 y * y)) (Eq.symm (abs_mul_abs_self x))))\n    (mul_self_le_mul_self (abs_nonneg x) (iff.mpr abs_le { left := iff.mpr neg_le h\u2082, right := h\u2081 }))\n\ntheorem nonneg_of_mul_nonpos_left {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b \u2264 0) (hb : b < 0) : 0 \u2264 a :=\n  le_of_not_gt fun (ha : 0 > a) => absurd h (has_lt.lt.not_le (mul_pos_of_neg_of_neg ha hb))\n\ntheorem nonneg_of_mul_nonpos_right {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b \u2264 0) (ha : a < 0) : 0 \u2264 b :=\n  le_of_not_gt fun (hb : 0 > b) => absurd h (has_lt.lt.not_le (mul_pos_of_neg_of_neg ha hb))\n\ntheorem pos_of_mul_neg_left {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b < 0) (hb : b \u2264 0) : 0 < a :=\n  lt_of_not_ge fun (ha : 0 \u2265 a) => absurd h (has_le.le.not_lt (mul_nonneg_of_nonpos_of_nonpos ha hb))\n\ntheorem pos_of_mul_neg_right {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * b < 0) (ha : a \u2264 0) : 0 < b :=\n  lt_of_not_ge fun (hb : 0 \u2265 b) => absurd h (has_le.le.not_lt (mul_nonneg_of_nonpos_of_nonpos ha hb))\n\n/-- The sum of two squares is zero iff both elements are zero. -/\ntheorem mul_self_add_mul_self_eq_zero {\u03b1 : Type u} [linear_ordered_ring \u03b1] {x : \u03b1} {y : \u03b1} : x * x + y * y = 0 \u2194 x = 0 \u2227 y = 0 := sorry\n\ntheorem eq_zero_of_mul_self_add_mul_self_eq_zero {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} (h : a * a + b * b = 0) : a = 0 :=\n  and.left (iff.mp mul_self_add_mul_self_eq_zero h)\n\ntheorem abs_eq_iff_mul_self_eq {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} : abs a = abs b \u2194 a * a = b * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (abs a = abs b \u2194 a * a = b * b)) (Eq.symm (abs_mul_abs_self a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (abs a = abs b \u2194 abs a * abs a = b * b)) (Eq.symm (abs_mul_abs_self b))))\n      (iff.symm (mul_self_inj (abs_nonneg a) (abs_nonneg b))))\n\ntheorem abs_lt_iff_mul_self_lt {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} : abs a < abs b \u2194 a * a < b * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (abs a < abs b \u2194 a * a < b * b)) (Eq.symm (abs_mul_abs_self a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (abs a < abs b \u2194 abs a * abs a < b * b)) (Eq.symm (abs_mul_abs_self b))))\n      (mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)))\n\ntheorem abs_le_iff_mul_self_le {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} {b : \u03b1} : abs a \u2264 abs b \u2194 a * a \u2264 b * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (abs a \u2264 abs b \u2194 a * a \u2264 b * b)) (Eq.symm (abs_mul_abs_self a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (abs a \u2264 abs b \u2194 abs a * abs a \u2264 b * b)) (Eq.symm (abs_mul_abs_self b))))\n      (mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)))\n\ntheorem abs_le_one_iff_mul_self_le_one {\u03b1 : Type u} [linear_ordered_ring \u03b1] {a : \u03b1} : abs a \u2264 1 \u2194 a * a \u2264 1 := sorry\n\n/-- A `linear_ordered_comm_ring \u03b1` is a commutative ring `\u03b1` with a linear order\nsuch that multiplication with a positive number and addition are monotone. -/\nclass linear_ordered_comm_ring (\u03b1 : Type u) \nextends linear_ordered_ring \u03b1, comm_monoid \u03b1\nwhere\n\nprotected instance linear_ordered_comm_ring.to_ordered_comm_ring {\u03b1 : Type u} [d : linear_ordered_comm_ring \u03b1] : ordered_comm_ring \u03b1 := sorry\n\n-- One might hope that `{ ..linear_ordered_ring.to_linear_ordered_semiring, ..d }`\n\n-- achieved the same result here.\n\n-- Unfortunately with that definition we see mismatched instances in `algebra.star.chsh`.\n\nprotected instance linear_ordered_comm_ring.to_integral_domain {\u03b1 : Type u} [s : linear_ordered_comm_ring \u03b1] : integral_domain \u03b1 :=\n  integral_domain.mk domain.add sorry domain.zero sorry sorry domain.neg domain.sub sorry sorry domain.mul sorry\n    domain.one sorry sorry sorry sorry linear_ordered_comm_ring.mul_comm sorry sorry\n\nprotected instance linear_ordered_comm_ring.to_linear_ordered_semiring {\u03b1 : Type u} [d : linear_ordered_comm_ring \u03b1] : linear_ordered_semiring \u03b1 := sorry\n\ntheorem max_mul_mul_le_max_mul_max {\u03b1 : Type u} [linear_ordered_comm_ring \u03b1] {a : \u03b1} {d : \u03b1} (b : \u03b1) (c : \u03b1) (ha : 0 \u2264 a) (hd : 0 \u2264 d) : max (a * b) (d * c) \u2264 max a c * max d b := sorry\n\ntheorem abs_sub_square {\u03b1 : Type u} [linear_ordered_comm_ring \u03b1] (a : \u03b1) (b : \u03b1) : abs (a - b) * abs (a - b) = a * a + b * b - (1 + 1) * a * b := sorry\n\n/-- Extend `nonneg_add_comm_group` to support ordered rings\n  specified by their nonnegative elements -/\nclass nonneg_ring (\u03b1 : Type u_1) \nextends nonneg_add_comm_group \u03b1, ring \u03b1\nwhere\n  one_nonneg : nonneg 1\n  mul_nonneg : \u2200 {a b : \u03b1}, nonneg a \u2192 nonneg b \u2192 nonneg (a * b)\n  mul_pos : \u2200 {a b : \u03b1}, pos a \u2192 pos b \u2192 pos (a * b)\n\n/-- Extend `nonneg_add_comm_group` to support linearly ordered rings\n  specified by their nonnegative elements -/\nclass linear_nonneg_ring (\u03b1 : Type u_1) \nextends nonneg_add_comm_group \u03b1, domain \u03b1\nwhere\n  one_pos : pos 1\n  mul_nonneg : \u2200 {a b : \u03b1}, nonneg a \u2192 nonneg b \u2192 nonneg (a * b)\n  nonneg_total : \u2200 (a : \u03b1), nonneg a \u2228 nonneg (-a)\n\nnamespace nonneg_ring\n\n\n/-- `to_linear_nonneg_ring` shows that a `nonneg_ring` with a total order is a `domain`,\nhence a `linear_nonneg_ring`. -/\ndef to_linear_nonneg_ring {\u03b1 : Type u} [nonneg_ring \u03b1] [nontrivial \u03b1] (nonneg_total : \u2200 (a : \u03b1), nonneg a \u2228 nonneg (-a)) : linear_nonneg_ring \u03b1 :=\n  linear_nonneg_ring.mk add add_assoc zero zero_add add_zero neg sub add_left_neg add_comm mul mul_assoc one one_mul\n    mul_one left_distrib right_distrib nontrivial.exists_pair_ne sorry nonneg pos zero_nonneg add_nonneg nonneg_antisymm\n    sorry mul_nonneg nonneg_total\n\nend nonneg_ring\n\n\nnamespace linear_nonneg_ring\n\n\nprotected instance to_nonneg_ring {\u03b1 : Type u} [linear_nonneg_ring \u03b1] : nonneg_ring \u03b1 :=\n  nonneg_ring.mk add add_assoc zero zero_add add_zero neg sub add_left_neg add_comm mul mul_assoc one one_mul mul_one\n    left_distrib right_distrib nonneg pos zero_nonneg add_nonneg nonneg_antisymm sorry mul_nonneg sorry\n\n/-- Construct `linear_order` from `linear_nonneg_ring`. This is not an instance\nbecause we don't use it in `mathlib`. -/\ndef to_linear_order {\u03b1 : Type u} [linear_nonneg_ring \u03b1] [decidable_pred nonneg] : linear_order \u03b1 :=\n  linear_order.mk ordered_add_comm_group.le ordered_add_comm_group.lt sorry sorry sorry sorry\n    (fun (a b : \u03b1) => _inst_2 (b - a)) Mathlib.decidable_eq_of_decidable_le\n    fun (a b : \u03b1) => Mathlib.decidable_lt_of_decidable_le a b\n\n/-- Construct `linear_ordered_ring` from `linear_nonneg_ring`.\nThis is not an instance because we don't use it in `mathlib`. -/\ndef to_linear_ordered_ring {\u03b1 : Type u} [linear_nonneg_ring \u03b1] [decidable_pred nonneg] : linear_ordered_ring \u03b1 :=\n  linear_ordered_ring.mk add add_assoc zero zero_add add_zero neg sub add_left_neg add_comm mul mul_assoc one one_mul\n    mul_one left_distrib right_distrib ordered_add_comm_group.le ordered_add_comm_group.lt sorry sorry sorry sorry sorry\n    sorry sorry linear_order.decidable_le linear_order.decidable_eq linear_order.decidable_lt exists_pair_ne\n\n/-- Convert a `linear_nonneg_ring` with a commutative multiplication and\ndecidable non-negativity into a `linear_ordered_comm_ring` -/\ndef to_linear_ordered_comm_ring {\u03b1 : Type u} [linear_nonneg_ring \u03b1] [decidable_pred nonneg] [comm : is_commutative \u03b1 Mul.mul] : linear_ordered_comm_ring \u03b1 :=\n  linear_ordered_comm_ring.mk linear_ordered_ring.add sorry linear_ordered_ring.zero sorry sorry linear_ordered_ring.neg\n    linear_ordered_ring.sub sorry sorry linear_ordered_ring.mul sorry linear_ordered_ring.one sorry sorry sorry sorry\n    linear_ordered_ring.le linear_ordered_ring.lt sorry sorry sorry sorry sorry sorry sorry\n    linear_ordered_ring.decidable_le linear_ordered_ring.decidable_eq linear_ordered_ring.decidable_lt sorry sorry\n\nend linear_nonneg_ring\n\n\n/-- A canonically ordered commutative semiring is an ordered, commutative semiring\nin which `a \u2264 b` iff there exists `c` with `b = a + c`. This is satisfied by the\nnatural numbers, for example, but not the integers or other ordered groups. -/\nclass canonically_ordered_comm_semiring (\u03b1 : Type u_1) \nextends comm_semiring \u03b1, canonically_ordered_add_monoid \u03b1\nwhere\n  eq_zero_or_eq_zero_of_mul_eq_zero : \u2200 (a b : \u03b1), a * b = 0 \u2192 a = 0 \u2228 b = 0\n\nnamespace canonically_ordered_semiring\n\n\nprotected instance canonically_ordered_comm_semiring.to_no_zero_divisors {\u03b1 : Type u} [canonically_ordered_comm_semiring \u03b1] : no_zero_divisors \u03b1 :=\n  no_zero_divisors.mk canonically_ordered_comm_semiring.eq_zero_or_eq_zero_of_mul_eq_zero\n\ntheorem mul_le_mul {\u03b1 : Type u} [canonically_ordered_comm_semiring \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hab : a \u2264 b) (hcd : c \u2264 d) : a * c \u2264 b * d := sorry\n\ntheorem mul_le_mul_left' {\u03b1 : Type u} [canonically_ordered_comm_semiring \u03b1] {b : \u03b1} {c : \u03b1} (h : b \u2264 c) (a : \u03b1) : a * b \u2264 a * c :=\n  mul_le_mul le_rfl h\n\ntheorem mul_le_mul_right' {\u03b1 : Type u} [canonically_ordered_comm_semiring \u03b1] {b : \u03b1} {c : \u03b1} (h : b \u2264 c) (a : \u03b1) : b * a \u2264 c * a :=\n  mul_le_mul h le_rfl\n\n/-- A version of `zero_lt_one : 0 < 1` for a `canonically_ordered_comm_semiring`. -/\ntheorem zero_lt_one {\u03b1 : Type u} [canonically_ordered_comm_semiring \u03b1] [nontrivial \u03b1] : 0 < 1 :=\n  has_le.le.lt_of_ne (zero_le 1) zero_ne_one\n\ntheorem mul_pos {\u03b1 : Type u} [canonically_ordered_comm_semiring \u03b1] {a : \u03b1} {b : \u03b1} : 0 < a * b \u2194 0 < a \u2227 0 < b := sorry\n\nend canonically_ordered_semiring\n\n\nnamespace with_top\n\n\nprotected instance nontrivial {\u03b1 : Type u} [Nonempty \u03b1] : nontrivial (with_top \u03b1) :=\n  option.nontrivial\n\nprotected instance mul_zero_class {\u03b1 : Type u} [DecidableEq \u03b1] [HasZero \u03b1] [Mul \u03b1] : mul_zero_class (with_top \u03b1) :=\n  mul_zero_class.mk\n    (fun (m n : with_top \u03b1) => ite (m = 0 \u2228 n = 0) 0 (option.bind m fun (a : \u03b1) => option.bind n fun (b : \u03b1) => \u2191(a * b)))\n    0 sorry sorry\n\ntheorem mul_def {\u03b1 : Type u} [DecidableEq \u03b1] [HasZero \u03b1] [Mul \u03b1] {a : with_top \u03b1} {b : with_top \u03b1} : a * b = ite (a = 0 \u2228 b = 0) 0 (option.bind a fun (a : \u03b1) => option.bind b fun (b : \u03b1) => \u2191(a * b)) :=\n  rfl\n\n@[simp] theorem mul_top {\u03b1 : Type u} [DecidableEq \u03b1] [HasZero \u03b1] [Mul \u03b1] {a : with_top \u03b1} (h : a \u2260 0) : a * \u22a4 = \u22a4 := sorry\n\n@[simp] theorem top_mul {\u03b1 : Type u} [DecidableEq \u03b1] [HasZero \u03b1] [Mul \u03b1] {a : with_top \u03b1} (h : a \u2260 0) : \u22a4 * a = \u22a4 := sorry\n\n@[simp] theorem top_mul_top {\u03b1 : Type u} [DecidableEq \u03b1] [HasZero \u03b1] [Mul \u03b1] : \u22a4 * \u22a4 = \u22a4 :=\n  top_mul top_ne_zero\n\ntheorem coe_mul {\u03b1 : Type u} [DecidableEq \u03b1] [mul_zero_class \u03b1] {a : \u03b1} {b : \u03b1} : \u2191(a * b) = \u2191a * \u2191b := sorry\n\ntheorem mul_coe {\u03b1 : Type u} [DecidableEq \u03b1] [mul_zero_class \u03b1] {b : \u03b1} (hb : b \u2260 0) {a : with_top \u03b1} : a * \u2191b = option.bind a fun (a : \u03b1) => \u2191(a * b) := sorry\n\n@[simp] theorem mul_eq_top_iff {\u03b1 : Type u} [DecidableEq \u03b1] [mul_zero_class \u03b1] {a : with_top \u03b1} {b : with_top \u03b1} : a * b = \u22a4 \u2194 a \u2260 0 \u2227 b = \u22a4 \u2228 a = \u22a4 \u2227 b \u2260 0 := sorry\n\nprotected instance no_zero_divisors {\u03b1 : Type u} [DecidableEq \u03b1] [mul_zero_class \u03b1] [no_zero_divisors \u03b1] : no_zero_divisors (with_top \u03b1) := sorry\n\n-- `nontrivial \u03b1` is needed here as otherwise\n\n-- we have `1 * \u22a4 = \u22a4` but also `= 0 * \u22a4 = 0`.\n\nprotected instance canonically_ordered_comm_semiring {\u03b1 : Type u} [DecidableEq \u03b1] [canonically_ordered_comm_semiring \u03b1] [nontrivial \u03b1] : canonically_ordered_comm_semiring (with_top \u03b1) :=\n  canonically_ordered_comm_semiring.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry\n    canonically_ordered_add_monoid.le canonically_ordered_add_monoid.lt sorry sorry sorry sorry sorry\n    canonically_ordered_add_monoid.bot sorry sorry mul_zero_class.mul sorry \u21911 sorry sorry sorry sorry sorry sorry sorry\n    sorry\n\ntheorem mul_lt_top {\u03b1 : Type u} [DecidableEq \u03b1] [canonically_ordered_comm_semiring \u03b1] [nontrivial \u03b1] {a : with_top \u03b1} {b : with_top \u03b1} (ha : a < \u22a4) (hb : b < \u22a4) : a * b < \u22a4 := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/ordered_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7279483467294677}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, S\u00e9bastien Gou\u00ebzel\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.analysis.calculus.mean_value\nimport Mathlib.data.nat.parity\nimport Mathlib.analysis.special_functions.pow\nimport Mathlib.PostPort\n\nuniverses u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# Collection of convex functions\n\nIn this file we prove that the following functions are convex:\n\n* `convex_on_exp` : the exponential function is convex on $(-\u221e, +\u221e)$;\n* `convex_on_pow_of_even` : given an even natural number $n$, the function $f(x)=x^n$\n  is convex on $(-\u221e, +\u221e)$;\n* `convex_on_pow` : for a natural $n$, the function $f(x)=x^n$ is convex on $[0, +\u221e)$;\n* `convex_on_fpow` : for an integer $m$, the function $f(x)=x^m$ is convex on $(0, +\u221e)$.\n* `convex_on_rpow : \u2200 p : \u211d, 1 \u2264 p \u2192 convex_on (Ici 0) (\u03bb x, x ^ p)`\n* `concave_on_log_Ioi` and `concave_on_log_Iio`: log is concave on `Ioi 0` and `Iio 0` respectively.\n-/\n\n/-- `exp` is convex on the whole real line -/\ntheorem convex_on_exp : convex_on set.univ real.exp := sorry\n\n/-- `x^n`, `n : \u2115` is convex on the whole real line whenever `n` is even -/\ntheorem convex_on_pow_of_even {n : \u2115} (hn : even n) : convex_on set.univ fun (x : \u211d) => x ^ n :=\n  sorry\n\n/-- `x^n`, `n : \u2115` is convex on `[0, +\u221e)` for all `n` -/\ntheorem convex_on_pow (n : \u2115) : convex_on (set.Ici 0) fun (x : \u211d) => x ^ n := sorry\n\ntheorem finset.prod_nonneg_of_card_nonpos_even {\u03b1 : Type u_1} {\u03b2 : Type u_2}\n    [linear_ordered_comm_ring \u03b2] {f : \u03b1 \u2192 \u03b2} [decidable_pred fun (x : \u03b1) => f x \u2264 0] {s : finset \u03b1}\n    (h0 : even (finset.card (finset.filter (fun (x : \u03b1) => f x \u2264 0) s))) :\n    0 \u2264 finset.prod s fun (x : \u03b1) => f x :=\n  sorry\n\ntheorem int_prod_range_nonneg (m : \u2124) (n : \u2115) (hn : even n) :\n    0 \u2264 finset.prod (finset.range n) fun (k : \u2115) => m - \u2191k :=\n  sorry\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` -/\ntheorem convex_on_fpow (m : \u2124) : convex_on (set.Ioi 0) fun (x : \u211d) => x ^ m := sorry\n\ntheorem convex_on_rpow {p : \u211d} (hp : 1 \u2264 p) : convex_on (set.Ici 0) fun (x : \u211d) => x ^ p := sorry\n\ntheorem concave_on_log_Ioi : concave_on (set.Ioi 0) real.log := sorry\n\ntheorem concave_on_log_Iio : concave_on (set.Iio 0) real.log := sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/analysis/convex/specific_functions_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7279121638906582}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Heather Macbeth\n-/\nimport analysis.convex.cone\nimport analysis.normed_space.is_R_or_C\nimport analysis.normed_space.extend\n\n/-!\n# Hahn-Banach theorem\n\nIn this file we prove a version of Hahn-Banach theorem for continuous linear\nfunctions on normed spaces over `\u211d` and `\u2102`.\n\nIn order to state and prove its corollaries uniformly, we prove the statements for a field `\ud835\udd5c`\nsatisfying `is_R_or_C \ud835\udd5c`.\n\nIn this setting, `exists_dual_vector` states that, for any nonzero `x`, there exists a continuous\nlinear form `g` of norm `1` with `g x = \u2225x\u2225` (where the norm has to be interpreted as an element\nof `\ud835\udd5c`).\n\n-/\n\nuniverses u v\n\nnamespace real\nvariables {E : Type*} [semi_normed_group E] [semi_normed_space \u211d E]\n\n/-- Hahn-Banach theorem for continuous linear functions over `\u211d`. -/\ntheorem exists_extension_norm_eq (p : subspace \u211d E) (f : p \u2192L[\u211d] \u211d) :\n  \u2203 g : E \u2192L[\u211d] \u211d, (\u2200 x : p, g x = f x) \u2227 \u2225g\u2225 = \u2225f\u2225 :=\nbegin\n  rcases exists_extension_of_le_sublinear \u27e8p, f\u27e9 (\u03bb x, \u2225f\u2225 * \u2225x\u2225)\n    (\u03bb c hc x, by simp only [norm_smul c x, real.norm_eq_abs, abs_of_pos hc, mul_left_comm])\n    (\u03bb x y, _) (\u03bb x, le_trans (le_abs_self _) (f.le_op_norm _))\n    with \u27e8g, g_eq, g_le\u27e9,\n  set g' := g.mk_continuous (\u2225f\u2225)\n    (\u03bb x, abs_le.2 \u27e8neg_le.1 $ g.map_neg x \u25b8 norm_neg x \u25b8 g_le (-x), g_le x\u27e9),\n  { refine \u27e8g', g_eq, _\u27e9,\n    { apply le_antisymm (g.mk_continuous_norm_le (norm_nonneg f) _),\n      refine f.op_norm_le_bound (norm_nonneg _) (\u03bb x, _),\n      dsimp at g_eq,\n      rw \u2190 g_eq,\n      apply g'.le_op_norm } },\n  { simp only [\u2190 mul_add],\n    exact mul_le_mul_of_nonneg_left (norm_add_le x y) (norm_nonneg f) }\nend\n\nend real\n\nsection is_R_or_C\nopen is_R_or_C\n\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {F : Type*} [semi_normed_group F] [semi_normed_space \ud835\udd5c F]\n\n/-- Hahn-Banach theorem for continuous linear functions over `\ud835\udd5c` satisyfing `is_R_or_C \ud835\udd5c`. -/\ntheorem exists_extension_norm_eq (p : subspace \ud835\udd5c F) (f : p \u2192L[\ud835\udd5c] \ud835\udd5c) :\n  \u2203 g : F \u2192L[\ud835\udd5c] \ud835\udd5c, (\u2200 x : p, g x = f x) \u2227 \u2225g\u2225 = \u2225f\u2225 :=\nbegin\n  letI : module \u211d F := restrict_scalars.module \u211d \ud835\udd5c F,\n  letI : is_scalar_tower \u211d \ud835\udd5c F := restrict_scalars.is_scalar_tower _ _ _,\n  letI : semi_normed_space \u211d F := semi_normed_space.restrict_scalars _ \ud835\udd5c _,\n  -- Let `fr: p \u2192L[\u211d] \u211d` be the real part of `f`.\n  let fr := re_clm.comp (f.restrict_scalars \u211d),\n  have fr_apply : \u2200 x, fr x = re (f x), by { assume x, refl },\n  -- Use the real version to get a norm-preserving extension of `fr`, which\n  -- we'll call `g : F \u2192L[\u211d] \u211d`.\n  rcases real.exists_extension_norm_eq (p.restrict_scalars \u211d) fr with \u27e8g, \u27e8hextends, hnormeq\u27e9\u27e9,\n  -- Now `g` can be extended to the `F \u2192L[\ud835\udd5c] \ud835\udd5c` we need.\n  refine \u27e8g.extend_to_\ud835\udd5c, _\u27e9,\n  -- It is an extension of `f`.\n  have h : \u2200 x : p, g.extend_to_\ud835\udd5c x = f x,\n  { assume x,\n    rw [continuous_linear_map.extend_to_\ud835\udd5c_apply, \u2190submodule.coe_smul, hextends, hextends],\n    have : (fr x : \ud835\udd5c) - I * \u2191(fr (I \u2022 x)) = (re (f x) : \ud835\udd5c) - (I : \ud835\udd5c) * (re (f ((I : \ud835\udd5c) \u2022 x))),\n      by refl,\n    rw this,\n    apply ext,\n    { simp only [add_zero, algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add,\n        zero_sub, I_im', zero_mul, of_real_re, eq_self_iff_true, sub_zero, mul_neg_eq_neg_mul_symm,\n        of_real_neg, mul_re, mul_zero, sub_neg_eq_add, continuous_linear_map.map_smul] },\n    { simp only [algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add, zero_sub, I_im',\n        zero_mul, of_real_re, mul_neg_eq_neg_mul_symm, mul_im, zero_add, of_real_neg, mul_re,\n        sub_neg_eq_add, continuous_linear_map.map_smul] } },\n  -- And we derive the equality of the norms by bounding on both sides.\n  refine \u27e8h, le_antisymm _ _\u27e9,\n  { calc \u2225g.extend_to_\ud835\udd5c\u2225\n        \u2264 \u2225g\u2225 : g.extend_to_\ud835\udd5c.op_norm_le_bound g.op_norm_nonneg (norm_bound _)\n    ... = \u2225fr\u2225 : hnormeq\n    ... \u2264 \u2225re_clm\u2225 * \u2225f\u2225 : continuous_linear_map.op_norm_comp_le _ _\n    ... = \u2225f\u2225 : by rw [re_clm_norm, one_mul] },\n  { exact f.op_norm_le_bound g.extend_to_\ud835\udd5c.op_norm_nonneg (\u03bb x, h x \u25b8 g.extend_to_\ud835\udd5c.le_op_norm x) }\nend\n\nend is_R_or_C\n\nsection dual_vector\nvariables (\ud835\udd5c : Type v) [is_R_or_C \ud835\udd5c]\nvariables {E : Type u} [normed_group E] [normed_space \ud835\udd5c E]\n\nopen continuous_linear_equiv submodule\nopen_locale classical\n\nlemma coord_norm' {x : E} (h : x \u2260 0) : \u2225(\u2225x\u2225 : \ud835\udd5c) \u2022 coord \ud835\udd5c x h\u2225 = 1 :=\nby rw [norm_smul, is_R_or_C.norm_coe_norm, coord_norm, mul_inv_cancel (mt norm_eq_zero.mp h)]\n\n/-- Corollary of Hahn-Banach.  Given a nonzero element `x` of a normed space, there exists an\n    element of the dual space, of norm `1`, whose value on `x` is `\u2225x\u2225`. -/\ntheorem exists_dual_vector (x : E) (h : x \u2260 0) : \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 = 1 \u2227 g x = \u2225x\u2225 :=\nbegin\n  let p : submodule \ud835\udd5c E := \ud835\udd5c \u2219 x,\n  let f := (\u2225x\u2225 : \ud835\udd5c) \u2022 coord \ud835\udd5c x h,\n  obtain \u27e8g, hg\u27e9 := exists_extension_norm_eq p f,\n  refine \u27e8g, _, _\u27e9,\n  { rw [hg.2, coord_norm'] },\n  { calc g x = g (\u27e8x, mem_span_singleton_self x\u27e9 : \ud835\udd5c \u2219 x) : by rw coe_mk\n    ... = ((\u2225x\u2225 : \ud835\udd5c) \u2022 coord \ud835\udd5c x h) (\u27e8x, mem_span_singleton_self x\u27e9 : \ud835\udd5c \u2219 x) : by rw \u2190 hg.1\n    ... = \u2225x\u2225 : by simp }\nend\n\n/-- Variant of Hahn-Banach, eliminating the hypothesis that `x` be nonzero, and choosing\n    the dual element arbitrarily when `x = 0`. -/\ntheorem exists_dual_vector' [nontrivial E] (x : E) :\n  \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 = 1 \u2227 g x = \u2225x\u2225 :=\nbegin\n  by_cases hx : x = 0,\n  { obtain \u27e8y, hy\u27e9 := exists_ne (0 : E),\n    obtain \u27e8g, hg\u27e9 : \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 = 1 \u2227 g y = \u2225y\u2225 := exists_dual_vector \ud835\udd5c y hy,\n    refine \u27e8g, hg.left, _\u27e9,\n    simp [hx] },\n  { exact exists_dual_vector \ud835\udd5c x hx }\nend\n\n/-- Variant of Hahn-Banach, eliminating the hypothesis that `x` be nonzero, but only ensuring that\n    the dual element has norm at most `1` (this can not be improved for the trivial\n    vector space). -/\ntheorem exists_dual_vector'' (x : E) :\n  \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 \u2264 1 \u2227 g x = \u2225x\u2225 :=\nbegin\n  by_cases hx : x = 0,\n  { refine \u27e80, by simp, _\u27e9,\n    symmetry,\n    simp [hx], },\n  { rcases exists_dual_vector \ud835\udd5c x hx with \u27e8g, g_norm, g_eq\u27e9,\n    exact \u27e8g, g_norm.le, g_eq\u27e9 }\nend\n\nend dual_vector\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/normed_space/hahn_banach.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7279121484827359}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning, Patrick Lutz\n-/\n\nimport group_theory.perm.cycle_type\nimport analysis.complex.polynomial\nimport field_theory.galois\n\n/-!\n# Galois Groups of Polynomials\n\nIn this file, we introduce the Galois group of a polynomial `p` over a field `F`,\ndefined as the automorphism group of its splitting field. We also provide\nsome results about some extension `E` above `p.splitting_field`, and some specific\nresults about the Galois groups of \u211a-polynomials with specific numbers of non-real roots.\n\n## Main definitions\n\n- `polynomial.gal p`: the Galois group of a polynomial p.\n- `polynomial.gal.restrict p E`: the restriction homomorphism `(E \u2243\u2090[F] E) \u2192 gal p`.\n- `polynomial.gal.gal_action p E`: the action of `gal p` on the roots of `p` in `E`.\n\n## Main results\n\n- `polynomial.gal.restrict_smul`: `restrict p E` is compatible with `gal_action p E`.\n- `polynomial.gal.gal_action_hom_injective`: `gal p` acting on the roots of `p` in `E` is faithful.\n- `polynomial.gal.restrict_prod_injective`: `gal (p * q)` embeds as a subgroup of `gal p \u00d7 gal q`.\n- `polynomial.gal.card_of_separable`: For a separable polynomial, its Galois group has cardinality\nequal to the dimension of its splitting field over `F`.\n- `polynomial.gal.gal_action_hom_bijective_of_prime_degree`:\nAn irreducible polynomial of prime degree with two non-real roots has full Galois group.\n\n## Other results\n- `polynomial.gal.card_complex_roots_eq_card_real_add_card_not_gal_inv`: The number of complex roots\nequals the number of real roots plus the number of roots not fixed by complex conjugation\n(i.e. with some imaginary component).\n\n-/\n\nnoncomputable theory\nopen_locale classical polynomial\n\nopen finite_dimensional\n\nnamespace polynomial\n\nvariables {F : Type*} [field F] (p q : F[X]) (E : Type*) [field E] [algebra F E]\n\n/-- The Galois group of a polynomial. -/\n@[derive [group, fintype]]\ndef gal := p.splitting_field \u2243\u2090[F] p.splitting_field\n\nnamespace gal\n\ninstance : has_coe_to_fun p.gal (\u03bb _, p.splitting_field \u2192 p.splitting_field) :=\nalg_equiv.has_coe_to_fun\n\n@[ext] lemma ext {\u03c3 \u03c4 : p.gal} (h : \u2200 x \u2208 p.root_set p.splitting_field, \u03c3 x = \u03c4 x) : \u03c3 = \u03c4 :=\nbegin\n  refine alg_equiv.ext (\u03bb x, (alg_hom.mem_equalizer \u03c3.to_alg_hom \u03c4.to_alg_hom x).mp\n      ((set_like.ext_iff.mp _ x).mpr algebra.mem_top)),\n  rwa [eq_top_iff, \u2190splitting_field.adjoin_roots, algebra.adjoin_le_iff],\nend\n\n/-- If `p` splits in `F` then the `p.gal` is trivial. -/\ndef unique_gal_of_splits (h : p.splits (ring_hom.id F)) : unique p.gal :=\n{ default := 1,\n  uniq := \u03bb f, alg_equiv.ext (\u03bb x, by { obtain \u27e8y, rfl\u27e9 := algebra.mem_bot.mp\n    ((set_like.ext_iff.mp ((is_splitting_field.splits_iff _ p).mp h) x).mp algebra.mem_top),\n    rw [alg_equiv.commutes, alg_equiv.commutes] }) }\n\ninstance [h : fact (p.splits (ring_hom.id F))] : unique p.gal :=\nunique_gal_of_splits _ (h.1)\n\ninstance unique_gal_zero : unique (0 : F[X]).gal :=\nunique_gal_of_splits _ (splits_zero _)\n\ninstance unique_gal_one : unique (1 : F[X]).gal :=\nunique_gal_of_splits _ (splits_one _)\n\ninstance unique_gal_C (x : F) : unique (C x).gal :=\nunique_gal_of_splits _ (splits_C _ _)\n\ninstance unique_gal_X : unique (X : F[X]).gal :=\nunique_gal_of_splits _ (splits_X _)\n\ninstance unique_gal_X_sub_C (x : F) : unique (X - C x).gal :=\nunique_gal_of_splits _ (splits_X_sub_C _)\n\ninstance unique_gal_X_pow (n : \u2115) : unique (X ^ n : F[X]).gal :=\nunique_gal_of_splits _ (splits_X_pow _ _)\n\ninstance [h : fact (p.splits (algebra_map F E))] : algebra p.splitting_field E :=\n(is_splitting_field.lift p.splitting_field p h.1).to_ring_hom.to_algebra\n\ninstance [h : fact (p.splits (algebra_map F E))] : is_scalar_tower F p.splitting_field E :=\nis_scalar_tower.of_algebra_map_eq\n  (\u03bb x, ((is_splitting_field.lift p.splitting_field p h.1).commutes x).symm)\n\n-- The `algebra p.splitting_field E` instance above behaves badly when\n-- `E := p.splitting_field`, since it may result in a unification problem\n-- `is_splitting_field.lift.to_ring_hom.to_algebra =?= algebra.id`,\n-- which takes an extremely long time to resolve, causing timeouts.\n-- Since we don't really care about this definition, marking it as irreducible\n-- causes that unification to error out early.\nattribute [irreducible] gal.algebra\n\n/-- Restrict from a superfield automorphism into a member of `gal p`. -/\ndef restrict [fact (p.splits (algebra_map F E))] : (E \u2243\u2090[F] E) \u2192* p.gal :=\nalg_equiv.restrict_normal_hom p.splitting_field\n\nlemma restrict_surjective [fact (p.splits (algebra_map F E))] [normal F E] :\n  function.surjective (restrict p E) :=\nalg_equiv.restrict_normal_hom_surjective E\n\nsection roots_action\n\n/-- The function taking `roots p p.splitting_field` to `roots p E`. This is actually a bijection,\nsee `polynomial.gal.map_roots_bijective`. -/\ndef map_roots [fact (p.splits (algebra_map F E))] :\n  root_set p p.splitting_field \u2192 root_set p E :=\n\u03bb x, \u27e8is_scalar_tower.to_alg_hom F p.splitting_field E x, begin\n  have key := subtype.mem x,\n  by_cases p = 0,\n  { simp only [h, root_set_zero] at key,\n    exact false.rec _ key },\n  { rw [mem_root_set h, aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end\u27e9\n\nlemma map_roots_bijective [h : fact (p.splits (algebra_map F E))] :\n  function.bijective (map_roots p E) :=\nbegin\n  split,\n  { exact \u03bb _ _ h, subtype.ext (ring_hom.injective _ (subtype.ext_iff.mp h)) },\n  { intro y,\n    -- this is just an equality of two different ways to write the roots of `p` as an `E`-polynomial\n    have key := roots_map\n      (is_scalar_tower.to_alg_hom F p.splitting_field E : p.splitting_field \u2192+* E)\n      ((splits_id_iff_splits _).mpr (is_splitting_field.splits p.splitting_field p)),\n    rw [map_map, alg_hom.comp_algebra_map] at key,\n    have hy := subtype.mem y,\n    simp only [root_set, finset.mem_coe, multiset.mem_to_finset, key, multiset.mem_map] at hy,\n    rcases hy with \u27e8x, hx1, hx2\u27e9,\n    exact \u27e8\u27e8x, multiset.mem_to_finset.mpr hx1\u27e9, subtype.ext hx2\u27e9 }\nend\n\n/-- The bijection between `root_set p p.splitting_field` and `root_set p E`. -/\ndef roots_equiv_roots [fact (p.splits (algebra_map F E))] :\n  (root_set p p.splitting_field) \u2243 (root_set p E) :=\nequiv.of_bijective (map_roots p E) (map_roots_bijective p E)\n\ninstance gal_action_aux : mul_action p.gal (root_set p p.splitting_field) :=\n{ smul := \u03bb \u03d5 x, \u27e8\u03d5 x, begin\n    have key := subtype.mem x,\n    --simp only [root_set, finset.mem_coe, multiset.mem_to_finset] at *,\n    by_cases p = 0,\n    { simp only [h, root_set_zero] at key,\n      exact false.rec _ key },\n    { rw mem_root_set h,\n      change aeval (\u03d5.to_alg_hom x) p = 0,\n      rw [aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end\u27e9,\n  one_smul := \u03bb _, by { ext, refl },\n  mul_smul := \u03bb _ _ _, by { ext, refl } }\n\n/-- The action of `gal p` on the roots of `p` in `E`. -/\ninstance gal_action [fact (p.splits (algebra_map F E))] : mul_action p.gal (root_set p E) :=\n{ smul := \u03bb \u03d5 x, roots_equiv_roots p E (\u03d5 \u2022 ((roots_equiv_roots p E).symm x)),\n  one_smul := \u03bb _, by simp only [equiv.apply_symm_apply, one_smul],\n  mul_smul := \u03bb _ _ _, by simp only [equiv.apply_symm_apply, equiv.symm_apply_apply, mul_smul] }\n\nvariables {p E}\n\n/-- `polynomial.gal.restrict p E` is compatible with `polynomial.gal.gal_action p E`. -/\n@[simp] lemma restrict_smul [fact (p.splits (algebra_map F E))]\n  (\u03d5 : E \u2243\u2090[F] E) (x : root_set p E) : \u2191((restrict p E \u03d5) \u2022 x) = \u03d5 x :=\nbegin\n  let \u03c8 := alg_equiv.of_injective_field (is_scalar_tower.to_alg_hom F p.splitting_field E),\n  change \u2191(\u03c8 (\u03c8.symm _)) = \u03d5 x,\n  rw alg_equiv.apply_symm_apply \u03c8,\n  change \u03d5 (roots_equiv_roots p E ((roots_equiv_roots p E).symm x)) = \u03d5 x,\n  rw equiv.apply_symm_apply (roots_equiv_roots p E),\nend\n\nvariables (p E)\n\n/-- `polynomial.gal.gal_action` as a permutation representation -/\ndef gal_action_hom [fact (p.splits (algebra_map F E))] : p.gal \u2192* equiv.perm (root_set p E) :=\n{ to_fun := \u03bb \u03d5, equiv.mk (\u03bb x, \u03d5 \u2022 x) (\u03bb x, \u03d5\u207b\u00b9 \u2022 x)\n  (\u03bb x, inv_smul_smul \u03d5 x) (\u03bb x, smul_inv_smul \u03d5 x),\n  map_one' := by { ext1 x, exact mul_action.one_smul x },\n  map_mul' := \u03bb x y, by { ext1 z, exact mul_action.mul_smul x y z } }\n\nlemma gal_action_hom_restrict [fact (p.splits (algebra_map F E))]\n  (\u03d5 : E \u2243\u2090[F] E) (x : root_set p E) : \u2191(gal_action_hom p E (restrict p E \u03d5) x) = \u03d5 x :=\nrestrict_smul \u03d5 x\n\n/-- `gal p` embeds as a subgroup of permutations of the roots of `p` in `E`. -/\nlemma gal_action_hom_injective [fact (p.splits (algebra_map F E))] :\n  function.injective (gal_action_hom p E) :=\nbegin\n  rw monoid_hom.injective_iff,\n  intros \u03d5 h\u03d5,\n  ext x hx,\n  have key := equiv.perm.ext_iff.mp h\u03d5 (roots_equiv_roots p E \u27e8x, hx\u27e9),\n  change roots_equiv_roots p E (\u03d5 \u2022 (roots_equiv_roots p E).symm\n    (roots_equiv_roots p E \u27e8x, hx\u27e9)) = roots_equiv_roots p E \u27e8x, hx\u27e9 at key,\n  rw equiv.symm_apply_apply at key,\n  exact subtype.ext_iff.mp (equiv.injective (roots_equiv_roots p E) key),\nend\n\nend roots_action\n\nvariables {p q}\n\n/-- `polynomial.gal.restrict`, when both fields are splitting fields of polynomials. -/\ndef restrict_dvd (hpq : p \u2223 q) : q.gal \u2192* p.gal :=\nif hq : q = 0 then 1 else @restrict F _ p _ _ _\n  \u27e8splits_of_splits_of_dvd (algebra_map F q.splitting_field) hq (splitting_field.splits q) hpq\u27e9\n\nlemma restrict_dvd_surjective (hpq : p \u2223 q) (hq : q \u2260 0) :\n  function.surjective (restrict_dvd hpq) :=\nby simp only [restrict_dvd, dif_neg hq, restrict_surjective]\n\nvariables (p q)\n\n/-- The Galois group of a product maps into the product of the Galois groups.  -/\ndef restrict_prod : (p * q).gal \u2192* p.gal \u00d7 q.gal :=\nmonoid_hom.prod (restrict_dvd (dvd_mul_right p q)) (restrict_dvd (dvd_mul_left q p))\n\n/-- `polynomial.gal.restrict_prod` is actually a subgroup embedding. -/\nlemma restrict_prod_injective : function.injective (restrict_prod p q) :=\nbegin\n  by_cases hpq : (p * q) = 0,\n  { haveI : unique (p * q).gal, { rw hpq, apply_instance },\n    exact \u03bb f g h, eq.trans (unique.eq_default f) (unique.eq_default g).symm },\n  intros f g hfg,\n  dsimp only [restrict_prod, restrict_dvd] at hfg,\n  simp only [dif_neg hpq, monoid_hom.prod_apply, prod.mk.inj_iff] at hfg,\n  ext x hx,\n  rw [root_set, map_mul, polynomial.roots_mul] at hx,\n  cases multiset.mem_add.mp (multiset.mem_to_finset.mp hx) with h h,\n  { haveI : fact (p.splits (algebra_map F (p * q).splitting_field)) :=\n      \u27e8splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_right p q)\u27e9,\n    have key : x = algebra_map (p.splitting_field) (p * q).splitting_field\n      ((roots_equiv_roots p _).inv_fun \u27e8x, multiset.mem_to_finset.mpr h\u27e9) :=\n      subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots p _) \u27e8x, _\u27e9).symm,\n    rw [key, \u2190alg_equiv.restrict_normal_commutes, \u2190alg_equiv.restrict_normal_commutes],\n    exact congr_arg _ (alg_equiv.ext_iff.mp hfg.1 _) },\n  { haveI : fact (q.splits (algebra_map F (p * q).splitting_field)) :=\n      \u27e8splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_left q p)\u27e9,\n    have key : x = algebra_map (q.splitting_field) (p * q).splitting_field\n      ((roots_equiv_roots q _).inv_fun \u27e8x, multiset.mem_to_finset.mpr h\u27e9) :=\n      subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots q _) \u27e8x, _\u27e9).symm,\n    rw [key, \u2190alg_equiv.restrict_normal_commutes, \u2190alg_equiv.restrict_normal_commutes],\n    exact congr_arg _ (alg_equiv.ext_iff.mp hfg.2 _) },\n  { rwa [ne.def, mul_eq_zero, map_eq_zero, map_eq_zero, \u2190mul_eq_zero] }\nend\n\n\n\n/-- `p` splits in the splitting field of `p \u2218 q`, for `q` non-constant. -/\nlemma splits_in_splitting_field_of_comp (hq : q.nat_degree \u2260 0) :\n  p.splits (algebra_map F (p.comp q).splitting_field) :=\nbegin\n  let P : F[X] \u2192 Prop := \u03bb r, r.splits (algebra_map F (r.comp q).splitting_field),\n  have key1 : \u2200 {r : F[X]}, irreducible r \u2192 P r,\n  { intros r hr,\n    by_cases hr' : nat_degree r = 0,\n    { exact splits_of_nat_degree_le_one _ (le_trans (le_of_eq hr') zero_le_one) },\n    obtain \u27e8x, hx\u27e9 := exists_root_of_splits _ (splitting_field.splits (r.comp q))\n      (\u03bb h, hr' ((mul_eq_zero.mp (nat_degree_comp.symm.trans\n        (nat_degree_eq_of_degree_eq_some h))).resolve_right hq)),\n    rw [\u2190aeval_def, aeval_comp] at hx,\n    have h_normal : normal F (r.comp q).splitting_field := splitting_field.normal (r.comp q),\n    have qx_int := normal.is_integral h_normal (aeval x q),\n    exact splits_of_splits_of_dvd _\n      (minpoly.ne_zero qx_int)\n      (normal.splits h_normal _)\n      ((minpoly.irreducible qx_int).dvd_symm hr (minpoly.dvd F _ hx)) },\n  have key2 : \u2200 {p\u2081 p\u2082 : F[X]}, P p\u2081 \u2192 P p\u2082 \u2192 P (p\u2081 * p\u2082),\n  { intros p\u2081 p\u2082 hp\u2081 hp\u2082,\n    by_cases h\u2081 : p\u2081.comp q = 0,\n    { cases comp_eq_zero_iff.mp h\u2081 with h h,\n      { rw [h, zero_mul],\n        exact splits_zero _ },\n      { exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },\n    by_cases h\u2082 : p\u2082.comp q = 0,\n    { cases comp_eq_zero_iff.mp h\u2082 with h h,\n      { rw [h, mul_zero],\n        exact splits_zero _ },\n      { exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },\n    have key := mul_splits_in_splitting_field_of_mul h\u2081 h\u2082 hp\u2081 hp\u2082,\n    rwa \u2190 mul_comp at key },\n  exact wf_dvd_monoid.induction_on_irreducible p (splits_zero _)\n    (\u03bb _, splits_of_is_unit _) (\u03bb _ _ _ h, key2 (key1 h)),\nend\n\n/-- `polynomial.gal.restrict` for the composition of polynomials. -/\ndef restrict_comp (hq : q.nat_degree \u2260 0) : (p.comp q).gal \u2192* p.gal :=\n@restrict F _ p _ _ _ \u27e8splits_in_splitting_field_of_comp p q hq\u27e9\n\nlemma restrict_comp_surjective (hq : q.nat_degree \u2260 0) :\n  function.surjective (restrict_comp p q hq) :=\nby simp only [restrict_comp, restrict_surjective]\n\nvariables {p q}\n\n/-- For a separable polynomial, its Galois group has cardinality\nequal to the dimension of its splitting field over `F`. -/\nlemma card_of_separable (hp : p.separable) :\n  fintype.card p.gal = finrank F p.splitting_field :=\nbegin\n  haveI : is_galois F p.splitting_field := is_galois.of_separable_splitting_field hp,\n  exact is_galois.card_aut_eq_finrank F p.splitting_field,\nend\n\nlemma prime_degree_dvd_card [char_zero F] (p_irr : irreducible p) (p_deg : p.nat_degree.prime) :\n  p.nat_degree \u2223 fintype.card p.gal :=\nbegin\n  rw gal.card_of_separable p_irr.separable,\n  have hp : p.degree \u2260 0 :=\n    \u03bb h, nat.prime.ne_zero p_deg (nat_degree_eq_zero_iff_degree_le_zero.mpr (le_of_eq h)),\n  let \u03b1 : p.splitting_field := root_of_splits (algebra_map F p.splitting_field)\n    (splitting_field.splits p) hp,\n  have h\u03b1 : is_integral F \u03b1 := algebra.is_integral_of_finite _ _ \u03b1,\n  use finite_dimensional.finrank F\u27ee\u03b1\u27ef p.splitting_field,\n  suffices : (minpoly F \u03b1).nat_degree = p.nat_degree,\n  { rw [\u2190finite_dimensional.finrank_mul_finrank F F\u27ee\u03b1\u27ef p.splitting_field,\n        intermediate_field.adjoin.finrank h\u03b1, this] },\n  suffices : minpoly F \u03b1 \u2223 p,\n  { have key := (minpoly.irreducible h\u03b1).dvd_symm p_irr this,\n    apply le_antisymm,\n    { exact nat_degree_le_of_dvd this p_irr.ne_zero },\n    { exact nat_degree_le_of_dvd key (minpoly.ne_zero h\u03b1) } },\n  apply minpoly.dvd F \u03b1,\n  rw [aeval_def, map_root_of_splits _ (splitting_field.splits p) hp],\nend\n\nsection rationals\n\nlemma splits_\u211a_\u2102 {p : \u211a[X]} : fact (p.splits (algebra_map \u211a \u2102)) :=\n\u27e8is_alg_closed.splits_codomain p\u27e9\n\nlocal attribute [instance] splits_\u211a_\u2102\n\n/-- The number of complex roots equals the number of real roots plus\n    the number of roots not fixed by complex conjugation (i.e. with some imaginary component). -/\nlemma card_complex_roots_eq_card_real_add_card_not_gal_inv (p : \u211a[X]) :\n  (p.root_set \u2102).to_finset.card = (p.root_set \u211d).to_finset.card +\n  (gal_action_hom p \u2102 (restrict p \u2102 (complex.conj_ae.restrict_scalars \u211a))).support.card :=\nbegin\n  by_cases hp : p = 0,\n  { simp_rw [hp, root_set_zero, set.to_finset_eq_empty_iff.mpr rfl, finset.card_empty, zero_add],\n    refine eq.symm (nat.le_zero_iff.mp ((finset.card_le_univ _).trans (le_of_eq _))),\n    simp_rw [hp, root_set_zero, fintype.card_eq_zero_iff],\n    apply_instance },\n  have inj : function.injective (is_scalar_tower.to_alg_hom \u211a \u211d \u2102) := (algebra_map \u211d \u2102).injective,\n  rw [\u2190finset.card_image_of_injective _ subtype.coe_injective,\n      \u2190finset.card_image_of_injective _ inj],\n  let a : finset \u2102 := _,\n  let b : finset \u2102 := _,\n  let c : finset \u2102 := _,\n  change a.card = b.card + c.card,\n  have ha : \u2200 z : \u2102, z \u2208 a \u2194 aeval z p = 0 :=\n  \u03bb z, by rw [set.mem_to_finset, mem_root_set hp],\n  have hb : \u2200 z : \u2102, z \u2208 b \u2194 aeval z p = 0 \u2227 z.im = 0,\n  { intro z,\n    simp_rw [finset.mem_image, exists_prop, set.mem_to_finset, mem_root_set hp],\n    split,\n    { rintros \u27e8w, hw, rfl\u27e9,\n      exact \u27e8by rw [aeval_alg_hom_apply, hw, alg_hom.map_zero], rfl\u27e9 },\n    { rintros \u27e8hz1, hz2\u27e9,\n      have key : is_scalar_tower.to_alg_hom \u211a \u211d \u2102 z.re = z := by { ext, refl, rw hz2, refl },\n      exact \u27e8z.re, inj (by rwa [\u2190aeval_alg_hom_apply, key, alg_hom.map_zero]), key\u27e9 } },\n  have hc0 : \u2200 w : p.root_set \u2102, gal_action_hom p \u2102\n    (restrict p \u2102 (complex.conj_ae.restrict_scalars \u211a)) w = w \u2194 w.val.im = 0,\n  { intro w,\n    rw [subtype.ext_iff, gal_action_hom_restrict],\n    exact complex.eq_conj_iff_im },\n  have hc : \u2200 z : \u2102, z \u2208 c \u2194 aeval z p = 0 \u2227 z.im \u2260 0,\n  { intro z,\n    simp_rw [finset.mem_image, exists_prop],\n    split,\n    { rintros \u27e8w, hw, rfl\u27e9,\n      exact \u27e8(mem_root_set hp).mp w.2, mt (hc0 w).mpr (equiv.perm.mem_support.mp hw)\u27e9 },\n    { rintros \u27e8hz1, hz2\u27e9,\n      exact \u27e8\u27e8z, (mem_root_set hp).mpr hz1\u27e9,\n        equiv.perm.mem_support.mpr (mt (hc0 _).mp hz2), rfl\u27e9 } },\n  rw \u2190 finset.card_disjoint_union,\n  { apply congr_arg finset.card,\n    simp_rw [finset.ext_iff, finset.mem_union, ha, hb, hc],\n    tauto },\n  { intro z,\n    rw [finset.inf_eq_inter, finset.mem_inter, hb, hc],\n    tauto },\n  { apply_instance },\nend\n\n/-- An irreducible polynomial of prime degree with two non-real roots has full Galois group. -/\nlemma gal_action_hom_bijective_of_prime_degree\n  {p : \u211a[X]} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)\n  (p_roots : fintype.card (p.root_set \u2102) = fintype.card (p.root_set \u211d) + 2) :\n  function.bijective (gal_action_hom p \u2102) :=\nbegin\n  have h1 : fintype.card (p.root_set \u2102) = p.nat_degree,\n  { simp_rw [root_set_def, finset.coe_sort_coe, fintype.card_coe],\n    rw [multiset.to_finset_card_of_nodup, \u2190nat_degree_eq_card_roots],\n    { exact is_alg_closed.splits_codomain p },\n    { exact nodup_roots ((separable_map (algebra_map \u211a \u2102)).mpr p_irr.separable) } },\n  have h2 : fintype.card p.gal = fintype.card (gal_action_hom p \u2102).range :=\n  fintype.card_congr (monoid_hom.of_injective (gal_action_hom_injective p \u2102)).to_equiv,\n  let conj := restrict p \u2102 (complex.conj_ae.restrict_scalars \u211a),\n  refine \u27e8gal_action_hom_injective p \u2102, \u03bb x, (congr_arg (has_mem.mem x)\n    (show (gal_action_hom p \u2102).range = \u22a4, from _)).mpr (subgroup.mem_top x)\u27e9,\n  apply equiv.perm.subgroup_eq_top_of_swap_mem,\n  { rwa h1 },\n  { rw h1,\n    convert prime_degree_dvd_card p_irr p_deg using 1,\n    convert h2.symm },\n  { exact \u27e8conj, rfl\u27e9 },\n  { rw \u2190 equiv.perm.card_support_eq_two,\n    apply nat.add_left_cancel,\n    rw [\u2190p_roots, \u2190set.to_finset_card (root_set p \u211d), \u2190set.to_finset_card (root_set p \u2102)],\n    exact (card_complex_roots_eq_card_real_add_card_not_gal_inv p).symm },\nend\n\n/-- An irreducible polynomial of prime degree with 1-3 non-real roots has full Galois group. -/\nlemma gal_action_hom_bijective_of_prime_degree'\n  {p : \u211a[X]} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)\n  (p_roots1 : fintype.card (p.root_set \u211d) + 1 \u2264 fintype.card (p.root_set \u2102))\n  (p_roots2 : fintype.card (p.root_set \u2102) \u2264 fintype.card (p.root_set \u211d) + 3) :\n  function.bijective (gal_action_hom p \u2102) :=\nbegin\n  apply gal_action_hom_bijective_of_prime_degree p_irr p_deg,\n  let n := (gal_action_hom p \u2102 (restrict p \u2102\n    (complex.conj_ae.restrict_scalars \u211a))).support.card,\n  have hn : 2 \u2223 n :=\n  equiv.perm.two_dvd_card_support (by rw [\u2190monoid_hom.map_pow, \u2190monoid_hom.map_pow,\n    show alg_equiv.restrict_scalars \u211a complex.conj_ae ^ 2 = 1,\n    from alg_equiv.ext complex.conj_conj, monoid_hom.map_one, monoid_hom.map_one]),\n  have key := card_complex_roots_eq_card_real_add_card_not_gal_inv p,\n  simp_rw [set.to_finset_card] at key,\n  rw [key, add_le_add_iff_left] at p_roots1 p_roots2,\n  rw [key, add_right_inj],\n  suffices : \u2200 m : \u2115, 2 \u2223 m \u2192 1 \u2264 m \u2192 m \u2264 3 \u2192 m = 2,\n  { exact this n hn p_roots1 p_roots2 },\n  rintros m \u27e8k, rfl\u27e9 h2 h3,\n  exact le_antisymm (nat.lt_succ_iff.mp (lt_of_le_of_ne h3 (show 2 * k \u2260 2 * 1 + 1,\n    from nat.two_mul_ne_two_mul_add_one))) (nat.succ_le_iff.mpr (lt_of_le_of_ne h2\n    (show 2 * 0 + 1 \u2260 2 * k, from nat.two_mul_ne_two_mul_add_one.symm))),\nend\n\nend rationals\n\nend gal\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/field_theory/polynomial_galois_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7279042784597424}}
{"text": "/-\nCOMP2009-ACE\n\nExercise 03 (Bool)\n\n    This exercise has 2 parts.\n\n    The first part is \"logic chess\" which has slightly different rules\n    than logic poker but see below. The 2nd part ass you to define\n    operations on booleans correspoding to implication and universal \n    quantification and prove it correct.\n\n    Don't worry, if you can't do the universal quantification part. \n    This is intended as a challenge and only counts for 20% of the \n    exercise. \n-/\n\nnamespace ex03\n\ndef bnot : bool \u2192 bool \n| tt := ff\n| ff := tt \n\ndef band : bool \u2192 bool \u2192 bool \n| tt b := b\n| ff b := ff\n\ndef bor : bool \u2192 bool \u2192 bool \n| tt b := tt\n| ff b := b\n\ndef is_tt : bool \u2192 Prop \n| tt := true\n| ff := false\nlocal notation x && y := band x y \nlocal notation x || y := bor x y\n\n/-\nIf you get an error update your lean or use:\nlocal notation x && y := band x y \nlocal notation x || y := bor x y\n-/\n\n\nprefix `!`:90 := bnot\n\n/-\nPART I (60%)\n============\nLogic chess\n\nUnlike logic poker in logic chess there is no guessing. You either\nprove the proposition or you prove its negation, for example if the\nproposition is true, e.g. \n\nchx0) \u2200 x : bool, x=x\n\nthen you just go ahead and prove it -/\n\ntheorem chx0 : \u2200 x : bool, x=x :=\nbegin\n  assume x,\n  reflexivity\nend\n\n/- However, if the proposition is false, e.g.\n\nchx1) \u2200 x : bool, x \u2260 x\n\nthen  you prove its negation -/\n\ntheorem chx1 : \u00ac (\u2200 x : bool, x \u2260 x) :=\nbegin\n  assume h,\n  have g : tt \u2260 tt,\n  apply h,\n  apply g,\n  reflexivity,\nend\n\n/-\nFor each of the following proposition either prove them or their negation.\n\nch01) \u2200 x : bool, ! (! x) = x\nch02) \u2200 x:bool,\u2203 y:bool, x \u2260 y\nch03) \u2203 x:bool,\u2200 y:bool, x \u2260 y\nch04) \u2200 x y : bool, x=y \u2228 x \u2260 y\nch05) \u2203 x:bool, x=bnot x\nch06) \u2200 x y z : bool, x=y \u2228 x=z \u2228 y=z\nch07) \u2200 y:bool, \u2203 x:bool, y = bnot x\nch08) \u2200 x y : bool, ! x = ! y \u2192 x=y\nch09) \u2203 b : bool, \u2200 y:bool, b && y = y\nch10) \u2203 b : bool, \u2200 y:bool, b && y = b\n-/\ntheorem ch01 : \u2200 x : bool, ! (! x) = x :=\nbegin\n    assume x,\n    /-\n        x : bool\n        \u22a2 ! (! x) = x\n    -/\n    cases x,\n    /-\n        (Case tt)\n        \u22a2 ! (! tt) = tt\n    \n        (Case ff)\n        \u22a2 ! (! ff) = ff\n    -/\n    refl,\n    /-\n        Gets rid of Case tt\n    -/\n    refl,\n    /-\n        No goals (Gets rid of Case ff)\n    -/\nend\n\ntheorem ch02 : \u2200 x : bool, \u2203 y : bool, x \u2260 y :=\nbegin\n    assume f,\n    /-\n        f : bool\n        \u22a2 \u2203 y : bool, x \u2260 y\n    -/\n    cases f,\n    /-\n        (Case ff)\n        \u22a2 \u2203 y : bool, ff \u2260 y\n\n        (Case tt)\n        \u22a2 \u2203 y : bool, tt \u2260 y\n    -/\n    existsi tt,\n     /-\n        (Case ff)\n        \u22a2 ff \u2260 tt\n\n        (Case tt)\n        \u22a2 \u2203 y : bool, ff \u2260 y\n    -/\n    assume g,\n    /-\n        (Case ff)\n        g : ff = tt\n        \u22a2 false\n\n        (Case tt)\n        \u22a2 \u2203 y : bool, tt \u2260 y\n    -/\n    contradiction,\n    /-\n        Gets rid of Case ff\n    -/\n    existsi ff,\n    /-\n        (Case ff)\n        \u22a2 \u2203 y : bool, tt \u2260 ff\n    -/\n    assume h,\n    /-\n        (Case ff)\n        h : tt = ff \n        \u22a2 false\n    -/\n    contradiction,\n    /-\n        No goals (Gets rid of Case tt)\nend\n\ntheorem ch03: \u00ac(\u2203 x:bool,\u2200 y:bool, x \u2260 y) :=\nbegin\n    assume x,\n    /-\n        x : \u2203 x:bool,\u2200 y:bool, x \u2260 y\n        \u22a2 false\n    -/\n    cases x with a b,\n    /-\n        a : bool\n        b : \u2200 y:bool, x \u2260 y\n        \u22a2 false\n    -/\n    apply b,\n    /-\n        a : bool\n        b : \u2200 y:bool, x \u2260 y\n        \u22a2 x = ?m_1\n    -/\n    refl,\n    /-\n        No goals\n    -/\nend\n\ntheorem ch04: \u2200 x y : bool, x=y \u2228 x \u2260 y :=\nbegin\n    assume x y,\n    /-\n        x : bool\n        y : bool\n        \u22a2 x=y \u2228 x \u2260 y\n    -/\n    cases x,\n    /-\n        (Case ff)\n        y : bool\n        \u22a2 ff =y \u2228 ff \u2260 y\n\n        (Case tt)\n         y : bool\n        \u22a2 tt =y \u2228 tt \u2260 y\n    -/\n    cases y,\n    /-\n        (Case ff, ff)\n        \u22a2 ff = ff \u2228 ff \u2260 ff\n\n        (Case ff, tt)\n        \u22a2 ff = tt \u2228 ff \u2260 tt\n        \n        (Case tt)\n         y : bool\n        \u22a2 tt =y \u2228 tt \u2260 y\n    -/\n    left,\n    /-\n        (Case ff, ff)\n        \u22a2 ff = ff \n\n        (Case ff, tt)\n        \u22a2 ff = tt \u2228 ff \u2260 tt\n        \n        (Case tt)\n         y : bool\n        \u22a2 tt =y \u2228 tt \u2260 y\n    -/\n    refl,\n    /-\n        Gets rid of Case ff, ff\n    -/\n    right,\n    /-\n        (Case ff, tt)\n        \u22a2 ff \u2260 tt\n        \n        (Case tt)\n        y : bool\n        \u22a2 tt =y \u2228 tt \u2260 y\n    -/  \n    assume a,\n    /-\n        (Case ff, tt)\n        a : ff = tt\n        \u22a2 false\n        \n        (Case tt)\n        y : bool\n        \u22a2 tt =y \u2228 tt \u2260 y\n    -/  \n    contradiction,\n    /-\n        Gets rid of Case ff, tt\n    -/\n    cases y,\n    /-\n        (Case tt, ff)\n        \u22a2 tt = ff \u2228 tt \u2260 ff\n        \n        (Case tt, tt)\n        \u22a2 tt = tt \u2228 tt \u2260 tt\n    -/  \n    right,\n    /-\n        (Case tt, ff)\n        \u22a2 tt \u2260 ff\n        \n        (Case tt, tt)\n        \u22a2 tt = tt \u2228 tt \u2260 tt\n    -/  \n    assume a,\n    /-\n        (Case tt, ff)\n        a : tt = ff\n        \u22a2 false\n        \n        (Case tt, tt)\n        \u22a2 tt = tt \u2228 tt \u2260 tt\n    -/  \n    contradiction,\n    /-\n        Gets rid of Case tt, ff\n    -/\n    left,\n    /-\n        (Case tt, tt)\n        \u22a2 tt = tt \n    -/  \n    refl,\n    /-\n        No goals (Gets rid of Case tt, tt)\n    -/\nend\n\ntheorem ch05: \u00ac (\u2203 x:bool, x=bnot x) :=\nbegin\n    assume x,\n    /-\n        \u2203 x:bool, x=bnot x\n        \u22a2 false\n    -/\n    cases x with a b,\n    /-\n        a : bool\n        b : a = !a\n        \u22a2 false\n    -/\n    cases a,\n    /-\n        (Case ff)\n        b : ff = !ff\n        \u22a2 false\n        \n        (Case tt)\n        b : tt = !tt\n        \u22a2 false\n    -/\n    contradiction,\n    /-\n        Gets rid of Case ff\n    -/\n    contradiction,\n    /-\n        No goals (Gets rid of Case tt)\n    -/\nend\ntheorem ch06: \u2200 x y z : bool, x=y \u2228 x=z \u2228 y=z :=\nbegin\n    assume x y z,\n    /-\n        x y z : bool\n        \u22a2 x=y \u2228 x=z \u2228 y=z\n    -/\n    cases x,\n    /-\n        (Case ff)\n        y z : bool\n        \u22a2 ff = y \u2228 ff = z \u2228 y = z\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    cases y,\n    /-\n        (Case ff, ff)\n        z : bool\n        \u22a2 ff = ff \u2228 ff = z \u2228 ff = z\n\n        (Case ff, tt)\n        z : bool\n        \u22a2 ff = tt \u2228 ff = z \u2228 tt = z\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    left,\n    /-\n        (Case ff, ff)\n        z : bool\n        \u22a2 ff = ff\n\n        (Case ff, tt)\n        z : bool\n        \u22a2 ff = tt \u2228 ff = z \u2228 tt = z\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    refl,\n    /-\n        Gets rid of Case ff, ff\n    -/\n    cases z,\n    /-\n        (Case ff, tt, ff)\n        \u22a2 ff = tt \u2228 ff = ff \u2228 tt = ff\n\n        (Case ff, tt, tt)\n        \u22a2 ff = tt \u2228 ff = tt \u2228 tt = tt\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    right,\n    /-\n        (Case ff, tt, ff)\n        \u22a2 ff = ff \u2228 tt = ff\n\n        (Case ff, tt, tt)\n        \u22a2 ff = tt \u2228 ff = tt \u2228 tt = tt\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    left,\n    /-\n        (Case ff, tt, ff)\n        \u22a2 ff = ff \n\n        (Case ff, tt, tt)\n        \u22a2 ff = tt \u2228 ff = tt \u2228 tt = tt\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    refl,\n    /-\n        Gets rid of Case ff, tt, ff\n    -/\n    right,\n    /-\n        (Case ff, tt, tt)\n        \u22a2 ff = tt \u2228 tt = tt\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    right,\n    /-\n        (Case ff, tt, tt)\n        \u22a2 tt = tt\n\n        (Case tt)\n        y z : bool\n        \u22a2 tt = y \u2228 tt = z \u2228 y = z\n    -/\n    refl,\n    /-\n        Gets rid of Case ff, tt, tt\n    -/\n    cases y,\n    /-\n        (Case tt, ff)\n        z : bool\n        \u22a2 tt = ff \u2228 tt = z \u2228 ff = z\n\n        (Case tt, tt)\n        z : bool\n        \u22a2 tt = tt \u2228 tt = z \u2228 tt = z\n\n    -/\n    cases z,\n    /-\n        (Case tt, ff, ff)\n        \u22a2 tt = ff \u2228 tt = ff \u2228 ff = ff\n\n        (Case tt, ff, tt)\n        \u22a2 tt = ff \u2228 tt = tt \u2228 ff = tt\n\n        (Case tt, tt)\n        z : bool\n        \u22a2 tt = tt \u2228 tt = z \u2228 tt = z\n\n    -/\n    right,\n    /-\n        (Case tt, ff, ff)\n        \u22a2 tt = ff \u2228 ff = ff\n\n        (Case tt, ff, tt)\n        \u22a2 tt = ff \u2228 tt = tt \u2228 ff = tt\n\n        (Case tt, tt)\n        z : bool\n        \u22a2 tt = tt \u2228 tt = z \u2228 tt = z\n\n    -/\n    right,\n    /-\n        (Case tt, ff, ff)\n        \u22a2 ff = ff\n\n        (Case tt, ff, tt)\n        \u22a2 tt = ff \u2228 tt = tt \u2228 ff = tt\n\n        (Case tt, tt)\n        z : bool\n        \u22a2 tt = tt \u2228 tt = z \u2228 tt = z\n\n    -/\n    refl,\n    /-\n        Gets rid of Case tt, ff, ff\n    -/\n    right,\n    /-\n        (Case tt, ff, tt)\n        \u22a2 tt = tt \u2228 ff = tt\n\n        (Case tt, tt)\n        z : bool\n        \u22a2 tt = tt \u2228 tt = z \u2228 tt = z\n\n    -/\n    left,\n    /-\n        (Case tt, ff, tt)\n        \u22a2 tt = tt\n\n        (Case tt, tt)\n        z : bool\n        \u22a2 tt = tt \u2228 tt = z \u2228 tt = z\n    -/\n    refl,\n    /-\n        Gets rid of Case tt, ff, tt\n    -/\n    left,\n    /-\n        (Case tt, tt)\n        z : bool\n        \u22a2 tt = tt\n    -/\n    refl,\n    /-\n        No goals (Case tt, tt)\n    -/\nend\n\ntheorem ch07 : \u2200 y:bool, \u2203 x:bool, y = ! x :=\nbegin\n    assume y,\n    /-\n        y : bool\n        \u22a2 \u2203 x:bool, y = ! x\n    -/\n    cases y,\n    /-\n        (Case ff)\n        \u22a2 \u2203 x:bool, ff = ! x\n    \n        (Case tt)\n        \u22a2 \u2203 x:bool, tt = ! x\n    -/\n    existsi tt,\n    /-\n        (Case ff)\n        ff = !tt\n    \n        (Case tt)\n        \u22a2 \u2203 x:bool, tt = ! x\n    -/\n    refl,\n    /-\n        Gets rid of Case ff\n    -/\n    existsi ff,\n    /-\n        (Case tt)\n        \u22a2 tt = !ff\n    -/\n    refl,\n    /-\n        No goals (gets rid of Case tt)\n    -/\nend\n\ntheorem ch09 : \u2203 b : bool, \u2200 y:bool, b && y = y :=\nbegin\n    existsi tt,\n    /-\n        \u2200 y:bool, tt && y = y\n    -/\n    assume a,\n    /-\n        a : bool,\n        \u22a2 tt && a = a\n    -/\n    refl,\n    /-\n        No goals\n    -/\nend\n\ntheorem ch10: \u2203 b : bool, \u2200 y:bool, b && y = b :=\nbegin\n    existsi ff,\n    /-\n        \u2200 y:bool, ff && y = ff\n    -/\n    assume y,\n    /-\n        y = bool\n        \u22a2 ff && y = ff\n    -/\n    refl,\n    /-\n        No goals\n    -/\nend\n\u22a2\n/- \nPART II (40%)\n=============\n\nDefine operations \n\nimplb :   bool \u2192 bool \u2192 bool \nallb  :   (bool \u2192 bool) \u2192 bool\n\nshow that it corresponds to implication on Prop, i.e. prove\n\ntheorem implb_ok : \u2200 x y : bool , is_tt (implb x y) \u2194 is_tt x \u2192 is_tt y \ntheorem allb_ok : \u2200 f : bool \u2192 bool, is_tt (allb f) \u2194 \u2200 x : bool, is_tt (f x) \n\nRemark: you can define implb by pattern matching or using previous \nboolean operations. In the latter case you need to write\n\ndef implb (x y : bool) := ...\n\nallb can only be defined this way (since there is no pattern matching on \nfunctions), i.e.\n\ndef allb (f : bool \u2192 bool) := ...\n\n(*) the allb part is difficult, you only loose 20% if you don't do it.\n-/\n\nend ex03\n\n", "meta": {"author": "BraxWong", "repo": "lean_Rev", "sha": "c626bda0d38477f95ba4edaf20b9eaa034375c48", "save_path": "github-repos/lean/BraxWong-lean_Rev", "path": "github-repos/lean/BraxWong-lean_Rev/lean_Rev-c626bda0d38477f95ba4edaf20b9eaa034375c48/ex03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7279042731759946}}
{"text": "/-\nCopyright (c) 2021 Tian Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tian Chen\n-/\n\nimport analysis.special_functions.pow\n\n/-!\n# IMO 2001 Q2\n\nLet $a$, $b$, $c$ be positive reals. Prove that\n$$\n\\frac{a}{\\sqrt{a^2 + 8bc}} +\n\\frac{b}{\\sqrt{b^2 + 8ca}} +\n\\frac{c}{\\sqrt{c^2 + 8ab}} \u2265 1.\n$$\n\n## Solution\n\nThis proof is based on the bound\n$$\n\\frac{a}{\\sqrt{a^2 + 8bc}} \u2265\n\\frac{a^{\\frac43}}{a^{\\frac43} + b^{\\frac43} + c^{\\frac43}}.\n$$\n\n-/\n\nopen real\n\nvariables {a b c : \u211d}\n\nlemma denom_pos (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) :\n  0 < a ^ 4 + b ^ 4 + c ^ 4 :=\nadd_pos (add_pos (pow_pos ha 4) (pow_pos hb 4)) (pow_pos hc 4)\n\nlemma bound (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) :\n  a ^ 4 / (a ^ 4 + b ^ 4 + c ^ 4) \u2264\n  a ^ 3 / sqrt ((a ^ 3) ^ 2 + 8 * b ^ 3 * c ^ 3) :=\nbegin\n  have hsqrt := add_pos_of_nonneg_of_pos (sq_nonneg (a ^ 3))\n    (mul_pos (mul_pos (bit0_pos zero_lt_four) (pow_pos hb 3)) (pow_pos hc 3)),\n  have hdenom := denom_pos ha hb hc,\n  rw div_le_div_iff hdenom (sqrt_pos.mpr hsqrt),\n  conv_lhs { rw [pow_succ', mul_assoc] },\n  apply mul_le_mul_of_nonneg_left _ (pow_pos ha 3).le,\n  apply le_of_pow_le_pow _ hdenom.le zero_lt_two,\n  rw [mul_pow, sq_sqrt hsqrt.le, \u2190 sub_nonneg],\n  calc  (a ^ 4 + b ^ 4 + c ^ 4) ^ 2 - a ^ 2 * ((a ^ 3) ^ 2 + 8 * b ^ 3 * c ^ 3)\n      = 2 * (a ^ 2 * (b ^ 2 - c ^ 2)) ^ 2 + (b ^ 4 - c ^ 4) ^ 2 +\n        (2 * (a ^ 2 * b * c - b ^ 2 * c ^ 2)) ^ 2 : by ring\n  ... \u2265 0 : add_nonneg (add_nonneg (mul_nonneg zero_le_two (sq_nonneg _))\n              (sq_nonneg _)) (sq_nonneg _)\nend\n\ntheorem imo2001_q2' (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) :\n  1 \u2264 a ^ 3 / sqrt ((a ^ 3) ^ 2 + 8 * b ^ 3 * c ^ 3) +\n      b ^ 3 / sqrt ((b ^ 3) ^ 2 + 8 * c ^ 3 * a ^ 3) +\n      c ^ 3 / sqrt ((c ^ 3) ^ 2 + 8 * a ^ 3 * b ^ 3) :=\nhave h\u2081 : b ^ 4 + c ^ 4 + a ^ 4 = a ^ 4 + b ^ 4 + c ^ 4,\n  by rw [add_comm, \u2190 add_assoc],\nhave h\u2082 : c ^ 4 + a ^ 4 + b ^ 4 = a ^ 4 + b ^ 4 + c ^ 4,\n  by rw [add_assoc, add_comm],\ncalc _ \u2265 _ : add_le_add (add_le_add (bound ha hb hc) (bound hb hc ha)) (bound hc ha hb)\n   ... = 1 : by rw [h\u2081, h\u2082, \u2190 add_div, \u2190 add_div, div_self $ ne_of_gt $ denom_pos ha hb hc]\n\ntheorem imo2001_q2 (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) :\n  1 \u2264 a / sqrt (a ^ 2 + 8 * b * c) +\n      b / sqrt (b ^ 2 + 8 * c * a) +\n      c / sqrt (c ^ 2 + 8 * a * b) :=\nhave h3 : \u2200 {x : \u211d}, 0 < x \u2192 (x ^ (3 : \u211d)\u207b\u00b9) ^ 3 = x :=\n  \u03bb x hx, show \u21913 = (3 : \u211d), by norm_num \u25b8 rpow_nat_inv_pow_nat hx.le three_ne_zero,\ncalc 1 \u2264 _ : imo2001_q2' (rpow_pos_of_pos ha _) (rpow_pos_of_pos hb _) (rpow_pos_of_pos hc _)\n   ... = _ : by rw [h3 ha, h3 hb, h3 hc]\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2001_q2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7278818229057865}}
{"text": "def dm1 : Prop := \u2200 (A B : Prop), \u00ac (A \u2227 B) \u2194 \u00acA \u2228 \u00acB\n\nexample : dm1 :=\nbegin \nunfold dm1,                 -- unfold definition of dm1\nassume A B,                 -- assume A, B are arbitrary props\napply iff.intro _ _,        -- by iff.intro it will suffice to prove \u2192 in both directions\n/-\nIt's super-important to realize that the proof is *done*\nexcept for the need to provide the two smaller proofs to\nfill those \"holes\" marked by underscores above. You have\nthus reduced the task of proving the overall theorem to \nthe task of proving these two \"lemmas.\" So now we turn to\nthe lemmas.\n-/\n\n-- Lemma 1: The forward implication is valid.\n\nassume h,     -- assume the hypothesis, now show conclusion\n\n-- Prove the conclusion by case analysis on classical \n-- truth/falsity of each of A, B\ncases (classical.em A) with a na,   -- case analysis on truth of A\ncases (classical.em B) with b nb,   -- \"nested\" case analysis on B\n\n/-\nTwo cases for B, assuming A is true\n-/\n\n-- Case A true, B true\n/-\nAt this point you really *have to see* \nthat there is a contradiction in what we\nhave assumed, i.e., in our context. We've  \ngot a proof that neither A or B is true, but\nwe also have proofs that each of A and B is \ntrue. To finish this part of the proof, just\nnot that a and b, we can construct a proof \nof A \u2227 B (by and.intro), yielding a direct\ncontradiction with h.\n-/\nlet ab := and.intro a b,  -- ab proves A \u2227 B\n/-\nThe let construct is just another way to bind\na name to a value in the local context. Note\nthat ab gets added to your context.\n-/\n\n/-\nWhenever you have a direct contradiction, in\nthe form of a proof of \u00acX and a proof of X in\nyour assumptions/context, you can combine them\nto derive a proof of false, by \"applying\" the \nproof of \u00acX (i.e., X \u2192 false) to the proof of \nX, to derive a proof of false. A proof of false\nis an impossibility, which means that the case\nin question can't actually ever happen, so you\nare done with having to think about it. That is\nwhat false elimination does for you: you can \nnow ignore the current goal and be done. \n-/\nlet f := (h ab),\napply false.elim f,\n/-\nLean can automate the previous two steps in\ncases where you have a contradiction in your\ncontext. To see that work, comment out the\nprevious two lines and uncomment the next one.\n-/\n-- contradiction,\n\n\n\n-- Now we turn to the second case: A true, B false\n/-\nLook at the goal: a proof of a disjunction.\nNow look at your context. You have a proof \n(assumed in this case) of the right hand \nside. A simple application of or intro on\nthe right finishes the proof of this case\n(lemma).\n-/\napply or.inr nb,\n\n/-\nNow we address the two cases with \nA false, and B either true or false.\nBefore you read the next sentence look\nhard to make sure you see how to to\nprove it! A simple or introduction \nagain does the trick.\n-/\napply or.inl na,\n\n/-\nWe have now proven the major lemma, \nthat the implication is true in the\nforward direction. That fills in the\nfirst hole in our proof. Now we have\nto construct a proof to fill the second\nhole.\n-/\n\n\n-- REVERSE (You should add the comments here!)\n\n-- B true\nassume h,\ncases h with na nb,\nassume ab,\nlet a := and.elim_left ab,\ncontradiction,\n-- apply na (and.elim_left ab),\n\nassume ab,\nlet b := and.elim_right ab,\ncontradiction,\nend \n\n/-\nFrom the comments we've give and the \nones you added to explain the proof of\nthe implication in the reverse direction,\nyou should be able to write a precise and\ncomplete English language proof.\n-/\n\n\n\n/-\nWe now state and partially prove the second\nDeMorgan law. We prove it in one direction,\nleaving the proof in the reverse direction as\nan exercise. You should also comment the whole\nformal proof as a step towards having a full\nEnglish language proof.\n-/\n\nexample : \u2200 (P Q : Prop), \u00ac(P \u2228 Q) \u2194 \u00acP \u2227 \u00acQ :=\nbegin\nassume P Q,\napply iff.intro _ _,\n\n\n-- FORWARD\n\nassume h,\napply or.elim (classical.em P),\n\n-- Case P true\nassume p,\nlet porq : P \u2228 Q := or.inl p, -- new\ncontradiction,\n\n-- Case P false\nassume np,\n\napply or.elim (classical.em Q),\n\nassume q,\nlet porq : P \u2228 Q := or.inr q,\ncontradiction,\n\n/-\nYou should be able to finish\nthis proof by yourself without\nmuch difficulty at all.\n-/\n\n\nend ", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/examples/04_DeMorgan_Practice/demorgan.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7277466403989543}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport data.real.basic\nimport data.set.disjointed\nimport data.set.intervals\nimport set_theory.cardinal\n/-!\nProof that a cube (in dimension n \u2265 3) cannot be cubed:\nThere does not exist a partition of a cube into finitely many smaller cubes (at least two)\nof different sizes.\n\nWe follow the proof described here:\nhttp://www.alaricstephen.com/main-featured/2017/9/28/cubing-a-cube-proof\n-/\n\n\nopen real set function fin\n\nnoncomputable theory\n\nvariable {n : \u2115}\n\n/-- Given three intervals `I, J, K` such that `J \u2282 I`,\n  neither endpoint of `J` coincides with an endpoint of `I`, `\u00ac (K \u2286 J)` and\n  `K` does not lie completely to the left nor completely to the right of `J`.\n  Then `I \u2229 K \\ J` is nonempty. -/\nlemma Ico_lemma {\u03b1} [linear_order \u03b1] {x\u2081 x\u2082 y\u2081 y\u2082 z\u2081 z\u2082 w : \u03b1}\n  (h\u2081 : x\u2081 < y\u2081) (hy : y\u2081 < y\u2082) (h\u2082 : y\u2082 < x\u2082)\n  (hz\u2081 : z\u2081 \u2264 y\u2082) (hz\u2082 : y\u2081 \u2264 z\u2082) (hw : w \u2209 Ico y\u2081 y\u2082 \u2227 w \u2208 Ico z\u2081 z\u2082) :\n  \u2203w, w \u2208 Ico x\u2081 x\u2082 \u2227 w \u2209 Ico y\u2081 y\u2082 \u2227 w \u2208 Ico z\u2081 z\u2082 :=\nbegin\n  simp only [not_and, not_lt, mem_Ico] at hw,\n  refine \u27e8max x\u2081 (min w y\u2082), _, _, _\u27e9,\n  { simp [le_refl, lt_trans h\u2081 (lt_trans hy h\u2082), h\u2082] },\n  { simp [hw, lt_irrefl, not_le_of_lt h\u2081] {contextual := tt} },\n  { simp [hw.2.1, hw.2.2, hz\u2081, lt_of_lt_of_le h\u2081 hz\u2082] at \u22a2 }\nend\n\n/-- A (hyper)-cube (in standard orientation) is a vector `b` consisting of the bottom-left point\nof the cube, a width `w` and a proof that `w > 0`. We use functions from `fin n` to denote vectors.\n-/\nstructure cube (n : \u2115) : Type :=\n(b : fin n \u2192 \u211d) -- bottom-left coordinate\n(w : \u211d) -- width\n(hw : 0 < w)\n\nnamespace cube\nlemma hw' (c : cube n) : 0 \u2264 c.w := le_of_lt c.hw\n\n/-- The j-th side of a cube is the half-open interval `[b j, b j + w)` -/\ndef side (c : cube n) (j : fin n) : set \u211d :=\nIco (c.b j) (c.b j + c.w)\n\n@[simp] lemma b_mem_side (c : cube n) (j : fin n) : c.b j \u2208 c.side j :=\nby simp [side, cube.hw, le_refl]\n\ndef to_set (c : cube n) : set (fin n \u2192 \u211d) :=\n{ x | \u2200j, x j \u2208 side c j }\n\ndef to_set_subset {c c' : cube n} : c.to_set \u2286 c'.to_set \u2194 \u2200j, c.side j \u2286 c'.side j :=\nbegin\n  split, intros h j x hx,\n  let f : fin n \u2192 \u211d := \u03bb j', if j' = j then x else c.b j',\n  have : f \u2208 c.to_set,\n  { intro j', by_cases hj' : j' = j; simp [f, hj', if_pos, if_neg, hx] },\n  convert h this j, { simp [f, if_pos] },\n  intros h f hf j, exact h j (hf j)\nend\n\ndef to_set_disjoint {c c' : cube n} : disjoint c.to_set c'.to_set \u2194\n  \u2203j, disjoint (c.side j) (c'.side j) :=\nbegin\n  split, intros h, classical, by_contra h',\n  simp only [not_disjoint_iff, classical.skolem, not_exists] at h',\n  cases h' with f hf,\n  apply not_disjoint_iff.mpr \u27e8f, _, _\u27e9 h; intro j, exact (hf j).1, exact (hf j).2,\n  rintro \u27e8j, hj\u27e9, rw [set.disjoint_iff], rintros f \u27e8h1f, h2f\u27e9,\n  apply not_disjoint_iff.mpr \u27e8f j, h1f j, h2f j\u27e9 hj\nend\n\nlemma b_mem_to_set (c : cube n) : c.b \u2208 c.to_set :=\nby simp [to_set]\n\nprotected def tail (c : cube (n+1)) : cube n :=\n\u27e8tail c.b, c.w, c.hw\u27e9\n\nlemma side_tail (c : cube (n+1)) (j : fin n) : c.tail.side j = c.side j.succ := rfl\n\ndef bottom (c : cube (n+1)) : set (fin (n+1) \u2192 \u211d) :=\n{ x | x 0 = c.b 0 \u2227 tail x \u2208 c.tail.to_set }\n\nlemma b_mem_bottom (c : cube (n+1)) : c.b \u2208 c.bottom :=\nby simp [bottom, to_set, side, cube.hw, le_refl, cube.tail]\n\ndef xm (c : cube (n+1)) : \u211d :=\nc.b 0 + c.w\n\nlemma b_lt_xm (c : cube (n+1)) : c.b 0 < c.xm := by simp [xm, hw]\nlemma b_ne_xm (c : cube (n+1)) : c.b 0 \u2260 c.xm := ne_of_lt c.b_lt_xm\n\ndef shift_up (c : cube (n+1)) : cube (n+1) :=\n\u27e8cons c.xm $ tail c.b, c.w, c.hw\u27e9\n\n@[simp] lemma tail_shift_up (c : cube (n+1)) : c.shift_up.tail = c.tail :=\nby simp [shift_up, cube.tail]\n\n@[simp] lemma head_shift_up (c : cube (n+1)) : c.shift_up.b 0 = c.xm := rfl\n\ndef unit_cube : cube n :=\n\u27e8\u03bb _, 0, 1, by norm_num\u27e9\n\n@[simp] lemma side_unit_cube {j : fin n} : unit_cube.side j = Ico 0 1 :=\nby norm_num [unit_cube, side]\n\nend cube\nopen cube\n\nvariables {\u03b9 : Type} [fintype \u03b9] {cs : \u03b9 \u2192 cube (n+1)} {i i' : \u03b9}\n\n/-- A finite family of (at least 2) cubes partitioning the unit cube with different sizes -/\ndef correct (cs : \u03b9 \u2192 cube n) : Prop :=\npairwise (disjoint on (cube.to_set \u2218 cs)) \u2227\n(\u22c3(i : \u03b9), (cs i).to_set) = unit_cube.to_set \u2227\ninjective (cube.w \u2218 cs) \u2227\n2 \u2264 cardinal.mk \u03b9 \u2227\n3 \u2264 n\n\nvariable (h : correct cs)\n\ninclude h\nlemma to_set_subset_unit_cube {i} : (cs i).to_set \u2286 unit_cube.to_set :=\nby { rw [\u2190h.2.1], exact subset_Union _ i }\n\nlemma side_subset {i j} : (cs i).side j \u2286 Ico 0 1 :=\nby { have := to_set_subset_unit_cube h, rw [to_set_subset] at this,\n     convert this j, norm_num [unit_cube] }\n\nlemma zero_le_of_mem_side {i j x} (hx : x \u2208 (cs i).side j) : 0 \u2264 x :=\n(side_subset h hx).1\n\nlemma zero_le_of_mem {i p} (hp : p \u2208 (cs i).to_set) (j) : 0 \u2264 p j :=\nzero_le_of_mem_side h (hp j)\n\nlemma zero_le_b {i j} : 0 \u2264 (cs i).b j :=\nzero_le_of_mem h (cs i).b_mem_to_set j\n\nlemma b_add_w_le_one {j} : (cs i).b j + (cs i).w \u2264 1 :=\nby { have := side_subset h, rw [side, Ico_subset_Ico_iff] at this, convert this.2, simp [hw] }\n\n/-- The width of any cube in the partition cannot be 1. -/\nlemma w_ne_one (i : \u03b9) : (cs i).w \u2260 1 :=\nbegin\n  intro hi,\n  have := h.2.2.2.1, rw [cardinal.two_le_iff' i] at this, cases this with i' hi',\n  let p := (cs i').b,\n  have hp : p \u2208 (cs i').to_set := (cs i').b_mem_to_set,\n  have h2p : p \u2208 (cs i).to_set,\n  { intro j, split,\n    transitivity (0 : \u211d),\n    { rw [\u2190add_le_add_iff_right (1 : \u211d)], convert b_add_w_le_one h, rw hi, rw zero_add },\n    apply zero_le_b h, apply lt_of_lt_of_le (side_subset h $ (cs i').b_mem_side j).2,\n    simp [hi, zero_le_b h] },\n  apply not_disjoint_iff.mpr \u27e8p, hp, h2p\u27e9,\n  apply h.1, exact hi'.symm\nend\n\n/-- The top of a cube (which is the bottom of the cube shifted up by its width) must be covered by\n  bottoms of (other) cubes in the family. -/\nlemma shift_up_bottom_subset_bottoms (hc : (cs i).xm \u2260 1) :\n  (cs i).shift_up.bottom \u2286 \u22c3(i : \u03b9), (cs i).bottom :=\nbegin\n  intros p hp, cases hp with hp0 hps, rw [tail_shift_up] at hps,\n  have : p \u2208 (unit_cube : cube (n+1)).to_set,\n  { simp only [to_set, forall_fin_succ, hp0, side_unit_cube, mem_set_of_eq, mem_Ico,\n      head_shift_up], refine \u27e8\u27e8_, _\u27e9, _\u27e9,\n    { rw [\u2190zero_add (0 : \u211d)], apply add_le_add, apply zero_le_b h, apply (cs i).hw' },\n    { exact lt_of_le_of_ne (b_add_w_le_one h) hc },\n    intro j, exact side_subset h (hps j) },\n  rw [\u2190h.2.1] at this, rcases this with \u27e8_, \u27e8i', rfl\u27e9, hi'\u27e9,\n  rw [mem_Union], use i', refine \u27e8_, \u03bb j, hi' j.succ\u27e9,\n  have : i \u2260 i', { rintro rfl, apply not_le_of_lt (hi' 0).2, rw [hp0], refl },\n  have := h.1 i i' this, rw [on_fun, to_set_disjoint, exists_fin_succ] at this,\n  rcases this with h0|\u27e8j, hj\u27e9,\n  rw [hp0], symmetry, apply eq_of_Ico_disjoint h0 (by simp [hw]) _,\n  convert hi' 0, rw [hp0], refl,\n  exfalso, apply not_disjoint_iff.mpr \u27e8tail p j, hps j, hi' j.succ\u27e9 hj\nend\nomit h\n\n/-- A valley is a square on which cubes in the family of cubes are placed, so that the cubes\n  completely cover the valley and none of those cubes is partially outside the square.\n  We also require that no cube on it has the same size as the valley (so that there are at least\n  two cubes on the valley).\n  This is the main concept in the formalization.\n  We prove that the smallest cube on a valley has another valley on the top of it, which\n  gives an infinite sequence of cubes in the partition, which contradicts the finiteness.\n  A valley is characterized by a cube `c` (which is not a cube in the family cs) by considering\n  the bottom face of `c`. -/\ndef valley (cs : \u03b9 \u2192 cube (n+1)) (c : cube (n+1)) : Prop :=\nc.bottom \u2286 (\u22c3(i : \u03b9), (cs i).bottom) \u2227\n(\u2200i, (cs i).b 0 = c.b 0 \u2192 (\u2203x, x \u2208 (cs i).tail.to_set \u2229 c.tail.to_set) \u2192\n  (cs i).tail.to_set \u2286 c.tail.to_set) \u2227\n\u2200(i : \u03b9), (cs i).b 0 = c.b 0 \u2192 (cs i).w \u2260 c.w\n\nvariables {c : cube (n+1)} (v : valley cs c)\n\n/-- The bottom of the unit cube is a valley -/\nlemma valley_unit_cube (h : correct cs) : valley cs unit_cube :=\nbegin\n  refine \u27e8_, _, _\u27e9,\n  { intro v,\n    simp only [bottom, and_imp, mem_Union, mem_set_of_eq],\n    intros h0 hv,\n    have : v \u2208 (unit_cube : cube (n+1)).to_set,\n    { dsimp only [to_set, unit_cube, mem_set_of_eq],\n      rw [forall_fin_succ, h0], split, norm_num [side, unit_cube], exact hv },\n    rw [\u2190h.2.1] at this, rcases this with \u27e8_, \u27e8i, rfl\u27e9, hi\u27e9,\n    use i,\n    split, { apply le_antisymm, rw h0, exact zero_le_b h, exact (hi 0).1 },\n    intro j, exact hi _ },\n  { intros i hi h', rw to_set_subset, intro j, convert side_subset h using 1, simp [side_tail] },\n  { intros i hi, exact w_ne_one h i }\nend\n\n/-- the cubes which lie in the valley `c` -/\ndef bcubes (cs : \u03b9 \u2192 cube (n+1)) (c : cube (n+1)) : set \u03b9 :=\n{ i : \u03b9 | (cs i).b 0 = c.b 0 \u2227 (cs i).tail.to_set \u2286 c.tail.to_set }\n\n/-- A cube which lies on the boundary of a valley in dimension `j` -/\ndef on_boundary (hi : i \u2208 bcubes cs c) (j : fin n) : Prop :=\nc.b j.succ = (cs i).b j.succ \u2228 (cs i).b j.succ + (cs i).w = c.b j.succ + c.w\n\nlemma tail_sub (hi : i \u2208 bcubes cs c) : \u2200j, (cs i).tail.side j \u2286 c.tail.side j :=\nby { rw [\u2190to_set_subset], exact hi.2 }\n\nlemma bottom_mem_side (hi : i \u2208 bcubes cs c) : c.b 0 \u2208 (cs i).side 0 :=\nby { convert b_mem_side (cs i) _ using 1, rw hi.1 }\n\nlemma b_le_b (hi : i \u2208 bcubes cs c) (j : fin n) : c.b j.succ \u2264 (cs i).b j.succ :=\n(tail_sub hi j $ b_mem_side _ _).1\n\nlemma t_le_t (hi : i \u2208 bcubes cs c) (j : fin n) :\n  (cs i).b j.succ + (cs i).w \u2264 c.b j.succ + c.w  :=\nbegin\n  have h' := tail_sub hi j, dsimp only [side] at h', rw [Ico_subset_Ico_iff] at h',\n  exact h'.2, simp [hw]\nend\n\ninclude h v\n/-- Every cube in the valley must be smaller than it -/\nlemma w_lt_w (hi : i \u2208 bcubes cs c) : (cs i).w < c.w :=\nbegin\n  apply lt_of_le_of_ne _ (v.2.2 i hi.1),\n  have j : fin n := \u27e81, nat.le_of_succ_le_succ h.2.2.2.2\u27e9,\n  rw [\u2190add_le_add_iff_left ((cs i).b j.succ)],\n  apply le_trans (t_le_t hi j), rw [add_le_add_iff_right], apply b_le_b hi,\nend\n\nopen cardinal\n/-- There are at least two cubes in a valley -/\nlemma two_le_mk_bcubes : 2 \u2264 cardinal.mk (bcubes cs c) :=\nbegin\n  rw [two_le_iff],\n  rcases v.1 c.b_mem_bottom with \u27e8_, \u27e8i, rfl\u27e9, hi\u27e9,\n  have h2i : i \u2208 bcubes cs c :=\n    \u27e8hi.1.symm, v.2.1 i hi.1.symm \u27e8tail c.b, hi.2, \u03bb j, c.b_mem_side j.succ\u27e9\u27e9,\n  let j : fin (n+1) := \u27e82, h.2.2.2.2\u27e9,\n  have hj : 0 \u2260 j := by { simp only [fin.ext_iff, ne.def], contradiction },\n  let p : fin (n+1) \u2192 \u211d := \u03bb j', if j' = j then c.b j + (cs i).w else c.b j',\n  have hp : p \u2208 c.bottom,\n  { split, { simp only [bottom, p, if_neg hj] },\n    intro j', simp only [tail, side_tail],\n    by_cases hj' : j'.succ = j,\n    { simp [p, -add_comm, if_pos, side, hj', hw', w_lt_w h v h2i] },\n    { simp [p, -add_comm, if_neg hj'] }},\n  rcases v.1 hp with \u27e8_, \u27e8i', rfl\u27e9, hi'\u27e9,\n  have h2i' : i' \u2208 bcubes cs c := \u27e8hi'.1.symm, v.2.1 i' hi'.1.symm \u27e8tail p, hi'.2, hp.2\u27e9\u27e9,\n  refine \u27e8\u27e8i, h2i\u27e9, \u27e8i', h2i'\u27e9, _\u27e9,\n  intro hii', cases congr_arg subtype.val hii',\n  apply not_le_of_lt (hi'.2 \u27e81, nat.le_of_succ_le_succ h.2.2.2.2\u27e9).2,\n  simp only [-add_comm, tail, cube.tail, p],\n  rw [if_pos, add_le_add_iff_right],\n  { exact (hi.2 _).1 },\n  refl\nend\n\n/-- There is a cube in the valley -/\nlemma nonempty_bcubes : (bcubes cs c).nonempty :=\nbegin\n  rw [\u2190set.ne_empty_iff_nonempty], intro h', have := two_le_mk_bcubes h v, rw h' at this,\n  apply not_lt_of_le this, rw mk_emptyc, norm_cast, norm_num\nend\n\n/-- There is a smallest cube in the valley -/\nlemma exists_mi : \u2203(i : \u03b9), i \u2208 bcubes cs c \u2227 \u2200(i' \u2208 bcubes cs c),\n  (cs i).w \u2264 (cs i').w :=\nby simpa\n  using (bcubes cs c).exists_min_image (\u03bb i, (cs i).w) (finite.of_fintype _) (nonempty_bcubes h v)\n\n/-- We let `mi` be the (index for the) smallest cube in the valley `c` -/\ndef mi : \u03b9 := classical.some $ exists_mi h v\n\nvariables {h v}\nlemma mi_mem_bcubes : mi h v \u2208 bcubes cs c :=\n(classical.some_spec $ exists_mi h v).1\n\nlemma mi_minimal (hi : i \u2208 bcubes cs c) : (cs $ mi h v).w \u2264 (cs i).w :=\n(classical.some_spec $ exists_mi h v).2 i hi\n\nlemma mi_strict_minimal (hii' : mi h v \u2260 i) (hi : i \u2208 bcubes cs c) :\n  (cs $ mi h v).w < (cs i).w :=\nby { apply lt_of_le_of_ne (mi_minimal hi), apply h.2.2.1.ne, apply hii' }\n\n/-- The top of `mi` cannot be 1, since there is a larger cube in the valley -/\nlemma mi_xm_ne_one : (cs $ mi h v).xm \u2260 1 :=\nbegin\n  apply ne_of_lt, rcases (two_le_iff' _).mp (two_le_mk_bcubes h v) with \u27e8\u27e8i, hi\u27e9, h2i\u27e9,\n  swap, exact \u27e8mi h v, mi_mem_bcubes\u27e9,\n  apply lt_of_lt_of_le _ (b_add_w_le_one h), exact i, exact 0,\n  rw [xm, mi_mem_bcubes.1, hi.1, _root_.add_lt_add_iff_left],\n  apply mi_strict_minimal _ hi, intro h', apply h2i, rw subtype.ext_iff_val, exact h'\nend\n\n/-- If `mi` lies on the boundary of the valley in dimension j, then this lemma expresses that all\n  other cubes on the same boundary extend further from the boundary.\n  More precisely, there is a j-th coordinate `x : \u211d` in the valley, but not in `mi`,\n  such that every cube that shares a (particular) j-th coordinate with `mi` also contains j-th\n  coordinate `x` -/\nlemma smallest_on_boundary {j} (bi : on_boundary (mi_mem_bcubes : mi h v \u2208 _) j) :\n  \u2203(x : \u211d), x \u2208 c.side j.succ \\ (cs $ mi h v).side j.succ \u2227\n  \u2200{{i'}} (hi' : i' \u2208 bcubes cs c), i' \u2260 mi h v \u2192\n    (cs $ mi h v).b j.succ \u2208 (cs i').side j.succ \u2192 x \u2208 (cs i').side j.succ :=\nbegin\n  let i := mi h v, have hi : i \u2208 bcubes cs c := mi_mem_bcubes,\n  cases bi,\n  { refine \u27e8(cs i).b j.succ + (cs i).w, \u27e8_, _\u27e9, _\u27e9,\n    { simp [side, bi, hw', w_lt_w h v hi] },\n    { intro h', simpa [i, lt_irrefl] using h'.2 },\n    intros i' hi' i'_i h2i', split,\n    apply le_trans h2i'.1, { simp [hw'] },\n    apply lt_of_lt_of_le (add_lt_add_left (mi_strict_minimal i'_i.symm hi') _),\n    simp [bi.symm, b_le_b hi'] },\n  let s := bcubes cs c \\ { i },\n  have hs : s.nonempty,\n  { rcases (two_le_iff' (\u27e8i, hi\u27e9 : bcubes cs c)).mp (two_le_mk_bcubes h v) with \u27e8\u27e8i', hi'\u27e9, h2i'\u27e9,\n    refine \u27e8i', hi', _\u27e9, simp only [mem_singleton_iff], intro h, apply h2i', simp [h] },\n  rcases set.exists_min_image s (w \u2218 cs) (finite.of_fintype _) hs with \u27e8i', \u27e8hi', h2i'\u27e9, h3i'\u27e9,\n  rw [mem_singleton_iff] at h2i',\n  let x := c.b j.succ + c.w - (cs i').w,\n  have hx : x < (cs i).b j.succ,\n  { dsimp only [x], rw [\u2190bi, add_sub_assoc, add_lt_iff_neg_left, sub_lt_zero],\n    apply mi_strict_minimal (ne.symm h2i') hi' },\n  refine \u27e8x, \u27e8_, _\u27e9, _\u27e9,\n  { simp only [side, x, -add_comm, -add_assoc, neg_lt_zero, hw, add_lt_iff_neg_left, and_true,\n      mem_Ico, sub_eq_add_neg],\n    rw [add_assoc, le_add_iff_nonneg_right, \u2190sub_eq_add_neg, sub_nonneg],\n    apply le_of_lt (w_lt_w h v hi') },\n  { simp only [side, not_and_distrib, not_lt, add_comm, not_le, mem_Ico], left, exact hx },\n  intros i'' hi'' h2i'' h3i'', split, swap, apply lt_trans hx h3i''.2,\n  simp only [x], rw [le_sub_iff_add_le],\n  refine le_trans _ (t_le_t hi'' j), rw [add_le_add_iff_left], apply h3i' i'' \u27e8hi'', _\u27e9,\n  simp [mem_singleton, h2i'']\nend\n\nvariables (h v)\n/-- `mi` cannot lie on the boundary of the valley. Otherwise, the cube adjacent to it in the `j`-th\n  direction will intersect one of the neighbouring cubes on the same boundary as `mi`. -/\nlemma mi_not_on_boundary (j : fin n) : \u00acon_boundary (mi_mem_bcubes : mi h v \u2208 _) j :=\nbegin\n  let i := mi h v, have hi : i \u2208 bcubes cs c := mi_mem_bcubes,\n  rcases (two_le_iff' j).mp _ with \u27e8j', hj'\u27e9, swap,\n  { rw [mk_fin, \u2190nat.cast_two, nat_cast_le], apply nat.le_of_succ_le_succ h.2.2.2.2 },\n  intro hj,\n  rcases smallest_on_boundary hj with \u27e8x, \u27e8hx, h2x\u27e9, h3x\u27e9,\n  let p : fin (n+1) \u2192 \u211d := cons (c.b 0) (\u03bb j\u2082, if j\u2082 = j then x else (cs i).b j\u2082.succ),\n  have hp : p \u2208 c.bottom,\n  { suffices : \u2200 (j' : fin n), ite (j' = j) x ((cs i).b j'.succ) \u2208 c.side j'.succ,\n    { simpa [bottom, p, to_set, tail, side_tail] },\n    intro j\u2082,\n    by_cases hj\u2082 : j\u2082 = j, { simp [hj\u2082, hx] },\n    simp only [hj\u2082, if_false], apply tail_sub hi, apply b_mem_side },\n  rcases v.1 hp with \u27e8_, \u27e8i', rfl\u27e9, hi'\u27e9,\n  have h2i' : i' \u2208 bcubes cs c := \u27e8hi'.1.symm, v.2.1 i' hi'.1.symm \u27e8tail p, hi'.2, hp.2\u27e9\u27e9,\n  have i_i' : i \u2260 i', { rintro rfl, simpa [p, side_tail, i, h2x] using hi'.2 j },\n  have : nonempty \u21a5((cs i').tail.side j' \\ (cs i).tail.side j'),\n  { apply nonempty_Ico_sdiff, apply mi_strict_minimal i_i' h2i', apply hw },\n  rcases this with \u27e8\u27e8x', hx'\u27e9\u27e9,\n  let p' : fin (n+1) \u2192 \u211d :=\n  cons (c.b 0) (\u03bb j\u2082, if j\u2082 = j' then x' else (cs i).b j\u2082.succ),\n  have hp' : p' \u2208 c.bottom,\n  { suffices : \u2200 (j : fin n), ite (j = j') x' ((cs i).b j.succ) \u2208 c.side j.succ,\n    { simpa [bottom, p', to_set, tail, side_tail] },\n    intro j\u2082,\n    by_cases hj\u2082 : j\u2082 = j', simp [hj\u2082], apply tail_sub h2i', apply hx'.1,\n    simp only [if_congr, if_false, hj\u2082], apply tail_sub hi, apply b_mem_side },\n  rcases v.1 hp' with \u27e8_, \u27e8i'', rfl\u27e9, hi''\u27e9,\n  have h2i'' : i'' \u2208 bcubes cs c := \u27e8hi''.1.symm, v.2.1 i'' hi''.1.symm \u27e8tail p', hi''.2, hp'.2\u27e9\u27e9,\n  have i'_i'' : i' \u2260 i'',\n  { rintro \u27e8\u27e9,\n    have : (cs i).b \u2208 (cs i').to_set,\n    { simp only [to_set, forall_fin_succ, hi.1, bottom_mem_side h2i', true_and, mem_set_of_eq],\n    intro j\u2082, by_cases hj\u2082 : j\u2082 = j,\n    { simpa [side_tail, p', hj', hj\u2082] using hi''.2 j },\n    { simpa [hj\u2082] using hi'.2 j\u2082 } },\n    apply not_disjoint_iff.mpr \u27e8(cs i).b, (cs i).b_mem_to_set, this\u27e9 (h.1 i i' i_i') },\n  have i_i'' : i \u2260 i'', { intro h, induction h, simpa [hx'.2] using hi''.2 j' },\n  apply not.elim _ (h.1 i' i'' i'_i''),\n  simp only [on_fun, to_set_disjoint, not_disjoint_iff, forall_fin_succ, not_exists, comp_app],\n  refine \u27e8\u27e8c.b 0, bottom_mem_side h2i', bottom_mem_side h2i''\u27e9, _\u27e9,\n  intro j\u2082,\n  by_cases hj\u2082 : j\u2082 = j,\n  { cases hj\u2082, refine \u27e8x, _, _\u27e9,\n    { convert hi'.2 j, simp [p] },\n    apply h3x h2i'' i_i''.symm, convert hi''.2 j, simp [p', hj'] },\n  by_cases h2j\u2082 : j\u2082 = j',\n  { cases h2j\u2082, refine \u27e8x', hx'.1, _\u27e9, convert hi''.2 j', simp },\n  refine \u27e8(cs i).b j\u2082.succ, _, _\u27e9,\n  { convert hi'.2 j\u2082, simp [hj\u2082] },\n  { convert hi''.2 j\u2082, simp [h2j\u2082] }\nend\n\nvariables {h v}\n/-- The same result that `mi` cannot lie on the boundary of the valley written as inequalities. -/\nlemma mi_not_on_boundary' (j : fin n) : c.tail.b j < (cs (mi h v)).tail.b j \u2227\n  (cs (mi h v)).tail.b j + (cs (mi h v)).w < c.tail.b j + c.w :=\nbegin\n  have := mi_not_on_boundary h v j,\n  simp only [on_boundary, not_or_distrib] at this, cases this with h1 h2,\n  split,\n  apply lt_of_le_of_ne (b_le_b mi_mem_bcubes _) h1,\n  apply lt_of_le_of_ne _ h2,\n  apply ((Ico_subset_Ico_iff _).mp (tail_sub mi_mem_bcubes j)).2,\n  simp [hw]\nend\n\n/-- The top of `mi` gives rise to a new valley, since the neighbouring cubes extend further upward\n  than `mi`. -/\ndef valley_mi : valley cs ((cs (mi h v)).shift_up) :=\nbegin\n  let i := mi h v, have hi : i \u2208 bcubes cs c := mi_mem_bcubes,\n  refine \u27e8_, _, _\u27e9,\n  { intro p, apply shift_up_bottom_subset_bottoms h mi_xm_ne_one },\n  { rintros i' hi' \u27e8p2, hp2, h2p2\u27e9, simp only [head_shift_up] at hi', classical, by_contra h2i',\n    rw [tail_shift_up] at h2p2, simp only [not_subset, tail_shift_up] at h2i',\n    rcases h2i' with \u27e8p1, hp1, h2p1\u27e9,\n    have : \u2203p3, p3 \u2208 (cs i').tail.to_set \u2227 p3 \u2209 (cs i).tail.to_set \u2227 p3 \u2208 c.tail.to_set,\n    { simp only [to_set, not_forall, mem_set_of_eq] at h2p1, cases h2p1 with j hj,\n      rcases Ico_lemma (mi_not_on_boundary' j).1 (by simp [hw]) (mi_not_on_boundary' j).2\n        (le_trans (hp2 j).1 $ le_of_lt (h2p2 j).2)\n        (le_trans (h2p2 j).1 $ le_of_lt (hp2 j).2) \u27e8hj, hp1 j\u27e9 with \u27e8w, hw, h2w, h3w\u27e9,\n      refine \u27e8\u03bb j', if j' = j then w else p2 j', _, _, _\u27e9,\n      { intro j', by_cases h : j' = j,\n        { simp only [if_pos h], convert h3w },\n        { simp only [if_neg h], exact hp2 j' } },\n      { simp only [to_set, not_forall, mem_set_of_eq], use j, rw [if_pos rfl], convert h2w },\n      { intro j', by_cases h : j' = j,\n        { simp only [if_pos h, side_tail], convert hw },\n        { simp only [if_neg h], apply hi.2, apply h2p2 } } },\n    rcases this with \u27e8p3, h1p3, h2p3, h3p3\u27e9,\n    let p := @cons n (\u03bb_, \u211d) (c.b 0) p3,\n    have hp : p \u2208 c.bottom, { refine \u27e8rfl, _\u27e9, rwa [tail_cons] },\n    rcases v.1 hp with \u27e8_, \u27e8i'', rfl\u27e9, hi''\u27e9,\n    have h2i'' : i'' \u2208 bcubes cs c,\n    { use hi''.1.symm, apply v.2.1 i'' hi''.1.symm,\n      use tail p, split, exact hi''.2, rw [tail_cons], exact h3p3 },\n    have h3i'' : (cs i).w < (cs i'').w,\n    { apply mi_strict_minimal _ h2i'', rintro rfl, apply h2p3, convert hi''.2, rw [tail_cons] },\n    let p' := @cons n (\u03bb_, \u211d) (cs i).xm p3,\n    have hp' : p' \u2208 (cs i').to_set,\n    { simpa [to_set, forall_fin_succ, p', hi'.symm] using h1p3 },\n    have h2p' : p' \u2208 (cs i'').to_set,\n    { simp only [to_set, forall_fin_succ, p', cons_succ, cons_zero, mem_set_of_eq],\n      refine \u27e8_, by simpa [to_set, p] using hi''.2\u27e9,\n      have : (cs i).b 0 = (cs i'').b 0, { by rw [hi.1, h2i''.1] },\n      simp [side, hw', xm, this, h3i''] },\n    apply not_disjoint_iff.mpr \u27e8p', hp', h2p'\u27e9,\n    apply h.1, rintro rfl, apply (cs i).b_ne_xm, rw [\u2190hi', \u2190hi''.1, hi.1], refl },\n  { intros i' hi' h2i',\n    dsimp only [shift_up] at h2i',\n    replace h2i' := h.2.2.1 h2i'.symm,\n    induction h2i',\n    exact b_ne_xm (cs i) hi' }\nend\n\nvariables (h)\nomit v\n\n/-- We get a sequence of cubes whose size is decreasing -/\nnoncomputable def sequence_of_cubes : \u2115 \u2192 { i : \u03b9 // valley cs ((cs i).shift_up) }\n| 0     := let v := valley_unit_cube h      in \u27e8mi h v, valley_mi\u27e9\n| (k+1) := let v := (sequence_of_cubes k).2 in \u27e8mi h v, valley_mi\u27e9\n\ndef decreasing_sequence (k : \u2115) : order_dual \u211d :=\n(cs (sequence_of_cubes h k).1).w\n\nlemma strict_mono_sequence_of_cubes : strict_mono $ decreasing_sequence h :=\nstrict_mono.nat $\nbegin\n  intro k, let v := (sequence_of_cubes h k).2, dsimp only [decreasing_sequence, sequence_of_cubes],\n  apply w_lt_w h v (mi_mem_bcubes : mi h v \u2208 _),\nend\n\nomit h\n/-- The infinite sequence of cubes contradicts the finiteness of the family. -/\ntheorem not_correct : \u00accorrect cs :=\nbegin\n  intro h, apply not_le_of_lt (lt_omega_iff_fintype.mpr \u27e8_inst_1\u27e9),\n  rw [omega, lift_id], fapply mk_le_of_injective, exact \u03bb n, (sequence_of_cubes h n).1,\n  intros n m hnm, apply strict_mono.injective (strict_mono_sequence_of_cubes h),\n  dsimp only [decreasing_sequence], rw hnm\nend\n\n/-- A cube cannot be cubed. -/\ntheorem cannot_cube_a_cube :\n  \u2200{n : \u2115}, n \u2265 3 \u2192                              -- In \u211d^n for n \u2265 3\n  \u2200{\u03b9 : Type} [fintype \u03b9] {cs : \u03b9 \u2192 cube n},     -- given a finite collection of (hyper)cubes\n  2 \u2264 cardinal.mk \u03b9 \u2192                            -- containing at least two elements\n  pairwise (disjoint on (cube.to_set \u2218 cs)) \u2192    -- which is pairwise disjoint\n  (\u22c3(i : \u03b9), (cs i).to_set) = unit_cube.to_set \u2192 -- whose union is the unit cube\n  injective (cube.w \u2218 cs) \u2192                      -- such that the widths of all cubes are different\n  false :=                                       -- then we can derive a contradiction\nbegin\n  intros n hn \u03b9 h\u03b9 cs h1 h2 h3 h4, resetI,\n  rcases n, cases hn,\n  exact not_correct \u27e8h2, h3, h4, h1, hn\u27e9\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/100-theorems-list/82_cubing_a_cube.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7277466403989543}}
{"text": "def f (x : Nat) :=\n  open Nat in\n  succ (succ x)\n\ntheorem f_eq : f x = Nat.succ (Nat.succ x) :=\n  rfl\n\ndef g (x : Nat) := open Nat in succ (succ x)\n\ntheorem f_eq_g : f x = g x := rfl\n\ndef h (x : Nat) := Nat.succ (open Nat in succ x)\n\ntheorem f_eq_h : f x = h x := rfl\n\nopen Nat in\ndef h' (x : Nat) := succ x\n\ntheorem ex (x y : Nat) (h : x = y) : x + 1 = y + 1 := by\n  open Nat in show succ x = succ y\n  apply congrArg\n  assumption\n\n\ninductive InductiveWithAVeryLongName where\n  | c1 | c2 | c3 | c4 | c5 | c6 | c7\n\ndef foo (e : InductiveWithAVeryLongName) : Type :=\n  open InductiveWithAVeryLongName in\n  match e with\n    | c1 => Nat\n    | c2 => Nat \u2192 Nat\n    | c3 => Nat \u2192 Nat \u2192 Nat\n    | c4 => Nat \u2192 Nat \u2192 Nat \u2192 Nat\n    | c5 => Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat\n    | c6 => Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat\n    | c7 => Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat \u2192 Nat\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/openTermTactic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005327, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7277228932667177}}
{"text": "import data.nat.basic\nimport data.nat.parity\nimport tactic\n\nopen nat\n-- SOLUTIONS:\n-- There are no exercises in this section.\n/- TEXT:\nOverview\n--------\n\nPut simply, Lean is a tool for building complex expressions in a formal language\nknown as *dependent type theory*.\n\n.. index:: check, commands ; check\n\nEvery expression has a *type*, and you can use the `#check` command to\nprint it.\nSome expressions have types like `\u2115` or `\u2115 \u2192 \u2115`.\nThese are mathematical objects.\nTEXT. -/\n/- These are pieces of data. -/\n\n-- QUOTE:\n#check 2 + 2\n\ndef f (x : \u2115) := x + 3\n\n#check f\n-- QUOTE.\n\n/- TEXT:\nSome expressions have type `Prop`.\nThese are mathematical statements.\nTEXT. -/\n/- These are propositions, of type `Prop`. -/\n\n-- QUOTE:\n#check 2 + 2 = 4\n\ndef fermat_last_theorem :=\n  \u2200 x y z n : \u2115, n > 2 \u2227 x * y * z \u2260 0 \u2192 x^n + y^n \u2260 z^n\n\n#check fermat_last_theorem\n-- QUOTE.\n\n/- TEXT:\nSome expressions have a type, `P`, where `P` itself has type `Prop`.\nSuch an expression is a proof of the proposition `P`.\nTEXT. -/\n/- These are proofs of propositions. -/\n\n-- QUOTE:\ntheorem easy : 2 + 2 = 4 := rfl\n\n#check easy\n\ntheorem hard : fermat_last_theorem := sorry\n\n#check hard\n-- QUOTE.\n\n/- TEXT:\nIf you manage to construct an expression of type `fermat_last_theorem` and\nLean accepts it as a term of that type,\nyou have done something very impressive.\n(Using ``sorry`` is cheating, and Lean knows it.)\nSo now you know the game.\nAll that is left to learn are the rules.\n\nThis book is complementary to a companion tutorial,\n`Theorem Proving in Lean <https://leanprover.github.io/theorem_proving_in_lean/>`_,\nwhich provides a more thorough introduction to the underlying logical framework\nand core syntax of Lean.\n*Theorem Proving in Lean* is for people who prefer to read a user manual cover to cover before\nusing a new dishwasher.\nIf you are the kind of person who prefers to hit the *start* button and\nfigure out how to activate the potscrubber feature later,\nit makes more sense to start here and refer back to\n*Theorem Proving in Lean* as necessary.\n\nAnother thing that distinguishes *Mathematics in Lean* from\n*Theorem Proving in Lean* is that here we place a much greater\nemphasis on the use of *tactics*.\nGiven that we are trying to build complex expressions,\nLean offers two ways of going about it:\nwe can write down the expressions themselves\n(that is, suitable text descriptions thereof),\nor we can provide Lean with *instructions* as to how to construct them.\nFor example, the following expression represents a proof of the fact that\nif ``n`` is even then so is ``m * n``:\nTEXT. -/\n/- Here are some proofs. -/\n\n-- QUOTE:\nexample : \u2200 m n : nat, even n \u2192 even (m * n) :=\nassume m n \u27e8k, (hk : n = k + k)\u27e9,\nhave hmn : m * n = m * k + m * k,\n  by rw [hk, mul_add],\nshow \u2203 l, m * n = l + l,\n  from \u27e8_, hmn\u27e9\n-- QUOTE.\n\n/- TEXT:\nThe *proof term* can be compressed to a single line:\nTEXT. -/\n-- QUOTE:\nexample : \u2200 m n : nat, even n \u2192 even (m * n) :=\n\u03bb m n \u27e8k, hk\u27e9, \u27e8m * k, by rw [hk, mul_add]\u27e9\n-- QUOTE.\n\n/- TEXT:\nThe following is, instead, a *tactic-style* proof of the same theorem:\nTEXT. -/\n-- QUOTE:\nexample : \u2200 m n : nat, even n \u2192 even (m * n) :=\nbegin\n  -- say m and n are natural numbers, and assume n=2*k\n  rintros m n \u27e8k, hk\u27e9,\n  -- We need to prove m*n is twice a natural. Let's show it's twice m*k.\n  use m * k,\n  -- substitute in for n\n  rw hk,\n  -- and now it's obvious\n  ring\nend\n-- QUOTE.\n\n/- TEXT:\nAs you enter each line of such a proof in VS Code,\nLean displays the *proof state* in a separate window,\ntelling you what facts you have already established and what\ntasks remain to prove your theorem.\nYou can replay the proof by stepping through the lines,\nsince Lean will continue to show you the state of the proof\nat the point where the cursor is.\nIn this example, you will then see that\nthe first line of the proof introduces ``m`` and ``n``\n(we could have renamed them at that point, if we wanted to),\nand also decomposes the hypothesis ``even n`` to\na ``k`` and the assumption that ``n = 2 * k``.\nThe second line, ``use m * k``,\ndeclares that we are going to show that ``m * n`` is even by\nshowing ``m * n = 2 * (m * k)``.\nThe next line uses the ``rewrite`` tactic\nto replace ``n`` by ``2 * k`` in the goal,\nand the `ring` tactic solves the resulting goal ``m * (2 * k) = 2 * (m * k)``.\n\nThe ability to build a proof in small steps with incremental feedback\nis extremely powerful. For that reason,\ntactic proofs are often easier and quicker to write than\nproof terms.\nThere isn't a sharp distinction between the two:\ntactic proofs can be inserted in proof terms,\nas we did with the phrase ``by rw [hk, mul_left_comm]`` in the example above.\nWe will also see that, conversely,\nit is often useful to insert a short proof term in the middle of a tactic proof.\nThat said, in this book, our emphasis will be on the use of tactics.\n\nIn our example, the tactic proof can also be reduced to a one-liner:\nTEXT. -/\n-- QUOTE:\nexample : \u2200 m n : nat, even n \u2192 even (m * n) :=\nby { rintros m n \u27e8k, hk\u27e9, use m * k, rw hk, ring }\n-- QUOTE.\n\n/- TEXT:\nHere we have used tactics to carry out small proof steps.\nBut they can also provide substantial automation,\nand justify longer calculations and bigger inferential steps.\nFor example, we can invoke Lean's simplifier with\nspecific rules for simplifying statements about parity to\nprove our theorem automatically.\nTEXT. -/\n-- QUOTE:\nexample : \u2200 m n : nat, even n \u2192 even (m * n) :=\nby intros; simp * with parity_simps\n-- QUOTE.\n\n/- TEXT:\nAnother big difference between the two introductions is that\n*Theorem Proving in Lean* depends only on core Lean and its built-in\ntactics, whereas *Mathematics in Lean* is built on top of Lean's\npowerful and ever-growing library, *mathlib*.\nAs a result, we can show you how to use some of the mathematical\nobjects and theorems in the library,\nand some of the very useful tactics.\nThis book is not meant to be used as an overview of the library;\nthe `community <https://leanprover-community.github.io/>`_\nweb pages contain extensive documentation.\nRather, our goal is to introduce you to the style of thinking that\nunderlies that formalization,\nso that you are comfortable browsing the library and\nfinding things on your own.\n\nInteractive theorem proving can be frustrating,\nand the learning curve is steep.\nBut the Lean community is very welcoming to newcomers,\nand people are available on the\n`Lean Zulip chat group <https://leanprover.zulipchat.com/>`_ round the clock\nto answer questions.\nWe hope to see you there, and have no doubt that\nsoon enough you, too, will be able to answer such questions\nand contribute to the development of *mathlib*.\n\nSo here is your mission, should you choose to accept it:\ndive in, try the exercises, come to Zulip with questions, and have fun.\nBut be forewarned:\ninteractive theorem proving will challenge you to think about\nmathematics and mathematical reasoning in fundamentally new ways.\nYour life may never be the same.\n\n*Acknowledgments.* We are grateful to Gabriel Ebner for setting up the\ninfrastructure for running this tutorial in VS Code.\nWe are also grateful for help from\nBryan Gin-ge Chen, Johan Commelin, Julian K\u00fclshammer, and Guilherme Silva.\nOur work has been partially supported by the Hoskinson Center for\nFormal Mathematics.\nTEXT. -/\n", "meta": {"author": "avigad", "repo": "mathematics_in_lean_source", "sha": "4eeb8c43762522c1acaa7f799599609d6a48f59e", "save_path": "github-repos/lean/avigad-mathematics_in_lean_source", "path": "github-repos/lean/avigad-mathematics_in_lean_source/mathematics_in_lean_source-4eeb8c43762522c1acaa7f799599609d6a48f59e/lean_source/01_Introduction/source_02_Overview.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7277228869539621}}
{"text": "import algebra.group -- for is_add_group_hom\nimport group_theory.subgroup -- for kernels\nimport algebra.module\nimport tactic.linarith\nimport tactic.omega\nimport tactic.fin_cases\nimport add_group_hom.basic\nimport algebra.pi_instances\n\nclass G_module (G : Type*) [group G] (M : Type*) [add_comm_group M]\n  extends  has_scalar G M :=\n(id : \u2200 m : M, (1 : G) \u2022 m = m)\n(mul : \u2200 g h : G, \u2200 m : M, g \u2022 (h \u2022 m) = (g * h) \u2022 m)\n(linear : \u2200 g : G, \u2200 m n : M, g \u2022 (m + n) = g \u2022 m + g \u2022 n)\n\nattribute [simp] G_module.linear G_module.mul\n\n@[simp] lemma G_module.G_neg {G : Type*} [group G] {M : Type*} [add_comm_group M]\n  [G_module G M]\n  (g : G) (m : M) : g \u2022 (-m) = -(g \u2022 m) := \n  begin\n  -- h1: g \u2022 (m+(-m))=(0:M),\n  --norm_num,\n -- have h: g\u2022 (0:M)+g\u2022 (0:M)=g\u2022 ((0:M)+(0:M)),\n  --rw G_module.linear,\n -- rw add_zero at h,\n  --exact add_left_eq_self.mp h,\n  --rw G_module.linear at h1,\n  --have h2:g \u2022 m + g \u2022 -m -(g\u2022 m)= -(g\u2022 m),\n -- exact add_left_eq_self.mpr h1,\n -- have h3:g \u2022 m + g \u2022 -m -(g\u2022 m)= g \u2022 -m,\n -- exact add_sub_cancel' _ _,\n -- exact (eq.congr rfl h2).mp (eq.symm h3),\n have h:g \u2022 -m +g \u2022 m= -(g \u2022 m)+g \u2022 m,\n rw <-G_module.linear,\n norm_num,\n have h: g\u2022 (0:M)+g\u2022 (0:M)=g\u2022 ((0:M)+(0:M)),\n rw G_module.linear,\n rw add_zero at h,\n exact add_left_eq_self.mp h,\n exact (add_right_inj (g \u2022 m)).mp h,\n  end\n\n\nlemma G_module.G_sum_smul {G : Type*} [group G] {M : Type*} [add_comm_group M]\n[G_module G M] (n:\u2115 )(g : G)(f: \u2115 \u2192 M):finset.sum  (finset.range (n+1))(\u03bb (x : \u2115 ), g \u2022 f x) = g \u2022 finset.sum (finset.range(n+1)) f:=\nbegin \ninduction n with d hd,\nnorm_num,\nrw finset.sum_range_succ,\nrw hd,\nrw <-G_module.linear,\nrw <-finset.sum_range_succ _ (d+1),\nend\n\nlemma G_module.neg_one_pow_mul_comm {G : Type*} [group G] {M : Type*} [add_comm_group M]\n[G_module G M] (n:\u2115  )(g:G)(m:M): (-1:\u2124 )^n \u2022 g \u2022 m = g \u2022 (-1:\u2124)^n \u2022 m:=\nbegin\ninduction n with d hd,\nnorm_num,\nrw nat.succ_eq_add_one,\nrw pow_add,\nnorm_num,\nexact hd,\nend", "meta": {"author": "Shenyang1995", "repo": "M4R", "sha": "a6a3399c4d1935b39a22f64c30f293ef2a32fdeb", "save_path": "github-repos/lean/Shenyang1995-M4R", "path": "github-repos/lean/Shenyang1995-M4R/M4R-a6a3399c4d1935b39a22f64c30f293ef2a32fdeb/src/G_module/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7277228806204684}}
{"text": "-- Existencia_de_valor_intermedio.lean\n-- \u2203 x \u2208 \u211d, 2 < x < 3.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 25-noviembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que hay alg\u00fan n\u00famero real entre 2 y 3.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\nbegin\n  have h : 2 < (5 : \u211d) / 2 \u2227 (5 : \u211d) / 2 < 3,\n    by norm_num,\n  show \u2203 x : \u211d, 2 < x \u2227 x < 3,\n    by exact Exists.intro (5 / 2) h,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\nbegin\n  have h : 2 < (5 : \u211d) / 2 \u2227 (5 : \u211d) / 2 < 3,\n    by norm_num,\n  show \u2203 x : \u211d, 2 < x \u2227 x < 3,\n    by exact \u27e85 / 2, h\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\nbegin\n  use 5 / 2,\n  norm_num\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\n\u27e85 / 2, by norm_num\u27e9\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Existencia_de_valor_intermedio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7277228743180819}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport set_theory.cardinal.ordinal\n\n/-!\n# Cardinality of continuum\n\nIn this file we define `cardinal.continuum` (notation: `\ud835\udd20`, localized in `cardinal`) to be `2 ^ \u2135\u2080`.\nWe also prove some `simp` lemmas about cardinal arithmetic involving `\ud835\udd20`.\n\n## Notation\n\n- `\ud835\udd20` : notation for `cardinal.continuum` in locale `cardinal`.\n-/\n\nnamespace cardinal\n\nuniverses u v\n\nopen_locale cardinal\n\n/-- Cardinality of continuum. -/\ndef continuum : cardinal.{u} := 2 ^ aleph_0.{u}\n\nlocalized \"notation `\ud835\udd20` := cardinal.continuum\" in cardinal\n\n@[simp] lemma two_power_aleph_0 : 2 ^ aleph_0.{u} = continuum.{u} := rfl\n\n@[simp] lemma lift_continuum : lift.{v} \ud835\udd20 = \ud835\udd20 :=\nby rw [\u2190two_power_aleph_0, lift_two_power, lift_aleph_0, two_power_aleph_0]\n\n/-!\n### Inequalities\n-/\n\nlemma aleph_0_lt_continuum : \u2135\u2080 < \ud835\udd20 := cantor \u2135\u2080\n\nlemma aleph_0_le_continuum : \u2135\u2080 \u2264 \ud835\udd20 := aleph_0_lt_continuum.le\n\nlemma nat_lt_continuum (n : \u2115) : \u2191n < \ud835\udd20 := (nat_lt_aleph_0 n).trans aleph_0_lt_continuum\n\nlemma mk_set_nat : #(set \u2115) = \ud835\udd20 := by simp\n\nlemma continuum_pos : 0 < \ud835\udd20 := nat_lt_continuum 0\n\nlemma continuum_ne_zero : \ud835\udd20 \u2260 0 := continuum_pos.ne'\n\nlemma aleph_one_le_continuum : aleph 1 \u2264 \ud835\udd20 :=\nby { rw \u2190succ_aleph_0, exact order.succ_le_of_lt aleph_0_lt_continuum }\n\n/-!\n### Addition\n-/\n\n@[simp] lemma aleph_0_add_continuum : \u2135\u2080 + \ud835\udd20 = \ud835\udd20 :=\nadd_eq_right aleph_0_le_continuum aleph_0_le_continuum\n\n@[simp] lemma continuum_add_aleph_0 : \ud835\udd20 + \u2135\u2080 = \ud835\udd20 :=\n(add_comm _ _).trans aleph_0_add_continuum\n\n@[simp] lemma continuum_add_self : \ud835\udd20 + \ud835\udd20 = \ud835\udd20 :=\nadd_eq_right aleph_0_le_continuum le_rfl\n\n@[simp] lemma nat_add_continuum (n : \u2115) : \u2191n + \ud835\udd20 = \ud835\udd20 :=\nadd_eq_right aleph_0_le_continuum (nat_lt_continuum n).le\n\n@[simp] lemma continuum_add_nat (n : \u2115) : \ud835\udd20 + n = \ud835\udd20 :=\n(add_comm _ _).trans (nat_add_continuum n)\n\n/-!\n### Multiplication\n-/\n\n@[simp] \n\n@[simp] lemma continuum_mul_aleph_0 : \ud835\udd20 * \u2135\u2080 = \ud835\udd20 :=\nmul_eq_left aleph_0_le_continuum aleph_0_le_continuum aleph_0_ne_zero\n\n@[simp] lemma aleph_0_mul_continuum : \u2135\u2080 * \ud835\udd20 = \ud835\udd20 :=\n(mul_comm _ _).trans continuum_mul_aleph_0\n\n@[simp] lemma nat_mul_continuum {n : \u2115} (hn : n \u2260 0) : \u2191n * \ud835\udd20 = \ud835\udd20 :=\nmul_eq_right aleph_0_le_continuum (nat_lt_continuum n).le (nat.cast_ne_zero.2 hn)\n\n@[simp] lemma continuum_mul_nat {n : \u2115} (hn : n \u2260 0) : \ud835\udd20 * n = \ud835\udd20 :=\n(mul_comm _ _).trans (nat_mul_continuum hn)\n\n/-!\n### Power\n-/\n\n@[simp] lemma aleph_0_power_aleph_0 : aleph_0.{u} ^ aleph_0.{u} = \ud835\udd20 :=\npower_self_eq le_rfl\n\n@[simp] lemma nat_power_aleph_0 {n : \u2115} (hn : 2 \u2264 n) : (n ^ aleph_0.{u} : cardinal.{u}) = \ud835\udd20 :=\nnat_power_eq le_rfl hn\n\n@[simp] lemma continuum_power_aleph_0 : continuum.{u} ^ aleph_0.{u} = \ud835\udd20 :=\nby rw [\u2190two_power_aleph_0, \u2190power_mul, mul_eq_left le_rfl le_rfl aleph_0_ne_zero]\n\nend cardinal\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/set_theory/cardinal/continuum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7275631068297475}}
{"text": "namespace andOrCom\n    theorem and_com {p q : Prop} : p \u2227 q \u2194 q \u2227 p :=\n    iff.intro\n        (\u03bb h : p \u2227 q, and.intro h.right h.left)\n        (\u03bb h : q \u2227 p, and.intro h.right h.left)\n    #check and_com\n\n    lemma or_lem_1 {p q : Prop} : p \u2228 q \u2192 q \u2228 p :=\n    \u03bb h : p \u2228 q,\n    h.elim (\u03bb hp : p, or.inr hp) (\u03bb hq : q, or.inl hq)\n    lemma or_lem_2 {p q : Prop} : q \u2228 p \u2192 p \u2228 q :=\n    \u03bb h : q \u2228 p,\n    h.elim (\u03bb hq : q, or.inr hq) (\u03bb hp : p, or.inl hp)\n    theorem or_com {p q : Prop} : p \u2228 q \u2194 q \u2228 p :=\n    iff.intro\n        or_lem_1\n        or_lem_2\n    #check or_com\nend andOrCom\nnamespace andOrAssoc\n    lemma aal1 {p q r : Prop} : (p \u2227 q) \u2227 r \u2192 p \u2227 (q \u2227 r) :=\n    \u03bb h : (p \u2227 q) \u2227 r,\n    have hp : p, from (h.left).left,\n    have hq : q, from (h.left).right,\n    have hr : r, from h.right,\n    \u27e8hp, hq, hr\u27e9\n    lemma aal2 {p q r : Prop} : p \u2227 (q \u2227 r) \u2192 (p \u2227 q) \u2227 r :=\n    \u03bb h : p \u2227 (q \u2227 r),\n    have hp : p, from h.left,\n    have hq : q, from (h.right).left,\n    have hr : r, from (h.right).right,\n    \u27e8\u27e8hp, hq\u27e9, hr\u27e9\n    theorem and_assoc {p q r : Prop} : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n    iff.intro\n        aal1\n        aal2\n\n    lemma oal1 {p q r : Prop} : (p \u2228 q) \u2228 r \u2192 p \u2228 (q \u2228 r) :=\n    \u03bb h : (p \u2228 q) \u2228 r,\n    h.elim\n        (assume hpq : p \u2228 q,\n            hpq.elim\n                (assume hp : p,\n                    show p \u2228 q \u2228 r, from or.inl hp)\n                (assume hq : q,\n                    show p \u2228 q \u2228 r, from or.inr $ or.inl hq))\n        (assume hr : r,\n            show p \u2228 q \u2228 r, from or.inr $ or.inr hr)\n    lemma oal2 {p q r : Prop} : p \u2228 (q \u2228 r) \u2192 (p \u2228 q) \u2228 r :=\n    \u03bb h : p \u2228 (q \u2228 r),\n    h.elim\n        (assume hp : p,\n            show (p \u2228 q) \u2228 r, from or.inl $ or.inl hp)\n        (assume hqr : q \u2228 r,\n            hqr.elim\n                (assume hq : q,\n                    show (p \u2228 q) \u2228 r, from or.inl $ or.inr hq)\n                (assume hr : r,\n                    show (p \u2228 q) \u2228 r, from or.inr hr))\n    theorem or_assoc {p q r : Prop} : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n    iff.intro\n        oal1\n        oal2\nend andOrAssoc\n\nnamespace andOrDistrib\n    lemma aod1 {p q r : Prop} : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\n    \u03bb h : p \u2227 (q \u2228 r),\n    have hp : p, from h.left,\n    have hqr : (q \u2228 r), from h.right,\n    hqr.elim\n        (assume hq : q,\n            show (p \u2227 q) \u2228 (p \u2227 r), from or.inl \u27e8hp, hq\u27e9)\n        (assume hr : r,\n            show (p \u2227 q) \u2228 (p \u2227 r), from or.inr \u27e8hp, hr\u27e9)\n\n\n    lemma aod2 {p q r : Prop} : (p \u2227 q) \u2228 (p \u2227 r) \u2192 p \u2227 (q \u2228 r) :=\n    \u03bb h : (p \u2227 q) \u2228 (p \u2227 r),\n    h.elim\n        (assume hpq : p \u2227 q,\n        have hp : p, from hpq.left,\n        have hq : q, from hpq.right,\n        and.intro\n            (show p, from hp)\n            (show q \u2228 r, from or.inl hq))\n        (assume hpr : p \u2227 r,\n        have hp : p, from hpr.left,\n        have hr : r, from hpr.right,\n        and.intro\n            (show p, from hp)\n            (show q \u2228 r, from or.inr hr))\n    theorem and_or_distrib {p q r : Prop} : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n    iff.intro\n        aod1\n        aod2\n\n\nlemma oad1 {p q r : Prop} : p \u2228 (q \u2227 r) \u2192 (p \u2228 q) \u2227 (p \u2228 r) :=\n\u03bb h : p \u2228 (q \u2227 r),\nh.elim\n    (assume hp : p,\n     and.intro\n        (show p \u2228 q,from or.inl hp)\n        (show p \u2228 r, from or.inl hp))\n    (assume hqr : q \u2227 r,\n     have hq : q, from hqr.left,\n     have hr : r, from hqr.right,\n     and.intro\n        (show p \u2228 q, from or.inr hq)\n        (show p \u2228 r, from or.inr hr))\n\nlemma oad2 {p q r : Prop} : (p \u2228 q) \u2227 (p \u2228 r) \u2192 p \u2228 (q \u2227 r) :=\n\u03bb h : (p \u2228 q) \u2227 (p \u2228 r),\nhave hpq : p \u2228 q, from h.left,\nhave hpr : p \u2228 r, from h.right,\nsorry\n\ntheorem or_and_distrib {p q r : Prop} : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\niff.intro\n    (oad1)\n    (oad2)\n#check or_and_distrib\n\nend andOrDistrib\n", "meta": {"author": "robkorn", "repo": "theorem-proving-in-lean-exercises", "sha": "9c51da587105ee047a9db55d52709d881a39be7a", "save_path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises", "path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises/theorem-proving-in-lean-exercises-9c51da587105ee047a9db55d52709d881a39be7a/Chapter3/3-6+7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7275631027203485}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport linear_algebra.finite_dimensional\n\n/-!\n\n# Vector spaces\n\nThe definition of a vector space `V` over a field `k` is the following:\n\n1) `V` is an abelian group\n2) If `r : k` and `v : V` there's an element `r \u2022 v : V`\n3) Axioms for `\u2022`: `(r + s) \u2022 v = r \u2022 v + s \u2022 v`, `r \u2022 (v + w) = r \u2022 v = r \u2022 w` \nand `1 \u2022 v = v`. \n\nFields have inverses, but there is no mention of inverses in the axioms of a vector\nspace. This means that we can make the *definition* of a vector space just under\nthe assumption that `k` is a `ring`, rather than a `field`, although of course\nfewer things will be true (for example, over a general ring it is not true that\nevery vector space has a basis). However, when `k` is a ring, mathematicians don't\ncall these things vector spaces; they call them *modules*. So the way we say\n\"let `V` be a vector space over `k`\" in Lean is \"let `V` be a module over `k`\".\n\n(**TODO** add the vector_space notation back in a locale and PR to mathlib\nso that next year's students don't have to suffer this)\n\n-/\n\n-- if we make variable definitions in a section then they will disappear\n-- when we close the section\nsection explanations\n\n-- This says \"let `k` be a field and let `V` be a vector space over `k`\"\nvariables (k : Type) [field k] (V : Type) [add_comm_group V] [module k V]\n\n-- This says \"let `B` be a basis for `V`, with basis vectors e\u1d62 for `i : I`\"\nvariables (I : Type) (B : basis I k V)\n\n-- This says \"assume `V` is finite-dimensional\n\nvariable [finite_dimensional k V]\n\nend explanations\n\n/-\n\n# subspaces of a vector space are a lattice\n\n-/\n\nsection lattice\n\n-- Let V be a vector space over a field k\nvariables (k : Type) [field k] (V : Type) [add_comm_group V] [module k V]\n\n-- let A and B be subspaces\nvariables (A B : subspace k V)\n\n-- Note that A and B are terms not types.\n\n-- How do we say A \u2286 B?\n\n-- #check A \u2286 B -- doesn't work!\n\n-- We need to use *lattice notation*\n\n#check A \u2264 B -- A is a subset of B; it's a Prop\n\n#check A \u2293 B -- intersection of A and B, as a subspace\n\n#check A \u2294 B -- A + B, as a subspace\n\n#check (\u22a5 : subspace k V) -- the 0-dimensional subspace\n\n#check (\u22a4 : subspace k V) -- V considered as a subspace of itself; note that\n                          -- we can't use V to represent this subspace because\n                          -- V is a type, and a subspace of V is a term\n\n-- For elements it's just like sets:\n\nvariable (v : V)\n\n#check v \u2208 A -- it's a Prop\n\n-- There are a ton of general theorems about lattices such as `A \u2264 A \u2294 B`\n-- and `A \u2293 B \u2264 B` in the library; they apply to all lattices (like the lattice\n-- of subsets of a type, the lattice of subgroups of a group etc etc).\n\nend lattice\n\n/-\n\n# The question\n\nA 2019 University of Edinburgh example sheet question: prove that if `V` is a 9-dimensional\nvector space and `A, B` are two subspaces of dimension 5, then `A \u2229 B` cannot be \nthe zero vector space.\n\n-/\n\n-- let k be a field and let V be a k-vector space\nvariables (k : Type) [field k] (V : Type) [add_comm_group V] [module k V]\n\n-- Let `A` and `B` be subspaces of `V`\nvariables (A B : subspace k V)\n\n-- If we don't put in a finite-dimensional hypothesis then `dim V` will be a \"cardinal\",\n-- a generalisation of a number which could be infinity. \n\nvariables [finite_dimensional k V]\n\n-- Now we can use `finite_dimensional.finrank k V` which is the dimension of V as a natural number\n-- However, if we open the namespace...\nopen finite_dimensional\n\n-- ...then we can just talk about `finrank` which makes typing easier. Here's the question.\n\nexample (hV : finrank k V = 9) (hA : finrank k A = 5) (hB : finrank k B = 5) :\n  A \u2293 B \u2260 \u22a5 :=\nbegin\n  -- see below for the API (i.e. the theorems) you will need\n  sorry,\nend\n\n/-\n\n## Some API for finite-dimensional vector spaces\n\n`submodule.dim_sup_add_dim_inf_eq A B : finrank k \u21a5(A \u2294 B) + finrank k \u21a5(A \u2293 B) = finrank k \u21a5A + finrank k \u21a5B`\n`submodule.finrank_le A : finrank k \u21a5A \u2264 finrank k V`\n`finrank_bot k V : finrank K \u21a5\u22a5 = 0`\n\n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section10vectorspaces/sheet1findim.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8104788995148792, "lm_q1q2_score": 0.7275630902285705}}
{"text": "namespace ind\n\n  inductive nat : Type\n  | O : nat\n  | S : nat \u2192 nat\n\n  namespace nat\n    def add : nat \u2192 nat \u2192 nat\n    | O n := n\n    | (S m) n := S (add m n)\n\n    notation x `+` y := add x y\n\n    def mul : nat \u2192 nat \u2192 nat\n    | O n := O\n    | (S m) n := add n (mul m n)\n\n    #reduce (S (S O)) + (S (S (S O)))\n\n    theorem add_zero_id : \u2200 n : nat, n = n + O :=\n    begin\n      intro,\n      induction n with n IH,\n        refl,\n        simp [add], apply IH\n    end\n\n    theorem add_comm : \u2200 m n : nat, m + n = n + m :=\n    begin\n      intro,\n      induction m with m IH,\n        intro,\n        simp [add], rewrite <- add_zero_id n,\n\n        intro,\n        simp [add],\n        rewrite IH,\n        induction n with n IHn,\n          simp [add],\n          rewrite <- IH,\n\n          simp [add],\n          rewrite IH,\n          simp [add],\n          exact IHn,\n    end\n  end nat\n\n  inductive l  : Type\n  | E : l\n  | A : nat \u2192 l \u2192 l\n\n  variable x : nat\n  variable y : nat\n  variable z : nat\n\n  namespace l\n    #check A\n    #check E  -- ()\n    #check A x E  -- (x)\n    #check A x (A x E)  -- (x, x)\n    #check A z (A y (A x E))  -- (x, y, z)\n\n    def len : l \u2192 nat\n    | E := nat.O\n    | (A t s) := nat.S (len s)\n\n    example : \u2200 s : l, \u2200 n : nat, len (A n s) = nat.S (len s) :=\n    begin\n      intro, intro, refl\n    end\n  end l\n\n  inductive p (A B : Type) : Type -- A x B\n  | con : A \u2192 B \u2192 p\n\n  namespace p\n    def p1 (A B : Type) : (p A B) \u2192 A\n    | (con m n) := m\n\n    def p2 (A B : Type) : (p A B) \u2192 B\n    | (con m n) := n\n\n    def s (A B : Type) : (p A B) -> (p B A)\n    | (con m n) := con n m\n\n    def s1 (A B : Type) : (p A B) -> (p B A):= fun x : (p A B),\n                            con (p2 A B x) (p1 A B x)\n  end p\n\nend ind", "meta": {"author": "BelegCuthalion", "repo": "lean-exc", "sha": "9143dc8b8aac62b9b2dcee85b619fe5c2e2a7144", "save_path": "github-repos/lean/BelegCuthalion-lean-exc", "path": "github-repos/lean/BelegCuthalion-lean-exc/lean-exc-9143dc8b8aac62b9b2dcee85b619fe5c2e2a7144/ind.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7275281875698635}}
{"text": "/-\nCopyright (c) 2022 Jun Yoshida. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n-/\n\nimport Std.Logic\n\ntheorem not_or_iff_and_not {p q : Prop} : \u00ac (p \u2228 q) \u2194 \u00ac p \u2227 \u00ac q where\n  mp := by\n    intro hnpq\n    constructor\n    case left =>\n      exact hnpq \u2218 Or.inl\n    case right =>\n      exact hnpq \u2218 Or.inr\n  mpr := by\n    intro hnpnq hpq\n    cases hpq\n    case inl hp => exact hnpnq.1 hp\n    case inr hq => exact hnpnq.2 hq\n\ntheorem And.map {p\u2081 p\u2082 q\u2081 q\u2082 : Prop} (hp : p\u2081 \u2192 p\u2082) (hq : q\u2081 \u2192 q\u2082) : p\u2081 \u2227 q\u2081 \u2192 p\u2082 \u2227 q\u2082\n| And.intro hp\u2081 hq\u2081 => And.intro (hp hp\u2081) (hq hq\u2081)\n\ntheorem And.substIff {p\u2081 p\u2082 q\u2081 q\u2082 : Prop} (hp : p\u2081 \u2194 p\u2082) (hq : q\u2081 \u2194 q\u2082) : (p\u2081 \u2227 q\u2081) \u2194 (p\u2082 \u2227 q\u2082) where\n  mp h1 := h1.map hp.mp hq.mp\n  mpr h2 := h2.map hp.mpr hq.mpr\n\ntheorem Or.map {p\u2081 p\u2082 q\u2081 q\u2082 : Prop} (hp : p\u2081 \u2192 p\u2082) (hq : q\u2081 \u2192 q\u2082) : p\u2081 \u2228 q\u2081 \u2192 p\u2082 \u2228 q\u2082\n| Or.inl hp\u2081 => Or.inl (hp hp\u2081)\n| Or.inr hq\u2081 => Or.inr (hq hq\u2081)\n\ntheorem Or.substIff {p\u2081 p\u2082 q\u2081 q\u2082 : Prop} (hp : p\u2081 \u2194 p\u2082) (hq : q\u2081 \u2194 q\u2082) : (p\u2081 \u2228 q\u2081 \u2194  p\u2082 \u2228 q\u2082) where\n  mp h1 := h1.map hp.mp hq.mp\n  mpr h2 := h2.map hp.mpr hq.mpr\n", "meta": {"author": "Junology", "repo": "algdata", "sha": "ef0e552747c3f1004705755a3afc7ccedec92bf6", "save_path": "github-repos/lean/Junology-algdata", "path": "github-repos/lean/Junology-algdata/algdata-ef0e552747c3f1004705755a3afc7ccedec92bf6/Algdata/Init/Logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7275281869592355}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Heather Macbeth, Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport algebra.big_operators.intervals\nimport analysis.normed.group.basic\nimport topology.instances.nnreal\n\n/-!\n# Infinite sums in (semi)normed groups\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn a complete (semi)normed group,\n\n- `summable_iff_vanishing_norm`: a series `\u2211' i, f i` is summable if and only if for any `\u03b5 > 0`,\n  there exists a finite set `s` such that the sum `\u2211 i in t, f i` over any finite set `t` disjoint\n  with `s` has norm less than `\u03b5`;\n\n- `summable_of_norm_bounded`, `summable_of_norm_bounded_eventually`: if `\u2016f i\u2016` is bounded above by\n  a summable series `\u2211' i, g i`, then `\u2211' i, f i` is summable as well; the same is true if the\n  inequality hold only off some finite set.\n\n- `tsum_of_norm_bounded`, `has_sum.norm_le_of_bounded`: if `\u2016f i\u2016 \u2264 g i`, where `\u2211' i, g i` is a\n  summable series, then `\u2016\u2211' i, f i\u2016 \u2264 \u2211' i, g i`.\n\n## Tags\n\ninfinite series, absolute convergence, normed group\n-/\n\nopen_locale classical big_operators topology nnreal\nopen finset filter metric\n\nvariables {\u03b9 \u03b1 E F : Type*} [seminormed_add_comm_group E] [seminormed_add_comm_group F]\n\nlemma cauchy_seq_finset_iff_vanishing_norm {f : \u03b9 \u2192 E} :\n  cauchy_seq (\u03bb s : finset \u03b9, \u2211 i in s, f i) \u2194\n    \u2200\u03b5 > (0 : \u211d), \u2203s:finset \u03b9, \u2200t, disjoint t s \u2192 \u2016 \u2211 i in t, f i \u2016 < \u03b5 :=\nbegin\n  rw [cauchy_seq_finset_iff_vanishing, nhds_basis_ball.forall_iff],\n  { simp only [ball_zero_eq, set.mem_set_of_eq] },\n  { rintros s t hst \u27e8s', hs'\u27e9,\n    exact \u27e8s', \u03bb t' ht', hst $ hs' _ ht'\u27e9 }\nend\n\nlemma summable_iff_vanishing_norm [complete_space E] {f : \u03b9 \u2192 E} :\n  summable f \u2194 \u2200\u03b5 > (0 : \u211d), \u2203s:finset \u03b9, \u2200t, disjoint t s \u2192 \u2016 \u2211 i in t, f i \u2016 < \u03b5 :=\nby rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing_norm]\n\nlemma cauchy_seq_finset_of_norm_bounded_eventually {f : \u03b9 \u2192 E} {g : \u03b9 \u2192 \u211d} (hg : summable g)\n  (h : \u2200\u1da0 i in cofinite, \u2016f i\u2016 \u2264 g i) : cauchy_seq (\u03bb s, \u2211 i in s, f i) :=\nbegin\n  refine cauchy_seq_finset_iff_vanishing_norm.2 (\u03bb \u03b5 h\u03b5, _),\n  rcases summable_iff_vanishing_norm.1 hg \u03b5 h\u03b5 with \u27e8s, hs\u27e9,\n  refine \u27e8s \u222a h.to_finset, \u03bb t ht, _\u27e9,\n  have : \u2200 i \u2208 t, \u2016f i\u2016 \u2264 g i,\n  { intros i hi,\n    simp only [disjoint_left, mem_union, not_or_distrib, h.mem_to_finset, set.mem_compl_iff,\n      not_not] at ht,\n    exact (ht hi).2 },\n  calc \u2016\u2211 i in t, f i\u2016 \u2264 \u2211 i in t, g i    : norm_sum_le_of_le _ this\n                    ... \u2264 \u2016\u2211 i in t, g i\u2016 : le_abs_self _\n                    ... < \u03b5               : hs _ (ht.mono_right le_sup_left),\nend\n\nlemma cauchy_seq_finset_of_norm_bounded {f : \u03b9 \u2192 E} (g : \u03b9 \u2192 \u211d) (hg : summable g)\n  (h : \u2200i, \u2016f i\u2016 \u2264 g i) : cauchy_seq (\u03bb s : finset \u03b9, \u2211 i in s, f i) :=\ncauchy_seq_finset_of_norm_bounded_eventually hg $ eventually_of_forall h\n\n/-- A version of the **direct comparison test** for conditionally convergent series.\nSee `cauchy_seq_finset_of_norm_bounded` for the same statement about absolutely convergent ones. -/\nlemma cauchy_seq_range_of_norm_bounded {f : \u2115 \u2192 E} (g : \u2115 \u2192 \u211d)\n  (hg : cauchy_seq (\u03bb n, \u2211 i in range n, g i)) (hf : \u2200 i, \u2016f i\u2016 \u2264 g i) :\n  cauchy_seq (\u03bb n, \u2211 i in range n, f i) :=\nbegin\n  refine metric.cauchy_seq_iff'.2 (\u03bb \u03b5 h\u03b5, _),\n  refine (metric.cauchy_seq_iff'.1 hg \u03b5 h\u03b5).imp (\u03bb N hg n hn, _),\n  specialize hg n hn,\n  rw [dist_eq_norm, \u2190sum_Ico_eq_sub _ hn] at \u22a2 hg,\n  calc  \u2016\u2211 k in Ico N n, f k\u2016\n      \u2264  \u2211 k in _, \u2016f k\u2016 : norm_sum_le _ _\n  ... \u2264  \u2211 k in _, g k   : sum_le_sum (\u03bb x _, hf x)\n  ... \u2264 \u2016\u2211 k in _, g k\u2016  : le_abs_self _\n  ... <  \u03b5               : hg\nend\n\nlemma cauchy_seq_finset_of_summable_norm {f : \u03b9 \u2192 E} (hf : summable (\u03bba, \u2016f a\u2016)) :\n  cauchy_seq (\u03bb s : finset \u03b9, \u2211 a in s, f a) :=\ncauchy_seq_finset_of_norm_bounded _ hf (assume i, le_rfl)\n\n/-- If a function `f` is summable in norm, and along some sequence of finsets exhausting the space\nits sum is converging to a limit `a`, then this holds along all finsets, i.e., `f` is summable\nwith sum `a`. -/\nlemma has_sum_of_subseq_of_summable {f : \u03b9 \u2192 E} (hf : summable (\u03bba, \u2016f a\u2016))\n  {s : \u03b1 \u2192 finset \u03b9} {p : filter \u03b1} [ne_bot p]\n  (hs : tendsto s p at_top) {a : E} (ha : tendsto (\u03bb b, \u2211 i in s b, f i) p (\ud835\udcdd a)) :\n  has_sum f a :=\ntendsto_nhds_of_cauchy_seq_of_subseq (cauchy_seq_finset_of_summable_norm hf) hs ha\n\nlemma has_sum_iff_tendsto_nat_of_summable_norm {f : \u2115 \u2192 E} {a : E} (hf : summable (\u03bbi, \u2016f i\u2016)) :\n  has_sum f a \u2194 tendsto (\u03bbn:\u2115, \u2211 i in range n, f i) at_top (\ud835\udcdd a) :=\n\u27e8\u03bb h, h.tendsto_sum_nat,\n\u03bb h, has_sum_of_subseq_of_summable hf tendsto_finset_range h\u27e9\n\n/-- The direct comparison test for series:  if the norm of `f` is bounded by a real function `g`\nwhich is summable, then `f` is summable. -/\nlemma summable_of_norm_bounded\n  [complete_space E] {f : \u03b9 \u2192 E} (g : \u03b9 \u2192 \u211d) (hg : summable g) (h : \u2200i, \u2016f i\u2016 \u2264 g i) :\n  summable f :=\nby { rw summable_iff_cauchy_seq_finset, exact cauchy_seq_finset_of_norm_bounded g hg h }\n\nlemma has_sum.norm_le_of_bounded {f : \u03b9 \u2192 E} {g : \u03b9 \u2192 \u211d} {a : E} {b : \u211d}\n  (hf : has_sum f a) (hg : has_sum g b) (h : \u2200 i, \u2016f i\u2016 \u2264 g i) :\n  \u2016a\u2016 \u2264 b :=\nle_of_tendsto_of_tendsto' hf.norm hg $ \u03bb s, norm_sum_le_of_le _ $ \u03bb i hi, h i\n\n/-- Quantitative result associated to the direct comparison test for series:  If `\u2211' i, g i` is\nsummable, and for all `i`, `\u2016f i\u2016 \u2264 g i`, then `\u2016\u2211' i, f i\u2016 \u2264 \u2211' i, g i`. Note that we do not\nassume that `\u2211' i, f i` is summable, and it might not be the case if `\u03b1` is not a complete space. -/\nlemma tsum_of_norm_bounded {f : \u03b9 \u2192 E} {g : \u03b9 \u2192 \u211d} {a : \u211d} (hg : has_sum g a)\n  (h : \u2200 i, \u2016f i\u2016 \u2264 g i) :\n  \u2016\u2211' i : \u03b9, f i\u2016 \u2264 a :=\nbegin\n  by_cases hf : summable f,\n  { exact hf.has_sum.norm_le_of_bounded hg h },\n  { rw [tsum_eq_zero_of_not_summable hf, norm_zero],\n    exact ge_of_tendsto' hg (\u03bb s, sum_nonneg $ \u03bb i hi, (norm_nonneg _).trans (h i)) }\nend\n\n/-- If `\u2211' i, \u2016f i\u2016` is summable, then `\u2016\u2211' i, f i\u2016 \u2264 (\u2211' i, \u2016f i\u2016)`. Note that we do not assume\nthat `\u2211' i, f i` is summable, and it might not be the case if `\u03b1` is not a complete space. -/\nlemma norm_tsum_le_tsum_norm {f : \u03b9 \u2192 E} (hf : summable (\u03bbi, \u2016f i\u2016)) :\n  \u2016\u2211' i, f i\u2016 \u2264 \u2211' i, \u2016f i\u2016 :=\ntsum_of_norm_bounded hf.has_sum $ \u03bb i, le_rfl\n\n/-- Quantitative result associated to the direct comparison test for series: If `\u2211' i, g i` is\nsummable, and for all `i`, `\u2016f i\u2016\u208a \u2264 g i`, then `\u2016\u2211' i, f i\u2016\u208a \u2264 \u2211' i, g i`. Note that we\ndo not assume that `\u2211' i, f i` is summable, and it might not be the case if `\u03b1` is not a complete\nspace. -/\nlemma tsum_of_nnnorm_bounded {f : \u03b9 \u2192 E} {g : \u03b9 \u2192 \u211d\u22650} {a : \u211d\u22650} (hg : has_sum g a)\n  (h : \u2200 i, \u2016f i\u2016\u208a \u2264 g i) :\n  \u2016\u2211' i : \u03b9, f i\u2016\u208a \u2264 a :=\nbegin\n  simp only [\u2190 nnreal.coe_le_coe, \u2190 nnreal.has_sum_coe, coe_nnnorm] at *,\n  exact tsum_of_norm_bounded hg h\nend\n\n/-- If `\u2211' i, \u2016f i\u2016\u208a` is summable, then `\u2016\u2211' i, f i\u2016\u208a \u2264 \u2211' i, \u2016f i\u2016\u208a`. Note that\nwe do not assume that `\u2211' i, f i` is summable, and it might not be the case if `\u03b1` is not a complete\nspace. -/\nlemma nnnorm_tsum_le {f : \u03b9 \u2192 E} (hf : summable (\u03bbi, \u2016f i\u2016\u208a)) :\n  \u2016\u2211' i, f i\u2016\u208a \u2264 \u2211' i, \u2016f i\u2016\u208a :=\ntsum_of_nnnorm_bounded hf.has_sum (\u03bb i, le_rfl)\n\nvariable [complete_space E]\n\n/-- Variant of the direct comparison test for series:  if the norm of `f` is eventually bounded by a\nreal function `g` which is summable, then `f` is summable. -/\nlemma summable_of_norm_bounded_eventually {f : \u03b9 \u2192 E} (g : \u03b9 \u2192 \u211d) (hg : summable g)\n  (h : \u2200\u1da0 i in cofinite, \u2016f i\u2016 \u2264 g i) : summable f :=\nsummable_iff_cauchy_seq_finset.2 $ cauchy_seq_finset_of_norm_bounded_eventually hg h\n\nlemma summable_of_nnnorm_bounded {f : \u03b9 \u2192 E} (g : \u03b9 \u2192 \u211d\u22650) (hg : summable g)\n  (h : \u2200i, \u2016f i\u2016\u208a \u2264 g i) : summable f :=\nsummable_of_norm_bounded (\u03bb i, (g i : \u211d)) (nnreal.summable_coe.2 hg) (\u03bb i, by exact_mod_cast h i)\n\nlemma summable_of_summable_norm {f : \u03b9 \u2192 E} (hf : summable (\u03bba, \u2016f a\u2016)) : summable f :=\nsummable_of_norm_bounded _ hf (assume i, le_rfl)\n\nlemma summable_of_summable_nnnorm {f : \u03b9 \u2192 E} (hf : summable (\u03bb a, \u2016f a\u2016\u208a)) : summable f :=\nsummable_of_nnnorm_bounded _ hf (assume i, le_rfl)\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed/group/infinite_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7275281627595942}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\n! This file was ported from Lean 3 source module data.pnat.factors\n! leanprover-community/mathlib commit e3d9ab8faa9dea8f78155c6c27d62a621f4c152d\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.BigOperators.Multiset.Basic\nimport Mathlib.Data.PNat.Prime\nimport Mathlib.Data.Nat.Factors\nimport Mathlib.Data.Multiset.Sort\n\n/-!\n# Prime factors of nonzero naturals\n\nThis file defines the factorization of a nonzero natural number `n` as a multiset of primes,\nthe multiplicity of `p` in this factors multiset being the p-adic valuation of `n`.\n\n## Main declarations\n\n* `PrimeMultiset`: Type of multisets of prime numbers.\n* `FactorMultiset n`: Multiset of prime factors of `n`.\n-/\n\n-- Porting note: `deriving` contained\n-- Inhabited, CanonicallyOrderedAddMonoid, DistribLattice, SemilatticeSup, OrderBot, Sub, OrderedSub\n/-- The type of multisets of prime numbers.  Unique factorization\n gives an equivalence between this set and \u2115+, as we will formalize\n below. -/\ndef PrimeMultiset :=\n  Multiset Nat.Primes deriving Inhabited, CanonicallyOrderedAddMonoid, DistribLattice,\n  SemilatticeSup, Sub\n#align prime_multiset PrimeMultiset\n\ninstance : OrderBot PrimeMultiset where\n  bot_le := by simp only [bot_le, forall_const]\n\ninstance : OrderedSub PrimeMultiset where\n  tsub_le_iff_right _ _ _ := Multiset.sub_le_iff_le_add\n\nnamespace PrimeMultiset\n\n-- `@[derive]` doesn't work for `meta` instances\nunsafe instance : Repr PrimeMultiset := by delta PrimeMultiset; infer_instance\n\n/-- The multiset consisting of a single prime -/\ndef ofPrime (p : Nat.Primes) : PrimeMultiset :=\n  ({p} : Multiset Nat.Primes)\n#align prime_multiset.of_prime PrimeMultiset.ofPrime\n\ntheorem card_ofPrime (p : Nat.Primes) : Multiset.card (ofPrime p) = 1 :=\n  rfl\n#align prime_multiset.card_of_prime PrimeMultiset.card_ofPrime\n\n/-- We can forget the primality property and regard a multiset\n of primes as just a multiset of positive integers, or a multiset\n of natural numbers.  In the opposite direction, if we have a\n multiset of positive integers or natural numbers, together with\n a proof that all the elements are prime, then we can regard it\n as a multiset of primes.  The next block of results records\n obvious properties of these coercions.\n-/\ndef toNatMultiset : PrimeMultiset \u2192 Multiset \u2115 := fun v => v.map Coe.coe\n#align prime_multiset.to_nat_multiset PrimeMultiset.toNatMultiset\n\ninstance coeNat : Coe PrimeMultiset (Multiset \u2115) :=\n  \u27e8toNatMultiset\u27e9\n#align prime_multiset.coe_nat PrimeMultiset.coeNat\n\n/-- `PrimeMultiset.coe`, the coercion from a multiset of primes to a multiset of\nnaturals, promoted to an `AddMonoidHom`. -/\ndef coeNatMonoidHom : PrimeMultiset \u2192+ Multiset \u2115 :=\n  { Multiset.mapAddMonoidHom Coe.coe with toFun := Coe.coe }\n#align prime_multiset.coe_nat_monoid_hom PrimeMultiset.coeNatMonoidHom\n\n@[simp]\ntheorem coe_coeNatMonoidHom : (coeNatMonoidHom : PrimeMultiset \u2192 Multiset \u2115) = Coe.coe :=\n  rfl\n#align prime_multiset.coe_coe_nat_monoid_hom PrimeMultiset.coe_coeNatMonoidHom\n\ntheorem coeNat_injective : Function.Injective (Coe.coe : PrimeMultiset \u2192 Multiset \u2115) :=\n  Multiset.map_injective Nat.Primes.coe_nat_injective\n#align prime_multiset.coe_nat_injective PrimeMultiset.coeNat_injective\n\ntheorem coeNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset \u2115) = {(p : \u2115)} :=\n  rfl\n#align prime_multiset.coe_nat_of_prime PrimeMultiset.coeNat_ofPrime\n\ntheorem coeNat_prime (v : PrimeMultiset) (p : \u2115) (h : p \u2208 (v : Multiset \u2115)) : p.Prime := by\n  rcases Multiset.mem_map.mp h with \u27e8\u27e8_, hp'\u27e9, \u27e8_, h_eq\u27e9\u27e9\n  exact h_eq \u25b8 hp'\n#align prime_multiset.coe_nat_prime PrimeMultiset.coeNat_prime\n\n/-- Converts a `PrimeMultiset` to a `Multiset \u2115+`. -/\ndef toPNatMultiset : PrimeMultiset \u2192 Multiset \u2115+ := fun v => v.map Coe.coe\n#align prime_multiset.to_pnat_multiset PrimeMultiset.toPNatMultiset\n\ninstance coePNat : Coe PrimeMultiset (Multiset \u2115+) :=\n  \u27e8toPNatMultiset\u27e9\n#align prime_multiset.coe_pnat PrimeMultiset.coePNat\n\n/-- `coePNat`, the coercion from a multiset of primes to a multiset of positive\nnaturals, regarded as an `AddMonoidHom`. -/\ndef coePNatMonoidHom : PrimeMultiset \u2192+ Multiset \u2115+ :=\n  { Multiset.mapAddMonoidHom Coe.coe with toFun := Coe.coe }\n#align prime_multiset.coe_pnat_monoid_hom PrimeMultiset.coePNatMonoidHom\n\n@[simp]\ntheorem coe_coePNatMonoidHom : (coePNatMonoidHom : PrimeMultiset \u2192 Multiset \u2115+) = Coe.coe :=\n  rfl\n#align prime_multiset.coe_coe_pnat_monoid_hom PrimeMultiset.coe_coePNatMonoidHom\n\ntheorem coePNat_injective : Function.Injective (Coe.coe : PrimeMultiset \u2192 Multiset \u2115+) :=\n  Multiset.map_injective Nat.Primes.coe_pnat_injective\n#align prime_multiset.coe_pnat_injective PrimeMultiset.coePNat_injective\n\ntheorem coePNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset \u2115+) = {(p : \u2115+)} :=\n  rfl\n#align prime_multiset.coe_pnat_of_prime PrimeMultiset.coePNat_ofPrime\n\ntheorem coePNat_prime (v : PrimeMultiset) (p : \u2115+) (h : p \u2208 (v : Multiset \u2115+)) : p.Prime := by\n  rcases Multiset.mem_map.mp h with \u27e8\u27e8_, hp'\u27e9, \u27e8_, h_eq\u27e9\u27e9\n  exact h_eq \u25b8 hp'\n#align prime_multiset.coe_pnat_prime PrimeMultiset.coePNat_prime\n\ninstance coeMultisetPNatNat : Coe (Multiset \u2115+) (Multiset \u2115) :=\n  \u27e8fun v => v.map Coe.coe\u27e9\n#align prime_multiset.coe_multiset_pnat_nat PrimeMultiset.coeMultisetPNatNat\n\ntheorem coePNat_nat (v : PrimeMultiset) : ((v : Multiset \u2115+) : Multiset \u2115) = (v : Multiset \u2115) := by\n  change (v.map (Coe.coe : Nat.Primes \u2192 \u2115+)).map Subtype.val = v.map Subtype.val\n  rw [Multiset.map_map]\n  congr\n#align prime_multiset.coe_pnat_nat PrimeMultiset.coePNat_nat\n\n/-- The product of a `PrimeMultiset`, as a `\u2115+`. -/\ndef prod (v : PrimeMultiset) : \u2115+ :=\n  (v : Multiset PNat).prod\n#align prime_multiset.prod PrimeMultiset.prod\n\ntheorem coe_prod (v : PrimeMultiset) : (v.prod : \u2115) = (v : Multiset \u2115).prod := by\n  let h : (v.prod : \u2115) = ((v.map Coe.coe).map Coe.coe).prod :=\n    PNat.coeMonoidHom.map_multiset_prod v.toPNatMultiset\n  rw [Multiset.map_map] at h\n  have : (Coe.coe : \u2115+ \u2192 \u2115) \u2218 (Coe.coe : Nat.Primes \u2192 \u2115+) = Coe.coe := funext fun p => rfl\n  rw [this] at h; exact h\n#align prime_multiset.coe_prod PrimeMultiset.coe_prod\n\ntheorem prod_ofPrime (p : Nat.Primes) : (ofPrime p).prod = (p : \u2115+) :=\n  Multiset.prod_singleton _\n#align prime_multiset.prod_of_prime PrimeMultiset.prod_ofPrime\n\n/-- If a `Multiset \u2115` consists only of primes, it can be recast as a `PrimeMultiset`. -/\ndef ofNatMultiset (v : Multiset \u2115) (h : \u2200 p : \u2115, p \u2208 v \u2192 p.Prime) : PrimeMultiset :=\n  @Multiset.pmap \u2115 Nat.Primes Nat.Prime (fun p hp => \u27e8p, hp\u27e9) v h\n#align prime_multiset.of_nat_multiset PrimeMultiset.ofNatMultiset\n\ntheorem to_ofNatMultiset (v : Multiset \u2115) (h) : (ofNatMultiset v h : Multiset \u2115) = v := by\n  dsimp [ofNatMultiset, toNatMultiset]\n  have : (fun p h => (Coe.coe : Nat.Primes \u2192 \u2115) \u27e8p, h\u27e9) = fun p _ => id p := by\n    funext p h\n    rfl\n  rw [Multiset.map_pmap, this, Multiset.pmap_eq_map, Multiset.map_id]\n#align prime_multiset.to_of_nat_multiset PrimeMultiset.to_ofNatMultiset\n\ntheorem prod_ofNatMultiset (v : Multiset \u2115) (h) : ((ofNatMultiset v h).prod : \u2115) = (v.prod : \u2115) :=\n  by rw [coe_prod, to_ofNatMultiset]\n#align prime_multiset.prod_of_nat_multiset PrimeMultiset.prod_ofNatMultiset\n\n/-- If a `Multiset \u2115+` consists only of primes, it can be recast as a `PrimeMultiset`. -/\ndef ofPNatMultiset (v : Multiset \u2115+) (h : \u2200 p : \u2115+, p \u2208 v \u2192 p.Prime) : PrimeMultiset :=\n  @Multiset.pmap \u2115+ Nat.Primes PNat.Prime (fun p hp => \u27e8(p : \u2115), hp\u27e9) v h\n#align prime_multiset.of_pnat_multiset PrimeMultiset.ofPNatMultiset\n\ntheorem to_ofPNatMultiset (v : Multiset \u2115+) (h) : (ofPNatMultiset v h : Multiset \u2115+) = v := by\n  dsimp [ofPNatMultiset, toPNatMultiset]\n  have : (fun (p : \u2115+) (h : p.Prime) => (Coe.coe : Nat.Primes \u2192 \u2115+) \u27e8p, h\u27e9) = fun p _ => id p := by\n    funext p h\n    apply Subtype.eq\n    rfl\n  rw [Multiset.map_pmap, this, Multiset.pmap_eq_map, Multiset.map_id]\n#align prime_multiset.to_of_pnat_multiset PrimeMultiset.to_ofPNatMultiset\n\ntheorem prod_ofPNatMultiset (v : Multiset \u2115+) (h) : ((ofPNatMultiset v h).prod : \u2115+) = v.prod := by\n  dsimp [prod]\n  rw [to_ofPNatMultiset]\n#align prime_multiset.prod_of_pnat_multiset PrimeMultiset.prod_ofPNatMultiset\n\n/-- Lists can be coerced to multisets; here we have some results\nabout how this interacts with our constructions on multisets. -/\ndef ofNatList (l : List \u2115) (h : \u2200 p : \u2115, p \u2208 l \u2192 p.Prime) : PrimeMultiset :=\n  ofNatMultiset (l : Multiset \u2115) h\n#align prime_multiset.of_nat_list PrimeMultiset.ofNatList\n\ntheorem prod_ofNatList (l : List \u2115) (h) : ((ofNatList l h).prod : \u2115) = l.prod := by\n  have := prod_ofNatMultiset (l : Multiset \u2115) h\n  rw [Multiset.coe_prod] at this\n  exact this\n#align prime_multiset.prod_of_nat_list PrimeMultiset.prod_ofNatList\n\n/-- If a `List \u2115+` consists only of primes, it can be recast as a `PrimeMultiset` with\nthe coercion from lists to multisets. -/\ndef ofPNatList (l : List \u2115+) (h : \u2200 p : \u2115+, p \u2208 l \u2192 p.Prime) : PrimeMultiset :=\n  ofPNatMultiset (l : Multiset \u2115+) h\n#align prime_multiset.of_pnat_list PrimeMultiset.ofPNatList\n\ntheorem prod_ofPNatList (l : List \u2115+) (h) : (ofPNatList l h).prod = l.prod := by\n  have := prod_ofPNatMultiset (l : Multiset \u2115+) h\n  rw [Multiset.coe_prod] at this\n  exact this\n#align prime_multiset.prod_of_pnat_list PrimeMultiset.prod_ofPNatList\n\n/-- The product map gives a homomorphism from the additive monoid\nof multisets to the multiplicative monoid \u2115+. -/\ntheorem prod_zero : (0 : PrimeMultiset).prod = 1 := by\n  dsimp [Prod]\n  exact Multiset.prod_zero\n#align prime_multiset.prod_zero PrimeMultiset.prod_zero\n\ntheorem prod_add (u v : PrimeMultiset) : (u + v).prod = u.prod * v.prod := by\n  change (coePNatMonoidHom (u + v)).prod = _\n  rw [coePNatMonoidHom.map_add]\n  exact Multiset.prod_add _ _\n#align prime_multiset.prod_add PrimeMultiset.prod_add\n\n-- Porting note: Need to replace ^ with Pow.pow to get the original mathlib statement\ntheorem prod_smul (d : \u2115) (u : PrimeMultiset) : (d \u2022 u).prod = Pow.pow u.prod d := by\n  induction' d with n ih\n  \u00b7 rfl\n  \u00b7 have : \u2200 n' : \u2115, Pow.pow (prod u) n' = Monoid.npow n' (prod u) := fun _ \u21a6 rfl\n    rw [succ_nsmul, prod_add, ih, this, this, Monoid.npow_succ, mul_comm]\n#align prime_multiset.prod_smul PrimeMultiset.prod_smul\n\nend PrimeMultiset\n\nnamespace PNat\n\n/-- The prime factors of n, regarded as a multiset -/\ndef factorMultiset (n : \u2115+) : PrimeMultiset :=\n  PrimeMultiset.ofNatList (Nat.factors n) (@Nat.prime_of_mem_factors n)\n#align pnat.factor_multiset PNat.factorMultiset\n\n/-- The product of the factors is the original number -/\ntheorem prod_factorMultiset (n : \u2115+) : (factorMultiset n).prod = n :=\n  eq <| by\n    dsimp [factorMultiset]\n    rw [PrimeMultiset.prod_ofNatList]\n    exact Nat.prod_factors n.ne_zero\n#align pnat.prod_factor_multiset PNat.prod_factorMultiset\n\ntheorem coeNat_factorMultiset (n : \u2115+) :\n    (factorMultiset n : Multiset \u2115) = (Nat.factors n : Multiset \u2115) :=\n  PrimeMultiset.to_ofNatMultiset (Nat.factors n) (@Nat.prime_of_mem_factors n)\n#align pnat.coe_nat_factor_multiset PNat.coeNat_factorMultiset\n\nend PNat\n\nnamespace PrimeMultiset\n\n/-- If we start with a multiset of primes, take the product and\n then factor it, we get back the original multiset. -/\ntheorem factorMultiset_prod (v : PrimeMultiset) : v.prod.factorMultiset = v := by\n  apply PrimeMultiset.coeNat_injective\n  suffices toNatMultiset (PNat.factorMultiset (prod v)) = toNatMultiset v by exact this\n  rw [v.prod.coeNat_factorMultiset, PrimeMultiset.coe_prod]\n  rcases v with \u27e8l\u27e9\n  --unfold_coes\n  dsimp [PrimeMultiset.toNatMultiset]\n  rw [Multiset.coe_prod]\n  let l' := l.map (Coe.coe : Nat.Primes \u2192 \u2115)\n  have : \u2200 p : \u2115, p \u2208 l' \u2192 p.Prime := fun p hp => by\n    rcases List.mem_map.mp hp with \u27e8\u27e8_, hp'\u27e9, \u27e8_, h_eq\u27e9\u27e9\n    exact h_eq \u25b8 hp'\n  exact Multiset.coe_eq_coe.mpr (@Nat.factors_unique _ l' rfl this).symm\n#align prime_multiset.factor_multiset_prod PrimeMultiset.factorMultiset_prod\n\nend PrimeMultiset\n\nnamespace PNat\n\n/-- Positive integers biject with multisets of primes. -/\ndef factorMultisetEquiv : \u2115+ \u2243 PrimeMultiset\n    where\n  toFun := factorMultiset\n  invFun := PrimeMultiset.prod\n  left_inv := prod_factorMultiset\n  right_inv := PrimeMultiset.factorMultiset_prod\n#align pnat.factor_multiset_equiv PNat.factorMultisetEquiv\n\n/-- Factoring gives a homomorphism from the multiplicative\n monoid \u2115+ to the additive monoid of multisets. -/\n\n\ntheorem factorMultiset_mul (n m : \u2115+) :\n    factorMultiset (n * m) = factorMultiset n + factorMultiset m := by\n  let u := factorMultiset n\n  let v := factorMultiset m\n  have : n = u.prod := (prod_factorMultiset n).symm; rw [this]\n  have : m = v.prod := (prod_factorMultiset m).symm; rw [this]\n  rw [\u2190 PrimeMultiset.prod_add]\n  repeat' rw [PrimeMultiset.factorMultiset_prod]\n#align pnat.factor_multiset_mul PNat.factorMultiset_mul\n\ntheorem factorMultiset_pow (n : \u2115+) (m : \u2115) :\n    factorMultiset (Pow.pow n m ) = m \u2022 factorMultiset n := by\n  let u := factorMultiset n\n  have : n = u.prod := (prod_factorMultiset n).symm\n  rw [this, \u2190 PrimeMultiset.prod_smul]\n  repeat' rw [PrimeMultiset.factorMultiset_prod]\n#align pnat.factor_multiset_pow PNat.factorMultiset_pow\n\n/-- Factoring a prime gives the corresponding one-element multiset. -/\ntheorem factorMultiset_ofPrime (p : Nat.Primes) :\n    (p : \u2115+).factorMultiset = PrimeMultiset.ofPrime p := by\n  apply factorMultisetEquiv.symm.injective\n  change (p : \u2115+).factorMultiset.prod = (PrimeMultiset.ofPrime p).prod\n  rw [(p : \u2115+).prod_factorMultiset, PrimeMultiset.prod_ofPrime]\n#align pnat.factor_multiset_of_prime PNat.factorMultiset_ofPrime\n\n/-- We now have four different results that all encode the\n idea that inequality of multisets corresponds to divisibility\n of positive integers. -/\ntheorem factorMultiset_le_iff {m n : \u2115+} : factorMultiset m \u2264 factorMultiset n \u2194 m \u2223 n := by\n  constructor\n  \u00b7 intro h\n    rw [\u2190 prod_factorMultiset m, \u2190 prod_factorMultiset m]\n    apply Dvd.intro (n.factorMultiset - m.factorMultiset).prod\n    rw [\u2190 PrimeMultiset.prod_add, PrimeMultiset.factorMultiset_prod, add_tsub_cancel_of_le h,\n      prod_factorMultiset]\n  \u00b7 intro h\n    rw [\u2190 mul_div_exact h, factorMultiset_mul]\n    exact le_self_add\n#align pnat.factor_multiset_le_iff PNat.factorMultiset_le_iff\n\ntheorem factorMultiset_le_iff' {m : \u2115+} {v : PrimeMultiset} : factorMultiset m \u2264 v \u2194 m \u2223 v.prod :=\n  by\n  let h := @factorMultiset_le_iff m v.prod\n  rw [v.factorMultiset_prod] at h\n  exact h\n#align pnat.factor_multiset_le_iff' PNat.factorMultiset_le_iff'\n\nend PNat\n\nnamespace PrimeMultiset\n\ntheorem prod_dvd_iff {u v : PrimeMultiset} : u.prod \u2223 v.prod \u2194 u \u2264 v := by\n  let h := @PNat.factorMultiset_le_iff' u.prod v\n  rw [u.factorMultiset_prod] at h\n  exact h.symm\n#align prime_multiset.prod_dvd_iff PrimeMultiset.prod_dvd_iff\n\ntheorem prod_dvd_iff' {u : PrimeMultiset} {n : \u2115+} : u.prod \u2223 n \u2194 u \u2264 n.factorMultiset := by\n  let h := @prod_dvd_iff u n.factorMultiset\n  rw [n.prod_factorMultiset] at h\n  exact h\n#align prime_multiset.prod_dvd_iff' PrimeMultiset.prod_dvd_iff'\n\nend PrimeMultiset\n\nnamespace PNat\n\n/-- The gcd and lcm operations on positive integers correspond\n to the inf and sup operations on multisets. -/\ntheorem factorMultiset_gcd (m n : \u2115+) :\n    factorMultiset (gcd m n) = factorMultiset m \u2293 factorMultiset n := by\n  apply le_antisymm\n  \u00b7 apply le_inf_iff.mpr ; constructor <;> apply factorMultiset_le_iff.mpr\n    exact gcd_dvd_left m n\n    exact gcd_dvd_right m n\n  \u00b7 rw [\u2190 PrimeMultiset.prod_dvd_iff, prod_factorMultiset]\n    apply dvd_gcd <;> rw [PrimeMultiset.prod_dvd_iff']\n    exact inf_le_left\n    exact inf_le_right\n#align pnat.factor_multiset_gcd PNat.factorMultiset_gcd\n\ntheorem factorMultiset_lcm (m n : \u2115+) :\n    factorMultiset (lcm m n) = factorMultiset m \u2294 factorMultiset n := by\n  apply le_antisymm\n  \u00b7 rw [\u2190 PrimeMultiset.prod_dvd_iff, prod_factorMultiset]\n    apply lcm_dvd <;> rw [\u2190 factorMultiset_le_iff']\n    exact le_sup_left\n    exact le_sup_right\n  \u00b7 apply sup_le_iff.mpr ; constructor <;> apply factorMultiset_le_iff.mpr\n    exact dvd_lcm_left m n\n    exact dvd_lcm_right m n\n#align pnat.factor_multiset_lcm PNat.factorMultiset_lcm\n\n/-- The number of occurrences of p in the factor multiset of m\n is the same as the p-adic valuation of m. -/\ntheorem count_factorMultiset (m : \u2115+) (p : Nat.Primes) (k : \u2115) :\n    Pow.pow (p : \u2115+) k \u2223 m \u2194 k \u2264 m.factorMultiset.count p := by\n  intros\n  rw [Multiset.le_count_iff_replicate_le, \u2190 factorMultiset_le_iff, factorMultiset_pow,\n    factorMultiset_ofPrime]\n  congr! 2\n  apply Multiset.eq_replicate.mpr\n  constructor\n  \u00b7 rw [Multiset.card_nsmul, PrimeMultiset.card_ofPrime, mul_one]\n  \u00b7 intro q h\n    rw [PrimeMultiset.ofPrime, Multiset.nsmul_singleton _ k] at h\n    exact Multiset.eq_of_mem_replicate h\n#align pnat.count_factor_multiset PNat.count_factorMultiset\n\nend PNat\n\nnamespace PrimeMultiset\n\ntheorem prod_inf (u v : PrimeMultiset) : (u \u2293 v).prod = PNat.gcd u.prod v.prod := by\n  let n := u.prod\n  let m := v.prod\n  change (u \u2293 v).prod = PNat.gcd n m\n  have : u = n.factorMultiset := u.factorMultiset_prod.symm; rw [this]\n  have : v = m.factorMultiset := v.factorMultiset_prod.symm; rw [this]\n  rw [\u2190 PNat.factorMultiset_gcd n m, PNat.prod_factorMultiset]\n#align prime_multiset.prod_inf PrimeMultiset.prod_inf\n\ntheorem prod_sup (u v : PrimeMultiset) : (u \u2294 v).prod = PNat.lcm u.prod v.prod := by\n  let n := u.prod\n  let m := v.prod\n  change (u \u2294 v).prod = PNat.lcm n m\n  have : u = n.factorMultiset := u.factorMultiset_prod.symm; rw [this]\n  have : v = m.factorMultiset := v.factorMultiset_prod.symm; rw [this]\n  rw [\u2190 PNat.factorMultiset_lcm n m, PNat.prod_factorMultiset]\n#align prime_multiset.prod_sup PrimeMultiset.prod_sup\n\nend PrimeMultiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/PNat/Factors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7275230873567335}}
{"text": "import data.nat.basic\n\nsection\nvariables x y : \u2115\n\ndef double := x + x\n\n#check double\n#check double (2 * x)\n\nlocal attribute [simp] add_assoc add_comm add_left_comm\n\ntheorem t1 : double (x + y) = double x + double y :=\nby simp [double]\n\n#check t1 y\n#check t1 (2 * x)\n\ntheorem t2 : double (x * y) = double x * y :=\nby simp [double, add_mul]\n\nend\n\nsection\nvariables (x y z : \u2115)\nvariables (h\u2081 : x = y) (h\u2082 : y = z)\n\ninclude h\u2081 h\u2082\ntheorem foo : x = z :=\nbegin\n  rw [h\u2081, h\u2082],\nend\nomit h\u2081 h\u2082\n\ntheorem bar : x = z :=\neq.trans h\u2081 h\u2082\n\ntheorem baz : x = x := rfl\n\n#check @foo\n#check @bar \n#check @baz\n\nend\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/06-Interacting-with-Lean/example-6.2-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7275230866393323}}
{"text": "import SciLean.Core.Defs\nimport SciLean.Core.Tactic.FunctionTransformation.AttribInit\n\nnamespace SciLean\n\n\n#check differential\n\n@[fun_trans_def]\ndef diff {X Y} [Vec X] [Vec Y] (f : X \u2192 Y) : X \u2192 X \u2192 Y := sorry\n\n@[fun_trans_def]\ndef inv {X Y} [Nonempty X] (f : X \u2192 Y) : Y \u2192 X := sorry\n\n\n@[fun_trans_rule]\ntheorem diff_id (X) [Vec X]\n  : diff (\u03bb x : X => x)\n    =\n    \u03bb x dx => dx := sorry\n\n@[fun_trans_rule]\ntheorem diff_const {X} (Y : Type) [Vec X] [Vec Y] (x : X)\n  : diff (\u03bb y : Y => x)\n    =\n    \u03bb y dy => 0 := sorry\n\n@[fun_trans_rule]\ntheorem diff_comp {X Y Z} [Vec X] [Vec Y] [Vec Z]\n  (f : Y \u2192 Z) (g : X \u2192 Y)\n  : diff (\u03bb x : X => f (g x))\n    =\n    \u03bb x dx => diff f (g x) (diff g x dx) := sorry\n\n@[fun_trans_rule]\ntheorem diff_swap {\u03b1 X Y : Type} [Vec X] [Vec Y]\n  (f : \u03b1 \u2192 X \u2192 Y) \n  : diff (\u03bb (x : X) (a : \u03b1) => f a x)\n    =\n    \u03bb x dx a => diff (f a) x dx := sorry\n\n@[fun_trans_rule]\ntheorem diff_forallMap {\u03b1 X Y : Type} [Vec X] [Vec Y]\n  (f : \u03b1 \u2192 X \u2192 Y)\n  : diff (\u03bb (g : \u03b1 \u2192 X) (a : \u03b1) => f a (g a))\n    =\n    \u03bb g dg a => diff (f a) (g a) (dg a) := sorry\n\n@[fun_trans_rule]\ntheorem diff_eval {\u03b1} (X) [Vec X] (a : \u03b1)\n  : diff (\u03bb (f : \u03b1 \u2192 X) => f a)\n    =\n    \u03bb f df => df a := sorry\n\n@[fun_trans_rule]\ntheorem diff_letE {X Y Z} [Vec X] [Vec Y] [Vec Z]\n  (f : X \u2192 Y \u2192 Z) (g : X \u2192 Y)\n  : diff (\u03bb (x : X) => let y := g x; f x y)\n    =\n    \u03bb x dx =>\n      let y  := g x\n      let dy := diff g x dx \n      diff (\u03bb xy => f xy.1 xy.2) (x,y) (dx,dy) := sorry\n\n@[fun_trans_rule]\ntheorem diff_letComp {X Y Z} [Vec X] [Vec Y] [Vec Z]\n  (f : Y \u2192 Z) (g : X \u2192 Y)\n  : diff (\u03bb (x : X) => let y := g x; f y)\n    =\n    \u03bb x dx =>\n      let y  := g x\n      let dy := diff g x dx \n      diff f y dy := sorry\n\n\n@[fun_trans]\ntheorem diff_fst (X Y) [Vec X] [Vec Y]\n  : diff (\u03bb (xy : X\u00d7Y) => xy.1)\n    =\n    \u03bb xy dxy => dxy.1 := sorry\n\n\n@[fun_trans_rule]\ntheorem inv_id (X) [Nonempty X]\n  : inv (\u03bb x : X => x)\n    =\n    \u03bb x => x := sorry\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/SciLean/Core/Tactic/FunctionTransformation/Test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7275230832147123}}
{"text": "import formula\nimport semantics\nimport schemas\nimport model_theory.basic\nimport model_theory.terms_and_formulas\nimport data.fin.basic\nimport data.fin.vec_notation\n\nopen first_order.language\nopen first_order.language.bounded_formula\n\nvariables {vars : Type} [denumerable vars] {W : Type} [nonempty W]\nvariables {A B C : form vars}\n\n/-- Classes of models defined by a property of their frames. -/\ndef \ud835\udd3d (F_prop : \u2200 {W : Type}, (W \u2192 W \u2192 Prop) \u2192 Prop) : set frame :=\n{F | F_prop F.R}\n\ndef \ud835\udd3d_reflexive : set frame :=\n\ud835\udd3d (\u03bb W R, \u2200 w, R w w)\n\ndef \ud835\udd3d_transitive : set frame :=\n\ud835\udd3d (\u03bb W R, is_trans W R)\n\ndef \ud835\udd3d_euclidean : set frame :=\n\ud835\udd3d (\u03bb W R, \u2200 u v w, R u v \u2192 R u w \u2192 R v w)\n\ndef \ud835\udd3d_converse_well_founded : set frame :=\n\ud835\udd3d (\u03bb W R, well_founded (flip R))\n\n@[simp]\nlemma \ud835\udd3d_reflexive_def (F : frame) : F \u2208 \ud835\udd3d_reflexive \u2194 \u2200 w, F.R w w :=\nby simp only [\ud835\udd3d_reflexive, \ud835\udd3d, set.mem_set_of_eq] \n\n/-- A is true in a frame F iff M \u22a9 A for every model M based on F. -/\ndef frame_eval (F : frame) (A : form vars) := \u2200 V, \u27e8F, V\u27e9 \u22a9 A\nnotation F ` \u22a9 ` A := frame_eval F A\nnotation F ` \u22ae ` A := \u00ac frame_eval F A\n\ntheorem frame_eval_and (F : frame) : (F \u22a9 A) \u2227 (F \u22a9 B) \u2194 (F \u22a9 A \u22c0 B) :=\nbegin\n  simp [frame_eval, \u2190forall_and_distrib],\nend\n\n/-- A is valid in a class of frames \ud835\udd3d iff F \u22a8 A for every frame F \u2208 \ud835\udd3d. -/\ndef class_frame_valid (\ud835\udd3d : set frame) (A : form vars) := \u2200 F \u2208 \ud835\udd3d, F \u22a9 A\nnotation \ud835\udd3d ` \u22a8 ` A := class_frame_valid \ud835\udd3d A\n\ndef defines (A : form vars) (\ud835\udd3d : set frame) := \n\u2200 F, F \u2208 \ud835\udd3d \u2194 (F \u22a9 A)\n\ntheorem \ud835\udd3d_reflexive_is_definable {p : vars} \n: defines (\u25a1 \u2983p\u2984 \u27f9 \u2983p\u2984) \ud835\udd3d_reflexive := \nbegin\n  intro F,\n  simp only [\ud835\udd3d_reflexive_def, diamond_eq_not_box_not],\n  split,\n  { -- This direction is easy: if \u25a1 p holds at w, then p holds at all worlds \n    -- related to w, which includes w itself by the reflexivity of R.\n    intros hF V w,\n    simp only [eval, not_forall, set.not_not_mem, exists_prop],\n    intro hw,\n    exact hw w (hF w)\n  },\n  { -- Suppose for a contradiction R is not reflexive\n    intros hT w,\n    by_contra,\n    -- so we have a world w s.t. h : \u00ac R w w.\n    -- We want to contradict against hT, which states T is true at all worlds \n    -- under all valuations\n    simp only [frame_eval, eval] at hT,\n    -- so we need a valuation that falsifies T at some world.\n    -- i.e. makes \u25a1 p true but p false at w (the only world we have in scope)\n    -- Since \u00ac R w w, w is not included in the following set so p is false at w\n    -- However, \u25a1 p is true at w since p is true in all worlds related to w by\n    -- construction.\n    let V := \u03bb _, {w' | F.R w w'},\n    specialize hT V w,\n    have := mt hT h,\n    simp only [set.mem_set_of_eq, imp_self, forall_const, not_true] at this,\n    exact this\n  }\nend\n\n/-- Transitive frames are defined by formula 4 (name due to historical reasons)\n-/\ntheorem \ud835\udd3d_transitive_is_definable {p : vars} \n: defines (\u25c7 \u25c7 \u2983p\u2984 \u27f9 \u25c7 \u2983p\u2984) \ud835\udd3d_transitive :=\nbegin\n  intro F,\n  split,\n  { simp only [frame_eval, eval, not_forall, set.not_not_mem, exists_prop, \n               not_exists, not_and, forall_exists_index, and_imp],\n    rintros \u27e8hF\u27e9 V u v huv w hvw hw,\n    use w,\n    exact \u27e8hF u v w huv hvw, hw\u27e9\n  },\n  { -- as before we prove by contradiction and forming a valuation that \n    -- falsifies the defining formula from the assumption that F is intransitive\n    intros h4,\n    refine \u27e8_\u27e9,\n    intros u v w huv hvw,\n    by_contra,\n    let V := \u03bb _, {w}, -- so from world u, only \u25c7 \u25c7 p holds but not \u25c7 p since p \n                      -- is not true in v\n    simp only [frame_eval, eval, not_forall, set.not_not_mem, exists_prop, \n               not_exists, not_and, forall_exists_index, and_imp] at h4,\n    specialize h4 V u v huv w hvw (set.mem_singleton w),\n    simp only [set.mem_singleton_iff, exists_eq_right] at h4,\n    exact h h4\n  }\nend\n\n/-- Euclidean frames are defined by formula 5 (again, historical reasons)-/\ntheorem \ud835\udd3d_euclidean_is_definable {p : vars} \n: defines (\u25c7 \u2983p\u2984 \u27f9 \u25a1 \u25c7 \u2983p\u2984) \ud835\udd3d_euclidean :=\nbegin\n  intro F,\n  split,\n  { simp only [frame_eval, eval, not_forall, set.not_not_mem, exists_prop, forall_exists_index, and_imp],\n    rintros hF V u w huw hw v huv,\n    use w,\n    exact \u27e8hF u v w huv huw, hw\u27e9\n  },\n  { intros h5 u v w huv huw,\n    by_contra,\n    -- since \u00ac F.R v w, w is in this set so \u25c7 p holds in u by virtue of R u w.\n    -- However, by construction \u25c7 p does not hold in v as p is false in all the \n    -- worlds accessible from v, so \u25a1 \u25c7 p does not hold in u. \n    let V := \u03bb_, {z | \u00ac F.R v z},\n    simp only [frame_eval, eval, not_forall, set.not_not_mem, exists_prop, \n               not_exists, not_and, forall_exists_index, and_imp] at h5,\n    specialize h5 V u w huw h v huv,\n    simp at h5,\n    exact h5\n  }\nend\n\ntheorem \ud835\udd3d_inter {\ud835\udd3d\u2081 \ud835\udd3d\u2082 : set frame} (h1 : defines A \ud835\udd3d\u2081) (h2 : defines B \ud835\udd3d\u2082)\n: defines (A \u22c0 B) (\ud835\udd3d\u2081 \u2229 \ud835\udd3d\u2082) :=\nbegin\n  intro F,\n  simp only [set.mem_inter_eq],\n  rw [h1, h2],\n  exact frame_eval_and F,\nend\n\n/-- The Lob formula characterise frames that are transitive and converse \nwell-founded.-/\ntheorem \ud835\udd3d_transitive_converse_well_founded_is_definable {p : vars}\n: defines (\u25a1 (\u25a1 \u2983p\u2984 \u27f9 \u2983p\u2984) \u27f9 \u25a1 \u2983p\u2984) (\ud835\udd3d_transitive \u2229 \ud835\udd3d_converse_well_founded)\n:= begin\n  intro F,\n  split,\n  { intros hF V w,\n    rcases hF with \u27e8htrans, hwf\u27e9,\n    simp [\ud835\udd3d_converse_well_founded, \ud835\udd3d] at hwf,\n    -- Supppose for a contradiction that the defining formula is not true in F\n    by_contra,\n    -- So we have a world w s.t. w \u22a9 \u25a1 (\u25a1 p \u27f9 p) but w \u22ae \u25a1 p\n    unfold1 eval at h,\n    simp only [not_forall, exists_prop] at h,\n    rcases h with \u27e8h1, h2\u27e9,\n    -- From this, we can form an infinite chain w\u2081Rw\u2082... of worlds to\n    -- contradict R's (converse) wellfoundness.\n    -- Since w \u22ae \u25a1 p, w has an R-successor w\u2081 s.t.  w\u2081 \u22ae p.\n    -- Since w \u22a9 \u25a1 (\u25a1 p \u27f9 p). w\u2081 \u22a9 \u25a1 p \u27f9 p. So by modus tolens, w\u2081 \u22ae \u25a1 p.\n    -- Now we can repeat the argument: since w\u1d62 \u22ae \u25a1 p then w\u1d62\u208a\u2081 \u22ae p for some\n    -- successor w\u1d62\u208a\u2081 of w\u1d62. By transitivity, w\u1d62\u208a\u2081 is also a successor of w so\n    -- w\u1d62\u208a\u2081 \u22a9 \u25a1 p \u27f9 p and hence we can conclude w\u1d62\u208a\u2081 \u22ae \u25a1 p.\n\n    -- To formalise this argument, we find a maximal world a satisfying the\n    -- required conditions using the (converse) wellfoundness of R. We apply the\n    -- inductive part of the argument to effectively show that since a = w\u1d62 for\n    -- some i, then a' = w\u1d62\u208a\u2081 is an R-successor of a, so in fact a is not the\n    -- maximal world. This gives the required contradiction.\n    haveI : is_trans F.W F.R := by { simp [\ud835\udd3d_transitive, \ud835\udd3d] at htrans, exact htrans },\n    -- the min of the flipped R is the max of R.\n    obtain \u27e8a, ha, hwf\u27e9 := \n      well_founded.has_min hwf \n      {u | F.R w u \u2227\n        (\u27eaF, V\u27eb@@u \u22a9 \u25a1 \u2983p\u2984 \u27f9 \u2983p\u2984) \u2227\n        (\u27eaF, V\u27eb@@u \u22ae (\u25a1 \u2983p\u2984))} \n      -- the base case forms the proof of nonemptiness\n      \u27e8_, _\u27e9,\n    rotate,\n\n    -- The base case\n    unfold1 eval at h2,\n    simp only [not_forall, exists_prop] at h2,\n    let w\u2081 := classical.some h2,\n    exact w\u2081,\n    unfold1 eval at h2,\n    simp only [not_forall, exists_prop] at h2,\n    obtain \u27e8hww\u2081, h2\u27e9 := classical.some_spec h2,\n    exact \u27e8hww\u2081, h1 _ hww\u2081, mt (h1 _ hww\u2081) h2\u27e9,\n\n    -- The inductive case \n    obtain \u27e8hwa, ih1, ih2\u27e9 := ha,\n    unfold1 eval at ih2, simp only [not_forall, exists_prop] at ih2,\n    rcases ih2 with \u27e8a', haa', ih2\u27e9,\n    have hwa' := trans hwa haa',\n    specialize hwf a' \u27e8hwa', h1 a' hwa', mt (h1 a' hwa') ih2\u27e9,\n    simp [inv_image, flip] at hwf,\n    exact hwf haa',\n  }, {\n    sorry -- not enough time!\n  }\nend\n\n/-- The first order frame language with one 2-ary relation symbol. -/\ndef L : first_order.language := {\n  functions := \u03bb _, empty,\n  relations := \u03bb n, match n with\n    | 2 := unit\n    | n := empty\n  end\n}\n\ndef realize_sentence' (M : L.Structure W) (S : L.sentence) \n:= realize_sentence W S\n\ndef first_order_definable (\ud835\udd3d : set frame) (S : L.sentence) :=\nbegin\n  refine \u2200 F, F \u2208 \ud835\udd3d \u2194 _,\n  let M : L.Structure F.W := {\n    fun_map := \u03bb n e args, empty.elim e, \n    rel_map := \u03bb n t args, match n, args with\n    | 2, args := F.R (args 0) (args 1)\n    | n, args := false\n    end\n  },\n  -- M \u22a8 S\n  exact realize_sentence' M S,\nend\n\ntheorem \ud835\udd3d_reflexive_is_fodefinable : first_order_definable \ud835\udd3d_reflexive\n(bounded_formula.all \n  (@relations.bounded_formula L empty 2 1 () \n    ![term.var (sum.inr 0), term.var (sum.inr 0)]))\n:= begin\n  -- It turns out you don't even need the simp...\n  -- but I don't actualy understand what's going on unless I simp it so\n  -- leave this here just in case.\n  -- simp only [first_order_definable, realize_sentence', realize_sentence,\n  --            formula.realize, realize_all, realize_rel, term.realize,\n  --            matrix.cons_val_zero, sum.elim_inr, matrix.cons_val_one, \n  --            matrix.head_cons, \ud835\udd3d_reflexive, \ud835\udd3d, set.mem_set_of_eq],\n  intro F,\n  split,\n  { intros hF, exact hF },\n  { intros h, exact h }\nend\n\n/- The key reason for using this embedded first-order language is I wanted\nto show that the converse-wellfounded + transitive class from before cannot\nbe defined by a first-order sentence. I never got around to it, but I still\nlearned about using lean's definitions for first-order logic.-/", "meta": {"author": "alyata", "repo": "formalising-math-2", "sha": "30a001f2ff3d54a8a3432a178d0314a4abda57aa", "save_path": "github-repos/lean/alyata-formalising-math-2", "path": "github-repos/lean/alyata-formalising-math-2/formalising-math-2-30a001f2ff3d54a8a3432a178d0314a4abda57aa/src/frame_definability.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7275182091191124}}
{"text": "/-\nCopyright (c) 2020 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport ring_theory.polynomial.cyclotomic.basic\nimport topology.algebra.polynomial\nimport field_theory.finite.basic\n\n/-!\n# Primes congruent to one\n\nWe prove that, for any positive `k : \u2115`, there are infinitely many primes `p` such that\n`p \u2261 1 [MOD k]`.\n-/\n\nnamespace nat\n\nopen polynomial nat filter\n\n/-- For any positive `k : \u2115` there are infinitely many primes `p` such that `p \u2261 1 [MOD k]`. -/\nlemma exists_prime_ge_modeq_one (k n : \u2115) (hpos : 0 < k) :\n  \u2203 (p : \u2115), nat.prime p \u2227 n \u2264 p \u2227 p \u2261 1 [MOD k] :=\nbegin\n  have hli : tendsto (abs \u2218 (\u03bb (a : \u2115), |(a : \u211a)|)) at_top at_top,\n  { simp only [(\u2218), abs_cast],\n    exact nat.strict_mono_cast.monotone.tendsto_at_top_at_top exists_nat_ge },\n  have hcff : int.cast_ring_hom \u211a (cyclotomic k \u2124).leading_coeff \u2260 0,\n  { simp only [cyclotomic.monic, ring_hom.eq_int_cast, monic.leading_coeff, int.cast_one, ne.def,\n     not_false_iff, one_ne_zero] },\n  obtain \u27e8a, ha\u27e9 := tendsto_at_top_at_top.1 (tendsto_abv_eval\u2082_at_top (int.cast_ring_hom \u211a)\n    abs (cyclotomic k \u2124) (degree_cyclotomic_pos k \u2124 hpos) hcff hli) 2,\n  let b := a * (k * n.factorial),\n  have hgt : 1 < (eval \u2191(a * (k * n.factorial)) (cyclotomic k \u2124)).nat_abs,\n  { suffices hgtabs : 1 < |eval \u2191b (cyclotomic k \u2124)|,\n    { rw [int.abs_eq_nat_abs] at hgtabs,\n      exact_mod_cast hgtabs },\n    suffices hgtrat : 1 < |eval \u2191b (cyclotomic k \u211a)|,\n    { rw [\u2190 map_cyclotomic_int k \u211a, \u2190 int.cast_coe_nat, \u2190 int.coe_cast_ring_hom, eval_map,\n        eval\u2082_hom, int.coe_cast_ring_hom] at hgtrat,\n      assumption_mod_cast },\n    suffices hleab : a \u2264 b,\n    { replace ha := lt_of_lt_of_le one_lt_two (ha b hleab),\n      rwa [\u2190 eval_map, map_cyclotomic_int k \u211a, abs_cast] at ha },\n    exact le_mul_of_pos_right (mul_pos hpos (factorial_pos n)) },\n  let p := min_fac (eval \u2191b (cyclotomic k \u2124)).nat_abs,\n  haveI hprime : fact p.prime := \u27e8min_fac_prime (ne_of_lt hgt).symm\u27e9,\n  have hroot : is_root (cyclotomic k (zmod p)) (cast_ring_hom (zmod p) b),\n  { rw [is_root.def, \u2190 map_cyclotomic_int k (zmod p), eval_map, coe_cast_ring_hom,\n    \u2190 int.cast_coe_nat, \u2190 int.coe_cast_ring_hom, eval\u2082_hom, int.coe_cast_ring_hom,\n      zmod.int_coe_zmod_eq_zero_iff_dvd _ _],\n    apply int.dvd_nat_abs.1,\n    exact_mod_cast min_fac_dvd (eval \u2191b (cyclotomic k \u2124)).nat_abs },\n  refine \u27e8p, hprime.1, _, _\u27e9,\n  { by_contra habs,\n    exact (prime.dvd_iff_not_coprime hprime.1).1\n      (dvd_factorial (min_fac_pos _) (le_of_not_ge habs))\n      (coprime_of_root_cyclotomic hpos hroot).symm.coprime_mul_left_right.coprime_mul_left_right },\n  { have hdiv := order_of_dvd_of_pow_eq_one (zmod.units_pow_card_sub_one_eq_one p\n      (zmod.unit_of_coprime b (coprime_of_root_cyclotomic hpos hroot))),\n    have : \u00acp \u2223 k := hprime.1.coprime_iff_not_dvd.1\n      (coprime_of_root_cyclotomic hpos hroot).symm.coprime_mul_left_right.coprime_mul_right_right,\n    haveI := ne_zero.of_not_dvd (zmod p) this,\n    have : k = order_of (b : zmod p) := (is_root_cyclotomic_iff.mp hroot).eq_order_of,\n    rw [\u2190order_of_units, zmod.coe_unit_of_coprime, \u2190this] at hdiv,\n    exact ((modeq_iff_dvd' hprime.1.pos).2 hdiv).symm }\nend\n\nlemma frequently_at_top_modeq_one (k : \u2115) (hpos : 0 < k) :\n  \u2203\u1da0 p in at_top, nat.prime p \u2227 p \u2261 1 [MOD k] :=\nbegin\n  refine frequently_at_top.2 (\u03bb n, _),\n  obtain \u27e8p, hp\u27e9 := exists_prime_ge_modeq_one k n hpos,\n  exact \u27e8p, \u27e8hp.2.1, hp.1, hp.2.2\u27e9\u27e9\nend\n\nlemma infinite_set_of_prime_modeq_one (k : \u2115) (hpos : 0 < k) :\n  set.infinite {p : \u2115 | nat.prime p \u2227 p \u2261 1 [MOD k]} :=\nfrequently_at_top_iff_infinite.1 (frequently_at_top_modeq_one k hpos)\n\nend nat\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/number_theory/primes_congruent_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7274933816025634}}
{"text": "-- Relacion_entre_los_indices_de_las_subsucesiones_y_de_la_sucesion.lean\n-- Relaci\u00f3n entre los \u00edndices de las subsucesiones y los de la sucesi\u00f3n\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 29 de agosto de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Para extraer una subsucesi\u00f3n se aplica una funci\u00f3n de extracci\u00f3n que\n-- conserva el orden; por ejemplo, la subsucesi\u00f3n\n--    u\u2092, u\u2082, u\u2084, u\u2086, ...\n-- se ha obtenido con la funci\u00f3n de extracci\u00f3n \u03c6 tal que \u03c6(n) = 2*n.\n--\n-- En Lean, se puede definir que \u03c6 es una funci\u00f3n de extracci\u00f3n por\n--    def extraccion (\u03c6 : \u2115 \u2192 \u2115) :=\n--      \u2200 {n m}, n < m \u2192 \u03c6 n < \u03c6 m\n--\n-- Demostrar que si \u03c6 es una funci\u00f3n de extracci\u00f3n, entonces\n--    \u2200 n, n \u2264 \u03c6 n\n-- ---------------------------------------------------------------------\n\nimport tactic\nopen nat\n\nvariable {\u03c6 : \u2115 \u2192 \u2115}\n\nset_option pp.structure_projections false\n\ndef extraccion (\u03c6 : \u2115 \u2192 \u2115) :=\n  \u2200 {n m}, n < m \u2192 \u03c6 n < \u03c6 m\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  extraccion \u03c6 \u2192 \u2200 n, n \u2264 \u03c6 n :=\nbegin\n  intros h n,\n  induction n with m HI,\n  { exact nat.zero_le (\u03c6 0), },\n  { apply nat.succ_le_of_lt,\n    have h1 : m < succ m := lt_add_one m,\n    calc m \u2264 \u03c6 m        : HI\n       ... < \u03c6 (succ m) : h h1, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  extraccion \u03c6 \u2192 \u2200 n, n \u2264 \u03c6 n :=\nbegin\n  intros h n,\n  induction n with m HI,\n  { exact nat.zero_le (\u03c6 0), },\n  { apply nat.succ_le_of_lt,\n    calc m \u2264 \u03c6 m        : HI\n       ... < \u03c6 (succ m) : h (lt_add_one m), },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  extraccion \u03c6 \u2192 \u2200 n, n \u2264 \u03c6 n :=\nassume h : extraccion \u03c6,\nassume n,\nnat.rec_on n\n  ( show 0 \u2264 \u03c6 0,\n      from nat.zero_le (\u03c6 0) )\n  ( assume m,\n    assume HI : m \u2264 \u03c6 m,\n    have h1 : m < succ m,\n      from lt_add_one m,\n    have h2 : m < \u03c6 (succ m), from\n      calc m \u2264 \u03c6 m        : HI\n         ... < \u03c6 (succ m) : h h1,\n    show succ m \u2264 \u03c6 (succ m),\n      from nat.succ_le_of_lt h2)\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Relacion_entre_los_indices_de_las_subsucesiones_y_de_la_sucesion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7274933609725136}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport data.set.function\nimport logic.function.iterate\n\n/-!\n# Fixed points of a self-map\n\nIn this file we define\n\n* the predicate `is_fixed_pt f x := f x = x`;\n* the set `fixed_points f` of fixed points of a self-map `f`.\n\nWe also prove some simple lemmas about `is_fixed_pt` and `\u2218`, `iterate`, and `semiconj`.\n\n## Tags\n\nfixed point\n-/\n\nuniverses u v\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {f fa g : \u03b1 \u2192 \u03b1} {x y : \u03b1} {fb : \u03b2 \u2192 \u03b2} {m n k : \u2115}\n\nnamespace function\n\n/-- A point `x` is a fixed point of `f : \u03b1 \u2192 \u03b1` if `f x = x`. -/\ndef is_fixed_pt (f : \u03b1 \u2192 \u03b1) (x : \u03b1) := f x = x\n\n/-- Every point is a fixed point of `id`. -/\nlemma is_fixed_pt_id (x : \u03b1) : is_fixed_pt id x := (rfl : _)\n\nnamespace is_fixed_pt\n\ninstance [h : decidable_eq \u03b1] {f : \u03b1 \u2192 \u03b1} {x : \u03b1} : decidable (is_fixed_pt f x) :=\nh (f x) x\n\n/-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`.-/\nprotected \n\n/-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f \u2218 g`. -/\nprotected lemma comp (hf : is_fixed_pt f x) (hg : is_fixed_pt g x) : is_fixed_pt (f \u2218 g) x :=\ncalc f (g x) = f x : congr_arg f hg\n         ... = x   : hf\n\n/-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/\nprotected lemma iterate (hf : is_fixed_pt f x) (n : \u2115) : is_fixed_pt (f^[n]) x :=\niterate_fixed hf n\n\n/-- If `x` is a fixed point of `f \u2218 g` and `g`, then it is a fixed point of `f`. -/\nlemma left_of_comp (hfg : is_fixed_pt (f \u2218 g) x) (hg : is_fixed_pt g x) : is_fixed_pt f x :=\ncalc f x = f (g x) : congr_arg f hg.symm\n     ... = x       : hfg\n\n/-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed\npoint of `g`. -/\nlemma to_left_inverse (hf : is_fixed_pt f x) (h : left_inverse g f) : is_fixed_pt g x :=\ncalc g x = g (f x) : congr_arg g hf.symm\n     ... = x       : h x\n\n/-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\nprotected lemma map {x : \u03b1} (hx : is_fixed_pt fa x) {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) :\n  is_fixed_pt fb (g x) :=\ncalc fb (g x) = g (fa x) : (h.eq x).symm\n          ... = g x      : congr_arg g hx\n\nend is_fixed_pt\n\n/-- The set of fixed points of a map `f : \u03b1 \u2192 \u03b1`. -/\ndef fixed_points (f : \u03b1 \u2192 \u03b1) : set \u03b1 := {x : \u03b1 | is_fixed_pt f x}\n\ninstance fixed_points.decidable [decidable_eq \u03b1] (f : \u03b1 \u2192 \u03b1) (x : \u03b1) :\n  decidable (x \u2208 fixed_points f) :=\nis_fixed_pt.decidable\n\n@[simp] lemma mem_fixed_points : x \u2208 fixed_points f \u2194 is_fixed_pt f x := iff.rfl\n\n@[simp] lemma fixed_points_id : fixed_points (@id \u03b1) = set.univ :=\nset.ext $ \u03bb _, by simpa using is_fixed_pt_id _\n\n/-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\nlemma semiconj.maps_to_fixed_pts {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) :\n  set.maps_to g (fixed_points fa) (fixed_points fb) :=\n\u03bb x hx, hx.map h\n\n/-- Any two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1` are inverse of each other on the sets of fixed points\nof `f \u2218 g` and `g \u2218 f`, respectively. -/\nlemma inv_on_fixed_pts_comp (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n  set.inv_on f g (fixed_points $ f \u2218 g) (fixed_points $ g \u2218 f) :=\n\u27e8\u03bb x, id, \u03bb x, id\u27e9\n\n/-- Any map `f` sends fixed points of `g \u2218 f` to fixed points of `f \u2218 g`. -/\nlemma maps_to_fixed_pts_comp (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n  set.maps_to f (fixed_points $ g \u2218 f) (fixed_points $ f \u2218 g) :=\n\u03bb x hx, hx.map $ \u03bb x, rfl\n\n/-- Given two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1`, `g` is a bijective map between the fixed points\nof `f \u2218 g` and the fixed points of `g \u2218 f`. The inverse map is `f`, see `inv_on_fixed_pts_comp`. -/\nlemma bij_on_fixed_pts_comp (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n  set.bij_on g (fixed_points $ f \u2218 g) (fixed_points $ g \u2218 f) :=\n(inv_on_fixed_pts_comp f g).bij_on (maps_to_fixed_pts_comp g f) (maps_to_fixed_pts_comp f g)\n\n/-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points\nof `f \u2218 g`. This is a particular case of `function.inv_on_fixed_pts_comp`. -/\nlemma commute.inv_on_fixed_pts_comp (h : commute f g) :\n  set.inv_on f g (fixed_points $ f \u2218 g) (fixed_points $ f \u2218 g) :=\nby simpa only [h.comp_eq] using inv_on_fixed_pts_comp f g\n\n/-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\nlemma commute.left_bij_on_fixed_pts_comp (h : commute f g) :\n  set.bij_on f (fixed_points $ f \u2218 g) (fixed_points $ f \u2218 g) :=\nby simpa only [h.comp_eq] using bij_on_fixed_pts_comp g f\n\n/-- If self-maps `f` and `g` commute, then `g` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\nlemma commute.right_bij_on_fixed_pts_comp (h : commute f g) :\n  set.bij_on g (fixed_points $ f \u2218 g) (fixed_points $ f \u2218 g) :=\nby simpa only [h.comp_eq] using bij_on_fixed_pts_comp f g\n\nend function\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/dynamics/fixed_points/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985637, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.7274933530117288}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard,\nAmelia Livingston, Yury Kudryashov\n-/\nimport group_theory.submonoid.operations\nimport algebra.big_operators.basic\nimport algebra.free_monoid.basic\nimport data.finset.noncomm_prod\n\n/-!\n# Submonoids: membership criteria\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove various facts about membership in a submonoid:\n\n* `list_prod_mem`, `multiset_prod_mem`, `prod_mem`: if each element of a collection belongs\n  to a multiplicative submonoid, then so does their product;\n* `list_sum_mem`, `multiset_sum_mem`, `sum_mem`: if each element of a collection belongs\n  to an additive submonoid, then so does their sum;\n* `pow_mem`, `nsmul_mem`: if `x \u2208 S` where `S` is a multiplicative (resp., additive) submonoid and\n  `n` is a natural number, then `x^n` (resp., `n \u2022 x`) belongs to `S`;\n* `mem_supr_of_directed`, `coe_supr_of_directed`, `mem_Sup_of_directed_on`,\n  `coe_Sup_of_directed_on`: the supremum of a directed collection of submonoid is their union.\n* `sup_eq_range`, `mem_sup`: supremum of two submonoids `S`, `T` of a commutative monoid is the set\n  of products;\n* `closure_singleton_eq`, `mem_closure_singleton`, `mem_closure_pair`: the multiplicative (resp.,\n  additive) closure of `{x}` consists of powers (resp., natural multiples) of `x`, and a similar\n  result holds for the closure of `{x, y}`.\n\n## Tags\nsubmonoid, submonoids\n-/\n\nopen_locale big_operators\n\nvariables {M A B : Type*}\n\nsection assoc\nvariables [monoid M] [set_like B M] [submonoid_class B M] {S : B}\n\nnamespace submonoid_class\n\n@[simp, norm_cast, to_additive] theorem coe_list_prod (l : list S) :\n  (l.prod : M) = (l.map coe).prod :=\n(submonoid_class.subtype S : _ \u2192* M).map_list_prod l\n\n@[simp, norm_cast, to_additive] theorem coe_multiset_prod {M} [comm_monoid M] [set_like B M]\n  [submonoid_class B M] (m : multiset S) : (m.prod : M) = (m.map coe).prod :=\n(submonoid_class.subtype S : _ \u2192* M).map_multiset_prod m\n\n@[simp, norm_cast, to_additive] theorem coe_finset_prod {\u03b9 M} [comm_monoid M] [set_like B M]\n  [submonoid_class B M] (f : \u03b9 \u2192 S) (s : finset \u03b9) :\n  \u2191(\u220f i in s, f i) = (\u220f i in s, f i : M) :=\n(submonoid_class.subtype S : _ \u2192* M).map_prod f s\n\nend submonoid_class\n\nopen submonoid_class\n\n/-- Product of a list of elements in a submonoid is in the submonoid. -/\n@[to_additive \"Sum of a list of elements in an `add_submonoid` is in the `add_submonoid`.\"]\nlemma list_prod_mem {l : list M} (hl : \u2200 x \u2208 l, x \u2208 S) : l.prod \u2208 S :=\nby { lift l to list S using hl, rw \u2190 coe_list_prod, exact l.prod.coe_prop }\n\n/-- Product of a multiset of elements in a submonoid of a `comm_monoid` is in the submonoid. -/\n@[to_additive \"Sum of a multiset of elements in an `add_submonoid` of an `add_comm_monoid` is\nin the `add_submonoid`.\"]\nlemma multiset_prod_mem {M} [comm_monoid M] [set_like B M] [submonoid_class B M] (m : multiset M)\n  (hm : \u2200 a \u2208 m, a \u2208 S) : m.prod \u2208 S :=\nby { lift m to multiset S using hm, rw \u2190 coe_multiset_prod, exact m.prod.coe_prop }\n\n/-- Product of elements of a submonoid of a `comm_monoid` indexed by a `finset` is in the\n    submonoid. -/\n@[to_additive \"Sum of elements in an `add_submonoid` of an `add_comm_monoid` indexed by a `finset`\nis in the `add_submonoid`.\"]\nlemma prod_mem {M : Type*} [comm_monoid M] [set_like B M] [submonoid_class B M]\n  {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 M} (h : \u2200c \u2208 t, f c \u2208 S) :\n  \u220f c in t, f c \u2208 S :=\nmultiset_prod_mem (t.1.map f) $ \u03bb x hx, let \u27e8i, hi, hix\u27e9 := multiset.mem_map.1 hx in hix \u25b8 h i hi\n\nnamespace submonoid\n\nvariables (s : submonoid M)\n\n@[simp, norm_cast, to_additive] theorem coe_list_prod (l : list s) :\n  (l.prod : M) = (l.map coe).prod :=\ns.subtype.map_list_prod l\n\n@[simp, norm_cast, to_additive] theorem coe_multiset_prod {M} [comm_monoid M] (S : submonoid M)\n  (m : multiset S) : (m.prod : M) = (m.map coe).prod :=\nS.subtype.map_multiset_prod m\n\n@[simp, norm_cast, to_additive] theorem coe_finset_prod {\u03b9 M} [comm_monoid M] (S : submonoid M)\n  (f : \u03b9 \u2192 S) (s : finset \u03b9) :\n  \u2191(\u220f i in s, f i) = (\u220f i in s, f i : M) :=\nS.subtype.map_prod f s\n\n/-- Product of a list of elements in a submonoid is in the submonoid. -/\n@[to_additive \"Sum of a list of elements in an `add_submonoid` is in the `add_submonoid`.\"]\nlemma list_prod_mem {l : list M} (hl : \u2200 x \u2208 l, x \u2208 s) : l.prod \u2208 s :=\nby { lift l to list s using hl, rw \u2190 coe_list_prod, exact l.prod.coe_prop }\n\n/-- Product of a multiset of elements in a submonoid of a `comm_monoid` is in the submonoid. -/\n@[to_additive \"Sum of a multiset of elements in an `add_submonoid` of an `add_comm_monoid` is\nin the `add_submonoid`.\"]\nlemma multiset_prod_mem {M} [comm_monoid M] (S : submonoid M) (m : multiset M)\n  (hm : \u2200 a \u2208 m, a \u2208 S) : m.prod \u2208 S :=\nby { lift m to multiset S using hm, rw \u2190 coe_multiset_prod, exact m.prod.coe_prop }\n\n@[to_additive]\nlemma multiset_noncomm_prod_mem (S : submonoid M) (m : multiset M) (comm) (h : \u2200 (x \u2208 m), x \u2208 S) :\n  m.noncomm_prod comm \u2208 S :=\nbegin\n  induction m using quotient.induction_on with l,\n  simp only [multiset.quot_mk_to_coe, multiset.noncomm_prod_coe],\n  exact submonoid.list_prod_mem _ h,\nend\n\n/-- Product of elements of a submonoid of a `comm_monoid` indexed by a `finset` is in the\n    submonoid. -/\n@[to_additive \"Sum of elements in an `add_submonoid` of an `add_comm_monoid` indexed by a `finset`\nis in the `add_submonoid`.\"]\nlemma prod_mem {M : Type*} [comm_monoid M] (S : submonoid M)\n  {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 M} (h : \u2200c \u2208 t, f c \u2208 S) :\n  \u220f c in t, f c \u2208 S :=\nS.multiset_prod_mem (t.1.map f) $ \u03bb x hx, let \u27e8i, hi, hix\u27e9 := multiset.mem_map.1 hx in hix \u25b8 h i hi\n\n@[to_additive]\nlemma noncomm_prod_mem (S : submonoid M) {\u03b9 : Type*} (t : finset \u03b9) (f : \u03b9 \u2192 M) (comm)\n  (h : \u2200 c \u2208 t, f c \u2208 S) :\n  t.noncomm_prod f comm \u2208 S :=\nbegin\n  apply multiset_noncomm_prod_mem,\n  intro y,\n  rw multiset.mem_map,\n  rintros \u27e8x, \u27e8hx, rfl\u27e9\u27e9,\n  exact h x hx,\nend\n\nend submonoid\n\nend assoc\n\nsection non_assoc\nvariables [mul_one_class M]\n\nopen set\n\nnamespace submonoid\n\n-- TODO: this section can be generalized to `[submonoid_class B M] [complete_lattice B]`\n-- such that `complete_lattice.le` coincides with `set_like.le`\n\n@[to_additive]\nlemma mem_supr_of_directed {\u03b9} [h\u03b9 : nonempty \u03b9] {S : \u03b9 \u2192 submonoid M} (hS : directed (\u2264) S)\n  {x : M} :\n  x \u2208 (\u2a06 i, S i) \u2194 \u2203 i, x \u2208 S i :=\nbegin\n  refine \u27e8_, \u03bb \u27e8i, hi\u27e9, (set_like.le_def.1 $ le_supr S i) hi\u27e9,\n  suffices : x \u2208 closure (\u22c3 i, (S i : set M)) \u2192 \u2203 i, x \u2208 S i,\n    by simpa only [closure_Union, closure_eq (S _)] using this,\n  refine (\u03bb hx, closure_induction hx (\u03bb _, mem_Union.1) _ _),\n  { exact h\u03b9.elim (\u03bb i, \u27e8i, (S i).one_mem\u27e9) },\n  { rintros x y \u27e8i, hi\u27e9 \u27e8j, hj\u27e9,\n    rcases hS i j with \u27e8k, hki, hkj\u27e9,\n    exact \u27e8k, (S k).mul_mem (hki hi) (hkj hj)\u27e9 }\nend\n\n@[to_additive]\nlemma coe_supr_of_directed {\u03b9} [nonempty \u03b9] {S : \u03b9 \u2192 submonoid M} (hS : directed (\u2264) S) :\n  ((\u2a06 i, S i : submonoid M) : set M) = \u22c3 i, \u2191(S i) :=\nset.ext $ \u03bb x, by simp [mem_supr_of_directed hS]\n\n@[to_additive]\nlemma mem_Sup_of_directed_on {S : set (submonoid M)} (Sne : S.nonempty)\n  (hS : directed_on (\u2264) S) {x : M} :\n  x \u2208 Sup S \u2194 \u2203 s \u2208 S, x \u2208 s :=\nbegin\n  haveI : nonempty S := Sne.to_subtype,\n  simp only [Sup_eq_supr', mem_supr_of_directed hS.directed_coe, set_coe.exists, subtype.coe_mk]\nend\n\n@[to_additive]\nlemma coe_Sup_of_directed_on {S : set (submonoid M)} (Sne : S.nonempty) (hS : directed_on (\u2264) S) :\n  (\u2191(Sup S) : set M) = \u22c3 s \u2208 S, \u2191s :=\nset.ext $ \u03bb x, by simp [mem_Sup_of_directed_on Sne hS]\n\n@[to_additive]\nlemma mem_sup_left {S T : submonoid M} : \u2200 {x : M}, x \u2208 S \u2192 x \u2208 S \u2294 T :=\nshow S \u2264 S \u2294 T, from le_sup_left\n\n@[to_additive]\nlemma mem_sup_right {S T : submonoid M} : \u2200 {x : M}, x \u2208 T \u2192 x \u2208 S \u2294 T :=\nshow T \u2264 S \u2294 T, from le_sup_right\n\n@[to_additive]\nlemma mul_mem_sup {S T : submonoid M} {x y : M} (hx : x \u2208 S) (hy : y \u2208 T) : x * y \u2208 S \u2294 T :=\n(S \u2294 T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n\n@[to_additive]\nlemma mem_supr_of_mem {\u03b9 : Sort*} {S : \u03b9 \u2192 submonoid M} (i : \u03b9) :\n  \u2200 {x : M}, x \u2208 S i \u2192 x \u2208 supr S :=\nshow S i \u2264 supr S, from le_supr _ _\n\n@[to_additive]\nlemma mem_Sup_of_mem {S : set (submonoid M)} {s : submonoid M}\n  (hs : s \u2208 S) : \u2200 {x : M}, x \u2208 s \u2192 x \u2208 Sup S :=\nshow s \u2264 Sup S, from le_Sup hs\n\n/-- An induction principle for elements of `\u2a06 i, S i`.\nIf `C` holds for `1` and all elements of `S i` for all `i`, and is preserved under multiplication,\nthen it holds for all elements of the supremum of `S`. -/\n@[elab_as_eliminator, to_additive /-\" An induction principle for elements of `\u2a06 i, S i`.\nIf `C` holds for `0` and all elements of `S i` for all `i`, and is preserved under addition,\nthen it holds for all elements of the supremum of `S`. \"-/]\nlemma supr_induction {\u03b9 : Sort*} (S : \u03b9 \u2192 submonoid M) {C : M \u2192 Prop} {x : M} (hx : x \u2208 \u2a06 i, S i)\n  (hp : \u2200 i (x \u2208 S i), C x)\n  (h1 : C 1)\n  (hmul : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) : C x :=\nbegin\n  rw supr_eq_closure at hx,\n  refine closure_induction hx (\u03bb x hx, _) h1 hmul,\n  obtain \u27e8i, hi\u27e9 := set.mem_Union.mp hx,\n  exact hp _ _ hi,\nend\n\n/-- A dependent version of `submonoid.supr_induction`. -/\n@[elab_as_eliminator, to_additive /-\"A dependent version of `add_submonoid.supr_induction`. \"-/]\nlemma supr_induction' {\u03b9 : Sort*} (S : \u03b9 \u2192 submonoid M) {C : \u03a0 x, (x \u2208 \u2a06 i, S i) \u2192 Prop}\n  (hp : \u2200 i (x \u2208 S i), C x (mem_supr_of_mem i \u2039_\u203a))\n  (h1 : C 1 (one_mem _))\n  (hmul : \u2200 x y hx hy, C x hx \u2192 C y hy \u2192 C (x * y) (mul_mem \u2039_\u203a \u2039_\u203a))\n  {x : M} (hx : x \u2208 \u2a06 i, S i) : C x hx :=\nbegin\n  refine exists.elim _ (\u03bb (hx : x \u2208 \u2a06 i, S i) (hc : C x hx), hc),\n  refine supr_induction S hx (\u03bb i x hx, _) _ (\u03bb x y, _),\n  { exact \u27e8_, hp _ _ hx\u27e9 },\n  { exact \u27e8_, h1\u27e9 },\n  { rintro \u27e8_, Cx\u27e9 \u27e8_, Cy\u27e9,\n    refine \u27e8_, hmul _ _ _ _ Cx Cy\u27e9 },\nend\n\nend submonoid\n\nend non_assoc\n\nnamespace free_monoid\n\nvariables {\u03b1 : Type*}\n\nopen submonoid\n\n@[to_additive]\ntheorem closure_range_of : closure (set.range $ @of \u03b1) = \u22a4 :=\neq_top_iff.2 $ \u03bb x hx, free_monoid.rec_on x (one_mem _) $ \u03bb x xs hxs,\n  mul_mem (subset_closure $ set.mem_range_self _) hxs\n\nend free_monoid\n\nnamespace submonoid\n\nvariables [monoid M]\n\nopen monoid_hom\n\nlemma closure_singleton_eq (x : M) : closure ({x} : set M) = (powers_hom M x).mrange :=\nclosure_eq_of_le (set.singleton_subset_iff.2 \u27e8multiplicative.of_add 1, pow_one x\u27e9) $\n  \u03bb x \u27e8n, hn\u27e9, hn \u25b8 pow_mem (subset_closure $ set.mem_singleton _) _\n\n/-- The submonoid generated by an element of a monoid equals the set of natural number powers of\n    the element. -/\nlemma mem_closure_singleton {x y : M} : y \u2208 closure ({x} : set M) \u2194 \u2203 n:\u2115, x^n=y :=\nby rw [closure_singleton_eq, mem_mrange]; refl\n\nlemma mem_closure_singleton_self {y : M} : y \u2208 closure ({y} : set M) :=\nmem_closure_singleton.2 \u27e81, pow_one y\u27e9\n\nlemma closure_singleton_one : closure ({1} : set M) = \u22a5 :=\nby simp [eq_bot_iff_forall, mem_closure_singleton]\n\n@[to_additive] lemma _root_.free_monoid.mrange_lift {\u03b1} (f : \u03b1 \u2192 M) :\n  (free_monoid.lift f).mrange = closure (set.range f) :=\nby rw [mrange_eq_map, \u2190 free_monoid.closure_range_of, map_mclosure, \u2190 set.range_comp,\n  free_monoid.lift_comp_of]\n\n@[to_additive]\nlemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift (coe : s \u2192 M)).mrange :=\nby rw [free_monoid.mrange_lift, subtype.range_coe]\n\n@[to_additive] lemma closure_eq_image_prod (s : set M) :\n  (closure s : set M) = list.prod '' {l : list M | \u2200 x \u2208 l, x \u2208 s} :=\nbegin\n  rw [closure_eq_mrange, coe_mrange, \u2190 set.range_list_map_coe, \u2190 set.range_comp],\n  exact congr_arg _ (funext $ free_monoid.lift_apply _)\nend\n\n@[to_additive]\nlemma exists_list_of_mem_closure {s : set M} {x : M} (hx : x \u2208 closure s) :\n  \u2203 (l : list M) (hl : \u2200 y \u2208 l, y \u2208 s), l.prod = x :=\nby rwa [\u2190 set_like.mem_coe, closure_eq_image_prod, set.mem_image_iff_bex] at hx\n\n@[to_additive]\nlemma exists_multiset_of_mem_closure {M : Type*} [comm_monoid M] {s : set M}\n  {x : M} (hx : x \u2208 closure s) : \u2203 (l : multiset M) (hl : \u2200 y \u2208 l, y \u2208 s), l.prod = x :=\nbegin\n  obtain \u27e8l, h1, h2\u27e9 := exists_list_of_mem_closure hx,\n  exact \u27e8l, h1, (multiset.coe_prod l).trans h2\u27e9,\nend\n\n@[to_additive]\nlemma closure_induction_left {s : set M} {p : M \u2192 Prop} {x : M} (h : x \u2208 closure s) (H1 : p 1)\n  (Hmul : \u2200 (x \u2208 s) y, p y \u2192 p (x * y)) : p x :=\nbegin\n  rw closure_eq_mrange at h,\n  obtain \u27e8l, rfl\u27e9 := h,\n  induction l using free_monoid.rec_on with x y ih,\n  { exact H1 },\n  { simpa only [map_mul, free_monoid.lift_eval_of] using Hmul _ x.prop _ ih }\nend\n\n@[elab_as_eliminator, to_additive]\nlemma induction_of_closure_eq_top_left {s : set M} {p : M \u2192 Prop} (hs : closure s = \u22a4) (x : M)\n  (H1 : p 1) (Hmul : \u2200 (x \u2208 s) y, p y \u2192 p (x * y)) : p x :=\nclosure_induction_left (by { rw [hs], exact mem_top _ }) H1 Hmul\n\n@[to_additive]\nlemma closure_induction_right {s : set M} {p : M \u2192 Prop} {x : M} (h : x \u2208 closure s) (H1 : p 1)\n  (Hmul : \u2200 x (y \u2208 s), p x \u2192 p (x * y)) : p x :=\n@closure_induction_left _ _ (mul_opposite.unop \u207b\u00b9' s) (p \u2218 mul_opposite.unop) (mul_opposite.op x)\n  (closure_induction h (\u03bb x hx, subset_closure hx) (one_mem _) (\u03bb x y hx hy, mul_mem hy hx))\n  H1 (\u03bb x hx y, Hmul _ _ hx)\n\n@[elab_as_eliminator, to_additive]\nlemma induction_of_closure_eq_top_right {s : set M} {p : M \u2192 Prop} (hs : closure s = \u22a4) (x : M)\n  (H1 : p 1) (Hmul : \u2200 x (y \u2208 s), p x \u2192 p (x * y)) : p x :=\nclosure_induction_right (by { rw [hs], exact mem_top _ }) H1 Hmul\n\n/-- The submonoid generated by an element. -/\ndef powers (n : M) : submonoid M :=\nsubmonoid.copy (powers_hom M n).mrange (set.range ((^) n : \u2115 \u2192 M)) $\nset.ext (\u03bb n, exists_congr $ \u03bb i, by simp; refl)\n\n@[simp] lemma mem_powers (n : M) : n \u2208 powers n := \u27e81, pow_one _\u27e9\n\nlemma mem_powers_iff (x z : M) : x \u2208 powers z \u2194 \u2203 n : \u2115, z ^ n = x := iff.rfl\n\nlemma powers_eq_closure (n : M) : powers n = closure {n} :=\nby { ext, exact mem_closure_singleton.symm }\n\nlemma powers_subset {n : M} {P : submonoid M} (h : n \u2208 P) : powers n \u2264 P :=\n\u03bb x hx, match x, hx with _, \u27e8i, rfl\u27e9 := pow_mem h i end\n\n@[simp] lemma powers_one : powers (1 : M) = \u22a5 := bot_unique $ powers_subset (one_mem _)\n\n/-- Exponentiation map from natural numbers to powers. -/\n@[simps] def pow (n : M) (m : \u2115) : powers n :=\n(powers_hom M n).mrange_restrict (multiplicative.of_add m)\n\nlemma pow_apply (n : M) (m : \u2115) : submonoid.pow n m = \u27e8n ^ m, m, rfl\u27e9 := rfl\n\n/-- Logarithms from powers to natural numbers. -/\ndef log [decidable_eq M] {n : M} (p : powers n) : \u2115 :=\nnat.find $ (mem_powers_iff p.val n).mp p.prop\n\n@[simp] theorem pow_log_eq_self [decidable_eq M] {n : M} (p : powers n) : pow n (log p) = p :=\nsubtype.ext $ nat.find_spec p.prop\n\nlemma pow_right_injective_iff_pow_injective {n : M} :\n  function.injective (\u03bb m : \u2115, n ^ m) \u2194 function.injective (pow n) :=\nsubtype.coe_injective.of_comp_iff (pow n)\n\n@[simp] theorem log_pow_eq_self [decidable_eq M] {n : M} (h : function.injective (\u03bb m : \u2115, n ^ m))\n  (m : \u2115) : log (pow n m) = m :=\npow_right_injective_iff_pow_injective.mp h $ pow_log_eq_self _\n\n/-- The exponentiation map is an isomorphism from the additive monoid on natural numbers to powers\nwhen it is injective. The inverse is given by the logarithms. -/\n@[simps]\ndef pow_log_equiv [decidable_eq M] {n : M} (h : function.injective (\u03bb m : \u2115, n ^ m)) :\n  multiplicative \u2115 \u2243* powers n :=\n{ to_fun := \u03bb m, pow n m.to_add,\n  inv_fun := \u03bb m, multiplicative.of_add (log m),\n  left_inv := log_pow_eq_self h,\n  right_inv := pow_log_eq_self,\n  map_mul' := \u03bb _ _, by { simp only [pow, map_mul, of_add_add, to_add_mul] } }\n\nlemma log_mul [decidable_eq M] {n : M} (h : function.injective (\u03bb m : \u2115, n ^ m))\n  (x y : powers (n : M)) : log (x * y) = log x + log y := (pow_log_equiv h).symm.map_mul x y\n\ntheorem log_pow_int_eq_self {x : \u2124} (h : 1 < x.nat_abs) (m : \u2115) : log (pow x m) = m :=\n(pow_log_equiv (int.pow_right_injective h)).symm_apply_apply _\n\n@[simp] lemma map_powers {N : Type*} {F : Type*} [monoid N] [monoid_hom_class F M N]\n  (f : F) (m : M) : (powers m).map f = powers (f m) :=\nby simp only [powers_eq_closure, map_mclosure f, set.image_singleton]\n\n/-- If all the elements of a set `s` commute, then `closure s` is a commutative monoid. -/\n@[to_additive \"If all the elements of a set `s` commute, then `closure s` forms an additive\ncommutative monoid.\"]\ndef closure_comm_monoid_of_comm {s : set M} (hcomm : \u2200 a b \u2208 s, a * b = b * a) :\n  comm_monoid (closure s) :=\n{ mul_comm := \u03bb x y,\n  begin\n    ext,\n    simp only [submonoid.coe_mul],\n    exact closure_induction\u2082 x.prop y.prop hcomm commute.one_left commute.one_right\n      (\u03bb x y z, commute.mul_left) (\u03bb x y z, commute.mul_right),\n  end,\n  .. (closure s).to_monoid }\n\nend submonoid\n\n@[to_additive] lemma is_scalar_tower.of_mclosure_eq_top {N \u03b1} [monoid M] [mul_action M N]\n  [has_smul N \u03b1] [mul_action M \u03b1] {s : set M} (htop : submonoid.closure s = \u22a4)\n  (hs : \u2200 (x \u2208 s) (y : N) (z : \u03b1), (x \u2022 y) \u2022 z = x \u2022 (y \u2022 z)) :\n  is_scalar_tower M N \u03b1 :=\nbegin\n  refine \u27e8\u03bb x, submonoid.induction_of_closure_eq_top_left htop x _ _\u27e9,\n  { intros y z, rw [one_smul, one_smul] },\n  { clear x, intros x hx x' hx' y z, rw [mul_smul, mul_smul, hs x hx, hx'] }\nend\n\n@[to_additive] lemma smul_comm_class.of_mclosure_eq_top {N \u03b1} [monoid M]\n  [has_smul N \u03b1] [mul_action M \u03b1] {s : set M} (htop : submonoid.closure s = \u22a4)\n  (hs : \u2200 (x \u2208 s) (y : N) (z : \u03b1), x \u2022 y \u2022 z = y \u2022 x \u2022 z) :\n  smul_comm_class M N \u03b1 :=\nbegin\n  refine \u27e8\u03bb x, submonoid.induction_of_closure_eq_top_left htop x _ _\u27e9,\n  { intros y z, rw [one_smul, one_smul] },\n  { clear x, intros x hx x' hx' y z, rw [mul_smul, mul_smul, hx', hs x hx] }\nend\n\nnamespace submonoid\n\nvariables {N : Type*} [comm_monoid N]\n\nopen monoid_hom\n\n@[to_additive]\nlemma sup_eq_range (s t : submonoid N) : s \u2294 t = (s.subtype.coprod t.subtype).mrange :=\nby rw [mrange_eq_map, \u2190 mrange_inl_sup_mrange_inr, map_sup, map_mrange, coprod_comp_inl,\n  map_mrange, coprod_comp_inr, range_subtype, range_subtype]\n\n@[to_additive]\nlemma mem_sup {s t : submonoid N} {x : N} :\n  x \u2208 s \u2294 t \u2194 \u2203 (y \u2208 s) (z \u2208 t), y * z = x :=\nby simp only [sup_eq_range, mem_mrange, coprod_apply, prod.exists, set_like.exists,\n  coe_subtype, subtype.coe_mk]\n\nend submonoid\n\nnamespace add_submonoid\n\nvariables [add_monoid A]\n\nopen set\n\nlemma closure_singleton_eq (x : A) : closure ({x} : set A) = (multiples_hom A x).mrange :=\nclosure_eq_of_le (set.singleton_subset_iff.2 \u27e81, one_nsmul x\u27e9) $\n  \u03bb x \u27e8n, hn\u27e9, hn \u25b8 nsmul_mem (subset_closure $ set.mem_singleton _) _\n\n/-- The `add_submonoid` generated by an element of an `add_monoid` equals the set of\nnatural number multiples of the element. -/\nlemma mem_closure_singleton {x y : A} :\n  y \u2208 closure ({x} : set A) \u2194 \u2203 n:\u2115, n \u2022 x = y :=\nby rw [closure_singleton_eq, add_monoid_hom.mem_mrange]; refl\n\nlemma closure_singleton_zero : closure ({0} : set A) = \u22a5 :=\nby simp [eq_bot_iff_forall, mem_closure_singleton, nsmul_zero]\n\n/-- The additive submonoid generated by an element. -/\ndef multiples (x : A) : add_submonoid A :=\nadd_submonoid.copy (multiples_hom A x).mrange (set.range (\u03bb i, i \u2022 x : \u2115 \u2192 A)) $\nset.ext (\u03bb n, exists_congr $ \u03bb i, by simp; refl)\n\nattribute [to_additive multiples] submonoid.powers\nattribute [to_additive mem_multiples] submonoid.mem_powers\nattribute [to_additive mem_multiples_iff] submonoid.mem_powers_iff\nattribute [to_additive multiples_eq_closure] submonoid.powers_eq_closure\nattribute [to_additive multiples_subset] submonoid.powers_subset\nattribute [to_additive multiples_zero] submonoid.powers_one\n\nend add_submonoid\n\n/-! Lemmas about additive closures of `subsemigroup`. -/\nnamespace mul_mem_class\n\nvariables {R : Type*} [non_unital_non_assoc_semiring R] [set_like M R] [mul_mem_class M R]\n  {S : M} {a b : R}\n\n/-- The product of an element of the additive closure of a multiplicative subsemigroup `M`\nand an element of `M` is contained in the additive closure of `M`. -/\nlemma mul_right_mem_add_closure\n  (ha : a \u2208 add_submonoid.closure (S : set R)) (hb : b \u2208 S) :\n  a * b \u2208 add_submonoid.closure (S : set R) :=\nbegin\n  revert b,\n  refine add_submonoid.closure_induction ha _ _ _; clear ha a,\n  { exact \u03bb r hr b hb, add_submonoid.mem_closure.mpr (\u03bb y hy, hy (mul_mem hr hb)) },\n  { exact \u03bb b hb, by simp only [zero_mul, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw add_mul,\n    exact \u03bb r s hr hs b hb, (add_submonoid.closure (S : set R)).add_mem (hr hb) (hs hb) }\nend\n\n/-- The product of two elements of the additive closure of a submonoid `M` is an element of the\nadditive closure of `M`. -/\nlemma mul_mem_add_closure\n  (ha : a \u2208 add_submonoid.closure (S : set R)) (hb : b \u2208 add_submonoid.closure (S : set R)) :\n  a * b \u2208 add_submonoid.closure (S : set R) :=\nbegin\n  revert a,\n  refine add_submonoid.closure_induction hb _ _ _; clear hb b,\n  { exact \u03bb r hr b hb, mul_mem_class.mul_right_mem_add_closure hb hr },\n  { exact \u03bb b hb, by simp only [mul_zero, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw mul_add,\n    exact \u03bb r s hr hs b hb, (add_submonoid.closure (S : set R)).add_mem (hr hb) (hs hb) }\nend\n\n/-- The product of an element of `S` and an element of the additive closure of a multiplicative\nsubmonoid `S` is contained in the additive closure of `S`. -/\nlemma mul_left_mem_add_closure (ha : a \u2208 S) (hb : b \u2208 add_submonoid.closure (S : set R)) :\n  a * b \u2208 add_submonoid.closure (S : set R) :=\nmul_mem_add_closure (add_submonoid.mem_closure.mpr (\u03bb sT hT, hT ha)) hb\n\nend mul_mem_class\n\nnamespace submonoid\n\n/-- An element is in the closure of a two-element set if it is a linear combination of those two\nelements. -/\n@[to_additive \"An element is in the closure of a two-element set if it is a linear combination of\nthose two elements.\"]\n\n\nend submonoid\n\nsection mul_add\n\nlemma of_mul_image_powers_eq_multiples_of_mul [monoid M] {x : M} :\n  additive.of_mul '' ((submonoid.powers x) : set M) = add_submonoid.multiples (additive.of_mul x) :=\nbegin\n  ext,\n  split,\n  { rintros \u27e8y, \u27e8n, hy1\u27e9, hy2\u27e9,\n    use n,\n    simpa [\u2190 of_mul_pow, hy1] },\n  { rintros \u27e8n, hn\u27e9,\n    refine \u27e8x ^ n, \u27e8n, rfl\u27e9, _\u27e9,\n    rwa of_mul_pow }\nend\n\nlemma of_add_image_multiples_eq_powers_of_add [add_monoid A] {x : A} :\n  multiplicative.of_add '' ((add_submonoid.multiples x) : set A) =\n  submonoid.powers (multiplicative.of_add x) :=\nbegin\n  symmetry,\n  rw equiv.eq_image_iff_symm_image_eq,\n  exact of_mul_image_powers_eq_multiples_of_mul,\nend\n\nend mul_add\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/submonoid/membership.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587668, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.7274488184584673}}
{"text": "/-\nCopyright (c) 2018 Louis Carlin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Louis Carlin, Mario Carneiro\n\nEuclidean domains and Euclidean algorithm (extended to come)\nA lot is based on pre-existing code in mathlib for natural number gcds\n-/\nimport data.int.basic\n\nuniverse u\n\nclass euclidean_domain (\u03b1 : Type u) extends nonzero_comm_ring \u03b1 :=\n(quotient : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(quotient_zero : \u2200 a, quotient a 0 = 0)\n(remainder : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n -- This could be changed to the same order as int.mod_add_div.\n -- We normally write qb+r rather than r + qb though.\n(quotient_mul_add_remainder_eq : \u2200 a b, b * quotient a b + remainder a b = a)\n(r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n(r_well_founded : well_founded r)\n(remainder_lt : \u2200 a {b}, b \u2260 0 \u2192 r (remainder a b) b)\n/- `val_le_mul_left` is often not a required in definitions of a euclidean\n  domain since given the other properties we can show there is a\n  (noncomputable) euclidean domain \u03b1 with the property `val_le_mul_left`.\n  So potentially this definition could be split into two different ones\n  (euclidean_domain_weak and euclidean_domain_strong) with a noncomputable\n  function from weak to strong. I've currently divided the lemmas into\n  strong and weak depending on whether they require `val_le_mul_left` or not. -/\n(mul_left_not_lt : \u2200 a {b}, b \u2260 0 \u2192 \u00acr (a * b) a)\n\nnamespace euclidean_domain\nvariable {\u03b1 : Type u}\nvariables [euclidean_domain \u03b1]\n\nlocal infix ` \u227a `:50 := euclidean_domain.r\n\ninstance : has_div \u03b1 := \u27e8quotient\u27e9\n\ninstance : has_mod \u03b1 := \u27e8remainder\u27e9\n\ntheorem div_add_mod (a b : \u03b1) : b * (a / b) + a % b = a :=\nquotient_mul_add_remainder_eq _ _\n\nlemma mod_eq_sub_mul_div {\u03b1 : Type*} [euclidean_domain \u03b1] (a b : \u03b1) :\n  a % b = a - b * (a / b) :=\ncalc a % b = b * (a / b) + a % b - b * (a / b) : (add_sub_cancel' _ _).symm\n... = a - b * (a / b) : by rw div_add_mod\n\ntheorem mod_lt : \u2200 a {b : \u03b1}, b \u2260 0 \u2192 (a % b) \u227a b :=\nremainder_lt\n\ntheorem mul_right_not_lt {a : \u03b1} (b) (h : a \u2260 0) : \u00ac(a * b) \u227a b :=\nby rw mul_comm; exact mul_left_not_lt b h\n\nlemma mul_div_cancel_left {a : \u03b1} (b) (a0 : a \u2260 0) : a * b / a = b :=\neq.symm $ eq_of_sub_eq_zero $ classical.by_contradiction $ \u03bb h,\nbegin\n  have := mul_left_not_lt a h,\n  rw [mul_sub, sub_eq_iff_eq_add'.2 (div_add_mod (a*b) a).symm] at this,\n  exact this (mod_lt _ a0)\nend\n\nlemma mul_div_cancel (a) {b : \u03b1} (b0 : b \u2260 0) : a * b / b = a :=\nby rw mul_comm; exact mul_div_cancel_left a b0\n\n@[simp] lemma mod_zero (a : \u03b1) : a % 0 = a :=\nby simpa only [zero_mul, zero_add] using div_add_mod a 0\n\n@[simp] lemma mod_eq_zero {a b : \u03b1} : a % b = 0 \u2194 b \u2223 a :=\n\u27e8\u03bb h, by rw [\u2190 div_add_mod a b, h, add_zero]; exact dvd_mul_right _ _,\n \u03bb \u27e8c, e\u27e9, begin\n  rw [e, \u2190 add_left_cancel_iff, div_add_mod, add_zero],\n  haveI := classical.dec,\n  by_cases b0 : b = 0,\n  { simp only [b0, zero_mul] },\n  { rw [mul_div_cancel_left _ b0] }\n end\u27e9\n\n@[simp] lemma mod_self (a : \u03b1) : a % a = 0 :=\nmod_eq_zero.2 (dvd_refl _)\n\nlemma dvd_mod_iff {a b c : \u03b1} (h : c \u2223 b) : c \u2223 a % b \u2194 c \u2223 a :=\nby rw [dvd_add_iff_right (dvd_mul_of_dvd_left h _), div_add_mod]\n\nlemma lt_one (a : \u03b1) : a \u227a (1:\u03b1) \u2192 a = 0 :=\nby haveI := classical.dec; exact\nnot_imp_not.1 (\u03bb h, by simpa only [one_mul] using mul_left_not_lt 1 h)\n\nlemma val_dvd_le : \u2200 a b : \u03b1, b \u2223 a \u2192 a \u2260 0 \u2192 \u00aca \u227a b\n| _ b \u27e8d, rfl\u27e9 ha := mul_left_not_lt b (mt (by rintro rfl; exact mul_zero _) ha)\n\n@[simp] lemma mod_one (a : \u03b1) : a % 1 = 0 :=\nmod_eq_zero.2 (one_dvd _)\n\n@[simp] lemma zero_mod (b : \u03b1) : 0 % b = 0 :=\nmod_eq_zero.2 (dvd_zero _)\n\n@[simp] lemma div_zero (a : \u03b1) : a / 0 = 0 :=\nquotient_zero a\n\n@[simp] lemma zero_div {a : \u03b1} : 0 / a = 0 :=\nclassical.by_cases\n  (\u03bb a0 : a = 0, a0.symm \u25b8 div_zero 0)\n  (\u03bb a0, by simpa only [zero_mul] using mul_div_cancel 0 a0)\n\n@[simp] lemma div_self {a : \u03b1} (a0 : a \u2260 0) : a / a = 1 :=\nby simpa only [one_mul] using mul_div_cancel 1 a0\n\nlemma eq_div_of_mul_eq_left {a b c : \u03b1} (hb : b \u2260 0) (h : a * b = c) : a = c / b :=\nby rw [\u2190 h, mul_div_cancel _ hb]\n\nlemma eq_div_of_mul_eq_right {a b c : \u03b1} (ha : a \u2260 0) (h : a * b = c) : b = c / a :=\nby rw [\u2190 h, mul_div_cancel_left _ ha]\n\ntheorem mul_div_assoc (x : \u03b1) {y z : \u03b1} (h : z \u2223 y) : x * y / z = x * (y / z) :=\nbegin\n  classical, by_cases hz : z = 0,\n  { subst hz, rw [div_zero, div_zero, mul_zero] },\n  rcases h with \u27e8p, rfl\u27e9,\n  rw [mul_div_cancel_left _ hz, mul_left_comm, mul_div_cancel_left _ hz]\nend\n\nsection gcd\nvariable [decidable_eq \u03b1]\n\ndef gcd : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n| a := \u03bb b, if a0 : a = 0 then b else\n  have h:_ := mod_lt b a0,\n  gcd (b%a) a\nusing_well_founded {dec_tac := tactic.assumption,\n  rel_tac := \u03bb _ _, `[exact \u27e8_, r_well_founded \u03b1\u27e9]}\n\n@[simp] theorem gcd_zero_left (a : \u03b1) : gcd 0 a = a :=\nby rw gcd; exact if_pos rfl\n\n@[simp] theorem gcd_zero_right (a : \u03b1) : gcd a 0 = a :=\nby rw gcd; split_ifs; simp only [h, zero_mod, gcd_zero_left]\n\ntheorem gcd_val (a b : \u03b1) : gcd a b = gcd (b % a) a :=\nby rw gcd; split_ifs; [simp only [h, mod_zero, gcd_zero_right], refl]\n\n@[elab_as_eliminator]\ntheorem gcd.induction {P : \u03b1 \u2192 \u03b1 \u2192 Prop} : \u2200 a b : \u03b1,\n  (\u2200 x, P 0 x) \u2192\n  (\u2200 a b, a \u2260 0 \u2192 P (b % a) a \u2192 P a b) \u2192\n  P a b\n| a := \u03bb b H0 H1, if a0 : a = 0 then by rw [a0]; apply H0 else\n  have h:_ := mod_lt b a0,\n  H1 _ _ a0 (gcd.induction (b%a) a H0 H1)\nusing_well_founded {dec_tac := tactic.assumption,\n  rel_tac := \u03bb _ _, `[exact \u27e8_, r_well_founded \u03b1\u27e9]}\n\ntheorem gcd_dvd (a b : \u03b1) : gcd a b \u2223 a \u2227 gcd a b \u2223 b :=\ngcd.induction a b\n  (\u03bb b, by rw [gcd_zero_left]; exact \u27e8dvd_zero _, dvd_refl _\u27e9)\n  (\u03bb a b aneq \u27e8IH\u2081, IH\u2082\u27e9, by rw gcd_val;\n    exact \u27e8IH\u2082, (dvd_mod_iff IH\u2082).1 IH\u2081\u27e9)\n\ntheorem gcd_dvd_left (a b : \u03b1) : gcd a b \u2223 a := (gcd_dvd a b).left\n\ntheorem gcd_dvd_right (a b : \u03b1) : gcd a b \u2223 b := (gcd_dvd a b).right\n\nprotected theorem gcd_eq_zero_iff {a b : \u03b1} :\n  gcd a b = 0 \u2194 a = 0 \u2227 b = 0 :=\n\u27e8\u03bb h, by simpa [h] using gcd_dvd a b,\n by rintro \u27e8rfl, rfl\u27e9; simp\u27e9\n\ntheorem dvd_gcd {a b c : \u03b1} : c \u2223 a \u2192 c \u2223 b \u2192 c \u2223 gcd a b :=\ngcd.induction a b\n  (\u03bb _ _ H, by simpa only [gcd_zero_left] using H)\n  (\u03bb a b a0 IH ca cb, by rw gcd_val;\n    exact IH ((dvd_mod_iff ca).2 cb) ca)\n\ntheorem gcd_eq_left {a b : \u03b1} : gcd a b = a \u2194 a \u2223 b :=\n\u27e8\u03bb h, by rw \u2190 h; apply gcd_dvd_right,\n \u03bb h, by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]\u27e9\n\n@[simp] theorem gcd_one_left (a : \u03b1) : gcd 1 a = 1 :=\ngcd_eq_left.2 (one_dvd _)\n\n@[simp] theorem gcd_self (a : \u03b1) : gcd a a = a :=\ngcd_eq_left.2 (dvd_refl _)\n\ndef xgcd_aux : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u00d7 \u03b1 \u00d7 \u03b1\n| r := \u03bb s t r' s' t',\nif hr : r = 0 then (r', s', t')\n  else\n  have r' % r \u227a r, from mod_lt _ hr,\n  let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t\nusing_well_founded {dec_tac := tactic.assumption,\n  rel_tac := \u03bb _ _, `[exact \u27e8_, r_well_founded \u03b1\u27e9]}\n\n@[simp] theorem xgcd_zero_left {s t r' s' t' : \u03b1} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=\nby unfold xgcd_aux; exact if_pos rfl\n\n@[simp] theorem xgcd_aux_rec {r s t r' s' t' : \u03b1} (h : r \u2260 0) :\n  xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=\nby conv {to_lhs, rw [xgcd_aux]}; exact if_neg h\n\n/-- Use the extended GCD algorithm to generate the `a` and `b` values\n  satisfying `gcd x y = x * a + y * b`. -/\ndef xgcd (x y : \u03b1) : \u03b1 \u00d7 \u03b1 := (xgcd_aux x 1 0 y 0 1).2\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_a (x y : \u03b1) : \u03b1 := (xgcd x y).1\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcd_b (x y : \u03b1) : \u03b1 := (xgcd x y).2\n\n@[simp] theorem xgcd_aux_fst (x y : \u03b1) : \u2200 s t s' t',\n  (xgcd_aux x s t y s' t').1 = gcd x y :=\ngcd.induction x y (by intros; rw [xgcd_zero_left, gcd_zero_left])\n(\u03bb x y h IH s t s' t', by simp only [xgcd_aux_rec h, if_neg h, IH]; rw \u2190 gcd_val)\n\ntheorem xgcd_aux_val (x y : \u03b1) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=\nby rw [xgcd, \u2190 xgcd_aux_fst x y 1 0 0 1, prod.mk.eta]\n\ntheorem xgcd_val (x y : \u03b1) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nprod.mk.eta.symm\n\nprivate def P (a b : \u03b1) : \u03b1 \u00d7 \u03b1 \u00d7 \u03b1 \u2192 Prop | (r, s, t) := (r : \u03b1) = a * s + b * t\n\ntheorem xgcd_aux_P (a b : \u03b1) {r r' : \u03b1} : \u2200 {s t s' t'}, P a b (r, s, t) \u2192\n  P a b (r', s', t') \u2192 P a b (xgcd_aux r s t r' s' t') :=\ngcd.induction r r' (by intros; simpa only [xgcd_zero_left]) $ \u03bb x y h IH s t s' t' p p', begin\n  rw [xgcd_aux_rec h], refine IH _ p, unfold P at p p' \u22a2,\n  rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, \u2190 p', sub_sub,\n    mul_comm _ s, \u2190 mul_assoc, mul_comm _ t, \u2190 mul_assoc, \u2190 add_mul, \u2190 p,\n    mod_eq_sub_mul_div]\nend\n\ntheorem gcd_eq_gcd_ab (a b : \u03b1) : (gcd a b : \u03b1) = a * gcd_a a b + b * gcd_b a b :=\nby have := @xgcd_aux_P _ _ _ a b a b 1 0 0 1\n  (by rw [P, mul_one, mul_zero, add_zero]) (by rw [P, mul_one, mul_zero, zero_add]);\nrwa [xgcd_aux_val, xgcd_val] at this\n\ninstance (\u03b1 : Type*) [e : euclidean_domain \u03b1] : integral_domain \u03b1 :=\nby haveI := classical.dec_eq \u03b1; exact\n{ eq_zero_or_eq_zero_of_mul_eq_zero :=\n    \u03bb a b (h : a * b = 0), or_iff_not_and_not.2 $ \u03bb h0 : a \u2260 0 \u2227 b \u2260 0,\n      h0.1 $ by rw [\u2190 mul_div_cancel a h0.2, h, zero_div],\n  ..e }\n\nend gcd\n\nsection lcm\nvariables [decidable_eq \u03b1]\n\ndef lcm (x y : \u03b1) : \u03b1 :=\nx * y / gcd x y\n\ntheorem dvd_lcm_left (x y : \u03b1) : x \u2223 lcm x y :=\nclassical.by_cases\n  (assume hxy : gcd x y = 0, by rw [lcm, hxy, div_zero]; exact dvd_zero _)\n  (\u03bb hxy, let \u27e8z, hz\u27e9 := (gcd_dvd x y).2 in \u27e8z, eq.symm $ eq_div_of_mul_eq_left hxy $\n    by rw [mul_right_comm, mul_assoc, \u2190 hz]\u27e9)\n\ntheorem dvd_lcm_right (x y : \u03b1) : y \u2223 lcm x y :=\nclassical.by_cases\n  (assume hxy : gcd x y = 0, by rw [lcm, hxy, div_zero]; exact dvd_zero _)\n  (\u03bb hxy, let \u27e8z, hz\u27e9 := (gcd_dvd x y).1 in \u27e8z, eq.symm $ eq_div_of_mul_eq_right hxy $\n    by rw [\u2190 mul_assoc, mul_right_comm, \u2190 hz]\u27e9)\n\ntheorem lcm_dvd {x y z : \u03b1} (hxz : x \u2223 z) (hyz : y \u2223 z) : lcm x y \u2223 z :=\nbegin\n  rw lcm, by_cases hxy : gcd x y = 0,\n  { rw [hxy, div_zero], rw euclidean_domain.gcd_eq_zero_iff at hxy, rwa hxy.1 at hxz },\n  rcases gcd_dvd x y with \u27e8\u27e8r, hr\u27e9, \u27e8s, hs\u27e9\u27e9,\n  suffices : x * y \u2223 z * gcd x y,\n  { cases this with p hp, use p,\n    generalize_hyp : gcd x y = g at hxy hs hp \u22a2, subst hs,\n    rw [mul_left_comm, mul_div_cancel_left _ hxy, \u2190 domain.mul_right_inj hxy, hp],\n    rw [\u2190 mul_assoc], simp only [mul_right_comm] },\n  rw [gcd_eq_gcd_ab, mul_add], apply dvd_add,\n  { rw mul_left_comm, exact mul_dvd_mul_left _ (dvd_mul_of_dvd_left hyz _) },\n  { rw [mul_left_comm, mul_comm], exact mul_dvd_mul_left _ (dvd_mul_of_dvd_left hxz _) }\nend\n\n@[simp] lemma lcm_dvd_iff {x y z : \u03b1} : lcm x y \u2223 z \u2194 x \u2223 z \u2227 y \u2223 z :=\n\u27e8\u03bb hz, \u27e8dvd_trans (dvd_lcm_left _ _) hz, dvd_trans (dvd_lcm_right _ _) hz\u27e9,\n\u03bb \u27e8hxz, hyz\u27e9, lcm_dvd hxz hyz\u27e9\n\n@[simp] lemma lcm_zero_left (x : \u03b1) : lcm 0 x = 0 :=\nby rw [lcm, zero_mul, zero_div]\n\n@[simp] lemma lcm_zero_right (x : \u03b1) : lcm x 0 = 0 :=\nby rw [lcm, mul_zero, zero_div]\n\n@[simp] lemma lcm_eq_zero_iff {x y : \u03b1} : lcm x y = 0 \u2194 x = 0 \u2228 y = 0 :=\nbegin\n  split,\n  { intro hxy, rw [lcm, mul_div_assoc _ (gcd_dvd_right _ _), mul_eq_zero] at hxy,\n    apply or_of_or_of_imp_right hxy, intro hy,\n    by_cases hgxy : gcd x y = 0,\n    { rw euclidean_domain.gcd_eq_zero_iff at hgxy, exact hgxy.2 },\n    { rcases gcd_dvd x y with \u27e8\u27e8r, hr\u27e9, \u27e8s, hs\u27e9\u27e9,\n      generalize_hyp : gcd x y = g at hr hs hy hgxy \u22a2, subst hs,\n      rw [mul_div_cancel_left _ hgxy] at hy, rw [hy, mul_zero] } },\n  rintro (hx | hy),\n  { rw [hx, lcm_zero_left] },\n  { rw [hy, lcm_zero_right] }\nend\n\n@[simp] lemma gcd_mul_lcm (x y : \u03b1) : gcd x y * lcm x y = x * y :=\nbegin\n  rw lcm, by_cases h : gcd x y = 0,\n  { rw [h, zero_mul], rw euclidean_domain.gcd_eq_zero_iff at h, rw [h.1, zero_mul] },\n  rcases gcd_dvd x y with \u27e8\u27e8r, hr\u27e9, \u27e8s, hs\u27e9\u27e9,\n  generalize_hyp : gcd x y = g at h hr \u22a2, subst hr,\n  rw [mul_assoc, mul_div_cancel_left _ h]\nend\n\nend lcm\n\nend euclidean_domain\n\nopen euclidean_domain\n\ninstance int.euclidean_domain : euclidean_domain \u2124 :=\n{ quotient := (/),\n  quotient_zero := int.div_zero,\n  remainder := (%),\n  quotient_mul_add_remainder_eq := \u03bb a b, by rw add_comm; exact int.mod_add_div _ _,\n  r := \u03bb a b, a.nat_abs < b.nat_abs,\n  r_well_founded := measure_wf (\u03bb a, int.nat_abs a),\n  remainder_lt := \u03bb a b b0, int.coe_nat_lt.1 $\n    by rw [int.nat_abs_of_nonneg (int.mod_nonneg _ b0), \u2190 int.abs_eq_nat_abs];\n    exact int.mod_lt _ b0,\n  mul_left_not_lt := \u03bb a b b0, not_lt_of_ge $\n    by rw [\u2190 mul_one a.nat_abs, int.nat_abs_mul];\n    exact mul_le_mul_of_nonneg_left (int.nat_abs_pos_of_ne_zero b0) (nat.zero_le _) }\n\ninstance discrete_field.to_euclidean_domain {K : Type u} [discrete_field K] : euclidean_domain K :=\n{ quotient := (/),\n  remainder := \u03bb a b, if b = 0 then a else 0,\n  quotient_zero := div_zero,\n  quotient_mul_add_remainder_eq := \u03bb a b,\n    if H : b = 0 then by rw [if_pos H, H, zero_mul, zero_add] else\n    by rw [if_neg H, add_zero, mul_div_cancel' _ H],\n  r := \u03bb a b, a = 0 \u2227 b \u2260 0,\n  r_well_founded := well_founded.intro $ \u03bb a, acc.intro _ $ \u03bb b \u27e8hb, hna\u27e9,\n    acc.intro _ $ \u03bb c \u27e8hc, hnb\u27e9, false.elim $ hnb hb,\n  remainder_lt := \u03bb a b hnb, \u27e8if_neg hnb, hnb\u27e9,\n  mul_left_not_lt := \u03bb a b hnb \u27e8hab, hna\u27e9, or.cases_on (mul_eq_zero.1 hab) hna hnb }\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/algebra/euclidean_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7274488118258428}}
{"text": "/-\nCopyright (c) S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport data.complex.determinant\nimport data.complex.is_R_or_C\n\n/-!\n# Normed space structure on `\u2102`.\n\nThis file gathers basic facts on complex numbers of an analytic nature.\n\n## Main results\n\nThis file registers `\u2102` as a normed field, expresses basic properties of the norm, and gives\ntools on the real vector space structure of `\u2102`. Notably, in the namespace `complex`,\nit defines functions:\n\n* `re_clm`\n* `im_clm`\n* `of_real_clm`\n* `conj_cle`\n\nThey are bundled versions of the real part, the imaginary part, the embedding of `\u211d` in `\u2102`, and\nthe complex conjugate as continuous `\u211d`-linear maps. The last two are also bundled as linear\nisometries in `of_real_li` and `conj_lie`.\n\nWe also register the fact that `\u2102` is an `is_R_or_C` field.\n-/\nnoncomputable theory\n\n\nnamespace complex\n\nopen_locale complex_conjugate\n\ninstance : has_norm \u2102 := \u27e8abs\u27e9\n\ninstance : normed_group \u2102 :=\nnormed_group.of_core \u2102\n{ norm_eq_zero_iff := \u03bb z, abs_eq_zero,\n  triangle := abs_add,\n  norm_neg := abs_neg }\n\ninstance : normed_field \u2102 :=\n{ norm := abs,\n  dist_eq := \u03bb _ _, rfl,\n  norm_mul' := abs_mul,\n  .. complex.field }\n\ninstance : nondiscrete_normed_field \u2102 :=\n{ non_trivial := \u27e82, by simp [norm]; norm_num\u27e9 }\n\ninstance {R : Type*} [normed_field R] [normed_algebra R \u211d] : normed_algebra R \u2102 :=\n{ norm_algebra_map_eq := \u03bb x, (abs_of_real $ algebra_map R \u211d x).trans (norm_algebra_map_eq \u211d x),\n  to_algebra := complex.algebra }\n\n/-- The module structure from `module.complex_to_real` is a normed space. -/\n@[priority 900] -- see Note [lower instance priority]\ninstance _root_.normed_space.complex_to_real {E : Type*} [normed_group E] [normed_space \u2102 E] :\n  normed_space \u211d E :=\nnormed_space.restrict_scalars \u211d \u2102 E\n\n@[simp] lemma norm_eq_abs (z : \u2102) : \u2225z\u2225 = abs z := rfl\n\nlemma dist_eq (z w : \u2102) : dist z w = abs (z - w) := rfl\n\nlemma dist_self_conj (z : \u2102) : dist z (conj z) = 2 * |z.im| :=\nby simp only [dist_eq, sub_conj, of_real_mul, of_real_bit0, of_real_one, abs_mul, abs_two,\n  abs_of_real, abs_I, mul_one]\n\nlemma dist_conj_self (z : \u2102) : dist (conj z) z = 2 * |z.im| :=\nby rw [dist_comm, dist_self_conj]\n\n@[simp] lemma norm_real (r : \u211d) : \u2225(r : \u2102)\u2225 = \u2225r\u2225 := abs_of_real _\n\n@[simp] lemma norm_rat (r : \u211a) : \u2225(r : \u2102)\u2225 = |(r : \u211d)| :=\nby { rw \u2190 of_real_rat_cast, exact norm_real _ }\n\n@[simp] lemma norm_nat (n : \u2115) : \u2225(n : \u2102)\u2225 = n := abs_of_nat _\n\n@[simp] lemma norm_int {n : \u2124} : \u2225(n : \u2102)\u2225 = |n| :=\nby simp [\u2190 rat.cast_coe_int] {single_pass := tt}\n\nlemma norm_int_of_nonneg {n : \u2124} (hn : 0 \u2264 n) : \u2225(n : \u2102)\u2225 = n :=\nby simp [hn]\n\n@[continuity] lemma continuous_abs : continuous abs := continuous_norm\n\n@[continuity] lemma continuous_norm_sq : continuous norm_sq :=\nby simpa [\u2190 norm_sq_eq_abs] using continuous_abs.pow 2\n\n@[simp, norm_cast] lemma nnnorm_real (r : \u211d) : \u2225(r : \u2102)\u2225\u208a = \u2225r\u2225\u208a :=\nsubtype.ext $ norm_real r\n\n@[simp, norm_cast] lemma nnnorm_nat (n : \u2115) : \u2225(n : \u2102)\u2225\u208a = n :=\nsubtype.ext $ by simp\n\n@[simp, norm_cast] lemma nnnorm_int (n : \u2124) : \u2225(n : \u2102)\u2225\u208a = \u2225n\u2225\u208a :=\nsubtype.ext $ by simp only [coe_nnnorm, norm_int, int.norm_eq_abs]\n\nlemma nnnorm_eq_one_of_pow_eq_one {\u03b6 : \u2102} {n : \u2115} (h : \u03b6 ^ n = 1) (hn : n \u2260 0) :\n  \u2225\u03b6\u2225\u208a = 1 :=\nbegin\n  refine (@pow_left_inj nnreal _ _ _ _ zero_le' zero_le' hn.bot_lt).mp _,\n  rw [\u2190nnnorm_pow, h, nnnorm_one, one_pow],\nend\n\nlemma norm_eq_one_of_pow_eq_one {\u03b6 : \u2102} {n : \u2115} (h : \u03b6 ^ n = 1) (hn : n \u2260 0) :\n  \u2225\u03b6\u2225 = 1 :=\ncongr_arg coe (nnnorm_eq_one_of_pow_eq_one h hn)\n\n/-- The `abs` function on `\u2102` is proper. -/\nlemma tendsto_abs_cocompact_at_top : filter.tendsto abs (filter.cocompact \u2102) filter.at_top :=\ntendsto_norm_cocompact_at_top\n\n/-- The `norm_sq` function on `\u2102` is proper. -/\nlemma tendsto_norm_sq_cocompact_at_top :\n  filter.tendsto norm_sq (filter.cocompact \u2102) filter.at_top :=\nby simpa [mul_self_abs] using\n  tendsto_abs_cocompact_at_top.at_top_mul_at_top tendsto_abs_cocompact_at_top\n\nopen continuous_linear_map\n\n/-- Continuous linear map version of the real part function, from `\u2102` to `\u211d`. -/\ndef re_clm : \u2102 \u2192L[\u211d] \u211d := re_lm.mk_continuous 1 (\u03bb x, by simp [real.norm_eq_abs, abs_re_le_abs])\n\n@[continuity] lemma continuous_re : continuous re := re_clm.continuous\n\n@[simp] lemma re_clm_coe : (coe (re_clm) : \u2102 \u2192\u2097[\u211d] \u211d) = re_lm := rfl\n\n@[simp] \n\n@[simp] lemma re_clm_norm : \u2225re_clm\u2225 = 1 :=\nle_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _) $\ncalc 1 = \u2225re_clm 1\u2225 : by simp\n   ... \u2264 \u2225re_clm\u2225 : unit_le_op_norm _ _ (by simp)\n\n/-- Continuous linear map version of the real part function, from `\u2102` to `\u211d`. -/\ndef im_clm : \u2102 \u2192L[\u211d] \u211d := im_lm.mk_continuous 1 (\u03bb x, by simp [real.norm_eq_abs, abs_im_le_abs])\n\n@[continuity] lemma continuous_im : continuous im := im_clm.continuous\n\n@[simp] lemma im_clm_coe : (coe (im_clm) : \u2102 \u2192\u2097[\u211d] \u211d) = im_lm := rfl\n\n@[simp] lemma im_clm_apply (z : \u2102) : (im_clm : \u2102 \u2192 \u211d) z = z.im := rfl\n\n@[simp] lemma im_clm_norm : \u2225im_clm\u2225 = 1 :=\nle_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _) $\ncalc 1 = \u2225im_clm I\u2225 : by simp\n   ... \u2264 \u2225im_clm\u2225 : unit_le_op_norm _ _ (by simp)\n\nlemma restrict_scalars_one_smul_right' {E : Type*} [normed_group E] [normed_space \u2102 E] (x : E) :\n  continuous_linear_map.restrict_scalars \u211d ((1 : \u2102 \u2192L[\u2102] \u2102).smul_right x : \u2102 \u2192L[\u2102] E) =\n    re_clm.smul_right x + I \u2022 im_clm.smul_right x :=\nby { ext \u27e8a, b\u27e9, simp [mk_eq_add_mul_I, add_smul, mul_smul, smul_comm I] }\n\nlemma restrict_scalars_one_smul_right (x : \u2102) :\n  continuous_linear_map.restrict_scalars \u211d ((1 : \u2102 \u2192L[\u2102] \u2102).smul_right x : \u2102 \u2192L[\u2102] \u2102) = x \u2022 1 :=\nby { ext1 z, dsimp, apply mul_comm }\n\n/-- The complex-conjugation function from `\u2102` to itself is an isometric linear equivalence. -/\ndef conj_lie : \u2102 \u2243\u2097\u1d62[\u211d] \u2102 := \u27e8conj_ae.to_linear_equiv, abs_conj\u27e9\n\n@[simp] lemma conj_lie_apply (z : \u2102) : conj_lie z = conj z := rfl\n\n@[simp] lemma conj_lie_symm : conj_lie.symm = conj_lie := rfl\n\nlemma isometry_conj : isometry (conj : \u2102 \u2192 \u2102) := conj_lie.isometry\n\n@[simp] lemma dist_conj_conj (z w : \u2102) : dist (conj z) (conj w) = dist z w :=\nisometry_conj.dist_eq z w\n\nlemma dist_conj_comm (z w : \u2102) : dist (conj z) w = dist z (conj w) :=\nby rw [\u2190 dist_conj_conj, conj_conj]\n\n/-- The determinant of `conj_lie`, as a linear map. -/\n@[simp] lemma det_conj_lie : (conj_lie.to_linear_equiv : \u2102 \u2192\u2097[\u211d] \u2102).det = -1 :=\ndet_conj_ae\n\n/-- The determinant of `conj_lie`, as a linear equiv. -/\n@[simp] lemma linear_equiv_det_conj_lie : conj_lie.to_linear_equiv.det = -1 :=\nlinear_equiv_det_conj_ae\n\n@[continuity] lemma continuous_conj : continuous (conj : \u2102 \u2192 \u2102) := conj_lie.continuous\n\n/-- Continuous linear equiv version of the conj function, from `\u2102` to `\u2102`. -/\ndef conj_cle : \u2102 \u2243L[\u211d] \u2102 := conj_lie\n\n@[simp] lemma conj_cle_coe : conj_cle.to_linear_equiv = conj_ae.to_linear_equiv := rfl\n\n@[simp] lemma conj_cle_apply (z : \u2102) : conj_cle z = conj z := rfl\n\n@[simp] lemma conj_cle_norm : \u2225(conj_cle : \u2102 \u2192L[\u211d] \u2102)\u2225 = 1 :=\nconj_lie.to_linear_isometry.norm_to_continuous_linear_map\n\n/-- Linear isometry version of the canonical embedding of `\u211d` in `\u2102`. -/\ndef of_real_li : \u211d \u2192\u2097\u1d62[\u211d] \u2102 := \u27e8of_real_am.to_linear_map, norm_real\u27e9\n\nlemma isometry_of_real : isometry (coe : \u211d \u2192 \u2102) := of_real_li.isometry\n\n@[continuity] lemma continuous_of_real : continuous (coe : \u211d \u2192 \u2102) := of_real_li.continuous\n\n/-- Continuous linear map version of the canonical embedding of `\u211d` in `\u2102`. -/\ndef of_real_clm : \u211d \u2192L[\u211d] \u2102 := of_real_li.to_continuous_linear_map\n\n@[simp] lemma of_real_clm_coe : (of_real_clm : \u211d \u2192\u2097[\u211d] \u2102) = of_real_am.to_linear_map := rfl\n\n@[simp] lemma of_real_clm_apply (x : \u211d) : of_real_clm x = x := rfl\n\n@[simp] lemma of_real_clm_norm : \u2225of_real_clm\u2225 = 1 := of_real_li.norm_to_continuous_linear_map\n\nnoncomputable instance : is_R_or_C \u2102 :=\n{ re := \u27e8complex.re, complex.zero_re, complex.add_re\u27e9,\n  im := \u27e8complex.im, complex.zero_im, complex.add_im\u27e9,\n  I := complex.I,\n  I_re_ax := by simp only [add_monoid_hom.coe_mk, complex.I_re],\n  I_mul_I_ax := by simp only [complex.I_mul_I, eq_self_iff_true, or_true],\n  re_add_im_ax := \u03bb z, by simp only [add_monoid_hom.coe_mk, complex.re_add_im,\n                                     complex.coe_algebra_map, complex.of_real_eq_coe],\n  of_real_re_ax := \u03bb r, by simp only [add_monoid_hom.coe_mk, complex.of_real_re,\n                                      complex.coe_algebra_map, complex.of_real_eq_coe],\n  of_real_im_ax := \u03bb r, by simp only [add_monoid_hom.coe_mk, complex.of_real_im,\n                                      complex.coe_algebra_map, complex.of_real_eq_coe],\n  mul_re_ax := \u03bb z w, by simp only [complex.mul_re, add_monoid_hom.coe_mk],\n  mul_im_ax := \u03bb z w, by simp only [add_monoid_hom.coe_mk, complex.mul_im],\n  conj_re_ax := \u03bb z, rfl,\n  conj_im_ax := \u03bb z, rfl,\n  conj_I_ax := by simp only [complex.conj_I, ring_hom.coe_mk],\n  norm_sq_eq_def_ax := \u03bb z, by simp only [\u2190complex.norm_sq_eq_abs, \u2190complex.norm_sq_apply,\n    add_monoid_hom.coe_mk, complex.norm_eq_abs],\n  mul_im_I_ax := \u03bb z, by simp only [mul_one, add_monoid_hom.coe_mk, complex.I_im],\n  inv_def_ax := \u03bb z, by simp only [complex.inv_def, complex.norm_sq_eq_abs, complex.coe_algebra_map,\n    complex.of_real_eq_coe, complex.norm_eq_abs],\n  div_I_ax := complex.div_I }\n\nlemma _root_.is_R_or_C.re_eq_complex_re : \u21d1(is_R_or_C.re : \u2102 \u2192+ \u211d) = complex.re := rfl\nlemma _root_.is_R_or_C.im_eq_complex_im : \u21d1(is_R_or_C.im : \u2102 \u2192+ \u211d) = complex.im := rfl\n\nsection\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n  [add_comm_monoid \u03b1] [topological_space \u03b1] [add_comm_monoid \u03b3] [topological_space \u03b3]\n\n/-- The natural `add_equiv` from `\u2102` to `\u211d \u00d7 \u211d`. -/\n@[simps apply symm_apply_re symm_apply_im { simp_rhs := tt }]\ndef equiv_real_prod_add_hom : \u2102 \u2243+ \u211d \u00d7 \u211d :=\n{ map_add' := by simp, .. equiv_real_prod }\n\n/-- The natural `linear_equiv` from `\u2102` to `\u211d \u00d7 \u211d`. -/\n@[simps apply symm_apply_re symm_apply_im { simp_rhs := tt }]\ndef equiv_real_prod_add_hom_lm : \u2102 \u2243\u2097[\u211d] \u211d \u00d7 \u211d :=\n{ map_smul' := by simp [equiv_real_prod_add_hom], .. equiv_real_prod_add_hom }\n\n/-- The natural `continuous_linear_equiv` from `\u2102` to `\u211d \u00d7 \u211d`. -/\n@[simps apply symm_apply_re symm_apply_im { simp_rhs := tt }]\ndef equiv_real_prod\u2097 : \u2102 \u2243L[\u211d] \u211d \u00d7 \u211d :=\nequiv_real_prod_add_hom_lm.to_continuous_linear_equiv\n\nend\n\nlemma has_sum_iff {\u03b1} (f : \u03b1 \u2192 \u2102) (c : \u2102) :\n  has_sum f c \u2194 has_sum (\u03bb x, (f x).re) c.re \u2227 has_sum (\u03bb x, (f x).im) c.im :=\nbegin\n  -- For some reason, `continuous_linear_map.has_sum` is orders of magnitude faster than\n  -- `has_sum.mapL` here:\n  refine \u27e8\u03bb h, \u27e8re_clm.has_sum h, im_clm.has_sum h\u27e9, _\u27e9,\n  rintro \u27e8h\u2081, h\u2082\u27e9,\n  convert (h\u2081.prod_mk h\u2082).mapL equiv_real_prod\u2097.symm.to_continuous_linear_map,\n  { ext x; refl },\n  { cases c, refl }\nend\n\nend complex\n\nnamespace is_R_or_C\n\nlocal notation `reC` := @is_R_or_C.re \u2102 _\nlocal notation `imC` := @is_R_or_C.im \u2102 _\nlocal notation `IC` := @is_R_or_C.I \u2102 _\nlocal notation `absC` := @is_R_or_C.abs \u2102 _\nlocal notation `norm_sqC` := @is_R_or_C.norm_sq \u2102 _\n\n@[simp] lemma re_to_complex {x : \u2102} : reC x = x.re := rfl\n@[simp] lemma im_to_complex {x : \u2102} : imC x = x.im := rfl\n@[simp] lemma I_to_complex : IC = complex.I := rfl\n@[simp] lemma norm_sq_to_complex {x : \u2102} : norm_sqC x = complex.norm_sq x :=\nby simp [is_R_or_C.norm_sq, complex.norm_sq]\n@[simp] lemma abs_to_complex {x : \u2102} : absC x = complex.abs x :=\nby simp [is_R_or_C.abs, complex.abs]\n\nend is_R_or_C\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7274488024505467}}
{"text": "import topology.basic data.set.intervals analysis.exponential\nopen real set\n\n-- * Example 1: y(x)=1/(2-x) is continuous on [0,2)\n\n-- This test involves a small amount of arithmetic composition; it\n-- should be slightly harder than my super-basic running examples of\n-- x and 1/x.  I'll have to understand the mechanics of mathlib\n-- style proofs better.\n\n-- As a general reflection on how this work relates to F Abstracts, I'll note that 'sorry'\n-- is a pretty handy tool for looking around the corner to see what's coming, or for \n-- making a theory\ndef twoco_interval := (Ico (0:\u211d) 2)\n\nnoncomputable def simple_rational := function.restrict (\u03bb (x:\u211d), 1/(x-2)) twoco_interval\n\nlemma simple_rational_of_twoco_items_are_nonzero :  \u2200 (a : subtype twoco_interval), a.val - 2 \u2260 0 := \nbegin\nintro,\ncases a.2 with l r,\n-- Know: 0 \u2264 a.val < 2\n--     :     a.val < 2\n-- Show: a.val -2 < 0\nhave h, from sub_neg_of_lt r,      -- lemma for moving a term from the right to the left of  <\nexact (ne_of_lt h),\nend\n\n-- I guess now that I'm getting some experience with these I can begin to see\n-- how to compress the tactic-mode proofs towards terms mode proofs.  I guess\n-- I can also see why people who understand the term style do find it convenient.\n\nlemma simple_rational_of_twoco_items_are_nonzero' :  \u2200 (a : subtype twoco_interval), a.val - 2 \u2260 0 := \n(\u03bb a, (ne_of_lt (sub_neg_of_lt a.2.2)))\n\nlemma simple_denom_over_twoco_interval_continuous : continuous (\u03bb (x : subtype twoco_interval), (x.val - 2)) := \nbegin\nrefine continuous_add _ _,\napply continuous_subtype_val,\nexact continuous_const,\nend\n\nlemma simple_rational_cont : continuous simple_rational :=\nbegin\n  unfold simple_rational function.restrict,\n  simp only [one_div_eq_inv],\n  -- This roughly follows cont_punctured_inv\n  -- an error when plonking that proof in here tells about the first lemma we need\n  -- sorry'ing that one, I get an error that explains the other needed lemma\n  -- These are then copied above and proofs filled in\n  exact continuous_inv simple_rational_of_twoco_items_are_nonzero\n                       simple_denom_over_twoco_interval_continuous,\nend\n\n#print simple_rational_cont\n\n-- * Example 2: sin(sin(x)) is continuous over [1,2].\n\n-- This again deals with composition of functions, which considered\n-- over an interval rather than over all of \\(\\mathbb{R}\\).  This\n-- example also prepares for further examples based on composition in\n-- coming weeks.\n\n-- Notice that we need to use the \u03bb because writing \"sin sin\" doesn't\n-- work.  You need to have it apply to an (x:\u211d) in order to generate\n-- a (sin_x:\u211d) for the next step\n\n#check sin\n--  sin : \u211d \u2192 \u211d\n#check (\u03bb (x:\u211d), sin(x))\n-- \u03bb (x : \u211d), sin x : \u211d \u2192 \u211d\n\ndef onetwo_interval := (Icc (1:\u211d) 2)\n\nnoncomputable def sin_sin := function.restrict (\u03bb (x:\u211d), sin(sin(x))) onetwo_interval\n\nlemma sin_sin_cont : continuous sin_sin :=\nbegin\n  unfold sin_sin function.restrict,\n  refine continuous.comp _ _,\n  apply continuous_subtype_val.comp, -- this deals with the subtype application\n  apply continuous_sin,\n  apply continuous_sin,\nend\n\nnoncomputable def sin_sin_sin := function.restrict (\u03bb (x:\u211d), sin(sin(sin(x)))) onetwo_interval\n\nlemma sin_sin_sin_cont : continuous sin_sin_sin :=\nbegin\n  unfold sin_sin_sin function.restrict,\n  refine continuous.comp _ _,\n  refine continuous.comp _ _,\n  apply continuous_subtype_val.comp, -- we only need this once\n  apply continuous_sin,\n  apply continuous_sin,\n  apply continuous_sin,\nend\n\n#print sin_sin_cont\n\n-- * Example 3: y(x)=1/2-(1/2)e^{-x^2} is continuous on (i) \u211d and (ii) [0,1].\n\n-- This includes more arithmetic combinators than the earlier\n-- examples, but (i) should follow the same style as existing mathlib\n-- proofs.  It will be interesting to see how/whether what we learn in\n-- (i) transfers to (ii).\n\n-- So this is kind of interesting, it basically looks like rippling,\n-- in which I follow the shape of the function and deal with each\n-- \"hole\" or \"box\" as it comes up.\n\n-- It's somewhat unexpected that mul_neg_one takes care of the\n-- continuity of -1, and that continuous_neg can't be used\n-- there instead.\n\nnoncomputable def my_fun := (\u03bb (x:\u211d), 1/2 - (1/2) * exp (-x^2))\n\nlemma my_fun_cont : continuous my_fun :=\nbegin\n  unfold my_fun,\n  refine continuous_add _ _,\n  exact continuous_const,\n  refine continuous_neg _,\n  refine continuous_mul _ _,\n  exact continuous_const,\n  refine continuous.comp _ _,\n  simp [mul_neg_one],         -- * something unexpected!\n  refine continuous_pow _,\n  exact continuous_exp,\nend\n\n\n#print my_fun_cont\n", "meta": {"author": "holtzermann17", "repo": "lean_experiments", "sha": "3ebb7048c9ca766814c10404ba217b50544d20b2", "save_path": "github-repos/lean/holtzermann17-lean_experiments", "path": "github-repos/lean/holtzermann17-lean_experiments/lean_experiments-3ebb7048c9ca766814c10404ba217b50544d20b2/src/paper_examples_123.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7274381336691219}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl, Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Zhouhang Zhou\n\n! This file was ported from Lean 3 source module measure_theory.function.ae_eq_fun\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Integral.Lebesgue\nimport Mathbin.Order.Filter.Germ\nimport Mathbin.Topology.ContinuousFunction.Algebra\nimport Mathbin.MeasureTheory.Function.StronglyMeasurable.Basic\n\n/-!\n\n# Almost everywhere equal functions\n\nWe build a space of equivalence classes of functions, where two functions are treated as identical\nif they are almost everywhere equal. We form the set of equivalence classes under the relation of\nbeing almost everywhere equal, which is sometimes known as the `L\u2070` space.\nTo use this space as a basis for the `L^p` spaces and for the Bochner integral, we consider\nequivalence classes of strongly measurable functions (or, equivalently, of almost everywhere\nstrongly measurable functions.)\n\nSee `l1_space.lean` for `L\u00b9` space.\n\n## Notation\n\n* `\u03b1 \u2192\u2098[\u03bc] \u03b2` is the type of `L\u2070` space, where `\u03b1` is a measurable space, `\u03b2` is a topological\n  space, and `\u03bc` is a measure on `\u03b1`. `f : \u03b1 \u2192\u2098 \u03b2` is a \"function\" in `L\u2070`.\n  In comments, `[f]` is also used to denote an `L\u2070` function.\n\n  `\u2098` can be typed as `\\_m`. Sometimes it is shown as a box if font is missing.\n\n## Main statements\n\n* The linear structure of `L\u2070` :\n    Addition and scalar multiplication are defined on `L\u2070` in the natural way, i.e.,\n    `[f] + [g] := [f + g]`, `c \u2022 [f] := [c \u2022 f]`. So defined, `\u03b1 \u2192\u2098 \u03b2` inherits the linear structure\n    of `\u03b2`. For example, if `\u03b2` is a module, then `\u03b1 \u2192\u2098 \u03b2` is a module over the same ring.\n\n    See `mk_add_mk`,  `neg_mk`,     `mk_sub_mk`,  `smul_mk`,\n        `add_to_fun`, `neg_to_fun`, `sub_to_fun`, `smul_to_fun`\n\n* The order structure of `L\u2070` :\n    `\u2264` can be defined in a similar way: `[f] \u2264 [g]` if `f a \u2264 g a` for almost all `a` in domain.\n    And `\u03b1 \u2192\u2098 \u03b2` inherits the preorder and partial order of `\u03b2`.\n\n    TODO: Define `sup` and `inf` on `L\u2070` so that it forms a lattice. It seems that `\u03b2` must be a\n    linear order, since otherwise `f \u2294 g` may not be a measurable function.\n\n## Implementation notes\n\n* `f.to_fun`     : To find a representative of `f : \u03b1 \u2192\u2098 \u03b2`, use the coercion `(f : \u03b1 \u2192 \u03b2)`, which\n                 is implemented as `f.to_fun`.\n                 For each operation `op` in `L\u2070`, there is a lemma called `coe_fn_op`,\n                 characterizing, say, `(f op g : \u03b1 \u2192 \u03b2)`.\n* `ae_eq_fun.mk` : To constructs an `L\u2070` function `\u03b1 \u2192\u2098 \u03b2` from an almost everywhere strongly\n                 measurable function `f : \u03b1 \u2192 \u03b2`, use `ae_eq_fun.mk`\n* `comp`         : Use `comp g f` to get `[g \u2218 f]` from `g : \u03b2 \u2192 \u03b3` and `[f] : \u03b1 \u2192\u2098 \u03b3` when `g` is\n                 continuous. Use `comp_measurable` if `g` is only measurable (this requires the\n                 target space to be second countable).\n* `comp\u2082`        : Use `comp\u2082 g f\u2081 f\u2082 to get `[\u03bb a, g (f\u2081 a) (f\u2082 a)]`.\n                 For example, `[f + g]` is `comp\u2082 (+)`\n\n\n## Tags\n\nfunction space, almost everywhere equal, `L\u2070`, ae_eq_fun\n\n-/\n\n\nnoncomputable section\n\nopen Classical ENNReal Topology\n\nopen Set Filter TopologicalSpace ENNReal Emetric MeasureTheory Function\n\nvariable {\u03b1 \u03b2 \u03b3 \u03b4 : Type _} [MeasurableSpace \u03b1] {\u03bc \u03bd : Measure \u03b1}\n\nnamespace MeasureTheory\n\nsection MeasurableSpace\n\nvariable [TopologicalSpace \u03b2]\n\nvariable (\u03b2)\n\n/-- The equivalence relation of being almost everywhere equal for almost everywhere strongly\nmeasurable functions. -/\ndef Measure.aeEqSetoid (\u03bc : Measure \u03b1) : Setoid { f : \u03b1 \u2192 \u03b2 // AeStronglyMeasurable f \u03bc } :=\n  \u27e8fun f g => (f : \u03b1 \u2192 \u03b2) =\u1d50[\u03bc] g, fun f => ae_eq_refl f, fun f g => ae_eq_symm, fun f g h =>\n    ae_eq_trans\u27e9\n#align measure_theory.measure.ae_eq_setoid MeasureTheory.Measure.aeEqSetoid\n\nvariable (\u03b1)\n\n/-- The space of equivalence classes of almost everywhere strongly measurable functions, where two\n    strongly measurable functions are equivalent if they agree almost everywhere, i.e.,\n    they differ on a set of measure `0`.  -/\ndef AeEqFun (\u03bc : Measure \u03b1) : Type _ :=\n  Quotient (\u03bc.aeEqSetoid \u03b2)\n#align measure_theory.ae_eq_fun MeasureTheory.AeEqFun\n\nvariable {\u03b1 \u03b2}\n\n-- mathport name: \u00abexpr \u2192\u2098[ ] \u00bb\nnotation:25 \u03b1 \" \u2192\u2098[\" \u03bc \"] \" \u03b2 => AeEqFun \u03b1 \u03b2 \u03bc\n\nend MeasurableSpace\n\nnamespace AeEqFun\n\nvariable [TopologicalSpace \u03b2] [TopologicalSpace \u03b3] [TopologicalSpace \u03b4]\n\n/-- Construct the equivalence class `[f]` of an almost everywhere measurable function `f`, based\n    on the equivalence relation of being almost everywhere equal. -/\ndef mk {\u03b2 : Type _} [TopologicalSpace \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : AeStronglyMeasurable f \u03bc) : \u03b1 \u2192\u2098[\u03bc] \u03b2 :=\n  Quotient.mk'' \u27e8f, hf\u27e9\n#align measure_theory.ae_eq_fun.mk MeasureTheory.AeEqFun.mk\n\n/-- A measurable representative of an `ae_eq_fun` [f] -/\ninstance : CoeFun (\u03b1 \u2192\u2098[\u03bc] \u03b2) fun _ => \u03b1 \u2192 \u03b2 :=\n  \u27e8fun f =>\n    AeStronglyMeasurable.mk _ (Quotient.out' f : { f : \u03b1 \u2192 \u03b2 // AeStronglyMeasurable f \u03bc }).2\u27e9\n\nprotected theorem stronglyMeasurable (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : StronglyMeasurable f :=\n  AeStronglyMeasurable.stronglyMeasurable_mk _\n#align measure_theory.ae_eq_fun.strongly_measurable MeasureTheory.AeEqFun.stronglyMeasurable\n\nprotected theorem aeStronglyMeasurable (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : AeStronglyMeasurable f \u03bc :=\n  f.StronglyMeasurable.AeStronglyMeasurable\n#align measure_theory.ae_eq_fun.ae_strongly_measurable MeasureTheory.AeEqFun.aeStronglyMeasurable\n\nprotected theorem measurable [PseudoMetrizableSpace \u03b2] [MeasurableSpace \u03b2] [BorelSpace \u03b2]\n    (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : Measurable f :=\n  AeStronglyMeasurable.measurable_mk _\n#align measure_theory.ae_eq_fun.measurable MeasureTheory.AeEqFun.measurable\n\nprotected theorem aeMeasurable [PseudoMetrizableSpace \u03b2] [MeasurableSpace \u03b2] [BorelSpace \u03b2]\n    (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : AeMeasurable f \u03bc :=\n  f.Measurable.AeMeasurable\n#align measure_theory.ae_eq_fun.ae_measurable MeasureTheory.AeEqFun.aeMeasurable\n\n@[simp]\ntheorem quot_mk_eq_mk (f : \u03b1 \u2192 \u03b2) (hf) :\n    (Quot.mk (@Setoid.r _ <| \u03bc.aeEqSetoid \u03b2) \u27e8f, hf\u27e9 : \u03b1 \u2192\u2098[\u03bc] \u03b2) = mk f hf :=\n  rfl\n#align measure_theory.ae_eq_fun.quot_mk_eq_mk MeasureTheory.AeEqFun.quot_mk_eq_mk\n\n@[simp]\ntheorem mk_eq_mk {f g : \u03b1 \u2192 \u03b2} {hf hg} : (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2) = mk g hg \u2194 f =\u1d50[\u03bc] g :=\n  Quotient.eq''\n#align measure_theory.ae_eq_fun.mk_eq_mk MeasureTheory.AeEqFun.mk_eq_mk\n\n@[simp]\ntheorem mk_coeFn (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : mk f f.AeStronglyMeasurable = f :=\n  by\n  conv_rhs => rw [\u2190 Quotient.out_eq' f]\n  set g : { f : \u03b1 \u2192 \u03b2 // ae_strongly_measurable f \u03bc } := Quotient.out' f with hg\n  have : g = \u27e8g.1, g.2\u27e9 := Subtype.eq rfl\n  rw [this, \u2190 mk, mk_eq_mk]\n  exact (ae_strongly_measurable.ae_eq_mk _).symm\n#align measure_theory.ae_eq_fun.mk_coe_fn MeasureTheory.AeEqFun.mk_coeFn\n\n@[ext]\ntheorem ext {f g : \u03b1 \u2192\u2098[\u03bc] \u03b2} (h : f =\u1d50[\u03bc] g) : f = g := by\n  rwa [\u2190 f.mk_coe_fn, \u2190 g.mk_coe_fn, mk_eq_mk]\n#align measure_theory.ae_eq_fun.ext MeasureTheory.AeEqFun.ext\n\ntheorem ext_iff {f g : \u03b1 \u2192\u2098[\u03bc] \u03b2} : f = g \u2194 f =\u1d50[\u03bc] g :=\n  \u27e8fun h => by rw [h], fun h => ext h\u27e9\n#align measure_theory.ae_eq_fun.ext_iff MeasureTheory.AeEqFun.ext_iff\n\ntheorem coeFn_mk (f : \u03b1 \u2192 \u03b2) (hf) : (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2) =\u1d50[\u03bc] f :=\n  by\n  apply (ae_strongly_measurable.ae_eq_mk _).symm.trans\n  exact @Quotient.mk_out' _ (\u03bc.ae_eq_setoid \u03b2) (\u27e8f, hf\u27e9 : { f // ae_strongly_measurable f \u03bc })\n#align measure_theory.ae_eq_fun.coe_fn_mk MeasureTheory.AeEqFun.coeFn_mk\n\n@[elab_as_elim]\ntheorem inductionOn (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) {p : (\u03b1 \u2192\u2098[\u03bc] \u03b2) \u2192 Prop} (H : \u2200 f hf, p (mk f hf)) : p f :=\n  Quotient.inductionOn' f <| Subtype.forall.2 H\n#align measure_theory.ae_eq_fun.induction_on MeasureTheory.AeEqFun.inductionOn\n\n@[elab_as_elim]\ntheorem inductionOn\u2082 {\u03b1' \u03b2' : Type _} [MeasurableSpace \u03b1'] [TopologicalSpace \u03b2'] {\u03bc' : Measure \u03b1'}\n    (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) (f' : \u03b1' \u2192\u2098[\u03bc'] \u03b2') {p : (\u03b1 \u2192\u2098[\u03bc] \u03b2) \u2192 (\u03b1' \u2192\u2098[\u03bc'] \u03b2') \u2192 Prop}\n    (H : \u2200 f hf f' hf', p (mk f hf) (mk f' hf')) : p f f' :=\n  inductionOn f fun f hf => inductionOn f' <| H f hf\n#align measure_theory.ae_eq_fun.induction_on\u2082 MeasureTheory.AeEqFun.inductionOn\u2082\n\n@[elab_as_elim]\ntheorem inductionOn\u2083 {\u03b1' \u03b2' : Type _} [MeasurableSpace \u03b1'] [TopologicalSpace \u03b2'] {\u03bc' : Measure \u03b1'}\n    {\u03b1'' \u03b2'' : Type _} [MeasurableSpace \u03b1''] [TopologicalSpace \u03b2''] {\u03bc'' : Measure \u03b1''}\n    (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) (f' : \u03b1' \u2192\u2098[\u03bc'] \u03b2') (f'' : \u03b1'' \u2192\u2098[\u03bc''] \u03b2'')\n    {p : (\u03b1 \u2192\u2098[\u03bc] \u03b2) \u2192 (\u03b1' \u2192\u2098[\u03bc'] \u03b2') \u2192 (\u03b1'' \u2192\u2098[\u03bc''] \u03b2'') \u2192 Prop}\n    (H : \u2200 f hf f' hf' f'' hf'', p (mk f hf) (mk f' hf') (mk f'' hf'')) : p f f' f'' :=\n  inductionOn f fun f hf => inductionOn\u2082 f' f'' <| H f hf\n#align measure_theory.ae_eq_fun.induction_on\u2083 MeasureTheory.AeEqFun.inductionOn\u2083\n\n/-- Given a continuous function `g : \u03b2 \u2192 \u03b3`, and an almost everywhere equal function `[f] : \u03b1 \u2192\u2098 \u03b2`,\n    return the equivalence class of `g \u2218 f`, i.e., the almost everywhere equal function\n    `[g \u2218 f] : \u03b1 \u2192\u2098 \u03b3`. -/\ndef comp (g : \u03b2 \u2192 \u03b3) (hg : Continuous g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : \u03b1 \u2192\u2098[\u03bc] \u03b3 :=\n  Quotient.liftOn' f (fun f => mk (g \u2218 (f : \u03b1 \u2192 \u03b2)) (hg.compAeStronglyMeasurable f.2)) fun f f' H =>\n    mk_eq_mk.2 <| H.fun_comp g\n#align measure_theory.ae_eq_fun.comp MeasureTheory.AeEqFun.comp\n\n@[simp]\ntheorem comp_mk (g : \u03b2 \u2192 \u03b3) (hg : Continuous g) (f : \u03b1 \u2192 \u03b2) (hf) :\n    comp g hg (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2) = mk (g \u2218 f) (hg.compAeStronglyMeasurable hf) :=\n  rfl\n#align measure_theory.ae_eq_fun.comp_mk MeasureTheory.AeEqFun.comp_mk\n\ntheorem comp_eq_mk (g : \u03b2 \u2192 \u03b3) (hg : Continuous g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) :\n    comp g hg f = mk (g \u2218 f) (hg.compAeStronglyMeasurable f.AeStronglyMeasurable) := by\n  rw [\u2190 comp_mk g hg f f.ae_strongly_measurable, mk_coe_fn]\n#align measure_theory.ae_eq_fun.comp_eq_mk MeasureTheory.AeEqFun.comp_eq_mk\n\ntheorem coeFn_comp (g : \u03b2 \u2192 \u03b3) (hg : Continuous g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : comp g hg f =\u1d50[\u03bc] g \u2218 f :=\n  by\n  rw [comp_eq_mk]\n  apply [anonymous]\n#align measure_theory.ae_eq_fun.coe_fn_comp MeasureTheory.AeEqFun.coeFn_comp\n\nsection CompMeasurable\n\nvariable [MeasurableSpace \u03b2] [PseudoMetrizableSpace \u03b2] [BorelSpace \u03b2] [MeasurableSpace \u03b3]\n  [PseudoMetrizableSpace \u03b3] [OpensMeasurableSpace \u03b3] [SecondCountableTopology \u03b3]\n\n/-- Given a measurable function `g : \u03b2 \u2192 \u03b3`, and an almost everywhere equal function `[f] : \u03b1 \u2192\u2098 \u03b2`,\n    return the equivalence class of `g \u2218 f`, i.e., the almost everywhere equal function\n    `[g \u2218 f] : \u03b1 \u2192\u2098 \u03b3`. This requires that `\u03b3` has a second countable topology. -/\ndef compMeasurable (g : \u03b2 \u2192 \u03b3) (hg : Measurable g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : \u03b1 \u2192\u2098[\u03bc] \u03b3 :=\n  Quotient.liftOn' f\n    (fun f' => mk (g \u2218 (f' : \u03b1 \u2192 \u03b2)) (hg.compAeMeasurable f'.2.AeMeasurable).AeStronglyMeasurable)\n    fun f f' H => mk_eq_mk.2 <| H.fun_comp g\n#align measure_theory.ae_eq_fun.comp_measurable MeasureTheory.AeEqFun.compMeasurable\n\n@[simp]\ntheorem compMeasurable_mk (g : \u03b2 \u2192 \u03b3) (hg : Measurable g) (f : \u03b1 \u2192 \u03b2)\n    (hf : AeStronglyMeasurable f \u03bc) :\n    compMeasurable g hg (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2) =\n      mk (g \u2218 f) (hg.compAeMeasurable hf.AeMeasurable).AeStronglyMeasurable :=\n  rfl\n#align measure_theory.ae_eq_fun.comp_measurable_mk MeasureTheory.AeEqFun.compMeasurable_mk\n\ntheorem compMeasurable_eq_mk (g : \u03b2 \u2192 \u03b3) (hg : Measurable g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) :\n    compMeasurable g hg f = mk (g \u2218 f) (hg.compAeMeasurable f.AeMeasurable).AeStronglyMeasurable :=\n  by rw [\u2190 comp_measurable_mk g hg f f.ae_strongly_measurable, mk_coe_fn]\n#align measure_theory.ae_eq_fun.comp_measurable_eq_mk MeasureTheory.AeEqFun.compMeasurable_eq_mk\n\ntheorem coeFn_compMeasurable (g : \u03b2 \u2192 \u03b3) (hg : Measurable g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) :\n    compMeasurable g hg f =\u1d50[\u03bc] g \u2218 f :=\n  by\n  rw [comp_measurable_eq_mk]\n  apply [anonymous]\n#align measure_theory.ae_eq_fun.coe_fn_comp_measurable MeasureTheory.AeEqFun.coeFn_compMeasurable\n\nend CompMeasurable\n\n/-- The class of `x \u21a6 (f x, g x)`. -/\ndef pair (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) (g : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u03b1 \u2192\u2098[\u03bc] \u03b2 \u00d7 \u03b3 :=\n  Quotient.liftOn\u2082' f g (fun f g => mk (fun x => (f.1 x, g.1 x)) (f.2.prod_mk g.2))\n    fun f g f' g' Hf Hg => mk_eq_mk.2 <| Hf.prod_mk Hg\n#align measure_theory.ae_eq_fun.pair MeasureTheory.AeEqFun.pair\n\n@[simp]\ntheorem pair_mk_mk (f : \u03b1 \u2192 \u03b2) (hf) (g : \u03b1 \u2192 \u03b3) (hg) :\n    (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2).pair (mk g hg) = mk (fun x => (f x, g x)) (hf.prod_mk hg) :=\n  rfl\n#align measure_theory.ae_eq_fun.pair_mk_mk MeasureTheory.AeEqFun.pair_mk_mk\n\ntheorem pair_eq_mk (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) (g : \u03b1 \u2192\u2098[\u03bc] \u03b3) :\n    f.pair g = mk (fun x => (f x, g x)) (f.AeStronglyMeasurable.prod_mk g.AeStronglyMeasurable) :=\n  by simp only [\u2190 pair_mk_mk, mk_coe_fn]\n#align measure_theory.ae_eq_fun.pair_eq_mk MeasureTheory.AeEqFun.pair_eq_mk\n\ntheorem coeFn_pair (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) (g : \u03b1 \u2192\u2098[\u03bc] \u03b3) : f.pair g =\u1d50[\u03bc] fun x => (f x, g x) :=\n  by\n  rw [pair_eq_mk]\n  apply [anonymous]\n#align measure_theory.ae_eq_fun.coe_fn_pair MeasureTheory.AeEqFun.coeFn_pair\n\n/-- Given a continuous function `g : \u03b2 \u2192 \u03b3 \u2192 \u03b4`, and almost everywhere equal functions\n    `[f\u2081] : \u03b1 \u2192\u2098 \u03b2` and `[f\u2082] : \u03b1 \u2192\u2098 \u03b3`, return the equivalence class of the function\n    `\u03bb a, g (f\u2081 a) (f\u2082 a)`, i.e., the almost everywhere equal function\n    `[\u03bb a, g (f\u2081 a) (f\u2082 a)] : \u03b1 \u2192\u2098 \u03b3` -/\ndef comp\u2082 (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Continuous (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2) (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) :\n    \u03b1 \u2192\u2098[\u03bc] \u03b4 :=\n  comp _ hg (f\u2081.pair f\u2082)\n#align measure_theory.ae_eq_fun.comp\u2082 MeasureTheory.AeEqFun.comp\u2082\n\n@[simp]\ntheorem comp\u2082_mk_mk (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Continuous (uncurry g)) (f\u2081 : \u03b1 \u2192 \u03b2) (f\u2082 : \u03b1 \u2192 \u03b3)\n    (hf\u2081 hf\u2082) :\n    comp\u2082 g hg (mk f\u2081 hf\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2) (mk f\u2082 hf\u2082) =\n      mk (fun a => g (f\u2081 a) (f\u2082 a)) (hg.compAeStronglyMeasurable (hf\u2081.prod_mk hf\u2082)) :=\n  rfl\n#align measure_theory.ae_eq_fun.comp\u2082_mk_mk MeasureTheory.AeEqFun.comp\u2082_mk_mk\n\ntheorem comp\u2082_eq_pair (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Continuous (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) : comp\u2082 g hg f\u2081 f\u2082 = comp _ hg (f\u2081.pair f\u2082) :=\n  rfl\n#align measure_theory.ae_eq_fun.comp\u2082_eq_pair MeasureTheory.AeEqFun.comp\u2082_eq_pair\n\ntheorem comp\u2082_eq_mk (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Continuous (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) :\n    comp\u2082 g hg f\u2081 f\u2082 =\n      mk (fun a => g (f\u2081 a) (f\u2082 a))\n        (hg.compAeStronglyMeasurable (f\u2081.AeStronglyMeasurable.prod_mk f\u2082.AeStronglyMeasurable)) :=\n  by rw [comp\u2082_eq_pair, pair_eq_mk, comp_mk] <;> rfl\n#align measure_theory.ae_eq_fun.comp\u2082_eq_mk MeasureTheory.AeEqFun.comp\u2082_eq_mk\n\ntheorem coeFn_comp\u2082 (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Continuous (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) : comp\u2082 g hg f\u2081 f\u2082 =\u1d50[\u03bc] fun a => g (f\u2081 a) (f\u2082 a) :=\n  by\n  rw [comp\u2082_eq_mk]\n  apply [anonymous]\n#align measure_theory.ae_eq_fun.coe_fn_comp\u2082 MeasureTheory.AeEqFun.coeFn_comp\u2082\n\nsection\n\nvariable [MeasurableSpace \u03b2] [PseudoMetrizableSpace \u03b2] [BorelSpace \u03b2] [SecondCountableTopology \u03b2]\n  [MeasurableSpace \u03b3] [PseudoMetrizableSpace \u03b3] [BorelSpace \u03b3] [SecondCountableTopology \u03b3]\n  [MeasurableSpace \u03b4] [PseudoMetrizableSpace \u03b4] [OpensMeasurableSpace \u03b4] [SecondCountableTopology \u03b4]\n\n/-- Given a measurable function `g : \u03b2 \u2192 \u03b3 \u2192 \u03b4`, and almost everywhere equal functions\n    `[f\u2081] : \u03b1 \u2192\u2098 \u03b2` and `[f\u2082] : \u03b1 \u2192\u2098 \u03b3`, return the equivalence class of the function\n    `\u03bb a, g (f\u2081 a) (f\u2082 a)`, i.e., the almost everywhere equal function\n    `[\u03bb a, g (f\u2081 a) (f\u2082 a)] : \u03b1 \u2192\u2098 \u03b3`. This requires `\u03b4` to have second-countable topology. -/\ndef comp\u2082Measurable (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Measurable (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u03b1 \u2192\u2098[\u03bc] \u03b4 :=\n  compMeasurable _ hg (f\u2081.pair f\u2082)\n#align measure_theory.ae_eq_fun.comp\u2082_measurable MeasureTheory.AeEqFun.comp\u2082Measurable\n\n@[simp]\ntheorem comp\u2082Measurable_mk_mk (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Measurable (uncurry g)) (f\u2081 : \u03b1 \u2192 \u03b2)\n    (f\u2082 : \u03b1 \u2192 \u03b3) (hf\u2081 hf\u2082) :\n    comp\u2082Measurable g hg (mk f\u2081 hf\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2) (mk f\u2082 hf\u2082) =\n      mk (fun a => g (f\u2081 a) (f\u2082 a))\n        (hg.compAeMeasurable (hf\u2081.AeMeasurable.prod_mk hf\u2082.AeMeasurable)).AeStronglyMeasurable :=\n  rfl\n#align measure_theory.ae_eq_fun.comp\u2082_measurable_mk_mk MeasureTheory.AeEqFun.comp\u2082Measurable_mk_mk\n\ntheorem comp\u2082Measurable_eq_pair (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Measurable (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) : comp\u2082Measurable g hg f\u2081 f\u2082 = compMeasurable _ hg (f\u2081.pair f\u2082) :=\n  rfl\n#align measure_theory.ae_eq_fun.comp\u2082_measurable_eq_pair MeasureTheory.AeEqFun.comp\u2082Measurable_eq_pair\n\ntheorem comp\u2082Measurable_eq_mk (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Measurable (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) :\n    comp\u2082Measurable g hg f\u2081 f\u2082 =\n      mk (fun a => g (f\u2081 a) (f\u2082 a))\n        (hg.compAeMeasurable (f\u2081.AeMeasurable.prod_mk f\u2082.AeMeasurable)).AeStronglyMeasurable :=\n  by rw [comp\u2082_measurable_eq_pair, pair_eq_mk, comp_measurable_mk] <;> rfl\n#align measure_theory.ae_eq_fun.comp\u2082_measurable_eq_mk MeasureTheory.AeEqFun.comp\u2082Measurable_eq_mk\n\ntheorem coeFn_comp\u2082Measurable (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Measurable (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) : comp\u2082Measurable g hg f\u2081 f\u2082 =\u1d50[\u03bc] fun a => g (f\u2081 a) (f\u2082 a) :=\n  by\n  rw [comp\u2082_measurable_eq_mk]\n  apply [anonymous]\n#align measure_theory.ae_eq_fun.coe_fn_comp\u2082_measurable MeasureTheory.AeEqFun.coeFn_comp\u2082Measurable\n\nend\n\n/-- Interpret `f : \u03b1 \u2192\u2098[\u03bc] \u03b2` as a germ at `\u03bc.ae` forgetting that `f` is almost everywhere\n    strongly measurable. -/\ndef toGerm (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : Germ \u03bc.ae \u03b2 :=\n  Quotient.liftOn' f (fun f => ((f : \u03b1 \u2192 \u03b2) : Germ \u03bc.ae \u03b2)) fun f g H => Germ.coe_eq.2 H\n#align measure_theory.ae_eq_fun.to_germ MeasureTheory.AeEqFun.toGerm\n\n@[simp]\ntheorem mk_toGerm (f : \u03b1 \u2192 \u03b2) (hf) : (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2).toGerm = f :=\n  rfl\n#align measure_theory.ae_eq_fun.mk_to_germ MeasureTheory.AeEqFun.mk_toGerm\n\ntheorem toGerm_eq (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : f.toGerm = (f : \u03b1 \u2192 \u03b2) := by rw [\u2190 mk_to_germ, mk_coe_fn]\n#align measure_theory.ae_eq_fun.to_germ_eq MeasureTheory.AeEqFun.toGerm_eq\n\ntheorem toGerm_injective : Injective (toGerm : (\u03b1 \u2192\u2098[\u03bc] \u03b2) \u2192 Germ \u03bc.ae \u03b2) := fun f g H =>\n  ext <| Germ.coe_eq.1 <| by rwa [\u2190 to_germ_eq, \u2190 to_germ_eq]\n#align measure_theory.ae_eq_fun.to_germ_injective MeasureTheory.AeEqFun.toGerm_injective\n\ntheorem comp_toGerm (g : \u03b2 \u2192 \u03b3) (hg : Continuous g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) :\n    (comp g hg f).toGerm = f.toGerm.map g :=\n  inductionOn f fun f hf => by simp\n#align measure_theory.ae_eq_fun.comp_to_germ MeasureTheory.AeEqFun.comp_toGerm\n\ntheorem compMeasurable_toGerm [MeasurableSpace \u03b2] [BorelSpace \u03b2] [PseudoMetrizableSpace \u03b2]\n    [PseudoMetrizableSpace \u03b3] [SecondCountableTopology \u03b3] [MeasurableSpace \u03b3]\n    [OpensMeasurableSpace \u03b3] (g : \u03b2 \u2192 \u03b3) (hg : Measurable g) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) :\n    (compMeasurable g hg f).toGerm = f.toGerm.map g :=\n  inductionOn f fun f hf => by simp\n#align measure_theory.ae_eq_fun.comp_measurable_to_germ MeasureTheory.AeEqFun.compMeasurable_toGerm\n\ntheorem comp\u2082_toGerm (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Continuous (uncurry g)) (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2)\n    (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) : (comp\u2082 g hg f\u2081 f\u2082).toGerm = f\u2081.toGerm.zipWith g f\u2082.toGerm :=\n  inductionOn\u2082 f\u2081 f\u2082 fun f\u2081 hf\u2081 f\u2082 hf\u2082 => by simp\n#align measure_theory.ae_eq_fun.comp\u2082_to_germ MeasureTheory.AeEqFun.comp\u2082_toGerm\n\ntheorem comp\u2082Measurable_toGerm [PseudoMetrizableSpace \u03b2] [SecondCountableTopology \u03b2]\n    [MeasurableSpace \u03b2] [BorelSpace \u03b2] [PseudoMetrizableSpace \u03b3] [SecondCountableTopology \u03b3]\n    [MeasurableSpace \u03b3] [BorelSpace \u03b3] [PseudoMetrizableSpace \u03b4] [SecondCountableTopology \u03b4]\n    [MeasurableSpace \u03b4] [OpensMeasurableSpace \u03b4] (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) (hg : Measurable (uncurry g))\n    (f\u2081 : \u03b1 \u2192\u2098[\u03bc] \u03b2) (f\u2082 : \u03b1 \u2192\u2098[\u03bc] \u03b3) :\n    (comp\u2082Measurable g hg f\u2081 f\u2082).toGerm = f\u2081.toGerm.zipWith g f\u2082.toGerm :=\n  inductionOn\u2082 f\u2081 f\u2082 fun f\u2081 hf\u2081 f\u2082 hf\u2082 => by simp\n#align measure_theory.ae_eq_fun.comp\u2082_measurable_to_germ MeasureTheory.AeEqFun.comp\u2082Measurable_toGerm\n\n/-- Given a predicate `p` and an equivalence class `[f]`, return true if `p` holds of `f a`\n    for almost all `a` -/\ndef LiftPred (p : \u03b2 \u2192 Prop) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : Prop :=\n  f.toGerm.lift_pred p\n#align measure_theory.ae_eq_fun.lift_pred MeasureTheory.AeEqFun.LiftPred\n\n/-- Given a relation `r` and equivalence class `[f]` and `[g]`, return true if `r` holds of\n    `(f a, g a)` for almost all `a` -/\ndef LiftRel (r : \u03b2 \u2192 \u03b3 \u2192 Prop) (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) (g : \u03b1 \u2192\u2098[\u03bc] \u03b3) : Prop :=\n  f.toGerm.LiftRel r g.toGerm\n#align measure_theory.ae_eq_fun.lift_rel MeasureTheory.AeEqFun.LiftRel\n\ntheorem liftRel_mk_mk {r : \u03b2 \u2192 \u03b3 \u2192 Prop} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} {hf hg} :\n    LiftRel r (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2) (mk g hg) \u2194 \u2200\u1d50 a \u2202\u03bc, r (f a) (g a) :=\n  Iff.rfl\n#align measure_theory.ae_eq_fun.lift_rel_mk_mk MeasureTheory.AeEqFun.liftRel_mk_mk\n\ntheorem liftRel_iff_coeFn {r : \u03b2 \u2192 \u03b3 \u2192 Prop} {f : \u03b1 \u2192\u2098[\u03bc] \u03b2} {g : \u03b1 \u2192\u2098[\u03bc] \u03b3} :\n    LiftRel r f g \u2194 \u2200\u1d50 a \u2202\u03bc, r (f a) (g a) := by rw [\u2190 lift_rel_mk_mk, mk_coe_fn, mk_coe_fn]\n#align measure_theory.ae_eq_fun.lift_rel_iff_coe_fn MeasureTheory.AeEqFun.liftRel_iff_coeFn\n\nsection Order\n\ninstance [Preorder \u03b2] : Preorder (\u03b1 \u2192\u2098[\u03bc] \u03b2) :=\n  Preorder.lift toGerm\n\n@[simp]\ntheorem mk_le_mk [Preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} (hf hg) : (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2) \u2264 mk g hg \u2194 f \u2264\u1d50[\u03bc] g :=\n  Iff.rfl\n#align measure_theory.ae_eq_fun.mk_le_mk MeasureTheory.AeEqFun.mk_le_mk\n\n@[simp, norm_cast]\ntheorem coeFn_le [Preorder \u03b2] {f g : \u03b1 \u2192\u2098[\u03bc] \u03b2} : (f : \u03b1 \u2192 \u03b2) \u2264\u1d50[\u03bc] g \u2194 f \u2264 g :=\n  liftRel_iff_coeFn.symm\n#align measure_theory.ae_eq_fun.coe_fn_le MeasureTheory.AeEqFun.coeFn_le\n\ninstance [PartialOrder \u03b2] : PartialOrder (\u03b1 \u2192\u2098[\u03bc] \u03b2) :=\n  PartialOrder.lift toGerm toGerm_injective\n\nsection Lattice\n\nsection Sup\n\nvariable [SemilatticeSup \u03b2] [ContinuousSup \u03b2]\n\ninstance : Sup (\u03b1 \u2192\u2098[\u03bc] \u03b2) where sup f g := AeEqFun.comp\u2082 (\u00b7 \u2294 \u00b7) continuous_sup f g\n\ntheorem coeFn_sup (f g : \u03b1 \u2192\u2098[\u03bc] \u03b2) : \u21d1(f \u2294 g) =\u1d50[\u03bc] fun x => f x \u2294 g x :=\n  coeFn_comp\u2082 _ _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_sup MeasureTheory.AeEqFun.coeFn_sup\n\nprotected theorem le_sup_left (f g : \u03b1 \u2192\u2098[\u03bc] \u03b2) : f \u2264 f \u2294 g :=\n  by\n  rw [\u2190 coe_fn_le]\n  filter_upwards [coe_fn_sup f g]with _ ha\n  rw [ha]\n  exact le_sup_left\n#align measure_theory.ae_eq_fun.le_sup_left MeasureTheory.AeEqFun.le_sup_left\n\nprotected theorem le_sup_right (f g : \u03b1 \u2192\u2098[\u03bc] \u03b2) : g \u2264 f \u2294 g :=\n  by\n  rw [\u2190 coe_fn_le]\n  filter_upwards [coe_fn_sup f g]with _ ha\n  rw [ha]\n  exact le_sup_right\n#align measure_theory.ae_eq_fun.le_sup_right MeasureTheory.AeEqFun.le_sup_right\n\nprotected theorem sup_le (f g f' : \u03b1 \u2192\u2098[\u03bc] \u03b2) (hf : f \u2264 f') (hg : g \u2264 f') : f \u2294 g \u2264 f' :=\n  by\n  rw [\u2190 coe_fn_le] at hf hg\u22a2\n  filter_upwards [hf, hg, coe_fn_sup f g]with _ haf hag ha_sup\n  rw [ha_sup]\n  exact sup_le haf hag\n#align measure_theory.ae_eq_fun.sup_le MeasureTheory.AeEqFun.sup_le\n\nend Sup\n\nsection Inf\n\nvariable [SemilatticeInf \u03b2] [ContinuousInf \u03b2]\n\ninstance : Inf (\u03b1 \u2192\u2098[\u03bc] \u03b2) where inf f g := AeEqFun.comp\u2082 (\u00b7 \u2293 \u00b7) continuous_inf f g\n\ntheorem coeFn_inf (f g : \u03b1 \u2192\u2098[\u03bc] \u03b2) : \u21d1(f \u2293 g) =\u1d50[\u03bc] fun x => f x \u2293 g x :=\n  coeFn_comp\u2082 _ _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_inf MeasureTheory.AeEqFun.coeFn_inf\n\nprotected theorem inf_le_left (f g : \u03b1 \u2192\u2098[\u03bc] \u03b2) : f \u2293 g \u2264 f :=\n  by\n  rw [\u2190 coe_fn_le]\n  filter_upwards [coe_fn_inf f g]with _ ha\n  rw [ha]\n  exact inf_le_left\n#align measure_theory.ae_eq_fun.inf_le_left MeasureTheory.AeEqFun.inf_le_left\n\nprotected theorem inf_le_right (f g : \u03b1 \u2192\u2098[\u03bc] \u03b2) : f \u2293 g \u2264 g :=\n  by\n  rw [\u2190 coe_fn_le]\n  filter_upwards [coe_fn_inf f g]with _ ha\n  rw [ha]\n  exact inf_le_right\n#align measure_theory.ae_eq_fun.inf_le_right MeasureTheory.AeEqFun.inf_le_right\n\nprotected theorem le_inf (f' f g : \u03b1 \u2192\u2098[\u03bc] \u03b2) (hf : f' \u2264 f) (hg : f' \u2264 g) : f' \u2264 f \u2293 g :=\n  by\n  rw [\u2190 coe_fn_le] at hf hg\u22a2\n  filter_upwards [hf, hg, coe_fn_inf f g]with _ haf hag ha_inf\n  rw [ha_inf]\n  exact le_inf haf hag\n#align measure_theory.ae_eq_fun.le_inf MeasureTheory.AeEqFun.le_inf\n\nend Inf\n\ninstance [Lattice \u03b2] [TopologicalLattice \u03b2] : Lattice (\u03b1 \u2192\u2098[\u03bc] \u03b2) :=\n  { AeEqFun.partialOrder with\n    sup := Sup.sup\n    le_sup_left := AeEqFun.le_sup_left\n    le_sup_right := AeEqFun.le_sup_right\n    sup_le := AeEqFun.sup_le\n    inf := Inf.inf\n    inf_le_left := AeEqFun.inf_le_left\n    inf_le_right := AeEqFun.inf_le_right\n    le_inf := AeEqFun.le_inf }\n\nend Lattice\n\nend Order\n\nvariable (\u03b1)\n\n/-- The equivalence class of a constant function: `[\u03bb a:\u03b1, b]`, based on the equivalence relation of\n    being almost everywhere equal -/\ndef const (b : \u03b2) : \u03b1 \u2192\u2098[\u03bc] \u03b2 :=\n  mk (fun a : \u03b1 => b) aeStronglyMeasurableConst\n#align measure_theory.ae_eq_fun.const MeasureTheory.AeEqFun.const\n\ntheorem coeFn_const (b : \u03b2) : (const \u03b1 b : \u03b1 \u2192\u2098[\u03bc] \u03b2) =\u1d50[\u03bc] Function.const \u03b1 b :=\n  coeFn_mk _ _\n#align measure_theory.ae_eq_fun.coe_fn_const MeasureTheory.AeEqFun.coeFn_const\n\nvariable {\u03b1}\n\ninstance [Inhabited \u03b2] : Inhabited (\u03b1 \u2192\u2098[\u03bc] \u03b2) :=\n  \u27e8const \u03b1 default\u27e9\n\n@[to_additive]\ninstance [One \u03b2] : One (\u03b1 \u2192\u2098[\u03bc] \u03b2) :=\n  \u27e8const \u03b1 1\u27e9\n\n@[to_additive]\ntheorem one_def [One \u03b2] : (1 : \u03b1 \u2192\u2098[\u03bc] \u03b2) = mk (fun a : \u03b1 => 1) aeStronglyMeasurableConst :=\n  rfl\n#align measure_theory.ae_eq_fun.one_def MeasureTheory.AeEqFun.one_def\n#align measure_theory.ae_eq_fun.zero_def MeasureTheory.AeEqFun.zero_def\n\n@[to_additive]\ntheorem coeFn_one [One \u03b2] : \u21d1(1 : \u03b1 \u2192\u2098[\u03bc] \u03b2) =\u1d50[\u03bc] 1 :=\n  coeFn_const _ _\n#align measure_theory.ae_eq_fun.coe_fn_one MeasureTheory.AeEqFun.coeFn_one\n#align measure_theory.ae_eq_fun.coe_fn_zero MeasureTheory.AeEqFun.coe_fn_zero\n\n@[simp, to_additive]\ntheorem one_toGerm [One \u03b2] : (1 : \u03b1 \u2192\u2098[\u03bc] \u03b2).toGerm = 1 :=\n  rfl\n#align measure_theory.ae_eq_fun.one_to_germ MeasureTheory.AeEqFun.one_toGerm\n#align measure_theory.ae_eq_fun.zero_to_germ MeasureTheory.AeEqFun.zero_to_germ\n\n-- Note we set up the scalar actions before the `monoid` structures in case we want to\n-- try to override the `nsmul` or `zsmul` fields in future.\nsection SMul\n\nvariable {\ud835\udd5c \ud835\udd5c' : Type _}\n\nvariable [SMul \ud835\udd5c \u03b3] [ContinuousConstSMul \ud835\udd5c \u03b3]\n\nvariable [SMul \ud835\udd5c' \u03b3] [ContinuousConstSMul \ud835\udd5c' \u03b3]\n\ninstance : SMul \ud835\udd5c (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  \u27e8fun c f => comp ((\u00b7 \u2022 \u00b7) c) (continuous_id.const_smul c) f\u27e9\n\n@[simp]\ntheorem smul_mk (c : \ud835\udd5c) (f : \u03b1 \u2192 \u03b3) (hf : AeStronglyMeasurable f \u03bc) :\n    c \u2022 (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b3) = mk (c \u2022 f) (hf.const_smul _) :=\n  rfl\n#align measure_theory.ae_eq_fun.smul_mk MeasureTheory.AeEqFun.smul_mk\n\ntheorem coeFn_smul (c : \ud835\udd5c) (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u21d1(c \u2022 f) =\u1d50[\u03bc] c \u2022 f :=\n  coeFn_comp _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_smul MeasureTheory.AeEqFun.coeFn_smul\n\ntheorem smul_toGerm (c : \ud835\udd5c) (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) : (c \u2022 f).toGerm = c \u2022 f.toGerm :=\n  comp_toGerm _ _ _\n#align measure_theory.ae_eq_fun.smul_to_germ MeasureTheory.AeEqFun.smul_toGerm\n\ninstance [SMulCommClass \ud835\udd5c \ud835\udd5c' \u03b3] : SMulCommClass \ud835\udd5c \ud835\udd5c' (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  \u27e8fun a b f => inductionOn f fun f hf => by simp_rw [smul_mk, smul_comm]\u27e9\n\ninstance [SMul \ud835\udd5c \ud835\udd5c'] [IsScalarTower \ud835\udd5c \ud835\udd5c' \u03b3] : IsScalarTower \ud835\udd5c \ud835\udd5c' (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  \u27e8fun a b f => inductionOn f fun f hf => by simp_rw [smul_mk, smul_assoc]\u27e9\n\ninstance [SMul \ud835\udd5c\u1d50\u1d52\u1d56 \u03b3] [IsCentralScalar \ud835\udd5c \u03b3] : IsCentralScalar \ud835\udd5c (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  \u27e8fun a f => inductionOn f fun f hf => by simp_rw [smul_mk, op_smul_eq_smul]\u27e9\n\nend SMul\n\nsection Mul\n\nvariable [Mul \u03b3] [ContinuousMul \u03b3]\n\n@[to_additive]\ninstance : Mul (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  \u27e8comp\u2082 (\u00b7 * \u00b7) continuous_mul\u27e9\n\n@[simp, to_additive]\ntheorem mk_mul_mk (f g : \u03b1 \u2192 \u03b3) (hf : AeStronglyMeasurable f \u03bc) (hg : AeStronglyMeasurable g \u03bc) :\n    (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b3) * mk g hg = mk (f * g) (hf.mul hg) :=\n  rfl\n#align measure_theory.ae_eq_fun.mk_mul_mk MeasureTheory.AeEqFun.mk_mul_mk\n#align measure_theory.ae_eq_fun.mk_add_mk MeasureTheory.AeEqFun.mk_add_mk\n\n@[to_additive]\ntheorem coeFn_mul (f g : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u21d1(f * g) =\u1d50[\u03bc] f * g :=\n  coeFn_comp\u2082 _ _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_mul MeasureTheory.AeEqFun.coeFn_mul\n#align measure_theory.ae_eq_fun.coe_fn_add MeasureTheory.AeEqFun.coe_fn_add\n\n@[simp, to_additive]\ntheorem mul_toGerm (f g : \u03b1 \u2192\u2098[\u03bc] \u03b3) : (f * g).toGerm = f.toGerm * g.toGerm :=\n  comp\u2082_toGerm _ _ _ _\n#align measure_theory.ae_eq_fun.mul_to_germ MeasureTheory.AeEqFun.mul_toGerm\n#align measure_theory.ae_eq_fun.add_to_germ MeasureTheory.AeEqFun.add_to_germ\n\nend Mul\n\ninstance [AddMonoid \u03b3] [ContinuousAdd \u03b3] : AddMonoid (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.AddMonoid toGerm zero_to_germ add_to_germ fun _ _ => smul_toGerm _ _\n\ninstance [AddCommMonoid \u03b3] [ContinuousAdd \u03b3] : AddCommMonoid (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.AddCommMonoid toGerm zero_to_germ add_to_germ fun _ _ => smul_toGerm _ _\n\nsection Monoid\n\nvariable [Monoid \u03b3] [ContinuousMul \u03b3]\n\ninstance : Pow (\u03b1 \u2192\u2098[\u03bc] \u03b3) \u2115 :=\n  \u27e8fun f n => comp _ (continuous_pow n) f\u27e9\n\n@[simp]\ntheorem mk_pow (f : \u03b1 \u2192 \u03b3) (hf) (n : \u2115) :\n    (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b3) ^ n = mk (f ^ n) ((continuous_pow n).compAeStronglyMeasurable hf) :=\n  rfl\n#align measure_theory.ae_eq_fun.mk_pow MeasureTheory.AeEqFun.mk_pow\n\ntheorem coeFn_pow (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) (n : \u2115) : \u21d1(f ^ n) =\u1d50[\u03bc] f ^ n :=\n  coeFn_comp _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_pow MeasureTheory.AeEqFun.coeFn_pow\n\n@[simp]\ntheorem pow_toGerm (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) (n : \u2115) : (f ^ n).toGerm = f.toGerm ^ n :=\n  comp_toGerm _ _ _\n#align measure_theory.ae_eq_fun.pow_to_germ MeasureTheory.AeEqFun.pow_toGerm\n\n@[to_additive]\ninstance : Monoid (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.Monoid toGerm one_toGerm mul_toGerm pow_toGerm\n\n/-- `ae_eq_fun.to_germ` as a `monoid_hom`. -/\n@[to_additive \"`ae_eq_fun.to_germ` as an `add_monoid_hom`.\", simps]\ndef toGermMonoidHom : (\u03b1 \u2192\u2098[\u03bc] \u03b3) \u2192* \u03bc.ae.Germ \u03b3\n    where\n  toFun := toGerm\n  map_one' := one_toGerm\n  map_mul' := mul_toGerm\n#align measure_theory.ae_eq_fun.to_germ_monoid_hom MeasureTheory.AeEqFun.toGermMonoidHom\n#align measure_theory.ae_eq_fun.to_germ_add_monoid_hom MeasureTheory.AeEqFun.to_germ_add_monoid_hom\n\nend Monoid\n\n@[to_additive]\ninstance [CommMonoid \u03b3] [ContinuousMul \u03b3] : CommMonoid (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.CommMonoid toGerm one_toGerm mul_toGerm pow_toGerm\n\nsection Group\n\nvariable [Group \u03b3] [TopologicalGroup \u03b3]\n\nsection Inv\n\n@[to_additive]\ninstance : Inv (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  \u27e8comp Inv.inv continuous_inv\u27e9\n\n@[simp, to_additive]\ntheorem inv_mk (f : \u03b1 \u2192 \u03b3) (hf) : (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b3)\u207b\u00b9 = mk f\u207b\u00b9 hf.inv :=\n  rfl\n#align measure_theory.ae_eq_fun.inv_mk MeasureTheory.AeEqFun.inv_mk\n#align measure_theory.ae_eq_fun.neg_mk MeasureTheory.AeEqFun.neg_mk\n\n@[to_additive]\ntheorem coeFn_inv (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u21d1f\u207b\u00b9 =\u1d50[\u03bc] f\u207b\u00b9 :=\n  coeFn_comp _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_inv MeasureTheory.AeEqFun.coeFn_inv\n#align measure_theory.ae_eq_fun.coe_fn_neg MeasureTheory.AeEqFun.coe_fn_neg\n\n@[to_additive]\ntheorem inv_toGerm (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) : f\u207b\u00b9.toGerm = f.toGerm\u207b\u00b9 :=\n  comp_toGerm _ _ _\n#align measure_theory.ae_eq_fun.inv_to_germ MeasureTheory.AeEqFun.inv_toGerm\n#align measure_theory.ae_eq_fun.neg_to_germ MeasureTheory.AeEqFun.neg_to_germ\n\nend Inv\n\nsection Div\n\n@[to_additive]\ninstance : Div (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  \u27e8comp\u2082 Div.div continuous_div'\u27e9\n\n@[simp, to_additive]\ntheorem mk_div (f g : \u03b1 \u2192 \u03b3) (hf : AeStronglyMeasurable f \u03bc) (hg : AeStronglyMeasurable g \u03bc) :\n    mk (f / g) (hf.div hg) = (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b3) / mk g hg :=\n  rfl\n#align measure_theory.ae_eq_fun.mk_div MeasureTheory.AeEqFun.mk_div\n#align measure_theory.ae_eq_fun.mk_sub MeasureTheory.AeEqFun.mk_sub\n\n@[to_additive]\ntheorem coeFn_div (f g : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u21d1(f / g) =\u1d50[\u03bc] f / g :=\n  coeFn_comp\u2082 _ _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_div MeasureTheory.AeEqFun.coeFn_div\n#align measure_theory.ae_eq_fun.coe_fn_sub MeasureTheory.AeEqFun.coe_fn_sub\n\n@[to_additive]\ntheorem div_toGerm (f g : \u03b1 \u2192\u2098[\u03bc] \u03b3) : (f / g).toGerm = f.toGerm / g.toGerm :=\n  comp\u2082_toGerm _ _ _ _\n#align measure_theory.ae_eq_fun.div_to_germ MeasureTheory.AeEqFun.div_toGerm\n#align measure_theory.ae_eq_fun.sub_to_germ MeasureTheory.AeEqFun.sub_to_germ\n\nend Div\n\nsection Zpow\n\ninstance hasIntPow : Pow (\u03b1 \u2192\u2098[\u03bc] \u03b3) \u2124 :=\n  \u27e8fun f n => comp _ (continuous_zpow n) f\u27e9\n#align measure_theory.ae_eq_fun.has_int_pow MeasureTheory.AeEqFun.hasIntPow\n\n@[simp]\ntheorem mk_zpow (f : \u03b1 \u2192 \u03b3) (hf) (n : \u2124) :\n    (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b3) ^ n = mk (f ^ n) ((continuous_zpow n).compAeStronglyMeasurable hf) :=\n  rfl\n#align measure_theory.ae_eq_fun.mk_zpow MeasureTheory.AeEqFun.mk_zpow\n\ntheorem coeFn_zpow (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) (n : \u2124) : \u21d1(f ^ n) =\u1d50[\u03bc] f ^ n :=\n  coeFn_comp _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_zpow MeasureTheory.AeEqFun.coeFn_zpow\n\n@[simp]\ntheorem zpow_toGerm (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) (n : \u2124) : (f ^ n).toGerm = f.toGerm ^ n :=\n  comp_toGerm _ _ _\n#align measure_theory.ae_eq_fun.zpow_to_germ MeasureTheory.AeEqFun.zpow_toGerm\n\nend Zpow\n\nend Group\n\ninstance [AddGroup \u03b3] [TopologicalAddGroup \u03b3] : AddGroup (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.AddGroup toGerm zero_to_germ add_to_germ neg_to_germ sub_to_germ\n    (fun _ _ => smul_toGerm _ _) fun _ _ => smul_toGerm _ _\n\ninstance [AddCommGroup \u03b3] [TopologicalAddGroup \u03b3] : AddCommGroup (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.AddCommGroup toGerm zero_to_germ add_to_germ neg_to_germ sub_to_germ\n    (fun _ _ => smul_toGerm _ _) fun _ _ => smul_toGerm _ _\n\n@[to_additive]\ninstance [Group \u03b3] [TopologicalGroup \u03b3] : Group (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.Group _ one_toGerm mul_toGerm inv_toGerm div_toGerm pow_toGerm zpow_toGerm\n\n@[to_additive]\ninstance [CommGroup \u03b3] [TopologicalGroup \u03b3] : CommGroup (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.CommGroup _ one_toGerm mul_toGerm inv_toGerm div_toGerm pow_toGerm zpow_toGerm\n\nsection Module\n\nvariable {\ud835\udd5c : Type _}\n\ninstance [Monoid \ud835\udd5c] [MulAction \ud835\udd5c \u03b3] [ContinuousConstSMul \ud835\udd5c \u03b3] : MulAction \ud835\udd5c (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.MulAction toGerm smul_toGerm\n\ninstance [Monoid \ud835\udd5c] [AddMonoid \u03b3] [ContinuousAdd \u03b3] [DistribMulAction \ud835\udd5c \u03b3]\n    [ContinuousConstSMul \ud835\udd5c \u03b3] : DistribMulAction \ud835\udd5c (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.DistribMulAction (to_germ_add_monoid_hom : (\u03b1 \u2192\u2098[\u03bc] \u03b3) \u2192+ _) fun c : \ud835\udd5c =>\n    smul_toGerm c\n\ninstance [Semiring \ud835\udd5c] [AddCommMonoid \u03b3] [ContinuousAdd \u03b3] [Module \ud835\udd5c \u03b3] [ContinuousConstSMul \ud835\udd5c \u03b3] :\n    Module \ud835\udd5c (\u03b1 \u2192\u2098[\u03bc] \u03b3) :=\n  toGerm_injective.Module \ud835\udd5c (to_germ_add_monoid_hom : (\u03b1 \u2192\u2098[\u03bc] \u03b3) \u2192+ _) smul_toGerm\n\nend Module\n\nopen ENNReal\n\n/-- For `f : \u03b1 \u2192 \u211d\u22650\u221e`, define `\u222b [f]` to be `\u222b f` -/\ndef lintegral (f : \u03b1 \u2192\u2098[\u03bc] \u211d\u22650\u221e) : \u211d\u22650\u221e :=\n  Quotient.liftOn' f (fun f => \u222b\u207b a, (f : \u03b1 \u2192 \u211d\u22650\u221e) a \u2202\u03bc) fun f g => lintegral_congr_ae\n#align measure_theory.ae_eq_fun.lintegral MeasureTheory.AeEqFun.lintegral\n\n@[simp]\ntheorem lintegral_mk (f : \u03b1 \u2192 \u211d\u22650\u221e) (hf) : (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u211d\u22650\u221e).lintegral = \u222b\u207b a, f a \u2202\u03bc :=\n  rfl\n#align measure_theory.ae_eq_fun.lintegral_mk MeasureTheory.AeEqFun.lintegral_mk\n\ntheorem lintegral_coeFn (f : \u03b1 \u2192\u2098[\u03bc] \u211d\u22650\u221e) : (\u222b\u207b a, f a \u2202\u03bc) = f.lintegral := by\n  rw [\u2190 lintegral_mk, mk_coe_fn]\n#align measure_theory.ae_eq_fun.lintegral_coe_fn MeasureTheory.AeEqFun.lintegral_coeFn\n\n@[simp]\ntheorem lintegral_zero : lintegral (0 : \u03b1 \u2192\u2098[\u03bc] \u211d\u22650\u221e) = 0 :=\n  lintegral_zero\n#align measure_theory.ae_eq_fun.lintegral_zero MeasureTheory.AeEqFun.lintegral_zero\n\n@[simp]\ntheorem lintegral_eq_zero_iff {f : \u03b1 \u2192\u2098[\u03bc] \u211d\u22650\u221e} : lintegral f = 0 \u2194 f = 0 :=\n  inductionOn f fun f hf => (lintegral_eq_zero_iff' hf.AeMeasurable).trans mk_eq_mk.symm\n#align measure_theory.ae_eq_fun.lintegral_eq_zero_iff MeasureTheory.AeEqFun.lintegral_eq_zero_iff\n\ntheorem lintegral_add (f g : \u03b1 \u2192\u2098[\u03bc] \u211d\u22650\u221e) : lintegral (f + g) = lintegral f + lintegral g :=\n  inductionOn\u2082 f g fun f hf g hg => by simp [lintegral_add_left' hf.ae_measurable]\n#align measure_theory.ae_eq_fun.lintegral_add MeasureTheory.AeEqFun.lintegral_add\n\ntheorem lintegral_mono {f g : \u03b1 \u2192\u2098[\u03bc] \u211d\u22650\u221e} : f \u2264 g \u2192 lintegral f \u2264 lintegral g :=\n  inductionOn\u2082 f g fun f hf g hg hfg => lintegral_mono_ae hfg\n#align measure_theory.ae_eq_fun.lintegral_mono MeasureTheory.AeEqFun.lintegral_mono\n\nsection Abs\n\ntheorem coeFn_abs {\u03b2} [TopologicalSpace \u03b2] [Lattice \u03b2] [TopologicalLattice \u03b2] [AddGroup \u03b2]\n    [TopologicalAddGroup \u03b2] (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : \u21d1(|f|) =\u1d50[\u03bc] fun x => |f x| :=\n  by\n  simp_rw [abs_eq_sup_neg]\n  filter_upwards [ae_eq_fun.coe_fn_sup f (-f), ae_eq_fun.coe_fn_neg f]with x hx_sup hx_neg\n  rw [hx_sup, hx_neg, Pi.neg_apply]\n#align measure_theory.ae_eq_fun.coe_fn_abs MeasureTheory.AeEqFun.coeFn_abs\n\nend Abs\n\nsection PosPart\n\nvariable [LinearOrder \u03b3] [OrderClosedTopology \u03b3] [Zero \u03b3]\n\n/-- Positive part of an `ae_eq_fun`. -/\ndef posPart (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u03b1 \u2192\u2098[\u03bc] \u03b3 :=\n  comp (fun x => max x 0) (continuous_id.max continuous_const) f\n#align measure_theory.ae_eq_fun.pos_part MeasureTheory.AeEqFun.posPart\n\n@[simp]\ntheorem posPart_mk (f : \u03b1 \u2192 \u03b3) (hf) :\n    posPart (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b3) =\n      mk (fun x => max (f x) 0)\n        ((continuous_id.max continuous_const).compAeStronglyMeasurable hf) :=\n  rfl\n#align measure_theory.ae_eq_fun.pos_part_mk MeasureTheory.AeEqFun.posPart_mk\n\ntheorem coeFn_posPart (f : \u03b1 \u2192\u2098[\u03bc] \u03b3) : \u21d1(posPart f) =\u1d50[\u03bc] fun a => max (f a) 0 :=\n  coeFn_comp _ _ _\n#align measure_theory.ae_eq_fun.coe_fn_pos_part MeasureTheory.AeEqFun.coeFn_posPart\n\nend PosPart\n\nend AeEqFun\n\nend MeasureTheory\n\nnamespace ContinuousMap\n\nopen MeasureTheory\n\nvariable [TopologicalSpace \u03b1] [BorelSpace \u03b1] (\u03bc)\n\nvariable [TopologicalSpace \u03b2] [SecondCountableTopologyEither \u03b1 \u03b2] [PseudoMetrizableSpace \u03b2]\n\n/-- The equivalence class of `\u03bc`-almost-everywhere measurable functions associated to a continuous\nmap. -/\ndef toAeEqFun (f : C(\u03b1, \u03b2)) : \u03b1 \u2192\u2098[\u03bc] \u03b2 :=\n  AeEqFun.mk f f.Continuous.AeStronglyMeasurable\n#align continuous_map.to_ae_eq_fun ContinuousMap.toAeEqFun\n\ntheorem coeFn_toAeEqFun (f : C(\u03b1, \u03b2)) : f.toAeEqFun \u03bc =\u1d50[\u03bc] f :=\n  AeEqFun.coeFn_mk f _\n#align continuous_map.coe_fn_to_ae_eq_fun ContinuousMap.coeFn_toAeEqFun\n\nvariable [Group \u03b2] [TopologicalGroup \u03b2]\n\n/-- The `mul_hom` from the group of continuous maps from `\u03b1` to `\u03b2` to the group of equivalence\nclasses of `\u03bc`-almost-everywhere measurable functions. -/\n@[to_additive\n      \"The `add_hom` from the group of continuous maps from `\u03b1` to `\u03b2` to the group of\\nequivalence classes of `\u03bc`-almost-everywhere measurable functions.\"]\ndef toAeEqFunMulHom : C(\u03b1, \u03b2) \u2192* \u03b1 \u2192\u2098[\u03bc] \u03b2\n    where\n  toFun := ContinuousMap.toAeEqFun \u03bc\n  map_one' := rfl\n  map_mul' f g :=\n    AeEqFun.mk_mul_mk _ _ f.Continuous.AeStronglyMeasurable g.Continuous.AeStronglyMeasurable\n#align continuous_map.to_ae_eq_fun_mul_hom ContinuousMap.toAeEqFunMulHom\n#align continuous_map.to_ae_eq_fun_add_hom ContinuousMap.to_ae_eq_fun_add_hom\n\nvariable {\ud835\udd5c : Type _} [Semiring \ud835\udd5c]\n\nvariable [TopologicalSpace \u03b3] [PseudoMetrizableSpace \u03b3] [AddCommGroup \u03b3] [Module \ud835\udd5c \u03b3]\n  [TopologicalAddGroup \u03b3] [ContinuousConstSMul \ud835\udd5c \u03b3] [SecondCountableTopologyEither \u03b1 \u03b3]\n\n/-- The linear map from the group of continuous maps from `\u03b1` to `\u03b2` to the group of equivalence\nclasses of `\u03bc`-almost-everywhere measurable functions. -/\ndef toAeEqFunLinearMap : C(\u03b1, \u03b3) \u2192\u2097[\ud835\udd5c] \u03b1 \u2192\u2098[\u03bc] \u03b3 :=\n  { to_ae_eq_fun_add_hom \u03bc with\n    map_smul' := fun c f => AeEqFun.smul_mk c f f.Continuous.AeStronglyMeasurable }\n#align continuous_map.to_ae_eq_fun_linear_map ContinuousMap.toAeEqFunLinearMap\n\nend ContinuousMap\n\n-- Guard against import creep\nassert_not_exists inner_product_space\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Function/AeEqFun.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7274381306097499}}
{"text": "import .tactics .ScholzeHelpLemmas\n\nopen real\n\nexample (s : \u211d) (h : 0 < s) : 4*s^s = exp(log 4 + s*log s) :=\nbegin\n  rw [exp_add, exp_log (show 0 < (4 : \u211d), by norm_num), \u2190 log_rpow h, exp_log],\n  apply rpow_pos_of_pos,\n  linarith,\nend\n\nexample (s : \u211d) (h : 0 < s) : (s+1)^(s+1) = exp((s+1) * log(s+1)) :=\nbegin\n  rw \u2190 log_rpow (show 0 < s+1, by linarith),\n  rw exp_log,\n  apply rpow_pos_of_pos,\n  linarith\nend\n\nexample (s : \u211d) (s_pos : 0 < s): (s+1)^(s+1) = exp((s+1) * log(s+1)) :=\nbegin\n  rw [\u2190 log_rpow (show 0 < s+1, by linarith), exp_log],\n  apply rpow_pos_of_pos,\n  linarith,\nend", "meta": {"author": "jamesa9283", "repo": "special-functions", "sha": "392758fb7207762c9ba6938462614994ff45bdc4", "save_path": "github-repos/lean/jamesa9283-special-functions", "path": "github-repos/lean/jamesa9283-special-functions/special-functions-392758fb7207762c9ba6938462614994ff45bdc4/src/ScholzeLog/logLemmas/examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7274342663105012}}
{"text": "/-\nCopyright (c) 2020 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n-/\n\nimport data.set.finite\nimport group_theory.subgroup.basic\nimport group_theory.submonoid.membership\n\n/-!\n# Subgroups\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides some result on multiplicative and additive subgroups in the finite context.\n\n## Tags\nsubgroup, subgroups\n-/\n\nopen_locale big_operators\n\nvariables {G : Type*} [group G]\nvariables {A : Type*} [add_group A]\n\nnamespace subgroup\n\n@[to_additive]\ninstance (K : subgroup G) [d : decidable_pred (\u2208 K)] [fintype G] : fintype K :=\nshow fintype {g : G // g \u2208 K}, from infer_instance\n\n@[to_additive]\ninstance (K : subgroup G) [finite G] : finite K :=\nsubtype.finite\n\nend subgroup\n\n/-!\n### Conversion to/from `additive`/`multiplicative`\n-/\nnamespace subgroup\n\nvariables (H K : subgroup G)\n\n/-- Product of a list of elements in a subgroup is in the subgroup. -/\n@[to_additive \"Sum of a list of elements in an `add_subgroup` is in the `add_subgroup`.\"]\nprotected lemma list_prod_mem {l : list G} : (\u2200 x \u2208 l, x \u2208 K) \u2192 l.prod \u2208 K :=\nlist_prod_mem\n\n/-- Product of a multiset of elements in a subgroup of a `comm_group` is in the subgroup. -/\n@[to_additive \"Sum of a multiset of elements in an `add_subgroup` of an `add_comm_group`\nis in the `add_subgroup`.\"]\nprotected \n\n@[to_additive]\nlemma multiset_noncomm_prod_mem (K : subgroup G) (g : multiset G) (comm) :\n  (\u2200 a \u2208 g, a \u2208 K) \u2192 g.noncomm_prod comm \u2208 K :=\nK.to_submonoid.multiset_noncomm_prod_mem g comm\n\n/-- Product of elements of a subgroup of a `comm_group` indexed by a `finset` is in the\n    subgroup. -/\n@[to_additive \"Sum of elements in an `add_subgroup` of an `add_comm_group` indexed by a `finset`\nis in the `add_subgroup`.\"]\nprotected lemma prod_mem {G : Type*} [comm_group G] (K : subgroup G)\n  {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 G} (h : \u2200 c \u2208 t, f c \u2208 K) :\n  \u220f c in t, f c \u2208 K :=\nprod_mem h\n\n@[to_additive]\nlemma noncomm_prod_mem (K : subgroup G) {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 G} (comm) :\n  (\u2200 c \u2208 t, f c \u2208 K) \u2192 t.noncomm_prod f comm \u2208 K :=\nK.to_submonoid.noncomm_prod_mem t f comm\n\n@[simp, norm_cast, to_additive] theorem coe_list_prod (l : list H) :\n  (l.prod : G) = (l.map coe).prod :=\nsubmonoid_class.coe_list_prod l\n\n@[simp, norm_cast, to_additive] theorem coe_multiset_prod {G} [comm_group G] (H : subgroup G)\n  (m : multiset H) : (m.prod : G) = (m.map coe).prod :=\nsubmonoid_class.coe_multiset_prod m\n\n@[simp, norm_cast, to_additive] theorem coe_finset_prod {\u03b9 G} [comm_group G] (H : subgroup G)\n  (f : \u03b9 \u2192 H) (s : finset \u03b9) :\n  \u2191(\u220f i in s, f i) = (\u220f i in s, f i : G) :=\nsubmonoid_class.coe_finset_prod f s\n\n@[to_additive] instance fintype_bot : fintype (\u22a5 : subgroup G) := \u27e8{1},\nby {rintro \u27e8x, \u27e8hx\u27e9\u27e9, exact finset.mem_singleton_self _}\u27e9\n\n/- curly brackets `{}` are used here instead of instance brackets `[]` because\n  the instance in a goal is often not the same as the one inferred by type class inference.  -/\n@[simp, to_additive] lemma card_bot {_ : fintype \u21a5(\u22a5 : subgroup G)} :\n  fintype.card (\u22a5 : subgroup G)  = 1 :=\nfintype.card_eq_one_iff.2\n  \u27e8\u27e8(1 : G), set.mem_singleton 1\u27e9, \u03bb \u27e8y, hy\u27e9, subtype.eq $ subgroup.mem_bot.1 hy\u27e9\n\n@[to_additive] lemma eq_top_of_card_eq [fintype H] [fintype G]\n  (h : fintype.card H = fintype.card G) : H = \u22a4 :=\nbegin\n  haveI : fintype (H : set G) := \u2039fintype H\u203a,\n  rw [set_like.ext'_iff, coe_top, \u2190 finset.coe_univ, \u2190 (H : set G).coe_to_finset, finset.coe_inj,\n    \u2190 finset.card_eq_iff_eq_univ, \u2190 h, set.to_finset_card],\n  congr\nend\n\n@[to_additive] lemma eq_top_of_le_card [fintype H] [fintype G]\n  (h : fintype.card G \u2264 fintype.card H) : H = \u22a4 :=\neq_top_of_card_eq H (le_antisymm (fintype.card_le_of_injective coe subtype.coe_injective) h)\n\n@[to_additive] lemma eq_bot_of_card_le [fintype H] (h : fintype.card H \u2264 1) : H = \u22a5 :=\nlet _ := fintype.card_le_one_iff_subsingleton.mp h in by exactI eq_bot_of_subsingleton H\n\n@[to_additive] lemma eq_bot_of_card_eq [fintype H] (h : fintype.card H = 1) : H = \u22a5 :=\nH.eq_bot_of_card_le (le_of_eq h)\n\n@[to_additive] lemma card_le_one_iff_eq_bot [fintype H] : fintype.card H \u2264 1 \u2194 H = \u22a5 :=\n\u27e8\u03bb h, (eq_bot_iff_forall _).2\n    (\u03bb x hx, by simpa [subtype.ext_iff] using fintype.card_le_one_iff.1 h \u27e8x, hx\u27e9 1),\n  \u03bb h, by simp [h]\u27e9\n\n@[to_additive] lemma one_lt_card_iff_ne_bot [fintype H] : 1 < fintype.card H \u2194 H \u2260 \u22a5 :=\nlt_iff_not_le.trans H.card_le_one_iff_eq_bot.not\n\nend subgroup\n\nnamespace subgroup\n\nsection pi\n\nopen set\n\nvariables {\u03b7 : Type*} {f : \u03b7 \u2192 Type*} [\u2200 i, group (f i)]\n\n@[to_additive]\nlemma pi_mem_of_mul_single_mem_aux [decidable_eq \u03b7] (I : finset \u03b7) {H : subgroup (\u03a0 i, f i) }\n  (x : \u03a0 i, f i) (h1 : \u2200 i, i \u2209 I \u2192 x i = 1) (h2 : \u2200 i, i \u2208 I \u2192 pi.mul_single i (x i) \u2208 H ) :\n  x \u2208 H :=\nbegin\n  induction I using finset.induction_on with i I hnmem ih generalizing x,\n  { convert one_mem H,\n    ext i,\n    exact (h1 i (not_mem_empty i)) },\n  { have : x = function.update x i 1 * pi.mul_single i (x i),\n    { ext j,\n      by_cases heq : j = i,\n      { subst heq, simp, },\n      { simp [heq], }, },\n    rw this, clear this,\n    apply mul_mem,\n    { apply ih; clear ih,\n      { intros j hj,\n        by_cases heq : j = i,\n        { subst heq, simp, },\n        { simp [heq], apply h1 j, simpa [heq] using hj, } },\n      { intros j hj,\n        have : j \u2260 i, by { rintro rfl, contradiction },\n        simp [this],\n        exact h2 _ (finset.mem_insert_of_mem hj), }, },\n    { apply h2, simp, } }\nend\n\n@[to_additive]\nlemma pi_mem_of_mul_single_mem [finite \u03b7] [decidable_eq \u03b7] {H : subgroup (\u03a0 i, f i)}\n  (x : \u03a0 i, f i) (h : \u2200 i, pi.mul_single i (x i) \u2208 H) : x \u2208 H :=\nby { casesI nonempty_fintype \u03b7,\n   exact pi_mem_of_mul_single_mem_aux finset.univ x (by simp) (\u03bb i _, h i) }\n\n/-- For finite index types, the `subgroup.pi` is generated by the embeddings of the groups.  -/\n@[to_additive \"For finite index types, the `subgroup.pi` is generated by the embeddings of the\nadditive groups.\"]\nlemma pi_le_iff [decidable_eq \u03b7] [finite \u03b7] {H : \u03a0 i, subgroup (f i)} {J : subgroup (\u03a0 i, f i)} :\n  pi univ H \u2264 J \u2194 \u2200 i : \u03b7, map (monoid_hom.single f i) (H i) \u2264 J :=\nbegin\n  split,\n  { rintros h i _ \u27e8x, hx, rfl\u27e9, apply h, simpa using hx },\n  { exact \u03bb h x hx, pi_mem_of_mul_single_mem  x (\u03bb i, h i (mem_map_of_mem _ (hx i trivial))), }\nend\n\nend pi\n\nend subgroup\n\nnamespace subgroup\n\nsection normalizer\n\nlemma mem_normalizer_fintype {S : set G} [finite S] {x : G}\n  (h : \u2200 n, n \u2208 S \u2192 x * n * x\u207b\u00b9 \u2208 S) : x \u2208 subgroup.set_normalizer S :=\nby haveI := classical.prop_decidable; casesI nonempty_fintype S;\nhaveI := set.fintype_image S (\u03bb n, x * n * x\u207b\u00b9); exact\n\u03bb n, \u27e8h n, \u03bb h\u2081,\nhave heq : (\u03bb n, x * n * x\u207b\u00b9) '' S = S := set.eq_of_subset_of_card_le\n  (\u03bb n \u27e8y, hy\u27e9, hy.2 \u25b8 h y hy.1) (by rw set.card_image_of_injective S conj_injective),\nhave x * n * x\u207b\u00b9 \u2208 (\u03bb n, x * n * x\u207b\u00b9) '' S := heq.symm \u25b8 h\u2081,\nlet \u27e8y, hy\u27e9 := this in conj_injective hy.2 \u25b8 hy.1\u27e9\n\nend normalizer\n\nend subgroup\n\nnamespace monoid_hom\n\nvariables {N : Type*} [group N]\n\nopen subgroup\n\n@[to_additive]\ninstance decidable_mem_range (f : G \u2192* N) [fintype G] [decidable_eq N] :\n  decidable_pred (\u2208 f.range) :=\n\u03bb x, fintype.decidable_exists_fintype\n\n-- this instance can't go just after the definition of `mrange` because `fintype` is\n-- not imported at that stage\n\n/-- The range of a finite monoid under a monoid homomorphism is finite.\nNote: this instance can form a diamond with `subtype.fintype` in the\npresence of `fintype N`. -/\n@[to_additive \"The range of a finite additive monoid under an additive monoid homomorphism is\nfinite.\n\nNote: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the\npresence of `fintype N`.\"]\ninstance fintype_mrange {M N : Type*} [monoid M] [monoid N] [fintype M] [decidable_eq N]\n  (f : M \u2192* N) : fintype (mrange f) :=\nset.fintype_range f\n\n/-- The range of a finite group under a group homomorphism is finite.\n\nNote: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the\npresence of `fintype N`. -/\n@[to_additive \"The range of a finite additive group under an additive group homomorphism is finite.\n\nNote: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the\npresence of `fintype N`.\"]\ninstance fintype_range  [fintype G] [decidable_eq N] (f : G \u2192* N) : fintype (range f) :=\nset.fintype_range f\n\nend monoid_hom\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/subgroup/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7274131373919762}}
{"text": "import tactic\nimport data.set.basic\n\n\n/--\nAn ideal of R consists of a nonempty subset of R which is closed under addition, additive inverses, \nand multiplication by elements of R.\n-/\n@[nolint has_inhabited_instance]\nstructure myideal (R : Type) [comm_ring R] :=\n  (iset : set R)\n  (not_empty : iset.nonempty)\n  (r_mul_mem' {x r}: x \u2208 iset \u2192 r * x \u2208 iset)\n  (add_mem' {x y} : x \u2208 iset \u2192 y \u2208 iset \u2192 (x + y) \u2208 iset)\n  (neg_mem' {x} : x \u2208 iset \u2192 -x \u2208 iset)\n  \nattribute [ext] myideal\n\nnamespace myideal\n\nvariables {R : Type} [comm_ring R] (I : myideal R)\ninstance : has_mem R (myideal R) :=\n{ mem := \u03bb x i , x \u2208 i.iset}\n\ninstance : has_coe (myideal R) (set R) := \n{coe := \u03bb x, x.iset}\n\ninstance : has_subset (myideal R) :=\n{ subset := \u03bb x y, x.iset \u2286 y.iset }\n\ntheorem add_mem {x y : R}: x \u2208 I \u2192 y \u2208 I \u2192 x + y \u2208 I := by apply add_mem'\n\ntheorem neg_mem {x : R} : x \u2208 I \u2192 -x \u2208 I := by apply neg_mem'\n\ntheorem r_mul_mem {x r : R} : x \u2208 I \u2192 r * x \u2208 I := by apply r_mul_mem'\nend myideal\n\n\nvariables {R : Type} [comm_ring R]\n\n/--\nAn integral domain has no zero divisors.\n-/\ndef is_integral_domain (R: Type) [comm_ring R]: Prop :=\n  \u2200 (x y : R), x * y = 0 \u2192 x = 0 \u2228 y = 0\n\n/--\nA principal ideal is of the form aR for some a \u2208 R\n-/\ndef principal_ideal (x : R) : myideal R :=\n{ \n  iset := { i : R | \u2203(v:R), i = x * v},\n  not_empty := begin\n    rw set.nonempty_def,\n    use x,\n    use 1,\n    rw mul_one,\n  end,\n  r_mul_mem' := begin\n    intro i,\n    intro j,\n    intro h,\n    cases h,\n    use (j * h_w),\n    rw h_h,\n    ring,\n  end,\n  add_mem' := begin\n    intros i j hi hj,\n    cases hi,\n    cases hj,\n    use hi_w + hj_w,\n    rw mul_add,\n    rw hi_h, rw hj_h,\n  end,\n  neg_mem' := begin\n    intros i hi,\n    cases hi,\n    use -hi_w,\n    rw hi_h,\n    ring,\n  end \n}\n/--\nAn integral domain is a PID iff every ideal is principal.\n-/\ndef is_pid (R: Type) [comm_ring R]: Prop :=\n  is_integral_domain R \u2227 \u2200(I : myideal R), \u2203 (x : R), I = principal_ideal x\n\n\n--1 \u2208 I \u2192 I = R\nlemma one_mem_ideal_R {I : myideal R} : (1:R) \u2208 I \u2192 coe I = {x : R | true} :=\nbegin\n  intro h,\n  ext,\n  split,\n  intro, triv,\n  intro h2,\n  rw \u2190mul_one x,\n  apply myideal.r_mul_mem, \n  exact h,\nend\n\nlemma zero_mem_ideal {I : myideal R} : (0:R) \u2208 I :=\nbegin\n  have h := myideal.not_empty I,\n  rw set.nonempty at h,\n  cases h with x hx,\n  have h2 : x + (-x) = 0,\n  ring,\n  rw \u2190h2,\n  apply myideal.add_mem I,\n  exact hx,\n  apply myideal.neg_mem I,\n  exact hx,\nend\n\n/--\nThe sum of two ideals is also an ideal.\n-/\ndef sum_ideal (I J : myideal R) : myideal R :=\n{ iset := {r : R | \u2203 (i \u2208 I) (j \u2208 J), r = i + j},\n  not_empty := begin\n    have h1 := myideal.not_empty I,\n    have h2 := myideal.not_empty J,\n    rw set.nonempty at h1 h2 \u22a2,\n    cases h1,\n    cases h2,\n    use h1_w + h2_w,\n    use h1_w, split, exact h1_h,\n    use h2_w, split, exact h2_h,\n    refl,\n  end,\n  r_mul_mem' := begin\n    intros x r h,\n    cases h with i h2,\n    cases h2 with hi h2,\n    cases h2 with j h2,\n    cases h2 with hj h2,\n    rw h2,\n    rw mul_add,\n    use r * i,\n    split,\n      apply myideal.r_mul_mem,\n      exact hi,\n    use r * j,\n    split,\n      apply myideal.r_mul_mem,\n      exact hj,\n    refl,\n  end,\n  add_mem' := begin\n    intros x y hxm hym,\n    cases hxm with xi hxi,\n    cases hxi with hxi h2,\n    cases h2 with xj hxj,\n    cases hxj with hxj hx,\n    cases hym with yi hyi,\n    cases hyi with hyi h2,\n    cases h2 with yj hyj,\n    cases hyj with hyj hy,\n    use xi + yi,\n    split,\n    apply myideal.add_mem, exact hxi, exact hyi,\n    use xj + yj,\n    split,\n    apply myideal.add_mem, exact hxj, exact hyj,\n    rw hy,\n    rw hx,\n    ring,\n  end,\n  neg_mem' := begin\n    intros x h,\n    cases h with i hi,\n    cases hi with hi h2,\n    cases h2 with j h2,\n    cases h2 with hj h2,\n    use -i,\n    split,\n    apply myideal.neg_mem,\n    exact hi,\n    use -j,\n    split,\n    apply myideal.neg_mem,\n    exact hj,\n    rw h2, ring,\n  end \n}\n\nnotation I ` + ` J := sum_ideal I J\n\n/--\nAn element r of R is irreducible iff it is not a unit and \nfor all factorisations x * y = r, x or y is a unit.\n-/\ndef irreducible (r : R) : Prop :=\n  \u00acis_unit r \u2227 \u2200(x y : R), x * y = r \u2192 is_unit x \u2228 is_unit y\n\nlemma r_prod_unit_r_unit (r a : R) (hpu : is_unit (r * a)) :\n  is_unit r :=\nbegin\n  have h2:=  is_unit.exists_right_inv hpu,\n  cases h2,\n  rw is_unit_iff_exists_inv',\n  use a * h2_w, rw mul_comm, rw \u2190 mul_assoc, exact h2_h,\nend\n\nlemma unit_mul_irr_is_irr (r a : R) (hirr :irreducible r) (hu: is_unit a) :\n irreducible (a * r) :=\nbegin\n  split,\n  {\n    by_contra,\n    cases hirr, \n    apply hirr_left, \n    apply r_prod_unit_r_unit r a, \n    rw mul_comm, \n    exact h\n  },\n  {\n    intros x y h,\n    have h2 : \u2203 (b : R), r = (b * x) * y,\n      rw is_unit_iff_exists_inv at hu,\n      cases hu with c h3,\n      use c, rw mul_assoc, rw h,\n      ring_nf, rw mul_assoc, rw h3, rw mul_one,\n    cases hirr,\n    cases h2 with b hb,\n    specialize hirr_right (b * x) y,\n    rw eq_comm at hb,\n    have h3 := hirr_right hb,\n    cases h3,\n    left, \n      rw mul_comm at h3, \n      apply r_prod_unit_r_unit x b, \n      exact h3,\n    right,\n    exact h3,\n  }\nend\n\n/--\n  For some a and b, a divides b iff there is a c \u2208 R such that a * c = b\n-/\ndef divisible (a b: R) : Prop :=\n  \u2203 (c : R), b = a * c\n\nnotation a ` \\ ` b := divisible a b\n\n/--\n  Two elements a b are associates iff a = b * c for some unit c.\n-/\ndef associates (a b : R) : Prop :=\n  \u2203 (c : R), is_unit c \u2227 b = a * c\n\nnotation a ` ~ ` b := associates a b\n\nlemma assoc_sym (a b : R) : a ~ b \u2192 b ~ a:=\nbegin\n  intro h,\n  cases h with u h2,\n  cases h2 with hunit h3,\n  rw is_unit_iff_exists_inv at hunit,\n  cases hunit with uinv huinv,\n  use uinv,\n  split,\n    rw is_unit_iff_exists_inv,\n    use u,\n    rw mul_comm, \n    exact huinv,\n  rw h3,\n  rw mul_assoc,\n  rw huinv,\n  rw mul_one,\nend\n\nlemma symm_divisible_associates_int_domain (hint : is_integral_domain R) (a b : R) : a \\ b \u2192 b \\ a \u2192 a ~ b :=\nbegin\n  intros h1 h2,\n  cases h1 with x hx,\n  cases h2 with y hy,\n  by_cases a \u2260 0,\n  {\n    rw hx at hy,\n    apply_fun \u03bb x, x + (-a) at hy,\n    rw add_neg_self at hy,\n    rw \u2190mul_one (-a) at hy,\n    rw neg_mul_comm a 1 at hy,\n    rw mul_assoc at hy,\n    rw \u2190mul_add at hy,\n    specialize hint a (x * y + (-1)),\n    have h2 := hint (eq.symm hy),\n    cases h2,\n    exfalso, apply h, exact h2,\n    apply_fun \u03bb x, x + 1 at h2,\n    rw zero_add at h2,\n    rw add_assoc at h2,\n    rw neg_add_self at h2,\n    rw add_zero at h2,\n    use x,\n    split,\n    rw is_unit_iff_exists_inv,\n    use y, \n    exact h2,\n    exact hx,\n  },\n  {\n    use 1,\n    split,\n    exact is_unit_one,\n    rw not_ne_iff at h,\n    rw h at hx,\n    rw hx,\n    rw h,\n    rw zero_mul,\n    rw zero_mul,\n  }\nend\n\nlemma generators_associate_if_ideals_eq (a b : R) (hint : is_integral_domain R):\n  principal_ideal a = principal_ideal b \u2192 a ~ b :=\nbegin\n  intro h,\n  have h1 : a \u2208 principal_ideal a,\n    use 1, rw mul_one,\n  have h2 : b \u2208 principal_ideal b,\n    use 1, rw mul_one,\n  rw h at h1,\n  rw \u2190h at h2,\n  apply symm_divisible_associates_int_domain,\n  exact hint,\n  exact h2,\n  exact h1,\nend\n\n/--\nIn a dividing sequence, each term is divisible by the next term.\n-/\ndef dividing_sequence (f : \u2115 \u2192 R) : Prop :=\n\u2200 (n : \u2115),  f (n + 1) \\ f n\n\n/--\nA unique factorisation domain (UFD) is an integral domain such that:\n  All infinite dividing sequences 'stabilise': past some n \u2208 \u2115, all terms are associate.#check\n  All irreducible elements are prime.\n-/\ndef is_ufd  (R : Type) [comm_ring R] : Prop :=\n  is_integral_domain R \u2227 (\u2200(f : \u2115 \u2192 R), dividing_sequence f \u2192 \n  \u2203 (m : \u2115), \u2200(q : \u2115), m \u2264 q \u2192 f q ~ f (q + 1) ) \u2227\n   (\u2200 (p: R), irreducible p \u2192\u2200 (a b: R), p \\ (a*b) \u2192 p \\ a \u2228 p \\ b )\n\n/--\nIn an ascending ideal chain, each ideal is contained in the next one.\n-/\ndef asc_ideal_chain (i : \u2115 \u2192 myideal R) : Prop :=\n  \u2200 (n : \u2115), i n \u2286 i (n + 1) \n\nlemma asc_ideal_chain_add (i : \u2115 \u2192 myideal R) :\nasc_ideal_chain i \u2192 \u2200(n : \u2115), \u2200 (m : \u2115),  i n \u2286  i (m+n) :=\nbegin\n  intros h n m,\n  induction m,\n  rw zero_add, refl,\n  specialize h (m_n + n),\n  rw nat.succ_eq_add_one,\n  \n  change (i n).iset \u2286 (i (m_n + n)).iset at m_ih,\n  change (i (m_n + n)).iset \u2286 (i (m_n + n + 1)).iset at h,\n  change (i n).iset \u2286 (i (m_n + 1 + n)).iset,\n  apply set.subset.trans,\n  exact m_ih,\n  nth_rewrite_rhs 1 add_comm,\n  rw add_assoc,\n  nth_rewrite_rhs 0 add_comm,\n  exact h,\nend\n\nlemma asc_ideal_chain_ind (i : \u2115 \u2192 myideal R) :\nasc_ideal_chain i \u2194 \u2200(n : \u2115), \u2200 (m : \u2115),  n \u2264 m \u2192 i n \u2286 i m :=\nbegin\n  split,\n  {\n    intros h n m h2,\n    have h3 : \u2203 (r: \u2115), n + r = m,\n      use m - n,\n      linarith,\n    cases h3 with s hs,\n    rw \u2190hs,\n    rw add_comm,\n    apply asc_ideal_chain_add,\n    exact h,\n  },\n  {\n    intros h n,\n    specialize h n (n+1),\n    apply h,\n    norm_num,\n  }\nend\n\ntheorem pid_is_noetherian (R : Type) [comm_ring R] (hpid : is_pid R) \n(i :\u2115 \u2192  myideal R) (hinc : asc_ideal_chain i)  : \n\u2203(r : \u2115), \u2200(s : \u2115 ), r \u2264 s \u2192 i s = i (s + 1)\n :=\nbegin\n  cases hpid with hint hpid,\n  let S := set.Union (\u03bb (x : \u2115), myideal.iset (i x)),\n  let si := myideal.mk S,\n  let sii : myideal R,\n  apply si,\n  {\n    rw set.nonempty, \n    let i0 := i 0,\n    have hne := myideal.not_empty i0,\n    rw set.nonempty at hne,\n    cases hne with x0 hx0,\n    use x0,\n    rw set.mem_Union,\n    use 0, exact hx0,\n  },\n  {\n    intros x r h,\n    rw set.mem_Union at h \u22a2,\n    cases h,\n    use h_w,\n    apply myideal.r_mul_mem',\n    exact h_h,\n  },{\n    intros x y h1 h2,\n    rw set.mem_Union at h1 h2 \u22a2,\n    cases h1 with i1 hi1,\n    cases h2 with i2 hi2,\n    by_cases i1 \u2264 i2,\n    {\n      have h3 := ((asc_ideal_chain_ind i).mp) hinc,\n      specialize h3 i1 i2,\n      have h4 := h3 h,\n      use i2,\n      apply myideal.add_mem',\n      apply set.mem_of_subset_of_mem h4,\n      exact hi1,\n      exact hi2,\n    },\n    {\n      have hbt : i2 \u2264 i1,\n        rw le_iff_lt_or_eq,\n        left,\n        push_neg at h,\n        exact h,\n      have h3 := ((asc_ideal_chain_ind i).mp) hinc,\n      specialize h3 i2 i1,\n      have h4 := h3 hbt,\n      use i1,\n      apply myideal.add_mem',\n      exact hi1,\n      apply set.mem_of_subset_of_mem h4,\n      exact hi2,\n    } \n  },{\n    intros x h,\n    rw set.mem_Union at h \u22a2,\n    cases h with b hb,\n    use b,\n    apply myideal.neg_mem',\n    exact hb,\n  },\n  specialize hpid sii,\n  cases hpid with a ha,\n  have hasi : a \u2208 sii,\n    rw ha,\n    change \u2203(v:R), a = a * v,\n    use 1,\n    rw mul_one,\n  change a \u2208 sii.iset at hasi,\n  rw set.mem_Union at hasi,\n  cases hasi with q hq,\n  use q,\n  intro s,\n  intro hsq,\n  have hisq : (i q).iset = S,\n  {\n    ext,\n    split,\n      intro h,\n      rw set.mem_Union,\n      use q, exact h,\n    intro h,\n    change x \u2208 sii.iset at h,\n    rw ha at h,\n    cases h,\n    rw mul_comm at h_h,\n    rw h_h,\n    apply myideal.r_mul_mem',\n    exact hq,\n  },\n  apply myideal.ext,\n  apply set.subset.antisymm,\n  specialize hinc s,\n  exact hinc,\n  apply @set.subset.trans _ (i (s + 1)).iset (i q).iset,\n  rw hisq,\n  exact set.subset_Union (\u03bb (x : \u2115), myideal.iset (i x)) (s + 1),\n  rw asc_ideal_chain_ind at hinc,\n  specialize hinc q s,\n  apply hinc,\n  exact hsq,\nend\n\ntheorem pid_irreducible_is_prime (hpid : is_pid R)  (p : R) (hirr : irreducible p) :\n  \u2200 (a b : R), p \\ (a * b) \u2192 p \\ a \u2228  p \\ b :=\nbegin\n  cases hpid with hint hpid,\n  intros a b h,\n  let I := sum_ideal (principal_ideal a) (principal_ideal p),\n  specialize hpid I,\n  cases hpid with d hd,\n  have hpi: p \u2208 I,\n    use 0,\n    split,\n    exact zero_mem_ideal,\n    use p,\n    split,\n    use 1,\n    rw mul_one,\n    rw zero_add,\n  rw hd at hpi,\n  cases hpi with r hdr,\n  cases hirr,\n  specialize hirr_right d r,\n  have hut := hirr_right (eq_comm.mpr hdr),\n  cases hut,\n  { \n    right,\n    have hone : (1:R) \u2208 I,\n      rw is_unit_iff_exists_inv at hut,\n      rw hd,\n      cases hut with di hdi,\n      use di,\n      rw hdi,\n    cases hone with u h2,\n    cases h2 with hu h2,\n    cases h2 with v h2,\n    cases h2 with hv h2,\n    cases hu with s hs,\n    cases hv with t ht,\n    rw hs at h2,\n    rw ht at h2,\n    apply_fun \u03bb x, b*x at h2,\n    rw mul_one at h2,\n    rw mul_add at h2,\n    rw h2,\n    rw \u2190 mul_assoc,\n    rw mul_comm b a,\n    cases h with q hq,\n    rw hq,\n    use q * s + b * t,\n    ring,\n  },{\n    have hai : a \u2208 I,\n      use a,\n      split,\n      use 1,\n      rw mul_one,\n      use 0,\n      split,\n      exact zero_mem_ideal,\n      rw add_zero,\n    rw hd at hai,\n    cases hai with e he,\n    rw is_unit_iff_exists_inv at hut,\n    cases hut with ri hri,\n    apply_fun \u03bb x, x * ri at hdr,\n    rw mul_assoc at hdr,\n    rw hri at hdr, \n    rw mul_one at hdr,\n    rw \u2190hdr at he,\n    left,\n    use (ri * e),\n    rw \u2190 mul_assoc, \n    exact he,\n  }\nend\n\ntheorem pid_is_ufd (R : Type) [hc : comm_ring R] (hpid : is_pid R): is_ufd R:=\nbegin\n  split,\n    exact hpid.left,\n  split,\n  {\n    intro f,\n    intro h,\n    let i := \u03bb(x : \u2115), principal_ideal (f x),\n    have hinc : asc_ideal_chain i,\n      intro n,\n      change principal_ideal (f n) \u2286 principal_ideal (f (n+1)),\n      specialize h n,\n      cases h with y hy,\n      rw hy,\n      intros x h2,\n      cases h2 with z hz,\n      use y * z,\n      rw \u2190 mul_assoc,\n      exact hz,\n    have hnoet := pid_is_noetherian R hpid,\n    specialize hnoet i,\n    have hstab := hnoet hinc,\n    cases hstab with m hm,\n    use m,\n    intro q,\n    specialize hm q,\n    intro hmq,\n    have hiqs := hm hmq,\n    apply generators_associate_if_ideals_eq,\n    exact hpid.left,\n    exact hiqs,\n  },\n  {\n    exact pid_irreducible_is_prime hpid,\n  }\nend\n#lint", "meta": {"author": "sterguel", "repo": "formalising-mathematics", "sha": "ecbb2b6d22ee08606c54b3968bf96950488aed42", "save_path": "github-repos/lean/sterguel-formalising-mathematics", "path": "github-repos/lean/sterguel-formalising-mathematics/formalising-mathematics-ecbb2b6d22ee08606c54b3968bf96950488aed42/src/cw2/cw2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7274131349665646}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (s \\ t) \\ u \u2286 s \\ (t \u222a u)\n-- ----------------------------------------------------------------------\n\nimport tactic\n\nvariable {\u03b1 : Type*}\nvariables (s t u : set \u03b1)\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x xstu,\n  have xs : x \u2208 s := xstu.1.1,\n  have xnt : x \u2209 t := xstu.1.2,\n  have xnu : x \u2209 u := xstu.2,\n  split,\n  { exact xs }, \n  { dsimp,\n    intro xtu, \n    cases xtu with xt xu,\n    { show false, \n      from xnt xt },\n    { show false, \n      from xnu xu }},\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1\n\u22a2 s \\ t \\ u \u2286 s \\ (t \u222a u)\n  >> intros x xstu,\nx : \u03b1,\nxstu : x \u2208 s \\ t \\ u\n\u22a2 x \u2208 s \\ (t \u222a u)\n  >> have xs : x \u2208 s := xstu.1.1,\nxs : x \u2208 s\n\u22a2 x \u2208 s \\ (t \u222a u)\n  >> have xnt : x \u2209 t := xstu.1.2,\nxnt : x \u2209 t\n\u22a2 x \u2208 s \\ (t \u222a u)\n  >> have xnu : x \u2209 u := xstu.2,\nxnu : x \u2209 u\n\u22a2 x \u2208 s \\ (t \u222a u)\n  >> split,\n| \u22a2 x \u2208 s\n|   >> { exact xs },\n\u22a2 (\u03bb (a : \u03b1), a \u2209 t \u222a u) x \n  >> { dsimp,\n\u22a2 \u00ac(x \u2208 t \u2228 x \u2208 u)\n  >>   intro xtu, \nxtu : x \u2208 t \u2228 x \u2208 u\n\u22a2 false\n  >>   cases xtu with xt xu,\n| xt : x \u2208 t\n| \u22a2 false\n|   >>   { show false, \n| \u22a2 false\n|   >>     from xnt xt },\nxu : x \u2208 u\n\u22a2 false\n  >>   { show false,\n\u22a2 false \n  >>     from xnu xu }},\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ t \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8xs, xnt\u27e9, xnu\u27e9,\n  use xs,\n  rintros (xt | xu), \n  { contradiction },\n  { contradiction },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1\n\u22a2 s \\ t \\ u \u2286 s \\ (t \u222a u)\n  >> rintros x \u27e8\u27e8xs, xnt\u27e9, xnu\u27e9,\nx : \u03b1,\nxnu : x \u2209 u,\nxs : x \u2208 s,\nxnt : x \u2209 t\n\u22a2 x \u2208 s \\ (t \u222a u)\n  >> use xs,\n\u22a2 (\u03bb (a : \u03b1), a \u2209 t \u222a u) x\n  >> rintros (xt | xu), \n| xt : x \u2208 t\n| \u22a2 false\n|   >> { contradiction },\nxu : x \u2208 u\n\u22a2 false\n  >> { contradiction },\nno goals\n-/\n\n\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ t \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8xs, xnt\u27e9, xnu\u27e9,\n  use xs,\n  rintros (xt | xu); contradiction\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    s \\ (t \u222a u) \u2286 (s \\ t) \\ u\n-- ----------------------------------------------------------------------\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  rintros x \u27e8xs, xntu\u27e9,\n  use xs,\n  { intro xt, \n    exact xntu (or.inl xt) },\n  { intro xu,\n    apply xntu (or.inr xu) },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1\n\u22a2 s \\ (t \u222a u) \u2286 s \\ t \\ u\n  >> rintros x \u27e8xs, xntu\u27e9,\nx : \u03b1,\nxs : x \u2208 s,\nxntu : x \u2209 t \u222a u\n\u22a2 x \u2208 s \\ t \\ u\n  >> use xs,\n| \u22a2 (\u03bb (a : \u03b1), a \u2209 t) x\n|   >> { intro xt, \n| xt : x \u2208 t\n| \u22a2 false\n|   >>   exact xntu (or.inl xt) },\n\u22a2 (\u03bb (a : \u03b1), a \u2209 u) x\n  >> { intro xu,\nxu : x \u2208 u\n\u22a2 false\n  >>   apply xntu (or.inr xu) },\nno goals\n-/\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Diferencia_de_diferencia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7274131339805322}}
{"text": "import data.fintype.big_operators algebra.big_operators.intervals algebra.big_operators.order\n\n/-! # IMO 2006 A2 -/\n\nnamespace IMOSL\nnamespace IMO2006A2\n\nopen finset\n\nvariables {F : Type*} [linear_ordered_field F]\n\nprivate lemma div_sub_lt_div_sub {a b c : F} (h : 0 < a) (h0 : a < b) (h1 : b < c) :\n  c / (c - a) < b / (b - a) :=\n  by rwa [div_lt_div_iff (sub_pos.mpr (lt_trans h0 h1)) (sub_pos.mpr h0),\n    mul_sub, mul_sub, mul_comm, sub_lt_sub_iff_left, mul_lt_mul_right h]\n\n\n\ndef a : \u2115 \u2192 F := nat.strong_rec' (\u03bb n (f : \u03a0 m, m < n \u2192 F),\n    ite (n = 0) (-1) (-(univ : finset (fin n)).sum (\u03bb i, f i i.2 / (n.succ - i))))\n\nprivate lemma a_zero : a 0 = (-1 : F) :=\n  by rw [a, nat.strong_rec', if_pos rfl] \n\nprivate lemma a_nonzero {n : \u2115} (h : n \u2260 0) :\n  (a n : F) = - (range n).sum (\u03bb i, a i / (n.succ - i)) :=\n  by rw [\u2190 fin.sum_univ_eq_sum_range, a, nat.strong_rec', \u2190 a, if_neg h]; refl\n\n\n\n/-- Final solution -/\ntheorem final_solution {n : \u2115} (h : 0 < n) : 0 < (a n : F) :=\nbegin\n  ---- Setup for strong induction, including the base case\n  rw [\u2190 nat.succ_le_iff, le_iff_exists_add'] at h,\n  rcases h with \u27e8n, rfl\u27e9,\n  induction n using nat.strong_induction_on with n n_ih,\n  rcases n.eq_zero_or_pos with rfl | h,\n  rw [zero_add, a_nonzero one_ne_zero, sum_range_one, a_zero, neg_div,\n      neg_neg, one_div_pos, sub_pos, nat.cast_two, nat.cast_zero],\n  exact two_pos,\n\n  ---- Induction step\n  have X : 0 < (n.succ.succ : F) := nat.cast_pos.mpr n.succ.succ_pos,\n  rw [a_nonzero n.succ_ne_zero, neg_pos, sum_range_succ', nat.cast_zero,\n      sub_zero, \u2190 lt_neg_iff_add_neg, \u2190 neg_div, lt_div_iff X, sum_mul],\n  replace X : (a n : F) = _ := a_nonzero (ne_of_gt h),\n  have X0 : (n.succ : F) \u2260 0 := nat.cast_ne_zero.mpr n.succ_ne_zero,\n  rw [eq_neg_iff_add_eq_zero, \u2190 sum_range_succ_sub_top, nat.cast_succ, add_tsub_cancel_left,\n      div_one, add_sub_cancel'_right, sum_range_succ', nat.cast_zero, \u2190 nat.cast_succ,\n      sub_zero, add_eq_zero_iff_eq_neg, \u2190 neg_div, eq_div_iff X0] at X,\n  rw [\u2190 X, sum_mul]; clear X X0,\n  refine sum_lt_sum_of_nonempty (nonempty_range_iff.mpr $ ne_of_gt h) (\u03bb i h0, _),\n  rw mem_range at h0,\n  rw [mul_comm_div, mul_comm_div, mul_lt_mul_left (n_ih i h0)],\n  refine div_sub_lt_div_sub (nat.cast_pos.mpr i.succ_pos) _ _,\n  rwa [nat.cast_lt, nat.succ_lt_succ_iff],\n  rw nat.cast_lt; exact n.succ.lt_succ_self\nend\n\nend IMO2006A2\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2006/A2/A2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7274131330143343}}
{"text": "import linear_algebra.tensor_product\n\nimport tut2\n\nopen_locale tensor_product\n\nvariables {\u210b : Type} [complex_hilbert_space \u210b]\n{\u03c1 \u03c3 \u03c4 : \u210b \u2192\u2097[\u2102] \u210b} [quantum_state \u03c1] [quantum_state \u03c3] [quantum_state \u03c4]\n\n#check tensor_product\n#check \u03c1 \u2297\u209c[\u2102] \u03c3\n\nnotation A ` \u2297 ` B := A \u2297\u209c[\u2102] B\n\nexample {a : \u2102} : a \u2022 (\u03c1 \u2297 \u03c3) = (a \u2022 \u03c1) \u2297 \u03c3 :=\nbegin\n    exact rfl,\nend\n\nexample {a : \u2102} : a \u2022 (\u03c1 \u2297 \u03c3) = \u03c1 \u2297 (a \u2022 \u03c3) :=\nbegin\n    norm_num,\nend\n\nexample {a : \u2102} : a \u2022 (\u03c1 + \u03c3) = a \u2022 \u03c1 + a \u2022 \u03c3 := \nbegin\n    rw smul_add,\nend\n\nexample : \u03c1 \u2297 (\u03c3 + \u03c4) = \u03c1 \u2297 \u03c3 + \u03c1 \u2297 \u03c4 := \nbegin\n    rw tensor_product.tmul_add,\nend \n\nexample : (\u03c3 + \u03c4) \u2297 \u03c1 = \u03c3 \u2297 \u03c1 + \u03c4 \u2297 \u03c1 := \nbegin\n    rw tensor_product.add_tmul,\nend", "meta": {"author": "BassemSafieldeen", "repo": "Lean-tutorials", "sha": "031a14fa9700898e9895c9d41be8495275618c46", "save_path": "github-repos/lean/BassemSafieldeen-Lean-tutorials", "path": "github-repos/lean/BassemSafieldeen-Lean-tutorials/Lean-tutorials-031a14fa9700898e9895c9d41be8495275618c46/src/tut3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012640659996, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.7273970503778598}}
{"text": "/-\nCopyright (c) 2023 Tian Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tian Chen\n-/\n\nimport analysis.mean_inequalities\nimport matrix.doubly_stochastic.birkhoff\nimport ineq.symm_sum\nimport ineq.doubly_stochastic\n\nopen_locale big_operators\n\nopen finset\n\nlemma real.prod_pow {\u03b9 : Type*} {a : \u211d} {s : finset \u03b9} {f : \u03b9 \u2192 \u211d} (h : \u2200 x \u2208 s, 0 \u2264 f x) :\n  (\u220f x in s, f x) ^ a = \u220f x in s, f x ^ a :=\nbegin\n  induction s using finset.cons_induction with i s his hs,\n  { exact real.one_rpow _ },\n  rw finset.forall_mem_cons at h,\n  rw [prod_cons, prod_cons, real.mul_rpow h.1 (prod_nonneg h.2), hs h.2]\nend\n\nvariables {\u03b9 : Type*} [fintype \u03b9] [decidable_eq \u03b9]\n\nprivate lemma symm_mean_right_sum_le {\u03b9' : Type*} [fintype \u03b9']\n  (c : \u03b9' \u2192 \u211d) (hc0 : \u2200 i, 0 \u2264 c i)\n  (hc1 : \u2211 i, c i = 1)\n  (v : \u03b9' \u2192 \u03b9 \u2192 \u211d) (z : \u03b9 \u2192 \u211d) (hz : \u2200 i, 0 < z i) :\n  symm_mean z (\u2211 i, c i \u2022 v i) \u2264 \u2211 i, c i * symm_mean z (v i) :=\nbegin\n  simp_rw [symm_mean_def, mul_sum, sum_apply, pi.smul_apply, smul_eq_mul],\n  rw sum_comm,\n  apply sum_le_sum,\n  intros \u03c3 _,\n  calc  \u220f i, z i ^ \u2211 j, c j * v j (\u03c3 i)\n      = \u220f i, \u220f j, z i ^ (c j * v j (\u03c3 i)) :\n          prod_congr rfl $ \u03bb i _, real.rpow_sum_of_pos (hz _) _ _\n  ... = \u220f i, \u220f j, (z i ^ v j (\u03c3 i)) ^ c j :\n          prod_congr rfl $ \u03bb i _, prod_congr rfl $ \u03bb j _,\n            by rw mul_comm; exact real.rpow_mul (hz _).le _ _\n  ... = \u220f j, (\u220f i, z i ^ v j (\u03c3 i)) ^ c j :\n          by rw prod_comm; apply prod_congr rfl; intros j _;\n            rw real.prod_pow;\n            intros;\n            exact (real.rpow_pos_of_pos (hz _) _).le\n  ... \u2264 \u2211 j, c j * \u220f i, z i ^ v j (\u03c3 i) :\n          real.geom_mean_le_arith_mean_weighted _ c _ (\u03bb _ _, hc0 _) hc1 $\n            \u03bb _ _, prod_nonneg $ \u03bb _ _, (real.rpow_pos_of_pos (hz _) _).le\nend\n\n/-- **Muirhead's Inequality** -/\ntheorem majorize.symm_mean_le_symm_mean {p q : \u03b9 \u2192 \u211d} (hpq : majorize q p)\n  (z : \u03b9 \u2192 \u211d) (hz : \u2200 i, 0 < z i) :\n  symm_mean z q \u2264 symm_mean z p :=\nbegin\n  obtain \u27e8M, hM, hM'\u27e9 := hpq.exists_doubly_stochastic,\n  rcases hM.mem_convex_hull' with \u27e8w, hw0, hw1, hMw\u27e9,\n  rw [show q = matrix.mul_vec.add_monoid_hom_left p M, from hM', hMw, map_sum],\n  rw [matrix.mul_vec.add_monoid_hom_left, add_monoid_hom.coe_mk],\n  simp_rw [matrix.smul_mul_vec_assoc],\n  convert symm_mean_right_sum_le w hw0 hw1 _ z hz,\n  have : \u2200 \u03c3 : \u03b9 \u2243 \u03b9, \u03c3.to_pequiv.to_matrix.mul_vec p = p \u2218 \u03c3,\n  { intro \u03c3,\n    ext i,\n    rw [function.comp_app, matrix.mul_vec, matrix.dot_product],\n    simp_rw [pequiv.equiv_to_pequiv_to_matrix, matrix.one_apply, boole_mul],\n    rw [sum_ite_eq, if_pos (mem_univ _)] },\n  simp_rw [this, symm_mean_equiv_right],\n  rw [\u2190 sum_mul, hw1, one_mul]\nend\n", "meta": {"author": "peakpoint", "repo": "muirhead", "sha": "f6cbdafa9e9c1626d37378493fce68cc68eeea97", "save_path": "github-repos/lean/peakpoint-muirhead", "path": "github-repos/lean/peakpoint-muirhead/muirhead-f6cbdafa9e9c1626d37378493fce68cc68eeea97/src/ineq/muirhead.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7273745689090627}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.calculus.deriv\nimport linear_algebra.affine_space.slope\n\n/-!\n# Slope of a differentiable function\n\nGiven a function `f : \ud835\udd5c \u2192 E` from a nondiscrete normed field to a normed space over this field,\n`dslope f a b` is defined as `slope f a b = (b - a)\u207b\u00b9 \u2022 (f b - f a)` for `a \u2260 b` and as `deriv f a`\nfor `a = b`.\n\nIn this file we define `dslope` and prove some basic lemmas about its continuity and\ndifferentiability.\n-/\n\nopen_locale classical topological_space filter\nopen function set filter\n\nvariables {\ud835\udd5c E : Type*} [nondiscrete_normed_field \ud835\udd5c] [normed_group E] [normed_space \ud835\udd5c E]\n\n/-- `dslope f a b` is defined as `slope f a b = (b - a)\u207b\u00b9 \u2022 (f b - f a)` for `a \u2260 b` and\n`deriv f a` for `a = b`. -/\nnoncomputable def dslope (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : \ud835\udd5c \u2192 E := update (slope f a) a (deriv f a)\n\n@[simp] lemma dslope_same (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : dslope f a a = deriv f a := update_same _ _ _\n\nvariables {f : \ud835\udd5c \u2192 E} {a b : \ud835\udd5c} {s : set \ud835\udd5c}\n\nlemma dslope_of_ne (f : \ud835\udd5c \u2192 E) (h : b \u2260 a) : dslope f a b = slope f a b :=\nupdate_noteq h _ _\n\nlemma eq_on_dslope_slope (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : eq_on (dslope f a) (slope f a) {a}\u1d9c :=\n\u03bb b, dslope_of_ne f\n\nlemma dslope_eventually_eq_slope_of_ne (f : \ud835\udd5c \u2192 E) (h : b \u2260 a) : dslope f a =\u1da0[\ud835\udcdd b] slope f a :=\n(eq_on_dslope_slope f a).eventually_eq_of_mem (is_open_ne.mem_nhds h)\n\nlemma dslope_eventually_eq_slope_punctured_nhds (f : \ud835\udd5c \u2192 E) : dslope f a =\u1da0[\ud835\udcdd[\u2260] a] slope f a :=\n(eq_on_dslope_slope f a).eventually_eq_of_mem self_mem_nhds_within\n\n@[simp] lemma sub_smul_dslope (f : \ud835\udd5c \u2192 E) (a b : \ud835\udd5c) : (b - a) \u2022 dslope f a b = f b - f a :=\nby rcases eq_or_ne b a with rfl | hne; simp [dslope_of_ne, *]\n\nlemma dslope_sub_smul_of_ne (f : \ud835\udd5c \u2192 E) (h : b \u2260 a) : dslope (\u03bb x, (x - a) \u2022 f x) a b = f b :=\nby rw [dslope_of_ne _ h, slope_sub_smul _ h.symm]\n\nlemma eq_on_dslope_sub_smul (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : eq_on (dslope (\u03bb x, (x - a) \u2022 f x) a) f {a}\u1d9c :=\n\u03bb b, dslope_sub_smul_of_ne f\n\nlemma dslope_sub_smul [decidable_eq \ud835\udd5c] (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) :\n  dslope (\u03bb x, (x - a) \u2022 f x) a = update f a (deriv (\u03bb x, (x - a) \u2022 f x) a) :=\neq_update_iff.2 \u27e8dslope_same _ _, eq_on_dslope_sub_smul f a\u27e9\n\n@[simp] lemma continuous_at_dslope_same : continuous_at (dslope f a) a \u2194 differentiable_at \ud835\udd5c f a :=\nby simp only [dslope, continuous_at_update_same, \u2190 has_deriv_at_deriv_iff,\n  has_deriv_at_iff_tendsto_slope]\n\nlemma continuous_within_at.of_dslope (h : continuous_within_at (dslope f a) s b) :\n  continuous_within_at f s b :=\nhave continuous_within_at (\u03bb x, (x - a) \u2022 dslope f a x + f a) s b,\n  from ((continuous_within_at_id.sub continuous_within_at_const).smul h).add\n    continuous_within_at_const,\nby simpa only [sub_smul_dslope, sub_add_cancel] using this\n\nlemma continuous_at.of_dslope (h : continuous_at (dslope f a) b) : continuous_at f b :=\n(continuous_within_at_univ _ _).1 h.continuous_within_at.of_dslope\n\nlemma continuous_on.of_dslope (h : continuous_on (dslope f a) s) : continuous_on f s :=\n\u03bb x hx, (h x hx).of_dslope\n\nlemma continuous_within_at_dslope_of_ne (h : b \u2260 a) :\n  continuous_within_at (dslope f a) s b \u2194 continuous_within_at f s b :=\nbegin\n  refine \u27e8continuous_within_at.of_dslope, \u03bb hc, _\u27e9,\n  simp only [dslope, continuous_within_at_update_of_ne h],\n  exact ((continuous_within_at_id.sub continuous_within_at_const).inv\u2080\n      (sub_ne_zero.2 h)).smul (hc.sub continuous_within_at_const)\nend\n\nlemma continuous_at_dslope_of_ne (h : b \u2260 a) : continuous_at (dslope f a) b \u2194 continuous_at f b :=\nby simp only [\u2190 continuous_within_at_univ, continuous_within_at_dslope_of_ne h]\n\nlemma continuous_on_dslope (h : s \u2208 \ud835\udcdd a) :\n  continuous_on (dslope f a) s \u2194 continuous_on f s \u2227 differentiable_at \ud835\udd5c f a :=\nbegin\n  refine \u27e8\u03bb hc, \u27e8hc.of_dslope, continuous_at_dslope_same.1 $ hc.continuous_at h\u27e9, _\u27e9,\n  rintro \u27e8hc, hd\u27e9 x hx,\n  rcases eq_or_ne x a with rfl | hne,\n  exacts [(continuous_at_dslope_same.2 hd).continuous_within_at,\n    (continuous_within_at_dslope_of_ne hne).2 (hc x hx)]\nend\n\nlemma differentiable_within_at.of_dslope (h : differentiable_within_at \ud835\udd5c (dslope f a) s b) :\n  differentiable_within_at \ud835\udd5c f s b :=\nby simpa only [id, sub_smul_dslope f a, sub_add_cancel]\n  using ((differentiable_within_at_id.sub_const a).smul h).add_const (f a)\n\nlemma differentiable_at.of_dslope (h : differentiable_at \ud835\udd5c (dslope f a) b) :\n  differentiable_at \ud835\udd5c f b :=\ndifferentiable_within_at_univ.1 h.differentiable_within_at.of_dslope\n\nlemma differentiable_on.of_dslope (h : differentiable_on \ud835\udd5c (dslope f a) s) :\n  differentiable_on \ud835\udd5c f s :=\n\u03bb x hx, (h x hx).of_dslope\n\nlemma differentiable_within_at_dslope_of_ne (h : b \u2260 a) :\n  differentiable_within_at \ud835\udd5c (dslope f a) s b \u2194 differentiable_within_at \ud835\udd5c f s b :=\nbegin\n  refine \u27e8differentiable_within_at.of_dslope, \u03bb hd, _\u27e9,\n  refine (((differentiable_within_at_id.sub_const a).inv\n    (sub_ne_zero.2 h)).smul (hd.sub_const (f a))).congr_of_eventually_eq _ (dslope_of_ne _ h),\n  refine (eq_on_dslope_slope _ _).eventually_eq_of_mem _,\n  exact mem_nhds_within_of_mem_nhds (is_open_ne.mem_nhds h)\nend\n\nlemma differentiable_on_dslope_of_nmem (h : a \u2209 s) :\n  differentiable_on \ud835\udd5c (dslope f a) s \u2194 differentiable_on \ud835\udd5c f s :=\nforall_congr $ \u03bb x, forall_congr $ \u03bb hx, differentiable_within_at_dslope_of_ne $\n  ne_of_mem_of_not_mem hx h\n\nlemma differentiable_at_dslope_of_ne (h : b \u2260 a) :\n  differentiable_at \ud835\udd5c (dslope f a) b \u2194 differentiable_at \ud835\udd5c f b :=\nby simp only [\u2190 differentiable_within_at_univ,\n  differentiable_within_at_dslope_of_ne h]\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/calculus/dslope.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7273745689090627}}
{"text": "-- Estudante: Lucas Emanuel Resck Domingues\n\nopen set\n\nvariable U : Type\nvariables A B : set U\n\nlemma eq_of_subset_of_subset {U : Type} {A B : set U} (h1 : A \u2286 B) (h2 : B \u2286 A): A = B := sorry \n\nlemma first {U : Type} {A B : set U}: powerset (A \u2229 B) \u2286 powerset A \u2229 powerset B :=\n    assume X,\n    show X \u2208 powerset (A \u2229 B) \u2192 X \u2208 powerset A \u2229 powerset B, from\n        assume h1 : X \u2208 powerset (A \u2229 B),\n            have h2 : \u2200 x, x \u2208 X \u2192 x \u2208 A \u2229 B, from h1,\n            have h3 : \u2200 x, x \u2208 X \u2192 x \u2208 A, from\n                (assume x,\n                    assume h4 : x \u2208 X,\n                    show x \u2208 A, from (h2 x h4).left),\n            have h4 : X \u2208 powerset A, from h3,\n            have h5 : \u2200 x, x \u2208 X \u2192 x \u2208 B, from\n                (assume x,\n                    assume h6 : x \u2208 X,\n                    show x \u2208 B, from (h2 x h6).right),\n            have h6 : X \u2208 powerset B, from h5,\n        show X \u2208 powerset A \u2229 powerset B, from and.intro h4 h6\n\nlemma second {U : Type} {A B : set U}: powerset A \u2229 powerset B \u2286 powerset (A \u2229 B) :=\n    assume X,\n        assume h1 : X \u2208 powerset A \u2229 powerset B,\n            have h2 : \u2200 x, x \u2208 X \u2192 x \u2208 A, from h1.left,\n            have h3 : \u2200 x, x \u2208 X \u2192 x \u2208 B, from h1.right,\n            have h4 : \u2200 x, x \u2208 X \u2192 x \u2208 A \u2229 B, from\n                (assume x,\n                    assume h5 : x \u2208 X,\n                        have h6 : x \u2208 A, from h2 x h5,\n                        have h7 : x \u2208 B, from h3 x h5,\n                    show x \u2208 A \u2229 B, from and.intro h6 h7),\n        show X \u2208 powerset (A \u2229 B), from h4\n\ntheorem exercise : powerset (A \u2229 B) = powerset A \u2229 powerset B :=\n    eq_of_subset_of_subset\n        first\n        second\n", "meta": {"author": "lucasresck", "repo": "Discrete-Mathematics", "sha": "0a08081c5f393e5765259d3f1253c3a6dd043dac", "save_path": "github-repos/lean/lucasresck-Discrete-Mathematics", "path": "github-repos/lean/lucasresck-Discrete-Mathematics/Discrete-Mathematics-0a08081c5f393e5765259d3f1253c3a6dd043dac/Lists of exercises/List 6/Lista6-LucasDomingues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.727374562795175}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Benjamin Davidson\n-/\nimport analysis.special_functions.integrals\n/-!\n# Pi\n\nThis file contains lemmas which establish bounds on or approximations of `real.pi`. Notably, these\ninclude `pi_gt_sqrt_two_add_series` and `pi_lt_sqrt_two_add_series`, which bound `\u03c0` using series;\nnumerical bounds on `\u03c0` such as `pi_gt_314`and `pi_lt_315` (more precise versions are given, too);\nand exact (infinite) formulas involving `\u03c0`, such as `tendsto_sum_pi_div_four`, Leibniz's\nseries for `\u03c0`, and `tendsto_prod_pi_div_two`, the Wallis product for `\u03c0`.\n-/\n\nopen_locale real\nnamespace real\n\nlemma pi_gt_sqrt_two_add_series (n : \u2115) : 2 ^ (n+1) * sqrt (2 - sqrt_two_add_series 0 n) < \u03c0 :=\nbegin\n  have : sqrt (2 - sqrt_two_add_series 0 n) / 2 * 2 ^ (n+2) < \u03c0,\n  { rw [\u2190 lt_div_iff, \u2190sin_pi_over_two_pow_succ], apply sin_lt, apply div_pos pi_pos,\n    all_goals { apply pow_pos, norm_num } },\n  apply lt_of_le_of_lt (le_of_eq _) this,\n  rw [pow_succ _ (n+1), \u2190mul_assoc, div_mul_cancel, mul_comm], norm_num\nend\n\nlemma pi_lt_sqrt_two_add_series (n : \u2115) :\n  \u03c0 < 2 ^ (n+1) * sqrt (2 - sqrt_two_add_series 0 n) + 1 / 4 ^ n :=\nbegin\n  have : \u03c0 < (sqrt (2 - sqrt_two_add_series 0 n) / 2 + 1 / (2 ^ n) ^ 3 / 4) * 2 ^ (n+2),\n  { rw [\u2190 div_lt_iff, \u2190 sin_pi_over_two_pow_succ],\n    refine lt_of_lt_of_le (lt_add_of_sub_right_lt (sin_gt_sub_cube _ _)) _,\n    { apply div_pos pi_pos, apply pow_pos, norm_num },\n    { rw div_le_iff',\n      { refine le_trans pi_le_four _,\n        simp only [show ((4 : \u211d) = 2 ^ 2), by norm_num, mul_one],\n        apply pow_le_pow, norm_num, apply le_add_of_nonneg_left, apply nat.zero_le },\n        { apply pow_pos, norm_num }},\n    apply add_le_add_left, rw div_le_div_right,\n    rw [le_div_iff, \u2190mul_pow],\n    refine le_trans _ (le_of_eq (one_pow 3)), apply pow_le_pow_of_le_left,\n    { apply le_of_lt, apply mul_pos, apply div_pos pi_pos, apply pow_pos, norm_num, apply pow_pos,\n      norm_num },\n    rw \u2190 le_div_iff,\n    refine le_trans ((div_le_div_right _).mpr pi_le_four) _, apply pow_pos, norm_num,\n    rw [pow_succ, pow_succ, \u2190mul_assoc, \u2190div_div_eq_div_mul],\n    convert le_refl _,\n    all_goals { repeat {apply pow_pos}, norm_num }},\n  apply lt_of_lt_of_le this (le_of_eq _), rw [add_mul], congr' 1,\n  { rw [pow_succ _ (n+1), \u2190mul_assoc, div_mul_cancel, mul_comm], norm_num },\n  rw [pow_succ, \u2190pow_mul, mul_comm n 2, pow_mul, show (2 : \u211d) ^ 2 = 4, by norm_num, pow_succ,\n      pow_succ, \u2190mul_assoc (2 : \u211d), show (2 : \u211d) * 2 = 4, by norm_num, \u2190mul_assoc, div_mul_cancel,\n      mul_comm ((2 : \u211d) ^ n), \u2190div_div_eq_div_mul, div_mul_cancel],\n  apply pow_ne_zero, norm_num, norm_num\nend\n\n/-- From an upper bound on `sqrt_two_add_series 0 n = 2 cos (\u03c0 / 2 ^ (n+1))` of the form\n`sqrt_two_add_series 0 n \u2264 2 - (a / 2 ^ (n + 1)) ^ 2)`, one can deduce the lower bound `a < \u03c0`\nthanks to basic trigonometric inequalities as expressed in `pi_gt_sqrt_two_add_series`. -/\ntheorem pi_lower_bound_start (n : \u2115) {a}\n  (h : sqrt_two_add_series ((0:\u2115) / (1:\u2115)) n \u2264 2 - (a / 2 ^ (n + 1)) ^ 2) : a < \u03c0 :=\nbegin\n  refine lt_of_le_of_lt _ (pi_gt_sqrt_two_add_series n), rw [mul_comm],\n  refine (div_le_iff (pow_pos (by norm_num) _ : (0 : \u211d) < _)).mp (le_sqrt_of_sq_le _),\n  rwa [le_sub, show (0:\u211d) = (0:\u2115)/(1:\u2115), by rw [nat.cast_zero, zero_div]],\nend\n\nlemma sqrt_two_add_series_step_up (c d : \u2115) {a b n : \u2115} {z : \u211d}\n  (hz : sqrt_two_add_series (c/d) n \u2264 z) (hb : 0 < b) (hd : 0 < d)\n  (h : (2 * b + a) * d ^ 2 \u2264 c ^ 2 * b) : sqrt_two_add_series (a/b) (n+1) \u2264 z :=\nbegin\n  refine le_trans _ hz, rw sqrt_two_add_series_succ, apply sqrt_two_add_series_monotone_left,\n  have hb' : 0 < (b:\u211d) := nat.cast_pos.2 hb,\n  have hd' : 0 < (d:\u211d) := nat.cast_pos.2 hd,\n  rw [sqrt_le_left (div_nonneg c.cast_nonneg d.cast_nonneg), div_pow,\n    add_div_eq_mul_add_div _ _ (ne_of_gt hb'), div_le_div_iff hb' (pow_pos hd' _)],\n  exact_mod_cast h\nend\n\n/-- Create a proof of `a < \u03c0` for a fixed rational number `a`, given a witness, which is a\nsequence of rational numbers `sqrt 2 < r 1 < r 2 < ... < r n < 2` satisfying the property that\n`sqrt (2 + r i) \u2264 r(i+1)`, where `r 0 = 0` and `sqrt (2 - r n) \u2265 a/2^(n+1)`. -/\nmeta def pi_lower_bound (l : list \u211a) : tactic unit :=\ndo let n := l.length,\n  tactic.apply `(@pi_lower_bound_start %%(reflect n)),\n  l.mmap' (\u03bb r, do\n    let a := r.num.to_nat, let b := r.denom,\n    (() <$ tactic.apply `(@sqrt_two_add_series_step_up %%(reflect a) %%(reflect b)));\n    [tactic.skip, `[norm_num1], `[norm_num1], `[norm_num1]]),\n  `[simp only [sqrt_two_add_series, nat.cast_bit0, nat.cast_bit1, nat.cast_one, nat.cast_zero]],\n  `[norm_num1]\n\n/-- From a lower bound on `sqrt_two_add_series 0 n = 2 cos (\u03c0 / 2 ^ (n+1))` of the form\n`2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 \u2264 sqrt_two_add_series 0 n`, one can deduce the upper bound\n`\u03c0 < a` thanks to basic trigonometric formulas as expressed in `pi_lt_sqrt_two_add_series`. -/\ntheorem pi_upper_bound_start (n : \u2115) {a}\n  (h : 2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 \u2264 sqrt_two_add_series ((0:\u2115) / (1:\u2115)) n)\n  (h\u2082 : 1 / 4 ^ n \u2264 a) : \u03c0 < a :=\nbegin\n  refine lt_of_lt_of_le (pi_lt_sqrt_two_add_series n) _,\n  rw [\u2190 le_sub_iff_add_le, \u2190 le_div_iff', sqrt_le_left, sub_le],\n  { rwa [nat.cast_zero, zero_div] at h },\n  { exact div_nonneg (sub_nonneg.2 h\u2082) (pow_nonneg (le_of_lt zero_lt_two) _) },\n  { exact pow_pos zero_lt_two _ }\nend\n\nlemma sqrt_two_add_series_step_down (a b : \u2115) {c d n : \u2115} {z : \u211d}\n  (hz : z \u2264 sqrt_two_add_series (a/b) n) (hb : 0 < b) (hd : 0 < d)\n  (h : a ^ 2 * d \u2264 (2 * d + c) * b ^ 2) : z \u2264 sqrt_two_add_series (c/d) (n+1) :=\nbegin\n  apply le_trans hz, rw sqrt_two_add_series_succ, apply sqrt_two_add_series_monotone_left,\n  apply le_sqrt_of_sq_le,\n  have hb' : 0 < (b:\u211d) := nat.cast_pos.2 hb,\n  have hd' : 0 < (d:\u211d) := nat.cast_pos.2 hd,\n  rw [div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hd'), div_le_div_iff (pow_pos hb' _) hd'],\n  exact_mod_cast h\nend\n\n/-- Create a proof of `\u03c0 < a` for a fixed rational number `a`, given a witness, which is a\nsequence of rational numbers `sqrt 2 < r 1 < r 2 < ... < r n < 2` satisfying the property that\n`sqrt (2 + r i) \u2265 r(i+1)`, where `r 0 = 0` and `sqrt (2 - r n) \u2265 (a - 1/4^n) / 2^(n+1)`. -/\nmeta def pi_upper_bound (l : list \u211a) : tactic unit :=\ndo let n := l.length,\n  (() <$ tactic.apply `(@pi_upper_bound_start %%(reflect n))); [pure (), `[norm_num1]],\n  l.mmap' (\u03bb r, do\n    let a := r.num.to_nat, let b := r.denom,\n    (() <$ tactic.apply `(@sqrt_two_add_series_step_down %%(reflect a) %%(reflect b)));\n    [pure (), `[norm_num1], `[norm_num1], `[norm_num1]]),\n  `[simp only [sqrt_two_add_series, nat.cast_bit0, nat.cast_bit1, nat.cast_one, nat.cast_zero]],\n  `[norm_num]\n\nlemma pi_gt_three : 3 < \u03c0 := by pi_lower_bound [23/16]\n\nlemma pi_gt_314 : 3.14 < \u03c0 := by pi_lower_bound [99/70, 874/473, 1940/989, 1447/727]\n\nlemma pi_lt_315 : \u03c0 < 3.15 := by pi_upper_bound [140/99, 279/151, 51/26, 412/207]\n\nlemma pi_gt_31415 : 3.1415 < \u03c0 := by pi_lower_bound [\n  11482/8119, 5401/2923, 2348/1197, 11367/5711, 25705/12868, 23235/11621]\n\nlemma pi_lt_31416 : \u03c0 < 3.1416 := by pi_upper_bound [\n  4756/3363, 101211/54775, 505534/257719, 83289/41846,\n  411278/205887, 438142/219137, 451504/225769, 265603/132804, 849938/424971]\n\nlemma pi_gt_3141592 : 3.141592 < \u03c0 := by pi_lower_bound [\n  11482/8119, 7792/4217, 54055/27557, 949247/476920, 3310126/1657059,\n  2635492/1318143, 1580265/790192, 1221775/610899, 3612247/1806132, 849943/424972]\n\nlemma pi_lt_3141593 : \u03c0 < 3.141593 := by pi_upper_bound [\n  27720/19601, 56935/30813, 49359/25163, 258754/130003, 113599/56868, 1101994/551163,\n  8671537/4336095, 3877807/1938940, 52483813/26242030, 56946167/28473117, 23798415/11899211]\n\n\n/-! ### Leibniz's Series for Pi -/\n\nopen filter set\nopen_locale classical big_operators topological_space\nlocal notation `|`x`|` := abs x\n\n/-- This theorem establishes Leibniz's series for `\u03c0`: The alternating sum of the reciprocals of the\n  odd numbers is `\u03c0/4`. Note that this is a conditionally rather than absolutely convergent series.\n  The main tool that this proof uses is the Mean Value Theorem (specifically avoiding the\n  Fundamental Theorem of Calculus).\n\n  Intuitively, the theorem holds because Leibniz's series is the Taylor series of `arctan x`\n  centered about `0` and evaluated at the value `x = 1`. Therefore, much of this proof consists of\n  reasoning about a function\n    `f := arctan x - \u2211 i in finset.range k, (-(1:\u211d))^i * x^(2*i+1) / (2*i+1)`,\n  the difference between `arctan` and the `k`-th partial sum of its Taylor series. Some ingenuity is\n  required due to the fact that the Taylor series is not absolutely convergent at `x = 1`.\n\n  This proof requires a bound on `f 1`, the key idea being that `f 1` can be split as the sum of\n  `f 1 - f u` and `f u`, where `u` is a sequence of values in [0,1], carefully chosen such that\n  each of these two terms can be controlled (in different ways).\n\n  We begin the proof by (1) introducing that sequence `u` and then proving that another sequence\n  constructed from `u` tends to `0` at `+\u221e`. After (2) converting the limit in our goal to an\n  inequality, we (3) introduce the auxiliary function `f` defined above. Next, we (4) compute the\n  derivative of `f`, denoted by `f'`, first generally and then on each of two subintervals of [0,1].\n  We then (5) prove a bound for `f'`, again both generally as well as on each of the two\n  subintervals. Finally, we (6) apply the Mean Value Theorem twice, obtaining bounds on `f 1 - f u`\n  and `f u - f 0` from the bounds on `f'` (note that `f 0 = 0`). -/\ntheorem tendsto_sum_pi_div_four :\n  tendsto (\u03bb k, \u2211 i in finset.range k, ((-(1:\u211d))^i / (2*i+1))) at_top (\ud835\udcdd (\u03c0/4)) :=\nbegin\n  rw [tendsto_iff_norm_tendsto_zero, \u2190 tendsto_zero_iff_norm_tendsto_zero],\n  -- (1) We introduce a useful sequence `u` of values in [0,1], then prove that another sequence\n  --     constructed from `u` tends to `0` at `+\u221e`\n  let u := \u03bb k : \u2115, (k:nnreal) ^ (-1 / (2 * (k:\u211d) + 1)),\n  have H : tendsto (\u03bb k : \u2115, (1:\u211d) - (u k) + (u k) ^ (2 * (k:\u211d) + 1)) at_top (\ud835\udcdd 0),\n  { convert (((tendsto_rpow_div_mul_add (-1) 2 1 $ by norm_num).neg.const_add 1).add\n      tendsto_inv_at_top_zero).comp tendsto_coe_nat_at_top_at_top,\n    { ext k,\n      simp only [nnreal.coe_nat_cast, function.comp_app, nnreal.coe_rpow],\n      rw [\u2190 rpow_mul (nat.cast_nonneg k) ((-1)/(2*(k:\u211d)+1)) (2*(k:\u211d)+1),\n          @div_mul_cancel _ _ _ (2*(k:\u211d)+1) (by { norm_cast, linarith }), rpow_neg_one k],\n      ring },\n    { simp } },\n  -- (2) We convert the limit in our goal to an inequality\n  refine squeeze_zero_norm _ H,\n  intro k,\n  -- Since `k` is now fixed, we henceforth denote `u k` as `U`\n  let U := u k,\n  -- (3) We introduce an auxiliary function `f`\n  let b := \u03bb (i:\u2115) x, (-(1:\u211d))^i * x^(2*i+1) / (2*i+1),\n  let f := \u03bb x, arctan x - (\u2211 i in finset.range k, b i x),\n  suffices f_bound : |f 1 - f 0| \u2264 (1:\u211d) - U + U ^ (2 * (k:\u211d) + 1),\n  { rw \u2190 norm_neg,\n    convert f_bound,\n    simp only [f], simp [b] },\n  -- We show that `U` is indeed in [0,1]\n  have hU1 : (U:\u211d) \u2264 1,\n  { by_cases hk : k = 0,\n    { simpa only [U, hk] using zero_rpow_le_one _ },\n    { exact rpow_le_one_of_one_le_of_nonpos (by { norm_cast, exact nat.succ_le_iff.mpr\n        (nat.pos_of_ne_zero hk) }) (le_of_lt (@div_neg_of_neg_of_pos _ _ (-(1:\u211d)) (2*k+1)\n          (by norm_num) (by { norm_cast, linarith }))) } },\n  have hU2 := nnreal.coe_nonneg U,\n  -- (4) We compute the derivative of `f`, denoted by `f'`\n  let f' := \u03bb x : \u211d, (-x^2) ^ k / (1 + x^2),\n  have has_deriv_at_f : \u2200 x, has_deriv_at f (f' x) x,\n  { intro x,\n    have has_deriv_at_b : \u2200 i \u2208 finset.range k, (has_deriv_at (b i) ((-x^2)^i) x),\n    { intros i hi,\n      convert has_deriv_at.const_mul ((-1:\u211d)^i / (2*i+1)) (@has_deriv_at.pow _ _ _ _ _ (2*i+1)\n        (has_deriv_at_id x)),\n      { ext y,\n        simp only [b, id.def],\n        ring },\n      { simp only [nat.add_succ_sub_one, add_zero, mul_one, id.def, nat.cast_bit0, nat.cast_add,\n                  nat.cast_one, nat.cast_mul],\n        rw [\u2190 mul_assoc, @div_mul_cancel _ _ _ (2*(i:\u211d)+1) (by { norm_cast, linarith }),\n            pow_mul x 2 i, \u2190 mul_pow (-1) (x^2) i],\n        ring_nf } },\n    convert (has_deriv_at_arctan x).sub (has_deriv_at.sum has_deriv_at_b),\n    have g_sum := @geom_sum_eq _ _ (-x^2) (by linarith [neg_nonpos.mpr (sq_nonneg x)]) k,\n    simp only [geom_sum, f'] at g_sum \u22a2,\n    rw [g_sum, \u2190 neg_add' (x^2) 1, add_comm (x^2) 1, sub_eq_add_neg, neg_div', neg_div_neg_eq],\n    ring },\n  have hderiv1 : \u2200 x \u2208 Icc (U:\u211d) 1, has_deriv_within_at f (f' x) (Icc (U:\u211d) 1) x :=\n    \u03bb x hx, (has_deriv_at_f x).has_deriv_within_at,\n  have hderiv2 : \u2200 x \u2208 Icc 0 (U:\u211d), has_deriv_within_at f (f' x) (Icc 0 (U:\u211d)) x :=\n    \u03bb x hx, (has_deriv_at_f x).has_deriv_within_at,\n  -- (5) We prove a general bound for `f'` and then more precise bounds on each of two subintervals\n  have f'_bound : \u2200 x \u2208 Icc (-1:\u211d) 1, |f' x| \u2264 |x|^(2*k),\n  { intros x hx,\n    rw [abs_div, is_absolute_value.abv_pow abs (-x^2) k, abs_neg, is_absolute_value.abv_pow abs x 2,\n        tactic.ring_exp.pow_e_pf_exp rfl rfl, @abs_of_pos _ _ (1+x^2) (by nlinarith)],\n    convert @div_le_div_of_le_left _ _ _ (1+x^2) 1 (pow_nonneg (abs_nonneg x) (2*k)) (by norm_num)\n      (by nlinarith),\n    simp },\n  have hbound1 : \u2200 x \u2208 Ico (U:\u211d) 1, |f' x| \u2264 1,\n  { rintros x \u27e8hx_left, hx_right\u27e9,\n    have hincr := pow_le_pow_of_le_left (le_trans hU2 hx_left) (le_of_lt hx_right) (2*k),\n    rw [one_pow (2*k), \u2190 abs_of_nonneg (le_trans hU2 hx_left)] at hincr,\n    rw \u2190 abs_of_nonneg (le_trans hU2 hx_left) at hx_right,\n    linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_of_lt hx_right)))] },\n  have hbound2 : \u2200 x \u2208 Ico 0 (U:\u211d), |f' x| \u2264 U ^ (2*k),\n  { rintros x \u27e8hx_left, hx_right\u27e9,\n    have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2*k),\n    rw \u2190 abs_of_nonneg hx_left at hincr hx_right,\n    rw \u2190 abs_of_nonneg hU2 at hU1 hx_right,\n    linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_trans (le_of_lt hx_right) hU1)))] },\n  -- (6) We twice apply the Mean Value Theorem to obtain bounds on `f` from the bounds on `f'`\n  have mvt1 :=\n    norm_image_sub_le_of_norm_deriv_le_segment' hderiv1 hbound1 _ (right_mem_Icc.mpr hU1),\n  have mvt2 :=\n    norm_image_sub_le_of_norm_deriv_le_segment' hderiv2 hbound2 _ (right_mem_Icc.mpr hU2),\n  -- The following algebra is enough to complete the proof\n  calc |f 1 - f 0| = |(f 1 - f U) + (f U - f 0)| : by ring_nf\n               ... \u2264 1 * (1-U) + U^(2*k) * (U - 0) : le_trans (abs_add (f 1 - f U) (f U - f 0))\n                                                      (add_le_add mvt1 mvt2)\n               ... = 1 - U + U^(2*k) * U : by ring\n               ... = 1 - (u k) + (u k)^(2*(k:\u211d)+1) : by { rw [\u2190 pow_succ' (U:\u211d) (2*k)], norm_cast },\nend\n\n/-! ### The Wallis Product for Pi -/\n\nopen finset interval_integral\n\nlemma integral_sin_pow_div_tendsto_one :\n  tendsto (\u03bb k, (\u222b x in 0..\u03c0, sin x ^ (2 * k + 1)) / \u222b x in 0..\u03c0, sin x ^ (2 * k)) at_top (\ud835\udcdd 1) :=\nbegin\n  have h\u2083 : \u2200 n, (\u222b x in 0..\u03c0, sin x ^ (2 * n + 1)) / \u222b x in 0..\u03c0, sin x ^ (2 * n) \u2264 1 :=\n    \u03bb n, (div_le_one (integral_sin_pow_pos _)).mpr (integral_sin_pow_antimono _),\n  have h\u2084 :\n    \u2200 n, (\u222b x in 0..\u03c0, sin x ^ (2 * n + 1)) / \u222b x in 0..\u03c0, sin x ^ (2 * n) \u2265 2 * n / (2 * n + 1),\n  { rintro \u27e8n\u27e9,\n    { have : 0 \u2264 (1 + 1) / \u03c0, exact div_nonneg (by norm_num) pi_pos.le,\n      simp [this] },\n    calc (\u222b x in 0..\u03c0, sin x ^ (2 * n.succ + 1)) / \u222b x in 0..\u03c0, sin x ^ (2 * n.succ) \u2265\n      (\u222b x in 0..\u03c0, sin x ^ (2 * n.succ + 1)) / \u222b x in 0..\u03c0, sin x ^ (2 * n + 1) :\n      by { refine div_le_div (integral_sin_pow_pos _).le (le_refl _) (integral_sin_pow_pos _) _,\n        convert integral_sin_pow_antimono (2 * n + 1) using 1 }\n    ... = 2 * \u2191(n.succ) / (2 * \u2191(n.succ) + 1) :\n      by { rw div_eq_iff (integral_sin_pow_pos (2 * n + 1)).ne',\n           convert integral_sin_pow (2 * n + 1), simp with field_simps, norm_cast } },\n  refine tendsto_of_tendsto_of_tendsto_of_le_of_le _ _ (\u03bb n, (h\u2084 n).le) (\u03bb n, (h\u2083 n)),\n  { refine metric.tendsto_at_top.mpr (\u03bb \u03b5 h\u03b5, \u27e8nat_ceil (1 / \u03b5), \u03bb n hn, _\u27e9),\n    have h : (2:\u211d) * n / (2 * n + 1) - 1 = -1 / (2 * n + 1),\n    { conv_lhs { congr, skip, rw \u2190 @div_self _ _ ((2:\u211d) * n + 1) (by { norm_cast, linarith }), },\n      rw [\u2190 sub_div, \u2190 sub_sub, sub_self, zero_sub] },\n    have hpos : (0:\u211d) < 2 * n + 1, { norm_cast, norm_num },\n    rw [dist_eq, h, abs_div, abs_neg, abs_one, abs_of_pos hpos, one_div_lt hpos h\u03b5],\n    calc 1 / \u03b5 \u2264 nat_ceil (1 / \u03b5) : le_nat_ceil _\n          ... \u2264 n : by exact_mod_cast hn.le\n          ... < 2 * n + 1 : by { norm_cast, linarith } },\n  { exact tendsto_const_nhds },\nend\n\n/-- This theorem establishes the Wallis Product for `\u03c0`. Our proof is largely about analyzing\n  the behavior of the ratio of the integral of `sin x ^ n` as `n \u2192 \u221e`.\n  See: https://en.wikipedia.org/wiki/Wallis_product\n\n  The proof can be broken down into two pieces.\n  (Pieces involving general properties of the integral of `sin x ^n` can be found\n  in `analysis.special_functions.integrals`.) First, we use integration by parts to obtain a\n  recursive formula for `\u222b x in 0..\u03c0, sin x ^ (n + 2)` in terms of `\u222b x in 0..\u03c0, sin x ^ n`.\n  From this we can obtain closed form products of `\u222b x in 0..\u03c0, sin x ^ (2 * n)` and\n  `\u222b x in 0..\u03c0, sin x ^ (2 * n + 1)` via induction. Next, we study the behavior of the ratio\n  `\u222b (x : \u211d) in 0..\u03c0, sin x ^ (2 * k + 1)) / \u222b (x : \u211d) in 0..\u03c0, sin x ^ (2 * k)` and prove that\n  it converges to one using the squeeze theorem. The final product for `\u03c0` is obtained after some\n  algebraic manipulation. -/\ntheorem tendsto_prod_pi_div_two :\n  tendsto (\u03bb k, \u220f i in range k,\n    (((2:\u211d) * i + 2) / (2 * i + 1)) * ((2 * i + 2) / (2 * i + 3))) at_top (\ud835\udcdd (\u03c0/2)) :=\nbegin\n  suffices h : tendsto (\u03bb k, 2 / \u03c0  * \u220f i in range k,\n    (((2:\u211d) * i + 2) / (2 * i + 1)) * ((2 * i + 2) / (2 * i + 3))) at_top (\ud835\udcdd 1),\n  { have := tendsto.const_mul (\u03c0 / 2) h,\n    have h : \u03c0 / 2 \u2260 0, norm_num [pi_ne_zero],\n    simp only [\u2190 mul_assoc, \u2190 @inv_div _ _ \u03c0 2, mul_inv_cancel h, one_mul, mul_one] at this,\n    exact this },\n  have h : (\u03bb (k : \u2115), (2:\u211d) / \u03c0 * \u220f (i : \u2115) in range k,\n    ((2 * i + 2) / (2 * i + 1)) * ((2 * i + 2) / (2 * i + 3))) =\n  \u03bb k, (2 * \u220f i in range k,\n    (2 * i + 2) / (2 * i + 3)) / (\u03c0 * \u220f (i : \u2115) in range k, (2 * i + 1) / (2 * i + 2)),\n  { funext,\n    have h : \u220f (i : \u2115) in range k, ((2:\u211d) * \u2191i + 2) / (2 * \u2191i + 1) =\n      1 / (\u220f (i : \u2115) in range k, (2 * \u2191i + 1) / (2 * \u2191i + 2)),\n    { rw [one_div, \u2190 finset.prod_inv_distrib'],\n      refine prod_congr rfl (\u03bb x hx, _),\n      field_simp },\n    rw [prod_mul_distrib, h],\n    field_simp },\n  simp only [h, \u2190 integral_sin_pow_even, \u2190 integral_sin_pow_odd],\n  exact integral_sin_pow_div_tendsto_one,\nend\n\nend real\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/real/pi.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7273745609410897}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport algebra.gcd_monoid.multiset\nimport combinatorics.partition\nimport data.list.rotate\nimport group_theory.perm.cycle.basic\nimport ring_theory.int.basic\nimport tactic.linarith\n\n/-!\n# Cycle Types\n\nIn this file we define the cycle type of a permutation.\n\n## Main definitions\n\n- `\u03c3.cycle_type` where `\u03c3` is a permutation of a `fintype`\n- `\u03c3.partition` where `\u03c3` is a permutation of a `fintype`\n\n## Main results\n\n- `sum_cycle_type` : The sum of `\u03c3.cycle_type` equals `\u03c3.support.card`\n- `lcm_cycle_type` : The lcm of `\u03c3.cycle_type` equals `order_of \u03c3`\n- `is_conj_iff_cycle_type_eq` : Two permutations are conjugate if and only if they have the same\n  cycle type.\n- `exists_prime_order_of_dvd_card`: For every prime `p` dividing the order of a finite group `G`\n  there exists an element of order `p` in `G`. This is known as Cauchy's theorem.\n-/\n\nnamespace equiv.perm\nopen equiv list multiset\n\nvariables {\u03b1 : Type*} [fintype \u03b1]\n\nsection cycle_type\n\nvariables [decidable_eq \u03b1]\n\n/-- The cycle type of a permutation -/\ndef cycle_type (\u03c3 : perm \u03b1) : multiset \u2115 :=\n\u03c3.cycle_factors_finset.1.map (finset.card \u2218 support)\n\nlemma cycle_type_def (\u03c3 : perm \u03b1) :\n  \u03c3.cycle_type = \u03c3.cycle_factors_finset.1.map (finset.card \u2218 support) := rfl\n\nlemma cycle_type_eq' {\u03c3 : perm \u03b1} (s : finset (perm \u03b1))\n  (h1 : \u2200 f : perm \u03b1, f \u2208 s \u2192 f.is_cycle) (h2 : (s : set (perm \u03b1)).pairwise disjoint)\n  (h0 : s.noncomm_prod id (h2.imp $ \u03bb _ _, disjoint.commute) = \u03c3) :\n  \u03c3.cycle_type = s.1.map (finset.card \u2218 support) :=\nbegin\n  rw cycle_type_def,\n  congr,\n  rw cycle_factors_finset_eq_finset,\n  exact \u27e8h1, h2, h0\u27e9\nend\n\nlemma cycle_type_eq {\u03c3 : perm \u03b1} (l : list (perm \u03b1)) (h0 : l.prod = \u03c3)\n  (h1 : \u2200 \u03c3 : perm \u03b1, \u03c3 \u2208 l \u2192 \u03c3.is_cycle) (h2 : l.pairwise disjoint) :\n  \u03c3.cycle_type = l.map (finset.card \u2218 support) :=\nbegin\n  have hl : l.nodup := nodup_of_pairwise_disjoint_cycles h1 h2,\n  rw cycle_type_eq' l.to_finset,\n  { simp [list.dedup_eq_self.mpr hl] },\n  { simpa using h1 },\n  { simpa [hl] using h0 },\n  { simpa [list.dedup_eq_self.mpr hl] using h2.forall disjoint.symmetric }\nend\n\nlemma cycle_type_one : (1 : perm \u03b1).cycle_type = 0 :=\ncycle_type_eq [] rfl (\u03bb _, false.elim) pairwise.nil\n\nlemma cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type = 0 \u2194 \u03c3 = 1 :=\nby simp [cycle_type_def, cycle_factors_finset_eq_empty_iff]\n\nlemma card_cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 0 \u2194 \u03c3 = 1 :=\nby rw [card_eq_zero, cycle_type_eq_zero]\n\nlemma two_le_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 2 \u2264 n :=\nbegin\n  simp only [cycle_type_def, \u2190finset.mem_def, function.comp_app, multiset.mem_map,\n    mem_cycle_factors_finset_iff] at h,\n  obtain \u27e8_, \u27e8hc, -\u27e9, rfl\u27e9 := h,\n  exact hc.two_le_card_support\nend\n\nlemma one_lt_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 1 < n :=\ntwo_le_of_mem_cycle_type h\n\nlemma is_cycle.cycle_type {\u03c3 : perm \u03b1} (h\u03c3 : is_cycle \u03c3) : \u03c3.cycle_type = [\u03c3.support.card] :=\ncycle_type_eq [\u03c3] (mul_one \u03c3) (\u03bb \u03c4 h\u03c4, (congr_arg is_cycle (list.mem_singleton.mp h\u03c4)).mpr h\u03c3)\n  (pairwise_singleton disjoint \u03c3)\n\nlemma card_cycle_type_eq_one {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 1 \u2194 \u03c3.is_cycle :=\nbegin\n  rw card_eq_one,\n  simp_rw [cycle_type_def, multiset.map_eq_singleton, \u2190finset.singleton_val,\n           finset.val_inj, cycle_factors_finset_eq_singleton_iff],\n  split,\n  { rintro \u27e8_, _, \u27e8h, -\u27e9, -\u27e9,\n    exact h },\n  { intro h,\n    use [\u03c3.support.card, \u03c3],\n    simp [h] }\nend\n\nlemma disjoint.cycle_type {\u03c3 \u03c4 : perm \u03b1} (h : disjoint \u03c3 \u03c4) :\n  (\u03c3 * \u03c4).cycle_type = \u03c3.cycle_type + \u03c4.cycle_type :=\nbegin\n  rw [cycle_type_def, cycle_type_def, cycle_type_def, h.cycle_factors_finset_mul_eq_union,\n      \u2190multiset.map_add, finset.union_val, multiset.add_eq_union_iff_disjoint.mpr _],\n  exact finset.disjoint_val.2 h.disjoint_cycle_factors_finset\nend\n\nlemma cycle_type_inv (\u03c3 : perm \u03b1) : \u03c3\u207b\u00b9.cycle_type = \u03c3.cycle_type :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4\u207b\u00b9.cycle_type = \u03c4.cycle_type) \u03c3 rfl\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, h\u03c3.inv.cycle_type, support_inv])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [mul_inv_rev, h\u03c3\u03c4.cycle_type, \u2190h\u03c3, \u2190h\u03c4, add_comm,\n    disjoint.cycle_type (\u03bb x, or.imp (\u03bb h : \u03c4 x = x, inv_eq_iff_eq.mpr h.symm)\n    (\u03bb h : \u03c3 x = x, inv_eq_iff_eq.mpr h.symm) (h\u03c3\u03c4 x).symm)])\n\nlemma cycle_type_conj {\u03c3 \u03c4 : perm \u03b1} : (\u03c4 * \u03c3 * \u03c4\u207b\u00b9).cycle_type = \u03c3.cycle_type :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intro,\n    simp },\n  { intros \u03c3 h\u03c3 \u03c4,\n    rw [h\u03c3.cycle_type, h\u03c3.conj.cycle_type, card_support_conj] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4 \u03c0,\n    rw [\u2190 conj_mul, hd.cycle_type, disjoint.cycle_type, h\u03c3, h\u03c4],\n    intro a,\n    apply (hd (\u03c0\u207b\u00b9 a)).imp _ _;\n    { intro h, rw [perm.mul_apply, perm.mul_apply, h, apply_inv_self] } }\nend\n\nlemma sum_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.sum = \u03c3.support.card :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.sum = \u03c4.support.card) \u03c3\n  (by rw [cycle_type_one, sum_zero, support_one, finset.card_empty])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, coe_sum, list.sum_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, sum_add, h\u03c3, h\u03c4, h\u03c3\u03c4.card_support_mul])\n\nlemma sign_of_cycle_type' (\u03c3 : perm \u03b1) :\n  sign \u03c3 = (\u03c3.cycle_type.map (\u03bb n, -(-1 : \u2124\u02e3) ^ n)).prod :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, sign \u03c4 = (\u03c4.cycle_type.map (\u03bb n, -(-1 : \u2124\u02e3) ^ n)).prod) \u03c3\n  (by rw [sign_one, cycle_type_one, multiset.map_zero, prod_zero])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.sign, h\u03c3.cycle_type, coe_map, coe_prod,\n    list.map_singleton, list.prod_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [sign_mul, h\u03c3, h\u03c4, h\u03c3\u03c4.cycle_type, multiset.map_add, prod_add])\n\nlemma sign_of_cycle_type (f : perm \u03b1) :\n  sign f = (-1 : \u2124\u02e3)^(f.cycle_type.sum + f.cycle_type.card) :=\ncycle_induction_on\n  (\u03bb f : perm \u03b1, sign f = (-1 : \u2124\u02e3)^(f.cycle_type.sum + f.cycle_type.card))\n  f\n  ( -- base_one\n    by rw [equiv.perm.cycle_type_one, sign_one, multiset.sum_zero, multiset.card_zero, pow_zero] )\n  ( -- base_cycles\n    \u03bb f hf,\n      by rw [equiv.perm.is_cycle.cycle_type hf, hf.sign,\n      coe_sum, list.sum_cons, sum_nil, add_zero, coe_card, length_singleton,\n      pow_add, pow_one, mul_comm, neg_mul, one_mul] )\n  ( -- induction_disjoint\n    \u03bb f g hfg hf Pf Pg,\n    by rw [equiv.perm.disjoint.cycle_type hfg,\n      multiset.sum_add, multiset.card_add,\u2190 add_assoc,\n      add_comm f.cycle_type.sum g.cycle_type.sum,\n      add_assoc g.cycle_type.sum _ _,\n      add_comm g.cycle_type.sum _,\n      add_assoc, pow_add,\n      \u2190 Pf, \u2190 Pg,\n      equiv.perm.sign_mul])\n\nlemma lcm_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.lcm = order_of \u03c3 :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.lcm = order_of \u03c4) \u03c3\n  (by rw [cycle_type_one, lcm_zero, order_of_one])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, coe_singleton, lcm_singleton, h\u03c3.order_of,\n    normalize_eq])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, lcm_add, lcm_eq_nat_lcm, h\u03c3\u03c4.order_of, h\u03c3, h\u03c4])\n\nlemma dvd_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : n \u2223 order_of \u03c3 :=\nbegin\n  rw \u2190 lcm_cycle_type,\n  exact dvd_lcm h,\nend\n\nlemma order_of_cycle_of_dvd_order_of (f : perm \u03b1) (x : \u03b1) :\n  order_of (cycle_of f x) \u2223 order_of f :=\nbegin\n  by_cases hx : f x = x,\n  { rw \u2190cycle_of_eq_one_iff at hx,\n    simp [hx] },\n  { refine dvd_of_mem_cycle_type _,\n    rw [cycle_type, multiset.mem_map],\n    refine \u27e8f.cycle_of x, _, _\u27e9,\n    { rwa [\u2190finset.mem_def, cycle_of_mem_cycle_factors_finset_iff, mem_support] },\n    { simp [(is_cycle_cycle_of _ hx).order_of] } }\nend\n\nlemma two_dvd_card_support {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ 2 = 1) : 2 \u2223 \u03c3.support.card :=\n(congr_arg (has_dvd.dvd 2) \u03c3.sum_cycle_type).mp\n  (multiset.dvd_sum (\u03bb n hn, by rw le_antisymm (nat.le_of_dvd zero_lt_two $\n  (dvd_of_mem_cycle_type hn).trans $ order_of_dvd_of_pow_eq_one h\u03c3) (two_le_of_mem_cycle_type hn)))\n\nlemma cycle_type_prime_order {\u03c3 : perm \u03b1} (h\u03c3 : (order_of \u03c3).prime) :\n  \u2203 n : \u2115, \u03c3.cycle_type = replicate (n + 1) (order_of \u03c3) :=\nbegin\n  rw eq_replicate_of_mem (\u03bb n hn, or_iff_not_imp_left.mp\n    (h\u03c3.eq_one_or_self_of_dvd n (dvd_of_mem_cycle_type hn)) (one_lt_of_mem_cycle_type hn).ne'),\n  use \u03c3.cycle_type.card - 1,\n  rw tsub_add_cancel_of_le,\n  rw [nat.succ_le_iff, pos_iff_ne_zero, ne, card_cycle_type_eq_zero],\n  intro H,\n  rw [H, order_of_one] at h\u03c3,\n  exact h\u03c3.ne_one rfl,\nend\n\nlemma is_cycle_of_prime_order {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : \u03c3.support.card < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  obtain \u27e8n, hn\u27e9 := cycle_type_prime_order h1,\n  rw [\u2190\u03c3.sum_cycle_type, hn, multiset.sum_replicate, nsmul_eq_mul, nat.cast_id, mul_lt_mul_right\n      (order_of_pos \u03c3), nat.succ_lt_succ_iff, nat.lt_succ_iff, le_zero_iff] at h2,\n  rw [\u2190card_cycle_type_eq_one, hn, card_replicate, h2],\nend\n\nlemma cycle_type_le_of_mem_cycle_factors_finset {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  f.cycle_type \u2264 g.cycle_type :=\nbegin\n  rw mem_cycle_factors_finset_iff at hf,\n  rw [cycle_type_def, cycle_type_def, hf.left.cycle_factors_finset_eq_singleton],\n  refine map_le_map _,\n  simpa [\u2190finset.mem_def, mem_cycle_factors_finset_iff] using hf\nend\n\nlemma cycle_type_mul_mem_cycle_factors_finset_eq_sub {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  (g * f\u207b\u00b9).cycle_type = g.cycle_type - f.cycle_type :=\nbegin\n  suffices : (g * f\u207b\u00b9).cycle_type + f.cycle_type = g.cycle_type - f.cycle_type + f.cycle_type,\n  { rw tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf) at this,\n    simp [\u2190this] },\n  simp [\u2190(disjoint_mul_inv_of_mem_cycle_factors_finset hf).cycle_type,\n    tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf)]\nend\n\ntheorem is_conj_of_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} (h : cycle_type \u03c3 = cycle_type \u03c4) : is_conj \u03c3 \u03c4 :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intros \u03c4 h,\n    rw [cycle_type_one, eq_comm, cycle_type_eq_zero] at h,\n    rw h },\n  { intros \u03c3 h\u03c3 \u03c4 h\u03c3\u03c4,\n    have h\u03c4 := card_cycle_type_eq_one.2 h\u03c3,\n    rw [h\u03c3\u03c4, card_cycle_type_eq_one] at h\u03c4,\n    apply h\u03c3.is_conj h\u03c4,\n    rw [h\u03c3.cycle_type, h\u03c4.cycle_type, coe_eq_coe, singleton_perm] at h\u03c3\u03c4,\n    simp only [and_true, eq_self_iff_true] at h\u03c3\u03c4,\n    exact h\u03c3\u03c4 },\n  { intros \u03c3 \u03c4 h\u03c3\u03c4 h\u03c3 h1 h2 \u03c0 h\u03c0,\n    rw [h\u03c3\u03c4.cycle_type] at h\u03c0,\n    { have h : \u03c3.support.card \u2208 map (finset.card \u2218 perm.support) \u03c0.cycle_factors_finset.val,\n      { simp [\u2190cycle_type_def, \u2190h\u03c0, h\u03c3.cycle_type] },\n      obtain \u27e8\u03c3', h\u03c3'l, h\u03c3'\u27e9 := multiset.mem_map.mp h,\n      have key : is_conj (\u03c3' * (\u03c0 * \u03c3'\u207b\u00b9)) \u03c0,\n      { rw is_conj_iff,\n        use \u03c3'\u207b\u00b9,\n        simp [mul_assoc] },\n      refine is_conj.trans _ key,\n      have hs : \u03c3.cycle_type = \u03c3'.cycle_type,\n      { rw [\u2190finset.mem_def, mem_cycle_factors_finset_iff] at h\u03c3'l,\n        rw [h\u03c3.cycle_type, \u2190h\u03c3', h\u03c3'l.left.cycle_type] },\n      refine h\u03c3\u03c4.is_conj_mul (h1 hs) (h2 _) _,\n      { rw [cycle_type_mul_mem_cycle_factors_finset_eq_sub, \u2190h\u03c0, add_comm, hs,\n            add_tsub_cancel_right],\n        rwa finset.mem_def },\n      { exact (disjoint_mul_inv_of_mem_cycle_factors_finset h\u03c3'l).symm } } }\nend\n\ntheorem is_conj_iff_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.cycle_type = \u03c4.cycle_type :=\n\u27e8\u03bb h, begin\n  obtain \u27e8\u03c0, rfl\u27e9 := is_conj_iff.1 h,\n  rw cycle_type_conj,\nend, is_conj_of_cycle_type_eq\u27e9\n\n@[simp] lemma cycle_type_extend_domain {\u03b2 : Type*} [fintype \u03b2] [decidable_eq \u03b2]\n  {p : \u03b2 \u2192 Prop} [decidable_pred p] (f : \u03b1 \u2243 subtype p) {g : perm \u03b1} :\n  cycle_type (g.extend_domain f) = cycle_type g :=\nbegin\n  apply cycle_induction_on _ g,\n  { rw [extend_domain_one, cycle_type_one, cycle_type_one] },\n  { intros \u03c3 h\u03c3,\n    rw [(h\u03c3.extend_domain f).cycle_type, h\u03c3.cycle_type, card_support_extend_domain] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4,\n    rw [hd.cycle_type, \u2190 extend_domain_mul, (hd.extend_domain f).cycle_type, h\u03c3, h\u03c4] }\nend\n\nlemma cycle_type_of_subtype {p : \u03b1 \u2192 Prop} [decidable_pred p] {g : perm (subtype p)}:\n  cycle_type (g.of_subtype) = cycle_type g := cycle_type_extend_domain (equiv.refl (subtype p))\n\nlemma mem_cycle_type_iff {n : \u2115} {\u03c3 : perm \u03b1} :\n  n \u2208 cycle_type \u03c3 \u2194 \u2203 c \u03c4 : perm \u03b1, \u03c3 = c * \u03c4 \u2227 disjoint c \u03c4 \u2227 is_cycle c \u2227 c.support.card = n :=\nbegin\n  split,\n  { intro h,\n    obtain \u27e8l, rfl, hlc, hld\u27e9 := trunc_cycle_factors \u03c3,\n    rw cycle_type_eq _ rfl hlc hld at h,\n    obtain \u27e8c, cl, rfl\u27e9 := list.exists_of_mem_map h,\n    rw (list.perm_cons_erase cl).pairwise_iff (\u03bb _ _ hd, _) at hld,\n    swap, { exact hd.symm },\n    refine \u27e8c, (l.erase c).prod, _, _, hlc _ cl, rfl\u27e9,\n    { rw [\u2190 list.prod_cons,\n        (list.perm_cons_erase cl).symm.prod_eq' (hld.imp (\u03bb _ _, disjoint.commute))] },\n    { exact disjoint_prod_right _ (\u03bb g, list.rel_of_pairwise_cons hld) } },\n  { rintros \u27e8c, t, rfl, hd, hc, rfl\u27e9,\n    simp [hd.cycle_type, hc.cycle_type] }\nend\n\nlemma le_card_support_of_mem_cycle_type {n : \u2115} {\u03c3 : perm \u03b1} (h : n \u2208 cycle_type \u03c3) :\n  n \u2264 \u03c3.support.card :=\n(le_sum_of_mem h).trans (le_of_eq \u03c3.sum_cycle_type)\n\nlemma cycle_type_of_card_le_mem_cycle_type_add_two {n : \u2115} {g : perm \u03b1}\n  (hn2 : fintype.card \u03b1 < n + 2) (hng : n \u2208 g.cycle_type) :\n  g.cycle_type = {n} :=\nbegin\n  obtain \u27e8c, g', rfl, hd, hc, rfl\u27e9 := mem_cycle_type_iff.1 hng,\n  by_cases g'1 : g' = 1,\n  { rw [hd.cycle_type, hc.cycle_type, coe_singleton, g'1, cycle_type_one, add_zero] },\n  contrapose! hn2,\n  apply le_trans _ (c * g').support.card_le_univ,\n  rw [hd.card_support_mul],\n  exact add_le_add_left (two_le_card_support_of_ne_one g'1) _,\nend\n\nend cycle_type\n\nlemma card_compl_support_modeq [decidable_eq \u03b1] {p n : \u2115} [hp : fact p.prime] {\u03c3 : perm \u03b1}\n  (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u03c3.support\u1d9c.card \u2261 fintype.card \u03b1 [MOD p] :=\nbegin\n  rw [nat.modeq_iff_dvd' \u03c3.support\u1d9c.card_le_univ, \u2190finset.card_compl, compl_compl],\n  refine (congr_arg _ \u03c3.sum_cycle_type).mp (multiset.dvd_sum (\u03bb k hk, _)),\n  obtain \u27e8m, -, hm\u27e9 := (nat.dvd_prime_pow hp.out).mp (order_of_dvd_of_pow_eq_one h\u03c3),\n  obtain \u27e8l, -, rfl\u27e9 := (nat.dvd_prime_pow hp.out).mp\n    ((congr_arg _ hm).mp (dvd_of_mem_cycle_type hk)),\n  exact dvd_pow_self _ (\u03bb h, (one_lt_of_mem_cycle_type hk).ne $ by rw [h, pow_zero]),\nend\n\nlemma exists_fixed_point_of_prime {p n : \u2115} [hp : fact p.prime] (h\u03b1 : \u00ac p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u2203 a : \u03b1, \u03c3 a = a :=\nbegin\n  classical,\n  contrapose! h\u03b1,\n  simp_rw \u2190 mem_support at h\u03b1,\n  exact nat.modeq_zero_iff_dvd.mp ((congr_arg _ (finset.card_eq_zero.mpr (compl_eq_bot.mpr\n    (finset.eq_univ_iff_forall.mpr h\u03b1)))).mp (card_compl_support_modeq h\u03c3).symm),\nend\n\nlemma exists_fixed_point_of_prime' {p n : \u2115} [hp : fact p.prime] (h\u03b1 : p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) {a : \u03b1} (ha : \u03c3 a = a) : \u2203 b : \u03b1, \u03c3 b = b \u2227 b \u2260 a :=\nbegin\n  classical,\n  have h : \u2200 b : \u03b1, b \u2208 \u03c3.support\u1d9c \u2194 \u03c3 b = b :=\n  \u03bb b, by rw [finset.mem_compl, mem_support, not_not],\n  obtain \u27e8b, hb1, hb2\u27e9 := finset.exists_ne_of_one_lt_card (lt_of_lt_of_le hp.out.one_lt\n    (nat.le_of_dvd (finset.card_pos.mpr \u27e8a, (h a).mpr ha\u27e9) (nat.modeq_zero_iff_dvd.mp\n    ((card_compl_support_modeq h\u03c3).trans (nat.modeq_zero_iff_dvd.mpr h\u03b1))))) a,\n  exact \u27e8b, (h b).mp hb1, hb2\u27e9,\nend\n\nlemma is_cycle_of_prime_order' {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : fintype.card \u03b1 < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  classical,\n  exact is_cycle_of_prime_order h1 (lt_of_le_of_lt \u03c3.support.card_le_univ h2),\nend\n\n\n\nsection cauchy\n\nvariables (G : Type*) [group G] (n : \u2115)\n\n/-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/\ndef vectors_prod_eq_one : set (vector G n) :=\n{v | v.to_list.prod = 1}\n\nnamespace vectors_prod_eq_one\n\nlemma mem_iff {n : \u2115} (v : vector G n) :\nv \u2208 vectors_prod_eq_one G n \u2194 v.to_list.prod = 1 := iff.rfl\n\nlemma zero_eq : vectors_prod_eq_one G 0 = {vector.nil} :=\nset.eq_singleton_iff_unique_mem.mpr \u27e8eq.refl (1 : G), \u03bb v hv, v.eq_nil\u27e9\n\nlemma one_eq : vectors_prod_eq_one G 1 = {vector.nil.cons 1} :=\nbegin\n  simp_rw [set.eq_singleton_iff_unique_mem, mem_iff,\n    vector.to_list_singleton, list.prod_singleton, vector.head_cons],\n  exact \u27e8rfl, \u03bb v hv, v.cons_head_tail.symm.trans (congr_arg2 vector.cons hv v.tail.eq_nil)\u27e9,\nend\n\ninstance zero_unique : unique (vectors_prod_eq_one G 0) :=\nby { rw zero_eq, exact set.unique_singleton vector.nil }\n\ninstance one_unique : unique (vectors_prod_eq_one G 1) :=\nby { rw one_eq, exact set.unique_singleton (vector.nil.cons 1) }\n\n/-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`,\nby appending the inverse of the product of `v`. -/\n@[simps] def vector_equiv : vector G n \u2243 vectors_prod_eq_one G (n + 1) :=\n{ to_fun := \u03bb v, \u27e8v.to_list.prod\u207b\u00b9 ::\u1d65 v,\n    by rw [mem_iff, vector.to_list_cons, list.prod_cons, inv_mul_self]\u27e9,\n  inv_fun := \u03bb v, v.1.tail,\n  left_inv := \u03bb v, v.tail_cons v.to_list.prod\u207b\u00b9,\n  right_inv := \u03bb v, subtype.ext ((congr_arg2 vector.cons (eq_inv_of_mul_eq_one_left (by\n  { rw [\u2190list.prod_cons, \u2190vector.to_list_cons, v.1.cons_head_tail],\n    exact v.2 })).symm rfl).trans v.1.cons_head_tail) }\n\n/-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`,\nby deleting the last entry of `v`. -/\ndef equiv_vector : vectors_prod_eq_one G n \u2243 vector G (n - 1) :=\n((vector_equiv G (n - 1)).trans (if hn : n = 0 then (show vectors_prod_eq_one G (n - 1 + 1) \u2243\n  vectors_prod_eq_one G n, by { rw hn, apply equiv_of_unique })\n  else by rw tsub_add_cancel_of_le (nat.pos_of_ne_zero hn).nat_succ_le)).symm\n\ninstance [fintype G] : fintype (vectors_prod_eq_one G n) :=\nfintype.of_equiv (vector G (n - 1)) (equiv_vector G n).symm\n\nlemma card [fintype G] :\n  fintype.card (vectors_prod_eq_one G n) = fintype.card G ^ (n - 1) :=\n(fintype.card_congr (equiv_vector G n)).trans (card_vector (n - 1))\n\nvariables {G n} {g : G} (v : vectors_prod_eq_one G n) (j k : \u2115)\n\n/-- Rotate a vector whose product is 1. -/\ndef rotate : vectors_prod_eq_one G n :=\n\u27e8\u27e8_, (v.1.1.length_rotate k).trans v.1.2\u27e9, list.prod_rotate_eq_one_of_prod_eq_one v.2 k\u27e9\n\nlemma rotate_zero : rotate v 0 = v :=\nsubtype.ext (subtype.ext v.1.1.rotate_zero)\n\nlemma rotate_rotate : rotate (rotate v j) k = rotate v (j + k) :=\nsubtype.ext (subtype.ext (v.1.1.rotate_rotate j k))\n\nlemma rotate_length : rotate v n = v :=\nsubtype.ext (subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length))\n\nend vectors_prod_eq_one\n\n/-- For every prime `p` dividing the order of a finite group `G` there exists an element of order\n`p` in `G`. This is known as Cauchy's theorem. -/\nlemma _root_.exists_prime_order_of_dvd_card {G : Type*} [group G] [fintype G] (p : \u2115)\n  [hp : fact p.prime] (hdvd : p \u2223 fintype.card G) : \u2203 x : G, order_of x = p :=\nbegin\n  have hp' : p - 1 \u2260 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_lt hp.out.one_lt),\n  have Scard := calc p \u2223 fintype.card G ^ (p - 1) : hdvd.trans (dvd_pow (dvd_refl _) hp')\n  ... = fintype.card (vectors_prod_eq_one G p) : (vectors_prod_eq_one.card G p).symm,\n  let f : \u2115 \u2192 vectors_prod_eq_one G p \u2192 vectors_prod_eq_one G p :=\n  \u03bb k v, vectors_prod_eq_one.rotate v k,\n  have hf1 : \u2200 v, f 0 v = v := vectors_prod_eq_one.rotate_zero,\n  have hf2 : \u2200 j k v, f k (f j v) = f (j + k) v :=\n  \u03bb j k v, vectors_prod_eq_one.rotate_rotate v j k,\n  have hf3 : \u2200 v, f p v = v := vectors_prod_eq_one.rotate_length,\n  let \u03c3 := equiv.mk (f 1) (f (p - 1))\n    (\u03bb s, by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3])\n    (\u03bb s, by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3]),\n  have h\u03c3 : \u2200 k v, (\u03c3 ^ k) v = f k v :=\n  \u03bb k v, nat.rec (hf1 v).symm (\u03bb k hk, eq.trans (by exact congr_arg \u03c3 hk) (hf2 k 1 v)) k,\n  replace h\u03c3 : \u03c3 ^ (p ^ 1) = 1 := perm.ext (\u03bb v, by rw [pow_one, h\u03c3, hf3, one_apply]),\n  let v\u2080 : vectors_prod_eq_one G p :=\n    \u27e8vector.replicate p 1, (list.prod_replicate p 1).trans (one_pow p)\u27e9,\n  have hv\u2080 : \u03c3 v\u2080 = v\u2080 := subtype.ext (subtype.ext (list.rotate_replicate (1 : G) p 1)),\n  obtain \u27e8v, hv1, hv2\u27e9 := exists_fixed_point_of_prime' Scard h\u03c3 hv\u2080,\n  refine exists_imp_exists (\u03bb g hg, order_of_eq_prime _ (\u03bb hg', hv2 _))\n    (list.rotate_one_eq_self_iff_eq_replicate.mp (subtype.ext_iff.mp (subtype.ext_iff.mp hv1))),\n  { rw [\u2190list.prod_replicate, \u2190v.1.2, \u2190hg, (show v.val.val.prod = 1, from v.2)] },\n  { rw [subtype.ext_iff_val, subtype.ext_iff_val, hg, hg', v.1.2],\n    refl },\nend\n\n/-- For every prime `p` dividing the order of a finite additive group `G` there exists an element of\norder `p` in `G`. This is the additive version of Cauchy's theorem. -/\nlemma _root_.exists_prime_add_order_of_dvd_card {G : Type*} [add_group G] [fintype G] (p : \u2115)\n  [hp : fact p.prime] (hdvd : p \u2223 fintype.card G) : \u2203 x : G, add_order_of x = p :=\n@exists_prime_order_of_dvd_card (multiplicative G) _ _ _ _ hdvd\n\nattribute [to_additive exists_prime_add_order_of_dvd_card] exists_prime_order_of_dvd_card\n\nend cauchy\n\nlemma subgroup_eq_top_of_swap_mem [decidable_eq \u03b1] {H : subgroup (perm \u03b1)}\n  [d : decidable_pred (\u2208 H)] {\u03c4 : perm \u03b1} (h0 : (fintype.card \u03b1).prime)\n  (h1 : fintype.card \u03b1 \u2223 fintype.card H) (h2 : \u03c4 \u2208 H) (h3 : is_swap \u03c4) :\n  H = \u22a4 :=\nbegin\n  haveI : fact (fintype.card \u03b1).prime := \u27e8h0\u27e9,\n  obtain \u27e8\u03c3, h\u03c3\u27e9 := exists_prime_order_of_dvd_card (fintype.card \u03b1) h1,\n  have h\u03c31 : order_of (\u03c3 : perm \u03b1) = fintype.card \u03b1 := (order_of_subgroup \u03c3).trans h\u03c3,\n  have h\u03c32 : is_cycle \u2191\u03c3 := is_cycle_of_prime_order'' h0 h\u03c31,\n  have h\u03c33 : (\u03c3 : perm \u03b1).support = \u22a4 :=\n    finset.eq_univ_of_card (\u03c3 : perm \u03b1).support (h\u03c32.order_of.symm.trans h\u03c31),\n  have h\u03c34 : subgroup.closure {\u2191\u03c3, \u03c4} = \u22a4 := closure_prime_cycle_swap h0 h\u03c32 h\u03c33 h3,\n  rw [eq_top_iff, \u2190h\u03c34, subgroup.closure_le, set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8subtype.mem \u03c3, h2\u27e9,\nend\n\nsection partition\n\nvariables [decidable_eq \u03b1]\n\n/-- The partition corresponding to a permutation -/\ndef partition (\u03c3 : perm \u03b1) : (fintype.card \u03b1).partition :=\n{ parts := \u03c3.cycle_type + replicate (fintype.card \u03b1 - \u03c3.support.card) 1,\n  parts_pos := \u03bb n hn,\n  begin\n    cases mem_add.mp hn with hn hn,\n    { exact zero_lt_one.trans (one_lt_of_mem_cycle_type hn) },\n    { exact lt_of_lt_of_le zero_lt_one (ge_of_eq (multiset.eq_of_mem_replicate hn)) },\n  end,\n  parts_sum := by rw [sum_add, sum_cycle_type, multiset.sum_replicate, nsmul_eq_mul,\n    nat.cast_id, mul_one, add_tsub_cancel_of_le \u03c3.support.card_le_univ] }\n\nlemma parts_partition {\u03c3 : perm \u03b1} :\n  \u03c3.partition.parts = \u03c3.cycle_type + replicate (fintype.card \u03b1 - \u03c3.support.card) 1 := rfl\n\nlemma filter_parts_partition_eq_cycle_type {\u03c3 : perm \u03b1} :\n  (partition \u03c3).parts.filter (\u03bb n, 2 \u2264 n) = \u03c3.cycle_type :=\nbegin\n  rw [parts_partition, filter_add, multiset.filter_eq_self.2 (\u03bb _, two_le_of_mem_cycle_type),\n    multiset.filter_eq_nil.2 (\u03bb a h, _), add_zero],\n  rw multiset.eq_of_mem_replicate h,\n  dec_trivial\nend\n\nlemma partition_eq_of_is_conj {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.partition = \u03c4.partition :=\nbegin\n  rw [is_conj_iff_cycle_type_eq],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rw [nat.partition.ext_iff, parts_partition, parts_partition,\n      \u2190 sum_cycle_type, \u2190 sum_cycle_type, h] },\n  { rw [\u2190 filter_parts_partition_eq_cycle_type, \u2190 filter_parts_partition_eq_cycle_type, h] }\nend\n\nend partition\n\n/-!\n### 3-cycles\n-/\n\n/-- A three-cycle is a cycle of length 3. -/\ndef is_three_cycle [decidable_eq \u03b1] (\u03c3 : perm \u03b1) : Prop := \u03c3.cycle_type = {3}\n\nnamespace is_three_cycle\n\nvariables [decidable_eq \u03b1] {\u03c3 : perm \u03b1}\n\nlemma cycle_type (h : is_three_cycle \u03c3) : \u03c3.cycle_type = {3} := h\n\nlemma card_support (h : is_three_cycle \u03c3) : \u03c3.support.card = 3 :=\nby rw [\u2190sum_cycle_type, h.cycle_type, multiset.sum_singleton]\n\nlemma _root_.card_support_eq_three_iff : \u03c3.support.card = 3 \u2194 \u03c3.is_three_cycle :=\nbegin\n  refine \u27e8\u03bb h, _, is_three_cycle.card_support\u27e9,\n  by_cases h0 : \u03c3.cycle_type = 0,\n  { rw [\u2190sum_cycle_type, h0, sum_zero] at h,\n    exact (ne_of_lt zero_lt_three h).elim },\n  obtain \u27e8n, hn\u27e9 := exists_mem_of_ne_zero h0,\n  by_cases h1 : \u03c3.cycle_type.erase n = 0,\n  { rw [\u2190sum_cycle_type, \u2190cons_erase hn, h1, cons_zero, multiset.sum_singleton] at h,\n    rw [is_three_cycle, \u2190cons_erase hn, h1, h, \u2190cons_zero] },\n  obtain \u27e8m, hm\u27e9 := exists_mem_of_ne_zero h1,\n  rw [\u2190sum_cycle_type, \u2190cons_erase hn, \u2190cons_erase hm, multiset.sum_cons, multiset.sum_cons] at h,\n  -- TODO: linarith [...] should solve this directly\n  have : \u2200 {k}, 2 \u2264 m \u2192 2 \u2264 n \u2192 n + (m + k) = 3 \u2192 false, { intros, linarith },\n  cases this (two_le_of_mem_cycle_type (mem_of_mem_erase hm)) (two_le_of_mem_cycle_type hn) h,\nend\n\nlemma is_cycle (h : is_three_cycle \u03c3) : is_cycle \u03c3 :=\nby rw [\u2190card_cycle_type_eq_one, h.cycle_type, card_singleton]\n\nlemma sign (h : is_three_cycle \u03c3) : sign \u03c3 = 1 :=\nbegin\n  rw [equiv.perm.sign_of_cycle_type, h.cycle_type],\n  refl,\nend\n\nlemma inv {f : perm \u03b1} (h : is_three_cycle f) : is_three_cycle (f\u207b\u00b9) :=\nby rwa [is_three_cycle, cycle_type_inv]\n\n@[simp] lemma inv_iff {f : perm \u03b1} : is_three_cycle (f\u207b\u00b9) \u2194 is_three_cycle f :=\n\u27e8by { rw \u2190 inv_inv f, apply inv }, inv\u27e9\n\nlemma order_of {g : perm \u03b1} (ht : is_three_cycle g) :\n  order_of g = 3 :=\nby rw [\u2190lcm_cycle_type, ht.cycle_type, multiset.lcm_singleton, normalize_eq]\n\nlemma is_three_cycle_sq {g : perm \u03b1} (ht : is_three_cycle g) :\n  is_three_cycle (g * g) :=\nbegin\n  rw [\u2190pow_two, \u2190card_support_eq_three_iff, support_pow_coprime, ht.card_support],\n  rw [ht.order_of, nat.coprime_iff_gcd_eq_one],\n  norm_num,\nend\n\nend is_three_cycle\n\nsection\nvariable [decidable_eq \u03b1]\n\nlemma is_three_cycle_swap_mul_swap_same\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) (bc : b \u2260 c) :\n  is_three_cycle (swap a b * swap a c) :=\nbegin\n  suffices h : support (swap a b * swap a c) = {a, b, c},\n  { rw [\u2190card_support_eq_three_iff, h],\n    simp [ab, ac, bc] },\n  apply le_antisymm ((support_mul_le _ _).trans (\u03bb x, _)) (\u03bb x hx, _),\n  { simp [ab, ac, bc] },\n  { simp only [finset.mem_insert, finset.mem_singleton] at hx,\n    rw mem_support,\n    simp only [perm.coe_mul, function.comp_app, ne.def],\n    obtain rfl | rfl | rfl := hx,\n    { rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm],\n      exact ac.symm },\n    { rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right],\n      exact ab },\n    { rw [swap_apply_right, swap_apply_left],\n      exact bc } }\nend\n\nopen subgroup\n\nlemma swap_mul_swap_same_mem_closure_three_cycles\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) :\n  (swap a b * swap a c) \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  by_cases bc : b = c,\n  { subst bc,\n    simp [one_mem] },\n  exact subset_closure (is_three_cycle_swap_mul_swap_same ab ac bc)\nend\n\nlemma is_swap.mul_mem_closure_three_cycles {\u03c3 \u03c4 : perm \u03b1}\n  (h\u03c3 : is_swap \u03c3) (h\u03c4 : is_swap \u03c4) :\n  \u03c3 * \u03c4 \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  obtain \u27e8a, b, ab, rfl\u27e9 := h\u03c3,\n  obtain \u27e8c, d, cd, rfl\u27e9 := h\u03c4,\n  by_cases ac : a = c,\n  { subst ac,\n    exact swap_mul_swap_same_mem_closure_three_cycles ab cd },\n  have h' : swap a b * swap c d = swap a b * swap a c * (swap c a * swap c d),\n  { simp [swap_comm c a, mul_assoc] },\n  rw h',\n  exact mul_mem (swap_mul_swap_same_mem_closure_three_cycles ab ac)\n    (swap_mul_swap_same_mem_closure_three_cycles (ne.symm ac) cd),\nend\n\nend\n\nend equiv.perm\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/perm/cycle/type.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695833, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7273745582850984}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n\nVarious multiplicative and additive structures. Partially modeled on Isabelle's library.\n-/\n\nimport logic.eq data.unit data.sigma data.prod\nimport algebra.binary algebra.priority\n\nopen binary\n\nvariable {A : Type}\n\n/- semigroup -/\n\nattribute inv [light 3]\nattribute neg [light 3]\n\nstructure semigroup [class] (A : Type) extends has_mul A :=\n(mul_assoc : \u2200a b c, mul (mul a b) c = mul a (mul b c))\n\n-- We add pattern hints to the following lemma because we want it to be used in both directions\n-- at inst_simp strategy.\ntheorem mul.assoc [simp] [semigroup A] (a b c : A) : (: a * b * c :) = (: a * (b * c) :) :=\n!semigroup.mul_assoc\n\nstructure comm_semigroup [class] (A : Type) extends semigroup A :=\n(mul_comm : \u2200a b, mul a b = mul b a)\n\ntheorem mul.comm [simp] [comm_semigroup A] (a b : A) : a * b = b * a :=\n!comm_semigroup.mul_comm\n\ntheorem mul.left_comm [simp] [comm_semigroup A] (a b c : A) : a * (b * c) = b * (a * c) :=\nbinary.left_comm (@mul.comm A _) (@mul.assoc A _) a b c\n\ntheorem mul.right_comm [comm_semigroup A] (a b c : A) : (a * b) * c = (a * c) * b :=\nby simp\n\nstructure left_cancel_semigroup [class] (A : Type) extends semigroup A :=\n(mul_left_cancel : \u2200a b c, mul a b = mul a c \u2192 b = c)\n\ntheorem mul.left_cancel [left_cancel_semigroup A] {a b c : A} : a * b = a * c \u2192 b = c :=\n!left_cancel_semigroup.mul_left_cancel\n\nabbreviation eq_of_mul_eq_mul_left' := @mul.left_cancel\n\nstructure right_cancel_semigroup [class] (A : Type) extends semigroup A :=\n(mul_right_cancel : \u2200a b c, mul a b = mul c b \u2192 a = c)\n\ntheorem mul.right_cancel [right_cancel_semigroup A] {a b c : A} : a * b = c * b \u2192 a = c :=\n!right_cancel_semigroup.mul_right_cancel\n\nabbreviation eq_of_mul_eq_mul_right' := @mul.right_cancel\n\n/- additive semigroup -/\n\nstructure add_semigroup [class] (A : Type) extends has_add A :=\n(add_assoc : \u2200a b c, add (add a b) c = add a (add b c))\n\ntheorem add.assoc [simp] [add_semigroup A] (a b c : A) : (: a + b + c :) = (: a + (b + c) :) :=\n!add_semigroup.add_assoc\n\nstructure add_comm_semigroup [class] (A : Type) extends add_semigroup A :=\n(add_comm : \u2200a b, add a b = add b a)\n\ntheorem add.comm [simp] [add_comm_semigroup A] (a b : A) : a + b = b + a :=\n!add_comm_semigroup.add_comm\n\ntheorem add.left_comm [simp] [add_comm_semigroup A] (a b c : A) : a + (b + c) = b + (a + c) :=\nbinary.left_comm (@add.comm A _) (@add.assoc A _) a b c\n\ntheorem add.right_comm [add_comm_semigroup A] (a b c : A) : (a + b) + c = (a + c) + b :=\nby simp\n\nstructure add_left_cancel_semigroup [class] (A : Type) extends add_semigroup A :=\n(add_left_cancel : \u2200a b c, add a b = add a c \u2192 b = c)\n\ntheorem add.left_cancel [add_left_cancel_semigroup A] {a b c : A} : a + b = a + c \u2192 b = c :=\n!add_left_cancel_semigroup.add_left_cancel\n\nabbreviation eq_of_add_eq_add_left := @add.left_cancel\n\nstructure add_right_cancel_semigroup [class] (A : Type) extends add_semigroup A :=\n(add_right_cancel : \u2200a b c, add a b = add c b \u2192 a = c)\n\ntheorem add.right_cancel [add_right_cancel_semigroup A] {a b c : A} : a + b = c + b \u2192 a = c :=\n!add_right_cancel_semigroup.add_right_cancel\n\nabbreviation eq_of_add_eq_add_right := @add.right_cancel\n\n/- monoid -/\n\nstructure monoid [class] (A : Type) extends semigroup A, has_one A :=\n(one_mul : \u2200a, mul one a = a) (mul_one : \u2200a, mul a one = a)\n\ntheorem one_mul [simp] [monoid A] (a : A) : 1 * a = a := !monoid.one_mul\n\ntheorem mul_one [simp] [monoid A] (a : A) : a * 1 = a := !monoid.mul_one\n\nstructure comm_monoid [class] (A : Type) extends monoid A, comm_semigroup A\n\n/- additive monoid -/\n\nstructure add_monoid [class] (A : Type) extends add_semigroup A, has_zero A :=\n(zero_add : \u2200a, add zero a = a) (add_zero : \u2200a, add a zero = a)\n\ntheorem zero_add [simp] [add_monoid A] (a : A) : 0 + a = a := !add_monoid.zero_add\n\ntheorem add_zero [simp] [add_monoid A] (a : A) : a + 0 = a := !add_monoid.add_zero\n\nstructure add_comm_monoid [class] (A : Type) extends add_monoid A, add_comm_semigroup A\n\ndefinition add_monoid.to_monoid {A : Type} [add_monoid A] : monoid A :=\n\u2983 monoid,\n  mul         := add_monoid.add,\n  mul_assoc   := add_monoid.add_assoc,\n  one         := add_monoid.zero A,\n  mul_one     := add_monoid.add_zero,\n  one_mul     := add_monoid.zero_add\n\u2984\n\ndefinition add_comm_monoid.to_comm_monoid {A : Type} [add_comm_monoid A] : comm_monoid A :=\n\u2983 comm_monoid,\n  add_monoid.to_monoid,\n  mul_comm    := add_comm_monoid.add_comm\n\u2984\n\ndefinition monoid.to_add_monoid {A : Type} [s : monoid A] : add_monoid A :=\n\u2983 add_monoid,\n  add         := monoid.mul,\n  add_assoc   := monoid.mul_assoc,\n  zero        := monoid.one A,\n  add_zero    := monoid.mul_one,\n  zero_add    := monoid.one_mul\n\u2984\n\ndefinition comm_monoid.to_add_comm_monoid {A : Type} [s : comm_monoid A] : add_comm_monoid A :=\n\u2983 add_comm_monoid,\n  monoid.to_add_monoid,\n  add_comm    := comm_monoid.mul_comm\n\u2984\n\nsection add_comm_monoid\n  variables [add_comm_monoid A]\n\n  theorem add_comm_three  (a b c : A) : a + b + c = c + b + a :=\n  by simp\n\n  theorem add.comm4 : \u2200 (n m k l : A), n + m + (k + l) = n + k + (m + l) :=\n  by simp\nend add_comm_monoid\n\n/- group -/\n\nstructure group [class] (A : Type) extends monoid A, has_inv A :=\n(mul_left_inv : \u2200a, mul (inv a) a = one)\n\n-- Note: with more work, we could derive the axiom one_mul\n\nsection group\n  variable [group A]\n\n  theorem mul.left_inv [simp] (a : A) : a\u207b\u00b9 * a = 1 := !group.mul_left_inv\n\n  theorem inv_mul_cancel_left [simp] (a b : A) : a\u207b\u00b9 * (a * b) = b :=\n  by rewrite [-mul.assoc, mul.left_inv, one_mul]\n\n  theorem inv_mul_cancel_right [simp] (a b : A) : a * b\u207b\u00b9 * b = a :=\n  by simp\n\n  theorem inv_eq_of_mul_eq_one {a b : A} (H : a * b = 1) : a\u207b\u00b9 = b :=\n  have a\u207b\u00b9 * 1 = b, by inst_simp,\n  by inst_simp\n\n  theorem one_inv [simp] : 1\u207b\u00b9 = (1 : A) :=\n  inv_eq_of_mul_eq_one (one_mul 1)\n\n  theorem inv_inv [simp] (a : A) : (a\u207b\u00b9)\u207b\u00b9 = a :=\n  inv_eq_of_mul_eq_one (mul.left_inv a)\n\n  variable (A)\n  theorem left_inverse_inv : function.left_inverse (\u03bb a : A, a\u207b\u00b9) (\u03bb a, a\u207b\u00b9) :=\n  take a, inv_inv a\n  variable {A}\n\n  theorem inv.inj {a b : A} (H : a\u207b\u00b9 = b\u207b\u00b9) : a = b :=\n  have a = a\u207b\u00b9\u207b\u00b9, by simp_nohyps,\n  by inst_simp\n\n  theorem inv_eq_inv_iff_eq (a b : A) : a\u207b\u00b9 = b\u207b\u00b9 \u2194 a = b :=\n  iff.intro (assume H, inv.inj H) (by simp)\n\n  theorem inv_eq_one_iff_eq_one (a : A) : a\u207b\u00b9 = 1 \u2194 a = 1 :=\n  have a\u207b\u00b9 = 1\u207b\u00b9 \u2194 a = 1, from inv_eq_inv_iff_eq a 1,\n  by simp\n\n  theorem eq_one_of_inv_eq_one (a : A) : a\u207b\u00b9 = 1 \u2192 a = 1 :=\n  iff.mp !inv_eq_one_iff_eq_one\n\n  theorem eq_inv_of_eq_inv {a b : A} (H : a = b\u207b\u00b9) : b = a\u207b\u00b9 :=\n  by simp\n\n  theorem eq_inv_iff_eq_inv (a b : A) : a = b\u207b\u00b9 \u2194 b = a\u207b\u00b9 :=\n  iff.intro !eq_inv_of_eq_inv !eq_inv_of_eq_inv\n\n  theorem eq_inv_of_mul_eq_one {a b : A} (H : a * b = 1) : a = b\u207b\u00b9 :=\n  have a\u207b\u00b9 = b, from inv_eq_of_mul_eq_one H,\n  by inst_simp\n\n  theorem mul.right_inv [simp] (a : A) : a * a\u207b\u00b9 = 1 :=\n  have a = a\u207b\u00b9\u207b\u00b9, by simp,\n  by inst_simp\n\n  theorem mul_inv_cancel_left [simp] (a b : A) : a * (a\u207b\u00b9 * b) = b :=\n  by inst_simp\n\n  theorem mul_inv_cancel_right [simp] (a b : A) : a * b * b\u207b\u00b9 = a :=\n  by inst_simp\n\n  theorem mul_inv [simp] (a b : A) : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\n  inv_eq_of_mul_eq_one (by inst_simp)\n\n  theorem eq_of_mul_inv_eq_one {a b : A} (H : a * b\u207b\u00b9 = 1) : a = b :=\n  have a\u207b\u00b9 * 1 = a\u207b\u00b9, by inst_simp,\n  by inst_simp\n\n  theorem eq_mul_inv_of_mul_eq {a b c : A} (H : a * c = b) : a = b * c\u207b\u00b9 :=\n  by simp\n\n  theorem eq_inv_mul_of_mul_eq {a b c : A} (H : b * a = c) : a = b\u207b\u00b9 * c :=\n  by simp\n\n  theorem inv_mul_eq_of_eq_mul {a b c : A} (H : b = a * c) : a\u207b\u00b9 * b = c :=\n  by simp\n\n  theorem mul_inv_eq_of_eq_mul {a b c : A} (H : a = c * b) : a * b\u207b\u00b9 = c :=\n  by simp\n\n  theorem eq_mul_of_mul_inv_eq {a b c : A} (H : a * c\u207b\u00b9 = b) : a = b * c :=\n  by simp\n\n  theorem eq_mul_of_inv_mul_eq {a b c : A} (H : b\u207b\u00b9 * a = c) : a = b * c :=\n  by simp\n\n  theorem mul_eq_of_eq_inv_mul {a b c : A} (H : b = a\u207b\u00b9 * c) : a * b = c :=\n  by simp\n\n  theorem mul_eq_of_eq_mul_inv {a b c : A} (H : a = c * b\u207b\u00b9) : a * b = c :=\n  by simp\n\n  theorem mul_eq_iff_eq_inv_mul (a b c : A) : a * b = c \u2194 b = a\u207b\u00b9 * c :=\n  iff.intro eq_inv_mul_of_mul_eq mul_eq_of_eq_inv_mul\n\n  theorem mul_eq_iff_eq_mul_inv (a b c : A) : a * b = c \u2194 a = c * b\u207b\u00b9 :=\n  iff.intro eq_mul_inv_of_mul_eq mul_eq_of_eq_mul_inv\n\n  theorem mul_left_cancel {a b c : A} (H : a * b = a * c) : b = c :=\n  have a\u207b\u00b9 * (a * b) = b, by inst_simp,\n  by inst_simp\n\n  theorem mul_right_cancel {a b c : A} (H : a * b = c * b) : a = c :=\n  have a * b * b\u207b\u00b9 = a, by inst_simp,\n  by inst_simp\n\n  theorem mul_eq_one_of_mul_eq_one {a b : A} (H : b * a = 1) : a * b = 1 :=\n  by rewrite [-inv_eq_of_mul_eq_one H, mul.left_inv]\n\n  theorem mul_eq_one_iff_mul_eq_one (a b : A) : a * b = 1 \u2194 b * a = 1 :=\n  iff.intro !mul_eq_one_of_mul_eq_one !mul_eq_one_of_mul_eq_one\n\n  definition conj_by (g a : A) := g * a * g\u207b\u00b9\n  definition is_conjugate (a b : A) := \u2203 x, conj_by x b = a\n\n  local infixl ` ~ ` := is_conjugate\n  local infixr ` \u2218c `:55 := conj_by\n\n  local attribute conj_by [reducible]\n\n  lemma conj_compose [simp] (f g a : A) : f \u2218c g \u2218c a = f*g \u2218c a :=\n  by inst_simp\n\n  lemma conj_id [simp] (a : A) : 1 \u2218c a = a :=\n  by inst_simp\n\n  lemma conj_one [simp] (g : A) : g \u2218c 1 = 1 :=\n  by inst_simp\n\n  lemma conj_inv_cancel [simp] (g : A) : \u2200 a, g\u207b\u00b9 \u2218c g \u2218c a = a :=\n  by inst_simp\n\n  lemma conj_inv [simp] (g : A) : \u2200 a, (g \u2218c a)\u207b\u00b9 = g \u2218c a\u207b\u00b9 :=\n  by inst_simp\n\n  lemma is_conj.refl (a : A) : a ~ a := exists.intro 1 (conj_id a)\n\n  lemma is_conj.symm (a b : A) : a ~ b \u2192 b ~ a :=\n  assume Pab, obtain x (Pconj : x \u2218c b = a), from Pab,\n  have Pxinv : x\u207b\u00b9 \u2218c x \u2218c b = x\u207b\u00b9 \u2218c a,   by simp,\n  exists.intro x\u207b\u00b9 (by simp)\n\n  lemma is_conj.trans (a b c : A) : a ~ b \u2192 b ~ c \u2192 a ~ c :=\n  assume Pab, assume Pbc,\n  obtain x (Px : x \u2218c b = a), from Pab,\n  obtain y (Py : y \u2218c c = b), from Pbc,\n  exists.intro (x*y) (by inst_simp)\n\nend group\n\ndefinition group.to_left_cancel_semigroup [trans_instance] [s : group A] :\n    left_cancel_semigroup A :=\n\u2983 left_cancel_semigroup, s,\n  mul_left_cancel := @mul_left_cancel A s \u2984\n\ndefinition group.to_right_cancel_semigroup [trans_instance] [s : group A] :\n    right_cancel_semigroup A :=\n\u2983 right_cancel_semigroup, s,\n  mul_right_cancel := @mul_right_cancel A s \u2984\n\nstructure comm_group [class] (A : Type) extends group A, comm_monoid A\n\n/- additive group -/\n\nstructure add_group [class] (A : Type) extends add_monoid A, has_neg A :=\n(add_left_inv : \u2200a, add (neg a) a = zero)\n\ndefinition add_group.to_group {A : Type} [add_group A] : group A :=\n\u2983 group, add_monoid.to_monoid,\n  mul_left_inv := add_group.add_left_inv \u2984\n\ndefinition group.to_add_group {A : Type} [s : group A] : add_group A :=\n\u2983 add_group, monoid.to_add_monoid,\n  add_left_inv := group.mul_left_inv \u2984\n\nsection add_group\n  variables [s : add_group A]\n  include s\n\n  theorem add.left_inv [simp] (a : A) : -a + a = 0 := !add_group.add_left_inv\n\n  theorem neg_add_cancel_left [simp] (a b : A) : -a + (a + b) = b :=\n  calc -a + (a + b) = (-a + a) + b : by rewrite add.assoc\n               ...  = b            : by simp\n\n  theorem neg_add_cancel_right [simp] (a b : A) : a + -b + b = a :=\n  by simp\n\n  theorem neg_eq_of_add_eq_zero {a b : A} (H : a + b = 0) : -a = b :=\n  have -a + 0 = b, by inst_simp,\n  by inst_simp\n\n  theorem neg_zero [simp] : -0 = (0 : A) := neg_eq_of_add_eq_zero (zero_add 0)\n\n  theorem neg_neg [simp] (a : A) : -(-a) = a := neg_eq_of_add_eq_zero (add.left_inv a)\n\n  variable (A)\n  theorem left_inverse_neg : function.left_inverse (\u03bb a : A, - a) (\u03bb a, - a) :=\n  take a, neg_neg a\n  variable {A}\n\n  theorem eq_neg_of_add_eq_zero {a b : A} (H : a + b = 0) : a = -b :=\n  have -a = b, from neg_eq_of_add_eq_zero H,\n  by inst_simp\n\n  theorem neg.inj {a b : A} (H : -a = -b) : a = b :=\n  have a = -(-a), by simp_nohyps,\n  by inst_simp\n\n  theorem neg_eq_neg_iff_eq (a b : A) : -a = -b \u2194 a = b :=\n  iff.intro (assume H, neg.inj H) (by simp)\n\n  theorem eq_of_neg_eq_neg {a b : A} : -a = -b \u2192 a = b :=\n  iff.mp !neg_eq_neg_iff_eq\n\n  theorem neg_eq_zero_iff_eq_zero (a : A) : -a = 0 \u2194 a = 0 :=\n  have -a = -0 \u2194 a = 0, from neg_eq_neg_iff_eq a 0,\n  by simp\n\n  theorem eq_zero_of_neg_eq_zero {a : A} : -a = 0 \u2192 a = 0 :=\n  iff.mp !neg_eq_zero_iff_eq_zero\n\n  theorem eq_neg_of_eq_neg {a b : A} (H : a = -b) : b = -a :=\n  by simp\n\n  theorem eq_neg_iff_eq_neg (a b : A) : a = -b \u2194 b = -a :=\n  iff.intro !eq_neg_of_eq_neg !eq_neg_of_eq_neg\n\n  theorem add.right_inv [simp] (a : A) : a + -a = 0 :=\n  have a = -(-a), by simp,\n  by inst_simp\n\n  theorem add_neg_cancel_left [simp] (a b : A) : a + (-a + b) = b :=\n  by inst_simp\n\n  theorem add_neg_cancel_right [simp] (a b : A) : a + b + -b = a :=\n  by simp\n\n  theorem neg_add_rev [simp] (a b : A) : -(a + b) = -b + -a :=\n  neg_eq_of_add_eq_zero (by simp)\n\n  -- TODO: delete these in favor of sub rules?\n  theorem eq_add_neg_of_add_eq {a b c : A} (H : a + c = b) : a = b + -c :=\n  by simp\n\n  theorem eq_neg_add_of_add_eq {a b c : A} (H : b + a = c) : a = -b + c :=\n  by simp\n\n  theorem neg_add_eq_of_eq_add {a b c : A} (H : b = a + c) : -a + b = c :=\n  by simp\n\n  theorem add_neg_eq_of_eq_add {a b c : A} (H : a = c + b) : a + -b = c :=\n  by simp\n\n  theorem eq_add_of_add_neg_eq {a b c : A} (H : a + -c = b) : a = b + c :=\n  by simp\n\n  theorem eq_add_of_neg_add_eq {a b c : A} (H : -b + a = c) : a = b + c :=\n  by simp\n\n  theorem add_eq_of_eq_neg_add {a b c : A} (H : b = -a + c) : a + b = c :=\n  by simp\n\n  theorem add_eq_of_eq_add_neg {a b c : A} (H : a = c + -b) : a + b = c :=\n  by simp\n\n  theorem add_eq_iff_eq_neg_add (a b c : A) : a + b = c \u2194 b = -a + c :=\n  iff.intro eq_neg_add_of_add_eq add_eq_of_eq_neg_add\n\n  theorem add_eq_iff_eq_add_neg (a b c : A) : a + b = c \u2194 a = c + -b :=\n  iff.intro eq_add_neg_of_add_eq add_eq_of_eq_add_neg\n\n  theorem add_left_cancel {a b c : A} (H : a + b = a + c) : b = c :=\n  have -a + (a + b) = b, by inst_simp,\n  by inst_simp\n\n  theorem add_right_cancel {a b c : A} (H : a + b = c + b) : a = c :=\n  have a + b + -b = a, by inst_simp,\n  by inst_simp\n\n  definition add_group.to_add_left_cancel_semigroup [trans_instance] :\n    add_left_cancel_semigroup A :=\n  \u2983 add_left_cancel_semigroup, s,\n    add_left_cancel := @add_left_cancel A s \u2984\n\n  definition add_group.to_add_right_cancel_semigroup [trans_instance] :\n    add_right_cancel_semigroup A :=\n  \u2983 add_right_cancel_semigroup, s,\n    add_right_cancel := @add_right_cancel A s \u2984\n\n  theorem add_neg_eq_neg_add_rev {a b : A} : a + -b = -(b + -a) :=\n  by simp\n\n  theorem ne_add_of_ne_zero_right (a : A) {b : A} (H : b \u2260 0) : a \u2260 b + a :=\n    begin\n      intro Heq,\n      apply H,\n      rewrite [-zero_add a at Heq{1}],\n      let Heq' := eq_of_add_eq_add_right Heq,\n      apply eq.symm Heq'\n    end\n\n  theorem ne_add_of_ne_zero_left (a : A) {b : A} (H : b \u2260 0) : a \u2260 a + b :=\n    begin\n      intro Heq,\n      apply H,\n      rewrite [-add_zero a at Heq{1}],\n      let Heq' := eq_of_add_eq_add_left Heq,\n      apply eq.symm Heq'\n    end\n\n  /- sub -/\n\n  -- TODO: derive corresponding facts for div in a field\n  protected definition algebra.sub [reducible] (a b : A) : A := a + -b\n\n  definition add_group_has_sub [instance] : has_sub A :=\n  has_sub.mk algebra.sub\n\n  theorem sub_eq_add_neg [simp] (a b : A) : a - b = a + -b := rfl\n\n  theorem sub_self (a : A) : a - a = 0 := !add.right_inv\n\n  theorem sub_add_cancel (a b : A) : a - b + b = a := !neg_add_cancel_right\n\n  theorem add_sub_cancel (a b : A) : a + b - b = a := !add_neg_cancel_right\n\n  theorem add_sub_assoc (a b c : A) : a + b - c = a + (b - c) :=\n    by rewrite [sub_eq_add_neg, add.assoc, -sub_eq_add_neg]\n\n  theorem eq_of_sub_eq_zero {a b : A} (H : a - b = 0) : a = b :=\n  have -a + 0 = -a, by inst_simp,\n  by inst_simp\n\n  theorem eq_iff_sub_eq_zero (a b : A) : a = b \u2194 a - b = 0 :=\n  iff.intro (assume H, eq.subst H !sub_self) (assume H, eq_of_sub_eq_zero H)\n\n  theorem zero_sub (a : A) : 0 - a = -a := !zero_add\n\n  theorem sub_zero (a : A) : a - 0 = a :=\n  by simp\n\n  theorem sub_ne_zero_of_ne {a b : A} (H : a \u2260 b) : a - b \u2260 0 :=\n    begin\n      intro Hab,\n      apply H,\n      apply eq_of_sub_eq_zero Hab\n    end\n\n  theorem sub_neg_eq_add (a b : A) : a - (-b) = a + b :=\n  by simp\n\n  theorem neg_sub (a b : A) : -(a - b) = b - a :=\n  neg_eq_of_add_eq_zero (by inst_simp)\n\n  theorem add_sub (a b c : A) : a + (b - c) = a + b - c :=\n  by simp\n\n  theorem sub_add_eq_sub_sub_swap (a b c : A) : a - (b + c) = a - c - b :=\n  by inst_simp\n\n  theorem sub_eq_iff_eq_add (a b c : A) : a - b = c \u2194 a = c + b :=\n  iff.intro (assume H, eq_add_of_add_neg_eq H) (assume H, add_neg_eq_of_eq_add H)\n\n  theorem eq_sub_iff_add_eq (a b c : A) : a = b - c \u2194 a + c = b :=\n  iff.intro (assume H, add_eq_of_eq_add_neg H) (assume H, eq_add_neg_of_add_eq H)\n\n  theorem eq_iff_eq_of_sub_eq_sub {a b c d : A} (H : a - b = c - d) : a = b \u2194 c = d :=\n  calc\n    a = b \u2194 a - b = 0   : eq_iff_sub_eq_zero\n      ... = (c - d = 0) : H\n      ... \u2194 c = d       : iff.symm (eq_iff_sub_eq_zero c d)\n\n  theorem eq_sub_of_add_eq {a b c : A} (H : a + c = b) : a = b - c :=\n  by simp\n\n  theorem sub_eq_of_eq_add {a b c : A} (H : a = c + b) : a - b = c :=\n  by simp\n\n  theorem eq_add_of_sub_eq {a b c : A} (H : a - c = b) : a = b + c :=\n  by simp\n\n  theorem add_eq_of_eq_sub {a b c : A} (H : a = c - b) : a + b = c :=\n  by simp\n\n  theorem left_inverse_sub_add_left (c : A) : function.left_inverse (\u03bb x, x - c) (\u03bb x, x + c) :=\n  take x, add_sub_cancel x c\n\n  theorem left_inverse_add_left_sub (c : A) : function.left_inverse (\u03bb x, x + c) (\u03bb x, x - c) :=\n  take x, sub_add_cancel x c\n\n  theorem left_inverse_add_right_neg_add (c : A) :\n      function.left_inverse (\u03bb x, c + x) (\u03bb x, - c + x) :=\n  take x, add_neg_cancel_left c x\n\n  theorem left_inverse_neg_add_add_right (c : A) :\n      function.left_inverse (\u03bb x, - c + x) (\u03bb x, c + x) :=\n  take x, neg_add_cancel_left c x\nend add_group\n\nstructure add_comm_group [class] (A : Type) extends add_group A, add_comm_monoid A\n\ndefinition add_comm_group.to_comm_group (A : Type) [s : add_comm_group A] : comm_group A :=\n\u2983 comm_group, add_group.to_group,\n  mul_comm := add_comm_group.add_comm \u2984\n\ndefinition comm_group.to_add_comm_group (A : Type) [s : comm_group A] : add_comm_group A :=\n\u2983 add_comm_group, group.to_add_group,\n  add_comm := comm_group.mul_comm \u2984\n\n\nsection add_comm_group\n  variable [s : add_comm_group A]\n  include s\n\n  theorem sub_add_eq_sub_sub (a b c : A) : a - (b + c) = a - b - c :=\n  by simp\n\n  theorem neg_add_eq_sub (a b : A) : -a + b = b - a :=\n  by simp\n\n  theorem neg_add (a b : A) : -(a + b) = -a + -b :=\n  by simp\n\n  theorem sub_add_eq_add_sub (a b c : A) : a - b + c = a + c - b :=\n  by simp\n\n  theorem sub_sub (a b c : A) : a - b - c = a - (b + c) :=\n  by simp\n\n  theorem add_sub_add_left_eq_sub (a b c : A) : (c + a) - (c + b) = a - b :=\n  by simp\n\n  theorem eq_sub_of_add_eq' {a b c : A} (H : c + a = b) : a = b - c :=\n  by simp\n\n  theorem sub_eq_of_eq_add' {a b c : A} (H : a = b + c) : a - b = c :=\n  by simp\n\n  theorem eq_add_of_sub_eq' {a b c : A} (H : a - b = c) : a = b + c :=\n  by simp\n\n  theorem add_eq_of_eq_sub' {a b c : A} (H : b = c - a) : a + b = c :=\n  by simp\n\n  theorem sub_sub_self (a b : A) : a - (a - b) = b :=\n  by simp\n\n  theorem add_sub_comm (a b c d : A) : a + b - (c + d) = (a - c) + (b - d) :=\n  by simp\n\n  theorem sub_eq_sub_add_sub (a b c : A) : a - b = c - b + (a - c) :=\n  by simp\n\n  theorem neg_neg_sub_neg (a b : A) : - (-a - -b) = a - b :=\n  by simp\n\nend add_comm_group\n\ndefinition group_of_add_group (A : Type) [G : add_group A] : group A :=\n\u2983group,\n  mul             := has_add.add,\n  mul_assoc       := add.assoc,\n  one             := !has_zero.zero,\n  one_mul         := zero_add,\n  mul_one         := add_zero,\n  inv             := has_neg.neg,\n  mul_left_inv    := add.left_inv\u2984\n\nnamespace norm_num\nreveal add.assoc\n\ndefinition add1 [has_add A] [has_one A] (a : A) : A := add a one\n\nlocal attribute add1 bit0 bit1 [reducible]\n\ntheorem add_comm_four [add_comm_semigroup A] (a b : A) : a + a + (b + b) = (a + b) + (a + b) :=\nby simp\n\ntheorem add_comm_middle [add_comm_semigroup A] (a b c : A) : a + b + c = a + c + b :=\nby simp\n\ntheorem bit0_add_bit0 [add_comm_semigroup A] (a b : A) : bit0 a + bit0 b = bit0 (a + b) :=\nby simp\n\ntheorem bit0_add_bit0_helper [add_comm_semigroup A] (a b t : A) (H : a + b = t) :\n        bit0 a + bit0 b = bit0 t :=\nby rewrite -H; simp\n\ntheorem bit1_add_bit0 [add_comm_semigroup A] [has_one A] (a b : A) :\n        bit1 a + bit0 b = bit1 (a + b) :=\nby simp\n\ntheorem bit1_add_bit0_helper [add_comm_semigroup A] [has_one A] (a b t : A)\n        (H : a + b = t) : bit1 a + bit0 b = bit1 t :=\nby rewrite -H; simp\n\ntheorem bit0_add_bit1 [add_comm_semigroup A] [has_one A] (a b : A) :\n        bit0 a + bit1 b = bit1 (a + b) :=\nby simp\n\ntheorem bit0_add_bit1_helper [add_comm_semigroup A] [has_one A] (a b t : A)\n        (H : a + b = t) : bit0 a + bit1 b = bit1 t :=\nby rewrite -H; simp\n\ntheorem bit1_add_bit1 [add_comm_semigroup A] [has_one A] (a b : A) :\n        bit1 a + bit1 b = bit0 (add1 (a + b)) :=\nby simp\n\ntheorem bit1_add_bit1_helper [add_comm_semigroup A] [has_one A] (a b t s: A)\n        (H : (a + b) = t) (H2 : add1 t = s) : bit1 a + bit1 b = bit0 s :=\nby inst_simp\n\ntheorem bin_add_zero [add_monoid A] (a : A) : a + zero = a :=\nby simp\n\ntheorem bin_zero_add [add_monoid A] (a : A) : zero + a = a :=\nby simp\n\ntheorem one_add_bit0 [add_comm_semigroup A] [has_one A] (a : A) : one + bit0 a = bit1 a :=\nby simp\n\ntheorem bit0_add_one [has_add A] [has_one A] (a : A) : bit0 a + one = bit1 a :=\nrfl\n\ntheorem bit1_add_one [has_add A] [has_one A] (a : A) : bit1 a + one = add1 (bit1 a) :=\nrfl\n\ntheorem bit1_add_one_helper [has_add A] [has_one A] (a t : A) (H : add1 (bit1 a) = t) :\n        bit1 a + one = t :=\nby inst_simp\n\ntheorem one_add_bit1 [add_comm_semigroup A] [has_one A] (a : A) : one + bit1 a = add1 (bit1 a) :=\nby simp\n\ntheorem one_add_bit1_helper [add_comm_semigroup A] [has_one A] (a t : A)\n        (H : add1 (bit1 a) = t) : one + bit1 a = t :=\nby inst_simp\n\ntheorem add1_bit0 [has_add A] [has_one A] (a : A) : add1 (bit0 a) = bit1 a :=\nrfl\n\ntheorem add1_bit1 [add_comm_semigroup A] [has_one A] (a : A) :\n        add1 (bit1 a) = bit0 (add1 a) :=\nby simp\n\ntheorem add1_bit1_helper [add_comm_semigroup A] [has_one A] (a t : A) (H : add1 a = t) :\n        add1 (bit1 a) = bit0 t :=\nby inst_simp\n\ntheorem add1_one [has_add A] [has_one A] : add1 (one : A) = bit0 one :=\nrfl\n\ntheorem add1_zero [add_monoid A] [has_one A] : add1 (zero : A) = one :=\nby simp\n\ntheorem one_add_one [has_add A] [has_one A] : (one : A) + one = bit0 one :=\nrfl\n\ntheorem subst_into_sum [has_add A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)\n        (prt : tl + tr = t) : l + r = t :=\nby simp\n\ntheorem neg_zero_helper [add_group A] (a : A) (H : a = 0) : - a = 0 :=\nby simp\n\nend norm_num\n\nattribute [simp]\n  zero_add add_zero one_mul mul_one\n  at simplifier.unit\n\nattribute [simp]\n  neg_neg sub_eq_add_neg\n  at simplifier.neg\n\nattribute [simp]\n  add.assoc add.comm add.left_comm\n  mul.left_comm mul.comm mul.assoc\n  at simplifier.ac\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/algebra/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7273745556291074}}
{"text": "import ..lectures.love04_functional_programming_demo\n\n\n/-! # LoVe Homework 4: Functional Programming\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (2 points): Maps\n\n1.1 (1 point). Complete the following definition. The `map_btree` function\nshould apply its argument `f` to all values of type `\u03b1` stored in the tree and\notherwise preserve the tree's structure. -/\n\ndef map_btree {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) : btree \u03b1 \u2192 btree \u03b2 :=\nsorry\n\n/-! 1.2 (1 point). Prove the following lemma about your `map_btree` function. -/\n\nlemma map_btree_iden {\u03b1 : Type} :\n  \u2200t : btree \u03b1, map_btree (\u03bba, a) t = t :=\nsorry\n\n\n/-! ## Question 2 (4 points): Tail-Recursive Factorials\n\nRecall the definition of the factorial functions: -/\n\n#check fact\n\n/-! 2.1 (2 points). Experienced functional programmers tend to avoid definitions\nsuch as the above, because they lead to a deep call stack. Tail recursion can be\nused to avoid this. Results are accumulated in an argument and returned. This\ncan be optimized by compilers. For factorials, this gives the following\ndefinition: -/\n\ndef accufact : \u2115 \u2192 \u2115 \u2192 \u2115\n| a 0       := a\n| a (n + 1) := accufact ((n + 1) * a) n\n\n/-! Prove that, given 1 as the accumulator `a`, `accufact` computes `fact`.\n\nHint: You will need to prove a generalized version of the statement as a\nseparate lemma or `have`, because the desired property fixes `a` to 1, which\nyields a too weak induction hypothesis. -/\n\nlemma accufact_1_eq_fact (n : \u2115) :\n  accufact 1 n = fact n :=\nsorry\n\n/-! 2.2 (2 points). Prove the same property as above again, this time as a\n\"paper\" proof. Follow the guidelines given in question 1.4 of the exercise. -/\n\n-- enter your paper proof here\n\n\n/-! ## Question 3 (3 points): Gauss's Summation Formula -/\n\n-- `sum_upto f n = f 0 + f 1 + \u22ef + f n`\ndef sum_upto (f : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115\n| 0       := f 0\n| (m + 1) := sum_upto m + f (m + 1)\n\n/-! 3.1 (2 point). Prove the following lemma, discovered by Carl Friedrich Gauss\nas a pupil.\n\nHint: The `mul_add` and `add_mul` lemmas might be useful to reason about\nmultiplication. -/\n\n#check mul_add\n#check add_mul\n\nlemma sum_upto_eq :\n  \u2200m : \u2115, 2 * sum_upto (\u03bbi, i) m = m * (m + 1) :=\nsorry\n\n/-! 3.2 (1 point). Prove the following property of `sum_upto`. -/\n\nlemma sum_upto_mul (f g : \u2115 \u2192 \u2115) :\n  \u2200n : \u2115, sum_upto (\u03bbi, f i + g i) n = sum_upto f n + sum_upto g n :=\nsorry\n\n\n\n\n/-! # Question 4: Heterogeneous Lists (6 points)\nWe've become familiar with `list`s, which contain multiple ordered values of the\nsame type. But what if we want to store values of different types? Can this be\ndone in a type-safe way?\n\nYes! Below we define `hlist`, a type of *heterogeneous lists*. While `list` is\nparametrized by a single type (e.g., a `list string` contains `string`s, and a\n`list bool` contains `bools`), `hlist` is parametrized by a *list* of types.\nEach element of this type-level list defines the type of the entry at the same\nposition in the `hlist`. For instance, an `hlist [\u2115, string, bool]` contains a\nnatural number in the first position, a string in the second position, and a\nboolean in the third position. Be sure you see how this achieved by the\nfollowing inductive definition. -/\n\ninductive hlist : list Type \u2192 Type 1\n| nil : hlist []\n| cons {\u03b1 : Type} {\u03b1s : list Type} : \u03b1 \u2192 hlist \u03b1s \u2192 hlist (\u03b1 :: \u03b1s)\n\n-- This is notation to let us succinctly write `hlist`s. Note that this notation\n-- cannot be used when pattern-matching.\nlocal notation `H[]` := hlist.nil\nlocal notation `H[` l:(foldr `,` (h t, hlist.cons h t) hlist.nil) `]` := l\n\n#check H[]\n#check H[9, \"hello\", tt]\n#check H[(\"value\", 4), (\u03bb x, x + 1)]\n\n/-! If we write a function that adds, removes, or changes the types of elements\nin an `hlist`, therefore, we must also reflect these changes at the type level.\nFor instance, consider the function `hlist.snoc` (which appends an element to\nthe end of an `hlist`) below. Notice the parallel between the type it returns\nand the structure of the data it returns! -/\n\n-- Note: for reasons that may become clearer later in this question, the type\n-- index variable `\u03b1s : list Type` can't go before the colon (i.e., we can't\n-- parametrize `snoc` over `\u03b1s`). Instead, we take `\u03b1s` as an argument to the\n-- function and simply \"ignore\" it when pattern-matching by using an underscore.\ndef hlist.snoc {\u03b1 : Type} : \u2200 {\u03b1s : list Type}, hlist \u03b1s \u2192 \u03b1 \u2192 hlist (\u03b1s ++ [\u03b1])\n| _ hlist.nil         y := hlist.cons y hlist.nil\n| _ (hlist.cons x xs) y := hlist.cons x (hlist.snoc xs y)\n\n#check hlist.snoc H[14, tt] 52\n#reduce hlist.snoc H[14, tt] 52\n\n/-! 4.1 (1 point). Write a function `append` that appends two `hlist`s together.\nYou'll need to complete the type as well as implement the function!\n\nNote: when you're testing a function that returns an `hlist`, you'll need to use\n`#reduce` instead of `#eval` (for complicated reasons). Therefore, you'll want\nto avoid writing tests using types that are difficult for the kernel to compute\nwith, such as `string` and `char`. -/\n\ndef hlist.append : \u2200 {\u03b1s \u03b2s : list Type}, hlist \u03b1s \u2192 hlist \u03b2s \u2192 sorry :=\nsorry\n\n\n/-! Heterogeneous lists can be used in conjunction with traditional lists to\nstore multi-typed tabular data (similar to Pyret, for those who are familiar).\nWe can think of some `\u03b1s : list Type` as indicating the type stored in each\ncolumn and an `hlist \u03b1s` as a row. Since every row contains the same types as\nthe others, a collection of such rows would simply be a list of values of type\n`hlist \u03b1s`. Therefore, a table, which is a collection of rows, is represented\nby a value of type `list (hlist \u03b1s)`. For instance, the following table is\nrepresented by a `list (hlist [string, string, nat])`:\n\n------------------------------\n| \"Providence\" | \"RI\" | 2912 |\n| \"Pawtucket\"  | \"RI\" | 2860 |\n| \"Boston\"     | \"MA\" | 2110 |\n------------------------------\n\nBut we can also think of a table as a collection of columns: each column\ncontains data of a single type and so is a traditional `list`, but since each\ncolumn has a different type, the collection of all the columns must be an\n`hlist`. For instance, the column-wise representation of the above would have\ntype `hlist [list string, list string, list nat]`.\n\nSince these representations are storing equivalent data, it would be useful to\nbe able to convert between them. This conversion will be our focus for the rest\nof this question.\n\n4.2 (1 point). Let `\u03b1s : list Type` represent the types stored in a given row of\na table with row-wise representation of type `list (hlist \u03b1s)`. Write a function\nthat produces some `\u03b2s : list Type` such that `hlist \u03b2s` is the type of the\ncolumn-wise representation of that same table. -/\n\ndef columnwise_type (\u03b1s : list Type) : list Type :=\nsorry\n\n/-! 4.3 (2 points). Now that we can state its type, implement the function\n`list_hlist_to_hlist_list` that converts the row-wise representation of a table\ninto a column-wise representation.\n\nHint: In prior problems, we've simply been ignoring `\u03b1s` when pattern-matching.\nHere, however, you may find it useful to pattern-match on it! -/\n\n-- You may use these helper functions in your solution\ndef hlist.hd {\u03b1 \u03b1s} : hlist (\u03b1 :: \u03b1s) \u2192 \u03b1\n| (hlist.cons x _) := x\n\ndef hlist.tl {\u03b1 \u03b1s} : hlist (\u03b1 :: \u03b1s) \u2192 hlist \u03b1s\n| (hlist.cons _ xs) := xs\n\ndef list_hlist_to_hlist_list :\n  \u2200 {\u03b1s : list Type}, list (hlist \u03b1s) \u2192 hlist (columnwise_type \u03b1s) :=\nsorry\n\n\n/-! But what about the other direction? We might be tempted to declare a\nfunction that turns a collection of columns into a collection of rows. That\nfunction might have this signature: -/\n\nconstant hlist_list_to_list_hlist :\n  \u2200 {\u03b1s : list Type}, hlist (columnwise_type \u03b1s) \u2192 list (hlist \u03b1s)\n\n/-! We can describe the type of behavior we expect this function to have. For\ninstance, if we have a table that consists of a single cell, we'd expect to get\nback a table with a single cell: -/\naxiom hllh_singleton :\n  \u2200 (\u03c4 : Type) (hl : hlist (columnwise_type [\u03c4])),\n    \u2203 v : \u03c4, @hlist_list_to_list_hlist [\u03c4] hl = [H[v]]\n\n/- 4.4 (1 point). But, in fact, we cannot define a function with this behavior!\nShow that we can obtain `false` using the above declarations. -/\n\n-- Hint: You will likely find `empty.elim` helpful\n#check @empty.elim\n\ntheorem false_via_hllh : false :=\nsorry\n\n\n/-! 4.5 (1 point). In fact, there is only one function with type\n`\u2200 {\u03b1s : list Type}, hlist (\u03b1s.map list) \u2192 list (hlist \u03b1s)`,\nand it does not satisfy the property in `hllh_singleton`. Describe this\nfunction's behavior and why it is the only function with this type. Then explain\nwhat we would need to be able to assume about the argument to\n`hlist_list_to_list_hlist` in order to create a function that inverts the\nrow-column representation as we desire. -/\n\n/-\nWrite your answer to part 7 here.\n-/\n\n\n\n/-! A final note! This is not the only possible encoding of a heterogeneous\nlist. Below, we declare a type `hlist'` that stores heterogeneously typed data\nbut does *not* contain any data about the types it contains at type level. We\nalso declare a function `hlist'.append` that appends two heterogeneous lists of\nthis type. -/\n\ninductive hlist'\n| nil : hlist'\n| cons {\u03b1 : Type} : \u03b1 \u2192 hlist' \u2192 hlist'\n\ndef hlist'.append : hlist' \u2192 hlist' \u2192 hlist'\n| hlist'.nil ys := ys\n| (hlist'.cons x xs) ys := hlist'.cons x (hlist'.append xs ys)\n\n/-! \n\nFood for thought: what are some pros and cons of this approach compared to\n`hlist`? (How easy is each to declare? To extract data from? How confident\nare you that each `append` function is correct by virtue of the fact that it\ntype-checks?)\n\nWe won't be grading your answers here, but if you'd like to share your thoughts,\nwe're happy to read them!\n\n-/\n\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/homework/love04_functional_programming_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835248143776, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.7273696815163424}}
{"text": "constants p q : Prop \n\ntheorem t1 : p \u2192 q \u2192 p := \u03bb hp : p, \u03bb hq : q, hp\n#check t1\n#print t1\n\ntheorem t1' : p \u2192 q \u2192 p :=\nassume hp : p,\nassume hq : q,\nhp\n#print t1\n\ntheorem t1'' : p \u2192 q \u2192 p :=\nassume hp : p,\nassume hq : q,\nshow p, from hp\n#print t1''\n\nlemma t1l : p \u2192 q \u2192 p :=\nassume hp : p,\nassume hq : q,\nshow p, from hp\n#check t1l\n#print t1l \n\ntheorem t1f (hp : p) (hq : q) : p := hp\n#check t1f\n#print t1f\n\naxiom hp : p\n\ntheorem t2 : q \u2192 p := t1 hp\n#check t2\n#print t2\n\ntheorem t1g (p q : Prop) (hp : p) (hq : q) : p : hp\n#check t1g\n\ntheorem t1g' : \u2200 (p q : Prop), p \u2192 q \u2192 p := \n\u03bb (p q : Prop) (hp : p) (hq : q), hp\n#check \u2200 (p q : Prop), p \u2192 q \u2192 p\n#check \u03bb (p q : Prop) (hp : p) (hq : q), hp\n#check t1g'\n#print t1g'\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/03-Propositions-and-Proofs/example-3.2-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.8354835432479663, "lm_q1q2_score": 0.7273696793314072}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning, Jireh Loreaux\n-/\nimport group_theory.subsemigroup.center\n\n/-!\n# Centralizers of magmas and semigroups\n\n## Main definitions\n\n* `set.centralizer`: the centralizer of a subset of a magma\n* `subsemigroup.centralizer`: the centralizer of a subset of a semigroup\n* `set.add_centralizer`: the centralizer of a subset of an additive magma\n* `add_subsemigroup.centralizer`: the centralizer of a subset of an additive semigroup\n\nWe provide `monoid.centralizer`, `add_monoid.centralizer`, `subgroup.centralizer`, and\n`add_subgroup.centralizer` in other files.\n-/\n\nvariables {M : Type*} {S T : set M}\n\nnamespace set\n\nvariables (S)\n\n/-- The centralizer of a subset of a magma. -/\n@[to_additive add_centralizer /-\" The centralizer of a subset of an additive magma. \"-/]\ndef centralizer [has_mul M] : set M := {c | \u2200 m \u2208 S, m * c = c * m}\n\nvariables {S}\n\n@[to_additive mem_add_centralizer]\nlemma mem_centralizer_iff [has_mul M] {c : M} : c \u2208 centralizer S \u2194 \u2200 m \u2208 S, m * c = c * m :=\niff.rfl\n\n@[to_additive decidable_mem_add_centralizer]\ninstance decidable_mem_centralizer [has_mul M] [decidable_eq M] [fintype M]\n  [decidable_pred (\u2208 S)] : decidable_pred (\u2208 centralizer S) :=\n\u03bb _, decidable_of_iff' _ (mem_centralizer_iff)\n\nvariables (S)\n\n@[simp, to_additive zero_mem_add_centralizer]\nlemma one_mem_centralizer [mul_one_class M] : (1 : M) \u2208 centralizer S :=\nby simp [mem_centralizer_iff]\n\n@[simp]\nlemma zero_mem_centralizer [mul_zero_class M] : (0 : M) \u2208 centralizer S :=\nby simp [mem_centralizer_iff]\n\nvariables {S} {a b : M}\n\n@[simp, to_additive add_mem_add_centralizer]\nlemma mul_mem_centralizer [semigroup M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a * b \u2208 centralizer S :=\n\u03bb g hg, by rw [mul_assoc, \u2190hb g hg, \u2190 mul_assoc, ha g hg, mul_assoc]\n\n@[simp, to_additive neg_mem_add_centralizer]\nlemma inv_mem_centralizer [group M] (ha : a \u2208 centralizer S) : a\u207b\u00b9 \u2208 centralizer S :=\n\u03bb g hg, by rw [mul_inv_eq_iff_eq_mul, mul_assoc, eq_inv_mul_iff_mul_eq, ha g hg]\n\n@[simp]\nlemma add_mem_centralizer [distrib M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a + b \u2208 centralizer S :=\n\u03bb c hc, by rw [add_mul, mul_add, ha c hc, hb c hc]\n\n@[simp]\nlemma neg_mem_centralizer [has_mul M] [has_distrib_neg M] (ha : a \u2208 centralizer S) :\n  -a \u2208 centralizer S :=\n\u03bb c hc, by rw [mul_neg, ha c hc, neg_mul]\n\n@[simp]\nlemma inv_mem_centralizer\u2080 [group_with_zero M] (ha : a \u2208 centralizer S) : a\u207b\u00b9 \u2208 centralizer S :=\n(eq_or_ne a 0).elim (\u03bb h, by { rw [h, inv_zero], exact zero_mem_centralizer S })\n  (\u03bb ha0 c hc, by rw [mul_inv_eq_iff_eq_mul\u2080 ha0, mul_assoc, eq_inv_mul_iff_mul_eq\u2080 ha0, ha c hc])\n\n@[simp, to_additive sub_mem_add_centralizer]\nlemma div_mem_centralizer [group M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a / b \u2208 centralizer S :=\nbegin\n  rw [div_eq_mul_inv],\n  exact mul_mem_centralizer ha (inv_mem_centralizer hb),\nend\n\n@[simp]\nlemma div_mem_centralizer\u2080 [group_with_zero M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a / b \u2208 centralizer S :=\nbegin\n  rw div_eq_mul_inv,\n  exact mul_mem_centralizer ha (inv_mem_centralizer\u2080 hb),\nend\n\n@[to_additive add_centralizer_subset]\nlemma centralizer_subset [has_mul M] (h : S \u2286 T) : centralizer T \u2286 centralizer S :=\n\u03bb t ht s hs, ht s (h hs)\n\nvariables (M)\n\n@[simp, to_additive add_centralizer_univ]\nlemma centralizer_univ [has_mul M] : centralizer univ = center M :=\nsubset.antisymm (\u03bb a ha b, ha b (set.mem_univ b)) (\u03bb a ha b hb, ha b)\n\nvariables {M} (S)\n\n@[simp, to_additive add_centralizer_eq_univ]\nlemma centralizer_eq_univ [comm_semigroup M] : centralizer S = univ :=\nsubset.antisymm (subset_univ _) $ \u03bb x hx y hy, mul_comm y x\n\nend set\n\nnamespace subsemigroup\nsection\nvariables {M} [semigroup M] (S)\n\n/-- The centralizer of a subset of a semigroup `M`. -/\n@[to_additive \"The centralizer of a subset of an additive semigroup.\"]\ndef centralizer : subsemigroup M :=\n{ carrier := S.centralizer,\n  mul_mem' := \u03bb a b, set.mul_mem_centralizer }\n\n@[simp, norm_cast, to_additive] lemma coe_centralizer : \u2191(centralizer S) = S.centralizer := rfl\n\nvariables {S}\n\n@[to_additive] lemma mem_centralizer_iff {z : M} : z \u2208 centralizer S \u2194 \u2200 g \u2208 S, g * z = z * g :=\niff.rfl\n\n@[to_additive] instance decidable_mem_centralizer [decidable_eq M] [fintype M]\n  [decidable_pred (\u2208 S)] : decidable_pred (\u2208 centralizer S) :=\n\u03bb _, decidable_of_iff' _ mem_centralizer_iff\n\n@[to_additive]\nlemma centralizer_le (h : S \u2286 T) : centralizer T \u2264 centralizer S :=\nset.centralizer_subset h\n\nvariables (M)\n\n@[simp, to_additive]\nlemma centralizer_univ : centralizer set.univ = center M :=\nset_like.ext' (set.centralizer_univ M)\n\nend\n\nend subsemigroup\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/group_theory/subsemigroup/centralizer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7273596895947696}}
{"text": "/-\nCopyright (c) 2018 Jan-David Salchow. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jan-David Salchow, Patrick Massot\n-/\nimport topology.bases\nimport topology.subset_properties\nimport topology.metric_space.basic\n\n/-!\n# Sequences in topological spaces\n\nIn this file we define sequences in topological spaces and show how they are related to\nfilters and the topology. In particular, we\n* define the sequential closure of a set and prove that it's contained in the closure,\n* define a type class \"sequential_space\" in which closure and sequential closure agree,\n* define sequential continuity and show that it coincides with continuity in sequential spaces,\n* provide an instance that shows that every first-countable (and in particular metric) space is\n  a sequential space.\n* define sequential compactness, prove that compactness implies sequential compactness in first\n  countable spaces, and prove they are equivalent for uniform spaces having a countable uniformity\n  basis (in particular metric spaces).\n-/\n\nopen set filter\nopen_locale topological_space\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n\nlocal notation f ` \u27f6 ` limit := tendsto f at_top (\ud835\udcdd limit)\n\n/-! ### Sequential closures, sequential continuity, and sequential spaces. -/\nsection topological_space\nvariables [topological_space \u03b1] [topological_space \u03b2]\n\n/-- A sequence converges in the sence of topological spaces iff the associated statement for filter\nholds. -/\nlemma topological_space.seq_tendsto_iff {x : \u2115 \u2192 \u03b1} {limit : \u03b1} :\n  tendsto x at_top (\ud835\udcdd limit) \u2194\n    \u2200 U : set \u03b1, limit \u2208 U \u2192 is_open U \u2192 \u2203 N, \u2200 n \u2265 N, (x n) \u2208 U :=\n(at_top_basis.tendsto_iff (nhds_basis_opens limit)).trans $\n  by simp only [and_imp, exists_prop, true_and, set.mem_Ici, ge_iff_le, id]\n\n/-- The sequential closure of a subset M \u2286 \u03b1 of a topological space \u03b1 is\nthe set of all p \u2208 \u03b1 which arise as limit of sequences in M. -/\ndef sequential_closure (M : set \u03b1) : set \u03b1 :=\n{p | \u2203 x : \u2115 \u2192 \u03b1, (\u2200 n : \u2115, x n \u2208 M) \u2227 (x \u27f6 p)}\n\nlemma subset_sequential_closure (M : set \u03b1) : M \u2286 sequential_closure M :=\nassume p (_ : p \u2208 M), show p \u2208 sequential_closure M, from\n  \u27e8\u03bb n, p, assume n, \u2039p \u2208 M\u203a, tendsto_const_nhds\u27e9\n\n/-- A set `s` is sequentially closed if for any converging sequence `x n` of elements of `s`,\nthe limit belongs to `s` as well. -/\ndef is_seq_closed (s : set \u03b1) : Prop := s = sequential_closure s\n\n/-- A convenience lemma for showing that a set is sequentially closed. -/\nlemma is_seq_closed_of_def {A : set \u03b1}\n  (h : \u2200(x : \u2115 \u2192 \u03b1) (p : \u03b1), (\u2200 n : \u2115, x n \u2208 A) \u2192 (x \u27f6 p) \u2192 p \u2208 A) : is_seq_closed A :=\nshow A = sequential_closure A, from subset.antisymm\n  (subset_sequential_closure A)\n  (show \u2200 p, p \u2208 sequential_closure A \u2192 p \u2208 A, from\n    (assume p \u27e8x, _, _\u27e9, show p \u2208 A, from h x p \u2039\u2200 n : \u2115, ((x n) \u2208 A)\u203a \u2039(x \u27f6 p)\u203a))\n\n/-- The sequential closure of a set is contained in the closure of that set.\nThe converse is not true. -/\nlemma sequential_closure_subset_closure (M : set \u03b1) : sequential_closure M \u2286 closure M :=\nassume p \u27e8x, xM, xp\u27e9,\nmem_closure_of_tendsto xp (univ_mem_sets' xM)\n\n/-- A set is sequentially closed if it is closed. -/\nlemma is_seq_closed_of_is_closed (M : set \u03b1) (_ : is_closed M) : is_seq_closed M :=\nsuffices sequential_closure M \u2286 M, from\n  set.eq_of_subset_of_subset (subset_sequential_closure M) this,\ncalc sequential_closure M \u2286 closure M : sequential_closure_subset_closure M\n  ... = M : is_closed.closure_eq \u2039is_closed M\u203a\n\n/-- The limit of a convergent sequence in a sequentially closed set is in that set.-/\nlemma mem_of_is_seq_closed {A : set \u03b1} (_ : is_seq_closed A) {x : \u2115 \u2192 \u03b1}\n  (_ : \u2200 n, x n \u2208 A) {limit : \u03b1} (_ : (x \u27f6 limit)) : limit \u2208 A :=\nhave limit \u2208 sequential_closure A, from\n  show \u2203 x : \u2115 \u2192 \u03b1, (\u2200 n : \u2115, x n \u2208 A) \u2227 (x \u27f6 limit), from \u27e8x, \u2039\u2200 n, x n \u2208 A\u203a, \u2039(x \u27f6 limit)\u203a\u27e9,\neq.subst (eq.symm \u2039is_seq_closed A\u203a) \u2039limit \u2208 sequential_closure A\u203a\n\n/-- The limit of a convergent sequence in a closed set is in that set.-/\nlemma mem_of_is_closed_sequential {A : set \u03b1} (_ : is_closed A) {x : \u2115 \u2192 \u03b1}\n  (_ : \u2200 n, x n \u2208 A) {limit : \u03b1} (_ : x \u27f6 limit) : limit \u2208 A :=\nmem_of_is_seq_closed (is_seq_closed_of_is_closed A \u2039is_closed A\u203a) \u2039\u2200 n, x n \u2208 A\u203a \u2039(x \u27f6 limit)\u203a\n\n/-- A sequential space is a space in which 'sequences are enough to probe the topology'. This can be\n formalised by demanding that the sequential closure and the closure coincide. The following\n statements show that other topological properties can be deduced from sequences in sequential\n spaces. -/\nclass sequential_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(sequential_closure_eq_closure : \u2200 M : set \u03b1, sequential_closure M = closure M)\n\n/-- In a sequential space, a set is closed iff it's sequentially closed. -/\nlemma is_seq_closed_iff_is_closed [sequential_space \u03b1] {M : set \u03b1} :\n  is_seq_closed M \u2194 is_closed M :=\niff.intro\n  (assume _, closure_eq_iff_is_closed.mp (eq.symm\n    (calc M = sequential_closure M : by assumption\n        ... = closure M            : sequential_space.sequential_closure_eq_closure M)))\n  (is_seq_closed_of_is_closed M)\n\n/-- In a sequential space, a point belongs to the closure of a set iff it is a limit of a sequence\ntaking values in this set. -/\nlemma mem_closure_iff_seq_limit [sequential_space \u03b1] {s : set \u03b1} {a : \u03b1} :\n  a \u2208 closure s \u2194 \u2203 x : \u2115 \u2192 \u03b1, (\u2200 n : \u2115, x n \u2208 s) \u2227 (x \u27f6 a) :=\nby { rw \u2190 sequential_space.sequential_closure_eq_closure, exact iff.rfl }\n\n/-- A function between topological spaces is sequentially continuous if it commutes with limit of\n convergent sequences. -/\ndef sequentially_continuous (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 (x : \u2115 \u2192 \u03b1), \u2200 {limit : \u03b1}, (x \u27f6 limit) \u2192 (f\u2218x \u27f6 f limit)\n\n/- A continuous function is sequentially continuous. -/\nlemma continuous.to_sequentially_continuous {f : \u03b1 \u2192 \u03b2} (_ : continuous f) :\n  sequentially_continuous f :=\nassume x limit (_ : x \u27f6 limit),\nhave tendsto f (\ud835\udcdd limit) (\ud835\udcdd (f limit)), from continuous.tendsto \u2039continuous f\u203a limit,\nshow (f \u2218 x) \u27f6 (f limit), from tendsto.comp this \u2039(x \u27f6 limit)\u203a\n\n/-- In a sequential space, continuity and sequential continuity coincide. -/\nlemma continuous_iff_sequentially_continuous {f : \u03b1 \u2192 \u03b2} [sequential_space \u03b1] :\n  continuous f \u2194 sequentially_continuous f :=\niff.intro\n  (assume _, \u2039continuous f\u203a.to_sequentially_continuous)\n  (assume : sequentially_continuous f, show continuous f, from\n    suffices h : \u2200 {A : set \u03b2}, is_closed A \u2192 is_seq_closed (f \u207b\u00b9' A), from\n      continuous_iff_is_closed.mpr (assume A _, is_seq_closed_iff_is_closed.mp $ h \u2039is_closed A\u203a),\n    assume A (_ : is_closed A),\n      is_seq_closed_of_def $\n        assume (x : \u2115 \u2192 \u03b1) p (_ : \u2200 n, f (x n) \u2208 A) (_ : x \u27f6 p),\n        have (f \u2218 x) \u27f6 (f p), from \u2039sequentially_continuous f\u203a x \u2039(x \u27f6 p)\u203a,\n        show f p \u2208 A, from\n          mem_of_is_closed_sequential \u2039is_closed A\u203a \u2039\u2200 n, f (x n) \u2208 A\u203a \u2039(f\u2218x \u27f6 f p)\u203a)\n\nend topological_space\n\nnamespace topological_space\n\nnamespace first_countable_topology\n\nvariables [topological_space \u03b1] [first_countable_topology \u03b1]\n\n/-- Every first-countable space is sequential. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance : sequential_space \u03b1 :=\n\u27e8show \u2200 M, sequential_closure M = closure M, from assume M,\n  suffices closure M \u2286 sequential_closure M,\n    from set.subset.antisymm (sequential_closure_subset_closure M) this,\n  -- For every p \u2208 closure M, we need to construct a sequence x in M that converges to p:\n  assume (p : \u03b1) (hp : p \u2208 closure M),\n  -- Since we are in a first-countable space, the neighborhood filter around `p` has a decreasing\n  -- basis `U` indexed by `\u2115`.\n  let \u27e8U, hU\u27e9 := (nhds_generated_countable p).exists_antimono_basis in\n  -- Since `p \u2208 closure M`, there is an element in each `M \u2229 U i`\n  have hp : \u2200 (i : \u2115), \u2203 (y : \u03b1), y \u2208 M \u2227 y \u2208 U i,\n    by simpa using (mem_closure_iff_nhds_basis hU.1).mp hp,\n  begin\n    -- The axiom of (countable) choice builds our sequence from the later fact\n    choose u hu using hp,\n    rw forall_and_distrib at hu,\n    -- It clearly takes values in `M`\n    use [u, hu.1],\n    -- and converges to `p` because the basis is decreasing.\n    apply hU.tendsto hu.2,\n  end\u27e9\n\n\nend first_countable_topology\n\nend topological_space\n\nsection seq_compact\nopen topological_space topological_space.first_countable_topology\nvariables [topological_space \u03b1]\n\n/-- A set `s` is sequentially compact if every sequence taking values in `s` has a\nconverging subsequence. -/\ndef is_seq_compact (s : set \u03b1) :=\n  \u2200 \u2983u : \u2115 \u2192 \u03b1\u2984, (\u2200 n, u n \u2208 s) \u2192\n    \u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x)\n\n/-- A space `\u03b1` is sequentially compact if every sequence in `\u03b1` has a\nconverging subsequence. -/\nclass seq_compact_space (\u03b1 : Type*) [topological_space \u03b1] : Prop :=\n(seq_compact_univ : is_seq_compact (univ : set \u03b1))\n\nlemma is_seq_compact.subseq_of_frequently_in {s : set \u03b1} (hs : is_seq_compact s) {u : \u2115 \u2192 \u03b1}\n  (hu : \u2203\u1da0 n in at_top, u n \u2208 s) :\n  \u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nlet \u27e8\u03c8, h\u03c8, hu\u03c8\u27e9 := extraction_of_frequently_at_top hu, \u27e8x, x_in, \u03c6, h\u03c6, h\u27e9 := hs hu\u03c8 in\n\u27e8x, x_in, \u03c8 \u2218 \u03c6, h\u03c8.comp h\u03c6, h\u27e9\n\nlemma seq_compact_space.tendsto_subseq [seq_compact_space \u03b1] (u : \u2115 \u2192 \u03b1) :\n  \u2203 x (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nlet \u27e8x, _, \u03c6, mono, h\u27e9 := seq_compact_space.seq_compact_univ (by simp : \u2200 n, u n \u2208 univ) in\n\u27e8x, \u03c6, mono, h\u27e9\n\nsection first_countable_topology\nvariables [first_countable_topology \u03b1]\nopen topological_space.first_countable_topology\n\nlemma is_compact.is_seq_compact {s : set \u03b1} (hs : is_compact s) : is_seq_compact s :=\n\u03bb u u_in,\nlet \u27e8x, x_in, hx\u27e9 := @hs (map u at_top) _\n  (le_principal_iff.mpr (univ_mem_sets' u_in : _)) in \u27e8x, x_in, tendsto_subseq hx\u27e9\n\nlemma is_compact.tendsto_subseq' {s : set \u03b1} {u : \u2115 \u2192 \u03b1} (hs : is_compact s)\n  (hu : \u2203\u1da0 n in at_top, u n \u2208 s) :\n\u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nhs.is_seq_compact.subseq_of_frequently_in hu\n\nlemma is_compact.tendsto_subseq {s : set \u03b1} {u : \u2115 \u2192 \u03b1} (hs : is_compact s) (hu : \u2200 n, u n \u2208 s) :\n\u2203 (x \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nhs.is_seq_compact hu\n\n@[priority 100] -- see Note [lower instance priority]\ninstance first_countable_topology.seq_compact_of_compact [compact_space \u03b1] : seq_compact_space \u03b1 :=\n\u27e8compact_univ.is_seq_compact\u27e9\n\nlemma compact_space.tendsto_subseq [compact_space \u03b1] (u : \u2115 \u2192 \u03b1) :\n  \u2203 x (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd x) :=\nseq_compact_space.tendsto_subseq u\n\nend first_countable_topology\nend seq_compact\n\nsection uniform_space_seq_compact\n\nopen_locale uniformity\nopen uniform_space prod\n\nvariables [uniform_space \u03b2] {s : set \u03b2}\n\nlemma lebesgue_number_lemma_seq {\u03b9 : Type*} {c : \u03b9 \u2192 set \u03b2}\n  (hs : is_seq_compact s) (hc\u2081 : \u2200 i, is_open (c i)) (hc\u2082 : s \u2286 \u22c3 i, c i)\n  (hU : is_countably_generated (\ud835\udce4 \u03b2)) :\n  \u2203 V \u2208 \ud835\udce4 \u03b2, symmetric_rel V \u2227 \u2200 x \u2208 s, \u2203 i, ball x V \u2286 c i :=\nbegin\n  classical,\n  obtain \u27e8V, hV, Vsymm\u27e9 :\n    \u2203 V : \u2115 \u2192 set (\u03b2 \u00d7 \u03b2), (\ud835\udce4 \u03b2).has_antimono_basis (\u03bb _, true) V \u2227  \u2200 n, swap \u207b\u00b9' V n = V n,\n      from uniform_space.has_seq_basis hU, clear hU,\n  suffices : \u2203 n, \u2200 x \u2208 s, \u2203 i, ball x (V n) \u2286 c i,\n  { cases this with n hn,\n    exact \u27e8V n, hV.to_has_basis.mem_of_mem trivial, Vsymm n, hn\u27e9 },\n  by_contradiction H,\n  obtain \u27e8x, x_in, hx\u27e9 : \u2203 x : \u2115 \u2192 \u03b2, (\u2200 n, x n \u2208 s) \u2227 \u2200 n i, \u00ac ball (x n) (V n) \u2286 c i,\n  { push_neg at H,\n    choose x hx using H,\n    exact \u27e8x, forall_and_distrib.mp hx\u27e9 }, clear H,\n  obtain \u27e8x\u2080, x\u2080_in, \u03c6, \u03c6_mono, hlim\u27e9 : \u2203 (x\u2080 \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 (x \u2218 \u03c6 \u27f6 x\u2080),\n    from hs x_in, clear hs,\n  obtain \u27e8i\u2080, x\u2080_in\u27e9 : \u2203 i\u2080, x\u2080 \u2208 c i\u2080,\n  { rcases hc\u2082 x\u2080_in with \u27e8_, \u27e8i\u2080, rfl\u27e9, x\u2080_in_c\u27e9,\n    exact \u27e8i\u2080, x\u2080_in_c\u27e9 }, clear hc\u2082,\n  obtain \u27e8n\u2080, hn\u2080\u27e9 : \u2203 n\u2080, ball x\u2080 (V n\u2080) \u2286 c i\u2080,\n  { rcases (nhds_basis_uniformity hV.to_has_basis).mem_iff.mp\n      (is_open_iff_mem_nhds.mp (hc\u2081 i\u2080) _ x\u2080_in) with \u27e8n\u2080, _, h\u27e9,\n    use n\u2080,\n    rwa \u2190 ball_eq_of_symmetry (Vsymm n\u2080) at h }, clear hc\u2081,\n  obtain \u27e8W, W_in, hWW\u27e9 : \u2203 W \u2208 \ud835\udce4 \u03b2, W \u25cb W \u2286 V n\u2080,\n    from comp_mem_uniformity_sets (hV.to_has_basis.mem_of_mem trivial),\n  obtain \u27e8N, x_\u03c6_N_in, hVNW\u27e9 : \u2203 N, x (\u03c6 N) \u2208 ball x\u2080 W \u2227 V (\u03c6 N) \u2286 W,\n  { obtain \u27e8N\u2081, h\u2081\u27e9 : \u2203 N\u2081, \u2200 n \u2265 N\u2081, x (\u03c6 n) \u2208 ball x\u2080 W,\n      from tendsto_at_top'.mp hlim _ (mem_nhds_left x\u2080 W_in),\n    obtain \u27e8N\u2082, h\u2082\u27e9 : \u2203 N\u2082, V (\u03c6 N\u2082) \u2286 W,\n    { rcases hV.to_has_basis.mem_iff.mp W_in with \u27e8N, _, hN\u27e9,\n      use N,\n      exact subset.trans (hV.decreasing trivial trivial $  \u03c6_mono.id_le _) hN },\n    have : \u03c6 N\u2082 \u2264 \u03c6 (max N\u2081 N\u2082),\n      from \u03c6_mono.le_iff_le.mpr (le_max_right _ _),\n    exact \u27e8max N\u2081 N\u2082, h\u2081 _ (le_max_left _ _), trans (hV.decreasing trivial trivial this) h\u2082\u27e9 },\n  suffices : ball (x (\u03c6 N)) (V (\u03c6 N)) \u2286 c i\u2080,\n    from hx (\u03c6 N) i\u2080 this,\n  calc\n    ball (x $ \u03c6 N) (V $ \u03c6 N) \u2286 ball (x $ \u03c6 N) W : preimage_mono hVNW\n                         ... \u2286 ball x\u2080 (V n\u2080)   : ball_subset_of_comp_subset x_\u03c6_N_in hWW\n                         ... \u2286 c i\u2080             : hn\u2080,\nend\n\nlemma is_seq_compact.totally_bounded (h : is_seq_compact s) : totally_bounded s :=\nbegin\n  classical,\n  apply totally_bounded_of_forall_symm,\n  unfold is_seq_compact at h,\n  contrapose! h,\n  rcases h with \u27e8V, V_in, V_symm, h\u27e9,\n  simp_rw [not_subset] at h,\n  have : \u2200 (t : set \u03b2), finite t \u2192 \u2203 a, a \u2208 s \u2227 a \u2209 \u22c3 y \u2208 t, ball y V,\n  { intros t ht,\n    obtain \u27e8a, a_in, H\u27e9 : \u2203 a \u2208 s, \u2200 (x : \u03b2), x \u2208 t \u2192 (x, a) \u2209 V,\n      by simpa [ht] using h t,\n    use [a, a_in],\n    intro H',\n    obtain \u27e8x, x_in, hx\u27e9 := mem_bUnion_iff.mp H',\n    exact H x x_in hx },\n  cases seq_of_forall_finite_exists this with u hu, clear h this,\n  simp [forall_and_distrib] at hu,\n  cases hu with u_in hu,\n  use [u, u_in], clear u_in,\n  intros x x_in \u03c6,\n  intros h\u03c6 hu\u03c6,\n  obtain \u27e8N, hN\u27e9 : \u2203 N, \u2200 p q, p \u2265 N \u2192 q \u2265 N \u2192 (u (\u03c6 p), u (\u03c6 q)) \u2208 V,\n    from hu\u03c6.cauchy_seq.mem_entourage V_in,\n  specialize hN N (N+1) (le_refl N) (nat.le_succ N),\n  specialize hu (\u03c6 $ N+1) (\u03c6 N) (h\u03c6 $ lt_add_one N),\n  exact hu hN,\nend\n\nprotected lemma is_seq_compact.is_compact (h : is_countably_generated $ \ud835\udce4 \u03b2)\n  (hs : is_seq_compact s) :\n  is_compact s :=\nbegin\n  classical,\n  rw compact_iff_finite_subcover,\n  intros \u03b9 U Uop s_sub,\n  rcases lebesgue_number_lemma_seq hs Uop s_sub h with \u27e8V, V_in, Vsymm, H\u27e9,\n  rcases totally_bounded_iff_subset.mp hs.totally_bounded V V_in with \u27e8t,t_sub, tfin,  ht\u27e9,\n  have : \u2200 x : t, \u2203 (i : \u03b9), ball x.val V \u2286 U i,\n  { rintros \u27e8x, x_in\u27e9,\n    exact H x (t_sub x_in) },\n  choose i hi using this,\n  haveI : fintype t := tfin.fintype,\n  use finset.image i finset.univ,\n  transitivity \u22c3 y \u2208 t, ball y V,\n  { intros x x_in,\n    specialize ht x_in,\n    rw mem_bUnion_iff at *,\n    simp_rw ball_eq_of_symmetry Vsymm,\n    exact ht },\n  { apply bUnion_subset_bUnion,\n    intros x x_in,\n    exact \u27e8i \u27e8x, x_in\u27e9, finset.mem_image_of_mem _ (finset.mem_univ _), hi \u27e8x, x_in\u27e9\u27e9 },\nend\n\nprotected lemma uniform_space.compact_iff_seq_compact (h : is_countably_generated $ \ud835\udce4 \u03b2) :\n is_compact s \u2194 is_seq_compact s :=\nbegin\n  haveI := uniform_space.first_countable_topology h,\n  exact \u27e8\u03bb H, H.is_seq_compact, \u03bb H, H.is_compact h\u27e9\nend\n\nlemma uniform_space.compact_space_iff_seq_compact_space (H : is_countably_generated $ \ud835\udce4 \u03b2) :\n  compact_space \u03b2 \u2194 seq_compact_space \u03b2 :=\nhave key : is_compact univ \u2194 is_seq_compact univ := uniform_space.compact_iff_seq_compact H,\n\u27e8\u03bb \u27e8h\u27e9, \u27e8key.mp h\u27e9, \u03bb \u27e8h\u27e9, \u27e8key.mpr h\u27e9\u27e9\n\nend uniform_space_seq_compact\n\nsection metric_seq_compact\n\nvariables [metric_space \u03b2] {s : set \u03b2}\nopen metric\n\n/-- A version of Bolzano-Weistrass: in a metric space, is_compact s \u2194 is_seq_compact s -/\nlemma metric.compact_iff_seq_compact : is_compact s \u2194 is_seq_compact s :=\nuniform_space.compact_iff_seq_compact emetric.uniformity_has_countable_basis\n\n/-- A version of Bolzano-Weistrass: in a proper metric space (eg. $\u211d^n$),\nevery bounded sequence has a converging subsequence. This version assumes only\nthat the sequence is frequently in some bounded set. -/\nlemma tendsto_subseq_of_frequently_bounded [proper_space \u03b2] (hs : bounded s)\n  {u : \u2115 \u2192 \u03b2} (hu : \u2203\u1da0 n in at_top, u n \u2208 s) :\n\u2203 b \u2208 closure s, \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd b) :=\nbegin\n  have hcs : is_compact (closure s) :=\n    compact_iff_closed_bounded.mpr \u27e8is_closed_closure, bounded_closure_of_bounded hs\u27e9,\n  replace hcs : is_seq_compact (closure s),\n    by rwa metric.compact_iff_seq_compact at hcs,\n  have hu' : \u2203\u1da0 n in at_top, u n \u2208 closure s,\n  { apply frequently.mono hu,\n    intro n,\n    apply subset_closure },\n  exact hcs.subseq_of_frequently_in hu',\nend\n\n/-- A version of Bolzano-Weistrass: in a proper metric space (eg. $\u211d^n$),\nevery bounded sequence has a converging subsequence. -/\nlemma tendsto_subseq_of_bounded [proper_space \u03b2] (hs : bounded s)\n  {u : \u2115 \u2192 \u03b2} (hu : \u2200 n, u n \u2208 s) :\n\u2203 b \u2208 closure s, \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd b) :=\ntendsto_subseq_of_frequently_bounded hs $ frequently_of_forall hu\n\nlemma metric.compact_space_iff_seq_compact_space : compact_space \u03b2 \u2194 seq_compact_space \u03b2 :=\nuniform_space.compact_space_iff_seq_compact_space emetric.uniformity_has_countable_basis\n\nlemma seq_compact.lebesgue_number_lemma_of_metric\n  {\u03b9 : Type*} {c : \u03b9 \u2192 set \u03b2} (hs : is_seq_compact s)\n  (hc\u2081 : \u2200 i, is_open (c i)) (hc\u2082 : s \u2286 \u22c3 i, c i) :\n  \u2203 \u03b4 > 0, \u2200 x \u2208 s, \u2203 i, ball x \u03b4 \u2286 c i :=\nbegin\n  rcases lebesgue_number_lemma_seq hs hc\u2081 hc\u2082 emetric.uniformity_has_countable_basis\n    with \u27e8V, V_in, _, hV\u27e9,\n  rcases uniformity_basis_dist.mem_iff.mp V_in with \u27e8\u03b4, \u03b4_pos, h\u27e9,\n  use [\u03b4, \u03b4_pos],\n  intros x x_in,\n  rcases hV x x_in with \u27e8i, hi\u27e9,\n  use i,\n  have := ball_mono h x,\n  rw ball_eq_ball' at this,\n  exact subset.trans this hi,\nend\n\nend metric_seq_compact\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/topology/sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7273451128352754}}
{"text": "import tuto_lib\n\n\nsection\n/-\nThe first part of this file makes sure you can negate quantified statements\nin your head without the help of `push_neg`.\n\nYou need to complete the statement and then use the `check_me` tactic\nto check your answer. This tactic exists only for those exercises,\nit mostly calls `push_neg` and then cleans up a bit.\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from \u211d to \u211d\n-- x\u2080 and l are real numbers\nvariables (u : \u2115 \u2192 \u211d) (f : \u211d \u2192 \u211d) (x\u2080 l : \u211d)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5) \u2194\n-- sorry\n\u2203 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |u n - l| > \u03b5\n-- sorry\n:=\nbegin\n  -- sorry\n  check_me,\n  -- sorry\nend\n\n/- Negation of \"f is continuous at x\u2080\" -/\n-- 0063\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192  |f x - f x\u2080| \u2264 \u03b5) \u2194\n-- sorry\n\u2203 \u03b5 > 0, \u2200 \u03b4 > 0, \u2203 x, |x - x\u2080| \u2264 \u03b4 \u2227 |f x - f x\u2080| > \u03b5\n-- sorry\n:=\nbegin\n  -- sorry\n  check_me,\n  -- sorry\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`\u2200 x x', ...` is the abbreviation of\n`\u2200 x, \u2200 x', ... `. \n\nAlso, `\u2203 x x', ...` is the abbreviation of `\u2203 x, \u2203 x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on \u211d\" -/\n-- 0064\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x x', |x' - x| \u2264 \u03b4 \u2192  |f x' - f x| \u2264 \u03b5) \u2194\n-- sorry\n\u2203 \u03b5 > 0, \u2200 \u03b4 > 0, \u2203 x x', |x' - x| \u2264 \u03b4 \u2227 |f x' - f x| > \u03b5\n-- sorry\n:=\nbegin\n  -- sorry\n  check_me,\n  -- sorry\nend\n\n/- Negation of \"f is sequentially continuous at x\u2080\" -/\n-- 0065\nexample : \u00ac (\u2200 u : \u2115 \u2192 \u211d, (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b5) \u2192 (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |(f \u2218 u) n - f x\u2080| \u2264 \u03b5))  \u2194\n-- sorry\n\u2203 u : \u2115 \u2192 \u211d,\n  (\u2200 \u03b4 > 0, \u2203 N, \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b4) \u2227\n  (\u2203 \u03b5 > 0,  \u2200 N, \u2203 n \u2265 N, |f (u n) - f x\u2080| > \u03b5)\n-- sorry\n:=\nbegin\n  -- sorry\n  check_me,\n  -- sorry\nend\nend\n\n/-\nWe now turn to elementary applications of negations to limits of sequences.\nRemember that `linarith` can find easy numerical contradictions.\n\nAlso recall the following lemmas:\n\nabs_le {x y : \u211d} : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\n/-- The sequence `u` tends to `+\u221e`. -/\ndef tendsto_infinity (u : \u2115 \u2192 \u211d) := \u2200 A, \u2203 N, \u2200 n \u2265 N, u n \u2265 A\n-/\n\n-- 0066\nexample {u : \u2115 \u2192 \u211d} : tendsto_infinity u \u2192 \u2200 l, \u00ac seq_limit u l :=\nbegin\n  -- sorry\n  intros lim_infinie l lim_l,\n  cases lim_l 1 (by linarith) with N hN,\n  cases lim_infinie (l+2) with N' hN',\n  let N\u2080 := max N N',\n  specialize hN N\u2080 (le_max_left _ _),\n  specialize hN' N\u2080 (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\n  -- sorry\nend\n\ndef nondecreasing_seq (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- 0067\nexample (u : \u2115 \u2192 \u211d) (l : \u211d) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  \u2200 n, u n \u2264 l :=\nbegin\n  -- sorry\n  intro n,\n  by_contradiction H,\n  push_neg at H,\n  cases h ((u n - l)/2) (by linarith) with N hN,\n  specialize hN (max n N) (le_max_right _ _),\n  specialize h' n (max n N) (le_max_left _ _),\n  rw abs_le at hN,\n  linarith,\n  -- sorry\nend\n\n/-\nIn the following exercises, `A : set \u211d` means that A is a set of real numbers.\nWe can use the usual notation x \u2208 A.\n\nThe notation `\u2200 x \u2208 A, ...` is the abbreviation of `\u2200 x, x \u2208 A \u2192 ... `\n\nThe notation `\u2203 x \u2208 A, ...` is the abbreviation of `\u2203 x, x \u2208 A \u2227 ... `.\nMore precisely it is the abbreviation of `\u2203 x (H : x \u2208 A), ...`\nwhich is Lean's strange way of saying `\u2203 x, x \u2208 A \u2227 ... `. \nYou can convert between these forms using the lemma \n  exists_prop {p q : Prop} : (\u2203 (h : p), q) \u2194 p \u2227 q\n\nWe'll work with upper bounds and supremums.\nAgain we'll introduce specialized definitions for the sake of exercises, but mathlib\nhas more general versions.\n\n\ndef upper_bound (A : set \u211d) (x : \u211d) := \u2200 a \u2208 A, a \u2264 x\n\ndef is_sup (A : set \u211d) (x : \u211d) := upper_bound A x \u2227 \u2200 y, upper_bound A y \u2192 x \u2264 y\n\n\nRemark: one can easily show that a set of real numbers has at most one sup,\nbut we won't need this.\n-/\n\n-- 0068\nexample {A : set \u211d} {x : \u211d} (hx : is_sup A x) :\n\u2200 y, y < x \u2192 \u2203 a \u2208 A, y < a :=\nbegin\n  -- sorry\n  intro y,\n  contrapose!,\n  exact hx.right y,\n  -- sorry\nend\n\n/-\nLet's do a variation on an example from file 07 that will be useful in the last\nexercise below.\n-/\n\n-- 0069\nlemma le_of_le_add_all' {x y : \u211d} :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  -- sorry\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\n  -- sorry\nend\n\n-- 0070\nexample {x y : \u211d} {u : \u2115 \u2192 \u211d} (hu : seq_limit u x)\n  (ineg : \u2200 n, u n \u2264 y) : x \u2264 y :=\nbegin\n  -- sorry\n  apply le_of_le_add_all',\n  intros \u03b5 \u03b5_pos,\n  cases hu \u03b5 \u03b5_pos with N hN,\n  specialize hN N (by linarith),\n  rw abs_le at hN,\n  linarith [ineg N],\n  -- sorry\nend\n", "meta": {"author": "leanprover-community", "repo": "tutorials", "sha": "79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1", "save_path": "github-repos/lean/leanprover-community-tutorials", "path": "github-repos/lean/leanprover-community-tutorials/tutorials-79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1/src/solutions/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894548800271, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7273451001612767}}
{"text": "import M4R.Algebra.Group.Monoid\n\nnamespace M4R\n  namespace Group\n    open Monoid\n\n    protected instance Product (\u03b1\u2081 : Type _) (\u03b1\u2082 : Type _) [Group \u03b1\u2081] [Group \u03b1\u2082] : Group (\u03b1\u2081 \u00d7 \u03b1\u2082) where\n      neg := fun (x\u2081, x\u2082) => (-x\u2081, -x\u2082)\n      add_neg := fun (a\u2081, a\u2082) => by simp [HAdd.hAdd, Add.add, product_zero]; exact \u27e8add_neg a\u2081, add_neg a\u2082\u27e9\n\n    theorem product_neg {\u03b1\u2081 : Type _} {\u03b1\u2082 : Type _} [Group \u03b1\u2081] [Group \u03b1\u2082] : \u2200 x : \u03b1\u2081 \u00d7 \u03b1\u2082, -x = (-x.fst, -x.snd) :=\n      fun (x\u2081, x\u2082) => rfl\n\n    protected instance multi_product.Neg {\u03b9 : Type _} (f\u03b9 : \u03b9 \u2192 Type _) [\u2200 i, Neg (f\u03b9 i)] : Neg (MultiProd f\u03b9) where\n      neg := (- \u00b7 \u00b7)\n    protected theorem multi_product.Neg_def {\u03b9 : Type _} {f\u03b9 : \u03b9 \u2192 Type _} [\u2200 i, Neg (f\u03b9 i)] (a : MultiProd f\u03b9) :\n      \u2200 i, (- a) i = - (a i) := fun _ => rfl\n\n    protected instance multi_product {\u03b9 : Type _} (f\u03b9 : \u03b9 \u2192 Type _) [\u2200 i, Group (f\u03b9 i)] : Group (MultiProd f\u03b9) where\n      add_neg := fun a => funext fun i => Group.add_neg (a i)\n\n    theorem neg_add [Group \u03b1] (a : \u03b1) : -a + a = 0 := by\n      calc\n        -a + a = -a + a + (-a + - -a) := by rw [add_neg, add_zero]\n        _      = -a + (a + -a) + - -a := by rw [\u2190add_assoc (-a + a), add_assoc (-a)]\n        _      = (0 : \u03b1)              := by rw [add_neg, add_zero, add_neg]\n    theorem add_neg_comm [Group \u03b1] (a : \u03b1) : a + (-a) = (-a) + a :=\n      Eq.trans (add_neg a) (Eq.symm (neg_add a))\n\n    theorem neg_zero [Group \u03b1] : -(0 : \u03b1) = 0 := by\n      rw [\u2190zero_add (-0), add_neg]\n\n    theorem sub_def [Group \u03b1] (a b : \u03b1) : a - b = a + -b := rfl\n    theorem sub_self [Group \u03b1] (a : \u03b1) : a - a = 0 := by rw [sub_def, add_neg]\n    theorem sub_add [Group \u03b1] (a b : \u03b1) : a - b + b = a := by rw [sub_def, add_assoc, neg_add, add_zero]\n\n    theorem add_right_cancel [Group \u03b1] (a b c : \u03b1) : a + c = b + c \u2194 a = b  := by\n      have : \u2200 (x y z : \u03b1), x = y \u2192 x + z = y + z := fun x y z => congrArg (\u00b7 + z)\n      apply Iff.intro\n      case mpr => exact this a b c\n      case mp =>\n        intro hacbc\n        rw [\u2190 add_zero a, \u2190 add_zero b, \u2190 add_neg c, \u2190 add_assoc a, \u2190 add_assoc b]\n        exact this (a+c) (b+c) (-c) hacbc\n\n    theorem sub_right [Group \u03b1] {a b c : \u03b1} : a + c = b \u2194 a = b + -c :=\n      \u27e8by intro h; rw [\u2190h, add_assoc, add_neg, add_zero],\n      by intro h; rw [h, add_assoc, neg_add, add_zero]\u27e9\n    theorem sub_eq [Group \u03b1] {a b c : \u03b1} : a - b = c \u2194 a = c + b :=\n      \u27e8fun h => (sub_right.mpr h.symm).symm, fun h => (sub_right.mp h.symm).symm\u27e9\n\n    theorem neg_neg [Group \u03b1] (a : \u03b1) : - - a = a := by\n      rw [\u2190add_right_cancel _ _ (-a), neg_add, add_neg]\n\n    /-- Use `AbelianGroup.neg_add_distrib` for `-(a + b) = -a + -b`. -/\n    theorem neg_add_distrib [Group \u03b1] (a b : \u03b1) : -(a + b) = -b + -a := by\n      rw [\u2190add_right_cancel _ _ (a + b), neg_add, add_assoc, \u2190add_assoc (-a), neg_add, zero_add, neg_add]\n\n    theorem neg_inj [g : Group \u03b1] : Function.injective g.neg := by\n      intro x y h; rw [\u2190neg_neg x, \u2190neg_neg y]; exact congrArg g.neg h\n\n    protected class constructor_g (\u03b1 : Type _) extends Zero \u03b1, Add \u03b1, Neg \u03b1 where\n      add_zero  : \u2200 a : \u03b1, a + 0 = a\n      add_assoc : \u2200 a b c : \u03b1, (a + b) + c = a + (b + c)\n      add_neg   : \u2200 a : \u03b1, a + (-a) = 0\n\n    protected def construct {\u03b1 : Type _} (c : Group.constructor_g \u03b1) : Group \u03b1 where\n      add_zero := c.add_zero\n      zero_add := fun a => by\n        rw [\u2190c.add_neg a, c.add_assoc]\n        (conv => lhs rhs rhs rw [\u2190c.add_zero a, \u2190c.add_neg (-a), \u2190c.add_assoc, c.add_neg])\n        rw [\u2190c.add_assoc (-a), c.add_zero, c.add_neg, c.add_zero]\n      add_assoc := c.add_assoc\n      add_neg := c.add_neg\n\n    protected def to_constructor (\u03b1 : Type _) [Group \u03b1] : Group.constructor_g \u03b1 where\n      add_zero  := Monoid.add_zero\n      add_assoc := Monoid.add_assoc\n      add_neg   := Group.add_neg\n\n  end Group\n\n  namespace AbelianGroup\n\n    protected instance Product (\u03b1\u2081 : Type _) (\u03b1\u2082 : Type _) [AbelianGroup \u03b1\u2081] [AbelianGroup \u03b1\u2082] : AbelianGroup (\u03b1\u2081 \u00d7 \u03b1\u2082) where\n      add_comm := (CommMonoid.Product \u03b1\u2081 \u03b1\u2082).add_comm\n\n    protected instance multi_product {\u03b9 : Type _} (f\u03b9 : \u03b9 \u2192 Type _) [\u2200 i, AbelianGroup (f\u03b9 i)] : AbelianGroup (MultiProd f\u03b9) where\n      add_comm := (CommMonoid.multi_product f\u03b9).add_comm\n\n    protected class constructor_ab (\u03b1 : Type _) extends Group.constructor_g \u03b1, CommMonoid.constructor_cm \u03b1\n\n    protected def construct {\u03b1 : Type _} (c : AbelianGroup.constructor_ab \u03b1) : AbelianGroup \u03b1 where\n      toGroup  := Group.construct c.toconstructor_g\n      add_comm := c.add_comm\n\n    protected def to_constructor (\u03b1 : Type _) [AbelianGroup \u03b1] : AbelianGroup.constructor_ab \u03b1 where\n      toconstructor_g := Group.to_constructor \u03b1\n      add_comm        := CommMonoid.add_comm\n\n    protected theorem neg_add_distrib [AbelianGroup \u03b1] (a b : \u03b1) : -(a + b) = -a + -b := by\n      rw [Group.neg_add_distrib, add_comm]\n\n  end AbelianGroup\n\n  instance IntGroup : AbelianGroup Int := AbelianGroup.construct\n  {\n    add_zero  := Int.add_zero\n    add_assoc := Int.add_assoc\n    add_neg   := Int.add_neg\n    add_comm  := Int.add_comm\n  }\n\nend M4R\n", "meta": {"author": "Hop311", "repo": "M4R", "sha": "ebd1b04af344f9737d290bf8b48b3cde35e9787b", "save_path": "github-repos/lean/Hop311-M4R", "path": "github-repos/lean/Hop311-M4R/M4R-ebd1b04af344f9737d290bf8b48b3cde35e9787b/M4R/Algebra/Group/Group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.727345098133079}}
{"text": "import tuto_lib\n\n\nsection\n/-\nThe first part of this file makes sure you can negate quantified statements\nin your head without the help of `push_neg`.\n\nYou need to complete the statement and then use the `check_me` tactic\nto check your answer. This tactic exists only for those exercises,\nit mostly calls `push_neg` and then cleans up a bit.\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from \u211d to \u211d\n-- x\u2080 and l are real numbers\nvariables (u : \u2115 \u2192 \u211d) (f : \u211d \u2192 \u211d) (x\u2080 l : \u211d)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/- Negation of \"f is continuous at x\u2080\" -/\n-- 0063\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192  |f x - f x\u2080| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`\u2200 x x', ...` is the abbreviation of\n`\u2200 x, \u2200 x', ... `. \n\nAlso, `\u2203 x x', ...` is the abbreviation of `\u2203 x, \u2203 x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on \u211d\" -/\n-- 0064\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x x', |x' - x| \u2264 \u03b4 \u2192  |f x' - f x| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/- Negation of \"f is sequentially continuous at x\u2080\" -/\n-- 0065\nexample : \u00ac (\u2200 u : \u2115 \u2192 \u211d, (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b5) \u2192 (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |(f \u2218 u) n - f x\u2080| \u2264 \u03b5))  \u2194\nsorry\n:=\nbegin\n  sorry\nend\nend\n\n/-\nWe now turn to elementary applications of negations to limits of sequences.\nRemember that `linarith` can find easy numerical contradictions.\n\nAlso recall the following lemmas:\n\nabs_le (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\n/-- The sequence `u` tends to `+\u221e`. -/\ndef tendsto_infinity (u : \u2115 \u2192 \u211d) := \u2200 A, \u2203 N, \u2200 n \u2265 N, u n \u2265 A\n-/\n\n-- 0066\nexample {u : \u2115 \u2192 \u211d} : tendsto_infinity u \u2192 \u2200 l, \u00ac seq_limit u l :=\nbegin\n  sorry\nend\n\ndef nondecreasing_seq (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- 0067\nexample (u : \u2115 \u2192 \u211d) (l : \u211d) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  \u2200 n, u n \u2264 l :=\nbegin\n  sorry\nend\n\n/-\nIn the following exercises, `A : set \u211d` means that A is a set of real numbers.\nWe can use the usual notation x \u2208 A.\n\nThe notation `\u2200 x \u2208 A, ...` is the abbreviation of `\u2200 x, x \u2208 A \u2192 ... `\n\nThe notation `\u2203 x \u2208 A, ...` is the abbreviation of `\u2203 x, x \u2208 A \u2227 ... `.\nMore precisely it is the abbreviation of `\u2203 x (H : x \u2208 A), ...`\nwhich is Lean's strange way of saying `\u2203 x, x \u2208 A \u2227 ... `. \nYou can convert between these forms using the lemma \n  exists_prop {p q : Prop} : (\u2203 (h : p), q) \u2194 p \u2227 q\n\nWe'll work with upper bounds and supremums.\nAgain we'll introduce specialized definitions for the sake of exercises, but mathlib\nhas more general versions.\n\n\ndef upper_bound (A : set \u211d) (x : \u211d) := \u2200 a \u2208 A, a \u2264 x\n\ndef is_sup (A : set \u211d) (x : \u211d) := upper_bound A x \u2227 \u2200 y, upper_bound A y \u2192 x \u2264 y\n\n\nRemark: one can easily show that a set of real numbers has at most one sup,\nbut we won't need this.\n-/\n\n-- 0068\nexample {A : set \u211d} {x : \u211d} (hx : is_sup A x) :\n\u2200 y, y < x \u2192 \u2203 a \u2208 A, y < a :=\nbegin\n  sorry\nend\n\n/-\nLet's do a variation on an example from file 07 that will be useful in the last\nexercise below.\n-/\n\n-- 0069\nlemma le_of_le_add_all' {x y : \u211d} :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  sorry\nend\n\n-- 0070\nexample {x y : \u211d} {u : \u2115 \u2192 \u211d} (hu : seq_limit u x)\n  (ineg : \u2200 n, u n \u2264 y) : x \u2264 y :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "pedrominicz", "repo": "learn", "sha": "b79b802a9846c86c21d4b6f3e17af36e7382f0ef", "save_path": "github-repos/lean/pedrominicz-learn", "path": "github-repos/lean/pedrominicz-learn/learn-b79b802a9846c86c21d4b6f3e17af36e7382f0ef/src/tutorials/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7273069588889971}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Functions in Lean.\n\nIn this sheet we'll learn how to manipulate the concepts of \ninjectivity and surjectivity in Lean. \n\nThe notation for functions is the usual one in mathematics:\nif `X` and `Y` are types, then `f : X \u2192 Y` denotes a function\nfrom `X` to `Y`. In fact what is going on here is that `X \u2192 Y`\ndenotes the type of all functions from `X` to `Y`, and `f : X \u2192 Y`\nmeans that `f` is a term of type `X \u2192 Y`, i.e., a function\nfrom `X` to `Y`.\n\nOne thing worth mentioning is that the simplest kind of function\nevaluation, where you have `x : X` and `f : X \u2192 Y`, doesn't need\nbrackets: you can just write `f x` instead of `f(x)`. You only\nneed it when evaluating a function at a more complex object;\nfor example if we also had `g : Y \u2192 Z` then we can't write\n`g f x` for `g(f(x))`, we have to write `g(f x)` otherwise\n`g` would eat `f` and get confused. Without brackets,\na function just eats the next term greedily.\n\n## The API we'll be using\n\nLean has the predicates `function.injective` and `function.surjective` on functions.\nIn other words, if `f : X \u2192 Y` is a function, then `function.injective f`\nand `function.surjective f` are true-false statements. \n\n-/\n\n-- Typing `function.` gets old quite quickly, so let's open the function namespace\nopen function\n\n-- Now we can just write `injective f` and `surjective f`.\n\n -- Our functions will go between these sets, or Types as Lean calls them\nvariables (X Y Z : Type)\n\n-- Let's prove some theorems, each of which are true by definition.\n\ntheorem injective_def (f : X \u2192 Y) : \n  injective f \u2194 \u2200 (a b : X), f a = f b \u2192 a = b :=\nbegin\n  refl -- this proof works, because `injective f` \n       -- means \u2200 a b, f a = f b \u2192 a = b *by definition*\n       -- so the proof is \"it's reflexivity of `\u2194`\"\nend\n\n-- similarly this is the *definition* of `surjective f`\ntheorem surjective_def (f : X \u2192 Y) : \n  surjective f \u2194 \u2200 b : Y, \u2203 a : X, f a = b :=\nbegin\n  refl\nend\n\n-- similarly the *definition* of `id x` is `x`\ntheorem id_eval (x : X) :\n  id x = x :=\nbegin\n  refl\nend\n\n-- Function composition is `\u2218` in Lean (find out how to type it by putting your cursor on it). \n-- The *definition* of (g \u2218 f) (x) is g(f(x)).\ntheorem comp_eval (f : X \u2192 Y) (g : Y \u2192 Z) (x : X) :\n  (g \u2218 f) x = g (f x) :=\nbegin\n  refl\nend\n\n-- Why did we just prove all those theorems with a proof\n-- saying \"it's true by definition\"? Because now, if we want,\n-- we can `rw` the theorems to replace things by their definitions.\n\nexample : injective (id : X \u2192 X) :=\nbegin\n  -- you can start with `rw injective_def` if you like,\n  -- and later you can `rw id_eval`, although `rw` doesn't\n  -- work under binders like `\u2200`, so use `intro` first.\n  sorry\nend\n\nexample : surjective (id : X \u2192 X) :=\nbegin\n  sorry\nend\n\nexample (f : X \u2192 Y) (g : Y \u2192 Z) (hf : injective f) (hg : injective g) :\n  injective (g \u2218 f) :=\nbegin\n  sorry\nend\n\nexample (f : X \u2192 Y) (g : Y \u2192 Z) (hf : surjective f) (hg : surjective g) :\n  surjective (g \u2218 f) :=\nbegin\n  sorry,\nend\n\n-- This is a question on the IUM function problem sheet\nexample (f : X \u2192 Y) (g : Y \u2192 Z) : \n  injective (g \u2218 f) \u2192 injective f :=\nbegin\n  sorry\nend\n\n-- This is another one\nexample (f : X \u2192 Y) (g : Y \u2192 Z) : \n  surjective (g \u2218 f) \u2192 surjective g :=\nbegin\n  sorry\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2022/functions/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7272915901146121}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n/-!\n\n# Advanced proposition world.\n\n## Level 4: `iff_trans`.\n\nThe mathematical statement `P \u2194 Q` is equivalent to `(P \u27f9 Q) \u2227 (Q \u27f9 P)`. The `cases`\nand `split` tactics work on hypotheses and goals (respectively) of the form `P \u2194 Q`.\n\n> If you need to write an `\u2194` arrow in Visual Studio Code you can do so by typing `\\iff`.\nSee the \"Lean 4: Show All Abbreviations\" command.\n\nAfter an initial `intro h` you can type `cases h with hpq hqp` to break `h : P \u2194 Q` into its constituent parts.\n\n## Lemma\nIf `P`, `Q` and `R` are true/false statements, then `P \u2194 Q` and `Q \u2194 R` together imply `P \u2194 R`.\n-/\nlemma iff_trans (P Q R : Prop) : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) := by\n  intro hpq\n  intro hqr\n  constructor\n  cases hpq with\n  | intro pq qp =>\n    cases hqr with\n    | intro qr rq =>\n      intro p\n      apply qr\n      apply pq\n      exact p\n  cases hpq with\n  | intro pq qp =>\n    cases hqr with\n    | intro qr rq =>\n      intro r\n      apply qp\n      apply rq\n      exact r\n/-!\n\n\nNext up [Level 5](./Level5.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedPropositionWorld/Level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7272913590277437}}
{"text": "import tactic\nimport data.real.sqrt\nimport analysis.specific_limits.basic\nimport analysis.specific_limits.normed\n\nopen filter real\n\nopen_locale topological_space\nnoncomputable theory\n\n\ntheorem rudin_3_1 (f : \u2115 \u2192 \u211d) \n  (h : \u2203 (a : \u211d), tendsto (\u03bb (n : \u2115), f n) at_top (\ud835\udcdd a)) :\n  \u2203 (a : \u211d), tendsto (\u03bb (n : \u2115), |f n|) at_top (\ud835\udcdd a) :=\nbegin\n  cases h with a h,\n  use |a|,\n  apply filter.tendsto.abs h,\nend\n\ntheorem rudin_3_2 : \n  tendsto (\u03bb (n : \u211d), (sqrt (n^2 + n) - n)) at_top (\ud835\udcdd (1/2)) :=\nbegin\n  sorry, \nend\n\ntheorem rudin_3_3 (f : \u2115 \u2192 \u211d) (hf1 : f 0 = sqrt 2) \n  (hf2 : \u2200 n : \u2115, f n.succ = sqrt(2 + sqrt (f n))) : \n  \u2203 (x : \u211d), tendsto f at_top (\ud835\udcdd x) \u2227 \u2200 n, f n < 2 :=\nbegin\n  sorry,\nend\n\ntheorem rudin_3_22 (X : Type*) [metric_space X] [complete_space X] (G : \u2115 \u2192 set X)\n  (hG : \u2200 n : \u2115, is_open (G n) \u2227 dense (G n)) :\n  \u2203 x : X, \u2200 n : \u2115, x \u2208 G n\n:=\nbegin \n  sorry, \nend \n", "meta": {"author": "wudcscheme", "repo": "lean-challenges", "sha": "dfaf3f6f71148b60db75479e7b09c68012f354c1", "save_path": "github-repos/lean/wudcscheme-lean-challenges", "path": "github-repos/lean/wudcscheme-lean-challenges/lean-challenges-dfaf3f6f71148b60db75479e7b09c68012f354c1/src/analysis/rudin_chapter3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7272913467207079}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport linear_algebra.basis\nimport algebra.free_algebra\nimport linear_algebra.finsupp_vector_space\n/-!\n# Linear algebra properties of `free_algebra R X`\n\nThis file provides a `free_monoid X` basis on the `free_algebra R X`, and uses it to show the\ndimension of the algebra is the cardinality of `list X`\n-/\n\nuniverses u v\n\nnamespace free_algebra\n\n/-- The `free_monoid X` basis on the `free_algebra R X`,\nmapping `[x\u2081, x\u2082, ..., x\u2099]` to the \"monomial\" `1 \u2022 x\u2081 * x\u2082 * \u22ef * x\u2099` -/\n@[simps]\nnoncomputable def basis_free_monoid (R : Type u) (X : Type v) [comm_ring R] :\n  basis (free_monoid X) R (free_algebra R X) :=\nfinsupp.basis_single_one.map\n  (equiv_monoid_algebra_free_monoid.symm.to_linear_equiv : _ \u2243\u2097[R] free_algebra R X)\n\n-- TODO: generalize to `X : Type v`\nlemma dim_eq {K : Type u} {X : Type (max u v)} [field K] :\n  module.rank K (free_algebra K X) = cardinal.mk (list X) :=\n(cardinal.lift_inj.mp (basis_free_monoid K X).mk_eq_dim).symm\n\nend free_algebra\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/free_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7272913454603704}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 6 : \"or\" (\u2228`)\n\nWe learn about how to manipulate `P \u2228 Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following tactics\n\n* `left` and `right`\n* `cases` (new functionality)\n\n### The `left` and `right` tactics.\n\nIf your goal is `\u22a2 P \u2228 Q` then `left,` will change it to `\u22a2 P`\nand `right,` will change it to `\u22a2 Q`.\n\n### The `cases` tactic again\n\nIf we have `h : P \u2228 Q` as a hypothesis then `cases h with hP hQ`\nwill turn your goal into two goals, one with `hP : P` as a hypothesis\nand the other with `hQ : Q`.\n\n-/\n\n-- Throughout this sheet, `P`, `Q`, `R` and `S` will denote propositions.\n\nvariables (P Q R S : Prop)\n\nexample : P \u2192 P \u2228 Q :=\nbegin\n  intro hP,\n  left,\n  apply hP,\nend\n\nexample : Q \u2192 P \u2228 Q :=\nbegin\n  intro hQ,\n  right, apply hQ,\nend\n\nexample : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  intros hPQ h\u2081 h\u2082,\n  cases hPQ with hP hQ,\n  apply h\u2081 hP,\n  apply h\u2082 hQ,\nend\n\n-- symmetry of `or`\nexample : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  intro hPQ,\n  cases hPQ with hP hQ,\n  right,\n  exact hP,\n  left,\n  exact hQ,\nend\n\n-- associativity of `or`\nexample : (P \u2228 Q) \u2228 R \u2194 P \u2228 (Q \u2228 R) :=\nbegin\n  split,\n  {intros h,\n  cases h with hPQ hR,\n  cases hPQ with hP hQ,\n  left, apply hP,\n  right, left, apply hQ,\n  right, right, apply hR,},\n  intro h,\n  cases h with hP hQR,\n  left, left, apply hP,\n  cases hQR with hQ hR,\n  left, right, apply hQ,\n  right, apply hR,\nend\n\nexample : (P \u2192 R) \u2192 (Q \u2192 S) \u2192 P \u2228 Q \u2192 R \u2228 S :=\nbegin\n  intros hPR hQS hPQ,\n  cases hPQ with hP hQ,\n  left,\n  apply hPR hP,\n  right,\n  apply hQS hQ,\nend\n\nexample : (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R :=\nbegin\n  intros hPQ hPR,\n  cases hPR,\n  left,\n  apply hPQ hPR,\n  right, \n  apply hPR,\nend\n\nexample : (P \u2194 R) \u2192 (Q \u2194 S) \u2192 (P \u2228 Q \u2194 R \u2228 S) :=\nbegin\n  intros hPR hQS,\n  split,\n  {intro hPQ,\n  cases hPQ with hP hQ,\n  left, rw \u2190hPR, apply hP,\n  right, rw \u2190hQS, apply hQ,},\n  intro hRS,\n  cases hRS,\n  left, rw hPR, apply hRS,\n  right, rw hQS, apply hRS,\nend\n\n-- de Morgan's laws\nexample : \u00ac (P \u2228 Q) \u2194 \u00ac P \u2227 \u00ac Q :=\nbegin\n  split,\n  {intro h1,\n  by_cases P,\n  {have hPQ: P \u2228 Q, {left, exact h,},\n  trivial,},\n  split,\n  exact h,\n  by_cases Q,\n  {have hPQ : P \u2228 Q, {right, exact h,},\n  by_contra hPQ,\n  trivial,},\n  exact h,\n  },\n  intro h,\n  by_cases P \u2228 Q,\n  cases h with hP hQ,\n  have hP': \u00ac P, by exact h.1,\n  trivial,                          /-attention!-/\n  have hQ': \u00ac Q, by exact h.2,\n  trivial,\n  exact h,\nend\n\nexample : \u00ac (P \u2227 Q) \u2194 \u00ac P \u2228 \u00ac Q :=\nbegin\n  split,\n  {intro h,\n  by_cases P,\n  {have hQ : Q \u2228 \u00ac Q, \n  {by_cases Q, left, exact h, right, exact h},\n  cases hQ with hQ hQ',\n  {have hPQ : P \u2227 Q, {split, exact h, exact hQ,},\n  trivial,},\n  right, exact hQ',},\n  left, exact h,\n  },\n  intro h,\n  cases h with hP' hQ',\n  {change P \u2192 false at hP',\n  have hPQ': P \u2227 Q \u2192 false,\n  {intro h\u2081, exact hP' h\u2081.1,},\n  trivial,},\n  {change Q \u2192 false at hQ',\n  have hPQ': P \u2227 Q \u2192 false,\n  {intro h\u2082, exact hQ' h\u2082.2,},\n  trivial,},\nend\n", "meta": {"author": "Siesta233", "repo": "LeanPractice", "sha": "3795eeb8763edacf2c74b9c8925f642d6cc56daf", "save_path": "github-repos/lean/Siesta233-LeanPractice", "path": "github-repos/lean/Siesta233-LeanPractice/LeanPractice-3795eeb8763edacf2c74b9c8925f642d6cc56daf/src/PS6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7272913398258299}}
{"text": "import tactic\n\n/-!\n# Cubic equations with infinitely many solutions\n\nThe goal of this project is to prove the following\n\n**Theorem.** If a > 2 is a cube-free integer such that the equation\n  x\u00b3 + y\u00b3 = a                                                       (59)\nhas a solution in rational numbers, then it has infinitely many rational solutions.\n\nSee Ireland-Rosen, \u00a717.9:\n\nWe say that an integer a is *cube-free* if ord\u209a a \u2264 2 for all primes p, that is,\nno cube \u2260 \u00b11 divides a.\n\nPROOF (of the theorem above).\nLet (\u03b1, \u03b2) be a rational point on (59). If \u03b1 = x\u2081/z\u2081, \u03b2 = y\u2081/z\u2081' and\ngcd(x\u2081, z\u2081) = gcd(y\u2081, z\u2081') = 1 with x\u2081, y\u2081, z\u2081, z\u2081' integers, then it is easy to see\nthat z\u2081 = z\u2081'. Since a > 2 is cube-free, x\u2081 y\u2081 \u2260 0 and x\u2081 \u2260 y\u2081. The tangent line to (59) at\n(\u03b1, \u03b2) is \u03b1\u00b2 x + \u03b2\u00b2 y = a. Solving for y and substituting in (59) gives\n  x\u00b3 + ((a - \u03b1\u00b2 x)/\u03b2\u00b2)\u00b3 - a = 0.                                    (60)\nThe left-hand side of (60) is a cubic pol ynomial with \u03b1 as a double root (at least).\nIfthe third root is \u03b3, then since the sum of the roots is the negative of\nthe coefficient of x\u00b2, we obtain after a simple calculation,\n  2 \u03b1 + \u03b3 = 3 \u03b1\u2074/(\u03b1\u00b3 - \u03b2\u00b3) .                                        (61)\nThus\n  \u03b3 = \u03b1(\u03b1\u00b3 + 2\u03b2\u00b3)/(\u03b1\u00b3 - \u03b2\u00b3) = (x\u2081/z\u2081) (x\u2081\u00b3 + 2y\u2081\u00b3)/(x\u2081\u00b3 - y\u2081\u00b3) .    (62)\nThe corresponding value for y = (a - \u03b1\u00b2 x)/\u03b2\u00b2 is\n  \u03c1 = (-y\u2081/z\u2081) (2x\u2081\u00b3 + y\u2081\u00b3)/(x\u2081\u00b3 - y\u2081\u00b3)                             (63)\nand by (60), (\u03b3, \u03c1) is a rational point on the cubic. The reader may verify\ndirectly, of course, that (\u03b3, \u03c1) satisfies \u03b3\u00b3 + \u03c1\u00b3 = a. It remains to show that\n(\u03b3, \u03c1) is distinct from (\u03b1, \u03b2) and moreover that one obtains by this process an\ninfinite number of points on the curve. Define the integer A by A > 0 and\n  A x\u2082 = x\u2081(x\u2081\u00b3 + 2y\u2081\u00b3),\n  A y\u2082 = -y\u2081(2x\u2081\u00b3 + y\u2081\u00b3),                                           (64)\n  A z\u2082 = z\u2081(x\u2081\u00b3 - y\u2081\u00b3),\nwith gcd(x\u2082, y\u2082, z\u2082) = 1. Thus A is the greatest common divisor of the integers on\nthe right-hand side of (64). Clearly one has\n  x\u2082\u00b3 + y\u2082\u00b3 = a z\u2082\u00b3,  z\u2082 \u2260 0.                                       (65)\nSince a is cube-free and gcd(x\u2082, y\u2082, z\u2082) = 1, we see that gcd(x\u2082, y\u2082) = gcd(x\u2082, z\u2082) =\ngcd(y\u2082, z\u2082) = 1. We claim that A is equal to 1 or 3. For if p is prime and p \u2223 A, then\nit follows without difficulty from (64) that p does not divide x\u2081 y\u2081 z\u2081. Thus p divides\neach of the second factors on the right-hand side of (64) and consequently p \u2223 3 y\u2081\u00b3.\nThus p is 1 or 3. Notice, also, that gcd(A, z\u2081) = 1 implies A \u2223 x\u2081\u00b3 - y\u2081\u00b3.\n\nThe proof will be completed by showing that |z\u2082| > |z\u2081|. To this end one has\n  |z\u2082| = (|z\u2081|/A) |x\u2081\u00b3 - y\u2081\u00b3| = (|z\u2081|/A) |x\u2081 - y\u2081| |x\u2081\u00b2 + x\u2081 y\u2081 + y\u2081\u00b2|. (66)\nOne sees, 4 |x\u2081\u00b2 + x\u2081 y\u2081 + y\u2081\u00b2| = |(2x\u2081 + Y\u2081)\u00b2 + 3y\u2081\u00b2| > 4 and consequently\none has the inequality |z\u2082| > |z\u2081| |x\u2081 - y\u2081|/A. If A = 1, then (66) shows\nthat |z\u2082| > |z\u2081|. On the other hand, if A = 3, then since A | x\u2081\u00b3 - y\u2081\u00b3, one has\nx\u2081\u00b3 \u2261 y\u2081\u00b3 mod 3, which implies that x\u2081 \u2261 y\u2081 mod 3, and once again (66) implies\nthat |z\u2082| > |z\u2081|. Continuing in this manner, one obtains a succession of points\n(x\u2099/z\u2099, y\u2099/z\u2099), x\u2099 y\u2099 \u2260 0, gcd(x\u2099, z\u2099) = gcd(y\u2099, z\u2099) = 1 and |z\u2099| > |z\u2099\u208b\u2081|, and the\nproof is co mplete. QED\n\n-/", "meta": {"author": "MichaelStollBayreuth", "repo": "seminar-bayreuth-2022", "sha": "1e5accbfb6054c8ca4b6d3b192818fdbb90ed841", "save_path": "github-repos/lean/MichaelStollBayreuth-seminar-bayreuth-2022", "path": "github-repos/lean/MichaelStollBayreuth-seminar-bayreuth-2022/seminar-bayreuth-2022-1e5accbfb6054c8ca4b6d3b192818fdbb90ed841/src/cubic_equations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.8459424411924674, "lm_q1q2_score": 0.7272260547525423}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport analysis.special_functions.bernstein\nimport topology.algebra.algebra\n\n/-!\n# The Weierstrass approximation theorem for continuous functions on `[a,b]`\n\nWe've already proved the Weierstrass approximation theorem\nin the sense that we've shown that the Bernstein approximations\nto a continuous function on `[0,1]` converge uniformly.\n\nHere we rephrase this more abstractly as\n`polynomial_functions_closure_eq_top' : (polynomial_functions I).topological_closure = \u22a4`\nand then, by precomposing with suitable affine functions,\n`polynomial_functions_closure_eq_top : (polynomial_functions (set.Icc a b)).topological_closure = \u22a4`\n-/\n\nopen continuous_map filter\nopen_locale unit_interval\n\n/--\nThe special case of the Weierstrass approximation theorem for the interval `[0,1]`.\nThis is just a matter of unravelling definitions and using the Bernstein approximations.\n-/\ntheorem polynomial_functions_closure_eq_top' :\n  (polynomial_functions I).topological_closure = \u22a4 :=\nbegin\n  apply eq_top_iff.mpr,\n  rintros f -,\n  refine filter.frequently.mem_closure _,\n  refine filter.tendsto.frequently (bernstein_approximation_uniform f) _,\n  apply frequently_of_forall,\n  intro n,\n  simp only [set_like.mem_coe],\n  apply subalgebra.sum_mem,\n  rintro n -,\n  apply subalgebra.smul_mem,\n  dsimp [bernstein, polynomial_functions],\n  simp,\nend\n\n/--\nThe **Weierstrass Approximation Theorem**:\npolynomials functions on `[a, b] \u2286 \u211d` are dense in `C([a,b],\u211d)`\n\n(While we could deduce this as an application of the Stone-Weierstrass theorem,\nour proof of that relies on the fact that `abs` is in the closure of polynomials on `[-M, M]`,\nso we may as well get this done first.)\n-/\ntheorem polynomial_functions_closure_eq_top (a b : \u211d) :\n  (polynomial_functions (set.Icc a b)).topological_closure = \u22a4 :=\nbegin\n  by_cases h : a < b, -- (Otherwise it's easy; we'll deal with that later.)\n  { -- We can pullback continuous functions on `[a,b]` to continuous functions on `[0,1]`,\n    -- by precomposing with an affine map.\n    let W : C(set.Icc a b, \u211d) \u2192\u2090[\u211d] C(I, \u211d) :=\n      comp_right_alg_hom \u211d \u211d (Icc_homeo_I a b h).symm.to_continuous_map,\n    -- This operation is itself a homeomorphism\n    -- (with respect to the norm topologies on continuous functions).\n    let W' : C(set.Icc a b, \u211d) \u2243\u209c C(I, \u211d) := comp_right_homeomorph \u211d (Icc_homeo_I a b h).symm,\n    have w : (W : C(set.Icc a b, \u211d) \u2192 C(I, \u211d)) = W' := rfl,\n    -- Thus we take the statement of the Weierstrass approximation theorem for `[0,1]`,\n    have p := polynomial_functions_closure_eq_top',\n    -- and pullback both sides, obtaining an equation between subalgebras of `C([a,b], \u211d)`.\n    apply_fun (\u03bb s, s.comap W) at p,\n    simp only [algebra.comap_top] at p,\n    -- Since the pullback operation is continuous, it commutes with taking `topological_closure`,\n    rw subalgebra.topological_closure_comap_homeomorph _ W W' w at p,\n    -- and precomposing with an affine map takes polynomial functions to polynomial functions.\n    rw polynomial_functions.comap_comp_right_alg_hom_Icc_homeo_I at p,\n    -- \ud83c\udf89\n    exact p },\n  { -- Otherwise, `b \u2264 a`, and the interval is a subsingleton,\n    -- so all subalgebras are the same anyway.\n    haveI : subsingleton (set.Icc a b) := \u27e8\u03bb x y, le_antisymm\n      ((x.2.2.trans (not_lt.mp h)).trans y.2.1) ((y.2.2.trans (not_lt.mp h)).trans x.2.1)\u27e9,\n    apply subsingleton.elim, }\nend\n\n/--\nAn alternative statement of Weierstrass' theorem.\n\nEvery real-valued continuous function on `[a,b]` is a uniform limit of polynomials.\n-/\ntheorem continuous_map_mem_polynomial_functions_closure (a b : \u211d) (f : C(set.Icc a b, \u211d)) :\n  f \u2208 (polynomial_functions (set.Icc a b)).topological_closure :=\nbegin\n  rw polynomial_functions_closure_eq_top _ _,\n  simp,\nend\n\nopen_locale polynomial\n\n/--\nAn alternative statement of Weierstrass' theorem,\nfor those who like their epsilons.\n\nEvery real-valued continuous function on `[a,b]` is within any `\u03b5 > 0` of some polynomial.\n-/\ntheorem exists_polynomial_near_continuous_map (a b : \u211d) (f : C(set.Icc a b, \u211d))\n  (\u03b5 : \u211d) (pos : 0 < \u03b5) :\n  \u2203 (p : \u211d[X]), \u2016p.to_continuous_map_on _ - f\u2016 < \u03b5 :=\nbegin\n  have w := mem_closure_iff_frequently.mp (continuous_map_mem_polynomial_functions_closure _ _ f),\n  rw metric.nhds_basis_ball.frequently_iff at w,\n  obtain \u27e8-, H, \u27e8m, \u27e8-, rfl\u27e9\u27e9\u27e9 := w \u03b5 pos,\n  rw [metric.mem_ball, dist_eq_norm] at H,\n  exact \u27e8m, H\u27e9,\nend\n\n/--\nAnother alternative statement of Weierstrass's theorem,\nfor those who like epsilons, but not bundled continuous functions.\n\nEvery real-valued function `\u211d \u2192 \u211d` which is continuous on `[a,b]`\ncan be approximated to within any `\u03b5 > 0` on `[a,b]` by some polynomial.\n-/\ntheorem exists_polynomial_near_of_continuous_on\n  (a b : \u211d) (f : \u211d \u2192 \u211d) (c : continuous_on f (set.Icc a b)) (\u03b5 : \u211d) (pos : 0 < \u03b5) :\n  \u2203 (p : \u211d[X]), \u2200 x \u2208 set.Icc a b, |p.eval x - f x| < \u03b5 :=\nbegin\n  let f' : C(set.Icc a b, \u211d) := \u27e8\u03bb x, f x, continuous_on_iff_continuous_restrict.mp c\u27e9,\n  obtain \u27e8p, b\u27e9 := exists_polynomial_near_continuous_map a b f' \u03b5 pos,\n  use p,\n  rw norm_lt_iff _ pos at b,\n  intros x m,\n  exact b \u27e8x, m\u27e9,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/continuous_function/weierstrass.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7272260511162664}}
{"text": "/-\nCopyright (c) 2020 Heather Macbeth, Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth, Patrick Massot\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.group_theory.subgroup\nimport Mathlib.algebra.archimedean\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Archimedean groups\n\nThis file proves a few facts about ordered groups which satisfy the `archimedean` property, that is:\n`class archimedean (\u03b1) [ordered_add_comm_monoid \u03b1] : Prop :=`\n`(arch : \u2200 (x : \u03b1) {y}, 0 < y \u2192 \u2203 n : \u2115, x \u2264 n \u2022\u2115 y)`\n\nThey are placed here in a separate file (rather than incorporated as a continuation of\n`algebra.archimedean`) because they rely on some imports from `group_theory` -- bundled subgroups\nin particular.\n\nThe main result is `add_subgroup.cyclic_of_min`:  a subgroup of a decidable archimedean abelian\ngroup is cyclic, if its set of positive elements has a minimal element.\n\nThis result is used in this file to deduce `int.subgroup_cyclic`, proving that every subgroup of `\u2124`\nis cyclic.  (There are several other methods one could use to prove this fact, including more purely\nalgebraic methods, but none seem to exist in mathlib as of writing.  The closest is\n`subgroup.is_cyclic`, but that has not been transferred to `add_subgroup`.)\n\nThe result is also used in `topology.instances.real` as an ingredient in the classification of\nsubgroups of `\u211d`.\n-/\n\n/-- Given a subgroup `H` of a decidable linearly ordered archimedean abelian group `G`, if there\nexists a minimal element `a` of `H \u2229 G_{>0}` then `H` is generated by `a`. -/\ntheorem add_subgroup.cyclic_of_min {G : Type u_1} [linear_ordered_add_comm_group G] [archimedean G] {H : add_subgroup G} {a : G} (ha : is_least (set_of fun (g : G) => g \u2208 H \u2227 0 < g) a) : H = add_subgroup.closure (singleton a) := sorry\n\n/-- Every subgroup of `\u2124` is cyclic. -/\ntheorem int.subgroup_cyclic (H : add_subgroup \u2124) : \u2203 (a : \u2124), H = add_subgroup.closure (singleton a) := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/group_theory/archimedean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7272260453306266}}
{"text": "/-\nCopyright (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n\n! This file was ported from Lean 3 source module init.data.int.comp_lemmas\n! leanprover-community/mathlib commit 4a03bdeb31b3688c31d02d7ff8e0ff2e5d6174db\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nprelude\nimport Leanbin.Init.Data.Int.Order\n\nnamespace Int\n\n/-!\n# Auxiliary lemmas for proving that two int numerals are differen\n-/\n\n\n/-! 1. Lemmas for reducing the problem to the case where the numerals are positive -/\n\n\nprotected theorem ne_neg_of_ne {a b : \u2124} : a \u2260 b \u2192 -a \u2260 -b := fun h\u2081 h\u2082 =>\n  absurd (Int.neg_eq_neg h\u2082) h\u2081\n#align int.ne_neg_of_ne Int.ne_neg_of_ne\n\nprotected theorem neg_ne_zero_of_ne {a : \u2124} : a \u2260 0 \u2192 -a \u2260 0 := fun h\u2081 h\u2082 =>\n  by\n  have : -a = -0 := by rwa [Int.neg_zero]\n  have : a = 0 := Int.neg_eq_neg this\n  contradiction\n#align int.neg_ne_zero_of_ne Int.neg_ne_zero_of_ne\n\nprotected theorem zero_ne_neg_of_ne {a : \u2124} (h : 0 \u2260 a) : 0 \u2260 -a :=\n  Ne.symm (Int.neg_ne_zero_of_ne (Ne.symm h))\n#align int.zero_ne_neg_of_ne Int.zero_ne_neg_of_ne\n\nprotected theorem neg_ne_of_pos {a b : \u2124} : 0 < a \u2192 0 < b \u2192 -a \u2260 b := fun h\u2081 h\u2082 h =>\n  by\n  rw [\u2190 h] at h\u2082\n  change 0 < a at h\u2081\n  have := le_of_lt h\u2081\n  exact absurd (le_of_lt h\u2081) (not_le_of_gt (Int.neg_of_neg_pos h\u2082))\n#align int.neg_ne_of_pos Int.neg_ne_of_pos\n\nprotected theorem ne_neg_of_pos {a b : \u2124} : 0 < a \u2192 0 < b \u2192 a \u2260 -b := fun h\u2081 h\u2082 =>\n  Ne.symm (Int.neg_ne_of_pos h\u2082 h\u2081)\n#align int.ne_neg_of_pos Int.ne_neg_of_pos\n\n/-! 2. Lemmas for proving that positive int numerals are nonneg and positive -/\n\n\nprotected theorem one_pos : 0 < (1 : Int) :=\n  Int.zero_lt_one\n#align int.one_pos Int.one_pos\n\nprotected theorem bit0_pos {a : \u2124} : 0 < a \u2192 0 < bit0 a := fun h => Int.add_pos h h\n#align int.bit0_pos Int.bit0_pos\n\nprotected theorem bit1_pos {a : \u2124} : 0 \u2264 a \u2192 0 < bit1 a := fun h =>\n  Int.lt_add_of_le_of_pos (Int.add_nonneg h h) Int.zero_lt_one\n#align int.bit1_pos Int.bit1_pos\n\nprotected theorem zero_nonneg : 0 \u2264 (0 : \u2124) :=\n  le_refl 0\n#align int.zero_nonneg Int.zero_nonneg\n\nprotected theorem one_nonneg : 0 \u2264 (1 : \u2124) :=\n  le_of_lt Int.zero_lt_one\n#align int.one_nonneg Int.one_nonneg\n\nprotected theorem bit0_nonneg {a : \u2124} : 0 \u2264 a \u2192 0 \u2264 bit0 a := fun h => Int.add_nonneg h h\n#align int.bit0_nonneg Int.bit0_nonneg\n\nprotected theorem bit1_nonneg {a : \u2124} : 0 \u2264 a \u2192 0 \u2264 bit1 a := fun h => le_of_lt (Int.bit1_pos h)\n#align int.bit1_nonneg Int.bit1_nonneg\n\nprotected theorem nonneg_of_pos {a : \u2124} : 0 < a \u2192 0 \u2264 a :=\n  le_of_lt\n#align int.nonneg_of_pos Int.nonneg_of_pos\n\n/-! 3. nat_abs auxiliary lemmas -/\n\n\n/- warning: int.neg_succ_of_nat_lt_zero clashes with int.neg_succ_lt_zero -> Int.negSucc_lt_zero\nCase conversion may be inaccurate. Consider using '#align int.neg_succ_of_nat_lt_zero Int.negSucc_lt_zero\u2093'. -/\n#print Int.negSucc_lt_zero /-\ntheorem negSucc_lt_zero (n : \u2115) : negSucc n < 0 :=\n  @lt.intro _ _ n\n    (by\n      simp [neg_succ_of_nat_coe, Int.ofNat_succ, Int.ofNat_add, Int.ofNat_one, Int.add_comm,\n        Int.add_left_comm, Int.neg_add, Int.add_right_neg, Int.zero_add])\n#align int.neg_succ_of_nat_lt_zero Int.negSucc_lt_zero\n-/\n\ntheorem zero_le_ofNat (n : \u2115) : 0 \u2264 ofNat n :=\n  @le.intro _ _ n (by rw [Int.zero_add, Int.coe_nat_eq])\n#align int.zero_le_of_nat Int.zero_le_ofNat\n\n#print Int.ofNat_natAbs_eq_of_nonneg /-\ntheorem ofNat_natAbs_eq_of_nonneg : \u2200 {a : \u2124}, 0 \u2264 a \u2192 ofNat (natAbs a) = a\n  | of_nat n, h => rfl\n  | neg_succ_of_nat n, h => absurd (negSucc_lt_zero n) (not_lt_of_ge h)\n#align int.of_nat_nat_abs_eq_of_nonneg Int.ofNat_natAbs_eq_of_nonneg\n-/\n\ntheorem ne_of_natAbs_ne_natAbs_of_nonneg {a b : \u2124} (ha : 0 \u2264 a) (hb : 0 \u2264 b)\n    (h : natAbs a \u2260 natAbs b) : a \u2260 b := fun h =>\n  by\n  have : ofNat (natAbs a) = ofNat (natAbs b) := by\n    rwa [of_nat_nat_abs_eq_of_nonneg ha, of_nat_nat_abs_eq_of_nonneg hb]\n  injection this\n  contradiction\n#align int.ne_of_nat_abs_ne_nat_abs_of_nonneg Int.ne_of_natAbs_ne_natAbs_of_nonneg\n\nprotected theorem ne_of_nat_ne_nonneg_case {a b : \u2124} {n m : Nat} (ha : 0 \u2264 a) (hb : 0 \u2264 b)\n    (e1 : natAbs a = n) (e2 : natAbs b = m) (h : n \u2260 m) : a \u2260 b :=\n  have : natAbs a \u2260 natAbs b := by rwa [e1, e2]\n  ne_of_natAbs_ne_natAbs_of_nonneg ha hb this\n#align int.ne_of_nat_ne_nonneg_case Int.ne_of_nat_ne_nonneg_case\n\n/-! 4. Aux lemmas for pushing nat_abs inside numerals\n   nat_abs_zero and nat_abs_one are defined at init/data/int/basic.lean -/\n\n\ntheorem natAbs_ofNat_core (n : \u2115) : natAbs (ofNat n) = n :=\n  rfl\n#align int.nat_abs_of_nat_core Int.natAbs_ofNat_core\n\ntheorem natAbs_of_negSucc (n : \u2115) : natAbs (negSucc n) = Nat.succ n :=\n  rfl\n#align int.nat_abs_of_neg_succ_of_nat Int.natAbs_of_negSucc\n\nprotected theorem natAbs_add_nonneg :\n    \u2200 {a b : Int}, 0 \u2264 a \u2192 0 \u2264 b \u2192 natAbs (a + b) = natAbs a + natAbs b\n  | of_nat n, of_nat m, h\u2081, h\u2082 =>\n    by\n    have : ofNat n + ofNat m = ofNat (n + m) := rfl\n    simp [nat_abs_of_nat_core, this]\n  | _, neg_succ_of_nat m, h\u2081, h\u2082 => absurd (negSucc_lt_zero m) (not_lt_of_ge h\u2082)\n  | neg_succ_of_nat n, _, h\u2081, h\u2082 => absurd (negSucc_lt_zero n) (not_lt_of_ge h\u2081)\n#align int.nat_abs_add_nonneg Int.natAbs_add_nonneg\n\nprotected theorem natAbs_add_neg :\n    \u2200 {a b : Int}, a < 0 \u2192 b < 0 \u2192 natAbs (a + b) = natAbs a + natAbs b\n  | neg_succ_of_nat n, neg_succ_of_nat m, h\u2081, h\u2082 =>\n    by\n    have : -[n+1] + -[m+1] = -[Nat.succ (n + m)+1] := rfl\n    simp [nat_abs_of_neg_succ_of_nat, this, Nat.succ_add, Nat.add_succ]\n#align int.nat_abs_add_neg Int.natAbs_add_neg\n\nprotected theorem natAbs_bit0 : \u2200 a : Int, natAbs (bit0 a) = bit0 (natAbs a)\n  | of_nat n => Int.natAbs_add_nonneg (zero_le_ofNat n) (zero_le_ofNat n)\n  | neg_succ_of_nat n => Int.natAbs_add_neg (negSucc_lt_zero n) (negSucc_lt_zero n)\n#align int.nat_abs_bit0 Int.natAbs_bit0\n\nprotected theorem natAbs_bit0_step {a : Int} {n : Nat} (h : natAbs a = n) :\n    natAbs (bit0 a) = bit0 n := by rw [\u2190 h]; apply Int.natAbs_bit0\n#align int.nat_abs_bit0_step Int.natAbs_bit0_step\n\nprotected theorem natAbs_bit1_nonneg {a : Int} (h : 0 \u2264 a) : natAbs (bit1 a) = bit1 (natAbs a) :=\n  show natAbs (bit0 a + 1) = bit0 (natAbs a) + natAbs 1 by\n    rw [Int.natAbs_add_nonneg (Int.bit0_nonneg h) (le_of_lt Int.zero_lt_one), Int.natAbs_bit0]\n#align int.nat_abs_bit1_nonneg Int.natAbs_bit1_nonneg\n\nprotected theorem natAbs_bit1_nonneg_step {a : Int} {n : Nat} (h\u2081 : 0 \u2264 a) (h\u2082 : natAbs a = n) :\n    natAbs (bit1 a) = bit1 n := by rw [\u2190 h\u2082]; apply Int.natAbs_bit1_nonneg h\u2081\n#align int.nat_abs_bit1_nonneg_step Int.natAbs_bit1_nonneg_step\n\nend Int\n\n", "meta": {"author": "leanprover-community", "repo": "lean3port", "sha": "9ed1898f23e4379865ee93d62cb6353e5ed6c270", "save_path": "github-repos/lean/leanprover-community-lean3port", "path": "github-repos/lean/leanprover-community-lean3port/lean3port-9ed1898f23e4379865ee93d62cb6353e5ed6c270/Leanbin/Init/Data/Int/CompLemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7270478829116941}}
{"text": "/- Even more induction! -/\n\nvariable (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n-- The reflexive transitive closure of `r` as an inductive predicate\ninductive RTC : \u03b1 \u2192 \u03b1 \u2192 Prop where\n  -- Notice how declaring `r` as a `variable` instead of as a parameter instead of declaring it\n  -- directly as a parameter of `RTC` means we don't have to write `RTC r a a` inside the\n  -- declaration of `RTC`. This also works with recursive `def`s!\n  | refl : RTC a a\n  | trans : r a b \u2192 RTC b c \u2192 RTC a c\n\n-- We have arbitrarily chosen a \"left-biased\" definition of `RTC.trans`, but can easily show the\n-- mirror version by induction on the predicate\ntheorem RTC.trans' : RTC r a b \u2192 r b c \u2192 RTC r a c := by\n  intros hab hbc\n  induction hab with\n  | refl => exact RTC.trans hbc RTC.refl\n  -- `a/b/c` in the constructor `RTC.trans` are marked as *implicit* because we didn't specify them\n  -- explicitly.\n  -- Just like in other contexts, we can use `@` to specify/match implicit parameters in `induction`.\n  | @trans a a' b haa' ha'b ih => exact RTC.trans haa' (ih hbc)\n\nopen Nat\n\n-- By the way, we can leave out `:= fun p1 ... => match p1, ... with` at `def`\ndef double : Nat \u2192 Nat\n  | zero   => 0\n  | succ n => succ (succ (double n))\n\ntheorem double.inj : double n = double m \u2192 n = m := by\n  intro h\n  -- Try to finish this proof. You might find that the inductive case is impossible to solve!\n  -- Do you see a different approach? If not, read on!\n  induction n generalizing m with/-SOL-/\n  | zero => cases m <;> trivial\n  | succ n ih =>\n    cases m with\n    | zero => contradiction\n    | succ m =>\n      simp only [double] at h\n      injection h with h\n      injection h with h\n      rw [ih h]\n      -- alternatively:\n      --apply congrArg\n      --apply ih\n      -- -- with `simp_all` we sometimes have to exclude \"problematic\" assumptions such as `ih` from fixpoint simplification\n      --simp_all [-ih, double]\n\n-- The issue with the above approach is that our inductive hypothesis is not sufficiently general!\n-- When we begin induction, we have already fixed (introduced) a particular `m`, but for the inductive\n-- step we need the inductive hypothesis for a *different* m.\n-- We could avoid this by carefully introducing `m` (and `h`, which depends on it) only after `induction`:\n-- ```\n-- theorem double.inj : \u2200 m, double n = double m \u2192 n = m := by\n--   induction n with\n--   | zero => intro m h; ...\n--   ...\n-- ```\n-- `induction` even allows us to apply a tactic before *each* case:\n-- ```\n-- theorem double.inj : \u2200 m, double n = double m \u2192 n = m := by\n--   induction n with\n--       intro m h\n--   | zero => ...\n--   ...\n-- ```\n-- However, it turns out that we do not have to change the theorem statement at all: if we simply say\n-- ```\n-- induction n generalizing m with\n-- ```\n-- then `induction` will automatically `revert` (yes, that's also a tactic) and re`intro`duce the variable(s)\n-- before/after induction for us! So add `generalizing m` above, see how the inductive hypothesis is\n-- affected, and then go finish that proof!\n\n\n/- Partial & dependent maps -/\n\n-- *Partial maps* are a useful data type for the semantics project and many other topics.\n-- They map *some* keys of one type to values of another type.\nabbrev Map (\u03b1 \u03b2 : Type) := \u03b1 \u2192 Option \u03b2\n-- We express partiality via the `Option` type, which either holds `some b` for `b : \u03b2`, or `none`.\n-- Ctrl+click it for the whole definition.\n\nnamespace Map\n\ndef empty : Map \u03b1 \u03b2 := fun k => none\n\n-- If we wanted a partial map for programming, we might choose a more efficient implementation such\n-- as a search tree or a hash map. If, on the other hand, we are only interested in using it in a\n-- formalization, a simple function like above is usually the simpler solution. For example, a\n-- simple typing context `\u0393` can be formalized as a partial map from variable names to their types.\n\n-- The function-based definition makes defining operations such as a map update quite easy:\n\n/-- Set the entry `k` of the map `m` to the value `v`. All other entries are unchanged. -/\ndef update [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) (k : \u03b1) (v : Option \u03b2) : Map \u03b1 \u03b2 := \n  fun k' => if k = k' then v else m k'\n\n-- A `scoped` notation is activated only when opening/inside the current namespace\nscoped notation:max m \"[\" k \" \u21a6 \" v \"]\" => update m k v\n\ntheorem apply_update [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) : m[k \u21a6 v] k = v := by simp [update]\n\n-- hint: use function extensionality (`apply funext`)\ntheorem update_self [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) : m[k \u21a6 m k] = m := by\n  funext k'  -- an abbreviation for `apply funext; intro k'`\n  byCases h : k = k' <;> simp [update, h]\n\nend Map\n\n-- One interesting generalization of partial maps we can express in Lean are *dependent maps* where\n-- the *type* of the value may depend on the key:\nabbrev DepMap (\u03b1 : Type) (\u03b2 : \u03b1 \u2192 Type) := (k : \u03b1) \u2192 Option (\u03b2 k)\n\nnamespace DepMap\n\ndef empty : DepMap \u03b1 \u03b2 := fun k => none\n\n-- If we try to define `update` as above, it turns out that we run into a type error!\n-- You may want to use the \"dependent if\" `if h : p then t else e` that makes a *proof* of\n-- the condition `p` available in each branch: `h : p` in the `then` branch and `h : \u00acp` in the\n-- `else` branch. You should then be able to use rewriting (e.g. `\u25b8`) to fix the type error.\ndef update [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) (k : \u03b1) (v : Option (\u03b2 k)) : DepMap \u03b1 \u03b2 := \n  fun k' => if h : k = k' then h \u25b8 v else m k'\n\nlocal notation:max m \"[\" k \" \u21a6 \" v \"]\" => update m k v\n\n-- This one should be as before...\ntheorem apply_update [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) : m[k \u21a6 v] k = v := by simp [update]\n\n-- ...but this one is where the fun starts: try replicating the corresponding `Map` proof...\ntheorem update_self [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) : m[k \u21a6 m k] = m := by\n  funext k'\n  byCases h : k = k'\n  case inl =>\n    rw [h]\n    simp [update]\n  case inr =>\n    simp [update, h]\n-- and you should end up with an unsolved goal containing a subterm of the shape `(_ : a = b) \u25b8 c`. This\n-- is the rewrite from `update`; the proof is elided as `_` by default because, as we said in week 1, Lean\n-- considers all proofs of a proposition as equal, so we really don't care what proof is displayed there.\n-- So how do we get rid of the `\u25b8`? We know it is something like a match  on `Eq.refl`; more formally,\n-- both `\u25b8` and such a match compile down to an application of `Eq`'s *recursor* (week 3).\n-- We know matches/recursors reduce (\"go away\") when applied to a matching constructor application,\n-- i.e. for `\u25b8` we have `(rfl \u25b8 c) \u2261 c`.\n-- So why didn't `simp` reduce away `(_ : a = b) \u25b8` if it works for `rfl` and all proofs are the same?\n-- Well, all proofs of a *single* proposition are the same, but `rfl` is not a proof of `a = b` unless\n-- `a` and `b` are in fact the same term! Thus the general way to get rid of `(_ : a = b) \u25b8` is to\n-- first rewrite the goal with a proof of the very equality `a = b`. After that, `simp`, or definitional\n-- equality in general, will get rid of the `\u25b8`.\n-- Now, for technical reasons we should use `rw` instead of `simp` itself to do this rewrite. The short\n-- answer as to why that is is that `simp` tries to be *too clever* in this case: it will rewrite `a = b`\n-- on both sides of the `\u25b8` individually, which usually makes it more flexible (week 4, slide pages 17 & 20),\n-- but in this case unfortunately leads to a type-incorrect proof. The \"naive\" strategy of `rw`, which will\n-- simply replace all `a` with `b` everywhere simultaneously by applying the `Eq` recursor once at the root,\n-- turns out to be the better approach in this case.\n-- Phew, that was a lot of typing (in the theoretic sense and on my keyboard). If you can't get the proof to\n-- work, don't worry about it, we will not bother you with this kind of \"esoteric\" proof again. If, on the\n-- other hand, you are interested in this kind of strong dependent typing, we may have an interesting variant\n-- of the semantics project to offer you next week!\n\nend DepMap\n\nopen List Nat\n\n/- Insertion Sort -/\n\n-- We want to implement insertion sort in Lean and show that the resulting `List` is indeed sorted.\n-- To that end, we first assume that the type `\u03b1` is of the type class `LE`, meaning that we can use\n-- the symbol `\u2264` (\\le) as notation.\n-- We also assume (notice that cool dot notation) that this relation is decidable:\nvariable [LE \u03b1] [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n\n-- First, we want to define a predicate that holds if a list is sorted.\n-- The predicate should have three constructors:\n-- The empty list `[]` and the single element list `[a]` are sorted,\n-- and we can add `a` to the front of a sorted list `b :: l`, if `a \u2264 b`.s\ninductive Sorted : List \u03b1 \u2192 Prop where \n  | nil : Sorted []\n  | single : Sorted [a]\n  | cons_cons : a \u2264 b \u2192 Sorted (b::l) \u2192 Sorted (a::b::l) \n\n-- The main ingredient to insertion sort is a function `insertInOrder` which inserts\n-- a given element `a` before the first entry `x` of a list for which `a \u2264 x` holds.\n-- Define that function by recursion on the list. Remember that `\u2264` is decidable.\ndef insertInOrder (a : \u03b1) (xs : List \u03b1) : List \u03b1 := \n  match xs with\n  | [] => [a]\n  | x :: xs =>\n    if a \u2264 x then\n      a :: x :: xs\n    else\n      x :: insertInOrder a xs\n\n-- Now, see whether the function actually does what it should do.\n#eval insertInOrder 4 [1, 3, 4, 6, 7]\n#eval insertInOrder 4 [1, 2, 3]\n\n-- Defining `insertionSort` itself is now an easy recursion.\ndef insertionSort (xs : List \u03b1) : List \u03b1 := \n  match xs with\n  | []      => []\n  | x :: xs => insertInOrder x (insertionSort xs)\n\n-- Let's test the sorting algorithm next.\n#eval insertionSort [6, 2, 4, 4, 1, 3, 64]\n#eval insertionSort [1, 2, 3]\n#eval insertionSort (repeat (fun xs => xs.length :: xs) 500 [])\n\n-- Now we want to move on to actually verify that the algorithm does what it claims to do!\n-- To prove this, we don't need the relation to be transitive, but we need to assume the following property:\nvariable (antisymm : \u2200 {x y : \u03b1}, \u00ac x \u2264 y \u2192 (y \u2264 x))\n\n-- Okay, now prove the statement itself!\n-- Hints:\n--   * You might at one point have the choice to either apply induction on a list or on a witness of `Sorted`.\n--     Choose wisely.\n--   * Remember the tactic `byCases` from the fifth exercise!\ntheorem sorted_insertInOrder {xs : List \u03b1} (h : Sorted xs) : Sorted (insertInOrder x xs) := by\n  induction h with\n  | nil => exact Sorted.single\n  | @single a => \n    simp only [insertInOrder]\n    byCases hxa : x \u2264 a <;> simp only [hxa]\n    case inl => exact Sorted.cons_cons hxa Sorted.single\n    case inr => exact Sorted.cons_cons (antisymm hxa) Sorted.single\n  | @cons_cons a b l hab hbl ih => \n    simp only [insertInOrder]\n    byCases hxa : x \u2264 a <;> simp only [hxa]\n    case inl => exact Sorted.cons_cons hxa (Sorted.cons_cons hab hbl)\n    case inr =>\n      byCases hxb : x \u2264 b <;> simp only [hxb]\n      case inl => exact Sorted.cons_cons (antisymm hxa) (Sorted.cons_cons hxb hbl)\n      case inr =>\n        simp only [insertInOrder, hxb] at ih\n        exact Sorted.cons_cons hab ih\n\n\ntheorem sorted_insertionSort (as : List \u03b1) : Sorted (insertionSort as) := \n  match as with\n  | []      => Sorted.nil\n  | x :: xs => sorted_insertInOrder antisymm (sorted_insertionSort xs)\n\n-- Here's a \"soft\" question: Have we now fully verified that `insertionSort` is a sorting algorithm?\n-- What other property would be an obvious one to verify?\n\n/-\nWe need to show that the resulting list is a permutation of the input.\nOtherwise, `insertionSort (as : List \u03b1) := []` would be a valid sorting algorithm.\n-/\n\n", "meta": {"author": "IPDSnelting", "repo": "tba-2021", "sha": "b6390e55b768423d3266969e81d19290129c5914", "save_path": "github-repos/lean/IPDSnelting-tba-2021", "path": "github-repos/lean/IPDSnelting-tba-2021/tba-2021-b6390e55b768423d3266969e81d19290129c5914/TBA/Solutions/Exercise6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.727047874675814}}
{"text": "/-\nCopyright (c) 2022 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport algebra.star.basic\nimport group_theory.submonoid.operations\n\n/-!\n# Unitary elements of a star monoid\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines `unitary R`, where `R` is a star monoid, as the submonoid made of the elements\nthat satisfy `star U * U = 1` and `U * star U = 1`, and these form a group.\nThis includes, for instance, unitary operators on Hilbert spaces.\n\nSee also `matrix.unitary_group` for specializations to `unitary (matrix n n R)`.\n\n## Tags\n\nunitary\n-/\n\n/--\nIn a *-monoid, `unitary R` is the submonoid consisting of all the elements `U` of\n`R` such that `star U * U = 1` and `U * star U = 1`.\n-/\ndef unitary (R : Type*) [monoid R] [star_semigroup R] : submonoid R :=\n{ carrier := {U | star U * U = 1 \u2227 U * star U = 1},\n  one_mem' := by simp only [mul_one, and_self, set.mem_set_of_eq, star_one],\n  mul_mem' := \u03bb U B \u27e8hA\u2081, hA\u2082\u27e9 \u27e8hB\u2081, hB\u2082\u27e9,\n  begin\n    refine \u27e8_, _\u27e9,\n    { calc star (U * B) * (U * B) = star B * star U * U * B     : by simp only [mul_assoc, star_mul]\n                            ...   = star B * (star U * U) * B   : by rw [\u2190mul_assoc]\n                            ...   = 1                           : by rw [hA\u2081, mul_one, hB\u2081] },\n    { calc U * B * star (U * B) = U * B * (star B * star U)     : by rw [star_mul]\n                            ... = U * (B * star B) * star U     : by simp_rw [\u2190mul_assoc]\n                            ... = 1                             : by rw [hB\u2082, mul_one, hA\u2082] }\n  end }\n\nvariables {R : Type*}\n\nnamespace unitary\n\nsection monoid\nvariables [monoid R] [star_semigroup R]\n\nlemma mem_iff {U : R} : U \u2208 unitary R \u2194 star U * U = 1 \u2227 U * star U = 1 := iff.rfl\n@[simp] lemma star_mul_self_of_mem {U : R} (hU : U \u2208 unitary R) : star U * U = 1 := hU.1\n@[simp] lemma mul_star_self_of_mem {U : R} (hU : U \u2208 unitary R) : U * star U = 1 := hU.2\n\nlemma star_mem {U : R} (hU : U \u2208 unitary R) : star U \u2208 unitary R :=\n\u27e8by rw [star_star, mul_star_self_of_mem hU], by rw [star_star, star_mul_self_of_mem hU]\u27e9\n\n@[simp] lemma star_mem_iff {U : R} : star U \u2208 unitary R \u2194 U \u2208 unitary R :=\n\u27e8\u03bb h, star_star U \u25b8 star_mem h, star_mem\u27e9\n\ninstance : has_star (unitary R) := \u27e8\u03bb U, \u27e8star U, star_mem U.prop\u27e9\u27e9\n\n@[simp, norm_cast] lemma coe_star {U : unitary R} : \u2191(star U) = (star U : R) := rfl\n\nlemma coe_star_mul_self (U : unitary R) : (star U : R) * U = 1 := star_mul_self_of_mem U.prop\nlemma coe_mul_star_self (U : unitary R) :  (U : R) * star U = 1 := mul_star_self_of_mem U.prop\n\n@[simp] lemma star_mul_self (U : unitary R) : star U * U = 1 := subtype.ext $ coe_star_mul_self U\n@[simp] lemma mul_star_self (U : unitary R) : U * star U = 1 := subtype.ext $ coe_mul_star_self U\n\ninstance : group (unitary R) :=\n{ inv := star,\n  mul_left_inv := star_mul_self,\n  ..submonoid.to_monoid _ }\n\ninstance : has_involutive_star (unitary R) :=\n\u27e8\u03bb _, by { ext, simp only [coe_star, star_star] }\u27e9\n\ninstance : star_semigroup (unitary R) :=\n\u27e8\u03bb _ _, by { ext, simp only [coe_star, submonoid.coe_mul, star_mul] }\u27e9\n\ninstance : inhabited (unitary R) := \u27e81\u27e9\n\nlemma star_eq_inv (U : unitary R) : star U = U\u207b\u00b9 := rfl\n\nlemma star_eq_inv' : (star : unitary R \u2192 unitary R) = has_inv.inv := rfl\n\n/-- The unitary elements embed into the units. -/\n@[simps]\ndef to_units : unitary R \u2192* R\u02e3 :=\n{ to_fun := \u03bb x, \u27e8x, \u2191(x\u207b\u00b9), coe_mul_star_self x, coe_star_mul_self x\u27e9,\n  map_one' := units.ext rfl,\n  map_mul' := \u03bb x y, units.ext rfl }\n\nlemma to_units_injective : function.injective (to_units : unitary R \u2192 R\u02e3) :=\n\u03bb x y h, subtype.ext $ units.ext_iff.mp h\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid R] [star_semigroup R]\n\ninstance : comm_group (unitary R) :=\n{ ..unitary.group,\n  ..submonoid.to_comm_monoid _ }\n\nlemma mem_iff_star_mul_self {U : R} : U \u2208 unitary R \u2194 star U * U = 1 :=\nmem_iff.trans $ and_iff_left_of_imp $ \u03bb h, mul_comm (star U) U \u25b8 h\n\nlemma mem_iff_self_mul_star {U : R} : U \u2208 unitary R \u2194 U * star U = 1 :=\nmem_iff.trans $ and_iff_right_of_imp $ \u03bb h, mul_comm U (star U) \u25b8 h\n\nend comm_monoid\n\nsection group_with_zero\nvariables [group_with_zero R] [star_semigroup R]\n\n@[norm_cast] lemma coe_inv (U : unitary R) : \u2191(U\u207b\u00b9) = (U\u207b\u00b9 : R) :=\neq_inv_of_mul_eq_one_right $ coe_mul_star_self _\n\n@[norm_cast] lemma coe_div (U\u2081 U\u2082 : unitary R) : \u2191(U\u2081 / U\u2082) = (U\u2081 / U\u2082 : R) :=\nby simp only [div_eq_mul_inv, coe_inv, submonoid.coe_mul]\n\n@[norm_cast] lemma coe_zpow (U : unitary R) (z : \u2124) : \u2191(U ^ z) = (U ^ z : R) :=\nbegin\n  induction z,\n  { simp [submonoid_class.coe_pow], },\n  { simp [coe_inv] },\nend\n\nend group_with_zero\n\nsection ring\nvariables [ring R] [star_ring R]\n\ninstance : has_neg (unitary R) :=\n{ neg := \u03bb U, \u27e8-U, by { simp_rw [mem_iff, star_neg, neg_mul_neg], exact U.prop }\u27e9 }\n\n@[norm_cast] lemma coe_neg (U : unitary R) : \u2191(-U) = (-U : R) := rfl\n\ninstance : has_distrib_neg (unitary R) :=\nsubtype.coe_injective.has_distrib_neg _ coe_neg (unitary R).coe_mul\n\nend ring\n\nend unitary\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/star/unitary.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105441, "lm_q2_score": 0.8438951025545427, "lm_q1q2_score": 0.7270478636018577}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, S\u00e9bastien Gou\u00ebzel, R\u00e9my Degenne\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.analysis.convex.specific_functions\nimport Mathlib.analysis.special_functions.pow\nimport Mathlib.data.real.conjugate_exponents\nimport Mathlib.tactic.nth_rewrite.default\nimport Mathlib.measure_theory.integration\nimport Mathlib.PostPort\n\nuniverses u u_1 \n\nnamespace Mathlib\n\n/-!\n# Mean value inequalities\n\nIn this file we prove several inequalities, including AM-GM inequality, Young's inequality,\nH\u00f6lder inequality, and Minkowski inequality.\n\n## Main theorems\n\n### AM-GM inequality:\n\nThe inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal\nto their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$\nare two non-negative vectors and $\\sum_{i\\in s} w_i=1$, then\n$$\n\\prod_{i\\in s} z_i^{w_i} \u2264 \\sum_{i\\in s} w_iz_i.\n$$\nThe classical version is a special case of this inequality for $w_i=\\frac{1}{n}$.\n\nWe prove a few versions of this inequality. Each of the following lemmas comes in two versions:\na version for real-valued non-negative functions is in the `real` namespace, and a version for\n`nnreal`-valued functions is in the `nnreal` namespace.\n\n- `geom_mean_le_arith_mean_weighted` : weighted version for functions on `finset`s;\n- `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers;\n- `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers;\n- `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers.\n\n### Generalized mean inequality\n\nThe inequality says that for two non-negative vectors $w$ and $z$ with $\\sum_{i\\in s} w_i=1$\nand $p \u2264 q$ we have\n$$\n\\sqrt[p]{\\sum_{i\\in s} w_i z_i^p} \u2264 \\sqrt[q]{\\sum_{i\\in s} w_i z_i^q}.\n$$\n\nCurrently we only prove this inequality for $p=1$. As in the rest of `mathlib`, we provide\ndifferent theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents\n(`fpow_arith_mean_le_arith_mean_fpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and\n`arith_mean_le_rpow_mean`). In the first two cases we prove\n$$\n\\left(\\sum_{i\\in s} w_i z_i\\right)^n \u2264 \\sum_{i\\in s} w_i z_i^n\n$$\nin order to avoid using real exponents. For real exponents we prove both this and standard versions.\n\n### Young's inequality\n\nYoung's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that\n$\\frac{1}{p}+\\frac{1}{q}=1$ we have\n$$\nab \u2264 \\frac{a^p}{p} + \\frac{b^q}{q}.\n$$\n\nThis inequality is a special case of the AM-GM inequality. It can be used to prove H\u00f6lder's\ninequality (see below) but we use a different proof.\n\n### H\u00f6lder's inequality\n\nThe inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers\nsuch that $\\frac{1}{p}+\\frac{1}{q}=1$) and any two non-negative vectors their inner product is\nless than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the\nsecond vector:\n$$\n\\sum_{i\\in s} a_ib_i \u2264 \\sqrt[p]{\\sum_{i\\in s} a_i^p}\\sqrt[q]{\\sum_{i\\in s} b_i^q}.\n$$\n\nWe give versions of this result in `real`, `nnreal` and `ennreal`.\n\nThere are at least two short proofs of this inequality. In one proof we prenormalize both vectors,\nthen apply Young's inequality to each $a_ib_i$. We use a different proof deducing this inequality\nfrom the generalized mean inequality for well-chosen vectors and weights.\n\nH\u00f6lder's inequality for the Lebesgue integral of ennreal and nnreal functions: we prove\n`\u222b (f * g) \u2202\u03bc \u2264 (\u222b f^p \u2202\u03bc) ^ (1/p) * (\u222b g^q \u2202\u03bc) ^ (1/q)` for `p`, `q` conjugate real exponents\nand `\u03b1\u2192(e)nnreal` functions in two cases,\n* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ennreal functions,\n* `nnreal.lintegral_mul_le_Lp_mul_Lq`  : nnreal functions.\n\n### Minkowski's inequality\n\nThe inequality says that for `p \u2265 1` the function\n$$\n\\|a\\|_p=\\sqrt[p]{\\sum_{i\\in s} a_i^p}\n$$\nsatisfies the triangle inequality $\\|a+b\\|_p\\le \\|a\\|_p+\\|b\\|_p$.\n\nWe give versions of this result in `real`, `nnreal` and `ennreal`.\n\nWe deduce this inequality from H\u00f6lder's inequality. Namely, H\u00f6lder inequality implies that $\\|a\\|_p$\nis the maximum of the inner product $\\sum_{i\\in s}a_ib_i$ over `b` such that $\\|b\\|_q\\le 1$. Now\nMinkowski's inequality follows from the fact that the maximum value of the sum of two functions is\nless than or equal to the sum of the maximum values of the summands.\n\nMinkowski's inequality for the Lebesgue integral of measurable functions with `ennreal` values:\nwe prove `(\u222b (f + g)^p \u2202\u03bc) ^ (1/p) \u2264 (\u222b f^p \u2202\u03bc) ^ (1/p) + (\u222b g^p \u2202\u03bc) ^ (1/p)` for `1 \u2264 p`.\n\n## TODO\n\n- each inequality `A \u2264 B` should come with a theorem `A = B \u2194 _`; one of the ways to prove them\n  is to define `strict_convex_on` functions.\n- generalized mean inequality with any `p \u2264 q`, including negative numbers;\n- prove that the power mean tends to the geometric mean as the exponent tends to zero.\n- prove integral versions of these inequalities.\n\n-/\n\nnamespace real\n\n\n/-- AM-GM inequality: the geometric mean is less than or equal to the arithmetic mean, weighted\nversion for real-valued nonnegative functions. -/\ntheorem geom_mean_le_arith_mean_weighted {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 \u211d) (z : \u03b9 \u2192 \u211d) (hw : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 w i) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) (hz : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 z i) : (finset.prod s fun (i : \u03b9) => z i ^ w i) \u2264 finset.sum s fun (i : \u03b9) => w i * z i := sorry\n\ntheorem pow_arith_mean_le_arith_mean_pow {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 \u211d) (z : \u03b9 \u2192 \u211d) (hw : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 w i) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) (hz : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 z i) (n : \u2115) : (finset.sum s fun (i : \u03b9) => w i * z i) ^ n \u2264 finset.sum s fun (i : \u03b9) => w i * z i ^ n :=\n  convex_on.map_sum_le (convex_on_pow n) hw hw' hz\n\ntheorem pow_arith_mean_le_arith_mean_pow_of_even {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 \u211d) (z : \u03b9 \u2192 \u211d) (hw : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 w i) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) {n : \u2115} (hn : even n) : (finset.sum s fun (i : \u03b9) => w i * z i) ^ n \u2264 finset.sum s fun (i : \u03b9) => w i * z i ^ n :=\n  convex_on.map_sum_le (convex_on_pow_of_even hn) hw hw' fun (_x : \u03b9) (_x : _x \u2208 s) => trivial\n\ntheorem fpow_arith_mean_le_arith_mean_fpow {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 \u211d) (z : \u03b9 \u2192 \u211d) (hw : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 w i) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) (hz : \u2200 (i : \u03b9), i \u2208 s \u2192 0 < z i) (m : \u2124) : (finset.sum s fun (i : \u03b9) => w i * z i) ^ m \u2264 finset.sum s fun (i : \u03b9) => w i * z i ^ m :=\n  convex_on.map_sum_le (convex_on_fpow m) hw hw' hz\n\ntheorem rpow_arith_mean_le_arith_mean_rpow {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 \u211d) (z : \u03b9 \u2192 \u211d) (hw : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 w i) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) (hz : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 z i) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => w i * z i) ^ p \u2264 finset.sum s fun (i : \u03b9) => w i * z i ^ p :=\n  convex_on.map_sum_le (convex_on_rpow hp) hw hw' hz\n\ntheorem arith_mean_le_rpow_mean {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 \u211d) (z : \u03b9 \u2192 \u211d) (hw : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 w i) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) (hz : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 z i) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => w i * z i) \u2264 (finset.sum s fun (i : \u03b9) => w i * z i ^ p) ^ (1 / p) := sorry\n\nend real\n\n\nnamespace nnreal\n\n\n/-- The geometric mean is less than or equal to the arithmetic mean, weighted version\nfor `nnreal`-valued functions. -/\ntheorem geom_mean_le_arith_mean_weighted {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 nnreal) (z : \u03b9 \u2192 nnreal) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) : (finset.prod s fun (i : \u03b9) => z i ^ \u2191(w i)) \u2264 finset.sum s fun (i : \u03b9) => w i * z i := sorry\n\n/-- The geometric mean is less than or equal to the arithmetic mean, weighted version\nfor two `nnreal` numbers. -/\ntheorem geom_mean_le_arith_mean2_weighted (w\u2081 : nnreal) (w\u2082 : nnreal) (p\u2081 : nnreal) (p\u2082 : nnreal) : w\u2081 + w\u2082 = 1 \u2192 p\u2081 ^ \u2191w\u2081 * p\u2082 ^ \u2191w\u2082 \u2264 w\u2081 * p\u2081 + w\u2082 * p\u2082 := sorry\n\ntheorem geom_mean_le_arith_mean3_weighted (w\u2081 : nnreal) (w\u2082 : nnreal) (w\u2083 : nnreal) (p\u2081 : nnreal) (p\u2082 : nnreal) (p\u2083 : nnreal) : w\u2081 + w\u2082 + w\u2083 = 1 \u2192 p\u2081 ^ \u2191w\u2081 * p\u2082 ^ \u2191w\u2082 * p\u2083 ^ \u2191w\u2083 \u2264 w\u2081 * p\u2081 + w\u2082 * p\u2082 + w\u2083 * p\u2083 := sorry\n\ntheorem geom_mean_le_arith_mean4_weighted (w\u2081 : nnreal) (w\u2082 : nnreal) (w\u2083 : nnreal) (w\u2084 : nnreal) (p\u2081 : nnreal) (p\u2082 : nnreal) (p\u2083 : nnreal) (p\u2084 : nnreal) : w\u2081 + w\u2082 + w\u2083 + w\u2084 = 1 \u2192 p\u2081 ^ \u2191w\u2081 * p\u2082 ^ \u2191w\u2082 * p\u2083 ^ \u2191w\u2083 * p\u2084 ^ \u2191w\u2084 \u2264 w\u2081 * p\u2081 + w\u2082 * p\u2082 + w\u2083 * p\u2083 + w\u2084 * p\u2084 := sorry\n\n/-- Weighted generalized mean inequality, version sums over finite sets, with `\u211d\u22650`-valued\nfunctions and natural exponent. -/\ntheorem pow_arith_mean_le_arith_mean_pow {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 nnreal) (z : \u03b9 \u2192 nnreal) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) (n : \u2115) : (finset.sum s fun (i : \u03b9) => w i * z i) ^ n \u2264 finset.sum s fun (i : \u03b9) => w i * z i ^ n := sorry\n\n/-- Weighted generalized mean inequality, version for sums over finite sets, with `\u211d\u22650`-valued\nfunctions and real exponents. -/\ntheorem rpow_arith_mean_le_arith_mean_rpow {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 nnreal) (z : \u03b9 \u2192 nnreal) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => w i * z i) ^ p \u2264 finset.sum s fun (i : \u03b9) => w i * z i ^ p := sorry\n\n/-- Weighted generalized mean inequality, version for two elements of `\u211d\u22650` and real exponents. -/\ntheorem rpow_arith_mean_le_arith_mean2_rpow (w\u2081 : nnreal) (w\u2082 : nnreal) (z\u2081 : nnreal) (z\u2082 : nnreal) (hw' : w\u2081 + w\u2082 = 1) {p : \u211d} (hp : 1 \u2264 p) : (w\u2081 * z\u2081 + w\u2082 * z\u2082) ^ p \u2264 w\u2081 * z\u2081 ^ p + w\u2082 * z\u2082 ^ p := sorry\n\n/-- Weighted generalized mean inequality, version for sums over finite sets, with `\u211d\u22650`-valued\nfunctions and real exponents. -/\ntheorem arith_mean_le_rpow_mean {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 nnreal) (z : \u03b9 \u2192 nnreal) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => w i * z i) \u2264 (finset.sum s fun (i : \u03b9) => w i * z i ^ p) ^ (1 / p) := sorry\n\nend nnreal\n\n\nnamespace ennreal\n\n\n/-- Weighted generalized mean inequality, version for sums over finite sets, with `ennreal`-valued\nfunctions and real exponents. -/\ntheorem rpow_arith_mean_le_arith_mean_rpow {\u03b9 : Type u} (s : finset \u03b9) (w : \u03b9 \u2192 ennreal) (z : \u03b9 \u2192 ennreal) (hw' : (finset.sum s fun (i : \u03b9) => w i) = 1) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => w i * z i) ^ p \u2264 finset.sum s fun (i : \u03b9) => w i * z i ^ p := sorry\n\n/-- Weighted generalized mean inequality, version for two elements of `ennreal` and real\nexponents. -/\ntheorem rpow_arith_mean_le_arith_mean2_rpow (w\u2081 : ennreal) (w\u2082 : ennreal) (z\u2081 : ennreal) (z\u2082 : ennreal) (hw' : w\u2081 + w\u2082 = 1) {p : \u211d} (hp : 1 \u2264 p) : (w\u2081 * z\u2081 + w\u2082 * z\u2082) ^ p \u2264 w\u2081 * z\u2081 ^ p + w\u2082 * z\u2082 ^ p := sorry\n\nend ennreal\n\n\nnamespace real\n\n\ntheorem geom_mean_le_arith_mean2_weighted {w\u2081 : \u211d} {w\u2082 : \u211d} {p\u2081 : \u211d} {p\u2082 : \u211d} (hw\u2081 : 0 \u2264 w\u2081) (hw\u2082 : 0 \u2264 w\u2082) (hp\u2081 : 0 \u2264 p\u2081) (hp\u2082 : 0 \u2264 p\u2082) (hw : w\u2081 + w\u2082 = 1) : p\u2081 ^ w\u2081 * p\u2082 ^ w\u2082 \u2264 w\u2081 * p\u2081 + w\u2082 * p\u2082 :=\n  nnreal.geom_mean_le_arith_mean2_weighted { val := w\u2081, property := hw\u2081 } { val := w\u2082, property := hw\u2082 }\n    { val := p\u2081, property := hp\u2081 } { val := p\u2082, property := hp\u2082 } (iff.mp nnreal.coe_eq hw)\n\ntheorem geom_mean_le_arith_mean3_weighted {w\u2081 : \u211d} {w\u2082 : \u211d} {w\u2083 : \u211d} {p\u2081 : \u211d} {p\u2082 : \u211d} {p\u2083 : \u211d} (hw\u2081 : 0 \u2264 w\u2081) (hw\u2082 : 0 \u2264 w\u2082) (hw\u2083 : 0 \u2264 w\u2083) (hp\u2081 : 0 \u2264 p\u2081) (hp\u2082 : 0 \u2264 p\u2082) (hp\u2083 : 0 \u2264 p\u2083) (hw : w\u2081 + w\u2082 + w\u2083 = 1) : p\u2081 ^ w\u2081 * p\u2082 ^ w\u2082 * p\u2083 ^ w\u2083 \u2264 w\u2081 * p\u2081 + w\u2082 * p\u2082 + w\u2083 * p\u2083 :=\n  nnreal.geom_mean_le_arith_mean3_weighted { val := w\u2081, property := hw\u2081 } { val := w\u2082, property := hw\u2082 }\n    { val := w\u2083, property := hw\u2083 } { val := p\u2081, property := hp\u2081 } { val := p\u2082, property := hp\u2082 }\n    { val := p\u2083, property := hp\u2083 } (iff.mp nnreal.coe_eq hw)\n\ntheorem geom_mean_le_arith_mean4_weighted {w\u2081 : \u211d} {w\u2082 : \u211d} {w\u2083 : \u211d} {w\u2084 : \u211d} {p\u2081 : \u211d} {p\u2082 : \u211d} {p\u2083 : \u211d} {p\u2084 : \u211d} (hw\u2081 : 0 \u2264 w\u2081) (hw\u2082 : 0 \u2264 w\u2082) (hw\u2083 : 0 \u2264 w\u2083) (hw\u2084 : 0 \u2264 w\u2084) (hp\u2081 : 0 \u2264 p\u2081) (hp\u2082 : 0 \u2264 p\u2082) (hp\u2083 : 0 \u2264 p\u2083) (hp\u2084 : 0 \u2264 p\u2084) (hw : w\u2081 + w\u2082 + w\u2083 + w\u2084 = 1) : p\u2081 ^ w\u2081 * p\u2082 ^ w\u2082 * p\u2083 ^ w\u2083 * p\u2084 ^ w\u2084 \u2264 w\u2081 * p\u2081 + w\u2082 * p\u2082 + w\u2083 * p\u2083 + w\u2084 * p\u2084 :=\n  nnreal.geom_mean_le_arith_mean4_weighted { val := w\u2081, property := hw\u2081 } { val := w\u2082, property := hw\u2082 }\n    { val := w\u2083, property := hw\u2083 } { val := w\u2084, property := hw\u2084 } { val := p\u2081, property := hp\u2081 }\n    { val := p\u2082, property := hp\u2082 } { val := p\u2083, property := hp\u2083 } { val := p\u2084, property := hp\u2084 } (iff.mp nnreal.coe_eq hw)\n\n/-- Young's inequality, a version for nonnegative real numbers. -/\ntheorem young_inequality_of_nonneg {a : \u211d} {b : \u211d} {p : \u211d} {q : \u211d} (ha : 0 \u2264 a) (hb : 0 \u2264 b) (hpq : is_conjugate_exponent p q) : a * b \u2264 a ^ p / p + b ^ q / q := sorry\n\n/-- Young's inequality, a version for arbitrary real numbers. -/\ntheorem young_inequality (a : \u211d) (b : \u211d) {p : \u211d} {q : \u211d} (hpq : is_conjugate_exponent p q) : a * b \u2264 abs a ^ p / p + abs b ^ q / q :=\n  le_trans (trans_rel_left LessEq (le_abs_self (a * b)) (abs_mul a b))\n    (young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq)\n\nend real\n\n\nnamespace nnreal\n\n\n/-- Young's inequality, `\u211d\u22650` version. We use `{p q : \u211d\u22650}` in order to avoid constructing\nwitnesses of `0 \u2264 p` and `0 \u2264 q` for the denominators.  -/\ntheorem young_inequality (a : nnreal) (b : nnreal) {p : nnreal} {q : nnreal} (hp : 1 < p) (hpq : 1 / p + 1 / q = 1) : a * b \u2264 a ^ \u2191p / p + b ^ \u2191q / q :=\n  real.young_inequality_of_nonneg (coe_nonneg a) (coe_nonneg b)\n    (real.is_conjugate_exponent.mk hp (iff.mpr nnreal.coe_eq hpq))\n\n/-- Young's inequality, `\u211d\u22650` version with real conjugate exponents. -/\ntheorem young_inequality_real (a : nnreal) (b : nnreal) {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) : a * b \u2264 a ^ p / nnreal.of_real p + b ^ q / nnreal.of_real q := sorry\n\n/-- H\u00f6lder inequality: the scalar product of two functions is bounded by the product of their\n`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,\nwith `\u211d\u22650`-valued functions. -/\ntheorem inner_le_Lp_mul_Lq {\u03b9 : Type u} (s : finset \u03b9) (f : \u03b9 \u2192 nnreal) (g : \u03b9 \u2192 nnreal) {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) : (finset.sum s fun (i : \u03b9) => f i * g i) \u2264\n  (finset.sum s fun (i : \u03b9) => f i ^ p) ^ (1 / p) * (finset.sum s fun (i : \u03b9) => g i ^ q) ^ (1 / q) := sorry\n\n/-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product\n`\u2211 i in s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/\ntheorem is_greatest_Lp {\u03b9 : Type u} (s : finset \u03b9) (f : \u03b9 \u2192 nnreal) {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) : is_greatest\n  ((fun (g : \u03b9 \u2192 nnreal) => finset.sum s fun (i : \u03b9) => f i * g i) ''\n    set_of fun (g : \u03b9 \u2192 nnreal) => (finset.sum s fun (i : \u03b9) => g i ^ q) \u2264 1)\n  ((finset.sum s fun (i : \u03b9) => f i ^ p) ^ (1 / p)) := sorry\n\n/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal\nto the sum of the `L_p`-seminorms of the summands. A version for `nnreal`-valued functions. -/\ntheorem Lp_add_le {\u03b9 : Type u} (s : finset \u03b9) (f : \u03b9 \u2192 nnreal) (g : \u03b9 \u2192 nnreal) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => (f i + g i) ^ p) ^ (1 / p) \u2264\n  (finset.sum s fun (i : \u03b9) => f i ^ p) ^ (1 / p) + (finset.sum s fun (i : \u03b9) => g i ^ p) ^ (1 / p) := sorry\n\nend nnreal\n\n\nnamespace real\n\n\n/-- H\u00f6lder inequality: the scalar product of two functions is bounded by the product of their\n`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,\nwith real-valued functions. -/\ntheorem inner_le_Lp_mul_Lq {\u03b9 : Type u} (s : finset \u03b9) (f : \u03b9 \u2192 \u211d) (g : \u03b9 \u2192 \u211d) {p : \u211d} {q : \u211d} (hpq : is_conjugate_exponent p q) : (finset.sum s fun (i : \u03b9) => f i * g i) \u2264\n  (finset.sum s fun (i : \u03b9) => abs (f i) ^ p) ^ (1 / p) * (finset.sum s fun (i : \u03b9) => abs (g i) ^ q) ^ (1 / q) := sorry\n\n/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal\nto the sum of the `L_p`-seminorms of the summands. A version for `real`-valued functions. -/\ntheorem Lp_add_le {\u03b9 : Type u} (s : finset \u03b9) (f : \u03b9 \u2192 \u211d) (g : \u03b9 \u2192 \u211d) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => abs (f i + g i) ^ p) ^ (1 / p) \u2264\n  (finset.sum s fun (i : \u03b9) => abs (f i) ^ p) ^ (1 / p) + (finset.sum s fun (i : \u03b9) => abs (g i) ^ p) ^ (1 / p) := sorry\n\n/-- H\u00f6lder inequality: the scalar product of two functions is bounded by the product of their\n`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,\nwith real-valued nonnegative functions. -/\ntheorem inner_le_Lp_mul_Lq_of_nonneg {\u03b9 : Type u} (s : finset \u03b9) {f : \u03b9 \u2192 \u211d} {g : \u03b9 \u2192 \u211d} {p : \u211d} {q : \u211d} (hpq : is_conjugate_exponent p q) (hf : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 f i) (hg : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 g i) : (finset.sum s fun (i : \u03b9) => f i * g i) \u2264\n  (finset.sum s fun (i : \u03b9) => f i ^ p) ^ (1 / p) * (finset.sum s fun (i : \u03b9) => g i ^ q) ^ (1 / q) := sorry\n\n/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal\nto the sum of the `L_p`-seminorms of the summands. A version for `real`-valued nonnegative\nfunctions. -/\ntheorem Lp_add_le_of_nonneg {\u03b9 : Type u} (s : finset \u03b9) {f : \u03b9 \u2192 \u211d} {g : \u03b9 \u2192 \u211d} {p : \u211d} (hp : 1 \u2264 p) (hf : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 f i) (hg : \u2200 (i : \u03b9), i \u2208 s \u2192 0 \u2264 g i) : (finset.sum s fun (i : \u03b9) => (f i + g i) ^ p) ^ (1 / p) \u2264\n  (finset.sum s fun (i : \u03b9) => f i ^ p) ^ (1 / p) + (finset.sum s fun (i : \u03b9) => g i ^ p) ^ (1 / p) := sorry\n\nend real\n\n\nnamespace ennreal\n\n\n/-- Young's inequality, `ennreal` version with real conjugate exponents. -/\ntheorem young_inequality (a : ennreal) (b : ennreal) {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) : a * b \u2264 a ^ p / ennreal.of_real p + b ^ q / ennreal.of_real q := sorry\n\n/-- H\u00f6lder inequality: the scalar product of two functions is bounded by the product of their\n`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,\nwith `ennreal`-valued functions. -/\ntheorem inner_le_Lp_mul_Lq {\u03b9 : Type u} (s : finset \u03b9) (f : \u03b9 \u2192 ennreal) (g : \u03b9 \u2192 ennreal) {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) : (finset.sum s fun (i : \u03b9) => f i * g i) \u2264\n  (finset.sum s fun (i : \u03b9) => f i ^ p) ^ (1 / p) * (finset.sum s fun (i : \u03b9) => g i ^ q) ^ (1 / q) := sorry\n\n/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal\nto the sum of the `L_p`-seminorms of the summands. A version for `ennreal` valued nonnegative\nfunctions. -/\ntheorem Lp_add_le {\u03b9 : Type u} (s : finset \u03b9) (f : \u03b9 \u2192 ennreal) (g : \u03b9 \u2192 ennreal) {p : \u211d} (hp : 1 \u2264 p) : (finset.sum s fun (i : \u03b9) => (f i + g i) ^ p) ^ (1 / p) \u2264\n  (finset.sum s fun (i : \u03b9) => f i ^ p) ^ (1 / p) + (finset.sum s fun (i : \u03b9) => g i ^ p) ^ (1 / p) := sorry\n\ntheorem add_rpow_le_rpow_add {p : \u211d} (a : ennreal) (b : ennreal) (hp1 : 1 \u2264 p) : a ^ p + b ^ p \u2264 (a + b) ^ p := sorry\n\ntheorem rpow_add_rpow_le_add {p : \u211d} (a : ennreal) (b : ennreal) (hp1 : 1 \u2264 p) : (a ^ p + b ^ p) ^ (1 / p) \u2264 a + b := sorry\n\ntheorem rpow_add_rpow_le {p : \u211d} {q : \u211d} (a : ennreal) (b : ennreal) (hp_pos : 0 < p) (hpq : p \u2264 q) : (a ^ q + b ^ q) ^ (1 / q) \u2264 (a ^ p + b ^ p) ^ (1 / p) := sorry\n\ntheorem rpow_add_le_add_rpow {p : \u211d} (a : ennreal) (b : ennreal) (hp_pos : 0 < p) (hp1 : p \u2264 1) : (a + b) ^ p \u2264 a ^ p + b ^ p := sorry\n\nend ennreal\n\n\n/-!\n### H\u00f6lder's inequality for the Lebesgue integral of ennreal and nnreal functions\n\nWe prove `\u222b (f * g) \u2202\u03bc \u2264 (\u222b f^p \u2202\u03bc) ^ (1/p) * (\u222b g^q \u2202\u03bc) ^ (1/q)` for `p`, `q`\nconjugate real exponents and `\u03b1\u2192(e)nnreal` functions in several cases, the first two being useful\nonly to prove the more general results:\n* `ennreal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ennreal functions for which the\n    integrals on the right are equal to 1,\n* `ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ennreal functions for which the\n    integrals on the right are neither \u22a4 nor 0,\n* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ennreal functions,\n* `nnreal.lintegral_mul_le_Lp_mul_Lq`  : nnreal functions.\n-/\n\nnamespace ennreal\n\n\ntheorem lintegral_mul_le_one_of_lintegral_rpow_eq_one {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hg : ae_measurable g) (hf_norm : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) = 1) (hg_norm : (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ q) = 1) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Mul.mul f g a) \u2264 1 := sorry\n\n/-- Function multiplied by the inverse of its p-seminorm `(\u222b\u207b f^p \u2202\u03bc) ^ 1/p`-/\ndef fun_mul_inv_snorm {\u03b1 : Type u_1} [measurable_space \u03b1] (f : \u03b1 \u2192 ennreal) (p : \u211d) (\u03bc : measure_theory.measure \u03b1) : \u03b1 \u2192 ennreal :=\n  fun (a : \u03b1) => f a * ((measure_theory.lintegral \u03bc fun (c : \u03b1) => f c ^ p) ^ (1 / p)\u207b\u00b9)\n\ntheorem fun_eq_fun_mul_inv_snorm_mul_snorm {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} (f : \u03b1 \u2192 ennreal) (hf_nonzero : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 0) (hf_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 \u22a4) {a : \u03b1} : f a = fun_mul_inv_snorm f p \u03bc a * (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) ^ (1 / p) := sorry\n\ntheorem fun_mul_inv_snorm_rpow {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} (hp0 : 0 < p) {f : \u03b1 \u2192 ennreal} {a : \u03b1} : fun_mul_inv_snorm f p \u03bc a ^ p = f a ^ p * ((measure_theory.lintegral \u03bc fun (c : \u03b1) => f c ^ p)\u207b\u00b9) := sorry\n\ntheorem lintegral_rpow_fun_mul_inv_snorm_eq_one {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} (hp0_lt : 0 < p) {f : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hf_nonzero : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 0) (hf_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 \u22a4) : (measure_theory.lintegral \u03bc fun (c : \u03b1) => fun_mul_inv_snorm f p \u03bc c ^ p) = 1 := sorry\n\n/-- H\u00f6lder's inequality in case of finite non-zero integrals -/\ntheorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hg : ae_measurable g) (hf_nontop : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 \u22a4) (hg_nontop : (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ q) \u2260 \u22a4) (hf_nonzero : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 0) (hg_nonzero : (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ q) \u2260 0) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Mul.mul f g a) \u2264\n  (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) ^ (1 / p) *\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ q) ^ (1 / q) := sorry\n\ntheorem ae_eq_zero_of_lintegral_rpow_eq_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} (hp0_lt : 0 < p) {f : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hf_zero : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) = 0) : filter.eventually_eq (measure_theory.measure.ae \u03bc) f 0 := sorry\n\ntheorem lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} (hp0_lt : 0 < p) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hf_zero : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) = 0) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Mul.mul f g a) = 0 := sorry\n\ntheorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {q : \u211d} (hp0_lt : 0 < p) (hq0 : 0 \u2264 q) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) = \u22a4) (hg_nonzero : (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ q) \u2260 0) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Mul.mul f g a) \u2264\n  (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) ^ (1 / p) *\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ q) ^ (1 / q) := sorry\n\n/-- H\u00f6lder's inequality for functions `\u03b1 \u2192 ennreal`. The integral of the product of two functions\nis bounded by the product of their `\u2112p` and `\u2112q` seminorms when `p` and `q` are conjugate\nexponents. -/\ntheorem lintegral_mul_le_Lp_mul_Lq {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure_theory.measure \u03b1) {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hg : ae_measurable g) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Mul.mul f g a) \u2264\n  (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) ^ (1 / p) *\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ q) ^ (1 / q) := sorry\n\ntheorem lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hf_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) < \u22a4) (hg : ae_measurable g) (hg_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ p) < \u22a4) (hp1 : 1 \u2264 p) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Add.add f g a ^ p) < \u22a4 := sorry\n\ntheorem lintegral_Lp_mul_le_Lq_mul_Lr {\u03b1 : Type u_1} [measurable_space \u03b1] {p : \u211d} {q : \u211d} {r : \u211d} (hp0_lt : 0 < p) (hpq : p < q) (hpqr : 1 / p = 1 / q + 1 / r) (\u03bc : measure_theory.measure \u03b1) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hg : ae_measurable g) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Mul.mul f g a ^ p) ^ (1 / p) \u2264\n  (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ q) ^ (1 / q) *\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ r) ^ (1 / r) := sorry\n\ntheorem lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hg : ae_measurable g) (hf_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 \u22a4) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a * g a ^ (p - 1)) \u2264\n  (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) ^ (1 / p) *\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ p) ^ (1 / q) := sorry\n\ntheorem lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hf_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) \u2260 \u22a4) (hg : ae_measurable g) (hg_top : (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ p) \u2260 \u22a4) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Add.add f g a ^ p) \u2264\n  ((measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) ^ (1 / p) +\n      (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ p) ^ (1 / p)) *\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => (f a + g a) ^ p) ^ (1 / q) := sorry\n\n/-- Minkowski's inequality for functions `\u03b1 \u2192 ennreal`: the `\u2112p` seminorm of the sum of two\nfunctions is bounded by the sum of their `\u2112p` seminorms. -/\ntheorem lintegral_Lp_add_le {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {f : \u03b1 \u2192 ennreal} {g : \u03b1 \u2192 ennreal} (hf : ae_measurable f) (hg : ae_measurable g) (hp1 : 1 \u2264 p) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => Add.add f g a ^ p) ^ (1 / p) \u2264\n  (measure_theory.lintegral \u03bc fun (a : \u03b1) => f a ^ p) ^ (1 / p) +\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => g a ^ p) ^ (1 / p) := sorry\n\nend ennreal\n\n\n/-- H\u00f6lder's inequality for functions `\u03b1 \u2192 \u211d\u22650`. The integral of the product of two functions\nis bounded by the product of their `\u2112p` and `\u2112q` seminorms when `p` and `q` are conjugate\nexponents. -/\ntheorem nnreal.lintegral_mul_le_Lp_mul_Lq {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} {p : \u211d} {q : \u211d} (hpq : real.is_conjugate_exponent p q) {f : \u03b1 \u2192 nnreal} {g : \u03b1 \u2192 nnreal} (hf : ae_measurable f) (hg : ae_measurable g) : (measure_theory.lintegral \u03bc fun (a : \u03b1) => \u2191(Mul.mul f g a)) \u2264\n  (measure_theory.lintegral \u03bc fun (a : \u03b1) => \u2191(f a) ^ p) ^ (1 / p) *\n    (measure_theory.lintegral \u03bc fun (a : \u03b1) => \u2191(g a) ^ q) ^ (1 / q) := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/analysis/mean_inequalities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7270478598371356}}
{"text": "/-\nCopyright (c) 2020 Gihan Marasingha. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gihan Marasingha\n-/\nimport .decision_nec\nimport tactic.linarith\n\n/-!\n# Decision procedure - sufficient condition and decidability\n\nWe give a sufficient condition for a string to be derivable in the MIU language. Together with the\nnecessary condition, we use this to prove that `derivable` is an instance of `decidable_pred`.\n\nLet `count I st` and `count U st` denote the number of `I`s (respectively `U`s) in `st : miustr`.\n\nWe'll show that `st` is derivable if it has the form `M::x` where `x` is a string of `I`s and `U`s\nfor which `count I x` is congruent to 1 or 2 modulo 3.\n\nTo prove this, it suffices to show `derivable M::y` where `y` is any `miustr` consisting only of\n`I`s such that the number of `I`s in `y` is `a+3b`, where `a = count I x` and `b = count U x`.\nThis suffices because Rule 3 permits us to change any string of three consecutive `I`s into a `U`.\n\nAs `count I y = (count I x) + 3*(count U x) \u2261 (count I x) [MOD 3]`, it suffices to show\n`derivable M::z` where `z` is an `miustr` of `I`s such that `count I z` is congruent to\n1 or 2 modulo 3.\n\nLet `z` be such an `miustr` and let `c` denote `count I z`, so `c \u2261 1 or 2 [MOD 3]`.\nTo derive such an `miustr`, it suffices to derive an `miustr` `M::w`, where again w is an\n`miustr` of only `I`s with the additional conditions that `count I w` is a power of 2, that\n`count I w \u2265 c` and that `count I w \u2261 c [MOD 3]`.\n\nTo see that this suffices, note that we can remove triples of `I`s from the end of `M::w`,\ncreating `U`s as we go along. Once the number of `I`s equals `m`, we remove `U`s two at a time\nuntil we have no `U`s. The only issue is that we may begin the removal process with an odd number\nof `U`s.\n\nWriting `d = count I w`, we see that this happens if and only if `(d-c)/3` is odd.\nIn this case, we must apply Rule 1 to `z`, prior to removing triples of `I`s. We thereby\nintroduce an additional `U` and ensure that the final number of `U`s will be even.\n\n## Tags\n\nmiu, decision procedure, decidability, decidable_pred, decidable\n-/\n\nnamespace miu\n\nopen miu_atom list nat\n\n/--\nWe start by showing that an `miustr` `M::w` can be derived, where `w` consists only of `I`s and\nwhere `count I w` is a power of 2.\n-/\nprivate lemma der_cons_replicate (n : \u2115) : derivable (M::(replicate (2^n) I)) :=\nbegin\n  induction n with k hk,\n  { constructor, }, -- base case\n  { rw [succ_eq_add_one, pow_add, pow_one 2, mul_two,replicate_add], -- inductive step\n    exact derivable.r2 hk, },\nend\n\n/-!\n## Converting `I`s to `U`s\n\nFor any given natural number `c \u2261 1 or 2 [MOD 3]`, we need to show that can derive an `miustr`\n`M::w` where `w` consists only of `I`s,  where `d = count I w` is a power of 2, where `d \u2265 c` and\nwhere `d \u2261 c [MOD 3]`.\n\nGiven the above lemmas, the desired result reduces to an arithmetic result, given in the file\n`arithmetic.lean`.\n\nWe'll use this result to show we can derive an `miustr` of the form `M::z` where `z` is an string\nconsisting only of `I`s such that `count I z \u2261 1 or 2 [MOD 3]`.\n\nAs an intermediate step, we show that derive `z` from `zt`, where `t` is aN `miustr` consisting of\nan even number of `U`s and `z` is any `miustr`.\n-/\n\n/--\nAny number of successive occurrences of `\"UU\"` can be removed from the end of a `derivable` `miustr`\nto produce another `derivable` `miustr`.\n-/\nlemma der_of_der_append_replicate_U_even {z : miustr} {m : \u2115}\n  (h : derivable (z ++ replicate (m*2) U)) : derivable z :=\nbegin\n  induction m with k hk,\n  { revert h,\n    simp only [list.replicate, zero_mul, append_nil, imp_self], },\n  { apply hk,\n    simp only [succ_mul, replicate_add] at h,\n    change replicate 2 U with [U,U] at h,\n    rw \u2190(append_nil (z ++ replicate (k*2) U)),\n    apply derivable.r4,\n    simp only [append_nil, append_assoc,h], },\nend\n\n/-!\nIn fine-tuning my application of `simp`, I issued the following commend to determine which lemmas\n`simp` uses.\n\n`set_option trace.simplify.rewrite true`\n-/\n\n/--\nWe may replace several consecutive occurrences of  `\"III\"` with the same number of `\"U\"`s.\nIn application of the following lemma, `xs` will either be `[]` or `[U]`.\n-/\nlemma der_cons_replicate_I_replicate_U_append_of_der_cons_replicate_I_append (c k : \u2115)\n  (hc : c % 3 = 1 \u2228 c % 3 = 2) (xs : miustr) (hder : derivable (M ::(replicate (c+3*k) I) ++ xs)) :\n    derivable (M::(replicate c I ++ replicate k U) ++ xs) :=\nbegin\n  revert xs,\n  induction k with a ha,\n  { simp only [list.replicate, mul_zero, add_zero, append_nil, forall_true_iff, imp_self],},\n  { intro xs,\n    specialize ha (U::xs),\n    intro h\u2082,\n    simp only [succ_eq_add_one, replicate_add], -- We massage the goal\n    rw [\u2190append_assoc, \u2190cons_append],        -- into a form amenable\n    change replicate 1 U with [U],             -- to the application of\n    rw [append_assoc, singleton_append],     -- ha.\n    apply ha,\n    apply derivable.r3,\n    change [I,I,I] with replicate 3 I,\n    simp only [cons_append, \u2190replicate_add],\n    convert h\u2082, },\nend\n\n/-!\n### Arithmetic\n\nWe collect purely arithmetic lemmas: `add_mod2` is used to ensure we have an even number of `U`s\nwhile `le_pow2_and_pow2_eq_mod3` treats the congruence condition modulo 3.\n-/\nsection arithmetic\n\n/--\nFor every `a`, the number `a + a % 2` is even.\n-/\nlemma add_mod2 (a : \u2115) : \u2203 t, a + a % 2 = t*2 :=\nbegin\n  simp only [mul_comm _ 2], -- write `t*2` as `2*t`\n  apply dvd_of_mod_eq_zero, -- it suffices to prove `(a + a % 2) % 2 = 0`\n  rw [add_mod, mod_mod, \u2190two_mul, mul_mod_right],\nend\n\nprivate lemma le_pow2_and_pow2_eq_mod3' (c : \u2115) (x : \u2115) (h : c = 1 \u2228 c = 2) :\n  \u2203 m : \u2115, c + 3*x \u2264 2^m \u2227 2^m % 3 = c % 3 :=\nbegin\n  induction x with k hk,\n  { use (c+1),\n    cases h with hc hc;\n    { rw hc, norm_num }, },\n  rcases hk with \u27e8g, hkg, hgmod\u27e9,\n  by_cases hp : (c + 3*(k+1) \u2264 2 ^g),\n  { use g, exact \u27e8hp, hgmod\u27e9 },\n  refine \u27e8g + 2, _, _\u27e9,\n  { rw [mul_succ, \u2190add_assoc, pow_add],\n    change 2^2 with (1+3), rw [mul_add (2^g) 1 3, mul_one],\n    linarith [hkg, one_le_two_pow g], },\n  { rw [pow_add, \u2190mul_one c],\n    exact modeq.mul hgmod rfl }\nend\n\n/--\nIf `a` is 1 or 2 modulo 3, then exists `k` a power of 2 for which `a \u2264 k` and `a \u2261 k [MOD 3]`.\n-/\nlemma le_pow2_and_pow2_eq_mod3 (a : \u2115) (h : a % 3 = 1 \u2228 a % 3 = 2) :\n  \u2203 m : \u2115, a \u2264 2^m \u2227 2^m % 3 = a % 3:=\nbegin\n  cases le_pow2_and_pow2_eq_mod3' (a%3) (a/3) h with m hm,\n  use m,\n  split,\n  { convert hm.1, exact (mod_add_div a 3).symm, },\n  { rw [hm.2, mod_mod _ 3], },\nend\n\nend arithmetic\n\nlemma replicate_pow_minus_append  {m : \u2115} :\n  M :: replicate (2^m - 1) I ++ [I] = M::(replicate (2^m) I) :=\nbegin\n  change [I] with replicate 1 I,\n  rw [cons_append, \u2190replicate_add, tsub_add_cancel_of_le (one_le_pow' m 1)],\nend\n\n/--\n`der_replicate_I_of_mod3` states that `M::y` is `derivable` if `y` is any `miustr` consisiting just\nof `I`s, where `count I y` is 1 or 2 modulo 3.\n-/\nlemma der_replicate_I_of_mod3 (c : \u2115) (h : c % 3 = 1 \u2228 c % 3 = 2):\n  derivable (M::(replicate c I)) :=\nbegin\n  -- From `der_cons_replicate`, we can derive the `miustr` `M::w` described in the introduction.\n  cases (le_pow2_and_pow2_eq_mod3 c h) with m hm, -- `2^m` will be  the number of `I`s in `M::w`\n  have hw\u2082 : derivable (M::(replicate (2^m) I) ++ replicate ((2^m -c)/3 % 2) U),\n  { cases mod_two_eq_zero_or_one ((2^m -c)/3) with h_zero h_one,\n    { -- `(2^m - c)/3 \u2261 0 [MOD 2]`\n      simp only [der_cons_replicate m, append_nil,list.replicate, h_zero], },\n    { rw [h_one, \u2190replicate_pow_minus_append, append_assoc], -- case `(2^m - c)/3 \u2261 1 [MOD 2]`\n      apply derivable.r1,\n      rw replicate_pow_minus_append,\n      exact (der_cons_replicate m), }, },\n  have hw\u2083 :\n    derivable (M::(replicate c I) ++ replicate ((2^m-c)/3) U ++ replicate ((2^m-c)/3 % 2) U),\n  { apply der_cons_replicate_I_replicate_U_append_of_der_cons_replicate_I_append c ((2^m-c)/3) h,\n    convert hw\u2082, -- now we must show `c + 3 * ((2 ^ m - c) / 3) = 2 ^ m`\n    rw nat.mul_div_cancel',\n    { exact add_tsub_cancel_of_le hm.1 },\n    { exact (modeq_iff_dvd' hm.1).mp hm.2.symm } },\n  rw [append_assoc, \u2190replicate_add _ _] at hw\u2083,\n  cases add_mod2 ((2^m-c)/3) with t ht,\n  rw ht at hw\u2083,\n  exact der_of_der_append_replicate_U_even hw\u2083,\nend\n\nexample (c : \u2115) (h : c % 3 = 1 \u2228 c % 3 = 2):\n  derivable (M::(replicate c I)) :=\nbegin\n  -- From `der_cons_replicate`, we can derive the `miustr` `M::w` described in the introduction.\n  cases (le_pow2_and_pow2_eq_mod3 c h) with m hm, -- `2^m` will be  the number of `I`s in `M::w`\n  have hw\u2082 : derivable (M::(replicate (2^m) I) ++ replicate ((2^m -c)/3 % 2) U),\n  { cases mod_two_eq_zero_or_one ((2^m -c)/3) with h_zero h_one,\n    { -- `(2^m - c)/3 \u2261 0 [MOD 2]`\n      simp only [der_cons_replicate m, append_nil, list.replicate, h_zero] },\n    { rw [h_one, \u2190replicate_pow_minus_append, append_assoc], -- case `(2^m - c)/3 \u2261 1 [MOD 2]`\n      apply derivable.r1,\n      rw replicate_pow_minus_append,\n      exact (der_cons_replicate m), }, },\n  have hw\u2083 :\n    derivable (M::(replicate c I) ++ replicate ((2^m-c)/3) U ++ replicate ((2^m-c)/3 % 2) U),\n  { apply der_cons_replicate_I_replicate_U_append_of_der_cons_replicate_I_append c ((2^m-c)/3) h,\n    convert hw\u2082, -- now we must show `c + 3 * ((2 ^ m - c) / 3) = 2 ^ m`\n    rw nat.mul_div_cancel',\n    { exact add_tsub_cancel_of_le hm.1 },\n    { exact (modeq_iff_dvd' hm.1).mp hm.2.symm } },\n  rw [append_assoc, \u2190replicate_add _ _] at hw\u2083,\n  cases add_mod2 ((2^m-c)/3) with t ht,\n  rw ht at hw\u2083,\n  exact der_of_der_append_replicate_U_even hw\u2083,\nend\n\n/-!\n### `decstr` is a sufficient condition\n\nThe remainder of this file sets up the proof that `dectstr en` is sufficent to ensure\n`derivable en`. Decidability of `derivable en` is an easy consequence.\n\nThe proof proceeds by induction on the `count U` of `en`.\n\nWe tackle first the base case of the induction. This requires auxiliary results giving\nconditions under which  `count I ys = length ys`.\n-/\n\n/--\nIf an `miustr` has a zero `count U` and contains no `M`, then its `count I` is its length.\n-/\nlemma count_I_eq_length_of_count_U_zero_and_neg_mem {ys : miustr} (hu : count U ys = 0)\n  (hm : M \u2209 ys) : count I ys = length ys :=\nbegin\n  induction ys with x xs hxs,\n  { refl, },\n  { cases x,\n    { exfalso, exact hm (mem_cons_self M xs), }, -- case `x = M` gives a contradiction.\n    { rw [count_cons, if_pos (rfl), length, succ_eq_add_one, succ_inj'], -- case `x = I`\n      apply hxs,\n      { simpa only [count], },\n      { simp only [mem_cons_iff,false_or] at hm, exact hm, }, },\n    { exfalso, simp only [count, countp_cons_of_pos] at hu,  -- case `x = U` gives a contradiction.\n      exact succ_ne_zero _ hu, }, },\nend\n\n/--\n`base_case_suf` is the base case of the sufficiency result.\n-/\nlemma base_case_suf (en : miustr) (h : decstr en) (hu : count U en = 0) : derivable en :=\nbegin\n  rcases h with \u27e8\u27e8mhead, nmtail\u27e9, hi \u27e9,\n  have : en \u2260 nil,\n  { intro k, simp only [k, count, countp, if_false, zero_mod, zero_ne_one, false_or] at hi,\n    contradiction, },\n  rcases (exists_cons_of_ne_nil this) with \u27e8y,ys,rfl\u27e9,\n  rw head at mhead,\n  rw mhead at *,\n  rsuffices \u27e8c, rfl, hc\u27e9 : \u2203 c, replicate c I = ys \u2227 (c % 3 = 1 \u2228 c % 3 = 2),\n  { exact der_replicate_I_of_mod3 c hc, },\n  { simp only [count] at *,\n    use (count I ys),\n    refine and.intro _ hi,\n    apply replicate_count_eq_of_count_eq_length,\n    exact count_I_eq_length_of_count_U_zero_and_neg_mem hu nmtail, },\nend\n\n/-!\nBefore continuing to the proof of the induction step, we need other auxiliary results that\nrelate to `count U`.\n-/\nlemma mem_of_count_U_eq_succ {xs : miustr} {k : \u2115} (h : count U xs = succ k) : U \u2208 xs :=\nbegin\n  induction xs with z zs hzs,\n  { exfalso, rw count at h, contradiction, },\n  { simp only [mem_cons_iff],\n    cases z,\n    repeat -- cases `z = M` and `z=I`\n    { right, apply hzs, simp only [count, countp, if_false] at h, rw \u2190h, refl, },\n    { left, refl, }, }, -- case `z = U`\nend\n\nlemma eq_append_cons_U_of_count_U_pos {k : \u2115} {zs : miustr} (h : count U zs = succ k) :\n\u2203 (as bs : miustr), (zs = as ++ U :: bs) :=\nmem_split (mem_of_count_U_eq_succ h)\n\n/--\n`ind_hyp_suf` is the inductive step of the sufficiency result.\n -/\nlemma ind_hyp_suf (k : \u2115) (ys : miustr) (hu : count U ys = succ k) (hdec : decstr ys) :\n\u2203 (as bs : miustr), (ys = M::as ++ U:: bs) \u2227 (count U (M::as ++ [I,I,I] ++ bs) = k) \u2227\n  decstr (M::as ++ [I,I,I] ++ bs) :=\nbegin\n  rcases hdec with \u27e8\u27e8mhead,nmtail\u27e9, hic\u27e9,\n  have : ys \u2260 nil,\n  { intro k, simp only [k ,count, countp, zero_mod, false_or, zero_ne_one] at hic, contradiction, },\n  rcases (exists_cons_of_ne_nil this) with \u27e8z,zs,rfl\u27e9,\n  rw head at mhead,\n  rw mhead at *,\n  simp only [count, countp, cons_append, if_false, countp_append] at *,\n  rcases (eq_append_cons_U_of_count_U_pos hu) with \u27e8as,bs,hab\u27e9,\n  rw hab at *,\n  simp only [countp, cons_append, if_pos, if_false, countp_append] at *,\n  use [as,bs],\n  apply and.intro rfl (and.intro (succ.inj hu) _),\n  split,\n  { apply and.intro rfl,\n    simp only [tail, mem_append, mem_cons_iff, false_or, not_mem_nil, or_false] at *,\n    exact nmtail, },\n  { simp only [count, countp, cons_append, if_false, countp_append, if_pos],\n    rw [add_right_comm, add_mod_right], exact hic, },\nend\n\n/--\n`der_of_decstr` states that `derivable en` follows from `decstr en`.\n-/\ntheorem der_of_decstr {en : miustr} (h : decstr en) : derivable en :=\nbegin\n/- The next three lines have the effect of introducing `count U en` as a variable that can be used\n for induction -/\n  have hu : \u2203 n, count U en = n := exists_eq',\n  cases hu with n hu,\n  revert en, /- Crucially, we need the induction hypothesis to quantify over `en` -/\n  induction n with k hk,\n  { exact base_case_suf, },\n  { intros ys hdec hus,\n    rcases ind_hyp_suf k ys hus hdec with \u27e8as, bs, hyab, habuc, hdecab\u27e9,\n    have h\u2082 : derivable (M::as ++ [I,I,I] ++ bs) := hk hdecab habuc,\n    rw hyab,\n    exact derivable.r3 h\u2082, },\nend\n\n/-!\n### Decidability of `derivable`\n-/\n\n/--\nFinally, we have the main result, namely that `derivable` is a decidable predicate.\n-/\ninstance : decidable_pred derivable :=\n\u03bb en, decidable_of_iff _ \u27e8der_of_decstr, decstr_of_der\u27e9\n\n/-!\nBy decidability, we can automatically determine whether any given `miustr` is `derivable`.\n-/\n\nexample : \u00ac(derivable \"MU\") :=\ndec_trivial\n\nexample : derivable \"MUIUIUIIIIIUUUIUII\" :=\ndec_trivial\n\nend miu\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/miu_language/decision_suf.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7270333496398642}}
{"text": "/-\nCopyright (c) 2021 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\n\nimport data.fin.basic\nimport data.finset.sort\nimport order.lexicographic\n\n/-!\n\n# Sorting tuples by their values\n\nGiven an `n`-tuple `f : fin n \u2192 \u03b1` where `\u03b1` is ordered,\nwe may want to turn it into a sorted `n`-tuple.\nThis file provides an API for doing so, with the sorted `n`-tuple given by\n`f \u2218 tuple.sort f`.\n\n## Main declarations\n\n* `tuple.sort`: given `f : fin n \u2192 \u03b1`, produces a permutation on `fin n`\n* `tuple.monotone_sort`: `f \u2218 tuple.sort f` is `monotone`\n\n-/\n\nnamespace tuple\n\nvariables {n : \u2115}\nvariables {\u03b1 : Type*} [linear_order \u03b1]\n\n/--\n`graph f` produces the finset of pairs `(f i, i)`\nequipped with the lexicographic order.\n-/\ndef graph (f : fin n \u2192 \u03b1) : finset (\u03b1 \u00d7\u2097 (fin n)) :=\nfinset.univ.image (\u03bb i, (f i, i))\n\n/--\nGiven `p : \u03b1 \u00d7\u2097 (fin n) := (f i, i)` with `p \u2208 graph f`,\n`graph.proj p` is defined to be `f i`.\n-/\ndef graph.proj {f : fin n \u2192 \u03b1} : graph f \u2192 \u03b1 := \u03bb p, p.1.1\n\n@[simp] lemma graph.card (f : fin n \u2192 \u03b1) : (graph f).card = n :=\nbegin\n  rw [graph, finset.card_image_of_injective],\n  { exact finset.card_fin _ },\n  { intros _ _,\n    simp }\nend\n\n/--\n`graph_equiv\u2081 f` is the natural equivalence between `fin n` and `graph f`,\nmapping `i` to `(f i, i)`. -/\ndef graph_equiv\u2081 (f : fin n \u2192 \u03b1) : fin n \u2243 graph f :=\n{ to_fun := \u03bb i, \u27e8(f i, i), by simp [graph]\u27e9,\n  inv_fun := \u03bb p, p.1.2,\n  left_inv := \u03bb i, by simp,\n  right_inv := \u03bb \u27e8\u27e8x, i\u27e9, h\u27e9, by simpa [graph] using h }\n\n@[simp] lemma proj_equiv\u2081' (f : fin n \u2192 \u03b1) : graph.proj \u2218 graph_equiv\u2081 f = f :=\nrfl\n\n/--\n`graph_equiv\u2082 f` is an equivalence between `fin n` and `graph f` that respects the order.\n-/\ndef graph_equiv\u2082 (f : fin n \u2192 \u03b1) : fin n \u2243o graph f :=\nfinset.order_iso_of_fin _ (by simp)\n\n/-- `sort f` is the permutation that orders `fin n` according to the order of the outputs of `f`. -/\ndef sort (f : fin n \u2192 \u03b1) : equiv.perm (fin n) :=\n(graph_equiv\u2082 f).to_equiv.trans (graph_equiv\u2081 f).symm\n\nlemma self_comp_sort (f : fin n \u2192 \u03b1) : f \u2218 sort f = graph.proj \u2218 graph_equiv\u2082 f :=\nshow graph.proj \u2218 ((graph_equiv\u2081 f) \u2218 (graph_equiv\u2081 f).symm) \u2218 (graph_equiv\u2082 f).to_equiv = _,\n  by simp\n\n\nlemma monotone_proj (f : fin n \u2192 \u03b1) : monotone (graph.proj : graph f \u2192 \u03b1) :=\nbegin\n  rintro \u27e8\u27e8x, i\u27e9, hx\u27e9 \u27e8\u27e8y, j\u27e9, hy\u27e9 (h|h),\n  { exact le_of_lt \u2039_\u203a },\n  { simp [graph.proj] },\nend\n\nlemma monotone_sort (f : fin n \u2192 \u03b1) : monotone (f \u2218 sort f) :=\nbegin\n  rw [self_comp_sort],\n  exact (monotone_proj f).comp (graph_equiv\u2082 f).monotone,\nend\n\nend tuple\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/fin/tuple/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.727005301493106}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.box_integral.box.subbox_induction\nimport analysis.box_integral.partition.tagged\n\n/-!\n# Induction on subboxes\n\nIn this file we prove (see\n`box_integral.tagged_partition.exists_is_Henstock_is_subordinate_homothetic`) that for every box `I`\nin `\u211d\u207f` and a function `r : \u211d\u207f \u2192 \u211d` positive on `I` there exists a tagged partition `\u03c0` of `I` such\nthat\n\n* `\u03c0` is a Henstock partition;\n* `\u03c0` is subordinate to `r`;\n* each box in `\u03c0` is homothetic to `I` with coefficient of the form `1 / 2 ^ n`.\n\nLater we will use this lemma to prove that the Henstock filter is nontrivial, hence the Henstock\nintegral is well-defined.\n\n## Tags\n\npartition, tagged partition, Henstock integral\n-/\n\nnamespace box_integral\n\nopen set metric\nopen_locale classical topological_space\nnoncomputable theory\n\nvariables {\u03b9 : Type*} [fintype \u03b9] {I J : box \u03b9}\n\nnamespace prepartition\n\n/-- Split a box in `\u211d\u207f` into `2 ^ n` boxes by hyperplanes passing through its center. -/\ndef split_center (I : box \u03b9) : prepartition I :=\n{ boxes := finset.univ.map (box.split_center_box_emb I),\n  le_of_mem' := by simp [I.split_center_box_le],\n  pairwise_disjoint :=\n    begin\n      rw [finset.coe_map, finset.coe_univ, image_univ],\n      rintro _ \u27e8s, rfl\u27e9 _ \u27e8t, rfl\u27e9 Hne,\n      exact I.disjoint_split_center_box (mt (congr_arg _) Hne)\n    end }\n\n@[simp] lemma mem_split_center : J \u2208 split_center I \u2194 \u2203 s, I.split_center_box s = J :=\nby simp [split_center]\n\nlemma is_partition_split_center (I : box \u03b9) : is_partition (split_center I) :=\n\u03bb x hx, by simp [hx]\n\nlemma upper_sub_lower_of_mem_split_center (h : J \u2208 split_center I) (i : \u03b9) :\n  J.upper i - J.lower i = (I.upper i - I.lower i) / 2 :=\nlet \u27e8s, hs\u27e9 := mem_split_center.1 h in hs \u25b8 I.upper_sub_lower_split_center_box s i\n\nend prepartition\n\nnamespace box\n\nopen prepartition tagged_prepartition\n\n/-- Let `p` be a predicate on `box \u03b9`, let `I` be a box. Suppose that the following two properties\nhold true.\n\n* Consider a smaller box `J \u2264 I`. The hyperplanes passing through the center of `J` split it into\n  `2 ^ n` boxes. If `p` holds true on each of these boxes, then it true on `J`.\n* For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such\n  that for every box `J \u2264 I` such that `z \u2208 J.Icc \u2286 U`, if `J` is homothetic to `I` with a\n  coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`.\n\nThen `p I` is true. See also `box_integral.box.subbox_induction_on'` for a version using\n`box_integral.box.split_center_box` instead of `box_integral.prepartition.split_center`. -/\n@[elab_as_eliminator]\nlemma subbox_induction_on {p : box \u03b9 \u2192 Prop} (I : box \u03b9)\n  (H_ind : \u2200 J \u2264 I, (\u2200 J' \u2208 split_center J, p J') \u2192 p J)\n  (H_nhds : \u2200 z \u2208 I.Icc, \u2203 (U \u2208 \ud835\udcdd[I.Icc] z), \u2200 (J \u2264 I) (m : \u2115), z \u2208 J.Icc \u2192 J.Icc \u2286 U \u2192\n    (\u2200 i, J.upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) \u2192 p J) :\n  p I :=\nbegin\n  refine subbox_induction_on' I (\u03bb J hle hs, H_ind J hle $ \u03bb J' h', _) H_nhds,\n  rcases mem_split_center.1 h' with \u27e8s, rfl\u27e9,\n  exact hs s\nend\n\n/-- Given a box `I` in `\u211d\u207f` and a function `r : \u211d\u207f \u2192 (0, \u221e)`, there exists a tagged partition `\u03c0` of\n`I` such that\n\n* `\u03c0` is a Henstock partition;\n* `\u03c0` is subordinate to `r`;\n* each box in `\u03c0` is homothetic to `I` with coefficient of the form `1 / 2 ^ m`.\n\nThis lemma implies that the Henstock filter is nontrivial, hence the Henstock integral is\nwell-defined. -/\nlemma exists_tagged_partition_is_Henstock_is_subordinate_homothetic (I : box \u03b9)\n  (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  \u2203 \u03c0 : tagged_prepartition I, \u03c0.is_partition \u2227 \u03c0.is_Henstock \u2227 \u03c0.is_subordinate r \u2227\n    (\u2200 J \u2208 \u03c0, \u2203 m : \u2115, \u2200 i, (J : _).upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) \u2227\n    \u03c0.distortion = I.distortion :=\nbegin\n  refine subbox_induction_on I (\u03bb J hle hJ, _) (\u03bb z hz, _),\n  { choose! \u03c0i hP hHen hr Hn Hd using hJ, choose! n hn using Hn,\n    have hP : ((split_center J).bUnion_tagged \u03c0i).is_partition,\n      from (is_partition_split_center _).bUnion_tagged hP,\n    have hsub : \u2200 (J' \u2208 (split_center J).bUnion_tagged \u03c0i), \u2203 n : \u2115, \u2200 i,\n      (J' : _).upper i - J'.lower i = (J.upper i - J.lower i) / 2 ^ n,\n    { intros J' hJ',\n      rcases (split_center J).mem_bUnion_tagged.1 hJ' with \u27e8J\u2081, h\u2081, h\u2082\u27e9,\n      refine \u27e8n J\u2081 J' + 1, \u03bb i, _\u27e9,\n      simp only [hn J\u2081 h\u2081 J' h\u2082, upper_sub_lower_of_mem_split_center h\u2081, pow_succ,\n        div_div_eq_div_mul] },\n    refine \u27e8_, hP, is_Henstock_bUnion_tagged.2 hHen, is_subordinate_bUnion_tagged.2 hr, hsub, _\u27e9,\n    refine tagged_prepartition.distortion_of_const _ hP.nonempty_boxes (\u03bb J' h', _),\n    rcases hsub J' h' with \u27e8n, hn\u27e9,\n    exact box.distortion_eq_of_sub_eq_div hn },\n  { refine \u27e8I.Icc \u2229 closed_ball z (r z),\n      inter_mem_nhds_within _ (closed_ball_mem_nhds _ (r z).coe_prop), _\u27e9,\n    intros J Hle n Hmem HIcc Hsub,\n    rw set.subset_inter_iff at HIcc,\n    refine \u27e8single _ _ le_rfl _ Hmem, is_partition_single _, is_Henstock_single _,\n      (is_subordinate_single _ _).2 HIcc.2, _, distortion_single _ _\u27e9,\n    simp only [tagged_prepartition.mem_single, forall_eq],\n    refine \u27e80, \u03bb i, _\u27e9, simp }\nend\n\nend box\n\nnamespace prepartition\n\nopen tagged_prepartition finset function\n\n/-- Given a box `I` in `\u211d\u207f`, a function `r : \u211d\u207f \u2192 (0, \u221e)`, and a prepartition `\u03c0` of `I`, there\nexists a tagged prepartition `\u03c0'` of `I` such that\n\n* each box of `\u03c0'` is included in some box of `\u03c0`;\n* `\u03c0'` is a Henstock partition;\n* `\u03c0'` is subordinate to `r`;\n* `\u03c0'` covers exactly the same part of `I` as `\u03c0`;\n* the distortion of `\u03c0'` is equal to the distortion of `\u03c0`.\n-/\nlemma exists_tagged_le_is_Henstock_is_subordinate_Union_eq {I : box \u03b9} (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d))\n  (\u03c0 : prepartition I) :\n  \u2203 \u03c0' : tagged_prepartition I, \u03c0'.to_prepartition \u2264 \u03c0 \u2227\n    \u03c0'.is_Henstock \u2227 \u03c0'.is_subordinate r \u2227 \u03c0'.distortion = \u03c0.distortion \u2227\n    \u03c0'.Union = \u03c0.Union :=\nbegin\n  have := \u03bb J, box.exists_tagged_partition_is_Henstock_is_subordinate_homothetic J r,\n  choose! \u03c0i \u03c0ip \u03c0iH \u03c0ir hsub \u03c0id, clear hsub,\n  refine \u27e8\u03c0.bUnion_tagged \u03c0i, bUnion_le _ _, is_Henstock_bUnion_tagged.2 (\u03bb J _, \u03c0iH J),\n    is_subordinate_bUnion_tagged.2 (\u03bb J _, \u03c0ir J), _, \u03c0.Union_bUnion_partition (\u03bb J _, \u03c0ip J)\u27e9,\n  rw [distortion_bUnion_tagged],\n  exact sup_congr rfl (\u03bb J _, \u03c0id J)\nend\n\n/-- Given a prepartition `\u03c0` of a box `I` and a function `r : \u211d\u207f \u2192 (0, \u221e)`, `\u03c0.to_subordinate r`\nis a tagged partition `\u03c0'` such that\n\n* each box of `\u03c0'` is included in some box of `\u03c0`;\n* `\u03c0'` is a Henstock partition;\n* `\u03c0'` is subordinate to `r`;\n* `\u03c0'` covers exactly the same part of `I` as `\u03c0`;\n* the distortion of `\u03c0'` is equal to the distortion of `\u03c0`.\n-/\ndef to_subordinate (\u03c0 : prepartition I) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) : tagged_prepartition I :=\n(\u03c0.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some\n\n\n\nlemma is_Henstock_to_subordinate (\u03c0 : prepartition I) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  (\u03c0.to_subordinate r).is_Henstock :=\n(\u03c0.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some_spec.2.1\n\nlemma is_subordinate_to_subordinate (\u03c0 : prepartition I) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  (\u03c0.to_subordinate r).is_subordinate r :=\n(\u03c0.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some_spec.2.2.1\n\n@[simp] lemma distortion_to_subordinate (\u03c0 : prepartition I) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  (\u03c0.to_subordinate r).distortion = \u03c0.distortion :=\n(\u03c0.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some_spec.2.2.2.1\n\n@[simp] lemma Union_to_subordinate (\u03c0 : prepartition I) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  (\u03c0.to_subordinate r).Union = \u03c0.Union :=\n(\u03c0.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some_spec.2.2.2.2\n\nend prepartition\n\nnamespace tagged_prepartition\n\n/-- Given a tagged prepartition `\u03c0\u2081`, a prepartition `\u03c0\u2082` that covers exactly `I \\ \u03c0\u2081.Union`, and\na function `r : \u211d\u207f \u2192 (0, \u221e)`, returns the union of `\u03c0\u2081` and `\u03c0\u2082.to_subordinate r`. This partition\n`\u03c0` has the following properties:\n\n* `\u03c0` is a partition, i.e. it covers the whole `I`;\n* `\u03c0\u2081.boxes \u2286 \u03c0.boxes`;\n* `\u03c0.tag J = \u03c0\u2081.tag J` whenever `J \u2208 \u03c0\u2081`;\n* `\u03c0` is Henstock outside of `\u03c0\u2081`: `\u03c0.tag J \u2208 J.Icc` whenever `J \u2208 \u03c0`, `J \u2209 \u03c0\u2081`;\n* `\u03c0` is subordinate to `r` outside of `\u03c0\u2081`;\n* the distortion of `\u03c0` is equal to the maximum of the distortions of `\u03c0\u2081` and `\u03c0\u2082`.\n-/\ndef union_compl_to_subordinate (\u03c0\u2081 : tagged_prepartition I) (\u03c0\u2082 : prepartition I)\n  (hU : \u03c0\u2082.Union = I \\ \u03c0\u2081.Union) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  tagged_prepartition I :=\n\u03c0\u2081.disj_union (\u03c0\u2082.to_subordinate r)\n  (((\u03c0\u2082.Union_to_subordinate r).trans hU).symm \u25b8 disjoint_diff)\n\nlemma is_partition_union_compl_to_subordinate (\u03c0\u2081 : tagged_prepartition I) (\u03c0\u2082 : prepartition I)\n  (hU : \u03c0\u2082.Union = I \\ \u03c0\u2081.Union) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  is_partition (\u03c0\u2081.union_compl_to_subordinate \u03c0\u2082 hU r) :=\nprepartition.is_partition_disj_union_of_eq_diff ((\u03c0\u2082.Union_to_subordinate r).trans hU)\n\n@[simp] lemma union_compl_to_subordinate_boxes (\u03c0\u2081 : tagged_prepartition I) (\u03c0\u2082 : prepartition I)\n  (hU : \u03c0\u2082.Union = I \\ \u03c0\u2081.Union) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  (\u03c0\u2081.union_compl_to_subordinate \u03c0\u2082 hU r).boxes = \u03c0\u2081.boxes \u222a (\u03c0\u2082.to_subordinate r).boxes :=\nrfl\n\n@[simp] lemma Union_union_compl_to_subordinate_boxes (\u03c0\u2081 : tagged_prepartition I)\n  (\u03c0\u2082 : prepartition I) (hU : \u03c0\u2082.Union = I \\ \u03c0\u2081.Union) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  (\u03c0\u2081.union_compl_to_subordinate \u03c0\u2082 hU r).Union = I :=\n(is_partition_union_compl_to_subordinate _ _ _ _).Union_eq\n\n@[simp] lemma distortion_union_compl_to_subordinate (\u03c0\u2081 : tagged_prepartition I)\n  (\u03c0\u2082 : prepartition I) (hU : \u03c0\u2082.Union = I \\ \u03c0\u2081.Union) (r : (\u03b9 \u2192 \u211d) \u2192 Ioi (0 : \u211d)) :\n  (\u03c0\u2081.union_compl_to_subordinate \u03c0\u2082 hU r).distortion = max \u03c0\u2081.distortion \u03c0\u2082.distortion :=\nby simp [union_compl_to_subordinate]\n\nend tagged_prepartition\n\nend box_integral\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/box_integral/partition/subbox_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7270052946854106}}
{"text": "import data.real.basic\nimport data.real.sqrt\n\nopen set real\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la funci\u00f3n cuadrado es inyectiva sobre los\n-- n\u00fameros no negativos.\n-- ----------------------------------------------------------------------\n\nexample : inj_on sqrt { x | x \u2265 0 } :=\nbegin\n  intros x hx y hy,\n  intro e,\n  calc\n    x   = (sqrt x)^2 : by finish\n    ... = (sqrt y)^2 : congr_arg (\u03bb x, x^2) e\n    ... = y          : by finish\nend\n\n-- Prueba\n-- ======\n\n/-\n\u22a2 inj_on sqrt {x : \u211d | x \u2265 0}\n  >> intros x y xnonneg ynonneg,\n\u22a2 inj_on sqrt {x : \u211d | x \u2265 0}\n  >> intro e,\ne : x.sqrt = y.sqrt\n\u22a2 x = y\n  >> calc\n  >>   x   = (sqrt x)^2 : by rw sqr_sqrt xnonneg\n  >>   ... = (sqrt y)^2 : by rw e\n  >>   ... = y          : by rw sqr_sqrt ynonneg,\nno goals\n-/\n\n-- Comentario: Se ha usado el lema\n-- + sqr_sqrt : 0 \u2264 x \u2192 (sqrt x) ^ 2 = x\n\n-- Comprobaci\u00f3n:\nvariable (x : \u211d)\n-- #check @sqr_sqrt x\n\nexample : inj_on (\u03bb (x : \u211d), x^2) { x | x \u2265 0 } :=\nbegin\n  intros x xnonneg y ynonneg,\n  simp,\n  intro e,\n  calc\n    x   = sqrt (x ^ 2) : by finish\n    ... = sqrt (y ^ 2) : by rw e\n    ... = y            : by finish\nend\n\n-- Prueba\n-- ======\n\n/-\n\u22a2 inj_on (\u03bb (x : \u211d), x ^ 2) {x : \u211d | x \u2265 0}\n  >> intros x y xnonneg ynonneg,\nx y : \u211d,\nxnonneg : x \u2208 {x : \u211d | x \u2265 0},\nynonneg : y \u2208 {x : \u211d | x \u2265 0}\n\u22a2 (\u03bb (x : \u211d), x ^ 2) x = (\u03bb (x : \u211d), x ^ 2) y \u2192 x = y\n  >> simp,\n\u22a2 x ^ 2 = y ^ 2 \u2192 x = y\n  >> intro e,\ne : x ^ 2 = y ^ 2\n\u22a2 x = y\n  >> calc\n  >>   x   = sqrt (x ^ 2) : by rw sqrt_sqr xnonneg\n  >>   ... = sqrt (y ^ 2) : by rw e\n  >>   ... = y            : by rw sqrt_sqr ynonneg,\nno goals\n-/\n\n-- Comentario: Se ha usado el lema\n-- + sqrt_sqr : 0 \u2264 x \u2192 (x ^ 2).sqrt = x\n\n-- #check @sqrt_sqr x\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Inyectividad_del_cuadrado.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7269741363862334}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world2.level1 -- hide\nnamespace mynat -- hide\n\n/- \n# Addition world\n\nDon't forget to use the drop down boxes on the left to see your tactics and\nwhat you have proved so far.\n\n## Level 2: `add_assoc` -- associativity of addition.\n\nIt's well-known that (1 + 2) + 3 = 1 + (2 + 3) -- if we have three numbers\nto add up, it doesn't matter which of the additions we do first. This fact\nis called *associativity of addition* by mathematicians, and it is *not*\nobvious. For example, subtraction really is not associative: $(6 - 2) - 1$\nis really not equal to $6 - (2 - 1)$. We are going to have to prove\nthat addition, as defined the way we've defined it, is associative. \n \nSee if you can prove associativity of addition. Hint: because addition was defined\nby recursion on the right-most variable, use induction on the right-most\nvariable (try other variables at your peril!). Note that when Lean writes `a + b + c`,\nit means `(a + b) + c`. If it wants to talk about `a + (b + c)` it will put the brackets\nin explictly.\n\nReminder: you are done when you see \"Proof complete!\" in the top right, and an empty\nbox (no errors) in the bottom right. You can move between levels and worlds (i.e. you\ncan go back and review old stuff) without losing anything.\n\nOnce you're done with associativity (sub-boss), we can move on to commutativity (boss).\n-/\n\n/- Lemma\nOn the set of natural numbers, addition is associative.\nIn other words, for all natural numbers $a, b$ and $c$, we have\n$$ (a + b) + c = a + (b + c). $$\n-/\nlemma add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) :=\nbegin [nat_num_game]\n  induction c with d hd,\n  { -- \u22a2 a + b + 0 = a + (b + 0)\n    rw add_zero,\n    rw add_zero,\n    refl\n  },\n  { -- \u22a2 (a + b) + succ d = a + (b + succ d)\n    rw add_succ,\n    rw add_succ,\n    rw add_succ,\n    rw hd,\n    refl,\n  }\nend\n\nend mynat -- hide \n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world2/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7269741248214334}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n-/\nimport data.real.sqrt\n\n/-!\n# The complex numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe complex numbers are modelled as \u211d^2 in the obvious way and it is shown that they form a field\nof characteristic zero. The result that the complex numbers are algebraically closed, see\n`field_theory.algebraic_closure`.\n-/\n\nopen_locale big_operators\nopen set function\n\n/-! ### Definition and basic arithmmetic -/\n\n/-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\nopen_locale complex_conjugate\n\nnoncomputable instance : decidable_eq \u2102 := classical.dec_eq _\n\n/-- The equivalence between the complex numbers and `\u211d \u00d7 \u211d`. -/\n@[simps apply]\ndef equiv_real_prod : \u2102 \u2243 (\u211d \u00d7 \u211d) :=\n{ to_fun := \u03bb z, \u27e8z.re, z.im\u27e9,\n  inv_fun := \u03bb p, \u27e8p.1, p.2\u27e9,\n  left_inv := \u03bb \u27e8x, y\u27e9, rfl,\n  right_inv := \u03bb \u27e8x, y\u27e9, rfl }\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8a, b\u27e9 := rfl\n\n@[ext]\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], \u03bb h, ext h.1 h.2\u27e9\n\ntheorem re_surjective : surjective re := \u03bb x, \u27e8\u27e8x, 0\u27e9, rfl\u27e9\ntheorem im_surjective : surjective im := \u03bb y, \u27e8\u27e80, y\u27e9, rfl\u27e9\n\n@[simp] theorem range_re : range re = univ := re_surjective.range_eq\n@[simp] theorem range_im : range im = univ := im_surjective.range_eq\n\ninstance : has_coe \u211d \u2102 := \u27e8\u03bb r, \u27e8r, 0\u27e9\u27e9\n\n@[simp, norm_cast] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\nlemma of_real_def (r : \u211d) : (r : \u2102) = \u27e8r, 0\u27e9 := rfl\n\n@[simp, norm_cast] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\ntheorem of_real_injective : function.injective (coe : \u211d \u2192 \u2102) :=\n\u03bb z w, congr_arg re\n\ninstance can_lift : can_lift \u2102 \u211d coe (\u03bb z, z.im = 0) :=\n{ prf := \u03bb z hz, \u27e8z.re, ext rfl hz.symm\u27e9 }\n\n/-- The product of a set on the real axis and a set on the imaginary axis of the complex plane,\ndenoted by `s \u00d7\u2102 t`. -/\ndef _root_.set.re_prod_im (s t : set \u211d) : set \u2102 := re \u207b\u00b9' s \u2229 im \u207b\u00b9' t\n\ninfix ` \u00d7\u2102 `:72 := set.re_prod_im\n\nlemma mem_re_prod_im {z : \u2102} {s t : set \u211d} : z \u2208 s \u00d7\u2102 t \u2194 z.re \u2208 s \u2227 z.im \u2208 t := iff.rfl\n\ninstance : has_zero \u2102 := \u27e8(0 : \u211d)\u27e9\ninstance : inhabited \u2102 := \u27e80\u27e9\n\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\ninstance : has_one \u2102 := \u27e8(1 : \u211d)\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\n@[simp] theorem of_real_eq_one {z : \u211d} : (z : \u2102) = 1 \u2194 z = 1 := of_real_inj\ntheorem of_real_ne_one {z : \u211d} : (z : \u2102) \u2260 1 \u2194 z \u2260 1 := not_congr of_real_eq_one\n\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n\n@[simp] lemma bit0_re (z : \u2102) : (bit0 z).re = bit0 z.re := rfl\n@[simp] lemma bit1_re (z : \u2102) : (bit1 z).re = bit1 z.re := rfl\n@[simp] lemma bit0_im (z : \u2102) : (bit0 z).im = bit0 z.im := eq.refl _\n@[simp] lemma bit1_im (z : \u2102) : (bit1 z).im = bit0 z.im := add_zero _\n\n@[simp, norm_cast] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s :=\next_iff.2 $ by simp\n\n@[simp, norm_cast] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r :=\next_iff.2 $ by simp [bit0]\n\n@[simp, norm_cast] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r :=\next_iff.2 $ by simp [bit1]\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n@[simp, norm_cast] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\ninstance : has_sub \u2102 := \u27e8\u03bb z w, \u27e8z.re - w.re, z.im - w.im\u27e9\u27e9\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp, norm_cast] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\nlemma of_real_mul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp\nlemma of_real_mul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp\nlemma of_real_mul' (r : \u211d) (z : \u2102) : (\u2191r * z) = \u27e8r * z.re, r * z.im\u27e9 :=\next (of_real_mul_re _ _) (of_real_mul_im _ _)\n\n/-! ### The imaginary unit, `I` -/\n\n/-- The imaginary unit. -/\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := rfl\n@[simp] lemma I_im : I.im = 1 := rfl\n\n@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp\nlemma I_mul (z : \u2102) : I * z = \u27e8-z.im, z.re\u27e9 :=\next_iff.2 $ by simp\n\nlemma I_ne_zero : (I : \u2102) \u2260 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\next_iff.2 $ by simp\n\nlemma mul_I_re (z : \u2102) : (z * I).re = -z.im := by simp\nlemma mul_I_im (z : \u2102) : (z * I).im = z.re := by simp\nlemma I_mul_re (z : \u2102) : (I * z).re = -z.im := by simp\nlemma I_mul_im (z : \u2102) : (I * z).im = z.re := by simp\n\n@[simp] lemma equiv_real_prod_symm_apply (p : \u211d \u00d7 \u211d) :\n  equiv_real_prod.symm p = p.1 + p.2 * I :=\nby { ext; simp [equiv_real_prod] }\n\n/-! ### Commutative ring instance and lemmas -/\n\n/- We use a nonstandard formula for the `\u2115` and `\u2124` actions to make sure there is no\ndiamond from the other actions they inherit through the `\u211d`-action on `\u2102` and action transitivity\ndefined in `data.complex.module.lean`. -/\n\ninstance : nontrivial \u2102 := pullback_nonzero re rfl rfl\n\ninstance : add_comm_group \u2102 :=\nby refine_struct\n  { zero := (0 : \u2102),\n    add := (+),\n    neg := has_neg.neg,\n    sub := has_sub.sub,\n    nsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9,\n    zsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9 };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\ninstance : add_group_with_one \u2102 :=\n{ nat_cast := \u03bb n, \u27e8n, 0\u27e9,\n  nat_cast_zero := by ext; simp [nat.cast],\n  nat_cast_succ := \u03bb _, by ext; simp [nat.cast],\n  int_cast := \u03bb n, \u27e8n, 0\u27e9,\n  int_cast_of_nat := \u03bb _, by ext; simp [\u03bb n, show @coe \u2115 \u2102 \u27e8_\u27e9 n = \u27e8n, 0\u27e9, from rfl],\n  int_cast_neg_succ_of_nat := \u03bb _, by ext; simp [\u03bb n, show @coe \u2115 \u2102 \u27e8_\u27e9 n = \u27e8n, 0\u27e9, from rfl],\n  one := 1,\n  .. complex.add_comm_group }\n\ninstance : comm_ring \u2102 :=\nby refine_struct\n  { zero := (0 : \u2102),\n    add := (+),\n    one := 1,\n    mul := (*),\n    npow := @npow_rec _ \u27e8(1 : \u2102)\u27e9 \u27e8(*)\u27e9,\n    .. complex.add_group_with_one };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\n/-- This shortcut instance ensures we do not find `ring` via the noncomputable `complex.field`\ninstance. -/\ninstance : ring \u2102 := by apply_instance\n\n/-- This shortcut instance ensures we do not find `comm_semiring` via the noncomputable\n`complex.field` instance. -/\ninstance : comm_semiring \u2102 := infer_instance\n\n/-- The \"real part\" map, considered as an additive group homomorphism. -/\ndef re_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := re,\n  map_zero' := zero_re,\n  map_add' := add_re }\n\n@[simp] lemma coe_re_add_group_hom : (re_add_group_hom : \u2102 \u2192 \u211d) = re := rfl\n\n/-- The \"imaginary part\" map, considered as an additive group homomorphism. -/\ndef im_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := im,\n  map_zero' := zero_im,\n  map_add' := add_im }\n\n@[simp] lemma coe_im_add_group_hom : (im_add_group_hom : \u2102 \u2192 \u211d) = im := rfl\n\n@[simp] lemma I_pow_bit0 (n : \u2115) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [pow_bit0', I_mul_I]\n\n@[simp] lemma I_pow_bit1 (n : \u2115) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [pow_bit1', I_mul_I]\n\n/-! ### Complex conjugation -/\n\n/-- This defines the complex conjugate as the `star` operation of the `star_ring \u2102`. It\nis recommended to use the ring endomorphism version `star_ring_end`, available under the\nnotation `conj` in the locale `complex_conjugate`. -/\ninstance : star_ring \u2102 :=\n{ star := \u03bb z, \u27e8z.re, -z.im\u27e9,\n  star_involutive := \u03bb x, by simp only [eta, neg_neg],\n  star_mul := \u03bb a b, by ext; simp [add_comm]; ring,\n  star_add := \u03bb a b, by ext; simp [add_comm] }\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := rfl\n\nlemma conj_of_real (r : \u211d) : conj (r : \u2102) = r := ext_iff.2 $ by simp [conj]\n\n@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp\n\nlemma conj_bit0 (z : \u2102) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]\nlemma conj_bit1 (z : \u2102) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0]\n\n@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp\n\nlemma eq_conj_iff_real {z : \u2102} : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n\u27e8\u03bb h, \u27e8z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)\u27e9,\n \u03bb \u27e8h, e\u27e9, by rw [e, conj_of_real]\u27e9\n\nlemma eq_conj_iff_re {z : \u2102} : conj z = z \u2194 (z.re : \u2102) = z :=\neq_conj_iff_real.trans \u27e8by rintro \u27e8r, rfl\u27e9; simp, \u03bb h, \u27e8_, h.symm\u27e9\u27e9\n\nlemma eq_conj_iff_im {z : \u2102} : conj z = z \u2194 z.im = 0 :=\n\u27e8\u03bb h, add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)),\n  \u03bb h, ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))\u27e9\n\n-- `simp_nf` complains about this being provable by `is_R_or_C.star_def` even\n-- though it's not imported by this file.\n@[simp, nolint simp_nf] lemma star_def : (has_star.star : \u2102 \u2192 \u2102) = conj := rfl\n\n/-! ### Norm squared -/\n\n/-- The norm squared function. -/\n@[pp_nodot] def norm_sq : \u2102 \u2192*\u2080 \u211d :=\n{ to_fun := \u03bb z, z.re * z.re + z.im * z.im,\n  map_zero' := by simp,\n  map_one' := by simp,\n  map_mul' := \u03bb z w, by { dsimp, ring } }\n\nlemma norm_sq_apply (z : \u2102) : norm_sq z = z.re * z.re + z.im * z.im := rfl\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mk (x y : \u211d) : norm_sq \u27e8x, y\u27e9 = x * x + y * y := rfl\n\nlemma norm_sq_add_mul_I (x y : \u211d) : norm_sq (x + y * I) = x ^ 2 + y ^ 2 :=\nby rw [\u2190 mk_eq_add_mul_I, norm_sq_mk, sq, sq]\n\nlemma norm_sq_eq_conj_mul_self {z : \u2102} : (norm_sq z : \u2102) = conj z * z :=\nby { ext; simp [norm_sq, mul_comm], }\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := norm_sq.map_zero\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := norm_sq.map_one\n@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\n@[simp] lemma range_norm_sq : range norm_sq = Ici 0 :=\nsubset.antisymm (range_subset_iff.2 norm_sq_nonneg) $ \u03bb x hx,\n  \u27e8real.sqrt x, by rw [norm_sq_of_real, real.mul_self_sqrt hx]\u27e9\n\nlemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\n\u27e8\u03bb h, ext\n  (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n  (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),\n \u03bb h, h.symm \u25b8 norm_sq_zero\u27e9\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\n(norm_sq_nonneg z).lt_iff_ne.trans $ not_congr (eq_comm.trans norm_sq_eq_zero)\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\nlemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nnorm_sq.map_mul z w\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nby dsimp [norm_sq]; ring\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\next_iff.2 $ by simp [two_mul]\n\n/-- The coercion `\u211d \u2192 \u2102` as a `ring_hom`. -/\ndef of_real : \u211d \u2192+* \u2102 := \u27e8coe, of_real_one, of_real_mul, of_real_zero, of_real_add\u27e9\n\n@[simp] lemma of_real_eq_coe (r : \u211d) : of_real r = r := rfl\n\n@[simp] lemma I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]\n\n@[simp] lemma sub_re (z w : \u2102) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : \u2102) : (z - w).im = z.im - w.im := rfl\n@[simp, norm_cast] lemma of_real_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s := ext_iff.2 $ by simp\n@[simp, norm_cast] lemma of_real_pow (r : \u211d) (n : \u2115) : ((r ^ n : \u211d) : \u2102) = r ^ n :=\nby induction n; simp [*, of_real_mul, pow_succ]\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\next_iff.2 $ by simp [two_mul, sub_eq_add_neg]\n\nlemma norm_sq_sub (z w : \u2102) : norm_sq (z - w) =\n  norm_sq z + norm_sq w - 2 * (z * conj w).re :=\nby { rw [sub_eq_add_neg, norm_sq_add],\n     simp only [ring_hom.map_neg, mul_neg, neg_re,\n                tactic.ring.add_neg_eq_sub, norm_sq_neg] }\n\n/-! ### Inversion -/\n\nnoncomputable instance : has_inv \u2102 := \u27e8\u03bb z, conj z * ((norm_sq z)\u207b\u00b9:\u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((norm_sq z)\u207b\u00b9:\u211d) := rfl\n@[simp] lemma inv_re (z : \u2102) : (z\u207b\u00b9).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : \u2102) : (z\u207b\u00b9).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\n@[simp, norm_cast] lemma of_real_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = r\u207b\u00b9 :=\next_iff.2 $ by simp\n\nprotected \n\nprotected theorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nby rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 of_real_mul,\n  mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]\n\n/-! ### Field instance and lemmas -/\n\nnoncomputable instance : field \u2102 :=\n{ inv := has_inv.inv,\n  mul_inv_cancel := @complex.mul_inv_cancel,\n  inv_zero := complex.inv_zero,\n  ..complex.comm_ring, ..complex.nontrivial }\n\n@[simp] lemma I_zpow_bit0 (n : \u2124) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [zpow_bit0', I_mul_I]\n\n@[simp] lemma I_zpow_bit1 (n : \u2124) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [zpow_bit1', I_mul_I]\n\nlemma div_re (z w : \u2102) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]\nlemma div_im (z w : \u2102) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]\n\nlemma conj_inv (x : \u2102) : conj (x\u207b\u00b9) = (conj x)\u207b\u00b9 := star_inv' _\n\n@[simp, norm_cast] lemma of_real_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\nmap_div\u2080 of_real r s\n\n@[simp, norm_cast] lemma of_real_zpow (r : \u211d) (n : \u2124) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n :=\nmap_zpow\u2080 of_real r n\n\n@[simp] lemma div_I (z : \u2102) : z / I = -(z * I) :=\n(div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc]\n\n@[simp] lemma inv_I : I\u207b\u00b9 = -I :=\nby simp [inv_eq_one_div]\n\n@[simp] lemma norm_sq_inv (z : \u2102) : norm_sq z\u207b\u00b9 = (norm_sq z)\u207b\u00b9 :=\nmap_inv\u2080 norm_sq z\n\n@[simp] lemma norm_sq_div (z w : \u2102) : norm_sq (z / w) = norm_sq z / norm_sq w :=\nmap_div\u2080 norm_sq z w\n\n/-! ### Cast lemmas -/\n\n@[simp, norm_cast] theorem of_real_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\nmap_nat_cast of_real n\n\n@[simp, norm_cast] lemma nat_cast_re (n : \u2115) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_nat_cast, of_real_re]\n\n@[simp, norm_cast] lemma nat_cast_im (n : \u2115) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_nat_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_int_cast (n : \u2124) : ((n : \u211d) : \u2102) = n := map_int_cast of_real n\n\n@[simp, norm_cast] lemma int_cast_re (n : \u2124) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_int_cast, of_real_re]\n\n@[simp, norm_cast] lemma int_cast_im (n : \u2124) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_int_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_rat_cast (n : \u211a) : ((n : \u211d) : \u2102) = n := map_rat_cast of_real n\n\n@[simp, norm_cast] lemma rat_cast_re (q : \u211a) : (q : \u2102).re = q :=\nby rw [\u2190 of_real_rat_cast, of_real_re]\n\n@[simp, norm_cast] lemma rat_cast_im (q : \u211a) : (q : \u2102).im = 0 :=\nby rw [\u2190 of_real_rat_cast, of_real_im]\n\n/-! ### Characteristic zero -/\n\ninstance char_zero_complex : char_zero \u2102 :=\nchar_zero_of_inj_zero $ \u03bb n h,\nby rwa [\u2190 of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h\n\n/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 :=\nby simp only [add_conj, of_real_mul, of_real_one, of_real_bit0,\n     mul_div_cancel_left (z.re:\u2102) two_ne_zero]\n\n/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/\ntheorem im_eq_sub_conj (z : \u2102) : (z.im : \u2102) = (z - conj(z))/(2 * I) :=\nby simp only [sub_conj, of_real_mul, of_real_one, of_real_bit0, mul_right_comm,\n     mul_div_cancel_left _ (mul_ne_zero two_ne_zero I_ne_zero : 2 * I \u2260 0)]\n\n/-! ### Absolute value -/\n\nnamespace abs_theory\n-- We develop enough theory to bundle `abs` into an `absolute_value` before making things public;\n-- this is so there's not two versions of it hanging around.\n\nlocal notation (name := abs) `abs` z := ((norm_sq z).sqrt)\n\nprivate lemma mul_self_abs (z : \u2102) : (abs z) * (abs z) = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\nprivate lemma abs_nonneg' (z : \u2102) : 0 \u2264 abs z :=\nreal.sqrt_nonneg _\n\nlemma abs_conj (z : \u2102) : (abs (conj z)) = abs z :=\nby simp\n\nprivate lemma abs_re_le_abs (z : \u2102) : |z.re| \u2264 abs z :=\nbegin\n  rw [mul_self_le_mul_self_iff (abs_nonneg z.re) (abs_nonneg' _),\n       abs_mul_abs_self, mul_self_abs],\n  apply re_sq_le_norm_sq\nend\n\nprivate lemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nprivate lemma abs_mul (z w : \u2102) : (abs (z * w)) = (abs z) * abs w :=\nby rw [norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]\n\nprivate lemma abs_add (z w : \u2102) : (abs (z + w)) \u2264 (abs z) + abs w :=\n(mul_self_le_mul_self_iff (abs_nonneg' (z + w))\n  (add_nonneg (abs_nonneg' z) (abs_nonneg' w))).2 $\nbegin\n  rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs, add_right_comm, norm_sq_add,\n      add_le_add_iff_left, mul_assoc, mul_le_mul_left (zero_lt_two' \u211d),\n      \u2190real.sqrt_mul $ norm_sq_nonneg z, \u2190norm_sq_conj w, \u2190map_mul],\n  exact re_le_abs (z * conj w)\nend\n\n/-- The complex absolute value function, defined as the square root of the norm squared. -/\nnoncomputable def _root_.complex.abs : absolute_value \u2102 \u211d :=\n{ to_fun := \u03bb x, abs x,\n  map_mul' := abs_mul,\n  nonneg' := abs_nonneg',\n  eq_zero' := \u03bb _, (real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero,\n  add_le' := abs_add }\n\nend abs_theory\n\nlemma abs_def : (abs : \u2102 \u2192 \u211d) = \u03bb z, (norm_sq z).sqrt := rfl\nlemma abs_apply {z : \u2102} : abs z = (norm_sq z).sqrt := rfl\n\n@[simp, norm_cast] lemma abs_of_real (r : \u211d) : abs r = |r| :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\nlemma abs_of_nat (n : \u2115) : complex.abs n = n :=\ncalc complex.abs n = complex.abs (n:\u211d) : by rw [of_real_nat_cast]\n  ... = _ : abs_of_nonneg (nat.cast_nonneg n)\n\nlemma mul_self_abs (z : \u2102) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\nlemma sq_abs (z : \u2102) : abs z ^ 2 = norm_sq z :=\nreal.sq_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma sq_abs_sub_sq_re (z : \u2102) : abs z ^ 2 - z.re ^ 2 = z.im ^ 2 :=\nby rw [sq_abs, norm_sq_apply, \u2190 sq, \u2190 sq, add_sub_cancel']\n\n@[simp] lemma sq_abs_sub_sq_im (z : \u2102) : abs z ^ 2 - z.im ^ 2 = z.re ^ 2 :=\nby rw [\u2190 sq_abs_sub_sq_re, sub_sub_cancel]\n\n@[simp] lemma abs_I : abs I = 1 := by simp [abs]\n\n@[simp] lemma abs_two : abs 2 = 2 :=\ncalc abs 2 = abs (2 : \u211d) : by rw [of_real_bit0, of_real_one]\n... = (2 : \u211d) : abs_of_nonneg (by norm_num)\n\n@[simp] lemma range_abs : range abs = Ici 0 :=\nsubset.antisymm (range_subset_iff.2 abs.nonneg) $ \u03bb x hx, \u27e8x, abs_of_nonneg hx\u27e9\n\n@[simp] lemma abs_conj (z : \u2102) : abs (conj z) = abs z := abs_theory.abs_conj z\n\n@[simp] lemma abs_prod {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 \u2102) :\n  abs (s.prod f) = s.prod (\u03bb i, abs (f i)) :=\nmap_prod abs _ _\n\n@[simp] lemma abs_pow (z : \u2102) (n : \u2115) : abs (z ^ n) = abs z ^ n :=\nmap_pow abs z n\n\n@[simp] lemma abs_zpow (z : \u2102) (n : \u2124) : abs (z ^ n) = abs z ^ n :=\nmap_zpow\u2080 abs z n\n\nlemma abs_re_le_abs (z : \u2102) : |z.re| \u2264 abs z :=\nreal.abs_le_sqrt $ by { rw [norm_sq_apply, \u2190 sq], exact le_add_of_nonneg_right (mul_self_nonneg _) }\n\nlemma abs_im_le_abs (z : \u2102) : |z.im| \u2264 abs z :=\nreal.abs_le_sqrt $ by { rw [norm_sq_apply, \u2190 sq, \u2190 sq], exact le_add_of_nonneg_left (sq_nonneg _) }\n\nlemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : \u2102) : z.im \u2264 abs z :=\n(abs_le.1 (abs_im_le_abs _)).2\n\n@[simp] lemma abs_re_lt_abs {z : \u2102} : |z.re| < abs z \u2194 z.im \u2260 0 :=\nby rw [abs, absolute_value.coe_mk, mul_hom.coe_mk, real.lt_sqrt (abs_nonneg _), norm_sq_apply,\n       _root_.sq_abs, \u2190 sq, lt_add_iff_pos_right, mul_self_pos]\n\n@[simp] lemma abs_im_lt_abs {z : \u2102} : |z.im| < abs z \u2194 z.re \u2260 0 :=\nby simpa using @abs_re_lt_abs (z * I)\n\n@[simp] lemma abs_abs (z : \u2102) : |(abs z)| = abs z :=\n_root_.abs_of_nonneg (abs.nonneg _)\n\nlemma abs_le_abs_re_add_abs_im (z : \u2102) : abs z \u2264 |z.re| + |z.im| :=\nby simpa [re_add_im] using abs.add_le z.re (z.im * I)\n\nlemma abs_le_sqrt_two_mul_max (z : \u2102) : abs z \u2264 real.sqrt 2 * max (|z.re|) (|z.im|) :=\nbegin\n  cases z with x y,\n  simp only [abs_apply, norm_sq_mk, \u2190 sq],\n  wlog hle : |x| \u2264 |y|,\n  { rw [add_comm, max_comm], exact this _ _ (le_of_not_le hle), },\n  calc real.sqrt (x ^ 2 + y ^ 2) \u2264 real.sqrt (y ^ 2 + y ^ 2) :\n    real.sqrt_le_sqrt (add_le_add_right (sq_le_sq.2 hle) _)\n  ... = real.sqrt 2 * max (|x|) (|y|) :\n    by rw [max_eq_right hle, \u2190 two_mul, real.sqrt_mul two_pos.le, real.sqrt_sq_eq_abs],\nend\n\nlemma abs_re_div_abs_le_one (z : \u2102) : |z.re / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs.pos hz), one_mul, abs_re_le_abs] }\n\nlemma abs_im_div_abs_le_one (z : \u2102) : |z.im / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs.pos hz), one_mul, abs_im_le_abs] }\n\n@[simp, norm_cast] lemma abs_cast_nat (n : \u2115) : abs (n : \u2102) = n :=\nby rw [\u2190 of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]\n\n@[simp, norm_cast] lemma int_cast_abs (n : \u2124) : \u2191|n| = abs n :=\nby rw [\u2190 of_real_int_cast, abs_of_real, int.cast_abs]\n\nlemma norm_sq_eq_abs (x : \u2102) : norm_sq x = abs x ^ 2 :=\nby simp [abs, sq, real.mul_self_sqrt (norm_sq_nonneg _)]\n\n/--\nWe put a partial order on \u2102 so that `z \u2264 w` exactly if `w - z` is real and nonnegative.\nComplex numbers with different imaginary parts are incomparable.\n-/\nprotected def partial_order : partial_order \u2102 :=\n{ le := \u03bb z w, z.re \u2264 w.re \u2227 z.im = w.im,\n  lt := \u03bb z w, z.re < w.re \u2227 z.im = w.im,\n  lt_iff_le_not_le := \u03bb z w, by { dsimp, rw lt_iff_le_not_le, tauto },\n  le_refl := \u03bb x, \u27e8le_rfl, rfl\u27e9,\n  le_trans := \u03bb x y z h\u2081 h\u2082, \u27e8h\u2081.1.trans h\u2082.1, h\u2081.2.trans h\u2082.2\u27e9,\n  le_antisymm := \u03bb z w h\u2081 h\u2082, ext (h\u2081.1.antisymm h\u2082.1) h\u2081.2 }\n\nsection complex_order\n\nlocalized \"attribute [instance] complex.partial_order\" in complex_order\n\nlemma le_def {z w : \u2102} : z \u2264 w \u2194 z.re \u2264 w.re \u2227 z.im = w.im := iff.rfl\nlemma lt_def {z w : \u2102} : z < w \u2194 z.re < w.re \u2227 z.im = w.im := iff.rfl\n\n@[simp, norm_cast] lemma real_le_real {x y : \u211d} : (x : \u2102) \u2264 (y : \u2102) \u2194 x \u2264 y := by simp [le_def]\n\n@[simp, norm_cast] lemma real_lt_real {x y : \u211d} : (x : \u2102) < (y : \u2102) \u2194 x < y := by simp [lt_def]\n\n@[simp, norm_cast] lemma zero_le_real {x : \u211d} : (0 : \u2102) \u2264 (x : \u2102) \u2194 0 \u2264 x := real_le_real\n@[simp, norm_cast] lemma zero_lt_real {x : \u211d} : (0 : \u2102) < (x : \u2102) \u2194 0 < x := real_lt_real\n\nlemma not_le_iff {z w : \u2102} : \u00ac(z \u2264 w) \u2194 w.re < z.re \u2228 z.im \u2260 w.im :=\nby rw [le_def, not_and_distrib, not_le]\n\nlemma not_lt_iff {z w : \u2102} : \u00ac(z < w) \u2194 w.re \u2264 z.re \u2228 z.im \u2260 w.im :=\nby rw [lt_def, not_and_distrib, not_lt]\n\nlemma not_le_zero_iff {z : \u2102} : \u00acz \u2264 0 \u2194 0 < z.re \u2228 z.im \u2260 0 := not_le_iff\nlemma not_lt_zero_iff {z : \u2102} : \u00acz < 0 \u2194 0 \u2264 z.re \u2228 z.im \u2260 0 := not_lt_iff\n\nlemma eq_re_of_real_le {r : \u211d} {z : \u2102} (hz : (r : \u2102) \u2264 z) : z = z.re :=\nby { ext, refl, simp only [\u2190(complex.le_def.1 hz).2, complex.zero_im, complex.of_real_im] }\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a strictly ordered ring.\n-/\nprotected def strict_ordered_comm_ring : strict_ordered_comm_ring \u2102 :=\n{ zero_le_one := \u27e8zero_le_one, rfl\u27e9,\n  add_le_add_left := \u03bb w z h y, \u27e8add_le_add_left h.1 _, congr_arg2 (+) rfl h.2\u27e9,\n  mul_pos := \u03bb z w hz hw,\n    by simp [lt_def, mul_re, mul_im, \u2190 hz.2, \u2190 hw.2, mul_pos hz.1 hw.1],\n  ..complex.partial_order, ..complex.comm_ring, ..complex.nontrivial }\n\nlocalized \"attribute [instance] complex.strict_ordered_comm_ring\" in complex_order\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a star ordered ring.\n(That is, a star ring in which the nonnegative elements are those of the form `star z * z`.)\n-/\nprotected def star_ordered_ring : star_ordered_ring \u2102 :=\n{ nonneg_iff := \u03bb r, by\n  { refine \u27e8\u03bb hr, \u27e8real.sqrt r.re, _\u27e9, \u03bb h, _\u27e9,\n    { have h\u2081 : 0 \u2264 r.re := by { rw [le_def] at hr, exact hr.1 },\n      have h\u2082 : r.im = 0 := by { rw [le_def] at hr, exact hr.2.symm },\n      ext,\n      { simp only [of_real_im, star_def, of_real_re, sub_zero, conj_re, mul_re, mul_zero,\n                   \u2190real.sqrt_mul h\u2081 r.re, real.sqrt_mul_self h\u2081] },\n      { simp only [h\u2082, add_zero, of_real_im, star_def, zero_mul, conj_im,\n                   mul_im, mul_zero, neg_zero] } },\n    { obtain \u27e8s, rfl\u27e9 := h,\n      simp only [\u2190norm_sq_eq_conj_mul_self, norm_sq_nonneg, zero_le_real, star_def] } },\n  ..complex.strict_ordered_comm_ring }\n\nlocalized \"attribute [instance] complex.star_ordered_ring\" in complex_order\n\nend complex_order\n\n/-! ### Cauchy sequences -/\n\nlocal notation `abs'` := has_abs.abs\n\ntheorem is_cau_seq_re (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).re) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n\ntheorem is_cau_seq_im (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).im) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n\n/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_re (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_re f\u27e9\n\n/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_im (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_im f\u27e9\n\nlemma is_cau_seq_abs {f : \u2115 \u2192 \u2102} (hf : is_cau_seq abs f) :\n  is_cau_seq abs' (abs \u2218 f) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := hf \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs.abs_abv_sub_le_abv_sub _ _) (hi j hj)\u27e9\n\n/-- The limit of a Cauchy sequence of complex numbers. -/\nnoncomputable def lim_aux (f : cau_seq \u2102 abs) : \u2102 :=\n\u27e8cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)\u27e9\n\ntheorem equiv_lim_aux (f : cau_seq \u2102 abs) : f \u2248 cau_seq.const abs (lim_aux f) :=\n\u03bb \u03b5 \u03b50, (exists_forall_ge_and\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_re f\u27e9 _ (half_pos \u03b50))\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_im f\u27e9 _ (half_pos \u03b50))).imp $\n\u03bb i H j ij, begin\n  cases H _ ij with H\u2081 H\u2082,\n  apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),\n  dsimp [lim_aux] at *,\n  have := add_lt_add H\u2081 H\u2082,\n  rwa add_halves at this,\nend\n\ninstance : cau_seq.is_complete \u2102 abs :=\n\u27e8\u03bb f, \u27e8lim_aux f, equiv_lim_aux f\u27e9\u27e9\n\nopen cau_seq\n\nlemma lim_eq_lim_im_add_lim_re (f : cau_seq \u2102 abs) : lim f =\n  \u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I :=\nlim_eq_of_equiv_const $\ncalc f \u2248 _ : equiv_lim_aux f\n... = cau_seq.const abs (\u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I) :\n  cau_seq.ext (\u03bb _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))\n\nlemma lim_re (f : cau_seq \u2102 abs) : lim (cau_seq_re f) = (lim f).re :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma lim_im (f : cau_seq \u2102 abs) : lim (cau_seq_im f) = (lim f).im :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma is_cau_seq_conj (f : cau_seq \u2102 abs) : is_cau_seq abs (\u03bb n, conj (f n)) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := f.2 \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, by rw [\u2190 ring_hom.map_sub, abs_conj]; exact hi j hj\u27e9\n\n/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/\nnoncomputable def cau_seq_conj (f : cau_seq \u2102 abs) : cau_seq \u2102 abs :=\n\u27e8_, is_cau_seq_conj f\u27e9\n\nlemma lim_conj (f : cau_seq \u2102 abs) : lim (cau_seq_conj f) = conj (lim f) :=\ncomplex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])\n  (by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)\n\n/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_abs (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_abs f.2\u27e9\n\nlemma lim_abs (f : cau_seq \u2102 abs) : lim (cau_seq_abs f) = abs (lim f) :=\nlim_eq_of_equiv_const (\u03bb \u03b5 \u03b50,\nlet \u27e8i, hi\u27e9 := equiv_lim f \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs.abs_abv_sub_le_abv_sub _ _) (hi j hj)\u27e9)\n\nvariables {\u03b1 : Type*} (s : finset \u03b1)\n\n@[simp, norm_cast] lemma of_real_prod (f : \u03b1 \u2192 \u211d) :\n  ((\u220f i in s, f i : \u211d) : \u2102) = \u220f i in s, (f i : \u2102) :=\nring_hom.map_prod of_real _ _\n\n@[simp, norm_cast] lemma of_real_sum (f : \u03b1 \u2192 \u211d) :\n  ((\u2211 i in s, f i : \u211d) : \u2102) = \u2211 i in s, (f i : \u2102) :=\nring_hom.map_sum of_real _ _\n\n@[simp] lemma re_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).re = \u2211 i in s, (f i).re :=\nre_add_group_hom.map_sum f s\n\n@[simp] lemma im_sum (f : \u03b1 \u2192 \u2102) : (\u2211 i in s, f i).im = \u2211 i in s, (f i).im :=\nim_add_group_hom.map_sum f s\n\nend complex\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.7269485298891315}}
{"text": "-- \u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\n\nuniverse u\nvariables \u03b1 \u03b2 : Type u                              -- \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f \u03b1\nvariable r : \u03b1 \u2192 \u03b1 \u2192 Prop                           -- \u0412\u0432\u0435\u0434\u0435\u043c \u043d\u0430 \u043d\u0435\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u043e\u0442\u043d\u043e\u0435\u0448\u043d\u0438\u0435 r\n\nvariable trans_r : \u2200 {x y z : \u03b1},                   -- \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u044b\u043c, \u0443\u043a\u0430\u0437\u0430\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u043a\u0442\n                     r x y \u2192 r y z \u2192 r x z\n\nvariables a b c : \u03b1                                 -- \u0442\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u044f \u043d\u0430\u0431\u043e\u0440 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 \u03b1\nvariables (hab : r a b) (hbc : r b c)               -- \u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439 \u043e \u0441\u0432\u044f\u0437\u0438 \u0438\u0445 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438\n#check trans_r hab hbc -- r a c                     -- \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 r a c\n\nvariable refl_r : \u2200 {x : \u03b1}, r x x                  -- \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0432\u043d\u043e\u0441\u0442\u044c r\nvariable symm_r : \u2200 {x y : \u03b1}, r x y \u2192 r y x        -- \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u043e\u0441\u0442\u044c r\n                                                    -- \u0442\u0435\u043f\u0435\u0440\u044c r \u2014 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438\n\nexample (a b c d : \u03b1) (hab : r a b)                 -- \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\n        (hcb : r c b) (hcd : r c d) : r a d :=      -- \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 r-\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 a \u0438 d\n  trans_r (trans_r hab (symm_r hcb)) hcd\n\n-- \u042d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\n\n#check @eq.refl  -- \u2200 {\u03b1 : Type u}, \u03b1 = \u03b1           -- \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0435\u0441\u0442\u044c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435\n#check @eq.symm  -- \u2200 {\u03b1 : Type u} {a b : \u03b1},\n                 --   a = b \u2192 b = a\n#check @eq.trans -- \u2200 {\u03b1 : Type u} {a b c : \u03b1},\n                 --   a = b \u2192 b = c \u2192 a = c\n\nexample (a b c d : \u03b1) (hab : a = b)                 -- \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\n        (hcb : c = b) (hcd : c = d) : a = d :=\n  eq.trans (eq.trans hab (eq.symm hcb)) hcd\n\nexample (a b c d : \u03b1) (hab : a = b)                 -- \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 projection notation (\u043d\u0435\u0447\u0438\u0442\u0430\u0435\u043c\u043e)\n        (hcb : c = b) (hcd : c = d) : a = d :=\n  (hab.trans hcb.symm).trans hcd\n\nexample (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (\u03bb x, f x) a = f a := -- \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u0440\u0435\u0434\u0443\u043a\u0446\u0438\u0438 \u0442\u0430\u043a\u0430\u044f \u0448\u0442\u0443\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u043c\n  eq.refl _\nexample (a : \u03b1) (b : \u03b2) : (a, b).1 = a :=           -- \u0438 \u0442\u0430\u043a\u0430\u044f \u0442\u043e\u0436\u0435\n  eq.refl _\nexample : 39 + 3 = 42 := eq.refl _                  -- \u0438 \u0434\u0430\u0436\u0435 \u0442\u0430\u043a\u0430\u044f\n\n#check @rfl -- \u2200 {\u03b1 : Type u}, {a : \u03b1}, a = a       -- \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u0436\u0435 \u0432\u0432\u043e\u0434\u044f\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e rfl == eq.refl _\n                                                    -- \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0435\n\nexample (a : \u03b1) (b : \u03b2) : (a, b).1 = a := rfl\n\n#check @eq.subst -- \u2200 {a : Type u} {a b : \u03b1} {p : \u03b1 \u2192 Prop},\n                 --   a = b \u2192 p a = p b             -- \u0432\u0430\u0436\u043d\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0432\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n                                                    -- \u0432\u043d\u0443\u0442\u0440\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430\n\nvariable p : \u03b1 \u2192 Prop\nexample (h\u2081 : a = b) (h\u2082 : p a) : p b :=            -- \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f eq.subst\n  eq.subst h\u2081 h\u2082\n\nexample (h\u2081 : a = b) (h\u2082 : p a) : p b := h\u2081 \u25b8 h\u2082    -- \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043b\u044f eq.subst (\u25b8 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \\t)\n\n#check @congr_arg -- \u2200 {\u03b1 : Type u} {\u03b2 : Type v}    -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430\u043c, \u0437\u0430\u043c\u0435\u043d\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0438\n                  --   {a\u2081 a\u2082 : \u03b1} (f : \u03b1 \u2192 \u03b2),     -- \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u0434 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0432\u0441\u0435\u043b\u0435\u043d\u043d\u044b\u0445\n                  --   a\u2081 = a\u2082 \u2192 f a\u2081 = f a\u2082        -- \u044d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0433\u0440\u0443\u044d\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0443\n\n#check @congr_fun -- \u2200 {\u03b1 : Type u} {\u03b2 : \u03b1 \u2192 Type v}-- \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u0435\u0442 \u0438 \u0441\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e\n                  --   {f g : \u03a0 (x : \u03b1), \u03b2 x},\n                  --   f = g \u2192 \u2200 x : \u03b1, f a = g a\n\n#check @congr     -- \u2200 {\u03b1 : Type u} {\u03b2 : Type v}    -- \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\n                  --   {f\u2081 f\u2082 : \u03b1 \u2192 \u03b2}\n                  --   {a\u2081 a\u2082 : \u03b1},\n                  --   f\u2081 = f\u2082 \u2192 a\u2081 = a\u2082 \u2192 f\u2081 a\u2081 = f\u2082 a\u2082\n\nexample (h : a = b) (f : \u03b1 \u2192 \u03b2) : f a = f b :=      -- \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439\n  congr_arg f h\n\nexample (f g : \u03b1 \u2192 \u03b2) (h : f = g) : f a = g a :=\n  congr_fun h a\n\nexample (f g : \u03b1 \u2192 \u03b2)\n        (h\u2081 : f = g)\n        (h\u2082 : a = b) : f a = g b :=\n  congr h\u2081 h\u2082\n\n-- \u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430\n\nexample (a b c d e : \u2115)                                   -- \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439 \u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0435\n        (h\u2081 : a = b) (h\u2082 : b = c + 1)                     -- \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e\n        (h\u2083 : c = d) (h\u2084 : e = 1 + d) : a = e :=\n  have h\u2085 : a = c + 1,     from eq.trans h\u2081 h\u2082,           -- a = b = c + 1 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430\n  have h\u2086 : c + 1 = d + 1, from congr_arg _ h\u2083,           -- \u0447\u0442\u043e\u0431 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0438\u0437 a = c + 1 \u0432 a = d + 1 \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u044b c \u043d\u0430 d,\n                                                          -- \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0438\u0437 c = d \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e c + 1 = d + 1 \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 congr_arg\n  have h\u2087 : a = d + 1,     from eq.trans h\u2085 h\u2086,           -- \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c a = c + 1 = d + 1 \u0438\u0437 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438\n  have h\u2088 : 1 + d = d + 1, from nat.add_comm 1 d,         -- \u0447\u0442\u043e\u0431 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0438\u0437 a = d + 1 \u0432 a = e \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u044b e \u043d\u0430 d + 1,\n                                                          -- \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0438\u0437 \u043a\u043e\u043c\u043c\u0443\u043d\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f (nat.add_comm) 1 + d = d + 1\n  have h\u2089 : e = d + 1,     from eq.trans h\u2084 h\u2088,           -- \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c e = 1 + d = d + 1 \u0438\u0437 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438\n  show a = e,              from eq.trans h\u2087 (eq.symm h\u2089)  -- \u0442\u0430\u043a \u043a\u0430\u043a \u0446\u0438\u0444\u0440\u044b \u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c, \u0441\u043a\u043b\u0435\u0438\u043c \u0434\u0432\u0430 \u043f\u0443\u043d\u043a\u0442\u0430 \u0432 \u043e\u0434\u0438\u043d :)\n                                                          -- \u0438\u0437 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043c e = d + 1 \u043d\u0430 d + 1 = e, \u0430 \u0434\u0430\u043b\u0435\u0435\n                                                          -- \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c a = d + 1 = e \u0438\u0437 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438\n\nexample (a b c d e : \u2115)                                   -- \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0447\u0435\u0440\u0435\u0437 \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e calc,\n        (h\u2081 : a = b) (h\u2082 : b = c + 1)                     -- \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043d\u0443\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432; \u043e\u043d\u0430 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \n        (h\u2083 : c = d) (h\u2084 : e = 1 + d) : a = e :=          -- \u0432 \u0442\u0430\u043a\u0438\u0445 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430\u0445 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438\n  calc\n    a   = b     : h\u2081                                      -- \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0435 : \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e (\u0442\u0443\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e)\n    ... = c + 1 : h\u2082                                      -- \u0442\u0440\u0438 \u0442\u043e\u0447\u043a\u0438 \u0433\u043e\u0432\u043e\u0440\u044f\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430\n    ... = d + 1 : congr_arg _ h\u2083                          -- \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043a\u043e\u043d\u0433\u0440\u0443\u044d\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u03bb x, x + 1\n    ... = 1 + d : nat.add_comm d (1 : \u2115)                  -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f\n    ... = e     : eq.symm h\u2084                              -- \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\n\n-- \u043e\u0431\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 calc:\n-- calc\n--   expr\u2080 op\u2081 expr\u2081 : proof\u2081\n--   ...   op\u2082 expr\u2082 : proof\u2082\n--   {\u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u043e\u043a}\n--   ...   opn exprn : proofn\n\nexample (a b c d e : \u2115)                                   -- \u0435\u0449\u0435 \u0440\u0430\u0437 \u0442\u043e \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u0442\u0438\u043a\u0438 rw\n        (h\u2081 : a = b) (h\u2082 : b = c + 1)                     -- \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0442\u0430\u043a\u0442\u0438\u043a\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435, \u0437\u0434\u0435\u0441\u044c \u0436\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e\n        (h\u2083 : c = d) (h\u2084 : e = 1 + d) : a = e :=          -- \u0442\u0430\u043a\u0430\u044f \u0442\u0430\u043a\u0442\u0438\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0443\u0441\u043e\u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u0440\u0430\u0432\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b\n  calc                                                    -- \u043e\u0442 \u0440\u0430\u0432\u0435\u0441\u0442\u0432\u0430, \u0447\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0433\u0440\u0443\u044d\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e\n    a   = b     : by rw h\u2081\n    ... = c + 1 : by rw h\u2082                                -- \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0442\u0438\u043a\u0438: by {tactic} {argumets}\n    ... = d + 1 : by rw h\u2083                                -- \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435: by rw {\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c}\n    ... = 1 + d : by rw nat.add_comm\n    ... = e     : by rw h\u2084\n\nexample (a b c d e : \u2115)                                   -- \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u0441\u0445\u043b\u043e\u043f\u043d\u0443\u0442\u044c\n        (h\u2081 : a = b) (h\u2082 : b = c + 1)                     -- \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0442\u0430\u043a\u0442\u0438\u043a\u0435 rw \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\n        (h\u2083 : c = d) (h\u2084 : e = 1 + d) : a = e :=\n  calc\n    a   = d + 1 : by rw [h\u2081, h\u2082, h\u2083]\n    ... = 1 + d : by rw nat.add_comm\n    ... = e     : by rw h\u2084\n    \nexample (a b c d e : \u2115)                                   -- \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u043e\u0442 \u0442\u0430\u043a\n        (h\u2081 : a = b) (h\u2082 : b = c + 1)\n        (h\u2083 : c = d) (h\u2084 : e = 1 + d) : a = e :=\n  by rw [h\u2081, h\u2082, h\u2083, nat.add_comm, h\u2084]\n\nexample (a b c d e : \u2115)                                   -- \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u0442\u0438\u043a\u0430 simp\n        (h\u2081 : a = b) (h\u2082 : b = c + 1)                     -- \u043e\u043d\u0430 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\n        (h\u2083 : c = d) (h\u2084 : e = 1 + d) : a = e :=          -- \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e\n  by simp [h\u2081, h\u2082, h\u2083, h\u2084]                                -- \u043f\u043e\u043a\u0430 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u0442\n\ntheorem T1 (a b c d e : \u2115)                                -- \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0432 \u0442\u0430\u043a\u043e\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e,\n           (h\u2081 : a = b) (h\u2082 : b = c + 1)                  -- \u043c\u044b \u0434\u0430\u0436\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0438 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043e\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u043e\n           (h\u2083 : c = d) (h\u2084 : e = 1 + d) : a = e :=\n  by simp [h\u2084, h\u2082, h\u2081, h\u2083]\n\n#print T1\n\nexample (x y : \u2115) :                                       -- \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 \u0441\u0443\u043c\u043c\u044b\n          (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n  calc\n    (x + y) * (x + y) = (x + y) * x + (x + y) * y       : by rw mul_add\n    ...               = x * x + y * x + (x + y) * y     : by rw add_mul\n    ...               = x * x + y * x + (x * y + y * y) : by rw add_mul\n    ...               = x * x + y * x + x * y + y * y   : by rw \u2190add_assoc -- \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043a\u0430 \u2190 (\\l) \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \n                                                                           -- \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f\n                                                                           -- \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443\n\n#check @add_assoc -- \u2200 {\u03b1 : Type u} (a b c : \u03b1) [_ : add_semigroup \u03b1] (a b c : \u03b1), a + b + c = a + (b + c)\n                  -- \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u043e\u043a\u0430 \u043e\u043f\u0443\u0441\u0442\u0438\u043c add_semigroup \u03b1, \u043d\u0430 \u044d\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435, \u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e typeclass\n                  -- \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0433\u043b\u0430\u0441\u0438\u0442, \u0447\u0442\u043e a + b + c = a + (b + c), \u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442:\n                  -- \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u0441\u043e \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0431\u0435\u0437 \u0441\u043a\u043e\u0431\u043e\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0438 \u043d\u0443\u0436\u043d\u0430 \u0441\u0442\u0440\u0435\u043b\u043a\u0430 \u2190\n\nlemma T2 (x y : \u2115) :                                      -- \u0438 \u0442\u0430\u043a \u0442\u043e\u0436\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 (\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u0441\u0430\u043c\u0430)\n          (x + y) * (x + y) = x * x + y * x + \n                              x * y + y * y :=\n  by simp [mul_add, add_mul]\n\n#print T2\n\nexample (f : \u2115 \u2192 \u2115)                                       -- \u0442\u0435\u043c\u0438 \u0436\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0440\u0430\u0432\u0435\u0441\u0442\u0432\u0430\n        (h : \u2200 x : \u2115, f x \u2264 f (x + 1)) : f 0 \u2264 f 3 :=\n  calc\n    f 0 \u2264 f 1 : h 0\n    ... \u2264 f 2 : h 1\n    ... \u2264 f 3 : h 2", "meta": {"author": "zmactep", "repo": "llfgg", "sha": "ed684ae69b94a4a042615c412fef68bdec8fc80c", "save_path": "github-repos/lean/zmactep-llfgg", "path": "github-repos/lean/zmactep-llfgg/llfgg-ed684ae69b94a4a042615c412fef68bdec8fc80c/4_equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7269485256261344}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Mario Carneiro\n-/\nimport tactic.basic\n\n/-- `\u2115+` is the type of positive natural numbers. It is defined as a subtype,\n  and the VM representation of `\u2115+` is the same as `\u2115` because the proof\n  is not stored. -/\ndef pnat := {n : \u2115 // n > 0}\nnotation `\u2115+` := pnat\n\ninstance coe_pnat_nat : has_coe \u2115+ \u2115 := \u27e8subtype.val\u27e9\n\nnamespace nat\n\n/-- Convert a natural number to a positive natural number. The\n  positivity assumption is inferred by `dec_trivial`. -/\ndef to_pnat (n : \u2115) (h : n > 0 . tactic.exact_dec_trivial) : \u2115+ := \u27e8n, h\u27e9\n\n/-- Write a successor as an element of `\u2115+`. -/\ndef succ_pnat (n : \u2115) : \u2115+ := \u27e8succ n, succ_pos n\u27e9\n\n@[simp] theorem succ_pnat_coe (n : \u2115) : (succ_pnat n : \u2115) = succ n := rfl\n\n/-- Convert a natural number to a pnat. `n+1` is mapped to itself,\n  and `0` becomes `1`. -/\ndef to_pnat' (n : \u2115) : \u2115+ := succ_pnat (pred n)\n\nend nat\n\nnamespace pnat\n\nopen nat\n@[simp] theorem pos (n : \u2115+) : (n : \u2115) > 0 := n.2\n\ntheorem eq {m n : \u2115+} : (m : \u2115) = n \u2192 m = n := subtype.eq\n\n@[simp] theorem mk_coe (n h) : ((\u27e8n, h\u27e9 : \u2115+) : \u2115) = n := rfl\n\ninstance : has_add \u2115+ := \u27e8\u03bb m n, \u27e8m + n, add_pos m.2 n.2\u27e9\u27e9\n\n@[simp] theorem add_coe (m n : \u2115+) : ((m + n : \u2115+) : \u2115) = m + n := rfl\n\n@[simp] theorem ne_zero (n : \u2115+) : (n : \u2115) \u2260 0 := ne_of_gt n.2\n\n@[simp] theorem to_pnat'_coe {n : \u2115} : n > 0 \u2192 (n.to_pnat' : \u2115) = n := succ_pred_eq_of_pos\n\n@[simp] theorem coe_to_pnat' (n : \u2115+) : (n : \u2115).to_pnat' = n := eq (to_pnat'_coe n.pos)\n\ninstance : comm_monoid \u2115+ :=\n{ mul       := \u03bb m n, \u27e8m.1 * n.1, mul_pos m.2 n.2\u27e9,\n  mul_assoc := \u03bb a b c, subtype.eq (mul_assoc _ _ _),\n  one       := succ_pnat 0,\n  one_mul   := \u03bb a, subtype.eq (one_mul _),\n  mul_one   := \u03bb a, subtype.eq (mul_one _),\n  mul_comm  := \u03bb a b, subtype.eq (mul_comm _ _) }\n\n@[simp] theorem one_coe : ((1 : \u2115+) : \u2115) = 1 := rfl\n\n@[simp] theorem mul_coe (m n : \u2115+) : ((m * n : \u2115+) : \u2115) = m * n := rfl\n\n/-- The power of a pnat and a nat is a pnat. -/\ndef pow (m : \u2115+) (n : \u2115) : \u2115+ :=\n\u27e8m ^ n, nat.pos_pow_of_pos _ m.pos\u27e9\n\ninstance : has_pow \u2115+ \u2115 := \u27e8pow\u27e9\n\n@[simp] theorem pow_coe (m : \u2115+) (n : \u2115) : (\u2191(m ^ n) : \u2115) = m ^ n := rfl\n\ninstance : has_repr \u2115+ := \u27e8\u03bb n, repr n.1\u27e9\n\nend pnat\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/pnat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7269485248953684}}
{"text": "/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov, Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module order.ord_continuous\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.ConditionallyCompleteLattice.Basic\nimport Mathbin.Order.RelIso.Basic\n\n/-!\n# Order continuity\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe say that a function is *left order continuous* if it sends all least upper bounds\nto least upper bounds. The order dual notion is called *right order continuity*.\n\nFor monotone functions `\u211d \u2192 \u211d` these notions correspond to the usual left and right continuity.\n\nWe prove some basic lemmas (`map_sup`, `map_Sup` etc) and prove that an `rel_iso` is both left\nand right order continuous.\n-/\n\n\nuniverse u v w x\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x}\n\nopen Function OrderDual Set\n\n/-!\n### Definitions\n-/\n\n\n#print LeftOrdContinuous /-\n/-- A function `f` between preorders is left order continuous if it preserves all suprema.  We\ndefine it using `is_lub` instead of `Sup` so that the proof works both for complete lattices and\nconditionally complete lattices. -/\ndef LeftOrdContinuous [Preorder \u03b1] [Preorder \u03b2] (f : \u03b1 \u2192 \u03b2) :=\n  \u2200 \u2983s : Set \u03b1\u2984 \u2983x\u2984, IsLUB s x \u2192 IsLUB (f '' s) (f x)\n#align left_ord_continuous LeftOrdContinuous\n-/\n\n#print RightOrdContinuous /-\n/-- A function `f` between preorders is right order continuous if it preserves all infima.  We\ndefine it using `is_glb` instead of `Inf` so that the proof works both for complete lattices and\nconditionally complete lattices. -/\ndef RightOrdContinuous [Preorder \u03b1] [Preorder \u03b2] (f : \u03b1 \u2192 \u03b2) :=\n  \u2200 \u2983s : Set \u03b1\u2984 \u2983x\u2984, IsGLB s x \u2192 IsGLB (f '' s) (f x)\n#align right_ord_continuous RightOrdContinuous\n-/\n\nnamespace LeftOrdContinuous\n\nsection Preorder\n\nvariable (\u03b1) [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2}\n\n#print LeftOrdContinuous.id /-\nprotected theorem id : LeftOrdContinuous (id : \u03b1 \u2192 \u03b1) := fun s x h => by\n  simpa only [image_id] using h\n#align left_ord_continuous.id LeftOrdContinuous.id\n-/\n\nvariable {\u03b1}\n\n#print LeftOrdContinuous.order_dual /-\nprotected theorem order_dual : LeftOrdContinuous f \u2192 RightOrdContinuous (toDual \u2218 f \u2218 ofDual) :=\n  id\n#align left_ord_continuous.order_dual LeftOrdContinuous.order_dual\n-/\n\n#print LeftOrdContinuous.map_isGreatest /-\ntheorem map_isGreatest (hf : LeftOrdContinuous f) {s : Set \u03b1} {x : \u03b1} (h : IsGreatest s x) :\n    IsGreatest (f '' s) (f x) :=\n  \u27e8mem_image_of_mem f h.1, (hf h.IsLUB).1\u27e9\n#align left_ord_continuous.map_is_greatest LeftOrdContinuous.map_isGreatest\n-/\n\n#print LeftOrdContinuous.mono /-\ntheorem mono (hf : LeftOrdContinuous f) : Monotone f := fun a\u2081 a\u2082 h =>\n  have : IsGreatest {a\u2081, a\u2082} a\u2082 := \u27e8Or.inr rfl, by simp [*]\u27e9\n  (hf.map_isGreatest this).2 <| mem_image_of_mem _ (Or.inl rfl)\n#align left_ord_continuous.mono LeftOrdContinuous.mono\n-/\n\n#print LeftOrdContinuous.comp /-\ntheorem comp (hg : LeftOrdContinuous g) (hf : LeftOrdContinuous f) : LeftOrdContinuous (g \u2218 f) :=\n  fun s x h => by simpa only [image_image] using hg (hf h)\n#align left_ord_continuous.comp LeftOrdContinuous.comp\n-/\n\n#print LeftOrdContinuous.iterate /-\nprotected theorem iterate {f : \u03b1 \u2192 \u03b1} (hf : LeftOrdContinuous f) (n : \u2115) :\n    LeftOrdContinuous (f^[n]) :=\n  Nat.recOn n (LeftOrdContinuous.id \u03b1) fun n ihn => ihn.comp hf\n#align left_ord_continuous.iterate LeftOrdContinuous.iterate\n-/\n\nend Preorder\n\nsection SemilatticeSup\n\nvariable [SemilatticeSup \u03b1] [SemilatticeSup \u03b2] {f : \u03b1 \u2192 \u03b2}\n\n/- warning: left_ord_continuous.map_sup -> LeftOrdContinuous.map_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeSup.{u1} \u03b1] [_inst_2 : SemilatticeSup.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2)) f) -> (forall (x : \u03b1) (y : \u03b1), Eq.{succ u2} \u03b2 (f (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 _inst_1) x y)) (Sup.sup.{u2} \u03b2 (SemilatticeSup.toHasSup.{u2} \u03b2 _inst_2) (f x) (f y)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeSup.{u1} \u03b1] [_inst_2 : SemilatticeSup.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2)) f) -> (forall (x : \u03b1) (y : \u03b1), Eq.{succ u2} \u03b2 (f (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 _inst_1) x y)) (Sup.sup.{u2} \u03b2 (SemilatticeSup.toSup.{u2} \u03b2 _inst_2) (f x) (f y)))\nCase conversion may be inaccurate. Consider using '#align left_ord_continuous.map_sup LeftOrdContinuous.map_sup\u2093'. -/\ntheorem map_sup (hf : LeftOrdContinuous f) (x y : \u03b1) : f (x \u2294 y) = f x \u2294 f y :=\n  (hf isLUB_pair).unique <| by simp only [image_pair, isLUB_pair]\n#align left_ord_continuous.map_sup LeftOrdContinuous.map_sup\n\n#print LeftOrdContinuous.le_iff /-\ntheorem le_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x \u2264 f y \u2194 x \u2264 y := by\n  simp only [\u2190 sup_eq_right, \u2190 hf.map_sup, h.eq_iff]\n#align left_ord_continuous.le_iff LeftOrdContinuous.le_iff\n-/\n\n#print LeftOrdContinuous.lt_iff /-\ntheorem lt_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x < f y \u2194 x < y := by\n  simp only [lt_iff_le_not_le, hf.le_iff h]\n#align left_ord_continuous.lt_iff LeftOrdContinuous.lt_iff\n-/\n\nvariable (f)\n\n#print LeftOrdContinuous.toOrderEmbedding /-\n/-- Convert an injective left order continuous function to an order embedding. -/\ndef toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) : \u03b1 \u21aao \u03b2 :=\n  \u27e8\u27e8f, h\u27e9, fun x y => hf.le_iff h\u27e9\n#align left_ord_continuous.to_order_embedding LeftOrdContinuous.toOrderEmbedding\n-/\n\nvariable {f}\n\n/- warning: left_ord_continuous.coe_to_order_embedding -> LeftOrdContinuous.coe_toOrderEmbedding is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeSup.{u1} \u03b1] [_inst_2 : SemilatticeSup.{u2} \u03b2] {f : \u03b1 -> \u03b2} (hf : LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2)) f) (h : Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 f), Eq.{max (succ u1) (succ u2)} (\u03b1 -> \u03b2) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (OrderEmbedding.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1))) (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2)))) (fun (_x : RelEmbedding.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1)))) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2))))) => \u03b1 -> \u03b2) (RelEmbedding.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1)))) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2))))) (LeftOrdContinuous.toOrderEmbedding.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f hf h)) f\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeSup.{u1} \u03b1] [_inst_2 : SemilatticeSup.{u2} \u03b2] {f : \u03b1 -> \u03b2} (hf : LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2)) f) (h : Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 f), Eq.{max (succ u1) (succ u2)} (forall (\u1fb0 : \u03b1), (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) \u1fb0) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u1, succ u2} \u03b1 \u03b2)) (RelEmbedding.toEmbedding.{u1, u2} \u03b1 \u03b2 (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : \u03b1) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_1))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : \u03b2) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : \u03b2) => LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeSup.toPartialOrder.{u2} \u03b2 _inst_2))) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (LeftOrdContinuous.toOrderEmbedding.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f hf h))) f\nCase conversion may be inaccurate. Consider using '#align left_ord_continuous.coe_to_order_embedding LeftOrdContinuous.coe_toOrderEmbedding\u2093'. -/\n@[simp]\ntheorem coe_toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) :\n    \u21d1(hf.toOrderEmbedding f h) = f :=\n  rfl\n#align left_ord_continuous.coe_to_order_embedding LeftOrdContinuous.coe_toOrderEmbedding\n\nend SemilatticeSup\n\nsection CompleteLattice\n\nvariable [CompleteLattice \u03b1] [CompleteLattice \u03b2] {f : \u03b1 \u2192 \u03b2}\n\n/- warning: left_ord_continuous.map_Sup' -> LeftOrdContinuous.map_sup\u209b' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (SupSet.sup\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toHasSup.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (SupSet.sup\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toSupSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align left_ord_continuous.map_Sup' LeftOrdContinuous.map_sup\u209b'\u2093'. -/\ntheorem map_sup\u209b' (hf : LeftOrdContinuous f) (s : Set \u03b1) : f (sup\u209b s) = sup\u209b (f '' s) :=\n  (hf <| isLUB_sup\u209b s).sup\u209b_eq.symm\n#align left_ord_continuous.map_Sup' LeftOrdContinuous.map_sup\u209b'\n\n/- warning: left_ord_continuous.map_Sup -> LeftOrdContinuous.map_sup\u209b is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (sup\u1d62.{u2, succ u1} \u03b2 (ConditionallyCompleteLattice.toHasSup.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b1 (fun (x : \u03b1) => sup\u1d62.{u2, 0} \u03b2 (ConditionallyCompleteLattice.toHasSup.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) => f x))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (sup\u1d62.{u2, succ u1} \u03b2 (ConditionallyCompleteLattice.toSupSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b1 (fun (x : \u03b1) => sup\u1d62.{u2, 0} \u03b2 (ConditionallyCompleteLattice.toSupSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) => f x))))\nCase conversion may be inaccurate. Consider using '#align left_ord_continuous.map_Sup LeftOrdContinuous.map_sup\u209b\u2093'. -/\ntheorem map_sup\u209b (hf : LeftOrdContinuous f) (s : Set \u03b1) : f (sup\u209b s) = \u2a06 x \u2208 s, f x := by\n  rw [hf.map_Sup', sup\u209b_image]\n#align left_ord_continuous.map_Sup LeftOrdContinuous.map_sup\u209b\n\n/- warning: left_ord_continuous.map_supr -> LeftOrdContinuous.map_sup\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (g : \u03b9 -> \u03b1), Eq.{succ u2} \u03b2 (f (sup\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) \u03b9 (fun (i : \u03b9) => g i))) (sup\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toHasSup.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b9 (fun (i : \u03b9) => f (g i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (g : \u03b9 -> \u03b1), Eq.{succ u2} \u03b2 (f (sup\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) \u03b9 (fun (i : \u03b9) => g i))) (sup\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toSupSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b9 (fun (i : \u03b9) => f (g i))))\nCase conversion may be inaccurate. Consider using '#align left_ord_continuous.map_supr LeftOrdContinuous.map_sup\u1d62\u2093'. -/\ntheorem map_sup\u1d62 (hf : LeftOrdContinuous f) (g : \u03b9 \u2192 \u03b1) : f (\u2a06 i, g i) = \u2a06 i, f (g i) := by\n  simp only [sup\u1d62, hf.map_Sup', \u2190 range_comp]\n#align left_ord_continuous.map_supr LeftOrdContinuous.map_sup\u1d62\n\nend CompleteLattice\n\nsection ConditionallyCompleteLattice\n\nvariable [ConditionallyCompleteLattice \u03b1] [ConditionallyCompleteLattice \u03b2] [Nonempty \u03b9] {f : \u03b1 \u2192 \u03b2}\n\n/- warning: left_ord_continuous.map_cSup -> LeftOrdContinuous.map_csup\u209b is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {s : Set.{u1} \u03b1}, (Set.Nonempty.{u1} \u03b1 s) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) s) -> (Eq.{succ u2} \u03b2 (f (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 _inst_1) s)) (SupSet.sup\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toHasSup.{u2} \u03b2 _inst_2) (Set.image.{u1, u2} \u03b1 \u03b2 f s))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {s : Set.{u1} \u03b1}, (Set.Nonempty.{u1} \u03b1 s) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) s) -> (Eq.{succ u2} \u03b2 (f (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 _inst_1) s)) (SupSet.sup\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toSupSet.{u2} \u03b2 _inst_2) (Set.image.{u1, u2} \u03b1 \u03b2 f s))))\nCase conversion may be inaccurate. Consider using '#align left_ord_continuous.map_cSup LeftOrdContinuous.map_csup\u209b\u2093'. -/\ntheorem map_csup\u209b (hf : LeftOrdContinuous f) {s : Set \u03b1} (sne : s.Nonempty) (sbdd : BddAbove s) :\n    f (sup\u209b s) = sup\u209b (f '' s) :=\n  ((hf <| isLUB_csup\u209b sne sbdd).csup\u209b_eq <| sne.image f).symm\n#align left_ord_continuous.map_cSup LeftOrdContinuous.map_csup\u209b\n\n/- warning: left_ord_continuous.map_csupr -> LeftOrdContinuous.map_csup\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] [_inst_3 : Nonempty.{u3} \u03b9] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {g : \u03b9 -> \u03b1}, (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (Set.range.{u1, u3} \u03b1 \u03b9 g)) -> (Eq.{succ u2} \u03b2 (f (sup\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 _inst_1) \u03b9 (fun (i : \u03b9) => g i))) (sup\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toHasSup.{u2} \u03b2 _inst_2) \u03b9 (fun (i : \u03b9) => f (g i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] [_inst_3 : Nonempty.{u3} \u03b9] {f : \u03b1 -> \u03b2}, (LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {g : \u03b9 -> \u03b1}, (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (Set.range.{u1, u3} \u03b1 \u03b9 g)) -> (Eq.{succ u2} \u03b2 (f (sup\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 _inst_1) \u03b9 (fun (i : \u03b9) => g i))) (sup\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toSupSet.{u2} \u03b2 _inst_2) \u03b9 (fun (i : \u03b9) => f (g i)))))\nCase conversion may be inaccurate. Consider using '#align left_ord_continuous.map_csupr LeftOrdContinuous.map_csup\u1d62\u2093'. -/\ntheorem map_csup\u1d62 (hf : LeftOrdContinuous f) {g : \u03b9 \u2192 \u03b1} (hg : BddAbove (range g)) :\n    f (\u2a06 i, g i) = \u2a06 i, f (g i) := by\n  simp only [sup\u1d62, hf.map_cSup (range_nonempty _) hg, \u2190 range_comp]\n#align left_ord_continuous.map_csupr LeftOrdContinuous.map_csup\u1d62\n\nend ConditionallyCompleteLattice\n\nend LeftOrdContinuous\n\nnamespace RightOrdContinuous\n\nsection Preorder\n\nvariable (\u03b1) [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2}\n\n#print RightOrdContinuous.id /-\nprotected theorem id : RightOrdContinuous (id : \u03b1 \u2192 \u03b1) := fun s x h => by\n  simpa only [image_id] using h\n#align right_ord_continuous.id RightOrdContinuous.id\n-/\n\nvariable {\u03b1}\n\n#print RightOrdContinuous.orderDual /-\nprotected theorem orderDual : RightOrdContinuous f \u2192 LeftOrdContinuous (toDual \u2218 f \u2218 ofDual) :=\n  id\n#align right_ord_continuous.order_dual RightOrdContinuous.orderDual\n-/\n\n#print RightOrdContinuous.map_isLeast /-\ntheorem map_isLeast (hf : RightOrdContinuous f) {s : Set \u03b1} {x : \u03b1} (h : IsLeast s x) :\n    IsLeast (f '' s) (f x) :=\n  hf.OrderDual.map_isGreatest h\n#align right_ord_continuous.map_is_least RightOrdContinuous.map_isLeast\n-/\n\n#print RightOrdContinuous.mono /-\ntheorem mono (hf : RightOrdContinuous f) : Monotone f :=\n  hf.OrderDual.mono.dual\n#align right_ord_continuous.mono RightOrdContinuous.mono\n-/\n\n#print RightOrdContinuous.comp /-\ntheorem comp (hg : RightOrdContinuous g) (hf : RightOrdContinuous f) : RightOrdContinuous (g \u2218 f) :=\n  hg.OrderDual.comp hf.OrderDual\n#align right_ord_continuous.comp RightOrdContinuous.comp\n-/\n\n#print RightOrdContinuous.iterate /-\nprotected theorem iterate {f : \u03b1 \u2192 \u03b1} (hf : RightOrdContinuous f) (n : \u2115) :\n    RightOrdContinuous (f^[n]) :=\n  hf.OrderDual.iterate n\n#align right_ord_continuous.iterate RightOrdContinuous.iterate\n-/\n\nend Preorder\n\nsection SemilatticeInf\n\nvariable [SemilatticeInf \u03b1] [SemilatticeInf \u03b2] {f : \u03b1 \u2192 \u03b2}\n\n/- warning: right_ord_continuous.map_inf -> RightOrdContinuous.map_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeInf.{u1} \u03b1] [_inst_2 : SemilatticeInf.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2)) f) -> (forall (x : \u03b1) (y : \u03b1), Eq.{succ u2} \u03b2 (f (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 _inst_1) x y)) (Inf.inf.{u2} \u03b2 (SemilatticeInf.toHasInf.{u2} \u03b2 _inst_2) (f x) (f y)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeInf.{u1} \u03b1] [_inst_2 : SemilatticeInf.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2)) f) -> (forall (x : \u03b1) (y : \u03b1), Eq.{succ u2} \u03b2 (f (Inf.inf.{u1} \u03b1 (SemilatticeInf.toInf.{u1} \u03b1 _inst_1) x y)) (Inf.inf.{u2} \u03b2 (SemilatticeInf.toInf.{u2} \u03b2 _inst_2) (f x) (f y)))\nCase conversion may be inaccurate. Consider using '#align right_ord_continuous.map_inf RightOrdContinuous.map_inf\u2093'. -/\ntheorem map_inf (hf : RightOrdContinuous f) (x y : \u03b1) : f (x \u2293 y) = f x \u2293 f y :=\n  hf.OrderDual.map_sup x y\n#align right_ord_continuous.map_inf RightOrdContinuous.map_inf\n\n#print RightOrdContinuous.le_iff /-\ntheorem le_iff (hf : RightOrdContinuous f) (h : Injective f) {x y} : f x \u2264 f y \u2194 x \u2264 y :=\n  hf.OrderDual.le_iff h\n#align right_ord_continuous.le_iff RightOrdContinuous.le_iff\n-/\n\n#print RightOrdContinuous.lt_iff /-\ntheorem lt_iff (hf : RightOrdContinuous f) (h : Injective f) {x y} : f x < f y \u2194 x < y :=\n  hf.OrderDual.lt_iff h\n#align right_ord_continuous.lt_iff RightOrdContinuous.lt_iff\n-/\n\nvariable (f)\n\n#print RightOrdContinuous.toOrderEmbedding /-\n/-- Convert an injective left order continuous function to a `order_embedding`. -/\ndef toOrderEmbedding (hf : RightOrdContinuous f) (h : Injective f) : \u03b1 \u21aao \u03b2 :=\n  \u27e8\u27e8f, h\u27e9, fun x y => hf.le_iff h\u27e9\n#align right_ord_continuous.to_order_embedding RightOrdContinuous.toOrderEmbedding\n-/\n\nvariable {f}\n\n/- warning: right_ord_continuous.coe_to_order_embedding -> RightOrdContinuous.coe_toOrderEmbedding is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeInf.{u1} \u03b1] [_inst_2 : SemilatticeInf.{u2} \u03b2] {f : \u03b1 -> \u03b2} (hf : RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2)) f) (h : Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 f), Eq.{max (succ u1) (succ u2)} (\u03b1 -> \u03b2) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (OrderEmbedding.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1))) (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2)))) (fun (_x : RelEmbedding.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1)))) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2))))) => \u03b1 -> \u03b2) (RelEmbedding.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1)))) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2))))) (RightOrdContinuous.toOrderEmbedding.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f hf h)) f\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : SemilatticeInf.{u1} \u03b1] [_inst_2 : SemilatticeInf.{u2} \u03b2] {f : \u03b1 -> \u03b2} (hf : RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1)) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2)) f) (h : Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 f), Eq.{max (succ u1) (succ u2)} (forall (\u1fb0 : \u03b1), (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) \u1fb0) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u1, succ u2} \u03b1 \u03b2)) (RelEmbedding.toEmbedding.{u1, u2} \u03b1 \u03b2 (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : \u03b1) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_1))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : \u03b2) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : \u03b2) => LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 _inst_2))) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (RightOrdContinuous.toOrderEmbedding.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f hf h))) f\nCase conversion may be inaccurate. Consider using '#align right_ord_continuous.coe_to_order_embedding RightOrdContinuous.coe_toOrderEmbedding\u2093'. -/\n@[simp]\ntheorem coe_toOrderEmbedding (hf : RightOrdContinuous f) (h : Injective f) :\n    \u21d1(hf.toOrderEmbedding f h) = f :=\n  rfl\n#align right_ord_continuous.coe_to_order_embedding RightOrdContinuous.coe_toOrderEmbedding\n\nend SemilatticeInf\n\nsection CompleteLattice\n\nvariable [CompleteLattice \u03b1] [CompleteLattice \u03b2] {f : \u03b1 \u2192 \u03b2}\n\n/- warning: right_ord_continuous.map_Inf' -> RightOrdContinuous.map_inf\u209b' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (InfSet.inf\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toHasInf.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (InfSet.inf\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toInfSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align right_ord_continuous.map_Inf' RightOrdContinuous.map_inf\u209b'\u2093'. -/\ntheorem map_inf\u209b' (hf : RightOrdContinuous f) (s : Set \u03b1) : f (inf\u209b s) = inf\u209b (f '' s) :=\n  hf.OrderDual.map_sup\u209b' s\n#align right_ord_continuous.map_Inf' RightOrdContinuous.map_inf\u209b'\n\n/- warning: right_ord_continuous.map_Inf -> RightOrdContinuous.map_inf\u209b is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (inf\u1d62.{u2, succ u1} \u03b2 (ConditionallyCompleteLattice.toHasInf.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b1 (fun (x : \u03b1) => inf\u1d62.{u2, 0} \u03b2 (ConditionallyCompleteLattice.toHasInf.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) => f x))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (s : Set.{u1} \u03b1), Eq.{succ u2} \u03b2 (f (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (inf\u1d62.{u2, succ u1} \u03b2 (ConditionallyCompleteLattice.toInfSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b1 (fun (x : \u03b1) => inf\u1d62.{u2, 0} \u03b2 (ConditionallyCompleteLattice.toInfSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) (fun (H : Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x s) => f x))))\nCase conversion may be inaccurate. Consider using '#align right_ord_continuous.map_Inf RightOrdContinuous.map_inf\u209b\u2093'. -/\ntheorem map_inf\u209b (hf : RightOrdContinuous f) (s : Set \u03b1) : f (inf\u209b s) = \u2a05 x \u2208 s, f x :=\n  hf.OrderDual.map_sup\u209b s\n#align right_ord_continuous.map_Inf RightOrdContinuous.map_inf\u209b\n\n/- warning: right_ord_continuous.map_infi -> RightOrdContinuous.map_inf\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (g : \u03b9 -> \u03b1), Eq.{succ u2} \u03b2 (f (inf\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) \u03b9 (fun (i : \u03b9) => g i))) (inf\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toHasInf.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b9 (fun (i : \u03b9) => f (g i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : CompleteLattice.{u1} \u03b1] [_inst_2 : CompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))) (PartialOrder.toPreorder.{u2} \u03b2 (CompleteSemilatticeInf.toPartialOrder.{u2} \u03b2 (CompleteLattice.toCompleteSemilatticeInf.{u2} \u03b2 _inst_2))) f) -> (forall (g : \u03b9 -> \u03b1), Eq.{succ u2} \u03b2 (f (inf\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (CompleteLattice.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) \u03b9 (fun (i : \u03b9) => g i))) (inf\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toInfSet.{u2} \u03b2 (CompleteLattice.toConditionallyCompleteLattice.{u2} \u03b2 _inst_2)) \u03b9 (fun (i : \u03b9) => f (g i))))\nCase conversion may be inaccurate. Consider using '#align right_ord_continuous.map_infi RightOrdContinuous.map_inf\u1d62\u2093'. -/\ntheorem map_inf\u1d62 (hf : RightOrdContinuous f) (g : \u03b9 \u2192 \u03b1) : f (\u2a05 i, g i) = \u2a05 i, f (g i) :=\n  hf.OrderDual.map_sup\u1d62 g\n#align right_ord_continuous.map_infi RightOrdContinuous.map_inf\u1d62\n\nend CompleteLattice\n\nsection ConditionallyCompleteLattice\n\nvariable [ConditionallyCompleteLattice \u03b1] [ConditionallyCompleteLattice \u03b2] [Nonempty \u03b9] {f : \u03b1 \u2192 \u03b2}\n\n/- warning: right_ord_continuous.map_cInf -> RightOrdContinuous.map_cinf\u209b is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {s : Set.{u1} \u03b1}, (Set.Nonempty.{u1} \u03b1 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) s) -> (Eq.{succ u2} \u03b2 (f (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 _inst_1) s)) (InfSet.inf\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toHasInf.{u2} \u03b2 _inst_2) (Set.image.{u1, u2} \u03b1 \u03b2 f s))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {s : Set.{u1} \u03b1}, (Set.Nonempty.{u1} \u03b1 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) s) -> (Eq.{succ u2} \u03b2 (f (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 _inst_1) s)) (InfSet.inf\u209b.{u2} \u03b2 (ConditionallyCompleteLattice.toInfSet.{u2} \u03b2 _inst_2) (Set.image.{u1, u2} \u03b1 \u03b2 f s))))\nCase conversion may be inaccurate. Consider using '#align right_ord_continuous.map_cInf RightOrdContinuous.map_cinf\u209b\u2093'. -/\ntheorem map_cinf\u209b (hf : RightOrdContinuous f) {s : Set \u03b1} (sne : s.Nonempty) (sbdd : BddBelow s) :\n    f (inf\u209b s) = inf\u209b (f '' s) :=\n  hf.OrderDual.map_csup\u209b sne sbdd\n#align right_ord_continuous.map_cInf RightOrdContinuous.map_cinf\u209b\n\n/- warning: right_ord_continuous.map_cinfi -> RightOrdContinuous.map_cinf\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] [_inst_3 : Nonempty.{u3} \u03b9] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {g : \u03b9 -> \u03b1}, (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (Set.range.{u1, u3} \u03b1 \u03b9 g)) -> (Eq.{succ u2} \u03b2 (f (inf\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 _inst_1) \u03b9 (fun (i : \u03b9) => g i))) (inf\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toHasInf.{u2} \u03b2 _inst_2) \u03b9 (fun (i : \u03b9) => f (g i)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b9 : Sort.{u3}} [_inst_1 : ConditionallyCompleteLattice.{u1} \u03b1] [_inst_2 : ConditionallyCompleteLattice.{u2} \u03b2] [_inst_3 : Nonempty.{u3} \u03b9] {f : \u03b1 -> \u03b2}, (RightOrdContinuous.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (ConditionallyCompleteLattice.toLattice.{u2} \u03b2 _inst_2)))) f) -> (forall {g : \u03b9 -> \u03b1}, (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 _inst_1)))) (Set.range.{u1, u3} \u03b1 \u03b9 g)) -> (Eq.{succ u2} \u03b2 (f (inf\u1d62.{u1, u3} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 _inst_1) \u03b9 (fun (i : \u03b9) => g i))) (inf\u1d62.{u2, u3} \u03b2 (ConditionallyCompleteLattice.toInfSet.{u2} \u03b2 _inst_2) \u03b9 (fun (i : \u03b9) => f (g i)))))\nCase conversion may be inaccurate. Consider using '#align right_ord_continuous.map_cinfi RightOrdContinuous.map_cinf\u1d62\u2093'. -/\ntheorem map_cinf\u1d62 (hf : RightOrdContinuous f) {g : \u03b9 \u2192 \u03b1} (hg : BddBelow (range g)) :\n    f (\u2a05 i, g i) = \u2a05 i, f (g i) :=\n  hf.OrderDual.map_csup\u1d62 hg\n#align right_ord_continuous.map_cinfi RightOrdContinuous.map_cinf\u1d62\n\nend ConditionallyCompleteLattice\n\nend RightOrdContinuous\n\nnamespace OrderIso\n\nsection Preorder\n\nvariable [Preorder \u03b1] [Preorder \u03b2] (e : \u03b1 \u2243o \u03b2) {s : Set \u03b1} {x : \u03b1}\n\n/- warning: order_iso.left_ord_continuous -> OrderIso.leftOrdContinuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] (e : OrderIso.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 _inst_1) (Preorder.toLE.{u2} \u03b2 _inst_2)), LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (OrderIso.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 _inst_1) (Preorder.toLE.{u2} \u03b2 _inst_2)) (fun (_x : RelIso.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2))) => \u03b1 -> \u03b2) (RelIso.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2))) e)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] (e : OrderIso.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 _inst_1) (Preorder.toLE.{u2} \u03b2 _inst_2)), LeftOrdContinuous.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u1, succ u2} \u03b1 \u03b2)) (RelEmbedding.toEmbedding.{u1, u2} \u03b1 \u03b2 (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1281 : \u03b1) (x._@.Mathlib.Order.Hom.Basic._hyg.1283 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) x._@.Mathlib.Order.Hom.Basic._hyg.1281 x._@.Mathlib.Order.Hom.Basic._hyg.1283) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1296 : \u03b2) (x._@.Mathlib.Order.Hom.Basic._hyg.1298 : \u03b2) => LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2) x._@.Mathlib.Order.Hom.Basic._hyg.1296 x._@.Mathlib.Order.Hom.Basic._hyg.1298) (RelIso.toRelEmbedding.{u1, u2} \u03b1 \u03b2 (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1281 : \u03b1) (x._@.Mathlib.Order.Hom.Basic._hyg.1283 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) x._@.Mathlib.Order.Hom.Basic._hyg.1281 x._@.Mathlib.Order.Hom.Basic._hyg.1283) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1296 : \u03b2) (x._@.Mathlib.Order.Hom.Basic._hyg.1298 : \u03b2) => LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2) x._@.Mathlib.Order.Hom.Basic._hyg.1296 x._@.Mathlib.Order.Hom.Basic._hyg.1298) e)))\nCase conversion may be inaccurate. Consider using '#align order_iso.left_ord_continuous OrderIso.leftOrdContinuous\u2093'. -/\nprotected theorem leftOrdContinuous : LeftOrdContinuous e := fun s x hx =>\n  \u27e8Monotone.mem_upperBounds_image (fun x y => e.map_rel_iff.2) hx.1, fun y hy =>\n    e.rel_symm_apply.1 <|\n      (isLUB_le_iff hx).2 fun x' hx' => e.rel_symm_apply.2 <| hy <| mem_image_of_mem _ hx'\u27e9\n#align order_iso.left_ord_continuous OrderIso.leftOrdContinuous\n\n/- warning: order_iso.right_ord_continuous -> OrderIso.rightOrdContinuous is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] (e : OrderIso.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 _inst_1) (Preorder.toLE.{u2} \u03b2 _inst_2)), RightOrdContinuous.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (OrderIso.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 _inst_1) (Preorder.toLE.{u2} \u03b2 _inst_2)) (fun (_x : RelIso.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2))) => \u03b1 -> \u03b2) (RelIso.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)) (LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2))) e)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] (e : OrderIso.{u1, u2} \u03b1 \u03b2 (Preorder.toLE.{u1} \u03b1 _inst_1) (Preorder.toLE.{u2} \u03b2 _inst_2)), RightOrdContinuous.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 (fun (_x : \u03b1) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : \u03b1) => \u03b2) _x) (EmbeddingLike.toFunLike.{max (succ u1) (succ u2), succ u1, succ u2} (Function.Embedding.{succ u1, succ u2} \u03b1 \u03b2) \u03b1 \u03b2 (Function.instEmbeddingLikeEmbedding.{succ u1, succ u2} \u03b1 \u03b2)) (RelEmbedding.toEmbedding.{u1, u2} \u03b1 \u03b2 (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1281 : \u03b1) (x._@.Mathlib.Order.Hom.Basic._hyg.1283 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) x._@.Mathlib.Order.Hom.Basic._hyg.1281 x._@.Mathlib.Order.Hom.Basic._hyg.1283) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1296 : \u03b2) (x._@.Mathlib.Order.Hom.Basic._hyg.1298 : \u03b2) => LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2) x._@.Mathlib.Order.Hom.Basic._hyg.1296 x._@.Mathlib.Order.Hom.Basic._hyg.1298) (RelIso.toRelEmbedding.{u1, u2} \u03b1 \u03b2 (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1281 : \u03b1) (x._@.Mathlib.Order.Hom.Basic._hyg.1283 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) x._@.Mathlib.Order.Hom.Basic._hyg.1281 x._@.Mathlib.Order.Hom.Basic._hyg.1283) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1296 : \u03b2) (x._@.Mathlib.Order.Hom.Basic._hyg.1298 : \u03b2) => LE.le.{u2} \u03b2 (Preorder.toLE.{u2} \u03b2 _inst_2) x._@.Mathlib.Order.Hom.Basic._hyg.1296 x._@.Mathlib.Order.Hom.Basic._hyg.1298) e)))\nCase conversion may be inaccurate. Consider using '#align order_iso.right_ord_continuous OrderIso.rightOrdContinuous\u2093'. -/\nprotected theorem rightOrdContinuous : RightOrdContinuous e :=\n  OrderIso.leftOrdContinuous e.dual\n#align order_iso.right_ord_continuous OrderIso.rightOrdContinuous\n\nend Preorder\n\nend OrderIso\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/OrdContinuous.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782094, "lm_q2_score": 0.8333245953120234, "lm_q1q2_score": 0.7269485229752249}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Kenny Lau\n\n! This file was ported from Lean 3 source module data.int.range\n! leanprover-community/mathlib commit 7b78d1776212a91ecc94cf601f83bdcc46b04213\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.List.Range\nimport Mathlib.Data.Int.Order.Basic\n\n/-!\n# Intervals in \u2124\n\nThis file defines integer ranges. `range m n` is the set of integers greater than `m` and strictly\nless than `n`.\n\n## Note\n\nThis could be unified with `Data.List.Intervals`. See the TODOs there.\n-/\n\n-- Porting note: Many unfolds about `Lean.Internal.coeM`\nnamespace Int\n\n/-- List enumerating `[m, n)`. This is the \u2124 variant of `List.Ico`. -/\ndef range (m n : \u2124) : List \u2124 :=\n  ((List.range (toNat (n - m))) : List \u2115).map fun (r : \u2115) => (m + r : \u2124)\n#align int.range Int.range\n\ntheorem mem_range_iff {m n r : \u2124} : r \u2208 range m n \u2194 m \u2264 r \u2227 r < n := by\n  simp only [range, List.mem_map, List.mem_range, lt_toNat, lt_sub_iff_add_lt, add_comm]\n  exact \u27e8fun \u27e8a, ha\u27e9 => ha.2 \u25b8 \u27e8le_add_of_nonneg_right (Int.coe_nat_nonneg _), ha.1\u27e9,\n    fun h => \u27e8toNat (r - m), by simp [toNat_of_nonneg (sub_nonneg.2 h.1), h.2] \u27e9\u27e9\n\n#align int.mem_range_iff Int.mem_range_iff\n\ninstance decidableLELT (P : Int \u2192 Prop) [DecidablePred P] (m n : \u2124) :\n    Decidable (\u2200 r, m \u2264 r \u2192 r < n \u2192 P r) :=\n  decidable_of_iff (\u2200 r \u2208 range m n, P r) <| by simp only [mem_range_iff, and_imp]\n#align int.decidable_le_lt Int.decidableLELT\n\ninstance decidableLELE (P : Int \u2192 Prop) [DecidablePred P] (m n : \u2124) :\n    Decidable (\u2200 r, m \u2264 r \u2192 r \u2264 n \u2192 P r) := by\n  -- Porting note: The previous code was:\n  -- decidable_of_iff (\u2200 r \u2208 range m (n + 1), P r) <| by\n  --   simp only [mem_range_iff, and_imp, lt_add_one_iff]\n  --\n  -- This fails to synthesize an instance\n  -- `Decidable (\u2200 (r : \u2124), r \u2208 range m (n + 1) \u2192 P r)`\n    apply decidable_of_iff (\u2200 r \u2208 range m (n + 1), P r)\n    apply Iff.intro <;> intros h _ _\n    . intro _; apply h\n      simp_all only [mem_range_iff, and_imp, lt_add_one_iff]\n    . simp_all only [mem_range_iff, and_imp, lt_add_one_iff]\n#align int.decidable_le_le Int.decidableLELE\n\ninstance decidableLTLT (P : Int \u2192 Prop) [DecidablePred P] (m n : \u2124) :\n    Decidable (\u2200 r, m < r \u2192 r < n \u2192 P r) :=\n  Int.decidableLELT P _ _\n#align int.decidable_lt_lt Int.decidableLTLT\n\ninstance decidableLTLE (P : Int \u2192 Prop) [DecidablePred P] (m n : \u2124) :\n    Decidable (\u2200 r, m < r \u2192 r \u2264 n \u2192 P r) :=\n  Int.decidableLELE P _ _\n#align int.decidable_lt_le Int.decidableLTLE\n\nend Int\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/Range.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7269485202096619}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n-/\nimport algebra.order.absolute_value\nimport algebra.field_power\nimport ring_theory.int.basic\nimport tactic.basic\nimport tactic.ring_exp\nimport number_theory.divisors\nimport data.nat.factorization.basic\n\n/-!\n# p-adic Valuation\n\nThis file defines the p-adic valuation on \u2115, \u2124, and \u211a.\n\nThe p-adic valuation on \u211a is the difference of the multiplicities of `p` in the numerator and\ndenominator of `q`. This function obeys the standard properties of a valuation, with the appropriate\nassumptions on p. The p-adic valuations on \u2115 and \u2124 agree with that on \u211a.\n\nThe valuation induces a norm on \u211a. This norm is defined in padic_norm.lean.\n\n## Notations\n\nThis file uses the local notation `/.` for `rat.mk`.\n\n## Implementation notes\n\nMuch, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically\nby taking `[fact (prime p)]` as a type class argument.\n\n## References\n\n* [F. Q. Gouv\u00eaa, *p-adic numbers*][gouvea1997]\n* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]\n* <https://en.wikipedia.org/wiki/P-adic_number>\n\n## Tags\n\np-adic, p adic, padic, norm, valuation\n-/\n\nuniverse u\n\nopen nat\n\nopen_locale rat\n\nopen multiplicity\n\n/--\nFor `p \u2260 1`, the p-adic valuation of a natural `n \u2260 0` is the largest natural number `k` such that\np^k divides z.\nIf `n = 0` or `p = 1`, then `padic_val_nat p q` defaults to 0.\n-/\ndef padic_val_nat (p : \u2115) (n : \u2115) : \u2115 :=\nif h : p \u2260 1 \u2227 0 < n\nthen (multiplicity p n).get (multiplicity.finite_nat_iff.2 h)\nelse 0\n\nnamespace padic_val_nat\nopen multiplicity\nvariables {p : \u2115}\n\n/-- `padic_val_nat p 0` is 0 for any `p`. -/\n@[simp] protected \n\n/-- `padic_val_nat p 1` is 0 for any `p`. -/\n@[simp] protected lemma one : padic_val_nat p 1 = 0 :=\nby unfold padic_val_nat; split_ifs; simp *\n\n/-- For `p \u2260 0, p \u2260 1, `padic_val_rat p p` is 1. -/\n@[simp] lemma self (hp : 1 < p) : padic_val_nat p p = 1 :=\nbegin\n  have neq_one : (\u00ac p = 1) \u2194 true,\n  { exact iff_of_true ((ne_of_lt hp).symm) trivial, },\n  have eq_zero_false : (p = 0) \u2194 false,\n  { exact iff_false_intro ((ne_of_lt (trans zero_lt_one hp)).symm) },\n  simp [padic_val_nat, neq_one, eq_zero_false],\nend\n\nlemma eq_zero_of_not_dvd {n : \u2115} (h : \u00ac p \u2223 n) : padic_val_nat p n = 0 :=\nbegin\n  rw padic_val_nat,\n  split_ifs,\n  { simp [multiplicity_eq_zero_of_not_dvd h], },\n  refl,\nend\n\nend padic_val_nat\n\n/--\nFor `p \u2260 1`, the p-adic valuation of an integer `z \u2260 0` is the largest natural number `k` such that\np^k divides z.\nIf `x = 0` or `p = 1`, then `padic_val_int p q` defaults to 0.\n-/\ndef padic_val_int (p : \u2115) (z : \u2124) : \u2115 :=\npadic_val_nat p (z.nat_abs)\n\nnamespace padic_val_int\nopen multiplicity\nvariables {p : \u2115}\n\nlemma of_ne_one_ne_zero {z : \u2124} (hp : p \u2260 1) (hz : z \u2260 0) : padic_val_int p z =\n  (multiplicity (p : \u2124) z).get (by {apply multiplicity.finite_int_iff.2, simp [hp, hz]}) :=\nbegin\n  rw [padic_val_int, padic_val_nat, dif_pos (and.intro hp (int.nat_abs_pos_of_ne_zero hz))],\n  simp_rw multiplicity.int.nat_abs p z,\n  refl,\nend\n\n/-- `padic_val_int p 0` is 0 for any `p`. -/\n@[simp] protected lemma zero : padic_val_int p 0 = 0 :=\nby simp [padic_val_int]\n\n/-- `padic_val_int p 1` is 0 for any `p`. -/\n@[simp] protected lemma one : padic_val_int p 1 = 0 :=\nby simp [padic_val_int]\n\n/-- The p-adic value of an natural is its p-adic_value as an integer -/\n@[simp] lemma of_nat {n : \u2115} : padic_val_int p (n : \u2124) = padic_val_nat p n :=\nby simp [padic_val_int]\n\n/-- For `p \u2260 0, p \u2260 1, `padic_val_int p p` is 1. -/\nlemma self (hp : 1 < p) : padic_val_int p p = 1 :=\nby simp [padic_val_nat.self hp]\n\nlemma eq_zero_of_not_dvd {z : \u2124} (h : \u00ac (p : \u2124) \u2223 z) : padic_val_int p z = 0 :=\nbegin\n  rw [padic_val_int, padic_val_nat],\n  split_ifs,\n  { simp_rw multiplicity.int.nat_abs,\n    simp [multiplicity_eq_zero_of_not_dvd h], },\n  refl,\nend\n\nend padic_val_int\n\n/--\n`padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the\nvaluation of `q.denom`.\nIf `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to 0.\n-/\ndef padic_val_rat (p : \u2115) (q : \u211a) : \u2124 :=\npadic_val_int p q.num - padic_val_nat p q.denom\n\nnamespace padic_val_rat\nopen multiplicity\nvariables {p : \u2115}\n\n/-- `padic_val_rat p q` is symmetric in `q`. -/\n@[simp] protected lemma neg (q : \u211a) : padic_val_rat p (-q) = padic_val_rat p q :=\nby simp [padic_val_rat, padic_val_int]\n\n/-- `padic_val_rat p 0` is 0 for any `p`. -/\n@[simp]\nprotected lemma zero (m : nat) : padic_val_rat m 0 = 0 := by simp [padic_val_rat, padic_val_int]\n\n/-- `padic_val_rat p 1` is 0 for any `p`. -/\n@[simp] protected lemma one : padic_val_rat p 1 = 0 := by simp [padic_val_rat, padic_val_int]\n\n/-- The p-adic value of an integer `z \u2260 0` is its p-adic_value as a rational -/\n@[simp] lemma of_int {z : \u2124} : padic_val_rat p (z : \u211a) = padic_val_int p z :=\nby simp [padic_val_rat]\n\n/-- The p-adic value of an integer `z \u2260 0` is the multiplicity of `p` in `z`. -/\nlemma of_int_multiplicity (z : \u2124) (hp : p \u2260 1) (hz : z \u2260 0) :\n  padic_val_rat p (z : \u211a) = (multiplicity (p : \u2124) z).get\n    (finite_int_iff.2 \u27e8hp, hz\u27e9) :=\nby rw [of_int, padic_val_int.of_ne_one_ne_zero hp hz]\n\nlemma multiplicity_sub_multiplicity {q : \u211a} (hp : p \u2260 1) (hq : q \u2260 0) :\n  padic_val_rat p q =\n  (multiplicity (p : \u2124) q.num).get (finite_int_iff.2 \u27e8hp, rat.num_ne_zero_of_ne_zero hq\u27e9) -\n  (multiplicity p q.denom).get\n    (by { rw [\u2190finite_iff_dom, finite_nat_iff, and_iff_right hp], exact q.pos }) :=\nbegin\n  rw [padic_val_rat, padic_val_int.of_ne_one_ne_zero hp, padic_val_nat, dif_pos],\n  { refl },\n  { exact \u27e8hp, q.pos\u27e9 },\n  { exact rat.num_ne_zero_of_ne_zero hq },\nend\n\n/-- The p-adic value of an integer `z \u2260 0` is its p-adic_value as a rational -/\n@[simp] lemma of_nat {n : \u2115} : padic_val_rat p (n : \u211a) = padic_val_nat p n :=\nby simp [padic_val_rat, padic_val_int]\n\n/-- For `p \u2260 0, p \u2260 1, `padic_val_rat p p` is 1. -/\nlemma self (hp : 1 < p) : padic_val_rat p p = 1 := by simp [of_nat, hp]\n\nend padic_val_rat\n\nsection padic_val_nat\n\nlemma zero_le_padic_val_rat_of_nat (p n : \u2115) : 0 \u2264 padic_val_rat p n := by simp\n\n-- /-- `padic_val_rat` coincides with `padic_val_nat`. -/\n@[norm_cast] lemma padic_val_rat_of_nat (p n : \u2115) :\n  \u2191(padic_val_nat p n) = padic_val_rat p n :=\nby simp [padic_val_rat, padic_val_int]\n\n/--\nA simplification of `padic_val_nat` when one input is prime, by analogy with `padic_val_rat_def`.\n-/\nlemma padic_val_nat_def {p : \u2115} [hp : fact p.prime] {n : \u2115} (hn : 0 < n) :\n  padic_val_nat p n =\n  (multiplicity p n).get\n    (multiplicity.finite_nat_iff.2 \u27e8nat.prime.ne_one hp.1, hn\u27e9) :=\nbegin\n  simp [padic_val_nat],\n  split_ifs,\n  { refl, },\n  { exfalso,\n    apply h \u27e8(hp.out).ne_one, hn\u27e9, }\nend\n\nlemma padic_val_nat_def' {n p : \u2115} (hp : p \u2260 1) (hn : 0 < n) :\n  \u2191(padic_val_nat p n) = multiplicity p n :=\nby simp [padic_val_nat, hp, hn]\n\n@[simp] lemma padic_val_nat_self (p : \u2115) [fact p.prime] : padic_val_nat p p = 1 :=\nby simp [padic_val_nat_def (fact.out p.prime).pos]\n\nlemma one_le_padic_val_nat_of_dvd\n  {n p : nat} [prime : fact p.prime] (n_pos : 0 < n) (div : p \u2223 n) :\n  1 \u2264 padic_val_nat p n :=\nbegin\n  rw @padic_val_nat_def _ prime _ n_pos,\n  let one_le_mul : _ \u2264 multiplicity p n :=\n    @multiplicity.le_multiplicity_of_pow_dvd _ _ _ p n 1 (begin norm_num, exact div end),\n  simp only [nat.cast_one] at one_le_mul,\n  rcases one_le_mul with \u27e8_, q\u27e9,\n  dsimp at q,\n  solve_by_elim,\nend\n\nend padic_val_nat\n\nnamespace padic_val_rat\nopen multiplicity\nvariables (p : \u2115) [p_prime : fact p.prime]\ninclude p_prime\n\n/-- The multiplicity of `p : \u2115` in `a : \u2124` is finite exactly when `a \u2260 0`. -/\nlemma finite_int_prime_iff {p : \u2115} [p_prime : fact p.prime] {a : \u2124} : finite (p : \u2124) a \u2194 a \u2260 0 :=\nby simp [finite_int_iff, ne.symm (ne_of_lt (p_prime.1.one_lt))]\n\n/-- A rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`. -/\nprotected lemma defn {q : \u211a} {n d : \u2124} (hqz : q \u2260 0) (qdf : q = n /. d) :\n  padic_val_rat p q = (multiplicity (p : \u2124) n).get (finite_int_iff.2\n    \u27e8ne.symm $ ne_of_lt p_prime.1.one_lt, \u03bb hn, by simp * at *\u27e9) -\n  (multiplicity (p : \u2124) d).get (finite_int_iff.2 \u27e8ne.symm $ ne_of_lt p_prime.1.one_lt,\n    \u03bb hd, by simp * at *\u27e9) :=\nhave hd : d \u2260 0, from rat.mk_denom_ne_zero_of_ne_zero hqz qdf,\nlet \u27e8c, hc1, hc2\u27e9 := rat.num_denom_mk hd qdf in\nbegin\n  rw [padic_val_rat.multiplicity_sub_multiplicity];\n  simp [hc1, hc2, multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1),\n    (ne.symm (ne_of_lt p_prime.1.one_lt)), hqz, pos_iff_ne_zero],\n  simp_rw [int.coe_nat_multiplicity p q.denom],\nend\n\n/-- A rewrite lemma for `padic_val_rat p (q * r)` with conditions `q \u2260 0`, `r \u2260 0`. -/\nprotected lemma mul {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_rat p (q * r) = padic_val_rat p q + padic_val_rat p r :=\nhave q*r = (q.num * r.num) /. (\u2191q.denom * \u2191r.denom), by rw_mod_cast rat.mul_num_denom,\nhave hq' : q.num /. q.denom \u2260 0, by rw rat.num_denom; exact hq,\nhave hr' : r.num /. r.denom \u2260 0, by rw rat.num_denom; exact hr,\nhave hp' : _root_.prime (p : \u2124), from nat.prime_iff_prime_int.1 p_prime.1,\nbegin\n  rw [padic_val_rat.defn p (mul_ne_zero hq hr) this],\n  conv_rhs { rw [\u2190(@rat.num_denom q), padic_val_rat.defn p hq',\n    \u2190(@rat.num_denom r), padic_val_rat.defn p hr'] },\n  rw [multiplicity.mul' hp', multiplicity.mul' hp']; simp [add_comm, add_left_comm, sub_eq_add_neg]\nend\n\n/-- A rewrite lemma for `padic_val_rat p (q^k)` with condition `q \u2260 0`. -/\nprotected lemma pow {q : \u211a} (hq : q \u2260 0) {k : \u2115} :\n    padic_val_rat p (q ^ k) = k * padic_val_rat p q :=\nby induction k; simp [*, padic_val_rat.mul _ hq (pow_ne_zero _ hq),\n  pow_succ, add_mul, add_comm]\n\n/--\nA rewrite lemma for `padic_val_rat p (q\u207b\u00b9)` with condition `q \u2260 0`.\n-/\nprotected lemma inv (q : \u211a) :\n  padic_val_rat p (q\u207b\u00b9) = -padic_val_rat p q :=\nbegin\n  by_cases hq : q = 0,\n  { simp [hq], },\n  { rw [eq_neg_iff_add_eq_zero, \u2190 padic_val_rat.mul p (inv_ne_zero hq) hq,\n      inv_mul_cancel hq, padic_val_rat.one] },\nend\n\n/-- A rewrite lemma for `padic_val_rat p (q / r)` with conditions `q \u2260 0`, `r \u2260 0`. -/\nprotected lemma div {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_rat p (q / r) = padic_val_rat p q - padic_val_rat p r :=\nby rw [div_eq_mul_inv, padic_val_rat.mul p hq (inv_ne_zero hr),\n    padic_val_rat.inv p r, sub_eq_add_neg]\n\n/--\nA condition for `padic_val_rat p (n\u2081 / d\u2081) \u2264 padic_val_rat p (n\u2082 / d\u2082),\nin terms of divisibility by `p^n`.\n-/\nlemma padic_val_rat_le_padic_val_rat_iff {n\u2081 n\u2082 d\u2081 d\u2082 : \u2124}\n  (hn\u2081 : n\u2081 \u2260 0) (hn\u2082 : n\u2082 \u2260 0) (hd\u2081 : d\u2081 \u2260 0) (hd\u2082 : d\u2082 \u2260 0) :\n  padic_val_rat p (n\u2081 /. d\u2081) \u2264 padic_val_rat p (n\u2082 /. d\u2082) \u2194\n  \u2200 (n : \u2115), \u2191p ^ n \u2223 n\u2081 * d\u2082 \u2192 \u2191p ^ n \u2223 n\u2082 * d\u2081 :=\nhave hf1 : finite (p : \u2124) (n\u2081 * d\u2082),\n  from finite_int_prime_iff.2 (mul_ne_zero hn\u2081 hd\u2082),\nhave hf2 : finite (p : \u2124) (n\u2082 * d\u2081),\n  from finite_int_prime_iff.2 (mul_ne_zero hn\u2082 hd\u2081),\n  by conv\n  { to_lhs,\n    rw [padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn\u2081 hd\u2081) rfl,\n      padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn\u2082 hd\u2082) rfl,\n      sub_le_iff_le_add',\n      \u2190 add_sub_assoc,\n      le_sub_iff_add_le],\n    norm_cast,\n    rw [\u2190 multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf1, add_comm,\n      \u2190 multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf2,\n      enat.get_le_get, multiplicity_le_multiplicity_iff] }\n\n/--\nSufficient conditions to show that the p-adic valuation of `q` is less than or equal to the\np-adic vlauation of `q + r`.\n-/\ntheorem le_padic_val_rat_add_of_le {q r : \u211a}\n  (hqr : q + r \u2260 0)\n  (h : padic_val_rat p q \u2264 padic_val_rat p r) :\n  padic_val_rat p q \u2264 padic_val_rat p (q + r) :=\nif hq : q = 0 then by simpa [hq] using h else\nif hr : r = 0 then by simp [hr] else\nhave hqn : q.num \u2260 0, from rat.num_ne_zero_of_ne_zero hq,\nhave hqd : (q.denom : \u2124) \u2260 0, by exact_mod_cast rat.denom_ne_zero _,\nhave hrn : r.num \u2260 0, from rat.num_ne_zero_of_ne_zero hr,\nhave hrd : (r.denom : \u2124) \u2260 0, by exact_mod_cast rat.denom_ne_zero _,\nhave hqreq : q + r = (((q.num * r.denom + q.denom * r.num : \u2124)) /. (\u2191q.denom * \u2191r.denom : \u2124)),\n  from rat.add_num_denom _ _,\nhave hqrd : q.num * \u2191(r.denom) + \u2191(q.denom) * r.num \u2260 0,\n  from rat.mk_num_ne_zero_of_ne_zero hqr hqreq,\nbegin\n  conv_lhs { rw \u2190(@rat.num_denom q) },\n  rw [hqreq, padic_val_rat_le_padic_val_rat_iff p hqn hqrd hqd (mul_ne_zero hqd hrd),\n    \u2190 multiplicity_le_multiplicity_iff, mul_left_comm,\n    multiplicity.mul (nat.prime_iff_prime_int.1 p_prime.1), add_mul],\n  rw [\u2190(@rat.num_denom q), \u2190(@rat.num_denom r),\n    padic_val_rat_le_padic_val_rat_iff p hqn hrn hqd hrd, \u2190 multiplicity_le_multiplicity_iff] at h,\n  calc _ \u2264 min (multiplicity \u2191p (q.num * \u2191(r.denom) * \u2191(q.denom)))\n    (multiplicity \u2191p (\u2191(q.denom) * r.num * \u2191(q.denom))) : (le_min\n    (by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (nat.prime_iff_prime_int.1 p_prime.1), add_comm])\n    (by rw [mul_assoc, @multiplicity.mul _ _ _ _ (q.denom : \u2124)\n        (_ * _) (nat.prime_iff_prime_int.1 p_prime.1)];\n      exact add_le_add_left h _))\n    ... \u2264 _ : min_le_multiplicity_add\nend\n\n/--\nThe minimum of the valuations of `q` and `r` is less than or equal to the valuation of `q + r`.\n-/\ntheorem min_le_padic_val_rat_add {q r : \u211a} (hqr : q + r \u2260 0) :\n  min (padic_val_rat p q) (padic_val_rat p r) \u2264 padic_val_rat p (q + r) :=\n(le_total (padic_val_rat p q) (padic_val_rat p r)).elim\n  (\u03bb h, by rw [min_eq_left h]; exact le_padic_val_rat_add_of_le _ hqr h)\n  (\u03bb h, by rw [min_eq_right h, add_comm]; exact le_padic_val_rat_add_of_le _\n    (by rwa add_comm) h)\n\nopen_locale big_operators\n\n/-- A finite sum of rationals with positive p-adic valuation has positive p-adic valuation\n  (if the sum is non-zero). -/\ntheorem sum_pos_of_pos {n : \u2115} {F : \u2115 \u2192 \u211a}\n  (hF : \u2200 i, i < n \u2192 0 < padic_val_rat p (F i)) (hn0 : \u2211 i in finset.range n, F i \u2260 0) :\n  0 < padic_val_rat p (\u2211 i in finset.range n, F i) :=\nbegin\n  induction n with d hd,\n  { exact false.elim (hn0 rfl) },\n  { rw finset.sum_range_succ at hn0 \u22a2,\n    by_cases h : \u2211 (x : \u2115) in finset.range d, F x = 0,\n    { rw [h, zero_add],\n      exact hF d (lt_add_one _) },\n    { refine lt_of_lt_of_le _ (min_le_padic_val_rat_add p hn0),\n      { refine lt_min (hd (\u03bb i hi, _) h) (hF d (lt_add_one _)),\n        exact hF _ (lt_trans hi (lt_add_one _)) }, } }\nend\n\nend padic_val_rat\n\nnamespace padic_val_nat\n\n/-- A rewrite lemma for `padic_val_nat p (q * r)` with conditions `q \u2260 0`, `r \u2260 0`. -/\nprotected lemma mul (p : \u2115) [p_prime : fact p.prime] {q r : \u2115} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_nat p (q * r) = padic_val_nat p q + padic_val_nat p r :=\nbegin\n  apply int.coe_nat_inj,\n  simp only [padic_val_rat_of_nat, nat.cast_mul],\n  rw padic_val_rat.mul,\n  norm_cast,\n  exact cast_ne_zero.mpr hq,\n  exact cast_ne_zero.mpr hr,\nend\n\nprotected lemma div_of_dvd (p : \u2115) [hp : fact p.prime] {a b : \u2115} (h : b \u2223 a) :\n  padic_val_nat p (a / b) = padic_val_nat p a - padic_val_nat p b :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simp },\n  obtain \u27e8k, rfl\u27e9 := h,\n  obtain \u27e8hb, hk\u27e9 := mul_ne_zero_iff.mp ha,\n  rw [mul_comm, k.mul_div_cancel hb.bot_lt, padic_val_nat.mul p hk hb, nat.add_sub_cancel]\nend\n\n/-- Dividing out by a prime factor reduces the padic_val_nat by 1. -/\nprotected lemma div {p : \u2115} [p_prime : fact p.prime] {b : \u2115} (dvd : p \u2223 b) :\n  (padic_val_nat p (b / p)) = (padic_val_nat p b) - 1 :=\nbegin\n  convert padic_val_nat.div_of_dvd p dvd,\n  rw padic_val_nat_self p\nend\n\n/-- A version of `padic_val_rat.pow` for `padic_val_nat` -/\nprotected lemma pow (p q n : \u2115) [fact p.prime] (hq : q \u2260 0) :\n  padic_val_nat p (q ^ n) = n * padic_val_nat p q :=\nbegin\n  apply @nat.cast_injective \u2124,\n  push_cast,\n  exact padic_val_rat.pow _ (cast_ne_zero.mpr hq),\nend\n\n@[simp] protected lemma prime_pow (p n : \u2115) [fact p.prime] : padic_val_nat p (p ^ n) = n :=\nby rw [padic_val_nat.pow p _ _ (fact.out p.prime).ne_zero, padic_val_nat_self p, mul_one]\n\nprotected lemma div_pow {p : \u2115} [p_prime : fact p.prime] {b k : \u2115} (dvd : p ^ k \u2223 b) :\n  (padic_val_nat p (b / p ^ k)) = (padic_val_nat p b) - k :=\nbegin\n  convert padic_val_nat.div_of_dvd p dvd,\n  rw padic_val_nat.prime_pow\nend\n\nend padic_val_nat\n\nsection padic_val_nat\n\nlemma dvd_of_one_le_padic_val_nat {n p : nat} (hp : 1 \u2264 padic_val_nat p n) :\n  p \u2223 n :=\nbegin\n  by_contra h,\n  rw padic_val_nat.eq_zero_of_not_dvd h at hp,\n  exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp),\nend\n\nlemma pow_padic_val_nat_dvd {p n : \u2115} : p ^ (padic_val_nat p n) \u2223 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn, { simp },\n  rcases eq_or_ne p 1 with rfl | hp, { simp },\n  rw [multiplicity.pow_dvd_iff_le_multiplicity, padic_val_nat_def']; assumption,\nend\n\nlemma pow_succ_padic_val_nat_not_dvd {p n : \u2115} [hp : fact (nat.prime p)] (hn : 0 < n) :\n  \u00ac p ^ (padic_val_nat p n + 1) \u2223 n :=\nbegin\n  rw multiplicity.pow_dvd_iff_le_multiplicity,\n  rw padic_val_nat_def hn,\n  { rw [nat.cast_add, enat.coe_get],\n    simp only [nat.cast_one, not_le],\n    exact enat.lt_add_one (ne_top_iff_finite.mpr\n      (finite_nat_iff.mpr \u27e8(fact.elim hp).ne_one, hn\u27e9)), },\n  { apply_instance }\nend\n\nlemma padic_val_nat_dvd_iff (p : \u2115) [hp :fact p.prime] (n : \u2115) (a : \u2115) :\n  p^n \u2223 a \u2194 a = 0 \u2228 n \u2264 padic_val_nat p a :=\nbegin\n  split,\n  { rw [pow_dvd_iff_le_multiplicity, padic_val_nat],\n    split_ifs,\n    { rw enat.coe_le_iff,\n      exact \u03bb hn, or.inr (hn _) },\n    { simp only [true_and, not_lt, ne.def, not_false_iff, nat.le_zero_iff, hp.out.ne_one] at h,\n      exact \u03bb hn, or.inl h } },\n  { rintro (rfl|h),\n    { exact dvd_zero (p ^ n) },\n    { exact dvd_trans (pow_dvd_pow p h) pow_padic_val_nat_dvd } },\nend\n\nlemma padic_val_nat_primes {p q : \u2115} [p_prime : fact p.prime] [q_prime : fact q.prime]\n  (neq : p \u2260 q) : padic_val_nat p q = 0 :=\n@padic_val_nat.eq_zero_of_not_dvd p q $\n(not_congr (iff.symm (prime_dvd_prime_iff_eq p_prime.1 q_prime.1))).mp neq\n\nprotected lemma padic_val_nat.div' {p : \u2115} [p_prime : fact p.prime] :\n  \u2200 {m : \u2115} (cpm : coprime p m) {b : \u2115} (dvd : m \u2223 b), padic_val_nat p (b / m) = padic_val_nat p b\n| 0 := \u03bb cpm b dvd, by { rw zero_dvd_iff at dvd, rw [dvd, nat.zero_div], }\n| (n + 1) :=\n  \u03bb cpm b dvd,\n  begin\n    rcases dvd with \u27e8c, rfl\u27e9,\n    rw [mul_div_right c (nat.succ_pos _)],by_cases hc : c = 0,\n    { rw [hc, mul_zero] },\n    { rw padic_val_nat.mul,\n      { suffices : \u00ac p \u2223 (n+1),\n        { rw [padic_val_nat.eq_zero_of_not_dvd this, zero_add] },\n        contrapose! cpm,\n        exact p_prime.1.dvd_iff_not_coprime.mp cpm },\n      { exact nat.succ_ne_zero _ },\n      { exact hc } },\n  end\n\nlemma padic_val_nat_eq_factorization (p n : \u2115) [hp : fact p.prime] :\n  padic_val_nat p n = n.factorization p :=\nbegin\n  by_cases hn : n = 0, { subst hn, simp },\n  rw @padic_val_nat_def p _ n (nat.pos_of_ne_zero hn),\n  simp [@multiplicity_eq_factorization n p hp.elim hn],\nend\n\nopen_locale big_operators\n\nlemma prod_pow_prime_padic_val_nat (n : nat) (hn : n \u2260 0) (m : nat) (pr : n < m) :\n  \u220f p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n :=\nbegin\n  nth_rewrite_rhs 0 \u2190factorization_prod_pow_eq_self hn,\n  rw eq_comm,\n  apply finset.prod_subset_one_on_sdiff,\n  { exact \u03bb p hp, finset.mem_filter.mpr\n      \u27e8finset.mem_range.mpr (gt_of_gt_of_ge pr (le_of_mem_factorization hp)),\n       prime_of_mem_factorization hp\u27e9 },\n  { intros p hp,\n    cases finset.mem_sdiff.mp hp with hp1 hp2,\n    haveI := fact_iff.mpr (finset.mem_filter.mp hp1).2,\n    rw padic_val_nat_eq_factorization p n,\n    simp [finsupp.not_mem_support_iff.mp hp2] },\n  { intros p hp,\n    haveI := fact_iff.mpr (prime_of_mem_factorization hp),\n    simp [padic_val_nat_eq_factorization] }\nend\n\nlemma range_pow_padic_val_nat_subset_divisors {n : \u2115} (p : \u2115) (hn : n \u2260 0) :\n  (finset.range (padic_val_nat p n + 1)).image (pow p) \u2286 n.divisors :=\nbegin\n  intros t ht,\n  simp only [exists_prop, finset.mem_image, finset.mem_range] at ht,\n  obtain \u27e8k, hk, rfl\u27e9 := ht,\n  rw nat.mem_divisors,\n  exact \u27e8(pow_dvd_pow p $ by linarith).trans pow_padic_val_nat_dvd, hn\u27e9\nend\n\nlemma range_pow_padic_val_nat_subset_divisors' {n : \u2115} (p : \u2115) [h : fact p.prime] :\n  (finset.range (padic_val_nat p n)).image (\u03bb t, p ^ (t + 1)) \u2286 (n.divisors \\ {1}) :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  intros t ht,\n  simp only [exists_prop, finset.mem_image, finset.mem_range] at ht,\n  obtain \u27e8k, hk, rfl\u27e9 := ht,\n  rw [finset.mem_sdiff, nat.mem_divisors],\n  refine \u27e8\u27e8(pow_dvd_pow p $ by linarith).trans pow_padic_val_nat_dvd, hn\u27e9, _\u27e9,\n  rw [finset.mem_singleton],\n  nth_rewrite 1 \u2190one_pow (k + 1),\n  exact (nat.pow_lt_pow_of_lt_left h.1.one_lt $ nat.succ_pos k).ne',\nend\n\nend padic_val_nat\n\nsection padic_val_int\nvariables (p : \u2115) [p_prime : fact p.prime]\n\nlemma padic_val_int_dvd_iff (p : \u2115) [fact p.prime] (n : \u2115) (a : \u2124) :\n  \u2191p^n \u2223 a \u2194 a = 0 \u2228 n \u2264 padic_val_int p a :=\nby rw [padic_val_int, \u2190int.nat_abs_eq_zero, \u2190padic_val_nat_dvd_iff, \u2190int.coe_nat_dvd_left,\n       int.coe_nat_pow]\n\nlemma padic_val_int_dvd (p : \u2115) [fact p.prime] (a : \u2124) : \u2191p^(padic_val_int p a) \u2223 a :=\nbegin\n  rw padic_val_int_dvd_iff,\n  exact or.inr le_rfl,\nend\n\nlemma padic_val_int_self (p : \u2115) [pp : fact p.prime] : padic_val_int p p = 1 :=\npadic_val_int.self pp.out.one_lt\n\nlemma padic_val_int.mul (p : \u2115) [fact p.prime] {a b : \u2124} (ha : a \u2260 0) (hb : b \u2260 0) :\n  padic_val_int p (a*b) = padic_val_int p a + padic_val_int p b :=\nbegin\n  simp_rw padic_val_int,\n  rw [int.nat_abs_mul, padic_val_nat.mul];\n  rwa int.nat_abs_ne_zero,\nend\n\nlemma padic_val_int_mul_eq_succ (p : \u2115) [pp : fact p.prime] (a : \u2124) (ha : a \u2260 0) :\n  padic_val_int p (a * p) = (padic_val_int p a) + 1 :=\nbegin\n  rw padic_val_int.mul p ha (int.coe_nat_ne_zero.mpr (pp.out).ne_zero),\n  simp only [eq_self_iff_true, padic_val_int.of_nat, padic_val_nat_self],\nend\n\nend padic_val_int\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/number_theory/padics/padic_val.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7269485174440992}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov\n-/\nimport group_theory.quotient_group\nimport linear_algebra.span\n\n/-!\n# Quotients by submodules\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n* If `p` is a submodule of `M`, `M \u29f8 p` is the quotient of `M` with respect to `p`:\n  that is, elements of `M` are identified if their difference is in `p`. This is itself a module.\n\n-/\n\n-- For most of this file we work over a noncommutative ring\nsection ring\n\nnamespace submodule\n\nvariables {R M : Type*} {r : R} {x y : M} [ring R] [add_comm_group M] [module R M]\nvariables (p p' : submodule R M)\n\nopen linear_map quotient_add_group\n\n/-- The equivalence relation associated to a submodule `p`, defined by `x \u2248 y` iff `-x + y \u2208 p`.\n\nNote this is equivalent to `y - x \u2208 p`, but defined this way to be be defeq to the `add_subgroup`\nversion, where commutativity can't be assumed. -/\ndef quotient_rel : setoid M :=\nquotient_add_group.left_rel p.to_add_subgroup\n\nlemma quotient_rel_r_def {x y : M} : @setoid.r _ (p.quotient_rel) x y \u2194 x - y \u2208 p :=\niff.trans (by { rw [left_rel_apply, sub_eq_add_neg, neg_add, neg_neg], refl }) neg_mem_iff\n\n/-- The quotient of a module `M` by a submodule `p \u2286 M`. -/\ninstance has_quotient : has_quotient M (submodule R M) := \u27e8\u03bb p, quotient (quotient_rel p)\u27e9\n\nnamespace quotient\n\n/-- Map associating to an element of `M` the corresponding element of `M/p`,\nwhen `p` is a submodule of `M`. -/\ndef mk {p : submodule R M} : M \u2192 M \u29f8 p := quotient.mk'\n\n@[simp] theorem mk_eq_mk {p : submodule R M} (x : M) :\n  (@_root_.quotient.mk _ (quotient_rel p) x) = mk x := rfl\n@[simp] theorem mk'_eq_mk {p : submodule R M} (x : M) : (quotient.mk' x : M \u29f8 p) = mk x := rfl\n@[simp] theorem quot_mk_eq_mk {p : submodule R M} (x : M) : (quot.mk _ x : M \u29f8 p) = mk x := rfl\n\nprotected theorem eq' {x y : M} : (mk x : M \u29f8 p) = mk y \u2194 -x + y \u2208 p := quotient_add_group.eq\n\nprotected theorem eq {x y : M} : (mk x : M \u29f8 p) = mk y \u2194 x - y \u2208 p :=\n(p^.quotient.eq').trans (left_rel_apply.symm.trans p.quotient_rel_r_def)\n\ninstance : has_zero (M \u29f8 p) := \u27e8mk 0\u27e9\ninstance : inhabited (M \u29f8 p) := \u27e80\u27e9\n\n@[simp] theorem mk_zero : mk 0 = (0 : M \u29f8 p) := rfl\n\n@[simp] theorem mk_eq_zero : (mk x : M \u29f8 p) = 0 \u2194 x \u2208 p :=\nby simpa using (quotient.eq p : mk x = 0 \u2194 _)\n\ninstance add_comm_group : add_comm_group (M \u29f8 p) :=\nquotient_add_group.quotient.add_comm_group p.to_add_subgroup\n\n@[simp] theorem mk_add : (mk (x + y) : M \u29f8 p) = mk x + mk y := rfl\n\n@[simp] theorem mk_neg : (mk (-x) : M \u29f8 p) = -mk x := rfl\n\n@[simp] theorem mk_sub : (mk (x - y) : M \u29f8 p) = mk x - mk y := rfl\n\nsection has_smul\n\nvariables {S : Type*} [has_smul S R] [has_smul S M] [is_scalar_tower S R M] (P : submodule R M)\n\ninstance has_smul' : has_smul S (M \u29f8 P) :=\n\u27e8\u03bb a, quotient.map' ((\u2022) a) $ \u03bb x y h, left_rel_apply.mpr $\n  by simpa [smul_sub] using P.smul_mem (a \u2022 1 : R) (left_rel_apply.mp h)\u27e9\n\n/-- Shortcut to help the elaborator in the common case. -/\ninstance has_smul : has_smul R (M \u29f8 P) :=\nquotient.has_smul' P\n\n@[simp] theorem mk_smul (r : S) (x : M) : (mk (r \u2022 x) : M \u29f8 p) = r \u2022 mk x := rfl\n\ninstance smul_comm_class (T : Type*) [has_smul T R] [has_smul T M] [is_scalar_tower T R M]\n  [smul_comm_class S T M] : smul_comm_class S T (M \u29f8 P) :=\n{ smul_comm := \u03bb x y, quotient.ind' $ by exact \u03bb z, congr_arg mk (smul_comm _ _ _) }\n\ninstance is_scalar_tower (T : Type*) [has_smul T R] [has_smul T M] [is_scalar_tower T R M]\n  [has_smul S T] [is_scalar_tower S T M] : is_scalar_tower S T (M \u29f8 P) :=\n{ smul_assoc := \u03bb x y, quotient.ind' $ by exact \u03bb z, congr_arg mk (smul_assoc _ _ _) }\n\ninstance is_central_scalar [has_smul S\u1d50\u1d52\u1d56 R] [has_smul S\u1d50\u1d52\u1d56 M] [is_scalar_tower S\u1d50\u1d52\u1d56 R M]\n  [is_central_scalar S M] : is_central_scalar S (M \u29f8 P) :=\n{ op_smul_eq_smul := \u03bb x, quotient.ind' $ by exact \u03bb z, congr_arg mk $ op_smul_eq_smul _ _ }\n\nend has_smul\n\nsection module\n\nvariables {S : Type*}\n\ninstance mul_action' [monoid S] [has_smul S R] [mul_action S M] [is_scalar_tower S R M]\n  (P : submodule R M) : mul_action S (M \u29f8 P) :=\nfunction.surjective.mul_action mk (surjective_quot_mk _) P^.quotient.mk_smul\n\ninstance mul_action (P : submodule R M) : mul_action R (M \u29f8 P) :=\nquotient.mul_action' P\n\ninstance smul_zero_class' [has_smul S R] [smul_zero_class S M]\n  [is_scalar_tower S R M]\n  (P : submodule R M) : smul_zero_class S (M \u29f8 P) :=\nzero_hom.smul_zero_class \u27e8mk, mk_zero _\u27e9 P^.quotient.mk_smul\n\ninstance smul_zero_class (P : submodule R M) : smul_zero_class R (M \u29f8 P) :=\nquotient.smul_zero_class' P\n\ninstance distrib_smul' [has_smul S R] [distrib_smul S M]\n  [is_scalar_tower S R M]\n  (P : submodule R M) : distrib_smul S (M \u29f8 P) :=\nfunction.surjective.distrib_smul\n  \u27e8mk, rfl, \u03bb _ _, rfl\u27e9 (surjective_quot_mk _) P^.quotient.mk_smul\n\ninstance distrib_smul (P : submodule R M) : distrib_smul R (M \u29f8 P) :=\nquotient.distrib_smul' P\n\ninstance distrib_mul_action' [monoid S] [has_smul S R] [distrib_mul_action S M]\n  [is_scalar_tower S R M]\n  (P : submodule R M) : distrib_mul_action S (M \u29f8 P) :=\nfunction.surjective.distrib_mul_action\n  \u27e8mk, rfl, \u03bb _ _, rfl\u27e9 (surjective_quot_mk _) P^.quotient.mk_smul\n\ninstance distrib_mul_action (P : submodule R M) : distrib_mul_action R (M \u29f8 P) :=\nquotient.distrib_mul_action' P\n\ninstance module' [semiring S] [has_smul S R] [module S M] [is_scalar_tower S R M]\n  (P : submodule R M) : module S (M \u29f8 P) :=\nfunction.surjective.module _\n  \u27e8mk, rfl, \u03bb _ _, rfl\u27e9 (surjective_quot_mk _) P^.quotient.mk_smul\n\ninstance module (P : submodule R M) : module R (M \u29f8 P) :=\nquotient.module' P\n\nvariables (S)\n\n/-- The quotient of `P` as an `S`-submodule is the same as the quotient of `P` as an `R`-submodule,\nwhere `P : submodule R M`.\n-/\ndef restrict_scalars_equiv [ring S] [has_smul S R] [module S M] [is_scalar_tower S R M]\n  (P : submodule R M) :\n  (M \u29f8 P.restrict_scalars S) \u2243\u2097[S] M \u29f8 P :=\n{ map_add' := \u03bb x y, quotient.induction_on\u2082' x y (\u03bb x' y', rfl),\n  map_smul' := \u03bb c x, quotient.induction_on' x (\u03bb x', rfl),\n  ..quotient.congr_right $ \u03bb _ _, iff.rfl }\n\n@[simp] lemma restrict_scalars_equiv_mk\n  [ring S] [has_smul S R] [module S M] [is_scalar_tower S R M] (P : submodule R M)\n  (x : M) : restrict_scalars_equiv S P (mk x) = mk x :=\nrfl\n\n@[simp] lemma restrict_scalars_equiv_symm_mk\n  [ring S] [has_smul S R] [module S M] [is_scalar_tower S R M] (P : submodule R M)\n  (x : M) : (restrict_scalars_equiv S P).symm (mk x) = mk x :=\nrfl\n\n\nend module\n\nlemma mk_surjective : function.surjective (@mk _ _ _ _ _ p) :=\nby { rintros \u27e8x\u27e9, exact \u27e8x, rfl\u27e9 }\n\nlemma nontrivial_of_lt_top (h : p < \u22a4) : nontrivial (M \u29f8 p) :=\nbegin\n  obtain \u27e8x, _, not_mem_s\u27e9 := set_like.exists_of_lt h,\n  refine \u27e8\u27e8mk x, 0, _\u27e9\u27e9,\n  simpa using not_mem_s\nend\n\nend quotient\n\ninstance quotient_bot.infinite [infinite M] : infinite (M \u29f8 (\u22a5 : submodule R M)) :=\ninfinite.of_injective submodule.quotient.mk $ \u03bb x y h, sub_eq_zero.mp $\n  (submodule.quotient.eq \u22a5).mp h\n\ninstance quotient_top.unique : unique (M \u29f8 (\u22a4 : submodule R M)) :=\n{ default := 0,\n  uniq := \u03bb x, quotient.induction_on' x $ \u03bb x, (submodule.quotient.eq \u22a4).mpr submodule.mem_top }\n\ninstance quotient_top.fintype : fintype (M \u29f8 (\u22a4 : submodule R M)) :=\nfintype.of_subsingleton 0\n\nvariables {p}\n\nlemma subsingleton_quotient_iff_eq_top : subsingleton (M \u29f8 p) \u2194 p = \u22a4 :=\nbegin\n  split,\n  { rintro h,\n    refine eq_top_iff.mpr (\u03bb x _, _),\n    have this : x - 0 \u2208 p := (submodule.quotient.eq p).mp (by exactI subsingleton.elim _ _),\n    rwa sub_zero at this },\n  { rintro rfl,\n    apply_instance }\nend\n\nlemma unique_quotient_iff_eq_top : nonempty (unique (M \u29f8 p)) \u2194 p = \u22a4 :=\n\u27e8\u03bb \u27e8h\u27e9, subsingleton_quotient_iff_eq_top.mp (@@unique.subsingleton h),\n by { rintro rfl, exact \u27e8quotient_top.unique\u27e9 }\u27e9\n\nvariables (p)\n\nnoncomputable instance quotient.fintype [fintype M] (S : submodule R M) :\n  fintype (M \u29f8 S) :=\n@@quotient.fintype _ _ (\u03bb _ _, classical.dec _)\n\nlemma card_eq_card_quotient_mul_card [fintype M] (S : submodule R M) [decidable_pred (\u2208 S)]  :\n  fintype.card M = fintype.card S * fintype.card (M \u29f8 S) :=\nby { rw [mul_comm, \u2190 fintype.card_prod],\n     exact fintype.card_congr add_subgroup.add_group_equiv_quotient_times_add_subgroup }\n\nsection\n\nvariables {M\u2082 : Type*} [add_comm_group M\u2082] [module R M\u2082]\n\nlemma quot_hom_ext \u2983f g : M \u29f8 p \u2192\u2097[R] M\u2082\u2984 (h : \u2200 x, f (quotient.mk x) = g (quotient.mk x)) :\n  f = g :=\nlinear_map.ext $ \u03bb x, quotient.induction_on' x h\n\n/-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/\ndef mkq : M \u2192\u2097[R] M \u29f8 p :=\n{ to_fun := quotient.mk, map_add' := by simp, map_smul' := by simp }\n\n@[simp] theorem mkq_apply (x : M) : p.mkq x = quotient.mk x := rfl\n\nlemma mkq_surjective (A : submodule R M) : function.surjective A.mkq :=\nby rintro \u27e8x\u27e9; exact \u27e8x, rfl\u27e9\n\nend\n\nvariables {R\u2082 M\u2082 : Type*} [ring R\u2082] [add_comm_group M\u2082] [module R\u2082 M\u2082] {\u03c4\u2081\u2082 : R \u2192+* R\u2082}\n\n/-- Two `linear_map`s from a quotient module are equal if their compositions with\n`submodule.mkq` are equal.\n\nSee note [partially-applied ext lemmas]. -/\n@[ext]\nlemma linear_map_qext \u2983f g : M \u29f8 p \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082\u2984 (h : f.comp p.mkq = g.comp p.mkq) : f = g :=\nlinear_map.ext $ \u03bb x, quotient.induction_on' x $ (linear_map.congr_fun h : _)\n\n/-- The map from the quotient of `M` by a submodule `p` to `M\u2082` induced by a linear map `f : M \u2192 M\u2082`\nvanishing on `p`, as a linear map. -/\ndef liftq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : p \u2264 f.ker) : M \u29f8 p \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082 :=\n{ map_smul' := by rintro a \u27e8x\u27e9; exact f.map_smul\u209b\u2097 a x,\n  ..quotient_add_group.lift p.to_add_subgroup f.to_add_monoid_hom h }\n\n@[simp] theorem liftq_apply (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) {h} (x : M) :\n  p.liftq f h (quotient.mk x) = f x := rfl\n\n@[simp] theorem liftq_mkq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) : (p.liftq f h).comp p.mkq = f :=\nby ext; refl\n\n/--Special case of `liftq` when `p` is the span of `x`. In this case, the condition on `f` simply\nbecomes vanishing at `x`.-/\ndef liftq_span_singleton (x : M) (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : f x = 0) : (M \u29f8 R \u2219 x) \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082 :=\n(R \u2219 x).liftq f $ by rw [span_singleton_le_iff_mem, linear_map.mem_ker, h]\n\n@[simp] lemma liftq_span_singleton_apply (x : M) (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : f x = 0) (y : M) :\nliftq_span_singleton x f h (quotient.mk y) = f y := rfl\n\n@[simp] theorem range_mkq : p.mkq.range = \u22a4 :=\neq_top_iff'.2 $ by rintro \u27e8x\u27e9; exact \u27e8x, rfl\u27e9\n\n@[simp] theorem ker_mkq : p.mkq.ker = p :=\nby ext; simp\n\nlemma le_comap_mkq (p' : submodule R (M \u29f8 p)) : p \u2264 comap p.mkq p' :=\nby simpa using (comap_mono bot_le : p.mkq.ker \u2264 comap p.mkq p')\n\n@[simp] theorem mkq_map_self : map p.mkq p = \u22a5 :=\nby rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkq]; exact le_rfl\n\n@[simp] theorem comap_map_mkq : comap p.mkq (map p.mkq p') = p \u2294 p' :=\nby simp [comap_map_eq, sup_comm]\n\n@[simp] theorem map_mkq_eq_top : map p.mkq p' = \u22a4 \u2194 p \u2294 p' = \u22a4 :=\nby simp only [map_eq_top_iff p.range_mkq, sup_comm, ker_mkq]\n\nvariables (q : submodule R\u2082 M\u2082)\n\n/-- The map from the quotient of `M` by submodule `p` to the quotient of `M\u2082` by submodule `q` along\n`f : M \u2192 M\u2082` is linear. -/\ndef mapq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : p \u2264 comap f q) :\n  (M \u29f8 p) \u2192\u209b\u2097[\u03c4\u2081\u2082] (M\u2082 \u29f8 q) :=\np.liftq (q.mkq.comp f) $ by simpa [ker_comp] using h\n\n@[simp] theorem mapq_apply (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) {h} (x : M) :\n  mapq p q f h (quotient.mk x) = quotient.mk (f x) := rfl\n\ntheorem mapq_mkq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) {h} : (mapq p q f h).comp p.mkq = q.mkq.comp f :=\nby ext x; refl\n\n@[simp] lemma mapq_zero (h : p \u2264 q.comap (0 : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) := by simp) :\n  p.mapq q (0 : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) h = 0 :=\nby { ext, simp, }\n\n/-- Given submodules `p \u2286 M`, `p\u2082 \u2286 M\u2082`, `p\u2083 \u2286 M\u2083` and maps `f : M \u2192 M\u2082`, `g : M\u2082 \u2192 M\u2083` inducing\n`mapq f : M \u29f8 p \u2192 M\u2082 \u29f8 p\u2082` and `mapq g : M\u2082 \u29f8 p\u2082 \u2192 M\u2083 \u29f8 p\u2083` then\n`mapq (g \u2218 f) = (mapq g) \u2218 (mapq f)`. -/\nlemma mapq_comp {R\u2083 M\u2083 : Type*} [ring R\u2083] [add_comm_group M\u2083] [module R\u2083 M\u2083]\n  (p\u2082 : submodule R\u2082 M\u2082) (p\u2083 : submodule R\u2083 M\u2083)\n  {\u03c4\u2082\u2083 : R\u2082 \u2192+* R\u2083} {\u03c4\u2081\u2083 : R \u2192+* R\u2083} [ring_hom_comp_triple \u03c4\u2081\u2082 \u03c4\u2082\u2083 \u03c4\u2081\u2083]\n  (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (g : M\u2082 \u2192\u209b\u2097[\u03c4\u2082\u2083] M\u2083) (hf : p \u2264 p\u2082.comap f) (hg : p\u2082 \u2264 p\u2083.comap g)\n  (h := (hf.trans (comap_mono hg))) :\n  p.mapq p\u2083 (g.comp f) h = (p\u2082.mapq p\u2083 g hg).comp (p.mapq p\u2082 f hf) :=\nby { ext, simp, }\n\n@[simp] lemma mapq_id (h : p \u2264 p.comap linear_map.id := by { rw comap_id, exact le_refl _ }) :\n  p.mapq p linear_map.id h = linear_map.id :=\nby { ext, simp, }\n\nlemma mapq_pow {f : M \u2192\u2097[R] M} (h : p \u2264 p.comap f) (k : \u2115)\n  (h' : p \u2264 p.comap (f^k) := p.le_comap_pow_of_le_comap h k) :\n  p.mapq p (f^k) h' = (p.mapq p f h)^k :=\nbegin\n  induction k with k ih,\n  { simp [linear_map.one_eq_id], },\n  { simp only [linear_map.iterate_succ, \u2190 ih],\n    apply p.mapq_comp, },\nend\n\ntheorem comap_liftq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) :\n  q.comap (p.liftq f h) = (q.comap f).map (mkq p) :=\nle_antisymm\n  (by rintro \u27e8x\u27e9 hx; exact \u27e8_, hx, rfl\u27e9)\n  (by rw [map_le_iff_le_comap, \u2190 comap_comp, liftq_mkq]; exact le_rfl)\n\ntheorem map_liftq [ring_hom_surjective \u03c4\u2081\u2082] (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) (q : submodule R (M \u29f8 p)) :\n  q.map (p.liftq f h) = (q.comap p.mkq).map f :=\nle_antisymm\n  (by rintro _ \u27e8\u27e8x\u27e9, hxq, rfl\u27e9; exact \u27e8x, hxq, rfl\u27e9)\n  (by rintro _ \u27e8x, hxq, rfl\u27e9; exact \u27e8quotient.mk x, hxq, rfl\u27e9)\n\ntheorem ker_liftq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) :\n  ker (p.liftq f h) = (ker f).map (mkq p) := comap_liftq _ _ _ _\n\ntheorem range_liftq [ring_hom_surjective \u03c4\u2081\u2082] (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) :\n  range (p.liftq f h) = range f :=\nby simpa only [range_eq_map] using map_liftq _ _ _ _\n\ntheorem ker_liftq_eq_bot (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) (h' : ker f \u2264 p) : ker (p.liftq f h) = \u22a5 :=\nby rw [ker_liftq, le_antisymm h h', mkq_map_self]\n\n/-- The correspondence theorem for modules: there is an order isomorphism between submodules of the\nquotient of `M` by `p`, and submodules of `M` larger than `p`. -/\ndef comap_mkq.rel_iso :\n  submodule R (M \u29f8 p) \u2243o {p' : submodule R M // p \u2264 p'} :=\n{ to_fun    := \u03bb p', \u27e8comap p.mkq p', le_comap_mkq p _\u27e9,\n  inv_fun   := \u03bb q, map p.mkq q,\n  left_inv  := \u03bb p', map_comap_eq_self $ by simp,\n  right_inv := \u03bb \u27e8q, hq\u27e9, subtype.ext_val $ by simpa [comap_map_mkq p],\n  map_rel_iff'      := \u03bb p\u2081 p\u2082, comap_le_comap_iff $ range_mkq _ }\n\n/-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules\nof `M`. -/\ndef comap_mkq.order_embedding :\n  submodule R (M \u29f8 p) \u21aao submodule R M :=\n(rel_iso.to_rel_embedding $ comap_mkq.rel_iso p).trans (subtype.rel_embedding _ _)\n\n@[simp] lemma comap_mkq_embedding_eq (p' : submodule R (M \u29f8 p)) :\n  comap_mkq.order_embedding p p' = comap p.mkq p' := rfl\n\nlemma span_preimage_eq [ring_hom_surjective \u03c4\u2081\u2082] {f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082} {s : set M\u2082} (h\u2080 : s.nonempty)\n  (h\u2081 : s \u2286 range f) :\n  span R (f \u207b\u00b9' s) = (span R\u2082 s).comap f :=\nbegin\n  suffices : (span R\u2082 s).comap f \u2264 span R (f \u207b\u00b9' s),\n  { exact le_antisymm (span_preimage_le f s) this, },\n  have hk : ker f \u2264 span R (f \u207b\u00b9' s),\n  { let y := classical.some h\u2080, have hy : y \u2208 s, { exact classical.some_spec h\u2080, },\n    rw ker_le_iff, use [y, h\u2081 hy], rw \u2190 set.singleton_subset_iff at hy,\n    exact set.subset.trans subset_span (span_mono (set.preimage_mono hy)), },\n  rw \u2190 left_eq_sup at hk, rw f.range_coe at h\u2081,\n  rw [hk, \u2190linear_map.map_le_map_iff, map_span, map_comap_eq, set.image_preimage_eq_of_subset h\u2081],\n  exact inf_le_right,\nend\n\n/-- If `P` is a submodule of `M` and `Q` a submodule of `N`,\nand `f : M \u2243\u2097 N` maps `P` to `Q`, then `M \u29f8 P` is equivalent to `N \u29f8 Q`. -/\n@[simps] def quotient.equiv {N : Type*} [add_comm_group N] [module R N]\n  (P : submodule R M) (Q : submodule R N)\n  (f : M \u2243\u2097[R] N) (hf : P.map f = Q) : (M \u29f8 P) \u2243\u2097[R] N \u29f8 Q :=\n{ to_fun := P.mapq Q (f : M \u2192\u2097[R] N) (\u03bb x hx, hf \u25b8 submodule.mem_map_of_mem hx),\n  inv_fun := Q.mapq P (f.symm : N \u2192\u2097[R] M) (\u03bb x hx, begin\n    rw [\u2190 hf, submodule.mem_map] at hx,\n    obtain \u27e8y, hy, rfl\u27e9 := hx,\n    simpa\n  end),\n  left_inv := \u03bb x, quotient.induction_on' x (by simp),\n  right_inv := \u03bb x, quotient.induction_on' x (by simp),\n  .. P.mapq Q (f : M \u2192\u2097[R] N) (\u03bb x hx, hf \u25b8 submodule.mem_map_of_mem hx) }\n\n@[simp] \n\n@[simp] lemma quotient.equiv_trans {N O : Type*} [add_comm_group N] [module R N]\n  [add_comm_group O] [module R O]\n  (P : submodule R M) (Q : submodule R N) (S : submodule R O)\n  (e : M \u2243\u2097[R] N) (f : N \u2243\u2097[R] O)\n  (he : P.map e = Q) (hf : Q.map f = S) (hef : P.map (e.trans f) = S) :\n  quotient.equiv P S (e.trans f) hef = (quotient.equiv P Q e he).trans (quotient.equiv Q S f hf) :=\nbegin\n  ext,\n  -- `simp` can deal with `hef` depending on `e` and `f`\n  simp only [quotient.equiv_apply, linear_equiv.trans_apply, linear_equiv.coe_trans],\n  -- `rw` can deal with `mapq_comp` needing extra hypotheses coming from the RHS\n  rw [mapq_comp, linear_map.comp_apply]\nend\n\nend submodule\n\nopen submodule\n\nnamespace linear_map\n\nsection ring\n\nvariables {R M R\u2082 M\u2082 R\u2083 M\u2083 : Type*}\nvariables [ring R] [ring R\u2082] [ring R\u2083]\nvariables [add_comm_monoid M] [add_comm_group M\u2082] [add_comm_monoid M\u2083]\nvariables [module R M] [module R\u2082 M\u2082] [module R\u2083 M\u2083]\nvariables {\u03c4\u2081\u2082 : R \u2192+* R\u2082} {\u03c4\u2082\u2083 : R\u2082 \u2192+* R\u2083} {\u03c4\u2081\u2083 : R \u2192+* R\u2083}\nvariables [ring_hom_comp_triple \u03c4\u2081\u2082 \u03c4\u2082\u2083 \u03c4\u2081\u2083] [ring_hom_surjective \u03c4\u2081\u2082]\n\nlemma range_mkq_comp (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) : f.range.mkq.comp f = 0 :=\nlinear_map.ext $ \u03bb x, by simp\n\nlemma ker_le_range_iff {f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082} {g : M\u2082 \u2192\u209b\u2097[\u03c4\u2082\u2083] M\u2083} :\n  g.ker \u2264 f.range \u2194 f.range.mkq.comp g.ker.subtype = 0 :=\nby rw [\u2190range_le_ker_iff, submodule.ker_mkq, submodule.range_subtype]\n\n/-- An epimorphism is surjective. -/\nlemma range_eq_top_of_cancel {f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082}\n  (h : \u2200 (u v : M\u2082 \u2192\u2097[R\u2082] M\u2082 \u29f8 f.range), u.comp f = v.comp f \u2192 u = v) : f.range = \u22a4 :=\nbegin\n  have h\u2081 : (0 : M\u2082 \u2192\u2097[R\u2082] M\u2082 \u29f8 f.range).comp f = 0 := zero_comp _,\n  rw [\u2190submodule.ker_mkq f.range, \u2190h 0 f.range.mkq (eq.trans h\u2081 (range_mkq_comp _).symm)],\n  exact ker_zero\nend\n\nend ring\n\nend linear_map\n\nopen linear_map\n\nnamespace submodule\n\nvariables {R M : Type*} {r : R} {x y : M} [ring R] [add_comm_group M] [module R M]\nvariables (p p' : submodule R M)\n\n/-- If `p = \u22a5`, then `M / p \u2243\u2097[R] M`. -/\ndef quot_equiv_of_eq_bot (hp : p = \u22a5) : (M \u29f8 p) \u2243\u2097[R] M :=\nlinear_equiv.of_linear (p.liftq id $ hp.symm \u25b8 bot_le) p.mkq (liftq_mkq _ _ _) $\n  p.quot_hom_ext $ \u03bb x, rfl\n\n@[simp] lemma quot_equiv_of_eq_bot_apply_mk (hp : p = \u22a5) (x : M) :\n  p.quot_equiv_of_eq_bot hp (quotient.mk x) = x := rfl\n\n@[simp] lemma quot_equiv_of_eq_bot_symm_apply (hp : p = \u22a5) (x : M) :\n  (p.quot_equiv_of_eq_bot hp).symm x = quotient.mk x := rfl\n\n@[simp] lemma coe_quot_equiv_of_eq_bot_symm (hp : p = \u22a5) :\n  ((p.quot_equiv_of_eq_bot hp).symm : M \u2192\u2097[R] M \u29f8 p) = p.mkq := rfl\n\n/-- Quotienting by equal submodules gives linearly equivalent quotients. -/\ndef quot_equiv_of_eq (h : p = p') : (M \u29f8 p) \u2243\u2097[R] M \u29f8 p' :=\n{ map_add' := by { rintros \u27e8x\u27e9 \u27e8y\u27e9, refl }, map_smul' := by { rintros x \u27e8y\u27e9, refl },\n  ..@quotient.congr _ _ (quotient_rel p) (quotient_rel p') (equiv.refl _) $\n    \u03bb a b, by { subst h, refl } }\n\n@[simp]\nlemma quot_equiv_of_eq_mk (h : p = p') (x : M) :\n  submodule.quot_equiv_of_eq p p' h (submodule.quotient.mk x) = submodule.quotient.mk x :=\nrfl\n\n@[simp] lemma quotient.equiv_refl (P : submodule R M) (Q : submodule R M)\n  (hf : P.map (linear_equiv.refl R M : M \u2192\u2097[R] M) = Q) :\n  quotient.equiv P Q (linear_equiv.refl R M) hf = quot_equiv_of_eq _ _ (by simpa using hf) :=\nrfl\n\nend submodule\n\nend ring\n\nsection comm_ring\n\nvariables {R M M\u2082 : Type*} {r : R} {x y : M} [comm_ring R]\n  [add_comm_group M] [module R M] [add_comm_group M\u2082] [module R M\u2082]\n  (p : submodule R M) (q : submodule R M\u2082)\n\nnamespace submodule\n\n/-- Given modules `M`, `M\u2082` over a commutative ring, together with submodules `p \u2286 M`, `q \u2286 M\u2082`,\nthe natural map $\\{f \u2208 Hom(M, M\u2082) | f(p) \u2286 q \\} \\to Hom(M/p, M\u2082/q)$ is linear. -/\ndef mapq_linear : compatible_maps p q \u2192\u2097[R] (M \u29f8 p) \u2192\u2097[R] (M\u2082 \u29f8 q) :=\n{ to_fun    := \u03bb f, mapq _ _ f.val f.property,\n  map_add'  := \u03bb x y, by { ext, refl, },\n  map_smul' := \u03bb c f, by { ext, refl, } }\n\nend submodule\n\nend comm_ring\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7269485128730453}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n\nSeparation properties of topological spaces.\n-/\nimport topology.subset_properties\nimport topology.connected\n\nopen set filter\nopen_locale topological_space filter\nlocal attribute [instance] classical.prop_decidable -- TODO: use \"open_locale classical\"\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n\nsection separation\n\n/--\n`separated` is a predicate on pairs of sub`set`s of a topological space.  It holds if the two\nsub`set`s are contained in disjoint open sets.\n-/\ndef separated : set \u03b1 \u2192 set \u03b1 \u2192 Prop :=\n  \u03bb (s t : set \u03b1), \u2203 U V : (set \u03b1), (is_open U) \u2227 is_open V \u2227\n  (s \u2286 U) \u2227 (t \u2286 V) \u2227 disjoint U V\n\nnamespace separated\n\nopen separated\n\n@[symm] lemma symm {s t : set \u03b1} : separated s t \u2192 separated t s :=\n\u03bb \u27e8U, V, oU, oV, aU, bV, UV\u27e9, \u27e8V, U, oV, oU, bV, aU, disjoint.symm UV\u27e9\n\nlemma comm (s t : set \u03b1) : separated s t \u2194 separated t s :=\n\u27e8symm, symm\u27e9\n\nlemma empty_right (a : set \u03b1) : separated a \u2205 :=\n\u27e8_, _, is_open_univ, is_open_empty, \u03bb a h, mem_univ a, \u03bb a h, by cases h, disjoint_empty _\u27e9\n\nlemma empty_left (a : set \u03b1) : separated \u2205 a :=\n(empty_right _).symm\n\nlemma union_left {a b c : set \u03b1} : separated a c \u2192 separated b c \u2192 separated (a \u222a b) c :=\n\u03bb \u27e8U, V, oU, oV, aU, bV, UV\u27e9 \u27e8W, X, oW, oX, aW, bX, WX\u27e9,\n  \u27e8U \u222a W, V \u2229 X, is_open_union oU oW, is_open_inter oV oX,\n    union_subset_union aU aW, subset_inter bV bX, set.disjoint_union_left.mpr\n    \u27e8disjoint_of_subset_right (inter_subset_left _ _) UV,\n      disjoint_of_subset_right (inter_subset_right _ _) WX\u27e9\u27e9\n\nlemma union_right {a b c : set \u03b1} (ab : separated a b) (ac : separated a c) :\n  separated a (b \u222a c) :=\n(ab.symm.union_left ac.symm).symm\n\nend separated\n\n/-- A T\u2080 space, also known as a Kolmogorov space, is a topological space\n  where for every pair `x \u2260 y`, there is an open set containing one but not the other. -/\nclass t0_space (\u03b1 : Type u) [topological_space \u03b1] : Prop :=\n(t0 : \u2200 x y, x \u2260 y \u2192 \u2203 U:set \u03b1, is_open U \u2227 (xor (x \u2208 U) (y \u2208 U)))\n\ntheorem is_closed.exists_closed_singleton {\u03b1 : Type*} [topological_space \u03b1]\n  [t0_space \u03b1] [compact_space \u03b1] {S : set \u03b1} (hS : is_closed S) (hne : S.nonempty) :\n  \u2203 (x : \u03b1), x \u2208 S \u2227 is_closed ({x} : set \u03b1) :=\nbegin\n  obtain \u27e8V, Vsub, Vne, Vcls, hV\u27e9 := hS.exists_minimal_nonempty_closed_subset hne,\n  by_cases hnt : \u2203 (x y : \u03b1) (hx : x \u2208 V) (hy : y \u2208 V), x \u2260 y,\n  { exfalso,\n    obtain \u27e8x, y, hx, hy, hne\u27e9 := hnt,\n    obtain \u27e8U, hU, hsep\u27e9 := t0_space.t0 _ _ hne,\n    have : \u2200 (z w : \u03b1) (hz : z \u2208 V) (hw : w \u2208 V) (hz' : z \u2208 U) (hw' : \u00ac w \u2208 U), false,\n    { intros z w hz hw hz' hw',\n      have uvne : (V \u2229 U\u1d9c).nonempty,\n      { use w, simp only [hw, hw', set.mem_inter_eq, not_false_iff, and_self, set.mem_compl_eq], },\n      specialize hV (V \u2229 U\u1d9c) (set.inter_subset_left _ _) uvne\n        (is_closed_inter Vcls (is_closed_compl_iff.mpr hU)),\n      have : V \u2286 U\u1d9c,\n      { rw \u2190hV, exact set.inter_subset_right _ _ },\n      exact this hz hz', },\n    cases hsep,\n    { exact this x y hx hy hsep.1 hsep.2 },\n    { exact this y x hy hx hsep.1 hsep.2 } },\n  { push_neg at hnt,\n    obtain \u27e8z, hz\u27e9 := Vne,\n    refine \u27e8z, Vsub hz, _\u27e9,\n    convert Vcls,\n    ext,\n    simp only [set.mem_singleton_iff, set.mem_compl_eq],\n    split,\n    { rintro rfl, exact hz, },\n    { exact \u03bb hx, hnt x z hx hz, }, },\nend\n\ntheorem exists_open_singleton_of_open_finset [t0_space \u03b1] (s : finset \u03b1) (sne : s.nonempty)\n  (hso : is_open (\u2191s : set \u03b1)) :\n  \u2203 x \u2208 s, is_open ({x} : set \u03b1):=\nbegin\n  induction s using finset.strong_induction_on with s ihs,\n  by_cases hs : set.subsingleton (\u2191s : set \u03b1),\n  { rcases sne with \u27e8x, hx\u27e9,\n    refine \u27e8x, hx, _\u27e9,\n    have : (\u2191s : set \u03b1) = {x}, from hs.eq_singleton_of_mem hx,\n    rwa this at hso },\n  { dunfold set.subsingleton at hs,\n    push_neg at hs,\n    rcases hs with \u27e8x, hx, y, hy, hxy\u27e9,\n    rcases t0_space.t0 x y hxy with \u27e8U, hU, hxyU\u27e9,\n    wlog H : x \u2208 U \u2227 y \u2209 U := hxyU using [x y, y x],\n    obtain \u27e8z, hzs, hz\u27e9 : \u2203 z \u2208 s.filter (\u03bb z, z \u2208 U), is_open ({z} : set \u03b1),\n    { refine ihs _ (finset.filter_ssubset.2 \u27e8y, hy, H.2\u27e9) \u27e8x, finset.mem_filter.2 \u27e8hx, H.1\u27e9\u27e9 _,\n      rw [finset.coe_filter],\n      exact is_open_inter hso hU },\n    exact \u27e8z, (finset.mem_filter.1 hzs).1, hz\u27e9 }\nend\n\ntheorem exists_open_singleton_of_fintype [t0_space \u03b1] [f : fintype \u03b1] [ha : nonempty \u03b1] :\n  \u2203 x:\u03b1, is_open ({x}:set \u03b1) :=\nbegin\n  refine ha.elim (\u03bb x, _),\n  have : is_open (\u2191(finset.univ : finset \u03b1) : set \u03b1), { simp },\n  rcases exists_open_singleton_of_open_finset _ \u27e8x, finset.mem_univ x\u27e9 this with \u27e8x, _, hx\u27e9,\n  exact \u27e8x, hx\u27e9\nend\n\ninstance subtype.t0_space [t0_space \u03b1] {p : \u03b1 \u2192 Prop} : t0_space (subtype p) :=\n\u27e8\u03bb x y hxy, let \u27e8U, hU, hxyU\u27e9 := t0_space.t0 (x:\u03b1) y ((not_congr subtype.ext_iff_val).1 hxy) in\n  \u27e8(coe : subtype p \u2192 \u03b1) \u207b\u00b9' U, is_open_induced hU, hxyU\u27e9\u27e9\n\n/-- A T\u2081 space, also known as a Fr\u00e9chet space, is a topological space\n  where every singleton set is closed. Equivalently, for every pair\n  `x \u2260 y`, there is an open set containing `x` and not `y`. -/\nclass t1_space (\u03b1 : Type u) [topological_space \u03b1] : Prop :=\n(t1 : \u2200x, is_closed ({x} : set \u03b1))\n\nlemma is_closed_singleton [t1_space \u03b1] {x : \u03b1} : is_closed ({x} : set \u03b1) :=\nt1_space.t1 x\n\nlemma is_open_compl_singleton [t1_space \u03b1] {x : \u03b1} : is_open ({x}\u1d9c : set \u03b1) :=\nis_closed_singleton.is_open_compl\n\nlemma is_open_ne [t1_space \u03b1] {x : \u03b1} : is_open {y | y \u2260 x} :=\nis_open_compl_singleton\n\ninstance subtype.t1_space {\u03b1 : Type u} [topological_space \u03b1] [t1_space \u03b1] {p : \u03b1 \u2192 Prop} :\n  t1_space (subtype p) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, is_closed_induced_iff.2 $ \u27e8{x}, is_closed_singleton, set.ext $ \u03bb y,\n  by simp [subtype.ext_iff_val]\u27e9\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t1_space.t0_space [t1_space \u03b1] : t0_space \u03b1 :=\n\u27e8\u03bb x y h, \u27e8{z | z \u2260 y}, is_open_ne, or.inl \u27e8h, not_not_intro rfl\u27e9\u27e9\u27e9\n\nlemma t1_iff_exists_open : t1_space \u03b1 \u2194\n  \u2200 (x y), x \u2260 y \u2192 (\u2203 (U : set \u03b1) (hU : is_open U), x \u2208 U \u2227 y \u2209 U) :=\nbegin\n  split,\n  { introsI t1 x y hxy,\n    exact \u27e8{y}\u1d9c, is_open_compl_iff.mpr (t1_space.t1 y),\n            mem_compl_singleton_iff.mpr hxy,\n            not_not.mpr rfl\u27e9},\n  { intro h,\n    constructor,\n    intro x,\n    rw \u2190 is_open_compl_iff,\n    have p : \u22c3\u2080 {U : set \u03b1 | (x \u2209 U) \u2227 (is_open U)} = {x}\u1d9c,\n    { apply subset.antisymm; intros t ht,\n      { rcases ht with \u27e8A, \u27e8hxA, hA\u27e9, htA\u27e9,\n        rw [mem_compl_eq, mem_singleton_iff],\n        rintro rfl,\n        contradiction },\n      { obtain \u27e8U, hU, hh\u27e9 := h t x (mem_compl_singleton_iff.mp ht),\n        exact \u27e8U, \u27e8hh.2, hU\u27e9, hh.1\u27e9}},\n    rw \u2190 p,\n    exact is_open_sUnion (\u03bb B hB, hB.2) }\nend\n\nlemma compl_singleton_mem_nhds [t1_space \u03b1] {x y : \u03b1} (h : y \u2260 x) : {x}\u1d9c \u2208 \ud835\udcdd y :=\nmem_nhds_sets is_open_compl_singleton $ by rwa [mem_compl_eq, mem_singleton_iff]\n\n@[simp] lemma closure_singleton [t1_space \u03b1] {a : \u03b1} :\n  closure ({a} : set \u03b1) = {a} :=\nis_closed_singleton.closure_eq\n\nlemma set.subsingleton.closure [t1_space \u03b1] {s : set \u03b1} (hs : s.subsingleton) :\n  (closure s).subsingleton :=\nhs.induction_on (by simp) $ \u03bb x, by simp\n\n@[simp] lemma subsingleton_closure [t1_space \u03b1] {s : set \u03b1} :\n  (closure s).subsingleton \u2194 s.subsingleton :=\n\u27e8\u03bb h, h.mono subset_closure, \u03bb h, h.closure\u27e9\n\nlemma is_closed_map_const {\u03b1 \u03b2} [topological_space \u03b1] [topological_space \u03b2] [t1_space \u03b2] {y : \u03b2} :\n  is_closed_map (function.const \u03b1 y) :=\nbegin\n  apply is_closed_map.of_nonempty, intros s hs h2s, simp_rw [h2s.image_const, is_closed_singleton]\nend\n\nlemma discrete_of_t1_of_finite {X : Type*} [topological_space X] [t1_space X] [fintype X] :\n  discrete_topology X :=\nbegin\n  apply singletons_open_iff_discrete.mp,\n  intros x,\n  rw [\u2190 is_closed_compl_iff, \u2190 bUnion_of_singleton ({x} : set X)\u1d9c],\n  exact is_closed_bUnion (finite.of_fintype _) (\u03bb y _, is_closed_singleton)\nend\n\nlemma singleton_mem_nhds_within_of_mem_discrete {s : set \u03b1} [discrete_topology s]\n  {x : \u03b1} (hx : x \u2208 s) :\n  {x} \u2208 \ud835\udcdd[s] x :=\nbegin\n  have : ({\u27e8x, hx\u27e9} : set s) \u2208 \ud835\udcdd (\u27e8x, hx\u27e9 : s), by simp [nhds_discrete],\n  simpa only [nhds_within_eq_map_subtype_coe hx, image_singleton]\n    using @image_mem_map _ _ _ (coe : s \u2192 \u03b1) _ this\nend\n\nlemma nhds_within_of_mem_discrete {s : set \u03b1} [discrete_topology s] {x : \u03b1} (hx : x \u2208 s) :\n  \ud835\udcdd[s] x = pure x :=\nle_antisymm (le_pure_iff.2 $ singleton_mem_nhds_within_of_mem_discrete hx) (pure_le_nhds_within hx)\n\nlemma filter.has_basis.exists_inter_eq_singleton_of_mem_discrete\n  {\u03b9 : Type*} {p : \u03b9 \u2192 Prop} {t : \u03b9 \u2192 set \u03b1} {s : set \u03b1} [discrete_topology s] {x : \u03b1}\n  (hb : (\ud835\udcdd x).has_basis p t) (hx : x \u2208 s) :\n  \u2203 i (hi : p i), t i \u2229 s = {x} :=\nbegin\n  rcases (nhds_within_has_basis hb s).mem_iff.1 (singleton_mem_nhds_within_of_mem_discrete hx)\n    with \u27e8i, hi, hix\u27e9,\n  exact \u27e8i, hi, subset.antisymm hix $ singleton_subset_iff.2 \u27e8mem_of_nhds $ hb.mem_of_mem hi, hx\u27e9\u27e9\nend\n\n/-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood\nthat only meets `s` at `x`.  -/\nlemma nhds_inter_eq_singleton_of_mem_discrete {s : set \u03b1} [discrete_topology s]\n  {x : \u03b1} (hx : x \u2208 s) :\n  \u2203 U \u2208 \ud835\udcdd x, U \u2229 s = {x} :=\nby simpa using (\ud835\udcdd x).basis_sets.exists_inter_eq_singleton_of_mem_discrete hx\n\n/-- For point `x` in a discrete subset `s` of a topological space, there is a set `U`\nsuch that\n1. `U` is a punctured neighborhood of `x` (ie. `U \u222a {x}` is a neighbourhood of `x`),\n2. `U` is disjoint from `s`.\n-/\nlemma disjoint_nhds_within_of_mem_discrete {s : set \u03b1} [discrete_topology s] {x : \u03b1} (hx : x \u2208 s) :\n  \u2203 U \u2208 \ud835\udcdd[{x}\u1d9c] x, disjoint U s :=\nlet \u27e8V, h, h'\u27e9 := nhds_inter_eq_singleton_of_mem_discrete hx in\n  \u27e8{x}\u1d9c \u2229 V, inter_mem_nhds_within _ h,\n    (disjoint_iff_inter_eq_empty.mpr (by { rw [inter_assoc, h', compl_inter_self] }))\u27e9\n\n/-- Let `X` be a topological space and let `s, t \u2286 X` be two subsets.  If there is an inclusion\n`t \u2286 s`, then the topological space structure on `t` induced by `X` is the same as the one\nobtained by the induced topological space structure on `s`. -/\nlemma topological_space.subset_trans {X : Type*} [tX : topological_space X]\n  {s t : set X} (ts : t \u2286 s) :\n  (subtype.topological_space : topological_space t) =\n    (subtype.topological_space : topological_space s).induced (set.inclusion ts) :=\nbegin\n  change tX.induced ((coe : s \u2192 X) \u2218 (set.inclusion ts)) =\n    topological_space.induced (set.inclusion ts) (tX.induced _),\n  rw \u2190 induced_compose,\nend\n\n/-- This lemma characterizes discrete topological spaces as those whose singletons are\nneighbourhoods. -/\nlemma discrete_topology_iff_nhds {X : Type*} [topological_space X] :\n  discrete_topology X \u2194 (nhds : X \u2192 filter X) = pure :=\nbegin\n  split,\n  { introI hX,\n    exact nhds_discrete X },\n  { intro h,\n    constructor,\n    apply eq_of_nhds_eq_nhds,\n    simp [h, nhds_bot] }\nend\n\n/-- The topology pulled-back under an inclusion `f : X \u2192 Y` from the discrete topology (`\u22a5`) is the\ndiscrete topology.\nThis version does not assume the choice of a topology on either the source `X`\nnor the target `Y` of the inclusion `f`. -/\nlemma induced_bot {X Y : Type*} {f : X \u2192 Y} (hf : function.injective f) :\n  topological_space.induced f \u22a5 = \u22a5 :=\neq_of_nhds_eq_nhds (by simp [nhds_induced, \u2190 set.image_singleton, hf.preimage_image, nhds_bot])\n\n/-- The topology induced under an inclusion `f : X \u2192 Y` from the discrete topological space `Y`\nis the discrete topology on `X`. -/\nlemma discrete_topology_induced {X Y : Type*} [tY : topological_space Y] [discrete_topology Y]\n  {f : X \u2192 Y} (hf : function.injective f) : @discrete_topology X (topological_space.induced f tY) :=\nbegin\n  constructor,\n  rw discrete_topology.eq_bot Y,\n  exact induced_bot hf\nend\n\n/-- Let `s, t \u2286 X` be two subsets of a topological space `X`.  If `t \u2286 s` and the topology induced\nby `X`on `s` is discrete, then also the topology induces on `t` is discrete.  -/\nlemma discrete_topology.of_subset {X : Type*} [topological_space X] {s t : set X}\n  (ds : discrete_topology s) (ts : t \u2286 s) :\n  discrete_topology t :=\nbegin\n  rw [topological_space.subset_trans ts, ds.eq_bot],\n  exact {eq_bot := induced_bot (set.inclusion_injective ts)}\nend\n\n/-- A T\u2082 space, also known as a Hausdorff space, is one in which for every\n  `x \u2260 y` there exists disjoint open sets around `x` and `y`. This is\n  the most widely used of the separation axioms. -/\nclass t2_space (\u03b1 : Type u) [topological_space \u03b1] : Prop :=\n(t2 : \u2200x y, x \u2260 y \u2192 \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 x \u2208 u \u2227 y \u2208 v \u2227 u \u2229 v = \u2205)\n\nlemma t2_separation [t2_space \u03b1] {x y : \u03b1} (h : x \u2260 y) :\n  \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 x \u2208 u \u2227 y \u2208 v \u2227 u \u2229 v = \u2205 :=\nt2_space.t2 x y h\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t2_space.t1_space [t2_space \u03b1] : t1_space \u03b1 :=\n\u27e8\u03bb x, is_open_compl_iff.1 $ is_open_iff_forall_mem_open.2 $ \u03bb y hxy,\nlet \u27e8u, v, hu, hv, hyu, hxv, huv\u27e9 := t2_separation (mt mem_singleton_of_eq hxy) in\n\u27e8u, \u03bb z hz1 hz2, (ext_iff.1 huv x).1 \u27e8mem_singleton_iff.1 hz2 \u25b8 hz1, hxv\u27e9, hu, hyu\u27e9\u27e9\n\nlemma eq_of_nhds_ne_bot [ht : t2_space \u03b1] {x y : \u03b1} (h : ne_bot (\ud835\udcdd x \u2293 \ud835\udcdd y)) : x = y :=\nclassical.by_contradiction $ assume : x \u2260 y,\nlet \u27e8u, v, hu, hv, hx, hy, huv\u27e9 := t2_space.t2 x y this in\nabsurd huv $ (inf_ne_bot_iff.1 h (mem_nhds_sets hu hx) (mem_nhds_sets hv hy)).ne_empty\n\nlemma t2_iff_nhds : t2_space \u03b1 \u2194 \u2200 {x y : \u03b1}, ne_bot (\ud835\udcdd x \u2293 \ud835\udcdd y) \u2192 x = y :=\n\u27e8assume h, by exactI \u03bb x y, eq_of_nhds_ne_bot,\n assume h, \u27e8assume x y xy,\n   have \ud835\udcdd x \u2293 \ud835\udcdd y = \u22a5 := not_ne_bot.1 $ mt h xy,\n   let \u27e8u', hu', v', hv', u'v'\u27e9 := empty_in_sets_eq_bot.mpr this,\n       \u27e8u, uu', uo, hu\u27e9 := mem_nhds_sets_iff.mp hu',\n       \u27e8v, vv', vo, hv\u27e9 := mem_nhds_sets_iff.mp hv' in\n   \u27e8u, v, uo, vo, hu, hv, disjoint.eq_bot $ disjoint.mono uu' vv' u'v'\u27e9\u27e9\u27e9\n\nlemma t2_iff_ultrafilter :\n  t2_space \u03b1 \u2194 \u2200 {x y : \u03b1} (f : ultrafilter \u03b1), \u2191f \u2264 \ud835\udcdd x \u2192 \u2191f \u2264 \ud835\udcdd y \u2192 x = y :=\nt2_iff_nhds.trans $ by simp only [\u2190exists_ultrafilter_iff, and_imp, le_inf_iff, exists_imp_distrib]\n\nlemma is_closed_diagonal [t2_space \u03b1] : is_closed (diagonal \u03b1) :=\nbegin\n  refine is_closed_iff_cluster_pt.mpr _,\n  rintro \u27e8a\u2081, a\u2082\u27e9 h,\n  refine eq_of_nhds_ne_bot \u27e8\u03bb this : \ud835\udcdd a\u2081 \u2293 \ud835\udcdd a\u2082 = \u22a5, h.ne _\u27e9,\n  obtain \u27e8t\u2081, (ht\u2081 : t\u2081 \u2208 \ud835\udcdd a\u2081), t\u2082, (ht\u2082 : t\u2082 \u2208 \ud835\udcdd a\u2082), (h' : t\u2081 \u2229 t\u2082 \u2286 \u2205)\u27e9 :=\n    by rw [\u2190empty_in_sets_eq_bot, mem_inf_sets] at this; exact this,\n  rw [nhds_prod_eq, \u2190empty_in_sets_eq_bot],\n  apply filter.sets_of_superset,\n  apply inter_mem_inf_sets (prod_mem_prod ht\u2081 ht\u2082) (mem_principal_sets.mpr (subset.refl _)),\n  exact assume \u27e8x\u2081, x\u2082\u27e9 \u27e8\u27e8hx\u2081, hx\u2082\u27e9, (heq : x\u2081 = x\u2082)\u27e9,\n    show false, from @h' x\u2081 \u27e8hx\u2081, heq.symm \u25b8 hx\u2082\u27e9\nend\n\nlemma t2_iff_is_closed_diagonal : t2_space \u03b1 \u2194 is_closed (diagonal \u03b1) :=\nbegin\n  split,\n  { introI h,\n    exact is_closed_diagonal },\n  { intro h,\n    constructor,\n    intros x y hxy,\n    have : (x, y) \u2208 (diagonal \u03b1)\u1d9c, by rwa [mem_compl_iff],\n    obtain \u27e8t, t_sub, t_op, xyt\u27e9 : \u2203 t \u2286 (diagonal \u03b1)\u1d9c, is_open t \u2227 (x, y) \u2208 t :=\n      is_open_iff_forall_mem_open.mp h.is_open_compl _ this,\n    rcases is_open_prod_iff.mp t_op x y xyt with \u27e8U, V, U_op, V_op, xU, yV, H\u27e9,\n    use [U, V, U_op, V_op, xU, yV],\n    have := subset.trans H t_sub,\n    rw eq_empty_iff_forall_not_mem,\n    rintros z \u27e8zU, zV\u27e9,\n    have : \u00ac (z, z) \u2208 diagonal \u03b1 := this (mk_mem_prod zU zV),\n    exact this rfl },\nend\n\nsection separated\n\nopen separated finset\n\nlemma finset_disjoint_finset_opens_of_t2 [t2_space \u03b1] :\n  \u2200 (s t : finset \u03b1), disjoint s t \u2192 separated (s : set \u03b1) t :=\nbegin\n  refine induction_on_union _ (\u03bb a b hi d, (hi d.symm).symm) (\u03bb a d, empty_right a) (\u03bb a b ab, _) _,\n  { obtain \u27e8U, V, oU, oV, aU, bV, UV\u27e9 := t2_separation\n      (by { rw [ne.def, \u2190 finset.mem_singleton], exact (disjoint_singleton.mp ab.symm) }),\n    refine \u27e8U, V, oU, oV, _, _, set.disjoint_iff_inter_eq_empty.mpr UV\u27e9;\n    exact singleton_subset_set_iff.mpr \u2039_\u203a },\n  { intros a b c ac bc d,\n    apply_mod_cast union_left (ac (disjoint_of_subset_left (a.subset_union_left b) d)) (bc _),\n    exact disjoint_of_subset_left (a.subset_union_right b) d },\nend\n\nlemma point_disjoint_finset_opens_of_t2 [t2_space \u03b1] {x : \u03b1} {s : finset \u03b1} (h : x \u2209 s) :\n  separated ({x} : set \u03b1) \u2191s :=\nby exact_mod_cast finset_disjoint_finset_opens_of_t2 {x} s (singleton_disjoint.mpr h)\n\nend separated\n\n@[simp] lemma nhds_eq_nhds_iff {a b : \u03b1} [t2_space \u03b1] : \ud835\udcdd a = \ud835\udcdd b \u2194 a = b :=\n\u27e8assume h, eq_of_nhds_ne_bot $ by rw [h, inf_idem]; exact nhds_ne_bot, assume h, h \u25b8 rfl\u27e9\n\n@[simp] lemma nhds_le_nhds_iff {a b : \u03b1} [t2_space \u03b1] : \ud835\udcdd a \u2264 \ud835\udcdd b \u2194 a = b :=\n\u27e8assume h, eq_of_nhds_ne_bot $ by rw [inf_of_le_left h]; exact nhds_ne_bot, assume h, h \u25b8 le_refl _\u27e9\n\nlemma tendsto_nhds_unique [t2_space \u03b1] {f : \u03b2 \u2192 \u03b1} {l : filter \u03b2} {a b : \u03b1}\n  [ne_bot l] (ha : tendsto f l (\ud835\udcdd a)) (hb : tendsto f l (\ud835\udcdd b)) : a = b :=\neq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb\n\nlemma tendsto_nhds_unique' [t2_space \u03b1] {f : \u03b2 \u2192 \u03b1} {l : filter \u03b2} {a b : \u03b1}\n  (hl : ne_bot l) (ha : tendsto f l (\ud835\udcdd a)) (hb : tendsto f l (\ud835\udcdd b)) : a = b :=\neq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb\n\nlemma tendsto_nhds_unique_of_eventually_eq [t2_space \u03b1] {f g : \u03b2 \u2192 \u03b1} {l : filter \u03b2} {a b : \u03b1}\n  [ne_bot l] (ha : tendsto f l (\ud835\udcdd a)) (hb : tendsto g l (\ud835\udcdd b)) (hfg : f =\u1da0[l] g) :\n  a = b :=\ntendsto_nhds_unique (ha.congr' hfg) hb\n\n/-- A T2,5 space, also known as a Urysohn space, is a topological space\n  where for every pair `x \u2260 y`, there are two open sets, with the intersection of clousures\n  empty, one containing `x` and the other `y` . -/\nclass t2_5_space (\u03b1 : Type u) [topological_space \u03b1]: Prop :=\n(t2_5 : \u2200 x y  (h : x \u2260 y), \u2203 (U V: set \u03b1), is_open U \u2227  is_open V \u2227\n                                            closure U \u2229 closure V = \u2205 \u2227 x \u2208 U \u2227 y \u2208 V)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t2_5_space.t2_space [t2_5_space \u03b1] : t2_space \u03b1 :=\n\u27e8\u03bb x y hxy,\n  let \u27e8U, V, hU, hV, hUV, hh\u27e9 := t2_5_space.t2_5 x y hxy in\n  \u27e8U, V, hU, hV, hh.1, hh.2, subset_eq_empty (powerset_mono.mpr\n    (closure_inter_subset_inter_closure U V) subset_closure) hUV\u27e9\u27e9\n\nsection lim\nvariables [t2_space \u03b1] {f : filter \u03b1}\n\n/-!\n### Properties of `Lim` and `lim`\n\nIn this section we use explicit `nonempty \u03b1` instances for `Lim` and `lim`. This way the lemmas\nare useful without a `nonempty \u03b1` instance.\n-/\n\nlemma Lim_eq {a : \u03b1} [ne_bot f] (h : f \u2264 \ud835\udcdd a) :\n  @Lim _ _ \u27e8a\u27e9 f = a :=\ntendsto_nhds_unique (le_nhds_Lim \u27e8a, h\u27e9) h\n\nlemma Lim_eq_iff [ne_bot f] (h : \u2203 (a : \u03b1), f \u2264 nhds a) {a} : @Lim _ _ \u27e8a\u27e9 f = a \u2194 f \u2264 \ud835\udcdd a :=\n\u27e8\u03bb c, c \u25b8 le_nhds_Lim h, Lim_eq\u27e9\n\nlemma ultrafilter.Lim_eq_iff_le_nhds [compact_space \u03b1] {x : \u03b1} {F : ultrafilter \u03b1} :\n  F.Lim = x \u2194 \u2191F \u2264 \ud835\udcdd x :=\n\u27e8\u03bb h, h \u25b8 F.le_nhds_Lim, Lim_eq\u27e9\n\nlemma is_open_iff_ultrafilter' [compact_space \u03b1] (U : set \u03b1) :\n  is_open U \u2194 (\u2200 F : ultrafilter \u03b1, F.Lim \u2208 U \u2192 U \u2208 F.1) :=\nbegin\n  rw is_open_iff_ultrafilter,\n  refine \u27e8\u03bb h F hF, h F.Lim hF F F.le_nhds_Lim, _\u27e9,\n  intros cond x hx f h,\n  rw [\u2190 (ultrafilter.Lim_eq_iff_le_nhds.2 h)] at hx,\n  exact cond _ hx\nend\n\nlemma filter.tendsto.lim_eq {a : \u03b1} {f : filter \u03b2} [ne_bot f] {g : \u03b2 \u2192 \u03b1} (h : tendsto g f (\ud835\udcdd a)) :\n  @lim _ _ _ \u27e8a\u27e9 f g = a :=\nLim_eq h\n\nlemma filter.lim_eq_iff {f : filter \u03b2} [ne_bot f] {g : \u03b2 \u2192 \u03b1} (h : \u2203 a, tendsto g f (\ud835\udcdd a)) {a} :\n  @lim _ _ _ \u27e8a\u27e9 f g = a \u2194 tendsto g f (\ud835\udcdd a) :=\n\u27e8\u03bb c, c \u25b8 tendsto_nhds_lim h, filter.tendsto.lim_eq\u27e9\n\nlemma continuous.lim_eq [topological_space \u03b2] {f : \u03b2 \u2192 \u03b1} (h : continuous f) (a : \u03b2) :\n  @lim _ _ _ \u27e8f a\u27e9 (\ud835\udcdd a) f = f a :=\n(h.tendsto a).lim_eq\n\n@[simp] lemma Lim_nhds (a : \u03b1) : @Lim _ _ \u27e8a\u27e9 (\ud835\udcdd a) = a :=\nLim_eq (le_refl _)\n\n@[simp] lemma lim_nhds_id (a : \u03b1) : @lim _ _ _ \u27e8a\u27e9 (\ud835\udcdd a) id = a :=\nLim_nhds a\n\n@[simp] lemma Lim_nhds_within {a : \u03b1} {s : set \u03b1} (h : a \u2208 closure s) :\n  @Lim _ _ \u27e8a\u27e9 (\ud835\udcdd[s] a) = a :=\nby haveI : ne_bot (\ud835\udcdd[s] a) := mem_closure_iff_cluster_pt.1 h;\nexact Lim_eq inf_le_left\n\n@[simp] lemma lim_nhds_within_id {a : \u03b1} {s : set \u03b1} (h : a \u2208 closure s) :\n  @lim _ _ _ \u27e8a\u27e9 (\ud835\udcdd[s] a) id = a :=\nLim_nhds_within h\n\nend lim\n\n/-!\n### Instances of `t2_space` typeclass\n\nWe use two lemmas to prove that various standard constructions generate Hausdorff spaces from\nHausdorff spaces:\n\n* `separated_by_continuous` says that two points `x y : \u03b1` can be separated by open neighborhoods\n  provided that there exists a continuous map `f`: \u03b1 \u2192 \u03b2` with a Hausdorff codomain such that\n  `f x \u2260 f y`. We use this lemma to prove that topological spaces defined using `induced` are\n  Hausdorff spaces.\n\n* `separated_by_open_embedding` says that for an open embedding `f : \u03b1 \u2192 \u03b2` of a Hausdorff space\n  `\u03b1`, the images of two distinct points `x y : \u03b1`, `x \u2260 y` can be separated by open neighborhoods.\n  We use this lemma to prove that topological spaces defined using `coinduced` are Hausdorff spaces.\n-/\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t2_space_discrete {\u03b1 : Type*} [topological_space \u03b1] [discrete_topology \u03b1] : t2_space \u03b1 :=\n{ t2 := assume x y hxy, \u27e8{x}, {y}, is_open_discrete _, is_open_discrete _, rfl, rfl,\n  eq_empty_iff_forall_not_mem.2 $ by intros z hz;\n    cases eq_of_mem_singleton hz.1; cases eq_of_mem_singleton hz.2; cc\u27e9 }\n\nlemma separated_by_continuous {\u03b1 : Type*} {\u03b2 : Type*}\n  [topological_space \u03b1] [topological_space \u03b2] [t2_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : continuous f) {x y : \u03b1} (h : f x \u2260 f y) :\n  \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 x \u2208 u \u2227 y \u2208 v \u2227 u \u2229 v = \u2205 :=\nlet \u27e8u, v, uo, vo, xu, yv, uv\u27e9 := t2_separation h in\n\u27e8f \u207b\u00b9' u, f \u207b\u00b9' v, uo.preimage hf, vo.preimage hf, xu, yv,\n  by rw [\u2190preimage_inter, uv, preimage_empty]\u27e9\n\nlemma separated_by_open_embedding {\u03b1 \u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n  [t2_space \u03b1] {f : \u03b1 \u2192 \u03b2} (hf : open_embedding f) {x y : \u03b1} (h : x \u2260 y) :\n  \u2203 u v : set \u03b2, is_open u \u2227 is_open v \u2227 f x \u2208 u \u2227 f y \u2208 v \u2227 u \u2229 v = \u2205 :=\nlet \u27e8u, v, uo, vo, xu, yv, uv\u27e9 := t2_separation h in\n\u27e8f '' u, f '' v, hf.is_open_map _ uo, hf.is_open_map _ vo,\n  mem_image_of_mem _ xu, mem_image_of_mem _ yv, by rw [image_inter hf.inj, uv, image_empty]\u27e9\n\ninstance {\u03b1 : Type*} {p : \u03b1 \u2192 Prop} [t : topological_space \u03b1] [t2_space \u03b1] : t2_space (subtype p) :=\n\u27e8assume x y h, separated_by_continuous continuous_subtype_val (mt subtype.eq h)\u27e9\n\ninstance {\u03b1 : Type*} {\u03b2 : Type*} [t\u2081 : topological_space \u03b1] [t2_space \u03b1]\n  [t\u2082 : topological_space \u03b2] [t2_space \u03b2] : t2_space (\u03b1 \u00d7 \u03b2) :=\n\u27e8assume \u27e8x\u2081,x\u2082\u27e9 \u27e8y\u2081,y\u2082\u27e9 h,\n  or.elim (not_and_distrib.mp (mt prod.ext_iff.mpr h))\n    (\u03bb h\u2081, separated_by_continuous continuous_fst h\u2081)\n    (\u03bb h\u2082, separated_by_continuous continuous_snd h\u2082)\u27e9\n\nlemma embedding.t2_space [topological_space \u03b2] [t2_space \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : embedding f) :\n  t2_space \u03b1 :=\n\u27e8\u03bb x y h, separated_by_continuous hf.continuous (hf.inj.ne h)\u27e9\n\ninstance {\u03b1 : Type*} {\u03b2 : Type*} [t\u2081 : topological_space \u03b1] [t2_space \u03b1]\n  [t\u2082 : topological_space \u03b2] [t2_space \u03b2] : t2_space (\u03b1 \u2295 \u03b2) :=\nbegin\n  constructor,\n  rintros (x|x) (y|y) h,\n  { replace h : x \u2260 y := \u03bb c, (c.subst h) rfl,\n    exact separated_by_open_embedding open_embedding_inl h },\n  { exact \u27e8_, _, is_open_range_inl, is_open_range_inr, \u27e8x, rfl\u27e9, \u27e8y, rfl\u27e9,\n      range_inl_inter_range_inr\u27e9 },\n  { exact \u27e8_, _, is_open_range_inr, is_open_range_inl, \u27e8x, rfl\u27e9, \u27e8y, rfl\u27e9,\n      range_inr_inter_range_inl\u27e9 },\n  { replace h : x \u2260 y := \u03bb c, (c.subst h) rfl,\n    exact separated_by_open_embedding open_embedding_inr h }\nend\n\ninstance Pi.t2_space {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type v} [t\u2082 : \u03a0a, topological_space (\u03b2 a)]\n  [\u2200a, t2_space (\u03b2 a)] :\n  t2_space (\u03a0a, \u03b2 a) :=\n\u27e8assume x y h,\n  let \u27e8i, hi\u27e9 := not_forall.mp (mt funext h) in\n  separated_by_continuous (continuous_apply i) hi\u27e9\n\ninstance sigma.t2_space {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0i, topological_space (\u03b1 i)]\n  [\u2200a, t2_space (\u03b1 a)] :\n  t2_space (\u03a3i, \u03b1 i) :=\nbegin\n  constructor,\n  rintros \u27e8i, x\u27e9 \u27e8j, y\u27e9 neq,\n  rcases em (i = j) with (rfl|h),\n  { replace neq : x \u2260 y := \u03bb c, (c.subst neq) rfl,\n    exact separated_by_open_embedding open_embedding_sigma_mk neq },\n  { exact \u27e8_, _, is_open_range_sigma_mk, is_open_range_sigma_mk, \u27e8x, rfl\u27e9, \u27e8y, rfl\u27e9, by tidy\u27e9 }\nend\n\nvariables [topological_space \u03b2]\n\nlemma is_closed_eq [t2_space \u03b1] {f g : \u03b2 \u2192 \u03b1}\n  (hf : continuous f) (hg : continuous g) : is_closed {x:\u03b2 | f x = g x} :=\ncontinuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_diagonal\n\n/-- If two continuous maps are equal on `s`, then they are equal on the closure of `s`. -/\nlemma set.eq_on.closure [t2_space \u03b1] {s : set \u03b2} {f g : \u03b2 \u2192 \u03b1} (h : eq_on f g s)\n  (hf : continuous f) (hg : continuous g) :\n  eq_on f g (closure s) :=\nclosure_minimal h (is_closed_eq hf hg)\n\n/-- If two continuous functions are equal on a dense set, then they are equal. -/\nlemma continuous.ext_on [t2_space \u03b1] {s : set \u03b2} (hs : dense s) {f g : \u03b2 \u2192 \u03b1}\n  (hf : continuous f) (hg : continuous g) (h : eq_on f g s) :\n  f = g :=\nfunext $ \u03bb x, h.closure hf hg (hs x)\n\nlemma function.left_inverse.closed_range [t2_space \u03b1] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (h : function.left_inverse f g) (hf : continuous f) (hg : continuous g) :\n  is_closed (range g) :=\nhave eq_on (g \u2218 f) id (closure $ range g),\n  from h.right_inv_on_range.eq_on.closure (hg.comp hf) continuous_id,\nis_closed_of_closure_subset $ \u03bb x hx,\ncalc x = g (f x) : (this hx).symm\n   ... \u2208 _ : mem_range_self _\n\nlemma function.left_inverse.closed_embedding [t2_space \u03b1] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (h : function.left_inverse f g) (hf : continuous f) (hg : continuous g) :\n  closed_embedding g :=\n\u27e8h.embedding hf hg, h.closed_range hf hg\u27e9\n\nlemma diagonal_eq_range_diagonal_map {\u03b1 : Type*} : {p:\u03b1\u00d7\u03b1 | p.1 = p.2} = range (\u03bbx, (x,x)) :=\next $ assume p, iff.intro\n  (assume h, \u27e8p.1, prod.ext_iff.2 \u27e8rfl, h\u27e9\u27e9)\n  (assume \u27e8x, hx\u27e9, show p.1 = p.2, by rw \u2190hx)\n\nlemma prod_subset_compl_diagonal_iff_disjoint {\u03b1 : Type*} {s t : set \u03b1} :\n  set.prod s t \u2286 {p:\u03b1\u00d7\u03b1 | p.1 = p.2}\u1d9c \u2194 s \u2229 t = \u2205 :=\nby rw [eq_empty_iff_forall_not_mem, subset_compl_comm,\n       diagonal_eq_range_diagonal_map, range_subset_iff]; simp\n\nlemma compact_compact_separated [t2_space \u03b1] {s t : set \u03b1}\n  (hs : is_compact s) (ht : is_compact t) (hst : s \u2229 t = \u2205) :\n  \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 u \u2229 v = \u2205 :=\nby simp only [prod_subset_compl_diagonal_iff_disjoint.symm] at \u22a2 hst;\n   exact generalized_tube_lemma hs ht is_closed_diagonal.is_open_compl hst\n\n/-- In a `t2_space`, every compact set is closed. -/\nlemma is_compact.is_closed [t2_space \u03b1] {s : set \u03b1} (hs : is_compact s) : is_closed s :=\nis_open_compl_iff.1 $ is_open_iff_forall_mem_open.mpr $ assume x hx,\n  let \u27e8u, v, uo, vo, su, xv, uv\u27e9 :=\n    compact_compact_separated hs (compact_singleton : is_compact {x})\n      (by rwa [inter_comm, \u2190subset_compl_iff_disjoint, singleton_subset_iff]) in\n  have v \u2286 s\u1d9c, from\n    subset_compl_comm.mp (subset.trans su (subset_compl_iff_disjoint.mpr uv)),\n\u27e8v, this, vo, by simpa using xv\u27e9\n\nlemma compact_exhaustion.is_closed [t2_space \u03b1] (K : compact_exhaustion \u03b1) (n : \u2115) :\n  is_closed (K n) :=\n(K.is_compact n).is_closed\n\nlemma is_compact.inter [t2_space \u03b1] {s t : set \u03b1} (hs : is_compact s) (ht : is_compact t) :\n  is_compact (s \u2229 t) :=\nhs.inter_right $ ht.is_closed\n\nlemma compact_closure_of_subset_compact [t2_space \u03b1] {s t : set \u03b1} (ht : is_compact t) (h : s \u2286 t) :\n  is_compact (closure s) :=\ncompact_of_is_closed_subset ht is_closed_closure (closure_minimal h ht.is_closed)\n\nlemma image_closure_of_compact [t2_space \u03b2]\n  {s : set \u03b1} (hs : is_compact (closure s)) {f : \u03b1 \u2192 \u03b2} (hf : continuous_on f (closure s)) :\n  f '' closure s = closure (f '' s) :=\nsubset.antisymm hf.image_closure $ closure_minimal (image_subset f subset_closure)\n  (hs.image_of_continuous_on hf).is_closed\n\n/-- If a compact set is covered by two open sets, then we can cover it by two compact subsets. -/\nlemma is_compact.binary_compact_cover [t2_space \u03b1] {K U V : set \u03b1} (hK : is_compact K)\n  (hU : is_open U) (hV : is_open V) (h2K : K \u2286 U \u222a V) :\n  \u2203 K\u2081 K\u2082 : set \u03b1, is_compact K\u2081 \u2227 is_compact K\u2082 \u2227 K\u2081 \u2286 U \u2227 K\u2082 \u2286 V \u2227 K = K\u2081 \u222a K\u2082 :=\nbegin\n  rcases compact_compact_separated (compact_diff hK hU) (compact_diff hK hV)\n    (by rwa [diff_inter_diff, diff_eq_empty]) with \u27e8O\u2081, O\u2082, h1O\u2081, h1O\u2082, h2O\u2081, h2O\u2082, hO\u27e9,\n  refine \u27e8_, _, compact_diff hK h1O\u2081, compact_diff hK h1O\u2082,\n    by rwa [diff_subset_comm], by rwa [diff_subset_comm], by rw [\u2190 diff_inter, hO, diff_empty]\u27e9\nend\n\nlemma continuous.is_closed_map [compact_space \u03b1] [t2_space \u03b2] {f : \u03b1 \u2192 \u03b2} (h : continuous f) :\n  is_closed_map f :=\n\u03bb s hs, (hs.compact.image h).is_closed\n\nlemma continuous.closed_embedding [compact_space \u03b1] [t2_space \u03b2] {f : \u03b1 \u2192 \u03b2} (h : continuous f)\n  (hf : function.injective f) : closed_embedding f :=\nclosed_embedding_of_continuous_injective_closed h hf h.is_closed_map\n\nsection\nopen finset function\n/-- For every finite open cover `U\u1d62` of a compact set, there exists a compact cover `K\u1d62 \u2286 U\u1d62`. -/\nlemma is_compact.finite_compact_cover [t2_space \u03b1] {s : set \u03b1} (hs : is_compact s)\n  {\u03b9} (t : finset \u03b9) (U : \u03b9 \u2192 set \u03b1) (hU : \u2200 i \u2208 t, is_open (U i)) (hsC : s \u2286 \u22c3 i \u2208 t, U i) :\n  \u2203 K : \u03b9 \u2192 set \u03b1, (\u2200 i, is_compact (K i)) \u2227 (\u2200i, K i \u2286 U i) \u2227 s = \u22c3 i \u2208 t, K i :=\nbegin\n  classical,\n  induction t using finset.induction with x t hx ih generalizing U hU s hs hsC,\n  { refine \u27e8\u03bb _, \u2205, \u03bb i, compact_empty, \u03bb i, empty_subset _, _\u27e9, simpa only [subset_empty_iff,\n      finset.not_mem_empty, Union_neg, Union_empty, not_false_iff] using hsC },\n  simp only [finset.set_bUnion_insert] at hsC,\n  simp only [finset.mem_insert] at hU,\n  have hU' : \u2200 i \u2208 t, is_open (U i) := \u03bb i hi, hU i (or.inr hi),\n  rcases hs.binary_compact_cover (hU x (or.inl rfl)) (is_open_bUnion hU') hsC\n    with \u27e8K\u2081, K\u2082, h1K\u2081, h1K\u2082, h2K\u2081, h2K\u2082, hK\u27e9,\n  rcases ih U hU' h1K\u2082 h2K\u2082 with \u27e8K, h1K, h2K, h3K\u27e9,\n  refine \u27e8update K x K\u2081, _, _, _\u27e9,\n  { intros i, by_cases hi : i = x,\n    { simp only [update_same, hi, h1K\u2081] },\n    { rw [\u2190 ne.def] at hi, simp only [update_noteq hi, h1K] }},\n  { intros i, by_cases hi : i = x,\n    { simp only [update_same, hi, h2K\u2081] },\n    { rw [\u2190 ne.def] at hi, simp only [update_noteq hi, h2K] }},\n  { simp only [set_bUnion_insert_update _ hx, hK, h3K] }\nend\nend\n\nlemma locally_compact_of_compact_nhds [t2_space \u03b1] (h : \u2200 x : \u03b1, \u2203 s, s \u2208 \ud835\udcdd x \u2227 is_compact s) :\n  locally_compact_space \u03b1 :=\n\u27e8assume x n hn,\n  let \u27e8u, un, uo, xu\u27e9 := mem_nhds_sets_iff.mp hn in\n  let \u27e8k, kx, kc\u27e9 := h x in\n  -- K is compact but not necessarily contained in N.\n  -- K \\ U is again compact and doesn't contain x, so\n  -- we may find open sets V, W separating x from K \\ U.\n  -- Then K \\ W is a compact neighborhood of x contained in U.\n  let \u27e8v, w, vo, wo, xv, kuw, vw\u27e9 :=\n    compact_compact_separated compact_singleton (compact_diff kc uo)\n      (by rw [singleton_inter_eq_empty]; exact \u03bb h, h.2 xu) in\n  have wn : w\u1d9c \u2208 \ud835\udcdd x, from\n   mem_nhds_sets_iff.mpr\n     \u27e8v, subset_compl_iff_disjoint.mpr vw, vo, singleton_subset_iff.mp xv\u27e9,\n  \u27e8k \\ w,\n   filter.inter_mem_sets kx wn,\n   subset.trans (diff_subset_comm.mp kuw) un,\n   compact_diff kc wo\u27e9\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance locally_compact_of_compact [t2_space \u03b1] [compact_space \u03b1] : locally_compact_space \u03b1 :=\nlocally_compact_of_compact_nhds (assume x, \u27e8univ, mem_nhds_sets is_open_univ trivial, compact_univ\u27e9)\n\n/-- In a locally compact T\u2082 space, every point has an open neighborhood with compact closure -/\nlemma exists_open_with_compact_closure [locally_compact_space \u03b1] [t2_space \u03b1] (x : \u03b1) :\n  \u2203 (U : set \u03b1), is_open U \u2227 x \u2208 U \u2227 is_compact (closure U) :=\nbegin\n  rcases exists_compact_mem_nhds x with \u27e8K, hKc, hxK\u27e9,\n  rcases mem_nhds_sets_iff.1 hxK with \u27e8t, h1t, h2t, h3t\u27e9,\n  exact \u27e8t, h2t, h3t, compact_closure_of_subset_compact hKc h1t\u27e9\nend\n\nend separation\n\nsection regularity\n\n/-- A T\u2083 space, also known as a regular space (although this condition sometimes\n  omits T\u2082), is one in which for every closed `C` and `x \u2209 C`, there exist\n  disjoint open sets containing `x` and `C` respectively. -/\nclass regular_space (\u03b1 : Type u) [topological_space \u03b1] extends t0_space \u03b1 : Prop :=\n(regular : \u2200{s:set \u03b1} {a}, is_closed s \u2192 a \u2209 s \u2192 \u2203t, is_open t \u2227 s \u2286 t \u2227 \ud835\udcdd[t] a = \u22a5)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance regular_space.t1_space [regular_space \u03b1] : t1_space \u03b1 :=\nbegin\n  rw t1_iff_exists_open,\n  intros x y hxy,\n  obtain \u27e8U, hU, h\u27e9 := t0_space.t0 x y hxy,\n  cases h,\n  { exact \u27e8U, hU, h\u27e9 },\n  { obtain \u27e8R, hR, hh\u27e9 := regular_space.regular (is_closed_compl_iff.mpr hU) (not_not.mpr h.1),\n    obtain \u27e8V, hV, hhh\u27e9 := mem_nhds_sets_iff.1 (filter.inf_principal_eq_bot.1 hh.2),\n    exact \u27e8R, hR, hh.1 (mem_compl h.2), hV hhh.2\u27e9 }\nend\n\nlemma nhds_is_closed [regular_space \u03b1] {a : \u03b1} {s : set \u03b1} (h : s \u2208 \ud835\udcdd a) :\n  \u2203 t \u2208 \ud835\udcdd a, t \u2286 s \u2227 is_closed t :=\nlet \u27e8s', h\u2081, h\u2082, h\u2083\u27e9 := mem_nhds_sets_iff.mp h in\nhave \u2203t, is_open t \u2227 s'\u1d9c \u2286 t \u2227 \ud835\udcdd[t] a = \u22a5,\n  from regular_space.regular (is_closed_compl_iff.mpr h\u2082) (not_not_intro h\u2083),\nlet \u27e8t, ht\u2081, ht\u2082, ht\u2083\u27e9 := this in\n\u27e8t\u1d9c,\n  mem_sets_of_eq_bot $ by rwa [compl_compl],\n  subset.trans (compl_subset_comm.1 ht\u2082) h\u2081,\n  is_closed_compl_iff.mpr ht\u2081\u27e9\n\nlemma closed_nhds_basis [regular_space \u03b1] (a : \u03b1) :\n  (\ud835\udcdd a).has_basis (\u03bb s : set \u03b1, s \u2208 \ud835\udcdd a \u2227 is_closed s) id :=\n\u27e8\u03bb t, \u27e8\u03bb t_in, let \u27e8s, s_in, h_st, h\u27e9 := nhds_is_closed t_in in \u27e8s, \u27e8s_in, h\u27e9, h_st\u27e9,\n       \u03bb \u27e8s, \u27e8s_in, hs\u27e9, hst\u27e9, mem_sets_of_superset s_in hst\u27e9\u27e9\n\ninstance subtype.regular_space [regular_space \u03b1] {p : \u03b1 \u2192 Prop} : regular_space (subtype p) :=\n\u27e8begin\n   intros s a hs ha,\n   rcases is_closed_induced_iff.1 hs with \u27e8s, hs', rfl\u27e9,\n   rcases regular_space.regular hs' ha with \u27e8t, ht, hst, hat\u27e9,\n   refine \u27e8coe \u207b\u00b9' t, is_open_induced ht, preimage_mono hst, _\u27e9,\n   rw [nhds_within, nhds_induced, \u2190 comap_principal, \u2190 comap_inf, \u2190 nhds_within, hat, comap_bot]\n end\u27e9\n\nvariable (\u03b1)\n@[priority 100] -- see Note [lower instance priority]\ninstance regular_space.t2_space [regular_space \u03b1] : t2_space \u03b1 :=\n\u27e8\u03bb x y hxy,\nlet \u27e8s, hs, hys, hxs\u27e9 := regular_space.regular is_closed_singleton\n    (mt mem_singleton_iff.1 hxy),\n  \u27e8t, hxt, u, hsu, htu\u27e9 := empty_in_sets_eq_bot.2 hxs,\n  \u27e8v, hvt, hv, hxv\u27e9 := mem_nhds_sets_iff.1 hxt in\n\u27e8v, s, hv, hs, hxv, singleton_subset_iff.1 hys,\neq_empty_of_subset_empty $ \u03bb z \u27e8hzv, hzs\u27e9, htu \u27e8hvt hzv, hsu hzs\u27e9\u27e9\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance regular_space.t2_5_space [regular_space \u03b1] : t2_5_space \u03b1 :=\n\u27e8\u03bb x y hxy,\nlet \u27e8U, V, hU, hV, hh_1, hh_2, hUV\u27e9 := t2_space.t2 x y hxy,\n  hxcV := not_not.mpr ((interior_maximal (subset_compl_iff_disjoint.mpr hUV) hU) hh_1),\n  \u27e8R, hR, hh\u27e9 := regular_space.regular is_closed_closure (by rwa closure_eq_compl_interior_compl),\n  \u27e8A, hA, hhh\u27e9 := mem_nhds_sets_iff.1 (filter.inf_principal_eq_bot.1 hh.2) in\n\u27e8A, V, hhh.1, hV, subset_eq_empty ((closure V).inter_subset_inter_left\n  (subset.trans (closure_minimal hA (is_closed_compl_iff.mpr hR)) (compl_subset_compl.mpr hh.1)))\n  (compl_inter_self (closure V)), hhh.2, hh_2\u27e9\u27e9\n\nvariable {\u03b1}\n\nlemma disjoint_nested_nhds [regular_space \u03b1] {x y : \u03b1} (h : x \u2260 y) :\n  \u2203 (U\u2081 V\u2081 \u2208 \ud835\udcdd x) (U\u2082 V\u2082 \u2208 \ud835\udcdd y), is_closed V\u2081 \u2227 is_closed V\u2082 \u2227 is_open U\u2081 \u2227 is_open U\u2082 \u2227\n  V\u2081 \u2286 U\u2081 \u2227 V\u2082 \u2286 U\u2082 \u2227 U\u2081 \u2229 U\u2082 = \u2205 :=\nbegin\n  rcases t2_separation h with \u27e8U\u2081, U\u2082, U\u2081_op, U\u2082_op, x_in, y_in, H\u27e9,\n  rcases nhds_is_closed (mem_nhds_sets U\u2081_op x_in) with \u27e8V\u2081, V\u2081_in, h\u2081, V\u2081_closed\u27e9,\n  rcases nhds_is_closed (mem_nhds_sets U\u2082_op y_in) with \u27e8V\u2082, V\u2082_in, h\u2082, V\u2082_closed\u27e9,\n  use [U\u2081, V\u2081, mem_sets_of_superset V\u2081_in h\u2081, V\u2081_in,\n       U\u2082, V\u2082, mem_sets_of_superset V\u2082_in h\u2082, V\u2082_in],\n  tauto\nend\n\nend regularity\n\nsection normality\n\n/-- A T\u2084 space, also known as a normal space (although this condition sometimes\n  omits T\u2082), is one in which for every pair of disjoint closed sets `C` and `D`,\n  there exist disjoint open sets containing `C` and `D` respectively. -/\nclass normal_space (\u03b1 : Type u) [topological_space \u03b1] extends t1_space \u03b1 : Prop :=\n(normal : \u2200 s t : set \u03b1, is_closed s \u2192 is_closed t \u2192 disjoint s t \u2192\n  \u2203 u v, is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 disjoint u v)\n\ntheorem normal_separation [normal_space \u03b1] {s t : set \u03b1}\n  (H1 : is_closed s) (H2 : is_closed t) (H3 : disjoint s t) :\n  \u2203 u v, is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 disjoint u v :=\nnormal_space.normal s t H1 H2 H3\n\ntheorem normal_exists_closure_subset [normal_space \u03b1] {s t : set \u03b1} (hs : is_closed s)\n  (ht : is_open t) (hst : s \u2286 t) :\n  \u2203 u, is_open u \u2227 s \u2286 u \u2227 closure u \u2286 t :=\nbegin\n  have : disjoint s t\u1d9c, from \u03bb x \u27e8hxs, hxt\u27e9, hxt (hst hxs),\n  rcases normal_separation hs (is_closed_compl_iff.2 ht) this\n    with \u27e8s', t', hs', ht', hss', htt', hs't'\u27e9,\n  refine \u27e8s', hs', hss',\n    subset.trans (closure_minimal _ (is_closed_compl_iff.2 ht')) (compl_subset_comm.1 htt')\u27e9,\n  exact \u03bb x hxs hxt, hs't' \u27e8hxs, hxt\u27e9\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance normal_space.regular_space [normal_space \u03b1] : regular_space \u03b1 :=\n{ regular := \u03bb s x hs hxs, let \u27e8u, v, hu, hv, hsu, hxv, huv\u27e9 :=\n    normal_separation hs is_closed_singleton\n      (\u03bb _ \u27e8hx, hy\u27e9, hxs $ mem_of_eq_of_mem (eq_of_mem_singleton hy).symm hx) in\n    \u27e8u, hu, hsu, filter.empty_in_sets_eq_bot.1 $ filter.mem_inf_sets.2\n      \u27e8v, mem_nhds_sets hv (singleton_subset_iff.1 hxv), u, filter.mem_principal_self u,\n        inter_comm u v \u25b8 huv\u27e9\u27e9 }\n\n-- We can't make this an instance because it could cause an instance loop.\nlemma normal_of_compact_t2 [compact_space \u03b1] [t2_space \u03b1] : normal_space \u03b1 :=\nbegin\n  refine \u27e8assume s t hs ht st, _\u27e9,\n  simp only [disjoint_iff],\n  exact compact_compact_separated hs.compact ht.compact st.eq_bot\nend\n\nend normality\n\n/-- In a compact t2 space, the connected component of a point equals the intersection of all\nits clopen neighbourhoods. -/\nlemma connected_component_eq_Inter_clopen [t2_space \u03b1] [compact_space \u03b1] {x : \u03b1} :\n  connected_component x = \u22c2 Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, Z :=\nbegin\n  apply eq_of_subset_of_subset connected_component_subset_Inter_clopen,\n  -- Reduce to showing that the clopen intersection is connected.\n  refine is_preconnected.subset_connected_component _ (mem_Inter.2 (\u03bb Z, Z.2.2)),\n  -- We do this by showing that any disjoint cover by two closed sets implies\n  -- that one of these closed sets must contain our whole thing.\n  -- To reduce to the case where the cover is disjoint on all of `\u03b1` we need that `s` is closed\n  have hs : @is_closed _ _inst_1 (\u22c2 (Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) :=\n    is_closed_Inter (\u03bb Z, Z.2.1.2),\n  rw (is_preconnected_iff_subset_of_fully_disjoint_closed hs),\n  intros a b ha hb hab ab_empty,\n  haveI := @normal_of_compact_t2 \u03b1 _ _ _,\n  -- Since our space is normal, we get two larger disjoint open sets containing the disjoint\n  -- closed sets. If we can show that our intersection is a subset of any of these we can then\n  -- \"descend\" this to show that it is a subset of either a or b.\n  rcases normal_separation ha hb (disjoint_iff.2 ab_empty) with \u27e8u, v, hu, hv, hau, hbv, huv\u27e9,\n  -- If we can find a clopen set around x, contained in u \u222a v, we get a disjoint decomposition\n  -- Z = Z \u2229 u \u222a Z \u2229 v of clopen sets. The intersection of all clopen neighbourhoods will then lie\n  -- in whichever of u or v x lies in and hence will be a subset of either a or b.\n  suffices : \u2203 (Z : set \u03b1), is_clopen Z \u2227 x \u2208 Z \u2227 Z \u2286 u \u222a v,\n  { cases this with Z H,\n    rw [disjoint_iff_inter_eq_empty] at huv,\n    have H1 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hu hv huv,\n    rw [union_comm] at H,\n    have H2 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hv hu (inter_comm u v \u25b8 huv),\n    by_cases (x \u2208 u),\n    -- The x \u2208 u case.\n    { left,\n      suffices : (\u22c2 (Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2286 u,\n      { rw \u2190set.disjoint_iff_inter_eq_empty at huv,\n        replace hab : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 a \u222a b := hab,\n        replace this : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 u := this,\n        exact disjoint.left_le_of_le_sup_right hab (huv.mono this hbv) },\n      { apply subset.trans _ (inter_subset_right Z u),\n        apply Inter_subset (\u03bb Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, \u2191Z)\n          \u27e8Z \u2229 u, H1, mem_inter H.2.1 h\u27e9 } },\n    -- If x \u2209 u, we get x \u2208 v since x \u2208 u \u222a v. The rest is then like the x \u2208 u case.\n    have h1 : x \u2208 v,\n    { cases (mem_union x u v).1 (mem_of_subset_of_mem (subset.trans hab\n        (union_subset_union hau hbv)) (mem_Inter.2 (\u03bb i, i.2.2))) with h1 h1,\n      { exfalso, exact h h1},\n      { exact h1} },\n    right,\n    suffices : (\u22c2 (Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2286 v,\n    { rw [inter_comm, \u2190set.disjoint_iff_inter_eq_empty] at huv,\n      replace hab : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 a \u222a b := hab,\n      replace this : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 v := this,\n      exact disjoint.left_le_of_le_sup_left hab (huv.mono this hau) },\n    { apply subset.trans _ (inter_subset_right Z v),\n      apply Inter_subset (\u03bb Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, \u2191Z)\n        \u27e8Z \u2229 v, H2, mem_inter H.2.1 h1\u27e9 } },\n  -- Now we find the required Z. We utilize the fact that X \\ u \u222a v will be compact,\n  -- so there must be some finite intersection of clopen neighbourhoods of X disjoint to it,\n  -- but a finite intersection of clopen sets is clopen so we let this be our Z.\n  have H1 := ((is_closed_compl_iff.2 (is_open_union hu hv)).compact.inter_Inter_nonempty\n    (\u03bb Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, Z) (\u03bb Z, Z.2.1.2)),\n  rw [\u2190not_imp_not, not_forall, not_nonempty_iff_eq_empty, inter_comm] at H1,\n  have huv_union := subset.trans hab (union_subset_union hau hbv),\n  rw [\u2190 compl_compl (u \u222a v), subset_compl_iff_disjoint] at huv_union,\n  cases H1 huv_union with Zi H2,\n  refine \u27e8(\u22c2 (U \u2208 Zi), subtype.val U), _, _, _\u27e9,\n  { exact is_clopen_bInter (\u03bb Z hZ, Z.2.1) },\n  { exact mem_bInter_iff.2 (\u03bb Z hZ, Z.2.2) },\n  { rwa [not_nonempty_iff_eq_empty, inter_comm, \u2190subset_compl_iff_disjoint, compl_compl] at H2 }\nend\n\nsection connected_component_setoid\nlocal attribute [instance] connected_component_setoid\n\n/-- `connected_components \u03b1` is Hausdorff when `\u03b1` is Hausdorff and compact -/\ninstance connected_components.t2 [t2_space \u03b1] [compact_space \u03b1] :\n  t2_space (connected_components \u03b1) :=\nbegin\n  -- Proof follows that of: https://stacks.math.columbia.edu/tag/0900\n  -- Fix 2 distinct connected components, with points a and b\n  refine \u27e8\u03bb x y, quotient.induction_on x (quotient.induction_on y (\u03bb a b ne, _))\u27e9,\n  rw connected_component_nrel_iff at ne,\n  have h := connected_component_disjoint ne,\n  -- write \u27e6b\u27e7 as the intersection of all clopen subsets containing it\n  rw [connected_component_eq_Inter_clopen, disjoint_iff_inter_eq_empty, inter_comm] at h,\n  -- Now we show that this can be reduced to some clopen containing \u27e6b\u27e7 being disjoint to \u27e6a\u27e7\n  cases is_closed_connected_component.compact.elim_finite_subfamily_closed _ _ h\n    with fin_a ha,\n  swap, { exact \u03bb Z, Z.2.1.2 },\n  set U : set \u03b1 := (\u22c2 (i : {Z // is_clopen Z \u2227 b \u2208 Z}) (H : i \u2208 fin_a), \u2191i) with hU,\n  rw \u2190hU at ha,\n  have hu_clopen : is_clopen U := is_clopen_bInter (\u03bb i j, i.2.1),\n  -- This clopen and its complement will separate the points corresponding to \u27e6a\u27e7 and \u27e6b\u27e7\n  use [quotient.mk '' U, quotient.mk '' U\u1d9c],\n  -- Using the fact that clopens are unions of connected components, we show that\n  -- U and U\u1d9c is the preimage of a clopen set in the quotient\n  have hu : quotient.mk \u207b\u00b9' (quotient.mk '' U) = U :=\n    (connected_components_preimage_image U \u25b8 eq.symm) hu_clopen.eq_union_connected_components,\n  have huc : quotient.mk \u207b\u00b9' (quotient.mk '' U\u1d9c) = U\u1d9c :=\n    (connected_components_preimage_image U\u1d9c \u25b8 eq.symm)\n      (is_clopen_compl hu_clopen).eq_union_connected_components,\n  -- showing that U and U\u1d9c are open and separates \u27e6a\u27e7 and \u27e6b\u27e7\n  refine \u27e8_,_,_,_,_\u27e9,\n  { rw [(quotient_map_iff.1 quotient_map_quotient_mk).2 _, hu],\n    exact hu_clopen.1 },\n  { rw [(quotient_map_iff.1 quotient_map_quotient_mk).2 _, huc],\n    exact is_open_compl_iff.2 hu_clopen.2 },\n  { exact mem_image_of_mem _ (mem_Inter.2 (\u03bb Z, mem_Inter.2 (\u03bb Zmem, Z.2.2))) },\n  { apply mem_image_of_mem,\n    exact mem_of_subset_of_mem (subset_compl_iff_disjoint.2 ha) (@mem_connected_component _ _ a) },\n  apply preimage_injective.2 (@surjective_quotient_mk _ _),\n  rw [preimage_inter, preimage_empty, hu, huc, inter_compl_self _],\nend\n\nend connected_component_setoid\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/topology/separation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.726847497867601}}
{"text": "/-\nCopyright (c) 2015 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Robert Y. Lewis\n-/\nimport algebra.ordered_ring\nimport algebra.group_power.basic\n\n/-!\n# Lemmas about the interaction of power operations with order\n\nNote that some lemmas are in `algebra/group_power/lemmas.lean` as they import files which\ndepend on this file.\n-/\n\nvariables {A R : Type*}\n\nsection add_monoid\nvariable [ordered_add_comm_monoid A]\n\ntheorem nsmul_nonneg {a : A} (H : 0 \u2264 a) : \u2200 n : \u2115, 0 \u2264 n \u2022 a\n| 0     := by rw [zero_nsmul]\n| (n+1) := by { rw succ_nsmul, exact add_nonneg H (nsmul_nonneg n) }\n\nlemma nsmul_pos {a : A} (ha : 0 < a) {k : \u2115} (hk : 0 < k) : 0 < k \u2022 a :=\nbegin\n  rcases nat.exists_eq_succ_of_ne_zero (ne_of_gt hk) with \u27e8l, rfl\u27e9,\n  clear hk,\n  induction l with l IH,\n  { simpa using ha },\n  { rw succ_nsmul,\n    exact add_pos ha IH }\nend\n\ntheorem nsmul_le_nsmul {a : A} {n m : \u2115} (ha : 0 \u2264 a) (h : n \u2264 m) : n \u2022 a \u2264 m \u2022 a :=\nlet \u27e8k, hk\u27e9 := nat.le.dest h in\ncalc n \u2022 a = n \u2022 a + 0 : (add_zero _).symm\n  ... \u2264 n \u2022 a + k \u2022 a : add_le_add_left (nsmul_nonneg ha _) _\n  ... = m \u2022 a : by rw [\u2190 hk, add_nsmul]\n\nlemma nsmul_le_nsmul_of_le_right {a b : A} (hab : a \u2264 b) : \u2200 i : \u2115, i \u2022 a \u2264 i \u2022 b\n| 0 := by simp [zero_nsmul]\n| (k+1) := by { rw [succ_nsmul, succ_nsmul], exact add_le_add hab (nsmul_le_nsmul_of_le_right _) }\n\nend add_monoid\n\nsection add_group\nvariable [ordered_add_comm_group A]\n\ntheorem gsmul_nonneg {a : A} (H : 0 \u2264 a) {n : \u2124} (hn : 0 \u2264 n) :\n  0 \u2264 n \u2022 a :=\nbegin\n  lift n to \u2115 using hn,\n  rw gsmul_coe_nat,\n  apply nsmul_nonneg H,\nend\n\nend add_group\n\nsection cancel_add_monoid\nvariable [ordered_cancel_add_comm_monoid A]\n\ntheorem nsmul_lt_nsmul {a : A} {n m : \u2115} (ha : 0 < a) (h : n < m) :\n  n \u2022 a < m \u2022 a :=\nlet \u27e8k, hk\u27e9 := nat.le.dest h in\nbegin\n  have succ_swap : n.succ + k = n + k.succ := nat.succ_add n k,\n  calc n \u2022 a = (n \u2022 a : A) + (0 : A) : (add_zero _).symm\n    ... < n \u2022 a + (k.succ \u2022 a : A) : add_lt_add_left (nsmul_pos ha (nat.succ_pos k)) _\n    ... = m \u2022 a : by rw [\u2190 hk, succ_swap, add_nsmul]\nend\n\nend cancel_add_monoid\n\nnamespace canonically_ordered_semiring\nvariable [canonically_ordered_comm_semiring R]\n\ntheorem pow_pos {a : R} (H : 0 < a) : \u2200 n : \u2115, 0 < a ^ n\n| 0     := by { nontriviality, rw pow_zero, exact canonically_ordered_semiring.zero_lt_one }\n| (n+1) := by { rw pow_succ, exact canonically_ordered_semiring.mul_pos.2 \u27e8H, pow_pos n\u27e9 }\n\n@[mono] lemma pow_le_pow_of_le_left {a b : R} (hab : a \u2264 b) : \u2200 i : \u2115, a^i \u2264 b^i\n| 0     := by simp\n| (k+1) := by { rw [pow_succ, pow_succ],\n    exact canonically_ordered_semiring.mul_le_mul hab (pow_le_pow_of_le_left k) }\n\ntheorem one_le_pow_of_one_le {a : R} (H : 1 \u2264 a) (n : \u2115) : 1 \u2264 a ^ n :=\nby simpa only [one_pow] using pow_le_pow_of_le_left H n\n\ntheorem pow_le_one {a : R} (H : a \u2264 1) (n : \u2115) : a ^ n \u2264 1:=\nby simpa only [one_pow] using pow_le_pow_of_le_left H n\n\nend canonically_ordered_semiring\n\nsection ordered_semiring\nvariable [ordered_semiring R]\n\n@[simp] theorem pow_pos {a : R} (H : 0 < a) : \u2200 (n : \u2115), 0 < a ^ n\n| 0     := by { nontriviality, rw pow_zero, exact zero_lt_one }\n| (n+1) := by { rw pow_succ, exact mul_pos H (pow_pos _) }\n\n@[simp] theorem pow_nonneg {a : R} (H : 0 \u2264 a) : \u2200 (n : \u2115), 0 \u2264 a ^ n\n| 0     := by { rw pow_zero, exact zero_le_one}\n| (n+1) := by { rw pow_succ, exact mul_nonneg H (pow_nonneg _) }\n\ntheorem pow_add_pow_le {x y : R} {n : \u2115} (hx : 0 \u2264 x) (hy : 0 \u2264 y) (hn : n \u2260 0) :\n  x ^ n + y ^ n \u2264 (x + y) ^ n :=\nbegin\n  rcases nat.exists_eq_succ_of_ne_zero hn with \u27e8k, rfl\u27e9,\n  induction k with k ih, { simp only [pow_one] },\n  let n := k.succ,\n  have h1 := add_nonneg (mul_nonneg hx (pow_nonneg hy n)) (mul_nonneg hy (pow_nonneg hx n)),\n  have h2 := add_nonneg hx hy,\n  calc x^n.succ + y^n.succ\n    \u2264 x*x^n + y*y^n + (x*y^n + y*x^n) :\n      by { rw [pow_succ _ n, pow_succ _ n], exact le_add_of_nonneg_right h1 }\n    ... = (x+y) * (x^n + y^n) :\n      by rw [add_mul, mul_add, mul_add, add_comm (y*x^n), \u2190 add_assoc,\n        \u2190 add_assoc, add_assoc (x*x^n) (x*y^n), add_comm (x*y^n) (y*y^n), \u2190 add_assoc]\n    ... \u2264 (x+y)^n.succ :\n      by { rw [pow_succ _ n], exact mul_le_mul_of_nonneg_left (ih (nat.succ_ne_zero k)) h2 }\nend\n\ntheorem pow_lt_pow_of_lt_left {x y : R} {n : \u2115} (Hxy : x < y) (Hxpos : 0 \u2264 x) (Hnpos : 0 < n) :\n  x ^ n < y ^ n :=\nbegin\n  cases lt_or_eq_of_le Hxpos,\n  { rw \u2190nat.sub_add_cancel Hnpos,\n    induction (n - 1), { simpa only [pow_one] },\n    rw [pow_add, pow_add, nat.succ_eq_add_one, pow_one, pow_one],\n    apply mul_lt_mul ih (le_of_lt Hxy) h (le_of_lt (pow_pos (lt_trans h Hxy) _)) },\n  { rw [\u2190h, zero_pow Hnpos], apply pow_pos (by rwa \u2190h at Hxy : 0 < y),}\nend\n\ntheorem strict_mono_incr_on_pow {n : \u2115} (hn : 0 < n) :\n  strict_mono_incr_on (\u03bb x : R, x ^ n) (set.Ici 0) :=\n\u03bb x hx y hy h, pow_lt_pow_of_lt_left h hx hn\n\ntheorem one_le_pow_of_one_le {a : R} (H : 1 \u2264 a) : \u2200 (n : \u2115), 1 \u2264 a ^ n\n| 0     := by rw [pow_zero]\n| (n+1) := by { rw pow_succ, simpa only [mul_one] using mul_le_mul H (one_le_pow_of_one_le n)\n    zero_le_one (le_trans zero_le_one H) }\n\nlemma pow_mono {a : R} (h : 1 \u2264 a) : monotone (\u03bb n : \u2115, a ^ n) :=\nmonotone_of_monotone_nat $ \u03bb n,\n  by { rw pow_succ, exact le_mul_of_one_le_left (pow_nonneg (zero_le_one.trans h) _) h }\n\ntheorem pow_le_pow {a : R} {n m : \u2115} (ha : 1 \u2264 a) (h : n \u2264 m) : a ^ n \u2264 a ^ m :=\npow_mono ha h\n\nlemma strict_mono_pow {a : R} (h : 1 < a) : strict_mono (\u03bb n : \u2115, a ^ n) :=\nhave 0 < a := zero_le_one.trans_lt h,\nstrict_mono.nat $ \u03bb n, by simpa only [one_mul, pow_succ]\n  using mul_lt_mul h (le_refl (a ^ n)) (pow_pos this _) this.le\n\nlemma pow_lt_pow {a : R} {n m : \u2115} (h : 1 < a) (h2 : n < m) : a ^ n < a ^ m :=\nstrict_mono_pow h h2\n\nlemma pow_lt_pow_iff {a : R} {n m : \u2115} (h : 1 < a) : a ^ n < a ^ m \u2194 n < m :=\n(strict_mono_pow h).lt_iff_lt\n\n@[mono] lemma pow_le_pow_of_le_left {a b : R} (ha : 0 \u2264 a) (hab : a \u2264 b) : \u2200 i : \u2115, a^i \u2264 b^i\n| 0     := by simp\n| (k+1) := by { rw [pow_succ, pow_succ],\n    exact mul_le_mul hab (pow_le_pow_of_le_left _) (pow_nonneg ha _) (le_trans ha hab) }\n\nend ordered_semiring\n\nsection linear_ordered_semiring\nvariable [linear_ordered_semiring R]\n\ntheorem pow_left_inj {x y : R} {n : \u2115} (Hxpos : 0 \u2264 x) (Hypos : 0 \u2264 y) (Hnpos : 0 < n)\n  (Hxyn : x ^ n = y ^ n) : x = y :=\n(@strict_mono_incr_on_pow R _ _ Hnpos).inj_on Hxpos Hypos Hxyn\n\nlemma lt_of_pow_lt_pow {a b : R} (n : \u2115) (hb : 0 \u2264 b) (h : a ^ n < b ^ n) : a < b :=\nlt_of_not_ge $ \u03bb hn, not_lt_of_ge (pow_le_pow_of_le_left hb hn _) h\n\nlemma le_of_pow_le_pow {a b : R} (n : \u2115) (hb : 0 \u2264 b) (hn : 0 < n) (h : a ^ n \u2264 b ^ n) : a \u2264 b :=\nle_of_not_lt $ \u03bb h1, not_le_of_lt (pow_lt_pow_of_lt_left h1 hb hn) h\n\nend linear_ordered_semiring\n\nsection linear_ordered_ring\n\nvariable [linear_ordered_ring R]\n\nlemma pow_abs (a : R) (n : \u2115) : (abs a) ^ n = abs (a ^ n) :=\n((abs_hom.to_monoid_hom : R \u2192* R).map_pow a n).symm\n\nlemma abs_neg_one_pow (n : \u2115) : abs ((-1 : R) ^ n) = 1 :=\nby rw [\u2190pow_abs, abs_neg, abs_one, one_pow]\n\ntheorem pow_bit0_nonneg (a : R) (n : \u2115) : 0 \u2264 a ^ bit0 n :=\nby { rw pow_bit0, exact mul_self_nonneg _ }\n\ntheorem sq_nonneg (a : R) : 0 \u2264 a ^ 2 :=\npow_bit0_nonneg a 1\n\nalias sq_nonneg \u2190 pow_two_nonneg\n\ntheorem pow_bit0_pos {a : R} (h : a \u2260 0) (n : \u2115) : 0 < a ^ bit0 n :=\n(pow_bit0_nonneg a n).lt_of_ne (pow_ne_zero _ h).symm\n\ntheorem sq_pos_of_ne_zero (a : R) (h : a \u2260 0) : 0 < a ^ 2 :=\npow_bit0_pos h 1\n\nalias sq_pos_of_ne_zero \u2190 pow_two_pos_of_ne_zero\n\nvariables {x y : R}\n\ntheorem sq_abs (x : R) : abs x ^ 2 = x ^ 2 :=\nby simpa only [sq] using abs_mul_abs_self x\n\ntheorem abs_sq (x : R) : abs (x ^ 2) = x ^ 2 :=\nby simpa only [sq] using abs_mul_self x\n\ntheorem sq_lt_sq (h : abs x < y) : x ^ 2 < y ^ 2 :=\nby simpa only [sq_abs] using pow_lt_pow_of_lt_left h (abs_nonneg x) (1:\u2115).succ_pos\n\ntheorem sq_lt_sq' (h1 : -y < x) (h2 : x < y) : x ^ 2 < y ^ 2 :=\nsq_lt_sq (abs_lt.mpr \u27e8h1, h2\u27e9)\n\ntheorem sq_le_sq (h : abs x \u2264 abs y) : x ^ 2 \u2264 y ^ 2 :=\nby simpa only [sq_abs] using pow_le_pow_of_le_left (abs_nonneg x) h 2\n\ntheorem sq_le_sq' (h1 : -y \u2264 x) (h2 : x \u2264 y) : x ^ 2 \u2264 y ^ 2 :=\nsq_le_sq (le_trans (abs_le.mpr \u27e8h1, h2\u27e9) (le_abs_self _))\n\ntheorem abs_lt_abs_of_sq_lt_sq (h : x^2 < y^2) : abs x < abs y :=\nlt_of_pow_lt_pow 2 (abs_nonneg y) $ by rwa [\u2190 sq_abs x, \u2190 sq_abs y] at h\n\ntheorem abs_lt_of_sq_lt_sq (h : x^2 < y^2) (hy : 0 \u2264 y) : abs x < y :=\nbegin\n  rw [\u2190 abs_of_nonneg hy],\n  exact abs_lt_abs_of_sq_lt_sq h,\nend\n\ntheorem abs_lt_of_sq_lt_sq' (h : x^2 < y^2) (hy : 0 \u2264 y) : -y < x \u2227 x < y :=\nabs_lt.mp $ abs_lt_of_sq_lt_sq h hy\n\ntheorem abs_le_abs_of_sq_le_sq (h : x^2 \u2264 y^2) : abs x \u2264 abs y :=\nle_of_pow_le_pow 2 (abs_nonneg y) (1:\u2115).succ_pos $ by rwa [\u2190 sq_abs x, \u2190 sq_abs y] at h\n\ntheorem abs_le_of_sq_le_sq (h : x^2 \u2264 y^2) (hy : 0 \u2264 y) : abs x \u2264 y :=\nbegin\n  rw [\u2190 abs_of_nonneg hy],\n  exact abs_le_abs_of_sq_le_sq h,\nend\n\ntheorem abs_le_of_sq_le_sq' (h : x^2 \u2264 y^2) (hy : 0 \u2264 y) : -y \u2264 x \u2227 x \u2264 y :=\nabs_le.mp $ abs_le_of_sq_le_sq h hy\n\nend linear_ordered_ring\n\nsection linear_ordered_comm_ring\nvariables [linear_ordered_comm_ring R]\n\n@[simp] lemma eq_of_sq_eq_sq {a b : R} (ha : 0 \u2264 a) (hb : 0 \u2264 b) : a ^ 2 = b ^ 2 \u2194 a = b :=\nbegin\n  refine \u27e8_, congr_arg _\u27e9,\n  intros h,\n  refine (eq_or_eq_neg_of_sq_eq_sq _ _ h).elim id _,\n  rintros rfl,\n  rw le_antisymm (neg_nonneg.mp ha) hb,\n  exact neg_zero\nend\n\n/-- Arithmetic mean-geometric mean (AM-GM) inequality for linearly ordered commutative rings. -/\nlemma two_mul_le_add_sq (a b : R) : 2 * a * b \u2264 a ^ 2 + b ^ 2 :=\nsub_nonneg.mp ((sub_add_eq_add_sub _ _ _).subst ((sub_sq a b).subst (sq_nonneg _)))\n\nalias two_mul_le_add_sq \u2190 two_mul_le_add_pow_two\n\nend linear_ordered_comm_ring\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/group_power/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7268474953556898}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module algebra.order.monoid.defs\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Order.Monoid.Lemmas\nimport Mathbin.Order.BoundedOrder\n\n/-!\n# Ordered monoids\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides the definitions of ordered monoids.\n\n-/\n\n\nopen Function\n\nuniverse u\n\nvariable {\u03b1 : Type u} {\u03b2 : Type _}\n\n#print OrderedCommMonoid /-\n/-- An ordered commutative monoid is a commutative monoid\nwith a partial order such that `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone)\n-/\n@[protect_proj]\nclass OrderedCommMonoid (\u03b1 : Type _) extends CommMonoid \u03b1, PartialOrder \u03b1 where\n  mul_le_mul_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b\n#align ordered_comm_monoid OrderedCommMonoid\n-/\n\n#print OrderedAddCommMonoid /-\n/-- An ordered (additive) commutative monoid is a commutative monoid\n  with a partial order such that `a \u2264 b \u2192 c + a \u2264 c + b` (addition is monotone)\n-/\n@[protect_proj]\nclass OrderedAddCommMonoid (\u03b1 : Type _) extends AddCommMonoid \u03b1, PartialOrder \u03b1 where\n  add_le_add_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b\n#align ordered_add_comm_monoid OrderedAddCommMonoid\n-/\n\nattribute [to_additive] OrderedCommMonoid\n\nsection OrderedInstances\n\n/- warning: ordered_comm_monoid.to_covariant_class_left -> OrderedCommMonoid.to_covariantClass_left is a dubious translation:\nlean 3 declaration is\n  forall (M : Type.{u1}) [_inst_1 : OrderedCommMonoid.{u1} M], CovariantClass.{u1, u1} M M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M (OrderedCommMonoid.toCommMonoid.{u1} M _inst_1)))))) (LE.le.{u1} M (Preorder.toLE.{u1} M (PartialOrder.toPreorder.{u1} M (OrderedCommMonoid.toPartialOrder.{u1} M _inst_1))))\nbut is expected to have type\n  forall (M : Type.{u1}) [_inst_1 : OrderedCommMonoid.{u1} M], CovariantClass.{u1, u1} M M (fun (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.104 : M) (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.106 : M) => HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M (OrderedCommMonoid.toCommMonoid.{u1} M _inst_1))))) x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.104 x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.106) (fun (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.119 : M) (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.121 : M) => LE.le.{u1} M (Preorder.toLE.{u1} M (PartialOrder.toPreorder.{u1} M (OrderedCommMonoid.toPartialOrder.{u1} M _inst_1))) x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.119 x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.121)\nCase conversion may be inaccurate. Consider using '#align ordered_comm_monoid.to_covariant_class_left OrderedCommMonoid.to_covariantClass_left\u2093'. -/\n@[to_additive]\ninstance OrderedCommMonoid.to_covariantClass_left (M : Type _) [OrderedCommMonoid M] :\n    CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)\n    where elim a b c bc := OrderedCommMonoid.mul_le_mul_left _ _ bc a\n#align ordered_comm_monoid.to_covariant_class_left OrderedCommMonoid.to_covariantClass_left\n#align ordered_add_comm_monoid.to_covariant_class_left OrderedAddCommMonoid.to_covariantClass_left\n\n/- warning: ordered_comm_monoid.to_covariant_class_right -> OrderedCommMonoid.to_covariantClass_right is a dubious translation:\nlean 3 declaration is\n  forall (M : Type.{u1}) [_inst_1 : OrderedCommMonoid.{u1} M], CovariantClass.{u1, u1} M M (Function.swap.{succ u1, succ u1, succ u1} M M (fun (\u1fb0 : M) (\u1fb0 : M) => M) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M (OrderedCommMonoid.toCommMonoid.{u1} M _inst_1))))))) (LE.le.{u1} M (Preorder.toLE.{u1} M (PartialOrder.toPreorder.{u1} M (OrderedCommMonoid.toPartialOrder.{u1} M _inst_1))))\nbut is expected to have type\n  forall (M : Type.{u1}) [_inst_1 : OrderedCommMonoid.{u1} M], CovariantClass.{u1, u1} M M (Function.swap.{succ u1, succ u1, succ u1} M M (fun (\u1fb0 : M) (\u1fb0 : M) => M) (fun (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.170 : M) (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.172 : M) => HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M (CommMonoid.toMonoid.{u1} M (OrderedCommMonoid.toCommMonoid.{u1} M _inst_1))))) x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.170 x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.172)) (fun (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.185 : M) (x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.187 : M) => LE.le.{u1} M (Preorder.toLE.{u1} M (PartialOrder.toPreorder.{u1} M (OrderedCommMonoid.toPartialOrder.{u1} M _inst_1))) x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.185 x._@.Mathlib.Algebra.Order.Monoid.Defs._hyg.187)\nCase conversion may be inaccurate. Consider using '#align ordered_comm_monoid.to_covariant_class_right OrderedCommMonoid.to_covariantClass_right\u2093'. -/\n/- This instance can be proven with `by apply_instance`.  However, `with_bot \u2115` does not\npick up a `covariant_class M M (function.swap (*)) (\u2264)` instance without it (see PR #7940). -/\n@[to_additive]\ninstance OrderedCommMonoid.to_covariantClass_right (M : Type _) [OrderedCommMonoid M] :\n    CovariantClass M M (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7) :=\n  covariant_swap_mul_le_of_covariant_mul_le M\n#align ordered_comm_monoid.to_covariant_class_right OrderedCommMonoid.to_covariantClass_right\n#align ordered_add_comm_monoid.to_covariant_class_right OrderedAddCommMonoid.to_covariantClass_right\n\n#print Mul.to_covariantClass_left /-\n/- This is not an instance, to avoid creating a loop in the type-class system: in a\n`left_cancel_semigroup` with a `partial_order`, assuming `covariant_class M M (*) (\u2264)` implies\n`covariant_class M M (*) (<)`, see `left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le`. -/\n@[to_additive]\ntheorem Mul.to_covariantClass_left (M : Type _) [Mul M] [PartialOrder M]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 < \u00b7)] : CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7) :=\n  \u27e8covariant_le_of_covariant_lt _ _ _ CovariantClass.elim\u27e9\n#align has_mul.to_covariant_class_left Mul.to_covariantClass_left\n#align has_add.to_covariant_class_left Add.to_covariantClass_left\n-/\n\n#print Mul.to_covariantClass_right /-\n/- This is not an instance, to avoid creating a loop in the type-class system: in a\n`right_cancel_semigroup` with a `partial_order`, assuming `covariant_class M M (swap (*)) (<)`\nimplies `covariant_class M M (swap (*)) (\u2264)`, see\n`right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le`. -/\n@[to_additive]\ntheorem Mul.to_covariantClass_right (M : Type _) [Mul M] [PartialOrder M]\n    [CovariantClass M M (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)] : CovariantClass M M (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7) :=\n  \u27e8covariant_le_of_covariant_lt _ _ _ CovariantClass.elim\u27e9\n#align has_mul.to_covariant_class_right Mul.to_covariantClass_right\n#align has_add.to_covariant_class_right Add.to_covariantClass_right\n-/\n\nend OrderedInstances\n\n/- warning: bit0_pos -> bit0_pos is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : OrderedAddCommMonoid.{u1} \u03b1] {a : \u03b1}, (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (OrderedAddCommMonoid.toPartialOrder.{u1} \u03b1 _inst_1))) (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (AddZeroClass.toHasZero.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 _inst_1))))))) a) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (OrderedAddCommMonoid.toPartialOrder.{u1} \u03b1 _inst_1))) (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (AddZeroClass.toHasZero.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 _inst_1))))))) (bit0.{u1} \u03b1 (AddZeroClass.toHasAdd.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 _inst_1)))) a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : OrderedAddCommMonoid.{u1} \u03b1] {a : \u03b1}, (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (OrderedAddCommMonoid.toPartialOrder.{u1} \u03b1 _inst_1))) (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (AddMonoid.toZero.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 _inst_1))))) a) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (OrderedAddCommMonoid.toPartialOrder.{u1} \u03b1 _inst_1))) (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (AddMonoid.toZero.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 _inst_1))))) (bit0.{u1} \u03b1 (AddZeroClass.toAdd.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 _inst_1)))) a))\nCase conversion may be inaccurate. Consider using '#align bit0_pos bit0_pos\u2093'. -/\ntheorem bit0_pos [OrderedAddCommMonoid \u03b1] {a : \u03b1} (h : 0 < a) : 0 < bit0 a :=\n  add_pos' h h\n#align bit0_pos bit0_pos\n\n#print LinearOrderedAddCommMonoid /-\n/-- A linearly ordered additive commutative monoid. -/\n@[protect_proj]\nclass LinearOrderedAddCommMonoid (\u03b1 : Type _) extends LinearOrder \u03b1, OrderedAddCommMonoid \u03b1\n#align linear_ordered_add_comm_monoid LinearOrderedAddCommMonoid\n-/\n\n#print LinearOrderedCommMonoid /-\n/-- A linearly ordered commutative monoid. -/\n@[protect_proj, to_additive]\nclass LinearOrderedCommMonoid (\u03b1 : Type _) extends LinearOrder \u03b1, OrderedCommMonoid \u03b1\n#align linear_ordered_comm_monoid LinearOrderedCommMonoid\n#align linear_ordered_add_comm_monoid LinearOrderedAddCommMonoid\n-/\n\n#print LinearOrderedAddCommMonoidWithTop /-\n/-- A linearly ordered commutative monoid with an additively absorbing `\u22a4` element.\n  Instances should include number systems with an infinite element adjoined.` -/\n@[protect_proj]\nclass LinearOrderedAddCommMonoidWithTop (\u03b1 : Type _) extends LinearOrderedAddCommMonoid \u03b1,\n  Top \u03b1 where\n  le_top : \u2200 x : \u03b1, x \u2264 \u22a4\n  top_add' : \u2200 x : \u03b1, \u22a4 + x = \u22a4\n#align linear_ordered_add_comm_monoid_with_top LinearOrderedAddCommMonoidWithTop\n-/\n\n#print LinearOrderedAddCommMonoidWithTop.toOrderTop /-\n-- see Note [lower instance priority]\ninstance (priority := 100) LinearOrderedAddCommMonoidWithTop.toOrderTop (\u03b1 : Type u)\n    [h : LinearOrderedAddCommMonoidWithTop \u03b1] : OrderTop \u03b1 :=\n  { h with }\n#align linear_ordered_add_comm_monoid_with_top.to_order_top LinearOrderedAddCommMonoidWithTop.toOrderTop\n-/\n\nsection LinearOrderedAddCommMonoidWithTop\n\nvariable [LinearOrderedAddCommMonoidWithTop \u03b1] {a b : \u03b1}\n\n/- warning: top_add -> top_add is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrderedAddCommMonoidWithTop.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (HAdd.hAdd.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHAdd.{u1} \u03b1 (AddZeroClass.toHasAdd.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoid.toOrderedAddCommMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toLinearOrderedAddCommMonoid.{u1} \u03b1 _inst_1))))))) (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toHasTop.{u1} \u03b1 _inst_1)) a) (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toHasTop.{u1} \u03b1 _inst_1))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrderedAddCommMonoidWithTop.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (HAdd.hAdd.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHAdd.{u1} \u03b1 (AddZeroClass.toAdd.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toLinearOrderedAddCommMonoid.{u1} \u03b1 _inst_1)))))) (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toTop.{u1} \u03b1 _inst_1)) a) (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toTop.{u1} \u03b1 _inst_1))\nCase conversion may be inaccurate. Consider using '#align top_add top_add\u2093'. -/\n@[simp]\ntheorem top_add (a : \u03b1) : \u22a4 + a = \u22a4 :=\n  LinearOrderedAddCommMonoidWithTop.top_add' a\n#align top_add top_add\n\n/- warning: add_top -> add_top is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrderedAddCommMonoidWithTop.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (HAdd.hAdd.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHAdd.{u1} \u03b1 (AddZeroClass.toHasAdd.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (OrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoid.toOrderedAddCommMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toLinearOrderedAddCommMonoid.{u1} \u03b1 _inst_1))))))) a (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toHasTop.{u1} \u03b1 _inst_1))) (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toHasTop.{u1} \u03b1 _inst_1))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrderedAddCommMonoidWithTop.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (HAdd.hAdd.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHAdd.{u1} \u03b1 (AddZeroClass.toAdd.{u1} \u03b1 (AddMonoid.toAddZeroClass.{u1} \u03b1 (AddCommMonoid.toAddMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoid.toAddCommMonoid.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toLinearOrderedAddCommMonoid.{u1} \u03b1 _inst_1)))))) a (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toTop.{u1} \u03b1 _inst_1))) (Top.top.{u1} \u03b1 (LinearOrderedAddCommMonoidWithTop.toTop.{u1} \u03b1 _inst_1))\nCase conversion may be inaccurate. Consider using '#align add_top add_top\u2093'. -/\n@[simp]\ntheorem add_top (a : \u03b1) : a + \u22a4 = \u22a4 :=\n  trans (add_comm _ _) (top_add _)\n#align add_top add_top\n\nend LinearOrderedAddCommMonoidWithTop\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Order/Monoid/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7268474910855846}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# Lattices\n\nIn a *linear* order like \u211d, any two elements have\na min and a max. Using fancier language, if `x` and `y`\nare real numbers, then the set `{x,y}` has a least upper\nbound or supremum (namely `max x y`) and an infimum\n(namely `min x y`).\n\nBut partial orders can be pretty general objects. Consider\nfor example the partial order with the following four\nelements (all subsets of \u2115):\n\na={1}\nb={2}\nc={1,2,3}\nd={1,2,4}\n\nThis is a partial order, with the ordering given by `\u2286`.\nNote that `a \u2270 b` and `b \u2270 a`, so `max a b` doesn't seem\nto make any sense. But what about `Sup {a, b}`? Well, \nWe have `a \u2264 c` and `b \u2264 c`, and also `a \u2264 d` and `b \u2264 d`.\nSo both `c` and `d` are upper bounds for the set `{a,b}`,\nbut neither of them are *least* upper bounds, because\n`c \u2270 d` and `d \u2270 c`, so neither `c` nor `d` satisfy\nthe least upper bound axiom (they are not `\u2264` all other upper\nbounds). \n\nA *lattice* is a partial order where any two elements\nhave a least upper bound and a greatest lower bound. So\nthe example `{a,b,c,d}` above is a partial order but not\na lattice. \n\nNotation: if `L` is a lattice, and if `a : L` and `b : L`\nthen their least upper bound is denoted by `a \u2294 b` and\ntheir greatest lower bound is denoted by `a \u2293 b`. Hover\nover these symbols in VS Code to see how to type them\nin Lean.\n\nA nice example of a lattice is the subsets of\na type, ordered by `\u2286`. In this example the least upper\nbound of subsets `a` and `b` is `a \u222a b`, and the greatest\nlower bound is `a \u2229 b`. \n\nAn example which requires a little more thought is the\nlattice of subspaces of a vector spaces. If `V` and `W` are subspaces\nof `U` then their greatest lower bound `V \u2293 W` is just `V \u2229 W`, which\nis also a subspace. However their least upper bound is not so simple,\nbecause `V \u222a W` is in general not a vector space.\nThe least upper bound is supposed to be the smallest subspace\ncontaining `V` and `W`, so in this case `V \u2294 W` is the subspace\n`V + W` generated by `V` and `W`.\n\nAnother example is subgroups of a group. We'll talk about subgroups and subspaces\nlater on;  for now let's talk about the general theory of lattices. \nThe API you need to know is:\n\n`a \u2294 b` is the least upper bound of `a` and `b`:\n`le_sup_left : a \u2264 a \u2294 b`\n`le_sup_right : b \u2264 a \u2294 b`\n`sup_le : a \u2264 c \u2192 b \u2264 c \u2192 a \u2294 b \u2264 c`\n\n`a \u2293 b` is the greatest lower bound of `a` and `b`:\n`inf_le_left : a \u2293 b \u2264 a`\n`inf_le_right : a \u2293 b \u2264 b`\n`le_inf : a \u2264 b \u2192 a \u2264 c \u2192 a \u2264 b \u2293 c`\n\nUsing these axioms, see if you can develop the basic theory of lattices.\n\n-/\n\n-- let L be a lattice, and let a,b,c be elements of L\nvariables (L : Type) [lattice L] (a b c : L)\n\nexample : a \u2294 b = b \u2294 a :=\nbegin\n  -- you might want to start with `apply le_antisymm`.\n  -- You'll then have two goals so put them both in `{ }`s\n  -- and remember to indent two more spaces\n  sorry\nend\n\nexample : (a \u2294 b) \u2294 c = a \u2294 (b \u2294 c) :=\nbegin\n  sorry\nend\n\n-- `a \u2293 _` preserves `\u2264`.\n-- Note: this is called `inf_le_inf_left a h` in mathlib; see if you can prove it\n-- directly without using this.\nexample (h : b \u2264 c) : a \u2293 b \u2264 a \u2293 c :=\nbegin\n  sorry\nend\n\n/-\n\nWe all know that multiplication \"distributes\" over addition, i.e. `p*(q+r)=p*q+p*r`,\nbut of course addition does not distribute over multiplication (`p+(q*r)\u2260(p+q)*(p+r)`).\nIn sets (rather surprisingly, in my view), \u2229 distributes over \u222a and \u222a also\ndistributes over \u2229! However this is not true in more general lattices. For example,\nif `U`, `V` and `W` are three distinct lines in `\u211d\u00b2` then `U \u2229 (V + W) = U`\nwhereas `U \u2229 V + U \u2229 W = 0`, and `U + (V \u2229 W) = U \u2260 (U + V) \u2229 (U + W) = \u211d\u00b2`. We\ndo have inclusions though, which is what you can prove in general.\n\n-/\n\n-- `inf_le_inf_left`, proved above, is helpful here.\nexample : (a \u2293 b) \u2294 (a \u2293 c) \u2264 a \u2293 (b \u2294 c) :=\nbegin\n  sorry\nend\n\n-- use `sup_le_sup_left` for this one.\nexample : a \u2294 (b \u2293 c) \u2264 (a \u2294 b) \u2293 (a \u2294 c) :=\nbegin\n  sorry\nend\n\n-- Bonus question: look up the binding powers of \u2293 and \u2294 and figure out which brackets\n-- can be removed in the statements of the previous two examples without changing\n-- their meaning.", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section06orderings_and_lattices/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.72682520969689}}
{"text": "-- Traza_de_reescrituras.lean\n-- Traza de reescrituras\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 10 de agosto de 2021\n-- ---------------------------------------------------------------------\n\nimport tactic\n\nset_option trace.simplify.rewrite true\n\nexample (a b n m : \u2115): (a + b) * (n + m) = a * n + a * m  + b * n + b * m :=\nbegin\n  simp [mul_add, add_assoc, add_mul], -- succeeds\nend\n\n-- Escribe\n--    0. [simplify.rewrite] [add_mul]: (a + b) * (n + m) ==> a * (n + m) + b * (n + m)\n--    0. [simplify.rewrite] [mul_add]: a * (n + m) ==> a * n + a * m\n--    0. [simplify.rewrite] [mul_add]: b * (n + m) ==> b * n + b * m\n--    0. [simplify.rewrite] [add_assoc]: a * n + a * m + (b * n + b * m) ==> a * n + (a * m + (b * n + b * m))\n--    0. [simplify.rewrite] [add_assoc]: a * n + a * m + b * n ==> a * n + (a * m + b * n)\n--    0. [simplify.rewrite] [add_assoc]: a * n + (a * m + b * n) + b * m ==> a * n + (a * m + b * n + b * m)\n--    0. [simplify.rewrite] [add_assoc]: a * m + b * n + b * m ==> a * m + (b * n + b * m)\n--    0. [simplify.rewrite] [add_left_inj]: a * n + (a * m + (b * n + b * m))\n--                                          = a * n + (a * m + (b * n + b * m)) ==> a * n = a * n\n--    0. [simplify.rewrite] [mul_eq_mul_left_iff]: a * n = a * n ==> n = n \u2228 a = 0\n--    0. [simplify.rewrite] [eq_self_iff_true]: n = n ==> true\n--    0. [simplify.rewrite] [true_or]: true \u2228 a = 0 ==> true\n\nexample (a b n m : \u2115): (a + b) * (n + m) = a * n + a * m  + b * n + b * m :=\nbegin\n  simp [add_mul, mul_add, add_assoc], -- fails\n  sorry\nend\n\n-- Escribe:\n--    0. [simplify.rewrite] [mul_add]: (a + b) * (n + m) ==> (a + b) * n + (a + b) * m\n--    0. [simplify.rewrite] [add_mul]: (a + b) * n ==> a * n + b * n\n--    0. [simplify.rewrite] [add_mul]: (a + b) * m ==> a * m + b * m\n--    0. [simplify.rewrite] [add_assoc]: a * n + b * n + (a * m + b * m) ==> a * n + (b * n + (a * m + b * m))\n--    0. [simplify.rewrite] [add_assoc]: a * n + a * m + b * n ==> a * n + (a * m + b * n)\n--    0. [simplify.rewrite] [add_assoc]: a * n + (a * m + b * n) + b * m ==> a * n + (a * m + b * n + b * m)\n--    0. [simplify.rewrite] [add_assoc]: a * m + b * n + b * m ==> a * m + (b * n + b * m)\n--    0. [simplify.rewrite] [add_right_inj]: a * n + (b * n + (a * m + b * m)) =\n--                                           a * n + (a * m + (b * n + b * m)) ==>\n--                                           b * n + (a * m + b * m) = a * m + (b * n + b * m)\n\nexample (a b n m : \u2115): (a + b) * (n + m) = a * n + a * m  + b * n + b * m :=\nbegin\n  simp [mul_add, add_assoc, add_mul, add_left_comm], -- succeeds\nend\n\nexample (a b n m : \u2115): (a + b) * (n + m) = a * n + a * m  + b * n + b * m :=\nbegin\n  simp [add_mul, mul_add, add_assoc, add_left_comm], -- succeeds\nend\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Traza_de_reescrituras.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7268252046356657}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n\n! This file was ported from Lean 3 source module group_theory.submonoid.centralizer\n! leanprover-community/mathlib commit 44b58b42794e5abe2bf86397c38e26b587e07e59\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.GroupTheory.Subsemigroup.Centralizer\nimport Mathlib.GroupTheory.Submonoid.Center\n\n/-!\n# Centralizers of magmas and monoids\n\n## Main definitions\n\n* `Submonoid.centralizer`: the centralizer of a subset of a monoid\n* `AddSubmonoid.centralizer`: the centralizer of a subset of an additive monoid\n\nWe provide `Subgroup.centralizer`, `AddSubgroup.centralizer` in other files.\n-/\n\n\nvariable {M : Type _} {S T : Set M}\n\nnamespace Submonoid\n\nsection\n\nvariable [Monoid M] (S)\n\n/-- The centralizer of a subset of a monoid `M`. -/\n@[to_additive \"The centralizer of a subset of an additive monoid.\"]\ndef centralizer : Submonoid M where\n  carrier := S.centralizer\n  one_mem' := S.one_mem_centralizer\n  mul_mem' := Set.mul_mem_centralizer\n#align submonoid.centralizer Submonoid.centralizer\n#align add_submonoid.centralizer AddSubmonoid.centralizer\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_centralizer : \u2191(centralizer S) = S.centralizer :=\n  rfl\n#align submonoid.coe_centralizer Submonoid.coe_centralizer\n#align add_submonoid.coe_centralizer AddSubmonoid.coe_centralizer\n\ntheorem centralizer_toSubsemigroup : (centralizer S).toSubsemigroup = Subsemigroup.centralizer S :=\n  rfl\n#align submonoid.centralizer_to_subsemigroup Submonoid.centralizer_toSubsemigroup\n\ntheorem _root_.AddSubmonoid.centralizer_toAddSubsemigroup {M} [AddMonoid M] (S : Set M) :\n    (AddSubmonoid.centralizer S).toAddSubsemigroup = AddSubsemigroup.centralizer S :=\n  rfl\n#align add_submonoid.centralizer_to_add_subsemigroup AddSubmonoid.centralizer_toAddSubsemigroup\n\nattribute [to_additive existing AddSubmonoid.centralizer_toAddSubsemigroup]\n  Submonoid.centralizer_toSubsemigroup\n\nvariable {S}\n\n@[to_additive]\ntheorem mem_centralizer_iff {z : M} : z \u2208 centralizer S \u2194 \u2200 g \u2208 S, g * z = z * g :=\n  Iff.rfl\n#align submonoid.mem_centralizer_iff Submonoid.mem_centralizer_iff\n#align add_submonoid.mem_centralizer_iff AddSubmonoid.mem_centralizer_iff\n\n@[to_additive]\ninstance decidableMemCentralizer (a) [Decidable <| \u2200 b \u2208 S, b * a = a * b] :\n    Decidable (a \u2208 centralizer S) :=\n  decidable_of_iff' _ mem_centralizer_iff\n#align submonoid.decidable_mem_centralizer Submonoid.decidableMemCentralizer\n#align add_submonoid.decidable_mem_centralizer AddSubmonoid.decidableMemCentralizer\n\n@[to_additive]\ntheorem centralizer_le (h : S \u2286 T) : centralizer T \u2264 centralizer S :=\n  Set.centralizer_subset h\n#align submonoid.centralizer_le Submonoid.centralizer_le\n#align add_submonoid.centralizer_le AddSubmonoid.centralizer_le\n\nvariable (M)\n\n@[to_additive (attr := simp)]\ntheorem centralizer_univ : centralizer Set.univ = center M :=\n  SetLike.ext' (Set.centralizer_univ M)\n#align submonoid.centralizer_univ Submonoid.centralizer_univ\n#align add_submonoid.centralizer_univ AddSubmonoid.centralizer_univ\n\nend\n\nend Submonoid\n\n-- Porting note: `assert_not_exists` not implemented yet\n-- Guard against import creep\n--assert_not_exists finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/Submonoid/Centralizer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064587, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7268252030780071}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth, Yury Kudryashov\n\n! This file was ported from Lean 3 source module topology.algebra.order.monotone_convergence\n! leanprover-community/mathlib commit 4c19a16e4b705bf135cf9a80ac18fcc99c438514\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.Order.Basic\n\n/-!\n# Bounded monotone sequences converge\n\nIn this file we prove a few theorems of the form \u201cif the range of a monotone function `f : \u03b9 \u2192 \u03b1`\nadmits a least upper bound `a`, then `f x` tends to `a` as `x \u2192 \u221e`\u201d, as well as version of this\nstatement for (conditionally) complete lattices that use `\u2a06 x, f x` instead of `IsLUB`.\n\nThese theorems work for linear orders with order topologies as well as their products (both in terms\nof `Prod` and in terms of function types). In order to reduce code duplication, we introduce two\ntypeclasses (one for the property formulated above and one for the dual property), prove theorems\nassuming one of these typeclasses, and provide instances for linear orders and their products.\n\nWe also prove some \"inverse\" results: if `f n` is a monotone sequence and `a` is its limit,\nthen `f n \u2264 a` for all `n`.\n\n## Tags\n\nmonotone convergence\n-/\n\n\nopen Filter Set Function\n\nopen Filter Topology Classical\n\nvariable {\u03b1 \u03b2 : Type _}\n\n/-- We say that `\u03b1` is a `SupConvergenceClass` if the following holds. Let `f : \u03b9 \u2192 \u03b1` be a\nmonotone function, let `a : \u03b1` be a least upper bound of `Set.range f`. Then `f x` tends to `\ud835\udcdd a`\n as `x \u2192 \u221e` (formally, at the filter `Filter.atTop`). We require this for `\u03b9 = (s : Set \u03b1)`,\n`f = CoeTC.coe` in the definition, then prove it for any `f` in `tendsto_atTop_isLUB`.\n\nThis property holds for linear orders with order topology as well as their products. -/\nclass SupConvergenceClass (\u03b1 : Type _) [Preorder \u03b1] [TopologicalSpace \u03b1] : Prop where\n  /-- proof that a monotone function tends to `\ud835\udcdd a` as `x \u2192 \u221e` -/\n  tendsto_coe_atTop_isLUB :\n    \u2200 (a : \u03b1) (s : Set \u03b1), IsLUB s a \u2192 Tendsto (CoeTC.coe : s \u2192 \u03b1) atTop (\ud835\udcdd a)\n#align Sup_convergence_class SupConvergenceClass\n\n/-- We say that `\u03b1` is an `InfConvergenceClass` if the following holds. Let `f : \u03b9 \u2192 \u03b1` be a\nmonotone function, let `a : \u03b1` be a greatest lower bound of `Set.range f`. Then `f x` tends to `\ud835\udcdd a`\nas `x \u2192 -\u221e` (formally, at the filter `Filter.atBot`). We require this for `\u03b9 = (s : Set \u03b1)`,\n`f = CoeTC.coe` in the definition, then prove it for any `f` in `tendsto_atBot_isGLB`.\n\nThis property holds for linear orders with order topology as well as their products. -/\nclass InfConvergenceClass (\u03b1 : Type _) [Preorder \u03b1] [TopologicalSpace \u03b1] : Prop where\n  /-- proof that a monotone function tends to `\ud835\udcdd a` as `x \u2192 -\u221e`-/\n  tendsto_coe_atBot_isGLB :\n    \u2200 (a : \u03b1) (s : Set \u03b1), IsGLB s a \u2192 Tendsto (CoeTC.coe : s \u2192 \u03b1) atBot (\ud835\udcdd a)\n#align Inf_convergence_class InfConvergenceClass\n\ninstance OrderDual.supConvergenceClass [Preorder \u03b1] [TopologicalSpace \u03b1] [InfConvergenceClass \u03b1] :\n    SupConvergenceClass \u03b1\u1d52\u1d48 :=\n  \u27e8\u2039InfConvergenceClass \u03b1\u203a.1\u27e9\n#align order_dual.Sup_convergence_class OrderDual.supConvergenceClass\n\ninstance OrderDual.infConvergenceClass [Preorder \u03b1] [TopologicalSpace \u03b1] [SupConvergenceClass \u03b1] :\n    InfConvergenceClass \u03b1\u1d52\u1d48 :=\n  \u27e8\u2039SupConvergenceClass \u03b1\u203a.1\u27e9\n#align order_dual.Inf_convergence_class OrderDual.infConvergenceClass\n\n-- see Note [lower instance priority]\ninstance (priority := 100) LinearOrder.supConvergenceClass [TopologicalSpace \u03b1] [LinearOrder \u03b1]\n    [OrderTopology \u03b1] : SupConvergenceClass \u03b1 := by\n  refine' \u27e8fun a s ha => tendsto_order.2 \u27e8fun b hb => _, fun b hb => _\u27e9\u27e9\n  \u00b7 rcases ha.exists_between hb with \u27e8c, hcs, bc, bca\u27e9\n    lift c to s using hcs\n    refine' (eventually_ge_atTop c).mono fun x hx => bc.trans_le hx\n  \u00b7 exact eventually_of_forall fun x => (ha.1 x.2).trans_lt hb\n#align linear_order.Sup_convergence_class LinearOrder.supConvergenceClass\n\n-- see Note [lower instance priority]\ninstance (priority := 100) LinearOrder.infConvergenceClass [TopologicalSpace \u03b1] [LinearOrder \u03b1]\n    [OrderTopology \u03b1] : InfConvergenceClass \u03b1 :=\n  show InfConvergenceClass \u03b1\u1d52\u1d48\u1d52\u1d48 from OrderDual.infConvergenceClass\n#align linear_order.Inf_convergence_class LinearOrder.infConvergenceClass\n\nsection\n\nvariable {\u03b9 : Type _} [Preorder \u03b9] [TopologicalSpace \u03b1]\n\nsection IsLUB\n\nvariable [Preorder \u03b1] [SupConvergenceClass \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem tendsto_atTop_isLUB (h_mono : Monotone f) (ha : IsLUB (Set.range f) a) :\n    Tendsto f atTop (\ud835\udcdd a) := by\n  suffices : Tendsto (rangeFactorization f) atTop atTop\n  exact (SupConvergenceClass.tendsto_coe_atTop_isLUB _ _ ha).comp this\n  exact h_mono.rangeFactorization.tendsto_atTop_atTop fun b => b.2.imp fun a ha => ha.ge\n#align tendsto_at_top_is_lub tendsto_atTop_isLUB\n\ntheorem tendsto_atBot_isLUB (h_anti : Antitone f) (ha : IsLUB (Set.range f) a) :\n    Tendsto f atBot (\ud835\udcdd a) := by convert tendsto_atTop_isLUB h_anti.dual_left ha using 1\n#align tendsto_at_bot_is_lub tendsto_atBot_isLUB\n\nend IsLUB\n\nsection IsGLB\n\nvariable [Preorder \u03b1] [InfConvergenceClass \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem tendsto_atBot_isGLB (h_mono : Monotone f) (ha : IsGLB (Set.range f) a) :\n    Tendsto f atBot (\ud835\udcdd a) := by convert tendsto_atTop_isLUB h_mono.dual ha.dual using 1\n#align tendsto_at_bot_is_glb tendsto_atBot_isGLB\n\ntheorem tendsto_atTop_isGLB (h_anti : Antitone f) (ha : IsGLB (Set.range f) a) :\n    Tendsto f atTop (\ud835\udcdd a) := by convert tendsto_atBot_isLUB h_anti.dual ha.dual using 1\n#align tendsto_at_top_is_glb tendsto_atTop_isGLB\n\nend IsGLB\n\nsection Csup\u1d62\n\nvariable [ConditionallyCompleteLattice \u03b1] [SupConvergenceClass \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem tendsto_atTop_csup\u1d62 (h_mono : Monotone f) (hbdd : BddAbove <| range f) :\n    Tendsto f atTop (\ud835\udcdd (\u2a06 i, f i)) := by\n  cases isEmpty_or_nonempty \u03b9\n  exacts[tendsto_of_isEmpty, tendsto_atTop_isLUB h_mono (isLUB_csup\u1d62 hbdd)]\n#align tendsto_at_top_csupr tendsto_atTop_csup\u1d62\n\ntheorem tendsto_atBot_csup\u1d62 (h_anti : Antitone f) (hbdd : BddAbove <| range f) :\n    Tendsto f atBot (\ud835\udcdd (\u2a06 i, f i)) := by convert tendsto_atTop_csup\u1d62 h_anti.dual hbdd.dual using 1\n#align tendsto_at_bot_csupr tendsto_atBot_csup\u1d62\n\nend Csup\u1d62\n\nsection Cinf\u1d62\n\nvariable [ConditionallyCompleteLattice \u03b1] [InfConvergenceClass \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem tendsto_atBot_cinf\u1d62 (h_mono : Monotone f) (hbdd : BddBelow <| range f) :\n    Tendsto f atBot (\ud835\udcdd (\u2a05 i, f i)) := by convert tendsto_atTop_csup\u1d62 h_mono.dual hbdd.dual using 1\n#align tendsto_at_bot_cinfi tendsto_atBot_cinf\u1d62\n\ntheorem tendsto_atTop_cinf\u1d62 (h_anti : Antitone f) (hbdd : BddBelow <| range f) :\n    Tendsto f atTop (\ud835\udcdd (\u2a05 i, f i)) := by convert tendsto_atBot_csup\u1d62 h_anti.dual hbdd.dual using 1\n#align tendsto_at_top_cinfi tendsto_atTop_cinf\u1d62\n\nend Cinf\u1d62\n\nsection sup\u1d62\n\nvariable [CompleteLattice \u03b1] [SupConvergenceClass \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem tendsto_atTop_sup\u1d62 (h_mono : Monotone f) : Tendsto f atTop (\ud835\udcdd (\u2a06 i, f i)) :=\n  tendsto_atTop_csup\u1d62 h_mono (OrderTop.bddAbove _)\n#align tendsto_at_top_supr tendsto_atTop_sup\u1d62\n\ntheorem tendsto_atBot_sup\u1d62 (h_anti : Antitone f) : Tendsto f atBot (\ud835\udcdd (\u2a06 i, f i)) :=\n  tendsto_atBot_csup\u1d62 h_anti (OrderTop.bddAbove _)\n#align tendsto_at_bot_supr tendsto_atBot_sup\u1d62\n\nend sup\u1d62\n\nsection inf\u1d62\n\nvariable [CompleteLattice \u03b1] [InfConvergenceClass \u03b1] {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem tendsto_atBot_inf\u1d62 (h_mono : Monotone f) : Tendsto f atBot (\ud835\udcdd (\u2a05 i, f i)) :=\n  tendsto_atBot_cinf\u1d62 h_mono (OrderBot.bddBelow _)\n#align tendsto_at_bot_infi tendsto_atBot_inf\u1d62\n\ntheorem tendsto_atTop_inf\u1d62 (h_anti : Antitone f) : Tendsto f atTop (\ud835\udcdd (\u2a05 i, f i)) :=\n  tendsto_atTop_cinf\u1d62 h_anti (OrderBot.bddBelow _)\n#align tendsto_at_top_infi tendsto_atTop_inf\u1d62\n\nend inf\u1d62\n\nend\n\ninstance supConvergenceClassProd [Preorder \u03b1] [Preorder \u03b2] [TopologicalSpace \u03b1] [TopologicalSpace \u03b2]\n  [SupConvergenceClass \u03b1] [SupConvergenceClass \u03b2] : SupConvergenceClass (\u03b1 \u00d7 \u03b2) := by\n  constructor\n  rintro \u27e8a, b\u27e9 s h\n  rw [isLUB_prod, \u2190 range_restrict, \u2190 range_restrict] at h\n  have A : Tendsto (fun x : s => (x : \u03b1 \u00d7 \u03b2).1) atTop (\ud835\udcdd a) :=\n    tendsto_atTop_isLUB (monotone_fst.restrict s) h.1\n  have B : Tendsto (fun x : s => (x : \u03b1 \u00d7 \u03b2).2) atTop (\ud835\udcdd b) :=\n    tendsto_atTop_isLUB (monotone_snd.restrict s) h.2\n  convert A.prod_mk_nhds B\n  -- porting note: previously required below to close\n  -- ext1 \u27e8\u27e8x, y\u27e9, h\u27e9\n  -- rfl\n\ninstance [Preorder \u03b1] [Preorder \u03b2] [TopologicalSpace \u03b1] [TopologicalSpace \u03b2] [InfConvergenceClass \u03b1]\n    [InfConvergenceClass \u03b2] : InfConvergenceClass (\u03b1 \u00d7 \u03b2) :=\n  show InfConvergenceClass (\u03b1\u1d52\u1d48 \u00d7 \u03b2\u1d52\u1d48)\u1d52\u1d48 from OrderDual.infConvergenceClass\n\ninstance Pi.supConvergenceClass\n    {\u03b9 : Type _} {\u03b1 : \u03b9 \u2192 Type _} [\u2200 i, Preorder (\u03b1 i)] [\u2200 i, TopologicalSpace (\u03b1 i)]\n    [\u2200 i, SupConvergenceClass (\u03b1 i)] : SupConvergenceClass (\u2200 i, \u03b1 i) := by\n  refine' \u27e8fun f s h => _\u27e9\n  simp only [isLUB_pi, \u2190 range_restrict] at h\n  exact tendsto_pi_nhds.2 fun i => tendsto_atTop_isLUB ((monotone_eval _).restrict _) (h i)\n\ninstance Pi.infConvergenceClass\n    {\u03b9 : Type _} {\u03b1 : \u03b9 \u2192 Type _} [\u2200 i, Preorder (\u03b1 i)] [\u2200 i, TopologicalSpace (\u03b1 i)]\n    [\u2200 i, InfConvergenceClass (\u03b1 i)] : InfConvergenceClass (\u2200 i, \u03b1 i) :=\n  show InfConvergenceClass (\u2200 i, (\u03b1 i)\u1d52\u1d48)\u1d52\u1d48 from OrderDual.infConvergenceClass\n\ninstance Pi.Sup_convergence_class' {\u03b9 : Type _} [Preorder \u03b1] [TopologicalSpace \u03b1]\n    [SupConvergenceClass \u03b1] : SupConvergenceClass (\u03b9 \u2192 \u03b1) :=\n  supConvergenceClass\n#align pi.Sup_convergence_class' Pi.Sup_convergence_class'\n\ninstance Pi.Inf_convergence_class' {\u03b9 : Type _} [Preorder \u03b1] [TopologicalSpace \u03b1]\n    [InfConvergenceClass \u03b1] : InfConvergenceClass (\u03b9 \u2192 \u03b1) :=\n  Pi.infConvergenceClass\n#align pi.Inf_convergence_class' Pi.Inf_convergence_class'\n\ntheorem tendsto_of_monotone {\u03b9 \u03b1 : Type _} [Preorder \u03b9] [TopologicalSpace \u03b1]\n    [ConditionallyCompleteLinearOrder \u03b1] [OrderTopology \u03b1] {f : \u03b9 \u2192 \u03b1} (h_mono : Monotone f) :\n    Tendsto f atTop atTop \u2228 \u2203 l, Tendsto f atTop (\ud835\udcdd l) :=\n  if H : BddAbove (range f) then Or.inr \u27e8_, tendsto_atTop_csup\u1d62 h_mono H\u27e9\n  else Or.inl <| tendsto_atTop_atTop_of_monotone' h_mono H\n#align tendsto_of_monotone tendsto_of_monotone\n\ntheorem tendsto_iff_tendsto_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type _} [SemilatticeSup \u03b9\u2081] [Preorder \u03b9\u2082]\n    [Nonempty \u03b9\u2081] [TopologicalSpace \u03b1] [ConditionallyCompleteLinearOrder \u03b1] [OrderTopology \u03b1]\n    [NoMaxOrder \u03b1] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} {l : \u03b1} (hf : Monotone f)\n    (hg : Tendsto \u03c6 atTop atTop) : Tendsto f atTop (\ud835\udcdd l) \u2194 Tendsto (f \u2218 \u03c6) atTop (\ud835\udcdd l) := by\n  constructor <;> intro h\n  \u00b7 exact h.comp hg\n  \u00b7 rcases tendsto_of_monotone hf with (h' | \u27e8l', hl'\u27e9)\n    \u00b7 exact (not_tendsto_atTop_of_tendsto_nhds h (h'.comp hg)).elim\n    \u00b7 rwa [tendsto_nhds_unique h (hl'.comp hg)]\n#align tendsto_iff_tendsto_subseq_of_monotone tendsto_iff_tendsto_subseq_of_monotone\n\n/-! The next family of results, such as `isLUB_of_tendsto_atTop` and `sup\u1d62_eq_of_tendsto`, are\nconverses to the standard fact that bounded monotone functions converge. They state, that if a\nmonotone function `f` tends to `a` along `Filter.atTop`, then that value `a` is a least upper bound\nfor the range of `f`.\n\nRelated theorems above (`IsLUB.isLUB_of_tendsto`, `IsGLB.isGLB_of_tendsto` etc) cover the case\nwhen `f x` tends to `a` as `x` tends to some point `b` in the domain. -/\n\nset_option autoImplicit false\ntheorem Monotone.ge_of_tendsto [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [SemilatticeSup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Monotone f) (ha : Tendsto f atTop (\ud835\udcdd a)) (b : \u03b2) :\n    f b \u2264 a :=\n  haveI : Nonempty \u03b2 := Nonempty.intro b\n  _root_.ge_of_tendsto ha ((eventually_ge_atTop b).mono fun _ hxy => hf hxy)\n#align monotone.ge_of_tendsto Monotone.ge_of_tendsto\n\ntheorem Monotone.le_of_tendsto [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [SemilatticeInf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Monotone f) (ha : Tendsto f atBot (\ud835\udcdd a)) (b : \u03b2) :\n    a \u2264 f b :=\n  hf.dual.ge_of_tendsto ha b\n#align monotone.le_of_tendsto Monotone.le_of_tendsto\n\ntheorem Antitone.le_of_tendsto [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [SemilatticeSup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Antitone f) (ha : Tendsto f atTop (\ud835\udcdd a)) (b : \u03b2) :\n    a \u2264 f b :=\n  hf.dual_right.ge_of_tendsto ha b\n#align antitone.le_of_tendsto Antitone.le_of_tendsto\n\ntheorem Antitone.ge_of_tendsto [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [SemilatticeInf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Antitone f) (ha : Tendsto f atBot (\ud835\udcdd a)) (b : \u03b2) :\n    f b \u2264 a :=\n  hf.dual_right.le_of_tendsto ha b\n#align antitone.ge_of_tendsto Antitone.ge_of_tendsto\n\ntheorem isLUB_of_tendsto_atTop [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [Nonempty \u03b2] [SemilatticeSup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Monotone f)\n    (ha : Tendsto f atTop (\ud835\udcdd a)) : IsLUB (Set.range f) a := by\n  constructor\n  \u00b7 rintro _ \u27e8b, rfl\u27e9\n    exact hf.ge_of_tendsto ha b\n  \u00b7 exact fun _ hb => le_of_tendsto' ha fun x => hb (Set.mem_range_self x)\n#align is_lub_of_tendsto_at_top isLUB_of_tendsto_atTop\n\ntheorem isGLB_of_tendsto_atBot [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [Nonempty \u03b2] [SemilatticeInf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Monotone f)\n    (ha : Tendsto f atBot (\ud835\udcdd a)) : IsGLB (Set.range f) a :=\n  @isLUB_of_tendsto_atTop \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ hf.dual ha\n#align is_glb_of_tendsto_at_bot isGLB_of_tendsto_atBot\n\ntheorem isLUB_of_tendsto_atBot [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [Nonempty \u03b2] [SemilatticeInf \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Antitone f)\n    (ha : Tendsto f atBot (\ud835\udcdd a)) : IsLUB (Set.range f) a :=\n  @isLUB_of_tendsto_atTop \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ hf.dual_left ha\n#align is_lub_of_tendsto_at_bot isLUB_of_tendsto_atBot\n\ntheorem isGLB_of_tendsto_atTop [TopologicalSpace \u03b1] [Preorder \u03b1] [OrderClosedTopology \u03b1]\n    [Nonempty \u03b2] [SemilatticeSup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Antitone f)\n    (ha : Tendsto f atTop (\ud835\udcdd a)) : IsGLB (Set.range f) a :=\n  @isGLB_of_tendsto_atBot \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ hf.dual_left ha\n#align is_glb_of_tendsto_at_top isGLB_of_tendsto_atTop\n\ntheorem sup\u1d62_eq_of_tendsto {\u03b1 \u03b2} [TopologicalSpace \u03b1] [CompleteLinearOrder \u03b1] [OrderTopology \u03b1]\n    [Nonempty \u03b2] [SemilatticeSup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Monotone f) :\n    Tendsto f atTop (\ud835\udcdd a) \u2192 sup\u1d62 f = a :=\n  tendsto_nhds_unique (tendsto_atTop_sup\u1d62 hf)\n#align supr_eq_of_tendsto sup\u1d62_eq_of_tendsto\n\ntheorem inf\u1d62_eq_of_tendsto {\u03b1} [TopologicalSpace \u03b1] [CompleteLinearOrder \u03b1] [OrderTopology \u03b1]\n    [Nonempty \u03b2] [SemilatticeSup \u03b2] {f : \u03b2 \u2192 \u03b1} {a : \u03b1} (hf : Antitone f) :\n    Tendsto f atTop (\ud835\udcdd a) \u2192 inf\u1d62 f = a :=\n  tendsto_nhds_unique (tendsto_atTop_inf\u1d62 hf)\n#align infi_eq_of_tendsto inf\u1d62_eq_of_tendsto\n\ntheorem sup\u1d62_eq_sup\u1d62_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type _} [Preorder \u03b9\u2082] [CompleteLattice \u03b1]\n    {l : Filter \u03b9\u2081} [l.NeBot] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} (hf : Monotone f)\n    (h\u03c6 : Tendsto \u03c6 l atTop) : (\u2a06 i, f i) = \u2a06 i, f (\u03c6 i) :=\n  le_antisymm\n    (sup\u1d62_mono' fun i =>\n      Exists.imp (fun j (hj : i \u2264 \u03c6 j) => hf hj) (h\u03c6.eventually <| eventually_ge_atTop i).exists)\n    (sup\u1d62_mono' fun i => \u27e8\u03c6 i, le_rfl\u27e9)\n#align supr_eq_supr_subseq_of_monotone sup\u1d62_eq_sup\u1d62_subseq_of_monotone\n\ntheorem inf\u1d62_eq_inf\u1d62_subseq_of_monotone {\u03b9\u2081 \u03b9\u2082 \u03b1 : Type _} [Preorder \u03b9\u2082] [CompleteLattice \u03b1]\n    {l : Filter \u03b9\u2081} [l.NeBot] {f : \u03b9\u2082 \u2192 \u03b1} {\u03c6 : \u03b9\u2081 \u2192 \u03b9\u2082} (hf : Monotone f)\n    (h\u03c6 : Tendsto \u03c6 l atBot) : (\u2a05 i, f i) = \u2a05 i, f (\u03c6 i) :=\n  sup\u1d62_eq_sup\u1d62_subseq_of_monotone hf.dual h\u03c6\n#align infi_eq_infi_subseq_of_monotone inf\u1d62_eq_inf\u1d62_subseq_of_monotone\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/Algebra/Order/MonotoneConvergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199034, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7268252013648935}}
{"text": "import .induction .size \n\nuniverses u v w\n\nvariables {\u03b1 : Type*} [fintype \u03b1]\nopen set \n\nlemma induction_set_size_remove (P : set \u03b1 \u2192 Prop) : \n  (P \u2205) \u2192 (\u2200 (X : set \u03b1) (e : X), P (X \\ {e}) \u2192 P X) \u2192 (\u2200 X, P X) := \nbegin\n  intros h0 h, \n  refine nonneg_int_strong_induction_param P size (size_nonneg) (\u03bb X hX, _) (\u03bb X hX hX', _ ), \n  { convert h0, apply empty_of_size_zero hX}, \n  rcases size_pos_iff_has_mem.mp hX with \u27e8e,he\u27e9, \n  exact h X \u27e8e,he\u27e9 (hX' (X \\ {e}) (by linarith [size_remove_mem he])), \nend\n\nlemma induction_set_size_add (P : set \u03b1 \u2192 Prop) : \n  (P \u2205) \u2192 (\u2200 (X : set \u03b1) (e : \u03b1), e \u2209 X \u2192 P X \u2192 P (X \u222a {e})) \u2192 (\u2200 X, P X) :=\nbegin\n  intros h0 h, \n  refine nonneg_int_strong_induction_param P size \n    (size_nonneg) \n    (\u03bb X hX, _) \n    (\u03bb X hX hX', _ ), \n  { convert h0, apply empty_of_size_zero hX}, \n  rcases size_pos_iff_has_mem.mp hX with \u27e8e,he\u27e9, \n  convert h (X \\ {e}) e _ (hX' _ _);\n  simp [remove_union_mem_singleton he, int.zero_lt_one,size_remove_mem he], \nend\n\nlemma induction_set_size_insert (P : set \u03b1 \u2192 Prop) : \n  (P \u2205) \u2192 (\u2200 (X : set \u03b1) (e : \u03b1), e \u2209 X \u2192 P X \u2192 P (insert e X)) \u2192 (\u2200 X, P X) :=\nbegin\n  intros h0 h, \n  refine nonneg_int_strong_induction_param P size \n    (size_nonneg) \n    (\u03bb X hX, _) \n    (\u03bb X hX hX', _ ), \n  { convert h0, apply empty_of_size_zero hX}, \n  rcases size_pos_iff_has_mem.mp hX with \u27e8e,he\u27e9, \n  convert h (X \\ {e}) e _ (hX' _ _);\n  simp [remove_union_mem_singleton he, int.zero_lt_one,size_remove_mem he, insert_eq_of_mem he], \nend\n\nlemma induction_set_size_insert_finite {\u03b1 : Type*} (P : set \u03b1 \u2192 Prop) :\n  (P \u2205) \u2192 (\u2200 (X : set \u03b1) (e : \u03b1), e \u2209 X \u2192 P X \u2192 P (insert e X)) \u2192 (\u2200 (s : set \u03b1), s.finite \u2192 P s) :=\nbegin\n  intro h_empt, \n  have h := nonneg_int_strong_induction_param \n    (\u03bb (s : set \u03b1), s.finite \u2192 P s) \n    size \n    (\u03bb _, size_nonneg _)\n    (by { intros s hs hf, rw finite.size_zero_iff_empty hf at hs, rwa hs,}), \n  refine \u03bb h' s hfin, h (\u03bb t h\u2081 ih hf, (_)) _ hfin, \n  obtain (rfl | ht) := em (t = \u2205), assumption, \n  obtain \u27e8e, he\u27e9 := ne_empty_iff_has_mem.mp ht, \n  specialize ih (t \\ {e}) (by {rw finite.size_remove_mem hf he, norm_num}) (finite.diff hf _), \n  convert h' (t \\ {e}) e (nonmem_diff_of_mem _ (by simp)) ih, \n  simp [insert_eq_of_mem he], \nend\n\n\n/-- P holds for all proper subsets of Y-/\ndef below (P : set \u03b1 \u2192 Prop) (Y : set \u03b1) : Prop :=\n  forall (X :  set \u03b1), X \u2282 Y \u2192 (P X)\n\n/-- if P holds for all proper subsets of Y, it holds for Y-/\ndef augment (P : set \u03b1 \u2192 Prop) : Prop :=\n  forall (Y : set \u03b1), (below P Y) \u2192 (P Y)\n\nlemma strong_induction (P : set \u03b1 \u2192 Prop) :\n  (augment P) \u2192 (forall (Z : set \u03b1), P Z) :=\nbegin\n  intros h_augment, \n  let  Q : \u2124 \u2192 Prop := \u03bb n, \u2200 Y : set \u03b1, size Y = n \u2192 P Y,\n  suffices : \u2200 n, 0 \u2264 n \u2192 Q n,  \n  from \u03bb Z, this (size Z) (size_nonneg _)  Z rfl, \n  refine nonneg_int_strong_induction Q _ _,\n  \n  intros Y hY, rw [size_zero_iff_empty] at hY, rw hY, \n  refine h_augment _ _, \n  from \u03bb X hX, false.elim (ssubset_empty _ hX), \n  intros n h0n hn X hXn, \n  refine h_augment _ _,\n  intros Y hY, \n  refine hn (size Y) (size_nonneg Y) _ Y rfl, \n  rw \u2190hXn, \n  from size_strict_monotone hY, \nend\n\nlemma minimal_example (P : set \u03b1 \u2192 Prop){X : set \u03b1} : \n  (P X) \u2192 \u2203 Y, Y \u2286 X \u2227 P Y \u2227 \u2200 Z, Z \u2282 Y \u2192 \u00acP Z := \nbegin\n  set minimal_P := \u03bb (Y : set \u03b1), P Y \u2227 \u2200 (Z : set \u03b1), Z \u2282 Y \u2192 \u00ac P Z with hmin, \n  revert X, refine strong_induction _ _, intros T hT hPT, \n  by_cases \u2200 Z, Z \u2282 T \u2192 \u00acP Z, use T, exact \u27e8subset_refl T, \u27e8hPT, h\u27e9\u27e9, \n  push_neg at h, rcases h with \u27e8Z, \u27e8hZT, hPZ\u27e9\u27e9, \n  specialize hT Z hZT hPZ, rcases hT with \u27e8Y, \u27e8hYZ, hQY\u27e9\u27e9, \n  use Y, exact \u27e8subset.trans hYZ hZT.1, hQY\u27e9, \nend\n\nlemma maximal_example (P : set \u03b1 \u2192 Prop){X : set \u03b1} : \n  (P X) \u2192 \u2203 Y, X \u2286 Y \u2227 P Y \u2227 \u2200 Z, Y \u2282 Z \u2192 \u00acP Z := \nbegin\n  intro h, rw \u2190compl_compl X at h, \n  rcases minimal_example (\u03bb S, P S\u1d9c) h with \u27e8Y,\u27e8hY\u2081, hY\u2082, hY\u2083\u27e9\u27e9, \n  use Y\u1d9c, refine \u27e8subset_compl_comm.mpr hY\u2081, hY\u2082,\u03bb Z hZ, _\u27e9,  \n  rw \u2190compl_compl Z, exact hY\u2083 Z\u1d9c (compl_ssubset_comm.mp hZ), \nend\n\nlemma maximal_example_from_empty (P : set \u03b1 \u2192 Prop) : \n  P \u2205 \u2192 \u2203 Y, P Y \u2227 \u2200 Z, Y \u2282 Z \u2192 \u00acP Z := \n  \u03bb h, by {rcases maximal_example P h with \u27e8Y, \u27e8_,h'\u27e9\u27e9, from \u27e8Y,h'\u27e9  }\n\nlemma maximal_example_aug (P : set \u03b1 \u2192 Prop){X : set \u03b1} : \n  (P X) \u2192 \u2203 Y, X \u2286 Y \u2227 P Y \u2227 \u2200 (e : \u03b1), e \u2209 Y \u2192 \u00acP (Y \u222a {e}) := \nbegin\n  intro hPX, \n  rcases maximal_example P hPX with \u27e8Y, \u27e8hXY, \u27e8hPY, hmax\u27e9\u27e9\u27e9, \n  from \u27e8Y, \u27e8hXY, \u27e8hPY, \u03bb e he, hmax (Y \u222a {e}) (ssub_of_add_nonmem he) \u27e9\u27e9\u27e9,  \nend \n\nlemma maximal_example_aug_from_empty (P : set \u03b1 \u2192 Prop) : \n  P \u2205 \u2192 \u2203 Y, P Y \u2227 \u2200 (e : \u03b1), e \u2209 Y \u2192 \u00acP (Y \u222a {e}) := \n  \u03bb h, by {rcases maximal_example_aug P h with \u27e8Y, \u27e8_,h'\u27e9\u27e9, from \u27e8Y,h'\u27e9}\n\nlemma minimal_example_remove (P : set \u03b1 \u2192 Prop){X : set \u03b1} : \n  (P X) \u2192 \u2203 Y, Y \u2286 X \u2227 P Y \u2227 \u2200 (e : \u03b1), e \u2208 Y \u2192 \u00acP (Y \\ {e}) := \nbegin\n  intro hPX, \n  rcases minimal_example P hPX with \u27e8Y, \u27e8hXY, \u27e8hPY, hmin\u27e9\u27e9\u27e9, \n  from \u27e8Y, \u27e8hXY, \u27e8hPY, \u03bb e he, hmin (Y \\ {e}) (ssubset_of_remove_mem he) \u27e9\u27e9\u27e9,  \nend \n\n/-lemma minimal_example_size (P : set \u03b1 \u2192 Prop) (hP : set.nonempty P) :\n  \u2203 X, P X \u2227 \u2200 Y, size Y < size X \u2192 \u00ac P Y := \nbegin\n  by_contra h, push_neg at h, \nend-/\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_aux/prelim/induction_size.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.7268251881271268}}
{"text": "/-\nCopyright (c) 2022 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky, Floris van Doorn\n-/\nimport data.pnat.basic\n\n/-!\n# Explicit least witnesses to existentials on positive natural numbers\n\nImplemented via calling out to `nat.find`.\n\n-/\n\nnamespace pnat\n\nvariables {p q : \u2115+ \u2192 Prop} [decidable_pred p] [decidable_pred q] (h : \u2203 n, p n)\n\ninstance decidable_pred_exists_nat :\n  decidable_pred (\u03bb n' : \u2115, \u2203 (n : \u2115+) (hn : n' = n), p n) := \u03bb n',\ndecidable_of_iff' (\u2203 (h : 0 < n'), p \u27e8n', h\u27e9) $ subtype.exists.trans $\n  by simp_rw [subtype.coe_mk, @exists_comm (_ < _) (_ = _), exists_prop, exists_eq_left']\n\n\ninclude h\n\n/-- The `pnat` version of `nat.find_x` -/\nprotected def find_x : {n // p n \u2227 \u2200 m : \u2115+, m < n \u2192 \u00acp m} :=\nbegin\n  have : \u2203 (n' : \u2115) (n : \u2115+) (hn' : n' = n), p n, from exists.elim h (\u03bb n hn, \u27e8n, n, rfl, hn\u27e9),\n  have n := nat.find_x this,\n  refine \u27e8\u27e8n, _\u27e9, _, \u03bb m hm pm, _\u27e9,\n  { obtain \u27e8n', hn', -\u27e9 := n.prop.1,\n    rw hn',\n    exact n'.prop },\n  { obtain \u27e8n', hn', pn'\u27e9 := n.prop.1,\n    simpa [hn', subtype.coe_eta] using pn' },\n  { exact n.prop.2 m hm \u27e8m, rfl, pm\u27e9 }\nend\n\n/--\nIf `p` is a (decidable) predicate on `\u2115+` and `hp : \u2203 (n : \u2115+), p n` is a proof that\nthere exists some positive natural number satisfying `p`, then `pnat.find hp` is the\nsmallest positive natural number satisfying `p`. Note that `pnat.find` is protected,\nmeaning that you can't just write `find`, even if the `pnat` namespace is open.\n\nThe API for `pnat.find` is:\n\n* `pnat.find_spec` is the proof that `pnat.find hp` satisfies `p`.\n* `pnat.find_min` is the proof that if `m < pnat.find hp` then `m` does not satisfy `p`.\n* `pnat.find_min'` is the proof that if `m` does satisfy `p` then `pnat.find hp \u2264 m`.\n-/\nprotected def find : \u2115+ :=\npnat.find_x h\n\nprotected theorem find_spec : p (pnat.find h) :=\n(pnat.find_x h).prop.left\n\nprotected theorem find_min : \u2200 {m : \u2115+}, m < pnat.find h \u2192 \u00acp m :=\n(pnat.find_x h).prop.right\n\nprotected theorem find_min' {m : \u2115+} (hm : p m) : pnat.find h \u2264 m :=\nle_of_not_lt (\u03bb l, pnat.find_min h l hm)\n\nvariables {n m : \u2115+}\n\nlemma find_eq_iff : pnat.find h = m \u2194 p m \u2227 \u2200 n < m, \u00ac p n :=\nbegin\n  split,\n  { rintro rfl, exact \u27e8pnat.find_spec h, \u03bb _, pnat.find_min h\u27e9 },\n  { rintro \u27e8hm, hlt\u27e9,\n    exact le_antisymm (pnat.find_min' h hm) (not_lt.1 $ imp_not_comm.1 (hlt _) $ pnat.find_spec h) }\nend\n\n@[simp] lemma find_lt_iff (n : \u2115+) : pnat.find h < n \u2194 \u2203 m < n, p m :=\n\u27e8\u03bb h2, \u27e8pnat.find h, h2, pnat.find_spec h\u27e9, \u03bb \u27e8m, hmn, hm\u27e9, (pnat.find_min' h hm).trans_lt hmn\u27e9\n\n@[simp] lemma find_le_iff (n : \u2115+) : pnat.find h \u2264 n \u2194 \u2203 m \u2264 n, p m :=\nby simp only [exists_prop, \u2190 lt_add_one_iff, find_lt_iff]\n\n@[simp] lemma le_find_iff (n : \u2115+) : n \u2264 pnat.find h \u2194 \u2200 m < n, \u00ac p m :=\nby simp_rw [\u2190 not_lt, find_lt_iff, not_exists]\n\n@[simp] lemma lt_find_iff (n : \u2115+) : n < pnat.find h \u2194 \u2200 m \u2264 n, \u00ac p m :=\nby simp only [\u2190 add_one_le_iff, le_find_iff, add_le_add_iff_right]\n\n@[simp] lemma find_eq_one : pnat.find h = 1 \u2194 p 1 :=\nby simp [find_eq_iff]\n\n@[simp] lemma one_le_find : 1 < pnat.find h \u2194 \u00ac p 1 :=\nnot_iff_not.mp $ by simp\n\ntheorem find_mono (h : \u2200 n, q n \u2192 p n)\n  {hp : \u2203 n, p n} {hq : \u2203 n, q n} :\n  pnat.find hp \u2264 pnat.find hq :=\npnat.find_min' _ (h _ (pnat.find_spec hq))\n\nlemma find_le {h : \u2203 n, p n} (hn : p n) : pnat.find h \u2264 n :=\n(pnat.find_le_iff _ _).2 \u27e8n, le_rfl, hn\u27e9\n\nlemma find_comp_succ (h : \u2203 n, p n) (h\u2082 : \u2203 n, p (n + 1)) (h1 : \u00ac p 1) :\n  pnat.find h = pnat.find h\u2082 + 1 :=\nbegin\n  refine (find_eq_iff _).2 \u27e8pnat.find_spec h\u2082, \u03bb n, pnat.rec_on n _ _\u27e9,\n  { simp [h1] },\n  intros m IH hm,\n  simp only [add_lt_add_iff_right, lt_find_iff] at hm,\n  exact hm _ le_rfl\nend\n\nend pnat\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/data/pnat/find.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438126, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7268009965785655}}
{"text": "-- Propiedades_asociativa_y_conmutativa.lean\n-- Propiedades asociativa y conmutativa del producto de los reales.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 12 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- En esta relaci\u00f3n se presentan distintas pruebas con Lean de una\n-- igualdad con productos de n\u00fameros reales. La primera es por\n-- reescritura usando las propiedades asociativa y conmutativa, La\n-- segunda es con encadenamiento de ecuaciones. Las restantes son\n-- autom\u00e1ticas. \n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sean a, b y c n\u00fameros reales. Demostrar que\n--    (a * b) * c = b * (a * c) \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables (a b c : \u211d)\n\n-- 1\u00aa demostraci\u00f3n (hacia atr\u00e1s con rw) \n-- ====================================\n\nexample : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc,\nend\n\n-- Prueba:\n/-\n  a b c : \u211d\n  \u22a2 (a * b) * c = b * (a * c)\nrw mul_comm a b,\n  \u22a2 (b * a) * c = b * (a * c)\nrw mul_assoc,\n  no goals\n-/\n\n-- Comentarios:\n-- + Se han usado los lemas\n--   + mul_comm : \u2200 (a b : \u211d), a * b = b * a \n--   + mul_assoc : \u2200 (a b c : \u211d), a * b * c = a * (b * c)   \n\n-- 2\u00aa demostraci\u00f3n (encadenamiento de igualdades)\n-- ==============================================\n\nexample : (a * b) * c = b * (a * c) :=\nbegin\n  calc (a * b) * c = (b * a) * c : by rw mul_comm a b\n              ...  = b * (a * c) : by rw mul_assoc,    \nend\n\n-- 3\u00aa demostraci\u00f3n (autom\u00e1tica con linarith)\n-- =========================================\n\nexample : (a * b) * c = b * (a * c) :=\nby linarith\n\n-- 4\u00aa demostraci\u00f3n (autom\u00e1tica con finish)\n-- =======================================\n\nexample : (a * b) * c = b * (a * c) :=\nby finish\n\n-- 5\u00aa demostraci\u00f3n (autom\u00e1tica con ring)\n-- =====================================\n\nexample : (a * b) * c = b * (a * c) :=\nby ring\n\n-- Comentarios:\n-- + La t\u00e1ctica ring demuestra la conclusi\u00f3n normalizando las\n--   expresiones con las reglas de los anillos.\n\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/1_Igualdad/Propiedades_asociativa_y_conmutativa.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438126, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7268009871948542}}
{"text": "/-\nDefine the abstract and concrete syntax and semantics of simple arithmetic expressions, to\ninclude variables.\n-/\n\ninductive avar : Type\n| mk (n : nat)\n\ndef a_state := avar \u2192 nat \n\ninductive aexp : Type \n| lit_expr (n : nat)\n| var_expr (a : avar)\n| add_expr (e1 e2 : aexp)\n| mul_expr (e1 e2 : aexp)\n\nopen aexp\n\ndef aeval : aexp \u2192 a_state \u2192 nat \n| (lit_expr n) st := n\n| (var_expr v) st :=  st v\n| (add_expr e1 e2) st := (aeval e1 st) + (aeval e2 st)\n| (mul_expr e1 e2) st := (aeval e1 st) * (aeval e2 st)\n\nnotation `[` n `]` := lit_expr n\nnotation `[` v `]` := var_expr v\nnotation e1 + e2 := add_expr e1 e2\nnotation e1 * e2 := mul_expr e1 e2\n\ndef st0 := \u03bb (v : avar), 0\nexample : aeval ([3] + [5]) st0 = 8 := rfl ", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/inClassNotes/langs/arith_expr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191309994467, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.726664125693245}}
{"text": "/-\nCopyright (c) 2022 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\nimport adeles_R\nimport number_theory.function_field\n\n/-!\n# The valuation at infinity on k(t)\nFor a field `k`, the valuation at infinity on the function field `k(t)` is the nonarchimedean\nvaluation on `k(t)` with uniformizer `1/t`. Explicitly, if `f/g \u2208 k(t)` is a nonzero quotient of\npolynomials, its valuation at infinity is `multiplicative.of_add(degree(f) - degree(g))`.\n\n## Main definitions\n- `infty_valuation` : The valuation at infinity on `k(t)`.\n- `kt_infty` : The completion `k((t\u207b\u00b9))` of `k(t)` with respect to `infty_valuation`.\n\n## Implementation notes\nThe code in this file has already been incorporated to mathlib and can be found in the file\n`number_theory/function_field.lean`. Note that `kt_infty` is called `Fqt_infty` there for\nconsistency with the file's notation, and that some of the names of definitions and lemmas have been\nmodified. We keep this version of the code here so that this branch is a complete reference for the\narticle \"Formalizing the Rings of Ad\u00e8les of a Global Field\".\n\n## Tags\nfunction field, valuation\n-/\n\nnoncomputable theory\n\nopen_locale classical\n\nvariables (k : Type) [field k]\n/-- The valuation at infinity is the nonarchimedean valuation on `k(t)` with uniformizer `1/t`. -/\ndef infty_valuation_def (r : ratfunc k) : with_zero (multiplicative \u2124) :=\nif (r = 0) then 0 else (multiplicative.of_add ((r.num.nat_degree : \u2124) - r.denom.nat_degree))\n\nlemma infty_valuation.map_zero' : infty_valuation_def k 0 = 0 := \nby { rw [infty_valuation_def, if_pos], refl, }\n\nlemma infty_valuation.map_one' : infty_valuation_def k 1 = 1 := \nbegin\n  rw [infty_valuation_def, if_neg (zero_ne_one.symm : (1 : ratfunc k) \u2260 0)],\n  simp only [polynomial.nat_degree_one, ratfunc.num_one, int.coe_nat_zero, sub_zero,\n    ratfunc.denom_one, of_add_zero, with_zero.coe_one],\nend\n\nlemma infty_valuation.map_mul' (x y : ratfunc k) :\n  infty_valuation_def k (x * y) = infty_valuation_def k x * infty_valuation_def k y :=\nbegin\n  rw [infty_valuation_def, infty_valuation_def, infty_valuation_def],\n  by_cases hx : x = 0,\n  { rw [hx, zero_mul, if_pos (eq.refl _), zero_mul] },\n  { by_cases hy : y = 0,\n    { rw [hy, mul_zero, if_pos (eq.refl _), mul_zero] },\n    { rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), \u2190 with_zero.coe_mul,\n        with_zero.coe_inj, \u2190 of_add_add],\n      apply congr_arg,\n      rw [add_sub, sub_add, sub_sub_assoc_swap, sub_sub, sub_eq_sub_iff_add_eq_add],\n      norm_cast,\n      rw [\u2190 polynomial.nat_degree_mul x.denom_ne_zero y.denom_ne_zero,\n        \u2190 polynomial.nat_degree_mul (ratfunc.num_ne_zero (mul_ne_zero hx hy))\n          (mul_ne_zero x.denom_ne_zero y.denom_ne_zero),\n        \u2190 polynomial.nat_degree_mul (ratfunc.num_ne_zero hx) (ratfunc.num_ne_zero hy),\n        \u2190 polynomial.nat_degree_mul (mul_ne_zero (ratfunc.num_ne_zero hx) (ratfunc.num_ne_zero hy))\n          (x * y).denom_ne_zero, ratfunc.num_denom_mul],}}\nend\n\nvariable {k}\n/-- Equivalent fractions have the same valuation -/\nlemma infty_valuation_well_defined {r\u2081 r\u2082 s\u2081 s\u2082 : polynomial k} (hr\u2081 : r\u2081 \u2260 0) (hs\u2081 : s\u2081 \u2260 0) \n  (hr\u2082 : r\u2082 \u2260 0) (hs\u2082 : s\u2082 \u2260 0) (h_eq : r\u2081*s\u2082 = r\u2082*s\u2081) :\n  (r\u2081.nat_degree : \u2124) - s\u2081.nat_degree = (r\u2082.nat_degree : \u2124) - s\u2082.nat_degree :=\nbegin\n  rw sub_eq_sub_iff_add_eq_add,\n  norm_cast,\n  rw [\u2190 polynomial.nat_degree_mul hr\u2081 hs\u2082, \u2190 polynomial.nat_degree_mul hr\u2082 hs\u2081, h_eq],\nend\n\nlemma ratfunc.num_add_ne_zero {x y : ratfunc k} (hxy : x + y \u2260 0) :\n  x.num * y.denom + x.denom * y.num \u2260 0 :=\nbegin\n  intro h_zero,\n  have h := ratfunc.num_denom_add x y,\n  rw [h_zero, zero_mul] at h,\n  exact (mul_ne_zero (ratfunc.num_ne_zero hxy) (mul_ne_zero x.denom_ne_zero y.denom_ne_zero)) h,\nend\n\nlemma infty_valuation_add_rw {x y : ratfunc k} (hxy : x + y \u2260 0) :\n  ((x + y).num.nat_degree : \u2124) - ((x + y).denom.nat_degree)  = \n  ((x.num) * y.denom + (x.denom) * y.num).nat_degree - ((x.denom) * y.denom).nat_degree :=\ninfty_valuation_well_defined (ratfunc.num_ne_zero hxy) ((x + y).denom_ne_zero)\n    (ratfunc.num_add_ne_zero hxy) (mul_ne_zero x.denom_ne_zero y.denom_ne_zero)\n    (ratfunc.num_denom_add x y)\n\nlemma infty_valuation_rw {x : ratfunc k} (hx : x \u2260 0) {s : polynomial k} (hs : s \u2260 0):\n  (x.num.nat_degree : \u2124) - (x.denom.nat_degree)  = \n  ((x.num)*s).nat_degree - (s*(x.denom)).nat_degree :=\nbegin\n  apply infty_valuation_well_defined (ratfunc.num_ne_zero hx) x.denom_ne_zero\n    (mul_ne_zero (ratfunc.num_ne_zero hx) hs) (mul_ne_zero hs x.denom_ne_zero),\n  rw mul_assoc,\nend\n\nvariable (k)\nlemma infty_valuation.map_add' (x y : ratfunc k) :\n  infty_valuation_def k (x + y) \u2264 max (infty_valuation_def k x) (infty_valuation_def k y) :=\nbegin\n  by_cases hx : x = 0,\n    { rw [hx, zero_add],\n      conv_rhs {rw [infty_valuation_def, if_pos (eq.refl _)]},\n      rw max_eq_right (with_zero.zero_le (infty_valuation_def k y)),\n      exact le_refl _, },\n    { by_cases hy : y = 0,\n        { rw [hy, add_zero],\n          conv_rhs {rw [max_comm, infty_valuation_def, if_pos (eq.refl _)]},\n          rw max_eq_right (with_zero.zero_le (infty_valuation_def k x)), \n          exact le_refl _ },\n        { by_cases hxy : x + y = 0,\n          { rw [infty_valuation_def, if_pos hxy], exact zero_le',},\n          { rw [infty_valuation_def, infty_valuation_def, infty_valuation_def, if_neg hx,\n              if_neg hy, if_neg hxy, infty_valuation_add_rw hxy,\n              infty_valuation_rw hx y.denom_ne_zero, mul_comm y.denom,\n              infty_valuation_rw hy x.denom_ne_zero, le_max_iff, with_zero.coe_le_coe, of_add_le,\n              with_zero.coe_le_coe, of_add_le, sub_le_sub_iff_right, int.coe_nat_le,\n              sub_le_sub_iff_right, int.coe_nat_le, \u2190 le_max_iff, mul_comm y.num],\n            exact polynomial.nat_degree_add_le _ _, }}},\nend\n\n/-- The valuation at infinity on `k(t)`. -/\ndef infty_valuation  : valuation (ratfunc k) (with_zero (multiplicative \u2124)) :=\n{ to_fun    := infty_valuation_def k, \n  map_zero' := infty_valuation.map_zero' k,\n  map_one'  := infty_valuation.map_one' k,\n  map_mul'  := infty_valuation.map_mul' k,\n  map_add_le_max'  := infty_valuation.map_add' k }\n\n/-- The valued field `k(t)` with the valuation at infinity. -/\ndef infty_valued_kt : valued (ratfunc k) (with_zero (multiplicative \u2124)) := \n\u27e8infty_valuation k\u27e9\n\nlemma infty_valued_kt.def {x : ratfunc k} :\n  @valued.v (ratfunc k) _ _ _ (infty_valued_kt k) (x) = infty_valuation_def k x := rfl\n\n/-- The topology structure on `k(t)` induced by the valuation at infinity. -/\ndef tsq' : topological_space (ratfunc k) :=\n@valued.topological_space (ratfunc k) _ _ _ (infty_valued_kt k)\n\nlemma tdrq' : @topological_division_ring (ratfunc k) _ (tsq' k) := \n@valued.topological_division_ring (ratfunc k) _ _ _ (infty_valued_kt k)\n\nlemma trq' : @topological_ring (ratfunc k) (tsq' k) _ := infer_instance\n\nlemma tgq' : @topological_add_group (ratfunc k) (tsq' k) _ := infer_instance\n\n/-- The uniform structure on `k(t)` induced by the valuation at infinity. -/\ndef usq' : uniform_space (ratfunc k) := \n@topological_add_group.to_uniform_space (ratfunc k) _ (tsq' k) _\n\nlemma ugq' : @uniform_add_group (ratfunc k) (usq' k) _ := \n@topological_add_group_is_uniform (ratfunc k) _ (tsq' k) _\n\nlemma cfq' : @completable_top_field (ratfunc k) _ (usq' k) :=\n@valued.completable (ratfunc k) _ _ _ (infty_valued_kt k)\n\nlemma ssq' : @separated_space (ratfunc k) (usq' k) :=\n@valued_ring.separated (ratfunc k) _ _ _ (infty_valued_kt k)\n\n/-- The completion `k((t\u207b\u00b9))`  of `k(t)` with respect to the valuation at infinity. -/\ndef kt_infty := @uniform_space.completion (ratfunc k) (usq' k)\n\ninstance : field (kt_infty k) :=\n@field_completion (ratfunc k) _ (usq' k) (tdrq' k) _ (ugq' k)\n\n/-- The valuation at infinity on `k(t)` extends to a valuation on `kt_infty`. -/\ninstance valued_kt_infty : valued (kt_infty k) (with_zero (multiplicative \u2124)):= \n\u27e8@valued.extension_valuation (ratfunc k) _ _ _ (infty_valued_kt k)\u27e9\n\nlemma valued_kt_infty.def {x : kt_infty k} :\n  valued.v (x) = @valued.extension (ratfunc k) _ _ _ (infty_valued_kt k) x := rfl\n\ninstance tsq : topological_space (kt_infty k) :=\n@valued.topological_space (kt_infty k) _ _ _ (valued_kt_infty k)\n\ninstance tdrq : @topological_division_ring (kt_infty k) _ (tsq k) := \n@valued.topological_division_ring (kt_infty k) _ _ _(valued_kt_infty k)\n\ninstance trq : @topological_ring (kt_infty k) (tsq k) _ := (tdrq k).to_topological_ring\n\ninstance tgq : @topological_add_group (kt_infty k) (tsq k) _ := \n@topological_ring.to_topological_add_group (kt_infty k) _ (tsq k) (trq k)\n\ninstance usq : uniform_space (kt_infty k) := \n@topological_add_group.to_uniform_space (kt_infty k) _ (tsq k) (tgq k)\n\ninstance ugq : @uniform_add_group (kt_infty k) (usq k) _ := \n@topological_add_group_is_uniform (kt_infty k) _ (tsq k) (tgq k)\n\ninstance : inhabited (kt_infty k) := \u27e8(0 : kt_infty k)\u27e9", "meta": {"author": "mariainesdff", "repo": "ideles-journal", "sha": "fe49f5246910592f8ac56c5470b34f2c66a23220", "save_path": "github-repos/lean/mariainesdff-ideles-journal", "path": "github-repos/lean/mariainesdff-ideles-journal/ideles-journal-fe49f5246910592f8ac56c5470b34f2c66a23220/src/function_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.726630744232266}}
{"text": "import algebra.ring\n\n#check add_comm\n#check zero_add\n#check add_left_neg \n\nnamespace my_ring\n\nvariables {R : Type*} [ring R]\n\ntheorem add_zero (a : R) : a + 0 = a :=\nbegin \n rw add_comm,\n rw zero_add,\nend\n\n-- A shorter proof \nexample (a : R) : a + 0 = a :=\nby rw [add_comm, zero_add]\n  /- Multiple rewrites can be combined using the notation \n     rw [t_1, ..., t_n], which is just shorthand for rewrite \n     t_1, ..., rewrite t_n. -/\n\ntheorem add_right_neg (a : R) : a + -a = 0 :=\nbegin \n  sorry,\nend\n\nend my_ring\n\n#check add_zero\n#check add_right_neg", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/1_rw/ex6_rw_add_comm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7266307348192548}}
{"text": "import data.real.basic\nimport game.functions.bothInjective game.functions.bothSurjective\nopen function\n\n/-\n# Chapter 6 : Functions\n\n## Level 3\n\nBe sure to make use of the results in the previous two levels.\n-/\n\n/- Lemma\nIf $f : X \\to Y$ and $g : Y \\to Z$ are both bijective functions, then\nthe function resulting from their composition is also bijective.\n-/\ntheorem both_bijective\n    (X Y Z : set \u211d) (f : X \u2192 Y) (g : Y \u2192 Z) : \n    bijective f \u2227 bijective g \u2192 bijective (g \u2218 f) :=\nbegin\n    -- Since $f$ and $g$ are bijective, they are also both injective and surjective.\n    rintro \u27e8\u27e8hfi, hfs\u27e9, hgi, hgs\u27e9,\n    split,\n    -- Since $f$ and $g$ are injective, $g \u2218 f$ is injective by a previous result.\n    apply both_injective,\n    split,\n    repeat {assumption},\n    -- Similarly, since $f$ and $g$ are surjective, $g \u2218 f$ is surjective.\n    apply both_surjective,\n    split,\n    -- Hence, since $g \u2218 f$ is injective and surjective, $g \u2218 f$ is bijective.\n    repeat {assumption}, done\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/functions/bothBijective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7266307348192548}}
{"text": "theorem mul_pos (a b : mynat) : a \u2260 0 \u2192 b \u2260 0 \u2192 a * b \u2260 0 :=\nbegin\ncases a,\nrw zero_mul,\nintros h1 h2,\napply h1,\ncases b,\nrw mul_zero,\nintros h1 h2,\napply h2,\nintros h1 h2 h3,\nrw mul_succ at h3,\nrw add_succ at h3,\nexact succ_ne_zero (succ a * b + a) h3,\nend\n", "meta": {"author": "chanha-park", "repo": "naturalNumberGame", "sha": "4e0d7100ce4575e1add92feefa38b1250431b879", "save_path": "github-repos/lean/chanha-park-naturalNumberGame", "path": "github-repos/lean/chanha-park-naturalNumberGame/naturalNumberGame-4e0d7100ce4575e1add92feefa38b1250431b879/Advanced_Multiplication/1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088045171238, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7266307317185997}}
{"text": "import game.limits.Blockus_Time -- hide\nimport game.sets.L01defs -- hide\nimport game.sup_inf.GLBprop_if_LUBprop -- hide\nimport game.limits.bounded_if_convergent -- hide\nimport data.real.basic -- hide\nimport tactic.linarith -- hide\nimport game.limits.seq_limitProd -- hide\nimport game.limits.lim_recip -- hide\nimport game.limits.Mulv2 -- hide\n\n\nnamespace xena -- hide\n/-\n# Chapter 7 : Limits\n\n## Level 13\n\n\nProve the quotient property of limits. \n\nIn this proof, you may find that you will have to \ncompare equal functions. For this, you will want to use \n\"funext\", which basically says that if two functions \nhave equal parts, then they are equal. \n\nGood luck. \n-/\n\n\n\nlocal notation `|`x`|` := abs x\n\n\n\nlemma lim_quo (a : \u2115 \u2192 \u211d) (b : \u2115 \u2192 \u211d) (L  R  : \u211d)\n    (ha : is_limit a L) (hb : is_limit b R) (hbnz : \u2200 n : \u2115, b n \u2260 0) (hr : R \u2260 0): \n    is_limit ( \u03bb n, (a n) / (b n) ) (L / R) :=\n    begin  \n        \n       have L1 := lim_recip b R hr hb hbnz,\n       set c := (\u03bbn , 1 / b n),\n       have L2 := lim_mul a c L (1/R) ha L1,\n       have L3 : L * (1 / R) = L / R, ring, rw L3 at L2, \n       have L4 : (\u03bbn , a n * c n) = (\u03bbn, a n / b n),\n       funext, have F : c n = 1 / b n, refl, \n       rw F, symmetry, exact div_eq_mul_one_div (a n) (b n), \n       rw L4 at L2, exact L2,   \n       \n    end \n\nend xena -- hide", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/limits/lim_quo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7266307302237944}}
{"text": "import tactic -- hide\nopen function nat -- hide\n\n/-\n## Some more on `apply`\n\nIn the following example, `h` eats a number $x$ and a proof of the fact that $1\\leq x$, and gives\na proof of the fact that $1\\leq x^2$. So if we `apply h`, *Lean* can figure out that $x$ must be set to\n$2$ (we could just as well type `apply h 2` to help him), but then it will want a proof of the fact that $1\\leq 2$. In this case, *Lean* has in its library\na proof of\nthis fact, called `one_le_two`, which we can `apply` after `h`.\n-/\n\n/- Lemma : no-side-bar\nKnowing that for all x, if $1\\leq x$ then $1 \u2264 x^2$, we can prove that $1 \u2264 2^2$.\n-/\nlemma l7 (h : \u2200 x, 1 \u2264 x \u2192 1 \u2264 x^2) : 1 \u2264 2^2:=\nbegin\n  apply h,\n  apply one_le_two,\n\n\n  \nend", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/tutorial_world/07_apply.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7266307255172888}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.coeff\n! leanprover-community/mathlib commit fa256f00ce018e7b40e1dc756e403c86680bf448\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.Basic\nimport Mathlib.Data.Finset.NatAntidiagonal\nimport Mathlib.Data.Nat.Choose.Sum\n\n/-!\n# Theory of univariate polynomials\n\nThe theorems include formulas for computing coefficients, such as\n`coeff_add`, `coeff_sum`, `coeff_mul`\n\n-/\n\n\nset_option linter.uppercaseLean3 false\n\nnoncomputable section\n\nopen Finsupp Finset AddMonoidAlgebra\n\nopen BigOperators Polynomial\n\nnamespace Polynomial\n\nuniverse u v\n\nvariable {R : Type u} {S : Type v} {a b : R} {n m : \u2115}\n\nvariable [Semiring R] {p q r : R[X]}\n\nsection Coeff\n\ntheorem coeff_one (n : \u2115) : coeff (1 : R[X]) n = if 0 = n then 1 else 0 :=\n  coeff_monomial\n#align polynomial.coeff_one Polynomial.coeff_one\n\n@[simp]\ntheorem coeff_add (p q : R[X]) (n : \u2115) : coeff (p + q) n = coeff p n + coeff q n := by\n  rcases p with \u27e8\u27e9\n  rcases q with \u27e8\u27e9\n  simp_rw [\u2190 ofFinsupp_add, coeff]\n  exact Finsupp.add_apply _ _ _\n#align polynomial.coeff_add Polynomial.coeff_add\n\nset_option linter.deprecated false in\n@[simp]\ntheorem coeff_bit0 (p : R[X]) (n : \u2115) : coeff (bit0 p) n = bit0 (coeff p n) := by simp [bit0]\n#align polynomial.coeff_bit0 Polynomial.coeff_bit0\n\n@[simp]\ntheorem coeff_smul [Monoid S] [DistribMulAction S R] (r : S) (p : R[X]) (n : \u2115) :\n    coeff (r \u2022 p) n = r \u2022 coeff p n := by\n  rcases p with \u27e8\u27e9\n  simp_rw [\u2190 ofFinsupp_smul, coeff]\n  exact Finsupp.smul_apply _ _ _\n#align polynomial.coeff_smul Polynomial.coeff_smul\n\ntheorem support_smul [Monoid S] [DistribMulAction S R] (r : S) (p : R[X]) :\n    support (r \u2022 p) \u2286 support p := by\n  intro i hi\n  simp [mem_support_iff] at hi\u22a2\n  contrapose! hi\n  simp [hi]\n#align polynomial.support_smul Polynomial.support_smul\n\n/-- `Polynomial.sum` as a linear map. -/\n@[simps]\ndef lsum {R A M : Type _} [Semiring R] [Semiring A] [AddCommMonoid M] [Module R A] [Module R M]\n    (f : \u2115 \u2192 A \u2192\u2097[R] M) : A[X] \u2192\u2097[R] M\n    where\n  toFun p := p.sum fun n r => f n r\n  map_add' p q := sum_add_index p q _ (fun n => (f n).map_zero) fun n _ _ => (f n).map_add _ _\n  map_smul' c p := by\n    -- Porting note: `dsimp only []` is required for beta reduction.\n    dsimp only []\n    rw [sum_eq_of_subset _ (fun n r => f n r) (fun n => (f n).map_zero) _ (support_smul c p)]\n    simp only [sum_def, Finset.smul_sum, coeff_smul, LinearMap.map_smul, RingHom.id_apply]\n#align polynomial.lsum Polynomial.lsum\n#align polynomial.lsum_apply Polynomial.lsum_apply\n\nvariable (R)\n\n/-- The nth coefficient, as a linear map. -/\ndef lcoeff (n : \u2115) : R[X] \u2192\u2097[R] R where\n  toFun p := coeff p n\n  map_add' p q := coeff_add p q n\n  map_smul' r p := coeff_smul r p n\n#align polynomial.lcoeff Polynomial.lcoeff\n\nvariable {R}\n\n@[simp]\ntheorem lcoeff_apply (n : \u2115) (f : R[X]) : lcoeff R n f = coeff f n :=\n  rfl\n#align polynomial.lcoeff_apply Polynomial.lcoeff_apply\n\n@[simp]\ntheorem finset_sum_coeff {\u03b9 : Type _} (s : Finset \u03b9) (f : \u03b9 \u2192 R[X]) (n : \u2115) :\n    coeff (\u2211 b in s, f b) n = \u2211 b in s, coeff (f b) n :=\n  (lcoeff R n).map_sum\n#align polynomial.finset_sum_coeff Polynomial.finset_sum_coeff\n\ntheorem coeff_sum [Semiring S] (n : \u2115) (f : \u2115 \u2192 R \u2192 S[X]) :\n    coeff (p.sum f) n = p.sum fun a b => coeff (f a b) n := by\n  rcases p with \u27e8\u27e9\n  -- Porting note: Was `simp [Polynomial.sum, support, coeff]`.\n  simp [Polynomial.sum, support_ofFinsupp, coeff_ofFinsupp]\n#align polynomial.coeff_sum Polynomial.coeff_sum\n\n/-- Decomposes the coefficient of the product `p * q` as a sum\nover `Nat.antidiagonal`. A version which sums over `range (n + 1)` can be obtained\nby using `Finset.Nat.sum_antidiagonal_eq_sum_range_succ`. -/\ntheorem coeff_mul (p q : R[X]) (n : \u2115) :\n    coeff (p * q) n = \u2211 x in Nat.antidiagonal n, coeff p x.1 * coeff q x.2 := by\n  rcases p with \u27e8p\u27e9; rcases q with \u27e8q\u27e9\n  simp_rw [\u2190 ofFinsupp_mul, coeff]\n  exact AddMonoidAlgebra.mul_apply_antidiagonal p q n _ Nat.mem_antidiagonal\n#align polynomial.coeff_mul Polynomial.coeff_mul\n\n@[simp]\ntheorem mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 := by simp [coeff_mul]\n#align polynomial.mul_coeff_zero Polynomial.mul_coeff_zero\n\n/-- `constantCoeff p` returns the constant term of the polynomial `p`,\n  defined as `coeff p 0`. This is a ring homomorphism. -/\n@[simps]\ndef constantCoeff : R[X] \u2192+* R where\n  toFun p := coeff p 0\n  map_one' := coeff_one_zero\n  map_mul' := mul_coeff_zero\n  map_zero' := coeff_zero 0\n  map_add' p q := coeff_add p q 0\n#align polynomial.constant_coeff Polynomial.constantCoeff\n#align polynomial.constant_coeff_apply Polynomial.constantCoeff_apply\n\ntheorem isUnit_C {x : R} : IsUnit (C x) \u2194 IsUnit x :=\n  \u27e8fun h => (congr_arg IsUnit coeff_C_zero).mp (h.map <| @constantCoeff R _), fun h => h.map C\u27e9\n#align polynomial.is_unit_C Polynomial.isUnit_C\n\ntheorem coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp\n#align polynomial.coeff_mul_X_zero Polynomial.coeff_mul_X_zero\n\ntheorem coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp\n#align polynomial.coeff_X_mul_zero Polynomial.coeff_X_mul_zero\n\ntheorem coeff_C_mul_X_pow (x : R) (k n : \u2115) :\n    coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 := by\n  rw [C_mul_X_pow_eq_monomial, coeff_monomial]\n  congr 1\n  simp [eq_comm]\n#align polynomial.coeff_C_mul_X_pow Polynomial.coeff_C_mul_X_pow\n\ntheorem coeff_C_mul_X (x : R) (n : \u2115) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 := by\n  rw [\u2190 pow_one X, coeff_C_mul_X_pow]\n#align polynomial.coeff_C_mul_X Polynomial.coeff_C_mul_X\n\n@[simp]\ntheorem coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n := by\n  rcases p with \u27e8p\u27e9\n  simp_rw [\u2190 monomial_zero_left, \u2190 ofFinsupp_single, \u2190 ofFinsupp_mul, coeff]\n  exact AddMonoidAlgebra.single_zero_mul_apply p a n\n#align polynomial.coeff_C_mul Polynomial.coeff_C_mul\n\ntheorem C_mul' (a : R) (f : R[X]) : C a * f = a \u2022 f := by\n  ext\n  rw [coeff_C_mul, coeff_smul, smul_eq_mul]\n#align polynomial.C_mul' Polynomial.C_mul'\n\n@[simp]\ntheorem coeff_mul_C (p : R[X]) (n : \u2115) (a : R) : coeff (p * C a) n = coeff p n * a := by\n  rcases p with \u27e8p\u27e9\n  simp_rw [\u2190 monomial_zero_left, \u2190 ofFinsupp_single, \u2190 ofFinsupp_mul, coeff]\n  exact AddMonoidAlgebra.mul_single_zero_apply p a n\n#align polynomial.coeff_mul_C Polynomial.coeff_mul_C\n\ntheorem coeff_X_pow (k n : \u2115) : coeff (X ^ k : R[X]) n = if n = k then 1 else 0 := by\n  simp only [one_mul, RingHom.map_one, \u2190 coeff_C_mul_X_pow]\n#align polynomial.coeff_X_pow Polynomial.coeff_X_pow\n\n@[simp]\ntheorem coeff_X_pow_self (n : \u2115) : coeff (X ^ n : R[X]) n = 1 := by simp [coeff_X_pow]\n#align polynomial.coeff_X_pow_self Polynomial.coeff_X_pow_self\n\nsection Fewnomials\n\nopen Finset\n\ntheorem support_binomial {k m : \u2115} (hkm : k \u2260 m) {x y : R} (hx : x \u2260 0) (hy : y \u2260 0) :\n    support (C x * X ^ k + C y * X ^ m) = {k, m} := by\n  apply subset_antisymm (support_binomial' k m x y)\n  simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,\n    coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm, mul_zero, zero_add,\n    add_zero, Ne.def, hx, hy]\n#align polynomial.support_binomial Polynomial.support_binomial\n\ntheorem support_trinomial {k m n : \u2115} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x \u2260 0)\n    (hy : y \u2260 0) (hz : z \u2260 0) :\n    support (C x * X ^ k + C y * X ^ m + C z * X ^ n) = {k, m, n} := by\n  apply subset_antisymm (support_trinomial' k m n x y z)\n  simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,\n    coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne,\n    if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne', mul_zero, add_zero,\n    zero_add, Ne.def, hx, hy, hz]\n#align polynomial.support_trinomial Polynomial.support_trinomial\n\ntheorem card_support_binomial {k m : \u2115} (h : k \u2260 m) {x y : R} (hx : x \u2260 0) (hy : y \u2260 0) :\n    card (support (C x * X ^ k + C y * X ^ m)) = 2 := by\n  rw [support_binomial h hx hy, card_insert_of_not_mem (mt mem_singleton.mp h), card_singleton]\n#align polynomial.card_support_binomial Polynomial.card_support_binomial\n\ntheorem card_support_trinomial {k m n : \u2115} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x \u2260 0)\n    (hy : y \u2260 0) (hz : z \u2260 0) : card (support (C x * X ^ k + C y * X ^ m + C z * X ^ n)) = 3 := by\n  rw [support_trinomial hkm hmn hx hy hz,\n    card_insert_of_not_mem\n      (mt mem_insert.mp (not_or_of_not hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))),\n    card_insert_of_not_mem (mt mem_singleton.mp hmn.ne), card_singleton]\n#align polynomial.card_support_trinomial Polynomial.card_support_trinomial\n\nend Fewnomials\n\n@[simp]\ntheorem coeff_mul_X_pow (p : R[X]) (n d : \u2115) :\n    coeff (p * Polynomial.X ^ n) (d + n) = coeff p d := by\n  rw [coeff_mul, sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]\n  \u00b7 rintro \u27e8i, j\u27e9 h1 h2\n    rw [coeff_X_pow, if_neg, mul_zero]\n    rintro rfl\n    apply h2\n    rw [Nat.mem_antidiagonal, add_right_cancel_iff] at h1\n    subst h1\n    rfl\n  \u00b7 exact fun h1 => (h1 (Nat.mem_antidiagonal.2 rfl)).elim\n#align polynomial.coeff_mul_X_pow Polynomial.coeff_mul_X_pow\n\n@[simp]\ntheorem coeff_X_pow_mul (p : R[X]) (n d : \u2115) : coeff (Polynomial.X ^ n * p) (d + n) = coeff p d :=\n  by rw [(commute_X_pow p n).eq, coeff_mul_X_pow]\n#align polynomial.coeff_X_pow_mul Polynomial.coeff_X_pow_mul\n\ntheorem coeff_mul_X_pow' (p : R[X]) (n d : \u2115) :\n    (p * X ^ n).coeff d = ite (n \u2264 d) (p.coeff (d - n)) 0 := by\n  split_ifs with h\n  \u00b7 rw [\u2190 tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right]\n  \u00b7 refine' (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => _)\n    rw [coeff_X_pow, if_neg, mul_zero]\n    exact ((le_of_add_le_right (Finset.Nat.mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne\n#align polynomial.coeff_mul_X_pow' Polynomial.coeff_mul_X_pow'\n\ntheorem coeff_X_pow_mul' (p : R[X]) (n d : \u2115) :\n    (X ^ n * p).coeff d = ite (n \u2264 d) (p.coeff (d - n)) 0 := by\n  rw [(commute_X_pow p n).eq, coeff_mul_X_pow']\n#align polynomial.coeff_X_pow_mul' Polynomial.coeff_X_pow_mul'\n\n@[simp]\ntheorem coeff_mul_X (p : R[X]) (n : \u2115) : coeff (p * X) (n + 1) = coeff p n := by\n  simpa only [pow_one] using coeff_mul_X_pow p 1 n\n#align polynomial.coeff_mul_X Polynomial.coeff_mul_X\n\n@[simp]\ntheorem coeff_X_mul (p : R[X]) (n : \u2115) : coeff (X * p) (n + 1) = coeff p n := by\n  rw [(commute_X p).eq, coeff_mul_X]\n#align polynomial.coeff_X_mul Polynomial.coeff_X_mul\n\ntheorem coeff_mul_monomial (p : R[X]) (n d : \u2115) (r : R) :\n    coeff (p * monomial n r) (d + n) = coeff p d * r := by\n  rw [\u2190 C_mul_X_pow_eq_monomial, \u2190 X_pow_mul, \u2190 mul_assoc, coeff_mul_C, coeff_mul_X_pow]\n#align polynomial.coeff_mul_monomial Polynomial.coeff_mul_monomial\n\ntheorem coeff_monomial_mul (p : R[X]) (n d : \u2115) (r : R) :\n    coeff (monomial n r * p) (d + n) = r * coeff p d := by\n  rw [\u2190 C_mul_X_pow_eq_monomial, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow]\n#align polynomial.coeff_monomial_mul Polynomial.coeff_monomial_mul\n\n-- This can already be proved by `simp`.\ntheorem coeff_mul_monomial_zero (p : R[X]) (d : \u2115) (r : R) :\n    coeff (p * monomial 0 r) d = coeff p d * r :=\n  coeff_mul_monomial p 0 d r\n#align polynomial.coeff_mul_monomial_zero Polynomial.coeff_mul_monomial_zero\n\n-- This can already be proved by `simp`.\ntheorem coeff_monomial_zero_mul (p : R[X]) (d : \u2115) (r : R) :\n    coeff (monomial 0 r * p) d = r * coeff p d :=\n  coeff_monomial_mul p 0 d r\n#align polynomial.coeff_monomial_zero_mul Polynomial.coeff_monomial_zero_mul\n\ntheorem mul_X_pow_eq_zero {p : R[X]} {n : \u2115} (H : p * X ^ n = 0) : p = 0 :=\n  ext fun k => (coeff_mul_X_pow p n k).symm.trans <| ext_iff.1 H (k + n)\n#align polynomial.mul_X_pow_eq_zero Polynomial.mul_X_pow_eq_zero\n\ntheorem mul_X_pow_injective (n : \u2115) : Function.Injective fun P : R[X] => X ^ n * P := by\n  intro P Q hPQ\n  simp only at hPQ\n  ext i\n  rw [\u2190 coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i]\n#align polynomial.mul_X_pow_injective Polynomial.mul_X_pow_injective\n\ntheorem mul_X_injective : Function.Injective fun P : R[X] => X * P :=\n  pow_one (X : R[X]) \u25b8 mul_X_pow_injective 1\n#align polynomial.mul_X_injective Polynomial.mul_X_injective\n\ntheorem coeff_X_add_C_pow (r : R) (n k : \u2115) :\n    ((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) := by\n  rw [(commute_X (C r : R[X])).add_pow, \u2190 lcoeff_apply, LinearMap.map_sum]\n  simp only [one_pow, mul_one, lcoeff_apply, \u2190 C_eq_nat_cast, \u2190 C_pow, coeff_mul_C, Nat.cast_id]\n  rw [Finset.sum_eq_single k, coeff_X_pow_self, one_mul]\n  \u00b7 intro _ _ h\n    simp [coeff_X_pow, h.symm]\n  \u00b7 simp only [coeff_X_pow_self, one_mul, not_lt, Finset.mem_range]\n    intro h\n    rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, mul_zero]\n#align polynomial.coeff_X_add_C_pow Polynomial.coeff_X_add_C_pow\n\n\n\ntheorem coeff_one_add_X_pow (R : Type _) [Semiring R] (n k : \u2115) :\n    ((1 + X) ^ n).coeff k = (n.choose k : R) := by rw [add_comm _ X, coeff_X_add_one_pow]\n#align polynomial.coeff_one_add_X_pow Polynomial.coeff_one_add_X_pow\n\ntheorem C_dvd_iff_dvd_coeff (r : R) (\u03c6 : R[X]) : C r \u2223 \u03c6 \u2194 \u2200 i, r \u2223 \u03c6.coeff i := by\n  constructor\n  \u00b7 rintro \u27e8\u03c6, rfl\u27e9 c\n    rw [coeff_C_mul]\n    apply dvd_mul_right\n  \u00b7 intro h\n    choose c hc using h\n    classical\n      let c' : \u2115 \u2192 R := fun i => if i \u2208 \u03c6.support then c i else 0\n      let \u03c8 : R[X] := \u2211 i in \u03c6.support, monomial i (c' i)\n      use \u03c8\n      ext i\n      simp only [coeff_C_mul, mem_support_iff, coeff_monomial, finset_sum_coeff,\n        Finset.sum_ite_eq']\n      split_ifs with hi\n      \u00b7 rw [hc]\n      \u00b7 rw [Classical.not_not] at hi\n        rwa [mul_zero]\n#align polynomial.C_dvd_iff_dvd_coeff Polynomial.C_dvd_iff_dvd_coeff\n\nset_option linter.deprecated false in\ntheorem coeff_bit0_mul (P Q : R[X]) (n : \u2115) : coeff (bit0 P * Q) n = 2 * coeff (P * Q) n := by\n  -- Porting note: `two_mul` is required.\n  simp [bit0, add_mul, two_mul]\n#align polynomial.coeff_bit0_mul Polynomial.coeff_bit0_mul\n\nset_option linter.deprecated false in\ntheorem coeff_bit1_mul (P Q : R[X]) (n : \u2115) :\n    coeff (bit1 P * Q) n = 2 * coeff (P * Q) n + coeff Q n := by\n  simp [bit1, add_mul, coeff_bit0_mul]\n#align polynomial.coeff_bit1_mul Polynomial.coeff_bit1_mul\n\ntheorem smul_eq_C_mul (a : R) : a \u2022 p = C a * p := by simp [ext_iff]\n#align polynomial.smul_eq_C_mul Polynomial.smul_eq_C_mul\n\ntheorem update_eq_add_sub_coeff {R : Type _} [Ring R] (p : R[X]) (n : \u2115) (a : R) :\n    p.update n a = p + Polynomial.C (a - p.coeff n) * Polynomial.X ^ n := by\n  ext\n  rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow]\n  split_ifs with h <;> simp [h]\n#align polynomial.update_eq_add_sub_coeff Polynomial.update_eq_add_sub_coeff\n\nend Coeff\n\nsection cast\n\n@[simp]\ntheorem nat_cast_coeff_zero {n : \u2115} {R : Type _} [Semiring R] : (n : R[X]).coeff 0 = n := by\n  induction' n with n ih\n  \u00b7 simp\n  \u00b7 simp [ih]\n#align polynomial.nat_cast_coeff_zero Polynomial.nat_cast_coeff_zero\n\n@[norm_cast] -- @[simp] -- Porting note: simp can prove this\ntheorem nat_cast_inj {m n : \u2115} {R : Type _} [Semiring R] [CharZero R] :\n    (\u2191m : R[X]) = \u2191n \u2194 m = n := by\n  constructor\n  \u00b7 intro h\n    apply_fun fun p => p.coeff 0  at h\n    simpa using h\n  \u00b7 rintro rfl\n    rfl\n#align polynomial.nat_cast_inj Polynomial.nat_cast_inj\n\n@[simp]\ntheorem int_cast_coeff_zero {i : \u2124} {R : Type _} [Ring R] : (i : R[X]).coeff 0 = i := by\n  cases i <;> simp\n#align polynomial.int_cast_coeff_zero Polynomial.int_cast_coeff_zero\n\n@[norm_cast] -- @[simp] -- Porting note: simp can prove this\ntheorem int_cast_inj {m n : \u2124} {R : Type _} [Ring R] [CharZero R] : (\u2191m : R[X]) = \u2191n \u2194 m = n := by\n  constructor\n  \u00b7 intro h\n    apply_fun fun p => p.coeff 0  at h\n    simpa using h\n  \u00b7 rintro rfl\n    rfl\n#align polynomial.int_cast_inj Polynomial.int_cast_inj\n\nend cast\n\ninstance charZero [CharZero R] : CharZero R[X] where cast_injective _x _y := nat_cast_inj.mp\n#align polynomial.char_zero Polynomial.charZero\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Coeff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.7266307177101274}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.algebra_map\nimport data.polynomial.degree.lemmas\nimport data.polynomial.monic\n\n/-!\n# Theory of monic polynomials\n\nWe define `integral_normalization`, which relate arbitrary polynomials to monic ones.\n-/\n\nopen_locale big_operators polynomial\n\nnamespace polynomial\nuniverses u v y\nvariables {R : Type u} {S : Type v} {a b : R} {m n : \u2115} {\u03b9 : Type y}\n\nsection integral_normalization\n\nsection semiring\nvariables [semiring R]\n\n/-- If `f : R[X]` is a nonzero polynomial with root `z`, `integral_normalization f` is\na monic polynomial with root `leading_coeff f * z`.\n\nMoreover, `integral_normalization 0 = 0`.\n-/\nnoncomputable def integral_normalization (f : R[X]) : R[X] :=\n\u2211 i in f.support, monomial i (if f.degree = i then 1 else\n  coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i))\n\n@[simp] lemma integral_normalization_zero :\n  integral_normalization (0 : R[X]) = 0 :=\nby simp [integral_normalization]\n\nlemma integral_normalization_coeff {f : R[X]} {i : \u2115} :\n  (integral_normalization f).coeff i =\n    if f.degree = i then 1 else coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i) :=\nhave f.coeff i = 0 \u2192 f.degree \u2260 i, from \u03bb hc hd, coeff_ne_zero_of_eq_degree hd hc,\nby simp [integral_normalization, coeff_monomial, this, mem_support_iff] {contextual := tt}\n\nlemma integral_normalization_support {f : R[X]} :\n  (integral_normalization f).support \u2286 f.support :=\nby { intro, simp [integral_normalization, coeff_monomial, mem_support_iff] {contextual := tt} }\n\nlemma integral_normalization_coeff_degree {f : R[X]} {i : \u2115} (hi : f.degree = i) :\n  (integral_normalization f).coeff i = 1 :=\nby rw [integral_normalization_coeff, if_pos hi]\n\nlemma integral_normalization_coeff_nat_degree {f : R[X]} (hf : f \u2260 0) :\n  (integral_normalization f).coeff (nat_degree f) = 1 :=\nintegral_normalization_coeff_degree (degree_eq_nat_degree hf)\n\nlemma integral_normalization_coeff_ne_degree {f : R[X]} {i : \u2115} (hi : f.degree \u2260 i) :\n  coeff (integral_normalization f) i = coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i) :=\nby rw [integral_normalization_coeff, if_neg hi]\n\nlemma integral_normalization_coeff_ne_nat_degree\n  {f : R[X]} {i : \u2115} (hi : i \u2260 nat_degree f) :\n  coeff (integral_normalization f) i = coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i) :=\nintegral_normalization_coeff_ne_degree (degree_ne_of_nat_degree_ne hi.symm)\n\nlemma monic_integral_normalization {f : R[X]} (hf : f \u2260 0) :\n  monic (integral_normalization f) :=\nmonic_of_degree_le f.nat_degree\n  (finset.sup_le $ \u03bb i h, with_bot.coe_le_coe.2 $\n    le_nat_degree_of_mem_supp i $ integral_normalization_support h)\n  (integral_normalization_coeff_nat_degree hf)\n\nend semiring\n\nsection is_domain\nvariables [ring R] [is_domain R]\n\n@[simp] lemma support_integral_normalization {f : R[X]} :\n  (integral_normalization f).support = f.support :=\nbegin\n  by_cases hf : f = 0, { simp [hf] },\n  ext i,\n  refine \u27e8\u03bb h, integral_normalization_support h, _\u27e9,\n  simp only [integral_normalization_coeff, mem_support_iff],\n  intro hfi,\n  split_ifs with hi; simp [hfi, hi, pow_ne_zero _ (leading_coeff_ne_zero.mpr hf)]\nend\nend is_domain\n\nsection is_domain\nvariables [comm_ring R] [is_domain R]\nvariables [comm_ring S]\n\nlemma integral_normalization_eval\u2082_eq_zero {p : R[X]} (f : R \u2192+* S)\n  {z : S} (hz : eval\u2082 f z p = 0) (inj : \u2200 (x : R), f x = 0 \u2192 x = 0) :\n  eval\u2082 f (z * f p.leading_coeff) (integral_normalization p) = 0 :=\ncalc eval\u2082 f (z * f p.leading_coeff) (integral_normalization p)\n    = p.support.attach.sum\n        (\u03bb i, f (coeff (integral_normalization p) i.1 * p.leading_coeff ^ i.1) * z ^ i.1) :\n      by { rw [eval\u2082, sum_def, support_integral_normalization],\n           simp only [mul_comm z, mul_pow, mul_assoc, ring_hom.map_pow, ring_hom.map_mul],\n           exact finset.sum_attach.symm }\n... = p.support.attach.sum\n        (\u03bb i, f (coeff p i.1 * p.leading_coeff ^ (nat_degree p - 1)) * z ^ i.1) :\n      begin\n        by_cases hp : p = 0, { simp [hp] },\n        have one_le_deg : 1 \u2264 nat_degree p :=\n          nat.succ_le_of_lt (nat_degree_pos_of_eval\u2082_root hp f hz inj),\n        congr' with i,\n        congr' 2,\n        by_cases hi : i.1 = nat_degree p,\n        { rw [hi, integral_normalization_coeff_degree, one_mul, leading_coeff, \u2190pow_succ,\n              tsub_add_cancel_of_le one_le_deg],\n          exact degree_eq_nat_degree hp },\n        { have : i.1 \u2264 p.nat_degree - 1 := nat.le_pred_of_lt (lt_of_le_of_ne\n            (le_nat_degree_of_ne_zero (mem_support_iff.mp i.2)) hi),\n          rw [integral_normalization_coeff_ne_nat_degree hi, mul_assoc, \u2190pow_add,\n              tsub_add_cancel_of_le this] }\n      end\n... = f p.leading_coeff ^ (nat_degree p - 1) * eval\u2082 f z p :\n      by { simp_rw [eval\u2082, sum_def, \u03bb i, mul_comm (coeff p i), ring_hom.map_mul,\n                    ring_hom.map_pow, mul_assoc, \u2190finset.mul_sum],\n           congr' 1,\n           exact @finset.sum_attach _ _ p.support _ (\u03bb i, f (p.coeff i) * z ^ i) }\n... = 0 : by rw [hz, _root_.mul_zero]\n\n\n\nend is_domain\n\nend integral_normalization\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/polynomial/integral_normalization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7266265138204352}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Robert Y. Lewis\n\n! This file was ported from Lean 3 source module data.mv_polynomial.expand\n! leanprover-community/mathlib commit 5da451b4c96b4c2e122c0325a7fce17d62ee46c6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.MvPolynomial.Monad\n\n/-!\n## Expand multivariate polynomials\n\nGiven a multivariate polynomial `\u03c6`, one may replace every occurence of `X i` by `X i ^ n`,\nfor some natural number `n`.\nThis operation is called `mv_polynomial.expand` and it is an algebra homomorphism.\n\n### Main declaration\n\n* `mv_polynomial.expand`: expand a polynomial by a factor of p, so `\u2211 a\u2099 x\u207f` becomes `\u2211 a\u2099 x\u207f\u1d56`.\n-/\n\n\nopen BigOperators\n\nnamespace MvPolynomial\n\nvariable {\u03c3 \u03c4 R S : Type _} [CommSemiring R] [CommSemiring S]\n\n/-- Expand the polynomial by a factor of p, so `\u2211 a\u2099 x\u207f` becomes `\u2211 a\u2099 x\u207f\u1d56`.\n\nSee also `polynomial.expand`. -/\nnoncomputable def expand (p : \u2115) : MvPolynomial \u03c3 R \u2192\u2090[R] MvPolynomial \u03c3 R :=\n  { (eval\u2082Hom C fun i => X i ^ p : MvPolynomial \u03c3 R \u2192+* MvPolynomial \u03c3 R) with\n    commutes' := fun r => eval\u2082Hom_C _ _ _ }\n#align mv_polynomial.expand MvPolynomial.expand\n\n@[simp]\ntheorem expand_c (p : \u2115) (r : R) : expand p (C r : MvPolynomial \u03c3 R) = C r :=\n  eval\u2082Hom_C _ _ _\n#align mv_polynomial.expand_C MvPolynomial.expand_c\n\n@[simp]\ntheorem expand_x (p : \u2115) (i : \u03c3) : expand p (X i : MvPolynomial \u03c3 R) = X i ^ p :=\n  eval\u2082Hom_X' _ _ _\n#align mv_polynomial.expand_X MvPolynomial.expand_x\n\n@[simp]\ntheorem expand_monomial (p : \u2115) (d : \u03c3 \u2192\u2080 \u2115) (r : R) :\n    expand p (monomial d r) = C r * \u220f i in d.support, (X i ^ p) ^ d i :=\n  bind\u2081_monomial _ _ _\n#align mv_polynomial.expand_monomial MvPolynomial.expand_monomial\n\ntheorem expand_one_apply (f : MvPolynomial \u03c3 R) : expand 1 f = f := by\n  simp only [expand, bind\u2081_X_left, AlgHom.id_apply, RingHom.toFun_eq_coe, eval\u2082_hom_C_left,\n    AlgHom.coe_toRingHom, pow_one, AlgHom.coe_mks]\n#align mv_polynomial.expand_one_apply MvPolynomial.expand_one_apply\n\n@[simp]\ntheorem expand_one : expand 1 = AlgHom.id R (MvPolynomial \u03c3 R) :=\n  by\n  ext1 f\n  rw [expand_one_apply, AlgHom.id_apply]\n#align mv_polynomial.expand_one MvPolynomial.expand_one\n\ntheorem expand_comp_bind\u2081 (p : \u2115) (f : \u03c3 \u2192 MvPolynomial \u03c4 R) :\n    (expand p).comp (bind\u2081 f) = bind\u2081 fun i => expand p (f i) :=\n  by\n  apply alg_hom_ext\n  intro i\n  simp only [AlgHom.comp_apply, bind\u2081_X_right]\n#align mv_polynomial.expand_comp_bind\u2081 MvPolynomial.expand_comp_bind\u2081\n\ntheorem expand_bind\u2081 (p : \u2115) (f : \u03c3 \u2192 MvPolynomial \u03c4 R) (\u03c6 : MvPolynomial \u03c3 R) :\n    expand p (bind\u2081 f \u03c6) = bind\u2081 (fun i => expand p (f i)) \u03c6 := by\n  rw [\u2190 AlgHom.comp_apply, expand_comp_bind\u2081]\n#align mv_polynomial.expand_bind\u2081 MvPolynomial.expand_bind\u2081\n\n@[simp]\ntheorem map_expand (f : R \u2192+* S) (p : \u2115) (\u03c6 : MvPolynomial \u03c3 R) :\n    map f (expand p \u03c6) = expand p (map f \u03c6) := by simp [expand, map_bind\u2081]\n#align mv_polynomial.map_expand MvPolynomial.map_expand\n\n@[simp]\ntheorem rename_expand (f : \u03c3 \u2192 \u03c4) (p : \u2115) (\u03c6 : MvPolynomial \u03c3 R) :\n    rename f (expand p \u03c6) = expand p (rename f \u03c6) := by simp [expand, bind\u2081_rename, rename_bind\u2081]\n#align mv_polynomial.rename_expand MvPolynomial.rename_expand\n\n@[simp]\ntheorem rename_comp_expand (f : \u03c3 \u2192 \u03c4) (p : \u2115) :\n    (rename f).comp (expand p) =\n      (expand p).comp (rename f : MvPolynomial \u03c3 R \u2192\u2090[R] MvPolynomial \u03c4 R) :=\n  by\n  ext1 \u03c6\n  simp only [rename_expand, AlgHom.comp_apply]\n#align mv_polynomial.rename_comp_expand MvPolynomial.rename_comp_expand\n\nend MvPolynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/MvPolynomial/Expand.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7266265037509325}}
{"text": "/-\nThe \"exact\" and \"apply\" tactics construct proofs\nof the current goal. \n\nThe exact tactic is meant to be given a *complete* \nproof term, with no remaining holes (placeholders)\nthat remain to be filled in. \n\nThe apply tactic will accept a complete proof term,\nand so can be used anywhere \"exact\" is used, but it\nis reall meant to accept proof terms with holes that\nremain to be filled in with actual values. These \nholes are generally arguments that need to be provided\nto some inference rule, or proof of an implication or\ngeneralization, for it to construct a final, complete\nproof. \n\nLet's see some simple examples. (We start by stating\nthat P Q and R should be treated as variables of type\nProp).\n-/\n\nvariables P Q R : Prop  -- assume these are props\n\n\n/-\nNow recall the inference rule for \u2227. \n\n(p : Q) (q : Q) \u22a2 (pq : P \u2227 Q) [and.intro]\n\nIn other words, and.intro is a procedure\nthat *takes* two arguments, here called p\nand q, and *constructs* a proof of P \u2227 Q. \n-/\n\n\n-- an example using exact\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  assume (p : P) (q :Q),\n  exact (and.intro p q),\n  -- QED!\nend\n\n-- an example using apply\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  assume (p : P) (q :Q),\n  apply (and.intro _ _),\n  -- The _'s become subgoals\n  exact p,\n  exact q,\n  -- This is top-down structured decomposition\nend\n\n-- you can leave out the _ _ by the way\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  assume (p : P) (q :Q),\n  apply (and.intro),      -- _ _ left out\n  exact p,                -- now we fill holes \n  exact q,\nend\n\n-- You can even provide *some* arguments!\n\n-- you can leave out the _ _ by the way\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  assume (p : P) (q :Q),\n  apply (and.intro _ q),      -- _ _ left out\n  exact p,                -- now we fill holes \nend\n\nexample : P \u2194 Q :=\nbegin\n  apply iff.intro _ _,\nend ", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/99_Lean_Prover/03_Proof_Tactics/02_exact_apply.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8175744784160989, "lm_q1q2_score": 0.726626502209425}}
{"text": "import set_theory.pgame\n\nuniverse u\n\n/-!\n# Basic definitions about who has a winning stratergy\n\nWe define `G.p_position`, `G.n_position`, `G.l_position` and `G.r_position`\nfor a pgame `G`, which means the second, first, left and right players\nhave a winning stratergy respectivly. \nThese are defined by inequalities which can be unfolded with, `pgame.lt_def`\nand `pgame.le_def`.\n-/\n\nnamespace pgame\n\nlocal infix ` \u2248 ` := pgame.equiv\n\n/-- The player who goes first loses -/\ndef p_position (G : pgame) : Prop := G \u2264 0 \u2227 0 \u2264 G\n\n/-- The player who goes first wins -/\ndef n_position (G : pgame) : Prop := 0 < G \u2227 G < 0\n\n/-- The left player can always win -/\ndef l_position (G : pgame) : Prop := 0 < G \u2227 0 \u2264 G\n\n/-- The right player can always win -/\ndef r_position (G : pgame) : Prop := G \u2264 0 \u2227 G < 0\n\ntheorem zero_p_postition : p_position 0 := by tidy\ntheorem one_l_postition : l_position 1 := \nbegin\n    split,\n    rw lt_def_le,\n    tidy\nend\ntheorem star_n_postition : n_position star := \u27e8 zero_lt_star, star_lt_zero \u27e9\ntheorem omega_l_postition : l_position omega := \nbegin\n  split,\n    rw lt_def_le,\n    left,\n    use 0,\n  tidy\nend\n\nlemma position_cases (G : pgame) : G.l_position \u2228 G.r_position \u2228 G.p_position \u2228 G.n_position :=\nbegin\n  classical,\n  by_cases hpos : 0 < G;\n  by_cases hneg : G < 0;\n  { try { rw not_lt at hpos },\n    try { rw not_lt at hneg },\n    try { left, exact \u27e8 hpos, hneg \u27e9 },\n    try { right, left, exact \u27e8 hpos, hneg \u27e9 },\n    try { right, right, left, exact \u27e8 hpos, hneg \u27e9 },\n    try { right, right, right, exact \u27e8 hpos, hneg \u27e9 } }\nend\n\nlemma p_position_is_zero {G : pgame} : G.p_position \u2194 G \u2248 0 := by refl\n\nlemma p_position_of_equiv {G H : pgame} (h : G \u2248 H) : G.p_position \u2192 H.p_position :=\n\u03bb hGp, \u27e8 le_of_equiv_of_le h.symm hGp.1, le_of_le_of_equiv hGp.2 h \u27e9\nlemma n_position_of_equiv {G H : pgame} (h : G \u2248 H) : G.n_position \u2192 H.n_position :=\n\u03bb hGn, \u27e8 lt_of_lt_of_equiv hGn.1 h, lt_of_equiv_of_lt h.symm hGn.2 \u27e9\nlemma l_position_of_equiv {G H : pgame} (h : G \u2248 H) : G.l_position \u2192 H.l_position :=\n\u03bb hGl, \u27e8 lt_of_lt_of_equiv hGl.1 h, le_of_le_of_equiv hGl.2 h \u27e9\nlemma r_position_of_equiv {G H : pgame} (h : G \u2248 H) : G.r_position \u2192 H.r_position :=\n\u03bb hGr, \u27e8 le_of_equiv_of_le h.symm hGr.1, lt_of_equiv_of_lt h.symm hGr.2 \u27e9\n\nlemma p_position_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.p_position \u2194 H.p_position :=\n\u27e8 p_position_of_equiv h, p_position_of_equiv h.symm \u27e9\nlemma n_position_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.n_position \u2194 H.n_position :=\n\u27e8 n_position_of_equiv h, n_position_of_equiv h.symm \u27e9\nlemma l_position_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.l_position \u2194 H.l_position :=\n\u27e8 l_position_of_equiv h, l_position_of_equiv h.symm \u27e9\nlemma r_position_of_equiv_iff {G H : pgame} (h : G \u2248 H) : G.r_position \u2194 H.r_position :=\n\u27e8 r_position_of_equiv h, r_position_of_equiv h.symm \u27e9 \n\nend pgame", "meta": {"author": "foxthomson", "repo": "impartial", "sha": "5f8b405dbbd864682f1ccd30ff7504a23bb20a42", "save_path": "github-repos/lean/foxthomson-impartial", "path": "github-repos/lean/foxthomson-impartial/impartial-5f8b405dbbd864682f1ccd30ff7504a23bb20a42/src/position.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7266163331289546}}
{"text": "-- BOTH:\nimport data.real.basic\nimport data.nat.prime\n\n/- TEXT:\n.. _conjunction_and_biimplication:\n\nConjunction and Bi-implication\n------------------------------\n\n.. index:: split, tactics ; split\n\nYou have already seen that the conjunction symbol, ``\u2227``,\nis used to express \"and.\"\nThe ``split`` tactic allows you to prove a statement of\nthe form ``A \u2227 B``\nby proving ``A`` and then proving ``B``.\nTEXT. -/\n-- QUOTE:\nexample {x y : \u211d} (h\u2080 : x \u2264 y) (h\u2081 : \u00ac y \u2264 x) : x \u2264 y \u2227 x \u2260 y :=\nbegin\n  split,\n  { assumption },\n  intro h,\n  apply h\u2081,\n  rw h\nend\n-- QUOTE.\n\n/- TEXT:\n.. index:: assumption, tactics ; assumption\n\nIn this example, the ``assumption`` tactic\ntells Lean to find an assumption that will solve the goal.\nNotice that the final ``rw`` finishes the goal by\napplying the reflexivity of ``\u2264``.\nThe following are alternative ways of carrying out\nthe previous examples using the anonymous constructor\nangle brackets.\nThe first is a slick proof-term version of the\nprevious proof,\nwhich drops into tactic mode at the keyword ``by``.\nTEXT. -/\n-- QUOTE:\nexample {x y : \u211d} (h\u2080 : x \u2264 y) (h\u2081 : \u00ac y \u2264 x) : x \u2264 y \u2227 x \u2260 y :=\n\u27e8h\u2080, \u03bb h, h\u2081 (by rw h)\u27e9\n\nexample {x y : \u211d} (h\u2080 : x \u2264 y) (h\u2081 : \u00ac y \u2264 x) : x \u2264 y \u2227 x \u2260 y :=\nbegin\n  have h : x \u2260 y,\n  { contrapose! h\u2081,\n    rw h\u2081 },\n  exact \u27e8h\u2080, h\u27e9\nend\n-- QUOTE.\n\n/- TEXT:\n*Using* a conjunction instead of proving one involves unpacking the proofs of the\ntwo parts.\nYou can use the ``cases`` tactic for that,\nas well as ``rcases``, ``rintros``, or a pattern-matching lambda,\nall in a manner similar to the way they are used with\nthe existential quantifier.\nTEXT. -/\n-- QUOTE:\nexample {x y : \u211d} (h : x \u2264 y \u2227 x \u2260 y) : \u00ac y \u2264 x :=\nbegin\n  cases h with h\u2080 h\u2081,\n  contrapose! h\u2081,\n  exact le_antisymm h\u2080 h\u2081\nend\n\nexample {x y : \u211d} : x \u2264 y \u2227 x \u2260 y \u2192 \u00ac y \u2264 x :=\nbegin\n  rintros \u27e8h\u2080, h\u2081\u27e9 h',\n  exact h\u2081 (le_antisymm h\u2080 h')\nend\n\nexample {x y : \u211d} : x \u2264 y \u2227 x \u2260 y \u2192 \u00ac y \u2264 x :=\n\u03bb \u27e8h\u2080, h\u2081\u27e9 h', h\u2081 (le_antisymm h\u2080 h')\n-- QUOTE.\n\n/- TEXT:\nIn contrast to using an existential quantifier,\nyou can also extract proofs of the two components\nof a hypothesis ``h : A \u2227 B``\nby writing ``h.left`` and ``h.right``,\nor, equivalently, ``h.1`` and ``h.2``.\nTEXT. -/\n-- QUOTE:\nexample {x y : \u211d} (h : x \u2264 y \u2227 x \u2260 y) : \u00ac y \u2264 x :=\nbegin\n  intro h',\n  apply h.right,\n  exact le_antisymm h.left h'\nend\n\nexample {x y : \u211d} (h : x \u2264 y \u2227 x \u2260 y) : \u00ac y \u2264 x :=\n\u03bb h', h.right (le_antisymm h.left h')\n-- QUOTE.\n\n/- TEXT:\nTry using these techniques to come up with various ways of proving of the following:\nTEXT. -/\n-- QUOTE:\nexample {m n : \u2115} (h : m \u2223 n \u2227 m \u2260 n) :\n  m \u2223 n \u2227 \u00ac n \u2223 m :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample {m n : \u2115} (h : m \u2223 n \u2227 m \u2260 n) :\n  m \u2223 n \u2227 \u00ac n \u2223 m :=\nbegin\n  cases h with h0 h1,\n  split,\n  { exact h0 },\n  intro h2,\n  apply h1,\n  apply nat.dvd_antisymm h0 h2,\nend\n\n/- TEXT:\nYou can nest uses of ``\u2203`` and ``\u2227``\nwith anonymous constructors, ``rintros``, and ``rcases``.\nTEXT. -/\n-- QUOTE:\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 4 :=\n\u27e85/2, by norm_num, by norm_num\u27e9\n\nexample (x y : \u211d) : (\u2203 z : \u211d, x < z \u2227 z < y) \u2192 x < y :=\nbegin\n  rintros \u27e8z, xltz, zlty\u27e9,\n  exact lt_trans xltz zlty\nend\n\nexample (x y : \u211d) : (\u2203 z : \u211d, x < z \u2227 z < y) \u2192 x < y :=\n\u03bb \u27e8z, xltz, zlty\u27e9, lt_trans xltz zlty\n-- QUOTE.\n\n/- TEXT:\nYou can also use the ``use`` tactic:\nTEXT. -/\n-- QUOTE:\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 4 :=\nbegin\n  use 5 / 2,\n  split; norm_num\nend\n\nexample : \u2203 m n : \u2115,\n  4 < m \u2227 m < n \u2227 n < 10 \u2227 nat.prime m \u2227 nat.prime n :=\nbegin\n  use [5, 7],\n  norm_num\nend\n\nexample {x y : \u211d} : x \u2264 y \u2227 x \u2260 y \u2192 x \u2264 y \u2227 \u00ac y \u2264 x :=\nbegin\n  rintros \u27e8h\u2080, h\u2081\u27e9,\n  use [h\u2080, \u03bb h', h\u2081 (le_antisymm h\u2080 h')]\nend\n-- QUOTE.\n\n/- TEXT:\nIn the first example, the semicolon after the ``split`` command tells Lean to use the\n``norm_num`` tactic on both of the goals that result.\n\nIn Lean, ``A \u2194 B`` is *not* defined to be ``(A \u2192 B) \u2227 (B \u2192 A)``,\nbut it could have been,\nand it behaves roughly the same way.\nYou have already seen that you can write ``h.mp`` and ``h.mpr``\nor ``h.1`` and ``h.2`` for the two directions of ``h : A \u2194 B``.\nYou can also use ``cases`` and friends.\nTo prove an if-and-only-if statement,\nyou can uses ``split`` or angle brackets,\njust as you would if you were proving a conjunction.\nTEXT. -/\n-- QUOTE:\nexample {x y : \u211d} (h : x \u2264 y) : \u00ac y \u2264 x \u2194 x \u2260 y :=\nbegin\n  split,\n  { contrapose!,\n    rintro rfl,\n    reflexivity },\n  contrapose!,\n  exact le_antisymm h\nend\n\nexample {x y : \u211d} (h : x \u2264 y) : \u00ac y \u2264 x \u2194 x \u2260 y :=\n\u27e8\u03bb h\u2080 h\u2081, h\u2080 (by rw h\u2081), \u03bb h\u2080 h\u2081, h\u2080 (le_antisymm h h\u2081)\u27e9\n-- QUOTE.\n\n/- TEXT:\nThe last proof term is inscrutable. Remember that you can\nuse underscores while writing an expression like that to\nsee what Lean expects.\n\nTry out the various techniques and gadgets you have just seen\nin order to prove the following:\nTEXT. -/\n-- QUOTE:\nexample {x y : \u211d} : x \u2264 y \u2227 \u00ac y \u2264 x \u2194 x \u2264 y \u2227 x \u2260 y :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample {x y : \u211d} : x \u2264 y \u2227 \u00ac y \u2264 x \u2194 x \u2264 y \u2227 x \u2260 y :=\nbegin\n  split,\n  { rintros \u27e8h0, h1\u27e9,\n    split,\n    { exact h0 },\n    intro h2,\n    apply h1,\n    rw h2 },\n  rintros \u27e8h0, h1\u27e9,\n  split,\n  { exact h0 },\n  intro h2,\n  apply h1,\n  apply le_antisymm h0 h2\nend\n\n/- TEXT:\nFor a more interesting exercise, show that for any\ntwo real numbers ``x`` and ``y``,\n``x^2 + y^2 = 0`` if and only if ``x = 0`` and ``y = 0``.\nWe suggest proving an auxiliary lemma using\n``linarith``, ``pow_two_nonneg``, and ``pow_eq_zero``.\nTEXT. -/\n-- QUOTE:\ntheorem aux {x y : \u211d} (h : x^2 + y^2 = 0) : x = 0 :=\nbegin\n  have h' : x^2 = 0,\n  { sorry },\n  exact pow_eq_zero h'\nend\n\nexample (x y : \u211d) : x^2 + y^2 = 0 \u2194 x = 0 \u2227 y = 0 :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem aux\u03b1\u03b1 {x y : \u211d} (h : x^2 + y^2 = 0) : x = 0 :=\nbegin\n  have h' : x^2 = 0,\n  { linarith [pow_two_nonneg x, pow_two_nonneg y] },\n  exact pow_eq_zero h'\nend\n\nexample (x y : \u211d) : x^2 + y^2 = 0 \u2194 x = 0 \u2227 y = 0 :=\nbegin\n  split,\n  { intro h,\n    split,\n    { exact aux h },\n    rw add_comm at h,\n    exact aux h },\n  rintros \u27e8rfl, rfl\u27e9,\n  norm_num\nend\n\n/- TEXT:\nIn Lean, bi-implication leads a double-life.\nYou can treat it like a conjunction and use its two\nparts separately.\nBut Lean also knows that it is a reflexive, symmetric,\nand transitive relation between propositions,\nand you can also use it with ``calc`` and ``rw``.\nIt is often convenient to rewrite a statement to\nan equivalent one.\nIn the next example, we use ``abs_lt`` to\nreplace an expression of the form ``abs x < y``\nby the equivalent expression ``- y < x \u2227 x < y``,\nand in the one after that we use ``nat.dvd_gcd_iff``\nto replace an expression of the form ``m \u2223 nat.gcd n k`` by the equivalent expression ``m \u2223 n \u2227 m \u2223 k``.\nTEXT. -/\nsection\n\n-- QUOTE:\nexample (x y : \u211d) : abs (x + 3) < 5 \u2192 -8 < x \u2227 x < 2 :=\nbegin\n  rw abs_lt,\n  intro h,\n  split; linarith\nend\n\nexample : 3 \u2223 nat.gcd 6 15 :=\nbegin\n  rw nat.dvd_gcd_iff,\n  split; norm_num\nend\n-- QUOTE.\n\nend\n\n/- TEXT:\nSee if you can use ``rw`` with the theorem below\nto provide a short proof that negation is not a\nnondecreasing function. (Note that ``push_neg`` won't\nunfold definitions for you, so the ``rw monotone`` in\nthe proof of the theorem is needed.)\nBOTH: -/\n-- QUOTE:\ntheorem not_monotone_iff {f : \u211d \u2192 \u211d}:\n  \u00ac monotone f \u2194 \u2203 x y, x \u2264 y \u2227 f x > f y :=\nby { rw monotone, push_neg }\n\n-- EXAMPLES:\nexample : \u00ac monotone (\u03bb x : \u211d, -x) :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : \u00ac monotone (\u03bb x : \u211d, -x) :=\nbegin\n  rw not_monotone_iff,\n  use [0, 1],\n  norm_num\nend\n\n/- TEXT:\nThe remaining exercises in this section are designed\nto give you some more practice with conjunction and\nbi-implication. Remember that a *partial order* is a\nbinary relation that is transitive, reflexive, and\nantisymmetric.\nAn even weaker notion sometimes arises:\na *preorder* is just a reflexive, transitive relation.\nFor any pre-order ``\u2264``,\nLean axiomatizes the associated strict pre-order by\n``a < b \u2194 a \u2264 b \u2227 \u00ac b \u2264 a``.\nShow that if ``\u2264`` is a partial order,\nthen ``a < b`` is equivalent to ``a \u2264 b \u2227 a \u2260 b``:\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {\u03b1 : Type*} [partial_order \u03b1]\nvariables a b : \u03b1\n\n-- EXAMPLES:\nexample : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\nbegin\n  rw lt_iff_le_not_le,\n  sorry\nend\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\nbegin\n  rw lt_iff_le_not_le,\n  split,\n  { rintros \u27e8h0, h1\u27e9,\n    split,\n    { exact h0 },\n    intro h2,\n    apply h1,\n    rw h2 },\n  rintros \u27e8h0, h1\u27e9,\n  split,\n  { exact h0 },\n  intro h2,\n  apply h1,\n  apply le_antisymm h0 h2\nend\n\n-- BOTH:\nend\n\n/- TEXT:\n.. index:: simp, tactics ; simp\n\nBeyond logical operations, you should not need\nanything more than ``le_refl`` and ``le_antisymm``.\nThen show that even in the case where ``\u2264``\nis only assumed to be a preorder,\nwe can prove that the strict order is irreflexive\nand transitive.\nYou do not need anything more than ``le_refl`` and ``le_trans``.\nIn the second example,\nfor convenience, we use the simplifier rather than ``rw``\nto express ``<`` in terms of ``\u2264`` and ``\u00ac``.\nWe will come back to the simplifier later,\nbut here we are only relying on the fact that it will\nuse the indicated lemma repeatedly, even if it needs\nto be instantiated to different values.\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {\u03b1 : Type*} [preorder \u03b1]\nvariables a b c : \u03b1\n\n-- EXAMPLES:\nexample : \u00ac a < a :=\nbegin\n  rw lt_iff_le_not_le,\n  sorry\nend\n\nexample : a < b \u2192 b < c \u2192 a < c :=\nbegin\n  simp only [lt_iff_le_not_le],\n  sorry\nend\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : \u00ac a < a :=\nbegin\n  rw lt_iff_le_not_le,\n  rintros \u27e8h0, h1\u27e9,\n  exact h1 h0\nend\n\nexample : a < b \u2192 b < c \u2192 a < c :=\nbegin\n  simp only [lt_iff_le_not_le],\n  rintros \u27e8h0, h1\u27e9 \u27e8h2, h3\u27e9,\n  split,\n  { apply le_trans h0 h2 },\n  intro h4,\n  apply h1,\n  apply le_trans h2 h4\nend\n\n-- BOTH:\nend\n", "meta": {"author": "avigad", "repo": "mathematics_in_lean_source", "sha": "4eeb8c43762522c1acaa7f799599609d6a48f59e", "save_path": "github-repos/lean/avigad-mathematics_in_lean_source", "path": "github-repos/lean/avigad-mathematics_in_lean_source/mathematics_in_lean_source-4eeb8c43762522c1acaa7f799599609d6a48f59e/lean_source/03_Logic/source_04_Conjunction_and_Bi-implication.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.9019206692796966, "lm_q1q2_score": 0.7266163230792408}}
{"text": "import data.nat.prime\nimport data.rat.basic\nimport data.real.basic\nimport tactic\n\n-- could use:\n-- (univ : set X)\n-- to have X be recognized as a subset of X\n-- X has Type u for some universe u; it doesn't have type set X\n\ntheorem sqrt_two_irrational {a b : \u2115} (co : nat.gcd a b = 1) : a^2 \u2260 2 * b^2 :=\nbegin\n    intro h,\n    have h1 : 2 \u2223 a^2, simp [h],\n    have h2 : 2 \u2223 a, from nat.prime.dvd_of_dvd_pow nat.prime_two h1,\n    cases h2 with c aeq,\n    have h3 : 2 * ( 2 * c^2) = 2 * b^2,\n        by simp [eq.symm h, aeq]; \n           simp [nat.pow_succ, mul_comm, mul_assoc, mul_left_comm],\n    have h4 : 2 * c^2 = b^2,\n        from nat.eq_of_mul_eq_mul_left dec_trivial h3,\n    have h5 : 2 \u2223 b^2, by simp [eq.symm h4],\n    have hb : 2 \u2223 b, from nat.prime.dvd_of_dvd_pow nat.prime_two h5,\n    have ha : 2 \u2223 a, from nat.prime.dvd_of_dvd_pow nat.prime_two h1,\n    have h6 : 2 \u2223 nat.gcd a b, from nat.dvd_gcd ha hb,\n    have habs : 2 \u2223 (1 : \u2115), by \n        {rw co at h6, exact h6},\n    have h7 : \u00ac 2 \u2223 1, exact dec_trivial,\n    exact h7 habs, done\nend\n\n-- Some simple preliminary results. Not really needed, but they make the proof shorter\nlemma rat_times_rat (r : \u211a) : r * r * \u2191(r.denom) ^ 2 = \u2191(r.num) ^ 2 :=\nbegin\n    have h1 := @rat.mul_denom_eq_num r,\n    rw pow_two,\n    rw mul_assoc, rw \u2190 mul_assoc r r.denom r.denom,\n    rw h1, rw \u2190 mul_assoc, rw mul_comm, rw \u2190 mul_assoc,\n    rw mul_comm \u2191r.denom r, rw h1, rw pow_two, done\nend\n#check nat.coprime.pow\n#check nat.coprime.pow_left\n#check nat.coprime.dvd_of_dvd_mul_left\n#check nat.coprime.coprime_dvd_left\n\ntheorem rational_not_sqrt_two : \u00ac \u2203 r : \u211a, r ^ 2 = (2:\u211a)  := \nbegin\n    intro h,\n    cases h with r H,\n    let num := r.num, set den := r.denom with hden,\n    --explicitly build the hypothetical rational number r\n    have hr := @rat.num_denom r,\n    rw \u2190 hr at H, -- use it in the main assumption\n    -- now we can figure out some properties of r.num and r.denom\n    -- first off, the denominator is not zero; this is encoded in r.\n    have hdenom := r.pos,  -- the denom is actually positive\n    have hdne : r.denom \u2260 0, linarith, -- so it is non zero; linarith can handle that\n    set n := int.nat_abs num with hn1,\n    have hn : (n ^2 : \u2124) = num ^ 2,\n        norm_cast, rw \u2190 int.nat_abs_pow_two num, rw \u2190 int.coe_nat_pow,\n    have G : (2:\u211a) * (r.denom ^2) = (r.num ^ 2),\n        rw \u2190 H, norm_cast, simp,\n        rw pow_two r, simp * at *,\n        exact rat_times_rat r,\n    norm_cast at G,\n    rw \u2190 hn at G,\n    have g1 : nat.gcd n den = 1, \n        have g11 := r.cop, \n        unfold nat.coprime at g11,\n        have g12 := nat.coprime.pow_left 2 g11,\n        have g13 := nat.coprime.coprime_mul_left g12,\n        rw \u2190 hn1 at g13, exact g13,\n    have E := sqrt_two_irrational g1,\n    have g2 := G.symm, \n    norm_cast at g2,\n    done\nend\n\nexample (a b : \u211d) : a = b \u2192 a^2 = b^2 := by library_search\n\n-- some extra stuff on rationals from Zulip\n--import data.rat.basic tactic\n\nlemma rat_id01 {a b : \u2124} (hb0 : 0 < b) (h : nat.coprime a.nat_abs b.nat_abs) :\n  (a / b : \u211a).num = a \u2227 ((a / b : \u211a).denom : \u2124) = b :=\nbegin\n  lift b to \u2115 using le_of_lt hb0,\n  norm_cast at hb0 h,\n  rw [\u2190 rat.mk_eq_div, \u2190 rat.mk_pnat_eq a b hb0, rat.mk_pnat_num, rat.mk_pnat_denom,\n    pnat.mk_coe, h.gcd_eq_one, int.coe_nat_one, int.div_one, nat.div_one],\n  split; refl\nend\n\n--import data.rat.basic tactic\n\nlemma rat_id02 {a b : \u2124} (hb0 : 0 < b) (h : nat.coprime a.nat_abs b.nat_abs) :\n  (a / b : \u211a).num = a \u2227 ((a / b : \u211a).denom : \u2124) = b :=\nbegin\n  lift b to \u2115 using le_of_lt hb0,\n  norm_cast at hb0 h,\n  rw [\u2190 rat.mk_eq_div, \u2190 rat.mk_pnat_eq a b hb0],\n  split; simp [rat.mk_pnat_num, rat.mk_pnat_denom, h.gcd_eq_one]\nend", "meta": {"author": "stanescuUW", "repo": "numerical-analysis-with-Lean", "sha": "98e6974f8b68cc5232ceff40535d776a33444c73", "save_path": "github-repos/lean/stanescuUW-numerical-analysis-with-Lean", "path": "github-repos/lean/stanescuUW-numerical-analysis-with-Lean/numerical-analysis-with-Lean-98e6974f8b68cc5232ceff40535d776a33444c73/src/NewtonMethod/uwyo_sqrt2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.7266163204437641}}
{"text": "import Lean4Axiomatic.Rational.Impl.Fraction.Addition\nimport Lean4Axiomatic.Rational.Multiplication\n\nnamespace Lean4Axiomatic.Rational.Impl.Fraction\n\nopen Logic (AP)\nopen Signed (Positive)\n\nvariable {\u2115 : Type} [Natural \u2115]\nvariable {\u2124 : Type} [Integer (\u2115 := \u2115) \u2124]\n\n/-! ## Fraction multiplication -/\n\n/-- Multiplication of fractions. -/\ndef mul : Fraction \u2124 \u2192 Fraction \u2124 \u2192 Fraction \u2124\n| p//q, r//s => (p * r)//(q * s)\n\ninstance multiplication_ops : Multiplication.Ops (Fraction \u2124) := {\n  mul := mul\n}\n\n/--\nMultiplication of integer fractions is consistent with its equivalent on\nintegers.\n\n**Property intuition**: This must be true if we want integers to be represented\nas integer fractions.\n\n**Proof intuition**: Expand the definition of multiplication and use integer\nalgebra on the numerator and denominator.\n-/\ntheorem mul_compat_from_integer\n    {a b : \u2124} : from_integer (a * b) \u2243 from_integer a * from_integer b\n    := by\n  show (a * b)//1 \u2243 a//1 * b//1\n  have : a//1 * b//1 \u2243 (a * b)//1 := calc\n    a//1 * b//1      \u2243 _ := eqv_refl\n    (a * b)//(1 * 1) \u2243 _ := substD AA.identL\n    (a * b)//1       \u2243 _ := eqv_refl\n  exact eqv_symm this\n\n/--\nMultiplication of integer fractions is commutative.\n\n**Property intuition**: We'd expect this to be true due to the viewpoint that\nfractions are scaled integers.\n\n**Proof intuition**: Expand the definition of multiplication and use integer\nalgebra on the numerator and denominator.\n-/\ntheorem mul_comm {p q : Fraction \u2124} : p * q \u2243 q * p := by\n  revert p; intro (pn//pd); revert q; intro (qn//qd)\n  show pn//pd * qn//qd \u2243 qn//qd * pn//pd\n  calc\n    pn//pd * qn//qd      \u2243 _ := eqv_refl\n    (pn * qn)//(pd * qd) \u2243 _ := substN AA.comm\n    (qn * pn)//(pd * qd) \u2243 _ := substD AA.comm\n    (qn * pn)//(qd * pd) \u2243 _ := eqv_refl\n    qn//qd * pn//pd      \u2243 _ := eqv_refl\n\n/--\nReplacing the left operand in a product of fractions with an equivalent value\ngives an equivalent result.\n\n**Property intuition**: This must be true for multiplication on fractions to be\na valid function.\n\n**Proof intuition**: Expand all definitions in the hypotheses and goal until\nequivalences involving only integers are reached. Show the goal equivalence\nusing algebra and the equivalence from the `p\u2081 \u2243 p\u2082` hypothesis.\n-/\ntheorem mul_substL {p\u2081 p\u2082 q : Fraction \u2124} : p\u2081 \u2243 p\u2082 \u2192 p\u2081 * q \u2243 p\u2082 * q := by\n  revert p\u2081; intro (p\u2081n//p\u2081d); revert p\u2082; intro (p\u2082n//p\u2082d)\n  revert q; intro (qn//qd)\n  intro (_ : p\u2081n//p\u2081d \u2243 p\u2082n//p\u2082d)\n  show p\u2081n//p\u2081d * qn//qd \u2243 p\u2082n//p\u2082d * qn//qd\n  show (p\u2081n * qn)//(p\u2081d * qd) \u2243 (p\u2082n * qn)//(p\u2082d * qd)\n  show (p\u2081n * qn) * (p\u2082d * qd) \u2243 (p\u2082n * qn) * (p\u2081d * qd)\n  have : p\u2081n * p\u2082d \u2243 p\u2082n * p\u2081d := \u2039p\u2081n//p\u2081d \u2243 p\u2082n//p\u2082d\u203a\n  calc\n    (p\u2081n * qn) * (p\u2082d * qd) \u2243 _ := AA.expr_xxfxxff_lr_swap_rl\n    (p\u2081n * p\u2082d) * (qn * qd) \u2243 _ := AA.substL \u2039p\u2081n * p\u2082d \u2243 p\u2082n * p\u2081d\u203a\n    (p\u2082n * p\u2081d) * (qn * qd) \u2243 _ := AA.expr_xxfxxff_lr_swap_rl\n    (p\u2082n * qn) * (p\u2081d * qd) \u2243 _ := Rel.refl\n\n/--\nReplacing the right operand in a product of fractions with an equivalent value\ngives an equivalent result.\n\n**Property intuition**: This must be true for multiplication on fractions to be\na valid function.\n\n**Proof intuition**: Flip the product around using commutativity, perform left\nsubstitution, then flip it back.\n-/\ntheorem mul_substR {p q\u2081 q\u2082 : Fraction \u2124} : q\u2081 \u2243 q\u2082 \u2192 p * q\u2081 \u2243 p * q\u2082 := by\n  intro (_ : q\u2081 \u2243 q\u2082)\n  show p * q\u2081 \u2243 p * q\u2082\n  calc\n    p * q\u2081 \u2243 _ := mul_comm\n    q\u2081 * p \u2243 _ := mul_substL \u2039q\u2081 \u2243 q\u2082\u203a\n    q\u2082 * p \u2243 _ := mul_comm\n    p * q\u2082 \u2243 _ := eqv_refl\n\n/--\nFraction multiplication is associative.\n\n**Property intuition**: We'd expect this to be true due to the viewpoint that\nfractions are scaled integers.\n\n**Proof intuition**: Evaluate all multiplications until a single fraction is\nobtained. Associativity on its numerator and denominator gives the result.\n-/\ntheorem mul_assoc {p q r : Fraction \u2124} : (p * q) * r \u2243 p * (q * r) := by\n  revert p; intro (pn//pd); revert q; intro (qn//qd); revert r; intro (rn//rd)\n  show (pn//pd * qn//qd) * rn//rd \u2243 pn//pd * (qn//qd * rn//rd)\n  calc\n    (pn//pd * qn//qd) * rn//rd         \u2243 _ := eqv_refl\n    (pn * qn)//(pd * qd) * rn//rd      \u2243 _ := eqv_refl\n    ((pn * qn) * rn)//((pd * qd) * rd) \u2243 _ := substN AA.assoc\n    (pn * (qn * rn))//((pd * qd) * rd) \u2243 _ := substD AA.assoc\n    (pn * (qn * rn))//(pd * (qd * rd)) \u2243 _ := eqv_refl\n    pn//pd * (qn * rn)//(qd * rd)      \u2243 _ := eqv_refl\n    pn//pd * (qn//qd * rn//rd)         \u2243 _ := eqv_refl\n\n/--\nOne is the left multiplicative identity for fractions.\n\n**Property intuition**: We'd expect this to be true due to the viewpoint that\nfractions are scaled integers.\n\n**Proof intuition**: Evaluate the multiplication to obtain a single fraction.\nUse the integer multiplicative identity on its numerator and denominator.\n-/\ntheorem mul_identL {p : Fraction \u2124} : 1 * p \u2243 p := by\n  revert p; intro (pn//pd)\n  show 1 * pn//pd \u2243 pn//pd\n  calc\n    1 * pn//pd         \u2243 _ := eqv_refl\n    1//1 * pn//pd      \u2243 _ := eqv_refl\n    (1 * pn)//(1 * pd) \u2243 _ := substN AA.identL\n    pn//(1 * pd)       \u2243 _ := substD AA.identL\n    pn//pd             \u2243 _ := eqv_refl\n\n/--\nOne is the right multiplicative identity for fractions.\n\n**Property intuition**: We'd expect this to be true due to the viewpoint that\nfractions are scaled integers.\n\n**Proof intuition**: Follows from left identity via commutativity.\n-/\ntheorem mul_identR {p : Fraction \u2124} : p * 1 \u2243 p :=\n  eqv_trans mul_comm mul_identL\n\n/--\nA common factor on the left of the numerator and denominator can be removed.\n\n**Property and proof intuition**: A fraction of products, in the numerator and\ndenominator, is equivalent to a product of fractions of the factors. If the two\nfactors on the left of the numerator and denominator are the same, then the\ncorresponding fraction factor is equivalent to one, and doesn't contribute to\nthe result.\n-/\ntheorem cancelL\n    {a b c : \u2124} [AP (Positive a)] [AP (Positive c)] : (a * b)//(a * c) \u2243 b//c\n    := calc\n  (a * b)//(a * c) \u2243 _ := eqv_refl\n  a//a * b//c      \u2243 _ := mul_substL (eqv_one_iff_numer_eqv_denom.mpr Rel.refl)\n  1 * b//c         \u2243 _ := mul_identL\n  b//c             \u2243 _ := eqv_refl\n\n/--\nA common factor on the right of the numerator and denominator can be removed.\n\n**Property and proof intuition**: This follows from left-cancellation and\ncommutativity.\n-/\ntheorem cancelR\n    {a b c : \u2124} [AP (Positive a)] [AP (Positive c)] : (b * a)//(c * a) \u2243 b//c\n    := calc\n  (b * a)//(c * a) \u2243 _ := substN AA.comm\n  (a * b)//(c * a) \u2243 _ := substD AA.comm\n  (a * b)//(a * c) \u2243 _ := cancelL\n  b//c             \u2243 _ := eqv_refl\n\n/--\nAddition of fractions with the same denominator can be accomplished by adding\ntheir numerators.\n\n**Property intuition**: The numerators are at the same \"scale\" because the\ndenominators are the same, so they can be added as integers.\n\n**Proof intuition**: Evaluate the addition, then pull out the common factor of\n`d` in the numerator using integer distributivity. With a factor of `d` in the\nnumerator and denominator, the fraction is the result of multiplication by\n`d//d`, which is `1`. So the common factor can be removed, achieving the goal.\n-/\ntheorem add_eqv_denominators\n    {a b d : \u2124} [AP (Positive d)] : a//d + b//d \u2243 (a + b)//d\n    := calc\n  a//d + b//d\n    \u2243 _ := eqv_refl\n  (a * d + d * b)//(d * d)\n    \u2243 _ := substN (AA.substR AA.comm)\n  (a * d + b * d)//(d * d)\n    \u2243 _ := substN (Rel.symm AA.distribR)\n  ((a + b) * d)//(d * d)\n    \u2243 _ := cancelR\n  (a + b)//d\n    \u2243 _ := eqv_refl\n\n/--\nFraction multiplication (on the left) distributes over fraction addition.\n\n**Property intuition**: We'd expect this to be true due to the viewpoint that\nfractions are scaled integers.\n\n**Proof intuition**: Evaluate the addition and multiplication of the left-hand\nside to produce a single fraction. Use integer distributivity to make the\nnumerator a sum. Split the fraction into a sum of fractions with the same\ndenominator. Cancel common factors and separate each term into a product of the\ninput fractions.\n-/\ntheorem mul_distribL {p q r : Fraction \u2124} : p * (q + r) \u2243 p * q + p * r := by\n  revert p; intro (pn//pd); revert q; intro (qn//qd); revert r; intro (rn//rd)\n  show pn//pd * (qn//qd + rn//rd) \u2243 pn//pd * qn//qd + pn//pd * rn//rd\n  -- For some unknown reason this is needed to prevent a compile error\n  have pos_mul_denom_prq : AP (Positive (pd * (rd * qd))) := inferInstance\n  calc\n    pn//pd * (qn//qd + rn//rd)\n      \u2243 _ := eqv_refl\n    pn//pd * (qn * rd + qd * rn)//(qd * rd)\n      \u2243 _ := eqv_refl\n    (pn * (qn * rd + qd * rn))//(pd * (qd * rd))\n      \u2243 _ := substN AA.distribL\n    (pn * (qn * rd) + pn * (qd * rn))//(pd * (qd * rd))\n      \u2243 _ := eqv_symm add_eqv_denominators\n    (pn * (qn * rd))//(pd * (qd * rd)) + (pn * (qd * rn))//(pd * (qd * rd))\n      \u2243 _ := add_substL (substN (Rel.symm AA.assoc))\n    ((pn * qn) * rd)//(pd * (qd * rd)) + (pn * (qd * rn))//(pd * (qd * rd))\n      \u2243 _ := add_substL (substD (Rel.symm AA.assoc))\n    ((pn * qn) * rd)//((pd * qd) * rd) + (pn * (qd * rn))//(pd * (qd * rd))\n      \u2243 _ := add_substL cancelR\n    (pn * qn)//(pd * qd) + (pn * (qd * rn))//(pd * (qd * rd))\n      \u2243 _ := add_substR (substN (AA.substR AA.comm))\n    (pn * qn)//(pd * qd) + (pn * (rn * qd))//(pd * (qd * rd))\n      \u2243 _ := add_substR (substD (pb\u2082 := pos_mul_denom_prq) (AA.substR AA.comm))\n    (pn * qn)//(pd * qd) + (pn * (rn * qd))//(pd * (rd * qd))\n      \u2243 _ := add_substR (substN (Rel.symm AA.assoc))\n    (pn * qn)//(pd * qd) + ((pn * rn) * qd)//(pd * (rd * qd))\n      \u2243 _ := add_substR (substD (Rel.symm AA.assoc))\n    (pn * qn)//(pd * qd) + ((pn * rn) * qd)//((pd * rd) * qd)\n      \u2243 _ := add_substR cancelR\n    (pn * qn)//(pd * qd) + (pn * rn)//(pd * rd)\n      \u2243 _ := eqv_refl\n    pn//pd * qn//qd + (pn * rn)//(pd * rd)\n      \u2243 _ := eqv_refl\n    pn//pd * qn//qd + pn//pd * rn//rd\n      \u2243 _ := eqv_refl\n\n/--\nFraction multiplication (on the right) distributes over fraction addition.\n\n**Property intuition**: We'd expect this to be true due to the viewpoint that\nfractions are scaled integers.\n\n**Proof intuition**: Follows from left-distributivity and commutativity of\naddition and multiplication.\n-/\ntheorem mul_distribR {p q r : Fraction \u2124} : (q + r) * p \u2243 q * p + r * p := calc\n  (q + r) * p   \u2243 _ := mul_comm\n  p * (q + r)   \u2243 _ := mul_distribL\n  p * q + p * r \u2243 _ := add_substL mul_comm\n  q * p + p * r \u2243 _ := add_substR mul_comm\n  q * p + r * p \u2243 _ := eqv_refl\n\ninstance multiplication_props : Multiplication.Props (Fraction \u2124) := {\n  mul_substL := mul_substL\n  mul_substR := mul_substR\n  mul_compat_from_integer := mul_compat_from_integer\n  mul_comm := mul_comm\n  mul_assoc := mul_assoc\n  mul_identL := mul_identL\n  mul_identR := mul_identR\n  mul_distribL := mul_distribL\n  mul_distribR := mul_distribR\n}\n\ninstance multiplication : Multiplication (Fraction \u2124) := {\n  toOps := multiplication_ops\n  toProps := multiplication_props\n}\n\nend Lean4Axiomatic.Rational.Impl.Fraction\n", "meta": {"author": "cruhland", "repo": "lean4-axiomatic", "sha": "6384bd38b8ba104530247d25456858775fe3c442", "save_path": "github-repos/lean/cruhland-lean4-axiomatic", "path": "github-repos/lean/cruhland-lean4-axiomatic/lean4-axiomatic-6384bd38b8ba104530247d25456858775fe3c442/Lean4Axiomatic/Rational/Impl/Fraction/Multiplication.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7265916086500204}}
{"text": "/-\nCopyright (c) 2022 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen, Alex J. Best\n-/\n\nimport linear_algebra.determinant\nimport linear_algebra.free_module.finite.basic\n\n/-!\n# Determinants in free (finite) modules\n\nQuite a lot of our results on determinants (that you might know in vector spaces) will work for all\nfree (finite) modules over any commutative ring.\n\n## Main results\n\n * `linear_map.det_zero''`: The determinant of the constant zero map is zero, in a finite free\n   nontrivial module.\n-/\n\n@[simp] lemma linear_map.det_zero'' {R M : Type*} [comm_ring R] [add_comm_group M] [module R M]\n  [module.free R M] [module.finite R M] [nontrivial M] :\n  linear_map.det (0 : M \u2192\u2097[R] M) = 0 :=\nbegin\n  letI : nonempty (module.free.choose_basis_index R M) :=\n    (module.free.choose_basis R M).index_nonempty,\n  nontriviality R,\n  exact linear_map.det_zero' (module.free.choose_basis R M)\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/free_module/determinant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7265916005902077}}
{"text": "import linear_algebra.basic\nimport linear_algebra.basis\nopen linear_map\nopen is_basis\nuniverse variables u v w \nnamespace classical_basis\nset_option trace.simplify.rewrite true\nvariables {G : Type u} {R : Type v} [group G] [comm_ring R] \nvariables {X : Type w} [fintype X] [decidable_eq X] \n/-!\n    Definition of classical basis of `X \u2192 R`. \n    `\u03b5 x = \u03bb y, if x = y then 1 else 0`.\n-/\ndef \u03b5 {R : Type v}[comm_ring R]{X : Type w}(x : X) [fintype X] [decidable_eq X] : \n        (X \u2192 R) := (\u03bb y : X, if x = y then 1 else 0)\nvariable (x : X)\n#check \u03b5 x x     -- premier probleme est-ce que je dois mettre X et R ?\n                    -- C'est lourd\n\nlemma epsilon_eq (x : X) : \u03b5 x x = (1 : R) :=   --- un meilleur nom ! \nbegin \n    unfold \u03b5,simp, \nend\n/-!\n    On va integrer les sommes pour obtenir une formule du style \n    pour f : X \u2192 R , f = \u2211 \u03bb x, f x * (\u03b5  x) ! \n    C'est la d\u00e9composition dans la base \u03b5 ! \n-/\n@[simp]lemma epsilon_ne ( x y : X)(HYP : \u00ac y = x) : \u03b5 x y = (0 : R) := begin \n    unfold \u03b5, split_ifs, rw h at HYP, trivial,\n    exact rfl,\nend \n@[simp]lemma smul_ite (\u03c6 : X \u2192 R) ( y : X) : (\u03bb (x : X), \u03c6 x \u2022 (\u03b5 x y)) =  (\u03bb x : X, if y = x then \u03c6 x else 0) := begin \n    funext,\n    split_ifs, \n        rw h, rw epsilon_eq, exact mul_one (\u03c6 x),\n        rw epsilon_ne x y h,\n        exact mul_zero (\u03c6 x), \nend\nnotation `\u03a3` := finset.sum finset.univ \nlemma gen (\u03c6 : X \u2192 R) : \u03c6  = \u03a3 (\u03bb (x : X), \u03c6  x  \u2022 \u03b5  x) := \nbegin \n    funext y, \n    rw finset.sum_apply, \n    --change _ = \u03a3 (\u03bb x : X, \u03c6 x \u2022  \u03b5 x y),\n    erw smul_ite,\n    erw finset.sum_ite_eq,\n    split_ifs,exact rfl, \n    have R : y \u2208 finset.univ, exact finset.mem_univ y, trivial,\nend\n\n   \n#check is_basis R \u03b5 \n@[simp]lemma  test  (g : X \u2192 R)(s : finset X)(y \u2208  s) : \n        finset.sum s (\u03bb i : X, g i \u2022 (\u03b5  i : X \u2192 R) ) y = finset.sum s (\u03bb i : X, (g i \u2022 \u03b5 i) y) := \nbegin exact finset.sum_apply (\u03bb (i : X), R) (\u03bb (i : X), g i \u2022 \u03b5 i) y,\n    \nend\n@[simp]lemma classical_basis : is_basis R (\u03bb x : X, (\u03b5  x : X \u2192 R)) :=  --- c'est un peu chiant \nbegin\n    split,\n    rw linear_independent_iff', intros s, intros \u03c6, intros hyp, intros x, intros hyp_x, \n    rw function.funext_iff at hyp, specialize hyp x, \n    rw finset.sum_apply (\u03bb (i : X), R) _ _ at hyp,\n    change finset.sum s (\u03bb y : X, \u03c6 y \u2022 (\u03b5 y x : R)) = 0   at hyp,\n    rw smul_ite at hyp,\n    erw finset.sum_ite_eq at hyp, split_ifs at hyp,assumption,\n    rw eq_top_iff, rw submodule.le_def',\n    intros \u03c6, intros,\n    rw gen \u03c6,\n    let p := (submodule.span R (set.range (\u03bb (x : X), \u03b5 x))),\n    apply submodule.sum_mem p,\n    intros x, intros hyp,\n    apply submodule.smul_mem p, \n    have r : \u03b5 x \u2208 set.range (\u03bb (t : X), \u03b5 t), \n        rw set.mem_range,\n        use x,\n    have rr :  set.range (\u03bb (t : X), \u03b5 t) \u2286 \u2191p,\n        exact submodule.subset_span ,\n    have rrr : \u03b5 x \u2208 \u2191p,\n        exact set.mem_of_mem_of_subset r rr,\n    exact rrr,\nend   \nend classical_basis\n", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep1/matrix_representation_refondation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.7853085909370423, "lm_q1q2_score": 0.7265910338966889}}
{"text": "import Mathlib.Logic.Function.Basic\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Zify\nimport Playground.Data.GeneralDotNotation\n\nsection\n  namespace Function\n  noncomputable def right_inverse_of_surjective {f : \u03b1 \u2192 \u03b2} (h : Surjective f) \n    : \u03b2 \u2192 \u03b1 := \n    \u03bb y => (h y).choose\n\n  theorem right_inverse.is_RightInverse (h : Surjective f)\n    : RightInverse (right_inverse_of_surjective h) f := \n    \u03bb y => (h y).choose_spec\n\n  theorem right_inverse.is_injective (h : Surjective f)\n    : Injective (right_inverse_of_surjective h) :=\n    (is_RightInverse h).injective\n\n  end Function\nend\n\nsection\n  open Function\n\n  def finMapExcluding : (a : Fin (n + 1)) \u2192 { x : Fin (n + 1) // x \u2260 a } \u2192 Fin n\n    | \u27e8a, a_lt\u27e9, \u27e8\u27e8i, i_lt\u27e9, i_prop\u27e9 =>\n      have : i \u2260 a := \u03bb c => i_prop (Fin.eq_of_val_eq c)\n      if hi : i \u2264 a then\n        have := lt_of_le_of_ne hi this\n        { val := i, isLt := by linarith }\n      else\n        have : i > 0 := by linarith\n        { val := i - 1, isLt := by zify [this]; linarith }\n\n  theorem finMapExcluding_injective : \u2200 a : Fin (n + 1), (finMapExcluding a).Injective\n    | \u27e8a, a_lt\u27e9, \u27e8\u27e8i, i_lt\u27e9, i_prop\u27e9, \u27e8\u27e8j, j_lt\u27e9, j_prop\u27e9, (h : dite .. = dite ..) =>\n      if hi : i \u2264 a then\n        if hj : j \u2264 a then by\n          simp [hi, hj] at h\n          subst h; rfl\n        else by\n          simp [hi, hj] at h\n          have : j > 0 := by linarith\n          zify [this] at h\n          have : i = a := by linarith\n          subst this; contradiction\n      else \n        if hj : j \u2264 a then by\n          simp [hi, hj] at h\n          have : i > 0 := by linarith\n          zify [this] at h\n          have : j + 1 = i := by linarith\n          have : j = a := by linarith\n          subst this; contradiction\n        else by\n          simp [hi, hj] at h\n          have i_pos : i > 0 := by linarith\n          have j_pos : j > 0 := by linarith\n          zify [i_pos, j_pos] at h\n          have : i = j := by linarith\n          subst this; rfl\n\n  theorem le_of_injective {f : Fin n \u2192 Fin m} (hf : Injective f) : n \u2264 m :=\n    match n, m with\n    | 0, _ => Nat.zero_le _\n    | _ + 1, 0 => (Nat.not_lt_zero _ (f \u27e80, Nat.zero_lt_succ _\u27e9).isLt).elim\n    | n + 1, m + 1 =>\n      let a := f { val := n, isLt := by linarith }\n      let g\u2081 : Fin n \u2192 { x : Fin (m + 1) // x \u2260 a } :=\n        \u03bb { val := i, isLt := i_lt_n } => {\n          val := f { val := i, isLt := by linarith }\n          property := \u03bb c => Nat.ne_of_lt i_lt_n $ Fin.val_eq_of_eq $ hf c\n        }\n      have hg\u2081 : Injective g\u2081 := \u03bb i j h =>\n        have := Fin.val_eq_of_eq $ hf $ congrArg Subtype.val h\n        Fin.eq_of_val_eq this\n      let hg\u2082 := finMapExcluding_injective a\n      Nat.succ_le_succ <| le_of_injective <| Injective.comp hg\u2082 hg\u2081\n\n  theorem ge_of_surjective {f : Fin n \u2192 Fin m} (hf : Surjective f) : n \u2265 m :=\n    right_inverse.is_injective hf |> le_of_injective\n\n  theorem eq_of_bijective {f : Fin n \u2192 Fin m} (hf : Bijective f) : n = m := \n    (le_of_injective hf.injective)\u00b7le_antisymm (ge_of_surjective hf.surjective)\n\nexample (a b : \u2115) (h : a \u2264 b) (g : b \u2264 a) : a = b := by\n  -- linarith\n  sorry\nend\n\nsection\n  open Function\n\n  universe u\n  variable (type : Type u)\n\n  def has_card (n : Nat) := \u2203 f : Fin n \u2192 type, Bijective f\n\n  def is_finite := \u2203 n, type\u00b7has_card n\n\n  -- def Inhabited.has_card (type : Inhabited (Type u)) (n : Nat) := \u2203 f : Fin n \u2192 type.default, bijective f\n  -- def Inhabited.is_finite (type : Inhabited (Type u)) := \u2203 n, type.has_card n\n\n  noncomputable def card : Option Nat := \n    let this := Classical.propDecidable\n    if h : type\u00b7is_finite then some h.choose\n    else none\n\n  theorem has_card_unique (hn : type\u00b7has_card n) (hm : type\u00b7has_card m) \n    : n = m :=\n    let \u27e8fn, hfn\u27e9 := hn\n    let \u27e8fm, hfm\u27e9 := hm\n    sorry\n\nend", "meta": {"author": "michelsol", "repo": "lean-playground", "sha": "0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca", "save_path": "github-repos/lean/michelsol-lean-playground", "path": "github-repos/lean/michelsol-lean-playground/lean-playground-0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca/Playground/Data/FinType.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7265910338966889}}
{"text": "import Mathlib.Algebra.Group.Defs\nimport Mathlib.Logic.Basic\n\nsection AddCommSemigroup_lemmas\n\nvariable {A : Type u} [AddCommSemigroup A]\n\nlemma add_left_comm (a b c : A) : a + (b + c) = b + (a + c) :=\nby rw [\u2190 add_assoc, add_comm a, add_assoc]\n\nlemma add_right_comm (a b c : A) : a + b + c = a + c + b :=\nby rw [add_assoc, add_comm b, add_assoc]\n\ntheorem add_add_add_comm (a b c d : A) : (a + b) +(c + d) = (a + c) + (b + d) :=\nby simp [add_left_comm, add_assoc]\n\nend AddCommSemigroup_lemmas\n\nsection CommSemigroup_lemmas\n\nvariable {M : Type u} [CommSemigroup M]\n\ntheorem mul_mul_mul_comm (a b c d : M) : (a * b) * (c * d) = (a * c) * (b * d) :=\nby simp [mul_assoc, mul_left_comm]\n\nend CommSemigroup_lemmas\n\nsection AddLeftCancelMonoid_lemmas\n-- too lazy to do mul versions and right versions\n\nvariable {A : Type u} [AddMonoid A] [IsAddLeftCancel A] {a b : A}\n\nlemma add_right_eq_self : a + b = a \u2194 b = 0 :=\nby rw [\u2190add_left_cancel_iff (c := 0), add_zero]\n\nlemma self_eq_add_right : a = a + b \u2194 b = 0 :=\nby rw [\u2190add_left_cancel_iff (c := 0), add_zero, eq_comm]\n\nend AddLeftCancelMonoid_lemmas\n", "meta": {"author": "JOSHCLUNE", "repo": "Keller_reduction", "sha": "dc392b3da352fc1ffcfbecb1d4717d05f5faed4a", "save_path": "github-repos/lean/JOSHCLUNE-Keller_reduction", "path": "github-repos/lean/JOSHCLUNE-Keller_reduction/Keller_reduction-dc392b3da352fc1ffcfbecb1d4717d05f5faed4a/Lean4_Clique/Mathlib/Mathlib/Algebra/Group/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109622750986, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7265719982208256}}
{"text": "-- Exercise 1\n\nsection ex1\n\nvariables p q r : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\nhave beep : p \u2227 q \u2192 q \u2227 p, from \u03bb p_and_q : p \u2227 q, and.intro p_and_q.2 p_and_q.1,\nhave boop : q \u2227 p \u2192 p \u2227 q, from \u03bb q_and_p : q \u2227 p, and.intro q_and_p.2 q_and_p.1,\nshow p \u2227 q \u2194 q \u2227 p, from iff.intro beep boop\n\nexample : p \u2228 q \u2194 q \u2228 p :=\nhave beep : p \u2228 q \u2192 q \u2228 p, from \u03bb p_or_q : p \u2228 q,\n    or.elim\n        p_or_q\n        (or.intro_right q)\n        (or.intro_left p),\nhave boop : q \u2228 p \u2192 p \u2228 q, from \u03bb q_or_p : q \u2228 p,\n    or.elim\n        q_or_p\n        (or.intro_right p)\n        (or.intro_left q),\nshow p \u2228 q \u2194 q \u2228 p, from iff.intro beep boop\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\nhave group_left : (p \u2227 q) \u2227 r \u2192 p \u2227 (q \u2227 r), from (\n    \u03bb (left_grouped: (p \u2227 q) \u2227 r),\n    and.intro\n        left_grouped.elim_left.elim_left\n        (and.intro left_grouped.elim_left.elim_right left_grouped.elim_right)\n),\nhave group_right : p \u2227 (q \u2227 r) \u2192 (p \u2227 q) \u2227 r, from (\n    \u03bb (right_grouped: p \u2227 (q \u2227 r)),\n    and.intro\n        (and.intro right_grouped.elim_left right_grouped.elim_right.elim_left)\n        right_grouped.elim_right.elim_right\n),\nshow (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r), from iff.intro group_left group_right\n\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\nhave flattened_left : (p \u2228 q) \u2228 r \u2192 p \u2228 q \u2228 r, from (\n    \u03bb grouped, or.elim grouped\n        (\u03bb group,\n            or.elim group\n                (\u03bb (hp : p), or.inl hp)\n                (\u03bb (hq : q), or.inr (or.inl hq))\n            )\n        (\u03bb (hr : r), or.inr (or.inr hr))\n),\nhave unflattened_left : p \u2228 q \u2228 r \u2192 (p \u2228 q) \u2228 r, from (\n    \u03bb flat, or.elim flat\n        (\u03bb (hp : p), or.inl (or.inl hp))\n        (\u03bb (hqr : q \u2228 r), or.elim hqr\n            (\u03bb (hq : q), or.inl (or.inr hq))\n            (\u03bb (hr : r), or.inr hr)\n        )\n),\nhave flattened_right : p \u2228 (q \u2228 r) \u2192 p \u2228 q \u2228 r, from \u03bb a, a,\nhave unflattened_right : p \u2228 q \u2228 r \u2192 p \u2228 (q \u2228 r), from \u03bb a, a,\nhave left_flattens : (p \u2228 q) \u2228 r \u2194 p \u2228 q \u2228 r, from iff.intro flattened_left unflattened_left,\nhave right_flattens : p \u2228 (q \u2228 r) \u2194 p \u2228 q \u2228 r, from iff.intro flattened_right unflattened_right,\nshow (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r), from iff.trans left_flattens right_flattens\n\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\nhave expansion : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r), from (\n    \u03bb factorized,\n    let (hp : p) := factorized.left in\n    let (q_or_r_hypothesis : q \u2228 r) := factorized.right in\n    let (first_branch : q \u2192 (p \u2227 q) \u2228 (p \u2227 r)) := \u03bb hq,  or.intro_left (p \u2227 r) (and.intro hp hq) in\n    let (second_branch : r \u2192 p \u2227 q \u2228 p \u2227 r) := \u03bb hr, or.intro_right (p \u2227 q) (and.intro hp hr) in\n    or.elim\n        q_or_r_hypothesis\n        first_branch\n        second_branch\n),\nhave factorization : (p \u2227 q) \u2228 (p \u2227 r) \u2192 p \u2227 (q \u2228 r), from (\n    \u03bb expanded,\n    let (hp : p) := or.elim expanded and.left and.left in\n    let (extract_q : (p \u2227 q) \u2192 (q \u2228 r)) := \u03bb p_and_q, or.intro_left r (and.right p_and_q) in\n    let (extract_r : (p \u2227 r) \u2192 (q \u2228 r)) := \u03bb p_and_r, or.intro_right q (and.right p_and_r) in\n    let (q_or_r_hypothesis : q \u2228 r) := or.elim expanded extract_q extract_r in\n    and.intro hp q_or_r_hypothesis\n),\nshow p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r), from iff.intro expansion factorization\n\n\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\nhave expansion : p \u2228 (q \u2227 r) \u2192 (p \u2228 q) \u2227 (p \u2228 r), from (\n    \u03bb factorized,\n    let (p_or_q : (p \u2228 q)) := or.elim factorized (or.intro_left q) (\u03bb conj, or.intro_right p conj.left) in\n    let (p_or_r : (p \u2228 r)) := or.elim factorized (or.intro_left r) (\u03bb conj, or.intro_right p conj.right) in\n    and.intro p_or_q p_or_r\n),\nhave factorization : (p \u2228 q) \u2227 (p \u2228 r) \u2192 p \u2228 (q \u2227 r), from (\n    \u03bb expanded,\n    let (p_case : p \u2192 p \u2228 (q \u2227 r)) := \u03bb (hp : p), or.intro_left (q \u2227 r) hp in\n    let (q_and_r_case : (q \u2227 r) \u2192 p \u2228 (q \u2227 r)) := \u03bb (q_and_r : q \u2227 r), or.intro_right p q_and_r in\n    let split := \u03bb (p_or_q : p \u2228 q) (p_or_r : p \u2228 r),\n        or.elim p_or_q p_case (\u03bb hq, or.elim p_or_r p_case (\u03bb hr, q_and_r_case (and.intro hq hr))) in\n    let (analyzed : p \u2228 (q \u2227 r)) := and.elim expanded split in\n    or.elim analyzed p_case q_and_r_case\n),\nshow p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r), from iff.intro expansion factorization\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\nhave implication : (p \u2192 (q \u2192 r)) \u2192 (p \u2227 q \u2192 r), from \u03bb p_to_q_to_r, \u03bb p_and_q, p_to_q_to_r p_and_q.left p_and_q.right,\nhave reversed :  (p \u2227 q \u2192 r) \u2192 (p \u2192 (q \u2192 r)), from \u03bb p_and_q_to_r, \u03bb p, \u03bb q, p_and_q_to_r (and.intro p q),\nshow (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r), from iff.intro implication reversed\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\nhave expansion : ((p \u2228 q) \u2192 r) \u2192 (p \u2192 r) \u2227 (q \u2192 r), from (\n    \u03bb p_or_q_to_r,\n        and.intro\n            (\u03bb hp, let p_or_q := or.intro_left q hp in p_or_q_to_r p_or_q)\n            (\u03bb hq, let p_or_q := or.intro_right p hq in p_or_q_to_r p_or_q)\n),\nhave factorization : (p \u2192 r) \u2227 (q \u2192 r) \u2192 ((p \u2228 q) \u2192 r), from (\n    \u03bb p_to_r_and_q_to_r, \u03bb p_or_q, and.elim p_to_r_and_q_to_r (\u03bb p_to_r q_to_r, or.elim p_or_q p_to_r q_to_r)\n),\nshow ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r), from iff.intro expansion factorization\n\n\n-- de morgan disjunction\ndef de_morgan_disjunction : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\nhave left_to_right : \u00ac(p \u2228 q) \u2192 \u00acp \u2227 \u00acq, from (\n    assume not_p_or_q,\n    and.intro\n        (\u03bb hnotp, not_p_or_q (or.inl hnotp))\n        (\u03bb hnotq, not_p_or_q (or.inr hnotq))\n),\nhave right_to_left : \u00acp \u2227 \u00acq \u2192 \u00ac(p \u2228 q), from (\n    \u03bb not_p_and_not_q, not.intro (\u03bb p_or_q, or.elim p_or_q (\u03bb hp, not_p_and_not_q.left hp) (\u03bb hq, not_p_and_not_q.right hq))\n),\nshow \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq, from iff.intro left_to_right right_to_left\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := @de_morgan_disjunction p q\n\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := \u03bb not_p_or_not_q,\n    not.intro (\n        \u03bb p_and_q,\n        and.elim p_and_q (\u03bb hp hq, or.elim not_p_or_not_q (\u03bb not_p, not_p hp) (\u03bb not_q, not_q hq))\n    )\n\n\nexample : \u00ac(p \u2227 \u00acp) := \u03bb conjunction, absurd conjunction.1 conjunction.2\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\nassume (p_and_not_q : p \u2227 \u00acq),\nhave hp : p, from p_and_not_q.left,\nhave nq : \u00acq, from p_and_not_q.right,\nshow \u00ac(p \u2192 q), from not.intro (\u03bb p_to_q, absurd (p_to_q hp) nq)\n\nexample : \u00acp \u2192 (p \u2192 q) := \u03bb (np : \u00acp), \u03bb (hp : p), absurd hp np\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n\u03bb not_p_or_q,\n\u03bb hp,\nor.elim not_p_or_q (\u03bb not_p, absurd hp not_p) (\u03bb hq, hq)\n\nexample : p \u2228 false \u2194 p :=\nhave p_or_false_implies_p : (p \u2228 false) \u2192 p, from (\n    \u03bb p_or_false, or.elim p_or_false (\u03bb hp, hp) false.elim\n),\nhave p_implies_p_or_false : p \u2192 (p \u2228 false), from (\n    \u03bb hp, or.intro_left false hp\n),\nshow p \u2228 false \u2194 p, from iff.intro p_or_false_implies_p p_implies_p_or_false\n\nexample : p \u2227 false \u2194 false :=\nhave p_and_false_implies_false : (p \u2227 false) \u2192 false, from and.right,\nhave false_implies_p_and_false : false \u2192 (p \u2227 false), from false.elim,\nshow p \u2227 false \u2194 false, from iff.intro p_and_false_implies_false false_implies_p_and_false\n\n\nexample : \u00ac(p \u2194 \u00acp) := @not.intro (p \u2194 \u00acp) (\n    assume p_iff_not_p : p \u2194 \u00acp,\n    have hnp : \u00acp, from (\n        assume hp : p,\n        have not_p : \u00acp, from iff.elim_left p_iff_not_p hp,\n        show false, from absurd hp not_p\n    ),\n    have hp : p, from iff.elim_right p_iff_not_p hnp,\n    show false, from absurd hp hnp\n)\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n\u03bb (hpq : p \u2192 q), \u03bb (nq : \u00acq), not.intro (\u03bb hp, absurd (hpq hp) nq)\n\nend ex1\n\n-- Exercize 2\nsection ex2\n    open classical\n\n    variables p q r s : Prop\n\n\n    example : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n    assume p_to_r_or_s : p \u2192 r \u2228 s,\n    -- assume hp : p,\n    -- have r_or_s : r \u2228 s, from p_to_r_or_s hp,\n    sorry\n\n    -- de morgan conjunction\n    example : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n    assume npandq : \u00ac(p \u2227 q),\n    by_contradiction (\n        assume hno : \u00ac(\u00acp \u2228 \u00acq),\n        have transformed : \u03a0 p\u2081 q\u2081, \u00ac(\u00acp\u2081 \u2228 \u00acq\u2081) \u2192 (\u00acp\u2081 \u2227 \u00acq\u2081), from \u03bb l, iff.elim_left de_morgan_disjunction l\n        -- have hdm : \u00acp \u2227 \u00acq, from (iff.elim_left de_morgan_disjunction hno),\n        sorry\n    )\n\n    example : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n    assume h : \u00ac(p \u2192 q),\n    sorry\n\n\n    example : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n    assume p_implies_q : p \u2192 q,\n    sorry\n\n\n    example : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n    assume not_q_to_not_p : \u00acq \u2192 \u00acp,\n    assume hp : p,\n    sorry\n\n    example : p \u2228 \u00acp := @em p\n\n    example : (((p \u2192 q) \u2192 p) \u2192 p) :=\n    assume p_implies_q_implies_p : ((p \u2192 q) \u2192 p),\n    sorry\n\nend ex2\n", "meta": {"author": "tomhoule", "repo": "theorem-proving-in-lean-exercises", "sha": "60ccc71b8a6df6924e7cc90aab713b804f78da9f", "save_path": "github-repos/lean/tomhoule-theorem-proving-in-lean-exercises", "path": "github-repos/lean/tomhoule-theorem-proving-in-lean-exercises/theorem-proving-in-lean-exercises-60ccc71b8a6df6924e7cc90aab713b804f78da9f/theorem-proving-in-lean/src/chap_3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.7265719738817255}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n-/\nimport order.basic\nimport order.preorder_hom\nimport order.galois_connection\nimport tactic.monotonicity\n\n/-!\n# Closure operators on a partial order\n\nWe define (bundled) closure operators on a partial order as an monotone (increasing), extensive\n(inflationary) and idempotent function.\nWe define closed elements for the operator as elements which are fixed by it.\n\nNote that there is close connection to Galois connections and Galois insertions: every closure\noperator induces a Galois insertion (from the set of closed elements to the underlying type), and\nevery Galois connection induces a closure operator (namely the composition). In particular,\na Galois insertion can be seen as a general case of a closure operator, where the inclusion is given\nby coercion, see `closure_operator.gi`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets\n\n-/\nuniverse u\n\nvariables (\u03b1 : Type u) [partial_order \u03b1]\n\n/--\nA closure operator on the partial order `\u03b1` is a monotone function which is extensive (every `x`\nis less than its closure) and idempotent.\n-/\nstructure closure_operator extends \u03b1 \u2192\u2098 \u03b1 :=\n(le_closure' : \u2200 x, x \u2264 to_fun x)\n(idempotent' : \u2200 x, to_fun (to_fun x) = to_fun x)\n\ninstance : has_coe_to_fun (closure_operator \u03b1) :=\n{ F := _, coe := \u03bb c, c.to_fun }\n\n/-- See Note [custom simps projection] -/\ndef closure_operator.simps.apply (f : closure_operator \u03b1) : \u03b1 \u2192 \u03b1 := f\n\ninitialize_simps_projections closure_operator (to_preorder_hom_to_fun \u2192 apply, -to_preorder_hom)\n\nnamespace closure_operator\n\n/-- The identity function as a closure operator. -/\n@[simps]\ndef id : closure_operator \u03b1 :=\n{ to_fun := \u03bb x, x,\n  monotone' := \u03bb _ _ h, h,\n  le_closure' := \u03bb _, le_refl _,\n  idempotent' := \u03bb _, rfl }\n\ninstance : inhabited (closure_operator \u03b1) := \u27e8id \u03b1\u27e9\n\nvariables {\u03b1} (c : closure_operator \u03b1)\n\n@[ext] lemma ext :\n  \u2200 (c\u2081 c\u2082 : closure_operator \u03b1), (c\u2081 : \u03b1 \u2192 \u03b1) = (c\u2082 : \u03b1 \u2192 \u03b1) \u2192 c\u2081 = c\u2082\n| \u27e8\u27e8c\u2081, _\u27e9, _, _\u27e9 \u27e8\u27e8c\u2082, _\u27e9, _, _\u27e9 h := by { congr, exact h }\n\n/-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) \u2264 f x`. -/\n@[simps]\ndef mk' (f : \u03b1 \u2192 \u03b1) (hf\u2081 : monotone f) (hf\u2082 : \u2200 x, x \u2264 f x) (hf\u2083 : \u2200 x, f (f x) \u2264 f x) :\n  closure_operator \u03b1 :=\n{ to_fun := f,\n  monotone' := hf\u2081,\n  le_closure' := hf\u2082,\n  idempotent' := \u03bb x, le_antisymm (hf\u2083 x) (hf\u2081 (hf\u2082 x)) }\n\n@[mono] \n\nlemma le_closure_iff (x y : \u03b1) : x \u2264 c y \u2194 c x \u2264 c y :=\n\u27e8\u03bb h, c.idempotent y \u25b8 c.monotone h, \u03bb h, le_trans (c.le_closure x) h\u27e9\n\nlemma closure_top {\u03b1 : Type u} [order_top \u03b1] (c : closure_operator \u03b1) : c \u22a4 = \u22a4 :=\nle_antisymm le_top (c.le_closure _)\n\nlemma closure_inter_le {\u03b1 : Type u} [semilattice_inf \u03b1] (c : closure_operator \u03b1) (x y : \u03b1) :\n  c (x \u2293 y) \u2264 c x \u2293 c y :=\nc.monotone.map_inf_le _ _\n\nlemma closure_union_closure_le {\u03b1 : Type u} [semilattice_sup \u03b1] (c : closure_operator \u03b1) (x y : \u03b1) :\n  c x \u2294 c y \u2264 c (x \u2294 y) :=\nc.monotone.le_map_sup _ _\n\n/-- An element `x` is closed for the closure operator `c` if it is a fixed point for it. -/\ndef closed : set \u03b1 := \u03bb x, c x = x\n\nlemma mem_closed_iff (x : \u03b1) : x \u2208 c.closed \u2194 c x = x := iff.rfl\nlemma mem_closed_iff_closure_le (x : \u03b1) : x \u2208 c.closed \u2194 c x \u2264 x :=\n\u27e8le_of_eq, \u03bb h, le_antisymm h (c.le_closure x)\u27e9\nlemma closure_eq_self_of_mem_closed {x : \u03b1} (h : x \u2208 c.closed) : c x = x := h\n\n@[simp] lemma closure_is_closed (x : \u03b1) : c x \u2208 c.closed := c.idempotent x\n\n/-- The set of closed elements for `c` is exactly its range. -/\nlemma closed_eq_range_close : c.closed = set.range c :=\nset.ext $ \u03bb x, \u27e8\u03bb h, \u27e8x, h\u27e9, by { rintro \u27e8y, rfl\u27e9, apply c.idempotent }\u27e9\n\n/-- Send an `x` to an element of the set of closed elements (by taking the closure). -/\ndef to_closed (x : \u03b1) : c.closed := \u27e8c x, c.closure_is_closed x\u27e9\n\nlemma top_mem_closed {\u03b1 : Type u} [order_top \u03b1] (c : closure_operator \u03b1) : \u22a4 \u2208 c.closed :=\nc.closure_top\n\nlemma closure_le_closed_iff_le {x y : \u03b1} (hy : c.closed y) : x \u2264 y \u2194 c x \u2264 y :=\nby rw [\u2190 c.closure_eq_self_of_mem_closed hy, le_closure_iff]\n\n/-- The set of closed elements has a Galois insertion to the underlying type. -/\ndef gi : galois_insertion c.to_closed coe :=\n{ choice := \u03bb x hx, \u27e8x, le_antisymm hx (c.le_closure x)\u27e9,\n  gc := \u03bb x y, (c.closure_le_closed_iff_le y.2).symm,\n  le_l_u := \u03bb x, c.le_closure _,\n  choice_eq := \u03bb x hx, le_antisymm (c.le_closure x) hx }\n\nend closure_operator\n\nvariables {\u03b1} (c : closure_operator \u03b1)\n\n/--\nEvery Galois connection induces a closure operator given by the composition. This is the partial\norder version of the statement that every adjunction induces a monad.\n-/\n@[simps]\ndef galois_connection.closure_operator {\u03b2 : Type u} [preorder \u03b2]\n  {l : \u03b1 \u2192 \u03b2} {u : \u03b2 \u2192 \u03b1} (gc : galois_connection l u) :\n  closure_operator \u03b1 :=\n{ to_fun := \u03bb x, u (l x),\n  monotone' := \u03bb x y h, gc.monotone_u (gc.monotone_l h),\n  le_closure' := gc.le_u_l,\n  idempotent' := \u03bb x, le_antisymm (gc.monotone_u (gc.l_u_le _)) (gc.le_u_l _) }\n\n/--\nThe Galois insertion associated to a closure operator can be used to reconstruct the closure\noperator.\n\nNote that the inverse in the opposite direction does not hold in general.\n-/\n@[simp]\nlemma closure_operator_gi_self : c.gi.gc.closure_operator = c :=\nby { ext x, refl }\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/closure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.7265505186566736}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module data.polynomial.taylor\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.AlgebraMap\nimport Mathlib.Data.Polynomial.HasseDeriv\nimport Mathlib.Data.Polynomial.Degree.Lemmas\n\n/-!\n# Taylor expansions of polynomials\n\n## Main declarations\n\n* `Polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`\n* `Polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is\n  `(Polynomial.hasseDeriv k f).eval r`\n* `Polynomial.eq_zero_of_hasseDeriv_eq_zero`:\n  the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero\n\n-/\n\n\nnoncomputable section\n\nnamespace Polynomial\n\nopen Polynomial\n\nvariable {R : Type _} [Semiring R] (r : R) (f : R[X])\n\n/-- The Taylor expansion of a polynomial `f` at `r`. -/\ndef taylor (r : R) : R[X] \u2192\u2097[R] R[X] where\n  toFun f := f.comp (X + C r)\n  map_add' f g := add_comp\n  map_smul' c f := by simp only [smul_eq_C_mul, C_mul_comp, RingHom.id_apply]\n#align polynomial.taylor Polynomial.taylor\n\ntheorem taylor_apply : taylor r f = f.comp (X + C r) :=\n  rfl\n#align polynomial.taylor_apply Polynomial.taylor_apply\n\n@[simp]\ntheorem taylor_X : taylor r X = X + C r := by simp only [taylor_apply, X_comp]\nset_option linter.uppercaseLean3 false in\n#align polynomial.taylor_X Polynomial.taylor_X\n\n@[simp]\ntheorem taylor_C (x : R) : taylor r (C x) = C x := by simp only [taylor_apply, C_comp]\nset_option linter.uppercaseLean3 false in\n#align polynomial.taylor_C Polynomial.taylor_C\n\n@[simp]\ntheorem taylor_zero' : taylor (0 : R) = LinearMap.id := by\n  ext\n  simp only [taylor_apply, add_zero, comp_X, _root_.map_zero, LinearMap.id_comp,\n    Function.comp_apply, LinearMap.coe_comp]\n#align polynomial.taylor_zero' Polynomial.taylor_zero'\n\ntheorem taylor_zero (f : R[X]) : taylor 0 f = f := by rw [taylor_zero', LinearMap.id_apply]\n#align polynomial.taylor_zero Polynomial.taylor_zero\n\n@[simp]\ntheorem taylor_one : taylor r (1 : R[X]) = C 1 := by rw [\u2190 C_1, taylor_C]\n#align polynomial.taylor_one Polynomial.taylor_one\n\n@[simp]\ntheorem taylor_monomial (i : \u2115) (k : R) : taylor r (monomial i k) = C k * (X + C r) ^ i := by\n  simp [taylor_apply]\n#align polynomial.taylor_monomial Polynomial.taylor_monomial\n\n/-- The `k`th coefficient of `Polynomial.taylor r f` is `(Polynomial.hasseDeriv k f).eval r`. -/\ntheorem taylor_coeff (n : \u2115) : (taylor r f).coeff n = (hasseDeriv n f).eval r :=\n  show (lcoeff R n).comp (taylor r) f = (leval r).comp (hasseDeriv n) f by\n    congr 1; clear! f; ext i\n    simp only [leval_apply, mul_one, one_mul, eval_monomial, LinearMap.comp_apply, coeff_C_mul,\n      hasseDeriv_monomial, taylor_apply, monomial_comp, C_1, (commute_X (C r)).add_pow i,\n      LinearMap.map_sum]\n    simp only [lcoeff_apply, \u2190 C_eq_nat_cast, mul_assoc, \u2190 C_pow, \u2190 C_mul, coeff_mul_C,\n      (Nat.cast_commute _ _).eq, coeff_X_pow, boole_mul, Finset.sum_ite_eq, Finset.mem_range]\n    split_ifs with h; \u00b7 rfl\n    push_neg at h; rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, MulZeroClass.mul_zero]\n#align polynomial.taylor_coeff Polynomial.taylor_coeff\n\n@[simp]\ntheorem taylor_coeff_zero : (taylor r f).coeff 0 = f.eval r := by\n  rw [taylor_coeff, hasseDeriv_zero, LinearMap.id_apply]\n#align polynomial.taylor_coeff_zero Polynomial.taylor_coeff_zero\n\n@[simp]\ntheorem taylor_coeff_one : (taylor r f).coeff 1 = f.derivative.eval r := by\n  rw [taylor_coeff, hasseDeriv_one]\n#align polynomial.taylor_coeff_one Polynomial.taylor_coeff_one\n\n@[simp]\ntheorem natDegree_taylor (p : R[X]) (r : R) : natDegree (taylor r p) = natDegree p := by\n  refine' map_natDegree_eq_natDegree _ _\n  nontriviality R\n  intro n c c0\n  simp [taylor_monomial, natDegree_c_mul_eq_of_mul_ne_zero, natDegree_pow_X_add_c, c0]\n#align polynomial.nat_degree_taylor Polynomial.natDegree_taylor\n\n@[simp]\ntheorem taylor_mul {R} [CommSemiring R] (r : R) (p q : R[X]) :\n    taylor r (p * q) = taylor r p * taylor r q := by simp only [taylor_apply, mul_comp]\n#align polynomial.taylor_mul Polynomial.taylor_mul\n\n/-- `Polynomial.taylor` as an `AlgHom` for commutative semirings -/\n@[simps!]\ndef taylorAlgHom {R} [CommSemiring R] (r : R) : R[X] \u2192\u2090[R] R[X] :=\n  AlgHom.ofLinearMap (taylor r) (taylor_one r) (taylor_mul r)\n#align polynomial.taylor_alg_hom Polynomial.taylorAlgHom\n\ntheorem taylor_taylor {R} [CommSemiring R] (f : R[X]) (r s : R) :\n    taylor r (taylor s f) = taylor (r + s) f := by\n  simp only [taylor_apply, comp_assoc, map_add, add_comp, X_comp, C_comp, C_add, add_assoc]\n#align polynomial.taylor_taylor Polynomial.taylor_taylor\n\ntheorem taylor_eval {R} [CommSemiring R] (r : R) (f : R[X]) (s : R) :\n    (taylor r f).eval s = f.eval (s + r) := by\n  simp only [taylor_apply, eval_comp, eval_C, eval_X, eval_add]\n#align polynomial.taylor_eval Polynomial.taylor_eval\n\ntheorem taylor_eval_sub {R} [CommRing R] (r : R) (f : R[X]) (s : R) :\n    (taylor r f).eval (s - r) = f.eval s := by rw [taylor_eval, sub_add_cancel]\n#align polynomial.taylor_eval_sub Polynomial.taylor_eval_sub\n\ntheorem taylor_injective {R} [CommRing R] (r : R) : Function.Injective (taylor r) := by\n  intro f g h\n  apply_fun taylor (-r) at h\n  simpa only [taylor_apply, comp_assoc, add_comp, X_comp, C_comp, C_neg, neg_add_cancel_right,\n    comp_X] using h\n#align polynomial.taylor_injective Polynomial.taylor_injective\n\ntheorem eq_zero_of_hasseDeriv_eq_zero {R} [CommRing R] (f : R[X]) (r : R)\n    (h : \u2200 k, (hasseDeriv k f).eval r = 0) : f = 0 := by\n  apply taylor_injective r\n  rw [LinearMap.map_zero]\n  ext k\n  simp only [taylor_coeff, h, coeff_zero]\n#align polynomial.eq_zero_of_hasse_deriv_eq_zero Polynomial.eq_zero_of_hasseDeriv_eq_zero\n\n/-- Taylor's formula. -/\ntheorem sum_taylor_eq {R} [CommRing R] (f : R[X]) (r : R) :\n    ((taylor r f).sum fun i a => C a * (X - C r) ^ i) = f := by\n  rw [\u2190 comp_eq_sum_left, sub_eq_add_neg, \u2190 C_neg, \u2190 taylor_apply, taylor_taylor, neg_add_self,\n    taylor_zero]\n#align polynomial.sum_taylor_eq Polynomial.sum_taylor_eq\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Taylor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7265505064017012}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro\n-/\nimport algebra.order.group\nimport algebra.order.sub\nimport data.set.intervals.basic\n\n/-!\n# Ordered rings and semirings\n\nThis file develops the basics of ordered (semi)rings.\n\nEach typeclass here comprises\n* an algebraic class (`semiring`, `comm_semiring`, `ring`, `comm_ring`)\n* an order class (`partial_order`, `linear_order`)\n* assumptions on how both interact ((strict) monotonicity, canonicity)\n\nFor short,\n* \"`+` respects `\u2264`\" means \"monotonicity of addition\"\n* \"`*` respects `<`\" means \"strict monotonicity of multiplication by a positive number\".\n\n## Typeclasses\n\n* `ordered_semiring`: Semiring with a partial order such that `+` respects `\u2264` and `*` respects `<`.\n* `ordered_comm_semiring`: Commutative semiring with a partial order such that `+` respects `\u2264` and\n  `*` respects `<`.\n* `ordered_ring`: Ring with a partial order such that `+` respects `\u2264` and `*` respects `<`.\n* `ordered_comm_ring`: Commutative ring with a partial order such that `+` respects `\u2264` and\n  `*` respects `<`.\n* `linear_ordered_semiring`: Semiring with a linear order such that `+` respects `\u2264` and\n  `*` respects `<`.\n* `linear_ordered_ring`: Ring with a linear order such that `+` respects `\u2264` and `*` respects `<`.\n* `linear_ordered_comm_ring`: Commutative ring with a linear order such that `+` respects `\u2264` and\n  `*` respects `<`.\n* `canonically_ordered_comm_semiring`: Commutative semiring with a partial order such that `+`\n  respects `\u2264`, `*` respects `<`, and `a \u2264 b \u2194 \u2203 c, b = a + c`.\n\nand some typeclasses to define ordered rings by specifying their nonegative elements:\n* `nonneg_ring`: To define `ordered_ring`s.\n* `linear_nonneg_ring`: To define `linear_ordered_ring`s.\n\n## Hierarchy\n\nThe hardest part of proving order lemmas might be to figure out the correct generality and its\ncorresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its\nimmediate predecessors and what conditions are added to each of them.\n\n* `ordered_semiring`\n  - `ordered_cancel_add_comm_monoid` & multiplication & `*` respects `<`\n  - `semiring` & partial order structure & `+` respects `\u2264` & `*` respects `<`\n* `ordered_comm_semiring`\n  - `ordered_semiring` & commutativity of multiplication\n  - `comm_semiring` & partial order structure & `+` respects `\u2264` & `*` respects `<`\n* `ordered_ring`\n  - `ordered_semiring` & additive inverses\n  - `ordered_add_comm_group` & multiplication & `*` respects `<`\n  - `ring` & partial order structure & `+` respects `\u2264` & `*` respects `<`\n* `ordered_comm_ring`\n  - `ordered_ring` & commutativity of multiplication\n  - `ordered_comm_semiring` & additive inverses\n  - `comm_ring` & partial order structure & `+` respects `\u2264` & `*` respects `<`\n* `linear_ordered_semiring`\n  - `ordered_semiring` & totality of the order & nontriviality\n  - `linear_ordered_add_comm_monoid` & multiplication & nontriviality & `*` respects `<`\n* `linear_ordered_ring`\n  - `ordered_ring` & totality of the order & nontriviality\n  - `linear_ordered_semiring` & additive inverses\n  - `linear_ordered_add_comm_group` & multiplication & `*` respects `<`\n  - `domain` & linear order structure\n* `linear_ordered_comm_ring`\n  - `ordered_comm_ring` & totality of the order & nontriviality\n  - `linear_ordered_ring` & commutativity of multiplication\n  - `is_domain` & linear order structure\n* `canonically_ordered_comm_semiring`\n  - `canonically_ordered_add_monoid` & multiplication & `*` respects `<` & no zero divisors\n  - `comm_semiring` & `a \u2264 b \u2194 \u2203 c, b = a + c` & no zero divisors\n\n## TODO\n\nWe're still missing some typeclasses, like\n* `linear_ordered_comm_semiring`\n* `canonically_ordered_semiring`\nThey have yet to come up in practice.\n-/\n\nset_option old_structure_cmd true\n\nuniverse u\nvariable {\u03b1 : Type u}\n\nlemma add_one_le_two_mul [preorder \u03b1] [semiring \u03b1] [covariant_class \u03b1 \u03b1 (+) (\u2264)]\n  {a : \u03b1} (a1 : 1 \u2264 a) :\n  a + 1 \u2264 2 * a :=\ncalc  a + 1 \u2264 a + a : add_le_add_left a1 a\n        ... = 2 * a : (two_mul _).symm\n\n/-- An `ordered_semiring \u03b1` is a semiring `\u03b1` with a partial order such that\naddition is monotone and multiplication by a positive number is strictly monotone. -/\n@[protect_proj]\nclass ordered_semiring (\u03b1 : Type u) extends semiring \u03b1, ordered_cancel_add_comm_monoid \u03b1 :=\n(zero_le_one : 0 \u2264 (1 : \u03b1))\n(mul_lt_mul_of_pos_left :  \u2200 a b c : \u03b1, a < b \u2192 0 < c \u2192 c * a < c * b)\n(mul_lt_mul_of_pos_right : \u2200 a b c : \u03b1, a < b \u2192 0 < c \u2192 a * c < b * c)\n\nsection ordered_semiring\nvariables [ordered_semiring \u03b1] {a b c d : \u03b1}\n\n@[simp] lemma zero_le_one : 0 \u2264 (1:\u03b1) :=\nordered_semiring.zero_le_one\n\nlemma zero_le_two : 0 \u2264 (2:\u03b1) :=\nadd_nonneg zero_le_one zero_le_one\n\nlemma one_le_two : 1 \u2264 (2:\u03b1) :=\ncalc (1:\u03b1) = 0 + 1 : (zero_add _).symm\n       ... \u2264 1 + 1 : add_le_add_right zero_le_one _\n\nsection nontrivial\n\nvariables [nontrivial \u03b1]\n\n@[simp] lemma zero_lt_one : 0 < (1 : \u03b1) :=\nlt_of_le_of_ne zero_le_one zero_ne_one\n\nlemma zero_lt_two : 0 < (2:\u03b1) := add_pos zero_lt_one zero_lt_one\n\n@[field_simps] lemma two_ne_zero : (2:\u03b1) \u2260 0 :=\nne.symm (ne_of_lt zero_lt_two)\n\nlemma one_lt_two : 1 < (2:\u03b1) :=\ncalc (2:\u03b1) = 1+1 : one_add_one_eq_two\n     ...   > 1+0 : add_lt_add_left zero_lt_one _\n     ...   = 1   : add_zero 1\n\nlemma zero_lt_three : 0 < (3:\u03b1) := add_pos zero_lt_two zero_lt_one\n\nlemma zero_lt_four : 0 < (4:\u03b1) := add_pos zero_lt_two zero_lt_two\n\nend nontrivial\n\nlemma mul_lt_mul_of_pos_left (h\u2081 : a < b) (h\u2082 : 0 < c) : c * a < c * b :=\nordered_semiring.mul_lt_mul_of_pos_left a b c h\u2081 h\u2082\n\nlemma mul_lt_mul_of_pos_right (h\u2081 : a < b) (h\u2082 : 0 < c) : a * c < b * c :=\nordered_semiring.mul_lt_mul_of_pos_right a b c h\u2081 h\u2082\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_mul_of_nonneg_left [@decidable_rel \u03b1 (\u2264)]\n  (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c * a \u2264 c * b :=\nbegin\n  by_cases ba : b \u2264 a, { simp [ba.antisymm h\u2081] },\n  by_cases c0 : c \u2264 0, { simp [c0.antisymm h\u2082] },\n  exact (mul_lt_mul_of_pos_left (h\u2081.lt_of_not_le ba) (h\u2082.lt_of_not_le c0)).le,\nend\n\nlemma mul_le_mul_of_nonneg_left : a \u2264 b \u2192 0 \u2264 c \u2192 c * a \u2264 c * b :=\nby classical; exact decidable.mul_le_mul_of_nonneg_left\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_mul_of_nonneg_right [@decidable_rel \u03b1 (\u2264)]\n  (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : a * c \u2264 b * c :=\nbegin\n  by_cases ba : b \u2264 a, { simp [ba.antisymm h\u2081] },\n  by_cases c0 : c \u2264 0, { simp [c0.antisymm h\u2082] },\n  exact (mul_lt_mul_of_pos_right (h\u2081.lt_of_not_le ba) (h\u2082.lt_of_not_le c0)).le,\nend\n\nlemma mul_le_mul_of_nonneg_right : a \u2264 b \u2192 0 \u2264 c \u2192 a * c \u2264 b * c :=\nby classical; exact decidable.mul_le_mul_of_nonneg_right\n\n-- TODO: there are four variations, depending on which variables we assume to be nonneg\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_mul [@decidable_rel \u03b1 (\u2264)]\n  (hac : a \u2264 c) (hbd : b \u2264 d) (nn_b : 0 \u2264 b) (nn_c : 0 \u2264 c) : a * b \u2264 c * d :=\ncalc\n  a * b \u2264 c * b : decidable.mul_le_mul_of_nonneg_right hac nn_b\n    ... \u2264 c * d : decidable.mul_le_mul_of_nonneg_left hbd nn_c\n\nlemma mul_le_mul : a \u2264 c \u2192 b \u2264 d \u2192 0 \u2264 b \u2192 0 \u2264 c \u2192 a * b \u2264 c * d :=\nby classical; exact decidable.mul_le_mul\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_nonneg_le_one_le {\u03b1 : Type*} [ordered_semiring \u03b1]\n  [@decidable_rel \u03b1 (\u2264)] {a b c : \u03b1}\n  (h\u2081 : 0 \u2264 c) (h\u2082 : a \u2264 c) (h\u2083 : 0 \u2264 b) (h\u2084 : b \u2264 1) : a * b \u2264 c :=\nby simpa only [mul_one] using decidable.mul_le_mul h\u2082 h\u2084 h\u2083 h\u2081\n\nlemma mul_nonneg_le_one_le {\u03b1 : Type*} [ordered_semiring \u03b1] {a b c : \u03b1} :\n  0 \u2264 c \u2192 a \u2264 c \u2192 0 \u2264 b \u2192 b \u2264 1 \u2192 a * b \u2264 c :=\nby classical; exact decidable.mul_nonneg_le_one_le\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_nonneg [@decidable_rel \u03b1 (\u2264)]\n  (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a * b :=\nhave h : 0 * b \u2264 a * b, from decidable.mul_le_mul_of_nonneg_right ha hb,\nby rwa [zero_mul] at h\n\nlemma mul_nonneg : 0 \u2264 a \u2192 0 \u2264 b \u2192 0 \u2264 a * b := by classical; exact decidable.mul_nonneg\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_nonpos_of_nonneg_of_nonpos [@decidable_rel \u03b1 (\u2264)]\n  (ha : 0 \u2264 a) (hb : b \u2264 0) : a * b \u2264 0 :=\nhave h : a * b \u2264 a * 0, from decidable.mul_le_mul_of_nonneg_left hb ha,\nby rwa mul_zero at h\n\nlemma mul_nonpos_of_nonneg_of_nonpos : 0 \u2264 a \u2192 b \u2264 0 \u2192 a * b \u2264 0 :=\n by classical; exact decidable.mul_nonpos_of_nonneg_of_nonpos\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_nonpos_of_nonpos_of_nonneg [@decidable_rel \u03b1 (\u2264)]\n  (ha : a \u2264 0) (hb : 0 \u2264 b) : a * b \u2264 0 :=\nhave h : a * b \u2264 0 * b, from decidable.mul_le_mul_of_nonneg_right ha hb,\nby rwa zero_mul at h\n\nlemma mul_nonpos_of_nonpos_of_nonneg : a \u2264 0 \u2192 0 \u2264 b \u2192 a * b \u2264 0 :=\nby classical; exact decidable.mul_nonpos_of_nonpos_of_nonneg\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_lt_mul [@decidable_rel \u03b1 (\u2264)]\n  (hac : a < c) (hbd : b \u2264 d) (pos_b : 0 < b) (nn_c : 0 \u2264 c) : a * b < c * d :=\ncalc\n  a * b < c * b : mul_lt_mul_of_pos_right hac pos_b\n    ... \u2264 c * d : decidable.mul_le_mul_of_nonneg_left hbd nn_c\n\nlemma mul_lt_mul : a < c \u2192 b \u2264 d \u2192 0 < b \u2192 0 \u2264 c \u2192 a * b < c * d :=\nby classical; exact decidable.mul_lt_mul\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_lt_mul' [@decidable_rel \u03b1 (\u2264)]\n  (h1 : a \u2264 c) (h2 : b < d) (h3 : 0 \u2264 b) (h4 : 0 < c) : a * b < c * d :=\ncalc\n   a * b \u2264 c * b : decidable.mul_le_mul_of_nonneg_right h1 h3\n     ... < c * d : mul_lt_mul_of_pos_left h2 h4\n\nlemma mul_lt_mul' : a \u2264 c \u2192 b < d \u2192 0 \u2264 b \u2192 0 < c \u2192 a * b < c * d :=\nby classical; exact decidable.mul_lt_mul'\n\nlemma mul_pos (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=\nhave h : 0 * b < a * b, from mul_lt_mul_of_pos_right ha hb,\nby rwa zero_mul at h\n\nlemma mul_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a * b < 0 :=\nhave h : a * b < a * 0, from mul_lt_mul_of_pos_left hb ha,\nby rwa mul_zero at h\n\nlemma mul_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a * b < 0 :=\nhave h : a * b < 0 * b, from mul_lt_mul_of_pos_right ha hb,\nby rwa zero_mul at  h\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_self_lt_mul_self [@decidable_rel \u03b1 (\u2264)]\n  (h1 : 0 \u2264 a) (h2 : a < b) : a * a < b * b :=\ndecidable.mul_lt_mul' h2.le h2 h1 $ h1.trans_lt h2\n\nlemma mul_self_lt_mul_self (h1 : 0 \u2264 a) (h2 : a < b) : a * a < b * b :=\nmul_lt_mul' h2.le h2 h1 $ h1.trans_lt h2\n\n-- See Note [decidable namespace]\nprotected lemma decidable.strict_mono_on_mul_self [@decidable_rel \u03b1 (\u2264)] :\n  strict_mono_on (\u03bb x : \u03b1, x * x) (set.Ici 0) :=\n\u03bb x hx y hy hxy, decidable.mul_self_lt_mul_self hx hxy\n\nlemma strict_mono_on_mul_self : strict_mono_on (\u03bb x : \u03b1, x * x) (set.Ici 0) :=\n\u03bb x hx y hy hxy, mul_self_lt_mul_self hx hxy\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_self_le_mul_self [@decidable_rel \u03b1 (\u2264)]\n  (h1 : 0 \u2264 a) (h2 : a \u2264 b) : a * a \u2264 b * b :=\ndecidable.mul_le_mul h2 h2 h1 $ h1.trans h2\n\nlemma mul_self_le_mul_self (h1 : 0 \u2264 a) (h2 : a \u2264 b) : a * a \u2264 b * b :=\nmul_le_mul h2 h2 h1 $ h1.trans h2\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_lt_mul'' [@decidable_rel \u03b1 (\u2264)]\n  (h1 : a < c) (h2 : b < d) (h3 : 0 \u2264 a) (h4 : 0 \u2264 b) : a * b < c * d :=\nh4.lt_or_eq_dec.elim\n  (\u03bb b0, decidable.mul_lt_mul h1 h2.le b0 $ h3.trans h1.le)\n  (\u03bb b0, by rw [\u2190 b0, mul_zero]; exact\n    mul_pos (h3.trans_lt h1) (h4.trans_lt h2))\n\nlemma mul_lt_mul'' : a < c \u2192 b < d \u2192 0 \u2264 a \u2192 0 \u2264 b \u2192 a * b < c * d :=\nby classical; exact decidable.mul_lt_mul''\n\n-- See Note [decidable namespace]\nprotected lemma decidable.le_mul_of_one_le_right [@decidable_rel \u03b1 (\u2264)]\n  (hb : 0 \u2264 b) (h : 1 \u2264 a) : b \u2264 b * a :=\nsuffices b * 1 \u2264 b * a, by rwa mul_one at this,\ndecidable.mul_le_mul_of_nonneg_left h hb\n\nlemma le_mul_of_one_le_right : 0 \u2264 b \u2192 1 \u2264 a \u2192 b \u2264 b * a :=\nby classical; exact decidable.le_mul_of_one_le_right\n\n-- See Note [decidable namespace]\nprotected lemma decidable.le_mul_of_one_le_left [@decidable_rel \u03b1 (\u2264)]\n  (hb : 0 \u2264 b) (h : 1 \u2264 a) : b \u2264 a * b :=\nsuffices 1 * b \u2264 a * b, by rwa one_mul at this,\ndecidable.mul_le_mul_of_nonneg_right h hb\n\nlemma le_mul_of_one_le_left : 0 \u2264 b \u2192 1 \u2264 a \u2192 b \u2264 a * b :=\nby classical; exact decidable.le_mul_of_one_le_left\n\n-- See Note [decidable namespace]\nprotected lemma decidable.lt_mul_of_one_lt_right [@decidable_rel \u03b1 (\u2264)]\n  (hb : 0 < b) (h : 1 < a) : b < b * a :=\nsuffices b * 1 < b * a, by rwa mul_one at this,\ndecidable.mul_lt_mul' le_rfl h zero_le_one hb\n\nlemma lt_mul_of_one_lt_right : 0 < b \u2192 1 < a \u2192 b < b * a :=\nby classical; exact decidable.lt_mul_of_one_lt_right\n\n-- See Note [decidable namespace]\nprotected lemma decidable.lt_mul_of_one_lt_left [@decidable_rel \u03b1 (\u2264)]\n  (hb : 0 < b) (h : 1 < a) : b < a * b :=\nsuffices 1 * b < a * b, by rwa one_mul at this,\ndecidable.mul_lt_mul h le_rfl hb (zero_le_one.trans h.le)\n\nlemma lt_mul_of_one_lt_left : 0 < b \u2192 1 < a \u2192 b < a * b :=\nby classical; exact decidable.lt_mul_of_one_lt_left\n\n-- See Note [decidable namespace]\nprotected lemma decidable.add_le_mul_two_add [@decidable_rel \u03b1 (\u2264)] {a b : \u03b1}\n  (a2 : 2 \u2264 a) (b0 : 0 \u2264 b) : a + (2 + b) \u2264 a * (2 + b) :=\ncalc a + (2 + b) \u2264 a + (a + a * b) :\n      add_le_add_left (add_le_add a2 (decidable.le_mul_of_one_le_left b0 (one_le_two.trans a2))) a\n             ... \u2264 a * (2 + b) : by rw [mul_add, mul_two, add_assoc]\n\nlemma add_le_mul_two_add {a b : \u03b1} : 2 \u2264 a \u2192 0 \u2264 b \u2192 a + (2 + b) \u2264 a * (2 + b) :=\nby classical; exact decidable.add_le_mul_two_add\n\n-- See Note [decidable namespace]\nprotected lemma decidable.one_le_mul_of_one_le_of_one_le [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} (a1 : 1 \u2264 a) (b1 : 1 \u2264 b) : (1 : \u03b1) \u2264 a * b :=\n(mul_one (1 : \u03b1)).symm.le.trans (decidable.mul_le_mul a1 b1 zero_le_one (zero_le_one.trans a1))\n\nlemma one_le_mul_of_one_le_of_one_le {a b : \u03b1} : 1 \u2264 a \u2192 1 \u2264 b \u2192 (1 : \u03b1) \u2264 a * b :=\nby classical; exact decidable.one_le_mul_of_one_le_of_one_le\n\n/-- Pullback an `ordered_semiring` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef function.injective.ordered_semiring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_semiring \u03b2 :=\n{ zero_le_one := show f 0 \u2264 f 1, by simp only [zero, one, zero_le_one],\n  mul_lt_mul_of_pos_left := \u03bb  a b c ab c0, show f (c * a) < f (c * b),\n    begin\n      rw [mul, mul],\n      refine mul_lt_mul_of_pos_left ab _,\n      rwa \u2190 zero,\n    end,\n  mul_lt_mul_of_pos_right := \u03bb a b c ab c0, show f (a * c) < f (b * c),\n    begin\n      rw [mul, mul],\n      refine mul_lt_mul_of_pos_right ab _,\n      rwa \u2190 zero,\n    end,\n  ..hf.ordered_cancel_add_comm_monoid f zero add,\n  ..hf.semiring f zero one add mul }\n\nsection\nvariable [nontrivial \u03b1]\n\nlemma bit1_pos (h : 0 \u2264 a) : 0 < bit1 a :=\nlt_add_of_le_of_pos (add_nonneg h h) zero_lt_one\n\nlemma lt_add_one (a : \u03b1) : a < a + 1 :=\nlt_add_of_le_of_pos le_rfl zero_lt_one\n\nlemma lt_one_add (a : \u03b1) : a < 1 + a :=\nby { rw [add_comm], apply lt_add_one }\n\nend\n\nlemma bit1_pos' (h : 0 < a) : 0 < bit1 a :=\nbegin\n  nontriviality,\n  exact bit1_pos h.le,\nend\n\n-- See Note [decidable namespace]\nprotected lemma decidable.one_lt_mul [@decidable_rel \u03b1 (\u2264)]\n  (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\nbegin\n  nontriviality,\n  exact (one_mul (1 : \u03b1)) \u25b8 decidable.mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)\nend\n\nlemma one_lt_mul : 1 \u2264 a \u2192 1 < b \u2192 1 < a * b :=\nby classical; exact decidable.one_lt_mul\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_one [@decidable_rel \u03b1 (\u2264)]\n  (ha : a \u2264 1) (hb' : 0 \u2264 b) (hb : b \u2264 1) : a * b \u2264 1 :=\nbegin rw \u2190 one_mul (1 : \u03b1), apply decidable.mul_le_mul; {assumption <|> apply zero_le_one} end\n\nlemma mul_le_one : a \u2264 1 \u2192 0 \u2264 b \u2192 b \u2264 1 \u2192 a * b \u2264 1 :=\nby classical; exact decidable.mul_le_one\n\n-- See Note [decidable namespace]\nprotected lemma decidable.one_lt_mul_of_le_of_lt [@decidable_rel \u03b1 (\u2264)]\n  (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\nbegin\n  nontriviality,\n  calc 1 = 1 * 1 : by rw one_mul\n     ... < a * b : decidable.mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)\nend\n\nlemma one_lt_mul_of_le_of_lt : 1 \u2264 a \u2192 1 < b \u2192 1 < a * b :=\nby classical; exact decidable.one_lt_mul_of_le_of_lt\n\n-- See Note [decidable namespace]\nprotected lemma decidable.one_lt_mul_of_lt_of_le [@decidable_rel \u03b1 (\u2264)]\n  (ha : 1 < a) (hb : 1 \u2264 b) : 1 < a * b :=\nbegin\n  nontriviality,\n  calc 1 = 1 * 1 : by rw one_mul\n    ... < a * b : decidable.mul_lt_mul ha hb zero_lt_one $ zero_le_one.trans ha.le\nend\n\nlemma one_lt_mul_of_lt_of_le : 1 < a \u2192 1 \u2264 b \u2192 1 < a * b :=\nby classical; exact decidable.one_lt_mul_of_lt_of_le\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_of_le_one_right [@decidable_rel \u03b1 (\u2264)]\n  (ha : 0 \u2264 a) (hb1 : b \u2264 1) : a * b \u2264 a :=\ncalc a * b \u2264 a * 1 : decidable.mul_le_mul_of_nonneg_left hb1 ha\n... = a : mul_one a\n\nlemma mul_le_of_le_one_right : 0 \u2264 a \u2192 b \u2264 1 \u2192 a * b \u2264 a :=\nby classical; exact decidable.mul_le_of_le_one_right\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_of_le_one_left [@decidable_rel \u03b1 (\u2264)]\n  (hb : 0 \u2264 b) (ha1 : a \u2264 1) : a * b \u2264 b :=\ncalc a * b \u2264 1 * b : decidable.mul_le_mul ha1 le_rfl hb zero_le_one\n... = b : one_mul b\n\nlemma mul_le_of_le_one_left : 0 \u2264 b \u2192 a \u2264 1 \u2192 a * b \u2264 b :=\nby classical; exact decidable.mul_le_of_le_one_left\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_lt_one_of_nonneg_of_lt_one_left [@decidable_rel \u03b1 (\u2264)]\n  (ha0 : 0 \u2264 a) (ha : a < 1) (hb : b \u2264 1) : a * b < 1 :=\ncalc a * b \u2264 a : decidable.mul_le_of_le_one_right ha0 hb\n... < 1 : ha\n\nlemma mul_lt_one_of_nonneg_of_lt_one_left : 0 \u2264 a \u2192 a < 1 \u2192 b \u2264 1 \u2192 a * b < 1 :=\nby classical; exact decidable.mul_lt_one_of_nonneg_of_lt_one_left\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_lt_one_of_nonneg_of_lt_one_right [@decidable_rel \u03b1 (\u2264)]\n  (ha : a \u2264 1) (hb0 : 0 \u2264 b) (hb : b < 1) : a * b < 1 :=\ncalc a * b \u2264 b : decidable.mul_le_of_le_one_left hb0 ha\n... < 1 : hb\n\nlemma mul_lt_one_of_nonneg_of_lt_one_right : a \u2264 1 \u2192 0 \u2264 b \u2192 b < 1 \u2192 a * b < 1 :=\nby classical; exact decidable.mul_lt_one_of_nonneg_of_lt_one_right\n\nend ordered_semiring\n\nsection ordered_comm_semiring\n\n/-- An `ordered_comm_semiring \u03b1` is a commutative semiring `\u03b1` with a partial order such that\naddition is monotone and multiplication by a positive number is strictly monotone. -/\n@[protect_proj]\nclass ordered_comm_semiring (\u03b1 : Type u) extends ordered_semiring \u03b1, comm_semiring \u03b1\n\n/-- Pullback an `ordered_comm_semiring` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef function.injective.ordered_comm_semiring [ordered_comm_semiring \u03b1] {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_comm_semiring \u03b2 :=\n{ ..hf.comm_semiring f zero one add mul,\n  ..hf.ordered_semiring f zero one add mul }\n\nend ordered_comm_semiring\n\n/--\nA `linear_ordered_semiring \u03b1` is a nontrivial semiring `\u03b1` with a linear order\nsuch that addition is monotone and multiplication by a positive number is strictly monotone.\n-/\n-- It's not entirely clear we should assume `nontrivial` at this point;\n-- it would be reasonable to explore changing this,\n-- but be warned that the instances involving `domain` may cause\n-- typeclass search loops.\n@[protect_proj]\nclass linear_ordered_semiring (\u03b1 : Type u)\n  extends ordered_semiring \u03b1, linear_ordered_add_comm_monoid \u03b1, nontrivial \u03b1\n\nsection linear_ordered_semiring\nvariables [linear_ordered_semiring \u03b1] {a b c d : \u03b1}\n\n-- `norm_num` expects the lemma stating `0 < 1` to have a single typeclass argument\n-- (see `norm_num.prove_pos_nat`).\n-- Rather than working out how to relax that assumption,\n-- we provide a synonym for `zero_lt_one` (which needs both `ordered_semiring \u03b1` and `nontrivial \u03b1`)\n-- with only a `linear_ordered_semiring` typeclass argument.\nlemma zero_lt_one' : 0 < (1 : \u03b1) := zero_lt_one\n\nlemma lt_of_mul_lt_mul_left (h : c * a < c * b) (hc : 0 \u2264 c) : a < b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact lt_of_not_ge\n  (assume h1 : b \u2264 a,\n   have h2 : c * b \u2264 c * a, from decidable.mul_le_mul_of_nonneg_left h1 hc,\n   h2.not_lt h)\n\nlemma lt_of_mul_lt_mul_right (h : a * c < b * c) (hc : 0 \u2264 c) : a < b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact lt_of_not_ge\n  (assume h1 : b \u2264 a,\n   have h2 : b * c \u2264 a * c, from decidable.mul_le_mul_of_nonneg_right h1 hc,\n   h2.not_lt h)\n\nlemma le_of_mul_le_mul_left (h : c * a \u2264 c * b) (hc : 0 < c) : a \u2264 b :=\nle_of_not_gt\n  (assume h1 : b < a,\n   have h2 : c * b < c * a, from mul_lt_mul_of_pos_left h1 hc,\n   h2.not_le h)\n\nlemma le_of_mul_le_mul_right (h : a * c \u2264 b * c) (hc : 0 < c) : a \u2264 b :=\nle_of_not_gt\n  (assume h1 : b < a,\n   have h2 : b * c < a * c, from mul_lt_mul_of_pos_right h1 hc,\n   h2.not_le h)\n\nlemma pos_and_pos_or_neg_and_neg_of_mul_pos (hab : 0 < a * b) :\n  (0 < a \u2227 0 < b) \u2228 (a < 0 \u2227 b < 0) :=\nbegin\n  haveI := @linear_order.decidable_le \u03b1 _,\n  rcases lt_trichotomy 0 a with (ha|rfl|ha),\n  { refine or.inl \u27e8ha, lt_imp_lt_of_le_imp_le (\u03bb hb, _) hab\u27e9,\n    exact decidable.mul_nonpos_of_nonneg_of_nonpos ha.le hb },\n  { rw [zero_mul] at hab, exact hab.false.elim },\n  { refine or.inr \u27e8ha, lt_imp_lt_of_le_imp_le (\u03bb hb, _) hab\u27e9,\n    exact decidable.mul_nonpos_of_nonpos_of_nonneg ha.le hb }\nend\n\nlemma nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg (hab : 0 \u2264 a * b) :\n    (0 \u2264 a \u2227 0 \u2264 b) \u2228 (a \u2264 0 \u2227 b \u2264 0) :=\nbegin\n  haveI := @linear_order.decidable_le \u03b1 _,\n  refine decidable.or_iff_not_and_not.2 _,\n  simp only [not_and, not_le], intros ab nab, apply not_lt_of_le hab _,\n  rcases lt_trichotomy 0 a with (ha|rfl|ha),\n  exacts [mul_neg_of_pos_of_neg ha (ab ha.le), ((ab le_rfl).asymm (nab le_rfl)).elim,\n    mul_neg_of_neg_of_pos ha (nab ha.le)]\nend\n\nlemma pos_of_mul_pos_left (h : 0 < a * b) (ha : 0 \u2264 a) : 0 < b :=\n((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ \u03bb h, h.1.not_le ha).2\n\nlemma pos_of_mul_pos_right (h : 0 < a * b) (hb : 0 \u2264 b) : 0 < a :=\n((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ \u03bb h, h.2.not_le hb).1\n\nlemma pos_iff_pos_of_mul_pos (hab : 0 < a * b) : 0 < a \u2194 0 < b :=\n\u27e8pos_of_mul_pos_left hab \u2218 le_of_lt, pos_of_mul_pos_right hab \u2218 le_of_lt\u27e9\n\nlemma neg_of_mul_pos_left (h : 0 < a * b) (ha : a \u2264 0) : b < 0 :=\n((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left $ \u03bb h, h.1.not_le ha).2\n\nlemma neg_of_mul_pos_right (h : 0 < a * b) (ha : b \u2264 0) : a < 0 :=\n((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left $ \u03bb h, h.2.not_le ha).1\n\nlemma neg_iff_neg_of_mul_pos (hab : 0 < a * b) : a < 0 \u2194 b < 0 :=\n\u27e8neg_of_mul_pos_left hab \u2218 le_of_lt, neg_of_mul_pos_right hab \u2218 le_of_lt\u27e9\n\nlemma nonneg_of_mul_nonneg_left (h : 0 \u2264 a * b) (h1 : 0 < a) : 0 \u2264 b :=\nle_of_not_gt (assume h2 : b < 0, (mul_neg_of_pos_of_neg h1 h2).not_le h)\n\nlemma nonneg_of_mul_nonneg_right (h : 0 \u2264 a * b) (h1 : 0 < b) : 0 \u2264 a :=\nle_of_not_gt (assume h2 : a < 0, (mul_neg_of_neg_of_pos h2 h1).not_le h)\n\nlemma neg_of_mul_neg_left (h : a * b < 0) (h1 : 0 \u2264 a) : b < 0 :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nlt_of_not_ge (assume h2 : b \u2265 0, (decidable.mul_nonneg h1 h2).not_lt h)\n\nlemma neg_of_mul_neg_right (h : a * b < 0) (h1 : 0 \u2264 b) : a < 0 :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nlt_of_not_ge (assume h2 : a \u2265 0, (decidable.mul_nonneg h2 h1).not_lt h)\n\nlemma nonpos_of_mul_nonpos_left (h : a * b \u2264 0) (h1 : 0 < a) : b \u2264 0 :=\nle_of_not_gt (assume h2 : b > 0, (mul_pos h1 h2).not_le h)\n\nlemma nonpos_of_mul_nonpos_right (h : a * b \u2264 0) (h1 : 0 < b) : a \u2264 0 :=\nle_of_not_gt (assume h2 : a > 0, (mul_pos h2 h1).not_le h)\n\n@[simp] lemma mul_le_mul_left (h : 0 < c) : c * a \u2264 c * b \u2194 a \u2264 b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8\u03bb h', le_of_mul_le_mul_left h' h, \u03bb h', decidable.mul_le_mul_of_nonneg_left h' h.le\u27e9\n\n@[simp] lemma mul_le_mul_right (h : 0 < c) : a * c \u2264 b * c \u2194 a \u2264 b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8\u03bb h', le_of_mul_le_mul_right h' h, \u03bb h', decidable.mul_le_mul_of_nonneg_right h' h.le\u27e9\n\n@[simp] lemma mul_lt_mul_left (h : 0 < c) : c * a < c * b \u2194 a < b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8lt_imp_lt_of_le_imp_le $ \u03bb h', decidable.mul_le_mul_of_nonneg_left h' h.le,\n \u03bb h', mul_lt_mul_of_pos_left h' h\u27e9\n\n@[simp] lemma mul_lt_mul_right (h : 0 < c) : a * c < b * c \u2194 a < b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8lt_imp_lt_of_le_imp_le $ \u03bb h', decidable.mul_le_mul_of_nonneg_right h' h.le,\n \u03bb h', mul_lt_mul_of_pos_right h' h\u27e9\n\n@[simp] lemma zero_le_mul_left (h : 0 < c) : 0 \u2264 c * b \u2194 0 \u2264 b :=\nby { convert mul_le_mul_left h, simp }\n\n@[simp] lemma zero_le_mul_right (h : 0 < c) : 0 \u2264 b * c \u2194 0 \u2264 b :=\nby { convert mul_le_mul_right h, simp }\n\n@[simp] lemma zero_lt_mul_left (h : 0 < c) : 0 < c * b \u2194 0 < b :=\nby { convert mul_lt_mul_left h, simp }\n\n@[simp] lemma zero_lt_mul_right (h : 0 < c) : 0 < b * c \u2194 0 < b :=\nby { convert mul_lt_mul_right h, simp }\n\nlemma add_le_mul_of_left_le_right (a2 : 2 \u2264 a) (ab : a \u2264 b) : a + b \u2264 a * b :=\nhave 0 < b, from\ncalc 0 < 2 : zero_lt_two\n   ... \u2264 a : a2\n   ... \u2264 b : ab,\ncalc a + b \u2264 b + b : add_le_add_right ab b\n       ... = 2 * b : (two_mul b).symm\n       ... \u2264 a * b : (mul_le_mul_right this).mpr a2\n\nlemma add_le_mul_of_right_le_left (b2 : 2 \u2264 b) (ba : b \u2264 a) : a + b \u2264 a * b :=\nhave 0 < a, from\ncalc 0 < 2 : zero_lt_two\n   ... \u2264 b : b2\n   ... \u2264 a : ba,\ncalc a + b \u2264 a + a : add_le_add_left ba a\n       ... = a * 2 : (mul_two a).symm\n       ... \u2264 a * b : (mul_le_mul_left this).mpr b2\n\nlemma add_le_mul (a2 : 2 \u2264 a) (b2 : 2 \u2264 b) : a + b \u2264 a * b :=\nif hab : a \u2264 b then add_le_mul_of_left_le_right a2 hab\n               else add_le_mul_of_right_le_left b2 (le_of_not_le hab)\n\nlemma add_le_mul' (a2 : 2 \u2264 a) (b2 : 2 \u2264 b) : a + b \u2264 b * a :=\n(le_of_eq (add_comm _ _)).trans (add_le_mul b2 a2)\n\nsection\nvariables [nontrivial \u03b1]\n\n@[simp] lemma bit0_le_bit0 : bit0 a \u2264 bit0 b \u2194 a \u2264 b :=\nby rw [bit0, bit0, \u2190 two_mul, \u2190 two_mul, mul_le_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma bit0_lt_bit0 : bit0 a < bit0 b \u2194 a < b :=\nby rw [bit0, bit0, \u2190 two_mul, \u2190 two_mul, mul_lt_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma bit1_le_bit1 : bit1 a \u2264 bit1 b \u2194 a \u2264 b :=\n(add_le_add_iff_right 1).trans bit0_le_bit0\n\n@[simp] lemma bit1_lt_bit1 : bit1 a < bit1 b \u2194 a < b :=\n(add_lt_add_iff_right 1).trans bit0_lt_bit0\n\n@[simp] lemma one_le_bit1 : (1 : \u03b1) \u2264 bit1 a \u2194 0 \u2264 a :=\nby rw [bit1, le_add_iff_nonneg_left, bit0, \u2190 two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma one_lt_bit1 : (1 : \u03b1) < bit1 a \u2194 0 < a :=\nby rw [bit1, lt_add_iff_pos_left, bit0, \u2190 two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma zero_le_bit0 : (0 : \u03b1) \u2264 bit0 a \u2194 0 \u2264 a :=\nby rw [bit0, \u2190 two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma zero_lt_bit0 : (0 : \u03b1) < bit0 a \u2194 0 < a :=\nby rw [bit0, \u2190 two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\nend\n\nlemma le_mul_iff_one_le_left (hb : 0 < b) : b \u2264 a * b \u2194 1 \u2264 a :=\nsuffices 1 * b \u2264 a * b \u2194 1 \u2264 a, by rwa one_mul at this,\nmul_le_mul_right hb\n\nlemma lt_mul_iff_one_lt_left (hb : 0 < b) : b < a * b \u2194 1 < a :=\nsuffices 1 * b < a * b \u2194 1 < a, by rwa one_mul at this,\nmul_lt_mul_right hb\n\nlemma le_mul_iff_one_le_right (hb : 0 < b) : b \u2264 b * a \u2194 1 \u2264 a :=\nsuffices b * 1 \u2264 b * a \u2194 1 \u2264 a, by rwa mul_one at this,\nmul_le_mul_left hb\n\nlemma lt_mul_iff_one_lt_right (hb : 0 < b) : b < b * a \u2194 1 < a :=\nsuffices b * 1 < b * a \u2194 1 < a, by rwa mul_one at this,\nmul_lt_mul_left hb\n\ntheorem mul_nonneg_iff_right_nonneg_of_pos (ha : 0 < a) : 0 \u2264 a * b \u2194 0 \u2264 b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8\u03bb h, nonneg_of_mul_nonneg_left h ha, \u03bb h, decidable.mul_nonneg ha.le h\u27e9\n\ntheorem mul_nonneg_iff_left_nonneg_of_pos (hb : 0 < b) : 0 \u2264 a * b \u2194 0 \u2264 a :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8\u03bb h, nonneg_of_mul_nonneg_right h hb, \u03bb h, decidable.mul_nonneg h hb.le\u27e9\n\nlemma mul_le_iff_le_one_left (hb : 0 < b) : a * b \u2264 b \u2194 a \u2264 1 :=\n\u27e8 \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).2 h.not_lt),\n  \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).1 h.not_lt) \u27e9\n\nlemma mul_lt_iff_lt_one_left (hb : 0 < b) : a * b < b \u2194 a < 1 :=\nlt_iff_lt_of_le_iff_le $ le_mul_iff_one_le_left hb\n\nlemma mul_le_iff_le_one_right (hb : 0 < b) : b * a \u2264 b \u2194 a \u2264 1 :=\n\u27e8 \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).2 h.not_lt),\n  \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).1 h.not_lt) \u27e9\n\nlemma mul_lt_iff_lt_one_right (hb : 0 < b) : b * a < b \u2194 a < 1 :=\nlt_iff_lt_of_le_iff_le $ le_mul_iff_one_le_right hb\n\n-- TODO: `left` and `right` for these two lemmas are backwards compared to `neg_of_mul_pos`\n-- lemmas.\nlemma nonpos_of_mul_nonneg_left (h : 0 \u2264 a * b) (hb : b < 0) : a \u2264 0 :=\nle_of_not_gt (\u03bb ha, absurd h (mul_neg_of_pos_of_neg ha hb).not_le)\n\nlemma nonpos_of_mul_nonneg_right (h : 0 \u2264 a * b) (ha : a < 0) : b \u2264 0 :=\nle_of_not_gt (\u03bb hb, absurd h (mul_neg_of_neg_of_pos ha hb).not_le)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_semiring.to_no_max_order {\u03b1 : Type*} [linear_ordered_semiring \u03b1] :\n  no_max_order \u03b1 :=\n\u27e8assume a, \u27e8a + 1, lt_add_of_pos_right _ zero_lt_one\u27e9\u27e9\n\n/-- Pullback a `linear_ordered_semiring` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef function.injective.linear_ordered_semiring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  linear_ordered_semiring \u03b2 :=\n{ .. linear_order.lift f hf,\n  .. pullback_nonzero f zero one,\n  .. hf.ordered_semiring f zero one add mul }\n\n@[simp] lemma units.inv_pos {u : \u03b1\u02e3} : (0 : \u03b1) < \u2191u\u207b\u00b9 \u2194 (0 : \u03b1) < u :=\nhave \u2200 {u : \u03b1\u02e3}, (0 : \u03b1) < u \u2192 (0 : \u03b1) < \u2191u\u207b\u00b9 := \u03bb u h,\n  (zero_lt_mul_left h).mp $ u.mul_inv.symm \u25b8 zero_lt_one,\n\u27e8this, this\u27e9\n\n@[simp] lemma units.inv_neg {u : \u03b1\u02e3} : \u2191u\u207b\u00b9 < (0 : \u03b1) \u2194 \u2191u < (0 : \u03b1) :=\nhave \u2200 {u : \u03b1\u02e3}, \u2191u < (0 : \u03b1) \u2192 \u2191u\u207b\u00b9 < (0 : \u03b1) := \u03bb u h,\n  neg_of_mul_pos_left (by exact (u.mul_inv.symm \u25b8 zero_lt_one)) h.le,\n\u27e8this, this\u27e9\n\nend linear_ordered_semiring\n\nsection mono\nvariables {\u03b2 : Type*} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f g : \u03b2 \u2192 \u03b1} {a : \u03b1}\n\nlemma monotone_mul_left_of_nonneg (ha : 0 \u2264 a) : monotone (\u03bb x, a*x) :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nassume b c b_le_c, decidable.mul_le_mul_of_nonneg_left b_le_c ha\n\nlemma monotone_mul_right_of_nonneg (ha : 0 \u2264 a) : monotone (\u03bb x, x*a) :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nassume b c b_le_c, decidable.mul_le_mul_of_nonneg_right b_le_c ha\n\nlemma monotone.mul_const (hf : monotone f) (ha : 0 \u2264 a) :\n  monotone (\u03bb x, (f x) * a) :=\n(monotone_mul_right_of_nonneg ha).comp hf\n\nlemma monotone.const_mul (hf : monotone f) (ha : 0 \u2264 a) :\n  monotone (\u03bb x, a * (f x)) :=\n(monotone_mul_left_of_nonneg ha).comp hf\n\nlemma monotone.mul (hf : monotone f) (hg : monotone g) (hf0 : \u2200 x, 0 \u2264 f x) (hg0 : \u2200 x, 0 \u2264 g x) :\n  monotone (\u03bb x, f x * g x) :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u03bb x y h, decidable.mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)\n\nlemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (\u03bb x, a * x) :=\nassume b c b_lt_c, (mul_lt_mul_left ha).2 b_lt_c\n\nlemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (\u03bb x, x * a) :=\nassume b c b_lt_c, (mul_lt_mul_right ha).2 b_lt_c\n\nlemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) :\n  strict_mono (\u03bb x, (f x) * a) :=\n(strict_mono_mul_right_of_pos ha).comp hf\n\nlemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) :\n  strict_mono (\u03bb x, a * (f x)) :=\n(strict_mono_mul_left_of_pos ha).comp hf\n\nlemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : \u2200 x, 0 \u2264 f x)\n  (hg0 : \u2200 x, 0 < g x) :\n  strict_mono (\u03bb x, f x * g x) :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u03bb x y h, decidable.mul_lt_mul (hf h) (hg h.le) (hg0 x) (hf0 y)\n\nlemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : \u2200 x, 0 < f x)\n  (hg0 : \u2200 x, 0 \u2264 g x) :\n  strict_mono (\u03bb x, f x * g x) :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u03bb x y h, decidable.mul_lt_mul' (hf h.le) (hg h) (hg0 x) (hf0 y)\n\nlemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : \u2200 x, 0 \u2264 f x)\n  (hg0 : \u2200 x, 0 \u2264 g x) :\n  strict_mono (\u03bb x, f x * g x) :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u03bb x y h, decidable.mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)\n\nend mono\n\nsection linear_ordered_semiring\nvariables [linear_ordered_semiring \u03b1] {a b c : \u03b1}\n\nlemma mul_max_of_nonneg (b c : \u03b1) (ha : 0 \u2264 a) : a * max b c = max (a * b) (a * c) :=\n(monotone_mul_left_of_nonneg ha).map_max\n\nlemma mul_min_of_nonneg (b c : \u03b1) (ha : 0 \u2264 a) : a * min b c = min (a * b) (a * c) :=\n(monotone_mul_left_of_nonneg ha).map_min\n\nlemma max_mul_of_nonneg (a b : \u03b1) (hc : 0 \u2264 c) : max a b * c = max (a * c) (b * c) :=\n(monotone_mul_right_of_nonneg hc).map_max\n\nlemma min_mul_of_nonneg (a b : \u03b1) (hc : 0 \u2264 c) : min a b * c = min (a * c) (b * c) :=\n(monotone_mul_right_of_nonneg hc).map_min\n\nend linear_ordered_semiring\n\n/-- An `ordered_ring \u03b1` is a ring `\u03b1` with a partial order such that\naddition is monotone and multiplication by a positive number is strictly monotone. -/\n@[protect_proj]\nclass ordered_ring (\u03b1 : Type u) extends ring \u03b1, ordered_add_comm_group \u03b1 :=\n(zero_le_one : 0 \u2264 (1 : \u03b1))\n(mul_pos     : \u2200 a b : \u03b1, 0 < a \u2192 0 < b \u2192 0 < a * b)\n\nsection ordered_ring\nvariables [ordered_ring \u03b1] {a b c : \u03b1}\n\n-- See Note [decidable namespace]\nprotected lemma decidable.ordered_ring.mul_nonneg [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} (h\u2081 : 0 \u2264 a) (h\u2082 : 0 \u2264 b) : 0 \u2264 a * b :=\nbegin\n  by_cases ha : a \u2264 0, { simp [le_antisymm ha h\u2081] },\n  by_cases hb : b \u2264 0, { simp [le_antisymm hb h\u2082] },\n  exact (le_not_le_of_lt (ordered_ring.mul_pos a b (h\u2081.lt_of_not_le ha) (h\u2082.lt_of_not_le hb))).1,\nend\n\nlemma ordered_ring.mul_nonneg : 0 \u2264 a \u2192 0 \u2264 b \u2192 0 \u2264 a * b :=\nby classical; exact decidable.ordered_ring.mul_nonneg\n\n-- See Note [decidable namespace]\nprotected lemma decidable.ordered_ring.mul_le_mul_of_nonneg_left\n  [@decidable_rel \u03b1 (\u2264)] (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c * a \u2264 c * b :=\nbegin\n  rw [\u2190 sub_nonneg, \u2190 mul_sub],\n  exact decidable.ordered_ring.mul_nonneg h\u2082 (sub_nonneg.2 h\u2081),\nend\n\nlemma ordered_ring.mul_le_mul_of_nonneg_left : a \u2264 b \u2192 0 \u2264 c \u2192 c * a \u2264 c * b :=\nby classical; exact decidable.ordered_ring.mul_le_mul_of_nonneg_left\n\n-- See Note [decidable namespace]\nprotected lemma decidable.ordered_ring.mul_le_mul_of_nonneg_right\n  [@decidable_rel \u03b1 (\u2264)] (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : a * c \u2264 b * c :=\nbegin\n  rw [\u2190 sub_nonneg, \u2190 sub_mul],\n  exact decidable.ordered_ring.mul_nonneg (sub_nonneg.2 h\u2081) h\u2082,\nend\n\nlemma ordered_ring.mul_le_mul_of_nonneg_right : a \u2264 b \u2192 0 \u2264 c \u2192 a * c \u2264 b * c :=\nby classical; exact decidable.ordered_ring.mul_le_mul_of_nonneg_right\n\nlemma ordered_ring.mul_lt_mul_of_pos_left (h\u2081 : a < b) (h\u2082 : 0 < c) : c * a < c * b :=\nbegin\n  rw [\u2190 sub_pos, \u2190 mul_sub],\n  exact ordered_ring.mul_pos _ _ h\u2082 (sub_pos.2 h\u2081),\nend\n\nlemma ordered_ring.mul_lt_mul_of_pos_right (h\u2081 : a < b) (h\u2082 : 0 < c) : a * c < b * c :=\nbegin\n  rw [\u2190 sub_pos, \u2190 sub_mul],\n  exact ordered_ring.mul_pos _ _ (sub_pos.2 h\u2081) h\u2082,\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance ordered_ring.to_ordered_semiring : ordered_semiring \u03b1 :=\n{ mul_zero                   := mul_zero,\n  zero_mul                   := zero_mul,\n  add_left_cancel            := @add_left_cancel \u03b1 _,\n  le_of_add_le_add_left      := @le_of_add_le_add_left \u03b1 _ _ _,\n  mul_lt_mul_of_pos_left     := @ordered_ring.mul_lt_mul_of_pos_left \u03b1 _,\n  mul_lt_mul_of_pos_right    := @ordered_ring.mul_lt_mul_of_pos_right \u03b1 _,\n  ..\u2039ordered_ring \u03b1\u203a }\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_mul_of_nonpos_left [@decidable_rel \u03b1 (\u2264)]\n  {a b c : \u03b1} (h : b \u2264 a) (hc : c \u2264 0) : c * a \u2264 c * b :=\nhave -c \u2265 0,              from neg_nonneg_of_nonpos hc,\nhave -c * b \u2264 -c * a,     from decidable.mul_le_mul_of_nonneg_left h this,\nhave -(c * b) \u2264 -(c * a), by rwa [\u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul] at this,\nle_of_neg_le_neg this\n\nlemma mul_le_mul_of_nonpos_left {a b c : \u03b1} : b \u2264 a \u2192 c \u2264 0 \u2192 c * a \u2264 c * b :=\nby classical; exact decidable.mul_le_mul_of_nonpos_left\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_le_mul_of_nonpos_right [@decidable_rel \u03b1 (\u2264)]\n  {a b c : \u03b1} (h : b \u2264 a) (hc : c \u2264 0) : a * c \u2264 b * c :=\nhave -c \u2265 0,              from neg_nonneg_of_nonpos hc,\nhave b * -c \u2264 a * -c,     from decidable.mul_le_mul_of_nonneg_right h this,\nhave -(b * c) \u2264 -(a * c), by rwa [\u2190 neg_mul_eq_mul_neg, \u2190 neg_mul_eq_mul_neg] at this,\nle_of_neg_le_neg this\n\nlemma mul_le_mul_of_nonpos_right {a b c : \u03b1} : b \u2264 a \u2192 c \u2264 0 \u2192 a * c \u2264 b * c :=\nby classical; exact decidable.mul_le_mul_of_nonpos_right\n\n-- See Note [decidable namespace]\nprotected lemma decidable.mul_nonneg_of_nonpos_of_nonpos [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} (ha : a \u2264 0) (hb : b \u2264 0) : 0 \u2264 a * b :=\nhave 0 * b \u2264 a * b, from decidable.mul_le_mul_of_nonpos_right ha hb,\nby rwa zero_mul at this\n\nlemma mul_nonneg_of_nonpos_of_nonpos {a b : \u03b1} : a \u2264 0 \u2192 b \u2264 0 \u2192 0 \u2264 a * b :=\nby classical; exact decidable.mul_nonneg_of_nonpos_of_nonpos\n\nlemma mul_lt_mul_of_neg_left {a b c : \u03b1} (h : b < a) (hc : c < 0) : c * a < c * b :=\nhave -c > 0,              from neg_pos_of_neg hc,\nhave -c * b < -c * a,     from mul_lt_mul_of_pos_left h this,\nhave -(c * b) < -(c * a), by rwa [\u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul] at this,\nlt_of_neg_lt_neg this\n\nlemma mul_lt_mul_of_neg_right {a b c : \u03b1} (h : b < a) (hc : c < 0) : a * c < b * c :=\nhave -c > 0,              from neg_pos_of_neg hc,\nhave b * -c < a * -c,     from mul_lt_mul_of_pos_right h this,\nhave -(b * c) < -(a * c), by rwa [\u2190 neg_mul_eq_mul_neg, \u2190 neg_mul_eq_mul_neg] at this,\nlt_of_neg_lt_neg this\n\nlemma mul_pos_of_neg_of_neg {a b : \u03b1} (ha : a < 0) (hb : b < 0) : 0 < a * b :=\nhave 0 * b < a * b, from mul_lt_mul_of_neg_right ha hb,\nby rwa zero_mul at this\n\n/-- Pullback an `ordered_ring` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef function.injective.ordered_ring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (- x) = - f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  ordered_ring \u03b2 :=\n{ mul_pos := \u03bb a b a0 b0, show f 0 < f (a * b), by { rw [zero, mul], apply mul_pos; rwa \u2190 zero },\n  ..hf.ordered_semiring f zero one add mul,\n  ..hf.ring f zero one add mul neg sub }\n\nlemma le_iff_exists_nonneg_add (a b : \u03b1) : a \u2264 b \u2194 \u2203 c \u2265 0, b = a + c :=\n\u27e8\u03bb h, \u27e8b - a, sub_nonneg.mpr h, by simp\u27e9,\n  \u03bb \u27e8c, hc, h\u27e9, by { rw [h, le_add_iff_nonneg_right], exact hc }\u27e9\n\nend ordered_ring\n\nsection ordered_comm_ring\n\n/-- An `ordered_comm_ring \u03b1` is a commutative ring `\u03b1` with a partial order such that\naddition is monotone and multiplication by a positive number is strictly monotone. -/\n@[protect_proj]\nclass ordered_comm_ring (\u03b1 : Type u) extends ordered_ring \u03b1, comm_ring \u03b1\n\n@[priority 100] -- See note [lower instance priority]\ninstance ordered_comm_ring.to_ordered_comm_semiring {\u03b1 : Type u} [ordered_comm_ring \u03b1] :\n  ordered_comm_semiring \u03b1 :=\n{ .. (by apply_instance : ordered_semiring \u03b1),\n  .. \u2039ordered_comm_ring \u03b1\u203a }\n\n/-- Pullback an `ordered_comm_ring` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef function.injective.ordered_comm_ring [ordered_comm_ring \u03b1] {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (- x) = - f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  ordered_comm_ring \u03b2 :=\n{ ..hf.ordered_ring f zero one add mul neg sub,\n  ..hf.comm_ring f zero one add mul neg sub }\n\nend ordered_comm_ring\n\n/-- A `linear_ordered_ring \u03b1` is a ring `\u03b1` with a linear order such that\naddition is monotone and multiplication by a positive number is strictly monotone. -/\n@[protect_proj] class linear_ordered_ring (\u03b1 : Type u)\n  extends ordered_ring \u03b1, linear_order \u03b1, nontrivial \u03b1\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_ring.to_linear_ordered_add_comm_group [s : linear_ordered_ring \u03b1] :\n  linear_ordered_add_comm_group \u03b1 :=\n{ .. s }\n\nsection linear_ordered_ring\nvariables [linear_ordered_ring \u03b1] {a b c : \u03b1}\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semiring \u03b1 :=\n{ mul_zero                   := mul_zero,\n  zero_mul                   := zero_mul,\n  add_left_cancel            := @add_left_cancel \u03b1 _,\n  le_of_add_le_add_left      := @le_of_add_le_add_left \u03b1 _ _ _,\n  mul_lt_mul_of_pos_left     := @mul_lt_mul_of_pos_left \u03b1 _,\n  mul_lt_mul_of_pos_right    := @mul_lt_mul_of_pos_right \u03b1 _,\n  le_total                   := linear_ordered_ring.le_total,\n  ..\u2039linear_ordered_ring \u03b1\u203a }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_ring.is_domain : is_domain \u03b1 :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero :=\n    begin\n      intros a b hab,\n      refine decidable.or_iff_not_and_not.2 (\u03bb h, _), revert hab,\n      cases lt_or_gt_of_ne h.1 with ha ha; cases lt_or_gt_of_ne h.2 with hb hb,\n      exacts [(mul_pos_of_neg_of_neg ha hb).ne.symm, (mul_neg_of_neg_of_pos ha hb).ne,\n        (mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne.symm]\n    end,\n  .. \u2039linear_ordered_ring \u03b1\u203a }\n\n@[simp] lemma abs_one : |(1 : \u03b1)| = 1 := abs_of_pos zero_lt_one\n@[simp] lemma abs_two : |(2 : \u03b1)| = 2 := abs_of_pos zero_lt_two\n\nlemma abs_mul (a b : \u03b1) : |a * b| = |a| * |b| :=\nbegin\n  haveI := @linear_order.decidable_le \u03b1 _,\n  rw [abs_eq (decidable.mul_nonneg (abs_nonneg a) (abs_nonneg b))],\n  cases le_total a 0 with ha ha; cases le_total b 0 with hb hb;\n    simp only [abs_of_nonpos, abs_of_nonneg, true_or, or_true, eq_self_iff_true,\n      neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm, neg_neg, *]\nend\n\n/-- `abs` as a `monoid_with_zero_hom`. -/\ndef abs_hom : \u03b1 \u2192*\u2080 \u03b1 := \u27e8abs, abs_zero, abs_one, abs_mul\u27e9\n\n@[simp] lemma abs_mul_abs_self (a : \u03b1) : |a| * |a| = a * a :=\nabs_by_cases (\u03bb x, x * x = a * a) rfl (neg_mul_neg a a)\n\n@[simp] lemma abs_mul_self (a : \u03b1) : |a * a| = a * a :=\nby rw [abs_mul, abs_mul_abs_self]\n\nlemma mul_pos_iff : 0 < a * b \u2194 0 < a \u2227 0 < b \u2228 a < 0 \u2227 b < 0 :=\n\u27e8pos_and_pos_or_neg_and_neg_of_mul_pos,\n  \u03bb h, h.elim (and_imp.2 mul_pos) (and_imp.2 mul_pos_of_neg_of_neg)\u27e9\n\nlemma mul_neg_iff : a * b < 0 \u2194 0 < a \u2227 b < 0 \u2228 a < 0 \u2227 0 < b :=\nby rw [\u2190 neg_pos, neg_mul_eq_mul_neg, mul_pos_iff, neg_pos, neg_lt_zero]\n\nlemma mul_nonneg_iff : 0 \u2264 a * b \u2194 0 \u2264 a \u2227 0 \u2264 b \u2228 a \u2264 0 \u2227 b \u2264 0 :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg,\n  \u03bb h, h.elim (and_imp.2 decidable.mul_nonneg) (and_imp.2 decidable.mul_nonneg_of_nonpos_of_nonpos)\u27e9\n\n/-- Out of three elements of a `linear_ordered_ring`, two must have the same sign. -/\nlemma mul_nonneg_of_three (a b c : \u03b1) :\n  0 \u2264 a * b \u2228 0 \u2264 b * c \u2228 0 \u2264 c * a :=\nby iterate 3 { rw mul_nonneg_iff };\n  have := le_total 0 a; have := le_total 0 b; have := le_total 0 c; itauto\n\nlemma mul_nonpos_iff : a * b \u2264 0 \u2194 0 \u2264 a \u2227 b \u2264 0 \u2228 a \u2264 0 \u2227 0 \u2264 b :=\nby rw [\u2190 neg_nonneg, neg_mul_eq_mul_neg, mul_nonneg_iff, neg_nonneg, neg_nonpos]\n\nlemma mul_self_nonneg (a : \u03b1) : 0 \u2264 a * a :=\nabs_mul_self a \u25b8 abs_nonneg _\n\n@[simp] lemma neg_le_self_iff : -a \u2264 a \u2194 0 \u2264 a :=\nby simp [neg_le_iff_add_nonneg, \u2190 two_mul, mul_nonneg_iff, zero_le_one, (@zero_lt_two \u03b1 _ _).not_le]\n\n@[simp] lemma neg_lt_self_iff : -a < a \u2194 0 < a :=\nby simp [neg_lt_iff_pos_add, \u2190 two_mul, mul_pos_iff, zero_lt_one, (@zero_lt_two \u03b1 _ _).not_lt]\n\n@[simp] lemma le_neg_self_iff : a \u2264 -a \u2194 a \u2264 0 :=\ncalc a \u2264 -a \u2194 -(-a) \u2264 -a : by rw neg_neg\n... \u2194 0 \u2264 -a : neg_le_self_iff\n... \u2194 a \u2264 0 : neg_nonneg\n\n@[simp] lemma lt_neg_self_iff : a < -a \u2194 a < 0 :=\ncalc a < -a \u2194 -(-a) < -a : by rw neg_neg\n... \u2194 0 < -a : neg_lt_self_iff\n... \u2194 a < 0 : neg_pos\n\n@[simp] lemma abs_eq_self : |a| = a \u2194 0 \u2264 a := by simp [abs_eq_max_neg]\n\n@[simp] lemma abs_eq_neg_self : |a| = -a \u2194 a \u2264 0 := by simp [abs_eq_max_neg]\n\n/-- For an element `a` of a linear ordered ring, either `abs a = a` and `0 \u2264 a`,\n    or `abs a = -a` and `a < 0`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma abs_cases (a : \u03b1) : (|a| = a \u2227 0 \u2264 a) \u2228 (|a| = -a \u2227 a < 0) :=\nbegin\n  by_cases 0 \u2264 a,\n  { left,\n    exact \u27e8abs_eq_self.mpr h, h\u27e9 },\n  { right,\n    push_neg at h,\n    exact \u27e8abs_eq_neg_self.mpr (le_of_lt h), h\u27e9 }\nend\n\nlemma gt_of_mul_lt_mul_neg_left (h : c * a < c * b) (hc : c \u2264 0) : b < a :=\nhave nhc : 0 \u2264 -c, from neg_nonneg_of_nonpos hc,\nhave h2 : -(c * b) < -(c * a), from neg_lt_neg h,\nhave h3 : (-c) * b < (-c) * a, from calc\n     (-c) * b = - (c * b)    : by rewrite neg_mul_eq_neg_mul\n          ... < -(c * a)     : h2\n          ... = (-c) * a     : by rewrite neg_mul_eq_neg_mul,\nlt_of_mul_lt_mul_left h3 nhc\n\nlemma neg_one_lt_zero : -1 < (0:\u03b1) := neg_lt_zero.2 zero_lt_one\n\nlemma le_of_mul_le_of_one_le {a b c : \u03b1} (h : a * c \u2264 b) (hb : 0 \u2264 b) (hc : 1 \u2264 c) : a \u2264 b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nhave h' : a * c \u2264 b * c, from calc\n     a * c \u2264 b : h\n       ... = b * 1 : by rewrite mul_one\n       ... \u2264 b * c : decidable.mul_le_mul_of_nonneg_left hc hb,\nle_of_mul_le_mul_right h' (zero_lt_one.trans_le hc)\n\nlemma nonneg_le_nonneg_of_sq_le_sq {a b : \u03b1} (hb : 0 \u2264 b) (h : a * a \u2264 b * b) : a \u2264 b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nle_of_not_gt (\u03bbhab, (decidable.mul_self_lt_mul_self hb hab).not_le h)\n\nlemma mul_self_le_mul_self_iff {a b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a \u2264 b \u2194 a * a \u2264 b * b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8decidable.mul_self_le_mul_self h1, nonneg_le_nonneg_of_sq_le_sq h2\u27e9\n\nlemma mul_self_lt_mul_self_iff {a b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a < b \u2194 a * a < b * b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n((@decidable.strict_mono_on_mul_self \u03b1 _ _).lt_iff_lt h1 h2).symm\n\nlemma mul_self_inj {a b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a * a = b * b \u2194 a = b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n(@decidable.strict_mono_on_mul_self \u03b1 _ _).inj_on.eq_iff h1 h2\n\n@[simp] lemma mul_le_mul_left_of_neg {a b c : \u03b1} (h : c < 0) : c * a \u2264 c * b \u2194 b \u2264 a :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8le_imp_le_of_lt_imp_lt $ \u03bb h', mul_lt_mul_of_neg_left h' h,\n  \u03bb h', decidable.mul_le_mul_of_nonpos_left h' h.le\u27e9\n\n@[simp] lemma mul_le_mul_right_of_neg {a b c : \u03b1} (h : c < 0) : a * c \u2264 b * c \u2194 b \u2264 a :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\n\u27e8le_imp_le_of_lt_imp_lt $ \u03bb h', mul_lt_mul_of_neg_right h' h,\n  \u03bb h', decidable.mul_le_mul_of_nonpos_right h' h.le\u27e9\n\n@[simp] lemma mul_lt_mul_left_of_neg {a b c : \u03b1} (h : c < 0) : c * a < c * b \u2194 b < a :=\nlt_iff_lt_of_le_iff_le (mul_le_mul_left_of_neg h)\n\n@[simp] lemma mul_lt_mul_right_of_neg {a b c : \u03b1} (h : c < 0) : a * c < b * c \u2194 b < a :=\nlt_iff_lt_of_le_iff_le (mul_le_mul_right_of_neg h)\n\nlemma sub_one_lt (a : \u03b1) : a - 1 < a :=\nsub_lt_iff_lt_add.2 (lt_add_one a)\n\n@[simp] lemma mul_self_pos {a : \u03b1} : 0 < a * a \u2194 a \u2260 0 :=\nbegin\n  split,\n  { rintro h rfl, rw mul_zero at h, exact h.false },\n  { intro h,\n    cases h.lt_or_lt with h h,\n    exacts [mul_pos_of_neg_of_neg h h, mul_pos h h] }\nend\n\nlemma mul_self_le_mul_self_of_le_of_neg_le {x y : \u03b1} (h\u2081 : x \u2264 y) (h\u2082 : -x \u2264 y) : x * x \u2264 y * y :=\nbegin\n  haveI := @linear_order.decidable_le \u03b1 _,\n  rw [\u2190 abs_mul_abs_self x],\n  exact decidable.mul_self_le_mul_self (abs_nonneg x) (abs_le.2 \u27e8neg_le.2 h\u2082, h\u2081\u27e9)\nend\n\nlemma nonneg_of_mul_nonpos_left {a b : \u03b1} (h : a * b \u2264 0) (hb : b < 0) : 0 \u2264 a :=\nle_of_not_gt (\u03bb ha, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)\n\nlemma nonneg_of_mul_nonpos_right {a b : \u03b1} (h : a * b \u2264 0) (ha : a < 0) : 0 \u2264 b :=\nle_of_not_gt (\u03bb hb, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)\n\nlemma pos_of_mul_neg_left {a b : \u03b1} (h : a * b < 0) (hb : b \u2264 0) : 0 < a :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nlt_of_not_ge (\u03bb ha, absurd h (decidable.mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)\n\nlemma pos_of_mul_neg_right {a b : \u03b1} (h : a * b < 0) (ha : a \u2264 0) : 0 < b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nlt_of_not_ge (\u03bb hb, absurd h (decidable.mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)\n\nlemma neg_iff_pos_of_mul_neg (hab : a * b < 0) : a < 0 \u2194 0 < b :=\n\u27e8pos_of_mul_neg_right hab \u2218 le_of_lt, neg_of_mul_neg_right hab \u2218 le_of_lt\u27e9\n\nlemma pos_iff_neg_of_mul_neg (hab : a * b < 0) : 0 < a \u2194 b < 0 :=\n\u27e8neg_of_mul_neg_left hab \u2218 le_of_lt, pos_of_mul_neg_left hab \u2218 le_of_lt\u27e9\n\n/-- The sum of two squares is zero iff both elements are zero. -/\nlemma mul_self_add_mul_self_eq_zero {x y : \u03b1} : x * x + y * y = 0 \u2194 x = 0 \u2227 y = 0 :=\nby rw [add_eq_zero_iff', mul_self_eq_zero, mul_self_eq_zero]; apply mul_self_nonneg\n\nlemma eq_zero_of_mul_self_add_mul_self_eq_zero (h : a * a + b * b = 0) : a = 0 :=\n(mul_self_add_mul_self_eq_zero.mp h).left\n\nlemma abs_eq_iff_mul_self_eq : |a| = |b| \u2194 a * a = b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm,\nend\n\nlemma abs_lt_iff_mul_self_lt : |a| < |b| \u2194 a * a < b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)\nend\n\nlemma abs_le_iff_mul_self_le : |a| \u2264 |b| \u2194 a * a \u2264 b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)\nend\n\nlemma abs_le_one_iff_mul_self_le_one : |a| \u2264 1 \u2194 a * a \u2264 1 :=\nby simpa only [abs_one, one_mul] using @abs_le_iff_mul_self_le \u03b1 _ a 1\n\n/-- Pullback a `linear_ordered_ring` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef function.injective.linear_ordered_ring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  linear_ordered_ring \u03b2 :=\n{ .. linear_order.lift f hf,\n  .. pullback_nonzero f zero one,\n  .. hf.ordered_ring f zero one add mul neg sub }\n\nend linear_ordered_ring\n\n/-- A `linear_ordered_comm_ring \u03b1` is a commutative ring `\u03b1` with a linear order\nsuch that addition is monotone and multiplication by a positive number is strictly monotone. -/\n@[protect_proj]\nclass linear_ordered_comm_ring (\u03b1 : Type u) extends linear_ordered_ring \u03b1, comm_monoid \u03b1\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_comm_ring.to_ordered_comm_ring [d : linear_ordered_comm_ring \u03b1] :\n  ordered_comm_ring \u03b1 :=\n{ ..d }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_comm_ring.to_linear_ordered_semiring [d : linear_ordered_comm_ring \u03b1] :\n   linear_ordered_semiring \u03b1 :=\n{ .. d, ..linear_ordered_ring.to_linear_ordered_semiring }\n\nsection linear_ordered_comm_ring\n\nvariables [linear_ordered_comm_ring \u03b1] {a b c d : \u03b1}\n\nlemma max_mul_mul_le_max_mul_max (b c : \u03b1) (ha : 0 \u2264 a) (hd: 0 \u2264 d) :\n  max (a * b) (d * c) \u2264 max a c * max d b :=\nby haveI := @linear_order.decidable_le \u03b1 _; exact\nhave ba : b * a \u2264 max d b * max c a, from\n  decidable.mul_le_mul (le_max_right d b) (le_max_right c a) ha (le_trans hd (le_max_left d b)),\nhave cd : c * d \u2264 max a c * max b d, from\n  decidable.mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c)),\nmax_le\n  (by simpa [mul_comm, max_comm] using ba)\n  (by simpa [mul_comm, max_comm] using cd)\n\nlemma abs_sub_sq (a b : \u03b1) : |a - b| * |a - b| = a * a + b * b - (1 + 1) * a * b :=\nbegin\n  rw abs_mul_abs_self,\n  simp only [mul_add, add_comm, add_left_comm, mul_comm, sub_eq_add_neg,\n    mul_one, mul_neg_eq_neg_mul_symm, neg_add_rev, neg_neg],\nend\n\nend linear_ordered_comm_ring\nsection\nvariables [ring \u03b1] [linear_order \u03b1] {a b : \u03b1}\n\n@[simp] lemma abs_dvd (a b : \u03b1) : |a| \u2223 b \u2194 a \u2223 b :=\nby { cases abs_choice a with h h; simp only [h, neg_dvd] }\n\nlemma abs_dvd_self (a : \u03b1) : |a| \u2223 a :=\n(abs_dvd a a).mpr (dvd_refl a)\n\n@[simp] lemma dvd_abs (a b : \u03b1) : a \u2223 |b| \u2194 a \u2223 b :=\nby { cases abs_choice b with h h; simp only [h, dvd_neg] }\n\nlemma self_dvd_abs (a : \u03b1) : a \u2223 |a| :=\n(dvd_abs a a).mpr (dvd_refl a)\n\nlemma abs_dvd_abs (a b : \u03b1) : |a| \u2223 |b| \u2194 a \u2223 b :=\n(abs_dvd _ _).trans (dvd_abs _ _)\n\nlemma even_abs {a : \u03b1} : even (|a|) \u2194 even a :=\ndvd_abs _ _\n\nlemma odd_abs {a : \u03b1} : odd (abs a) \u2194 odd a :=\nby { cases abs_choice a with h h; simp only [h, odd_neg] }\n\nend\n\nsection linear_ordered_comm_ring\n\nvariables [linear_ordered_comm_ring \u03b1]\n\n/-- Pullback a `linear_ordered_comm_ring` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef function.injective.linear_ordered_comm_ring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  linear_ordered_comm_ring \u03b2 :=\n{ .. linear_order.lift f hf,\n  .. pullback_nonzero f zero one,\n  .. hf.ordered_comm_ring f zero one add mul neg sub }\n\nend linear_ordered_comm_ring\n\nnamespace ring\n\n/-- A positive cone in a ring consists of a positive cone in underlying `add_comm_group`,\nwhich contains `1` and such that the positive elements are closed under multiplication. -/\n@[nolint has_inhabited_instance]\nstructure positive_cone (\u03b1 : Type*) [ring \u03b1] extends add_comm_group.positive_cone \u03b1 :=\n(one_nonneg : nonneg 1)\n(mul_pos : \u2200 (a b), pos a \u2192 pos b \u2192 pos (a * b))\n\n/-- Forget that a positive cone in a ring respects the multiplicative structure. -/\nadd_decl_doc positive_cone.to_positive_cone\n\n/-- A positive cone in a ring induces a linear order if `1` is a positive element. -/\n@[nolint has_inhabited_instance]\nstructure total_positive_cone (\u03b1 : Type*) [ring \u03b1]\n  extends positive_cone \u03b1, add_comm_group.total_positive_cone \u03b1 :=\n(one_pos : pos 1)\n\n/-- Forget that a `total_positive_cone` in a ring is total. -/\nadd_decl_doc total_positive_cone.to_positive_cone\n\n/-- Forget that a `total_positive_cone` in a ring respects the multiplicative structure. -/\nadd_decl_doc total_positive_cone.to_total_positive_cone\n\nend ring\n\nnamespace ordered_ring\n\nopen ring\n\n/-- Construct an `ordered_ring` by\ndesignating a positive cone in an existing `ring`. -/\ndef mk_of_positive_cone {\u03b1 : Type*} [ring \u03b1] (C : positive_cone \u03b1) :\n  ordered_ring \u03b1 :=\n{ zero_le_one := by { change C.nonneg (1 - 0), convert C.one_nonneg, simp, },\n  mul_pos := \u03bb x y xp yp, begin\n    change C.pos (x*y - 0),\n    convert C.mul_pos x y (by { convert xp, simp, }) (by { convert yp, simp, }),\n    simp,\n  end,\n  ..\u2039ring \u03b1\u203a,\n  ..ordered_add_comm_group.mk_of_positive_cone C.to_positive_cone }\n\nend ordered_ring\n\nnamespace linear_ordered_ring\n\nopen ring\n\n/-- Construct a `linear_ordered_ring` by\ndesignating a positive cone in an existing `ring`. -/\ndef mk_of_positive_cone {\u03b1 : Type*} [ring \u03b1] (C : total_positive_cone \u03b1) :\n  linear_ordered_ring \u03b1 :=\n{ exists_pair_ne := \u27e80, 1, begin\n    intro h,\n    have one_pos := C.one_pos,\n    rw [\u2190h, C.pos_iff] at one_pos,\n    simpa using one_pos,\n  end\u27e9,\n  ..ordered_ring.mk_of_positive_cone C.to_positive_cone,\n  ..linear_ordered_add_comm_group.mk_of_positive_cone C.to_total_positive_cone, }\n\nend linear_ordered_ring\n\n/-- A canonically ordered commutative semiring is an ordered, commutative semiring\nin which `a \u2264 b` iff there exists `c` with `b = a + c`. This is satisfied by the\nnatural numbers, for example, but not the integers or other ordered groups. -/\n@[protect_proj]\nclass canonically_ordered_comm_semiring (\u03b1 : Type*) extends\n  canonically_ordered_add_monoid \u03b1, comm_semiring \u03b1 :=\n(eq_zero_or_eq_zero_of_mul_eq_zero : \u2200 a b : \u03b1, a * b = 0 \u2192 a = 0 \u2228 b = 0)\n\nnamespace canonically_ordered_comm_semiring\nvariables [canonically_ordered_comm_semiring \u03b1] {a b : \u03b1}\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_no_zero_divisors : no_zero_divisors \u03b1 :=\n\u27e8canonically_ordered_comm_semiring.eq_zero_or_eq_zero_of_mul_eq_zero\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_covariant_mul_le : covariant_class \u03b1 \u03b1 (*) (\u2264) :=\nbegin\n  refine \u27e8\u03bb a b c h, _\u27e9,\n  rcases le_iff_exists_add.1 h with \u27e8c, rfl\u27e9,\n  rw mul_add,\n  apply self_le_add_right\nend\n\n/-- A version of `zero_lt_one : 0 < 1` for a `canonically_ordered_comm_semiring`. -/\nlemma zero_lt_one [nontrivial \u03b1] : (0:\u03b1) < 1 := (zero_le 1).lt_of_ne zero_ne_one\n\n@[simp] lemma mul_pos : 0 < a * b \u2194 (0 < a) \u2227 (0 < b) :=\nby simp only [pos_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib]\n\n\nend canonically_ordered_comm_semiring\n\nsection sub\n\nvariables [canonically_ordered_comm_semiring \u03b1] {a b c : \u03b1}\nvariables [has_sub \u03b1] [has_ordered_sub \u03b1]\n\nvariables [is_total \u03b1 (\u2264)]\n\nnamespace add_le_cancellable\nprotected lemma mul_tsub (h : add_le_cancellable (a * c)) :\n  a * (b - c) = a * b - a * c :=\nbegin\n  cases total_of (\u2264) b c with hbc hcb,\n  { rw [tsub_eq_zero_iff_le.2 hbc, mul_zero, tsub_eq_zero_iff_le.2 (mul_le_mul_left' hbc a)] },\n  { apply h.eq_tsub_of_add_eq, rw [\u2190 mul_add, tsub_add_cancel_of_le hcb] }\nend\n\nprotected lemma tsub_mul (h : add_le_cancellable (b * c)) : (a - b) * c = a * c - b * c :=\nby { simp only [mul_comm _ c] at *, exact h.mul_tsub }\n\nend add_le_cancellable\n\nvariables [contravariant_class \u03b1 \u03b1 (+) (\u2264)]\n\nlemma mul_tsub (a b c : \u03b1) : a * (b - c) = a * b - a * c :=\ncontravariant.add_le_cancellable.mul_tsub\n\nlemma tsub_mul (a b c : \u03b1) : (a - b) * c = a * c - b * c :=\ncontravariant.add_le_cancellable.tsub_mul\n\nend sub\n\n/-! ### Structures involving `*` and `0` on `with_top` and `with_bot`\n\nThe main results of this section are `with_top.canonically_ordered_comm_semiring` and\n`with_bot.comm_monoid_with_zero`.\n-/\n\nnamespace with_top\n\ninstance [nonempty \u03b1] : nontrivial (with_top \u03b1) :=\noption.nontrivial\n\nvariable [decidable_eq \u03b1]\n\nsection has_mul\n\nvariables [has_zero \u03b1] [has_mul \u03b1]\n\ninstance : mul_zero_class (with_top \u03b1) :=\n{ zero := 0,\n  mul := \u03bbm n, if m = 0 \u2228 n = 0 then 0 else m.bind (\u03bba, n.bind $ \u03bbb, \u2191(a * b)),\n  zero_mul := assume a, if_pos $ or.inl rfl,\n  mul_zero := assume a, if_pos $ or.inr rfl }\n\nlemma mul_def {a b : with_top \u03b1} :\n  a * b = if a = 0 \u2228 b = 0 then 0 else a.bind (\u03bba, b.bind $ \u03bbb, \u2191(a * b)) := rfl\n\n@[simp] lemma mul_top {a : with_top \u03b1} (h : a \u2260 0) : a * \u22a4 = \u22a4 :=\nby cases a; simp [mul_def, h]; refl\n\n@[simp] lemma top_mul {a : with_top \u03b1} (h : a \u2260 0) : \u22a4 * a = \u22a4 :=\nby cases a; simp [mul_def, h]; refl\n\n@[simp] lemma top_mul_top : (\u22a4 * \u22a4 : with_top \u03b1) = \u22a4 :=\ntop_mul top_ne_zero\n\nend has_mul\n\nsection mul_zero_class\n\nvariables [mul_zero_class \u03b1]\n\n@[norm_cast] lemma coe_mul {a b : \u03b1} : (\u2191(a * b) : with_top \u03b1) = a * b :=\ndecidable.by_cases (assume : a = 0, by simp [this]) $ assume ha,\ndecidable.by_cases (assume : b = 0, by simp [this]) $ assume hb,\nby { simp [*, mul_def], refl }\n\nlemma mul_coe {b : \u03b1} (hb : b \u2260 0) : \u2200{a : with_top \u03b1}, a * b = a.bind (\u03bba:\u03b1, \u2191(a * b))\n| none     := show (if (\u22a4:with_top \u03b1) = 0 \u2228 (b:with_top \u03b1) = 0 then 0 else \u22a4 : with_top \u03b1) = \u22a4,\n    by simp [hb]\n| (some a) := show \u2191a * \u2191b = \u2191(a * b), from coe_mul.symm\n\n@[simp] lemma mul_eq_top_iff {a b : with_top \u03b1} : a * b = \u22a4 \u2194 (a \u2260 0 \u2227 b = \u22a4) \u2228 (a = \u22a4 \u2227 b \u2260 0) :=\nbegin\n  cases a; cases b; simp only [none_eq_top, some_eq_coe],\n  { simp [\u2190 coe_mul] },\n  { suffices : \u22a4 * (b : with_top \u03b1) = \u22a4 \u2194 b \u2260 0, by simpa,\n    by_cases hb : b = 0; simp [hb] },\n  { suffices : (a : with_top \u03b1) * \u22a4 = \u22a4 \u2194 a \u2260 0, by simpa,\n    by_cases ha : a = 0; simp [ha] },\n  { simp [\u2190 coe_mul] }\nend\n\nlemma mul_lt_top [partial_order \u03b1] {a b : with_top \u03b1} (ha : a \u2260 \u22a4) (hb : b \u2260 \u22a4) : a * b < \u22a4 :=\nbegin\n  lift a to \u03b1 using ha,\n  lift b to \u03b1 using hb,\n  simp only [\u2190 coe_mul, coe_lt_top]\nend\n\nend mul_zero_class\n\n/-- `nontrivial \u03b1` is needed here as otherwise we have `1 * \u22a4 = \u22a4` but also `= 0 * \u22a4 = 0`. -/\ninstance [mul_zero_one_class \u03b1] [nontrivial \u03b1] : mul_zero_one_class (with_top \u03b1) :=\n{ mul := (*),\n  one := 1,\n  zero := 0,\n  one_mul := \u03bb a, match a with\n  | none     := show ((1:\u03b1) : with_top \u03b1) * \u22a4 = \u22a4, by simp [-with_top.coe_one]\n  | (some a) := show ((1:\u03b1) : with_top \u03b1) * a = a, by simp [coe_mul.symm, -with_top.coe_one]\n  end,\n  mul_one := \u03bb a, match a with\n  | none     := show \u22a4 * ((1:\u03b1) : with_top \u03b1) = \u22a4, by simp [-with_top.coe_one]\n  | (some a) := show \u2191a * ((1:\u03b1) : with_top \u03b1) = a, by simp [coe_mul.symm, -with_top.coe_one]\n  end,\n  .. with_top.mul_zero_class }\n\ninstance [mul_zero_class \u03b1] [no_zero_divisors \u03b1] : no_zero_divisors (with_top \u03b1) :=\n\u27e8\u03bb a b, by cases a; cases b; dsimp [mul_def]; split_ifs;\n  simp [*, none_eq_top, some_eq_coe, mul_eq_zero] at *\u27e9\n\ninstance [semigroup_with_zero \u03b1] [no_zero_divisors \u03b1] : semigroup_with_zero (with_top \u03b1) :=\n{ mul := (*),\n  zero := 0,\n  mul_assoc := \u03bb a b c, begin\n    cases a,\n    { by_cases hb : b = 0; by_cases hc : c = 0;\n        simp [*, none_eq_top] },\n    cases b,\n    { by_cases ha : a = 0; by_cases hc : c = 0;\n        simp [*, none_eq_top, some_eq_coe] },\n    cases c,\n    { by_cases ha : a = 0; by_cases hb : b = 0;\n        simp [*, none_eq_top, some_eq_coe] },\n    simp [some_eq_coe, coe_mul.symm, mul_assoc]\n  end,\n  .. with_top.mul_zero_class }\n\ninstance [monoid_with_zero \u03b1] [no_zero_divisors \u03b1] [nontrivial \u03b1] : monoid_with_zero (with_top \u03b1) :=\n{ .. with_top.mul_zero_one_class, .. with_top.semigroup_with_zero }\n\ninstance [comm_monoid_with_zero \u03b1] [no_zero_divisors \u03b1] [nontrivial \u03b1] :\n  comm_monoid_with_zero (with_top \u03b1) :=\n{ mul := (*),\n  zero := 0,\n  mul_comm := \u03bb a b, begin\n    by_cases ha : a = 0, { simp [ha] },\n    by_cases hb : b = 0, { simp [hb] },\n    simp [ha, hb, mul_def, option.bind_comm a b, mul_comm]\n  end,\n  .. with_top.monoid_with_zero }\n\nvariables [canonically_ordered_comm_semiring \u03b1]\n\nprivate lemma distrib' (a b c : with_top \u03b1) : (a + b) * c = a * c + b * c :=\nbegin\n  cases c,\n  { show (a + b) * \u22a4 = a * \u22a4 + b * \u22a4,\n    by_cases ha : a = 0; simp [ha] },\n  { show (a + b) * c = a * c + b * c,\n    by_cases hc : c = 0, { simp [hc] },\n    simp [mul_coe hc], cases a; cases b,\n    repeat { refl <|> exact congr_arg some (add_mul _ _ _) } }\nend\n\n/-- This instance requires `canonically_ordered_comm_semiring` as it is the smallest class\nthat derives from both `non_assoc_non_unital_semiring` and `canonically_ordered_add_monoid`, both\nof which are required for distributivity. -/\ninstance [nontrivial \u03b1] : comm_semiring (with_top \u03b1) :=\n{ right_distrib   := distrib',\n  left_distrib    := assume a b c, by rw [mul_comm, distrib', mul_comm b, mul_comm c]; refl,\n  .. with_top.add_comm_monoid, .. with_top.comm_monoid_with_zero,}\n\ninstance [nontrivial \u03b1] : canonically_ordered_comm_semiring (with_top \u03b1) :=\n{ .. with_top.comm_semiring,\n  .. with_top.canonically_ordered_add_monoid,\n  .. with_top.no_zero_divisors, }\n\nend with_top\n\nnamespace with_bot\n\ninstance [nonempty \u03b1] : nontrivial (with_bot \u03b1) :=\noption.nontrivial\n\nvariable [decidable_eq \u03b1]\n\nsection has_mul\n\nvariables [has_zero \u03b1] [has_mul \u03b1]\n\ninstance : mul_zero_class (with_bot \u03b1) :=\nwith_top.mul_zero_class\n\nlemma mul_def {a b : with_bot \u03b1} :\n  a * b = if a = 0 \u2228 b = 0 then 0 else a.bind (\u03bba, b.bind $ \u03bbb, \u2191(a * b)) := rfl\n\n@[simp] lemma mul_bot {a : with_bot \u03b1} (h : a \u2260 0) : a * \u22a5 = \u22a5 :=\nwith_top.mul_top h\n\n@[simp] lemma bot_mul {a : with_bot \u03b1} (h : a \u2260 0) : \u22a5 * a = \u22a5 :=\nwith_top.top_mul h\n\n@[simp] lemma bot_mul_bot : (\u22a5 * \u22a5 : with_bot \u03b1) = \u22a5 :=\nwith_top.top_mul_top\n\nend has_mul\n\nsection mul_zero_class\n\nvariables [mul_zero_class \u03b1]\n\n@[norm_cast] lemma coe_mul {a b : \u03b1} : (\u2191(a * b) : with_bot \u03b1) = a * b :=\ndecidable.by_cases (assume : a = 0, by simp [this]) $ assume ha,\ndecidable.by_cases (assume : b = 0, by simp [this]) $ assume hb,\nby { simp [*, mul_def], refl }\n\nlemma mul_coe {b : \u03b1} (hb : b \u2260 0) {a : with_bot \u03b1} : a * b = a.bind (\u03bba:\u03b1, \u2191(a * b)) :=\nwith_top.mul_coe hb\n\n@[simp] lemma mul_eq_bot_iff {a b : with_bot \u03b1} : a * b = \u22a5 \u2194 (a \u2260 0 \u2227 b = \u22a5) \u2228 (a = \u22a5 \u2227 b \u2260 0) :=\nwith_top.mul_eq_top_iff\n\nlemma bot_lt_mul [partial_order \u03b1] {a b : with_bot \u03b1} (ha : \u22a5 < a) (hb : \u22a5 < b) : \u22a5 < a * b :=\nbegin\n  lift a to \u03b1 using ne_bot_of_gt ha,\n  lift b to \u03b1 using ne_bot_of_gt hb,\n  simp only [\u2190 coe_mul, bot_lt_coe],\nend\n\nend mul_zero_class\n\n/-- `nontrivial \u03b1` is needed here as otherwise we have `1 * \u22a5 = \u22a5` but also `= 0 * \u22a5 = 0`. -/\ninstance [mul_zero_one_class \u03b1] [nontrivial \u03b1] : mul_zero_one_class (with_bot \u03b1) :=\nwith_top.mul_zero_one_class\n\ninstance [mul_zero_class \u03b1] [no_zero_divisors \u03b1] : no_zero_divisors (with_bot \u03b1) :=\nwith_top.no_zero_divisors\n\ninstance [semigroup_with_zero \u03b1] [no_zero_divisors \u03b1] : semigroup_with_zero (with_bot \u03b1) :=\nwith_top.semigroup_with_zero\n\ninstance [monoid_with_zero \u03b1] [no_zero_divisors \u03b1] [nontrivial \u03b1] : monoid_with_zero (with_bot \u03b1) :=\nwith_top.monoid_with_zero\n\ninstance [comm_monoid_with_zero \u03b1] [no_zero_divisors \u03b1] [nontrivial \u03b1] :\n  comm_monoid_with_zero (with_bot \u03b1) :=\nwith_top.comm_monoid_with_zero\n\ninstance [canonically_ordered_comm_semiring \u03b1] [nontrivial \u03b1] : comm_semiring (with_bot \u03b1) :=\nwith_top.comm_semiring\n\nend with_bot\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/order/ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7265505040046598}}
{"text": "import Mathlib.Data.Real.Basic\n\n/-\nWe have seen structures already. For example, \n-/ \n\nnamespace Notes \n\nstructure PartialOrder {\u03b1 : Type} (R : \u03b1 \u2192 \u03b1 \u2192 Prop) where \n  refl : \u2200 {a b}, R a b \u2192 R b a \u2192 a = b\n  antisym : \u2200 {a b}, R a b \u2192 R b a \u2192 a = b\n  trans : \u2200 {a b c}, R a b \u2192 R b c \u2192 R a c\n\n/-\nStructures, also often called records, are useful for \ncombining different types into a single type. Another example\n-/\n\nstructure Point3D (\u03b1 : Type) where \n  xCoord : \u03b1 \n  yCoord : \u03b1 \n  zCoord : \u03b1 \n\nstructure HPoint3D (\u03b1 \u03b2 \u03b3 : Type) : Type where \n  xCoord : \u03b1 \n  yCoord : \u03b2 \n  zCoord : \u03b3 \n\n#check HPoint3D Bool \u211d String \n\n/-\nYou tell Lean you are making a new type which is a structure by \nusing the `structure` keyword. \n\nNext comes the identifier `PartialOrder` and `Point3D` in the examples. \n\nAfter the identifier comes the _parameters_. These are things on which \nthe structure depends. So `PartialOrder` needs a relation `R` which \nin turn needs the type `\u03b1` of values it is relating. `Point3D` \ndepends on a type `\u03b1` which is the type of the coordinates. \n\nAfter the parameters, you can the `where` keyword (or a `:=`) to \ntell Lean that the _fields_ of the structure are coming. \n\nIn `PartialOrder`, we have three fields and their types. Same \nwith `Point3d`. \n-/\n\n/- Suppose we want to tell Lean about the point (1,1,1) in `\u211d\u00b3`. \nOne way looks as follows\n-/\n\ndef myPoint : Point3D \u211d := \n  { xCoord := 1 \n    yCoord := 1 \n    zCoord := 1 }\n\n/- Printing `myPoint` shows the alternate syntax for declaring \ninstances of structures -/\n#print myPoint\n\n/- One more way to get an instance is to use the built-in \nconstructor. The default name `mk`. -/\n\n#check Point3D.mk \n\nexample : Point3D \u211d := Point3D.mk 1 1 1 \nexample : HPoint3D \u2115 \u211a \u211d := HPoint3D.mk 1 1 1\n\n/- We can change the name of the default constructor if \nwe wish. This is why we can write `And.intro` and `Exists.intro` \nin place of `And.mk` and `Exists.mk` -/\n\n#check And\n\nstructure Point3D' (\u03b1 : Type) where \nbuild:: \n  xCoord : \u03b1 \n  yCoord : \u03b1 \n  zCoord : \u03b1 \n\nexample : Point3D \u211d := .mk 1 1 1\n\n-- example : Point3D' \u211d := .mk 1 1 1\n\n/- One more way to build a structure is using the _anonymous \nconstructor_ notation -/\n\nexample : Point3D \u211d := \u27e81,1,1\u27e9 \n\n-- This doesn't work because `\u2115` is a not a structure\n-- example : \u2115 := \u27e80\u27e9\n\n/- Here the brackets are typed \\< and \\>. Lean knows from the \ncontext that you need to put a term of type `Point3D \u211d` so \nunderstands what structure you are building from just the `1`'s. \n-/\n\n/- We can extend structures -/ \n\nstructure Point4D (\u03b1 : Type) extends Point3D \u03b1 where \n  time : \u03b1 \n\nexample {\u03b1 : Type} (p : Point3D \u03b1) (t : \u03b1) : Point4D \u03b1 := \u27e8p,t\u27e9\n\nexample {\u03b1 : Type} (p : Point4D \u03b1) : \u03b1 := p.toPoint3D.xCoord\n\n/- There is syntax for updating fields -/\n\nexample {\u03b1 : Type} (p : Point3D \u03b1) (x : \u03b1) : Point3D \u03b1 := {p with xCoord := x}\n\ndef myNewPt : Point3D \u211d := {myPoint with xCoord := 0}\n\n#print myNewPt\n\n/- Often is it useful to provide default values -/\n\nstructure UserData where \n  name : String  := \"Andres Galarraga\" \n  uid : \u2115  := 0 \n  email : String \n\ndef andres : UserData := {email := \"ag@email.sc.edu\"}\n\n#print andres \n\n/- Lean allows us the flexibility for fields in a structure \nto depend on other fields -/ \n\nstructure LawlessGroup where \n  Carrier : Type\n  unit : Carrier \n  mul : Carrier \u2192 Carrier \u2192 Carrier \n  inv : Carrier \u2192 Carrier\n\n#print LawlessGroup.unit \n\n-- `\u211d` is actually a group under addition \nexample : LawlessGroup where \n  Carrier := \u211d \n  unit := 0 \n  mul := fun x y => x + y \n  inv := fun x => -x \n\n-- This is not a real group which is why called it lawless. \nexample : LawlessGroup := \u27e8\u2115, 37, fun _ _ => 0, (\u00b7+1) \u27e9\n\nnamespace Better \n\nstructure LawlessGroup (G : Type) where \n  unit : G\n  mul : G \u2192 G \u2192 G \n  inv : G \u2192 G\n\nstructure Group (G : Type) extends LawlessGroup G where \n  mul_unit : \u2200 g, mul g unit = g \n  unit_mul : \u2200 g, mul unit g = g \n  mul_inv : \u2200 g, mul g (inv g) = unit \n  inv_mul : \u2200 g, mul (inv g) g = unit \n\nend Better\n\n/- Under the hood, a `structure` is essentially a inductive type \nwith a single constructor which is why the following works. -/\n\nnamespace Inductive \n\ninductive Inhabited (\u03b1 : Type) where \n | default (a : \u03b1) : Inhabited \u03b1  \n\nexample : Inhabited \u211d := \u27e8-1\u27e9 \n\n/- So `LawlessGroup` similar to -/\n\ninductive LawlessGroup \n  | mk : \u2200 (Carrier :Type), Carrier \u2192 (Carrier \u2192 Carrier \u2192 Carrier) \u2192 (Carrier \u2192 Carrier) \u2192 LawlessGroup\n\ndef LawlessGroup.Carrier : LawlessGroup \u2192 Type \n  | .mk Carrier _ _ _ => Carrier\n\ndef LawlessGroup.unit : (self : LawlessGroup) \u2192 self.Carrier  \n  | .mk _ unit _ _ => unit \n\ndef LawlessGroup.mul : (self : LawlessGroup) \u2192 self.Carrier \u2192 self.Carrier \u2192 self.Carrier \n  | .mk _ _ mul _ => mul \n\ndef LawlessGroup.inv : (self : LawlessGroup) \u2192 self.Carrier \u2192 self.Carrier\n  | .mk _ _ _ inv => inv \n\ndef ok : LawlessGroup := .mk \u211d 0 (\u00b7+\u00b7) (-\u00b7) \n\n#check ok.Carrier \n\n#check ok.unit \n\n#check ok.mul \n\n#check ok.inv\n\nend Inductive \n\n/- In general, structures can be more _bundled_ where parameters \nare pushed into the fields or more _unbundled_ where fields are \npushed into the parameters -/ \n\nstructure LawlessGroup' (Carrier : Type) where \n  unit : Carrier \n  mul : Carrier \u2192 Carrier \u2192 Carrier \n  inv : Carrier \u2192 Carrier\n", "meta": {"author": "UofSC-Spring-2023-SCHC-411-H01", "repo": "notes", "sha": "ef57142df34fbe92f6204d8eb636ec5061729bd0", "save_path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes", "path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes/notes-ef57142df34fbe92f6204d8eb636ec5061729bd0/Notes4/Struct.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.8740772450055544, "lm_q1q2_score": 0.7264832327893227}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.order.euclidean_absolute_value\nimport data.polynomial.field_division\n\n/-!\n# Absolute value on polynomials over a finite field.\n\nLet `Fq` be a finite field of cardinality `q`, then the map sending a polynomial `p`\nto `q ^ degree p` (where `q ^ degree 0 = 0`) is an absolute value.\n\n## Main definitions\n\n * `polynomial.card_pow_degree` is an absolute value on `\ud835\udd3d_q[t]`, the ring of\n   polynomials over a finite field of cardinality `q`, mapping a polynomial `p`\n   to `q ^ degree p` (where `q ^ degree 0 = 0`)\n\n## Main results\n * `polynomial.card_pow_degree_is_euclidean`: `card_pow_degree` respects the\n   Euclidean domain structure on the ring of polynomials\n\n-/\n\nnamespace polynomial\n\nvariables {Fq : Type*} [field Fq] [fintype Fq]\n\nopen absolute_value\n\nopen_locale classical polynomial\n\n/-- `card_pow_degree` is the absolute value on `\ud835\udd3d_q[t]` sending `f` to `q ^ degree f`.\n\n`card_pow_degree 0` is defined to be `0`. -/\nnoncomputable def card_pow_degree :\n  absolute_value Fq[X] \u2124 :=\nhave card_pos : 0 < fintype.card Fq := fintype.card_pos_iff.mpr infer_instance,\nhave pow_pos : \u2200 n, 0 < (fintype.card Fq : \u2124) ^ n := \u03bb n, pow_pos (int.coe_nat_pos.mpr card_pos) n,\n{ to_fun := \u03bb p, if p = 0 then 0 else fintype.card Fq ^ p.nat_degree,\n  nonneg' := \u03bb p, by { dsimp, split_ifs, { refl }, exact pow_nonneg (int.coe_zero_le _) _ },\n  eq_zero' := \u03bb p, ite_eq_left_iff.trans $ \u27e8\u03bb h, by { contrapose! h, exact \u27e8h, (pow_pos _).ne'\u27e9 },\n    absurd\u27e9,\n  add_le' := \u03bb p q, begin\n    by_cases hp : p = 0, { simp [hp] },\n    by_cases hq : q = 0, { simp [hq] },\n    by_cases hpq : p + q = 0,\n    { simp only [hpq, hp, hq, eq_self_iff_true, if_true, if_false],\n      exact add_nonneg (pow_pos _).le (pow_pos _).le },\n    simp only [hpq, hp, hq, if_false],\n    refine le_trans (pow_le_pow (by linarith) (polynomial.nat_degree_add_le _ _)) _,\n    refine le_trans (le_max_iff.mpr _)\n      (max_le_add_of_nonneg (pow_nonneg (by linarith) _) (pow_nonneg (by linarith) _)),\n    exact (max_choice p.nat_degree q.nat_degree).imp (\u03bb h, by rw [h]) (\u03bb h, by rw [h])\n  end,\n  map_mul' := \u03bb p q, begin\n    by_cases hp : p = 0, { simp [hp] },\n    by_cases hq : q = 0, { simp [hq] },\n    have hpq : p * q \u2260 0 := mul_ne_zero hp hq,\n    simp only [hpq, hp, hq, eq_self_iff_true, if_true, if_false,\n      polynomial.nat_degree_mul hp hq, pow_add],\n  end }\n\nlemma card_pow_degree_apply (p : Fq[X]) :\n  card_pow_degree p = if p = 0 then 0 else fintype.card Fq ^ nat_degree p := rfl\n\n@[simp] lemma card_pow_degree_zero : card_pow_degree (0 : Fq[X]) = 0 := if_pos rfl\n\n@[simp] lemma card_pow_degree_nonzero (p : Fq[X]) (hp : p \u2260 0) :\n  card_pow_degree p = fintype.card Fq ^ p.nat_degree :=\nif_neg hp\n\nlemma card_pow_degree_is_euclidean :\n  is_euclidean (card_pow_degree : absolute_value Fq[X] \u2124) :=\nhave card_pos : 0 < fintype.card Fq := fintype.card_pos_iff.mpr infer_instance,\nhave pow_pos : \u2200 n, 0 < (fintype.card Fq : \u2124) ^ n := \u03bb n, pow_pos (int.coe_nat_pos.mpr card_pos) n,\n{ map_lt_map_iff' := \u03bb p q, begin\n    simp only [euclidean_domain.r, card_pow_degree_apply],\n    split_ifs with hp hq hq,\n    { simp only [hp, hq, lt_self_iff_false] },\n    { simp only [hp, hq, degree_zero, ne.def, bot_lt_iff_ne_bot,\n        degree_eq_bot, pow_pos, not_false_iff] },\n    { simp only [hp, hq, degree_zero, not_lt_bot, (pow_pos _).not_lt] },\n    { rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq, with_bot.coe_lt_coe, pow_lt_pow_iff],\n      exact_mod_cast @fintype.one_lt_card Fq _ _ },\n  end }\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/degree/card_pow_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7264776493827989}}
{"text": "\n/-\n\nlemma divides_p_times (r : \u2115) (n : \u2115) : p^r \u2223 n \u2194 p^(r+1) \u2223 (p * n) :=\ncalc p^r \u2223 n \u2194 (p * p^r) \u2223 (p * n)  : (nat.mul_dvd_mul_iff_left (gt_zero hp)).symm\n     ...     = (p^r * p \u2223 p * n)     : by rw mul_comm\n\nlemma exactly_divides_p_times (r : \u2115) (n : \u2115) : p^r \u2223\u2223 n \u2194 p^(r+1) \u2223\u2223 (p * n) :=\nhave eq : (p * n) / p^(r+1) = n / p^r, from\ncalc (p * n) / p^(r+1) = (p * n) / (p^r * p)  : rfl\n     ...               = (p * n) / (p * p^r)  : by rw mul_comm (p^r) p\n     ...               = (p * n) / p / p^r    : by rw nat.div_div_eq_div_mul\n     ...               = n / p^r    : by rw (nat.mul_div_cancel_left n (gt_zero hp)),\n--      : congr_arg (\u03bb m, m / p^r) (nat.mul_div_cancel_left n gt_zero),\nand_congr (divides_p_times hp r n) (by rw eq)\n\nlemma exactly_divides' {r : \u2115} {n : \u2115} : p^r \u2223\u2223 n \u2192 (\u2200 i, p^i \u2223 n \u2194 i \u2264 r) :=\nbegin\n  intros prn i, apply iff.intro,\n  { intro pin,\n    apply (le_or_gt _ _).resolve_right, intro i_gt_r,\n    have :=\n    calc p^r * p = p^(r+1)  : rfl\n         ...     \u2223 p^i      : pow_dvd_pow p i_gt_r\n         ...     \u2223 n        : pin,\n    exact absurd (dvd_div_of_mul_dvd (pos_pow_of_pos r (gt_zero hp)) this) prn.right,\n  },\n  { intro i_le_r,\n    exact dvd.trans (pow_dvd_pow p i_le_r) (and.left prn) }\nend\n\n-/\n\n\n/-\n\nlemma exactly_divides_mul (r s a b : \u2115) : p^r \u2223\u2223 a \u2192 p^s \u2223\u2223 b \u2192 p^(r+s) \u2223\u2223 a*b :=\nbegin\n  intros pra psb, split,\n  { rw nat.pow_add, exact mul_dvd_mul pra.left psb.left },\n  let a' := a / p^r,\n  have ha : p^r * a' = a := nat.mul_div_cancel' pra.left,\n  let b' := b / p^s,\n  have hb : p^s * b' = b := nat.mul_div_cancel' psb.left,\n  have : (a * b) / (p^(r+s)) = (a / p^r) * (b / p^s) :=\n  calc (a * b) / (p^(r+s)) = ((p^r * a') * (p^s * b')) / (p^r * p^s)\n    : by rw [ha, hb, pow_add]\n       ...                 = ((p^r * p^s) * (a' * b')) / (p^r * p^s)\n    : by ac_refl\n       ...                 = a' * b'\n    : by rw nat.mul_div_cancel_left _\n            (mul_pos (pos_pow_of_pos r (gt_zero hp)) (pos_pow_of_pos s (gt_zero hp)))\n       ...                 = (a / p^r) * (b / p^s)  : rfl,\n  rw this,\n  exact prime.not_dvd_mul hp pra.right psb.right\nend\n\n-/\n\n\n", "meta": {"author": "rwbarton", "repo": "lean-elementary-number-theory", "sha": "fabef0737fd2486e3f24f9e04652db4c182d5425", "save_path": "github-repos/lean/rwbarton-lean-elementary-number-theory", "path": "github-repos/lean/rwbarton-lean-elementary-number-theory/lean-elementary-number-theory-fabef0737fd2486e3f24f9e04652db4c182d5425/src/data/nat/exactly_divides_old.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7264776385948943}}
{"text": "import order.complete_lattice order.order_iso order.fixed_points\n\nopen lattice\n\nuniverse u\n\nvariables {\u03b1 : Type u} [complete_lattice \u03b1]\nvariables (f : \u03b1 \u2192 \u03b1) (M : monotone f)\n\ndef fixed_points : set \u03b1 := { x | f x = x }\n\nnamespace fixed_points\n\ndef previous (x : \u03b1) : \u03b1 :=\ngfp (\u03bb z, x \u2293 f z)\n\nvariable {f}\n\ntheorem previous.le {x : \u03b1} : previous f x \u2264 x :=\ngfp_le $ \u03bb z hz, le_trans hz inf_le_left\n\ntheorem previous.le_apply {x : \u03b1} : previous f x \u2264 f (previous f x) :=\ngfp_le $ \u03bb z hz, le_trans (le_trans hz inf_le_right) $ M $ le_gfp hz\n\ntheorem previous.fixed {x : \u03b1} (H : f x \u2264 x) : f (previous f x) = previous f x :=\nle_antisymm\n  (le_gfp $ le_inf (le_trans (M previous.le) H) (M $ previous.le_apply M))\n  (previous.le_apply M)\n\nvariable f\n\ndef next (x : \u03b1) : \u03b1 :=\nlfp (\u03bb z, x \u2294 f z)\n\nvariable {f}\n\ntheorem next.le {x : \u03b1} : x \u2264 next f x :=\nle_lfp $ \u03bb z hz, le_trans le_sup_left hz\n\ntheorem next.apply_le {x : \u03b1} : f (next f x) \u2264 next f x :=\nle_lfp $ \u03bb z hz, le_trans (le_trans (M $ show next f x \u2264 z, from lfp_le hz) le_sup_right) hz\n\ntheorem next.fixed {x : \u03b1} (H : x \u2264 f x) : f (next f x) = next f x :=\nle_antisymm\n  (next.apply_le M)\n  (lfp_le $ sup_le (le_trans H (M next.le)) (M $ next.apply_le M))\n\nvariable f\n\ntheorem sup_le_f_of_fixed_points (x y : fixed_points f) : x.1 \u2294 y.1 \u2264 f (x.1 \u2294 y.1) :=\nsup_le\n  (x.2 \u25b8 (M $ show x.1 \u2264 f x.1 \u2294 y.1, from x.2.symm \u25b8 le_sup_left))\n  (y.2 \u25b8 (M $ show y.1 \u2264 x.1 \u2294 f y.1, from y.2.symm \u25b8 le_sup_right))\n\ntheorem f_le_inf_of_fixed_points (x y : fixed_points f) : f (x.1 \u2293 y.1) \u2264 x.1 \u2293 y.1 :=\nle_inf\n  (x.2 \u25b8 (M $ show f (x.1) \u2293 y.1 \u2264 x.1, from x.2.symm \u25b8 inf_le_left))\n  (y.2 \u25b8 (M $ show x.1 \u2293 f (y.1) \u2264 y.1, from y.2.symm \u25b8 inf_le_right))\n\ntheorem Sup_le_f_of_fixed_points (A : set \u03b1) (HA : A \u2286 fixed_points f) : Sup A \u2264 f (Sup A) :=\nSup_le $ \u03bb x hxA, (HA hxA) \u25b8 (M $ le_Sup hxA)\n\ntheorem f_le_Inf_of_fixed_points (A : set \u03b1) (HA : A \u2286 fixed_points f) : f (Inf A) \u2264 Inf A :=\nle_Inf $ \u03bb x hxA, (HA hxA) \u25b8 (M $ Inf_le hxA)\n\ninstance : complete_lattice (fixed_points f) :=\n{ le           := subrel (\u2264) _,\n  le_refl      := \u03bb x, le_refl x,\n  le_trans     := \u03bb x y z, le_trans,\n  le_antisymm  := \u03bb x y hx hy, subtype.eq $ le_antisymm hx hy,\n\n  sup          := \u03bb x y, \u27e8next f (x.1 \u2294 y.1), next.fixed M (sup_le_f_of_fixed_points f M x y)\u27e9,\n  le_sup_left  := \u03bb x y, show x.1 \u2264 _, from le_trans le_sup_left next.le,\n  le_sup_right := \u03bb x y, show y.1 \u2264 _, from le_trans le_sup_right next.le,\n  sup_le       := \u03bb x y z hxz hyz, lfp_le $ sup_le (sup_le hxz hyz) (z.2.symm \u25b8 le_refl z.1),\n\n  inf          := \u03bb x y, \u27e8previous f (x.1 \u2293 y.1), previous.fixed M (f_le_inf_of_fixed_points f M x y)\u27e9,\n  inf_le_left  := \u03bb x y, show _ \u2264 x.1, from le_trans previous.le inf_le_left,\n  inf_le_right := \u03bb x y, show _ \u2264 y.1, from le_trans previous.le inf_le_right,\n  le_inf       := \u03bb x y z hxy hxz, le_gfp $ le_inf (le_inf hxy hxz) (x.2.symm \u25b8 le_refl x),\n\n  top          := \u27e8previous f \u22a4, previous.fixed M le_top\u27e9,\n  le_top       := \u03bb \u27e8x, H\u27e9, le_gfp $ le_inf le_top (H.symm \u25b8 le_refl x),\n\n  bot          := \u27e8next f \u22a5, next.fixed M bot_le\u27e9,\n  bot_le       := \u03bb \u27e8x, H\u27e9, lfp_le $ sup_le bot_le (H.symm \u25b8 le_refl x),\n\n  Sup          := \u03bb A, \u27e8next f (Sup $ subtype.val '' A), next.fixed M (Sup_le_f_of_fixed_points f M (subtype.val '' A) (\u03bb z \u27e8x, hx\u27e9, hx.2 \u25b8 x.2))\u27e9,\n  le_Sup       := \u03bb A x hxA, show x.1 \u2264 _, from le_trans\n                    (le_Sup $ show x.1 \u2208 subtype.val '' A, from \u27e8x, hxA, rfl\u27e9)\n                    next.le,\n  Sup_le       := \u03bb A x Hx, lfp_le $ sup_le (Sup_le $ \u03bb z \u27e8y, hyA, hyz\u27e9, hyz \u25b8 Hx y hyA) (x.2.symm \u25b8 le_refl x),\n\n  Inf          := \u03bb A, \u27e8previous f (Inf $ subtype.val '' A), previous.fixed M (f_le_Inf_of_fixed_points f M (subtype.val '' A) (\u03bb z \u27e8x, hx\u27e9, hx.2 \u25b8 x.2))\u27e9,\n  le_Inf       := \u03bb A x Hx, le_gfp $ le_inf (le_Inf $ \u03bb z \u27e8y, hyA, hyz\u27e9, hyz \u25b8 Hx y hyA) (x.2.symm \u25b8 le_refl x.1),\n  Inf_le       := \u03bb A x hxA, show _ \u2264 x.1, from le_trans\n                    previous.le\n                    (Inf_le $ show x.1 \u2208 subtype.val '' A, from \u27e8x, hxA, rfl\u27e9) }\n\nend fixed_points\n", "meta": {"author": "kckennylau", "repo": "Lean", "sha": "907d0a4d2bd8f23785abd6142ad53d308c54fdcb", "save_path": "github-repos/lean/kckennylau-Lean", "path": "github-repos/lean/kckennylau-Lean/Lean-907d0a4d2bd8f23785abd6142ad53d308c54fdcb/Knaster-Tarski.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7263928407512225}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.mv_polynomial.rename\n\n/-!\n# `comap` operation on `mv_polynomial`\n\nThis file defines the `comap` function on `mv_polynomial`.\n\n`mv_polynomial.comap` is a low-tech example of a map of \"algebraic varieties,\" modulo the fact that\n`mathlib` does not yet define varieties.\n\n## Notation\n\nAs in other polynomial files, we typically use the notation:\n\n+ `\u03c3 : Type*` (indexing the variables)\n\n+ `R : Type*` `[comm_semiring R]` (the coefficients)\n\n-/\n\nnamespace mv_polynomial\nvariables {\u03c3 : Type*} {\u03c4 : Type*} {\u03c5 : Type*} {R : Type*} [comm_semiring R]\n\n/--\nGiven an algebra hom `f : mv_polynomial \u03c3 R \u2192\u2090[R] mv_polynomial \u03c4 R`\nand a variable evaluation `v : \u03c4 \u2192 R`,\n`comap f v` produces a variable evaluation `\u03c3 \u2192 R`.\n-/\nnoncomputable def comap (f : mv_polynomial \u03c3 R \u2192\u2090[R] mv_polynomial \u03c4 R) :\n  (\u03c4 \u2192 R) \u2192 (\u03c3 \u2192 R) :=\n\u03bb x i, aeval x (f (X i))\n\n@[simp] lemma comap_apply (f : mv_polynomial \u03c3 R \u2192\u2090[R] mv_polynomial \u03c4 R) (x : \u03c4 \u2192 R) (i : \u03c3) :\n  comap f x i = aeval x (f (X i)) := rfl\n\n@[simp] lemma comap_id_apply (x : \u03c3 \u2192 R) : comap (alg_hom.id R (mv_polynomial \u03c3 R)) x = x :=\nby { funext i, simp only [comap, alg_hom.id_apply, id.def, aeval_X], }\n\nvariables (\u03c3 R)\n\nlemma comap_id : comap (alg_hom.id R (mv_polynomial \u03c3 R)) = id :=\nby { funext x, exact comap_id_apply x }\n\nvariables {\u03c3 R}\n\nlemma comap_comp_apply (f : mv_polynomial \u03c3 R \u2192\u2090[R] mv_polynomial \u03c4 R)\n  (g : mv_polynomial \u03c4 R \u2192\u2090[R] mv_polynomial \u03c5 R) (x : \u03c5 \u2192 R) :\n  comap (g.comp f) x = comap f (comap g x) :=\nbegin\n  funext i,\n  transitivity (aeval x (aeval (\u03bb i, g (X i)) (f (X i)))),\n  { apply eval\u2082_hom_congr rfl rfl,\n    rw alg_hom.comp_apply,\n    suffices : g = aeval (\u03bb i, g (X i)), { rw \u2190 this, },\n    exact aeval_unique g },\n  { simp only [comap, aeval_eq_eval\u2082_hom, map_eval\u2082_hom, alg_hom.comp_apply],\n    refine eval\u2082_hom_congr _ rfl rfl,\n    ext r, apply aeval_C },\nend\n\nlemma comap_comp (f : mv_polynomial \u03c3 R \u2192\u2090[R] mv_polynomial \u03c4 R)\n  (g : mv_polynomial \u03c4 R \u2192\u2090[R] mv_polynomial \u03c5 R) :\n  comap (g.comp f) = comap f \u2218 comap g :=\nby { funext x, exact comap_comp_apply _ _ _ }\n\nlemma comap_eq_id_of_eq_id (f : mv_polynomial \u03c3 R \u2192\u2090[R] mv_polynomial \u03c3 R)\n  (hf : \u2200 \u03c6, f \u03c6 = \u03c6) (x : \u03c3 \u2192 R) :\n  comap f x = x :=\nby { convert comap_id_apply x, ext1 \u03c6, rw [hf, alg_hom.id_apply] }\n\nlemma comap_rename (f : \u03c3 \u2192 \u03c4) (x : \u03c4 \u2192 R) : comap (rename f) x = x \u2218 f :=\nby { ext i, simp only [rename_X, comap_apply, aeval_X] }\n\n/--\nIf two polynomial types over the same coefficient ring `R` are equivalent,\nthere is a bijection between the types of functions from their variable types to `R`.\n-/\nnoncomputable def comap_equiv (f : mv_polynomial \u03c3 R \u2243\u2090[R] mv_polynomial \u03c4 R) :\n  (\u03c4 \u2192 R) \u2243 (\u03c3 \u2192 R) :=\n{ to_fun    := comap f,\n  inv_fun   := comap f.symm,\n  left_inv  := by { intro x, rw [\u2190 comap_comp_apply], apply comap_eq_id_of_eq_id, intro,\n    simp only [alg_hom.id_apply, alg_equiv.comp_symm], },\n  right_inv := by { intro x, rw [\u2190 comap_comp_apply], apply comap_eq_id_of_eq_id, intro,\n  simp only [alg_hom.id_apply, alg_equiv.symm_comp] }, }\n\n@[simp] lemma comap_equiv_coe (f : mv_polynomial \u03c3 R \u2243\u2090[R] mv_polynomial \u03c4 R) :\n  (comap_equiv f : (\u03c4 \u2192 R) \u2192 (\u03c3 \u2192 R)) = comap f := rfl\n\n@[simp] lemma comap_equiv_symm_coe (f : mv_polynomial \u03c3 R \u2243\u2090[R] mv_polynomial \u03c4 R) :\n  ((comap_equiv f).symm : (\u03c3 \u2192 R) \u2192 (\u03c4 \u2192 R)) = comap f.symm := rfl\n\nend mv_polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/mv_polynomial/comap.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7263928370375848}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module algebra.category.Module.products\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Pi\nimport Mathbin.Algebra.Category.Module.Basic\n\n/-!\n# The concrete products in the category of modules are products in the categorical sense.\n-/\n\n\nopen CategoryTheory\n\nopen CategoryTheory.Limits\n\nuniverse u v w\n\nnamespace ModuleCat\n\nvariable {R : Type u} [Ring R]\n\nvariable {\u03b9 : Type v} (Z : \u03b9 \u2192 ModuleCat.{max v w} R)\n\n/-- The product cone induced by the concrete product. -/\ndef productCone : Fan Z :=\n  Fan.mk (ModuleCat.of R (\u2200 i : \u03b9, Z i)) fun i => (LinearMap.proj i : (\u2200 i : \u03b9, Z i) \u2192\u2097[R] Z i)\n#align Module.product_cone ModuleCat.productCone\n\n/-- The concrete product cone is limiting. -/\ndef productConeIsLimit : IsLimit (productCone Z)\n    where\n  lift s := (LinearMap.pi fun j => s.\u03c0.app \u27e8j\u27e9 : s.pt \u2192\u2097[R] \u2200 i : \u03b9, Z i)\n  fac s j := by\n    cases j\n    tidy\n  uniq s m w := by\n    ext (x i)\n    exact LinearMap.congr_fun (w \u27e8i\u27e9) x\n#align Module.product_cone_is_limit ModuleCat.productConeIsLimit\n\n-- While we could use this to construct a `has_products (Module R)` instance,\n-- we already have `has_limits (Module R)` in `algebra.category.Module.limits`.\nvariable [HasProduct Z]\n\n/-- The categorical product of a family of objects in `Module`\nagrees with the usual module-theoretical product.\n-/\nnoncomputable def piIsoPi : \u220f Z \u2245 ModuleCat.of R (\u2200 i, Z i) :=\n  limit.isoLimitCone \u27e8_, productConeIsLimit Z\u27e9\n#align Module.pi_iso_pi ModuleCat.piIsoPi\n\n-- We now show this isomorphism commutes with the inclusion of the kernel into the source.\n@[simp, elementwise]\ntheorem piIsoPi_inv_kernel_\u03b9 (i : \u03b9) :\n    (piIsoPi Z).inv \u226b Pi.\u03c0 Z i = (LinearMap.proj i : (\u2200 i : \u03b9, Z i) \u2192\u2097[R] Z i) :=\n  limit.isoLimitCone_inv_\u03c0 _ _\n#align Module.pi_iso_pi_inv_kernel_\u03b9 ModuleCat.piIsoPi_inv_kernel_\u03b9\n\n@[simp, elementwise]\ntheorem piIsoPi_hom_ker_subtype (i : \u03b9) :\n    (piIsoPi Z).hom \u226b (LinearMap.proj i : (\u2200 i : \u03b9, Z i) \u2192\u2097[R] Z i) = Pi.\u03c0 Z i :=\n  IsLimit.conePointUniqueUpToIso_inv_comp _ (limit.isLimit _) (Discrete.mk i)\n#align Module.pi_iso_pi_hom_ker_subtype ModuleCat.piIsoPi_hom_ker_subtype\n\nend ModuleCat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Category/Module/Products.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7263928325456442}}
{"text": "  import utilities\n\nopen list\nopen multiset\nopen set\nopen nat\n\nset_option trace.simplify.rewrite true\n\nvariables {\u03b1 : Type*} {\u03ba : Type*}\nvariable r: \u03ba \u2192 \u03ba \u2192 Prop\nvariables (x: \u03b1) (k: \u03ba ) (xs: list \u03b1)\nvariables (f: \u03b1 \u2192 \u03ba) (P: \u03b1 \u2192 Prop)\n\n/- \n# Insertion Sort w.r.t. Keys and Stability\n-/\n\ndef insort_key [decidable_rel r] [is_linear_order \u03ba r] : list \u03b1 \u2192 list \u03b1     \n| []       := [x]\n| (y :: ys) := if r (f x) (f y) then x :: y :: ys else y :: insort_key ys\n\ndef isort_key [decidable_rel r] [is_linear_order \u03ba r]: list \u03b1 \u2192 list \u03b1\n| []       := []\n| (x :: xs) := insort_key r x f (isort_key xs)\n\n/-\n## Functional Correctness\n -/\n\nlemma mset_insort_key [decidable_rel r] [is_linear_order \u03ba r]:\n  ((insort_key r x f xs): multiset \u03b1) = {x} + \u2191 xs :=\nbegin\n  induction' xs,\n  { refl},\n  simp [insort_key],\n  split_ifs,\n  { refl},\n  simp [\u2190 multiset.cons_coe, ih],\nend\n\nlemma mset_isort_key [decidable_rel r] [is_linear_order \u03ba r]: (\u2191 (isort_key r f xs): multiset \u03b1) = \u2191 xs :=\nbegin\n  induction' xs,\n  { refl},\n  simp [mset_insort_key, isort_key, ih],\n  refl,\nend\n\nlemma set_insort_key [decidable_rel r] [is_linear_order \u03ba r]: (insort_key r x f xs).to_set = {x} \u222a xs.to_set:=\nbegin\n  simp [\u2190 set_mset_mset, mset_insort_key, multiset.to_set],\n  refl\nend\n\nlemma set_isort_key [decidable_rel r] [is_linear_order \u03ba r]: (isort_key r f xs).to_set = xs.to_set :=\nbegin\n  simp [\u2190 set_mset_mset, mset_isort_key],\nend\n\nlemma sorted_insort_key [decidable_rel r] [is_linear_order \u03ba r]: \n  sorted' r ((insort_key r x f xs).map f) = sorted' r (xs.map f) :=\nbegin\n  induction' xs fixing *,\n  { simp [insort_key, sorted'],\n    intros,\n    exact false.elim H},\n  simp [insort_key],\n  split_ifs,\n  { simp [sorted', list.to_set],\n    intros h1 h2,\n    apply and.intro h,\n    intros k h3,\n    exact trans h (h1 k h3) },\n  simp [sorted', ih],\n  intros h1,\n  simp [\u2190 set_mset_mset, \u2190 multiset.coe_map, mset_insort_key, multiset.to_set],\n  intros h2,\n  exact or.resolve_left (total_of r (f x) (f hd)) h\nend\n\nlemma sorted_isort_key [decidable_rel r] [is_linear_order \u03ba r] : \n  sorted' r (map f (isort_key r f xs)) :=\nbegin\n  induction' xs,\n  repeat { simp [isort_key, sorted_insort_key, *] },\nend\n\n/-\n## Stability\n-/\n\nlemma insort_is_Cons [decidable_rel r] [is_linear_order \u03ba r]: \n  (\u2200 a \u2208 xs.to_set, r (f x) (f a)) \u2192 insort_key r x f xs = (x:: xs):=\nbegin\n  cases xs,\n  repeat { simp [insort_key, list.to_set] },\n  intros h h1 h2,\n  cc,\nend \n\nlemma filter_insort_key_neg [decidable_rel r] [is_linear_order \u03ba r] [decidable_pred P]:\n  \u00ac P x \u2192 (insort_key r x f xs).filter P = xs.filter P :=\nbegin\n  induction xs,\n  { intro h,\n    simp [insort_key, *] },\n  simp [insort_key],\n  split_ifs,\n  { intro h1,\n    simp * },\n  intro h1,\n  simp [list.filter, xs_ih h1],\nend\n\nlemma filter_insort_key_pos [decidable_rel r] [is_linear_order \u03ba r] [decidable_pred P]:\n  sorted' r (xs.map f) \u2227 P x \u2192 (insort_key r x f xs).filter P = insort_key r x f (xs.filter P) :=\nbegin\n  induction xs,\n  { intro,\n    simp [insort_key, *] },\n  simp [sorted', list.filter, insort_key],\n  split_ifs,\n  { intros,\n    simp [insort_key, *] },\n  { have h5: (\u2200 a \u2208 (list.filter P xs_tl).to_set, r (f x) (f a)) \u2192 insort_key r x f (filter P     xs_tl) = (x:: (filter P xs_tl)), from insort_is_Cons r x (filter P xs_tl) f,\n    simp [ \u2190 member_list_set] at h5 |-,\n    intros h2 h3 h4,\n    have h6: \u2200 (a : \u03b1), a \u2208 xs_tl \u2192 P a \u2192 r (f x) (f a), from begin\n      intros a h7 h8,\n      exact trans_of r h (h2 a h7),\n    end,\n    simp [*, h5 h6] },\n  { intros,\n    simp [list.filter, *, insort_key] },\n  intros,\n  simp [list.filter, *],\nend\n\n/-\nLemma 2.9 from __Functional Algorithms Verified!__\n-/\nlemma sort_key_stable [decidable_rel r] [is_linear_order \u03ba r] [decidable_pred (\u03bb y, f y = k)]: \n  (isort_key r f xs).filter (\u03bb y, f y = k) = xs.filter (\u03bb y, f y = k):=\nbegin\n  induction xs,\n  repeat { simp [isort_key, list.filter] },\n  split_ifs,\n  { simp [isort_key, *, filter_insort_key_pos, sorted_isort_key, \u2190 member_list_set],\n    have h1: (\u2200 a \u2208 (list.filter (\u03bb (y : \u03b1), f y = k) xs_tl).to_set, r (f _) (f a)) \u2192 insort_key r _ f _ = (_:: _) , from insort_is_Cons r xs_hd (filter (\u03bb (y : \u03b1), f y = k) xs_tl) f,\n    have h3: \u2200 (a : \u03b1), a \u2208 (list.filter (\u03bb (y : \u03b1), f y = k) xs_tl).to_set \u2192 r (f xs_hd) (f a), from begin\n      intros,\n      simp [\u2190 member_list_set, *] at *,\n      exact refl_of r k,\n    end,\n    exact h1 h3 },\n  simp [isort_key, filter_insort_key_neg, *],\nend\n\n", "meta": {"author": "MaschavanderMarel", "repo": "bachelor_project", "sha": "7ace1dea38fc87bfe73367c3a84273886a7f92e3", "save_path": "github-repos/lean/MaschavanderMarel-bachelor_project", "path": "github-repos/lean/MaschavanderMarel-bachelor_project/bachelor_project-7ace1dea38fc87bfe73367c3a84273886a7f92e3/src/insertion_sort_key.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7263928263914602}}
{"text": "import data.set.basic\nopen function set\n\ntheorem question5 (X Y Z : Type) (f : X \u2192 Z) (g : Y \u2192 Z) (hf : injective f) (hg : injective g) :\n  (\u2203 h : X \u2192 Y, bijective h \u2227 f = g \u2218 h) \u2194 (set.range f = set.range g) :=\nbegin\n  split,\n  { rintro \u27e8h, h1, h2\u27e9,\n    ext z,\n    split,\n      rintro \u27e8x, hx\u27e9,\n      use (h x),\n      convert hx,\n      rw h2,\n    rintro \u27e8y, hy\u27e9,\n    cases h1 with hinj hsurj,\n    cases hsurj y with x hx,\n    use x,\n    rw \u2190hy,\n    rw \u2190hx,\n    rw h2\n  },\n  { intro hfg,\n    have hx : \u2200 x : X, \u2203 y : Y, g y = f x,\n      intro x,\n      have hx : f x \u2208 range f, use x,\n      rw hfg at hx,\n      exact hx,\n    choose h hh using hx,\n    use h,\n    split,\n      split,\n        intros x1 x2 h12,\n        apply hf,\n        rw \u2190hh,\n        rw h12,\n        exact hh x2,\n      intro y,\n      have hy : g y \u2208 range g, use y,\n      rw \u2190hfg at hy,\n      cases hy with x hx,\n      use x,\n      apply hg,\n      convert hx,\n      exact hh x,\n    ext x,\n    exact (hh x).symm\n  }\nend\n\n#check eq.trans", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2019/solutions/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7263052363658975}}
{"text": "-- ==================== Syntax ====================\n\ndef loc := string\n\n\ninductive aexp : Type\n| Lookup : loc -> aexp\n| Int : int -> aexp\n| Plus : aexp -> aexp -> aexp\n-- | Minus\n-- | Times\n\n\ninductive bexp : Type\n| Bool : bool -> bexp\n| Equal : aexp -> aexp -> bexp\n-- | Less\n\n\ninductive cmd : Type\n| Assign : loc -> aexp -> cmd\n-- | IfThenElse \n-- | Seq \n-- | Skip \n-- | WhileDo \n\n-- ================== Example 'fact.imp' in LEAN notation. ==================\n\ndef fact : cmd :=\n  cmd.Seq\n    (cmd.Seq\n      (cmd.Assign \"n\" (aexp.Int 10))\n      (sorry) )\n    (cmd.WhileDo\n      (sorry)\n      (cmd.Seq\n        (cmd.Assign \"fact\" \n          (aexp.Times (aexp.Lookup \"fact\") (aexp.Lookup \"n\")) )\n        (cmd.Assign \"n\"\n          (sorry) ) ) )\n\n-- ==================== Environment ====================\n\ninductive env : Type\n| Nil : env\n| Cons : loc -> int -> env -> env\n\n\ninductive lookup : loc -> env -> int -> Prop\n| Find {loc i E} : \n    lookup loc (env.Cons loc i E) i \n| Search {loc loc' i' E' i} : \n    loc\u2260loc' -> lookup loc E' i -> \n    lookup loc (env.Cons loc' i' E') i\n\n-- ==================== Operational Semantics ====================\n\ninductive aeval : env -> aexp -> int -> Prop\n| Lookup {E loc i} :\n    lookup loc E i -> \n    aeval E (aexp.Lookup loc) i\n-- | Int :\n-- | Plus :\n-- | Minus :\n-- | Times :\n\n\n-- Lean works best with '<' and '\u2264' so we use them instead of '>' and '\u2265'.\ninductive beval : env -> bexp -> bool -> Prop\n| Bool {E b} :\n    beval E (bexp.Bool b) b\n| Equal_t {E a1 a2 i1 i2}:\n    aeval E a1 i1 -> aeval E a2 i2 -> i1 = i2 -- ->\n    -- ???\n-- | Equal_f :\n-- | Less_t :\n-- | Less_f :\n\n\ninductive ceval : env -> cmd -> env -> Prop\n-- | Assign :\n| IfThenElse_t {E b c1 c2 M'} :\n    beval E b true -> ceval E c1 M' ->\n    ceval E (cmd.IfThenElse b c1 c2) M'\n-- | IfThenElse_f :\n-- | Seq :\n| Skip {E} :\n    ceval E cmd.Skip E\n-- | WhileDo_t :\n-- | WhileDo_f :\n\n-- ==================== Safety ====================\n\n-- Contains all the names of already assigned locations.\ninductive locs : Type\n| Nil : locs\n| Cons : loc -> locs -> locs\n\n\ninductive loc_safe : loc -> locs -> Prop\n| Find {loc L} : \n    loc_safe loc (locs.Cons loc L) \n| Search {loc loc' L} : \n    loc'\u2260loc -> loc_safe loc L -> \n    loc_safe loc (locs.Cons loc' L)\n\n\ninductive asafe : locs -> aexp -> Prop\n-- | Lookup \n-- | Int\n| Plus {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    asafe L (aexp.Plus a1 a2)\n| Minus {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    asafe L (aexp.Minus a1 a2)\n| Times {L a1 a2} :\n    asafe L a1 -> asafe L a2 ->\n    asafe L (aexp.Times a1 a2)\n\n\ninductive bsafe : locs -> bexp -> Prop\n-- | Bool\n-- | Equal\n-- | Less\n\ninductive csafe : locs -> cmd -> locs -> Prop\n-- | Assign {L loc a} :\n\n-- | IfThenElse SKIP THIS CONSTRUCT\n-- Note: This part requires a definition of locs intersection.\n\n-- | Seq\n-- | Skip\n-- | WhileDo\n\n-- ==================== Auxiliary safety for lookup ====================\n\n-- Ensures that the given environment maps all the required locations.\ninductive env_maps : env -> locs -> Prop\n| Nil {E} :\n    env_maps E locs.Nil\n| Cons {loc E L} :\n    env_maps E L -> (\u2203i, lookup loc E i) ->\n    env_maps E (locs.Cons loc L)\n\n\n-- Increasing the environment does not break its safety.\ntheorem env_maps_weaken {E L loc i}:\n  env_maps E L -> env_maps (env.Cons loc i E) L\n:=\nbegin\n  intro es, induction es with E' loc' E' L' maps finds ih,\n  case env_maps.Nil\n    { sorry },\n  case env_maps.Cons\n    { apply env_maps.Cons, assumption,\n      -- we compare the the strings to know which lookup result is correct\n      cases string.has_decidable_eq loc' loc with neq eq,\n      { cases finds with i', existsi i',\n        -- lookup must search deeper \n        sorry },\n      existsi i, \n      -- loc' and loc are equal, 'subst eq' will rewrite them to the same name.\n      sorry,\nend\n\n\n-- If the location is safe in the same specification as the environment\n-- then we are guaranteed to look up a value\ntheorem safe_lookup {L E loc}:\n  loc_safe loc L -> env_maps E L -> \u2203 (i:int), lookup loc E i\n:=\nbegin\n  -- if we have an impossible hypothesis 'h' (such as a safety check in\n  -- an empty locs list) we can complete the proof with 'cases h'\n  sorry\nend\n\n-- ==================== Safety theorems ====================\n\ntheorem asafety {L E a}:\n  asafe L a -> env_maps E L -> \u2203 (i:int), aeval E a i\n:=\nbegin\n  intros s es,\n  induction s,\n  case asafe.Lookup\n    { cases safe_lookup s_a es with i, \n    -- cases safe_lookup ... applies the theorem and eliminates the \u2203 \n      existsi i, apply aeval.Lookup, assumption, },\n  case asafe.Int\n    { sorry },\n  case asafe.Plus\n    { cases s_ih_a es with i1,\n      cases s_ih_a_1 es with i2,\n      sorry },\n  case asafe.Minus\n    { sorry },\n  case asafe.Times\n    { sorry },\nend\n\n\ntheorem bsafety {L E b}:\n  bsafe L b -> env_maps E L -> \u2203 (v:bool), beval E b v\n:=\nbegin\n  intros s es,\n  induction s,\n  case bsafe.Bool\n    { existsi s_b, apply beval.Bool, },\n  case bsafe.Equal\n    { cases asafety s_a es with i1,\n      cases asafety s_a_1 es with i2,\n      cases int.decidable_eq i1 i2 with neq eq,\n      -- we cannot just do a case analysis on logical formulas because\n      -- we are not using classical logic. Luckily integer equality is\n      -- decidable, so we can specify to do a case analysis on that\n      -- i1 \u2260 i2\n      { sorry },\n      -- i1 = i2\n      { sorry }, },\n  case bsafe.Less\n    { sorry,\n      cases int.decidable_lt i1 i2 with neq eq,\n      -- i1 \u2270 i2\n      { sorry },\n      -- i1 < i2\n      { sorry }, },\nend\n\n\ntheorem csafety {L L' E c }:\n  csafe L c L' -> env_maps E L -> \u2203 (E':env), ceval E c E' \u2227 env_maps E' L'\n:=\nbegin\n  -- constructor splits \u2227 into two subgoals\n  intros s, revert E, -- we revert to obtain a stronger induction\n  induction s; intros E es,\n  case csafe.Assign\n    { cases asafety s_a_1 es with i,\n      existsi (env.Cons s_loc i E),\n      constructor, -- constructor splits \u2227 into two subgoals\n      { sorry },\n      sorry },\n  case csafe.Seq\n    { sorry },\n  case csafe.Skip\n    { sorry },\n  case csafe.WhileDo\n    { -- this part can't really be done in big step semantics\n      sorry },\nend", "meta": {"author": "tadejpetric", "repo": "tpj-coq", "sha": "dda9fb2e635f9a1302739e34d8692a4252066b76", "save_path": "github-repos/lean/tadejpetric-tpj-coq", "path": "github-repos/lean/tadejpetric-tpj-coq/tpj-coq-dda9fb2e635f9a1302739e34d8692a4252066b76/06-formalizacija-dokazov/vaje-imp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7263052343855332}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport representation_theory.basic\nimport representation_theory.maschke -- Maschke's theorem\n\n/-\n\n# Representation theory via k[G]-modules\n\nIt might have struck you as odd that we have a definition of `representation`\nbut not a definition of map between representations. One reason for this\nis that there's another way of thinking about representations, which is\nthat they are `k[G]-modules`. Here `k[G]` is the so-called group ring associated\nto `k` and `G`; it's a vector space with basis indexed by `G`, and multiplication\ngiven by multiplication on `G` and extended linearly, so (\u2211 a\u1d62g\u1d62)(\u2211 b\u2c7ch\u2c7c) := \u2211\u1d62\u2c7c(a\u1d62b\u2c7c)(g\u1d62h\u2c7c)\nfor `a\u1d62, b\u2c7c : k` and `g\u1d62, h\u2c7c : G`.\n\nBecause the construction works with monoids (note that there's no mention of inverses\nin the definition of the group ring), it's called `monoid_algebra` in Lean.\n\n-/\n\nvariables (k : Type) [field k] (G : Type) [group G]\n\nexample : Type := monoid_algebra k G\n\nnoncomputable theory -- Lean moans about various things if you don't switch this on\n-- Note that this doesn't matter for mathematicians, this is a computer science thing\n\nexample : ring (monoid_algebra k G) := infer_instance\n\n-- Turns out that there's a bijection between modules for the group ring k[G],\n-- and representations of G on k-vector spaces. The dictionary works like this.\n-- Let \u03c1 be a representation of G on a k-vector space V\n\nvariables (V : Type) [add_comm_group V] [module k V] (\u03c1 : representation k G V) \n\n-- Here's the underlying type of the module.\n\nexample : Type := \u03c1.as_module\n\n-- Note that `\u03c1.as_module` is definitionally equal to `V`, but it knows about `\u03c1` because `\u03c1` is in its name.\n-- As a result, this works:\n\nexample : module (monoid_algebra k G) \u03c1.as_module := infer_instance\n\n-- This wouldn't work with `\u03c1.as_module` replaced by `V`, because type class inference wouldn't\n-- be able to find `\u03c1`\n\n-- The other way: let `M` be a `k[G]`-module\n\nvariables (M : Type) [add_comm_group M] [module (monoid_algebra k G) M]\n\n-- Here's the representation\n\nexample : representation k G (restrict_scalars k (monoid_algebra k G) M) := representation.of_module k G M\n\n-- What's going on here? The issue is that type class inference can't by default find the k-module\n-- structure on `M`, so this `restrict_scalars k (monoid_algebra k G) M` thing means \"`M`, but with\n-- the `k`-action coming from the monoid_algebra k G action\"\n-- It's defeq to `M`:\n\nexample : restrict_scalars k (monoid_algebra k G) M = M := rfl \n\n-- So another way of doing morphisms between representations is as `monoid_algebra k G` morphisms.\n\n-- Let \u03c3 be another representation\nvariables (W : Type) [add_comm_group W] [module k W] (\u03c3 : representation k G W) \n\n-- The type of G-morphisms between `\u03c1` and `\u03c3`\n\nexample : Type := \u03c1.as_module \u2192\u2097[monoid_algebra k G] \u03c3.as_module \n\n-- If you do it this way, then you don't have to make G-morphisms. \n\n-- Let \u03c6 be a G-morphism\n\nvariable (\u03c6 : \u03c1.as_module \u2192\u2097[monoid_algebra k G] \u03c3.as_module)\n\n-- Then you can evaluate it at elements of `V`\n\nexample (v : V) : W := \u03c6 v \n\n-- This works because `V = \u03c1.as_module` definitionally. \n\n-- The k[G]-module language is how Lean expresses Maschke's theorem.\n\n-- Assume `G` is finite, and its order is invertible in `k`\nvariables [fintype G] [invertible (fintype.card G : k)]\n\n-- Assume `V` and `W` are k[G]-modules (with the k[G]-action compatible with the k-action)\n\nvariables \n  [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V]\n  [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W]\n\n-- Then every injective k[G]-linear map from `V` to `W` has a one-sided inverse\n-- (and hence a complement, namely the kernel of the inverse)\n\nexample (\u03c6 : V \u2192\u2097[monoid_algebra k G] W) (h\u03c6 : \u03c6.ker = \u22a5) : \n  \u2203 \u03c8 : W \u2192\u2097[monoid_algebra k G] V, \u03c8.comp \u03c6 = linear_map.id :=\nmonoid_algebra.exists_left_inverse_of_injective \u03c6 h\u03c6  ", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section20representation_theory/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7262757329239558}}
{"text": "import tactic\n\n/-\nThis file is an attempt to learn about classes by redefining\nthe class of groups as \"mygroup\" and proving a few simple results.\n\nThere is an exercise to prove that for any g \u2208 G, the map x \u21a6 g\u207b\u00b9*x*g\nis an isomorphism from G to G. \n-/\n\nclass my_group (G : Type*)\n  extends has_one G, has_mul G, has_inv G :=\n  (gp_assoc : \u2200 {x y z:G} , (x*y)*z = x*(y*z) )\n  (gp_mul_one : \u2200 {x : G} , x*1=x )\n  (gp_one_mul : \u2200 {x : G} , 1*x=x )\n  (gp_mul_inv : \u2200 {x : G} , x*x\u207b\u00b9 =1 )\n  (gp_inv_mul : \u2200 {x : G} , x\u207b\u00b9 *x=1 )\n\nclass morphism {G G' : Type*} (f:G\u2192 G') [my_group G] [my_group G'] :=\n  (property : \u2200 {x y : G}, f(x*y) = (f x) * (f y))\n\nclass isomorphism {G G' : Type*} (f : G \u2192 G') [my_group G] [my_group G']\n  extends morphism f :=\n  (injective : \u2200 {x y : G}, f x=f y \u2192 x=y)\n  (surjective : \u2200 {y : G'}, \u2203 x:G , f x = y)\n\ndef isomorphic (G G' : Type) [ my_group G] [my_group G'] : Prop :=\n  (\u2203 f : G \u2192 G', nonempty( isomorphism f) )\n\n--infix \" \u2245 \":55  := isomorphic\n\nstructure mysubgroup (G:Type*)[my_group G]:=\n  (elts : set G)\n  (one : (1:G) \u2208 elts)\n  (closure : \u2200 {x y:G}, x\u2208 elts \u2192 y\u2208 elts \u2192 x*y \u2208 elts)\n  (inverse : \u2200 {x: G}, x\u2208 elts \u2192 x\u207b\u00b9 \u2208 elts)\n\nstructure normal_mysubgroup (G:Type*) [my_group G]\n  extends mysubgroup G:=\n  (normal : \u2200 {x y:G}, x*y \u2208 elts \u2192 y*x \u2208 elts)\n\n-- def quotient_group_as_type (G:Type*) [my_group G] (H:normal_mysubgroup G) : Type* :=\n--   sorry\n\n\ninstance mysubgroup_to_sort {G:Type*} [my_group G] (H:mysubgroup G):\nhas_coe_to_sort (mysubgroup G) Type*:=\n  {\n    coe := \u03bb H, subtype H.elts\n  }\n\nnamespace my_group\n\nopen my_group\n\n-- lemmas about elements of a my_group G:\nvariables {G:Type} [my_group G]\nvariables {G':Type} [my_group G']\nvariables {x y z :G}\n\n-- restate the axioms as simplification lemmas, and in the my_group namespace\n@[simp] lemma assoc : x*y*z = x*(y*z) := gp_assoc \n@[simp] lemma mul_one : x*1 = x := gp_mul_one\n@[simp] lemma one_mul : 1*x = x := gp_one_mul\n@[simp] lemma mul_inv : x*x\u207b\u00b9 = 1 := gp_mul_inv\n@[simp] lemma inv_mul : x\u207b\u00b9*x = 1 := gp_inv_mul\n\n\nlemma unique_left_id (h: x*y=y): x=1 :=\ncalc\n  x = x*y*y\u207b\u00b9 : by rw [assoc,mul_inv,mul_one] ...\n    = 1       : by rw [h, mul_inv]\n\nlemma unique_left_inv (h: x*y=1) : x = y\u207b\u00b9 :=\ncalc\n  x = x*y*y\u207b\u00b9 : by squeeze_simp ... -- squeeze_simp's  answer doesn't work\n    = y\u207b\u00b9     : by rw [h, one_mul]\n\n@[simp] lemma inv_id : (1:G)\u207b\u00b9 = 1 :=  eq_comm.mp (unique_left_inv one_mul)\n\n-- Lemmas about my_group morphisms f:G \u2192 G' :\nvariables {f:G \u2192 G'} [morphism f]\n\n@[simp] lemma mor_mul : f(x * y) = (f x)*(f y) := morphism.property\n@[simp] lemma mor_id : f 1 = 1 := unique_left_id (calc (f 1)*(f 1) = f 1 : by rw [\u2190mor_mul, one_mul])\n@[simp] lemma mor_inv :f x\u207b\u00b9 = (f x)\u207b\u00b9 :=\nbegin\n  apply unique_left_inv,\n  simp [\u2190 mor_mul,inv_mul],\n  exact mor_id,\nend\n\ndef kernel (f:G \u2192 G') [morphism f] : mysubgroup G :=\n{\n  elts := {x:G | f x = 1},\n  one := mor_id,\n  closure := begin\n    intros x y hx hy,\n    rw [set.mem_set_of_eq] at *,\n    have : f(x*y) = (f x) * (f y) := mor_mul,\n    rw [this,hx,hy,one_mul],\n    --rw @mor_mul _ _ _ _  x y f,\n    --simp only [*, one_mul],\n  end,\n  inverse := begin\n    intros x hx,\n    simp only [set.mem_set_of_eq] at *,\n    have : f(x\u207b\u00b9)= (f x)\u207b\u00b9 := mor_inv,\n    simp only [*, inv_id],\n  end\n}\n\ndef image (f : G \u2192 G') [morphism f] : mysubgroup G' :=\n{\n  elts := {y : G' | \u2203 x:G, f x = y},\n  one := \u27e8 1, mor_id\u27e9,\n  closure := begin\n    intros x y hx hy,\n    --simp at *,\n    cases hx with gx hgx,\n    cases hy with gy hgy,\n    use gx*gy,\n    have : f(gx*gy)=(f gx)*(f gy) := mor_mul, -- why is this not simp?\n    simp only [*],\n  end,\n  inverse := begin\n    intros x hx,\n    cases hx with g hg,\n    use g\u207b\u00b9 ,\n    have : f g\u207b\u00b9 = (f g)\u207b\u00b9 := mor_inv, -- why is this not simp?\n    simp *,\n  end\n}\n\n\ninstance mysubgroup_to_group (H : mysubgroup G) : my_group (H.elts) :=\n{\n  mul := begin\n    intros x y,\n    cases x with x hx,\n    cases y with y hy,\n    use x*y,\n    exact H.closure hx hy,\n  end,\n  inv := begin\n    intro x,\n    cases x with x hx,\n    use x\u207b\u00b9,\n    exact H.inverse hx,\n  end,\n  one := \u27e8 1, H.one\u27e9,\n  gp_assoc := begin\n    intros x y z,\n    cases x, cases y, cases z,\n    simp,\n  end,\n  gp_mul_one := begin\n    intro x,\n    cases x,\n    simp,\n  end,\n  gp_one_mul := begin\n    intro x,\n    cases x,\n    simp,\n  end,\n  gp_mul_inv := begin\n    intro x,\n    cases x,\n    simp,\n  end,\n  gp_inv_mul := begin\n    intro x,\n    cases x,\n    simp,\n  end\n}\n\n\ndef inner_automorphism : G \u2192 G \u2192 G :=\n  \u03bb g x, g\u207b\u00b9 * x * g \n\n-- As an exercise, can you prove that an inner automorphism is an isomorphism?\n\ninstance iso_of_inner {G:Type} [my_group G] (g:G):\n  isomorphism (inner_automorphism g) :=\n{ \n  property :=\n  begin\n    intros x y,\n    unfold inner_automorphism,\n    sorry\n  end,\n  injective :=\n  begin \n    sorry\n  end,\n  surjective :=\n  begin \n    sorry\n  end\n}\n\n\n\n\n\nend my_group\n\n\n\n\n-- Now let's define a group with two elements I,X.\n-- we first define the type C_2 with those two elements\ninductive C_2\n| I : C_2\n| X : C_2\n\n\nopen C_2  -- this allows us to type I or X in place of C_2.I or C_2.X. \n\n\n\n--next define multiplication on the group\ndef mul : C_2 \u2192 C_2 \u2192 C_2 \n| I   a := a\n| a   I := a \n| _   _ := I\n\n\n--we can now make this into a group by supplying proofs that the axioms are true.\n--Since the group has only two elements, the proof of each axiom\n--is simply to check each case.\ninstance group_C_2 : my_group C_2 :=\n{\n  one := I,\n  mul := mul,\n  inv := id,\n  gp_assoc := \u03bb a b c, by {cases a; cases b; cases c; refl},\n  gp_mul_one := \u03bb a, by {cases a; refl} ,\n  gp_one_mul := \u03bb a, by {cases a; refl} ,\n  gp_mul_inv := \u03bb a, by {cases a; refl} ,\n  gp_inv_mul := \u03bb a, by {cases a; refl} \n}\n\n\n-- We can also make C_2 into a mathlib group.\n-- These are defined in a slightly different way.\n-- One can give lean a special algorithm to calculate powers of an element.\n-- for example, we could define the n-th power (for n\u2208 \u2115 ) using this function:\n\ndef npow : \u2115 \u2192 C_2 \u2192 C_2 \n| 0      a := I \n| (n+1)  a := mul a ( npow n a ) \n\n\n\ninstance gpC2 : group C_2 :=\n{\n  mul := mul,\n  mul_assoc := begin\n    intros a b c,\n    cases a; cases b; cases c;\n    refl,\n  end,\n  one := I,\n  one_mul := \u03bb a, by {cases a;refl} ,\n  mul_one := \u03bb a, by {cases a;refl},\n  npow := npow,\n  npow_zero' := begin\n    intro a,\n    refl,\n  end,\n  npow_succ' := begin\n    intros n x, refl,\n  end,\n  inv := id,\n  --div := _,\n  --div_eq_mul_inv := _,\n  --zpow := _,\n  --zpow_zero' := _,\n  --zpow_succ' := _,\n  --zpow_neg' := _,\n  mul_left_inv := begin\n    intro a,\n    cases a;\n    refl,\n  end\n}\n\n\n\n\n\ninstance \u2124_group : my_group \u2124 := { one := 0,\n  mul := \u03bb x y, x+y,\n  inv := \u03bb x, -x,\n  gp_assoc := add_assoc,\n  gp_mul_one := add_zero,\n  gp_one_mul := zero_add,\n  gp_mul_inv := sub_self,\n  gp_inv_mul := neg_add_self}", "meta": {"author": "jt496", "repo": "Lean_Club", "sha": "391289884977a76dff5a0549f74742ca3d533fbb", "save_path": "github-repos/lean/jt496-Lean_Club", "path": "github-repos/lean/jt496-Lean_Club/Lean_Club-391289884977a76dff5a0549f74742ca3d533fbb/src/examples/groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7262464653325926}}
{"text": "/-\nCopyright (c) 2021 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Julian Kuelshammer\n\n! This file was ported from Lean 3 source module group_theory.exponent\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Zmod.Quotient\nimport Mathbin.GroupTheory.NoncommPiCoprod\nimport Mathbin.GroupTheory.OrderOfElement\nimport Mathbin.Algebra.GcdMonoid.Finset\nimport Mathbin.Data.Nat.Factorization.Basic\nimport Mathbin.Tactic.ByContra\n\n/-!\n# Exponent of a group\n\nThis file defines the exponent of a group, or more generally a monoid. For a group `G` it is defined\nto be the minimal `n\u22651` such that `g ^ n = 1` for all `g \u2208 G`. For a finite group `G`,\nit is equal to the lowest common multiple of the order of all elements of the group `G`.\n\n## Main definitions\n\n* `monoid.exponent_exists` is a predicate on a monoid `G` saying that there is some positive `n`\n  such that `g ^ n = 1` for all `g \u2208 G`.\n* `monoid.exponent` defines the exponent of a monoid `G` as the minimal positive `n` such that\n  `g ^ n = 1` for all `g \u2208 G`, by convention it is `0` if no such `n` exists.\n* `add_monoid.exponent_exists` the additive version of `monoid.exponent_exists`.\n* `add_monoid.exponent` the additive version of `monoid.exponent`.\n\n## Main results\n\n* `monoid.lcm_order_eq_exponent`: For a finite left cancel monoid `G`, the exponent is equal to the\n  `finset.lcm` of the order of its elements.\n* `monoid.exponent_eq_supr_order_of(')`: For a commutative cancel monoid, the exponent is\n  equal to `\u2a06 g : G, order_of g` (or zero if it has any order-zero elements).\n\n## TODO\n* Refactor the characteristic of a ring to be the exponent of its underlying additive group.\n-/\n\n\nuniverse u\n\nvariable {G : Type u}\n\nopen Classical\n\nnamespace Monoid\n\nsection Monoid\n\nvariable (G) [Monoid G]\n\n/-- A predicate on a monoid saying that there is a positive integer `n` such that `g ^ n = 1`\n  for all `g`.-/\n@[to_additive\n      \"A predicate on an additive monoid saying that there is a positive integer `n` such\\n  that `n \u2022 g = 0` for all `g`.\"]\ndef ExponentExists :=\n  \u2203 n, 0 < n \u2227 \u2200 g : G, g ^ n = 1\n#align monoid.exponent_exists Monoid.ExponentExists\n#align add_monoid.exponent_exists AddMonoid.ExponentExists\n\n/-- The exponent of a group is the smallest positive integer `n` such that `g ^ n = 1` for all\n  `g \u2208 G` if it exists, otherwise it is zero by convention.-/\n@[to_additive\n      \"The exponent of an additive group is the smallest positive integer `n` such that\\n  `n \u2022 g = 0` for all `g \u2208 G` if it exists, otherwise it is zero by convention.\"]\nnoncomputable def exponent :=\n  if h : ExponentExists G then Nat.find h else 0\n#align monoid.exponent Monoid.exponent\n#align add_monoid.exponent AddMonoid.exponent\n\nvariable {G}\n\n@[to_additive]\ntheorem exponentExists_iff_ne_zero : ExponentExists G \u2194 exponent G \u2260 0 :=\n  by\n  rw [exponent]\n  split_ifs\n  \u00b7 simp [h, @not_lt_zero' \u2115]\n  --if this isn't done this way, `to_additive` freaks\n  \u00b7 tauto\n#align monoid.exponent_exists_iff_ne_zero Monoid.exponentExists_iff_ne_zero\n#align add_monoid.exponent_exists_iff_ne_zero AddMonoid.exponentExists_iff_ne_zero\n\n@[to_additive]\ntheorem exponent_eq_zero_iff : exponent G = 0 \u2194 \u00acExponentExists G := by\n  simp only [exponent_exists_iff_ne_zero, Classical.not_not]\n#align monoid.exponent_eq_zero_iff Monoid.exponent_eq_zero_iff\n#align add_monoid.exponent_eq_zero_iff AddMonoid.exponent_eq_zero_iff\n\n@[to_additive]\ntheorem exponent_eq_zero_of_order_zero {g : G} (hg : orderOf g = 0) : exponent G = 0 :=\n  exponent_eq_zero_iff.mpr fun \u27e8n, hn, hgn\u27e9 => orderOf_eq_zero_iff'.mp hg n hn <| hgn g\n#align monoid.exponent_eq_zero_of_order_zero Monoid.exponent_eq_zero_of_order_zero\n#align add_monoid.exponent_eq_zero_of_order_zero AddMonoid.exponent_eq_zero_of_order_zero\n\n@[to_additive exponent_nsmul_eq_zero]\ntheorem pow_exponent_eq_one (g : G) : g ^ exponent G = 1 :=\n  by\n  by_cases exponent_exists G\n  \u00b7 simp_rw [exponent, dif_pos h]\n    exact (Nat.find_spec h).2 g\n  \u00b7 simp_rw [exponent, dif_neg h, pow_zero]\n#align monoid.pow_exponent_eq_one Monoid.pow_exponent_eq_one\n#align add_monoid.exponent_nsmul_eq_zero AddMonoid.exponent_nsmul_eq_zero\n\n@[to_additive]\ntheorem pow_eq_mod_exponent {n : \u2115} (g : G) : g ^ n = g ^ (n % exponent G) :=\n  calc\n    g ^ n = g ^ (n % exponent G + exponent G * (n / exponent G)) := by rw [Nat.mod_add_div]\n    _ = g ^ (n % exponent G) := by simp [pow_add, pow_mul, pow_exponent_eq_one]\n    \n#align monoid.pow_eq_mod_exponent Monoid.pow_eq_mod_exponent\n#align add_monoid.nsmul_eq_mod_exponent AddMonoid.nsmul_eq_mod_exponent\n\n@[to_additive]\ntheorem exponent_pos_of_exists (n : \u2115) (hpos : 0 < n) (hG : \u2200 g : G, g ^ n = 1) : 0 < exponent G :=\n  by\n  have h : \u2203 n, 0 < n \u2227 \u2200 g : G, g ^ n = 1 := \u27e8n, hpos, hG\u27e9\n  rw [exponent, dif_pos]\n  exact (Nat.find_spec h).1\n#align monoid.exponent_pos_of_exists Monoid.exponent_pos_of_exists\n#align add_monoid.exponent_pos_of_exists AddMonoid.exponent_pos_of_exists\n\n@[to_additive]\ntheorem exponent_min' (n : \u2115) (hpos : 0 < n) (hG : \u2200 g : G, g ^ n = 1) : exponent G \u2264 n :=\n  by\n  rw [exponent, dif_pos]\n  \u00b7 apply Nat.find_min'\n    exact \u27e8hpos, hG\u27e9\n  \u00b7 exact \u27e8n, hpos, hG\u27e9\n#align monoid.exponent_min' Monoid.exponent_min'\n#align add_monoid.exponent_min' AddMonoid.exponent_min'\n\n@[to_additive]\ntheorem exponent_min (m : \u2115) (hpos : 0 < m) (hm : m < exponent G) : \u2203 g : G, g ^ m \u2260 1 :=\n  by\n  by_contra' h\n  have hcon : exponent G \u2264 m := exponent_min' m hpos h\n  linarith\n#align monoid.exponent_min Monoid.exponent_min\n#align add_monoid.exponent_min AddMonoid.exponent_min\n\n@[simp, to_additive]\ntheorem exp_eq_one_of_subsingleton [Subsingleton G] : exponent G = 1 :=\n  by\n  apply le_antisymm\n  \u00b7 apply exponent_min' _ Nat.one_pos\n    simp\n  \u00b7 apply Nat.succ_le_of_lt\n    apply exponent_pos_of_exists 1 Nat.one_pos\n    simp\n#align monoid.exp_eq_one_of_subsingleton Monoid.exp_eq_one_of_subsingleton\n#align add_monoid.exp_eq_zero_of_subsingleton AddMonoid.exp_eq_zero_of_subsingleton\n\n@[to_additive add_order_dvd_exponent]\ntheorem order_dvd_exponent (g : G) : orderOf g \u2223 exponent G :=\n  orderOf_dvd_of_pow_eq_one <| pow_exponent_eq_one g\n#align monoid.order_dvd_exponent Monoid.order_dvd_exponent\n#align add_monoid.add_order_dvd_exponent AddMonoid.add_order_dvd_exponent\n\nvariable (G)\n\n@[to_additive]\ntheorem exponent_dvd_of_forall_pow_eq_one (G) [Monoid G] (n : \u2115) (hG : \u2200 g : G, g ^ n = 1) :\n    exponent G \u2223 n := by\n  rcases n.eq_zero_or_pos with (rfl | hpos)\n  \u00b7 exact dvd_zero _\n  apply Nat.dvd_of_mod_eq_zero\n  by_contra h\n  have h\u2081 := Nat.pos_of_ne_zero h\n  have h\u2082 : n % exponent G < exponent G := Nat.mod_lt _ (exponent_pos_of_exists n hpos hG)\n  have h\u2083 : exponent G \u2264 n % exponent G :=\n    by\n    apply exponent_min' _ h\u2081\n    simp_rw [\u2190 pow_eq_mod_exponent]\n    exact hG\n  linarith\n#align monoid.exponent_dvd_of_forall_pow_eq_one Monoid.exponent_dvd_of_forall_pow_eq_one\n#align add_monoid.exponent_dvd_of_forall_nsmul_eq_zero AddMonoid.exponent_dvd_of_forall_nsmul_eq_zero\n\n@[to_additive lcm_add_order_of_dvd_exponent]\ntheorem lcm_orderOf_dvd_exponent [Fintype G] : (Finset.univ : Finset G).lcm orderOf \u2223 exponent G :=\n  by\n  apply Finset.lcm_dvd\n  intro g hg\n  exact order_dvd_exponent g\n#align monoid.lcm_order_of_dvd_exponent Monoid.lcm_orderOf_dvd_exponent\n#align add_monoid.lcm_add_order_of_dvd_exponent AddMonoid.lcm_add_orderOf_dvd_exponent\n\n@[to_additive exists_order_of_eq_pow_padic_val_nat_add_exponent]\ntheorem Nat.Prime.exists_orderOf_eq_pow_factorization_exponent {p : \u2115} (hp : p.Prime) :\n    \u2203 g : G, orderOf g = p ^ (exponent G).factorization p :=\n  by\n  haveI := Fact.mk hp\n  rcases eq_or_ne ((exponent G).factorization p) 0 with (h | h)\n  \u00b7 refine' \u27e81, by rw [h, pow_zero, orderOf_one]\u27e9\n  have he : 0 < exponent G :=\n    Ne.bot_lt fun ht => by\n      rw [ht] at h\n      apply h\n      rw [bot_eq_zero, Nat.factorization_zero, Finsupp.zero_apply]\n  rw [\u2190 Finsupp.mem_support_iff] at h\n  obtain \u27e8g, hg\u27e9 : \u2203 g : G, g ^ (exponent G / p) \u2260 1 :=\n    by\n    suffices key : \u00acexponent G \u2223 exponent G / p\n    \u00b7 simpa using mt (exponent_dvd_of_forall_pow_eq_one G (exponent G / p)) key\n    exact fun hd =>\n      hp.one_lt.not_le\n        ((mul_le_iff_le_one_left he).mp <|\n          Nat.le_of_dvd he <| Nat.mul_dvd_of_dvd_div (Nat.dvd_of_mem_factorization h) hd)\n  obtain \u27e8k, hk : exponent G = p ^ _ * k\u27e9 := Nat.ord_proj_dvd _ _\n  obtain \u27e8t, ht\u27e9 := Nat.exists_eq_succ_of_ne_zero (finsupp.mem_support_iff.mp h)\n  refine' \u27e8g ^ k, _\u27e9\n  rw [ht]\n  apply orderOf_eq_prime_pow\n  \u00b7 rwa [hk, mul_comm, ht, pow_succ', \u2190 mul_assoc, Nat.mul_div_cancel _ hp.pos, pow_mul] at hg\n  \u00b7 rw [\u2190 Nat.succ_eq_add_one, \u2190 ht, \u2190 pow_mul, mul_comm, \u2190 hk]\n    exact pow_exponent_eq_one g\n#align nat.prime.exists_order_of_eq_pow_factorization_exponent Nat.Prime.exists_orderOf_eq_pow_factorization_exponent\n#align nat.prime.exists_order_of_eq_pow_padic_val_nat_add_exponent Nat.Prime.exists_orderOf_eq_pow_padic_val_nat_add_exponent\n\nvariable {G}\n\n@[to_additive]\ntheorem exponent_ne_zero_iff_range_orderOf_finite (h : \u2200 g : G, 0 < orderOf g) :\n    exponent G \u2260 0 \u2194 (Set.range (orderOf : G \u2192 \u2115)).Finite :=\n  by\n  refine' \u27e8fun he => _, fun he => _\u27e9\n  \u00b7 by_contra h\n    obtain \u27e8m, \u27e8t, rfl\u27e9, het\u27e9 := Set.Infinite.exists_nat_lt h (exponent G)\n    exact pow_ne_one_of_lt_orderOf' he het (pow_exponent_eq_one t)\n  \u00b7 lift Set.range orderOf to Finset \u2115 using he with t ht\n    have htpos : 0 < t.prod id :=\n      by\n      refine' Finset.prod_pos fun a ha => _\n      rw [\u2190 Finset.mem_coe, ht] at ha\n      obtain \u27e8k, rfl\u27e9 := ha\n      exact h k\n    suffices exponent G \u2223 t.prod id by\n      intro h\n      rw [h, zero_dvd_iff] at this\n      exact htpos.ne' this\n    refine' exponent_dvd_of_forall_pow_eq_one _ _ fun g => _\n    rw [pow_eq_mod_orderOf, Nat.mod_eq_zero_of_dvd, pow_zero g]\n    apply Finset.dvd_prod_of_mem\n    rw [\u2190 Finset.mem_coe, ht]\n    exact Set.mem_range_self g\n#align monoid.exponent_ne_zero_iff_range_order_of_finite Monoid.exponent_ne_zero_iff_range_orderOf_finite\n#align add_monoid.exponent_ne_zero_iff_range_order_of_finite AddMonoid.exponent_ne_zero_iff_range_orderOf_finite\n\n@[to_additive]\ntheorem exponent_eq_zero_iff_range_orderOf_infinite (h : \u2200 g : G, 0 < orderOf g) :\n    exponent G = 0 \u2194 (Set.range (orderOf : G \u2192 \u2115)).Infinite :=\n  by\n  have := exponent_ne_zero_iff_range_orderOf_finite h\n  rwa [Ne.def, not_iff_comm, Iff.comm] at this\n#align monoid.exponent_eq_zero_iff_range_order_of_infinite Monoid.exponent_eq_zero_iff_range_orderOf_infinite\n#align add_monoid.exponent_eq_zero_iff_range_order_of_infinite AddMonoid.exponent_eq_zero_iff_range_orderOf_infinite\n\n@[to_additive lcm_add_order_eq_exponent]\ntheorem lcm_order_eq_exponent [Fintype G] : (Finset.univ : Finset G).lcm orderOf = exponent G :=\n  by\n  apply Nat.dvd_antisymm (lcm_order_of_dvd_exponent G)\n  refine' exponent_dvd_of_forall_pow_eq_one G _ fun g => _\n  obtain \u27e8m, hm\u27e9 : orderOf g \u2223 finset.univ.lcm orderOf := Finset.dvd_lcm (Finset.mem_univ g)\n  rw [hm, pow_mul, pow_orderOf_eq_one, one_pow]\n#align monoid.lcm_order_eq_exponent Monoid.lcm_order_eq_exponent\n#align add_monoid.lcm_add_order_eq_exponent AddMonoid.lcm_add_order_eq_exponent\n\nend Monoid\n\nsection LeftCancelMonoid\n\nvariable [LeftCancelMonoid G]\n\n@[to_additive]\ntheorem exponent_ne_zero_of_finite [Finite G] : exponent G \u2260 0 :=\n  by\n  cases nonempty_fintype G\n  simpa [\u2190 lcm_order_eq_exponent, Finset.lcm_eq_zero_iff] using fun x => (orderOf_pos x).ne'\n#align monoid.exponent_ne_zero_of_finite Monoid.exponent_ne_zero_of_finite\n#align add_monoid.exponent_ne_zero_of_finite AddMonoid.exponent_ne_zero_of_finite\n\nend LeftCancelMonoid\n\nsection CommMonoid\n\nvariable [CommMonoid G]\n\n@[to_additive]\ntheorem exponent_eq_sup\u1d62_orderOf (h : \u2200 g : G, 0 < orderOf g) : exponent G = \u2a06 g : G, orderOf g :=\n  by\n  rw [sup\u1d62]\n  rcases eq_or_ne (exponent G) 0 with (he | he)\n  \u00b7\n    rw [he,\n      Nat.Set.Infinite.Nat.sup\u209b_eq_zero <| (exponent_eq_zero_iff_range_order_of_infinite h).1 he]\n  have hne : (Set.range (orderOf : G \u2192 \u2115)).Nonempty := \u27e81, 1, orderOf_one\u27e9\n  have hfin : (Set.range (orderOf : G \u2192 \u2115)).Finite := by\n    rwa [\u2190 exponent_ne_zero_iff_range_order_of_finite h]\n  obtain \u27e8t, ht\u27e9 := hne.cSup_mem hfin\n  apply Nat.dvd_antisymm _\n  \u00b7 rw [\u2190 ht]\n    apply order_dvd_exponent\n  refine' Nat.dvd_of_factors_subperm he _\n  rw [List.subperm_ext_iff]\n  by_contra' h\n  obtain \u27e8p, hp, hpe\u27e9 := h\n  replace hp := Nat.prime_of_mem_factors hp\n  simp only [Nat.factors_count_eq] at hpe\n  set k := (orderOf t).factorization p with hk\n  obtain \u27e8g, hg\u27e9 := hp.exists_order_of_eq_pow_factorization_exponent G\n  suffices orderOf t < orderOf (t ^ p ^ k * g)\n    by\n    rw [ht] at this\n    exact this.not_le (le_csup\u209b hfin.bdd_above <| Set.mem_range_self _)\n  have hpk : p ^ k \u2223 orderOf t := Nat.ord_proj_dvd _ _\n  have hpk' : orderOf (t ^ p ^ k) = orderOf t / p ^ k := by\n    rw [orderOf_pow' t (pow_ne_zero k hp.ne_zero), Nat.gcd_eq_right hpk]\n  obtain \u27e8a, ha\u27e9 := Nat.exists_eq_add_of_lt hpe\n  have hcoprime : (orderOf (t ^ p ^ k)).coprime (orderOf g) :=\n    by\n    rw [hg, Nat.coprime_pow_right_iff (pos_of_gt hpe), Nat.coprime_comm]\n    apply Or.resolve_right (Nat.coprime_or_dvd_of_prime hp _)\n    nth_rw 1 [\u2190 pow_one p]\n    convert Nat.pow_succ_factorization_not_dvd (h <| t ^ p ^ k).ne' hp\n    rw [hpk', Nat.factorization_div hpk]\n    simp [hp]\n  rw [(Commute.all _ g).orderOf_mul_eq_mul_orderOf_of_coprime hcoprime, hpk', hg, ha, \u2190 ht, \u2190 hk,\n    pow_add, pow_add, pow_one, \u2190 mul_assoc, \u2190 mul_assoc, Nat.div_mul_cancel, mul_assoc,\n    lt_mul_iff_one_lt_right <| h t, \u2190 pow_succ']\n  exact one_lt_pow hp.one_lt a.succ_ne_zero\n  exact hpk\n#align monoid.exponent_eq_supr_order_of Monoid.exponent_eq_sup\u1d62_orderOf\n#align add_monoid.exponent_eq_supr_order_of AddMonoid.exponent_eq_sup\u1d62_orderOf\n\n@[to_additive]\ntheorem exponent_eq_sup\u1d62_order_of' :\n    exponent G = if \u2203 g : G, orderOf g = 0 then 0 else \u2a06 g : G, orderOf g :=\n  by\n  split_ifs\n  \u00b7 obtain \u27e8g, hg\u27e9 := h\n    exact exponent_eq_zero_of_order_zero hg\n  \u00b7 have := not_exists.mp h\n    exact exponent_eq_supr_order_of fun g => Ne.bot_lt <| this g\n#align monoid.exponent_eq_supr_order_of' Monoid.exponent_eq_sup\u1d62_order_of'\n#align add_monoid.exponent_eq_supr_order_of' AddMonoid.exponent_eq_sup\u1d62_order_of'\n\nend CommMonoid\n\nsection CancelCommMonoid\n\nvariable [CancelCommMonoid G]\n\n@[to_additive]\ntheorem exponent_eq_max'_orderOf [Fintype G] :\n    exponent G = ((@Finset.univ G _).image orderOf).max' \u27e81, by simp\u27e9 :=\n  by\n  rw [\u2190 Finset.Nonempty.cSup_eq_max', Finset.coe_image, Finset.coe_univ, Set.image_univ, \u2190 sup\u1d62]\n  exact exponent_eq_supr_order_of orderOf_pos\n#align monoid.exponent_eq_max'_order_of Monoid.exponent_eq_max'_orderOf\n#align add_monoid.exponent_eq_max'_order_of AddMonoid.exponent_eq_max'_order_of\n\nend CancelCommMonoid\n\nend Monoid\n\nsection CommGroup\n\nopen Subgroup\n\nopen BigOperators\n\nvariable (G) [CommGroup G] [Group.Fg G]\n\n@[to_additive]\ntheorem card_dvd_exponent_pow_rank : Nat.card G \u2223 Monoid.exponent G ^ Group.rank G :=\n  by\n  obtain \u27e8S, hS1, hS2\u27e9 := Group.rank_spec G\n  rw [\u2190 hS1, \u2190 Fintype.card_coe, \u2190 Finset.card_univ, \u2190 Finset.prod_const]\n  let f : (\u2200 g : S, zpowers (g : G)) \u2192* G := noncomm_pi_coprod fun s t h x y hx hy => mul_comm x y\n  have hf : Function.Surjective f :=\n    by\n    rw [\u2190 MonoidHom.range_top_iff_surjective, eq_top_iff, \u2190 hS2, closure_le]\n    exact fun g hg => \u27e8Pi.mulSingle \u27e8g, hg\u27e9 \u27e8g, mem_zpowers g\u27e9, noncomm_pi_coprod_mul_single _ _\u27e9\n  replace hf := nat_card_dvd_of_surjective f hf\n  rw [Nat.card_pi] at hf\n  refine' hf.trans (Finset.prod_dvd_prod_of_dvd _ _ fun g hg => _)\n  rw [\u2190 order_eq_card_zpowers']\n  exact Monoid.order_dvd_exponent (g : G)\n#align card_dvd_exponent_pow_rank card_dvd_exponent_pow_rank\n#align card_dvd_exponent_nsmul_rank card_dvd_exponent_nsmul_rank\n\n@[to_additive]\ntheorem card_dvd_exponent_pow_rank' {n : \u2115} (hG : \u2200 g : G, g ^ n = 1) :\n    Nat.card G \u2223 n ^ Group.rank G :=\n  (card_dvd_exponent_pow_rank G).trans\n    (pow_dvd_pow_of_dvd (Monoid.exponent_dvd_of_forall_pow_eq_one G n hG) (Group.rank G))\n#align card_dvd_exponent_pow_rank' card_dvd_exponent_pow_rank'\n#align card_dvd_exponent_nsmul_rank' card_dvd_exponent_nsmul_rank'\n\nend CommGroup\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/GroupTheory/Exponent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7262464503066443}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module algebra.category.Module.images\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Category.Module.Abelian\nimport Mathbin.CategoryTheory.Limits.Shapes.Images\n\n/-!\n# The category of R-modules has images.\n\nNote that we don't need to register any of the constructions here as instances, because we get them\nfrom the fact that `Module R` is an abelian category.\n-/\n\n\nopen CategoryTheory\n\nopen CategoryTheory.Limits\n\nuniverse u v\n\nnamespace ModuleCat\n\nvariable {R : Type u} [CommRing R]\n\nvariable {G H : ModuleCat.{v} R} (f : G \u27f6 H)\n\nattribute [local ext] Subtype.ext_val\n\nsection\n\n-- implementation details of `has_image` for Module; use the API, not these\n/-- The image of a morphism in `Module R` is just the bundling of `linear_map.range f` -/\ndef image : ModuleCat R :=\n  ModuleCat.of R (LinearMap.range f)\n#align Module.image ModuleCat.image\n\n/-- The inclusion of `image f` into the target -/\ndef image.\u03b9 : image f \u27f6 H :=\n  f.range.Subtype\n#align Module.image.\u03b9 ModuleCat.image.\u03b9\n\ninstance : Mono (image.\u03b9 f) :=\n  ConcreteCategory.mono_of_injective (image.\u03b9 f) Subtype.val_injective\n\n/-- The corestriction map to the image -/\ndef factorThruImage : G \u27f6 image f :=\n  f.range_restrict\n#align Module.factor_thru_image ModuleCat.factorThruImage\n\ntheorem image.fac : factorThruImage f \u226b image.\u03b9 f = f :=\n  by\n  ext\n  rfl\n#align Module.image.fac ModuleCat.image.fac\n\nattribute [local simp] image.fac\n\nvariable {f}\n\n/-- The universal property for the image factorisation -/\nnoncomputable def image.lift (F' : MonoFactorisation f) : image f \u27f6 F'.i\n    where\n  toFun := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : image f \u2192 F'.i)\n  map_add' := by\n    intro x y\n    haveI := F'.m_mono\n    apply (mono_iff_injective F'.m).1; infer_instance\n    rw [LinearMap.map_add]\n    change (F'.e \u226b F'.m) _ = (F'.e \u226b F'.m) _ + (F'.e \u226b F'.m) _\n    rw [F'.fac]\n    rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]\n    rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]\n    rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]\n    rfl\n  map_smul' c x := by\n    haveI := F'.m_mono\n    apply (mono_iff_injective F'.m).1; infer_instance\n    rw [LinearMap.map_smul]\n    change (F'.e \u226b F'.m) _ = _ \u2022 (F'.e \u226b F'.m) _\n    rw [F'.fac]\n    rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]\n    rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]\n    rfl\n#align Module.image.lift ModuleCat.image.lift\n\ntheorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' \u226b F'.m = image.\u03b9 f :=\n  by\n  ext x\n  change (F'.e \u226b F'.m) _ = _\n  rw [F'.fac, (Classical.indefiniteDescription _ x.2).2]\n  rfl\n#align Module.image.lift_fac ModuleCat.image.lift_fac\n\nend\n\n/-- The factorisation of any morphism in `Module R` through a mono. -/\ndef monoFactorisation : MonoFactorisation f\n    where\n  i := image f\n  m := image.\u03b9 f\n  e := factorThruImage f\n#align Module.mono_factorisation ModuleCat.monoFactorisation\n\n/-- The factorisation of any morphism in `Module R` through a mono has the universal property of\nthe image. -/\nnoncomputable def isImage : IsImage (monoFactorisation f)\n    where\n  lift := image.lift\n  lift_fac := image.lift_fac\n#align Module.is_image ModuleCat.isImage\n\n/-- The categorical image of a morphism in `Module R`\nagrees with the linear algebraic range.\n-/\nnoncomputable def imageIsoRange {G H : ModuleCat.{v} R} (f : G \u27f6 H) :\n    Limits.image f \u2245 ModuleCat.of R f.range :=\n  IsImage.isoExt (Image.isImage f) (isImage f)\n#align Module.image_iso_range ModuleCat.imageIsoRange\n\n@[simp, reassoc.1, elementwise]\ntheorem imageIsoRange_inv_image_\u03b9 {G H : ModuleCat.{v} R} (f : G \u27f6 H) :\n    (imageIsoRange f).inv \u226b Limits.image.\u03b9 f = ModuleCat.ofHom f.range.Subtype :=\n  IsImage.isoExt_inv_m _ _\n#align Module.image_iso_range_inv_image_\u03b9 ModuleCat.imageIsoRange_inv_image_\u03b9\n\n@[simp, reassoc.1, elementwise]\ntheorem imageIsoRange_hom_subtype {G H : ModuleCat.{v} R} (f : G \u27f6 H) :\n    (imageIsoRange f).hom \u226b ModuleCat.ofHom f.range.Subtype = Limits.image.\u03b9 f := by\n  erw [\u2190 image_iso_range_inv_image_\u03b9 f, iso.hom_inv_id_assoc]\n#align Module.image_iso_range_hom_subtype ModuleCat.imageIsoRange_hom_subtype\n\nend ModuleCat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Category/Module/Images.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7261836575559935}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\nThe integers, with addition, multiplication, and subtraction.\n-/\nimport data.nat.basic\nimport algebra.order_functions\n\nopen nat\n\nnamespace int\n\ninstance : inhabited \u2124 := \u27e8int.zero\u27e9\n\ninstance : nontrivial \u2124 :=\n\u27e8\u27e80, 1, int.zero_ne_one\u27e9\u27e9\n\ninstance : comm_ring int :=\n{ add            := int.add,\n  add_assoc      := int.add_assoc,\n  zero           := int.zero,\n  zero_add       := int.zero_add,\n  add_zero       := int.add_zero,\n  neg            := int.neg,\n  add_left_neg   := int.add_left_neg,\n  add_comm       := int.add_comm,\n  mul            := int.mul,\n  mul_assoc      := int.mul_assoc,\n  one            := int.one,\n  one_mul        := int.one_mul,\n  mul_one        := int.mul_one,\n  sub            := int.sub,\n  left_distrib   := int.distrib_left,\n  right_distrib  := int.distrib_right,\n  mul_comm       := int.mul_comm,\n  gsmul          := (*),\n  gsmul_zero'    := int.zero_mul,\n  gsmul_succ'    := \u03bb n x, by rw [succ_eq_one_add, of_nat_add, int.distrib_right, of_nat_one,\n                                  int.one_mul],\n  gsmul_neg'     := \u03bb n x, neg_mul_eq_neg_mul_symm (n.succ : \u2124) x }\n\n/-! ### Extra instances to short-circuit type class resolution -/\n-- instance : has_sub int            := by apply_instance -- This is in core\ninstance : add_comm_monoid int    := by apply_instance\ninstance : add_monoid int         := by apply_instance\ninstance : monoid int             := by apply_instance\ninstance : comm_monoid int        := by apply_instance\ninstance : comm_semigroup int     := by apply_instance\ninstance : semigroup int          := by apply_instance\ninstance : add_comm_semigroup int := by apply_instance\ninstance : add_semigroup int      := by apply_instance\ninstance : comm_semiring int      := by apply_instance\ninstance : semiring int           := by apply_instance\ninstance : ring int               := by apply_instance\ninstance : distrib int            := by apply_instance\n\ninstance : linear_ordered_comm_ring int :=\n{ add_le_add_left := @int.add_le_add_left,\n  mul_pos         := @int.mul_pos,\n  zero_le_one     := le_of_lt int.zero_lt_one,\n  .. int.comm_ring, .. int.linear_order, .. int.nontrivial }\n\ninstance : linear_ordered_add_comm_group int :=\nby apply_instance\n\n@[simp] lemma add_neg_one (i : \u2124) : i + -1 = i - 1 := rfl\n\ntheorem abs_eq_nat_abs : \u2200 a : \u2124, abs a = nat_abs a\n| (n : \u2115) := abs_of_nonneg $ coe_zero_le _\n| -[1+ n] := abs_of_nonpos $ le_of_lt $ neg_succ_lt_zero _\n\ntheorem nat_abs_abs (a : \u2124) : nat_abs (abs a) = nat_abs a :=\nby rw [abs_eq_nat_abs]; refl\n\ntheorem sign_mul_abs (a : \u2124) : sign a * abs a = a :=\nby rw [abs_eq_nat_abs, sign_mul_nat_abs]\n\n@[simp] lemma default_eq_zero : default \u2124 = 0 := rfl\n\nmeta instance : has_to_format \u2124 := \u27e8\u03bb z, to_string z\u27e9\nmeta instance : has_reflect \u2124 := by tactic.mk_has_reflect_instance\n\nattribute [simp] int.coe_nat_add int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_succ\nattribute [simp] int.of_nat_eq_coe int.bodd\n\n@[simp] theorem add_def {a b : \u2124} : int.add a b = a + b := rfl\n@[simp] theorem mul_def {a b : \u2124} : int.mul a b = a * b := rfl\n\n@[simp] lemma neg_succ_not_nonneg (n : \u2115) : 0 \u2264 -[1+ n] \u2194 false :=\nby { simp only [not_le, iff_false], exact int.neg_succ_lt_zero n, }\n\n@[simp] lemma neg_succ_not_pos (n : \u2115) : 0 < -[1+ n] \u2194 false :=\nby simp only [not_lt, iff_false]\n\n@[simp] lemma neg_succ_sub_one (n : \u2115) : -[1+ n] - 1 = -[1+ (n+1)] := rfl\n@[simp] theorem coe_nat_mul_neg_succ (m n : \u2115) : (m : \u2124) * -[1+ n] = -(m * succ n) := rfl\n@[simp] theorem neg_succ_mul_coe_nat (m n : \u2115) : -[1+ m] * n = -(succ m * n) := rfl\n@[simp] theorem neg_succ_mul_neg_succ (m n : \u2115) : -[1+ m] * -[1+ n] = succ m * succ n := rfl\n\n@[simp, norm_cast]\ntheorem coe_nat_le {m n : \u2115} : (\u2191m : \u2124) \u2264 \u2191n \u2194 m \u2264 n := coe_nat_le_coe_nat_iff m n\n@[simp, norm_cast]\ntheorem coe_nat_lt {m n : \u2115} : (\u2191m : \u2124) < \u2191n \u2194 m < n := coe_nat_lt_coe_nat_iff m n\n@[simp, norm_cast]\ntheorem coe_nat_inj' {m n : \u2115} : (\u2191m : \u2124) = \u2191n \u2194 m = n := int.coe_nat_eq_coe_nat_iff m n\n\n@[simp] theorem coe_nat_pos {n : \u2115} : (0 : \u2124) < n \u2194 0 < n :=\nby rw [\u2190 int.coe_nat_zero, coe_nat_lt]\n\n@[simp] theorem coe_nat_eq_zero {n : \u2115} : (n : \u2124) = 0 \u2194 n = 0 :=\nby rw [\u2190 int.coe_nat_zero, coe_nat_inj']\n\ntheorem coe_nat_ne_zero {n : \u2115} : (n : \u2124) \u2260 0 \u2194 n \u2260 0 :=\nnot_congr coe_nat_eq_zero\n\n@[simp] lemma coe_nat_nonneg (n : \u2115) : 0 \u2264 (n : \u2124) := coe_nat_le.2 (nat.zero_le _)\n\nlemma coe_nat_ne_zero_iff_pos {n : \u2115} : (n : \u2124) \u2260 0 \u2194 0 < n :=\n\u27e8\u03bb h, nat.pos_of_ne_zero (coe_nat_ne_zero.1 h),\n\u03bb h, (ne_of_lt (coe_nat_lt.2 h)).symm\u27e9\n\nlemma coe_nat_succ_pos (n : \u2115) : 0 < (n.succ : \u2124) := int.coe_nat_pos.2 (succ_pos n)\n\n@[simp, norm_cast] theorem coe_nat_abs (n : \u2115) : abs (n : \u2124) = n :=\nabs_of_nonneg (coe_nat_nonneg n)\n\n/-! ### succ and pred -/\n\n/-- Immediate successor of an integer: `succ n = n + 1` -/\ndef succ (a : \u2124) := a + 1\n\n/-- Immediate predecessor of an integer: `pred n = n - 1` -/\ndef pred (a : \u2124) := a - 1\n\ntheorem nat_succ_eq_int_succ (n : \u2115) : (nat.succ n : \u2124) = int.succ n := rfl\n\ntheorem pred_succ (a : \u2124) : pred (succ a) = a := add_sub_cancel _ _\n\ntheorem succ_pred (a : \u2124) : succ (pred a) = a := sub_add_cancel _ _\n\ntheorem neg_succ (a : \u2124) : -succ a = pred (-a) := neg_add _ _\n\ntheorem succ_neg_succ (a : \u2124) : succ (-succ a) = -a :=\nby rw [neg_succ, succ_pred]\n\ntheorem neg_pred (a : \u2124) : -pred a = succ (-a) :=\nby rw [eq_neg_of_eq_neg (neg_succ (-a)).symm, neg_neg]\n\ntheorem pred_neg_pred (a : \u2124) : pred (-pred a) = -a :=\nby rw [neg_pred, pred_succ]\n\ntheorem pred_nat_succ (n : \u2115) : pred (nat.succ n) = n := pred_succ n\n\ntheorem neg_nat_succ (n : \u2115) : -(nat.succ n : \u2124) = pred (-n) := neg_succ n\n\ntheorem succ_neg_nat_succ (n : \u2115) : succ (-nat.succ n) = -n := succ_neg_succ n\n\ntheorem lt_succ_self (a : \u2124) : a < succ a :=\nlt_add_of_pos_right _ zero_lt_one\n\ntheorem pred_self_lt (a : \u2124) : pred a < a :=\nsub_lt_self _ zero_lt_one\n\ntheorem add_one_le_iff {a b : \u2124} : a + 1 \u2264 b \u2194 a < b := iff.rfl\n\ntheorem lt_add_one_iff {a b : \u2124} : a < b + 1 \u2194 a \u2264 b :=\n@add_le_add_iff_right _ _ a b 1\n\n@[simp] lemma succ_coe_nat_pos (n : \u2115) : 0 < (n : \u2124) + 1 :=\nlt_add_one_iff.mpr (by simp)\n\n@[norm_cast] lemma coe_pred_of_pos (n : \u2115) (h : 0 < n) : ((n - 1 : \u2115) : \u2124) = (n : \u2124) - 1 :=\nby { cases n, cases h, simp, }\n\nlemma le_add_one {a b : \u2124} (h : a \u2264 b) : a \u2264 b + 1 :=\nle_of_lt (int.lt_add_one_iff.mpr h)\n\ntheorem sub_one_lt_iff {a b : \u2124} : a - 1 < b \u2194 a \u2264 b :=\nsub_lt_iff_lt_add.trans lt_add_one_iff\n\ntheorem le_sub_one_iff {a b : \u2124} : a \u2264 b - 1 \u2194 a < b :=\nle_sub_iff_add_le\n\n@[simp] lemma eq_zero_iff_abs_lt_one {a : \u2124} : abs a < 1 \u2194 a = 0 :=\n\u27e8\u03bb a0, let \u27e8hn, hp\u27e9 := abs_lt.mp a0 in (le_of_lt_add_one (by exact hp)).antisymm hn,\n  \u03bb a0, (abs_eq_zero.mpr a0).le.trans_lt zero_lt_one\u27e9\n\n@[elab_as_eliminator] protected lemma induction_on {p : \u2124 \u2192 Prop}\n  (i : \u2124) (hz : p 0) (hp : \u2200i : \u2115, p i \u2192 p (i + 1)) (hn : \u2200i : \u2115, p (-i) \u2192 p (-i - 1)) : p i :=\nbegin\n  induction i,\n  { induction i,\n    { exact hz },\n    { exact hp _ i_ih } },\n  { have : \u2200n:\u2115, p (- n),\n    { intro n, induction n,\n      { simp [hz] },\n      { convert hn _ n_ih using 1, simp [sub_eq_neg_add] } },\n    exact this (i + 1) }\nend\n\n/-- Inductively define a function on `\u2124` by defining it at `b`, for the `succ` of a number greater\n  than `b`, and the `pred` of a number less than `b`. -/\nprotected def induction_on' {C : \u2124 \u2192 Sort*} (z : \u2124) (b : \u2124) :\n  C b \u2192 (\u2200 k, b \u2264 k \u2192 C k \u2192 C (k + 1)) \u2192 (\u2200 k \u2264 b, C k \u2192 C (k - 1)) \u2192 C z :=\n\u03bb H0 Hs Hp,\nbegin\n  rw \u2190sub_add_cancel z b,\n  induction (z - b) with n n,\n  { induction n with n ih, { rwa [of_nat_zero, zero_add] },\n    rw [of_nat_succ, add_assoc, add_comm 1 b, \u2190add_assoc],\n    exact Hs _ (le_add_of_nonneg_left (of_nat_nonneg _)) ih },\n  { induction n with n ih,\n    { rw [neg_succ_of_nat_eq, \u2190of_nat_eq_coe, of_nat_zero, zero_add, neg_add_eq_sub],\n      exact Hp _ (le_refl _) H0 },\n    { rw [neg_succ_of_nat_coe', nat.succ_eq_add_one, \u2190neg_succ_of_nat_coe, sub_add_eq_add_sub],\n      exact Hp _ (le_of_lt (add_lt_of_neg_of_le (neg_succ_lt_zero _) (le_refl _))) ih } }\nend\n\n/-! ### nat abs -/\n\nattribute [simp] nat_abs nat_abs_of_nat nat_abs_zero nat_abs_one\n\ntheorem nat_abs_add_le (a b : \u2124) : nat_abs (a + b) \u2264 nat_abs a + nat_abs b :=\nbegin\n  have : \u2200 (a b : \u2115), nat_abs (sub_nat_nat a (nat.succ b)) \u2264 nat.succ (a + b),\n  { refine (\u03bb a b : \u2115, sub_nat_nat_elim a b.succ\n      (\u03bb m n i, n = b.succ \u2192 nat_abs i \u2264 (m + b).succ) _ _ rfl);\n    intros i n e,\n    { subst e, rw [add_comm _ i, add_assoc],\n      exact nat.le_add_right i (b.succ + b).succ },\n    { apply succ_le_succ,\n      rw [\u2190 succ.inj e, \u2190 add_assoc, add_comm],\n      apply nat.le_add_right } },\n  cases a; cases b with b b; simp [nat_abs, nat.succ_add];\n  try {refl}; [skip, rw add_comm a b]; apply this\nend\n\ntheorem nat_abs_neg_of_nat (n : \u2115) : nat_abs (neg_of_nat n) = n :=\nby cases n; refl\n\ntheorem nat_abs_mul (a b : \u2124) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) :=\nby cases a; cases b;\n  simp only [\u2190 int.mul_def, int.mul, nat_abs_neg_of_nat, eq_self_iff_true, int.nat_abs]\n\nlemma nat_abs_mul_nat_abs_eq {a b : \u2124} {c : \u2115} (h : a * b = (c : \u2124)) :\n  a.nat_abs * b.nat_abs = c :=\nby rw [\u2190 nat_abs_mul, h, nat_abs_of_nat]\n\n@[simp] lemma nat_abs_mul_self' (a : \u2124) : (nat_abs a * nat_abs a : \u2124) = a * a :=\nby rw [\u2190 int.coe_nat_mul, nat_abs_mul_self]\n\ntheorem neg_succ_of_nat_eq' (m : \u2115) : -[1+ m] = -m - 1 :=\nby simp [neg_succ_of_nat_eq, sub_eq_neg_add]\n\nlemma nat_abs_ne_zero_of_ne_zero {z : \u2124} (hz : z \u2260 0) : z.nat_abs \u2260 0 :=\n\u03bb h, hz $ int.eq_zero_of_nat_abs_eq_zero h\n\n@[simp] lemma nat_abs_eq_zero {a : \u2124} : a.nat_abs = 0 \u2194 a = 0 :=\n\u27e8int.eq_zero_of_nat_abs_eq_zero, \u03bb h, h.symm \u25b8 rfl\u27e9\n\n\n\nlemma nat_abs_lt_nat_abs_of_nonneg_of_lt {a b : \u2124} (w\u2081 : 0 \u2264 a) (w\u2082 : a < b) :\n  a.nat_abs < b.nat_abs :=\nbegin\n  lift b to \u2115 using le_trans w\u2081 (le_of_lt w\u2082),\n  lift a to \u2115 using w\u2081,\n  simpa using w\u2082,\nend\n\nlemma nat_abs_eq_nat_abs_iff {a b : \u2124} : a.nat_abs = b.nat_abs \u2194 a = b \u2228 a = -b :=\nbegin\n  split; intro h,\n  { cases int.nat_abs_eq a with h\u2081 h\u2081; cases int.nat_abs_eq b with h\u2082 h\u2082;\n    rw [h\u2081, h\u2082]; simp [h], },\n  { cases h; rw h, rw int.nat_abs_neg, },\nend\n\nlemma nat_abs_eq_iff {a : \u2124} {n : \u2115} : a.nat_abs = n \u2194 a = n \u2228 a = -n :=\nby rw [\u2190int.nat_abs_eq_nat_abs_iff, int.nat_abs_of_nat]\n\nlemma nat_abs_eq_iff_mul_self_eq {a b : \u2124} : a.nat_abs = b.nat_abs \u2194 a * a = b * b :=\nbegin\n  rw [\u2190 abs_eq_iff_mul_self_eq, abs_eq_nat_abs, abs_eq_nat_abs],\n  exact int.coe_nat_inj'.symm\nend\n\nlemma nat_abs_lt_iff_mul_self_lt {a b : \u2124} : a.nat_abs < b.nat_abs \u2194 a * a < b * b :=\nbegin\n  rw [\u2190 abs_lt_iff_mul_self_lt, abs_eq_nat_abs, abs_eq_nat_abs],\n  exact int.coe_nat_lt.symm\nend\n\nlemma nat_abs_le_iff_mul_self_le {a b : \u2124} : a.nat_abs \u2264 b.nat_abs \u2194 a * a \u2264 b * b :=\nbegin\n  rw [\u2190 abs_le_iff_mul_self_le, abs_eq_nat_abs, abs_eq_nat_abs],\n  exact int.coe_nat_le.symm\nend\n\nlemma nat_abs_eq_iff_sq_eq {a b : \u2124} : a.nat_abs = b.nat_abs \u2194 a ^ 2 = b ^ 2 :=\nby { rw [sq, sq], exact nat_abs_eq_iff_mul_self_eq }\n\nlemma nat_abs_lt_iff_sq_lt {a b : \u2124} : a.nat_abs < b.nat_abs \u2194 a ^ 2 < b ^ 2 :=\nby { rw [sq, sq], exact nat_abs_lt_iff_mul_self_lt }\n\nlemma nat_abs_le_iff_sq_le {a b : \u2124} : a.nat_abs \u2264 b.nat_abs \u2194 a ^ 2 \u2264 b ^ 2 :=\nby { rw [sq, sq], exact nat_abs_le_iff_mul_self_le }\n\n/-! ### `/`  -/\n\n@[simp] theorem of_nat_div (m n : \u2115) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl\n\n@[simp, norm_cast] theorem coe_nat_div (m n : \u2115) : ((m / n : \u2115) : \u2124) = m / n := rfl\n\ntheorem neg_succ_of_nat_div (m : \u2115) {b : \u2124} (H : 0 < b) :\n  -[1+m] / b = -(m / b + 1) :=\nmatch b, eq_succ_of_zero_lt H with ._, \u27e8n, rfl\u27e9 := rfl end\n\n-- Will be generalized to Euclidean domains.\nlocal attribute [simp]\nprotected theorem zero_div : \u2200 (b : \u2124), 0 / b = 0\n| 0       := show of_nat _ = _, by simp\n| (n+1:\u2115) := show of_nat _ = _, by simp\n| -[1+ n] := show -of_nat _ = _, by simp\n\nlocal attribute [simp] -- Will be generalized to Euclidean domains.\nprotected theorem div_zero : \u2200 (a : \u2124), a / 0 = 0\n| 0       := show of_nat _ = _, by simp\n| (n+1:\u2115) := show of_nat _ = _, by simp\n| -[1+ n] := rfl\n\n@[simp] protected theorem div_neg : \u2200 (a b : \u2124), a / -b = -(a / b)\n| (m : \u2115) 0       := show of_nat (m / 0) = -(m / 0 : \u2115), by rw nat.div_zero; refl\n| (m : \u2115) (n+1:\u2115) := rfl\n| 0       -[1+ n] := by simp\n| (m+1:\u2115) -[1+ n] := (neg_neg _).symm\n| -[1+ m] 0       := rfl\n| -[1+ m] (n+1:\u2115) := rfl\n| -[1+ m] -[1+ n] := rfl\n\n\ntheorem div_of_neg_of_pos {a b : \u2124} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) :=\nmatch a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with\n| ._, ._, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 :=\n  by change (- -[1+ m] : \u2124) with (m+1 : \u2124); rw add_sub_cancel; refl\nend\n\nprotected theorem div_nonneg {a b : \u2124} (Ha : 0 \u2264 a) (Hb : 0 \u2264 b) : 0 \u2264 a / b :=\nmatch a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with\n| ._, ._, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := coe_zero_le _\nend\n\nprotected theorem div_nonpos {a b : \u2124} (Ha : 0 \u2264 a) (Hb : b \u2264 0) : a / b \u2264 0 :=\nnonpos_of_neg_nonneg $ by rw [\u2190 int.div_neg]; exact int.div_nonneg Ha (neg_nonneg_of_nonpos Hb)\n\ntheorem div_neg' {a b : \u2124} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 :=\nmatch a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with\n| ._, ._, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := neg_succ_lt_zero _\nend\n\n@[simp] protected theorem div_one : \u2200 (a : \u2124), a / 1 = a\n| 0       := show of_nat _ = _, by simp\n| (n+1:\u2115) := congr_arg of_nat (nat.div_one _)\n| -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _)\n\ntheorem div_eq_zero_of_lt {a b : \u2124} (H1 : 0 \u2264 a) (H2 : a < b) : a / b = 0 :=\nmatch a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2  with\n| ._, ._, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9, H2 :=\n  congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2\nend\n\ntheorem div_eq_zero_of_lt_abs {a b : \u2124} (H1 : 0 \u2264 a) (H2 : a < abs b) : a / b = 0 :=\nmatch b, abs b, abs_eq_nat_abs b, H2 with\n| (n : \u2115), ._, rfl, H2 := div_eq_zero_of_lt H1 H2\n| -[1+ n], ._, rfl, H2 := neg_injective $ by rw [\u2190 int.div_neg]; exact div_eq_zero_of_lt H1 H2\nend\n\nprotected theorem add_mul_div_right (a b : \u2124) {c : \u2124} (H : c \u2260 0) :\n  (a + b * c) / c = a / c + b :=\nhave \u2200 {k n : \u2115} {a : \u2124}, (a + n * k.succ) / k.succ = a / k.succ + n, from\n\u03bb k n a, match a with\n| (m : \u2115) := congr_arg of_nat $ nat.add_mul_div_right _ _ k.succ_pos\n| -[1+ m] := show ((n * k.succ:\u2115) - m.succ : \u2124) / k.succ =\n                  n - (m / k.succ + 1 : \u2115), begin\n  cases lt_or_ge m (n*k.succ) with h h,\n  { rw [\u2190 int.coe_nat_sub h,\n        \u2190 int.coe_nat_sub ((nat.div_lt_iff_lt_mul _ _ k.succ_pos).2 h)],\n    apply congr_arg of_nat,\n    rw [mul_comm, nat.mul_sub_div], rwa mul_comm },\n  { change (\u2191(n * nat.succ k) - (m + 1) : \u2124) / \u2191(nat.succ k) =\n           \u2191n - ((m / nat.succ k : \u2115) + 1),\n    rw [\u2190 sub_sub, \u2190 sub_sub, \u2190 neg_sub (m:\u2124), \u2190 neg_sub _ (n:\u2124),\n        \u2190 int.coe_nat_sub h,\n        \u2190 int.coe_nat_sub ((nat.le_div_iff_mul_le _ _ k.succ_pos).2 h),\n        \u2190 neg_succ_of_nat_coe', \u2190 neg_succ_of_nat_coe'],\n    { apply congr_arg neg_succ_of_nat,\n      rw [mul_comm, nat.sub_mul_div], rwa mul_comm } }\n  end\nend,\nhave \u2200 {a b c : \u2124}, 0 < c \u2192 (a + b * c) / c = a / c + b, from\n\u03bb a b c H, match c, eq_succ_of_zero_lt H, b with\n| ._, \u27e8k, rfl\u27e9, (n : \u2115) := this\n| ._, \u27e8k, rfl\u27e9, -[1+ n] :=\n  show (a - n.succ * k.succ) / k.succ = (a / k.succ) - n.succ, from\n  eq_sub_of_add_eq $ by rw [\u2190 this, sub_add_cancel]\nend,\nmatch lt_trichotomy c 0 with\n| or.inl hlt          := neg_inj.1 $ by rw [\u2190 int.div_neg, neg_add, \u2190 int.div_neg, \u2190 neg_mul_neg];\n                         apply this (neg_pos_of_neg hlt)\n| or.inr (or.inl heq) := absurd heq H\n| or.inr (or.inr hgt) := this hgt\nend\n\nprotected theorem add_mul_div_left (a : \u2124) {b : \u2124} (c : \u2124) (H : b \u2260 0) :\n    (a + b * c) / b = a / b + c :=\nby rw [mul_comm, int.add_mul_div_right _ _ H]\n\nprotected theorem add_div_of_dvd_right {a b c : \u2124} (H : c \u2223 b) :\n  (a + b) / c = a / c + b / c :=\nbegin\n  by_cases h1 : c = 0,\n  { simp [h1] },\n  cases H with k hk,\n  rw hk,\n  change c \u2260 0 at h1,\n  rw [mul_comm c k, int.add_mul_div_right _ _ h1, \u2190zero_add (k * c), int.add_mul_div_right _ _ h1,\n      int.zero_div, zero_add]\nend\n\nprotected theorem add_div_of_dvd_left {a b c : \u2124} (H : c \u2223 a) :\n  (a + b) / c = a / c + b / c :=\nby rw [add_comm, int.add_div_of_dvd_right H, add_comm]\n\n@[simp] protected theorem mul_div_cancel (a : \u2124) {b : \u2124} (H : b \u2260 0) : a * b / b = a :=\nby have := int.add_mul_div_right 0 a H;\n   rwa [zero_add, int.zero_div, zero_add] at this\n\n@[simp] protected theorem mul_div_cancel_left {a : \u2124} (b : \u2124) (H : a \u2260 0) : a * b / a = b :=\nby rw [mul_comm, int.mul_div_cancel _ H]\n\n@[simp] protected theorem div_self {a : \u2124} (H : a \u2260 0) : a / a = 1 :=\nby have := int.mul_div_cancel 1 H; rwa one_mul at this\n\n/-! ### mod -/\n\ntheorem of_nat_mod (m n : nat) : (m % n : \u2124) = of_nat (m % n) := rfl\n\n@[simp, norm_cast] theorem coe_nat_mod (m n : \u2115) : (\u2191(m % n) : \u2124) = \u2191m % \u2191n := rfl\n\ntheorem neg_succ_of_nat_mod (m : \u2115) {b : \u2124} (bpos : 0 < b) :\n  -[1+m] % b = b - 1 - m % b :=\nby rw [sub_sub, add_comm]; exact\nmatch b, eq_succ_of_zero_lt bpos with ._, \u27e8n, rfl\u27e9 := rfl end\n\n@[simp] theorem mod_neg : \u2200 (a b : \u2124), a % -b = a % b\n| (m : \u2115) n := @congr_arg \u2115 \u2124 _ _ (\u03bb i, \u2191(m % i)) (nat_abs_neg _)\n| -[1+ m] n := @congr_arg \u2115 \u2124 _ _ (\u03bb i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _)\n\n@[simp] theorem mod_abs (a b : \u2124) : a % (abs b) = a % b :=\nabs_by_cases (\u03bb i, a % i = a % b) rfl (mod_neg _ _)\n\nlocal attribute [simp] -- Will be generalized to Euclidean domains.\ntheorem zero_mod (b : \u2124) : 0 % b = 0 := rfl\n\nlocal attribute [simp] -- Will be generalized to Euclidean domains.\ntheorem mod_zero : \u2200 (a : \u2124), a % 0 = a\n| (m : \u2115) := congr_arg of_nat $ nat.mod_zero _\n| -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _\n\nlocal attribute [simp] -- Will be generalized to Euclidean domains.\ntheorem mod_one : \u2200 (a : \u2124), a % 1 = 0\n| (m : \u2115) := congr_arg of_nat $ nat.mod_one _\n| -[1+ m] := show (1 - (m % 1).succ : \u2124) = 0, by rw nat.mod_one; refl\n\ntheorem mod_eq_of_lt {a b : \u2124} (H1 : 0 \u2264 a) (H2 : a < b) : a % b = a :=\nmatch a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with\n| ._, ._, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9, H2 :=\n  congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2)\nend\n\ntheorem mod_nonneg : \u2200 (a : \u2124) {b : \u2124}, b \u2260 0 \u2192 0 \u2264 a % b\n| (m : \u2115) n H := coe_zero_le _\n| -[1+ m] n H :=\n  sub_nonneg_of_le $ coe_nat_le_coe_nat_of_le $ nat.mod_lt _ (nat_abs_pos_of_ne_zero H)\n\ntheorem mod_lt_of_pos (a : \u2124) {b : \u2124} (H : 0 < b) : a % b < b :=\nmatch a, b, eq_succ_of_zero_lt H with\n| (m : \u2115), ._, \u27e8n, rfl\u27e9 := coe_nat_lt_coe_nat_of_lt (nat.mod_lt _ (nat.succ_pos _))\n| -[1+ m], ._, \u27e8n, rfl\u27e9 := sub_lt_self _ (coe_nat_lt_coe_nat_of_lt $ nat.succ_pos _)\nend\n\ntheorem mod_lt (a : \u2124) {b : \u2124} (H : b \u2260 0) : a % b < abs b :=\nby rw [\u2190 mod_abs]; exact mod_lt_of_pos _ (abs_pos.2 H)\n\ntheorem mod_add_div_aux (m n : \u2115) : (n - (m % n + 1) - (n * (m / n) + n) : \u2124) = -[1+ m] :=\nbegin\n  rw [\u2190 sub_sub, neg_succ_of_nat_coe, sub_sub (n:\u2124)],\n  apply eq_neg_of_eq_neg,\n  rw [neg_sub, sub_sub_self, add_right_comm],\n  exact @congr_arg \u2115 \u2124 _ _ (\u03bbi, (i + 1 : \u2124)) (nat.mod_add_div _ _).symm\nend\n\ntheorem mod_add_div : \u2200 (a b : \u2124), a % b + b * (a / b) = a\n| (m : \u2115) 0       := congr_arg of_nat (nat.mod_add_div _ _)\n| (m : \u2115) (n+1:\u2115) := congr_arg of_nat (nat.mod_add_div _ _)\n| 0       -[1+ n] := by simp\n| (m+1:\u2115) -[1+ n] := show (_ + -(n+1) * -((m + 1) / (n + 1) : \u2115) : \u2124) = _,\n  by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _)\n| -[1+ m] 0       := by rw [mod_zero, int.div_zero]; refl\n| -[1+ m] (n+1:\u2115) := mod_add_div_aux m n.succ\n| -[1+ m] -[1+ n] := mod_add_div_aux m n.succ\n\ntheorem div_add_mod (a b : \u2124) : b * (a / b) + a % b = a :=\n(add_comm _ _).trans (mod_add_div _ _)\n\nlemma mod_add_div' (m k : \u2124) : m % k + (m / k) * k = m :=\nby { rw mul_comm, exact mod_add_div _ _ }\n\nlemma div_add_mod' (m k : \u2124) : (m / k) * k + m % k = m :=\nby { rw mul_comm, exact div_add_mod _ _ }\n\ntheorem mod_def (a b : \u2124) : a % b = a - b * (a / b) :=\neq_sub_of_add_eq (mod_add_div _ _)\n\n@[simp] theorem add_mul_mod_self {a b c : \u2124} : (a + b * c) % c = a % c :=\nif cz : c = 0 then by rw [cz, mul_zero, add_zero] else\nby rw [mod_def, mod_def, int.add_mul_div_right _ _ cz,\n       mul_add, mul_comm, add_sub_add_right_eq_sub]\n\n@[simp] theorem add_mul_mod_self_left (a b c : \u2124) : (a + b * c) % b = a % b :=\nby rw [mul_comm, add_mul_mod_self]\n\n@[simp] theorem add_mod_self {a b : \u2124} : (a + b) % b = a % b :=\nby have := add_mul_mod_self_left a b 1; rwa mul_one at this\n\n@[simp] theorem add_mod_self_left {a b : \u2124} : (a + b) % a = b % a :=\nby rw [add_comm, add_mod_self]\n\n@[simp] theorem mod_add_mod (m n k : \u2124) : (m % n + k) % n = (m + k) % n :=\nby have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm;\n   rwa [add_right_comm, mod_add_div] at this\n\n@[simp] theorem add_mod_mod (m n k : \u2124) : (m + n % k) % k = (m + n) % k :=\nby rw [add_comm, mod_add_mod, add_comm]\n\nlemma add_mod (a b n : \u2124) : (a + b) % n = ((a % n) + (b % n)) % n :=\nby rw [add_mod_mod, mod_add_mod]\n\ntheorem add_mod_eq_add_mod_right {m n k : \u2124} (i : \u2124) (H : m % n = k % n) :\n  (m + i) % n = (k + i) % n :=\nby rw [\u2190 mod_add_mod, \u2190 mod_add_mod k, H]\n\ntheorem add_mod_eq_add_mod_left {m n k : \u2124} (i : \u2124) (H : m % n = k % n) :\n  (i + m) % n = (i + k) % n :=\nby rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm]\n\ntheorem mod_add_cancel_right {m n k : \u2124} (i) : (m + i) % n = (k + i) % n \u2194\n  m % n = k % n :=\n\u27e8\u03bb H, by have := add_mod_eq_add_mod_right (-i) H;\n      rwa [add_neg_cancel_right, add_neg_cancel_right] at this,\n add_mod_eq_add_mod_right _\u27e9\n\ntheorem mod_add_cancel_left {m n k i : \u2124} :\n  (i + m) % n = (i + k) % n \u2194 m % n = k % n :=\nby rw [add_comm, add_comm i, mod_add_cancel_right]\n\ntheorem mod_sub_cancel_right {m n k : \u2124} (i) : (m - i) % n = (k - i) % n \u2194\n  m % n = k % n :=\nmod_add_cancel_right _\n\ntheorem mod_eq_mod_iff_mod_sub_eq_zero {m n k : \u2124} : m % n = k % n \u2194 (m - k) % n = 0 :=\n(mod_sub_cancel_right k).symm.trans $ by simp\n\n@[simp] theorem mul_mod_left (a b : \u2124) : (a * b) % b = 0 :=\nby rw [\u2190 zero_add (a * b), add_mul_mod_self, zero_mod]\n\n@[simp] theorem mul_mod_right (a b : \u2124) : (a * b) % a = 0 :=\nby rw [mul_comm, mul_mod_left]\n\nlemma mul_mod (a b n : \u2124) : (a * b) % n = ((a % n) * (b % n)) % n :=\nbegin\n  conv_lhs {\n    rw [\u2190mod_add_div a n, \u2190mod_add_div' b n, right_distrib, left_distrib, left_distrib,\n        mul_assoc, mul_assoc, \u2190left_distrib n _ _, add_mul_mod_self_left, \u2190 mul_assoc,\n        add_mul_mod_self] }\nend\n\n@[simp] lemma neg_mod_two (i : \u2124) : (-i) % 2 = i % 2 :=\nbegin\n  apply int.mod_eq_mod_iff_mod_sub_eq_zero.mpr,\n  convert int.mul_mod_right 2 (-i),\n  simp only [two_mul, sub_eq_add_neg]\nend\n\nlocal attribute [simp] -- Will be generalized to Euclidean domains.\ntheorem mod_self {a : \u2124} : a % a = 0 :=\nby have := mul_mod_left 1 a; rwa one_mul at this\n\n@[simp] theorem mod_mod_of_dvd (n : int) {m k : int} (h : m \u2223 k) : n % k % m = n % m :=\nbegin\n  conv { to_rhs, rw \u2190mod_add_div n k },\n  rcases h with \u27e8t, rfl\u27e9, rw [mul_assoc, add_mul_mod_self_left]\nend\n\n@[simp] theorem mod_mod (a b : \u2124) : a % b % b = a % b :=\nby conv {to_rhs, rw [\u2190 mod_add_div a b, add_mul_mod_self_left]}\n\nlemma sub_mod (a b n : \u2124) : (a - b) % n = ((a % n) - (b % n)) % n :=\nbegin\n  apply (mod_add_cancel_right b).mp,\n  rw [sub_add_cancel, \u2190 add_mod_mod, sub_add_cancel, mod_mod]\nend\n\n/-! ### properties of `/` and `%` -/\n\n@[simp] theorem mul_div_mul_of_pos {a : \u2124} (b c : \u2124) (H : 0 < a) : a * b / (a * c) = b / c :=\nsuffices \u2200 (m k : \u2115) (b : \u2124), (m.succ * b / (m.succ * k) : \u2124) = b / k, from\nmatch a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with\n| ._, \u27e8m, rfl\u27e9, ._, \u27e8k, or.inl rfl\u27e9 := this _ _ _\n| ._, \u27e8m, rfl\u27e9, ._, \u27e8k, or.inr rfl\u27e9 :=\n  by rw [\u2190 neg_mul_eq_mul_neg, int.div_neg, int.div_neg];\n     apply congr_arg has_neg.neg; apply this\nend,\n\u03bb m k b, match b, k with\n| (n : \u2115), k   := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos)\n| -[1+ n], 0   := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero]\n| -[1+ n], k+1 := congr_arg neg_succ_of_nat $\n  show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin\n    apply nat.div_eq_of_lt_le,\n    { refine le_trans _ (nat.le_add_right _ _),\n      rw [\u2190 nat.mul_div_mul _ _ m.succ_pos],\n      apply nat.div_mul_le_self },\n    { change m.succ * n.succ \u2264 _,\n      rw [mul_left_comm],\n      apply nat.mul_le_mul_left,\n      apply (nat.div_lt_iff_lt_mul _ _ k.succ_pos).1,\n      apply nat.lt_succ_self }\n  end\nend\n\n@[simp] theorem mul_div_mul_of_pos_left (a : \u2124) {b : \u2124} (c : \u2124) (H : 0 < b) :\n  a * b / (c * b) = a / c :=\nby rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H]\n\n@[simp] theorem mul_mod_mul_of_pos {a : \u2124} (b c : \u2124) (H : 0 < a) : a * b % (a * c) = a * (b % c) :=\nby rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc]\n\ntheorem lt_div_add_one_mul_self (a : \u2124) {b : \u2124} (H : 0 < b) : a < (a / b + 1) * b :=\nby { rw [add_mul, one_mul, mul_comm, \u2190 sub_lt_iff_lt_add', \u2190 mod_def],\n  exact mod_lt_of_pos _ H }\n\ntheorem abs_div_le_abs : \u2200 (a b : \u2124), abs (a / b) \u2264 abs a :=\nsuffices \u2200 (a : \u2124) (n : \u2115), abs (a / n) \u2264 abs a, from\n\u03bb a b, match b, eq_coe_or_neg b with\n| ._, \u27e8n, or.inl rfl\u27e9 := this _ _\n| ._, \u27e8n, or.inr rfl\u27e9 := by rw [int.div_neg, abs_neg]; apply this\nend,\n\u03bb a n, by rw [abs_eq_nat_abs, abs_eq_nat_abs]; exact\ncoe_nat_le_coe_nat_of_le (match a, n with\n| (m : \u2115), n := nat.div_le_self _ _\n| -[1+ m], 0 := nat.zero_le _\n| -[1+ m], n+1 := nat.succ_le_succ (nat.div_le_self _ _)\nend)\n\ntheorem div_le_self {a : \u2124} (b : \u2124) (Ha : 0 \u2264 a) : a / b \u2264 a :=\nby have := le_trans (le_abs_self _) (abs_div_le_abs a b);\n   rwa [abs_of_nonneg Ha] at this\n\ntheorem mul_div_cancel_of_mod_eq_zero {a b : \u2124} (H : a % b = 0) : b * (a / b) = a :=\nby have := mod_add_div a b; rwa [H, zero_add] at this\n\ntheorem div_mul_cancel_of_mod_eq_zero {a b : \u2124} (H : a % b = 0) : a / b * b = a :=\nby rw [mul_comm, mul_div_cancel_of_mod_eq_zero H]\n\nlemma mod_two_eq_zero_or_one (n : \u2124) : n % 2 = 0 \u2228 n % 2 = 1 :=\nhave h : n % 2 < 2 := abs_of_nonneg (show 0 \u2264 (2 : \u2124), from dec_trivial) \u25b8 int.mod_lt _ dec_trivial,\nhave h\u2081 : 0 \u2264 n % 2 := int.mod_nonneg _ dec_trivial,\nmatch (n % 2), h, h\u2081 with\n| (0 : \u2115) := \u03bb _ _, or.inl rfl\n| (1 : \u2115) := \u03bb _ _, or.inr rfl\n| (k + 2 : \u2115) := \u03bb h _, absurd h dec_trivial\n| -[1+ a] := \u03bb _ h\u2081, absurd h\u2081 dec_trivial\nend\n\n/-! ### dvd -/\n\n@[norm_cast] theorem coe_nat_dvd {m n : \u2115} : (\u2191m : \u2124) \u2223 \u2191n \u2194 m \u2223 n :=\n\u27e8\u03bb \u27e8a, ae\u27e9, m.eq_zero_or_pos.elim\n  (\u03bbm0, by simp [m0] at ae; simp [ae, m0])\n  (\u03bbm0l, by {\n    cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_left \u2124 _ m a\n      (by simp [ae.symm]) (by simpa using m0l)) with k e,\n    subst a, exact \u27e8k, int.coe_nat_inj ae\u27e9 }),\n \u03bb \u27e8k, e\u27e9, dvd.intro k $ by rw [e, int.coe_nat_mul]\u27e9\n\ntheorem coe_nat_dvd_left {n : \u2115} {z : \u2124} : (\u2191n : \u2124) \u2223 z \u2194 n \u2223 z.nat_abs :=\nby rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]\n\ntheorem coe_nat_dvd_right {n : \u2115} {z : \u2124} : z \u2223 (\u2191n : \u2124) \u2194 z.nat_abs \u2223 n :=\nby rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]\n\ntheorem dvd_antisymm {a b : \u2124} (H1 : 0 \u2264 a) (H2 : 0 \u2264 b) : a \u2223 b \u2192 b \u2223 a \u2192 a = b :=\nbegin\n  rw [\u2190 abs_of_nonneg H1, \u2190 abs_of_nonneg H2, abs_eq_nat_abs, abs_eq_nat_abs],\n  rw [coe_nat_dvd, coe_nat_dvd, coe_nat_inj'],\n  apply nat.dvd_antisymm\nend\n\ntheorem dvd_of_mod_eq_zero {a b : \u2124} (H : b % a = 0) : a \u2223 b :=\n\u27e8b / a, (mul_div_cancel_of_mod_eq_zero H).symm\u27e9\n\ntheorem mod_eq_zero_of_dvd : \u2200 {a b : \u2124}, a \u2223 b \u2192 b % a = 0\n| a ._ \u27e8c, rfl\u27e9 := mul_mod_right _ _\n\ntheorem dvd_iff_mod_eq_zero (a b : \u2124) : a \u2223 b \u2194 b % a = 0 :=\n\u27e8mod_eq_zero_of_dvd, dvd_of_mod_eq_zero\u27e9\n\n/-- If `a % b = c` then `b` divides `a - c`. -/\nlemma dvd_sub_of_mod_eq {a b c : \u2124} (h : a % b = c) : b \u2223 a - c :=\nbegin\n  have hx : a % b % b = c % b, { rw h },\n  rw [mod_mod, \u2190mod_sub_cancel_right c, sub_self, zero_mod] at hx,\n  exact dvd_of_mod_eq_zero hx\nend\n\ntheorem nat_abs_dvd {a b : \u2124} : (a.nat_abs : \u2124) \u2223 b \u2194 a \u2223 b :=\n(nat_abs_eq a).elim (\u03bb e, by rw \u2190 e) (\u03bb e, by rw [\u2190 neg_dvd_iff_dvd, \u2190 e])\n\ntheorem dvd_nat_abs {a b : \u2124} : a \u2223 b.nat_abs \u2194 a \u2223 b :=\n(nat_abs_eq b).elim (\u03bb e, by rw \u2190 e) (\u03bb e, by rw [\u2190 dvd_neg_iff_dvd, \u2190 e])\n\ninstance decidable_dvd : @decidable_rel \u2124 (\u2223) :=\nassume a n, decidable_of_decidable_of_iff (by apply_instance) (dvd_iff_mod_eq_zero _ _).symm\n\nprotected theorem div_mul_cancel {a b : \u2124} (H : b \u2223 a) : a / b * b = a :=\ndiv_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H)\n\nprotected theorem mul_div_cancel' {a b : \u2124} (H : a \u2223 b) : a * (b / a) = b :=\nby rw [mul_comm, int.div_mul_cancel H]\n\nprotected theorem mul_div_assoc (a : \u2124) : \u2200 {b c : \u2124}, c \u2223 b \u2192 (a * b) / c = a * (b / c)\n| ._ c \u27e8d, rfl\u27e9 := if cz : c = 0 then by simp [cz] else\n  by rw [mul_left_comm, int.mul_div_cancel_left _ cz, int.mul_div_cancel_left _ cz]\n\nprotected theorem mul_div_assoc' (b : \u2124) {a c : \u2124} (h : c \u2223 a) : a * b / c = a / c * b :=\nby rw [mul_comm, int.mul_div_assoc _ h, mul_comm]\n\ntheorem div_dvd_div : \u2200 {a b c : \u2124} (H1 : a \u2223 b) (H2 : b \u2223 c), b / a \u2223 c / a\n| a ._ ._ \u27e8b, rfl\u27e9 \u27e8c, rfl\u27e9 := if az : a = 0 then by simp [az] else\n  by rw [int.mul_div_cancel_left _ az, mul_assoc, int.mul_div_cancel_left _ az];\n     apply dvd_mul_right\n\nprotected theorem eq_mul_of_div_eq_right {a b c : \u2124} (H1 : b \u2223 a) (H2 : a / b = c) :\n  a = b * c :=\nby rw [\u2190 H2, int.mul_div_cancel' H1]\n\nprotected theorem div_eq_of_eq_mul_right {a b c : \u2124} (H1 : b \u2260 0) (H2 : a = b * c) :\n  a / b = c :=\nby rw [H2, int.mul_div_cancel_left _ H1]\n\nprotected theorem eq_div_of_mul_eq_right {a b c : \u2124} (H1 : a \u2260 0) (H2 : a * b = c) :\n  b = c / a :=\neq.symm $ int.div_eq_of_eq_mul_right H1 H2.symm\n\nprotected theorem div_eq_iff_eq_mul_right {a b c : \u2124} (H : b \u2260 0) (H' : b \u2223 a) :\n  a / b = c \u2194 a = b * c :=\n\u27e8int.eq_mul_of_div_eq_right H', int.div_eq_of_eq_mul_right H\u27e9\n\nprotected theorem div_eq_iff_eq_mul_left {a b c : \u2124} (H : b \u2260 0) (H' : b \u2223 a) :\n  a / b = c \u2194 a = c * b :=\nby rw mul_comm; exact int.div_eq_iff_eq_mul_right H H'\n\nprotected theorem eq_mul_of_div_eq_left {a b c : \u2124} (H1 : b \u2223 a) (H2 : a / b = c) :\n  a = c * b :=\nby rw [mul_comm, int.eq_mul_of_div_eq_right H1 H2]\n\nprotected theorem div_eq_of_eq_mul_left {a b c : \u2124} (H1 : b \u2260 0) (H2 : a = c * b) :\n  a / b = c :=\nint.div_eq_of_eq_mul_right H1 (by rw [mul_comm, H2])\n\ntheorem neg_div_of_dvd : \u2200 {a b : \u2124} (H : b \u2223 a), -a / b = -(a / b)\n| ._ b \u27e8c, rfl\u27e9 := if bz : b = 0 then by simp [bz] else\n  by rw [neg_mul_eq_mul_neg, int.mul_div_cancel_left _ bz, int.mul_div_cancel_left _ bz]\n\nlemma sub_div_of_dvd {a b c : \u2124} (hcb : c \u2223 b) : (a - b) / c = a / c - b / c :=\nbegin\n  rw [sub_eq_add_neg, sub_eq_add_neg, int.add_div_of_dvd_right ((dvd_neg c b).mpr hcb)],\n  congr,\n  exact neg_div_of_dvd hcb,\nend\n\nlemma sub_div_of_dvd_sub {a b c : \u2124} (hcab : c \u2223 (a - b)) : (a - b) / c = a / c - b / c :=\nby rw [eq_sub_iff_add_eq, \u2190 int.add_div_of_dvd_left hcab, sub_add_cancel]\n\ntheorem div_sign : \u2200 a b, a / sign b = a * sign b\n| a (n+1:\u2115) := by unfold sign; simp\n| a 0       := by simp [sign]\n| a -[1+ n] := by simp [sign]\n\n@[simp] theorem sign_mul : \u2200 a b, sign (a * b) = sign a * sign b\n| a       0       := by simp\n| 0       b       := by simp\n| (m+1:\u2115) (n+1:\u2115) := rfl\n| (m+1:\u2115) -[1+ n] := rfl\n| -[1+ m] (n+1:\u2115) := rfl\n| -[1+ m] -[1+ n] := rfl\n\nprotected theorem sign_eq_div_abs (a : \u2124) : sign a = a / (abs a) :=\nif az : a = 0 then by simp [az] else\n(int.div_eq_of_eq_mul_left (mt abs_eq_zero.1 az)\n  (sign_mul_abs _).symm).symm\n\ntheorem mul_sign : \u2200 (i : \u2124), i * sign i = nat_abs i\n| (n+1:\u2115) := mul_one _\n| 0       := mul_zero _\n| -[1+ n] := mul_neg_one _\n\ntheorem le_of_dvd {a b : \u2124} (bpos : 0 < b) (H : a \u2223 b) : a \u2264 b :=\nmatch a, b, eq_succ_of_zero_lt bpos, H with\n| (m : \u2115), ._, \u27e8n, rfl\u27e9, H := coe_nat_le_coe_nat_of_le $\n  nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H\n| -[1+ m], ._, \u27e8n, rfl\u27e9, _ :=\n  le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _)\nend\n\ntheorem eq_one_of_dvd_one {a : \u2124} (H : 0 \u2264 a) (H' : a \u2223 1) : a = 1 :=\nmatch a, eq_coe_of_zero_le H, H' with\n| ._, \u27e8n, rfl\u27e9, H' := congr_arg coe $\n  nat.eq_one_of_dvd_one $ coe_nat_dvd.1 H'\nend\n\ntheorem eq_one_of_mul_eq_one_right {a b : \u2124} (H : 0 \u2264 a) (H' : a * b = 1) : a = 1 :=\neq_one_of_dvd_one H \u27e8b, H'.symm\u27e9\n\ntheorem eq_one_of_mul_eq_one_left {a b : \u2124} (H : 0 \u2264 b) (H' : a * b = 1) : b = 1 :=\neq_one_of_mul_eq_one_right H (by rw [mul_comm, H'])\n\nlemma of_nat_dvd_of_dvd_nat_abs {a : \u2115} : \u2200 {z : \u2124} (haz : a \u2223 z.nat_abs), \u2191a \u2223 z\n| (int.of_nat _) haz := int.coe_nat_dvd.2 haz\n| -[1+k] haz :=\n  begin\n    change \u2191a \u2223 -(k+1 : \u2124),\n    apply dvd_neg_of_dvd,\n    apply int.coe_nat_dvd.2,\n    exact haz\n  end\n\nlemma dvd_nat_abs_of_of_nat_dvd {a : \u2115} : \u2200 {z : \u2124} (haz : \u2191a \u2223 z), a \u2223 z.nat_abs\n| (int.of_nat _) haz := int.coe_nat_dvd.1 (int.dvd_nat_abs.2 haz)\n| -[1+k] haz :=\n  have haz' : (\u2191a:\u2124) \u2223 (\u2191(k+1):\u2124), from dvd_of_dvd_neg haz,\n  int.coe_nat_dvd.1 haz'\n\nlemma pow_dvd_of_le_of_pow_dvd {p m n : \u2115} {k : \u2124} (hmn : m \u2264 n) (hdiv : \u2191(p ^ n) \u2223 k) :\n      \u2191(p ^ m) \u2223 k :=\nbegin\n  induction k,\n    { apply int.coe_nat_dvd.2,\n      apply pow_dvd_of_le_of_pow_dvd hmn,\n      apply int.coe_nat_dvd.1 hdiv },\n    { change -[1+k] with -(\u2191(k+1) : \u2124),\n      apply dvd_neg_of_dvd,\n      apply int.coe_nat_dvd.2,\n      apply pow_dvd_of_le_of_pow_dvd hmn,\n      apply int.coe_nat_dvd.1,\n      apply dvd_of_dvd_neg,\n      exact hdiv }\nend\n\nlemma dvd_of_pow_dvd {p k : \u2115} {m : \u2124} (hk : 1 \u2264 k) (hpk : \u2191(p^k) \u2223 m) : \u2191p \u2223 m :=\nby rw \u2190pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk\n\n/-- If `n > 0` then `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)`\n  for some `k`. -/\nlemma exists_lt_and_lt_iff_not_dvd (m : \u2124) {n : \u2124} (hn : 0 < n) :\n  (\u2203 k, n * k < m \u2227 m < n * (k + 1)) \u2194 \u00ac n \u2223 m :=\nbegin\n  split,\n  { rintro \u27e8k, h1k, h2k\u27e9 \u27e8l, rfl\u27e9, rw [mul_lt_mul_left hn] at h1k h2k,\n    rw [lt_add_one_iff, \u2190 not_lt] at h2k, exact h2k h1k },\n  { intro h, rw [dvd_iff_mod_eq_zero, \u2190 ne.def] at h,\n    have := (mod_nonneg m hn.ne.symm).lt_of_ne h.symm,\n    simp only [\u2190 mod_add_div m n] {single_pass := tt},\n    refine \u27e8m / n, lt_add_of_pos_left _ this, _\u27e9,\n    rw [add_comm _ (1 : \u2124), left_distrib, mul_one], exact add_lt_add_right (mod_lt_of_pos _ hn) _ }\nend\n\n/-! ### `/` and ordering -/\n\nprotected theorem div_mul_le (a : \u2124) {b : \u2124} (H : b \u2260 0) : a / b * b \u2264 a :=\nle_of_sub_nonneg $ by rw [mul_comm, \u2190 mod_def]; apply mod_nonneg _ H\n\nprotected theorem div_le_of_le_mul {a b c : \u2124} (H : 0 < c) (H' : a \u2264 b * c) : a / c \u2264 b :=\nle_of_mul_le_mul_right (le_trans (int.div_mul_le _ (ne_of_gt H)) H') H\n\nprotected theorem mul_lt_of_lt_div {a b c : \u2124} (H : 0 < c) (H3 : a < b / c) : a * c < b :=\nlt_of_not_ge $ mt (int.div_le_of_le_mul H) (not_le_of_gt H3)\n\nprotected theorem mul_le_of_le_div {a b c : \u2124} (H1 : 0 < c) (H2 : a \u2264 b / c) : a * c \u2264 b :=\nle_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le _ (ne_of_gt H1))\n\nprotected theorem le_div_of_mul_le {a b c : \u2124} (H1 : 0 < c) (H2 : a * c \u2264 b) : a \u2264 b / c :=\nle_of_lt_add_one $ lt_of_mul_lt_mul_right\n  (lt_of_le_of_lt H2 (lt_div_add_one_mul_self _ H1)) (le_of_lt H1)\n\nprotected theorem le_div_iff_mul_le {a b c : \u2124} (H : 0 < c) : a \u2264 b / c \u2194 a * c \u2264 b :=\n\u27e8int.mul_le_of_le_div H, int.le_div_of_mul_le H\u27e9\n\nprotected theorem div_le_div {a b c : \u2124} (H : 0 < c) (H' : a \u2264 b) : a / c \u2264 b / c :=\nint.le_div_of_mul_le H (le_trans (int.div_mul_le _ (ne_of_gt H)) H')\n\nprotected theorem div_lt_of_lt_mul {a b c : \u2124} (H : 0 < c) (H' : a < b * c) : a / c < b :=\nlt_of_not_ge $ mt (int.mul_le_of_le_div H) (not_le_of_gt H')\n\nprotected theorem lt_mul_of_div_lt {a b c : \u2124} (H1 : 0 < c) (H2 : a / c < b) : a < b * c :=\nlt_of_not_ge $ mt (int.le_div_of_mul_le H1) (not_le_of_gt H2)\n\nprotected theorem div_lt_iff_lt_mul {a b c : \u2124} (H : 0 < c) : a / c < b \u2194 a < b * c :=\n\u27e8int.lt_mul_of_div_lt H, int.div_lt_of_lt_mul H\u27e9\n\nprotected theorem le_mul_of_div_le {a b c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 a) (H3 : a / b \u2264 c) :\n  a \u2264 c * b :=\nby rw [\u2190 int.div_mul_cancel H2]; exact mul_le_mul_of_nonneg_right H3 H1\n\nprotected theorem lt_div_of_mul_lt {a b c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 c) (H3 : a * b < c) :\n  a < c / b :=\nlt_of_not_ge $ mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3)\n\nprotected theorem lt_div_iff_mul_lt {a b : \u2124} (c : \u2124) (H : 0 < c) (H' : c \u2223 b) :\n  a < b / c \u2194 a * c < b :=\n\u27e8int.mul_lt_of_lt_div H, int.lt_div_of_mul_lt (le_of_lt H) H'\u27e9\n\ntheorem div_pos_of_pos_of_dvd {a b : \u2124} (H1 : 0 < a) (H2 : 0 \u2264 b) (H3 : b \u2223 a) : 0 < a / b :=\nint.lt_div_of_mul_lt H2 H3 (by rwa zero_mul)\n\ntheorem div_eq_div_of_mul_eq_mul {a b c d : \u2124} (H2 : d \u2223 c) (H3 : b \u2260 0)\n    (H4 : d \u2260 0) (H5 : a * d = b * c) :\n  a / b = c / d :=\nint.div_eq_of_eq_mul_right H3 $\nby rw [\u2190 int.mul_div_assoc _ H2]; exact\n(int.div_eq_of_eq_mul_left H4 H5.symm).symm\n\ntheorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : \u2124} (hb : b \u2260 0) (hbc : b \u2223 c)\n      (h : b * a = c * d) : a = c / b * d :=\nbegin\n  cases hbc with k hk,\n  subst hk,\n  rw [int.mul_div_cancel_left _ hb],\n  rw mul_assoc at h,\n  apply mul_left_cancel' hb h\nend\n\n/-- If an integer with larger absolute value divides an integer, it is\nzero. -/\nlemma eq_zero_of_dvd_of_nat_abs_lt_nat_abs {a b : \u2124} (w : a \u2223 b) (h : nat_abs b < nat_abs a) :\n  b = 0 :=\nbegin\n  rw [\u2190nat_abs_dvd, \u2190dvd_nat_abs, coe_nat_dvd] at w,\n  rw \u2190nat_abs_eq_zero,\n  exact eq_zero_of_dvd_of_lt w h\nend\n\nlemma eq_zero_of_dvd_of_nonneg_of_lt {a b : \u2124} (w\u2081 : 0 \u2264 a) (w\u2082 : a < b) (h : b \u2223 a) : a = 0 :=\neq_zero_of_dvd_of_nat_abs_lt_nat_abs h (nat_abs_lt_nat_abs_of_nonneg_of_lt w\u2081 w\u2082)\n\n/-- If two integers are congruent to a sufficiently large modulus,\nthey are equal. -/\nlemma eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs {a b c : \u2124} (h1 : a % b = c)\n    (h2 : nat_abs (a - c) < nat_abs b) :\n  a = c :=\neq_of_sub_eq_zero (eq_zero_of_dvd_of_nat_abs_lt_nat_abs (dvd_sub_of_mod_eq h1) h2)\n\ntheorem of_nat_add_neg_succ_of_nat_of_lt {m n : \u2115}\n  (h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] :=\nbegin\n change sub_nat_nat _ _ = _,\n have h' : n.succ - m = (n - m).succ,\n apply succ_sub,\n apply le_of_lt_succ h,\n simp [*, sub_nat_nat]\nend\n\ntheorem of_nat_add_neg_succ_of_nat_of_ge {m n : \u2115}\n  (h : n.succ \u2264 m) : of_nat m + -[1+n] = of_nat (m - n.succ) :=\nbegin\n change sub_nat_nat _ _ = _,\n have h' : n.succ - m = 0,\n apply sub_eq_zero_of_le h,\n simp [*, sub_nat_nat]\nend\n\n@[simp] theorem neg_add_neg (m n : \u2115) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl\n\n/-! ### to_nat -/\n\ntheorem to_nat_eq_max : \u2200 (a : \u2124), (to_nat a : \u2124) = max a 0\n| (n : \u2115) := (max_eq_left (coe_zero_le n)).symm\n| -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm\n\n@[simp] lemma to_nat_zero : (0 : \u2124).to_nat = 0 := rfl\n\n@[simp] lemma to_nat_one : (1 : \u2124).to_nat = 1 := rfl\n\n@[simp] theorem to_nat_of_nonneg {a : \u2124} (h : 0 \u2264 a) : (to_nat a : \u2124) = a :=\nby rw [to_nat_eq_max, max_eq_left h]\n\n@[simp] lemma to_nat_sub_of_le (a b : \u2124) (h : b \u2264 a) : (to_nat (a + -b) : \u2124) = a + - b :=\nint.to_nat_of_nonneg (sub_nonneg_of_le h)\n\n@[simp] theorem to_nat_coe_nat (n : \u2115) : to_nat \u2191n = n := rfl\n\n@[simp] lemma to_nat_coe_nat_add_one {n : \u2115} : ((n : \u2124) + 1).to_nat = n + 1 := rfl\n\ntheorem le_to_nat (a : \u2124) : a \u2264 to_nat a :=\nby rw [to_nat_eq_max]; apply le_max_left\n\n@[simp] theorem to_nat_le {a : \u2124} {n : \u2115} : to_nat a \u2264 n \u2194 a \u2264 n :=\nby rw [(coe_nat_le_coe_nat_iff _ _).symm, to_nat_eq_max, max_le_iff];\n   exact and_iff_left (coe_zero_le _)\n\n@[simp] theorem lt_to_nat {n : \u2115} {a : \u2124} : n < to_nat a \u2194 (n : \u2124) < a :=\nle_iff_le_iff_lt_iff_lt.1 to_nat_le\n\ntheorem to_nat_le_to_nat {a b : \u2124} (h : a \u2264 b) : to_nat a \u2264 to_nat b :=\nby rw to_nat_le; exact le_trans h (le_to_nat b)\n\ntheorem to_nat_lt_to_nat {a b : \u2124} (hb : 0 < b) : to_nat a < to_nat b \u2194 a < b :=\n\u27e8\u03bb h, begin cases a, exact lt_to_nat.1 h, exact lt_trans (neg_succ_of_nat_lt_zero a) hb, end,\n \u03bb h, begin rw lt_to_nat, cases a, exact h, exact hb end\u27e9\n\ntheorem lt_of_to_nat_lt {a b : \u2124} (h : to_nat a < to_nat b) : a < b :=\n(to_nat_lt_to_nat $ lt_to_nat.1 $ lt_of_le_of_lt (nat.zero_le _) h).1 h\n\nlemma to_nat_add {a b : \u2124} (ha : 0 \u2264 a) (hb : 0 \u2264 b) :\n  (a + b).to_nat = a.to_nat + b.to_nat :=\nbegin\n  lift a to \u2115 using ha,\n  lift b to \u2115 using hb,\n  norm_cast,\nend\n\nlemma to_nat_add_one {a : \u2124} (h : 0 \u2264 a) : (a + 1).to_nat = a.to_nat + 1 :=\nto_nat_add h (zero_le_one)\n\n@[simp]\nlemma pred_to_nat : \u2200 (i : \u2124), (i - 1).to_nat = i.to_nat - 1\n| (0:\u2115)   := rfl\n| (n+1:\u2115) := by simp\n| -[1+ n] := rfl\n\n@[simp]\nlemma to_nat_pred_coe_of_pos {i : \u2124} (h : 0 < i) : ((i.to_nat - 1 : \u2115) : \u2124) = i - 1 :=\nby simp [h, le_of_lt h] with push_cast\n\n/-- If `n : \u2115`, then `int.to_nat' n = some n`, if `n : \u2124` is negative, then `int.to_nat' n = none`.\n-/\ndef to_nat' : \u2124 \u2192 option \u2115\n| (n : \u2115) := some n\n| -[1+ n] := none\n\ntheorem mem_to_nat' : \u2200 (a : \u2124) (n : \u2115), n \u2208 to_nat' a \u2194 a = n\n| (m : \u2115) n := option.some_inj.trans coe_nat_inj'.symm\n| -[1+ m] n := by split; intro h; cases h\n\nlemma to_nat_zero_of_neg : \u2200 {z : \u2124}, z < 0 \u2192 z.to_nat = 0\n| (-[1+n]) _ := rfl\n| (int.of_nat n) h := (not_le_of_gt h $ int.of_nat_nonneg n).elim\n\n/-! ### units -/\n\n@[simp] theorem units_nat_abs (u : units \u2124) : nat_abs u = 1 :=\nunits.ext_iff.1 $ nat.units_eq_one \u27e8nat_abs u, nat_abs \u2191u\u207b\u00b9,\n  by rw [\u2190 nat_abs_mul, units.mul_inv]; refl,\n  by rw [\u2190 nat_abs_mul, units.inv_mul]; refl\u27e9\n\ntheorem units_eq_one_or (u : units \u2124) : u = 1 \u2228 u = -1 :=\nby simpa only [units.ext_iff, units_nat_abs] using nat_abs_eq u\n\nlemma is_unit_eq_one_or {a : \u2124} : is_unit a \u2192 a = 1 \u2228 a = -1\n| \u27e8x, hx\u27e9 := hx \u25b8 (units_eq_one_or _).imp (congr_arg coe) (congr_arg coe)\n\nlemma is_unit_iff {a : \u2124} : is_unit a \u2194 a = 1 \u2228 a = -1 :=\nbegin\n  refine \u27e8\u03bb h, is_unit_eq_one_or h, \u03bb h, _\u27e9,\n  rcases h with rfl | rfl,\n  { exact is_unit_one },\n  { exact is_unit_one.neg }\nend\n\ntheorem is_unit_iff_nat_abs_eq {n : \u2124} : is_unit n \u2194 n.nat_abs = 1 :=\nby simp [nat_abs_eq_iff, is_unit_iff]\n\nlemma units_inv_eq_self (u : units \u2124) : u\u207b\u00b9 = u :=\n(units_eq_one_or u).elim (\u03bb h, h.symm \u25b8 rfl) (\u03bb h, h.symm \u25b8 rfl)\n\n@[simp] lemma units_mul_self (u : units \u2124) : u * u = 1 :=\n(units_eq_one_or u).elim (\u03bb h, h.symm \u25b8 rfl) (\u03bb h, h.symm \u25b8 rfl)\n\n-- `units.coe_mul` is a \"wrong turn\" for the simplifier, this undoes it and simplifies further\n@[simp] lemma units_coe_mul_self (u : units \u2124) : (u * u : \u2124) = 1 :=\nby rw [\u2190units.coe_mul, units_mul_self, units.coe_one]\n\n@[simp] lemma neg_one_pow_ne_zero {n : \u2115} : (-1 : \u2124)^n \u2260 0 :=\npow_ne_zero _ (abs_pos.mp trivial)\n\n/-! ### bitwise ops -/\n\n@[simp] lemma bodd_zero : bodd 0 = ff := rfl\n@[simp] lemma bodd_one : bodd 1 = tt := rfl\nlemma bodd_two : bodd 2 = ff := rfl\n\n@[simp, norm_cast] lemma bodd_coe (n : \u2115) : int.bodd n = nat.bodd n := rfl\n\n@[simp] lemma bodd_sub_nat_nat (m n : \u2115) : bodd (sub_nat_nat m n) = bxor m.bodd n.bodd :=\nby apply sub_nat_nat_elim m n (\u03bb m n i, bodd i = bxor m.bodd n.bodd); intros;\n  simp; cases i.bodd; simp\n\n@[simp] lemma bodd_neg_of_nat (n : \u2115) : bodd (neg_of_nat n) = n.bodd :=\nby cases n; simp; refl\n\n@[simp] lemma bodd_neg (n : \u2124) : bodd (-n) = bodd n :=\nby cases n; simp [has_neg.neg, int.coe_nat_eq, int.neg, bodd, -of_nat_eq_coe]\n\n@[simp] lemma bodd_add (m n : \u2124) : bodd (m + n) = bxor (bodd m) (bodd n) :=\nby cases m with m m; cases n with n n; unfold has_add.add;\n  simp [int.add, -of_nat_eq_coe, bool.bxor_comm]\n\n@[simp] lemma bodd_mul (m n : \u2124) : bodd (m * n) = bodd m && bodd n :=\nby cases m with m m; cases n with n n;\n  simp [\u2190 int.mul_def, int.mul, -of_nat_eq_coe, bool.bxor_comm]\n\ntheorem bodd_add_div2 : \u2200 n, cond (bodd n) 1 0 + 2 * div2 n = n\n| (n : \u2115) :=\n  by rw [show (cond (bodd n) 1 0 : \u2124) = (cond (bodd n) 1 0 : \u2115),\n         by cases bodd n; refl]; exact congr_arg of_nat n.bodd_add_div2\n| -[1+ n] := begin\n    refine eq.trans _ (congr_arg neg_succ_of_nat n.bodd_add_div2),\n    dsimp [bodd], cases nat.bodd n; dsimp [cond, bnot, div2, int.mul],\n    { change -[1+ 2 * nat.div2 n] = _, rw zero_add },\n    { rw [zero_add, add_comm], refl }\n  end\n\ntheorem div2_val : \u2200 n, div2 n = n / 2\n| (n : \u2115) := congr_arg of_nat n.div2_val\n| -[1+ n] := congr_arg neg_succ_of_nat n.div2_val\n\nlemma bit0_val (n : \u2124) : bit0 n = 2 * n := (two_mul _).symm\n\nlemma bit1_val (n : \u2124) : bit1 n = 2 * n + 1 := congr_arg (+(1:\u2124)) (bit0_val _)\n\nlemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 :=\nby { cases b, apply (bit0_val n).trans (add_zero _).symm, apply bit1_val }\n\nlemma bit_decomp (n : \u2124) : bit (bodd n) (div2 n) = n :=\n(bit_val _ _).trans $ (add_comm _ _).trans $ bodd_add_div2 _\n\n/-- Defines a function from `\u2124` conditionally, if it is defined for odd and even integers separately\n  using `bit`. -/\ndef {u} bit_cases_on {C : \u2124 \u2192 Sort u} (n) (h : \u2200 b n, C (bit b n)) : C n :=\nby rw [\u2190 bit_decomp n]; apply h\n\n@[simp] lemma bit_zero : bit ff 0 = 0 := rfl\n\n@[simp] lemma bit_coe_nat (b) (n : \u2115) : bit b n = nat.bit b n :=\nby rw [bit_val, nat.bit_val]; cases b; refl\n\n@[simp] lemma bit_neg_succ (b) (n : \u2115) : bit b -[1+ n] = -[1+ nat.bit (bnot b) n] :=\nby rw [bit_val, nat.bit_val]; cases b; refl\n\n@[simp] lemma bodd_bit (b n) : bodd (bit b n) = b :=\nby rw bit_val; simp; cases b; cases bodd n; refl\n\n@[simp] lemma bodd_bit0 (n : \u2124) : bodd (bit0 n) = ff := bodd_bit ff n\n\n@[simp] lemma bodd_bit1 (n : \u2124) : bodd (bit1 n) = tt := bodd_bit tt n\n\n@[simp] lemma div2_bit (b n) : div2 (bit b n) = n :=\nbegin\n  rw [bit_val, div2_val, add_comm, int.add_mul_div_left, (_ : (_/2:\u2124) = 0), zero_add],\n  cases b,\n  { simp },\n  { show of_nat _ = _, rw nat.div_eq_zero; simp },\n  { cc }\nend\n\nlemma bit0_ne_bit1 (m n : \u2124) : bit0 m \u2260 bit1 n :=\nmt (congr_arg bodd) $ by simp\n\nlemma bit1_ne_bit0 (m n : \u2124) : bit1 m \u2260 bit0 n :=\n(bit0_ne_bit1 _ _).symm\n\nlemma bit1_ne_zero (m : \u2124) : bit1 m \u2260 0 :=\nby simpa only [bit0_zero] using bit1_ne_bit0 m 0\n\n@[simp] lemma test_bit_zero (b) : \u2200 n, test_bit (bit b n) 0 = b\n| (n : \u2115) := by rw [bit_coe_nat]; apply nat.test_bit_zero\n| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_zero];\n                clear test_bit_zero; cases b; refl\n\n@[simp] lemma test_bit_succ (m b) : \u2200 n, test_bit (bit b n) (nat.succ m) = test_bit n m\n| (n : \u2115) := by rw [bit_coe_nat]; apply nat.test_bit_succ\n| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_succ]\n\nprivate meta def bitwise_tac : tactic unit := `[\n  funext m,\n  funext n,\n  cases m with m m; cases n with n n; try {refl},\n  all_goals {\n    apply congr_arg of_nat <|> apply congr_arg neg_succ_of_nat,\n    try {dsimp [nat.land, nat.ldiff, nat.lor]},\n    try {rw [\n      show nat.bitwise (\u03bb a b, a && bnot b) n m =\n           nat.bitwise (\u03bb a b, b && bnot a) m n, from\n      congr_fun (congr_fun (@nat.bitwise_swap (\u03bb a b, b && bnot a) rfl) n) m]},\n    apply congr_arg (\u03bb f, nat.bitwise f m n),\n    funext a,\n    funext b,\n    cases a; cases b; refl\n  },\n  all_goals {unfold nat.land nat.ldiff nat.lor}\n]\n\ntheorem bitwise_or   : bitwise bor                  = lor   := by bitwise_tac\ntheorem bitwise_and  : bitwise band                 = land  := by bitwise_tac\ntheorem bitwise_diff : bitwise (\u03bb a b, a && bnot b) = ldiff := by bitwise_tac\ntheorem bitwise_xor  : bitwise bxor                 = lxor  := by bitwise_tac\n\n@[simp] lemma bitwise_bit (f : bool \u2192 bool \u2192 bool) (a m b n) :\n  bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=\nbegin\n  cases m with m m; cases n with n n;\n  repeat { rw [\u2190 int.coe_nat_eq] <|> rw bit_coe_nat <|> rw bit_neg_succ };\n  unfold bitwise nat_bitwise bnot;\n  [ induction h : f ff ff,\n    induction h : f ff tt,\n    induction h : f tt ff,\n    induction h : f tt tt ],\n  all_goals {\n    unfold cond, rw nat.bitwise_bit,\n    repeat { rw bit_coe_nat <|> rw bit_neg_succ <|> rw bnot_bnot } },\n  all_goals { unfold bnot {fail_if_unchanged := ff}; rw h; refl }\nend\n\n@[simp] lemma lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) :=\nby rw [\u2190 bitwise_or, bitwise_bit]\n\n@[simp] lemma land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) :=\nby rw [\u2190 bitwise_and, bitwise_bit]\n\n@[simp] lemma ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) :=\nby rw [\u2190 bitwise_diff, bitwise_bit]\n\n@[simp] lemma lxor_bit (a m b n) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) :=\nby rw [\u2190 bitwise_xor, bitwise_bit]\n\n@[simp] lemma lnot_bit (b) : \u2200 n, lnot (bit b n) = bit (bnot b) (lnot n)\n| (n : \u2115) := by simp [lnot]\n| -[1+ n] := by simp [lnot]\n\n@[simp] lemma test_bit_bitwise (f : bool \u2192 bool \u2192 bool) (m n k) :\n  test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=\nbegin\n  induction k with k IH generalizing m n;\n  apply bit_cases_on m; intros a m';\n  apply bit_cases_on n; intros b n';\n  rw bitwise_bit,\n  { simp [test_bit_zero] },\n  { simp [test_bit_succ, IH] }\nend\n\n@[simp] lemma test_bit_lor (m n k) : test_bit (lor m n) k = test_bit m k || test_bit n k :=\nby rw [\u2190 bitwise_or, test_bit_bitwise]\n\n@[simp] lemma test_bit_land (m n k) : test_bit (land m n) k = test_bit m k && test_bit n k :=\nby rw [\u2190 bitwise_and, test_bit_bitwise]\n\n@[simp]\nlemma test_bit_ldiff (m n k) : test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) :=\nby rw [\u2190 bitwise_diff, test_bit_bitwise]\n\n@[simp] lemma test_bit_lxor (m n k) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) :=\nby rw [\u2190 bitwise_xor, test_bit_bitwise]\n\n@[simp] lemma test_bit_lnot : \u2200 n k, test_bit (lnot n) k = bnot (test_bit n k)\n| (n : \u2115) k := by simp [lnot, test_bit]\n| -[1+ n] k := by simp [lnot, test_bit]\n\nlemma shiftl_add : \u2200 (m : \u2124) (n : \u2115) (k : \u2124), shiftl m (n + k) = shiftl (shiftl m n) k\n| (m : \u2115) n (k:\u2115) := congr_arg of_nat (nat.shiftl_add _ _ _)\n| -[1+ m] n (k:\u2115) := congr_arg neg_succ_of_nat (nat.shiftl'_add _ _ _ _)\n| (m : \u2115) n -[1+k] := sub_nat_nat_elim n k.succ\n    (\u03bb n k i, shiftl \u2191m i = nat.shiftr (nat.shiftl m n) k)\n    (\u03bb i n, congr_arg coe $\n      by rw [\u2190 nat.shiftl_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)\n    (\u03bb i n, congr_arg coe $\n      by rw [add_assoc, nat.shiftr_add, \u2190 nat.shiftl_sub, nat.sub_self]; refl)\n| -[1+ m] n -[1+k] := sub_nat_nat_elim n k.succ\n    (\u03bb n k i, shiftl -[1+ m] i = -[1+ nat.shiftr (nat.shiftl' tt m n) k])\n    (\u03bb i n, congr_arg neg_succ_of_nat $\n      by rw [\u2190 nat.shiftl'_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)\n    (\u03bb i n, congr_arg neg_succ_of_nat $\n      by rw [add_assoc, nat.shiftr_add, \u2190 nat.shiftl'_sub, nat.sub_self]; refl)\n\nlemma shiftl_sub (m : \u2124) (n : \u2115) (k : \u2124) : shiftl m (n - k) = shiftr (shiftl m n) k :=\nshiftl_add _ _ _\n\n@[simp] lemma shiftl_neg (m n : \u2124) : shiftl m (-n) = shiftr m n := rfl\n@[simp] lemma shiftr_neg (m n : \u2124) : shiftr m (-n) = shiftl m n := by rw [\u2190 shiftl_neg, neg_neg]\n\n@[simp] lemma shiftl_coe_nat (m n : \u2115) : shiftl m n = nat.shiftl m n := rfl\n@[simp] lemma shiftr_coe_nat (m n : \u2115) : shiftr m n = nat.shiftr m n := by cases n; refl\n\n@[simp] lemma shiftl_neg_succ (m n : \u2115) : shiftl -[1+ m] n = -[1+ nat.shiftl' tt m n] := rfl\n@[simp]\nlemma shiftr_neg_succ (m n : \u2115) : shiftr -[1+ m] n = -[1+ nat.shiftr m n] := by cases n; refl\n\nlemma shiftr_add : \u2200 (m : \u2124) (n k : \u2115), shiftr m (n + k) = shiftr (shiftr m n) k\n| (m : \u2115) n k := by rw [shiftr_coe_nat, shiftr_coe_nat,\n                        \u2190 int.coe_nat_add, shiftr_coe_nat, nat.shiftr_add]\n| -[1+ m] n k := by rw [shiftr_neg_succ, shiftr_neg_succ,\n                        \u2190 int.coe_nat_add, shiftr_neg_succ, nat.shiftr_add]\n\nlemma shiftl_eq_mul_pow : \u2200 (m : \u2124) (n : \u2115), shiftl m n = m * \u2191(2 ^ n)\n| (m : \u2115) n := congr_arg coe (nat.shiftl_eq_mul_pow _ _)\n| -[1+ m] n := @congr_arg \u2115 \u2124 _ _ (\u03bbi, -i) (nat.shiftl'_tt_eq_mul_pow _ _)\n\nlemma shiftr_eq_div_pow : \u2200 (m : \u2124) (n : \u2115), shiftr m n = m / \u2191(2 ^ n)\n| (m : \u2115) n := by rw shiftr_coe_nat; exact congr_arg coe (nat.shiftr_eq_div_pow _ _)\n| -[1+ m] n := begin\n  rw [shiftr_neg_succ, neg_succ_of_nat_div, nat.shiftr_eq_div_pow], refl,\n  exact coe_nat_lt_coe_nat_of_lt (pow_pos dec_trivial _)\nend\n\nlemma one_shiftl (n : \u2115) : shiftl 1 n = (2 ^ n : \u2115) :=\ncongr_arg coe (nat.one_shiftl _)\n\n@[simp] lemma zero_shiftl : \u2200 n : \u2124, shiftl 0 n = 0\n| (n : \u2115) := congr_arg coe (nat.zero_shiftl _)\n| -[1+ n] := congr_arg coe (nat.zero_shiftr _)\n\n@[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := zero_shiftl _\n\n/-! ### Least upper bound property for integers -/\n\nsection classical\nopen_locale classical\n\ntheorem exists_least_of_bdd {P : \u2124 \u2192 Prop}\n    (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 b \u2264 z)\n        (Hinh : \u2203 z : \u2124, P z) : \u2203 lb : \u2124, P lb \u2227 (\u2200 z : \u2124, P z \u2192 lb \u2264 z) :=\nlet \u27e8b, Hb\u27e9 := Hbdd in\nhave EX : \u2203 n : \u2115, P (b + n), from\n  let \u27e8elt, Helt\u27e9 := Hinh in\n  match elt, le.dest (Hb _ Helt), Helt with\n  | ._, \u27e8n, rfl\u27e9, Hn := \u27e8n, Hn\u27e9\n  end,\n\u27e8b + (nat.find EX : \u2124), nat.find_spec EX, \u03bb z h,\n  match z, le.dest (Hb _ h), h with\n  | ._, \u27e8n, rfl\u27e9, h := add_le_add_left\n    (int.coe_nat_le.2 $ nat.find_min' _ h) _\n  end\u27e9\n\ntheorem exists_greatest_of_bdd {P : \u2124 \u2192 Prop}\n    (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 z \u2264 b)\n        (Hinh : \u2203 z : \u2124, P z) : \u2203 ub : \u2124, P ub \u2227 (\u2200 z : \u2124, P z \u2192 z \u2264 ub) :=\nhave Hbdd' : \u2203 (b : \u2124), \u2200 (z : \u2124), P (-z) \u2192 b \u2264 z, from\nlet \u27e8b, Hb\u27e9 := Hbdd in \u27e8-b, \u03bb z h, neg_le.1 (Hb _ h)\u27e9,\nhave Hinh' : \u2203 z : \u2124, P (-z), from\nlet \u27e8elt, Helt\u27e9 := Hinh in \u27e8-elt, by rw [neg_neg]; exact Helt\u27e9,\nlet \u27e8lb, Plb, al\u27e9 := exists_least_of_bdd Hbdd' Hinh' in\n\u27e8-lb, Plb, \u03bb z h, le_neg.1 $ al _ $ by rwa neg_neg\u27e9\n\nend classical\n\nend int\n\nattribute [irreducible] int.nonneg\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/int/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7261836575559933}}
{"text": "import tactic.where\nimport tactic.ring\nimport analysis.topology.topological_space\nimport analysis.topology.topological_structures\nimport algebra.group_power\nimport ring_theory.subring\n\nuniverse u\n\nvariables {R : Type u} [comm_ring R] [topological_space R] [topological_ring R]\n\n/-- Wedhorn Definition 5.27 page 36 -/\ndefinition is_bounded (B : set R) : Prop :=\n\u2200 U \u2208 (nhds (0 : R)).sets, \u2203 V \u2208 (nhds (0 : R)).sets, \u2200 v \u2208 V, \u2200 b \u2208 B, v*b \u2208 U\n\ndefinition is_power_bounded (r : R) : Prop := is_bounded (powers r)\n\nvariable (R)\ndefinition power_bounded_subring := {r : R | is_power_bounded r}\n\nnamespace power_bounded\n\ninstance : has_coe (power_bounded_subring R) R := \u27e8subtype.val\u27e9\n\nlemma zero_mem : (0 : R) \u2208 power_bounded_subring R :=\n\u03bb U hU, \u27e8U,\nbegin\n  split, {exact hU},\n  intros v hv b H,\n  cases H with n H,\n  induction n ; { simp [H.symm, pow_succ, mem_of_nhds hU], try {assumption} }\nend\u27e9\n\nlemma one_mem : (1 : R) \u2208 power_bounded_subring R :=\n\u03bb U hU, \u27e8U,\nbegin\n  split, {exact hU},\n  intros v hv b H,\n  cases H with n H,\n  simpa [H.symm]\nend\u27e9\n\nlemma mul_mem :\n\u2200 {a b : R}, a \u2208 power_bounded_subring R \u2192 b \u2208 power_bounded_subring R \u2192 a * b \u2208 power_bounded_subring R :=\n\u03bb a b ha hb U U_nhd,\nbegin\n  rcases hb U U_nhd with \u27e8Vb, \u27e8Vb_nhd, hVb\u27e9\u27e9,\n  rcases ha Vb Vb_nhd with \u27e8Va, \u27e8Va_nhd, hVa\u27e9\u27e9,\n  clear ha hb,\n  existsi Va,\n  split, {exact Va_nhd},\n  { intros v hv x H,\n    cases H with n hx,\n    rw [\u2190 hx,\n          mul_pow,\n        \u2190 mul_assoc],\n    apply hVb (v * a^n) _ _ _,\n    apply hVa v hv _ _,\n    repeat { dsimp [powers],\n      existsi n,\n      refl } }\nend\n\nlemma neg_mem : \u2200 {a : R}, a \u2208 power_bounded_subring R \u2192 -a \u2208 power_bounded_subring R :=\n\u03bb a ha U hU,\nbegin\n  let Usymm := U \u2229 {u | -u \u2208 U},\n  let hUsymm : Usymm \u2208 (nhds (0 : R)).sets :=\n  begin\n    apply filter.inter_mem_sets hU,\n    apply continuous.tendsto (topological_add_group.continuous_neg R) 0,\n    simpa\n  end,\n  rcases ha Usymm hUsymm with \u27e8V, \u27e8V_nhd, hV\u27e9\u27e9,\n  clear hUsymm,\n  existsi V,\n  split, {exact V_nhd},\n  intros v hv b H,\n  cases H with n hb,\n  rw \u2190 hb,\n  rw show v * (-a)^n = ((-1)^n * v) * a^n,\n  begin\n    rw [neg_eq_neg_one_mul, mul_pow], ring,\n  end,\n  have H := hV v hv (a^n) _,\n  suffices : (-1)^n * v * a^n \u2208 Usymm,\n  { exact this.1 },\n  { simp,\n    cases (@neg_one_pow_eq_or R _ n) with h h;\n    { dsimp [Usymm] at H,\n      simp [h, H.1, H.2] } },\n  { dsimp [powers],\n      existsi n,\n      refl }\nend\n\ninstance submonoid : is_submonoid (power_bounded_subring R) :=\n{ one_mem := power_bounded.one_mem R,\n  mul_mem := \u03bb a b, power_bounded.mul_mem R }\n\ndefinition is_uniform : Prop := is_bounded (power_bounded_subring R)\n\nend power_bounded\n", "meta": {"author": "mr-infty", "repo": "perfectoid-spaces", "sha": "1a49b3897ec3c7b871d8c970926c00f727a4e2a6", "save_path": "github-repos/lean/mr-infty-perfectoid-spaces", "path": "github-repos/lean/mr-infty-perfectoid-spaces/perfectoid-spaces-1a49b3897ec3c7b871d8c970926c00f727a4e2a6/src/power_bounded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7261836466979419}}
{"text": "theorem not_succ_le_self (a : mynat) : \u00ac (succ a \u2264 a) :=\nbegin\nintro h,\nhave g := le_succ_self a,\nhave f := le_antisymm a (succ a) g h,\nexact ne_succ_self a f,\nend\n", "meta": {"author": "chanha-park", "repo": "naturalNumberGame", "sha": "4e0d7100ce4575e1add92feefa38b1250431b879", "save_path": "github-repos/lean/chanha-park-naturalNumberGame", "path": "github-repos/lean/chanha-park-naturalNumberGame/naturalNumberGame-4e0d7100ce4575e1add92feefa38b1250431b879/Inequality/13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9511422227627598, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7261816387916464}}
{"text": "import data.nat.basic algebra.group data.real.cau_seq\n\nopen nat is_absolute_value\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n\ndef series [has_add \u03b1] (f : \u2115 \u2192 \u03b1) : \u2115 \u2192 \u03b1\n| 0        := f 0\n| (succ i) := series i + f (succ i)\n\ndef nat.sum [has_add \u03b1] (f : \u2115 \u2192 \u03b1) (i j : \u2115) := series (\u03bb k, f (k + i)) (j - i)\n\n@[simp]\nlemma series_zero [has_add \u03b1] (f : \u2115 \u2192 \u03b1) : series f 0 = f 0 := by unfold series\n\nlemma series_succ [has_add \u03b1] (f : \u2115 \u2192 \u03b1) (i : \u2115) : series f (succ i) = series f i + f (succ i):= by unfold series\n\nlemma series_eq_sum_zero [has_add \u03b1] (f : \u2115 \u2192 \u03b1) (i : \u2115) : series f i = nat.sum f 0 i := by unfold nat.sum;simp\n\nlemma series_succ\u2081 [add_comm_monoid \u03b1] (f : \u2115 \u2192 \u03b1) (i : \u2115) : series f (succ i) = f 0 + series (\u03bb i, f (succ i)) i := begin\n induction i with i' hi,\n simp!,simp!,rw \u2190hi,simp!,\nend\n\nlemma series_comm {\u03b1 : Type*} [add_comm_monoid \u03b1] (f : \u2115 \u2192 \u03b1) (n : \u2115) : series f n = series (\u03bb i, f (n - i)) n := begin\n  induction n with n' hi,\n  simp!,simp!,rw hi,\n  have : (\u03bb (i : \u2115), f (succ n' - i)) (succ n') = f (n' - n'),simp,\n  rw \u2190this,have : (\u03bb (i : \u2115), f (succ n' - i)) (succ n') + series (\u03bb (i : \u2115), f (succ n' - i)) n' = series (\u03bb (i : \u2115), f (succ n' - i)) (succ n'),simp!,\n  rw this,\n  have : (\u03bb i, f (n' - i)) = (\u03bb i, f (succ n' - succ i)),\n   apply funext,assume i,rw succ_sub_succ,\n  rw this,clear this,\n  have : f (succ n') = (\u03bb (i : \u2115), f (succ n' - i)) 0,simp,rw this,rw \u2190series_succ\u2081,\nend\n\nlemma series_neg [ring \u03b1] (f : \u2115 \u2192 \u03b1) (n : \u2115) : -series f n = series (\u03bb m, -f m) n := begin\n  induction n with n' hi, simp!,simp![hi],\nend\n\nlemma series_sub_series [ring \u03b1] (f : \u2115 \u2192 \u03b1) {i j : \u2115} : i < j \u2192 series f j - series f i = nat.sum f (i + 1) j := begin\n  unfold nat.sum,assume ij,\n  induction i with i' hi,\n  cases j with j',exact absurd ij dec_trivial,\n  rw sub_eq_iff_eq_add',\n  exact series_succ\u2081  _ _,\n  rw [series_succ,sub_add_eq_sub_sub,hi (lt_of_succ_lt ij),sub_eq_iff_eq_add'],\n  have : (j - (i' + 1)) = succ (j - (succ i' + 1)),\n    rw [\u2190nat.succ_sub ij,succ_sub_succ],\n  rw this,\n  have : f (succ i') = (\u03bb (k : \u2115), f (k + (i' + 1))) 0,\n    simp,\n  rw this,simp[succ_add,add_succ],\n  rw series_succ\u2081,simp,\nend\n\nlemma series_const_zero [has_zero \u03b1] (i : \u2115): series (\u03bb j, 0) i = 0 := begin\n  induction i with i' hi,simp,simpa [series_succ],\nend\n\nlemma series_add [add_comm_monoid \u03b1] (f g : \u2115 \u2192 \u03b1) (n : \u2115) : series (\u03bb i, f i + g i) n = series f n + series g n := begin\n  induction n with n' hi,simp[series_zero],simp[series_succ,hi],\nend\n\nlemma series_mul_left [semiring \u03b1] (f : \u2115 \u2192 \u03b1) (a : \u03b1) (n : \u2115) : series (\u03bb i, a * f i) n = a * series f n := begin\n  induction n with n' hi,simp[series_zero],simp[series_succ,hi,mul_add],\nend\n \nlemma series_mul_right [semiring \u03b1] (f : \u2115 \u2192 \u03b1) (a : \u03b1) (n : \u2115) : series (\u03bb i, f i * a) n = series f n * a:= begin\n  induction n with n' hi,simp[series_zero],simp[series_succ,hi,add_mul],\nend\n\nlemma series_le [add_comm_monoid \u03b1] {f g : \u2115 \u2192 \u03b1} {n : \u2115} : (\u2200 i : \u2115, i \u2264 n \u2192 f i = g i) \u2192 series f n = series g n := begin\n  assume h, induction n with n' hi,simp,exact h 0 (le_refl _),\n  simp[series_succ],rw [h (succ n') (le_refl _),hi (\u03bb i h\u2081,h i (le_succ_of_le h\u2081))],\nend\n\nlemma abv_series_le_series_abv [discrete_linear_ordered_field \u03b1] [ring \u03b2] {f : \u2115 \u2192 \u03b2}\n    {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv] (n : \u2115) : abv (series f n) \u2264 series (\u03bb i, abv (f i)) n := begin\n  induction n with n' hi,\n  simp,simp[series_succ],\n  exact le_trans (abv_add _ _ _) (add_le_add_left hi _),\nend\n\nlemma series_mul_series [semiring \u03b1] (f g : \u2115 \u2192 \u03b1) (n m : \u2115) : series f n * series g m = series (\u03bb i, f i * series g m) n := begin\n  induction n with n' hi,\n  simp,simp[series_succ,mul_add,add_mul,hi],\nend\n\nlemma series_le_series [ordered_cancel_comm_monoid \u03b1] {f g : \u2115 \u2192 \u03b1} {n : \u2115} : (\u2200 m \u2264 n, f m \u2264 g m) \u2192 series f n \u2264 series g n := begin\n  assume h,induction n with n' hi,exact h 0 (le_refl _),\n  unfold series,exact add_le_add (hi (\u03bb m hm, h m (le_succ_of_le hm))) (h _ (le_refl _)),\nend\n\nlemma series_congr [has_add \u03b1] {f g : \u2115 \u2192 \u03b1} {i : \u2115} : (\u2200 j \u2264 i, f j = g j) \u2192 series f i = series g i := begin\n  assume h,induction i with i' hi,exact h 0 (zero_le _),\n  unfold series,rw h _ (le_refl (succ i')),\n  rw hi (\u03bb j ji, h j (le_succ_of_le ji)),\nend\n\nlemma series_nonneg [ordered_cancel_comm_monoid \u03b1] {f : \u2115 \u2192 \u03b1} {n : \u2115} : (\u2200 m \u2264 n, 0 \u2264 f m) \u2192 0 \u2264 series f n := begin\n  induction n with n' hi,simp,assume h,exact h 0 (le_refl _),\n  assume h,unfold series,refine add_nonneg (hi (\u03bb m hm, h m (le_succ_of_le hm))) (h _ (le_refl _)),\nend\n\nlemma series_series_diag_flip [add_comm_monoid \u03b1] (f : \u2115 \u2192 \u2115 \u2192 \u03b1) (n : \u2115) : series (\u03bb i, \nseries (\u03bb k, f k (i - k)) i) n = series (\u03bb i, series (\u03bb k, f i k) (n - i)) n := begin\n  have : \u2200 m : \u2115, m \u2264 n \u2192 series (\u03bb (i : \u2115), series (\u03bb k, f k (i - k)) (min m i)) n =\n      series (\u03bb i, series (\u03bb k, f i k) (n - i)) m,\n    assume m mn, induction m with m' hi,\n    simp[series_succ,series_zero,mul_add,max_eq_left (zero_le n)],\n    simp only [series_succ _ m'],rw \u2190hi (le_of_succ_le mn),clear hi,\n    induction n with n' hi,\n    simp[series_succ],exact absurd mn dec_trivial,cases n' with n\u2082,\n    simp [series_succ],rw [min_eq_left mn,series_succ,min_eq_left (le_of_succ_le mn)],\n    rw eq_zero_of_le_zero (le_of_succ_le_succ mn),simp,\n    cases lt_or_eq_of_le mn,\n    simp [series_succ _ (succ n\u2082),min_eq_left mn,hi (le_of_lt_succ h)],rw [\u2190add_assoc,\u2190add_assoc],\n    suffices : series (f (succ m')) (n\u2082 - m') + series (\u03bb (k : \u2115), f k (succ (succ n\u2082) - k)) (succ m')\n    = series (f (succ m')) (succ n\u2082 - m') +\n        series (\u03bb (k : \u2115), f k (succ (succ n\u2082) - k)) (min m' (succ (succ n\u2082))),\n      rw this,rw[min_eq_left (le_of_succ_le mn),series_succ,succ_sub_succ,succ_sub (le_of_succ_le_succ (le_of_lt_succ h)),series_succ],\n      rw [add_comm (series (\u03bb (k : \u2115), f k (succ (succ n\u2082) - k)) m'),add_assoc],      \n    rw \u2190h,simp[nat.sub_self],clear hi mn h,simp[series_succ,nat.sub_self],\n    suffices : series (\u03bb (i : \u2115), series (\u03bb (k : \u2115), f k (i - k)) (min (succ m') i)) m' = series (\u03bb (i : \u2115), series (\u03bb (k : \u2115), f k (i - k)) (min m' i)) m',\n      rw [this,min_eq_left (le_succ _)],clear n\u2082,\n    have h\u2081 : \u2200 i \u2264 m', (\u03bb (i : \u2115), series (\u03bb (k : \u2115), f k (i - k)) (min (succ m') i)) i = (\u03bb (i : \u2115), series (\u03bb (k : \u2115), f k (i - k)) (min m' i)) i,\n      assume i im,simp, rw [min_eq_right im,min_eq_right (le_succ_of_le im)],\n    rw series_congr h\u2081,\n  specialize this n (le_refl _),\n  rw \u2190this,refine series_congr _,assume i ni,rw min_eq_right ni,\nend\n\n\nlemma nat.sum_succ [has_add \u03b1] (f : \u2115 \u2192 \u03b1) (i j : \u2115) : i \u2264 j \u2192 nat.sum f i (succ j) = nat.sum f i j + f (succ j) := begin\n  assume ij,unfold nat.sum,rw [succ_sub ij,series_succ,\u2190succ_sub ij,nat.sub_add_cancel (le_succ_of_le ij)],\nend\n\nlemma nat.sum_le_sum [ordered_cancel_comm_monoid \u03b1] {f g : \u2115 \u2192 \u03b1} {i j : \u2115} : i \u2264 j \u2192 (\u2200 k \u2264 j, i \u2264 k \u2192 f k \u2264 g k) \u2192 nat.sum f i j \u2264 nat.sum g i j := begin\n  assume ij h ,unfold nat.sum,\n  refine series_le_series _,\n  assume m hm,rw nat.le_sub_right_iff_add_le ij at hm,\n  exact h (m + i) hm (le_add_left _ _),\nend\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff1", "sha": "cbcd788b8b1d07b20b2fff4482c870077a13d1c0", "save_path": "github-repos/lean/ChrisHughes24-leanstuff1", "path": "github-repos/lean/ChrisHughes24-leanstuff1/leanstuff1-cbcd788b8b1d07b20b2fff4482c870077a13d1c0/series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7261420318747431}}
{"text": "/-\nCopyright (c) 2022 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n-/\nimport algebra.is_prime_pow\nimport data.nat.factorization.basic\n\n/-!\n# Prime powers and factorizations\n\nThis file deals with factorizations of prime powers.\n-/\n\nvariables {R : Type*} [comm_monoid_with_zero R] (n p : R) (k : \u2115)\n\nlemma is_prime_pow.min_fac_pow_factorization_eq {n : \u2115} (hn : is_prime_pow n) :\n  n.min_fac ^ n.factorization n.min_fac = n :=\nbegin\n  obtain \u27e8p, k, hp, hk, rfl\u27e9 := hn,\n  rw \u2190nat.prime_iff at hp,\n  rw [hp.pow_min_fac hk.ne', hp.factorization_pow, finsupp.single_eq_same],\nend\n\nlemma is_prime_pow_of_min_fac_pow_factorization_eq {n : \u2115}\n  (h : n.min_fac ^ n.factorization n.min_fac = n) (hn : n \u2260 1) :\n  is_prime_pow n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn',\n  { simpa using h },\n  refine \u27e8_, _, (nat.min_fac_prime hn).prime, _, h\u27e9,\n  rw [pos_iff_ne_zero, \u2190finsupp.mem_support_iff, nat.factor_iff_mem_factorization,\n    nat.mem_factors_iff_dvd hn' (nat.min_fac_prime hn)],\n  apply nat.min_fac_dvd\nend\n\nlemma is_prime_pow_iff_min_fac_pow_factorization_eq {n : \u2115} (hn : n \u2260 1) :\n  is_prime_pow n \u2194 n.min_fac ^ n.factorization n.min_fac = n :=\n\u27e8\u03bb h, h.min_fac_pow_factorization_eq, \u03bb h, is_prime_pow_of_min_fac_pow_factorization_eq h hn\u27e9\n\nlemma is_prime_pow_iff_factorization_eq_single {n : \u2115} :\n  is_prime_pow n \u2194 \u2203 p k : \u2115, 0 < k \u2227 n.factorization = finsupp.single p k :=\nbegin\n  rw is_prime_pow_nat_iff,\n  refine exists\u2082_congr (\u03bb p k, _),\n  split,\n  { rintros \u27e8hp, hk, hn\u27e9,\n    exact \u27e8hk, by rw [\u2190hn, nat.prime.factorization_pow hp]\u27e9 },\n  { rintros \u27e8hk, hn\u27e9,\n    have hn0 : n \u2260 0,\n    { rintro rfl,\n      simpa only [finsupp.single_eq_zero, eq_comm, nat.factorization_zero, hk.ne'] using hn },\n    rw nat.eq_pow_of_factorization_eq_single hn0 hn,\n    exact \u27e8nat.prime_of_mem_factorization\n      (by simp [hn, hk.ne'] : p \u2208 n.factorization.support), hk, rfl\u27e9 }\nend\n\nlemma is_prime_pow_iff_card_support_factorization_eq_one {n : \u2115} :\n  is_prime_pow n \u2194 n.factorization.support.card = 1 :=\nby simp_rw [is_prime_pow_iff_factorization_eq_single, finsupp.card_support_eq_one', exists_prop,\n  pos_iff_ne_zero]\n\nlemma is_prime_pow.exists_ord_compl_eq_one {n : \u2115} (h : is_prime_pow n) :\n  \u2203 p : \u2115, p.prime \u2227 ord_compl[p] n = 1 :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn0, { cases not_is_prime_pow_zero h },\n  rcases is_prime_pow_iff_factorization_eq_single.mp h with \u27e8p, k, hk0, h1\u27e9,\n  rcases em' p.prime with pp | pp,\n  { refine absurd _ hk0.ne', simp [\u2190nat.factorization_eq_zero_of_non_prime n pp, h1] },\n  refine \u27e8p, pp, _\u27e9,\n  refine nat.eq_of_factorization_eq (nat.ord_compl_pos p hn0).ne' (by simp) (\u03bb q, _),\n  rw [nat.factorization_ord_compl n p, h1],\n  simp,\nend\n\nlemma exists_ord_compl_eq_one_iff_is_prime_pow {n : \u2115} (hn : n \u2260 1) :\n  is_prime_pow n \u2194 \u2203 p : \u2115, p.prime \u2227 ord_compl[p] n = 1 :=\nbegin\n  refine \u27e8\u03bb h, is_prime_pow.exists_ord_compl_eq_one h, \u03bb h, _\u27e9,\n  rcases h with \u27e8p, pp, h\u27e9,\n  rw is_prime_pow_nat_iff,\n  rw [\u2190nat.eq_of_dvd_of_div_eq_one (nat.ord_proj_dvd n p) h] at \u22a2 hn,\n  refine \u27e8p, n.factorization p, pp, _, by simp\u27e9,\n  contrapose! hn,\n  simp [le_zero_iff.1 hn],\nend\n\n/-- An equivalent definition for prime powers: `n` is a prime power iff there is a unique prime\ndividing it. -/\nlemma is_prime_pow_iff_unique_prime_dvd {n : \u2115} :\n  is_prime_pow n \u2194 \u2203! p : \u2115, p.prime \u2227 p \u2223 n :=\nbegin\n  rw is_prime_pow_nat_iff,\n  split,\n  { rintro \u27e8p, k, hp, hk, rfl\u27e9,\n    refine \u27e8p, \u27e8hp, dvd_pow_self _ hk.ne'\u27e9, _\u27e9,\n    rintro q \u27e8hq, hq'\u27e9,\n    exact (nat.prime_dvd_prime_iff_eq hq hp).1 (hq.dvd_of_dvd_pow hq') },\n  rintro \u27e8p, \u27e8hp, hn\u27e9, hq\u27e9,\n  rcases eq_or_ne n 0 with rfl | hn\u2080,\n  { cases (hq 2 \u27e8nat.prime_two, dvd_zero 2\u27e9).trans (hq 3 \u27e8nat.prime_three, dvd_zero 3\u27e9).symm },\n  refine \u27e8p, n.factorization p, hp, hp.factorization_pos_of_dvd hn\u2080 hn, _\u27e9,\n  simp only [and_imp] at hq,\n  apply nat.dvd_antisymm (nat.ord_proj_dvd _ _),\n  -- We need to show n \u2223 p ^ n.factorization p\n  apply nat.dvd_of_factors_subperm hn\u2080,\n  rw [hp.factors_pow, list.subperm_ext_iff],\n  intros q hq',\n  rw nat.mem_factors hn\u2080 at hq',\n  cases hq _ hq'.1 hq'.2,\n  simp,\nend\n\nlemma is_prime_pow_pow_iff {n k : \u2115} (hk : k \u2260 0) :\n  is_prime_pow (n ^ k) \u2194 is_prime_pow n :=\nbegin\n  simp only [is_prime_pow_iff_unique_prime_dvd],\n  apply exists_unique_congr,\n  simp only [and.congr_right_iff],\n  intros p hp,\n  exact \u27e8hp.dvd_of_dvd_pow, \u03bb t, t.trans (dvd_pow_self _ hk)\u27e9,\nend\n\nlemma nat.coprime.is_prime_pow_dvd_mul {n a b : \u2115} (hab : nat.coprime a b) (hn : is_prime_pow n) :\n  n \u2223 a * b \u2194 n \u2223 a \u2228 n \u2223 b :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simp only [nat.coprime_zero_left] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  rcases eq_or_ne b 0 with rfl | hb,\n  { simp only [nat.coprime_zero_right] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  refine \u27e8_, \u03bb h, or.elim h (\u03bb i, i.trans (dvd_mul_right _ _)) (\u03bb i, i.trans (dvd_mul_left _ _))\u27e9,\n  obtain \u27e8p, k, hp, hk, rfl\u27e9 := (is_prime_pow_nat_iff _).1 hn,\n  simp only [hp.pow_dvd_iff_le_factorization (mul_ne_zero ha hb),\n    nat.factorization_mul ha hb, hp.pow_dvd_iff_le_factorization ha,\n    hp.pow_dvd_iff_le_factorization hb, pi.add_apply, finsupp.coe_add],\n  have : a.factorization p = 0 \u2228 b.factorization p = 0,\n  { rw [\u2190finsupp.not_mem_support_iff, \u2190finsupp.not_mem_support_iff, \u2190not_and_distrib,\n      \u2190finset.mem_inter],\n    exact \u03bb t, (nat.factorization_disjoint_of_coprime hab).le_bot t },\n  cases this;\n  simp [this, imp_or_distrib],\nend\n\nlemma nat.mul_divisors_filter_prime_pow {a b : \u2115} (hab : a.coprime b) :\n  (a * b).divisors.filter is_prime_pow = (a.divisors \u222a b.divisors).filter is_prime_pow :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simp only [nat.coprime_zero_left] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  rcases eq_or_ne b 0 with rfl | hb,\n  { simp only [nat.coprime_zero_right] at hab,\n    simp [hab, finset.filter_singleton, not_is_prime_pow_one] },\n  ext n,\n  simp only [ha, hb, finset.mem_union, finset.mem_filter, nat.mul_eq_zero, and_true, ne.def,\n    and.congr_left_iff, not_false_iff, nat.mem_divisors, or_self],\n  apply hab.is_prime_pow_dvd_mul,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/factorization/prime_pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7261420301339182}}
{"text": "import utilities\n\nopen list\nopen multiset\nopen set\nopen nat\n\nset_option trace.simplify.rewrite true\n\nvariable {\u03b1 : Type*}\nvariable r: \u03b1 \u2192 \u03b1 \u2192 Prop\nvariable x: \u03b1 \nvariable xs: list \u03b1  \n\n/- \n# Insertion sort\n\nThe two functions insort and isort from __Functional Algorithms, Verified!__ are defined in Lean \nas ordered_insert and insertion_sort respectively and are reused.\n\n## Functional Correctness\n -/\n\nlemma mset_insort [decidable_rel r] : (ordered_insert r x xs: multiset \u03b1) = {x} + \u2191xs :=\nbegin\n  induction' xs, \n  { refl },\n  { simp,\n    split_ifs, \n      refl, \n      simp [\u2190 multiset.cons_coe, ih] }\nend\n\nlemma mset_isort [decidable_rel r] : (insertion_sort r xs: multiset \u03b1) = \u2191xs :=\nbegin\n  induction' xs,\n  { refl },\n  { simp [mset_insort, ih],\n    refl }\nend \n\nlemma set_insort [decidable_rel r] : (ordered_insert r x xs).to_set  = {x} \u222a xs.to_set  :=\nbegin\n  simp [set.insert_def, \u2190 set_mset_mset, mset_insort, multiset.to_set],\nend\n\nlemma sorted_insort [decidable_rel r] [is_linear_order \u03b1 r] : sorted' r (ordered_insert r x xs) = sorted' r xs :=\nbegin\n  -- By using fixing the trans and total_of functions work without writing the is_total and is_trans instances explicitly.\n  induction' xs fixing *, \n  { simp [sorted'],\n    intros,\n    exact false.elim H },\n  { simp only [ordered_insert],\n    split_ifs,\n    { simp [sorted', list.to_set],\n      intros h1 h2,\n      apply and.intro h,\n      intros y h3, \n      have h4: y \u2208 xs.to_set \u2192 r hd y, from h1 y,\n      have h5: r hd y, from h4 h3,\n      exact trans h h5 }, \n    { simp [sorted', list.to_set, ih, set_insort],\n      intros h1 h2,\n      exact or.resolve_right (total_of r hd x) h } }\nend\n\nlemma sorted_isort [decidable_rel r] [is_linear_order \u03b1 r]: sorted' r (insertion_sort r xs) :=\nbegin\n  induction' xs,\n  repeat { simp [sorted_insort, *] }\nend\n\n/- \n## Time Complexity\nWe count the number of function calls.\n -/\n\ndef T_insort [decidable_rel r] : \u03b1 \u2192 list \u03b1 \u2192 nat \n| x [] := 1\n| x (y::ys) := if  r x y  then 0 else T_insort x ys + 1 \n\ndef T_isort [decidable_rel r] : list \u03b1 \u2192 nat \n| [] := 1\n| (x::xs) := T_isort xs + T_insort r x (insertion_sort r xs) + 1\n\nlemma T_insort_length [decidable_rel r]: T_insort r x xs <= xs.length + 1 :=\nbegin\n  induction' xs,\n  repeat { simp [T_insort] },\n  split_ifs,\n  repeat { simp *},\nend\n\nlemma length_insort [decidable_rel r] : (ordered_insert r x xs).length = xs.length + 1 :=\nbegin\n  induction' xs,\n  repeat { simp [ordered_insert] },\n  split_ifs,\n  repeat { simp *},\nend\n\nlemma length_isort [decidable_rel r] : (insertion_sort r xs).length = xs.length :=\nbegin\n  induction' xs,\n  repeat { simp [length_insort, *] }\nend\n\n/-\nLemma 2.1 from __Functional Algorithms, Verified!__\n-/\nlemma T_isort_length [decidable_rel r]: T_isort r xs <= (xs.length + 1) ^ 2 :=\nbegin\n  induction' xs fixing *,\n  repeat { simp [T_isort, T_insort_length, length_isort ]},\n  show T_isort r xs + T_insort r hd (insertion_sort r xs) + 1 \u2264 (xs.length + 1 + 1) ^ 2, by calc\n  T_isort r xs + T_insort r hd (insertion_sort r xs) + 1 \u2264 (xs.length + 1) ^ 2 + T_insort r hd (insertion_sort r xs) + 1 : by simp [ih]\n  ... \u2264 (xs.length + 1) ^ 2 + ((insertion_sort r xs).length + 1) + 1 : by simp [T_insort_length]\n  ... = (xs.length + 1) ^ 2 + (xs.length + 1) + 1 : by simp [length_isort]\n  ... = xs.length ^2 + 2 * xs.length + xs.length + 3 : by ring\n  ... \u2264 xs.length ^2 + 2 * xs.length + xs.length + xs.length + 3 : by simp \n  ... \u2264 xs.length ^2 + 2 * xs.length + xs.length + xs.length + 4 : by simp \n  ... = (xs.length + 1 + 1) ^ 2 : by ring,\nend\n", "meta": {"author": "MaschavanderMarel", "repo": "bachelor_project", "sha": "7ace1dea38fc87bfe73367c3a84273886a7f92e3", "save_path": "github-repos/lean/MaschavanderMarel-bachelor_project", "path": "github-repos/lean/MaschavanderMarel-bachelor_project/bachelor_project-7ace1dea38fc87bfe73367c3a84273886a7f92e3/src/insertion_sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7261420177375578}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nPremetric spaces.\n\nAuthor: S\u00e9bastien Gou\u00ebzel\n\nMetric spaces are often defined as quotients of spaces endowed with a \"distance\"\nfunction satisfying the triangular inequality, but for which `dist x y = 0` does\nnot imply x = y. We call such a space a premetric space.\n`dist x y = 0` defines an equivalence relation, and the quotient\nis canonically a metric space.\n-/\n\nimport topology.metric_space.basic tactic.linarith\nnoncomputable theory\n\nuniverses u v\nvariables {\u03b1 : Type u}\n\nclass premetric_space (\u03b1 : Type u) extends has_dist \u03b1 : Type u :=\n(dist_self : \u2200 x : \u03b1, dist x x = 0)\n(dist_comm : \u2200 x y : \u03b1, dist x y = dist y x)\n(dist_triangle : \u2200 x y z : \u03b1, dist x z \u2264 dist x y + dist y z)\n\nnamespace premetric\nsection\n\nprotected lemma dist_nonneg {\u03b1 : Type u} [premetric_space \u03b1] {x y : \u03b1} : 0 \u2264 dist x y :=\nbegin\n  have := calc\n    0 = dist x x : (premetric_space.dist_self _).symm\n    ... \u2264 dist x y + dist y x : premetric_space.dist_triangle _ _ _\n    ... = dist x y + dist x y : by simp [premetric_space.dist_comm],\n  by linarith\nend\n\n/-- The canonical equivalence relation on a premetric space. -/\ndef dist_setoid (\u03b1 : Type u) [premetric_space \u03b1] : setoid \u03b1 :=\nsetoid.mk (\u03bbx y, dist x y = 0)\nbegin\n  unfold equivalence,\n  repeat { split },\n  { exact premetric_space.dist_self },\n  { assume x y h, rwa premetric_space.dist_comm },\n  { assume x y z hxy hyz,\n    refine le_antisymm _ premetric.dist_nonneg,\n    calc dist x z \u2264 dist x y + dist y z : premetric_space.dist_triangle _ _ _\n         ... = 0 + 0 : by rw [hxy, hyz]\n         ... = 0 : by simp }\nend\n\nlocal attribute [instance] dist_setoid\n\n/-- The canonical quotient of a premetric space, identifying points at distance 0. -/\n@[reducible] definition metric_quot (\u03b1 : Type u) [premetric_space \u03b1] : Type* :=\nquotient (premetric.dist_setoid \u03b1)\n\ninstance has_dist_metric_quot {\u03b1 : Type u} [premetric_space \u03b1] : has_dist (metric_quot \u03b1) :=\n{ dist := quotient.lift\u2082 (\u03bbp q : \u03b1, dist p q)\nbegin\n  assume x y x' y' hxx' hyy',\n  have Hxx' : dist x x' = 0 := hxx',\n  have Hyy' : dist y y' = 0 := hyy',\n  have A : dist x y \u2264 dist x' y' := calc\n    dist x y \u2264 dist x x' + dist x' y : premetric_space.dist_triangle _ _ _\n    ... = dist x' y : by simp [Hxx']\n    ... \u2264 dist x' y' + dist y' y : premetric_space.dist_triangle _ _ _\n    ... = dist x' y' : by simp [premetric_space.dist_comm, Hyy'],\n  have B : dist x' y' \u2264 dist x y := calc\n    dist x' y' \u2264 dist x' x + dist x y' : premetric_space.dist_triangle _ _ _\n    ... = dist x y' : by simp [premetric_space.dist_comm, Hxx']\n    ... \u2264 dist x y + dist y y' : premetric_space.dist_triangle _ _ _\n    ... = dist x y : by simp [Hyy'],\n  exact le_antisymm A B\nend }\n\nlemma metric_quot_dist_eq {\u03b1 : Type u} [premetric_space \u03b1] (p q : \u03b1) : dist \u27e6p\u27e7 \u27e6q\u27e7 = dist p q := rfl\n\ninstance metric_space_quot {\u03b1 : Type u} [premetric_space \u03b1] : metric_space (metric_quot \u03b1) :=\n{ dist_self := begin\n    refine quotient.ind (\u03bby, _),\n    exact premetric_space.dist_self _\n  end,\n  eq_of_dist_eq_zero :=\n    \u03bbxc yc, quotient.induction_on\u2082 xc yc (\u03bbx y H, quotient.sound H),\n  dist_comm :=\n    \u03bbxc yc, quotient.induction_on\u2082 xc yc (\u03bbx y, premetric_space.dist_comm _ _),\n  dist_triangle :=\n    \u03bbxc yc zc, quotient.induction_on\u2083 xc yc zc (\u03bbx y z, premetric_space.dist_triangle _ _ _) }\n\nend --section\nend premetric --namespace\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/topology/metric_space/premetric_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7261420119470479}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,\nNeil Strickland, Aaron Anderson\n-/\n\nimport algebra.group_with_zero.basic\n\n/-!\n# Divisibility\n\nThis file defines the basics of the divisibility relation in the context of `(comm_)` `monoid`s\n`(_with_zero)`.\n\n## Main definitions\n\n * `monoid.has_dvd`\n\n## Implementation notes\n\nThe divisibility relation is defined for all monoids, and as such, depends on the order of\n  multiplication if the monoid is not commutative. There are two possible conventions for\n  divisibility in the noncommutative context, and this relation follows the convention for ordinals,\n  so `a | b` is defined as `\u2203 c, b = a * c`.\n\n## Tags\n\ndivisibility, divides\n-/\n\nvariables {\u03b1 : Type*}\n\nsection semigroup\n\nvariables [semigroup \u03b1] {a b c : \u03b1}\n\n/-- There are two possible conventions for divisibility, which coincide in a `comm_monoid`.\n    This matches the convention for ordinals. -/\n@[priority 100]\ninstance semigroup_has_dvd : has_dvd \u03b1 :=\nhas_dvd.mk (\u03bb a b, \u2203 c, b = a * c)\n\n-- TODO: this used to not have `c` explicit, but that seems to be important\n--       for use with tactics, similar to `exists.intro`\ntheorem dvd.intro (c : \u03b1) (h : a * c = b) : a \u2223 b :=\nexists.intro c h^.symm\n\nalias dvd.intro \u2190 dvd_of_mul_right_eq\n\ntheorem exists_eq_mul_right_of_dvd (h : a \u2223 b) : \u2203 c, b = a * c := h\n\ntheorem dvd.elim {P : Prop} {a b : \u03b1} (H\u2081 : a \u2223 b) (H\u2082 : \u2200 c, b = a * c \u2192 P) : P :=\nexists.elim H\u2081 H\u2082\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\n@[trans] theorem dvd_trans (h\u2081 : a \u2223 b) (h\u2082 : b \u2223 c) : a \u2223 c :=\nmatch h\u2081, h\u2082 with\n| \u27e8d, (h\u2083 : b = a * d)\u27e9, \u27e8e, (h\u2084 : c = b * e)\u27e9 :=\n  \u27e8d * e, show c = a * (d * e), by simp [h\u2083, h\u2084]\u27e9\nend\n\nalias dvd_trans \u2190 has_dvd.dvd.trans\n\n@[simp] theorem dvd_mul_right (a b : \u03b1) : a \u2223 a * b := dvd.intro b rfl\n\ntheorem dvd_mul_of_dvd_left (h : a \u2223 b) (c : \u03b1) : a \u2223 b * c :=\nh.trans (dvd_mul_right b c)\n\nalias dvd_mul_of_dvd_left \u2190 has_dvd.dvd.mul_right\n\ntheorem dvd_of_mul_right_dvd (h : a * b \u2223 c) : a \u2223 c :=\n(dvd_mul_right a b).trans h\n\nsection map_dvd\n\nvariables {M N : Type*} [monoid M] [monoid N]\n\nlemma map_dvd {F : Type*} [mul_hom_class F M N] (f : F) {a b} : a \u2223 b \u2192 f a \u2223 f b\n| \u27e8c, h\u27e9 := \u27e8f c, h.symm \u25b8 map_mul f a c\u27e9\n\nlemma mul_hom.map_dvd (f : mul_hom M N) {a b} : a \u2223 b \u2192 f a \u2223 f b := map_dvd f\n\nlemma monoid_hom.map_dvd (f : M \u2192* N) {a b} : a \u2223 b \u2192 f a \u2223 f b := map_dvd f\n\nend map_dvd\n\nend semigroup\n\nsection monoid\n\nvariables [monoid \u03b1]\n\n@[refl, simp] theorem dvd_refl (a : \u03b1) : a \u2223 a :=\ndvd.intro 1 (mul_one _)\n\nlemma dvd_rfl {a : \u03b1} : a \u2223 a :=\ndvd_refl a\n\ntheorem one_dvd (a : \u03b1) : 1 \u2223 a := dvd.intro a (one_mul _)\n\nend monoid\n\nsection comm_semigroup\n\nvariables [comm_semigroup \u03b1] {a b c : \u03b1}\n\ntheorem dvd.intro_left (c : \u03b1) (h : c * a = b) : a \u2223 b :=\ndvd.intro _ (begin rewrite mul_comm at h, apply h end)\n\nalias dvd.intro_left \u2190 dvd_of_mul_left_eq\n\ntheorem exists_eq_mul_left_of_dvd (h : a \u2223 b) : \u2203 c, b = c * a :=\ndvd.elim h (assume c, assume H1 : b = a * c, exists.intro c (eq.trans H1 (mul_comm a c)))\n\nlemma dvd_iff_exists_eq_mul_left : a \u2223 b \u2194 \u2203 c, b = c * a :=\n\u27e8exists_eq_mul_left_of_dvd, by { rintro \u27e8c, rfl\u27e9, exact \u27e8c, mul_comm _ _\u27e9, }\u27e9\n\ntheorem dvd.elim_left {P : Prop} (h\u2081 : a \u2223 b) (h\u2082 : \u2200 c, b = c * a \u2192 P) : P :=\nexists.elim (exists_eq_mul_left_of_dvd h\u2081) (assume c, assume h\u2083 : b = c * a, h\u2082 c h\u2083)\n\n@[simp] theorem dvd_mul_left (a b : \u03b1) : a \u2223 b * a := dvd.intro b (mul_comm a b)\n\ntheorem dvd_mul_of_dvd_right (h : a \u2223 b) (c : \u03b1) : a \u2223 c * b :=\nbegin rw mul_comm, exact h.mul_right _ end\n\nalias dvd_mul_of_dvd_right \u2190 has_dvd.dvd.mul_left\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\ntheorem mul_dvd_mul : \u2200 {a b c d : \u03b1}, a \u2223 b \u2192 c \u2223 d \u2192 a * c \u2223 b * d\n| a ._ c ._ \u27e8e, rfl\u27e9 \u27e8f, rfl\u27e9 := \u27e8e * f, by simp\u27e9\n\ntheorem dvd_of_mul_left_dvd (h : a * b \u2223 c) : b \u2223 c :=\ndvd.elim h (\u03bb d ceq, dvd.intro (a * d) (by simp [ceq]))\n\nend comm_semigroup\n\nsection comm_monoid\n\nvariables [comm_monoid \u03b1] {a b : \u03b1}\n\ntheorem mul_dvd_mul_left (a : \u03b1) {b c : \u03b1} (h : b \u2223 c) : a * b \u2223 a * c :=\nmul_dvd_mul (dvd_refl a) h\n\ntheorem mul_dvd_mul_right (h : a \u2223 b) (c : \u03b1) : a * c \u2223 b * c :=\nmul_dvd_mul h (dvd_refl c)\n\nend comm_monoid\n\nsection semigroup_with_zero\n\nvariables [semigroup_with_zero \u03b1] {a : \u03b1}\n\ntheorem eq_zero_of_zero_dvd (h : 0 \u2223 a) : a = 0 :=\ndvd.elim h (assume c, assume H' : a = 0 * c, eq.trans H' (zero_mul c))\n\n/-- Given an element `a` of a commutative semigroup with zero, there exists another element whose\n    product with zero equals `a` iff `a` equals zero. -/\n@[simp] lemma zero_dvd_iff : 0 \u2223 a \u2194 a = 0 :=\n\u27e8eq_zero_of_zero_dvd, \u03bb h, by { rw h, use 0, simp, }\u27e9\n\n@[simp] theorem dvd_zero (a : \u03b1) : a \u2223 0 := dvd.intro 0 (by simp)\n\nend semigroup_with_zero\n\n/-- Given two elements `b`, `c` of a `cancel_monoid_with_zero` and a nonzero element `a`,\n `a*b` divides `a*c` iff `b` divides `c`. -/\ntheorem mul_dvd_mul_iff_left [cancel_monoid_with_zero \u03b1] {a b c : \u03b1}\n  (ha : a \u2260 0) : a * b \u2223 a * c \u2194 b \u2223 c :=\nexists_congr $ \u03bb d, by rw [mul_assoc, mul_right_inj' ha]\n\n/-- Given two elements `a`, `b` of a commutative `cancel_monoid_with_zero` and a nonzero\n  element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/\ntheorem mul_dvd_mul_iff_right [cancel_comm_monoid_with_zero \u03b1] {a b c : \u03b1} (hc : c \u2260 0) :\n  a * c \u2223 b * c \u2194 a \u2223 b :=\nexists_congr $ \u03bb d, by rw [mul_right_comm, mul_left_inj' hc]\n\n/-!\n### Units in various monoids\n-/\n\nnamespace units\n\nsection monoid\nvariables [monoid \u03b1] {a b : \u03b1} {u : \u03b1\u02e3}\n\n/-- Elements of the unit group of a monoid represented as elements of the monoid\n    divide any element of the monoid. -/\nlemma coe_dvd : \u2191u \u2223 a := \u27e8\u2191u\u207b\u00b9 * a, by simp\u27e9\n\n/-- In a monoid, an element `a` divides an element `b` iff `a` divides all\n    associates of `b`. -/\nlemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\niff.intro\n  (assume \u27e8c, eq\u27e9, \u27e8c * \u2191u\u207b\u00b9, by rw [\u2190 mul_assoc, \u2190 eq, units.mul_inv_cancel_right]\u27e9)\n  (assume \u27e8c, eq\u27e9, eq.symm \u25b8 (dvd_mul_right _ _).mul_right _)\n\n/-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/\nlemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\niff.intro\n  (\u03bb \u27e8c, eq\u27e9, \u27e8\u2191u * c, eq.trans (mul_assoc _ _ _)\u27e9)\n  (\u03bb h, dvd_trans (dvd.intro \u2191u\u207b\u00b9 (by rw [mul_assoc, u.mul_inv, mul_one])) h)\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] {a b : \u03b1} {u : \u03b1\u02e3}\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\nlemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b := by { rw mul_comm, apply dvd_mul_right }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\nlemma mul_left_dvd : \u2191u * a \u2223 b \u2194 a \u2223 b :=\nby { rw mul_comm, apply mul_right_dvd }\n\nend comm_monoid\n\nend units\n\nnamespace is_unit\n\nsection monoid\n\nvariables [monoid \u03b1] {a b u : \u03b1} (hu : is_unit u)\ninclude hu\n\n/-- Units of a monoid divide any element of the monoid. -/\n@[simp] lemma dvd : u \u2223 a := by { rcases hu with \u27e8u, rfl\u27e9, apply units.coe_dvd, }\n\n@[simp] lemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_right, }\n\n/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/\n@[simp] lemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_right_dvd, }\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] (a b u : \u03b1) (hu : is_unit u)\ninclude hu\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\n@[simp] lemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_left, }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\n@[simp] lemma mul_left_dvd : u * a \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_left_dvd, }\n\nend comm_monoid\n\nend is_unit\n\nsection comm_monoid\nvariables [comm_monoid \u03b1]\n\ntheorem is_unit_iff_dvd_one {x : \u03b1} : is_unit x \u2194 x \u2223 1 :=\n\u27e8by rintro \u27e8u, rfl\u27e9; exact \u27e8_, u.mul_inv.symm\u27e9,\n \u03bb \u27e8y, h\u27e9, \u27e8\u27e8x, y, h.symm, by rw [h, mul_comm]\u27e9, rfl\u27e9\u27e9\n\ntheorem is_unit_iff_forall_dvd {x : \u03b1} :\n  is_unit x \u2194 \u2200 y, x \u2223 y :=\nis_unit_iff_dvd_one.trans \u27e8\u03bb h y, h.trans (one_dvd _), \u03bb h, h _\u27e9\n\ntheorem is_unit_of_dvd_unit {x y : \u03b1}\n  (xy : x \u2223 y) (hu : is_unit y) : is_unit x :=\nis_unit_iff_dvd_one.2 $ xy.trans $ is_unit_iff_dvd_one.1 hu\n\nlemma is_unit_of_dvd_one : \u2200a \u2223 1, is_unit (a:\u03b1)\n| a \u27e8b, eq\u27e9 := \u27e8units.mk_of_mul_eq_one a b eq.symm, rfl\u27e9\n\nlemma not_is_unit_of_not_is_unit_dvd {a b : \u03b1} (ha : \u00acis_unit a) (hb : a \u2223 b) :\n  \u00ac is_unit b :=\nmt (is_unit_of_dvd_unit hb) ha\n\nend comm_monoid\n\nsection comm_monoid_with_zero\n\nvariable [comm_monoid_with_zero \u03b1]\n\n/-- `dvd_not_unit a b` expresses that `a` divides `b` \"strictly\", i.e. that `b` divided by `a`\nis not a unit. -/\ndef dvd_not_unit (a b : \u03b1) : Prop := a \u2260 0 \u2227 \u2203 x, \u00acis_unit x \u2227 b = a * x\n\nlemma dvd_not_unit_of_dvd_of_not_dvd {a b : \u03b1} (hd : a \u2223 b) (hnd : \u00ac b \u2223 a) :\n  dvd_not_unit a b :=\nbegin\n  split,\n  { rintro rfl, exact hnd (dvd_zero _) },\n  { rcases hd with \u27e8c, rfl\u27e9,\n    refine \u27e8c, _, rfl\u27e9,\n    rintro \u27e8u, rfl\u27e9,\n    simpa using hnd }\nend\n\nend comm_monoid_with_zero\n\nlemma dvd_and_not_dvd_iff [cancel_comm_monoid_with_zero \u03b1] {x y : \u03b1} :\n  x \u2223 y \u2227 \u00acy \u2223 x \u2194 dvd_not_unit x y :=\n\u27e8\u03bb \u27e8\u27e8d, hd\u27e9, hyx\u27e9, \u27e8\u03bb hx0, by simpa [hx0] using hyx, \u27e8d,\n    mt is_unit_iff_dvd_one.1 (\u03bb \u27e8e, he\u27e9, hyx \u27e8e, by rw [hd, mul_assoc, \u2190 he, mul_one]\u27e9), hd\u27e9\u27e9,\n  \u03bb \u27e8hx0, d, hdu, hdx\u27e9, \u27e8\u27e8d, hdx\u27e9, \u03bb \u27e8e, he\u27e9, hdu (is_unit_of_dvd_one _\n    \u27e8e, mul_left_cancel\u2080 hx0 $ by conv {to_lhs, rw [he, hdx]};simp [mul_assoc]\u27e9)\u27e9\u27e9\n\nsection monoid_with_zero\n\nvariable [monoid_with_zero \u03b1]\n\ntheorem ne_zero_of_dvd_ne_zero {p q : \u03b1} (h\u2081 : q \u2260 0)\n  (h\u2082 : p \u2223 q) : p \u2260 0 :=\nbegin\n  rcases h\u2082 with \u27e8u, rfl\u27e9,\n  exact left_ne_zero_of_mul h\u2081,\nend\n\nend monoid_with_zero\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7261233425624157}}
{"text": "import game.world8.level6 -- hide\nnamespace mynat -- hide\n\n/-\n\n# Advanced Addition World\n\n## Level 7: `add_right_cancel_iff`\n\nIt's sometimes convenient to have the \"if and only if\" version\nof theorems like `add_right_cancel`. Remember that you can use `split`\nto split an `\u2194` goal into the `\u2192` goal and the `\u2190` goal.\n\n## Pro tip:\n\n`exact add_right_cancel _ _ _` means \"let Lean figure out the missing inputs\"\n-/\n\n/- Theorem\nFor all naturals $a$, $b$ and $t$, \n$$ a + t = b + t\\iff a=b. $$\n-/\ntheorem add_right_cancel_iff (t a b : mynat) :  a + t = b + t \u2194 a = b :=\nbegin [nat_num_game]\n  split,\n  { exact add_right_cancel _ _ _}, -- done that way already,\n  { intro H, -- H : a = b,\n    rw H,\n    refl,\n  }\n\n\n\nend\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world8/level7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7260864822674699}}
{"text": "import analysis.normed_space.finite_dimension\nimport analysis.convolution\nimport measure_theory.function.jacobian\nimport measure_theory.integral.bochner\nimport measure_theory.measure.lebesgue\n\nopen set filter\nopen_locale topological_space filter ennreal\nnoncomputable theory\n\n/- TEXT:\n.. index:: measure theory\n\n.. _measure_theory:\n\nMeasure Theory\n--------------\n\nThe general context for integration in mathlib is measure theory. Even the elementary\nintegrals of the previous section are in fact Bochner integrals. Bochner integration is\na generalization of Lebesgue integration where the target space can be any Banach space,\nnot necessarily finite dimensional.\n\nThe first component in the development of measure theory\nis the notion of a :math:`\\sigma`-algebra of sets, which are called the\n*measurable* sets.\nThe type class ``measurable_space`` serves to equip a type with such a structure.\nThe sets ``empty`` and ``univ`` are measurable,\nthe complement of a measurable set is measurable,\nand a countable union or intersection of measurable sets is measurable.\nNote that these axioms are redundant; if you ``#print measurable_space``,\nyou will see the ones that mathlib uses.\nAs the examples below show, countability assumptions can be expressed using the\n``encodable`` type class.\nBOTH: -/\n-- QUOTE:\nvariables {\u03b1 : Type*} [measurable_space \u03b1]\n\n-- EXAMPLES:\nexample : measurable_set (\u2205 : set \u03b1) := measurable_set.empty\n\nexample : measurable_set (univ : set \u03b1) := measurable_set.univ\n\nexample {s : set \u03b1} (hs : measurable_set s) : measurable_set s\u1d9c :=\nhs.compl\n\nexample : encodable \u2115 :=\nby apply_instance\n\nexample (n : \u2115) : encodable (fin n) :=\nby apply_instance\n\n-- BOTH:\nvariables {\u03b9 : Type*} [encodable \u03b9]\n\n-- EXAMPLES:\nexample {f : \u03b9 \u2192 set \u03b1} (h : \u2200 b, measurable_set (f b)) :\n  measurable_set (\u22c3 b, f b) :=\nmeasurable_set.Union h\n\nexample {f : \u03b9 \u2192 set \u03b1} (h : \u2200 b, measurable_set (f b)) :\n  measurable_set (\u22c2 b, f b) :=\nmeasurable_set.Inter h\n-- QUOTE.\n\n/- TEXT:\nOnce a type is measurable, we can measure it. On paper, a measure on a set\n(or type) equipped with a\n:math:`\\sigma`-algebra is a function from the measurable sets to\nthe extended non-negative reals that is\nadditive on countable disjoint unions.\nIn mathlib, we don't want to carry around measurability assumptions\nevery time we write an application of the measure to a set.\nSo we extend the measure to any set ``s``\nas the infimum of measures of measurable sets containing ``s``.\nOf course, many lemmas still require\nmeasurability assumptions, but not all.\nBOTH: -/\n-- QUOTE:\nopen measure_theory\n\nvariables {\u03bc : measure \u03b1}\n\n-- EXAMPLES:\nexample (s : set \u03b1) : \u03bc s = \u2a05 t (st : s \u2286 t) (ht : measurable_set t), \u03bc t :=\nmeasure_eq_infi s\n\nexample  (s : \u03b9 \u2192 set \u03b1) : \u03bc (\u22c3 i, s i) \u2264 \u2211' i, \u03bc (s i) :=\nmeasure_Union_le s\n\nexample {f : \u2115 \u2192 set \u03b1}\n    (hmeas : \u2200 i, measurable_set (f i)) (hdis : pairwise (disjoint on f)) :\n  \u03bc (\u22c3 i, f i) = \u2211' i, \u03bc (f i) :=\n\u03bc.m_Union hmeas hdis\n-- QUOTE.\n\n/- TEXT:\nOnce a type has a measure associated with it, we say that a property ``P``\nholds *almost everywhere* if the set of elements where the property fails\nhas measure 0.\nThe collection of properties that hold almost everywhere form a filter,\nbut mathlib introduces special notation for saying that a property holds\nalmost everywhere.\nEXAMPLES: -/\n-- QUOTE:\nexample {P : \u03b1 \u2192 Prop} : (\u2200\u1d50 x \u2202\u03bc, P x) \u2194 \u2200\u1da0 x in \u03bc.ae, P x :=\niff.rfl\n-- QUOTE.\n", "meta": {"author": "avigad", "repo": "mathematics_in_lean_source", "sha": "4eeb8c43762522c1acaa7f799599609d6a48f59e", "save_path": "github-repos/lean/avigad-mathematics_in_lean_source", "path": "github-repos/lean/avigad-mathematics_in_lean_source/mathematics_in_lean_source-4eeb8c43762522c1acaa7f799599609d6a48f59e/lean_source/09_Integration_and_Measure_Theory/source_02_Measure_Theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7260864714380032}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n-/\nimport number_theory.legendre_symbol.jacobi_symbol\n\n/-!\n# A `norm_num` extension for Jacobi and Legendre symbols\n\nWe extend the `tactic.interactive.norm_num` tactic so that it can be used to provably compute\nthe value of the Jacobi symbol `J(a | b)` or the Legendre symbol `legendre_sym p a` when\nthe arguments are numerals.\n\n## Implementation notes\n\nWe use the Law of Quadratic Reciprocity for the Jacobi symbol to compute the value of `J(a | b)`\nefficiently, roughly comparable in effort with the euclidean algorithm for the computation\nof the gcd of `a` and `b`. More precisely, the computation is done in the following steps.\n\n* Use `J(a | 0) = 1` (an artifact of the definition) and `J(a | 1) = 1` to deal\n  with corner cases.\n\n* Use `J(a | b) = J(a % b | b)` to reduce to the case that `a` is a natural number.\n  We define a version of the Jacobi symbol restricted to natural numbers for use in\n  the following steps; see `norm_num.jacobi_sym_nat`. (But we'll continue to write `J(a | b)`\n  in this description.)\n\n* Remove powers of two from `b`. This is done via `J(2a | 2b) = 0` and\n  `J(2a+1 | 2b) = J(2a+1 | b)` (another artifact of the definition).\n\n* Now `0 \u2264 a < b` and `b` is odd. If `b = 1`, then the value is `1`.\n  If `a = 0` (and `b > 1`), then the value is `0`. Otherwise, we remove powers of two from `a`\n  via `J(4a | b) = J(a | b)` and `J(2a | b) = \u00b1J(a | b)`, where the sign is determined\n  by the residue class of `b` mod 8, to reduce to `a` odd.\n\n* Once `a` is odd, we use Quadratic Reciprocity (QR) in the form\n  `J(a | b) = \u00b1J(b % a | a)`, where the sign is determined by the residue classes\n  of `a` and `b` mod 4. We are then back in the previous case.\n\nWe provide customized versions of these results for the various reduction steps,\nwhere we encode the residue classes mod 2, mod 4, or mod 8 by using terms like\n`bit1 (bit0 a)`. In this way, the only divisions we have to compute and prove\nare the ones occurring in the use of QR above.\n-/\n\nsection lemmas\n\nnamespace norm_num\n\n/-- The Jacobi symbol restricted to natural numbers in both arguments. -/\ndef jacobi_sym_nat (a b : \u2115) : \u2124  := jacobi_sym a b\n\n/-!\n### API Lemmas\n\nWe repeat part of the API for `jacobi_sym` with `norm_num.jacobi_sym_nat` and without implicit\narguments, in a form that is suitable for constructing proofs in `norm_num`.\n-/\n\n/-- Base cases: `b = 0`, `b = 1`, `a = 0`, `a = 1`. -/\nlemma jacobi_sym_nat.zero_right (a : \u2115) : jacobi_sym_nat a 0 = 1 :=\nby rwa [jacobi_sym_nat, jacobi_sym.zero_right]\n\nlemma jacobi_sym_nat.one_right (a : \u2115) : jacobi_sym_nat a 1 = 1 :=\nby rwa [jacobi_sym_nat, jacobi_sym.one_right]\n\nlemma jacobi_sym_nat.zero_left_even (b : \u2115) (hb : b \u2260 0) : jacobi_sym_nat 0 (bit0 b) = 0 :=\nby rw [jacobi_sym_nat, nat.cast_zero, jacobi_sym.zero_left (nat.one_lt_bit0 hb)]\n\nlemma jacobi_sym_nat.zero_left_odd (b : \u2115) (hb : b \u2260 0) : jacobi_sym_nat 0 (bit1 b) = 0 :=\nby rw [jacobi_sym_nat, nat.cast_zero, jacobi_sym.zero_left (nat.one_lt_bit1 hb)]\n\nlemma jacobi_sym_nat.one_left_even (b : \u2115) : jacobi_sym_nat 1 (bit0 b) = 1 :=\nby rw [jacobi_sym_nat, nat.cast_one, jacobi_sym.one_left]\n\nlemma jacobi_sym_nat.one_left_odd (b : \u2115) : jacobi_sym_nat 1 (bit1 b) = 1 :=\nby rw [jacobi_sym_nat, nat.cast_one, jacobi_sym.one_left]\n\n/-- Turn a Legendre symbol into a Jacobi symbol. -/\nlemma legendre_sym.to_jacobi_sym (p : \u2115) (pp : fact (p.prime)) (a r : \u2124) (hr : jacobi_sym a p = r) :\n  legendre_sym p a = r :=\nby rwa [@legendre_sym.to_jacobi_sym p pp a]\n\n/-- The value depends only on the residue class of `a` mod `b`. -/\nlemma jacobi_sym.mod_left (a : \u2124) (b ab' : \u2115) (ab r b' : \u2124) (hb' : (b : \u2124) = b')\n  (hab : a % b' = ab) (h : (ab' : \u2124) = ab) (hr : jacobi_sym_nat ab' b = r) :\n  jacobi_sym a b = r :=\nby rw [\u2190 hr, jacobi_sym_nat, jacobi_sym.mod_left, hb', hab, \u2190 h]\n\nlemma jacobi_sym_nat.mod_left (a b ab : \u2115) (r : \u2124) (hab : a % b = ab)\n  (hr : jacobi_sym_nat ab b = r) :\n  jacobi_sym_nat a b = r :=\nby { rw [\u2190 hr, jacobi_sym_nat, jacobi_sym_nat, _root_.jacobi_sym.mod_left a b, \u2190 hab], refl, }\n\n/-- The symbol vanishes when both entries are even (and `b \u2260 0`). -/\nlemma jacobi_sym_nat.even_even (a b : \u2115) (hb\u2080 : b \u2260 0) :\n  jacobi_sym_nat (bit0 a) (bit0 b) = 0 :=\nbegin\n  refine jacobi_sym.eq_zero_iff.mpr \u27e8nat.bit0_ne_zero hb\u2080, \u03bb hf, _\u27e9,\n  have h : 2 \u2223 (bit0 a).gcd (bit0 b) := nat.dvd_gcd two_dvd_bit0 two_dvd_bit0,\n  change 2 \u2223 (bit0 a : \u2124).gcd (bit0 b) at h,\n  rw [\u2190 nat.cast_bit0, \u2190 nat.cast_bit0, hf, \u2190 even_iff_two_dvd] at h,\n  exact nat.not_even_one h,\nend\n\n/-- When `a` is odd and `b` is even, we can replace `b` by `b / 2`. -/\nlemma jacobi_sym_nat.odd_even (a b : \u2115) (r : \u2124) (hr : jacobi_sym_nat (bit1 a) b = r) :\n  jacobi_sym_nat (bit1 a) (bit0 b) = r :=\nbegin\n  have ha : legendre_sym 2 (bit1 a) = 1 :=\n  by simp only [legendre_sym, quadratic_char_apply, quadratic_char_fun_one, int.cast_bit1,\n                char_two.bit1_eq_one, pi.one_apply],\n  cases eq_or_ne b 0 with hb hb,\n  { rw [\u2190 hr, hb, jacobi_sym_nat.zero_right], },\n  { haveI : ne_zero b := \u27e8hb\u27e9, -- for `jacobi_sym.mul_right`\n    rwa [bit0_eq_two_mul b, jacobi_sym_nat, jacobi_sym.mul_right,\n         \u2190 _root_.legendre_sym.to_jacobi_sym, nat.cast_bit1, ha, one_mul], }\nend\n\n/-- If `a` is divisible by `4` and `b` is odd, then we can remove the factor `4` from `a`. -/\nlemma jacobi_sym_nat.double_even (a b : \u2115) (r : \u2124) (hr : jacobi_sym_nat a (bit1 b) = r) :\n  jacobi_sym_nat (bit0 (bit0 a)) (bit1 b) = r :=\nbegin\n  have : ((2 : \u2115) : \u2124).gcd ((bit1 b) : \u2115) = 1,\n  { rw [int.coe_nat_gcd, nat.bit1_eq_succ_bit0, bit0_eq_two_mul b, nat.succ_eq_add_one,\n        nat.gcd_mul_left_add_right, nat.gcd_one_right], },\n  rwa [bit0_eq_two_mul a, bit0_eq_two_mul (2 * a), \u2190 mul_assoc, \u2190 pow_two, jacobi_sym_nat,\n       nat.cast_mul, nat.cast_pow, jacobi_sym.mul_left, jacobi_sym.sq_one' this, one_mul],\nend\n\n/-- If `a` is even and `b` is odd, then we can remove a factor `2` from `a`,\nbut we may have to change the sign, depending on `b % 8`.\nWe give one version for each of the four odd residue classes mod `8`. -/\nlemma jacobi_sym_nat.even_odd\u2081 (a b : \u2115) (r : \u2124)\n  (hr : jacobi_sym_nat a (bit1 (bit0 (bit0 b))) = r) :\n  jacobi_sym_nat (bit0 a) (bit1 (bit0 (bit0 b))) = r :=\nbegin\n  have hb : (bit1 (bit0 (bit0 b))) % 8 = 1,\n  { rw [nat.bit1_mod_bit0, nat.bit0_mod_bit0, nat.bit0_mod_two], },\n  rw [jacobi_sym_nat, bit0_eq_two_mul a, nat.cast_mul, jacobi_sym.mul_left,\n      nat.cast_two, jacobi_sym.at_two (odd_bit1 _), zmod.\u03c7\u2088_nat_mod_eight, hb],\n  norm_num,\n  exact hr,\nend\n\nlemma jacobi_sym_nat.even_odd\u2087 (a b : \u2115) (r : \u2124)\n  (hr : jacobi_sym_nat a (bit1 (bit1 (bit1 b))) = r) :\n  jacobi_sym_nat (bit0 a) (bit1 (bit1 (bit1 b))) = r :=\nbegin\n  have hb : (bit1 (bit1 (bit1 b))) % 8 = 7,\n  { rw [nat.bit1_mod_bit0, nat.bit1_mod_bit0, nat.bit1_mod_two], },\n  rw [jacobi_sym_nat, bit0_eq_two_mul a, nat.cast_mul, jacobi_sym.mul_left,\n      nat.cast_two, jacobi_sym.at_two (odd_bit1 _), zmod.\u03c7\u2088_nat_mod_eight, hb],\n  norm_num,\n  exact hr,\nend\n\nlemma jacobi_sym_nat.even_odd\u2083 (a b : \u2115) (r : \u2124)\n  (hr : jacobi_sym_nat a (bit1 (bit1 (bit0 b))) = r) :\n  jacobi_sym_nat (bit0 a) (bit1 (bit1 (bit0 b))) = -r :=\nbegin\n  have hb : (bit1 (bit1 (bit0 b))) % 8 = 3,\n  { rw [nat.bit1_mod_bit0, nat.bit1_mod_bit0, nat.bit0_mod_two], },\n  rw [jacobi_sym_nat, bit0_eq_two_mul a, nat.cast_mul, jacobi_sym.mul_left,\n      nat.cast_two, jacobi_sym.at_two (odd_bit1 _), zmod.\u03c7\u2088_nat_mod_eight, hb],\n  norm_num,\n  exact hr,\nend\n\nlemma jacobi_sym_nat.even_odd\u2085 (a b : \u2115) (r : \u2124)\n  (hr : jacobi_sym_nat a (bit1 (bit0 (bit1 b))) = r) :\n  jacobi_sym_nat (bit0 a) (bit1 (bit0 (bit1 b))) = -r :=\nbegin\n  have hb : (bit1 (bit0 (bit1 b))) % 8 = 5,\n  { rw [nat.bit1_mod_bit0, nat.bit0_mod_bit0, nat.bit1_mod_two], },\n  rw [jacobi_sym_nat, bit0_eq_two_mul a, nat.cast_mul, jacobi_sym.mul_left,\n      nat.cast_two, jacobi_sym.at_two (odd_bit1 _), zmod.\u03c7\u2088_nat_mod_eight, hb],\n  norm_num,\n  exact hr,\nend\n\n/-- Use quadratic reciproity to reduce to smaller `b`. -/\nlemma jacobi_sym_nat.qr\u2081 (a b : \u2115) (r : \u2124) (hr : jacobi_sym_nat (bit1 b) (bit1 (bit0 a)) = r) :\n  jacobi_sym_nat (bit1 (bit0 a)) (bit1 b) = r :=\nbegin\n  have ha : (bit1 (bit0 a)) % 4 = 1,\n  { rw [nat.bit1_mod_bit0, nat.bit0_mod_two], },\n  have hb := nat.bit1_mod_two,\n  rwa [jacobi_sym_nat, jacobi_sym.quadratic_reciprocity_one_mod_four ha (nat.odd_iff.mpr hb)],\nend\n\nlemma jacobi_sym_nat.qr\u2081_mod (a b ab : \u2115) (r : \u2124) (hab : (bit1 b) % (bit1 (bit0 a)) = ab)\n  (hr : jacobi_sym_nat ab (bit1 (bit0 a)) = r) :\n  jacobi_sym_nat (bit1 (bit0 a)) (bit1 b) = r :=\njacobi_sym_nat.qr\u2081 _ _ _ $ jacobi_sym_nat.mod_left _ _ ab r hab hr\n\nlemma jacobi_sym_nat.qr\u2081' (a b : \u2115) (r : \u2124) (hr : jacobi_sym_nat (bit1 (bit0 b)) (bit1 a) = r) :\n  jacobi_sym_nat (bit1 a) (bit1 (bit0 b)) = r :=\nbegin\n  have hb : (bit1 (bit0 b)) % 4 = 1,\n  { rw [nat.bit1_mod_bit0, nat.bit0_mod_two], },\n  have ha := nat.bit1_mod_two,\n  rwa [jacobi_sym_nat, \u2190 jacobi_sym.quadratic_reciprocity_one_mod_four hb (nat.odd_iff.mpr ha)]\nend\n\nlemma jacobi_sym_nat.qr\u2081'_mod (a b ab : \u2115) (r : \u2124) (hab : (bit1 (bit0 b)) % (bit1 a) = ab)\n  (hr : jacobi_sym_nat ab (bit1 a) = r) :\n  jacobi_sym_nat (bit1 a) (bit1 (bit0 b)) = r :=\njacobi_sym_nat.qr\u2081' _ _ _ $ jacobi_sym_nat.mod_left _ _ ab r hab hr\n\nlemma jacobi_sym_nat.qr\u2083 (a b : \u2115) (r : \u2124)\n  (hr : jacobi_sym_nat (bit1 (bit1 b)) (bit1 (bit1 a)) = r) :\n  jacobi_sym_nat (bit1 (bit1 a)) (bit1 (bit1 b)) = -r :=\nbegin\n  have hb : (bit1 (bit1 b)) % 4 = 3,\n  { rw [nat.bit1_mod_bit0, nat.bit1_mod_two], },\n  have ha : (bit1 (bit1 a)) % 4 = 3,\n  { rw [nat.bit1_mod_bit0, nat.bit1_mod_two], },\n  rwa [jacobi_sym_nat, jacobi_sym.quadratic_reciprocity_three_mod_four ha hb, neg_inj]\nend\n\nlemma jacobi_sym_nat.qr\u2083_mod (a b ab : \u2115) (r : \u2124) (hab : (bit1 (bit1 b)) % (bit1 (bit1 a)) = ab)\n  (hr : jacobi_sym_nat ab (bit1 (bit1 a)) = r) :\n  jacobi_sym_nat (bit1 (bit1 a)) (bit1 (bit1 b)) = -r :=\njacobi_sym_nat.qr\u2083 _ _ _ $ jacobi_sym_nat.mod_left _ _ ab r hab hr\n\nend norm_num\n\nend lemmas\n\nsection evaluation\n\n/-!\n### Certified evaluation of the Jacobi symbol\n\nThe following functions recursively evaluate a Jacobi symbol and construct the\ncorresponding proof term.\n-/\n\nnamespace norm_num\nopen tactic\n\n/-- This evaluates `r := jacobi_sym_nat a b` recursively using quadratic reciprocity\nand produces a proof term for the equality, assuming that `a < b` and `b` is odd. -/\nmeta def prove_jacobi_sym_odd : instance_cache \u2192 instance_cache \u2192 expr \u2192 expr \u2192\n   tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| zc nc ea eb := do\n  match match_numeral eb with\n  | match_numeral_result.one :=  -- `b = 1`, result is `1`\n    pure (zc, nc, `(1 : \u2124), `(jacobi_sym_nat.one_right).mk_app [ea])\n  | match_numeral_result.bit1 eb\u2081 := do -- `b > 1` (recall that `b` is odd)\n    match match_numeral ea with\n    | match_numeral_result.zero := do -- `a = 0`, result is `0`\n      b \u2190 eb\u2081.to_nat,\n      (nc, phb\u2080) \u2190 prove_ne nc eb\u2081 `(0 : \u2115) b 0, -- proof of `b \u2260 0`\n      pure (zc, nc, `(0 : \u2124), `(jacobi_sym_nat.zero_left_odd).mk_app [eb\u2081, phb\u2080])\n    | match_numeral_result.one := do -- `a = 1`, result is `1`\n      pure (zc, nc, `(1 : \u2124), `(jacobi_sym_nat.one_left_odd).mk_app [eb\u2081])\n    | match_numeral_result.bit0 ea\u2081 := do -- `a` is even; check if divisible by `4`\n      match match_numeral ea\u2081 with\n      | match_numeral_result.bit0 ea\u2082 := do\n        (zc, nc, er, p) \u2190 prove_jacobi_sym_odd zc nc ea\u2082 eb, -- compute `jacobi_sym_nat (a / 4) b`\n        pure (zc, nc, er, `(jacobi_sym_nat.double_even).mk_app [ea\u2082, eb\u2081, er, p])\n      | _ := do -- reduce to `a / 2`; need to consider `b % 8`\n        (zc, nc, er, p) \u2190 prove_jacobi_sym_odd zc nc ea\u2081 eb, -- compute `jacobi_sym_nat (a / 2) b`\n        match match_numeral eb\u2081 with\n        -- | match_numeral_result.zero := -- `b = 1`, not reached\n        | match_numeral_result.one := do -- `b = 3`\n          r \u2190 er.to_int,\n          (zc, er') \u2190 zc.of_int (- r),\n          pure (zc, nc, er', `(jacobi_sym_nat.even_odd\u2083).mk_app [ea\u2081, `(0 : \u2115), er, p])\n        | match_numeral_result.bit0 eb\u2082 := do -- `b % 4 = 1`\n          match match_numeral eb\u2082 with\n          -- | match_numeral_result.zero := -- not reached\n          | match_numeral_result.one := do -- `b = 5`\n            r \u2190 er.to_int,\n            (zc, er') \u2190 zc.of_int (- r),\n            pure (zc, nc, er', `(jacobi_sym_nat.even_odd\u2085).mk_app [ea\u2081, `(0 : \u2115), er, p])\n          | match_numeral_result.bit0 eb\u2083 := do -- `b % 8 = 1`\n            pure (zc, nc, er, `(jacobi_sym_nat.even_odd\u2081).mk_app [ea\u2081, eb\u2083, er, p])\n          | match_numeral_result.bit1 eb\u2083 := do -- `b % 8 = 5`\n            r \u2190 er.to_int,\n            (zc, er') \u2190 zc.of_int (- r),\n            pure (zc, nc, er', `(jacobi_sym_nat.even_odd\u2085).mk_app [ea\u2081, eb\u2083, er, p])\n          | _ := failed\n          end\n        | match_numeral_result.bit1 eb\u2082 := do -- `b % 4 = 3`\n          match match_numeral eb\u2082 with\n          -- | match_numeral_result.zero := -- not reached\n          | match_numeral_result.one := do -- `b = 7`\n            pure (zc, nc, er, `(jacobi_sym_nat.even_odd\u2087).mk_app [ea\u2081, `(0 : \u2115), er, p])\n          | match_numeral_result.bit0 eb\u2083 := do -- `b % 8 = 3`\n            r \u2190 er.to_int,\n            (zc, er') \u2190 zc.of_int (- r),\n            pure (zc, nc, er', `(jacobi_sym_nat.even_odd\u2083).mk_app [ea\u2081, eb\u2083, er, p])\n          | match_numeral_result.bit1 eb\u2083 := do -- `b % 8 = 7`\n            pure (zc, nc, er, `(jacobi_sym_nat.even_odd\u2087).mk_app [ea\u2081, eb\u2083, er, p])\n          | _ := failed\n          end\n        | _ := failed\n        end\n      end\n    | match_numeral_result.bit1 ea\u2081 := do -- `a` is odd\n      -- use Quadratic Reciprocity; look at `a` and `b` mod `4`\n      (nc, bma, phab) \u2190 prove_div_mod nc eb ea tt, -- compute `b % a`\n      (zc, nc, er, p) \u2190 prove_jacobi_sym_odd zc nc bma ea, -- compute `jacobi_sym_nat (b % a) a`\n      match match_numeral ea\u2081 with\n      -- | match_numeral_result.zero :=  -- `a = 1`, not reached\n      | match_numeral_result.one := do -- `a = 3`; need to consider `b`\n        match match_numeral eb\u2081 with\n        -- | match_numeral_result.zero := -- `b = 1`, not reached\n        -- | match_numeral_result.one := -- `b = 3`, not reached, since `a < b`\n        | match_numeral_result.bit0 eb\u2082 := do -- `b % 4 = 1`\n          pure (zc, nc, er, `(jacobi_sym_nat.qr\u2081'_mod).mk_app [ea\u2081, eb\u2082, bma, er, phab, p])\n        | match_numeral_result.bit1 eb\u2082 := do -- `b % 4 = 3`\n          r \u2190 er.to_int,\n          (zc, er') \u2190 zc.of_int (- r),\n          pure (zc, nc, er', `(jacobi_sym_nat.qr\u2083_mod).mk_app [`(0 : \u2115), eb\u2082, bma, er, phab, p])\n        | _ := failed\n        end\n      | match_numeral_result.bit0 ea\u2082 := do -- `a % 4 = 1`\n        pure (zc, nc, er, `(jacobi_sym_nat.qr\u2081_mod).mk_app [ea\u2082, eb\u2081, bma, er, phab, p])\n      | match_numeral_result.bit1 ea\u2082 := do -- `a % 4 = 3`; need to consider `b`\n        match match_numeral eb\u2081 with\n        -- | match_numeral_result.zero := do -- `b = 1`, not reached\n        -- | match_numeral_result.one := do -- `b = 3`, not reached, since `a < b`\n        | match_numeral_result.bit0 eb\u2082 := do -- `b % 4 = 1`\n          pure (zc, nc, er, `(jacobi_sym_nat.qr\u2081'_mod).mk_app [ea\u2081, eb\u2082, bma, er, phab, p])\n        | match_numeral_result.bit1 eb\u2082 := do -- `b % 4 = 3`\n          r \u2190 er.to_int,\n          (zc, er') \u2190 zc.of_int (- r),\n          pure (zc, nc, er', `(jacobi_sym_nat.qr\u2083_mod).mk_app [ea\u2082, eb\u2082, bma, er, phab, p])\n        | _ := failed\n        end\n      | _ := failed\n      end\n    | _ := failed\n    end\n  | _ := failed\n  end\n\n/-- This evaluates `r := jacobi_sym_nat a b` and produces a proof term for the equality\nby removing powers of `2` from `b` and then calling `prove_jacobi_sym_odd`. -/\nmeta def prove_jacobi_sym_nat : instance_cache \u2192 instance_cache \u2192 expr \u2192 expr \u2192\n   tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| zc nc ea eb := do\n  match match_numeral eb with\n  | match_numeral_result.zero := -- `b = 0`, result is `1`\n    pure (zc, nc, `(1 : \u2124), `(jacobi_sym_nat.zero_right).mk_app [ea])\n  | match_numeral_result.one :=  -- `b = 1`, result is `1`\n    pure (zc, nc, `(1 : \u2124), `(jacobi_sym_nat.one_right).mk_app [ea])\n  | match_numeral_result.bit0 eb\u2081 := -- `b` is even and nonzero\n    match match_numeral ea with\n    | match_numeral_result.zero := do -- `a = 0`, result is `0`\n      b \u2190 eb\u2081.to_nat,\n      (nc, phb\u2080) \u2190 prove_ne nc eb\u2081 `(0 : \u2115) b 0, -- proof of `b \u2260 0`\n      pure (zc, nc, `(0 : \u2124), `(jacobi_sym_nat.zero_left_even).mk_app [eb\u2081, phb\u2080])\n    | match_numeral_result.one := do -- `a = 1`, result is `1`\n      pure (zc, nc, `(1 : \u2124), `(jacobi_sym_nat.one_left_even).mk_app [eb\u2081])\n    | match_numeral_result.bit0 ea\u2081 := do -- `a` is even, result is `0`\n      b \u2190 eb\u2081.to_nat,\n      (nc, phb\u2080) \u2190 prove_ne nc eb\u2081 `(0 : \u2115) b 0, -- proof of `b \u2260 0`\n      let er : expr := `(0 : \u2124),\n      pure (zc, nc, er, `(jacobi_sym_nat.even_even).mk_app [ea\u2081, eb\u2081, phb\u2080])\n    | match_numeral_result.bit1 ea\u2081 := do -- `a` is odd, reduce to `b / 2`\n      (zc, nc, er, p) \u2190 prove_jacobi_sym_nat zc nc ea eb\u2081,\n      pure (zc, nc, er, `(jacobi_sym_nat.odd_even).mk_app [ea\u2081, eb\u2081, er, p])\n    | _ := failed\n    end\n  | match_numeral_result.bit1 eb\u2081 := do -- `b` is odd\n    a \u2190 ea.to_nat,\n    b \u2190 eb.to_nat,\n    if b \u2264 a then do -- reduce to `jacobi_sym_nat (a % b) b`\n      (nc, amb, phab) \u2190 prove_div_mod nc ea eb tt, -- compute `a % b`\n      (zc, nc, er, p) \u2190 prove_jacobi_sym_odd zc nc amb eb, -- compute `jacobi_sym_nat (a % b) b`\n      pure (zc, nc, er, `(jacobi_sym_nat.mod_left).mk_app [ea, eb, amb, er, phab, p])\n    else\n    prove_jacobi_sym_odd zc nc ea eb\n  | _ := failed\n  end\n\n/-- This evaluates `r := jacobi_sym a b` and produces a proof term for the equality.\nThis is done by reducing to `r := jacobi_sym_nat (a % b) b`. -/\nmeta def prove_jacobi_sym : instance_cache \u2192 instance_cache \u2192 expr \u2192 expr\n    \u2192 tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n| zc nc ea eb := do\n  match match_numeral eb with -- deal with simple cases right away\n  | match_numeral_result.zero := pure (zc, nc, `(1 : \u2124), `(jacobi_sym.zero_right).mk_app [ea])\n  | match_numeral_result.one := pure (zc, nc, `(1 : \u2124), `(jacobi_sym.one_right).mk_app [ea])\n  | _ := do -- Now `1 < b`. Compute `jacobi_sym_nat (a % b) b` instead.\n    b \u2190 eb.to_nat,\n    (zc, eb') \u2190 zc.of_int (b : \u2124),\n    -- Get the proof that `(b : \u2124) = b'` (where `eb'` is the numeral representing `b'`).\n    -- This is important to avoid inefficient matching between the two.\n    (zc, nc, eb\u2081, pb') \u2190 prove_nat_uncast zc nc eb',\n    (zc, amb, phab) \u2190 prove_div_mod zc ea eb' tt, -- compute `a % b`\n    (zc, nc, amb', phab') \u2190 prove_nat_uncast zc nc amb, -- `a % b` as a natural number\n    (zc, nc, er, p) \u2190 prove_jacobi_sym_nat zc nc amb' eb\u2081, -- compute `jacobi_sym_nat (a % b) b`\n    pure (zc, nc, er,\n          `(jacobi_sym.mod_left).mk_app [ea, eb\u2081, amb', amb, er, eb', pb', phab, phab', p])\n  end\n\nend norm_num\n\nend evaluation\n\nsection tactic\n\n/-!\n### The `norm_num` plug-in\n-/\n\nnamespace tactic\nnamespace norm_num\n\n/-- This is the `norm_num` plug-in that evaluates Jacobi and Legendre symbols. -/\n@[norm_num] meta def eval_jacobi_sym : expr \u2192 tactic (expr \u00d7 expr)\n| `(jacobi_sym %%ea %%eb) := do -- Jacobi symbol\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> norm_num.prove_jacobi_sym zc nc ea eb\n| `(norm_num.jacobi_sym_nat %%ea %%eb) := do -- Jacobi symbol on natural numbers\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (prod.snd \u2218 prod.snd) <$> norm_num.prove_jacobi_sym_nat zc nc ea eb\n| `(@legendre_sym %%ep %%inst %%ea) := do -- Legendre symbol\n    zc \u2190 mk_instance_cache `(\u2124),\n    nc \u2190 mk_instance_cache `(\u2115),\n    (zc, nc, er, pf) \u2190 norm_num.prove_jacobi_sym zc nc ea ep,\n    pure (er, `(norm_num.legendre_sym.to_jacobi_sym).mk_app [ep, inst, ea, er, pf])\n| _ := failed\n\nend norm_num\nend tactic\n\nend tactic\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/legendre_symbol/norm_num.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7259872281897056}}
{"text": "import intro.level1 --hide\n/-\nWe can state lemmas assuming hypotheses with similar notation as we made a lemma\ndependent on natural numbers before.\n\nThe `rewrite` tactic can then be used to rewrite a hypothesis, after all we can substitute\nthings we know to be equal in facts we know as well as substituting into what we are trying to prove.\n\n### Example:\nYou can use `rewrite` to change a hypothesis as well.\nFor example, if your goal state looks like this:\n```\nn m : \u2115\nh1 : n + 1 = 7\nh2 : m = n + 1\n\u22a2 m + 2 = 9\n```\nthen `rewrite h2 at h1` will turn `h1` into `h1 : m = 7`.\n\nBelow are two useful results you can use to finish this level.\n-/\n\n/- Axiom :\nlemma add_zero : \u2200 x, x + 0 = x\n-/\nlemma add_zero : \u2200 x, x + 0 = x\n:= nat.add_zero --hide\n/- Axiom :\nlemma one_mul : \u2200 x, 1 * x = x\n-/\nlemma one_mul : \u2200 x, 1 * x = x\n:= nat.one_mul --hide\n\n/- Hint : Click here for a hint, in case you get stuck.\nDelete `sorry` and type `rw h,` (don't forget the comma!). Lean tries `refl` afterwards,\nso you will see that this suffices.\nDelete `sorry` and type `rewrite add_zero x at hx,` (don't forget the comma!), as a first step of the proof.\nIn fact, in this situation the `rewrite` tactic can infer that the argument of `add_zero` should be `x`,\nso one could leave out the argument `x`, i.e. simply write `rewrite add_zero at hx,` (don't forget the comma!).\n-/\n\n/- Lemma : no-side-bar\n-/\nlemma level2 (x y : \u2115) (hx : x + 0 = 1 * y) : x + y = y + y :=\nbegin\n  rw add_zero at hx,\n  rw one_mul at hx,\n  rw hx,\n\n\n\nend\n", "meta": {"author": "alexjbest", "repo": "CAP-game", "sha": "d823def7325d7142d61e766b2e027f936685a8ff", "save_path": "github-repos/lean/alexjbest-CAP-game", "path": "github-repos/lean/alexjbest-CAP-game/CAP-game-d823def7325d7142d61e766b2e027f936685a8ff/src/intro/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7259738415013348}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.finset.finsupp\n! leanprover-community/mathlib commit 59694bd07f0a39c5beccba34bd9f413a160782bf\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.BigOperators.Finsupp\nimport Mathlib.Data.Finset.Pointwise\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Data.Fintype.BigOperators\n\n/-!\n# Finitely supported product of finsets\n\nThis file defines the finitely supported product of finsets as a `Finset (\u03b9 \u2192\u2080 \u03b1)`.\n\n## Main declarations\n\n* `Finset.finsupp`: Finitely supported product of finsets. `s.finset t` is the product of the `t i`\n  over all `i \u2208 s`.\n* `Finsupp.pi`: `f.pi` is the finset of `Finsupp`s whose `i`-th value lies in `f i`. This is the\n  special case of `Finset.finsupp` where we take the product of the `f i` over the support of `f`.\n\n## Implementation notes\n\nWe make heavy use of the fact that `0 : Finset \u03b1` is `{0}`. This scalar actions convention turns out\nto be precisely what we want here too.\n-/\n\n\nnoncomputable section\n\nopen Finsupp\n\nopen BigOperators Classical Pointwise\n\nvariable {\u03b9 \u03b1 : Type _} [Zero \u03b1] {s : Finset \u03b9} {f : \u03b9 \u2192\u2080 \u03b1}\n\nnamespace Finset\n\n/-- Finitely supported product of finsets. -/\nprotected def finsupp (s : Finset \u03b9) (t : \u03b9 \u2192 Finset \u03b1) : Finset (\u03b9 \u2192\u2080 \u03b1) :=\n  (s.pi t).map \u27e8indicator s, indicator_injective s\u27e9\n#align finset.finsupp Finset.finsupp\n\ntheorem mem_finsupp_iff {t : \u03b9 \u2192 Finset \u03b1} : f \u2208 s.finsupp t \u2194 f.support \u2286 s \u2227 \u2200 i \u2208 s, f i \u2208 t i :=\n  by\n  refine' mem_map.trans \u27e8_, _\u27e9\n  \u00b7 rintro \u27e8f, hf, rfl\u27e9\n    refine' \u27e8support_indicator_subset _ _, fun i hi => _\u27e9\n    convert mem_pi.1 hf i hi\n    exact indicator_of_mem hi _\n  \u00b7 refine' fun h => \u27e8fun i _ => f i, mem_pi.2 h.2, _\u27e9\n    ext i\n    exact ite_eq_left_iff.2 fun hi => (not_mem_support_iff.1 fun H => hi <| h.1 H).symm\n#align finset.mem_finsupp_iff Finset.mem_finsupp_iff\n\n/-- When `t` is supported on `s`, `f \u2208 s.finsupp t` precisely means that `f` is pointwise in `t`. -/\n@[simp]\ntheorem mem_finsupp_iff_of_support_subset {t : \u03b9 \u2192\u2080 Finset \u03b1} (ht : t.support \u2286 s) :\n    f \u2208 s.finsupp t \u2194 \u2200 i, f i \u2208 t i := by\n  refine'\n    mem_finsupp_iff.trans\n      (forall_and.symm.trans <|\n        forall_congr' fun i =>\n          \u27e8fun h => _, fun h =>\n            \u27e8fun hi => ht <| mem_support_iff.2 fun H => mem_support_iff.1 hi _, fun _ => h\u27e9\u27e9)\n  \u00b7 by_cases hi : i \u2208 s\n    \u00b7 exact h.2 hi\n    \u00b7 rw [not_mem_support_iff.1 (mt h.1 hi), not_mem_support_iff.1 fun H => hi <| ht H]\n      exact zero_mem_zero\n  \u00b7 rwa [H, mem_zero] at h\n#align finset.mem_finsupp_iff_of_support_subset Finset.mem_finsupp_iff_of_support_subset\n\n@[simp]\ntheorem card_finsupp (s : Finset \u03b9) (t : \u03b9 \u2192 Finset \u03b1) :\n    (s.finsupp t).card = \u220f i in s, (t i).card :=\n  (card_map _).trans <| card_pi _ _\n#align finset.card_finsupp Finset.card_finsupp\n\nend Finset\n\nopen Finset\n\nnamespace Finsupp\n\n/-- Given a finitely supported function `f : \u03b9 \u2192\u2080 Finset \u03b1`, one can define the finset\n`f.pi` of all finitely supported functions whose value at `i` is in `f i` for all `i`. -/\ndef pi (f : \u03b9 \u2192\u2080 Finset \u03b1) : Finset (\u03b9 \u2192\u2080 \u03b1) :=\n  f.support.finsupp f\n#align finsupp.pi Finsupp.pi\n\n@[simp]\ntheorem mem_pi {f : \u03b9 \u2192\u2080 Finset \u03b1} {g : \u03b9 \u2192\u2080 \u03b1} : g \u2208 f.pi \u2194 \u2200 i, g i \u2208 f i :=\n  mem_finsupp_iff_of_support_subset <| Subset.refl _\n#align finsupp.mem_pi Finsupp.mem_pi\n\n@[simp]\ntheorem card_pi (f : \u03b9 \u2192\u2080 Finset \u03b1) : f.pi.card = f.prod fun i => (f i).card := by\n  rw [pi, card_finsupp]\n  exact Finset.prod_congr rfl fun i _ => by simp only [Pi.nat_apply, Nat.cast_id]\n#align finsupp.card_pi Finsupp.card_pi\n\nend Finsupp\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Finset/Finsupp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.725973838813899}}
{"text": "-- Teor\u00eda de grupos\n-- =====================================================================\n\nimport tactic\n\n-- Nota t\u00e9cnica: Trabajamos en un espacio de nombres `oculto` porque\n-- Lean ya tiene `group`. Ahora nuestra definici\u00f3n de grupo se llamar\u00e1\n-- realmente `oculto.group`.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir el espacio de nombres\n-- ---------------------------------------------------------------------\n\nnamespace oculto\n\n-- =====================================================================\n-- \u00a7 Definici\u00f3n de grupo                                              --\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase `group` como una extensi\u00f3n de las clases\n-- `has_mul`, `has_one` y `has_inv` que verifica las propiedades\n--    asociativa               : \u2200 (a b c : G), (a * b) * c = a * (b * c)\n--    neutro por la izquierda  : \u2200 (a : G), 1 * a = a\n--    inverso por la izquierda : \u2200 (a : G), a\u207b\u00b9 * a = 1\n-- ---------------------------------------------------------------------\n\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\n-- La forma de decir \"sea G un grupo\" ahora es `(G : Type) [group G]`\n\n-- Formalmente, un t\u00e9rmino de tipo `grupo G` consta de\n-- + la definici\u00f3n de una operaci\u00f3n interna: * : G \u2192 G \u2192 G\n-- + la definici\u00f3n de un elemento neutro: 1 : G\n-- + la definici\u00f3n de una operaci\u00f3n inversa: (\u207b\u00b9) : G \u2192 G\n-- + la 3 pruebas de los 3 axiomas.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir el espacio de nombres `group`\n-- ---------------------------------------------------------------------\n\nnamespace group\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir `G` como una variable sobre grupos.\n-- ---------------------------------------------------------------------\n\nvariables {G : Type} [group G]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que en los grupos se cumple la propiedad\n-- cancelativa por la izquierda\n--    a * b = a * c \u2192 b = c\n-- ---------------------------------------------------------------------\n\nlemma mul_left_cancel\n  (a b c : G)\n  (Habac : a * b = a * c)\n  : b = c :=\nbegin\n calc b = 1 * b         : by rw one_mul\n    ... = (a\u207b\u00b9 * a) * b : by rw mul_left_inv\n    ... = a\u207b\u00b9 * (a * b) : by rw mul_assoc\n    ... = a\u207b\u00b9 * (a * c) : by rw Habac\n    ... = (a\u207b\u00b9 * a) * c : by rw mul_assoc\n    ... = 1 * c         : by rw mul_left_inv\n    ... = c             : by rw one_mul\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    \u2200 a x y : G, x = a\u207b\u00b9 * y \u2192 a * x = y\n-- ---------------------------------------------------------------------\n\nlemma mul_eq_of_eq_inv_mul\n  {a x y : G}\n  (h : x = a\u207b\u00b9 * y)\n  : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rw \u2190mul_assoc,\n  rw mul_left_inv,\n  rwa one_mul,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir a, b, c, x e y como variables sobre G.\n-- ---------------------------------------------------------------------\n\nvariables (a b c x y : G)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio [KB-R11). Demostrar que 1 es neutro por la derecha; es\n-- decir,\n--    a * 1 = a\n-- ---------------------------------------------------------------------\n\n@[simp] theorem mul_one :\n  a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_left_inv,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio (KB-R13). Demostrar que\n--    a * a\u207b\u00b9 = 1\n-- ---------------------------------------------------------------------\n\n@[simp] theorem mul_right_inv :\n  a * a\u207b\u00b9 = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\n-- =====================================================================\n-- \u00a7 Simplificador de Lean                                            --\n-- =====================================================================\n\n-- Un humano ve \"a * a\u207b\u00b9\" en la teor\u00eda de grupos y lo reemplaza\n-- instant\u00e1neamente con \"1\".\n--\n-- Vamos a entrenar una IA simple llamada \"simp\" para que haga lo\n-- mismo.\n--\n-- El simplificador de Lean `simp` es un \"sistema de reescritura de\n-- t\u00e9rminos\". Esto significa que si le ense\u00f1as un mont\u00f3n de teoremas de\n-- la forma `A = B` o `P \u2194 Q` (etiquet\u00e1ndolos con el atributo `@[simp]`)\n-- y luego le das un objetivo complicado, como por ejemplo:\n--    (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1\n-- Lean intentar\u00e1 usar la t\u00e1ctica `rw` tanto como pueda, usando los\n-- lemas que se les ha ense\u00f1ado, en un intento de simplificar el\n-- objetivo. Si se las arregla para resolverlo por completo, \u00a1entonces\n-- genial! Si no es as\u00ed, pero piensas que deber\u00eda haberlo hecho, es\n-- posible que tengas que etiquetar m\u00e1s lemas con `@[simp]`.\n--\n-- `simp` solo debe usarse para cerrar completamente los objetivos.\n--\n-- Ahora vamos a entrenar al simplificador para resolver el ejemplo\n-- anterior (de hecho, estamos entren\u00e1ndolo para reducir un elemento\n-- arbitrario de un grupo libre en una forma normal \u00fanica, por lo que\n-- resolver\u00e1 cualquier igualdad que sea verdadera para todos los grupos,\n-- como en el ejemplo anterior).\n--\n-- Notal importante: El simplificador de Lean hace una serie de\n-- reescrituras, cada una reemplazando algo con algo m\u00e1s simple. \u00a1Pero\n-- el simplificador siempre reescribir\u00e1 de izquierda a derecha! Si le\n-- dice que `A = B` es un lema de simplificaci\u00f3n, entonces reemplazar\u00e1\n-- las `A` por las `B`, pero nunca reemplazar\u00e1 las `B` por las `A`.\n--\n-- Si etiqueta una prueba de `A = B` con `@[simp]` y tambi\u00e9n etiqueta\n-- una prueba de `B = A` con `@[simp]`, entonces el simplificador se\n-- atascar\u00e1 en un bucle infinito cuando se encuentra con una \"A\".\n--\n-- La igualdad no debe considerarse aqu\u00ed sim\u00e9trica.\n--\n-- Dado que el simplificador funciona de izquierda a derecha, es\n-- importante observar que si `A = B` es un lema de simplificaci\u00f3n,\n-- entonces `B` deber\u00eda ser m\u00e1s simple que `A`.\n--\n-- No es una coincidencia que en los teoremas a continuaci\u00f3n\n--    `@[simp] theorem mul_one (a : G) : a * 1 = a`\n--    `@[simp] theorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n-- el lado derecho es m\u00e1s simple que el lado izquierdo.\n--\n-- Ser\u00eda un desastre etiquetar `a = a * 1` con la etiqueta\n-- `@[simp]`. \u00bfPuedes ver por qu\u00e9?\n--\n-- \u00a1Entrenemos el simplificador de Lean! Ense\u00f1\u00e9mosle los axiomas de un\n-- grupo a continuaci\u00f3n. Ya hemos visto los axiomas, por lo que tenemos\n-- que etiquetarlos con el atributo `@ [simp]`.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Etiquetar como reglas de simplificaci\u00f3n los axiomas\n-- one_mul (KB-R1), mul_left_inv (KB-R2) y mul_assoc (KB-R3).\n-- ---------------------------------------------------------------------\n\nattribute [simp] one_mul mul_left_inv mul_assoc\n\n-- ---------------------------------------------------------------------\n-- Ejercicio (KB-R4). Demostrar que\n--    a\u207b\u00b9 * (a * b) = b\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  a\u207b\u00b9 * (a * b) = b :=\nbegin\n  rw \u2190 mul_assoc,\n  simp,\nend\n\n-- 2\u00aa demostraci\u00f3n\n@[simp] lemma inv_mul_cancel_left :\n  a\u207b\u00b9 * (a * b) = b :=\nbegin\n  rw \u2190 mul_assoc,\n  -- squeeze_simp,\n  simp only [one_mul,\n             mul_left_inv],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio (KB-R14). Demostrar que\n--    a * (a\u207b\u00b9 * b) = b\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  a * (a\u207b\u00b9 * b) = b :=\nbegin\n  rw \u2190mul_assoc,\n  simp,\nend\n\n-- 2\u00aa demostraci\u00f3n\n@[simp] lemma mul_inv_cancel_left :\n  a * (a\u207b\u00b9 * b) = b :=\nbegin\n  rw \u2190mul_assoc,\n  -- squeeze_simp,\n  simp only [one_mul,\n             mul_right_inv],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio (KB-R17). Demostrar que\n--    (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel (a * b),\n  rw mul_right_inv,\n  simp,\nend\n\n-- 2\u00aa demostraci\u00f3n\n@[simp] lemma inv_mul :\n  (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel (a * b),\n  rw mul_right_inv,\n  -- squeeze_simp,\n  simp only [mul_assoc,\n             mul_inv_cancel_left,\n             mul_right_inv]\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio (KB-R8). Demostrar que\n--    (1 : G)\u207b\u00b9 = 1\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (1 : G)\u207b\u00b9 = 1 :=\nbegin\n  apply mul_left_cancel (1 : G),\n  rw mul_right_inv,\n  simp,\nend\n\n-- 1\u00aa demostraci\u00f3n\n@[simp] lemma one_inv :\n  (1 : G)\u207b\u00b9 = 1 :=\nbegin\n  apply mul_left_cancel (1 : G),\n  rw mul_right_inv,\n  -- squeeze_simp,\n  simp only [one_mul],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio (KB-R12). Demostrar que\n--    (a \u207b\u00b9) \u207b\u00b9 = a\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (a \u207b\u00b9) \u207b\u00b9 = a :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  simp,\nend\n\n-- 2\u00aa demostraci\u00f3n\n@[simp] lemma inv_inv :\n  (a \u207b\u00b9) \u207b\u00b9 = a :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  -- squeeze_simp,\n  simp only [mul_right_inv,\n             mul_left_inv],\nend\n\n-- La raz\u00f3n para elegir estos cinco lemas es https://bit.ly/2YyZdhi\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1\n-- ---------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1 :=\n  by simp\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1 :=\n-- by squeeze_simp\nby simp only [mul_one,\n              mul_assoc,\n              mul_right_inv,\n              inv_inv,\n              mul_left_inv]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * c = b \u2192 a = b * c\u207b\u00b9\n-- ---------------------------------------------------------------------\n\nlemma eq_mul_inv_of_mul_eq\n  {a b c : G}\n  (h : a * c = b)\n  : a = b * c\u207b\u00b9 :=\nbegin\n  rw \u2190 h,\n  simp,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    b * a = c \u2192 a = b\u207b\u00b9 * c\n-- ---------------------------------------------------------------------\n\nlemma eq_inv_mul_of_mul_eq\n  {a b c : G}\n  (h : b * a = c)\n  : a = b\u207b\u00b9 * c :=\nbegin\n  rw \u2190 h,\n  simp,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * b = b \u2194 a = 1\n-- ---------------------------------------------------------------------\n\nlemma mul_left_eq_self\n  {a b : G}\n  : a * b = b \u2194 a = 1 :=\nbegin\n  split,\n  { intro h,\n    replace h := eq_mul_inv_of_mul_eq h,\n    simp [h] },\n  { intro h,\n    rw [h, one_mul] }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * b = a \u2194 b = 1\n-- ---------------------------------------------------------------------\n\nlemma mul_right_eq_self\n  {a b : G}\n  : a * b = a \u2194 b = 1 :=\nbegin\n  split,\n  { intro h,\n    replace h := eq_inv_mul_of_mul_eq h,\n    simp [h] },\n  { rintro rfl,\n    simp },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * b = 1 \u2192 a = b\u207b\u00b9\n-- ---------------------------------------------------------------------\n\nlemma eq_inv_of_mul_eq_one\n  {a b : G}\n  (h : a * b = 1)\n  : a = b\u207b\u00b9 :=\nbegin\n  convert eq_mul_inv_of_mul_eq h,\n  simp,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * b = 1 \u2192 a\u207b\u00b9 = b\n-- ---------------------------------------------------------------------\n\nlemma inv_eq_of_mul_eq_one\n  {a b : G}\n  (h : a * b = 1)\n  : a\u207b\u00b9 = b :=\nbegin\n  replace h := eq_mul_inv_of_mul_eq h,\n  simp [h],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    \u2200 x : G, e * x = x \u2192 e = 1\n-- ---------------------------------------------------------------------\n\nlemma unique_left_id {e : G} (h : \u2200 x : G, e * x = x) : e = 1 :=\ncalc e = e * 1 : by rw mul_one\n  ...  = 1     : by rw h 1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * b = 1 \u2192 b = a\u207b\u00b9\n-- ---------------------------------------------------------------------\n\nlemma unique_right_inv\n  {a b : G}\n  (h : a * b = 1)\n  : b = a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel a,\n  simp [h],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * x = a * y \u2194 x = y\n-- ---------------------------------------------------------------------\n\nlemma mul_left_cancel_iff\n  (a x y : G)\n  : a * x = a * y \u2194 x = y :=\nbegin\n  split,\n  { apply mul_left_cancel, },\n  { intro hxy,\n    rwa hxy, },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    x * a = y * a \u2192 x = y\n-- ---------------------------------------------------------------------\n\nlemma mul_right_cancel\n  (a x y : G)\n  (Habac : x * a = y * a)\n  : x = y :=\ncalc x = x * 1         : by rw mul_one\n  ...  = x * (a * a\u207b\u00b9) : by rw mul_right_inv\n  ...  = x * a * a\u207b\u00b9   : by rw mul_assoc\n  ...  = y * a * a\u207b\u00b9   : by rw Habac\n  ...  = y * (a * a\u207b\u00b9) : by rw mul_assoc\n  ...  = y * 1         : by rw mul_right_inv\n  ...  = y             : by rw mul_one\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a\u207b\u00b9 = b\u207b\u00b9 \u2194 a = b\n-- ---------------------------------------------------------------------\n\n@[simp] theorem inv_inj_iff\n  {a b : G}\n  : a\u207b\u00b9 = b\u207b\u00b9 \u2194 a = b :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190 inv_inv a, h, inv_inv b], },\n  { rintro rfl,\n    refl }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a\u207b\u00b9 = b \u2194 b\u207b\u00b9 = a\n-- ---------------------------------------------------------------------\n\ntheorem inv_eq\n  {a b : G}\n  : a\u207b\u00b9 = b \u2194 b\u207b\u00b9 = a :=\nbegin\n  split;\n  { rintro rfl,\n    rw inv_inv }\nend\n\nend group\n\nend oculto\n\n-- =====================================================================\n-- \u00a7 Referencias                                                      --\n-- =====================================================================\n\n-- + Kevin Buzzard. \"Formalising mathematics : workshop 2 \u2014 groups and\n--   subgroups. https://bit.ly/3iaYdqM\n-- + Kevin Buzzard. formalising-mathematics: week 2, Part_A_groups.lean\n--   https://bit.ly/2WGkyoy\n-- + Kevin Buzzard. formalising-mathematics: week 2, Part_A_groups_solutions.lean\n--   https://bit.ly/3le1WGc\n", "meta": {"author": "jaalonso", "repo": "Formalizacion_de_las_matematicas_en_Lean", "sha": "52bf9748d17a22d819cac19502fca9bc7340f7ae", "save_path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean/Formalizacion_de_las_matematicas_en_Lean-52bf9748d17a22d819cac19502fca9bc7340f7ae/src/2_Grupos_y_subgrupos/Grupos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7259738278874825}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Ya\u00ebl Dillies\n-/\nimport analysis.normed.group.add_torsor\nimport analysis.normed.group.pointwise\nimport analysis.normed_space.basic\n\n/-!\n# Properties of pointwise scalar multiplication of sets in normed spaces.\n\nWe explore the relationships between scalar multiplication of sets in vector spaces, and the norm.\nNotably, we express arbitrary balls as rescaling of other balls, and we show that the\nmultiplication of bounded sets remain bounded.\n-/\n\nopen metric set\nopen_locale pointwise topology\n\nvariables {\ud835\udd5c E : Type*} [normed_field \ud835\udd5c]\n\nsection seminormed_add_comm_group\nvariables [seminormed_add_comm_group E] [normed_space \ud835\udd5c E]\n\ntheorem smul_ball {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 ball x r = ball (c \u2022 x) (\u2016c\u2016 * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hc,\n  conv_lhs { rw \u2190inv_smul_smul\u2080 hc x },\n  simp [\u2190 div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hc), mul_comm _ r, dist_smul\u2080],\nend\n\nlemma smul_unit_ball {c : \ud835\udd5c} (hc : c \u2260 0) : c \u2022 ball (0 : E) (1 : \u211d) = ball (0 : E) (\u2016c\u2016) :=\nby rw [smul_ball hc, smul_zero, mul_one]\n\ntheorem smul_sphere' {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 sphere x r = sphere (c \u2022 x) (\u2016c\u2016 * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hc,\n  conv_lhs { rw \u2190inv_smul_smul\u2080 hc x },\n  simp only [mem_sphere, dist_smul\u2080, norm_inv, \u2190 div_eq_inv_mul,\n    div_eq_iff (norm_pos_iff.2 hc).ne', mul_comm r],\nend\n\ntheorem smul_closed_ball' {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 closed_ball x r = closed_ball (c \u2022 x) (\u2016c\u2016 * r) :=\nby simp only [\u2190 ball_union_sphere, set.smul_set_union, smul_ball hc, smul_sphere' hc]\n\nlemma metric.bounded.smul {s : set E} (hs : bounded s) (c : \ud835\udd5c) :\n  bounded (c \u2022 s) :=\nbegin\n  obtain \u27e8R, hR\u27e9 : \u2203 (R : \u211d), \u2200 x \u2208 s, \u2016x\u2016 \u2264 R := hs.exists_norm_le,\n  refine bounded_iff_forall_norm_le.2 \u27e8\u2016c\u2016 * R, \u03bb z hz, _\u27e9,\n  obtain \u27e8y, ys, rfl\u27e9 : \u2203 (y : E), y \u2208 s \u2227 c \u2022 y = z := mem_smul_set.1 hz,\n  calc \u2016c \u2022 y\u2016 = \u2016c\u2016 * \u2016y\u2016 : norm_smul _ _\n  ... \u2264 \u2016c\u2016 * R : mul_le_mul_of_nonneg_left (hR y ys) (norm_nonneg _)\nend\n\n/-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r \u2022 s` is contained in any\nfixed neighborhood of `x`. -/\nlemma eventually_singleton_add_smul_subset\n  {x : E} {s : set E} (hs : bounded s) {u : set E} (hu : u \u2208 \ud835\udcdd x) :\n  \u2200\u1da0 r in \ud835\udcdd (0 : \ud835\udd5c), {x} + r \u2022 s \u2286 u :=\nbegin\n  obtain \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9 : \u2203 \u03b5 (h\u03b5 : 0 < \u03b5), closed_ball x \u03b5 \u2286 u :=\n    nhds_basis_closed_ball.mem_iff.1 hu,\n  obtain \u27e8R, Rpos, hR\u27e9 : \u2203 (R : \u211d), 0 < R \u2227 s \u2286 closed_ball 0 R := hs.subset_ball_lt 0 0,\n  have : metric.closed_ball (0 : \ud835\udd5c) (\u03b5 / R) \u2208 \ud835\udcdd (0 : \ud835\udd5c) :=\n    closed_ball_mem_nhds _ (div_pos \u03b5pos Rpos),\n  filter_upwards [this] with r hr,\n  simp only [image_add_left, singleton_add],\n  assume y hy,\n  obtain \u27e8z, zs, hz\u27e9 : \u2203 (z : E), z \u2208 s \u2227 r \u2022 z = -x + y, by simpa [mem_smul_set] using hy,\n  have I : \u2016r \u2022 z\u2016 \u2264 \u03b5 := calc\n    \u2016r \u2022 z\u2016 = \u2016r\u2016 * \u2016z\u2016 : norm_smul _ _\n    ... \u2264 (\u03b5 / R) * R :\n      mul_le_mul (mem_closed_ball_zero_iff.1 hr)\n        (mem_closed_ball_zero_iff.1 (hR zs)) (norm_nonneg _) (div_pos \u03b5pos Rpos).le\n    ... = \u03b5 : by field_simp [Rpos.ne'],\n  have : y = x + r \u2022 z, by simp only [hz, add_neg_cancel_left],\n  apply h\u03b5,\n  simpa only [this, dist_eq_norm, add_sub_cancel', mem_closed_ball] using I,\nend\n\nvariables [normed_space \u211d E] {x y z : E} {\u03b4 \u03b5 : \u211d}\n\n/-- In a real normed space, the image of the unit ball under scalar multiplication by a positive\nconstant `r` is the ball of radius `r`. -/\nlemma smul_unit_ball_of_pos {r : \u211d} (hr : 0 < r) : r \u2022 ball 0 1 = ball (0 : E) r :=\nby rw [smul_unit_ball hr.ne', real.norm_of_nonneg hr.le]\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_eq (x z : E) {a b : \u211d} (ha : 0 \u2264 a) (hb : 0 \u2264 b) (hab : a + b = 1) :\n  \u2203 y, dist x y = b * dist x z \u2227 dist y z = a * dist x z :=\nbegin\n  use a \u2022 x + b \u2022 z,\n  nth_rewrite 0 [\u2190one_smul \u211d x],\n  nth_rewrite 3 [\u2190one_smul \u211d z],\n  simp [dist_eq_norm, \u2190hab, add_smul, \u2190smul_sub, norm_smul_of_nonneg, ha, hb],\nend\n\nlemma exists_dist_le_le (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 \u2264 \u03b5) (h : dist x z \u2264 \u03b5 + \u03b4) :\n  \u2203 y, dist x y \u2264 \u03b4 \u2227 dist y z \u2264 \u03b5 :=\nbegin\n  obtain rfl | h\u03b5' := h\u03b5.eq_or_lt,\n  { exact \u27e8z, by rwa zero_add at h, (dist_self _).le\u27e9 },\n  have h\u03b5\u03b4 := add_pos_of_pos_of_nonneg h\u03b5' h\u03b4,\n  refine (exists_dist_eq x z (div_nonneg h\u03b5 $ add_nonneg h\u03b5 h\u03b4) (div_nonneg h\u03b4 $ add_nonneg h\u03b5 h\u03b4) $\n    by rw [\u2190add_div, div_self h\u03b5\u03b4.ne']).imp (\u03bb y hy, _),\n  rw [hy.1, hy.2, div_mul_comm, div_mul_comm \u03b5],\n  rw \u2190div_le_one h\u03b5\u03b4 at h,\n  exact \u27e8mul_le_of_le_one_left h\u03b4 h, mul_le_of_le_one_left h\u03b5 h\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_le_lt (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 < \u03b5) (h : dist x z < \u03b5 + \u03b4) :\n  \u2203 y, dist x y \u2264 \u03b4 \u2227 dist y z < \u03b5 :=\nbegin\n  refine (exists_dist_eq x z (div_nonneg h\u03b5.le $ add_nonneg h\u03b5.le h\u03b4) (div_nonneg h\u03b4 $ add_nonneg\n    h\u03b5.le h\u03b4) $ by rw [\u2190add_div, div_self (add_pos_of_pos_of_nonneg h\u03b5 h\u03b4).ne']).imp (\u03bb y hy, _),\n  rw [hy.1, hy.2, div_mul_comm, div_mul_comm \u03b5],\n  rw \u2190div_lt_one (add_pos_of_pos_of_nonneg h\u03b5 h\u03b4) at h,\n  exact \u27e8mul_le_of_le_one_left h\u03b4 h.le, mul_lt_of_lt_one_left h\u03b5 h\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_lt_le (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 \u2264 \u03b5) (h : dist x z < \u03b5 + \u03b4) :\n  \u2203 y, dist x y < \u03b4 \u2227 dist y z \u2264 \u03b5 :=\nbegin\n  obtain \u27e8y, yz, xy\u27e9 := exists_dist_le_lt h\u03b5 h\u03b4\n    (show dist z x < \u03b4 + \u03b5, by simpa only [dist_comm, add_comm] using h),\n  exact \u27e8y, by simp [dist_comm x y, dist_comm y z, *]\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma exists_dist_lt_lt (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 < \u03b5) (h : dist x z < \u03b5 + \u03b4) :\n  \u2203 y, dist x y < \u03b4 \u2227 dist y z < \u03b5 :=\nbegin\n  refine (exists_dist_eq x z (div_nonneg h\u03b5.le $ add_nonneg h\u03b5.le h\u03b4.le) (div_nonneg h\u03b4.le $\n    add_nonneg h\u03b5.le h\u03b4.le) $ by rw [\u2190add_div, div_self (add_pos h\u03b5 h\u03b4).ne']).imp (\u03bb y hy, _),\n  rw [hy.1, hy.2, div_mul_comm, div_mul_comm \u03b5],\n  rw \u2190div_lt_one (add_pos h\u03b5 h\u03b4) at h,\n  exact \u27e8mul_lt_of_lt_one_left h\u03b4 h, mul_lt_of_lt_one_left h\u03b5 h\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma disjoint_ball_ball_iff (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 < \u03b5) :\n  disjoint (ball x \u03b4) (ball y \u03b5) \u2194 \u03b4 + \u03b5 \u2264 dist x y :=\nbegin\n  refine \u27e8\u03bb h, le_of_not_lt $ \u03bb hxy, _, ball_disjoint_ball\u27e9,\n  rw add_comm at hxy,\n  obtain \u27e8z, hxz, hzy\u27e9 := exists_dist_lt_lt h\u03b4 h\u03b5 hxy,\n  rw dist_comm at hxz,\n  exact h.le_bot \u27e8hxz, hzy\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma disjoint_ball_closed_ball_iff (h\u03b4 : 0 < \u03b4) (h\u03b5 : 0 \u2264 \u03b5) :\n  disjoint (ball x \u03b4) (closed_ball y \u03b5) \u2194 \u03b4 + \u03b5 \u2264 dist x y :=\nbegin\n  refine \u27e8\u03bb h, le_of_not_lt $ \u03bb hxy, _, ball_disjoint_closed_ball\u27e9,\n  rw add_comm at hxy,\n  obtain \u27e8z, hxz, hzy\u27e9 := exists_dist_lt_le h\u03b4 h\u03b5 hxy,\n  rw dist_comm at hxz,\n  exact h.le_bot \u27e8hxz, hzy\u27e9,\nend\n\n-- This is also true for `\u211a`-normed spaces\nlemma disjoint_closed_ball_ball_iff (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 < \u03b5) :\n  disjoint (closed_ball x \u03b4) (ball y \u03b5) \u2194 \u03b4 + \u03b5 \u2264 dist x y :=\nby rw [disjoint.comm, disjoint_ball_closed_ball_iff h\u03b5 h\u03b4, add_comm, dist_comm]; apply_instance\n\nlemma disjoint_closed_ball_closed_ball_iff (h\u03b4 : 0 \u2264 \u03b4) (h\u03b5 : 0 \u2264 \u03b5) :\n  disjoint (closed_ball x \u03b4) (closed_ball y \u03b5) \u2194 \u03b4 + \u03b5 < dist x y :=\nbegin\n  refine \u27e8\u03bb h, lt_of_not_ge $ \u03bb hxy, _, closed_ball_disjoint_closed_ball\u27e9,\n  rw add_comm at hxy,\n  obtain \u27e8z, hxz, hzy\u27e9 := exists_dist_le_le h\u03b4 h\u03b5 hxy,\n  rw dist_comm at hxz,\n  exact h.le_bot \u27e8hxz, hzy\u27e9,\nend\n\nopen emetric ennreal\n\n@[simp] lemma inf_edist_thickening (h\u03b4 : 0 < \u03b4) (s : set E) (x : E) :\n  inf_edist x (thickening \u03b4 s) = inf_edist x s - ennreal.of_real \u03b4 :=\nbegin\n  obtain hs | hs := lt_or_le (inf_edist x s) (ennreal.of_real \u03b4),\n  { rw [inf_edist_zero_of_mem, tsub_eq_zero_of_le hs.le], exact hs },\n  refine (tsub_le_iff_right.2 inf_edist_le_inf_edist_thickening_add).antisymm' _,\n  refine le_sub_of_add_le_right of_real_ne_top _,\n  refine le_inf_edist.2 (\u03bb z hz, le_of_forall_lt' $ \u03bb r h, _),\n  cases r,\n  { exact add_lt_top.2 \u27e8lt_top_iff_ne_top.2 $ inf_edist_ne_top \u27e8z, self_subset_thickening h\u03b4 _ hz\u27e9,\n      of_real_lt_top\u27e9 },\n  have hr : 0 < \u2191r - \u03b4,\n  { refine sub_pos_of_lt _,\n    have := hs.trans_lt ((inf_edist_le_edist_of_mem hz).trans_lt h),\n    rw [of_real_eq_coe_nnreal h\u03b4.le, some_eq_coe] at this,\n    exact_mod_cast this },\n  rw [some_eq_coe, edist_lt_coe, \u2190dist_lt_coe, \u2190add_sub_cancel'_right \u03b4 (\u2191r)] at h,\n  obtain \u27e8y, hxy, hyz\u27e9 := exists_dist_lt_lt hr h\u03b4 h,\n  refine (ennreal.add_lt_add_right of_real_ne_top $ inf_edist_lt_iff.2\n    \u27e8_, mem_thickening_iff.2 \u27e8_, hz, hyz\u27e9, edist_lt_of_real.2 hxy\u27e9).trans_le _,\n  rw [\u2190of_real_add hr.le h\u03b4.le, sub_add_cancel, of_real_coe_nnreal],\n  exact le_rfl,\nend\n\n@[simp] lemma thickening_thickening (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (s : set E) :\n  thickening \u03b5 (thickening \u03b4 s) = thickening (\u03b5 + \u03b4) s :=\n(thickening_thickening_subset _ _ _).antisymm $ \u03bb x, begin\n  simp_rw mem_thickening_iff,\n  rintro \u27e8z, hz, hxz\u27e9,\n  rw add_comm at hxz,\n  obtain \u27e8y, hxy, hyz\u27e9 := exists_dist_lt_lt h\u03b5 h\u03b4 hxz,\n  exact \u27e8y, \u27e8_, hz, hyz\u27e9, hxy\u27e9,\nend\n\n@[simp] lemma cthickening_thickening (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (s : set E) :\n  cthickening \u03b5 (thickening \u03b4 s) = cthickening (\u03b5 + \u03b4) s :=\n(cthickening_thickening_subset h\u03b5 _ _).antisymm $ \u03bb x, begin\n  simp_rw [mem_cthickening_iff, ennreal.of_real_add h\u03b5 h\u03b4.le, inf_edist_thickening h\u03b4],\n  exact tsub_le_iff_right.2,\nend\n\n-- Note: `interior (cthickening \u03b4 s) \u2260 thickening \u03b4 s` in general\n@[simp] lemma closure_thickening (h\u03b4 : 0 < \u03b4) (s : set E) :\n  closure (thickening \u03b4 s) = cthickening \u03b4 s :=\nby { rw [\u2190cthickening_zero, cthickening_thickening le_rfl h\u03b4, zero_add], apply_instance }\n\n@[simp] lemma inf_edist_cthickening (\u03b4 : \u211d) (s : set E) (x : E) :\n  inf_edist x (cthickening \u03b4 s) = inf_edist x s - ennreal.of_real \u03b4 :=\nbegin\n  obtain h\u03b4 | h\u03b4 := le_or_lt \u03b4 0,\n  { rw [cthickening_of_nonpos h\u03b4, inf_edist_closure, of_real_of_nonpos h\u03b4, tsub_zero] },\n  { rw [\u2190closure_thickening h\u03b4, inf_edist_closure, inf_edist_thickening h\u03b4]; apply_instance }\nend\n\n@[simp] lemma thickening_cthickening (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (s : set E) :\n  thickening \u03b5 (cthickening \u03b4 s) = thickening (\u03b5 + \u03b4) s :=\nbegin\n  obtain rfl | h\u03b4 := h\u03b4.eq_or_lt,\n  { rw [cthickening_zero, thickening_closure, add_zero] },\n  { rw [\u2190closure_thickening h\u03b4, thickening_closure, thickening_thickening h\u03b5 h\u03b4]; apply_instance }\nend\n\n@[simp] lemma cthickening_cthickening (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (s : set E) :\n  cthickening \u03b5 (cthickening \u03b4 s) = cthickening (\u03b5 + \u03b4) s :=\n(cthickening_cthickening_subset h\u03b5 h\u03b4 _).antisymm $ \u03bb x, begin\n  simp_rw [mem_cthickening_iff, ennreal.of_real_add h\u03b5 h\u03b4, inf_edist_cthickening],\n  exact tsub_le_iff_right.2,\nend\n\n@[simp] lemma thickening_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (x : E) :\n  thickening \u03b5 (ball x \u03b4) = ball x (\u03b5 + \u03b4) :=\nby rw [\u2190thickening_singleton, thickening_thickening h\u03b5 h\u03b4, thickening_singleton]; apply_instance\n\n@[simp] lemma thickening_closed_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  thickening \u03b5 (closed_ball x \u03b4) = ball x (\u03b5 + \u03b4) :=\nby rw [\u2190cthickening_singleton _ h\u03b4, thickening_cthickening h\u03b5 h\u03b4, thickening_singleton];\n  apply_instance\n\n@[simp] lemma cthickening_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (x : E) :\n  cthickening \u03b5 (ball x \u03b4) = closed_ball x (\u03b5 + \u03b4) :=\nby rw [\u2190thickening_singleton, cthickening_thickening h\u03b5 h\u03b4,\n  cthickening_singleton _ (add_nonneg h\u03b5 h\u03b4.le)]; apply_instance\n\n@[simp] lemma cthickening_closed_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  cthickening \u03b5 (closed_ball x \u03b4) = closed_ball x (\u03b5 + \u03b4) :=\nby rw [\u2190cthickening_singleton _ h\u03b4, cthickening_cthickening h\u03b5 h\u03b4,\n  cthickening_singleton _ (add_nonneg h\u03b5 h\u03b4)]; apply_instance\n\nlemma ball_add_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  ball a \u03b5 + ball b \u03b4 = ball (a + b) (\u03b5 + \u03b4) :=\nby rw [ball_add, thickening_ball h\u03b5 h\u03b4 b, metric.vadd_ball, vadd_eq_add]\n\nlemma ball_sub_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  ball a \u03b5 - ball b \u03b4 = ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_ball, ball_add_ball h\u03b5 h\u03b4]\n\nlemma ball_add_closed_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  ball a \u03b5 + closed_ball b \u03b4 = ball (a + b) (\u03b5 + \u03b4) :=\nby rw [ball_add, thickening_closed_ball h\u03b5 h\u03b4 b, metric.vadd_ball, vadd_eq_add]\n\nlemma ball_sub_closed_ball (h\u03b5 : 0 < \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  ball a \u03b5 - closed_ball b \u03b4 = ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_closed_ball, ball_add_closed_ball h\u03b5 h\u03b4]\n\nlemma closed_ball_add_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  closed_ball a \u03b5 + ball b \u03b4 = ball (a + b) (\u03b5 + \u03b4) :=\nby rw [add_comm, ball_add_closed_ball h\u03b4 h\u03b5 b, add_comm, add_comm \u03b4]\n\nlemma closed_ball_sub_ball (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 < \u03b4) (a b : E) :\n  closed_ball a \u03b5 - ball b \u03b4 = ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_ball, closed_ball_add_ball h\u03b5 h\u03b4]\n\nlemma closed_ball_add_closed_ball [proper_space E] (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  closed_ball a \u03b5 + closed_ball b \u03b4 = closed_ball (a + b) (\u03b5 + \u03b4) :=\nby rw [(is_compact_closed_ball _ _).add_closed_ball h\u03b4 b, cthickening_closed_ball h\u03b4 h\u03b5 a,\n  metric.vadd_closed_ball, vadd_eq_add, add_comm, add_comm \u03b4]\n\nlemma closed_ball_sub_closed_ball [proper_space E] (h\u03b5 : 0 \u2264 \u03b5) (h\u03b4 : 0 \u2264 \u03b4) (a b : E) :\n  closed_ball a \u03b5 - closed_ball b \u03b4 = closed_ball (a - b) (\u03b5 + \u03b4) :=\nby simp_rw [sub_eq_add_neg, neg_closed_ball, closed_ball_add_closed_ball h\u03b5 h\u03b4]\n\nend seminormed_add_comm_group\n\nsection normed_add_comm_group\nvariables [normed_add_comm_group E] [normed_space \ud835\udd5c E]\n\ntheorem smul_closed_ball (c : \ud835\udd5c) (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  c \u2022 closed_ball x r = closed_ball (c \u2022 x) (\u2016c\u2016 * r) :=\nbegin\n  rcases eq_or_ne c 0 with rfl|hc,\n  { simp [hr, zero_smul_set, set.singleton_zero, \u2190 nonempty_closed_ball] },\n  { exact smul_closed_ball' hc x r }\nend\n\nlemma smul_closed_unit_ball (c : \ud835\udd5c) : c \u2022 closed_ball (0 : E) (1 : \u211d) = closed_ball (0 : E) (\u2016c\u2016) :=\nby rw [smul_closed_ball _ _ zero_le_one, smul_zero, mul_one]\n\nvariables [normed_space \u211d E]\n\n/-- In a real normed space, the image of the unit closed ball under multiplication by a nonnegative\nnumber `r` is the closed ball of radius `r` with center at the origin. -/\nlemma smul_closed_unit_ball_of_nonneg {r : \u211d} (hr : 0 \u2264 r) :\n  r \u2022 closed_ball 0 1 = closed_ball (0 : E) r :=\nby rw [smul_closed_unit_ball, real.norm_of_nonneg hr]\n\n/-- In a nontrivial real normed space, a sphere is nonempty if and only if its radius is\nnonnegative. -/\n@[simp] lemma normed_space.sphere_nonempty [nontrivial E] {x : E} {r : \u211d} :\n  (sphere x r).nonempty \u2194 0 \u2264 r :=\nbegin\n  obtain \u27e8y, hy\u27e9 := exists_ne x,\n  refine \u27e8\u03bb h, nonempty_closed_ball.1 (h.mono sphere_subset_closed_ball), \u03bb hr,\n    \u27e8r \u2022 \u2016y - x\u2016\u207b\u00b9 \u2022 (y - x) + x, _\u27e9\u27e9,\n  have : \u2016y - x\u2016 \u2260 0, by simpa [sub_eq_zero],\n  simp [norm_smul, this, real.norm_of_nonneg hr],\nend\n\nlemma smul_sphere [nontrivial E] (c : \ud835\udd5c) (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  c \u2022 sphere x r = sphere (c \u2022 x) (\u2016c\u2016 * r) :=\nbegin\n  rcases eq_or_ne c 0 with rfl|hc,\n  { simp [zero_smul_set, set.singleton_zero, hr] },\n  { exact smul_sphere' hc x r }\nend\n\n/-- Any ball `metric.ball x r`, `0 < r` is the image of the unit ball under `\u03bb y, x + r \u2022 y`. -/\nlemma affinity_unit_ball {r : \u211d} (hr : 0 < r) (x : E) : x +\u1d65 r \u2022 ball 0 1 = ball x r :=\nby rw [smul_unit_ball_of_pos hr, vadd_ball_zero]\n\n/-- Any closed ball `metric.closed_ball x r`, `0 \u2264 r` is the image of the unit closed ball under\n`\u03bb y, x + r \u2022 y`. -/\nlemma affinity_unit_closed_ball {r : \u211d} (hr : 0 \u2264 r) (x : E) :\n  x +\u1d65 r \u2022 closed_ball 0 1 = closed_ball x r :=\nby rw [smul_closed_unit_ball, real.norm_of_nonneg hr, vadd_closed_ball_zero]\n\nend normed_add_comm_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7258904848309834}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\n! This file was ported from Lean 3 source module order.filter.partial\n! leanprover-community/mathlib commit 0a0ec35061ed9960bf0e7ffb0335f44447b58977\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.Filter.Basic\nimport Mathbin.Data.Pfun\n\n/-!\n# `tendsto` for relations and partial functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file generalizes `filter` definitions from functions to partial functions and relations.\n\n## Considering functions and partial functions as relations\n\nA function `f : \u03b1 \u2192 \u03b2` can be considered as the relation `rel \u03b1 \u03b2` which relates `x` and `f x` for\nall `x`, and nothing else. This relation is called `function.graph f`.\n\nA partial function `f : \u03b1 \u2192. \u03b2` can be considered as the relation `rel \u03b1 \u03b2` which relates `x` and\n`f x` for all `x` for which `f x` exists, and nothing else. This relation is called\n`pfun.graph' f`.\n\nIn this regard, a function is a relation for which every element in `\u03b1` is related to exactly one\nelement in `\u03b2` and a partial function is a relation for which every element in `\u03b1` is related to at\nmost one element in `\u03b2`.\n\nThis file leverages this analogy to generalize `filter` definitions from functions to partial\nfunctions and relations.\n\n## Notes\n\n`set.preimage` can be generalized to relations in two ways:\n* `rel.preimage` returns the image of the set under the inverse relation.\n* `rel.core` returns the set of elements that are only related to those in the set.\nBoth generalizations are sensible in the context of filters, so `filter.comap` and `filter.tendsto`\nget two generalizations each.\n\nWe first take care of relations. Then the definitions for partial functions are taken as special\ncases of the definitions for relations.\n-/\n\n\nuniverse u v w\n\nnamespace Filter\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nopen Filter\n\n/-! ### Relations -/\n\n\n#print Filter.rmap /-\n/-- The forward map of a filter under a relation. Generalization of `filter.map` to relations. Note\nthat `rel.core` generalizes `set.preimage`. -/\ndef rmap (r : Rel \u03b1 \u03b2) (l : Filter \u03b1) : Filter \u03b2\n    where\n  sets := { s | r.core s \u2208 l }\n  univ_sets := by simp\n  sets_of_superset s t hs st := mem_of_superset hs <| Rel.core_mono _ st\n  inter_sets s t hs ht := by simp [Rel.core_inter, inter_mem hs ht]\n#align filter.rmap Filter.rmap\n-/\n\n#print Filter.rmap_sets /-\ntheorem rmap_sets (r : Rel \u03b1 \u03b2) (l : Filter \u03b1) : (l.rmap r).sets = r.core \u207b\u00b9' l.sets :=\n  rfl\n#align filter.rmap_sets Filter.rmap_sets\n-/\n\n#print Filter.mem_rmap /-\n@[simp]\ntheorem mem_rmap (r : Rel \u03b1 \u03b2) (l : Filter \u03b1) (s : Set \u03b2) : s \u2208 l.rmap r \u2194 r.core s \u2208 l :=\n  Iff.rfl\n#align filter.mem_rmap Filter.mem_rmap\n-/\n\n#print Filter.rmap_rmap /-\n@[simp]\ntheorem rmap_rmap (r : Rel \u03b1 \u03b2) (s : Rel \u03b2 \u03b3) (l : Filter \u03b1) :\n    rmap s (rmap r l) = rmap (r.comp s) l :=\n  filter_eq <| by simp [rmap_sets, Set.preimage, Rel.core_comp]\n#align filter.rmap_rmap Filter.rmap_rmap\n-/\n\n#print Filter.rmap_compose /-\n@[simp]\ntheorem rmap_compose (r : Rel \u03b1 \u03b2) (s : Rel \u03b2 \u03b3) : rmap s \u2218 rmap r = rmap (r.comp s) :=\n  funext <| rmap_rmap _ _\n#align filter.rmap_compose Filter.rmap_compose\n-/\n\n#print Filter.Rtendsto /-\n/-- Generic \"limit of a relation\" predicate. `rtendsto r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `r`-core of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to relations. -/\ndef Rtendsto (r : Rel \u03b1 \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :=\n  l\u2081.rmap r \u2264 l\u2082\n#align filter.rtendsto Filter.Rtendsto\n-/\n\n#print Filter.rtendsto_def /-\ntheorem rtendsto_def (r : Rel \u03b1 \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :\n    Rtendsto r l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, r.core s \u2208 l\u2081 :=\n  Iff.rfl\n#align filter.rtendsto_def Filter.rtendsto_def\n-/\n\n#print Filter.rcomap /-\n/-- One way of taking the inverse map of a filter under a relation. One generalization of\n`filter.comap` to relations. Note that `rel.core` generalizes `set.preimage`. -/\ndef rcomap (r : Rel \u03b1 \u03b2) (f : Filter \u03b2) : Filter \u03b1\n    where\n  sets := Rel.image (fun s t => r.core s \u2286 t) f.sets\n  univ_sets := \u27e8Set.univ, univ_mem, Set.subset_univ _\u27e9\n  sets_of_superset := fun a b \u27e8a', ha', ma'a\u27e9 ab => \u27e8a', ha', ma'a.trans ab\u27e9\n  inter_sets := fun a b \u27e8a', ha\u2081, ha\u2082\u27e9 \u27e8b', hb\u2081, hb\u2082\u27e9 =>\n    \u27e8a' \u2229 b', inter_mem ha\u2081 hb\u2081, (r.core_inter a' b').Subset.trans (Set.inter_subset_inter ha\u2082 hb\u2082)\u27e9\n#align filter.rcomap Filter.rcomap\n-/\n\n#print Filter.rcomap_sets /-\ntheorem rcomap_sets (r : Rel \u03b1 \u03b2) (f : Filter \u03b2) :\n    (rcomap r f).sets = Rel.image (fun s t => r.core s \u2286 t) f.sets :=\n  rfl\n#align filter.rcomap_sets Filter.rcomap_sets\n-/\n\n#print Filter.rcomap_rcomap /-\ntheorem rcomap_rcomap (r : Rel \u03b1 \u03b2) (s : Rel \u03b2 \u03b3) (l : Filter \u03b3) :\n    rcomap r (rcomap s l) = rcomap (r.comp s) l :=\n  filter_eq <| by\n    ext t; simp [rcomap_sets, Rel.image, Rel.core_comp]; constructor\n    \u00b7 rintro \u27e8u, \u27e8v, vsets, hv\u27e9, h\u27e9\n      exact \u27e8v, vsets, Set.Subset.trans (Rel.core_mono _ hv) h\u27e9\n    rintro \u27e8t, tsets, ht\u27e9\n    exact \u27e8Rel.core s t, \u27e8t, tsets, Set.Subset.rfl\u27e9, ht\u27e9\n#align filter.rcomap_rcomap Filter.rcomap_rcomap\n-/\n\n#print Filter.rcomap_compose /-\n@[simp]\ntheorem rcomap_compose (r : Rel \u03b1 \u03b2) (s : Rel \u03b2 \u03b3) : rcomap r \u2218 rcomap s = rcomap (r.comp s) :=\n  funext <| rcomap_rcomap _ _\n#align filter.rcomap_compose Filter.rcomap_compose\n-/\n\n/- warning: filter.rtendsto_iff_le_rcomap -> Filter.rtendsto_iff_le_rcomap is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (r : Rel.{u1, u2} \u03b1 \u03b2) (l\u2081 : Filter.{u1} \u03b1) (l\u2082 : Filter.{u2} \u03b2), Iff (Filter.Rtendsto.{u1, u2} \u03b1 \u03b2 r l\u2081 l\u2082) (LE.le.{u1} (Filter.{u1} \u03b1) (Preorder.toLE.{u1} (Filter.{u1} \u03b1) (PartialOrder.toPreorder.{u1} (Filter.{u1} \u03b1) (Filter.partialOrder.{u1} \u03b1))) l\u2081 (Filter.rcomap.{u1, u2} \u03b1 \u03b2 r l\u2082))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (r : Rel.{u1, u2} \u03b1 \u03b2) (l\u2081 : Filter.{u1} \u03b1) (l\u2082 : Filter.{u2} \u03b2), Iff (Filter.Rtendsto.{u1, u2} \u03b1 \u03b2 r l\u2081 l\u2082) (LE.le.{u1} (Filter.{u1} \u03b1) (Preorder.toLE.{u1} (Filter.{u1} \u03b1) (PartialOrder.toPreorder.{u1} (Filter.{u1} \u03b1) (Filter.instPartialOrderFilter.{u1} \u03b1))) l\u2081 (Filter.rcomap.{u1, u2} \u03b1 \u03b2 r l\u2082))\nCase conversion may be inaccurate. Consider using '#align filter.rtendsto_iff_le_rcomap Filter.rtendsto_iff_le_rcomap\u2093'. -/\ntheorem rtendsto_iff_le_rcomap (r : Rel \u03b1 \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :\n    Rtendsto r l\u2081 l\u2082 \u2194 l\u2081 \u2264 l\u2082.rcomap r :=\n  by\n  rw [rtendsto_def]\n  change (\u2200 s : Set \u03b2, s \u2208 l\u2082.sets \u2192 r.core s \u2208 l\u2081) \u2194 l\u2081 \u2264 rcomap r l\u2082\n  simp [Filter.le_def, rcomap, Rel.mem_image]; constructor\n  \u00b7 exact fun h s t tl\u2082 => mem_of_superset (h t tl\u2082)\n  \u00b7 exact fun h t tl\u2082 => h _ t tl\u2082 Set.Subset.rfl\n#align filter.rtendsto_iff_le_rcomap Filter.rtendsto_iff_le_rcomap\n\n#print Filter.rcomap' /-\n-- Interestingly, there does not seem to be a way to express this relation using a forward map.\n-- Given a filter `f` on `\u03b1`, we want a filter `f'` on `\u03b2` such that `r.preimage s \u2208 f` if\n-- and only if `s \u2208 f'`. But the intersection of two sets satisfying the lhs may be empty.\n/-- One way of taking the inverse map of a filter under a relation. Generalization of `filter.comap`\nto relations. -/\ndef rcomap' (r : Rel \u03b1 \u03b2) (f : Filter \u03b2) : Filter \u03b1\n    where\n  sets := Rel.image (fun s t => r.Preimage s \u2286 t) f.sets\n  univ_sets := \u27e8Set.univ, univ_mem, Set.subset_univ _\u27e9\n  sets_of_superset := fun a b \u27e8a', ha', ma'a\u27e9 ab => \u27e8a', ha', ma'a.trans ab\u27e9\n  inter_sets := fun a b \u27e8a', ha\u2081, ha\u2082\u27e9 \u27e8b', hb\u2081, hb\u2082\u27e9 =>\n    \u27e8a' \u2229 b', inter_mem ha\u2081 hb\u2081,\n      (@Rel.preimage_inter _ _ r _ _).trans (Set.inter_subset_inter ha\u2082 hb\u2082)\u27e9\n#align filter.rcomap' Filter.rcomap'\n-/\n\n/- warning: filter.mem_rcomap' -> Filter.mem_rcomap' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (r : Rel.{u1, u2} \u03b1 \u03b2) (l : Filter.{u2} \u03b2) (s : Set.{u1} \u03b1), Iff (Membership.Mem.{u1, u1} (Set.{u1} \u03b1) (Filter.{u1} \u03b1) (Filter.hasMem.{u1} \u03b1) s (Filter.rcomap'.{u1, u2} \u03b1 \u03b2 r l)) (Exists.{succ u2} (Set.{u2} \u03b2) (fun (t : Set.{u2} \u03b2) => Exists.{0} (Membership.Mem.{u2, u2} (Set.{u2} \u03b2) (Filter.{u2} \u03b2) (Filter.hasMem.{u2} \u03b2) t l) (fun (H : Membership.Mem.{u2, u2} (Set.{u2} \u03b2) (Filter.{u2} \u03b2) (Filter.hasMem.{u2} \u03b2) t l) => HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Rel.preimage.{u1, u2} \u03b1 \u03b2 r t) s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (r : Rel.{u1, u2} \u03b1 \u03b2) (l : Filter.{u2} \u03b2) (s : Set.{u1} \u03b1), Iff (Membership.mem.{u1, u1} (Set.{u1} \u03b1) (Filter.{u1} \u03b1) (instMembershipSetFilter.{u1} \u03b1) s (Filter.rcomap'.{u1, u2} \u03b1 \u03b2 r l)) (Exists.{succ u2} (Set.{u2} \u03b2) (fun (t : Set.{u2} \u03b2) => And (Membership.mem.{u2, u2} (Set.{u2} \u03b2) (Filter.{u2} \u03b2) (instMembershipSetFilter.{u2} \u03b2) t l) (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Rel.preimage.{u1, u2} \u03b1 \u03b2 r t) s)))\nCase conversion may be inaccurate. Consider using '#align filter.mem_rcomap' Filter.mem_rcomap'\u2093'. -/\n@[simp]\ntheorem mem_rcomap' (r : Rel \u03b1 \u03b2) (l : Filter \u03b2) (s : Set \u03b1) :\n    s \u2208 l.rcomap' r \u2194 \u2203 t \u2208 l, r.Preimage t \u2286 s :=\n  Iff.rfl\n#align filter.mem_rcomap' Filter.mem_rcomap'\n\n#print Filter.rcomap'_sets /-\ntheorem rcomap'_sets (r : Rel \u03b1 \u03b2) (f : Filter \u03b2) :\n    (rcomap' r f).sets = Rel.image (fun s t => r.Preimage s \u2286 t) f.sets :=\n  rfl\n#align filter.rcomap'_sets Filter.rcomap'_sets\n-/\n\n#print Filter.rcomap'_rcomap' /-\n@[simp]\ntheorem rcomap'_rcomap' (r : Rel \u03b1 \u03b2) (s : Rel \u03b2 \u03b3) (l : Filter \u03b3) :\n    rcomap' r (rcomap' s l) = rcomap' (r.comp s) l :=\n  Filter.ext fun t => by\n    simp [rcomap'_sets, Rel.image, Rel.preimage_comp]; constructor\n    \u00b7 rintro \u27e8u, \u27e8v, vsets, hv\u27e9, h\u27e9\n      exact \u27e8v, vsets, (Rel.preimage_mono _ hv).trans h\u27e9\n    rintro \u27e8t, tsets, ht\u27e9\n    exact \u27e8s.preimage t, \u27e8t, tsets, Set.Subset.rfl\u27e9, ht\u27e9\n#align filter.rcomap'_rcomap' Filter.rcomap'_rcomap'\n-/\n\n#print Filter.rcomap'_compose /-\n@[simp]\ntheorem rcomap'_compose (r : Rel \u03b1 \u03b2) (s : Rel \u03b2 \u03b3) : rcomap' r \u2218 rcomap' s = rcomap' (r.comp s) :=\n  funext <| rcomap'_rcomap' _ _\n#align filter.rcomap'_compose Filter.rcomap'_compose\n-/\n\n#print Filter.Rtendsto' /-\n/-- Generic \"limit of a relation\" predicate. `rtendsto' r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `r`-preimage of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to relations. -/\ndef Rtendsto' (r : Rel \u03b1 \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :=\n  l\u2081 \u2264 l\u2082.rcomap' r\n#align filter.rtendsto' Filter.Rtendsto'\n-/\n\n#print Filter.rtendsto'_def /-\ntheorem rtendsto'_def (r : Rel \u03b1 \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :\n    Rtendsto' r l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, r.Preimage s \u2208 l\u2081 :=\n  by\n  unfold rtendsto' rcomap'; simp [le_def, Rel.mem_image]; constructor\n  \u00b7 exact fun h s hs => h _ _ hs Set.Subset.rfl\n  \u00b7 exact fun h s t ht => mem_of_superset (h t ht)\n#align filter.rtendsto'_def Filter.rtendsto'_def\n-/\n\n#print Filter.tendsto_iff_rtendsto /-\ntheorem tendsto_iff_rtendsto (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) (f : \u03b1 \u2192 \u03b2) :\n    Tendsto f l\u2081 l\u2082 \u2194 Rtendsto (Function.graph f) l\u2081 l\u2082 := by\n  simp [tendsto_def, Function.graph, rtendsto_def, Rel.core, Set.preimage]\n#align filter.tendsto_iff_rtendsto Filter.tendsto_iff_rtendsto\n-/\n\n#print Filter.tendsto_iff_rtendsto' /-\ntheorem tendsto_iff_rtendsto' (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) (f : \u03b1 \u2192 \u03b2) :\n    Tendsto f l\u2081 l\u2082 \u2194 Rtendsto' (Function.graph f) l\u2081 l\u2082 := by\n  simp [tendsto_def, Function.graph, rtendsto'_def, Rel.preimage_def, Set.preimage]\n#align filter.tendsto_iff_rtendsto' Filter.tendsto_iff_rtendsto'\n-/\n\n/-! ### Partial functions -/\n\n\n#print Filter.pmap /-\n/-- The forward map of a filter under a partial function. Generalization of `filter.map` to partial\nfunctions. -/\ndef pmap (f : \u03b1 \u2192. \u03b2) (l : Filter \u03b1) : Filter \u03b2 :=\n  Filter.rmap f.graph' l\n#align filter.pmap Filter.pmap\n-/\n\n#print Filter.mem_pmap /-\n@[simp]\ntheorem mem_pmap (f : \u03b1 \u2192. \u03b2) (l : Filter \u03b1) (s : Set \u03b2) : s \u2208 l.pmap f \u2194 f.core s \u2208 l :=\n  Iff.rfl\n#align filter.mem_pmap Filter.mem_pmap\n-/\n\n#print Filter.Ptendsto /-\n/-- Generic \"limit of a partial function\" predicate. `ptendsto r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `p`-core of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to partial function. -/\ndef Ptendsto (f : \u03b1 \u2192. \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :=\n  l\u2081.pmap f \u2264 l\u2082\n#align filter.ptendsto Filter.Ptendsto\n-/\n\n#print Filter.ptendsto_def /-\ntheorem ptendsto_def (f : \u03b1 \u2192. \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :\n    Ptendsto f l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, f.core s \u2208 l\u2081 :=\n  Iff.rfl\n#align filter.ptendsto_def Filter.ptendsto_def\n-/\n\n#print Filter.ptendsto_iff_rtendsto /-\ntheorem ptendsto_iff_rtendsto (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) (f : \u03b1 \u2192. \u03b2) :\n    Ptendsto f l\u2081 l\u2082 \u2194 Rtendsto f.graph' l\u2081 l\u2082 :=\n  Iff.rfl\n#align filter.ptendsto_iff_rtendsto Filter.ptendsto_iff_rtendsto\n-/\n\n/- warning: filter.pmap_res -> Filter.pmap_res is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (l : Filter.{u1} \u03b1) (s : Set.{u1} \u03b1) (f : \u03b1 -> \u03b2), Eq.{succ u2} (Filter.{u2} \u03b2) (Filter.pmap.{u1, u2} \u03b1 \u03b2 (PFun.res.{u1, u2} \u03b1 \u03b2 f s) l) (Filter.map.{u1, u2} \u03b1 \u03b2 f (Inf.inf.{u1} (Filter.{u1} \u03b1) (Filter.hasInf.{u1} \u03b1) l (Filter.principal.{u1} \u03b1 s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (l : Filter.{u1} \u03b1) (s : Set.{u1} \u03b1) (f : \u03b1 -> \u03b2), Eq.{succ u2} (Filter.{u2} \u03b2) (Filter.pmap.{u1, u2} \u03b1 \u03b2 (PFun.res.{u1, u2} \u03b1 \u03b2 f s) l) (Filter.map.{u1, u2} \u03b1 \u03b2 f (Inf.inf.{u1} (Filter.{u1} \u03b1) (Filter.instInfFilter.{u1} \u03b1) l (Filter.principal.{u1} \u03b1 s)))\nCase conversion may be inaccurate. Consider using '#align filter.pmap_res Filter.pmap_res\u2093'. -/\ntheorem pmap_res (l : Filter \u03b1) (s : Set \u03b1) (f : \u03b1 \u2192 \u03b2) : pmap (PFun.res f s) l = map f (l \u2293 \ud835\udcdf s) :=\n  by\n  ext t\n  simp only [PFun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or]\n  rfl\n#align filter.pmap_res Filter.pmap_res\n\n/- warning: filter.tendsto_iff_ptendsto -> Filter.tendsto_iff_ptendsto is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (l\u2081 : Filter.{u1} \u03b1) (l\u2082 : Filter.{u2} \u03b2) (s : Set.{u1} \u03b1) (f : \u03b1 -> \u03b2), Iff (Filter.Tendsto.{u1, u2} \u03b1 \u03b2 f (Inf.inf.{u1} (Filter.{u1} \u03b1) (Filter.hasInf.{u1} \u03b1) l\u2081 (Filter.principal.{u1} \u03b1 s)) l\u2082) (Filter.Ptendsto.{u1, u2} \u03b1 \u03b2 (PFun.res.{u1, u2} \u03b1 \u03b2 f s) l\u2081 l\u2082)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} (l\u2081 : Filter.{u1} \u03b1) (l\u2082 : Filter.{u2} \u03b2) (s : Set.{u1} \u03b1) (f : \u03b1 -> \u03b2), Iff (Filter.Tendsto.{u1, u2} \u03b1 \u03b2 f (Inf.inf.{u1} (Filter.{u1} \u03b1) (Filter.instInfFilter.{u1} \u03b1) l\u2081 (Filter.principal.{u1} \u03b1 s)) l\u2082) (Filter.Ptendsto.{u1, u2} \u03b1 \u03b2 (PFun.res.{u1, u2} \u03b1 \u03b2 f s) l\u2081 l\u2082)\nCase conversion may be inaccurate. Consider using '#align filter.tendsto_iff_ptendsto Filter.tendsto_iff_ptendsto\u2093'. -/\ntheorem tendsto_iff_ptendsto (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) (s : Set \u03b1) (f : \u03b1 \u2192 \u03b2) :\n    Tendsto f (l\u2081 \u2293 \ud835\udcdf s) l\u2082 \u2194 Ptendsto (PFun.res f s) l\u2081 l\u2082 := by\n  simp only [tendsto, ptendsto, pmap_res]\n#align filter.tendsto_iff_ptendsto Filter.tendsto_iff_ptendsto\n\n#print Filter.tendsto_iff_ptendsto_univ /-\ntheorem tendsto_iff_ptendsto_univ (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) (f : \u03b1 \u2192 \u03b2) :\n    Tendsto f l\u2081 l\u2082 \u2194 Ptendsto (PFun.res f Set.univ) l\u2081 l\u2082 :=\n  by\n  rw [\u2190 tendsto_iff_ptendsto]\n  simp [principal_univ]\n#align filter.tendsto_iff_ptendsto_univ Filter.tendsto_iff_ptendsto_univ\n-/\n\n#print Filter.pcomap' /-\n/-- Inverse map of a filter under a partial function. One generalization of `filter.comap` to\npartial functions. -/\ndef pcomap' (f : \u03b1 \u2192. \u03b2) (l : Filter \u03b2) : Filter \u03b1 :=\n  Filter.rcomap' f.graph' l\n#align filter.pcomap' Filter.pcomap'\n-/\n\n#print Filter.Ptendsto' /-\n/-- Generic \"limit of a partial function\" predicate. `ptendsto' r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `p`-preimage of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to partial functions. -/\ndef Ptendsto' (f : \u03b1 \u2192. \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :=\n  l\u2081 \u2264 l\u2082.rcomap' f.graph'\n#align filter.ptendsto' Filter.Ptendsto'\n-/\n\n#print Filter.ptendsto'_def /-\ntheorem ptendsto'_def (f : \u03b1 \u2192. \u03b2) (l\u2081 : Filter \u03b1) (l\u2082 : Filter \u03b2) :\n    Ptendsto' f l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, f.Preimage s \u2208 l\u2081 :=\n  rtendsto'_def _ _ _\n#align filter.ptendsto'_def Filter.ptendsto'_def\n-/\n\n#print Filter.ptendsto_of_ptendsto' /-\ntheorem ptendsto_of_ptendsto' {f : \u03b1 \u2192. \u03b2} {l\u2081 : Filter \u03b1} {l\u2082 : Filter \u03b2} :\n    Ptendsto' f l\u2081 l\u2082 \u2192 Ptendsto f l\u2081 l\u2082 :=\n  by\n  rw [ptendsto_def, ptendsto'_def]\n  exact fun h s sl\u2082 => mem_of_superset (h s sl\u2082) (PFun.preimage_subset_core _ _)\n#align filter.ptendsto_of_ptendsto' Filter.ptendsto_of_ptendsto'\n-/\n\n#print Filter.ptendsto'_of_ptendsto /-\ntheorem ptendsto'_of_ptendsto {f : \u03b1 \u2192. \u03b2} {l\u2081 : Filter \u03b1} {l\u2082 : Filter \u03b2} (h : f.Dom \u2208 l\u2081) :\n    Ptendsto f l\u2081 l\u2082 \u2192 Ptendsto' f l\u2081 l\u2082 :=\n  by\n  rw [ptendsto_def, ptendsto'_def]\n  intro h' s sl\u2082\n  rw [PFun.preimage_eq]\n  exact inter_mem (h' s sl\u2082) h\n#align filter.ptendsto'_of_ptendsto Filter.ptendsto'_of_ptendsto\n-/\n\nend Filter\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/Filter/Partial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7258904723744093}}
{"text": "import data.int.modeq\nimport data.nat.basic\nimport data.nat.modeq\nimport data.nat.parity\nimport data.nat.digits\nimport data.nat.gcd.basic\nimport algebra.big_operators.ring\n\nimport tactic.ring_exp\n\n/-!\nLet n be a natural number. Prove that\n\n  (a) n has a (nonzero) multiple whose representation in base 10 contains\n      only zeroes and ones; and\n  (b) 2^n has a multiple whose representation contains only ones and twos.\n-/\n\nopen_locale big_operators\n\ndef ones (b : \u2115) : \u2115 \u2192 \u2115\n| k := \u2211(i : \u2115) in finset.range k, b^i\n\ndef map_mod (n : \u2115) (hn: 0 < n) (f : \u2115 \u2192 \u2115) : \u2115 \u2192 fin n\n| m := \u27e8f m % n, nat.mod_lt (f m) hn\u27e9\n\nlemma pigeonhole (n : \u2115) (f : \u2115 \u2192 fin n) :\n  \u2203 a b : \u2115, a < b \u2227 f a = f b :=\nlet \u27e8a, b, hne, hfe\u27e9 := finite.exists_ne_map_eq_of_infinite f\nin hne.lt_or_lt.elim (\u03bb h, \u27e8a, b, h, hfe\u27e9) (\u03bb h, \u27e8b, a, h, hfe.symm\u27e9)\n\ndef is_zero_or_one : \u2115 \u2192 Prop\n| 0 := true\n| 1 := true\n| _ := false\n\ndef all_zero_or_one (l : list \u2115) : Prop := \u2200 e \u2208 l, is_zero_or_one e\n\nlemma digits_lemma\n  (base: \u2115)\n  (h2: 2 \u2264 base)\n  (n: \u2115)\n  (hn: 0 < n)\n  : (nat.digits base (base * n)) = 0 :: (nat.digits base n) :=\nbegin\n  have := nat.digits_add base h2 0 n (nat.lt_of_succ_lt (nat.succ_le_iff.mp h2))\n                              (or.inr (ne_of_gt hn)),\n  rwa (zero_add (base * n)) at this,\nend\n\nlemma times_base_still_all_zero_or_one\n  (base: \u2115)\n  (h2: 2 \u2264 base)\n  (n: \u2115)\n  (hn : all_zero_or_one (nat.digits base n))\n  : all_zero_or_one (nat.digits base (base * n)) :=\nbegin\n  cases (nat.eq_zero_or_pos n) with hz hp,\n  { rw hz,\n    simp [mul_zero, nat.digits_zero, all_zero_or_one] },\n  { rw (digits_lemma base h2 n hp),\n    simpa[is_zero_or_one, all_zero_or_one] }\nend\n\nlemma base_pow_still_all_zero_or_one\n  (base: \u2115)\n  (h2: 2 \u2264 base)\n  (k n: \u2115)\n  (hn : all_zero_or_one (nat.digits base n))\n  : all_zero_or_one (nat.digits base ((base ^ k) * n)) :=\nbegin\n  induction k with pk hpk,\n  { simpa },\n  have := times_base_still_all_zero_or_one base h2 _ hpk,\n  rwa [\u2190(nat.add_one pk), pow_succ' base pk, mul_comm (base^pk) base, mul_assoc],\nend\n\nlemma times_base_plus_one_still_all_zero_or_one\n  (base: \u2115)\n  (h2: 2 \u2264 base)\n  (n: \u2115)\n  (hazoo : all_zero_or_one (nat.digits base n))\n  : all_zero_or_one (nat.digits base (1 + base * n)) :=\nbegin\n  rw (nat.digits_add base h2 1 n (nat.succ_le_iff.mp h2) (or.inl nat.one_ne_zero)),\n  simpa[all_zero_or_one, is_zero_or_one],\nend\n\nlemma lemma_0 (k b : \u2115) (h2 : 2 \u2264 b) :\n  all_zero_or_one (b.digits (\u2211(i : \u2115) in finset.range k, b^i)) :=\nbegin\n  induction k with pk hpk,\n  { simp[all_zero_or_one] },\n  { have hh := calc\n          \u2211 (i : \u2115) in finset.range pk.succ, b ^ i\n        = \u2211 (i : \u2115) in finset.range pk, b ^ i.succ + b ^ 0 :\n               finset.sum_range_succ' (\u03bb (i : \u2115), b ^ i) pk\n    ... = b ^ 0 + \u2211 (i : \u2115) in finset.range pk, b ^ i.succ : add_comm _ _\n    ... = 1 + \u2211 (i : \u2115) in finset.range pk, b ^ i.succ : by rw pow_zero\n    ... = 1 + \u2211 (i : \u2115) in finset.range pk, b * b ^ i :\n          by {simp, exact finset.sum_congr rfl (\u03bbx _, pow_succ _ _)}\n    ... =  1 + b * \u2211 (i : \u2115) in finset.range pk, b ^ i :\n          by simp [finset.mul_sum],\n    have := times_base_plus_one_still_all_zero_or_one\n               b h2\n               (\u2211 (i : \u2115) in finset.range pk, b ^ i) hpk,\n    rwa hh,\n  },\nend\n\nlemma lemma_1 (k b m: \u2115) (h2 : 2 \u2264 b):\n  all_zero_or_one (b.digits (\u2211(i : \u2115) in finset.range k, b^(i + m))) :=\nbegin\n  have h := calc\n          (\u2211 (i : \u2115) in finset.range k, b ^ (i + m))\n        = (\u2211 (i : \u2115) in finset.range k, b ^ i * b ^ m) :\n             by { refine finset.sum_congr rfl _, intros x hx, exact pow_add b x m }\n    ... = (\u2211 (i : \u2115) in finset.range k, b ^ m * b ^ i) :\n             by { refine finset.sum_congr rfl _, intros x hx, exact mul_comm (b ^ x) (b ^ m) }\n    ... = b^m * (\u2211 (i : \u2115) in finset.range k, b ^ i) : finset.mul_sum.symm,\n\n  have := base_pow_still_all_zero_or_one b h2 m\n                       (\u2211 (i : \u2115) in finset.range k, b ^ i)\n                       (lemma_0 k b h2),\n  rwa h,\nend\n\nlemma lemma_2'''\n  (c d : \u2115)\n  (f: \u2115 \u2192 \u2115) :\n  (\u2211(i : \u2115) in finset.range c, f (i + d)) + (\u2211(i : \u2115) in finset.range d, f i)  =\n     \u2211(i : \u2115) in finset.range (c+d), f i :=\nbegin\n  induction c with pc hpc,\n  { simp },\n  { have h1 : \u2211 (i : \u2115) in finset.range pc.succ, f (i + d) =\n              \u2211 (i : \u2115) in finset.range pc, f (i + d) + f (pc + d) :=\n         finset.sum_range_succ (\u03bb (x : \u2115), f (x + d)) pc,\n\n    have h2 := calc\n          \u2211 (i : \u2115) in finset.range (pc.succ + d), f i\n        = \u2211 (i : \u2115) in finset.range (pc + d).succ, f i        : by rw nat.succ_add\n    ... = \u2211 (i : \u2115) in finset.range (pc + d), f i + f(pc + d) : finset.sum_range_succ f _,\n\n    linarith\n  },\nend\n\nlemma lemma_2''\n  (a b : \u2115)\n  (hlt : a < b)\n  (f: \u2115 \u2192 \u2115) :\n  (\u2211(i : \u2115) in finset.range (b - a), f (i + a)) + (\u2211(i : \u2115) in finset.range a, f i)  =\n     \u2211(i : \u2115) in finset.range b, f i :=\nbegin\n  have := lemma_2''' (b - a) a f,\n  rwa [nat.sub_add_cancel (le_of_lt hlt)] at this,\nend\n\nlemma lemma_2'\n  (a b : \u2115)\n  (hlt : a < b) :\n  (\u2211(i : \u2115) in finset.range (b - a), 10^(i + a)) + (\u2211(i : \u2115) in finset.range a, 10^i)  =\n     \u2211(i : \u2115) in finset.range b, 10^i :=\nbegin\n  exact lemma_2'' a b hlt (\u03bbi, 10^i),\nend\n\nlemma lemma_2_aux (n a b c: \u2115) (hc : a + b = c) (hab: a % n = c % n) : b % n = 0 :=\nbegin\n  have h1: a \u2261 c [MOD n] := hab,\n  have h2 : a + b \u2261 c + b [MOD n] := nat.modeq.add h1 rfl,\n  rw hc at h2,\n  have h2' : c + 0 = c := self_eq_add_right.mpr rfl,\n  have h2'' : c + 0 \u2261 c + b [MOD n] := by rwa h2',\n  have h3 : 0 \u2261 b [MOD n] := nat.modeq.add_left_cancel' c h2'',\n  have h4 : 0 % n = b % n := h3,\n  rw [nat.zero_mod] at h4,\n  exact eq.symm h4,\nend\n\nlemma lemma_2\n  (n : \u2115)\n  (hn : n > 0)\n  (a b : \u2115)\n  (hlt : a < b)\n  (hab : (\u2211(i : \u2115) in finset.range a, 10^i) % n = (\u2211(i : \u2115) in finset.range b, 10^i) % n) :\n  (\u2211(i : \u2115) in finset.range (b - a), 10^(i + a)) % n = 0 :=\nbegin\n  have h1 := lemma_2' a b hlt,\n  refine lemma_2_aux n _ (\u2211(i : \u2115) in finset.range (b - a), 10^(i + a)) _ _ hab,\n  rwa add_comm,\nend\n\nlemma lemma_3 {a n : \u2115} (ha: 0 < a) (hm : a % n = 0) : (\u2203 k : \u2115+, a = n * k) :=\nbegin\n  have h2 : n \u2223 a := nat.dvd_of_mod_eq_zero hm,\n  obtain \u27e8k', hk'\u27e9 := exists_eq_mul_right_of_dvd h2,\n  have hkp : 0 < k',\n  { cases k',\n    { rw hk' at ha,\n      rwa mul_zero at ha },\n    { exact nat.succ_pos k' } },\n  use \u27e8k', hkp\u27e9,\n  simpa [hkp],\nend\n\nlemma lemma_4 {k : \u2115} (hk : 0 < k) (f: \u2115 \u2192 \u2115) (hf0 : 0 < f 0) :\n      0 < \u2211(i : \u2115) in finset.range k, f i :=\nbegin\n  cases k,\n  { exfalso, exact nat.lt_asymm hk hk },\n  calc 0 < f 0                                         : hf0\n    ... \u2264 (\u2211(i : \u2115) in finset.range k, f i.succ) + f 0 : nat.le_add_left _ _\n    ... = (\u2211(i : \u2115) in finset.range k.succ, f i)       : (finset.sum_range_succ' _ _).symm\nend\n\nlemma two_le_ten : (2 : \u2115) \u2264 10 := tsub_eq_zero_iff_le.mp rfl\n\n--\n-- Prove that n has a positive multiple whose representation contains only zeroes and ones.\n--\ntheorem zeroes_and_ones (n : \u2115) : \u2203 k : \u2115+, all_zero_or_one (nat.digits 10 (n * k)) :=\nbegin\n  obtain (hn0 : n = 0 ) | (hn : n > 0) := nat.eq_zero_or_pos n,\n  { use 1, rw hn0, simp[all_zero_or_one] },\n  obtain \u27e8a, b, hlt, hab\u27e9 := pigeonhole n (\u03bbm, map_mod n hn (ones 10) m),\n  have h' : (\u2211(i : \u2115) in finset.range (b - a), 10^(i + a)) % n = 0 :=\n   lemma_2 n hn a b hlt (fin.mk.inj hab),\n  have ha: 0 < \u2211(i : \u2115) in finset.range (b - a), 10^(i + a),\n  { have hm : 0 < b - a := nat.sub_pos_of_lt hlt,\n    have hp : 0 < 10 ^ (0 + a) := pow_pos (nat.succ_pos _) _,\n    exact lemma_4 hm (\u03bb (i : \u2115), 10 ^ (i + a)) hp,\n  },\n  obtain \u27e8k, hk\u27e9 := lemma_3 ha h',\n  use k,\n  rw [\u2190hk],\n  exact lemma_1 (b - a) 10 a two_le_ten\nend\n\n\ndef is_one_or_two : \u2115 \u2192 Prop\n| 1 := true\n| 2 := true\n| _ := false\n\ndef all_one_or_two (l : list \u2115) : Prop := \u2200 e \u2208 l, is_one_or_two e\n\ndef prepend_one (n : \u2115) := 10 ^ (list.length (nat.digits 10 n)) + n\n\nlemma prepend_one_pos (n: \u2115) : 0 < prepend_one n :=\nbegin\n  cases n,\n  { simp[prepend_one], },\n  { rw[prepend_one],\n    norm_num },\nend\n\nlemma digits_len' (n : \u2115) (hn : 0 < n) :\n      list.length (nat.digits 10 n) = 1 + list.length (nat.digits 10 (n / 10)) :=\nbegin\n  rw[nat.digits_def' two_le_ten hn],\n  rw[list.length],\n  exact add_comm _ _,\nend\n\nlemma prepend_one_div (n : \u2115) (hn : 0 < n) : prepend_one n / 10 = prepend_one (n / 10) :=\nbegin\n  rw[prepend_one, prepend_one],\n  cases n,\n  { exfalso, exact nat.lt_asymm hn hn },\n  { rw[digits_len' n.succ (nat.succ_pos n)],\n    rw[pow_add, pow_one, add_comm],\n    rw [nat.add_mul_div_left _ _ (nat.succ_pos 9)],\n    exact add_comm _ _ }\nend\n\nlemma prepend_one_mod (n : \u2115) (hn : 0 < n) : prepend_one n % 10 = n % 10 :=\nbegin\n  rw[prepend_one],\n  rw[nat.digits_len _ _ two_le_ten (ne_of_gt hn)],\n  rw[pow_add, pow_one],\n  exact nat.mul_add_mod _ 10 n\nend\n\nlemma prepend_one_eq_append (n : \u2115) :\n    nat.digits 10 (prepend_one n) = (nat.digits 10 n) ++ [1] :=\nbegin\n  induction n using nat.strong_induction_on with n' ih,\n  cases n',\n  { simp[prepend_one], },\n  { rw[nat.digits_def' two_le_ten (prepend_one_pos _)],\n    rw[prepend_one_div _ (nat.succ_pos n')],\n    have hns : n'.succ / 10 < n'.succ := nat.div_lt_self' n' 8,\n    rw[ih _ hns],\n    rw[\u2190list.cons_append],\n    rw[prepend_one_mod _ (nat.succ_pos _), \u2190 nat.digits_def' two_le_ten (nat.succ_pos n')] }\nend\n\nlemma prepend_one_all_one_or_two (n : \u2115) (hn : all_one_or_two (nat.digits 10 n)) :\n    all_one_or_two (nat.digits 10 (prepend_one n)) :=\nbegin\n rw[prepend_one_eq_append, all_one_or_two],\n rw[all_one_or_two] at hn,\n intros e he,\n rw[list.mem_append] at he,\n cases he,\n { exact hn e he },\n { rw[list.mem_singleton] at he,\n   rw[he],\n   simp[is_one_or_two] }\nend\n\ndef prepend_two (n : \u2115) := 2 * (10 ^ (list.length (nat.digits 10 n))) + n\n\nlemma prepend_two_pos (n: \u2115) : 0 < prepend_two n :=\nbegin\n  cases n,\n  { simp[prepend_two], },\n  { rw[prepend_two],\n    norm_num },\nend\n\nlemma prepend_two_div (n : \u2115) (hn : 0 < n) : prepend_two n / 10 = prepend_two (n / 10) :=\nbegin\n  rw[prepend_two, prepend_two],\n  cases n,\n  { exfalso, exact nat.lt_asymm hn hn },\n  { rw[digits_len' n.succ (nat.succ_pos n)],\n    rw[pow_add, pow_one],\n    rw[add_comm],\n    rw[\u2190mul_left_comm],\n    rw [nat.add_mul_div_left _ _ (nat.succ_pos 9)],\n    exact add_comm _ _ }\nend\n\nlemma prepend_two_mod (n : \u2115) (hn : 0 < n) : prepend_two n % 10 = n % 10 :=\nbegin\n  rw[prepend_two],\n  rw[nat.digits_len _ _ two_le_ten (ne_of_gt hn)],\n  rw[pow_add, pow_one, \u2190mul_assoc],\n  exact nat.mul_add_mod _ 10 n\nend\n\nlemma prepend_two_eq_append (n : \u2115) :\n    nat.digits 10 (prepend_two n) = (nat.digits 10 n) ++ [2] :=\nbegin\n  induction n using nat.strong_induction_on with n' ih,\n  cases n',\n  { simp[prepend_two], },\n  { rw[nat.digits_def' two_le_ten (prepend_two_pos _)],\n    rw[prepend_two_div _ (nat.succ_pos n')],\n    have hns : n'.succ / 10 < n'.succ := nat.div_lt_self' n' 8,\n    rw[ih _ hns],\n    rw[\u2190list.cons_append],\n    rw[prepend_two_mod _ (nat.succ_pos _), \u2190 nat.digits_def' two_le_ten (nat.succ_pos n')] }\nend\n\nlemma prepend_two_all_one_or_two (n : \u2115) (hn : all_one_or_two (nat.digits 10 n)) :\n    all_one_or_two (nat.digits 10 (prepend_two n)) :=\nbegin\n rw[prepend_two_eq_append, all_one_or_two],\n rw[all_one_or_two] at hn,\n intros e he,\n rw[list.mem_append] at he,\n cases he,\n { exact hn e he },\n { rw[list.mem_singleton] at he,\n   rw[he],\n   simp[is_one_or_two] }\nend\n\nlemma factor_ten_pow (k : \u2115) : 10 ^ k = (2^k) * (5^k) :=\nbegin\n  induction k with k' ih,\n  { simp only [pow_zero, mul_one] },\n  { rw[pow_succ, pow_succ, pow_succ],\n    linarith }\nend\n\nlemma even_5_pow_plus_one (n : \u2115) : 2 \u2223 5 ^ n + 1 :=\nbegin\n  apply nat.dvd_of_mod_eq_zero,\n  have h0 : 5 ^ n % 2 = 1,\n  { induction n with n' ih,\n    { simp },\n    { rw[pow_succ, nat.mul_mod, ih],\n      simp}},\n  rw[nat.add_mod, h0],\n  simp\nend\n\nlemma ones_and_twos_aux (n : \u2115) :\n  \u2203 k : \u2115+, (list.length (nat.digits 10 (2^n.succ * k)) = n.succ) \u2227\n             all_one_or_two (nat.digits 10 (2^n.succ * k)) :=\nbegin\n  induction n with pn hpn,\n  { use 1, simp[all_one_or_two] },\n  obtain \u27e8pk, hpk1, hpk2\u27e9 := hpn,\n\n  /-\n    Adding a 1 or a 2 to the front of 2^pn.succ * pk increments it by 2^pn.succ * 5^pn.succ or\n    by 2^{pn.succ+1} * 5^pn.succ, in each case preserving divisibility by 2^pn.succ. Since the\n    two choices differ by 2^pn.succ * 5^pn.succ, one of them must actually achieve\n    divisibility by 2^{pn.succ+1}.\n  -/\n\n  obtain \u27e8t, ht : \u2191pk = t + t\u27e9 | \u27e8t, ht : \u2191pk = 2 * t + 1\u27e9 := (pk : \u2115).even_or_odd,\n  { -- Even case. Prepend 2.\n    rw[\u2190 two_mul] at ht,\n    have hd : 2 ^ pn.succ.succ \u2223 prepend_two (2 ^ pn.succ * \u2191pk),\n    { rw [prepend_two, factor_ten_pow, hpk1, ht],\n      have hr : 2 * (2 ^ pn.succ * 5 ^ pn.succ) + 2 ^ pn.succ * (2 * t) =\n                   2 ^ pn.succ.succ * (5 ^ pn.succ + t) := by ring_exp,\n      rw[hr],\n      exact dvd.intro (5 ^ nat.succ pn + t) rfl },\n    obtain \u27e8k', hk'\u27e9 := hd,\n    have hkp': 0 < k',\n    { cases k',\n      { exfalso,\n        have hzz := prepend_two_pos (2 ^ pn.succ * \u2191pk),\n        rw[mul_zero] at hk',\n        linarith },\n      {exact nat.succ_pos _}, },\n    use \u27e8k', hkp'\u27e9,\n    dsimp,\n    rw[\u2190 hk'],\n    split,\n    { rw[prepend_two_eq_append],\n      rw [list.length_append, list.length_singleton, hpk1] },\n    { exact prepend_two_all_one_or_two _ hpk2, },\n  },\n  { -- Odd case. Prepend 1.\n    have hd : 2 ^ pn.succ.succ \u2223 prepend_one (2 ^ pn.succ * \u2191pk),\n    { rw[prepend_one, hpk1, factor_ten_pow, ht],\n      have h5 : 2 ^ pn.succ * 5 ^ pn.succ + 2 ^ pn.succ * (2 * t + 1) =\n            2^pn.succ * (2 * (2 * 5 ^ pn + t) + (5^pn + 1)) := by ring_exp,\n      rw[h5],\n      obtain \u27e8k5,hk5\u27e9:= even_5_pow_plus_one pn,\n      rw[hk5],\n      have h5' : 2 ^ pn.succ * (2 * (2 * 5 ^ pn + t) + 2 * k5) =\n           2^pn.succ.succ * (2 * 5 ^ pn + t + k5) := by ring_exp,\n      rw[h5'],\n      exact dvd.intro (2 * 5 ^ pn + t + k5) rfl},\n    obtain \u27e8k', hk'\u27e9 := hd,\n    have hkp': 0 < k',\n    { cases k',\n      { exfalso,\n        have hzz := prepend_one_pos (2 ^ pn.succ * \u2191pk),\n        rw[mul_zero] at hk',\n        linarith },\n      {exact nat.succ_pos _}, },\n    use \u27e8k', hkp'\u27e9,\n    dsimp,\n    rw[\u2190 hk'],\n    split,\n    { rw [prepend_one_eq_append],\n      rw [list.length_append, list.length_singleton, hpk1] },\n    { exact prepend_one_all_one_or_two _ hpk2, }},\nend\n\n--\n-- Prove that 2^n has a positive multiple whose representation contains only ones and twos.\n--\ntheorem ones_and_twos (n : \u2115) : \u2203 k : \u2115+, all_one_or_two (nat.digits 10 (2^n * k)) :=\nbegin\n  cases n,\n  { use 1, simp[all_one_or_two] },\n  obtain \u27e8k, hk1, hk2\u27e9 := ones_and_twos_aux n,\n  exact \u27e8k, hk2\u27e9\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/zeroes_ones_and_twos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7258904578490454}}
{"text": "import .love01_definitions_and_statements_demo\n\n\n/-! # LoVe Demo 3: Forward Proofs\n\nWhen developing a proof, often it makes sense to work __forward__: to start with\nwhat we already know and proceed step by step towards our goal. Lean's\nstructured proofs and raw proof terms are two styles that support forward\nreasoning. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace forward_proofs\n\n\n/-! ## Structured Constructs\n\nStructured proofs are syntactic sugar sprinkled on top of Lean's\n__proof terms__.\n\nThe simplest kind of structured proof is the name of a lemma, possibly with\narguments. -/\n\nlemma add_comm (i j : \u2115) :\n  add i j = add j i :=\nsorry\n\nlemma add_comm_zero_left (n : \u2115) :\n  add 0 n = add n 0 :=\nadd_comm 0 n\n\nlemma add_comm_zero_left\u2082 (n : \u2115) :\n  add 0 n = add n 0 :=\nby exact add_comm 0 n\n\n/-! `fix` and `assume` move `\u2200`-quantified variables and assumptions from the\ngoal into the local context. They can be seen as structured versions of the\n`intros` tactic.\n\n`show` repeats the goal to prove. It is useful as documentation or to rephrase\nthe goal (up to computation). -/\n\nlemma fst_of_two_props :\n  \u2200a b : Prop, a \u2192 b \u2192 a :=\nfix a b : Prop,\nassume ha : a,\nassume hb : b,\nshow a, from\n  ha\n\n\nlemma fst_of_two_props\u2082 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nshow a, from\n  begin\n    exact ha\n  end\n\n#print fst_of_two_props\n#print fst_of_two_props\u2082 \n\nlemma fst_of_two_props\u2083 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nha\n\n/-! `have` proves an intermediate lemma, which can refer to the local context. -/\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nhave hb : b :=\n  hab ha,\nhave hc : c :=\n  hbc hb,\nshow c, from\n  hc\n\nlemma prop_comp\u2082 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nshow c, from\n  hbc (hab ha)\n\n\n/-! ## Forward Reasoning about Connectives and Quantifiers -/\n\nlemma and_swap (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nassume hab : a \u2227 b,\nhave ha : a :=\n  and.elim_left hab,\nhave hb : b :=\n  and.elim_right hab,\nshow b \u2227 a, from\n  and.intro hb ha\n\nlemma or_swap (a b : Prop) :\n  a \u2228 b \u2192 b \u2228 a :=\nassume hab : a \u2228 b,\nshow b \u2228 a, from\n  or.elim hab\n    (assume ha : a,\n     show b \u2228 a, from\n       or.intro_right b ha)\n    (assume hb : b,\n     show b \u2228 a, from\n       or.intro_left a hb)\n\ndef double (n : \u2115) : \u2115 :=\nn + n\n\nlemma nat_exists_double_iden :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0\n  (show double 0 = 0, from\n     by refl)\n\nlemma nat_exists_double_iden\u2082 :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0 (by refl)\n\nlemma modus_ponens (a b : Prop) :\n  (a \u2192 b) \u2192 a \u2192 b :=\nassume hab : a \u2192 b,\nassume ha : a,\nshow b, from\n  hab ha\n\nlemma not_not_intro (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nassume ha : a,\nassume hna : \u00ac a,\nshow false, from\n  hna ha\n\nlemma forall.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2200x, x = t \u2192 p x) \u2194 p t :=\niff.intro\n  (assume hall : \u2200x, x = t \u2192 p x,\n   show p t, from\n     begin\n       apply hall t,\n       refl\n     end)\n  (assume hp : p t,\n   fix x,\n   assume heq : x = t,\n   show p x, from\n     begin\n       rw heq,\n       exact hp\n     end)\n\nlemma beast_666 (beast : \u2115) :\n  (\u2200n, n = 666 \u2192 beast \u2265 n) \u2194 beast \u2265 666 :=\nforall.one_point _ _\n\n#print beast_666\n\nlemma exists.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2203x : \u03b1, x = t \u2227 p x) \u2194 p t :=\niff.intro\n  (assume hex : \u2203x, x = t \u2227 p x,\n   show p t, from\n     exists.elim hex\n       (fix x,\n        assume hand : x = t \u2227 p x,\n        show p t, from\n          by cc))\n  (assume hp : p t,\n   show \u2203x : \u03b1, x = t \u2227 p x, from\n     exists.intro t\n       (show t = t \u2227 p t, from\n          by cc))\n\n\n/-! ## Calculational Proofs\n\nIn informal mathematics, we often use transitive chains of equalities,\ninequalities, or equivalences (e.g., `a \u2265 b \u2265 c`). In Lean, such calculational\nproofs are supported by `calc`.\n\nSyntax:\n\n    calc      _term\u2080_\n        _op\u2081_ _term\u2081_ :\n      _proof\u2081_\n    ... _op\u2082_ _term\u2082_ :\n      _proof\u2082_\n     \u22ee\n    ... _opN_ _termN_ :\n      _proofN_ -/\n\nlemma two_mul_example (m n : \u2115) :\n  2 * m + n = m + n + m :=\ncalc  2 * m + n\n    = (m + m) + n :\n  by rw two_mul\n... = m + n + m :\n  by cc\n\n/-! `calc` saves some repetition, some `have` labels, and some transitive\nreasoning: -/\n\nlemma two_mul_example\u2082 (m n : \u2115) :\n  2 * m + n = m + n + m :=\nhave h\u2081 : 2 * m + n = (m + m) + n :=\n  by rw two_mul,\nhave h\u2082 : (m + m) + n = m + n + m :=\n  by cc,\nshow _, from\n  eq.trans h\u2081 h\u2082\n\n\n/-! ## Forward Reasoning with Tactics\n\nThe `have`, `let`, and `calc` structured proof commands are also available as a\ntactic. Even in tactic mode, it can be useful to state intermediate results and\ndefinitions in a forward fashion.\n\nObserve that the syntax for the tactic `let` is slightly different than for the\nstructured proof command `let`, with `,` instead of `in`. -/\n\nlemma prop_comp\u2083 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  have hb : b :=\n    hab ha,\n  let c' := c,\n  have hc : c' :=\n    hbc hb,\n  exact hc\nend\n\n\n/-! ## Dependent Types\n\nDependent types are the defining feature of the dependent type theory family of\nlogics.\n\nConsider a function `pick` that take a number `n : \u2115` and that returns a number\nbetween 0 and `n`. Conceptually, `pick` has a dependent type, namely\n\n    `(n : \u2115) \u2192 {i : \u2115 // i \u2264 n}`\n\nWe can think of this type as a `\u2115`-indexed family, where each member's type may\ndepend on the index:\n\n    `pick n : {i : \u2115 // i \u2264 n}`\n\nBut a type may also depend on another type, e.g., `list` (or `\u03bb\u03b1, list \u03b1`) and\n`\u03bb\u03b1, \u03b1 \u2192 \u03b1`.\n\nA term may depend on a type, e.g., `\u03bb\u03b1, \u03bbx : \u03b1, x` (a polymorphic identity\nfunction).\n\nOf course, a term may also depend on a term.\n\nUnless otherwise specified, a __dependent type__ means a type depending on a\nterm. This is what we mean when we say that simple type theory does not support\ndependent types.\n\nIn summary, there are four cases for `\u03bbx, t` in the calculus of inductive\nconstructions (cf. Barendregt's `\u03bb`-cube):\n\nBody (`t`) |              | Argument (`x`) | Description\n---------- | ------------ | -------------- | ------------------------------\nA term     | depending on | a term         | Simply typed `\u03bb`-expression\nA type     | depending on | a term         | Dependent type (strictly speaking)\nA term     | depending on | a type         | Polymorphic term\nA type     | depending on | a type         | Type constructor\n\nRevised typing rules:\n\n    C \u22a2 t : (x : \u03c3) \u2192 \u03c4[x]    C \u22a2 u : \u03c3\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    C \u22a2 t u : \u03c4[u]\n\n    C, x : \u03c3 \u22a2 t : \u03c4[x]\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    C \u22a2 (\u03bbx : \u03c3, t) : (x : \u03c3) \u2192 \u03c4[x]\n\nThese two rules degenerate to `App` and `Lam` if `x` does not occur in `\u03c4[x]`\n\nExample of `App'`:\n\n    \u22a2 pick : (x : \u2115) \u2192 {y : \u2115 // y \u2264 x}    \u22a2 5 : \u2115\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    \u22a2 pick 5 : {y : \u2115 // y \u2264 5}\n\nExample of `Lam'`:\n\n    \u03b1 : Type, x : \u03b1 \u22a2 x : \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam or Lam'\n    \u03b1 : Type \u22a2 (\u03bbx : \u03b1, x) : \u03b1 \u2192 \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    \u22a2 (\u03bb\u03b1 : Type, \u03bbx : \u03b1, x) : (\u03b1 : Type) \u2192 \u03b1 \u2192 \u03b1\n\nRegrettably, the intuitive syntax `(x : \u03c3) \u2192 \u03c4` is not available in Lean.\nInstead, we must write `\u2200x : \u03c3, \u03c4` to specify a dependent type.\n\nAliases:\n\n    `\u03c3 \u2192 \u03c4` := `\u2200_ : \u03c3, \u03c4`\n    `\u03a0`     := `\u2200`\n\n\n## The PAT Principle\n\n`\u2192` is used both as the implication symbol and as the type constructor of\nfunctions. Similarly, `\u2200` is used both as a quantifier and in dependent types.\n\nThe two pairs of concepts not only look the same, they are the same, by the PAT\nprinciple:\n\n* PAT = propositions as types;\n* PAT = proofs as terms.\n\nTypes:\n\n* `\u03c3 \u2192 \u03c4` is the type of total functions from `\u03c3` to `\u03c4`;\n* `\u2200x : \u03c3, \u03c4[x]` is the dependent function type from `x : \u03c3` to `\u03c4[x]`.\n\nPropositions:\n\n* `P \u2192 Q` can be read as \"`P` implies `Q`\", or as the type of functions mapping\n  proofs of `P` to proofs of `Q`.\n* `\u2200x : \u03c3, Q[x]` can be read as \"for all `x`, `Q[x]`\", or as the type of\n  functions mapping values `x` of type `\u03c3` to proofs of `Q[x]`.\n\nTerms:\n\n* A constant is a term.\n* A variable is a term.\n* `t u` is the application of function `t` to value `u`.\n* `\u03bbx, t[x]` is a function mapping `x` to `t[x]`.\n\nProofs:\n\n* A lemma or hypothesis name is a proof.\n* `H t`, which instantiates the leading parameter or quantifier of proof `H`'\n  statement with term `t`, is a proof.\n* `H G`, which discharges the leading assumption of `H`'s statement with\n  proof `G`, is a proof.\n* `\u03bbh : P, H[h]` is a proof of `P \u2192 Q`, assuming `H[h]` is a proof of `Q`\n  for `h : P`.\n* `\u03bbx : \u03c3, H[x]` is a proof of `\u2200x : \u03c3, Q[x]`, assuming `H[x]` is a proof of\n  `Q[x]` for `x : \u03c3`. -/\n\nlemma and_swap\u2083 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\n\u03bbhab : a \u2227 b, and.intro (and.elim_right hab) (and.elim_left hab)\n\nlemma and_swap\u2084 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intro hab,\n  apply and.intro,\n  apply and.elim_right,\n  exact hab,\n  apply and.elim_left,\n  exact hab\nend\n\n/-! Tactical proofs are reduced to proof terms. -/\n\n#print and_swap\u2083\n#print and_swap\u2084\n\nend forward_proofs\n\n\n/-! ## Induction by Pattern Matching\n\nBy the PAT principle, a proof by induction is the same as a recursively\nspecified proof term. Thus, as alternative to the `induction'` tactic, induction\ncan also be done by pattern matching:\n\n * the induction hypothesis is then available under the name of the lemma we are\n   proving;\n\n * well-foundedness of the argument is often proved automatically. -/\n\n#check reverse\n\nlemma reverse_append {\u03b1 : Type} :\n  \u2200xs ys : list \u03b1,\n    reverse (xs ++ ys) = reverse ys ++ reverse xs\n| []        ys := by simp [reverse]\n| (x :: xs) ys := by simp [reverse, reverse_append xs]\n\nlemma reverse_append\u2082 {\u03b1 : Type} (xs ys : list \u03b1) :\n  reverse (xs ++ ys) = reverse ys ++ reverse xs :=\nbegin\n  induction' xs,\n  { simp [reverse] },\n  { simp [reverse, ih] }\nend\n\nlemma reverse_reverse {\u03b1 : Type} :\n  \u2200xs : list \u03b1, reverse (reverse xs) = xs\n| []        := by refl\n| (x :: xs) :=\n  by simp [reverse, reverse_append, reverse_reverse xs]\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/lectures/love03_forward_proofs_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7258904560695347}}
{"text": "import game.max.level09 -- hide\n\nopen_locale classical -- hide\n\nnoncomputable theory -- hide\n\nnamespace xena -- hide\n\n/-\n# Chapter ? : Max\n\n## Level 10\n\nAnd finally `lt_max_iff`. \n-/\n\n/- Lemma\nIf $a$, $b$, $c$ are real numbers,\nthen $a<\\max(b,c)$ iff ($a<b$ or $a<c$).\n-/\n\ntheorem lt_max_iff {a b c : \u211d} : a < max b c \u2194 a < b \u2228 a < c :=\nbegin\n  split,\n  { intro ha,\n    cases le_total b c with hbc hcb,\n    { rw max_eq_right hbc at ha,\n      right,\n      assumption,\n    },\n    { rw max_eq_left hcb at ha,\n      left,\n      assumption\n    }\n  },\n  { intro habc,\n    cases habc with hab hac,\n    { apply lt_of_lt_of_le hab,\n      apply le_max_left},\n    { apply lt_of_lt_of_le hac,\n      apply le_max_right},\n  }\nend\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/max/level10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7258124652632352}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\n\nimport algebra.order.absolute_value\nimport algebra.big_operators.basic\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `\u220f` and `\u2211` operations.\n\n-/\n\nopen function\nopen_locale big_operators\n\nvariables {\u03b9 \u03b1 \u03b2 M N G k R : Type*}\n\nnamespace finset\n\nsection ordered_comm_monoid\n\nvariables [comm_monoid M] [ordered_comm_monoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M \u2192 N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y`. Let `g i`, `i \u2208 s`, be\na nonempty finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u220f x in s, g x) \u2264 \u220f x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\nlemma le_prod_nonempty_of_submultiplicative_on_pred\n  (f : M \u2192 N) (p : M \u2192 Prop) (h_mul : \u2200 x y, p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y)\n  (hp_mul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (g : \u03b9 \u2192 M) (s : finset \u03b9) (hs_nonempty : s.nonempty)\n  (hs : \u2200 i \u2208 s, p (g i)) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  refine le_trans (multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _,\n  { simp [hs_nonempty.ne_empty], },\n  { exact multiset.forall_mem_map_iff.mpr hs, },\n  rw multiset.map_map,\n  refl,\nend\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M \u2192 N` be a map subadditive on `{x | p x}`, i.e., `p x \u2192 p y \u2192 f (x + y) \u2264 f x + f y`. Let\n`g i`, `i \u2208 s`, be a nonempty finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M \u2192 N` is a submultiplicative function, `f (x * y) \u2264 f x * f y` and `g i`, `i \u2208 s`, is a\nnonempty finite family of elements of `M`, then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\nlemma le_prod_nonempty_of_submultiplicative\n  (f : M \u2192 N) (h_mul : \u2200 x y, f (x * y) \u2264 f x * f y) {s : finset \u03b9} (hs : s.nonempty) (g : \u03b9 \u2192 M) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nle_prod_nonempty_of_submultiplicative_on_pred f (\u03bb i, true) (\u03bb x y _ _, h_mul x y)\n  (\u03bb _ _ _ _, trivial) g s hs (\u03bb _ _, trivial)\n\n/-- If `f : M \u2192 N` is a subadditive function, `f (x + y) \u2264 f x + f y` and `g i`, `i \u2208 s`, is a\nnonempty finite family of elements of `M`, then `f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M \u2192 N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y`. Let `g i`, `i \u2208 s`, be a finite family of elements of `M` such\nthat `\u2200 i \u2208 s, p (g i)`. Then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\nlemma le_prod_of_submultiplicative_on_pred (f : M \u2192 N) (p : M \u2192 Prop) (h_one : f 1 = 1)\n  (h_mul : \u2200 x y, p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y)\n  (hp_mul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (g : \u03b9 \u2192 M) {s : finset \u03b9} (hs : \u2200 i \u2208 s, p (g i)) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  rcases eq_empty_or_nonempty s with rfl|hs_nonempty,\n  { simp [h_one] },\n  { exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs, },\nend\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M \u2192 N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x \u2192 p y \u2192 f (x + y) \u2264 f x + f y`.\nLet `g i`, `i \u2208 s`, be a finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u2211 x in s, g x) \u2264 \u2211 x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M \u2192 N` is a submultiplicative function, `f (x * y) \u2264 f x * f y`, `f 1 = 1`, and `g i`,\n`i \u2208 s`, is a finite family of elements of `M`, then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\nlemma le_prod_of_submultiplicative (f : M \u2192 N) (h_one : f 1 = 1)\n  (h_mul : \u2200 x y, f (x * y) \u2264 f x * f y) (s : finset \u03b9) (g : \u03b9 \u2192 M) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  refine le_trans (multiset.le_prod_of_submultiplicative f h_one h_mul _) _,\n  rw multiset.map_map,\n  refl,\nend\n\n/-- If `f : M \u2192 N` is a subadditive function, `f (x + y) \u2264 f x + f y`, `f 0 = 0`, and `g i`,\n`i \u2208 s`, is a finite family of elements of `M`, then `f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariables {f g : \u03b9 \u2192 N} {s t : finset \u03b9}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`\u220f i in s, f i \u2264 \u220f i in s, g i`. -/\n@[to_additive sum_le_sum]\nlemma prod_le_prod'' (h : \u2200 i \u2208 s, f i \u2264 g i) : \u220f i in s, f i \u2264 \u220f i in s, g i :=\nbegin\n  classical,\n  induction s using finset.induction_on with i s hi ihs h,\n  { refl },\n  { simp only [prod_insert hi],\n    exact mul_le_mul' (h _ (mem_insert_self _ _)) (ihs $ \u03bb j hj, h j (mem_insert_of_mem hj)) }\nend\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`\u2211 i in s, f i \u2264 \u2211 i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n@[to_additive sum_nonneg] lemma one_le_prod' (h : \u2200i \u2208 s, 1 \u2264 f i) : 1 \u2264 (\u220f i in s, f i) :=\nle_trans (by rw prod_const_one) (prod_le_prod'' h)\n\n@[to_additive finset.sum_nonneg']\nlemma one_le_prod'' (h : \u2200 (i : \u03b9), 1 \u2264 f i) : 1 \u2264 \u220f (i : \u03b9) in s, f i :=\nfinset.one_le_prod' (\u03bb i hi, h i)\n\n@[to_additive sum_nonpos] lemma prod_le_one' (h : \u2200i \u2208 s, f i \u2264 1) : (\u220f i in s, f i) \u2264 1 :=\n(prod_le_prod'' h).trans_eq (by rw prod_const_one)\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\nlemma prod_le_prod_of_subset_of_one_le' (h : s \u2286 t) (hf : \u2200 i \u2208 t, i \u2209 s \u2192 1 \u2264 f i) :\n  \u220f i in s, f i \u2264 \u220f i in t, f i :=\nby classical;\ncalc (\u220f i in s, f i) \u2264 (\u220f i in t \\ s, f i) * (\u220f i in s, f i) :\n    le_mul_of_one_le_left' $ one_le_prod' $ by simpa only [mem_sdiff, and_imp]\n  ... = \u220f i in t \\ s \u222a s, f i : (prod_union sdiff_disjoint).symm\n  ... = \u220f i in t, f i         : by rw [sdiff_union_of_subset h]\n\n@[to_additive sum_mono_set_of_nonneg]\nlemma prod_mono_set_of_one_le' (hf : \u2200 x, 1 \u2264 f x) : monotone (\u03bb s, \u220f x in s, f x) :=\n\u03bb s t hst, prod_le_prod_of_subset_of_one_le' hst $ \u03bb x _ _, hf x\n\n@[to_additive sum_le_univ_sum_of_nonneg]\nlemma prod_le_univ_prod_of_one_le' [fintype \u03b9] {s : finset \u03b9} (w : \u2200 x, 1 \u2264 f x) :\n  \u220f x in s, f x \u2264 \u220f x, f x :=\nprod_le_prod_of_subset_of_one_le' (subset_univ s) (\u03bb a _ _, w a)\n\n@[to_additive sum_eq_zero_iff_of_nonneg]\nlemma prod_eq_one_iff_of_one_le' : (\u2200 i \u2208 s, 1 \u2264 f i) \u2192 (\u220f i in s, f i = 1 \u2194 \u2200 i \u2208 s, f i = 1) :=\nbegin\n  classical,\n  apply finset.induction_on s,\n  exact \u03bb _, \u27e8\u03bb _ _, false.elim, \u03bb _, rfl\u27e9,\n  assume a s ha ih H,\n  have : \u2200 i \u2208 s, 1 \u2264 f i, from \u03bb _, H _ \u2218 mem_insert_of_mem,\n  rw [prod_insert ha, mul_eq_one_iff' (H _ $ mem_insert_self _ _) (one_le_prod' this),\n    forall_mem_insert, ih this]\nend\n\n@[to_additive sum_eq_zero_iff_of_nonneg]\nlemma prod_eq_one_iff_of_le_one' : (\u2200 i \u2208 s, f i \u2264 1) \u2192 (\u220f i in s, f i = 1 \u2194 \u2200 i \u2208 s, f i = 1) :=\n@prod_eq_one_iff_of_one_le' _ (order_dual N) _ _ _\n\n@[to_additive single_le_sum]\nlemma single_le_prod' (hf : \u2200 i \u2208 s, 1 \u2264 f i) {a} (h : a \u2208 s) : f a \u2264 (\u220f x in s, f x) :=\ncalc f a = \u220f i in {a}, f i : prod_singleton.symm\n     ... \u2264 \u220f i in s, f i   :\n  prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) $ \u03bb i hi _, hf i hi\n\n@[to_additive]\nlemma prod_le_of_forall_le (s : finset \u03b9) (f : \u03b9 \u2192 N) (n : N) (h : \u2200 x \u2208 s, f x \u2264 n) :\n  s.prod f \u2264 n ^ s.card :=\nbegin\n  refine (multiset.prod_le_of_forall_le (s.val.map f) n _).trans _,\n  { simpa using h },\n  { simpa }\nend\n\n@[to_additive]\nlemma le_prod_of_forall_le (s : finset \u03b9) (f : \u03b9 \u2192 N) (n : N) (h : \u2200 x \u2208 s, n \u2264 f x) :\n  n ^ s.card \u2264 s.prod f :=\n@finset.prod_le_of_forall_le _ (order_dual N) _ _ _ _ h\n\nlemma card_bUnion_le_card_mul [decidable_eq \u03b2] (s : finset \u03b9) (f : \u03b9 \u2192 finset \u03b2) (n : \u2115)\n  (h : \u2200 a \u2208 s, (f a).card \u2264 n) :\n  (s.bUnion f).card \u2264 s.card * n :=\ncard_bUnion_le.trans $ sum_le_of_forall_le _ _ _ h\n\nvariables {\u03b9' : Type*} [decidable_eq \u03b9']\n\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\nlemma prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : finset \u03b9'}\n  {g : \u03b9 \u2192 \u03b9'} {f : \u03b9 \u2192 N} (h : \u2200 y \u2209 t, (1 : N) \u2264 \u220f x in s.filter (\u03bb x, g x = y), f x) :\n  \u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x \u2264 \u220f x in s, f x :=\ncalc (\u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x) \u2264\n  (\u220f y in t \u222a s.image g, \u220f x in s.filter (\u03bb x, g x = y), f x) :\n  prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) $ \u03bb y hyts, h y\n... = \u220f x in s, f x :\n  prod_fiberwise_of_maps_to (\u03bb x hx, mem_union.2 $ or.inr $ mem_image_of_mem _ hx) _\n\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\nlemma prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : finset \u03b9'}\n  {g : \u03b9 \u2192 \u03b9'} {f : \u03b9 \u2192 N} (h : \u2200 y \u2209 t, (\u220f x in s.filter (\u03bb x, g x = y), f x) \u2264 1) :\n  (\u220f x in s, f x) \u2264 \u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x :=\n@prod_fiberwise_le_prod_of_one_le_prod_fiber' _ (order_dual N) _ _ _ _ _ _ _ h\n\nend ordered_comm_monoid\n\nlemma abs_sum_le_sum_abs {G : Type*} [linear_ordered_add_comm_group G] (f : \u03b9 \u2192 G) (s : finset \u03b9) :\n  |\u2211 i in s, f i| \u2264 \u2211 i in s, |f i| :=\nle_sum_of_subadditive _ abs_zero abs_add s f\n\nlemma abs_sum_of_nonneg {G : Type*} [linear_ordered_add_comm_group G] {f : \u03b9 \u2192 G} {s : finset \u03b9}\n  (hf : \u2200 i \u2208 s, 0 \u2264 f i) :\n  |\u2211 (i : \u03b9) in s, f i| = \u2211 (i : \u03b9) in s, f i :=\nby rw abs_of_nonneg (finset.sum_nonneg hf)\n\nlemma abs_sum_of_nonneg' {G : Type*} [linear_ordered_add_comm_group G] {f : \u03b9 \u2192 G} {s : finset \u03b9}\n  (hf : \u2200 i, 0 \u2264 f i) :\n  |\u2211 (i : \u03b9) in s, f i| = \u2211 (i : \u03b9) in s, f i :=\nby rw abs_of_nonneg (finset.sum_nonneg' hf)\n\nlemma abs_prod {R : Type*} [linear_ordered_comm_ring R] {f : \u03b9 \u2192 R} {s : finset \u03b9} :\n  |\u220f x in s, f x| = \u220f x in s, |f x| :=\n(abs_hom.to_monoid_hom : R \u2192* R).map_prod _ _\n\nsection pigeonhole\n\nvariable [decidable_eq \u03b2]\n\ntheorem card_le_mul_card_image_of_maps_to {f : \u03b1 \u2192 \u03b2} {s : finset \u03b1} {t : finset \u03b2}\n  (Hf : \u2200 a \u2208 s, f a \u2208 t) (n : \u2115) (hn : \u2200 a \u2208 t, (s.filter (\u03bb x, f x = a)).card \u2264 n) :\n  s.card \u2264 n * t.card :=\ncalc s.card = (\u2211 a in t, (s.filter (\u03bb x, f x = a)).card) : card_eq_sum_card_fiberwise Hf\n        ... \u2264 (\u2211 _ in t, n)                              : sum_le_sum hn\n        ... = _                                          : by simp [mul_comm]\n\ntheorem card_le_mul_card_image {f : \u03b1 \u2192 \u03b2} (s : finset \u03b1)\n  (n : \u2115) (hn : \u2200 a \u2208 s.image f, (s.filter (\u03bb x, f x = a)).card \u2264 n) :\n  s.card \u2264 n * (s.image f).card :=\ncard_le_mul_card_image_of_maps_to (\u03bb x, mem_image_of_mem _) n hn\n\ntheorem mul_card_image_le_card_of_maps_to {f : \u03b1 \u2192 \u03b2} {s : finset \u03b1} {t : finset \u03b2}\n  (Hf : \u2200 a \u2208 s, f a \u2208 t) (n : \u2115) (hn : \u2200 a \u2208 t, n \u2264 (s.filter (\u03bb x, f x = a)).card) :\n  n * t.card \u2264 s.card :=\ncalc n * t.card = (\u2211 _ in t, n) : by simp [mul_comm]\n            ... \u2264 (\u2211 a in t, (s.filter (\u03bb x, f x = a)).card) : sum_le_sum hn\n            ... = s.card : by rw \u2190 card_eq_sum_card_fiberwise Hf\n\ntheorem mul_card_image_le_card {f : \u03b1 \u2192 \u03b2} (s : finset \u03b1)\n  (n : \u2115) (hn : \u2200 a \u2208 s.image f, n \u2264 (s.filter (\u03bb x, f x = a)).card) :\n  n * (s.image f).card \u2264 s.card :=\nmul_card_image_le_card_of_maps_to (\u03bb x, mem_image_of_mem _) n hn\n\nend pigeonhole\n\nsection double_counting\nvariables [decidable_eq \u03b1] {s : finset \u03b1} {B : finset (finset \u03b1)} {n : \u2115}\n\n/-- If every element belongs to at most `n` finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\nlemma sum_card_inter_le (h : \u2200 a \u2208 s, (B.filter $ (\u2208) a).card \u2264 n) :\n  \u2211 t in B, (s \u2229 t).card \u2264 s.card * n :=\nbegin\n  refine le_trans _ (s.sum_le_of_forall_le _ _ h),\n  simp_rw [\u2190filter_mem_eq_inter, card_eq_sum_ones, sum_filter],\n  exact sum_comm.le,\nend\n\n/-- If every element belongs to at most `n` finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\nlemma sum_card_le [fintype \u03b1] (h : \u2200 a, (B.filter $ (\u2208) a).card \u2264 n) :\n  \u2211 s in B, s.card \u2264 fintype.card \u03b1 * n :=\ncalc \u2211 s in B, s.card = \u2211 s in B, (univ \u2229 s).card : by simp_rw univ_inter\n                  ... \u2264 fintype.card \u03b1 * n        : sum_card_inter_le (\u03bb a _, h a)\n\n/-- If every element belongs to at least `n` finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\nlemma le_sum_card_inter (h : \u2200 a \u2208 s, n \u2264 (B.filter $ (\u2208) a).card) :\n  s.card * n \u2264 \u2211 t in B, (s \u2229 t).card :=\nbegin\n  apply (s.le_sum_of_forall_le _ _ h).trans,\n  simp_rw [\u2190filter_mem_eq_inter, card_eq_sum_ones, sum_filter],\n  exact sum_comm.le,\nend\n\n/-- If every element belongs to at least `n` finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\nlemma le_sum_card [fintype \u03b1] (h : \u2200 a, n \u2264 (B.filter $ (\u2208) a).card) :\n  fintype.card \u03b1 * n \u2264 \u2211 s in B, s.card :=\ncalc fintype.card \u03b1 * n \u2264 \u2211 s in B, (univ \u2229 s).card : le_sum_card_inter (\u03bb a _, h a)\n                    ... = \u2211 s in B, s.card          : by simp_rw univ_inter\n\n/-- If every element belongs to exactly `n` finsets, then the sum of their sizes is `n` times how\nmany they are. -/\nlemma sum_card_inter (h : \u2200 a \u2208 s, (B.filter $ (\u2208) a).card = n) :\n  \u2211 t in B, (s \u2229 t).card = s.card * n :=\n(sum_card_inter_le $ \u03bb a ha, (h a ha).le).antisymm (le_sum_card_inter $ \u03bb a ha, (h a ha).ge)\n\n/-- If every element belongs to exactly `n` finsets, then the sum of their sizes is `n` times how\nmany they are. -/\nlemma sum_card [fintype \u03b1] (h : \u2200 a, (B.filter $ (\u2208) a).card = n) :\n  \u2211 s in B, s.card = fintype.card \u03b1 * n :=\nby simp_rw [fintype.card, \u2190sum_card_inter (\u03bb a _, h a), univ_inter]\n\nlemma card_le_card_bUnion {s : finset \u03b9} {f : \u03b9 \u2192 finset \u03b1} (hs : (s : set \u03b9).pairwise_disjoint f)\n  (hf : \u2200 i \u2208 s, (f i).nonempty) :\n  s.card \u2264 (s.bUnion f).card :=\nby { rw [card_bUnion hs, card_eq_sum_ones], exact sum_le_sum (\u03bb i hi, (hf i hi).card_pos) }\n\nlemma card_le_card_bUnion_add_card_fiber {s : finset \u03b9} {f : \u03b9 \u2192 finset \u03b1}\n  (hs : (s : set \u03b9).pairwise_disjoint f) :\n  s.card \u2264 (s.bUnion f).card + (s.filter $ \u03bb i, f i = \u2205).card :=\nbegin\n  rw [\u2190finset.filter_card_add_filter_neg_card_eq_card (\u03bb i, f i = \u2205), add_comm],\n  exact add_le_add_right ((card_le_card_bUnion (hs.subset $ filter_subset _ _) $ \u03bb i hi,\n    nonempty_of_ne_empty $ (mem_filter.1 hi).2).trans $ card_le_of_subset $\n    bUnion_subset_bUnion_of_subset_left _ $ filter_subset _ _) _,\nend\n\nlemma card_le_card_bUnion_add_one {s : finset \u03b9} {f : \u03b9 \u2192 finset \u03b1} (hf : injective f)\n  (hs : (s : set \u03b9).pairwise_disjoint f) :\n  s.card \u2264 (s.bUnion f).card + 1 :=\n(card_le_card_bUnion_add_card_fiber hs).trans $ add_le_add_left (card_le_one.2 $ \u03bb i hi j hj, hf $\n  (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n\nend double_counting\n\nsection canonically_ordered_monoid\n\nvariables [canonically_ordered_monoid M] {f : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[simp, to_additive sum_eq_zero_iff]\nlemma prod_eq_one_iff' : \u220f x in s, f x = 1 \u2194 \u2200 x \u2208 s, f x = 1 :=\nprod_eq_one_iff_of_one_le' $ \u03bb x hx, one_le (f x)\n\n@[to_additive sum_le_sum_of_subset]\nlemma prod_le_prod_of_subset' (h : s \u2286 t) : \u220f x in s, f x \u2264 \u220f x in t, f x :=\nprod_le_prod_of_subset_of_one_le' h $ assume x h\u2081 h\u2082, one_le _\n\n@[to_additive sum_mono_set]\nlemma prod_mono_set' (f : \u03b9 \u2192 M) : monotone (\u03bb s, \u220f x in s, f x) :=\n\u03bb s\u2081 s\u2082 hs, prod_le_prod_of_subset' hs\n\n@[to_additive sum_le_sum_of_ne_zero]\nlemma prod_le_prod_of_ne_one' (h : \u2200 x \u2208 s, f x \u2260 1 \u2192 x \u2208 t) :\n  \u220f x in s, f x \u2264 \u220f x in t, f x :=\nby classical;\ncalc \u220f x in s, f x = (\u220f x in s.filter (\u03bb x, f x = 1), f x) * \u220f x in s.filter (\u03bb x, f x \u2260 1), f x :\n    by rw [\u2190 prod_union, filter_union_filter_neg_eq];\n       exact disjoint_filter.2 (assume _ _ h n_h, n_h h)\n  ... \u2264 (\u220f x in t, f x) : mul_le_of_le_one_of_le\n      (prod_le_one' $ by simp only [mem_filter, and_imp]; exact \u03bb _ _, le_of_eq)\n      (prod_le_prod_of_subset' $ by simpa only [subset_iff, mem_filter, and_imp])\n\nend canonically_ordered_monoid\n\nsection ordered_cancel_comm_monoid\n\nvariables [ordered_cancel_comm_monoid M] {f g : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (Hle : \u2200 i \u2208 s, f i \u2264 g i) (Hlt : \u2203 i \u2208 s, f i < g i) :\n  \u220f i in s, f i < \u220f i in s, g i :=\nbegin\n  classical,\n  rcases Hlt with \u27e8i, hi, hlt\u27e9,\n  rw [\u2190 insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)],\n  exact mul_lt_mul_of_lt_of_le hlt (prod_le_prod'' $ \u03bb j hj, Hle j  $ mem_of_mem_erase hj)\nend\n\n@[to_additive sum_lt_sum_of_nonempty]\nlemma prod_lt_prod_of_nonempty' (hs : s.nonempty) (Hlt : \u2200 i \u2208 s, f i < g i) :\n  \u220f i in s, f i < \u220f i in s, g i :=\nbegin\n  apply prod_lt_prod',\n  { intros i hi, apply le_of_lt (Hlt i hi) },\n  cases hs with i hi,\n  exact \u27e8i, hi, Hlt i hi\u27e9,\nend\n\n@[to_additive sum_lt_sum_of_subset]\nlemma prod_lt_prod_of_subset' (h : s \u2286 t) {i : \u03b9} (ht : i \u2208 t) (hs : i \u2209 s) (hlt : 1 < f i)\n  (hle : \u2200 j \u2208 t, j \u2209 s \u2192 1 \u2264 f j) :\n  \u220f j in s, f j < \u220f j in t, f j :=\nby classical;\ncalc \u220f j in s, f j < \u220f j in insert i s, f j :\nbegin\n  rw prod_insert hs,\n  exact lt_mul_of_one_lt_left' (\u220f j in s, f j) hlt,\nend\n... \u2264 \u220f j in t, f j :\nbegin\n  apply prod_le_prod_of_subset_of_one_le',\n  { simp [finset.insert_subset, h, ht] },\n  { assume x hx h'x,\n    simp only [mem_insert, not_or_distrib] at h'x,\n    exact hle x hx h'x.2 }\nend\n\n@[to_additive single_lt_sum]\nlemma single_lt_prod' {i j : \u03b9} (hij : j \u2260 i) (hi : i \u2208 s) (hj : j \u2208 s) (hlt : 1 < f j)\n  (hle : \u2200 k \u2208 s, k \u2260 i \u2192 1 \u2264 f k) :\n  f i < \u220f k in s, f k :=\ncalc f i = \u220f k in {i}, f k : prod_singleton.symm\n     ... < \u220f k in s, f k   :\n  prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt $\n    \u03bb k hks hki, hle k hks (mt mem_singleton.2 hki)\n\n@[to_additive sum_pos] lemma one_lt_prod (h : \u2200i \u2208 s, 1 < f i) (hs : s.nonempty) :\n  1 < (\u220f i in s, f i) :=\nlt_of_le_of_lt (by rw prod_const_one) $ prod_lt_prod_of_nonempty' hs h\n\n@[to_additive] lemma prod_lt_one (h : \u2200i \u2208 s, f i < 1) (hs : s.nonempty) :\n  (\u220f i in s, f i) < 1 :=\n(prod_lt_prod_of_nonempty' hs h).trans_le (by rw prod_const_one)\n\n@[to_additive] lemma prod_eq_prod_iff_of_le {f g : \u03b9 \u2192 M} (h : \u2200 i \u2208 s, f i \u2264 g i) :\n  \u220f i in s, f i = \u220f i in s, g i \u2194 \u2200 i \u2208 s, f i = g i :=\nbegin\n  classical,\n  revert h,\n  refine finset.induction_on s (\u03bb _, \u27e8\u03bb _ _, false.elim, \u03bb _, rfl\u27e9) (\u03bb a s ha ih H, _),\n  specialize ih (\u03bb i, H i \u2218 finset.mem_insert_of_mem),\n  rw [finset.prod_insert ha, finset.prod_insert ha, finset.forall_mem_insert, \u2190ih],\n  exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (finset.prod_le_prod''\n    (\u03bb i, H i \u2218 finset.mem_insert_of_mem)),\nend\n\nend ordered_cancel_comm_monoid\n\nsection linear_ordered_cancel_comm_monoid\n\nvariables [linear_ordered_cancel_comm_monoid M] {f g : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : \u220f i in s, f i < \u220f i in s, g i) :\n  \u2203 i \u2208 s, f i < g i :=\nbegin\n  contrapose! Hlt with Hle,\n  exact prod_le_prod'' Hle\nend\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.nonempty) (Hle : \u220f i in s, f i \u2264 \u220f i in s, g i) :\n  \u2203 i \u2208 s, f i \u2264 g i :=\nbegin\n  contrapose! Hle with Hlt,\n  exact prod_lt_prod_of_nonempty' hs Hlt\nend\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\nlemma exists_one_lt_of_prod_one_of_exists_ne_one' (f : \u03b9 \u2192 M)\n  (h\u2081 : \u220f i in s, f i = 1) (h\u2082 : \u2203 i \u2208 s, f i \u2260 1) :\n  \u2203 i \u2208 s, 1 < f i :=\nbegin\n  contrapose! h\u2081,\n  obtain \u27e8i, m, i_ne\u27e9 : \u2203 i \u2208 s, f i \u2260 1 := h\u2082,\n  apply ne_of_lt,\n  calc \u220f j in s, f j < \u220f j in s, 1 : prod_lt_prod' h\u2081 \u27e8i, m, (h\u2081 i m).lt_of_ne i_ne\u27e9\n                 ... = 1           : prod_const_one\nend\n\nend linear_ordered_cancel_comm_monoid\n\nsection ordered_comm_semiring\n\nvariables [ordered_comm_semiring R] {f g : \u03b9 \u2192 R} {s t : finset \u03b9}\nopen_locale classical\n\n/- this is also true for a ordered commutative multiplicative monoid -/\nlemma prod_nonneg (h0 : \u2200 i \u2208 s, 0 \u2264 f i) : 0 \u2264 \u220f i in s, f i :=\nprod_induction f (\u03bb i, 0 \u2264 i) (\u03bb _ _ ha hb, mul_nonneg ha hb) zero_le_one h0\n\n/- this is also true for a ordered commutative multiplicative monoid -/\nlemma prod_pos [nontrivial R] (h0 : \u2200 i \u2208 s, 0 < f i) :\n  0 < \u220f i in s, f i :=\nprod_induction f (\u03bb x, 0 < x) (\u03bb _ _ ha hb, mul_pos ha hb) zero_lt_one h0\n\n/-- If all `f i`, `i \u2208 s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `finset.prod_le_prod''` for\nthe case of an ordered commutative multiplicative monoid. -/\nlemma prod_le_prod (h0 : \u2200 i \u2208 s, 0 \u2264 f i) (h1 : \u2200 i \u2208 s, f i \u2264 g i) :\n  \u220f i in s, f i \u2264 \u220f i in s, g i :=\nbegin\n  induction s using finset.induction with a s has ih h,\n  { simp },\n  { simp only [prod_insert has], apply mul_le_mul,\n    { exact h1 a (mem_insert_self a s) },\n    { apply ih (\u03bb x H, h0 _ _) (\u03bb x H, h1 _ _); exact (mem_insert_of_mem H) },\n    { apply prod_nonneg (\u03bb x H, h0 x (mem_insert_of_mem H)) },\n    { apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) } }\nend\n\n/-- If each `f i`, `i \u2208 s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\nlemma prod_le_one (h0 : \u2200 i \u2208 s, 0 \u2264 f i) (h1 : \u2200 i \u2208 s, f i \u2264 1) :\n  \u220f i in s, f i \u2264 1 :=\nbegin\n  convert \u2190 prod_le_prod h0 h1,\n  exact finset.prod_const_one\nend\n\n/-- If `g, h \u2264 f` and `g i + h i \u2264 f i`, then the product of `f` over `s` is at least the\n  sum of the products of `g` and `h`. This is the version for `ordered_comm_semiring`. -/\nlemma prod_add_prod_le {i : \u03b9} {f g h : \u03b9 \u2192 R}\n  (hi : i \u2208 s) (h2i : g i + h i \u2264 f i) (hgf : \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2264 f j)\n  (hhf : \u2200 j \u2208 s, j \u2260 i \u2192 h j \u2264 f j) (hg : \u2200 i \u2208 s, 0 \u2264 g i) (hh : \u2200 i \u2208 s, 0 \u2264 h i) :\n  \u220f i in s, g i + \u220f i in s, h i \u2264 \u220f i in s, f i :=\nbegin\n  simp_rw [prod_eq_mul_prod_diff_singleton hi],\n  refine le_trans _ (mul_le_mul_of_nonneg_right h2i _),\n  { rw [right_distrib],\n    apply add_le_add; apply mul_le_mul_of_nonneg_left; try { apply_assumption; assumption };\n      apply prod_le_prod; simp * { contextual := tt } },\n  { apply prod_nonneg, simp only [and_imp, mem_sdiff, mem_singleton],\n    intros j h1j h2j, exact le_trans (hg j h1j) (hgf j h1j h2j) }\nend\n\nend ordered_comm_semiring\n\nsection canonically_ordered_comm_semiring\n\nvariables [canonically_ordered_comm_semiring R] {f g h : \u03b9 \u2192 R} {s : finset \u03b9} {i : \u03b9}\n\nlemma prod_le_prod' (h : \u2200 i \u2208 s, f i \u2264 g i) :\n  \u220f i in s, f i \u2264 \u220f i in s, g i :=\nbegin\n  classical,\n  induction s using finset.induction with a s has ih h,\n  { simp },\n  { rw [finset.prod_insert has, finset.prod_insert has],\n    apply mul_le_mul',\n    { exact h _ (finset.mem_insert_self a s) },\n    { exact ih (\u03bb i hi, h _ (finset.mem_insert_of_mem hi)) } }\nend\n\n/-- If `g, h \u2264 f` and `g i + h i \u2264 f i`, then the product of `f` over `s` is at least the\n  sum of the products of `g` and `h`. This is the version for `canonically_ordered_comm_semiring`.\n-/\nlemma prod_add_prod_le' (hi : i \u2208 s) (h2i : g i + h i \u2264 f i)\n  (hgf : \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2264 f j) (hhf : \u2200 j \u2208 s, j \u2260 i \u2192 h j \u2264 f j) :\n  \u220f i in s, g i + \u220f i in s, h i \u2264 \u220f i in s, f i :=\nbegin\n  classical, simp_rw [prod_eq_mul_prod_diff_singleton hi],\n  refine le_trans _ (mul_le_mul_right' h2i _),\n  rw [right_distrib],\n  apply add_le_add; apply mul_le_mul_left'; apply prod_le_prod';\n  simp only [and_imp, mem_sdiff, mem_singleton]; intros; apply_assumption; assumption\nend\n\nend canonically_ordered_comm_semiring\n\nend finset\n\nnamespace fintype\n\nvariables [fintype \u03b9]\n\n@[to_additive sum_mono, mono]\nlemma prod_mono' [ordered_comm_monoid M] : monotone (\u03bb f : \u03b9 \u2192 M, \u220f i, f i) :=\n\u03bb f g hfg, finset.prod_le_prod'' $ \u03bb x _, hfg x\n\nattribute [mono] sum_mono\n\n@[to_additive sum_strict_mono]\nlemma prod_strict_mono' [ordered_cancel_comm_monoid M] : strict_mono (\u03bb f : \u03b9 \u2192 M, \u220f x, f x) :=\n\u03bb f g hfg, let \u27e8hle, i, hlt\u27e9 := pi.lt_def.mp hfg in\n  finset.prod_lt_prod' (\u03bb i _, hle i) \u27e8i, finset.mem_univ i, hlt\u27e9\n\nend fintype\n\nnamespace with_top\nopen finset\n\n/-- A product of finite numbers is still finite -/\nlemma prod_lt_top [canonically_ordered_comm_semiring R] [nontrivial R] [decidable_eq R]\n  {s : finset \u03b9} {f : \u03b9 \u2192 with_top R} (h : \u2200 i \u2208 s, f i \u2260 \u22a4) :\n  \u220f i in s, f i < \u22a4 :=\nprod_induction f (\u03bb a, a < \u22a4) (\u03bb a b h\u2081 h\u2082, mul_lt_top h\u2081.ne h\u2082.ne) (coe_lt_top 1) $\n  \u03bb a ha, lt_top_iff_ne_top.2 (h a ha)\n\n/-- A sum of finite numbers is still finite -/\nlemma sum_lt_top [ordered_add_comm_monoid M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M}\n  (h : \u2200 i \u2208 s, f i \u2260 \u22a4) : (\u2211 i in s, f i) < \u22a4 :=\nsum_induction f (\u03bb a, a < \u22a4) (\u03bb a b h\u2081 h\u2082, add_lt_top.2 \u27e8h\u2081, h\u2082\u27e9) zero_lt_top $\n  \u03bb i hi, lt_top_iff_ne_top.2 (h i hi)\n\n/-- A sum of numbers is infinite iff one of them is infinite -/\nlemma sum_eq_top_iff [ordered_add_comm_monoid M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M} :\n  \u2211 i in s, f i = \u22a4 \u2194 \u2203 i \u2208 s, f i = \u22a4 :=\nbegin\n  classical,\n  split,\n  { contrapose!,\n    exact \u03bb h, (sum_lt_top $ \u03bb i hi, (h i hi)).ne },\n  { rintro \u27e8i, his, hi\u27e9,\n    rw [sum_eq_add_sum_diff_singleton his, hi, top_add] }\nend\n\n/-- A sum of finite numbers is still finite -/\nlemma sum_lt_top_iff [ordered_add_comm_monoid M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M} :\n  \u2211 i in s, f i < \u22a4 \u2194 \u2200 i \u2208 s, f i < \u22a4 :=\nby simp only [lt_top_iff_ne_top, ne.def, sum_eq_top_iff, not_exists]\n\nend with_top\n\nsection absolute_value\n\nvariables {S : Type*}\n\nlemma absolute_value.sum_le [semiring R] [ordered_semiring S]\n  (abv : absolute_value R S) (s : finset \u03b9) (f : \u03b9 \u2192 R) :\n  abv (\u2211 i in s, f i) \u2264 \u2211 i in s, abv (f i) :=\nbegin\n  letI := classical.dec_eq \u03b9,\n  refine finset.induction_on s _ (\u03bb i s hi ih, _),\n  { simp },\n  { simp only [finset.sum_insert hi],\n  exact (abv.add_le _ _).trans (add_le_add le_rfl ih) },\nend\n\nlemma is_absolute_value.abv_sum [semiring R] [ordered_semiring S] (abv : R \u2192 S)\n  [is_absolute_value abv] (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u2211 i in s, f i) \u2264 \u2211 i in s, abv (f i) :=\n(is_absolute_value.to_absolute_value abv).sum_le _ _\n\nlemma absolute_value.map_prod [comm_semiring R] [nontrivial R] [linear_ordered_comm_ring S]\n  (abv : absolute_value R S) (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u220f i in s, f i) = \u220f i in s, abv (f i) :=\nabv.to_monoid_hom.map_prod f s\n\nlemma is_absolute_value.map_prod [comm_semiring R] [nontrivial R] [linear_ordered_comm_ring S]\n  (abv : R \u2192 S) [is_absolute_value abv] (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u220f i in s, f i) = \u220f i in s, abv (f i) :=\n(is_absolute_value.to_absolute_value abv).map_prod _ _\n\nend absolute_value\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/big_operators/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7258012232048899}}
{"text": "/-\nCopyright (c) 2022 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n\n! This file was ported from Lean 3 source module measure_theory.group.integration\n! leanprover-community/mathlib commit ec247d43814751ffceb33b758e8820df2372bf6f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Integral.Bochner\nimport Mathbin.MeasureTheory.Group.Measure\nimport Mathbin.MeasureTheory.Group.Action\n\n/-!\n# Integration on Groups\n\nWe develop properties of integrals with a group as domain.\nThis file contains properties about integrability, Lebesgue integration and Bochner integration.\n-/\n\n\nnamespace MeasureTheory\n\nopen Measure TopologicalSpace\n\nopen ENNReal\n\nvariable {\ud835\udd5c M \u03b1 G E F : Type _} [MeasurableSpace G]\n\nvariable [NormedAddCommGroup E] [NormedSpace \u211d E] [CompleteSpace E] [NormedAddCommGroup F]\n\nvariable {\u03bc : Measure G} {f : G \u2192 E} {g : G}\n\nsection MeasurableInv\n\nvariable [Group G] [HasMeasurableInv G]\n\n@[to_additive]\ntheorem Integrable.compInv [IsInvInvariant \u03bc] {f : G \u2192 F} (hf : Integrable f \u03bc) :\n    Integrable (fun t => f t\u207b\u00b9) \u03bc :=\n  (hf.monoMeasure (map_inv_eq_self \u03bc).le).compMeasurable measurable_inv\n#align measure_theory.integrable.comp_inv MeasureTheory.Integrable.compInv\n#align measure_theory.integrable.comp_neg MeasureTheory.Integrable.comp_neg\n\n@[to_additive]\ntheorem integral_inv_eq_self (f : G \u2192 E) (\u03bc : Measure G) [IsInvInvariant \u03bc] :\n    (\u222b x, f x\u207b\u00b9 \u2202\u03bc) = \u222b x, f x \u2202\u03bc :=\n  by\n  have h : MeasurableEmbedding fun x : G => x\u207b\u00b9 := (MeasurableEquiv.inv G).MeasurableEmbedding\n  rw [\u2190 h.integral_map, map_inv_eq_self]\n#align measure_theory.integral_inv_eq_self MeasureTheory.integral_inv_eq_self\n#align measure_theory.integral_neg_eq_self MeasureTheory.integral_neg_eq_self\n\nend MeasurableInv\n\nsection MeasurableMul\n\nvariable [Group G] [HasMeasurableMul G]\n\n/-- Translating a function by left-multiplication does not change its `measure_theory.lintegral`\nwith respect to a left-invariant measure. -/\n@[to_additive\n      \"Translating a function by left-addition does not change its\\n`measure_theory.lintegral` with respect to a left-invariant measure.\"]\ntheorem lintegral_mul_left_eq_self [IsMulLeftInvariant \u03bc] (f : G \u2192 \u211d\u22650\u221e) (g : G) :\n    (\u222b\u207b x, f (g * x) \u2202\u03bc) = \u222b\u207b x, f x \u2202\u03bc :=\n  by\n  convert(lintegral_map_equiv f <| MeasurableEquiv.mulLeft g).symm\n  simp [map_mul_left_eq_self \u03bc g]\n#align measure_theory.lintegral_mul_left_eq_self MeasureTheory.lintegral_mul_left_eq_self\n#align measure_theory.lintegral_add_left_eq_self MeasureTheory.lintegral_add_left_eq_self\n\n/-- Translating a function by right-multiplication does not change its `measure_theory.lintegral`\nwith respect to a right-invariant measure. -/\n@[to_additive\n      \"Translating a function by right-addition does not change its\\n`measure_theory.lintegral` with respect to a right-invariant measure.\"]\ntheorem lintegral_mul_right_eq_self [IsMulRightInvariant \u03bc] (f : G \u2192 \u211d\u22650\u221e) (g : G) :\n    (\u222b\u207b x, f (x * g) \u2202\u03bc) = \u222b\u207b x, f x \u2202\u03bc :=\n  by\n  convert(lintegral_map_equiv f <| MeasurableEquiv.mulRight g).symm\n  simp [map_mul_right_eq_self \u03bc g]\n#align measure_theory.lintegral_mul_right_eq_self MeasureTheory.lintegral_mul_right_eq_self\n#align measure_theory.lintegral_add_right_eq_self MeasureTheory.lintegral_add_right_eq_self\n\n@[simp, to_additive]\ntheorem lintegral_div_right_eq_self [IsMulRightInvariant \u03bc] (f : G \u2192 \u211d\u22650\u221e) (g : G) :\n    (\u222b\u207b x, f (x / g) \u2202\u03bc) = \u222b\u207b x, f x \u2202\u03bc := by\n  simp_rw [div_eq_mul_inv, lintegral_mul_right_eq_self f g\u207b\u00b9]\n#align measure_theory.lintegral_div_right_eq_self MeasureTheory.lintegral_div_right_eq_self\n#align measure_theory.lintegral_sub_right_eq_self MeasureTheory.lintegral_sub_right_eq_self\n\n/-- Translating a function by left-multiplication does not change its integral with respect to a\nleft-invariant measure. -/\n@[simp,\n  to_additive\n      \"Translating a function by left-addition does not change its integral with\\n  respect to a left-invariant measure.\"]\ntheorem integral_mul_left_eq_self [IsMulLeftInvariant \u03bc] (f : G \u2192 E) (g : G) :\n    (\u222b x, f (g * x) \u2202\u03bc) = \u222b x, f x \u2202\u03bc :=\n  by\n  have h_mul : MeasurableEmbedding fun x => g * x := (MeasurableEquiv.mulLeft g).MeasurableEmbedding\n  rw [\u2190 h_mul.integral_map, map_mul_left_eq_self]\n#align measure_theory.integral_mul_left_eq_self MeasureTheory.integral_mul_left_eq_self\n#align measure_theory.integral_add_left_eq_self MeasureTheory.integral_add_left_eq_self\n\n/-- Translating a function by right-multiplication does not change its integral with respect to a\nright-invariant measure. -/\n@[simp,\n  to_additive\n      \"Translating a function by right-addition does not change its integral with\\n  respect to a right-invariant measure.\"]\ntheorem integral_mul_right_eq_self [IsMulRightInvariant \u03bc] (f : G \u2192 E) (g : G) :\n    (\u222b x, f (x * g) \u2202\u03bc) = \u222b x, f x \u2202\u03bc :=\n  by\n  have h_mul : MeasurableEmbedding fun x => x * g :=\n    (MeasurableEquiv.mulRight g).MeasurableEmbedding\n  rw [\u2190 h_mul.integral_map, map_mul_right_eq_self]\n#align measure_theory.integral_mul_right_eq_self MeasureTheory.integral_mul_right_eq_self\n#align measure_theory.integral_add_right_eq_self MeasureTheory.integral_add_right_eq_self\n\n@[simp, to_additive]\ntheorem integral_div_right_eq_self [IsMulRightInvariant \u03bc] (f : G \u2192 E) (g : G) :\n    (\u222b x, f (x / g) \u2202\u03bc) = \u222b x, f x \u2202\u03bc := by\n  simp_rw [div_eq_mul_inv, integral_mul_right_eq_self f g\u207b\u00b9]\n#align measure_theory.integral_div_right_eq_self MeasureTheory.integral_div_right_eq_self\n#align measure_theory.integral_sub_right_eq_self MeasureTheory.integral_sub_right_eq_self\n\n/-- If some left-translate of a function negates it, then the integral of the function with respect\nto a left-invariant measure is 0. -/\n@[to_additive\n      \"If some left-translate of a function negates it, then the integral of the function\\nwith respect to a left-invariant measure is 0.\"]\ntheorem integral_eq_zero_of_mul_left_eq_neg [IsMulLeftInvariant \u03bc] (hf' : \u2200 x, f (g * x) = -f x) :\n    (\u222b x, f x \u2202\u03bc) = 0 := by\n  simp_rw [\u2190 self_eq_neg \u211d E, \u2190 integral_neg, \u2190 hf', integral_mul_left_eq_self]\n#align measure_theory.integral_eq_zero_of_mul_left_eq_neg MeasureTheory.integral_eq_zero_of_mul_left_eq_neg\n#align measure_theory.integral_eq_zero_of_add_left_eq_neg MeasureTheory.integral_eq_zero_of_add_left_eq_neg\n\n/-- If some right-translate of a function negates it, then the integral of the function with respect\nto a right-invariant measure is 0. -/\n@[to_additive\n      \"If some right-translate of a function negates it, then the integral of the function\\nwith respect to a right-invariant measure is 0.\"]\ntheorem integral_eq_zero_of_mul_right_eq_neg [IsMulRightInvariant \u03bc] (hf' : \u2200 x, f (x * g) = -f x) :\n    (\u222b x, f x \u2202\u03bc) = 0 := by\n  simp_rw [\u2190 self_eq_neg \u211d E, \u2190 integral_neg, \u2190 hf', integral_mul_right_eq_self]\n#align measure_theory.integral_eq_zero_of_mul_right_eq_neg MeasureTheory.integral_eq_zero_of_mul_right_eq_neg\n#align measure_theory.integral_eq_zero_of_add_right_eq_neg MeasureTheory.integral_eq_zero_of_add_right_eq_neg\n\n@[to_additive]\ntheorem Integrable.compMulLeft {f : G \u2192 F} [IsMulLeftInvariant \u03bc] (hf : Integrable f \u03bc) (g : G) :\n    Integrable (fun t => f (g * t)) \u03bc :=\n  (hf.monoMeasure (map_mul_left_eq_self \u03bc g).le).compMeasurable <| measurable_const_mul g\n#align measure_theory.integrable.comp_mul_left MeasureTheory.Integrable.compMulLeft\n#align measure_theory.integrable.comp_add_left MeasureTheory.Integrable.comp_add_left\n\n@[to_additive]\ntheorem Integrable.compMulRight {f : G \u2192 F} [IsMulRightInvariant \u03bc] (hf : Integrable f \u03bc) (g : G) :\n    Integrable (fun t => f (t * g)) \u03bc :=\n  (hf.monoMeasure (map_mul_right_eq_self \u03bc g).le).compMeasurable <| measurable_mul_const g\n#align measure_theory.integrable.comp_mul_right MeasureTheory.Integrable.compMulRight\n#align measure_theory.integrable.comp_add_right MeasureTheory.Integrable.comp_add_right\n\n@[to_additive]\ntheorem Integrable.compDivRight {f : G \u2192 F} [IsMulRightInvariant \u03bc] (hf : Integrable f \u03bc) (g : G) :\n    Integrable (fun t => f (t / g)) \u03bc :=\n  by\n  simp_rw [div_eq_mul_inv]\n  exact hf.comp_mul_right g\u207b\u00b9\n#align measure_theory.integrable.comp_div_right MeasureTheory.Integrable.compDivRight\n#align measure_theory.integrable.comp_sub_right MeasureTheory.Integrable.comp_sub_right\n\nvariable [HasMeasurableInv G]\n\n@[to_additive]\ntheorem Integrable.compDivLeft {f : G \u2192 F} [IsInvInvariant \u03bc] [IsMulLeftInvariant \u03bc]\n    (hf : Integrable f \u03bc) (g : G) : Integrable (fun t => f (g / t)) \u03bc :=\n  ((measurePreservingDivLeft \u03bc g).integrable_comp hf.AeStronglyMeasurable).mpr hf\n#align measure_theory.integrable.comp_div_left MeasureTheory.Integrable.compDivLeft\n#align measure_theory.integrable.comp_sub_left MeasureTheory.Integrable.comp_sub_left\n\n@[simp, to_additive]\ntheorem integrable_comp_div_left (f : G \u2192 F) [IsInvInvariant \u03bc] [IsMulLeftInvariant \u03bc] (g : G) :\n    Integrable (fun t => f (g / t)) \u03bc \u2194 Integrable f \u03bc :=\n  by\n  refine' \u27e8fun h => _, fun h => h.compDivLeft g\u27e9\n  convert h.comp_inv.comp_mul_left g\u207b\u00b9\n  simp_rw [div_inv_eq_mul, mul_inv_cancel_left]\n#align measure_theory.integrable_comp_div_left MeasureTheory.integrable_comp_div_left\n#align measure_theory.integrable_comp_sub_left MeasureTheory.integrable_comp_sub_left\n\n@[simp, to_additive]\ntheorem integral_div_left_eq_self (f : G \u2192 E) (\u03bc : Measure G) [IsInvInvariant \u03bc]\n    [IsMulLeftInvariant \u03bc] (x' : G) : (\u222b x, f (x' / x) \u2202\u03bc) = \u222b x, f x \u2202\u03bc := by\n  simp_rw [div_eq_mul_inv, integral_inv_eq_self (fun x => f (x' * x)) \u03bc,\n    integral_mul_left_eq_self f x']\n#align measure_theory.integral_div_left_eq_self MeasureTheory.integral_div_left_eq_self\n#align measure_theory.integral_sub_left_eq_self MeasureTheory.integral_sub_left_eq_self\n\nend MeasurableMul\n\nsection Smul\n\nvariable [Group G] [MeasurableSpace \u03b1] [MulAction G \u03b1] [HasMeasurableSmul G \u03b1]\n\n@[simp, to_additive]\ntheorem integral_smul_eq_self {\u03bc : Measure \u03b1} [SmulInvariantMeasure G \u03b1 \u03bc] (f : \u03b1 \u2192 E) {g : G} :\n    (\u222b x, f (g \u2022 x) \u2202\u03bc) = \u222b x, f x \u2202\u03bc :=\n  by\n  have h : MeasurableEmbedding fun x : \u03b1 => g \u2022 x := (MeasurableEquiv.smul g).MeasurableEmbedding\n  rw [\u2190 h.integral_map, map_smul]\n#align measure_theory.integral_smul_eq_self MeasureTheory.integral_smul_eq_self\n#align measure_theory.integral_vadd_eq_self MeasureTheory.integral_vadd_eq_self\n\nend Smul\n\nsection TopologicalGroup\n\nvariable [TopologicalSpace G] [Group G] [TopologicalGroup G] [BorelSpace G] [IsMulLeftInvariant \u03bc]\n\n/-- For nonzero regular left invariant measures, the integral of a continuous nonnegative function\n  `f` is 0 iff `f` is 0. -/\n@[to_additive\n      \"For nonzero regular left invariant measures, the integral of a continuous nonnegative\\nfunction `f` is 0 iff `f` is 0.\"]\ntheorem lintegral_eq_zero_of_isMulLeftInvariant [Regular \u03bc] (h\u03bc : \u03bc \u2260 0) {f : G \u2192 \u211d\u22650\u221e}\n    (hf : Continuous f) : (\u222b\u207b x, f x \u2202\u03bc) = 0 \u2194 f = 0 :=\n  by\n  haveI := is_open_pos_measure_of_mul_left_invariant_of_regular h\u03bc\n  rw [lintegral_eq_zero_iff hf.measurable, hf.ae_eq_iff_eq \u03bc continuous_zero]\n#align measure_theory.lintegral_eq_zero_of_is_mul_left_invariant MeasureTheory.lintegral_eq_zero_of_isMulLeftInvariant\n#align measure_theory.lintegral_eq_zero_of_is_add_left_invariant MeasureTheory.lintegral_eq_zero_of_is_add_left_invariant\n\nend TopologicalGroup\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Group/Integration.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7257967845867578}}
{"text": "/-\nCopyright (c) 2021 Stuart Presnell. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Stuart Presnell\n-/\nimport algebra.big_operators.finsupp\nimport data.finsupp.multiset\nimport data.nat.prime_fin\nimport number_theory.padics.padic_val\nimport data.nat.interval\nimport tactic.interval_cases\n\n/-!\n# Prime factorizations\n\n `n.factorization` is the finitely supported function `\u2115 \u2192\u2080 \u2115`\n mapping each prime factor of `n` to its multiplicity in `n`.  For example, since 2000 = 2^4 * 5^3,\n  * `factorization 2000 2` is 4\n  * `factorization 2000 5` is 3\n  * `factorization 2000 k` is 0 for all other `k : \u2115`.\n\n## TODO\n\n* As discussed in this Zulip thread:\nhttps://leanprover.zulipchat.com/#narrow/stream/217875/topic/Multiplicity.20in.20the.20naturals\nWe have lots of disparate ways of talking about the multiplicity of a prime\nin a natural number, including `factors.count`, `padic_val_nat`, `multiplicity`,\nand the material in `data/pnat/factors`.  Move some of this material to this file,\nprove results about the relationships between these definitions,\nand (where appropriate) choose a uniform canonical way of expressing these ideas.\n\n* Moreover, the results here should be generalised to an arbitrary unique factorization monoid\nwith a normalization function, and then deduplicated.  The basics of this have been started in\n`ring_theory/unique_factorization_domain`.\n\n* Extend the inductions to any `normalization_monoid` with unique factorization.\n\n-/\n\nopen nat finset list finsupp\nopen_locale big_operators\n\nnamespace nat\n\n/-- `n.factorization` is the finitely supported function `\u2115 \u2192\u2080 \u2115`\n mapping each prime factor of `n` to its multiplicity in `n`. -/\ndef factorization (n : \u2115) : \u2115 \u2192\u2080 \u2115 :=\n{ support := n.factors.to_finset,\n  to_fun := \u03bb p, if p.prime then padic_val_nat p n else 0,\n  mem_support_to_fun :=\n      begin\n        rcases eq_or_ne n 0 with rfl | hn0, { simp },\n        simp only [mem_factors hn0, mem_to_finset, ne.def, ite_eq_right_iff, not_forall,\n          exists_prop, and.congr_right_iff],\n        rintro p hp,\n        haveI := fact_iff.mpr hp,\n        exact dvd_iff_padic_val_nat_ne_zero hn0,\n      end }\n\nlemma factorization_def (n : \u2115) {p : \u2115} (pp : p.prime) : n.factorization p = padic_val_nat p n :=\nby simpa [factorization] using absurd pp\n\n/-- We can write both `n.factorization p` and `n.factors.count p` to represent the power\nof `p` in the factorization of `n`: we declare the former to be the simp-normal form. -/\n@[simp] lemma factors_count_eq {n p : \u2115} : n.factors.count p = n.factorization p :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn0, { simp [factorization] },\n  by_cases pp : p.prime, swap,\n  { rw count_eq_zero_of_not_mem (mt prime_of_mem_factors pp), simp [factorization, pp] },\n  simp only [factorization, coe_mk, pp, if_true],\n  rw [\u2190part_enat.coe_inj, padic_val_nat_def' pp.ne_one hn0,\n    unique_factorization_monoid.multiplicity_eq_count_normalized_factors pp hn0.ne'],\n  simp [factors_eq],\nend\n\nlemma factorization_eq_factors_multiset (n : \u2115) :\n  n.factorization = (n.factors : multiset \u2115).to_finsupp :=\nby { ext p, simp }\n\nlemma multiplicity_eq_factorization {n p : \u2115} (pp : p.prime) (hn : n \u2260 0) :\n  multiplicity p n = n.factorization p :=\nby simp [factorization, pp, (padic_val_nat_def' pp.ne_one hn.bot_lt)]\n\n/-! ### Basic facts about factorization -/\n\n@[simp] lemma factorization_prod_pow_eq_self {n : \u2115} (hn : n \u2260 0) : n.factorization.prod pow = n :=\nbegin\n  rw factorization_eq_factors_multiset n,\n  simp only [\u2190prod_to_multiset, factorization, multiset.coe_prod, multiset.to_finsupp_to_multiset],\n  exact prod_factors hn,\nend\n\nlemma eq_of_factorization_eq {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0)\n  (h : \u2200 p : \u2115, a.factorization p = b.factorization p) : a = b :=\neq_of_perm_factors ha hb (by simpa only [list.perm_iff_count, factors_count_eq] using h)\n\n/-- Every nonzero natural number has a unique prime factorization -/\nlemma factorization_inj : set.inj_on factorization { x : \u2115 | x \u2260 0 } :=\n\u03bb a ha b hb h, eq_of_factorization_eq ha hb (\u03bb p, by simp [h])\n\n@[simp] lemma factorization_zero : factorization 0 = 0 :=\nby simpa [factorization]\n\n@[simp] lemma factorization_one : factorization 1 = 0 :=\nby simpa [factorization]\n\n/-- The support of `n.factorization` is exactly `n.factors.to_finset` -/\n@[simp] lemma support_factorization {n : \u2115} : n.factorization.support = n.factors.to_finset :=\nby simp [factorization]\n\nlemma factor_iff_mem_factorization {n p : \u2115} : p \u2208 n.factorization.support \u2194 p \u2208 n.factors :=\nby simp only [support_factorization, list.mem_to_finset]\n\nlemma prime_of_mem_factorization {n p : \u2115} (hp : p \u2208 n.factorization.support) : p.prime :=\nprime_of_mem_factors (factor_iff_mem_factorization.mp hp)\n\nlemma pos_of_mem_factorization {n p : \u2115} (hp : p \u2208 n.factorization.support) : 0 < p :=\nprime.pos (prime_of_mem_factorization hp)\n\nlemma le_of_mem_factorization {n p : \u2115} (h : p \u2208 n.factorization.support) : p \u2264 n :=\nle_of_mem_factors (factor_iff_mem_factorization.mp h)\n\n/-! ## Lemmas characterising when `n.factorization p = 0` -/\n\nlemma factorization_eq_zero_iff (n p : \u2115) :\n  n.factorization p = 0 \u2194 \u00acp.prime \u2228 \u00acp \u2223 n \u2228 n = 0 :=\nbegin\n  rw [\u2190not_mem_support_iff, support_factorization, mem_to_finset],\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  { simp [hn, nat.mem_factors, not_and_distrib] },\nend\n\n@[simp]\nlemma factorization_eq_zero_of_non_prime (n : \u2115) {p : \u2115} (hp : \u00acp.prime) : n.factorization p = 0 :=\nby simp [factorization_eq_zero_iff, hp]\n\nlemma factorization_eq_zero_of_not_dvd {n p : \u2115} (h : \u00ac p \u2223 n) : n.factorization p = 0 :=\nby simp [factorization_eq_zero_iff, h]\n\nlemma factorization_eq_zero_of_lt {n p : \u2115} (h : n < p) : n.factorization p = 0 :=\nfinsupp.not_mem_support_iff.mp (mt le_of_mem_factorization (not_le_of_lt h))\n\n@[simp] lemma factorization_zero_right (n : \u2115) : n.factorization 0 = 0 :=\nfactorization_eq_zero_of_non_prime _ not_prime_zero\n\n@[simp] lemma factorization_one_right (n : \u2115) : n.factorization 1 = 0 :=\nfactorization_eq_zero_of_non_prime _ not_prime_one\n\nlemma dvd_of_factorization_pos {n p : \u2115} (hn : n.factorization p \u2260 0) : p \u2223 n :=\ndvd_of_mem_factors (factor_iff_mem_factorization.1 (mem_support_iff.2 hn))\n\nlemma prime.factorization_pos_of_dvd {n p : \u2115} (hp : p.prime) (hn : n \u2260 0) (h : p \u2223 n) :\n  0 < n.factorization p :=\nby rwa [\u2190factors_count_eq, count_pos, mem_factors_iff_dvd hn hp]\n\nlemma factorization_eq_zero_of_remainder {p r : \u2115} (i : \u2115) (hr : \u00ac p \u2223 r) :\n  (p * i + r).factorization p = 0 :=\nby { apply factorization_eq_zero_of_not_dvd, rwa \u2190nat.dvd_add_iff_right (dvd.intro i rfl) }\n\nlemma factorization_eq_zero_iff_remainder {p r : \u2115} (i : \u2115) (pp : p.prime) (hr0 : r \u2260 0) :\n  (\u00ac p \u2223 r) \u2194 (p * i + r).factorization p = 0 :=\nbegin\n  refine \u27e8factorization_eq_zero_of_remainder i, \u03bb h, _\u27e9,\n  rw factorization_eq_zero_iff at h,\n  contrapose! h,\n  refine \u27e8pp, _, _\u27e9,\n  { rwa \u2190nat.dvd_add_iff_right ((dvd.intro i rfl)) },\n  { contrapose! hr0, exact (_root_.add_eq_zero_iff.mp hr0).2 },\nend\n\n/-- The only numbers with empty prime factorization are `0` and `1` -/\nlemma factorization_eq_zero_iff' (n : \u2115) : n.factorization = 0 \u2194 n = 0 \u2228 n = 1 :=\nbegin\n  rw factorization_eq_factors_multiset n,\n  simp [factorization, add_equiv.map_eq_zero_iff, multiset.coe_eq_zero],\nend\n\n/-! ## Lemmas about factorizations of products and powers -/\n\n/-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\n@[simp] lemma factorization_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a * b).factorization = a.factorization + b.factorization :=\nby { ext p, simp only [add_apply, \u2190factors_count_eq,\n                       perm_iff_count.mp (perm_factors_mul ha hb) p, count_append] }\n\nlemma factorization_mul_support {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a * b).factorization.support = a.factorization.support \u222a b.factorization.support :=\nbegin\n  ext q,\n  simp only [finset.mem_union, factor_iff_mem_factorization],\n  exact mem_factors_mul ha hb\nend\n\n/-- If a product over `n.factorization` doesn't use the multiplicities of the prime factors\nthen it's equal to the corresponding product over `n.factors.to_finset` -/\nlemma prod_factorization_eq_prod_factors {n : \u2115} {\u03b2 : Type*} [comm_monoid \u03b2] (f : \u2115 \u2192 \u03b2) :\n  n.factorization.prod (\u03bb p k, f p) = \u220f p in n.factors.to_finset, (f p) :=\nby { apply prod_congr support_factorization, simp }\n\n/-- For any `p : \u2115` and any function `g : \u03b1 \u2192 \u2115` that's non-zero on `S : finset \u03b1`,\nthe power of `p` in `S.prod g` equals the sum over `x \u2208 S` of the powers of `p` in `g x`.\nGeneralises `factorization_mul`, which is the special case where `S.card = 2` and `g = id`. -/\nlemma factorization_prod {\u03b1 : Type*} {S : finset \u03b1} {g : \u03b1 \u2192 \u2115} (hS : \u2200 x \u2208 S, g x \u2260 0) :\n  (S.prod g).factorization = S.sum (\u03bb x, (g x).factorization) :=\nbegin\n  classical,\n  ext p,\n  apply finset.induction_on' S, { simp },\n  { intros x T hxS hTS hxT IH,\n    have hT : T.prod g \u2260 0 := prod_ne_zero_iff.mpr (\u03bb x hx, hS x (hTS hx)),\n    simp [prod_insert hxT, sum_insert hxT, \u2190IH, factorization_mul (hS x hxS) hT] }\nend\n\n/-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/\n@[simp] lemma factorization_pow (n k : \u2115) :\n  factorization (n^k) = k \u2022 n.factorization :=\nbegin\n  induction k with k ih, { simp },\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  rw [pow_succ, factorization_mul hn (pow_ne_zero _ hn), ih, succ_eq_one_add, add_smul, one_smul],\nend\n\n/-! ## Lemmas about factorizations of primes and prime powers -/\n\n/-- The only prime factor of prime `p` is `p` itself, with multiplicity `1` -/\n@[simp] lemma prime.factorization {p : \u2115} (hp : prime p) :\n  p.factorization = single p 1 :=\nbegin\n  ext q,\n  rw [\u2190factors_count_eq, factors_prime hp, single_apply, count_singleton', if_congr eq_comm];\n  refl,\nend\n\n/-- The multiplicity of prime `p` in `p` is `1` -/\n@[simp] lemma prime.factorization_self {p : \u2115} (hp : prime p) : p.factorization p = 1 :=\nby simp [hp]\n\n/-- For prime `p` the only prime factor of `p^k` is `p` with multiplicity `k` -/\nlemma prime.factorization_pow {p k : \u2115} (hp : prime p) :\n  factorization (p ^ k) = single p k :=\nby simp [hp]\n\n/-- If the factorization of `n` contains just one number `p` then `n` is a power of `p` -/\nlemma eq_pow_of_factorization_eq_single {n p k : \u2115} (hn : n \u2260 0)\n  (h : n.factorization = finsupp.single p k) : n = p ^ k :=\nby { rw [\u2190nat.factorization_prod_pow_eq_self hn, h], simp }\n\n/-- The only prime factor of prime `p` is `p` itself. -/\nlemma prime.eq_of_factorization_pos {p q : \u2115} (hp : prime p) (h : p.factorization q \u2260 0) :\n  p = q :=\nby simpa [hp.factorization, single_apply] using h\n\n/-! ### Equivalence between `\u2115+` and `\u2115 \u2192\u2080 \u2115` with support in the primes. -/\n\n/-- Any finsupp `f : \u2115 \u2192\u2080 \u2115` whose support is in the primes is equal to the factorization of\nthe product `\u220f (a : \u2115) in f.support, a ^ f a`. -/\nlemma prod_pow_factorization_eq_self {f : \u2115 \u2192\u2080 \u2115} (hf : \u2200 (p : \u2115), p \u2208 f.support \u2192 prime p) :\n  (f.prod pow).factorization = f :=\nbegin\n  have h : \u2200 x : \u2115, x \u2208 f.support \u2192 x ^ f x \u2260 0 := \u03bb p hp, pow_ne_zero _ (prime.ne_zero (hf p hp)),\n  simp only [finsupp.prod, factorization_prod h],\n  nth_rewrite_rhs 0 (sum_single f).symm,\n  exact sum_congr rfl (\u03bb p hp, prime.factorization_pow (hf p hp)),\nend\n\nlemma eq_factorization_iff {n : \u2115} {f : \u2115 \u2192\u2080 \u2115} (hn : n \u2260 0) (hf : \u2200 p \u2208 f.support, prime p) :\n  f = n.factorization \u2194 f.prod pow = n :=\n\u27e8\u03bb h, by rw [h, factorization_prod_pow_eq_self hn],\n \u03bb h, by rw [\u2190h, prod_pow_factorization_eq_self hf]\u27e9\n\n/-- The equiv between `\u2115+` and `\u2115 \u2192\u2080 \u2115` with support in the primes. -/\ndef factorization_equiv : \u2115+ \u2243 {f : \u2115 \u2192\u2080 \u2115 | \u2200 p \u2208 f.support, prime p} :=\n{ to_fun    := \u03bb \u27e8n, hn\u27e9, \u27e8n.factorization, \u03bb _, prime_of_mem_factorization\u27e9,\n  inv_fun   := \u03bb \u27e8f, hf\u27e9, \u27e8f.prod pow,\n    prod_pow_pos_of_zero_not_mem_support (\u03bb H, not_prime_zero (hf 0 H))\u27e9,\n  left_inv  := \u03bb \u27e8x, hx\u27e9, subtype.ext $ factorization_prod_pow_eq_self hx.ne.symm,\n  right_inv := \u03bb \u27e8f, hf\u27e9, subtype.ext $ prod_pow_factorization_eq_self hf }\n\nlemma factorization_equiv_apply (n : \u2115+) : (factorization_equiv n).1 = n.1.factorization :=\nby { cases n, refl }\n\nlemma factorization_equiv_inv_apply {f : \u2115 \u2192\u2080 \u2115} (hf : \u2200 p \u2208 f.support, prime p) :\n  (factorization_equiv.symm \u27e8f, hf\u27e9).1 = f.prod pow := rfl\n\n/-! ### Generalisation of the \"even part\" and \"odd part\" of a natural number\n\nWe introduce the notations `ord_proj[p] n` for the largest power of the prime `p` that\ndivides `n` and `ord_compl[p] n` for the complementary part. The `ord` naming comes from\nthe $p$-adic order/valuation of a number, and `proj` and `compl` are for the projection and\ncomplementary projection. The term `n.factorization p` is the $p$-adic order itself.\nFor example, `ord_proj[2] n` is the even part of `n` and `ord_compl[2] n` is the odd part. -/\n\nnotation `ord_proj[` p `] ` n:max := p ^ (nat.factorization n p)\nnotation `ord_compl[` p `] ` n:max := n / ord_proj[p] n\n\n@[simp] lemma ord_proj_of_not_prime (n p : \u2115) (hp : \u00ac p.prime) : ord_proj[p] n = 1 :=\nby simp [factorization_eq_zero_of_non_prime n hp]\n\n@[simp] lemma ord_compl_of_not_prime (n p : \u2115) (hp : \u00ac p.prime) : ord_compl[p] n = n :=\nby simp [factorization_eq_zero_of_non_prime n hp]\n\nlemma ord_proj_dvd (n p : \u2115) : ord_proj[p] n \u2223 n :=\nbegin\n  by_cases hp : p.prime, swap, { simp [hp] },\n  rw \u2190factors_count_eq,\n  apply dvd_of_factors_subperm (pow_ne_zero _ hp.ne_zero),\n  rw [hp.factors_pow, list.subperm_ext_iff],\n  intros q hq,\n  simp [list.eq_of_mem_replicate hq],\nend\n\nlemma ord_compl_dvd (n p : \u2115) : ord_compl[p] n \u2223 n :=\ndiv_dvd_of_dvd (ord_proj_dvd n p)\n\nlemma ord_proj_pos (n p : \u2115) : 0 < ord_proj[p] n :=\nbegin\n  by_cases pp : p.prime,\n  { simp [pow_pos pp.pos] },\n  { simp [pp] },\nend\n\nlemma ord_proj_le {n : \u2115} (p : \u2115) (hn : n \u2260 0) : ord_proj[p] n \u2264 n :=\nle_of_dvd hn.bot_lt (nat.ord_proj_dvd n p)\n\nlemma ord_compl_pos {n : \u2115} (p : \u2115) (hn : n \u2260 0) : 0 < ord_compl[p] n :=\nbegin\n  cases em' p.prime with pp pp,\n  { simpa [nat.factorization_eq_zero_of_non_prime n pp] using hn.bot_lt },\n  exact nat.div_pos (ord_proj_le p hn) (ord_proj_pos n p),\nend\n\nlemma ord_compl_le (n p : \u2115) : ord_compl[p] n \u2264 n :=\nnat.div_le_self _ _\n\nlemma ord_proj_mul_ord_compl_eq_self (n p : \u2115) : ord_proj[p] n * ord_compl[p] n = n :=\nnat.mul_div_cancel' (ord_proj_dvd n p)\n\nlemma ord_proj_mul {a b : \u2115} (p : \u2115) (ha : a \u2260 0) (hb : b \u2260 0):\n  ord_proj[p] (a * b) = ord_proj[p] a * ord_proj[p] b :=\nby simp [factorization_mul ha hb, pow_add]\n\nlemma ord_compl_mul (a b p : \u2115) :\n  ord_compl[p] (a * b) = ord_compl[p] a * ord_compl[p] b :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha, { simp },\n  rcases eq_or_ne b 0 with rfl | hb, { simp },\n  simp only [ord_proj_mul p ha hb],\n  rw (mul_div_mul_comm_of_dvd_dvd (ord_proj_dvd a p) (ord_proj_dvd b p)),\nend\n\n/-! ### Factorization and divisibility -/\n\nlemma dvd_of_mem_factorization {n p : \u2115} (h : p \u2208 n.factorization.support) : p \u2223 n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  simp [\u2190mem_factors_iff_dvd hn (prime_of_mem_factorization h), factor_iff_mem_factorization.mp h],\nend\n\n/-- A crude upper bound on `n.factorization p` -/\nlemma factorization_lt {n : \u2115} (p : \u2115) (hn : n \u2260 0) : n.factorization p < n :=\nbegin\n  by_cases pp : p.prime, swap, { simp [factorization_eq_zero_of_non_prime n pp], exact hn.bot_lt },\n  rw \u2190pow_lt_iff_lt_right pp.two_le,\n  apply lt_of_le_of_lt (ord_proj_le p hn),\n  exact lt_of_lt_of_le (lt_two_pow n) (pow_le_pow_of_le_left (by linarith) pp.two_le n),\nend\n\n/-- An upper bound on `n.factorization p` -/\nlemma factorization_le_of_le_pow {n p b : \u2115} (hb : n \u2264 p ^ b) : n.factorization p \u2264 b :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  by_cases pp : p.prime,\n  { exact (pow_le_iff_le_right pp.two_le).1 (le_trans (ord_proj_le p hn) hb) },\n  { simp [factorization_eq_zero_of_non_prime n pp] }\nend\n\nlemma factorization_le_iff_dvd {d n : \u2115} (hd : d \u2260 0) (hn : n \u2260 0) :\n  d.factorization \u2264 n.factorization \u2194 d \u2223 n :=\nbegin\n  split,\n  { intro hdn,\n    set K := n.factorization - d.factorization with hK,\n    use K.prod pow,\n    rw [\u2190factorization_prod_pow_eq_self hn, \u2190factorization_prod_pow_eq_self hd,\n        \u2190finsupp.prod_add_index' pow_zero pow_add, hK, add_tsub_cancel_of_le hdn] },\n  { rintro \u27e8c, rfl\u27e9, rw factorization_mul hd (right_ne_zero_of_mul hn), simp },\nend\n\nlemma factorization_prime_le_iff_dvd {d n : \u2115} (hd : d \u2260 0) (hn : n \u2260 0) :\n  (\u2200 p : \u2115, p.prime \u2192 d.factorization p \u2264 n.factorization p) \u2194 d \u2223 n :=\nbegin\n  rw \u2190 factorization_le_iff_dvd hd hn,\n  refine \u27e8\u03bb h p, (em p.prime).elim (h p) (\u03bb hp, _), \u03bb h p _, h p\u27e9,\n  simp_rw factorization_eq_zero_of_non_prime _ hp,\nend\n\nlemma pow_succ_factorization_not_dvd {n p : \u2115} (hn : n \u2260 0) (hp : p.prime) :\n  \u00ac p ^ (n.factorization p + 1) \u2223 n :=\nbegin\n  intro h,\n  rw \u2190factorization_le_iff_dvd (pow_pos hp.pos _).ne' hn at h,\n  simpa [hp.factorization] using h p,\nend\n\nlemma factorization_le_factorization_mul_left {a b : \u2115} (hb : b \u2260 0) :\n  a.factorization \u2264 (a * b).factorization :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha, { simp },\n  rw [factorization_le_iff_dvd ha $ mul_ne_zero ha hb],\n  exact dvd.intro b rfl\nend\n\nlemma factorization_le_factorization_mul_right {a b : \u2115} (ha : a \u2260 0) :\n  b.factorization \u2264 (a * b).factorization :=\nby { rw mul_comm, apply factorization_le_factorization_mul_left ha }\n\nlemma prime.pow_dvd_iff_le_factorization {p k n : \u2115} (pp : prime p) (hn : n \u2260 0) :\n  p ^ k \u2223 n \u2194 k \u2264 n.factorization p :=\nby rw [\u2190factorization_le_iff_dvd (pow_pos pp.pos k).ne' hn, pp.factorization_pow, single_le_iff]\n\nlemma prime.pow_dvd_iff_dvd_ord_proj {p k n : \u2115} (pp : prime p) (hn : n \u2260 0) :\n  p ^ k \u2223 n \u2194 p ^ k \u2223 ord_proj[p] n :=\nby rw [pow_dvd_pow_iff_le_right pp.one_lt, pp.pow_dvd_iff_le_factorization hn]\n\n\n\nlemma exists_factorization_lt_of_lt {a b : \u2115} (ha : a \u2260 0) (hab : a < b) :\n  \u2203 p : \u2115, a.factorization p < b.factorization p :=\nbegin\n  have hb : b \u2260 0 := (ha.bot_lt.trans hab).ne',\n  contrapose! hab,\n  rw [\u2190finsupp.le_def, factorization_le_iff_dvd hb ha] at hab,\n  exact le_of_dvd ha.bot_lt hab,\nend\n\n@[simp] lemma factorization_div {d n : \u2115} (h : d \u2223 n) :\n  (n / d).factorization = n.factorization - d.factorization :=\nbegin\n  rcases eq_or_ne d 0 with rfl | hd, { simp [zero_dvd_iff.mp h] },\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  apply add_left_injective d.factorization,\n  simp only,\n  rw [tsub_add_cancel_of_le $ (nat.factorization_le_iff_dvd hd hn).mpr h,\n      \u2190nat.factorization_mul (nat.div_pos (nat.le_of_dvd hn.bot_lt h) hd.bot_lt).ne' hd,\n      nat.div_mul_cancel h],\nend\n\nlemma dvd_ord_proj_of_dvd {n p : \u2115} (hn : n \u2260 0) (pp : p.prime) (h : p \u2223 n) :\n  p \u2223 ord_proj[p] n :=\ndvd_pow_self p (prime.factorization_pos_of_dvd pp hn h).ne'\n\nlemma not_dvd_ord_compl {n p : \u2115} (hp : prime p) (hn : n \u2260 0) :\n  \u00acp \u2223 ord_compl[p] n :=\nbegin\n  rw [nat.prime.dvd_iff_one_le_factorization hp (ord_compl_pos p hn).ne'],\n  rw [nat.factorization_div (nat.ord_proj_dvd n p)],\n  simp [hp.factorization],\nend\n\nlemma coprime_ord_compl {n p : \u2115} (hp : prime p) (hn : n \u2260 0) :\n  coprime p (ord_compl[p] n) :=\n(or_iff_left (not_dvd_ord_compl hp hn)).mp $ coprime_or_dvd_of_prime hp _\n\nlemma factorization_ord_compl (n p : \u2115) :\n  (ord_compl[p] n).factorization = n.factorization.erase p :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  by_cases pp : p.prime, swap, { simp [pp] },\n  ext q,\n  rcases eq_or_ne q p with rfl | hqp,\n  { simp only [finsupp.erase_same, factorization_eq_zero_iff, not_dvd_ord_compl pp hn],\n    simp },\n  { rw [finsupp.erase_ne hqp, factorization_div (ord_proj_dvd n p)],\n    simp [pp.factorization, hqp.symm] },\nend\n\n-- `ord_compl[p] n` is the largest divisor of `n` not divisible by `p`.\nlemma dvd_ord_compl_of_dvd_not_dvd {p d n : \u2115} (hdn : d \u2223 n) (hpd : \u00ac p \u2223 d) :\n  d \u2223 ord_compl[p] n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn0, { simp },\n  rcases eq_or_ne d 0 with rfl | hd0, { simp at hpd, cases hpd },\n  rw [\u2190(factorization_le_iff_dvd hd0 (ord_compl_pos p hn0).ne'), factorization_ord_compl],\n  intro q,\n  rcases eq_or_ne q p with rfl | hqp,\n  { simp [factorization_eq_zero_iff, hpd] },\n  { simp [hqp, (factorization_le_iff_dvd hd0 hn0).2 hdn q] },\nend\n\n/-- If `n` is a nonzero natural number and `p \u2260 1`, then there are natural numbers `e`\nand `n'` such that `n'` is not divisible by `p` and `n = p^e * n'`. -/\nlemma exists_eq_pow_mul_and_not_dvd {n : \u2115} (hn : n \u2260 0) (p : \u2115) (hp : p \u2260 1) :\n  \u2203 e n' : \u2115, \u00ac p \u2223 n' \u2227 n = p ^ e * n' :=\nlet \u27e8a', h\u2081, h\u2082\u27e9 := multiplicity.exists_eq_pow_mul_and_not_dvd\n                      (multiplicity.finite_nat_iff.mpr \u27e8hp, nat.pos_of_ne_zero hn\u27e9) in\n\u27e8_, a', h\u2082, h\u2081\u27e9\n\nlemma dvd_iff_div_factorization_eq_tsub {d n : \u2115} (hd : d \u2260 0) (hdn : d \u2264 n) :\n  d \u2223 n \u2194 (n / d).factorization = n.factorization - d.factorization :=\nbegin\n  refine \u27e8factorization_div, _\u27e9,\n  rcases eq_or_lt_of_le hdn with rfl | hd_lt_n, { simp },\n  have h1 : n / d \u2260 0 := \u03bb H, nat.lt_asymm hd_lt_n ((nat.div_eq_zero_iff hd.bot_lt).mp H),\n  intros h,\n  rw dvd_iff_le_div_mul n d,\n  by_contra h2,\n  cases (exists_factorization_lt_of_lt (mul_ne_zero h1 hd) (not_le.mp h2)) with p hp,\n  rwa [factorization_mul h1 hd, add_apply, \u2190lt_tsub_iff_right, h, tsub_apply,\n    lt_self_iff_false] at hp\nend\n\nlemma ord_proj_dvd_ord_proj_of_dvd {a b : \u2115} (hb0 : b \u2260 0) (hab : a \u2223 b) (p : \u2115) :\n  ord_proj[p] a \u2223 ord_proj[p] b :=\nbegin\n  rcases em' p.prime with pp | pp, { simp [pp] },\n  rcases eq_or_ne a 0 with rfl | ha0, { simp },\n  rw pow_dvd_pow_iff_le_right pp.one_lt,\n  exact (factorization_le_iff_dvd ha0 hb0).2 hab p,\nend\n\nlemma ord_proj_dvd_ord_proj_iff_dvd {a b : \u2115} (ha0 : a \u2260 0) (hb0 : b \u2260 0) :\n  (\u2200 p : \u2115, ord_proj[p] a \u2223 ord_proj[p] b) \u2194 (a \u2223 b) :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb hab p, ord_proj_dvd_ord_proj_of_dvd hb0 hab p\u27e9,\n  rw \u2190factorization_le_iff_dvd ha0 hb0,\n  intro q,\n  rcases le_or_lt q 1 with hq_le | hq1, { interval_cases q; simp },\n  exact (pow_dvd_pow_iff_le_right hq1).1 (h q),\nend\n\nlemma ord_compl_dvd_ord_compl_of_dvd {a b : \u2115} (hab : a \u2223 b) (p : \u2115) :\n  ord_compl[p] a \u2223 ord_compl[p] b :=\nbegin\n  rcases em' p.prime with pp | pp, { simp [pp, hab] },\n  rcases eq_or_ne b 0 with rfl | hb0, { simp },\n  rcases eq_or_ne a 0 with rfl | ha0, { cases hb0 (zero_dvd_iff.1 hab) },\n  have ha := (nat.div_pos (ord_proj_le p ha0) (ord_proj_pos a p)).ne',\n  have hb := (nat.div_pos (ord_proj_le p hb0) (ord_proj_pos b p)).ne',\n  rw [\u2190factorization_le_iff_dvd ha hb, factorization_ord_compl a p, factorization_ord_compl b p],\n  intro q,\n  rcases eq_or_ne q p with rfl | hqp, { simp },\n  simp_rw erase_ne hqp,\n  exact (factorization_le_iff_dvd ha0 hb0).2 hab q,\nend\n\nlemma ord_compl_dvd_ord_compl_iff_dvd (a b : \u2115) :\n  (\u2200 p : \u2115, ord_compl[p] a \u2223 ord_compl[p] b) \u2194 (a \u2223 b) :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb hab p, ord_compl_dvd_ord_compl_of_dvd hab p\u27e9,\n  rcases eq_or_ne b 0 with rfl | hb0, { simp },\n  by_cases pa : a.prime, swap, { simpa [pa] using h a },\n  by_cases pb : b.prime, swap, { simpa [pb] using h b },\n  rw prime_dvd_prime_iff_eq pa pb,\n  by_contradiction hab,\n  apply pa.ne_one,\n  rw [\u2190nat.dvd_one, \u2190nat.mul_dvd_mul_iff_left hb0.bot_lt, mul_one],\n  simpa [prime.factorization_self pb, prime.factorization pa, hab] using h b,\nend\n\nlemma dvd_iff_prime_pow_dvd_dvd (n d : \u2115) :\n  d \u2223 n \u2194 \u2200 p k : \u2115, prime p \u2192 p ^ k \u2223 d \u2192 p ^ k \u2223 n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  rcases eq_or_ne d 0 with rfl | hd,\n  { simp only [zero_dvd_iff, hn, false_iff, not_forall],\n    exact \u27e82, n, prime_two, dvd_zero _, mt (le_of_dvd hn.bot_lt) (lt_two_pow n).not_le\u27e9 },\n  refine \u27e8\u03bb h p k _ hpkd, dvd_trans hpkd h, _\u27e9,\n  rw [\u2190factorization_prime_le_iff_dvd hd hn],\n  intros h p pp,\n  simp_rw \u2190pp.pow_dvd_iff_le_factorization hn,\n  exact h p _ pp (ord_proj_dvd _ _)\nend\n\nlemma prod_prime_factors_dvd (n : \u2115) : (\u220f (p : \u2115) in n.factors.to_finset, p) \u2223 n :=\nbegin\n  by_cases hn : n = 0, { subst hn, simp },\n  simpa [prod_factors hn] using multiset.to_finset_prod_dvd_prod (n.factors : multiset \u2115),\nend\n\nlemma factorization_gcd {a b : \u2115} (ha_pos : a \u2260 0) (hb_pos : b \u2260 0) :\n  (gcd a b).factorization = a.factorization \u2293 b.factorization :=\nbegin\n  let dfac := a.factorization \u2293 b.factorization,\n  let d := dfac.prod pow,\n  have dfac_prime : \u2200 (p : \u2115), p \u2208 dfac.support \u2192 prime p,\n  { intros p hp,\n    have : p \u2208 a.factors \u2227 p \u2208 b.factors := by simpa using hp,\n    exact prime_of_mem_factors this.1 },\n  have h1 : d.factorization = dfac := prod_pow_factorization_eq_self dfac_prime,\n  have hd_pos : d \u2260 0 := (factorization_equiv.inv_fun \u27e8dfac, dfac_prime\u27e9).2.ne.symm,\n  suffices : d = (gcd a b), { rwa \u2190this },\n  apply gcd_greatest,\n  { rw [\u2190factorization_le_iff_dvd hd_pos ha_pos, h1], exact inf_le_left },\n  { rw [\u2190factorization_le_iff_dvd hd_pos hb_pos, h1], exact inf_le_right },\n  { intros e hea heb,\n    rcases decidable.eq_or_ne e 0 with rfl | he_pos,\n    { simp only [zero_dvd_iff] at hea, contradiction, },\n    have hea' := (factorization_le_iff_dvd he_pos ha_pos).mpr hea,\n    have heb' := (factorization_le_iff_dvd he_pos hb_pos).mpr heb,\n    simp [\u2190factorization_le_iff_dvd he_pos hd_pos, h1, hea', heb'] },\nend\n\nlemma factorization_lcm {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a.lcm b).factorization = a.factorization \u2294 b.factorization :=\nbegin\n  rw [\u2190 add_right_inj (a.gcd b).factorization,\n    \u2190 factorization_mul (mt gcd_eq_zero_iff.1 $ \u03bb h, ha h.1) (lcm_ne_zero ha hb),\n    gcd_mul_lcm, factorization_gcd ha hb, factorization_mul ha hb],\n  ext1, exact (min_add_max _ _).symm,\nend\n\n@[to_additive sum_factors_gcd_add_sum_factors_mul]\nlemma prod_factors_gcd_mul_prod_factors_mul {\u03b2 : Type*} [comm_monoid \u03b2] (m n : \u2115) (f : \u2115 \u2192 \u03b2) :\n  (m.gcd n).factors.to_finset.prod f * (m * n).factors.to_finset.prod f\n    = m.factors.to_finset.prod f * n.factors.to_finset.prod f :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hm0, { simp },\n  rcases eq_or_ne m 0 with rfl | hn0, { simp },\n  rw [\u2190@finset.prod_union_inter _ _ m.factors.to_finset n.factors.to_finset, mul_comm],\n  congr,\n  { apply factors_mul_to_finset; assumption },\n  { simp only [\u2190support_factorization, factorization_gcd hn0 hm0, finsupp.support_inf] },\nend\n\nlemma set_of_pow_dvd_eq_Icc_factorization {n p : \u2115} (pp : p.prime) (hn : n \u2260 0) :\n  {i : \u2115 | i \u2260 0 \u2227 p ^ i \u2223 n} = set.Icc 1 (n.factorization p) :=\nby { ext, simp [lt_succ_iff, one_le_iff_ne_zero, pp.pow_dvd_iff_le_factorization hn] }\n\n/-- The set of positive powers of prime `p` that divide `n` is exactly the set of\npositive natural numbers up to `n.factorization p`. -/\nlemma Icc_factorization_eq_pow_dvd (n : \u2115) {p : \u2115} (pp : prime p) :\n  Icc 1 ((n.factorization) p) = (Ico 1 n).filter (\u03bb (i : \u2115), p ^ i \u2223 n) :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  ext x,\n  simp only [mem_Icc, finset.mem_filter, mem_Ico, and_assoc, and.congr_right_iff,\n    pp.pow_dvd_iff_le_factorization hn, iff_and_self],\n  exact \u03bb H1 H2, lt_of_le_of_lt H2 (factorization_lt p hn),\nend\n\nlemma factorization_eq_card_pow_dvd (n : \u2115) {p : \u2115} (pp : p.prime) :\n  n.factorization p = ((Ico 1 n).filter (\u03bb i, p ^ i \u2223 n)).card :=\nby simp [\u2190Icc_factorization_eq_pow_dvd n pp]\n\nlemma Ico_filter_pow_dvd_eq {n p b : \u2115} (pp : p.prime) (hn : n \u2260 0) (hb : n \u2264 p ^ b):\n  (Ico 1 n).filter (\u03bb i, p ^ i \u2223 n) = (Icc 1 b).filter (\u03bb i, p ^ i \u2223 n) :=\nbegin\n  ext x,\n  simp only [finset.mem_filter, mem_Ico, mem_Icc, and.congr_left_iff, and.congr_right_iff],\n  rintro h1 -,\n  simp [lt_of_pow_dvd_right hn pp.two_le h1,\n    (pow_le_iff_le_right pp.two_le).1 ((le_of_dvd hn.bot_lt h1).trans hb)],\nend\n\n/-! ### Factorization and coprimes -/\n\n/-- For coprime `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\nlemma factorization_mul_apply_of_coprime {p a b : \u2115} (hab : coprime a b)  :\n  (a * b).factorization p = a.factorization p + b.factorization p :=\nby simp only [\u2190factors_count_eq, perm_iff_count.mp (perm_factors_mul_of_coprime hab), count_append]\n\n/-- For coprime `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\nlemma factorization_mul_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factorization = a.factorization + b.factorization :=\nbegin\n  ext q,\n  simp only [finsupp.coe_add, add_apply, \u2190factors_count_eq, factorization_mul_apply_of_coprime hab],\nend\n\n/-- If `p` is a prime factor of `a` then the power of `p` in `a` is the same that in `a * b`,\nfor any `b` coprime to `a`. -/\nlemma factorization_eq_of_coprime_left {p a b : \u2115} (hab : coprime a b) (hpa : p \u2208 a.factors) :\n  (a * b).factorization p = a.factorization p :=\nbegin\n  rw [factorization_mul_apply_of_coprime hab, \u2190factors_count_eq, \u2190factors_count_eq],\n  simpa only [count_eq_zero_of_not_mem (coprime_factors_disjoint hab hpa)],\nend\n\n/-- If `p` is a prime factor of `b` then the power of `p` in `b` is the same that in `a * b`,\nfor any `a` coprime to `b`. -/\nlemma factorization_eq_of_coprime_right {p a b : \u2115} (hab : coprime a b) (hpb : p \u2208 b.factors) :\n  (a * b).factorization p = b.factorization p :=\nby { rw mul_comm, exact factorization_eq_of_coprime_left (coprime_comm.mp hab) hpb }\n\n/-- The prime factorizations of coprime `a` and `b` are disjoint -/\nlemma factorization_disjoint_of_coprime {a b : \u2115} (hab : coprime a b) :\n  disjoint a.factorization.support b.factorization.support :=\nby simpa only [support_factorization]\n  using disjoint_to_finset_iff_disjoint.mpr (coprime_factors_disjoint hab)\n\n/-- For coprime `a` and `b` the prime factorization `a * b` is the union of those of `a` and `b` -/\nlemma factorization_mul_support_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factorization.support = a.factorization.support \u222a b.factorization.support :=\nbegin\n  rw factorization_mul_of_coprime hab,\n  exact support_add_eq (factorization_disjoint_of_coprime hab),\nend\n\n/-! ### Induction principles involving factorizations -/\n\n/-- Given `P 0, P 1` and a way to extend `P a` to `P (p ^ n * a)` for prime `p` not dividing `a`,\nwe can define `P` for all natural numbers. -/\n@[elab_as_eliminator]\ndef rec_on_prime_pow {P : \u2115 \u2192 Sort*} (h0 : P 0) (h1 : P 1)\n  (h : \u2200 a p n : \u2115, p.prime \u2192 \u00ac p \u2223 a \u2192 0 < n \u2192 P a \u2192 P (p ^ n * a)) : \u2200 (a : \u2115), P a :=\n\u03bb a, nat.strong_rec_on a $ \u03bb n,\n  match n with\n  | 0     := \u03bb _, h0\n  | 1     := \u03bb _, h1\n  | (k+2) := \u03bb hk, begin\n    let p := (k + 2).min_fac,\n    have hp : prime p := min_fac_prime (succ_succ_ne_one k),\n    -- the awkward `let` stuff here is because `factorization` is noncomputable (finsupp);\n    -- we get around this by using the computable `factors.count`, and rewriting when we want\n    -- to use the `factorization` API\n    let t := (k+2).factors.count p,\n    have ht : t = (k+2).factorization p := factors_count_eq,\n    have hpt : p ^ t \u2223 k + 2 := by { rw ht, exact ord_proj_dvd _ _ },\n    have htp : 0 < t :=\n    by { rw ht, exact hp.factorization_pos_of_dvd (nat.succ_ne_zero _) (min_fac_dvd _) },\n    convert h ((k + 2) / p ^ t) p t hp _ _ _,\n    { rw nat.mul_div_cancel' hpt, },\n    { rw [nat.dvd_div_iff hpt, \u2190pow_succ', ht],\n      exact pow_succ_factorization_not_dvd (k + 1).succ_ne_zero hp },\n    { exact htp },\n    { apply hk _ (nat.div_lt_of_lt_mul _),\n      simp [lt_mul_iff_one_lt_left nat.succ_pos', one_lt_pow_iff htp.ne, hp.one_lt] },\n    end\n  end\n\n/-- Given `P 0`, `P 1`, and `P (p ^ n)` for positive prime powers, and a way to extend `P a` and\n`P b` to `P (a * b)` when `a, b` are positive coprime, we can define `P` for all natural numbers. -/\n@[elab_as_eliminator]\ndef rec_on_pos_prime_pos_coprime {P : \u2115 \u2192 Sort*} (hp : \u2200 p n : \u2115, prime p \u2192 0 < n \u2192 P (p ^ n))\n  (h0 : P 0) (h1 : P 1) (h : \u2200 a b, 1 < a \u2192 1 < b \u2192 coprime a b \u2192 P a \u2192 P b \u2192 P (a * b)) :\n  \u2200 a, P a :=\nrec_on_prime_pow h0 h1 $\nbegin\n  intros a p n hp' hpa hn hPa,\n  by_cases ha1 : a = 1,\n  { rw [ha1, mul_one],\n    exact hp p n hp' hn },\n  refine h (p^n) a ((hp'.one_lt).trans_le (le_self_pow hn.ne' _)) _ _ (hp _ _ hp' hn) hPa,\n  { contrapose! hpa,\n    simp [lt_one_iff.1 (lt_of_le_of_ne hpa ha1)] },\n  simpa [hn, prime.coprime_iff_not_dvd hp'],\nend\n\n/-- Given `P 0`, `P (p ^ n)` for all prime powers, and a way to extend `P a` and `P b` to\n`P (a * b)` when `a, b` are positive coprime, we can define `P` for all natural numbers. -/\n@[elab_as_eliminator]\ndef rec_on_prime_coprime {P : \u2115 \u2192 Sort*} (h0 : P 0) (hp : \u2200 p n : \u2115, prime p \u2192 P (p ^ n))\n  (h : \u2200 a b, 1 < a \u2192 1 < b \u2192 coprime a b \u2192 P a \u2192 P b \u2192 P (a * b)) : \u2200 a, P a :=\nrec_on_pos_prime_pos_coprime (\u03bb p n h _, hp p n h) h0 (hp 2 0 prime_two) h\n\n/-- Given `P 0`, `P 1`, `P p` for all primes, and a way to extend `P a` and `P b` to\n`P (a * b)`, we can define `P` for all natural numbers. -/\n@[elab_as_eliminator]\ndef rec_on_mul {P : \u2115 \u2192 Sort*} (h0 : P 0) (h1 : P 1)\n  (hp : \u2200 p, prime p \u2192 P p) (h : \u2200 a b, P a \u2192 P b \u2192 P (a * b)) : \u2200 a, P a :=\nlet hp : \u2200 p n : \u2115, prime p \u2192 P (p ^ n) :=\n  \u03bb p n hp', match n with\n  | 0     := h1\n  | (n+1) := by exact h _ _ (hp p hp') (_match _)\n  end in\nrec_on_prime_coprime h0 hp $ \u03bb a b _ _ _, h a b\n\n/-- For any multiplicative function `f` with `f 1 = 1` and any `n \u2260 0`,\nwe can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/\nlemma multiplicative_factorization {\u03b2 : Type*} [comm_monoid \u03b2] (f : \u2115 \u2192 \u03b2)\n  (h_mult : \u2200 x y : \u2115, coprime x y \u2192 f (x * y) = f x * f y) (hf : f 1 = 1) :\n  \u2200 {n : \u2115}, n \u2260 0 \u2192 f n = n.factorization.prod (\u03bb p k, f (p ^ k)) :=\nbegin\n  apply' nat.rec_on_pos_prime_pos_coprime,\n  { intros p k hp hk hpk, simp [prime.factorization_pow hp, finsupp.prod_single_index _, hf] },\n  { simp },\n  { rintros -, rw [factorization_one, hf], simp },\n  { intros a b _ _ hab ha hb hab_pos,\n    rw [h_mult a b hab, ha (left_ne_zero_of_mul hab_pos), hb (right_ne_zero_of_mul hab_pos),\n        factorization_mul_of_coprime hab, \u2190prod_add_index_of_disjoint],\n    convert (factorization_disjoint_of_coprime hab) },\nend\n\n/-- For any multiplicative function `f` with `f 1 = 1` and `f 0 = 1`,\nwe can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/\nlemma multiplicative_factorization' {\u03b2 : Type*} [comm_monoid \u03b2] (f : \u2115 \u2192 \u03b2)\n  (h_mult : \u2200 x y : \u2115, coprime x y \u2192 f (x * y) = f x * f y) (hf0 : f 0 = 1) (hf1 : f 1 = 1) :\n  \u2200 {n : \u2115}, f n = n.factorization.prod (\u03bb p k, f (p ^ k)) :=\nbegin\n  apply' nat.rec_on_pos_prime_pos_coprime,\n  { intros p k hp hk, simp only [hp.factorization_pow], rw prod_single_index _, simp [hf1] },\n  { simp [hf0] },\n  { rw [factorization_one, hf1], simp },\n  { intros a b _ _ hab ha hb,\n    rw [h_mult a b hab, ha, hb, factorization_mul_of_coprime hab, \u2190prod_add_index_of_disjoint],\n    convert (factorization_disjoint_of_coprime hab) },\nend\n\n/-- Two positive naturals are equal if their prime padic valuations are equal -/\nlemma eq_iff_prime_padic_val_nat_eq (a b : \u2115) (ha : a \u2260 0) (hb : b \u2260 0) :\n  a = b \u2194 (\u2200 p : \u2115, p.prime \u2192 padic_val_nat p a = padic_val_nat p b) :=\nbegin\n  split,\n  { rintros rfl, simp },\n  { intro h,\n    refine eq_of_factorization_eq ha hb (\u03bb p, _),\n    by_cases pp : p.prime,\n    { simp [factorization_def, pp, h p pp] },\n    { simp [factorization_eq_zero_of_non_prime, pp] } },\nend\n\nlemma prod_pow_prime_padic_val_nat (n : nat) (hn : n \u2260 0) (m : nat) (pr : n < m) :\n  \u220f p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n :=\nbegin\n  nth_rewrite_rhs 0 \u2190factorization_prod_pow_eq_self hn,\n  rw eq_comm,\n  apply finset.prod_subset_one_on_sdiff,\n  { exact \u03bb p hp, finset.mem_filter.mpr\n      \u27e8finset.mem_range.mpr (gt_of_gt_of_ge pr (le_of_mem_factorization hp)),\n       prime_of_mem_factorization hp\u27e9 },\n  { intros p hp,\n    cases finset.mem_sdiff.mp hp with hp1 hp2,\n    rw \u2190factorization_def n (finset.mem_filter.mp hp1).2,\n    simp [finsupp.not_mem_support_iff.mp hp2] },\n  { intros p hp,\n    simp [factorization_def n (prime_of_mem_factorization hp)] }\nend\n\n/-! ### Lemmas about factorizations of particular functions -/\n\n-- TODO: Port lemmas from `data/nat/multiplicity` to here, re-written in terms of `factorization`\n\n/-- Exactly `n / p` naturals in `[1, n]` are multiples of `p`. -/\nlemma card_multiples (n p : \u2115) : card ((finset.range n).filter (\u03bb e, p \u2223 e + 1)) = n / p :=\nbegin\n  induction n with n hn, { simp },\n  simp [nat.succ_div, add_ite, add_zero, finset.range_succ, filter_insert, apply_ite card,\n    card_insert_of_not_mem, hn],\nend\n\n/-- Exactly `n / p` naturals in `(0, n]` are multiples of `p`. -/\nlemma Ioc_filter_dvd_card_eq_div (n p : \u2115) :\n  ((Ioc 0 n).filter (\u03bb x, p \u2223 x)).card = n / p :=\nbegin\n  induction n with n IH, { simp },\n  -- TODO: Golf away `h1` after Ya\u00ebl PRs a lemma asserting this\n  have h1 : Ioc 0 n.succ = insert n.succ (Ioc 0 n),\n  { rcases n.eq_zero_or_pos with rfl | hn, { simp },\n    simp_rw [\u2190Ico_succ_succ, Ico_insert_right (succ_le_succ hn.le), Ico_succ_right] },\n  simp [nat.succ_div, add_ite, add_zero, h1, filter_insert, apply_ite card,\n    card_insert_eq_ite, IH, finset.mem_filter, mem_Ioc, not_le.2 (lt_add_one n)],\nend\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/factorization/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7257967829631402}}
{"text": "import logic.function.basic\nimport tactic\n\nnoncomputable theory\nopen_locale classical\n\nopen set function classical\n\n\n/-\nThe Cantor-Bernstein Theorem: For any sets `A, B`, if there exist injections\n`f: A \u2192 B` and `g: B \u2192 A`, there exists a bijection `h: A \u2192 B`.\n-/\n\nvariables {A B : Type}\n\n/-\nThe proof of the theorem is based on the following informal reasoning: Look at\nthe directed bipartite graph with vertex sets `A` and `B` and edges defined by\n`f` and `g`. Each connected component of this graph can be seen to fall into\none of four categories:\n\n1) An infinite path starting at a vertex in `A`,\n2) An infinite path starting at a vertex in `B`,\n3) An infinite path extending in both directions,\n4) A directed cycle.\n\nIn case 1, we can create a bijection on that component by mapping each vertex\n`a \u2208 A` to the next one in the path, `f(a)`.\nIn case 2, we can create a bijection by mapping each vertex `a \u2208 A` to the\nprevious one in the path, `g\u207b\u00b9(a)`.\nIn case 3 and 4, we could go with either the scheme for case 1 or the scheme\nfor case 2 -- we'll arbitrarily go with the case 1 scheme.\nTaken together, these define a bijection `A \u2192 B`.\n\nIn other words, we want to define a function `h : A \u2192 B` such that\n`h(a) = g\u207b\u00b9(a)` whenever `a` belongs to a case 2 component, and `h(a) = f(a)`\notherwise, and then argue that `h` is a bijection.\n\nIn order to define `h`, we should first define a predicate that tells whether\n`a` belongs to a case 2 component. We start by defining a relation `follows`,\nwhich, given vertices `a \u2208 A` and `b \u2208 B`, says whether `a` follows `b`, i.e.,\nthere's a directed path in the graph from `b` to `a`. (In retrospect, my\nterminology may be a bit counterintuitive, depending on how you look at it.)\n\nWe can define this inductively. Our base case is when `a` comes immediately\nafter `b`, i.e., when `g(b) = a`. Then, if `a` follows `b`, then `g(f(a))`\nwill follow `b` as well.\n-/\n\ninductive follows (f : A \u2192 B) (g : B \u2192 A) : A \u2192 B \u2192 Prop\n| base {a : A} {b : B} : g b = a \u2192 follows a b\n| step {a : A} {b : B} : follows a b \u2192 follows (g (f a)) b\n\n\n/-\nNow we can define the set of elements of `A` in case 2 components; we call them\nthe `B_led` elements. Namely, these are the elements `a \u2208 A` that follow some\n`b \u2208 B` which \"leads\" a path, i.e., there's nothing that maps to `b`.\n-/\n\ndef B_led (f : A \u2192 B) (g : B \u2192 A) : set A :=\n{ a : A | \u2203 b : B, (follows f g a b \u2227 \u2200 a : A, f a \u2260 b) }\n\n\n/-\nThere's one more step before we can properly define `h`: we have to check that\nthe inverse of `g` is well-defined on `B_led` elements. This is \"obvious\",\nsince if nothing mapped to `a \u2208 A`, then it would be the leader in an `A_led`\ncomponent. However, we still have to prove it!\n-/\n\nlemma has_g_inv {f : A \u2192 B} {g : B \u2192 A} {a : A} (hyp_a : B_led f g a) :\n\u2203 b, g b = a :=\nbegin\n  cases hyp_a with p hyp_p,\n  replace hyp_p := hyp_p.left,\n  induction hyp_p with a b,\n  use b, assumption, use f hyp_p_a,\nend\n\n/-\nNow, we can define a function that, given a proof that `a` is `B_led`, returns\n`g\u207b\u00b9(a)`. (Well, technically, we're just returning *some* inverse of `a` -- we\nhaven't proved that the inverse is unique. We could do so easily, but it turns\nout we don't need to.)\n-/\n\ndef g_inv {f : A \u2192 B} {g : B \u2192 A} {a : A} (hyp_a : B_led f g a) : B :=\n  some (has_g_inv hyp_a)\n\n/-\nAnd a quick lemma: `g(g\u207b\u00b9(a)) = a` for any `B_led` element `a`.\n-/\n\nlemma inv_eq {f : A \u2192 B} {g : B \u2192 A} {a : A} (hyp : B_led f g a) :\ng (g_inv hyp) = a := some_spec (has_g_inv hyp)\n\n\n/-\nWe're finally ready to prove the bulk of the theorem. We'll actually prove a\nstronger version, which we used in our proof of the countable Hall matching\ntheorem: there exists a bijection that, regarded as a graph, is a subgraph of\nthe graph defined by `f` and `g`. In other words, whenever `h(a) = b`, we have\neither `f(a) = b` or `g(b) = a`. This doesn't add much extra work, since it's\nfairly obvious from the definition of `h`.\n-/\n\ntheorem cantor_bernstein_strong {f : A \u2192 B} {g : B \u2192 A} (hyp_f : injective f)\n(hyp_g : injective g) :\n\u2203 h : A \u2192 B, bijective h \u2227 \u2200 a b, h a = b \u2192 f a = b \u2228 g b = a :=\nbegin\n  /-\n  Here we define h: if `a` is `B_led`, then `h(a) = g\u207b\u00b9(a)`, else `h(a) = f(a)`.\n  -/\n  let h := \u03bb a, dite (B_led f g a) (\u03bb hyp_a, g_inv hyp_a) (\u03bb _, f a),\n  use h,\n  /-\n  We prove injectivity, then surjectivity, then the added \"strong\" property.\n  -/\n  split, split,\n  {\n    /-\n    The bulk of the proof of injectivity is showing that, if `h(a\u2081) = h(a\u2082)`,\n    then `a\u2081` and `a\u2082` belong to the same connected component. Thus, they're\n    either both `B_led` or both not, and in either case injectivity follows\n    pretty much immediately.\n\n    The proof can be informally stated as follows:\n\n    Suppose for sake of contradiction that `h(a\u2081) = h(a\u2082)`, but `a\u2081` is `B_led`\n    and `a\u2082` isn't. Then `g\u207b\u00b9(a\u2081) = f(a\u2082)`, so `a\u2081 = g(f(a\u2082))`.\n\n    Intuitively, we can see that this means `a\u2081` comes 2 steps after `a\u2082` in a \n    path, so they're in the same connected component, a contradiction.\n    \n    Putting it formally requires us to go back to our inductive definition of\n    \"following\". Let `b` be the leader of `a\u2081`'s component, so `a` follows `b`.\n    \n    The `base` case where `a\u2081` immediately follows `b` is impossible, since\n    otherwise `a\u2082` would point to `b`, contradicting `b`'s status as leader.\n    \n    But this leaves us with the `step` case, which implies there's some `a`\n    for which `a` follows `b` and `f(g(a)) = a\u2081 = f(g(a\u2082))`. Injectivity then\n    implies `a = a\u2082`, so `a\u2082` follows `b`, and is thus `B_led` -- contradiction.\n    -/\n    have impossible_case : \u2200 a\u2081 a\u2082 : A,\n    h a\u2081 = h a\u2082 \u2192 B_led f g a\u2081 \u2192 \u00acB_led f g a\u2082 \u2192 false :=\n    begin\n      intros a\u2081 a\u2082 hyp_a hyp_1 hyp_2,\n      apply hyp_2,\n      simp [h, dif_pos hyp_1, dif_neg hyp_2] at hyp_a,\n      clear hyp_2 h,\n      replace hyp_a := congr_arg g hyp_a, rw inv_eq hyp_1 at hyp_a,\n\n      cases hyp_1 with b hyp_b,\n      use b,\n      cases hyp_b,\n      rw and_iff_left hyp_b_right,\n      cases hyp_b_left with _ _ hyp_base a _ hyp_step,\n      {\n        apply false.elim, apply hyp_b_right a\u2082,\n        apply hyp_g,\n        rw [\u2190 hyp_a, hyp_base],\n      },\n      {\n        rwa \u2190 hyp_f (hyp_g hyp_a),\n      },\n    end,\n    /-\n    This finishes the \"impossible case\" -- the rest of the injectivity proof is\n    pretty straightforward.\n    -/\n    intros a\u2081 a\u2082 hyp_a,\n    cases classical.em (B_led f g a\u2081) with hyp_1 hyp_1;\n    cases classical.em (B_led f g a\u2082) with hyp_2 hyp_2,\n    {\n      simp [h, dif_pos hyp_1, dif_pos hyp_2] at hyp_a,\n      rw [\u2190 inv_eq hyp_1, \u2190 inv_eq hyp_2],\n      exact congr_arg g hyp_a,\n    },\n    {\n      exact false.elim (impossible_case a\u2081 a\u2082 hyp_a hyp_1 hyp_2),\n    },\n    {\n      exact false.elim (impossible_case a\u2082 a\u2081 (hyp_a.symm) hyp_2 hyp_1),\n    },\n    {\n      simp [h, dif_neg hyp_1, dif_neg hyp_2] at hyp_a,\n      exact hyp_f hyp_a,\n    },\n  },\n  {\n    /-\n    The proof of surjectivity is roughly as follows:\n\n    Take an arbitrary `b \u2208 B`, and do casework on whether `g(b)` is `B_led`.\n\n    If `g(b)` is `B_led`, then `h(g(b)) = g\u207b\u00b9(g(b)) = b`, so `g(b)` works and\n    we're done.\n\n    Otherwise, `g(b)` isn't `B_led`. This implies that there exists `a` such\n    that `f(a) = b` -- otherwise, `b` would be a leader of `g(b)`'s component.\n\n    Note that `a` can't be `B_led`, since otherwise `g(b) = g(f(a))` would also\n    be `B_led` (as immediately implied by the `step` case).\n\n    Thus, `h(a) = f(a) = b`, so `a` works and we're done.\n    -/\n    intro b,\n    cases classical.em (B_led f g (g b)) with hyp_1 hyp_1,\n    {\n      use g b,\n      simp [h, dif_pos hyp_1],\n      apply hyp_g, apply inv_eq,\n    },\n    {\n      have has_f_inv : \u2203 a, f a = b :=\n      begin\n        rw [B_led, \u2190 @mem_def _ _ {a | _}, nmem_set_of_eq] at hyp_1,\n        simp at hyp_1,\n        specialize hyp_1 b,\n        apply hyp_1,\n        exact follows.base rfl,\n      end,\n      cases has_f_inv with a hyp_2,\n      use a,\n      rw \u2190 hyp_2 at hyp_1,\n      replace hyp_1 : \u00acB_led f g a :=\n      begin\n        revert hyp_1, rw not_imp_not, intros hyp,\n        cases hyp with b hyp_b,\n        use b,\n        exact \u27e8(follows.step hyp_b.left), hyp_b.right\u27e9,\n      end,\n      simpa [h, dif_neg hyp_1],\n    },\n  },\n  {\n    /-\n    All that's left is to prove the extra fact about `h`, but this is very\n    straightforward.\n    -/\n    intros a b hyp,\n    simp [h] at hyp,\n    cases classical.em (B_led f g a) with hyp_pos hyp_neg,\n    {\n      replace hyp := congr_arg g hyp,\n      rw [dif_pos hyp_pos, inv_eq hyp_pos] at hyp,\n      exact or.intro_right _ hyp.symm,\n    },\n    {\n      rw dif_neg hyp_neg at hyp,\n      exact or.intro_left _ hyp,\n    },\n  },\nend\n\n\n/-\nWe've now formally proved the Cantor-Bernstein theorem -- yay!\n\nHere's the \"normal\" version, which obviously follows from the \"strong\" version.\n-/\n\ntheorem cantor_bernstein {f : A \u2192 B} {g : B \u2192 A} (hyp_f : injective f)\n(hyp_g : injective g) : \u2203 h : A \u2192 B, bijective h :=\nbegin\n  have cbs := cantor_bernstein_strong hyp_f hyp_g,\n  cases cbs with h hyp_h,\n  exact Exists.intro h hyp_h.left,\nend", "meta": {"author": "ccobb1", "repo": "lean-cantor-bernstein", "sha": "3d18117f1906fc779ddd484704a03145d561f8e9", "save_path": "github-repos/lean/ccobb1-lean-cantor-bernstein", "path": "github-repos/lean/ccobb1-lean-cantor-bernstein/lean-cantor-bernstein-3d18117f1906fc779ddd484704a03145d561f8e9/src/cantor_bernstein.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7257967813395223}}
{"text": "/-\nCopyright (c) 2021 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport logic.basic\n\n/-!\n# Girard's paradox\n\nGirard's paradox is a proof that `Type : Type` entails a contradiction. We can't say this directly\nin Lean because `Type : Type 1` and it's not possible to give `Type` a different type via an axiom,\nso instead we axiomatize the behavior of the Pi type and application if the typing rule for Pi was\n`(Type \u2192 Type) \u2192 Type` instead of `(Type \u2192 Type) \u2192 Type 1`.\n\nFurthermore, we don't actually want false axioms in mathlib, so rather than introducing the axioms\nusing `axiom` or `constant` declarations, we take them as assumptions to the `girard` theorem.\n\nBased on Watkins' LF implementation of Hurkens' simplification of Girard's paradox:\n<http://www.cs.cmu.edu/~kw/research/hurkens95tlca.elf>.\n\n## Main statements\n\n* `girard`: there are no Girard universes.\n-/\n\n/-- **Girard's paradox**: there are no universes `u` such that `Type u : Type u`.\nSince we can't actually change the type of Lean's `\u03a0` operator, we assume the existence of\n`pi`, `lam`, `app` and the `beta` rule equivalent to the `\u03a0` and `app` constructors of type theory.\n-/\ntheorem {u} girard\n  (pi : (Type u \u2192 Type u) \u2192 Type u)\n  (lam : \u2200 {A : Type u \u2192 Type u}, (\u2200 x, A x) \u2192 pi A)\n  (app : \u2200 {A}, pi A \u2192 \u2200 x, A x)\n  (beta : \u2200 {A : Type u \u2192 Type u} (f : \u2200 x, A x) (x), app (lam f) x = f x) : false :=\nlet F (X) := (set (set X) \u2192 X) \u2192 set (set X), U := pi F in\nlet G (T : set (set U)) (X) : F X := \u03bb f, {p | {x : U | f (app x X f) \u2208 p} \u2208 T} in\nlet \u03c4 (T : set (set U)) : U := lam (G T) in\nlet \u03c3 (S : U) : set (set U) := app S U \u03c4 in\nhave \u03c3\u03c4 : \u2200 {s S}, s \u2208 \u03c3 (\u03c4 S) \u2194 {x | \u03c4 (\u03c3 x) \u2208 s} \u2208 S := \u03bb s S,\n  iff_of_eq (congr_arg (\u03bb f : F U, s \u2208 f \u03c4) (beta (G S) U) : _),\nlet \u03c9 : set (set U) := {p | \u2200 x, p \u2208 \u03c3 x \u2192 x \u2208 p} in\nlet \u03b4 (S : set (set U)) := \u2200 p, p \u2208 S \u2192 \u03c4 S \u2208 p in\nhave \u03b4 \u03c9 := \u03bb p d, d (\u03c4 \u03c9) $ \u03c3\u03c4.2 $ \u03bb x h, d (\u03c4 (\u03c3 x)) (\u03c3\u03c4.2 h),\nthis {y | \u00ac \u03b4 (\u03c3 y)} (\u03bb x e f, f _ e (\u03bb p h, f _ (\u03c3\u03c4.1 h))) (\u03bb p h, this _ (\u03c3\u03c4.1 h))\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/counterexamples/girard.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7257967809648398}}
{"text": "import data.int.basic\nimport data.nat.parity\nimport data.nat.prime\nimport tactic\nimport tactic.linarith\n\nnamespace lecture4\n\nopen nat\n\ntheorem div_14_div_7 : \u2200 N, 14 \u2223 N \u2192 7 \u2223 N :=\nbegin\n  intros N h,\n  cases h with divisor h,\n  refine dvd.intro _ _,\n  let divisor' := 2 * divisor,\n  use divisor',\n  simp,\n  linarith,\nend\n\ntheorem prime_and_prime_succ : \u2200 p, prime p \u2192 prime (p + 1) \u2192 p = 2 :=\nbegin\n  intros p hprime hprimesucc,\n  cases even_or_odd p,\n  {\n    cases h with n hn,\n    let hprime2 := hprime,\n    cases hprime,\n    specialize hprime_right n,\n    have n_div_p : n \u2223 p,\n    {\n      exact dvd.intro_left 2 (eq.symm hn)\n    },\n\n    cases hprime_right n_div_p,\n    {\n      linarith,\n    },\n\n    have p_zero : p = 0,\n    {\n      rw h at hn,\n      linarith,\n    },\n\n    by_contradiction h',\n    apply not_prime_zero,\n    rw p_zero at hprime2,\n    exact hprime2,\n  },\n\n  let h2 := h,\n  cases h with n hn,\n  cases hprimesucc,\n\n  have n_div_succ_p : 2 \u2223 succ p,\n  {\n    refine even_iff_two_dvd.mp _,\n    refine even_succ.mpr _,\n    exact odd_iff_not_even.mp h2,\n  },\n\n  specialize hprimesucc_right 2,\n  cases hprimesucc_right n_div_succ_p,\n  {\n    by_contradiction h',\n    linarith,\n  },\n\n  have n_zero : n = 0,\n  {\n    linarith,\n  },\n\n  rw n_zero at hn,\n  by_contradiction,\n  refine not_prime_one _,\n  have p_one : p = 1,\n  {\n    linarith,\n  },\n  rw \u2190p_one,\n  exact hprime,\nend\n\n\nlemma only_even_prime_is_2 : \u2200 {n}, prime n -> even n -> n = 2 :=\nbegin\n  intros n hp he,\n  cases hp,\n  cases he,\n  specialize hp_right 2,\n  cases hp_right (dvd.intro he_w (eq.symm he_h) : 2 \u2223 n),\n  {\n    finish,\n  },\n  linarith,\nend\n\ntheorem prime_and_prime_succ2\n      {p} (hprime : prime p) (hprimesucc : prime (p + 1)) : p = 2 :=\nbegin\n  cases even_or_odd p,\n  {\n    exact only_even_prime_is_2 hprime h,\n  },\n  exfalso,\n  have p_succ_even : even (p + 1) := begin\n    refine even_succ.mpr _,\n    exact odd_iff_not_even.mp h,\n  end,\n  have p_succ_is_two : (p + 1) = 2 := only_even_prime_is_2 hprimesucc p_succ_even,\n  have p_is_one : p = 1 := by linarith,\n  refine not_prime_one _,\n  rw p_is_one at hprime,\n  exact hprime,\nend\n\n-- this should be defined over \u2124\ntheorem bounds_by_divisibility\n    {a b : \u2115} (a_divs_b : a \u2223 b) (b_neq_0 : b \u2260 0)\n    : a \u2264 b :=\nbegin\n  refine le_of_dvd _ a_divs_b,\n  by_contradiction,\n  have b_leq_0 : b \u2264 0 := by linarith,\n  finish,\nend\n\ntheorem div_trans\n    {a b c : \u2115} (a_divs_b : a \u2223 b) (b_divs_c : b \u2223 c)\n    : a \u2223 c :=\nbegin\n  cases a_divs_b with k hk,\n  cases b_divs_c with i hi,\n  refine dvd.intro _ _,\n  use k * i,\n  finish,\nend\n\ntheorem div_of_int_combo\n    {a b c : \u2115} (a_divs_b : a \u2223 b) (b_divs_c : b \u2223 c)\n    : \u2200 x y, a \u2223 (b * x + c * y) :=\nbegin\n  intros x y,\n  cases a_divs_b with k hk,\n  cases b_divs_c with i hi,\n  refine dvd.intro _ _,\n  use (k*x + k*i*y),\n  rw hi,\n  repeat {rw hk},\n  linarith,\nend\n\nend lecture4\n", "meta": {"author": "isovector", "repo": "math135", "sha": "e270f3a9cae435c066c0d2574f03a8adbe40b7b5", "save_path": "github-repos/lean/isovector-math135", "path": "github-repos/lean/isovector-math135/math135-e270f3a9cae435c066c0d2574f03a8adbe40b7b5/src/lecture4-divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7257967805901572}}
{"text": "import data.real.basic\nimport data.pnat.basic\nimport solutions_sheet_two\n\nlocal notation `|` x `|` := abs x\n\ndef is_limit (a : \u2115+ \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < \u03b5\n\ndef is_convergent (a : \u2115+ \u2192 \u211d) : Prop :=\n\u2203 l : \u211d, is_limit a l\n\ndef is_not_convergent (a : \u2115+ \u2192 \u211d) : Prop := \u00ac is_convergent a\n\n/-!\n\n# Q1\n\n-/\n\n/-\n\nWhich of the following sequences are convergent and which are not?\nWhat's the limit of the convergent ones?\n\n-/\n\ntheorem Q1a : is_limit (\u03bb n, (n+7)/n) 1 :=\nbegin\n  intros \u03b5 h\u03b5,\n  use (ceil ((37 : \u211d) / \u03b5)).nat_abs,\n  { apply int.nat_abs_pos_of_ne_zero,\n    apply norm_num.ne_zero_of_pos,\n    rw ceil_pos,\n    refine div_pos _ h\u03b5,\n    norm_num },\n  rintros \u27e8n, hn0\u27e9 hn,\n  simp only [pnat.mk_coe, coe_coe],\n  rw add_div,\n  rw div_self (show (n : \u211d) \u2260 0, by norm_cast; linarith),\n  simp only [add_sub_cancel'],\n  rw abs_lt,\n  split,\n  { refine lt_trans (show -\u03b5 < 0, by linarith) _,\n    refine div_pos (by norm_num) _,\n    assumption_mod_cast },\n  { rw div_lt_iff, swap, assumption_mod_cast,\n    simp at hn,\n\n    replace hn := le_trans int.le_nat_abs (int.coe_nat_le.mpr hn),\n    rw ceil_le at hn,\n    norm_cast at hn,\n    rw div_le_iff h\u03b5 at hn,\n    linarith }\nend\n\ntheorem Q1b : is_limit (\u03bb n, n/(n+7)) 1 :=\nbegin\n  sorry\nend\n\ntheorem Q1c : is_limit (\u03bb n, (n^2+5*n+6)/(n^3-2)) 0 :=\nbegin\n  sorry\nend\n\ntheorem Q1d : is_not_convergent (\u03bb n, (n^3-2)/(n^2+5*n+6)) :=\nbegin\n  sorry\nend\n\ndef is_cauchy (a : \u2115+ \u2192 \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N : \u2115+, \u2200 m n \u2265 N, |a m - a n| < \u03b5\n\ntheorem is_cauchy_of_is_convergent {a : \u2115+ \u2192 \u211d} : is_convergent a \u2192 is_cauchy a :=\nbegin\n  rintro \u27e8l, hl\u27e9,\n  intros \u03b5 h\u03b5,\n  specialize hl (\u03b5/2) (by linarith),\n  rcases hl with \u27e8B, hB1\u27e9,\n  use B,\n  intros m n hmB hnB,\n  have hm := hB1 m hmB, \n  have hn := hB1 n hnB,\n  have h := abs_add (a m - l) (l - a n),\n  have h2 : a m - l + (l - a n) = a m - a n := by ring,\n  rw h2 at h,\n  rw abs_sub l at h,\n  linarith,\nend\n\n\ntheorem Q1e : is_not_convergent (\u03bb n, (1 - n*(-1)^n.1)/n) :=\nbegin\n  intro h,\n  replace h := is_cauchy_of_is_convergent h,\n  -- 1/n + (-1)^{n+1}\n  specialize h 0.1 (by linarith),\n  cases h with N hN,\n  have htemp : N \u2264 N + 1,\n    cases N with N hN,\n    change N \u2264 _,\n    simp,\n  specialize hN N (N + 1) (le_refl N) htemp,\n  rw abs_lt at hN,\n  dsimp only at hN,\n  cases hN with hN1 hN2,\n  cases N with N hN,\n  simp at *,\n  sorry\nend\n\n/-!\n\n# Q3\n\n-/\n\n/-\n\nLet a_n be a sequence converging to a \u2208 \u211d. Suppose b_n is another\nsequence which is different than a_n but only differs from a_n\nin finitely many terms, that is the set {n : \u2115 | a_n \u2260 b_n} is\nnon-empty and finite. Prove b_n converges to a\n-/\n\ntheorem Q3 (a : \u2115+ \u2192 \u211d) (b : \u2115+ \u2192 \u211d) (h_never_used : {n : \u2115+ | a n \u2260 b n}.nonempty)\n  (h : {n : \u2115+ | a n \u2260 b n}.finite) (l : \u211d) (ha : is_limit a l) : is_limit b l :=\nbegin\n  intros \u03b5 h\u03b5,\n  cases ha \u03b5 h\u03b5 with B hB,\n  let S : finset \u2115+ := h.to_finset,\n  have hS : S.nonempty,\n    simp only [h_never_used, set.finite.to_finset.nonempty],\n  let m := finset.max' S hS,\n  use max B (m + 1),\n  intros n hn,\n  convert hB n _,\n  { suffices : n \u2209 {n | a n \u2260 b n},\n      symmetry,\n      by_contra htemp,\n      apply this,\n      exact htemp,\n    intro htemp,\n    have hS : n \u2208 S,\n      simp [htemp],\n      exact htemp,\n    have ZZZ : n \u2264 m := finset.le_max' S n hS,\n    change max _ _ \u2264 n at hn,\n    rw max_le_iff at hn,\n    cases hn,\n    have YYY := le_trans hn_right ZZZ,\n    change m.1 + 1 \u2264 m.1 at YYY,\n    linarith },\n  change _ \u2264 _ at hn,\n  rw max_le_iff at hn,\n  exact hn.1,\nend\n\n/-!\n\n# Q4\n\n-/\n\n/-\n\nLet S \u2286 \u211d be a nonempty bounded above set. show that there exists\na sequence of numbers s_n \u2208 S, n = 1, 2, 3,\u2026 such that s\u2099 \u2192 Sup S\n\n\n-/\n\n--theorem useful_lemma {S : set \u211d} {a : \u211d} (haS : is_lub S a) (t : \u211d)\n--  (ht : t < a) : \u2203 s, s \u2208 S \u2227 t < s :=\n\ntheorem useful_lemma2 (S : set \u211d) (hS1 : S.nonempty) (hS2 : bdd_above S) :\n  is_lub S (Sup S) :=\nbegin\n  cases hS1 with a ha,\n  cases hS2 with b hb,\n  apply real.is_lub_Sup ha hb,\nend\n\ntheorem pnat_aux_lemma {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {a : \u211d} (ha : 0 < a) : 0 < \u2308a / \u03b5\u2309.nat_abs :=\nbegin\n  apply int.nat_abs_pos_of_ne_zero,\n  apply norm_num.ne_zero_of_pos,\n  rw ceil_pos,\n  refine div_pos _ h\u03b5,\n  exact ha,\nend\n\n\ntheorem Q4 (S : set \u211d) (hS1 : S.nonempty) (hS2 : bdd_above S) :\n  \u2203 s : \u2115+ \u2192 \u211d, (\u2200 n, s n \u2208 S) \u2227 is_limit s (Sup S) :=\nbegin\n  have h := useful_lemma (useful_lemma2 S hS1 hS2),\n--  by_contra h2,\n--  unfold is_limit at h2,\n--  push_neg at h2,\n  let s : \u2115+ \u2192 \u211d :=\n  \u03bb n, classical.some (h (Sup S - 1/n) (show Sup S - 1/n < Sup S, from _)),\n  have hs : \u2200 n : \u2115+, _ :=\n  \u03bb n, classical.some_spec (h (Sup S - 1/n) (show Sup S - 1/n < Sup S, from _)),\n  use s,\n  swap,\n  { cases n with n hn,\n    rw sub_lt_self_iff,\n    rw one_div_pos,\n    simp [hn] },\n  have hs2 : \u2200 (n : \u2115+), s n \u2208 S,\n  { intro n,\n    dsimp at hs,\n    exact (hs n).1 },\n  use hs2,\n  intros \u03b5 h\u03b5,\n  use (ceil (2/\u03b5)).nat_abs,\n    exact pnat_aux_lemma h\u03b5 (show (0 : \u211d) < 2, by norm_num),\n  intros n hn,\n  have hn2 : Sup S - 1/n < s n,\n    exact (hs n).2,\n  rw sub_lt at hn2,\n  have hS3 := useful_lemma2 S hS1 hS2,\n  rw abs_lt,\n  split,\n  { suffices : (1 : \u211d) / n < \u03b5,\n      linarith,\n    cases n with n hn3, -- \n    show (1 : \u211d) / n < _,\n    rw div_lt_iff (show 0 < (n : \u211d), by assumption_mod_cast),\n    simp at hn,\n    replace hn := le_trans (int.le_nat_abs) (int.coe_nat_le.mpr hn),\n    rw ceil_le at hn,\n    norm_cast at hn,\n    rw div_le_iff at hn;\n    linarith },\n  { refine lt_of_le_of_lt _ h\u03b5,\n    specialize hs2 n,\n    rw sub_nonpos,\n    cases hS3 with hS4 hS5,\n    apply hS4 hs2 },\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "M40002", "sha": "a499db70323bd5ccae954c680ec9afbf15ffacca", "save_path": "github-repos/lean/ImperialCollegeLondon-M40002", "path": "github-repos/lean/ImperialCollegeLondon-M40002/M40002-a499db70323bd5ccae954c680ec9afbf15ffacca/src/solutions_sheet_three.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.725796778591857}}
{"text": "import tactic\nimport data.real.sqrt\nimport data.int.modeq\nimport data.real.irrational\nimport data.nat.factorization.prime_pow\n\n/-\n\nFor each of the following functions `f`, say whether `f` is `1-1` and whether `f`\nis `onto`.\n\n-/\n\ndef f1 (x : \u211d) : \u211d := x^2 + 2*x\n\nnoncomputable def f2 (x : \u211d) : \u211d := \n  if 1 < x then x - 2 \n  else if x < -1 then x + 2\n  else -x\n\nnoncomputable def f3 (x : \u211a) : \u211d := (x + real.sqrt 2)^2\n\ndef f4 (mnr : \u2115 \u00d7 \u2115 \u00d7 \u2115) : \u2115 := \nlet \u27e8m, n, r\u27e9 := mnr in\n2 ^ m * 3 ^ n * 5 ^ r\n\ndef f5 (mnr : \u2115 \u00d7 \u2115 \u00d7 \u2115) : \u2115 := \nlet \u27e8m, n, r\u27e9 := mnr in\n2 ^ m * 3 ^ n * 6 ^ r\n\n-- For the last question let's first make the equivalence relation\ndef e (a b : \u2124) : Prop := a \u2261 b [ZMOD 7]\n\nlemma he : equivalence e :=\n\u27e8 \n  -- reflexive\n  begin\n    intro x,\n    unfold e,\n  end,\n  -- symmetric\n  begin\n    intros x y h,\n    unfold e at *,\n    exact int.modeq.symm h,\n  end,\n  -- transitive\n  begin\n    intros x y z hxy hyz,\n    unfold e at *,\n    exact int.modeq.trans hxy hyz,\n  end \u27e9\n\n-- Let's now say that `e` is the \"canonical\" equivalence relation on \u2124\ninstance s : setoid \u2124 := \u27e8e, he\u27e9\n\nlemma s_def (a b : \u2124) : a \u2248 b \u2194 a \u2261 b [ZMOD 7]:= iff.rfl\n\n-- and now we can use the theory of quotients. The set `S` in the question\n-- is called `quotient s` here. \n\ndef f6 (x : quotient s) : quotient s :=\nquotient.map (\u03bb t : \u2124, t + 1) begin\n  -- Lean points out that if we don't show the below, then `f6` isn't well-defined!\n  show \u2200 a b : \u2124, a \u2248 b \u2192 a + 1 \u2248 b + 1,\n  -- So we have to prove it now.\n  intros a b hab,\n  rw s_def at *,\n  exact int.modeq.add_right 1 hab,\nend x\n\n-- `injective` is actually called `function.injective` so let's open `function`\nopen function\n\n-- now we can just call it `injective`\n\n/-\n\n## The rules\n\nIf the functions are injective/surjective, prove the lemmas. If they're not,\nthen put `\u00ac` in front of them (e.g. `exercise01inj : \u00ac (injective f1)` and prove\nthat instead!\n\n-/\nlemma exercise01inj : \u00ac (injective f1) :=\nbegin\n  intro h,\n  have hp : f1 (-2) = f1 0,\n  {unfold f1, norm_num},\n  specialize h hp,\n  norm_num at h,\nend\n\nlemma exercise01surj : \u00ac (surjective f1) :=\nbegin\n  intro h,\n  specialize h (-2),\n  cases h with x hx,\n  unfold f1 at hx,\n  have hp : \u2200 x : \u211d, x ^ 2 + 2 * x = -2 \u2194 (x + 1)^2 = -1,\n  {intro x, split, {intro h1, linear_combination h1},\n  {intros h2, linear_combination h2},\n  },\n  specialize hp x,\n  rw hp at hx,\n  nlinarith,\nend\n\nlemma exercise02inj : \u00ac (injective f2) :=\nbegin\n  intro h,\n  have hp : f2 (-1/2) = f2 (5/2),\n  {unfold f2, split_ifs; linarith},\n  specialize h hp,\n  norm_num at h,\nend\n\nlemma exercise02surj : (surjective f2) :=\nbegin\n  intro y,\n  rcases lt_trichotomy y 0 with h1 | rfl | h3,\n  {use (y-2), unfold f2, split_ifs; linarith},\n  {use 0, unfold f2, split_ifs; linarith},\n  {use (y+2), unfold f2, split_ifs; linarith},\nend\n\nlemma exercise03inj : injective f3 :=\nbegin\n  intros a b hab,\n  unfold f3 at hab,\n  simp [mul_self_eq_mul_self_iff, pow_two] at hab,\n  rcases hab with h1 | h2,\n  {assumption},\n  {exfalso, suffices h : real.sqrt 2 = -(a + b) / 2, \n  {norm_cast at h, apply irrational_sqrt_two, use (-(a + b) / 2), exact h.symm,},\n  {linear_combination h2 / 2}},\nend\n\nlemma exercise03surj : \u00ac (surjective f3) :=\nbegin\n  intro h,\n  specialize h (-1),\n  cases h with x h,\n  unfold f3 at h,\n  nlinarith,\nend\n\nlemma padic_val_nat_two_aux (a b c : \u2115) : padic_val_nat 2 (2 ^ a * 3 ^ b * 5 ^ c) = a :=\nbegin\n  haveI : fact (nat.prime 2) := fact.mk nat.prime_two,\n  rw [padic_val_nat.mul 2 (mul_ne_zero _ _), padic_val_nat.mul, padic_val_nat.prime_pow,\n    padic_val_nat.eq_zero_of_not_dvd, padic_val_nat.eq_zero_of_not_dvd],\n  { simp },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_two h,\n    norm_num at h, },\n    { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_two h,\n    norm_num at h, },\n  all_goals {exact pow_ne_zero _ (by norm_num)},\nend\n\nlemma padic_val_nat_three_aux (a b c : \u2115) : padic_val_nat 3 (2 ^ a * 3 ^ b * 5 ^ c) = b :=\nbegin\n  haveI : fact (nat.prime 3) := fact.mk nat.prime_three,\n  rw [padic_val_nat.mul 3 (mul_ne_zero _ _), padic_val_nat.mul, padic_val_nat.prime_pow,\n    padic_val_nat.eq_zero_of_not_dvd, padic_val_nat.eq_zero_of_not_dvd],\n  { simp },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_three h,\n    norm_num at h, },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_three h,\n    norm_num at h, },\n  all_goals {exact pow_ne_zero _ (by norm_num)},\nend\n\nlemma nat.prime_five : nat.prime 5 := by norm_num\n\nlemma padic_val_nat_five_aux (a b c : \u2115) : padic_val_nat 5 (2 ^ a * 3 ^ b * 5 ^ c) = c :=\nbegin\n  haveI : fact (nat.prime 5) := fact.mk nat.prime_five,\n  rw [padic_val_nat.mul 5 (mul_ne_zero _ _), padic_val_nat.mul, padic_val_nat.prime_pow,\n    padic_val_nat.eq_zero_of_not_dvd, padic_val_nat.eq_zero_of_not_dvd],\n  { simp },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_five h,\n    norm_num at h, },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_five h,\n    norm_num at h, },\n  all_goals {exact pow_ne_zero _ (by norm_num)},\nend\n\nlemma exercise04inj : injective f4 :=\nbegin\n  rintro \u27e8a1, b1, c1\u27e9 \u27e8a2, b2, c3\u27e9 h,\n  unfold f4 at h,\n  simp,\n  refine \u27e8_, _, _\u27e9,\n  { rw [\u2190 padic_val_nat_two_aux a1 b1 c1, h, padic_val_nat_two_aux], },\n  { rw [\u2190 padic_val_nat_three_aux a1 b1 c1, h, padic_val_nat_three_aux], },\n  { rw [\u2190 padic_val_nat_five_aux a1 b1 c1, h, padic_val_nat_five_aux], },\nend\n\nlemma nat.prime_seven : nat.prime 7 := by norm_num\n\nlemma padic_val_nat_seven_aux (a b c : \u2115) : padic_val_nat 7 (2 ^ a * 3 ^ b * 5 ^ c) = 0 :=\nbegin\n  haveI : fact (nat.prime 7) := fact.mk nat.prime_seven,\n  rw [padic_val_nat.mul 7 (mul_ne_zero _ _), padic_val_nat.mul, padic_val_nat.eq_zero_of_not_dvd,\n    padic_val_nat.eq_zero_of_not_dvd, padic_val_nat.eq_zero_of_not_dvd],\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_seven h,\n    norm_num at h, },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_seven h,\n    norm_num at h, },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_seven h,\n    norm_num at h, },\n  all_goals {exact pow_ne_zero _ (by norm_num)},\nend\n\nlemma exercise04surj : \u00ac (surjective f4) :=\nbegin\n  intro h,\n  specialize h 7,\n  cases h with x h,\n  rcases x with \u27e8a, b, c\u27e9,\n  unfold f4 at h,\n  have := padic_val_nat_seven_aux a b c,\n  rw h at this,\n  simpa using this,\nend\n\nlemma exercise05inj : \u00ac (injective f5) :=\nbegin\n  intro h,\n  unfold injective at h,\n  have hp : f5 \u27e81,1,1\u27e9 = f5 \u27e82,2,0\u27e9,\n  {unfold f5 at *, norm_num},\n  specialize h hp, \n  simpa using h,\nend\n\nlemma padic_val_nat_five_aux_ (a b c : \u2115) : padic_val_nat 5 (2 ^ a * 3 ^ b * 6 ^ c) = 0 :=\nbegin\n  haveI : fact (nat.prime 5) := fact.mk nat.prime_five,\n  rw [padic_val_nat.mul 5 (mul_ne_zero _ _), padic_val_nat.mul, padic_val_nat.eq_zero_of_not_dvd,\n    padic_val_nat.eq_zero_of_not_dvd, padic_val_nat.eq_zero_of_not_dvd],\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_five h,\n    norm_num at h, },\n  { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_five h,\n    norm_num at h, },\n    { intro h, \n    replace h := nat.prime.dvd_of_dvd_pow nat.prime_five h,\n    norm_num at h, },\n  all_goals {exact pow_ne_zero _ (by norm_num)},\nend\n\nlemma exercise05surj : \u00ac (surjective f5) :=\nbegin\n  intro h,\n  specialize h 5,\n  cases h with x h,\n  rcases x with \u27e8a, b, c\u27e9,\n  unfold f5 at h,\n  have := padic_val_nat_five_aux_ a b c,\n  rw h at this,\n  simpa using this,\nend\n\nlemma exercise06inj : injective f6 :=\nbegin\n  intros a b hab,\n  unfold f6 at hab,\n  revert hab,\n  apply quotient.induction_on\u2082 a b,\n  intros x y hab,\n  simp [s_def] at hab,\n  rw [quotient.eq, s_def],\n  convert int.modeq.sub_right 1 hab; simp,\nend\n\nlemma exercise06surj : surjective f6 :=\nbegin\n  intro y,\n  apply quotient.induction_on y,\n  clear y,\n  intro a,\n  use \u27e6a-1\u27e7,\n  unfold f6,\n  simp,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "m1fexplained_lean3", "sha": "570c9a3ff8cfc3805047f2796864516a49f51510", "save_path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3", "path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3/m1fexplained_lean3-570c9a3ff8cfc3805047f2796864516a49f51510/src/chapter19/exercises/exercise01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7257967745952562}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport data.zmod.basic\n\n/-\n\n# Prove that 19 \u2223 2^(2^(6k+2)) + 3 for k = 0,1,2,... \n\n\nThis is the fifth question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\nthoughts\n\nif a(k)=2^(2^(6k+2))\nthen a(k+1)=2^(2^6*2^(6k+2))=a(k)^64\n\nNote that 16^64 is 16 mod 19 according to a brute force calculation\nand so all of the a(k) are 16 mod 19 and we're done\n\n-/\n\nlemma sixteen_pow_sixtyfour_mod_nineteen : (16 : zmod 19)^64 = 16 :=\nbegin\n  refl,\nend\n\nexample (k : \u2115) : 19 \u2223 2^(2^(6*k+2))+3 :=\nbegin\n  induction k with d hd,\n  { refl },\n  have h : 2 ^ 2 ^ (6 * d.succ + 2) = (2 ^ 2 ^ (6 * d + 2)) ^ 64,\n  { ring_exp },\n  rw [\u2190 zmod.nat_coe_zmod_eq_zero_iff_dvd, nat.cast_add, add_eq_zero_iff_eq_neg] at hd \u22a2,\n  rw h,\n  rw nat.cast_pow,\n  rw hd,\n  convert sixteen_pow_sixtyfour_mod_nineteen,\nend\n\n\n\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section15number_theory/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7257967647286411}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport algebra.group.commute\nimport algebra.order.monoid.lemmas\nimport algebra.group_with_zero.basic\n\n/-!\n# Regular elements\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe introduce left-regular, right-regular and regular elements, along with their `to_additive`\nanalogues add-left-regular, add-right-regular and add-regular elements.\n\nBy definition, a regular element in a commutative ring is a non-zero divisor.\nLemma `is_regular_of_ne_zero` implies that every non-zero element of an integral domain is regular.\nSince it assumes that the ring is a `cancel_monoid_with_zero` it applies also, for instance, to `\u2115`.\n\nThe lemmas in Section `mul_zero_class` show that the `0` element is (left/right-)regular if and\nonly if the `mul_zero_class` is trivial.  This is useful when figuring out stopping conditions for\nregular sequences: if `0` is ever an element of a regular sequence, then we can extend the sequence\nby adding one further `0`.\n\nThe final goal is to develop part of the API to prove, eventually, results about non-zero-divisors.\n-/\nvariables {R : Type*}\n\nsection has_mul\n\nvariables [has_mul R]\n\n/-- A left-regular element is an element `c` such that multiplication on the left by `c`\nis injective. -/\n@[to_additive \"An add-left-regular element is an element `c` such that addition on the left by `c`\nis injective. -/\n\"]\ndef is_left_regular (c : R) := ((*) c).injective\n\n/-- A right-regular element is an element `c` such that multiplication on the right by `c`\nis injective. -/\n@[to_additive \"An add-right-regular element is an element `c` such that addition on the right by `c`\nis injective.\"]\ndef is_right_regular (c : R) := (* c).injective\n\n/-- An add-regular element is an element `c` such that addition by `c` both on the left and\non the right is injective. -/\nstructure is_add_regular {R : Type*} [has_add R] (c : R) : Prop :=\n(left : is_add_left_regular c)\n(right : is_add_right_regular c)\n\n/-- A regular element is an element `c` such that multiplication by `c` both on the left and\non the right is injective. -/\nstructure is_regular (c : R) : Prop :=\n(left : is_left_regular c)\n(right : is_right_regular c)\n\nattribute [to_additive] is_regular\n\n@[to_additive]\nprotected lemma mul_le_cancellable.is_left_regular [partial_order R] {a : R}\n  (ha : mul_le_cancellable a) : is_left_regular a :=\nha.injective\n\nlemma is_left_regular.right_of_commute {a : R} (ca : \u2200 b, commute a b)\n  (h : is_left_regular a) : is_right_regular a :=\n\u03bb x y xy, h $ (ca x).trans $ xy.trans $ (ca y).symm\n\nlemma commute.is_regular_iff {a : R} (ca : \u2200 b, commute a b) :\n  is_regular a \u2194 is_left_regular a :=\n\u27e8\u03bb h, h.left, \u03bb h, \u27e8h, h.right_of_commute ca\u27e9\u27e9\n\nend has_mul\n\nsection semigroup\n\nvariables [semigroup R] {a b : R}\n\n/-- In a semigroup, the product of left-regular elements is left-regular. -/\n@[to_additive \"In an additive semigroup, the sum of add-left-regular elements is add-left.regular.\"]\nlemma is_left_regular.mul (lra : is_left_regular a) (lrb : is_left_regular b) :\n  is_left_regular (a * b) :=\nshow function.injective ((*) (a * b)), from (comp_mul_left a b) \u25b8 lra.comp lrb\n\n/-- In a semigroup, the product of right-regular elements is right-regular. -/\n@[to_additive\n\"In an additive semigroup, the sum of add-right-regular elements is add-right-regular.\"]\nlemma is_right_regular.mul (rra : is_right_regular a) (rrb : is_right_regular b) :\n  is_right_regular (a * b) :=\nshow function.injective (* (a * b)), from (comp_mul_right b a) \u25b8 rrb.comp rra\n\n/--  If an element `b` becomes left-regular after multiplying it on the left by a left-regular\nelement, then `b` is left-regular. -/\n@[to_additive \"If an element `b` becomes add-left-regular after adding to it on the left a\nadd-left-regular element, then `b` is add-left-regular.\"]\nlemma is_left_regular.of_mul (ab : is_left_regular (a * b)) :\n  is_left_regular b :=\nfunction.injective.of_comp (by rwa comp_mul_left a b)\n\n/--  An element is left-regular if and only if multiplying it on the left by a left-regular element\nis left-regular. -/\n@[simp, to_additive \"An element is add-left-regular if and only if adding to it on the left a\nadd-left-regular element is add-left-regular.\"]\nlemma mul_is_left_regular_iff (b : R) (ha : is_left_regular a) :\n  is_left_regular (a * b) \u2194 is_left_regular b :=\n\u27e8\u03bb ab, is_left_regular.of_mul ab, \u03bb ab, is_left_regular.mul ha ab\u27e9\n\n/--  If an element `b` becomes right-regular after multiplying it on the right by a right-regular\nelement, then `b` is right-regular. -/\n@[to_additive \"If an element `b` becomes add-right-regular after adding to it on the right a\nadd-right-regular element, then `b` is add-right-regular.\"]\nlemma is_right_regular.of_mul (ab : is_right_regular (b * a)) :\n  is_right_regular b :=\nbegin\n  refine \u03bb x y xy, ab (_ : x * (b * a) = y * (b * a)),\n  rw [\u2190 mul_assoc, \u2190 mul_assoc],\n  exact congr_fun (congr_arg (*) xy) a,\nend\n\n/--  An element is right-regular if and only if multiplying it on the right with a right-regular\nelement is right-regular. -/\n@[simp, to_additive \"An element is add-right-regular if and only if adding it on the right to a\nadd-right-regular element is add-right-regular.\"]\nlemma mul_is_right_regular_iff (b : R) (ha : is_right_regular a) :\n  is_right_regular (b * a) \u2194 is_right_regular b :=\n\u27e8\u03bb ab, is_right_regular.of_mul ab, \u03bb ab, is_right_regular.mul ab ha\u27e9\n\n/--  Two elements `a` and `b` are regular if and only if both products `a * b` and `b * a`\nare regular. -/\n@[to_additive \"Two elements `a` and `b` are add-regular if and only if both sums `a + b` and `b + a`\nare add-regular.\"]\nlemma is_regular_mul_and_mul_iff :\n  is_regular (a * b) \u2227 is_regular (b * a) \u2194 is_regular a \u2227 is_regular b :=\nbegin\n  refine \u27e8_, _\u27e9,\n  { rintros \u27e8ab, ba\u27e9,\n    exact \u27e8\u27e8is_left_regular.of_mul ba.left, is_right_regular.of_mul ab.right\u27e9,\n      \u27e8is_left_regular.of_mul ab.left, is_right_regular.of_mul ba.right\u27e9\u27e9 },\n  { rintros \u27e8ha, hb\u27e9,\n    exact \u27e8\u27e8(mul_is_left_regular_iff _ ha.left).mpr hb.left,\n        (mul_is_right_regular_iff _ hb.right).mpr ha.right\u27e9,\n      \u27e8(mul_is_left_regular_iff _ hb.left).mpr ha.left,\n        (mul_is_right_regular_iff _ ha.right).mpr hb.right\u27e9\u27e9 }\nend\n\n/--  The \"most used\" implication of `mul_and_mul_iff`, with split hypotheses, instead of `\u2227`. -/\n@[to_additive \"The \\\"most used\\\" implication of `add_and_add_iff`, with split hypotheses,\ninstead of `\u2227`.\"]\nlemma is_regular.and_of_mul_of_mul (ab : is_regular (a * b)) (ba : is_regular (b * a)) :\n  is_regular a \u2227 is_regular b :=\nis_regular_mul_and_mul_iff.mp \u27e8ab, ba\u27e9\n\nend semigroup\n\nsection mul_zero_class\n\nvariables [mul_zero_class R] {a b : R}\n\n/--  The element `0` is left-regular if and only if `R` is trivial. -/\nlemma is_left_regular.subsingleton (h : is_left_regular (0 : R)) : subsingleton R :=\n\u27e8\u03bb a b, h $ eq.trans (zero_mul a) (zero_mul b).symm\u27e9\n\n/--  The element `0` is right-regular if and only if `R` is trivial. -/\nlemma is_right_regular.subsingleton (h : is_right_regular (0 : R)) : subsingleton R :=\n\u27e8\u03bb a b, h $ eq.trans (mul_zero a) (mul_zero b).symm\u27e9\n\n/--  The element `0` is regular if and only if `R` is trivial. -/\nlemma is_regular.subsingleton (h : is_regular (0 : R)) : subsingleton R :=\nh.left.subsingleton\n\n/--  The element `0` is left-regular if and only if `R` is trivial. -/\nlemma is_left_regular_zero_iff_subsingleton : is_left_regular (0 : R) \u2194 subsingleton R :=\n\u27e8\u03bb h, h.subsingleton, \u03bb H a b h, @subsingleton.elim _ H a b\u27e9\n\n/--  In a non-trivial `mul_zero_class`, the `0` element is not left-regular. -/\nlemma not_is_left_regular_zero_iff : \u00ac is_left_regular (0 : R) \u2194 nontrivial R :=\nbegin\n  rw [nontrivial_iff, not_iff_comm, is_left_regular_zero_iff_subsingleton, subsingleton_iff],\n  push_neg,\n  exact iff.rfl\nend\n\n/--  The element `0` is right-regular if and only if `R` is trivial. -/\nlemma is_right_regular_zero_iff_subsingleton : is_right_regular (0 : R) \u2194 subsingleton R :=\n\u27e8\u03bb h, h.subsingleton, \u03bb H a b h, @subsingleton.elim _ H a b\u27e9\n\n/--  In a non-trivial `mul_zero_class`, the `0` element is not right-regular. -/\nlemma not_is_right_regular_zero_iff : \u00ac is_right_regular (0 : R) \u2194 nontrivial R :=\nbegin\n  rw [nontrivial_iff, not_iff_comm, is_right_regular_zero_iff_subsingleton, subsingleton_iff],\n  push_neg,\n  exact iff.rfl\nend\n\n/--  The element `0` is regular if and only if `R` is trivial. -/\nlemma is_regular_iff_subsingleton : is_regular (0 : R) \u2194 subsingleton R :=\n\u27e8\u03bb h, h.left.subsingleton,\n \u03bb h, \u27e8is_left_regular_zero_iff_subsingleton.mpr h, is_right_regular_zero_iff_subsingleton.mpr h\u27e9\u27e9\n\n/-- A left-regular element of a `nontrivial` `mul_zero_class` is non-zero. -/\nlemma is_left_regular.ne_zero [nontrivial R] (la : is_left_regular a) : a \u2260 0 :=\nbegin\n  rintro rfl,\n  rcases exists_pair_ne R with \u27e8x, y, xy\u27e9,\n  refine xy (la _),\n  rw [zero_mul, zero_mul]\nend\n\n/-- A right-regular element of a `nontrivial` `mul_zero_class` is non-zero. -/\nlemma is_right_regular.ne_zero [nontrivial R] (ra : is_right_regular a) : a \u2260 0 :=\nbegin\n  rintro rfl,\n  rcases exists_pair_ne R with \u27e8x, y, xy\u27e9,\n  refine xy (ra (_ : x * 0 = y * 0)),\n  rw [mul_zero, mul_zero]\nend\n\n/-- A regular element of a `nontrivial` `mul_zero_class` is non-zero. -/\nlemma is_regular.ne_zero [nontrivial R] (la : is_regular a) : a \u2260 0 :=\nla.left.ne_zero\n\n/--  In a non-trivial ring, the element `0` is not left-regular -- with typeclasses. -/\nlemma not_is_left_regular_zero [nR : nontrivial R] : \u00ac is_left_regular (0 : R) :=\nnot_is_left_regular_zero_iff.mpr nR\n\n/--  In a non-trivial ring, the element `0` is not right-regular -- with typeclasses. -/\nlemma not_is_right_regular_zero [nR : nontrivial R] : \u00ac is_right_regular (0 : R) :=\nnot_is_right_regular_zero_iff.mpr nR\n\n/--  In a non-trivial ring, the element `0` is not regular -- with typeclasses. -/\nlemma not_is_regular_zero [nontrivial R] : \u00ac is_regular (0 : R) :=\n\u03bb h, is_regular.ne_zero h rfl\n\nend mul_zero_class\n\nsection mul_one_class\n\nvariable [mul_one_class R]\n\n/--  If multiplying by `1` on either side is the identity, `1` is regular. -/\n@[to_additive \"If adding `0` on either side is the identity, `0` is regular.\"]\nlemma is_regular_one : is_regular (1 : R) :=\n\u27e8\u03bb a b ab, (one_mul a).symm.trans (eq.trans ab (one_mul b)),\n  \u03bb a b ab, (mul_one a).symm.trans (eq.trans ab (mul_one b))\u27e9\n\nend mul_one_class\n\nsection comm_semigroup\n\nvariables [comm_semigroup R] {a b : R}\n\n/--  A product is regular if and only if the factors are. -/\n@[to_additive \"A sum is add-regular if and only if the summands are.\"]\nlemma is_regular_mul_iff : is_regular (a * b) \u2194 is_regular a \u2227 is_regular b :=\nbegin\n  refine iff.trans _ is_regular_mul_and_mul_iff,\n  refine \u27e8\u03bb ab, \u27e8ab, by rwa mul_comm\u27e9, \u03bb rab, rab.1\u27e9\nend\n\nend comm_semigroup\n\nsection monoid\n\nvariables [monoid R] {a b : R}\n\n/-- An element admitting a left inverse is left-regular. -/\n@[to_additive \"An element admitting a left additive opposite is add-left-regular.\"]\nlemma is_left_regular_of_mul_eq_one (h : b * a = 1) : is_left_regular a :=\n@is_left_regular.of_mul R _ _ _ (by { rw h, exact is_regular_one.left })\n\n/-- An element admitting a right inverse is right-regular. -/\n@[to_additive \"An element admitting a right additive opposite is add-right-regular.\"]\nlemma is_right_regular_of_mul_eq_one (h : a * b = 1) : is_right_regular a :=\nis_right_regular.of_mul (by { rw h, exact is_regular_one.right })\n\n/-- If `R` is a monoid, an element in `R\u02e3` is regular. -/\n@[to_additive \"If `R` is an additive monoid, an element in `add_units R` is add-regular.\"]\nlemma units.is_regular (a : R\u02e3) : is_regular (a : R) :=\n\u27e8is_left_regular_of_mul_eq_one a.inv_mul, is_right_regular_of_mul_eq_one a.mul_inv\u27e9\n\n/-- A unit in a monoid is regular. -/\n@[to_additive \"An additive unit in an additive monoid is add-regular.\"]\nlemma is_unit.is_regular (ua : is_unit a) : is_regular a :=\nbegin\n  rcases ua with \u27e8a, rfl\u27e9,\n  exact units.is_regular a,\nend\n\nend monoid\n\n/--  Elements of a left cancel semigroup are left regular. -/\n@[to_additive \"Elements of an add left cancel semigroup are add-left-regular.\"]\nlemma is_left_regular_of_left_cancel_semigroup [left_cancel_semigroup R] (g : R) :\n  is_left_regular g :=\nmul_right_injective g\n\n/--  Elements of a right cancel semigroup are right regular. -/\n@[to_additive \"Elements of an add right cancel semigroup are add-right-regular\"]\nlemma is_right_regular_of_right_cancel_semigroup [right_cancel_semigroup R] (g : R) :\n  is_right_regular g :=\nmul_left_injective g\n\nsection cancel_monoid\n\nvariables [cancel_monoid R]\n\n/--  Elements of a cancel monoid are regular.  Cancel semigroups do not appear to exist. -/\n@[to_additive\n\"Elements of an add cancel monoid are regular.  Add cancel semigroups do not appear to exist.\"]\nlemma is_regular_of_cancel_monoid (g : R) : is_regular g :=\n\u27e8mul_right_injective g, mul_left_injective g\u27e9\n\nend cancel_monoid\n\nsection cancel_monoid_with_zero\n\nvariables [cancel_monoid_with_zero R] {a : R}\n\n/--  Non-zero elements of an integral domain are regular. -/\nlemma is_regular_of_ne_zero (a0 : a \u2260 0) : is_regular a :=\n\u27e8\u03bb b c, (mul_right_inj' a0).mp, \u03bb b c, (mul_left_inj' a0).mp\u27e9\n\n/-- In a non-trivial integral domain, an element is regular iff it is non-zero. -/\nlemma is_regular_iff_ne_zero [nontrivial R] : is_regular a \u2194 a \u2260 0 :=\n\u27e8is_regular.ne_zero, is_regular_of_ne_zero\u27e9\n\nend cancel_monoid_with_zero\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/regular/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7257365058300291}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport data.real.basic -- imports the real numbers\nimport solutions.section02reals.sheet3 -- import the definition of `tends_to` from a previous sheet\n\n-- you can maybe do this one now\ntheorem tends_to_neg {a : \u2115 \u2192 \u211d} {t : \u211d} (ha : tends_to a t) :\n  tends_to (\u03bb n, - a n) (-t) :=\nbegin\n  sorry,\nend\n\n/-\n`tends_to_add` is quite a challenge. In a few weeks' time I'll\nshow you a two-line proof using filters, but right now\nas you're still learning I think it's important that you\ntry and suffer and struggle through the first principles proof.\nBIG piece of advice: write down a complete maths proof first,\nwith all the details there. Then, once you know the maths\nproof, try translating it into Lean. Note that a bunch\nof the results we proved in sheet 4 will be helpful. \n-/\n\n/-- If `a(n)` tends to `t` and `b(n)` tends to `u` then `a(n) + b(n)`\ntends to `t + u`. -/\ntheorem tends_to_add {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tends_to a t) (hb : tends_to b u) :\n  tends_to (\u03bb n, a n + b n) (t + u) :=\nbegin\n  sorry\nend\n\n/-- If `a(n)` tends to t and `b(n)` tends to `u` then `a(n) - b(n)`\ntends to `t - u`. -/\ntheorem tends_to_sub {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tends_to a t) (hb : tends_to b u) :\n  tends_to (\u03bb n, a n - b n) (t - u) :=\nbegin\n  -- this one follows without too much trouble from earlier results.\n  sorry\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section02reals/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.7257364972240975}}
{"text": "-- need access to many useful tactics\nimport tactic \n\n-- need injective functions\nopen function\n\n-- Let X, Y, Z be types and\n-- let f : X \u2192 Y and g : Y \u2192 Z be\n-- functions between these types\nvariables (X Y Z : Type)\n  (f : X \u2192 Y) (g : Y \u2192 Z)\n\n-- Theorem: if f and g are\n-- injective, then so is g \u2218 f.\ntheorem injective_comp :\n  injective f \u2227 injective g \u2192\n  injective (g \u2218 f) :=\nbegin\n  -- assume f and g are injective. \n  rintro \u27e8f_inj, g_inj\u27e9,\n  -- We want to prove g \u2218 f is\n  -- injective. So say a,b \u2208 X and\n  -- assume g(f(a))=g(f(b)).\n  intros a b hgf,\n  -- We want to prove that a = b. By\n  -- injectivity of f, it suffices to\n  -- prove that f(a)=f(b).\n  apply f_inj,\n  -- By injectivity of g, it suffices\n  -- to prove g(f(a))=g(f(b)).\n  apply g_inj,\n  -- But this is an assumption.\n  assumption,\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/src/Notices_AMS/injective_comp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7853085733507946, "lm_q1q2_score": 0.7257364958620328}}
{"text": "-- Razonamiento con tipos enumerados: Movimientos\n-- ==============================================\n\nimport tactic\n\n-- ----------------------------------------------------\n-- Nota. Usaremos los tipo Pos (como una abreviatura\n-- de pares de enteros para representar posiciones) y\n-- Direccion (como un tipo enumerado con las cuatro\n-- direcciones) y la funci\u00f3n opuesta, definidas\n-- anteriormente\n-- ----------------------------------------------------\n\ndef Pos : Type := \u2124 \u00d7 \u2124\n\ninductive Direccion : Type\n| Izquierda : Direccion\n| Derecha   : Direccion\n| Arriba    : Direccion\n| Abajo     : Direccion\n\nnamespace Direccion\n\n@[simp]\ndef opuesta : Direccion \u2192 Direccion\n| Izquierda := Derecha\n| Derecha   := Izquierda\n| Arriba    := Abajo\n| Abajo     := Arriba\n\n-- ----------------------------------------------------\n-- Ejercicio ?. Definir la funci\u00f3n\n--    movimiento : Direccion \u2192 Pos \u2192 Pos\n-- tal que (movimiento d p) es la posici\u00f3n alcanzada\n-- al dar un paso en la direcci\u00f3n d a partir de la\n-- posici\u00f3n p. Por ejemplo,\n--    movimiento Arriba (2,5) = (2, 6)\n-- ----------------------------------------------------\n\n@[simp]\ndef movimiento : Direccion \u2192 Pos \u2192 Pos\n| Izquierda (x,y) := (x-1,y)\n| Derecha   (x,y) := (x+1,y)\n| Arriba    (x,y) := (x,y+1)\n| Abajo     (x,y) := (x,y-1)\n\n-- #eval movimiento Arriba (2,5)\n-- Da: (2, 6)\n\n-- ----------------------------------------------------\n-- Ejercicio ?. Definir la funci\u00f3n\n--    movimientos : list Direccion \u2192 Pos \u2192 Pos\n-- tal que (movimientos ms p) es la posici\u00f3n obtenida\n-- aplicando la lista de movimientos ms a la posici\u00f3n\n-- p. Por ejemplo,\n--    movimientos [Arriba, Izquierda] (2,5) = (1,6)\n-- ----------------------------------------------------\n\ndef movimientos : list Direccion \u2192 Pos \u2192 Pos\n| []        p := p\n| (m :: ms) p := movimientos ms (movimiento m p)\n\n-- #eval movimientos [Arriba, Izquierda] (2,5)\n-- Da:  (1,6)\n\n-- ----------------------------------------------------\n-- Ejercicio ?. Demostrar que para cada direcci\u00f3n d\n-- existe una direcci\u00f3n d' tal que para toda posici\u00f3n p,\n--    movimiento d' (movimiento d p) = p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\nbegin\n  intro d,\n  use opuesta d,\n  rintro \u27e8x,y\u27e9,\n  cases d,\n  { calc movimiento (opuesta Izquierda) (movimiento Izquierda (x,y))\n         = movimiento (opuesta Izquierda) (x-1,y)       :by simp [movimiento]\n     ... = movimiento Derecha (x-1,y)                   :by simp [opuesta]\n     ... = (x-1+1,y)                                    :by simp [movimiento]\n     ... = (x,y)                                        :by simp },\n  { calc movimiento (opuesta Derecha) (movimiento Derecha (x,y))\n         = movimiento (opuesta Derecha) (x+1,y)         :by simp [movimiento]\n     ... = movimiento Izquierda (x+1,y)                 :by simp [opuesta]\n     ... = (x+1-1,y)                                    :by simp [movimiento]\n     ... = (x,y)                                        :by simp },\n  { calc movimiento (opuesta Arriba) (movimiento Arriba (x,y))\n         = movimiento (opuesta Arriba) (x,y+1)          :by simp [movimiento]\n     ... = movimiento Abajo (x,y+1)                     :by simp [opuesta]\n     ... = (x,y+1-1)                                    :by simp [movimiento]\n     ... = (x,y)                                        :by simp },\n  { calc movimiento (opuesta Abajo) (movimiento Abajo (x,y))\n         = movimiento (opuesta Abajo) (x,y-1)           :by simp [movimiento]\n     ... = movimiento Arriba (x,y-1)                    :by simp [opuesta]\n     ... = (x,y-1+1)                                    :by simp [movimiento]\n     ... = (x,y)                                        :by simp },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\nbegin\n  intro d,\n  use opuesta d,\n  rintro \u27e8x,y\u27e9,\n  cases d,\n  { calc movimiento (opuesta Izquierda) (movimiento Izquierda (x,y))\n         = movimiento (opuesta Izquierda) (x-1,y)       :by simp\n     ... = movimiento Derecha (x-1,y)                   :by simp\n     ... = (x-1+1,y)                                    :by simp\n     ... = (x,y)                                        :by simp },\n  { calc movimiento (opuesta Derecha) (movimiento Derecha (x,y))\n         = movimiento (opuesta Derecha) (x+1,y)         :by simp\n     ... = movimiento Izquierda (x+1,y)                 :by simp\n     ... = (x+1-1,y)                                    :by simp\n     ... = (x,y)                                        :by simp },\n  { calc movimiento (opuesta Arriba) (movimiento Arriba (x,y))\n         = movimiento (opuesta Arriba) (x,y+1)          :by simp\n     ... = movimiento Abajo (x,y+1)                     :by simp\n     ... = (x,y+1-1)                                    :by simp\n     ... = (x,y)                                        :by simp },\n  { calc movimiento (opuesta Abajo) (movimiento Abajo (x,y))\n         = movimiento (opuesta Abajo) (x,y-1)           :by simp\n     ... = movimiento Arriba (x,y-1)                    :by simp\n     ... = (x,y-1+1)                                    :by simp\n     ... = (x,y)                                        :by simp },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\nbegin\n  intro d,\n  use opuesta d,\n  rintro \u27e8x,y\u27e9,\n  cases d,\n  { simp, },\n  { simp, },\n  { simp, },\n  { simp, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\nbegin\n  intro d,\n  use opuesta d,\n  rintro \u27e8x,y\u27e9,\n  cases d ;\n  simp,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\nassume d,\nexists.intro (opuesta d)\n  (assume \u27e8x,y\u27e9,\n   show movimiento (opuesta d) (movimiento d (x,y)) = (x,y), from\n     Direccion.cases_on d\n       (calc movimiento (opuesta Izquierda) (movimiento Izquierda (x,y))\n             = movimiento (opuesta Izquierda) (x-1,y)       :by simp\n         ... = movimiento Derecha (x-1,y)                   :by simp\n         ... = (x-1+1,y)                                    :by simp\n         ... = (x,y)                                        :by simp)\n       (calc movimiento (opuesta Derecha) (movimiento Derecha (x,y))\n             = movimiento (opuesta Derecha) (x+1,y)         :by simp\n         ... = movimiento Izquierda (x+1,y)                 :by simp\n         ... = (x+1-1,y)                                    :by simp\n         ... = (x,y)                                        :by simp )\n       (calc movimiento (opuesta Arriba) (movimiento Arriba (x,y))\n             = movimiento (opuesta Arriba) (x,y+1)          :by simp\n         ... = movimiento Abajo (x,y+1)                     :by simp\n         ... = (x,y+1-1)                                    :by simp\n         ... = (x,y)                                        :by simp)\n       (calc movimiento (opuesta Abajo) (movimiento Abajo (x,y))\n             = movimiento (opuesta Abajo) (x,y-1)           :by simp\n         ... = movimiento Arriba (x,y-1)                    :by simp\n         ... = (x,y-1+1)                                    :by simp\n         ... = (x,y)                                        :by simp))\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\nassume d,\nexists.intro (opuesta d)\n  (assume \u27e8x,y\u27e9,\n   show movimiento (opuesta d) (movimiento d (x,y)) = (x,y), from\n     Direccion.cases_on d\n       (by simp)\n       (by simp)\n       (by simp)\n       (by simp))\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\nassume d,\nexists.intro (opuesta d)\n  (\u03bb \u27e8x,y\u27e9, Direccion.cases_on d (by simp) (by simp) (by simp) (by simp))\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  \u2200 d, \u2203 d', \u2200 p, movimiento d' (movimiento d p) = p :=\n\u03bb d, exists.intro (opuesta d)\n       (\u03bb \u27e8x,y\u27e9, Direccion.cases_on d (by simp) (by simp) (by simp) (by simp))\n\nend Direccion\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/8_Inductivos/Razonamiento_con_tipos_enumerados:_Movimientos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.7853085783754369, "lm_q1q2_score": 0.7257364939426797}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport solutions.section14polynomials.sheet04more_aux_ideal\n\n/-\n\nRecall that we know `aux_ideal I n` is an increasing function of `n`.\nIn this file we define `aux_ideal2 I` to be the union over all `n`\nof `aux_ideal I n`. Note that it is an ideal of `R`, so if `R` is\nNoetherian then it's going to be finitely-generated. This is a key\ningredient im the proof.\n\n-/\n\nvariables {R : Type} [comm_ring R] (I : ideal (polynomial R))\n\nopen polynomial\n\n/-\n\nRecall the key API for `\u22c3` is `set.mem_Union`\n-/\n\n/-- An auxiliary ideal used in the proof of Hilbert's Basis Theorem.\nIt's equal to the elements of `R` which are either 0, or the\nleading coefficient of an element of `I`. Showing that this is an\nideal is made much easier by the fact that it can also be thought\nof as a union of the increasing sequence of ideals `aux_ideal I n`. -/\ndef aux_ideal2 (I : ideal (polynomial R)) : ideal R :=\n{ carrier := \u22c3 n, aux_ideal I n,\n  zero_mem' := begin\n    rw set.mem_Union,\n    use 37,\n    exact ideal.zero_mem (aux_ideal I 37),\n  end,\n  add_mem' := begin\n    intros f g hf hg,\n    rw set.mem_Union at hf hg \u22a2,\n    rcases hf with \u27e8a, ha\u27e9,\n    rcases hg with \u27e8b, hb\u27e9,\n    use max a b,\n    apply (aux_ideal I (max a b)).add_mem,\n    { exact aux_ideal.mono _ (le_max_left a b) ha },\n    { exact aux_ideal.mono _ (le_max_right a b) hb },\n  end,\n  smul_mem' := begin\n    intros r f hf,\n    rw set.mem_Union at hf \u22a2,\n    cases hf with i hi,\n    use i,\n    refine submodule.smul_mem (aux_ideal I i) r hi, \n  end }\n\nnamespace aux_ideal2\n\n-- we make some helpful API.\n\nlemma mem (I : ideal (polynomial R)) (j : R) (hj : j \u2208 aux_ideal2 I) :\n  \u2203 m, j \u2208 aux_ideal I m :=\nset.mem_Union.1 hj\n\nlemma mem_iff (I : ideal (polynomial R)) (j : R) :\n j \u2208 aux_ideal2 I \u2194 \u2203 m, j \u2208 aux_ideal I m :=\nset.mem_Union\n\n/-\n\nAssume `R` is Noetherian. Because `aux_ideal2 I` is finitely-generated,\nthe increasing chain of ideals `aux_ideal I 0 \u2264 aux_ideal I 1 \u2264 aux_ideal I 2 \u2264 ...`\nmust stabilise. \n\nHelpful API: `finset.sup`. Don't forget to use the `classical` tactic\nif you run into decidability issues.\n\n-/\nlemma canonical_N (hR : is_noetherian_ring R) : \n  \u2203 N, \u2200 m, N \u2264 m \u2192 aux_ideal2 I = aux_ideal I m :=\nbegin\n  -- Q -- can this be done with `is_noetherian_iff_well_founded`?\n  obtain \u27e8S, hS\u27e9 := (is_noetherian_ring_iff_ideal_fg R).1 hR (aux_ideal2 I),\n  have hSmem : \u2200 r : R, r \u2208 S \u2192 r \u2208 aux_ideal2 I,\n  { rw \u2190 hS, intros r hr, exact ideal.subset_span hr },\n  choose g hg using mem I,\n  classical,\n  use finset.sup S (\u03bb r, if hr : r \u2208 aux_ideal2 I then g r hr else 37),\n  intros m hm,\n  apply le_antisymm,\n  { rw \u2190 hS,\n    rw ideal.span_le,\n    intros r hrS,\n    rw finset.sup_le_iff at hm,\n    specialize hm r hrS,\n    have hraux := hSmem _ hrS,\n    rw dif_pos hraux at hm,\n    apply aux_ideal.mono I hm,\n    apply hg },\n  { intros r hr,\n    rw mem_iff,\n    use m,\n    assumption },\nend\n\nend aux_ideal2", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/solutions/section14polynomials/sheet05aux_ideal2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461006, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7257341917518737}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro\n-/\nimport algebra.associated\nimport linear_algebra.basic\nimport order.zorn\nimport order.atoms\nimport order.compactly_generated\nimport tactic.abel\nimport data.nat.choose.sum\nimport linear_algebra.finsupp\n/-!\n\n# Ideals over a ring\n\nThis file defines `ideal R`, the type of ideals over a commutative ring `R`.\n\n## Implementation notes\n\n`ideal R` is implemented using `submodule R R`, where `\u2022` is interpreted as `*`.\n\n## TODO\n\nSupport one-sided ideals, and ideals over non-commutative rings.\n-/\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\nopen set function\n\nopen_locale classical big_operators pointwise\n\n/-- A (left) ideal in a semiring `R` is an additive submonoid `s` such that\n`a * b \u2208 s` whenever `b \u2208 s`. If `R` is a ring, then `s` is an additive subgroup.  -/\n@[reducible] def ideal (R : Type u) [semiring R] := submodule R R\n\nsection semiring\n\nnamespace ideal\nvariables [semiring \u03b1] (I : ideal \u03b1) {a b : \u03b1}\n\nprotected lemma zero_mem : (0 : \u03b1) \u2208 I := I.zero_mem\n\nprotected lemma add_mem : a \u2208 I \u2192 b \u2208 I \u2192 a + b \u2208 I := I.add_mem\n\nvariables (a)\nlemma mul_mem_left : b \u2208 I \u2192 a * b \u2208 I := I.smul_mem a\nvariables {a}\n\n@[ext] lemma ext {I J : ideal \u03b1} (h : \u2200 x, x \u2208 I \u2194 x \u2208 J) : I = J :=\nsubmodule.ext h\n\nlemma sum_mem (I : ideal \u03b1) {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 \u03b1} :\n  (\u2200c\u2208t, f c \u2208 I) \u2192 (\u2211 i in t, f i) \u2208 I := submodule.sum_mem I\n\ntheorem eq_top_of_unit_mem\n  (x y : \u03b1) (hx : x \u2208 I) (h : y * x = 1) : I = \u22a4 :=\neq_top_iff.2 $ \u03bb z _, calc\n    z = z * (y * x) : by simp [h]\n  ... = (z * y) * x : eq.symm $ mul_assoc z y x\n  ... \u2208 I : I.mul_mem_left _ hx\n\ntheorem eq_top_of_is_unit_mem {x} (hx : x \u2208 I) (h : is_unit x) : I = \u22a4 :=\nlet \u27e8y, hy\u27e9 := h.exists_left_inv in eq_top_of_unit_mem I x y hx hy\n\ntheorem eq_top_iff_one : I = \u22a4 \u2194 (1:\u03b1) \u2208 I :=\n\u27e8by rintro rfl; trivial,\n \u03bb h, eq_top_of_unit_mem _ _ 1 h (by simp)\u27e9\n\ntheorem ne_top_iff_one : I \u2260 \u22a4 \u2194 (1:\u03b1) \u2209 I :=\nnot_congr I.eq_top_iff_one\n\n@[simp]\ntheorem unit_mul_mem_iff_mem {x y : \u03b1} (hy : is_unit y) : y * x \u2208 I \u2194 x \u2208 I :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, I.mul_mem_left y h\u27e9,\n  obtain \u27e8y', hy'\u27e9 := hy.exists_left_inv,\n  have := I.mul_mem_left y' h,\n  rwa [\u2190 mul_assoc, hy', one_mul] at this,\nend\n\n/-- The ideal generated by a subset of a ring -/\ndef span (s : set \u03b1) : ideal \u03b1 := submodule.span \u03b1 s\n\n@[simp] lemma submodule_span_eq {s : set \u03b1} :\n  submodule.span \u03b1 s = ideal.span s :=\nrfl\n\n@[simp] lemma span_empty : span (\u2205 : set \u03b1) = \u22a5 := submodule.span_empty\n\n@[simp] lemma span_univ : span (set.univ : set \u03b1) = \u22a4 := submodule.span_univ\n\nlemma span_union (s t : set \u03b1) : span (s \u222a t) = span s \u2294 span t :=\nsubmodule.span_union _ _\n\nlemma span_Union {\u03b9} (s : \u03b9 \u2192 set \u03b1) : span (\u22c3 i, s i) = \u2a06 i, span (s i) :=\nsubmodule.span_Union _\n\nlemma mem_span {s : set \u03b1} (x) : x \u2208 span s \u2194 \u2200 p : ideal \u03b1, s \u2286 p \u2192 x \u2208 p :=\nmem_Inter\u2082\n\nlemma subset_span {s : set \u03b1} : s \u2286 span s := submodule.subset_span\n\nlemma span_le {s : set \u03b1} {I} : span s \u2264 I \u2194 s \u2286 I := submodule.span_le\n\nlemma span_mono {s t : set \u03b1} : s \u2286 t \u2192 span s \u2264 span t := submodule.span_mono\n\n@[simp] lemma span_eq : span (I : set \u03b1) = I := submodule.span_eq _\n\n@[simp] lemma span_singleton_one : span ({1} : set \u03b1) = \u22a4 :=\n(eq_top_iff_one _).2 $ subset_span $ mem_singleton _\n\nlemma mem_span_insert {s : set \u03b1} {x y} :\n  x \u2208 span (insert y s) \u2194 \u2203 a (z \u2208 span s), x = a * y + z := submodule.mem_span_insert\n\nlemma mem_span_singleton' {x y : \u03b1} :\n  x \u2208 span ({y} : set \u03b1) \u2194 \u2203 a, a * y = x := submodule.mem_span_singleton\n\nlemma span_insert (x) (s : set \u03b1) : span (insert x s) = span ({x} : set \u03b1) \u2294 span s :=\nsubmodule.span_insert x s\n\nlemma span_eq_bot {s : set \u03b1} : span s = \u22a5 \u2194 \u2200 x \u2208 s, (x:\u03b1) = 0 := submodule.span_eq_bot\n\n@[simp] lemma span_singleton_eq_bot {x} : span ({x} : set \u03b1) = \u22a5 \u2194 x = 0 :=\nsubmodule.span_singleton_eq_bot\n\n@[simp] lemma span_zero : span (0 : set \u03b1) = \u22a5 := by rw [\u2190set.singleton_zero, span_singleton_eq_bot]\n\n@[simp] lemma span_one : span (1 : set \u03b1) = \u22a4 := by rw [\u2190set.singleton_one, span_singleton_one]\n\nlemma span_eq_top_iff_finite (s : set \u03b1) :\n  span s = \u22a4 \u2194 \u2203 s' : finset \u03b1, \u2191s' \u2286 s \u2227 span (s' : set \u03b1) = \u22a4 :=\nbegin\n  simp_rw eq_top_iff_one,\n  exact \u27e8submodule.mem_span_finite_of_mem_span, \u03bb \u27e8s', h\u2081, h\u2082\u27e9, span_mono h\u2081 h\u2082\u27e9\nend\n\n/--\nThe ideal generated by an arbitrary binary relation.\n-/\ndef of_rel (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : ideal \u03b1 :=\nsubmodule.span \u03b1 { x | \u2203 (a b) (h : r a b), x + b = a }\n\n/-- An ideal `P` of a ring `R` is prime if `P \u2260 R` and `xy \u2208 P \u2192 x \u2208 P \u2228 y \u2208 P` -/\nclass is_prime (I : ideal \u03b1) : Prop :=\n(ne_top' : I \u2260 \u22a4)\n(mem_or_mem' : \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I)\n\ntheorem is_prime_iff {I : ideal \u03b1} :\n  is_prime I \u2194 I \u2260 \u22a4 \u2227 \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I :=\n\u27e8\u03bb h, \u27e8h.1, h.2\u27e9, \u03bb h, \u27e8h.1, h.2\u27e9\u27e9\n\ntheorem is_prime.ne_top {I : ideal \u03b1} (hI : I.is_prime) : I \u2260 \u22a4 := hI.1\n\ntheorem is_prime.mem_or_mem {I : ideal \u03b1} (hI : I.is_prime) :\n  \u2200 {x y : \u03b1}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I := hI.2\n\ntheorem is_prime.mem_or_mem_of_mul_eq_zero {I : ideal \u03b1} (hI : I.is_prime)\n  {x y : \u03b1} (h : x * y = 0) : x \u2208 I \u2228 y \u2208 I :=\nhI.mem_or_mem (h.symm \u25b8 I.zero_mem)\n\ntheorem is_prime.mem_of_pow_mem {I : ideal \u03b1} (hI : I.is_prime)\n  {r : \u03b1} (n : \u2115) (H : r^n \u2208 I) : r \u2208 I :=\nbegin\n  induction n with n ih,\n  { rw pow_zero at H, exact (mt (eq_top_iff_one _).2 hI.1).elim H },\n  { rw pow_succ at H, exact or.cases_on (hI.mem_or_mem H) id ih }\nend\n\nlemma not_is_prime_iff {I : ideal \u03b1} : \u00ac I.is_prime \u2194 I = \u22a4 \u2228 \u2203 (x \u2209 I) (y \u2209 I), x * y \u2208 I :=\nbegin\n  simp_rw [ideal.is_prime_iff, not_and_distrib, ne.def, not_not, not_forall, not_or_distrib],\n  exact or_congr iff.rfl\n    \u27e8\u03bb \u27e8x, y, hxy, hx, hy\u27e9, \u27e8x, hx, y, hy, hxy\u27e9, \u03bb \u27e8x, hx, y, hy, hxy\u27e9, \u27e8x, y, hxy, hx, hy\u27e9\u27e9\nend\n\ntheorem zero_ne_one_of_proper {I : ideal \u03b1} (h : I \u2260 \u22a4) : (0:\u03b1) \u2260 1 :=\n\u03bb hz, I.ne_top_iff_one.1 h $ hz \u25b8 I.zero_mem\n\nlemma bot_prime {R : Type*} [ring R] [is_domain R] : (\u22a5 : ideal R).is_prime :=\n\u27e8\u03bb h, one_ne_zero (by rwa [ideal.eq_top_iff_one, submodule.mem_bot] at h),\n \u03bb x y h, mul_eq_zero.mp (by simpa only [submodule.mem_bot] using h)\u27e9\n\n/-- An ideal is maximal if it is maximal in the collection of proper ideals. -/\nclass is_maximal (I : ideal \u03b1) : Prop := (out : is_coatom I)\n\ntheorem is_maximal_def {I : ideal \u03b1} : I.is_maximal \u2194 is_coatom I := \u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\ntheorem is_maximal.ne_top {I : ideal \u03b1} (h : I.is_maximal) : I \u2260 \u22a4 := (is_maximal_def.1 h).1\n\ntheorem is_maximal_iff {I : ideal \u03b1} : I.is_maximal \u2194\n  (1:\u03b1) \u2209 I \u2227 \u2200 (J : ideal \u03b1) x, I \u2264 J \u2192 x \u2209 I \u2192 x \u2208 J \u2192 (1:\u03b1) \u2208 J :=\nis_maximal_def.trans $ and_congr I.ne_top_iff_one $ forall_congr $ \u03bb J,\nby rw [lt_iff_le_not_le]; exact\n \u27e8\u03bb H x h hx\u2081 hx\u2082, J.eq_top_iff_one.1 $\n    H \u27e8h, not_subset.2 \u27e8_, hx\u2082, hx\u2081\u27e9\u27e9,\n  \u03bb H \u27e8h\u2081, h\u2082\u27e9, let \u27e8x, xJ, xI\u27e9 := not_subset.1 h\u2082 in\n   J.eq_top_iff_one.2 $ H x h\u2081 xI xJ\u27e9\n\ntheorem is_maximal.eq_of_le {I J : ideal \u03b1}\n  (hI : I.is_maximal) (hJ : J \u2260 \u22a4) (IJ : I \u2264 J) : I = J :=\neq_iff_le_not_lt.2 \u27e8IJ, \u03bb h, hJ (hI.1.2 _ h)\u27e9\n\ninstance : is_coatomic (ideal \u03b1) :=\nbegin\n  apply complete_lattice.coatomic_of_top_compact,\n  rw \u2190span_singleton_one,\n  exact submodule.singleton_span_is_compact_element 1,\nend\n\n/-- **Krull's theorem**: if `I` is an ideal that is not the whole ring, then it is included in some\n    maximal ideal. -/\ntheorem exists_le_maximal (I : ideal \u03b1) (hI : I \u2260 \u22a4) :\n  \u2203 M : ideal \u03b1, M.is_maximal \u2227 I \u2264 M :=\nlet \u27e8m, hm\u27e9 := (eq_top_or_exists_le_coatom I).resolve_left hI in \u27e8m, \u27e8\u27e8hm.1\u27e9, hm.2\u27e9\u27e9\n\nvariables (\u03b1)\n\n/-- Krull's theorem: a nontrivial ring has a maximal ideal. -/\ntheorem exists_maximal [nontrivial \u03b1] : \u2203 M : ideal \u03b1, M.is_maximal :=\nlet \u27e8I, \u27e8hI, _\u27e9\u27e9 := exists_le_maximal (\u22a5 : ideal \u03b1) bot_ne_top in \u27e8I, hI\u27e9\n\nvariables {\u03b1}\n\ninstance [nontrivial \u03b1] : nontrivial (ideal \u03b1) :=\nbegin\n  rcases @exists_maximal \u03b1 _ _ with \u27e8M, hM, _\u27e9,\n  exact nontrivial_of_ne M \u22a4 hM\nend\n\n/-- If P is not properly contained in any maximal ideal then it is not properly contained\n  in any proper ideal -/\nlemma maximal_of_no_maximal {R : Type u} [comm_semiring R] {P : ideal R}\n(hmax : \u2200 m : ideal R, P < m \u2192 \u00acis_maximal m) (J : ideal R) (hPJ : P < J) : J = \u22a4 :=\nbegin\n  by_contradiction hnonmax,\n  rcases exists_le_maximal J hnonmax with \u27e8M, hM1, hM2\u27e9,\n  exact hmax M (lt_of_lt_of_le hPJ hM2) hM1,\nend\n\ntheorem mem_span_pair {x y z : \u03b1} :\n  z \u2208 span ({x, y} : set \u03b1) \u2194 \u2203 a b, a * x + b * y = z :=\nby simp [mem_span_insert, mem_span_singleton', @eq_comm _ _ z]\n\ntheorem is_maximal.exists_inv {I : ideal \u03b1}\n  (hI : I.is_maximal) {x} (hx : x \u2209 I) : \u2203 y, \u2203 i \u2208 I, y * x + i = 1 :=\nbegin\n  cases is_maximal_iff.1 hI with H\u2081 H\u2082,\n  rcases mem_span_insert.1 (H\u2082 (span (insert x I)) x\n    (set.subset.trans (subset_insert _ _) subset_span)\n    hx (subset_span (mem_insert _ _))) with \u27e8y, z, hz, hy\u27e9,\n  refine \u27e8y, z, _, hy.symm\u27e9,\n  rwa \u2190 span_eq I,\nend\n\nsection lattice\nvariables {R : Type u} [semiring R]\n\nlemma mem_sup_left {S T : ideal R} : \u2200 {x : R}, x \u2208 S \u2192 x \u2208 S \u2294 T :=\nshow S \u2264 S \u2294 T, from le_sup_left\n\nlemma mem_sup_right {S T : ideal R} : \u2200 {x : R}, x \u2208 T \u2192 x \u2208 S \u2294 T :=\nshow T \u2264 S \u2294 T, from le_sup_right\n\n\n\nlemma mem_Sup_of_mem {S : set (ideal R)} {s : ideal R}\n  (hs : s \u2208 S) : \u2200 {x : R}, x \u2208 s \u2192 x \u2208 Sup S :=\nshow s \u2264 Sup S, from le_Sup hs\n\ntheorem mem_Inf {s : set (ideal R)} {x : R} :\n  x \u2208 Inf s \u2194 \u2200 \u2983I\u2984, I \u2208 s \u2192 x \u2208 I :=\n\u27e8\u03bb hx I his, hx I \u27e8I, infi_pos his\u27e9, \u03bb H I \u27e8J, hij\u27e9, hij \u25b8 \u03bb S \u27e8hj, hS\u27e9, hS \u25b8 H hj\u27e9\n\n@[simp] lemma mem_inf {I J : ideal R} {x : R} : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J := iff.rfl\n\n@[simp] lemma mem_infi {\u03b9 : Sort*} {I : \u03b9 \u2192 ideal R} {x : R} : x \u2208 infi I \u2194 \u2200 i, x \u2208 I i :=\nsubmodule.mem_infi _\n\n@[simp] lemma mem_bot {x : R} : x \u2208 (\u22a5 : ideal R) \u2194 x = 0 :=\nsubmodule.mem_bot _\n\nend lattice\n\nsection pi\nvariables (\u03b9 : Type v)\n\n/-- `I^n` as an ideal of `R^n`. -/\ndef pi : ideal (\u03b9 \u2192 \u03b1) :=\n{ carrier := { x | \u2200 i, x i \u2208 I },\n  zero_mem' := \u03bb i, I.zero_mem,\n  add_mem' := \u03bb a b ha hb i, I.add_mem (ha i) (hb i),\n  smul_mem' := \u03bb a b hb i, I.mul_mem_left (a i) (hb i) }\n\nlemma mem_pi (x : \u03b9 \u2192 \u03b1) : x \u2208 I.pi \u03b9 \u2194 \u2200 i, x i \u2208 I := iff.rfl\n\nend pi\n\nend ideal\n\nend semiring\n\nsection comm_semiring\n\nvariables {a b : \u03b1}\n\n-- A separate namespace definition is needed because the variables were historically in a different\n-- order.\nnamespace ideal\nvariables [comm_semiring \u03b1] (I : ideal \u03b1)\n\n@[simp]\ntheorem mul_unit_mem_iff_mem {x y : \u03b1} (hy : is_unit y) : x * y \u2208 I \u2194 x \u2208 I :=\nmul_comm y x \u25b8 unit_mul_mem_iff_mem I hy\n\nlemma mem_span_singleton {x y : \u03b1} :\n  x \u2208 span ({y} : set \u03b1) \u2194 y \u2223 x :=\nmem_span_singleton'.trans $ exists_congr $ \u03bb _, by rw [eq_comm, mul_comm]\n\nlemma span_singleton_le_span_singleton {x y : \u03b1} :\n  span ({x} : set \u03b1) \u2264 span ({y} : set \u03b1) \u2194 y \u2223 x :=\nspan_le.trans $ singleton_subset_iff.trans mem_span_singleton\n\nlemma span_singleton_eq_span_singleton {\u03b1 : Type u} [comm_ring \u03b1] [is_domain \u03b1] {x y : \u03b1} :\n  span ({x} : set \u03b1) = span ({y} : set \u03b1) \u2194 associated x y :=\nbegin\n  rw [\u2190dvd_dvd_iff_associated, le_antisymm_iff, and_comm],\n  apply and_congr;\n  rw span_singleton_le_span_singleton,\nend\n\nlemma span_singleton_mul_right_unit {a : \u03b1} (h2 : is_unit a) (x : \u03b1) :\n  span ({x * a} : set \u03b1) = span {x} :=\nbegin\n  apply le_antisymm,\n  { rw span_singleton_le_span_singleton, use a},\n  { rw span_singleton_le_span_singleton, rw is_unit.mul_right_dvd h2}\nend\n\nlemma span_singleton_mul_left_unit {a : \u03b1} (h2 : is_unit a) (x : \u03b1) :\n  span ({a * x} : set \u03b1) = span {x} := by rw [mul_comm, span_singleton_mul_right_unit h2]\n\nlemma span_singleton_eq_top {x} : span ({x} : set \u03b1) = \u22a4 \u2194 is_unit x :=\nby rw [is_unit_iff_dvd_one, \u2190 span_singleton_le_span_singleton, span_singleton_one,\n  eq_top_iff]\n\ntheorem span_singleton_prime {p : \u03b1} (hp : p \u2260 0) :\n  is_prime (span ({p} : set \u03b1)) \u2194 prime p :=\nby simp [is_prime_iff, prime, span_singleton_eq_top, hp, mem_span_singleton]\n\ntheorem is_maximal.is_prime {I : ideal \u03b1} (H : I.is_maximal) : I.is_prime :=\n\u27e8H.1.1, \u03bb x y hxy, or_iff_not_imp_left.2 $ \u03bb hx, begin\n  let J : ideal \u03b1 := submodule.span \u03b1 (insert x \u2191I),\n  have IJ : I \u2264 J  := (set.subset.trans (subset_insert _ _) subset_span),\n  have xJ : x \u2208 J := ideal.subset_span (set.mem_insert x I),\n  cases is_maximal_iff.1 H with _ oJ,\n  specialize oJ J x IJ hx xJ,\n  rcases submodule.mem_span_insert.mp oJ with \u27e8a, b, h, oe\u27e9,\n  obtain (F : y * 1 = y * (a \u2022 x + b)) := congr_arg (\u03bb g : \u03b1, y * g) oe,\n  rw [\u2190 mul_one y, F, mul_add, mul_comm, smul_eq_mul, mul_assoc],\n  refine submodule.add_mem I (I.mul_mem_left a hxy) (submodule.smul_mem I y _),\n  rwa submodule.span_eq at h,\nend\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_maximal.is_prime' (I : ideal \u03b1) : \u2200 [H : I.is_maximal], I.is_prime :=\nis_maximal.is_prime\n\nlemma span_singleton_lt_span_singleton [comm_ring \u03b2] [is_domain \u03b2] {x y : \u03b2} :\n  span ({x} : set \u03b2) < span ({y} : set \u03b2) \u2194 dvd_not_unit y x :=\nby rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton,\n  dvd_and_not_dvd_iff]\n\nlemma factors_decreasing [comm_ring \u03b2] [is_domain \u03b2]\n  (b\u2081 b\u2082 : \u03b2) (h\u2081 : b\u2081 \u2260 0) (h\u2082 : \u00ac is_unit b\u2082) :\n  span ({b\u2081 * b\u2082} : set \u03b2) < span {b\u2081} :=\nlt_of_le_not_le (ideal.span_le.2 $ singleton_subset_iff.2 $\n  ideal.mem_span_singleton.2 \u27e8b\u2082, rfl\u27e9) $ \u03bb h,\nh\u2082 $ is_unit_of_dvd_one _ $ (mul_dvd_mul_iff_left h\u2081).1 $\nby rwa [mul_one, \u2190 ideal.span_singleton_le_span_singleton]\n\nvariables (b)\nlemma mul_mem_right (h : a \u2208 I) : a * b \u2208 I := mul_comm b a \u25b8 I.mul_mem_left b h\nvariables {b}\n\nlemma pow_mem_of_mem (ha : a \u2208 I) (n : \u2115) (hn : 0 < n) : a ^ n \u2208 I :=\nnat.cases_on n (not.elim dec_trivial) (\u03bb m hm, (pow_succ a m).symm \u25b8 I.mul_mem_right (a^m) ha) hn\n\ntheorem is_prime.mul_mem_iff_mem_or_mem {I : ideal \u03b1} (hI : I.is_prime) :\n  \u2200 {x y : \u03b1}, x * y \u2208 I \u2194 x \u2208 I \u2228 y \u2208 I :=\n\u03bb x y, \u27e8hI.mem_or_mem, by { rintro (h | h), exacts [I.mul_mem_right y h, I.mul_mem_left x h] }\u27e9\n\ntheorem is_prime.pow_mem_iff_mem {I : ideal \u03b1} (hI : I.is_prime)\n  {r : \u03b1} (n : \u2115) (hn : 0 < n) : r ^ n \u2208 I \u2194 r \u2208 I :=\n\u27e8hI.mem_of_pow_mem n, (\u03bb hr, I.pow_mem_of_mem hr n hn)\u27e9\n\ntheorem pow_multiset_sum_mem_span_pow (s : multiset \u03b1) (n : \u2115) :\n  s.sum ^ (s.card * n + 1) \u2208 span ((s.map (\u03bb x, x ^ (n + 1))).to_finset : set \u03b1) :=\nbegin\n  induction s using multiset.induction_on with a s hs,\n  { simp },\n  simp only [finset.coe_insert, multiset.map_cons, multiset.to_finset_cons, multiset.sum_cons,\n    multiset.card_cons, add_pow],\n  refine submodule.sum_mem _ _,\n  intros c hc,\n  rw mem_span_insert,\n  by_cases h : n+1 \u2264 c,\n  { refine \u27e8a ^ (c - (n + 1)) * s.sum ^ ((s.card + 1) * n + 1 - c) *\n      (((s.card + 1) * n + 1).choose c), 0, submodule.zero_mem _, _\u27e9,\n    rw mul_comm _ (a ^ (n + 1)),\n    simp_rw \u2190 mul_assoc,\n    rw [\u2190 pow_add, add_zero, add_tsub_cancel_of_le h], },\n  { use 0,\n    simp_rw [zero_mul, zero_add],\n    refine \u27e8_,_,rfl\u27e9,\n    replace h : c \u2264 n := nat.lt_succ_iff.mp (not_le.mp h),\n    have : (s.card + 1) * n + 1 - c = s.card * n + 1 + (n - c),\n    { rw [add_mul, one_mul, add_assoc, add_comm n 1, \u2190 add_assoc, add_tsub_assoc_of_le h] },\n    rw [this, pow_add],\n    simp_rw [mul_assoc, mul_comm (s.sum ^ (s.card * n + 1)), \u2190 mul_assoc],\n    exact mul_mem_left _ _ hs }\nend\n\ntheorem sum_pow_mem_span_pow {\u03b9} (s : finset \u03b9) (f : \u03b9 \u2192 \u03b1) (n : \u2115) :\n  (\u2211 i in s, f i) ^ (s.card * n + 1) \u2208 span ((\u03bb i, f i ^ (n + 1)) '' s) :=\nbegin\n  convert pow_multiset_sum_mem_span_pow (s.1.map f) n,\n  { rw multiset.card_map, refl },\n  rw [multiset.map_map, multiset.to_finset_map, finset.val_to_finset, finset.coe_image]\nend\n\ntheorem span_pow_eq_top (s : set \u03b1)\n  (hs : span s = \u22a4) (n : \u2115) : span ((\u03bb x, x ^ n) '' s) = \u22a4 :=\nbegin\n  rw eq_top_iff_one,\n  cases n,\n  { obtain rfl | \u27e8x, hx\u27e9 := eq_empty_or_nonempty s,\n    { rw [set.image_empty, hs],\n      trivial },\n    { exact subset_span \u27e8_, hx, pow_zero _\u27e9 } },\n  rw [eq_top_iff_one, span, finsupp.mem_span_iff_total] at hs,\n  rcases hs with \u27e8f, hf\u27e9,\n  change f.support.sum (\u03bb a, f a * a) = 1 at hf,\n  have := sum_pow_mem_span_pow f.support (\u03bb a, f a * a) n,\n  rw [hf, one_pow] at this,\n  refine (span_le).mpr _ this,\n  rintros _ hx,\n  simp_rw [finset.mem_coe, set.mem_image] at hx,\n  rcases hx with \u27e8x, hx, rfl\u27e9,\n  have : span ({x ^ (n + 1)} : set \u03b1) \u2264 span ((\u03bb (x : \u03b1), x ^ (n + 1)) '' s),\n  { rw [span_le, set.singleton_subset_iff],\n    exact subset_span \u27e8x, x.prop, rfl\u27e9 },\n  refine this _,\n  rw [mul_pow, mem_span_singleton],\n  exact \u27e8f x ^ (n + 1), mul_comm _ _\u27e9\nend\n\nend ideal\n\nend comm_semiring\n\nsection ring\n\nnamespace ideal\n\nvariables [ring \u03b1] (I : ideal \u03b1) {a b : \u03b1}\n\nlemma neg_mem_iff : -a \u2208 I \u2194 a \u2208 I := I.neg_mem_iff\n\nlemma add_mem_iff_left : b \u2208 I \u2192 (a + b \u2208 I \u2194 a \u2208 I) := I.add_mem_iff_left\n\nlemma add_mem_iff_right : a \u2208 I \u2192 (a + b \u2208 I \u2194 b \u2208 I) := I.add_mem_iff_right\n\nprotected lemma sub_mem : a \u2208 I \u2192 b \u2208 I \u2192 a - b \u2208 I := I.sub_mem\n\nlemma mem_span_insert' {s : set \u03b1} {x y} :\n  x \u2208 span (insert y s) \u2194 \u2203a, x + a * y \u2208 span s := submodule.mem_span_insert'\n\nend ideal\n\nend ring\n\nsection division_ring\nvariables {K : Type u} [division_ring K] (I : ideal K)\n\nnamespace ideal\n\n/-- All ideals in a division ring are trivial. -/\nlemma eq_bot_or_top : I = \u22a5 \u2228 I = \u22a4 :=\nbegin\n  rw or_iff_not_imp_right,\n  change _ \u2260 _ \u2192 _,\n  rw ideal.ne_top_iff_one,\n  intro h1,\n  rw eq_bot_iff,\n  intros r hr,\n  by_cases H : r = 0, {simpa},\n  simpa [H, h1] using I.mul_mem_left r\u207b\u00b9 hr,\nend\n\nlemma eq_bot_of_prime [h : I.is_prime] : I = \u22a5 :=\nor_iff_not_imp_right.mp I.eq_bot_or_top h.1\n\nlemma bot_is_maximal : is_maximal (\u22a5 : ideal K) :=\n\u27e8\u27e8\u03bb h, absurd ((eq_top_iff_one (\u22a4 : ideal K)).mp rfl) (by rw \u2190 h; simp),\n\u03bb I hI, or_iff_not_imp_left.mp (eq_bot_or_top I) (ne_of_gt hI)\u27e9\u27e9\n\nend ideal\n\nend division_ring\n\nsection comm_ring\n\nnamespace ideal\n\ntheorem mul_sub_mul_mem {R : Type*} [comm_ring R] (I : ideal R) {a b c d : R}\n  (h1 : a - b \u2208 I) (h2 : c - d \u2208 I) : a * c - b * d \u2208 I :=\nbegin\n  rw (show a * c - b * d = (a - b) * c + b * (c - d), by {rw [sub_mul, mul_sub], abel}),\n  exact I.add_mem (I.mul_mem_right _ h1) (I.mul_mem_left _ h2),\nend\n\nend ideal\n\nend comm_ring\n\nnamespace ring\n\nvariables {R : Type*} [comm_ring R]\n\nlemma not_is_field_of_subsingleton {R : Type*} [ring R] [subsingleton R] : \u00ac is_field R :=\n\u03bb \u27e8\u27e8x, y, hxy\u27e9, _, _\u27e9, hxy (subsingleton.elim x y)\n\nlemma exists_not_is_unit_of_not_is_field [nontrivial R] (hf : \u00ac is_field R) :\n  \u2203 x \u2260 (0 : R), \u00ac is_unit x :=\nbegin\n  have : \u00ac _ := \u03bb h, hf \u27e8exists_pair_ne R, mul_comm, h\u27e9,\n  simp_rw is_unit_iff_exists_inv,\n  push_neg at \u22a2 this,\n  obtain \u27e8x, hx, not_unit\u27e9 := this,\n  exact \u27e8x, hx, not_unit\u27e9\nend\n\nlemma not_is_field_iff_exists_ideal_bot_lt_and_lt_top [nontrivial R] :\n  \u00ac is_field R \u2194 \u2203 I : ideal R, \u22a5 < I \u2227 I < \u22a4 :=\nbegin\n  split,\n  { intro h,\n    obtain \u27e8x, nz, nu\u27e9 := exists_not_is_unit_of_not_is_field h,\n    use ideal.span {x},\n    rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top],\n    exact \u27e8mt ideal.span_singleton_eq_bot.mp nz, mt ideal.span_singleton_eq_top.mp nu\u27e9 },\n  { rintros \u27e8I, bot_lt, lt_top\u27e9 hf,\n    obtain \u27e8x, mem, ne_zero\u27e9 := set_like.exists_of_lt bot_lt,\n    rw submodule.mem_bot at ne_zero,\n    obtain \u27e8y, hy\u27e9 := hf.mul_inv_cancel ne_zero,\n    rw [lt_top_iff_ne_top, ne.def, ideal.eq_top_iff_one, \u2190 hy] at lt_top,\n    exact lt_top (I.mul_mem_right _ mem), }\nend\n\nlemma not_is_field_iff_exists_prime [nontrivial R] :\n  \u00ac is_field R \u2194 \u2203 p : ideal R, p \u2260 \u22a5 \u2227 p.is_prime :=\nnot_is_field_iff_exists_ideal_bot_lt_and_lt_top.trans\n  \u27e8\u03bb \u27e8I, bot_lt, lt_top\u27e9, let \u27e8p, hp, le_p\u27e9 := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top) in\n    \u27e8p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.is_prime\u27e9,\n   \u03bb \u27e8p, ne_bot, prime\u27e9, \u27e8p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr prime.1\u27e9\u27e9\n\n/-- When a ring is not a field, the maximal ideals are nontrivial. -/\nlemma ne_bot_of_is_maximal_of_not_is_field [nontrivial R] {M : ideal R} (max : M.is_maximal)\n  (not_field : \u00ac is_field R) : M \u2260 \u22a5 :=\nbegin\n  rintros h,\n  rw h at max,\n  rcases max with \u27e8\u27e8h1, h2\u27e9\u27e9,\n  obtain \u27e8I, hIbot, hItop\u27e9 := not_is_field_iff_exists_ideal_bot_lt_and_lt_top.mp not_field,\n  exact ne_of_lt hItop (h2 I hIbot),\nend\n\nend ring\n\nnamespace ideal\n\n/-- Maximal ideals in a non-field are nontrivial. -/\nvariables {R : Type u} [comm_ring R] [nontrivial R]\nlemma bot_lt_of_maximal (M : ideal R) [hm : M.is_maximal] (non_field : \u00ac is_field R) : \u22a5 < M :=\nbegin\n  rcases (ring.not_is_field_iff_exists_ideal_bot_lt_and_lt_top.1 non_field)\n    with \u27e8I, Ibot, Itop\u27e9,\n  split, { simp },\n  intro mle,\n  apply @irrefl _ (<) _ (\u22a4 : ideal R),\n  have : M = \u22a5 := eq_bot_iff.mpr mle,\n  rw this at *,\n  rwa hm.1.2 I Ibot at Itop,\nend\n\nend ideal\n\nvariables {a b : \u03b1}\n\n/-- The set of non-invertible elements of a monoid. -/\ndef nonunits (\u03b1 : Type u) [monoid \u03b1] : set \u03b1 := { a | \u00acis_unit a }\n\n@[simp] theorem mem_nonunits_iff [monoid \u03b1] : a \u2208 nonunits \u03b1 \u2194 \u00ac is_unit a := iff.rfl\n\ntheorem mul_mem_nonunits_right [comm_monoid \u03b1] :\n  b \u2208 nonunits \u03b1 \u2192 a * b \u2208 nonunits \u03b1 :=\nmt is_unit_of_mul_is_unit_right\n\ntheorem mul_mem_nonunits_left [comm_monoid \u03b1] :\n  a \u2208 nonunits \u03b1 \u2192 a * b \u2208 nonunits \u03b1 :=\nmt is_unit_of_mul_is_unit_left\n\ntheorem zero_mem_nonunits [semiring \u03b1] : 0 \u2208 nonunits \u03b1 \u2194 (0:\u03b1) \u2260 1 :=\nnot_congr is_unit_zero_iff\n\n@[simp] theorem one_not_mem_nonunits [monoid \u03b1] : (1:\u03b1) \u2209 nonunits \u03b1 :=\nnot_not_intro is_unit_one\n\ntheorem coe_subset_nonunits [semiring \u03b1] {I : ideal \u03b1} (h : I \u2260 \u22a4) :\n  (I : set \u03b1) \u2286 nonunits \u03b1 :=\n\u03bb x hx hu, h $ I.eq_top_of_is_unit_mem hx hu\n\nlemma exists_max_ideal_of_mem_nonunits [comm_semiring \u03b1] (h : a \u2208 nonunits \u03b1) :\n  \u2203 I : ideal \u03b1, I.is_maximal \u2227 a \u2208 I :=\nbegin\n  have : ideal.span ({a} : set \u03b1) \u2260 \u22a4,\n  { intro H, rw ideal.span_singleton_eq_top at H, contradiction },\n  rcases ideal.exists_le_maximal _ this with \u27e8I, Imax, H\u27e9,\n  use [I, Imax], apply H, apply ideal.subset_span, exact set.mem_singleton a\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/ideal/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677699040321, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7257341837870358}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.complex.arg\nimport analysis.special_functions.log.basic\n\n/-!\n# The complex `log` function\n\nBasic properties, relationship with `exp`.\n-/\n\nnoncomputable theory\n\nnamespace complex\n\nopen set filter\n\nopen_locale real topological_space\n\n/-- Inverse of the `exp` function. Returns values such that `(log x).im > - \u03c0` and `(log x).im \u2264 \u03c0`.\n  `log 0 = 0`-/\n@[pp_nodot] noncomputable def log (x : \u2102) : \u2102 := x.abs.log + arg x * I\n\nlemma log_re (x : \u2102) : x.log.re = x.abs.log := by simp [log]\n\nlemma log_im (x : \u2102) : x.log.im = x.arg := by simp [log]\n\nlemma neg_pi_lt_log_im (x : \u2102) : -\u03c0 < (log x).im := by simp only [log_im, neg_pi_lt_arg]\nlemma log_im_le_pi (x : \u2102) : (log x).im \u2264 \u03c0 := by simp only [log_im, arg_le_pi]\n\nlemma exp_log {x : \u2102} (hx : x \u2260 0) : exp (log x) = x :=\nby rw [log, exp_add_mul_I, \u2190 of_real_sin, sin_arg, \u2190 of_real_cos, cos_arg hx,\n  \u2190 of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,\n  mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), \u2190 mul_assoc,\n  mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]\n\n@[simp] lemma range_exp : range exp = {0}\u1d9c :=\nset.ext $ \u03bb x, \u27e8by { rintro \u27e8x, rfl\u27e9, exact exp_ne_zero x }, \u03bb hx, \u27e8log x, exp_log hx\u27e9\u27e9\n\nlemma log_exp {x : \u2102} (hx\u2081 : -\u03c0 < x.im) (hx\u2082: x.im \u2264 \u03c0) : log (exp x) = x :=\nby rw [log, abs_exp, real.log_exp, exp_eq_exp_re_mul_sin_add_cos, \u2190 of_real_exp,\n  arg_mul_cos_add_sin_mul_I (real.exp_pos _) \u27e8hx\u2081, hx\u2082\u27e9, re_add_im]\n\nlemma exp_inj_of_neg_pi_lt_of_le_pi {x y : \u2102} (hx\u2081 : -\u03c0 < x.im) (hx\u2082 : x.im \u2264 \u03c0)\n  (hy\u2081 : - \u03c0 < y.im) (hy\u2082 : y.im \u2264 \u03c0) (hxy : exp x = exp y) : x = y :=\nby rw [\u2190 log_exp hx\u2081 hx\u2082, \u2190 log_exp hy\u2081 hy\u2082, hxy]\n\nlemma of_real_log {x : \u211d} (hx : 0 \u2264 x) : (x.log : \u2102) = log x :=\ncomplex.ext\n  (by rw [log_re, of_real_re, abs_of_nonneg hx])\n  (by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])\n\nlemma log_of_real_re (x : \u211d) : (log (x : \u2102)).re = real.log x := by simp [log_re]\n\n@[simp] lemma log_zero : log 0 = 0 := by simp [log]\n\n@[simp] lemma log_one : log 1 = 0 := by simp [log]\n\nlemma log_neg_one : log (-1) = \u03c0 * I := by simp [log]\n\nlemma log_I : log I = \u03c0 / 2 * I := by simp [log]\n\nlemma log_neg_I : log (-I) = -(\u03c0 / 2) * I := by simp [log]\n\nlemma two_pi_I_ne_zero : (2 * \u03c0 * I : \u2102) \u2260 0 :=\nby norm_num [real.pi_ne_zero, I_ne_zero]\n\nlemma exp_eq_one_iff {x : \u2102} : exp x = 1 \u2194 \u2203 n : \u2124, x = n * ((2 * \u03c0) * I) :=\nbegin\n  split,\n  { intro h,\n    rcases exists_unique_add_zsmul_mem_Ioc real.two_pi_pos x.im (-\u03c0) with \u27e8n, hn, -\u27e9,\n    use -n,\n    rw [int.cast_neg, neg_mul, eq_neg_iff_add_eq_zero],\n    have : (x + n * (2 * \u03c0 * I)).im \u2208 Ioc (-\u03c0) \u03c0, by simpa [two_mul, mul_add] using hn,\n    rw [\u2190 log_exp this.1 this.2, exp_periodic.int_mul n, h, log_one] },\n  { rintro \u27e8n, rfl\u27e9, exact (exp_periodic.int_mul n).eq.trans exp_zero }\nend\n\nlemma exp_eq_exp_iff_exp_sub_eq_one {x y : \u2102} : exp x = exp y \u2194 exp (x - y) = 1 :=\nby rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]\n\nlemma exp_eq_exp_iff_exists_int {x y : \u2102} : exp x = exp y \u2194 \u2203 n : \u2124, x = y + n * ((2 * \u03c0) * I) :=\nby simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']\n\n@[simp] lemma countable_preimage_exp {s : set \u2102} : (exp \u207b\u00b9' s).countable \u2194 s.countable :=\nbegin\n  refine \u27e8\u03bb hs, _, \u03bb hs, _\u27e9,\n  { refine ((hs.image exp).insert 0).mono _,\n    rw [image_preimage_eq_inter_range, range_exp, \u2190 diff_eq, \u2190 union_singleton, diff_union_self],\n    exact subset_union_left _ _ },\n  { rw \u2190 bUnion_preimage_singleton,\n    refine hs.bUnion (\u03bb z hz, _),\n    rcases em (\u2203 w, exp w = z) with \u27e8w, rfl\u27e9|hne,\n    { simp only [preimage, mem_singleton_iff, exp_eq_exp_iff_exists_int, set_of_exists],\n      exact countable_Union (\u03bb m, countable_singleton _) },\n    { push_neg at hne, simp [preimage, hne] } }\nend\n\nalias countable_preimage_exp \u2194 _ _root_.set.countable.preimage_cexp\n\nlemma tendsto_log_nhds_within_im_neg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto log (\ud835\udcdd[{z : \u2102 | z.im < 0}] z) (\ud835\udcdd $ real.log (abs z) - \u03c0 * I) :=\nbegin\n  have := (continuous_of_real.continuous_at.comp_continuous_within_at\n    (continuous_abs.continuous_within_at.log _)).tendsto.add\n    (((continuous_of_real.tendsto _).comp $\n    tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),\n  convert this,\n  { simp [sub_eq_add_neg] },\n  { lift z to \u211d using him, simpa using hre.ne }\nend\n\nlemma continuous_within_at_log_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  continuous_within_at log {z : \u2102 | 0 \u2264 z.im} z :=\nbegin\n  have := (continuous_of_real.continuous_at.comp_continuous_within_at\n    (continuous_abs.continuous_within_at.log _)).tendsto.add\n    ((continuous_of_real.continuous_at.comp_continuous_within_at $\n    continuous_within_at_arg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),\n  convert this,\n  { lift z to \u211d using him, simpa using hre.ne }\nend\n\nlemma tendsto_log_nhds_within_im_nonneg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto log (\ud835\udcdd[{z : \u2102 | 0 \u2264 z.im}] z) (\ud835\udcdd $ real.log (abs z) + \u03c0 * I) :=\nby simpa only [log, arg_eq_pi_iff.2 \u27e8hre, him\u27e9]\n  using (continuous_within_at_log_of_re_neg_of_im_zero hre him).tendsto\n\n@[simp] lemma map_exp_comap_re_at_bot : map exp (comap re at_bot) = \ud835\udcdd[\u2260] 0 :=\nby rw [\u2190 comap_exp_nhds_zero, map_comap, range_exp, nhds_within]\n\n@[simp] lemma map_exp_comap_re_at_top : map exp (comap re at_top) = comap abs at_top :=\nbegin\n  rw [\u2190 comap_exp_comap_abs_at_top, map_comap, range_exp, inf_eq_left, le_principal_iff],\n  exact eventually_ne_of_tendsto_norm_at_top tendsto_comap 0\nend\n\nend complex\n\nsection log_deriv\n\nopen complex filter\nopen_locale topological_space\n\nvariables {\u03b1 : Type*}\n\nlemma continuous_at_clog {x : \u2102} (h : 0 < x.re \u2228 x.im \u2260 0) :\n  continuous_at log x :=\nbegin\n  refine continuous_at.add _ _,\n  { refine continuous_of_real.continuous_at.comp _,\n    refine (real.continuous_at_log _).comp complex.continuous_abs.continuous_at,\n    rw abs_ne_zero,\n    rintro rfl,\n    simpa using h },\n  { have h_cont_mul : continuous (\u03bb x : \u2102, x * I), from continuous_id'.mul continuous_const,\n    refine h_cont_mul.continuous_at.comp (continuous_of_real.continuous_at.comp _),\n    exact continuous_at_arg h, },\nend\n\nlemma filter.tendsto.clog {l : filter \u03b1} {f : \u03b1 \u2192 \u2102} {x : \u2102} (h : tendsto f l (\ud835\udcdd x))\n  (hx : 0 < x.re \u2228 x.im \u2260 0) :\n  tendsto (\u03bb t, log (f t)) l (\ud835\udcdd $ log x) :=\n(continuous_at_clog hx).tendsto.comp h\n\nvariables [topological_space \u03b1]\n\nlemma continuous_at.clog {f : \u03b1 \u2192 \u2102} {x : \u03b1} (h\u2081 : continuous_at f x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_at (\u03bb t, log (f t)) x :=\nh\u2081.clog h\u2082\n\nlemma continuous_within_at.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} {x : \u03b1} (h\u2081 : continuous_within_at f s x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_within_at (\u03bb t, log (f t)) s x :=\nh\u2081.clog h\u2082\n\nlemma continuous_on.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} (h\u2081 : continuous_on f s)\n  (h\u2082 : \u2200 x \u2208 s, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_on (\u03bb t, log (f t)) s :=\n\u03bb x hx, (h\u2081 x hx).clog (h\u2082 x hx)\n\nlemma continuous.clog {f : \u03b1 \u2192 \u2102} (h\u2081 : continuous f) (h\u2082 : \u2200 x, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous (\u03bb t, log (f t)) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, h\u2081.continuous_at.clog (h\u2082 x)\n\nend log_deriv\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/analysis/special_functions/complex/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7257341785989181}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport data.nat.parity\nimport data.list.chain\n\n/-!\n# List of booleans\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove lemmas about the number of `ff`s and `tt`s in a list of booleans. First we\nprove that the number of `ff`s plus the number of `tt` equals the length of the list. Then we prove\nthat in a list with alternating `tt`s and `ff`s, the number of `tt`s differs from the number of\n`ff`s by at most one. We provide several versions of these statements.\n-/\n\nnamespace list\n\n@[simp]\n\n\n@[simp]\ntheorem count_add_count_bnot (l : list bool) (b : bool) : count b l + count (!b) l = length l :=\nby rw [add_comm, count_bnot_add_count]\n\n@[simp] theorem count_ff_add_count_tt (l : list bool) : count ff l + count tt l = length l :=\ncount_bnot_add_count l tt\n\n@[simp] theorem count_tt_add_count_ff (l : list bool) : count tt l + count ff l = length l :=\ncount_bnot_add_count l ff\n\nlemma chain.count_bnot :\n  \u2200 {b : bool} {l : list bool}, chain (\u2260) b l \u2192 count (!b) l = count b l + length l % 2\n| b [] h := rfl\n| b (x :: l) h :=\n  begin\n    obtain rfl : b = !x := bool.eq_bnot_iff.2 (rel_of_chain_cons h),\n    rw [bnot_bnot, count_cons_self, count_cons_of_ne x.bnot_ne_self,\n      chain.count_bnot (chain_of_chain_cons h), length, add_assoc, nat.mod_two_add_succ_mod_two]\n  end\n\nnamespace chain'\n\nvariables {l : list bool}\n\ntheorem count_bnot_eq_count (hl : chain' (\u2260) l) (h2 : even (length l)) (b : bool) :\n  count (!b) l = count b l :=\nbegin\n  cases l with x l, { refl },\n  rw [length_cons, nat.even_add_one, nat.not_even_iff] at h2,\n  suffices : count (!x) (x :: l) = count x (x :: l),\n  { cases b; cases x; try { exact this }; exact this.symm },\n  rw [count_cons_of_ne x.bnot_ne_self, hl.count_bnot, h2, count_cons_self]\nend\n\ntheorem count_ff_eq_count_tt (hl : chain' (\u2260) l) (h2 : even (length l)) : count ff l = count tt l :=\nhl.count_bnot_eq_count h2 tt\n\nlemma count_bnot_le_count_add_one (hl : chain' (\u2260) l) (b : bool) :\n  count (!b) l \u2264 count b l + 1 :=\nbegin\n  cases l with x l, { exact zero_le _ },\n  obtain rfl | rfl : b = x \u2228 b = !x, by simp only [bool.eq_bnot_iff, em],\n  { rw [count_cons_of_ne b.bnot_ne_self, count_cons_self, hl.count_bnot, add_assoc],\n    exact add_le_add_left (nat.mod_lt _ two_pos).le _ },\n  { rw [bnot_bnot, count_cons_self, count_cons_of_ne x.bnot_ne_self, hl.count_bnot],\n    exact add_le_add_right (le_add_right le_rfl) _ }\nend\n\nlemma count_ff_le_count_tt_add_one (hl : chain' (\u2260) l) : count ff l \u2264 count tt l + 1 :=\nhl.count_bnot_le_count_add_one tt\n\nlemma count_tt_le_count_ff_add_one (hl : chain' (\u2260) l) : count tt l \u2264 count ff l + 1 :=\nhl.count_bnot_le_count_add_one ff\n\ntheorem two_mul_count_bool_of_even (hl : chain' (\u2260) l) (h2 : even (length l)) (b : bool) :\n  2 * count b l = length l :=\nby rw [\u2190 count_bnot_add_count l b, hl.count_bnot_eq_count h2, two_mul]\n\ntheorem two_mul_count_bool_eq_ite (hl : chain' (\u2260) l) (b : bool) :\n  2 * count b l = if even (length l) then length l else\n    if b \u2208 l.head' then length l + 1 else length l - 1 :=\nbegin\n  by_cases h2 : even (length l),\n  { rw [if_pos h2, hl.two_mul_count_bool_of_even h2] },\n  { cases l with x l, { exact (h2 even_zero).elim },\n    simp only [if_neg h2, count_cons', mul_add, head', option.mem_some_iff, @eq_comm _ x],\n    rw [length_cons, nat.even_add_one, not_not] at h2,\n    replace hl : l.chain' (\u2260) := hl.tail,\n    rw [hl.two_mul_count_bool_of_even h2],\n    split_ifs; simp }\nend\n\ntheorem length_sub_one_le_two_mul_count_bool (hl : chain' (\u2260) l) (b : bool) :\n  length l - 1 \u2264 2 * count b l :=\nby { rw [hl.two_mul_count_bool_eq_ite], split_ifs; simp [le_tsub_add, nat.le_succ_of_le] }\n\ntheorem length_div_two_le_count_bool (hl : chain' (\u2260) l) (b : bool) : length l / 2 \u2264 count b l :=\nbegin\n  rw [nat.div_le_iff_le_mul_add_pred two_pos, \u2190 tsub_le_iff_right],\n  exact length_sub_one_le_two_mul_count_bool hl b\nend\n\nlemma two_mul_count_bool_le_length_add_one (hl : chain' (\u2260) l) (b : bool) :\n  2 * count b l \u2264 length l + 1 :=\nby { rw [hl.two_mul_count_bool_eq_ite], split_ifs; simp [nat.le_succ_of_le] }\n\nend chain'\n\nend list\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/bool/count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7257341690752135}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_462 :\n  (1 / 2 + 1 / 3) * (1 / 2 - 1 / 3) = 5 / 36 :=\nbegin\n  norm_num,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p462.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7256134021438272}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.invariant_basis_number\n! leanprover-community/mathlib commit 843240b048bbb19942c581fd64caecbbe96337be\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Matrix.ToLin\nimport Mathbin.LinearAlgebra.InvariantBasisNumber\n\n/-!\n# Invertible matrices over a ring with invariant basis number are square.\n-/\n\n\nvariable {n m : Type _} [Fintype n] [DecidableEq n] [Fintype m] [DecidableEq m]\n\nvariable {R : Type _} [Semiring R] [InvariantBasisNumber R]\n\nopen Matrix\n\ntheorem Matrix.square_of_invertible (M : Matrix n m R) (N : Matrix m n R) (h : M \u2b1d N = 1)\n    (h' : N \u2b1d M = 1) : Fintype.card n = Fintype.card m :=\n  card_eq_of_linearEquiv R (Matrix.toLinearEquivRight'OfInv h' h)\n#align matrix.square_of_invertible Matrix.square_of_invertible\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/InvariantBasisNumber.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7256134003035635}}
{"text": "import mynat.definition\nimport mynat.add\n\nnamespace mynat\n\ntheorem add_right_cancel (a t b : mynat) : a + t = b + t \u2192 a = b :=\nbegin [nat_num_game]\n    induction t with n hd,\n    {\n        rw add_zero,\n        rw add_zero,\n        intro h,\n        exact h,\n    },\n    {\n        rw add_succ,\n        rw add_succ,\n        intro h,\n        apply hd,\n        apply succ_inj,\n        exact h,\n    },\nend\n\nend mynat", "meta": {"author": "nomoid", "repo": "lean-proofs", "sha": "b9f03a24623d1a1d111d6c2bbf53c617e2596d6a", "save_path": "github-repos/lean/nomoid-lean-proofs", "path": "github-repos/lean/nomoid-lean-proofs/lean-proofs-b9f03a24623d1a1d111d6c2bbf53c617e2596d6a/src/world8/level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9648551505674444, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.7255832158086127}}
{"text": "import tuto_lib\n\n\nsection\n/-\nThe first part of this file makes sure you can negate quantified statements\nin your head without the help of `push_neg`.\n\nYou need to complete the statement and then use the `check_me` tactic\nto check your answer. This tactic exists only for those exercises,\nit mostly calls `push_neg` and then cleans up a bit.\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from \u211d to \u211d\n-- x\u2080 and l are real numbers\nvariables (u : \u2115 \u2192 \u211d) (f : \u211d \u2192 \u211d) (x\u2080 l : \u211d)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/- Negation of \"f is continuous at x\u2080\" -/\n-- 0063\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192  |f x - f x\u2080| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`\u2200 x x', ...` is the abbreviation of\n`\u2200 x, \u2200 x', ... `. \n\nAlso, `\u2203 x x', ...` is the abbreviation of `\u2203 x, \u2203 x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on \u211d\" -/\n-- 0064\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x x', |x' - x| \u2264 \u03b4 \u2192  |f x' - f x| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/- Negation of \"f is sequentially continuous at x\u2080\" -/\n-- 0065\nexample : \u00ac (\u2200 u : \u2115 \u2192 \u211d, (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b5) \u2192 (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |(f \u2218 u) n - f x\u2080| \u2264 \u03b5))  \u2194\nsorry\n:=\nbegin\n  sorry\nend\nend\n\n/-\nWe now turn to elementary applications of negations to limits of sequences.\nRemember that `linarith` can find easy numerical contradictions.\n\nAlso recall the following lemmas:\n\nabs_le {x y : \u211d} : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\n/-- The sequence `u` tends to `+\u221e`. -/\ndef tendsto_infinity (u : \u2115 \u2192 \u211d) := \u2200 A, \u2203 N, \u2200 n \u2265 N, u n \u2265 A\n-/\n\n-- 0066\nexample {u : \u2115 \u2192 \u211d} : tendsto_infinity u \u2192 \u2200 l, \u00ac seq_limit u l :=\nbegin\n  sorry\nend\n\ndef nondecreasing_seq (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- 0067\nexample (u : \u2115 \u2192 \u211d) (l : \u211d) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  \u2200 n, u n \u2264 l :=\nbegin\n  sorry\nend\n\n/-\nIn the following exercises, `A : set \u211d` means that A is a set of real numbers.\nWe can use the usual notation x \u2208 A.\n\nThe notation `\u2200 x \u2208 A, ...` is the abbreviation of `\u2200 x, x \u2208 A \u2192 ... `\n\nThe notation `\u2203 x \u2208 A, ...` is the abbreviation of `\u2203 x, x \u2208 A \u2227 ... `.\nMore precisely it is the abbreviation of `\u2203 x (H : x \u2208 A), ...`\nwhich is Lean's strange way of saying `\u2203 x, x \u2208 A \u2227 ... `. \nYou can convert between these forms using the lemma \n  exists_prop {p q : Prop} : (\u2203 (h : p), q) \u2194 p \u2227 q\n\nWe'll work with upper bounds and supremums.\nAgain we'll introduce specialized definitions for the sake of exercises, but mathlib\nhas more general versions.\n\n\ndef upper_bound (A : set \u211d) (x : \u211d) := \u2200 a \u2208 A, a \u2264 x\n\ndef is_sup (A : set \u211d) (x : \u211d) := upper_bound A x \u2227 \u2200 y, upper_bound A y \u2192 x \u2264 y\n\n\nRemark: one can easily show that a set of real numbers has at most one sup,\nbut we won't need this.\n-/\n\n-- 0068\nexample {A : set \u211d} {x : \u211d} (hx : is_sup A x) :\n\u2200 y, y < x \u2192 \u2203 a \u2208 A, y < a :=\nbegin\n  sorry\nend\n\n/-\nLet's do a variation on an example from file 07 that will be useful in the last\nexercise below.\n-/\n\n-- 0069\nlemma le_of_le_add_all' {x y : \u211d} :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  sorry\nend\n\n-- 0070\nexample {x y : \u211d} {u : \u2115 \u2192 \u211d} (hu : seq_limit u x)\n  (ineg : \u2200 n, u n \u2264 y) : x \u2264 y :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "leanprover-community", "repo": "tutorials", "sha": "79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1", "save_path": "github-repos/lean/leanprover-community-tutorials", "path": "github-repos/lean/leanprover-community-tutorials/tutorials-79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1/src/exercises/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7255556378927925}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport group_theory.group_action.quotient\nimport group_theory.order_of_element\n\n/-!\n# Complements\n\nIn this file we define the complement of a subgroup.\n\n## Main definitions\n\n- `is_complement S T` where `S` and `T` are subsets of `G` states that every `g : G` can be\n  written uniquely as a product `s * t` for `s \u2208 S`, `t \u2208 T`.\n- `left_transversals T` where `T` is a subset of `G` is the set of all left-complements of `T`,\n  i.e. the set of all `S : set G` that contain exactly one element of each left coset of `T`.\n- `right_transversals S` where `S` is a subset of `G` is the set of all right-complements of `S`,\n  i.e. the set of all `T : set G` that contain exactly one element of each right coset of `S`.\n\n## Main results\n\n- `is_complement_of_coprime` : Subgroups of coprime order are complements.\n-/\n\nopen_locale big_operators\n\nnamespace subgroup\n\nvariables {G : Type*} [group G] (H K : subgroup G) (S T : set G)\n\n/-- `S` and `T` are complements if `(*) : S \u00d7 T \u2192 G` is a bijection.\n  This notion generalizes left transversals, right transversals, and complementary subgroups. -/\n@[to_additive \"`S` and `T` are complements if `(*) : S \u00d7 T \u2192 G` is a bijection\"]\ndef is_complement : Prop := function.bijective (\u03bb x : S \u00d7 T, x.1.1 * x.2.1)\n\n/-- `H` and `K` are complements if `(*) : H \u00d7 K \u2192 G` is a bijection -/\n@[to_additive \"`H` and `K` are complements if `(*) : H \u00d7 K \u2192 G` is a bijection\"]\nabbreviation is_complement' := is_complement (H : set G) (K : set G)\n\n/-- The set of left-complements of `T : set G` -/\n@[to_additive \"The set of left-complements of `T : set G`\"]\ndef left_transversals : set (set G) := {S : set G | is_complement S T}\n\n/-- The set of right-complements of `S : set G` -/\n@[to_additive \"The set of right-complements of `S : set G`\"]\ndef right_transversals : set (set G) := {T : set G | is_complement S T}\n\nvariables {H K S T}\n\n@[to_additive] lemma is_complement'_def :\n  is_complement' H K \u2194 is_complement (H : set G) (K : set G) := iff.rfl\n\n@[to_additive] lemma is_complement_iff_exists_unique :\n  is_complement S T \u2194 \u2200 g : G, \u2203! x : S \u00d7 T, x.1.1 * x.2.1 = g :=\nfunction.bijective_iff_exists_unique _\n\n@[to_additive] lemma is_complement.exists_unique (h : is_complement S T) (g : G) :\n  \u2203! x : S \u00d7 T, x.1.1 * x.2.1 = g :=\nis_complement_iff_exists_unique.mp h g\n\n@[to_additive] lemma is_complement'.symm (h : is_complement' H K) : is_complement' K H :=\nbegin\n  let \u03d5 : H \u00d7 K \u2243 K \u00d7 H := equiv.mk (\u03bb x, \u27e8x.2\u207b\u00b9, x.1\u207b\u00b9\u27e9) (\u03bb x, \u27e8x.2\u207b\u00b9, x.1\u207b\u00b9\u27e9)\n    (\u03bb x, prod.ext (inv_inv _) (inv_inv _)) (\u03bb x, prod.ext (inv_inv _) (inv_inv _)),\n  let \u03c8 : G \u2243 G := equiv.mk (\u03bb g : G, g\u207b\u00b9) (\u03bb g : G, g\u207b\u00b9) inv_inv inv_inv,\n  suffices : \u03c8 \u2218 (\u03bb x : H \u00d7 K, x.1.1 * x.2.1) = (\u03bb x : K \u00d7 H, x.1.1 * x.2.1) \u2218 \u03d5,\n  { rwa [is_complement'_def, is_complement, \u2190equiv.bijective_comp, \u2190this, equiv.comp_bijective] },\n  exact funext (\u03bb x, mul_inv_rev _ _),\nend\n\n@[to_additive] lemma is_complement'_comm : is_complement' H K \u2194 is_complement' K H :=\n\u27e8is_complement'.symm, is_complement'.symm\u27e9\n\n@[to_additive] lemma is_complement_top_singleton {g : G} : is_complement (\u22a4 : set G) {g} :=\n\u27e8\u03bb \u27e8x, _, rfl\u27e9 \u27e8y, _, rfl\u27e9 h, prod.ext (subtype.ext (mul_right_cancel h)) rfl,\n  \u03bb x, \u27e8\u27e8\u27e8x * g\u207b\u00b9, \u27e8\u27e9\u27e9, g, rfl\u27e9, inv_mul_cancel_right x g\u27e9\u27e9\n\n@[to_additive] lemma is_complement_singleton_top {g : G} : is_complement ({g} : set G) \u22a4 :=\n\u27e8\u03bb \u27e8\u27e8_, rfl\u27e9, x\u27e9 \u27e8\u27e8_, rfl\u27e9, y\u27e9 h, prod.ext rfl (subtype.ext (mul_left_cancel h)),\n  \u03bb x, \u27e8\u27e8\u27e8g, rfl\u27e9, g\u207b\u00b9 * x, \u27e8\u27e9\u27e9, mul_inv_cancel_left g x\u27e9\u27e9\n\n@[to_additive] lemma is_complement_singleton_left {g : G} : is_complement {g} S \u2194 S = \u22a4 :=\nbegin\n  refine \u27e8\u03bb h, top_le_iff.mp (\u03bb x hx, _), \u03bb h, (congr_arg _ h).mpr is_complement_singleton_top\u27e9,\n  obtain \u27e8\u27e8\u27e8z, rfl : z = g\u27e9, y, _\u27e9, hy\u27e9 := h.2 (g * x),\n  rwa \u2190 mul_left_cancel hy,\nend\n\n@[to_additive] lemma is_complement_singleton_right {g : G} : is_complement S {g} \u2194 S = \u22a4 :=\nbegin\n  refine \u27e8\u03bb h, top_le_iff.mp (\u03bb x hx, _), \u03bb h, (congr_arg _ h).mpr is_complement_top_singleton\u27e9,\n  obtain \u27e8y, hy\u27e9 := h.2 (x * g),\n  conv_rhs at hy { rw \u2190 (show y.2.1 = g, from y.2.2) },\n  rw \u2190 mul_right_cancel hy,\n  exact y.1.2,\nend\n\n@[to_additive] lemma is_complement_top_left : is_complement \u22a4 S \u2194 \u2203 g : G, S = {g} :=\nbegin\n  refine \u27e8\u03bb h, set.exists_eq_singleton_iff_nonempty_subsingleton.mpr \u27e8_, \u03bb a ha b hb, _\u27e9, _\u27e9,\n  { obtain \u27e8a, ha\u27e9 := h.2 1,\n    exact \u27e8a.2.1, a.2.2\u27e9 },\n  { have : (\u27e8\u27e8_, mem_top a\u207b\u00b9\u27e9, \u27e8a, ha\u27e9\u27e9 : (\u22a4 : set G) \u00d7 S) = \u27e8\u27e8_, mem_top b\u207b\u00b9\u27e9, \u27e8b, hb\u27e9\u27e9 :=\n    h.1 ((inv_mul_self a).trans (inv_mul_self b).symm),\n    exact subtype.ext_iff.mp ((prod.ext_iff.mp this).2) },\n  { rintro \u27e8g, rfl\u27e9,\n    exact is_complement_top_singleton },\nend\n\n@[to_additive] lemma is_complement_top_right : is_complement S \u22a4 \u2194 \u2203 g : G, S = {g} :=\nbegin\n  refine \u27e8\u03bb h, set.exists_eq_singleton_iff_nonempty_subsingleton.mpr \u27e8_, \u03bb a ha b hb, _\u27e9, _\u27e9,\n  { obtain \u27e8a, ha\u27e9 := h.2 1,\n    exact \u27e8a.1.1, a.1.2\u27e9 },\n  { have : (\u27e8\u27e8a, ha\u27e9, \u27e8_, mem_top a\u207b\u00b9\u27e9\u27e9 : S \u00d7 (\u22a4 : set G)) = \u27e8\u27e8b, hb\u27e9, \u27e8_, mem_top b\u207b\u00b9\u27e9\u27e9 :=\n    h.1 ((mul_inv_self a).trans (mul_inv_self b).symm),\n    exact subtype.ext_iff.mp ((prod.ext_iff.mp this).1) },\n  { rintro \u27e8g, rfl\u27e9,\n    exact is_complement_singleton_top },\nend\n\n@[to_additive] lemma is_complement'_top_bot : is_complement' (\u22a4 : subgroup G) \u22a5 :=\nis_complement_top_singleton\n\n@[to_additive] lemma is_complement'_bot_top : is_complement' (\u22a5 : subgroup G) \u22a4 :=\nis_complement_singleton_top\n\n@[simp, to_additive] lemma is_complement'_bot_left : is_complement' \u22a5 H \u2194 H = \u22a4 :=\nis_complement_singleton_left.trans coe_eq_univ\n\n@[simp, to_additive] lemma is_complement'_bot_right : is_complement' H \u22a5 \u2194 H = \u22a4 :=\nis_complement_singleton_right.trans coe_eq_univ\n\n@[simp, to_additive] lemma is_complement'_top_left : is_complement' \u22a4 H \u2194 H = \u22a5 :=\nis_complement_top_left.trans coe_eq_singleton\n\n@[simp, to_additive] lemma is_complement'_top_right : is_complement' H \u22a4 \u2194 H = \u22a5 :=\nis_complement_top_right.trans coe_eq_singleton\n\n@[to_additive] lemma mem_left_transversals_iff_exists_unique_inv_mul_mem :\n  S \u2208 left_transversals T \u2194 \u2200 g : G, \u2203! s : S, (s : G)\u207b\u00b9 * g \u2208 T :=\nbegin\n  rw [left_transversals, set.mem_set_of_eq, is_complement_iff_exists_unique],\n  refine \u27e8\u03bb h g, _, \u03bb h g, _\u27e9,\n  { obtain \u27e8x, h1, h2\u27e9 := h g,\n    exact \u27e8x.1, (congr_arg (\u2208 T) (eq_inv_mul_of_mul_eq h1)).mp x.2.2, \u03bb y hy,\n      (prod.ext_iff.mp (h2 \u27e8y, y\u207b\u00b9 * g, hy\u27e9 (mul_inv_cancel_left y g))).1\u27e9 },\n  { obtain \u27e8x, h1, h2\u27e9 := h g,\n    refine \u27e8\u27e8x, x\u207b\u00b9 * g, h1\u27e9, mul_inv_cancel_left x g, \u03bb y hy, _\u27e9,\n    have := h2 y.1 ((congr_arg (\u2208 T) (eq_inv_mul_of_mul_eq hy)).mp y.2.2),\n    exact prod.ext this (subtype.ext (eq_inv_mul_of_mul_eq ((congr_arg _ this).mp hy))) },\nend\n\n@[to_additive] lemma mem_right_transversals_iff_exists_unique_mul_inv_mem :\n  S \u2208 right_transversals T \u2194 \u2200 g : G, \u2203! s : S, g * (s : G)\u207b\u00b9 \u2208 T :=\nbegin\n  rw [right_transversals, set.mem_set_of_eq, is_complement_iff_exists_unique],\n  refine \u27e8\u03bb h g, _, \u03bb h g, _\u27e9,\n  { obtain \u27e8x, h1, h2\u27e9 := h g,\n    exact \u27e8x.2, (congr_arg (\u2208 T) (eq_mul_inv_of_mul_eq h1)).mp x.1.2, \u03bb y hy,\n      (prod.ext_iff.mp (h2 \u27e8\u27e8g * y\u207b\u00b9, hy\u27e9, y\u27e9 (inv_mul_cancel_right g y))).2\u27e9 },\n  { obtain \u27e8x, h1, h2\u27e9 := h g,\n    refine \u27e8\u27e8\u27e8g * x\u207b\u00b9, h1\u27e9, x\u27e9, inv_mul_cancel_right g x, \u03bb y hy, _\u27e9,\n    have := h2 y.2 ((congr_arg (\u2208 T) (eq_mul_inv_of_mul_eq hy)).mp y.1.2),\n    exact prod.ext (subtype.ext (eq_mul_inv_of_mul_eq ((congr_arg _ this).mp hy))) this },\nend\n\n@[to_additive] lemma mem_left_transversals_iff_exists_unique_quotient_mk'_eq :\n  S \u2208 left_transversals (H : set G) \u2194\n  \u2200 q : quotient (quotient_group.left_rel H), \u2203! s : S, quotient.mk' s.1 = q :=\nbegin\n  simp_rw [mem_left_transversals_iff_exists_unique_inv_mul_mem, set_like.mem_coe,\n    \u2190 quotient_group.eq'],\n  exact \u27e8\u03bb h q, quotient.induction_on' q h, \u03bb h g, h (quotient.mk' g)\u27e9,\nend\n\n@[to_additive] lemma mem_right_transversals_iff_exists_unique_quotient_mk'_eq :\n  S \u2208 right_transversals (H : set G) \u2194\n  \u2200 q : quotient (quotient_group.right_rel H), \u2203! s : S, quotient.mk' s.1 = q :=\nbegin\n  simp_rw [mem_right_transversals_iff_exists_unique_mul_inv_mem, set_like.mem_coe,\n    \u2190 quotient_group.right_rel_apply, \u2190 quotient.eq'],\n  exact \u27e8\u03bb h q, quotient.induction_on' q h, \u03bb h g, h (quotient.mk' g)\u27e9,\nend\n\n@[to_additive] lemma mem_left_transversals_iff_bijective : S \u2208 left_transversals (H : set G) \u2194\n  function.bijective (S.restrict (quotient.mk' : G \u2192 quotient (quotient_group.left_rel H))) :=\nmem_left_transversals_iff_exists_unique_quotient_mk'_eq.trans\n  (function.bijective_iff_exists_unique (S.restrict quotient.mk')).symm\n\n@[to_additive] lemma mem_right_transversals_iff_bijective : S \u2208 right_transversals (H : set G) \u2194\n  function.bijective (S.restrict (quotient.mk' : G \u2192 quotient (quotient_group.right_rel H))) :=\nmem_right_transversals_iff_exists_unique_quotient_mk'_eq.trans\n  (function.bijective_iff_exists_unique (S.restrict quotient.mk')).symm\n\n@[to_additive] lemma range_mem_left_transversals {f : G \u29f8 H \u2192 G} (hf : \u2200 q, \u2191(f q) = q) :\n  set.range f \u2208 left_transversals (H : set G) :=\nmem_left_transversals_iff_bijective.mpr \u27e8by rintros \u27e8-, q\u2081, rfl\u27e9 \u27e8-, q\u2082, rfl\u27e9 h;\n  exact congr_arg _ (((hf q\u2081).symm.trans h).trans (hf q\u2082)), \u03bb q, \u27e8\u27e8f q, q, rfl\u27e9, hf q\u27e9\u27e9\n\n@[to_additive] lemma range_mem_right_transversals {f : quotient (quotient_group.right_rel H) \u2192 G}\n  (hf : \u2200 q, quotient.mk' (f q) = q) : set.range f \u2208 right_transversals (H : set G) :=\nmem_right_transversals_iff_bijective.mpr \u27e8by rintros \u27e8-, q\u2081, rfl\u27e9 \u27e8-, q\u2082, rfl\u27e9 h;\n  exact congr_arg _ (((hf q\u2081).symm.trans h).trans (hf q\u2082)), \u03bb q, \u27e8\u27e8f q, q, rfl\u27e9, hf q\u27e9\u27e9\n\n@[to_additive] lemma exists_left_transversal (g : G) :\n  \u2203 S \u2208 left_transversals (H : set G), g \u2208 S :=\nbegin\n  classical,\n  refine \u27e8set.range (function.update quotient.out' \u2191g g), range_mem_left_transversals (\u03bb q, _),\n    g, function.update_same g g quotient.out'\u27e9,\n  by_cases hq : q = g,\n  { exact hq.symm \u25b8 congr_arg _ (function.update_same g g quotient.out') },\n  { exact eq.trans (congr_arg _ (function.update_noteq hq g quotient.out')) q.out_eq' },\nend\n\n@[to_additive] lemma exists_right_transversal (g : G) :\n  \u2203 S \u2208 right_transversals (H : set G), g \u2208 S :=\nbegin\n  classical,\n  refine \u27e8set.range (function.update quotient.out' _ g), range_mem_right_transversals (\u03bb q, _),\n    quotient.mk' g, function.update_same (quotient.mk' g) g quotient.out'\u27e9,\n  by_cases hq : q = quotient.mk' g,\n  { exact hq.symm \u25b8 congr_arg _ (function.update_same (quotient.mk' g) g quotient.out') },\n  { exact eq.trans (congr_arg _ (function.update_noteq hq g quotient.out')) q.out_eq' },\nend\n\nnamespace mem_left_transversals\n\n/-- A left transversal is in bijection with left cosets. -/\n@[to_additive \"A left transversal is in bijection with left cosets.\"]\nnoncomputable def to_equiv (hS : S \u2208 subgroup.left_transversals (H : set G)) : G \u29f8 H \u2243 S :=\n(equiv.of_bijective _ (subgroup.mem_left_transversals_iff_bijective.mp hS)).symm\n\n@[to_additive] lemma mk'_to_equiv (hS : S \u2208 subgroup.left_transversals (H : set G)) (q : G \u29f8 H) :\n  quotient.mk' (to_equiv hS q : G) = q :=\n(to_equiv hS).symm_apply_apply q\n\n@[to_additive] lemma to_equiv_apply {f : G \u29f8 H \u2192 G} (hf : \u2200 q, (f q : G \u29f8 H) = q) (q : G \u29f8 H) :\n  (to_equiv (range_mem_left_transversals hf) q : G) = f q :=\nbegin\n  refine (subtype.ext_iff.mp _).trans (subtype.coe_mk (f q) \u27e8q, rfl\u27e9),\n  exact (to_equiv (range_mem_left_transversals hf)).apply_eq_iff_eq_symm_apply.mpr (hf q).symm,\nend\n\n/-- A left transversal can be viewed as a function mapping each element of the group\n  to the chosen representative from that left coset. -/\n@[to_additive \"A left transversal can be viewed as a function mapping each element of the group\n  to the chosen representative from that left coset.\"]\nnoncomputable def to_fun (hS : S \u2208 subgroup.left_transversals (H : set G)) : G \u2192 S :=\nto_equiv hS \u2218 quotient.mk'\n\n@[to_additive] lemma inv_to_fun_mul_mem (hS : S \u2208 subgroup.left_transversals (H : set G))\n  (g : G) : (to_fun hS g : G)\u207b\u00b9 * g \u2208 H :=\nquotient_group.left_rel_apply.mp $ quotient.exact' $ mk'_to_equiv _ _\n\n@[to_additive] lemma inv_mul_to_fun_mem (hS : S \u2208 subgroup.left_transversals (H : set G))\n  (g : G) : g\u207b\u00b9 * to_fun hS g \u2208 H :=\n(congr_arg (\u2208 H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (inv_to_fun_mul_mem hS g))\n\nend mem_left_transversals\n\nnamespace mem_right_transversals\n\n/-- A right transversal is in bijection with right cosets. -/\n@[to_additive \"A right transversal is in bijection with right cosets.\"]\nnoncomputable def to_equiv (hS : S \u2208 subgroup.right_transversals (H : set G)) :\n  quotient (quotient_group.right_rel H) \u2243 S :=\n(equiv.of_bijective _ (subgroup.mem_right_transversals_iff_bijective.mp hS)).symm\n\n@[to_additive] lemma mk'_to_equiv (hS : S \u2208 subgroup.right_transversals (H : set G))\n  (q : quotient (quotient_group.right_rel H)) : quotient.mk' (to_equiv hS q : G) = q :=\n(to_equiv hS).symm_apply_apply q\n\n@[to_additive] lemma to_equiv_apply {f : quotient (quotient_group.right_rel H) \u2192 G}\n  (hf : \u2200 q, quotient.mk' (f q) = q) (q : quotient (quotient_group.right_rel H)) :\n  (to_equiv (range_mem_right_transversals hf) q : G) = f q :=\nbegin\n  refine (subtype.ext_iff.mp _).trans (subtype.coe_mk (f q) \u27e8q, rfl\u27e9),\n  exact (to_equiv (range_mem_right_transversals hf)).apply_eq_iff_eq_symm_apply.mpr (hf q).symm,\nend\n\n/-- A right transversal can be viewed as a function mapping each element of the group\n  to the chosen representative from that right coset. -/\n@[to_additive \"A right transversal can be viewed as a function mapping each element of the group\n  to the chosen representative from that right coset.\"]\nnoncomputable def to_fun (hS : S \u2208 subgroup.right_transversals (H : set G)) : G \u2192 S :=\nto_equiv hS \u2218 quotient.mk'\n\n@[to_additive] lemma mul_inv_to_fun_mem (hS : S \u2208 subgroup.right_transversals (H : set G))\n  (g : G) : g * (to_fun hS g : G)\u207b\u00b9 \u2208 H :=\nquotient_group.right_rel_apply.mp $ quotient.exact' $ mk'_to_equiv _ _\n\n@[to_additive] lemma to_fun_mul_inv_mem (hS : S \u2208 subgroup.right_transversals (H : set G))\n  (g : G) : (to_fun hS g : G) * g\u207b\u00b9 \u2208 H :=\n(congr_arg (\u2208 H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (mul_inv_to_fun_mem hS g))\n\nend mem_right_transversals\n\nsection action\n\nopen_locale pointwise\n\nopen mul_action mem_left_transversals\n\nvariables {F : Type*} [group F] [mul_action F G] [quotient_action F H]\n\n@[to_additive] instance : mul_action F (left_transversals (H : set G)) :=\n{ smul := \u03bb f T, \u27e8f \u2022 T, by\n  { refine mem_left_transversals_iff_exists_unique_inv_mul_mem.mpr (\u03bb g, _),\n    obtain \u27e8t, ht1, ht2\u27e9 := mem_left_transversals_iff_exists_unique_inv_mul_mem.mp T.2 (f\u207b\u00b9 \u2022 g),\n    refine \u27e8\u27e8f \u2022 t, set.smul_mem_smul_set t.2\u27e9, _, _\u27e9,\n    { exact (congr_arg _ (smul_inv_smul f g)).mp (quotient_action.inv_mul_mem f ht1) },\n    { rintros \u27e8-, t', ht', rfl\u27e9 h,\n      replace h := quotient_action.inv_mul_mem f\u207b\u00b9 h,\n      simp only [subtype.ext_iff, subtype.coe_mk, smul_left_cancel_iff, inv_smul_smul] at h \u22a2,\n      exact subtype.ext_iff.mp (ht2 \u27e8t', ht'\u27e9 h) } }\u27e9,\n  one_smul := \u03bb T, subtype.ext (one_smul F T),\n  mul_smul := \u03bb f\u2081 f\u2082 T, subtype.ext (mul_smul f\u2081 f\u2082 T) }\n\n@[to_additive] lemma smul_to_fun (f : F) (T : left_transversals (H : set G)) (g : G) :\n  (f \u2022 to_fun T.2 g : G) = to_fun (f \u2022 T).2 (f \u2022 g) :=\nsubtype.ext_iff.mp $ @unique_of_exists_unique \u21a5(f \u2022 T) (\u03bb s, (\u2191s)\u207b\u00b9 * f \u2022 g \u2208 H)\n  (mem_left_transversals_iff_exists_unique_inv_mul_mem.mp (f \u2022 T).2 (f \u2022 g))\n  \u27e8f \u2022 to_fun T.2 g, set.smul_mem_smul_set (subtype.coe_prop _)\u27e9 (to_fun (f \u2022 T).2 (f \u2022 g))\n  (quotient_action.inv_mul_mem f (inv_to_fun_mul_mem T.2 g)) (inv_to_fun_mul_mem (f \u2022 T).2 (f \u2022 g))\n\n@[to_additive] lemma smul_to_equiv (f : F) (T : left_transversals (H : set G)) (q : G \u29f8 H) :\n  f \u2022 (to_equiv T.2 q : G) = to_equiv (f \u2022 T).2 (f \u2022 q) :=\nquotient.induction_on' q (\u03bb g, smul_to_fun f T g)\n\n@[to_additive] lemma smul_apply_eq_smul_apply_inv_smul (f : F) (T : left_transversals (H : set G))\n  (q : G \u29f8 H) : (to_equiv (f \u2022 T).2 q : G) = f \u2022 (to_equiv T.2 (f\u207b\u00b9 \u2022 q) : G) :=\nby rw [smul_to_equiv, smul_inv_smul]\n\nend action\n\n@[to_additive] instance : inhabited (left_transversals (H : set G)) :=\n\u27e8\u27e8set.range quotient.out', range_mem_left_transversals quotient.out_eq'\u27e9\u27e9\n\n@[to_additive] instance : inhabited (right_transversals (H : set G)) :=\n\u27e8\u27e8set.range quotient.out', range_mem_right_transversals quotient.out_eq'\u27e9\u27e9\n\nlemma is_complement'.is_compl (h : is_complement' H K) : is_compl H K :=\nbegin\n  refine \u27e8\u03bb g \u27e8p, q\u27e9, let x : H \u00d7 K := \u27e8\u27e8g, p\u27e9, 1\u27e9, y : H \u00d7 K := \u27e81, g, q\u27e9 in subtype.ext_iff.mp\n    (prod.ext_iff.mp (show x = y, from h.1 ((mul_one g).trans (one_mul g).symm))).1, \u03bb g _, _\u27e9,\n  obtain \u27e8\u27e8h, k\u27e9, rfl\u27e9 := h.2 g,\n  exact subgroup.mul_mem_sup h.2 k.2,\nend\n\nlemma is_complement'.sup_eq_top (h : subgroup.is_complement' H K) : H \u2294 K = \u22a4 :=\nh.is_compl.sup_eq_top\n\nlemma is_complement'.disjoint (h : is_complement' H K) : disjoint H K :=\nh.is_compl.disjoint\n\nlemma is_complement.card_mul [fintype G] [fintype S] [fintype T] (h : is_complement S T) :\n  fintype.card S * fintype.card T = fintype.card G :=\n(fintype.card_prod _ _).symm.trans (fintype.card_of_bijective h)\n\nlemma is_complement'.card_mul [fintype G] [fintype H] [fintype K] (h : is_complement' H K) :\n  fintype.card H * fintype.card K = fintype.card G :=\nh.card_mul\n\nlemma is_complement'_of_card_mul_and_disjoint [fintype G] [fintype H] [fintype K]\n  (h1 : fintype.card H * fintype.card K = fintype.card G) (h2 : disjoint H K) :\n  is_complement' H K :=\nbegin\n  refine (fintype.bijective_iff_injective_and_card _).mpr\n    \u27e8\u03bb x y h, _, (fintype.card_prod H K).trans h1\u27e9,\n  rw [\u2190eq_inv_mul_iff_mul_eq, \u2190mul_assoc, \u2190mul_inv_eq_iff_eq_mul] at h,\n  change \u2191(x.2 * y.2\u207b\u00b9) = \u2191(x.1\u207b\u00b9 * y.1) at h,\n  rw [prod.ext_iff, \u2190@inv_mul_eq_one H _ x.1 y.1, \u2190@mul_inv_eq_one K _ x.2 y.2, subtype.ext_iff,\n      subtype.ext_iff, coe_one, coe_one, h, and_self, \u2190mem_bot, \u2190h2.eq_bot, mem_inf],\n  exact \u27e8subtype.mem ((x.1)\u207b\u00b9 * (y.1)), (congr_arg (\u2208 K) h).mp (subtype.mem (x.2 * (y.2)\u207b\u00b9))\u27e9,\nend\n\nlemma is_complement'_iff_card_mul_and_disjoint [fintype G] [fintype H] [fintype K] :\n  is_complement' H K \u2194\n    fintype.card H * fintype.card K = fintype.card G \u2227 disjoint H K :=\n\u27e8\u03bb h, \u27e8h.card_mul, h.disjoint\u27e9, \u03bb h, is_complement'_of_card_mul_and_disjoint h.1 h.2\u27e9\n\nlemma is_complement'_of_coprime [fintype G] [fintype H] [fintype K]\n  (h1 : fintype.card H * fintype.card K = fintype.card G)\n  (h2 : nat.coprime (fintype.card H) (fintype.card K)) :\n  is_complement' H K :=\nis_complement'_of_card_mul_and_disjoint h1 (disjoint_iff.mpr (inf_eq_bot_of_coprime h2))\n\nlemma is_complement'_stabilizer {\u03b1 : Type*} [mul_action G \u03b1] (a : \u03b1)\n  (h1 : \u2200 (h : H), h \u2022 a = a \u2192 h = 1) (h2 : \u2200 g : G, \u2203 h : H, h \u2022 (g \u2022 a) = a) :\n  is_complement' H (mul_action.stabilizer G a) :=\nbegin\n  refine is_complement_iff_exists_unique.mpr (\u03bb g, _),\n  obtain \u27e8h, hh\u27e9 := h2 g,\n  have hh' : (\u2191h * g) \u2022 a = a := by rwa [mul_smul],\n  refine \u27e8\u27e8h\u207b\u00b9, h * g, hh'\u27e9, inv_mul_cancel_left h g, _\u27e9,\n  rintros \u27e8h', g, hg : g \u2022 a = a\u27e9 rfl,\n  specialize h1 (h * h') (by rwa [mul_smul, smul_def h', \u2190hg, \u2190mul_smul, hg]),\n  refine prod.ext (eq_inv_of_mul_eq_one_right h1) (subtype.ext _),\n  rwa [subtype.ext_iff, coe_one, coe_mul, \u2190self_eq_mul_left, mul_assoc \u2191h \u2191h' g] at h1,\nend\n\nend subgroup\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/group_theory/complement.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303678, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7255226136620917}}
{"text": "/- \ntaken from a comment by Junyan Xu on \nhttps://leanprover-community.github.io/archive/stream/113489-new-members/topic/Generalization.20of.20map_diff.html\n-/\nimport data.multiset.basic\nopen multiset\nvariables {\u03b1 \u03b2 : Type*} [decidable_eq \u03b1] [decidable_eq \u03b2] (f : \u03b1 \u2192 \u03b2)\n\nlemma multiset.map_diff_subset (s\u2081 : multiset \u03b1) (s\u2082 : multiset \u03b1) :\n  s\u2081.map f - s\u2082.map f \u2264 (s\u2081 - s\u2082).map f :=\nbegin\n  rw [tsub_le_iff_right, le_iff_count],\n  intro, simp only [count_add, count_map, \u2190 card_add, \u2190 filter_add],\n  exact card_le_of_le (filter_le_filter _ $ tsub_le_iff_right.1 le_rfl),\nend\n\nlemma list.map_diff_subset (l\u2081 : list \u03b1) (l\u2082 : list \u03b1) :\n  (l\u2081.map f).diff (l\u2082.map f) \u2286 (l\u2081.diff l\u2082).map f :=\nbegin\n  simp only [\u2190 coe_subset, \u2190 coe_sub, \u2190 coe_map],\n  exact subset_of_le (multiset.map_diff_subset f _ _),\nend", "meta": {"author": "pjrule", "repo": "cs208-project", "sha": "951d3a5a65f01e1ccb85db8eeff3da1b26e69196", "save_path": "github-repos/lean/pjrule-cs208-project", "path": "github-repos/lean/pjrule-cs208-project/cs208-project-951d3a5a65f01e1ccb85db8eeff3da1b26e69196/lean/opendp/src/junyan_multiset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7255226015082352}}
{"text": "/-\nCopyright (c) 2023 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\n\nimport algebra.monoid_algebra.division\nimport ring_theory.ideal.basic\n\n/-!\n# Lemmas about ideals of `monoid_algebra` and `add_monoid_algebra`\n-/\n\nvariables {k A G : Type*}\n\n/-- If `x` belongs to the ideal generated by generators in `s`, then every element of the support of\n`x` factors through an element of `s`.\n\nWe could spell `\u2203 d, m = d * m` as `mul_opposite.op m' \u2223 mul_opposite.op m` but this would be worse.\n-/\nlemma monoid_algebra.mem_ideal_span_of_image\n  [monoid G] [semiring k] {s : set G} {x : monoid_algebra k G} :\n  x \u2208 ideal.span (monoid_algebra.of k G '' s) \u2194 \u2200 m \u2208 x.support, \u2203 m' \u2208 s, \u2203 d, m = d * m' :=\nbegin\n  let RHS : ideal (monoid_algebra k G) :=\n  { carrier := {p | \u2200 (m : G), m \u2208 p.support \u2192 \u2203 m' \u2208 s, \u2203 d, m = d * m'},\n    add_mem' := \u03bb x y hx hy m hm, by classical;\n      exact (finset.mem_union.1 $ finsupp.support_add hm).elim (hx m) (hy m),\n    zero_mem' := \u03bb m hm, by cases hm,\n    smul_mem' := \u03bb x y hy m hm, begin\n      replace hm := finset.mem_bUnion.mp (finsupp.support_sum hm),\n      obtain \u27e8xm, hxm, hm\u27e9 := hm,\n      replace hm := finset.mem_bUnion.mp (finsupp.support_sum hm),\n      obtain \u27e8ym, hym, hm\u27e9 := hm,\n      replace hm := finset.mem_singleton.mp (finsupp.support_single_subset hm),\n      obtain rfl := hm,\n      refine (hy _ hym).imp (\u03bb sm, Exists.imp $ \u03bb hsm, _),\n      rintros \u27e8d, rfl\u27e9,\n      exact \u27e8xm * d, (mul_assoc _ _ _).symm\u27e9,\n    end },\n  change _ \u2194 x \u2208 RHS,\n  split,\n  { revert x,\n    refine ideal.span_le.2 _,\n    rintro _ \u27e8i, hi, rfl\u27e9 m hm,\n    refine \u27e8_, hi, 1, _\u27e9,\n    obtain rfl := finset.mem_singleton.mp (finsupp.support_single_subset hm),\n    exact (one_mul _).symm },\n  { intros hx,\n    rw \u2190finsupp.sum_single x,\n    apply ideal.sum_mem _ (\u03bb i hi, _),\n    obtain \u27e8d, hd, d2, rfl\u27e9 := hx _ hi,\n    convert ideal.mul_mem_left _ (id $ finsupp.single d2 $ (x (d2 * d)) : monoid_algebra k G) _,\n    swap 3,\n    refine ideal.subset_span \u27e8_, hd, rfl\u27e9,\n    rw [id.def, monoid_algebra.of_apply, monoid_algebra.single_mul_single, mul_one] },\nend\n\n/-- If `x` belongs to the ideal generated by generators in `s`, then every element of the support of\n`x` factors additively through an element of `s`.\n-/\nlemma add_monoid_algebra.mem_ideal_span_of'_image\n  [add_monoid A] [semiring k] {s : set A} {x : add_monoid_algebra k A} :\n  x \u2208 ideal.span (add_monoid_algebra.of' k A '' s) \u2194 \u2200 m \u2208 x.support, \u2203 m' \u2208 s, \u2203 d, m = d + m' :=\n@monoid_algebra.mem_ideal_span_of_image k (multiplicative A) _ _ _ _\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/monoid_algebra/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7255189182711878}}
{"text": "/-\nCopyright (c) 2014 Robert Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module algebra.order.field.pi\n! leanprover-community/mathlib commit 509de852e1de55e1efa8eacfa11df0823f26f226\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.Field.Basic\nimport Mathlib.Data.Fintype.Lattice\n\n/-!\n# Lemmas about (finite domain) functions into fields.\n\nWe split this from `Algebra.Order.Field.Basic` to avoid importing the finiteness hierarchy there.\n-/\n\n\nvariable {\u03b1 \u03b9 : Type _} [LinearOrderedSemifield \u03b1]\n\ntheorem Pi.exists_forall_pos_add_lt [ExistsAddOfLE \u03b1] [Finite \u03b9] {x y : \u03b9 \u2192 \u03b1}\n    (h : \u2200 i, x i < y i) : \u2203 \u03b5, 0 < \u03b5 \u2227 \u2200 i, x i + \u03b5 < y i := by\n  cases nonempty_fintype \u03b9\n  cases isEmpty_or_nonempty \u03b9\n  \u00b7 exact \u27e81, zero_lt_one, isEmptyElim\u27e9\n  choose \u03b5 h\u03b5 hx\u03b5 using fun i => exists_pos_add_of_lt' (h i)\n  obtain rfl : x + \u03b5 = y := funext hx\u03b5\n  have h\u03b5 : 0 < Finset.univ.inf' Finset.univ_nonempty \u03b5 := (Finset.lt_inf'_iff _).2 fun i _ => h\u03b5 _\n  exact\n    \u27e8_, half_pos h\u03b5, fun i =>\n      add_lt_add_left ((half_lt_self h\u03b5).trans_le <| Finset.inf'_le _ <| Finset.mem_univ _) _\u27e9\n#align pi.exists_forall_pos_add_lt Pi.exists_forall_pos_add_lt\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/Field/Pi.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7255189108131185}}
{"text": "/-\nCopyright (c) 2020 Benjamin Davidson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Benjamin Davidson\n\n! This file was ported from Lean 3 source module data.real.pi.leibniz\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv\n\n/-! ### Leibniz's Series for Pi -/\n\n\nnamespace Real\n\nopen Filter Set\n\nopen Classical BigOperators Topology Real\n\n-- mathport name: abs\nlocal notation \"|\" x \"|\" => abs x\n\n/-- This theorem establishes **Leibniz's series for `\u03c0`**: The alternating sum of the reciprocals\n  of the odd numbers is `\u03c0/4`. Note that this is a conditionally rather than absolutely convergent\n  series. The main tool that this proof uses is the Mean Value Theorem (specifically avoiding the\n  Fundamental Theorem of Calculus).\n\n  Intuitively, the theorem holds because Leibniz's series is the Taylor series of `arctan x`\n  centered about `0` and evaluated at the value `x = 1`. Therefore, much of this proof consists of\n  reasoning about a function\n    `f := arctan x - \u2211 i in finset.range k, (-(1:\u211d))^i * x^(2*i+1) / (2*i+1)`,\n  the difference between `arctan` and the `k`-th partial sum of its Taylor series. Some ingenuity is\n  required due to the fact that the Taylor series is not absolutely convergent at `x = 1`.\n\n  This proof requires a bound on `f 1`, the key idea being that `f 1` can be split as the sum of\n  `f 1 - f u` and `f u`, where `u` is a sequence of values in [0,1], carefully chosen such that\n  each of these two terms can be controlled (in different ways).\n\n  We begin the proof by (1) introducing that sequence `u` and then proving that another sequence\n  constructed from `u` tends to `0` at `+\u221e`. After (2) converting the limit in our goal to an\n  inequality, we (3) introduce the auxiliary function `f` defined above. Next, we (4) compute the\n  derivative of `f`, denoted by `f'`, first generally and then on each of two subintervals of [0,1].\n  We then (5) prove a bound for `f'`, again both generally as well as on each of the two\n  subintervals. Finally, we (6) apply the Mean Value Theorem twice, obtaining bounds on `f 1 - f u`\n  and `f u - f 0` from the bounds on `f'` (note that `f 0 = 0`). -/\ntheorem tendsto_sum_pi_div_four :\n    Tendsto (fun k => \u2211 i in Finset.range k, (-(1 : \u211d)) ^ i / (2 * i + 1)) atTop (\ud835\udcdd (\u03c0 / 4)) :=\n  by\n  rw [tendsto_iff_norm_tendsto_zero, \u2190 tendsto_zero_iff_norm_tendsto_zero]\n  -- (1) We introduce a useful sequence `u` of values in [0,1], then prove that another sequence\n  --     constructed from `u` tends to `0` at `+\u221e`\n  let u := fun k : \u2115 => (k : NNReal) ^ (-1 / (2 * (k : \u211d) + 1))\n  have H : tendsto (fun k : \u2115 => (1 : \u211d) - u k + u k ^ (2 * (k : \u211d) + 1)) at_top (\ud835\udcdd 0) :=\n    by\n    convert(((tendsto_rpow_div_mul_add (-1) 2 1 two_ne_zero.symm).neg.const_add 1).add\n            tendsto_inv_atTop_zero).comp\n        tendsto_nat_cast_atTop_atTop\n    \u00b7 ext k\n      simp only [NNReal.coe_nat_cast, Function.comp_apply, NNReal.coe_rpow]\n      rw [\u2190 rpow_mul (Nat.cast_nonneg k) (-1 / (2 * (k : \u211d) + 1)) (2 * (k : \u211d) + 1),\n        @div_mul_cancel _ _ (2 * (k : \u211d) + 1) _\n          (by\n            norm_cast\n            simp only [Nat.succ_ne_zero, not_false_iff]),\n        rpow_neg_one k, sub_eq_add_neg]\n    \u00b7 simp only [add_zero, add_right_neg]\n  -- (2) We convert the limit in our goal to an inequality\n  refine' squeeze_zero_norm _ H\n  intro k\n  -- Since `k` is now fixed, we henceforth denote `u k` as `U`\n  let U := u k\n  -- (3) We introduce an auxiliary function `f`\n  let b (i : \u2115) x := (-(1 : \u211d)) ^ i * x ^ (2 * i + 1) / (2 * i + 1)\n  let f x := arctan x - \u2211 i in Finset.range k, b i x\n  suffices f_bound : |f 1 - f 0| \u2264 (1 : \u211d) - U + U ^ (2 * (k : \u211d) + 1)\n  \u00b7 rw [\u2190 norm_neg]\n    convert f_bound\n    simp only [f]\n    simp [b]\n  -- We show that `U` is indeed in [0,1]\n  have hU1 : (U : \u211d) \u2264 1 := by\n    by_cases hk : k = 0\n    \u00b7 simp [u, U, hk]\n    \u00b7\n      exact\n        rpow_le_one_of_one_le_of_nonpos\n          (by\n            norm_cast\n            exact nat.succ_le_iff.mpr (Nat.pos_of_ne_zero hk))\n          (le_of_lt\n            (@div_neg_of_neg_of_pos _ _ (-(1 : \u211d)) (2 * k + 1) (neg_neg_iff_pos.mpr zero_lt_one)\n              (by\n                norm_cast\n                exact Nat.succ_pos')))\n  have hU2 := NNReal.coe_nonneg U\n  -- (4) We compute the derivative of `f`, denoted by `f'`\n  let f' := fun x : \u211d => (-x ^ 2) ^ k / (1 + x ^ 2)\n  have has_deriv_at_f : \u2200 x, HasDerivAt f (f' x) x :=\n    by\n    intro x\n    have has_deriv_at_b : \u2200 i \u2208 Finset.range k, HasDerivAt (b i) ((-x ^ 2) ^ i) x :=\n      by\n      intro i hi\n      convert HasDerivAt.const_mul ((-1 : \u211d) ^ i / (2 * i + 1))\n          (@HasDerivAt.pow _ _ _ _ _ (2 * i + 1) (hasDerivAt_id x))\n      \u00b7 ext y\n        simp only [b, id.def]\n        ring\n      \u00b7 simp only [Nat.add_succ_sub_one, add_zero, mul_one, id.def, Nat.cast_bit0, Nat.cast_add,\n          Nat.cast_one, Nat.cast_mul]\n        rw [\u2190 mul_assoc,\n          @div_mul_cancel _ _ (2 * (i : \u211d) + 1) _\n            (by\n              norm_cast\n              linarith),\n          pow_mul x 2 i, \u2190 mul_pow (-1) (x ^ 2) i]\n        ring_nf\n    convert(has_deriv_at_arctan x).sub (HasDerivAt.sum has_deriv_at_b)\n    have g_sum :=\n      @geom_sum_eq _ _ (-x ^ 2) ((neg_nonpos.mpr (sq_nonneg x)).trans_lt zero_lt_one).Ne k\n    simp only [f'] at g_sum\u22a2\n    rw [g_sum, \u2190 neg_add' (x ^ 2) 1, add_comm (x ^ 2) 1, sub_eq_add_neg, neg_div', neg_div_neg_eq]\n    ring\n  have hderiv1 : \u2200 x \u2208 Icc (U : \u211d) 1, HasDerivWithinAt f (f' x) (Icc (U : \u211d) 1) x := fun x hx =>\n    (has_deriv_at_f x).HasDerivWithinAt\n  have hderiv2 : \u2200 x \u2208 Icc 0 (U : \u211d), HasDerivWithinAt f (f' x) (Icc 0 (U : \u211d)) x := fun x hx =>\n    (has_deriv_at_f x).HasDerivWithinAt\n  -- (5) We prove a general bound for `f'` and then more precise bounds on each of two subintervals\n  have f'_bound : \u2200 x \u2208 Icc (-1 : \u211d) 1, |f' x| \u2264 |x| ^ (2 * k) :=\n    by\n    intro x hx\n    rw [abs_div, IsAbsoluteValue.abv_pow abs (-x ^ 2) k, abs_neg, IsAbsoluteValue.abv_pow abs x 2, \u2190\n      pow_mul]\n    refine' div_le_of_nonneg_of_le_mul (abs_nonneg _) (pow_nonneg (abs_nonneg _) _) _\n    refine' le_mul_of_one_le_right (pow_nonneg (abs_nonneg _) _) _\n    rw [abs_of_nonneg (add_nonneg zero_le_one (sq_nonneg x) : (0 : \u211d) \u2264 _)]\n    exact (le_add_of_nonneg_right (sq_nonneg x) : (1 : \u211d) \u2264 _)\n  have hbound1 : \u2200 x \u2208 Ico (U : \u211d) 1, |f' x| \u2264 1 :=\n    by\n    rintro x \u27e8hx_left, hx_right\u27e9\n    have hincr := pow_le_pow_of_le_left (le_trans hU2 hx_left) (le_of_lt hx_right) (2 * k)\n    rw [one_pow (2 * k), \u2190 abs_of_nonneg (le_trans hU2 hx_left)] at hincr\n    rw [\u2190 abs_of_nonneg (le_trans hU2 hx_left)] at hx_right\n    linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_of_lt hx_right)))]\n  have hbound2 : \u2200 x \u2208 Ico 0 (U : \u211d), |f' x| \u2264 U ^ (2 * k) :=\n    by\n    rintro x \u27e8hx_left, hx_right\u27e9\n    have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2 * k)\n    rw [\u2190 abs_of_nonneg hx_left] at hincr hx_right\n    rw [\u2190 abs_of_nonneg hU2] at hU1 hx_right\n    linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_trans (le_of_lt hx_right) hU1)))]\n  -- (6) We twice apply the Mean Value Theorem to obtain bounds on `f` from the bounds on `f'`\n  have mvt1 := norm_image_sub_le_of_norm_deriv_le_segment' hderiv1 hbound1 _ (right_mem_Icc.mpr hU1)\n  have mvt2 := norm_image_sub_le_of_norm_deriv_le_segment' hderiv2 hbound2 _ (right_mem_Icc.mpr hU2)\n  -- The following algebra is enough to complete the proof\n  calc\n    |f 1 - f 0| = |f 1 - f U + (f U - f 0)| := by ring_nf\n    _ \u2264 1 * (1 - U) + U ^ (2 * k) * (U - 0) :=\n      (le_trans (abs_add (f 1 - f U) (f U - f 0)) (add_le_add mvt1 mvt2))\n    _ = 1 - U + U ^ (2 * k) * U := by ring\n    _ = 1 - u k + u k ^ (2 * (k : \u211d) + 1) :=\n      by\n      rw [\u2190 pow_succ' (U : \u211d) (2 * k)]\n      norm_cast\n    \n#align real.tendsto_sum_pi_div_four Real.tendsto_sum_pi_div_four\n\nend Real\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Real/Pi/Leibniz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7255022477540741}}
{"text": "-- Si a es un punto de acumulaci\u00f3n de la sucesi\u00f3n de Cauchy u, entonces a es el l\u00edmite de u\n-- ========================================================================================\n\nimport data.real.basic\n\nvariable  {u : \u2115 \u2192 \u211d}\nvariables {a : \u211d}\nvariable  {\u03c6 : \u2115 \u2192 \u2115}\n\n-- ----------------------------------------------------\n-- Nota. Usaremos los siguientes conceptos estudiados\n-- anteriormente.\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\ndef limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n\u03bb u c, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - c| \u2264 \u03b5\n\ndef extraccion : (\u2115 \u2192 \u2115) \u2192 Prop\n| \u03c6 := \u2200 n m, n < m \u2192 \u03c6 n < \u03c6 m\n\nlemma id_mne_extraccion\n  (h : extraccion \u03c6)\n  : \u2200 n, n \u2264 \u03c6 n :=\nbegin\n  intros n,\n  induction n with m HI,\n  { linarith },\n  { exact nat.succ_le_of_lt (by linarith [h m (m+1) (by linarith)]) },\nend\n\nlemma extraccion_mye\n  (h : extraccion \u03c6)\n  : \u2200 N N', \u2203 n \u2265 N', \u03c6 n \u2265 N :=\n\u03bb N N',\n  \u27e8max N N', le_max_right N N',\n             le_trans (le_max_left N N')\n             (id_mne_extraccion h (max N N'))\u27e9\n\ndef punto_acumulacion : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop\n| u a := \u2203 \u03c6, extraccion \u03c6 \u2227 limite (u \u2218 \u03c6) a\n\nlemma cerca_acumulacion\n  (h : punto_acumulacion u a)\n  : \u2200 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |u n - a| \u2264 \u03b5 :=\nbegin\n  intros \u03b5 h\u03b5 N,\n  rcases h with \u27e8\u03c6, h\u03c61, h\u03c62\u27e9,\n  cases h\u03c62 \u03b5 h\u03b5 with N' hN',\n  rcases extraccion_mye h\u03c61 N N' with \u27e8m, hm, hm'\u27e9,\n  exact \u27e8\u03c6 m, hm', hN' _ hm\u27e9,\nend\n\ndef sucesion_de_Cauchy : (\u2115 \u2192 \u211d) \u2192 Prop\n| u := \u2200 \u03b5 > 0, \u2203 N, \u2200 p q, p \u2265 N \u2192 q \u2265 N \u2192 |u p - u q| \u2264 \u03b5\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que si u es una sucesi\u00f3n de\n-- Cauchy y a es un punto de acumulaci\u00f3n de u, entonces\n-- a es el l\u00edmite de u.\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (hu : sucesion_de_Cauchy u)\n  (ha : punto_acumulacion u a)\n  : limite u a :=\nbegin\n  -- unfold limite,\n  intros \u03b5 h\u03b5,\n  -- unfold sucesion_de_Cauchy at hu,\n  cases hu (\u03b5/2) (half_pos h\u03b5) with N hN,\n  use N,\n  have ha' : \u2203 N' \u2265 N, |u N' - a| \u2264 \u03b5/2,\n    apply cerca_acumulacion ha (\u03b5/2) (half_pos h\u03b5),\n  cases ha' with N' h,\n  cases h with hNN' hN',\n  intros n hn,\n  calc   |u n - a|\n       = |(u n - u N') + (u N' - a)| : by ring\n   ... \u2264 |u n - u N'| + |u N' - a|   : abs_add (u n - u N') (u N' - a)\n   ... \u2264 \u03b5/2 + |u N' - a|            : add_le_add_right (hN n N' hn hNN') _\n   ... \u2264 \u03b5/2 + \u03b5/2                   : add_le_add_left hN' (\u03b5 / 2)\n   ... = \u03b5                           : add_halves \u03b5\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (hu : sucesion_de_Cauchy u)\n  (ha : punto_acumulacion u a)\n  : limite u a :=\nbegin\n  intros \u03b5 h\u03b5,\n  cases hu (\u03b5/2) (by linarith) with N hN,\n  use N,\n  have ha' : \u2203 N' \u2265 N, |u N' - a| \u2264 \u03b5/2,\n    apply cerca_acumulacion ha (\u03b5/2) (by linarith),\n  rcases ha' with \u27e8N', hNN', hN'\u27e9,\n  intros n hn,\n  calc  |u n - a|\n      = |(u n - u N') + (u N' - a)| : by ring\n  ... \u2264 |u n - u N'| + |u N' - a|   : by simp [abs_add]\n  ... \u2264 \u03b5                           : by linarith [hN n N' hn hNN'],\nend\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/5_Limites/cauchy_acumulacion_limite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7255022394641477}}
{"text": "import game.order.level08\nopen real\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 9\n\nThis level invites you to work out a property of the absolute value.\nIn Lean the absolute value of $x$ is denoted by `abs x`. \nFor ease of use, a notation can be used around that definition as below.\nFeel free to use the triangle inequality on the real numbers,\n\n`abs_add : \u2200 (a b : ?M_1), |a + b| \u2264 |a| + |b|`\n\ntogether with the `linarith` and `norm_num` tactics.\n-/\n\nnotation `|` x `|` := abs x\n\n-- begin hide\n-- this to go in the side bar\nlemma eq_sqr_to_eq (a b : \u211d) (ha : 0 \u2264 a) (hb : 0 \u2264 b) : a^2 = b^2 \u2192 a = b :=\nbegin\n    intro H,\n    have A : sqrt (a ^ 2) = sqrt (a ^ 2), refl,\n    rw H at A {occs := occurrences.pos [2]},\n    have G := sqrt_sqr ha, rw G at A,\n    have F := sqrt_sqr hb, rw F at A, \n    exact A, done\nend\n-- end hide\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$|a + b| = |a| + |b|$$ if and only if $ab \\ge 0$ .\n-/\ntheorem abs_sub_eq_sum_abs (a b : \u211d) : |a + b| = |a| + |b| \u2194 a * b \u2265 0 :=\nbegin\n    have H0 : (a+b)^2 = |a+b|^2, \n        have h01 := abs_mul_abs_self (a+b),\n        rw pow_two _, rw pow_two _, symmetry, exact h01,\n    have H1 : 0 \u2264 (a + b) ^ 2, exact pow_two_nonneg (a+b),\n    have H2 : (a+b) ^ 2 = a ^2 + 2 * a * b + b^2, ring,\n    have H3 : ( |a| + |b| )^2 = |a|^2 + 2*|a|*|b| + |b|^2, ring,\n    rw H0 at H2,\n    have Ha : a^2 = |a|^2, \n        have h01 := abs_mul_abs_self a,\n        rw pow_two _, rw pow_two _, symmetry, exact h01,\n    have Hb : b^2 = |b|^2, \n        have h01 := abs_mul_abs_self b,\n        rw pow_two _, rw pow_two _, symmetry, exact h01,\n    rw [Ha, Hb] at H2,\n    split,\n    intro h,\n    rw h at H2, rw H3 at H2, simp at H2, \n    rw mul_assoc at H2, rw mul_assoc at H2,\n    have g1 : ( |a| * |b| ) = (a * b), linarith,\n    have g2 : |a * b| = ( |a| * |b| ), exact abs_mul _ _, \n    rw \u2190 g2 at g1,\n    by_contradiction hn, push_neg at hn,\n    have g3 : | a * b | = - (a *b), exact abs_of_neg hn,\n    rw g1 at g3, linarith,\n    -- the right-left direction\n    intro h,\n    have g1 : |a * b| = a * b, exact abs_of_nonneg h,\n    have g2 : |a * b| = ( |a| * |b| ), exact abs_mul _ _,\n    rw g2 at g1, rw mul_assoc 2 a b at H2,\n    rw \u2190 g1 at H2,\n    have g3 : |a| ^ 2 + 2 * ( |a| * |b| ) + |b| ^ 2 = ( |a| + |b| )^2, ring,\n    rw g3 at H2,\n    have g4 : sqrt ( |a + b| ^ 2 ) = sqrt ( |a + b| ^ 2), refl,\n    rw H2 at g4 {occs := occurrences.pos [2]},\n    have hab : 0 \u2264 |a + b|,  exact is_absolute_value.abv_nonneg abs (a+b),\n    have ha : 0 \u2264 |a|,  exact is_absolute_value.abv_nonneg abs a,\n    have hb : 0 \u2264 |b|,  exact is_absolute_value.abv_nonneg abs b,\n    have hc : 0 \u2264 |a| + |b|, linarith,\n    have G := eq_sqr_to_eq ( |a + b| ) ( |a| + |b| ) hab hc H2, exact G, done\nend\n\nend xena -- hide\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level09.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7255022373362938}}
{"text": "\nimport set_theory.cardinal.basic\nimport set_theory.cardinal.finite\nimport set_theory.cardinal.ordinal\n\nuniverse u\n\nnamespace cardinal\nlemma eq_one_iff_exists_unique {\u03b1 : Type*}:\n  cardinal.mk \u03b1 = 1 \u2194 \u2203! (a: \u03b1), true :=\nbegin\n  rw [eq_one_iff_unique],\n  exact \u27e8 \n      \u03bb h, h.right.elim (\u03bb a, \u27e8a, trivial, \u03bb _ _, @subsingleton.elim _ h.left _ _ \u27e9) ,\n      \u03bb h, exists_unique.elim h (\u03bb a _ ha, and.intro\n        (subsingleton.intro (\u03bb x y, trans (ha x trivial) (ha y trivial).symm))\n        (nonempty.intro a)) \u27e9,\nend\n\ntheorem lt_aleph_0' {c : cardinal} (hc: c < aleph_0): \u2203 n : \u2115, (n: cardinal) = c :=\n  exists.elim (cardinal.lt_aleph_0.mp hc) (\u03bb n hn, \u27e8n, hn.symm\u27e9)\n\nlemma le_mk_diff_add_mk_of_lt_aleph_0 {\u03b1: Type*} {c: cardinal} {s t: set \u03b1} (ht: cardinal.mk t < cardinal.aleph_0): c + cardinal.mk t \u2264 cardinal.mk s \u2192 c \u2264 cardinal.mk (s \\ t : set \u03b1) :=\n\u03bb h, (cardinal.add_le_add_iff_of_lt_aleph_0 ht).mp (trans h (le_mk_diff_add_mk _ _))\n\nlemma to_nat_inj {a b: cardinal} (ha: a < aleph_0) (hb: b < aleph_0) (h: a.to_nat = b.to_nat):\n   a = b := le_antisymm\n      ((cardinal.to_nat_le_iff_le_of_lt_aleph_0 ha hb).mp (le_of_eq h))\n      ((cardinal.to_nat_le_iff_le_of_lt_aleph_0 hb ha).mp (ge_of_eq h))\n\nlemma to_nat_inj_iff {a b: cardinal} (ha: a < aleph_0) (hb: b < aleph_0):\n  a.to_nat = b.to_nat \u2194 a = b :=\n    \u27e8 \u03bb h, to_nat_inj ha hb h, congr_arg _ \u27e9\n\nlemma nat_cast_add (n m: \u2115): ((n + m:\u2115): cardinal) = n + m :=\n  to_nat_inj (nat_lt_aleph_0 _) (add_lt_aleph_0 (nat_lt_aleph_0 _) (nat_lt_aleph_0 _)) (by simp)\n\ntheorem to_nat_even_iff (c: cardinal): even c \u2194 even c.to_nat :=\nbegin\n  split;\n  intro h;\n  cases h with x h,\n  { rw [h],\n    use to_nat x,\n    rw [\u2190 two_mul, \u2190 two_mul, to_nat_mul, \u2190 nat.cast_two, to_nat_cast] },\n  cases lt_or_ge c aleph_0 with hfin hinf,\n  { cases cardinal.lt_aleph_0' hfin with n hn,\n    induction hn,\n    rw [to_nat_cast] at h,\n    exact \u27e8 x, by rw [h, nat_cast_add] \u27e9 },\n  { exact \u27e8c, (add_eq_left hinf (le_refl _)).symm\u27e9 },\nend\n\ntheorem nat_mul_lt_aleph_0 (c: cardinal) {n: \u2115}: c < aleph_0 \u2192 (n:cardinal)*c < aleph_0 :=\nbegin\n  simp only [lt_aleph_0, forall_exists_index],\n  exact \u03bb m hm, \u27e8n * m, hm.symm \u25b8 (nat.cast_mul _ _).symm\u27e9\nend\n\n\ntheorem nat_mul_ge_aleph_0 (c: cardinal) {n: \u2115}: aleph_0 \u2264 c \u2192 n \u2260 0 \u2192 (n:cardinal)*c = c :=\nbegin\n  intros hc hn,\n  rwa [mul_eq_max_of_aleph_0_le_right _ hc, max_eq_right_iff.mpr _],\n  exact trans (le_of_lt (nat_lt_aleph_0 _)) hc,\n  rwa nat.cast_ne_zero,\nend\n\ntheorem nat_cast_left_mul_le_mul (c d: cardinal) {n: \u2115} (hn: 0 < n): (n:cardinal) * c \u2264 n * d \u2192 c \u2264 d :=\nbegin\n  by_cases hc: c < aleph_0;\n  by_cases hd: d < aleph_0,\n  { cases lt_aleph_0' hc with nc hc,\n    cases lt_aleph_0' hd with nd hd,\n    induction hc,\n    induction hd,\n    simpa only [\u2190 nat.cast_mul, nat.cast_le, mul_le_mul_left hn] using id },\n  { exact \u03bb _,  trans (le_of_lt hc) (le_of_not_gt hd) },\n  { intro h,\n    exfalso,\n    apply not_lt_of_ge h,\n    apply lt_of_lt_of_le (nat_mul_lt_aleph_0 _ hd),\n    rw [nat_mul_ge_aleph_0],\n    repeat { exact le_of_not_gt hc },\n    apply ne_of_gt hn },\n  { rw [nat_mul_ge_aleph_0, nat_mul_ge_aleph_0],\n    exact id,\n    any_goals { exact ne_of_gt hn },\n    { exact le_of_not_gt hd },\n    { exact le_of_not_gt hc },\n  },\nend\nend cardinal\n\n\nlemma set.cardinal_embedding {\u03b1: Type u} {s: set \u03b1} {c: cardinal.{u}}:\n  c \u2264 cardinal.mk s \u2192 \u2203 t: set \u03b1, cardinal.mk t = c \u2227 t \u2286 s :=\nbegin\n  intro hlt,\n  rw [\u2190 cardinal.mk_out c, cardinal.le_def] at hlt,\n  cases hlt,\n  use { v | \u2203 (hv : v \u2208 s) c, hlt.to_fun c = \u27e8v, hv\u27e9 },\n  refine \u27e8_, \u03bb hp, by simpa using \u03bb hp _ _, hp \u27e9,\n  conv_rhs { rw [\u2190 cardinal.mk_out c] },\n  apply eq.symm,\n  rw [cardinal.eq],\n  fconstructor,\n  refine equiv.of_bijective _ \u27e8_, _\u27e9,\n  { exact (\u03bb x, \u27e8 (hlt.to_fun x).val, by simp \u27e9) },\n  { intros c\u2081 c\u2082, simp [subtype.coe_inj] },\n  intros ha,\n  rcases ha with \u27e8a, ha, c', hc\u27e9,\n  use c',\n  revert hc,\n  simpa using congr_arg coe,\nend\n\nlemma set.cardinal_union_ge {\u03b1: Type*} (s t: set \u03b1):\n  cardinal.mk s \u2264 cardinal.mk (s \u222a t: set \u03b1) :=\n \u27e8 \u27e8  \u03bb a, \u27e8 a.val, or.inl a.property \u27e9, \u03bb a b, by simp [subtype.coe_inj] \u27e9 \u27e9\n\nlemma set.cardinal_union_of_aleph_0_le {\u03b1: Type*} (s t: set \u03b1):\n  cardinal.mk t \u2264 cardinal.mk s \u2192 cardinal.aleph_0 \u2264 cardinal.mk s \u2192 cardinal.mk (s \u222a t: set \u03b1) = cardinal.mk s :=\n  \u03bb h\u2081 h\u2082, le_antisymm\n    (trans (cardinal.mk_union_le _ _) (cardinal.add_le_of_le h\u2082 (le_refl _) h\u2081))\n    (cardinal.mk_le_mk_of_subset (set.subset_union_left _ _))", "meta": {"author": "calcu16", "repo": "lean_complexity", "sha": "0dcb73bde8d1d4237f782f4790166365ac3209fe", "save_path": "github-repos/lean/calcu16-lean_complexity", "path": "github-repos/lean/calcu16-lean_complexity/lean_complexity-0dcb73bde8d1d4237f782f4790166365ac3209fe/src/local/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7255022372624645}}
{"text": "import tactic\n\n#check mul_add\n#check dvd_mul_right\n\nvariables {a b c : \u2115}\n\n-- BEGIN\nexample (divab : a \u2223 b) (divac : a \u2223 c) : a \u2223 (b + c) :=\nbegin \n  cases divab with d beq,\n  cases divac with e ceq,\n  rw [beq, ceq],\n  rw \u2190 mul_add,\n  exact dvd_mul_right a (d + e),\nend\n\nexample (divab : a \u2223 b) (divac : a \u2223 c) : a \u2223 (b + c) :=\nbegin \n  cases divab with d beq,\n  cases divac with e ceq,\n  rw [beq, ceq],\n  rw \u2190 mul_add,\n  use (d + e),\nend\n-- END\n", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.1_cases_exist/ex9_cases_dvd_a(b+c).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7255022372255497}}
{"text": "/- Homework 3.1: Program Semantics \u2014 Operational Semantics -/\n\nattribute [pattern] or.intro_left or.intro_right\n\n\n/- Question 1: Semantics of regular expressions\n\nRegular expression are a very popular tool for software development. Often, when textual input needs\nto be analyzed it is matched against a regular expression. In this homework, we define the syntax of\nregular expressions and what it means that a regular expression matches a string.\n\nWe define `regex` to represent the following grammar:\n\n    R ::= c       \u2014 `char`: accepts one character `c`\n        | \u2205       \u2014 `nothing`: accepts nothing\n        | \u03b5       \u2014 `empty`: accepts the empty string\n        | R \u2b1d R    \u2014 `concat`: accepts the concatenation of two regexes\n        | R + R   \u2014 `alt`: accepts either of two regexes\n        | R*      \u2014 `star`: accept arbitrary many repetitions of a regex\n\nNotice the rough correspondence with a WHILE language:\n\n  `char`    ~ assignment\n (`nothing` ~ failing assertion)\n  `empty`   ~ `skip`\n  `concat`  ~ sequential composition\n  `alt`     ~ conditional statement\n  `star`    ~ while loop -/\n\n@[derive decidable_eq]\ninductive regex : Type\n| char    : char \u2192 regex\n| nothing : regex\n| empty   : regex\n| concat  : regex \u2192 regex \u2192 regex\n| alt     : regex \u2192 regex \u2192 regex\n| star    : regex \u2192 regex\n\n/- `accept r s`: the regular expression `r` accepts the string `s` -/\n\ninductive accept : regex \u2192 list char \u2192 Prop\n/- accept one character -/\n| char (c : char) :\n  accept (regex.char c) [c]\n/- accept the empty string -/\n| empty :\n  accept regex.empty []\n/- accept two concatenated regexes -/\n| concat {r\u2081 r\u2082 : regex} (s\u2081 s\u2082 : list char) (h\u2081 : accept r\u2081 s\u2081) (h\u2082 : accept r\u2082 s\u2082) :\n  accept (regex.concat r\u2081 r\u2082) (s\u2081 ++ s\u2082)\n/- accept the left alternative -/\n| alt_left {r\u2081 r\u2082 : regex} (s : list char) (h : accept r\u2081 s) :\n  accept (regex.alt r\u2081 r\u2082) s\n/- accept the right alternative -/\n| alt_right {r\u2081 r\u2082 : regex} (s : list char) (h : accept r\u2082 s) :\n  accept (regex.alt r\u2081 r\u2082) s\n/- accepts the empty string; this is the base case of `R*` -/\n| star_base {r : regex} : accept (regex.star r) []\n/- accepts `R` followed again by `R*`; this is the induction step of `R*` -/\n| star_step {r : regex} (s s' : list char) (h\u2081 : accept r s) (h\u2082 : accept (regex.star r) s') :\n  accept (regex.star r) (s ++ s')\n\n/- 1.1. Explain why there is no rule for `nothing`. -/\n\n/- Answer: There is no input nor output. So it would be weird to have a rule for nothing, as there is nothing.. -/\n\n/- 1.2. Prove the following inversion rules.\n\nThese proofs are very similar to the inversion rules in the lecture and in Question 2.1 of the\nexercise. -/\n\nvariables {s s\u2081 s\u2082 : list char} {r r\u2081 r\u2082  : regex} {c : char}\n\n@[simp] lemma accept_char : accept (regex.char c) s \u2194 s = [c] :=\nbegin\n  apply iff.intro,\n  intro h,\n  cases h,\n  trivial,\n  intro s,\n  cases s,\n  exact accept.char c\nend\n\n\n\n\n\n@[simp] lemma accept_nothing : \u00ac accept regex.nothing s:=\nbegin\n  intro s,\n  cases s\nend\n\n@[simp] lemma accept_empty : accept regex.empty s \u2194 s = [] :=\nbegin\n  apply iff.intro,\n  intro h,\n  cases h,\n  trivial,\n  intro h,\n  cases h,\n  exact accept.empty\nend\n\n@[simp] lemma accept_concat :\n  accept (regex.concat r\u2081 r\u2082) s \u2194 (\u2203s\u2081 s\u2082, accept r\u2081 s\u2081 \u2227 accept r\u2082 s\u2082 \u2227 s = s\u2081 ++ s\u2082) :=\n  begin\n    apply iff.intro,\n    intro h,\n    cases h,\n    apply exists.intro h_s\u2081,\n    apply exists.intro h_s\u2082,\n    apply and.intro,\n    assumption,\n    apply and.intro,\n    assumption,\n  \n  end\n\n@[simp] lemma accept_alt :\n  accept (regex.alt r\u2081 r\u2082) s \u2194 (accept r\u2081 s \u2228 accept r\u2082 s) :=\nbegin\n  apply iff.intro,\n  intro a,\n  cases a,\n  cases a_h,\n  apply or.inl,\n  assumption,\n  apply or.inl,\n  assumption,\n  apply or.inl,\n  assumption,\n  apply or.inl,\n  assumption,\n  apply or.inl,\n  assumption,\n  apply or.inl,\n  assumption,\n  apply or.inl,\n  assumption,\n  apply or.inr,\n  assumption,\n  intro b,\n  cases b,\n  exact accept.alt_left s b ,\n  exact accept.alt_right s b \nend\n\nlemma accept_star :\n  accept (regex.star r) s \u2194\n  (s = [] \u2228 (\u2203s\u2081 s\u2082, accept r s\u2081 \u2227 accept (regex.star r) s\u2082 \u2227 s = s\u2081 ++ s\u2082)) :=\nbegin\napply iff.intro,\nintro acc,\ncases s,\nsimp,\nrepeat{simp[accept.star_base, accept.star_step]},\nrepeat {apply exists.intro s_tl},\napply and.intro,\ncases s_tl,\ncases r,\nexact accept.empty, /-Does not work?-/\n\nend\n\n/- 1.3 **optional**. Prove a more sophisticated version of `accept_star`.\n\nThe previous rule `accept_star` has the problem that in the induction step, the accepted string for\n`r` could be empty. Now we want to **enforce** that the it is not empty, _without loss of\ngenerality_.\n\n*Hint*: In contrast to the other inversion rules, you now need to perform an induction. But the\narguments in our induction hypothesis `accept (regex.star r) (c :: s)` are not variables. So you\nwill need to generalize them. You can use `cases` to cope with the parts where the regex you handle\nis not of the form `regex.star r`. In the `accept.star_step` case, you might need to split on the\nstring first, and then use `cases` on the second generalized equality. -/\n\nlemma accept_star_cons :\n  accept (regex.star r) (c :: s) \u2192\n  \u2203s\u2081 s\u2082 : list char, accept r (c :: s\u2081) \u2227 accept (regex.star r) s\u2082 \u2227 s = s\u2081 ++ s\u2082 :=\nsorry\n\n\n/- Question 2 **optional**: Equivalence and matching of regular expressions -/\n\n/- We can prove equivalence between regular expressions, just like between programs. Two\nregular expressions are equivalent if they accept the same set of strings. -/\n\ndef regex_equiv (r\u2081 r\u2082 : regex) : Prop :=\n\u2200s, accept r\u2081 s \u2194 accept r\u2082 s\n\nlocal infix ` \u2248 ` := regex_equiv\n\n/- Program equivalence is a equivalence relation, i.e. it is reflexive, symmetric, and\ntransitive. -/\n\n@[refl] lemma regex_equiv.refl :\n  r \u2248 r :=\nassume s, by refl\n\n@[symm] lemma regex_equiv.symm :\n  r\u2081 \u2248 r\u2082 \u2192 r\u2082 \u2248 r\u2081 :=\nassume h s, (h s).symm\n\n@[trans] lemma regex_equiv.trans {r\u2083} (h\u2081\u2082 : r\u2081 \u2248 r\u2082) (h\u2082\u2083 : r\u2082 \u2248 r\u2083) :\n  r\u2081 \u2248 r\u2083 :=\nassume s, iff.trans (h\u2081\u2082 s) (h\u2082\u2083 s)\n\n/- 2.1 **optional**. Prove the following regular expression equivalences. -/\n\nlemma concat_empty_left : regex.concat regex.empty r \u2248 r :=\nsorry\n\n/- **Hint**: Below, you need to rewrite at some point `x ++ [] = x` (either\nusing `rw` or `simp`). Depending on your approach you may be required to\nintroduce an intermediate goal. Remember `simp [...] at h` or `rw [...] at h`\nallows you to rewrite a hypothesis. -/\n\nlemma concat_empty_right : regex.concat r regex.empty \u2248 r :=\nsorry\n\nlemma alt_idem : regex.alt r r \u2248 r :=\nsorry\n\nlemma star_unfold : regex.star r \u2248 regex.alt regex.empty (regex.concat r (regex.star r)) :=\nsorry\n\n/- **Hint**: For the next proof, you will probably need induction. -/\n\nlemma star_congr_aux (hr : r\u2081 \u2248 r\u2082) : accept (regex.star r\u2081) s \u2192 accept (regex.star r\u2082) s :=\nsorry\n\n/- **Hint**: For the next proof, you will probably need `star_congr_aux` and `regex.symm`. -/\n\nlemma star_congr (hr : r\u2081 \u2248 r\u2082) : regex.star r\u2081 \u2248 regex.star r\u2082 :=\nsorry\n\n/- The `match_regex` function below matches a regular expression using Brzozowski derivatives. See\nhttps://en.wikipedia.org/wiki/Brzozowski_derivative for details. -/\n\n@[simp] def accepts_empty : regex \u2192 bool\n| (regex.char c)       := ff\n| regex.nothing        := ff\n| regex.empty          := tt\n| (regex.concat r\u2081 r\u2082) := accepts_empty r\u2081 && accepts_empty r\u2082\n| (regex.alt r\u2081 r\u2082)    := accepts_empty r\u2081 || accepts_empty r\u2082\n| (regex.star r)       := tt\n\nlemma accepts_empty_iff : \u2200r : regex, accepts_empty r = tt \u2194 accept r []\n| (regex.char c)       := by simp\n| regex.nothing        := by simp\n| regex.empty          := by simp\n| (regex.concat r\u2081 r\u2082) :=\n  begin\n    simp [accepts_empty_iff r\u2081, accepts_empty_iff r\u2082],\n    exact iff.intro\n      (assume \u27e8h\u2081, h\u2082\u27e9, \u27e8[], [], h\u2081, h\u2082, rfl\u27e9)\n      (assume h, match h with \u27e8[], [], h\u2081, h\u2082, rfl\u27e9 := \u27e8h\u2081, h\u2082\u27e9 end)\n  end\n| (regex.alt r\u2081 r\u2082)    := by simp [accepts_empty_iff r\u2081, accepts_empty_iff r\u2082]\n| (regex.star r)       := by simp; constructor\n\n@[simp] def deriv : regex \u2192 char \u2192 regex\n| (regex.char c')      c := if c = c' then regex.empty else regex.nothing\n| regex.nothing        _ := regex.nothing\n| regex.empty          _ := regex.nothing\n| (regex.concat r\u2081 r\u2082) c :=\n  if accepts_empty r\u2081 = tt\n  then regex.alt (regex.concat (deriv r\u2081 c) r\u2082) (deriv r\u2082 c)\n  else regex.concat (deriv r\u2081 c) r\u2082\n| (regex.alt r\u2081 r\u2082)    c := regex.alt (deriv r\u2081 c) (deriv r\u2082 c)\n| (regex.star r)       c := regex.concat (deriv r c) (regex.star r)\n\ndef match_regex : regex \u2192 list char \u2192 bool\n| r []       := accepts_empty r\n| r (c :: s) := match_regex (deriv r c) s\n\n/- 2.2 **optional**. Fill in the `sorry` placeholders below. -/\n\nlemma accept_deriv : \u2200r : regex, \u2200c s, accept (deriv r c) s \u2194 accept r (c :: s)\n| (regex.char c')      c s :=\n  sorry\n| regex.nothing        c s :=\n  sorry\n| regex.empty          c s :=\n  sorry\n| (regex.concat r\u2081 r\u2082) c s :=\n  begin\n    by_cases h\u2081 : accepts_empty r\u2081 = tt;\n      simp [h\u2081, accept_deriv r\u2082, accept_deriv r\u2081];\n      simp [accepts_empty_iff] at h\u2081,\n    sorry,  -- in one direction, you will need to make a case distinction on the string\n    sorry\n  end\n| (regex.alt r\u2081 r\u2082)    c s := by simp [accept_deriv r\u2082, accept_deriv r\u2081]\n| (regex.star r)       c s :=\n  begin\n    rw [accept_star],\n    sorry  -- for one direction, you will probably need `accept_star_cons`\n  end\n", "meta": {"author": "KjellZijlemaker", "repo": "Logical_Verification_VU", "sha": "4578b93bf1615466996157bb333c84122b201d99", "save_path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU", "path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU/Logical_Verification_VU-4578b93bf1615466996157bb333c84122b201d99/Exercises 8/31_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.8031737987125613, "lm_q1q2_score": 0.7255022330805866}}
{"text": "-- Si_ff_es_biyectiva_entonces_f_es_biyectiva.lean\n-- Si f\u00b7f es biyectiva entonces f es biyectiva.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 28-junio-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si f\u00b7f es biyectiva, entonces f es biyectiva.\n-- ---------------------------------------------------------------------\n\nimport tactic\nopen function\n\nvariables {X Y Z : Type}\nvariable  {f : X \u2192 Y}\nvariable  {g : Y \u2192 Z}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nlemma iny_comp_iny_primera\n  (Hgf : injective (g \u2218 f))\n  : injective f :=\nbegin\n  intros x x' f_xx',\n  apply Hgf,\n  finish,\nend\n\nlemma supr_comp_supr_segunda\n  (Hgf : surjective (g \u2218 f))\n  : surjective g :=\nbegin\n  intros z,\n  rcases Hgf z with \u27e8x, hx\u27e9,\n  use f x,\n  calc g (f x) = (g \u2218 f) x : rfl\n           ... = z         : hx,\nend\n\nexample\n  (f : X \u2192 X)\n  (Hff : bijective (f \u2218 f))\n  : bijective f :=\nbegin\n  split,\n  { have h1 : injective (f \u2218 f) := bijective.injective Hff,\n    exact iny_comp_iny_primera h1, },\n  { have h2 : surjective (f \u2218 f) := bijective.surjective Hff,\n    exact supr_comp_supr_segunda h2, },\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Si_ff_es_biyectiva_entonces_f_es_biyectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7254957892356199}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson, Jalex Stark\n-/\nimport data.polynomial.monic\nimport data.polynomial.ring_division\nimport tactic.linarith\n/-!\n# Lemmas for the interaction between polynomials and `\u2211` and `\u220f`.\n\nRecall that `\u2211` and `\u220f` are notation for `finset.sum` and `finset.prod` respectively.\n\n## Main results\n\n- `polynomial.nat_degree_prod_of_monic` : the degree of a product of monic polynomials is the\n  product of degrees. We prove this only for `[comm_semiring R]`,\n  but it ought to be true for `[semiring R]` and `list.prod`.\n- `polynomial.nat_degree_prod` : for polynomials over an integral domain,\n  the degree of the product is the sum of degrees.\n- `polynomial.leading_coeff_prod` : for polynomials over an integral domain,\n  the leading coefficient is the product of leading coefficients.\n- `polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing\n  the second coefficient of the characteristic polynomial.\n-/\n\nopen finset\nopen multiset\n\nopen_locale big_operators\n\nuniverses u w\n\nvariables {R : Type u} {\u03b9 : Type w}\n\nnamespace polynomial\n\nvariables (s : finset \u03b9)\n\nsection comm_semiring\nvariables [comm_semiring R] (f : \u03b9 \u2192 polynomial R) (t : multiset (polynomial R))\n\nlemma nat_degree_multiset_prod_le :\n  t.prod.nat_degree \u2264 (t.map (\u03bb f, nat_degree f)).sum :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ih, _), { simp },\n  rw [prod_cons, map_cons, sum_cons],\n  transitivity a.nat_degree + t.prod.nat_degree,\n  { apply polynomial.nat_degree_mul_le },\n  { exact add_le_add (le_refl _) ih }\nend\n\nlemma nat_degree_prod_le : (\u220f i in s, f i).nat_degree \u2264 \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_le (s.1.map f)\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_multiset_prod' (h : (t.map (\u03bb f, leading_coeff f)).prod \u2260 0) :\n  t.prod.leading_coeff = (t.map (\u03bb f, leading_coeff f)).prod :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _), { simp },\n  rw [map_cons, prod_cons] at ht,\n  simp only [map_cons, prod_cons],\n  rw polynomial.leading_coeff_mul'; { rwa ih, apply right_ne_zero_of_mul ht }\nend\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod' (s.1.map f) (by simpa using h)\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_multiset_prod' (h : (t.map (\u03bb f, leading_coeff f)).prod \u2260 0) :\n  t.prod.nat_degree = (t.map (\u03bb f, nat_degree f)).sum :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _), { simp },\n  rw [map_cons, prod_cons] at ht \u22a2,\n  rw [sum_cons, polynomial.nat_degree_mul', ih],\n  { apply right_ne_zero_of_mul ht },\n  { rwa polynomial.leading_coeff_multiset_prod', apply right_ne_zero_of_mul ht },\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod' (s.1.map f) (by simpa using h)\n\nlemma nat_degree_multiset_prod_of_monic [nontrivial R] (h : \u2200 f \u2208 t, monic f) :\n  t.prod.nat_degree = (t.map (\u03bb f, nat_degree f)).sum :=\nbegin\n  apply nat_degree_multiset_prod',\n  suffices : (t.map (\u03bb f, leading_coeff f)).prod = 1, { rw this, simp },\n  convert prod_repeat (1 : R) t.card,\n  { simp only [eq_repeat, multiset.card_map, eq_self_iff_true, true_and],\n    rintros i hi,\n    obtain \u27e8i, hi, rfl\u27e9 := multiset.mem_map.mp hi,\n    apply h, assumption },\n  { simp }\nend\n\nlemma nat_degree_prod_of_monic [nontrivial R] (h : \u2200 i \u2208 s, (f i).monic) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_of_monic (s.1.map f) (by simpa using h)\n\nlemma coeff_zero_multiset_prod :\n  t.prod.coeff 0 = (t.map (\u03bb f, coeff f 0)).prod :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ht, _), { simp },\n  rw [prod_cons, map_cons, prod_cons, polynomial.mul_coeff_zero, ht]\nend\n\nlemma coeff_zero_prod :\n  (\u220f i in s, f i).coeff 0 = \u220f i in s, (f i).coeff 0 :=\nby simpa using coeff_zero_multiset_prod (s.1.map f)\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nopen monic\n-- Eventually this can be generalized with Vieta's formulas\n-- plus the connection between roots and factorization.\nlemma multiset_prod_X_sub_C_next_coeff [nontrivial R] (t : multiset R) :\n  next_coeff (t.map (\u03bb x, X - C x)).prod = -t.sum :=\nbegin\n  rw next_coeff_multiset_prod,\n  { simp only [next_coeff_X_sub_C],\n    refine t.sum_hom \u27e8has_neg.neg, _, _\u27e9; simp [add_comm] },\n  { intros, apply monic_X_sub_C }\nend\n\nlemma prod_X_sub_C_next_coeff [nontrivial R] {s : finset \u03b9} (f : \u03b9 \u2192 R) :\n  next_coeff \u220f i in s, (X - C (f i)) = -\u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_next_coeff (s.1.map f)\n\nlemma multiset_prod_X_sub_C_coeff_card_pred [nontrivial R] (t : multiset R) (ht : 0 < t.card) :\n  (t.map (\u03bb x, (X - C x))).prod.coeff (t.card - 1) = -t.sum :=\nbegin\n  convert multiset_prod_X_sub_C_next_coeff (by assumption),\n  rw next_coeff, split_ifs,\n  { rw nat_degree_multiset_prod_of_monic at h; simp only [multiset.mem_map] at *,\n    swap, { rintros _ \u27e8_, _, rfl\u27e9, apply monic_X_sub_C },\n    simp_rw [multiset.sum_eq_zero_iff, multiset.mem_map] at h,\n    contrapose! h,\n    obtain \u27e8x, hx\u27e9 := card_pos_iff_exists_mem.mp ht,\n    exact \u27e8_, \u27e8_, \u27e8x, hx, rfl\u27e9, nat_degree_X_sub_C _\u27e9, one_ne_zero\u27e9 },\n  congr, rw nat_degree_multiset_prod_of_monic; { simp [nat_degree_X_sub_C, monic_X_sub_C] },\nend\n\nlemma prod_X_sub_C_coeff_card_pred [nontrivial R] (s : finset \u03b9) (f : \u03b9 \u2192 R) (hs : 0 < s.card) :\n  (\u220f i in s, (X - C (f i))).coeff (s.card - 1) = - \u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_coeff_card_pred (s.1.map f) (by simpa using hs)\n\nend comm_ring\n\nsection no_zero_divisors\nvariables [comm_ring R] [no_zero_divisors R] (f : \u03b9 \u2192 polynomial R) (t : multiset (polynomial R))\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees.\n\nSee `polynomial.nat_degree_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma nat_degree_prod [nontrivial R] (h : \u2200 i \u2208 s, f i \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nbegin\n  apply nat_degree_prod',\n  rw prod_ne_zero_iff,\n  intros x hx, simp [h x hx]\nend\n\nlemma nat_degree_multiset_prod [nontrivial R] (s : multiset (polynomial R))\n  (h : (0 : polynomial R) \u2209 s) :\n  nat_degree s.prod = (s.map nat_degree).sum :=\nbegin\n  rw nat_degree_multiset_prod',\n  simp_rw [ne.def, multiset.prod_eq_zero_iff, multiset.mem_map, leading_coeff_eq_zero],\n  rintro \u27e8_, h, rfl\u27e9,\n  contradiction\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_multiset_prod [nontrivial R] :\n  t.prod.degree = (t.map (\u03bb f, degree f)).sum :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ht, _), { simp },\n  { rw [prod_cons, degree_mul, ht, map_cons, sum_cons] }\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_prod [nontrivial R] : (\u220f i in s, f i).degree = \u2211 i in s, (f i).degree :=\nby simpa using degree_multiset_prod (s.1.map f)\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_multiset_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_multiset_prod :\n  t.prod.leading_coeff = (t.map (\u03bb f, leading_coeff f)).prod :=\nby { rw [\u2190 leading_coeff_hom_apply, monoid_hom.map_multiset_prod], refl }\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_prod :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod (s.1.map f)\n\nend no_zero_divisors\nend polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/polynomial/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7254957850825372}}
{"text": "/-\nCopyright (c) 2022 Junyan Xu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Junyan Xu\n-/\nimport data.finsupp.lex\nimport data.finsupp.multiset\nimport order.game_add\n\n/-!\n# Termination of a hydra game\n\nThis file deals with the following version of the hydra game: each head of the hydra is\nlabelled by an element in a type `\u03b1`, and when you cut off one head with label `a`, it\ngrows back an arbitrary but finite number of heads, all labelled by elements smaller than\n`a` with respect to a well-founded relation `r` on `\u03b1`. We show that no matter how (in\nwhat order) you choose cut off the heads, the game always terminates, i.e. all heads will\neventually be cut off (but of course it can last arbitrarily long, i.e. takes an\narbitrary finite number of steps).\n\nThis result is stated as the well-foundedness of the `cut_expand` relation defined in\nthis file: we model the heads of the hydra as a multiset of elements of `\u03b1`, and the\nvalid \"moves\" of the game are modelled by the relation `cut_expand r` on `multiset \u03b1`:\n`cut_expand r s' s` is true iff `s'` is obtained by removing one head `a \u2208 s` and\nadding back an arbitrary multiset `t` of heads such that all `a' \u2208 t` satisfy `r a' a`.\n\nWe follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332.\n\nTODO: formalize the relations corresponding to more powerful (e.g. Kirby\u2013Paris and Buchholz)\nhydras, and prove their well-foundedness.\n-/\n\nnamespace relation\n\nopen multiset prod\n\nvariables {\u03b1 : Type*}\n\n/-- The relation that specifies valid moves in our hydra game. `cut_expand r s' s`\n  means that `s'` is obtained by removing one head `a \u2208 s` and adding back an arbitrary\n  multiset `t` of heads such that all `a' \u2208 t` satisfy `r a' a`.\n\n  This is most directly translated into `s' = s.erase a + t`, but `multiset.erase` requires\n  `decidable_eq \u03b1`, so we use the equivalent condition `s' + {a} = s + t` instead, which\n  is also easier to verify for explicit multisets `s'`, `s` and `t`.\n\n  We also don't include the condition `a \u2208 s` because `s' + {a} = s + t` already\n  guarantees `a \u2208 s + t`, and if `r` is irreflexive then `a \u2209 t`, which is the\n  case when `r` is well-founded, the case we are primarily interested in.\n\n  The lemma `relation.cut_expand_iff` below converts between this convenient definition\n  and the direct translation when `r` is irreflexive. -/\ndef cut_expand (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s' s : multiset \u03b1) : Prop :=\n\u2203 (t : multiset \u03b1) (a : \u03b1), (\u2200 a' \u2208 t, r a' a) \u2227 s' + {a} = s + t\n\nvariable {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nlemma cut_expand_le_inv_image_lex [hi : is_irrefl \u03b1 r] :\n  cut_expand r \u2264 inv_image (finsupp.lex (r\u1d9c \u2293 (\u2260)) (<)) to_finsupp :=\n\u03bb s t \u27e8u, a, hr, he\u27e9, begin\n  classical, refine \u27e8a, \u03bb b h, _, _\u27e9; simp_rw to_finsupp_apply,\n  { apply_fun count b at he, simp_rw count_add at he,\n    convert he; convert (add_zero _).symm; rw count_eq_zero; intro hb,\n    exacts [h.2 (mem_singleton.1 hb), h.1 (hr b hb)] },\n  { apply_fun count a at he, simp_rw [count_add, count_singleton_self] at he,\n    apply nat.lt_of_succ_le, convert he.le, convert (add_zero _).symm,\n    exact count_eq_zero.2 (\u03bb ha, hi.irrefl a $ hr a ha) },\nend\n\ntheorem cut_expand_singleton {s x} (h : \u2200 x' \u2208 s, r x' x) : cut_expand r s {x} :=\n\u27e8s, x, h, add_comm s _\u27e9\n\ntheorem cut_expand_singleton_singleton {x' x} (h : r x' x) : cut_expand r {x'} {x} :=\ncut_expand_singleton (\u03bb a h, by rwa mem_singleton.1 h)\n\ntheorem cut_expand_add_left {t u} (s) : cut_expand r (s + t) (s + u) \u2194 cut_expand r t u :=\nexists\u2082_congr $ \u03bb _ _, and_congr iff.rfl $ by rw [add_assoc, add_assoc, add_left_cancel_iff]\n\nlemma cut_expand_iff [decidable_eq \u03b1] [is_irrefl \u03b1 r] {s' s : multiset \u03b1} :\n  cut_expand r s' s \u2194 \u2203 (t : multiset \u03b1) a, (\u2200 a' \u2208 t, r a' a) \u2227 a \u2208 s \u2227 s' = s.erase a + t :=\nbegin\n  simp_rw [cut_expand, add_singleton_eq_iff],\n  refine exists\u2082_congr (\u03bb t a, \u27e8_, _\u27e9),\n  { rintro \u27e8ht, ha, rfl\u27e9,\n    obtain h|h := mem_add.1 ha,\n    exacts [\u27e8ht, h, t.erase_add_left_pos h\u27e9, (@irrefl \u03b1 r _ a (ht a h)).elim] },\n  { rintro \u27e8ht, h, rfl\u27e9,\n    exact \u27e8ht, mem_add.2 (or.inl h), (t.erase_add_left_pos h).symm\u27e9 },\nend\n\ntheorem not_cut_expand_zero [is_irrefl \u03b1 r] (s) : \u00ac cut_expand r s 0 :=\nby { classical, rw cut_expand_iff, rintro \u27e8_, _, _, \u27e8\u27e9, _\u27e9 }\n\n/-- For any relation `r` on `\u03b1`, multiset addition `multiset \u03b1 \u00d7 multiset \u03b1 \u2192 multiset \u03b1` is a\n  fibration between the game sum of `cut_expand r` with itself and `cut_expand r` itself. -/\nlemma cut_expand_fibration (r : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  fibration (game_add (cut_expand r) (cut_expand r)) (cut_expand r) (\u03bb s, s.1 + s.2) :=\nbegin\n  rintro \u27e8s\u2081, s\u2082\u27e9 s \u27e8t, a, hr, he\u27e9, dsimp at he \u22a2,\n  classical, obtain \u27e8ha, rfl\u27e9 := add_singleton_eq_iff.1 he,\n  rw [add_assoc, mem_add] at ha, obtain (h|h) := ha,\n  { refine \u27e8(s\u2081.erase a + t, s\u2082), game_add.fst \u27e8t, a, hr, _\u27e9, _\u27e9,\n    { rw [add_comm, \u2190 add_assoc, singleton_add, cons_erase h] },\n    { rw [add_assoc s\u2081, erase_add_left_pos _ h, add_right_comm, add_assoc] } },\n  { refine \u27e8(s\u2081, (s\u2082 + t).erase a), game_add.snd \u27e8t, a, hr, _\u27e9, _\u27e9,\n    { rw [add_comm, singleton_add, cons_erase h] },\n    { rw [add_assoc, erase_add_right_pos _ h] } },\nend\n\n/-- A multiset is accessible under `cut_expand` if all its singleton subsets are,\n  assuming `r` is irreflexive. -/\nlemma acc_of_singleton [is_irrefl \u03b1 r] {s : multiset \u03b1} :\n  (\u2200 a \u2208 s, acc (cut_expand r) {a}) \u2192 acc (cut_expand r) s :=\nbegin\n  refine multiset.induction _ _ s,\n  { exact \u03bb _, acc.intro 0 $ \u03bb s h, (not_cut_expand_zero s h).elim },\n  { intros a s ih hacc, rw \u2190 s.singleton_add a,\n    exact ((hacc a $ s.mem_cons_self a).prod_game_add $ ih $ \u03bb a ha,\n      hacc a $ mem_cons_of_mem ha).of_fibration _ (cut_expand_fibration r) },\nend\n\n/-- A singleton `{a}` is accessible under `cut_expand r` if `a` is accessible under `r`,\n  assuming `r` is irreflexive. -/\nlemma _root_.acc.cut_expand [is_irrefl \u03b1 r] {a : \u03b1} (hacc : acc r a) : acc (cut_expand r) {a} :=\nbegin\n  induction hacc with a h ih,\n  refine acc.intro _ (\u03bb s, _),\n  classical, rw cut_expand_iff,\n  rintro \u27e8t, a, hr, rfl|\u27e8\u27e8\u27e9\u27e9, rfl\u27e9,\n  refine acc_of_singleton (\u03bb a', _),\n  rw [erase_singleton, zero_add],\n  exact ih a' \u2218 hr a',\nend\n\n/-- `cut_expand r` is well-founded when `r` is. -/\ntheorem _root_.well_founded.cut_expand (hr : well_founded r) : well_founded (cut_expand r) :=\n\u27e8by { letI h := hr.is_irrefl, exact \u03bb s, acc_of_singleton $ \u03bb a _, (hr.apply a).cut_expand }\u27e9\n\nend relation\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/logic/hydra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7254957742796482}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport tactic.abel\nimport data.polynomial.eval\n\n/-!\n# The Pochhammer polynomials\n\nWe define and prove some basic relations about\n`pochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)`\nwhich is also known as the rising factorial. A version of this definition\nthat is focused on `nat` can be found in `data.nat.factorial` as `nat.asc_factorial`.\n\n## Implementation\n\nAs with many other families of polynomials, even though the coefficients are always in `\u2115`,\nwe define the polynomial with coefficients in any `[semiring S]`.\n\n## TODO\n\nThere is lots more in this direction:\n* q-factorials, q-binomials, q-Pochhammer.\n-/\n\nuniverses u v\n\nopen polynomial\nopen_locale polynomial\n\nsection semiring\nvariables (S : Type u) [semiring S]\n\n/--\n`pochhammer S n` is the polynomial `X * (X+1) * ... * (X + n - 1)`,\nwith coefficients in the semiring `S`.\n-/\nnoncomputable def pochhammer : \u2115 \u2192 S[X]\n| 0 := 1\n| (n+1) := X * (pochhammer n).comp (X + 1)\n\n@[simp] lemma pochhammer_zero : pochhammer S 0 = 1 := rfl\n@[simp] lemma pochhammer_one : pochhammer S 1 = X := by simp [pochhammer]\n\nlemma pochhammer_succ_left (n : \u2115) : pochhammer S (n+1) = X * (pochhammer S n).comp (X+1) :=\nby rw pochhammer\n\nsection\nvariables {S} {T : Type v} [semiring T]\n@[simp] lemma pochhammer_map (f : S \u2192+* T) (n : \u2115) : (pochhammer S n).map f = pochhammer T n :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih, pochhammer_succ_left, map_comp], },\nend\n\nend\n\n@[simp, norm_cast] lemma pochhammer_eval_cast (n k : \u2115) :\n  ((pochhammer \u2115 n).eval k : S) = (pochhammer S n).eval k :=\nbegin\n  rw [\u2190pochhammer_map (algebra_map \u2115 S), eval_map, \u2190eq_nat_cast (algebra_map \u2115 S),\n    eval\u2082_at_nat_cast, nat.cast_id, eq_nat_cast],\nend\n\nlemma pochhammer_eval_zero {n : \u2115} : (pochhammer S n).eval 0 = if n = 0 then 1 else 0 :=\nbegin\n  cases n,\n  { simp, },\n  { simp [X_mul, nat.succ_ne_zero, pochhammer_succ_left], }\nend\n\nlemma pochhammer_zero_eval_zero : (pochhammer S 0).eval 0 = 1 :=\nby simp\n\n@[simp] lemma pochhammer_ne_zero_eval_zero {n : \u2115} (h : n \u2260 0) : (pochhammer S n).eval 0 = 0 :=\nby simp [pochhammer_eval_zero, h]\n\nlemma pochhammer_succ_right (n : \u2115) : pochhammer S (n+1) = pochhammer S n * (X + n) :=\nbegin\n  suffices h : pochhammer \u2115 (n+1) = pochhammer \u2115 n * (X + n),\n  { apply_fun polynomial.map (algebra_map \u2115 S) at h,\n    simpa only [pochhammer_map, polynomial.map_mul, polynomial.map_add,\n                map_X, polynomial.map_nat_cast] using h },\n  induction n with n ih,\n  { simp, },\n  { conv_lhs\n  { rw [pochhammer_succ_left, ih, mul_comp, \u2190mul_assoc, \u2190pochhammer_succ_left, add_comp, X_comp,\n      nat_cast_comp, add_assoc, add_comm (1 : \u2115[X])], },\n    refl, },\nend\n\nlemma pochhammer_succ_eval {S : Type*} [semiring S] (n : \u2115) (k : S) :\n  (pochhammer S (n + 1)).eval k = (pochhammer S n).eval k * (k + n) :=\nby rw [pochhammer_succ_right, mul_add, eval_add, eval_mul_X, \u2190 nat.cast_comm, \u2190 C_eq_nat_cast,\n    eval_C_mul, nat.cast_comm, \u2190 mul_add]\n\nlemma pochhammer_succ_comp_X_add_one (n : \u2115) :\n  (pochhammer S (n + 1)).comp (X + 1) =\n    pochhammer S (n + 1) + (n + 1) \u2022 (pochhammer S n).comp (X + 1) :=\nbegin\n  suffices : (pochhammer \u2115 (n + 1)).comp (X + 1) =\n              pochhammer \u2115 (n + 1) + (n + 1) * (pochhammer \u2115 n).comp (X + 1),\n  { simpa [map_comp] using congr_arg (polynomial.map (nat.cast_ring_hom S)) this },\n  cases n,\n  { simp },\n  { nth_rewrite 1 pochhammer_succ_left,\n    rw [\u2190 add_mul, pochhammer_succ_right \u2115 (n + 1), mul_comp, mul_comm, add_comp, X_comp,\n      nat_cast_comp, add_comm \u2191(n + 1), \u2190 add_assoc] }\nend\n\nlemma polynomial.mul_X_add_nat_cast_comp {p q : S[X]} {n : \u2115} :\n  (p * (X + n)).comp q = (p.comp q) * (q + n) :=\nby rw [mul_add, add_comp, mul_X_comp, \u2190nat.cast_comm, nat_cast_mul_comp, nat.cast_comm, mul_add]\n\nlemma pochhammer_mul (n m : \u2115) :\n  pochhammer S n * (pochhammer S m).comp (X + n) = pochhammer S (n + m) :=\nbegin\n  induction m with m ih,\n  { simp, },\n  { rw [pochhammer_succ_right, polynomial.mul_X_add_nat_cast_comp, \u2190mul_assoc, ih,\n      nat.succ_eq_add_one, \u2190add_assoc, pochhammer_succ_right, nat.cast_add, add_assoc], }\nend\n\nlemma pochhammer_nat_eq_asc_factorial (n : \u2115) :\n  \u2200 k, (pochhammer \u2115 k).eval (n + 1) = n.asc_factorial k\n| 0 := by erw [eval_one]; refl\n| (t + 1) := begin\n  rw [pochhammer_succ_right, eval_mul, pochhammer_nat_eq_asc_factorial t],\n  suffices : n.asc_factorial t * (n + 1 + t) = n.asc_factorial (t + 1), by simpa,\n  rw [nat.asc_factorial_succ, add_right_comm, mul_comm]\nend\n\nlemma pochhammer_nat_eq_desc_factorial (a b : \u2115) :\n  (pochhammer \u2115 b).eval a = (a + b - 1).desc_factorial b :=\nbegin\n  cases b,\n  { rw [nat.desc_factorial_zero, pochhammer_zero, polynomial.eval_one] },\n  rw [nat.add_succ, nat.succ_sub_succ, tsub_zero],\n  cases a,\n  { rw [pochhammer_ne_zero_eval_zero _ b.succ_ne_zero, zero_add,\n    nat.desc_factorial_of_lt b.lt_succ_self] },\n  { rw [nat.succ_add, \u2190nat.add_succ, nat.add_desc_factorial_eq_asc_factorial,\n      pochhammer_nat_eq_asc_factorial] }\nend\n\nend semiring\n\nsection ordered_semiring\nvariables {S : Type*} [ordered_semiring S] [nontrivial S]\n\nlemma pochhammer_pos (n : \u2115) (s : S) (h : 0 < s) : 0 < (pochhammer S n).eval s :=\nbegin\n  induction n with n ih,\n  { simp only [nat.nat_zero_eq_zero, pochhammer_zero, eval_one], exact zero_lt_one, },\n  { rw [pochhammer_succ_right, mul_add, eval_add, \u2190nat.cast_comm, eval_nat_cast_mul, eval_mul_X,\n      nat.cast_comm, \u2190mul_add],\n    exact mul_pos ih\n      (lt_of_lt_of_le h ((le_add_iff_nonneg_right _).mpr (nat.cast_nonneg n))), }\nend\n\nend ordered_semiring\n\nsection factorial\n\nopen_locale nat\n\nvariables (S : Type*) [semiring S] (r n : \u2115)\n\n@[simp]\nlemma pochhammer_eval_one (S : Type*) [semiring S] (n : \u2115) :\n  (pochhammer S n).eval (1 : S) = (n! : S) :=\nby rw_mod_cast [pochhammer_nat_eq_asc_factorial, nat.zero_asc_factorial]\n\nlemma factorial_mul_pochhammer (S : Type*) [semiring S] (r n : \u2115) :\n  (r! : S) * (pochhammer S n).eval (r + 1) = (r + n)! :=\nby rw_mod_cast [pochhammer_nat_eq_asc_factorial, nat.factorial_mul_asc_factorial]\n\nlemma pochhammer_nat_eval_succ (r : \u2115) :\n  \u2200 n : \u2115, n * (pochhammer \u2115 r).eval (n + 1) = (n + r) * (pochhammer \u2115 r).eval n\n| 0 := begin\n  by_cases h : r = 0,\n  { simp only [h, zero_mul, zero_add], },\n  { simp only [pochhammer_eval_zero, zero_mul, if_neg h, mul_zero], }\nend\n| (k + 1) := by simp only [pochhammer_nat_eq_asc_factorial, nat.succ_asc_factorial, add_right_comm]\n\nlemma pochhammer_eval_succ (r n : \u2115) :\n  (n : S) * (pochhammer S r).eval (n + 1 : S) = (n + r) * (pochhammer S r).eval n :=\nby exact_mod_cast congr_arg nat.cast (pochhammer_nat_eval_succ r n)\n\nend factorial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/polynomial/pochhammer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7254957721783903}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Andrew Zipperer, Jeremy Avigad\n\nWe provide two versions of the quoptient construction. They use the same names and notation:\none lives in the namespace 'quotient_group' and the other lives in the namespace\n'quotient_group_general'.\n\nThe first takes a group, A, and a normal subgroup, H. We have\n\n  quotient H       := the quotient of A by H\n  qproj H a        := the projection, with notation a' * G\n  qproj H ' s      := the image of s, with notation s / G\n  extend H respf   := given f : A \u2192 B respecting the equivalence relation, we get a function\n                      f : quotient G \u2192 B\n  bar f            := the above, G = ker f)\n\nThe definition is constructive, using quotient types. We prove all the characteristic properties.\n\nAs in the SSReflect library, we also provide a construction to quotient by an *arbitrary subgroup*.\nNow we have\n\n  quotient H       := the quotient of normalizer H by H\n  qproj H a        := still denoted a '* H, the projection when a is in normalizer H,\n                      arbitrary otherwise\n  qproj H G        := still denoted G / H, the image of the above\n  extend H G respf := given a homomorphism on G with ker_in G f \u2286 H, extends to a\n                      homomorphism G / H\n  bar G f          := the above, with H = ker_in f G\n\nThis quotient H is defined by composing the first one with the construction which turns\nnormalizer H into a group.\n-/\nimport .subgroup_to_group theories.move\nopen set function subtype classical quot\n\nnamespace group_theory\nopen coset_notation\n\nvariables {A B C : Type}\n\n/- the quotient group -/\n\nnamespace quotient_group\n\nvariables [group A] (H : set A) [is_normal H]\n\ndefinition lcoset_setoid [instance] : setoid A :=\nsetoid.mk (lcoset_equiv H) (equivalence_lcoset_equiv H)\n\ndefinition quotient := quot (lcoset_setoid H)\n\nprivate definition qone : quotient H := \u27e6 1 \u27e7\n\nprivate definition qmul : quotient H \u2192 quotient H \u2192 quotient H :=\nquot.lift\u2082\n  (\u03bb a b, \u27e6a * b\u27e7)\n  (\u03bb a\u2081 a\u2082 b\u2081 b\u2082 e\u2081 e\u2082, quot.sound (lcoset_equiv_mul H e\u2081 e\u2082))\n\nprivate definition qinv : quotient H \u2192 quotient H :=\nquot.lift\n  (\u03bb a, \u27e6a\u207b\u00b9\u27e7)\n  (\u03bb a\u2081 a\u2082 e, quot.sound (lcoset_equiv_inv H e))\n\nprivate proposition qmul_assoc (a b c : quotient H) :\n  qmul H (qmul H a b) c = qmul H a (qmul H b c) :=\nquot.induction_on\u2082 a b (\u03bb a b, quot.induction_on c (\u03bb c,\n  have H :  \u27e6a * b * c\u27e7 = \u27e6a * (b * c)\u27e7, by rewrite mul.assoc,\n  H))\n\nprivate proposition qmul_qone (a : quotient H) : qmul H a (qone H) = a :=\nquot.induction_on a (\u03bb a', show \u27e6a' * 1\u27e7 = \u27e6a'\u27e7, by rewrite mul_one)\n\nprivate proposition qone_qmul (a : quotient H) : qmul H (qone H) a = a :=\nquot.induction_on a (\u03bb a', show \u27e61 * a'\u27e7 = \u27e6a'\u27e7, by rewrite one_mul)\n\nprivate proposition qmul_left_inv (a : quotient H) : qmul H (qinv H a) a = qone H :=\nquot.induction_on a (\u03bb a', show \u27e6a'\u207b\u00b9 * a'\u27e7 = \u27e61\u27e7, by rewrite mul.left_inv)\n\nprotected definition group [instance] : group (quotient H) :=\n\u2983 group,\n  mul          := qmul H,\n  inv          := qinv H,\n  one          := qone H,\n  mul_assoc    := qmul_assoc H,\n  mul_one      := qmul_qone H,\n  one_mul      := qone_qmul H,\n  mul_left_inv := qmul_left_inv H\n\u2984\n\n-- these theorems characterize the quotient group\n\ndefinition qproj (a : A) : quotient H := \u27e6a\u27e7\n\ninfix ` '* `:65  := \u03bb {A' : Type} [group A'] a H' [is_normal H'], qproj H' a\ninfix ` / `      := \u03bb {A' : Type} [group A'] G H' [is_normal H'], qproj H' ' G\n\nproposition is_hom_qproj [instance] : is_hom (qproj H) :=\nis_mul_hom.mk (\u03bb a b, rfl)\n\nvariable {H}\n\nproposition qproj_eq_qproj {a b : A} (h : a * H = b * H) : a '* H = b '* H :=\nquot.sound h\n\nproposition lcoset_eq_lcoset_of_qproj_eq_qproj {a b : A} (h : a '* H = b '* H) :  a * H = b * H :=\nquot.exact h\n\nvariable (H)\n\nproposition qproj_eq_qproj_iff (a b : A) : a '* H = b '* H \u2194 a * H = b * H :=\niff.intro lcoset_eq_lcoset_of_qproj_eq_qproj qproj_eq_qproj\n\nproposition ker_qproj [is_subgroup H] : ker (qproj H) = H :=\next (take a,\n  begin\n    rewrite [\u2191ker, mem_set_of_iff, -hom_one (qproj H), qproj_eq_qproj_iff,\n      one_lcoset],\n    show a * H = H \u2194 a \u2208 H, from iff.intro mem_of_lcoset_eq_self lcoset_eq_self_of_mem\n  end)\n\nproposition qproj_eq_one_iff [is_subgroup H] (a : A) : a '* H = 1 \u2194 a \u2208 H :=\nhave H : qproj H a = 1 \u2194 a \u2208 ker (qproj H), from iff.rfl,\nby rewrite [H, ker_qproj]\n\nvariable {H}\n\nproposition qproj_eq_one_of_mem [is_subgroup H] {a : A} (aH : a \u2208 H) : a '* H = 1 :=\niff.mpr (qproj_eq_one_iff H a) aH\n\nproposition mem_of_qproj_eq_one [is_subgroup H] {a : A} (h : a '* H = 1) : a \u2208 H :=\niff.mp (qproj_eq_one_iff H a) h\n\nvariable (H)\n\nproposition surjective_qproj : surjective (qproj H) :=\ntake y, quot.induction_on y (\u03bb a, exists.intro a rfl)\n\nvariable {H}\n\nproposition quotient_induction {P : quotient H \u2192 Prop} (h : \u2200 a, P (a '* H)) : \u2200 a, P a :=\nquot.ind h\n\nproposition quotient_induction\u2082 {P : quotient H \u2192 quotient H \u2192 Prop}\n    (h : \u2200 a\u2081 a\u2082, P (a\u2081 '* H) (a\u2082 '* H)) :\n  \u2200 a\u2081 a\u2082, P a\u2081 a\u2082 :=\nquot.ind\u2082 h\n\nvariable (H)\n\nproposition image_qproj_self [is_subgroup H] : H / H = '{1} :=\neq_of_subset_of_subset\n  (image_subset_of_maps_to\n    (take x, suppose x \u2208 H,\n      show x '* H \u2208 '{1},\n        from mem_singleton_of_eq (qproj_eq_one_of_mem `x \u2208 H`)))\n  (take x, suppose x \u2208 '{1},\n    have x = 1, from eq_of_mem_singleton this,\n    show x \u2208 H / H, by rewrite this; apply mem_image_of_mem _ one_mem)\n\n-- extending a function A \u2192 B to a function A / H \u2192 B\n\nsection respf\n\nvariable {H}\nvariables {f : A \u2192 B} (respf : \u2200 a\u2081 a\u2082, a\u2081 * H = a\u2082 * H \u2192 f a\u2081 = f a\u2082)\n\ndefinition extend : quotient H \u2192 B := quot.lift f respf\n\nproposition extend_qproj (a : A) : extend respf (a '* H) = f a := rfl\n\nproposition extend_comp_qproj : extend respf \u2218 (qproj H) = f := rfl\n\nproposition image_extend (G : set A) : (extend respf) ' (G / H) = f ' G :=\nby rewrite [-image_comp]\n\nvariable [group B]\n\nproposition is_hom_extend [instance] [is_hom f] : is_hom (extend respf) :=\nis_mul_hom.mk (take a b,\n  show (extend respf (a * b)) = (extend respf a) * (extend respf b), from\n    quot.induction_on\u2082 a b (take a b, hom_mul f a b))\n\nproposition ker_extend : ker (extend respf) = ker f / H :=\neq_of_subset_of_subset\n  (quotient_induction\n    (take a, assume Ha : qproj H a \u2208 ker (extend respf),\n      have f a = 1, from Ha,\n      show a '* H \u2208 ker f / H,\n        from mem_image_of_mem _ this))\n  (image_subset_of_maps_to\n    (take a, assume h : a \u2208 ker f,\n      show extend respf (a '* H) = 1, from h))\n\nend respf\n\nend quotient_group\n\n\n/- the first homomorphism theorem for the quotient group -/\n\nnamespace quotient_group\n  variables [group A] [group B] (f : A \u2192 B) [is_hom f]\n\n  lemma eq_of_lcoset_equiv_ker \u2983a b : A\u2984 (h : lcoset_equiv (ker f) a b) : f a = f b :=\n  have b\u207b\u00b9 * a \u2208 ker f, from inv_mul_mem_of_lcoset_eq_lcoset h,\n  eq.symm (eq_of_inv_mul_mem_ker this)\n\n  definition bar : quotient (ker f) \u2192 B := extend (eq_of_lcoset_equiv_ker f)\n\n  proposition bar_qproj (a : A) : bar f (a '* ker f) = f a := rfl\n\n  proposition is_hom_bar [instance] : is_hom (bar f) := is_hom_extend _\n\n  proposition image_bar (G : set A) : bar f ' (G / ker f) = f ' G :=\n  by rewrite [\u2191bar, image_extend]\n\n  proposition image_bar_univ : bar f ' univ = f ' univ :=\n  by rewrite [\u2191bar, -image_eq_univ_of_surjective (surjective_qproj (ker f)),\n       image_extend]\n\n  proposition surj_on_bar : surj_on (bar f) univ (f ' univ) :=\n  by rewrite [\u2191surj_on, image_bar_univ]; apply subset.refl\n\n  proposition ker_bar_eq : ker (bar f) = '{1} :=\n  by rewrite [\u2191bar, ker_extend, image_qproj_self]\n\n  proposition injective_bar : injective (bar f) :=\n  injective_of_ker_eq_singleton_one (ker_bar_eq f)\nend quotient_group\n\n\n/- a generic morphism extension property -/\n\nsection\n  variables [group A] [group B] [group C]\n  variables (G : set A) [is_subgroup G]\n  variables (g : A \u2192 C) (f : A \u2192 B)\n\n  noncomputable definition gen_extend : C \u2192 B := \u03bb c, f (inv_fun g G 1 c)\n\n  variables {G g f}\n\n  proposition eq_of_ker_in_subset {a\u2081 a\u2082 : A} (a\u2081G : a\u2081 \u2208 G) (a\u2082G : a\u2082 \u2208 G)\n      [is_hom_on g G] [is_hom_on f G] (Hker : ker_in g G \u2286 ker f) (H' : g a\u2081 = g a\u2082) :\n    f a\u2081 = f a\u2082 :=\n  have memG : a\u2081\u207b\u00b9 * a\u2082 \u2208 G, from mul_mem (inv_mem a\u2081G) a\u2082G,\n  have a\u2081\u207b\u00b9 * a\u2082 \u2208 ker_in g G, from inv_mul_mem_ker_in_of_eq a\u2081G a\u2082G H',\n  have a\u2081\u207b\u00b9 * a\u2082 \u2208 ker_in f G, from and.intro (Hker this) memG,\n  show f a\u2081 = f a\u2082, from eq_of_inv_mul_mem_ker_in a\u2081G a\u2082G this\n\n  proposition gen_extend_spec [is_hom_on g G] [is_hom_on f G] (Hker : ker_in g G \u2286 ker f)\n    {a : A} (aG : a \u2208 G) : gen_extend G g f (g a) = f a :=\n  eq_of_ker_in_subset (inv_fun_spec' aG) aG Hker (inv_fun_spec aG)\n\n  proposition is_hom_on_gen_extend [is_hom_on g G] [is_hom_on f G] (Hker : ker_in g G \u2286 ker f) :\n    is_hom_on (gen_extend G g f) (g ' G) :=\n  have is_subgroup (g ' G), from is_subgroup_image g G,\n  take c\u2081, assume c\u2081gG : c\u2081 \u2208 g ' G,\n  take c\u2082, assume c\u2082gG : c\u2082 \u2208 g ' G,\n  let ginv := inv_fun g G 1 in\n  have Hginv : maps_to ginv (g ' G) G, from maps_to_inv_fun one_mem,\n  have ginvc\u2081 : ginv c\u2081 \u2208 G, from Hginv c\u2081gG,\n  have ginvc\u2082 : ginv c\u2082 \u2208 G, from Hginv c\u2082gG,\n  have ginvc\u2081c\u2082 : ginv (c\u2081 * c\u2082) \u2208 G, from Hginv (mul_mem c\u2081gG c\u2082gG),\n  have HH : \u2200\u2080 c \u2208 g ' G, g (ginv c) = c,\n    from \u03bb a aG, right_inv_on_inv_fun_of_surj_on _ (surj_on_image g G) aG,\n  have eq\u2081 : g (ginv c\u2081) = c\u2081, from HH c\u2081gG,\n  have eq\u2082 : g (ginv c\u2082) = c\u2082, from HH c\u2082gG,\n  have eq\u2083 : g (ginv (c\u2081 * c\u2082)) = c\u2081 * c\u2082, from HH (mul_mem c\u2081gG c\u2082gG),\n  have g (ginv (c\u2081 * c\u2082)) = g ((ginv c\u2081) * (ginv c\u2082)),\n    by rewrite [eq\u2083, hom_on_mul g ginvc\u2081 ginvc\u2082, eq\u2081, eq\u2082],\n  have f (ginv (c\u2081 * c\u2082)) = f (ginv c\u2081 * ginv c\u2082),\n    from eq_of_ker_in_subset (ginvc\u2081c\u2082) (mul_mem ginvc\u2081 ginvc\u2082) Hker this,\n  show f (ginv (c\u2081 * c\u2082)) = f (ginv c\u2081) * f (ginv c\u2082),\n    by rewrite [this, hom_on_mul f ginvc\u2081 ginvc\u2082]\nend\n\n\n/- quotient by an arbitrary group, not necessarily normal -/\n\nnamespace quotient_group_general\n\nvariables [group A] (H : set A) [is_subgroup H]\n\nlemma is_normal_to_group_of_normalizer [instance] :\n  is_normal (to_group_of (normalizer H) ' H) :=\nhave H1 : is_normal_in (to_group_of (normalizer H) ' H)\n                       (to_group_of (normalizer H) ' (normalizer H)),\n  from is_normal_in_image_image (subset_normalizer_self H) (to_group_of (normalizer H)),\nhave H2 : to_group_of (normalizer H) ' (normalizer H) = univ,\n  from image_to_group_of_eq_univ (normalizer H),\nis_normal_of_is_normal_in_univ (by rewrite -H2; exact H1)\n\nsection quotient_group\nopen quotient_group\n\nnoncomputable definition quotient : Type := quotient (to_group_of (normalizer H) ' H)\n\nnoncomputable definition group_quotient  [instance] : group (quotient H) :=\nquotient_group.group (to_group_of (normalizer H) ' H)\n\nnoncomputable definition qproj : A \u2192 quotient H :=\nqproj (to_group_of (normalizer H) ' H) \u2218 (to_group_of (normalizer H))\n\ninfix ` '* `:65  := \u03bb {A' : Type} [group A'] a H' [is_subgroup H'], qproj H' a\ninfix ` / `      := \u03bb {A' : Type} [group A'] G H' [is_subgroup H'], qproj H' ' G\n\nproposition is_hom_on_qproj [instance] : is_hom_on (qproj H) (normalizer H) :=\nhave H\u2080 : is_hom_on (to_group_of (normalizer H)) (normalizer H),\n  from is_hom_on_to_group_of (normalizer H),\nhave H\u2081 : is_hom_on (quotient_group.qproj (to_group_of (normalizer H) ' H)) univ,\n  from iff.mpr (is_hom_on_univ_iff (quotient_group.qproj (to_group_of (normalizer H) ' H)))\n         (is_hom_qproj (to_group_of (normalizer H) ' H)),\nis_hom_on_comp H\u2080 H\u2081 (maps_to_univ (to_group_of (normalizer H)) (normalizer H))\n\nproposition is_hom_on_qproj' [instance] (G : set A) [is_normal_in H G] :\n  is_hom_on (qproj H) G :=\nis_hom_on_of_subset (qproj H) (subset_normalizer G H)\n\nproposition ker_in_qproj : ker_in (qproj H) (normalizer H) = H :=\nlet tg := to_group_of (normalizer H) in\nbegin\n  rewrite [\u2191ker_in, ker_eq_preimage_one, \u2191qproj, preimage_comp, -ker_eq_preimage_one],\n  have is_hom_on tg H, from is_hom_on_of_subset _ (subset_normalizer_self H),\n  have is_subgroup (tg ' H), from is_subgroup_image tg H,\n  krewrite [ker_qproj, to_group_of_preimage_to_group_of_image (subset_normalizer_self H)]\nend\n\nend quotient_group\n\nvariable {H}\n\nproposition qproj_eq_qproj_iff {a b : A} (Ha : a \u2208 normalizer H) (Hb : b \u2208 normalizer H) :\n   a '* H = b '* H \u2194 a * H = b * H :=\nby rewrite [lcoset_eq_lcoset_iff, eq_iff_inv_mul_mem_ker_in Ha Hb, ker_in_qproj,\n            -inv_mem_iff, mul_inv, inv_inv]\n\nproposition qproj_eq_qproj {a b : A} (Ha : a \u2208 normalizer H) (Hb : b \u2208 normalizer H)\n    (h : a * H = b * H) :\n  a '* H = b '* H :=\niff.mpr (qproj_eq_qproj_iff Ha Hb) h\n\nproposition lcoset_eq_lcoset_of_qproj_eq_qproj {a b : A}\n    (Ha : a \u2208 normalizer H) (Hb : b \u2208 normalizer H) (h : a '* H = b '* H) :\n  a * H = b * H :=\niff.mp (qproj_eq_qproj_iff Ha Hb) h\n\nvariable (H)\n\nproposition qproj_mem {a : A} {G : set A} (aG : a \u2208 G) : a '* H \u2208 G / H :=\nmem_image_of_mem _ aG\n\nproposition qproj_one : 1 '* H = 1 := hom_on_one (qproj H) (normalizer H)\n\nvariable {H}\n\nproposition mem_of_qproj_mem {a : A} (anH : a \u2208 normalizer H)\n    {G : set A} (HsubG : H \u2286 G) [is_subgroup G] [is_normal_in H G]\n  (aHGH : a '* H \u2208 G / H): a \u2208 G :=\nhave GH : G \u2286 normalizer H, from subset_normalizer G H,\nobtain b [bG (bHeq : b '* H = a '* H)], from aHGH,\nhave b * H = a * H, from lcoset_eq_lcoset_of_qproj_eq_qproj (GH bG) anH bHeq,\nhave a \u2208 b * H, by rewrite this; apply mem_lcoset_self,\nhave a \u2208 b * G, from lcoset_subset_lcoset b HsubG this,\nshow a \u2208 G, by rewrite [lcoset_eq_self_of_mem bG at this]; apply this\n\nproposition qproj_eq_one_iff {a : A} (Ha : a \u2208 normalizer H) : a '* H = 1 \u2194 a \u2208 H :=\nby rewrite [-hom_on_one (qproj H) (normalizer H), qproj_eq_qproj_iff Ha one_mem, one_lcoset,\n        lcoset_eq_self_iff]\n\nproposition qproj_eq_one_of_mem {a : A} (aH : a \u2208 H) : a '* H = 1 :=\niff.mpr (qproj_eq_one_iff (subset_normalizer_self H aH)) aH\n\nproposition mem_of_qproj_eq_one {a : A} (Ha : a \u2208 normalizer H) (h : a '* H = 1) : a \u2208 H :=\niff.mp (qproj_eq_one_iff Ha) h\n\nvariable (H)\n\nsection\nopen quotient_group\nproposition surj_on_qproj_normalizer : surj_on (qproj H) (normalizer H) univ :=\nhave H\u2080 : surj_on (to_group_of (normalizer H)) (normalizer H) univ,\n  from surj_on_to_group_of_univ (normalizer H),\nhave H\u2081 : surj_on (quotient_group.qproj (to_group_of (normalizer H) ' H)) univ univ,\n  from surj_on_univ_of_surjective univ (surjective_qproj _),\nsurj_on_comp H\u2081 H\u2080\nend\n\nvariable {H}\n\nproposition quotient_induction {P : quotient H \u2192 Prop} (hyp : \u2200\u2080 a \u2208 normalizer H, P (a '* H)) :\n  \u2200 a, P a :=\nsurj_on_univ_induction (surj_on_qproj_normalizer H) hyp\n\nproposition quotient_induction\u2082 {P : quotient H \u2192 quotient H \u2192 Prop}\n    (hyp : \u2200\u2080 a\u2081 \u2208 normalizer H, \u2200\u2080 a\u2082 \u2208 normalizer H, P (a\u2081 '* H) (a\u2082 '* H)) :\n  \u2200 a\u2081 a\u2082, P a\u2081 a\u2082 :=\nsurj_on_univ_induction\u2082 (surj_on_qproj_normalizer H) hyp\n\nvariable (H)\n\nproposition image_qproj_self : H / H = '{1} :=\neq_of_subset_of_subset\n  (image_subset_of_maps_to\n    (take x, suppose x \u2208 H,\n      show x '* H \u2208 '{1},\n        from mem_singleton_of_eq (qproj_eq_one_of_mem `x \u2208 H`)))\n  (take x, suppose x \u2208 '{1},\n    have x = 1, from eq_of_mem_singleton this,\n    show x \u2208 H / H,\n      by rewrite [this, -qproj_one H]; apply mem_image_of_mem _ one_mem)\n\nsection respf\n\nvariable (H)\nvariables [group B] (G : set A) [is_subgroup G] (f : A \u2192 B)\n\nnoncomputable definition extend : quotient H \u2192 B := gen_extend G (qproj H) f\n\nvariables [is_hom_on f G] [is_normal_in H G]\n\nprivate proposition aux : is_hom_on (qproj H) G :=\nis_hom_on_of_subset (qproj H) (subset_normalizer G H)\n\nlocal attribute [instance] aux\n\nvariables {H f}\n\nprivate proposition aux' (respf : H \u2286 ker f) : ker_in (qproj H) G \u2286 ker f :=\nsubset.trans\n  (show ker_in (qproj H) G \u2286 ker_in (qproj H) (normalizer H),\n    from inter_subset_inter_left _ (subset_normalizer G H))\n  (by rewrite [ker_in_qproj]; apply respf)\n\nvariable {G}\n\nproposition extend_qproj (respf : H \u2286 ker f) {a : A} (aG : a \u2208 G) :\n  extend H G f (a '* H) = f a :=\ngen_extend_spec (aux' G respf) aG\n\nproposition image_extend (respf : H \u2286 ker f) {s : set A} (ssubG : s \u2286 G) :\n  extend H G f ' (s / H) = f ' s :=\nbegin\n  rewrite [-image_comp],\n  apply image_eq_image_of_eq_on,\n  intro a amems,\n  apply extend_qproj respf (ssubG amems)\nend\n\nvariable (G)\n\nproposition is_hom_on_extend [instance] (respf : H \u2286 ker f) : is_hom_on (extend H G f) (G / H) :=\nby unfold extend; apply is_hom_on_gen_extend (aux' G respf)\n\nvariable {G}\n\nproposition ker_in_extend [is_subgroup G] (respf : H \u2286 ker f) (HsubG : H \u2286 G) :\n  ker_in (extend H G f) (G / H) = (ker_in f G) / H :=\nbegin\n  apply ext,\n  intro aH,\n  cases surj_on_qproj_normalizer H (show aH \u2208 univ, from trivial) with a atemp,\n  cases atemp with anH aHeq,\n  rewrite -aHeq,\n  apply iff.intro,\n  { intro akerin,\n    cases akerin with aker ain,\n    have a '* H \u2208 G / H, from ain,\n    have a \u2208 G, from mem_of_qproj_mem anH HsubG this,\n    have a '* H \u2208 ker (extend H G f), from aker,\n    have extend H G f (a '* H) = 1, from this,\n    have f a = extend H G f (a '* H), from eq.symm (extend_qproj respf `a \u2208 G`),\n    have f a = 1, by rewrite this; assumption,\n    have a \u2208 ker_in f G, from and.intro this `a \u2208 G`,\n    show a '* H \u2208 (ker_in f G) / H, from qproj_mem H this},\n  intro aHker,\n  have aker : a \u2208 ker_in f G,\n    begin\n      have Hsub : H \u2286 ker_in f G, from subset_inter respf HsubG,\n      have is_normal_in H (ker_in f G),\n        from subset.trans (inter_subset_right (ker f) G) (subset_normalizer G H),\n      apply (mem_of_qproj_mem anH Hsub aHker)\n    end,\n  have a \u2208 G, from and.right aker,\n  have f a = 1, from and.left aker,\n  have extend H G f (a '* H) = 1,\n    from eq.trans (extend_qproj respf `a \u2208 G`) this,\n  show a '* H \u2208 ker_in (extend H G f) (G / H),\n    from and.intro this (qproj_mem H `a \u2208 G`)\nend\n\n/- (comment from Jeremy)\nThis version kills the elaborator. I don't know why.\nTracing class instances doesn't show a problem. My best guess is that it is\nthe backgracking from the \"obtain\".\n\nproposition ker_in_extend [is_subgroup G] (respf : H \u2286 ker f) (HsubG : H \u2286 G) :\n  ker_in (extend H G f) (qproj H ' G) = qproj H ' (ker_in f G) :=\next (take aH,\n  obtain a [(anH : a \u2208 normalizer H) (aHeq : a '* H = aH)],\n    from surj_on_qproj_normalizer H (show aH \u2208 univ, from trivial),\n  begin\n    rewrite -aHeq, apply iff.intro, unfold ker_in,\n    exact\n      (assume aker : a '* H \u2208 ker (extend H G f) \u2229 (qproj H ' G),\n        have a '* H \u2208 qproj H ' G, from and.right aker,\n        have a \u2208 G, from mem_of_qproj_mem anH HsubG this,\n        -- Uncommenting the next line of code slows things down dramatically.\n        -- Uncommenting the one after kills the system.\n        -- have a '* H \u2208 ker (extend H G f), from and.left aker,\n        -- have extend H G f (a '* H) = 1, from this,\n        -- have f a = extend H G f (a '* H), from eq.symm (extend_qproj respf `a \u2208 G`),\n        -- have f a = 1, by rewrite [-this, extend_qproj respf aG],\n        -- have a \u2208 ker_in f G, from and.intro this `a \u2208 G`,\n        show a '* H \u2208 qproj H ' (ker_in f G), from sorry),\n    exact\n      (assume hyp : a '* H \u2208 qproj H ' (ker_in f G),\n        show a '* H \u2208 ker_in (extend H G f) (qproj H ' G), from sorry)\n  end)\n-/\n\nend respf\n\nattribute quotient [irreducible]\n\nend quotient_group_general\n\n/- the first homomorphism theorem for general quotient groups -/\n\nnamespace quotient_group_general\n\nvariables [group A] [group B] (G : set A) [is_subgroup G]\nvariables (f : A \u2192 B) [is_hom_on f G]\n\nnoncomputable definition bar : quotient (ker_in f G) \u2192 B :=\nextend (ker_in f G) G f\n\nproposition bar_qproj {a : A} (aG : a \u2208 G) : bar G f (a '* ker_in f G) = f a :=\nextend_qproj (inter_subset_left _ _) aG\n\nproposition is_hom_on_bar [instance] : is_hom_on (bar G f) (G / ker_in f G) :=\nhave is_subgroup (ker f \u2229 G), from is_subgroup_ker_in f G,\nhave is_normal_in (ker f \u2229 G) G, from is_normal_in_ker_in f G,\nis_hom_on_extend G (inter_subset_left _ _)\n\nproposition image_bar {s : set A} (ssubG : s \u2286 G) : bar G f ' (s / ker_in f G) = f ' s :=\nhave is_subgroup (ker f \u2229 G), from is_subgroup_ker_in f G,\nhave is_normal_in (ker f \u2229 G) G, from is_normal_in_ker_in f G,\nimage_extend (inter_subset_left _ _) ssubG\n\nproposition surj_on_bar : surj_on (bar G f) (G / ker_in f G) (f ' G) :=\nby rewrite [\u2191surj_on, image_bar G f (@subset.refl _ G)]; apply subset.refl\n\nproposition ker_in_bar : ker_in (bar G f) (G / ker_in f G) = '{1} :=\nhave H\u2080 : ker_in f G \u2286 ker f, from inter_subset_left _ _,\nhave H\u2081 : ker_in f G \u2286 G, from inter_subset_right _ _,\nby rewrite [\u2191bar, ker_in_extend H\u2080 H\u2081, image_qproj_self]\n\nproposition inj_on_bar : inj_on (bar G f) (G / ker_in f G) :=\ninj_on_of_ker_in_eq_singleton_one (ker_in_bar G f)\n\nend quotient_group_general\n\nend group_theory\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/theories/group_theory/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7254957721289568}}
{"text": "/-\nCopyright (c) 2021 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey\n-/\nimport algebra.periodic\nimport data.nat.count\nimport data.nat.interval\n\n/-!\n# Periodic Functions on \u2115\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file identifies a few functions on `\u2115` which are periodic, and also proves a lemma about\nperiodic predicates which helps determine their cardinality when filtering intervals over them.\n-/\n\nnamespace nat\n\nopen nat function\n\nlemma periodic_gcd (a : \u2115) : periodic (gcd a) a :=\nby simp only [forall_const, gcd_add_self_right, eq_self_iff_true, periodic]\n\nlemma periodic_coprime (a : \u2115) : periodic (coprime a) a :=\nby simp only [coprime_add_self_right, forall_const, iff_self, eq_iff_iff, periodic]\n\nlemma periodic_mod (a : \u2115) : periodic (\u03bb n, n % a) a :=\nby simp only [forall_const, eq_self_iff_true, add_mod_right, periodic]\n\nlemma _root_.function.periodic.map_mod_nat {\u03b1 : Type*} {f : \u2115 \u2192 \u03b1} {a : \u2115} (hf : periodic f a) :\n  \u2200 n, f (n % a) = f n :=\n\u03bb n, by conv_rhs { rw [\u2190 nat.mod_add_div n a, mul_comm, \u2190 nat.nsmul_eq_mul, hf.nsmul] }\n\nsection multiset\nopen multiset\n\n/-- An interval of length `a` filtered over a periodic predicate of period `a` has cardinality\nequal to the number naturals below `a` for which `p a` is true. -/\nlemma filter_multiset_Ico_card_eq_of_periodic (n a : \u2115) (p : \u2115 \u2192 Prop) [decidable_pred p]\n  (pp : periodic p a) :\n  (filter p (Ico n (n+a))).card = a.count p :=\nbegin\n  rw [count_eq_card_filter_range, finset.card, finset.filter_val, finset.range_val,\n    \u2190multiset_Ico_map_mod n, \u2190map_count_true_eq_filter_card, \u2190map_count_true_eq_filter_card,\n    map_map, function.comp],\n  simp only [pp.map_mod_nat],\nend\n\nend multiset\n\nsection finset\nopen finset\n\n/-- An interval of length `a` filtered over a periodic predicate of period `a` has cardinality\nequal to the number naturals below `a` for which `p a` is true. -/\nlemma filter_Ico_card_eq_of_periodic (n a : \u2115) (p : \u2115 \u2192 Prop) [decidable_pred p]\n  (pp : periodic p a) :\n  ((Ico n (n + a)).filter p).card = a.count p :=\nfilter_multiset_Ico_card_eq_of_periodic n a p pp\n\nend finset\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/periodic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509007, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7254901063708215}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport data.polynomial.cardinal\nimport ring_theory.algebraic\n\n/-!\n### Cardinality of algebraic numbers\n\nIn this file, we prove variants of the following result: the cardinality of algebraic numbers under\nan R-algebra is at most `# polynomial R * \u2135\u2080`.\n\nAlthough this can be used to prove that real or complex transcendental numbers exist, a more direct\nproof is given by `liouville.is_transcendental`.\n-/\n\nuniverses u v\n\nopen cardinal polynomial\nopen_locale cardinal\n\nnamespace algebraic\n\ntheorem aleph_0_le_cardinal_mk_of_char_zero (R A : Type*) [comm_ring R] [is_domain R]\n  [ring A] [algebra R A] [char_zero A] : \u2135\u2080 \u2264 #{x : A // is_algebraic R x} :=\n@mk_le_of_injective (ulift \u2115) {x : A | is_algebraic R x} (\u03bb n, \u27e8_, is_algebraic_nat n.down\u27e9)\n  (\u03bb m n hmn, by simpa using hmn)\n\nsection lift\n\nvariables (R : Type u) (A : Type v) [comm_ring R] [comm_ring A] [is_domain A] [algebra R A]\n  [no_zero_smul_divisors R A]\n\ntheorem cardinal_mk_lift_le_mul :\n  cardinal.lift.{u v} (#{x : A // is_algebraic R x}) \u2264 cardinal.lift.{v u} (#(polynomial R)) * \u2135\u2080 :=\nbegin\n  rw [\u2190mk_ulift, \u2190mk_ulift],\n  let g : ulift.{u} {x : A | is_algebraic R x} \u2192 ulift.{v} (polynomial R) :=\n    \u03bb x, ulift.up (classical.some x.1.2),\n  apply cardinal.mk_le_mk_mul_of_mk_preimage_le g (\u03bb f, _),\n  suffices : fintype (g \u207b\u00b9' {f}),\n  { exact @mk_le_aleph_0 _ (@fintype.to_encodable _ this) },\n  by_cases hf : f.1 = 0,\n  { convert set.fintype_empty,\n    apply set.eq_empty_iff_forall_not_mem.2 (\u03bb x hx, _),\n    simp only [set.mem_preimage, set.mem_singleton_iff] at hx,\n    apply_fun ulift.down at hx,\n    rw hf at hx,\n    exact (classical.some_spec x.1.2).1 hx },\n  let h : g \u207b\u00b9' {f} \u2192 f.down.root_set A := \u03bb x, \u27e8x.1.1.1, (mem_root_set_iff hf x.1.1.1).2 begin\n    have key' : g x = f := x.2,\n    simp_rw \u2190 key',\n    exact (classical.some_spec x.1.1.2).2\n  end\u27e9,\n  apply fintype.of_injective h (\u03bb _ _ H, _),\n  simp only [subtype.val_eq_coe, subtype.mk_eq_mk] at H,\n  exact subtype.ext (ulift.down_injective (subtype.ext H))\nend\n\ntheorem cardinal_mk_lift_le_max :\n  cardinal.lift.{u v} (#{x : A // is_algebraic R x}) \u2264 max (cardinal.lift.{v u} (#R)) \u2135\u2080 :=\n(cardinal_mk_lift_le_mul R A).trans $\n  (mul_le_mul_right' (lift_le.2 cardinal_mk_le_max) _).trans $ by simp [le_total]\n\ntheorem cardinal_mk_lift_le_of_infinite [infinite R] :\n  cardinal.lift.{u v} (#{x : A // is_algebraic R x}) \u2264 cardinal.lift.{v u} (#R) :=\n(cardinal_mk_lift_le_max R A).trans $ by simp\n\nvariable [encodable R]\n\n@[simp] theorem countable_of_encodable : set.countable {x : A | is_algebraic R x} :=\nbegin\n  rw [\u2190mk_set_le_aleph_0, \u2190lift_le],\n  apply (cardinal_mk_lift_le_max R A).trans,\n  simp\nend\n\n@[simp] theorem cardinal_mk_of_encodable_of_char_zero [char_zero A] [is_domain R] :\n  #{x : A // is_algebraic R x} = \u2135\u2080 :=\nle_antisymm (by simp) (aleph_0_le_cardinal_mk_of_char_zero R A)\n\nend lift\n\nsection non_lift\n\nvariables (R A : Type u) [comm_ring R] [comm_ring A] [is_domain A] [algebra R A]\n  [no_zero_smul_divisors R A]\n\ntheorem cardinal_mk_le_mul : #{x : A // is_algebraic R x} \u2264 #(polynomial R) * \u2135\u2080 :=\nby { rw [\u2190lift_id (#_), \u2190lift_id (#(polynomial R))], exact cardinal_mk_lift_le_mul R A }\n\ntheorem cardinal_mk_le_max : #{x : A // is_algebraic R x} \u2264 max (#R) \u2135\u2080 :=\nby { rw [\u2190lift_id (#_), \u2190lift_id (#R)], exact cardinal_mk_lift_le_max R A }\n\ntheorem cardinal_mk_le_of_infinite [infinite R] : #{x : A // is_algebraic R x} \u2264 #R :=\n(cardinal_mk_le_max R A).trans $ by simp\n\nend non_lift\n\nend algebraic\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/algebraic_card.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7254660346263615}}
{"text": "/-\nCopyright (c) 2022 Praneeth Kolichala. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Praneeth Kolichala\n-/\nimport data.num.lemmas\nimport data.nat.log\nimport lists\nimport log_lemmas\n\n/-!\n# Conversion of `num` to and from `list bool`\n\nThis file provides functions to encode `num` as a `list bool` and decode `list bool`'s into `num`'s.\nFor convenience, the decoding function always returns a value. If the most significant bit isn't\n`1`, it implicitly changes it to `1` when decoding. We then prove several lemmas about this\nencoding.\n-/\n\nnamespace pos_num\n\n/-- Convert a `pos_num` to a `list bool` in little-endian form (with LSB at the head).\nThis is an equivalence, so the msb (which is always present for positive numbers) is omitted. -/\ndef to_trailing_bits : pos_num \u2192 list bool\n| 1 := []\n| (bit0 xs) := ff :: xs.to_trailing_bits\n| (bit1 xs) := tt :: xs.to_trailing_bits\n\n/-- Equivalence between `pos_num` and `list bool` with lsb at the head and msb omitted -/\ndef equiv_list_bool : pos_num \u2243 list bool :=\n{ to_fun := to_trailing_bits,\n  inv_fun := \u03bb l, l.foldr (\u03bb b n, (cond b bit1 bit0) n) 1,\n  left_inv := \u03bb n, by induction n; simpa [to_trailing_bits],\n  right_inv := \u03bb l, by { induction l with hd, { refl, }, cases hd; simpa [to_trailing_bits], } }\n\n@[simp] lemma equiv_list_bool_one : equiv_list_bool 1 = [] := rfl\n@[simp] lemma equiv_list_bool_bit0 (n : pos_num) :\n  equiv_list_bool (bit0 n) = ff :: equiv_list_bool n := rfl\n@[simp] lemma equiv_list_bool_bit1 (n : pos_num) :\n  equiv_list_bool (bit1 n) = tt :: equiv_list_bool n := rfl\n@[simp] lemma equiv_list_bool_symm_cons_tt (l : list bool) :\n  equiv_list_bool.symm (tt :: l) = bit1 (equiv_list_bool.symm l) := rfl\n@[simp] lemma equiv_list_bool_symm_cons_ff (l : list bool) :\n  equiv_list_bool.symm (ff :: l) = bit0 (equiv_list_bool.symm l) := rfl\n\nlemma to_trailing_bits_len (n : pos_num) : (equiv_list_bool n).length = nat.log 2 n :=\nbegin\n  induction n with b ih b ih, { erw equiv_list_bool_one, simp, },\n  { simp [cast_bit1, nat.bit1_val b, ih], },\n  { simp [cast_bit0, nat.bit0_val b, ih], }\nend\n\nlemma equiv_list_bool_symm_lt (ls : list bool) : (equiv_list_bool.symm ls : \u2115) < 2^(ls.length+1) :=\nbegin\n  induction ls with hd tl ih, { simp [equiv_list_bool], },\n  cases hd,\n  { simp only [equiv_list_bool_symm_cons_ff, pos_num.cast_bit0],\n    rw [nat.bit0_val, mul_comm, pow_add], simpa, },\n  { simp only [equiv_list_bool_symm_cons_tt, pos_num.cast_bit1],\n    rw [nat.bit1_val, add_comm, pow_add],\n    apply @nat.lt_of_div_lt_div _ _ 2,\n    simpa [nat.add_mul_div_left, nat.div_eq_of_lt], },\nend\n\nend pos_num\n\nnamespace num\n\n/-- An encoding function of the binary numbers in bool. -/\ndef to_bits : num \u2192 list bool\n| num.zero := []\n| (num.pos n) := (pos_num.equiv_list_bool n) ++ [tt]\n\n@[simp] lemma to_bits_zero : to_bits 0 = [] := rfl\n\n@[simp] lemma to_bits_bit0 (n : num) (hn : n \u2260 0) : (num.bit0 n).to_bits = ff :: n.to_bits :=\nby { cases n, { contradiction, }, simp [to_bits, num.bit0], }\n\n@[simp] lemma to_bits_bit0' (n : num) (hn : n \u2260 0) : (_root_.bit0 n).to_bits = ff :: n.to_bits :=\nby { convert to_bits_bit0 _ hn, exact bit0_of_bit0 n, }\n\n@[simp] lemma to_bits_bit1 (n : num) : (num.bit1 n).to_bits = tt :: n.to_bits :=\nby { cases n, { refl, }, simp [to_bits, num.bit1], }\n\n@[simp] lemma to_bits_bit1' (n : num) : (_root_.bit1 n).to_bits = tt :: n.to_bits :=\nby { convert to_bits_bit1 n, exact bit1_of_bit1 n, }\n\n/-- A decoding function from `list bool` to `num` -/\ndef of_bits (L : list bool) : num := if L = [] then 0 else pos_num.equiv_list_bool.symm L.init\n\n@[simp] lemma of_bits_nil : of_bits [] = 0 := rfl\n@[simp] lemma of_bits_cons_ff (l : list bool) (hl : l \u2260 []) :\n  of_bits (ff :: l) = num.bit0 (of_bits l) := by simp [of_bits, hl, num.bit0]\n@[simp] lemma of_bits_cons_tt (l : list bool) : of_bits (tt :: l) = num.bit1 (of_bits l) :=\nby { cases l, { refl, }, simp [of_bits, num.bit1], }\n\n@[simp] lemma of_bits_to_bits (n : num) : of_bits (to_bits n) = n :=\nby { cases n, { refl, }, simp [of_bits, to_bits], }\n\nlemma of_bits_to_bits_left_inv : function.left_inverse of_bits to_bits := of_bits_to_bits\n\nlemma mem_to_bits_range_iff (l : list bool) :\n  l \u2208 set.range to_bits \u2194 l = [] \u2228 tt \u2208 l.last' :=\nbegin\n  split, { rintro \u27e8n, rfl\u27e9, cases n; simp [to_bits], },\n  apply list.reverse_cases_on l, { intro, use 0, refl, },\n  intros st lt h,\n  use (pos_num.equiv_list_bool.symm st),\n  symmetry, simpa [to_bits] using h,\nend\n\nlemma mem_to_bits_range_of_cons {hd : bool} {tl : list bool} (h : hd :: tl \u2208 set.range to_bits) :\n  tl \u2208 set.range to_bits :=\nby { rw mem_to_bits_range_iff at \u22a2 h, cases tl with hd' tl', { exact or.inl rfl, }, simpa using h, }\n\n@[simp] lemma to_bits_of_bits_valid {l : list bool} (h : l \u2208 set.range to_bits) :\n  to_bits (of_bits l) = l := of_bits_to_bits_left_inv.right_inv_on_range h\n\n@[simp] lemma of_bits_invalid (l : list bool) :\n  of_bits (l ++ [ff]) = of_bits (l ++ [tt]) := by simp [of_bits]\n\nlemma to_bits_len (n : num) : (to_bits n).length = if n = 0 then 0 else nat.log 2 n + 1 :=\nbegin\n  cases n, { refl, },\n  simp [(show pos n \u2260 0, by trivial), to_bits, pos_num.to_trailing_bits_len],\nend\n\nlemma to_bits_len_le (n : num) : (to_bits n).length \u2264 nat.log 2 n + 1 :=\nby { rw to_bits_len, split_ifs with h; simp [h],  }\n\nlemma of_bits_lt (l : list bool) : (of_bits l : \u2115) < 2^l.length :=\nbegin\n  apply list.reverse_cases_on l, { simp [of_bits], },\n  intros st tl, cases tl; simpa [of_bits] using pos_num.equiv_list_bool_symm_lt _,\nend\n\nlemma le_of_bits (l : list bool) (hl : l \u2260 []) : 2^(l.length - 1) \u2264 (of_bits l : \u2115) :=\nbegin\n  induction l with hd tl ih, { contradiction, },\n  cases tl with h t, { cases hd; simp [of_bits], },\n  specialize ih (by trivial),\n  cases hd,\n  { simpa [pow_add, nat.bit0_val (of_bits (h :: t)), mul_comm] using ih, },\n  simp only [of_bits_cons_tt, nat.bit1_val (of_bits (h :: t)), num.cast_bit1],\n  refine trans _ (nat.le_succ _),\n  simpa [pow_add, mul_comm] using ih,\nend\n\nlemma of_bits_strict_mono (l\u2081 l\u2082 : list bool) (h : l\u2081.length < l\u2082.length) :\n  (of_bits l\u2081 : \u2115) < of_bits l\u2082 :=\ncalc (of_bits l\u2081 : \u2115) < 2^l\u2081.length : of_bits_lt l\u2081\n                    ...  \u2264 2^(l\u2082.length - 1) : pow_mono (show 1 \u2264 2, by simp) (nat.le_pred_of_lt h)\n                    ...  \u2264 of_bits l\u2082 : le_of_bits l\u2082 (by { rintro rfl, simpa using h, })\n\n@[simp] lemma to_bits_nil_iff (n : num) : to_bits n = [] \u2194 n = 0 :=\n\u27e8\u03bb h, by simpa using congr_arg of_bits h, \u03bb h, by { rw h, refl, }\u27e9\n\n@[simp] lemma of_bits_zero_iff (l : list bool) : of_bits l = 0 \u2194 l = [] :=\n\u27e8\u03bb h, by { by_contra H, simp [of_bits, H] at h, contradiction, }, \u03bb h, by { rw h, refl, }\u27e9\n\nend num", "meta": {"author": "prakol16", "repo": "lean_complexity_theory_polytime_defs", "sha": "b4e5f5544e11cd5aca1a5a4b5b0231537af4962c", "save_path": "github-repos/lean/prakol16-lean_complexity_theory_polytime_defs", "path": "github-repos/lean/prakol16-lean_complexity_theory_polytime_defs/lean_complexity_theory_polytime_defs-b4e5f5544e11cd5aca1a5a4b5b0231537af4962c/src/to_bits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7254660292399161}}
{"text": "namespace TBA\n\n-- Let's work with some inductive types other than `Nat`!\n\n-- Here is our very own definition of `List`:\ninductive List (\u03b1 : Type) where\n  | nil : List \u03b1\n  | cons (head : \u03b1) (tail : List \u03b1) : List \u03b1\n\nnotation  (priority := high) \"[\" \"]\" => List.nil   -- `[]`\ninfixr:67 (priority := high) \" :: \"  => List.cons  -- `a :: as`\n\n-- as a warmup exercise, let's define concatenation of two lists\ndef append (as bs : List \u03b1) : List \u03b1 := \n  match as with\n  | []      => bs\n  | a :: as => a :: append as bs\n\ninfixl:65 (priority := high) \" ++ \" => append\n\nexample : 1::2::[] ++ 3::4::[] = 1::2::3::4::[] := rfl\n\n-- as with associativity on `Nat`, think twice about what induction variable to use!\ntheorem append_assoc {as bs cs : List \u03b1} : (as ++ bs) ++ cs = as ++ (bs ++ cs) := by\n  induction as with\n  | nil => rfl\n  | cons a as ih => simp [append, ih]\n\nopen Decidable\n\n/-\nOne important special case of `Decidable` is decidability of equalities:\n```\nabbrev DecidableEq (\u03b1 : Type) :=\n  (a b : \u03b1) \u2192 Decidable (a = b)\n\ndef decEq [s : DecidableEq \u03b1] (a b : \u03b1) : Decidable (a = b) :=\n  s a b\n```\nNote: `DecidableEq` is defined using `abbrev` instead of `def` because typeclass resolution only\nunfolds the former for performance reasons.\n\nLet's try to prove that `List` equality is decidable!\n-/\n-- hint: Something is still missing. Do we need to assume anything about `\u03b1`?\n-- hint: Apply `match` case distinctions until the the appropriate `Decidable` constructor is clear,\n--   then fill in its proof argument with `by`.\n--   We could also do everything in a `by` block, but it's nicer to reserve tactics for proofs so we have\n--   more control about the code of programs, i.e. the part that is actually executed\ndef ldecEq [DecidableEq \u03b1] (as bs : List \u03b1) : Decidable (as = bs) := /-SOL_-/\n  match as, bs with\n  | [],      []      => isTrue rfl\n  | [],      b :: bs => isFalse (by intro h; contradiction)  -- or simply:\n  | a :: as, []      => isFalse (by simp_all)\n  | a :: as, b :: bs =>\n    match decEq a b, ldecEq as bs with\n    | isTrue _,  isTrue _  => isTrue (by simp_all)\n    | isFalse _, _         => isFalse (by intro h; injection h; simp_all)\n    | _,         isFalse _ => isFalse (by intro h; injection h; simp_all)\n\n-- Let's declare the instance:\ninstance [DecidableEq \u03b1] : DecidableEq (List \u03b1) := /-SOL_-/ldecEq/-END-/\n\n-- This should now work:\n#eval decEq (1::2::[]) (1::3::[])\n\n/-\n`DecidabePred` is another convenient abbreviation of `Decidable`\n```\nabbrev DecidablePred (r : \u03b1 \u2192 Prop) :=\n  (a : \u03b1) \u2192 Decidable (r a)\n```\nIf we have `[DecidablePred p]`, we can e.g. use `if p a then ...` for some `a : \u03b1`.\n\n`filter p as` is a simple list function that should remove all elements `a` for which `p a` does not hold.\n-/\ndef filter (p : \u03b1 \u2192 Prop) [DecidablePred p] (as : List \u03b1) : List \u03b1 := \n  match as with\n  | [] => []\n  | a::as => if p a then a :: filter p as else filter p as\n\nexample : filter (fun x => x % 2 = 0) (1::2::3::4::[]) = 2::4::[] := rfl\n\nvariable {p : \u03b1 \u2192 Prop} [DecidablePred p] {as bs : List \u03b1}\n\n-- These helper theorems can be useful, also for manual rewriting\n@[simp] theorem filter_cons_true (h : p a) : filter p (a :: as) = a :: filter p as :=\n  by simp [filter, h]\n@[simp] theorem filter_cons_false (h : \u00ac p a) : filter p (a :: as) = filter p as :=\n  by simp [filter, h]\n-- It's worthwhile thinking about what's actually happening here:\n-- * first, `filter p (a :: as)` is unfolded to `if p a then a :: filter p as else filter p as`\n--   (note that the second `filter` cannot be unfolded)\n-- * then `if p a then ...` is rewritten to `if True then ...` using `h`\n-- * finally, `if True then a :: filter p as else ...` is rewritten to `a :: filter p as` using\n--   the built-in simp theorem `Lean.Simp.ite_True`\n\n-- useful tactic: `byCases h : q` for a decidable proposition `q`\ntheorem filter_idem : filter p (filter p as) = filter p as := by\n  induction as with\n  | nil => rfl\n  | cons a as ih => byCases h : p a <;> simp [ih, h]\n\ntheorem filter_append : filter p (as ++ bs) = filter p as ++ filter p bs := by\n  induction as with\n  | nil => rfl\n  | cons a as ih => byCases h : p a <;> simp [append, ih, h]\n\n-- list membership as an inductive predicate:\ninductive Mem (a : \u03b1) : List \u03b1 \u2192 Prop where\n  -- either it's the first element...\n  | head {as} : Mem a (a::as)\n  -- or it's in the remainder list\n  | tail {as} : Mem a as \u2192 Mem a (a'::as)\n\ninfix:50 \" \u2208 \" => Mem\n\n-- recall that `a \u2260 b` is the same as `a = b \u2192 False`\ntheorem mem_of_nonempty_filter (h : \u2200 a, p a \u2192 a = x) : filter p as \u2260 [] \u2192 x \u2208 as := by\n  intro hfil\n  induction as with\n  | nil => contradiction\n  | cons a as ih =>\n    byCases hpa : p a\n    case inl =>\n      rw [h _ hpa]\n      exact Mem.head\n    case inr =>\n      rw [filter_cons_false hpa] at hfil\n      exact Mem.tail (ih hfil)\n\n-- This proof is pretty long! Some hints:\n-- * If you have an assumption `h : a \u2208 []`, you can solve the current goal by `cases h`:\n--   since there is no constructor that could possibly match `[]`, there is nothing left to prove!\n--   This exclusion of cases, and case analysis on inductive predicates in general,\n--   is also called *rule inversion* since we (try to) apply the introduction rules (constructors)\n--   \"in reverse\".\n-- * On the other hand, if you try to do case analysis on a proof of e.g. `a \u2208 filter p as`,\n--   Lean will complain with \"dependent elimination failed\" since it *doesn't* know yet if\n--   the argument `filter p as` is of the form `_ :: _` as demanded by the `Mem` constructors.\n--   You need to get the assumption into the shape `_ \u2208 []` or `_ \u2208 _ :: _` before applying\n--   `(no)match/cases` to it.\ntheorem mem_filter : a \u2208 filter p as \u2194 a \u2208 as \u2227 p a := by\n  apply Iff.intro\n  case mp =>\n    intro h\n    induction as with\n    | nil => cases h\n    | cons a' as ih =>\n      byCases ha' : p a'\n      case inl =>\n        rw [filter_cons_true ha'] at h\n        cases h with\n        | head => exact \u27e8Mem.head, ha'\u27e9\n        | tail h => exact \u27e8Mem.tail (ih h).1, (ih h).2\u27e9\n      case inr =>\n        rw [filter_cons_false ha'] at h\n        exact \u27e8Mem.tail (ih h).1, (ih h).2\u27e9\n  case mpr =>\n    intro h\n    induction as with\n    | nil => cases h.1\n    | cons a' as ih =>\n      cases h.1 with\n      | head =>\n        rw [filter_cons_true h.2]\n        constructor\n      | tail ha =>\n        have : a \u2208 filter p as := ih \u27e8ha, h.2\u27e9\n        byCases hpa' : p a'\n        case inl =>\n          rw [filter_cons_true hpa']\n          apply Mem.tail this\n        case inr =>\n          rw [filter_cons_false hpa']\n          apply this\n\n-- Here is an alternative definition of list membership via `append`\ninductive Mem' (a : \u03b1) : List \u03b1 \u2192 Prop where\n  | intro (as bs) : Mem' a (as ++ (a :: bs))\n\ninfix:50 \" \u2208' \" => Mem'\n\n-- Let's prove that they are equivalent!\ntheorem mem_mem' : a \u2208 as \u2194 a \u2208' as := by\n  constructor\n  case mp =>\n    intro h\n    induction h with\n    | head => exact \u27e8[], _\u27e9\n    | tail h ih =>\n      have \u27e8as', bs'\u27e9 := ih\n      exact \u27e8_::as', _\u27e9\n  case mpr =>\n    intro \u27e8as', bs'\u27e9\n    induction as' with\n    | nil => exact Mem.head\n    | cons a' as' ih => exact Mem.tail ih\n\nend TBA\n", "meta": {"author": "IPDSnelting", "repo": "tba-2021", "sha": "b6390e55b768423d3266969e81d19290129c5914", "save_path": "github-repos/lean/IPDSnelting-tba-2021", "path": "github-repos/lean/IPDSnelting-tba-2021/tba-2021-b6390e55b768423d3266969e81d19290129c5914/TBA/Solutions/Exercise5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951064805861, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7254660292399161}}
{"text": "/-\nCopyright (c) 2014 Parikshit Khanna. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro\n-/\nimport data.list.big_operators\n\n/-!\n# Counting in lists\n\nThis file proves basic properties of `list.countp` and `list.count`, which count the number of\nelements of a list satisfying a predicate and equal to a given element respectively. Their\ndefinitions can be found in [`data.list.defs`](./data/list/defs).\n-/\n\nopen nat\n\nvariables {\u03b1 \u03b2 : Type*} {l l\u2081 l\u2082 : list \u03b1}\n\nnamespace list\n\nsection countp\nvariables (p : \u03b1 \u2192 Prop) [decidable_pred p]\n\n@[simp] lemma countp_nil : countp p [] = 0 := rfl\n\n@[simp] lemma countp_cons_of_pos {a : \u03b1} (l) (pa : p a) : countp p (a::l) = countp p l + 1 :=\nif_pos pa\n\n@[simp] lemma countp_cons_of_neg {a : \u03b1} (l) (pa : \u00ac p a) : countp p (a::l) = countp p l :=\nif_neg pa\n\nlemma length_eq_countp_add_countp (l) : length l = countp p l + countp (\u03bb a, \u00acp a) l :=\nby induction l with x h ih; [refl, by_cases p x];\n  [simp only [countp_cons_of_pos _ _ h, countp_cons_of_neg (\u03bb a, \u00acp a) _ (decidable.not_not.2 h),\n    ih, length],\n   simp only [countp_cons_of_pos (\u03bb a, \u00acp a) _ h, countp_cons_of_neg _ _ h, ih, length]]; ac_refl\n\nlemma countp_eq_length_filter (l) : countp p l = length (filter p l) :=\nby induction l with x l ih; [refl, by_cases (p x)];\n  [simp only [filter_cons_of_pos _ h, countp, ih, if_pos h],\n   simp only [countp_cons_of_neg _ _ h, ih, filter_cons_of_neg _ h]]; refl\n\n@[simp] lemma countp_append (l\u2081 l\u2082) : countp p (l\u2081 ++ l\u2082) = countp p l\u2081 + countp p l\u2082 :=\nby simp only [countp_eq_length_filter, filter_append, length_append]\n\nlemma countp_pos {l} : 0 < countp p l \u2194 \u2203 a \u2208 l, p a :=\nby simp only [countp_eq_length_filter, length_pos_iff_exists_mem, mem_filter, exists_prop]\n\nlemma length_filter_lt_length_iff_exists (l) : length (filter p l) < length l \u2194 \u2203 x \u2208 l, \u00acp x :=\nby rw [length_eq_countp_add_countp p l, \u2190 countp_pos, countp_eq_length_filter, lt_add_iff_pos_right]\n\nlemma sublist.countp_le (s : l\u2081 <+ l\u2082) : countp p l\u2081 \u2264 countp p l\u2082 :=\nby simpa only [countp_eq_length_filter] using length_le_of_sublist (s.filter p)\n\n@[simp] lemma countp_filter {q} [decidable_pred q] (l : list \u03b1) :\n  countp p (filter q l) = countp (\u03bb a, p a \u2227 q a) l :=\nby simp only [countp_eq_length_filter, filter_filter]\n\nend countp\n\n/-! ### count -/\n\nsection count\nvariables [decidable_eq \u03b1]\n\n@[simp] lemma count_nil (a : \u03b1) : count a [] = 0 := rfl\n\nlemma count_cons (a b : \u03b1) (l : list \u03b1) :\n  count a (b :: l) = if a = b then succ (count a l) else count a l := rfl\n\nlemma count_cons' (a b : \u03b1) (l : list \u03b1) :\n  count a (b :: l) = count a l + (if a = b then 1 else 0) :=\nbegin rw count_cons, split_ifs; refl end\n\n@[simp] lemma count_cons_self (a : \u03b1) (l : list \u03b1) : count a (a::l) = succ (count a l) := if_pos rfl\n\n@[simp, priority 990]\nlemma count_cons_of_ne {a b : \u03b1} (h : a \u2260 b) (l : list \u03b1) : count a (b::l) = count a l := if_neg h\n\nlemma count_tail : \u03a0 (l : list \u03b1) (a : \u03b1) (h : 0 < l.length),\n  l.tail.count a = l.count a - ite (a = list.nth_le l 0 h) 1 0\n| (_ :: _) a h := by { rw [count_cons], split_ifs; simp }\n\nlemma sublist.count_le (h : l\u2081 <+ l\u2082) (a : \u03b1) : count a l\u2081 \u2264 count a l\u2082 := h.countp_le _\n\nlemma count_le_count_cons (a b : \u03b1) (l : list \u03b1) : count a l \u2264 count a (b :: l) :=\n(sublist_cons _ _).count_le _\n\nlemma count_singleton (a : \u03b1) : count a [a] = 1 := if_pos rfl\n\n@[simp] lemma count_append (a : \u03b1) : \u2200 l\u2081 l\u2082, count a (l\u2081 ++ l\u2082) = count a l\u2081 + count a l\u2082 :=\ncountp_append _\n\nlemma count_concat (a : \u03b1) (l : list \u03b1) : count a (concat l a) = succ (count a l) :=\nby simp [-add_comm]\n\nlemma count_pos {a : \u03b1} {l : list \u03b1} : 0 < count a l \u2194 a \u2208 l :=\nby simp only [count, countp_pos, exists_prop, exists_eq_right']\n\n@[simp, priority 980]\nlemma count_eq_zero_of_not_mem {a : \u03b1} {l : list \u03b1} (h : a \u2209 l) : count a l = 0 :=\ndecidable.by_contradiction $ \u03bb h', h $ count_pos.1 (nat.pos_of_ne_zero h')\n\nlemma not_mem_of_count_eq_zero {a : \u03b1} {l : list \u03b1} (h : count a l = 0) : a \u2209 l :=\n\u03bb h', (count_pos.2 h').ne' h\n\n@[simp] lemma count_repeat (a : \u03b1) (n : \u2115) : count a (repeat a n) = n :=\nby rw [count, countp_eq_length_filter, filter_eq_self.2, length_repeat];\n   exact \u03bb b m, (eq_of_mem_repeat m).symm\n\nlemma le_count_iff_repeat_sublist {a : \u03b1} {l : list \u03b1} {n : \u2115} :\n  n \u2264 count a l \u2194 repeat a n <+ l :=\n\u27e8\u03bb h, ((repeat_sublist_repeat a).2 h).trans $\n  have filter (eq a) l = repeat a (count a l), from eq_repeat.2\n    \u27e8by simp only [count, countp_eq_length_filter], \u03bb b m, (of_mem_filter m).symm\u27e9,\n  by rw \u2190 this; apply filter_sublist,\n \u03bb h, by simpa only [count_repeat] using h.count_le a\u27e9\n\nlemma repeat_count_eq_of_count_eq_length  {a : \u03b1} {l : list \u03b1} (h : count a l = length l)  :\n  repeat a (count a l) = l :=\neq_of_sublist_of_length_eq (le_count_iff_repeat_sublist.mp (le_refl (count a l)))\n    (eq.trans (length_repeat a (count a l)) h)\n\n@[simp] lemma count_filter {p} [decidable_pred p]\n  {a} {l : list \u03b1} (h : p a) : count a (filter p l) = count a l :=\nby simp only [count, countp_filter]; congr; exact\nset.ext (\u03bb b, and_iff_left_of_imp (\u03bb e, e \u25b8 h))\n\nlemma count_bind {\u03b1 \u03b2} [decidable_eq \u03b2] (l : list \u03b1) (f : \u03b1 \u2192 list \u03b2) (x : \u03b2)  :\n  count x (l.bind f) = sum (map (count x \u2218 f) l) :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simpa }\nend\n\n@[simp] lemma count_map_map {\u03b1 \u03b2} [decidable_eq \u03b1] [decidable_eq \u03b2] (l : list \u03b1) (f : \u03b1 \u2192 \u03b2)\n  (hf : function.injective f) (x : \u03b1) :\n  count (f x) (map f l) = count x l :=\nbegin\n  induction l with y l IH generalizing x,\n  { simp },\n  { rw map_cons,\n    by_cases h : x = y,\n    { simpa [h] using IH _ },\n    { simpa [h, hf.ne h] using IH _ } }\nend\n\n@[simp] lemma count_erase_self (a : \u03b1) :\n  \u2200 (s : list \u03b1), count a (list.erase s a) = pred (count a s)\n| [] := by simp\n| (h :: t) :=\nbegin\n  rw erase_cons,\n  by_cases p : h = a,\n  { rw [if_pos p, count_cons', if_pos p.symm], simp },\n  { rw [if_neg p, count_cons', count_cons', if_neg (\u03bb x : a = h, p x.symm), count_erase_self],\n    simp }\nend\n\n@[simp] lemma count_erase_of_ne {a b : \u03b1} (ab : a \u2260 b) :\n  \u2200 (s : list \u03b1), count a (list.erase s b) = count a s\n| [] := by simp\n| (x :: xs) :=\nbegin\n  rw erase_cons,\n  split_ifs with h,\n  { rw [count_cons', h, if_neg ab], simp },\n  { rw [count_cons', count_cons', count_erase_of_ne] }\nend\n\nend count\n\nend list\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/list/count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764118, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7254660233249818}}
{"text": "/-\nCopyright (c) 2020 Markus Himmel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Markus Himmel\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.ring_theory.ideal.operations\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\n\n/-!\n# Ideals in product rings\n\nFor commutative rings `R` and `S` and ideals `I \u2264 R`, `J \u2264 S`, we define `ideal.prod I J` as the\nproduct `I \u00d7 J`, viewed as an ideal of `R \u00d7 S`. In `ideal_prod_eq` we show that every ideal of\n`R \u00d7 S` is of this form.  Furthermore, we show that every prime ideal of `R \u00d7 S` is of the form\n`p \u00d7 S` or `R \u00d7 p`, where `p` is a prime ideal.\n-/\n\nnamespace ideal\n\n\n/-- `I \u00d7 J` as an ideal of `R \u00d7 S`. -/\ndef prod {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal R) (J : ideal S) : ideal (R \u00d7 S) :=\n  submodule.mk (set_of fun (x : R \u00d7 S) => prod.fst x \u2208 I \u2227 prod.snd x \u2208 J) sorry sorry sorry\n\n@[simp] theorem mem_prod {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal R) (J : ideal S) {r : R} {s : S} : (r, s) \u2208 prod I J \u2194 r \u2208 I \u2227 s \u2208 J :=\n  iff.rfl\n\n@[simp] theorem prod_top_top {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] : prod \u22a4 \u22a4 = \u22a4 := sorry\n\n/-- Every ideal of the product ring is of the form `I \u00d7 J`, where `I` and `J` can be explicitly\n    given as the image under the projection maps. -/\ntheorem ideal_prod_eq {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal (R \u00d7 S)) : I = prod (map (ring_hom.fst R S) I) (map (ring_hom.snd R S) I) := sorry\n\n@[simp] theorem map_fst_prod {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal R) (J : ideal S) : map (ring_hom.fst R S) (prod I J) = I := sorry\n\n@[simp] theorem map_snd_prod {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal R) (J : ideal S) : map (ring_hom.snd R S) (prod I J) = J := sorry\n\n@[simp] theorem map_prod_comm_prod {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal R) (J : ideal S) : map (\u2191ring_equiv.prod_comm) (prod I J) = prod J I := sorry\n\n/-- Ideals of `R \u00d7 S` are in one-to-one correspondence with pairs of ideals of `R` and ideals of\n    `S`. -/\ndef ideal_prod_equiv {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] : ideal (R \u00d7 S) \u2243 ideal R \u00d7 ideal S :=\n  equiv.mk (fun (I : ideal (R \u00d7 S)) => (map (ring_hom.fst R S) I, map (ring_hom.snd R S) I))\n    (fun (I : ideal R \u00d7 ideal S) => prod (prod.fst I) (prod.snd I)) sorry sorry\n\n@[simp] theorem ideal_prod_equiv_symm_apply {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal R) (J : ideal S) : coe_fn (equiv.symm ideal_prod_equiv) (I, J) = prod I J :=\n  rfl\n\ntheorem prod.ext_iff {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {I : ideal R} {I' : ideal R} {J : ideal S} {J' : ideal S} : prod I J = prod I' J' \u2194 I = I' \u2227 J = J' := sorry\n\ntheorem is_prime_of_is_prime_prod_top {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {I : ideal R} (h : is_prime (prod I \u22a4)) : is_prime I := sorry\n\ntheorem is_prime_of_is_prime_prod_top' {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {I : ideal S} (h : is_prime (prod \u22a4 I)) : is_prime I :=\n  is_prime_of_is_prime_prod_top\n    (eq.mpr (id (Eq._oldrec (Eq.refl (is_prime (prod I \u22a4))) (Eq.symm (map_prod_comm_prod \u22a4 I))))\n      (map_is_prime_of_equiv ring_equiv.prod_comm))\n\ntheorem is_prime_ideal_prod_top {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {I : ideal R} [h : is_prime I] : is_prime (prod I \u22a4) := sorry\n\ntheorem is_prime_ideal_prod_top' {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {I : ideal S} [h : is_prime I] : is_prime (prod \u22a4 I) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (is_prime (prod \u22a4 I))) (Eq.symm (map_prod_comm_prod I \u22a4))))\n    (map_is_prime_of_equiv ring_equiv.prod_comm)\n\ntheorem ideal_prod_prime_aux {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {I : ideal R} {J : ideal S} : is_prime (prod I J) \u2192 I = \u22a4 \u2228 J = \u22a4 := sorry\n\n/-- Classification of prime ideals in product rings: the prime ideals of `R \u00d7 S` are precisely the\n    ideals of the form `p \u00d7 S` or `R \u00d7 p`, where `p` is a prime ideal of `R` or `S`. -/\ntheorem ideal_prod_prime {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal (R \u00d7 S)) : is_prime I \u2194 (\u2203 (p : ideal R), is_prime p \u2227 I = prod p \u22a4) \u2228 \u2203 (p : ideal S), is_prime p \u2227 I = prod \u22a4 p := sorry\n\n/-- The prime ideals of `R \u00d7 S` are in bijection with the disjoint union of the prime ideals\n    of `R` and the prime ideals of `S`. -/\ndef prime_ideals_equiv (R : Type u) (S : Type v) [comm_ring R] [comm_ring S] : (Subtype fun (K : ideal (R \u00d7 S)) => is_prime K) \u2243\n  (Subtype fun (I : ideal R) => is_prime I) \u2295 Subtype fun (J : ideal S) => is_prime J :=\n  equiv.symm (equiv.of_bijective prime_ideals_equiv_impl sorry)\n\n@[simp] theorem prime_ideals_equiv_symm_inl {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (I : ideal R) (h : is_prime I) : coe_fn (equiv.symm (prime_ideals_equiv R S)) (sum.inl { val := I, property := h }) =\n  { val := prod I \u22a4, property := is_prime_ideal_prod_top } :=\n  rfl\n\n@[simp] theorem prime_ideals_equiv_symm_inr {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (J : ideal S) (h : is_prime J) : coe_fn (equiv.symm (prime_ideals_equiv R S)) (sum.inr { val := J, property := h }) =\n  { val := prod \u22a4 J, property := is_prime_ideal_prod_top' } :=\n  rfl\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/ring_theory/ideal/prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7254203956683852}}
{"text": "import for_mathlib.decimal_expansions\n\nopen decimal\n\nnoncomputable definition s : \u211d := (71/100 : \u211d)\n\ntheorem sQ : s = ((71/100:\u211a):\u211d) := by unfold s;norm_num \n\ntheorem floor_s : floor s = 0 := \nby rw [\u2190 floor_of_bounds, s, int.cast_zero]; norm_num\n\ntheorem floor_10s : floor (71/10 : \u211d) = 7 :=\nbegin \nrw [\u2190 floor_of_bounds],\nsplit; norm_num\nend \n\nlemma expansion_auxing_s : expansion_aux s 2 = 0 :=\nbegin\nunfold expansion_aux,\nrw floor_s,\nunfold s,\nnorm_num,\nrw floor_10s,\nnorm_num,\nend \n\n\ntheorem expansion_auxed (n : \u2115) : expansion_aux s (n + 2) = 0 :=\nbegin\ninduction n with d Hd,exact expansion_auxing_s,\nrw expansion_aux.equations._eqn_2,\nrw Hd,\nsimp,\nend\n\n-- recall s = 71/100 \ntheorem no_eights_in_0_point_71 (n : \u2115) : decimal.expansion_nonneg s n \u2260 8 :=\nbegin\ncases n,unfold expansion_nonneg,rw floor_s,show 0 \u2260 8,by cc,\ncases n,unfold expansion_nonneg expansion_aux,rw floor_s,unfold s,\n  rw int.cast_zero,\n  have this : ((71 / 100 : \u211d) - 0) * 10 = 71 / 10 := by norm_num,\n  rw this,rw floor_10s,show 7 \u2260 8,by cc,\ncases n,unfold expansion_nonneg expansion_aux,rw floor_s,unfold s,\n  rw int.cast_zero,\n  norm_num,\n  rw floor_10s,\n  norm_num,\n  show 1 \u2260 8,\n  by cc,\nunfold expansion_nonneg,\nrw [expansion_auxed,floor_zero],\nshow 0 \u2260 8,\nby cc,\nend \n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1F-exam-may-2018", "sha": "8b5eca2037d4a14d6cfac3da1858b6c4119216d3", "save_path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018", "path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018/M1F-exam-may-2018-8b5eca2037d4a14d6cfac3da1858b6c4119216d3/src/zero_point_seven_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.725418809746684}}
{"text": "/-\nCopyright (c) 2022 Jo\u00ebl Riou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jo\u00ebl Riou\n\n! This file was ported from Lean 3 source module category_theory.localization.construction\n! leanprover-community/mathlib commit 1a5e56f2166e4e9d0964c71f4273b1d39227678d\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.MorphismProperty\nimport Mathlib.CategoryTheory.Category.QuivCat\n\n/-!\n\n# Construction of the localized category\n\nThis file constructs the localized category, obtained by formally inverting\na class of maps `W : MorphismProperty C` in a category `C`.\n\nWe first construct a quiver `LocQuiver W` whose objects are the same as those\nof `C` and whose maps are the maps in `C` and placeholders for the formal\ninverses of the maps in `W`.\n\nThe localized category `W.Localization` is obtained by taking the quotient\nof the path category of `LocQuiver W` by the congruence generated by four\ntypes of relations.\n\nThe obvious functor `Q W : C \u2964 W.Localization` satisfies the universal property\nof the localization. Indeed, if `G : C \u2964 D` sends morphisms in `W` to isomorphisms\nin `D` (i.e. we have `hG : W.IsInvertedBy G`), then there exists a unique functor\n`G' : W.Localization \u2964 D` such that `Q W \u226b G' = G`. This `G'` is `lift G hG`.\nThe expected property of `lift G hG` if expressed by the lemma `fac` and the\nuniqueness is expressed by `uniq`.\n\n## References\n\n* [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967]\n\n-/\n\n\nnoncomputable section\n\nopen CategoryTheory.Category\n\nnamespace CategoryTheory\n\nvariable {C : Type _} [Category C] (W : MorphismProperty C) {D : Type _} [Category D]\n\nnamespace Localization\n\nnamespace Construction\n\n-- porting note: removed @[nolint has_nonempty_instance]\n/-- If `W : MorphismProperty C`, `LocQuiver W` is a quiver with the same objects\nas `C`, and whose morphisms are those in `C` and placeholders for formal\ninverses of the morphisms in `W`. -/\nstructure LocQuiver (W : MorphismProperty C) where\n  /-- underlying object -/\n  obj : C\n#align category_theory.localization.construction.loc_quiver CategoryTheory.Localization.Construction.LocQuiver\n\ninstance : Quiver (LocQuiver W) where Hom A B := Sum (A.obj \u27f6 B.obj) { f : B.obj \u27f6 A.obj // W f }\n\n/-- The object in the path category of `LocQuiver W` attached to an object in\nthe category `C` -/\ndef \u03b9Paths (X : C) : Paths (LocQuiver W) :=\n  \u27e8X\u27e9\n#align category_theory.localization.construction.\u03b9_paths CategoryTheory.Localization.Construction.\u03b9Paths\n\n/-- The morphism in the path category associated to a morphism in the original category. -/\n@[simp]\ndef \u03c8\u2081 {X Y : C} (f : X \u27f6 Y) : \u03b9Paths W X \u27f6 \u03b9Paths W Y :=\n  Paths.of.map (Sum.inl f)\n#align category_theory.localization.construction.\u03c8\u2081 CategoryTheory.Localization.Construction.\u03c8\u2081\n\n/-- The morphism in the path category corresponding to a formal inverse. -/\n@[simp]\ndef \u03c8\u2082 {X Y : C} (w : X \u27f6 Y) (hw : W w) : \u03b9Paths W Y \u27f6 \u03b9Paths W X :=\n  Paths.of.map (Sum.inr \u27e8w, hw\u27e9)\n#align category_theory.localization.construction.\u03c8\u2082 CategoryTheory.Localization.Construction.\u03c8\u2082\n\n/-- The relations by which we take the quotient in order to get the localized category. -/\ninductive relations : HomRel (Paths (LocQuiver W))\n  | id (X : C) : relations (\u03c8\u2081 W (\ud835\udfd9 X)) (\ud835\udfd9 _)\n  | comp {X Y Z : C} (f : X \u27f6 Y) (g : Y \u27f6 Z) : relations (\u03c8\u2081 W (f \u226b g)) (\u03c8\u2081 W f \u226b \u03c8\u2081 W g)\n  | Winv\u2081 {X Y : C} (w : X \u27f6 Y) (hw : W w) : relations (\u03c8\u2081 W w \u226b \u03c8\u2082 W w hw) (\ud835\udfd9 _)\n  | Winv\u2082 {X Y : C} (w : X \u27f6 Y) (hw : W w) : relations (\u03c8\u2082 W w hw \u226b \u03c8\u2081 W w) (\ud835\udfd9 _)\n#align category_theory.localization.construction.relations CategoryTheory.Localization.Construction.relations\n\nend Construction\n\nend Localization\n\nnamespace MorphismProperty\n\nopen Localization.Construction\n\n-- porting note: removed @[nolint has_nonempty_instance]\n/-- The localized category obtained by formally inverting the morphisms\nin `W : MorphismProperty C` -/\ndef Localization :=\n  CategoryTheory.Quotient (Localization.Construction.relations W)\n#align category_theory.morphism_property.localization CategoryTheory.MorphismProperty.Localization\n\ninstance : Category (Localization W) := by\n  dsimp only [Localization]\n  infer_instance\n\n/-- The obvious functor `C \u2964 W.Localization` -/\ndef Q : C \u2964 W.Localization\n    where\n  obj X := (Quotient.functor _).obj (Paths.of.obj \u27e8X\u27e9)\n  map f := (Quotient.functor _).map (\u03c8\u2081 W f)\n  map_id X := Quotient.sound _ (relations.id X)\n  map_comp f g := Quotient.sound _ (relations.comp f g)\nset_option linter.uppercaseLean3 false in\n#align category_theory.morphism_property.Q CategoryTheory.MorphismProperty.Q\n\nend MorphismProperty\n\nnamespace Localization\n\nnamespace Construction\n\nvariable {W}\n/-- The isomorphism in `W.Localization` associated to a morphism `w` in W -/\ndef wIso {X Y : C} (w : X \u27f6 Y) (hw : W w) : Iso (W.Q.obj X) (W.Q.obj Y)\n    where\n  hom := W.Q.map w\n  inv := (Quotient.functor _).map (by dsimp; exact Paths.of.map (Sum.inr \u27e8w, hw\u27e9))\n  hom_inv_id := Quotient.sound _ (relations.Winv\u2081 w hw)\n  inv_hom_id := Quotient.sound _ (relations.Winv\u2082 w hw)\nset_option linter.uppercaseLean3 false in\n#align category_theory.localization.construction.Wiso CategoryTheory.Localization.Construction.wIso\n\n/-- The formal inverse in `W.Localization` of a morphism `w` in `W`. -/\nabbrev winv {X Y : C} (w : X \u27f6 Y) (hw : W w) :=\n  (wIso w hw).inv\nset_option linter.uppercaseLean3 false in\n#align category_theory.localization.construction.Winv CategoryTheory.Localization.Construction.winv\n\nvariable (W)\n\ntheorem _root_.CategoryTheory.MorphismProperty.Q_inverts : W.IsInvertedBy W.Q := fun _ _ w hw =>\n  IsIso.of_iso (Localization.Construction.wIso w hw)\nset_option linter.uppercaseLean3 false in\n#align category_theory.morphism_property.Q_inverts CategoryTheory.MorphismProperty.Q_inverts\n\nvariable {W} (G : C \u2964 D) (hG : W.IsInvertedBy G)\n\n/-- The lifting of a functor to the path category of `LocQuiver W` -/\n@[simps!]\ndef liftToPathCategory : Paths (LocQuiver W) \u2964 D :=\n  QuivCat.lift\n    { obj := fun X => G.obj X.obj\n      map := by\n        intros X Y\n        rintro (f | \u27e8g, hg\u27e9)\n        . exact G.map f\n        . haveI := hG g hg\n          exact inv (G.map g) }\n#align category_theory.localization.construction.lift_to_path_category CategoryTheory.Localization.Construction.liftToPathCategory\n\n/-- The lifting of a functor `C \u2964 D` inverting `W` as a functor `W.Localization \u2964 D` -/\n@[simps!]\ndef lift : W.Localization \u2964 D :=\n  Quotient.lift (relations W) (liftToPathCategory G hG)\n    (by\n      rintro \u27e8X\u27e9 \u27e8Y\u27e9 f\u2081 f\u2082 r\n      --Porting note: rest of proof was `rcases r with \u27e8\u27e9; tidy`\n      rcases r with (_|_|\u27e8f,hf\u27e9|\u27e8f,hf\u27e9)\n      . aesop_cat\n      . aesop_cat\n      all_goals\n        dsimp\n        haveI := hG f hf\n        simp\n        rfl)\n#align category_theory.localization.construction.lift CategoryTheory.Localization.Construction.lift\n\n@[simp]\ntheorem fac : W.Q \u22d9 lift G hG = G :=\n  Functor.ext (fun X => rfl)\n    (by\n      intro X Y f\n      simp only [Functor.comp_map, eqToHom_refl, comp_id, id_comp]\n      dsimp [MorphismProperty.Q, Quot.liftOn]\n      rw [composePath_toPath])\n#align category_theory.localization.construction.fac CategoryTheory.Localization.Construction.fac\n\ntheorem uniq (G\u2081 G\u2082 : W.Localization \u2964 D) (h : W.Q \u22d9 G\u2081 = W.Q \u22d9 G\u2082) : G\u2081 = G\u2082 := by\n  suffices h' : Quotient.functor _ \u22d9 G\u2081 = Quotient.functor _ \u22d9 G\u2082\n  \u00b7 refine' Functor.ext _ _\n    \u00b7 rintro \u27e8\u27e8X\u27e9\u27e9\n      apply Functor.congr_obj h\n    \u00b7 rintro \u27e8\u27e8X\u27e9\u27e9 \u27e8\u27e8Y\u27e9\u27e9 \u27e8f\u27e9\n      apply Functor.congr_hom h'\n  \u00b7 refine' Paths.ext_functor _ _\n    \u00b7 ext X\n      cases X\n      apply Functor.congr_obj h\n    \u00b7 rintro \u27e8X\u27e9 \u27e8Y\u27e9 (f | \u27e8w, hw\u27e9)\n      \u00b7 simpa only using Functor.congr_hom h f\n      \u00b7 have hw : W.Q.map w = (wIso w hw).hom := rfl\n        have hw' := Functor.congr_hom h w\n        simp only [Functor.comp_map, hw] at hw'\n        refine' Functor.congr_inv_of_congr_hom _ _ _ _ _ hw'\n        all_goals apply Functor.congr_obj h\n#align category_theory.localization.construction.uniq CategoryTheory.Localization.Construction.uniq\n\nvariable (W)\n\n/-- The canonical bijection between objects in a category and its\nlocalization with respect to a morphism_property `W` -/\n@[simps]\ndef objEquiv : C \u2243 W.Localization where\n  toFun := W.Q.obj\n  invFun X := X.as.obj\n  left_inv X := rfl\n  right_inv := by\n    rintro \u27e8\u27e8X\u27e9\u27e9\n    rfl\n#align category_theory.localization.construction.obj_equiv CategoryTheory.Localization.Construction.objEquiv\n\nvariable {W}\n\n/-- A `MorphismProperty` in `W.Localization` is satisfied by all\nmorphisms in the localized category if it contains the image of the\nmorphisms in the original category, the inverses of the morphisms\nin `W` and if it is stable under composition -/\ntheorem morphismProperty_is_top (P : MorphismProperty W.Localization)\n    (hP\u2081 : \u2200 \u2983X Y : C\u2984 (f : X \u27f6 Y), P (W.Q.map f))\n    (hP\u2082 : \u2200 \u2983X Y : C\u2984 (w : X \u27f6 Y) (hw : W w), P (winv w hw)) (hP\u2083 : P.StableUnderComposition) :\n    P = \u22a4 := by\n  funext X Y f\n  ext\n  constructor\n  . intro\n    apply MorphismProperty.top_apply\n  \u00b7 intro\n    let G : _ \u2964 W.Localization := Quotient.functor _\n    haveI : Full G := Quotient.fullFunctor _\n    suffices\n      \u2200 (X\u2081 X\u2082 : Paths (LocQuiver W)) (f : X\u2081 \u27f6 X\u2082), P (G.map f)\n      by\n      rcases X with \u27e8\u27e8X\u27e9\u27e9\n      rcases Y with \u27e8\u27e8Y\u27e9\u27e9\n      simpa only [Functor.image_preimage] using this _ _ (G.preimage f)\n    intros X\u2081 X\u2082 p\n    induction' p with X\u2082 X\u2083 p g hp\n    \u00b7 simpa only [Functor.map_id] using hP\u2081 (\ud835\udfd9 X\u2081.obj)\n    . let p' : X\u2081 \u27f6X\u2082 := p\n      rw [show p'.cons g = p' \u226b Quiver.Hom.toPath g by rfl, G.map_comp]\n      refine' hP\u2083 _ _ hp _\n      rcases g with (g | \u27e8g, hg\u27e9)\n      . apply hP\u2081\n      . apply hP\u2082\n#align category_theory.localization.construction.morphism_property_is_top CategoryTheory.Localization.Construction.morphismProperty_is_top\n\n/-- A `MorphismProperty` in `W.Localization` is satisfied by all\nmorphisms in the localized category if it contains the image of the\nmorphisms in the original category, if is stable under composition\nand if the property is stable by passing to inverses. -/\ntheorem morphismProperty_is_top' (P : MorphismProperty W.Localization)\n    (hP\u2081 : \u2200 \u2983X Y : C\u2984 (f : X \u27f6 Y), P (W.Q.map f))\n    (hP\u2082 : \u2200 \u2983X Y : W.Localization\u2984 (e : X \u2245 Y) (_ : P e.hom), P e.inv)\n    (hP\u2083 : P.StableUnderComposition) : P = \u22a4 :=\n  morphismProperty_is_top P hP\u2081 (fun _ _ w _ => hP\u2082 _ (hP\u2081 w)) hP\u2083\n#align category_theory.localization.construction.morphism_property_is_top' CategoryTheory.Localization.Construction.morphismProperty_is_top'\n\nnamespace NatTransExtension\n\nvariable {F\u2081 F\u2082 : W.Localization \u2964 D} (\u03c4 : W.Q \u22d9 F\u2081 \u27f6 W.Q \u22d9 F\u2082)\n\n/-- If `F\u2081` and `F\u2082` are functors `W.Localization \u2964 D` and if we have\n`\u03c4 : W.Q \u22d9 F\u2081 \u27f6 W.Q \u22d9 F\u2082`, we shall define a natural transformation `F\u2081 \u27f6 F\u2082`.\nThis is the `app` field of this natural transformation. -/\ndef app (X : W.Localization) : F\u2081.obj X \u27f6 F\u2082.obj X :=\n  eqToHom (congr_arg F\u2081.obj ((objEquiv W).right_inv X).symm) \u226b\n    \u03c4.app ((objEquiv W).invFun X) \u226b eqToHom (congr_arg F\u2082.obj ((objEquiv W).right_inv X))\n#align category_theory.localization.construction.nat_trans_extension.app CategoryTheory.Localization.Construction.NatTransExtension.app\n\n@[simp]\n\n\nend NatTransExtension\n\n/-- If `F\u2081` and `F\u2082` are functors `W.Localization \u2964 D`, a natural transformation `F\u2081 \u27f6 F\u2082`\ncan be obtained from a natural transformation `W.Q \u22d9 F\u2081 \u27f6 W.Q \u22d9 F\u2082`. -/\n@[simps]\ndef natTransExtension {F\u2081 F\u2082 : W.Localization \u2964 D} (\u03c4 : W.Q \u22d9 F\u2081 \u27f6 W.Q \u22d9 F\u2082) : F\u2081 \u27f6 F\u2082\n    where\n  app := NatTransExtension.app \u03c4\n  naturality := by\n    suffices MorphismProperty.naturalityProperty (NatTransExtension.app \u03c4) = \u22a4\n      by\n      intro X Y f\n      simpa only [\u2190 this] using MorphismProperty.top_apply f\n    refine' morphismProperty_is_top'\n      (MorphismProperty.naturalityProperty (NatTransExtension.app \u03c4))\n      _ (MorphismProperty.naturalityProperty.stableUnderInverse _)\n      (MorphismProperty.naturalityProperty.stableUnderComposition _)\n    intros X Y f\n    dsimp\n    simpa only [NatTransExtension.app_eq] using \u03c4.naturality f\n#align category_theory.localization.construction.nat_trans_extension CategoryTheory.Localization.Construction.natTransExtension\n\n@[simp]\ntheorem natTransExtension_hcomp {F G : W.Localization \u2964 D} (\u03c4 : W.Q \u22d9 F \u27f6 W.Q \u22d9 G) :\n    \ud835\udfd9 W.Q \u25eb natTransExtension \u03c4 = \u03c4 := by aesop_cat\n#align category_theory.localization.construction.nat_trans_extension_hcomp CategoryTheory.Localization.Construction.natTransExtension_hcomp\n\ntheorem natTrans_hcomp_injective {F G : W.Localization \u2964 D} {\u03c4\u2081 \u03c4\u2082 : F \u27f6 G}\n    (h : \ud835\udfd9 W.Q \u25eb \u03c4\u2081 = \ud835\udfd9 W.Q \u25eb \u03c4\u2082) : \u03c4\u2081 = \u03c4\u2082 := by\n  ext X\n  have eq := (objEquiv W).right_inv X\n  simp only [objEquiv] at eq\n  rw [\u2190 eq, \u2190 NatTrans.id_hcomp_app, \u2190 NatTrans.id_hcomp_app, h]\n#align category_theory.localization.construction.nat_trans_hcomp_injective CategoryTheory.Localization.Construction.natTrans_hcomp_injective\n\nvariable (W D)\n\nnamespace WhiskeringLeftEquivalence\n\n/-- The functor `(W.Localization \u2964 D) \u2964 (W.FunctorsInverting D)` induced by the\ncomposition with `W.Q : C \u2964 W.Localization`. -/\n@[simps!]\ndef functor : (W.Localization \u2964 D) \u2964 W.FunctorsInverting D :=\n  FullSubcategory.lift _ ((whiskeringLeft _ _ D).obj W.Q) fun _ =>\n    MorphismProperty.IsInvertedBy.of_comp W W.Q W.Q_inverts _\n#align category_theory.localization.construction.whiskering_left_equivalence.functor CategoryTheory.Localization.Construction.WhiskeringLeftEquivalence.functor\n\n/-- The function `(W.FunctorsInverting D) \u2964 (W.Localization \u2964 D)` induced by\n`Construction.lift`. -/\n@[simps!]\ndef inverse : W.FunctorsInverting D \u2964 W.Localization \u2964 D\n    where\n  obj G := lift G.obj G.property\n  map \u03c4 := natTransExtension (eqToHom (by rw [fac]) \u226b \u03c4 \u226b eqToHom (by rw [fac]))\n  map_id G :=\n    natTrans_hcomp_injective\n      (by\n        rw [natTransExtension_hcomp]\n        ext X\n        simp only [NatTrans.comp_app, eqToHom_app, eqToHom_refl, comp_id, id_comp,\n          NatTrans.hcomp_id_app, NatTrans.id_app, Functor.map_id]\n        rfl )\n  map_comp \u03c4\u2081 \u03c4\u2082 :=\n    natTrans_hcomp_injective\n      (by\n        ext X\n        simp only [natTransExtension_hcomp, NatTrans.comp_app, eqToHom_app, eqToHom_refl,\n          id_comp, comp_id, NatTrans.hcomp_app, NatTrans.id_app, Functor.map_id,\n          natTransExtension_app, NatTransExtension.app_eq]\n        rfl)\n#align category_theory.localization.construction.whiskering_left_equivalence.inverse CategoryTheory.Localization.Construction.WhiskeringLeftEquivalence.inverse\n\n/-- The unit isomorphism of the equivalence of categories `whiskeringLeftEquivalence W D`. -/\n@[simps!]\ndef unitIso : \ud835\udfed (W.Localization \u2964 D) \u2245 functor W D \u22d9 inverse W D :=\n  eqToIso\n    (by\n      refine' Functor.ext (fun G => _) fun G\u2081 G\u2082 \u03c4 => _\n      \u00b7 apply uniq\n        dsimp [Functor]\n        erw [fac]\n        rfl\n      \u00b7 apply natTrans_hcomp_injective\n        ext X\n        simp)\n#align category_theory.localization.construction.whiskering_left_equivalence.unit_iso CategoryTheory.Localization.Construction.WhiskeringLeftEquivalence.unitIso\n\n/-- The counit isomorphism of the equivalence of categories `WhiskeringLeftEquivalence W D`. -/\n@[simps!]\ndef counitIso : inverse W D \u22d9 functor W D \u2245 \ud835\udfed (W.FunctorsInverting D) :=\n  eqToIso\n    (by\n      refine' Functor.ext _ _\n      \u00b7 rintro \u27e8G, hG\u27e9\n        ext\n        exact fac G hG\n      \u00b7 rintro \u27e8G\u2081, hG\u2081\u27e9 \u27e8G\u2082, hG\u2082\u27e9 f\n        apply NatTrans.ext\n        ext1\n        apply NatTransExtension.app_eq)\n#align category_theory.localization.construction.whiskering_left_equivalence.counit_iso CategoryTheory.Localization.Construction.WhiskeringLeftEquivalence.counitIso\n\nend WhiskeringLeftEquivalence\n\n/-- The equivalence of categories `(W.localization \u2964 D) \u224c (W.FunctorsInverting D)`\ninduced by the composition with `W.Q : C \u2964 W.localization`. -/\ndef whiskeringLeftEquivalence : W.Localization \u2964 D \u224c W.FunctorsInverting D\n    where\n  functor := WhiskeringLeftEquivalence.functor W D\n  inverse := WhiskeringLeftEquivalence.inverse W D\n  unitIso := WhiskeringLeftEquivalence.unitIso W D\n  counitIso := WhiskeringLeftEquivalence.counitIso W D\n  functor_unitIso_comp F := by\n    apply NatTrans.ext\n    ext1\n    simp only [WhiskeringLeftEquivalence.unitIso_hom, eqToHom_app, eqToHom_refl,\n      WhiskeringLeftEquivalence.counitIso_hom, eqToHom_map, eqToHom_trans]\n    rfl\n#align category_theory.localization.construction.whiskering_left_equivalence CategoryTheory.Localization.Construction.whiskeringLeftEquivalence\n\nend Construction\n\nend Localization\n\nend CategoryTheory\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Localization/Construction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7254188034053899}}
{"text": "import analysis.real xenalib.M1Fstuff tactic.norm_num\n\n-- real numbers live in here in Lean mathlib\n-- NB you need mathlib installed to get this working.\n-- of_rat is the injection from the rationals to the reals.\n\n-- This question was absurdly difficult for me\n-- because we need to prove that 1/2 isn't an integer ;-)\n-- I did it in the end, and called it real_half_not_an_integer\n-- I put it in the M1Fstuff library.\n\n-- #check M1F.real_half_not_an_integer\n\nlocal infix ` ^ ` := monoid.pow \n\ndef A : set \u211d := { x | x^2 < 3}\ndef B : set \u211d := {x | (\u2203 y : \u2124, x = \u2191y) \u2227 x^2 < 3}\ndef C : set \u211d := {x | x^3 < 3}\n\n-- set_option pp.notation false\n\ntheorem part_a : \u00ac (((1/2):\u211d) \u2208 A \u2229 B) :=\nbegin\nassume H : ((1/2):\u211d) \u2208 A \u2229 B,\nhave H2: ((1/2):\u211d) \u2208 B,\nexact and.right H,\nhave H3: \u2203 y : \u2124, ((1/2):\u211d) = \u2191y,\nexact and.left H2,\nexact M1F.real_half_not_an_integer H3,\nend\n\n\n-- set_option pp.all true\n-- #check @of_rat_mul\n\n--set_option pp.notation false\ntheorem part_b : of_rat (1/2) \u2208 A \u222a B := \nbegin\nleft,\n-- this now says \n-- of_rat (1 / 2) ^ 2 < (3:real)\n-- (after a huge amount of unfolding)\nunfold has_mem.mem set.mem A set_of,\nhave J : (3:real) = of_rat(3),\nrw [\u2190coe_rat_eq_of_rat 3],\nsimp,\nrewrite J,clear J,\nunfold monoid.pow,\nhave J : (1:real) = of_rat(1),\n  apply of_rat_one,\nrewrite J,clear J,\nrewrite (@of_rat_mul (1/2) 1),\nrewrite (of_rat_mul),\nrewrite [\u2190coe_rat_eq_of_rat,\u2190coe_rat_eq_of_rat],\nrewrite rat.cast_lt,\nexact dec_trivial\nend\n\nset_option pp.notation true\n-- set_option pp.all true\ntheorem part_c : \u00ac (A \u2286 C) := \nbegin\nassume H : A \u2286 C,\nlet x := of_rat (3/2), --  strat is to prove x is in A but not C\nhave H2 : x \u2208 A,\nunfold A,\nunfold has_mem.mem set.mem set_of has_lt.lt preorder.lt,change x with of_rat (3/2),\nunfold partial_order.lt ordered_comm_monoid.lt discrete_linear_ordered_field.lt has_lt.lt,\nunfold preorder.lt partial_order.lt lattice.semilattice_inf.lt lattice.lattice.lt,\nunfold lattice.distrib_lattice.lt lattice.lattice.lt,\nunfold decidable_linear_order.lt decidable_linear_ordered_comm_group.lt,\nunfold monoid.pow,\nhave J : (3:real) = of_rat(3),\nrw [\u2190coe_rat_eq_of_rat 3],\nsimp,\nrewrite J,clear J,\nhave J : (1:real) = of_rat(1),\n  apply of_rat_one,\nrewrite J,clear J,\nrewrite (of_rat_mul),\nrewrite (of_rat_mul),\nrewrite [\u2190coe_rat_eq_of_rat,\u2190coe_rat_eq_of_rat],\nrewrite rat.cast_lt,\nsimp,\nexact dec_trivial,\nhave H3 : \u00ac (x \u2208 C),\nunfold C,\nunfold has_mem.mem set.mem set_of has_lt.lt preorder.lt,change x with of_rat (3/2),\nunfold partial_order.lt ordered_comm_monoid.lt discrete_linear_ordered_field.lt has_lt.lt,\nunfold preorder.lt partial_order.lt lattice.semilattice_inf.lt lattice.lattice.lt,\nunfold lattice.distrib_lattice.lt,\nunfold lattice.lattice.lt,\nunfold decidable_linear_order.lt decidable_linear_ordered_comm_group.lt,\nunfold monoid.pow,\nhave J : (3:real) = of_rat(3),\nrw [\u2190coe_rat_eq_of_rat 3],\nsimp,\nrewrite J,clear J,\nhave J : (1:real) = of_rat(1),\n  apply of_rat_one,\nrewrite J,clear J,\nrewrite (of_rat_mul),\nrewrite (of_rat_mul),\nrewrite (of_rat_mul),\nsimp,\n-- apply of_rat_le_of_rat.mpr,\n-- exact dec_trivial,\n\n-- now have 3/2 in A not C\n-- trivial,\nhave J : x \u2208 C,\nexact H H2,\n-- contradiction \nexact H3 J,\n-- simp with real_simps,\n-- unfold pow_nat,\n-- apply of_rat_lt_of_rat.mpr,\n-- simp [M1F.of_rat_inj] with real_simps,\nend\n\n-- To do part (d) it's helpful to evaluate B completely.\n-- def B : set \u211d := {x | (\u2203 y : \u2124, x = of_rat y) \u2227 x^2 < 3}\n\n-- #check @eq.subst\n-- #check rat.coe_int_mul\n-- #check rat.coe_int_lt\n--  set_option pp.notation false\n\n\nlemma B_is_minus_one_zero_one (x:\u211d): x \u2208 B \u2192 (x=((-1):\u211d)) \u2228 (x=(0:\u211d)) \u2228 (x=(1:\u211d)) :=\nbegin\nassume H : x \u2208 B,\nhave H2 : exists y : \u2124, x = (y:\u211d),\n  exact H.left,\nhave H3 : x^2 < 3,\n  exact H.right,\ncases H2 with y H4,\nunfold monoid.pow at H3,\nsimp at H3,\nhave H5 : ((y:\u211a):\u211d) * ((y:\u211a):\u211d) < 3,\n  exact (@eq.subst \u211d (\u03bb z, z*z<(3:real)) x (y:\u211a) (by simp [H4]) H3),\nrw [\u2190rat.cast_mul] at H5,\nhave J : (3:real) = (((3:\u2124):\u211a):\u211d),\n  simp,\nrw [J,rat.cast_lt,\u2190int.cast_mul,int.cast_lt] at H5,\n/-\n  rw \u2190coe_rat_eq_of_rat 3,exact \nhave H6 : of_rat (\u2191 y * \u2191 y) < of_rat 3,\n  exact eq.subst J H5,\nrewrite of_rat_lt_of_rat at H6,\nclear H3 H5 J,\nrewrite eq.symm (rat.coe_int_mul y y) at H6,\nchange (3:rat) with \u2191(3:int) at H6,\nrewrite rat.coe_int_lt at H6,\n\n-- Situation now:\n-- y is an integer, H6 is y*y<3\n-- H4 is x=of_rat(y)=y:real,\n-- and we want to prove x=-1 or 0 or 1.\n\n-/\nhave H6 : y*y<3,\n  exact H5,\n  clear H5,\n\ncases y with y m1my,\n  rewrite eq.symm (int.of_nat_mul y y) at H6,\n  have H1:y*y < 3,\n    exact @int.lt_of_coe_nat_lt_coe_nat (y*y) 3 H6,\n  cases y with ys,\n    right,left,\n    exact H4,\n  cases ys with yss,\n    right,right,simp [H4],\n  have H : 4<3,\n  exact calc\n  4 = 2*2 : dec_trivial\n  ...  \u2264  2*(yss+2) : nat.mul_le_mul_left 2 (nat.le_add_left 2 yss)\n  ... \u2264 (yss+2)*(yss+2) : nat.mul_le_mul_right (yss+2) (nat.le_add_left 2 yss)\n  ... < 3 : H1,\n  have H2 : \u00ac (4<3),\n  exact dec_trivial,\n  exfalso,\n  contradiction,\n  cases m1my with y2,\n    left,simp [H4],\n  exfalso,\n  have H1 : int.nat_abs (int.neg_succ_of_nat (nat.succ y2)) = y2+2,\n  refl,\n  have H2:\u2191((y2+2)*(y2+2))=(int.neg_succ_of_nat (nat.succ y2))*(int.neg_succ_of_nat (nat.succ y2)),\n    apply @int.nat_abs_mul_self (int.neg_succ_of_nat (nat.succ y2)),\n  have H3: \u2191((y2+2)*(y2+2)) < (\u21913:int),\n  exact H2 \u25b8 H6,\n  have H5 : (y2+2)*(y2+2) < 3,\n  exact @int.lt_of_coe_nat_lt_coe_nat ((y2+2)*(y2+2)) 3 H3,\n  have H : 4<3,\n  exact calc\n  4 = 2*2 : dec_trivial\n  ...  \u2264  2*(y2+2) : nat.mul_le_mul_left 2 (nat.le_add_left 2 y2)\n  ... \u2264 (y2+2)*(y2+2) : nat.mul_le_mul_right (y2+2) (nat.le_add_left 2 y2)\n  ... < 3 : H5,\n  have H2 : \u00ac (4<3),\n  exact dec_trivial,\n  exfalso,\n  contradiction,\n--  have H3:(y2+2)*(y2+2)<3,\n--  simp [H1,H6,int.lt_of_coe_nat_lt_coe_nat,int.nat_abs_mul_self]  \nend\n\n-- set_option pp.notation false\ntheorem part_d : B \u2286 C :=  -- B={-1,0,1} so this is true\nbegin\nintro x,\nintro H,\nhave H2 : (x=-1) \u2228 (x=0) \u2228 (x=1),\nexact B_is_minus_one_zero_one x H,\nunfold has_mem.mem set.mem C set_of,\ncases H2 with xm1 xrest,\n-- need to prove of_rat(-1)^3<3\nhave H2 : ((-1):\u211d)^3 < 3,\nunfold monoid.pow,\n{norm_num},\n-- apply (@eq.subst \u211d (\u03bb x,x^3<3) x (of_rat(-1)) xm1),\nexact @eq.subst \u211d (\u03bb t, t^3<3) (-1) x (eq.symm xm1) H2,\ncases xrest with x0 x1,\nhave H2 : of_rat(0)^3 < 3,\nunfold monoid.pow,\nrw [\u2190coe_rat_eq_of_rat],\n{norm_num},\n-- apply (@eq.subst \u211d (\u03bb x,x^3<3) x (of_rat(-1)) xm1),\nexact @eq.subst \u211d (\u03bb t, t^3<3) (of_rat(0)) x (eq.symm x0) H2,\nhave H2 : of_rat(1)^3 < 3,\nunfold monoid.pow,\nrw [\u2190coe_rat_eq_of_rat],\n{norm_num},\n-- apply (@eq.subst \u211d (\u03bb x,x^3<3) x (of_rat(-1)) xm1),\nexact @eq.subst \u211d (\u03bb t, t^3<3) (of_rat(1)) x (eq.symm x1) H2,\n\n-- simp with real_simps,\n\nend\n\n-- To do parts e and f it's useful to note that -2 is in C but not A or B.\n\nlemma two_in_C : (-2:real) \u2208 C :=\nbegin\nunfold has_mem.mem set.mem C monoid.pow set_of,\n{norm_num},\nend\n\nlemma two_not_in_A : (-2:real) \u2209 A :=\nbegin\nunfold has_mem.mem set.mem A monoid.pow set_of,\nnorm_num,\nend\n\nlemma two_not_in_B : (-2:real) \u2209 B :=\nbegin\nunfold has_mem.mem set.mem B monoid.pow set_of,\nnorm_num,\nend\n\ntheorem part_e : \u00ac (C \u2286 A \u222a B) := -- not true as C contains -2\nbegin\nlet x:=(-2:real),\nhave HC : x \u2208 C,\n  exact two_in_C,\nhave HnA : x \u2209 A,\n  exact two_not_in_A,\nhave HnB : x \u2209 B,\n  exact two_not_in_B,\nintro J,\nhave J2 : x \u2208 (A \u222a B),\nexact (@J x HC),\ncases J2 with HA HB,\ncontradiction,\ncontradiction,\nend\n\ntheorem part_f : \u00ac ((A \u2229 B) \u222a C = (A \u222a B) \u2229 C) := \nbegin\nlet x:=(-2:real),\nhave HC : x \u2208 C,\n  exact two_in_C,\nhave HnA : x \u2209 A,\n  exact two_not_in_A,\nhave HnB : x \u2209 B,\n  exact two_not_in_B,\nintro H,\nhave H1 : x \u2208  (A \u2229 B \u222a C),\n  right,exact HC,\nhave H2 : x \u2208 (A \u222a B) \u2229 C,\n  exact eq.subst H H1,\nhave H3 : x \u2208 (A \u222a B),\n  exact H2.left,\ncases H3 with HA HB,\n  exact HnA HA,\n  exact HnB HB\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/2017-18/Example_Sheet_01/Question_07/M1F_sheet01_solution07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7254188008849098}}
{"text": "variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := begin\napply iff.intro, {\n  intro h,\n  constructor, {\n    intro x, exact (h x).1\n  }, {\n    intro x, exact (h x).2\n  }\n}, {\n  intro h, intro x,\n  constructor, exact (h.1 x), exact (h.2 x)\n}\nend\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := begin\nintros, exact a x (a_1 x)\nend\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := begin\nintros,\napply or.elim a, {\n  intro hp, left, exact (hp x)\n}, {\n  intro hq, right, exact (hq x)\n}\nend\n", "meta": {"author": "ntabee", "repo": "lean-exercise", "sha": "5b23b9be3d361fff5e981d5be3a0a1175504b9f6", "save_path": "github-repos/lean/ntabee-lean-exercise", "path": "github-repos/lean/ntabee-lean-exercise/lean-exercise-5b23b9be3d361fff5e981d5be3a0a1175504b9f6/5.8.1-4.6.1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7253981352502467}}
{"text": "import tactic.pure_maths -- hide\n\n/-\n# Propositional logic\n## Level 2: And introduction\n\n## And introduction\n\nTo *prove* $p\\land q$ is to prove $p$ and to prove $q$.\n\nIn Lean, if `h\u2081 : p` is a proof of `p` and `h\u2082 : q` is a proof of `q`, then `and.intro h\u2081 h\u2082`\nis a proof of `p \u2227 q`.\n-/\n\nexample (p q : Prop) (h\u2081 : p) (h\u2082 : q) : p \u2227 q :=\nbegin\n  from and.intro h\u2081 h\u2082,\nend\n\n/-\nThe `split` tactic is an alternative (backward) proof technique. If the target is to prove `p \u2227 q`,\nthen `split` replaces the goal with two new goals: (1) to prove `p` and (2) to prove `q`.\n-/\n\nexample (p q : Prop) (h\u2081 : p) (h\u2082 : q) : p \u2227 q :=\nbegin\n  split,\n  { show p, from h\u2081, }, -- The first goal.\n  { show q, from h\u2082, }, -- The second goal.\nend\n\n\nnamespace exlean -- hide\n/-\n## Tasks\n\n1. Replace `sorry` below with a Lean proof using `and.intro`.\n2. Write another Lean proof using `split`.\n3. On a piece of paper, state and give a handwritten proof of this result.\n\n**Notation**: Recall that `h\u2081` is written `h\\1`.\n-/\n\n/- Tactic : split\n\nThe `split` tactic splits a 'compound' target into multiple goals. \n\n### Examples\n\n`split` turns the target `\u22a2 p \u2227 q` into two goals: (1) `\u22a2 p` and (2)  `\u22a2 q`.\n\nEqually, if the target is `\u22a2 p \u2194 q`, split creates the goals (1) to prove\n`p \u2192 q` and (2) to prove `q \u2192 p`.\n-/\n\n\n/- Axiom: and.intro (h\u2081 : p) (h\u2082 : q) :\np \u2227 q\n-/\n\nvariables (p q r : Prop) -- hide\n\n\n/- Theorem : no-side-bar\nLet $p$, $q$, and $r$ be propositions. Assuming $h_1 : p$, $h_2 : q$, and $h_3 : r$, we have\n$h : r \\land q$.\n-/\ntheorem and_intro_thm (h\u2081 : p) (h\u2082 : q) (h\u2083 : r) : r \u2227 q :=\nbegin\n  split,\n  { show r, from h\u2083, },\n  { show q, from h\u2082, },\n\n\nend\n\nend exlean -- hide", "meta": {"author": "gihanmarasingha", "repo": "lean-game-template", "sha": "75bb3c4cd17afb31062d74eb9b2ab9b232e49719", "save_path": "github-repos/lean/gihanmarasingha-lean-game-template", "path": "github-repos/lean/gihanmarasingha-lean-game-template/lean-game-template-75bb3c4cd17afb31062d74eb9b2ab9b232e49719/src/propositional_logic/and_introduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7253981287522335}}
{"text": "/-\nGive a natural deduction proof of \ud835\udc43 from \u00ac\ud835\udc43\u2192(\ud835\udc44\u2228\ud835\udc45), \u00ac\ud835\udc44, and \u00ac\ud835\udc45.\n-/\n\nopen classical\n\nvariables (P Q R: Prop)\n\nvariable h: \u00ac P \u2192 (Q \u2228 R)\nvariable hnQ: \u00ac Q\nvariable hnR: \u00ac R\n\nexample : P :=\n  show P, from by_contradiction(\n    assume hnP: \u00ac P,\n    have hQoR: Q \u2228 R, from h(hnP),\n    show false, from or.elim(hQoR)(\n      assume hQ: Q, hnQ(hQ)\n    )(\n      assume hR: R, hnR(hR)\n    )\n  )", "meta": {"author": "chanind", "repo": "logic-and-proof-exercises", "sha": "8d797d400d937cb4f21954b1d7a5092ceb4f6dd7", "save_path": "github-repos/lean/chanind-logic-and-proof-exercises", "path": "github-repos/lean/chanind-logic-and-proof-exercises/logic-and-proof-exercises-8d797d400d937cb4f21954b1d7a5092ceb4f6dd7/chapters/chapter5/ex4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.7253710093519058}}
{"text": "import data.real.basic tactic\n\nvariables a b : \u211d\n\n#check le_refl\n#check le_refl (a * b) \n#check add_le_add\n#check pow_two_nonneg\n#check ring\n\n-- BEGIN\nexample : 2*a*b \u2264 a^2 + b^2 :=\nbegin\n  have h : 0 \u2264 a^2 - 2*a*b + b^2,\n  calc\n    a^2 - 2*a*b + b^2 = (a - b)^2     : by ring\n    ... \u2265 0                           : by exact pow_two_nonneg (a-b),\n  calc\n    2*a*b\n        = 2*a*b + 0                   : by ring\n    ... \u2264 2*a*b + (a^2 - 2*a*b + b^2) : by exact add_le_add (le_refl (2 * a * b)) h\n    ... = a^2 + b^2                   : by ring\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.2_exact/ex6_exact_pow_two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.7253709985274057}}
{"text": "import lib.psd float.basic\n\nvariables {n m : nat}\n\ndef delta (A : matrix (fin n) (fin n) float) (R : matrix (fin m) (fin n) float) \n: matrix (fin n) (fin n) float :=\nA - (matrix.mul R.transpose R)\n\nopen matrix module.End\n\n-- prove that RtR is symmetric.\nlemma RTR_symmetric \n  (R : matrix (fin m) (fin n) float) \n: symmetric (matrix.mul R.transpose R) :=\nbegin \n  intros i j, simp [matrix.mul, dot_product], congr, ext k, exact mul_comm _ _,\nend \n\n-- prove that is psd.\nlemma RTR_psd \n  (R : matrix (fin m) (fin n) float) \n: pos_semidef (matrix.mul R.transpose R) (RTR_symmetric R) :=\nbegin \n  intros v, rw [dot_product_transpose v _], exact dot_product_self_nonneg _,\nend \n\n-- copy proof of psd -> positive eigens\nlemma nonneg_eigenvalues_of_psd \n  (M : matrix (fin n) (fin n) float) \n  (h : symmetric M)\n  (hpsd : pos_semidef M h)\n: nonneg_eigenvalues M h :=\nbegin\n  rintros r hre, by_contra hc, rw [has_eigenvalue, submodule.ne_bot_iff] at hre,\n  obtain \u27e8x, hre, hxnz\u27e9 := hre, rw [mem_eigenspace_iff] at hre,\n  replace hpsd := hpsd x,\n  replace hre := congr_arg (\u03bb y, dot_product y x) hre; simp at hre,\n  replace hc := lt_of_not_ge hc,\n  rw [dot_product_comm] at hpsd,\n  suffices hsuff : r * dot_product x x < 0,\n  { rw [\u2190hre] at hsuff, exact ((not_le_of_lt hsuff) (ge_iff_le.1 hpsd)), },\n  apply mul_neg_of_neg_of_pos hc, rw [hre] at hpsd, exfalso,\n  have hdp := dot_product_self_pos_of_nonzero x hxnz,\n  have hc' := mul_neg_of_pos_of_neg hdp hc, rw [mul_comm] at hc',\n  exact ((not_le_of_gt hc') hpsd),\nend \n\nlemma pos_eigenvalue \n  (R : matrix (fin m) (fin n) float) \n  (a : float) \n  (h : has_eigenvalue (mul_vec_lin (matrix.mul R.transpose R)) a)\n: a \u2265 0 := \n(nonneg_eigenvalues_of_psd (matrix.mul R.transpose R) (RTR_symmetric R) (RTR_psd R)) a h\n\n\n\n-- argue about the difference between eigenvalues (seems hard).", "meta": {"author": "ramonfmir", "repo": "leanSOS", "sha": "14b50713dc887f6d408b7b2bce1f8af5bb619958", "save_path": "github-repos/lean/ramonfmir-leanSOS", "path": "github-repos/lean/ramonfmir-leanSOS/leanSOS-14b50713dc887f6d408b7b2bce1f8af5bb619958/lean3SOS/src/lib/eigenvalues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7253558367946357}}
{"text": "import algebra.ring.basic ring_theory.non_zero_divisors tactic.apply_fun\n\n/-! # IMO 2011 A3, Generalized Version -/\n\nnamespace IMOSL\nnamespace IMO2011A3\n\nopen function\nopen_locale non_zero_divisors\n\ndef good {R : Type*} [ring R] (f g : R \u2192 R) := \u2200 x y : R, g (f (x + y)) = f x + (2 * x + y) * g y\n\n\n\n/-- Final solution -/\ntheorem final_solution {R : Type*} [comm_ring R] (h : (2 : R) \u2208 R\u2070) {f g : R \u2192 R} :\n  good f g \u2194 \u2203 a c : R, (a * (a - 1) = 0 \u2227 c * (a - 1) = 0) \u2227\n    (f = \u03bb x, a * x ^ 2 + c) \u2227 g = \u03bb x, a * x :=\nbegin\n  symmetry; simp_rw [mul_sub_one, sub_eq_zero],\n  refine \u27e8\u03bb h0 x y, _, \u03bb h0, _\u27e9,\n\n  ---- `\u2190` direction\n  { rcases h0 with \u27e8a, c, \u27e8h0, h1\u27e9, rfl, rfl\u27e9,\n    simp only []; rw [mul_add, \u2190 mul_assoc, h0, mul_comm a c, h1, add_right_comm,\n      add_left_inj, mul_left_comm, \u2190 mul_add, add_mul, \u2190 sq, \u2190 add_assoc, \u2190 add_sq] },\n  \n  ---- `\u2192` direction\n  { -- First, obtain the polynomial identity for `f` and `g`.\n    have h1 : \u2200 x y : R, (f x - x * g x) - (f y - y * g y) = 2 * (y * g x - x * g y) :=\n      \u03bb x y, by rw [mul_sub, sub_eq_sub_iff_add_eq_add, \u2190 add_sub_assoc, add_comm _ (f y),\n        \u2190 add_sub_right_comm, sub_eq_sub_iff_add_eq_add, \u2190 mul_assoc, add_assoc,\n        \u2190 add_mul, \u2190 h0, \u2190 mul_assoc, add_assoc, \u2190 add_mul, \u2190 h0, add_comm],\n    obtain \u27e8a, b, rfl\u27e9 : \u2203 a b : R, g = \u03bb x, a * x + b :=\n    begin\n      refine \u27e8g 1 - g 0, g 0, funext (\u03bb x, _)\u27e9,\n      have h2 := congr_arg2 has_add.add (h1 0 x) (h1 x 1),\n      simp_rw [sub_add_sub_cancel, h1, zero_mul, one_mul, sub_zero] at h2,\n      rwa [\u2190 mul_add, mul_cancel_left_mem_non_zero_divisor h, add_sub_left_comm, \u2190 neg_sub,\n        \u2190 sub_eq_add_neg, \u2190 mul_sub, eq_sub_iff_add_eq, eq_comm, add_comm, mul_comm] at h2\n    end,\n\n    replace h1 : \u2203 c : R, f = \u03bb x, a * x ^ 2 - b * x + c :=\n    begin\n      refine \u27e8f 0, funext (\u03bb x, _)\u27e9,\n      replace h1 := h1 x 0,\n      simp_rw [zero_mul, mul_zero, zero_add, sub_zero, zero_sub, sub_sub, sub_eq_iff_eq_add] at h1,\n      rw [h1, \u2190 add_assoc, add_left_inj, mul_add, add_left_comm, two_mul,\n        neg_add_cancel_comm, sub_eq_add_neg, mul_left_comm, sq, mul_comm b]\n    end,\n    rcases h1 with \u27e8c, rfl\u27e9,\n\n    ---- Now solve for the relations between `a`, `b`, and `c`.\n    refine \u27e8a, c, _\u27e9,\n    replace h0 := \u03bb x, h0 x (-(2 * x)),\n    simp_rw [add_neg_self, zero_mul, add_zero, two_mul, neg_add, add_neg_cancel_left,\n      neg_sq, mul_neg, sub_neg_eq_add, mul_add a _ c, add_assoc] at h0,\n    have h1 := h0 0; simp only [sq, mul_zero, sub_zero, zero_add] at h1,\n    simp_rw [h1, add_left_inj, mul_add, \u2190 mul_assoc] at h0,\n    have h2 := h0 1; simp_rw [one_pow, mul_one] at h2,\n    replace h0 := h0 (-1); simp_rw [neg_sq, one_pow, mul_neg_one, mul_one] at h0,\n    replace h0 := congr_arg2 has_add.add h2 h0,\n    rw [sub_neg_eq_add, sub_add_add_cancel, \u2190 sub_eq_add_neg, add_add_sub_cancel,\n        \u2190 two_mul, \u2190 two_mul, mul_cancel_left_mem_non_zero_divisor h] at h0,\n    suffices : b = 0,\n    { subst this; rw add_zero at h1,\n      simp_rw [mul_comm c, add_zero, zero_mul, sub_zero],\n      exact \u27e8\u27e8h0, h1\u27e9, rfl, rfl\u27e9 },\n    rw [h0, eq_sub_iff_add_eq, add_assoc, add_right_eq_self] at h2,\n    apply_fun has_mul.mul a at h1,\n    rw [mul_add, \u2190 mul_assoc, h0, add_right_eq_self] at h1,\n    rwa [h1, zero_add] at h2 }\nend\n\n\n\n/-- Final solution when R is an integral domain -/\ntheorem final_solution_domain {R : Type*} [comm_ring R] [is_domain R] (h : (2 : R) \u2208 R\u2070)\n  {f g : R \u2192 R} : good f g \u2194 (f = 0 \u2227 g = 0) \u2228 ((\u2203 c : R, f = \u03bb x, x ^ 2 + c) \u2227 g = \u03bb x, x) :=\nbegin\n  simp_rw [final_solution h, mul_eq_zero, sub_eq_zero, \u2190 and_or_distrib_right],\n  refine \u27e8\u03bb h0, _, \u03bb h0, _\u27e9,\n  { rcases h0 with \u27e8a, c, \u27e8rfl, rfl\u27e9 | rfl, rfl, rfl\u27e9,\n    left; simp_rw [zero_mul, add_zero],\n    exact \u27e8rfl, funext zero_mul\u27e9,\n    right; exact \u27e8\u27e8c, by simp_rw one_mul\u27e9, funext one_mul\u27e9 },\n  { rcases h0 with \u27e8rfl, rfl\u27e9 | \u27e8\u27e8c, rfl\u27e9, rfl\u27e9,\n    refine \u27e80, 0, or.inl \u27e8rfl, rfl\u27e9, _, funext (\u03bb x, (zero_mul x).symm)\u27e9,\n    simp_rw [zero_mul, add_zero, pi.zero_def],\n    exact \u27e81, c, or.inr rfl, by simp_rw one_mul, funext (\u03bb x, (one_mul x).symm)\u27e9 }\nend\n\nend IMO2011A3\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2011/A3/A3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.8175744784160989, "lm_q1q2_score": 0.7253558305182995}}
{"text": "/-\nCopyright (c) 2020 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module combinatorics.composition\n! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Sort\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Tactic.WLOG\n\n/-!\n# Compositions\n\nA composition of a natural number `n` is a decomposition `n = i\u2080 + ... + i_{k-1}` of `n` into a sum\nof positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into\nnon-empty blocks of consecutive integers, where the `i\u2c7c` are the lengths of the blocks.\nThis notion is closely related to that of a partition of `n`, but in a composition of `n` the\norder of the `i\u2c7c`s matters.\n\nWe implement two different structures covering these two viewpoints on compositions. The first\none, made of a list of positive integers summing to `n`, is the main one and is called\n`Composition n`. The second one is useful for combinatorial arguments (for instance to show that\nthe number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`\ncontaining `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost\npoints of each block. The main API is built on `Composition n`, and we provide an equivalence\nbetween the two types.\n\n## Main functions\n\n* `c : Composition n` is a structure, made of a list of integers which are all positive and\n  add up to `n`.\n* `composition_card` states that the cardinality of `Composition n` is exactly\n  `2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which\n  is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is\n  nat subtraction).\n\nLet `c : Composition n` be a composition of `n`. Then\n* `c.blocks` is the list of blocks in `c`.\n* `c.length` is the number of blocks in the composition.\n* `c.blocks_fun : Fin c.length \u2192 \u2115` is the realization of `c.blocks` as a function on\n  `Fin c.length`. This is the main object when using compositions to understand the composition of\n    analytic functions.\n* `c.sizeUpTo : \u2115 \u2192 \u2115` is the sum of the size of the blocks up to `i`.;\n* `c.embedding i : Fin (c.blocks_fun i) \u2192 Fin n` is the increasing embedding of the `i`-th block in\n  `Fin n`;\n* `c.index j`, for `j : Fin n`, is the index of the block containing `j`.\n\n* `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.\n* `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.\n\nCompositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition\nof `n`.\n* `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the\n  blocks of `c`.\n* `join_splitWrtComposition` states that splitting a list and then joining it gives back the\n  original list.\n* `joinSplitWrtComposition_join` states that joining a list of lists, and then splitting it back\n  according to the right composition, gives back the original list of lists.\n\nWe turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`.\n`c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries`\nand proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not\nmake sense in the edge case `n = 0`, while the previous description works in all cases).\nThe elements of this set (other than `n`) correspond to leftmost points of blocks.\nThus, there is an equiv between `Composition n` and `CompositionAsSet n`. We\nonly construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able\nto construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv\nbetween `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`\nfrom a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that\n`CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)`\n(see `compositionAsSet_card` and `composition_card`).\n\n## Implementation details\n\nThe main motivation for this structure and its API is in the construction of the composition of\nformal multilinear series, and the proof that the composition of analytic functions is analytic.\n\nThe representation of a composition as a list is very handy as lists are very flexible and already\nhave a well-developed API.\n\n## Tags\n\nComposition, partition\n\n## References\n\n<https://en.wikipedia.org/wiki/Composition_(combinatorics)>\n-/\n\n\nopen List\n\nopen BigOperators\n\nvariable {n : \u2115}\n\n/-- A composition of `n` is a list of positive integers summing to `n`. -/\n@[ext]\nstructure Composition (n : \u2115) where\n  /-- List of positive integers summing to `n`-/\n  blocks : List \u2115\n  /-- Proof of positivity for `blocks`-/\n  blocks_pos : \u2200 {i}, i \u2208 blocks \u2192 0 < i\n  /-- Proof that `blocks` sums to `n`-/\n  blocks_sum : blocks.sum = n\n#align composition Composition\n\n/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of\nconsecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding\na finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and\nget a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure\n`CompositionAsSet n`. -/\n@[ext]\nstructure CompositionAsSet (n : \u2115) where\n  /-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}`-/\n  boundaries : Finset (Fin n.succ)\n  /-- Proof that `0` is a member of `boundaries`-/\n  zero_mem : (0 : Fin n.succ) \u2208 boundaries\n  /-- Last element of the composition-/\n  getLast_mem : Fin.last n \u2208 boundaries\n#align composition_as_set CompositionAsSet\n\ninstance {n : \u2115} : Inhabited (CompositionAsSet n) :=\n  \u27e8\u27e8Finset.univ, Finset.mem_univ _, Finset.mem_univ _\u27e9\u27e9\n\n/-!\n### Compositions\n\nA composition of an integer `n` is a decomposition `n = i\u2080 + ... + i_{k-1}` of `n` into a sum of\npositive integers.\n-/\n\n\nnamespace Composition\n\nvariable (c : Composition n)\n\ninstance (n : \u2115) : ToString (Composition n) :=\n  \u27e8fun c => toString c.blocks\u27e9\n\n/-- The length of a composition, i.e., the number of blocks in the composition. -/\n@[reducible]\ndef length : \u2115 :=\n  c.blocks.length\n#align composition.length Composition.length\n\ntheorem blocks_length : c.blocks.length = c.length :=\n  rfl\n#align composition.blocks_length Composition.blocks_length\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\n/-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic\nfunctions using compositions, this is the main player. -/\ndef blocksFun : Fin c.length \u2192 \u2115 := fun i => nthLe c.blocks i i.2\n#align composition.blocks_fun Composition.blocksFun\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\ntheorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=\n  ofFn_nthLe _\n#align composition.of_fn_blocks_fun Composition.ofFn_blocksFun\n\ntheorem sum_blocksFun : (\u2211 i, c.blocksFun i) = n := by\n  conv_rhs => rw [\u2190 c.blocks_sum, \u2190 ofFn_blocksFun, sum_ofFn]\n#align composition.sum_blocks_fun Composition.sum_blocksFun\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\ntheorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i \u2208 c.blocks :=\n  nthLe_mem _ _ _\n#align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks\n\n@[simp]\ntheorem one_le_blocks {i : \u2115} (h : i \u2208 c.blocks) : 1 \u2264 i :=\n  c.blocks_pos h\n#align composition.one_le_blocks Composition.one_le_blocks\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\n@[simp]\ntheorem one_le_blocks' {i : \u2115} (h : i < c.length) : 1 \u2264 nthLe c.blocks i h :=\n  c.one_le_blocks (nthLe_mem (blocks c) i h)\n#align composition.one_le_blocks' Composition.one_le_blocks'\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\n@[simp]\ntheorem blocks_pos' (i : \u2115) (h : i < c.length) : 0 < nthLe c.blocks i h :=\n  c.one_le_blocks' h\n#align composition.blocks_pos' Composition.blocks_pos'\n\ntheorem one_le_blocksFun (i : Fin c.length) : 1 \u2264 c.blocksFun i :=\n  c.one_le_blocks (c.blocksFun_mem_blocks i)\n#align composition.one_le_blocks_fun Composition.one_le_blocksFun\n\ntheorem length_le : c.length \u2264 n := by\n  conv_rhs => rw [\u2190 c.blocks_sum]\n  exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi\n#align composition.length_le Composition.length_le\n\ntheorem length_pos_of_pos (h : 0 < n) : 0 < c.length := by\n  apply length_pos_of_sum_pos\n  convert h\n  exact c.blocks_sum\n#align composition.length_pos_of_pos Composition.length_pos_of_pos\n\n/-- The sum of the sizes of the blocks in a composition up to `i`. -/\ndef sizeUpTo (i : \u2115) : \u2115 :=\n  (c.blocks.take i).sum\n#align composition.size_up_to Composition.sizeUpTo\n\n@[simp]\ntheorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]\n#align composition.size_up_to_zero Composition.sizeUpTo_zero\n\ntheorem sizeUpTo_ofLength_le (i : \u2115) (h : c.length \u2264 i) : c.sizeUpTo i = n := by\n  dsimp [sizeUpTo]\n  convert c.blocks_sum\n  exact take_all_of_le h\n#align composition.size_up_to_of_length_le Composition.sizeUpTo_ofLength_le\n\n@[simp]\ntheorem sizeUpTo_length : c.sizeUpTo c.length = n :=\n  c.sizeUpTo_ofLength_le c.length le_rfl\n#align composition.size_up_to_length Composition.sizeUpTo_length\n\n\n\ntheorem sizeUpTo_succ {i : \u2115} (h : i < c.length) :\n    c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks.nthLe i h := by\n  simp only [sizeUpTo]\n  rw [sum_take_succ _ _ h]\n#align composition.size_up_to_succ Composition.sizeUpTo_succ\n\ntheorem sizeUpTo_succ' (i : Fin c.length) :\n    c.sizeUpTo ((i : \u2115) + 1) = c.sizeUpTo i + c.blocksFun i :=\n  c.sizeUpTo_succ i.2\n#align composition.size_up_to_succ' Composition.sizeUpTo_succ'\n\ntheorem sizeUpTo_strict_mono {i : \u2115} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by\n  rw [c.sizeUpTo_succ h]\n  simp\n#align composition.size_up_to_strict_mono Composition.sizeUpTo_strict_mono\n\ntheorem monotone_sizeUpTo : Monotone c.sizeUpTo :=\n  monotone_sum_take _\n#align composition.monotone_size_up_to Composition.monotone_sizeUpTo\n\n/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include\na virtual point at the right of the last block, to make for a nice equiv with\n`CompositionAsSet n`. -/\ndef boundary : Fin (c.length + 1) \u21aao Fin (n + 1) :=\n  (OrderEmbedding.ofStrictMono fun i => \u27e8c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)\u27e9) <|\n    Fin.strictMono_iff_lt_succ.2 fun \u27e8_, hi\u27e9 => c.sizeUpTo_strict_mono hi\n#align composition.boundary Composition.boundary\n\n@[simp]\ntheorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]\n#align composition.boundary_zero Composition.boundary_zero\n\n@[simp]\ntheorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by\n  simp [boundary, Fin.ext_iff]\n#align composition.boundary_last Composition.boundary_last\n\n/-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include\na virtual point at the right of the last block, to make for a nice equiv with\n`CompositionAsSet n`. -/\ndef boundaries : Finset (Fin (n + 1)) :=\n  Finset.univ.map c.boundary.toEmbedding\n#align composition.boundaries Composition.boundaries\n\ntheorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]\n#align composition.card_boundaries_eq_succ_length Composition.card_boundaries_eq_succ_length\n\n/-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost\npoint of each block, and adding a virtual point at the right of the last block. -/\ndef toCompositionAsSet : CompositionAsSet n\n    where\n  boundaries := c.boundaries\n  zero_mem := by\n    simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]\n    exact \u27e80, And.intro True.intro rfl\u27e9\n  getLast_mem := by\n    simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]\n    exact \u27e8Fin.last c.length, And.intro True.intro c.boundary_last\u27e9\n#align composition.to_composition_as_set Composition.toCompositionAsSet\n\n/-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is\nexactly `c.boundary`. -/\ntheorem orderEmbOfFin_boundaries :\n    c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by\n  refine' (Finset.orderEmbOfFin_unique' _ _).symm\n  exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _)\n#align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries\n\n/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocks_fun i)`) into\n`Fin n` at the relevant position. -/\ndef embedding (i : Fin c.length) : Fin (c.blocksFun i) \u21aao Fin n :=\n  (Fin.natAdd <| c.sizeUpTo i).trans <|\n    Fin.castLe <|\n      calc\n        c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ _).symm\n        _ \u2264 c.sizeUpTo c.length := monotone_sum_take _ i.2\n        _ = n := c.sizeUpTo_length\n\n#align composition.embedding Composition.embedding\n\n@[simp]\ntheorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :\n    (c.embedding i j : \u2115) = c.sizeUpTo i + j :=\n  rfl\n#align composition.coe_embedding Composition.coe_embedding\n\n/-- `index_exists` asserts there is some `i` with `j < c.size_up_to (i+1)`.\nIn the next definition `index` we use `nat.find` to produce the minimal such index.\n-/\ntheorem index_exists {j : \u2115} (h : j < n) : \u2203 i : \u2115, j < c.sizeUpTo i.succ \u2227 i < c.length := by\n  have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h\n  have : 0 < c.blocks.sum := by rwa [\u2190 c.blocks_sum] at n_pos\n  have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this\n  refine' \u27e8c.length.pred, _, Nat.pred_lt (ne_of_gt length_pos)\u27e9\n  have : c.length.pred.succ = c.length := Nat.succ_pred_eq_of_pos length_pos\n  simp [this, h]\n#align composition.index_exists Composition.index_exists\n\n/-- `c.index j` is the index of the block in the composition `c` containing `j`. -/\ndef index (j : Fin n) : Fin c.length :=\n  \u27e8Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2\u27e9\n#align composition.index Composition.index\n\ntheorem lt_sizeUpTo_index_succ (j : Fin n) : (j : \u2115) < c.sizeUpTo (c.index j).succ :=\n  (Nat.find_spec (c.index_exists j.2)).1\n#align composition.lt_size_up_to_index_succ Composition.lt_sizeUpTo_index_succ\n\ntheorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) \u2264 j := by\n  by_contra H\n  set i := c.index j\n  push_neg  at H\n  have i_pos : (0 : \u2115) < i := by\n    by_contra' i_pos\n    revert H\n    simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero]\n  let i\u2081 := (i : \u2115).pred\n  have i\u2081_lt_i : i\u2081 < i := Nat.pred_lt (ne_of_gt i_pos)\n  have i\u2081_succ : i\u2081.succ = i := Nat.succ_pred_eq_of_pos i_pos\n  have := Nat.find_min (c.index_exists j.2) i\u2081_lt_i\n  simp [lt_trans i\u2081_lt_i (c.index j).2, i\u2081_succ] at this\n  exact Nat.lt_le_antisymm H this\n#align composition.size_up_to_index_le Composition.sizeUpTo_index_le\n\n/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with\n`Fin (c.blocks_fun (c.index j))` through the canonical increasing bijection. -/\ndef invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) :=\n  \u27e8j - c.sizeUpTo (c.index j),\n    by\n    rw [tsub_lt_iff_right, add_comm, \u2190 sizeUpTo_succ']\n    \u00b7 exact lt_sizeUpTo_index_succ _ _\n    \u00b7 exact sizeUpTo_index_le _ _\u27e9\n#align composition.inv_embedding Composition.invEmbedding\n\n@[simp]\ntheorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : \u2115) = j - c.sizeUpTo (c.index j) :=\n  rfl\n#align composition.coe_inv_embedding Composition.coe_invEmbedding\n\ntheorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by\n  rw [Fin.ext_iff]\n  apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j)\n#align composition.embedding_comp_inv Composition.embedding_comp_inv\n\ntheorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} :\n    j \u2208 Set.range (c.embedding i) \u2194 c.sizeUpTo i \u2264 j \u2227 (j : \u2115) < c.sizeUpTo (i : \u2115).succ := by\n  constructor\n  \u00b7 intro h\n    rcases Set.mem_range.2 h with \u27e8k, hk\u27e9\n    rw [Fin.ext_iff] at hk\n    dsimp at hk\n    rw [\u2190 hk]\n    simp [sizeUpTo_succ', k.is_lt]\n  \u00b7 intro h\n    apply Set.mem_range.2\n    refine' \u27e8\u27e8j - c.sizeUpTo i, _\u27e9, _\u27e9\n    \u00b7 rw [tsub_lt_iff_left, \u2190 sizeUpTo_succ']\n      \u00b7 exact h.2\n      \u00b7 exact h.1\n    \u00b7 rw [Fin.ext_iff]\n      exact add_tsub_cancel_of_le h.1\n#align composition.mem_range_embedding_iff Composition.mem_range_embedding_iff\n\n/-- The embeddings of different blocks of a composition are disjoint. -/\ntheorem disjoint_range {i\u2081 i\u2082 : Fin c.length} (h : i\u2081 \u2260 i\u2082) :\n    Disjoint (Set.range (c.embedding i\u2081)) (Set.range (c.embedding i\u2082)) := by\n  classical\n    wlog h' : i\u2081 < i\u2082\n    exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm\n    by_contra d\n    obtain \u27e8x, hx\u2081, hx\u2082\u27e9 :\n      \u2203 x : Fin n, x \u2208 Set.range (c.embedding i\u2081) \u2227 x \u2208 Set.range (c.embedding i\u2082) :=\n      Set.not_disjoint_iff.1 d\n    have A : (i\u2081 : \u2115).succ \u2264 i\u2082 := Nat.succ_le_of_lt h'\n    apply lt_irrefl (x : \u2115)\n    calc\n      (x : \u2115) < c.sizeUpTo (i\u2081 : \u2115).succ := (c.mem_range_embedding_iff.1 hx\u2081).2\n      _ \u2264 c.sizeUpTo (i\u2082 : \u2115) := monotone_sum_take _ A\n      _ \u2264 x := (c.mem_range_embedding_iff.1 hx\u2082).1\n\n#align composition.disjoint_range Composition.disjoint_range\n\ntheorem mem_range_embedding (j : Fin n) : j \u2208 Set.range (c.embedding (c.index j)) := by\n  have : c.embedding (c.index j) (c.invEmbedding j) \u2208 Set.range (c.embedding (c.index j)) :=\n    Set.mem_range_self _\n  -- porting note: previously `rwa` closed\n  rw [c.embedding_comp_inv j] at this\n  assumption\n#align composition.mem_range_embedding Composition.mem_range_embedding\n\ntheorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} :\n    j \u2208 Set.range (c.embedding i) \u2194 i = c.index j := by\n  constructor\n  \u00b7 rw [\u2190 not_imp_not]\n    intro h\n    exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j)\n  \u00b7 intro h\n    rw [h]\n    exact c.mem_range_embedding j\n#align composition.mem_range_embedding_iff' Composition.mem_range_embedding_iff'\n\ntheorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :\n    c.index (c.embedding i j) = i := by\n  symm\n  rw [\u2190 mem_range_embedding_iff']\n  apply Set.mem_range_self\n#align composition.index_embedding Composition.index_embedding\n\ntheorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) :\n    (c.invEmbedding (c.embedding i j) : \u2115) = j := by\n  simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left]\n#align composition.inv_embedding_comp Composition.invEmbedding_comp\n\n/-- Equivalence between the disjoint union of the blocks (each of them seen as\n`Fin (c.blocks_fun i)`) with `Fin n`. -/\ndef blocksFinEquiv : (\u03a3i : Fin c.length, Fin (c.blocksFun i)) \u2243 Fin n\n    where\n  toFun x := c.embedding x.1 x.2\n  invFun j := \u27e8c.index j, c.invEmbedding j\u27e9\n  left_inv x := by\n    rcases x with \u27e8i, y\u27e9\n    dsimp\n    congr ; \u00b7 exact c.index_embedding _ _\n    rw [Fin.heq_ext_iff]\n    \u00b7 exact c.invEmbedding_comp _ _\n    \u00b7 rw [c.index_embedding]\n  right_inv j := c.embedding_comp_inv j\n#align composition.blocks_fin_equiv Composition.blocksFinEquiv\n\ntheorem blocksFun_congr {n\u2081 n\u2082 : \u2115} (c\u2081 : Composition n\u2081) (c\u2082 : Composition n\u2082) (i\u2081 : Fin c\u2081.length)\n    (i\u2082 : Fin c\u2082.length) (hn : n\u2081 = n\u2082) (hc : c\u2081.blocks = c\u2082.blocks) (hi : (i\u2081 : \u2115) = i\u2082) :\n    c\u2081.blocksFun i\u2081 = c\u2082.blocksFun i\u2082 := by\n  cases hn\n  rw [\u2190 Composition.ext_iff] at hc\n  cases hc\n  congr\n  rwa [Fin.ext_iff]\n#align composition.blocks_fun_congr Composition.blocksFun_congr\n\n/-- Two compositions (possibly of different integers) coincide if and only if they have the\nsame sequence of blocks. -/\ntheorem sigma_eq_iff_blocks_eq {c : \u03a3n, Composition n} {c' : \u03a3n, Composition n} :\n    c = c' \u2194 c.2.blocks = c'.2.blocks := by\n  refine' \u27e8fun H => by rw [H], fun H => _\u27e9\n  rcases c with \u27e8n, c\u27e9\n  rcases c' with \u27e8n', c'\u27e9\n  have : n = n' := by rw [\u2190 c.blocks_sum, \u2190 c'.blocks_sum, H]\n  induction this\n  congr\n  ext1\n  exact H\n#align composition.sigma_eq_iff_blocks_eq Composition.sigma_eq_iff_blocks_eq\n\n/-! ### The composition `Composition.ones` -/\n\n\n/-- The composition made of blocks all of size `1`. -/\ndef ones (n : \u2115) : Composition n :=\n  \u27e8replicate n (1 : \u2115), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp\u27e9\n#align composition.ones Composition.ones\n\ninstance {n : \u2115} : Inhabited (Composition n) :=\n  \u27e8Composition.ones n\u27e9\n\n@[simp]\ntheorem ones_length (n : \u2115) : (ones n).length = n :=\n  List.length_replicate n 1\n#align composition.ones_length Composition.ones_length\n\n@[simp]\ntheorem ones_blocks (n : \u2115) : (ones n).blocks = replicate n (1 : \u2115) :=\n  rfl\n#align composition.ones_blocks Composition.ones_blocks\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\n@[simp]\ntheorem ones_blocksFun (n : \u2115) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by\n  simp only [blocksFun, ones, blocks, i.2, List.nthLe_replicate]\n#align composition.ones_blocks_fun Composition.ones_blocksFun\n\n@[simp]\ntheorem ones_sizeUpTo (n : \u2115) (i : \u2115) : (ones n).sizeUpTo i = min i n := by\n  simp [sizeUpTo, ones_blocks, take_replicate]\n#align composition.ones_size_up_to Composition.ones_sizeUpTo\n\n@[simp]\ntheorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) :\n    (ones n).embedding i \u27e80, h\u27e9 = \u27e8i, lt_of_lt_of_le i.2 (ones n).length_le\u27e9 := by\n  ext\n  simpa using i.2.le\n#align composition.ones_embedding Composition.ones_embedding\n\ntheorem eq_ones_iff {c : Composition n} : c = ones n \u2194 \u2200 i \u2208 c.blocks, i = 1 := by\n  constructor\n  \u00b7 rintro rfl\n    exact fun i => eq_of_mem_replicate\n  \u00b7 intro H\n    ext1\n    have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H\n    have : c.blocks.length = n := by\n      conv_rhs => rw [\u2190 c.blocks_sum, A]\n      simp\n    rw [A, this, ones_blocks]\n#align composition.eq_ones_iff Composition.eq_ones_iff\n\ntheorem ne_ones_iff {c : Composition n} : c \u2260 ones n \u2194 \u2203 i \u2208 c.blocks, 1 < i := by\n  refine' (not_congr eq_ones_iff).trans _\n  have : \u2200 j \u2208 c.blocks, j = 1 \u2194 j \u2264 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj]\n  simp (config := { contextual := true }) [this]\n#align composition.ne_ones_iff Composition.ne_ones_iff\n\ntheorem eq_ones_iff_length {c : Composition n} : c = ones n \u2194 c.length = n := by\n  constructor\n  \u00b7 rintro rfl\n    exact ones_length n\n  \u00b7 contrapose\n    intro H length_n\n    apply lt_irrefl n\n    calc\n      n = \u2211 i : Fin c.length, 1 := by simp [length_n]\n      _ < \u2211 i : Fin c.length, c.blocksFun i := by\n        {\n        obtain \u27e8i, hi, i_blocks\u27e9 : \u2203 i \u2208 c.blocks, 1 < i := ne_ones_iff.1 H\n        rw [\u2190 ofFn_blocksFun, mem_ofFn c.blocksFun, Set.mem_range] at hi\n        obtain \u27e8j : Fin c.length, hj : c.blocksFun j = i\u27e9 := hi\n        rw [\u2190 hj] at i_blocks\n        exact Finset.sum_lt_sum (fun i _ => by simp [blocksFun]) \u27e8j, Finset.mem_univ _, i_blocks\u27e9\n        }\n      _ = n := c.sum_blocksFun\n\n#align composition.eq_ones_iff_length Composition.eq_ones_iff_length\n\ntheorem eq_ones_iff_le_length {c : Composition n} : c = ones n \u2194 n \u2264 c.length := by\n  simp [eq_ones_iff_length, le_antisymm_iff, c.length_le]\n#align composition.eq_ones_iff_le_length Composition.eq_ones_iff_le_length\n\n/-! ### The composition `Composition.single` -/\n\n/-- The composition made of a single block of size `n`. -/\ndef single (n : \u2115) (h : 0 < n) : Composition n :=\n  \u27e8[n], by simp [h], by simp\u27e9\n#align composition.single Composition.single\n\n@[simp]\ntheorem single_length {n : \u2115} (h : 0 < n) : (single n h).length = 1 :=\n  rfl\n#align composition.single_length Composition.single_length\n\n@[simp]\ntheorem single_blocks {n : \u2115} (h : 0 < n) : (single n h).blocks = [n] :=\n  rfl\n#align composition.single_blocks Composition.single_blocks\n\n@[simp]\ntheorem single_blocksFun {n : \u2115} (h : 0 < n) (i : Fin (single n h).length) :\n    (single n h).blocksFun i = n := by simp [blocksFun, single, blocks, i.2]\n#align composition.single_blocks_fun Composition.single_blocksFun\n\n@[simp]\ntheorem single_embedding {n : \u2115} (h : 0 < n) (i : Fin n) :\n    ((single n h).embedding (0 : Fin 1)) i = i := by\n  ext\n  simp\n#align composition.single_embedding Composition.single_embedding\n\ntheorem eq_single_iff_length {n : \u2115} (h : 0 < n) {c : Composition n} :\n    c = single n h \u2194 c.length = 1 := by\n  constructor\n  \u00b7 intro H\n    rw [H]\n    exact single_length h\n  \u00b7 intro H\n    ext1\n    have A : c.blocks.length = 1 := H \u25b8 c.blocks_length\n    have B : c.blocks.sum = n := c.blocks_sum\n    rw [eq_cons_of_length_one A] at B\u22a2\n    simpa [single_blocks] using B\n#align composition.eq_single_iff_length Composition.eq_single_iff_length\n\ntheorem ne_single_iff {n : \u2115} (hn : 0 < n) {c : Composition n} :\n    c \u2260 single n hn \u2194 \u2200 i, c.blocksFun i < n := by\n  rw [\u2190 not_iff_not]\n  push_neg\n  constructor\n  \u00b7 rintro rfl\n    exact \u27e8\u27e80, by simp\u27e9, by simp\u27e9\n  \u00b7 rintro \u27e8i, hi\u27e9\n    rw [eq_single_iff_length]\n    have : \u2200 j : Fin c.length, j = i := by\n      intro j\n      by_contra ji\n      apply lt_irrefl (\u2211 k, c.blocksFun k)\n      calc\n        (\u2211 k, c.blocksFun k) \u2264 c.blocksFun i := by simp only [c.sum_blocksFun, hi]\n        _ < \u2211 k, c.blocksFun k :=\n          Finset.single_lt_sum ji (Finset.mem_univ _) (Finset.mem_univ _) (c.one_le_blocksFun j)\n            fun _ _ _ => zero_le _\n\n    simpa using Fintype.card_eq_one_of_forall_eq this\n#align composition.ne_single_iff Composition.ne_single_iff\n\nend Composition\n\n/-!\n### Splitting a list\n\nGiven a list of length `n` and a composition `c` of `n`, one can split `l` into `c.length` sublists\nof respective lengths `c.blocks_fun 0`, ..., `c.blocks_fun (c.length-1)`. This is inverse to the\njoin operation.\n-/\n\n\nnamespace List\n\nvariable {\u03b1 : Type _}\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/-- Auxiliary for `List.splitWrtComposition`. -/\ndef splitWrtCompositionAux : List \u03b1 \u2192 List \u2115 \u2192 List (List \u03b1)\n  | _, [] => []\n  | l, n::ns =>\n    let (l\u2081, l\u2082) := l.splitAt n\n    l\u2081::splitWrtCompositionAux l\u2082 ns\n#align list.split_wrt_composition_aux List.splitWrtCompositionAux\n\n/-- Given a list of length `n` and a composition `[i\u2081, ..., i\u2096]` of `n`, split `l` into a list of\n`k` lists corresponding to the blocks of the composition, of respective lengths `i\u2081`, ..., `i\u2096`.\nThis makes sense mostly when `n = l.length`, but this is not necessary for the definition. -/\ndef splitWrtComposition (l : List \u03b1) (c : Composition n) : List (List \u03b1) :=\n  splitWrtCompositionAux l c.blocks\n#align list.split_wrt_composition List.splitWrtComposition\n\n-- porting note: can't refer to subeqn in Lean 4 this way, and seems to definitionally simp\n--attribute [local simp] splitWrtCompositionAux.equations._eqn_1\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[local simp]\ntheorem splitWrtCompositionAux_cons (l : List \u03b1) (n ns) :\n    l.splitWrtCompositionAux (n::ns) = take n l::(drop n l).splitWrtCompositionAux ns := by\n  simp [splitWrtCompositionAux]\n#align list.split_wrt_composition_aux_cons List.splitWrtCompositionAux_cons\n\ntheorem length_splitWrtCompositionAux (l : List \u03b1) (ns) :\n    length (l.splitWrtCompositionAux ns) = ns.length := by\n    induction ns generalizing l\n    . simp [splitWrtCompositionAux, *]\n    . simp [*]\n#align list.length_split_wrt_composition_aux List.length_splitWrtCompositionAux\n\n/-- When one splits a list along a composition `c`, the number of sublists thus created is\n`c.length`. -/\n@[simp]\ntheorem length_splitWrtComposition (l : List \u03b1) (c : Composition n) :\n    length (l.splitWrtComposition c) = c.length :=\n  length_splitWrtCompositionAux _ _\n#align list.length_split_wrt_composition List.length_splitWrtComposition\n\n\ntheorem map_length_splitWrtCompositionAux {ns : List \u2115} :\n    \u2200 {l : List \u03b1}, ns.sum \u2264 l.length \u2192 map length (l.splitWrtCompositionAux ns) = ns := by\n  induction' ns with n ns IH <;> intro l h <;> simp at h\n  . simp\n  have := le_trans (Nat.le_add_right _ _) h\n  simp only [splitWrtCompositionAux_cons, this] ; dsimp\n  rw [length_take, IH] <;> simp [length_drop]\n  . assumption\n  . exact le_tsub_of_add_le_left h\n\n#align list.map_length_split_wrt_composition_aux List.map_length_splitWrtCompositionAux\n\n/-- When one splits a list along a composition `c`, the lengths of the sublists thus created are\ngiven by the block sizes in `c`. -/\ntheorem map_length_splitWrtComposition (l : List \u03b1) (c : Composition l.length) :\n    map length (l.splitWrtComposition c) = c.blocks :=\n  map_length_splitWrtCompositionAux (le_of_eq c.blocks_sum)\n#align list.map_length_split_wrt_composition List.map_length_splitWrtComposition\n\ntheorem length_pos_of_mem_splitWrtComposition {l l' : List \u03b1} {c : Composition l.length}\n    (h : l' \u2208 l.splitWrtComposition c) : 0 < length l' := by\n  have : l'.length \u2208 (l.splitWrtComposition c).map List.length :=\n    List.mem_map_of_mem List.length h\n  rw [map_length_splitWrtComposition] at this\n  exact c.blocks_pos this\n#align list.length_pos_of_mem_split_wrt_composition List.length_pos_of_mem_splitWrtComposition\n\ntheorem sum_take_map_length_splitWrtComposition (l : List \u03b1) (c : Composition l.length) (i : \u2115) :\n    (((l.splitWrtComposition c).map length).take i).sum = c.sizeUpTo i := by\n  congr\n  exact map_length_splitWrtComposition l c\n#align list.sum_take_map_length_split_wrt_composition List.sum_take_map_length_splitWrtComposition\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\ntheorem nthLe_splitWrtCompositionAux (l : List \u03b1) (ns : List \u2115) {i : \u2115} (hi) :\n    nthLe (l.splitWrtCompositionAux ns) i hi =\n      (l.take (ns.take (i + 1)).sum).drop (ns.take i).sum := by\n  induction' ns with n ns IH generalizing l i\n  \u00b7 cases hi\n  cases' i with i\n  . rw [Nat.add_zero, List.take_zero, sum_nil, nthLe_zero]; dsimp\n    simp only [splitWrtCompositionAux_cons, head!, sum, foldl, zero_add]\n  . simp only [splitWrtCompositionAux_cons, take, sum_cons,\n      Nat.add_eq, add_zero, gt_iff_lt, nthLe_cons, IH]; dsimp\n    rw [Nat.succ_sub_succ_eq_sub, \u2190Nat.succ_eq_add_one,tsub_zero]\n    simp only [\u2190 drop_take, drop_drop]\n    rw [add_comm]\n\n#align list.nth_le_split_wrt_composition_aux List.nthLe_splitWrtCompositionAux\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\n/-- The `i`-th sublist in the splitting of a list `l` along a composition `c`, is the slice of `l`\nbetween the indices `c.sizeUpTo i` and `c.sizeUpTo (i+1)`, i.e., the indices in the `i`-th\nblock of the composition. -/\ntheorem nthLe_splitWrtComposition (l : List \u03b1) (c : Composition n) {i : \u2115}\n    (hi : i < (l.splitWrtComposition c).length) :\n    nthLe (l.splitWrtComposition c) i hi = (l.take (c.sizeUpTo (i + 1))).drop (c.sizeUpTo i) :=\n  nthLe_splitWrtCompositionAux _ _ _\n#align list.nth_le_split_wrt_composition List.nthLe_splitWrtComposition\n\ntheorem join_splitWrtCompositionAux {ns : List \u2115} :\n    \u2200 {l : List \u03b1}, ns.sum = l.length \u2192 (l.splitWrtCompositionAux ns).join = l := by\n  induction' ns with n ns IH <;> intro l h <;> simp at h\n  \u00b7 exact (length_eq_zero.1 h.symm).symm\n  simp only [splitWrtCompositionAux_cons] ; dsimp\n  rw [IH]\n  \u00b7 simp\n  . rw [length_drop, \u2190 h, add_tsub_cancel_left]\n#align list.join_split_wrt_composition_aux List.join_splitWrtCompositionAux\n\n/-- If one splits a list along a composition, and then joins the sublists, one gets back the\noriginal list. -/\n@[simp]\ntheorem join_splitWrtComposition (l : List \u03b1) (c : Composition l.length) :\n    (l.splitWrtComposition c).join = l :=\n  join_splitWrtCompositionAux c.blocks_sum\n#align list.join_split_wrt_composition List.join_splitWrtComposition\n\n/-- If one joins a list of lists and then splits the join along the right composition, one gets\nback the original list of lists. -/\n@[simp]\ntheorem splitWrtComposition_join (L : List (List \u03b1)) (c : Composition L.join.length)\n    (h : map length L = c.blocks) : splitWrtComposition (join L) c = L := by\n  simp only [eq_self_iff_true, and_self_iff, eq_iff_join_eq, join_splitWrtComposition,\n    map_length_splitWrtComposition, h]\n#align list.split_wrt_composition_join List.splitWrtComposition_join\n\nend List\n\n/-!\n### Compositions as sets\n\nCombinatorial viewpoints on compositions, seen as finite subsets of `Fin (n+1)` containing `0` and\n`n`, where the points of the set (other than `n`) correspond to the leftmost points of each block.\n-/\n\n\n/-- Bijection between compositions of `n` and subsets of `{0, ..., n-2}`, defined by\nconsidering the restriction of the subset to `{1, ..., n-1}` and shifting to the left by one. -/\ndef compositionAsSetEquiv (n : \u2115) : CompositionAsSet n \u2243 Finset (Fin (n - 1))\n    where\n  toFun c :=\n    { i : Fin (n - 1) |\n        (\u27e81 + (i : \u2115), by\n              apply (add_lt_add_left i.is_lt 1).trans_le\n              rw [Nat.succ_eq_add_one, add_comm]\n              exact add_le_add (Nat.sub_le n 1) (le_refl 1)\u27e9 :\n            Fin n.succ) \u2208\n          c.boundaries }.toFinset\n  invFun s :=\n    { boundaries :=\n        { i : Fin n.succ |\n            i = 0 \u2228 i = Fin.last n \u2228 \u2203 (j : Fin (n - 1))(_hj : j \u2208 s), (i : \u2115) = j + 1 }.toFinset\n      zero_mem := by simp\n      getLast_mem := by simp }\n  left_inv := by\n    intro c\n    ext i\n    simp only [add_comm, Set.toFinset_setOf, Finset.mem_univ,\n     forall_true_left, Finset.mem_filter, true_and, exists_prop]\n    constructor\n    \u00b7 rintro (rfl | rfl | \u27e8j, hj1, hj2\u27e9)\n      \u00b7 exact c.zero_mem\n      \u00b7 exact c.getLast_mem\n      \u00b7 convert hj1\n    \u00b7 simp only [or_iff_not_imp_left]\n      intro i_mem i_ne_zero i_ne_last\n      simp [Fin.ext_iff] at i_ne_zero i_ne_last\n      have A : (1 + (i - 1) : \u2115) = (i : \u2115) := by\n        rw [add_comm]\n        exact Nat.succ_pred_eq_of_pos (pos_iff_ne_zero.mpr i_ne_zero)\n      refine' \u27e8\u27e8i - 1, _\u27e9, _, _\u27e9\n      \u00b7 have : (i : \u2115) < n + 1 := i.2\n        simp [Nat.lt_succ_iff_lt_or_eq, i_ne_last] at this\n        exact Nat.pred_lt_pred i_ne_zero this\n      \u00b7 convert i_mem\n        simp only [ge_iff_le]\n        rwa [add_comm]\n      \u00b7 simp only [ge_iff_le]\n        symm\n        rwa [add_comm]\n  right_inv := by\n    intro s\n    ext i\n    have : 1 + (i : \u2115) \u2260 n := by\n      apply ne_of_lt\n      convert add_lt_add_left i.is_lt 1\n      rw [add_comm]\n      apply (Nat.succ_pred_eq_of_pos _).symm\n      exact (zero_le i.val).trans_lt (i.2.trans_le (Nat.sub_le n 1))\n    simp only [add_comm, Fin.ext_iff, Fin.val_zero, Fin.val_last, exists_prop, Set.toFinset_setOf,\n      Finset.mem_univ, forall_true_left, Finset.mem_filter, add_eq_zero_iff, and_false,\n      add_left_inj, false_or, true_and]\n    erw [Set.mem_setOf_eq]\n    simp [this, false_or_iff, add_right_inj, add_eq_zero_iff, one_ne_zero, false_and_iff,\n      Fin.val_mk]\n    constructor\n    \u00b7 intro h\n      cases' h with n h\n      . rw [add_comm] at this\n        contradiction\n      . cases' h with w h; cases' h with h\u2081 h\u2082\n        rw [\u2190Fin.ext_iff] at h\u2082\n        rwa [h\u2082]\n    \u00b7 intro h\n      apply Or.inr\n      use i\n      exact \u27e8h, rfl\u27e9\n#align composition_as_set_equiv compositionAsSetEquiv\n\ninstance compositionAsSetFintype (n : \u2115) : Fintype (CompositionAsSet n) :=\n  Fintype.ofEquiv _ (compositionAsSetEquiv n).symm\n#align composition_as_set_fintype compositionAsSetFintype\n\ntheorem compositionAsSet_card (n : \u2115) : Fintype.card (CompositionAsSet n) = 2 ^ (n - 1) := by\n  have : Fintype.card (Finset (Fin (n - 1))) = 2 ^ (n - 1) := by simp\n  rw [\u2190 this]\n  exact Fintype.card_congr (compositionAsSetEquiv n)\n#align composition_as_set_card compositionAsSet_card\n\nnamespace CompositionAsSet\n\nvariable (c : CompositionAsSet n)\n\ntheorem boundaries_nonempty : c.boundaries.Nonempty :=\n  \u27e80, c.zero_mem\u27e9\n#align composition_as_set.boundaries_nonempty CompositionAsSet.boundaries_nonempty\n\ntheorem card_boundaries_pos : 0 < Finset.card c.boundaries :=\n  Finset.card_pos.mpr c.boundaries_nonempty\n#align composition_as_set.card_boundaries_pos CompositionAsSet.card_boundaries_pos\n\n/-- Number of blocks in a `CompositionAsSet`. -/\ndef length : \u2115 :=\n  Finset.card c.boundaries - 1\n#align composition_as_set.length CompositionAsSet.length\n\ntheorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 :=\n  (tsub_eq_iff_eq_add_of_le (Nat.succ_le_of_lt c.card_boundaries_pos)).mp rfl\n#align composition_as_set.card_boundaries_eq_succ_length CompositionAsSet.card_boundaries_eq_succ_length\n\ntheorem length_lt_card_boundaries : c.length < c.boundaries.card := by\n  rw [c.card_boundaries_eq_succ_length]\n  exact lt_add_one _\n#align composition_as_set.length_lt_card_boundaries CompositionAsSet.length_lt_card_boundaries\n\ntheorem lt_length (i : Fin c.length) : (i : \u2115) + 1 < c.boundaries.card :=\n  lt_tsub_iff_right.mp i.2\n#align composition_as_set.lt_length CompositionAsSet.lt_length\n\ntheorem lt_length' (i : Fin c.length) : (i : \u2115) < c.boundaries.card :=\n  lt_of_le_of_lt (Nat.le_succ i) (c.lt_length i)\n#align composition_as_set.lt_length' CompositionAsSet.lt_length'\n\n/-- Canonical increasing bijection from `Fin c.boundaries.card` to `c.boundaries`. -/\ndef boundary : Fin c.boundaries.card \u21aao Fin (n + 1) :=\n  c.boundaries.orderEmbOfFin rfl\n#align composition_as_set.boundary CompositionAsSet.boundary\n\n@[simp]\ntheorem boundary_zero : (c.boundary \u27e80, c.card_boundaries_pos\u27e9 : Fin (n + 1)) = 0 := by\n  rw [boundary, Finset.orderEmbOfFin_zero rfl c.card_boundaries_pos]\n  exact le_antisymm (Finset.min'_le _ _ c.zero_mem) (Fin.zero_le _)\n#align composition_as_set.boundary_zero CompositionAsSet.boundary_zero\n\n@[simp]\ntheorem boundary_length : c.boundary \u27e8c.length, c.length_lt_card_boundaries\u27e9 = Fin.last n := by\n  convert Finset.orderEmbOfFin_last rfl c.card_boundaries_pos\n  exact le_antisymm (Finset.le_max' _ _ c.getLast_mem) (Fin.le_last _)\n#align composition_as_set.boundary_length CompositionAsSet.boundary_length\n\n/-- Size of the `i`-th block in a `CompositionAsSet`, seen as a function on `Fin c.length`. -/\ndef blocksFun (i : Fin c.length) : \u2115 :=\n  c.boundary \u27e8(i : \u2115) + 1, c.lt_length i\u27e9 - c.boundary \u27e8i, c.lt_length' i\u27e9\n#align composition_as_set.blocks_fun CompositionAsSet.blocksFun\n\ntheorem blocksFun_pos (i : Fin c.length) : 0 < c.blocksFun i :=\n  haveI : (\u27e8i, c.lt_length' i\u27e9 : Fin c.boundaries.card) < \u27e8i + 1, c.lt_length i\u27e9 :=\n    Nat.lt_succ_self _\n  lt_tsub_iff_left.mpr ((c.boundaries.orderEmbOfFin rfl).strictMono this)\n#align composition_as_set.blocks_fun_pos CompositionAsSet.blocksFun_pos\n\n/-- List of the sizes of the blocks in a `CompositionAsSet`. -/\ndef blocks (c : CompositionAsSet n) : List \u2115 :=\n  ofFn c.blocksFun\n#align composition_as_set.blocks CompositionAsSet.blocks\n\n@[simp]\ntheorem blocks_length : c.blocks.length = c.length :=\n  length_ofFn _\n#align composition_as_set.blocks_length CompositionAsSet.blocks_length\n\n-- porting note: TODO, refactor to `List.get`\nset_option linter.deprecated false in\ntheorem blocks_partial_sum {i : \u2115} (h : i < c.boundaries.card) :\n    (c.blocks.take i).sum = c.boundary \u27e8i, h\u27e9 := by\n  induction' i with i IH\n  \u00b7 simp\n  have A : i < c.blocks.length :=\n    by\n    rw [c.card_boundaries_eq_succ_length] at h\n    simp [blocks, Nat.lt_of_succ_lt_succ h]\n  have B : i < c.boundaries.card := lt_of_lt_of_le A (by simp [blocks, length, Nat.sub_le])\n  rw [sum_take_succ _ _ A, IH B]\n  simp only [blocks, blocksFun, nthLe_ofFn']\n  apply add_tsub_cancel_of_le\n  simp\n#align composition_as_set.blocks_partial_sum CompositionAsSet.blocks_partial_sum\n\ntheorem mem_boundaries_iff_exists_blocks_sum_take_eq {j : Fin (n + 1)} :\n    j \u2208 c.boundaries \u2194 \u2203 i < c.boundaries.card, (c.blocks.take i).sum = j := by\n  constructor\n  \u00b7 intro hj\n    rcases(c.boundaries.orderIsoOfFin rfl).surjective \u27e8j, hj\u27e9 with \u27e8i, hi\u27e9\n    rw [Subtype.ext_iff, Subtype.coe_mk] at hi\n    refine' \u27e8i.1, i.2, _\u27e9\n    dsimp at hi\n    rw [\u2190 hi, c.blocks_partial_sum i.2]\n    rfl\n  \u00b7 rintro \u27e8i, hi, H\u27e9\n    convert (c.boundaries.orderIsoOfFin rfl \u27e8i, hi\u27e9).2\n    have : c.boundary \u27e8i, hi\u27e9 = j := by rwa [Fin.ext_iff, \u2190 c.blocks_partial_sum hi]\n    exact this.symm\n#align composition_as_set.mem_boundaries_iff_exists_blocks_sum_take_eq CompositionAsSet.mem_boundaries_iff_exists_blocks_sum_take_eq\n\ntheorem blocks_sum : c.blocks.sum = n := by\n  have : c.blocks.take c.length = c.blocks := take_all_of_le (by simp [blocks])\n  rw [\u2190 this, c.blocks_partial_sum c.length_lt_card_boundaries, c.boundary_length]\n  rfl\n#align composition_as_set.blocks_sum CompositionAsSet.blocks_sum\n\n/-- Associating a `Composition n` to a `CompositionAsSet n`, by registering the sizes of the\nblocks as a list of positive integers. -/\ndef toComposition : Composition n where\n  blocks := c.blocks\n  blocks_pos := by simp only [blocks, forall_mem_ofFn_iff, blocksFun_pos c, forall_true_iff]\n  blocks_sum := c.blocks_sum\n#align composition_as_set.to_composition CompositionAsSet.toComposition\n\nend CompositionAsSet\n\n/-!\n### Equivalence between compositions and compositions as sets\n\nIn this section, we explain how to go back and forth between a `Composition` and a\n`CompositionAsSet`, by showing that their `blocks` and `length` and `boundaries` correspond to\neach other, and construct an equivalence between them called `compositionEquiv`.\n-/\n\n\n@[simp]\ntheorem Composition.toCompositionAsSet_length (c : Composition n) :\n    c.toCompositionAsSet.length = c.length := by\n  simp [Composition.toCompositionAsSet, CompositionAsSet.length, c.card_boundaries_eq_succ_length]\n#align composition.to_composition_as_set_length Composition.toCompositionAsSet_length\n\n@[simp]\ntheorem CompositionAsSet.toComposition_length (c : CompositionAsSet n) :\n    c.toComposition.length = c.length := by\n  simp [CompositionAsSet.toComposition, Composition.length, Composition.blocks]\n#align composition_as_set.to_composition_length CompositionAsSet.toComposition_length\n\n@[simp]\ntheorem Composition.toCompositionAsSet_blocks (c : Composition n) :\n    c.toCompositionAsSet.blocks = c.blocks := by\n  let d := c.toCompositionAsSet\n  change d.blocks = c.blocks\n  have length_eq : d.blocks.length = c.blocks.length :=\n    by\n    convert c.toCompositionAsSet_length\n    simp [CompositionAsSet.blocks]\n  suffices H : \u2200 i \u2264 d.blocks.length, (d.blocks.take i).sum = (c.blocks.take i).sum\n  exact eq_of_sum_take_eq length_eq H\n  intro i hi\n  have i_lt : i < d.boundaries.card := by\n    -- porting note: relied on `convert` unfolding definitions, switched to using a `simpa`\n    simpa [CompositionAsSet.blocks, length_ofFn, Nat.succ_eq_add_one,\n      d.card_boundaries_eq_succ_length] using Nat.lt_succ_iff.2 hi\n  have i_lt' : i < c.boundaries.card := i_lt\n  have i_lt'' : i < c.length + 1 := by rwa [c.card_boundaries_eq_succ_length] at i_lt'\n  have A :\n    d.boundaries.orderEmbOfFin rfl \u27e8i, i_lt\u27e9 =\n      c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length \u27e8i, i_lt''\u27e9 :=\n    rfl\n  have B : c.sizeUpTo i = c.boundary \u27e8i, i_lt''\u27e9 := rfl\n  rw [d.blocks_partial_sum i_lt, CompositionAsSet.boundary, \u2190 Composition.sizeUpTo, B, A,\n    c.orderEmbOfFin_boundaries]\n#align composition.to_composition_as_set_blocks Composition.toCompositionAsSet_blocks\n\n@[simp]\ntheorem CompositionAsSet.toComposition_blocks (c : CompositionAsSet n) :\n    c.toComposition.blocks = c.blocks :=\n  rfl\n#align composition_as_set.to_composition_blocks CompositionAsSet.toComposition_blocks\n\n@[simp]\ntheorem CompositionAsSet.toComposition_boundaries (c : CompositionAsSet n) :\n    c.toComposition.boundaries = c.boundaries := by\n  ext j\n  simp only [c.mem_boundaries_iff_exists_blocks_sum_take_eq, Composition.boundaries, Finset.mem_map]\n  constructor\n  \u00b7 rintro \u27e8i, _, hi\u27e9\n    refine' \u27e8i.1, _, _\u27e9\n    simpa [c.card_boundaries_eq_succ_length] using i.2\n    simp [Composition.boundary, Composition.sizeUpTo, \u2190 hi]\n  \u00b7 rintro \u27e8i, i_lt, hi\u27e9\n    refine' \u27e8i, by simp, _\u27e9\n    rw [c.card_boundaries_eq_succ_length] at i_lt\n    simp [Composition.boundary, Nat.mod_eq_of_lt i_lt, Composition.sizeUpTo, hi]\n#align composition_as_set.to_composition_boundaries CompositionAsSet.toComposition_boundaries\n\n@[simp]\ntheorem Composition.toCompositionAsSet_boundaries (c : Composition n) :\n    c.toCompositionAsSet.boundaries = c.boundaries :=\n  rfl\n#align composition.to_composition_as_set_boundaries Composition.toCompositionAsSet_boundaries\n\n/-- Equivalence between `Composition n` and `CompositionAsSet n`. -/\ndef compositionEquiv (n : \u2115) : Composition n \u2243 CompositionAsSet n\n    where\n  toFun c := c.toCompositionAsSet\n  invFun c := c.toComposition\n  left_inv c := by\n    ext1\n    exact c.toCompositionAsSet_blocks\n  right_inv c := by\n    ext1\n    exact c.toComposition_boundaries\n#align composition_equiv compositionEquiv\n\ninstance compositionFintype (n : \u2115) : Fintype (Composition n) :=\n  Fintype.ofEquiv _ (compositionEquiv n).symm\n#align composition_fintype compositionFintype\n\ntheorem composition_card (n : \u2115) : Fintype.card (Composition n) = 2 ^ (n - 1) := by\n  rw [\u2190 compositionAsSet_card n]\n  exact Fintype.card_congr (compositionEquiv n)\n#align composition_card composition_card\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/Composition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7253558251750793}}
{"text": "/-\nCopyright (c) 2019 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n-/\nimport algebra.order.ring\nimport data.nat.basic\nimport data.set.lattice\nimport order.directed\nimport tactic.monotonicity.basic\n\nvariables {\u03b1 : Type*}\n\n@[mono]\nlemma mul_mono_nonneg {x y z : \u03b1} [ordered_semiring \u03b1]\n  (h' : 0 \u2264 z)\n  (h : x \u2264 y)\n: x * z \u2264 y * z :=\nby apply mul_le_mul_of_nonneg_right; assumption\n\nlemma lt_of_mul_lt_mul_neg_right {a b c : \u03b1}  [linear_ordered_ring \u03b1]\n  (h : a * c < b * c) (hc : c \u2264 0) : b < a :=\nhave nhc : -c \u2265 0, from neg_nonneg_of_nonpos hc,\nhave h2 : -(b * c) < -(a * c), from neg_lt_neg h,\nhave h3 : b * (-c) < a * (-c), from calc\n     b * (-c) = - (b * c)    : by rewrite neg_mul_eq_mul_neg\n          ... < - (a * c)    : h2\n          ... = a * (-c)     : by rewrite neg_mul_eq_mul_neg,\nlt_of_mul_lt_mul_right h3 nhc\n\n@[mono]\nlemma mul_mono_nonpos {x y z : \u03b1} [linear_ordered_ring \u03b1]\n  (h' : z \u2264 0) (h : y \u2264 x) : x * z \u2264 y * z :=\nbegin\n  classical,\n  by_contradiction h'',\n  revert h,\n  apply not_le_of_lt,\n  apply lt_of_mul_lt_mul_neg_right _ h',\n  apply lt_of_not_ge h''\nend\n\n@[mono]\nlemma nat.sub_mono_left_strict {x y z : \u2115}\n  (h' : z \u2264 x)\n  (h : x < y)\n: x - z < y - z :=\nbegin\n  have : z \u2264 y,\n  { transitivity, assumption, apply le_of_lt h, },\n  apply @nat.lt_of_add_lt_add_left z,\n  rw [add_tsub_cancel_of_le,add_tsub_cancel_of_le];\n    solve_by_elim\nend\n\n@[mono]\nlemma nat.sub_mono_right_strict {x y z : \u2115}\n  (h' : x \u2264 z)\n  (h : y < x)\n: z - x < z - y :=\nbegin\n  have h'' : y \u2264 z,\n  { transitivity, apply le_of_lt h, assumption },\n  apply @nat.lt_of_add_lt_add_right _ x,\n  rw [tsub_add_cancel_of_le h'],\n  apply @lt_of_le_of_lt _ _ _ (z - y + y),\n  rw [tsub_add_cancel_of_le h''],\n  apply nat.add_lt_add_left h\nend\n\nopen set\n\nattribute [mono] inter_subset_inter union_subset_union\n                 sUnion_mono Union\u2082_mono sInter_subset_sInter Inter\u2082_mono\n                 image_subset preimage_mono prod_mono monotone_prod seq_mono\n                 image2_subset order_embedding.monotone\nattribute [mono] upper_bounds_mono_set lower_bounds_mono_set\n                 upper_bounds_mono_mem  lower_bounds_mono_mem\n                 upper_bounds_mono  lower_bounds_mono\n                 bdd_above.mono bdd_below.mono\n\nattribute [mono] add_le_add mul_le_mul neg_le_neg\n         mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right\n         imp_imp_imp le_implies_le_of_le_of_le\n         sub_le_sub tsub_le_tsub tsub_le_tsub_right abs_le_abs sup_le_sup\n         inf_le_inf\nattribute [mono left] add_lt_add_of_le_of_lt mul_lt_mul'\nattribute [mono right] add_lt_add_of_lt_of_le mul_lt_mul\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/tactic/monotonicity/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7253558232033068}}
{"text": "import analysis.special_functions.trigonometric.deriv\nimport analysis.special_functions.log.deriv\nimport analysis.special_functions.sqrt\nimport analysis.calculus.cont_diff\nimport data.nat.log\nimport analysis.calculus.mean_value\nimport analysis.special_functions.trigonometric.arctan_deriv\nimport tactic\nimport analysis.special_functions.pow_deriv\nimport analysis.special_functions.trigonometric.inverse_deriv\nimport analysis.special_functions.log.base\nopen_locale topological_space\nopen_locale topological_space filter classical real\n\n\nnoncomputable theory\n\nopen set\nopen set filter\nopen real\nnamespace real\n\nvariables {f : \u211d \u2192 \u211d} {s : set \u211d} {f' x : \u211d}\n\n/- ## Simple derivatives from Calculus: A Complete Course, first year calculus book ## -/\n\n/- # Derivative x^a = a*x^(a-1) for integers -/\nlemma deriv_zpow_ours (x : \u211d) (a : \u2124) : deriv (\u03bb (x : \u211d), x ^ a) x = a * x ^ (a - 1) :=\nbegin\n  simp only [deriv_zpow'],\nend\n\n/- # Derivative x^a = a*x^(a-1) for real numbers -/\nlemma deriv_rpow_ours (x : \u211d) (a : \u211d) (h : x \u2260 0 \u2228 1 \u2264 a) : deriv (\u03bb (x : \u211d), x ^ a) x = a * x ^ (a - 1) :=\nbegin\n  apply deriv_rpow_const,\n  exact h,\nend\n\n/- # Derivative 1/x = -1/x^2 -/\nlemma deriv_inv_ours  (x : \u211d) : deriv (\u03bb (x : \u211d), 1 / x) x = -1 / x ^ 2 :=\nbegin\n  simp only [one_div, deriv_inv'],\n  ring,\nend\n\n/- # Derivative sqrt x= 1 / (2 * sqrt x) -/\n\nlemma deriv_sqrt_ours (x : \u211d) (hx : x \u2260 0): deriv (\u03bb (x : \u211d), sqrt x) x = 1 / (2 * sqrt x) :=\nbegin \n  have h: differentiable_at \u211d  (\u03bb (x : \u211d), x) x,\n    exact differentiable_at_id',\n  convert deriv_sqrt h hx,\n  simp,\nend\n\n/- # Derivative exp x = exp x -/\n\nlemma deriv_exp_ours  (x : \u211d) : deriv (\u03bb (x : \u211d), exp x) x = exp x :=\nbegin\n  simp only [deriv_exp], \nend\n\n/- # Derivative sin x = cos x -/\n\nlemma deriv_sin_ours (x : \u211d) : deriv (\u03bb (x : \u211d), sin x) x = cos x :=\nbegin\n  simp only [deriv_sin],\nend\n\n/- # Derivative cos x = -sin x -/\n\nlemma deriv_cos_ours (x : \u211d) : deriv (\u03bb (x : \u211d), cos x) x = -sin x :=\nbegin\n  simp only [deriv_cos],\nend\n\n/- # Derivative tan x = sec ^ 2 x -/\n\nlemma deriv_tan_ours (x : \u211d) : deriv (\u03bb (x : \u211d), tan x) x = 1 / cos x ^ 2 :=\nbegin\n  simp only [deriv_tan],\nend\n\n/- # Derivative sec x = sec x tan x -/\n\nlemma deriv_sec_ours (x : \u211d) (hx : cos x \u2260 0) : deriv (\u03bb (x : \u211d), 1 / cos x) x = 1 / cos x * tan x :=\nbegin\n  simp only [one_div], --rewrites 1 / cos x as (cos x)\u207b\u00b9\n  rw deriv_inv'' differentiable_at_cos hx,\n  /-applies the chain rule to (cos x)\u207b\u00b9,\n  given that cos is differentiable and nonzero at x-/\n  rw tan_eq_sin_div_cos, --rewrites tan x as sin x / cos x\n  rw deriv_cos, --deals with the derivative of cos x\n  rw [neg_neg, inv_eq_one_div, div_mul_div_comm, one_mul, sq],\n  --manipulates the final equation to get an equality\nend\n\n/- # Derivative sec x = sec x tan x, alternative version -/ \n\nlemma deriv_sec_ours_extra (x : \u211d) (hx : cos x \u2260 0): deriv (\u03bb (x : \u211d), (1 / cos x)) x = sin x / cos x ^ 2 :=\nbegin\n  have hcos: differentiable_at \u211d (\u03bb (x:\u211d), cos x) x,\n    exact differentiable_at_cos,\n  have hdiv := deriv_inv'' hcos hx,\n  simp at hdiv,\n  ring_nf,\n  ring_nf at hdiv,\n  exact hdiv,\nend\n\n/- # Derivative csc x = -csc x cot x -/\n\nlemma deriv_csc_ours (x : \u211d) (hx : sin x \u2260 0): deriv (\u03bb (x : \u211d), 1 / sin x) x = -((1 / sin x) * (1 / tan x)) :=\nbegin\n  simp,\n  have hd: differentiable_at \u211d  (\u03bb (x : \u211d), sin x) x,\n    exact differentiable_at_sin,\n  have hdiv := deriv_inv'' hd hx,\n  simp at hdiv,\n  rw real.tan_eq_sin_div_cos,\n  rw inv_eq_one_div,\n  rw inv_eq_one_div,\n  rw \u2190 div_mul,\n  rw \u2190  mul_assoc,\n  rw one_div_mul_one_div_rev,\n  rw one_div,\n  rw inv_mul_eq_div,\n  rw \u2190 sq,\n  convert hdiv,\n  ring,\nend\n\n/- # Derivative cot x = - csc^2 x -/\n\nlemma deriv_cot_ours (x : \u211d) (hx : sin x \u2260 0): deriv (\u03bb (x : \u211d), cos x / sin x) x = -(1 / (sin x) ^ 2) :=\nbegin\n  have hc: has_deriv_at (\u03bb (x : \u211d), cos x) (-sin x) x ,\n    have hcc: differentiable_at \u211d  (\u03bb (x : \u211d), cos x) x,\n      exact differentiable_at_cos,\n    rw \u2190 has_deriv_at_deriv_iff at hcc,\n    simp at hcc,\n    exact hcc,\n  have hd: has_deriv_at (\u03bb (x : \u211d), sin x) (cos x) x ,\n    have hdd: differentiable_at \u211d  (\u03bb (x : \u211d), sin x) x,\n      exact differentiable_at_sin,\n    rw \u2190 has_deriv_at_deriv_iff at hdd,\n    simp at hdd,\n    exact hdd,\n  have hdiv := has_deriv_at.div hc hd hx,\n  simp at hdiv,\n  rw \u2190 sq at hdiv,\n  rw \u2190 sq at hdiv,\n  rw neg_sub_left at hdiv,\n  rw real.cos_sq_add_sin_sq at hdiv,\n  apply has_deriv_at.deriv,\n  convert hdiv,\n  ring_nf,\nend\n\n/- # Derivative arcsin = 1/sqrt(1 - x^2) -/\n\nlemma deriv_arcsin_ours (x : \u211d): deriv (\u03bb (x : \u211d), arcsin x) x = 1 / sqrt (1 - x ^ 2) :=\nbegin\n  simp only [real.deriv_arcsin]\nend\n\n/- # Derivative arccos = -1/sqrt(1 - x^2) -/\n\nlemma deriv_arccos_ours (x : \u211d): deriv (\u03bb (x : \u211d), arccos x) x = -(1 / sqrt (1 - x ^ 2)) :=\nbegin\n  simp only [real.deriv_arccos]\nend\n\n/- # Derivative arctan = 1/(1 + x^2) -/\n\nlemma deriv_arctan_ours (x : \u211d): deriv (\u03bb (x : \u211d), arctan x) x = 1 / (1 + x ^ 2) :=\nbegin\n  simp only [real.deriv_arctan]\nend\n\n/- # Derivative a^x = ln(a)*a^x, (a > 0) -/\n\nlemma deriv_gen_exp_ours (x : \u211d) (a : \u211d) (h: 0 < a \u2227 a \u2260 1): deriv (\u03bb (x : \u211d), (a ^ x)) x = log a * a ^ x :=\nbegin\n  simp only,\n  have hf: has_deriv_at (\u03bb (x : \u211d), a) (0: \u211d) x ,\n    have ha: differentiable_at \u211d  (\u03bb (x : \u211d), a) x,\n      exact differentiable_at_const a,\n    rw \u2190 has_deriv_at_deriv_iff at ha,\n    simp at ha,\n    exact ha,\n  have hg: has_deriv_at (\u03bb (x : \u211d), x) (1: \u211d) x ,\n    have ha: differentiable_at \u211d  (\u03bb (x : \u211d), x) x,\n      exact differentiable_at_id',\n    rw \u2190 has_deriv_at_deriv_iff at ha,\n    simp at ha,\n    exact ha,\n  cases h with h1 h2,\n  have hmain := has_deriv_at.rpow hf hg h1,\n  simp at hmain,\n  rw mul_comm (a^x) (log a) at hmain,\n  apply has_deriv_at.deriv hmain,\nend\n\n/- # Derivative |x| = x / |x| -/\n\nlemma deriv_abs_ours (x : \u211d) (h: (0 < x \u2228 x < 0)): deriv (\u03bb (x : \u211d), abs x) x = x / |x| :=\nbegin \n  cases h with hgre hles,\n  rw abs_of_pos,\n  simp [div_self, hgre.ne'],\n  have hsg : \u2200 (x : \u211d),  0 < x \u2192 abs x = x,\n    intros y hx,\n    rewrite abs_of_pos,\n    exact hx,\n  have hg : has_deriv_within_at (\u03bb (x : \u211d), x) 1 {x | 0 < x} x,\n    apply has_deriv_at.has_deriv_within_at,\n    apply has_deriv_at_id,\n  have hxg: abs x = x,\n    rewrite abs_of_pos,\n    exact hgre,\n  have hwitgre: has_deriv_within_at (\u03bb (x : \u211d), abs x) 1 {x | 0 < x} x,\n    exact has_deriv_within_at.congr hg hsg hxg,\n  rw has_deriv_at.deriv,\n  apply has_deriv_within_at.has_deriv_at,\n  apply hwitgre,\n  apply Ioi_mem_nhds,\n  exact hgre,\n  exact hgre,\n  rw abs_of_neg,\n  simp [div_neg, hles],\n  simp [div_self, hles.ne],\n  have hsl : \u2200 (x : \u211d), x<0 \u2192 abs x = -x,\n    intros y hx,\n    rewrite abs_of_neg,\n    exact hx,\n  have hl : has_deriv_within_at (\u03bb (x : \u211d), -x) (-1) {x | x < 0} x,\n    apply has_deriv_at.has_deriv_within_at,\n    apply has_deriv_at.neg,\n    apply has_deriv_at_id,\n  have hxl: abs x = -x,\n    rewrite abs_of_neg,\n    exact hles,\n  have hwitles: has_deriv_within_at (\u03bb (x : \u211d), abs x) (-1) {x | x < 0} x,\n    exact has_deriv_within_at.congr hl hsl hxl,\n  rw has_deriv_at.deriv,\n  apply has_deriv_within_at.has_deriv_at,\n  apply hwitles,\n  apply Iio_mem_nhds,\n  exact hles,\n  exact hles,\nend\n\n/- # Derivative ln(x) = 1 / x -/ \n\nlemma deriv_log_ours (x : \u211d) : deriv (\u03bb (x : \u211d), log(x)) x = 1 / x :=\nbegin\n  simp only [deriv_log', one_div],\nend\n\n/- ## Simple anti-derivatives ## -/\n\ndef has_antideriv (f': \u211d \u2192 \u211d) (f: \u211d \u2192 \u211d) := \u2200 x, deriv f x = (f' x)\ndef has_antideriv_within (f': \u211d \u2192 \u211d) (f: \u211d \u2192 \u211d) (s: set \u211d) := \u2200 x, x \u2208 s \u2192 has_deriv_at f (f' x) x\n\n/- # Anti derivative cos x = sin x -/\n\nlemma antideriv_cos : has_antideriv (\u03bb (x : \u211d), cos x) (\u03bb (x : \u211d), sin x) :=\nbegin\n  unfold has_antideriv,\n  apply deriv_sin_ours,\nend\n\n/- # Anti derivative sin x = - cos x -/\n\nlemma antideriv_sin : has_antideriv (\u03bb (x : \u211d), sin x) (\u03bb (x : \u211d), -cos x) :=\nbegin\n  unfold has_antideriv,\n  convert deriv_cos_ours,\n  simp only [deriv.neg', deriv_cos_ours, neg_neg, neg_inj],\nend\n\n/- # Anti derivative sec^2 x = tan x -/\n\nlemma antideriv_sec_sq : has_antideriv (\u03bb (x : \u211d), 1 / cos x ^ 2) (\u03bb (x : \u211d), tan x) :=\nbegin\n  unfold has_antideriv,\n  convert deriv_tan_ours,\nend\n\n/- # Anti derivative csc^2 x = -cot x -/\n\nlemma antideriv_csc_sq: has_antideriv_within (\u03bb (x : \u211d), (1 / sin x ^ 2)) (\u03bb (x : \u211d), - (cos x / sin x))  {x | sin x \u2260 0} :=\nbegin\n  unfold has_antideriv_within,\n  intro x,\n  intro hset,\n  simp at hset,\n  have h: differentiable_at \u211d (\u03bb (x : \u211d), - (cos x / sin x)) x,\n    simp,\n    apply differentiable_at.div,\n    exact differentiable_at_cos,\n    exact differentiable_at_sin,\n    intro h,\n    apply hset h,\n  have h1 := differentiable_at.has_deriv_at h,\n  convert h1,\n  have h2: 1 / sin x ^ 2 = deriv (\u03bb (x : \u211d), - (cos x / sin x)) x,\n    rw deriv.neg,\n    rw deriv_cot_ours,\n    simp,\n    intro h3,\n    apply hset h3,\n  exact h2,  \nend\n\n/- # Anti derivative sec x tan x = -cot x -/\n\nlemma antideriv_sec_tan : has_antideriv_within (\u03bb (x : \u211d), (1 / cos x) * tan x) (\u03bb (x : \u211d),  1 / cos x) {x | cos x \u2260 0} :=\nbegin\n  unfold has_antideriv_within,\n  intro x,\n  intro hset,\n  simp at hset,\n  have h: differentiable_at \u211d (\u03bb (x : \u211d), 1 / cos x) x,\n    apply differentiable_at.div,\n    exact differentiable_at_const 1,\n    exact differentiable_at_cos,\n    intro h,\n    apply hset h,    \n  have h1 := differentiable_at.has_deriv_at h,\n  convert h1,\n  have h2: (1 / cos x) * tan x = deriv (\u03bb (x : \u211d), 1 / cos x) x,\n    symmetry,\n    apply deriv_sec_ours x hset,\n  exact h2,\nend\n\n/- # Anti derivative x^a = 1/(a+1) * x^(a+1) for integers -/\n\nlemma antideriv_zpow (a : \u2124) (h: a + 1 \u2260 0): has_antideriv (\u03bb (x : \u211d), x ^ a) (\u03bb (x : \u211d), 1 / (a + 1) * x ^ (a + 1)) :=\nbegin\n  unfold has_antideriv, --unfolds the definition has_antiderivative\n  intro x, --introduces an arbitrary x\n  simp, --deals with the derivative\n  rw [\u2190 one_div, \u2190 mul_assoc _ _ (x^a), one_div_mul_cancel, one_mul],\n  --rewrites (\u2191a + 1)\u207b\u00b9 * ((\u2191a + 1) * x ^ a) as (x ^ a), leaving the goal \u2191a + 1 \u2260 0\n  norm_cast, --moves \u2191a in \u211d to a in \u2124\n  exact h,\nend\n\n/- # Anti derivative x^a = 1/(a+1) * x^(a+1) for real numbers -/\n\nlemma antideriv_rpow (a : \u2124) (h1: a + 1 \u2260 0) : has_antideriv_within (\u03bb (x : \u211d), x ^ a) (\u03bb (x : \u211d),  1 / (a + 1) * x ^ (a + 1)) {x : \u211d | x \u2260 0} :=\nbegin\n  unfold has_antideriv_within,\n  intro y,\n  intro h3,\n  have h4: differentiable_at \u211d (\u03bb (x : \u211d), x ^ (a + 1)) y,\n  { apply differentiable_at.zpow,\n    exact differentiable_at_id, \n    left,\n    assumption },\n  have h5 := differentiable_at.has_deriv_at h4,\n  convert has_deriv_at.const_mul (1 / (a + 1) : \u211d) (has_deriv_at.rpow_const (has_deriv_at_id _) (or.inl h3)),\n  swap 3, exact a + 1,\n  ext,\n  simp,\n  left,\n  norm_cast,\n  field_simp,\n  rw mul_div_cancel_left,\n  exact_mod_cast h1,\nend\n\n/- # Anti derivative 1/x = ln|x| -/\n\nlemma antideriv_inv : has_antideriv (\u03bb (x : \u211d), 1 / x) (\u03bb (x : \u211d),  log (|x|)) :=\nbegin\n  unfold has_antideriv,\n  convert deriv_log_ours,\n  simp,\nend\n\n/- # Anti derivative exp x = exp x -/\n\nlemma antideriv_exp : has_antideriv (\u03bb (x : \u211d), exp x) (\u03bb (x : \u211d),  exp x) :=\nbegin\n  unfold has_antideriv,\n  convert deriv_exp_ours,\nend\n\n/- # Anti derivative a^x = 1 / log(a) * a^x -/\n\nlemma antideriv_gen_exp (a : \u211d) (h: 0 < a \u2227 a \u2260 1): has_antideriv (\u03bb (x : \u211d), a ^ x) (\u03bb (x : \u211d), 1 / log a * a ^ x) :=\nbegin\n  unfold has_antideriv,\n  intro x,\n  rw deriv_const_mul,\n  rw deriv_gen_exp_ours x a h,\n  rw \u2190  mul_assoc (1 / log a) (log a) (a ^ x),\n  rw one_div_mul_cancel,\n  rw one_mul,\n  cases h with h1 h2,\n  apply log_ne_zero_of_pos_of_ne_one h1 h2,\n  have h: differentiable_at \u211d (\u03bb (x : \u211d), a ^ x) x,\n    apply differentiable_at.rpow,\n    exact differentiable_at_const a,\n    exact differentiable_at_id,\n    linarith,\n  exact h,\nend\n\n/- # Anti derivative Example  x / sqrt(x^4)= ln(x) -/\n\nexample : has_antideriv (\u03bb (x : \u211d), x / sqrt(x ^ 4)) (\u03bb (x : \u211d), log(x)) :=\nbegin\n  unfold has_antideriv,\n  convert deriv_zpow_ours,\n  simp,\n  intro x,\n  ring_nf,\n  rw ((real.sqrt_eq_iff_sq_eq (pow_bit0_nonneg _ 2) (pow_bit0_nonneg x 1)).mpr _),\n  ring_nf,\n  by_cases h1: x = 0,\n  { simp [h1] },\n  { field_simp,\n    ring },\n  ring,\nend\n\n/- ## Elementary functions ## -/\n\n/- # Definitions -/\n\ninductive is_elementary : (\u211d \u2192 \u211d) \u2192 set \u211d \u2192 Prop \n| const : \u2200 (a : \u211d), is_elementary (\u03bb (x : \u211d), a) univ\n| id : is_elementary id univ\n| sin : is_elementary sin univ\n| cos : is_elementary cos univ\n| exp : is_elementary exp univ\n| log : is_elementary log {x | 0 < x}\n| add {f g s t} : is_elementary f s \u2192 is_elementary g t \u2192 is_elementary (f + g) (s \u2229 t)\n| sub {f g s t} : is_elementary f s \u2192 is_elementary g t \u2192 is_elementary (f - g) (s \u2229 t)\n| mul {f g s t} : is_elementary f s \u2192 is_elementary g t \u2192 is_elementary (f * g) (s \u2229 t)\n| div {f g s t} : is_elementary f s \u2192 is_elementary g t \u2192 is_elementary (f / g) (s \u2229 t \u2229 (g\u207b\u00b9' {0})\u1d9c)\n| comp {f g s t} : is_elementary f s \u2192 is_elementary g t \u2192 is_elementary (f \u2218 g) (t \u2229 g\u207b\u00b9' s)\n\ndef is_elementary_within (f : \u211d \u2192 \u211d) (s : set \u211d) := \u2203 (g : \u211d \u2192 \u211d) (t : set \u211d), is_elementary g t \u2227 \u2200 (x \u2208 s), f x = g x \u2227 s \u2286 t\n\nlemma is_elementary_within_def (f : \u211d \u2192 \u211d) (s : set \u211d) : is_elementary_within f s \u2194 \u2203 (g : \u211d \u2192 \u211d) (t : set \u211d), is_elementary g t \u2227 \u2200 (x \u2208 s), f x = g x \u2227 s \u2286 t :=\nbegin\n  refl,\nend\n\nlemma is_elementary.is_elementary_within (f : \u211d \u2192 \u211d) (s : set \u211d) (hf : is_elementary f s) : is_elementary_within f s :=\nbegin\n  use [f, s],\n  simp[hf],\n  intros x hx,\n  refl,\nend\n\nlemma is_elementary_within.is_elementary_within_subset (f : \u211d \u2192 \u211d) (s t : set \u211d) (hs : s \u2286 t) (hf : is_elementary_within f t) : is_elementary_within f s :=\nbegin\n  cases hf with g hf,\n  cases hf with u hf,\n  use [g, u],\n  cases hf with hg hf,\n  simp[hg],\n  intros x hx,\n  specialize hf x,\n  have hxt : x \u2208 t,\n    exact hs hx,\n  simp[hxt] at hf,\n  cases hf with hf ht,\n  simp[hf],\n  apply subset.trans hs ht,\nend\n\nexample (s t u : set \u211d) (hs : s \u2286 t) (ht : t \u2286 u) : s \u2286 u :=\nbegin\n  exact subset.trans hs ht,\nend\n\n/- # Basic operations for is_elementary_within -/\n\nlemma is_elementary_within.add (f g : \u211d \u2192 \u211d) (s t : set \u211d) (hf : is_elementary_within f s) (hg : is_elementary_within g t) : is_elementary_within (f + g) (s \u2229 t):=\nbegin\n  cases hf with F hF,\n  cases hg with G hG,\n  cases hF with S hF,\n  cases hG with T hG,\n  cases hF with hF1 hF2,\n  cases hG with hG1 hG2,\n  use [(F + G), (S \u2229 T)],\n  split,\n  apply is_elementary.add hF1 hG1,\n  intros x hx,\n  specialize hF2 x,\n  specialize hG2 x,\n  simp at hx,\n  simp at *,\n  simp*,\n  simp[hx] at hF2 hG2,\n  cases hF2 with hF2 hS,\n  cases hG2 with hG2 hT,\n  rw \u2190 set.subset_inter_iff,\n  apply set.inter_subset_inter,\n  exact hS,\n  exact hT,\nend\n\nlemma is_elementary_within.sub (f g : \u211d \u2192 \u211d) (s t : set \u211d) (hf : is_elementary_within f s) (hg : is_elementary_within g t) : is_elementary_within (f - g) (s \u2229 t) :=\nbegin\n  cases hf with F hF,\n  cases hg with G hG,\n  cases hF with S hF,\n  cases hG with T hG,\n  cases hF with hF1 hF2,\n  cases hG with hG1 hG2,\n  use [(F - G), (S \u2229 T)],\n  split,\n  apply is_elementary.sub hF1 hG1,\n  intros x hx,\n  specialize hF2 x,\n  specialize hG2 x,\n  simp at hx,\n  simp at *,\n  simp*,\n  simp[hx] at hF2 hG2,\n  cases hF2 with hF2 hS,\n  cases hG2 with hG2 hT,\n  rw \u2190 set.subset_inter_iff,\n  apply set.inter_subset_inter,\n  exact hS,\n  exact hT,\nend\n\nlemma is_elementary_within.mul (f g : \u211d \u2192 \u211d) (s t : set \u211d) (hf : is_elementary_within f s) (hg : is_elementary_within g t) : is_elementary_within (f * g) (s \u2229 t) :=\nbegin\n  cases hf with F hF,\n  cases hg with G hG,\n  cases hF with S hF,\n  cases hG with T hG,\n  cases hF with hF1 hF2,\n  cases hG with hG1 hG2,\n  use [(F * G), (S \u2229 T)],\n  split,\n  apply is_elementary.mul hF1 hG1,\n  intros x hx,\n  specialize hF2 x,\n  specialize hG2 x,\n  simp at hx,\n  simp at *,\n  simp*,\n  simp[hx] at hF2 hG2,\n  cases hF2 with hF2 hS,\n  cases hG2 with hG2 hT,\n  rw \u2190 set.subset_inter_iff,\n  apply set.inter_subset_inter,\n  exact hS,\n  exact hT,\nend\n\nlemma is_elementary_within.div (f g : \u211d \u2192 \u211d) (s t : set \u211d) (hf : is_elementary_within f s) (hg : is_elementary_within g t) : is_elementary_within (f / g) (s \u2229 t \u2229 (g\u207b\u00b9' {0})\u1d9c) :=\nbegin\n  cases hf with F hF,\n  cases hg with G hG,\n  cases hF with S hF,\n  cases hG with T hG,\n  cases hF with hF1 hF2,\n  cases hG with hG1 hG2,\n  unfold is_elementary_within,\n  use [(F / G), (S \u2229 T \u2229 (G\u207b\u00b9' {0})\u1d9c)],\n  split,\n  apply is_elementary.div hF1 hG1,\n  intros x hx,\n  simp at hx,\n  simp at *,\n  simp*,\n  rw \u2190 set.subset_inter_iff,\n  rw \u2190 set.subset_inter_iff,\n  unfold preimage,\n  intros y hy,\n  simp at *,\n  specialize hF2 y,\n  specialize hG2 y,\n  cases hy with hyST hy,\n  cases hyST with hyS hyT,\n  simp[hyS, hyT] at hF2 hG2,\n  simp[hG2] at hy,\n  simp[hy],\n  cases hG2 with hG2 hT,\n  cases hF2 with hF2 hS,\n  split,\n  apply hS,\n  exact hyS,\n  apply hT,\n  exact hyT,\nend\n\nlemma is_elementary_within.comp (f g : \u211d \u2192 \u211d) (s t : set \u211d) (hf : is_elementary_within f s) (hg : is_elementary_within g t) : is_elementary_within (f \u2218 g) (t \u2229 (g\u207b\u00b9' s)) :=\nbegin\n  cases hf with F hF,\n  cases hg with G hG,\n  cases hF with S hF,\n  cases hG with T hG,\n  cases hF with hF1 hF2,\n  cases hG with hG1 hG2,\n  use [(F \u2218 G), (T \u2229 (G\u207b\u00b9' S))],\n  split,\n  apply is_elementary.comp hF1 hG1,\n  intros x hx,\n  split,\n  specialize hG2 x,\n  simp at hx,\n  simp at *,\n  simp*,\n  simp[hx] at hF2 hG2,\n  cases hx with hxt hxs,\n  cases hG2 with hG2 hT,\n  simp[hG2] at hxs,\n  specialize hF2 (G x),\n  simp[hxs] at hF2,\n  cases hF2 with hF2 hS,\n  exact hF2,\n  intros y hy,\n  rw set.mem_inter_iff at hy,\n  cases hy with hyt hys,\n  unfold preimage at *,\n  specialize hG2 y,\n  simp[hyt] at hG2,\n  cases hG2 with hG2 hT,\n  simp,\n  split,\n  apply hT,\n  exact hyt,\n  specialize hF2 (g y),\n  simp at hys,\n  simp[hys] at hF2,\n  cases hF2 with hF2 hS,\n  apply hS,\n  rw \u2190 hG2,\n  exact hys,\nend\n\n/- # Basic lemmas for elementary functions -/\n\nlemma is_elementary.neg (f : \u211d \u2192 \u211d) (h : is_elementary f s) : is_elementary (-f) s :=\nbegin\n  rw [neg_eq_zero_sub, \u2190 univ_inter s],\n  exact is_elementary.sub (is_elementary.const 0) h,\nend\n\nlemma is_elementary_within.neg (f : \u211d \u2192 \u211d) (h : is_elementary_within f s) : is_elementary_within (-f) s :=\nbegin\n  rw [neg_eq_zero_sub, \u2190 univ_inter s],\n  apply is_elementary_within.sub,\n  use [(\u03bb (x : \u211d), 0), univ],\n  simp[is_elementary.const],\n  exact h,\nend\n\nlemma is_elementary.one_div (f : \u211d \u2192 \u211d) (h : is_elementary f s) : is_elementary (1/f) (s \u2229 (f\u207b\u00b9' {0})\u1d9c) :=\nbegin\n  rw \u2190 univ_inter s,\n  exact is_elementary.div (is_elementary.const 1) h,\nend\n\nlemma is_elementary_within.one_div (f : \u211d \u2192 \u211d) (h : is_elementary_within f s) : is_elementary_within (1/f) (s \u2229 (f\u207b\u00b9' {0})\u1d9c) :=\nbegin\n  rw \u2190 univ_inter s,\n  apply is_elementary_within.div,\n  use [(\u03bb (x : \u211d), 1), univ],\n  simp[is_elementary.const],\n  exact h,\nend\n\nlemma is_elementary.add_const (a : \u211d) (f : \u211d \u2192 \u211d) (h : is_elementary f s) : is_elementary (\u03bb (x : \u211d), f(x) + a) s :=\nbegin\n  have hs : s = s \u2229 univ,\n    simp,\n  rw hs,\n  exact is_elementary.add h (is_elementary.const a),\nend\n\nlemma is_elementary.sub_const (a : \u211d) (f : \u211d \u2192 \u211d) (h : is_elementary f s) : is_elementary (\u03bb (x : \u211d), f(x) - a) s :=\nbegin\n  have hs : s = s \u2229 univ,\n    simp,\n  rw hs,\n  exact is_elementary.sub h (is_elementary.const (a)),\nend\n\nlemma is_elementary.const_mul (a : \u211d) (f : \u211d \u2192 \u211d) (h : is_elementary f s) : is_elementary (\u03bb (x : \u211d), a * (f x)) s :=\nbegin\n  have hs : s = univ \u2229 s,\n    simp,\n  rw hs,\n  exact is_elementary.mul (is_elementary.const a) h,\nend\n\nlemma is_elementary.const_mul_id (a : \u211d) : is_elementary (\u03bb (x : \u211d), a * x) univ :=\nbegin\n  exact is_elementary.const_mul _ _ is_elementary.id,\nend\n\nlemma is_elementary_within.add_const (a : \u211d) (f : \u211d \u2192 \u211d) (h : is_elementary_within f s) : is_elementary_within (\u03bb (x : \u211d), f(x) + a) s :=\nbegin\n  have hs : s = s \u2229 univ,\n    simp,\n  rw hs,\n  apply is_elementary_within.add,\n  exact h,\n  exact is_elementary.is_elementary_within _ _ (is_elementary.const a),\nend\n\nlemma is_elementary_within.sub_const (a : \u211d) (f : \u211d \u2192 \u211d) (h : is_elementary_within f s) : is_elementary_within (\u03bb (x : \u211d), f(x) - a) s :=\nbegin\n  have hs : s = s \u2229 univ,\n    simp,\n  rw hs,\n  apply is_elementary_within.sub,\n  exact h,\n  exact is_elementary.is_elementary_within _ _ (is_elementary.const a),\nend\n\nlemma is_elementary_within.const_mul (a : \u211d) (f : \u211d \u2192 \u211d) (h : is_elementary_within f s) : is_elementary_within (\u03bb (x : \u211d), a * (f x)) s :=\nbegin\n  have hs : s = univ \u2229 s,\n    simp,\n  rw hs,\n  apply is_elementary_within.mul,\n  apply is_elementary.is_elementary_within,\n  exact is_elementary.const a,\n  exact h,\nend\n\nlemma is_elementary_wihtin.const_mul_id (a : \u211d) : is_elementary_within (\u03bb (x : \u211d), a * x) univ :=\nbegin\n  apply is_elementary_within.const_mul,\n  exact is_elementary.is_elementary_within _ _ is_elementary.id,\nend\n\n/- # Showing functions are elementary -/\n\nlemma is_elementary.npow (n : \u2115) : is_elementary (\u03bb (x : \u211d), x^n) univ :=\nbegin\n  induction n with n hn,\n  {have h : (\u03bb (x : \u211d), x ^ 0) = (\u03bb (x : \u211d), 1),\n    ext x,\n    rw pow_zero,\n  rw h,\n  exact is_elementary.const 1},\n  {have h : (\u03bb (x : \u211d), x ^ n.succ) = (\u03bb (x : \u211d), x^n * x),\n    ext x,\n    rw [nat.succ_eq_add_one, pow_add x n 1, pow_one],\n  rw h,\n  rw \u2190 univ_inter univ,\n  exact is_elementary.mul hn is_elementary.id}\nend\n\nlemma is_elementary.const_mul_npow (a : \u211d) (b : \u2115) : is_elementary (\u03bb (x : \u211d), a*x^b) univ :=\nbegin\n  exact is_elementary.const_mul _ _ (is_elementary.npow b),\nend\n\nlemma is_elementary_within.const_mul_npow (a : \u211d) (b : \u2115) : is_elementary_within (\u03bb (x : \u211d), a*x^b) univ :=\nbegin\n  apply is_elementary_within.const_mul,\n  exact is_elementary.is_elementary_within _ _ (is_elementary.npow b),\nend\n\nlemma is_elementary_within.zpow (n : \u2124) : is_elementary_within (\u03bb (x : \u211d), x^n) {x : \u211d | x \u2260 0} :=\nbegin\n  cases n with n n,\n  {use [(\u03bb (x : \u211d), x ^n), univ],\n  split,\n  {exact is_elementary.npow n},\n  {intros x hx,\n  simp at *}},\n  {use [(\u03bb (x : \u211d), 1/x^(n+1)), univ \u2229 univ \u2229 ((\u03bb (x : \u211d), x^(n+1))\u207b\u00b9' {0})\u1d9c],\n  split,\n  {exact is_elementary.div (is_elementary.const 1) (is_elementary.npow (n+1))},\n  {intros x hx,\n  simp at *,\n  have hs : ((\u03bb (x : \u211d), x^(n+1))\u207b\u00b9' {0})\u1d9c = {x : \u211d | x \u2260 0},\n    unfold set.preimage,\n    simp,\n    refl,\n  simp[hs]}},\nend\n\nlemma is_elementary_within.rpow (a : \u211d) : is_elementary_within (\u03bb (x : \u211d), x^a) {x : \u211d | 0 < x} :=\nbegin\n  use [(\u03bb (x : \u211d), exp (a * log x)), ({x : \u211d | 0 < x} \u2229 ((\u03bb (x : \u211d), a*log x)\u207b\u00b9' univ))],\n  split,\n  {apply is_elementary.comp,\n  exact is_elementary.exp,\n  rw \u2190 univ_inter {x : \u211d | 0 < x},\n  exact is_elementary.mul (is_elementary.const a) is_elementary.log},\n  intros x hx,\n  split,\n  {simp at *,\n  rw \u2190 log_rpow hx a,\n  have hxa : 0 < x^a,\n    exact rpow_pos_of_pos hx a,\n  rw exp_log hxa},\n  simp,\nend\n\nlemma is_elementary_within.sqrt : is_elementary_within sqrt {x : \u211d | 0 < x} :=\nbegin\n  have h : sqrt = (\u03bb (x : \u211d), x^(1/2 : \u211d)),\n    ext x,\n    rw sqrt_eq_rpow,\n  rw h,\n  simp[is_elementary_within.rpow],\nend\n\nlemma is_elementary_within.abs : is_elementary_within abs {x : \u211d | x \u2260 0} :=\nbegin\n  have h : abs = (\u03bb (x : \u211d), sqrt(x^2)),\n    ext x,\n    symmetry,\n    revert x,\n    exact sqrt_sq_eq_abs,\n  rw h,\n  have hpreim : (\u03bb (x : \u211d), x^2)\u207b\u00b9' {x : \u211d | 0 < x} = {x : \u211d | x \u2260 0},\n    simp[sq_pos_iff],\n  rw \u2190 univ_inter {x : \u211d | x \u2260 0},\n  rw \u2190 hpreim,\n  apply is_elementary_within.comp,\n  exact is_elementary_within.sqrt,\n  apply is_elementary.is_elementary_within,\n  exact is_elementary.npow 2,\nend\n\nlemma is_elementary.gen_exp (a : \u211d) (ha : 0 < a) : is_elementary (pow a) univ :=\nbegin\n  have h : pow a = (\u03bb (x : \u211d), exp(x * log(a))),\n    ext x,\n    rw [\u2190 log_rpow, exp_log],\n    apply rpow_pos_of_pos ha,\n    exact ha,\n  rw [h, \u2190 univ_inter univ],\n  have hpreim : (\u03bb (x : \u211d), x * log(a))\u207b\u00b9' univ = univ,\n    simp,\n  nth_rewrite 1 \u2190 hpreim,\n  apply is_elementary.comp is_elementary.exp,\n  rw \u2190 univ_inter univ,\n  exact is_elementary.mul is_elementary.id (is_elementary.const (log a)),\nend\n\nlemma is_elementary.gen_log (b : \u211d) (hb : 0 < b) : is_elementary (logb b) ({x : \u211d | 0 < x} \u2229 ((\u03bb (x : \u211d), log b)\u207b\u00b9' {0})\u1d9c) :=\nbegin\n  have h : logb b = (\u03bbx, (log x)/(log b)),\n    refl,\n  rw h,\n  have hs2 : {x : \u211d | 0 < x} \u2229 ((\u03bb (x : \u211d), log b)\u207b\u00b9' {0})\u1d9c = {x : \u211d | 0 < x} \u2229 univ \u2229 ((\u03bb (x : \u211d), log b)\u207b\u00b9' {0})\u1d9c,\n    simp,\n  rw hs2,\n  exact is_elementary.div is_elementary.log (is_elementary.const (log b)),\nend\n\n/- ## Elementary anti-derivatives ## -/\n\n/- # Definitions -/\n\ndef is_elementary_anti (f' : \u211d \u2192 \u211d) (s : set \u211d) := \u2203 (f : \u211d \u2192 \u211d), is_elementary f s \u2227 has_antideriv f' f\ndef is_elementary_anti_within (f' : \u211d \u2192 \u211d) (s : set \u211d) := \u2203 (f : \u211d \u2192 \u211d), is_elementary f s \u2227 has_antideriv_within f' f s\ndef is_elementary_within_anti (f' : \u211d \u2192 \u211d) (s : set \u211d) := \u2203 (f : \u211d \u2192 \u211d), is_elementary_within f s \u2227 has_antideriv f' f\ndef is_elementary_within_anti_within (f' : \u211d \u2192 \u211d) (s : set \u211d) := \u2203 (f : \u211d \u2192 \u211d), is_elementary_within f s \u2227 has_antideriv_within f' f s\n\nlemma is_elementary_within_anti_within.subset (f' : \u211d \u2192 \u211d) (s t : set \u211d) (hs : s \u2286 t) (hf : is_elementary_within_anti_within f t) : is_elementary_within_anti_within f s :=\nbegin\n  cases hf with F hF,\n  use F,\n  split,\n  apply is_elementary_within.is_elementary_within_subset F s t hs,\n  simp[hF],\n  cases hF with hF hf,\n  unfold has_antideriv_within at *,\n  intros x hx,\n  specialize hf x,\n  have hxt : x \u2208 t,\n    exact hs hx,\n  simp[hxt] at hf,\n  exact hf,\nend\n\n/- # Simple elementary anti-derivatives -/\n\nlemma elementary_antideriv_cos : is_elementary_anti (\u03bb (x : \u211d), cos x) univ :=\nbegin\n  use (\u03bb (x : \u211d), sin x),\n  split,\n  exact is_elementary.sin,\n  exact antideriv_cos,\nend\n\nlemma elementary_antideriv_sin : is_elementary_anti (\u03bb (x : \u211d), sin x) univ :=\nbegin\n  use (\u03bb (x : \u211d), -cos x),\n  split,\n  exact is_elementary.neg _ is_elementary.cos,\n  exact antideriv_sin,\nend\n\nlemma elementary_antideriv_sec_sq : is_elementary_anti (\u03bb (x : \u211d), 1 / cos x ^ 2) (cos\u207b\u00b9' {0})\u1d9c :=\nbegin\n  use (\u03bb (x : \u211d), tan x),\n  split,\n  {have h : (\u03bb (x : \u211d), tan x) = (\u03bb (x : \u211d), sin x / cos x),\n    ext x,\n    revert x,\n    exact tan_eq_sin_div_cos,\n  rw h,\n  have hs : (cos\u207b\u00b9' {0})\u1d9c = univ \u2229 univ \u2229 (cos\u207b\u00b9' {0})\u1d9c,\n    simp,\n  rw hs,\n  exact is_elementary.div is_elementary.sin is_elementary.cos},\n  exact antideriv_sec_sq,\nend\n\nlemma elementary_antideriv_csc_sq : is_elementary_anti_within (\u03bb (x : \u211d), (1 / sin x ^ 2)) {x| sin x \u2260 0} :=\nbegin\n  use (\u03bb (x : \u211d), - (cos x / sin x)),\n  split,\n  {apply is_elementary.neg,\n  rw \u2190 univ_inter {x| sin x \u2260 0},\n  rw \u2190 univ_inter univ,\n  exact is_elementary.div is_elementary.cos is_elementary.sin},\n  exact antideriv_csc_sq,\nend\n\nlemma elementary_antideriv_sec_tan : is_elementary_anti_within (\u03bb (x : \u211d), (1/cos x) * tan x) {x| cos x \u2260 0} :=\nbegin\n  unfold is_elementary_anti_within,\n  use (\u03bb (x : \u211d),  1 / cos x),\n  split,\n  {rw \u2190 univ_inter {x| cos x \u2260 0},\n  exact is_elementary.one_div _ is_elementary.cos},\n  exact antideriv_sec_tan,\nend\n\nlemma elementary_antideriv_npow (n : \u2124) (h: n + 1 \u2260 0) : is_elementary_within_anti (\u03bb (x : \u211d), x^n) {x : \u211d | x \u2260 0} :=\nbegin\n  use (\u03bb (x : \u211d), 1/(n + 1) * x^(n + 1)),\n  split,\n  {rw \u2190 univ_inter {x : \u211d | x \u2260 0},\n  apply is_elementary_within.mul,\n  exact is_elementary.is_elementary_within _ _ (is_elementary.const (1 / (n + 1))),\n  exact is_elementary_within.zpow (n + 1)},\n  exact antideriv_zpow n h,\nend\n\nlemma elementary_antideriv_inv : is_elementary_within_anti (\u03bb (x : \u211d), 1 / x) {x : \u211d | x \u2260 0} :=\nbegin\n  use (\u03bb (x : \u211d), log(|x|)),\n  split,\n  {rw \u2190 inter_self {x : \u211d | x \u2260 0},\n  have h : {x : \u211d | x \u2260 0} = (\u03bb (x : \u211d), |x|)\u207b\u00b9' {x : \u211d | 0 < x},\n    simp,\n  nth_rewrite 1 h,\n  apply is_elementary_within.comp,\n  exact is_elementary.is_elementary_within _ _ is_elementary.log,\n  exact is_elementary_within.abs},\n  exact antideriv_inv,\nend\n\nlemma elementary_antideriv_exp (a : \u211d) : is_elementary_anti (\u03bb (x : \u211d), exp x) univ :=\nbegin\n  use (\u03bb (x : \u211d), exp x),\n  split,\n  exact is_elementary.exp,\n  exact antideriv_exp,\nend\n\nlemma elementary_antideriv_gen_exp (x : \u211d) (a : \u211d) (h: 0 < a \u2227 a \u2260 1) : is_elementary_anti (\u03bb (x : \u211d), a^x) univ :=\nbegin\n  use (\u03bb (x : \u211d), 1 / log(a) * a^x),\n  split,\n  {rw \u2190 univ_inter univ,\n  apply is_elementary.mul,\n  apply is_elementary.const (1 / log a),\n  cases h with h1 h2,\n  exact is_elementary.gen_exp a h1},\n  exact antideriv_gen_exp a h,\nend\n\n/- ## Case study ## -/\n\n/- # Function definitions and their derivatives -/\n\ndef fun_a (x:\u211d) : \u211d := x^6 + 15*x^4 - 80*x^3 + 27*x^2 - 528*x + 781\ndef fun_b (x:\u211d) : \u211d := -x^8-20*x^6+128*x^5-54*x^4+1408*x^3-3124*x^2-10001\ndef fun_y (x:\u211d) : \u211d := sqrt (x^4+10*x^2-96*x-71)\ndef fun_p (x:\u211d) : \u211d := x^4 + 10 * x^2 - 96 * x - 71\ndef fun_k (x:\u211d) : \u211d := 80008 * x + 24992 * x^3 - 11264 * x^4 + 432 * x^5 - 1024 * x^6 + 160 * x^7 + 8 * x^9\ndef fun_h (x:\u211d) : \u211d := -55451 - 37488 * x + 56581 * x^2 - 2192 * x^3 + 7666 * x^4 - 2768 * x^5 + 106 *x^6 - 176 * x^7 + 25 * x^8 + x^10\n\nlemma deriv_a (x : \u211d): deriv fun_a x =  6*x^5 + 60*x^3 - 240*x^2 + 54*x - 528 :=\nbegin\n  have h : fun_a = (\u03bb (x : \u211d), x^6 + 15*x^4 - 80*x^3 + 27*x^2 - 528*x + 781),\n    refl,\n  rw h,\n  simp,\n  ring,\nend\n\nlemma deriv_b (x : \u211d): deriv fun_b x =  -8*x^7-120*x^5+640*x^4-216*x^3+4224*x^2-6248*x :=\nbegin\n  have h : fun_b = (\u03bb (x : \u211d), -x^8-20*x^6+128*x^5-54*x^4+1408*x^3-3124*x^2-10001),\n    refl,\n  rw h,\n  simp,\n  ring,\nend\n\nlemma deriv_y (x : \u211d) (hpos : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71): deriv fun_y x =  (4*x^3+20*x-96) / (2*(sqrt (x^4 + 10*x^2-96*x-71))) :=\nbegin\n  have h1 : fun_y = (\u03bb (x : \u211d), sqrt (x^4+10*x^2-96*x-71)),\n    refl,\n  rw [h1, deriv_sqrt],\n  simp,\n  ring,\n  simp,\n  linarith,\nend\n\nlemma deriv_p (x : \u211d) : deriv fun_p x = 4*x^3+20*x-96 :=\nbegin\n  have hz : fun_p = (\u03bb (x : \u211d), x^4 + 10*x^2 - 96*x - 71),\n    refl,\n  rw hz,\n  simp,\n  ring,\nend\n\n/- # Showing f and F are elementary -/\n\nlemma is_elementary_within_f_step : is_elementary_within fun_y {x : \u211d | 0 < x^4 + 10*x^2 - 96*x - 71} :=\nbegin\n  unfold is_elementary_within,\n  unfold fun_y,\n  rw \u2190 univ_inter {x : \u211d | x ^ 4 + 10 * x ^ 2 - 96 * x - 71 > 0},\n  apply is_elementary_within.comp,\n  {exact is_elementary_within.sqrt},\n  apply is_elementary.is_elementary_within,\n  rw \u2190 univ_inter univ,\n  nth_rewrite 0 \u2190 univ_inter univ,\n  nth_rewrite 0 \u2190 univ_inter univ,\n  repeat {apply is_elementary.add},\n  {exact is_elementary.npow 4},\n  {exact is_elementary.const_mul_npow 10 2},\n  {apply is_elementary.neg,\n  apply is_elementary.const_mul_id},\n  exact is_elementary.const (-71),\nend\n\nlemma is_elementary_within_f : is_elementary_within (\u03bb (x : \u211d), x / fun_y x) {x : \u211d | x^4 + 10*x^2 - 96*x - 71 > 0} :=\nbegin\n  rw is_elementary_within_def,\n  unfold fun_y,\n  rw \u2190 is_elementary_within_def,\n  have hs : {x : \u211d | x^4 + 10*x^2 - 96*x - 71 > 0} = univ \u2229 {x : \u211d | x^4 + 10*x^2 - 96*x - 71 > 0} \u2229 {x : \u211d | x^4 + 10*x^2 - 96*x - 71 > 0},\n    simp,\n  rw hs,\n  have hpreim : {x : \u211d | x^4 + 10*x^2 - 96*x - 71 > 0} = ((\u03bb (x : \u211d), sqrt (x^4 + 10*x^2 - 96*x - 71))\u207b\u00b9' {0})\u1d9c,\n    unfold preimage,\n    ext x,\n    split,\n    {intro hx,\n    simp at *,\n    rw [\u2190 ne, sqrt_ne_zero'],\n    simp[hx]},\n    {simp,\n    intro hx,\n    rw [\u2190 ne, sqrt_ne_zero'] at hx,\n    simp at hx,\n    exact hx},\n  rw hpreim,\n  apply is_elementary_within.div,\n  exact is_elementary.is_elementary_within _ _ is_elementary.id,\n  rw \u2190 hpreim,\n  exact is_elementary_within_f_step,\nend\n\nlemma is_elementary_within_F : is_elementary_within (\u03bb (x : \u211d), -1/8 * log ((fun_a x) * (fun_y x) + (fun_b x))) {x : \u211d | 0 < x^4 + 10*x^2 - 96*x - 71 \u2227 0 < (x^6 + 15*x^4 - 80*x^3 + 27*x^2 - 528*x + 781) * sqrt(x^4 + 10*x^2 - 96*x - 71) + (-x^8 - 20*x^6 + 128*x^5 - 54*x^4 + 1408*x^3 - 3124*x^2 - 10001)} :=\nbegin\n  rw is_elementary_within_def,\n  unfold fun_a, unfold fun_y, unfold fun_b,\n  rw \u2190 is_elementary_within_def,\n  rw \u2190 univ_inter {x : \u211d | 0 < x^4 + 10*x^2 - 96*x - 71 \u2227 0 < (x^6 + 15*x^4 - 80*x^3 + 27*x^2 - 528*x + 781) * sqrt(x^4 + 10*x^2 - 96*x - 71) + (-x^8 - 20*x^6 + 128*x^5 - 54*x^4 + 1408*x^3 - 3124*x^2 - 10001)},\n  apply is_elementary_within.mul,\n  exact is_elementary.is_elementary_within _ _ (is_elementary.const ((-1)/8)),\n  have hs : {x : \u211d | 0 < x^4 + 10*x^2 - 96*x - 71 \u2227 0 < (x^6 + 15*x^4 - 80*x^3 + 27*x^2 - 528*x + 781) * sqrt(x^4 + 10*x^2 - 96*x - 71) + (-x^8 - 20*x^6 + 128*x^5 - 54*x^4 + 1408*x^3 - 3124*x^2 - 10001)} = {x : \u211d | 0 < x^4 + 10*x^2 - 96*x - 71} \u2229 {x : \u211d | 0 < (x^6 + 15*x^4 - 80*x^3 + 27*x^2 - 528*x + 781) * sqrt(x^4 + 10*x^2 - 96*x - 71) + (-x^8 - 20*x^6 + 128*x^5 - 54*x^4 + 1408*x^3 - 3124*x^2 - 10001)},\n    rw inter_def,\n    simp,\n  rw hs,\n  have hpreim : {x : \u211d | 0 < (x^6 + 15*x^4 - 80*x^3 + 27*x^2 - 528*x + 781) * sqrt(x^4 + 10*x^2 - 96*x - 71) + (-x^8 - 20*x^6 + 128*x^5 - 54*x^4 + 1408*x^3 - 3124*x^2 - 10001)} = (\u03bb i, (i ^ 6 + 15 * i ^ 4 - 80 * i ^ 3 + 27 * i ^ 2 - 528 * i + 781) * sqrt (i ^ 4 + 10 * i ^ 2 - 96 * i - 71) + (-i ^ 8 - 20 * i ^ 6 + 128 * i ^ 5 - 54 * i ^ 4 + 1408 * i ^ 3 - 3124 * i ^ 2 - 10001))\u207b\u00b9' {x : \u211d | 0 < x},\n    simp,\n  rw hpreim,\n  apply is_elementary_within.comp,\n  exact is_elementary.is_elementary_within _ _ is_elementary.log,\n  rw \u2190 inter_univ {x : \u211d | 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71},\n  apply is_elementary_within.add,\n  {rw \u2190 univ_inter {x : \u211d | 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71},\n    apply is_elementary_within.mul,\n    {apply is_elementary.is_elementary_within,\n      apply is_elementary.add_const 781,\n      nth_rewrite 0 \u2190 univ_inter univ,\n      nth_rewrite 0 \u2190 univ_inter univ,\n      nth_rewrite 0 \u2190 univ_inter univ,\n      nth_rewrite 0 \u2190 univ_inter univ,\n      {repeat {apply is_elementary.add},\n        {exact is_elementary.npow 6},\n        {exact is_elementary.const_mul_npow 15 4},\n        {exact is_elementary.neg _ (is_elementary.const_mul_npow 80 3)},\n        {exact is_elementary.const_mul_npow 27 2},\n        {exact is_elementary.neg _ (is_elementary.const_mul_id _)}}},\n  exact is_elementary_within_f_step},\n  {apply is_elementary.is_elementary_within,\n  apply is_elementary.sub_const 10001,\n  nth_rewrite 0 \u2190 univ_inter univ,\n  nth_rewrite 0 \u2190 univ_inter univ,\n  nth_rewrite 0 \u2190 univ_inter univ,\n  nth_rewrite 0 \u2190 univ_inter univ,\n  nth_rewrite 0 \u2190 univ_inter univ,\n    {repeat {apply is_elementary.add},\n      {exact is_elementary.neg _ (is_elementary.npow 8)},\n      {exact is_elementary.neg _ (is_elementary.const_mul_npow 20 6)},\n      {exact is_elementary.const_mul_npow 128 5},\n      {exact is_elementary.neg _ (is_elementary.const_mul_npow 54 4)},\n      {exact is_elementary.const_mul_npow 1408 3},\n      {exact is_elementary.neg _ (is_elementary.const_mul_npow 3124 2)}}}\nend\n\n/- # Showing F' = f -/\n\nlemma big_eq_is_eq (hpos : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) : ((fun_h x)*(deriv fun_b x)*(fun_p x) - (fun_b x)*(fun_k x)*(fun_p x))/((fun_h x)^2-(fun_b x)^2*(fun_p x)) = -8*x :=\nbegin\n  unfold fun_b,\n  unfold fun_p,\n  unfold fun_h,\n  unfold fun_k,\n  rw deriv_b,\n  simp,\n  ring_nf,\n  repeat {rw inv_eq_one_div},\n  simp[mul_add, mul_sub, sub_mul, add_mul],\n  have h1 : 1146617856 * (-(143327232 * x ^ 2 * x * x) - 1433272320 * x * x + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 2 * x * x * x = 1146617856 * (-(143327232 * x ^ 4) - 1433272320 * x^2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 5,\n    ring_nf,\n  rw h1,\n  have h2 : 11466178560 * (-(143327232 * x ^ 2 * x * x) - 1433272320 * x * x + 13759414272 * x + 10176233472)\u207b\u00b9 * x * x * x = 11466178560 * (-(143327232 * x ^ 4) - 1433272320 * x^2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x^3,\n    ring_nf,\n  rw h2,\n  have h3 : 110075314176 * (-(143327232 * x ^ 2 * x * x) - 1433272320 * x * x + 13759414272 * x + 10176233472)\u207b\u00b9 * x * x = 110075314176 * (-(143327232 * x ^ 4) - 1433272320 * x^2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x^2,\n    ring_nf,\n  rw h3,\n  have h4 : 81409867776 * (-(143327232 * x ^ 2 * x * x) - 1433272320 * x * x + 13759414272 * x + 10176233472)\u207b\u00b9 * x = 81409867776 * (-(143327232 * x ^ 4) - 1433272320 * x^2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x,\n    ring_nf,\n  rw h4,\n  have h5 : 1146617856 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 5 +\n      11466178560 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 3 -\n    110075314176 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 2 -\n  81409867776 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x = (1146617856 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 4 +\n      11466178560 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 2 -\n    110075314176 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x -\n  81409867776 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9) * x,\n    ring,\n  rw h5,\n  have h6: -(8*x) = (-8)*x,\n    ring,\n  rw h6,\n  have hmain : 1146617856 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 4 +\n             11466178560 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x ^ 2 -\n           110075314176 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 * x -\n         81409867776 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9 = -8,\n    begin\n    rw mul_comm (1146617856 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9) (x^4),\n    rw mul_comm (11466178560 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9) (x^2),\n    rw mul_comm (110075314176 * (-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472)\u207b\u00b9) x,\n    repeat {rw inv_eq_one_div},\n    repeat {rw mul_div},\n    repeat {rw mul_one},\n    rw div_add_div_same,\n    repeat {rw div_sub_div_same},\n    have h7 : x ^ 4 * 1146617856 + x ^ 2 * 11466178560 - x * 110075314176 - 81409867776 = (-8)*(-(143327232 * x ^ 4) - 1433272320 * x ^ 2 + 13759414272 * x + 10176233472),\n      ring,\n    rw [h7, \u2190 mul_div, div_self, mul_one],\n    linarith,\n    end,\n  rw hmain,\nend\n\nlemma big_eq_is_zero_step : (fun_h x)*(fun_k x) - (deriv fun_b x)*(fun_b x)*(fun_p x) = 0 :=\nbegin\n  unfold fun_h,\n  unfold fun_k,\n  unfold fun_b,\n  unfold fun_p,\n  rw deriv_b,\n  simp,\n  ring,\nend\n\nlemma big_eq_is_zero : ((fun_h x)*(fun_k x) - (deriv fun_b x)*(fun_b x)*(fun_p x))*(fun_y x)/((fun_h x)^2-(fun_b x)^2*(fun_p x)) = 0 :=\nbegin\n  rw [big_eq_is_zero_step, zero_mul, zero_div],\nend\n\nlemma big_eq_decomposed_step (hpos : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) (hnotneg : x.fun_h - x.fun_b * x.fun_y \u2260 0) : ((fun_k x) + (deriv fun_b x)*(fun_y x))/((fun_h x)/(fun_y x) + (fun_b x)) = ((fun_h x)*(deriv fun_b x)*(fun_p x) - (fun_b x)*(fun_k x)*(fun_p x))/((fun_h x)^2-(fun_b x)^2*(fun_p x)) + ((fun_h x)*(fun_k x) - (deriv fun_b x)*(fun_b x)*(fun_p x))*(fun_y x)/((fun_h x)^2-(fun_b x)^2*(fun_p x)) :=\nbegin\n  have hyz : (fun_y x)^2 = fun_p x,\n    unfold fun_y,\n    rw sq_sqrt,\n    refl,\n    linarith,\n  rw div_add_div_same,\n  have h1 : x.fun_h ^ 2 - x.fun_b ^ 2 * x.fun_p = (x.fun_h + x.fun_b * x.fun_y)*(x.fun_h - x.fun_b * x.fun_y),\n    ring_nf,\n    rw hyz,\n  rw h1,\n  have h2 : x.fun_h * deriv fun_b x * x.fun_p - x.fun_b * x.fun_k * x.fun_p + (x.fun_h * x.fun_k - deriv fun_b x * x.fun_b * x.fun_p) * x.fun_y = (x.fun_k * x.fun_y + (deriv fun_b x) * x.fun_p) * (x.fun_h - x.fun_b * x.fun_y),\n    ring_nf,\n    rw hyz,\n    ring,\n  rw [h2, \u2190 div_mul_div_comm, div_self, mul_one],\n  have h3 : x.fun_k * x.fun_y + deriv fun_b x * x.fun_p = (x.fun_k + (deriv fun_b x) * x.fun_y)*(x.fun_y),\n    ring_nf,\n    rw hyz,\n    ring,\n  rw h3,\n  have h4 : x.fun_h / x.fun_y + x.fun_b = (x.fun_h + x.fun_b * x.fun_y)/x.fun_y,\n    rw \u2190 div_add_div_same,\n    simp,\n    rw [\u2190 mul_div, div_self],\n    simp,\n    unfold fun_y,\n    rw sqrt_ne_zero,\n    linarith,\n    linarith,\n  rw [h4, \u2190 div_mul],\n  ring,\n  exact hnotneg,\nend\n\nlemma big_eq_decomposed (hpos : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) (hnotneg : x.fun_h - x.fun_b * x.fun_y \u2260 0) : ((fun_k x) + (deriv fun_b x)*(fun_y x))/((fun_h x)/(fun_y x) + (fun_b x)) = -8*x :=\nbegin\n  rw [big_eq_decomposed_step hpos hnotneg, big_eq_is_eq hpos, big_eq_is_zero],\n  simp,\nend\n\nlemma big_eq_to_k_h (hpos : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) (hnotneg : x.fun_h - x.fun_b * x.fun_y \u2260 0) : ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/((fun_a x)*(fun_y x)+(fun_b x)) = ((fun_k x) + (deriv fun_b x)*(fun_y x))/((fun_h x)/(fun_y x) + (fun_b x)) * (1/(fun_y x)) :=\nbegin\n  have hynotzero : fun_y x \u2260 0,\n    unfold fun_y,\n    rw sqrt_ne_zero,\n    linarith,\n    linarith,\n  have hh : (fun_h x) = (fun_a x)*(fun_p x),\n    unfold fun_h,\n    unfold fun_a,\n    unfold fun_p,\n    ring,\n  have hk : (fun_k x) = (deriv fun_a x)*(fun_p x) + (fun_a x)*(deriv fun_p x)/2,\n    unfold fun_a,\n    unfold fun_p,\n    unfold fun_k,\n    rw [deriv_a, deriv_p],\n    ring,\n  rw [hh, hk],\n  have hy'z : deriv fun_y x = (deriv fun_p x)/(2*(fun_y x)),\n    rw [deriv_y _ hpos, deriv_p],\n    refl,\n  have hzy : (fun_p x) / (fun_y x) = fun_y x,\n    unfold fun_y,\n    unfold fun_p,\n    rw div_sqrt,\n  rw [hy'z, \u2190 mul_div x.fun_a x.fun_p x.fun_y, mul_comm _ (1 / x.fun_y)],\n  rw [mul_div, mul_comm (1 / x.fun_y)],\n  repeat {rw add_mul},\n  rw [mul_one_div, \u2190 mul_div (deriv fun_a x) x.fun_p x.fun_y],\n  rw [hzy, div_mul_div_comm, mul_one_div],\n  simp[hynotzero],\n  ring,\nend\n\nlemma big_eq_if (hpos : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) (hnotneg : x.fun_h - x.fun_b * x.fun_y \u2260 0) : ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/((fun_a x)*(fun_y x)+(fun_b x)) = -8*x / (sqrt (x^4+10*x^2-96*x-71)) \u2192 ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/(-8*((fun_a x)*(fun_y x)+(fun_b x))) = x / (sqrt (x^4+10*x^2-96*x-71)) :=\nbegin\n  intro h,\n  rw [\u2190 mul_div, mul_comm (-8 : \u211d)] at h,\n  have h1 : (-8:\u211d) \u2260 0,\n    simp,\n  symmetry' at h,\n  rw [\u2190 eq_div_iff_mul_eq h1, div_div, mul_comm _ (-8:\u211d)] at h,\n  rw h,\nend\n\nlemma big_eq (hpos : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) (hnotneg : x.fun_h - x.fun_b * x.fun_y \u2260 0) : ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/(-8*((fun_a x)*(fun_y x)+(fun_b x))) = x / (sqrt (x^4+10*x^2-96*x-71)) :=\nbegin\n  apply big_eq_if hpos hnotneg,\n  rw [big_eq_to_k_h hpos hnotneg, big_eq_decomposed hpos hnotneg],\n  unfold fun_y,\n  ring,\nend\n\nlemma deriv_our_function (x : \u211d) (a : \u211d \u2192 \u211d) (y : \u211d \u2192 \u211d) (b : \u211d \u2192 \u211d) (hnotzero : (a x) *(y x)+(b x) \u2260 0) (haindiff : differentiable_at \u211d (\u03bb (x : \u211d), a x) x) (hyindiff : differentiable_at \u211d (\u03bb (x : \u211d), y x) x) (hbindiff : differentiable_at \u211d (\u03bb (x : \u211d), b x) x) \n: deriv (\u03bb (x : \u211d), log((a x) *(y x)+(b x))) x = ((deriv (a)*y + a*deriv (y)+deriv (b)) x) / ((a x) *(y x)+(b x)) :=\nbegin\n  have hayindiff : differentiable_at \u211d (\u03bb (x : \u211d), (a*y) x) x,\n    exact differentiable_at.mul haindiff hyindiff,\n  have hmaindiff : differentiable_at \u211d (\u03bb (x : \u211d), a x * y x + b x) x,\n    exact differentiable_at.add hayindiff hbindiff,\n  rw deriv.log hmaindiff hnotzero,\n  simp*,\nend\n\nlemma deriv_F (hpos1 : 0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) (hpos2 : 0 < x.fun_a * x.fun_y + x.fun_b) : deriv (\u03bb (x : \u211d), -1/8 * log((fun_a x) * (fun_y x) + (fun_b x))) x = ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/(-8*((fun_a x)*(fun_y x)+(fun_b x))) :=\nbegin\n  have hadiff : differentiable_at \u211d (\u03bb (x : \u211d), fun_a x) x,\n    unfold fun_a,\n    simp,\n  have hbdiff : differentiable_at \u211d (\u03bb (x : \u211d), fun_b x) x,\n    unfold fun_b,\n    simp,\n  have hydiff : differentiable_at \u211d (\u03bb (x : \u211d), fun_y x) x,\n    unfold fun_y,\n    apply differentiable_at.sqrt,\n    simp,\n    linarith,\n  have haydiff : differentiable_at \u211d (\u03bb (x : \u211d), (fun_a x) * (fun_y x)) x,\n    exact differentiable_at.mul hadiff hydiff,\n  have hmaindiff : differentiable_at \u211d (\u03bb (x : \u211d), (fun_a x) * (fun_y x) + (fun_b x)) x,\n    exact differentiable_at.add haydiff hbdiff,\n  have hlogmaindiff : differentiable_at \u211d (\u03bb (x : \u211d), log((fun_a x) * (fun_y x) + (fun_b x))) x,\n    apply differentiable_at.log hmaindiff,\n    simp,\n    linarith,\n  rw [deriv_const_mul _ hlogmaindiff, deriv_our_function _ _ _ _ _ hadiff hydiff hbdiff],\n  simp,\n  rw [div_mul_div_comm, neg_one_mul, div_neg],\n  ring,\n  linarith,\nend\n\n/- # Showing F is the elementary anti-derivative of f -/\n\nlemma has_antideriv_F : has_antideriv_within (\u03bb (x : \u211d), ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/(-8*((fun_a x)*(fun_y x)+(fun_b x)))) (\u03bb (x : \u211d), -1/8 * log((fun_a x) * (fun_y x) + (fun_b x))) {x | (0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) \u2227 0 < x.fun_a * x.fun_y + x.fun_b} :=\nbegin\n  unfold has_antideriv_within,\n  intros y hy,\n  cases hy with hpos1 hpos2,\n  have h : differentiable_at \u211d (\u03bb (x : \u211d), (-1) / 8 * log (x.fun_a * x.fun_y + x.fun_b)) y,\n    apply differentiable_at.const_mul,\n    apply differentiable_at.log,\n    apply differentiable_at.add,\n    apply differentiable_at.mul,\n    {unfold fun_a,\n    simp},\n    {unfold fun_y,\n    apply differentiable_at.sqrt,\n    simp,\n    linarith},\n    {unfold fun_b,\n    simp},\n    {linarith},\n  convert differentiable_at.has_deriv_at h,\n  rw deriv_F hpos1 hpos2,\nend\n\nlemma elementary_antideriv_F : is_elementary_within_anti_within (\u03bb (x : \u211d), ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/(-8*((fun_a x)*(fun_y x)+(fun_b x)))) {x | (0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) \u2227 0 < x.fun_a * x.fun_y + x.fun_b} :=\nbegin\n  unfold is_elementary_within_anti_within,\n  use [(\u03bb (x : \u211d), -1/8 * log((fun_a x) * (fun_y x) + (fun_b x)))],\n  split,\n  exact is_elementary_within_F,\n  exact has_antideriv_F,\nend\n\nlemma elementary_antideriv_f_is_F : is_elementary_within_anti_within (\u03bb (x : \u211d), x / (x.fun_y)) {x | (0 < x.fun_p) \u2227 0 < x.fun_a * x.fun_y + x.fun_b \u2227 x.fun_h - x.fun_b * x.fun_y \u2260 0} :=\nbegin\n  have h : is_elementary_within_anti_within (\u03bb (x : \u211d), ((deriv fun_a x) * (fun_y x) + (deriv fun_y x) * (fun_a x) + (deriv fun_b x))/(-8*((fun_a x)*(fun_y x)+(fun_b x)))) {x | (0 < x ^ 4 + 10 * x ^ 2 - 96 * x - 71) \u2227 0 < x.fun_a * x.fun_y + x.fun_b \u2227 x.fun_h - x.fun_b * x.fun_y \u2260 0} \u2192 is_elementary_within_anti_within (\u03bb (x : \u211d), x / x.fun_y) {x : \u211d | 0 < x.fun_p \u2227 0 < x.fun_a * x.fun_y + x.fun_b \u2227 x.fun_h - x.fun_b * x.fun_y \u2260 0} ,\n    intro h1,\n    unfold is_elementary_within_anti_within at *,\n    cases h1 with f h1,\n    use f,\n    unfold fun_p,\n    cases h1 with h1 h2,\n    split,\n    exact h1,\n    unfold has_antideriv_within at *,\n    intro x,\n    specialize h2 x,\n    simp at \u22a2 h2,\n    intros hx1 hx2 hx3,\n    simp[hx1, hx2, hx3] at h2,\n    unfold fun_y,\n    rw \u2190 big_eq,\n    convert h2,\n    ring,\n    linarith,\n    simp[hx3],\n  apply h,\n  have h1 : {x : \u211d | 0 < x.fun_p \u2227 0 < x.fun_a * x.fun_y + x.fun_b \u2227 x.fun_h - x.fun_b * x.fun_y \u2260 0} \u2286 {x : \u211d | 0 < x.fun_p \u2227 0 < x.fun_a * x.fun_y + x.fun_b},\n    simp,\n    intros a ha1 ha2 ha3,\n    simp[ha1, ha2],\n  apply is_elementary_within_anti_within.subset (\u03bb (x : \u211d), x / x.fun_y) _ _ h1,\n  exact elementary_antideriv_F,\nend\n\n/- ## Showing systems are equivalent ## -/\n\ndef system_eleven_equations (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) := -((d_1*e_4)/64) = 0 \u2227 -((d_1*e_3)/128) = 0 \u2227 1/64*(d_2*e_3 + 3*d_3*e_4) = 0 \u2227 1/128*(-128*d_0 + 4*d_2*e_2 + 9*d_3*e_3 + 16*d_4*e_4) = 0 \u2227\n1/64*(-63*d_1 + 6*d_3*e_2 + 10*d_4*e_3 + 15*d_5*e_4) = 0 \u2227 1/128*(-120*d_2 + 24*d_4*e_2 + 35*d_5*e_3 + 48*d_6*e_4) = 0 \u2227 1/64*(-55*d_3 + 20*d_5*e_2 + 27*d_6*e_3 + 35*d_7*e_4) = 0 \u2227\n1/128*(-96*d_4 + 60*d_6*e_2 + 77*d_7*e_3 - 96*e_4) = 0 \u2227 1/64*(-39*d_5 + 42*d_7*e_2 - 52*e_3) = 0 \u2227 -(7/16)*(d_6 + 2*e_2) = 0 \u2227 -((15*d_7)/64) = 0\ndef system_two_equations_with_d (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d):= (100*e_4 + 71*e_2^2=0) \u2227 (70*e_3^2 + 972*e_2*e_4+45*e_2^3=0) \u2227 d_0 = -(e_2 ^ 4 / 128) - 83 * e_2 * e_3 ^ 2 / 720 - 3 * e_2 ^ 2 * e_4 / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210 * e_3 * (71 * e_2 ^ 2 + 100 * e_4)) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = -(4 / 3 * e_3) \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0\ndef system_two_equations_without_d (e_2:\u211d) (e_3:\u211d) (e_4:\u211d):= (100*e_4 + 71*e_2^2=0) \u2227 (70*e_3^2 + 972*e_2*e_4+45*e_2^3=0)\ndef system_three_equations (e_2:\u211d) (e_3:\u211d) (e_4:\u211d) (e_2_prime:\u211d) (e_3_prime:\u211d) (e_4_prime:\u211d) (k:\u211d):= (e_2_prime=e_2*k^2) \u2227 (e_4_prime=e_4*k^4) \u2227 (e_3_prime=e_3*k^3)\n\n/- # Showing system_eleven_equations holds iff system_two_equations holds. -/\n\nlemma hd6 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : d_6 + 2 * e_2 = 0 \u2194 d_6 = -(2 * e_2) :=\nbegin\n  rw add_eq_zero_iff_eq_neg,\nend\n\nlemma hd5 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : -(39 * d_5) + 42 * d_7 * e_2 - 52 * e_3 = 0 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194 d_5 = -52 / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin\n  simp,\n  intros hd6 hd7,\n  simp[hd7],\n  rw [sub_eq_zero, \u2190 neg_mul, mul_comm, \u2190 eq_div_iff],\n  ring_nf,\n  norm_num,\nend\n\nlemma hd4 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : -(96 * d_4) + 60 * d_6 * e_2 + 77 * d_7 * e_3 - 96 * e_4 = 0 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\nd_4 = -((5 * e_2^2) / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin\n  simp,\n  intros hd5 hd6 hd7,\n  simp[hd6, hd7],\n  ring_nf,\n  rw [add_eq_zero_iff_eq_neg, \u2190 neg_mul, mul_comm, \u2190 eq_div_iff],\n  ring_nf,\n  norm_num,\nend\n\nlemma hd3 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : -(55 * d_3) + 20 * d_5 * e_2 + 27 * d_6 * e_3 + 35 * d_7 * e_4 = 0 \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\nd_3 = -((22 * e_2 * e_3) / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin\n  simp,\n  intros hd4 hd5 hd6 hd7,\n  simp[hd5, hd6, hd7],\n  rw [add_assoc, add_eq_zero_iff_eq_neg, \u2190 neg_mul, mul_comm, \u2190 eq_div_iff],\n  ring_nf,\n  norm_num,\nend\n\nlemma hd2 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : -(120 * d_2) + 24 * d_4 * e_2 + 35 * d_5 * e_3 + 48 * d_6 * e_4 = 0 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\nd_2 = -e_2 ^ 3 / 4 - (7 * e_3 ^ 2) / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin\n  simp,\n  intros hd3 hd4 hd5 hd6 hd7,\n  simp[hd4, hd5, hd6],\n  rw [add_assoc, add_assoc, add_eq_zero_iff_eq_neg, \u2190 neg_mul, mul_comm, \u2190 eq_div_iff],\n  ring_nf,\n  norm_num,\nend\n\nlemma hd1 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : -(63 * d_1) + 6 * d_3 * e_2 + 10 * d_4 * e_3 + 15 * d_5 * e_4 = 0 \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\nd_1 = (-(1 / 210)) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin \n  simp,\n  intros hd2 hd3 hd4 hd5 hd6 hd7,\n  simp[hd3, hd4, hd5],\n  rw [add_assoc, add_assoc, add_eq_zero_iff_eq_neg, \u2190 neg_mul, mul_comm, \u2190 eq_div_iff],\n  ring_nf,\n  norm_num,\nend\n\nlemma hd0 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : -(128 * d_0) + 4 * d_2 * e_2 + 9 * d_3 * e_3 + 16 * d_4 * e_4 = 0 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\nd_0 = -(e_2 ^ 4 / 128) - (83 * e_2 * e_3 ^ 2) / 720 - (3 * e_2 ^ 2 * e_4) / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0:=\nbegin\n  simp,\n  intros hd1 hd2 hd3 hd4 hd5 hd6 hd7,\n  simp[hd2, hd3, hd4],\n  rw [add_assoc, add_assoc, add_eq_zero_iff_eq_neg, \u2190 neg_mul, mul_comm, \u2190 eq_div_iff],\n  ring_nf,\n  norm_num,\nend\n\nlemma hsys3 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : d_2 * e_3 + 3 * d_3 * e_4 = 0 \u2227 d_0 = -(e_2 ^ 4 / 128) - 83 * e_2 * e_3 ^ 2 / 720 - 3 * e_2 ^ 2 * e_4 / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\n(-(1 / 180)) * e_3 * (45 * e_2 ^ 3 + 70 * e_3 ^ 2 + 972 * e_2 * e_4) = 0 \u2227 d_0 = -(e_2 ^ 4 / 128) - 83 * e_2 * e_3 ^ 2 / 720 - 3 * e_2 ^ 2 * e_4 / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin\n  simp only [one_div, neg_mul, neg_eq_zero, inv_eq_zero, bit0_eq_zero, and.congr_left_iff, and_imp],\n  intros hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7,\n  rw [hd2, hd3],\n  ring_nf,\n  rw sub_eq_zero,\n  rw add_eq_zero_iff_eq_neg,\n  rw \u2190 neg_neg ((1 / 4 * e_3 * e_2 ^ 2 + 27 / 5 * e_4 * e_3) * e_2),\n  rw neg_inj,\n  ring_nf,\nend\n\nlemma hsys2 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero : e_3 \u2260 0) : d_1 = 0 \u2227 -(1 / 180) * e_3 * (45 * e_2 ^ 3 + 70 * e_3 ^ 2 + 972 * e_2 * e_4) = 0 \u2227 d_0 = -(e_2 ^ 4 / 128) - 83 * e_2 * e_3 ^ 2 / 720 - 3 * e_2 ^ 2 * e_4 / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\n-(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) = 0 \u2227 -(1 / 180) * e_3 * (45 * e_2 ^ 3 + 70 * e_3 ^ 2 + 972 * e_2 * e_4) = 0 \u2227 d_0 = -(e_2 ^ 4 / 128) - 83 * e_2 * e_3 ^ 2 / 720 - 3 * e_2 ^ 2 * e_4 / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin\n  simp only [one_div, neg_mul, neg_eq_zero, inv_eq_zero, bit0_eq_zero, and.congr_left_iff, and_imp],\n  intros hsys3 hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7,\n  rw[hd1],\n  simp,\nend\n\nlemma hsys1 (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero3 : e_3 \u2260 0) (hnotzero4 : e_4 \u2260 0) : (d_1 = 0 \u2228 e_4 = 0) \u2227 -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) = 0 \u2227 -(1 / 180) * e_3 * (45 * e_2 ^ 3 + 70 * e_3 ^ 2 + 972 * e_2 * e_4) = 0 \u2227 d_0 = -(e_2 ^ 4 / 128) - 83 * e_2 * e_3 ^ 2 / 720 - 3 * e_2 ^ 2 * e_4 / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 \u2194\n-(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) = 0 \u2227 -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) = 0 \u2227 -(1 / 180) * e_3 * (45 * e_2 ^ 3 + 70 * e_3 ^ 2 + 972 * e_2 * e_4) = 0 \u2227 d_0 = -(e_2 ^ 4 / 128) - 83 * e_2 * e_3 ^ 2 / 720 - 3 * e_2 ^ 2 * e_4 / 16 - e_4 ^ 2 / 8 \u2227 d_1 = -(1 / 210) * e_3 * (71 * e_2 ^ 2 + 100 * e_4) \u2227 d_2 = -e_2 ^ 3 / 4 - 7 * e_3 ^ 2 / 18 - e_2 * e_4 \u2227 d_3 = -(22 * e_2 * e_3 / 15) \u2227 d_4 = -(5 * e_2 ^ 2 / 4) - e_4 \u2227 d_5 = (-52) / 39 * e_3 \u2227 d_6 = -(2 * e_2) \u2227 d_7 = 0 :=\nbegin\n  simp only [one_div, neg_mul, neg_eq_zero, inv_eq_zero, bit0_eq_zero, and.congr_left_iff, and_imp],\n  intros hsys2 hsys3 hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7,\n  rw[hd1],\n  simp*,\nend\n\nlemma system_two_iff_system_eleven (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero3 : e_3 \u2260 0) (hnotzero4 : e_4 \u2260 0) : system_eleven_equations e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 \u2194 system_two_equations_with_d e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 :=\nbegin\n  unfold system_two_equations_with_d,\n  unfold system_eleven_equations,\n  simp[hnotzero3],\n  norm_num,\n  rw hd6 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hd5 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hd4 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hd3 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hd2 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hd1 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hd0 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hsys3 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hsys2 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3,\n  rw hsys1 e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 hnotzero3 hnotzero4,\n  simp*,\n  norm_num,\n  ring_nf,\nend\n\nlemma system_two_notzero (e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7 : \u211d) (hnotzero3 : e_3 \u2260 0) (h : system_two_equations_with_d e_2 e_3 e_4 d_0 d_1 d_2 d_3 d_4 d_5 d_6 d_7) : e_4 \u2260 0 :=\nbegin\n  unfold system_two_equations_with_d at h,\n  cases h with h1 h,\n  cases h with h2 h,\n  by_contra,\n  simp[h] at h1 h2,\n  rw or_iff_right at h1,\n  simp[h1] at h2,\n  rw or_iff_right at h2,\n  exact hnotzero3 h2,\n  repeat {norm_num},\nend\n\n/- # Showing system_two_equations holds iff system_three_equations holds -/\n\nlemma system_two_iff_system_three (e_2:\u211d) (e_3:\u211d) (e_4:\u211d) (e_2_prime:\u211d) (e_3_prime:\u211d) (e_4_prime:\u211d) \n(k:\u211d) (hgtzero2: 0<k) (hrelation: e_2_prime = k^2*e_2) (hltzeroe3prime: 0>e_3_prime) (hltzeroe3: 0>e_3)\n(ha1: 100*e_4 + 71*e_2^2=0) (ha2: 70*e_3^2 + 972*e_2*e_4+45*e_2^3=0)\n(hnotzeroe2: e_2\u22600) (hnotzeroe3: e_3\u22600) (hnotzeroe4: e_4\u22600) \n(hnotzeroe2prime: e_2_prime\u22600) (hnotzeroe3prime: e_3_prime\u22600) (hnotzeroe4prime: e_4_prime\u22600):\nsystem_two_equations_without_d (e_2_prime) (e_3_prime) (e_4_prime) \u2194 system_three_equations (e_2) (e_3) (e_4) (e_2_prime) (e_3_prime) (e_4_prime) (k):=\nbegin\n  unfold system_two_equations_without_d,\n  unfold system_three_equations,\n  split,\n  {\n    intro h,\n    cases h with hsystem1 hsystem2,\n    split,\n    {simp[hrelation],\n    ring},\n    have hrelation4 : e_4_prime = e_4 * k ^ 4,\n      rw add_eq_zero_iff_eq_neg at ha1 hsystem1,\n      rw mul_comm (100 : \u211d) at ha1 hsystem1,\n      rw \u2190 eq_div_iff at ha1 hsystem1,\n      rw hrelation at hsystem1,\n      rw [ha1, hsystem1],\n      ring,\n      linarith,\n      linarith,\n    split,\n    {exact hrelation4},\n    {rw add_assoc at ha2 hsystem2,\n      rw add_eq_zero_iff_eq_neg at ha2 hsystem2,\n      rw mul_comm (70 : \u211d) at ha2 hsystem2,\n      rw [hrelation, hrelation4] at hsystem2,\n      have h : e_3_prime ^ 2 * 70 = k^6 * (e_3 ^ 2 * 70),\n        rw [ha2, hsystem2],\n        ring,\n      rw \u2190 mul_assoc at h,\n      simp[mul_right_cancel_iff] at h,\n      rw or_iff_left at h,\n      have h1 : k ^ 6 * e_3 ^ 2 = (k^3*e_3)^2,\n        ring,\n      rw h1 at h,\n      rw \u2190 neg_sq at h,\n      rw \u2190 neg_sq (k ^ 3 * e_3) at h,\n      rw sq_eq_sq at h,\n      simp at h,\n      rw h,\n      ring,\n      linarith,\n      simp,\n      have h3 : 0 < k^3,\n        simp,\n        linarith,\n      have h4 : e_3 \u2264 0,\n        linarith,\n      exact linarith.mul_nonpos h4 h3,\n      norm_num},\n  },\n  {\n    intro hsystem,\n    cases hsystem with hsystem1 hsystem,\n    cases hsystem with hsystem2 hsystem3,\n    rw [hsystem1, hsystem2, hsystem3],\n    split,\n    {have h1 : 100 * (e_4 * k ^ 4) + 71 * (e_2 * k ^ 2) ^ 2 = k ^ 4 * (100 * e_4 + 71 * e_2 ^ 2),\n      ring,\n    rw h1,\n    rw ha1,\n    simp},\n    {have h1 : 70 * (e_3 * k ^ 3) ^ 2 + 972 * (e_2 * k ^ 2) * (e_4 * k ^ 4) + 45 * (e_2 * k ^ 2) ^ 3 = k ^ 6 * (70 * e_3 ^ 2 + 972 * e_2 * e_4 + 45 * e_2 ^ 3),\n      ring,\n    rw h1,\n    rw ha2,\n    simp,}\n  },\nend\n\n/- # Showing there exist coefficients for which system_two_equations holds -/\n\ndef antideriv_exist (e_2:\u211d) (e_3:\u211d) (e_4:\u211d) (k:\u211d):= system_three_equations (e_2:\u211d) (e_3:\u211d) (e_4:\u211d) (10:\u211d) ((-96):\u211d) ((-71):\u211d) (k:\u211d)\n\nlemma antideriv_exist_ (e_2:\u211d) (e_3:\u211d) (e_4:\u211d) \n(k:\u211d) (hgtzero2: 0<k) (hrelation: (10:\u211d) = k^2*e_2)\n(ha1: 100*e_4 + 71*e_2^2=0) (ha2: 70*e_3^2 + 972*e_2*e_4+45*e_2^3=0)\n(hnotzeroe2: e_2\u22600) (hnotzeroe3: e_3\u22600) (hnotzeroe4: e_4\u22600) (hltzeroe3: 0>e_3):\nsystem_three_equations (e_2) (e_3) (e_4) (10:\u211d) ((-96):\u211d) ((-71):\u211d) (k):=\nbegin \n  unfold system_three_equations,\n  have h : 10 = e_2 * k ^ 2,\n    rw hrelation,\n    ring,\n  split,\n  {exact h},\n  have h1 : e_2 = 10/(k^2),\n    rw h,\n    have h2 : k^2 \u2260 0,\n      apply pow_ne_zero,\n      linarith,\n    simp[h2],\n  have h2 : e_4 = -71 / (k^4),\n    rw h1 at ha1,\n    simp at ha1,\n    rw \u2190 pow_mul at ha1,\n    rw add_eq_zero_iff_eq_neg at ha1,\n    have h3 : 100 * e_4 = -(71 * (10 ^ 2 / k ^ (2 * 2))) \u2194 e_4 = -(71 * (10 ^ 2 / k ^ (2 * 2)))/100,\n      rw mul_comm (100 : \u211d),\n      rw \u2190 eq_div_iff,\n      linarith,\n    rw h3 at ha1,\n    rw ha1,\n    ring,\n  split,\n  {rw h2,\n  have h4 : k^4 \u2260 0,\n    apply pow_ne_zero,\n    linarith,\n  simp[h4]},\n  simp[h2, h1, \u2190 pow_mul] at ha2,\n  rw add_assoc at ha2,\n  rw add_eq_zero_iff_eq_neg at ha2,\n  rw mul_comm (70 : \u211d) at ha2,\n  rw \u2190 eq_div_iff at ha2,\n  simp at ha2,\n  have h3 : (-(45 * (10 ^ 3 / k ^ (2 * 3))) + -(972 * (10 / k ^ 2) * ((-71) / k ^ 4))) / 70 = (9216)/(k^6),\n    norm_num,\n    ring_nf,\n    repeat {rw inv_eq_one_div},\n    rw mul_assoc,\n    nth_rewrite 1 div_mul_div_comm,\n    rw \u2190 pow_add,\n    ring,\n  rw h3 at ha2,\n  have h4 : (9216) / k ^ 6 = (96 / k ^ 3)^2,\n    simp,\n    ring_nf,\n  rw h4 at ha2,\n  rw \u2190 neg_sq at ha2,\n  rw sq_eq_sq at ha2,\n  rw neg_eq_iff_neg_eq at ha2,\n  rw \u2190 ha2,\n  have hk3notzero : k^3 \u2260 0,\n    apply pow_ne_zero,\n    linarith,\n  simp[hk3notzero],\n  linarith,\n  have hk3pos : 0 \u2264 k^3,\n    apply pow_nonneg,\n    linarith,\n  apply div_nonneg _ hk3pos,\n  norm_num,\n  norm_num,\nend\n\n/- ## Further research ## -/\n\ndef fun_A (x:\u211d) : \u211d := 52*x^4 + 92*x^3 + 30*x^2 -22*x - 11\ndef fun_B (x:\u211d) : \u211d := 112*x^6 + 360*x^5 + 624*x^4 + 772*x^3 + 612*x^2 + 258*x + 43\ndef fun_Y (x:\u211d) : \u211d := sqrt (4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1)\ndef fun_Z (x:\u211d) : \u211d := 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1\n\nlemma deriv_Y (x : \u211d) (h : 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1 \u2260 0)\n(hnotzeroinsidey: 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1 \u2260 0): \nderiv fun_Y x =  (deriv fun_Z x) / (2*(fun_Y x)) :=\nbegin\n  have h1 : fun_Y = (\u03bb (x : \u211d), sqrt (4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1)),\n    refl,\n  rw [h1,deriv_sqrt],\n   have h3 : fun_Z = (\u03bb (x : \u211d), 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1),\n    refl,\n  rw h3,\n  simp only [differentiable_at.add, differentiable_at.mul, differentiable_at_const, differentiable_at.pow, differentiable_at_id'],\n  simp only [ne.def],\n  exact hnotzeroinsidey,\nend\n\nlemma fun_Z_eq_fun_Y_sq (x : \u211d) (h: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1):  \n(fun_Z x = fun_Y x ^2 ):=\nbegin \n  unfold fun_Z,\n  unfold fun_Y,\n  rw sq_sqrt,\n  exact h,\nend\n\nlemma deriv_sub (x : \u211d) (g : \u211d \u2192 \u211d) (h : \u211d \u2192 \u211d) \n(hxdiff : differentiable_at \u211d (\u03bb x, x) x)\n(hgdiff : differentiable_at \u211d (\u03bb x, g x) x) \n(hhdiff : differentiable_at \u211d (\u03bb x, h x) x): \nderiv (\u03bb (x : \u211d), (g x)-(h x)) x = (deriv (g) -deriv (h) ) x :=\nbegin\n  apply deriv_sub (hgdiff) (hhdiff),\nend\n\n\nlemma factors_sq_equal (x : \u211d):  \n(fun_Z x) * (x*(fun_A x) + fun_B x - (1/6)*(x+1)*(deriv fun_B x))^2 = ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x)+((fun_A x)*(deriv fun_Z x)/2))-x*(fun_B x)-(fun_A x)*(fun_Z x))^2:=\nbegin\n  have h1 : fun_A = (\u03bb (x : \u211d), 52*x^4 + 92*x^3 + 30*x^2 -22*x - 11),\n    refl,\n  have h2 : fun_B = (\u03bb (x : \u211d), 112*x^6 + 360*x^5 + 624*x^4 + 772*x^3 + 612*x^2 + 258*x + 43),\n    refl,\n  have h3 : fun_Z = (\u03bb (x : \u211d), 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1),\n    refl,\n  rw [h1,h2,h3],\n  simp,\n  ring_nf,\nend\n\nlemma factors_equal (x : \u211d) (h: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1):  \n(fun_Y x) * (x*(fun_A x) + fun_B x - (1/6)*(x+1)*(deriv fun_B x)) = ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x)+((fun_A x)*(deriv fun_Z x)/2))-x*(fun_B x)-(fun_A x)*(fun_Z x)):=\nbegin\n  have h1 : fun_A = (\u03bb (x : \u211d), 52*x^4 + 92*x^3 + 30*x^2 -22*x - 11),\n    refl,\n  have h2 : fun_B = (\u03bb (x : \u211d), 112*x^6 + 360*x^5 + 624*x^4 + 772*x^3 + 612*x^2 + 258*x + 43),\n    refl,\n  have h3 : fun_Y = (\u03bb (x : \u211d), sqrt (4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1)),\n    refl,\n  have h4 : fun_Z = (\u03bb (x : \u211d), 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1),\n    refl,\n  have h5:  (fun_Z x) * (x*(fun_A x) + fun_B x - (1/6)*(x+1)*(deriv fun_B x))^2 = ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x)+((fun_A x)*(deriv fun_Z x)/2))-x*(fun_B x)-(fun_A x)*(fun_Z x))^2,\n    exact factors_sq_equal x,\n  have h: (fun_Z x) * (x*(fun_A x) + fun_B x - (1/6)*(x+1)*(deriv fun_B x))^2 = 0,\n    rw [h1,h2,h4],\n    simp,\n    ring_nf,\n    right,\n    norm_num,\n  rw h at h5,\n  symmetry' at h5,\n  rw sq_eq_zero_iff at h5, \n  rw [h5,h1,h2,h3],\n  simp,\n  ring_nf,\n  right,\n  norm_num,\nend\n\nlemma expanding_factors_add_equal (x : \u211d) (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1):  \nx*(fun_A x)*(fun_Y x)+x*(fun_B x) + (fun_A x)*(fun_Z x) + (fun_B x)*(fun_Y x) = (1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)) + (1/6)*(x+1)*(deriv fun_B x)*(fun_Y x) :=\nbegin\n  have h:  (fun_Y x) * (x*(fun_A x) + fun_B x - (1/6)*(x+1)*(deriv fun_B x)) = ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x)+((fun_A x)*(deriv fun_Z x)/2))-x*(fun_B x)-(fun_A x)*(fun_Z x)),\n    exact factors_equal x hgtzero,\n  have h1:  (fun_Y x) * (x*(fun_A x) + fun_B x - (1/6)*(x+1)*(deriv fun_B x)) =(fun_Y x) * (x*(fun_A x)) + (fun_Y x) *(fun_B x) - (fun_Y x) * (1/6)*(x+1)*(deriv fun_B x),\n      unfold fun_A,\n      unfold fun_B,\n      unfold fun_Y,\n      simp,\n      ring,\n  rw [h1,sub_eq_add_neg] at h,\n  rw add_comm (x.fun_Y * (x * x.fun_A) + x.fun_Y * x.fun_B) (-(x.fun_Y * (1 / 6) * (x + 1) * deriv fun_B x)) at h,\n  rw [neg_add_eq_iff_eq_add,sub_eq_add_neg,\u2190 add_assoc,\u2190 add_neg_eq_iff_eq_add] at h,\n  rw sub_eq_add_neg (1 / 6 * (x + 1) * (deriv fun_A x * x.fun_Z + x.fun_A * deriv fun_Z x / 2))  (x * x.fun_B) at h,\n  rw [\u2190 add_assoc,\u2190 add_neg_eq_iff_eq_add,neg_neg,neg_neg] at h,\n  have h2: x.fun_Y * (x * x.fun_A) + x.fun_Y * x.fun_B + x.fun_A * x.fun_Z + x * x.fun_B = x * x.fun_A * x.fun_Y + x * x.fun_B + x.fun_A * x.fun_Z + x.fun_B * x.fun_Y,\n    ring,\n  have h3: x.fun_Y * (1 / 6) * (x + 1) * deriv fun_B x + 1 / 6 * (x + 1) * (deriv fun_A x * x.fun_Z + x.fun_A * deriv fun_Z x / 2) = 1 / 6 * (x + 1) * (deriv fun_A x * x.fun_Z + x.fun_A * deriv fun_Z x / 2) + 1 / 6 * (x + 1) * deriv fun_B x * x.fun_Y,\n    ring,\n  rw [h2,h3] at h,\n  exact h,\nend\n\nlemma factoring_equal (x : \u211d) (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1):  \n(x+ fun_Y x)*((fun_A x)*(fun_Y x)+fun_B x) = (1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x))  :=\nbegin\n  have h:   x*(fun_A x)*(fun_Y x)+x*(fun_B x) + (fun_A x)*(fun_Z x) + (fun_B x)*(fun_Y x) = (1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)) + (1/6)*(x+1)*(deriv fun_B x)*(fun_Y x) ,\n    exact expanding_factors_add_equal x hgtzero,\n  have h1: x*(fun_A x)*(fun_Y x)+x*(fun_B x) + (fun_A x)*(fun_Z x) + (fun_B x)*(fun_Y x) = (x+ fun_Y x)*((fun_A x)*(fun_Y x)+fun_B x),\n    ring_nf,\n    rw \u2190 fun_Z_eq_fun_Y_sq,\n    exact hgtzero,\n  rw h1 at h,\n  have h2:  (1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x)) = (1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)) + (1/6)*(x+1)*(deriv fun_B x)*(fun_Y x) ,\n    ring_nf,\n  rw \u2190 h2 at h,\n  exact h,\nend\n\nlemma division_equal (x : \u211d) (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1)\n(hnotzeroden : (fun_A x) *(fun_Y x)+(fun_B x) \u2260 0) :  \n(x+ fun_Y x)= ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x)))/((fun_A x)*(fun_Y x)+fun_B x)  :=\nbegin\n  have h:   (x+ fun_Y x)*((fun_A x)*(fun_Y x)+fun_B x) = (1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x)),\n    exact factoring_equal x hgtzero,\n  symmetry' at h,\n  rw \u2190  div_eq_iff hnotzeroden at h,\n  symmetry' at h,\n  exact h,\nend\n\nlemma add_equal (x : \u211d) (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1)\n(hnotzeroden : (fun_A x) *(fun_Y x)+(fun_B x) \u2260 0) :  \nx= ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x)))/((fun_A x)*(fun_Y x)+fun_B x) + (- fun_Y x ):=\nbegin\n  have h:   (x+ fun_Y x)= ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x)))/((fun_A x)*(fun_Y x)+fun_B x),\n    exact division_equal x hgtzero hnotzeroden,\n  rw \u2190 eq_add_neg_iff_add_eq at h,\n  exact h,\nend\n\nlemma mul_Y_equal (x : \u211d)  (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1)\n(hnotzeroinsidey: 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1 \u2260 0) :  \n((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x)))/((fun_A x)*(fun_Y x)+fun_B x)= (1/6)*(x+1)*(fun_Y x)*(((deriv fun_A x)*(fun_Y x) + ((fun_A x)*(deriv fun_Z x)/(2*(fun_Y x)))+ (deriv fun_B x))/((fun_A x)*(fun_Y x)+fun_B x)):=\nbegin\n  have h: deriv fun_A x * x.fun_Z + x.fun_A * deriv fun_Z x / 2 + deriv fun_B x * x.fun_Y = (x.fun_Y)* (deriv fun_A x * x.fun_Y + (x.fun_A) *(deriv fun_Z x) / (2*(fun_Y x)) + deriv fun_B x),\n    rw [fun_Z_eq_fun_Y_sq,mul_add,mul_add,\u2190 mul_div_assoc],\n    rw \u2190  mul_assoc (x.fun_Y) (x.fun_A) (deriv fun_Z x),\n    rw mul_comm (x.fun_Y) (x.fun_A),\n    rw mul_assoc (x.fun_A) (x.fun_Y) (deriv fun_Z x),\n    rw mul_comm (x.fun_Y) (deriv fun_Z x),\n    rw \u2190 mul_assoc (x.fun_A) (deriv fun_Z x) (x.fun_Y),\n    rw mul_div_assoc (x.fun_A * deriv fun_Z x),\n    rw mul_comm (2) (x.fun_Y),\n    rw div_mul_eq_div_mul_one_div (x.fun_Y) (x.fun_Y) (2),\n    have hnotzero: x.fun_Y\u2260 0,\n      unfold fun_Y,\n      rw sqrt_ne_zero,\n      exact hnotzeroinsidey,\n      exact hgtzero,\n    rw [div_self hnotzero,one_mul,\u2190 mul_div_assoc (x.fun_A * deriv fun_Z x),mul_one],\n    ring_nf,\n  exact hgtzero,\n  rw [h,mul_div_assoc,mul_div_assoc,mul_assoc (1 / 6 * (x + 1))],\nend\n\nlemma divide_by_x_plus_1_mul_Y (x : \u211d) (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1) (hnotzeroden : (fun_A x) *(fun_Y x)+(fun_B x) \u2260 0)\n(hnotzeroinsidey: 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1 \u2260 0) (hnotzeroxplus1 : x+1 \u2260 0) :  \nx/((x+1)*(fun_Y x))=(1/6)*(((deriv fun_A x)*(fun_Y x) + ((fun_A x)*(deriv fun_Z x)/(2*(fun_Y x)))+ (deriv fun_B x))/((fun_A x)*(fun_Y x)+fun_B x)) + (- (1/(x+1))):=\nbegin\n  have h: x= ((1/6)*(x+1)*((deriv fun_A x)*(fun_Z x) + ((fun_A x)*(deriv fun_Z x)/2)+ (deriv fun_B x)*(fun_Y x)))/((fun_A x)*(fun_Y x)+fun_B x) + (- fun_Y x ),\n    exact add_equal x hgtzero hnotzeroden,\n  rw [mul_Y_equal x,\u2190 one_mul (-x.fun_Y)] at h,\n  have hnotzero: (x+1)\u22600,\n    exact hnotzeroxplus1,\n  nth_rewrite 4 \u2190 div_self hnotzero at h,\n  rw [div_mul_eq_mul_div (x + 1),mul_assoc (1 / 6) (x + 1) (x.fun_Y),mul_comm (1 / 6) ((x + 1) * x.fun_Y)] at h,\n  have h2: (x + 1) * -x.fun_Y = (x + 1) * (x.fun_Y) * (-1),\n    ring_nf,\n  rw [h2,mul_div_assoc ((x + 1) * x.fun_Y),mul_assoc,\u2190 mul_add] at h,\n  have hnotzeroy: x.fun_Y \u2260 0,\n    unfold fun_Y,\n    rw sqrt_ne_zero,\n    exact hnotzeroinsidey,\n    exact hgtzero,\n  have h3: (x + 1) * x.fun_Y \u2260 0,\n    apply mul_ne_zero hnotzeroxplus1 hnotzeroy,\n  rw [mul_comm ((x + 1) * x.fun_Y),\u2190  div_eq_iff h3,neg_div] at h,\n  exact h,\n  exact hgtzero,\n  exact hnotzeroinsidey,\nend\n\nlemma simplify_our_expression (x : \u211d) (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1) (hnotzeroden : (fun_A x) *(fun_Y x)+(fun_B x) \u2260 0)\n(hnotzeroinsidey: 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1 \u2260 0)  (hnotzeroxplus1 : x+1 \u2260 0):  \nx/((x+1)*(fun_Y x))=(1/6)*(((deriv fun_A x)*(fun_Y x) + ((fun_A x)*(deriv fun_Y x))+ (deriv fun_B x))/((fun_A x)*(fun_Y x)+fun_B x)) + (- (1/(x+1))):=\nbegin\n  have h: x/((x+1)*(fun_Y x))=(1/6)*(((deriv fun_A x)*(fun_Y x) + ((fun_A x)*(deriv fun_Z x)/(2*(fun_Y x)))+ (deriv fun_B x))/((fun_A x)*(fun_Y x)+fun_B x)) + (- (1/(x+1))),\n    exact divide_by_x_plus_1_mul_Y x hgtzero hnotzeroden hnotzeroinsidey hnotzeroxplus1,\n  rw deriv_Y x hnotzeroinsidey,\n  rw mul_div_assoc at h,\n  exact h,\n  exact hnotzeroinsidey,\nend\n\nlemma deriv_log_x_plus_1 (x : \u211d) (hnotzero: x+1 \u2260 0): deriv (\u03bb (x : \u211d), real.log(x+1)) x = 1/(x+1) :=\nbegin\n  rw [deriv.comp,real.deriv_log,div_eq_mul_inv,mul_comm],\n  simp only [deriv_add_const', deriv_id''],\n  simp only [differentiable_at_log_iff, ne.def],\n  exact hnotzero,\n  simp only [differentiable_at_add_const_iff, differentiable_at_id'],\nend\n\nlemma deriv_alternative_function (x : \u211d) (a : \u211d \u2192 \u211d) (y : \u211d \u2192 \u211d) (b : \u211d \u2192 \u211d) \n(hnotzeroden : (a x) *(y x)+(b x) \u2260 0) (hnotzeroxplus1 : x+1 \u2260 0) \n(hadiff : differentiable_at \u211d (\u03bb x, (a) x) x)\n(hydiff : differentiable_at \u211d (\u03bb x, (y) x) x)\n(hbdiff : differentiable_at \u211d (\u03bb x, b x) x): \nderiv (\u03bb (x : \u211d), (1/6)*real.log((a x) *(y x)+(b x)) - real.log(x+1)) x = (1/6)*((deriv (a)*y + a*deriv (y)+deriv (b) ) x) / ((a x) *(y x)+(b x) )  - 1 /(1+x):=\nbegin\n  rw [deriv_sub,pi.sub_apply,deriv_const_mul,deriv_our_function],\n  simp only [one_div, pi.add_apply, pi.mul_apply],\n  rw deriv_log_x_plus_1,\n  simp only [one_div],\n  rw [mul_div_assoc,add_comm (1) (x)],\n  exact hnotzeroxplus1,\n  exact hnotzeroden,\n  exact hadiff,\n  exact hydiff,\n  exact hbdiff,\n  apply differentiable_at.log,\n  apply differentiable_at.add,\n  apply differentiable_at.mul,\n  exact hadiff,\n  exact hydiff,\n  exact hbdiff,\n  exact hnotzeroden,\n  exact differentiable_at_id,\n  apply differentiable_at.const_mul,\n  apply differentiable_at.log,\n  apply differentiable_at.add,\n  apply differentiable_at.mul,\n  exact hadiff,\n  exact hydiff,\n  exact hbdiff,\n  exact hnotzeroden,\n  apply differentiable_at.log,\n  simp only [differentiable_at_add_const_iff, differentiable_at_id'],\n  exact hnotzeroxplus1,\nend\n\nlemma deriv_alt_function_w_simps (x : \u211d)  (hgtzero: 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1) (hnotzeroden : (fun_A x) *(fun_Y x)+(fun_B x) \u2260 0)\n(hnotzeroinsidey: 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1 \u2260 0)  (hnotzeroxplus1 : x+1 \u2260 0)\n(hadiff : differentiable_at \u211d (\u03bb x, (fun_A) x) x)\n(hydiff : differentiable_at \u211d (\u03bb x, (fun_Y) x) x)\n(hbdiff : differentiable_at \u211d (\u03bb x, (fun_B) x) x): \nderiv (\u03bb (x : \u211d), (1/6)*real.log((fun_A x) *(fun_Y x)+(fun_B x)) - real.log(x+1)) x = x/ ((1+x)*(fun_Y x)):=\nbegin\n  rw deriv_alternative_function,\n  have h1: (1/6)*(((deriv fun_A x)*(fun_Y x) + ((fun_A x)*(deriv fun_Y x))+ (deriv fun_B x))/((fun_A x)*(fun_Y x)+fun_B x)) = 1 / 6 * ((deriv (\u03bb (x : \u211d), x.fun_A) * \u03bb (x : \u211d), x.fun_Y) + (\u03bb (x : \u211d), x.fun_A) * deriv (\u03bb (x : \u211d), x.fun_Y) + deriv (\u03bb (x : \u211d), x.fun_B)) x / (x.fun_A * x.fun_Y + x.fun_B),\n    simp,\n    rw mul_div_assoc,\n  rw [\u2190  h1,sub_eq_add_neg,add_comm (1) (x),\u2190  simplify_our_expression x hgtzero hnotzeroden hnotzeroinsidey hnotzeroxplus1],\n  exact hnotzeroden,\n  exact hnotzeroxplus1,\n  exact hadiff,\n  exact hydiff,\n  exact hbdiff,\nend\n\nlemma antideriv_alt_function_within : has_antideriv_within (\u03bb (x : \u211d), x/ ((1+x)*(fun_Y x))) (\u03bb x,  (1/6)*real.log((fun_A x) *(fun_Y x)+(fun_B x))- real.log(x+1)) {x| (fun_A x) *(fun_Y x)+(fun_B x) \u2260 0 \u2227 x+1 \u2260 0 \u2227 4*x^4 + 8*x^3 + 12*x^2 + 8*x + 1 \u2260 0 \u2227 0 \u2264 4 * x ^ 4 + 8 * x ^ 3 + 12 * x ^ 2 + 8 * x + 1} :=\nbegin\n  unfold has_antideriv_within,\n  intro x,\n  intro hset,\n  have h: differentiable_at \u211d (\u03bb x,  (1/6)*real.log((fun_A x) *(fun_Y x)+(fun_B x)) - real.log(x+1)) x,\n    apply differentiable_at.sub,\n    apply differentiable_at.const_mul,\n    apply differentiable_at.log,\n    unfold fun_A,\n    unfold fun_B,\n    have hy: differentiable_at \u211d (\u03bb x,  fun_Y x) x,\n      apply differentiable_at.sqrt,\n      simp only [differentiable_at.add, differentiable_at.mul, differentiable_at_const, differentiable_at.pow, differentiable_at_id'],\n      cases hset with hset1 hset2,\n      cases hset2 with hset2 hset3,\n      cases hset3 with hset3 hset4,\n      exact hset3,\n    apply differentiable_at.add,\n    apply differentiable_at.mul,\n    simp only [differentiable_at.sub, differentiable_at.add, differentiable_at.mul, differentiable_at_const, differentiable_at.pow,\n  differentiable_at_id'],\n    exact hy,\n    simp only [differentiable_at.add, differentiable_at.mul, differentiable_at_const, differentiable_at.pow, differentiable_at_id'],\n    cases hset with hset1 hset2,\n    exact hset1,\n    apply differentiable_at.comp,\n    apply differentiable_at.log,\n    apply differentiable_at_id,\n    cases hset with hset1 hset2,\n    cases hset2 with hset2 hset3,\n    exact hset2,\n    simp only [differentiable_at_add_const_iff, differentiable_at_id'], \n  have h1:= differentiable_at.has_deriv_at h,\n  convert h1,\n  have h2:   x/ ((1+x)*(fun_Y x)) = deriv (\u03bb (x : \u211d), (1/6)*real.log((fun_A x) *(fun_Y x)+(fun_B x)) - real.log(x+1)) x ,\n    symmetry,\n    cases hset with hset1 hset2,\n    cases hset2 with hset2 hset3,\n    cases hset3 with hset3 hset4,\n    apply deriv_alt_function_w_simps x hset4 hset1 hset3 hset2,\n  unfold fun_A,\n  simp only [differentiable_at.sub, differentiable_at.add, differentiable_at.mul, differentiable_at_const, differentiable_at.pow,\n  differentiable_at_id'],\n  unfold fun_Y,\n  apply differentiable_at.sqrt,\n  simp only [differentiable_at.add, differentiable_at.mul, differentiable_at_const, differentiable_at.pow, differentiable_at_id'],\n  exact hset3,\n  unfold fun_B,\n  simp only [differentiable_at.add, differentiable_at.mul, differentiable_at_const, differentiable_at.pow, differentiable_at_id'],\n  exact h2,\nend\n\n\n\nend real\n\n/- !!!RENAME THINGS!!! -/", "meta": {"author": "rtertr", "repo": "Lean-CAP", "sha": "d1ac0ed855947f93c9cd14d9858ffe9979b26d18", "save_path": "github-repos/lean/rtertr-Lean-CAP", "path": "github-repos/lean/rtertr-Lean-CAP/Lean-CAP-d1ac0ed855947f93c9cd14d9858ffe9979b26d18/Clean total.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7253558221646511}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Johan Commelin\n-/\nimport group_theory.free_abelian_group\n\n/-!\n# Free rings\n\nThe theory of the free ring over a type.\n\n## Main definitions\n\n* `free_ring \u03b1` : the free (not commutative in general) ring over a type.\n* `lift (f : \u03b1 \u2192 R)` : the ring hom `free_ring \u03b1 \u2192+* R` induced by `f`.\n* `map (f : \u03b1 \u2192 \u03b2)` : the ring hom `free_ring \u03b1 \u2192+* free_ring \u03b2` induced by `f`.\n\n## Implementation details\n\n`free_ring \u03b1` is implemented as the free abelian group over the free monoid on `\u03b1`.\n\n## Tags\n\nfree ring\n\n-/\n\nuniverses u v\n\n/-- The free ring over a type `\u03b1`. -/\n@[derive [ring, inhabited]]\ndef free_ring (\u03b1 : Type u) : Type u :=\nfree_abelian_group $ free_monoid \u03b1\n\nnamespace free_ring\n\nvariables {\u03b1 : Type u}\n\n/-- The canonical map from \u03b1 to `free_ring \u03b1`. -/\ndef of (x : \u03b1) : free_ring \u03b1 :=\nfree_abelian_group.of (free_monoid.of x)\n\nlemma of_injective : function.injective (of : \u03b1 \u2192 free_ring \u03b1) :=\nfree_abelian_group.of_injective.comp free_monoid.of_injective\n\n@[elab_as_eliminator] protected lemma induction_on\n  {C : free_ring \u03b1 \u2192 Prop} (z : free_ring \u03b1)\n  (hn1 : C (-1)) (hb : \u2200 b, C (of b))\n  (ha : \u2200 x y, C x \u2192 C y \u2192 C (x + y))\n  (hm : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) : C z :=\nhave hn : \u2200 x, C x \u2192 C (-x), from \u03bb x ih, neg_one_mul x \u25b8 hm _ _ hn1 ih,\nhave h1 : C 1, from neg_neg (1 : free_ring \u03b1) \u25b8 hn _ hn1,\nfree_abelian_group.induction_on z\n  (add_left_neg (1 : free_ring \u03b1) \u25b8 ha _ _ hn1 h1)\n  (\u03bb m, list.rec_on m h1 $ \u03bb a m ih, hm _ _ (hb a) ih)\n  (\u03bb m ih, hn _ ih)\n  ha\n\nsection lift\n\nvariables {R : Type v} [ring R] (f : \u03b1 \u2192 R)\n\n/-- The ring homomorphism `free_ring \u03b1 \u2192+* R` induced from a map `\u03b1 \u2192 R`. -/\ndef lift : (\u03b1 \u2192 R) \u2243 (free_ring \u03b1 \u2192+* R) :=\nfree_monoid.lift.trans free_abelian_group.lift_monoid\n\n@[simp] lemma lift_of (x : \u03b1) : lift f (of x) = f x :=\ncongr_fun (lift.left_inv f) x\n\n@[simp] lemma lift_comp_of (f : free_ring \u03b1 \u2192+* R) : lift (f \u2218 of) = f :=\nlift.right_inv f\n\n@[ext]\nlemma hom_ext \u2983f g : free_ring \u03b1 \u2192+* R\u2984 (h : \u2200 x, f (of x) = g (of x)) :\n  f = g :=\nlift.symm.injective (funext h)\n\nend lift\n\nvariables {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2)\n\n/-- The canonical ring homomorphism `free_ring \u03b1 \u2192+* free_ring \u03b2` generated by a map `\u03b1 \u2192 \u03b2`. -/\ndef map : free_ring \u03b1 \u2192+* free_ring \u03b2 :=\nlift $ of \u2218 f\n\n@[simp]\nlemma map_of (x : \u03b1) : map f (of x) = of (f x) := lift_of _ _\n\nend free_ring\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/free_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7252649646363104}}
{"text": "import data.nat.basic\n\nopen fin nat\n\nnamespace fin\n\nvariable {n : \u2115}\n\n/-- The greatest value of `fin (n+1)` -/\ndef last (n : \u2115) : fin (n+1) := \u27e8_, n.lt_succ_self\u27e9\n\ntheorem le_last (i : fin (n+1)) : i \u2264 last n :=\nle_of_lt_succ i.is_lt\n\n/-- Embedding of `fin n` in `fin (n+1)` -/\ndef raise (k : fin n) : fin (n + 1) := \u27e8val k, lt_succ_of_lt (is_lt k)\u27e9\n\ndef add_nat {n} (i : fin n) (k) : fin (n + k) :=\n\u27e8i.1 + k, nat.add_lt_add_right i.2 _\u27e9\n\n@[simp] lemma succ_val (j : fin n) : j.succ.val = j.val.succ :=\nby cases j; simp [fin.succ]\n\n@[simp] lemma pred_val (j : fin (n+1)) (h : j \u2260 0) : (j.pred h).val = j.val.pred :=\nby cases j; simp [fin.pred]\n\n@[simp] protected lemma eta (a : fin n) (h : a.1 < n) : (\u27e8a.1, h\u27e9 : fin n) = a :=\nby cases a; refl\n\ninstance {n : \u2115} : decidable_linear_order (fin n) :=\n{ le_refl := \u03bb a, @le_refl \u2115 _ _,\n  le_trans := \u03bb a b c, @le_trans \u2115 _ _ _ _,\n  le_antisymm := \u03bb a b ha hb, fin.eq_of_veq $ le_antisymm ha hb,\n  le_total := \u03bb a b, @le_total \u2115 _ _ _,\n  lt_iff_le_not_le := \u03bb a b, @lt_iff_le_not_le \u2115 _ _ _,\n  decidable_le := fin.decidable_le,\n  ..fin.has_le,\n  ..fin.has_lt }\n\nend fin\n\ntheorem eq_of_lt_succ_of_not_lt {a b : \u2115} (h1 : a < b + 1) (h2 : \u00ac a < b) : a = b :=\nhave h3 : a \u2264 b, from le_of_lt_succ h1,\nor.elim (eq_or_lt_of_not_lt h2) (\u03bb h, h) (\u03bb h, absurd h (not_lt_of_ge h3))\n\ninstance fin_to_nat (n : \u2115) : has_coe (fin n) nat := \u27e8fin.val\u27e9\ninstance fin_to_int (n : \u2115) : has_coe (fin n) int := \u27e8\u03bb k, \u2191(fin.val k)\u27e9\n\nvariables {n : \u2115} {a b : fin n}\n\nprotected theorem fin.succ.inj (p : fin.succ a = fin.succ b) : a = b :=\nby cases a; cases b; exact eq_of_veq (nat.succ.inj (veq_of_eq p))\n\n@[elab_as_eliminator] def fin.succ_rec\n  {C : \u2200 n, fin n \u2192 Sort*}\n  (H0 : \u2200 n, C (succ n) 0)\n  (Hs : \u2200 n i, C n i \u2192 C (succ n) i.succ) : \u2200 {n : \u2115} (i : fin n), C n i\n| 0        i           := i.elim0\n| (succ n) \u27e80, _\u27e9      := H0 _\n| (succ n) \u27e8succ i, h\u27e9 := Hs _ _ (fin.succ_rec \u27e8i, lt_of_succ_lt_succ h\u27e9)\n\n@[elab_as_eliminator] def fin.succ_rec_on {n : \u2115} (i : fin n)\n  {C : \u2200 n, fin n \u2192 Sort*}\n  (H0 : \u2200 n, C (succ n) 0)\n  (Hs : \u2200 n i, C n i \u2192 C (succ n) i.succ) : C n i :=\ni.succ_rec H0 Hs\n\n@[simp] theorem fin.succ_rec_on_zero\n  {C : \u2200 n, fin n \u2192 Sort*} {H0 Hs} (n) :\n  @fin.succ_rec_on (succ n) 0 C H0 Hs = H0 n := rfl\n\n@[simp] theorem fin.succ_rec_on_succ\n  {C : \u2200 n, fin n \u2192 Sort*} {H0 Hs} {n} (i : fin n) :\n  @fin.succ_rec_on (succ n) i.succ C H0 Hs = Hs n i (fin.succ_rec_on i H0 Hs) :=\nby cases i; refl\n\n@[elab_as_eliminator] def fin.cases {n} {C : fin (succ n) \u2192 Sort*}\n  (H0 : C 0) (Hs : \u2200 i : fin n, C (i.succ)) :\n  \u2200 (i : fin (succ n)), C i\n| \u27e80, h\u27e9 := H0\n| \u27e8succ i, h\u27e9 := Hs \u27e8i, lt_of_succ_lt_succ h\u27e9\n\n@[simp] theorem fin.cases_zero\n  {n} {C : fin (succ n) \u2192 Sort*} {H0 Hs} :\n  @fin.cases n C H0 Hs 0 = H0 := rfl\n\n@[simp] theorem fin.cases_succ\n  {n} {C : fin (succ n) \u2192 Sort*} {H0 Hs} (i : fin n) :\n  @fin.cases n C H0 Hs i.succ = Hs i :=\nby cases i; refl\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382023207901, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.725264958219524}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Benjamin Davidson\n\nThe `even` and `odd` predicates on the integers.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.int.modeq\nimport Mathlib.data.nat.parity\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\nnamespace int\n\n\n@[simp] theorem mod_two_ne_one {n : \u2124} : \u00acn % bit0 1 = 1 \u2194 n % bit0 1 = 0 := sorry\n\ntheorem mod_two_ne_zero {n : \u2124} : \u00acn % bit0 1 = 0 \u2194 n % bit0 1 = 1 := sorry\n\n@[simp] theorem even_coe_nat (n : \u2115) : even \u2191n \u2194 even n := sorry\n\ntheorem even_iff {n : \u2124} : even n \u2194 n % bit0 1 = 0 := sorry\n\ntheorem odd_iff {n : \u2124} : odd n \u2194 n % bit0 1 = 1 := sorry\n\ntheorem not_even_iff {n : \u2124} : \u00aceven n \u2194 n % bit0 1 = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u00aceven n \u2194 n % bit0 1 = 1)) (propext even_iff)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u00acn % bit0 1 = 0 \u2194 n % bit0 1 = 1)) (propext mod_two_ne_zero)))\n      (iff.refl (n % bit0 1 = 1)))\n\ntheorem not_odd_iff {n : \u2124} : \u00acodd n \u2194 n % bit0 1 = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u00acodd n \u2194 n % bit0 1 = 0)) (propext odd_iff)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u00acn % bit0 1 = 1 \u2194 n % bit0 1 = 0)) (propext mod_two_ne_one)))\n      (iff.refl (n % bit0 1 = 0)))\n\ntheorem even_iff_not_odd {n : \u2124} : even n \u2194 \u00acodd n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (even n \u2194 \u00acodd n)) (propext not_odd_iff)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (even n \u2194 n % bit0 1 = 0)) (propext even_iff))) (iff.refl (n % bit0 1 = 0)))\n\n@[simp] theorem odd_iff_not_even {n : \u2124} : odd n \u2194 \u00aceven n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (odd n \u2194 \u00aceven n)) (propext not_even_iff)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (odd n \u2194 n % bit0 1 = 1)) (propext odd_iff))) (iff.refl (n % bit0 1 = 1)))\n\ntheorem even_or_odd (n : \u2124) : even n \u2228 odd n :=\n  or.imp_right (iff.mpr odd_iff_not_even) (em (even n))\n\ntheorem even_or_odd' (n : \u2124) : \u2203 (k : \u2124), n = bit0 1 * k \u2228 n = bit0 1 * k + 1 := sorry\n\ntheorem even_xor_odd (n : \u2124) : xor (even n) (odd n) :=\n  or.dcases_on (even_or_odd n) (fun (h : even n) => Or.inl { left := h, right := iff.mp even_iff_not_odd h })\n    fun (h : odd n) => Or.inr { left := h, right := iff.mp odd_iff_not_even h }\n\ntheorem even_xor_odd' (n : \u2124) : \u2203 (k : \u2124), xor (n = bit0 1 * k) (n = bit0 1 * k + 1) := sorry\n\ntheorem ne_of_odd_sum {x : \u2124} {y : \u2124} (h : odd (x + y)) : x \u2260 y := sorry\n\n@[simp] theorem two_dvd_ne_zero {n : \u2124} : \u00acbit0 1 \u2223 n \u2194 n % bit0 1 = 1 :=\n  not_even_iff\n\nprotected instance even.decidable_pred : decidable_pred even :=\n  fun (n : \u2124) => decidable_of_decidable_of_iff (int.decidable_eq (n % bit0 1) 0) sorry\n\nprotected instance decidable_pred_odd : decidable_pred odd :=\n  fun (n : \u2124) => decidable_of_decidable_of_iff not.decidable sorry\n\n@[simp] theorem even_zero : even 0 :=\n  Exists.intro 0 (of_as_true trivial)\n\n@[simp] theorem not_even_one : \u00aceven 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u00aceven 1)) (propext even_iff))) one_ne_zero\n\n@[simp] theorem even_bit0 (n : \u2124) : even (bit0 n) :=\n  Exists.intro n\n    (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 n = bit0 1 * n)) (bit0.equations._eqn_1 n)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (n + n = bit0 1 * n)) (two_mul n))) (Eq.refl (n + n))))\n\ntheorem even_add {m : \u2124} {n : \u2124} : even (m + n) \u2194 (even m \u2194 even n) := sorry\n\ntheorem even_neg {n : \u2124} : even (-n) \u2194 even n := sorry\n\n@[simp] theorem not_even_bit1 (n : \u2124) : \u00aceven (bit1 n) := sorry\n\ntheorem even_sub {m : \u2124} {n : \u2124} : even (m - n) \u2194 (even m \u2194 even n) := sorry\n\ntheorem even_mul {m : \u2124} {n : \u2124} : even (m * n) \u2194 even m \u2228 even n := sorry\n\ntheorem even_pow {m : \u2124} {n : \u2115} : even (m ^ n) \u2194 even m \u2227 n \u2260 0 := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/int/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7252649548006517}}
{"text": "-- Copyright \u00a9 2019 Fran\u00e7ois G. Dorais. All rights reserved.\n-- Released under Apache 2.0 license as described in the file LICENSE.\n\nimport .basic\nimport .group \nimport .monoid\n\nset_option default_priority 0\n\nnamespace algebra\n\nsignature semiring (\u03b1 : Type*) := \n(mul : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(one : \u03b1)\n(add : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(zero : \u03b1)\n\nnamespace semiring_sig\nvariables {\u03b1 : Type*} (s : semiring_sig \u03b1)\n\n@[signature_instance]\ndef to_add_monoid : monoid_sig \u03b1 :=\n{ op := s.add\n, id := s.zero\n}\n\n@[signature_instance]\ndef to_mul_monoid : monoid_sig \u03b1 :=\n{ op := s.mul\n, id := s.one\n}\n\nend semiring_sig\n\nvariables {\u03b1 : Type*} (s : semiring_sig \u03b1)\nlocal notation `\ud835\udfd8` := s.zero\nlocal notation `\ud835\udfd9` := s.one\nlocal infix + := s.add\nlocal infix \u2219 := s.mul\n\n@[theory]\nclass semiring : Prop := intro ::\n(add_associative : identity.op_associative s.add)\n(add_commutative : identity.op_commutative s.add)\n(add_right_identity : identity.op_right_identity s.add s.zero)\n(mul_associative : identity.op_associative s.mul)\n(mul_left_identity : identity.op_left_identity s.mul s.one)\n(mul_right_identity : identity.op_right_identity s.mul s.one)\n(mul_left_distributive : identity.op_left_distributive s.mul s.add)\n(mul_right_distributive : identity.op_right_distributive s.mul s.add)\n(mul_left_null : identity.op_left_fixpoint s.mul s.zero)\n(mul_right_null : identity.op_right_fixpoint s.mul s.zero)\n\nnamespace semiring\nvariable [i : semiring s]\ninclude i\n\ninstance to_add_comm_monoid : comm_monoid s.to_add_monoid := comm_monoid.infer _\n\ninstance to_mul_monoid : monoid s.to_mul_monoid := monoid.infer _\n\nend semiring\n\n@[theory]\nclass comm_semiring : Prop := intro ::\n(add_associative : identity.op_associative s.add)\n(add_commutative : identity.op_commutative s.add)\n(add_right_identity : identity.op_right_identity s.add s.zero)\n(mul_associative : identity.op_associative s.mul)\n(mul_commutative : identity.op_commutative s.mul)\n(mul_right_identity : identity.op_right_identity s.mul s.one)\n(mul_right_null : identity.op_right_fixpoint s.mul s.zero)\n(mul_right_distributive : identity.op_right_distributive s.mul s.add)\n\nnamespace comm_semiring\nvariable [i : comm_semiring s]\ninclude i\n\n@[identity_instance]\ntheorem mul_left_identity : identity.op_left_identity s.mul s.one :=\n\u03bb x, calc \ud835\udfd9 \u2219 x\n= x \u2219 \ud835\udfd9 : by rw op_commutative s.mul ...\n= x : by rw op_right_identity s.mul\n\n@[identity_instance]\ntheorem mul_left_null : identity.op_left_fixpoint s.mul s.zero :=\n\u03bb x, calc \ud835\udfd8 \u2219 x\n= x \u2219 \ud835\udfd8 : by rw op_commutative s.mul ...\n= \ud835\udfd8 : by rw op_right_fixpoint s.mul\n\n@[identity_instance]\ntheorem mul_left_distributive : identity.op_left_distributive s.mul s.add :=\n\u03bb x y z, calc (x + y) \u2219 z\n= z \u2219 (x + y) : by rw op_commutative s.mul ...\n= z \u2219 x + z \u2219 y : by rw op_right_distributive s.mul s.add ...\n= x \u2219 z + z \u2219 y : by rw op_commutative s.mul x ...\n= x \u2219 z + y \u2219 z : by rw op_commutative s.mul y\n\ninstance to_semiring : semiring s := semiring.infer _\n\ninstance to_mul_monoid : comm_monoid s.to_mul_monoid := comm_monoid.infer _\n\nend comm_semiring\n\nend algebra", "meta": {"author": "fgdorais", "repo": "lean-universal", "sha": "9259b0f7fb3aa83a9e0a7a3eaa44c262e42cc9b1", "save_path": "github-repos/lean/fgdorais-lean-universal", "path": "github-repos/lean/fgdorais-lean-universal/lean-universal-9259b0f7fb3aa83a9e0a7a3eaa44c262e42cc9b1/src/algebra/theories/semiring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7252468018426363}}
{"text": "import game.sets.sets_level05 -- hide\nimport tactic -- hide\n\n\nnamespace xena -- hide\n\nvariable X : Type\n\nopen_locale classical -- hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 6 : `sdiff` and `neg`\n-/\n\n/-\n\nThe set-theoretic difference `A \\ B` satisfies the following property:\n\n```\nlemma mem_sdiff_iff : x \u2208 A \\ B \u2194 x \u2208 A \u2227 x \u2209 B\n```\n\nThe complement `-A` of a set `A` (often denoted $A^c$ in textbooks)\nis all the elements of `X` which are not in `A`:\n\n```\nlemma mem_neg_iff : x \u2208 -A \u2194 x \u2209 A\n```\n\nIn this lemma, you might get a shock. The `rw` tactic is aggressive\nin the Real Number Game -- if after a rewrite the goal can be\nsolved by `refl`, then Lean will close the goal automatically.\n\n-/\n\n/- Axiom : mem_sdiff_iff :\nx \u2208 A \\ B \u2194 x \u2208 A \u2227 x \u2209 B\n-/\n\n/- Axiom : mem_neg_iff :\nx \u2208 -A \u2194 x \u2209 A\n-/\n\n/- Lemma\nIf $A$ and $B$ are sets with elements of type $X$, then\n\n$$(A \\setminus B) = A \\cap B^{c}.$$\n-/\ntheorem setdiff_eq_intersect_comp (A B : set X) : A \\ B = A \u2229 B\u1d9c := \nbegin\n  rw ext_iff,\n  intro h,\n  rw mem_sdiff_iff,\n  rw mem_inter_iff,\n  rw mem_neg_iff,\nend\n\n\nend xena -- hide\n\n\n\n/-\nrw ext_iff,\n  intro x,\n  rw mem_sdiff_iff,\n  rw mem_inter_iff,\n  rw mem_neg_iff,\n-/\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/sets/sets_level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7252468018426363}}
{"text": "-- vim: ts=2 sw=0 sts=-1 et ai tw=70\n\n-- boring propositional theorems\n\nnamespace hidden\n\nvariables {p q: Prop}\n\n-- kind of cute little fact.\n-- Basically comes from equivalence of p \u2192 q \u2192 r and p \u2227 q \u2192 r\ntheorem implication_of_neg_commutative: (p \u2192 \u00acq) \u2194 (q \u2192 \u00acp) :=\nbegin\n  split, {\n    assume hpnq hq hp,\n    from hpnq hp hq,\n  }, {\n    assume hqnp hp hq,\n    from hqnp hq hp,\n  },\nend\n\ntheorem mp_to_contrapositive: (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\nbegin\n  assume hpq hnq hp,\n  from hnq (hpq hp),\nend\n\ntheorem iff_to_contrapositive: (p \u2194 q) \u2192 (\u00acp \u2194 \u00acq) :=\nbegin\n  assume hpq,\n  split, {\n    from mp_to_contrapositive hpq.mpr,\n  }, {\n    from mp_to_contrapositive hpq.mp,\n  }\nend\n\ntheorem exists_or {\u03b1 : Type} {p q : \u03b1 \u2192 Prop}:\n(\u2203 k, p k \u2228 q k) \u2194 (\u2203 k, p k) \u2228 (\u2203 k, q k) :=\nbegin\n  split; assume h, {\n    cases h with k h,\n    cases h, {\n      left,\n      existsi k,\n      assumption,\n    }, {\n      right,\n      existsi k,\n      assumption,\n    },\n  }, {\n    cases h; cases h with k h, {\n      existsi k,\n      left,\n      assumption,\n    }, {\n      existsi k,\n      right,\n      assumption,\n    },\n  }\nend\n\nuniverse u\n\n@[simp]\ntheorem not_exists {\u03b1 : Sort u} {p : \u03b1 \u2192 Prop} :\n(\u00ac\u2203 x : \u03b1, p x) \u2194 \u2200 x : \u03b1, \u00acp x :=\nbegin\n  split; assume h,\n    intro x,\n    assume hpx,\n    apply h,\n    existsi x,\n    assumption,\n  assume hex,\n  cases hex with x hpx,\n  from h x hpx,\nend\n\ntheorem not_and {p q : Prop} : \u00ac(p \u2227 q) \u2194 (p \u2192 \u00ac q) :=\nbegin\n  split; assume h,\n    assume hp hq,\n    from h \u27e8hp, hq\u27e9,\n  assume hpq,\n  cases hpq with hp hq,\n  from h hp hq,\nend\n\nopen classical\n\n@[simp]\ntheorem not_and_distrib {p q : Prop} : \u00ac(p \u2227 q) \u2194 \u00acp \u2228 \u00acq :=\nbegin\n  split; assume h,\n    cases em p with hp hnp,\n      right,\n      assume hq,\n      from h \u27e8hp, hq\u27e9,\n    left, assumption,\n  assume h,\n  cases h with hp hq,\n  cases h,\n    from h hp,\n  from h hq,\nend\n\n@[simp]\ntheorem not_not {p : Prop} : \u00ac\u00acp \u2194 p :=\nbegin\n  split; assume h,\n    cases em p with hp hnp,\n      assumption,\n    contradiction,\n  assume hnp,\n  contradiction,\nend\n\nlocal attribute [instance] classical.prop_decidable\n\n@[simp]\ntheorem not_forall {\u03b1 : Sort u} {p : \u03b1 \u2192 Prop} : (\u00ac \u2200 x, p x) \u2194 \u2203 x, \u00ac p x :=\nbegin\n  split; assume h,\n    by_contradiction hnex,\n    simp at hnex,\n    contradiction,\n  assume hnall,\n  cases h with x hnpx,\n  have := hnall x,\n  contradiction,\nend\n\ntheorem not_imp {p q : Prop} : \u00ac(p \u2192 q) \u2194 p \u2227 \u00acq :=\nbegin\n  split; assume h, {\n    split,\n      cases em p with hp hnp,\n        assumption,\n      exfalso, from h (\u03bb hp, (hnp hp).elim),\n    assume hq,\n    from h (\u03bb hp, hq),\n  }, {\n    assume hpq,\n    cases h with hp hnq,\n    from hnq (hpq hp),\n  },\nend\n\nend hidden\n", "meta": {"author": "Sterrs", "repo": "leaning", "sha": "3901cc953694b33adda86cb88ca30ba99594db31", "save_path": "github-repos/lean/Sterrs-leaning", "path": "github-repos/lean/Sterrs-leaning/leaning-3901cc953694b33adda86cb88ca30ba99594db31/src/principia/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7252467955055014}}
{"text": "import analysis.normed.group.basic\n\nlemma norm_sub_le_add {G : Type*} [normed_add_comm_group G] (a b c : G) : \u2016a - b\u2016 \u2264 \u2016a - c\u2016 + \u2016c - b\u2016 :=\nby simp [\u2190 dist_eq_norm, \u2190 dist_eq_norm, \u2190 dist_eq_norm, dist_triangle]\n\nlemma norm_sub_le_add_of_le {G : Type*} [normed_add_comm_group G] {a b c : G} {d d' : \u211d}\n  (h : \u2016a - c\u2016 \u2264 d) (h' : \u2016c - b\u2016 \u2264 d') : \u2016a - b\u2016 \u2264 d + d' :=\n(norm_sub_le_add a b c).trans $ add_le_add h h'\n", "meta": {"author": "leanprover-community", "repo": "sphere-eversion", "sha": "324e02c1509db6177cf363618f6ac5be343ce2f5", "save_path": "github-repos/lean/leanprover-community-sphere-eversion", "path": "github-repos/lean/leanprover-community-sphere-eversion/sphere-eversion-324e02c1509db6177cf363618f6ac5be343ce2f5/src/to_mathlib/analysis/normed_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7252467907317761}}
{"text": "import data.finset\n\nuniverses u v \nvariable \u03b2 : Type\nvariable \u03b1 : Type u\n\nstructure graph  :=\n(vertex : Type u)\n(edge : Type v)\n(\u03c61 : (edge\u2192 vertex))\n(\u03c62 : (edge\u2192 vertex))\n\n#check graph\n#print graph\n\n/-graph with single point and loop-/\ninductive One:Type\n|one : One\ndef a (x:One) : One := One.one\ndef graph0 : graph := {vertex:=One , edge:=One , \u03c61:=a , \u03c62:=a}\n#print graph0\n\n/-graph with 2 points and an edge-/\ninductive Two : Type\n|one : Two\n|two : Two\ndef b1 (x:One) : Two := Two.one\ndef b2 (x:One) : Two := Two.two\ndef graph1 : graph := {vertex:=Two , edge:=One , \u03c61 :=b1 , \u03c62:= b2}\n#print graph1\n\ninductive path (g:graph.{u v}) (start:g.vertex) : (g.vertex) \u2192 Type (max u v)\n|fix{} : path start \n|addedge (add:g.edge) (last:g.vertex) (p:path last) (pr:last = g.\u03c61 add) : path (g.\u03c62 add) \n\n#check path \n#check path.addedge\n\n/-path with single point-/\ndef path0 : path graph0 One.one One.one := path.fix\n/-path with one edge-/\ndef path1a : path graph1 Two.one Two.one := path.fix \ndef path1b : path graph1 Two.one Two.two := path.addedge One.one Two.one path1a rfl\n#check path1b\n#print path1b\n\nstructure finitegraph (\u03b2 : Type):=\n(fvertex : finset \u03b2 )\n(fedge : finset (\u03b2 \u00d7 \u03b2))\n(is_sub : fedge \u2286 (finset.product fvertex fvertex))\n\n/-function to calculate immediate neighbors of a subset of vertices;\nI have used type nat henceforth as lean is unable to figure out decidability of proposition for a general type without a proof-/\ndef neighbor_of_set (g : finitegraph nat) (s:finset nat) (p: s \u2286 g.fvertex) : finset nat :=\n(finset.filter (\u03bb v, (\u2203 (w : nat ) (h : w \u2208 s), (v,w) \u2208 g.fedge \u2228 (w,v) \u2208 g.fedge)) g.fvertex) \u222a s\n\n#check neighbor_of_set\n#print neighbor_of_set\n\nlemma filler (g:finitegraph nat) (s:finset nat) (p:s \u2286 g.fvertex) : (neighbor_of_set g s p) \u2286 g.fvertex :=\nbegin intro, apply finset.union_subset (finset.filter_subset g.fvertex) (p), end\n\nlemma filler2 (g:finitegraph nat) (s:finset nat) (p: s \u2286 g.fvertex): s \u2286 (neighbor_of_set g s p) := \nbegin intro, apply finset.subset_union_right, end\n\nstructure connected_step (g: finitegraph nat) := \n(pr1 : finset nat)\n(pr2 : pr1 \u2286 g.fvertex) \n\n/-function to find connected component of a subset of vertices-/\ndef connected_comp (g:finitegraph nat) (s:finset nat) (p:s \u2286 g.fvertex): nat \u2192 connected_step g \n| 0 := {pr1:=s, pr2:=p}\n|(x+1) := { pr1 := neighbor_of_set g (connected_comp x).pr1 (connected_comp x).pr2, \n           pr2 := filler g (connected_comp x).pr1 (connected_comp x).pr2 } \n\n#check connected_comp\n#print connected_comp\n\n/-function to check if given graph is connected by finding the connected component of any given subset of vertices-/\ndef is_connected (g:finitegraph nat) (s:finset nat) (p:s \u2286 g.fvertex) := \nif ((connected_comp g s p (finset.card g.fvertex +1)).pr1 = g.fvertex) then 1 else 0\n\n#check is_connected\n#print is_connected\n\n/-simple example to check computation of functions defined above; proofs use sorry-/\n\ndef inputV : finset nat := {1,2,3,4,5}\ndef sset : finset nat := {1,2} \ndef inputE : finset (nat \u00d7 nat) := {(1,2),(1,3),(3,4),(1,5)}\nlemma sub : inputE \u2286 finset.product inputV inputV := sorry \ndef finite1 : finitegraph nat := { fvertex:=inputV , fedge:=inputE , is_sub:=sub }\nlemma prf : sset \u2286 finite1.fvertex := sorry\n\n#eval neighbor_of_set finite1 sset prf\n#eval (connected_comp finite1 sset prf 2).pr1\n#eval is_connected finite1 sset prf\n", "meta": {"author": "enharsha", "repo": "Graphs-in-Lean", "sha": "85dfae77cc918e118501d676a87849989a9e946c", "save_path": "github-repos/lean/enharsha-Graphs-in-Lean", "path": "github-repos/lean/enharsha-Graphs-in-Lean/Graphs-in-Lean-85dfae77cc918e118501d676a87849989a9e946c/graph.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7252467834488201}}
{"text": "import tactic --hide\n\nimport game.sets.sets_level06 -- hide\n\nvariable X : Type --hide\n\nopen_locale classical -- hide\n\nnamespace xena -- hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 7 : The empty set\n-/\n\n/-\n\nThe way to handle the empty set is the following:\n\n```\nlemma mem_empty_iff (a : X) : a \u2208 (\u2205 : set X) \u2194 false\n```\n-/\n\n/- Axiom : mem_empty_iff :\na \u2208 (\u2205 : set X) \u2194 false\n-/\n\n/- Hint : Stuck?\nRemember that `exfalso` changes any goal to `false`. This can be\nconvenient if your hypotheses can prove `false`.\n\nAnother approach: if `hx : false` then `cases hx` will do a case\nsplit into every proof of false -- but there are no proofs of\nfalse! So there will be no cases left to do.\n-/\n\n/- Lemma\nThe empty set is a subset of any set $A$. \n-/\ntheorem empty_set_subset (A : set X) : \u2205 \u2286 A :=\nbegin\n  rw subset_iff,\n  intro h,\n  rw mem_empty_iff,\n  intro j,\n  exfalso,\n  exact j,\n\n\nend\n\nend xena\n\n\n\n/-\nrw subset_iff,\n  intros x hx,\n  exfalso,\n  rw mem_empty_iff at hx,\n  exact hx,\n\n-/", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/sets/sets_level07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.7252308131672435}}
{"text": "import ring_theory.ideal.basic\nimport ring_theory.localization.at_prime\n\nnoncomputable theory\n\nvariables (R : Type*) [comm_ring R]\n\n/--\na chain of prime ideal of length `n` is `\ud835\udd2d\u2080 \u2282 \ud835\udd2d\u2081 \u2282 ... \u2282 \ud835\udd2d\u2099` where all `\ud835\udd2d\u1d62`s are prime ideals.\n-/\nstructure prime_ideal_chain :=\n(len : \u2115)\n(chain : fin (len + 1) \u2192 ideal R)\n(is_chain : strict_mono chain)\n[is_prime : \u2200 i, (chain i).is_prime]\n\nnamespace prime_ideal_chain\n\n/--\nIf `R` is not the zero ring, then there is at least one prime ideal chain for `R` has a maximal \nideal.\n-/\ninstance [nontrivial R] : nonempty (prime_ideal_chain R) :=\nnonempty.intro\n{ len := 0,\n  chain := \u03bb _, (ideal.exists_maximal R).some,\n  is_chain := by { rintros \u27e8i, (hi : i < 1)\u27e9 \u27e8j, (hj : j < 1)\u27e9 (hij : i < j), exfalso, linarith, },\n  is_prime := \u03bb _, (ideal.exists_maximal R).some_spec.is_prime }\n\ninstance [nontrivial R] : inhabited (prime_ideal_chain R) :=\n{ default :=\n  { len := 0,\n    chain := \u03bb _, (ideal.exists_maximal R).some,\n    is_chain := by { rintros \u27e8i, (hi : i < 1)\u27e9 \u27e8j, (hj : j < 1)\u27e9 (hij : i < j), exfalso, linarith, },\n    is_prime := \u03bb _, (ideal.exists_maximal R).some_spec.is_prime } }\n\n/--\nTwo prime ideal chains are equal when they have the same length and the same prime ideals.\n-/\n@[ext]\nlemma ext (M N : prime_ideal_chain R)\n(len_eq : M.len = N.len)\n(chain_eq : \u2200 (i : fin (M.len + 1)), M.chain i = N.chain i) :\nM = N :=\nbegin\ncases M with h l m,\ncases N with h' l' m',\ndsimp at *,\nsubst len_eq,\ncongr,\next,\nrw chain_eq,\nnorm_num,\nend\n\nend prime_ideal_chain\n\n/--\nA ring `R` is said to be finite dimensional if there is a prime ideal chain with the maximal length.\nNote that according to this definition, the zero ring is not finite dimensional, for it has no prime\nideal chains.\n-/\nclass finite_dimensional_ring : Prop :=\n(fin_dim : \u2203 (M : prime_ideal_chain R), \u2200 (N : prime_ideal_chain R), N.len \u2264 M.len)\n\n/--\nIf `R` is not the zero ring, then `R` is finite dimensional iff all prime ideal chains of `R` have\nlength bounded by some `n \u2208 \u2115`\n-/\nlemma finite_dimensional_ring.iff_len_bounded [nontrivial R] : \n  finite_dimensional_ring R \u2194 \n  \u2203 (n : \u2115), \u2200 (N : prime_ideal_chain R), N.len \u2264 n :=\n{ mp := \u03bb h, \u27e8h.fin_dim.some.len, h.fin_dim.some_spec\u27e9,\n  mpr := \u03bb h, \n  { fin_dim := \u27e8(@nat.Sup_mem (set.range (prime_ideal_chain.len : prime_ideal_chain R \u2192 \u2115))\n      \u27e8(default : prime_ideal_chain R).len, \u27e8_, rfl\u27e9\u27e9 \u27e8h.some, begin \n        rintros _ \u27e8x, rfl\u27e9,\n        exact h.some_spec _,\n      end\u27e9).some, \u03bb N, begin \n        classical,\n        generalize_proofs H,\n        rw H.some_spec,\n        rw nat.Sup_def \u27e8h.some, _\u27e9,\n        swap,\n        { rintros _ \u27e8m, rfl\u27e9,\n          refine h.some_spec _, },\n        generalize_proofs H2,\n        exact nat.find_spec H2 _ \u27e8_, rfl\u27e9,\n      end\u27e9 } }\n\n\n/--\nThe Krull dimension of a ring is the length of maximal chain if the ring is finite dimensional and \n0 otherwise.\nNotes on implementation:\nalternatively `krull_dim` should take value in `with_top (with_bot \u2115)` where the zero ring then\nwould have dimension negative infinity (`\u22a5`) and any infinite dimensional ring will have dimension \npositive infinity (`\u22a4`).\n-/\ndef krull_dim : \u2115 := \n@@dite (finite_dimensional_ring R) (classical.dec _) (\u03bb H, H.fin_dim.some.len) (\u03bb _, 0)\n\n/--\nIf `R` is finite dimensional, then it has a prime ideal chain with the greatest length.\n-/\ndef maximal_chain [finite_dimensional_ring R] : prime_ideal_chain R :=\nfinite_dimensional_ring.fin_dim.some\n\nlemma maximal_chain_is_maximal [finite_dimensional_ring R] (M : prime_ideal_chain R) :\n  M.len \u2264 (maximal_chain R).len :=\nfinite_dimensional_ring.fin_dim.some_spec M\n\n/--\nIf `R` is finite dimensional, then its dimension is the length of the longest prime ideal chain.\n-/\nlemma krull_dim_eq_len [finite_dimensional_ring R] : krull_dim R = (maximal_chain R).len :=\nbegin \n  dunfold krull_dim,\n  split_ifs,\n  refl,\nend\n\n/--\nIf `R` is infinite dimensional, then its dimension, according to our convention, is zero.\n-/\nlemma krull_dim_eq_zero (not_finite : \u00ac finite_dimensional_ring R) : krull_dim R = 0 :=\nbegin \n  dunfold krull_dim,\n  split_ifs,\n  refl,\nend\n\nsection\n\nvariables {R}\n\n/--\nPulling back a chain of prime ideal chain of `S` along a surjective ring homomorphism `f : R \u27f6 S`\nto obtain a prime idael chain of `R` by `\ud835\udd2d\u1d62 \u21a6 f\u207b\u00b9 \ud835\udd2d\u1d62`.\n-/\n@[simps] def prime_ideal_chain.comap {S : Type*} [comm_ring S] (N : prime_ideal_chain S)\n  (f : R \u2192+* S) (hf : function.surjective f) : prime_ideal_chain R :=\n{ len := N.len,\n    chain := \u03bb j, (N.chain j).comap f,\n    is_chain := \u03bb i j h, begin \n      dsimp,\n      rw lt_iff_le_and_ne,\n      split,\n      { refine ideal.comap_mono _,\n        refine le_of_lt (N.is_chain h), },\n      { have neq := ne_of_lt (N.is_chain h),\n        contrapose! neq,\n        ext1 s,\n        obtain \u27e8r, rfl\u27e9:= hf s,\n        rw [\u2190 ideal.mem_comap, neq, ideal.mem_comap], },\n    end,\n    is_prime := \u03bb j, begin\n      haveI := N.is_prime j,\n      refine ideal.comap_is_prime _ _,\n    end }\n\n\n/--\nIf `R` is finite dimensional and `R \u27f6 S` is a surjective ring homomorphism, then every prime ideal\nchain of `S` has length at most `krull_dim R` \n-/\ntheorem prime_ideal_chain.length_bounded {S : Type*} [comm_ring S]\n  (N : prime_ideal_chain S) [finite_dimensional_ring R]\n  (f : R \u2192+* S) (hf : function.surjective f) : \n  N.len \u2264 krull_dim R :=\nbegin\n  rw [show N.len = (N.comap f hf).len, from rfl, krull_dim_eq_len],\n  apply maximal_chain_is_maximal,\nend\n\nend\n\n/--\nIf `R` is finite dimensional and `R \u27f6 S` is a surjective ring homomorphism, then `S` is finite\ndimensional as well.\n-/\nlemma finite_dimensional_of_surj [finite_dimensional_ring R] \n  (S : Type*) [comm_ring S] [nontrivial S]\n  (f : R \u2192+* S) (hf : function.surjective f) : finite_dimensional_ring S :=\nbegin\n  rw finite_dimensional_ring.iff_len_bounded,\n  exact \u27e8krull_dim R, \u03bb N, N.length_bounded f hf \u27e9,\nend\n\n/--\nIf `R` is finite dimensional and `R \u27f6 S` is a surjective ring homomorphism, \nthen `krull_dim S \u2264 krull_dim R`.\n-/\ntheorem krull_dim_le_of_surj [finite_dimensional_ring R]\n  (S : Type*) [comm_ring S] [nontrivial S]\n  (f : R \u2192+* S) (hf : function.surjective f) : krull_dim S \u2264 krull_dim R :=\nbegin\n  haveI : finite_dimensional_ring S := finite_dimensional_of_surj R S f hf,\n  rw krull_dim_eq_len,\n  exact (maximal_chain S).length_bounded f hf,\nend\n\n/--\nIf `R` is finite dimensional and nontrivial and `S` is isomorphic\nto `R`, then `krull_dim R = krull_dim S`.\n-/\ntheorem krull_dim_eq_of_findim_nontriv_isom\n  [finite_dimensional_ring R] [nontrivial R]\n  (S : Type*) [comm_ring S] (e : R \u2243+* S) :\n  krull_dim R = krull_dim S :=\nbegin\n  haveI : nontrivial S,\n    exact function.injective.nontrivial\n    (equiv_like.injective e),\n  haveI : finite_dimensional_ring S,\n    exact finite_dimensional_of_surj R S e\n    (equiv_like.surjective e),\n  have hRS : krull_dim R \u2264 krull_dim S,\n    exact krull_dim_le_of_surj S R (ring_equiv.symm e)\n    (equiv_like.surjective (ring_equiv.symm e)),\n  have hSR : krull_dim S \u2264 krull_dim R,\n    exact krull_dim_le_of_surj R S e\n    (equiv_like.surjective e),\n  exact le_antisymm hRS hSR,\nend\n\n/--\nIf `R` is nontrivial and `S` is isomorphic to `R`, then `krull_dim R = krull_dim S`.\n-/\ntheorem krull_dim_eq_of_nontriv_isom [nontrivial R]\n  (S : Type*) [comm_ring S] (e : R \u2243+* S) :\n  krull_dim R = krull_dim S :=\nbegin\n  by_cases hf : finite_dimensional_ring R,\n  haveI : finite_dimensional_ring R,\n    exact hf,\n  exact krull_dim_eq_of_findim_nontriv_isom R S e,\n  have hi : \u00acfinite_dimensional_ring S,\n    contrapose hf,\n    rw not_not at hf \u22a2,\n    haveI : finite_dimensional_ring S,\n      exact hf,\n    exact finite_dimensional_of_surj S R (ring_equiv.symm e)\n    (equiv_like.surjective (ring_equiv.symm e)),\n  have h1 : krull_dim R = 0,\n    exact krull_dim_eq_zero R hf,\n  have h2 : krull_dim S = 0,\n    exact krull_dim_eq_zero S hi,\n  rw h1,\n  rw h2,\nend\n\n/--\nIf `R` is trivial, then according to our definition, `R` is not finite dimensional.\n-/\nlemma not_fin_dim_of_triv [ht : \u00acnontrivial R] :\n  \u00acfinite_dimensional_ring R :=\nbegin\n  by_contra hf,\n    have hI : \u2203 (I : ideal R), I.is_prime,\n      use hf.fin_dim.some.chain 0,\n      exact hf.fin_dim.some.is_prime 0,\n    cases hI with I hI',\n    have haz : \u2200 (x : R), x = 0,\n      intro x,\n      by_contra,\n      have htR : \u00ac(\u2203 (x y : R), x \u2260 y),\n        rw \u2190nontrivial_iff,\n        exact ht,\n      have nhtR : \u2203 (x y : R), x \u2260 y,\n        use x,\n        use 0,\n      exact htR nhtR,\n    have hIeqT : I = \u22a4,\n      ext x,\n      split,\n      intro,\n      triv,\n      rw (haz x),\n      intro,\n      exact ideal.zero_mem I,\n    exact ideal.is_prime.ne_top hI' hIeqT,\nend\n\n/--\nIf `R` and `S` are isomorphic, then `krull_dim R = krull_dim S`.\n-/\ntheorem krull_dim_eq_of_isom (S : Type*) [comm_ring S]\n  [e : R \u2243+* S] : krull_dim R = krull_dim S :=\nbegin\n  by_cases hnt : nontrivial R,\n  haveI : nontrivial R := hnt,\n  exact krull_dim_eq_of_nontriv_isom R S e,\n  have htS : \u00acnontrivial S,\n    intro hntS,\n    have hntR : nontrivial R,\n      rw nontrivial_iff at hntS \u22a2,\n      cases hntS with x h,\n      cases h with y h',\n      use ring_equiv.symm e x,\n      use ring_equiv.symm e y,\n      intro hxeye,\n      exact h' ((ring_equiv.injective (ring_equiv.symm e))\n      hxeye),\n    exact hnt hntR,\n  have hnfR : \u00acfinite_dimensional_ring R,\n    exact (@not_fin_dim_of_triv R _ hnt),\n  have hnfS : \u00acfinite_dimensional_ring S,\n    exact (@not_fin_dim_of_triv S _ htS),\n  have h1 : krull_dim R = 0,\n    exact krull_dim_eq_zero R hnfR,\n  have h2 : krull_dim S = 0,\n    exact krull_dim_eq_zero S hnfS,\n  rw h1,\n  rw h2,\nend\n\n/--\nIf `R` is finite dimensional, `I` is an ideal of `R`, and `R \u29f8 I` is\nnontrivial, then `krull_dim (R \u29f8 I) \u2264 krull_dim R`.\n-/\ntheorem krull_dim_le_of_quot [finite_dimensional_ring R] (I : ideal R) [nontrivial (R \u29f8 I)] : \n  krull_dim (R \u29f8 I) \u2264 krull_dim R :=\nbegin\n  haveI : finite_dimensional_ring (R \u29f8 I) := \n    finite_dimensional_of_surj R (R \u29f8 I) (ideal.quotient.mk I) ideal.quotient.mk_surjective,\n  exact krull_dim_le_of_surj _ _ (ideal.quotient.mk I) ideal.quotient.mk_surjective,\nend\n\n\nsection height\n\nvariables {R} \n\n/--\nThe height of a prime ideal `\ud835\udd2d` is defined to be `krull_dim R_\ud835\udd2d`\n-/\ndef ideal.height (p : ideal R) [p.is_prime] : \u2115 :=\nkrull_dim (localization.at_prime p)\n\nexample (p : ideal R) [p.is_prime] : \u2115 := p.height\n\nend height\n", "meta": {"author": "FMLJohn", "repo": "dimension_theory", "sha": "cb6fe6749f267e89a9552a1af39309c537859148", "save_path": "github-repos/lean/FMLJohn-dimension_theory", "path": "github-repos/lean/FMLJohn-dimension_theory/dimension_theory-cb6fe6749f267e89a9552a1af39309c537859148/src/krull_dimension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7252308117901354}}
{"text": "open classical\n\nvariables (men : Type) (barber : men)\nvariable  (shaves : men \u2192 men \u2192 Prop)\n\ntheorem not_p_iff_not_p {p : Prop} : \u00ac(p \u2194 \u00acp) :=\nassume h : p \u2194 \u00acp,\nhave hnp : \u00acp, from (assume hp : p, (h.mp hp) hp),\nhnp (h.mpr hnp)\n\n-- via not_p_iff_not_p\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : false :=\nnot_p_iff_not_p (h barber)\n\n-- standalone\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : false :=\nhave hparadox : shaves barber barber \u2194 \u00acshaves barber barber, from\n    (h barber),\nhave hn_self_shave : \u00acshaves barber barber, from\n    (show shaves barber barber \u2192 false, from\n        assume h_self_shave : shaves barber barber,\n        absurd h_self_shave (hparadox.mp h_self_shave)),\nabsurd (hparadox.mpr hn_self_shave) hn_self_shave\n\n", "meta": {"author": "hyponymous", "repo": "theorem-proving-in-lean-solutions", "sha": "a95320ae81c90c1b15da04574602cd378794400d", "save_path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions", "path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions/theorem-proving-in-lean-solutions-a95320ae81c90c1b15da04574602cd378794400d/4.6.3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.936285009303773, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7252308061773471}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Neil Strickland\n\n! This file was ported from Lean 3 source module data.pnat.prime\n! leanprover-community/mathlib commit 09597669f02422ed388036273d8848119699c22f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Prime\nimport Mathlib.Data.PNat.Basic\n\n/-!\n# Primality and GCD on pnat\n\nThis file extends the theory of `\u2115+` with `gcd`, `lcm` and `prime` functions, analogous to those on\n`Nat`.\n-/\n\n\nnamespace Nat.Primes\n\n-- Porting note: new definition\n/-- The canonical map from `Nat.Primes` to `\u2115+` -/\n@[coe] def toPNat : Nat.Primes \u2192 \u2115+ :=\n  fun p => \u27e8(p : \u2115), p.property.pos\u27e9\n\ninstance coePNat : Coe Nat.Primes \u2115+ :=\n  \u27e8toPNat\u27e9\n#align nat.primes.coe_pnat Nat.Primes.coePNat\n\n@[norm_cast]\ntheorem coe_pnat_nat (p : Nat.Primes) : ((p : \u2115+) : \u2115) = p :=\n  rfl\n#align nat.primes.coe_pnat_nat Nat.Primes.coe_pnat_nat\n\n\n\n@[norm_cast]\ntheorem coe_pnat_inj (p q : Nat.Primes) : (p : \u2115+) = (q : \u2115+) \u2194 p = q :=\n  coe_pnat_injective.eq_iff\n#align nat.primes.coe_pnat_inj Nat.Primes.coe_pnat_inj\n\nend Nat.Primes\n\nnamespace PNat\n\nopen Nat\n\n/-- The greatest common divisor (gcd) of two positive natural numbers,\n  viewed as positive natural number. -/\ndef gcd (n m : \u2115+) : \u2115+ :=\n  \u27e8Nat.gcd (n : \u2115) (m : \u2115), Nat.gcd_pos_of_pos_left (m : \u2115) n.pos\u27e9\n#align pnat.gcd PNat.gcd\n\n/-- The least common multiple (lcm) of two positive natural numbers,\n  viewed as positive natural number. -/\ndef lcm (n m : \u2115+) : \u2115+ :=\n  \u27e8Nat.lcm (n : \u2115) (m : \u2115), by\n    let h := mul_pos n.pos m.pos\n    rw [\u2190 gcd_mul_lcm (n : \u2115) (m : \u2115), mul_comm] at h\n    exact pos_of_dvd_of_pos (Dvd.intro (Nat.gcd (n : \u2115) (m : \u2115)) rfl) h\u27e9\n#align pnat.lcm PNat.lcm\n\n@[simp, norm_cast]\ntheorem gcd_coe (n m : \u2115+) : (gcd n m : \u2115) = Nat.gcd n m :=\n  rfl\n#align pnat.gcd_coe PNat.gcd_coe\n\n@[simp, norm_cast]\ntheorem lcm_coe (n m : \u2115+) : (lcm n m : \u2115) = Nat.lcm n m :=\n  rfl\n#align pnat.lcm_coe PNat.lcm_coe\n\ntheorem gcd_dvd_left (n m : \u2115+) : gcd n m \u2223 n :=\n  dvd_iff.2 (Nat.gcd_dvd_left (n : \u2115) (m : \u2115))\n#align pnat.gcd_dvd_left PNat.gcd_dvd_left\n\ntheorem gcd_dvd_right (n m : \u2115+) : gcd n m \u2223 m :=\n  dvd_iff.2 (Nat.gcd_dvd_right (n : \u2115) (m : \u2115))\n#align pnat.gcd_dvd_right PNat.gcd_dvd_right\n\ntheorem dvd_gcd {m n k : \u2115+} (hm : k \u2223 m) (hn : k \u2223 n) : k \u2223 gcd m n :=\n  dvd_iff.2 (Nat.dvd_gcd (dvd_iff.1 hm) (dvd_iff.1 hn))\n#align pnat.dvd_gcd PNat.dvd_gcd\n\ntheorem dvd_lcm_left (n m : \u2115+) : n \u2223 lcm n m :=\n  dvd_iff.2 (Nat.dvd_lcm_left (n : \u2115) (m : \u2115))\n#align pnat.dvd_lcm_left PNat.dvd_lcm_left\n\ntheorem dvd_lcm_right (n m : \u2115+) : m \u2223 lcm n m :=\n  dvd_iff.2 (Nat.dvd_lcm_right (n : \u2115) (m : \u2115))\n#align pnat.dvd_lcm_right PNat.dvd_lcm_right\n\ntheorem lcm_dvd {m n k : \u2115+} (hm : m \u2223 k) (hn : n \u2223 k) : lcm m n \u2223 k :=\n  dvd_iff.2 (@Nat.lcm_dvd (m : \u2115) (n : \u2115) (k : \u2115) (dvd_iff.1 hm) (dvd_iff.1 hn))\n#align pnat.lcm_dvd PNat.lcm_dvd\n\ntheorem gcd_mul_lcm (n m : \u2115+) : gcd n m * lcm n m = n * m :=\n  Subtype.eq (Nat.gcd_mul_lcm (n : \u2115) (m : \u2115))\n#align pnat.gcd_mul_lcm PNat.gcd_mul_lcm\n\ntheorem eq_one_of_lt_two {n : \u2115+} : n < 2 \u2192 n = 1 := by\n  intro h; apply le_antisymm; swap; apply PNat.one_le\n  exact PNat.lt_add_one_iff.1 h\n#align pnat.eq_one_of_lt_two PNat.eq_one_of_lt_two\n\nsection Prime\n\n/-! ### Prime numbers -/\n\n\n/-- Primality predicate for `\u2115+`, defined in terms of `Nat.Prime`. -/\ndef Prime (p : \u2115+) : Prop :=\n  (p : \u2115).Prime\n#align pnat.prime PNat.Prime\n\ntheorem Prime.one_lt {p : \u2115+} : p.Prime \u2192 1 < p :=\n  Nat.Prime.one_lt\n#align pnat.prime.one_lt PNat.Prime.one_lt\n\ntheorem prime_two : (2 : \u2115+).Prime :=\n  Nat.prime_two\n#align pnat.prime_two PNat.prime_two\n\ntheorem dvd_prime {p m : \u2115+} (pp : p.Prime) : m \u2223 p \u2194 m = 1 \u2228 m = p := by\n  rw [PNat.dvd_iff]\n  rw [Nat.dvd_prime pp]\n  simp\n#align pnat.dvd_prime PNat.dvd_prime\n\ntheorem Prime.ne_one {p : \u2115+} : p.Prime \u2192 p \u2260 1 := by\n  intro pp\n  intro contra\n  apply Nat.Prime.ne_one pp\n  rw [PNat.coe_eq_one_iff]\n  apply contra\n#align pnat.prime.ne_one PNat.Prime.ne_one\n\n@[simp]\ntheorem not_prime_one : \u00ac(1 : \u2115+).Prime :=\n  Nat.not_prime_one\n#align pnat.not_prime_one PNat.not_prime_one\n\ntheorem Prime.not_dvd_one {p : \u2115+} : p.Prime \u2192 \u00acp \u2223 1 := fun pp : p.Prime => by\n  rw [dvd_iff]\n  apply Nat.Prime.not_dvd_one pp\n#align pnat.prime.not_dvd_one PNat.Prime.not_dvd_one\n\ntheorem exists_prime_and_dvd {n : \u2115+} (hn : n \u2260 1) : \u2203 p : \u2115+, p.Prime \u2227 p \u2223 n := by\n  obtain \u27e8p, hp\u27e9 := Nat.exists_prime_and_dvd (mt coe_eq_one_iff.mp hn)\n  exists (\u27e8p, Nat.Prime.pos hp.left\u27e9 : \u2115+); rw [dvd_iff]; apply hp\n#align pnat.exists_prime_and_dvd PNat.exists_prime_and_dvd\n\nend Prime\n\nsection Coprime\n\n/-! ### Coprime numbers and gcd -/\n\n\n/-- Two pnats are coprime if their gcd is 1. -/\ndef Coprime (m n : \u2115+) : Prop :=\n  m.gcd n = 1\n#align pnat.coprime PNat.Coprime\n\n@[simp, norm_cast]\ntheorem coprime_coe {m n : \u2115+} : Nat.coprime \u2191m \u2191n \u2194 m.Coprime n := by\n  unfold coprime Coprime\n  rw [\u2190 coe_inj]\n  simp\n#align pnat.coprime_coe PNat.coprime_coe\n\ntheorem Coprime.mul {k m n : \u2115+} : m.Coprime k \u2192 n.Coprime k \u2192 (m * n).Coprime k := by\n  repeat' rw [\u2190 coprime_coe]\n  rw [mul_coe]\n  apply Nat.coprime.mul\n#align pnat.coprime.mul PNat.Coprime.mul\n\ntheorem Coprime.mul_right {k m n : \u2115+} : k.Coprime m \u2192 k.Coprime n \u2192 k.Coprime (m * n) := by\n  repeat' rw [\u2190 coprime_coe]\n  rw [mul_coe]\n  apply Nat.coprime.mul_right\n#align pnat.coprime.mul_right PNat.Coprime.mul_right\n\ntheorem gcd_comm {m n : \u2115+} : m.gcd n = n.gcd m := by\n  apply eq\n  simp only [gcd_coe]\n  apply Nat.gcd_comm\n#align pnat.gcd_comm PNat.gcd_comm\n\ntheorem gcd_eq_left_iff_dvd {m n : \u2115+} : m \u2223 n \u2194 m.gcd n = m := by\n  rw [dvd_iff]\n  rw [Nat.gcd_eq_left_iff_dvd]\n  rw [\u2190 coe_inj]\n  simp\n#align pnat.gcd_eq_left_iff_dvd PNat.gcd_eq_left_iff_dvd\n\ntheorem gcd_eq_right_iff_dvd {m n : \u2115+} : m \u2223 n \u2194 n.gcd m = m := by\n  rw [gcd_comm]\n  apply gcd_eq_left_iff_dvd\n#align pnat.gcd_eq_right_iff_dvd PNat.gcd_eq_right_iff_dvd\n\ntheorem Coprime.gcd_mul_left_cancel (m : \u2115+) {n k : \u2115+} :\n    k.Coprime n \u2192 (k * m).gcd n = m.gcd n := by\n  intro h; apply eq; simp only [gcd_coe, mul_coe]\n  apply Nat.coprime.gcd_mul_left_cancel; simpa\n#align pnat.coprime.gcd_mul_left_cancel PNat.Coprime.gcd_mul_left_cancel\n\ntheorem Coprime.gcd_mul_right_cancel (m : \u2115+) {n k : \u2115+} : k.Coprime n \u2192 (m * k).gcd n = m.gcd n :=\n  by rw [mul_comm]; apply Coprime.gcd_mul_left_cancel\n#align pnat.coprime.gcd_mul_right_cancel PNat.Coprime.gcd_mul_right_cancel\n\ntheorem Coprime.gcd_mul_left_cancel_right (m : \u2115+) {n k : \u2115+} :\n    k.Coprime m \u2192 m.gcd (k * n) = m.gcd n := by\n  intro h; iterate 2 rw [gcd_comm]; symm;\n  apply Coprime.gcd_mul_left_cancel _ h\n#align pnat.coprime.gcd_mul_left_cancel_right PNat.Coprime.gcd_mul_left_cancel_right\n\ntheorem Coprime.gcd_mul_right_cancel_right (m : \u2115+) {n k : \u2115+} :\n    k.Coprime m \u2192 m.gcd (n * k) = m.gcd n := by\n  rw [mul_comm];\n  apply Coprime.gcd_mul_left_cancel_right\n#align pnat.coprime.gcd_mul_right_cancel_right PNat.Coprime.gcd_mul_right_cancel_right\n\n@[simp]\ntheorem one_gcd {n : \u2115+} : gcd 1 n = 1 := by\n  rw [\u2190 gcd_eq_left_iff_dvd]\n  apply one_dvd\n#align pnat.one_gcd PNat.one_gcd\n\n@[simp]\ntheorem gcd_one {n : \u2115+} : gcd n 1 = 1 := by\n  rw [gcd_comm]\n  apply one_gcd\n#align pnat.gcd_one PNat.gcd_one\n\n@[symm]\ntheorem Coprime.symm {m n : \u2115+} : m.Coprime n \u2192 n.Coprime m := by\n  unfold Coprime\n  rw [gcd_comm]\n  simp\n#align pnat.coprime.symm PNat.Coprime.symm\n\n@[simp]\ntheorem one_coprime {n : \u2115+} : (1 : \u2115+).Coprime n :=\n  one_gcd\n#align pnat.one_coprime PNat.one_coprime\n\n@[simp]\ntheorem coprime_one {n : \u2115+} : n.Coprime 1 :=\n  Coprime.symm one_coprime\n#align pnat.coprime_one PNat.coprime_one\n\ntheorem Coprime.coprime_dvd_left {m k n : \u2115+} : m \u2223 k \u2192 k.Coprime n \u2192 m.Coprime n := by\n  rw [dvd_iff]\n  repeat' rw [\u2190 coprime_coe]\n  apply Nat.coprime.coprime_dvd_left\n#align pnat.coprime.coprime_dvd_left PNat.Coprime.coprime_dvd_left\n\ntheorem Coprime.factor_eq_gcd_left {a b m n : \u2115+} (cop : m.Coprime n) (am : a \u2223 m) (bn : b \u2223 n) :\n    a = (a * b).gcd m := by\n  rw [gcd_eq_left_iff_dvd] at am\n  conv_lhs => rw [\u2190 am]\n  rw [eq_comm]\n  apply Coprime.gcd_mul_right_cancel a\n  apply Coprime.coprime_dvd_left bn cop.symm\n#align pnat.coprime.factor_eq_gcd_left PNat.Coprime.factor_eq_gcd_left\n\ntheorem Coprime.factor_eq_gcd_right {a b m n : \u2115+} (cop : m.Coprime n) (am : a \u2223 m) (bn : b \u2223 n) :\n    a = (b * a).gcd m := by rw [mul_comm]; apply Coprime.factor_eq_gcd_left cop am bn\n#align pnat.coprime.factor_eq_gcd_right PNat.Coprime.factor_eq_gcd_right\n\ntheorem Coprime.factor_eq_gcd_left_right {a b m n : \u2115+} (cop : m.Coprime n) (am : a \u2223 m)\n    (bn : b \u2223 n) : a = m.gcd (a * b) := by rw [gcd_comm]; apply Coprime.factor_eq_gcd_left cop am bn\n#align pnat.coprime.factor_eq_gcd_left_right PNat.Coprime.factor_eq_gcd_left_right\n\ntheorem Coprime.factor_eq_gcd_right_right {a b m n : \u2115+} (cop : m.Coprime n) (am : a \u2223 m)\n    (bn : b \u2223 n) : a = m.gcd (b * a) := by\n  rw [gcd_comm]\n  apply Coprime.factor_eq_gcd_right cop am bn\n#align pnat.coprime.factor_eq_gcd_right_right PNat.Coprime.factor_eq_gcd_right_right\n\ntheorem Coprime.gcd_mul (k : \u2115+) {m n : \u2115+} (h : m.Coprime n) :\n    k.gcd (m * n) = k.gcd m * k.gcd n := by\n  rw [\u2190 coprime_coe] at h; apply eq\n  simp only [gcd_coe, mul_coe]; apply Nat.coprime.gcd_mul k h\n#align pnat.coprime.gcd_mul PNat.Coprime.gcd_mul\n\ntheorem gcd_eq_left {m n : \u2115+} : m \u2223 n \u2192 m.gcd n = m := by\n  rw [dvd_iff]\n  intro h\n  apply eq\n  simp only [gcd_coe]\n  apply Nat.gcd_eq_left h\n#align pnat.gcd_eq_left PNat.gcd_eq_left\n\ntheorem Coprime.pow {m n : \u2115+} (k l : \u2115) (h : m.Coprime n) : (m ^ k).coprime (n ^ l) := by\n  rw [\u2190 coprime_coe] at *; simp only [pow_coe]; apply Nat.coprime.pow; apply h\n#align pnat.coprime.pow PNat.Coprime.pow\n\nend Coprime\n\nend PNat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/PNat/Prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7252079963464889}}
{"text": "import linear_algebra.projective_space.basic\nimport linear_algebra.linear_independent\nimport algebra.field.basic\nimport tactic\nvariables {K V : Type*} [field K] [add_comm_group V] [module K V]\n\nopen projectivization\n\n--/-Projection into the quotient is a left inverse for the representative function-/\n--lemma mk_left_inverse_of_rep (v : \u2119 K V) :\n--  (projectivization.mk K v.rep (rep_nonzero v)) = v :=\n--mk_rep _\n\n/-Composition of function and a finite indexing commute-/\nlemma fin_comp_commutes\u2082 {\u03b1 \u03b2 : Type*} {a b : \u03b1} {f: \u03b1 \u2192 \u03b2} : (f \u2218 (![a, b])) = (![f a, f b]) :=\nby { ext, fin_cases x; refl }\n\nlemma fin_comp_commutes\u2083 {\u03b1 \u03b2 : Type*} {a b c : \u03b1} {f: \u03b1 \u2192 \u03b2} : (f \u2218 (![a, b, c])) = (![f a, f b, f c]) :=\nby { ext, fin_cases x; refl }\n\n/-Two nonzero vectors go to the same point in projective space iff one is in the span of the other-/\nlemma mk_eq_mk_iff' (v w: V) (hv : v \u2260 0) (hw : w \u2260 0) : mk K v hv = mk K w hw \u2194 \u2203 a : K, a \u2022 w = v :=\nbegin\n  rw mk_eq_mk_iff K v w hv hw,\n  split,\n  { rintro \u27e8a, ha\u27e9, \n    exact \u27e8a, ha\u27e9 },\n  { rintro \u27e8a, ha\u27e9, \n    refine \u27e8units.mk0 a (\u03bb c, hv.symm _), ha\u27e9, \n    rwa [c, zero_smul] at ha }\nend\n\n/-Two points are equal iff their representatives are multiples of eachother-/\nlemma eq_iff (v w : \u2119 K V) : v = w \u2194 \u2203 a : K\u02e3, a \u2022 w.rep = v.rep :=\nbegin\n  conv_lhs { rw [\u2190 mk_rep v, \u2190 mk_rep w] },\n  rw mk_eq_mk_iff,\nend\n\n/- An inductive definition of independence wherein a linearly independent familty of nonzero vectors\ngives an independent family in the projective space -/\ninductive independent {\u03b9 : Type*} : (\u03b9 \u2192 \u2119 K V) \u2192 Prop\n| mk (f : \u03b9 \u2192 V) (hf : \u2200 i : \u03b9, f i \u2260 0) (hl : linear_independent K f) : \n    independent (\u03bb i, mk K (f i) (hf i))\n\n-- The definitions of independence in a projective space are equivalent\nlemma independent_iff (\u03b9 : Type*) (f : \u03b9 \u2192 (\u2119 K V)) : (independent f) \u2194 \n  (linear_independent K (projectivization.rep \u2218 f)) := \nbegin\n  split,\n  { rintro h, induction h with ff hff hh,\n    choose a ha using \u03bb (i : \u03b9), exists_smul_eq_mk_rep K (ff i) (hff i),\n    convert hh.units_smul a,\n    ext i, exact (ha i).symm },\n  { intro h, \n    convert independent.mk _ _ h, \n    { ext, simp only [mk_rep] },\n    { intro i, apply rep_nonzero } }\nend\n\n/-An inductive definition of dependence wherein a linearly dependent family of nonzero vectors\ngives a dependent family in the projective space -/\ninductive dependent {\u03b9 : Type*} : (\u03b9 \u2192 \u2119 K V) \u2192 Prop\n| mk (f : \u03b9 \u2192 V) (hf : \u2200 i : \u03b9, f i \u2260 0) (h : \u00aclinear_independent K f) : \n    dependent (\u03bb i, mk K (f i) (hf i))\n\n/-The definitons of dependence are equivalent-/\nlemma dependent_iff (\u03b9 : Type*) (f : \u03b9 \u2192 (\u2119 K V)) : (dependent f) \u2194\n  (\u00ac linear_independent K (projectivization.rep \u2218 f)) :=\nbegin\n  split,\n  { rw \u2190 independent_iff,\n    intros h1, induction h1 with ff hff hh1, \n    contrapose! hh1, rw independent_iff at hh1,\n    choose a ha using \u03bb (i : \u03b9), exists_smul_eq_mk_rep K (ff i) (hff i),\n    convert hh1.units_smul a\u207b\u00b9,\n    ext i, simp only [\u2190 ha, inv_smul_smul, pi.smul_apply', pi.inv_apply, function.comp_app] },\n  { intro h, \n    convert dependent.mk _ _ h, \n    { ext, simp only [mk_rep] },\n    { intro i, apply rep_nonzero } }\nend\n\n/-Dependence is the negation of independence-/\nlemma dependent_iff_not_independent {\u03b9 : Type*} (f : \u03b9 \u2192 \u2119 K V) :\n  dependent f \u2194 \u00ac independent f :=\nby { rw [dependent_iff, independent_iff] }  \n\n/-Independence is the negation of dependence-/\nlemma independent_iff_not_dependent {\u03b9 : Type*} (f : \u03b9 \u2192 \u2119 K V) :\n  independent f \u2194 \u00ac dependent f :=\nby { rw [dependent_iff, independent_iff, not_not] }  \n\n\n/-A pair of points in a projective space are dependent iff they are equal-/\n@[simp] lemma pair_dependent_iff_eq (u v : \u2119 K V) : (dependent ![u, v]) \u2194 u = v :=\nbegin\n  rw dependent_iff_not_independent,\n  split,\n  { intro h, rw independent_iff at h,\n    rw linear_independent_fin2 at h,\n    simp at h,\n    specialize h (rep_nonzero v),\n    cases h with a ha,\n    rw [\u2190 (mk_rep u), \u2190(mk_rep v),\n      mk_eq_mk_iff' u.rep v.rep (rep_nonzero u) (rep_nonzero v)],\n    use a,\n    assumption  },\n  { intro h, rw independent_iff,\n    rw [h, linear_independent_fin2],\n    simp,\n    intro hv,\n    use 1,\n    simp, },\nend\n\n/-A pair of points in a projective space are independent iff they are not equal-/\n@[simp] lemma pair_independent_iff_neq (u v : \u2119 K V) : (independent ![u, v]) \u2194\n  u \u2260 v :=\nby {  rw independent_iff_not_dependent, simp,  }\n\nlemma nt_lin_comb_implies_in_span {u v : V} {a b : K} (ha : a \u2260 0) (hz : a \u2022 u + b \u2022 v = 0) :\n  (-a\u207b\u00b9*b) \u2022 v = u :=\nbegin\nhave huv : a \u2022 u = -(b \u2022 v), by {rw \u2190 eq_neg_iff_add_eq_zero at hz, exact hz},\nhave hv : u = (- a\u207b\u00b9*b) \u2022 v, by\n  {  calc\n  u = 1 \u2022 u : (one_smul _ (u)).symm\n  ... = (a\u207b\u00b9 * a) \u2022 u : by {  rw (inv_mul_cancel ha), simp  }\n  ... = (- a\u207b\u00b9*b) \u2022 v : by {  rw [mul_smul, huv, mul_smul], simp  }  },\nexact hv.symm\nend\n\nlemma dependent_iff_reps_dependent\u2082 (u v : \u2119 K V) : dependent ![u, v] \u2194\n  \u2203 (a b : K) (hnt : ![a, b] \u2260 0), a \u2022 u.rep + b \u2022 v.rep = 0 :=\nbegin\n  rw [dependent_iff, fin_comp_commutes\u2082, linear_independent_fin2],\n  split,\n  { intro h,\n    simp at h,\n    specialize h (rep_nonzero v),\n    cases h with a ha,\n    use [-1, a],\n    split; simp,\n    rw ha,\n    simp,  },\n  { rintros \u27e8a, b, \u27e8hnt, hz\u27e9\u27e9,\n    simp,\n    intro hv,\n    suffices ha : a \u2260 0, by {  use (-a\u207b\u00b9*b), exact nt_lin_comb_implies_in_span ha hz,  },\n    by_contradiction,\n    rw h at hz,\n    simp at *,\n    cases hz,\n    { exact hnt h hz },\n    { exact rep_nonzero v hz, } }\nend\n\nopen_locale big_operators\n\nlemma dependent_iff_reps_dependent\u2083 (u v w : \u2119 K V) : dependent ![u, v, w] \u2194\n  \u2203 (a b c : K) (hnt : ![a, b, c] \u2260 0), a \u2022 u.rep + b \u2022 v.rep + c \u2022 w.rep = 0 :=\nbegin\n  rw [dependent_iff, fintype.not_linear_independent_iff],\n  simp only [fin.sum_univ_succ, function.comp_app, matrix.cons_val_zero, matrix.cons_val_succ, \n    fin.succ_zero_eq_one, fintype.univ_of_subsingleton, fin.mk_eq_subtype_mk, fin.mk_zero, \n    finset.sum_singleton, fin.succ_one_eq_two, eq_iff_true_of_subsingleton, and_true, \n    not_and, exists_prop, add_assoc],\n  split,\n  { rintro \u27e8g,h1,\u27e8i,h2\u27e9\u27e9, \n    refine \u27e8g 0, g 1, g 2, _, h1\u27e9,\n    rw function.ne_iff, use i, fin_cases i; exact h2 },\n  { rintros \u27e8a,b,c,h1,h2\u27e9, \n    refine \u27e8![a,b,c], h2, _\u27e9,\n    rwa \u2190 function.ne_iff, }\nend\n\n/-A nontrivial linear combination of representatives which is zero implies both scalars are nonzero-/\nlemma lc_implies_both_nz {u v : \u2119 K V} {a b : K} (ht: ![a, b] \u2260 0) (hs : a \u2022 u.rep + b \u2022 v.rep = 0) : a \u2260 0 \u2227 b \u2260 0 :=\nbegin\nsplit;\nby_contradiction;\nrw h at hs;\nsimp at hs;\ncases hs,\n  {  have hz : ![a,b] = 0, by {  simp at *, split; assumption,  },\n  exact ht hz,  },\n  {  exact rep_nonzero v hs,  },\n  {  have hz : ![a,b] = 0, by {  simp at *, split; assumption,  },\n  exact ht hz,  },\n  {  exact rep_nonzero u hs,  },\nend\n\n/-If in a -/\n@[simp] lemma nontrivial_and_zero\u2081 {a b c : K} (ht : ![a, b, c] \u2260 0)\n  (ha : a = (0 : K)) : ![b, c] \u2260 0 :=\nbegin\nsimp at *,\nintro hb,\nby_contradiction,\nexact ((ht ha) hb) h,\nend\n\n\n@[simp] lemma nontrivial_and_zero\u2082 {a b c : K} (ht : ![a, b, c] \u2260 0)\n  (hb : b = (0 : K)) : ![a, c] \u2260 0 :=\nbegin\nsimp at *,\nintro ha,\nby_contradiction,\nexact ((ht ha) hb) h,\nend\n\n\nlemma neq_implies_sc_neq_zero {u v w : \u2119 K V} {a b c : K} (hneq : v \u2260 w)\n  (hnz : ![a, b, c] \u2260 0) (hsz : a \u2022 u.rep + b \u2022 v.rep + c \u2022 w.rep = 0) : a \u2260 0 :=\nbegin\nby_contradiction,\nrw h at hsz,\nsimp at hsz,\nhave hz, from nontrivial_and_zero\u2081 hnz h,\nhave h2, from lc_implies_both_nz hz hsz,\ncases h2 with hb hc,\nhave heq : v = w, by\n  {  rw [\u2190 mk_rep v, \u2190 mk_rep w,\n  mk_eq_mk_iff' v.rep w.rep (rep_nonzero v) (rep_nonzero w)],\n  use -b\u207b\u00b9*c,\n  exact nt_lin_comb_implies_in_span hb hsz,  },\nexact hneq heq,\nend\n\n\n\n/-Three points of a projective geometry are collinear if they are dependent-/\ndef collinear (u v w : \u2119 K V) : Prop :=\n  dependent _ ![u, v, w]\n\n/--The collinear relation satisfies the axioms of a projective geometry as defined in\nModern Projective Geometry by Faure and Frolicher-/\n\n/-Any two points of a projective space are collinear-/\nlemma L1 (u v : \u2119 K V) : collinear u v u :=\nbegin\nunfold collinear,\nrw dependent_iff_reps_dependent\u2083,\nuse [1, 0, -1],\nsplit;\nsimp,\nend\n\n\n/-Two distinct points determine a line-/\nlemma L2 (a b p q : \u2119 K V) (h1 : collinear a p q) (h2 : collinear b p q)\n  (hneq : p \u2260 q) : collinear a b p :=\nbegin\nunfold collinear at *,\nrw dependent_iff_reps_dependent\u2083 at *,\nrcases h1 with \u27e8x\u2081, y\u2081, z\u2081, \u27e8h1nt, h1z\u27e9\u27e9,\nrcases h2 with \u27e8x\u2082, y\u2082, z\u2082, \u27e8h2nt, h2z\u27e9\u27e9,\ncases classical.em (z\u2081 = 0) with hz\u2081 hz\u2081,\n  { rw hz\u2081 at h1z,\n  use [x\u2081, 0, y\u2081],\n  split,\n    {  by_contradiction,\n    simp at *,\n    exact h1nt h.1 h.2 hz\u2081,  },\n    {  simp at *, assumption  },  },\n  {  use  [- z\u2082*z\u2081\u207b\u00b9*x\u2081, x\u2082, y\u2082 - z\u2082*z\u2081\u207b\u00b9*y\u2081],\n  split,\n    {  have hx\u2082 : x\u2082 \u2260 0, from neq_implies_sc_neq_zero hneq h2nt h2z,\n    simp, intros _ _, contradiction,  },\n    {  have h2: 0 + (-z\u2082*z\u2081\u207b\u00b9) \u2022 (x\u2081 \u2022 a.rep + y\u2081 \u2022 p.rep + z\u2081 \u2022 q.rep)  = 0, by {  rw h1z, simp  },\n    nth_rewrite 0 [ \u2190 h2z] at h2,\n    rw [smul_add, smul_add, \u2190 mul_smul(-z\u2082*z\u2081\u207b\u00b9) z\u2081,\n      (@mul_assoc K _ (-z\u2082) z\u2081\u207b\u00b9 z\u2081), inv_mul_cancel hz\u2081] at h2,\n    simp at h2,\n    rw \u2190 h2,\n    abel,\n    repeat {  rw \u2190 mul_smul  },\n    rw [add_left_cancel_iff, add_comm (y\u2082 \u2022 p.rep) _, add_assoc _ _ (y\u2082 \u2022 p.rep)],\n    simp,\n    rw [add_comm],\n    abel,\n    rw [add_smul, add_left_cancel_iff, smul_assoc],  },  },\nend\n\n/-If a point belongs to two lines, then-/\nlemma L3 (a b c d p : \u2119 K V) (h1 : collinear p a b) (h2 : collinear p c d) :\n  \u2203 q : \u2119 K V, collinear q a c \u2227 collinear q b d :=\nbegin\nunfold collinear at *,\nrw dependent_iff_reps_dependent\u2083 at *,\nrcases h1 with \u27e8x\u2081, y\u2081, z\u2081, \u27e8h1nt, h1z\u27e9\u27e9,\nrcases h2 with \u27e8x\u2082, y\u2082, z\u2082, \u27e8h2nt, h2z\u27e9\u27e9,\nsimp_rw dependent_iff_reps_dependent\u2083,\ncases classical.em (c = a) with hca hnca,\n  {  rw hca,\n  use b,\n  split,\n    {  use [ 0, -1, 1], simp  },\n    {  use [-1, 1, 0], simp  }  },\n  {  cases classical.em (x\u2081 = 0) with hx\u2081 hx\u2081,\n    {  rw hx\u2081 at h1z,\n    simp at h1z,\n    have hab : a = b, by {rw [\u2190 pair_dependent_iff_eq, dependent_iff_reps_dependent\u2082], use [y\u2081, z\u2081], split, exact nontrivial_and_zero\u2081 h1nt hx\u2081, assumption,  },\n    rw hab,\n    use b,\n    split; use [1,-1,0]; split; simp,  },\n    {  cases classical.em (x\u2082 = 0) with hx\u2082 hx\u2082,\n      {  rw hx\u2082 at h2z,\n      simp at h2z,\n      have hcd : c = d, by {  rw [\u2190 pair_dependent_iff_eq, dependent_iff_reps_dependent\u2082], use [y\u2082, z\u2082], split, exact nontrivial_and_zero\u2081 h2nt hx\u2082, assumption,  },\n      rw hcd,\n      use d,\n      split; use [1, 0, -1]; split; simp,  },\n      cases classical.em (y\u2082 = 0) with hy\u2082 hy\u2082,\n        {  use a,\n        rw hy\u2082 at h2z,\n        simp at h2z,\n        have hpd : p = d, by {  rw [\u2190 pair_dependent_iff_eq, dependent_iff_reps_dependent\u2082], use [x\u2082, z\u2082], split, exact nontrivial_and_zero\u2082 h2nt hy\u2082, exact h2z  },\n        split,\n          {  use [1, -1, 0], simp,  },\n          {  rw \u2190 hpd, use [y\u2081, z\u2081, x\u2081], simp, split,\n            {  simp at h1nt, intros hy\u2081 hz\u2081, by_contradiction, exact h1nt h hy\u2081 hz\u2081  },\n            {  rw [add_comm, \u2190 add_assoc], exact h1z  },  },  },\n        {  let q := (x\u2082\u207b\u00b9*y\u2082) \u2022 c.rep + (-x\u2081\u207b\u00b9*y\u2081) \u2022 a.rep,\n        have hqneq : q \u2260 0, by\n          {  by_contradiction,\n          have hq : (x\u2082\u207b\u00b9*y\u2082) \u2022 c.rep + (-x\u2081\u207b\u00b9*y\u2081) \u2022 a.rep = 0, from h,\n          have hx\u2082y\u2082 : x\u2082\u207b\u00b9*y\u2082 \u2260 0, by {  refine mul_ne_zero _ hy\u2082,  exact left_ne_zero_of_mul_eq_one (inv_mul_cancel hx\u2082),  },\n          have tttt, from nt_lin_comb_implies_in_span hx\u2082y\u2082 hq,\n          have hca : c = a, by {  rw [\u2190 mk_rep a, \u2190 mk_rep c, mk_eq_mk_iff'], use -(x\u2082\u207b\u00b9*y\u2082)\u207b\u00b9*(-x\u2081\u207b\u00b9*y\u2081), exact tttt  },\n          exact hnca hca, },\n        use mk K q hqneq,\n        have hk, from exists_smul_eq_mk_rep K q hqneq,\n        cases hk with k hk,\n        have hk' : (k : K) \u2022 q = (mk K q hqneq).rep, by {  exact hk  },\n        have hnk : (k : K) \u2260 0, by {  rw \u2190 units.exists_iff_ne_zero, use k  },\n        rw \u2190 hk',\n        split,\n          {  use [((\u2191k)\u207b\u00b9 : K), x\u2081\u207b\u00b9*y\u2081, -x\u2082\u207b\u00b9*y\u2082 ],\n          rw [\u2190 mul_smul _ _ q, inv_mul_cancel hnk],\n          simp,  },\n          {  use [x\u2082*((\u2191k)\u207b\u00b9 : K), -(x\u2082*x\u2081\u207b\u00b9*z\u2081), z\u2082],\n          split,\n            {  simp, intro hzx\u2082, exfalso, exact hx\u2082 hzx\u2082  },\n            { rw [\u2190 mul_smul _ _ q, mul_assoc, inv_mul_cancel hnk],\n            simp,\n            have h2 : 0 + (-x\u2082*x\u2081\u207b\u00b9) \u2022 (x\u2081 \u2022 p.rep + y\u2081 \u2022 a.rep + z\u2081 \u2022 b.rep) = 0, by {  rw h1z, simp  },\n            nth_rewrite 0 [\u2190 h2z] at h2,\n            repeat {  rw [smul_add, \u2190 mul_smul] at h2  },\n            repeat {  rw \u2190 mul_smul  },\n            rw [\u2190 mul_assoc, mul_inv_cancel hx\u2082],\n            simp,\n            rw [mul_assoc (-x\u2082) _ _, inv_mul_cancel hx\u2081, \u2190 mul_smul] at h2,\n            simp at h2,\n            abel at h2,\n            abel,\n            rw \u2190 mul_assoc x\u2082 x\u2081\u207b\u00b9 _,\n            exact h2,  },  },  },  },  },\nend\n\n\n\n/- Dependence of points in the projective space is preserved by linear equivalences -/\n\nvariables {W : Type*} [add_comm_group W] [module K W]\nvariable (T : V \u2243\u2097[K] W)\n\n/- Projecting a nonzero vector to the quotient and evaluating an injective linear map\nat that vector commute -/\n@[simp] lemma map_mk_eq_mk' (T : V \u2192\u2097[K] W) (hT : function.injective T)\n  (v : V) (hv : v \u2260 0) :\n  map T hT (mk K v hv) = mk K (T v) (by {rw \u2190 (T.map_zero), exact hT.ne hv}) := by {  refl  }\n\nlemma map_mk_eq_mk (v : V) (hv : v \u2260 0) :\n  map T.to_linear_map T.injective (mk K v hv) =\n  mk _ (T v) (T.map_ne_zero_iff.mpr hv) :=\n  by {  refl  }\n\n\n/-The map induced by an Isomorphism of vector spaces preserves independence-/\n/- lemma independent_comp_iso_independent {\u03b9 : Type*} (f : \u03b9 \u2192 \u2119 K V) (hi : independent _ f) :\n  independent _ ((map T.to_linear_map T.injective) \u2218 f) :=\nbegin\nunfold independent at *,\nsuffices hsmul: \u2203 g : \u03b9 \u2192 K\u02e3, (projectivization.rep \u2218 map T.to_linear_map T.injective \u2218 f) = g \u2022 (T.to_linear_map \u2218 projectivization.rep \u2218 f), by\n  {cases hsmul with g hg,\n  rw hg,\n  suffices h : linear_independent K (T.to_linear_map \u2218 projectivization.rep \u2218 f) \u2194 linear_independent K (projectivization.rep \u2218 f), by\n    {rw \u2190 h  at hi,\n    exact linear_independent.units_smul hi g},\n\n  have ht : linear_independent K (T.to_linear_map \u2218 projectivization.rep \u2218 f) \u2194 linear_independent K (projectivization.rep \u2218 f), from linear_map.linear_independent_iff T.to_linear_map (linear_equiv.ker T),\n  exact ht  },\nhave g : \u03b9 \u2192 K\u02e3, by\n  {intro i,\n  have ht, from map_mk_eq_mk' (T.to_linear_map) (T.injective) (projectivization.rep (f i)) (rep_nonzero (f i)),\n  rw eq_iff _ _ at ht,\n\n\n\n  },\n\nend -/\n\n/- Independence of points is preserved by linear equivalences-/\nlemma independent_comp_iso_independent {\u03b9 : Type*} (f : \u03b9 \u2192 \u2119 K V) (hi : independent _ f) :\n  independent _ ((map T.to_linear_map T.injective) \u2218 f) :=\nbegin\nunfold independent at hi,\nhave hli, from linear_independent.map' hi T.to_linear_map (linear_equiv.ker T),\nhave hli', from independent'.mk (by {simp, intro i, exact rep_nonzero (f i), }) hli,\nrw independent_iff,\n  split,\n  {sorry},\n  {sorry},\n\nend\n\n\n/- Points are independent iff they are independent under the map induced by a linear equivalence-/\nlemma independent_iff_iso_independent {\u03b9 : Type*} (f : \u03b9 \u2192 \u2119 K V) :\n  independent _ f \u2194 independent _ ((map T.to_linear_map T.injective) \u2218 f) :=\nbegin\nsplit,\n  { intro h,\n    exact independent_comp_iso_independent _ f h},\n  {intro h,\n  have hT, from independent_comp_iso_independent T.symm ((map T.to_linear_map T.injective) \u2218 f) h,\n  rw [\u2190 function.comp.assoc, \u2190 map_comp] at hT,\n  suffices hid : map (T.symm.to_linear_map.comp T.to_linear_map) _ = map linear_map.id _, by\n    {rw [hid, map_id] at hT,\n    simp at hT,\n    exact hT,},\n  ext,\n  unfold map,\n  simp,},\nend\n\n/-Points are dependent iff they are dependent under the map induced by a linear equivalence-/\nlemma dependent_iff_iso_dependent {\u03b9 : Type*} (f : \u03b9 \u2192 \u2119 K V) :\n  dependent _ f \u2194 dependent _ ((map T.to_linear_map T.injective) \u2218 f) :=\nbegin\nrw [dependent_iff_not_independent, dependent_iff_not_independent, not_iff_not],\nexact independent_iff_iso_independent _ _,\nend\n\n\nlemma independent_iff_independent\u2082 (u v : \u2119 K V) : independent _ ![u, v] \u2194\n  independent _ ![map T.to_linear_map T.injective u, map T.to_linear_map T.injective v] :=\nbegin\nrw \u2190 fin_comp_commutes\u2082,\nexact independent_iff_iso_independent _ _,\nend\n\nlemma independent_iff_independent\u2083 (u v w: \u2119 K V) : independent _ ![u, v, w] \u2194\n  independent _ ![map T.to_linear_map T.injective u, map T.to_linear_map T.injective v,\n  map T.to_linear_map T.injective w] :=\nbegin\nrw \u2190 fin_comp_commutes\u2083,\nexact independent_iff_iso_independent _ _,\nend\n\nlemma dependent_iff_dependent\u2082 (u v : \u2119 K V) : dependent _ ![u, v] \u2194\n  dependent _ ![map T.to_linear_map T.injective u, map T.to_linear_map T.injective v] :=\nbegin\nrw \u2190 fin_comp_commutes\u2082,\nexact dependent_iff_iso_dependent _ _,\nend\n\nlemma dependent_iff_dependent\u2083 (u v w: \u2119 K V) : dependent _ ![u, v, w] \u2194\n  dependent _ ![map T.to_linear_map T.injective u, map T.to_linear_map T.injective v,\n  map T.to_linear_map T.injective w] :=\nbegin\nrw \u2190 fin_comp_commutes\u2083,\nexact dependent_iff_iso_dependent _ _,\nend\n", "meta": {"author": "adamtopaz", "repo": "projective_independence", "sha": "139954d2ad848a465f7499deb603106a1dc9dc44", "save_path": "github-repos/lean/adamtopaz-projective_independence", "path": "github-repos/lean/adamtopaz-projective_independence/projective_independence-139954d2ad848a465f7499deb603106a1dc9dc44/src/projective_independence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7252079877025861}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n-/\nimport data.fintype.parity\nimport number_theory.legendre_symbol.zmod_char\nimport field_theory.finite.basic\nimport number_theory.legendre_symbol.gauss_sum\n\n/-!\n# Quadratic characters of finite fields\n\nThis file defines the quadratic character on a finite field `F` and proves\nsome basic statements about it.\n\n## Tags\n\nquadratic character\n-/\n\n/-!\n### Definition of the quadratic character\n\nWe define the quadratic character of a finite field `F` with values in \u2124.\n-/\n\nsection define\n\n/-- Define the quadratic character with values in \u2124 on a monoid with zero `\u03b1`.\nIt takes the value zero at zero; for non-zero argument `a : \u03b1`, it is `1`\nif `a` is a square, otherwise it is `-1`.\n\nThis only deserves the name \"character\" when it is multiplicative,\ne.g., when `\u03b1` is a finite field. See `quadratic_char_fun_mul`.\n\nWe will later define `quadratic_char` to be a multiplicative character\nof type `mul_char F \u2124`, when the domain is a finite field `F`.\n-/\ndef quadratic_char_fun (\u03b1 : Type*) [monoid_with_zero \u03b1] [decidable_eq \u03b1]\n  [decidable_pred (is_square : \u03b1 \u2192 Prop)] (a : \u03b1) : \u2124 :=\nif a = 0 then 0 else if is_square a then 1 else -1\n\nend define\n\n/-!\n### Basic properties of the quadratic character\n\nWe prove some properties of the quadratic character.\nWe work with a finite field `F` here.\nThe interesting case is when the characteristic of `F` is odd.\n-/\n\nsection quadratic_char\n\nopen mul_char\n\nvariables {F : Type*} [field F] [fintype F] [decidable_eq F]\n\n/-- Some basic API lemmas -/\nlemma quadratic_char_fun_eq_zero_iff {a : F} : quadratic_char_fun F a = 0 \u2194 a = 0 :=\nbegin\n  simp only [quadratic_char_fun],\n  by_cases ha : a = 0,\n  { simp only [ha, eq_self_iff_true, if_true], },\n  { simp only [ha, if_false, iff_false],\n    split_ifs; simp only [neg_eq_zero, one_ne_zero, not_false_iff], },\nend\n\n@[simp]\nlemma quadratic_char_fun_zero : quadratic_char_fun F 0 = 0 :=\nby simp only [quadratic_char_fun, eq_self_iff_true, if_true, id.def]\n\n@[simp]\nlemma quadratic_char_fun_one : quadratic_char_fun F 1 = 1 :=\nby simp only [quadratic_char_fun, one_ne_zero, is_square_one, if_true, if_false, id.def]\n\n/-- If `ring_char F = 2`, then `quadratic_char_fun F` takes the value `1` on nonzero elements. -/\nlemma quadratic_char_fun_eq_one_of_char_two (hF : ring_char F = 2) {a : F} (ha : a \u2260 0) :\n  quadratic_char_fun F a = 1 :=\nbegin\n  simp only [quadratic_char_fun, ha, if_false, ite_eq_left_iff],\n  exact \u03bb h, false.rec _ (h (finite_field.is_square_of_char_two hF a))\nend\n\n/-- If `ring_char F` is odd, then `quadratic_char_fun F a` can be computed in\nterms of `a ^ (fintype.card F / 2)`. -/\nlemma quadratic_char_fun_eq_pow_of_char_ne_two (hF : ring_char F \u2260 2) {a : F} (ha : a \u2260 0) :\n  quadratic_char_fun F a = if a ^ (fintype.card F / 2) = 1 then 1 else -1 :=\nbegin\n  simp only [quadratic_char_fun, ha, if_false],\n  simp_rw finite_field.is_square_iff hF ha,\nend\n\n/-- The quadratic character is multiplicative. -/\nlemma quadratic_char_fun_mul (a b : F) :\n  quadratic_char_fun F (a * b) = quadratic_char_fun F a * quadratic_char_fun F b :=\nbegin\n  by_cases ha : a = 0,\n  { rw [ha, zero_mul, quadratic_char_fun_zero, zero_mul], },\n  -- now `a \u2260 0`\n  by_cases hb : b = 0,\n  { rw [hb, mul_zero, quadratic_char_fun_zero, mul_zero], },\n  -- now `a \u2260 0` and `b \u2260 0`\n  have hab := mul_ne_zero ha hb,\n  by_cases hF : ring_char F = 2,\n  { -- case `ring_char F = 2`\n    rw [quadratic_char_fun_eq_one_of_char_two hF ha,\n        quadratic_char_fun_eq_one_of_char_two hF hb,\n        quadratic_char_fun_eq_one_of_char_two hF hab,\n        mul_one], },\n  { -- case of odd characteristic\n    rw [quadratic_char_fun_eq_pow_of_char_ne_two hF ha,\n        quadratic_char_fun_eq_pow_of_char_ne_two hF hb,\n        quadratic_char_fun_eq_pow_of_char_ne_two hF hab,\n        mul_pow],\n    cases finite_field.pow_dichotomy hF hb with hb' hb',\n    { simp only [hb', mul_one, eq_self_iff_true, if_true], },\n    { have h := ring.neg_one_ne_one_of_char_ne_two hF, -- `-1 \u2260 1`\n      simp only [hb', h, mul_neg, mul_one, if_false, ite_mul, neg_mul],\n      cases finite_field.pow_dichotomy hF ha with ha' ha';\n        simp only [ha', h, neg_neg, eq_self_iff_true, if_true, if_false], }, },\nend\n\nvariables (F)\n\n/-- The quadratic character as a multiplicative character. -/\n@[simps] def quadratic_char : mul_char F \u2124 :=\n{ to_fun := quadratic_char_fun F,\n  map_one' := quadratic_char_fun_one,\n  map_mul' := quadratic_char_fun_mul,\n  map_nonunit' := \u03bb a ha, by { rw of_not_not (mt ne.is_unit ha), exact quadratic_char_fun_zero, } }\n\nvariables {F}\n\n/-- The value of the quadratic character on `a` is zero iff `a = 0`. -/\nlemma quadratic_char_eq_zero_iff {a : F} : quadratic_char F a = 0 \u2194 a = 0 :=\nquadratic_char_fun_eq_zero_iff\n\n@[simp]\nlemma quadratic_char_zero : quadratic_char F 0 = 0 :=\nby simp only [quadratic_char_apply, quadratic_char_fun_zero]\n\n/-- For nonzero `a : F`, `quadratic_char F a = 1 \u2194 is_square a`. -/\nlemma quadratic_char_one_iff_is_square {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = 1 \u2194 is_square a :=\nby simp only [quadratic_char_apply, quadratic_char_fun, ha, (dec_trivial : (-1 : \u2124) \u2260 1),\n              if_false, ite_eq_left_iff, imp_false, not_not]\n\n/-- The quadratic character takes the value `1` on nonzero squares. -/\nlemma quadratic_char_sq_one' {a : F} (ha : a \u2260 0) : quadratic_char F (a ^ 2) = 1 :=\nby simp only [quadratic_char_fun, ha, pow_eq_zero_iff, nat.succ_pos', is_square_sq, if_true,\n              if_false, quadratic_char_apply]\n\n/-- The square of the quadratic character on nonzero arguments is `1`. -/\nlemma quadratic_char_sq_one {a : F} (ha : a \u2260 0) : (quadratic_char F a) ^ 2 = 1 :=\nby rwa [pow_two, \u2190 map_mul, \u2190 pow_two, quadratic_char_sq_one']\n\n/-- The quadratic character is `1` or `-1` on nonzero arguments. -/\nlemma quadratic_char_dichotomy {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = 1 \u2228 quadratic_char F a = -1 :=\nsq_eq_one_iff.1 $ quadratic_char_sq_one ha\n\n/-- The quadratic character is `1` or `-1` on nonzero arguments. -/\nlemma quadratic_char_eq_neg_one_iff_not_one {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = -1 \u2194 \u00ac quadratic_char F a = 1 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h\u2082, (or_iff_right h\u2082).mp (quadratic_char_dichotomy ha)\u27e9,\n  rw h,\n  norm_num,\nend\n\n/-- For `a : F`, `quadratic_char F a = -1 \u2194 \u00ac is_square a`. -/\nlemma quadratic_char_neg_one_iff_not_is_square {a : F} :\n  quadratic_char F a = -1 \u2194 \u00ac is_square a :=\nbegin\n  by_cases ha : a = 0,\n  { simp only [ha, is_square_zero, mul_char.map_zero, zero_eq_neg, one_ne_zero, not_true], },\n  { rw [quadratic_char_eq_neg_one_iff_not_one ha, quadratic_char_one_iff_is_square ha] },\nend\n\n/-- If `F` has odd characteristic, then `quadratic_char F` takes the value `-1`. -/\nlemma quadratic_char_exists_neg_one (hF : ring_char F \u2260 2) : \u2203 a, quadratic_char F a = -1 :=\n(finite_field.exists_nonsquare hF).imp $ \u03bb b h\u2081, quadratic_char_neg_one_iff_not_is_square.mpr h\u2081\n\n/-- If `ring_char F = 2`, then `quadratic_char F` takes the value `1` on nonzero elements. -/\nlemma quadratic_char_eq_one_of_char_two (hF : ring_char F = 2) {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = 1 :=\nquadratic_char_fun_eq_one_of_char_two hF ha\n\n/-- If `ring_char F` is odd, then `quadratic_char F a` can be computed in\nterms of `a ^ (fintype.card F / 2)`. -/\nlemma quadratic_char_eq_pow_of_char_ne_two (hF : ring_char F \u2260 2) {a : F} (ha : a \u2260 0) :\n  quadratic_char F a = if a ^ (fintype.card F / 2) = 1 then 1 else -1 :=\nquadratic_char_fun_eq_pow_of_char_ne_two hF ha\n\nlemma quadratic_char_eq_pow_of_char_ne_two' (hF : ring_char F \u2260 2) (a : F) :\n  (quadratic_char F a : F) = a ^ (fintype.card F / 2) :=\nbegin\n  by_cases ha : a = 0,\n  { have : 0 < fintype.card F / 2 := nat.div_pos fintype.one_lt_card two_pos,\n    simp only [ha, zero_pow this, quadratic_char_apply, quadratic_char_zero, int.cast_zero], },\n  { rw [quadratic_char_eq_pow_of_char_ne_two hF ha],\n    by_cases ha' : a ^ (fintype.card F / 2) = 1,\n    { simp only [ha', eq_self_iff_true, if_true, int.cast_one], },\n    { have ha'' := or.resolve_left (finite_field.pow_dichotomy hF ha) ha',\n      simp only [ha'', int.cast_ite, int.cast_one, int.cast_neg, ite_eq_right_iff],\n      exact eq.symm, } }\nend\n\nvariables (F)\n\n/-- The quadratic character is quadratic as a multiplicative character. -/\nlemma quadratic_char_is_quadratic : (quadratic_char F).is_quadratic :=\nbegin\n  intro a,\n  by_cases ha : a = 0,\n  { left, rw ha, exact quadratic_char_zero, },\n  { right, exact quadratic_char_dichotomy ha, },\nend\n\nvariables {F}\n\n/-- The quadratic character is nontrivial as a multiplicative character\nwhen the domain has odd characteristic. -/\nlemma quadratic_char_is_nontrivial (hF : ring_char F \u2260 2) : (quadratic_char F).is_nontrivial :=\nbegin\n  rcases quadratic_char_exists_neg_one hF with \u27e8a, ha\u27e9,\n  have hu : is_unit a := by { by_contra hf, rw map_nonunit _ hf at ha, norm_num at ha, },\n  refine \u27e8hu.unit, (_ : quadratic_char F a \u2260 1)\u27e9,\n  rw ha,\n  norm_num,\nend\n\n/-- The number of solutions to `x^2 = a` is determined by the quadratic character. -/\nlemma quadratic_char_card_sqrts (hF : ring_char F \u2260 2) (a : F) :\n  \u2191{x : F | x^2 = a}.to_finset.card = quadratic_char F a + 1 :=\nbegin\n  -- we consider the cases `a = 0`, `a` is a nonzero square and `a` is a nonsquare in turn\n  by_cases h\u2080 : a = 0,\n  { simp only [h\u2080, pow_eq_zero_iff, nat.succ_pos', int.coe_nat_succ, int.coe_nat_zero,\n               mul_char.map_zero, set.set_of_eq_eq_singleton, set.to_finset_card,\n               set.card_singleton], },\n  { set s := {x : F | x^2 = a}.to_finset with hs,\n    by_cases h : is_square a,\n    { rw (quadratic_char_one_iff_is_square h\u2080).mpr h,\n      rcases h with \u27e8b, h\u27e9,\n      rw [h, mul_self_eq_zero] at h\u2080,\n      have h\u2081 : s = [b, -b].to_finset := by\n      { ext x,\n        simp only [finset.mem_filter, finset.mem_univ, true_and, list.to_finset_cons,\n                   list.to_finset_nil, insert_emptyc_eq, finset.mem_insert, finset.mem_singleton],\n        rw \u2190 pow_two at h,\n        simp only [hs, set.mem_to_finset, set.mem_set_of_eq, h],\n        split,\n        { exact eq_or_eq_neg_of_sq_eq_sq _ _, },\n        { rintro (h\u2082 | h\u2082); rw h\u2082,\n          simp only [neg_sq], }, },\n      norm_cast,\n      rw  [h\u2081, list.to_finset_cons, list.to_finset_cons, list.to_finset_nil],\n      exact finset.card_doubleton\n              (ne.symm (mt (ring.eq_self_iff_eq_zero_of_char_ne_two hF).mp h\u2080)), },\n    { rw quadratic_char_neg_one_iff_not_is_square.mpr h,\n      simp only [int.coe_nat_eq_zero, finset.card_eq_zero, set.to_finset_card,\n                 fintype.card_of_finset, set.mem_set_of_eq, add_left_neg],\n      ext x,\n      simp only [iff_false, finset.mem_filter, finset.mem_univ, true_and, finset.not_mem_empty],\n      rw is_square_iff_exists_sq at h,\n      exact \u03bb h', h \u27e8_, h'.symm\u27e9, }, },\nend\n\nopen_locale big_operators\n\n/-- The sum over the values of the quadratic character is zero when the characteristic is odd. -/\nlemma quadratic_char_sum_zero (hF : ring_char F \u2260 2) : \u2211 (a : F), quadratic_char F a = 0 :=\nis_nontrivial.sum_eq_zero (quadratic_char_is_nontrivial hF)\n\nend quadratic_char\n\n/-!\n### Special values of the quadratic character\n\nWe express `quadratic_char F (-1)` in terms of `\u03c7\u2084`.\n-/\n\nsection special_values\n\nopen zmod mul_char\n\nvariables {F : Type*} [field F] [fintype F]\n\n/-- The value of the quadratic character at `-1` -/\nlemma quadratic_char_neg_one [decidable_eq F] (hF : ring_char F \u2260 2) :\n  quadratic_char F (-1) = \u03c7\u2084 (fintype.card F) :=\nbegin\n  have h := quadratic_char_eq_pow_of_char_ne_two hF (neg_ne_zero.mpr one_ne_zero),\n  rw [h, \u03c7\u2084_eq_neg_one_pow (finite_field.odd_card_of_char_ne_two hF)],\n  set n := fintype.card F / 2,\n  cases (nat.even_or_odd n) with h\u2082 h\u2082,\n  { simp only [even.neg_one_pow h\u2082, eq_self_iff_true, if_true], },\n  { simp only [odd.neg_one_pow h\u2082, ite_eq_right_iff],\n    exact \u03bb hf, false.rec (1 = -1) (ring.neg_one_ne_one_of_char_ne_two hF hf), },\nend\n\n/-- `-1` is a square in `F` iff `#F` is not congruent to `3` mod `4`. -/\nlemma finite_field.is_square_neg_one_iff : is_square (-1 : F) \u2194 fintype.card F % 4 \u2260 3 :=\nbegin\n  classical, -- suggested by the linter (instead of `[decidable_eq F]`)\n  by_cases hF : ring_char F = 2,\n  { simp only [finite_field.is_square_of_char_two hF, ne.def, true_iff],\n    exact (\u03bb hf, one_ne_zero  $ (nat.odd_of_mod_four_eq_three hf).symm.trans\n                              $ finite_field.even_card_of_char_two hF) },\n  { have h\u2081 := finite_field.odd_card_of_char_ne_two hF,\n    rw [\u2190 quadratic_char_one_iff_is_square (neg_ne_zero.mpr (one_ne_zero' F)),\n        quadratic_char_neg_one hF, \u03c7\u2084_nat_eq_if_mod_four, h\u2081],\n    simp only [nat.one_ne_zero, if_false, ite_eq_left_iff, ne.def, (dec_trivial : (-1 : \u2124) \u2260 1),\n               imp_false, not_not],\n    exact \u27e8\u03bb h, ne_of_eq_of_ne h (dec_trivial : 1 \u2260 3),\n           or.resolve_right (nat.odd_mod_four_iff.mp h\u2081)\u27e9, },\nend\n\n/-- The value of the quadratic character at `2` -/\nlemma quadratic_char_two [decidable_eq F] (hF : ring_char F \u2260 2) :\n  quadratic_char F 2 = \u03c7\u2088 (fintype.card F) :=\nis_quadratic.eq_of_eq_coe (quadratic_char_is_quadratic F) is_quadratic_\u03c7\u2088 hF\n  ((quadratic_char_eq_pow_of_char_ne_two' hF 2).trans (finite_field.two_pow_card hF))\n\n/-- `2` is a square in `F` iff `#F` is not congruent to `3` or `5` mod `8`. -/\nlemma finite_field.is_square_two_iff :\n  is_square (2 : F) \u2194 fintype.card F % 8 \u2260 3 \u2227 fintype.card F % 8 \u2260 5 :=\nbegin\n  classical,\n  by_cases hF : ring_char F = 2,\n  focus\n  { have h := finite_field.even_card_of_char_two hF,\n    simp only [finite_field.is_square_of_char_two hF, true_iff], },\n  rotate, focus\n  { have h := finite_field.odd_card_of_char_ne_two hF,\n    rw [\u2190 quadratic_char_one_iff_is_square (ring.two_ne_zero hF), quadratic_char_two hF,\n        \u03c7\u2088_nat_eq_if_mod_eight],\n    simp only [h, nat.one_ne_zero, if_false, ite_eq_left_iff, ne.def, (dec_trivial : (-1 : \u2124) \u2260 1),\n               imp_false, not_not], },\n  all_goals\n  { rw [\u2190 nat.mod_mod_of_dvd _ (by norm_num : 2 \u2223 8)] at h,\n    have h\u2081 := nat.mod_lt (fintype.card F) (dec_trivial : 0 < 8),\n    revert h\u2081 h,\n    generalize : fintype.card F % 8 = n,\n    dec_trivial!, }\nend\n\n/-- The value of the quadratic character at `-2` -/\nlemma quadratic_char_neg_two [decidable_eq F] (hF : ring_char F \u2260 2) :\n  quadratic_char F (-2) = \u03c7\u2088' (fintype.card F) :=\nbegin\n  rw [(by norm_num : (-2 : F) = (-1) * 2), map_mul, \u03c7\u2088'_eq_\u03c7\u2084_mul_\u03c7\u2088, quadratic_char_neg_one hF,\n      quadratic_char_two hF, @cast_nat_cast _ (zmod 4) _ _ _ (by norm_num : 4 \u2223 8)],\nend\n\n/-- `-2` is a square in `F` iff `#F` is not congruent to `5` or `7` mod `8`. -/\nlemma finite_field.is_square_neg_two_iff :\n  is_square (-2 : F) \u2194 fintype.card F % 8 \u2260 5 \u2227 fintype.card F % 8 \u2260 7 :=\nbegin\n  classical,\n  by_cases hF : ring_char F = 2,\n  focus\n  { have h := finite_field.even_card_of_char_two hF,\n    simp only [finite_field.is_square_of_char_two hF, true_iff], },\n  rotate, focus\n  { have h := finite_field.odd_card_of_char_ne_two hF,\n    rw [\u2190 quadratic_char_one_iff_is_square (neg_ne_zero.mpr (ring.two_ne_zero hF)),\n        quadratic_char_neg_two hF, \u03c7\u2088'_nat_eq_if_mod_eight],\n    simp only [h, nat.one_ne_zero, if_false, ite_eq_left_iff, ne.def, (dec_trivial : (-1 : \u2124) \u2260 1),\n               imp_false, not_not], },\n  all_goals\n  { rw [\u2190 nat.mod_mod_of_dvd _ (by norm_num : 2 \u2223 8)] at h,\n    have h\u2081 := nat.mod_lt (fintype.card F) (dec_trivial : 0 < 8),\n    revert h\u2081 h,\n    generalize : fintype.card F % 8 = n,\n    dec_trivial! }\nend\n\n/-- The relation between the values of the quadratic character of one field `F` at the\ncardinality of another field `F'` and of the quadratic character of `F'` at the cardinality\nof `F`. -/\nlemma quadratic_char_card_card [decidable_eq F] (hF : ring_char F \u2260 2) {F' : Type*} [field F']\n  [fintype F'] [decidable_eq F'] (hF' : ring_char F' \u2260 2) (h : ring_char F' \u2260 ring_char F) :\n  quadratic_char F (fintype.card F') = quadratic_char F' (quadratic_char F (-1) * fintype.card F) :=\nbegin\n  let \u03c7 := (quadratic_char F).ring_hom_comp (algebra_map \u2124 F'),\n  have h\u03c7\u2081 : \u03c7.is_nontrivial,\n  { obtain \u27e8a, ha\u27e9 := quadratic_char_exists_neg_one hF,\n    have hu : is_unit a,\n    { contrapose ha,\n      exact ne_of_eq_of_ne (map_nonunit (quadratic_char F) ha)\n             (mt zero_eq_neg.mp one_ne_zero), },\n    use hu.unit,\n    simp only [is_unit.unit_spec, ring_hom_comp_apply, eq_int_cast, ne.def, ha],\n    rw [int.cast_neg, int.cast_one],\n    exact ring.neg_one_ne_one_of_char_ne_two hF', },\n  have h\u03c7\u2082 : \u03c7.is_quadratic := is_quadratic.comp (quadratic_char_is_quadratic F) _,\n  have h := char.card_pow_card h\u03c7\u2081 h\u03c7\u2082 h hF',\n  rw [\u2190 quadratic_char_eq_pow_of_char_ne_two' hF'] at h,\n  exact (is_quadratic.eq_of_eq_coe (quadratic_char_is_quadratic F')\n             (quadratic_char_is_quadratic F) hF' h).symm,\nend\n\n/-- The value of the quadratic character at an odd prime `p` different from `ring_char F`. -/\nlemma quadratic_char_odd_prime [decidable_eq F] (hF : ring_char F \u2260 2) {p : \u2115} [fact p.prime]\n  (hp\u2081 : p \u2260 2) (hp\u2082 : ring_char F \u2260 p) :\n  quadratic_char F p = quadratic_char (zmod p) (\u03c7\u2084 (fintype.card F) * fintype.card F) :=\nbegin\n  rw [\u2190 quadratic_char_neg_one hF],\n  have h := quadratic_char_card_card hF (ne_of_eq_of_ne (ring_char_zmod_n p) hp\u2081)\n              (ne_of_eq_of_ne (ring_char_zmod_n p) hp\u2082.symm),\n  rwa [card p] at h,\nend\n\n/-- An odd prime `p` is a square in `F` iff the quadratic character of `zmod p` does not\ntake the value `-1` on `\u03c7\u2084(#F) * #F`. -/\nlemma finite_field.is_square_odd_prime_iff (hF : ring_char F \u2260 2) {p : \u2115} [fact p.prime]\n  (hp : p \u2260 2) :\n  is_square (p : F) \u2194 quadratic_char (zmod p) (\u03c7\u2084 (fintype.card F) * fintype.card F) \u2260 -1 :=\nbegin\n  classical,\n  by_cases hFp : ring_char F = p,\n  { rw [show (p : F) = 0, by { rw \u2190 hFp, exact ring_char.nat.cast_ring_char }],\n    simp only [is_square_zero, ne.def, true_iff, map_mul],\n    obtain \u27e8n, _, hc\u27e9 := finite_field.card F (ring_char F),\n    have hchar : ring_char F = ring_char (zmod p) := by {rw hFp, exact (ring_char_zmod_n p).symm},\n    conv {congr, to_lhs, congr, skip, rw [hc, nat.cast_pow, map_pow, hchar, map_ring_char], },\n    simp only [zero_pow n.pos, mul_zero, zero_eq_neg, one_ne_zero, not_false_iff], },\n  { rw [\u2190 iff.not_left (@quadratic_char_neg_one_iff_not_is_square F _ _ _ _),\n        quadratic_char_odd_prime hF hp],\n    exact hFp, },\nend\n\nend special_values\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/legendre_symbol/quadratic_char.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7252079829289255}}
{"text": "/-\nThis file defines the at-most-k Boolean cardinality constraint.\n\nAuthors: Cayden Codel, Jeremy Avigad, Marijn Heule\nCarnegie Mellon University\n-/\n\nimport data.list.basic\nimport cnf.literal\nimport cnf.assignment\nimport cnf.clause\nimport cardinality.distinct\n\nvariables {V : Type*} [decidable_eq V] [inhabited V]\n\nopen assignment\nopen clause\nopen list\nopen nat\nopen distinct\n\ndef amk (k : nat) (l : list bool) : bool := l.count tt \u2264 k\n\nnamespace amk\n\n@[simp] theorem amk_nil (k : nat) : amk k [] = tt := rfl\n\n@[simp] theorem amk_singleton_pos (k : nat) (b : bool) : amk (k + 1) [b] = tt :=\nby { cases b; simp [amk, count_singleton'] }\n\nprotected def eval (k : nat) (\u03c4 : assignment V) (l : list (literal V)) : bool :=\n  amk k (l.map (literal.eval \u03c4))\n\nvariables (k : nat) (\u03c4 : assignment V) (l : list (literal V)) (lit : literal V)\n\n@[simp] theorem eval_nil : amk.eval k \u03c4 [] = tt :=\nby simp only [amk.eval, amk, count_nil, to_bool_true_eq_tt, zero_le, map_nil]\n\n@[simp] theorem eval_singleton_pos : amk.eval (k + 1) \u03c4 [lit] = tt :=\nby { cases h : lit.eval \u03c4; simp [amk.eval, amk, count_singleton', h] }\n\n@[simp] theorem eval_singleton_zero : \n  (amk.eval 0 \u03c4 [lit] = tt) \u2194 lit.eval \u03c4 = ff :=\nbegin\n  cases h : (lit.eval \u03c4),\n  { split,\n    { tautology },\n    { intro _, simp [amk.eval, amk, h] } },\n  { split,\n    { intro hamk,\n      simp [amk.eval, amk, h] at hamk,\n      contradiction },\n    { intro h, contradiction } }\nend\n\ntheorem eval_tt_of_ge_length {k : nat} {l : list (literal V)} :\n  k \u2265 length l \u2192 \u2200 (\u03c4 : assignment V), amk.eval k \u03c4 l = tt :=\nbegin\n  intros hk \u03c4,\n  simp [amk.eval, amk],\n  have := count_le_length tt (map (literal.eval \u03c4) l),\n  rw length_map at this,\n  exact le_trans this hk\nend\n\ntheorem eval_cons_pos {k : nat} {\u03c4 : assignment V} {lit : literal V} : \n  lit.eval \u03c4 = tt \u2192 \u2200 l, amk.eval (k + 1) \u03c4 (lit :: l) = amk.eval k \u03c4 l :=\nassume hlit l, by simp [amk.eval, amk, hlit, succ_le_succ_iff]\n\ntheorem eval_cons_neg {k : nat} {\u03c4 : assignment V} {lit : literal V} :\n  lit.eval \u03c4 = ff \u2192 \u2200 l, amk.eval k \u03c4 (lit :: l) = amk.eval k \u03c4 l :=\nassume hlit l, by simp [amk.eval, amk, hlit]\n\ntheorem eval_tt_of_le_of_eval_tt {\u03c4 : assignment V} {l : list (literal V)} \n  {k\u2081 k\u2082 : nat} : k\u2081 \u2264 k\u2082 \u2192 amk.eval k\u2081 \u03c4 l = tt \u2192 amk.eval k\u2082 \u03c4 l = tt :=\nbegin\n  simp only [amk.eval, amk, ge_iff_le, to_bool_iff],\n  intros hk h\u2081,\n  exact le_trans h\u2081 hk  \nend\n\ntheorem eval_sublist {k : nat} {\u03c4 : assignment V} {l\u2081 l\u2082 : list (literal V)} :\n  l\u2081 <+ l\u2082 \u2192 amk.eval k \u03c4 l\u2082 = tt \u2192 amk.eval k \u03c4 l\u2081 = tt :=\nbegin\n  simp [amk.eval, amk],\n  intros hs h, \n  exact le_trans (sublist.count_le (sublist.map (literal.eval \u03c4) hs) tt) h\nend\n\ntheorem eval_drop {k : nat} {\u03c4 : assignment V} {l : list (literal V)} :\n  amk.eval k \u03c4 l = tt \u2192 \u2200 (i : nat), amk.eval k \u03c4 (l.drop i) = tt :=\nassume hamk i, eval_sublist (drop_sublist i l) hamk\n\ntheorem eval_take {k : nat} {\u03c4 : assignment V} {l : list (literal V)} :\n  amk.eval k \u03c4 l = tt \u2192 \u2200 (i : nat), amk.eval k \u03c4 (l.take i) = tt :=\nassume hamk i, eval_sublist (take_sublist i l) hamk \n\n/-! # amz -/\n\ntheorem amz_of_amz_cons {\u03c4 : assignment V} {l : list (literal V)} {lit : literal V} :\n  amk.eval 0 \u03c4 (lit :: l) = tt \u2192 amk.eval 0 \u03c4 l = tt :=\nbegin\n  simp [amk.eval, amk], cases literal.eval \u03c4 lit; simp\nend\n\n-- The special case where k = 0 is handled\ntheorem amz_eval_tt_iff_forall_eval_ff :\n  amk.eval 0 \u03c4 l = tt \u2194 (\u2200 (lit : literal V), lit \u2208 l \u2192 lit.eval \u03c4 = ff) :=\nbegin\n  split,\n  { simp [amk.eval, amk] },\n  { intro h,\n    rw [amk.eval, amk, to_bool_iff, le_zero_iff],\n    apply count_eq_zero_of_not_mem,\n    simpa }\nend\n\n-- Can be done with contrapose, somehow\ntheorem amz_eval_ff_iff_exists_eval_tt :\n  amk.eval 0 \u03c4 l = ff \u2194 (\u2203 (lit : literal V), lit \u2208 l \u2227 lit.eval \u03c4 = tt) :=\nbegin\n  split,\n  { contrapose, simp,\n    exact (amz_eval_tt_iff_forall_eval_ff \u03c4 l).mpr },\n  { contrapose, simp,\n    exact (amz_eval_tt_iff_forall_eval_ff \u03c4 l).mp }\nend\n\ntheorem eval_cons_pos_zero {\u03c4 : assignment V} {lit : literal V} :\n  lit.eval \u03c4 = tt \u2192 \u2200 l, amk.eval 0 \u03c4 (lit :: l) = ff :=\nbegin\n  intros hlit l,\n  apply (amz_eval_ff_iff_exists_eval_tt \u03c4 (lit :: l)).mpr,\n  use [lit, mem_cons_self _ _, hlit]\nend\n\n/-! # back to general theorems -/\n\ntheorem eval_tail_pos {k i : nat} {\u03c4 : assignment V} {l : list (literal V)}\n  {hi : i < length l} : (l.nth_le i hi).eval \u03c4 = tt \u2192\n  amk.eval (k + 1) \u03c4 (l.take (i + 1)) = amk.eval k \u03c4 (l.take i) :=\nbegin\n  intro hamk,\n  induction l with l\u2081 ls ih generalizing i k,\n  { simp },\n  { cases i,\n    { simp },\n    { rw [take, take],\n      rw nth_le at hamk,\n      rw [length, succ_lt_succ_iff] at hi,\n      cases h\u2081 : (l\u2081.eval \u03c4),\n      { rw [eval_cons_neg h\u2081, eval_cons_neg h\u2081],\n        exact ih hamk },\n      { cases k,\n        { rw eval_cons_pos_zero h\u2081, -- Can be tightened up\n          rw eval_cons_pos h\u2081,\n          by_contradiction,\n          rw [eq_tt_eq_not_eq_ff, amz_eval_tt_iff_forall_eval_ff] at h,\n          have : length (ls.take (i + 1)) = i + 1,\n          { have h := length_take (i + 1) ls,\n            have : min (i + 1) (length ls) = i + 1,\n            { simp [succ_le_of_lt hi] },\n            rw this at h,\n            exact h },\n          have hlen : i < length (ls.take (i + 1)),\n          { rw this,\n            exact lt_succ_self i },\n          have hmem := nth_le_mem _ _ hlen,\n          have : (ls.nth_le i _) = (ls.take (i.succ)).nth_le i hlen,\n          { rw this at hlen,\n            exact nth_le_take ls hi hlen },\n          rw \u2190 this at hmem,\n          have hff := h _ hmem,\n          have : literal.eval \u03c4 (ls.nth_le i hi) = tt,\n          { assumption },\n          rw this at hff,\n          contradiction },\n        { rw [eval_cons_pos h\u2081, eval_cons_pos h\u2081],\n          exact ih hamk } } } }\nend\n\ntheorem eval_tail_neg {k i : nat} {\u03c4 : assignment V} {l : list (literal V)}\n  {hi : i < length l} : (l.nth_le i hi).eval \u03c4 = ff \u2192\n  amk.eval k \u03c4 (l.take (i + 1)) = amk.eval k \u03c4 (l.take i) :=\nbegin\n  intro hamk,\n  induction l with l\u2081 ls ih generalizing i k,\n  { simp },\n  { cases i,\n    { simp at hamk, cases k; simp [hamk] },\n    { rw [take, take],\n      rw nth_le at hamk,\n      rw [length, succ_lt_succ_iff] at hi,\n      cases h\u2081 : (l\u2081.eval \u03c4),\n      { rw [eval_cons_neg h\u2081, eval_cons_neg h\u2081],\n        exact ih hamk },\n      { cases k,\n        { rw [eval_cons_pos_zero h\u2081, eval_cons_pos_zero h\u2081] },\n        { rw [eval_cons_pos h\u2081, eval_cons_pos h\u2081],\n          exact ih hamk } } } }\nend\n\n-- Can probably be shortened with the correct order of cases\ntheorem exists_amk_split {k : nat} {\u03c4 : assignment V} {l : list (literal V)} : \n  amk.eval k \u03c4 l = tt \u2192 \u2200 {k\u2081 k\u2082 : nat}, k\u2081 + k\u2082 = k \u2192 \n  \u2203 {l\u2081 l\u2082 : list (literal V)}, l\u2081 ++ l\u2082 = l \u2227\n  amk.eval k\u2081 \u03c4 l\u2081 = tt \u2227 amk.eval k\u2082 \u03c4 l\u2082 = tt :=\nbegin\n  intros hamk k\u2081 k\u2082 hks,\n  induction l with lit\u2081 ls ih generalizing k k\u2081 k\u2082,\n  { use [[], []],\n    simp },\n  { cases k,\n    { cases hlit\u2081 : (literal.eval \u03c4 lit\u2081),\n      { rw eval_cons_neg hlit\u2081 at hamk,\n        rcases ih hamk hks with \u27e8l\u2081, l\u2082, hls, hl\u2081, hl\u2082\u27e9,\n        use [(lit\u2081 :: l\u2081), l\u2082],\n        simp [hls, eval_cons_neg hlit\u2081, hl\u2081, hl\u2082] },\n      { rw [amz_eval_tt_iff_forall_eval_ff] at hamk,\n        rw (hamk _ (mem_cons_self lit\u2081 ls)) at hlit\u2081,\n        contradiction } },\n    { cases k\u2081,\n      { rw zero_add at hks, subst hks,\n        use [[], lit\u2081 :: ls],\n        simpa },\n      { cases hlit\u2081 : (literal.eval \u03c4 lit\u2081),\n        { rw eval_cons_neg hlit\u2081 at hamk,\n          rcases ih hamk hks with \u27e8l\u2081, l\u2082, hls, hl\u2081, hl\u2082\u27e9,\n          use [(lit\u2081 :: l\u2081), l\u2082],\n          simp [hls, eval_cons_neg hlit\u2081, hl\u2081, hl\u2082] },\n        { rw succ_add at hks,\n          rw eval_cons_pos hlit\u2081 at hamk,\n          rcases ih hamk (succ.inj hks) with \u27e8l\u2081, l\u2082, hls, hl\u2081, hl\u2082\u27e9,\n          use [(lit\u2081 :: l\u2081), l\u2082],\n          simp [hls, eval_cons_pos hlit\u2081, hl\u2081, hl\u2082] } } } }\nend\n\ntheorem eval_eq_amk_of_eqod {\u03c4\u2081 \u03c4\u2082 : assignment V} {l : list (literal V)} :\n  \u2200 (k : nat), (eqod \u03c4\u2081 \u03c4\u2082 (clause.vars l)) \u2192 amk.eval k \u03c4\u2081 l = amk.eval k \u03c4\u2082 l :=\nbegin\n  intros k heqod,\n  induction l with l ls ih generalizing k,\n  { simp only [eval_nil] },\n  { have := eval_eq_of_eqod_of_var_mem heqod (mem_vars_of_mem (mem_cons_self l ls)),\n    cases h : (l.eval \u03c4\u2081),\n    { rw eval_cons_neg h,\n      rw this at h,\n      rw eval_cons_neg h,\n      exact ih (eqod_subset (vars_subset_of_vars_cons _ _) heqod) k },\n    { cases k,\n      { rw eval_cons_pos_zero h,\n        rw this at h,\n        rw eval_cons_pos_zero h },\n      { rw eval_cons_pos h,\n        rw this at h,\n        rw eval_cons_pos h,\n        exact ih (eqod_subset (vars_subset_of_vars_cons _ _) heqod) k } } }\nend\n\n/-! # amo -/\n\ntheorem amo_eval_tt_iff_distinct_eval_ff_of_eval_tt \n  {\u03c4 : assignment V} {l : list (literal V)} :\n  amk.eval 1 \u03c4 l = tt \u2194 (\u2200 {lit\u2081 lit\u2082 : literal V}, \n  distinct lit\u2081 lit\u2082 l \u2192 lit\u2081.eval \u03c4 = tt \u2192 lit\u2082.eval \u03c4 = ff) :=\nbegin\n  induction l with l\u2081 ls ih,\n  { split,\n    { intros _ lit\u2081 lit\u2082 hdis,\n      exact absurd hdis (not_distinct_nil _ _) },\n    { rw eval_nil, tautology } },\n  { cases ls with l\u2082 ls,\n    { split,\n      { intros _ lit\u2081 lit\u2082 hdis,\n        exact absurd hdis (not_distinct_singleton _ _ _) },\n      { rw eval_singleton_pos, tautology } },\n    { split,\n      { intros heval lit\u2081 lit\u2082 hdis h\u2081,\n        have hmem\u2082 := mem_tail_of_distinct_cons hdis,\n        rcases hdis with \u27e8i, j, hi, hj, hij, hil, hjl\u27e9,\n        cases i,\n        { rw nth_le at hil,\n          rw [hil, eval_cons_pos h\u2081, amz_eval_tt_iff_forall_eval_ff] at heval,\n          exact heval lit\u2082 hmem\u2082 },\n        { cases j,\n          { linarith },\n          { have : distinct lit\u2081 lit\u2082 (l\u2082 :: ls),\n            { rw [length, succ_lt_succ_iff] at hi hj,\n              rw succ_lt_succ_iff at hij,\n              rw nth_le at hil hjl,\n              exact \u27e8i, j, hi, hj, hij, hil, hjl\u27e9 },\n            cases h : (literal.eval \u03c4 l\u2081),\n            { rw eval_cons_neg h at heval,\n              exact ih.mp heval this h\u2081 },\n            { rw [eval_cons_pos h, amz_eval_tt_iff_forall_eval_ff] at heval,\n              exact heval lit\u2082 hmem\u2082 } } } },\n      { intro h,\n        cases h\u2081 : (literal.eval \u03c4 l\u2081),\n        { rw eval_cons_neg h\u2081,\n          apply ih.mpr,\n          intros lit\u2081 lit\u2082 hdis' h\u2081',\n          exact h (distinct_cons_of_distinct l\u2081 hdis') h\u2081' },\n        { rw [eval_cons_pos h\u2081, amz_eval_tt_iff_forall_eval_ff],\n          intros x hx,\n          exact h (distinct_cons_of_mem l\u2081 hx) h\u2081 } } } }\nend\n\nend amk", "meta": {"author": "chasenorman", "repo": "verified-encodings-social-choice", "sha": "72f88c5a31ce30df5a04a99f726244c327b9a6f6", "save_path": "github-repos/lean/chasenorman-verified-encodings-social-choice", "path": "github-repos/lean/chasenorman-verified-encodings-social-choice/verified-encodings-social-choice-72f88c5a31ce30df5a04a99f726244c327b9a6f6/src/cardinality/amk.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7252079795103918}}
{"text": "import data.nat.prime data.multiset\nimport data.list_extra data.multiset_extra\n\nnamespace nat\n\nlemma list.coprime_prod {n : \u2115} {l : list \u2115} (h : list.all_prop (coprime n) l) : \n coprime n l.prod := \nbegin\n induction l with m l ih,\n {rw[list.prod_nil],exact coprime_one_right n},\n {rw[list.all_prop] at h,rw[list.prod_cons],\n  exact coprime.mul_right h.left (ih h.right),\n }\nend\n\nlemma multiset.coprime_prod {n : \u2115} {s : multiset \u2115}\n (h : multiset.all_prop (coprime n) s) : coprime n s.prod := \nbegin\n rcases s with \u27e8l\u27e9,\n have : quot.mk setoid.r l = (l : multiset \u2115) := rfl, rw[this] at *,\n rw[multiset.all_prop_coe] at h,rw[multiset.coe_prod],\n exact list.coprime_prod h\nend\n\nlemma list.coprime_prod_dvd_of_dvd {l : list \u2115} (hc : l.pairwise coprime) \n {n : \u2115} (hd : list.all_prop (\u03bb p, p \u2223 n) l) : l.prod \u2223 n := \nbegin\n induction l with m l ih,\n {rw[list.prod_nil],exact one_dvd n},\n {rw[list.pairwise_cons] at hc,\n  rw[list.all_prop] at hd,rw[list.prod_cons],\n  exact coprime.mul_dvd_of_dvd_of_dvd\n   (list.coprime_prod (list.all_prop_iff.mpr hc.left)) \n    hd.left (ih hc.right hd.right),\n }\nend\n\nlemma multiset.coprime_prod_dvd_of_dvd {s : multiset \u2115} (hc : s.pairwise coprime) \n {n : \u2115} (hd : multiset.all_prop (\u03bb p, p \u2223 n) s) : s.prod \u2223 n := \nbegin\n rcases s with \u27e8l\u27e9,\n have : quot.mk setoid.r l = (l : multiset \u2115) := rfl, rw[this] at *,\n have : symmetric coprime := \u03bb n m, coprime.symm,\n rw[multiset.pairwise_coe_iff_pairwise this] at hc,\n rw[multiset.all_prop_coe] at hd,\n rw[multiset.coe_prod],\n exact list.coprime_prod_dvd_of_dvd hc hd,\nend\n\nlemma list.nodup_prime_coprime \n {l : list \u2115} (hd : l.nodup) (hp : list.all_prop nat.prime l) : \n  l.pairwise coprime := \nbegin\n let hp' := list.all_prop_iff.mp hp,\n apply @list.pairwise.imp_of_mem \u2115 ne coprime l _ hd,\n {intros p q hpl hql hpq,exact (coprime_primes (hp' p hpl) (hp' q hql)).mpr hpq,},\nend\n\nlemma multiset.nodup_prime_coprime \n {s : multiset \u2115} (hd : s.nodup) (hp : multiset.all_prop nat.prime s) : \n  s.pairwise coprime := \nbegin\n rcases s with \u27e8l\u27e9,\n have : quot.mk setoid.r l = (l : multiset \u2115) := rfl, rw[this] at *,\n rw[multiset.coe_nodup] at hd,\n rw[multiset.all_prop_coe] at hp,\n have : symmetric coprime := \u03bb n m, coprime.symm,\n rw[multiset.pairwise_coe_iff_pairwise this],\n exact list.nodup_prime_coprime hd hp,\nend\n\ndef padic_valuation (p : \u2115) (n : \u2115) : \u2115 := \n  multiset.count p n.factors\n\ndef unique_factors (n : \u2115) := (n.factors : multiset \u2115).dedup\n\nlemma mem_unique_factors {n : \u2115} (h : n \u2260 0) (p : \u2115) :\n p \u2208 unique_factors n \u2194 p.prime \u2227 p \u2223 n := \nbegin\n dsimp[unique_factors],rw[multiset.mem_coe,list.mem_dedup],\n split,\n {intro h0,\n  let h1 := ((nat.mem_factors h).mp h0).1,\n  let h2 := (nat.mem_factors_iff_dvd h h1).mp h0,\n  exact \u27e8h1,h2\u27e9\n },{\n  rintro \u27e8h1,h2\u27e9,exact (nat.mem_factors_iff_dvd h h1).mpr h2,\n }\nend\n\nlemma unique_factors_coprime (n : \u2115) :\n (unique_factors n).pairwise coprime := \nbegin\n by_cases h : n = 0,\n {rw[h], \n  have : unique_factors 0 = 0 := \n   by { dsimp[unique_factors], rw[factors_zero], refl },\n   rw[this],apply multiset.pairwise_zero},\n apply multiset.nodup_prime_coprime,\n {apply multiset.nodup_dedup},\n {rw[multiset.all_prop_iff],intros p hp,\n  replace hp := multiset.mem_dedup.mp hp,\n  rw[multiset.mem_coe] at hp,\n  exact ((nat.mem_factors h).mp hp).1,\n }\nend\n\ndef prime_power_factors (n : \u2115) := \n (unique_factors n).map (\u03bb p, p ^ (padic_valuation p n))\n\ndef prod_factors' (n : \u2115) (h : n \u2260 0) :\n (prime_power_factors n).prod = n := \nbegin\n let f : multiset \u2115 := n.factors,\n let f\u2081 := f.dedup,\n let u := \u03bb p, multiset.prod (multiset.repeat p (multiset.count p f)),\n let v := \u03bb p, p ^ (multiset.count p f),\n change (f\u2081.map v).prod = n,\n have : v = u := by {ext p,dsimp[u,v],rw[multiset.prod_repeat]},\n rw[this],\n let e : f.prod = n := by {rw[multiset.coe_prod],exact nat.prod_factors h},\n rw[\u2190 multiset.eq_repeat_count f] at e,\n rw[multiset.prod_bind] at e,\n exact e,\nend\n\ndef square_free (n : \u2115) : Prop := \u2200 k, (k * k) \u2223 (n : \u2115) \u2192 k = 1\n\nlemma square_free_iff (n : \u2115) : \n square_free n \u2194 \u2200 p, nat.prime p \u2192 \u00ac (p * p \u2223 n) := \nbegin\n split,\n {intros h p p_prime hp,\n  exact nat.prime.ne_one p_prime (h p hp),\n },{\n  intros h k hk, by_contradiction hk',\n  let p := nat.min_fac k,\n  let p_prime := nat.min_fac_prime hk',\n  let pp_dvd : p * p \u2223 n := \n    dvd_trans (mul_dvd_mul k.min_fac_dvd k.min_fac_dvd) hk,\n  exact (h p p_prime pp_dvd).elim\n }\nend\n\ndef square_free_radical (n : \u2115) : \u2115 := \n (n.factors : multiset \u2115).dedup.prod\n\nlemma square_free_radical_dvd (n : \u2115) : \n (square_free_radical n) \u2223 n := begin\n by_cases hn : n = 0,\n {rw[hn],use 0,rw[mul_zero]},\n {\n  let fl := n.factors,\n  let fm : multiset \u2115 := fl,\n  let fs := fm.dedup,\n  let ft := fm - fs,\n  let hm : fm.prod = n :=\n   (multiset.coe_prod fl).trans (nat.prod_factors hn),\n  have hl : fs \u2264 fm := multiset.dedup_le n.factors,\n  have : fm = ft + fs := (tsub_add_cancel_of_le hl).symm,\n  rw[this,multiset.prod_add,mul_comm] at hm,\n  use ft.prod,exact hm.symm,\n }\nend\n\nlemma square_free_radical_primes {n : \u2115} (hn : n \u2260 0) \n {p : \u2115} (p_prime : nat.prime p) : \n  p \u2223 (square_free_radical n) \u2194 p \u2223 n := \nbegin\n split,\n {intro h,exact dvd_trans h (square_free_radical_dvd n)},\n {intro p_dvd_n, \n  let fl := n.factors,\n  let fm : multiset \u2115 := fl,\n  let fs := fm.dedup,\n  change p \u2223 fs.prod,\n  have : p \u2208 fm := (nat.mem_factors_iff_dvd hn p_prime).mpr p_dvd_n,\n  have : p \u2208 fs := multiset.mem_dedup.mpr this,\n  rw[\u2190 multiset.cons_erase this,multiset.prod_cons], \n  apply dvd_mul_right,\n }\nend\n\nlemma square_free_radical_dvd_iff {n : \u2115} (hn : n \u2260 0) (m : \u2115) : \n (square_free_radical n) \u2223 m \u2194 \u2200 p, nat.prime p \u2192 p \u2223 n \u2192 p \u2223 m := begin\nsplit,\n{intros h p p_prime p_dvd_n,\n exact dvd_trans ((square_free_radical_primes hn p_prime).mpr p_dvd_n) h,\n},{\n intro h,dsimp[square_free_radical],\n apply multiset.coprime_prod_dvd_of_dvd (unique_factors_coprime n),\n rw[multiset.all_prop_iff],intros p hp,\n replace hp := (mem_unique_factors hn p).mp hp,\n exact h p hp.left hp.right,\n}\nend\n\nlemma dvd_square_free_radical {n : \u2115} (hn : n \u2260 0) :\n \u2203 (k : \u2115), n \u2223 n.square_free_radical ^ k := \nbegin\n let f : multiset \u2115 := n.factors,\n let f\u2081 := f.dedup,\n rcases multiset.le_smul_dedup f with \u27e8k,hk\u27e9,\n use k,change n \u2223 f\u2081.prod ^ k,\n let f\u2082 := add_monoid.nsmul k f\u2081, change f \u2264 f\u2082 at hk,\n have : f\u2082.prod = f\u2081.prod ^ k := by {\n   dsimp[f\u2082],rw[multiset.prod_nsmul]\n },\n rw[\u2190 this],\n have : f.prod = n := by {rw[multiset.coe_prod,nat.prod_factors hn],},\n rw[\u2190 this,\u2190 tsub_add_cancel_of_le hk,multiset.prod_add],\n apply dvd_mul_left, \nend\n\nend nat", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/data/nat/square_free.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7251555642750991}}
{"text": "import .equipotent .data.fin.misc\n\nuniverse u \n\ndef finitary (\u03b1 : Type u) (n) := equipotent \u03b1 (fin n) \ndef permutation (n) := finitary (fin n) n \n\nnamespace finitary  \n\ndef eq_of_finitary_fin {m n} : finitary (fin m) n \u2192 m = n \n:= assume H, \n   decidable.by_contradiction $ assume ne, \n     or.elim (lt_or_gt_of_ne ne) \n       (assume Hlt, fin.not_injective_of_gt _ Hlt \n         (bijection.injective_of_bijection H.bijection.inverse)) \n         (assume Hgt, fin.not_injective_of_gt _ Hgt (bijection.injective_of_bijection H.bijection))\n\nvariable {\u03b1 : Type u}\n\nlemma univalence {m n} : finitary \u03b1 n \u2192 finitary \u03b1 m \u2192 n = m := \n  assume Hn Hm, \n     eq_of_finitary_fin (equipotent.trans (equipotent.symm Hn) Hm)      \n\nlemma {v} equipotent_of_eq {n} {\u03b2 : Type v} : finitary \u03b1 n \u2192 finitary \u03b2 n \u2192 equipotent \u03b1 \u03b2 \n:= assume Ha Hb, equipotent.trans Ha (equipotent.symm Hb)\n\ndef empty_0 : finitary empty 0 := \n{\n    map := empty.rec _, \n    bijection := {\n        inv := fin.elim0,\n        left_inverse_of_inv := empty.rec _,\n        right_inverse_of_inv := take i, absurd i.is_lt (nat.not_lt_zero _)\n    }\n} \nprivate lemma fin1_eq_zero : \u2200 i : fin 1, i = 0 \n| \u27e80, is_lt\u27e9 := rfl \n| \u27e8n+1, is_lt\u27e9 := absurd (nat.lt_of_succ_lt_succ is_lt) (nat.not_lt_zero _) \n\ninstance : subsingleton (fin 1) := subsingleton.intro \n  (\u03bb i j, begin rw fin1_eq_zero i, rw fin1_eq_zero j end) \nend finitary \n\n\n", "meta": {"author": "tizmd", "repo": "lean-finitary", "sha": "8958fdb3fa3d9fcc304e116fd339448875025e95", "save_path": "github-repos/lean/tizmd-lean-finitary", "path": "github-repos/lean/tizmd-lean-finitary/lean-finitary-8958fdb3fa3d9fcc304e116fd339448875025e95/finitary.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7251555511706095}}
{"text": "import data.real.basic\n\ndef converges_to (s : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (s n - a) < \u03b5\n\n-- BEGIN\nvariables {s t : \u2115 \u2192 \u211d} {a b : \u211d}\n\n#check sub_sub (a + b) \n\ntheorem converges_to_add\n  (cs : converges_to s a) (ct : converges_to t b):\nconverges_to (\u03bb n, s n + t n) (a + b) :=\nbegin\n  intros \u03b5 \u03b5pos, \n  dsimp,\n  have \u03b52pos : 0 < \u03b5 / 2,\n  { linarith },\n  cases cs (\u03b5 / 2) \u03b52pos with Ns hs,\n  cases ct (\u03b5 / 2) \u03b52pos with Nt ht,\n  use max Ns Nt,\n  intros n hn,\n  specialize hs n (le_trans (le_max_left Ns Nt) hn),\n  specialize ht n (le_trans (le_max_right Ns Nt) hn),\n  rw (by ring : s n + t n - (a + b) = (s n - a) + (t n - b)),\n  rw \u2190 add_halves \u03b5,\n  have triangle := abs_add (s n - a) (t n - b),\n  have lt_two_half_\u03b5 := add_lt_add hs ht,\n  exact lt_of_le_of_lt triangle lt_two_half_\u03b5,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.1_cases_exist/ex12_cases_converge_add.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7251555498596702}}
{"text": "/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport data.fin.basic\nimport data.list.sort\nimport data.list.duplicate\n\n/-!\n# Equivalence between `fin (length l)` and elements of a list\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGiven a list `l`,\n\n* if `l` has no duplicates, then `list.nodup.nth_le_equiv` is the equivalence between\n  `fin (length l)` and `{x // x \u2208 l}` sending `\u27e8i, hi\u27e9` to `\u27e8nth_le l i hi, _\u27e9` with the inverse\n  sending `\u27e8x, hx\u27e9` to `\u27e8index_of x l, _\u27e9`;\n\n* if `l` has no duplicates and contains every element of a type `\u03b1`, then\n  `list.nodup.nth_le_equiv_of_forall_mem_list` defines an equivalence between\n  `fin (length l)` and `\u03b1`;  if `\u03b1` does not have decidable equality, then\n  there is a bijection `list.nodup.nth_le_bijection_of_forall_mem_list`;\n\n* if `l` is sorted w.r.t. `(<)`, then `list.sorted.nth_le_iso` is the same bijection reinterpreted\n  as an `order_iso`.\n\n-/\n\nnamespace list\n\nvariable {\u03b1 : Type*}\n\nnamespace nodup\n\n/-- If `l` lists all the elements of `\u03b1` without duplicates, then `list.nth_le` defines\na bijection `fin l.length \u2192 \u03b1`.  See `list.nodup.nth_le_equiv_of_forall_mem_list`\nfor a version giving an equivalence when there is decidable equality. -/\n@[simps]\ndef nth_le_bijection_of_forall_mem_list (l : list \u03b1) (nd : l.nodup) (h : \u2200 (x : \u03b1), x \u2208 l) :\n  {f : fin l.length \u2192 \u03b1 // function.bijective f} :=\n\u27e8\u03bb i, l.nth_le i i.property, \u03bb i j h, fin.ext $ (nd.nth_le_inj_iff _ _).1 h,\n \u03bb x, let \u27e8i, hi, hl\u27e9 := list.mem_iff_nth_le.1 (h x) in \u27e8\u27e8i, hi\u27e9, hl\u27e9\u27e9\n\nvariable [decidable_eq \u03b1]\n\n/-- If `l` has no duplicates, then `list.nth_le` defines an equivalence between `fin (length l)` and\nthe set of elements of `l`. -/\n@[simps]\ndef nth_le_equiv (l : list \u03b1) (H : nodup l) : fin (length l) \u2243 {x // x \u2208 l} :=\n{ to_fun := \u03bb i, \u27e8nth_le l i i.2, nth_le_mem l i i.2\u27e9,\n  inv_fun := \u03bb x, \u27e8index_of \u2191x l, index_of_lt_length.2 x.2\u27e9,\n  left_inv := \u03bb i, by simp [H],\n  right_inv := \u03bb x, by simp }\n\n/-- If `l` lists all the elements of `\u03b1` without duplicates, then `list.nth_le` defines\nan equivalence between `fin l.length` and `\u03b1`.\n\nSee `list.nodup.nth_le_bijection_of_forall_mem_list` for a version without\ndecidable equality. -/\n@[simps]\ndef nth_le_equiv_of_forall_mem_list (l : list \u03b1) (nd : l.nodup) (h : \u2200 (x : \u03b1), x \u2208 l) :\n  fin l.length \u2243 \u03b1 :=\n{ to_fun := \u03bb i, l.nth_le i i.2,\n  inv_fun := \u03bb a, \u27e8_, index_of_lt_length.2 (h a)\u27e9,\n  left_inv := \u03bb i, by simp [nd],\n  right_inv := \u03bb a, by simp }\n\nend nodup\n\nnamespace sorted\n\nvariables [preorder \u03b1] {l : list \u03b1}\n\nlemma nth_le_mono (h : l.sorted (\u2264)) :\n  monotone (\u03bb i : fin l.length, l.nth_le i i.2) :=\n\u03bb i j, h.rel_nth_le_of_le _ _\n\nlemma nth_le_strict_mono (h : l.sorted (<)) :\n  strict_mono (\u03bb i : fin l.length, l.nth_le i i.2) :=\n\u03bb i j, h.rel_nth_le_of_lt _ _\n\nvariable [decidable_eq \u03b1]\n\n/-- If `l` is a list sorted w.r.t. `(<)`, then `list.nth_le` defines an order isomorphism between\n`fin (length l)` and the set of elements of `l`. -/\ndef nth_le_iso (l : list \u03b1) (H : sorted (<) l) : fin (length l) \u2243o {x // x \u2208 l} :=\n{ to_equiv := H.nodup.nth_le_equiv l,\n  map_rel_iff' := \u03bb i j, H.nth_le_strict_mono.le_iff_le }\n\nvariables (H : sorted (<) l) {x : {x // x \u2208 l}} {i : fin l.length}\n\n@[simp] lemma coe_nth_le_iso_apply : (H.nth_le_iso l i : \u03b1) = nth_le l i i.2 := rfl\n@[simp] lemma coe_nth_le_iso_symm_apply : ((H.nth_le_iso l).symm x : \u2115) = index_of \u2191x l := rfl\n\nend sorted\n\nsection sublist\n\n/--\nIf there is `f`, an order-preserving embedding of `\u2115` into `\u2115` such that\nany element of `l` found at index `ix` can be found at index `f ix` in `l'`,\nthen `sublist l l'`.\n-/\n\n\n/--\nA `l : list \u03b1` is `sublist l l'` for `l' : list \u03b1` iff\nthere is `f`, an order-preserving embedding of `\u2115` into `\u2115` such that\nany element of `l` found at index `ix` can be found at index `f ix` in `l'`.\n-/\nlemma sublist_iff_exists_order_embedding_nth_eq {l l' : list \u03b1} :\n  l <+ l' \u2194 \u2203 (f : \u2115 \u21aao \u2115), \u2200 (ix : \u2115), l.nth ix = l'.nth (f ix) :=\nbegin\n  split,\n  { intro H,\n    induction H with xs ys y H IH xs ys x H IH,\n    { simp },\n    { obtain \u27e8f, hf\u27e9 := IH,\n      refine \u27e8f.trans (order_embedding.of_strict_mono (+ 1) (\u03bb _, by simp)), _\u27e9,\n      simpa using hf },\n    { obtain \u27e8f, hf\u27e9 := IH,\n      refine \u27e8order_embedding.of_map_le_iff\n        (\u03bb (ix : \u2115), if ix = 0 then 0 else (f ix.pred).succ) _, _\u27e9,\n      { rintro \u27e8_|a\u27e9 \u27e8_|b\u27e9;\n        simp [nat.succ_le_succ_iff] },\n      { rintro \u27e8_|i\u27e9,\n        { simp },\n        { simpa using hf _ } } } },\n  { rintro \u27e8f, hf\u27e9,\n    exact sublist_of_order_embedding_nth_eq f hf }\nend\n\n/--\nA `l : list \u03b1` is `sublist l l'` for `l' : list \u03b1` iff\nthere is `f`, an order-preserving embedding of `fin l.length` into `fin l'.length` such that\nany element of `l` found at index `ix` can be found at index `f ix` in `l'`.\n-/\nlemma sublist_iff_exists_fin_order_embedding_nth_le_eq {l l' : list \u03b1} :\n  l <+ l' \u2194 \u2203 (f : fin l.length \u21aao fin l'.length),\n    \u2200 (ix : fin l.length), l.nth_le ix ix.is_lt = l'.nth_le (f ix) (f ix).is_lt :=\nbegin\n  rw sublist_iff_exists_order_embedding_nth_eq,\n  split,\n  { rintro \u27e8f, hf\u27e9,\n    have h : \u2200 {i : \u2115} (h : i < l.length), f i < l'.length,\n    { intros i hi,\n      specialize hf i,\n      rw [nth_le_nth hi, eq_comm, nth_eq_some] at hf,\n      obtain \u27e8h, -\u27e9 := hf,\n      exact h },\n    refine \u27e8order_embedding.of_map_le_iff (\u03bb ix, \u27e8f ix, h ix.is_lt\u27e9) _, _\u27e9,\n    { simp },\n    { intro i,\n      apply option.some_injective,\n      simpa [\u2190nth_le_nth] using hf _ } },\n  { rintro \u27e8f, hf\u27e9,\n    refine \u27e8order_embedding.of_strict_mono\n      (\u03bb i, if hi : i < l.length then f \u27e8i, hi\u27e9 else i + l'.length) _, _\u27e9,\n    { intros i j h,\n      dsimp only,\n      split_ifs with hi hj hj hi,\n      { simpa using h },\n      { rw add_comm,\n        exact lt_add_of_lt_of_pos (fin.is_lt _) (i.zero_le.trans_lt h) },\n      { exact absurd (h.trans hj) hi },\n      { simpa using h } },\n    { intro i,\n      simp only [order_embedding.coe_of_strict_mono],\n      split_ifs with hi,\n      { rw [nth_le_nth hi, nth_le_nth, \u2190hf],\n        simp },\n      { rw [nth_len_le, nth_len_le],\n        { simp },\n        { simpa using hi } } } }\nend\n\n/--\nAn element `x : \u03b1` of `l : list \u03b1` is a duplicate iff it can be found\nat two distinct indices `n m : \u2115` inside the list `l`.\n-/\nlemma duplicate_iff_exists_distinct_nth_le {l : list \u03b1} {x : \u03b1} :\n  l.duplicate x \u2194 \u2203 (n : \u2115) (hn : n < l.length) (m : \u2115) (hm : m < l.length) (h : n < m),\n    x = l.nth_le n hn \u2227 x = l.nth_le m hm :=\nbegin\n  classical,\n  rw [duplicate_iff_two_le_count, le_count_iff_replicate_sublist,\n      sublist_iff_exists_fin_order_embedding_nth_le_eq],\n  split,\n  { rintro \u27e8f, hf\u27e9,\n    refine \u27e8f \u27e80, by simp\u27e9, fin.is_lt _, f \u27e81, by simp\u27e9, fin.is_lt _, by simp, _, _\u27e9,\n    { simpa using hf \u27e80, by simp\u27e9 },\n    { simpa using hf \u27e81, by simp\u27e9 } },\n  { rintro \u27e8n, hn, m, hm, hnm, h, h'\u27e9,\n    refine \u27e8order_embedding.of_strict_mono (\u03bb i, if (i : \u2115) = 0 then \u27e8n, hn\u27e9 else \u27e8m, hm\u27e9) _, _\u27e9,\n    { rintros \u27e8\u27e8_|i\u27e9, hi\u27e9 \u27e8\u27e8_|j\u27e9, hj\u27e9,\n      { simp },\n      { simp [hnm] },\n      { simp },\n      { simp only [nat.lt_succ_iff, nat.succ_le_succ_iff, replicate, length, nonpos_iff_eq_zero]\n          at hi hj,\n        simp [hi, hj] } },\n    { rintros \u27e8\u27e8_|i\u27e9, hi\u27e9,\n      { simpa using h },\n      { simpa using h' } } }\nend\n\nend sublist\n\nend list\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/list/nodup_equiv_fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7250454695292174}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning, Patrick Lutz\n-/\n\nimport group_theory.perm.cycle_type\nimport analysis.complex.polynomial\nimport field_theory.galois\n\n/-!\n# Galois Groups of Polynomials\n\nIn this file, we introduce the Galois group of a polynomial `p` over a field `F`,\ndefined as the automorphism group of its splitting field. We also provide\nsome results about some extension `E` above `p.splitting_field`, and some specific\nresults about the Galois groups of \u211a-polynomials with specific numbers of non-real roots.\n\n## Main definitions\n\n- `polynomial.gal p`: the Galois group of a polynomial p.\n- `polynomial.gal.restrict p E`: the restriction homomorphism `(E \u2243\u2090[F] E) \u2192 gal p`.\n- `polynomial.gal.gal_action p E`: the action of `gal p` on the roots of `p` in `E`.\n\n## Main results\n\n- `polynomial.gal.restrict_smul`: `restrict p E` is compatible with `gal_action p E`.\n- `polynomial.gal.gal_action_hom_injective`: `gal p` acting on the roots of `p` in `E` is faithful.\n- `polynomial.gal.restrict_prod_injective`: `gal (p * q)` embeds as a subgroup of `gal p \u00d7 gal q`.\n- `polynomial.gal.card_of_separable`: For a separable polynomial, its Galois group has cardinality\nequal to the dimension of its splitting field over `F`.\n- `polynomial.gal.gal_action_hom_bijective_of_prime_degree`:\nAn irreducible polynomial of prime degree with two non-real roots has full Galois group.\n\n## Other results\n- `polynomial.gal.card_complex_roots_eq_card_real_add_card_not_gal_inv`: The number of complex roots\nequals the number of real roots plus the number of roots not fixed by complex conjugation\n(i.e. with some imaginary component).\n\n-/\n\nnoncomputable theory\nopen_locale classical\n\nopen finite_dimensional\n\nnamespace polynomial\n\nvariables {F : Type*} [field F] (p q : polynomial F) (E : Type*) [field E] [algebra F E]\n\n/-- The Galois group of a polynomial. -/\n@[derive [group, fintype]]\ndef gal := p.splitting_field \u2243\u2090[F] p.splitting_field\n\nnamespace gal\n\ninstance : has_coe_to_fun p.gal (\u03bb _, p.splitting_field \u2192 p.splitting_field) :=\nalg_equiv.has_coe_to_fun\n\n@[ext] lemma ext {\u03c3 \u03c4 : p.gal} (h : \u2200 x \u2208 p.root_set p.splitting_field, \u03c3 x = \u03c4 x) : \u03c3 = \u03c4 :=\nbegin\n  refine alg_equiv.ext (\u03bb x, (alg_hom.mem_equalizer \u03c3.to_alg_hom \u03c4.to_alg_hom x).mp\n      ((set_like.ext_iff.mp _ x).mpr algebra.mem_top)),\n  rwa [eq_top_iff, \u2190splitting_field.adjoin_roots, algebra.adjoin_le_iff],\nend\n\n/-- If `p` splits in `F` then the `p.gal` is trivial. -/\ndef unique_gal_of_splits (h : p.splits (ring_hom.id F)) : unique p.gal :=\n{ default := 1,\n  uniq := \u03bb f, alg_equiv.ext (\u03bb x, by { obtain \u27e8y, rfl\u27e9 := algebra.mem_bot.mp\n    ((set_like.ext_iff.mp ((is_splitting_field.splits_iff _ p).mp h) x).mp algebra.mem_top),\n    rw [alg_equiv.commutes, alg_equiv.commutes] }) }\n\ninstance [h : fact (p.splits (ring_hom.id F))] : unique p.gal :=\nunique_gal_of_splits _ (h.1)\n\ninstance unique_gal_zero : unique (0 : polynomial F).gal :=\nunique_gal_of_splits _ (splits_zero _)\n\ninstance unique_gal_one : unique (1 : polynomial F).gal :=\nunique_gal_of_splits _ (splits_one _)\n\ninstance unique_gal_C (x : F) : unique (C x).gal :=\nunique_gal_of_splits _ (splits_C _ _)\n\ninstance unique_gal_X : unique (X : polynomial F).gal :=\nunique_gal_of_splits _ (splits_X _)\n\ninstance unique_gal_X_sub_C (x : F) : unique (X - C x).gal :=\nunique_gal_of_splits _ (splits_X_sub_C _)\n\ninstance unique_gal_X_pow (n : \u2115) : unique (X ^ n : polynomial F).gal :=\nunique_gal_of_splits _ (splits_X_pow _ _)\n\ninstance [h : fact (p.splits (algebra_map F E))] : algebra p.splitting_field E :=\n(is_splitting_field.lift p.splitting_field p h.1).to_ring_hom.to_algebra\n\ninstance [h : fact (p.splits (algebra_map F E))] : is_scalar_tower F p.splitting_field E :=\nis_scalar_tower.of_algebra_map_eq\n  (\u03bb x, ((is_splitting_field.lift p.splitting_field p h.1).commutes x).symm)\n\n-- The `algebra p.splitting_field E` instance above behaves badly when\n-- `E := p.splitting_field`, since it may result in a unification problem\n-- `is_splitting_field.lift.to_ring_hom.to_algebra =?= algebra.id`,\n-- which takes an extremely long time to resolve, causing timeouts.\n-- Since we don't really care about this definition, marking it as irreducible\n-- causes that unification to error out early.\nattribute [irreducible] gal.algebra\n\n/-- Restrict from a superfield automorphism into a member of `gal p`. -/\ndef restrict [fact (p.splits (algebra_map F E))] : (E \u2243\u2090[F] E) \u2192* p.gal :=\nalg_equiv.restrict_normal_hom p.splitting_field\n\nlemma restrict_surjective [fact (p.splits (algebra_map F E))] [normal F E] :\n  function.surjective (restrict p E) :=\nalg_equiv.restrict_normal_hom_surjective E\n\nsection roots_action\n\n/-- The function taking `roots p p.splitting_field` to `roots p E`. This is actually a bijection,\nsee `polynomial.gal.map_roots_bijective`. -/\ndef map_roots [fact (p.splits (algebra_map F E))] :\n  root_set p p.splitting_field \u2192 root_set p E :=\n\u03bb x, \u27e8is_scalar_tower.to_alg_hom F p.splitting_field E x, begin\n  have key := subtype.mem x,\n  by_cases p = 0,\n  { simp only [h, root_set_zero] at key,\n    exact false.rec _ key },\n  { rw [mem_root_set h, aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end\u27e9\n\nlemma map_roots_bijective [h : fact (p.splits (algebra_map F E))] :\n  function.bijective (map_roots p E) :=\nbegin\n  split,\n  { exact \u03bb _ _ h, subtype.ext (ring_hom.injective _ (subtype.ext_iff.mp h)) },\n  { intro y,\n    -- this is just an equality of two different ways to write the roots of `p` as an `E`-polynomial\n    have key := roots_map\n      (is_scalar_tower.to_alg_hom F p.splitting_field E : p.splitting_field \u2192+* E)\n      ((splits_id_iff_splits _).mpr (is_splitting_field.splits p.splitting_field p)),\n    rw [map_map, alg_hom.comp_algebra_map] at key,\n    have hy := subtype.mem y,\n    simp only [root_set, finset.mem_coe, multiset.mem_to_finset, key, multiset.mem_map] at hy,\n    rcases hy with \u27e8x, hx1, hx2\u27e9,\n    exact \u27e8\u27e8x, multiset.mem_to_finset.mpr hx1\u27e9, subtype.ext hx2\u27e9 }\nend\n\n/-- The bijection between `root_set p p.splitting_field` and `root_set p E`. -/\ndef roots_equiv_roots [fact (p.splits (algebra_map F E))] :\n  (root_set p p.splitting_field) \u2243 (root_set p E) :=\nequiv.of_bijective (map_roots p E) (map_roots_bijective p E)\n\ninstance gal_action_aux : mul_action p.gal (root_set p p.splitting_field) :=\n{ smul := \u03bb \u03d5 x, \u27e8\u03d5 x, begin\n    have key := subtype.mem x,\n    --simp only [root_set, finset.mem_coe, multiset.mem_to_finset] at *,\n    by_cases p = 0,\n    { simp only [h, root_set_zero] at key,\n      exact false.rec _ key },\n    { rw mem_root_set h,\n      change aeval (\u03d5.to_alg_hom x) p = 0,\n      rw [aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end\u27e9,\n  one_smul := \u03bb _, by { ext, refl },\n  mul_smul := \u03bb _ _ _, by { ext, refl } }\n\n/-- The action of `gal p` on the roots of `p` in `E`. -/\ninstance gal_action [fact (p.splits (algebra_map F E))] : mul_action p.gal (root_set p E) :=\n{ smul := \u03bb \u03d5 x, roots_equiv_roots p E (\u03d5 \u2022 ((roots_equiv_roots p E).symm x)),\n  one_smul := \u03bb _, by simp only [equiv.apply_symm_apply, one_smul],\n  mul_smul := \u03bb _ _ _, by simp only [equiv.apply_symm_apply, equiv.symm_apply_apply, mul_smul] }\n\nvariables {p E}\n\n/-- `polynomial.gal.restrict p E` is compatible with `polynomial.gal.gal_action p E`. -/\n@[simp] lemma restrict_smul [fact (p.splits (algebra_map F E))]\n  (\u03d5 : E \u2243\u2090[F] E) (x : root_set p E) : \u2191((restrict p E \u03d5) \u2022 x) = \u03d5 x :=\nbegin\n  let \u03c8 := alg_equiv.of_injective_field (is_scalar_tower.to_alg_hom F p.splitting_field E),\n  change \u2191(\u03c8 (\u03c8.symm _)) = \u03d5 x,\n  rw alg_equiv.apply_symm_apply \u03c8,\n  change \u03d5 (roots_equiv_roots p E ((roots_equiv_roots p E).symm x)) = \u03d5 x,\n  rw equiv.apply_symm_apply (roots_equiv_roots p E),\nend\n\nvariables (p E)\n\n/-- `polynomial.gal.gal_action` as a permutation representation -/\ndef gal_action_hom [fact (p.splits (algebra_map F E))] : p.gal \u2192* equiv.perm (root_set p E) :=\n{ to_fun := \u03bb \u03d5, equiv.mk (\u03bb x, \u03d5 \u2022 x) (\u03bb x, \u03d5\u207b\u00b9 \u2022 x)\n  (\u03bb x, inv_smul_smul \u03d5 x) (\u03bb x, smul_inv_smul \u03d5 x),\n  map_one' := by { ext1 x, exact mul_action.one_smul x },\n  map_mul' := \u03bb x y, by { ext1 z, exact mul_action.mul_smul x y z } }\n\nlemma gal_action_hom_restrict [fact (p.splits (algebra_map F E))]\n  (\u03d5 : E \u2243\u2090[F] E) (x : root_set p E) : \u2191(gal_action_hom p E (restrict p E \u03d5) x) = \u03d5 x :=\nrestrict_smul \u03d5 x\n\n/-- `gal p` embeds as a subgroup of permutations of the roots of `p` in `E`. -/\nlemma gal_action_hom_injective [fact (p.splits (algebra_map F E))] :\n  function.injective (gal_action_hom p E) :=\nbegin\n  rw monoid_hom.injective_iff,\n  intros \u03d5 h\u03d5,\n  ext x hx,\n  have key := equiv.perm.ext_iff.mp h\u03d5 (roots_equiv_roots p E \u27e8x, hx\u27e9),\n  change roots_equiv_roots p E (\u03d5 \u2022 (roots_equiv_roots p E).symm\n    (roots_equiv_roots p E \u27e8x, hx\u27e9)) = roots_equiv_roots p E \u27e8x, hx\u27e9 at key,\n  rw equiv.symm_apply_apply at key,\n  exact subtype.ext_iff.mp (equiv.injective (roots_equiv_roots p E) key),\nend\n\nend roots_action\n\nvariables {p q}\n\n/-- `polynomial.gal.restrict`, when both fields are splitting fields of polynomials. -/\ndef restrict_dvd (hpq : p \u2223 q) : q.gal \u2192* p.gal :=\nif hq : q = 0 then 1 else @restrict F _ p _ _ _\n  \u27e8splits_of_splits_of_dvd (algebra_map F q.splitting_field) hq (splitting_field.splits q) hpq\u27e9\n\nlemma restrict_dvd_surjective (hpq : p \u2223 q) (hq : q \u2260 0) :\n  function.surjective (restrict_dvd hpq) :=\nby simp only [restrict_dvd, dif_neg hq, restrict_surjective]\n\nvariables (p q)\n\n/-- The Galois group of a product maps into the product of the Galois groups.  -/\ndef restrict_prod : (p * q).gal \u2192* p.gal \u00d7 q.gal :=\nmonoid_hom.prod (restrict_dvd (dvd_mul_right p q)) (restrict_dvd (dvd_mul_left q p))\n\n/-- `polynomial.gal.restrict_prod` is actually a subgroup embedding. -/\nlemma restrict_prod_injective : function.injective (restrict_prod p q) :=\nbegin\n  by_cases hpq : (p * q) = 0,\n  { haveI : unique (p * q).gal, { rw hpq, apply_instance },\n    exact \u03bb f g h, eq.trans (unique.eq_default f) (unique.eq_default g).symm },\n  intros f g hfg,\n  dsimp only [restrict_prod, restrict_dvd] at hfg,\n  simp only [dif_neg hpq, monoid_hom.prod_apply, prod.mk.inj_iff] at hfg,\n  ext x hx,\n  rw [root_set, map_mul, polynomial.roots_mul] at hx,\n  cases multiset.mem_add.mp (multiset.mem_to_finset.mp hx) with h h,\n  { haveI : fact (p.splits (algebra_map F (p * q).splitting_field)) :=\n      \u27e8splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_right p q)\u27e9,\n    have key : x = algebra_map (p.splitting_field) (p * q).splitting_field\n      ((roots_equiv_roots p _).inv_fun \u27e8x, multiset.mem_to_finset.mpr h\u27e9) :=\n      subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots p _) \u27e8x, _\u27e9).symm,\n    rw [key, \u2190alg_equiv.restrict_normal_commutes, \u2190alg_equiv.restrict_normal_commutes],\n    exact congr_arg _ (alg_equiv.ext_iff.mp hfg.1 _) },\n  { haveI : fact (q.splits (algebra_map F (p * q).splitting_field)) :=\n      \u27e8splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_left q p)\u27e9,\n    have key : x = algebra_map (q.splitting_field) (p * q).splitting_field\n      ((roots_equiv_roots q _).inv_fun \u27e8x, multiset.mem_to_finset.mpr h\u27e9) :=\n      subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots q _) \u27e8x, _\u27e9).symm,\n    rw [key, \u2190alg_equiv.restrict_normal_commutes, \u2190alg_equiv.restrict_normal_commutes],\n    exact congr_arg _ (alg_equiv.ext_iff.mp hfg.2 _) },\n  { rwa [ne.def, mul_eq_zero, map_eq_zero, map_eq_zero, \u2190mul_eq_zero] }\nend\n\n\n\n/-- `p` splits in the splitting field of `p \u2218 q`, for `q` non-constant. -/\nlemma splits_in_splitting_field_of_comp (hq : q.nat_degree \u2260 0) :\n  p.splits (algebra_map F (p.comp q).splitting_field) :=\nbegin\n  let P : polynomial F \u2192 Prop := \u03bb r, r.splits (algebra_map F (r.comp q).splitting_field),\n  have key1 : \u2200 {r : polynomial F}, irreducible r \u2192 P r,\n  { intros r hr,\n    by_cases hr' : nat_degree r = 0,\n    { exact splits_of_nat_degree_le_one _ (le_trans (le_of_eq hr') zero_le_one) },\n    obtain \u27e8x, hx\u27e9 := exists_root_of_splits _ (splitting_field.splits (r.comp q))\n      (\u03bb h, hr' ((mul_eq_zero.mp (nat_degree_comp.symm.trans\n        (nat_degree_eq_of_degree_eq_some h))).resolve_right hq)),\n    rw [\u2190aeval_def, aeval_comp] at hx,\n    have h_normal : normal F (r.comp q).splitting_field := splitting_field.normal (r.comp q),\n    have qx_int := normal.is_integral h_normal (aeval x q),\n    exact splits_of_splits_of_dvd _\n      (minpoly.ne_zero qx_int)\n      (normal.splits h_normal _)\n      ((minpoly.irreducible qx_int).dvd_symm hr (minpoly.dvd F _ hx)) },\n  have key2 : \u2200 {p\u2081 p\u2082 : polynomial F}, P p\u2081 \u2192 P p\u2082 \u2192 P (p\u2081 * p\u2082),\n  { intros p\u2081 p\u2082 hp\u2081 hp\u2082,\n    by_cases h\u2081 : p\u2081.comp q = 0,\n    { cases comp_eq_zero_iff.mp h\u2081 with h h,\n      { rw [h, zero_mul],\n        exact splits_zero _ },\n      { exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },\n    by_cases h\u2082 : p\u2082.comp q = 0,\n    { cases comp_eq_zero_iff.mp h\u2082 with h h,\n      { rw [h, mul_zero],\n        exact splits_zero _ },\n      { exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },\n    have key := mul_splits_in_splitting_field_of_mul h\u2081 h\u2082 hp\u2081 hp\u2082,\n    rwa \u2190 mul_comp at key },\n  exact wf_dvd_monoid.induction_on_irreducible p (splits_zero _)\n    (\u03bb _, splits_of_is_unit _) (\u03bb _ _ _ h, key2 (key1 h)),\nend\n\n/-- `polynomial.gal.restrict` for the composition of polynomials. -/\ndef restrict_comp (hq : q.nat_degree \u2260 0) : (p.comp q).gal \u2192* p.gal :=\n@restrict F _ p _ _ _ \u27e8splits_in_splitting_field_of_comp p q hq\u27e9\n\nlemma restrict_comp_surjective (hq : q.nat_degree \u2260 0) :\n  function.surjective (restrict_comp p q hq) :=\nby simp only [restrict_comp, restrict_surjective]\n\nvariables {p q}\n\n/-- For a separable polynomial, its Galois group has cardinality\nequal to the dimension of its splitting field over `F`. -/\nlemma card_of_separable (hp : p.separable) :\n  fintype.card p.gal = finrank F p.splitting_field :=\nbegin\n  haveI : is_galois F p.splitting_field := is_galois.of_separable_splitting_field hp,\n  exact is_galois.card_aut_eq_finrank F p.splitting_field,\nend\n\nlemma prime_degree_dvd_card [char_zero F] (p_irr : irreducible p) (p_deg : p.nat_degree.prime) :\n  p.nat_degree \u2223 fintype.card p.gal :=\nbegin\n  rw gal.card_of_separable p_irr.separable,\n  have hp : p.degree \u2260 0 :=\n    \u03bb h, nat.prime.ne_zero p_deg (nat_degree_eq_zero_iff_degree_le_zero.mpr (le_of_eq h)),\n  let \u03b1 : p.splitting_field := root_of_splits (algebra_map F p.splitting_field)\n    (splitting_field.splits p) hp,\n  have h\u03b1 : is_integral F \u03b1 :=\n    (is_algebraic_iff_is_integral F).mp (algebra.is_algebraic_of_finite \u03b1),\n  use finite_dimensional.finrank F\u27ee\u03b1\u27ef p.splitting_field,\n  suffices : (minpoly F \u03b1).nat_degree = p.nat_degree,\n  { rw [\u2190finite_dimensional.finrank_mul_finrank F F\u27ee\u03b1\u27ef p.splitting_field,\n        intermediate_field.adjoin.finrank h\u03b1, this] },\n  suffices : minpoly F \u03b1 \u2223 p,\n  { have key := (minpoly.irreducible h\u03b1).dvd_symm p_irr this,\n    apply le_antisymm,\n    { exact nat_degree_le_of_dvd this p_irr.ne_zero },\n    { exact nat_degree_le_of_dvd key (minpoly.ne_zero h\u03b1) } },\n  apply minpoly.dvd F \u03b1,\n  rw [aeval_def, map_root_of_splits _ (splitting_field.splits p) hp],\nend\n\nsection rationals\n\nlemma splits_\u211a_\u2102 {p : polynomial \u211a} : fact (p.splits (algebra_map \u211a \u2102)) :=\n\u27e8is_alg_closed.splits_codomain p\u27e9\n\nlocal attribute [instance] splits_\u211a_\u2102\n\n/-- The number of complex roots equals the number of real roots plus\n    the number of roots not fixed by complex conjugation (i.e. with some imaginary component). -/\nlemma card_complex_roots_eq_card_real_add_card_not_gal_inv (p : polynomial \u211a) :\n  (p.root_set \u2102).to_finset.card = (p.root_set \u211d).to_finset.card +\n  (gal_action_hom p \u2102 (restrict p \u2102 (complex.conj_ae.restrict_scalars \u211a))).support.card :=\nbegin\n  by_cases hp : p = 0,\n  { simp_rw [hp, root_set_zero, set.to_finset_eq_empty_iff.mpr rfl, finset.card_empty, zero_add],\n    refine eq.symm (nat.le_zero_iff.mp ((finset.card_le_univ _).trans (le_of_eq _))),\n    simp_rw [hp, root_set_zero, fintype.card_eq_zero_iff],\n    apply_instance },\n  have inj : function.injective (is_scalar_tower.to_alg_hom \u211a \u211d \u2102) := (algebra_map \u211d \u2102).injective,\n  rw [\u2190finset.card_image_of_injective _ subtype.coe_injective,\n      \u2190finset.card_image_of_injective _ inj],\n  let a : finset \u2102 := _,\n  let b : finset \u2102 := _,\n  let c : finset \u2102 := _,\n  change a.card = b.card + c.card,\n  have ha : \u2200 z : \u2102, z \u2208 a \u2194 aeval z p = 0 :=\n  \u03bb z, by rw [set.mem_to_finset, mem_root_set hp],\n  have hb : \u2200 z : \u2102, z \u2208 b \u2194 aeval z p = 0 \u2227 z.im = 0,\n  { intro z,\n    simp_rw [finset.mem_image, exists_prop, set.mem_to_finset, mem_root_set hp],\n    split,\n    { rintros \u27e8w, hw, rfl\u27e9,\n      exact \u27e8by rw [aeval_alg_hom_apply, hw, alg_hom.map_zero], rfl\u27e9 },\n    { rintros \u27e8hz1, hz2\u27e9,\n      have key : is_scalar_tower.to_alg_hom \u211a \u211d \u2102 z.re = z := by { ext, refl, rw hz2, refl },\n      exact \u27e8z.re, inj (by rwa [\u2190aeval_alg_hom_apply, key, alg_hom.map_zero]), key\u27e9 } },\n  have hc0 : \u2200 w : p.root_set \u2102, gal_action_hom p \u2102\n    (restrict p \u2102 (complex.conj_ae.restrict_scalars \u211a)) w = w \u2194 w.val.im = 0,\n  { intro w,\n    rw [subtype.ext_iff, gal_action_hom_restrict],\n    exact complex.eq_conj_iff_im },\n  have hc : \u2200 z : \u2102, z \u2208 c \u2194 aeval z p = 0 \u2227 z.im \u2260 0,\n  { intro z,\n    simp_rw [finset.mem_image, exists_prop],\n    split,\n    { rintros \u27e8w, hw, rfl\u27e9,\n      exact \u27e8(mem_root_set hp).mp w.2, mt (hc0 w).mpr (equiv.perm.mem_support.mp hw)\u27e9 },\n    { rintros \u27e8hz1, hz2\u27e9,\n      exact \u27e8\u27e8z, (mem_root_set hp).mpr hz1\u27e9,\n        equiv.perm.mem_support.mpr (mt (hc0 _).mp hz2), rfl\u27e9 } },\n  rw \u2190 finset.card_disjoint_union,\n  { apply congr_arg finset.card,\n    simp_rw [finset.ext_iff, finset.mem_union, ha, hb, hc],\n    tauto },\n  { intro z,\n    rw [finset.inf_eq_inter, finset.mem_inter, hb, hc],\n    tauto },\n  { apply_instance },\nend\n\n/-- An irreducible polynomial of prime degree with two non-real roots has full Galois group. -/\nlemma gal_action_hom_bijective_of_prime_degree\n  {p : polynomial \u211a} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)\n  (p_roots : fintype.card (p.root_set \u2102) = fintype.card (p.root_set \u211d) + 2) :\n  function.bijective (gal_action_hom p \u2102) :=\nbegin\n  have h1 : fintype.card (p.root_set \u2102) = p.nat_degree,\n  { simp_rw [root_set_def, finset.coe_sort_coe, fintype.card_coe],\n    rw [multiset.to_finset_card_of_nodup, \u2190nat_degree_eq_card_roots],\n    { exact is_alg_closed.splits_codomain p },\n    { exact nodup_roots ((separable_map (algebra_map \u211a \u2102)).mpr p_irr.separable) } },\n  have h2 : fintype.card p.gal = fintype.card (gal_action_hom p \u2102).range :=\n  fintype.card_congr (monoid_hom.of_injective (gal_action_hom_injective p \u2102)).to_equiv,\n  let conj := restrict p \u2102 (complex.conj_ae.restrict_scalars \u211a),\n  refine \u27e8gal_action_hom_injective p \u2102, \u03bb x, (congr_arg (has_mem.mem x)\n    (show (gal_action_hom p \u2102).range = \u22a4, from _)).mpr (subgroup.mem_top x)\u27e9,\n  apply equiv.perm.subgroup_eq_top_of_swap_mem,\n  { rwa h1 },\n  { rw h1,\n    convert prime_degree_dvd_card p_irr p_deg using 1,\n    convert h2.symm },\n  { exact \u27e8conj, rfl\u27e9 },\n  { rw \u2190 equiv.perm.card_support_eq_two,\n    apply nat.add_left_cancel,\n    rw [\u2190p_roots, \u2190set.to_finset_card (root_set p \u211d), \u2190set.to_finset_card (root_set p \u2102)],\n    exact (card_complex_roots_eq_card_real_add_card_not_gal_inv p).symm },\nend\n\n/-- An irreducible polynomial of prime degree with 1-3 non-real roots has full Galois group. -/\nlemma gal_action_hom_bijective_of_prime_degree'\n  {p : polynomial \u211a} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)\n  (p_roots1 : fintype.card (p.root_set \u211d) + 1 \u2264 fintype.card (p.root_set \u2102))\n  (p_roots2 : fintype.card (p.root_set \u2102) \u2264 fintype.card (p.root_set \u211d) + 3) :\n  function.bijective (gal_action_hom p \u2102) :=\nbegin\n  apply gal_action_hom_bijective_of_prime_degree p_irr p_deg,\n  let n := (gal_action_hom p \u2102 (restrict p \u2102\n    (complex.conj_ae.restrict_scalars \u211a))).support.card,\n  have hn : 2 \u2223 n :=\n  equiv.perm.two_dvd_card_support (by rw [\u2190monoid_hom.map_pow, \u2190monoid_hom.map_pow,\n    show alg_equiv.restrict_scalars \u211a complex.conj_ae ^ 2 = 1,\n    from alg_equiv.ext complex.conj_conj, monoid_hom.map_one, monoid_hom.map_one]),\n  have key := card_complex_roots_eq_card_real_add_card_not_gal_inv p,\n  simp_rw [set.to_finset_card] at key,\n  rw [key, add_le_add_iff_left] at p_roots1 p_roots2,\n  rw [key, add_right_inj],\n  suffices : \u2200 m : \u2115, 2 \u2223 m \u2192 1 \u2264 m \u2192 m \u2264 3 \u2192 m = 2,\n  { exact this n hn p_roots1 p_roots2 },\n  rintros m \u27e8k, rfl\u27e9 h2 h3,\n  exact le_antisymm (nat.lt_succ_iff.mp (lt_of_le_of_ne h3 (show 2 * k \u2260 2 * 1 + 1,\n    from nat.two_mul_ne_two_mul_add_one))) (nat.succ_le_iff.mpr (lt_of_le_of_ne h2\n    (show 2 * 0 + 1 \u2260 2 * k, from nat.two_mul_ne_two_mul_add_one.symm))),\nend\n\nend rationals\n\nend gal\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/field_theory/polynomial_galois_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.725045444791601}}
{"text": "-- La identidad es biyectiva\n-- =========================\n\nimport tactic\n\nopen function\n\nvariables {X : Type}\n\n-- #print injective\n-- #print surjective\n-- #print bijective\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar que la identidad es inyectiva.\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : injective (@id X) :=\nbegin\n  intros x\u2081 x\u2082 h,\n  exact h,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : injective (@id X) :=\n\u03bb x\u2081 x\u2082 h, h\n\n-- 3\u00aa demostraci\u00f3n\nexample : injective (@id X) :=\n\u03bb x\u2081 x\u2082, id\n\n-- 4\u00aa demostraci\u00f3n\nexample : injective (@id X) :=\nassume x\u2081 x\u2082,\nassume h : id x\u2081 = id x\u2082,\nshow x\u2081 = x\u2082, from h\n\n-- 5\u00aa demostraci\u00f3n\nexample : injective (@id X) :=\n--by library_search\ninjective_id\n\n-- 6\u00aa demostraci\u00f3n\nexample : injective (@id X) :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample : injective (@id X) :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ej. 2. Demostrar que la identidad es suprayectiva.\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : surjective (@id X) :=\nbegin\n  intro x,\n  use x,\n  exact rfl,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : surjective (@id X) :=\nbegin\n  intro x,\n  exact \u27e8x, rfl\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : surjective (@id X) :=\n\u03bb x, \u27e8x, rfl\u27e9\n\n-- 4\u00aa demostraci\u00f3n\nexample : surjective (@id X) :=\nassume y,\nshow \u2203 x, id x = y, from exists.intro y rfl\n\n-- 5\u00aa demostraci\u00f3n\nexample : surjective (@id X) :=\n-- by library_search\nsurjective_id\n\n-- 6\u00aa demostraci\u00f3n\nexample : surjective (@id X) :=\n-- by hint\nby tauto\n\n-- ----------------------------------------------------\n-- Ej. 3. Demostrar que la identidad es biyectiva.\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : bijective (@id X) :=\nand.intro injective_id surjective_id\n\n-- 2\u00aa demostraci\u00f3n\nexample : bijective (@id X) :=\n\u27e8injective_id, surjective_id\u27e9\n\n-- 3\u00aa demostraci\u00f3n\nexample : bijective (@id X) :=\n-- by library_search\nbijective_id\n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/5_Funciones/La_identidad_es_biyectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7250192785903988}}
{"text": "import data.real.basic\nimport data.set.intervals.basic\n\n/-\n(from http://www.mit.edu/~erst/puzzles/)\n\nQ. Can the unit square [0, 1] x [0, 1] be colored with three colors so that any\npair of points with the same color have a distance between them of at most one?\n\nA. No.\n\n-/\n\ndef unit_square := set.Icc (0 : \u211d) (1 : \u211d) \u00d7 set.Icc (0 : \u211d) (1 : \u211d)\n\ndef within_distance_one (p1 p2 : unit_square) : Prop :=\n(p1.fst.val - p2.fst.val) ^ 2 + (p1.snd.val - p2.snd.val) ^ 2 \u2264 1\n\nlemma composition_preserves_coloring_property\n   (f : unit_square \u2192 fin 3)\n   (g : fin 3 \u2192 fin 3)\n   (h : \u2200 p\u2081 p\u2082 : unit_square, g (f p\u2081) = g (f p\u2082) \u2192 within_distance_one p\u2081 p\u2082) :\n   \u2200 p\u2081 p\u2082 : unit_square, f p\u2081 = f p\u2082 \u2192 within_distance_one p\u2081 p\u2082 :=\nbegin\n  intros p1 p2 hfp,\n  exact h p1 p2 (congr_arg g hfp),\nend\n\ntheorem square_three_coloring\n  (f : unit_square \u2192 fin 3)\n  (h : \u2200 p\u2081 p\u2082 : unit_square, f p\u2081 = f p\u2082 \u2192 within_distance_one p\u2081 p\u2082)\n  : false :=\nbegin\n  -- It suffices to consider just the boundary of the square...\n  sorry\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/square_three_coloring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7249875114153231}}
{"text": "import data.fintype.basic\nimport data.set \nimport data.finset\nimport tactic\n\nnoncomputable theory\nlocalized \"attribute [instance, priority 100000] classical.prop_decidable\n  noncomputable theory\" in classical\nopen_locale classical\nopen finset \n\nuniverses u\nvariables {\u03b3 : Type u}\n\ndef size (X : finset \u03b3) := (coe X.card : \u2124)\ndef type_size (\u03b3 : Type u) [fintype \u03b3] := (coe (fintype.card \u03b3) : \u2124)\n\nlemma size_empty : size (\u2205:finset \u03b3) = 0 := \nbegin\n    unfold size, simp,\nend\nlemma size_le_of_subset {s t: finset \u03b3} (h : s \u2286 t) : size(s) \u2264 size(t) :=\nbegin\n    unfold size, simp, exact card_le_of_subset h\nend\nlemma size_sdiff {s t : finset \u03b3} (h : s \u2286 t) : size (t \\ s) = size t - size s :=\nbegin\n    sorry,\nend\nlemma size_modular (s t : finset \u03b3) : size s + size t = size (s \u222a t) + size (s \u2229 t) :=\nbegin\n    sorry,\nend\n@[simp] lemma size_map {\u03b1 \u03b2} (f : \u03b1 \u21aa \u03b2) {s : finset \u03b1} : size (s.map f) = size s :=\nbegin\n    simp,\nend\nlemma size_compl [decidable_eq \u03b3] [fintype \u03b3] (s : finset \u03b3) :\n  size(s\u1d9c) = type_size \u03b3 - size s :=\nbegin\n    sorry\nend\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old/size.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.926303728259492, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7249831769187562}}
{"text": "-- topological spaces from first princples!\n\n-- Turns out there's quite a lot to it, but it's all straightforward\n\n-- I'll start on the hour. I'll do a brief review of last week\n-- (the below file, \n-- https://github.com/ImperialCollegeLondon/Example-Lean-Projects/blob/master/src/topology/twitch.lean\n-- and then I'll start on the proof that the continuous image of compact is compact.\n\nimport tactic\n\n-- remember : in Lean, `set X` means the type of subsets of X\n-- or, the type of \"sets of elements of X\"\n\nopen set\n\n/-- The definition of a topological space -/\nclass topological_space (X : Type) :=\n -- some subsets of X are called \"open sets\"\n(is_open : set X \u2192 Prop)\n -- X itself is open\n(is_open_univ : is_open univ)\n -- intersection of two open sets is open\n(is_open_inter : \u2200 U V : set X, is_open U \u2192 is_open V \u2192 is_open (U \u2229 V))\n-- arbitrary union of open sets is open\n(is_open_sUnion : \u2200 (\ud835\udc9e : set (set X)), (\u2200 U \u2208 \ud835\udc9e, is_open U) \u2192 is_open (\u22c3\u2080 \ud835\udc9e))\n\n-- what is an \"arbitrary union of open sets\"?\n-- I've set it up as a set of open sets\n-- but you might have an \"indexed family of open sets\"\n-- ie some type \u03b9, and for all  i \u2208 \u03b9 an open set U_i\n-- and you want \u22c3 U_i open\n\nnamespace topological_space\n\n-- let X be a topological space\n\nvariables {X : Type} [topological_space X]\n\n-- let's do indexed unions\n\nlemma is_open_Union {\u03b9 : Type} {f : \u03b9 \u2192 set X} (hf : \u2200 i : \u03b9, is_open (f i)) :\n  is_open (\u22c3 i, f i) :=\nbegin\n  apply is_open_sUnion,\n  intros U hU,\n  cases hU with i hi,\n  dsimp at hi,\n  rw \u2190hi,\n  apply hf,\nend\n\n-- empty set is open\nlemma is_open_empty : is_open (\u2205 : set X) :=\nbegin\n  let \ud835\udc9e : set (set X) := \u2205,\n  have h\ud835\udc9e : \u2200 U \u2208 \ud835\udc9e, is_open U,\n  { rintro U \u27e8\u27e9,\n  },\n  convert is_open_sUnion \ud835\udc9e h\ud835\udc9e,\n  rw sUnion_empty,\nend\n\n-- finite intersection of open sets is open\n-- proof by induction on size of finite set\nlemma is_open_sInter {\ud835\udc9e : set (set X)} (h\ud835\udc9e : finite \ud835\udc9e) :\n  (\u2200 U \u2208 \ud835\udc9e, is_open U) \u2192 is_open \u22c2\u2080 \ud835\udc9e :=\nbegin\n  apply finite.induction_on h\ud835\udc9e,\n  { -- base case,\n    intros,\n    convert is_open_univ,\n    rw sInter_empty },\n  { -- inductive step\n    -- going to use is_open_inter\n    intro U,\n    intro \ud835\udc9e,\n    intro hU\ud835\udc9e,\n    intro h\ud835\udc9e,\n    intro h\ud835\udc9e2,\n    -- h says \"assume both U and every element of \ud835\udc9e is open\"\n    -- insert U \ud835\udc9e means {U} \u222a \ud835\udc9e\n    intro h,\n    rw sInter_insert,\n    apply is_open_inter,\n    { apply h,\n      simp },\n    { apply h\ud835\udc9e2,\n      intros U hU,\n      apply h,\n      simp [hU] }},\nend\n\n-- a variant of finite intersection of opens is open\nlemma is_open_bInter {I : Type} {F : set I} (hf : finite F)\n  (U : I \u2192 set X) (hU : \u2200 (i : I), is_open (U i)) : \n  is_open (\u22c2 i \u2208 F, U i) :=\nbegin\n  rw bInter_eq_Inter,\n  show is_open (\u22c2\u2080 set.range (\u03bb x : F, U x)),\n  apply is_open_sInter,\n  { rw \u2190image_univ,\n    apply finite.image,\n    haveI := classical.choice hf,\n    apply finite_univ },\n  finish,\nend\n\n\n\ndef is_closed (C : set X) : Prop := is_open C\u1d9c\n\n@[simp] lemma is_closed_iff (C : set X) : is_closed C \u2194 is_open C\u1d9c := iff.rfl\n\n-- clearly could spend all day proving facts about closed sets now\n\nlemma is_closed_empty : is_closed (\u2205 : set X) :=\nbegin\n  simp [is_open_univ],\nend\n\nend topological_space\n\n-- next : continuous functions\n\nopen topological_space\n\nvariables {X : Type} [topological_space X]\n  {Y : Type} [topological_space Y]\n\n/-- a function X \u2192 Y between topological spaces is continuous if the\n  preimage of every open set is open -/\ndef continuous (f : X \u2192 Y) : Prop :=\n\u2200 U, is_open U \u2192 is_open (f\u207b\u00b9' U)\n\ntheorem continuous_id : continuous (id : X \u2192 X) :=\nbegin\n  intro U,\n  intro hU,\n  -- interesting question\n  -- clearly id\u207b\u00b9' U = U\n  -- But this is true *by definition*?\n  -- another interesting question\n  -- clearly id'' U = U (pushforward)\n  -- but is this true *by definition*?\n  -- THESE QUESTIONS ARE NOT MATHEMATICAL QUESTIONS\n  -- They depend not on the specification, but on the *implementation*\n--   have h1 : U = id '' U,\n--   { --refl, -- fails!\n--     -- not true by definition\n--     ext x,\n--     split,\n--       intro h,\n--       unfold set.image,\n--       use x, -- this is why it's not true by definition\n--       split, assumption, refl,\n--       rintro \u27e8y, hy1, rfl\u27e9,\n--       exact hy1,\n--   },\n--   have h2 : U = id\u207b\u00b9' U, -- true by definition\n--     refl,\n  exact hU,\nend\n\nvariables {Z : Type} [topological_space Z]\n\ntheorem continuous.comp {f : X \u2192 Y} {g : Y \u2192 Z} (hf : continuous f)\n  (hg : continuous g) : continuous (g \u2218 f) :=\nbegin\n  intro U,\n  intro hU,\n  change is_open ((g \u2218 f)\u207b\u00b9' U),\n  change is_open (f\u207b\u00b9' (g\u207b\u00b9' U)),\n  -- proving it backwards\n  apply hf,\n  apply hg,\n  exact hU\nend\n\n-- term mode proof (same proof!)\ntheorem continuous.comp' {f : X \u2192 Y} {g : Y \u2192 Z} (hf : continuous f)\n  (hg : continuous g) : continuous (g \u2218 f) :=\n\u03bb U hU, hf (g\u207b\u00b9' U) (hg _ hU)\n\n/-- a subset C of a top space X is compact if every open cover has a finite subcover -/\ndef compact (C : set X) : Prop :=\n  \u2200 (\u03b9 : Type) (U : \u03b9 \u2192 set X) (hi : \u2200 i : \u03b9, is_open (U i)) (hC : C \u2286 \u22c3i, U i),\n  \u2203 F : set \u03b9, finite F \u2227 C \u2286 \u22c3 i \u2208 F, U i\n\n-- this definition seems to me to be easier to work with\n\ndef hausdorff (X : Type) [topological_space X] : Prop :=\n\u2200 x y : X, x \u2260 y \u2192 \u2203 U V : set X, is_open U \u2227 is_open V \u2227 x \u2208 U \u2227 y \u2208 V \u2227 U \u2229 V = \u2205\n\n-- Theorem: continuous image of a compact set is compact\ntheorem compact_map {f : X \u2192 Y} (hf : continuous f) {C : set X} (hC : compact C) :\n  compact (f '' C) :=\nbegin\n  -- suffices to prove that if f(C) is covered by open sets, it has a \n  -- finite subcover\n  intros I U hU hUC,\n  -- hUC : f(C) \u2286 \u22c3_{i \u2208 I} U\u1d62\n  -- So say we've covered f(C) by open sets\n  -- Then C has a cover by open sets, namely V\u1d62 := f\u207b\u00b9(U\u1d62),\n  let V : I \u2192 set X := \u03bb i, f\u207b\u00b9' (U i),\n  -- Let's check that all the V\u1d62 are open\n  have hV : \u2200 i : I, is_open (V i),\n  { intro i,\n    apply hf,\n    apply hU },\n  -- Let's check that the V\u1d62 cover C\n  have hVC : C \u2286 \u22c3 i, V i,\n  { -- say x \u2208 C,\n    intro x,\n    intro hx,\n    -- then f(x) \u2208 \u22c3_i U\u1d62\n    have hx2 : f x \u2208 \u22c3 i, U i,\n      apply hUC,\n      use [x, hx],\n    -- f(x) \u2208 \u22c3_i U\u1d62, so \u2203 i s.t. f(x) \u2208 U\u1d62\n    rw mem_Union at hx2 \u22a2,\n    cases hx2 with i hi,\n    use i,\n    exact hi },\n  -- but C is compact\n  specialize hC I V hV hVC,\n  -- so there exists a finite subcover of V\u1d62,\n  rcases hC with \u27e8F, hF, hFC\u27e9,\n  -- I claim that corresponding U\u1d62 will work\n  use [F, hF],\n  -- Let's check they cover f(C),\n  rintros _ \u27e8x, hx1, rfl\u27e9,\n  specialize hFC hx1,\n  rw mem_bUnion_iff at hFC \u22a2,\n  exact hFC,\n  -- They do, so the cover of f(C) had a finite subcover :D\nend\n\n-- To prove that a compact subspace of a Hausdorff space is closed,\n-- we need the fact that a \"locally open\" set is open!\n\n-- So let's prove that first\n\nlemma open_iff_locally_open (V : set X) :\n  is_open V \u2194 \u2200 x : X, x \u2208 V \u2192 \u2203 U : set X, x \u2208 U \u2227 is_open U \u2227 U \u2286 V :=\n\u27e8\u03bb hV x hx, \u27e8V, hx, hV, subset.refl _\u27e9, \u03bb h, begin\n  let \ud835\udc9e : set (set X) := {U : set X | is_open U \u2227 U \u2286 V},\n    -- \ud835\udc9e doesn't just contain the neighbourhoods of x for each x \u2208 V\n    -- \ud835\udc9e contains more sets, e.g. the empty set!\n    -- Clearly every set in \ud835\udc9e is open, so their union is open\n    convert is_open_sUnion \ud835\udc9e _,\n    swap,\n    { intros U H, cases H, assumption},\n    -- It suffices to prove that V is the union of the elements of \ud835\udc9e\n    { ext x,\n      split,\n      -- let's prove inclusions in both directions\n      { intro hx,\n        rcases h x hx with \u27e8U, hU1, hU2, hU3\u27e9,\n        rw mem_sUnion,\n        use U,\n        use hU2,\n        exact hU3,\n        exact hU1 },\n      { -- easy way\n        intro hx,\n        rw mem_sUnion at hx,\n        rcases hx with \u27e8U, hUC, hxU\u27e9,\n        cases hUC with h1 h2,\n        apply h2 hxU }}\nend\u27e9\n-- #exit\n-- begin\n--   split,\n--   { -- This way is easy. Say V is open.\n--     intro hV,\n--     -- say x \u2208 V\n--     intros x hx,\n--     -- Want an open neighbourhood of x contained in V\n--     -- let's just use V :-)\n--     use V,\n--     use hx,\n--     use hV }, -- last goal V \u2286 V closed automatically by `refl`,\n--   { intro h,\n--     -- Reid Barton trick!\n--     let \ud835\udc9e : set (set X) := {U : set X | is_open U \u2227 U \u2286 V},\n--     -- \ud835\udc9e doesn't just contain the neighbourhoods of x for each x \u2208 V\n--     -- \ud835\udc9e contains more sets, e.g. the empty set!\n--     -- Clearly every set in \ud835\udc9e is open, so their union is open\n--     convert is_open_sUnion \ud835\udc9e _,\n--     swap,\n--     { tidy },\n--     -- It suffices to prove that V is the union of the elements of \ud835\udc9e\n--     { ext x,\n--       split,\n--       -- let's prove inclusions in both directions\n--       { intro hx,\n--         rcases h x hx with \u27e8U, hU1, hU2, hU3\u27e9,\n--         rw mem_sUnion,\n--         use U,\n--         use hU2,\n--         exact hU3,\n--         exact hU1 },\n--       { -- easy way\n--         intro hx,\n--         rw mem_sUnion at hx,\n--         rcases hx with \u27e8U, hUC, hxU\u27e9,\n--         cases hUC with h1 h2,\n--         apply h2 hxU }}}\n-- end\n\n\n\n-- stream starts at 10am UK time (UTC+2)\n\n-- Goal today\n\n\ntheorem is_closed_of_compact (hX : hausdorff X) {C : set X} (hC : compact C) : is_closed C :=\nbegin\n  unfold is_closed,\n  -- let's start with the maths proof\n  -- We're going to prove that C\u1d9c is open by showing it's locally open\n  -- Let x \u2208 C\u1d9c i.e. x : X and x \u2209 C\n  -- If we can find an open subset U \u2286 C\u1d9c with x \u2208 U then we're done\n  -- by the previous lemma\n  rw open_iff_locally_open,\n  intros x hx,\n  rw mem_compl_iff at hx,\n  -- Where do we find such U?\n  -- Now is where we use compactness.\n  -- We're going to cover C by a bunch of open sets\n  -- Where do we get the open sets?\n  -- We get them from Hausdorffness\n  -- Let's regard x as fixed.\n  -- Say y \u2208 C (y is moving)\n  -- Then x \u2260 y because x \u2209 C\n  -- so by Hausdorff there exists opens U=U(y) and V=V(y)\n  -- disjoint, with x \u2208 V and y \u2208 U\n  -- In particular x \u2209 U = U(y)\n  -- The union of the U(y) covers C because y \u2208 C was arbitrary and y \u2208 U(y)\n  -- So there's a finite subcover, U(y\u2081), U(y\u2082)...U(y\u2099) of C\n  -- Now take the intersection of the corresponding V(y)'s\n  -- this is an open nhd of x\n  -- and it's disjoint from the union of the U(y)'s so it's disjoint from C\n  -- This V works!\n\n  -- \"issue\" with the maths proof -- uses the axiom of choice!\n  -- Grateful to Reid Barton and Andrej Bauer who independently showed\n  -- me a \"AC removal principle\" -- which makes proofs look (a) a bit slicker\n  -- and (b) a bit harder to remember (possibly).\n\n  -- AC removal principle says \"DON'T CHOOSE! USE ALL THE CHOICES!\"\n\n  -- in our actual proof we'll define a slightly different cover\n\n  -- I is the set of pairs (V,U) of open subsets of X, with\n  -- x \u2208 V, and U \u2229 V empty\n  let I := {VU : set X \u00d7 set X //\n    x \u2208 VU.1 \u2227 is_open VU.1 \u2227 is_open VU.2 \u2227 VU.1 \u2229 VU.2 = \u2205},\n  -- We want to consider all the U's coming from pairs (V,U) in I\n  let U : I \u2192 set X := \u03bb VUH, VUH.1.2, -- send (V,U) to U\n  -- My claim is that as i ranges through I, the U(i) are an open cover\n  -- Let's first prove they're all open\n  have hU1 : \u2200 i : I, is_open (U i),\n  { rintro \u27e8\u27e8V, U\u27e9, _, _, h, _\u27e9,\n    exact h },\n  -- now let's prove they cover C\n  have hU2 : C \u2286 \u22c3 i, U i,\n  { intros y hy,\n    /-\n    def hausdorff (X : Type) [topological_space X] : Prop :=\n    \u2200 x y : X, x \u2260 y \u2192 \u2203 U V : set X, is_open U \u2227 is_open V \u2227 x \u2208 U \u2227 y \u2208 V \u2227 U \u2229 V = \u2205\n    -/\n    have hxy : x \u2260 y,\n    { rintro rfl,\n      contradiction },\n    -- now use that X is Hausdorff\n    rcases hX x y hxy with \u27e8V, U, hV, hU, hxV, hyU, hUV\u27e9,\n    rw mem_Union,\n    -- now let's give the term of type I\n    use \u27e8(V, U), \u27e8hxV, hV, hU, hUV\u27e9\u27e9,\n    exact hyU },\n  /-\n  def compact (C : set X) : Prop :=\n  \u2200 (\u03b9 : Type) (U : \u03b9 \u2192 set X) (hi : \u2200 i : \u03b9, is_open (U i)) (hC : C \u2286 \u22c3i, U i),\n  \u2203 F : set \u03b9, finite F \u2227 C \u2286 \u22c3 i \u2208 F, U i\n  -/\n  specialize hC I U hU1 hU2,\n  rcases hC with \u27e8F, hF, hFC\u27e9,\n  -- now we have our finite subcover\n  -- now let's create the open nhd of x\n  let W := \u22c2 i \u2208 F, (i : I).1.1,\n  use W,\n  refine \u27e8_, _, _\u27e9,\n  { show x \u2208 \u22c2 (i : I) (H : i \u2208 F), i.val.fst,\n    rw mem_bInter_iff,\n    rintro \u27e8\u27e8V, U\u27e9, hxV, hV, hU, hUV\u27e9,\n    intro hi,\n    use hxV },\n  { -- we're missing a lemma here\n    -- need a different kind of \"finite intersection of opens is open\"\n    show is_open (\u22c2 (i : I) (H : i \u2208 F), i.val.fst),\n    apply is_open_bInter hF,\n    rintro \u27e8\u27e8V, U\u27e9, hxV, hV, hU, hUV\u27e9,\n    exact hV,\n  },\n  { rw subset_compl_comm,\n    rw compl_Inter,\n    refine set.subset.trans hFC _,\n    apply Union_subset_Union,\n    intro i,\n    rw compl_Inter,\n    apply Union_subset_Union,\n    rintro hi,\n    rcases i with \u27e8\u27e8V, U\u27e9, hxV, hV, hU, hUV\u27e9,\n    show U \u2286 V\u1d9c,\n    rw subset_compl_iff_disjoint,\n    rw inter_comm,\n    exact hUV },\nend\n\n\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "Example-Lean-Projects", "sha": "87b27ba616eaf03f3642000829a481a1932dd08e", "save_path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects", "path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects/Example-Lean-Projects-87b27ba616eaf03f3642000829a481a1932dd08e/src/topology/twitch.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7249831722229224}}
{"text": "-- new import\nimport algebra.punit_instances \n\n-- That import is a bunch of structure on the type `unit`.\n-- This type just has one term, called punit.star, although\n-- we prefer to use the notation ()\n\nexample : unit := ()\n\n\n-- **IMPORTANT NOTE**: I propose we change the definition\n-- of G_module, based on comments at\n-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/more.20type.20class.20inference.20issues/near/167024793\nclass G_module (G : Type*) [group G] (M : Type*) [add_comm_group M]\n  extends has_scalar G M :=\n(id : \u2200 m : M, (1 : G) \u2022 m = m)\n(mul : \u2200 g h : G, \u2200 m : M, g \u2022 (h \u2022 m) = (g * h) \u2022 m)\n(linear : \u2200 g : G, \u2200 m n : M, g \u2022 (m + n) = g \u2022 m + g \u2022 n)\n\n\n-- So now we want to make unit a G-module.\n-- By the definition of G_module, we first need to make\n-- sure that unit is an add_comm_group, and that there is a scalar\n-- multiplication of G on unit.\n\n-- Put in a more computer science way, we need to make\n-- sure that Lean's type class inference system can \n-- find terms of type `add_comm_group unit` and `has_scalar G unit`.\n\n-- The import algebra.punit_instances gives the add_comm_group instance.\nexample : add_comm_group unit := by apply_instance\n\n-- But nobody wrote has_scalar G unit, so we have to write it ourselves. \n\n-- has_scalar is a class, so the definition should be an instance.\ninstance (G : Type*) [group G] : has_scalar G unit :=\n{ smul := \u03bb g u, u }\n\n-- using instances means that typeclass inference will work for us.\n\nexample (G : Type*) [group G] : has_scalar G unit := by apply_instance\n\n-- That works. The `apply_instance` tactic shows us that \"[]\" will work\n-- if we need a term of type `has_scalar G unit`.\n\n-- Now the structure of a G-module on unit:\ninstance (G : Type*) [group G] : G_module G unit :=\nby refine { id := \u03bb _, rfl,\n  mul := \u03bb _ _ _, rfl,\n  linear := \u03bb _ _ _, rfl}; apply_instance\n\n-- Anca -- this now means that `unit` has the structure of a G_module.\n-- You could factor this file out into a file called something\n-- like unit_G_module.lean and just import it when you need it.\n-- You should be able to now prove things like unit -> A -> B is exact\n-- iff A -> B is injective. Before you do that, you'll need results\n-- such as that the map from unit to A sending () to 0 is an add_group_hom,\n-- and I guess the crucial thing you'll need is that a group hom A -> B is\n-- injective if and only if its kernel is {0}. This is in mathlib;\n-- it's called inj_iff_trivial_ker. You should learn how to use the\n-- search tool (the magnifying glass in the column on the left) to\n-- find where it is.\n\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Anca_project/subgroups_and_zero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.724924059535131}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n\n! This file was ported from Lean 3 source module computability.regular_expressions\n! leanprover-community/mathlib commit a239cd3e7ac2c7cde36c913808f9d40c411344f6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Tactic.Rcases\nimport Mathbin.Computability.Language\n\n/-!\n# Regular Expressions\n\nThis file contains the formal definition for regular expressions and basic lemmas. Note these are\nregular expressions in terms of formal language theory. Note this is different to regex's used in\ncomputer science such as the POSIX standard.\n\n## TODO\n\n* Show that this regular expressions and DFA/NFA's are equivalent.\n* `attribute [pattern] has_mul.mul` has been added into this file, it could be moved.\n-/\n\n\nopen List Set\n\nopen Computability\n\nuniverse u\n\nvariable {\u03b1 \u03b2 \u03b3 : Type _} [dec : DecidableEq \u03b1]\n\n/-- This is the definition of regular expressions. The names used here is to mirror the definition\nof a Kleene algebra (https://en.wikipedia.org/wiki/Kleene_algebra).\n* `0` (`zero`) matches nothing\n* `1` (`epsilon`) matches only the empty string\n* `char a` matches only the string 'a'\n* `star P` matches any finite concatenation of strings which match `P`\n* `P + Q` (`plus P Q`) matches anything which match `P` or `Q`\n* `P * Q` (`comp P Q`) matches `x ++ y` if `x` matches `P` and `y` matches `Q`\n-/\ninductive RegularExpression (\u03b1 : Type u) : Type u\n  | zero : RegularExpression\n  | epsilon : RegularExpression\n  | Char : \u03b1 \u2192 RegularExpression\n  | plus : RegularExpression \u2192 RegularExpression \u2192 RegularExpression\n  | comp : RegularExpression \u2192 RegularExpression \u2192 RegularExpression\n  | star : RegularExpression \u2192 RegularExpression\n#align regular_expression RegularExpression\n\nnamespace RegularExpression\n\nvariable {a b : \u03b1}\n\ninstance : Inhabited (RegularExpression \u03b1) :=\n  \u27e8zero\u27e9\n\ninstance : Add (RegularExpression \u03b1) :=\n  \u27e8plus\u27e9\n\ninstance : Mul (RegularExpression \u03b1) :=\n  \u27e8comp\u27e9\n\ninstance : One (RegularExpression \u03b1) :=\n  \u27e8epsilon\u27e9\n\ninstance : Zero (RegularExpression \u03b1) :=\n  \u27e8zero\u27e9\n\ninstance : Pow (RegularExpression \u03b1) \u2115 :=\n  \u27e8fun n r => npowRec r n\u27e9\n\nattribute [match_pattern] Mul.mul\n\n@[simp]\ntheorem zero_def : (zero : RegularExpression \u03b1) = 0 :=\n  rfl\n#align regular_expression.zero_def RegularExpression.zero_def\n\n@[simp]\ntheorem one_def : (epsilon : RegularExpression \u03b1) = 1 :=\n  rfl\n#align regular_expression.one_def RegularExpression.one_def\n\n@[simp]\ntheorem plus_def (P Q : RegularExpression \u03b1) : plus P Q = P + Q :=\n  rfl\n#align regular_expression.plus_def RegularExpression.plus_def\n\n@[simp]\ntheorem comp_def (P Q : RegularExpression \u03b1) : comp P Q = P * Q :=\n  rfl\n#align regular_expression.comp_def RegularExpression.comp_def\n\n/-- `matches P` provides a language which contains all strings that `P` matches -/\n@[simp]\ndef matches : RegularExpression \u03b1 \u2192 Language \u03b1\n  | 0 => 0\n  | 1 => 1\n  | Char a => {[a]}\n  | P + Q => P.matches + Q.matches\n  | P * Q => P.matches * Q.matches\n  | star P => P.matches\u2217\n#align regular_expression.matches RegularExpression.matches\n\n@[simp]\ntheorem matches_zero : (0 : RegularExpression \u03b1).matches = 0 :=\n  rfl\n#align regular_expression.matches_zero RegularExpression.matches_zero\n\n@[simp]\ntheorem matches_epsilon : (1 : RegularExpression \u03b1).matches = 1 :=\n  rfl\n#align regular_expression.matches_epsilon RegularExpression.matches_epsilon\n\n@[simp]\ntheorem matches_char (a : \u03b1) : (char a).matches = {[a]} :=\n  rfl\n#align regular_expression.matches_char RegularExpression.matches_char\n\n@[simp]\ntheorem matches_add (P Q : RegularExpression \u03b1) : (P + Q).matches = P.matches + Q.matches :=\n  rfl\n#align regular_expression.matches_add RegularExpression.matches_add\n\n@[simp]\ntheorem matches_mul (P Q : RegularExpression \u03b1) : (P * Q).matches = P.matches * Q.matches :=\n  rfl\n#align regular_expression.matches_mul RegularExpression.matches_mul\n\n@[simp]\ntheorem matches_pow (P : RegularExpression \u03b1) : \u2200 n : \u2115, (P ^ n).matches = P.matches ^ n\n  | 0 => matches_epsilon\n  | n + 1 => (matches_mul _ _).trans <| Eq.trans (congr_arg _ (matches_pow n)) (pow_succ _ _).symm\n#align regular_expression.matches_pow RegularExpression.matches_pow\n\n@[simp]\ntheorem matches_star (P : RegularExpression \u03b1) : P.unit.matches = P.matches\u2217 :=\n  rfl\n#align regular_expression.matches_star RegularExpression.matches_star\n\n/-- `match_epsilon P` is true if and only if `P` matches the empty string -/\ndef matchEpsilon : RegularExpression \u03b1 \u2192 Bool\n  | 0 => false\n  | 1 => true\n  | Char _ => false\n  | P + Q => P.matchEpsilon || Q.matchEpsilon\n  | P * Q => P.matchEpsilon && Q.matchEpsilon\n  | star P => true\n#align regular_expression.match_epsilon RegularExpression.matchEpsilon\n\ninclude dec\n\n/-- `P.deriv a` matches `x` if `P` matches `a :: x`, the Brzozowski derivative of `P` with respect\n  to `a` -/\ndef deriv : RegularExpression \u03b1 \u2192 \u03b1 \u2192 RegularExpression \u03b1\n  | 0, _ => 0\n  | 1, _ => 0\n  | Char a\u2081, a\u2082 => if a\u2081 = a\u2082 then 1 else 0\n  | P + Q, a => deriv P a + deriv Q a\n  | P * Q, a => if P.matchEpsilon then deriv P a * Q + deriv Q a else deriv P a * Q\n  | star P, a => deriv P a * star P\n#align regular_expression.deriv RegularExpression.deriv\n\n@[simp]\ntheorem deriv_zero (a : \u03b1) : deriv 0 a = 0 :=\n  rfl\n#align regular_expression.deriv_zero RegularExpression.deriv_zero\n\n@[simp]\ntheorem deriv_one (a : \u03b1) : deriv 1 a = 0 :=\n  rfl\n#align regular_expression.deriv_one RegularExpression.deriv_one\n\n@[simp]\ntheorem deriv_char_self (a : \u03b1) : deriv (char a) a = 1 :=\n  if_pos rfl\n#align regular_expression.deriv_char_self RegularExpression.deriv_char_self\n\n@[simp]\ntheorem deriv_char_of_ne (h : a \u2260 b) : deriv (char a) b = 0 :=\n  if_neg h\n#align regular_expression.deriv_char_of_ne RegularExpression.deriv_char_of_ne\n\n@[simp]\ntheorem deriv_add (P Q : RegularExpression \u03b1) (a : \u03b1) : deriv (P + Q) a = deriv P a + deriv Q a :=\n  rfl\n#align regular_expression.deriv_add RegularExpression.deriv_add\n\n@[simp]\ntheorem deriv_star (P : RegularExpression \u03b1) (a : \u03b1) : deriv P.unit a = deriv P a * star P :=\n  rfl\n#align regular_expression.deriv_star RegularExpression.deriv_star\n\n/-- `P.rmatch x` is true if and only if `P` matches `x`. This is a computable definition equivalent\n  to `matches`. -/\ndef rmatch : RegularExpression \u03b1 \u2192 List \u03b1 \u2192 Bool\n  | P, [] => matchEpsilon P\n  | P, a :: as => rmatch (P.deriv a) as\n#align regular_expression.rmatch RegularExpression.rmatch\n\n@[simp]\ntheorem zero_rmatch (x : List \u03b1) : rmatch 0 x = false := by\n  induction x <;> simp [rmatch, match_epsilon, *]\n#align regular_expression.zero_rmatch RegularExpression.zero_rmatch\n\ntheorem one_rmatch_iff (x : List \u03b1) : rmatch 1 x \u2194 x = [] := by\n  induction x <;> simp [rmatch, match_epsilon, *]\n#align regular_expression.one_rmatch_iff RegularExpression.one_rmatch_iff\n\ntheorem char_rmatch_iff (a : \u03b1) (x : List \u03b1) : rmatch (char a) x \u2194 x = [a] :=\n  by\n  cases' x with _ x\n  decide\n  cases x\n  rw [rmatch, deriv]\n  split_ifs <;> tauto\n  rw [rmatch, deriv]\n  split_ifs\n  rw [one_rmatch_iff]\n  tauto\n  rw [zero_rmatch]\n  tauto\n#align regular_expression.char_rmatch_iff RegularExpression.char_rmatch_iff\n\ntheorem add_rmatch_iff (P Q : RegularExpression \u03b1) (x : List \u03b1) :\n    (P + Q).rmatch x \u2194 P.rmatch x \u2228 Q.rmatch x :=\n  by\n  induction' x with _ _ ih generalizing P Q\n  \u00b7 simp only [rmatch, match_epsilon, Bool.or_coe_iff]\n  \u00b7 repeat' rw [rmatch]\n    rw [deriv]\n    exact ih _ _\n#align regular_expression.add_rmatch_iff RegularExpression.add_rmatch_iff\n\ntheorem mul_rmatch_iff (P Q : RegularExpression \u03b1) (x : List \u03b1) :\n    (P * Q).rmatch x \u2194 \u2203 t u : List \u03b1, x = t ++ u \u2227 P.rmatch t \u2227 Q.rmatch u :=\n  by\n  induction' x with a x ih generalizing P Q\n  \u00b7 rw [rmatch, match_epsilon]\n    constructor\n    \u00b7 intro h\n      refine' \u27e8[], [], rfl, _\u27e9\n      rw [rmatch, rmatch]\n      rwa [Bool.and_coe_iff] at h\n    \u00b7 rintro \u27e8t, u, h\u2081, h\u2082\u27e9\n      cases' List.append_eq_nil.1 h\u2081.symm with ht hu\n      subst ht\n      subst hu\n      repeat' rw [rmatch] at h\u2082\n      simp [h\u2082]\n  \u00b7 rw [rmatch, deriv]\n    split_ifs with hepsilon\n    \u00b7 rw [add_rmatch_iff, ih]\n      constructor\n      \u00b7 rintro (\u27e8t, u, _\u27e9 | h)\n        \u00b7 exact \u27e8a :: t, u, by tauto\u27e9\n        \u00b7 exact \u27e8[], a :: x, rfl, hepsilon, h\u27e9\n      \u00b7 rintro \u27e8t, u, h, hP, hQ\u27e9\n        cases' t with b t\n        \u00b7 right\n          rw [List.nil_append] at h\n          rw [\u2190 h] at hQ\n          exact hQ\n        \u00b7 left\n          simp only [List.cons_append] at h\n          refine' \u27e8t, u, h.2, _, hQ\u27e9\n          rw [rmatch] at hP\n          convert hP\n          exact h.1\n    \u00b7 rw [ih]\n      constructor <;> rintro \u27e8t, u, h, hP, hQ\u27e9\n      \u00b7 exact \u27e8a :: t, u, by tauto\u27e9\n      \u00b7 cases' t with b t\n        \u00b7 contradiction\n        \u00b7 simp only [List.cons_append] at h\n          refine' \u27e8t, u, h.2, _, hQ\u27e9\n          rw [rmatch] at hP\n          convert hP\n          exact h.1\n#align regular_expression.mul_rmatch_iff RegularExpression.mul_rmatch_iff\n\ntheorem star_rmatch_iff (P : RegularExpression \u03b1) :\n    \u2200 x : List \u03b1, (star P).rmatch x \u2194 \u2203 S : List (List \u03b1), x = S.join \u2227 \u2200 t \u2208 S, t \u2260 [] \u2227 P.rmatch t\n  | x =>\n    by\n    have A : \u2200 m n : \u2115, n < m + n + 1 := by\n      intro m n\n      convert add_lt_add_of_le_of_lt (add_le_add (zero_le m) (le_refl n)) zero_lt_one\n      simp\n    have IH := fun t (h : List.length t < List.length x) => star_rmatch_iff t\n    clear star_rmatch_iff\n    constructor\n    \u00b7 cases' x with a x\n      \u00b7 intro\n        fconstructor\n        exact []\n        tauto\n      \u00b7 rw [rmatch, deriv, mul_rmatch_iff]\n        rintro \u27e8t, u, hs, ht, hu\u27e9\n        have hwf : u.length < (List.cons a x).length :=\n          by\n          rw [hs, List.length_cons, List.length_append]\n          apply A\n        rw [IH _ hwf] at hu\n        rcases hu with \u27e8S', hsum, helem\u27e9\n        use (a :: t) :: S'\n        constructor\n        \u00b7 simp [hs, hsum]\n        \u00b7 intro t' ht'\n          cases' ht' with ht' ht'\n          \u00b7 rw [ht']\n            exact \u27e8by decide, ht\u27e9\n          \u00b7 exact helem _ ht'\n    \u00b7 rintro \u27e8S, hsum, helem\u27e9\n      cases' x with a x\n      \u00b7 decide\n      \u00b7 rw [rmatch, deriv, mul_rmatch_iff]\n        cases' S with t' U\n        \u00b7 exact \u27e8[], [], by tauto\u27e9\n        \u00b7 cases' t' with b t\n          \u00b7 simp only [forall_eq_or_imp, List.mem_cons] at helem\n            simp only [eq_self_iff_true, not_true, Ne.def, false_and_iff] at helem\n            cases helem\n          simp only [List.join, List.cons_append] at hsum\n          refine' \u27e8t, U.join, hsum.2, _, _\u27e9\n          \u00b7 specialize helem (b :: t) (by simp)\n            rw [rmatch] at helem\n            convert helem.2\n            exact hsum.1\n          \u00b7 have hwf : U.join.length < (List.cons a x).length :=\n              by\n              rw [hsum.1, hsum.2]\n              simp only [List.length_append, List.length_join, List.length]\n              apply A\n            rw [IH _ hwf]\n            refine' \u27e8U, rfl, fun t h => helem t _\u27e9\n            right\n            assumption termination_by'\n  \u27e8fun L\u2081 L\u2082 : List _ => L\u2081.length < L\u2082.length, InvImage.wf _ Nat.lt_wfRel\u27e9\n#align regular_expression.star_rmatch_iff RegularExpression.star_rmatch_iff\n\n@[simp]\ntheorem rmatch_iff_matches (P : RegularExpression \u03b1) : \u2200 x : List \u03b1, P.rmatch x \u2194 x \u2208 P.matches :=\n  by\n  intro x\n  induction P generalizing x\n  all_goals\n    try rw [zero_def]\n    try rw [one_def]\n    try rw [plus_def]\n    try rw [comp_def]\n    rw [matches]\n  case zero =>\n    rw [zero_rmatch]\n    tauto\n  case epsilon =>\n    rw [one_rmatch_iff]\n    rfl\n  case char =>\n    rw [char_rmatch_iff]\n    rfl\n  case plus _ _ ih\u2081 ih\u2082 =>\n    rw [add_rmatch_iff, ih\u2081, ih\u2082]\n    rfl\n  case\n    comp P Q ih\u2081 ih\u2082 =>\n    simp only [mul_rmatch_iff, comp_def, Language.mul_def, exists_and_left, Set.mem_image2,\n      Set.image_prod]\n    constructor\n    \u00b7 rintro \u27e8x, y, hsum, hmatch\u2081, hmatch\u2082\u27e9\n      rw [ih\u2081] at hmatch\u2081\n      rw [ih\u2082] at hmatch\u2082\n      exact \u27e8x, hmatch\u2081, y, hmatch\u2082, hsum.symm\u27e9\n    \u00b7 rintro \u27e8x, hmatch\u2081, y, hmatch\u2082, hsum\u27e9\n      rw [\u2190 ih\u2081] at hmatch\u2081\n      rw [\u2190 ih\u2082] at hmatch\u2082\n      exact \u27e8x, y, hsum.symm, hmatch\u2081, hmatch\u2082\u27e9\n  case star _ ih =>\n    rw [star_rmatch_iff, Language.kstar_def_nonempty]\n    constructor\n    all_goals\n      rintro \u27e8S, hx, hS\u27e9\n      refine' \u27e8S, hx, _\u27e9\n      intro y\n      specialize hS y\n    \u00b7 rw [\u2190 ih y]\n      tauto\n    \u00b7 rw [ih y]\n      tauto\n#align regular_expression.rmatch_iff_matches RegularExpression.rmatch_iff_matches\n\ninstance (P : RegularExpression \u03b1) : DecidablePred P.matches :=\n  by\n  intro x\n  change Decidable (x \u2208 P.matches)\n  rw [\u2190 rmatch_iff_matches]\n  exact Eq.decidable _ _\n\nomit dec\n\n/-- Map the alphabet of a regular expression. -/\n@[simp]\ndef map (f : \u03b1 \u2192 \u03b2) : RegularExpression \u03b1 \u2192 RegularExpression \u03b2\n  | 0 => 0\n  | 1 => 1\n  | Char a => char (f a)\n  | R + S => map R + map S\n  | R * S => map R * map S\n  | star R => star (map R)\n#align regular_expression.map RegularExpression.map\n\n@[simp]\nprotected theorem map_pow (f : \u03b1 \u2192 \u03b2) (P : RegularExpression \u03b1) :\n    \u2200 n : \u2115, map f (P ^ n) = map f P ^ n\n  | 0 => rfl\n  | n + 1 => (congr_arg ((\u00b7 * \u00b7) (map f P)) (map_pow n) : _)\n#align regular_expression.map_pow RegularExpression.map_pow\n\n@[simp]\ntheorem map_id : \u2200 P : RegularExpression \u03b1, P.map id = P\n  | 0 => rfl\n  | 1 => rfl\n  | Char a => rfl\n  | R + S => by simp_rw [map, map_id]\n  | R * S => by simp_rw [map, map_id]\n  | star R => by simp_rw [map, map_id]\n#align regular_expression.map_id RegularExpression.map_id\n\n@[simp]\ntheorem map_map (g : \u03b2 \u2192 \u03b3) (f : \u03b1 \u2192 \u03b2) : \u2200 P : RegularExpression \u03b1, (P.map f).map g = P.map (g \u2218 f)\n  | 0 => rfl\n  | 1 => rfl\n  | Char a => rfl\n  | R + S => by simp_rw [map, map_map]\n  | R * S => by simp_rw [map, map_map]\n  | star R => by simp_rw [map, map_map]\n#align regular_expression.map_map RegularExpression.map_map\n\n/-- The language of the map is the map of the language. -/\n@[simp]\ntheorem matches_map (f : \u03b1 \u2192 \u03b2) :\n    \u2200 P : RegularExpression \u03b1, (P.map f).matches = Language.map f P.matches\n  | 0 => (map_zero _).symm\n  | 1 => (map_one _).symm\n  | Char a => by\n    rw [eq_comm]\n    exact image_singleton\n  | R + S => by simp only [matches_map, map, matches_add, map_add]\n  | R * S => by simp only [matches_map, map, matches_mul, map_mul]\n  | star R => by\n    simp_rw [map, matches, matches_map]\n    rw [Language.kstar_eq_sup\u1d62_pow, Language.kstar_eq_sup\u1d62_pow]\n    simp_rw [\u2190 map_pow]\n    exact image_Union.symm\n#align regular_expression.matches_map RegularExpression.matches_map\n\nend RegularExpression\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Computability/RegularExpressions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7249240571977714}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.reverse\nimport algebra.associated\nimport algebra.regular.smul\n\n/-!\n# Theory of monic polynomials\n\nWe give several tools for proving that polynomials are monic, e.g.\n`monic_mul`, `monic_map`.\n-/\n\nnoncomputable theory\n\nopen finset\nopen_locale big_operators classical\n\nnamespace polynomial\nuniverses u v y\nvariables {R : Type u} {S : Type v} {a b : R} {m n : \u2115} {\u03b9 : Type y}\n\nsection semiring\nvariables [semiring R] {p q r : polynomial R}\n\nlemma monic.as_sum {p : polynomial R} (hp : p.monic) :\n  p = X^(p.nat_degree) + (\u2211 i in range p.nat_degree, C (p.coeff i) * X^i) :=\nbegin\n  conv_lhs { rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] },\n  suffices : C (p.coeff p.nat_degree) = 1,\n  { rw [this, one_mul] },\n  exact congr_arg C hp\nend\n\nlemma ne_zero_of_monic_of_zero_ne_one (hp : monic p) (h : (0 : R) \u2260 1) :\n  p \u2260 0 := mt (congr_arg leading_coeff) $ by rw [monic.def.1 hp, leading_coeff_zero]; cc\n\nlemma ne_zero_of_ne_zero_of_monic (hp : p \u2260 0) (hq : monic q) : q \u2260 0 :=\nbegin\n  intro h, rw [h, monic.def, leading_coeff_zero] at hq,\n  rw [\u2190 mul_one p, \u2190 C_1, \u2190 hq, C_0, mul_zero] at hp,\n  exact hp rfl\nend\n\nlemma monic_map [semiring S] (f : R \u2192+* S) (hp : monic p) : monic (p.map f) :=\nif h : (0 : S) = 1 then\n  by haveI := subsingleton_of_zero_eq_one h;\n  exact subsingleton.elim _ _\nelse\nhave f (leading_coeff p) \u2260 0,\n  by rwa [show _ = _, from hp, f.map_one, ne.def, eq_comm],\nby\nbegin\n  rw [monic, leading_coeff, coeff_map],\n  suffices : p.coeff (map f p).nat_degree = 1, simp [this],\n  suffices : (map f p).nat_degree = p.nat_degree, rw this, exact hp,\n  rwa nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero f _)\nend\n\nlemma monic_C_mul_of_mul_leading_coeff_eq_one [nontrivial R] {b : R}\n  (hp : b * p.leading_coeff = 1) : monic (C b * p) :=\nby rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp]\n\nlemma monic_mul_C_of_leading_coeff_mul_eq_one [nontrivial R] {b : R}\n  (hp : p.leading_coeff * b = 1) : monic (p * C b) :=\nby rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp]\n\ntheorem monic_of_degree_le (n : \u2115) (H1 : degree p \u2264 n) (H2 : coeff p n = 1) : monic p :=\ndecidable.by_cases\n  (assume H : degree p < n, eq_of_zero_eq_one\n    (H2 \u25b8 (coeff_eq_zero_of_degree_lt H).symm) _ _)\n  (assume H : \u00acdegree p < n,\n    by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H])\n\ntheorem monic_X_pow_add {n : \u2115} (H : degree p \u2264 n) : monic (X ^ (n+1) + p) :=\nhave H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)),\nmonic_of_degree_le (n+1)\n  (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1)))\n  (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero])\n\ntheorem monic_X_add_C (x : R) : monic (X + C x) :=\npow_one (X : polynomial R) \u25b8 monic_X_pow_add degree_C_le\n\nlemma monic_mul (hp : monic p) (hq : monic q) : monic (p * q) :=\nif h0 : (0 : R) = 1 then by haveI := subsingleton_of_zero_eq_one h0;\n  exact subsingleton.elim _ _\nelse\n  have leading_coeff p * leading_coeff q \u2260 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0],\n  by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul]\n\nlemma monic_pow (hp : monic p) : \u2200 (n : \u2115), monic (p ^ n)\n| 0     := monic_one\n| (n+1) := by { rw pow_succ, exact monic_mul hp (monic_pow n) }\n\nlemma monic_add_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :\n  monic (p + q) :=\nby rwa [monic, add_comm, leading_coeff_add_of_degree_lt hpq]\n\nlemma monic_add_of_right {p q : polynomial R} (hq : monic q) (hpq : degree p < degree q) :\n  monic (p + q) :=\nby rwa [monic, leading_coeff_add_of_degree_lt hpq]\n\nnamespace monic\n\n@[simp]\nlemma nat_degree_eq_zero_iff_eq_one {p : polynomial R} (hp : p.monic) :\n  p.nat_degree = 0 \u2194 p = 1 :=\nbegin\n  split; intro h,\n  swap, { rw h, exact nat_degree_one },\n  have : p = C (p.coeff 0),\n  { rw \u2190 polynomial.degree_le_zero_iff,\n    rwa polynomial.nat_degree_eq_zero_iff_degree_le_zero at h },\n  rw this, convert C_1, rw \u2190 h, apply hp,\nend\n\n@[simp]\nlemma degree_le_zero_iff_eq_one {p : polynomial R} (hp : p.monic) :\n  p.degree \u2264 0 \u2194 p = 1 :=\nby rw [\u2190hp.nat_degree_eq_zero_iff_eq_one, nat_degree_eq_zero_iff_degree_le_zero]\n\nlemma nat_degree_mul {p q : polynomial R} (hp : p.monic) (hq : q.monic) :\n  (p * q).nat_degree = p.nat_degree + q.nat_degree :=\nbegin\n  nontriviality R,\n  apply nat_degree_mul',\n  simp [hp.leading_coeff, hq.leading_coeff]\nend\n\nlemma degree_mul_comm {p : polynomial R} (hp : p.monic) (q : polynomial R) :\n  (p * q).degree = (q * p).degree :=\nbegin\n  by_cases h : q = 0,\n  { simp [h] },\n  rw [degree_mul', hp.degree_mul],\n  { exact add_comm _ _ },\n  { rwa [hp.leading_coeff, one_mul, leading_coeff_ne_zero] }\nend\n\nlemma nat_degree_mul' {p q : polynomial R} (hp : p.monic) (hq : q \u2260 0) :\n  (p * q).nat_degree = p.nat_degree + q.nat_degree :=\nbegin\n  rw [nat_degree_mul', add_comm],\n  simpa [hp.leading_coeff, leading_coeff_ne_zero]\nend\n\nlemma nat_degree_mul_comm {p : polynomial R} (hp : p.monic) (q : polynomial R) :\n  (p * q).nat_degree = (q * p).nat_degree :=\nbegin\n  by_cases h : q = 0,\n  { simp [h] },\n  rw [hp.nat_degree_mul' h, polynomial.nat_degree_mul', add_comm],\n  simpa [hp.leading_coeff, leading_coeff_ne_zero]\nend\n\nlemma next_coeff_mul {p q : polynomial R} (hp : monic p) (hq : monic q) :\n  next_coeff (p * q) = next_coeff p + next_coeff q :=\nbegin\n  nontriviality,\n  simp only [\u2190 coeff_one_reverse],\n  rw reverse_mul;\n    simp [coeff_mul, nat.antidiagonal, hp.leading_coeff, hq.leading_coeff, add_comm]\nend\n\nlemma eq_one_of_map_eq_one {S : Type*} [semiring S] [nontrivial S]\n  (f : R \u2192+* S) (hp : p.monic) (map_eq : p.map f = 1) : p = 1 :=\nbegin\n  nontriviality R,\n  have hdeg : p.degree = 0,\n  { rw [\u2190 degree_map_eq_of_leading_coeff_ne_zero f _, map_eq, degree_one],\n    { rw [hp.leading_coeff, f.map_one],\n      exact one_ne_zero } },\n  have hndeg : p.nat_degree = 0 :=\n    with_bot.coe_eq_coe.mp ((degree_eq_nat_degree hp.ne_zero).symm.trans hdeg),\n  convert eq_C_of_degree_eq_zero hdeg,\n  rw [\u2190 hndeg, \u2190 polynomial.leading_coeff, hp.leading_coeff, C.map_one]\nend\n\nend monic\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R] {p : polynomial R}\n\nlemma monic_multiset_prod_of_monic (t : multiset \u03b9) (f : \u03b9 \u2192 polynomial R)\n  (ht : \u2200 i \u2208 t, monic (f i)) :\n  monic (t.map f).prod :=\nbegin\n  revert ht,\n  refine t.induction_on _ _, { simp },\n  intros a t ih ht,\n  rw [multiset.map_cons, multiset.prod_cons],\n  exact monic_mul\n    (ht _ (multiset.mem_cons_self _ _))\n    (ih (\u03bb _ hi, ht _ (multiset.mem_cons_of_mem hi)))\nend\n\nlemma monic_prod_of_monic (s : finset \u03b9) (f : \u03b9 \u2192 polynomial R) (hs : \u2200 i \u2208 s, monic (f i)) :\n  monic (\u220f i in s, f i) :=\nmonic_multiset_prod_of_monic s.1 f hs\n\nlemma is_unit_C {x : R} : is_unit (C x) \u2194 is_unit x :=\nbegin\n  rw [is_unit_iff_dvd_one, is_unit_iff_dvd_one],\n  split,\n  { rintros \u27e8g, hg\u27e9,\n    replace hg := congr_arg (eval 0) hg,\n    rw [eval_one, eval_mul, eval_C] at hg,\n    exact \u27e8g.eval 0, hg\u27e9 },\n  { rintros \u27e8y, hy\u27e9,\n    exact \u27e8C y, by rw [\u2190 C_mul, \u2190 hy, C_1]\u27e9 }\nend\n\nlemma eq_one_of_is_unit_of_monic (hm : monic p) (hpu : is_unit p) : p = 1 :=\nhave degree p \u2264 0,\n  from calc degree p \u2264 degree (1 : polynomial R) :\n    let \u27e8u, hu\u27e9 := is_unit_iff_dvd_one.1 hpu in\n    if hu0 : u = 0\n    then begin\n        rw [hu0, mul_zero] at hu,\n        rw [\u2190 mul_one p, hu, mul_zero],\n        simp\n      end\n    else have p.leading_coeff * u.leading_coeff \u2260 0,\n        by rw [hm.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero];\n          exact hu0,\n      by rw [hu, degree_mul' this];\n        exact le_add_of_nonneg_right (degree_nonneg_iff_ne_zero.2 hu0)\n  ... \u2264 0 : degree_one_le,\nby rw [eq_C_of_degree_le_zero this, \u2190 nat_degree_eq_zero_iff_degree_le_zero.2 this,\n    \u2190 leading_coeff, hm.leading_coeff, C_1]\n\nlemma monic.next_coeff_multiset_prod (t : multiset \u03b9) (f : \u03b9 \u2192 polynomial R)\n  (h : \u2200 i \u2208 t, monic (f i)) :\n  next_coeff (t.map f).prod = (t.map (\u03bb i, next_coeff (f i))).sum :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _),\n  { simp only [multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, multiset.map_zero,\n               multiset.prod_zero, multiset.sum_zero, not_false_iff, forall_true_iff],\n    rw \u2190 C_1, rw next_coeff_C_eq_zero },\n  { rw [multiset.map_cons, multiset.prod_cons, multiset.map_cons, multiset.sum_cons,\n        monic.next_coeff_mul, ih],\n    exacts [\u03bb i hi, ht i (multiset.mem_cons_of_mem hi), ht a (multiset.mem_cons_self _ _),\n            monic_multiset_prod_of_monic _ _ (\u03bb b bs, ht _ (multiset.mem_cons_of_mem bs))] }\nend\n\nlemma monic.next_coeff_prod (s : finset \u03b9) (f : \u03b9 \u2192 polynomial R) (h : \u2200 i \u2208 s, monic (f i)) :\n  next_coeff (\u220f i in s, f i) = \u2211 i in s, next_coeff (f i) :=\nmonic.next_coeff_multiset_prod s.1 f h\n\nend comm_semiring\n\nsection ring\nvariables [ring R] {p : polynomial R}\n\ntheorem monic_X_sub_C (x : R) : monic (X - C x) :=\nby simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)\n\ntheorem monic_X_pow_sub {n : \u2115} (H : degree p \u2264 n) : monic (X ^ (n+1) - p) :=\nby simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) \u2264 n, by rwa \u2190degree_neg p at H)\n\n/-- `X ^ n - a` is monic. -/\nlemma monic_X_pow_sub_C {R : Type u} [ring R] (a : R) {n : \u2115} (h : n \u2260 0) : (X ^ n - C a).monic :=\nbegin\n  obtain \u27e8k, hk\u27e9 := nat.exists_eq_succ_of_ne_zero h,\n  convert monic_X_pow_sub _,\n  exact le_trans degree_C_le nat.with_bot.coe_nonneg,\nend\n\nlemma not_is_unit_X_pow_sub_one (R : Type*) [comm_ring R] [nontrivial R] (n : \u2115) :\n  \u00ac is_unit (X ^ n - 1 : polynomial R) :=\nbegin\n  intro h,\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simpa using h },\n  apply hn,\n  rwa [\u2190 @nat_degree_X_pow_sub_C _ _ _ n (1 : R),\n      eq_one_of_is_unit_of_monic (monic_X_pow_sub_C (1 : R) hn),\n      nat_degree_one]\nend\n\nlemma monic_sub_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :\n  monic (p - q) :=\nby { rw sub_eq_add_neg, apply monic_add_of_left hp, rwa degree_neg }\n\nlemma monic_sub_of_right {p q : polynomial R}\n  (hq : q.leading_coeff = -1) (hpq : degree p < degree q) : monic (p - q) :=\nhave (-q).coeff (-q).nat_degree = 1 :=\nby rw [nat_degree_neg, coeff_neg, show q.coeff q.nat_degree = -1, from hq, neg_neg],\nby { rw sub_eq_add_neg, apply monic_add_of_right this, rwa degree_neg }\n\nsection injective\nopen function\nvariables [semiring S] {f : R \u2192+* S} (hf : injective f)\ninclude hf\n\nlemma degree_map_eq_of_injective (p : polynomial R) : degree (p.map f) = degree p :=\nif h : p = 0 then by simp [h]\nelse degree_map_eq_of_leading_coeff_ne_zero _\n  (by rw [\u2190 f.map_zero]; exact mt hf.eq_iff.1\n    (mt leading_coeff_eq_zero.1 h))\n\nlemma degree_map' (p : polynomial R) :\n  degree (p.map f) = degree p :=\np.degree_map_eq_of_injective hf\n\nlemma nat_degree_map' (p : polynomial R) :\n  nat_degree (p.map f) = nat_degree p :=\nnat_degree_eq_of_degree_eq (degree_map' hf p)\n\nlemma leading_coeff_map' (p : polynomial R) :\n  leading_coeff (p.map f) = f (leading_coeff p) :=\nbegin\n  unfold leading_coeff,\n  rw [coeff_map, nat_degree_map' hf p],\nend\n\nlemma next_coeff_map (p : polynomial R) :\n  (p.map f).next_coeff = f p.next_coeff :=\nbegin\n  unfold next_coeff,\n  rw nat_degree_map' hf,\n  split_ifs; simp\nend\n\nlemma leading_coeff_of_injective (p : polynomial R) :\n  leading_coeff (p.map f) = f (leading_coeff p) :=\nbegin\n  delta leading_coeff,\n  rw [coeff_map f, nat_degree_map' hf p]\nend\n\nlemma monic_of_injective {p : polynomial R} (hp : (p.map f).monic) : p.monic :=\nbegin\n  apply hf,\n  rw [\u2190 leading_coeff_of_injective hf, hp.leading_coeff, f.map_one]\nend\n\nend injective\nend ring\n\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : polynomial R}\n\n@[simp] lemma not_monic_zero : \u00acmonic (0 : polynomial R) :=\nby simpa only [monic, leading_coeff_zero] using (zero_ne_one : (0 : R) \u2260 1)\n\nlemma ne_zero_of_monic (h : monic p) : p \u2260 0 :=\n\u03bb h\u2081, @not_monic_zero R _ _ (h\u2081 \u25b8 h)\n\nend nonzero_semiring\n\nsection not_zero_divisor\n\n-- TODO: using gh-8537, rephrase lemmas that involve commutation around `*` using the op-ring\n\nvariables [semiring R] {p : polynomial R}\n\nlemma monic.mul_left_ne_zero (hp : monic p) {q : polynomial R} (hq : q \u2260 0) :\n  q * p \u2260 0 :=\nbegin\n  by_cases h : p = 1,\n  { simpa [h] },\n  rw [ne.def, \u2190degree_eq_bot, hp.degree_mul, with_bot.add_eq_bot, not_or_distrib, degree_eq_bot],\n  refine \u27e8hq, _\u27e9,\n  rw [\u2190hp.degree_le_zero_iff_eq_one, not_le] at h,\n  refine (lt_trans _ h).ne',\n  simp\nend\n\nlemma monic.mul_right_ne_zero (hp : monic p) {q : polynomial R} (hq : q \u2260 0) :\n  p * q \u2260 0 :=\nbegin\n  by_cases h : p = 1,\n  { simpa [h] },\n  rw [ne.def, \u2190degree_eq_bot, hp.degree_mul_comm, hp.degree_mul, with_bot.add_eq_bot,\n      not_or_distrib, degree_eq_bot],\n  refine \u27e8hq, _\u27e9,\n  rw [\u2190hp.degree_le_zero_iff_eq_one, not_le] at h,\n  refine (lt_trans _ h).ne',\n  simp\nend\n\nlemma monic.mul_nat_degree_lt_iff (h : monic p) {q : polynomial R} :\n  (p * q).nat_degree < p.nat_degree \u2194 p \u2260 1 \u2227 q = 0 :=\nbegin\n  by_cases hq : q = 0,\n  { suffices : 0 < p.nat_degree \u2194 p.nat_degree \u2260 0,\n    { simpa [hq, \u2190h.nat_degree_eq_zero_iff_eq_one] },\n    exact \u27e8\u03bb h, h.ne', \u03bb h, lt_of_le_of_ne (nat.zero_le _) h.symm \u27e9 },\n  { simp [h.nat_degree_mul', hq] }\nend\n\nlemma monic.mul_right_eq_zero_iff (h : monic p) {q : polynomial R} :\n  p * q = 0 \u2194 q = 0 :=\nbegin\n  by_cases hq : q = 0;\n  simp [h.mul_right_ne_zero, hq]\nend\n\nlemma monic.mul_left_eq_zero_iff (h : monic p) {q : polynomial R} :\n  q * p = 0 \u2194 q = 0 :=\nbegin\n  by_cases hq : q = 0;\n  simp [h.mul_left_ne_zero, hq]\nend\n\nlemma monic.is_regular {R : Type*} [ring R] {p : polynomial R} (hp : monic p) : is_regular p :=\nbegin\n  split,\n  { intros q r h,\n    rw [\u2190sub_eq_zero, \u2190hp.mul_right_eq_zero_iff, mul_sub, h, sub_self] },\n  { intros q r h,\n    simp only at h,\n    rw [\u2190sub_eq_zero, \u2190hp.mul_left_eq_zero_iff, sub_mul, h, sub_self] }\nend\n\nlemma degree_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]\n  {k : S} (p : polynomial R) (h : is_smul_regular R k) :\n  (k \u2022 p).degree = p.degree :=\nbegin\n  refine le_antisymm _ _,\n  { rw degree_le_iff_coeff_zero,\n    intros m hm,\n    rw degree_lt_iff_coeff_zero at hm,\n    simp [hm m le_rfl] },\n  { rw degree_le_iff_coeff_zero,\n    intros m hm,\n    rw degree_lt_iff_coeff_zero at hm,\n    refine h _,\n    simpa using hm m le_rfl },\nend\n\nlemma nat_degree_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]\n  {k : S} (p : polynomial R) (h : is_smul_regular R k) :\n  (k \u2022 p).nat_degree = p.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp] },\n  rw [\u2190with_bot.coe_eq_coe, \u2190degree_eq_nat_degree hp, \u2190degree_eq_nat_degree,\n      degree_smul_of_smul_regular p h],\n  contrapose! hp,\n  rw \u2190smul_zero k at hp,\n  exact h.polynomial hp\nend\n\nlemma leading_coeff_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]\n  {k : S} (p : polynomial R) (h : is_smul_regular R k) :\n  (k \u2022 p).leading_coeff = k \u2022 p.leading_coeff :=\nby rw [leading_coeff, leading_coeff, coeff_smul, nat_degree_smul_of_smul_regular p h]\n\nlemma monic_of_is_unit_leading_coeff_inv_smul (h : is_unit p.leading_coeff) :\n  monic (h.unit\u207b\u00b9 \u2022 p) :=\nbegin\n  rw [monic.def, leading_coeff_smul_of_smul_regular _ (is_smul_regular_of_group _), units.smul_def],\n  obtain \u27e8k, hk\u27e9 := h,\n  simp only [\u2190hk, smul_eq_mul, \u2190units.coe_mul, units.coe_eq_one, inv_mul_eq_iff_eq_mul],\n  simp [units.ext_iff, is_unit.unit_spec]\nend\n\nlemma is_unit_leading_coeff_mul_right_eq_zero_iff (h : is_unit p.leading_coeff) {q : polynomial R} :\n  p * q = 0 \u2194 q = 0 :=\nbegin\n  split,\n  { intro hp,\n    rw \u2190smul_eq_zero_iff_eq (h.unit)\u207b\u00b9 at hp,\n    have : (h.unit)\u207b\u00b9 \u2022 (p * q) = ((h.unit)\u207b\u00b9 \u2022 p) * q,\n    { ext,\n      simp only [units.smul_def, coeff_smul, coeff_mul, smul_eq_mul, mul_sum],\n      refine sum_congr rfl (\u03bb x hx, _),\n      rw \u2190mul_assoc },\n    rwa [this, monic.mul_right_eq_zero_iff] at hp,\n    exact monic_of_is_unit_leading_coeff_inv_smul _ },\n  { rintro rfl,\n    simp }\nend\n\n\n\nend not_zero_divisor\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/monic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7249240472165062}}
{"text": "/-\nCopyright (c) 2022 Alexander Bentkamp. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.spectrum\n! leanprover-community/mathlib commit 46b633fd842bef9469441c0209906f6dddd2b4f5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.InnerProductSpace.Spectrum\nimport Mathbin.LinearAlgebra.Matrix.Hermitian\n\n/-! # Spectral theory of hermitian matrices\n\nThis file proves the spectral theorem for matrices. The proof of the spectral theorem is based on\nthe spectral theorem for linear maps (`diagonalization_basis_apply_self_apply`).\n\n## Tags\n\nspectral theorem, diagonalization theorem\n\n-/\n\n\nnamespace Matrix\n\nvariable {\ud835\udd5c : Type _} [IsROrC \ud835\udd5c] [DecidableEq \ud835\udd5c] {n : Type _} [Fintype n] [DecidableEq n]\n\nvariable {A : Matrix n n \ud835\udd5c}\n\nopen Matrix\n\nopen BigOperators\n\nnamespace IsHermitian\n\nvariable (hA : A.IsHermitian)\n\n/-- The eigenvalues of a hermitian matrix, indexed by `fin (fintype.card n)` where `n` is the index\ntype of the matrix. -/\nnoncomputable def eigenvalues\u2080 : Fin (Fintype.card n) \u2192 \u211d :=\n  (isHermitian_iff_isSymmetric.1 hA).Eigenvalues finrank_euclideanSpace\n#align matrix.is_hermitian.eigenvalues\u2080 Matrix.IsHermitian.eigenvalues\u2080\n\n/-- The eigenvalues of a hermitian matrix, reusing the index `n` of the matrix entries. -/\nnoncomputable def eigenvalues : n \u2192 \u211d := fun i =>\n  hA.eigenvalues\u2080 <| (Fintype.equivOfCardEq (Fintype.card_fin _)).symm i\n#align matrix.is_hermitian.eigenvalues Matrix.IsHermitian.eigenvalues\n\n/-- A choice of an orthonormal basis of eigenvectors of a hermitian matrix. -/\nnoncomputable def eigenvectorBasis : OrthonormalBasis n \ud835\udd5c (EuclideanSpace \ud835\udd5c n) :=\n  ((isHermitian_iff_isSymmetric.1 hA).eigenvectorBasis finrank_euclideanSpace).reindex\n    (Fintype.equivOfCardEq (Fintype.card_fin _))\n#align matrix.is_hermitian.eigenvector_basis Matrix.IsHermitian.eigenvectorBasis\n\n/-- A matrix whose columns are an orthonormal basis of eigenvectors of a hermitian matrix. -/\nnoncomputable def eigenvectorMatrix : Matrix n n \ud835\udd5c :=\n  (PiLp.basisFun _ \ud835\udd5c n).toMatrix (eigenvectorBasis hA).toBasis\n#align matrix.is_hermitian.eigenvector_matrix Matrix.IsHermitian.eigenvectorMatrix\n\n/-- The inverse of `eigenvector_matrix` -/\nnoncomputable def eigenvectorMatrixInv : Matrix n n \ud835\udd5c :=\n  (eigenvectorBasis hA).toBasis.toMatrix (PiLp.basisFun _ \ud835\udd5c n)\n#align matrix.is_hermitian.eigenvector_matrix_inv Matrix.IsHermitian.eigenvectorMatrixInv\n\ntheorem eigenvectorMatrix_mul_inv : hA.eigenvectorMatrix \u2b1d hA.eigenvectorMatrixInv = 1 := by\n  apply Basis.toMatrix_mul_toMatrix_flip\n#align matrix.is_hermitian.eigenvector_matrix_mul_inv Matrix.IsHermitian.eigenvectorMatrix_mul_inv\n\nnoncomputable instance : Invertible hA.eigenvectorMatrixInv :=\n  invertibleOfLeftInverse _ _ hA.eigenvectorMatrix_mul_inv\n\nnoncomputable instance : Invertible hA.eigenvectorMatrix :=\n  invertibleOfRightInverse _ _ hA.eigenvectorMatrix_mul_inv\n\ntheorem eigenvectorMatrix_apply (i j : n) : hA.eigenvectorMatrix i j = hA.eigenvectorBasis j i := by\n  simp_rw [eigenvector_matrix, Basis.toMatrix_apply, OrthonormalBasis.coe_toBasis,\n    PiLp.basisFun_repr]\n#align matrix.is_hermitian.eigenvector_matrix_apply Matrix.IsHermitian.eigenvectorMatrix_apply\n\ntheorem eigenvectorMatrixInv_apply (i j : n) :\n    hA.eigenvectorMatrixInv i j = star (hA.eigenvectorBasis i j) := by\n  rw [eigenvector_matrix_inv, Basis.toMatrix_apply, OrthonormalBasis.coe_toBasis_repr_apply,\n    OrthonormalBasis.repr_apply_apply, PiLp.basisFun_apply, PiLp.equiv_symm_single,\n    EuclideanSpace.inner_single_right, one_mul, IsROrC.star_def]\n#align matrix.is_hermitian.eigenvector_matrix_inv_apply Matrix.IsHermitian.eigenvectorMatrixInv_apply\n\ntheorem conjTranspose_eigenvectorMatrixInv : hA.eigenvectorMatrixInv\u1d34 = hA.eigenvectorMatrix :=\n  by\n  ext (i j)\n  rw [conj_transpose_apply, eigenvector_matrix_inv_apply, eigenvector_matrix_apply, star_star]\n#align matrix.is_hermitian.conj_transpose_eigenvector_matrix_inv Matrix.IsHermitian.conjTranspose_eigenvectorMatrixInv\n\ntheorem conjTranspose_eigenvectorMatrix : hA.eigenvectorMatrix\u1d34 = hA.eigenvectorMatrixInv := by\n  rw [\u2190 conj_transpose_eigenvector_matrix_inv, conj_transpose_conj_transpose]\n#align matrix.is_hermitian.conj_transpose_eigenvector_matrix Matrix.IsHermitian.conjTranspose_eigenvectorMatrix\n\n/-- *Diagonalization theorem*, *spectral theorem* for matrices; A hermitian matrix can be\ndiagonalized by a change of basis.\n\nFor the spectral theorem on linear maps, see `diagonalization_basis_apply_self_apply`. -/\ntheorem spectral_theorem :\n    hA.eigenvectorMatrixInv \u2b1d A = diagonal (coe \u2218 hA.Eigenvalues) \u2b1d hA.eigenvectorMatrixInv :=\n  by\n  rw [eigenvector_matrix_inv, PiLp.basis_toMatrix_basisFun_mul]\n  ext (i j)\n  have := is_hermitian_iff_is_symmetric.1 hA\n  convert this.diagonalization_basis_apply_self_apply finrank_euclideanSpace\n      (EuclideanSpace.single j 1) ((Fintype.equivOfCardEq (Fintype.card_fin _)).symm i) using\n    1\n  \u00b7 dsimp only [EuclideanSpace.single, to_euclidean_lin_pi_Lp_equiv_symm, to_lin'_apply,\n      Matrix.of_apply, is_hermitian.eigenvector_basis]\n    simp_rw [mul_vec_single, mul_one, OrthonormalBasis.coe_toBasis_repr_apply,\n      OrthonormalBasis.repr_reindex]\n    rfl\n  \u00b7 simp only [diagonal_mul, (\u00b7 \u2218 \u00b7), eigenvalues]\n    rw [eigenvector_basis, Basis.toMatrix_apply, OrthonormalBasis.coe_toBasis_repr_apply,\n      OrthonormalBasis.repr_reindex, eigenvalues\u2080, PiLp.basisFun_apply, PiLp.equiv_symm_single]\n#align matrix.is_hermitian.spectral_theorem Matrix.IsHermitian.spectral_theorem\n\ntheorem eigenvalues_eq (i : n) :\n    hA.Eigenvalues i =\n      IsROrC.re (star (hA.eigenvectorMatrix\u1d40 i) \u2b1d\u1d65 A.mulVec (hA.eigenvectorMatrix\u1d40 i)) :=\n  by\n  have := hA.spectral_theorem\n  rw [\u2190 Matrix.mul_inv_eq_iff_eq_mul_of_invertible] at this\n  have := congr_arg IsROrC.re (congr_fun (congr_fun this i) i)\n  rw [diagonal_apply_eq, IsROrC.of_real_re, inv_eq_left_inv hA.eigenvector_matrix_mul_inv, \u2190\n    conj_transpose_eigenvector_matrix, mul_mul_apply] at this\n  exact this.symm\n#align matrix.is_hermitian.eigenvalues_eq Matrix.IsHermitian.eigenvalues_eq\n\n/-- The determinant of a hermitian matrix is the product of its eigenvalues. -/\ntheorem det_eq_prod_eigenvalues : det A = \u220f i, hA.Eigenvalues i :=\n  by\n  apply mul_left_cancel\u2080 (det_ne_zero_of_left_inverse (eigenvector_matrix_mul_inv hA))\n  rw [\u2190 det_mul, spectral_theorem, det_mul, mul_comm, det_diagonal]\n#align matrix.is_hermitian.det_eq_prod_eigenvalues Matrix.IsHermitian.det_eq_prod_eigenvalues\n\nend IsHermitian\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/Spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.7248705636223495}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov, Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Anne Baanen\n\n! This file was ported from Lean 3 source module algebra.big_operators.fin\n! leanprover-community/mathlib commit f93c11933efbc3c2f0299e47b8ff83e9b539cbf6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fintype.BigOperators\nimport Mathlib.Data.Fintype.Fin\nimport Mathlib.Data.List.FinRange\nimport Mathlib.Logic.Equiv.Fin\n\n/-!\n# Big operators and `Fin`\n\nSome results about products and sums over the type `Fin`.\n\nThe most important results are the induction formulas `Fin.prod_univ_castSucc`\nand `Fin.prod_univ_succ`, and the formula `Fin.prod_const` for the product of a\nconstant function. These results have variants for sums instead of products.\n\n-/\n\nopen BigOperators\n\nopen Finset\n\nvariable {\u03b1 : Type _} {\u03b2 : Type _}\n\nnamespace Finset\n\n@[to_additive]\ntheorem prod_range [CommMonoid \u03b2] {n : \u2115} (f : \u2115 \u2192 \u03b2) :\n    (\u220f i in Finset.range n, f i) = \u220f i : Fin n, f i :=\n  prod_bij' (fun k w => \u27e8k, mem_range.mp w\u27e9) (fun _ _ => mem_univ _)\n    (fun _ _ => congr_arg _ (Fin.val_mk _).symm) (fun a _ => a) (fun a _ => mem_range.mpr a.prop)\n    (fun _ _ => Fin.val_mk _) fun _ _ => Fin.eta _ _\n#align finset.prod_range Finset.prod_range\n#align finset.sum_range Finset.sum_range\n\nend Finset\n\nnamespace Fin\n\n@[to_additive]\ntheorem prod_univ_def [CommMonoid \u03b2] {n : \u2115} (f : Fin n \u2192 \u03b2) :\n    (\u220f i, f i) = ((List.finRange n).map f).prod := by simp [univ_def]\n#align fin.prod_univ_def Fin.prod_univ_def\n#align fin.sum_univ_def Fin.sum_univ_def\n\n@[to_additive]\ntheorem prod_ofFn [CommMonoid \u03b2] {n : \u2115} (f : Fin n \u2192 \u03b2) : (List.ofFn f).prod = \u220f i, f i := by\n  rw [List.ofFn_eq_map, prod_univ_def]\n#align fin.prod_of_fn Fin.prod_ofFn\n#align fin.sum_of_fn Fin.sum_ofFn\n\n/-- A product of a function `f : Fin 0 \u2192 \u03b2` is `1` because `Fin 0` is empty -/\n@[to_additive \"A sum of a function `f : Fin 0 \u2192 \u03b2` is `0` because `Fin 0` is empty\"]\ntheorem prod_univ_zero [CommMonoid \u03b2] (f : Fin 0 \u2192 \u03b2) : (\u220f i, f i) = 1 :=\n  rfl\n#align fin.prod_univ_zero Fin.prod_univ_zero\n#align fin.sum_univ_zero Fin.sum_univ_zero\n\n/-- A product of a function `f : Fin (n + 1) \u2192 \u03b2` over all `Fin (n + 1)`\nis the product of `f x`, for some `x : Fin (n + 1)` times the remaining product -/\n@[to_additive \"A sum of a function `f : Fin (n + 1) \u2192 \u03b2` over all `Fin (n + 1)` is the sum of\n`f x`, for some `x : Fin (n + 1)` plus the remaining product\"]\ntheorem prod_univ_succAbove [CommMonoid \u03b2] {n : \u2115} (f : Fin (n + 1) \u2192 \u03b2) (x : Fin (n + 1)) :\n    (\u220f i, f i) = f x * \u220f i : Fin n, f (x.succAbove i) := by\n  rw [univ_succAbove, prod_cons, Finset.prod_map]\n#align fin.prod_univ_succ_above Fin.prod_univ_succAbove\n#align fin.sum_univ_succ_above Fin.sum_univ_succAbove\n\n/-- A product of a function `f : Fin (n + 1) \u2192 \u03b2` over all `Fin (n + 1)`\nis the product of `f 0` plus the remaining product -/\n@[to_additive \"A sum of a function `f : Fin (n + 1) \u2192 \u03b2` over all `Fin (n + 1)` is the sum of\n`f 0` plus the remaining product\"]\ntheorem prod_univ_succ [CommMonoid \u03b2] {n : \u2115} (f : Fin (n + 1) \u2192 \u03b2) :\n    (\u220f i, f i) = f 0 * \u220f i : Fin n, f i.succ :=\n  prod_univ_succAbove f 0\n#align fin.prod_univ_succ Fin.prod_univ_succ\n#align fin.sum_univ_succ Fin.sum_univ_succ\n\n/-- A product of a function `f : Fin (n + 1) \u2192 \u03b2` over all `Fin (n + 1)`\nis the product of `f (Fin.last n)` plus the remaining product -/\n@[to_additive \"A sum of a function `f : Fin (n + 1) \u2192 \u03b2` over all `Fin (n + 1)` is the sum of\n`f (Fin.last n)` plus the remaining sum\"]\ntheorem prod_univ_castSucc [CommMonoid \u03b2] {n : \u2115} (f : Fin (n + 1) \u2192 \u03b2) :\n    (\u220f i, f i) = (\u220f i : Fin n, f (Fin.castSucc i)) * f (last n) := by\n  simpa [mul_comm] using prod_univ_succAbove f (last n)\n#align fin.prod_univ_cast_succ Fin.prod_univ_castSucc\n#align fin.sum_univ_cast_succ Fin.sum_univ_castSucc\n\n@[to_additive]\ntheorem prod_cons [CommMonoid \u03b2] {n : \u2115} (x : \u03b2) (f : Fin n \u2192 \u03b2) :\n    (\u220f i : Fin n.succ, (cons x f : Fin n.succ \u2192 \u03b2) i) = x * \u220f i : Fin n, f i := by\n  simp_rw [prod_univ_succ, cons_zero, cons_succ]\n#align fin.prod_cons Fin.prod_cons\n#align fin.sum_cons Fin.sum_cons\n\n@[to_additive sum_univ_one]\ntheorem prod_univ_one [CommMonoid \u03b2] (f : Fin 1 \u2192 \u03b2) : (\u220f i, f i) = f 0 := by simp\n#align fin.prod_univ_one Fin.prod_univ_one\n#align fin.sum_univ_one Fin.sum_univ_one\n\n@[to_additive (attr := simp)]\ntheorem prod_univ_two [CommMonoid \u03b2] (f : Fin 2 \u2192 \u03b2) : (\u220f i, f i) = f 0 * f 1 := by\n  simp [prod_univ_succ]\n#align fin.prod_univ_two Fin.prod_univ_two\n#align fin.sum_univ_two Fin.sum_univ_two\n\n@[to_additive]\n\n\n@[to_additive]\ntheorem prod_univ_four [CommMonoid \u03b2] (f : Fin 4 \u2192 \u03b2) : (\u220f i, f i) = f 0 * f 1 * f 2 * f 3 := by\n  rw [prod_univ_castSucc, prod_univ_three]\n  rfl\n#align fin.prod_univ_four Fin.prod_univ_four\n#align fin.sum_univ_four Fin.sum_univ_four\n\n@[to_additive]\ntheorem prod_univ_five [CommMonoid \u03b2] (f : Fin 5 \u2192 \u03b2) :\n    (\u220f i, f i) = f 0 * f 1 * f 2 * f 3 * f 4 := by\n  rw [prod_univ_castSucc, prod_univ_four]\n  rfl\n#align fin.prod_univ_five Fin.prod_univ_five\n#align fin.sum_univ_five Fin.sum_univ_five\n\n@[to_additive]\ntheorem prod_univ_six [CommMonoid \u03b2] (f : Fin 6 \u2192 \u03b2) :\n    (\u220f i, f i) = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 := by\n  rw [prod_univ_castSucc, prod_univ_five]\n  rfl\n#align fin.prod_univ_six Fin.prod_univ_six\n#align fin.sum_univ_six Fin.sum_univ_six\n\n@[to_additive]\ntheorem prod_univ_seven [CommMonoid \u03b2] (f : Fin 7 \u2192 \u03b2) :\n    (\u220f i, f i) = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 := by\n  rw [prod_univ_castSucc, prod_univ_six]\n  rfl\n#align fin.prod_univ_seven Fin.prod_univ_seven\n#align fin.sum_univ_seven Fin.sum_univ_seven\n\n@[to_additive]\ntheorem prod_univ_eight [CommMonoid \u03b2] (f : Fin 8 \u2192 \u03b2) :\n    (\u220f i, f i) = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 * f 7 := by\n  rw [prod_univ_castSucc, prod_univ_seven]\n  rfl\n#align fin.prod_univ_eight Fin.prod_univ_eight\n#align fin.sum_univ_eight Fin.sum_univ_eight\n\ntheorem sum_pow_mul_eq_add_pow {n : \u2115} {R : Type _} [CommSemiring R] (a b : R) :\n    (\u2211 s : Finset (Fin n), a ^ s.card * b ^ (n - s.card)) = (a + b) ^ n := by\n  simpa using Fintype.sum_pow_mul_eq_add_pow (Fin n) a b\n#align fin.sum_pow_mul_eq_add_pow Fin.sum_pow_mul_eq_add_pow\n\ntheorem prod_const [CommMonoid \u03b1] (n : \u2115) (x : \u03b1) : (\u220f _i : Fin n, x) = x ^ n := by simp\n#align fin.prod_const Fin.prod_const\n\ntheorem sum_const [AddCommMonoid \u03b1] (n : \u2115) (x : \u03b1) : (\u2211 _i : Fin n, x) = n \u2022 x := by simp\n#align fin.sum_const Fin.sum_const\n\n@[to_additive]\ntheorem prod_Ioi_zero {M : Type _} [CommMonoid M] {n : \u2115} {v : Fin n.succ \u2192 M} :\n    (\u220f i in Ioi 0, v i) = \u220f j : Fin n, v j.succ := by\n  rw [Ioi_zero_eq_map, Finset.prod_map, val_succEmbedding]\n#align fin.prod_Ioi_zero Fin.prod_Ioi_zero\n#align fin.sum_Ioi_zero Fin.sum_Ioi_zero\n\n@[to_additive]\ntheorem prod_Ioi_succ {M : Type _} [CommMonoid M] {n : \u2115} (i : Fin n) (v : Fin n.succ \u2192 M) :\n    (\u220f j in Ioi i.succ, v j) = \u220f j in Ioi i, v j.succ := by\n  rw [Ioi_succ, Finset.prod_map, val_succEmbedding]\n#align fin.prod_Ioi_succ Fin.prod_Ioi_succ\n#align fin.sum_Ioi_succ Fin.sum_Ioi_succ\n\n@[to_additive]\ntheorem prod_congr' {M : Type _} [CommMonoid M] {a b : \u2115} (f : Fin b \u2192 M) (h : a = b) :\n    (\u220f i : Fin a, f (cast h i)) = \u220f i : Fin b, f i := by\n  subst h\n  congr\n#align fin.prod_congr' Fin.prod_congr'\n#align fin.sum_congr' Fin.sum_congr'\n\n@[to_additive]\ntheorem prod_univ_add {M : Type _} [CommMonoid M] {a b : \u2115} (f : Fin (a + b) \u2192 M) :\n    (\u220f i : Fin (a + b), f i) = (\u220f i : Fin a, f (castAdd b i)) * \u220f i : Fin b, f (natAdd a i) := by\n  rw [Fintype.prod_equiv finSumFinEquiv.symm f fun i => f (finSumFinEquiv.toFun i)]\n  \u00b7 apply Fintype.prod_sum_type\n  \u00b7 intro x\n    simp only [Equiv.toFun_as_coe, Equiv.apply_symm_apply]\n#align fin.prod_univ_add Fin.prod_univ_add\n#align fin.sum_univ_add Fin.sum_univ_add\n\n@[to_additive]\ntheorem prod_trunc {M : Type _} [CommMonoid M] {a b : \u2115} (f : Fin (a + b) \u2192 M)\n    (hf : \u2200 j : Fin b, f (natAdd a j) = 1) :\n    (\u220f i : Fin (a + b), f i) = \u220f i : Fin a, f (castLe (Nat.le.intro rfl) i) := by\n  rw [prod_univ_add, Fintype.prod_eq_one _ hf, mul_one]\n  rfl\n#align fin.prod_trunc Fin.prod_trunc\n#align fin.sum_trunc Fin.sum_trunc\n\nsection PartialProd\n\nvariable [Monoid \u03b1] {n : \u2115}\n\n/-- For `f = (a\u2081, ..., a\u2099)` in `\u03b1\u207f`, `partialProd f` is `(1, a\u2081, a\u2081a\u2082, ..., a\u2081...a\u2099)` in `\u03b1\u207f\u207a\u00b9`. -/\n@[to_additive \"For `f = (a\u2081, ..., a\u2099)` in `\u03b1\u207f`, `partialSum f` is\\n\n`(0, a\u2081, a\u2081 + a\u2082, ..., a\u2081 + ... + a\u2099)` in `\u03b1\u207f\u207a\u00b9`.\"]\ndef partialProd (f : Fin n \u2192 \u03b1) (i : Fin (n + 1)) : \u03b1 :=\n  ((List.ofFn f).take i).prod\n#align fin.partial_prod Fin.partialProd\n#align fin.partial_sum Fin.partialSum\n\n@[to_additive (attr := simp)]\ntheorem partialProd_zero (f : Fin n \u2192 \u03b1) : partialProd f 0 = 1 := by simp [partialProd]\n#align fin.partial_prod_zero Fin.partialProd_zero\n#align fin.partial_sum_zero Fin.partialSum_zero\n\n@[to_additive]\ntheorem partialProd_succ (f : Fin n \u2192 \u03b1) (j : Fin n) :\n    partialProd f j.succ = partialProd f (Fin.castSucc j) * f j := by\n  simp [partialProd, List.take_succ, List.ofFnNthVal, dif_pos j.is_lt, \u2190 Option.coe_def]\n#align fin.partial_prod_succ Fin.partialProd_succ\n#align fin.partial_sum_succ Fin.partialSum_succ\n\n@[to_additive]\ntheorem partialProd_succ' (f : Fin (n + 1) \u2192 \u03b1) (j : Fin (n + 1)) :\n    partialProd f j.succ = f 0 * partialProd (Fin.tail f) j := by\n  simp [partialProd]\n  rfl\n#align fin.partial_prod_succ' Fin.partialProd_succ'\n#align fin.partial_sum_succ' Fin.partialSum_succ'\n\n@[to_additive]\ntheorem partialProd_left_inv {G : Type _} [Group G] (f : Fin (n + 1) \u2192 G) :\n    (f 0 \u2022 partialProd fun i : Fin n => (f i)\u207b\u00b9 * f i.succ) = f :=\n  funext fun x => Fin.inductionOn x (by simp) fun x hx => by\n    simp only [coe_eq_castSucc, Pi.smul_apply, smul_eq_mul] at hx\u22a2\n    rw [partialProd_succ, \u2190 mul_assoc, hx, mul_inv_cancel_left]\n#align fin.partial_prod_left_inv Fin.partialProd_left_inv\n#align fin.partial_sum_left_neg Fin.partialSum_left_neg\n\n-- Porting note:\n-- 1) Changed `i` in statement to `(Fin.castLt i (Nat.lt_succ_of_lt i.2))` because of\n--    coercion issues. Might need to be fixed later.\n-- 2) The current proof is really bad! It should be redone once `assoc_rw` is\n--    implemented and `rw` knows that `i.succ = i + 1`.\n-- 3) The original Mathport output was:\n--   cases' i with i hn\n--   induction' i with i hi generalizing hn\n--   \u00b7 simp [\u2190 Fin.succ_mk, partialProd_succ]\n--   \u00b7 specialize hi (lt_trans (Nat.lt_succ_self i) hn)\n--     simp only [mul_inv_rev, Fin.coe_eq_castSucc, Fin.succ_mk, Fin.castSucc_mk, smul_eq_mul,\n--       Pi.smul_apply] at hi \u22a2\n--     rw [\u2190 Fin.succ_mk _ _ (lt_trans (Nat.lt_succ_self _) hn), \u2190 Fin.succ_mk]\n--     simp only [partialProd_succ, mul_inv_rev, Fin.castSucc_mk]\n--     assoc_rw [hi, inv_mul_cancel_left]\n@[to_additive]\ntheorem partialProd_right_inv {G : Type _} [Group G] (g : G) (f : Fin n \u2192 G) (i : Fin n) :\n    ((g \u2022 partialProd f) (Fin.castLt i (Nat.lt_succ_of_lt i.2)))\u207b\u00b9 *\n    (g \u2022 partialProd f) i.succ = f i := by\n  rcases i with \u27e8i, hn\u27e9\n  induction i with\n  | zero =>\n    simp\n    change partialProd f (succ \u27e80, hn\u27e9) = f \u27e80, hn\u27e9\n    rw [partialProd_succ]\n    simp\n  | succ i hi =>\n    specialize hi (lt_trans (Nat.lt_succ_self i) hn)\n    simp at hi \u22a2\n    change (partialProd f (succ \u27e8i, Nat.lt_of_succ_lt hn\u27e9))\u207b\u00b9 * g\u207b\u00b9 * (g *\n      partialProd f (succ \u27e8i + 1, hn\u27e9)) = f \u27e8Nat.succ i, hn\u27e9\n    rw [partialProd_succ, partialProd_succ, Fin.castSucc_mk, Fin.castSucc_mk, mul_inv_rev]\n    simp_rw [\u2190 mul_assoc] at hi \u22a2\n    suffices h : (f \u27e8i, Nat.lt_of_succ_lt hn\u27e9)\u207b\u00b9 *\n        ((partialProd f \u27e8i, Nat.lt_succ_of_lt (Nat.lt_of_succ_lt hn)\u27e9)\u207b\u00b9 * g\u207b\u00b9 *\n        (g * partialProd f \u27e8i + 1, Nat.succ_lt_succ (Nat.lt_of_succ_lt hn)\u27e9)) *\n        f \u27e8Nat.succ i, hn\u27e9 = f \u27e8Nat.succ i, hn\u27e9\n    \u00b7 simp_rw[\u2190mul_assoc] at h\n      assumption\n    \u00b7 rw [mul_left_eq_self, inv_mul_eq_one, \u2190hi, \u2190 mul_assoc]\n#align fin.partial_prod_right_inv Fin.partialProd_right_inv\n#align fin.partial_sum_right_neg Fin.partialSum_right_neg\n\nend PartialProd\n\nend Fin\n\nnamespace List\n\nsection CommMonoid\n\nvariable [CommMonoid \u03b1]\n\n@[to_additive]\ntheorem prod_take_ofFn {n : \u2115} (f : Fin n \u2192 \u03b1) (i : \u2115) :\n    ((ofFn f).take i).prod = \u220f j in Finset.univ.filter fun j : Fin n => j.val < i, f j := by\n  induction i with\n  | zero =>\n    simp\n  | succ i IH =>\n    by_cases h : i < n\n    \u00b7 have : i < length (ofFn f) := by rwa [length_ofFn f]\n      rw [prod_take_succ _ _ this]\n      have A : ((Finset.univ : Finset (Fin n)).filter fun j => j.val < i + 1) =\n          ((Finset.univ : Finset (Fin n)).filter fun j => j.val < i) \u222a {(\u27e8i, h\u27e9 : Fin n)} := by\n        ext \u27e8_, _\u27e9\n        simp [Nat.lt_succ_iff_lt_or_eq]\n      have B : _root_.Disjoint (Finset.filter (fun j : Fin n => j.val < i) Finset.univ)\n          (singleton (\u27e8i, h\u27e9 : Fin n)) := by simp\n      rw [A, Finset.prod_union B, IH]\n      simp\n    \u00b7 have A : (ofFn f).take i = (ofFn f).take i.succ := by\n        rw [\u2190 length_ofFn f] at h\n        have : length (ofFn f) \u2264 i := not_lt.mp h\n        rw [take_all_of_le this, take_all_of_le (le_trans this (Nat.le_succ _))]\n      have B : \u2200 j : Fin n, ((j : \u2115) < i.succ) = ((j : \u2115) < i) := by\n        intro j\n        have : (j : \u2115) < i := lt_of_lt_of_le j.2 (not_lt.mp h)\n        simp [this, lt_trans this (Nat.lt_succ_self _)]\n      simp [\u2190 A, B, IH]\n#align list.prod_take_of_fn List.prod_take_ofFn\n#align list.sum_take_of_fn List.sum_take_ofFn\n\n@[to_additive]\ntheorem prod_ofFn {n : \u2115} {f : Fin n \u2192 \u03b1} : (ofFn f).prod = \u220f i, f i := by\n  convert prod_take_ofFn f n\n  \u00b7 rw [take_all_of_le (le_of_eq (length_ofFn f))]\n  \u00b7 simp\n#align list.prod_of_fn List.prod_ofFn\n#align list.sum_of_fn List.sum_ofFn\n\nend CommMonoid\n\n-- Porting note: Statement had deprecated `L.nthLe i i.is_lt` instead of `L.get i`.\n@[to_additive]\ntheorem alternatingProd_eq_finset_prod {G : Type _} [CommGroup G] :\n    \u2200 (L : List G), alternatingProd L = \u220f i : Fin L.length, L.get i ^ (-1 : \u2124) ^ (i : \u2115)\n  | [] => by\n    rw [alternatingProd, Finset.prod_eq_one]\n    rintro \u27e8i, \u27e8\u27e9\u27e9\n  | g::[] => by\n    show g = \u220f i : Fin 1, [g].get i ^ (-1 : \u2124) ^ (i : \u2115)\n    rw [Fin.prod_univ_succ]; simp\n  | g::h::L =>\n    calc g * h\u207b\u00b9 * L.alternatingProd\n      = g * h\u207b\u00b9 * \u220f i : Fin L.length, L.get i ^ (-1 : \u2124) ^ (i : \u2115) :=\n        congr_arg _ (alternatingProd_eq_finset_prod _)\n    _ = \u220f i : Fin (L.length + 2), List.get (g::h::L) i ^ (-1 : \u2124) ^ (i : \u2115) := by\n        { rw [Fin.prod_univ_succ, Fin.prod_univ_succ, mul_assoc]\n          simp [Nat.succ_eq_add_one, pow_add]}\n#align list.alternating_prod_eq_finset_prod List.alternatingProd_eq_finset_prod\n#align list.alternating_sum_eq_finset_sum List.alternatingSum_eq_finset_sum\n\nend List\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/BigOperators/Fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.724823041548572}}
{"text": "/-\nCopyright (c) 2020 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n-/\n\nimport ..todo\nimport topology.subset_properties\nimport topology.separation\nimport topology.metric_space.basic\n\n/-!\nA formal roadmap for basic properties of paracompact spaces.\n\nIt contains the statements that compact spaces and metric spaces are paracompact,\nand that paracompact t2 spaces are normal, as well as partially formalised proofs.\n\nAny contributor should feel welcome to contribute complete proofs. When this happens,\nwe should also consider preserving the current file as an exemplar of a formal roadmap.\n-/\n\nopen set filter\n\nuniverse u\n\nnamespace roadmap\n\nclass paracompact_space (X : Type u) [topological_space X] : Prop :=\n(locally_finite_refinement :\n  \u2200 {\u03b1 : Type u} (u : \u03b1 \u2192 set X) (uo : \u2200 a, is_open (u a)) (uc : Union u = univ),\n  \u2203 {\u03b2 : Type u} (v : \u03b2 \u2192 set X) (vo : \u2200 b, is_open (v b)) (vc : Union v = univ),\n  locally_finite v \u2227 \u2200 b, \u2203 a, v b \u2286 u a)\n\n/-- Any open cover of a paracompact space has a locally finite *precise* refinement, that is,\n one indexed on the same type with each open set contained in the corresponding original one. -/\nlemma paracompact_space.precise_refinement {X : Type u} [topological_space X] [paracompact_space X]\n  {\u03b1 : Type u} (u : \u03b1 \u2192 set X) (uo : \u2200 a, is_open (u a)) (uc : Union u = univ) :\n  \u2203 v : \u03b1 \u2192 set X, (\u2200 a, is_open (v a)) \u2227 Union v = univ \u2227 locally_finite v \u2227 (\u2200 a, v a \u2286 u a) :=\nbegin\n  obtain \u27e8\u03b2, w, wo, wc, lfw, wr\u27e9 := paracompact_space.locally_finite_refinement u uo uc,\n  choose f hf using wr,\n  refine \u27e8\u03bb a, \u22c3\u2080 {s | \u2203 b, f b = a \u2227 s = w b}, \u03bb a, _, _, _, \u03bb a, _\u27e9,\n  { apply is_open_sUnion _,\n    rintros t \u27e8b, rfl, rfl\u27e9,\n    apply wo },\n  { todo },\n  { todo },\n  { apply sUnion_subset,\n    rintros t \u27e8b, rfl, rfl\u27e9,\n    apply hf }\nend\n\nlemma paracompact_of_compact {X : Type u} [topological_space X] [compact_space X] :\n  paracompact_space X :=\nbegin\n  refine \u27e8\u03bb \u03b1 u uo uc, _\u27e9,\n  obtain \u27e8s, _, sf, sc\u27e9 :=\n    compact_univ.elim_finite_subcover_image (\u03bb a _, uo a) (by rwa [univ_subset_iff, bUnion_univ]),\n  refine \u27e8s, \u03bb b, u b.val, \u03bb b, uo b.val, _, _, \u03bb b, \u27e8b.val, subset.refl _\u27e9\u27e9,\n  { todo },\n  { intro x,\n    refine \u27e8univ, univ_mem_sets, _\u27e9,\n    todo },\nend\n\nlemma normal_of_paracompact_t2 {X : Type u} [topological_space X] [t2_space X]\n  [paracompact_space X] : normal_space X :=\ntodo\n/-\nSimilar to the proof of `generalized_tube_lemma`, but different enough not to merge them.\nLemma: if `s : set X` is closed and can be separated from any point by open sets,\nthen `s` can also be separated from any closed set by open sets. Apply twice.\n\nSee\n* Bourbaki, General Topology, Chapter IX, \u00a74.4\n* https://ncatlab.org/nlab/show/paracompact+Hausdorff+spaces+are+normal\n-/\n\nlemma paracompact_of_metric {X : Type u} [metric_space X] : paracompact_space X :=\ntodo\n/-\nSee Mary Ellen Rudin, A new proof that metric spaces are paracompact.\nhttps://www.ams.org/journals/proc/1969-020-02/S0002-9939-1969-0236876-3/S0002-9939-1969-0236876-3.pdf\n-/\nend roadmap\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/roadmap/topology/paracompact.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.724823037042037}}
{"text": "/-\nCopyright (c) 2021 Patrick Stevens. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Stevens, Thomas Browning\n-/\n\nimport data.nat.choose.basic\nimport data.nat.choose.sum\n\n/-!\n# Central binomial coefficients\n\nThis file proves properties of the central binomial coefficients (that is, `nat.choose (2 * n) n`).\n\n## Main definition and results\n\n* `nat.central_binom`: the central binomial coefficient, `(2 * n).choose n`.\n* `nat.succ_mul_central_binom_succ`: the inductive relationship between successive central binomial\n  coefficients.\n* `nat.four_pow_lt_mul_central_binom`: an exponential lower bound on the central binomial\n  coefficient.\n* `succ_dvd_central_binom`: The result that `n+1 \u2223 n.central_binom`, ensuring that the explicit\n  definition of the Catalan numbers is integer-valued.\n-/\n\nnamespace nat\n\n/--\nThe central binomial coefficient, `nat.choose (2 * n) n`.\n-/\ndef central_binom (n : \u2115) := (2 * n).choose n\n\nlemma central_binom_eq_two_mul_choose (n : \u2115) : central_binom n = (2 * n).choose n := rfl\n\nlemma central_binom_pos (n : \u2115) : 0 < central_binom n :=\nchoose_pos (nat.le_mul_of_pos_left zero_lt_two)\n\nlemma central_binom_ne_zero (n : \u2115) : central_binom n \u2260 0 :=\n(central_binom_pos n).ne'\n\n@[simp] lemma central_binom_zero : central_binom 0 = 1 :=\nchoose_zero_right _\n\n/--\nThe central binomial coefficient is the largest binomial coefficient.\n-/\nlemma choose_le_central_binom (r n : \u2115) : choose (2 * n) r \u2264 central_binom n :=\ncalc (2 * n).choose r \u2264 (2 * n).choose (2 * n / 2) : choose_le_middle r (2 * n)\n... = (2 * n).choose n : by rw nat.mul_div_cancel_left n zero_lt_two\n\nlemma two_le_central_binom (n : \u2115) (n_pos : 0 < n) : 2 \u2264 central_binom n :=\ncalc 2 \u2264 2 * n : le_mul_of_pos_right n_pos\n... = (2 * n).choose 1 : (choose_one_right (2 * n)).symm\n... \u2264 central_binom n : choose_le_central_binom 1 n\n\n/--\nAn inductive property of the central binomial coefficient.\n-/\nlemma succ_mul_central_binom_succ (n : \u2115) :\n  (n + 1) * central_binom (n + 1) = 2 * (2 * n + 1) * central_binom n :=\ncalc (n + 1) * (2 * (n + 1)).choose (n + 1) = (2 * n + 2).choose (n + 1) * (n + 1) : mul_comm _ _\n... = (2 * n + 1).choose n * (2 * n + 2) : by rw [choose_succ_right_eq, choose_mul_succ_eq]\n... = 2 * ((2 * n + 1).choose n * (n + 1)) : by ring\n... = 2 * ((2 * n + 1).choose n * ((2 * n + 1) - n)) :\n  by rw [two_mul n, add_assoc, nat.add_sub_cancel_left]\n... = 2 * ((2 * n).choose n * (2 * n + 1)) : by rw choose_mul_succ_eq\n... = (2 * (2 * n + 1)) * (2 * n).choose n : by rw [mul_assoc, mul_comm (2 * n + 1)]\n\n/--\nAn exponential lower bound on the central binomial coefficient.\nThis bound is of interest because it appears in\n[Tochiori's refinement of Erd\u0151s's proof of Bertrand's postulate](tochiori_bertrand).\n-/\nlemma four_pow_lt_mul_central_binom (n : \u2115) (n_big : 4 \u2264 n) : 4 ^ n < n * central_binom n :=\nbegin\n  induction n using nat.strong_induction_on with n IH,\n  rcases lt_trichotomy n 4 with (hn|rfl|hn),\n  { clear IH, dec_trivial! },\n  { norm_num [central_binom, choose] },\n  obtain \u27e8n, rfl\u27e9 : \u2203 m, n = m + 1 := nat.exists_eq_succ_of_ne_zero (zero_lt_four.trans hn).ne',\n  calc 4 ^ (n + 1) < 4 * (n * central_binom n) :\n      (mul_lt_mul_left zero_lt_four).mpr (IH n n.lt_succ_self (nat.le_of_lt_succ hn))\n  ... \u2264 2 * (2 * n + 1) * central_binom n : by { rw \u2190 mul_assoc, linarith }\n  ... = (n + 1) * central_binom (n + 1) : (succ_mul_central_binom_succ n).symm,\nend\n\n/--\nAn exponential lower bound on the central binomial coefficient.\nThis bound is weaker than `four_pow_n_lt_n_mul_central_binom`, but it is of historical interest\nbecause it appears in Erd\u0151s's proof of Bertrand's postulate.\n-/\nlemma four_pow_le_two_mul_self_mul_central_binom : \u2200 (n : \u2115) (n_pos : 0 < n),\n  4 ^ n \u2264 (2 * n) * central_binom n\n| 0 pr := (nat.not_lt_zero _ pr).elim\n| 1 pr := by norm_num [central_binom, choose]\n| 2 pr := by norm_num [central_binom, choose]\n| 3 pr := by norm_num [central_binom, choose]\n| n@(m + 4) _ :=\ncalc 4 ^ n \u2264 n * central_binom n : (four_pow_lt_mul_central_binom _ le_add_self).le\n... \u2264 2 * n * central_binom n    : by { rw [mul_assoc], refine le_mul_of_pos_left zero_lt_two }\n\nlemma two_dvd_central_binom_succ (n : \u2115) : 2 \u2223 central_binom (n + 1) :=\nbegin\n  use (n+1+n).choose n,\n  rw [central_binom_eq_two_mul_choose, two_mul, \u2190 add_assoc, choose_succ_succ, choose_symm_add,\n      \u2190 two_mul],\nend\n\nlemma two_dvd_central_binom_of_one_le {n : \u2115} (h : 0 < n) : 2 \u2223 central_binom n :=\nbegin\n  rw \u2190 nat.succ_pred_eq_of_pos h,\n  exact two_dvd_central_binom_succ n.pred,\nend\n\n/-- A crucial lemma to ensure that Catalan numbers can be defined via their explicit formula\n  `catalan n = n.central_binom / (n + 1)`. -/\nlemma succ_dvd_central_binom (n : \u2115) : (n + 1) \u2223 n.central_binom :=\nbegin\n  have h_s : (n+1).coprime (2*n+1),\n  { rw [two_mul,add_assoc, coprime_add_self_right, coprime_self_add_left],\n    exact coprime_one_left n },\n  apply h_s.dvd_of_dvd_mul_left,\n  apply dvd_of_mul_dvd_mul_left zero_lt_two,\n  rw [\u2190 mul_assoc, \u2190 succ_mul_central_binom_succ, mul_comm],\n  exact mul_dvd_mul_left _ (two_dvd_central_binom_succ n),\nend\n\nend nat\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/nat/choose/central.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7248230258849709}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport data.equiv.encodable.basic\nimport order.atoms\n\n/-!\n# Order ideals, cofinal sets, and the Rasiowa\u2013Sikorski lemma\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections require more\nstructure, such as a bottom element, a top element, or a join-semilattice structure.\n- `order.ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.\n  Dual to the notion of a filter on a preorder.\n- `order.is_ideal P`: a predicate for when a `set P` is an ideal.\n- `order.ideal.principal p`: the principal ideal generated by `p : P`.\n- `order.ideal.is_proper P`: a predicate for proper ideals.\n  Dual to the notion of a proper filter.\n- `order.ideal.is_maximal`: a predicate for maximal ideals.\n  Dual to the notion of an ultrafilter.\n- `ideal_Inter_nonempty P`: a predicate for when the intersection of all ideals of\n  `P` is nonempty.\n- `order.cofinal P`: the type of subsets of `P` containing arbitrarily large elements.\n  Dual to the notion of 'dense set' used in forcing.\n- `order.ideal_of_cofinals p \ud835\udc9f`, where `p : P`, and `\ud835\udc9f` is a countable family of cofinal\n  subsets of P: an ideal in `P` which contains `p` and intersects every set in `\ud835\udc9f`. (This a form\n  of the Rasiowa\u2013Sikorski lemma.)\n\n## References\n\n- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>\n- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>\n- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>\n\nNote that for the Rasiowa\u2013Sikorski lemma, Wikipedia uses the opposite ordering on `P`,\nin line with most presentations of forcing.\n\n## TODO\n\n`order.ideal.ideal_Inter_nonempty` is a complicated way to say that `P` has a bottom element. It\nshould be replaced by this clearer condition, which could be called strong directedness and which\nis a Prop version of `order_bot`.\n\n## Tags\n\nideal, cofinal, dense, countable, generic\n\n-/\n\nopen function\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- An ideal on an order `P` is a subset of `P` that is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\nstructure ideal (P) [has_le P] :=\n(carrier   : set P)\n(nonempty  : carrier.nonempty)\n(directed  : directed_on (\u2264) carrier)\n(mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 y \u2208 carrier \u2192 x \u2208 carrier)\n\n/-- A subset of a preorder `P` is an ideal if it is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\n@[mk_iff] structure is_ideal {P} [has_le P] (I : set P) : Prop :=\n(nonempty : I.nonempty)\n(directed : directed_on (\u2264) I)\n(mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 y \u2208 I \u2192 x \u2208 I)\n\nattribute [protected] ideal.nonempty ideal.directed is_ideal.nonempty is_ideal.directed\n\n/-- Create an element of type `order.ideal` from a set satisfying the predicate\n`order.is_ideal`. -/\ndef is_ideal.to_ideal [has_le P] {I : set P} (h : is_ideal I) : ideal P :=\n\u27e8I, h.1, h.2, h.3\u27e9\n\nnamespace ideal\nsection has_le\nvariables [has_le P] {I J : ideal P} {x y : P}\n\n/-- An ideal of `P` can be viewed as a subset of `P`. -/\ninstance : has_coe (ideal P) (set P) := \u27e8carrier\u27e9\n\n/-- For the notation `x \u2208 I`. -/\ninstance : has_mem P (ideal P) := \u27e8\u03bb x I, x \u2208 (I : set P)\u27e9\n\n@[simp] lemma mem_coe : x \u2208 (I : set P) \u2194 x \u2208 I := iff_of_eq rfl\n\n/-- Two ideals are equal when their underlying sets are equal. -/\n@[ext] lemma ext : \u2200 {I J : ideal P}, (I : set P) = J \u2192 I = J\n| \u27e8_, _, _, _\u27e9 \u27e8_, _, _, _\u27e9 rfl := rfl\n\nlemma coe_injective : injective (coe : ideal P \u2192 set P) := \u03bb _ _, ext\n\n@[simp, norm_cast] lemma coe_inj : (I : set P) = J \u2194 I = J := \u27e8by ext, congr_arg _\u27e9\n\nlemma ext_iff : I = J \u2194 (I : set P) = J := coe_inj.symm\n\nprotected lemma is_ideal (I : ideal P) : is_ideal (I : set P) := \u27e8I.2, I.3, I.4\u27e9\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (ideal P) := partial_order.lift coe coe_injective\n\n@[trans] lemma mem_of_mem_of_le : x \u2208 I \u2192 I \u2264 J \u2192 x \u2208 J :=\n@set.mem_of_mem_of_subset P x I J\n\n/-- A proper ideal is one that is not the whole set.\n    Note that the whole set might not be an ideal. -/\n@[mk_iff] class is_proper (I : ideal P) : Prop := (ne_univ : (I : set P) \u2260 set.univ)\n\nlemma is_proper_of_not_mem {I : ideal P} {p : P} (nmem : p \u2209 I) : is_proper I :=\n\u27e8\u03bb hp, begin\n  change p \u2209 \u2191I at nmem,\n  rw hp at nmem,\n  exact nmem (set.mem_univ p),\nend\u27e9\n\n/-- An ideal is maximal if it is maximal in the collection of proper ideals.\n\nNote that `is_coatom` is less general because ideals only have a top element when `P` is directed\nand nonempty. -/\n@[mk_iff] class is_maximal (I : ideal P) extends is_proper I : Prop :=\n(maximal_proper : \u2200 \u2983J : ideal P\u2984, I < J \u2192 (J : set P) = set.univ)\n\nvariable (P)\n\n/-- An order `P` has the `ideal_Inter_nonempty` property if the intersection of all ideals is\nnonempty. Most importantly, the ideals of a `semilattice_sup` with this property form a complete\nlattice.\n\nTODO: This is equivalent to the existence of a bottom element and shouldn't be specialized to\nideals. -/\nclass ideal_Inter_nonempty : Prop :=\n(Inter_nonempty : (\u22c2 (I : ideal P), (I : set P)).nonempty)\n\nvariable {P}\n\nlemma Inter_nonempty [ideal_Inter_nonempty P] :\n  (\u22c2 (I : ideal P), (I : set P)).nonempty :=\nideal_Inter_nonempty.Inter_nonempty\n\nlemma ideal_Inter_nonempty.exists_all_mem [ideal_Inter_nonempty P] :\n  \u2203 a : P, \u2200 I : ideal P, a \u2208 I :=\nbegin\n  change \u2203 (a : P), \u2200 (I : ideal P), a \u2208 (I : set P),\n  rw \u2190 set.nonempty_Inter,\n  exact Inter_nonempty,\nend\n\nlemma ideal_Inter_nonempty_of_exists_all_mem (h : \u2203 a : P, \u2200 I : ideal P, a \u2208 I) :\n  ideal_Inter_nonempty P :=\n{ Inter_nonempty := by rwa set.nonempty_Inter }\n\nlemma ideal_Inter_nonempty_iff :\n  ideal_Inter_nonempty P \u2194 \u2203 a : P, \u2200 I : ideal P, a \u2208 I :=\n\u27e8\u03bb _, by exactI ideal_Inter_nonempty.exists_all_mem, ideal_Inter_nonempty_of_exists_all_mem\u27e9\n\nlemma inter_nonempty [is_directed P (swap (\u2264))] (I J : ideal P) : (I \u2229 J : set P).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 := I.nonempty,\n  obtain \u27e8b, hb\u27e9 := J.nonempty,\n  obtain \u27e8c, hac, hbc\u27e9 := directed_of (swap (\u2264)) a b,\n  exact \u27e8c, I.mem_of_le hac ha, J.mem_of_le hbc hb\u27e9,\nend\n\nend has_le\n\nsection preorder\nvariables [preorder P] {I J : ideal P} {x y : P}\n\n/-- The smallest ideal containing a given element. -/\ndef principal (p : P) : ideal P :=\n{ carrier   := { x | x \u2264 p },\n  nonempty  := \u27e8p, le_rfl\u27e9,\n  directed  := \u03bb x hx y hy, \u27e8p, le_rfl, hx, hy\u27e9,\n  mem_of_le := \u03bb x y hxy hy, le_trans hxy hy, }\n\ninstance [inhabited P] : inhabited (ideal P) := \u27e8ideal.principal default\u27e9\n\n@[simp] lemma principal_le_iff : principal x \u2264 I \u2194 x \u2208 I :=\n\u27e8\u03bb (h : \u2200 {y}, y \u2264 x \u2192 y \u2208 I), h (le_refl x),\n \u03bb h_mem y (h_le : y \u2264 x), I.mem_of_le h_le h_mem\u27e9\n\n@[simp] lemma mem_principal : x \u2208 principal y \u2194 x \u2264 y := iff.rfl\n\nlemma mem_compl_of_ge {x y : P} : x \u2264 y \u2192 x \u2208 (I : set P)\u1d9c \u2192 y \u2208 (I : set P)\u1d9c :=\n\u03bb h, mt (I.mem_of_le h)\n\nend preorder\n\nsection order_bot\n\n/-- A specific witness of `I.nonempty` when `P` has a bottom element. -/\n@[simp] lemma bot_mem [has_le P] [order_bot P] {I : ideal P} : \u22a5 \u2208 I :=\nI.mem_of_le bot_le I.nonempty.some_mem\n\nvariables [preorder P] [order_bot P] {I : ideal P}\n\n/-- There is a bottom ideal when `P` has a bottom element. -/\ninstance : order_bot (ideal P) :=\n{ bot := principal \u22a5,\n  bot_le := by simp }\n\n@[priority 100]\ninstance order_bot.ideal_Inter_nonempty : ideal_Inter_nonempty P :=\nby { rw ideal_Inter_nonempty_iff, exact \u27e8\u22a5, \u03bb I, bot_mem\u27e9 }\n\nend order_bot\n\nsection directed\nvariables [has_le P] [is_directed P (\u2264)] [nonempty P] {I : ideal P}\n\n/-- In a directed and nonempty order, the top ideal of a is `set.univ`. -/\ninstance : order_top (ideal P) :=\n{ top := { carrier := set.univ,\n           nonempty := set.univ_nonempty,\n           directed := directed_on_univ,\n           mem_of_le := \u03bb _ _ _ _, trivial },\n  le_top := \u03bb I, le_top }\n\n@[simp] lemma coe_top : ((\u22a4 : ideal P) : set P) = set.univ := rfl\n\nlemma is_proper_of_ne_top (ne_top : I \u2260 \u22a4) : is_proper I := \u27e8\u03bb h, ne_top $ ext h\u27e9\n\nlemma is_proper.ne_top (hI : is_proper I) : I \u2260 \u22a4 :=\nbegin\n  intro h,\n  rw [ext_iff, coe_top] at h,\n  apply hI.ne_univ,\n  assumption,\nend\n\nlemma _root_.is_coatom.is_proper (hI : is_coatom I) : is_proper I := is_proper_of_ne_top hI.1\n\nlemma is_proper_iff_ne_top : is_proper I \u2194 I \u2260 \u22a4 := \u27e8\u03bb h, h.ne_top, \u03bb h, is_proper_of_ne_top h\u27e9\n\nlemma is_maximal.is_coatom (h : is_maximal I) : is_coatom I :=\n\u27e8is_maximal.to_is_proper.ne_top,\n  \u03bb _ _, by { rw [ext_iff, coe_top], exact is_maximal.maximal_proper \u2039_\u203a }\u27e9\n\nlemma is_maximal.is_coatom' [is_maximal I] : is_coatom I := is_maximal.is_coatom \u2039_\u203a\n\nlemma _root_.is_coatom.is_maximal (hI : is_coatom I) : is_maximal I :=\n{ maximal_proper := \u03bb _ _, by simp [hI.2 _ \u2039_\u203a],\n  ..is_coatom.is_proper \u2039_\u203a }\n\nlemma is_maximal_iff_is_coatom : is_maximal I \u2194 is_coatom I := \u27e8\u03bb h, h.is_coatom, \u03bb h, h.is_maximal\u27e9\n\nend directed\n\nsection order_top\nvariables [has_le P] [order_top P] {I : ideal P}\n\nlemma top_of_top_mem (hI : \u22a4 \u2208 I) : I = \u22a4 :=\nby { ext, exact iff_of_true (I.mem_of_le le_top hI) trivial }\n\nlemma is_proper.top_not_mem (hI : is_proper I) : \u22a4 \u2209 I := \u03bb h, hI.ne_top $ top_of_top_mem h\n\nend order_top\n\nsection semilattice_sup\nvariables [semilattice_sup P] {x y : P} {I : ideal P}\n\n/-- A specific witness of `I.directed` when `P` has joins. -/\nlemma sup_mem (x y \u2208 I) : x \u2294 y \u2208 I :=\nlet \u27e8z, h_mem, hx, hy\u27e9 := I.directed x \u2039_\u203a y \u2039_\u203a in\nI.mem_of_le (sup_le hx hy) h_mem\n\n@[simp] lemma sup_mem_iff : x \u2294 y \u2208 I \u2194 x \u2208 I \u2227 y \u2208 I :=\n\u27e8\u03bb h, \u27e8I.mem_of_le le_sup_left h, I.mem_of_le le_sup_right h\u27e9,\n \u03bb h, sup_mem x h.left y h.right\u27e9\n\nend semilattice_sup\n\nsection semilattice_sup_directed\nvariables [semilattice_sup P] [is_directed P (swap (\u2264))] {x : P} {I J K : ideal P}\n\n/-- The infimum of two ideals of a co-directed order is their intersection. -/\ninstance : has_inf (ideal P) :=\n\u27e8\u03bb I J, { carrier   := I \u2229 J,\n  nonempty  := inter_nonempty I J,\n  directed  := \u03bb x \u27e8_, _\u27e9 y \u27e8_, _\u27e9, \u27e8x \u2294 y, \u27e8sup_mem x \u2039_\u203a y \u2039_\u203a, sup_mem x \u2039_\u203a y \u2039_\u203a\u27e9, by simp\u27e9,\n  mem_of_le := \u03bb x y h \u27e8_, _\u27e9, \u27e8mem_of_le I h \u2039_\u203a, mem_of_le J h \u2039_\u203a\u27e9 }\u27e9\n\n/-- The supremum of two ideals of a co-directed order is the union of the down sets of the pointwise\nsupremum of `I` and `J`. -/\ninstance : has_sup (ideal P) :=\n\u27e8\u03bb I J, { carrier   := {x | \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j},\n  nonempty  := by { cases inter_nonempty I J, exact \u27e8w, w, h.1, w, h.2, le_sup_left\u27e9 },\n  directed  := \u03bb x \u27e8xi, _, xj, _, _\u27e9 y \u27e8yi, _, yj, _, _\u27e9,\n    \u27e8x \u2294 y,\n     \u27e8xi \u2294 yi, sup_mem xi \u2039_\u203a yi \u2039_\u203a,\n      xj \u2294 yj, sup_mem xj \u2039_\u203a yj \u2039_\u203a,\n      sup_le\n        (calc x \u2264 xi \u2294 xj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_left le_sup_left)\n        (calc y \u2264 yi \u2294 yj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_right le_sup_right)\u27e9,\n     le_sup_left, le_sup_right\u27e9,\n  mem_of_le := \u03bb x y _ \u27e8yi, _, yj, _, _\u27e9, \u27e8yi, \u2039_\u203a, yj, \u2039_\u203a, le_trans \u2039x \u2264 y\u203a \u2039_\u203a\u27e9 }\u27e9\n\ninstance : lattice (ideal P) :=\n{ sup          := (\u2294),\n  le_sup_left  := \u03bb I J (i \u2208 I), by { cases J.nonempty, exact \u27e8i, \u2039_\u203a, w, \u2039_\u203a, le_sup_left\u27e9 },\n  le_sup_right := \u03bb I J (j \u2208 J), by { cases I.nonempty, exact \u27e8w, \u2039_\u203a, j, \u2039_\u203a, le_sup_right\u27e9 },\n  sup_le       := \u03bb I J K hIK hJK a \u27e8i, hi, j, hj, ha\u27e9,\n    K.mem_of_le ha $ sup_mem i (mem_of_mem_of_le hi hIK) j (mem_of_mem_of_le hj hJK),\n  inf          := (\u2293),\n  inf_le_left  := \u03bb I J, set.inter_subset_left I J,\n  inf_le_right := \u03bb I J, set.inter_subset_right I J,\n  le_inf       := \u03bb I J K, set.subset_inter,\n  .. ideal.partial_order }\n\n@[simp] lemma mem_inf : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J := iff.rfl\n@[simp] lemma mem_sup : x \u2208 I \u2294 J \u2194 \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j := iff.rfl\n\nlemma lt_sup_principal_of_not_mem (hx : x \u2209 I) : I < I \u2294 principal x :=\nle_sup_left.lt_of_ne $ \u03bb h, hx $ by simpa only [left_eq_sup, principal_le_iff] using h\n\nend semilattice_sup_directed\n\nsection ideal_Inter_nonempty\n\nvariables [preorder P] [ideal_Inter_nonempty P]\n\n@[priority 100]\ninstance ideal_Inter_nonempty.to_directed_ge : is_directed P (swap (\u2264)) :=\n\u27e8\u03bb a b, begin\n    obtain \u27e8c, hc\u27e9 : \u2203 a, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n    exact \u27e8c, hc (principal a), hc (principal b)\u27e9,\n  end\u27e9\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*} {\u03b9 : Sort*}\n\nlemma ideal_Inter_nonempty.all_Inter_nonempty {f : \u03b9 \u2192 ideal P} :\n  (\u22c2 x, (f x : set P)).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 : \u2203 a : P, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n  exact \u27e8a, by simp [ha]\u27e9\nend\n\nlemma ideal_Inter_nonempty.all_bInter_nonempty {f : \u03b1 \u2192 ideal P} {s : set \u03b1} :\n  (\u22c2 x \u2208 s, (f x : set P)).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 : \u2203 a : P, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n  exact \u27e8a, by simp [ha]\u27e9\nend\n\nend ideal_Inter_nonempty\n\nsection semilattice_sup_ideal_Inter_nonempty\n\nvariables [semilattice_sup P] [ideal_Inter_nonempty P] {x : P} {I J K : ideal P}\n\ninstance : has_Inf (ideal P) :=\n{ Inf := \u03bb s, { carrier := \u22c2 (I \u2208 s), (I : set P),\n  nonempty := ideal_Inter_nonempty.all_bInter_nonempty,\n  directed := \u03bb x hx y hy, \u27e8x \u2294 y, \u27e8\u03bb S \u27e8I, hS\u27e9,\n    begin\n      simp only [\u2190hS, sup_mem_iff, mem_coe, set.mem_Inter],\n      intro hI,\n      rw set.mem_Inter\u2082 at *,\n      exact \u27e8hx _ hI, hy _ hI\u27e9\n    end,\n    le_sup_left, le_sup_right\u27e9\u27e9,\n  mem_of_le := \u03bb x y hxy hy,\n    begin\n      rw set.mem_Inter\u2082 at *,\n      exact \u03bb I hI, mem_of_le I \u2039_\u203a (hy I hI)\n    end } }\n\nvariables {s : set (ideal P)}\n\n@[simp] lemma mem_Inf : x \u2208 Inf s \u2194 \u2200 I \u2208 s, x \u2208 I :=\nby { change x \u2208 (\u22c2 (I \u2208 s), (I : set P)) \u2194 \u2200 I \u2208 s, x \u2208 I, simp }\n\n@[simp] lemma coe_Inf : \u2191(Inf s) = \u22c2 (I \u2208 s), (I : set P) := rfl\n\nlemma Inf_le (hI : I \u2208 s) : Inf s \u2264 I :=\n\u03bb _ hx, hx I \u27e8I, by simp [hI]\u27e9\n\nlemma le_Inf (h : \u2200 J \u2208 s, I \u2264 J) : I \u2264 Inf s :=\n\u03bb _ _, by { simp only [mem_coe, coe_Inf, set.mem_Inter], tauto }\n\nlemma is_glb_Inf : is_glb s (Inf s) := \u27e8\u03bb _, Inf_le, \u03bb _, le_Inf\u27e9\n\ninstance : complete_lattice (ideal P) :=\n{ ..ideal.lattice,\n  ..complete_lattice_of_Inf (ideal P) (\u03bb _, @is_glb_Inf _ _ _ _) }\n\nend semilattice_sup_ideal_Inter_nonempty\n\nsection distrib_lattice\n\nvariables [distrib_lattice P]\nvariables {I J : ideal P}\n\nlemma eq_sup_of_le_sup {x i j: P} (hi : i \u2208 I) (hj : j \u2208 J) (hx : x \u2264 i \u2294 j) :\n  \u2203 (i' \u2208 I) (j' \u2208 J), x = i' \u2294 j' :=\nbegin\n  refine \u27e8x \u2293 i, I.mem_of_le inf_le_right hi, x \u2293 j, J.mem_of_le inf_le_right hj, _\u27e9,\n  calc\n  x    = x \u2293 (i \u2294 j)       : left_eq_inf.mpr hx\n  ...  = (x \u2293 i) \u2294 (x \u2293 j) : inf_sup_left,\nend\n\nlemma coe_sup_eq : \u2191(I \u2294 J) = {x | \u2203 i \u2208 I, \u2203 j \u2208 J, x = i \u2294 j} :=\nbegin\n  ext,\n  rw [mem_coe, mem_sup],\n  exact \u27e8\u03bb \u27e8_, _, _, _, _\u27e9, eq_sup_of_le_sup \u2039_\u203a \u2039_\u203a \u2039_\u203a,\n  \u03bb \u27e8i, _, j, _, _\u27e9, \u27e8i, \u2039_\u203a, j, \u2039_\u203a, le_of_eq \u2039_\u203a\u27e9\u27e9\nend\n\nend distrib_lattice\n\nsection boolean_algebra\n\nvariables [boolean_algebra P] {x : P} {I : ideal P}\n\nlemma is_proper.not_mem_of_compl_mem (hI : is_proper I) (hxc : x\u1d9c \u2208 I) : x \u2209 I :=\nbegin\n  intro hx,\n  apply hI.top_not_mem,\n  have ht : x \u2294 x\u1d9c \u2208 I := sup_mem _ \u2039_\u203a _ \u2039_\u203a,\n  rwa sup_compl_eq_top at ht,\nend\n\nlemma is_proper.not_mem_or_compl_not_mem (hI : is_proper I) : x \u2209 I \u2228 x\u1d9c \u2209 I :=\nhave h : x\u1d9c \u2208 I \u2192 x \u2209 I := hI.not_mem_of_compl_mem, by tauto\n\nend boolean_algebra\n\nend ideal\n\n/-- For a preorder `P`, `cofinal P` is the type of subsets of `P`\n  containing arbitrarily large elements. They are the dense sets in\n  the topology whose open sets are terminal segments. -/\nstructure cofinal (P) [preorder P] :=\n(carrier : set P)\n(mem_gt  : \u2200 x : P, \u2203 y \u2208 carrier, x \u2264 y)\n\nnamespace cofinal\n\nvariables [preorder P]\n\ninstance : inhabited (cofinal P) :=\n\u27e8{ carrier := set.univ, mem_gt := \u03bb x, \u27e8x, trivial, le_rfl\u27e9 }\u27e9\n\ninstance : has_mem P (cofinal P) := \u27e8\u03bb x D, x \u2208 D.carrier\u27e9\n\nvariables (D : cofinal P) (x : P)\n/-- A (noncomputable) element of a cofinal set lying above a given element. -/\nnoncomputable def above : P := classical.some $ D.mem_gt x\n\nlemma above_mem : D.above x \u2208 D :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb a _, a\n\nlemma le_above : x \u2264 D.above x :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb _ b, b\n\nend cofinal\n\nsection ideal_of_cofinals\n\nvariables [preorder P] (p : P) {\u03b9 : Type*} [encodable \u03b9] (\ud835\udc9f : \u03b9 \u2192 cofinal P)\n\n/-- Given a starting point, and a countable family of cofinal sets,\n  this is an increasing sequence that intersects each cofinal set. -/\nnoncomputable def sequence_of_cofinals : \u2115 \u2192 P\n| 0 := p\n| (n+1) := match encodable.decode \u03b9 n with\n           | none   := sequence_of_cofinals n\n           | some i := (\ud835\udc9f i).above (sequence_of_cofinals n)\n           end\n\nlemma sequence_of_cofinals.monotone : monotone (sequence_of_cofinals p \ud835\udc9f) :=\nby { apply monotone_nat_of_le_succ, intros n, dunfold sequence_of_cofinals,\n  cases encodable.decode \u03b9 n, { refl }, { apply cofinal.le_above }, }\n\nlemma sequence_of_cofinals.encode_mem (i : \u03b9) :\n  sequence_of_cofinals p \ud835\udc9f (encodable.encode i + 1) \u2208 \ud835\udc9f i :=\nby { dunfold sequence_of_cofinals, rw encodable.encodek, apply cofinal.above_mem, }\n\n/-- Given an element `p : P` and a family `\ud835\udc9f` of cofinal subsets of a preorder `P`,\n  indexed by a countable type, `ideal_of_cofinals p \ud835\udc9f` is an ideal in `P` which\n  - contains `p`, according to `mem_ideal_of_cofinals p \ud835\udc9f`, and\n  - intersects every set in `\ud835\udc9f`, according to `cofinal_meets_ideal_of_cofinals p \ud835\udc9f`.\n\n  This proves the Rasiowa\u2013Sikorski lemma. -/\ndef ideal_of_cofinals : ideal P :=\n{ carrier   := { x : P | \u2203 n, x \u2264 sequence_of_cofinals p \ud835\udc9f n },\n  nonempty  := \u27e8p, 0, le_rfl\u27e9,\n  directed  := \u03bb x \u27e8n, hn\u27e9 y \u27e8m, hm\u27e9,\n               \u27e8_, \u27e8max n m, le_rfl\u27e9,\n               le_trans hn $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_left _ _),\n               le_trans hm $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_right _ _) \u27e9,\n  mem_of_le := \u03bb x y hxy \u27e8n, hn\u27e9, \u27e8n, le_trans hxy hn\u27e9, }\n\nlemma mem_ideal_of_cofinals : p \u2208 ideal_of_cofinals p \ud835\udc9f := \u27e80, le_rfl\u27e9\n\n/-- `ideal_of_cofinals p \ud835\udc9f` is `\ud835\udc9f`-generic. -/\nlemma cofinal_meets_ideal_of_cofinals (i : \u03b9) : \u2203 x : P, x \u2208 \ud835\udc9f i \u2227 x \u2208 ideal_of_cofinals p \ud835\udc9f :=\n\u27e8_, sequence_of_cofinals.encode_mem p \ud835\udc9f i, _, le_rfl\u27e9\n\nend ideal_of_cofinals\n\nend order\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.7248179310851139}}
{"text": "\nsection Logic\n\ntheorem andSymm : p \u2227 q \u2192 q \u2227 p := \u03bb (And.intro x y) => And.intro y x\n\ntheorem andComm : p \u2227 q \u2194 q \u2227 p := Iff.intro andSymm andSymm\n\ntheorem orSymm : p \u2228 q \u2192 q \u2228 p\n| Or.inl x => Or.inr x\n| Or.inr x => Or.inl x\n\ntheorem orComm : p \u2228 q \u2194 q \u2228 p := Iff.intro orSymm orSymm\n\nend Logic\n\ndef Set (\u03b1 : Type u) : Type u := \u03b1 \u2192 Prop\n\n@[reducible]\ndef Set.mk (p : \u03b1 \u2192 Prop) : Set \u03b1 := p\n\nclass HasMem (\u03b1 : outParam $ Type u) (\u03b2 : Type v) where\n    mem : \u03b1 \u2192 \u03b2 \u2192 Prop\n\ninfix:50 \" \u2208 \" => HasMem.mem\n\ninstance : HasMem \u03b1 (Set \u03b1) where\n    mem x s := s x\n\nsyntax \"{ \" ident (\" : \" term)? \" | \" term \" }\" : term\n\nmacro_rules\n  | `({ $x : $type | $p }) => `(Set.mk (\u03bb ($x:ident : $type) => $p))\n  | `({ $x | $p })         => `(Set.mk (\u03bb ($x:ident : _) => $p))\n\nabbrev setOf (b : \u03b2) [HasMem \u03b1 \u03b2] : Set \u03b1 := {x | x \u2208 b}\n\n\nnamespace Set\n\ntheorem ext {s t : Set \u03b1} (h : (x : \u03b1) \u2192 x \u2208 s \u2194 x \u2208 t) : s = t := by\n    funext x\n    exact propext (h x)\n\ndef univ {\u03b1 : Type u} : Set \u03b1 := \u03bb _ => True\n\ndef subset (s t : Set \u03b1) : Prop := \u2200 {x}, x \u2208 s \u2192 x \u2208 t\ndef inter (s t : Set \u03b1) : Set \u03b1 := {x | x \u2208 s \u2227 x \u2208 t}\ndef union (s t : Set \u03b1) : Set \u03b1 := {x | x \u2208 s \u2228 x \u2208 t}\n\ninfixl:70 \" \u2229 \" => inter\ninfixl:65 \" \u222a \" => union\ninfix:50 \" \u2286 \" => subset\n\n@[simp] theorem memUniv (a : \u03b1) : a \u2208 univ := trivial\n\n@[simp] theorem memInter (x : \u03b1) (s t : Set \u03b1) : x \u2208 s \u2229 t \u2194 x \u2208 s \u2227 x \u2208 t := Iff.rfl\n@[simp] theorem memUnion (x : \u03b1) (s t : Set \u03b1) : x \u2208 s \u222a t \u2194 x \u2208 s \u2228 x \u2208 t := Iff.rfl\n\ntheorem interComm (s t : Set \u03b1) : s \u2229 t = t \u2229 s := by\n    apply ext\n    simp\n    intro\n    rw andComm\n    exact Iff.rfl\n\ntheorem unionComm (s t : Set \u03b1) : s \u222a t = t \u222a s := by\n    apply ext\n    simp\n    intro\n    rw orComm\n    exact Iff.rfl\n\nend Set", "meta": {"author": "kbuzzard", "repo": "lean4-filters", "sha": "29f90055b7a2341c86d924954463c439bd128fb7", "save_path": "github-repos/lean/kbuzzard-lean4-filters", "path": "github-repos/lean/kbuzzard-lean4-filters/lean4-filters-29f90055b7a2341c86d924954463c439bd128fb7/other_peoples_work/miller_logic_and_set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7248179063294042}}
{"text": "/-\n\u00a9 2021 by the Rector and Visitors of the University of Virginia\n-/\n\nimport .lin2kcoord\n\n/-\nWe illustrate the use of, and test, lin2kcoord.lean. \n-/\n\n-- 2D coordinate vectors over a field, K = \u211a \ndef v1 := ((1, 1) : \u211a \u00d7 \u211a)\ndef v2 := ((-1,1) : \u211a \u00d7 \u211a)\n\n-- element addition, abstract now\ndef v3 := v1 + v2\n\nexample : v3 = (0,2) := \nbegin\nunfold v1 v2 v3,\nsimp,\ntrivial,\nend\n\n-- scaling (smul)\ndef v4 := 5 \u2022 v3\nexample : v4 = (0,10) := \nbegin\n  unfold v4 v3 v2 v1,\n  simp,\n  trivial,\nend\n", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/old/lin2Kcoord/lin2kcoord_test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533163686647, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.7247958381756997}}
{"text": "-- SETSIMP\n\nimport syntax\n\n@[simp]\nlemma union_singleton_is_insert {X : finset formula} {\u03d5: formula} :\n  X \u222a {\u03d5} = insert \u03d5 X :=\nbegin\n  have fo := finset.insert_eq \u03d5 X,\n  finish,\nend\n\n@[simp]\nlemma sdiff_singleton_is_erase {X : finset formula} {\u03d5: formula} :\n  X \\ {\u03d5} = X.erase \u03d5 :=\nbegin\n  apply finset.induction_on X,\n  simp,\n  intros g Y gNotInY IH,\n  ext1,\n  finish,\nend\n\n@[simp]\nlemma lengthAdd {X : finset formula} :\n  \u2200 {\u03d5} (h : \u03d5 \u2209 X), lengthOfSet (insert \u03d5 X) = lengthOfSet X + lengthOfFormula \u03d5 :=\nbegin\n  apply finset.induction_on X,\n  {\n    unfold lengthOfSet,\n    simp,\n  },\n  {\n    intros \u03c8 Y psiNotInY IH,\n    unfold lengthOfSet at *,\n    intros \u03d5 h,\n    finish,\n  },\nend\n\n@[simp]\nlemma lengthOf_insert_leq_plus {X: finset formula} {\u03d5 : formula} :\n  lengthOfSet (insert \u03d5 X) \u2264 lengthOfSet X + lengthOfFormula \u03d5 :=\nbegin\ncases (em (\u03d5 \u2208 X)) with in_x not_in_x,\n{ rw finset.insert_eq_of_mem in_x, simp, },\n{ rw lengthAdd not_in_x, },\nend\n\n@[simp]\nlemma lengthRemove (X : finset formula) :\n  \u2200 \u03d5 \u2208 X, lengthOfSet (X.erase \u03d5) + lengthOfFormula \u03d5 = lengthOfSet X :=\nbegin\n  intros \u03d5 in_X,\n  have claim : lengthOfSet (insert \u03d5 (X \\ {\u03d5})) = lengthOfSet (X \\ {\u03d5}) + lengthOfFormula \u03d5,\n  {\n    apply lengthAdd,\n    simp,\n  },\n  have anotherClaim : insert \u03d5 (X \\ {\u03d5}) = X, {\n    ext1,\n    simp only [finset.mem_sdiff, finset.mem_insert, finset.mem_singleton],\n    split,\n    finish,\n    tauto,\n  },\n  rw anotherClaim at claim,\n  finish,\nend\n\n\n@[simp]\nlemma sum_union_le { T } [decidable_eq T] : \u2200 { X Y : finset T } { F : T \u2192 \u2115 }, (X \u222a Y).sum F \u2264 X.sum F + Y.sum F :=\nbegin\n  intros X Y F,\n  { calc (X \u222a Y).sum F\n       \u2264 (X \u222a Y).sum F + (X \u2229 Y).sum F : by { simp, }\n   ... = X.sum F + Y.sum F : finset.sum_union_inter,\n  },\nend\n", "meta": {"author": "m4lvin", "repo": "tablean", "sha": "836202612fc2bfacb5545696412e7d27f7704141", "save_path": "github-repos/lean/m4lvin-tablean", "path": "github-repos/lean/m4lvin-tablean/tablean-836202612fc2bfacb5545696412e7d27f7704141/src/setsimp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7247289754059791}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\nPorted by: Anatole Dedecker\n\n! This file was ported from Lean 3 source module order.chain\n! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Pairwise.Basic\nimport Mathlib.Data.Set.Lattice\nimport Mathlib.Data.SetLike.Basic\n\n/-!\n# Chains and flags\n\nThis file defines chains for an arbitrary relation and flags for an order and proves Hausdorff's\nMaximality Principle.\n\n## Main declarations\n\n* `IsChain s`: A chain `s` is a set of comparable elements.\n* `maxChain_spec`: Hausdorff's Maximality Principle.\n* `Flag`: The type of flags, aka maximal chains, of an order.\n\n## Notes\n\nOriginally ported from Isabelle/HOL. The\n[original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D.\nFleuriot, Tobias Nipkow, Christian Sternagel.\n-/\n\n\nopen Classical Set\n\nvariable {\u03b1 \u03b2 : Type _}\n\n/-! ### Chains -/\n\n\nsection Chain\n\nvariable (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n/-- In this file, we use `\u227a` as a local notation for any relation `r`. -/\nlocal infixl:50 \" \u227a \" => r\n\n/-- A chain is a set `s` satisfying `x \u227a y \u2228 x = y \u2228 y \u227a x` for all `x y \u2208 s`. -/\ndef IsChain (s : Set \u03b1) : Prop :=\n  s.Pairwise fun x y => x \u227a y \u2228 y \u227a x\n#align is_chain IsChain\n\n/-- `SuperChain s t` means that `t` is a chain that strictly includes `s`. -/\ndef SuperChain (s t : Set \u03b1) : Prop :=\n  IsChain r t \u2227 s \u2282 t\n#align super_chain SuperChain\n\n/-- A chain `s` is a maximal chain if there does not exists a chain strictly including `s`. -/\ndef IsMaxChain (s : Set \u03b1) : Prop :=\n  IsChain r s \u2227 \u2200 \u2983t\u2984, IsChain r t \u2192 s \u2286 t \u2192 s = t\n#align is_max_chain IsMaxChain\n\nvariable {r} {c c\u2081 c\u2082 c\u2083 s t : Set \u03b1} {a b x y : \u03b1}\n\ntheorem isChain_empty : IsChain r \u2205 :=\n  Set.pairwise_empty _\n#align is_chain_empty isChain_empty\n\ntheorem Set.Subsingleton.isChain (hs : s.Subsingleton) : IsChain r s :=\n  hs.pairwise _\n#align set.subsingleton.is_chain Set.Subsingleton.isChain\n\ntheorem IsChain.mono : s \u2286 t \u2192 IsChain r t \u2192 IsChain r s :=\n  Set.Pairwise.mono\n#align is_chain.mono IsChain.mono\n\ntheorem IsChain.mono_rel {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (h : IsChain r s) (h_imp : \u2200 x y, r x y \u2192 r' x y) :\n    IsChain r' s :=\n  h.mono' fun x y => Or.imp (h_imp x y) (h_imp y x)\n#align is_chain.mono_rel IsChain.mono_rel\n\n/-- This can be used to turn `IsChain (\u2265)` into `IsChain (\u2264)` and vice-versa. -/\ntheorem IsChain.symm (h : IsChain r s) : IsChain (flip r) s :=\n  h.mono' fun _ _ => Or.symm\n#align is_chain.symm IsChain.symm\n\ntheorem isChain_of_trichotomous [IsTrichotomous \u03b1 r] (s : Set \u03b1) : IsChain r s :=\n  fun a _ b _ hab => (trichotomous_of r a b).imp_right fun h => h.resolve_left hab\n#align is_chain_of_trichotomous isChain_of_trichotomous\n\ntheorem IsChain.insert (hs : IsChain r s) (ha : \u2200 b \u2208 s, a \u2260 b \u2192 a \u227a b \u2228 b \u227a a) :\n    IsChain r (insert a s) :=\n  hs.insert_of_symmetric (fun _ _ => Or.symm) ha\n#align is_chain.insert IsChain.insert\n\ntheorem isChain_univ_iff : IsChain r (univ : Set \u03b1) \u2194 IsTrichotomous \u03b1 r := by\n  refine' \u27e8fun h => \u27e8fun a b => _\u27e9, fun h => @isChain_of_trichotomous _ _ h univ\u27e9\n  rw [or_left_comm, or_iff_not_imp_left]\n  exact h trivial trivial\n#align is_chain_univ_iff isChain_univ_iff\n\ntheorem IsChain.image (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) (f : \u03b1 \u2192 \u03b2)\n    (h : \u2200 x y, r x y \u2192 s (f x) (f y)) {c : Set \u03b1} (hrc : IsChain r c) : IsChain s (f '' c) :=\n  fun _ \u27e8_, ha\u2081, ha\u2082\u27e9 _ \u27e8_, hb\u2081, hb\u2082\u27e9 =>\n  ha\u2082 \u25b8 hb\u2082 \u25b8 fun hxy => (hrc ha\u2081 hb\u2081 <| ne_of_apply_ne f hxy).imp (h _ _) (h _ _)\n#align is_chain.image IsChain.image\n\nsection Total\n\nvariable [IsRefl \u03b1 r]\n\ntheorem IsChain.total (h : IsChain r s) (hx : x \u2208 s) (hy : y \u2208 s) : x \u227a y \u2228 y \u227a x :=\n  (eq_or_ne x y).elim (fun e => Or.inl <| e \u25b8 refl _) (h hx hy)\n#align is_chain.total IsChain.total\n\ntheorem IsChain.directedOn (H : IsChain r s) : DirectedOn r s := fun x hx y hy =>\n  ((H.total hx hy).elim fun h => \u27e8y, hy, h, refl _\u27e9) fun h => \u27e8x, hx, refl _, h\u27e9\n#align is_chain.directed_on IsChain.directedOn\n\nprotected theorem IsChain.directed {f : \u03b2 \u2192 \u03b1} {c : Set \u03b2} (h : IsChain (f \u207b\u00b9'o r) c) :\n    Directed r fun x : { a : \u03b2 // a \u2208 c } => f x :=\n  fun \u27e8a, ha\u27e9 \u27e8b, hb\u27e9 =>\n    (by_cases fun hab : a = b => by\n      simp only [hab, exists_prop, and_self_iff, Subtype.exists]\n      exact \u27e8b, hb, refl _\u27e9)\n    fun hab => ((h ha hb hab).elim fun h => \u27e8\u27e8b, hb\u27e9, h, refl _\u27e9) fun h => \u27e8\u27e8a, ha\u27e9, refl _, h\u27e9\n#align is_chain.directed IsChain.directed\n\ntheorem IsChain.exists3 (hchain : IsChain r s) [IsTrans \u03b1 r] {a b c} (mem1 : a \u2208 s) (mem2 : b \u2208 s)\n    (mem3 : c \u2208 s) : \u2203 (z : _) (_ : z \u2208 s), r a z \u2227 r b z \u2227 r c z := by\n  rcases directedOn_iff_directed.mpr (IsChain.directed hchain) a mem1 b mem2 with \u27e8z, mem4, H1, H2\u27e9\n  rcases directedOn_iff_directed.mpr (IsChain.directed hchain) z mem4 c mem3 with\n    \u27e8z', mem5, H3, H4\u27e9\n  exact \u27e8z', mem5, _root_.trans H1 H3, _root_.trans H2 H3, H4\u27e9\n#align is_chain.exists3 IsChain.exists3\n\nend Total\n\ntheorem IsMaxChain.isChain (h : IsMaxChain r s) : IsChain r s :=\n  h.1\n#align is_max_chain.is_chain IsMaxChain.isChain\n\ntheorem IsMaxChain.not_superChain (h : IsMaxChain r s) : \u00acSuperChain r s t := fun ht =>\n  ht.2.ne <| h.2 ht.1 ht.2.1\n#align is_max_chain.not_super_chain IsMaxChain.not_superChain\n\ntheorem IsMaxChain.bot_mem [LE \u03b1] [OrderBot \u03b1] (h : IsMaxChain (\u00b7 \u2264 \u00b7) s) : \u22a5 \u2208 s :=\n  (h.2 (h.1.insert fun _ _ _ => Or.inl bot_le) <| subset_insert _ _).symm \u25b8 mem_insert _ _\n#align is_max_chain.bot_mem IsMaxChain.bot_mem\n\ntheorem IsMaxChain.top_mem [LE \u03b1] [OrderTop \u03b1] (h : IsMaxChain (\u00b7 \u2264 \u00b7) s) : \u22a4 \u2208 s :=\n  (h.2 (h.1.insert fun _ _ _ => Or.inr le_top) <| subset_insert _ _).symm \u25b8 mem_insert _ _\n#align is_max_chain.top_mem IsMaxChain.top_mem\n\nopen Classical\n\n/-- Given a set `s`, if there exists a chain `t` strictly including `s`, then `SuccChain s`\nis one of these chains. Otherwise it is `s`. -/\ndef SuccChain (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : Set \u03b1) : Set \u03b1 :=\n  if h : \u2203 t, IsChain r s \u2227 SuperChain r s t then choose h else s\n#align succ_chain SuccChain\n\ntheorem succChain_spec (h : \u2203 t, IsChain r s \u2227 SuperChain r s t) :\n    SuperChain r s (SuccChain r s) := by\n  have : IsChain r s \u2227 SuperChain r s (choose h) :=\n    @choose_spec _ (fun t => IsChain r s \u2227 SuperChain r s t) _\n  simpa [SuccChain, dif_pos, exists_and_left.mp h] using this.2\n\n#align succ_chain_spec succChain_spec\n\ntheorem IsChain.succ (hs : IsChain r s) : IsChain r (SuccChain r s) :=\n  if h : \u2203 t, IsChain r s \u2227 SuperChain r s t then (succChain_spec h).1\n  else by\n    rw [exists_and_left] at h\n    simpa [SuccChain, dif_neg, h] using hs\n#align is_chain.succ IsChain.succ\n\ntheorem IsChain.superChain_succChain (hs\u2081 : IsChain r s) (hs\u2082 : \u00acIsMaxChain r s) :\n    SuperChain r s (SuccChain r s) := by\n  simp only [IsMaxChain, not_and, not_forall, exists_prop, exists_and_left] at hs\u2082\n  obtain \u27e8t, ht, hst\u27e9 := hs\u2082 hs\u2081\n  exact succChain_spec \u27e8t, hs\u2081, ht, ssubset_iff_subset_ne.2 hst\u27e9\n#align is_chain.super_chain_succ_chain IsChain.superChain_succChain\n\ntheorem subset_succChain : s \u2286 SuccChain r s :=\n  if h : \u2203 t, IsChain r s \u2227 SuperChain r s t then (succChain_spec h).2.1\n  else by\n    rw [exists_and_left] at h\n    simp [SuccChain, dif_neg, h, Subset.rfl]\n#align subset_succ_chain subset_succChain\n\n/-- Predicate for whether a set is reachable from `\u2205` using `SuccChain` and `\u22c3\u2080`. -/\ninductive ChainClosure (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : Set \u03b1 \u2192 Prop\n  | succ : \u2200 {s}, ChainClosure r s \u2192 ChainClosure r (SuccChain r s)\n  | union : \u2200 {s}, (\u2200 a \u2208 s, ChainClosure r a) \u2192 ChainClosure r (\u22c3\u2080s)\n#align chain_closure ChainClosure\n\n/-- An explicit maximal chain. `maxChain` is taken to be the union of all sets in `ChainClosure`.\n-/\ndef maxChain (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : Set \u03b1 :=\n  \u22c3\u2080 setOf (ChainClosure r)\n#align max_chain maxChain\n\ntheorem chainClosure_empty : ChainClosure r \u2205 := by\n  have : ChainClosure r (\u22c3\u2080\u2205) := ChainClosure.union fun a h => False.rec h\n  simpa using this\n#align chain_closure_empty chainClosure_empty\n\ntheorem chainClosure_maxChain : ChainClosure r (maxChain r) :=\n  ChainClosure.union fun _ => id\n#align chain_closure_max_chain chainClosure_maxChain\n\nprivate theorem chainClosure_succ_total_aux (hc\u2081 : ChainClosure r c\u2081) (_ : ChainClosure r c\u2082)\n    (h : \u2200 \u2983c\u2083\u2984, ChainClosure r c\u2083 \u2192 c\u2083 \u2286 c\u2082 \u2192 c\u2082 = c\u2083 \u2228 SuccChain r c\u2083 \u2286 c\u2082) :\n    SuccChain r c\u2082 \u2286 c\u2081 \u2228 c\u2081 \u2286 c\u2082 := by\n  induction hc\u2081\n  case succ c\u2083 hc\u2083 ih =>\n    cases' ih with ih ih\n    \u00b7 exact Or.inl (ih.trans subset_succChain)\n    \u00b7 exact (h hc\u2083 ih).imp_left fun (h : c\u2082 = c\u2083) => h \u25b8 Subset.rfl\n  case union s _ ih =>\n    refine' or_iff_not_imp_left.2 fun hn => union\u209b_subset fun a ha => _\n    exact (ih a ha).resolve_left fun h => hn <| h.trans <| subset_union\u209b_of_mem ha\n\nprivate theorem chainClosure_succ_total (hc\u2081 : ChainClosure r c\u2081) (hc\u2082 : ChainClosure r c\u2082)\n    (h : c\u2081 \u2286 c\u2082) : c\u2082 = c\u2081 \u2228 SuccChain r c\u2081 \u2286 c\u2082 := by\n  induction hc\u2082 generalizing c\u2081 hc\u2081\n  case succ c\u2082 hc\u2082 ih =>\n    refine' ((chainClosure_succ_total_aux hc\u2081 hc\u2082) fun c\u2081 => ih).imp h.antisymm' fun h\u2081 => _\n    obtain rfl | h\u2082 := ih hc\u2081 h\u2081\n    \u00b7 exact Subset.rfl\n    \u00b7 exact h\u2082.trans subset_succChain\n  case union s hs ih =>\n    apply Or.imp_left h.antisymm'\n    apply by_contradiction\n    simp only [union\u209b_subset_iff, not_or, not_forall, exists_prop, and_imp, forall_exists_index]\n    intro c\u2083 hc\u2083 h\u2081 h\u2082\n    obtain h | h := chainClosure_succ_total_aux hc\u2081 (hs c\u2083 hc\u2083) fun c\u2084 => ih _ hc\u2083\n    \u00b7 exact h\u2081 (subset_succChain.trans h)\n    obtain h' | h' := ih c\u2083 hc\u2083 hc\u2081 h\n    \u00b7 exact h\u2081 h'.subset\n    \u00b7 exact h\u2082 (h'.trans <| subset_union\u209b_of_mem hc\u2083)\n\ntheorem ChainClosure.total (hc\u2081 : ChainClosure r c\u2081) (hc\u2082 : ChainClosure r c\u2082) :\n    c\u2081 \u2286 c\u2082 \u2228 c\u2082 \u2286 c\u2081 :=\n  ((chainClosure_succ_total_aux hc\u2082 hc\u2081) fun _ hc\u2083 => chainClosure_succ_total hc\u2083 hc\u2081).imp_left\n    subset_succChain.trans\n#align chain_closure.total ChainClosure.total\n\ntheorem ChainClosure.succ_fixpoint (hc\u2081 : ChainClosure r c\u2081) (hc\u2082 : ChainClosure r c\u2082)\n    (hc : SuccChain r c\u2082 = c\u2082) : c\u2081 \u2286 c\u2082 := by\n  induction hc\u2081\n  case succ s\u2081 hc\u2081 h => exact (chainClosure_succ_total hc\u2081 hc\u2082 h).elim (fun h => h \u25b8 hc.subset) id\n  case union s _ ih => exact union\u209b_subset ih\n#align chain_closure.succ_fixpoint ChainClosure.succ_fixpoint\n\ntheorem ChainClosure.succ_fixpoint_iff (hc : ChainClosure r c) :\n    SuccChain r c = c \u2194 c = maxChain r :=\n  \u27e8fun h => (subset_union\u209b_of_mem hc).antisymm <| chainClosure_maxChain.succ_fixpoint hc h,\n    fun h => subset_succChain.antisymm' <| (subset_union\u209b_of_mem hc.succ).trans h.symm.subset\u27e9\n#align chain_closure.succ_fixpoint_iff ChainClosure.succ_fixpoint_iff\n\ntheorem ChainClosure.isChain (hc : ChainClosure r c) : IsChain r c := by\n  induction hc\n  case succ c _ h => exact h.succ\n  case union s hs h =>\n    exact fun c\u2081 \u27e8t\u2081, ht\u2081, (hc\u2081 : c\u2081 \u2208 t\u2081)\u27e9 c\u2082 \u27e8t\u2082, ht\u2082, (hc\u2082 : c\u2082 \u2208 t\u2082)\u27e9 hneq =>\n      ((hs _ ht\u2081).total <| hs _ ht\u2082).elim (fun ht => h t\u2082 ht\u2082 (ht hc\u2081) hc\u2082 hneq) fun ht =>\n        h t\u2081 ht\u2081 hc\u2081 (ht hc\u2082) hneq\n#align chain_closure.is_chain ChainClosure.isChain\n\n/-- **Hausdorff's maximality principle**\n\nThere exists a maximal totally ordered set of `\u03b1`.\nNote that we do not require `\u03b1` to be partially ordered by `r`. -/\ntheorem maxChain_spec : IsMaxChain r (maxChain r) :=\n  by_contradiction fun h =>\n    let \u27e8_, H\u27e9 := chainClosure_maxChain.isChain.superChain_succChain h\n    H.ne (chainClosure_maxChain.succ_fixpoint_iff.mpr rfl).symm\n#align max_chain_spec maxChain_spec\n\nend Chain\n\n/-! ### Flags -/\n\n\n/-- The type of flags, aka maximal chains, of an order. -/\nstructure Flag (\u03b1 : Type _) [LE \u03b1] where\n  /-- The `carrier` of a flag is the underlying set. -/\n  carrier : Set \u03b1\n  /-- By definition, a flag is a chain -/\n  Chain' : IsChain (\u00b7 \u2264 \u00b7) carrier\n  /-- By definition, a flag is a maximal chain -/\n  max_chain' : \u2200 \u2983s\u2984, IsChain (\u00b7 \u2264 \u00b7) s \u2192 carrier \u2286 s \u2192 carrier = s\n#align flag Flag\n\nnamespace Flag\n\nsection LE\n\nvariable [LE \u03b1] {s t : Flag \u03b1} {a : \u03b1}\n\ninstance : SetLike (Flag \u03b1) \u03b1 where\n  coe := carrier\n  coe_injective' s t h := by\n    cases s\n    cases t\n    congr\n\n@[ext]\ntheorem ext : (s : Set \u03b1) = t \u2192 s = t :=\n  SetLike.ext'\n#align flag.ext Flag.ext\n\n-- Porting note: `simp` can now prove this\n-- @[simp]\ntheorem mem_coe_iff : a \u2208 (s : Set \u03b1) \u2194 a \u2208 s :=\n  Iff.rfl\n#align flag.mem_coe_iff Flag.mem_coe_iff\n\n@[simp]\ntheorem coe_mk (s : Set \u03b1) (h\u2081 h\u2082) : (mk s h\u2081 h\u2082 : Set \u03b1) = s :=\n  rfl\n#align flag.coe_mk Flag.coe_mk\n\n@[simp]\ntheorem mk_coe (s : Flag \u03b1) : mk (s : Set \u03b1) s.Chain' s.max_chain' = s :=\n  ext rfl\n#align flag.mk_coe Flag.mk_coe\n\ntheorem chain_le (s : Flag \u03b1) : IsChain (\u00b7 \u2264 \u00b7) (s : Set \u03b1) :=\n  s.Chain'\n#align flag.chain_le Flag.chain_le\n\nprotected theorem maxChain (s : Flag \u03b1) : IsMaxChain (\u00b7 \u2264 \u00b7) (s : Set \u03b1) :=\n  \u27e8s.chain_le, s.max_chain'\u27e9\n#align flag.max_chain Flag.maxChain\n\ntheorem top_mem [OrderTop \u03b1] (s : Flag \u03b1) : (\u22a4 : \u03b1) \u2208 s :=\n  s.maxChain.top_mem\n#align flag.top_mem Flag.top_mem\n\ntheorem bot_mem [OrderBot \u03b1] (s : Flag \u03b1) : (\u22a5 : \u03b1) \u2208 s :=\n  s.maxChain.bot_mem\n#align flag.bot_mem Flag.bot_mem\n\nend LE\n\nsection Preorder\n\nvariable [Preorder \u03b1] {a b : \u03b1}\n\nprotected theorem le_or_le (s : Flag \u03b1) (ha : a \u2208 s) (hb : b \u2208 s) : a \u2264 b \u2228 b \u2264 a :=\n  s.chain_le.total ha hb\n#align flag.le_or_le Flag.le_or_le\n\ninstance [OrderTop \u03b1] (s : Flag \u03b1) : OrderTop s :=\n  Subtype.orderTop s.top_mem\n\ninstance [OrderBot \u03b1] (s : Flag \u03b1) : OrderBot s :=\n  Subtype.orderBot s.bot_mem\n\ninstance [BoundedOrder \u03b1] (s : Flag \u03b1) : BoundedOrder s :=\n  Subtype.boundedOrder s.bot_mem s.top_mem\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b1]\n\ntheorem chain_lt (s : Flag \u03b1) : IsChain (\u00b7 < \u00b7) (s : Set \u03b1) := fun _ ha _ hb h =>\n  (s.le_or_le ha hb).imp h.lt_of_le h.lt_of_le'\n#align flag.chain_lt Flag.chain_lt\n\ninstance [@DecidableRel \u03b1 (\u00b7 \u2264 \u00b7)] [@DecidableRel \u03b1 (\u00b7 < \u00b7)] (s : Flag \u03b1) :\n    LinearOrder s :=\n  { Subtype.partialOrder _ with\n    le_total := fun a b => s.le_or_le a.2 b.2\n    decidable_le := Subtype.decidableLE\n    decidable_lt := Subtype.decidableLT }\n\nend PartialOrder\n\ninstance [LinearOrder \u03b1] : Unique (Flag \u03b1) where\n  default := \u27e8univ, isChain_of_trichotomous _, fun s _ => s.subset_univ.antisymm'\u27e9\n  uniq s := SetLike.coe_injective <| s.3 (isChain_of_trichotomous _) <| subset_univ _\n\nend Flag\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/Chain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7247289643232616}}
{"text": "import data.real.basic\nimport algebra.pi_instances\nimport tuto_lib\n\nnotation `|`x`|` := abs x\n\n/-\nIn this file we manipulate the elementary definition of limits of\nsequences of real numbers.\nmathlib has a much more general definition of limits, but here\nwe want to practice using the logical operators and relations\ncovered in the previous files.\n\nA sequence u is a function from \u2115 to \u211d, hence Lean says\nu : \u2115 \u2192 \u211d\nThe definition we'll be using is:\n\n-- Definition of \u00ab u tends to l \u00bb\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\nNote the use of `\u2200 \u03b5 > 0, ...` which is an abbreviation of\n`\u2200 \u03b5, \u03b5 > 0 \u2192 ... `\n\nIn particular, a statement like `h : \u2200 \u03b5 > 0, ...`\ncan be specialized to a given \u03b5\u2080 by\n  `specialize h \u03b5\u2080 h\u03b5\u2080`\nwhere h\u03b5\u2080 is a proof of \u03b5\u2080 > 0.\n\nAlso recall that, wherever Lean expects some proof term, we can\nstart a tactic mode proof using the keyword `by` (followed by curly braces\nif you need more than one tactic invocation).\nFor instance, if the local context contains:\n\n\u03b4 : \u211d\n\u03b4_pos : \u03b4 > 0\nh : \u2200 \u03b5 > 0, ...\n\nthen we can specialize h to the real number \u03b4/2 using:\n  `specialize h (\u03b4/2) (by linarith)`\nwhere `by linarith` will provide the proof of `\u03b4/2 > 0` expected by Lean.\n\nWe'll take this opportunity to use two new tactics:\n\n`norm_num` will perform numerical normalization on the goal and `norm_num at h`\nwill do the same in assumption `h`. This will get rid of trivial calculations on numbers,\nlike replacing |l - l| by zero in the next exercise.\n\n`congr'` will try to prove equalities between applications of functions by recursively\nproving the arguments are the same.\nFor instance, if the goal is `f x + g y = f z + g t` then congr will replace it by\ntwo goals: `x = z` and `y = t`.\nYou can limit the recursion depth by specifying a natural number after `congr'`.\nFor instance, in the above example, `congr' 1` will give new goals\n`f x = f z` and `g y = g t`, which only inspect arguments of the addition and not deeper.\n-/\n\nvariables (u v w : \u2115 \u2192 \u211d) (l l' : \u211d)\n\n-- If u is constant with value l then u tends to l\n-- 0033\nexample : (\u2200 n, u n = l) \u2192 seq_limit u l :=\nbegin\n  intros h e epos,\n  have t : (\u2200 n : \u2115, n \u2265 0 ->  |u n - l| \u2264 e), by\n    {intros n hn,\n    have h1 : -0 \u2264 (0:\u211d) \u2227 (0:\u211d) \u2264 0, from \u27e8by linarith, by linarith\u27e9,\n    have h2 : |(0:\u211d)| \u2264 0, from abs_le.mpr h1,\n    calc | u n - l | = | l - l | : by rw (h n)\n                 ... = |(0:\u211d)| : by rw (sub_self l)\n                 ... \u2264 0 : by exact h2\n                 ... \u2264 e : by linarith [epos]},\n  exact \u27e80, t\u27e9\nend\n\n/- When dealing with absolute values, we'll use lemmas:\n\nabs_le (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nabs_add (x y : \u211d) : |x + y| \u2264 |x| + |y|\n\nabs_sub (x y : \u211d) : |x - y| = |y - x|\n\nYou should probably write them down on a sheet of paper that you keep at\nhand since they are used in many exercises.\n-/\n\n-- Assume l > 0. Then u tends to l implies u n \u2265 l/2 for large enough n\n-- 0034\nexample (hl : l > 0) : seq_limit u l \u2192 \u2203 N, \u2200 n \u2265 N, u n \u2265 l/2 :=\nbegin\n  intros h,\n  unfold seq_limit at h,\n  specialize h (l/2) (by linarith [hl]),\n  rcases h with \u27e8t,rfl\u27e9,\n\n  exact h\nend\n\n/-\nWhen dealing with max, you can use\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\nYou should probably add them to the sheet of paper where you wrote\nthe `abs` lemmas since they are used in many exercises.\n\nLet's see an example.\n-/\n\n-- If u tends to l and v tends l' then u+v tends to l+l'\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\nseq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  cases ge_max_iff.mp hn with hn\u2081 hn\u2082,\n  have fact\u2081 : |u n - l| \u2264 \u03b5/2,\n    from hN\u2081 n (by linarith),  -- note the use of `from`.\n                               -- This is an alias for `exact`,\n                               -- but reads nicer in this context\n  have fact\u2082 : |v n - l'| \u2264 \u03b5/2,\n    from hN\u2082 n (by linarith),\n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1 ; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith,\nend\n\n/-\nIn the above proof, we used `have` to prepare facts for `linarith` consumption in the last line.\nSince we have direct proof terms for them, we can feed them directly to `linarith` as in the next proof\nof the same statement.\nAnother variation we introduce is rewriting using `ge_max_iff` and letting `linarith` handle the\nconjunction, instead of creating two new assumptions.\n-/\n\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\nseq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  rw ge_max_iff at hn,\n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1 ; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith [hN\u2081 n (by sorry), hN\u2082 n (by sorry)],\nend\n\n/- Let's do something similar: the squeezing theorem. -/\n-- 0035\nexample (hu : seq_limit u l) (hw : seq_limit w l)\n(h : \u2200 n, u n \u2264 v n)\n(h' : \u2200 n, v n \u2264 w n) : seq_limit v l :=\nbegin\n  sorry\n\nend\n\n/- What about < \u03b5? -/\n-- 0036\nexample (u l) : seq_limit u l \u2194\n \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5 :=\nbegin\n  sorry\nend\n\n/- In the next exercise, we'll use\n\neq_of_abs_sub_le_all (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y\n-/\n\n-- A sequence admits at most one limit\n-- 0037\nexample : seq_limit u l \u2192 seq_limit u l' \u2192 l = l' :=\nbegin\n  sorry\nend\n\n/-\nLet's now practice deciphering definitions before proving.\n-/\n\ndef non_decreasing (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\ndef is_seq_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n-- 0038\nexample (M : \u211d) (h : is_seq_sup M u) (h' : non_decreasing u) :\nseq_limit u M :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "kris-brown", "repo": "theorem_proving_in_lean", "sha": "774460c21bf857daff158210741bd88d1c8323cd", "save_path": "github-repos/lean/kris-brown-theorem_proving_in_lean", "path": "github-repos/lean/kris-brown-theorem_proving_in_lean/theorem_proving_in_lean-774460c21bf857daff158210741bd88d1c8323cd/tutorial_src/exercises/05_sequence_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7246422986072589}}
{"text": "import .algebra_util\n\nsection definitions\nvariables {R : Type _} [ring R]\n\ndef is_nilpotent (x : R) := \u2203 n : \u2115, x^n = 0\ndef is_unit (u : R) := \u2203 v, u*v = 1\n\ndef sequence (A : Type _) := nat \u2192 A\ndef convolve (a b : sequence R) :=\n  \u03bb n, sum_over (\u03bb j : fin (nat.succ n), a j.val * b (n - j.val))\ninfix ` \u2217 `:70 := convolve\n\nlemma convolution_assoc\n  : \u2200 a b c : sequence R, (a \u2217 b) \u2217 c = a \u2217 (b \u2217 c) :=\nbegin\n  intros, funext, dsimp [(\u2217), (\u2217)],\n  transitivity sum_over\n      (\u03bb (j : fin (nat.succ n)),\n         sum_over (\u03bb (j_1 : fin (nat.succ (j.val))), a (j_1.val) * b (j.val - j_1.val) * c (n - j.val))),\n  { congr, funext, rw mul_sum_over_right },\n  transitivity sum_over\n      (\u03bb (j : fin (nat.succ n)),\n         sum_over (\u03bb (j_1 : fin (nat.succ (n - j.val))), a (j.val) * (b (j_1.val) * c (n - j.val - j_1.val)))),\n  { rw double_sum_triangle (\u03bb (j j_1 : fin (nat.succ n)), a (j_1.val) * b (j.val - j_1.val) * c (n - j.val)),\n    congr, funext,\n    have : nat.succ n - k.val = nat.succ (n - k.val),\n    rw nat.succ_sub (nat.le_of_succ_le_succ k.is_lt),\n    congr, funext, exact this, apply fin.funext _ this, \n    intro x, cases x, simp *,\n    rw nat.add_sub_cancel, rw \u2190 mul_assoc, apply congr_arg,\n    apply congr_arg, rw nat.sub_sub, rw add_comm },\n  { congr, funext, rw mul_sum_over_left }\nend\n\nstructure power_series (R' : Type _) :=\n(coefficients : sequence R')\n\nlemma power_series.eq {R' : Type _}\n  : \u2200 p q : power_series R',\n    (\u2200 n, p.coefficients n = q.coefficients n) \n  \u2192 p = q\n| (power_series.mk a) (power_series.mk b) :=\n  \u03bb h, congr_arg power_series.mk (funext h)\n\npostfix `[[x]]`:100 := power_series\n\ndef power_series.zero_coeff : sequence R := \u03bb _, 0\ndef power_series.one_coeff : sequence R\n| 0 := 1\n| (nat.succ _) := 0\nlemma power_series.one_coeff_of_pos\n  : \u2200 {n}, 0 < n \u2192 power_series.one_coeff n = (0 : R) :=\nby { intros, cases n, exfalso, exact lt_irrefl 0 a, refl }\n\nmeta def power_series_preamble := \n`[intros, apply power_series.eq, intro, dsimp [power_series.coefficients]]\n\ninstance : ring (R[[x]]) := { ring .\n  zero := power_series.mk power_series.zero_coeff,\n  one  := power_series.mk power_series.one_coeff,\n  add  := \u03bb p q, power_series.mk (\u03bb n, p.coefficients n + q.coefficients n),\n  neg  := \u03bb p, power_series.mk (\u03bb n, - p.coefficients n),\n  mul  := \u03bb p q, power_series.mk (convolve p.coefficients q.coefficients),\n  zero_add := by { power_series_preamble, apply zero_add },\n  add_zero := by { power_series_preamble, apply add_zero },\n  add_left_neg := by { power_series_preamble, apply add_left_neg },\n  add_assoc := by { power_series_preamble, apply add_assoc },\n  add_comm := by { power_series_preamble, apply add_comm },\n  mul_assoc := by { intros, cases a, cases b, cases c,\n                    dsimp [power_series.coefficients], rw convolution_assoc },\n  one_mul := by { power_series_preamble, dsimp [(\u2217)],\n                  rw sum_over.step_front, dsimp [power_series.one_coeff],\n                  rw one_mul, transitivity a.coefficients n + 0, congr,\n                  rw \u2190 sum_over_eq_zero, congr, funext,\n                  transitivity 0 * a.coefficients (n - nat.succ (j.val)),\n                  congr, apply sum_over_eq_zero, apply zero_mul, apply add_zero },\n  mul_one := by { power_series_preamble, dsimp [(\u2217)], \n                  rw sum_over.step, rw nat.sub_self, dsimp [power_series.one_coeff],\n                  rw mul_one, transitivity 0 + a.coefficients n, congr,\n                  rw \u2190 sum_over_eq_zero, congr, funext, dsimp [fin.restrict],\n                  transitivity a.coefficients k.val * 0, congr,\n                  rw power_series.one_coeff_of_pos (nat.sub_pos_of_lt k.is_lt),\n                  apply mul_zero, apply zero_add },\n  left_distrib := by { power_series_preamble, dsimp [(\u2217)],\n                       rw \u2190 sum_over_sum, congr, funext, apply left_distrib },\n  right_distrib := by { power_series_preamble, dsimp [(\u2217)],\n                       rw \u2190 sum_over_sum, congr, funext, apply right_distrib } }\n\nend definitions\n\nsection lemmas\nvariables {R : Type _} [ring R]\n\nlemma my_mul_zero : \u2200 x : R, x * 0 = 0 :=\n\u03bb x, add_group.eq_zero_of_add_eq_self $ eq.symm $\n     calc x * 0 = x * (0 + 0)   : by rw zero_add\n          ...   = x * 0 + x * 0 : left_distrib _ _ _\n\nend lemmas\n\nnamespace problem1 section\nparameters {R : Type _} [ring R]\n\nlemma a : 1 * 1 = (1 : R) := mul_one 1\n\nlemma b : (- 1) * (- 1) = (1 : R) :=\n  have (-1)*(-1) = -(-1 : R),\n  from add_group.inv_unique (-1 : R) (-1 * -1)\n       $ calc -1 * (-1 : R) + -1 = -1 * -1 + -1 * 1 : by rw mul_one\n             ...                = (-1) * (-1 + 1)   : by rw eq.symm (left_distrib (-1 : R) (-1) 1)\n             ...                = (-1) * 0          : by rw [neg_add_eq_sub, sub_self]\n             ...                = 0                 : my_mul_zero (-1),\n  show (-1 : R) * (-1) = 1, from eq.trans this $ neg_neg (1 : R)\nend end problem1\n\nnamespace problem2 section\nparameters {R : Type _} [comm_ring R]\n\nlemma a : \u2200 x y : R, is_nilpotent x \u2192 is_nilpotent y \u2192 is_nilpotent (x + y) :=\nbegin\n  intros x y hx hy, cases hx with n hx, cases hy with m hy,\n  existsi n + m, rw binomial_theorem x y (mul_comm x y),\n  rw \u2190 @sum_over_eq_zero _ _ (n+m+1), dsimp [binomial_expansion],\n  congr, funext,\n  cases k with k hk, simp, by_cases k < n,\n  { rw (_ : n + m - k = m + (n - k)), \n    rw [monoid.pow_of_sum_eq_mul, hy], simp,\n    rw [nat.add_comm, nat.add_sub_assoc], \n    apply le_of_lt, assumption },\n  { rw (_ : x^k = x^(n + (k - n))), \n    rw [monoid.pow_of_sum_eq_mul, hx], simp,\n    congr, rw [nat.add_comm, nat.sub_add_cancel],\n    apply le_of_not_gt, assumption }\nend\n\nlemma b.helper1 : \u2200 (x : R) (n : nat), x^n = 0 \u2192 (- x)^n = 0 :=\nby intros; rw neg_eq_neg_one_mul; rw [power_of_prod, a, mul_zero]\n\nlemma b.helper2 : \u2200 (x y : R), x * y = 1 \u2192 \u2200 (n : nat), x^n * y^n = 1 :=\nby intros; rw [\u2190 power_of_prod]; rw a; rw power_of_one n\n\nlemma b : \u2200 x y : R, is_nilpotent x \u2192 is_unit y \u2192 is_unit (x + y) :=\nbegin\n  intros x y hx hy, cases hy with y_inv hy, cases hx with n hx,\n  cases n with n; simp [(^), mul_n_times] at hx,\n  { existsi (0 : R), rw hx, apply mul_zero },\n  cases n with n,\n  { simp [ mul_n_times] at hx, subst hx,\n    rw zero_add, existsi y_inv, assumption },\n  rw (_ : (x + y) = -((- 1) - x * y_inv) * y),\n  { existsi y_inv * elephant (- 1) (x * y_inv) (nat.succ (nat.succ (n * 2))),\n    rw mul_assoc, transitivity -(-1 - x * y_inv) * ((y * y_inv) * elephant (-1) (x * y_inv) (nat.succ (nat.succ (n * 2)))),\n    rw mul_assoc, rw [hy, one_mul], \n    { rw [neg_eq_neg_one_mul, mul_assoc],\n      rw [\u2190 elephant_teacup],\n      rw (_ : (x * y_inv) ^ nat.succ (nat.succ (nat.succ (n * 2))) = (x * y_inv) ^ ((n+2) + (n + 1))),\n      { rw [monoid.pow_of_sum_eq_mul, power_of_prod], \n        rw (_ : x ^ (n + 2) = mul_n_times x (nat.succ n) * x),\n        rw [hx, zero_mul, zero_mul, sub_zero, mul_comm],\n        transitivity (-1 : R)^((n+2)*2),\n        { dsimp [(^)], congr, dsimp [(*)],\n          rw [(_ : nat.add 1 0 = 1), (_ : nat.add n 0 = n), (_ : nat.mul (n+2) 1 = n + 2)],\n          rw [(_ : nat.mul n 2 = n + n), (_ : n + 2 = n.succ.succ)], \n          rw \u2190 nat.succ_add, rw \u2190 nat.succ_add, refl,\n          any_goals {refl},\n          rw \u2190 nat.mul_two, refl,\n          transitivity (n+2)*1, refl, rw mul_one },\n        { rw mul_comm, rw exp_of_prod, rw (_ : (-1)^2 = (1 : R)),\n          apply power_of_one, dsimp [(^), mul_n_times], \n          rw [one_mul], rw problem1.b },\n        { refl } },\n      congr, rw nat.mul_two, \n      rw [(_ : nat.add n 0 = n), (_ : n + 2 = n.succ.succ)],\n      rw [\u2190 nat.succ_add, \u2190 nat.succ_add], refl, refl, refl,\n      rw mul_comm, } },\n  { rw [neg_sub, sub_neg_eq_add, right_distrib],\n    rw [one_mul, mul_assoc, mul_comm _ y, hy, mul_one] }\nend\n\nend end problem2\n\n-- for parts a and c, see boolean_rings\nnamespace problem3\n\nlemma b {R} [integral_domain R]\n  : (\u2200 x : R, x*x = x) \u2192 (\u2200 x : R, x = 1 \u2228 x = 0) :=\nbegin\n  intros is_bool x,\n  rw (_ : x = 1 \u2194 1 + -x = 0),\n  apply eq_zero_or_eq_zero_of_mul_eq_zero,\n  rw [right_distrib, neg_mul_eq_neg_mul_symm, is_bool],\n  rw one_mul, apply add_neg_self,\n  constructor; intro h, subst h, apply add_neg_self,\n  rw eq_add_of_add_neg_eq h, simp,\nend\n\nend problem3\n\nnamespace problem4 section\n\nparameters {R : Type _} [ring R]\n\ndef a.helper1 (a\u2099 : sequence R) (b\u2080 : R) : sequence R\n| 0 := b\u2080\n| (nat.succ n) := b\u2080 * -sum_over\n        (\u03bb (j : fin (nat.succ n)),\n           have this : n - j.val < nat.succ n := nat.lt_of_le_of_lt (nat.sub_le _ _) (nat.lt_succ_self _),\n           a\u2099 j.val.succ * a.helper1 (n - j.val))\n\nlemma a.helper1.of_zero (a\u2099 : sequence R) (b\u2080 : R) : a.helper1 a\u2099 b\u2080 0 = b\u2080 := rfl\nlemma a.helper1.of_succ (a\u2099 : sequence R) (b\u2080 : R)\n  : \u2200 n, a.helper1 a\u2099 b\u2080 (nat.succ n)\n       = b\u2080 * -sum_over\n          (\u03bb (j : fin (nat.succ n)),\n            a\u2099 j.val.succ * a.helper1 a\u2099 b\u2080 (n - j.val)) :=\n  \u03bb _, rfl\n\nlemma a : \u2200 p : R[[x]], is_unit p \u2194 is_unit (p.coefficients 0) :=\nbegin\n  intro p,\n  constructor,\n  { intro h, cases h with q h, \n    existsi q.coefficients 0,\n    have : (p*q).coefficients 0 = power_series.coefficients 1 0,\n    { rw h }, dsimp [power_series.coefficients, (\u2217)] at this,\n    dsimp [sum_over] at this, rw zero_add at this, exact this },\n  { intro h, cases h with b\u2080 h,\n    existsi (power_series.mk (a.helper1 p.coefficients b\u2080)),\n    apply power_series.eq, intro, dsimp [power_series.coefficients],\n    cases n with n,\n    { dsimp [(\u2217), sum_over], rw (a.helper1.of_zero), rw [zero_add, h], refl },\n    { dsimp [(\u2217)], rw sum_over.step_front, simp,\n      rw [a.helper1.of_succ, \u2190 mul_assoc, h, one_mul],\n      rw add_comm, rw add_neg_self, refl } }\nend\n\nend end problem4\n\nsection week2\n\n\n\nend week2", "meta": {"author": "Shamrock-Frost", "repo": "boolean_rings", "sha": "5da11beeaa37ec186c1deff946f2dbf7594fceb4", "save_path": "github-repos/lean/Shamrock-Frost-boolean_rings", "path": "github-repos/lean/Shamrock-Frost-boolean_rings/boolean_rings-5da11beeaa37ec186c1deff946f2dbf7594fceb4/other_problems.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7246422982374584}}
{"text": "import algebra.homology.homological_complex\nimport category_theory.abelian.exact\nimport algebra.category.Module.abelian\n\nimport tactic.interval_cases\n\nimport .test\n\n/-!\n\n# Collapsing double complex into a single complex\n\nWe can consider homological bicomplexes indexed by either natural numbers or integers \n(or maybe even $\\mathbb Z_n$ for shorter complexes) and the arrows can be either up or down \n(homology or cohomology). Below is an example where the indexing set is integers and arrows are \ngoing up (going from smaller number to bigger numbers). We want to collapse a double complex \n$(C_{i, j}, d_h, d_v)$ into a single complex $\\operatorname{Tot}^{\\oplus}_k := \\bigoplus_{i+j = k}C_{i, j}$ \nwith differential $d^{\\oplus} = d_h + d_v$. For this to be a differential, \nthe bicomplex need to have anticommutative squares (i.e. $d_hd_v + d_vd_h = 0$).\n$$\n\\begin{CD}\n@. \\cdots @.\\cdots @.\\cdots\\\\\n@. @VVV @VVV @VVV \\\\\n\\cdots @>>> C_{-1,0} @>{d_h}>>C_{-1, 1} @>{d_h}>> C_{-1, 2} @>>>\\cdots\\\\\n@. @V{d_v}VV @V{d_v}VV @V{d_v}VV\\\\\n\\cdots @>>> C_{0,0} @>{d_h}>> C_{0, 1} @>{d_h}>> C_{0, 2} @>>>\\cdots\\\\\n@. @V{d_v}VV @V{d_v}VV @V{d_v}VV\\\\\n\\cdots @>>> C_{1,0} @>{d_h}>> C_{1, 1} @>{d_h}>> C_{1,2} @>>> \\cdots\\\\\n@. @VVV @VVV @VVV \\\\\n@. \\cdots @. \\cdots @. \\cdots\n\\end{CD}\n$$\n\nThe only issue is that we don't want to keep repeating for different indexing sets and different directions of arrows. So we generalize to allow the homological bicomplex to have a row shape $a$ indexed by $\\alpha$ and a column shape $b$ indexed by $\\beta$. Then we collect $\\operatorname{Tot}^{\\oplus}$ using a new shape $c$ on $\\gamma$. To achieve this, we need a heterogeneous addition function $(+) : \\alpha \\to \\beta \\to \\gamma$ such that\n\n- for all $i, i' \\in \\alpha$ and $j \\in \\beta$, $i \\to_a i'$ if and only if $i + j \\to_c i' + j$;\n- for all $j, j' \\in \\beta$ and $i \\in \\alpha$, $j \\to_b j'$ if and only if $i+j\\to_c i + j'$;\n- addition is cancellative on both input: $i + j = i' + j$ if and only if $i = i'$ and $i + j = i + j'$ if and only if $j = j'$;\n- if $i+j\\to_c k \\to_c \\operatorname{succ}(i) + \\operatorname{succ}(j)$ then $k$ is equal to both $\\operatorname{succ}(i) + j$ and $i + \\operatorname{succ}(j)$;\n\nand the shapes $a, b, c$ must all be irreflexive. Then the total differential $\\bigoplus_{i+j=k}\\to \\bigoplus_{m+n=k'}$ is defined to be the linear map whose $(i,j)$-th projection is\n$$\n\\sum_{m=i~\\mathrm{or}~n=j}\\left(C_{i,j}\\stackrel{D}{\\to} C_{m,n}\\hookrightarrow\\bigoplus_{m+n=k}\\right),\n$$\nwhere\n$$\nD =\\left\\{\n\\begin{aligned}\nd_h & & i = j \\\\\nd_v & & m = n \\\\\n0 & & \\text{otherwise}\n\\end{aligned}\\right..\n$$\n\n## Main definitions\n\n- `has_hadd`: the typeclass of heterogeneous addition respecting row shape, column shape and result \n  shape.\n- `has_sign`: the typeclass allowing a complex shape to act on group by either `1` or `-1` with the\n  constrain that `rel i i'` implies the sign of `i` and `i'` is different.\n- `homological_bicomplex`: a web of the form `\u03b1 -> \u03b2 -> C` with rows and columns as complexes and\n  anticommutative squares.\n- `total_at`: (only in category of modules), given bicomplex `{C_ij}`, the `n`-th module of the total \n  complex is defined to be `\u2a01_{i + j = n}, C_ij`.\n- `total_d`: (only in category of modules), given bicomplex `{C_ij}`, the linear map \n  from `\u2a01_{i + j = n}, C_ij` to `\u2a01_{i + j = n'}, C_ij` is defined to be the linear map whose \n  `(i,j)`-th projection is `\u2211_{i' + j' = n' | i' = i \u2228 j' = j} (C_ij \u27f6 C_{i', j'} \u27f6 \u2a01_{p+q = n'} C_pq)`.\n- `total_d_comp_d`: if the resulting shape is irreflexive, then `total_d \u226b total_d` is zero whenever\n  `n, n', n''` are all related\n- `total_d_shape`: if row shape and column shape is irreflexive, then `total_d` is zero whenever \n  `n, n'` is not related\n- `total_complex`: the total complex of `{C_ij}` by means of direct sum with total differential \n  `total_d`.\n\n-/\n\nnoncomputable theory\n\nuniverses v u\n\nopen category_theory category_theory.category category_theory.limits\n\nvariables {\u03b1 \u03b2 : Type}\nvariables (V : Type u) [category.{v} V] [preadditive V]\n\nsection\n\n/--\nA complex shape `a` on `\u03b1` is irreflexive if `i` is not relate to `i` for all `i : \u03b1`. \n-/\ndef complex_shape.irrefl (a : complex_shape \u03b1) : Prop :=\n\u2200 (i : \u03b1), \u00ac a.rel i i\n\nlemma complex_shape.irrefl.ne {a : complex_shape \u03b1} (ha : a.irrefl) {i i' : \u03b1} :\n  a.rel i i' \u2192 i \u2260 i' :=\nbegin \n  contrapose!,\n  rintro rfl,\n  exact ha _,\nend\n\n/--\nA homological bicomplex `C` on `\u03b3` with rows of shape `a` on `\u03b1` and columns of shape `b` on `\u03b2` is \n`\u03b1 \u2192 \u03b2 \u2192 \u03b3` such that the diagram below has the following property\n```\n           ...      ->          ...\n            |                    |\n            v                    v\n... -> C (prev i) j -> C (prev i) (next j) -> ...\n            |        (\u2020)         |\n            v                    v\n... -> C i  j       -> C i   (next j)      -> ...\n            |                    |\n            v                    v\n           ...      ->          ...\n```\n\n* rows are homological complex of shape `a` with differential `d_h`;\n* columns are homological complex of shape `\u03b2` with differential `d_v`;\n* each square like (\u2020) anticommutes, i.e. `d_h \u226b d_v + d_v \u226b d_h = 0`.\n\n**WARNING**: Thus the diagram is not commutative.\n-/\n@[nolint has_nonempty_instance]\nstructure homological_bicomplex (a : complex_shape \u03b1) (b : complex_shape \u03b2) :=\n(X : \u03b1 \u2192 \u03b2 \u2192 V)\n(d_h : \u03a0 (i : \u03b1) (j j' : \u03b2), X i j \u27f6 X i j')\n(shape_h' : \u2200 (i : \u03b1) (j j' : \u03b2), \u00ac b.rel j j' \u2192 d_h i j j' = 0)\n(d_v : \u03a0 (j : \u03b2) (i i' : \u03b1), X i j \u27f6 X i' j)\n(shape_v' : \u2200 (j : \u03b2) (i i' : \u03b1), \u00ac a.rel i i' \u2192 d_v j i i' = 0)\n(d_comp_d_v' : \u2200 (j : \u03b2) (i\u2081 i\u2082 i\u2083 : \u03b1), a.rel i\u2081 i\u2082 \u2192 a.rel i\u2082 i\u2083 \u2192 \n  d_v j i\u2081 i\u2082 \u226b d_v j i\u2082 i\u2083 = 0)\n(d_comp_d_h' : \u2200 (i : \u03b1) (j\u2081 j\u2082 j\u2083 : \u03b2), b.rel j\u2081 j\u2082 \u2192 b.rel j\u2082 j\u2083 \u2192 \n  d_h i j\u2081 j\u2082 \u226b d_h i j\u2082 j\u2083 = 0)\n(anticomm' : \u2200 (i\u2081 i\u2082 : \u03b1) (j\u2081 j\u2082 : \u03b2), a.rel i\u2081 i\u2082 \u2192 b.rel j\u2081 j\u2082 \u2192 \n  d_h i\u2081 j\u2081 j\u2082 \u226b d_v j\u2082 i\u2081 i\u2082 + d_v j\u2081 i\u2081 i\u2082 \u226b d_h i\u2082 j\u2081 j\u2082 = 0)\n\nend\n\nnamespace homological_bicomplex\n\nrestate_axiom shape_h'\nrestate_axiom shape_v'\nattribute [simp] shape_h shape_v\n\nvariables {V}  {\u03b3 : Type} (a : complex_shape \u03b1) (b : complex_shape \u03b2) (c : complex_shape \u03b3)\n\n/--\nA complex shape `a` on `\u03b1` can be treated as having signs if any two related terms have different \nsign. \n-/\nclass has_sign :=\n(sign : \u03b1 \u2192 zmod 2)\n(rel : \u2200 (i i' : \u03b1), a.rel i i' \u2192 sign i \u2260 sign i')\n\n/--\nGiven three complex shapes `a` on `\u03b1`, `b` on `\u03b2` and `c` on `\u03b3`, a heterogeneous addition \n`(+[a,b,c]) : \u03b1 \u2192 \u03b2 \u2192 \u03b3` (written as `(+)` if `a, b, c` are clear from content) with respect to\nthe said complex shapes is such that:\n* for all `j : \u03b2`, `i -> i'` according to `a` if and only if `i + j -> i' + j` according to `c`;\n* for all `i : \u03b1`, `j -> j'` according to `b` if and only if `i + j -> i + j'` according to `c`;\n* addition is cancellative, i.e. `i + j = i + j'` if and only if `i = j` and `i' + j = i' + j` \n  if and only if `j = j'`;\n* it is possible to \"squeeze\" the middle term: if `i : \u03b1`, `j : \u03b2` and `k : \u03b3` are three terms such\n  that `(i + j) -> k` and `k -> (next i + next j)` according to `c`, then `k` is equal to both \n  `next i + j` and `i + next j`.\n-/\nclass has_hadd :=\n(add' {} : \u03b1 \u2192 \u03b2 \u2192 \u03b3)\n(rel_h' {} : \u2200 (i\u2081 i\u2082 : \u03b1) (j : \u03b2), a.rel i\u2081 i\u2082 \u2194 c.rel (add' i\u2081 j) (add' i\u2082 j))\n(rel_v' {} : \u2200 (i : \u03b1) (j\u2081 j\u2082 : \u03b2), b.rel j\u2081 j\u2082 \u2194 c.rel (add' i j\u2081) (add' i j\u2082))\n(add_cancel_h' : \u2200 (i\u2081 i\u2082 : \u03b1) (j : \u03b2), add' i\u2081 j = add' i\u2082 j \u2194 i\u2081 = i\u2082)\n(add_cancel_v' : \u2200 (i : \u03b1) (j\u2081 j\u2082 : \u03b2), add' i j\u2081 = add' i j\u2082 \u2194 j\u2081 = j\u2082)\n(squeeze' : \u2200 (i : \u03b1) (j : \u03b2) (k : \u03b3), c.rel (add' i j) k \u2192 c.rel k (add' (a.next i) (b.next j)) \u2192\n  (k = add' (a.next i) j \u2227 k = add' i (b.next j)))\n\nnotation (name := hadd.add) i `+[` a, b, c`]` j := (has_hadd.add' a b c i j)\nvariables [has_hadd a b c]\n\ninstance has_hadd_down_nat : has_hadd (complex_shape.down \u2115) (complex_shape.down \u2115) (complex_shape.down \u2115) :=\n{ add' := (+),\n  rel_h' := \u03bb i i' j,\n  begin \n    dsimp,\n    split,\n    { rintro rfl, ring, },\n    { intros h, linarith, },\n  end,\n  rel_v' := \u03bb i j j',\n  begin \n    dsimp,\n    split,\n    { rintro rfl, ring, },\n    { intros h, linarith, },\n  end,\n  add_cancel_h' := \u03bb _ _ _, add_left_inj _,\n  add_cancel_v' := \u03bb _ _ _, add_right_inj _,\n  squeeze' := \u03bb i j k h1 h2,  \n  begin \n    dsimp at h1 h2,\n    have eq0 : (complex_shape.down \u2115).next 0 = 0,\n    { dunfold complex_shape.next,\n      rw dif_neg,\n      push_neg,\n      intros j, dsimp, linarith, },\n    have eq1 : \u2200 (k : \u2115), (complex_shape.down \u2115).next k.succ = k,\n    { intros k, \n      rw complex_shape.next_eq',\n      dsimp,\n      refl, },\n    cases i; cases j,\n    { exfalso,\n      rw eq0 at *,\n      linarith, },\n    { rw [eq0, zero_add] at h2,\n      rw zero_add at h1,\n      have eq' : k = j,\n      { rw nat.succ_eq_add_one at h1,\n        linarith, },\n      subst eq',\n      rw [eq1] at h2,\n      linarith, },\n    { rw [eq0, eq1, add_zero] at h2 \u22a2,\n      subst h2,\n      rw [add_zero, nat.succ_eq_add_one] at h1,\n      linarith, },\n    { simp only [eq1] at *,\n      subst h2,\n      refine \u27e8rfl, _\u27e9,\n      rw [nat.succ_eq_add_one],\n      ring, },\n  end }\n\ninstance has_hadd_up_nat : has_hadd (complex_shape.up \u2115) (complex_shape.up \u2115) (complex_shape.up \u2115) :=\n{ add' := (+),\n  rel_h' := \u03bb i i' j,\n  begin \n    dsimp,\n    split,\n    { rintro rfl, ring, },\n    { intros h, linarith, },\n  end,\n  rel_v' := \u03bb i j j',\n  begin \n    dsimp,\n    split,\n    { rintro rfl, ring, },\n    { intros h, linarith, },\n  end,\n  add_cancel_h' := \u03bb _ _ _, add_left_inj _,\n  add_cancel_v' := \u03bb _ _ _, add_right_inj _,\n  squeeze' := \u03bb i j k h1 h2,\n  begin \n    dsimp at h1 h2,\n    have eq1 : \u2200 (k : \u2115), (complex_shape.up \u2115).next k = k + 1,\n    { intros k, \n      rw complex_shape.next_eq',\n      dsimp,\n      refl, },\n    simp only [eq1] at *,\n    split;\n    linarith,\n  end }\n\ndef complex_shape.up_fin : \u03a0 (m : \u2115), complex_shape (fin m)\n| 0 := \n{ rel := \u03bb _ _, false,\n  next_eq := \u03bb _ _ _ _ _, fin_zero_elim _,\n  prev_eq := \u03bb _ _ _ _ _, fin_zero_elim _ }\n| 1 := \n{ rel := \u03bb i j, false,\n  next_eq := \u03bb _ _ _ _ h, h.elim,\n  prev_eq := \u03bb _ _ _ _ h, h.elim }\n| (m+2) := \n{ rel := \u03bb i j, i.val < m + 1 \u2227 i + 1 = j,\n  next_eq := begin \n    rintros \u27e8i, hi1\u27e9 \u27e8j, hj1\u27e9 \u27e8k, hk1\u27e9 \u27e8hi2, hi3\u27e9 \u27e8-, hi3'\u27e9,\n    rw [\u2190 hi3, \u2190 hi3'],\n  end,\n  prev_eq := begin \n    rintros \u27e8i, hi1\u27e9 \u27e8j, hj1\u27e9 \u27e8k, hk1\u27e9 \u27e8hi2, hi3\u27e9 \u27e8hi2', hi3'\u27e9,\n    have eq1 : (\u27e8i, hi1\u27e9 + 1 : fin (m + 2)) = \u27e8i+1, by linarith\u27e9,\n    { ext, rw [fin.coe_add_eq_ite, if_neg],\n      { refl, },\n      { push_neg, dsimp, linarith, } },\n    have eq2 : (\u27e8j, hj1\u27e9 + 1 : fin (m + 2)) = \u27e8j+1, by linarith\u27e9,\n    { ext, rw [fin.coe_add_eq_ite, if_neg],\n      { refl, },\n      { push_neg, dsimp, linarith,  } },\n    \n    rw [\u2190 hi3', eq1, eq2, fin.eq_iff_veq] at hi3,\n    simp_rw nat.add_right_cancel hi3,\n  end }\n\nexample : true := trivial\n\n@[simp] lemma complex_shape.up_fin_zero_rel : (complex_shape.up_fin 0).rel = \u03bb _ _, false := rfl\n@[simp] lemma complex_shape.up_fin_one_rel : (complex_shape.up_fin 1).rel = \u03bb _ _, false := rfl \n@[simp] lemma complex_shape.up_fin_rel (m : \u2115) : \n  (complex_shape.up_fin (m + 2)).rel = \u03bb i j, i.val < m + 1 \u2227 i + 1 = j := \nrfl\n\ninstance has_hadd_fin (m n : \u2115) : \n  has_hadd (complex_shape.up_fin (m + 2)) (complex_shape.up_fin (n + 2)) (complex_shape.up_fin (m + n + 5)) :=\n{ add' := \u03bb i j, \u27e8i.1 + j.1, begin \n    have hi := i.2, have hj := j.2,\n    linarith,\n  end\u27e9,\n  rel_h' := begin \n    rintros \u27e8i\u2081, hi\u2081\u27e9 \u27e8i\u2082, hi\u2082\u27e9 \u27e8j, hj\u27e9,\n    dsimp [nat.succ_eq_add_one] at *,\n    generalize_proofs h3 h4,\n    split,\n    { rintros \u27e8H1, H2\u27e9,\n      refine \u27e8by linarith, _\u27e9,\n      sorry },\n    { rintros \u27e8H1, H2\u27e9,\n      refine \u27e8_, _\u27e9,\n      { sorry,\n        /-\n        i\u2082 = i\u2081 + 1 < m + 2 so i\u2081 < m + 1\n        -/\n      },\n      { sorry }, }\n  end,\n  rel_v' := sorry,\n  add_cancel_h' := \u03bb i\u2081 i\u2082 j, \u27e8sorry, \u03bb h, h \u25b8 rfl\u27e9,\n  add_cancel_v' := \u03bb i j\u2081 j\u2082, \u27e8sorry, \u03bb h, h \u25b8 rfl\u27e9,\n  squeeze' := \u03bb i j k h1 h2, \n  begin \n    dsimp at h1 h2,\n    sorry\n  end }\n\nvariables {a b c} \n\n@[simp] lemma d_comp_d_v (C : homological_bicomplex V a b) (j : \u03b2) (i\u2081 i\u2082 i\u2083 : \u03b1) :\n  C.d_v j i\u2081 i\u2082 \u226b C.d_v j i\u2082 i\u2083 = 0 := \nbegin \n  classical,\n  by_cases h\u2081\u2082 : a.rel i\u2081 i\u2082,\n  { refine (em (a.rel i\u2082 i\u2083)).elim (\u03bb h\u2082\u2083, C.d_comp_d_v' j i\u2081 i\u2082 i\u2083 h\u2081\u2082 h\u2082\u2083) (\u03bb h\u2082\u2083, _),\n    rw [C.shape_v j _ _ h\u2082\u2083, comp_zero], },\n  rw [C.shape_v _ _ _ h\u2081\u2082, zero_comp],\nend\n\n@[simp] lemma anticomm (C : homological_bicomplex V a b) (j\u2081 j\u2082 : \u03b2) (i\u2081 i\u2082 : \u03b1) :\n  C.d_h i\u2081 j\u2081 j\u2082 \u226b C.d_v j\u2082 i\u2081 i\u2082 +\n  C.d_v j\u2081 i\u2081 i\u2082 \u226b C.d_h i\u2082 j\u2081 j\u2082 = 0 := \nbegin \n  classical,\n  by_cases ha : a.rel i\u2081 i\u2082;\n  by_cases hb : b.rel j\u2081 j\u2082,\n  { rw C.anticomm'; assumption },\n  { rw [C.shape_h, C.shape_h, comp_zero, zero_comp]; abel <|> assumption },\n  { rw [C.shape_v, C.shape_v, comp_zero, zero_comp]; abel <|> assumption },\n  { rw [C.shape_v, C.shape_v, comp_zero, zero_comp]; abel <|> assumption },\nend\n\n@[simp] lemma d_comp_d_h (C : homological_bicomplex V a b) (i : \u03b1) (j\u2081 j\u2082 j\u2083 : \u03b2) :\n  C.d_h i j\u2081 j\u2082 \u226b C.d_h i j\u2082 j\u2083 = 0 := \nbegin \n  by_cases h\u2081\u2082 : b.rel j\u2081 j\u2082,\n  { refine (em (b.rel j\u2082 j\u2083)).elim (\u03bb h\u2082\u2083, C.d_comp_d_h' i j\u2081 j\u2082 j\u2083 h\u2081\u2082 h\u2082\u2083) (\u03bb h\u2082\u2083, _),\n    rw [C.shape_h i _ _ h\u2082\u2083, comp_zero], },\n  rw [C.shape_h _ _ _ h\u2081\u2082, zero_comp],\nend\n\nvariables [decidable_eq \u03b1] [decidable_eq \u03b2] [decidable_eq \u03b3]\n\n/--\nA general differential for the bicomplex from `(i, j)` to `(i', j')` where it acts as the horizontal \ndifferential if `i = i'` and the vertical differential if `j = j'` and zero otherwise.\n-/\ndef D (C : homological_bicomplex V a b) (i\u2081 i\u2082 : \u03b1) (j\u2081 j\u2082 : \u03b2) :\n  C.X i\u2081 j\u2081 \u27f6 C.X i\u2082 j\u2082 :=\nif H_h : i\u2081 = i\u2082 \nthen C.d_h i\u2081 j\u2081 j\u2082 \u226b eq_to_hom (by rw H_h)\nelse if H_v : j\u2081 = j\u2082\n  then C.d_v j\u2081 i\u2081 i\u2082 \u226b eq_to_hom (by rw H_v)\n  else 0\n\nlemma D_eq_of_eq_h (C : homological_bicomplex V a b) (i\u2081 i\u2082 : \u03b1) (j\u2081 j\u2082 : \u03b2)\n  (h : i\u2081 = i\u2082) :\n  C.D i\u2081 i\u2082 j\u2081 j\u2082 = C.d_h i\u2081 j\u2081 j\u2082 \u226b eq_to_hom (by rw h) :=\nby rw [D, dif_pos h]  \n\nlemma D_eq_of_eq_v (C : homological_bicomplex V a b) (ha : a.irrefl) (hb : b.irrefl)\n  (i\u2081 i\u2082 : \u03b1) (j\u2081 j\u2082 : \u03b2)\n  (h : j\u2081 = j\u2082) :\n  C.D i\u2081 i\u2082 j\u2081 j\u2082 = C.d_v j\u2081 i\u2081 i\u2082 \u226b eq_to_hom (by rw h) :=\nbegin \n  rw [D],\n  split_ifs with h1,\n  { rw [C.shape_h, C.shape_v, zero_comp, zero_comp],\n    { substs h1 h, exact ha _, },\n    { substs h1 h, exact hb _, }, },\n  { refl, },\nend\n\nlemma D_comp_D (C : homological_bicomplex V a b) (i\u2081 i\u2082 i\u2083 : \u03b1) (j\u2081 j\u2082 j\u2083 : \u03b2) :\n  C.D i\u2081 i\u2082 j\u2081 j\u2082 \u226b C.D i\u2082 i\u2083 j\u2082 j\u2083 = \n  if i\u2081 = i\u2082\n  then if i\u2082 = i\u2083 \n    then 0 \n    else if j\u2082 = j\u2083 \n      then C.d_h _ _ _ \u226b C.d_v _ _ _ \n      else 0 \n  else if i\u2082 = i\u2083 \n    then if j\u2081 = j\u2082 \n      then C.d_v _ _ _ \u226b C.d_h _ _ _ \n      else 0 \n    else 0 :=\nbegin \n  rw [D, D],\n  by_cases i\u2081 = i\u2082,\n  { subst h,\n    rw [dif_pos rfl, eq_to_hom_refl, comp_id],\n    by_cases i\u2081 = i\u2083,\n    { subst h,\n      rw [dif_pos rfl, eq_to_hom_refl, comp_id, d_comp_d_h, if_pos rfl, if_pos rfl], },\n    { rw [dif_neg h, if_pos rfl, if_neg h],\n      by_cases j\u2082 = j\u2083,\n      { subst h,\n        rw [dif_pos rfl, if_pos rfl, eq_to_hom_refl, comp_id], },\n      { rw [dif_neg h, if_neg h, comp_zero], }, }, },\n  { rw [dif_neg h, if_neg h],\n    by_cases i\u2082 = i\u2083,\n    { subst h,\n      rw [dif_pos rfl, if_pos rfl, eq_to_hom_refl, comp_id],\n      by_cases j\u2081 = j\u2082,\n      { subst h,\n        rw [dif_pos rfl, if_pos rfl, eq_to_hom_refl, comp_id], },\n      { rw [dif_neg h, zero_comp, if_neg h], }, },\n    { rw [if_neg h, dif_neg h],\n      split_ifs with h2 h3,\n      { substs h2 h3,\n        rw [eq_to_hom_refl, eq_to_hom_refl, comp_id, comp_id, d_comp_d_v], },\n      { rw comp_zero },\n      { rw zero_comp },\n      { rw zero_comp }, }, },\nend \n\n\nsection\n\nvariables {R : Type u} [comm_ring R] (C : homological_bicomplex (Module.{v} R) a b)\nvariables (c) (k k' : \u03b3) \n\nopen_locale direct_sum big_operators\n\nlemma direct_sum.to_module_comp (R : Type*) [comm_ring R] \n  {\u03b1 \u03b2 \u03b3} [decidable_eq \u03b1] [decidable_eq \u03b2]\n  (L : (\u03b1 \u2192 Type*))  [\u2200 i , add_comm_monoid (L i)] [\u2200 i , module R (L i)]\n  (M : (\u03b2 \u2192 Type*))  [\u2200 i , add_comm_monoid (M i)] [\u2200 i , module R (M i)]\n  (N : (\u03b3 \u2192 Type*))  [\u2200 i , add_comm_monoid (N i)] [\u2200 i , module R (N i)]\n  (fLM : \u03a0 (a : \u03b1) , L a \u2192\u2097[R] \u2a01 j, M j)\n  (fMN : \u03a0 (b : \u03b2), M b \u2192\u2097[R] \u2a01 k, N k)\n  (fLN : \u03a0 (a : \u03b1) , L a \u2192\u2097[R] \u2a01 k, N k)\n  (H : \u2200 (i : \u03b1), (direct_sum.to_module _ _ _ fMN).comp (fLM i) = fLN i) :\n  (direct_sum.to_module _ _ _ fMN : \n      (\u2a01 i, M i) \u2192\u2097[R] (\u2a01 i, N i)).comp \n    (direct_sum.to_module _ _ _ fLM : \n      (\u2a01 i, L i) \u2192\u2097[R] (\u2a01 i, M i)) = \n  direct_sum.to_module _ _ _ fLN :=\nbegin \n  classical,\n  apply direct_sum.linear_map_ext,\n  intros i,\n  ext1 y,\n  simp only [linear_map.comp_apply, direct_sum.to_module_lof],\n  specialize H i,\n  rw \u2190 H,\n  refl,\nend\n\nsection\n\nvariables (a b c)\n\n/--\nThe diagonal of `k : \u03b3` with respect to shapes `a`, `b` and `c` is pairs `(i, j) \u2208 a \u00d7 b` such that\n`i +[a, b, c] j = k`.\n-/\n@[ext, nolint has_nonempty_instance]\nstructure diagonal (k : \u03b3) :=\n(fst : \u03b1) (snd : \u03b2) (add_eq : (fst +[a, b, c] snd) = k)\n\nend\n\nvariables {a b}\n/--\nThe total complex at `k`-th position is `\u2a01_{i + j = k} C_ij`.\n-/\ndef total_at (j : \u03b3) : Module R :=\nModule.of.{v} R $ \u2a01 (p : diagonal a b c j), C.X p.fst p.snd\n\n\n/--\nThe map `C_mn \u27f6 \u2a01_{i + j = k} C_ij` where `m + n = k`\n-/\n@[reducible]\ndef total_at_embed (k : \u03b3) (p : diagonal a b c k) [\u2200 k, decidable_eq $ diagonal a b c k] :\n  C.X p.fst p.snd \u2192\u2097[R] C.total_at c k :=\ndirect_sum.lof R _ _ p\n\nlemma total_at_embed_comp_D_congr (k : \u03b3) (p p' : diagonal a b c k) (EQ : p = p') (M : Module.{v} R)\n  (f : \u03a0 (p : diagonal a b c k), (M \u2192\u2097[R] C.X p.1 p.2)) [\u2200 k, decidable_eq $ diagonal a b c k] :\n  (total_at_embed c C k p).comp (f p) = \n  (total_at_embed c C k p').comp (f p') := \nbegin \n  rcases \u27e8p, p'\u27e9 with \u27e8\u27e8i, j, h\u27e9, \u27e8i', j', h'\u27e9\u27e9,\n  rw diagonal.ext_iff at EQ,\n  dsimp only at EQ,\n  cases EQ with EQ1 EQ2,\n  substs EQ1 EQ2,\nend\n\n/--\nConsidering `C_ij \u27f6 C_mn`, only if `i = m` or `j = n` will `D` be potentially nonzero.\n-/\n@[reducible]\ndef diagonal.potentially_nonzero \u2983k : \u03b3\u2984 (p : diagonal a b c k) (k') : set (diagonal a b c k') :=\n{p' | p'.1 = p.1} \u222a {p' | p'.2 = p.2}\n\nlemma diagonal.subsingleton_of_fst_eq \u2983k : \u03b3\u2984 (p : diagonal a b c k) (k' : \u03b3) :\n  {p' : diagonal a b c k' | p'.1 = p.1}.subsingleton :=\nbegin \n  rintros \u27e8x1, y1, eq1\u27e9 hx1 \u27e8x2, y2, eq2\u27e9 hx2,\n  dsimp at hx1 hx2,\n  substs hx1 hx2,\n  ext,\n  { refl },\n  { rw [\u2190 eq1, has_hadd.add_cancel_v'] at eq2,\n    subst eq2, },\nend\n\nlemma diagonal.subsingleton_of_snd_eq \u2983k : \u03b3\u2984 (p : diagonal a b c k) (k' : \u03b3) :\n  {p' : diagonal a b c k' | p'.2 = p.2}.subsingleton :=\nbegin \n  rintros \u27e8x1, y1, eq1\u27e9 hx1 \u27e8x2, y2, eq2\u27e9 hx2,\n  dsimp at hx1 hx2,\n  substs hx1 hx2,\n  ext,\n  { rw [\u2190 eq1, has_hadd.add_cancel_h'] at eq2,\n    subst eq2, },\n  { refl },\nend\n\nlemma diagonal.potentially_nonzero_finite \u2983k : \u03b3\u2984 (p : diagonal a b c k) (k' : \u03b3) :\n  (p.potentially_nonzero c k').finite :=\nbegin\n  refine set.finite.union (set.subsingleton.finite _) (set.subsingleton.finite _),\n  { exact p.subsingleton_of_fst_eq c k' },\n  { exact p.subsingleton_of_snd_eq c k' },\nend\n\n/--\n`\u2a01_{i + j = k} C_ij \u27f6 \u2a01_{i + j = k'} C_ij` is defined to be the linear map whose `(i, j)`-th\nprojection `C_ij \u27f6 \u2a01_{m + n = k'} C_mn` is defined to be the sum of all `C_ij \u27f6 C_mn \u27f6 \u2a01`.\n-/\n@[reducible]\ndef total_d [\u2200 k, decidable_eq $ diagonal a b c k] : C.total_at c k \u27f6 C.total_at c k' :=\ndirect_sum.to_module R _ _ $ \u03bb p, \n  \u2211 (p' : diagonal a b c k') in (p.potentially_nonzero_finite c k').to_finset, \n    (C.total_at_embed c k' p').comp (C.D p.1 p'.1 p.2 p'.2)\n\ninstance t1 {k k'} (p : diagonal a b c k) : fintype {p' : diagonal a b c k' | p'.fst = p.fst} := \n(p.subsingleton_of_fst_eq c k').finite.fintype\n\ninstance t2 {k k'} (p : diagonal a b c k) : fintype {p' : diagonal a b c k' | p'.snd = p.snd} := \n(p.subsingleton_of_snd_eq c k').finite.fintype\n\nlemma sum_potentially_nonzero_finite_eq_union (c_ir : c.irrefl) (hc : c.rel k k') \n  {M : Type*} [add_comm_monoid M]\n  (p : diagonal a b c k) (f : diagonal a b c k' \u2192 M) :\n  \u2211 (p' : diagonal a b c k') in (p.potentially_nonzero_finite c k').to_finset, f p' = \n  (\u2211 p' in {p' : diagonal a b c k' | p'.fst = p.fst}.to_finset, f p') +\n  (\u2211 p' in {p' : diagonal a b c k' | p'.snd = p.snd}.to_finset, f p') := \nbegin\n  classical,\n  haveI : fintype {p' : diagonal a b c k' | p'.fst = p.fst},\n  { exact (p.subsingleton_of_fst_eq c k').finite.fintype, },\n  haveI : fintype {p' : diagonal a b c k' | p'.snd = p.snd},\n  { exact (p.subsingleton_of_snd_eq c k').finite.fintype, },\n\n  transitivity \u2211 (p' : diagonal a b c k') in \n    ({p' | p'.1 = p.1} : set (diagonal a b c k')).to_finset \u222a {p' : diagonal a b c k' | p'.2 = p.2}.to_finset, \n    f p',\n  { refine finset.sum_congr _ (\u03bb _ _, rfl),\n    ext1, simp only [set.finite.mem_to_finset, set.mem_union, finset.mem_union, set.mem_to_finset], },\n  transitivity \u2211 (p' : diagonal a b c k') in\n    ({p' | p'.1 = p.1} : set (diagonal a b c k')).to_finset.disj_union \n      ({p' : diagonal a b c k' | p'.2 = p.2}.to_finset) _, f p',\n  work_on_goal 2 {\n    rw finset.disjoint_iff_ne,\n    rintros \u27e8i1, j1, h1\u27e9 hi1 \u27e8i2, j2, h2\u27e9 hi2 H,\n    simp only [set.mem_to_finset, set.mem_set_of_eq] at hi1 hi2,\n    rw [diagonal.ext_iff] at H,\n    dsimp only at H,\n    rcases H with \u27e8H1, H2\u27e9,\n    substs H1 H2,\n    rw [hi1, hi2, p.add_eq] at h1,\n    exact c_ir.ne hc h1,\n  },\n  { refine finset.sum_congr _ (\u03bb _ _, rfl),\n    exact (finset.disj_union_eq_union _ _ _).symm, },\n  rw finset.sum_disj_union,\n  congr,\nend\n\nlemma total_d_comp_d_eq_double_sum (k\u2081 k\u2082 k\u2083 : \u03b3) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, \n    \u2211 (p\u2082 : diagonal a b c k\u2082) in (p\u2081.potentially_nonzero_finite c k\u2082).to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in (p\u2082.potentially_nonzero_finite c k\u2083).to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2))) :=\nbegin\n  rw [total_d, total_d],\n  refine direct_sum.to_module_comp R _ _ _ _ _ _ _,\n  intros p\u2081,\n  rw [linear_map.comp_sum],\n  refine finset.sum_congr rfl _,\n  intros p\u2082 hp\u2082,\n  simp only [set.finite.mem_to_finset, set.mem_union, set.mem_set_of_eq] at hp\u2082,\n  ext1 x,\n  simp only [linear_map.comp_apply, direct_sum.to_module_lof, linear_map.sum_apply],\nend\n\nlemma total_d_comp_d_eq_4_sums (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, \n    (\u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2))) +\n    (\u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2))) +\n    (\u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2))) +\n    (\u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)))) :=\nbegin\n  classical,\n  rw total_d_comp_d_eq_double_sum c C _ _ _,\n  ext p\u2081 x : 2,\n  simp only [direct_sum.to_module_lof, linear_map.comp_apply, linear_map.sum_apply, \n    linear_map.zero_apply, direct_sum.zero_apply],\n  rw sum_potentially_nonzero_finite_eq_union c k\u2081 k\u2082 c_ir hc12 p\u2081 _,\n  simp only [linear_map.add_apply, linear_map.sum_apply],\n  rw [add_assoc],\n  congr' 1,\n  { rw [\u2190 finset.sum_add_distrib],\n    refine finset.sum_congr rfl _,\n    intros p\u2082 hp\u2082,\n    rw sum_potentially_nonzero_finite_eq_union c k\u2082 k\u2083 c_ir hc23 p\u2082 _,\n    congr, },\n  { rw [\u2190 finset.sum_add_distrib],\n    refine finset.sum_congr rfl _,\n    intros p\u2082 hp\u2082,\n    rw sum_potentially_nonzero_finite_eq_union c k\u2082 k\u2083 c_ir hc23 p\u2082 _,\n    congr, },\nend\n\nlemma total_d_comp_d_eq_4_sums.fourth_zero (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] :\n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) = 0 := \nbegin \n  apply finset.sum_eq_zero,\n  intros p\u2082 hp\u2082,\n  apply finset.sum_eq_zero,\n  intros p\u2083 hp\u2083,\n  simp only [set.mem_to_finset, set.mem_set_of_eq] at hp\u2082 hp\u2083,\n  suffices :  C.D p\u2081.fst p\u2082.fst p\u2081.snd p\u2082.snd \u226b C.D p\u2082.fst p\u2083.fst p\u2082.snd p\u2083.snd = 0,\n  { change linear_map.comp _ _ = 0 at this,\n    rw [this, linear_map.comp_zero], },\n  rw [D_comp_D, if_neg],\n  work_on_goal 2 \n  { intro rid,\n    have EQ1 := p\u2081.add_eq,\n    have EQ2 := p\u2082.add_eq,\n    rw [\u2190 rid, hp\u2082, EQ1] at EQ2,\n    exact c_ir.ne hc12 EQ2, },\n  rw [if_neg],\n  { intro rid,\n    have EQ2 := p\u2082.add_eq,\n    have EQ3 := p\u2083.add_eq,\n    rw [\u2190 rid, hp\u2083, EQ2] at EQ3,\n    exact c_ir.ne hc23 EQ3, },\nend\n\nlemma total_d_comp_d_eq_4_sums.fst_zero (k\u2081 k\u2082 k\u2083 : \u03b3) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] :\n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) = 0 := \nbegin \n  apply finset.sum_eq_zero,\n  intros p\u2082 hp\u2082,\n  apply finset.sum_eq_zero,\n  intros p\u2083 hp\u2083,\n  simp only [set.mem_to_finset, set.mem_set_of_eq] at hp\u2082 hp\u2083,\n  suffices :  C.D p\u2081.fst p\u2082.fst p\u2081.snd p\u2082.snd \u226b C.D p\u2082.fst p\u2083.fst p\u2082.snd p\u2083.snd = 0,\n  { change linear_map.comp _ _ = 0 at this,\n    rw [this, linear_map.comp_zero], },\n  rw [D_comp_D, if_pos hp\u2083.symm, if_pos hp\u2082.symm],\nend\n\nlemma total_d_comp_d_eq_2_sums (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, \n    (\u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2))) +\n    (\u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n      \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n        (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)))) :=\nbegin\n  classical,\n  rw total_d_comp_d_eq_4_sums c C _ _ _ c_ir hc12 hc23,\n  congr' 1,\n  ext p\u2081 : 1,\n  rw total_d_comp_d_eq_4_sums.fst_zero;\n  try { assumption },\n  rw [zero_add, total_d_comp_d_eq_4_sums.fourth_zero];\n  try { assumption },\n  rw [add_zero],\nend\n\nlemma diagonal.subsingleton_of_fst_eq_and_snd_eq (i : \u03b1) (j : \u03b2) : \n  set.subsingleton {p : diagonal a b c k | p.1 = i \u2227 p.2 = j} :=\nbegin \n  rintros \u27e8i1, j1, h1\u27e9 \u27e8rfl, rfl\u27e9 \u27e8i2, j2, h2\u27e9 \u27e8h21, h22\u27e9,\n  dsimp at h21 h22,\n  substs h21 h22,\nend\n\ninstance diagonal.fintype_of_fst_eq_and_snd_eq (i : \u03b1) (j : \u03b2) :\n  fintype {p : diagonal a b c k | p.1 = i \u2227 p.2 = j} :=\nbegin \n  haveI : subsingleton {p : diagonal a b c k | p.fst = i \u2227 p.snd = j},\n  { fconstructor, \n    rintros \u27e8p1, h1\u27e9 \u27e8p2, h2\u27e9, \n    ext1,\n    exact diagonal.subsingleton_of_fst_eq_and_snd_eq c k i j h1 h2, },\n  exact fintype.of_finite _,\nend\n\nlemma diagonal.fixed_of_fst_eq (p : diagonal a b c k) (hc : c.rel k k') :\n  {p' : diagonal a b c k' | p'.1 = p.1} =\n  {p' : diagonal a b c k' | p'.1 = p.1 \u2227 p'.2 = b.next p.2} := \nbegin \n  rcases p with \u27e8i, j, h\u27e9,\n  ext1 \u27e8i', j', h'\u27e9,\n  dsimp,\n  split,\n  { rintro rfl,\n    refine \u27e8rfl, _\u27e9,\n    rw [\u2190 h, \u2190 h', \u2190has_hadd.rel_v'] at hc,\n    exact (b.next_eq' hc).symm, },\n  { rintro \u27e8rfl, -\u27e9, refl, },\nend\n\nlemma diagonal.fixed_of_snd_eq (p : diagonal a b c k) (hc : c.rel k k') :\n  {p' : diagonal a b c k' | p'.2 = p.2} =\n  {p' : diagonal a b c k' | p'.1 = a.next p.1 \u2227 p'.2 = p.2} := \nbegin \n  rcases p with \u27e8i, j, h\u27e9,\n  ext1 \u27e8i', j', h'\u27e9,\n  dsimp,\n  split,\n  { rintro rfl,\n    refine \u27e8_, rfl\u27e9,\n    rw [\u2190 h, \u2190 h', \u2190has_hadd.rel_h'] at hc,\n    exact (a.next_eq' hc).symm, },\n  { rintro \u27e8-, rfl\u27e9, refl, },\nend\n\nlemma total_d_comp_d_eq_2_sums.fst_eq1 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) := \nbegin \n  classical,\n  refine finset.sum_congr _ (\u03bb p\u2082 hp\u2082, finset.sum_congr _ (\u03bb _ _, rfl)),\n  { rw set.to_finset_inj,\n    rw diagonal.fixed_of_fst_eq,\n    assumption, },\n  { rw set.to_finset_inj,\n    rw diagonal.fixed_of_snd_eq,\n    work_on_goal 2 { assumption, },\n    simp only [set.mem_to_finset, set.mem_set_of_eq] at hp\u2082,\n    rw [hp\u2082.1, hp\u2082.2], }\nend\n\n\nlemma total_d_comp_d_eq_2_sums.snd_eq1 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = p\u2081.snd}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) := \nbegin \n  classical,\n  refine finset.sum_congr _ (\u03bb p\u2082 hp\u2082, finset.sum_congr _ (\u03bb _ _, rfl)),\n  { rw set.to_finset_inj,\n    rw diagonal.fixed_of_snd_eq,\n    assumption, },\n  { rw set.to_finset_inj,\n    rw diagonal.fixed_of_fst_eq,\n    work_on_goal 2 { assumption, },\n    simp only [set.mem_to_finset, set.mem_set_of_eq] at hp\u2082,\n    rw [hp\u2082.1, hp\u2082.2], }\nend\n\nlemma total_d_comp_d_eq_2_sums.fst_eq2 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset,\n    \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) := \nbegin \n  rw total_d_comp_d_eq_2_sums.fst_eq1;\n  try { assumption },\n  exact finset.sum_comm,\nend\n\n\nlemma total_d_comp_d_eq_2_sums.snd_eq2 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset,\n    \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = p\u2081.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) := \nbegin \n  rw total_d_comp_d_eq_2_sums.snd_eq1;\n  try { assumption },\n  exact finset.sum_comm,\nend\n\nlemma total_d_comp_d_eq_2_sums.fst_eq3 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n    \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset,\n      (C.total_at_embed c _ \u27e8a.next p\u2081.fst, b.next p\u2081.snd, begin \n        have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n        rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n      end\u27e9).comp ((C.D p\u2082.1 (a.next p\u2081.1) p\u2082.2 (b.next p\u2081.2)).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) := \nbegin \n  rw total_d_comp_d_eq_2_sums.fst_eq2;\n  try { assumption },\n  rw \u2190 finset.sum_attach,\n  refine finset.sum_congr rfl _,\n  rintros \u27e8p\u2083, hp3\u27e9 -,\n  refine finset.sum_congr rfl _,\n  rintros p\u2082 hp2,\n  simp only [set.mem_to_finset, set.mem_set_of_eq, finset.mem_attach] at hp3 hp2,\n  rw [subtype.coe_mk],\n  apply total_at_embed_comp_D_congr,\n  ext, \n  { exact hp3.1 }, \n  { exact hp3.2 }\nend\n\n\nlemma total_d_comp_d_eq_2_sums.snd_eq3 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n    \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = p\u2081.snd}.to_finset,\n      (C.total_at_embed c _ \u27e8a.next p\u2081.1, b.next p\u2081.2, begin \n        have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n        rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n      end\u27e9).comp ((C.D p\u2082.1 (a.next p\u2081.1) p\u2082.2 (b.next p\u2081.2)).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) := \nbegin \n  rw total_d_comp_d_eq_2_sums.snd_eq2;\n  try { assumption },\n  rw \u2190 finset.sum_attach,\n  refine finset.sum_congr rfl _,\n  rintros \u27e8p\u2083, hp3\u27e9 -,\n  refine finset.sum_congr rfl _,\n  rintros p\u2082 hp2,\n  simp only [set.mem_to_finset, set.mem_set_of_eq, finset.mem_attach] at hp3 hp2,\n  rw [subtype.coe_mk],\n  apply total_at_embed_comp_D_congr,\n  ext, \n  { exact hp3.1 }, \n  { exact hp3.2 }\nend\n\nlemma total_d_comp_d_eq_2_sums.fst_eq4 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.snd = p\u2082.snd}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n    (C.total_at_embed c _ \u27e8a.next p\u2081.fst, b.next p\u2081.snd, begin \n      have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n      rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n    end\u27e9).comp ((C.D p\u2081.1 (a.next p\u2081.1) (b.next p\u2081.2) (b.next p\u2081.2)).comp (C.D p\u2081.1 p\u2081.1 p\u2081.2 (b.next p\u2081.2))) := \nbegin\n  rw total_d_comp_d_eq_2_sums.fst_eq3;\n  try { assumption },\n  refine finset.sum_congr rfl _,\n  rintros \u27e8p\u2083, hp3\u27e9 -,\n  simp only [set.mem_to_finset, set.mem_set_of_eq] at hp3,\n  have add_eq1 : (p\u2081.fst+[a,b,c]b.next p\u2081.snd) = k\u2082,\n  { have add_eq3 := p\u2083.add_eq,\n    rw [hp3.1, hp3.2] at add_eq3,\n    rw \u2190 add_eq3 at hc23,\n    rw \u2190 p\u2081.add_eq at hc12, \n    exact (has_hadd.squeeze' _ _ _ hc12 hc23).2.symm,\n  },\n  have EQ : {p' : diagonal a b c k\u2082 | p'.fst = p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset =\n    {\u27e8p\u2081.1, b.next p\u2081.2, add_eq1\u27e9},\n  { ext1 p\u2082,\n    simp only [set.mem_to_finset, set.mem_set_of_eq, finset.mem_singleton],\n    split,\n    { rintros \u27e8h1, h2\u27e9, simp_rw [\u2190h1, \u2190h2], ext, { refl, }, { refl, } },\n    { intros h, rw diagonal.ext_iff at h, exact \u27e8h.1, h.2\u27e9, }, },\n  rw [EQ, finset.sum_singleton],\nend\n\nlemma total_d_comp_d_eq_2_sums.snd_eq4 (k\u2081 k\u2082 k\u2083 : \u03b3)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) (p\u2081 : diagonal a b c k\u2081) \n  [\u2200 k, decidable_eq $ diagonal a b c k] : \n  \u2211 (p\u2082 : diagonal a b c k\u2082) in {p' : diagonal a b c k\u2082 | p'.snd = p\u2081.snd}.to_finset,\n    \u2211 (p\u2083 : diagonal a b c k\u2083) in {p' : diagonal a b c k\u2083 | p'.fst = p\u2082.fst}.to_finset,\n      (C.total_at_embed c _ p\u2083).comp ((C.D p\u2082.1 p\u2083.1 p\u2082.2 p\u2083.2).comp (C.D p\u2081.1 p\u2082.1 p\u2081.2 p\u2082.2)) =\n  \u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n    (C.total_at_embed c _ \u27e8a.next p\u2081.1, b.next p\u2081.2, begin \n      have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n      rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n    end\u27e9).comp ((C.D (a.next p\u2081.1) (a.next p\u2081.1) p\u2081.2 (b.next p\u2081.2)).comp (C.D p\u2081.1 (a.next p\u2081.1) p\u2081.2 p\u2081.2)) := \nbegin\n  rw total_d_comp_d_eq_2_sums.snd_eq3;\n  try { assumption },\n  refine finset.sum_congr rfl _,\n  rintros \u27e8p\u2083, hp3\u27e9 -,\n  simp only [set.mem_to_finset, set.mem_set_of_eq] at hp3,\n  have add_eq1 : (a.next p\u2081.fst +[a,b,c] p\u2081.snd) = k\u2082,\n  { have add_eq3 := p\u2083.add_eq,\n    rw [hp3.1, hp3.2] at add_eq3,\n    rw \u2190 add_eq3 at hc23,\n    rw \u2190 p\u2081.add_eq at hc12, \n    exact (has_hadd.squeeze' _ _ _ hc12 hc23).1.symm,\n  },\n  have EQ : {p' : diagonal a b c k\u2082 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = p\u2081.snd}.to_finset =\n    {\u27e8a.next p\u2081.1, p\u2081.2, add_eq1\u27e9},\n  { ext1 p\u2082,\n    simp only [set.mem_to_finset, set.mem_set_of_eq, finset.mem_singleton],\n    split,\n    { rintros \u27e8h1, h2\u27e9, simp_rw [\u2190h1, \u2190h2], ext, { refl, }, { refl, } },\n    { intros h, rw diagonal.ext_iff at h, exact \u27e8h.1, h.2\u27e9, }, },\n  rw [EQ, finset.sum_singleton],\nend\n\nlemma total_d_comp_d_eq_2_sums' (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, \n    (\u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n      (C.total_at_embed c _ \u27e8a.next p\u2081.fst, b.next p\u2081.snd, begin \n        have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n        rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n      end\u27e9).comp ((C.D p\u2081.1 (a.next p\u2081.1) (b.next p\u2081.2) (b.next p\u2081.2)).comp (C.D p\u2081.1 p\u2081.1 p\u2081.2 (b.next p\u2081.2)))) +\n    (\u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n      (C.total_at_embed c _ \u27e8a.next p\u2081.1, b.next p\u2081.2, begin \n        have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n        rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n      end\u27e9).comp ((C.D (a.next p\u2081.1) (a.next p\u2081.1) p\u2081.2 (b.next p\u2081.2)).comp (C.D p\u2081.1 (a.next p\u2081.1) p\u2081.2 p\u2081.2)))) :=\nbegin \n  rw total_d_comp_d_eq_2_sums;\n  try { assumption },\n  congr' 1,\n  ext p\u2081 : 1,\n  congr' 1,\n  { rw [total_d_comp_d_eq_2_sums.fst_eq4];\n    assumption },\n  { rw [total_d_comp_d_eq_2_sums.snd_eq4];\n    assumption },\nend\n\n\nlemma total_d_comp_d_eq_single_sum (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, \n    (\u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n      ((C.total_at_embed c _ \u27e8a.next p\u2081.fst, b.next p\u2081.snd, begin \n        have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n        rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n      end\u27e9).comp ((C.D p\u2081.1 (a.next p\u2081.1) (b.next p\u2081.2) (b.next p\u2081.2)).comp (C.D p\u2081.1 p\u2081.1 p\u2081.2 (b.next p\u2081.2))) +\n      (C.total_at_embed c _ \u27e8a.next p\u2081.1, b.next p\u2081.2, begin \n          have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n          rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n        end\u27e9).comp ((C.D (a.next p\u2081.1) (a.next p\u2081.1) p\u2081.2 (b.next p\u2081.2)).comp (C.D p\u2081.1 (a.next p\u2081.1) p\u2081.2 p\u2081.2))))) :=\nbegin \n  rw total_d_comp_d_eq_2_sums';\n  try { assumption },\n  congr' 1,\n  ext1 p\u2081,\n  rw finset.sum_add_distrib,\nend\n\n\nlemma total_d_comp_d_eq_single_sum' (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, \n    (\u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n      ((C.total_at_embed c _ \u27e8a.next p\u2081.fst, b.next p\u2081.snd, begin \n        have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n        rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n      end\u27e9).comp \n        (((C.D p\u2081.1 (a.next p\u2081.1) (b.next p\u2081.2) (b.next p\u2081.2)).comp (C.D p\u2081.1 p\u2081.1 p\u2081.2 (b.next p\u2081.2))) + \n         ((C.D (a.next p\u2081.1) (a.next p\u2081.1) p\u2081.2 (b.next p\u2081.2)).comp (C.D p\u2081.1 (a.next p\u2081.1) p\u2081.2 p\u2081.2)))))) :=\nbegin \n  rw total_d_comp_d_eq_single_sum;\n  try { assumption },\n  congr' 1,\n  ext1 p\u2081,\n  refine finset.sum_congr rfl _,\n  rintros \u27e8p\u2082, hp2\u27e9 -,\n  rw linear_map.comp_add,\nend\n\n\nlemma total_d_comp_d_eq_single_sum'' (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, \n    (\u2211 p\u2083 in {p' : diagonal a b c k\u2083 | p'.fst = a.next p\u2081.fst \u2227 p'.snd = b.next p\u2081.snd}.to_finset.attach,\n      ((C.total_at_embed c _ \u27e8a.next p\u2081.fst, b.next p\u2081.snd, begin \n        have h3 := p\u2083.2, simp only [set.mem_to_finset, set.mem_set_of_eq] at h3,\n        rw [\u2190h3.1], simp_rw [\u2190h3.2], exact p\u2083.1.add_eq,\n      end\u27e9).comp \n        (((C.d_v (b.next p\u2081.2) p\u2081.1 (a.next p\u2081.1)).comp (C.d_h p\u2081.1 p\u2081.2 (b.next p\u2081.2))) + \n         ((C.d_h (a.next p\u2081.1) p\u2081.2 (b.next p\u2081.2)).comp (C.d_v p\u2081.2 p\u2081.1 (a.next p\u2081.1))))))) :=\nbegin \n  rw total_d_comp_d_eq_single_sum';\n  try { assumption },\n  congr' 1,\n  ext1 p\u2081,\n  refine finset.sum_congr rfl _,\n  rintros \u27e8p\u2082, hp2\u27e9 -,\n  simp only [set.mem_to_finset, set.mem_set_of_eq] at hp2,\n  have hc12' := hc12,\n  have hc23' := hc23,\n  rw [\u2190 p\u2082.add_eq, hp2.1, hp2.2] at hc23,\n  rw [\u2190 p\u2081.add_eq] at hc12,\n  have hk2 := has_hadd.squeeze' _ _ _ hc12 hc23,\n  have h1 : p\u2081.fst \u2260 a.next p\u2081.fst,\n  { intro rid,\n    rw [\u2190 rid] at hk2,\n    simp_rw \u2190 p\u2081.add_eq at hk2,\n    suffices : k\u2082 = k\u2081,\n    { rw this at hc12',\n      refine c_ir.ne hc12' rfl, },\n    rw [hk2.1, p\u2081.add_eq], },\n  congr' 3;\n  rw [D],\n  { rw [dif_neg h1, dif_pos rfl, eq_to_hom_refl, comp_id], },\n  { rw [dif_pos rfl, eq_to_hom_refl, comp_id], },\n  { rw [dif_pos rfl, eq_to_hom_refl, comp_id], },\n  { rw [dif_neg h1, dif_pos rfl, eq_to_hom_refl, comp_id], },\nend\n\nlemma total_d_comp_d_eq_0' (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = \n  direct_sum.to_module _ _ _ (\u03bb p\u2081, 0) :=\nbegin \n  rw total_d_comp_d_eq_single_sum'';\n  try { assumption },\n  congr' 1,\n  ext p\u2081 : 1,\n  refine finset.sum_eq_zero _,\n  rintros \u27e8p\u2083, hp3\u27e9 -,\n  convert linear_map.comp_zero _,\n  work_on_goal 2 { exact ring_hom_comp_triple.ids, },\n  change (C.d_h p\u2081.fst p\u2081.snd (b.next p\u2081.snd) \u226b C.d_v (b.next p\u2081.snd) p\u2081.fst (a.next p\u2081.fst)) + \n    (C.d_v p\u2081.snd p\u2081.fst (a.next p\u2081.fst) \u226b C.d_h (a.next p\u2081.fst) p\u2081.snd (b.next p\u2081.snd)) = 0,\n  exact C.anticomm _ _ _ _,\nend\n\n\nlemma total_d_comp_d' (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2082 k\u2083).comp (C.total_d c k\u2081 k\u2082) = 0 :=\nbegin \n  rw total_d_comp_d_eq_0';\n  try { assumption },\n  apply direct_sum.linear_map_ext,\n  intros p\u2081,\n  rw [linear_map.zero_comp],\n  ext1 x,\n  simp only [linear_map.comp_apply, linear_map.zero_apply, direct_sum.to_module_lof],\nend\n\nlemma total_d_comp_d (k\u2081 k\u2082 k\u2083 : \u03b3) (c_ir : c.irrefl)\n  (hc12 : c.rel k\u2081 k\u2082) (hc23 : c.rel k\u2082 k\u2083) [\u2200 k, decidable_eq $ diagonal a b c k] : \n  (C.total_d c k\u2081 k\u2082) \u226b (C.total_d c k\u2082 k\u2083) = 0 :=\nC.total_d_comp_d' c k\u2081 k\u2082 k\u2083 c_ir hc12 hc23\n\nlemma total_d_shape' (a_ir : a.irrefl) (b_ir : b.irrefl) (hc : \u00ac c.rel k k') [\u03a0 (k : \u03b3), decidable_eq (diagonal a b c k)] : \n  C.total_d c k k' = 0 :=\nbegin \n  rw [total_d],\n  apply direct_sum.linear_map_ext,\n  intros p,\n  ext1 x,\n  simp only [linear_map.comp_apply, linear_map.zero_apply, direct_sum.to_module_lof, \n    linear_map.zero_comp, linear_map.sum_apply],\n  refine finset.sum_eq_zero (\u03bb p' hp', _),\n  simp only [set.finite.mem_to_finset, set.mem_union, set.mem_set_of_eq] at hp',\n  suffices : C.D p.fst p'.fst p.snd p'.snd = 0,\n  { rw [this, linear_map.zero_apply, map_zero] },\n  rcases hp' with (hp'|hp'),\n  { rw [D, dif_pos hp'.symm, C.shape_h, zero_comp],\n    contrapose! hc,\n    rwa [\u2190 p.add_eq, \u2190 p'.add_eq, hp', \u2190 has_hadd.rel_v'], },\n  { rw [D_eq_of_eq_v C a_ir b_ir _ _ _ _ hp'.symm, C.shape_v, zero_comp],\n    { contrapose! hc,\n      rwa [\u2190 p.add_eq, \u2190 p'.add_eq, hp', \u2190 has_hadd.rel_h'], }, },\nend\n\n/--\nThe total complex associated with a double complex by taking direct sums.\n-/\n@[simps]\ndef total_complex (a_ir : a.irrefl) (b_ir : b.irrefl) (c_ir : c.irrefl) \n  [\u03a0 (k : \u03b3), decidable_eq (diagonal a b c k)] : \n  homological_complex (Module R) c :=\n{ X := C.total_at c,\n  d := \u03bb i j, C.total_d c i j,\n  shape' := \u03bb i j hc, C.total_d_shape' c i j a_ir b_ir hc,\n  d_comp_d' := \u03bb i j k h1 h2, C.total_d_comp_d c i j k c_ir h1 h2 }\n\n\nend\n\nend homological_bicomplex\n", "meta": {"author": "jjaassoonn", "repo": "flat", "sha": "bab2f5c18fdee0042680c31b0350c69d241e9a82", "save_path": "github-repos/lean/jjaassoonn-flat", "path": "github-repos/lean/jjaassoonn-flat/flat-bab2f5c18fdee0042680c31b0350c69d241e9a82/src/bicomplex3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126078, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7246422777460179}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.free_module.finite.basic\nimport linear_algebra.matrix.charpoly.coeff\nimport field_theory.minpoly\n\n/-!\n\n# Characteristic polynomial\n\nWe define the characteristic polynomial of `f : M \u2192\u2097[R] M`, where `M` is a finite and\nfree `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f`\nin any basis is in `linear_algebra/charpoly/to_matrix`.\n\n## Main definition\n\n* `linear_map.charpoly f` : the characteristic polynomial of `f : M \u2192\u2097[R] M`.\n\n-/\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} [comm_ring R] [nontrivial R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M] (f : M \u2192\u2097[R] M)\n\nopen_locale classical matrix polynomial\n\nnoncomputable theory\n\n\nopen module.free polynomial matrix\n\nnamespace linear_map\n\nsection basic\n\n/-- The characteristic polynomial of `f : M \u2192\u2097[R] M`. -/\ndef charpoly : R[X] :=\n(to_matrix (choose_basis R M) (choose_basis R M) f).charpoly\n\n\n\nend basic\n\nsection coeff\n\nlemma charpoly_monic : f.charpoly.monic := charpoly_monic _\n\nend coeff\n\nsection cayley_hamilton\n\n/-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied\nto the linear map itself, is zero.\n\nSee `matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/\nlemma aeval_self_charpoly : aeval f f.charpoly = 0 :=\nbegin\n  apply (linear_equiv.map_eq_zero_iff (alg_equiv_matrix _).to_linear_equiv).1,\n  rw [alg_equiv.to_linear_equiv_apply, \u2190 alg_equiv.coe_alg_hom,\n    \u2190 polynomial.aeval_alg_hom_apply _ _ _, charpoly_def],\n  exact aeval_self_charpoly _,\nend\n\nlemma is_integral : is_integral R f := \u27e8f.charpoly, \u27e8charpoly_monic f, aeval_self_charpoly f\u27e9\u27e9\n\nlemma minpoly_dvd_charpoly {K : Type u} {M : Type v} [field K] [add_comm_group M] [module K M]\n  [finite_dimensional K M] (f : M \u2192\u2097[K] M) : minpoly K f \u2223 f.charpoly :=\nminpoly.dvd _ _ (aeval_self_charpoly f)\n\n/-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %\u2098 f.charpoly`; that is,\n`p` is equivalent to a polynomial with degree less than the dimension of the module. -/\nlemma aeval_eq_aeval_mod_charpoly (p : R[X]) : aeval f p = aeval f (p %\u2098 f.charpoly) :=\n(aeval_mod_by_monic_eq_self_of_root f.charpoly_monic f.aeval_self_charpoly).symm\n\n/-- Any endomorphism power can be computed as the sum of endomorphism powers less than the\ndimension of the module. -/\nlemma pow_eq_aeval_mod_charpoly (k : \u2115) : f^k = aeval f (X^k %\u2098 f.charpoly) :=\nby rw [\u2190aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]\n\nvariable {f}\n\nlemma minpoly_coeff_zero_of_injective (hf : function.injective f) : (minpoly R f).coeff 0 \u2260 0 :=\nbegin\n  intro h,\n  obtain \u27e8P, hP\u27e9 := X_dvd_iff.2 h,\n  have hdegP : P.degree < (minpoly R f).degree,\n  { rw [hP, mul_comm],\n    refine degree_lt_degree_mul_X (\u03bb h, _),\n    rw [h, mul_zero] at hP,\n    exact minpoly.ne_zero (is_integral f) hP },\n  have hPmonic : P.monic,\n  { suffices : (minpoly R f).monic,\n    { rwa [monic.def, hP, mul_comm, leading_coeff_mul_X, \u2190 monic.def] at this },\n    exact minpoly.monic (is_integral f) },\n  have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _,\n  simp only [hP, mul_eq_comp, ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp, alg_hom.map_mul,\n    zero_apply] at hzero,\n  exact not_le.2 hdegP (minpoly.min _ _ hPmonic (ext hzero)),\nend\n\nend cayley_hamilton\n\nend linear_map\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.7246150465789809}}
{"text": "/-\nCopyright (c) 2022 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Devon Tuma\n-/\nimport data.vector.basic\n/-!\n# Theorems about membership of elements in vectors\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains theorems for membership in a `v.to_list` for a vector `v`.\nHaving the length available in the type allows some of the lemmas to be\n  simpler and more general than the original version for lists.\nIn particular we can avoid some assumptions about types being `inhabited`,\n  and make more general statements about `head` and `tail`.\n-/\n\nnamespace vector\nvariables {\u03b1 \u03b2 : Type*} {n : \u2115} (a a' : \u03b1)\n\n@[simp] lemma nth_mem (i : fin n) (v : vector \u03b1 n) : v.nth i \u2208 v.to_list :=\nby { rw nth_eq_nth_le,  exact list.nth_le_mem _ _ _ }\n\nlemma mem_iff_nth (v : vector \u03b1 n) : a \u2208 v.to_list \u2194 \u2203 i, v.nth i = a :=\nby simp only [list.mem_iff_nth_le, fin.exists_iff, vector.nth_eq_nth_le];\n  exact \u27e8\u03bb \u27e8i, hi, h\u27e9, \u27e8i, by rwa to_list_length at hi, h\u27e9,\n    \u03bb \u27e8i, hi, h\u27e9, \u27e8i, by rwa to_list_length, h\u27e9\u27e9\n\n\n\nlemma not_mem_zero (v : vector \u03b1 0) : a \u2209 v.to_list :=\n(vector.eq_nil v).symm \u25b8 (not_mem_nil a)\n\nlemma mem_cons_iff (v : vector \u03b1 n) :\n  a' \u2208 (a ::\u1d65 v).to_list \u2194 a' = a \u2228 a' \u2208 v.to_list :=\nby rw [vector.to_list_cons, list.mem_cons_iff]\n\nlemma mem_succ_iff (v : vector \u03b1 (n + 1)) :\n  a \u2208 v.to_list \u2194 a = v.head \u2228 a \u2208 v.tail.to_list :=\nbegin\n  obtain \u27e8a', v', h\u27e9 := exists_eq_cons v,\n  simp_rw [h, vector.mem_cons_iff, vector.head_cons, vector.tail_cons],\nend\n\nlemma mem_cons_self (v : vector \u03b1 n) : a \u2208 (a ::\u1d65 v).to_list :=\n(vector.mem_iff_nth a (a ::\u1d65 v)).2 \u27e80, vector.nth_cons_zero a v\u27e9\n\n@[simp] lemma head_mem (v : vector \u03b1 (n + 1)) : v.head \u2208 v.to_list :=\n(vector.mem_iff_nth v.head v).2 \u27e80, vector.nth_zero v\u27e9\n\nlemma mem_cons_of_mem (v : vector \u03b1 n) (ha' : a' \u2208 v.to_list) : a' \u2208 (a ::\u1d65 v).to_list :=\n(vector.mem_cons_iff a a' v).2 (or.inr ha')\n\nlemma mem_of_mem_tail (v : vector \u03b1 n) (ha : a \u2208 v.tail.to_list) : a \u2208 v.to_list :=\nbegin\n  induction n with n hn,\n  { exact false.elim (vector.not_mem_zero a v.tail ha) },\n  { exact (mem_succ_iff a v).2 (or.inr ha) }\nend\n\nlemma mem_map_iff (b : \u03b2) (v : vector \u03b1 n) (f : \u03b1 \u2192 \u03b2) :\n  b \u2208 (v.map f).to_list \u2194 \u2203 (a : \u03b1), a \u2208 v.to_list \u2227 f a = b :=\nby rw [vector.to_list_map, list.mem_map]\n\nlemma not_mem_map_zero (b : \u03b2) (v : vector \u03b1 0) (f : \u03b1 \u2192 \u03b2) : b \u2209 (v.map f).to_list :=\nby simpa only [vector.eq_nil v, vector.map_nil, vector.to_list_nil] using list.not_mem_nil b\n\nlemma mem_map_succ_iff (b : \u03b2) (v : vector \u03b1 (n + 1)) (f : \u03b1 \u2192 \u03b2) :\n  b \u2208 (v.map f).to_list \u2194 f v.head = b \u2228 \u2203 (a : \u03b1), a \u2208 v.tail.to_list \u2227 f a = b :=\nby rw [mem_succ_iff, head_map, tail_map, mem_map_iff, @eq_comm _ b]\n\nend vector\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/vector/mem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388209992571, "lm_q2_score": 0.8740772417253256, "lm_q1q2_score": 0.7245565582180741}}
{"text": "import ring_theory.ideals linear_algebra.quotient_module tactic.ring\n\nopen set function\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [comm_ring \u03b1] [comm_ring \u03b2] {a b : \u03b1}\n\nnamespace is_ideal\n\nlemma zero (S : set \u03b1) [is_ideal S] : (0 : \u03b1) \u2208 S := is_submodule.zero_ \u03b1 S\n\nlemma add {S : set \u03b1} [is_ideal S] : a \u2208 S \u2192 b \u2208 S \u2192 a + b \u2208 S := is_submodule.add_ \u03b1\n\nlemma neg_iff {S : set \u03b1} [is_ideal S] : a \u2208 S \u2194 -a \u2208 S := \u27e8is_submodule.neg, \u03bb h, neg_neg a \u25b8 is_submodule.neg h\u27e9\n\nlemma sub {S : set \u03b1} [is_ideal S] : a \u2208 S \u2192 b \u2208 S \u2192 a - b \u2208 S := is_submodule.sub\n\nlemma mul_left {S : set \u03b1} [is_ideal S] : b \u2208 S \u2192 a * b \u2208 S := @is_submodule.smul \u03b1 \u03b1 _ _ _ _ a _\n\nlemma mul_right {S : set \u03b1} [is_ideal S] : a \u2208 S \u2192 a * b \u2208 S := mul_comm b a \u25b8 mul_left\n\ndef quotient_rel (S : set \u03b1) [is_ideal S] := is_submodule.quotient_rel S\n\nlocal attribute [instance] quotient_rel\n\ndef quotient (S : set \u03b1) [is_ideal S] := quotient (quotient_rel S)\n\ninstance (S : set \u03b1) [is_ideal S] : comm_ring (quotient S) :=\n{ mul := \u03bb a b, quotient.lift_on\u2082 a b (\u03bb a b, \u27e6a * b\u27e7) \n  (\u03bb a\u2081 a\u2082 b\u2081 b\u2082 (h\u2081 : a\u2081 - b\u2081 \u2208 S) (h\u2082 : a\u2082 - b\u2082 \u2208 S), \n    quotient.sound\n    (show a\u2081 * a\u2082 - b\u2081 * b\u2082 \u2208 S, from\n    have h : a\u2082 * (a\u2081 - b\u2081) + (a\u2082 - b\u2082) * b\u2081 =\n      a\u2081 * a\u2082 - b\u2081 * b\u2082, by ring,\n    h \u25b8 add (mul_left h\u2081) (mul_right h\u2082))),\n  mul_assoc := \u03bb a b c, quotient.induction_on\u2083 a b c $ \n    \u03bb a b c, show \u27e6_\u27e7 = \u27e6_\u27e7, by rw mul_assoc,\n  mul_comm := \u03bb a b, quotient.induction_on\u2082 a b $\n    \u03bb a b, show \u27e6_\u27e7 = \u27e6_\u27e7, by rw mul_comm,\n  one := \u27e61\u27e7,\n  one_mul := \u03bb a, quotient.induction_on a $\n    \u03bb a, show \u27e6_\u27e7 = \u27e6_\u27e7, by rw one_mul,\n  mul_one := \u03bb a, quotient.induction_on a $\n    \u03bb a, show \u27e6_\u27e7 = \u27e6_\u27e7, by rw mul_one,\n  left_distrib := \u03bb a b c, quotient.induction_on\u2083 a b c $ \n    \u03bb a b c, show \u27e6_\u27e7 = \u27e6_\u27e7, by rw mul_add,\n  right_distrib := \u03bb a b c, quotient.induction_on\u2083 a b c $ \n    \u03bb a b c, show \u27e6_\u27e7 = \u27e6_\u27e7, by rw add_mul,\n  ..is_submodule.quotient.add_comm_group S }\n\nlemma is_proper_ideal_iff_one_not_mem {S : set \u03b1} [hS : is_ideal S] : \n  is_proper_ideal S \u2194 (1 : \u03b1) \u2209 S :=\n\u27e8\u03bb h h1, by exactI is_proper_ideal.ne_univ S \n  (eq_univ_iff_forall.2 (\u03bb a, mul_one a \u25b8 mul_left h1)), \n\u03bb h, {ne_univ := mt eq_univ_iff_forall.1 (\u03bb ha, h (ha _)), ..hS}\u27e9\n\nlemma quotient_eq_zero_iff_mem {S : set \u03b1} [is_ideal S] : \u27e6a\u27e7 = (0 : quotient S) \u2194 a \u2208 S :=\nby conv {to_rhs, rw \u2190 sub_zero a }; exact quotient.eq\n\ninstance (S : set \u03b1) [is_prime_ideal S] : integral_domain (quotient S) :=\n{ zero_ne_one := ne.symm $ mt quotient_eq_zero_iff_mem.1 \n    (is_proper_ideal_iff_one_not_mem.1 (by apply_instance)),\n  eq_zero_or_eq_zero_of_mul_eq_zero := \u03bb a b,\n    quotient.induction_on\u2082 a b $ \u03bb a b hab,\n      (is_prime_ideal.mem_or_mem_of_mul_mem \n        (quotient_eq_zero_iff_mem.1 hab)).elim\n      (or.inl \u2218 quotient_eq_zero_iff_mem.2)\n      (or.inr \u2218 quotient_eq_zero_iff_mem.2),\n  ..is_ideal.comm_ring S }\n\ninstance (S : set \u03b1) : is_ideal (span S) :=\n{ ..show is_submodule (span S), by apply_instance }\n\nlemma exists_inv {S : set \u03b1} [is_maximal_ideal S] {a : quotient S} : a \u2260 0 \u2192\n  \u2203 b : quotient S, a * b = 1 :=\nquotient.induction_on  a $ \u03bb a ha,\nclassical.by_contradiction $ \u03bb h,\nhave haS : a \u2209 S := mt quotient_eq_zero_iff_mem.2 ha,\nby haveI hS : is_proper_ideal (span (set.insert a S)) :=\n  is_proper_ideal_iff_one_not_mem.2\n  (mt mem_span_insert.1 $ \u03bb \u27e8b, hb\u27e9,\n  h \u27e8-\u27e6b\u27e7, quotient.sound (show a * -b - 1 \u2208 S,\n    from neg_iff.2 (begin\n      rw [neg_sub, mul_neg_eq_neg_mul_symm, sub_eq_add_neg, neg_neg, mul_comm],\n      rw span_eq_of_is_submodule (show is_submodule S, by apply_instance) at hb,\n      exact hb\n    end))\u27e9);\nexact\n  have span (set.insert a S) = S :=\n    or.resolve_right (is_maximal_ideal.eq_or_univ_of_subset (span (set.insert a S))\n    (subset.trans (subset_insert _ _) subset_span)) (is_proper_ideal.ne_univ _),\n  haS (this \u25b8 subset_span (mem_insert _ _))\n\nlocal attribute [instance] classical.prop_decidable\n\n/-- quotient by maximal ideal is a field. A definition rather than an instance, since\nit is noncomputable, and users may have a computable inverse in some applications-/\nnoncomputable def field (S : set \u03b1) [is_maximal_ideal S] : field (quotient S) :=\n{ zero_ne_one := ne.symm $ mt quotient_eq_zero_iff_mem.1 \n    (is_proper_ideal_iff_one_not_mem.1 (by apply_instance)),\n  inv := \u03bb a, if ha : a = 0 then 0 else classical.some (exists_inv ha),\n  mul_inv_cancel := \u03bb a (ha : a \u2260 0), show a * dite _ _ _ = _, \n    by rw dif_neg ha;\n    exact classical.some_spec (exists_inv ha),\n  inv_mul_cancel := \u03bb a (ha : a \u2260 0), show dite _ _ _ * a = _, \n    by rw [mul_comm, dif_neg ha];\n    exact classical.some_spec (exists_inv ha),\n  ..is_ideal.comm_ring S }\n\ninstance is_ring_hom_quotient_mk (S : set \u03b1) [is_ideal S] : \n  @is_ring_hom _ (quotient S) _ _ quotient.mk :=\nby refine {..}; intros; refl\n\nend is_ideal", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/quotient_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.72455654257065}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\n\nimport algebra.group.defs\nimport order.basic\nimport order.monotone\n\n/-!\n\n# Covariants and contravariants\n\nThis file contains general lemmas and instances to work with the interactions between a relation and\nan action on a Type.\n\nThe intended application is the splitting of the ordering from the algebraic assumptions on the\noperations in the `ordered_[...]` hierarchy.\n\nThe strategy is to introduce two more flexible typeclasses, `covariant_class` and\n`contravariant_class`:\n\n* `covariant_class` models the implication `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone),\n* `contravariant_class` models the implication `a * b < a * c \u2192 b < c`.\n\nSince `co(ntra)variant_class` takes as input the operation (typically `(+)` or `(*)`) and the order\nrelation (typically `(\u2264)` or `(<)`), these are the only two typeclasses that I have used.\n\nThe general approach is to formulate the lemma that you are interested in and prove it, with the\n`ordered_[...]` typeclass of your liking.  After that, you convert the single typeclass,\nsay `[ordered_cancel_monoid M]`, into three typeclasses, e.g.\n`[left_cancel_semigroup M] [partial_order M] [covariant_class M M (function.swap (*)) (\u2264)]`\nand have a go at seeing if the proof still works!\n\nNote that it is possible to combine several co(ntra)variant_class assumptions together.\nIndeed, the usual ordered typeclasses arise from assuming the pair\n`[covariant_class M M (*) (\u2264)] [contravariant_class M M (*) (<)]`\non top of order/algebraic assumptions.\n\nA formal remark is that normally `covariant_class` uses the `(\u2264)`-relation, while\n`contravariant_class` uses the `(<)`-relation. This need not be the case in general, but seems to be\nthe most common usage. In the opposite direction, the implication\n```lean\n[semigroup \u03b1] [partial_order \u03b1] [contravariant_class \u03b1 \u03b1 (*) (\u2264)] => left_cancel_semigroup \u03b1\n```\nholds -- note the `co*ntra*` assumption on the `(\u2264)`-relation.\n\n# Formalization notes\n\nWe stick to the convention of using `function.swap (*)` (or `function.swap (+)`), for the\ntypeclass assumptions, since `function.swap` is slightly better behaved than `flip`.\nHowever, sometimes as a **non-typeclass** assumption, we prefer `flip (*)` (or `flip (+)`),\nas it is easier to use. -/\n\n-- TODO: convert `has_exists_mul_of_le`, `has_exists_add_of_le`?\n-- TODO: relationship with `con/add_con`\n-- TODO: include equivalence of `left_cancel_semigroup` with\n-- `semigroup partial_order contravariant_class \u03b1 \u03b1 (*) (\u2264)`?\n-- TODO : use \u21d2, as per Eric's suggestion?  See\n-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff/near/236148738\n-- for a discussion.\n\nopen function\n\nsection variants\nvariables {M N : Type*} (\u03bc : M \u2192 N \u2192 N) (r : N \u2192 N \u2192 Prop)\n\nvariables (M N)\n/-- `covariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `covariant_class` doc-string for its meaning. -/\ndef covariant     : Prop := \u2200 (m) {n\u2081 n\u2082}, r n\u2081 n\u2082 \u2192 r (\u03bc m n\u2081) (\u03bc m n\u2082)\n\n/-- `contravariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `contravariant_class` doc-string for its meaning. -/\ndef contravariant : Prop := \u2200 (m) {n\u2081 n\u2082}, r (\u03bc m n\u2081) (\u03bc m n\u2082) \u2192 r n\u2081 n\u2082\n\n/--  Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`covariant_class` says that \"the action `\u03bc` preserves the relation `r`.\"\n\nMore precisely, the `covariant_class` is a class taking two Types `M N`, together with an \"action\"\n`\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the assertion that\nfor all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the pair\n`(n\u2081, n\u2082)`, then, the relation `r` also holds for the pair `(\u03bc m n\u2081, \u03bc m n\u2082)`,\nobtained from `(n\u2081, n\u2082)` by acting upon it by `m`.\n\nIf `m : M` and `h : r n\u2081 n\u2082`, then `covariant_class.elim m h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`.\n-/\n@[protect_proj] class covariant_class : Prop :=\n(elim :  covariant M N \u03bc r)\n\n/--  Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`contravariant_class` says that \"if the result of the action `\u03bc` on a pair satisfies the\nrelation `r`, then the initial pair satisfied the relation `r`.\"\n\nMore precisely, the `contravariant_class` is a class taking two Types `M N`, together with an\n\"action\" `\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the\nassertion that for all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the\npair `(\u03bc m n\u2081, \u03bc m n\u2082)` obtained from `(n\u2081, n\u2082)` by acting upon it by `m`, then, the relation\n`r` also holds for the pair `(n\u2081, n\u2082)`.\n\nIf `m : M` and `h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`, then `contravariant_class.elim m h : r n\u2081 n\u2082`.\n-/\n@[protect_proj] class contravariant_class : Prop :=\n(elim : contravariant M N \u03bc r)\n\nlemma rel_iff_cov [covariant_class M N \u03bc r] [contravariant_class M N \u03bc r] (m : M) {a b : N} :\n  r (\u03bc m a) (\u03bc m b) \u2194 r a b :=\n\u27e8contravariant_class.elim _, covariant_class.elim _\u27e9\n\nsection flip\n\nvariables {M N \u03bc r}\n\nlemma covariant.flip (h : covariant M N \u03bc r) : covariant M N \u03bc (flip r) :=\n\u03bb a b c hbc, h a hbc\n\nlemma contravariant.flip (h : contravariant M N \u03bc r) : contravariant M N \u03bc (flip r) :=\n\u03bb a b c hbc, h a hbc\n\nend flip\n\nsection covariant\nvariables {M N \u03bc r} [covariant_class M N \u03bc r]\n\nlemma act_rel_act_of_rel (m : M) {a b : N} (ab : r a b) :\n  r (\u03bc m a) (\u03bc m b) :=\ncovariant_class.elim _ ab\n\n@[to_additive]\nlemma group.covariant_iff_contravariant [group N] :\n  covariant N N (*) r \u2194 contravariant N N (*) r :=\nbegin\n  refine \u27e8\u03bb h a b c bc, _, \u03bb h a b c bc, _\u27e9,\n  { rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c],\n    exact h a\u207b\u00b9 bc },\n  { rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c] at bc,\n    exact h a\u207b\u00b9 bc }\nend\n\n@[to_additive]\nlemma group.covconv [group N] [covariant_class N N (*) r] :\n  contravariant_class N N (*) r :=\n\u27e8group.covariant_iff_contravariant.mp covariant_class.elim\u27e9\n\nsection is_trans\nvariables [is_trans N r] (m n : M) {a b c d : N}\n\n/-  Lemmas with 3 elements. -/\nlemma act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (\u03bc m b) c) :\n  r (\u03bc m a) c :=\ntrans (act_rel_act_of_rel m ab) rl\n\nlemma rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (\u03bc m a)) :\n  r c (\u03bc m b) :=\ntrans rr (act_rel_act_of_rel _ ab)\n\nend is_trans\n\nend covariant\n\n/-  Lemma with 4 elements. -/\nsection M_eq_N\nvariables {M N \u03bc r} {mu : N \u2192 N \u2192 N} [is_trans N r]\n  [covariant_class N N mu r] [covariant_class N N (swap mu) r] {a b c d : N}\n\nlemma act_rel_act_of_rel_of_rel (ab : r a b) (cd : r c d) :\n  r (mu a c) (mu b d) :=\ntrans (act_rel_act_of_rel c ab : _) (act_rel_act_of_rel b cd)\n\nend M_eq_N\n\nsection contravariant\nvariables {M N \u03bc r} [contravariant_class M N \u03bc r]\n\nlemma rel_of_act_rel_act (m : M) {a b : N} (ab : r (\u03bc m a) (\u03bc m b)) :\n  r a b :=\ncontravariant_class.elim _ ab\n\nsection is_trans\nvariables [is_trans N r] (m n : M) {a b c d : N}\n\n/-  Lemmas with 3 elements. -/\nlemma act_rel_of_act_rel_of_rel_act_rel (ab : r (\u03bc m a) b) (rl : r (\u03bc m b) (\u03bc m c)) :\n  r (\u03bc m a) c :=\ntrans ab (rel_of_act_rel_act m rl)\n\nlemma rel_act_of_act_rel_act_of_rel_act (ab : r (\u03bc m a) (\u03bc m b)) (rr : r b (\u03bc m c)) :\n  r a (\u03bc m c) :=\ntrans (rel_of_act_rel_act m ab) rr\n\nend is_trans\n\nend contravariant\n\nsection monotone\n\nvariables {\u03b1 : Type*} {M N \u03bc} [preorder \u03b1] [preorder N]\nvariable {f : N \u2192 \u03b1}\n\n/-- The partial application of a constant to a covariant operator is monotone. -/\nlemma covariant.monotone_of_const [covariant_class M N \u03bc (\u2264)] (m : M) : monotone (\u03bc m) :=\n\u03bb a b ha, covariant_class.elim m ha\n\n/-- A monotone function remains monotone when composed with the partial application\nof a covariant operator. E.g., `\u2200 (m : \u2115), monotone f \u2192 monotone (\u03bb n, f (m + n))`. -/\nlemma monotone.covariant_of_const [covariant_class M N \u03bc (\u2264)] (hf : monotone f) (m : M) :\n  monotone (\u03bb n, f (\u03bc m n)) :=\nhf.comp $ covariant.monotone_of_const m\n\n/-- Same as `monotone.covariant_of_const`, but with the constant on the other side of\nthe operator.  E.g., `\u2200 (m : \u2115), monotone f \u2192 monotone (\u03bb n, f (n + m))`. -/\nlemma monotone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [covariant_class N N (swap \u03bc) (\u2264)]\n  (hf : monotone f) (m : N) :\n  monotone (\u03bb n, f (\u03bc n m)) :=\nhf.comp $ covariant.monotone_of_const m\n\n/-- Dual of `monotone.covariant_of_const` -/\nlemma antitone.covariant_of_const [covariant_class M N \u03bc (\u2264)] (hf : antitone f) (m : M) :\n  antitone (\u03bb n, f (\u03bc m n)) :=\nhf.comp_monotone $ covariant.monotone_of_const m\n\n/-- Dual of `monotone.covariant_of_const'` -/\nlemma antitone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [covariant_class N N (swap \u03bc) (\u2264)]\n  (hf : antitone f) (m : N) :\n  antitone (\u03bb n, f (\u03bc n m)) :=\nhf.comp_monotone $ covariant.monotone_of_const m\n\nend monotone\n\nlemma covariant_le_of_covariant_lt [partial_order N] :\n  covariant M N \u03bc (<) \u2192 covariant M N \u03bc (\u2264) :=\nbegin\n  refine \u03bb h a b c bc, _,\n  rcases le_iff_eq_or_lt.mp bc with rfl | bc,\n  { exact rfl.le },\n  { exact (h _ bc).le }\nend\n\nlemma contravariant_lt_of_contravariant_le [partial_order N] :\n  contravariant M N \u03bc (\u2264) \u2192 contravariant M N \u03bc (<) :=\nbegin\n  refine \u03bb h a b c bc, lt_iff_le_and_ne.mpr \u27e8h a bc.le, _\u27e9,\n  rintro rfl,\n  exact lt_irrefl _ bc,\nend\n\nlemma covariant_le_iff_contravariant_lt [linear_order N] :\n  covariant M N \u03bc (\u2264) \u2194 contravariant M N \u03bc (<) :=\n\u27e8 \u03bb h a b c bc, not_le.mp (\u03bb k, not_le.mpr bc (h _ k)),\n  \u03bb h a b c bc, not_lt.mp (\u03bb k, not_lt.mpr bc (h _ k))\u27e9\n\nlemma covariant_lt_iff_contravariant_le [linear_order N] :\n  covariant M N \u03bc (<) \u2194 contravariant M N \u03bc (\u2264) :=\n\u27e8 \u03bb h a b c bc, not_lt.mp (\u03bb k, not_lt.mpr bc (h _ k)),\n  \u03bb h a b c bc, not_le.mp (\u03bb k, not_le.mpr bc (h _ k))\u27e9\n\n@[to_additive]\nlemma covariant_flip_mul_iff [comm_semigroup N] :\n  covariant N N (flip (*)) (r) \u2194 covariant N N (*) (r) :=\nby rw is_symm_op.flip_eq\n\n@[to_additive]\nlemma contravariant_flip_mul_iff [comm_semigroup N] :\n  contravariant N N (flip (*)) (r) \u2194 contravariant N N (*) (r) :=\nby rw is_symm_op.flip_eq\n\n@[to_additive]\ninstance contravariant_mul_lt_of_covariant_mul_le [has_mul N] [linear_order N]\n  [covariant_class N N (*) (\u2264)] : contravariant_class N N (*) (<) :=\n{ elim := (covariant_le_iff_contravariant_lt N N (*)).mp covariant_class.elim }\n\n@[to_additive]\ninstance covariant_mul_lt_of_contravariant_mul_le [has_mul N] [linear_order N]\n  [contravariant_class N N (*) (\u2264)] : covariant_class N N (*) (<) :=\n{ elim := (covariant_lt_iff_contravariant_le N N (*)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance covariant_swap_mul_le_of_covariant_mul_le [comm_semigroup N] [has_le N]\n  [covariant_class N N (*) (\u2264)] : covariant_class N N (swap (*)) (\u2264) :=\n{ elim := (covariant_flip_mul_iff N (\u2264)).mpr covariant_class.elim }\n\n@[to_additive]\ninstance contravariant_swap_mul_le_of_contravariant_mul_le [comm_semigroup N] [has_le N]\n  [contravariant_class N N (*) (\u2264)] : contravariant_class N N (swap (*)) (\u2264) :=\n{ elim := (contravariant_flip_mul_iff N (\u2264)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance contravariant_swap_mul_lt_of_contravariant_mul_lt [comm_semigroup N] [has_lt N]\n  [contravariant_class N N (*) (<)] : contravariant_class N N (swap (*)) (<) :=\n{ elim := (contravariant_flip_mul_iff N (<)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance covariant_swap_mul_lt_of_covariant_mul_lt [comm_semigroup N] [has_lt N]\n  [covariant_class N N (*) (<)] : covariant_class N N (swap (*)) (<) :=\n{ elim := (covariant_flip_mul_iff N (<)).mpr covariant_class.elim }\n\n@[to_additive]\ninstance left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le\n  [left_cancel_semigroup N] [partial_order N] [covariant_class N N (*) (\u2264)] :\n  covariant_class N N (*) (<) :=\n{ elim := \u03bb a b c bc, by { cases lt_iff_le_and_ne.mp bc with bc cb,\n    exact lt_iff_le_and_ne.mpr \u27e8covariant_class.elim a bc, (mul_ne_mul_right a).mpr cb\u27e9 } }\n\n@[to_additive]\ninstance right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le\n  [right_cancel_semigroup N] [partial_order N] [covariant_class N N (swap (*)) (\u2264)] :\n  covariant_class N N (swap (*)) (<) :=\n{ elim := \u03bb a b c bc, by { cases lt_iff_le_and_ne.mp bc with bc cb,\n    exact lt_iff_le_and_ne.mpr \u27e8covariant_class.elim a bc, (mul_ne_mul_left a).mpr cb\u27e9 } }\n\n@[to_additive]\ninstance left_cancel_semigroup.contravariant_mul_le_of_contravariant_mul_lt\n  [left_cancel_semigroup N] [partial_order N] [contravariant_class N N (*) (<)] :\n  contravariant_class N N (*) (\u2264) :=\n{ elim := \u03bb a b c bc, by { cases le_iff_eq_or_lt.mp bc with h h,\n    { exact ((mul_right_inj a).mp h).le },\n    { exact (contravariant_class.elim _ h).le } } }\n\n@[to_additive]\ninstance right_cancel_semigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt\n  [right_cancel_semigroup N] [partial_order N] [contravariant_class N N (swap (*)) (<)] :\n  contravariant_class N N (swap (*)) (\u2264) :=\n{ elim := \u03bb a b c bc, by { cases le_iff_eq_or_lt.mp bc with h h,\n    { exact ((mul_left_inj a).mp h).le },\n    { exact (contravariant_class.elim _ h).le } } }\n\nend variants\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/covariant_and_contravariant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7245565418009312}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen, Mario Carneiro\n-/\n\nimport Mathlib.Tactic.SimpRw\n\n-- `simp_rw` can perform rewrites under binders:\nexample : (\u03bb (x y : Nat) => x + y) = (\u03bb x y => y + x) := by simp_rw [Nat.add_comm]\n\n-- `simp_rw` can apply reverse rules:\nexample (f : Nat \u2192 Nat) {a b c : Nat} (ha : f b = a) (hc : f b = c) : a = c := by simp_rw [\u2190 ha, hc]\n\n-- `simp_rw` applies rewrite rules multiple times:\nexample (a b c d : Nat) : a + (b + (c + d)) = ((d + c) + b) + a := by simp_rw [Nat.add_comm]\n\n-- `simp_rw` can also rewrite in assumptions:\nexample (p : Nat \u2192 Prop) (a b : Nat) (h : p (a + b)) : p (b + a) :=\nby {simp_rw [Nat.add_comm a b] at h; exact h}\n-- or at multiple assumptions:\nexample (p : Nat \u2192 Prop) (a b : Nat) (h\u2081 : p (b + a) \u2192 p (a + b))  (h\u2082 : p (a + b)) : p (b + a) :=\nby {simp_rw [Nat.add_comm a b] at h\u2081 h\u2082; exact h\u2081 h\u2082}\n-- or everywhere:\nexample (p : Nat \u2192 Prop) (a b : Nat) (h\u2081 : p (b + a) \u2192 p (a + b))  (h\u2082 : p (a + b)) : p (a + b) :=\nby {simp_rw [Nat.add_comm a b] at *; exact h\u2081 h\u2082}\n\n-- `simp` and `rw`, alone, can't close this goal. But `simp_rw` can\nexample {a : Nat}\n  (h1 : \u2200 a b : Nat, a - 1 \u2264 b \u2194 a \u2264 b + 1)\n  (h2 : \u2200 a b : Nat, a \u2264 b \u2194 \u2200 c, c < a \u2192 c < b) :\n  (\u2200 b, a - 1 \u2264 b) = \u2200 b c : Nat, c < a \u2192 c < b + 1 :=\nby simp_rw [h1, h2]\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/test/SimpRw.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7245565388768457}}
{"text": "import algebra.module\n\nopen list\n\n-- The binomial coefficient, defined recursively on the natural numbers\ndef B : \u2115 \u2192 \u2115 \u2192 \u2115\n| _ 0 := 1\n| 0 _ := 0\n| (n+1) (k+1) := B n (k+1) + B n k\n\n-- This _almost_ holds definitionally, but requires cases on n\n@[simp] lemma B.zero : \u03a0 {n : \u2115}, B n 0 = 1\n| 0 := rfl\n| (n+1) := rfl\n\n@[simp] lemma B.gt : \u03a0 {n k : \u2115}, k > n \u2192 B n k = 0\n| 0 0 h := absurd h (lt_irrefl 0)\n| 0 (m+1) h := rfl\n| (n+1) (m+1) h :=\n    begin\n    unfold B,\n    rw [B.gt (nat.lt_of_succ_lt h), B.gt (nat.lt_of_succ_lt_succ h)],\n    end\n\n@[simp] lemma B.self : \u03a0 {n : \u2115}, B n n = 1\n| 0 := rfl\n| (n+1) := \n    begin\n    unfold B,\n    rw [@B.self n, B.gt (le_refl (nat.succ n))],\n    end\n\nlemma B.symm : \u03a0 {n k : \u2115}, k \u2264 n \u2192 B n k = B n (n-k)\n| 0 0 h := rfl\n| (n+1) 0 h := by unfold B; simp\n| (n+1) (k+1) h :=\n    begin\n    unfold B, simp,\n    by_cases honk : n = k,\n    { rw honk, simp [nat.sub_self], rw [B.gt (le_refl (nat.succ k))] },\n    have : k < n,\n        cases lt_or_eq_of_le (nat.le_of_succ_le_succ h),\n        exact h_1, exfalso, cc,\n    rw [B.symm (nat.le_of_succ_le_succ h), B.symm this],\n    cases heckin : (n-k),\n    exfalso, have := nat.sub_pos_of_lt this, exact ne_of_gt this heckin,\n    unfold B,\n    congr, rw [nat.sub_succ, heckin], refl,\n    end\n\nlemma list.range_core.concat : \u03a0 {n : \u2115} {l : list \u2115},\n    range_core n l = range_core n [] ++ l\n| 0 l := rfl\n| (n+1) [] := by simp\n| (n+1) (hd :: tl) :=\n    begin\n    unfold1 range_core,\n    rw [@list.range_core.concat n [n]],\n    rw [@list.range_core.concat n (n :: hd :: tl)],\n    simp,\n    end\n\n\n-- Split apart a range into lower and upper parts, where the upper part\n-- is a range that is mapped using addition.\nlemma list.range_core.split {n m : \u2115} :\n    range (n+m) = range n ++ map (\u03bb i, i+n) (range m) :=\n    begin\n    induction m with m, simp [range, range_core],\n    unfold1 range, unfold1 range_core,\n    rw [@list.range_core.concat (n+m), @list.range_core.concat m],\n    rw [map_append, \u2190 list.append_assoc],\n    unfold map, tactic.congr_core, exact m_ih, rw add_comm,\n    end\n\nlemma range_core.step {n : \u2115} :\n    range (nat.succ n) = range n ++ [n] :=\n    have this : map (\u03bb (i : \u2115), i + n) (range 1) = [n]\n      := by simp [range, range_core],\n    eq.subst this (@list.range_core.split n 1)\n\n-- A product distributes across each term of the sum.\nlemma list.sum.distrib {\u03b1 : Type} [semiring \u03b1] {a : \u03b1} {l : list \u03b1} :\n    a * sum l = sum (map (\u03bb b, a*b) l) :=\n    begin\n    induction l, simp,\n    rw [sum_cons, left_distrib, map_cons, sum_cons, l_ih],\n    end\n\n-- Sums mapped over the same list can be combined pairwise,\n-- when commutativity holds.\nlemma list.sum.combine {\u03b1 \u03b2 : Type} [add_comm_monoid \u03b2] {f g : \u03b1 \u2192 \u03b2} {l : list \u03b1} :\n    sum (map f l) + sum (map g l) = sum (map (\u03bb a, f a+g a) l) :=\n    begin\n    induction l, { simp },\n    unfold map, rw [sum_cons, sum_cons, sum_cons],\n    transitivity,\n    show f l_hd + sum (map f l_tl) + (g l_hd + sum (map g l_tl))\n        = f l_hd + g l_hd + (sum (map f l_tl) + sum (map g l_tl)), ac_refl,\n    rw l_ih,\n    end\n\n-- This is the formula for the expansion of the power `n` of a binomial `(a+b)`,\n-- where `a` and `b` are in some commutative semiring\ndef binomial.expansion {\u03b1 : Type} [comm_semiring \u03b1] (a b : \u03b1) (n : \u2115) : \u03b1\n    := sum (map (\u03bb i, B n i * a^i * b^(n-i)) (range (n+1)))\n\n-- The theorem that the expansion is correct\ntheorem binomial_theorem {\u03b1 : Type} [comm_semiring \u03b1] (a b : \u03b1) (n : \u2115) :\n    (a+b)^n = binomial.expansion a b n :=\n    begin\n    -- Classic induction on \u2115, of course!\n    induction n with n ih,\n    -- Base case is trivial, after unfolding some definitions\n    { simp [range, range_core, binomial.expansion] },\n    -- unfold the definition\n    unfold binomial.expansion,\n    -- split off the first binomial\n    transitivity, apply pow_succ, transitivity,\n    calc (a+b)*(a+b)^n\n        -- start by expanding using induction hypothesis\n        = (a+b) * binomial.expansion a b n : by rw ih\n    ... = a * binomial.expansion a b n\n        + b * binomial.expansion a b n : by rw right_distrib\n        -- we will need to work with the sums separately\n    ... = a*sum (map (\u03bb i, B n i * a^i * b^(n-i)) (range (n+1)))\n        + b*sum (map (\u03bb i, B n i * a^i * b^(n-i)) (range (n+1))) : rfl\n        -- distribute the `a` and `b` factors towards the inside\n    ... = sum (map (\u03bb i, a * (B n i * a^i * b^(n-i))) (range (n+1)))\n        + sum (map (\u03bb i, b * (B n i * a^i * b^(n-i))) (range (n+1))) :\n        by rw [list.sum.distrib, list.sum.distrib, list.map_map, list.map_map]\n        -- and add them to the exponents\n    ... = sum (map (\u03bb i, B n i * a^(i+1) * b^(n-i))   (range (n+1)))\n        + sum (map (\u03bb i, B n i * a^i     * b^(n-i+1)) (range (n+1))) :\n        begin\n        have : \u2200 (c : \u03b1) (i : \u2115), c^(i+1) = c*c^i, intros, refl,\n        -- simp reduces inside lambdas\n        simp only [this a, this b],\n        -- just focus on those lambdas\n        congr,\n        -- funny rearrangement of terms\n        apply funext, intro i, simp [mul_comm, mul_assoc],\n        apply funext, intro i, simp [mul_comm],\n        rw [\u2190 mul_assoc, \u2190 mul_assoc]\n        end\n        -- split off the `a` term\n    ... = a^(n+1)\n        + sum (map (\u03bb i, B n i * a^(i+1) * b^(n-i))   (range n))\n        + sum (map (\u03bb i, B n i * a^i     * b^(n-i+1)) (range (n+1))) :\n        begin\n        rw [@range_core.step n, map_append, sum_append],\n        simp [nat.sub_self],\n        end\n        -- split off the `b` term\n    ... = a^(n+1)\n        + sum (map (\u03bb i, B n i     * a^(i+1) * b^(n-i))       (range n))\n        + b^(n+1)\n        + sum (map (\u03bb i, B n (i+1) * a^(i+1) * b^(n-(i+1)+1)) (range n)) :\n        begin\n        rw [add_comm n 1, @list.range_core.split 1 n, map_append, sum_append],\n        unfold1 range, unfold1 range_core, unfold1 range_core,\n        unfold map, simp,\n        end\n        -- move them to the front, group the sums\n    ... = a^(n+1) + b^(n+1)\n        + (sum (map (\u03bb i, B n i     * a^(i+1) * b^(n-i))       (range n))\n        +  sum (map (\u03bb i, B n (i+1) * a^(i+1) * b^(n-(i+1)+1)) (range n))) :\n        by ac_refl\n        -- simplify the exponent: `n-(i+1)+1 = n-i` for `i \u2208 range n`\n    ... = a^(n+1) + b^(n+1)\n        + (sum (map (\u03bb i, B n i     * a^(i+1) * b^(n-i)) (range n))\n        +  sum (map (\u03bb i, B n (i+1) * a^(i+1) * b^(n-i)) (range n))) :\n        begin\n            -- `n-(i+1)+1 = nat.pred (n - i) + 1`\n            simp only [nat.sub_succ, nat.pred_succ],\n            -- focus on this term\n            suffices\n                : map (\u03bb i, \u2191(B n (i + 1)) * a^(i+1) * b^(nat.pred (n-i) + 1)) (range n)\n                = map (\u03bb i, \u2191(B n (i + 1)) * a^(i+1) * b^(n-i)) (range n),\n                by rw this,\n            -- which we can apply the special_map lemma to\n            apply map_congr, intro i, intro ismem,\n            -- and now we focus on this part\n            suffices : nat.pred (n - i) + 1 = n - i, by rw this,\n            -- `i \u2208 range n \u2194 i < n`\n            rw list.mem_range at ismem,\n            apply nat.succ_pred_eq_of_pos,\n            exact nat.sub_pos_of_lt ismem,\n        end\n        -- okay, now we can combine the sums, since they range over the same list\n    ... = a^(n+1) + b^(n+1)\n        + sum (map (\u03bb i, B n i     * a^(i+1) * b^(n-i)\n                       + B n (i+1) * a^(i+1) * b^(n-i)) (range n)) :\n        by rw list.sum.combine\n        -- and they simplify nicely using the inductive definition of B\n    ... = a^(n+1) + b^(n+1)\n        + (sum (map (\u03bb i, B (n+1) (i+1) * a^(i+1) * b^(n-i)) (range n))) :\n        begin\n            simp [mul_assoc, right_distrib, B.equations._eqn_4]\n        end,\n    -- split off the term a^(n+1) on the RHS to match the LHS\n    rw [@range_core.step (n+1), map_append, sum_append],\n    simp [nat.sub_self],\n    -- and prove that the rest should be equal\n    tactic.congr_core, refl,\n    -- split off the first term on the RHS now\n    rw [add_comm n 1],\n    rw [@list.range_core.split 1 n, map_append, sum_append],\n    unfold range range_core,\n    simp, congr,\n    -- prove that the mapping functions are equal\n    -- simp helps with `(n+1)-(i+1) = n-i` in particular, yay!\n    apply funext, intro i, simp,\n    end\n", "meta": {"author": "MonoidMusician", "repo": "lean-math-stuff", "sha": "56e6ae80b4a634f23a90989a7156ce053a012acf", "save_path": "github-repos/lean/MonoidMusician-lean-math-stuff", "path": "github-repos/lean/MonoidMusician-lean-math-stuff/lean-math-stuff-56e6ae80b4a634f23a90989a7156ce053a012acf/src/binomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7245450416574818}}
{"text": "import tactic \nimport data.rat.default \nimport data.real.basic\nimport data.real.irrational\nimport analysis.inner_product_space.basic\nimport analysis.inner_product_space.pi_L2\n\nopen complex\nopen_locale big_operators\nopen_locale complex_conjugate\n\ntheorem rudin_1_1a (x : \u211d) (y : \u211a) :\n  ( irrational x ) -> irrational ( x + y ) :=\nbegin\n  apply irrational.add_rat,\nend\n\ntheorem rudin_1_1b (x : \u211d) (y : \u211a) (h : y \u2260 0) :\n  ( irrational x ) -> irrational ( x * y ) :=\nbegin\n  intro g,\n  apply irrational.mul_rat g h,\nend\n\n\ntheorem rudin_1_2 : \n  \u00ac \u2203 (x : \u211a), ( x ^ 2 = 12 ) :=\nbegin\n  sorry, \nend\n\ntheorem rudin_1_4 (\u03b1 : Type*) [partial_order \u03b1] (s : set \u03b1) (x y : \u03b1) \n  (h\u2080 : set.nonempty s) (h\u2081 : x \u2208 lower_bounds s) \n  (h\u2082 : y \u2208 upper_bounds s) : \n  x \u2264 y :=\nbegin\n  have h : \u2203 z, z \u2208 s := h\u2080,\n  cases h with z,\n  have xlez : x \u2264 z :=\n  begin\n    apply h\u2081,\n    assumption,\n  end,\n  have zley : z \u2264 y :=\n  begin\n    apply h\u2082,\n    assumption,\n  end,\n  exact xlez.trans zley,\nend\n\ntheorem rudin_1_11 (z : \u2102) :\n  \u2203 (r : \u211d) (w : \u2102), abs w = 1 \u2227 z = r * w :=\nbegin\n  by_cases h : z = 0,\n  {\n    use [0, 1],\n    simp,\n    assumption,\n  },\n  {\n    use abs z,\n    use z / \u2191(abs z),\n    split,\n    {\n      simp,\n      field_simp [h],\n    },\n    {\n      field_simp [h],\n      apply mul_comm,\n    },\n  },\nend\n\n\ntheorem rudin_1_12 (n : \u2115) (f : \u2115 \u2192 \u2102):\n  abs (\u2211 i in finset.range n, f i) \u2264 \u2211 i in finset.range n, \n  abs (f i) :=\nbegin\n  induction n with n ih, simp,\n  rw finset.range_succ,\n  simp, transitivity,\n  apply complex.abs_add,\n  apply add_le_add_left,\n  exact ih,\nend\n\ntheorem rudin_1_13 (x y : \u2102) :\n  |(abs x) - (abs y)| \u2264 abs (x - y) :=\nbegin\n  sorry,\nend\n\ntheorem rudin_1_14 (z : \u2102) (h : abs z = 1) :\n  (abs (1 + z)) ^ 2 + (abs (1 - z)) ^ 2 = 4 :=\nbegin\n  sorry,\nend\n\ntheorem rudina_1_16a (n : \u2115) (d r : \u211d) (x y z : euclidean_space \u211d (fin n))\n  (h\u2081 : n \u2265 3) (h\u2082 : \u2225x - y\u2225 = d) (h\u2083 : d > 0) (h\u2084 : r > 0) (h\u2085 : 2 * r > d) :\n  set.infinite {z : euclidean_space \u211d (fin n) | \u2225z - x\u2225 = r \u2227 \u2225z - y\u2225 = r} :=\nbegin\n  sorry,\nend\n\ntheorem rudin_1_17 (n : \u2115) (x y : euclidean_space \u211d (fin n)) : \n  \u2225x + y\u2225^2 + \u2225x - y\u2225^2 = 2*\u2225x\u2225^2 + 2*\u2225y\u2225^2 :=\nbegin\n  sorry,\nend\n\ntheorem rudin_1_18a (n : \u2115) (h : n > 1) (x : euclidean_space \u211d (fin n)) :\n  \u2203 (y : euclidean_space \u211d (fin n)), y \u2260 0 \u2227 (inner x y) = (0 : \u211d) :=\nbegin\n  sorry,\nend\n\ntheorem rudin_1_18b :\n  \u00ac \u2200 (x : \u211d), \u2203 (y : \u211d), y \u2260 0 \u2227 x * y = 0 :=\nbegin\n  simp,\n  use 1,\n  intros x h\u2081 h\u2082,\n  cases h\u2082,\n  {norm_num at h\u2082},\n  {exact absurd h\u2082 h\u2081},\nend\n\ntheorem rudin_1_19 (n : \u2115) (a b c x : euclidean_space \u211d (fin n)) (r : \u211d)\n  (h\u2081 : r > 0) (h\u2082 : 3 \u2022 c = 4 \u2022 b - a) (h\u2083 : 3 * r = 2 * \u2225x - b\u2225) :\n  \u2225x - a\u2225 = 2 * \u2225x - b\u2225 \u2194 \u2225x - c\u2225 = r :=\nbegin\n  sorry,\nend", "meta": {"author": "wudcscheme", "repo": "lean-challenges", "sha": "dfaf3f6f71148b60db75479e7b09c68012f354c1", "save_path": "github-repos/lean/wudcscheme-lean-challenges", "path": "github-repos/lean/wudcscheme-lean-challenges/lean-challenges-dfaf3f6f71148b60db75479e7b09c68012f354c1/src/analysis/rudin_chapter1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7245450384410537}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport ring_theory.adjoin_root\n\n/-!\n# Splitting fields\n\nThis file introduces the notion of a splitting field of a polynomial and provides an embedding from\na splitting field to any field that splits the polynomial. A polynomial `f : polynomial K` splits\nover a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have\ndegree `1`. A field extension of `K` of a polynomial `f : polynomial K` is called a splitting field\nif it is the smallest field extension of `K` such that `f` splits.\n\n## Main definitions\n\n* `polynomial.splits i f`: A predicate on a field homomorphism `i : K \u2192 L` and a polynomial `f`\n  saying that `f` is zero or all of its irreducible factors over `L` have degree `1`.\n* `polynomial.splitting_field f`: A fixed splitting field of the polynomial `f`.\n* `polynomial.is_splitting_field`: A predicate on a field to be a splitting field of a polynomial\n  `f`.\n\n## Main statements\n\n* `polynomial.C_leading_coeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its\n  degree, it can be written as the product of its leading coefficient with `\u220f (X - a)` where `a`\n  ranges through its roots.\n* `lift_of_splits`: If `K` and `L` are field extensions of a field `F` and for some finite subset\n  `S` of `K`, the minimal polynomial of every `x \u2208 K` splits as a polynomial with coefficients in\n  `L`, then `algebra.adjoin F S` embeds into `L`.\n* `polynomial.is_splitting_field.lift`: An embedding of a splitting field of the polynomial `f` into\n  another field such that `f` splits.\n* `polynomial.is_splitting_field.alg_equiv`: Every splitting field of a polynomial `f` is isomorphic\n  to `splitting_field f` and thus, being a splitting field is unique up to isomorphism.\n\n-/\n\nnoncomputable theory\nopen_locale classical big_operators polynomial\n\nuniverses u v w\n\nvariables {F : Type u} {K : Type v} {L : Type w}\n\nnamespace polynomial\n\nvariables [field K] [field L] [field F]\nopen polynomial\n\nsection splits\n\nvariables (i : K \u2192+* L)\n\n/-- A polynomial `splits` iff it is zero or all of its irreducible factors have `degree` 1. -/\ndef splits (f : K[X]) : Prop :=\nf = 0 \u2228 \u2200 {g : L[X]}, irreducible g \u2192 g \u2223 f.map i \u2192 degree g = 1\n\n@[simp] lemma splits_zero : splits i (0 : K[X]) := or.inl rfl\n\n@[simp] lemma splits_C (a : K) : splits i (C a) :=\nif ha : a = 0 then ha.symm \u25b8 (@C_0 K _).symm \u25b8 splits_zero i\nelse\nhave hia : i a \u2260 0, from mt ((injective_iff_map_eq_zero i).1 i.injective _) ha,\nor.inr $ \u03bb g hg \u27e8p, hp\u27e9, absurd hg.1 (not_not.2 (is_unit_iff_degree_eq_zero.2 $\n  by have := congr_arg degree hp;\n    simp [degree_C hia, @eq_comm (with_bot \u2115) 0,\n      nat.with_bot.add_eq_zero_iff] at this; clear _fun_match; tauto))\n\nlemma splits_of_degree_eq_one {f : K[X]} (hf : degree f = 1) : splits i f :=\nor.inr $ \u03bb g hg \u27e8p, hp\u27e9,\n  by have := congr_arg degree hp;\n  simp [nat.with_bot.add_eq_one_iff, hf, @eq_comm (with_bot \u2115) 1,\n    mt is_unit_iff_degree_eq_zero.2 hg.1] at this;\n  clear _fun_match; tauto\n\nlemma splits_of_degree_le_one {f : K[X]} (hf : degree f \u2264 1) : splits i f :=\nbegin\n  cases h : degree f with n,\n  { rw [degree_eq_bot.1 h]; exact splits_zero i },\n  { cases n with n,\n    { rw [eq_C_of_degree_le_zero (trans_rel_right (\u2264) h le_rfl)];\n      exact splits_C _ _ },\n    { have hn : n = 0,\n      { rw h at hf,\n        cases n, { refl }, { exact absurd hf dec_trivial } },\n      exact splits_of_degree_eq_one _ (by rw [h, hn]; refl) } }\nend\n\nlemma splits_of_nat_degree_le_one {f : K[X]} (hf : nat_degree f \u2264 1) : splits i f :=\nsplits_of_degree_le_one i (degree_le_of_nat_degree_le hf)\n\nlemma splits_of_nat_degree_eq_one {f : K[X]} (hf : nat_degree f = 1) : splits i f :=\nsplits_of_nat_degree_le_one i (le_of_eq hf)\n\nlemma splits_mul {f g : K[X]} (hf : splits i f) (hg : splits i g) : splits i (f * g) :=\nif h : f * g = 0 then by simp [h]\nelse or.inr $ \u03bb p hp hpf, ((principal_ideal_ring.irreducible_iff_prime.1 hp).2.2 _ _\n    (show p \u2223 map i f * map i g, by convert hpf; rw polynomial.map_mul)).elim\n  (hf.resolve_left (\u03bb hf, by simpa [hf] using h) hp)\n  (hg.resolve_left (\u03bb hg, by simpa [hg] using h) hp)\n\nlemma splits_of_splits_mul {f g : K[X]} (hfg : f * g \u2260 0) (h : splits i (f * g)) :\n  splits i f \u2227 splits i g :=\n\u27e8or.inr $ \u03bb g hgi hg, or.resolve_left h hfg hgi\n   (by rw polynomial.map_mul; exact hg.trans (dvd_mul_right _ _)),\n or.inr $ \u03bb g hgi hg, or.resolve_left h hfg hgi\n   (by rw polynomial.map_mul; exact hg.trans (dvd_mul_left _ _))\u27e9\n\nlemma splits_of_splits_of_dvd {f g : K[X]} (hf0 : f \u2260 0) (hf : splits i f) (hgf : g \u2223 f) :\n  splits i g :=\nby { obtain \u27e8f, rfl\u27e9 := hgf, exact (splits_of_splits_mul i hf0 hf).1 }\n\nlemma splits_of_splits_gcd_left {f g : K[X]} (hf0 : f \u2260 0) (hf : splits i f) :\n  splits i (euclidean_domain.gcd f g) :=\npolynomial.splits_of_splits_of_dvd i hf0 hf (euclidean_domain.gcd_dvd_left f g)\n\nlemma splits_of_splits_gcd_right {f g : K[X]} (hg0 : g \u2260 0) (hg : splits i g) :\n  splits i (euclidean_domain.gcd f g) :=\npolynomial.splits_of_splits_of_dvd i hg0 hg (euclidean_domain.gcd_dvd_right f g)\n\nlemma splits_map_iff (j : L \u2192+* F) {f : K[X]} :\n  splits j (f.map i) \u2194 splits (j.comp i) f :=\nby simp [splits, polynomial.map_map]\n\ntheorem splits_one : splits i 1 :=\nsplits_C i 1\n\ntheorem splits_of_is_unit {u : K[X]} (hu : is_unit u) : u.splits i :=\nsplits_of_splits_of_dvd i one_ne_zero (splits_one _) $ is_unit_iff_dvd_one.1 hu\n\ntheorem splits_X_sub_C {x : K} : (X - C x).splits i :=\nsplits_of_degree_eq_one _ $ degree_X_sub_C x\n\ntheorem splits_X : X.splits i :=\nsplits_of_degree_eq_one _ $ degree_X\n\ntheorem splits_id_iff_splits {f : K[X]} :\n  (f.map i).splits (ring_hom.id L) \u2194 f.splits i :=\nby rw [splits_map_iff, ring_hom.id_comp]\n\ntheorem splits_mul_iff {f g : K[X]} (hf : f \u2260 0) (hg : g \u2260 0) :\n  (f * g).splits i \u2194 f.splits i \u2227 g.splits i :=\n\u27e8splits_of_splits_mul i (mul_ne_zero hf hg), \u03bb \u27e8hfs, hgs\u27e9, splits_mul i hfs hgs\u27e9\n\ntheorem splits_prod {\u03b9 : Type u} {s : \u03b9 \u2192 K[X]} {t : finset \u03b9} :\n  (\u2200 j \u2208 t, (s j).splits i) \u2192 (\u220f x in t, s x).splits i :=\nbegin\n  refine finset.induction_on t (\u03bb _, splits_one i) (\u03bb a t hat ih ht, _),\n  rw finset.forall_mem_insert at ht, rw finset.prod_insert hat,\n  exact splits_mul i ht.1 (ih ht.2)\nend\n\nlemma splits_pow {f : K[X]} (hf : f.splits i) (n : \u2115) : (f ^ n).splits i :=\nbegin\n  rw [\u2190finset.card_range n, \u2190finset.prod_const],\n  exact splits_prod i (\u03bb j hj, hf),\nend\n\nlemma splits_X_pow (n : \u2115) : (X ^ n).splits i := splits_pow i (splits_X i) n\n\ntheorem splits_prod_iff {\u03b9 : Type u} {s : \u03b9 \u2192 K[X]} {t : finset \u03b9} :\n  (\u2200 j \u2208 t, s j \u2260 0) \u2192 ((\u220f x in t, s x).splits i \u2194 \u2200 j \u2208 t, (s j).splits i) :=\nbegin\n  refine finset.induction_on t (\u03bb _, \u27e8\u03bb _ _ h, h.elim, \u03bb _, splits_one i\u27e9) (\u03bb a t hat ih ht, _),\n  rw finset.forall_mem_insert at ht \u22a2,\n  rw [finset.prod_insert hat, splits_mul_iff i ht.1 (finset.prod_ne_zero_iff.2 ht.2), ih ht.2]\nend\n\nlemma degree_eq_one_of_irreducible_of_splits {p : L[X]}\n  (hp : irreducible p) (hp_splits : splits (ring_hom.id L) p) :\n  p.degree = 1 :=\nbegin\n  by_cases h_nz : p = 0,\n  { exfalso, simp * at *, },\n  rcases hp_splits,\n  { contradiction },\n  { apply hp_splits hp, simp }\nend\n\nlemma exists_root_of_splits {f : K[X]} (hs : splits i f) (hf0 : degree f \u2260 0) :\n  \u2203 x, eval\u2082 i x f = 0 :=\nif hf0 : f = 0 then by simp [hf0]\nelse\n  let \u27e8g, hg\u27e9 := wf_dvd_monoid.exists_irreducible_factor\n    (show \u00ac is_unit (f.map i), from mt is_unit_iff_degree_eq_zero.1 (by rwa degree_map))\n    (map_ne_zero hf0) in\n  let \u27e8x, hx\u27e9 := exists_root_of_degree_eq_one (hs.resolve_left hf0 hg.1 hg.2) in\n  let \u27e8i, hi\u27e9 := hg.2 in\n  \u27e8x, by rw [\u2190 eval_map, hi, eval_mul, show _ = _, from hx, zero_mul]\u27e9\n\nlemma roots_ne_zero_of_splits {f : K[X]} (hs : splits i f) (hf0 : nat_degree f \u2260 0) :\n  (f.map i).roots \u2260 0 :=\nlet \u27e8x, hx\u27e9 := exists_root_of_splits i hs (\u03bb h, hf0 $ nat_degree_eq_of_degree_eq_some h) in\n\u03bb h, by { rw \u2190 eval_map at hx,\n  cases h.subst ((mem_roots _).2 hx), exact map_ne_zero (\u03bb h, (h.subst hf0) rfl) }\n\n/-- Pick a root of a polynomial that splits. -/\ndef root_of_splits {f : K[X]} (hf : f.splits i) (hfd : f.degree \u2260 0) : L :=\nclassical.some $ exists_root_of_splits i hf hfd\n\ntheorem map_root_of_splits {f : K[X]} (hf : f.splits i) (hfd) :\n  f.eval\u2082 i (root_of_splits i hf hfd) = 0 :=\nclassical.some_spec $ exists_root_of_splits i hf hfd\n\nlemma nat_degree_eq_card_roots {p : K[X]} {i : K \u2192+* L}\n  (hsplit : splits i p) : p.nat_degree = (p.map i).roots.card :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, nat_degree_zero, polynomial.map_zero, roots_zero, multiset.card_zero] },\n  obtain \u27e8q, he, hd, hr\u27e9 := exists_prod_multiset_X_sub_C_mul (p.map i),\n  rw [\u2190 splits_id_iff_splits, \u2190 he] at hsplit,\n  have hpm : p.map i \u2260 0 := map_ne_zero hp, rw \u2190 he at hpm,\n  have hq : q \u2260 0 := \u03bb h, hpm (by rw [h, mul_zero]),\n  rw [\u2190 nat_degree_map i, \u2190 hd, add_right_eq_self],\n  by_contra,\n  have := roots_ne_zero_of_splits (ring_hom.id L) (splits_of_splits_mul _ _ hsplit).2 h,\n  { rw map_id at this, exact this hr },\n  { exact mul_ne_zero monic_prod_multiset_X_sub_C.ne_zero hq },\nend\n\nlemma degree_eq_card_roots {p : K[X]} {i : K \u2192+* L} (p_ne_zero : p \u2260 0)\n  (hsplit : splits i p) : p.degree = (p.map i).roots.card :=\nby rw [degree_eq_nat_degree p_ne_zero, nat_degree_eq_card_roots hsplit]\n\ntheorem roots_map {f : K[X]} (hf : f.splits $ ring_hom.id K) :\n  (f.map i).roots = f.roots.map i :=\n(roots_map_of_injective_card_eq_total_degree i.injective $\n  by { convert (nat_degree_eq_card_roots hf).symm, rw map_id }).symm\n\nlemma eq_prod_roots_of_splits {p : K[X]} {i : K \u2192+* L} (hsplit : splits i p) :\n  p.map i = C (i p.leading_coeff) * ((p.map i).roots.map (\u03bb a, X - C a)).prod :=\nbegin\n  rw \u2190 leading_coeff_map, symmetry,\n  apply C_leading_coeff_mul_prod_multiset_X_sub_C,\n  rw nat_degree_map, exact (nat_degree_eq_card_roots hsplit).symm,\nend\n\nlemma eq_prod_roots_of_splits_id {p : K[X]}\n  (hsplit : splits (ring_hom.id K) p) :\n  p = C p.leading_coeff * (p.roots.map (\u03bb a, X - C a)).prod :=\nby simpa using eq_prod_roots_of_splits hsplit\n\nlemma eq_prod_roots_of_monic_of_splits_id {p : K[X]}\n  (m : monic p) (hsplit : splits (ring_hom.id K) p) :\n  p = (p.roots.map (\u03bb a, X - C a)).prod :=\nbegin\n  convert eq_prod_roots_of_splits_id hsplit,\n  simp [m],\nend\n\nlemma eq_X_sub_C_of_splits_of_single_root {x : K} {h : K[X]} (h_splits : splits i h)\n  (h_roots : (h.map i).roots = {i x}) : h = C h.leading_coeff * (X - C x) :=\nbegin\n  apply polynomial.map_injective _ i.injective,\n  rw [eq_prod_roots_of_splits h_splits, h_roots],\n  simp,\nend\n\nsection UFD\n\nlocal attribute [instance, priority 10] principal_ideal_ring.to_unique_factorization_monoid\nlocal infix ` ~\u1d64 ` : 50 := associated\n\nopen unique_factorization_monoid associates\n\nlemma splits_of_exists_multiset {f : K[X]} {s : multiset L}\n  (hs : f.map i = C (i f.leading_coeff) * (s.map (\u03bb a : L, X - C a)).prod) :\n  splits i f :=\nif hf0 : f = 0 then or.inl hf0\nelse or.inr $ \u03bb p hp hdp, begin\n  rw irreducible_iff_prime at hp,\n  rw [hs, \u2190 multiset.prod_to_list] at hdp,\n  obtain (hd|hd) := hp.2.2 _ _ hdp,\n  { refine (hp.2.1 $ is_unit_of_dvd_unit hd _).elim,\n    exact is_unit_C.2 ((leading_coeff_ne_zero.2 hf0).is_unit.map i) },\n  { obtain \u27e8q, hq, hd\u27e9 := hp.dvd_prod_iff.1 hd,\n    obtain \u27e8a, ha, rfl\u27e9 := multiset.mem_map.1 ((multiset.mem_to_list _ _).1 hq),\n    rw degree_eq_degree_of_associated ((hp.dvd_prime_iff_associated $ prime_X_sub_C a).1 hd),\n    exact degree_X_sub_C a },\nend\n\nlemma splits_of_splits_id {f : K[X]} : splits (ring_hom.id _) f \u2192 splits i f :=\nunique_factorization_monoid.induction_on_prime f (\u03bb _, splits_zero _)\n  (\u03bb _ hu _, splits_of_degree_le_one _\n    ((is_unit_iff_degree_eq_zero.1 hu).symm \u25b8 dec_trivial))\n  (\u03bb a p ha0 hp ih hfi, splits_mul _\n    (splits_of_degree_eq_one _\n      ((splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).1.resolve_left\n        hp.1 hp.irreducible (by rw map_id)))\n    (ih (splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).2))\n\nend UFD\n\nlemma splits_iff_exists_multiset {f : K[X]} : splits i f \u2194\n  \u2203 (s : multiset L), f.map i = C (i f.leading_coeff) * (s.map (\u03bb a : L, X - C a)).prod :=\n\u27e8\u03bb hf, \u27e8(f.map i).roots, eq_prod_roots_of_splits hf\u27e9, \u03bb \u27e8s, hs\u27e9, splits_of_exists_multiset i hs\u27e9\n\nlemma splits_comp_of_splits (j : L \u2192+* F) {f : K[X]}\n  (h : splits i f) : splits (j.comp i) f :=\nbegin\n  change i with ((ring_hom.id _).comp i) at h,\n  rw [\u2190 splits_map_iff],\n  rw [\u2190 splits_map_iff i] at h,\n  exact splits_of_splits_id _ h\nend\n\n/-- A polynomial splits if and only if it has as many roots as its degree. -/\nlemma splits_iff_card_roots {p : K[X]} :\n  splits (ring_hom.id K) p \u2194 p.roots.card = p.nat_degree :=\nbegin\n  split,\n  { intro H, rw [nat_degree_eq_card_roots H, map_id] },\n  { intro hroots,\n    rw splits_iff_exists_multiset (ring_hom.id K),\n    use p.roots,\n    simp only [ring_hom.id_apply, map_id],\n    exact (C_leading_coeff_mul_prod_multiset_X_sub_C hroots).symm },\nend\n\nlemma aeval_root_derivative_of_splits [algebra K L] {P : K[X]} (hmo : P.monic)\n  (hP : P.splits (algebra_map K L)) {r : L} (hr : r \u2208 (P.map (algebra_map K L)).roots) :\n  aeval r P.derivative = (((P.map $ algebra_map K L).roots.erase r).map (\u03bb a, r - a)).prod :=\nbegin\n  replace hmo := hmo.map (algebra_map K L),\n  replace hP := (splits_id_iff_splits (algebra_map K L)).2 hP,\n  rw [aeval_def, \u2190 eval_map, \u2190 derivative_map],\n  nth_rewrite 0 [eq_prod_roots_of_monic_of_splits_id hmo hP],\n  rw [eval_multiset_prod_X_sub_C_derivative hr]\nend\n\n/-- If `P` is a monic polynomial that splits, then `coeff P 0` equals the product of the roots. -/\nlemma prod_roots_eq_coeff_zero_of_monic_of_split {P : K[X]} (hmo : P.monic)\n  (hP : P.splits (ring_hom.id K)) : coeff P 0 = (-1) ^ P.nat_degree * P.roots.prod :=\nbegin\n  nth_rewrite 0 [eq_prod_roots_of_monic_of_splits_id hmo hP],\n  rw [coeff_zero_eq_eval_zero, eval_multiset_prod, multiset.map_map],\n  simp_rw [function.comp_app, eval_sub, eval_X, zero_sub, eval_C],\n  conv_lhs { congr, congr, funext,\n    rw [neg_eq_neg_one_mul] },\n  rw [multiset.prod_map_mul, multiset.map_const, multiset.prod_repeat, multiset.map_id',\n    splits_iff_card_roots.1 hP]\nend\n\n/-- If `P` is a monic polynomial that splits, then `P.next_coeff` equals the sum of the roots. -/\nlemma sum_roots_eq_next_coeff_of_monic_of_split {P : K[X]} (hmo : P.monic)\n  (hP : P.splits (ring_hom.id K)) : P.next_coeff = - P.roots.sum :=\nbegin\n  nth_rewrite 0 [eq_prod_roots_of_monic_of_splits_id hmo hP],\n  rw [monic.next_coeff_multiset_prod _ _ (\u03bb a ha, _)],\n  { simp_rw [next_coeff_X_sub_C, multiset.sum_map_neg'] },\n  { exact monic_X_sub_C a }\nend\n\nend splits\n\nend polynomial\n\n\nsection embeddings\n\nvariables (F) [field F]\n\n/-- If `p` is the minimal polynomial of `a` over `F` then `F[a] \u2243\u2090[F] F[x]/(p)` -/\ndef alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly\n  {R : Type*} [comm_ring R] [algebra F R] (x : R) :\n  algebra.adjoin F ({x} : set R) \u2243\u2090[F] adjoin_root (minpoly F x) :=\nalg_equiv.symm $ alg_equiv.of_bijective\n  (alg_hom.cod_restrict\n    (adjoin_root.lift_hom _ x $ minpoly.aeval F x) _\n    (\u03bb p, adjoin_root.induction_on _ p $ \u03bb p,\n      (algebra.adjoin_singleton_eq_range_aeval F x).symm \u25b8\n        (polynomial.aeval _).mem_range.mpr \u27e8p, rfl\u27e9))\n  \u27e8(alg_hom.injective_cod_restrict _ _ _).2 $ (injective_iff_map_eq_zero _).2 $ \u03bb p,\n    adjoin_root.induction_on _ p $ \u03bb p hp, ideal.quotient.eq_zero_iff_mem.2 $\n    ideal.mem_span_singleton.2 $ minpoly.dvd F x hp,\n  \u03bb y,\n    let \u27e8p, hp\u27e9 := (set_like.ext_iff.1\n      (algebra.adjoin_singleton_eq_range_aeval F x) (y : R)).1 y.2 in\n    \u27e8adjoin_root.mk _ p, subtype.eq hp\u27e9\u27e9\n\nopen finset\n\n/-- If a `subalgebra` is finite_dimensional as a submodule then it is `finite_dimensional`. -/\nlemma finite_dimensional.of_subalgebra_to_submodule\n  {K V : Type*} [field K] [ring V] [algebra K V] {s : subalgebra K V}\n  (h : finite_dimensional K s.to_submodule) : finite_dimensional K s := h\n\n/-- If `K` and `L` are field extensions of `F` and we have `s : finset K` such that\nthe minimal polynomial of each `x \u2208 s` splits in `L` then `algebra.adjoin F s` embeds in `L`. -/\ntheorem lift_of_splits {F K L : Type*} [field F] [field K] [field L]\n  [algebra F K] [algebra F L] (s : finset K) :\n  (\u2200 x \u2208 s, is_integral F x \u2227 polynomial.splits (algebra_map F L) (minpoly F x)) \u2192\n  nonempty (algebra.adjoin F (\u2191s : set K) \u2192\u2090[F] L) :=\nbegin\n  refine finset.induction_on s (\u03bb H, _) (\u03bb a s has ih H, _),\n  { rw [coe_empty, algebra.adjoin_empty],\n    exact \u27e8(algebra.of_id F L).comp (algebra.bot_equiv F K)\u27e9 },\n  rw forall_mem_insert at H, rcases H with \u27e8\u27e8H1, H2\u27e9, H3\u27e9, cases ih H3 with f,\n  choose H3 H4 using H3,\n  rw [coe_insert, set.insert_eq, set.union_comm, algebra.adjoin_union_eq_adjoin_adjoin],\n  letI := (f : algebra.adjoin F (\u2191s : set K) \u2192+* L).to_algebra,\n  haveI : finite_dimensional F (algebra.adjoin F (\u2191s : set K)) := (\n    (submodule.fg_iff_finite_dimensional _).1\n      (fg_adjoin_of_finite (set.finite_mem_finset s) H3)).of_subalgebra_to_submodule,\n  letI := field_of_finite_dimensional F (algebra.adjoin F (\u2191s : set K)),\n  have H5 : is_integral (algebra.adjoin F (\u2191s : set K)) a := is_integral_of_is_scalar_tower a H1,\n  have H6 : (minpoly (algebra.adjoin F (\u2191s : set K)) a).splits\n    (algebra_map (algebra.adjoin F (\u2191s : set K)) L),\n  { refine polynomial.splits_of_splits_of_dvd _\n      (polynomial.map_ne_zero $ minpoly.ne_zero H1 :\n        polynomial.map (algebra_map _ _) _ \u2260 0)\n      ((polynomial.splits_map_iff _ _).2 _)\n      (minpoly.dvd _ _ _),\n    { rw \u2190 is_scalar_tower.algebra_map_eq, exact H2 },\n    { rw [\u2190 is_scalar_tower.aeval_apply, minpoly.aeval] } },\n  obtain \u27e8y, hy\u27e9 := polynomial.exists_root_of_splits _ H6 (ne_of_lt (minpoly.degree_pos H5)).symm,\n  refine \u27e8subalgebra.of_restrict_scalars _ _ _\u27e9,\n  refine (adjoin_root.lift_hom (minpoly (algebra.adjoin F (\u2191s : set K)) a) y hy).comp _,\n  exact alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly (algebra.adjoin F (\u2191s : set K)) a\nend\n\nend embeddings\n\n\nnamespace polynomial\n\nvariables [field K] [field L] [field F]\nopen polynomial\n\nsection splitting_field\n\n/-- Non-computably choose an irreducible factor from a polynomial. -/\ndef factor (f : K[X]) : K[X] :=\nif H : \u2203 g, irreducible g \u2227 g \u2223 f then classical.some H else X\n\ninstance irreducible_factor (f : K[X]) : irreducible (factor f) :=\nbegin\n  rw factor, split_ifs with H, { exact (classical.some_spec H).1 }, { exact irreducible_X }\nend\n\ntheorem factor_dvd_of_not_is_unit {f : K[X]} (hf1 : \u00acis_unit f) : factor f \u2223 f :=\nbegin\n  by_cases hf2 : f = 0, { rw hf2, exact dvd_zero _ },\n  rw [factor, dif_pos (wf_dvd_monoid.exists_irreducible_factor hf1 hf2)],\n  exact (classical.some_spec $ wf_dvd_monoid.exists_irreducible_factor hf1 hf2).2\nend\n\ntheorem factor_dvd_of_degree_ne_zero {f : K[X]} (hf : f.degree \u2260 0) : factor f \u2223 f :=\nfactor_dvd_of_not_is_unit (mt degree_eq_zero_of_is_unit hf)\n\ntheorem factor_dvd_of_nat_degree_ne_zero {f : K[X]} (hf : f.nat_degree \u2260 0) :\n  factor f \u2223 f :=\nfactor_dvd_of_degree_ne_zero (mt nat_degree_eq_of_degree_eq_some hf)\n\n/-- Divide a polynomial f by X - C r where r is a root of f in a bigger field extension. -/\ndef remove_factor (f : K[X]) : polynomial (adjoin_root $ factor f) :=\nmap (adjoin_root.of f.factor) f /\u2098 (X - C (adjoin_root.root f.factor))\n\ntheorem X_sub_C_mul_remove_factor (f : K[X]) (hf : f.nat_degree \u2260 0) :\n  (X - C (adjoin_root.root f.factor)) * f.remove_factor = map (adjoin_root.of f.factor) f :=\nlet \u27e8g, hg\u27e9 := factor_dvd_of_nat_degree_ne_zero hf in\nmul_div_by_monic_eq_iff_is_root.2 $ by rw [is_root.def, eval_map, hg, eval\u2082_mul, \u2190 hg,\n    adjoin_root.eval\u2082_root, zero_mul]\n\ntheorem nat_degree_remove_factor (f : K[X]) :\n  f.remove_factor.nat_degree = f.nat_degree - 1 :=\nby rw [remove_factor, nat_degree_div_by_monic _ (monic_X_sub_C _), nat_degree_map,\n       nat_degree_X_sub_C]\n\ntheorem nat_degree_remove_factor' {f : K[X]} {n : \u2115} (hfn : f.nat_degree = n+1) :\n  f.remove_factor.nat_degree = n :=\nby rw [nat_degree_remove_factor, hfn, n.add_sub_cancel]\n\n/-- Auxiliary construction to a splitting field of a polynomial. Uses induction on the degree. -/\ndef splitting_field_aux (n : \u2115) : \u03a0 {K : Type u} [field K], by exactI \u03a0 (f : K[X]),\n  f.nat_degree = n \u2192 Type u :=\nnat.rec_on n (\u03bb K _ _ _, K) $ \u03bb n ih K _ f hf, by exactI\nih f.remove_factor (nat_degree_remove_factor' hf)\n\nnamespace splitting_field_aux\n\ntheorem succ (n : \u2115) (f : K[X]) (hfn : f.nat_degree = n + 1) :\n  splitting_field_aux (n+1) f hfn =\n    splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn) := rfl\n\ninstance field (n : \u2115) : \u03a0 {K : Type u} [field K], by exactI\n  \u03a0 {f : K[X]} (hfn : f.nat_degree = n), field (splitting_field_aux n f hfn) :=\nnat.rec_on n (\u03bb K _ _ _, \u2039field K\u203a) $ \u03bb n ih K _ f hf, ih _\n\ninstance inhabited {n : \u2115} {f : K[X]} (hfn : f.nat_degree = n) :\n  inhabited (splitting_field_aux n f hfn) := \u27e837\u27e9\n\n/-\nNote that the recursive nature of this definition and `splitting_field_aux.field` creates\nnon-definitionally-equal diamonds in the `\u2115`- and `\u2124`- actions.\n```lean\nexample (n : \u2115) {K : Type u} [field K] {f : K[X]} (hfn : f.nat_degree = n) :\n    (add_comm_monoid.nat_module : module \u2115 (splitting_field_aux n f hfn)) =\n  @algebra.to_module _ _ _ _ (splitting_field_aux.algebra n _ hfn) :=\nrfl  -- fails\n```\nIt's not immediately clear whether this _can_ be fixed; the failure is much the same as the reason\nthat the following fails:\n```lean\ndef cases_twice {\u03b1} (a\u2080 a\u2099 : \u03b1) : \u2115 \u2192 \u03b1 \u00d7 \u03b1\n| 0 := (a\u2080, a\u2080)\n| (n + 1) := (a\u2099, a\u2099)\n\nexample (x : \u2115) {\u03b1} (a\u2080 a\u2099 : \u03b1) : (cases_twice a\u2080 a\u2099 x).1 = (cases_twice a\u2080 a\u2099 x).2 := rfl  -- fails\n```\nWe don't really care at this point because this is an implementation detail (which is why this is\nnot a docstring), but we do in `splitting_field.algebra'` below. -/\ninstance algebra (n : \u2115) : \u03a0 (R : Type*) {K : Type u} [comm_semiring R] [field K],\n  by exactI \u03a0 [algebra R K] {f : K[X]} (hfn : f.nat_degree = n),\n    algebra R (splitting_field_aux n f hfn) :=\nnat.rec_on n (\u03bb R K _ _ _ _ _, by exactI \u2039algebra R K\u203a) $\n         \u03bb n ih R K _ _ _ f hfn, by exactI ih R (nat_degree_remove_factor' hfn)\n\ninstance is_scalar_tower (n : \u2115) : \u03a0 (R\u2081 R\u2082 : Type*) {K : Type u}\n  [comm_semiring R\u2081] [comm_semiring R\u2082] [has_scalar R\u2081 R\u2082] [field K],\n  by exactI \u03a0 [algebra R\u2081 K] [algebra R\u2082 K],\n  by exactI \u03a0 [is_scalar_tower R\u2081 R\u2082 K] {f : K[X]} (hfn : f.nat_degree = n),\n    is_scalar_tower R\u2081 R\u2082 (splitting_field_aux n f hfn) :=\nnat.rec_on n (\u03bb R\u2081 R\u2082 K _ _ _ _ _ _ _ _ _, by exactI \u2039is_scalar_tower R\u2081 R\u2082 K\u203a) $\n         \u03bb n ih R\u2081 R\u2082 K _ _ _ _ _ _ _ f hfn, by exactI ih R\u2081 R\u2082 (nat_degree_remove_factor' hfn)\n\ninstance algebra''' {n : \u2115} {f : K[X]} (hfn : f.nat_degree = n + 1) :\n  algebra (adjoin_root f.factor)\n    (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)) :=\nsplitting_field_aux.algebra n _ _\n\ninstance algebra' {n : \u2115} {f : K[X]} (hfn : f.nat_degree = n + 1) :\n  algebra (adjoin_root f.factor) (splitting_field_aux n.succ f hfn) :=\nsplitting_field_aux.algebra''' _\n\ninstance algebra'' {n : \u2115} {f : K[X]} (hfn : f.nat_degree = n + 1) :\n  algebra K (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)) :=\nsplitting_field_aux.algebra n K _\n\ninstance scalar_tower' {n : \u2115} {f : K[X]} (hfn : f.nat_degree = n + 1) :\n  is_scalar_tower K (adjoin_root f.factor)\n    (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)) :=\nbegin\n  -- finding this instance ourselves makes things faster\n  haveI : is_scalar_tower K (adjoin_root f.factor) (adjoin_root f.factor) :=\n    is_scalar_tower.right,\n  exact\n    splitting_field_aux.is_scalar_tower n K (adjoin_root f.factor) (nat_degree_remove_factor' hfn),\nend\n\ninstance scalar_tower {n : \u2115} {f : K[X]} (hfn : f.nat_degree = n + 1) :\n  is_scalar_tower K (adjoin_root f.factor) (splitting_field_aux _ f hfn) :=\nsplitting_field_aux.scalar_tower' _\n\ntheorem algebra_map_succ (n : \u2115) (f : K[X]) (hfn : f.nat_degree = n + 1) :\n  by exact algebra_map K (splitting_field_aux _ _ hfn) =\n    (algebra_map (adjoin_root f.factor)\n        (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn))).comp\n      (adjoin_root.of f.factor) :=\nis_scalar_tower.algebra_map_eq _ _ _\n\nprotected theorem splits (n : \u2115) : \u2200 {K : Type u} [field K], by exactI\n  \u2200 (f : K[X]) (hfn : f.nat_degree = n),\n    splits (algebra_map K $ splitting_field_aux n f hfn) f :=\nnat.rec_on n (\u03bb K _ _ hf, by exactI splits_of_degree_le_one _\n  (le_trans degree_le_nat_degree $ hf.symm \u25b8 with_bot.coe_le_coe.2 zero_le_one)) $ \u03bb n ih K _ f hf,\nby { resetI, rw [\u2190 splits_id_iff_splits, algebra_map_succ, \u2190 map_map, splits_id_iff_splits,\n    \u2190 X_sub_C_mul_remove_factor f (\u03bb h, by { rw h at hf, cases hf })],\nexact splits_mul _ (splits_X_sub_C _) (ih _ _) }\n\ntheorem exists_lift (n : \u2115) : \u2200 {K : Type u} [field K], by exactI\n  \u2200 (f : K[X]) (hfn : f.nat_degree = n) {L : Type*} [field L], by exactI\n    \u2200 (j : K \u2192+* L) (hf : splits j f), \u2203 k : splitting_field_aux n f hfn \u2192+* L,\n      k.comp (algebra_map _ _) = j :=\nnat.rec_on n (\u03bb K _ _ _ L _ j _, by exactI \u27e8j, j.comp_id\u27e9) $ \u03bb n ih K _ f hf L _ j hj, by exactI\nhave hndf : f.nat_degree \u2260 0, by { intro h, rw h at hf, cases hf },\nhave hfn0 : f \u2260 0, by { intro h, rw h at hndf, exact hndf rfl },\nlet \u27e8r, hr\u27e9 := exists_root_of_splits _ (splits_of_splits_of_dvd j hfn0 hj\n  (factor_dvd_of_nat_degree_ne_zero hndf))\n  (mt is_unit_iff_degree_eq_zero.2 f.irreducible_factor.1) in\nhave hmf0 : map (adjoin_root.of f.factor) f \u2260 0, from map_ne_zero hfn0,\nhave hsf : splits (adjoin_root.lift j r hr) f.remove_factor,\nby { rw \u2190 X_sub_C_mul_remove_factor _ hndf at hmf0, refine (splits_of_splits_mul _ hmf0 _).2,\n  rwa [X_sub_C_mul_remove_factor _ hndf, \u2190 splits_id_iff_splits, map_map, adjoin_root.lift_comp_of,\n      splits_id_iff_splits] },\nlet \u27e8k, hk\u27e9 := ih f.remove_factor (nat_degree_remove_factor' hf) (adjoin_root.lift j r hr) hsf in\n\u27e8k, by rw [algebra_map_succ, \u2190 ring_hom.comp_assoc, hk, adjoin_root.lift_comp_of]\u27e9\n\ntheorem adjoin_roots (n : \u2115) : \u2200 {K : Type u} [field K], by exactI\n  \u2200 (f : K[X]) (hfn : f.nat_degree = n),\n    algebra.adjoin K (\u2191(f.map $ algebra_map K $ splitting_field_aux n f hfn).roots.to_finset :\n      set (splitting_field_aux n f hfn)) = \u22a4 :=\nnat.rec_on n (\u03bb K _ f hf, by exactI algebra.eq_top_iff.2 (\u03bb x, subalgebra.range_le _ \u27e8x, rfl\u27e9)) $\n\u03bb n ih K _ f hfn, by exactI\nhave hndf : f.nat_degree \u2260 0, by { intro h, rw h at hfn, cases hfn },\nhave hfn0 : f \u2260 0, by { intro h, rw h at hndf, exact hndf rfl },\nhave hmf0 : map (algebra_map K (splitting_field_aux n.succ f hfn)) f \u2260 0 := map_ne_zero hfn0,\nby { rw [algebra_map_succ, \u2190 map_map, \u2190 X_sub_C_mul_remove_factor _ hndf,\n         polynomial.map_mul] at hmf0 \u22a2,\nrw [roots_mul hmf0, polynomial.map_sub, map_X, map_C, roots_X_sub_C, multiset.to_finset_add,\n    finset.coe_union, multiset.to_finset_singleton, finset.coe_singleton,\n    algebra.adjoin_union_eq_adjoin_adjoin, \u2190 set.image_singleton,\n    algebra.adjoin_algebra_map K (adjoin_root f.factor)\n      (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)),\n    adjoin_root.adjoin_root_eq_top, algebra.map_top,\n    is_scalar_tower.adjoin_range_to_alg_hom K (adjoin_root f.factor)\n      (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)),\n    ih, subalgebra.restrict_scalars_top] }\n\nend splitting_field_aux\n\n/-- A splitting field of a polynomial. -/\ndef splitting_field (f : K[X]) :=\nsplitting_field_aux _ f rfl\n\nnamespace splitting_field\n\nvariables (f : K[X])\n\ninstance : field (splitting_field f) :=\nsplitting_field_aux.field _ _\n\ninstance inhabited : inhabited (splitting_field f) := \u27e837\u27e9\n\n/-- This should be an instance globally, but it creates diamonds with the `\u2115` and `\u2124` actions:\n\n```lean\nexample :\n  (add_comm_monoid.nat_module : module \u2115 (splitting_field f)) =\n    @algebra.to_module _ _ _ _ (splitting_field.algebra' f) :=\nrfl  -- fails\n\nexample :\n  (add_comm_group.int_module _ : module \u2124 (splitting_field f)) =\n    @algebra.to_module _ _ _ _ (splitting_field.algebra' f) :=\nrfl  -- fails\n```\n\nUntil we resolve these diamonds, it's more convenient to only turn this instance on with\n`local attribute [instance]` in places where the benefit of having the instance outweighs the cost.\n\nIn the meantime, the `splitting_field.algebra` instance below is immune to these particular diamonds\nsince `K = \u2115` and `K = \u2124` are not possible due to the `field K` assumption. Diamonds in\n`algebra \u211a (splitting_field f)` instances are still possible, but this is a problem throughout the\nlibrary and not unique to this `algebra` instance.\n-/\ninstance algebra' {R} [comm_semiring R] [algebra R K] : algebra R (splitting_field f) :=\nsplitting_field_aux.algebra _ _ _\n\ninstance : algebra K (splitting_field f) :=\nsplitting_field_aux.algebra _ _ _\n\nprotected theorem splits : splits (algebra_map K (splitting_field f)) f :=\nsplitting_field_aux.splits _ _ _\n\nvariables [algebra K L] (hb : splits (algebra_map K L) f)\n\n/-- Embeds the splitting field into any other field that splits the polynomial. -/\ndef lift : splitting_field f \u2192\u2090[K] L :=\n{ commutes' := \u03bb r, by { have := classical.some_spec (splitting_field_aux.exists_lift _ _ _ _ hb),\n    exact ring_hom.ext_iff.1 this r },\n  .. classical.some (splitting_field_aux.exists_lift _ _ _ _ hb) }\n\ntheorem adjoin_roots : algebra.adjoin K\n    (\u2191(f.map (algebra_map K $ splitting_field f)).roots.to_finset : set (splitting_field f)) = \u22a4 :=\nsplitting_field_aux.adjoin_roots _ _ _\n\ntheorem adjoin_root_set : algebra.adjoin K (f.root_set f.splitting_field) = \u22a4 :=\nadjoin_roots f\n\nend splitting_field\n\nvariables (K L) [algebra K L]\n/-- Typeclass characterising splitting fields. -/\nclass is_splitting_field (f : K[X]) : Prop :=\n(splits [] : splits (algebra_map K L) f)\n(adjoin_roots [] : algebra.adjoin K (\u2191(f.map (algebra_map K L)).roots.to_finset : set L) = \u22a4)\n\nnamespace is_splitting_field\n\nvariables {K}\ninstance splitting_field (f : K[X]) : is_splitting_field K (splitting_field f) f :=\n\u27e8splitting_field.splits f, splitting_field.adjoin_roots f\u27e9\n\nsection scalar_tower\n\nvariables {K L F} [algebra F K] [algebra F L] [is_scalar_tower F K L]\n\nvariables {K}\ninstance map (f : F[X]) [is_splitting_field F L f] :\n  is_splitting_field K L (f.map $ algebra_map F K) :=\n\u27e8by { rw [splits_map_iff, \u2190 is_scalar_tower.algebra_map_eq], exact splits L f },\n subalgebra.restrict_scalars_injective F $\n  by { rw [map_map, \u2190 is_scalar_tower.algebra_map_eq, subalgebra.restrict_scalars_top,\n    eq_top_iff, \u2190 adjoin_roots L f, algebra.adjoin_le_iff],\n  exact \u03bb x hx, @algebra.subset_adjoin K _ _ _ _ _ _ hx }\u27e9\n\nvariables {K} (L)\ntheorem splits_iff (f : K[X]) [is_splitting_field K L f] :\n  polynomial.splits (ring_hom.id K) f \u2194 (\u22a4 : subalgebra K L) = \u22a5 :=\n\u27e8\u03bb h, eq_bot_iff.2 $ adjoin_roots L f \u25b8 (roots_map (algebra_map K L) h).symm \u25b8\n  algebra.adjoin_le_iff.2 (\u03bb y hy,\n    let \u27e8x, hxs, hxy\u27e9 := finset.mem_image.1 (by rwa multiset.to_finset_map at hy) in\n    hxy \u25b8 set_like.mem_coe.2 $ subalgebra.algebra_map_mem _ _),\n \u03bb h, @ring_equiv.to_ring_hom_refl K _ \u25b8\n  ring_equiv.self_trans_symm (ring_equiv.of_bijective _ $ algebra.bijective_algebra_map_iff.2 h) \u25b8\n  by { rw ring_equiv.to_ring_hom_trans, exact splits_comp_of_splits _ _ (splits L f) }\u27e9\n\ntheorem mul (f g : F[X]) (hf : f \u2260 0) (hg : g \u2260 0) [is_splitting_field F K f]\n  [is_splitting_field K L (g.map $ algebra_map F K)] :\n  is_splitting_field F L (f * g) :=\n\u27e8(is_scalar_tower.algebra_map_eq F K L).symm \u25b8 splits_mul _\n  (splits_comp_of_splits _ _ (splits K f))\n  ((splits_map_iff _ _).1 (splits L $ g.map $ algebra_map F K)),\n by rw [polynomial.map_mul, roots_mul (mul_ne_zero (map_ne_zero hf : f.map (algebra_map F L) \u2260 0)\n        (map_ne_zero hg)), multiset.to_finset_add, finset.coe_union,\n      algebra.adjoin_union_eq_adjoin_adjoin,\n      is_scalar_tower.algebra_map_eq F K L, \u2190 map_map,\n      roots_map (algebra_map K L) ((splits_id_iff_splits $ algebra_map F K).2 $ splits K f),\n      multiset.to_finset_map, finset.coe_image, algebra.adjoin_algebra_map, adjoin_roots,\n      algebra.map_top, is_scalar_tower.adjoin_range_to_alg_hom, \u2190 map_map, adjoin_roots,\n      subalgebra.restrict_scalars_top]\u27e9\n\nend scalar_tower\n\n/-- Splitting field of `f` embeds into any field that splits `f`. -/\ndef lift [algebra K F] (f : K[X]) [is_splitting_field K L f]\n  (hf : polynomial.splits (algebra_map K F) f) : L \u2192\u2090[K] F :=\nif hf0 : f = 0 then (algebra.of_id K F).comp $\n  (algebra.bot_equiv K L : (\u22a5 : subalgebra K L) \u2192\u2090[K] K).comp $\n  by { rw \u2190 (splits_iff L f).1 (show f.splits (ring_hom.id K), from hf0.symm \u25b8 splits_zero _),\n  exact algebra.to_top } else\nalg_hom.comp (by { rw \u2190 adjoin_roots L f, exact classical.choice (lift_of_splits _ $ \u03bb y hy,\n    have aeval y f = 0, from (eval\u2082_eq_eval_map _).trans $\n      (mem_roots $ by exact map_ne_zero hf0).1 (multiset.mem_to_finset.mp hy),\n    \u27e8is_algebraic_iff_is_integral.1 \u27e8f, hf0, this\u27e9,\n      splits_of_splits_of_dvd _ hf0 hf $ minpoly.dvd _ _ this\u27e9) })\n  algebra.to_top\n\ntheorem finite_dimensional (f : K[X]) [is_splitting_field K L f] : finite_dimensional K L :=\n\u27e8@algebra.top_to_submodule K L _ _ _ \u25b8 adjoin_roots L f \u25b8\n  fg_adjoin_of_finite (set.finite_mem_finset _) (\u03bb y hy,\n  if hf : f = 0\n  then by { rw [hf, polynomial.map_zero, roots_zero] at hy, cases hy }\n  else is_algebraic_iff_is_integral.1 \u27e8f, hf, (eval\u2082_eq_eval_map _).trans $\n    (mem_roots $ by exact map_ne_zero hf).1 (multiset.mem_to_finset.mp hy)\u27e9)\u27e9\n\ninstance (f : K[X]) : _root_.finite_dimensional K f.splitting_field :=\nfinite_dimensional f.splitting_field f\n\n/-- Any splitting field is isomorphic to `splitting_field f`. -/\ndef alg_equiv (f : K[X]) [is_splitting_field K L f] : L \u2243\u2090[K] splitting_field f :=\nbegin\n  refine alg_equiv.of_bijective (lift L f $ splits (splitting_field f) f)\n    \u27e8ring_hom.injective (lift L f $ splits (splitting_field f) f).to_ring_hom, _\u27e9,\n  haveI := finite_dimensional (splitting_field f) f,\n  haveI := finite_dimensional L f,\n  have : finite_dimensional.finrank K L = finite_dimensional.finrank K (splitting_field f) :=\n  le_antisymm\n    (linear_map.finrank_le_finrank_of_injective\n      (show function.injective (lift L f $ splits (splitting_field f) f).to_linear_map, from\n        ring_hom.injective (lift L f $ splits (splitting_field f) f : L \u2192+* f.splitting_field)))\n    (linear_map.finrank_le_finrank_of_injective\n      (show function.injective (lift (splitting_field f) f $ splits L f).to_linear_map, from\n        ring_hom.injective (lift (splitting_field f) f $ splits L f : f.splitting_field \u2192+* L))),\n  change function.surjective (lift L f $ splits (splitting_field f) f).to_linear_map,\n  refine (linear_map.injective_iff_surjective_of_finrank_eq_finrank this).1 _,\n  exact ring_hom.injective (lift L f $ splits (splitting_field f) f : L \u2192+* f.splitting_field)\nend\n\nend is_splitting_field\n\nend splitting_field\n\nend polynomial\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/field_theory/splitting_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7245450344513458}}
{"text": "import linear_algebra.determinant\nimport linear_algebra.matrix\nopen linear_map\nnotation f ` \u229a `:80 g:80  := linear_map.comp f g    \nuniverse variables u v w  w'\nopen matrix\nopen_locale big_operators matrix\n\nvariables {R : Type v} [comm_ring R] \nvariables {X : Type w} [fintype X] [decidable_eq X] \nvariables {Y : Type w} [fintype Y] [decidable_eq Y] \nvariables {Z : Type w} [fintype Z] [decidable_eq Z] \n/-! \n   Study of the operation `to_matrix`.\n   The file contain the classical operation of this function.     \n-/\nlemma proof_strategy (A B : matrix X Y R) : to_lin A = to_lin B \u2192 A = B :=\nbegin \n    intro hyp,\n    have RR : to_matrix (to_lin A) = to_matrix (to_lin B),\n        congr',\n    iterate 2 {rw  to_lin_to_matrix  at RR},\n    exact RR,   \nend\n/--\n    `(a * b) \u2022 M = a \u2022 (b \u2022 M)`\n-/\nlemma mul_smul_mat (a b : R ) (M : matrix X X R ) : (a * b) \u2022 M = a \u2022 (b \u2022 M) :=\nbegin\n    apply matrix.ext, intros, exact mul_smul a b (M i j),\nend\n/--\n    For composable morphism : \n    `to_matrix (\u03c8 \u229a \u03c6) =   to_matrix \u03c8  \u2b1d to_matrix \u03c6`\n-/\n@[simp]lemma to_matrix_mul (\u03c6 : (X \u2192 R) \u2192\u2097[R] (Y \u2192 R))(\u03c8 : (Y \u2192 R) \u2192\u2097[R] (Z \u2192 R))  : \n   to_matrix (\u03c8 \u229a \u03c6) =   to_matrix \u03c8  \u2b1d to_matrix \u03c6 := \nbegin\n    apply proof_strategy, erw to_matrix_to_lin,\n    rw mul_to_lin, rw to_matrix_to_lin, rw to_matrix_to_lin,\nend\n/--\n    `to_matrix (\u03c8 + \u03c6) =   to_matrix \u03c8  + to_matrix \u03c6`\n-/\n@[simp]lemma to_matrix_add (\u03c6 \u03c8  : (X \u2192 R) \u2192\u2097[R] (Y \u2192 R)) : \n            to_matrix (\u03c6 + \u03c8 ) = to_matrix (\u03c6 )+ to_matrix(\u03c8) :=\nbegin \n    --change linear_equiv_matrix'.to_fun _ = _ ,\n    --erw linear_equiv_matrix'.add, exact rfl,\n    apply proof_strategy,\n    rw to_matrix_to_lin,\n    rw to_lin_add, \n    rw to_matrix_to_lin, rw to_matrix_to_lin,\nend\n/-! \n    For composable morphism : \n    `to_matrix (\u03c8 \u229a \u03c6) =   to_matrix \u03c8  \u2b1d to_matrix \u03c6`\n-/\n\n@[simp]lemma to_matrix_smul (r : R) (\u03c6 : (X \u2192 R) \u2192\u2097[R] (Y \u2192 R))  : \n   to_matrix (r \u2022  \u03c6) =   r \u2022  (to_matrix \u03c6) := \nbegin\n    apply proof_strategy, \n    rw to_matrix_to_lin, \n    erw is_linear_map.smul (to_lin) (r) (to_matrix (\u03c6 )),\n    rw to_matrix_to_lin,\nend\n/-! \n    `to_matrix (0) =   0`\n-/\n@[simp] lemma to_matrix_zero : to_matrix (0 : (X \u2192 R) \u2192\u2097[R] (Y \u2192 R)) = 0 :=\nbegin \n    apply proof_strategy, rw to_matrix_to_lin, rw to_lin_zero,\nend\n/-!  \n    `to_matrix (1) =   1`\n-/\n@[simp] lemma to_matrix_one  : to_matrix (1 : (X \u2192 R) \u2192\u2097[R] (X \u2192 R)) = 1 :=\nbegin \n    apply proof_strategy,\n    rw to_matrix_to_lin,\n    rw to_lin_one, exact rfl,\nend\n/-! \n    `matrix.trace X R R (to_matrix (\u03c8  \u229a \u03c6 )) =  matrix.trace Y R R (to_matrix (\u03c6 \u229a \u03c8 ))`\n-/\n@[simp]lemma to_matrix_trace_comm (\u03c6 : (X \u2192 R) \u2192\u2097[R] (Y \u2192 R))(\u03c8 : (Y \u2192 R) \u2192\u2097[R] (X \u2192 R)) :\nmatrix.trace X R R (to_matrix (\u03c8  \u229a \u03c6 )) =  matrix.trace Y R R (to_matrix (\u03c6 \u229a \u03c8 )) := \nbegin \n    rw to_matrix_mul,\n    rw trace_mul_comm, rw \u2190 to_matrix_mul,\nend\n/--\n    `to_matrix (\u2211 w, \u03c6 w) = \u2211 w, to_matrix (\u03c6 w)`\n-/\nlemma to_matrix_sum {W : Type w'} [fintype W][decidable_eq W] (\u03c6 : W \u2192 (X \u2192 R) \u2192\u2097[R] (Y \u2192 R) ) : \nto_matrix (\u2211 w, \u03c6 w) = \u2211 w, to_matrix (\u03c6 w) := \nbegin \n    apply proof_strategy, rw to_matrix_to_lin,\n    rw \u2190  finset.sum_hom finset.univ  to_lin, \n    congr,funext,rw to_matrix_to_lin, by apply_instance,\nend\n/-!\n    `trace  (\u2211 w, \u03c6 w) = \u2211 w, trace (\u03c6 w)`\n-/\nlemma sum_trace {W : Type w'} [fintype W][decidable_eq W] (\u03c6 : W \u2192 (matrix X X R )) : \nmatrix.trace X R R (\u2211 w, \u03c6 w) = \u2211 w, matrix.trace X R R (\u03c6 w) :=\nbegin \n    rw \u2190 finset.sum_hom finset.univ (matrix.trace X R R),\nend\n/--\n    `trace (to_matrix ( \u2211 w, \u03c6 w ) ) =  \u2211 w, trace (to_matrix (  \u03c6 w ) )`\n-/\nlemma to_matrix_sum_trace {W : Type w'} [fintype W][decidable_eq W] (\u03c6 : W \u2192 (X \u2192 R) \u2192\u2097[R] (X \u2192 R) ) : \nmatrix.trace X R R (to_matrix ( \u2211 w, \u03c6 w ) ) =  \u2211 w, matrix.trace X R R (to_matrix (  \u03c6 w ) ) := \neq.trans  (congr_arg (matrix.trace X R R) (to_matrix_sum \u03c6)) (sum_trace (\u03bb w, to_matrix (\u03c6 w)))\n\n/--  \n    For `\u03c6 : W \u2192 matrix Y X R ` we have  `(\u2211 s, \u03c6 s )  y x = \u2211 s, (\u03c6 s y x)`\n-/\nlemma sum_apply_mat {W : Type w'} [fintype W][decidable_eq W] (\u03c6 : W \u2192 matrix Y X R )(x : X) (y : Y) : (\u2211 s, \u03c6 s )  y x = \u2211 s, (\u03c6 s y x) := \nbegin \n    rw finset.sum_apply, rw finset.sum_apply,\nend\n/--\n    `trace  M = \u2211 i, M i i`\n-/\nlemma trace_value (M : matrix X X R) : matrix.trace X R R M = \u2211 i, M i i := rfl\n\n\nlemma homo_eq_diag (f : (X \u2192 R) \u2192\u2097[R] (X \u2192 R))(t :R) (hyp : f + t \u2022 1 = 0) :\nto_matrix f = (- t) \u2022 (1 : matrix X X R ) := \nbegin \n    have : f = f+ t\u2022 1+ (-t) \u2022 1,\n        simp,\n    rw this, rw hyp,rw zero_add, rw to_matrix_smul, rw to_matrix_one,\nend", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep_2/Tools/matrix_tools.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7243990643824889}}
{"text": "class Semigroup (\u03b1 : Type u) extends Mul \u03b1 where\n  mul_assoc (a b c : \u03b1) : a * b * c = a * (b * c)\n\nexport Semigroup (mul_assoc)\n\nclass MulComm (\u03b1 : Type u)  extends Mul \u03b1 where\n  mul_comm (a b : \u03b1) : a * b = b * a\n\nexport MulComm (mul_comm)\n\nclass CommSemigroup (\u03b1 : Type u) extends Semigroup \u03b1 where\n  mul_comm (a b : \u03b1) : a * b = b * a\n\ninstance [CommSemigroup \u03b1] : MulComm \u03b1 where\n  mul_comm := CommSemigroup.mul_comm\n\nclass One (\u03b1 : Type u) where\n  one : \u03b1\n\ninstance [One \u03b1] : OfNat \u03b1 (nat_lit 1) where\n  ofNat := One.one\n\nclass Monoid (\u03b1 : Type u) extends Semigroup \u03b1, One \u03b1 where\n  one_mul (a : \u03b1) : 1 * a = a\n  mul_one (a : \u03b1) : a * 1 = a\n\nexport Monoid (one_mul mul_one)\n\nclass CommMonoid (\u03b1 : Type u) extends Monoid \u03b1 where\n  mul_comm (a b : \u03b1) : a * b = b * a\n\ninstance [CommMonoid \u03b1] : CommSemigroup \u03b1 where\n  mul_comm := CommMonoid.mul_comm\n\ninstance [CommMonoid \u03b1] : MulComm \u03b1 where\n  mul_comm := CommSemigroup.mul_comm\n\nclass Inv (\u03b1 : Type u) where\n  inv : \u03b1 \u2192 \u03b1\n\npostfix:max \"\u207b\u00b9\" => Inv.inv\n\nclass Group (\u03b1 : Type u) extends Monoid \u03b1, Inv \u03b1 where\n  mul_left_inv (a : \u03b1) : a\u207b\u00b9 * a = 1\n\nexport Group (mul_left_inv)\n\nclass CommGroup (\u03b1 : Type u) extends Group \u03b1 where\n  mul_comm (a b : \u03b1) : a * b = b * a\n\ninstance [CommGroup \u03b1] : CommMonoid \u03b1 where\n  mul_comm := CommGroup.mul_comm\n\ninstance [CommGroup \u03b1] : MulComm \u03b1 where\n  mul_comm := CommGroup.mul_comm\n\ntheorem inv_mul_cancel_left [Group \u03b1] (a b : \u03b1) : a\u207b\u00b9 * (a * b) = b := by\n  rw [\u2190 mul_assoc, mul_left_inv, one_mul]\n\ntheorem inv_eq_of_mul_eq_one [Group \u03b1] {a b : \u03b1} (h : a * b = 1) : a\u207b\u00b9 = b := by\n  rw [\u2190 mul_one a\u207b\u00b9, \u2190h, \u2190mul_assoc, mul_left_inv, one_mul]\n\ntheorem inv_inv [Group \u03b1] (a : \u03b1) : (a\u207b\u00b9)\u207b\u00b9 = a :=\n  inv_eq_of_mul_eq_one (mul_left_inv a)\n\ntheorem mul_right_inv [Group \u03b1] (a : \u03b1) : a * a\u207b\u00b9 = 1 := by\n  have : a\u207b\u00b9\u207b\u00b9 * a\u207b\u00b9 = 1 := by rw [mul_left_inv]\n  rw [inv_inv] at this\n  assumption\n\ntheorem mul_inv_rev [Group \u03b1] (a b : \u03b1) : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 := by\n  apply inv_eq_of_mul_eq_one\n  rw [mul_assoc, \u2190 mul_assoc b, mul_right_inv, one_mul, mul_right_inv]\n\ntheorem mul_inv [CommGroup \u03b1] (a b : \u03b1) : (a * b)\u207b\u00b9 = a\u207b\u00b9 * b\u207b\u00b9 := by\n  rw [mul_inv_rev, mul_comm]\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/alg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7243990559128397}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\nZorn's lemmas.\n\nPorted from Isabelle/HOL (written by Jacques D. Fleuriot, Tobias Nipkow, and Christian Sternagel).\n-/\nimport data.set.lattice\nnoncomputable theory\n\nuniverses u\nopen set classical\nopen_locale classical\n\nnamespace zorn\n\nsection chain\nparameters {\u03b1 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\nlocal infix ` \u227a `:50  := r\n\n/-- A chain is a subset `c` satisfying\n  `x \u227a y \u2228 x = y \u2228 y \u227a x` for all `x y \u2208 c`. -/\ndef chain (c : set \u03b1) := pairwise_on c (\u03bb x y, x \u227a y \u2228 y \u227a x)\nparameters {r}\n\ntheorem chain.total_of_refl [is_refl \u03b1 r]\n  {c} (H : chain c) {x y} (hx : x \u2208 c) (hy : y \u2208 c) :\n  x \u227a y \u2228 y \u227a x :=\nif e : x = y then or.inl (e \u25b8 refl _) else H _ hx _ hy e\n\ntheorem chain.mono {c c'} :\n  c' \u2286 c \u2192 chain c \u2192 chain c' :=\npairwise_on.mono\n\ntheorem chain.directed_on [is_refl \u03b1 r] {c} (H : chain c) :\n  directed_on (\u227a) c :=\nassume x hx y hy,\nmatch H.total_of_refl hx hy with\n| or.inl h := \u27e8y, hy, h, refl _\u27e9\n| or.inr h := \u27e8x, hx, refl _, h\u27e9\nend\n\ntheorem chain_insert {c : set \u03b1} {a : \u03b1} (hc : chain c) (ha : \u2200 b \u2208 c, b \u2260 a \u2192 a \u227a b \u2228 b \u227a a) :\n  chain (insert a c) :=\nforall_insert_of_forall\n  (assume x hx, forall_insert_of_forall (hc x hx) (assume hneq, (ha x hx hneq).symm))\n  (forall_insert_of_forall\n    (assume x hx hneq, ha x hx $ assume h', hneq h'.symm) (assume h, (h rfl).rec _))\n\n/-- `super_chain c\u2081 c\u2082` means that `c\u2082 is a chain that strictly includes `c\u2081`. -/\ndef super_chain (c\u2081 c\u2082 : set \u03b1) : Prop := chain c\u2082 \u2227 c\u2081 \u2282 c\u2082\n\n/-- A chain `c` is a maximal chain if there does not exists a chain strictly including `c`. -/\ndef is_max_chain (c : set \u03b1) := chain c \u2227 \u00ac (\u2203 c', super_chain c c')\n\n/-- Given a set `c`, if there exists a chain `c'` strictly including `c`, then `succ_chain c`\nis one of these chains. Otherwise it is `c`. -/\ndef succ_chain (c : set \u03b1) : set \u03b1 :=\nif h : \u2203 c', chain c \u2227 super_chain c c' then some h else c\n\ntheorem succ_spec {c : set \u03b1} (h : \u2203 c', chain c \u2227 super_chain c c') :\n  super_chain c (succ_chain c) :=\nlet \u27e8c', hc'\u27e9 := h in\nhave chain c \u2227 super_chain c (some h),\n  from @some_spec _ (\u03bbc', chain c \u2227 super_chain c c') _,\nby simp [succ_chain, dif_pos, h, this.right]\n\ntheorem chain_succ {c : set \u03b1} (hc : chain c) :\n  chain (succ_chain c) :=\nif h : \u2203 c', chain c \u2227 super_chain c c' then\n  (succ_spec h).left\nelse\n  by simp [succ_chain, dif_neg, h]; exact hc\n\ntheorem super_of_not_max {c : set \u03b1} (hc\u2081 : chain c) (hc\u2082 : \u00ac is_max_chain c) :\n  super_chain c (succ_chain c) :=\nbegin\n  simp [is_max_chain, not_and_distrib, not_forall_not] at hc\u2082,\n  cases hc\u2082.neg_resolve_left hc\u2081 with c' hc',\n  exact succ_spec \u27e8c', hc\u2081, hc'\u27e9\nend\n\ntheorem succ_increasing {c : set \u03b1} :\n  c \u2286 succ_chain c :=\nif h : \u2203 c', chain c \u2227 super_chain c c' then\n  have super_chain c (succ_chain c), from succ_spec h,\n  this.right.left\nelse by simp [succ_chain, dif_neg, h, subset.refl]\n\n/-- Set of sets reachable from `\u2205` using `succ_chain` and `\u22c3\u2080`. -/\ninductive chain_closure : set \u03b1 \u2192 Prop\n| succ : \u2200 {s}, chain_closure s \u2192 chain_closure (succ_chain s)\n| union : \u2200 {s}, (\u2200 a \u2208 s, chain_closure a) \u2192 chain_closure (\u22c3\u2080 s)\n\ntheorem chain_closure_empty :\n  chain_closure \u2205 :=\nhave chain_closure (\u22c3\u2080 \u2205),\n  from chain_closure.union $ assume a h, h.rec _,\nby simp at this; assumption\n\ntheorem chain_closure_closure :\n  chain_closure (\u22c3\u2080 chain_closure) :=\nchain_closure.union $ assume s hs, hs\n\nvariables {c c\u2081 c\u2082 c\u2083 : set \u03b1}\n\nprivate lemma chain_closure_succ_total_aux (hc\u2081 : chain_closure c\u2081) (hc\u2082 : chain_closure c\u2082)\n  (h : \u2200 {c\u2083}, chain_closure c\u2083 \u2192 c\u2083 \u2286 c\u2082 \u2192 c\u2082 = c\u2083 \u2228 succ_chain c\u2083 \u2286 c\u2082) :\n  c\u2081 \u2286 c\u2082 \u2228 succ_chain c\u2082 \u2286 c\u2081 :=\nbegin\n  induction hc\u2081,\n  case succ : c\u2083 hc\u2083 ih {\n    cases ih with ih ih,\n    { have h := h hc\u2083 ih,\n      cases h with h h,\n      { exact or.inr (h \u25b8 subset.refl _) },\n      { exact or.inl h } },\n    { exact or.inr (subset.trans ih succ_increasing) } },\n  case union : s hs ih {\n    refine (or_iff_not_imp_right.2 $ \u03bb hn, sUnion_subset $ \u03bb a ha, _),\n    apply (ih a ha).resolve_right,\n    apply mt (\u03bb h, _) hn,\n    exact subset.trans h (subset_sUnion_of_mem ha) }\nend\n\nprivate lemma chain_closure_succ_total (hc\u2081 : chain_closure c\u2081) (hc\u2082 : chain_closure c\u2082)\n  (h : c\u2081 \u2286 c\u2082) :\n  c\u2082 = c\u2081 \u2228 succ_chain c\u2081 \u2286 c\u2082 :=\nbegin\n  induction hc\u2082 generalizing c\u2081 hc\u2081 h,\n  case succ : c\u2082 hc\u2082 ih {\n    have h\u2081 : c\u2081 \u2286 c\u2082 \u2228 @succ_chain \u03b1 r c\u2082 \u2286 c\u2081 :=\n      (chain_closure_succ_total_aux hc\u2081 hc\u2082 $ assume c\u2081, ih),\n    cases h\u2081 with h\u2081 h\u2081,\n    { have h\u2082 := ih hc\u2081 h\u2081,\n      cases h\u2082 with h\u2082 h\u2082,\n      { exact (or.inr $ h\u2082 \u25b8 subset.refl _) },\n      { exact (or.inr $ subset.trans h\u2082 succ_increasing) } },\n    { exact (or.inl $ subset.antisymm h\u2081 h) } },\n  case union : s hs ih {\n    apply or.imp_left (assume h', subset.antisymm h' h),\n    apply classical.by_contradiction,\n    simp [not_or_distrib, sUnion_subset_iff, not_forall],\n    intros c\u2083 hc\u2083 h\u2081 h\u2082,\n    have h := chain_closure_succ_total_aux hc\u2081 (hs c\u2083 hc\u2083) (assume c\u2084, ih _ hc\u2083),\n    cases h with h h,\n    { have h' := ih c\u2083 hc\u2083 hc\u2081 h,\n      cases h' with h' h',\n      { exact (h\u2081 $ h' \u25b8 subset.refl _) },\n      { exact (h\u2082 $ subset.trans h' $ subset_sUnion_of_mem hc\u2083) } },\n    { exact (h\u2081 $ subset.trans succ_increasing h) } }\nend\n\ntheorem chain_closure_total (hc\u2081 : chain_closure c\u2081) (hc\u2082 : chain_closure c\u2082) :\n  c\u2081 \u2286 c\u2082 \u2228 c\u2082 \u2286 c\u2081 :=\nhave c\u2081 \u2286 c\u2082 \u2228 succ_chain c\u2082 \u2286 c\u2081,\n  from chain_closure_succ_total_aux hc\u2081 hc\u2082 $ assume c\u2083 hc\u2083, chain_closure_succ_total hc\u2083 hc\u2082,\nor.imp_right (assume : succ_chain c\u2082 \u2286 c\u2081, subset.trans succ_increasing this) this\n\ntheorem chain_closure_succ_fixpoint (hc\u2081 : chain_closure c\u2081) (hc\u2082 : chain_closure c\u2082)\n  (h_eq : succ_chain c\u2082 = c\u2082) :\n  c\u2081 \u2286 c\u2082 :=\nbegin\n  induction hc\u2081,\n  case succ : c\u2081 hc\u2081 h {\n    exact or.elim (chain_closure_succ_total hc\u2081 hc\u2082 h)\n      (assume h, h \u25b8 h_eq.symm \u25b8 subset.refl c\u2082) id },\n  case union : s hs ih {\n    exact (sUnion_subset $ assume c\u2081 hc\u2081, ih c\u2081 hc\u2081) }\nend\n\ntheorem chain_closure_succ_fixpoint_iff (hc : chain_closure c) :\n  succ_chain c = c \u2194 c = \u22c3\u2080 chain_closure :=\n\u27e8assume h, subset.antisymm\n    (subset_sUnion_of_mem hc)\n    (chain_closure_succ_fixpoint chain_closure_closure hc h),\n  assume : c = \u22c3\u2080{c : set \u03b1 | chain_closure c},\n  subset.antisymm\n    (calc succ_chain c \u2286 \u22c3\u2080{c : set \u03b1 | chain_closure c} :\n        subset_sUnion_of_mem $ chain_closure.succ hc\n      ... = c : this.symm)\n    succ_increasing\u27e9\n\ntheorem chain_chain_closure (hc : chain_closure c) :\n  chain c :=\nbegin\n  induction hc,\n  case succ : c hc h {\n    exact chain_succ h },\n  case union : s hs h {\n    have h : \u2200 c \u2208 s, zorn.chain c := h,\n    exact assume c\u2081 \u27e8t\u2081, ht\u2081, (hc\u2081 : c\u2081 \u2208 t\u2081)\u27e9 c\u2082 \u27e8t\u2082, ht\u2082, (hc\u2082 : c\u2082 \u2208 t\u2082)\u27e9 hneq,\n      have t\u2081 \u2286 t\u2082 \u2228 t\u2082 \u2286 t\u2081, from chain_closure_total (hs _ ht\u2081) (hs _ ht\u2082),\n      or.elim this\n        (assume : t\u2081 \u2286 t\u2082, h t\u2082 ht\u2082 c\u2081 (this hc\u2081) c\u2082 hc\u2082 hneq)\n        (assume : t\u2082 \u2286 t\u2081, h t\u2081 ht\u2081 c\u2081 hc\u2081 c\u2082 (this hc\u2082) hneq) }\nend\n\n/-- `max_chain` is the union of all sets in the chain closure. -/\ndef max_chain := \u22c3\u2080 chain_closure\n\n/-- Hausdorff's maximality principle\n\nThere exists a maximal totally ordered subset of `\u03b1`.\nNote that we do not require `\u03b1` to be partially ordered by `r`. -/\ntheorem max_chain_spec :\n  is_max_chain max_chain :=\nclassical.by_contradiction $\nassume : \u00ac is_max_chain (\u22c3\u2080 chain_closure),\nhave super_chain (\u22c3\u2080 chain_closure) (succ_chain (\u22c3\u2080 chain_closure)),\n  from super_of_not_max (chain_chain_closure chain_closure_closure) this,\nlet \u27e8h\u2081, H\u27e9 := this,\n  \u27e8h\u2082, (h\u2083 : (\u22c3\u2080 chain_closure) \u2260 succ_chain (\u22c3\u2080 chain_closure))\u27e9 := ssubset_iff_subset_ne.1 H in\nhave succ_chain (\u22c3\u2080 chain_closure) = (\u22c3\u2080 chain_closure),\n  from (chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl,\nh\u2083 this.symm\n\n/-- Zorn's lemma\n\nIf every chain has an upper bound, then there is a maximal element -/\ntheorem exists_maximal_of_chains_bounded (h : \u2200 c, chain c \u2192 \u2203 ub, \u2200 a \u2208 c, a \u227a ub)\n  (trans : \u2200 {a b c}, a \u227a b \u2192 b \u227a c \u2192 a \u227a c) :\n  \u2203 m, \u2200 a, m \u227a a \u2192 a \u227a m :=\nhave \u2203 ub, \u2200 a \u2208 max_chain, a \u227a ub,\n  from h _ $ max_chain_spec.left,\nlet \u27e8ub, (hub : \u2200 a \u2208 max_chain, a \u227a ub)\u27e9 := this in\n\u27e8ub, assume a ha,\n  have chain (insert a max_chain),\n    from chain_insert max_chain_spec.left $ assume b hb _, or.inr $ trans (hub b hb) ha,\n  have a \u2208 max_chain, from\n    classical.by_contradiction $ assume h : a \u2209 max_chain,\n    max_chain_spec.right $ \u27e8insert a max_chain, this, ssubset_insert h\u27e9,\n  hub a this\u27e9\n\n/--\nIf every nonempty chain of a nonempty type has an upper bound, then there is a maximal element.\n(A variant of Zorn's lemma.)\n-/\ntheorem exists_maximal_of_nonempty_chains_bounded [nonempty \u03b1]\n  (h : \u2200 c, chain c \u2192 c.nonempty \u2192 \u2203 ub, \u2200 a \u2208 c, a \u227a ub)\n  (trans : \u2200 {a b c}, a \u227a b \u2192 b \u227a c \u2192 a \u227a c) :\n  \u2203 m, \u2200 a, m \u227a a \u2192 a \u227a m :=\nexists_maximal_of_chains_bounded\n  (\u03bb c hc,\n    (eq_empty_or_nonempty c).elim\n      (\u03bb h, \u27e8classical.arbitrary \u03b1, \u03bb x hx, (h \u25b8 hx : x \u2208 (\u2205 : set \u03b1)).elim\u27e9)\n      (h c hc))\n  (\u03bb a b c, trans)\n\nend chain\n\n--This lemma isn't under section `chain` because `parameters` messes up with it. Feel free to fix it\n/-- This can be used to turn `zorn.chain (\u2265)` into `zorn.chain (\u2264)` and vice-versa. -/\ntheorem chain.symm {\u03b1 : Type u} {s : set \u03b1} {q : \u03b1 \u2192 \u03b1 \u2192 Prop} (h : chain q s) :\n  chain (flip q) s :=\nh.mono' (\u03bb _ _, or.symm)\n\ntheorem zorn_partial_order {\u03b1 : Type u} [partial_order \u03b1]\n  (h : \u2200 c : set \u03b1, chain (\u2264) c \u2192 \u2203 ub, \u2200 a \u2208 c, a \u2264 ub) :\n  \u2203 m : \u03b1, \u2200 a, m \u2264 a \u2192 a = m :=\nlet \u27e8m, hm\u27e9 := @exists_maximal_of_chains_bounded \u03b1 (\u2264) h (assume a b c, le_trans) in\n\u27e8m, assume a ha, le_antisymm (hm a ha) ha\u27e9\n\ntheorem zorn_nonempty_partial_order {\u03b1 : Type u} [partial_order \u03b1] [nonempty \u03b1]\n  (h : \u2200 (c : set \u03b1), chain (\u2264) c \u2192 c.nonempty \u2192 \u2203 ub, \u2200 a \u2208 c, a \u2264 ub) :\n  \u2203 (m : \u03b1), \u2200 a, m \u2264 a \u2192 a = m :=\nlet \u27e8m, hm\u27e9 := @exists_maximal_of_nonempty_chains_bounded \u03b1 (\u2264) _ h (\u03bb a b c, le_trans) in\n\u27e8m, \u03bb a ha, le_antisymm (hm a ha) ha\u27e9\n\ntheorem zorn_partial_order\u2080 {\u03b1 : Type u} [partial_order \u03b1] (s : set \u03b1)\n  (ih : \u2200 c \u2286 s, chain (\u2264) c \u2192 \u2203 ub \u2208 s, \u2200 z \u2208 c, z \u2264 ub) :\n  \u2203 m \u2208 s, \u2200 z \u2208 s, m \u2264 z \u2192 z = m :=\nlet \u27e8\u27e8m, hms\u27e9, h\u27e9 := @zorn_partial_order {m // m \u2208 s} _\n  (\u03bb c hc,\n    let \u27e8ub, hubs, hub\u27e9 := ih (subtype.val '' c) (\u03bb _ \u27e8\u27e8x, hx\u27e9, _, h\u27e9, h \u25b8 hx)\n      (by { rintro _ \u27e8p, hpc, rfl\u27e9 _ \u27e8q, hqc, rfl\u27e9 hpq;\n        refine hc _ hpc _ hqc (\u03bb t, hpq (subtype.ext_iff.1 t)) })\n    in \u27e8\u27e8ub, hubs\u27e9, \u03bb \u27e8y, hy\u27e9 hc, hub _ \u27e8_, hc, rfl\u27e9\u27e9)\nin \u27e8m, hms, \u03bb z hzs hmz, congr_arg subtype.val (h \u27e8z, hzs\u27e9 hmz)\u27e9\n\ntheorem zorn_nonempty_partial_order\u2080 {\u03b1 : Type u} [partial_order \u03b1] (s : set \u03b1)\n  (ih : \u2200 c \u2286 s, chain (\u2264) c \u2192 \u2200 y \u2208 c, \u2203 ub \u2208 s, \u2200 z \u2208 c, z \u2264 ub) (x : \u03b1) (hxs : x \u2208 s) :\n  \u2203 m \u2208 s, x \u2264 m \u2227 \u2200 z \u2208 s, m \u2264 z \u2192 z = m :=\nlet \u27e8\u27e8m, hms, hxm\u27e9, h\u27e9 := @zorn_partial_order {m // m \u2208 s \u2227 x \u2264 m} _\n  (\u03bb c hc, c.eq_empty_or_nonempty.elim\n    (assume hce, hce.symm \u25b8 \u27e8\u27e8x, hxs, le_refl _\u27e9, \u03bb _, false.elim\u27e9)\n    (assume \u27e8m, hmc\u27e9,\n      let \u27e8ub, hubs, hub\u27e9 := ih (subtype.val '' c) (image_subset_iff.2 $ \u03bb z hzc, z.2.1)\n        (by rintro _ \u27e8p, hpc, rfl\u27e9 _ \u27e8q, hqc, rfl\u27e9 hpq;\n          exact hc p hpc q hqc (mt (by rintro rfl; refl) hpq)) m.1 (mem_image_of_mem _ hmc) in\n    \u27e8\u27e8ub, hubs, le_trans m.2.2 $ hub m.1 $ mem_image_of_mem _ hmc\u27e9,\n      \u03bb a hac, hub a.1 \u27e8a, hac, rfl\u27e9\u27e9)) in\n\u27e8m, hms, hxm, \u03bb z hzs hmz, congr_arg subtype.val $ h \u27e8z, hzs, le_trans hxm hmz\u27e9 hmz\u27e9\n\ntheorem zorn_subset {\u03b1 : Type u} (S : set (set \u03b1))\n  (h : \u2200 c \u2286 S, chain (\u2286) c \u2192 \u2203 ub \u2208 S, \u2200 s \u2208 c, s \u2286 ub) :\n  \u2203 m \u2208 S, \u2200 a \u2208 S, m \u2286 a \u2192 a = m :=\nzorn_partial_order\u2080 S h\n\ntheorem zorn_subset_nonempty {\u03b1 : Type u} (S : set (set \u03b1))\n  (H : \u2200 c \u2286 S, chain (\u2286) c \u2192 c.nonempty \u2192 \u2203 ub \u2208 S, \u2200 s \u2208 c, s \u2286 ub) (x) (hx : x \u2208 S) :\n  \u2203 m \u2208 S, x \u2286 m \u2227 \u2200 a \u2208 S, m \u2286 a \u2192 a = m :=\nzorn_nonempty_partial_order\u2080 _ (\u03bb c cS hc y yc, H _ cS hc \u27e8y, yc\u27e9) _ hx\n\ntheorem zorn_superset {\u03b1 : Type u} (S : set (set \u03b1))\n  (h : \u2200 c \u2286 S, chain (\u2286) c \u2192 \u2203 lb \u2208 S, \u2200 s \u2208 c, lb \u2286 s) :\n  \u2203 m \u2208 S, \u2200 a \u2208 S, a \u2286 m \u2192 a = m :=\n@zorn_partial_order\u2080 (order_dual (set \u03b1)) _ S $ \u03bb c cS hc, h c cS hc.symm\n\ntheorem zorn_superset_nonempty {\u03b1 : Type u} (S : set (set \u03b1))\n  (H : \u2200 c \u2286 S, chain (\u2286) c \u2192 c.nonempty \u2192 \u2203 lb \u2208 S, \u2200 s \u2208 c, lb \u2286 s) (x) (hx : x \u2208 S) :\n  \u2203 m \u2208 S, m \u2286 x \u2227 \u2200 a \u2208 S, a \u2286 m \u2192 a = m :=\n@zorn_nonempty_partial_order\u2080 (order_dual (set \u03b1)) _ S (\u03bb c cS hc y yc, H _ cS\n  hc.symm \u27e8y, yc\u27e9) _ hx\n\ntheorem chain.total {\u03b1 : Type u} [preorder \u03b1] {c : set \u03b1} (H : chain (\u2264) c) :\n  \u2200 {x y}, x \u2208 c \u2192 y \u2208 c \u2192 x \u2264 y \u2228 y \u2264 x :=\n\u03bb x y, H.total_of_refl\n\ntheorem chain.image {\u03b1 \u03b2 : Type*} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) (f : \u03b1 \u2192 \u03b2)\n  (h : \u2200 x y, r x y \u2192 s (f x) (f y)) {c : set \u03b1} (hrc : chain r c) :\n  chain s (f '' c) :=\n\u03bb x \u27e8a, ha\u2081, ha\u2082\u27e9 y \u27e8b, hb\u2081, hb\u2082\u27e9, ha\u2082 \u25b8 hb\u2082 \u25b8 \u03bb hxy,\n  (hrc a ha\u2081 b hb\u2081 (mt (congr_arg f) $ hxy)).elim\n    (or.inl \u2218 h _ _) (or.inr \u2218 h _ _)\n\nend zorn\n\ntheorem directed_of_chain {\u03b1 \u03b2 r} [is_refl \u03b2 r] {f : \u03b1 \u2192 \u03b2} {c : set \u03b1}\n  (h : zorn.chain (f \u207b\u00b9'o r) c) :\n  directed r (\u03bb x : {a : \u03b1 // a \u2208 c}, f x) :=\nassume \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, classical.by_cases\n  (assume : a = b, by simp only [this, exists_prop, and_self, subtype.exists];\n    exact \u27e8b, hb, refl _\u27e9)\n  (assume : a \u2260 b, (h a ha b hb this).elim\n    (\u03bb h : r (f a) (f b), \u27e8\u27e8b, hb\u27e9, h, refl _\u27e9)\n    (\u03bb h : r (f b) (f a), \u27e8\u27e8a, ha\u27e9, refl _, h\u27e9))\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/zorn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7243941166525865}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Kexing Ying\n-/\nimport probability.notation\nimport probability.integration\n\n/-!\n# Variance of random variables\n\nWe define the variance of a real-valued random variable as `Var[X] = \ud835\udd3c[(X - \ud835\udd3c[X])^2]` (in the\n`probability_theory` locale).\n\n## Main definitions\n\n* `probability_theory.evariance`: the variance of a real-valued random variable as a extended\n  non-negative real.\n* `probability_theory.variance`: the variance of a real-valued random variable as a real number.\n\n## Main results\n\n* `probability_theory.variance_le_expectation_sq`: the inequality `Var[X] \u2264 \ud835\udd3c[X^2]`.\n* `probability_theory.meas_ge_le_variance_div_sq`: Chebyshev's inequality, i.e.,\n      `\u2119 {\u03c9 | c \u2264 |X \u03c9 - \ud835\udd3c[X]|} \u2264 ennreal.of_real (Var[X] / c ^ 2)`.\n* `probability_theory.meas_ge_le_evariance_div_sq`: Chebyshev's inequality formulated with\n  `evariance` without requiring the random variables to be L\u00b2.\n* `probability_theory.indep_fun.variance_add`: the variance of the sum of two independent\n  random variables is the sum of the variances.\n* `probability_theory.indep_fun.variance_sum`: the variance of a finite sum of pairwise\n  independent random variables is the sum of the variances.\n-/\n\nopen measure_theory filter finset\n\nnoncomputable theory\n\nopen_locale big_operators measure_theory probability_theory ennreal nnreal\n\nnamespace probability_theory\n\n/-- The `\u211d\u22650\u221e`-valued variance of a real-valued random variable defined as the Lebesgue integral of\n`(X - \ud835\udd3c[X])^2`. -/\ndef evariance {\u03a9 : Type*} {m : measurable_space \u03a9} (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) : \u211d\u22650\u221e :=\n\u222b\u207b \u03c9, \u2016X \u03c9 - \u03bc[X]\u2016\u208a^2 \u2202\u03bc\n\n/-- The `\u211d`-valued variance of a real-valued random variable defined by applying `ennreal.to_real`\nto `evariance`. -/\ndef variance {\u03a9 : Type*} {m : measurable_space \u03a9} (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) : \u211d :=\n(evariance X \u03bc).to_real\n\nvariables {\u03a9 : Type*} {m : measurable_space \u03a9} {X : \u03a9 \u2192 \u211d} {\u03bc : measure \u03a9}\n\nlemma _root_.measure_theory.mem_\u2112p.evariance_lt_top [is_finite_measure \u03bc] (hX : mem_\u2112p X 2 \u03bc) :\n  evariance X \u03bc < \u221e :=\nbegin\n  have := ennreal.pow_lt_top (hX.sub $ mem_\u2112p_const $ \u03bc[X]).2 2,\n  rw [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ennreal.two_ne_top,\n    \u2190 ennreal.rpow_two] at this,\n  simp only [pi.sub_apply, ennreal.to_real_bit0, ennreal.one_to_real, one_div] at this,\n  rw [\u2190 ennreal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : \u211d) \u2260 0), ennreal.rpow_one] at this,\n  simp_rw ennreal.rpow_two at this,\n  exact this,\nend\n\nlemma evariance_eq_top [is_finite_measure \u03bc]\n  (hXm : ae_strongly_measurable X \u03bc) (hX : \u00ac mem_\u2112p X 2 \u03bc) :\n  evariance X \u03bc = \u221e :=\nbegin\n  by_contra h,\n  rw [\u2190 ne.def, \u2190 lt_top_iff_ne_top] at h,\n  have : mem_\u2112p (\u03bb \u03c9, X \u03c9 - \u03bc[X]) 2 \u03bc,\n  { refine \u27e8hXm.sub ae_strongly_measurable_const, _\u27e9,\n    rw snorm_eq_lintegral_rpow_nnnorm two_ne_zero ennreal.two_ne_top,\n    simp only [ennreal.to_real_bit0, ennreal.one_to_real, ennreal.rpow_two, ne.def],\n    exact ennreal.rpow_lt_top_of_nonneg (by simp) h.ne },\n  refine hX _,\n  convert this.add (mem_\u2112p_const $ \u03bc[X]),\n  ext \u03c9,\n  rw [pi.add_apply, sub_add_cancel],\nend\n\nlemma evariance_lt_top_iff_mem_\u2112p [is_finite_measure \u03bc]\n  (hX : ae_strongly_measurable X \u03bc) :\n  evariance X \u03bc < \u221e \u2194 mem_\u2112p X 2 \u03bc :=\nbegin\n  refine \u27e8_, measure_theory.mem_\u2112p.evariance_lt_top\u27e9,\n  contrapose,\n  rw [not_lt, top_le_iff],\n  exact evariance_eq_top hX\nend\n\nlemma _root_.measure_theory.mem_\u2112p.of_real_variance_eq [is_finite_measure \u03bc]\n  (hX : mem_\u2112p X 2 \u03bc) :\n  ennreal.of_real (variance X \u03bc) = evariance X \u03bc :=\nby { rw [variance, ennreal.of_real_to_real], exact hX.evariance_lt_top.ne, }\n\ninclude m\n\nlemma evariance_eq_lintegral_of_real (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) :\n  evariance X \u03bc = \u222b\u207b \u03c9, ennreal.of_real ((X \u03c9 - \u03bc[X])^2) \u2202\u03bc :=\nbegin\n  rw evariance,\n  congr,\n  ext1 \u03c9,\n  rw [pow_two, \u2190 ennreal.coe_mul, \u2190 nnnorm_mul, \u2190 pow_two],\n  congr,\n  exact (real.to_nnreal_eq_nnnorm_of_nonneg $ sq_nonneg _).symm,\nend\n\nlemma _root_.measure_theory.mem_\u2112p.variance_eq_of_integral_eq_zero\n  (hX : mem_\u2112p X 2 \u03bc) (hXint : \u03bc[X] = 0) :\n  variance X \u03bc = \u03bc[X^2] :=\nbegin\n  rw [variance, evariance_eq_lintegral_of_real, \u2190 of_real_integral_eq_lintegral_of_real,\n    ennreal.to_real_of_real];\n  simp_rw [hXint, sub_zero],\n  { refl },\n  { exact integral_nonneg (\u03bb \u03c9, pow_two_nonneg _) },\n  { convert hX.integrable_norm_rpow two_ne_zero ennreal.two_ne_top,\n    ext \u03c9,\n    simp only [pi.sub_apply, real.norm_eq_abs, ennreal.to_real_bit0, ennreal.one_to_real,\n      real.rpow_two, pow_bit0_abs] },\n  { exact ae_of_all _ (\u03bb \u03c9, pow_two_nonneg _) }\nend\n\nlemma _root_.measure_theory.mem_\u2112p.variance_eq [is_finite_measure \u03bc]\n  (hX : mem_\u2112p X 2 \u03bc) :\n  variance X \u03bc = \u03bc[(X - (\u03bb \u03c9, \u03bc[X]))^2] :=\nbegin\n  rw [variance, evariance_eq_lintegral_of_real, \u2190 of_real_integral_eq_lintegral_of_real,\n    ennreal.to_real_of_real],\n  { refl },\n  { exact integral_nonneg (\u03bb \u03c9, pow_two_nonneg _) },\n  { convert (hX.sub $ mem_\u2112p_const (\u03bc[X])).integrable_norm_rpow\n      two_ne_zero ennreal.two_ne_top,\n    ext \u03c9,\n    simp only [pi.sub_apply, real.norm_eq_abs, ennreal.to_real_bit0, ennreal.one_to_real,\n      real.rpow_two, pow_bit0_abs] },\n  { exact ae_of_all _ (\u03bb \u03c9, pow_two_nonneg _) }\nend\n\n@[simp] \n\nlemma evariance_eq_zero_iff (hX : ae_measurable X \u03bc) :\n  evariance X \u03bc = 0 \u2194 X =\u1d50[\u03bc] \u03bb \u03c9, \u03bc[X] :=\nbegin\n  rw [evariance, lintegral_eq_zero_iff'],\n  split; intro hX; filter_upwards [hX] with \u03c9 h\u03c9,\n  { simp only [pi.zero_apply, pow_eq_zero_iff, nat.succ_pos', ennreal.coe_eq_zero,\n      nnnorm_eq_zero, sub_eq_zero] at h\u03c9,\n    exact h\u03c9 },\n  { rw h\u03c9,\n    simp },\n  { measurability }\nend\n\nlemma evariance_mul (c : \u211d) (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) :\n  evariance (\u03bb \u03c9, c * X \u03c9) \u03bc = ennreal.of_real (c^2) * evariance X \u03bc :=\nbegin\n  rw [evariance, evariance, \u2190 lintegral_const_mul' _ _ ennreal.of_real_lt_top.ne],\n  congr,\n  ext1 \u03c9,\n  rw [ennreal.of_real, \u2190 ennreal.coe_pow, \u2190 ennreal.coe_pow, \u2190 ennreal.coe_mul],\n  congr,\n  rw [\u2190 sq_abs, \u2190 real.rpow_two, real.to_nnreal_rpow_of_nonneg (abs_nonneg _), nnreal.rpow_two,\n    \u2190 mul_pow, real.to_nnreal_mul_nnnorm _ (abs_nonneg _)],\n  conv_rhs { rw [\u2190 nnnorm_norm, norm_mul, norm_abs_eq_norm, \u2190 norm_mul, nnnorm_norm, mul_sub] },\n  congr,\n  rw mul_comm,\n  simp_rw [\u2190 smul_eq_mul, \u2190 integral_smul_const, smul_eq_mul, mul_comm],\nend\n\nlocalized \"notation (name := probability_theory.evariance) `eVar[` X `]` :=\n  probability_theory.evariance X measure_theory.measure_space.volume\" in probability_theory\n\n@[simp] lemma variance_zero (\u03bc : measure \u03a9) : variance 0 \u03bc = 0 :=\nby simp only [variance, evariance_zero, ennreal.zero_to_real]\n\nlemma variance_nonneg (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) :\n  0 \u2264 variance X \u03bc :=\nennreal.to_real_nonneg\n\nlemma variance_mul (c : \u211d) (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) :\n  variance (\u03bb \u03c9, c * X \u03c9) \u03bc = c^2 * variance X \u03bc :=\nbegin\n  rw [variance, evariance_mul, ennreal.to_real_mul, ennreal.to_real_of_real (sq_nonneg _)],\n  refl,\nend\n\nlemma variance_smul (c : \u211d) (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) :\n  variance (c \u2022 X) \u03bc = c^2 * variance X \u03bc :=\nvariance_mul c X \u03bc\n\nlemma variance_smul' {A : Type*} [comm_semiring A] [algebra A \u211d]\n  (c : A) (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) :\n  variance (c \u2022 X) \u03bc = c^2 \u2022 variance X \u03bc :=\nbegin\n  convert variance_smul (algebra_map A \u211d c) X \u03bc,\n  { ext1 x, simp only [algebra_map_smul], },\n  { simp only [algebra.smul_def, map_pow], }\nend\n\nlocalized \"notation (name := probability_theory.variance) `Var[` X `]` :=\n  probability_theory.variance X measure_theory.measure_space.volume\" in probability_theory\n\nomit m\n\nvariables [measure_space \u03a9]\n\nlemma variance_def' [is_probability_measure (\u2119 : measure \u03a9)]\n  {X : \u03a9 \u2192 \u211d} (hX : mem_\u2112p X 2) :\n  Var[X] = \ud835\udd3c[X^2] - \ud835\udd3c[X]^2 :=\nbegin\n  rw [hX.variance_eq, sub_sq', integral_sub', integral_add'], rotate,\n  { exact hX.integrable_sq },\n  { convert integrable_const (\ud835\udd3c[X] ^ 2),\n    apply_instance },\n  { apply hX.integrable_sq.add,\n    convert integrable_const (\ud835\udd3c[X] ^ 2),\n    apply_instance },\n  { exact ((hX.integrable one_le_two).const_mul 2).mul_const' _ },\n  simp only [integral_mul_right, pi.pow_apply, pi.mul_apply, pi.bit0_apply, pi.one_apply,\n    integral_const (integral \u2119 X ^ 2), integral_mul_left (2 : \u211d), one_mul,\n    variance, pi.pow_apply, measure_univ, ennreal.one_to_real, algebra.id.smul_eq_mul],\n  ring,\nend\n\nlemma variance_le_expectation_sq [is_probability_measure (\u2119 : measure \u03a9)]\n  {X : \u03a9 \u2192 \u211d} (hm : ae_strongly_measurable X \u2119) :\n  Var[X] \u2264 \ud835\udd3c[X^2] :=\nbegin\n  by_cases hX : mem_\u2112p X 2,\n  { rw variance_def' hX,\n    simp only [sq_nonneg, sub_le_self_iff] },\n  rw [variance, evariance_eq_lintegral_of_real, \u2190 integral_eq_lintegral_of_nonneg_ae],\n  by_cases hint : integrable X, swap,\n  { simp only [integral_undef hint, pi.pow_apply, pi.sub_apply, sub_zero] },\n  { rw integral_undef,\n    { exact integral_nonneg (\u03bb a, sq_nonneg _) },\n    { intro h,\n      have A : mem_\u2112p (X - \u03bb (\u03c9 : \u03a9), \ud835\udd3c[X]) 2 \u2119 := (mem_\u2112p_two_iff_integrable_sq\n        (hint.ae_strongly_measurable.sub ae_strongly_measurable_const)).2 h,\n      have B : mem_\u2112p (\u03bb (\u03c9 : \u03a9), \ud835\udd3c[X]) 2 \u2119 := mem_\u2112p_const _,\n      apply hX,\n      convert A.add B,\n      simp } },\n  { exact ae_of_all _ (\u03bb x, sq_nonneg _) },\n  { exact (ae_measurable.pow_const (hm.ae_measurable.sub_const _) _).ae_strongly_measurable },\nend\n\nlemma evariance_def' [is_probability_measure (\u2119 : measure \u03a9)]\n  {X : \u03a9 \u2192 \u211d} (hX : ae_strongly_measurable X \u2119) :\n  eVar[X] = (\u222b\u207b \u03c9, \u2016X \u03c9\u2016\u208a^2) - ennreal.of_real (\ud835\udd3c[X]^2) :=\nbegin\n  by_cases h\u2112 : mem_\u2112p X 2,\n  { rw [\u2190 h\u2112.of_real_variance_eq, variance_def' h\u2112, ennreal.of_real_sub _ (sq_nonneg _)],\n    congr,\n    simp_rw \u2190 ennreal.coe_pow,\n    rw lintegral_coe_eq_integral,\n    { congr' 2 with \u03c9,\n      simp only [pi.pow_apply, nnreal.coe_pow, coe_nnnorm, real.norm_eq_abs, pow_bit0_abs] },\n    { exact h\u2112.abs.integrable_sq } },\n  { symmetry,\n    rw [evariance_eq_top hX h\u2112, ennreal.sub_eq_top_iff],\n    refine \u27e8_, ennreal.of_real_ne_top\u27e9,\n    rw [mem_\u2112p, not_and] at h\u2112,\n    specialize h\u2112 hX,\n    simp only [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ennreal.two_ne_top, not_lt,\n      top_le_iff, ennreal.to_real_bit0, ennreal.one_to_real, ennreal.rpow_two, one_div,\n      ennreal.rpow_eq_top_iff, inv_lt_zero, inv_pos, zero_lt_bit0, zero_lt_one, and_true,\n      or_iff_not_imp_left, not_and_distrib] at h\u2112,\n    exact h\u2112 (\u03bb _, zero_le_two) }\nend\n\n/-- *Chebyshev's inequality* for `\u211d\u22650\u221e`-valued variance. -/\ntheorem meas_ge_le_evariance_div_sq {X : \u03a9 \u2192 \u211d}\n  (hX : ae_strongly_measurable X \u2119) {c : \u211d\u22650} (hc : c \u2260 0) :\n  \u2119 {\u03c9 | \u2191c \u2264 |X \u03c9 - \ud835\udd3c[X]|} \u2264 eVar[X] / c ^ 2 :=\nbegin\n  have A : (c : \u211d\u22650\u221e) \u2260 0, { rwa [ne.def, ennreal.coe_eq_zero] },\n  have B : ae_strongly_measurable (\u03bb (\u03c9 : \u03a9), \ud835\udd3c[X]) \u2119 := ae_strongly_measurable_const,\n  convert meas_ge_le_mul_pow_snorm \u2119 two_ne_zero ennreal.two_ne_top (hX.sub B) A,\n  { ext \u03c9,\n    simp only [pi.sub_apply, ennreal.coe_le_coe, \u2190 real.norm_eq_abs, \u2190 coe_nnnorm,\n      nnreal.coe_le_coe, ennreal.of_real_coe_nnreal] },\n  { rw snorm_eq_lintegral_rpow_nnnorm two_ne_zero ennreal.two_ne_top,\n    simp only [ennreal.to_real_bit0, ennreal.one_to_real, pi.sub_apply, one_div],\n    rw [div_eq_mul_inv, ennreal.inv_pow, mul_comm, ennreal.rpow_two],\n    congr,\n    simp_rw [\u2190 ennreal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : \u211d) \u2260 0), ennreal.rpow_two,\n      ennreal.rpow_one, evariance] }\nend\n\n/-- *Chebyshev's inequality* : one can control the deviation probability of a real random variable\nfrom its expectation in terms of the variance. -/\ntheorem meas_ge_le_variance_div_sq [is_finite_measure (\u2119 : measure \u03a9)]\n  {X : \u03a9 \u2192 \u211d} (hX : mem_\u2112p X 2) {c : \u211d} (hc : 0 < c) :\n  \u2119 {\u03c9 | c \u2264 |X \u03c9 - \ud835\udd3c[X]|} \u2264 ennreal.of_real (Var[X] / c ^ 2) :=\nbegin\n  rw [ennreal.of_real_div_of_pos (sq_pos_of_ne_zero _ hc.ne.symm), hX.of_real_variance_eq],\n  convert @meas_ge_le_evariance_div_sq _ _ _ hX.1 (c.to_nnreal) (by simp [hc]),\n  { simp only [real.coe_to_nnreal', max_le_iff, abs_nonneg, and_true] },\n  { rw ennreal.of_real_pow hc.le,\n    refl }\nend\n\n/-- The variance of the sum of two independent random variables is the sum of the variances. -/\ntheorem indep_fun.variance_add [is_probability_measure (\u2119 : measure \u03a9)]\n  {X Y : \u03a9 \u2192 \u211d} (hX : mem_\u2112p X 2) (hY : mem_\u2112p Y 2) (h : indep_fun X Y) :\n  Var[X + Y] = Var[X] + Var[Y] :=\ncalc\nVar[X + Y] = \ud835\udd3c[\u03bb a, (X a)^2 + (Y a)^2 + 2 * X a * Y a] - \ud835\udd3c[X+Y]^2 :\n  by simp [variance_def' (hX.add hY), add_sq']\n... = (\ud835\udd3c[X^2] + \ud835\udd3c[Y^2] + 2 * \ud835\udd3c[X * Y]) - (\ud835\udd3c[X] + \ud835\udd3c[Y])^2 :\nbegin\n  simp only [pi.add_apply, pi.pow_apply, pi.mul_apply, mul_assoc],\n  rw [integral_add, integral_add, integral_add, integral_mul_left],\n  { exact hX.integrable one_le_two },\n  { exact hY.integrable one_le_two },\n  { exact hX.integrable_sq },\n  { exact hY.integrable_sq },\n  { exact hX.integrable_sq.add hY.integrable_sq },\n  { apply integrable.const_mul,\n    exact h.integrable_mul (hX.integrable one_le_two) (hY.integrable one_le_two) }\nend\n... = (\ud835\udd3c[X^2] + \ud835\udd3c[Y^2] + 2 * (\ud835\udd3c[X] * \ud835\udd3c[Y])) - (\ud835\udd3c[X] + \ud835\udd3c[Y])^2 :\nbegin\n  congr,\n  exact h.integral_mul_of_integrable\n    (hX.integrable one_le_two) (hY.integrable one_le_two),\nend\n... = Var[X] + Var[Y] :\n  by { simp only [variance_def', hX, hY, pi.pow_apply], ring }\n\n/-- The variance of a finite sum of pairwise independent random variables is the sum of the\nvariances. -/\ntheorem indep_fun.variance_sum [is_probability_measure (\u2119 : measure \u03a9)]\n  {\u03b9 : Type*} {X : \u03b9 \u2192 \u03a9 \u2192 \u211d} {s : finset \u03b9}\n  (hs : \u2200 i \u2208 s, mem_\u2112p (X i) 2) (h : set.pairwise \u2191s (\u03bb i j, indep_fun (X i) (X j))) :\n  Var[\u2211 i in s, X i] = \u2211 i in s, Var[X i] :=\nbegin\n  classical,\n  induction s using finset.induction_on with k s ks IH,\n  { simp only [finset.sum_empty, variance_zero] },\n  rw [variance_def' (mem_\u2112p_finset_sum' _ hs), sum_insert ks, sum_insert ks],\n  simp only [add_sq'],\n  calc \ud835\udd3c[X k ^ 2 + (\u2211 i in s, X i) ^ 2 + 2 * X k * \u2211 i in s, X i] - \ud835\udd3c[X k + \u2211 i in s, X i] ^ 2\n  = (\ud835\udd3c[X k ^ 2] + \ud835\udd3c[(\u2211 i in s, X i) ^ 2] + \ud835\udd3c[2 * X k * \u2211 i in s, X i])\n    - (\ud835\udd3c[X k] + \ud835\udd3c[\u2211 i in s, X i]) ^ 2 :\n  begin\n    rw [integral_add', integral_add', integral_add'],\n    { exact mem_\u2112p.integrable one_le_two (hs _ (mem_insert_self _ _)) },\n    { apply integrable_finset_sum' _ (\u03bb i hi, _),\n      exact mem_\u2112p.integrable one_le_two (hs _ (mem_insert_of_mem hi)) },\n    { exact mem_\u2112p.integrable_sq (hs _ (mem_insert_self _ _)) },\n    { apply mem_\u2112p.integrable_sq,\n      exact mem_\u2112p_finset_sum' _ (\u03bb i hi, (hs _ (mem_insert_of_mem hi))) },\n    { apply integrable.add,\n      { exact mem_\u2112p.integrable_sq (hs _ (mem_insert_self _ _)) },\n      { apply mem_\u2112p.integrable_sq,\n        exact mem_\u2112p_finset_sum' _ (\u03bb i hi, (hs _ (mem_insert_of_mem hi))) } },\n    { rw mul_assoc,\n      apply integrable.const_mul _ (2:\u211d),\n      simp only [mul_sum, sum_apply, pi.mul_apply],\n      apply integrable_finset_sum _ (\u03bb i hi, _),\n      apply indep_fun.integrable_mul _\n        (mem_\u2112p.integrable one_le_two (hs _ (mem_insert_self _ _)))\n        (mem_\u2112p.integrable one_le_two (hs _ (mem_insert_of_mem hi))),\n      apply h (mem_insert_self _ _) (mem_insert_of_mem hi),\n      exact (\u03bb hki, ks (hki.symm \u25b8 hi)) }\n  end\n  ... = Var[X k] + Var[\u2211 i in s, X i] +\n    (\ud835\udd3c[2 * X k * \u2211 i in s, X i] - 2 * \ud835\udd3c[X k] * \ud835\udd3c[\u2211 i in s, X i]) :\n  begin\n    rw [variance_def' (hs _ (mem_insert_self _ _)),\n        variance_def' (mem_\u2112p_finset_sum' _ (\u03bb i hi, (hs _ (mem_insert_of_mem hi))))],\n    ring,\n  end\n  ... = Var[X k] + Var[\u2211 i in s, X i] :\n  begin\n    simp only [mul_assoc, integral_mul_left, pi.mul_apply, pi.bit0_apply, pi.one_apply, sum_apply,\n      add_right_eq_self, mul_sum],\n    rw integral_finset_sum s (\u03bb i hi, _), swap,\n    { apply integrable.const_mul _ (2:\u211d),\n      apply indep_fun.integrable_mul _\n        (mem_\u2112p.integrable one_le_two (hs _ (mem_insert_self _ _)))\n        (mem_\u2112p.integrable one_le_two (hs _ (mem_insert_of_mem hi))),\n      apply h (mem_insert_self _ _) (mem_insert_of_mem hi),\n      exact (\u03bb hki, ks (hki.symm \u25b8 hi)) },\n    rw [integral_finset_sum s\n      (\u03bb i hi, (mem_\u2112p.integrable one_le_two (hs _ (mem_insert_of_mem hi)))),\n      mul_sum, mul_sum, \u2190 sum_sub_distrib],\n    apply finset.sum_eq_zero (\u03bb i hi, _),\n    rw [integral_mul_left, indep_fun.integral_mul', sub_self],\n    { apply h (mem_insert_self _ _) (mem_insert_of_mem hi),\n      exact (\u03bb hki, ks (hki.symm \u25b8 hi)) },\n    { exact mem_\u2112p.ae_strongly_measurable (hs _ (mem_insert_self _ _)) },\n    { exact mem_\u2112p.ae_strongly_measurable (hs _ (mem_insert_of_mem hi)) }\n  end\n  ... = Var[X k] + \u2211 i in s, Var[X i] :\n    by rw IH (\u03bb i hi, hs i (mem_insert_of_mem hi))\n      (h.mono (by simp only [coe_insert, set.subset_insert]))\nend\n\nend probability_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/probability/variance.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357632379241, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7243941115927255}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n-/\nimport data.list.prime\nimport data.list.sort\nimport data.nat.gcd\nimport data.nat.sqrt_norm_num\nimport data.set.finite\nimport tactic.wlog\nimport algebra.parity\n\n/-!\n# Prime numbers\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\n- `nat.prime`: the predicate that expresses that a natural number `p` is prime\n- `nat.primes`: the subtype of natural numbers that are prime\n- `nat.min_fac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers.\n  This also appears as `nat.not_bdd_above_set_of_prime` and `nat.infinite_set_of_prime`.\n- `nat.factors n`: the prime factorization of `n`\n- `nat.factors_unique`: uniqueness of the prime factorisation\n- `nat.prime_iff`: `nat.prime` coincides with the general definition of `prime`\n- `nat.irreducible_iff_prime`: a non-unit natural number is only divisible by `1` iff it is prime\n\n-/\n\nopen bool subtype\nopen_locale nat\n\nnamespace nat\n\n/-- `prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\n@[pp_nodot]\ndef prime (p : \u2115) := _root_.irreducible p\n\ntheorem _root_.irreducible_iff_nat_prime (a : \u2115) : irreducible a \u2194 nat.prime a := iff.rfl\n\ntheorem not_prime_zero : \u00ac prime 0\n| h := h.ne_zero rfl\n\ntheorem not_prime_one : \u00ac prime 1\n| h := h.ne_one rfl\n\ntheorem prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 := irreducible.ne_zero h\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : 0 < p := nat.pos_of_ne_zero pp.ne_zero\n\ntheorem prime.two_le : \u2200 {p : \u2115}, prime p \u2192 2 \u2264 p\n| 0 h := (not_prime_zero h).elim\n| 1 h := (not_prime_one h).elim\n| (n+2) _ := le_add_self\n\ntheorem prime.one_lt {p : \u2115} : prime p \u2192 1 < p := prime.two_le\n\ninstance prime.one_lt' (p : \u2115) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := \u27e8hp.1.one_lt\u27e9\n\nlemma prime.ne_one {p : \u2115} (hp : p.prime) : p \u2260 1 :=\nhp.one_lt.ne'\n\nlemma prime.eq_one_or_self_of_dvd {p : \u2115} (pp : p.prime) (m : \u2115) (hm : m \u2223 p) : m = 1 \u2228 m = p :=\nbegin\n  obtain \u27e8n, hn\u27e9 := hm,\n  have := pp.is_unit_or_is_unit hn,\n  rw [nat.is_unit_iff, nat.is_unit_iff] at this,\n  apply or.imp_right _ this,\n  rintro rfl,\n  rw [hn, mul_one]\nend\n\ntheorem prime_def_lt'' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m \u2223 p, m = 1 \u2228 m = p :=\nbegin\n  refine \u27e8\u03bb h, \u27e8h.two_le, h.eq_one_or_self_of_dvd\u27e9, \u03bb h, _\u27e9,\n  have h1 := one_lt_two.trans_le h.1,\n  refine \u27e8mt nat.is_unit_iff.mp h1.ne', \u03bb a b hab, _\u27e9,\n  simp only [nat.is_unit_iff],\n  apply or.imp_right _ (h.2 a _),\n  { rintro rfl,\n    rw [\u2190nat.mul_right_inj (pos_of_gt h1), \u2190hab, mul_one] },\n  { rw hab,\n    exact dvd_mul_right _ _ }\nend\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\nprime_def_lt''.trans $\nand_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h l d, (h d).resolve_right (ne_of_lt l),\n \u03bb h d, (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left (\u03bb l, h l d)\u27e9\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00ac m \u2223 p :=\nprime_def_lt.trans $ and_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h m2 l d, not_lt_of_ge m2 ((h l d).symm \u25b8 dec_trivial),\n\u03bb h l d, begin\n  rcases m with _|_|m,\n  { rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },\n  { refl },\n  { exact (h dec_trivial l).elim d }\nend\u27e9\n\ntheorem prime_def_le_sqrt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227\n  \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac m \u2223 p :=\nprime_def_lt'.trans $ and_congr_right $ \u03bb p2,\n\u27e8\u03bb a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,\n \u03bb a, have \u2200 {m k}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k, from\n  \u03bb m k mk m1 e, a m m1\n    (le_sqrt.2 (e.symm \u25b8 nat.mul_le_mul_left m mk)) \u27e8k, e\u27e9,\n  \u03bb m m2 l \u27e8k, e\u27e9, begin\n    cases (le_total m k) with mk km,\n    { exact this mk m2 e },\n    { rw [mul_comm] at e,\n      refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,\n      rwa [one_mul, \u2190 e] }\n  end\u27e9\n\ntheorem prime_of_coprime (n : \u2115) (h1 : 1 < n) (h : \u2200 m < n, m \u2260 0 \u2192 n.coprime m) : prime n :=\nbegin\n  refine prime_def_lt.mpr \u27e8h1, \u03bb m mlt mdvd, _\u27e9,\n  have hm : m \u2260 0,\n  { rintro rfl,\n    rw zero_dvd_iff at mdvd,\n    exact mlt.ne' mdvd },\n  exact (h m mlt hm).symm.eq_one_of_dvd mdvd,\nend\n\nsection\n\n/--\n  This instance is slower than the instance `decidable_prime` defined below,\n  but has the advantage that it works in the kernel for small values.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\nlocal attribute [instance]\ndef decidable_prime_1 (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_lt'\n\ntheorem prime_two : prime 2 := dec_trivial\n\nend\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : 0 < pred p :=\nlt_pred_iff.2 pp.one_lt\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : succ (pred p) = p :=\nsucc_pred_eq_of_pos pp.pos\n\ntheorem dvd_prime {p m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n\u27e8\u03bb d, pp.eq_one_or_self_of_dvd m d, \u03bb h, h.elim (\u03bb e, e.symm \u25b8 one_dvd _) (\u03bb e, e.symm \u25b8 dvd_rfl)\u27e9\n\ntheorem dvd_prime_two_le {p m : \u2115} (pp : prime p) (H : 2 \u2264 m) : m \u2223 p \u2194 m = p :=\n(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H\n\ntheorem prime_dvd_prime_iff_eq {p q : \u2115} (pp : p.prime) (qp : q.prime) : p \u2223 q \u2194 p = q :=\ndvd_prime_two_le qp (prime.two_le pp)\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00ac p \u2223 1 :=\npp.not_dvd_one\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00ac prime (a * b) :=\n\u03bb h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $\nby simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)\n\nlemma not_prime_mul' {a b n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) : \u00ac prime n :=\nby { rw \u2190 h, exact not_prime_mul h\u2081 h\u2082 }\n\nlemma prime_mul_iff {a b : \u2115} :\n  nat.prime (a * b) \u2194 (a.prime \u2227 b = 1) \u2228 (b.prime \u2227 a = 1) :=\nby simp only [iff_self, irreducible_mul_iff, \u2190irreducible_iff_nat_prime, nat.is_unit_iff]\n\nlemma prime.dvd_iff_eq {p a : \u2115} (hp : p.prime) (a1 : a \u2260 1) : a \u2223 p \u2194 p = a :=\nbegin\n  refine \u27e8_, by { rintro rfl, refl }\u27e9,\n  -- rintro \u27e8j, rfl\u27e9 does not work, due to `nat.prime` depending on the class `irreducible`\n  rintro \u27e8j, hj\u27e9,\n  rw hj at hp \u22a2,\n  rcases prime_mul_iff.mp hp with \u27e8h, rfl\u27e9 | \u27e8h, rfl\u27e9,\n  { exact mul_one _ },\n  { exact (a1 rfl).elim }\nend\n\nsection min_fac\n\nlemma min_fac_lemma (n k : \u2115) (h : \u00ac n < k * k) :\n  sqrt n - k < sqrt n + 2 - k :=\n(tsub_lt_tsub_iff_right $ le_sqrt.2 $ le_of_not_gt h).2 $\nnat.lt_add_of_pos_right dec_trivial\n\n/-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.\n  Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.\n  If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/\ndef min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115\n| k :=\n  if h : n < k * k then n else\n  if k \u2223 n then k else\n  have _, from min_fac_lemma n k h,\n  min_fac_aux (k + 2)\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n/-- Returns the smallest prime factor of `n \u2260 1`. -/\ndef min_fac : \u2115 \u2192 \u2115\n| 0 := 2\n| 1 := 1\n| (n+2) := if 2 \u2223 n then 2 else min_fac_aux (n + 2) 3\n\n@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl\n@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\ntheorem min_fac_eq : \u2200 n, min_fac n = if 2 \u2223 n then 2 else min_fac_aux n 3\n| 0     := by simp\n| 1     := by simp [show 2\u22601, from dec_trivial]; rw min_fac_aux; refl\n| (n+2) :=\n  have 2 \u2223 n + 2 \u2194 2 \u2223 n, from\n    (nat.dvd_add_iff_left (by refl)).symm,\n  by simp [min_fac, this]; congr\n\nprivate def min_fac_prop (n k : \u2115) :=\n  2 \u2264 k \u2227 k \u2223 n \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m\n\ntheorem min_fac_aux_has_prop {n : \u2115} (n2 : 2 \u2264 n) :\n  \u2200 k i, k = 2*i+3 \u2192 (\u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k)\n| k := \u03bb i e a, begin\n  rw min_fac_aux,\n  by_cases h : n < k*k; simp [h],\n  { have pp : prime n :=\n      prime_def_le_sqrt.2 \u27e8n2, \u03bb m m2 l d,\n        not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9,\n    from \u27e8n2, dvd_rfl, \u03bb m m2 d, le_of_eq\n      ((dvd_prime_two_le pp m2).1 d).symm\u27e9 },\n  have k2 : 2 \u2264 k, { subst e, exact dec_trivial },\n  by_cases dk : k \u2223 n; simp [dk],\n  { exact \u27e8k2, dk, a\u27e9 },\n  { refine have _, from min_fac_lemma n k h,\n      min_fac_aux_has_prop (k+2) (i+1)\n        (by simp [e, left_distrib]) (\u03bb m m2 d, _),\n    cases nat.eq_or_lt_of_le (a m m2 d) with me ml,\n    { subst me, contradiction },\n    apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,\n    rw [\u2190 me, e] at d, change 2 * (i + 2) \u2223 n at d,\n    have := a _ le_rfl (dvd_of_mul_right_dvd d),\n    rw e at this, exact absurd this dec_trivial }\nend\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\ntheorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) :\n  min_fac_prop n (min_fac n) :=\nbegin\n  by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},\n  have n2 : 2 \u2264 n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },\n  simp [min_fac_eq],\n  by_cases d2 : 2 \u2223 n; simp [d2],\n  { exact \u27e8le_rfl, d2, \u03bb k k2 d, k2\u27e9 },\n  { refine min_fac_aux_has_prop n2 3 0 rfl\n      (\u03bb m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),\n    exact \u03bb e, e.symm \u25b8 d }\nend\n\ntheorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\nif n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1\n\ntheorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) :=\nlet \u27e8f2, fd, a\u27e9 := min_fac_has_prop n1 in\nprime_def_lt'.2 \u27e8f2, \u03bb m m2 l d, not_le_of_gt l (a m m2 (d.trans fd))\u27e9\n\ntheorem min_fac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, 2 \u2264 m \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\nby by_cases n1 : n = 1;\n  [exact \u03bb m m2 d, n1.symm \u25b8 le_trans dec_trivial m2,\n    exact (min_fac_has_prop n1).2.2]\n\ntheorem min_fac_pos (n : \u2115) : 0 < min_fac n :=\nby by_cases n1 : n = 1;\n    [exact n1.symm \u25b8 dec_trivial, exact (min_fac_prime n1).pos]\n\ntheorem min_fac_le {n : \u2115} (H : 0 < n) : min_fac n \u2264 n :=\nle_of_dvd H (min_fac_dvd n)\n\ntheorem le_min_fac {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, prime p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p pp d, h.elim\n  (by rintro rfl; cases pp.not_dvd_one d)\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp.two_le d),\n  \u03bb H, or_iff_not_imp_left.2 $ \u03bb n1, H _ (min_fac_prime n1) (min_fac_dvd _)\u27e9\n\ntheorem le_min_fac' {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, 2 \u2264 p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p (pp:1<p) d, h.elim\n  (by rintro rfl; cases not_le_of_lt pp (le_of_dvd dec_trivial d))\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp d),\n  \u03bb H, le_min_fac.2 (\u03bb p pp d, H p pp.two_le d)\u27e9\n\ntheorem prime_def_min_fac {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 min_fac p = p :=\n\u27e8\u03bb pp, \u27e8pp.two_le,\n  let \u27e8f2, fd, a\u27e9 := min_fac_has_prop $ ne_of_gt pp.one_lt in\n  ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n  \u03bb \u27e8p2, e\u27e9, e \u25b8 min_fac_prime (ne_of_gt p2)\u27e9\n\n@[simp] lemma prime.min_fac_eq {p : \u2115} (hp : prime p) : min_fac p = p :=\n(prime_def_min_fac.1 hp).2\n\n/--\nThis instance is faster in the virtual machine than `decidable_prime_1`,\nbut slower in the kernel.\n\nIf you need to prove that a particular number is prime, in any case\nyou should not use `dec_trivial`, but rather `by norm_num`, which is\nmuch faster.\n-/\ninstance decidable_prime (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_min_fac\n\ntheorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : 2 \u2264 n) : \u00ac prime n \u2194 min_fac n < n :=\n(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $\n  (lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm\n\nlemma min_fac_le_div {n : \u2115} (pos : 0 < n) (np : \u00ac prime n) : min_fac n \u2264 n / min_fac n :=\nmatch min_fac_dvd n with\n| \u27e80, h0\u27e9     := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial\n| \u27e81, h1\u27e9     :=\n  begin\n    rw mul_one at h1,\n    rw [prime_def_min_fac, not_and_distrib, \u2190 h1, eq_self_iff_true, not_true, or_false,\n      not_le] at np,\n    rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]\n  end\n| \u27e8(x+2), hx\u27e9 :=\n  begin\n    conv_rhs { congr, rw hx },\n    rw [nat.mul_div_cancel_left _ (min_fac_pos _)],\n    exact min_fac_le_of_dvd dec_trivial \u27e8min_fac n, by rwa mul_comm\u27e9\n  end\nend\n\n/--\nThe square of the smallest prime factor of a composite number `n` is at most `n`.\n-/\nlemma min_fac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00ac prime n) : (min_fac n)^2 \u2264 n :=\nhave t : (min_fac n) \u2264 (n/min_fac n) := min_fac_le_div w h,\ncalc\n(min_fac n)^2 = (min_fac n) * (min_fac n)   : sq (min_fac n)\n          ... \u2264 (n/min_fac n) * (min_fac n) : nat.mul_le_mul_right (min_fac n) t\n          ... \u2264 n                           : div_mul_le_self n (min_fac n)\n\n@[simp]\nlemma min_fac_eq_one_iff {n : \u2115} : min_fac n = 1 \u2194 n = 1 :=\nbegin\n  split,\n  { intro h,\n    by_contradiction hn,\n    have := min_fac_prime hn,\n    rw h at this,\n    exact not_prime_one this, },\n  { rintro rfl, refl, }\nend\n\n@[simp]\nlemma min_fac_eq_two_iff (n : \u2115) : min_fac n = 2 \u2194 2 \u2223 n :=\nbegin\n  split,\n  { intro h,\n    convert min_fac_dvd _,\n    rw h, },\n  { intro h,\n    have ub := min_fac_le_of_dvd (le_refl 2) h,\n    have lb := min_fac_pos n,\n    apply ub.eq_or_lt.resolve_right (\u03bb h', _),\n    have := le_antisymm (nat.succ_le_of_lt lb) (lt_succ_iff.mp h'),\n    rw [eq_comm, nat.min_fac_eq_one_iff] at this,\n    subst this,\n    exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two }\nend\n\nend min_fac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n\u27e8min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,\n  ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 2 \u2264 m \u2227 m < n :=\n\u27e8min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,\n  (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_prime_and_dvd {n : \u2115} (hn : n \u2260 1) : \u2203 p, prime p \u2227 p \u2223 n :=\n\u27e8min_fac n, min_fac_prime hn, min_fac_dvd _\u27e9\n\n/-- Euclid's theorem on the **infinitude of primes**.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, n \u2264 p \u2227 prime p :=\nlet p := min_fac (n! + 1) in\nhave f1 : n! + 1 \u2260 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,\nhave pp : prime p, from min_fac_prime f1,\nhave np : n \u2264 p, from le_of_not_ge $ \u03bb h,\n  have h\u2081 : p \u2223 n!, from dvd_factorial (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  pp.not_dvd_one h\u2082,\n\u27e8p, np, pp\u27e9\n\n/-- A version of `nat.exists_infinite_primes` using the `bdd_above` predicate. -/\nlemma not_bdd_above_set_of_prime : \u00ac bdd_above {p | prime p} :=\nbegin\n  rw not_bdd_above_iff,\n  intro n,\n  obtain \u27e8p, hi, hp\u27e9 := exists_infinite_primes n.succ,\n  exact \u27e8p, hp, hi\u27e9,\nend\n\n/-- A version of `nat.exists_infinite_primes` using the `set.infinite` predicate. -/\nlemma infinite_set_of_prime : {p | prime p}.infinite :=\nset.infinite_of_not_bdd_above not_bdd_above_set_of_prime\n\nlemma prime.eq_two_or_odd {p : \u2115} (hp : prime p) : p = 2 \u2228 p % 2 = 1 :=\np.mod_two_eq_zero_or_one.imp_left\n  (\u03bb h, ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)\n\nlemma prime.eq_two_or_odd' {p : \u2115} (hp : prime p) : p = 2 \u2228 odd p :=\nor.imp_right (\u03bb h, \u27e8p / 2, (div_add_mod p 2).symm.trans (congr_arg _ h)\u27e9) hp.eq_two_or_odd\n\nlemma prime.even_iff {p : \u2115} (hp : prime p) : even p \u2194 p = 2 :=\nby rw [even_iff_two_dvd, prime_dvd_prime_iff_eq prime_two hp, eq_comm]\n\n/-- A prime `p` satisfies `p % 2 = 1` if and only if `p \u2260 2`. -/\nlemma prime.mod_two_eq_one_iff_ne_two {p : \u2115} [fact p.prime] : p % 2 = 1 \u2194 p \u2260 2 :=\nbegin\n  refine \u27e8\u03bb h hf, _, (nat.prime.eq_two_or_odd $ fact.out p.prime).resolve_left\u27e9,\n  rw hf at h,\n  simpa using h,\nend\n\ntheorem coprime_of_dvd {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 \u00ac k \u2223 n) : coprime m n :=\nbegin\n  rw [coprime_iff_gcd_eq_one],\n  by_contra g2,\n  obtain \u27e8p, hp, hpdvd\u27e9 := exists_prime_and_dvd g2,\n  apply H p hp; apply dvd_trans hpdvd,\n  { exact gcd_dvd_left _ _ },\n  { exact gcd_dvd_right _ _ }\nend\n\ntheorem coprime_of_dvd' {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) : coprime m n :=\ncoprime_of_dvd $ \u03bbk kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn\n\ntheorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=\ndiv_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 list \u2115\n| 0 := []\n| 1 := []\n| n@(k+2) :=\n  let m := min_fac n in have n / m < n := factors_lemma,\n  m :: factors (n / m)\n\n@[simp] lemma factors_zero : factors 0 = [] := by rw factors\n@[simp] lemma factors_one : factors 1 = [] := by rw factors\n\nlemma prime_of_mem_factors : \u2200 {n p}, p \u2208 factors n \u2192 prime p\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb p h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  have h\u2081 : p = m \u2228 p \u2208 (factors (n / m)) :=\n    (list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),\n  or.cases_on h\u2081 (\u03bb h\u2082, h\u2082.symm \u25b8 min_fac_prime dec_trivial)\n    prime_of_mem_factors\n\nlemma pos_of_mem_factors {n p : \u2115} (h : p \u2208 factors n) : 0 < p :=\nprime.pos (prime_of_mem_factors h)\n\nlemma prod_factors : \u2200 {n}, n \u2260 0 \u2192 list.prod (factors n) = n\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  show (factors n).prod = n, from\n  have h\u2081 : n / m \u2260 0 := \u03bb h,\n    have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,\n    by rw zero_mul at this; exact (show k + 2 \u2260 0, from dec_trivial) this,\n  by rw [factors, list.prod_cons, prod_factors h\u2081, nat.mul_div_cancel' (min_fac_dvd _)]\n\nlemma factors_prime {p : \u2115} (hp : nat.prime p) : p.factors = [p] :=\nbegin\n  have : p = (p - 2) + 2 := (tsub_eq_iff_eq_add_of_le hp.two_le).mp rfl,\n  rw [this, nat.factors],\n  simp only [eq.symm this],\n  have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,\n  split,\n  { exact this, },\n  { simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },\nend\n\nlemma factors_chain : \u2200 {n a}, (\u2200 p, prime p \u2192 p \u2223 n \u2192 a \u2264 p) \u2192 list.chain (\u2264) a (factors n)\n| 0       := \u03bb a h, by simp\n| 1       := \u03bb a h, by simp\n| n@(k+2) := \u03bb a h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  begin\n    rw factors,\n    refine list.chain.cons ((le_min_fac.2 h).resolve_left dec_trivial) (factors_chain _),\n    exact \u03bb p pp d, min_fac_le_of_dvd pp.two_le (d.trans $ div_dvd_of_dvd $ min_fac_dvd _),\n  end\n\nlemma factors_chain_2 (n) : list.chain (\u2264) 2 (factors n) := factors_chain $ \u03bb p pp _, pp.two_le\n\nlemma factors_chain' (n) : list.chain' (\u2264) (factors n) :=\n@list.chain'.tail _ _ (_::_) (factors_chain_2 _)\n\nlemma factors_sorted (n : \u2115) : list.sorted (\u2264) (factors n) :=\n(list.chain'_iff_pairwise (@le_trans _ _)).1 (factors_chain' _)\n\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\nlemma factors_add_two (n : \u2115) :\n  factors (n+2) = min_fac (n+2) :: factors ((n+2) / min_fac (n+2)) :=\nby rw factors\n\n@[simp]\nlemma factors_eq_nil (n : \u2115) : n.factors = [] \u2194 n = 0 \u2228 n = 1 :=\nbegin\n  split; intro h,\n  { rcases n with (_ | _ | n),\n    { exact or.inl rfl },\n    { exact or.inr rfl },\n    { rw factors at h, injection h }, },\n  { rcases h with (rfl | rfl),\n    { exact factors_zero },\n    { exact factors_one }, }\nend\n\nlemma eq_of_perm_factors {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) (h : a.factors ~ b.factors) : a = b :=\nby simpa [prod_factors ha, prod_factors hb] using list.perm.prod_eq h\n\ntheorem prime.coprime_iff_not_dvd {p n : \u2115} (pp : prime p) : coprime p n \u2194 \u00ac p \u2223 n :=\n\u27e8\u03bb co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),\n \u03bb nd, coprime_of_dvd $ \u03bb m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm \u25b8 nd\u27e9\n\ntheorem prime.dvd_iff_not_coprime {p n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00ac coprime p n :=\niff_not_comm.2 pp.coprime_iff_not_dvd\n\ntheorem prime.not_coprime_iff_dvd {m n : \u2115} :\n  \u00ac coprime m n \u2194 \u2203p, prime p \u2227 p \u2223 m \u2227 p \u2223 n :=\nbegin\n  apply iff.intro,\n  { intro h,\n    exact \u27e8min_fac (gcd m n), min_fac_prime h,\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_left m n)),\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_right m n))\u27e9 },\n  { intro h,\n    cases h with p hp,\n    apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }\nend\n\ntheorem prime.dvd_mul {p m n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n\u27e8\u03bb H, or_iff_not_imp_left.2 $ \u03bb h,\n  (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n or.rec (\u03bb h : p \u2223 m, h.mul_right _) (\u03bb h : p \u2223 n, h.mul_left _)\u27e9\n\ntheorem prime.not_dvd_mul {p m n : \u2115} (pp : prime p)\n  (Hm : \u00ac p \u2223 m) (Hn : \u00ac p \u2223 n) : \u00ac p \u2223 m * n :=\nmt pp.dvd_mul.1 $ by simp [Hm, Hn]\n\ntheorem prime_iff {p : \u2115} : p.prime \u2194 _root_.prime p :=\n\u27e8\u03bb h, \u27e8h.ne_zero, h.not_unit, \u03bb a b, h.dvd_mul.mp\u27e9, prime.irreducible\u27e9\n\ntheorem irreducible_iff_prime {p : \u2115} : irreducible p \u2194 _root_.prime p :=\nby rw [\u2190prime_iff, prime]\n\ntheorem prime.dvd_of_dvd_pow {p m n : \u2115} (pp : prime p) (h : p \u2223 m^n) : p \u2223 m :=\nbegin\n  induction n with n IH,\n  { exact pp.not_dvd_one.elim h },\n  { rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH }\nend\n\nlemma prime.pow_not_prime {x n : \u2115} (hn : 2 \u2264 n) : \u00ac (x ^ n).prime :=\n\u03bb hp, (hp.eq_one_or_self_of_dvd x $ dvd_trans \u27e8x, sq _\u27e9 (pow_dvd_pow _ hn)).elim\n  (\u03bb hx1, hp.ne_one $ hx1.symm \u25b8 one_pow _)\n  (\u03bb hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm\n     ... < x ^ n : nat.pow_right_strict_mono (hxn.symm \u25b8 hp.two_le) hn\n     ... = x : hxn.symm)\n\nlemma prime.pow_not_prime' {x : \u2115} : \u2200 {n : \u2115}, n \u2260 1 \u2192 \u00ac (x ^ n).prime\n| 0     := \u03bb _, not_prime_one\n| 1     := \u03bb h, (h rfl).elim\n| (n+2) := \u03bb _, prime.pow_not_prime le_add_self\n\nlemma prime.eq_one_of_pow {x n : \u2115} (h : (x ^ n).prime) : n = 1 :=\nnot_imp_not.mp prime.pow_not_prime' h\n\nlemma prime.pow_eq_iff {p a k : \u2115} (hp : p.prime) : a ^ k = p \u2194 a = p \u2227 k = 1 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, by rw [h.1, h.2, pow_one]\u27e9,\n  rw \u2190h at hp,\n  rw [\u2190h, hp.eq_one_of_pow, eq_self_iff_true, and_true, pow_one],\nend\n\nlemma pow_min_fac {n k : \u2115} (hk : k \u2260 0) : (n^k).min_fac = n.min_fac :=\nbegin\n  rcases eq_or_ne n 1 with rfl | hn,\n  { simp },\n  have hnk : n ^ k \u2260 1 := \u03bb hk', hn ((pow_eq_one_iff hk).1 hk'),\n  apply (min_fac_le_of_dvd (min_fac_prime hn).two_le ((min_fac_dvd n).pow hk)).antisymm,\n  apply min_fac_le_of_dvd (min_fac_prime hnk).two_le\n    ((min_fac_prime hnk).dvd_of_dvd_pow (min_fac_dvd _)),\nend\n\nlemma prime.pow_min_fac {p k : \u2115} (hp : p.prime) (hk : k \u2260 0) : (p^k).min_fac = p :=\nby rw [pow_min_fac hk, hp.min_fac_eq]\n\nlemma prime.mul_eq_prime_sq_iff {x y p : \u2115} (hp : p.prime) (hx : x \u2260 1) (hy : y \u2260 1) :\n  x * y = p ^ 2 \u2194 x = p \u2227 y = p :=\n\u27e8\u03bb h, have pdvdxy : p \u2223 x * y, by rw h; simp [sq],\nbegin\n  wlog := hp.dvd_mul.1 pdvdxy using x y,\n  cases case with a ha,\n  have hap : a \u2223 p, from \u27e8y, by rwa [ha, sq,\n        mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at h\u27e9,\n  exact ((nat.dvd_prime hp).1 hap).elim\n    (\u03bb _, by clear_aux_decl; simp [*, sq, nat.mul_right_inj hp.pos] at *\n      {contextual := tt})\n    (\u03bb _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,\n      nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *\n      {contextual := tt})\nend,\n\u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.symm \u25b8 h\u2082.symm \u25b8 (sq _).symm\u27e9\n\nlemma prime.dvd_factorial : \u2200 {n p : \u2115} (hp : prime p), p \u2223 n! \u2194 p \u2264 n\n| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)\n| (n+1) p hp := begin\n  rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],\n  exact \u27e8\u03bb h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,\n    \u03bb h, (_root_.lt_or_eq_of_le h).elim (or.inr \u2218 le_of_lt_succ)\n      (\u03bb h, or.inl $ by rw h)\u27e9\nend\n\ntheorem prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : prime p) (h : \u00ac p \u2223 a) : coprime a (p^m) :=\n(pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n\ntheorem coprime_primes {p q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\npp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : prime p) (pq : prime q) (h : p \u2260 q) :\n  coprime (p^n) (q^m) :=\n((coprime_primes pp pq).2 h).pow _ _\n\ntheorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\nby rw [pp.dvd_iff_not_coprime]; apply em\n\nlemma coprime_of_lt_prime {n p} (n_pos : 0 < n) (hlt : n < p) (pp : prime p) :\n  coprime p n :=\n(coprime_or_dvd_of_prime pp n).resolve_right $ \u03bb h, lt_le_antisymm hlt (le_of_dvd n_pos h)\n\nlemma eq_or_coprime_of_le_prime {n p} (n_pos : 0 < n) (hle : n \u2264 p) (pp : prime p) :\n  p = n \u2228 coprime p n :=\nhle.eq_or_lt.imp eq.symm (\u03bb h, coprime_of_lt_prime n_pos h pp)\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m i : \u2115} : i \u2223 (p^m) \u2194 \u2203 k \u2264 m, i = p^k :=\nby simp_rw [dvd_prime_pow (prime_iff.mp pp) m, associated_eq_eq]\n\nlemma prime.dvd_mul_of_dvd_ne {p1 p2 n : \u2115} (h_neq : p1 \u2260 p2) (pp1 : prime p1) (pp2 : prime p2)\n  (h1 : p1 \u2223 n) (h2 : p2 \u2223 n) : (p1 * p2 \u2223 n) :=\ncoprime.mul_dvd_of_dvd_of_dvd ((coprime_primes pp1 pp2).mpr h_neq) h1 h2\n\n/--\nIf `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\nlemma eq_prime_pow_of_dvd_least_prime_pow\n  {a p k : \u2115} (pp : prime p) (h\u2081 : \u00ac(a \u2223 p^k)) (h\u2082 : a \u2223 p^(k+1)) :\n  a = p^(k+1) :=\nbegin\n  obtain \u27e8l, \u27e8h, rfl\u27e9\u27e9 := (dvd_prime_pow pp).1 h\u2082,\n  congr,\n  exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h\u2081)),\nend\n\nlemma ne_one_iff_exists_prime_dvd : \u2200 {n}, n \u2260 1 \u2194 \u2203 p : \u2115, p.prime \u2227 p \u2223 n\n| 0 := by simpa using (Exists.intro 2 nat.prime_two)\n| 1 := by simp [nat.not_prime_one]\n| (n+2) :=\nlet a := n+2 in\nlet ha : a \u2260 1 := nat.succ_succ_ne_one n in\nbegin\n  simp only [true_iff, ne.def, not_false_iff, ha],\n  exact \u27e8a.min_fac, nat.min_fac_prime ha, a.min_fac_dvd\u27e9,\nend\n\nlemma eq_one_iff_not_exists_prime_dvd {n : \u2115} : n = 1 \u2194 \u2200 p : \u2115, p.prime \u2192 \u00acp \u2223 n :=\nby simpa using not_iff_not.mpr ne_one_iff_exists_prime_dvd\n\nsection\nopen list\n\nlemma mem_factors_iff_dvd {n p : \u2115} (hn : n \u2260 0) (hp : prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n\u27e8\u03bb h, prod_factors hn \u25b8 list.dvd_prod h,\n  \u03bb h, mem_list_primes_of_dvd_prod\n    (prime_iff.mp hp)\n    (\u03bb p h, prime_iff.mp (prime_of_mem_factors h))\n    ((prod_factors hn).symm \u25b8 h)\u27e9\n\nlemma dvd_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2223 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { exact dvd_zero p },\n  { rwa \u2190mem_factors_iff_dvd hn.ne' (prime_of_mem_factors h) }\nend\n\nlemma mem_factors {n p} (hn : n \u2260 0) : p \u2208 factors n \u2194 prime p \u2227 p \u2223 n :=\n\u27e8\u03bb h, \u27e8prime_of_mem_factors h, dvd_of_mem_factors h\u27e9,\n \u03bb \u27e8hprime, hdvd\u27e9, (mem_factors_iff_dvd hn hprime).mpr hdvd\u27e9\n\nlemma le_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2264 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { rw factors_zero at h, cases h },\n  { exact le_of_dvd hn (dvd_of_mem_factors h) },\nend\n\n/-- **Fundamental theorem of arithmetic**-/\nlemma factors_unique {n : \u2115} {l : list \u2115} (h\u2081 : prod l = n) (h\u2082 : \u2200 p \u2208 l, prime p) :\n  l ~ factors n :=\nbegin\n  refine perm_of_prod_eq_prod _ _ _,\n  { rw h\u2081,\n    refine (prod_factors _).symm,\n    rintro rfl,\n    rw prod_eq_zero_iff at h\u2081,\n    exact prime.ne_zero (h\u2082 0 h\u2081) rfl },\n  { simp_rw \u2190prime_iff, exact h\u2082 },\n  { simp_rw \u2190prime_iff, exact (\u03bb p, prime_of_mem_factors) },\nend\n\nlemma prime.factors_pow {p : \u2115} (hp : p.prime) (n : \u2115) :\n  (p ^ n).factors = list.repeat p n :=\nbegin\n  symmetry,\n  rw \u2190 list.repeat_perm,\n  apply nat.factors_unique (list.prod_repeat p n),\n  intros q hq,\n  rwa eq_of_mem_repeat hq,\nend\n\nlemma eq_prime_pow_of_unique_prime_dvd {n p : \u2115} (hpos : n \u2260 0)\n  (h : \u2200 {d}, nat.prime d \u2192 d \u2223 n \u2192 d = p) :\n  n = p ^ n.factors.length :=\nbegin\n  set k := n.factors.length,\n  rw [\u2190prod_factors hpos, \u2190prod_repeat p k,\n    eq_repeat_of_mem (\u03bb d hd, h (prime_of_mem_factors hd) (dvd_of_mem_factors hd))],\nend\n\n/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  refine (factors_unique _ _).symm,\n  { rw [list.prod_append, prod_factors ha, prod_factors hb] },\n  { intros p hp,\n    rw list.mem_append at hp,\n    cases hp;\n    exact prime_of_mem_factors hp },\nend\n\n/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  exact perm_factors_mul ha.ne' hb.ne',\nend\n\nlemma factors_sublist_right {n k : \u2115} (h : k \u2260 0) : n.factors <+ (n * k).factors :=\nbegin\n  cases n,\n  { rw zero_mul },\n  apply sublist_of_subperm_of_sorted _ (factors_sorted _) (factors_sorted _),\n  rw (perm_factors_mul n.succ_ne_zero h).subperm_left,\n  exact (sublist_append_left _ _).subperm,\nend\n\nlemma factors_sublist_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors <+ k.factors :=\nbegin\n  obtain \u27e8a, rfl\u27e9 := h,\n  exact factors_sublist_right (right_ne_zero_of_mul h'),\nend\n\nlemma factors_subset_right {n k : \u2115} (h : k \u2260 0) : n.factors \u2286 (n * k).factors :=\n(factors_sublist_right h).subset\n\nlemma factors_subset_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors \u2286 k.factors :=\n(factors_sublist_of_dvd h h').subset\n\nlemma dvd_of_factors_subperm {a b : \u2115} (ha : a \u2260 0) (h : a.factors <+~ b.factors) : a \u2223 b :=\nbegin\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { exact dvd_zero _ },\n  rcases a with (_|_|a),\n  { exact (ha rfl).elim },\n  { exact one_dvd _ },\n  use (b.factors.diff a.succ.succ.factors).prod,\n  nth_rewrite 0 \u2190nat.prod_factors ha,\n  rw [\u2190list.prod_append,\n      list.perm.prod_eq $ list.subperm_append_diff_self_of_count_le $ list.subperm_ext_iff.mp h,\n      nat.prod_factors hb.ne']\nend\n\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m n k l : \u2115}\n      (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k+l+1) \u2223 m*n) :\n      p ^ (k+1) \u2223 m \u2228 p ^ (l+1) \u2223 n :=\nhave hpd : p^(k+l)*p \u2223 m*n, by rwa pow_succ' at hpmn,\nhave hpd2 : p \u2223 (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,\nhave hpd3 : p \u2223 (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,\nhave hpd4 : p \u2223 (m / p^k) * (n / p^l), by simpa [nat.div_mul_div_comm hpm hpn] using hpd3,\nhave hpd5 : p \u2223 (m / p^k) \u2228 p \u2223 (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,\nsuffices p^k*p \u2223 m \u2228 p^l*p \u2223 n, by rwa [pow_succ', pow_succ'],\n  hpd5.elim\n    (assume : p \u2223 m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)\n    (assume : p \u2223 n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)\n\nlemma prime_iff_prime_int {p : \u2115} : p.prime \u2194 _root_.prime (p : \u2124) :=\n\u27e8\u03bb hp, \u27e8int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt int.is_unit_iff_nat_abs_eq.1 hp.ne_one,\n  \u03bb a b h, by rw [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;\n    rwa [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, \u2190 int.dvd_nat_abs, int.coe_nat_dvd]\u27e9,\n  \u03bb hp, nat.prime_iff.2 \u27e8int.coe_nat_ne_zero.1 hp.1,\n      mt nat.is_unit_iff.1 $ \u03bb h, by simpa [h, not_prime_one] using hp,\n    \u03bb a b, by simpa only [int.coe_nat_dvd, (int.coe_nat_mul _ _).symm] using hp.2.2 a b\u27e9\u27e9\n\n/-- The type of prime numbers -/\ndef primes := {p : \u2115 // p.prime}\n\nnamespace primes\n\ninstance : has_repr nat.primes := \u27e8\u03bb p, repr p.val\u27e9\ninstance inhabited_primes : inhabited primes := \u27e8\u27e82, prime_two\u27e9\u27e9\n\ninstance coe_nat : has_coe nat.primes \u2115 := \u27e8subtype.val\u27e9\n\ntheorem coe_nat_inj (p q : nat.primes) : (p : \u2115) = (q : \u2115) \u2192 p = q :=\n\u03bb h, subtype.eq h\n\nend primes\n\ninstance monoid.prime_pow {\u03b1 : Type*} [monoid \u03b1] : has_pow \u03b1 primes := \u27e8\u03bb x p, x^p.val\u27e9\n\nend nat\n\n/-! ### Primality prover -/\n\nopen norm_num\n\nnamespace tactic\nnamespace norm_num\n\nlemma is_prime_helper (n : \u2115)\n  (h\u2081 : 1 < n) (h\u2082 : nat.min_fac n = n) : nat.prime n :=\nnat.prime_def_min_fac.2 \u27e8h\u2081, h\u2082\u27e9\n\nlemma min_fac_bit0 (n : \u2115) : nat.min_fac (bit0 n) = 2 :=\nby simp [nat.min_fac_eq, show 2 \u2223 bit0 n, by simp [bit0_eq_two_mul n]]\n\n/-- A predicate representing partial progress in a proof of `min_fac`. -/\ndef min_fac_helper (n k : \u2115) : Prop :=\n0 < k \u2227 bit1 k \u2264 nat.min_fac (bit1 n)\n\ntheorem min_fac_helper.n_pos {n k : \u2115} (h : min_fac_helper n k) : 0 < n :=\npos_iff_ne_zero.2 $ \u03bb e,\nby rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2\n\nlemma min_fac_ne_bit0 {n k : \u2115} : nat.min_fac (bit1 n) \u2260 bit0 k :=\nbegin\n  rw bit0_eq_two_mul,\n  refine (\u03bb e, absurd ((nat.dvd_add_iff_right _).2\n    (dvd_trans \u27e8_, e\u27e9 (nat.min_fac_dvd _))) _); simp\nend\n\nlemma min_fac_helper_0 (n : \u2115) (h : 0 < n) : min_fac_helper n 1 :=\nbegin\n  refine \u27e8zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symm\u27e9,\n  rw nat.succ_le_iff,\n  refine lt_of_le_of_ne (nat.min_fac_pos _) (\u03bb e, nat.not_prime_one _),\n  rw e,\n  exact nat.min_fac_prime (nat.bit1_lt h).ne',\nend\n\nlemma min_fac_helper_1 {n k k' : \u2115} (e : k + 1 = k')\n  (np : nat.min_fac (bit1 n) \u2260 bit1 k)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  rw \u2190 e,\n  refine \u27e8nat.succ_pos _,\n    (lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)\n      min_fac_ne_bit0.symm : bit0 (k+1) < _)\u27e9,\n  { rw add_right_comm, exact h.2 },\n  { rw add_right_comm, exact np.symm }\nend\n\nlemma min_fac_helper_2 (n k k' : \u2115) (e : k + 1 = k')\n  (np : \u00ac nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  intro e\u2081, rw \u2190 e\u2081 at np,\n  exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)\nend\n\nlemma min_fac_helper_3 (n k k' c : \u2115) (e : k + 1 = k')\n  (nc : bit1 n % bit1 k = c) (c0 : 0 < c)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  refine mt _ (ne_of_gt c0), intro e\u2081,\n  rw [\u2190 nc, \u2190 nat.dvd_iff_mod_eq_zero, \u2190 e\u2081],\n  apply nat.min_fac_dvd\nend\n\nlemma min_fac_helper_4 (n k : \u2115) (hd : bit1 n % bit1 k = 0)\n  (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=\nby { rw \u2190 nat.dvd_iff_mod_eq_zero at hd,\n  exact le_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2 }\n\nlemma min_fac_helper_5 (n k k' : \u2115) (e : bit1 k * bit1 k = k')\n  (hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=\nbegin\n  refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2\n    \u27e8nat.bit1_lt h.n_pos, _\u27e9)).2,\n  rw \u2190 e at hd,\n  intros m m2 hm md,\n  have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),\n  rw nat.le_sqrt at this,\n  exact not_le_of_lt hd this\nend\n\n/-- Given `e` a natural numeral and `d : nat` a factor of it, return `\u22a2 \u00ac prime e`. -/\nmeta def prove_non_prime (e : expr) (n d\u2081 : \u2115) : tactic expr :=\ndo let e\u2081 := reflect d\u2081,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n  let d\u2082 := n / d\u2081, let e\u2082 := reflect d\u2082,\n  (c, e', p) \u2190 prove_mul_nat c e\u2081 e\u2082,\n  guard (e' =\u2090 e),\n  (c, p\u2082) \u2190 prove_lt_nat c `(1) e\u2082,\n  return $ `(@nat.not_prime_mul').mk_app [e\u2081, e\u2082, e, p, p\u2081, p\u2082]\n\n/-- Given `a`,`a1 := bit1 a`, `n1` the value of `a1`, `b` and `p : min_fac_helper a b`,\n  returns `(c, \u22a2 min_fac a1 = c)`. -/\nmeta def prove_min_fac_aux (a a1 : expr) (n1 : \u2115) :\n  instance_cache \u2192 expr \u2192 expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| ic b p := do\n  k \u2190 b.to_nat,\n  let k1 := bit1 k,\n  let b1 := `(bit1:\u2115\u2192\u2115).mk_app [b],\n  if n1 < k1*k1 then do\n    (ic, e', p\u2081) \u2190 prove_mul_nat ic b1 b1,\n    (ic, p\u2082) \u2190 prove_lt_nat ic a1 e',\n    return (ic, a1, `(min_fac_helper_5).mk_app [a, b, e', p\u2081, p\u2082, p])\n  else let d := k1.min_fac in\n  if to_bool (d < k1) then do\n    let k' := k+1, let e' := reflect k',\n    (ic, p\u2081) \u2190 prove_succ ic b e',\n    p\u2082 \u2190 prove_non_prime b1 k1 d,\n    prove_min_fac_aux ic e' $ `(min_fac_helper_2).mk_app [a, b, e', p\u2081, p\u2082, p]\n  else do\n    let nc := n1 % k1,\n    (ic, c, pc) \u2190 prove_div_mod ic a1 b1 tt,\n    if nc = 0 then\n      return (ic, b1, `(min_fac_helper_4).mk_app [a, b, pc, p])\n    else do\n      (ic, p\u2080) \u2190 prove_pos ic c,\n      let k' := k+1, let e' := reflect k',\n      (ic, p\u2081) \u2190 prove_succ ic b e',\n      prove_min_fac_aux ic e' $ `(min_fac_helper_3).mk_app [a, b, e', c, p\u2081, pc, p\u2080, p]\n\n/-- Given `a` a natural numeral, returns `(b, \u22a2 min_fac a = b)`. -/\nmeta def prove_min_fac (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\nmatch match_numeral e with\n| match_numeral_result.zero := return (ic, `(2:\u2115), `(nat.min_fac_zero))\n| match_numeral_result.one := return (ic, `(1:\u2115), `(nat.min_fac_one))\n| match_numeral_result.bit0 e := return (ic, `(2), `(min_fac_bit0).mk_app [e])\n| match_numeral_result.bit1 e := do\n  n \u2190 e.to_nat,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p) \u2190 prove_pos c e,\n  let a1 := `(bit1:\u2115\u2192\u2115).mk_app [e],\n  prove_min_fac_aux e a1 (bit1 n) c `(1) (`(min_fac_helper_0).mk_app [e, p])\n| _ := failed\nend\n\n/-- A partial proof of `factors`. Asserts that `l` is a sorted list of primes, lower bounded by a\nprime `p`, which multiplies to `n`. -/\ndef factors_helper (n p : \u2115) (l : list \u2115) : Prop :=\np.prime \u2192 list.chain (\u2264) p l \u2227 (\u2200 a \u2208 l, nat.prime a) \u2227 list.prod l = n\n\nlemma factors_helper_nil (a : \u2115) : factors_helper 1 a [] :=\n\u03bb pa, \u27e8list.chain.nil, by rintro _ \u27e8\u27e9, list.prod_nil\u27e9\n\nlemma factors_helper_cons' (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a \u2264 b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\n\u03bb pa,\n  have pb : b.prime, from nat.prime_def_min_fac.2 \u27e8le_trans pa.two_le h\u2082, h\u2083\u27e9,\n  let \u27e8f\u2081, f\u2082, f\u2083\u27e9 := H pb in\n  \u27e8list.chain.cons h\u2082 f\u2081, \u03bb c h, h.elim (\u03bb e, e.symm \u25b8 pb) (f\u2082 _),\n   by rw [list.prod_cons, f\u2083, h\u2081]\u27e9\n\nlemma factors_helper_cons (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a < b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\nfactors_helper_cons' _ _ _ _ _ h\u2081 h\u2082.le h\u2083 H\n\nlemma factors_helper_sn (n a : \u2115) (h\u2081 : a < n) (h\u2082 : nat.min_fac n = n) : factors_helper n a [n] :=\nfactors_helper_cons _ _ _ _ _ (mul_one _) h\u2081 h\u2082 (factors_helper_nil _)\n\nlemma factors_helper_same (n m a : \u2115) (l : list \u2115) (h : a * m = n)\n  (H : factors_helper m a l) : factors_helper n a (a :: l) :=\n\u03bb pa, factors_helper_cons' _ _ _ _ _ h le_rfl (nat.prime_def_min_fac.1 pa).2 H pa\n\nlemma factors_helper_same_sn (a : \u2115) : factors_helper a a [a] :=\nfactors_helper_same _ _ _ _ (mul_one _) (factors_helper_nil _)\n\nlemma factors_helper_end (n : \u2115) (l : list \u2115) (H : factors_helper n 2 l) : nat.factors n = l :=\nlet \u27e8h\u2081, h\u2082, h\u2083\u27e9 := H nat.prime_two in\nhave _, from (list.chain'_iff_pairwise (@le_trans _ _)).1 (@list.chain'.tail _ _ (_::_) h\u2081),\n(list.eq_of_perm_of_sorted (nat.factors_unique h\u2083 h\u2082) this (nat.factors_sorted _)).symm\n\n/-- Given `n` and `a` natural numerals, returns `(l, \u22a2 factors_helper n a l)`. -/\nmeta def prove_factors_aux :\n  instance_cache \u2192 expr \u2192 expr \u2192 \u2115 \u2192 \u2115 \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| c en ea n a :=\n  let b := n.min_fac in\n  if b < n then do\n    let m := n / b,\n    (c, em) \u2190 c.of_nat m,\n    if b = a then do\n      (c, _, p\u2081) \u2190 prove_mul_nat c ea em,\n      (c, l, p\u2082) \u2190 prove_factors_aux c em ea m a,\n      pure (c, `(%%ea::%%l:list \u2115), `(factors_helper_same).mk_app [en, em, ea, l, p\u2081, p\u2082])\n    else do\n      (c, eb) \u2190 c.of_nat b,\n      (c, _, p\u2081) \u2190 prove_mul_nat c eb em,\n      (c, p\u2082) \u2190 prove_lt_nat c ea eb,\n      (c, _, p\u2083) \u2190 prove_min_fac c eb,\n      (c, l, p\u2084) \u2190 prove_factors_aux c em eb m b,\n      pure (c, `(%%eb::%%l : list \u2115),\n        `(factors_helper_cons).mk_app [en, em, ea, eb, l, p\u2081, p\u2082, p\u2083, p\u2084])\n  else if b = a then\n    pure (c, `([%%ea] : list \u2115), `(factors_helper_same_sn).mk_app [ea])\n  else do\n    (c, p\u2081) \u2190 prove_lt_nat c ea en,\n    (c, _, p\u2082) \u2190 prove_min_fac c en,\n    pure (c, `([%%en] : list \u2115), `(factors_helper_sn).mk_app [en, ea, p\u2081, p\u2082])\n\n/-- Evaluates the `prime` and `min_fac` functions. -/\n@[norm_num] meta def eval_prime : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.prime %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := false_intro `(nat.not_prime_zero)\n  | 1 := false_intro `(nat.not_prime_one)\n  | _ := let d\u2081 := n.min_fac in\n    if d\u2081 < n then prove_non_prime e n d\u2081 >>= false_intro\n    else do\n      let e\u2081 := reflect d\u2081,\n      c \u2190 mk_instance_cache `(\u2115),\n      (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n      (c, e\u2081, p) \u2190 prove_min_fac c e,\n      true_intro $ `(is_prime_helper).mk_app [e, p\u2081, p]\n  end\n| `(nat.min_fac %%e) := do\n  ic \u2190 mk_instance_cache `(\u2115),\n  prod.snd <$> prove_min_fac ic e\n| `(nat.factors %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := pure (`(@list.nil \u2115), `(nat.factors_zero))\n  | 1 := pure (`(@list.nil \u2115), `(nat.factors_one))\n  | _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, l, p) \u2190 prove_factors_aux c e `(2) n 2,\n    pure (l, `(factors_helper_end).mk_app [e, l, p])\n  end\n| _ := failed\n\nend norm_num\nend tactic\n\nnamespace nat\n\ntheorem prime_three : prime 3 := by norm_num\n\ninstance fact_prime_two : fact (prime 2) := \u27e8prime_two\u27e9\n\ninstance fact_prime_three : fact (prime 3) := \u27e8prime_three\u27e9\n\nend nat\n\n\nnamespace nat\n\nlemma mem_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) {p : \u2115} :\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u2228 p \u2208 b.factors :=\nbegin\n  rw [mem_factors (mul_ne_zero ha hb), mem_factors ha, mem_factors hb, \u2190and_or_distrib_left],\n  simpa only [and.congr_right_iff] using prime.dvd_mul\nend\n\n/-- If `a`, `b` are positive, the prime divisors of `a * b` are the union of those of `a` and `b` -/\nlemma factors_mul_to_finset {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a * b).factors.to_finset = a.factors.to_finset \u222a b.factors.to_finset :=\n(list.to_finset.ext $ \u03bb x, (mem_factors_mul ha hb).trans list.mem_union.symm).trans $\n  list.to_finset_union _ _\n\nlemma pow_succ_factors_to_finset (n k : \u2115) :\n  (n^(k+1)).factors.to_finset = n.factors.to_finset :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  induction k with k ih,\n  { simp },\n  rw [pow_succ, factors_mul_to_finset hn (pow_ne_zero _ hn), ih, finset.union_idempotent]\nend\n\nlemma pow_factors_to_finset (n : \u2115) {k : \u2115} (hk : k \u2260 0) :\n  (n^k).factors.to_finset = n.factors.to_finset :=\nbegin\n  cases k,\n  { simpa using hk },\n  rw pow_succ_factors_to_finset\nend\n\n/-- The only prime divisor of positive prime power `p^k` is `p` itself -/\nlemma prime_pow_prime_divisor {p k : \u2115} (hk : k \u2260 0) (hp : prime p) :\n  (p^k).factors.to_finset = {p} :=\nby simp [pow_factors_to_finset p hk, factors_prime hp]\n\n/-- The sets of factors of coprime `a` and `b` are disjoint -/\nlemma coprime_factors_disjoint {a b : \u2115} (hab : a.coprime b) : list.disjoint a.factors b.factors :=\nbegin\n  intros q hqa hqb,\n  apply not_prime_one,\n  rw \u2190(eq_one_of_dvd_coprimes hab (dvd_of_mem_factors hqa) (dvd_of_mem_factors hqb)),\n  exact prime_of_mem_factors hqa\nend\n\nlemma mem_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) (p : \u2115):\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u222a b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  rw [mem_factors_mul ha.ne' hb.ne', list.mem_union]\nend\n\nlemma factors_mul_to_finset_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factors.to_finset = a.factors.to_finset \u222a b.factors.to_finset :=\n(list.to_finset.ext $ mem_factors_mul_of_coprime hab).trans $ list.to_finset_union _ _\n\nopen list\n\n/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/\nlemma mem_factors_mul_left {p a b : \u2115} (hpa : p \u2208 a.factors) (hb : b \u2260 0) : p \u2208 (a*b).factors :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simpa using hpa },\n  apply (mem_factors_mul ha hb).2 (or.inl hpa),\nend\n\n/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/\nlemma mem_factors_mul_right {p a b : \u2115} (hpb : p \u2208 b.factors) (ha : a \u2260 0) : p \u2208 (a*b).factors :=\nby { rw mul_comm, exact mem_factors_mul_left hpb ha }\n\nlemma eq_two_pow_or_exists_odd_prime_and_dvd (n : \u2115) :\n  (\u2203 k : \u2115, n = 2 ^ k) \u2228 \u2203 p, nat.prime p \u2227 p \u2223 n \u2227 odd p :=\n(eq_or_ne n 0).elim\n  (\u03bb hn, (or.inr \u27e83, prime_three, hn.symm \u25b8 dvd_zero 3, \u27e81, rfl\u27e9\u27e9))\n  (\u03bb hn, or_iff_not_imp_right.mpr\n    (\u03bb H, \u27e8n.factors.length, eq_prime_pow_of_unique_prime_dvd hn\n      (\u03bb p hprime hdvd, hprime.eq_two_or_odd'.resolve_right\n        (\u03bb hodd, H \u27e8p, hprime, hdvd, hodd\u27e9))\u27e9))\n\nend nat\n\nnamespace int\nlemma prime_two : prime (2 : \u2124) := nat.prime_iff_prime_int.mp nat.prime_two\nlemma prime_three : prime (3 : \u2124) := nat.prime_iff_prime_int.mp nat.prime_three\nend int\n\nsection\nopen finset\n/-- Exactly `n / p` naturals in `[1, n]` are multiples of `p`. -/\nlemma card_multiples (n p : \u2115) : card ((range n).filter (\u03bb e, p \u2223 e + 1)) = n / p :=\nbegin\n  induction n with n hn,\n  { rw [nat.zero_div, range_zero, filter_empty, card_empty] },\n  { rw [nat.succ_div, add_ite, add_zero, range_succ, filter_insert, apply_ite card,\n      card_insert_of_not_mem (mem_filter.not.mpr (not_and_of_not_left _ not_mem_range_self)), hn] }\nend\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/nat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7243940951966412}}
{"text": "/-\nCopyright (c) 2022 Ivan Sadofschi Costa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ivan Sadofschi Costa\n-/\nimport topology.order\nimport topology.sets.opens\nimport topology.continuous_function.basic\n\n/-!\n# Any T0 space embeds in a product of copies of the Sierpinski space.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe consider `Prop` with the Sierpinski topology. If `X` is a topological space, there is a\ncontinuous map `product_of_mem_opens` from `X` to `opens X \u2192 Prop` which is the product of the maps\n`X \u2192 Prop` given by `x \u21a6 x \u2208 u`.\n\nThe map `product_of_mem_opens` is always inducing. Whenever `X` is T0, `product_of_mem_opens` is\nalso injective and therefore an embedding.\n-/\n\nnoncomputable theory\n\nnamespace topological_space\n\nlemma eq_induced_by_maps_to_sierpinski (X : Type*) [t : topological_space X] :\n  t = \u2a05 (u : opens X), sierpinski_space.induced (\u2208 u) :=\nbegin\n  apply le_antisymm,\n  { rw [le_infi_iff],\n    exact \u03bb u, continuous.le_induced (is_open_iff_continuous_mem.mp u.2) },\n  { intros u h,\n    rw \u2190 generate_from_Union_is_open,\n    apply is_open_generate_from_of_mem,\n    simp only [set.mem_Union, set.mem_set_of_eq, is_open_induced_iff],\n    exact \u27e8\u27e8u, h\u27e9, {true}, is_open_singleton_true, by simp [set.preimage]\u27e9 },\nend\n\nvariables (X : Type*) [topological_space X]\n\n/--\nThe continuous map from `X` to the product of copies of the Sierpinski space, (one copy for each\nopen subset `u` of `X`). The `u` coordinate of `product_of_mem_opens x` is given by `x \u2208 u`.\n-/\ndef product_of_mem_opens : C(X, opens X \u2192 Prop) :=\n{ to_fun := \u03bb x u, x \u2208 u,\n  continuous_to_fun := continuous_pi_iff.2 (\u03bb u, continuous_Prop.2 u.is_open) }\n\nlemma product_of_mem_opens_inducing : inducing (product_of_mem_opens X) :=\nbegin\n  convert inducing_infi_to_pi (\u03bb (u : opens X) (x : X), x \u2208 u),\n  apply eq_induced_by_maps_to_sierpinski,\nend\n\nlemma product_of_mem_opens_injective [t0_space X] : function.injective (product_of_mem_opens X) :=\nbegin\n  intros x1 x2 h,\n  apply inseparable.eq,\n  rw [\u2190inducing.inseparable_iff (product_of_mem_opens_inducing X), h],\n end\n\ntheorem product_of_mem_opens_embedding [t0_space X] : embedding (product_of_mem_opens X) :=\nembedding.mk (product_of_mem_opens_inducing X) (product_of_mem_opens_injective X)\n\nend topological_space\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/continuous_function/t0_sierpinski.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7243940876797681}}
{"text": "import tactic\n \n\nnoncomputable theory\nopen_locale classical\nuniverse u\n\n/-?\n\n# The Maths\n\nA groupoid (G, *) is a gyrogroup if its binary operation satisfies the following axioms:\n\n* In G there is at least one element e called a left identity with e * a = a for all a \u2208 G.\n* For each a \u2208 G there is an element a\u207b\u00b9 in G called a left inverse of a with a\u207b\u00b9 * a = e.\n* For any a, b, c in G there exists a unique element gyr[a, b]c in G such that the binary operation obeys the left gyroassociative law: a{\\displaystyle \\oplus }\\oplus (b{\\displaystyle \\oplus }\\oplus c) = (a{\\displaystyle \\oplus }\\oplus b){\\displaystyle \\oplus }\\oplus gyr[a, b]c\nThe map gyr[a, b]:G \u2192 G given by c \u2192 gyr[a, b]c is an automorphism of the groupoid (G, {\\displaystyle \\oplus }\\oplus ). That is gyr[a, b] is a member of Aut(G, {\\displaystyle \\oplus }\\oplus ) and the automorphism gyr[a, b] of G is called the gyroautomorphism of G generated by a, b in G. The operation gyr:G \u00d7 G \u2192 Aut(G, {\\displaystyle \\oplus }\\oplus ) is called the gyrator of G.\nThe gyroautomorphism gyr[a, b] has the left loop property gyr[a, b] = gyr[a{\\displaystyle \\oplus }\\oplus b, b]\nThe first pair of axioms are like the group axioms. The last pair present the gyrator axioms and the middle axiom links the two pairs.\n\nSince a gyrogroup has inverses and an identity it qualifies as a quasigroup and a loop.\n\nGyrogroups are a generalization of groups. Every group is an example of a gyrogroup with gyr defined as the identity map.\n-/\n\n\n/-?\nMagma, which may be called a groupoid by different people.\n\nA group is a magma (G, +) whose binary operation satisfies the following axioms.\n* In G there is at least one element, 0, called a left identity, satisfying \n                                  *(G1) 0+a=a for all a \u2208 G*. \n* There is an element 0 \u2208 G satisfying axion (G1) such that for each a \u2208 G there is \nan element \u2212a \u2208 G, called a left inverse of a, satisfying\n                                  *(G2) \u2212a + a = 0*\n* Moreover, the binary operation obeys the associative law\n                                 *(G3) (a + b) + c = a + (b + c) for all a, b, c \u2208 G*.\n\n-/\nclass magma_not (S : Type) extends has_add S, has_neg S, has_zero S :=\n-- axiom 1: \u2200 a \u2203 0, 0 + a = a\n(zero_add: \u2200 (a : S), 0 + a = a)\n-- axiom 2: \u2200 a \u2203 -a, -a + a = 0\n(add_left_neg: \u2200 (a : S), -a + a = 0)\n-- axiom 3: \u2200 a b c, (a + b) + c = a + (b + c)\n(add_magma_assoc: \u2200 (a b c : S), (a + b) + c = a + (b + c)) \n\n/-?\nA loop is a magma (S, +) with an identity element in\nwhich each of the two equations a + x = b and y + a = b for the unknowns x\nand y possesses a unique solution.\n-/\n\nclass loop (S : Type) extends has_add S, has_neg S, has_zero S :=\n-- axiom 1: \u2200 a \u2203 0, 0 + a = a\n(zero_add: \u2200 (a : S), 0 + a = a)\n-- axiom 2: \u2200 a \u2203 -a, -a + a = 0\n(add_left_neg: \u2200 (a : S), -a + a = 0)\n(add_right_neg: \u2200 (a : S), a + -a = 0)\n-- axiom 3: \u2200 a b c, (a + b) + c = a + (b + c)\n(add_magma_assoc: \u2200 (a b c : S), (a + b) + c = a + (b + c)) \n\n\nclass has_gyrop        (\u03b1 : Type u) := (gyrop : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_subgyrop     (\u03b1 : Type u) := (subgyrop : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_neggyrop     (\u03b1 : Type u) := (neggyrop : \u03b1 \u2192 \u03b1)\nclass has_cogyrop      (\u03b1 : Type u) := (cogyrop : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_subcogyrop      (\u03b1 : Type u) := (subcogyrop : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_negcogyrop      (\u03b1 : Type u) := (negcogyrop : \u03b1 \u2192 \u03b1)\n\n#print notation -\n\ninfix ` \u2299 `:75 := has_gyrop.gyrop\ninfix ` \u229d `:65 := has_subgyrop.subgyrop\nprefix ` \u229d `:75 := has_neggyrop.neggyrop\ninfix ` \u229e `:80 := has_cogyrop.cogyrop\ninfix ` \u229f `:80 := has_subcogyrop.subcogyrop -- what a long name\nprefix ` \u229f `:85 := has_negcogyrop.negcogyrop\n\n#print notation \u229d\n\n--#check a \u229d b\n\n\n\n", "meta": {"author": "jamesa9283", "repo": "gyrovectors-lean", "sha": "0c2e972c34045c2810b6a5832f5aeee738fb185e", "save_path": "github-repos/lean/jamesa9283-gyrovectors-lean", "path": "github-repos/lean/jamesa9283-gyrovectors-lean/gyrovectors-lean-0c2e972c34045c2810b6a5832f5aeee738fb185e/src/basic/conventional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7243611275257686}}
{"text": "/-\nCopyright (c) 2021 Gabriel Moise. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Gabriel Moise.\n-/\n\nimport algebra.big_operators.basic\nimport combinatorics.simple_graph.basic\nimport data.fintype.basic\nimport data.sym2\nimport linear_algebra.matrix\n\n/-!\n# Incidence matrices\n\nThis module defines the incidence matrix `inc_matrix` of an undirected graph `simple_graph`, and provides\ntheorems and lemmas connecting graph properties to computational properties of the matrix. It also\ndefines the notion of `orientation` for a `simple_graph`, picking a direction for each undirected\nedge in the graph.\n\n## Main definitions\n\n* `inc_matrix` is the incidence matrix `M` of a `simple_graph` with coefficients in a given ring R.\n* `orientation` is a structure that defines a choice of direction on the edges of a `simple_graph`.\n* `dir_inc_matrix` is the directed incidence matrix `N(o)` of a `simple_graph` with\nrespect to a given `orientation`.\n\n## Main statements\n\n1. \u2211 e : E, M i e * M j e = 1, for any two adjacent vertices i and j.\n2. M i e * M j e = 0, for any two distinct non-adjacent vertices i, j and edge e.\n3. Every element from M is idempotent.\n4. For any vertex i, the sum on the ith row of M is equal to the degree of i.\n5. (N(o) i e) ^ 2 = M i e, for any orientation o, vertex i and edge e.\n6. For any adjacent vertices i j and edge e, N(o) i e * N(o) j e = if e = (i,j) then -1 else 0.\n7. For any non-adjacent distinct vertices i j and edge e, N(o) i e * N(o) j e = 0.\n8. (x\u1d40 \u2b1d N) e = x head(e) - x tail(e).\n-/\n\nopen_locale big_operators matrix\nopen finset matrix simple_graph sym2\n\nuniverse u\nvariables {R : Type u} [ring R] [nontrivial R] [decidable_eq R]\n\n@[simp]\nlemma ite_prod_one_zero {P Q : Prop} [decidable P] [decidable Q] :\n  (ite P 1 0) * (ite Q 1 0) = ite (P \u2227 Q) (1 : R) 0 :=\nby { by_cases h : P; simp [h] }\n\nlemma fintype.card_coe_filter {\u03b1 : Sort*} {s t : set \u03b1} [fintype s] [fintype t]\n  [decidable_pred (\u03bb (x : t), (x : \u03b1) \u2208 s)] (h : s \u2286 t) :\n  fintype.card s = finset.card (finset.filter (\u03bb (x : t), (x : \u03b1) \u2208 s) finset.univ) :=\nbegin\n  refine finset.card_congr _ _ _ _,\n  { rintros \u27e8e, he\u27e9 he',\n    exact \u27e8e, h he\u27e9 },\n  { rintros \u27e8e, he\u27e9 he',\n    simpa only [true_and, finset.mem_univ, finset.mem_filter] using he},\n  { rintros \u27e8e1, he1\u27e9 \u27e8e2, he2\u27e9 he1' he2' hr,\n    ext,\n    simp only [subtype.mk_eq_mk] at hr,\n    simp only [hr] },\n  { rintros \u27e8e, he\u27e9 he',\n    use [e],\n    { simpa only [true_and, finset.mem_univ, finset.mem_filter] using he'},\n    { simp only [finset.mem_univ, exists_prop_of_true] } }\nend\n\nnamespace simple_graph\n\nuniverse v\nvariables {V : Type v} [fintype V] (G : simple_graph V) (R) [decidable_rel G.adj] [decidable_eq V]\n\n-- ## Incidence matrix M\n\n/-- `inc_matrix G R` is the matrix `M` such that `M i e = 1` if vertex `i` is an\nendpoint of the edge `e` in the simple graph `G`, otherwise `M i j = 0`. -/\ndef inc_matrix : matrix V G.edge_set R\n| i e := if (e : sym2 V) \u2208 G.incidence_set i then 1 else 0\n\n@[simp]\nlemma inc_matrix_apply {i : V} {e : G.edge_set} :\n  G.inc_matrix R i e = if (e : sym2 V) \u2208 G.incidence_set i then 1 else 0 := rfl\n\nlemma inc_matrix_def : G.inc_matrix R = \u03bb i e, ite ((e : sym2 V) \u2208 G.incidence_set i) 1 0 :=\nby { ext, simp only [inc_matrix_apply] }\n\n-- ## Relation between inc_matrix elements and incidence_set property\n\n@[simp]\nlemma inc_matrix_zero {i : V} {e : G.edge_set} : G.inc_matrix R i e = 0 \u2194 e.val \u2209 G.incidence_set i :=\nby simp only [inc_matrix, ite_eq_right_iff, subtype.val_eq_coe, \u2190 decidable.not_imp_not,\n              forall_true_left, not_false_iff, one_ne_zero]\n\n@[simp]\nlemma inc_matrix_one {i : V} {e : G.edge_set} : G.inc_matrix R i e = 1 \u2194 e.val \u2208 G.incidence_set i :=\nby simp only [inc_matrix, ite_eq_left_iff, subtype.val_eq_coe, \u2190 decidable.not_imp_not,\n              set.not_not_mem, forall_true_left, not_false_iff, zero_ne_one]\n\n-- ## One - zero properties\n\n@[simp]\nlemma inc_matrix_not_zero {i : V} {e : G.edge_set} : \u00ac G.inc_matrix R i e = 0 \u2194 G.inc_matrix R i e = 1 :=\nby simp only [inc_matrix_zero, inc_matrix_one, set.not_not_mem]\n\n@[simp]\nlemma inc_matrix_not_one {i : V} {e : G.edge_set} : \u00ac G.inc_matrix R i e = 1 \u2194 G.inc_matrix R i e = 0 :=\nby simp only [inc_matrix_zero, inc_matrix_one]\n\nlemma inc_matrix_zero_or_one {i : V} {e : G.edge_set} :\n  G.inc_matrix R i e = 0 \u2228 G.inc_matrix R i e = 1 :=\nby { rw [inc_matrix_zero, inc_matrix_one], exact (em (e.val \u2208 G.incidence_set i)).symm }\n\n@[simp]\nlemma inc_matrix_elements_product_one {i j : V} {e : G.edge_set} :\n  G.inc_matrix R i e * G.inc_matrix R j e = 1 \u2194 G.inc_matrix R i e = 1 \u2227 G.inc_matrix R j e = 1 :=\nbegin\n  cases G.inc_matrix_zero_or_one R with H\u2080 H\u2081,\n  { rw H\u2080, simp only [if_t_t, mul_boole, inc_matrix_apply, zero_ne_one, false_and] },\n  { rw H\u2081, simp only [true_and, mul_boole, inc_matrix_apply, eq_self_iff_true] }\nend\n\n-- ## Helping lemmas for edges\n\n@[simp]\nlemma edge_val_equiv {e\u2081 e\u2082 : G.edge_set} : e\u2081.val = e\u2082.val \u2194 e\u2081 = e\u2082 :=\nbegin\n  split,\n  { exact subtype.eq },\n  { intro hyp,\n    rw hyp }\nend\n\nlemma edge_val_in_set {e : G.edge_set} : e.val \u2208 G.edge_set :=\nby simp only [subtype.coe_prop, subtype.val_eq_coe]\n\nlemma edge_set_ne {u v : V} {e: G.edge_set} (h : e.val = \u27e6(u, v)\u27e7) : u \u2260 v :=\nbegin\n  apply G.ne_of_adj,\n  simp only [\u2190 G.mem_edge_set, \u2190 h, edge_val_in_set],\nend\n\nlemma incidence_equiv {i : V} {e : G.edge_set} : e.val \u2208 G.incidence_set i \u2194 i \u2208 e.val :=\nby simp only [incidence_set, true_and, set.mem_sep_eq, edge_val_in_set]\n\nlemma incidence_set_iff_any_vertex {i u v : V} (h : \u27e6(u, v)\u27e7 \u2208 G.edge_set) :\n  \u27e6(u, v)\u27e7 \u2208 G.incidence_set i \u2194 i = u \u2228 i = v :=\nby simp only [\u2190 mem_iff, h, incidence_set, true_and, set.mem_sep_eq]\n\nlemma edge_in_two_incidence_sets {i j : V} {e : sym2 V} (H_ne : i \u2260 j) :\n  e \u2208 G.incidence_set i \u2227 e \u2208 G.incidence_set j \u2192 e = \u27e6(i, j)\u27e7 :=\nbegin\n  refine quotient.rec_on_subsingleton e (\u03bb p, _),\n  rcases p with \u27e8v, w\u27e9,\n  rw eq_iff,\n  rintros \u27e8\u27e8_, H_i\u27e9, \u27e8_, H_j\u27e9\u27e9,\n  cases (mem_iff.mp H_i) with H_i\u2081 H_i\u2082;\n  cases (mem_iff.mp H_j) with H_j\u2081 H_j\u2082,\n  { exfalso, apply H_ne, rw [H_i\u2081, H_j\u2081] }, -- i = v, j = v\n  { left, use [H_i\u2081.symm, H_j\u2082.symm] },     -- i = v, j = w\n  { right, use [H_j\u2081.symm, H_i\u2082.symm] },    -- i = w, j = v\n  { exfalso, apply H_ne, rw [H_i\u2082, H_j\u2082] }  -- i = w, j = w\nend\n\nlemma mem_incidence_sets_iff_eq_of_adj {i j : V} {e : sym2 V} (h : G.adj i j) :\n  e \u2208 G.incidence_set i \u2227 e \u2208 G.incidence_set j \u2194 e = \u27e6(i, j)\u27e7 :=\nbegin\n  refine quotient.rec_on_subsingleton e (\u03bb p, _),\n  rcases p with \u27e8v, w\u27e9,\n  rw eq_iff,\n  simp only [incidence_set],\n  tidy,\nend\n\nlemma adj_iff_exists_edge_val {i j : V} : G.adj i j \u2194 \u2203 (e : G.edge_set), e.val = \u27e6(i, j)\u27e7 :=\nby simp only [mem_edge_set, exists_prop, set_coe.exists, exists_eq_right, subtype.coe_mk]\n\n-- 1. \u2211 e : E, M i e * M j e = 1, where i and j are adjacent.\nlemma adj_sum_of_prod_inc_one {i j : V} (H_adj : G.adj i j) :\n  \u2211 (e : G.edge_set), G.inc_matrix R i e * G.inc_matrix R j e = (1 : R) :=\nbegin\n  simp only [inc_matrix_apply, ite_prod_one_zero, G.mem_incidence_sets_iff_eq_of_adj H_adj,\n             sum_boole, \u2190 subtype.val_eq_coe],\n  rw adj_iff_exists_edge_val at H_adj,\n  rcases H_adj with \u27e8e, H_e\u27e9,\n  simp only [\u2190 H_e, edge_val_equiv],\n  have H : filter (\u03bb (x : G.edge_set), x = e) univ = {e},\n  { ext, simp only [true_and, mem_filter, mem_univ, mem_singleton] },\n  simp only [H, filter_congr_decidable, nat.cast_one, card_singleton]\nend\n\n-- 2. M i e * M j e = 0, where i, j distinct non-adjacent vertices, e an edge.\nlemma inc_matrix_prod_non_adj {i j : V} {e : G.edge_set} (Hne : i \u2260 j) (H_non_adj : \u00ac G.adj i j) :\n  G.inc_matrix R i e * G.inc_matrix R j e = 0 :=\nbegin\n  by_cases H\u2081 : G.inc_matrix R i e = 0,\n  { rw [H\u2081, zero_mul] },\n  { rw [inc_matrix_not_zero, inc_matrix_one] at H\u2081,\n    by_cases H\u2082 : G.inc_matrix R j e = 0,\n    { rw [H\u2082, mul_zero] },\n    { rw [inc_matrix_not_zero, inc_matrix_one] at H\u2082,\n      exfalso,\n      apply H_non_adj,\n      rw [\u2190 mem_edge_set, \u2190 G.edge_in_two_incidence_sets Hne \u27e8H\u2081, H\u2082\u27e9],\n      exact G.edge_val_in_set } }\nend\n\n-- 3. (M i e) ^ 2 = M i e; with i a vertex, e an edge.\n@[simp]\nlemma inc_matrix_element_power_id {i : V} {e : G.edge_set} :\n  (G.inc_matrix R i e) * (G.inc_matrix R i e) = G.inc_matrix R i e :=\nby simp [inc_matrix_apply]\n\n-- 4. degree(i) = \u2211 e : E, M i e; where i is a vertex.\nlemma degree_equals_sum_of_incidence_row {i : V} : (G.degree i : R) = \u2211 (e : G.edge_set), G.inc_matrix R i e :=\nbegin\n  rw [inc_matrix_def, \u2190card_incidence_set_eq_degree],\n  simp only [sum_boole, nat.cast_inj, fintype.card_coe_filter (G.incidence_set_subset i)],\nend\n\n-- ## Orientations\n\n/-- Define an `orientation` on the undirected graph G as a structure that defines (consistently)\nfor each edge a `head` and a `tail`. -/\n@[ext]\nstructure orientation (G : simple_graph V) :=\n(head : G.edge_set \u2192 V)\n(tail : G.edge_set \u2192 V)\n(consistent : \u2200 e : G.edge_set, e.val = \u27e6(head(e),tail(e))\u27e7)\n\n-- ## Directed Incidence Matrix N(o)\n\n/-- A `directed incidence matrix` N(o) is defined with respect to the orientation of the edges and is defined to be\n`1` for entries (`i`,`e`) where `i` is the head of `e`, `-1` where `i` is the tail of `e`, and `0` otherwise. -/\ndef dir_inc_matrix (o : orientation G) : matrix V G.edge_set R :=\n\u03bb i e, if i = o.head e then 1 else (if i = o.tail e then (-1 : R) else 0)\n\nvariables {o : orientation G}\n\n@[simp]\nlemma dir_inc_matrix_apply {i : V} {e : G.edge_set} :\n  G.dir_inc_matrix R o i e = if i = o.head e then 1 else (if i = o.tail e then (-1 : R) else 0) := rfl\n\nlemma head_neq_tail {e : G.edge_set} : o.head(e) \u2260 o.tail(e) :=\nby exact G.edge_set_ne (o.consistent e)\n\n@[simp]\nlemma dir_inc_matrix_head {i : V} {e : G.edge_set} (H_head : i = o.head e) :\n  G.dir_inc_matrix R o i e = 1 :=\nby simp only [H_head, if_true, eq_self_iff_true, dir_inc_matrix_apply]\n\n@[simp]\nlemma dir_inc_matrix_tail {i : V} {e : G.edge_set} (H_tail : i = o.tail e) :\n  G.dir_inc_matrix R o i e = -1 :=\nby simp only [H_tail, dir_inc_matrix, (G.head_neq_tail).symm, if_false, if_true, eq_self_iff_true]\n\n@[simp]\nlemma dir_inc_matrix_zero {i : V} {e : G.edge_set} :\n  G.dir_inc_matrix R o i e = 0 \u2194 i \u2260 o.head e \u2227 i \u2260 o.tail e :=\nbegin\n  by_cases H\u2081 : i = o.head e,\n  { simp only [dir_inc_matrix, H\u2081, if_true, eq_self_iff_true, not_true,\n               ne.def, one_ne_zero, false_and] },\n  { by_cases H\u2082 : i = o.tail e,\n    { simp only [H\u2082, dir_inc_matrix_tail, eq_self_iff_true, not_true,\n                 ne.def, neg_eq_zero, one_ne_zero, and_false] },\n    { simp only [H\u2081, H\u2082, eq_self_iff_true, if_false, ne.def,\n                 not_false_iff, and_self, dir_inc_matrix_apply] } }\nend\n\n@[simp]\nlemma dir_inc_matrix_non_zero {i : V} {e : G.edge_set} :\n  \u00ac G.dir_inc_matrix R o i e = 0 \u2194 i = o.head e \u2228 i = o.tail e :=\nbegin\n  by_cases H\u2081 : i = o.head e,\n  { simp only [H\u2081, if_true, true_or, eq_self_iff_true, ne.def,\n               not_false_iff, one_ne_zero, dir_inc_matrix_apply] },\n  { by_cases H\u2082 : i = o.tail e,\n    { simp only [H\u2082, dir_inc_matrix_tail, eq_self_iff_true, ne.def, or_true,\n                 not_false_iff, neg_eq_zero, one_ne_zero] },\n    { simp only [H\u2081, H\u2082, eq_self_iff_true, not_true, if_false,\n                 ne.def, dir_inc_matrix_apply, or_self] } }\nend\n\nlemma incidence_set_orientation_head {e : G.edge_set} : e.val \u2208 G.incidence_set (o.head e) :=\nby { rw [incidence_equiv, o.consistent e], simp only [mem_iff, true_or, eq_self_iff_true] }\n\nlemma incidence_set_orientation_tail {e : G.edge_set} : e.val \u2208 G.incidence_set (o.tail e) :=\nby { rw [incidence_equiv, o.consistent e], simp only [mem_iff, eq_self_iff_true, or_true] }\n\nlemma incidence_set_orientation {i : V} {e : G.edge_set} :\n  e.val \u2208 G.incidence_set i \u2194 i = o.head e \u2228 i = o.tail e :=\nbegin\n  rw o.consistent e,\n  have key : \u27e6(o.head e, o.tail e)\u27e7 \u2208 G.edge_set, {rw \u2190 o.consistent e, exact G.edge_val_in_set},\n  exact G.incidence_set_iff_any_vertex key,\nend\n\nlemma not_incidence_set_orientation {i : V} {e : G.edge_set}\n  (H_head : i \u2260 o.head e) (H_tail : i \u2260 o.tail e) : e.val \u2209 G.incidence_set i :=\nbegin\n  intro h,\n  rw G.incidence_set_orientation at h,\n  tauto,\nend\n\n-- 5. (N(o) i e) ^ 2 = M i e, for any orientation o, vertex i and edge e.\n@[simp]\nlemma dir_inc_matrix_elem_squared {i : V} {e : G.edge_set} :\n  G.dir_inc_matrix R o i e * G.dir_inc_matrix R o i e = G.inc_matrix R i e :=\nbegin\n  by_cases H_head : i = o.head e,\n  { rw [G.dir_inc_matrix_head R H_head, H_head, mul_one, eq_comm, inc_matrix_one],\n    exact G.incidence_set_orientation_head },\n  { by_cases H_tail : i = o.tail e,\n    { rw [G.dir_inc_matrix_tail R H_tail, H_tail, mul_neg_eq_neg_mul_symm, mul_one,\n          neg_neg, eq_comm, inc_matrix_one],\n      exact G.incidence_set_orientation_tail },\n    { rw [(G.dir_inc_matrix_zero R).mpr \u27e8H_head, H_tail\u27e9, mul_zero, eq_comm, inc_matrix_zero],\n      exact G.not_incidence_set_orientation H_head H_tail } }\nend\n\n-- 6. For any adjacent vertices i j and edge e, N(o) i e * N(o) j e = if e = (i,j) then -1 else 0.\nlemma dir_inc_matrix_prod_of_adj {i j : V} {e : G.edge_set} (H_adj : G.adj i j) :\n  G.dir_inc_matrix R o i e * G.dir_inc_matrix R o j e = ite (e.val = \u27e6(i, j)\u27e7) (-1) 0 :=\nbegin\n  by_cases H_e : e.val = \u27e6(i, j)\u27e7,\n  { rw [H_e, if_pos rfl],\n    rw [o.consistent e, eq_iff] at H_e,\n    rcases H_e with (\u27e8H_head_i, H_tail_j\u27e9 | \u27e8H_head_j, H_tail_i\u27e9),\n    { rw [G.dir_inc_matrix_head R H_head_i.symm, G.dir_inc_matrix_tail R H_tail_j.symm,\n          mul_neg_eq_neg_mul_symm, mul_one] },\n    { rw [G.dir_inc_matrix_head R H_head_j.symm, G.dir_inc_matrix_tail R H_tail_i.symm, mul_one] } },\n  { simp only [H_e, if_false],\n    rw [o.consistent e, eq_iff, decidable.not_or_iff_and_not] at H_e,\n    repeat { rw decidable.not_and_iff_or_not at H_e },\n    rcases H_e with \u27e8(H_head_i | H_tail_j), (H_head_j | H_tail_i)\u27e9,\n    { have H_tail : o.tail e \u2260 i \u2228 o.tail e \u2260 j,\n      { by_contradiction h,\n        rw [decidable.not_or_iff_and_not, not_not, not_not] at h,\n        rcases h with \u27e8h_i, h_j\u27e9, rw h_i at h_j,\n        exact G.ne_of_adj H_adj h_j },\n      cases H_tail with H_tail_i H_tail_j,\n      { rw [(G.dir_inc_matrix_zero R).mpr \u27e8ne.symm H_head_i, ne.symm H_tail_i\u27e9, zero_mul] },\n      { rw [(G.dir_inc_matrix_zero R).mpr \u27e8ne.symm H_head_j, ne.symm H_tail_j\u27e9, mul_zero] } },\n    { rw [(G.dir_inc_matrix_zero R).mpr \u27e8ne.symm H_head_i, ne.symm H_tail_i\u27e9, zero_mul] },\n    { rw [(G.dir_inc_matrix_zero R).mpr \u27e8ne.symm H_head_j, ne.symm H_tail_j\u27e9, mul_zero] },\n    { have H_head : o.head e \u2260 i \u2228 o.head e \u2260 j,\n      { by_contradiction h,\n        rw [decidable.not_or_iff_and_not, not_not, not_not] at h,\n        rcases h with \u27e8h_i, h_j\u27e9, rw h_i at h_j,\n        exact G.ne_of_adj H_adj h_j },\n      cases H_head with H_head_i H_head_j,\n      { rw [(G.dir_inc_matrix_zero R).mpr \u27e8ne.symm H_head_i, ne.symm H_tail_i\u27e9, zero_mul] },\n      { rw [(G.dir_inc_matrix_zero R).mpr \u27e8ne.symm H_head_j, ne.symm H_tail_j\u27e9, mul_zero] } } }\nend\n\n-- 7. For any non-adjacent distinct vertices i j and edge e, N(o) i e * N(o) j e = 0.\nlemma dir_inc_matrix_prod_non_adj {i j : V} {e : G.edge_set} (H_ij : i \u2260 j) (H_not_adj : \u00ac G.adj i j) :\n  G.dir_inc_matrix R o i e * G.dir_inc_matrix R o j e = 0 :=\nbegin\n  by_cases H\u2081 : G.dir_inc_matrix R o i e = 0,\n  { rw [H\u2081, zero_mul] },\n  { by_cases H\u2082 : G.dir_inc_matrix R o j e = 0,\n    { rw [H\u2082, mul_zero] },\n    {\n      rcases ((G.dir_inc_matrix_non_zero R).mp H\u2081) with (H_head_i | H_tail_i) ;\n      rcases ((G.dir_inc_matrix_non_zero R).mp H\u2082) with (H_head_j | H_tail_j),\n      { rw [H_head_i, H_head_j] at H_ij, tauto },\n      { exfalso, apply H_not_adj, rw [H_head_i, H_tail_j, \u2190 mem_edge_set, \u2190 o.consistent e],\n        simp only [subtype.coe_prop, subtype.val_eq_coe] },\n      { exfalso, apply H_not_adj, rw [edge_symm, H_tail_i, H_head_j, \u2190 mem_edge_set, \u2190 o.consistent e],\n        simp only [subtype.coe_prop, subtype.val_eq_coe] },\n      { rw [H_tail_i, H_tail_j] at H_ij, tauto } } }\nend\n\n-- 8. (x\u1d40 \u2b1d N) e = x head(e) - x tail(e).\nlemma vec_mul_dir_inc_matrix {o : orientation G} (x : V \u2192 R) (e : G.edge_set) :\n  vec_mul x (G.dir_inc_matrix R o) e = x (o.head e) - x (o.tail e) :=\nbegin\n  simp only [vec_mul, dot_product, dir_inc_matrix, mul_ite, mul_one, mul_neg_eq_neg_mul_symm, mul_zero],\n  rw [sum_ite, sum_ite, sum_filter, sum_ite_eq', sum_const_zero, add_zero, filter_filter],\n  simp only [mem_univ, if_true],\n  have key : filter (\u03bb (a : V), \u00aca = o.head e \u2227 a = o.tail e) univ = {o.tail e},\n  { ext,\n    simp only [mem_filter, mem_singleton, true_and, and_iff_right_iff_imp, mem_univ],\n    intro hyp,\n    rw hyp,\n    exact ne.symm (G.head_neq_tail) },\n  rw [key, sum_singleton],\n  ring_nf\nend\n\nend simple_graph\n", "meta": {"author": "gabrielmoise", "repo": "Lean-work", "sha": "52b2a2c840f8477e293cbb897335a19ebf482cf7", "save_path": "github-repos/lean/gabrielmoise-Lean-work", "path": "github-repos/lean/gabrielmoise-Lean-work/Lean-work-52b2a2c840f8477e293cbb897335a19ebf482cf7/incidence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7243464520779195}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Eric Wieser\n-/\nimport algebra.order.module\nimport data.real.basic\n\n/-!\n# Pointwise operations on sets of reals\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file relates `Inf (a \u2022 s)`/`Sup (a \u2022 s)` with `a \u2022 Inf s`/`a \u2022 Sup s` for `s : set \u211d`.\n\nFrom these, it relates `\u2a05 i, a \u2022 f i` / `\u2a06 i, a \u2022 f i` with `a \u2022 (\u2a05 i, f i)` / `a \u2022 (\u2a06 i, f i)`,\nand provides lemmas about distributing `*` over `\u2a05` and `\u2a06`.\n\n# TODO\n\nThis is true more generally for conditionally complete linear order whose default value is `0`. We\ndon't have those yet.\n-/\n\nopen set\nopen_locale pointwise\n\nvariables {\u03b9 : Sort*} {\u03b1 : Type*} [linear_ordered_field \u03b1]\n\nsection mul_action_with_zero\nvariables [mul_action_with_zero \u03b1 \u211d] [ordered_smul \u03b1 \u211d] {a : \u03b1}\n\nlemma real.Inf_smul_of_nonneg (ha : 0 \u2264 a) (s : set \u211d) : Inf (a \u2022 s) = a \u2022 Inf s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Inf_empty, smul_zero] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cInf_singleton 0 },\n  by_cases bdd_below s,\n  { exact ((order_iso.smul_left \u211d ha').map_cInf' hs h).symm },\n  { rw [real.Inf_of_not_bdd_below (mt (bdd_below_smul_iff_of_pos ha').1 h),\n      real.Inf_of_not_bdd_below h, smul_zero] }\nend\n\nlemma real.smul_infi_of_nonneg (ha : 0 \u2264 a) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a05 i, f i) = \u2a05 i, a \u2022 f i :=\n(real.Inf_smul_of_nonneg ha _).symm.trans $ congr_arg Inf $ (range_comp _ _).symm\n\nlemma real.Sup_smul_of_nonneg (ha : 0 \u2264 a) (s : set \u211d) : Sup (a \u2022 s) = a \u2022 Sup s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Sup_empty, smul_zero] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cSup_singleton 0 },\n  by_cases bdd_above s,\n  { exact ((order_iso.smul_left \u211d ha').map_cSup' hs h).symm },\n  { rw [real.Sup_of_not_bdd_above (mt (bdd_above_smul_iff_of_pos ha').1 h),\n      real.Sup_of_not_bdd_above h, smul_zero] }\nend\n\nlemma real.smul_supr_of_nonneg (ha : 0 \u2264 a) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a06 i, f i) = \u2a06 i, a \u2022 f i :=\n(real.Sup_smul_of_nonneg ha _).symm.trans $ congr_arg Sup $ (range_comp _ _).symm\n\nend mul_action_with_zero\n\nsection module\nvariables [module \u03b1 \u211d] [ordered_smul \u03b1 \u211d] {a : \u03b1}\n\nlemma real.Inf_smul_of_nonpos (ha : a \u2264 0) (s : set \u211d) : Inf (a \u2022 s) = a \u2022 Sup s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Inf_empty, real.Sup_empty, smul_zero] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cInf_singleton 0 },\n  by_cases bdd_above s,\n  { exact ((order_iso.smul_left_dual \u211d ha').map_cSup' hs h).symm },\n  { rw [real.Inf_of_not_bdd_below (mt (bdd_below_smul_iff_of_neg ha').1 h),\n      real.Sup_of_not_bdd_above h, smul_zero] }\nend\n\nlemma real.smul_supr_of_nonpos (ha : a \u2264 0) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a06 i, f i) = \u2a05 i, a \u2022 f i :=\n(real.Inf_smul_of_nonpos ha _).symm.trans $ congr_arg Inf $ (range_comp _ _).symm\n\nlemma real.Sup_smul_of_nonpos (ha : a \u2264 0) (s : set \u211d) : Sup (a \u2022 s) = a \u2022 Inf s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Sup_empty, real.Inf_empty, smul_zero] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cSup_singleton 0 },\n  by_cases bdd_below s,\n  { exact ((order_iso.smul_left_dual \u211d ha').map_cInf' hs h).symm },\n  { rw [real.Sup_of_not_bdd_above (mt (bdd_above_smul_iff_of_neg ha').1 h),\n      real.Inf_of_not_bdd_below h, smul_zero] }\nend\n\nlemma real.smul_infi_of_nonpos (ha : a \u2264 0) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a05 i, f i) = \u2a06 i, a \u2022 f i :=\n(real.Sup_smul_of_nonpos ha _).symm.trans $ congr_arg Sup $ (range_comp _ _).symm\n\nend module\n\n/-! ## Special cases for real multiplication -/\n\nsection mul\n\nvariables {r : \u211d}\n\nlemma real.mul_infi_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : r * (\u2a05 i, f i) = \u2a05 i, r * f i :=\nreal.smul_infi_of_nonneg ha f\n\nlemma real.mul_supr_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : r * (\u2a06 i, f i) = \u2a06 i, r * f i :=\nreal.smul_supr_of_nonneg ha f\n\nlemma real.mul_infi_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : r * (\u2a05 i, f i) = \u2a06 i, r * f i :=\nreal.smul_infi_of_nonpos ha f\n\nlemma real.mul_supr_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : r * (\u2a06 i, f i) = \u2a05 i, r * f i :=\nreal.smul_supr_of_nonpos ha f\n\nlemma real.infi_mul_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : (\u2a05 i, f i) * r = \u2a05 i, f i * r :=\nby simp only [real.mul_infi_of_nonneg ha, mul_comm]\n\nlemma real.supr_mul_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : (\u2a06 i, f i) * r = \u2a06 i, f i * r :=\nby simp only [real.mul_supr_of_nonneg ha, mul_comm]\n\nlemma real.infi_mul_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : (\u2a05 i, f i) * r = \u2a06 i, f i * r :=\nby simp only [real.mul_infi_of_nonpos ha, mul_comm]\n\nlemma real.supr_mul_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : (\u2a06 i, f i) * r = \u2a05 i, f i * r :=\nby simp only [real.mul_supr_of_nonpos ha, mul_comm]\n\nend mul\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/real/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7242313367991092}}
{"text": "/-\nCopyright (c) 2021 Patrick Stevens. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Stevens, Thomas Browning\n\n! This file was ported from Lean 3 source module data.nat.choose.central\n! leanprover-community/mathlib commit 3e32bc908f617039c74c06ea9a897e30c30803c2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Choose.Basic\nimport Mathbin.Tactic.Linarith.Default\n\n/-!\n# Central binomial coefficients\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves properties of the central binomial coefficients (that is, `nat.choose (2 * n) n`).\n\n## Main definition and results\n\n* `nat.central_binom`: the central binomial coefficient, `(2 * n).choose n`.\n* `nat.succ_mul_central_binom_succ`: the inductive relationship between successive central binomial\n  coefficients.\n* `nat.four_pow_lt_mul_central_binom`: an exponential lower bound on the central binomial\n  coefficient.\n* `succ_dvd_central_binom`: The result that `n+1 \u2223 n.central_binom`, ensuring that the explicit\n  definition of the Catalan numbers is integer-valued.\n-/\n\n\nnamespace Nat\n\n#print Nat.centralBinom /-\n/-- The central binomial coefficient, `nat.choose (2 * n) n`.\n-/\ndef centralBinom (n : \u2115) :=\n  (2 * n).choose n\n#align nat.central_binom Nat.centralBinom\n-/\n\n#print Nat.centralBinom_eq_two_mul_choose /-\ntheorem centralBinom_eq_two_mul_choose (n : \u2115) : centralBinom n = (2 * n).choose n :=\n  rfl\n#align nat.central_binom_eq_two_mul_choose Nat.centralBinom_eq_two_mul_choose\n-/\n\n#print Nat.centralBinom_pos /-\ntheorem centralBinom_pos (n : \u2115) : 0 < centralBinom n :=\n  choose_pos (Nat.le_mul_of_pos_left zero_lt_two)\n#align nat.central_binom_pos Nat.centralBinom_pos\n-/\n\n#print Nat.centralBinom_ne_zero /-\ntheorem centralBinom_ne_zero (n : \u2115) : centralBinom n \u2260 0 :=\n  (centralBinom_pos n).ne'\n#align nat.central_binom_ne_zero Nat.centralBinom_ne_zero\n-/\n\n#print Nat.centralBinom_zero /-\n@[simp]\ntheorem centralBinom_zero : centralBinom 0 = 1 :=\n  choose_zero_right _\n#align nat.central_binom_zero Nat.centralBinom_zero\n-/\n\n#print Nat.choose_le_centralBinom /-\n/-- The central binomial coefficient is the largest binomial coefficient.\n-/\ntheorem choose_le_centralBinom (r n : \u2115) : choose (2 * n) r \u2264 centralBinom n :=\n  calc\n    (2 * n).choose r \u2264 (2 * n).choose (2 * n / 2) := choose_le_middle r (2 * n)\n    _ = (2 * n).choose n := by rw [Nat.mul_div_cancel_left n zero_lt_two]\n    \n#align nat.choose_le_central_binom Nat.choose_le_centralBinom\n-/\n\n#print Nat.two_le_centralBinom /-\ntheorem two_le_centralBinom (n : \u2115) (n_pos : 0 < n) : 2 \u2264 centralBinom n :=\n  calc\n    2 \u2264 2 * n := le_mul_of_pos_right n_pos\n    _ = (2 * n).choose 1 := (choose_one_right (2 * n)).symm\n    _ \u2264 centralBinom n := choose_le_centralBinom 1 n\n    \n#align nat.two_le_central_binom Nat.two_le_centralBinom\n-/\n\n#print Nat.succ_mul_centralBinom_succ /-\n/-- An inductive property of the central binomial coefficient.\n-/\ntheorem succ_mul_centralBinom_succ (n : \u2115) :\n    (n + 1) * centralBinom (n + 1) = 2 * (2 * n + 1) * centralBinom n :=\n  calc\n    (n + 1) * (2 * (n + 1)).choose (n + 1) = (2 * n + 2).choose (n + 1) * (n + 1) := mul_comm _ _\n    _ = (2 * n + 1).choose n * (2 * n + 2) := by rw [choose_succ_right_eq, choose_mul_succ_eq]\n    _ = 2 * ((2 * n + 1).choose n * (n + 1)) := by ring\n    _ = 2 * ((2 * n + 1).choose n * (2 * n + 1 - n)) := by\n      rw [two_mul n, add_assoc, Nat.add_sub_cancel_left]\n    _ = 2 * ((2 * n).choose n * (2 * n + 1)) := by rw [choose_mul_succ_eq]\n    _ = 2 * (2 * n + 1) * (2 * n).choose n := by rw [mul_assoc, mul_comm (2 * n + 1)]\n    \n#align nat.succ_mul_central_binom_succ Nat.succ_mul_centralBinom_succ\n-/\n\n#print Nat.four_pow_lt_mul_centralBinom /-\n/-- An exponential lower bound on the central binomial coefficient.\nThis bound is of interest because it appears in\n[Tochiori's refinement of Erd\u0151s's proof of Bertrand's postulate](tochiori_bertrand).\n-/\ntheorem four_pow_lt_mul_centralBinom (n : \u2115) (n_big : 4 \u2264 n) : 4 ^ n < n * centralBinom n :=\n  by\n  induction' n using Nat.strong_induction_on with n IH\n  rcases lt_trichotomy n 4 with (hn | rfl | hn)\n  \u00b7 clear IH\n    decide!\n  \u00b7 norm_num [central_binom, choose]\n  obtain \u27e8n, rfl\u27e9 : \u2203 m, n = m + 1 := Nat.exists_eq_succ_of_ne_zero (zero_lt_four.trans hn).ne'\n  calc\n    4 ^ (n + 1) < 4 * (n * central_binom n) :=\n      (mul_lt_mul_left <| zero_lt_four' \u2115).mpr (IH n n.lt_succ_self (Nat.le_of_lt_succ hn))\n    _ \u2264 2 * (2 * n + 1) * central_binom n :=\n      by\n      rw [\u2190 mul_assoc]\n      linarith\n    _ = (n + 1) * central_binom (n + 1) := (succ_mul_central_binom_succ n).symm\n    \n#align nat.four_pow_lt_mul_central_binom Nat.four_pow_lt_mul_centralBinom\n-/\n\n#print Nat.four_pow_le_two_mul_self_mul_centralBinom /-\n/-- An exponential lower bound on the central binomial coefficient.\nThis bound is weaker than `nat.four_pow_lt_mul_central_binom`, but it is of historical interest\nbecause it appears in Erd\u0151s's proof of Bertrand's postulate.\n-/\ntheorem four_pow_le_two_mul_self_mul_centralBinom :\n    \u2200 (n : \u2115) (n_pos : 0 < n), 4 ^ n \u2264 2 * n * centralBinom n\n  | 0, pr => (Nat.not_lt_zero _ pr).elim\n  | 1, pr => by norm_num [central_binom, choose]\n  | 2, pr => by norm_num [central_binom, choose]\n  | 3, pr => by norm_num [central_binom, choose]\n  | n@(m + 4), _ =>\n    calc\n      4 ^ n \u2264 n * centralBinom n := (four_pow_lt_mul_centralBinom _ le_add_self).le\n      _ \u2264 2 * n * centralBinom n := by\n        rw [mul_assoc]\n        refine' le_mul_of_pos_left zero_lt_two\n      \n#align nat.four_pow_le_two_mul_self_mul_central_binom Nat.four_pow_le_two_mul_self_mul_centralBinom\n-/\n\n#print Nat.two_dvd_centralBinom_succ /-\ntheorem two_dvd_centralBinom_succ (n : \u2115) : 2 \u2223 centralBinom (n + 1) :=\n  by\n  use (n + 1 + n).choose n\n  rw [central_binom_eq_two_mul_choose, two_mul, \u2190 add_assoc, choose_succ_succ, choose_symm_add, \u2190\n    two_mul]\n#align nat.two_dvd_central_binom_succ Nat.two_dvd_centralBinom_succ\n-/\n\n#print Nat.two_dvd_centralBinom_of_one_le /-\ntheorem two_dvd_centralBinom_of_one_le {n : \u2115} (h : 0 < n) : 2 \u2223 centralBinom n :=\n  by\n  rw [\u2190 Nat.succ_pred_eq_of_pos h]\n  exact two_dvd_central_binom_succ n.pred\n#align nat.two_dvd_central_binom_of_one_le Nat.two_dvd_centralBinom_of_one_le\n-/\n\n#print Nat.succ_dvd_centralBinom /-\n/-- A crucial lemma to ensure that Catalan numbers can be defined via their explicit formula\n  `catalan n = n.central_binom / (n + 1)`. -/\ntheorem succ_dvd_centralBinom (n : \u2115) : n + 1 \u2223 n.centralBinom :=\n  by\n  have h_s : (n + 1).coprime (2 * n + 1) :=\n    by\n    rw [two_mul, add_assoc, coprime_add_self_right, coprime_self_add_left]\n    exact coprime_one_left n\n  apply h_s.dvd_of_dvd_mul_left\n  apply dvd_of_mul_dvd_mul_left zero_lt_two\n  rw [\u2190 mul_assoc, \u2190 succ_mul_central_binom_succ, mul_comm]\n  exact mul_dvd_mul_left _ (two_dvd_central_binom_succ n)\n#align nat.succ_dvd_central_binom Nat.succ_dvd_centralBinom\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Choose/Central.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7242124365307211}}
{"text": "/-\nCopyright (c) 2021 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n\n! This file was ported from Lean 3 source module algebra.lie.character\n! leanprover-community/mathlib commit 132328c4dd48da87adca5d408ca54f315282b719\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Lie.Abelian\nimport Mathbin.Algebra.Lie.Solvable\nimport Mathbin.LinearAlgebra.Dual\n\n/-!\n# Characters of Lie algebras\n\nA character of a Lie algebra `L` over a commutative ring `R` is a morphism of Lie algebras `L \u2192 R`,\nwhere `R` is regarded as a Lie algebra over itself via the ring commutator. For an Abelian Lie\nalgebra (e.g., a Cartan subalgebra of a semisimple Lie algebra) a character is just a linear form.\n\n## Main definitions\n\n  * `lie_algebra.lie_character`\n  * `lie_algebra.lie_character_equiv_linear_dual`\n\n## Tags\n\nlie algebra, lie character\n-/\n\n\nuniverse u v w w\u2081\n\nnamespace LieAlgebra\n\nvariable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L]\n\n/-- A character of a Lie algebra is a morphism to the scalars. -/\nabbrev LieCharacter :=\n  L \u2192\u2097\u2045R\u2046 R\n#align lie_algebra.lie_character LieAlgebra.LieCharacter\n\nvariable {R L}\n\n@[simp]\ntheorem lieCharacter_apply_lie (\u03c7 : LieCharacter R L) (x y : L) : \u03c7 \u2045x, y\u2046 = 0 := by\n  rw [LieHom.map_lie, LieRing.of_associative_ring_bracket, mul_comm, sub_self]\n#align lie_algebra.lie_character_apply_lie LieAlgebra.lieCharacter_apply_lie\n\ntheorem lieCharacter_apply_of_mem_derived (\u03c7 : LieCharacter R L) {x : L}\n    (h : x \u2208 derivedSeries R L 1) : \u03c7 x = 0 :=\n  by\n  rw [derived_series_def, derived_series_of_ideal_succ, derived_series_of_ideal_zero, \u2190\n    LieSubmodule.mem_coeSubmodule, LieSubmodule.lieIdeal_oper_eq_linear_span] at h\n  apply Submodule.span_induction h\n  \u00b7 rintro y \u27e8\u27e8z, hz\u27e9, \u27e8\u27e8w, hw\u27e9, rfl\u27e9\u27e9\n    apply lie_character_apply_lie\n  \u00b7 exact \u03c7.map_zero\n  \u00b7 intro y z hy hz\n    rw [LieHom.map_add, hy, hz, add_zero]\n  \u00b7 intro t y hy\n    rw [LieHom.map_smul, hy, smul_zero]\n#align lie_algebra.lie_character_apply_of_mem_derived LieAlgebra.lieCharacter_apply_of_mem_derived\n\n/-- For an Abelian Lie algebra, characters are just linear forms. -/\n@[simps]\ndef lieCharacterEquivLinearDual [IsLieAbelian L] : LieCharacter R L \u2243 Module.Dual R L\n    where\n  toFun \u03c7 := (\u03c7 : L \u2192\u2097[R] R)\n  invFun \u03c8 :=\n    { \u03c8 with\n      map_lie' := fun x y => by\n        rw [LieModule.IsTrivial.trivial, LieRing.of_associative_ring_bracket, mul_comm, sub_self,\n          LinearMap.toFun_eq_coe, LinearMap.map_zero] }\n  left_inv \u03c7 := by\n    ext\n    rfl\n  right_inv \u03c8 := by\n    ext\n    rfl\n#align lie_algebra.lie_character_equiv_linear_dual LieAlgebra.lieCharacterEquivLinearDual\n\nend LieAlgebra\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Lie/Character.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7242124347200972}}
{"text": "/-\nCopyright (c) 2020 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n\n! This file was ported from Lean 3 source module ring_theory.eisenstein_criterion\n! leanprover-community/mathlib commit da420a8c6dd5bdfb85c4ced85c34388f633bc6ff\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Cast.WithTop\nimport Mathbin.RingTheory.Prime\nimport Mathbin.RingTheory.Polynomial.Content\nimport Mathbin.RingTheory.Ideal.QuotientOperations\n\n/-!\n# Eisenstein's criterion\n\nA proof of a slight generalisation of Eisenstein's criterion for the irreducibility of\na polynomial over an integral domain.\n-/\n\n\nopen Polynomial Ideal.Quotient\n\nvariable {R : Type _} [CommRing R]\n\nnamespace Polynomial\n\nopen Polynomial\n\nnamespace EisensteinCriterionAux\n\n-- Section for auxiliary lemmas used in the proof of `irreducible_of_eisenstein_criterion`\ntheorem map_eq_c_mul_x_pow_of_forall_coeff_mem {f : R[X]} {P : Ideal R}\n    (hfP : \u2200 n : \u2115, \u2191n < f.degree \u2192 f.coeff n \u2208 P) :\n    map (mk P) f = C ((mk P) f.leadingCoeff) * X ^ f.natDegree :=\n  Polynomial.ext fun n => by\n    by_cases hf0 : f = 0; \u00b7 simp [hf0]\n    rcases lt_trichotomy (\u2191n) (degree f) with (h | h | h)\n    \u00b7 erw [coeff_map, eq_zero_iff_mem.2 (hfP n h), coeff_C_mul, coeff_X_pow, if_neg,\n        MulZeroClass.mul_zero]\n      rintro rfl\n      exact not_lt_of_ge degree_le_nat_degree h\n    \u00b7 have : nat_degree f = n := nat_degree_eq_of_degree_eq_some h.symm\n      rw [coeff_C_mul, coeff_X_pow, if_pos this.symm, mul_one, leading_coeff, this, coeff_map]\n    \u00b7 rw [coeff_eq_zero_of_degree_lt, coeff_eq_zero_of_degree_lt]\n      \u00b7 refine' lt_of_le_of_lt (degree_C_mul_X_pow_le _ _) _\n        rwa [\u2190 degree_eq_nat_degree hf0]\n      \u00b7 exact lt_of_le_of_lt (degree_map_le _ _) h\n#align polynomial.eisenstein_criterion_aux.map_eq_C_mul_X_pow_of_forall_coeff_mem Polynomial.EisensteinCriterionAux.map_eq_c_mul_x_pow_of_forall_coeff_mem\n\ntheorem le_natDegree_of_map_eq_mul_x_pow {n : \u2115} {P : Ideal R} (hP : P.IsPrime) {q : R[X]}\n    {c : Polynomial (R \u29f8 P)} (hq : map (mk P) q = c * X ^ n) (hc0 : c.degree = 0) :\n    n \u2264 q.natDegree :=\n  WithBot.coe_le_coe.1\n    (calc\n      \u2191n = degree (q.map (mk P)) := by\n        rw [hq, degree_mul, hc0, zero_add, degree_pow, degree_X, nsmul_one, Nat.cast_withBot]\n      _ \u2264 degree q := (degree_map_le _ _)\n      _ \u2264 natDegree q := degree_le_natDegree\n      )\n#align polynomial.eisenstein_criterion_aux.le_nat_degree_of_map_eq_mul_X_pow Polynomial.EisensteinCriterionAux.le_natDegree_of_map_eq_mul_x_pow\n\ntheorem eval_zero_mem_ideal_of_eq_mul_x_pow {n : \u2115} {P : Ideal R} {q : R[X]}\n    {c : Polynomial (R \u29f8 P)} (hq : map (mk P) q = c * X ^ n) (hn0 : 0 < n) : eval 0 q \u2208 P := by\n  rw [\u2190 coeff_zero_eq_eval_zero, \u2190 eq_zero_iff_mem, \u2190 coeff_map, coeff_zero_eq_eval_zero, hq,\n    eval_mul, eval_pow, eval_X, zero_pow hn0, MulZeroClass.mul_zero]\n#align polynomial.eisenstein_criterion_aux.eval_zero_mem_ideal_of_eq_mul_X_pow Polynomial.EisensteinCriterionAux.eval_zero_mem_ideal_of_eq_mul_x_pow\n\ntheorem isUnit_of_natDegree_eq_zero_of_forall_dvd_isUnit {p q : R[X]}\n    (hu : \u2200 x : R, C x \u2223 p * q \u2192 IsUnit x) (hpm : p.natDegree = 0) : IsUnit p :=\n  by\n  rw [eq_C_of_degree_le_zero (nat_degree_eq_zero_iff_degree_le_zero.1 hpm), is_unit_C]\n  refine' hu _ _\n  rw [\u2190 eq_C_of_degree_le_zero (nat_degree_eq_zero_iff_degree_le_zero.1 hpm)]\n  exact dvd_mul_right _ _\n#align polynomial.eisenstein_criterion_aux.is_unit_of_nat_degree_eq_zero_of_forall_dvd_is_unit Polynomial.EisensteinCriterionAux.isUnit_of_natDegree_eq_zero_of_forall_dvd_isUnit\n\nend EisensteinCriterionAux\n\nopen EisensteinCriterionAux\n\nvariable [IsDomain R]\n\n/-- If `f` is a non constant polynomial with coefficients in `R`, and `P` is a prime ideal in `R`,\nthen if every coefficient in `R` except the leading coefficient is in `P`, and\nthe trailing coefficient is not in `P^2` and no non units in `R` divide `f`, then `f` is\nirreducible. -/\ntheorem irreducible_of_eisenstein_criterion {f : R[X]} {P : Ideal R} (hP : P.IsPrime)\n    (hfl : f.leadingCoeff \u2209 P) (hfP : \u2200 n : \u2115, \u2191n < degree f \u2192 f.coeff n \u2208 P) (hfd0 : 0 < degree f)\n    (h0 : f.coeff 0 \u2209 P ^ 2) (hu : f.IsPrimitive) : Irreducible f :=\n  have hf0 : f \u2260 0 := fun _ => by simp_all only [not_true, Submodule.zero_mem, coeff_zero]\n  have hf : f.map (mk P) = C (mk P (leadingCoeff f)) * X ^ natDegree f :=\n    map_eq_c_mul_x_pow_of_forall_coeff_mem hfP\n  have hfd0 : 0 < f.natDegree := WithBot.coe_lt_coe.1 (lt_of_lt_of_le hfd0 degree_le_natDegree)\n  \u27e8mt degree_eq_zero_of_isUnit fun h => by simp_all only [lt_irrefl],\n    by\n    rintro p q rfl\n    rw [Polynomial.map_mul] at hf\n    rcases mul_eq_mul_prime_pow\n        (show Prime (X : Polynomial (R \u29f8 P)) from monic_X.prime_of_degree_eq_one degree_X) hf with\n      \u27e8m, n, b, c, hmnd, hbc, hp, hq\u27e9\n    have hmn : 0 < m \u2192 0 < n \u2192 False := by\n      intro hm0 hn0\n      refine' h0 _\n      rw [coeff_zero_eq_eval_zero, eval_mul, sq]\n      exact\n        Ideal.mul_mem_mul (eval_zero_mem_ideal_of_eq_mul_X_pow hp hm0)\n          (eval_zero_mem_ideal_of_eq_mul_X_pow hq hn0)\n    have hpql0 : (mk P) (p * q).leadingCoeff \u2260 0 := by rwa [Ne.def, eq_zero_iff_mem]\n    have hp0 : p \u2260 0 := fun h => by\n      simp_all only [MulZeroClass.zero_mul, eq_self_iff_true, not_true, Ne.def]\n    have hq0 : q \u2260 0 := fun h => by\n      simp_all only [eq_self_iff_true, not_true, Ne.def, MulZeroClass.mul_zero]\n    have hbc0 : degree b = 0 \u2227 degree c = 0 :=\n      by\n      apply_fun degree  at hbc\n      rwa [degree_C hpql0, degree_mul, eq_comm, Nat.WithBot.add_eq_zero_iff] at hbc\n    have hmp : m \u2264 nat_degree p := le_nat_degree_of_map_eq_mul_X_pow hP hp hbc0.1\n    have hnq : n \u2264 nat_degree q := le_nat_degree_of_map_eq_mul_X_pow hP hq hbc0.2\n    have hpmqn : p.nat_degree = m \u2227 q.nat_degree = n :=\n      by\n      rw [nat_degree_mul hp0 hq0] at hmnd\n      clear * - hmnd hmp hnq\n      contrapose hmnd\n      apply ne_of_lt\n      rw [not_and_or] at hmnd\n      cases hmnd\n      \u00b7 exact add_lt_add_of_lt_of_le (lt_of_le_of_ne hmp (Ne.symm hmnd)) hnq\n      \u00b7 exact add_lt_add_of_le_of_lt hmp (lt_of_le_of_ne hnq (Ne.symm hmnd))\n    obtain rfl | rfl : m = 0 \u2228 n = 0 := by\n      rwa [pos_iff_ne_zero, pos_iff_ne_zero, imp_false, Classical.not_not, \u2190 or_iff_not_imp_left] at\n        hmn\n    \u00b7 exact Or.inl (is_unit_of_nat_degree_eq_zero_of_forall_dvd_is_unit hu hpmqn.1)\n    \u00b7\n      exact\n        Or.inr\n          (is_unit_of_nat_degree_eq_zero_of_forall_dvd_is_unit (by simpa only [mul_comm] using hu)\n            hpmqn.2)\u27e9\n#align polynomial.irreducible_of_eisenstein_criterion Polynomial.irreducible_of_eisenstein_criterion\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RingTheory/EisensteinCriterion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7242124238563532}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport logic.equiv.basic\nimport tactic.norm_fin\n\n/-!\n# `norm_swap`\n\nEvaluating `swap x y z` for numerals `x y z` that are `\u2115`, `\u2124`, or `\u211a`, via a `norm_num` plugin.\nTerms are passed to `eval`, quickly failing if not of the form `swap x y z`.\nThe expressions for numerals `x y z` are converted to `nat`, and then compared.\nBased on equality of these `nat`s, equality proofs are generated using either\n`equiv.swap_apply_left`, `equiv.swap_apply_right`, or `swap_apply_of_ne_of_ne`.\n-/\n\nopen equiv tactic expr\n\nopen norm_num\n\nnamespace norm_swap\n\n/--\nA `norm_num` plugin for normalizing `equiv.swap a b c`\nwhere `a b c` are numerals of `\u2115`, `\u2124`, `\u211a` or `fin n`.\n\n```\nexample : equiv.swap 1 2 1 = 2 := by norm_num\n```\n-/\n@[norm_num] meta def eval : expr \u2192 tactic (expr \u00d7 expr) := \u03bb e, do\n  (swapt, fun_ty, coe_fn_inst, fexpr, c) \u2190 e.match_app_coe_fn\n    <|> fail \"did not get an app coe_fn expr\",\n  guard (fexpr.get_app_fn.const_name = ``equiv.swap) <|> fail \"coe_fn not of equiv.swap\",\n  [\u03b1, deceq_inst, a, b] \u2190 pure fexpr.get_app_args <|>\n    fail \"swap did not have exactly two args applied\",\n  na \u2190 a.to_rat <|> (do (fa, _) \u2190 norm_fin.eval_fin_num a, fa.to_rat),\n  nb \u2190 b.to_rat <|> (do (fb, _) \u2190 norm_fin.eval_fin_num b, fb.to_rat),\n  nc \u2190 c.to_rat <|> (do (fc, _) \u2190 norm_fin.eval_fin_num c, fc.to_rat),\n  if nc = na then do\n    p \u2190 mk_mapp `equiv.swap_apply_left [\u03b1, deceq_inst, a, b],\n    pure (b, p)\n  else if nc = nb then do\n    p \u2190 mk_mapp `equiv.swap_apply_right [\u03b1, deceq_inst, a, b],\n    pure (a, p)\n  else do\n    nic \u2190 mk_instance_cache \u03b1,\n    hca \u2190 (prod.snd <$> prove_ne nic c a nc na) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c a, pure p),\n    hcb \u2190 (prod.snd <$> prove_ne nic c b nc nb) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c b, pure p),\n    p \u2190 mk_mapp `equiv.swap_apply_of_ne_of_ne [\u03b1, deceq_inst, a, b, c, hca, hcb],\n    pure (c, p)\n\nend norm_swap\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/tactic/norm_swap.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7242046178394532}}
{"text": "/-\nSo far, all of the propositions that we've\nseen are in the form of assertions about\nequalities: 0 = 0, 1 = 1, 2 + 3 = 4, and so\non. And we've seen how to prove propositions\nof this kind (that are actually true) using\neq.refl and rfl as a shorthand.\n\nWe are now about to set out to explore the\ndifferent forms of propositions that arise\nin predicate logic. \n\nIn this unit, we meet the simplest of all\npropositions, even simpler than equality\nstatements, namely the propositions that\nin lean are called \"true\"  and \"false\".\nFirst, true is the proposition that is \nalways trivially provable. \n-/\n\n/- The \"true introduction\" inference rule -/\n\n/-\nHere's the inference rule for true. Note \nthat it doesn't require an inputs/premises \nat all. It is truly an axiom. Makes sense:\nYou can alway assume that the proposition\ntrue is true. \n\n  -------- (true.intro)\n  pf: true\n\nThe true.intro inference rule is called\ntrue.intro because it is an introduction\nrule in the sense that it introduces a \ntrue in the conclusion that wasn't in the\npremises (of which there are none here).\n\nHere then is a formal (mathematically \nprecise) and mechanically checked proof\nof the proposition, true, in Lean.\n-/\n\ntheorem t : true := true.intro\n#check t\n#reduce t\n\n/-\nWe could of course have used tactics\nas well.\n\nEXERCISE prove t' : true using a \ntactic script.\n-/\n\nlemma t' : true :=\nbegin\n  apply true.intro\nend\n\n/- \nThat's it! Super easy. \n-/\n\n/-\nThere is no introduction rule for false!\n-/\n\n/-\nWhereas true is trivially provable, the\nproposition, false, has not proof and can\nnever be proved. Viewed as a type, it has\nno values at all. It's what we call an\nuninhabited type. Therefore there can be\nno inference rule or sequence of rules \nthat derive a proof of false, because\nsuch a thing simply does not exist! That\nis after all the meaning of false: it is\nnot true, so there must be no proof of\nit, otherwise it would be true, and \nthat would be a fatal contradiction.\n-/\n\n\n/-\nThe difference between tt/ff and the\npropositions, true and false.\n-/\n\n\n/-\nTo clarify one major potential point of\nconfusion it's imperative to see that the\npropositions, true and false, are not the \nsame as the boolean truth values, which\nin Lean are called tt and ff. In some \nother languages, they're called \"true\" \nand \"false\", which really is a source of\npossible confusion.\n-/\n\n/-\nFirst, let's confirm that the types of\ntt and ff are bool.\n-/\n\n#check tt\n#check ff\n\n/-\nYou will recall that we can assign \nthese values to variables of type bool\n-/\n\ndef boolean_false := ff\n\n#check boolean_false\n#reduce boolean_false\n\n\n/-\nBy contrast, we cannot assign the\nvalue tt as a proof of true. It's not\neven of the right type. Uncomment the\nfollowing line to see that this is the\ncase. Read the error message carefully.\n\nEXERCISE: Read and explain the error\nmessage to a colleague in your class.\n-/\n\n-- theorem bad : true := tt\n\n\n/- * EX FALSO QUOD LIBET * -/\n\n/-\nNow we come to a very fundamental\nconcept in logic: from a contradiction,\nyou can derive a proof of any proposition\nwhatsoever. To put it in English terms,\nif the impossible has happened, then \nanything goes! \n\nThe inference rule for this says that \nif you're given a proof of false, let's \ncall it f, and any proposition, P, \nwhatsoever (any value, P, of type \nProp!), then you can derive a proof \nof P, and the false disappears from\nthe conclusion (which is why we call\nthis inference rule false elimination).\n\nHere's the rule:\n\n  P : Prop, f : false \n  ------------------- false.elim\n        pf : P\n\nNote that the proposition argument, \nP, is not to be given explicitly as\nan argument to false.elim, but is to\nbe inferred from context, instead. \n-/\n\n/-\nLet's see how this works in Lean.\nLet's start by simply asserting as \nan axiom, without proof, that f is \na proof of false. \n-/\n\naxiom f : false\n\n/-\nWell, it was probably a bad idea.\nIt just says, \"trust me and accept\nthat the impossible just occurred.\"\nThe problem is that our logic is \nnow inconsistent and anything at\nall can be proved. We just feed\nour proof of false to false.elim\nto prove any proposition at all.\nLet's try to prove 0 = 1.\n-/  \n\ntheorem zeqo : 0 = 1 := false.elim f\n\n/-\nIt will very occasionally be useful\nto add an axiom to Lean, but one must\ntake extraordinary care to ensure that\nit is consistent with the underlying\nlogic of lean. The axiom that there\nis a proof of false immediately makes\nthe whole logic useful because it\ncollapses the distinction between\ntrue and false entirely, and in this\ncase, any claim can be proven true,\nand that would put us logically in\na post-truth work, which would be a\nbad and useless place to be.\n-/\n\n/-\nEXERCISE: Prove true = false (given\nthat we've assume there is a proof of\nfalse).\n-/\n\n/-\nAs a final observation, we note that\nthere are some propositions that one\nmight think of as being false, and thus\nprovable from a contradiction, but that\nwe cannot even state in Lean. For\nexample, we can't even state the claim\nthat 1 = tt because Lean requires that\nthe types of the arguments on each side\nof the = be the same.\n\n\nEXERCISE: Try it. The error message that\nappears is a little bit complicate but in\na nutshell it's saying \"I can't find a way\nto coerce/convert 1 into a bool, and so I\ncan't do anything with this expression.\"\nIn simple terms, the expression 1 = tt \nhas a type error. It's not even a well\nformed expression.\n-/\n\n\n\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm", "sha": "bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c", "save_path": "github-repos/lean/kevinsullivan-cs-dm", "path": "github-repos/lean/kevinsullivan-cs-dm/cs-dm-bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c/02_True_False/00_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7242046141932705}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl, Yuyang Zhao\n\n! This file was ported from Lean 3 source module algebra.order.monoid.nat_cast\n! leanprover-community/mathlib commit 07fee0ca54c320250c98bacf31ca5f288b2bcbe2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.Monoid.Lemmas\nimport Mathlib.Algebra.Order.ZeroLEOne\nimport Mathlib.Data.Nat.Cast.Defs\n\n/-!\n# Order of numerals in an `AddMonoidWithOne`.\n-/\n\nvariable {\u03b1 : Type _}\n\nopen Function\n\nlemma lt_add_one [One \u03b1] [AddZeroClass \u03b1] [PartialOrder \u03b1] [ZeroLEOneClass \u03b1]\n  [NeZero (1 : \u03b1)] [CovariantClass \u03b1 \u03b1 (\u00b7+\u00b7) (\u00b7<\u00b7)] (a : \u03b1) : a < a + 1 :=\nlt_add_of_pos_right _ zero_lt_one\n#align lt_add_one lt_add_one\n\nlemma lt_one_add [One \u03b1] [AddZeroClass \u03b1] [PartialOrder \u03b1] [ZeroLEOneClass \u03b1]\n  [NeZero (1 : \u03b1)] [CovariantClass \u03b1 \u03b1 (swap (\u00b7+\u00b7)) (\u00b7<\u00b7)] (a : \u03b1) : a < 1 + a :=\nlt_add_of_pos_left _ zero_lt_one\n#align lt_one_add lt_one_add\n\nvariable [AddMonoidWithOne \u03b1]\n\nlemma zero_le_two [Preorder \u03b1] [ZeroLEOneClass \u03b1] [CovariantClass \u03b1 \u03b1 (\u00b7+\u00b7) (\u00b7\u2264\u00b7)] :\n    (0 : \u03b1) \u2264 2 := by\n  rw [\u2190 one_add_one_eq_two]\n  exact add_nonneg zero_le_one zero_le_one\n#align zero_le_two zero_le_two\n\nlemma zero_le_three [Preorder \u03b1] [ZeroLEOneClass \u03b1] [CovariantClass \u03b1 \u03b1 (\u00b7+\u00b7) (\u00b7\u2264\u00b7)] :\n  (0 : \u03b1) \u2264 3 := by\n  rw [\u2190 two_add_one_eq_three]\n  exact add_nonneg zero_le_two zero_le_one\n#align zero_le_three zero_le_three\n\nlemma zero_le_four [Preorder \u03b1] [ZeroLEOneClass \u03b1] [CovariantClass \u03b1 \u03b1 (\u00b7+\u00b7) (\u00b7\u2264\u00b7)] :\n    (0 : \u03b1) \u2264 4 := by\n  rw [\u2190 three_add_one_eq_four]\n  exact add_nonneg zero_le_three zero_le_one\n#align zero_le_four zero_le_four\n\nlemma one_le_two [LE \u03b1] [ZeroLEOneClass \u03b1] [CovariantClass \u03b1 \u03b1 (\u00b7+\u00b7) (\u00b7\u2264\u00b7)] :\n  (1 : \u03b1) \u2264 2 :=\ncalc (1 : \u03b1) = 1 + 0 := (add_zero 1).symm\n     _ \u2264 1 + 1 := add_le_add_left zero_le_one _\n     _ = 2 := one_add_one_eq_two\n#align one_le_two one_le_two\n\nlemma one_le_two' [LE \u03b1] [ZeroLEOneClass \u03b1] [CovariantClass \u03b1 \u03b1 (swap (\u00b7+\u00b7)) (\u00b7\u2264\u00b7)] :\n  (1 : \u03b1) \u2264 2 :=\ncalc (1 : \u03b1) = 0 + 1 := (zero_add 1).symm\n     _ \u2264 1 + 1 := add_le_add_right zero_le_one _\n     _ = 2 := one_add_one_eq_two\n#align one_le_two' one_le_two'\n\nsection\nvariable [PartialOrder \u03b1] [ZeroLEOneClass \u03b1] [NeZero (1 : \u03b1)]\n\nsection\nvariable [CovariantClass \u03b1 \u03b1 (\u00b7+\u00b7) (\u00b7\u2264\u00b7)]\n\n/-- See `zero_lt_two'` for a version with the type explicit. -/\n@[simp] lemma zero_lt_two : (0 : \u03b1) < 2 := zero_lt_one.trans_le one_le_two\n/-- See `zero_lt_three'` for a version with the type explicit. -/\n@[simp] lemma zero_lt_three : (0 : \u03b1) < 3 := by\n  rw [\u2190 two_add_one_eq_three]\n  exact lt_add_of_lt_of_nonneg zero_lt_two zero_le_one\n/-- See `zero_lt_four'` for a version with the type explicit. -/\n@[simp] lemma zero_lt_four : (0 : \u03b1) < 4 := by\n  rw [\u2190 three_add_one_eq_four]\n  exact lt_add_of_lt_of_nonneg zero_lt_three zero_le_one\n#align zero_lt_four zero_lt_four\n#align zero_lt_three zero_lt_three\n#align zero_lt_two zero_lt_two\n\nvariable (\u03b1)\n\n/-- See `zero_lt_two` for a version with the type implicit. -/\nlemma zero_lt_two' : (0 : \u03b1) < 2 := zero_lt_two\n/-- See `zero_lt_three` for a version with the type implicit. -/\nlemma zero_lt_three' : (0 : \u03b1) < 3 := zero_lt_three\n/-- See `zero_lt_four` for a version with the type implicit. -/\nlemma zero_lt_four' : (0 : \u03b1) < 4 := zero_lt_four\n#align zero_lt_four' zero_lt_four'\n#align zero_lt_three' zero_lt_three'\n#align zero_lt_two' zero_lt_two'\n\ninstance ZeroLEOneClass.neZero.two : NeZero (2 : \u03b1) := \u27e8zero_lt_two.ne'\u27e9\ninstance ZeroLEOneClass.neZero.three : NeZero (3 : \u03b1) := \u27e8zero_lt_three.ne'\u27e9\ninstance ZeroLEOneClass.neZero.four : NeZero (4 : \u03b1) := \u27e8zero_lt_four.ne'\u27e9\n\nend\n\nlemma one_lt_two [CovariantClass \u03b1 \u03b1 (\u00b7+\u00b7) (\u00b7<\u00b7)] : (1 : \u03b1) < 2 := by\n  rw [\u2190 one_add_one_eq_two]\n  exact lt_add_one _\n#align one_lt_two one_lt_two\n\nend\n\nalias zero_lt_two \u2190 two_pos\nalias zero_lt_three \u2190 three_pos\nalias zero_lt_four \u2190 four_pos\n#align four_pos four_pos\n#align three_pos three_pos\n#align two_pos two_pos\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/Monoid/NatCast.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7241817849738038}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Floris van Doorn\n-/\nimport algebra.module.basic\nimport algebra.bounds\nimport algebra.order.archimedean\nimport algebra.star.basic\nimport data.real.cau_seq_completion\nimport order.conditionally_complete_lattice\n\n/-!\n# Real numbers from Cauchy sequences\n\nThis file defines `\u211d` as the type of equivalence classes of Cauchy sequences of rational numbers.\nThis choice is motivated by how easy it is to prove that `\u211d` is a commutative ring, by simply\nlifting everything to `\u211a`.\n-/\n\nopen_locale pointwise\n\n/-- The type `\u211d` of real numbers constructed as equivalence classes of Cauchy sequences of rational\nnumbers. -/\nstructure real := of_cauchy ::\n(cauchy : @cau_seq.completion.Cauchy \u211a _ _ _ abs _)\nnotation `\u211d` := real\n\nattribute [pp_using_anonymous_constructor] real\n\nnamespace real\nopen cau_seq cau_seq.completion\n\nvariables {x y : \u211d}\n\nlemma ext_cauchy_iff : \u2200 {x y : real}, x = y \u2194 x.cauchy = y.cauchy\n| \u27e8a\u27e9 \u27e8b\u27e9 := by split; cc\n\nlemma ext_cauchy {x y : real} : x.cauchy = y.cauchy \u2192 x = y :=\next_cauchy_iff.2\n\n/-- The real numbers are isomorphic to the quotient of Cauchy sequences on the rationals. -/\ndef equiv_Cauchy : \u211d \u2243 cau_seq.completion.Cauchy :=\n\u27e8real.cauchy, real.of_cauchy, \u03bb \u27e8_\u27e9, rfl, \u03bb _, rfl\u27e9\n\n-- irreducible doesn't work for instances: https://github.com/leanprover-community/lean/issues/511\n@[irreducible] private def zero : \u211d := \u27e80\u27e9\n@[irreducible] private def one : \u211d := \u27e81\u27e9\n@[irreducible] private def add : \u211d \u2192 \u211d \u2192 \u211d | \u27e8a\u27e9 \u27e8b\u27e9 := \u27e8a + b\u27e9\n@[irreducible] private def neg : \u211d \u2192 \u211d | \u27e8a\u27e9 := \u27e8-a\u27e9\n@[irreducible] private def mul : \u211d \u2192 \u211d \u2192 \u211d | \u27e8a\u27e9 \u27e8b\u27e9 := \u27e8a * b\u27e9\n\ninstance : has_zero \u211d := \u27e8zero\u27e9\ninstance : has_one \u211d := \u27e8one\u27e9\ninstance : has_add \u211d := \u27e8add\u27e9\ninstance : has_neg \u211d := \u27e8neg\u27e9\ninstance : has_mul \u211d := \u27e8mul\u27e9\n\nlemma zero_cauchy : (\u27e80\u27e9 : \u211d) = 0 := show _ = zero, by rw zero\nlemma one_cauchy : (\u27e81\u27e9 : \u211d) = 1 := show _ = one, by rw one\nlemma add_cauchy {a b} : (\u27e8a\u27e9 + \u27e8b\u27e9 : \u211d) = \u27e8a + b\u27e9 := show add _ _ = _, by rw add\nlemma neg_cauchy {a} : (-\u27e8a\u27e9 : \u211d) = \u27e8-a\u27e9 := show neg _ = _, by rw neg\nlemma mul_cauchy {a b} : (\u27e8a\u27e9 * \u27e8b\u27e9 : \u211d) = \u27e8a * b\u27e9 := show mul _ _ = _, by rw mul\n\ninstance : comm_ring \u211d :=\nbegin\n  refine_struct { zero  := (0 : \u211d),\n                  one   := (1 : \u211d),\n                  mul   := (*),\n                  add   := (+),\n                  neg   := @has_neg.neg \u211d _,\n                  sub   := \u03bb a b, a + (-b),\n                  npow  := @npow_rec \u211d \u27e81\u27e9 \u27e8(*)\u27e9,\n                  nsmul := @nsmul_rec \u211d \u27e80\u27e9 \u27e8(+)\u27e9,\n                  zsmul := @zsmul_rec \u211d \u27e80\u27e9 \u27e8(+)\u27e9 \u27e8@has_neg.neg \u211d _\u27e9 };\n  repeat { rintro \u27e8_\u27e9, };\n  try { refl };\n  simp [\u2190 zero_cauchy, \u2190 one_cauchy, add_cauchy, neg_cauchy, mul_cauchy];\n  apply add_assoc <|> apply add_comm <|> apply mul_assoc <|> apply mul_comm <|>\n    apply left_distrib <|> apply right_distrib <|> apply sub_eq_add_neg <|> skip\nend\n\n/-! Extra instances to short-circuit type class resolution.\n\n These short-circuits have an additional property of ensuring that a computable path is found; if\n `field \u211d` is found first, then decaying it to these typeclasses would result in a `noncomputable`\n version of them. -/\ninstance : ring \u211d               := by apply_instance\ninstance : comm_semiring \u211d      := by apply_instance\ninstance : semiring \u211d           := by apply_instance\ninstance : comm_monoid_with_zero \u211d := by apply_instance\ninstance : monoid_with_zero \u211d   := by apply_instance\ninstance : add_comm_group \u211d     := by apply_instance\ninstance : add_group \u211d          := by apply_instance\ninstance : add_comm_monoid \u211d    := by apply_instance\ninstance : add_monoid \u211d         := by apply_instance\ninstance : add_left_cancel_semigroup \u211d := by apply_instance\ninstance : add_right_cancel_semigroup \u211d := by apply_instance\ninstance : add_comm_semigroup \u211d := by apply_instance\ninstance : add_semigroup \u211d      := by apply_instance\ninstance : comm_monoid \u211d        := by apply_instance\ninstance : monoid \u211d             := by apply_instance\ninstance : comm_semigroup \u211d     := by apply_instance\ninstance : semigroup \u211d          := by apply_instance\ninstance : has_sub \u211d            := by apply_instance\ninstance : module \u211d \u211d           := by apply_instance\ninstance : inhabited \u211d          := \u27e80\u27e9\n\n/-- The real numbers are a `*`-ring, with the trivial `*`-structure. -/\ninstance : star_ring \u211d          := star_ring_of_comm\n\n/-- Coercion `\u211a` \u2192 `\u211d` as a `ring_hom`. Note that this\nis `cau_seq.completion.of_rat`, not `rat.cast`. -/\ndef of_rat : \u211a \u2192+* \u211d :=\nby refine_struct { to_fun := of_cauchy \u2218 of_rat };\n  simp [of_rat_one, of_rat_zero, of_rat_mul, of_rat_add,\n    one_cauchy, zero_cauchy, \u2190 mul_cauchy, \u2190 add_cauchy]\n\nlemma of_rat_apply (x : \u211a) : of_rat x = of_cauchy (cau_seq.completion.of_rat x) := rfl\n\n/-- Make a real number from a Cauchy sequence of rationals (by taking the equivalence class). -/\ndef mk (x : cau_seq \u211a abs) : \u211d := \u27e8cau_seq.completion.mk x\u27e9\n\ntheorem mk_eq {f g : cau_seq \u211a abs} : mk f = mk g \u2194 f \u2248 g :=\next_cauchy_iff.trans mk_eq\n\n@[irreducible]\nprivate def lt : \u211d \u2192 \u211d \u2192 Prop | \u27e8x\u27e9 \u27e8y\u27e9 :=\nquotient.lift_on\u2082 x y (<) $\n  \u03bb f\u2081 g\u2081 f\u2082 g\u2082 hf hg, propext $\n  \u27e8\u03bb h, lt_of_eq_of_lt (setoid.symm hf) (lt_of_lt_of_eq h hg),\n   \u03bb h, lt_of_eq_of_lt hf (lt_of_lt_of_eq h (setoid.symm hg))\u27e9\n\ninstance : has_lt \u211d := \u27e8lt\u27e9\n\nlemma lt_cauchy {f g} : (\u27e8\u27e6f\u27e7\u27e9 : \u211d) < \u27e8\u27e6g\u27e7\u27e9 \u2194 f < g := show lt _ _ \u2194 _, by rw lt; refl\n\n@[simp] theorem mk_lt {f g : cau_seq \u211a abs} : mk f < mk g \u2194 f < g :=\nlt_cauchy\n\nlemma mk_zero : mk 0 = 0 := by rw \u2190 zero_cauchy; refl\nlemma mk_one : mk 1 = 1 := by rw \u2190 one_cauchy; refl\nlemma mk_add {f g : cau_seq \u211a abs} : mk (f + g) = mk f + mk g := by simp [mk, add_cauchy]\nlemma mk_mul {f g : cau_seq \u211a abs} : mk (f * g) = mk f * mk g := by simp [mk, mul_cauchy]\nlemma mk_neg {f : cau_seq \u211a abs} : mk (-f) = -mk f := by simp [mk, neg_cauchy]\n\n@[simp] theorem mk_pos {f : cau_seq \u211a abs} : 0 < mk f \u2194 pos f :=\nby rw [\u2190 mk_zero, mk_lt]; exact iff_of_eq (congr_arg pos (sub_zero f))\n\n@[irreducible] private def le (x y : \u211d) : Prop := x < y \u2228 x = y\ninstance : has_le \u211d := \u27e8le\u27e9\nprivate lemma le_def {x y : \u211d} : x \u2264 y \u2194 x < y \u2228 x = y := show le _ _ \u2194 _, by rw le\n\n@[simp] theorem mk_le {f g : cau_seq \u211a abs} : mk f \u2264 mk g \u2194 f \u2264 g :=\nby simp [le_def, mk_eq]; refl\n\n@[elab_as_eliminator]\nprotected lemma ind_mk {C : real \u2192 Prop} (x : real) (h : \u2200 y, C (mk y)) : C x :=\nbegin\n  cases x with x,\n  induction x using quot.induction_on with x,\n  exact h x\nend\n\ntheorem add_lt_add_iff_left {a b : \u211d} (c : \u211d) : c + a < c + b \u2194 a < b :=\nbegin\n  induction a using real.ind_mk,\n  induction b using real.ind_mk,\n  induction c using real.ind_mk,\n  simp only [mk_lt, \u2190 mk_add],\n  show pos _ \u2194 pos _, rw add_sub_add_left_eq_sub\nend\n\ninstance : partial_order \u211d :=\n{ le := (\u2264), lt := (<),\n  lt_iff_le_not_le := \u03bb a b, real.ind_mk a $ \u03bb a, real.ind_mk b $ \u03bb b,\n    by simpa using lt_iff_le_not_le,\n  le_refl := \u03bb a, a.ind_mk (by intro a; rw mk_le),\n  le_trans := \u03bb a b c, real.ind_mk a $ \u03bb a, real.ind_mk b $ \u03bb b, real.ind_mk c $ \u03bb c,\n    by simpa using le_trans,\n  lt_iff_le_not_le := \u03bb a b, real.ind_mk a $ \u03bb a, real.ind_mk b $ \u03bb b,\n    by simpa using lt_iff_le_not_le,\n  le_antisymm := \u03bb a b, real.ind_mk a $ \u03bb a, real.ind_mk b $ \u03bb b,\n    by simpa [mk_eq] using @cau_seq.le_antisymm _ _ a b }\n\ninstance : preorder \u211d := by apply_instance\n\ntheorem of_rat_lt {x y : \u211a} : of_rat x < of_rat y \u2194 x < y :=\nbegin\n  rw [mk_lt] {md := tactic.transparency.semireducible},\n  exact const_lt\nend\n\nprotected theorem zero_lt_one : (0 : \u211d) < 1 :=\nby convert of_rat_lt.2 zero_lt_one; simp\n\nprotected theorem mul_pos {a b : \u211d} : 0 < a \u2192 0 < b \u2192 0 < a * b :=\nbegin\n  induction a using real.ind_mk with a,\n  induction b using real.ind_mk with b,\n  simpa only [mk_lt, mk_pos, \u2190 mk_mul] using cau_seq.mul_pos\nend\n\ninstance : ordered_comm_ring \u211d :=\n{ add_le_add_left :=\n  begin\n    simp only [le_iff_eq_or_lt],\n    rintros a b \u27e8rfl, h\u27e9,\n    { simp },\n    { exact \u03bb c, or.inr ((add_lt_add_iff_left c).2 \u2039_\u203a) }\n  end,\n  zero_le_one := le_of_lt real.zero_lt_one,\n  mul_pos     := @real.mul_pos,\n  .. real.comm_ring, .. real.partial_order, .. real.semiring }\n\ninstance : ordered_ring \u211d               := by apply_instance\ninstance : ordered_semiring \u211d           := by apply_instance\ninstance : ordered_add_comm_group \u211d     := by apply_instance\ninstance : ordered_cancel_add_comm_monoid \u211d := by apply_instance\ninstance : ordered_add_comm_monoid \u211d    := by apply_instance\ninstance : nontrivial \u211d := \u27e8\u27e80, 1, ne_of_lt real.zero_lt_one\u27e9\u27e9\n\nopen_locale classical\n\nnoncomputable instance : linear_order \u211d :=\n{ le_total := begin\n    intros a b,\n    induction a using real.ind_mk with a,\n    induction b using real.ind_mk with b,\n    simpa using le_total a b,\n  end,\n  decidable_le := by apply_instance,\n  .. real.partial_order }\n\nnoncomputable instance : linear_ordered_comm_ring \u211d :=\n{ .. real.nontrivial, .. real.ordered_ring, .. real.comm_ring, .. real.linear_order }\n\n/- Extra instances to short-circuit type class resolution -/\nnoncomputable instance : linear_ordered_ring \u211d        := by apply_instance\nnoncomputable instance : linear_ordered_semiring \u211d    := by apply_instance\ninstance : is_domain \u211d :=\n{ .. real.nontrivial, .. real.comm_ring, .. linear_ordered_ring.is_domain }\n\n/-- The real numbers are an ordered `*`-ring, with the trivial `*`-structure. -/\ninstance : star_ordered_ring \u211d :=\n{ star_mul_self_nonneg := \u03bb r, mul_self_nonneg r, }\n\n@[irreducible] private noncomputable def inv' : \u211d \u2192 \u211d | \u27e8a\u27e9 := \u27e8a\u207b\u00b9\u27e9\nnoncomputable instance : has_inv \u211d := \u27e8inv'\u27e9\nlemma inv_cauchy {f} : (\u27e8f\u27e9 : \u211d)\u207b\u00b9 = \u27e8f\u207b\u00b9\u27e9 := show inv' _ = _, by rw inv'\n\nnoncomputable instance : linear_ordered_field \u211d :=\n{ inv := has_inv.inv,\n  mul_inv_cancel := begin\n    rintros \u27e8a\u27e9 h,\n    rw mul_comm,\n    simp only [inv_cauchy, mul_cauchy, \u2190 one_cauchy, \u2190 zero_cauchy, ne.def] at *,\n    exact cau_seq.completion.inv_mul_cancel h,\n  end,\n  inv_zero := by simp [\u2190 zero_cauchy, inv_cauchy],\n  ..real.linear_ordered_comm_ring, }\n\n/- Extra instances to short-circuit type class resolution -/\n\nnoncomputable instance : linear_ordered_add_comm_group \u211d          := by apply_instance\nnoncomputable instance field : field \u211d                            := by apply_instance\nnoncomputable instance : division_ring \u211d                          := by apply_instance\nnoncomputable instance : distrib_lattice \u211d                        := by apply_instance\nnoncomputable instance : lattice \u211d                                := by apply_instance\nnoncomputable instance : semilattice_inf \u211d                        := by apply_instance\nnoncomputable instance : semilattice_sup \u211d                        := by apply_instance\nnoncomputable instance : has_inf \u211d                                := by apply_instance\nnoncomputable instance : has_sup \u211d                                := by apply_instance\nnoncomputable instance decidable_lt (a b : \u211d) : decidable (a < b) := by apply_instance\nnoncomputable instance decidable_le (a b : \u211d) : decidable (a \u2264 b) := by apply_instance\nnoncomputable instance decidable_eq (a b : \u211d) : decidable (a = b) := by apply_instance\n\nopen rat\n\n@[simp] theorem of_rat_eq_cast : \u2200 x : \u211a, of_rat x = x :=\nof_rat.eq_rat_cast\n\ntheorem le_mk_of_forall_le {f : cau_seq \u211a abs} :\n  (\u2203 i, \u2200 j \u2265 i, x \u2264 f j) \u2192 x \u2264 mk f :=\nbegin\n  intro h,\n  induction x using real.ind_mk with x,\n  apply le_of_not_lt,\n  rw mk_lt,\n  rintro \u27e8K, K0, hK\u27e9,\n  obtain \u27e8i, H\u27e9 := exists_forall_ge_and h\n    (exists_forall_ge_and hK (f.cauchy\u2083 $ half_pos K0)),\n  apply not_lt_of_le (H _ (le_refl _)).1,\n  rw \u2190 of_rat_eq_cast,\n  rw [mk_lt] {md := tactic.transparency.semireducible},\n  refine \u27e8_, half_pos K0, i, \u03bb j ij, _\u27e9,\n  have := add_le_add (H _ ij).2.1\n    (le_of_lt (abs_lt.1 $ (H _ (le_refl _)).2.2 _ ij).1),\n  rwa [\u2190 sub_eq_add_neg, sub_self_div_two, sub_apply, sub_add_sub_cancel] at this\nend\n\n\n\ntheorem mk_near_of_forall_near {f : cau_seq \u211a abs} {x : \u211d} {\u03b5 : \u211d}\n  (H : \u2203 i, \u2200 j \u2265 i, |(f j : \u211d) - x| \u2264 \u03b5) : |mk f - x| \u2264 \u03b5 :=\nabs_sub_le_iff.2\n  \u27e8sub_le_iff_le_add'.2 $ mk_le_of_forall_le $\n    H.imp $ \u03bb i h j ij, sub_le_iff_le_add'.1 (abs_sub_le_iff.1 $ h j ij).1,\n  sub_le.1 $ le_mk_of_forall_le $\n    H.imp $ \u03bb i h j ij, sub_le.1 (abs_sub_le_iff.1 $ h j ij).2\u27e9\n\ninstance : archimedean \u211d :=\narchimedean_iff_rat_le.2 $ \u03bb x, real.ind_mk x $ \u03bb f,\nlet \u27e8M, M0, H\u27e9 := f.bounded' 0 in\n\u27e8M, mk_le_of_forall_le \u27e80, \u03bb i _,\n  rat.cast_le.2 $ le_of_lt (abs_lt.1 (H i)).2\u27e9\u27e9\n\nnoncomputable instance : floor_ring \u211d := archimedean.floor_ring _\n\ntheorem is_cau_seq_iff_lift {f : \u2115 \u2192 \u211a} : is_cau_seq abs f \u2194 is_cau_seq\n  abs (\u03bb i, (f i : \u211d)) :=\n\u27e8\u03bb H \u03b5 \u03b50,\n  let \u27e8\u03b4, \u03b40, \u03b4\u03b5\u27e9 := exists_pos_rat_lt \u03b50 in\n  (H _ \u03b40).imp $ \u03bb i hi j ij, lt_trans\n    (by simpa using (@rat.cast_lt \u211d _ _ _).2 (hi _ ij)) \u03b4\u03b5,\n \u03bb H \u03b5 \u03b50, (H _ (rat.cast_pos.2 \u03b50)).imp $\n   \u03bb i hi j ij, (@rat.cast_lt \u211d _ _ _).1 $ by simpa using hi _ ij\u27e9\n\ntheorem of_near (f : \u2115 \u2192 \u211a) (x : \u211d)\n  (h : \u2200 \u03b5 > 0, \u2203 i, \u2200 j \u2265 i, |(f j : \u211d) - x| < \u03b5) :\n  \u2203 h', real.mk \u27e8f, h'\u27e9 = x :=\n\u27e8is_cau_seq_iff_lift.2 (of_near _ (const abs x) h),\n sub_eq_zero.1 $ abs_eq_zero.1 $\n  eq_of_le_of_forall_le_of_dense (abs_nonneg _) $ \u03bb \u03b5 \u03b50,\n    mk_near_of_forall_near $\n    (h _ \u03b50).imp (\u03bb i h j ij, le_of_lt (h j ij))\u27e9\n\ntheorem exists_floor (x : \u211d) : \u2203 (ub : \u2124), (ub:\u211d) \u2264 x \u2227\n   \u2200 (z : \u2124), (z:\u211d) \u2264 x \u2192 z \u2264 ub :=\nint.exists_greatest_of_bdd\n  (let \u27e8n, hn\u27e9 := exists_int_gt x in \u27e8n, \u03bb z h',\n    int.cast_le.1 $ le_trans h' $ le_of_lt hn\u27e9)\n  (let \u27e8n, hn\u27e9 := exists_int_lt x in \u27e8n, le_of_lt hn\u27e9)\n\ntheorem exists_is_lub (S : set \u211d) (hne : S.nonempty) (hbdd : bdd_above S) :\n  \u2203 x, is_lub S x :=\nbegin\n  rcases \u27e8hne, hbdd\u27e9 with \u27e8\u27e8L, hL\u27e9, \u27e8U, hU\u27e9\u27e9,\n  have : \u2200 d : \u2115, bdd_above {m : \u2124 | \u2203 y \u2208 S, (m : \u211d) \u2264 y * d},\n  { cases exists_int_gt U with k hk,\n    refine \u03bb d, \u27e8k * d, \u03bb z h, _\u27e9,\n    rcases h with \u27e8y, yS, hy\u27e9,\n    refine int.cast_le.1 (hy.trans _),\n    push_cast,\n    exact mul_le_mul_of_nonneg_right ((hU yS).trans hk.le) d.cast_nonneg },\n  choose f hf using \u03bb d : \u2115, int.exists_greatest_of_bdd (this d) \u27e8\u230aL * d\u230b, L, hL, int.floor_le _\u27e9,\n  have hf\u2081 : \u2200 n > 0, \u2203 y \u2208 S, ((f n / n:\u211a):\u211d) \u2264 y := \u03bb n n0,\n    let \u27e8y, yS, hy\u27e9 := (hf n).1 in\n    \u27e8y, yS, by simpa using (div_le_iff ((nat.cast_pos.2 n0):((_:\u211d) < _))).2 hy\u27e9,\n  have hf\u2082 : \u2200 (n > 0) (y \u2208 S), (y - (n:\u2115)\u207b\u00b9 : \u211d) < (f n / n:\u211a),\n  { intros n n0 y yS,\n    have := (int.sub_one_lt_floor _).trans_le (int.cast_le.2 $ (hf n).2 _ \u27e8y, yS, int.floor_le _\u27e9),\n    simp [-sub_eq_add_neg],\n    rwa [lt_div_iff ((nat.cast_pos.2 n0):((_:\u211d) < _)), sub_mul, _root_.inv_mul_cancel],\n    exact ne_of_gt (nat.cast_pos.2 n0) },\n  have hg : is_cau_seq abs (\u03bb n, f n / n : \u2115 \u2192 \u211a),\n  { intros \u03b5 \u03b50,\n    suffices : \u2200 j k \u2265 \u2308\u03b5\u207b\u00b9\u2309\u208a, (f j / j - f k / k : \u211a) < \u03b5,\n    { refine \u27e8_, \u03bb j ij, abs_lt.2 \u27e8_, this _ _ ij (le_refl _)\u27e9\u27e9,\n      rw [neg_lt, neg_sub], exact this _ _ (le_refl _) ij },\n    intros j k ij ik,\n    replace ij := le_trans (nat.le_ceil _) (nat.cast_le.2 ij),\n    replace ik := le_trans (nat.le_ceil _) (nat.cast_le.2 ik),\n    have j0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 \u03b50) ij),\n    have k0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 \u03b50) ik),\n    rcases hf\u2081 _ j0 with \u27e8y, yS, hy\u27e9,\n    refine lt_of_lt_of_le ((@rat.cast_lt \u211d _ _ _).1 _)\n      ((inv_le \u03b50 (nat.cast_pos.2 k0)).1 ik),\n    simpa using sub_lt_iff_lt_add'.2\n      (lt_of_le_of_lt hy $ sub_lt_iff_lt_add.1 $ hf\u2082 _ k0 _ yS) },\n  let g : cau_seq \u211a abs := \u27e8\u03bb n, f n / n, hg\u27e9,\n  refine \u27e8mk g, \u27e8\u03bb x xS, _, \u03bb y h, _\u27e9\u27e9,\n  { refine le_of_forall_ge_of_dense (\u03bb z xz, _),\n    cases exists_nat_gt (x - z)\u207b\u00b9 with K hK,\n    refine le_mk_of_forall_le \u27e8K, \u03bb n nK, _\u27e9,\n    replace xz := sub_pos.2 xz,\n    replace hK := le_trans (le_of_lt hK) (nat.cast_le.2 nK),\n    have n0 : 0 < n := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 xz) hK),\n    refine le_trans _ (le_of_lt $ hf\u2082 _ n0 _ xS),\n    rwa [le_sub, inv_le ((nat.cast_pos.2 n0):((_:\u211d) < _)) xz] },\n  { exact mk_le_of_forall_le \u27e81, \u03bb n n1,\n      let \u27e8x, xS, hx\u27e9 := hf\u2081 _ n1 in le_trans hx (h xS)\u27e9 }\nend\n\nnoncomputable instance : has_Sup \u211d :=\n\u27e8\u03bb S, if h : S.nonempty \u2227 bdd_above S then classical.some (exists_is_lub S h.1 h.2) else 0\u27e9\n\nlemma Sup_def (S : set \u211d) :\n  Sup S = if h : S.nonempty \u2227 bdd_above S\n    then classical.some (exists_is_lub S h.1 h.2) else 0 := rfl\n\nprotected theorem is_lub_Sup (S : set \u211d) (h\u2081 : S.nonempty) (h\u2082 : bdd_above S) : is_lub S (Sup S) :=\nby { simp only [Sup_def, dif_pos (and.intro h\u2081 h\u2082)], apply classical.some_spec }\n\nnoncomputable instance : has_Inf \u211d := \u27e8\u03bb S, -Sup (-S)\u27e9\n\nlemma Inf_def (S : set \u211d) : Inf S = -Sup (-S) := rfl\n\nprotected theorem is_glb_Inf (S : set \u211d) (h\u2081 : S.nonempty) (h\u2082 : bdd_below S) :\n  is_glb S (Inf S) :=\nbegin\n  rw [Inf_def, \u2190 is_lub_neg', neg_neg],\n  exact real.is_lub_Sup _ h\u2081.neg h\u2082.neg\nend\n\nnoncomputable instance : conditionally_complete_linear_order \u211d :=\n{ Sup := has_Sup.Sup,\n  Inf := has_Inf.Inf,\n  le_cSup := \u03bb s a hs ha, (real.is_lub_Sup s \u27e8a, ha\u27e9 hs).1 ha,\n  cSup_le := \u03bb s a hs ha, (real.is_lub_Sup s hs \u27e8a, ha\u27e9).2 ha,\n  cInf_le := \u03bb s a hs ha, (real.is_glb_Inf s \u27e8a, ha\u27e9 hs).1 ha,\n  le_cInf := \u03bb s a hs ha, (real.is_glb_Inf s hs \u27e8a, ha\u27e9).2 ha,\n ..real.linear_order, ..real.lattice}\n\nlemma lt_Inf_add_pos {s : set \u211d} (h : s.nonempty) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n  \u2203 a \u2208 s, a < Inf s + \u03b5 :=\nexists_lt_of_cInf_lt h $ lt_add_of_pos_right _ h\u03b5\n\nlemma add_neg_lt_Sup {s : set \u211d} (h : s.nonempty) {\u03b5 : \u211d} (h\u03b5 : \u03b5 < 0) :\n  \u2203 a \u2208 s, Sup s + \u03b5 < a :=\nexists_lt_of_lt_cSup h $ add_lt_iff_neg_left.2 h\u03b5\n\nlemma Inf_le_iff {s : set \u211d} (h : bdd_below s) (h' : s.nonempty) {a : \u211d} :\n  Inf s \u2264 a \u2194 \u2200 \u03b5, 0 < \u03b5 \u2192 \u2203 x \u2208 s, x < a + \u03b5 :=\nbegin\n  rw le_iff_forall_pos_lt_add,\n  split; intros H \u03b5 \u03b5_pos,\n  { exact exists_lt_of_cInf_lt h' (H \u03b5 \u03b5_pos) },\n  { rcases H \u03b5 \u03b5_pos with \u27e8x, x_in, hx\u27e9,\n    exact cInf_lt_of_lt h x_in hx }\nend\n\nlemma le_Sup_iff {s : set \u211d} (h : bdd_above s) (h' : s.nonempty) {a : \u211d} :\n  a \u2264 Sup s \u2194 \u2200 \u03b5, \u03b5 < 0 \u2192 \u2203 x \u2208 s, a + \u03b5 < x :=\nbegin\n  rw le_iff_forall_pos_lt_add,\n  refine \u27e8\u03bb H \u03b5 \u03b5_neg, _, \u03bb H \u03b5 \u03b5_pos, _\u27e9,\n  { exact exists_lt_of_lt_cSup h' (lt_sub_iff_add_lt.mp (H _ (neg_pos.mpr \u03b5_neg))) },\n  { rcases H _ (neg_lt_zero.mpr \u03b5_pos) with \u27e8x, x_in, hx\u27e9,\n    exact sub_lt_iff_lt_add.mp (lt_cSup_of_lt h x_in hx) }\nend\n\n@[simp] theorem Sup_empty : Sup (\u2205 : set \u211d) = 0 := dif_neg $ by simp\n\ntheorem Sup_of_not_bdd_above {s : set \u211d} (hs : \u00ac bdd_above s) : Sup s = 0 :=\ndif_neg $ assume h, hs h.2\n\ntheorem Sup_univ : Sup (@set.univ \u211d) = 0 :=\nreal.Sup_of_not_bdd_above $ \u03bb \u27e8x, h\u27e9, not_le_of_lt (lt_add_one _) $ h (set.mem_univ _)\n\n@[simp] theorem Inf_empty : Inf (\u2205 : set \u211d) = 0 :=\nby simp [Inf_def, Sup_empty]\n\ntheorem Inf_of_not_bdd_below {s : set \u211d} (hs : \u00ac bdd_below s) : Inf s = 0 :=\nneg_eq_zero.2 $ Sup_of_not_bdd_above $ mt bdd_above_neg.1 hs\n\n/--\nAs `0` is the default value for `real.Sup` of the empty set or sets which are not bounded above, it\nsuffices to show that `S` is bounded below by `0` to show that `0 \u2264 Inf S`.\n-/\nlemma Sup_nonneg (S : set \u211d) (hS : \u2200 x \u2208 S, (0:\u211d) \u2264 x) : 0 \u2264 Sup S :=\nbegin\n  rcases S.eq_empty_or_nonempty with rfl | \u27e8y, hy\u27e9,\n  { exact Sup_empty.ge },\n  { apply dite _ (\u03bb h, le_cSup_of_le h hy $ hS y hy) (\u03bb h, (Sup_of_not_bdd_above h).ge) }\nend\n\n/--\nAs `0` is the default value for `real.Sup` of the empty set, it suffices to show that `S` is\nbounded above by `0` to show that `Sup S \u2264 0`.\n-/\nlemma Sup_nonpos (S : set \u211d) (hS : \u2200 x \u2208 S, x \u2264 (0:\u211d)) : Sup S \u2264 0 :=\nbegin\n  rcases S.eq_empty_or_nonempty with rfl | hS\u2082,\n  exacts [Sup_empty.le, cSup_le hS\u2082 hS],\nend\n\n/--\nAs `0` is the default value for `real.Inf` of the empty set, it suffices to show that `S` is\nbounded below by `0` to show that `0 \u2264 Inf S`.\n-/\nlemma Inf_nonneg (S : set \u211d) (hS : \u2200 x \u2208 S, (0:\u211d) \u2264 x) : 0 \u2264 Inf S :=\nbegin\n  rcases S.eq_empty_or_nonempty with rfl | hS\u2082,\n  exacts [Inf_empty.ge, le_cInf hS\u2082 hS]\nend\n\n/--\nAs `0` is the default value for `real.Inf` of the empty set or sets which are not bounded below, it\nsuffices to show that `S` is bounded above by `0` to show that `Inf S \u2264 0`.\n-/\nlemma Inf_nonpos (S : set \u211d) (hS : \u2200 x \u2208 S, x \u2264 (0:\u211d)) : Inf S \u2264 0 :=\nbegin\n  rcases S.eq_empty_or_nonempty with rfl | \u27e8y, hy\u27e9,\n  { exact Inf_empty.le },\n  { apply dite _ (\u03bb h, cInf_le_of_le h hy $ hS y hy) (\u03bb h, (Inf_of_not_bdd_below h).le) }\nend\n\nlemma Inf_le_Sup (s : set \u211d) (h\u2081 : bdd_below s) (h\u2082 : bdd_above s) : Inf s \u2264 Sup s :=\nbegin\n  rcases s.eq_empty_or_nonempty with rfl | hne,\n  { rw [Inf_empty, Sup_empty] },\n  { exact cInf_le_cSup h\u2081 h\u2082 hne }\nend\n\ntheorem cau_seq_converges (f : cau_seq \u211d abs) : \u2203 x, f \u2248 const abs x :=\nbegin\n  let S := {x : \u211d | const abs x < f},\n  have lb : \u2203 x, x \u2208 S := exists_lt f,\n  have ub' : \u2200 x, f < const abs x \u2192 \u2200 y \u2208 S, y \u2264 x :=\n    \u03bb x h y yS, le_of_lt $ const_lt.1 $ cau_seq.lt_trans yS h,\n  have ub : \u2203 x, \u2200 y \u2208 S, y \u2264 x := (exists_gt f).imp ub',\n  refine \u27e8Sup S,\n    ((lt_total _ _).resolve_left (\u03bb h, _)).resolve_right (\u03bb h, _)\u27e9,\n  { rcases h with \u27e8\u03b5, \u03b50, i, ih\u27e9,\n    refine (cSup_le lb (ub' _ _)).not_lt (sub_lt_self _ (half_pos \u03b50)),\n    refine \u27e8_, half_pos \u03b50, i, \u03bb j ij, _\u27e9,\n    rw [sub_apply, const_apply, sub_right_comm,\n      le_sub_iff_add_le, add_halves],\n    exact ih _ ij },\n  { rcases h with \u27e8\u03b5, \u03b50, i, ih\u27e9,\n    refine (le_cSup ub _).not_lt ((lt_add_iff_pos_left _).2 (half_pos \u03b50)),\n    refine \u27e8_, half_pos \u03b50, i, \u03bb j ij, _\u27e9,\n    rw [sub_apply, const_apply, add_comm, \u2190 sub_sub,\n      le_sub_iff_add_le, add_halves],\n    exact ih _ ij }\nend\n\nnoncomputable instance : cau_seq.is_complete \u211d abs := \u27e8cau_seq_converges\u27e9\n\nend real\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/real/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7241817779096739}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_96\n  (x y z a : \u211d)\n  (h\u2080 : 0 < x \u2227 0 < y \u2227 0 < z \u2227 0 < a)\n  (h\u2081 : real.log x - real.log y = a)\n  (h\u2082 : real.log y - real.log z = 15)\n  (h\u2083 : real.log z - real.log x = -7) :\n  a = -8 :=\nbegin\n  nlinarith [h\u2081, h\u2082, h\u2083],\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p96.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7241522855528904}}
{"text": "variable A : Type\nvariable f : A -> A \nvariable P : A -> Prop \nvariable h : forall x, P x -> P(f x)\nvariable ht : forall x, P x\nexample : forall y, P y -> P (f (f y)) :=\nassume t,\nshow P t -> P (f (f t)), from\nhave h1 : P t -> P (f t), from h t,\nhave h2 : P (f t) -> P (f (f t)), from h (f t),\nassume h3 : P t,\nhave h4 : P (f t), from h1 h3,\nshow  P (f (f t)), from h2 h4\n", "meta": {"author": "ucmani", "repo": "leanexamples", "sha": "387daef46eaf61bd4a08db076f60ac237daff559", "save_path": "github-repos/lean/ucmani-leanexamples", "path": "github-repos/lean/ucmani-leanexamples/leanexamples-387daef46eaf61bd4a08db076f60ac237daff559/example9.5.1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7241522823498645}}
{"text": "section\n  variable A : Type\n  variable f : A \u2192 A\n  variable P : A \u2192 Prop\n  variable h : \u2200 x, P x \u2192 P (f x)\n\n-- Show the following:\n  example : \u2200 y, P y \u2192 P (f(f(y))):=\n  assume y : A,\n  assume py : P y,\n  have hpf : P y \u2192 P (f (y)), from h y,\n  have hpff : P (f(y)) \u2192 P (f (f(y))), from h (f(y)),\n  hpff (hpf (py)) \nend\n\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2200 x, A x \u2227 B x) \u2192 \u2200 x, A x :=  \n  assume h : (\u2200 x, A x \u2227 B x),\n  assume y,\n  show A y, from and.left (h y) \nend\n\nsection\n  variable U : Type\n  variables A B C : U \u2192 Prop\n  variable h1 : \u2200 x, A x \u2228 B x\n  variable h2 : \u2200 x, A x \u2192 C x\n  variable h3 : \u2200 x, B x \u2192 C x\n  \n  example : \u2200 x, C x :=\n  assume y,\n  or.elim (h1 y) \n    (assume ha : A y ,  (h2 y) ha)  \n    (assume hb : B y, (h3 y) hb)\nend\n\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n  example : (\u2203 x, A x) \u2192 \u2203 x, A x \u2228 B x :=\n  assume h,\n  exists.elim h \n    (assume y (h1 : A y),\n    show \u2203 x, A x \u2228 B x, from exists.intro y (or.inl h1))\nend\n\nsection \n  variable U : Type\n  variables A B C : U \u2192 Prop\n  \n  example : (\u00ac \u2203 x, A x) \u2192 \u2200 x, \u00ac A x :=\n  sorry\n\n  example : (\u2200 x, \u00ac A x) \u2192 \u00ac \u2203 x, A x :=\n  sorry\nend", "meta": {"author": "faustoUrtiz", "repo": "learning-leanprover", "sha": "3acddd0ffb952ce32b0135b8f49de5e930c9820a", "save_path": "github-repos/lean/faustoUrtiz-learning-leanprover", "path": "github-repos/lean/faustoUrtiz-learning-leanprover/learning-leanprover-3acddd0ffb952ce32b0135b8f49de5e930c9820a/fisrt-order-logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7241427732823206}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport data.fin\nimport data.fintype.basic\n/-!\n# The structure of `fintype (fin n)`\n\nThis file contains some basic results about the `fintype` instance for `fin`,\nespecially properties of `finset.univ : finset (fin n)`.\n-/\n\n\nopen finset\nopen fintype\n\nnamespace fin\n\n@[simp]\nlemma univ_filter_zero_lt {n : \u2115} :\n  (univ : finset (fin n.succ)).filter (\u03bb i, 0 < i) =\n    univ.map (fin.succ_embedding _).to_embedding :=\nbegin\n  ext i,\n  simp only [mem_filter, mem_map, mem_univ, true_and,\n  function.embedding.coe_fn_mk, exists_true_left],\n  split,\n  { refine cases _ _ i,\n    { rintro \u27e8\u27e8\u27e9\u27e9 },\n    { intros i _, exact \u27e8i, mem_univ _, rfl\u27e9 } },\n  { rintro \u27e8i, _, rfl\u27e9,\n    exact succ_pos _ },\nend\n\n@[simp]\nlemma univ_filter_succ_lt {n : \u2115} (j : fin n) :\n  (univ : finset (fin n.succ)).filter (\u03bb i, j.succ < i) =\n    (univ.filter (\u03bb i, j < i)).map (fin.succ_embedding _).to_embedding :=\nbegin\n  ext i,\n  simp only [mem_filter, mem_map, mem_univ, true_and,\n  function.embedding.coe_fn_mk, exists_true_left],\n  split,\n  { refine cases _ _ i,\n    { rintro \u27e8\u27e8\u27e9\u27e9 },\n    { intros i hi,\n      exact \u27e8i, mem_filter.mpr \u27e8mem_univ _, succ_lt_succ_iff.mp hi\u27e9, rfl\u27e9 } },\n  { rintro \u27e8i, hi, rfl\u27e9,\n    exact succ_lt_succ_iff.mpr (mem_filter.mp hi).2 },\nend\n\nend fin\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/fintype/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7241353262271187}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\n\nimport data.int.basic data.nat.modeq\n\nnamespace int\n\ndef modeq (n a b : \u2124) := a % n = b % n\n\nnotation a ` \u2261 `:50 b ` [ZMOD `:50 n `]`:0 := modeq n a b\n\nnamespace modeq\nvariables {n m a b c d : \u2124}\n\n@[refl] protected theorem refl (a : \u2124) : a \u2261 a [ZMOD n] := @rfl _ _\n\n@[symm] protected theorem symm : a \u2261 b [ZMOD n] \u2192 b \u2261 a [ZMOD n] := eq.symm\n\n@[trans] protected theorem trans : a \u2261 b [ZMOD n] \u2192 b \u2261 c [ZMOD n] \u2192 a \u2261 c [ZMOD n] := eq.trans\n\nlemma coe_nat_modeq_iff {a b n : \u2115} : a \u2261 b [ZMOD n] \u2194 a \u2261 b [MOD n] :=\nby unfold modeq nat.modeq; rw \u2190 int.coe_nat_eq_coe_nat_iff; simp [int.coe_nat_mod]\n\ninstance : decidable (a \u2261 b [ZMOD n]) := by unfold modeq; apply_instance\n\ntheorem modeq_zero_iff : a \u2261 0 [ZMOD n] \u2194 n \u2223 a :=\nby rw [modeq, zero_mod, dvd_iff_mod_eq_zero]\n\ntheorem modeq_iff_dvd : a \u2261 b [ZMOD n] \u2194 (n:\u2124) \u2223 b - a :=\nby rw [modeq, eq_comm];\n   simp [int.mod_eq_mod_iff_mod_sub_eq_zero, int.dvd_iff_mod_eq_zero]\n\ntheorem modeq_of_dvd_of_modeq (d : m \u2223 n) (h : a \u2261 b [ZMOD n]) : a \u2261 b [ZMOD m] :=\nmodeq_iff_dvd.2 $ dvd_trans d (modeq_iff_dvd.1 h)\n\ntheorem modeq_mul_left' (hc : 0 \u2264 c) (h : a \u2261 b [ZMOD n]) : c * a \u2261 c * b [ZMOD (c * n)] :=\nor.cases_on (lt_or_eq_of_le hc) (\u03bb hc,\n  by unfold modeq;\n  simp [mul_mod_mul_of_pos _ _ hc, (show _ = _, from h)] )\n(\u03bb hc, by simp [hc.symm])\n\ntheorem modeq_mul_right' (hc : 0 \u2264 c) (h : a \u2261 b [ZMOD n]) : a * c \u2261 b * c [ZMOD (n * c)] :=\nby rw [mul_comm a, mul_comm b, mul_comm n]; exact modeq_mul_left' hc h\n\ntheorem modeq_add (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : c \u2261 d [ZMOD n]) : a + c \u2261 b + d [ZMOD n] :=\nmodeq_iff_dvd.2 $ by simpa using dvd_add (modeq_iff_dvd.1 h\u2081) (modeq_iff_dvd.1 h\u2082)\n\ntheorem modeq_add_cancel_left (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : a + c \u2261 b + d [ZMOD n]) : c \u2261 d [ZMOD n] :=\nhave (n:\u2124) \u2223 a + (-a + (d + -c)),\nby simpa using dvd_sub (modeq_iff_dvd.1 h\u2082) (modeq_iff_dvd.1 h\u2081),\nmodeq_iff_dvd.2 $ by rwa add_neg_cancel_left at this\n\ntheorem modeq_add_cancel_right (h\u2081 : c \u2261 d [ZMOD n]) (h\u2082 : a + c \u2261 b + d [ZMOD n]) : a \u2261 b [ZMOD n] :=\nby rw [add_comm a, add_comm b] at h\u2082; exact modeq_add_cancel_left h\u2081 h\u2082\n\ntheorem modeq_neg (h : a \u2261 b [ZMOD n]) : -a \u2261 -b [ZMOD n] :=\nmodeq_add_cancel_left h (by simp)\n\ntheorem modeq_sub (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : c \u2261 d [ZMOD n]) : a - c \u2261 b - d [ZMOD n] :=\nby rw [sub_eq_add_neg, sub_eq_add_neg]; exact modeq_add h\u2081 (modeq_neg h\u2082)\n\ntheorem modeq_mul_left (c : \u2124) (h : a \u2261 b [ZMOD n]) : c * a \u2261 c * b [ZMOD n] :=\nor.cases_on (le_total 0 c)\n(\u03bb hc, modeq_of_dvd_of_modeq (dvd_mul_left _ _) (modeq_mul_left' hc h))\n(\u03bb hc, by rw [\u2190 neg_neg c, \u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul _ b];\n    exact modeq_neg (modeq_of_dvd_of_modeq (dvd_mul_left _ _)\n    (modeq_mul_left' (neg_nonneg.2 hc) h)))\n\ntheorem modeq_mul_right (c : \u2124) (h : a \u2261 b [ZMOD n]) : a * c \u2261 b * c [ZMOD n] :=\nby rw [mul_comm a, mul_comm b]; exact modeq_mul_left c h\n\ntheorem modeq_mul (h\u2081 : a \u2261 b [ZMOD n]) (h\u2082 : c \u2261 d [ZMOD n]) : a * c \u2261 b * d [ZMOD n] :=\n(modeq_mul_left _ h\u2082).trans (modeq_mul_right _ h\u2081)\n\nend modeq\nend int\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/int/modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.72413532469377}}
{"text": "/-\nCopyright (c) 2020 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n-/\nimport data.set.finite\n\n/-!\n# Infinitude of intervals\n\nBounded intervals in dense orders are infinite, as are unbounded intervals\nin orders that are unbounded on the appropriate side. We also prove that an unbounded\npreorder is an infinite type.\n-/\n\nvariables {\u03b1 : Type*} [preorder \u03b1]\n\n/-- A nonempty preorder with no maximal element is infinite. This is not an instance to avoid\na cycle with `infinite \u03b1 \u2192 nontrivial \u03b1 \u2192 nonempty \u03b1`. -/\nlemma no_max_order.infinite [nonempty \u03b1] [no_max_order \u03b1] : infinite \u03b1 :=\nlet \u27e8f, hf\u27e9 := nat.exists_strict_mono \u03b1 in infinite.of_injective f hf.injective\n\n/-- A nonempty preorder with no minimal element is infinite. This is not an instance to avoid\na cycle with `infinite \u03b1 \u2192 nontrivial \u03b1 \u2192 nonempty \u03b1`. -/\nlemma no_min_order.infinite [nonempty \u03b1] [no_min_order \u03b1] : infinite \u03b1 :=\n@no_max_order.infinite \u03b1\u1d52\u1d48 _ _ _\n\nnamespace set\n\nsection densely_ordered\n\nvariables [densely_ordered \u03b1] {a b : \u03b1} (h : a < b)\n\nlemma Ioo.infinite : infinite (Ioo a b) := @no_max_order.infinite _ _ (nonempty_Ioo_subtype h) _\nlemma Ioo_infinite : (Ioo a b).infinite := infinite_coe_iff.1 $ Ioo.infinite h\n\nlemma Ico_infinite : (Ico a b).infinite := (Ioo_infinite h).mono Ioo_subset_Ico_self\n\n\nlemma Ioc_infinite : (Ioc a b).infinite := (Ioo_infinite h).mono Ioo_subset_Ioc_self\nlemma Ioc.infinite : infinite (Ioc a b) := infinite_coe_iff.2 $ Ioc_infinite h\n\nlemma Icc_infinite : (Icc a b).infinite := (Ioo_infinite h).mono Ioo_subset_Icc_self\nlemma Icc.infinite : infinite (Icc a b) := infinite_coe_iff.2 $ Icc_infinite h\n\nend densely_ordered\n\ninstance [no_min_order \u03b1] {a : \u03b1} : infinite (Iio a) := no_min_order.infinite\nlemma Iio_infinite [no_min_order \u03b1] (a : \u03b1) : (Iio a).infinite := infinite_coe_iff.1 Iio.infinite\n\ninstance [no_min_order \u03b1] {a : \u03b1} : infinite (Iic a) := no_min_order.infinite\nlemma Iic_infinite [no_min_order \u03b1] (a : \u03b1) : (Iic a).infinite := infinite_coe_iff.1 Iic.infinite\n\ninstance [no_max_order \u03b1] {a : \u03b1} : infinite (Ioi a) := no_max_order.infinite\nlemma Ioi_infinite [no_min_order \u03b1] (a : \u03b1) : (Iio a).infinite := infinite_coe_iff.1 Iio.infinite\n\ninstance [no_max_order \u03b1] {a : \u03b1} : infinite (Ici a) := no_max_order.infinite\nlemma Ici_infinite [no_max_order \u03b1] (a : \u03b1) : (Ici a).infinite := infinite_coe_iff.1 Ici.infinite\n\nend set\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/set/intervals/infinite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571774, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7241353230535076}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport data.set.intervals.basic\n\n/-!\n\n# Upper / lower bounds\n\nIn this file we define:\n\n* `upper_bounds`, `lower_bounds` : the set of upper bounds (resp., lower bounds) of a set;\n* `bdd_above s`, `bdd_below s` : the set `s` is bounded above (resp., below), i.e., the set of upper\n  (resp., lower) bounds of `s` is nonempty;\n* `is_least s a`, `is_greatest s a` : `a` is a least (resp., greatest) element of `s`;\n  for a partial order, it is unique if exists;\n* `is_lub s a`, `is_glb s a` : `a` is a least upper bound (resp., a greatest lower bound)\n  of `s`; for a partial order, it is unique if exists.\n\nWe also prove various lemmas about monotonicity, behaviour under `\u222a`, `\u2229`, `insert`, and provide\nformulas for `\u2205`, `univ`, and intervals.\n-/\n\nopen function set order_dual (to_dual of_dual)\n\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x}\n\nsection\nvariables [preorder \u03b1] [preorder \u03b2] {s t : set \u03b1} {a b : \u03b1}\n\n/-!\n### Definitions\n-/\n\n/-- The set of upper bounds of a set. -/\ndef upper_bounds (s : set \u03b1) : set \u03b1 := { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 a \u2264 x }\n/-- The set of lower bounds of a set. -/\ndef lower_bounds (s : set \u03b1) : set \u03b1 := { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 x \u2264 a }\n\n/-- A set is bounded above if there exists an upper bound. -/\ndef bdd_above (s : set \u03b1) := (upper_bounds s).nonempty\n/-- A set is bounded below if there exists a lower bound. -/\ndef bdd_below (s : set \u03b1) := (lower_bounds s).nonempty\n\n/-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/\ndef is_least (s : set \u03b1) (a : \u03b1) : Prop := a \u2208 s \u2227 a \u2208 lower_bounds s\n/-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists -/\ndef is_greatest (s : set \u03b1) (a : \u03b1) : Prop := a \u2208 s \u2227 a \u2208 upper_bounds s\n\n/-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/\ndef is_lub (s : set \u03b1) : \u03b1 \u2192 Prop := is_least (upper_bounds s)\n/-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/\ndef is_glb (s : set \u03b1) : \u03b1 \u2192 Prop := is_greatest (lower_bounds s)\n\nlemma mem_upper_bounds : a \u2208 upper_bounds s \u2194 \u2200 x \u2208 s, x \u2264 a := iff.rfl\nlemma mem_lower_bounds : a \u2208 lower_bounds s \u2194 \u2200 x \u2208 s, a \u2264 x := iff.rfl\n\nlemma bdd_above_def : bdd_above s \u2194 \u2203 x, \u2200 y \u2208 s, y \u2264 x := iff.rfl\nlemma bdd_below_def : bdd_below s \u2194 \u2203 x, \u2200 y \u2208 s, x \u2264 y := iff.rfl\n\nlemma bot_mem_lower_bounds [order_bot \u03b1] (s : set \u03b1) : \u22a5 \u2208 lower_bounds s := \u03bb _ _, bot_le\nlemma top_mem_upper_bounds [order_top \u03b1] (s : set \u03b1) : \u22a4 \u2208 upper_bounds s := \u03bb _ _, le_top\n\n@[simp] lemma is_least_bot_iff [order_bot \u03b1] : is_least s \u22a5 \u2194 \u22a5 \u2208 s :=\nand_iff_left $ bot_mem_lower_bounds _\n\n@[simp] lemma is_greatest_top_iff [order_top \u03b1] : is_greatest s \u22a4 \u2194 \u22a4 \u2208 s :=\nand_iff_left $ top_mem_upper_bounds _\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not greater than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(y \u2264 x)`. A version for linear orders is called `not_bdd_above_iff`. -/\nlemma not_bdd_above_iff' : \u00acbdd_above s \u2194 \u2200 x, \u2203 y \u2208 s, \u00ac(y \u2264 x) :=\nby simp [bdd_above, upper_bounds, set.nonempty]\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not less than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(x \u2264 y)`. A version for linear orders is called `not_bdd_below_iff`. -/\nlemma not_bdd_below_iff' : \u00acbdd_below s \u2194 \u2200 x, \u2203 y \u2208 s, \u00ac x \u2264 y := @not_bdd_above_iff' \u03b1\u1d52\u1d48 _ _\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` that is greater\nthan `x`. A version for preorders is called `not_bdd_above_iff'`. -/\nlemma not_bdd_above_iff {\u03b1 : Type*} [linear_order \u03b1] {s : set \u03b1} :\n  \u00acbdd_above s \u2194 \u2200 x, \u2203 y \u2208 s, x < y :=\nby simp only [not_bdd_above_iff', not_le]\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` that is less\nthan `x`. A version for preorders is called `not_bdd_below_iff'`. -/\nlemma not_bdd_below_iff {\u03b1 : Type*} [linear_order \u03b1] {s : set \u03b1} :\n  \u00acbdd_below s \u2194 \u2200 x, \u2203 y \u2208 s, y < x :=\n@not_bdd_above_iff \u03b1\u1d52\u1d48 _ _\n\nlemma bdd_above.dual (h : bdd_above s) : bdd_below (of_dual \u207b\u00b9' s) := h\n\nlemma bdd_below.dual (h : bdd_below s) : bdd_above (of_dual \u207b\u00b9' s) := h\n\nlemma is_least.dual (h : is_least s a) : is_greatest (of_dual \u207b\u00b9' s) (to_dual a) := h\n\nlemma is_greatest.dual (h : is_greatest s a) : is_least (of_dual \u207b\u00b9' s) (to_dual a) := h\n\nlemma is_lub.dual (h : is_lub s a) : is_glb (of_dual \u207b\u00b9' s) (to_dual a) := h\n\nlemma is_glb.dual (h : is_glb s a) : is_lub (of_dual \u207b\u00b9' s) (to_dual a) := h\n\n/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/\n@[reducible] def is_least.order_bot (h : is_least s a) : order_bot s :=\n{ bot := \u27e8a, h.1\u27e9,\n  bot_le := subtype.forall.2 h.2 }\n\n/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/\n@[reducible] def is_greatest.order_top (h : is_greatest s a) : order_top s :=\n{ top := \u27e8a, h.1\u27e9,\n  le_top := subtype.forall.2 h.2 }\n\n/-!\n### Monotonicity\n-/\n\nlemma upper_bounds_mono_set \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) :\n  upper_bounds t \u2286 upper_bounds s :=\n\u03bb b hb x h, hb $ hst h\n\nlemma lower_bounds_mono_set \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) :\n  lower_bounds t \u2286 lower_bounds s :=\n\u03bb b hb x h, hb $ hst h\n\nlemma upper_bounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : a \u2208 upper_bounds s \u2192 b \u2208 upper_bounds s :=\n\u03bb ha x h, le_trans (ha h) hab\n\nlemma lower_bounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : b \u2208 lower_bounds s \u2192 a \u2208 lower_bounds s :=\n\u03bb hb x h, le_trans hab (hb h)\n\nlemma upper_bounds_mono \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n  a \u2208 upper_bounds t \u2192 b \u2208 upper_bounds s :=\n\u03bb ha, upper_bounds_mono_set hst $ upper_bounds_mono_mem hab ha\n\nlemma lower_bounds_mono \u2983s t : set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n  b \u2208 lower_bounds t \u2192 a \u2208 lower_bounds s :=\n\u03bb hb, lower_bounds_mono_set hst $ lower_bounds_mono_mem hab hb\n\n/-- If `s \u2286 t` and `t` is bounded above, then so is `s`. -/\nlemma bdd_above.mono \u2983s t : set \u03b1\u2984 (h : s \u2286 t) : bdd_above t \u2192 bdd_above s :=\nnonempty.mono $ upper_bounds_mono_set h\n\n/-- If `s \u2286 t` and `t` is bounded below, then so is `s`. -/\nlemma bdd_below.mono \u2983s t : set \u03b1\u2984 (h : s \u2286 t) : bdd_below t \u2192 bdd_below s :=\nnonempty.mono $ lower_bounds_mono_set h\n\n/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\nlemma is_lub.of_subset_of_superset {s t p : set \u03b1} (hs : is_lub s a) (hp : is_lub p a)\n  (hst : s \u2286 t) (htp : t \u2286 p) : is_lub t a :=\n\u27e8upper_bounds_mono_set htp hp.1, lower_bounds_mono_set (upper_bounds_mono_set hst) hs.2\u27e9\n\n/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\nlemma is_glb.of_subset_of_superset {s t p : set \u03b1} (hs : is_glb s a) (hp : is_glb p a)\n  (hst : s \u2286 t) (htp : t \u2286 p) : is_glb t a :=\nhs.dual.of_subset_of_superset hp hst htp\n\nlemma is_least.mono (ha : is_least s a) (hb : is_least t b) (hst : s \u2286 t) : b \u2264 a :=\nhb.2 (hst ha.1)\n\nlemma is_greatest.mono (ha : is_greatest s a) (hb : is_greatest t b) (hst : s \u2286 t) : a \u2264 b :=\nhb.2 (hst ha.1)\n\nlemma is_lub.mono (ha : is_lub s a) (hb : is_lub t b) (hst : s \u2286 t) : a \u2264 b :=\nhb.mono ha $ upper_bounds_mono_set hst\n\nlemma is_glb.mono (ha : is_glb s a) (hb : is_glb t b) (hst : s \u2286 t) : b \u2264 a :=\nhb.mono ha $ lower_bounds_mono_set hst\n\nlemma subset_lower_bounds_upper_bounds (s : set \u03b1) : s \u2286 lower_bounds (upper_bounds s) :=\n\u03bb x hx y hy, hy hx\n\nlemma subset_upper_bounds_lower_bounds (s : set \u03b1) : s \u2286 upper_bounds (lower_bounds s) :=\n\u03bb x hx y hy, hy hx\n\nlemma set.nonempty.bdd_above_lower_bounds (hs : s.nonempty) : bdd_above (lower_bounds s) :=\nhs.mono (subset_upper_bounds_lower_bounds s)\n\nlemma set.nonempty.bdd_below_upper_bounds (hs : s.nonempty) : bdd_below (upper_bounds s) :=\nhs.mono (subset_lower_bounds_upper_bounds s)\n\n/-!\n### Conversions\n-/\n\nlemma is_least.is_glb (h : is_least s a) : is_glb s a := \u27e8h.2, \u03bb b hb, hb h.1\u27e9\n\nlemma is_greatest.is_lub (h : is_greatest s a) : is_lub s a := \u27e8h.2, \u03bb b hb, hb h.1\u27e9\n\nlemma is_lub.upper_bounds_eq (h : is_lub s a) : upper_bounds s = Ici a :=\nset.ext $ \u03bb b, \u27e8\u03bb hb, h.2 hb, \u03bb hb, upper_bounds_mono_mem hb h.1\u27e9\n\nlemma is_glb.lower_bounds_eq (h : is_glb s a) : lower_bounds s = Iic a := h.dual.upper_bounds_eq\n\nlemma is_least.lower_bounds_eq (h : is_least s a) : lower_bounds s = Iic a :=\nh.is_glb.lower_bounds_eq\n\nlemma is_greatest.upper_bounds_eq (h : is_greatest s a) : upper_bounds s = Ici a :=\nh.is_lub.upper_bounds_eq\n\nlemma is_lub_le_iff (h : is_lub s a) : a \u2264 b \u2194 b \u2208 upper_bounds s :=\nby { rw h.upper_bounds_eq, refl }\n\nlemma le_is_glb_iff (h : is_glb s a) : b \u2264 a \u2194 b \u2208 lower_bounds s :=\nby { rw h.lower_bounds_eq, refl }\n\nlemma is_lub_iff_le_iff : is_lub s a \u2194 \u2200 b, a \u2264 b \u2194 b \u2208 upper_bounds s :=\n\u27e8\u03bb h b, is_lub_le_iff h, \u03bb H, \u27e8(H _).1 le_rfl, \u03bb b hb, (H b).2 hb\u27e9\u27e9\n\nlemma is_glb_iff_le_iff : is_glb s a \u2194 \u2200 b, b \u2264 a \u2194 b \u2208 lower_bounds s :=\n@is_lub_iff_le_iff \u03b1\u1d52\u1d48 _ _ _\n\n/-- If `s` has a least upper bound, then it is bounded above. -/\nlemma is_lub.bdd_above (h : is_lub s a) : bdd_above s := \u27e8a, h.1\u27e9\n\n/-- If `s` has a greatest lower bound, then it is bounded below. -/\nlemma is_glb.bdd_below (h : is_glb s a) : bdd_below s := \u27e8a, h.1\u27e9\n\n/-- If `s` has a greatest element, then it is bounded above. -/\nlemma is_greatest.bdd_above (h : is_greatest s a) : bdd_above s := \u27e8a, h.2\u27e9\n\n/-- If `s` has a least element, then it is bounded below. -/\nlemma is_least.bdd_below (h : is_least s a) : bdd_below s := \u27e8a, h.2\u27e9\n\nlemma is_least.nonempty (h : is_least s a) : s.nonempty := \u27e8a, h.1\u27e9\n\nlemma is_greatest.nonempty (h : is_greatest s a) : s.nonempty := \u27e8a, h.1\u27e9\n\n/-!\n### Union and intersection\n-/\n\n@[simp] lemma upper_bounds_union : upper_bounds (s \u222a t) = upper_bounds s \u2229 upper_bounds t :=\nsubset.antisymm\n  (\u03bb b hb, \u27e8\u03bb x hx, hb (or.inl hx), \u03bb x hx, hb (or.inr hx)\u27e9)\n  (\u03bb b hb x hx, hx.elim (\u03bb hs, hb.1 hs) (\u03bb ht, hb.2 ht))\n\n@[simp] lemma lower_bounds_union : lower_bounds (s \u222a t) = lower_bounds s \u2229 lower_bounds t :=\n@upper_bounds_union \u03b1\u1d52\u1d48 _ s t\n\nlemma union_upper_bounds_subset_upper_bounds_inter :\n  upper_bounds s \u222a upper_bounds t \u2286 upper_bounds (s \u2229 t) :=\nunion_subset\n  (upper_bounds_mono_set $ inter_subset_left _ _)\n  (upper_bounds_mono_set $ inter_subset_right _ _)\n\nlemma union_lower_bounds_subset_lower_bounds_inter :\n  lower_bounds s \u222a lower_bounds t \u2286 lower_bounds (s \u2229 t) :=\n@union_upper_bounds_subset_upper_bounds_inter \u03b1\u1d52\u1d48 _ s t\n\nlemma is_least_union_iff {a : \u03b1} {s t : set \u03b1} :\n  is_least (s \u222a t) a \u2194 (is_least s a \u2227 a \u2208 lower_bounds t \u2228 a \u2208 lower_bounds s \u2227 is_least t a) :=\nby simp [is_least, lower_bounds_union, or_and_distrib_right, and_comm (a \u2208 t), and_assoc]\n\nlemma is_greatest_union_iff :\n  is_greatest (s \u222a t) a \u2194 (is_greatest s a \u2227 a \u2208 upper_bounds t \u2228\n    a \u2208 upper_bounds s \u2227 is_greatest t a) :=\n@is_least_union_iff \u03b1\u1d52\u1d48 _ a s t\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\nlemma bdd_above.inter_of_left (h : bdd_above s) : bdd_above (s \u2229 t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\nlemma bdd_above.inter_of_right (h : bdd_above t) : bdd_above (s \u2229 t) :=\nh.mono $ inter_subset_right s t\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\nlemma bdd_below.inter_of_left (h : bdd_below s) : bdd_below (s \u2229 t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\nlemma bdd_below.inter_of_right (h : bdd_below t) : bdd_below (s \u2229 t) :=\nh.mono $ inter_subset_right s t\n\n/-- If `s` and `t` are bounded above sets in a `semilattice_sup`, then so is `s \u222a t`. -/\nlemma bdd_above.union [semilattice_sup \u03b3] {s t : set \u03b3} :\n  bdd_above s \u2192 bdd_above t \u2192 bdd_above (s \u222a t) :=\nbegin\n  rintros \u27e8bs, hs\u27e9 \u27e8bt, ht\u27e9,\n  use bs \u2294 bt,\n  rw upper_bounds_union,\n  exact \u27e8upper_bounds_mono_mem le_sup_left hs,\n    upper_bounds_mono_mem le_sup_right ht\u27e9\nend\n\n/-- The union of two sets is bounded above if and only if each of the sets is. -/\nlemma bdd_above_union [semilattice_sup \u03b3] {s t : set \u03b3} :\n  bdd_above (s \u222a t) \u2194 bdd_above s \u2227 bdd_above t :=\n\u27e8\u03bb h, \u27e8h.mono $ subset_union_left s t, h.mono $ subset_union_right s t\u27e9,\n  \u03bb h, h.1.union h.2\u27e9\n\nlemma bdd_below.union [semilattice_inf \u03b3] {s t : set \u03b3} :\n  bdd_below s \u2192 bdd_below t \u2192 bdd_below (s \u222a t) :=\n@bdd_above.union \u03b3\u1d52\u1d48 _ s t\n\n/--The union of two sets is bounded above if and only if each of the sets is.-/\nlemma bdd_below_union [semilattice_inf \u03b3] {s t : set \u03b3} :\n  bdd_below (s \u222a t) \u2194 bdd_below s \u2227 bdd_below t :=\n@bdd_above_union \u03b3\u1d52\u1d48 _ s t\n\n/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,\nthen `a \u2294 b` is the least upper bound of `s \u222a t`. -/\nlemma is_lub.union [semilattice_sup \u03b3] {a b : \u03b3} {s t : set \u03b3}\n  (hs : is_lub s a) (ht : is_lub t b) :\n  is_lub (s \u222a t) (a \u2294 b) :=\n\u27e8\u03bb c h, h.cases_on (\u03bb h, le_sup_of_le_left $ hs.left h) (\u03bb h, le_sup_of_le_right $ ht.left h),\n  \u03bb c hc, sup_le (hs.right $ \u03bb d hd, hc $ or.inl hd) (ht.right $ \u03bb d hd, hc $ or.inr hd)\u27e9\n\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a \u2293 b` is the greatest lower bound of `s \u222a t`. -/\nlemma is_glb.union [semilattice_inf \u03b3] {a\u2081 a\u2082 : \u03b3} {s t : set \u03b3}\n  (hs : is_glb s a\u2081) (ht : is_glb t a\u2082) :\n  is_glb (s \u222a t) (a\u2081 \u2293 a\u2082) :=\nhs.dual.union ht\n\n/-- If `a` is the least element of `s` and `b` is the least element of `t`,\nthen `min a b` is the least element of `s \u222a t`. -/\nlemma is_least.union [linear_order \u03b3] {a b : \u03b3} {s t : set \u03b3}\n  (ha : is_least s a) (hb : is_least t b) : is_least (s \u222a t) (min a b) :=\n\u27e8by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_glb.union hb.is_glb).1\u27e9\n\n/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,\nthen `max a b` is the greatest element of `s \u222a t`. -/\nlemma is_greatest.union [linear_order \u03b3] {a b : \u03b3} {s t : set \u03b3}\n  (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (s \u222a t) (max a b) :=\n\u27e8by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_lub.union hb.is_lub).1\u27e9\n\nlemma is_lub.inter_Ici_of_mem [linear_order \u03b3] {s : set \u03b3} {a b : \u03b3} (ha : is_lub s a)\n  (hb : b \u2208 s) : is_lub (s \u2229 Ici b) a :=\n\u27e8\u03bb x hx, ha.1 hx.1, \u03bb c hc, have hbc : b \u2264 c, from hc \u27e8hb, le_rfl\u27e9,\n  ha.2 $ \u03bb x hx, (le_total x b).elim (\u03bb hxb, hxb.trans hbc) $ \u03bb hbx, hc \u27e8hx, hbx\u27e9\u27e9\n\nlemma is_glb.inter_Iic_of_mem [linear_order \u03b3] {s : set \u03b3} {a b : \u03b3} (ha : is_glb s a)\n  (hb : b \u2208 s) : is_glb (s \u2229 Iic b) a :=\nha.dual.inter_Ici_of_mem hb\n\nlemma bdd_above_iff_exists_ge [semilattice_sup \u03b3] {s : set \u03b3} (x\u2080 : \u03b3) :\n  bdd_above s \u2194 \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x :=\nby { rw [bdd_above_def, exists_ge_and_iff_exists], exact monotone.ball (\u03bb x hx, monotone_le) }\n\nlemma bdd_below_iff_exists_le [semilattice_inf \u03b3] {s : set \u03b3} (x\u2080 : \u03b3) :\n  bdd_below s \u2194 \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\nbdd_above_iff_exists_ge (to_dual x\u2080)\n\nlemma bdd_above.exists_ge  [semilattice_sup \u03b3] {s : set \u03b3} (hs : bdd_above s) (x\u2080 : \u03b3) :\n  \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x :=\n(bdd_above_iff_exists_ge x\u2080).mp hs\n\nlemma bdd_below.exists_le  [semilattice_inf \u03b3] {s : set \u03b3} (hs : bdd_below s) (x\u2080 : \u03b3) :\n  \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\n(bdd_below_iff_exists_le x\u2080).mp hs\n\n/-!\n### Specific sets\n\n#### Unbounded intervals\n-/\n\nlemma is_least_Ici : is_least (Ici a) a := \u27e8left_mem_Ici, \u03bb x, id\u27e9\n\nlemma is_greatest_Iic : is_greatest (Iic a) a := \u27e8right_mem_Iic, \u03bb x, id\u27e9\n\nlemma is_lub_Iic : is_lub (Iic a) a := is_greatest_Iic.is_lub\n\nlemma is_glb_Ici : is_glb (Ici a) a := is_least_Ici.is_glb\n\nlemma upper_bounds_Iic : upper_bounds (Iic a) = Ici a := is_lub_Iic.upper_bounds_eq\n\nlemma lower_bounds_Ici : lower_bounds (Ici a) = Iic a := is_glb_Ici.lower_bounds_eq\n\nlemma bdd_above_Iic : bdd_above (Iic a) := is_lub_Iic.bdd_above\n\nlemma bdd_below_Ici : bdd_below (Ici a) := is_glb_Ici.bdd_below\n\nlemma bdd_above_Iio : bdd_above (Iio a) := \u27e8a, \u03bb x hx, le_of_lt hx\u27e9\n\nlemma bdd_below_Ioi : bdd_below (Ioi a) := \u27e8a, \u03bb x hx, le_of_lt hx\u27e9\n\nlemma lub_Iio_le (a : \u03b1) (hb : is_lub (set.Iio a) b) : b \u2264 a :=\n(is_lub_le_iff hb).mpr $ \u03bb k hk, le_of_lt hk\n\nlemma le_glb_Ioi (a : \u03b1) (hb : is_glb (set.Ioi a) b) : a \u2264 b := @lub_Iio_le \u03b1\u1d52\u1d48 _ _ a hb\n\nlemma lub_Iio_eq_self_or_Iio_eq_Iic [partial_order \u03b3] {j : \u03b3} (i : \u03b3) (hj : is_lub (set.Iio i) j) :\n  j = i \u2228 set.Iio i = set.Iic j :=\nbegin\n  cases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i,\n  { exact or.inl hj_eq_i, },\n  { right,\n    exact set.ext (\u03bb k, \u27e8\u03bb hk_lt, hj.1 hk_lt, \u03bb hk_le_j, lt_of_le_of_lt hk_le_j hj_lt_i\u27e9), },\nend\n\nlemma glb_Ioi_eq_self_or_Ioi_eq_Ici [partial_order \u03b3] {j : \u03b3} (i : \u03b3) (hj : is_glb (set.Ioi i) j) :\n  j = i \u2228 set.Ioi i = set.Ici j :=\n@lub_Iio_eq_self_or_Iio_eq_Iic \u03b3\u1d52\u1d48 _ j i hj\n\nsection\n\nvariables [linear_order \u03b3]\n\nlemma exists_lub_Iio (i : \u03b3) : \u2203 j, is_lub (set.Iio i) j :=\nbegin\n  by_cases h_exists_lt : \u2203 j, j \u2208 upper_bounds (set.Iio i) \u2227 j < i,\n  { obtain \u27e8j, hj_ub, hj_lt_i\u27e9 := h_exists_lt,\n    exact \u27e8j, hj_ub, \u03bb k hk_ub, hk_ub hj_lt_i\u27e9, },\n  { refine \u27e8i, \u03bb j hj, le_of_lt hj, _\u27e9,\n    rw mem_lower_bounds,\n    by_contra,\n    refine h_exists_lt _,\n    push_neg at h,\n    exact h, },\nend\n\nlemma exists_glb_Ioi (i : \u03b3) : \u2203 j, is_glb (set.Ioi i) j := @exists_lub_Iio \u03b3\u1d52\u1d48 _ i\n\nvariables [densely_ordered \u03b3]\n\nlemma is_lub_Iio {a : \u03b3} : is_lub (Iio a) a :=\n\u27e8\u03bb x hx, le_of_lt hx, \u03bb y hy, le_of_forall_ge_of_dense hy\u27e9\n\nlemma is_glb_Ioi {a : \u03b3} : is_glb (Ioi a) a := @is_lub_Iio \u03b3\u1d52\u1d48 _ _ a\n\nlemma upper_bounds_Iio {a : \u03b3} : upper_bounds (Iio a) = Ici a := is_lub_Iio.upper_bounds_eq\n\nlemma lower_bounds_Ioi {a : \u03b3} : lower_bounds (Ioi a) = Iic a := is_glb_Ioi.lower_bounds_eq\n\nend\n\n/-!\n#### Singleton\n-/\n\nlemma is_greatest_singleton : is_greatest {a} a :=\n\u27e8mem_singleton a, \u03bb x hx, le_of_eq $ eq_of_mem_singleton hx\u27e9\n\nlemma is_least_singleton : is_least {a} a := @is_greatest_singleton \u03b1\u1d52\u1d48 _ a\n\nlemma is_lub_singleton : is_lub {a} a := is_greatest_singleton.is_lub\n\nlemma is_glb_singleton : is_glb {a} a := is_least_singleton.is_glb\n\nlemma bdd_above_singleton : bdd_above ({a} : set \u03b1) := is_lub_singleton.bdd_above\n\nlemma bdd_below_singleton : bdd_below ({a} : set \u03b1) := is_glb_singleton.bdd_below\n\n@[simp] lemma upper_bounds_singleton : upper_bounds {a} = Ici a := is_lub_singleton.upper_bounds_eq\n\n@[simp] lemma lower_bounds_singleton : lower_bounds {a} = Iic a := is_glb_singleton.lower_bounds_eq\n\n/-!\n#### Bounded intervals\n-/\n\nlemma bdd_above_Icc : bdd_above (Icc a b) := \u27e8b, \u03bb _, and.right\u27e9\n\nlemma bdd_below_Icc : bdd_below (Icc a b) := \u27e8a, \u03bb _, and.left\u27e9\n\nlemma bdd_above_Ico : bdd_above (Ico a b) := bdd_above_Icc.mono Ico_subset_Icc_self\n\nlemma bdd_below_Ico : bdd_below (Ico a b) := bdd_below_Icc.mono Ico_subset_Icc_self\n\nlemma bdd_above_Ioc : bdd_above (Ioc a b) := bdd_above_Icc.mono Ioc_subset_Icc_self\n\nlemma bdd_below_Ioc : bdd_below (Ioc a b) := bdd_below_Icc.mono Ioc_subset_Icc_self\n\nlemma bdd_above_Ioo : bdd_above (Ioo a b) := bdd_above_Icc.mono Ioo_subset_Icc_self\n\nlemma bdd_below_Ioo : bdd_below (Ioo a b) := bdd_below_Icc.mono Ioo_subset_Icc_self\n\nlemma is_greatest_Icc (h : a \u2264 b) : is_greatest (Icc a b) b :=\n\u27e8right_mem_Icc.2 h, \u03bb x, and.right\u27e9\n\nlemma is_lub_Icc (h : a \u2264 b) : is_lub (Icc a b) b := (is_greatest_Icc h).is_lub\n\nlemma upper_bounds_Icc (h : a \u2264 b) : upper_bounds (Icc a b) = Ici b :=\n(is_lub_Icc h).upper_bounds_eq\n\nlemma is_least_Icc (h : a \u2264 b) : is_least (Icc a b) a :=\n\u27e8left_mem_Icc.2 h, \u03bb x, and.left\u27e9\n\nlemma is_glb_Icc (h : a \u2264 b) : is_glb (Icc a b) a := (is_least_Icc h).is_glb\n\nlemma lower_bounds_Icc (h : a \u2264 b) : lower_bounds (Icc a b) = Iic a :=\n(is_glb_Icc h).lower_bounds_eq\n\nlemma is_greatest_Ioc (h : a < b) : is_greatest (Ioc a b) b :=\n\u27e8right_mem_Ioc.2 h, \u03bb x, and.right\u27e9\n\nlemma is_lub_Ioc (h : a < b) : is_lub (Ioc a b) b :=\n(is_greatest_Ioc h).is_lub\n\nlemma upper_bounds_Ioc (h : a < b) : upper_bounds (Ioc a b) = Ici b :=\n(is_lub_Ioc h).upper_bounds_eq\n\nlemma is_least_Ico (h : a < b) : is_least (Ico a b) a :=\n\u27e8left_mem_Ico.2 h, \u03bb x, and.left\u27e9\n\nlemma is_glb_Ico (h : a < b) : is_glb (Ico a b) a :=\n(is_least_Ico h).is_glb\n\nlemma lower_bounds_Ico (h : a < b) : lower_bounds (Ico a b) = Iic a :=\n(is_glb_Ico h).lower_bounds_eq\n\nsection\n\nvariables [semilattice_sup \u03b3] [densely_ordered \u03b3]\n\nlemma is_glb_Ioo {a b : \u03b3} (h : a < b) :\n  is_glb (Ioo a b) a :=\n\u27e8\u03bb x hx, hx.1.le, \u03bb x hx,\nbegin\n  cases eq_or_lt_of_le (le_sup_right : a \u2264 x \u2294 a) with h\u2081 h\u2082,\n  { exact h\u2081.symm \u25b8 le_sup_left },\n  obtain \u27e8y, lty, ylt\u27e9 := exists_between h\u2082,\n  apply (not_lt_of_le (sup_le (hx \u27e8lty, ylt.trans_le (sup_le _ h.le)\u27e9) lty.le) ylt).elim,\n  obtain \u27e8u, au, ub\u27e9 := exists_between h,\n  apply (hx \u27e8au, ub\u27e9).trans ub.le,\nend\u27e9\n\nlemma lower_bounds_Ioo {a b : \u03b3} (hab : a < b) : lower_bounds (Ioo a b) = Iic a :=\n(is_glb_Ioo hab).lower_bounds_eq\n\nlemma is_glb_Ioc {a b : \u03b3} (hab : a < b) : is_glb (Ioc a b) a :=\n(is_glb_Ioo hab).of_subset_of_superset (is_glb_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self\n\nlemma lower_bound_Ioc {a b : \u03b3} (hab : a < b) : lower_bounds (Ioc a b) = Iic a :=\n(is_glb_Ioc hab).lower_bounds_eq\n\nend\n\nsection\n\nvariables [semilattice_inf \u03b3] [densely_ordered \u03b3]\n\nlemma is_lub_Ioo {a b : \u03b3} (hab : a < b) : is_lub (Ioo a b) b :=\nby simpa only [dual_Ioo] using is_glb_Ioo hab.dual\n\nlemma upper_bounds_Ioo {a b : \u03b3} (hab : a < b) : upper_bounds (Ioo a b) = Ici b :=\n(is_lub_Ioo hab).upper_bounds_eq\n\nlemma is_lub_Ico {a b : \u03b3} (hab : a < b) : is_lub (Ico a b) b :=\nby simpa only [dual_Ioc] using is_glb_Ioc hab.dual\n\nlemma upper_bounds_Ico {a b : \u03b3} (hab : a < b) : upper_bounds (Ico a b) = Ici b :=\n(is_lub_Ico hab).upper_bounds_eq\n\nend\n\nlemma bdd_below_iff_subset_Ici : bdd_below s \u2194 \u2203 a, s \u2286 Ici a := iff.rfl\n\nlemma bdd_above_iff_subset_Iic : bdd_above s \u2194 \u2203 a, s \u2286 Iic a := iff.rfl\n\nlemma bdd_below_bdd_above_iff_subset_Icc : bdd_below s \u2227 bdd_above s \u2194 \u2203 a b, s \u2286 Icc a b :=\nby simp only [Ici_inter_Iic.symm, subset_inter_iff, bdd_below_iff_subset_Ici,\n  bdd_above_iff_subset_Iic, exists_and_distrib_left, exists_and_distrib_right]\n\n/-!\n#### Univ\n-/\n\nlemma is_greatest_univ [preorder \u03b3] [order_top \u03b3] : is_greatest (univ : set \u03b3) \u22a4 :=\n\u27e8mem_univ _, \u03bb x hx, le_top\u27e9\n\n@[simp] lemma order_top.upper_bounds_univ [partial_order \u03b3] [order_top \u03b3] :\n  upper_bounds (univ : set \u03b3) = {\u22a4} :=\nby rw [is_greatest_univ.upper_bounds_eq, Ici_top]\n\nlemma is_lub_univ [preorder \u03b3] [order_top \u03b3] : is_lub (univ : set \u03b3) \u22a4 :=\nis_greatest_univ.is_lub\n\n@[simp] lemma order_bot.lower_bounds_univ [partial_order \u03b3] [order_bot \u03b3] :\n  lower_bounds (univ : set \u03b3) = {\u22a5} :=\n@order_top.upper_bounds_univ \u03b3\u1d52\u1d48 _ _\n\nlemma is_least_univ [preorder \u03b3] [order_bot \u03b3] : is_least (univ : set \u03b3) \u22a5 :=\n@is_greatest_univ \u03b3\u1d52\u1d48 _ _\n\nlemma is_glb_univ [preorder \u03b3] [order_bot \u03b3] : is_glb (univ : set \u03b3) \u22a5 :=\nis_least_univ.is_glb\n\n@[simp] lemma no_max_order.upper_bounds_univ [no_max_order \u03b1] : upper_bounds (univ : set \u03b1) = \u2205 :=\neq_empty_of_subset_empty $ \u03bb b hb, let \u27e8x, hx\u27e9 := exists_gt b in\nnot_le_of_lt hx (hb trivial)\n\n@[simp] lemma no_min_order.lower_bounds_univ [no_min_order \u03b1] : lower_bounds (univ : set \u03b1) = \u2205 :=\n@no_max_order.upper_bounds_univ \u03b1\u1d52\u1d48 _ _\n\n@[simp] lemma not_bdd_above_univ [no_max_order \u03b1] : \u00acbdd_above (univ : set \u03b1) :=\nby simp [bdd_above]\n\n@[simp] lemma not_bdd_below_univ [no_min_order \u03b1] : \u00acbdd_below (univ : set \u03b1) :=\n@not_bdd_above_univ \u03b1\u1d52\u1d48 _ _\n\n/-!\n#### Empty set\n-/\n\n@[simp] lemma upper_bounds_empty : upper_bounds (\u2205 : set \u03b1) = univ :=\nby simp only [upper_bounds, eq_univ_iff_forall, mem_set_of_eq, ball_empty_iff, forall_true_iff]\n\n@[simp] lemma lower_bounds_empty : lower_bounds (\u2205 : set \u03b1) = univ := @upper_bounds_empty \u03b1\u1d52\u1d48 _\n\n@[simp] lemma bdd_above_empty [nonempty \u03b1] : bdd_above (\u2205 : set \u03b1) :=\nby simp only [bdd_above, upper_bounds_empty, univ_nonempty]\n\n@[simp] lemma bdd_below_empty [nonempty \u03b1] : bdd_below (\u2205 : set \u03b1) :=\nby simp only [bdd_below, lower_bounds_empty, univ_nonempty]\n\nlemma is_glb_empty [preorder \u03b3] [order_top \u03b3] : is_glb \u2205 (\u22a4:\u03b3) :=\nby simp only [is_glb, lower_bounds_empty, is_greatest_univ]\n\nlemma is_lub_empty [preorder \u03b3] [order_bot \u03b3] : is_lub \u2205 (\u22a5:\u03b3) := @is_glb_empty \u03b3\u1d52\u1d48 _ _\n\nlemma is_lub.nonempty [no_min_order \u03b1] (hs : is_lub s a) : s.nonempty :=\nlet \u27e8a', ha'\u27e9 := exists_lt a in\nne_empty_iff_nonempty.1 $ \u03bb h, not_le_of_lt ha' $ hs.right $ by simp only [h, upper_bounds_empty]\n\nlemma is_glb.nonempty [no_max_order \u03b1] (hs : is_glb s a) : s.nonempty := hs.dual.nonempty\n\nlemma nonempty_of_not_bdd_above [ha : nonempty \u03b1] (h : \u00acbdd_above s) : s.nonempty :=\nnonempty.elim ha $ \u03bb x, (not_bdd_above_iff'.1 h x).imp $ \u03bb a ha, ha.fst\n\nlemma nonempty_of_not_bdd_below [ha : nonempty \u03b1] (h : \u00acbdd_below s) : s.nonempty :=\n@nonempty_of_not_bdd_above \u03b1\u1d52\u1d48 _ _ _ h\n\n/-!\n#### insert\n-/\n\n/-- Adding a point to a set preserves its boundedness above. -/\n@[simp] lemma bdd_above_insert [semilattice_sup \u03b3] (a : \u03b3) {s : set \u03b3} :\n  bdd_above (insert a s) \u2194 bdd_above s :=\nby simp only [insert_eq, bdd_above_union, bdd_above_singleton, true_and]\n\nlemma bdd_above.insert [semilattice_sup \u03b3] (a : \u03b3) {s : set \u03b3} (hs : bdd_above s) :\n  bdd_above (insert a s) :=\n(bdd_above_insert a).2 hs\n\n/--Adding a point to a set preserves its boundedness below.-/\n@[simp] lemma bdd_below_insert [semilattice_inf \u03b3] (a : \u03b3) {s : set \u03b3} :\n  bdd_below (insert a s) \u2194 bdd_below s :=\nby simp only [insert_eq, bdd_below_union, bdd_below_singleton, true_and]\n\nlemma bdd_below.insert [semilattice_inf \u03b3] (a : \u03b3) {s : set \u03b3} (hs : bdd_below s) :\n  bdd_below (insert a s) :=\n(bdd_below_insert a).2 hs\n\nlemma is_lub.insert [semilattice_sup \u03b3] (a) {b} {s : set \u03b3} (hs : is_lub s b) :\n  is_lub (insert a s) (a \u2294 b) :=\nby { rw insert_eq, exact is_lub_singleton.union hs }\n\nlemma is_glb.insert [semilattice_inf \u03b3] (a) {b} {s : set \u03b3} (hs : is_glb s b) :\n  is_glb (insert a s) (a \u2293 b) :=\nby { rw insert_eq, exact is_glb_singleton.union hs }\n\nlemma is_greatest.insert [linear_order \u03b3] (a) {b} {s : set \u03b3} (hs : is_greatest s b) :\n  is_greatest (insert a s) (max a b) :=\nby { rw insert_eq, exact is_greatest_singleton.union hs }\n\nlemma is_least.insert [linear_order \u03b3] (a) {b} {s : set \u03b3} (hs : is_least s b) :\n  is_least (insert a s) (min a b) :=\nby { rw insert_eq, exact is_least_singleton.union hs }\n\n@[simp] lemma upper_bounds_insert (a : \u03b1) (s : set \u03b1) :\n  upper_bounds (insert a s) = Ici a \u2229 upper_bounds s :=\nby rw [insert_eq, upper_bounds_union, upper_bounds_singleton]\n\n@[simp] lemma lower_bounds_insert (a : \u03b1) (s : set \u03b1) :\n  lower_bounds (insert a s) = Iic a \u2229 lower_bounds s :=\nby rw [insert_eq, lower_bounds_union, lower_bounds_singleton]\n\n/-- When there is a global maximum, every set is bounded above. -/\n@[simp] protected lemma order_top.bdd_above [preorder \u03b3] [order_top \u03b3] (s : set \u03b3) : bdd_above s :=\n\u27e8\u22a4, \u03bb a ha, order_top.le_top a\u27e9\n\n/-- When there is a global minimum, every set is bounded below. -/\n@[simp] protected lemma order_bot.bdd_below [preorder \u03b3] [order_bot \u03b3] (s : set \u03b3) : bdd_below s :=\n\u27e8\u22a5, \u03bb a ha, order_bot.bot_le a\u27e9\n\n/-!\n#### Pair\n-/\n\nlemma is_lub_pair [semilattice_sup \u03b3] {a b : \u03b3} : is_lub {a, b} (a \u2294 b) :=\nis_lub_singleton.insert _\n\nlemma is_glb_pair [semilattice_inf \u03b3] {a b : \u03b3} : is_glb {a, b} (a \u2293 b) :=\nis_glb_singleton.insert _\n\nlemma is_least_pair [linear_order \u03b3] {a b : \u03b3} : is_least {a, b} (min a b) :=\nis_least_singleton.insert _\n\nlemma is_greatest_pair [linear_order \u03b3] {a b : \u03b3} : is_greatest {a, b} (max a b) :=\nis_greatest_singleton.insert _\n\n/-!\n#### Lower/upper bounds\n-/\n\n@[simp] lemma is_lub_lower_bounds : is_lub (lower_bounds s) a \u2194 is_glb s a :=\n\u27e8\u03bb H, \u27e8\u03bb x hx, H.2 $ subset_upper_bounds_lower_bounds s hx, H.1\u27e9, is_greatest.is_lub\u27e9\n\n@[simp] lemma is_glb_upper_bounds : is_glb (upper_bounds s) a \u2194 is_lub s a :=\n@is_lub_lower_bounds \u03b1\u1d52\u1d48 _ _ _\n\nend\n\n/-!\n### (In)equalities with the least upper bound and the greatest lower bound\n-/\n\nsection preorder\nvariables [preorder \u03b1] {s : set \u03b1} {a b : \u03b1}\n\nlemma lower_bounds_le_upper_bounds (ha : a \u2208 lower_bounds s) (hb : b \u2208 upper_bounds s) :\n  s.nonempty \u2192 a \u2264 b\n| \u27e8c, hc\u27e9 := le_trans (ha hc) (hb hc)\n\nlemma is_glb_le_is_lub (ha : is_glb s a) (hb : is_lub s b) (hs : s.nonempty) : a \u2264 b :=\nlower_bounds_le_upper_bounds ha.1 hb.1 hs\n\nlemma is_lub_lt_iff (ha : is_lub s a) : a < b \u2194 \u2203 c \u2208 upper_bounds s, c < b :=\n\u27e8\u03bb hb, \u27e8a, ha.1, hb\u27e9, \u03bb \u27e8c, hcs, hcb\u27e9, lt_of_le_of_lt (ha.2 hcs) hcb\u27e9\n\nlemma lt_is_glb_iff (ha : is_glb s a) : b < a \u2194 \u2203 c \u2208 lower_bounds s, b < c := is_lub_lt_iff ha.dual\n\nlemma le_of_is_lub_le_is_glb {x y} (ha : is_glb s a) (hb : is_lub s b) (hab : b \u2264 a)\n  (hx : x \u2208 s) (hy : y \u2208 s) : x \u2264 y :=\ncalc x \u2264 b : hb.1 hx\n   ... \u2264 a : hab\n   ... \u2264 y : ha.1 hy\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] {s : set \u03b1} {a b : \u03b1}\n\nlemma is_least.unique (Ha : is_least s a) (Hb : is_least s b) : a = b :=\nle_antisymm (Ha.right Hb.left) (Hb.right Ha.left)\n\nlemma is_least.is_least_iff_eq (Ha : is_least s a) : is_least s b \u2194 a = b :=\niff.intro Ha.unique (\u03bb h, h \u25b8 Ha)\n\nlemma is_greatest.unique (Ha : is_greatest s a) (Hb : is_greatest s b) : a = b :=\nle_antisymm (Hb.right Ha.left) (Ha.right Hb.left)\n\nlemma is_greatest.is_greatest_iff_eq (Ha : is_greatest s a) : is_greatest s b \u2194 a = b :=\niff.intro Ha.unique (\u03bb h, h \u25b8 Ha)\n\nlemma is_lub.unique (Ha : is_lub s a) (Hb : is_lub s b) : a = b :=\nHa.unique Hb\n\nlemma is_glb.unique (Ha : is_glb s a) (Hb : is_glb s b) : a = b :=\nHa.unique Hb\n\nlemma set.subsingleton_of_is_lub_le_is_glb (Ha : is_glb s a) (Hb : is_lub s b) (hab : b \u2264 a) :\n  s.subsingleton :=\n\u03bb x hx y hy, le_antisymm (le_of_is_lub_le_is_glb Ha Hb hab hx hy)\n  (le_of_is_lub_le_is_glb Ha Hb hab hy hx)\n\nlemma is_glb_lt_is_lub_of_ne (Ha : is_glb s a) (Hb : is_lub s b)\n  {x y} (Hx : x \u2208 s) (Hy : y \u2208 s) (Hxy : x \u2260 y) :\n  a < b :=\nlt_iff_le_not_le.2\n  \u27e8lower_bounds_le_upper_bounds Ha.1 Hb.1 \u27e8x, Hx\u27e9,\n    \u03bb hab, Hxy $ set.subsingleton_of_is_lub_le_is_glb Ha Hb hab Hx Hy\u27e9\n\nend partial_order\n\nsection linear_order\nvariables [linear_order \u03b1] {s : set \u03b1} {a b : \u03b1}\n\nlemma lt_is_lub_iff (h : is_lub s a) : b < a \u2194 \u2203 c \u2208 s, b < c :=\nby simp only [\u2190 not_le, is_lub_le_iff h, mem_upper_bounds, not_forall]\n\nlemma is_glb_lt_iff (h : is_glb s a) : a < b \u2194 \u2203 c \u2208 s, c < b := lt_is_lub_iff h.dual\n\nlemma is_lub.exists_between (h : is_lub s a) (hb : b < a) :\n  \u2203 c \u2208 s, b < c \u2227 c \u2264 a :=\nlet \u27e8c, hcs, hbc\u27e9 := (lt_is_lub_iff h).1 hb in \u27e8c, hcs, hbc, h.1 hcs\u27e9\n\nlemma is_lub.exists_between' (h : is_lub s a) (h' : a \u2209 s) (hb : b < a) :\n  \u2203 c \u2208 s, b < c \u2227 c < a :=\nlet \u27e8c, hcs, hbc, hca\u27e9 := h.exists_between hb\nin \u27e8c, hcs, hbc, hca.lt_of_ne $ \u03bb hac, h' $ hac \u25b8 hcs\u27e9\n\nlemma is_glb.exists_between (h : is_glb s a) (hb : a < b) :\n  \u2203 c \u2208 s, a \u2264 c \u2227 c < b :=\nlet \u27e8c, hcs, hbc\u27e9 := (is_glb_lt_iff h).1 hb in \u27e8c, hcs, h.1 hcs, hbc\u27e9\n\nlemma is_glb.exists_between' (h : is_glb s a) (h' : a \u2209 s) (hb : a < b) :\n  \u2203 c \u2208 s, a < c \u2227 c < b :=\nlet \u27e8c, hcs, hac, hcb\u27e9 := h.exists_between hb\nin \u27e8c, hcs, hac.lt_of_ne $ \u03bb hac, h' $ hac.symm \u25b8 hcs, hcb\u27e9\n\nend linear_order\n\n/-!\n### Least upper bound and the greatest lower bound in linear ordered additive commutative groups\n-/\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1] {s : set \u03b1} {a \u03b5 : \u03b1}\n\nlemma is_glb.exists_between_self_add (h : is_glb s a) (h\u03b5 : 0 < \u03b5) :\n  \u2203 b \u2208 s, a \u2264 b \u2227 b < a + \u03b5 :=\nh.exists_between $ lt_add_of_pos_right _ h\u03b5\n\nlemma is_glb.exists_between_self_add' (h : is_glb s a) (h\u2082 : a \u2209 s) (h\u03b5 : 0 < \u03b5) :\n  \u2203 b \u2208 s, a < b \u2227 b < a + \u03b5 :=\nh.exists_between' h\u2082 $ lt_add_of_pos_right _ h\u03b5\n\nlemma is_lub.exists_between_sub_self  (h : is_lub s a) (h\u03b5 : 0 < \u03b5) : \u2203 b \u2208 s, a - \u03b5 < b \u2227 b \u2264 a :=\nh.exists_between $ sub_lt_self _ h\u03b5\n\nlemma is_lub.exists_between_sub_self' (h : is_lub s a) (h\u2082 : a \u2209 s) (h\u03b5 : 0 < \u03b5) :\n  \u2203 b \u2208 s, a - \u03b5 < b \u2227 b < a :=\nh.exists_between' h\u2082 $ sub_lt_self _ h\u03b5\n\nend linear_ordered_add_comm_group\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\nnamespace monotone_on\n\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : set \u03b1}\n  (Hf : monotone_on f t) {a : \u03b1} (Hst : s \u2286 t)\ninclude Hf\n\nlemma mem_upper_bounds_image (Has : a \u2208 upper_bounds s) (Hat : a \u2208 t) :\n  f a \u2208 upper_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf (Hst H) Hat (Has H))\n\nlemma mem_upper_bounds_image_self : a \u2208 upper_bounds t \u2192 a \u2208 t \u2192 f a \u2208 upper_bounds (f '' t) :=\nHf.mem_upper_bounds_image subset_rfl\n\nlemma mem_lower_bounds_image (Has : a \u2208 lower_bounds s) (Hat : a \u2208 t) :\n  f a \u2208 lower_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf Hat (Hst H) (Has H))\n\nlemma mem_lower_bounds_image_self : a \u2208 lower_bounds t \u2192 a \u2208 t \u2192 f a \u2208 lower_bounds (f '' t) :=\nHf.mem_lower_bounds_image subset_rfl\n\nlemma image_upper_bounds_subset_upper_bounds_image (Hst : s \u2286 t) :\n  f '' (upper_bounds s \u2229 t) \u2286 upper_bounds (f '' s) :=\nby { rintro _ \u27e8a, ha, rfl\u27e9, exact Hf.mem_upper_bounds_image Hst ha.1 ha.2 }\n\nlemma image_lower_bounds_subset_lower_bounds_image :\n  f '' (lower_bounds s \u2229 t) \u2286 lower_bounds (f '' s) :=\nHf.dual.image_upper_bounds_subset_upper_bounds_image Hst\n\n/-- The image under a monotone function on a set `t` of a subset which has an upper bound in `t`\n  is bounded above. -/\nlemma map_bdd_above : (upper_bounds s \u2229 t).nonempty \u2192 bdd_above (f '' s) :=\n\u03bb \u27e8C, hs, ht\u27e9, \u27e8f C, Hf.mem_upper_bounds_image Hst hs ht\u27e9\n\n/-- The image under a monotone function on a set `t` of a subset which has a lower bound in `t`\n  is bounded below. -/\nlemma map_bdd_below : (lower_bounds s \u2229 t).nonempty \u2192 bdd_below (f '' s) :=\n\u03bb \u27e8C, hs, ht\u27e9, \u27e8f C, Hf.mem_lower_bounds_image Hst hs ht\u27e9\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\nlemma map_is_least (Ha : is_least t a) : is_least (f '' t) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image_self Ha.2 Ha.1\u27e9\n\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\nlemma map_is_greatest (Ha : is_greatest t a) : is_greatest (f '' t) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image_self Ha.2 Ha.1\u27e9\n\nend monotone_on\n\nnamespace antitone_on\n\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : set \u03b1}\n  (Hf : antitone_on f t) {a : \u03b1} (Hst : s \u2286 t)\ninclude Hf\n\nlemma mem_upper_bounds_image (Has : a \u2208 lower_bounds s) : a \u2208 t \u2192 f a \u2208 upper_bounds (f '' s) :=\nHf.dual_right.mem_lower_bounds_image Hst Has\n\nlemma mem_upper_bounds_image_self : a \u2208 lower_bounds t \u2192 a \u2208 t \u2192 f a \u2208 upper_bounds (f '' t) :=\nHf.dual_right.mem_lower_bounds_image_self\n\nlemma mem_lower_bounds_image : a \u2208 upper_bounds s \u2192 a \u2208 t \u2192 f a \u2208 lower_bounds (f '' s) :=\nHf.dual_right.mem_upper_bounds_image Hst\n\nlemma mem_lower_bounds_image_self : a \u2208 upper_bounds t \u2192 a \u2208 t \u2192 f a \u2208 lower_bounds (f '' t) :=\nHf.dual_right.mem_upper_bounds_image_self\n\nlemma image_lower_bounds_subset_upper_bounds_image :\n  f '' (lower_bounds s \u2229 t) \u2286 upper_bounds (f '' s) :=\nHf.dual_right.image_lower_bounds_subset_lower_bounds_image Hst\n\nlemma image_upper_bounds_subset_lower_bounds_image :\n  f '' (upper_bounds s \u2229 t) \u2286 lower_bounds (f '' s) :=\nHf.dual_right.image_upper_bounds_subset_upper_bounds_image Hst\n\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\nlemma map_bdd_above : (upper_bounds s \u2229 t).nonempty \u2192 bdd_below (f '' s) :=\nHf.dual_right.map_bdd_above Hst\n\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\nlemma map_bdd_below : (lower_bounds s \u2229 t).nonempty \u2192 bdd_above (f '' s) :=\nHf.dual_right.map_bdd_below Hst\n\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\nlemma map_is_greatest : is_greatest t a \u2192 is_least (f '' t) (f a) :=\nHf.dual_right.map_is_greatest\n\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\nlemma map_is_least : is_least t a \u2192 is_greatest (f '' t) (f a) :=\nHf.dual_right.map_is_least\n\nend antitone_on\n\nnamespace monotone\n\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (Hf : monotone f) {a : \u03b1} {s : set \u03b1}\ninclude Hf\n\nlemma mem_upper_bounds_image (Ha : a \u2208 upper_bounds s) : f a \u2208 upper_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf (Ha H))\n\nlemma mem_lower_bounds_image (Ha : a \u2208 lower_bounds s) : f a \u2208 lower_bounds (f '' s) :=\nball_image_of_ball (\u03bb x H, Hf (Ha H))\n\nlemma image_upper_bounds_subset_upper_bounds_image : f '' upper_bounds s \u2286 upper_bounds (f '' s) :=\nby { rintro _ \u27e8a, ha, rfl\u27e9, exact Hf.mem_upper_bounds_image ha }\n\nlemma image_lower_bounds_subset_lower_bounds_image : f '' lower_bounds s \u2286 lower_bounds (f '' s) :=\nHf.dual.image_upper_bounds_subset_upper_bounds_image\n\n/-- The image under a monotone function of a set which is bounded above is bounded above. See also\n`bdd_above.image2`. -/\nlemma map_bdd_above : bdd_above s \u2192 bdd_above (f '' s)\n| \u27e8C, hC\u27e9 := \u27e8f C, Hf.mem_upper_bounds_image hC\u27e9\n\n/-- The image under a monotone function of a set which is bounded below is bounded below. See also\n`bdd_below.image2`. -/\nlemma map_bdd_below : bdd_below s \u2192 bdd_below (f '' s)\n| \u27e8C, hC\u27e9 := \u27e8f C, Hf.mem_lower_bounds_image hC\u27e9\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\nlemma map_is_least (Ha : is_least s a) : is_least (f '' s) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image Ha.2\u27e9\n\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\nlemma map_is_greatest (Ha : is_greatest s a) : is_greatest (f '' s) (f a) :=\n\u27e8mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image Ha.2\u27e9\n\nend monotone\n\nnamespace antitone\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : antitone f) {a : \u03b1} {s : set \u03b1}\n\nlemma mem_upper_bounds_image : a \u2208 lower_bounds s \u2192 f a \u2208 upper_bounds (f '' s) :=\nhf.dual_right.mem_lower_bounds_image\n\nlemma mem_lower_bounds_image : a \u2208 upper_bounds s \u2192 f a \u2208 lower_bounds (f '' s) :=\nhf.dual_right.mem_upper_bounds_image\n\nlemma image_lower_bounds_subset_upper_bounds_image : f '' lower_bounds s \u2286 upper_bounds (f '' s) :=\nhf.dual_right.image_lower_bounds_subset_lower_bounds_image\n\nlemma image_upper_bounds_subset_lower_bounds_image : f '' upper_bounds s \u2286 lower_bounds (f '' s) :=\nhf.dual_right.image_upper_bounds_subset_upper_bounds_image\n\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\nlemma map_bdd_above : bdd_above s \u2192 bdd_below (f '' s) :=\nhf.dual_right.map_bdd_above\n\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\nlemma map_bdd_below : bdd_below s \u2192 bdd_above (f '' s) :=\nhf.dual_right.map_bdd_below\n\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\nlemma map_is_greatest : is_greatest s a \u2192 is_least (f '' s) (f a) :=\nhf.dual_right.map_is_greatest\n\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\nlemma map_is_least : is_least s a \u2192 is_greatest (f '' s) (f a) :=\nhf.dual_right.map_is_least\n\nend antitone\n\nsection image2\nvariables [preorder \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {s : set \u03b1} {t : set \u03b2} {a : \u03b1}\n  {b : \u03b2}\n\nsection monotone_monotone\nvariables (h\u2080 : \u2200 b, monotone (swap f b)) (h\u2081 : \u2200 a, monotone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2 (ha : a \u2208 upper_bounds s) (hb : b \u2208 upper_bounds t) :\n  f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2 (ha : a \u2208 lower_bounds s) (hb : b \u2208 lower_bounds t) :\n  f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_upper_bounds_upper_bounds_subset :\n  image2 f (upper_bounds s) (upper_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_upper_bounds_image2 h\u2080 h\u2081 ha hb }\n\nlemma image2_lower_bounds_lower_bounds_subset :\n  image2 f (lower_bounds s) (lower_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_lower_bounds_image2 h\u2080 h\u2081 ha hb }\n\n/-- See also `monotone.map_bdd_above`. -/\nlemma bdd_above.image2 : bdd_above s \u2192 bdd_above t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, exact \u27e8f a b, mem_upper_bounds_image2 h\u2080 h\u2081 ha hb\u27e9 }\n\n/-- See also `monotone.map_bdd_below`. -/\nlemma bdd_below.image2 : bdd_below s \u2192 bdd_below t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, exact \u27e8f a b, mem_lower_bounds_image2 h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_greatest.image2 (ha : is_greatest s a) (hb : is_greatest t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_least.image2 (ha : is_least s a) (hb : is_least t b) : is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend monotone_monotone\n\nsection monotone_antitone\nvariables (h\u2080 : \u2200 b, monotone (swap f b)) (h\u2081 : \u2200 a, antitone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds (ha : a \u2208 upper_bounds s)\n  (hb : b \u2208 lower_bounds t) : f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds (ha : a \u2208 lower_bounds s)\n  (hb : b \u2208 upper_bounds t) : f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_upper_bounds_lower_bounds_subset_upper_bounds_image2 :\n  image2 f (upper_bounds s) (lower_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb }\n\nlemma image2_lower_bounds_upper_bounds_subset_lower_bounds_image2 :\n  image2 f (lower_bounds s) (upper_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb }\n\nlemma bdd_above.bdd_above_image2_of_bdd_below :\n  bdd_above s \u2192 bdd_below t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma bdd_below.bdd_below_image2_of_bdd_above :\n  bdd_below s \u2192 bdd_above t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_greatest.is_greatest_image2_of_is_least (ha : is_greatest s a) (hb : is_least t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_least.is_least_image2_of_is_greatest (ha : is_least s a) (hb : is_greatest t b) :\n  is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend monotone_antitone\n\nsection antitone_antitone\nvariables (h\u2080 : \u2200 b, antitone (swap f b)) (h\u2081 : \u2200 a, antitone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2_of_mem_lower_bounds (ha : a \u2208 lower_bounds s)\n  (hb : b \u2208 lower_bounds t) :\n  f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2_of_mem_upper_bounds (ha : a \u2208 upper_bounds s)\n  (hb : b \u2208 upper_bounds t) :\n  f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_upper_bounds_upper_bounds_subset_upper_bounds_image2 :\n  image2 f (lower_bounds s) (lower_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_upper_bounds_image2_of_mem_lower_bounds h\u2080 h\u2081 ha hb }\n\nlemma image2_lower_bounds_lower_bounds_subset_lower_bounds_image2 :\n  image2 f (upper_bounds s) (upper_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_lower_bounds_image2_of_mem_upper_bounds h\u2080 h\u2081 ha hb }\n\nlemma bdd_below.image2_bdd_above : bdd_below s \u2192 bdd_below t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_upper_bounds_image2_of_mem_lower_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma bdd_above.image2_bdd_below : bdd_above s \u2192 bdd_above t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_lower_bounds_image2_of_mem_upper_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_least.is_greatest_image2 (ha : is_least s a) (hb : is_least t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2_of_mem_lower_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_greatest.is_least_image2 (ha : is_greatest s a) (hb : is_greatest t b) :\n  is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2_of_mem_upper_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend antitone_antitone\n\nsection antitone_monotone\nvariables (h\u2080 : \u2200 b, antitone (swap f b)) (h\u2081 : \u2200 a, monotone (f a))\ninclude h\u2080 h\u2081\n\nlemma mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds (ha : a \u2208 lower_bounds s)\n  (hb : b \u2208 upper_bounds t) : f a b \u2208 upper_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds (ha : a \u2208 upper_bounds s)\n  (hb : b \u2208 lower_bounds t) : f a b \u2208 lower_bounds (image2 f s t) :=\nforall_image2_iff.2 $ \u03bb x hx y hy, (h\u2080 _ $ ha hx).trans $ h\u2081 _ $ hb hy\n\nlemma image2_lower_bounds_upper_bounds_subset_upper_bounds_image2 :\n  image2 f (lower_bounds s) (upper_bounds t) \u2286 upper_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb }\n\nlemma image2_upper_bounds_lower_bounds_subset_lower_bounds_image2 :\n  image2 f (upper_bounds s) (lower_bounds t) \u2286 lower_bounds (image2 f s t) :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9,\n  exact mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb }\n\nlemma bdd_below.bdd_above_image2_of_bdd_above :\n  bdd_below s \u2192 bdd_above t \u2192 bdd_above (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma bdd_above.bdd_below_image2_of_bdd_above :\n  bdd_above s \u2192 bdd_below t \u2192 bdd_below (image2 f s t) :=\nby { rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n  exact \u27e8f a b, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha hb\u27e9 }\n\nlemma is_least.is_greatest_image2_of_is_greatest (ha : is_least s a) (hb : is_greatest t b) :\n  is_greatest (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nlemma is_greatest.is_least_image2_of_is_least (ha : is_greatest s a) (hb : is_least t b) :\n  is_least (image2 f s t) (f a b) :=\n\u27e8mem_image2_of_mem ha.1 hb.1,\n  mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n\nend antitone_monotone\nend image2\n\nlemma is_glb.of_image [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n  {s : set \u03b1} {x : \u03b1} (hx : is_glb (f '' s) (f x)) :\n  is_glb s x :=\n\u27e8\u03bb y hy, hf.1 $ hx.1 $ mem_image_of_mem _ hy,\n  \u03bb y hy, hf.1 $ hx.2 $ monotone.mem_lower_bounds_image (\u03bb x y, hf.2) hy\u27e9\n\nlemma is_lub.of_image [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n  {s : set \u03b1} {x : \u03b1} (hx : is_lub (f '' s) (f x)) :\n  is_lub s x :=\n@is_glb.of_image \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ f (\u03bb x y, hf) _ _ hx\n\nlemma is_lub_pi {\u03c0 : \u03b1 \u2192 Type*} [\u03a0 a, preorder (\u03c0 a)] {s : set (\u03a0 a, \u03c0 a)} {f : \u03a0 a, \u03c0 a} :\n  is_lub s f \u2194 \u2200 a, is_lub (function.eval a '' s) (f a) :=\nbegin\n  classical,\n  refine \u27e8\u03bb H a, \u27e8(function.monotone_eval a).mem_upper_bounds_image H.1, \u03bb b hb, _\u27e9, \u03bb H, \u27e8_, _\u27e9\u27e9,\n  { suffices : function.update f a b \u2208 upper_bounds s,\n      from function.update_same a b f \u25b8 H.2 this a,\n    refine \u03bb g hg, le_update_iff.2 \u27e8hb $ mem_image_of_mem _ hg, \u03bb i hi, H.1 hg i\u27e9 },\n  { exact \u03bb g hg a, (H a).1 (mem_image_of_mem _ hg) },\n  { exact \u03bb g hg a, (H a).2 ((function.monotone_eval a).mem_upper_bounds_image hg) }\nend\n\nlemma is_glb_pi {\u03c0 : \u03b1 \u2192 Type*} [\u03a0 a, preorder (\u03c0 a)] {s : set (\u03a0 a, \u03c0 a)} {f : \u03a0 a, \u03c0 a} :\n  is_glb s f \u2194 \u2200 a, is_glb (function.eval a '' s) (f a) :=\n@is_lub_pi \u03b1 (\u03bb a, (\u03c0 a)\u1d52\u1d48) _ s f\n\nlemma is_lub_prod [preorder \u03b1] [preorder \u03b2] {s : set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n  is_lub s p \u2194 is_lub (prod.fst '' s) p.1 \u2227 is_lub (prod.snd '' s) p.2 :=\nbegin\n  refine \u27e8\u03bb H, \u27e8\u27e8monotone_fst.mem_upper_bounds_image H.1, \u03bb a ha, _\u27e9,\n    \u27e8monotone_snd.mem_upper_bounds_image H.1, \u03bb a ha, _\u27e9\u27e9, \u03bb H, \u27e8_, _\u27e9\u27e9,\n  { suffices : (a, p.2) \u2208 upper_bounds s, from (H.2 this).1,\n    exact \u03bb q hq, \u27e8ha $ mem_image_of_mem _ hq, (H.1 hq).2\u27e9 },\n  { suffices : (p.1, a) \u2208 upper_bounds s, from (H.2 this).2,\n    exact \u03bb q hq, \u27e8(H.1 hq).1, ha $ mem_image_of_mem _ hq\u27e9 },\n  { exact \u03bb q hq, \u27e8H.1.1 $ mem_image_of_mem _ hq, H.2.1 $ mem_image_of_mem _ hq\u27e9 },\n  { exact \u03bb q hq, \u27e8H.1.2 $ monotone_fst.mem_upper_bounds_image hq,\n      H.2.2 $ monotone_snd.mem_upper_bounds_image hq\u27e9 }\nend\n\nlemma is_glb_prod [preorder \u03b1] [preorder \u03b2] {s : set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n  is_glb s p \u2194 is_glb (prod.fst '' s) p.1 \u2227 is_glb (prod.snd '' s) p.2 :=\n@is_lub_prod \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _\n\nnamespace order_iso\n\nvariables [preorder \u03b1] [preorder \u03b2] (f : \u03b1 \u2243o \u03b2)\n\nlemma upper_bounds_image {s : set \u03b1} :\n  upper_bounds (f '' s) = f '' upper_bounds s :=\nsubset.antisymm\n  (\u03bb x hx, \u27e8f.symm x, \u03bb y hy, f.le_symm_apply.2 (hx $ mem_image_of_mem _ hy), f.apply_symm_apply x\u27e9)\n  f.monotone.image_upper_bounds_subset_upper_bounds_image\n\nlemma lower_bounds_image {s : set \u03b1} : lower_bounds (f '' s) = f '' lower_bounds s :=\n@upper_bounds_image \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ f.dual _\n\n@[simp] lemma is_lub_image {s : set \u03b1} {x : \u03b2} :\n  is_lub (f '' s) x \u2194 is_lub s (f.symm x) :=\n\u27e8\u03bb h, is_lub.of_image (\u03bb _ _, f.le_iff_le) ((f.apply_symm_apply x).symm \u25b8 h),\n  \u03bb h, is_lub.of_image (\u03bb _ _, f.symm.le_iff_le) $ (f.symm_image_image s).symm \u25b8 h\u27e9\n\nlemma is_lub_image' {s : set \u03b1} {x : \u03b1} :\n  is_lub (f '' s) (f x) \u2194 is_lub s x :=\nby rw [is_lub_image, f.symm_apply_apply]\n\n@[simp] lemma is_glb_image {s : set \u03b1} {x : \u03b2} :\n  is_glb (f '' s) x \u2194 is_glb s (f.symm x) :=\nf.dual.is_lub_image\n\nlemma is_glb_image' {s : set \u03b1} {x : \u03b1} :\n  is_glb (f '' s) (f x) \u2194 is_glb s x :=\nf.dual.is_lub_image'\n\n@[simp] lemma is_lub_preimage {s : set \u03b2} {x : \u03b1} :\n  is_lub (f \u207b\u00b9' s) x \u2194 is_lub s (f x) :=\nby rw [\u2190 f.symm_symm, \u2190 image_eq_preimage, is_lub_image]\n\nlemma is_lub_preimage' {s : set \u03b2} {x : \u03b2} :\n  is_lub (f \u207b\u00b9' s) (f.symm x) \u2194 is_lub s x :=\nby rw [is_lub_preimage, f.apply_symm_apply]\n\n@[simp] lemma is_glb_preimage {s : set \u03b2} {x : \u03b1} :\n  is_glb (f \u207b\u00b9' s) x \u2194 is_glb s (f x) :=\nf.dual.is_lub_preimage\n\nlemma is_glb_preimage' {s : set \u03b2} {x : \u03b2} :\n  is_glb (f \u207b\u00b9' s) (f.symm x) \u2194 is_glb s x :=\nf.dual.is_lub_preimage'\n\nend order_iso\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7241353214132453}}
{"text": "-- Presentation aimed for March 4, 2020\n-- (prime p = 4k+1 is sum of two squares)\n\n-- Must arrive at 10:00, MIT Lab on that day.\n\n-- https://github.com/leanprover-community/mathlib/blob/master/docs/install/windows.md\n\nimport tactic\nimport algebra.group_power\nimport data.int.basic\n--import data.zmod.quadratic_reciprocity\nuniverse u\nlocal attribute [instance] classical.prop_decidable\n\ndef ex1 (x y z : \u2115) : \u2115 := x + y * z\n\ndef even (n : \u2115) : Prop := \u2203 k, n = 2*k\ndef odd (n : \u2115) : Prop := \u2203 k, n = 2*k+1\n\nlemma even_or_odd (n : \u2115) : or (even n) (odd n) :=\nbegin\ninduction n with d hd,\nleft,\nrw even,\nuse 0,\nsimp,\ncases hd with p q,\nrw even at p,\ncases p with k p,\nright,\nrw odd,\nuse k,\nrw p,\nrw odd at q,\ncases q with k q,\nleft,\nrw even,\nuse k+1,\nrw mul_add,\nrw q,\nrefl,\nend\n\nlemma not_both_even_odd (n : \u2115) : \u00ac((even n) \u2227 (odd n)) :=\nbegin\nby_cases h : (even n) \u2227 (odd n),\nexfalso,\ncases h with h1 h2,\nrw even at h1,\ncases h1 with k h1k,\nrw odd at h2,\ncases h2 with k' h2k,\nrw h1k at h2k,\nhave hk := nat.mul_mod_right 2 k,\nrw h2k at hk,\nrw add_comm at hk,\nhave hk1 := nat.add_mul_mod_self_left 1 2 k',\nhave one_lt_two : 1 < 2 := by {exact nat.lt_succ_self 1},\nhave one_mod_two_is_one := nat.mod_eq_of_lt one_lt_two,\nrw one_mod_two_is_one at hk1,\nrw hk at hk1,\nhave zero_lt_one : 0 < 1 := by exact nat.lt_succ_self 0,\nrw hk1 at zero_lt_one,\nexact lt_irrefl 1 zero_lt_one,\nexact h,\nend\n\nlemma even_plus_even_is_even (n m : \u2115) (h : and (even n) (even m)) : even (n+m) :=\nbegin\ncases h with p q,\nrw even at p,\ncases p with k p,\nrw even at q,\ncases q with l q,\nrw even,\nuse k+l,\nrw mul_add,\nrw p,\nrw q,\nend\n\nlemma even_plus_odd_is_odd (n m : \u2115) (h : and (even n) (odd m)) : odd (n+m) :=\nbegin\ncases h with p q,\nrw even at p,\ncases p with k p,\nrw odd at q,\ncases q with l q,\nrw odd,\nuse k+l,\nrw mul_add,\nrw p,\nrw q,\nring,\nend\n\nlemma odd_plus_even_is_odd (n m : \u2115) (h : and (odd n) (even m)) : odd (n+m) :=\nbegin\nrw and_comm at h,\nrw add_comm,\napply even_plus_odd_is_odd,\nexact h,\nend\n\nlemma odd_plus_odd_is_even (n m : \u2115) (h : and (odd n) (odd m)) : even (n+m) :=\nbegin\ncases h with p q,\nrw odd at p,\ncases p with k p,\nrw odd at q,\ncases q with l q,\nrw even,\nuse k+l+1,\nrw p,\nrw q,\nrw mul_add,\nrw mul_add,\nring,\nend\n\nlemma even_minus_even_is_even (n m : \u2115) (h : (even n) \u2227 (even m) \u2227 (m \u2264 n))\n  : even (n - m) :=\nbegin\ncases h with h1 h2,\ncases h2 with h3 h4,\nhave deo := even_or_odd (n-m),\ncases deo with deven dodd,\nexact deven,\nexfalso,\nhave sum := odd_plus_even_is_odd (n-m) m \u27e8dodd, h3\u27e9,\nhave claim : n - m + m = n,\nhave summ := nat.le.dest h4,\ncases summ with smd summ',\nrw add_comm at summ',\nrw (eq.symm summ'),\nrw nat.add_sub_cancel,\nrw claim at sum,\nexact not_both_even_odd n \u27e8h1, sum\u27e9,\nend\n\nlemma odd_minus_odd_is_even (n m : \u2115) (h : (odd n) \u2227 (odd m) \u2227 (m \u2264 n))\n  : even (n - m) :=\nbegin\ncases h with h1 h2,\ncases h2 with h3 h4,\nhave deo := even_or_odd (n-m),\ncases deo with deven dodd,\nexact deven,\nexfalso,\nhave sum := odd_plus_odd_is_even (n-m) m \u27e8dodd, h3\u27e9,\nhave claim : n - m + m = n,\nhave summ := nat.le.dest h4,\ncases summ with smd summ',\nrw add_comm at summ',\nrw (eq.symm summ'),\nrw nat.add_sub_cancel,\nrw claim at sum,\nexact not_both_even_odd n \u27e8sum, h1\u27e9,\nend\n\nlemma even_times_nat_is_even (n m : \u2115) (h : even n) : even (n*m) :=\nbegin\nrw even,\nrw even at h,\ncases h with p kp,\nuse m*p,\nrw kp,\nring,\nend\n\nlemma nat_times_even_is_even (n m : \u2115) (h : even m) : even (n*m) :=\nbegin\nrw mul_comm,\napply even_times_nat_is_even,\nexact h,\nend\n\nlemma odd_times_odd_is_odd (n m : \u2115) (h : and (odd n) (odd m)) : odd (n*m) :=\nbegin\nrw odd,\ncases h with h1 h2,\nrw odd at h1,\ncases h1 with p kp,\nrw odd at h2,\ncases h2 with q kq,\nuse 2*p*q + p + q,\nrw kp,\nrw kq,\nring,\nend\n\nlemma even_square_is_even (n : \u2115) (h : even n) : even (n^2) :=\nbegin\nrw nat.pow_two,\nexact nat_times_even_is_even n n h,\nend\n\nlemma odd_square_is_odd (n : \u2115) (h : odd n) : odd (n^2) :=\nbegin\nrw nat.pow_two,\nexact odd_times_odd_is_odd n n \u27e8h, h\u27e9,\nend\n\nlemma not_and_eq_or_not (p q : Prop) : \u00ac(p \u2227 q) \u2194 \u00acp \u2228 \u00acq :=\nbegin\nsplit,\nintro f,\n by_cases hp : p,\n  { by_cases hq : q,\n    { exact (f \u27e8hp, hq\u27e9).elim, },\n    exact or.inr hq, },\n  { exact or.inl hp, },\nintro g,\ncases g with g1 g2,\nby_cases h : p \u2227 q,\nexfalso,\ncases h with h1 h2,\nexact g1(h1),\nexact h,\nby_cases h : p \u2227 q,\nexfalso,\ncases h with h1 h2,\nexact g2(h2),\nexact h,\nend\n\nlemma not_or_eq_and_not (p q : Prop) : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\nbegin\nsplit,\nintro f,\nby_cases hp : p,\nhave i := or.intro_left q hp,\nexfalso,\nexact f(i),\nby_cases hq : q,\nhave i := or.intro_right p hq,\nexfalso,\nexact f(i),\nexact \u27e8hp, hq\u27e9,\nintro f,\ncases f with f1 f2,\nby_cases h : p \u2228 q,\ncases h with h1 h2,\nexfalso,\nexact f1(h1),\nexfalso,\nexact f2(h2),\nexact h,\nend\n\nlemma pos_or_zero (n : \u2115) : 0 < n \u2228 n = 0 :=\nbegin\nhave tri := lt_trichotomy 0 n,\ncases tri with tri1 tri2,\nleft,\nexact tri1,\ncases tri2 with tri3 tri4,\nright,\nexact (eq.symm tri3),\nexfalso,\nhave nng := zero_le n,\nhave lt1 := lt_of_le_of_lt nng tri4,\nexact lt_irrefl 0 lt1,\nend\n\nlemma mul_cancel (a b c : \u2115) (h : a*b = a*c) (p : 0 < a) : b = c :=\nbegin\nhave ltr := lt_trichotomy b c,\ncases ltr with ltr' ltr1,\nexfalso,\nhave thing := mul_lt_mul_of_pos_left ltr' p,\nrw h at thing,\nexact lt_irrefl (a*c) thing,\ncases ltr1 with ltr2 ltr3,\nexact ltr2,\nexfalso,\nhave thing := mul_lt_mul_of_pos_left ltr3 p,\nrw h at thing,\nexact lt_irrefl (a*c) thing,\nend\n\nlemma int_mul_cancel (a b c : \u2124) (h : a*b = a*c) (p : 0 < a) : b = c :=\nbegin\nhave ltr := lt_trichotomy b c,\ncases ltr with ltr' ltr1,\nexfalso,\nhave thing := mul_lt_mul_of_pos_left ltr' p,\nrw h at thing,\nexact lt_irrefl (a*c) thing,\ncases ltr1 with ltr2 ltr3,\nexact ltr2,\nexfalso,\nhave thing := mul_lt_mul_of_pos_left ltr3 p,\nrw h at thing,\nexact lt_irrefl (a*c) thing,\nend\n\nlemma int_mul_cancel_lt (a b c : \u2124) (h : a*b < a*c) (p : 0 < a) : b < c :=\nbegin\nhave ltr := lt_trichotomy b c,\ncases ltr with ltr' ltr1,\nexact ltr',\nexfalso,\ncases ltr1 with ltr2 ltr3,\nrw ltr2 at h,\nexact lt_irrefl (a*c) h,\nhave th := mul_lt_mul_of_pos_left ltr3 p,\nexact lt_irrefl (a*b) (lt_trans h th),\nend\n\n-- I imagine that those will be important.  Now for the real deal.\n\ndef divides (n m : \u2115) : Prop := \u2203 k, n*k = m\ndef prime' (p : \u2115) : Prop := 1 < p \u2227 (\u2200 k, (divides k p \u2192 (k = 1 \u2228 k = p)))\n\nlemma square_eq_times_itself (a : \u2124) : a^2 = a*a :=\nbegin\nrw pow_succ,\nrw pow_succ,\nrw pow_zero,\nrw mul_one,\nend\n\nlemma square_eq_sq_of_nat (a : \u2124) : \u2203(n:\u2115),(a^2=(n:\u2124)^2) :=\nbegin\nhave ltr := lt_trichotomy 0 a,\ncases ltr with ltr1 ltr',\nhave thing := int.eq_coe_of_zero_le (le_of_lt ltr1),\ncases thing with n th',\nuse n,\nrw th',\ncases ltr' with ltr2 ltr3,\nuse 0,\nrw (eq.symm ltr2),\nring,\nhave th := int.add_lt_add_left ltr3 (-a),\nrw add_zero at th,\nhave fill_in_hole : -a+a=0 := by ring,\nrw fill_in_hole at th,\nhave thing := int.eq_coe_of_zero_le (le_of_lt th),\ncases thing with n th',\nuse n,\nrw (eq.symm th'),\nring,\nend\n\nlemma nonzero_square_pos (a : \u2124) (h : 0 \u2260 a) : 0 < a^2 :=\nbegin\nby_cases p : 0 < a,\nrw square_eq_times_itself,\nrw [\u2190( int.mul_zero a)],\nexact mul_lt_mul_of_pos_left p p,\nhave q := lt_trichotomy 0 a,\ncases q,\nexfalso,\napply p,\nexact q,\ncases q,\nexfalso,\napply h,\nexact q,\nrw square_eq_times_itself,\nrw [\u2190( int.mul_zero a)],\nexact mul_lt_mul_of_neg_left q q,\nend\n\nlemma square_nonneg (a : \u2124) : 0 <= a^2 :=\nbegin\nby_cases p : a = 0,\nrw p,\nrefl,\napply le_of_lt,\napply nonzero_square_pos,\nby_cases q : 0 = a,\nhave r := eq.symm q,\nexfalso,\napply p,\nexact r,\nexact q,\nend\n\nlemma LCex (a p : \u2115) (hp : 0 < p) :\n  \u2203(d:\u2115), 0 < d \u2227 (\u2203(x:\u2124), (\u2203(y:\u2124), (x*a + y*p = d))) :=\nbegin\nuse (a*\u2191a+p*\u2191p),\nsplit,\nhave q := square_nonneg(\u2191a),\nrw square_eq_times_itself at q,\nhave s := nonzero_square_pos(\u2191p),\nnorm_cast,\nrw square_eq_times_itself at s,\nnorm_cast at s,\nnorm_cast at q,\nby_cases pz : 0 = p,\nrw pz at hp,\nhave ir := gt_irrefl p,\nexfalso,\napply ir,\nexact hp,\nhave r1 := s(pz),\nhave ala := add_lt_add_left r1 (a*a),\nrw add_zero at ala,\nexact lt_of_le_of_lt q ala,\nnorm_cast,\nuse a,\nuse p,\nnorm_cast,\nend\n\nlemma div_alg (a b : \u2115) (hp : 0 < b) : \u2203(r q : \u2115), (a = b*q+r \u2227 r < b) :=\nbegin\ninduction a with d hd,\nuse 0,\nuse 0,\nsplit,\nring,\nexact hp,\ncases hd with r rh,\ncases rh with q qh,\ncases qh with qh1 qh2,\nby_cases p : nat.succ r = b,\nuse 0,\nuse q+1,\nrw qh1,\nsplit,\nhave p1 := eq.symm p,\nrw p1,\nring,\nexact hp,\nhave qh3 := nat.succ_le_of_lt qh2,\nhave tri := lt_trichotomy (nat.succ r) b,\ncases tri with tri1 tri2,\nuse nat.succ r,\nuse q,rw qh1,\nrw nat.add_succ,\nsplit,\nrefl,\nexact tri1,\ncases tri2 with tri3 tri4,\nexfalso,\napply p,\nexact tri3,\nexfalso,\nhave i := nat.lt_of_le_of_lt qh3 tri4,\nhave ir := lt_irrefl (nat.succ r),\napply ir,\nexact i,\nend\n\nlemma div_alg_near_zero (a b : \u2115) (b_pos : 0 < b) (ho : odd b) :\n  \u2203(q:\u2124), \u2203(r:\u2124), ((a:\u2124) = b*q+r \u2227 2*r < b \u2227 -2*r < b) :=\nbegin\nhave div := div_alg a b b_pos,\ncases div with r divr,\ncases divr with q divq,\nhave tri := lt_trichotomy (2*r) b,\ncases tri with tri1 tri2,\nuse q,\nuse r,\ncases divq with divq1 divq2,\nsplit,\nnorm_cast,\nexact divq1,\nsplit,\nnorm_cast,\nexact tri1,\nhave claim : (-2:\u2124)*r \u2264 0,\nhave thing := zero_le (2*r),\nhave thing2 : (0 \u2264 2 * (r : \u2124)) :=\n  by { norm_cast, exact thing },\nhave st := add_le_add_left thing2 ((-2:\u2124)*r),\nrw add_zero at st,\nhave claim1 : (-2:\u2124) * \u2191r + 2 * \u2191r = 0 := by ring,\nrw claim1 at st,\nexact st,\nhave b_pos_int : (0 < (b:\u2124)) := by {norm_cast, exact b_pos},\nexact lt_of_le_of_lt claim b_pos_int,\ncases tri2 with tri3 tri4,\nexfalso,\nhave claim : even b := by {rw even, use r, exact (eq.symm tri3)},\nhave not_both := not_both_even_odd b,\nexact not_both \u27e8claim, ho\u27e9,\nuse q+1,\nuse r-b,\ncases divq with divq1 divq2,\nsplit,\nrw divq1,\npush_cast,\nring,\nsplit,\nhave claim : 0 < (b:\u2124) := by {norm_cast, exact b_pos},\nhave claim2 : (r:\u2124) < (b:\u2124) := by {norm_cast, exact divq2},\nhave st := add_lt_add_left claim2 (-b:\u2124),\nhave claim3 : -(b:\u2124) + (r:\u2124) = (r:\u2124) - (b:\u2124) := by {ring},\nrw claim3 at st,\nhave fillinhole : -(b:\u2124) + (b:\u2124) = 0 := by {ring},\nrw fillinhole at st,\nhave st' := mul_lt_mul_of_pos_left st (lt_trans zero_lt_one one_lt_two),\nrw mul_zero at st',\nexact (lt_trans st' claim),\nhave claim : (b:\u2124) < 2*(r:\u2124) := by {norm_cast, exact tri4},\nhave st := add_lt_add_left claim (b - 2*(r:\u2124)),\nhave claim2 : (b:\u2124) - 2*(r:\u2124) + b = (-(2:\u2124))*(r-(b:\u2124)) := by {ring},\nrw claim2 at st,\nhave claim3 : (b:\u2124) - 2*(r:\u2124) + 2*r = b := by {ring},\nrw claim3 at st,\nexact st,\nend\n\nlemma abs_thing (a b : \u2124) (h1 : a < b) (h2 : -a < b) : a^2 < b^2 :=\nbegin\nhave h1' := add_lt_add_right h1 (-a),\nhave f1 : a + (-a) = 0 := by ring,\nrw f1 at h1',\nhave h2' := add_lt_add_right h2 a,\nhave f2 : (-a) + a = 0 := by ring,\nrw f2 at h2',\nhave thing : 0 < (b+a)*(b+(-a)) := by {exact mul_pos' h2' h1'},\nhave soandso : (b+a)*(b+(-a)) = b^2-a^2 := by ring,\nrw soandso at thing,\nhave res := add_lt_add_right thing (a^2),\nrw zero_add at res,\nhave th' : b^2-a^2+a^2 = b^2 := by ring,\nrw th' at res,\nexact res,\nend\n\ndef isLC (a p d : \u2115) : Prop := 0 < d \u2227 (\u2203(x:\u2124), (\u2203(y:\u2124), (x*a + y*p = d)))\n\n-- The following lemmas show that the *smallest* positive integer linear\n-- combination of a and b is a common divisor of a and b.\n\nlemma bezout (a b d : \u2115) (h_pos : 0 < d)\n  (h1 : \u2203(x:\u2124), (\u2203(y:\u2124), (x*a + y*b = d)))\n  (h2 : \u2200(d':\u2115), (0 < d' \u2227 \u2203(x:\u2124), (\u2203(y:\u2124), (x*a + y*b = d'))) \u2192 d \u2264 d') :\n  divides d a :=\nbegin\nhave r1 := div_alg a d h_pos,\ncases r1 with r hr,\ncases hr with q hq,\ncases hq with hq1 hq2,\nhave htr := pos_or_zero r,\ncases htr with htr1 htr2,\nexfalso,\nhave claim1 : (a:\u2124)-d*q = r,\nrw hq1,\npush_cast,\nring,\ncases h1 with x_ex hx,\ncases hx with y_ex hy,\nhave claim2 : (1-x_ex*q)*a + (-y_ex*q)*b = r,\nrw (eq.symm claim1),\nrw (eq.symm hy),\nring,\nhave thing := h2(r),\nhave EG : \u2203 (x y : \u2124), x * \u2191a + y * \u2191b = \u2191r,\nuse (1 - x_ex * q),\nuse (-y_ex * q),\nexact claim2,\nhave concl := thing(\u27e8htr1, EG\u27e9),\nhave ir1 := lt_of_le_of_lt concl hq2,\nhave ir2 := lt_irrefl d,\nexact ir2(ir1),\nrw htr2 at hq1,\nrw add_zero at hq1,\nrw divides,\nuse q,\nrw hq1,\nend\n\n-- The above shows that d divides a.\n-- Now we apply it to show d divides both of them, without\n-- rewriting the entire argument.\n\nlemma bezout_doub (a b d : \u2115) (h_pos : 0 < d)\n  (h1 : \u2203(x:\u2124), (\u2203(y:\u2124), (x*a + y*b = d)))\n  (h2 : \u2200(d':\u2115), (0 < d' \u2227 \u2203(x:\u2124), (\u2203(y:\u2124), (x*a + y*b = d'))) \u2192 d \u2264 d') :\n  divides d a \u2227 divides d b :=\nbegin\nsplit,\nexact bezout a b d h_pos h1 h2,\nhave h1_swap : \u2203 (x y : \u2124), x * b + y * a = d,\ncases h1 with xex h1a,\ncases h1a with yex h1b,\nuse yex,\nuse xex,\nrw (eq.symm h1b),\nrw add_comm,\nhave h2_swap : \u2200 (d' : \u2115), (0 < d' \u2227 \u2203 (x y : \u2124), x * b + y * a = d') \u2192 d \u2264 d',\nintro d',\nintro f,\ncases f with f1 f2,\nhave f2_swap : \u2203 (x y : \u2124), x * a + y * b = d',\ncases f2 with xex f2a,\ncases f2a with yex f2b,\nuse yex,\nuse xex,\nrw (eq.symm f2b),\nrw add_comm,\nhave thing := h2(d'),\nexact thing(\u27e8f1, f2_swap\u27e9),\nexact bezout b a d h_pos h1_swap h2_swap,\nend\n\nlemma bezout1 (a p : \u2115) (hp : prime' p) (ha : \u00ac(divides p a)) :\n  \u2203(x:\u2124), (\u2203(y:\u2124), (x*a + y*p = 1)) :=\nbegin\nrw prime' at hp,\ncases hp with hp1 hp2,\nhave zero_lt_one := nat.lt_succ_self 0,\nhave p_pos := lt_trans zero_lt_one hp1,\nhave dh : \u2203 (d : \u2115), 0 < d \u2227 \u2203 (x y : \u2124), x * \u2191a + y * \u2191p = \u2191d := LCex a p p_pos,\nlet d := nat.find(dh),\nhave dx : 0 < d \u2227 \u2203 (x y : \u2124), x * \u2191a + y * \u2191p = \u2191d := nat.find_spec dh,\nhave dm : \u2200 d', (0 < d' \u2227 \u2203 (x y : \u2124), x * \u2191a + y * \u2191p = \u2191d') \u2192 d \u2264 d' := \u03bb d', nat.find_min' dh,\ncases dx with d_pos dx2,\nhave dividing := bezout_doub a p d d_pos dx2 dm,\ncases dividing with div1 div2,\nhave concl := hp2(d)(div2),\ncases concl with c1 c2,\ncases dx2 with xex dx3,\ncases dx3 with yex dx4,\nuse xex,\nuse yex,\nrw c1 at dx4,\nnorm_cast at dx4,\nexact dx4,\nexfalso,\nrw c2 at div1,\nexact ha(div1),\nend\n\nlemma neg_one_is_square (p : \u2115) (hp : prime' p) (hm : divides 4 (p-1)) :\n  \u2203 x, (0 < x \u2227 x < p \u2227 divides p (x^2+1)) :=\nbegin\nsorry -- when I tried to import quadratic_reciprocity, memory was overloaded\nend\n\nlemma nat_square_sep (a b : \u2115) (a_pos : 0 < a) (bound : a < b) : a^2 + 1 < b^2 :=\nbegin\nhave b_pos := lt_trans a_pos bound,\nhave st1 := nat.mul_lt_mul_of_pos_right bound b_pos,\nhave st2 := nat.mul_lt_mul_of_pos_left bound a_pos,\nhave st2' := nat.succ_le_of_lt st2,\nhave res := lt_of_le_of_lt st2' st1,\nrw nat.pow_two,\nrw nat.pow_two,\nexact res,\nend\n\ntheorem mult_sum_of_two_squares (p : \u2115) (hp : prime' p) (hm : divides 4 (p-1)) :\n  \u2203 m, (0 < m \u2227 m < p \u2227 \u2203 x, \u2203 y, m*p = x^2+y^2) :=\nbegin\nhave q := neg_one_is_square p hp hm,\ncases q with a ka,\nrw divides at ka,\ncases ka with a_pos ka1,\ncases ka1 with a_bound ka2,\ncases ka2 with n kb,\nuse n,\nsplit,\nhave zero_lt_one := nat.lt_succ_self 0,\nhave posmul := nat.mul_lt_mul_of_pos_left a_pos a_pos,\nrw mul_zero at posmul,\nhave summing := add_lt_add_right posmul 1,\nrw zero_add at summing,\nhave res := lt_trans zero_lt_one summing,\nrw nat.pow_two at kb,\nrw (eq.symm kb) at res,\nhave n_pos_zero := pos_or_zero n,\ncases n_pos_zero with n_pos n_zero,\nexact n_pos,\nexfalso,\nrw n_zero at res,\nrw mul_zero at res,\nexact lt_irrefl 0 res,\nsplit,\nhave st := nat_square_sep a p a_pos a_bound,\nrw (eq.symm kb) at st,\nrw nat.pow_two at st,\nhave tri := lt_trichotomy p n,\ncases tri with tri1 tri2,\nexfalso,\nhave tri1a := nat.mul_lt_mul_of_pos_left tri1 (lt.trans a_pos a_bound),\nhave tri1b := lt.trans st tri1a,\nexact lt_irrefl (p*n) tri1b,\ncases tri2 with tri3 tri4,\nexfalso,\nrw tri3 at st,\nexact lt_irrefl (n*n) st,\nexact tri4,\nuse a,\nuse 1,\nrw mul_comm,\nrw kb,\nring,\nend\n\nlemma prelim (x y : \u2115) (h : x < y) :\n  2 * (x ^ 2 + y ^ 2) = (y + x) ^ 2 + (y - x) ^ 2 :=\nbegin\napply int.coe_nat_inj,\npush_cast,\nrw int.coe_nat_sub (le_of_lt h),\nring,\nsimp,\nend\n\nlemma halving_first (n x y : \u2115) (h : x < y) (h1 : 2*n = x^2 + y^2) :\n  \u2203a:\u2115, \u2203b:\u2115, n = a^2 + b^2 :=\nbegin\nhave zero_lt_two := lt_trans (nat.lt_succ_self 0) (nat.lt_succ_self 1),\nhave xeo := even_or_odd x,\nhave yeo := even_or_odd y,\ncases xeo with x_even x_odd,\ncases yeo with y_even y_odd,\nhave sum_even := even_plus_even_is_even y x \u27e8y_even, x_even\u27e9,\nhave diff_even := even_minus_even_is_even y x \u27e8y_even, x_even, le_of_lt h\u27e9,\nrw even at sum_even,\ncases sum_even with sum' sum_ev,\nrw even at diff_even,\ncases diff_even with diff' diff_ev,\nuse sum',\nuse diff',\nhave claim : 2*n = 2*(sum'^2 + diff'^2),\nrw h1,\nhave claim' : 2*(x^2+y^2) = 4*(sum'^2+diff'^2),\nhave thing : 4*(sum'^2+diff'^2) = (2*sum')^2+(2*diff')^2 := by ring,\nrw thing,\nrw (eq.symm sum_ev),\nrw (eq.symm diff_ev),\nexact prelim x y h,\nhave thing : 4*(sum'^2+diff'^2) = 2*(2*(sum'^2+diff'^2)) := by ring,\nrw thing at claim',\nexact mul_cancel 2 (x^2+y^2) (2*(sum'^2+diff'^2)) claim' zero_lt_two,\nexact mul_cancel 2 n (sum'^2+diff'^2) claim zero_lt_two,\n\nexfalso,\nhave xsq_even := even_times_nat_is_even x x x_even,\nhave ysq_odd := odd_times_odd_is_odd y y \u27e8y_odd, y_odd\u27e9,\nhave sum_odd := even_plus_odd_is_odd (x*x) (y*y) \u27e8xsq_even, ysq_odd\u27e9,\nrw nat.pow_two at h1,\nrw nat.pow_two at h1,\nhave claim : even (x*x+y*y) := by {rw even, use n, rw h1},\nexact not_both_even_odd (x*x+y*y) \u27e8claim, sum_odd\u27e9,\ncases yeo with y_even y_odd,\n\nexfalso,\nhave xsq_odd := odd_times_odd_is_odd x x \u27e8x_odd, x_odd\u27e9,\nhave ysq_even := even_times_nat_is_even y y y_even,\nhave sum_odd := odd_plus_even_is_odd (x*x) (y*y) \u27e8xsq_odd, ysq_even\u27e9,\nrw nat.pow_two at h1,\nrw nat.pow_two at h1,\nhave claim : even (x*x+y*y) := by {rw even, use n, rw h1},\nexact not_both_even_odd (x*x+y*y) \u27e8claim, sum_odd\u27e9,\n\nhave sum_even := odd_plus_odd_is_even y x \u27e8y_odd, x_odd\u27e9,\nhave diff_even := odd_minus_odd_is_even y x \u27e8y_odd, x_odd, le_of_lt h\u27e9,\nrw even at sum_even,\ncases sum_even with sum' sum_ev,\nrw even at diff_even,\ncases diff_even with diff' diff_ev,\nuse sum',\nuse diff',\nhave claim : 2*n = 2*(sum'^2 + diff'^2),\nrw h1,\nhave claim' : 2*(x^2+y^2) = 4*(sum'^2+diff'^2),\nhave thing : 4*(sum'^2+diff'^2) = (2*sum')^2+(2*diff')^2 := by ring,\nrw thing,\nrw (eq.symm sum_ev),\nrw (eq.symm diff_ev),\nexact prelim x y h,\nhave thing : 4*(sum'^2+diff'^2) = 2*(2*(sum'^2+diff'^2)) := by ring,\nrw thing at claim',\nexact mul_cancel 2 (x^2+y^2) (2*(sum'^2+diff'^2)) claim' zero_lt_two,\nexact mul_cancel 2 n (sum'^2+diff'^2) claim zero_lt_two,\nend\n\n-- halving just applies halving_first several times to rid the assumption\n-- of the comparison on x and y.\n\nlemma halving (n x y : \u2115) (h1 : 2*n = x^2 + y^2) :\n  \u2203a:\u2115, \u2203b:\u2115, n = a^2 + b^2 :=\nbegin\nhave ltr := lt_trichotomy x y,\ncases ltr with ltr' ltr1,\nexact halving_first n x y ltr' h1,\ncases ltr1 with ltr2 ltr3,\nuse x,\nuse 0,\nrw (eq.symm ltr2) at h1,\nhave claim : x^2 + x^2 = 2*(x^2) := by ring,\nrw claim at h1,\nhave zero_lt_two := lt_trans (nat.lt_succ_self 0) (nat.lt_succ_self 1),\nhave thing := mul_cancel 2 n (x^2) h1 zero_lt_two,\nrw thing,\nring,\nrw add_comm at h1,\nexact halving_first n y x ltr3 h1,\nend\n\nlemma ineq's (n k : \u2115) (h1 : 0 < 2*n) (h2 : 2*n < k) :\n  0 < n \u2227 n < k :=\nbegin\nsplit,\nhave pz := pos_or_zero n,\ncases pz with pz1 pz2,\nexact pz1,\nexfalso,\nrw pz2 at h1,\nrw mul_zero at h1,\nexact lt_irrefl 0 h1,\nhave ltr := lt_trichotomy n k,\ncases ltr with ltr' ltr1,\nexact ltr',\nexfalso,\ncases ltr1 with ltr2 ltr3,\nrw ltr2 at h2,\nhave claim : k \u2264 2*k,\nhave thing := add_le_add_left (zero_le k) k,\nrw add_zero at thing,\nhave thing' : k + k = 2*k := by ring,\nrw thing' at thing,\nexact thing,\nhave thing := lt_of_le_of_lt claim h2,\nexact lt_irrefl k thing,\nhave zero_lt_two : 0 < 2 := by {\n  exact lt_trans (nat.lt_succ_self 0) (nat.lt_succ_self 1)\n},\nhave thing := mul_lt_mul_of_pos_left ltr3 zero_lt_two,\nhave h2' := lt_trans thing h2,\nhave claim : k \u2264 2*k,\nhave thing := add_le_add_left (zero_le k) k,\nrw add_zero at thing,\nhave thing' : k + k = 2*k := by ring,\nrw thing' at thing,\nexact thing,\nhave thing := lt_of_le_of_lt claim h2',\nexact lt_irrefl k thing,\nend\n\ntheorem sum_of_two_squares (p : \u2115) (hp : prime' p) (hm : divides 4 (p-1)) :\n  \u2203 x, \u2203 y, p = x^2+y^2 :=\nbegin\nlet m := nat.find(mult_sum_of_two_squares p hp hm),\nhave mx : 0 < m \u2227 m < p \u2227 \u2203 x, \u2203 y, m*p = x^2+y^2 := nat.find_spec(mult_sum_of_two_squares p hp hm),\nhave mm : \u2200 m', (0 < m' \u2227 m' < p \u2227 \u2203 x, \u2203 y, m'*p = x^2+y^2) \u2192 m \u2264 m' := \u03bb d', nat.find_min'(mult_sum_of_two_squares p hp hm),\nhave meo := even_or_odd m,\ncases mx with mx1 mx1',\ncases mx1' with mx2 mx3,\ncases meo with m_even m_odd,\nexfalso,\nrw even at m_even,\ncases m_even with m' m_ev,\ncases mx3 with xex mx3',\ncases mx3' with yex mx4,\n\nrw m_ev at mx4,\nrw mul_assoc at mx4,\nhave half := halving (m'*p) xex yex mx4,\nrw m_ev at mx1,\nrw m_ev at mx2,\nhave ineqs := ineq's m' p mx1 mx2,\ncases ineqs with ineq1 ineq2,\nhave fact := mm m' \u27e8ineq1, ineq2, half\u27e9,\nrw m_ev at fact,\nhave fact2 := add_lt_add_left ineq1 m',\nrw add_zero at fact2,\nhave ir := lt_of_le_of_lt fact fact2,\nhave claim : m' + m' = 2 * m' := by ring,\nrw claim at ir,\nexact lt_irrefl (2*m') ir,\n\n-- Now for the case that m is odd.\n\nby_cases is_m_one : m = 1,\nrw is_m_one at mx3,\ncases mx3 with xex mx3',\ncases mx3' with yex mx3'',\nrw one_mul at mx3'',\nuse xex,\nuse yex,\nexact mx3'',\n\n-- Now for the case that m is odd and > 1.\n\ncases mx3 with xex mx3',\ncases mx3' with yex mx4,\nhave xd := div_alg_near_zero xex m mx1 m_odd,\ncases xd with qx xd'',\ncases xd'' with x1 xd',\nhave yd := div_alg_near_zero yex m mx1 m_odd,\ncases yd with qy yd'',\ncases yd'' with y1 yd',\ncases xd' with xd1 xd1',\ncases xd1' with xd2 xd3,\ncases yd' with yd1 yd1',\ncases yd1' with yd2 yd3,\n\nhave claim : \u2203(n:\u2124), (m:\u2124)*n = x1^2+y1^2,\nuse (p:\u2124) - (xex+x1)*qx - (yex+y1)*qy,\nhave thing0 : \u2191m * (\u2191p - (\u2191xex + x1) * qx - (\u2191yex + y1) * qy)\n  = (\u2191m * \u2191p) - \u2191m * (\u2191xex + x1) * qx - \u2191m * (\u2191yex + y1) * qy := by ring,\nrw thing0,\nhave thing0' : (m:\u2124)*p = (xex:\u2124)^2+yex^2 := by {norm_cast, exact mx4},\nhave thing1 : x1 = (xex:\u2124) - (m:\u2124)*qx := by {rw xd1, ring},\nhave thing2 : y1 = (yex:\u2124) - (m:\u2124)*qy := by {rw yd1, ring},\nrw thing1,\nrw thing2,\nrw thing0',\nring,\n\ncases claim with n cn,\n\nhave n_pos : 0 < n,\nhave ltr := lt_trichotomy 0 n,\ncases ltr with ltr1 ltr1',\nexact ltr1,\nexfalso,\ncases ltr1' with ltr2 ltr3,\nrw (eq.symm ltr2) at cn,\nrw mul_zero at cn,\nhave x1sq_nn := square_nonneg x1,\nhave y1sq_nn := square_nonneg y1,\nhave clema := add_le_add_right x1sq_nn (y1^2),\nrw zero_add at clema,\nrw (eq.symm cn) at clema,\nhave y1sq_zero := le_antisymm clema y1sq_nn,\nhave y1_zero : 0 = y1 := by {\n  by_cases contr : 0 = y1,\n  exact contr,\n  exfalso,\n  have thing := nonzero_square_pos y1 contr,\n  rw y1sq_zero at thing,\n  exact lt_irrefl 0 thing\n},\nhave clema' := add_le_add_left y1sq_nn (x1^2),\nrw add_zero at clema',\nrw (eq.symm cn) at clema',\nhave x1sq_zero := le_antisymm clema' x1sq_nn,\nhave x1_zero : 0 = x1 := by {\n  by_cases contr : 0 = x1,\n  exact contr,\n  exfalso,\n  have thing := nonzero_square_pos x1 contr,\n  rw x1sq_zero at thing,\n  exact lt_irrefl 0 thing\n},\nrw (eq.symm x1_zero) at xd1,\nrw add_zero at xd1,\nrw (eq.symm y1_zero) at yd1,\nrw add_zero at yd1,\nhave mx4' : (m:\u2124)*p = (xex:\u2124)^2 + yex^2 := by {norm_cast, exact mx4},\nrw xd1 at mx4',\nrw yd1 at mx4',\nhave mx4'' : (m:\u2124)*p = (m:\u2124)*(m*(qx^2+qy^2)) := by {rw mx4', ring},\nhave int_m_pos : (0:\u2124) < (m:\u2124) := by {norm_cast, exact mx1},\nhave thing := int_mul_cancel m p (m*(qx^2+qy^2)) mx4'' int_m_pos,\nhave qx_nat := square_eq_sq_of_nat qx,\ncases qx_nat with qxn qx_nat',\nhave qy_nat := square_eq_sq_of_nat qy,\ncases qy_nat with qyn qy_nat',\nrw qx_nat' at thing,\nrw qy_nat' at thing,\nhave thing' := int.coe_nat_inj thing,\nhave oth : divides m p := by {\n  rw divides, use qxn * (qxn * 1) + qyn * (qyn * 1), exact eq.symm thing'},\nrw prime' at hp,\ncases hp with hp1 hp2,\nhave conc := hp2 m oth,\ncases conc with conc1 conc2,\nexact is_m_one conc1,\nrw conc2 at mx2,\nexact lt_irrefl p mx2,\n-- FINALLY confirmed n can't be zero.\nhave x1sq_nn := square_nonneg x1,\nhave y1sq_nn := square_nonneg y1,\nhave clema := add_le_add_right x1sq_nn (y1^2),\nrw zero_add at clema,\nrw (eq.symm cn) at clema,\nhave clema' := le_trans y1sq_nn clema,\nhave mx1' : (m:\u2124) > 0 := by {norm_cast, exact mx1},\nhave thing := linarith.mul_neg ltr3 mx1',\nexact lt_irrefl 0 (lt_of_le_of_lt clema' thing),\n\nhave n_lt_m : n < m,\nhave two_squared_is_four : (2:\u2124)^2 = (4:\u2124) := by ring,\nhave negstx : (-2)*x1=-(2*x1) := by ring,\nrw negstx at xd3,\nhave squarerelx := abs_thing (2*x1) (m:\u2124) xd2 xd3,\nrw mul_pow at squarerelx,\nrw two_squared_is_four at squarerelx,\nhave negsty : (-2)*y1=-(2*y1) := by ring,\nrw negsty at yd3,\nhave squarerely := abs_thing (2*y1) (m:\u2124) yd2 yd3,\nrw mul_pow at squarerely,\nrw two_squared_is_four at squarerely,\nhave cn'4 : 4*((m:\u2124)*n) = 4*(x1^2+y1^2) := by {rw cn},\nrw mul_add at cn'4,\nhave compare := add_lt_add squarerelx squarerely,\nrw (eq.symm cn'4) at compare,\nhave th'1 : 4*((m:\u2124)*n)=(2*(m:\u2124))*(2*n) := by ring,\nrw th'1 at compare,\nhave th'2 : (m:\u2124)^2+m^2 = (2*(m:\u2124))*m := by ring,\nrw th'2 at compare,\nhave thong : 0 < 2*(m:\u2124) := by {\n  norm_cast,\n  have mx1' := add_lt_add_left mx1 m,\n  rw add_zero at mx1',\n  have th : 2*m=m+m := by ring,\n  rw th,\n  exact (lt_trans mx1 mx1')\n},\nhave res := int_mul_cancel_lt (2*(m:\u2124)) (2*n) (m:\u2124) compare thong,\nhave final : n < 2*n := by {\n  have fin := add_lt_add_left n_pos n,\n  rw add_zero at fin,\n  have th : 2*n=n+n := by ring,\n  rw th, exact fin\n},\nexact lt_trans final res,\n\n-- Now we can finally carry on with the rest.\n-- We just need to show n*p is a sum of two squares.\nhave first_divis_lemma : \u2203(a:\u2124),(m:\u2124)*a=xex*x1+yex*y1,\nuse p - xex*qx - yex*qy,\nhave claim : (m:\u2124)*(p-xex*qx-yex*qy) = (m:\u2124)*p - (m:\u2124)*(xex*qx+yex*qy) := by ring,\nrw claim,\nhave mx4' : ((m:\u2124)*p = (xex:\u2124)^2+yex^2) := by {norm_cast, exact mx4},\nrw mx4',\nhave xd1' : x1 = (xex:\u2124)-((m:\u2124)*qx) := by {rw xd1, ring},\nrw xd1',\nhave yd1' : y1 = (yex:\u2124)-((m:\u2124)*qy) := by {rw yd1, ring},\nrw yd1',\nring,\n\nhave second_divis_lemma : \u2203(b:\u2124),(m:\u2124)*b=xex*y1-yex*x1,\nuse (yex:\u2124)*qx - (xex:\u2124)*qy,\nhave xd1' : x1 = (xex:\u2124)-((m:\u2124)*qx) := by {rw xd1, ring},\nrw xd1',\nhave yd1' : y1 = (yex:\u2124)-((m:\u2124)*qy) := by {rw yd1, ring},\nrw yd1',\nring,\n\ncases first_divis_lemma with a fdl,\ncases second_divis_lemma with b sdl,\nhave claim1 : ((m:\u2124)^2)*(n*p) = (xex*x1+yex*y1)^2 + (xex*y1-yex*x1)^2 := by {\n  have thong : ((m:\u2124)^2)*(n*p) = ((m:\u2124)*n)*((m:\u2124)*p) := by ring,\n  rw thong,\n  have mx4' : ((m:\u2124)*p = (xex:\u2124)^2+yex^2) := by {norm_cast, exact mx4},\n  rw cn,\n  rw mx4',\n  ring\n},\nrw (eq.symm fdl) at claim1,\nrw (eq.symm sdl) at claim1,\nhave dist : ((m:\u2124)*a)^2 + ((m:\u2124)*b)^2 = (m:\u2124)^2*(a^2+b^2) := by ring,\nrw dist at claim1,\nhave mx1' : 0 < (m:\u2124) := by {norm_cast, exact mx1},\nby_cases could_it_be : (0:\u2124) = (m:\u2124),\nexfalso,\nrw could_it_be at mx1',\nexact lt_irrefl (m:\u2124) mx1',\nhave sq_pos := nonzero_square_pos (m:\u2124) could_it_be,\nhave res := int_mul_cancel ((m:\u2124)^2) (n*(p:\u2124)) (a^2+b^2) claim1 sq_pos,\nhave n_can_be_coed := int.eq_coe_of_zero_le (le_of_lt n_pos),\ncases n_can_be_coed with n' nc,\nhave ext_claim : \u2203 (x y : \u2115), n'*p = x^2+y^2 := by {\n  have a_nat := square_eq_sq_of_nat a,\n  cases a_nat with aex a_n,\n  have b_nat := square_eq_sq_of_nat b,\n  cases b_nat with bex b_n,\n  use aex, use bex,\n  apply int.coe_nat_inj,\n  push_cast,\n  rw (eq.symm a_n),\n  rw (eq.symm b_n),\n  rw (eq.symm nc), exact res\n},\nrw nc at n_pos,\nhave n_pos' := int.coe_nat_lt.mp n_pos,\nrw nc at n_lt_m,\nhave n_lt_m' := int.coe_nat_lt.mp n_lt_m,\nhave n_lt_p := lt_trans n_lt_m' mx2,\nhave final_thing := mm n' \u27e8n_pos', n_lt_p, ext_claim\u27e9,\nexfalso,\nexact lt_irrefl m (lt_of_le_of_lt final_thing n_lt_m'),\n\nend", "meta": {"author": "ReptDecGuy", "repo": "Nicholas", "sha": "cc2da306f188cd42f7360de9d69231aef3d4ee07", "save_path": "github-repos/lean/ReptDecGuy-Nicholas", "path": "github-repos/lean/ReptDecGuy-Nicholas/Nicholas-cc2da306f188cd42f7360de9d69231aef3d4ee07/fermat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7241353085905041}}
{"text": "open lean\nopen tactic\nopen interactive\n\n@[intro] lemma option_bind_some_back {\u03b1 \u03b2 : Type} :\n  forall (o1 : option \u03b1) (o2 : \u03b1 \u2192 option \u03b2) v v',\n    o1 = some v \u2192\n    o2 v = some v' \u2192\n    o1 >>= o2 = some v' :=\nbegin\n  intros,\n  rw a,\n  simp [bind, has_bind.bind, option.bind],\n  rw a_1,\nend\n\nlemma option_bind_some {\u03b1 \u03b2 : Type} :\n  forall (o1 : option \u03b1) (o2 : \u03b1 \u2192 option \u03b2) v,\n    o1 >>= o2 = some v \u2192\n    exists v', o1 = some v' \u2227\n      o2 v' = some v :=\nbegin\n  intros, destruct o1 ; intros,\n  unfold bind at *, subst a_1,\n  dsimp [option.bind] at *,\n  cases a,\n  subst a_1,\n  unfold bind at *,\n  dsimp [option.bind] at *,\n  constructor,\n  split, reflexivity,\n  assumption,\nend\n\nmeta def simp_option (hyp_name : parse lean.parser.ident) : tactic unit :=\ndo h \u2190 get_local hyp_name,\n   ty \u2190 tactic.infer_type h,\n   (a :: b :: o1 :: o2 :: v :: _) \u2190 tactic.match_expr\n     ``(fun (a b : Type) (o1 : option a) (o2 : a \u2192 option b) (v : b), has_bind.bind o1 o2 = some v) ty | tactic.failed,\n   n \u2190 get_unused_name `o,\n   prf \u2190 to_expr ``(option_bind_some %%o1 %%o2 %%v %%h),\n   tactic.note n none prf,\n   vn \u2190 get_unused_name `v,\n   ex \u2190 get_local n,\n   cases ex [vn, n],\n   conj \u2190 get_local n,\n   r \u2190 get_unused_name `right,\n   l \u2190 get_unused_name `left,\n   cases conj [l, r],\n   get_local hyp_name >>= clear,\n   try (get_local l >>= dsimp_hyp),\n   try (get_local r >>= dsimp_hyp),\n   return ()\n", "meta": {"author": "uwplse", "repo": "struct_tact", "sha": "22188ea2e97705d1185f75dde24e6bab88054ab0", "save_path": "github-repos/lean/uwplse-struct_tact", "path": "github-repos/lean/uwplse-struct_tact/struct_tact-22188ea2e97705d1185f75dde24e6bab88054ab0/src/struct_tact/simp_option.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7240904941968844}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport order.lattice\n\n/-!\n# `max` and `min`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves basic properties about maxima and minima on a `linear_order`.\n\n## Tags\n\nmin, max\n-/\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\n\nattribute [simp] max_eq_left max_eq_right min_eq_left min_eq_right\n\nsection\nvariables [linear_order \u03b1] [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a b c d : \u03b1}\n\n-- translate from lattices to linear orders (sup \u2192 max, inf \u2192 min)\n@[simp] lemma le_min_iff : c \u2264 min a b \u2194 c \u2264 a \u2227 c \u2264 b := le_inf_iff\n@[simp] lemma le_max_iff : a \u2264 max b c \u2194 a \u2264 b \u2228 a \u2264 c := le_sup_iff\n@[simp] lemma min_le_iff : min a b \u2264 c \u2194 a \u2264 c \u2228 b \u2264 c := inf_le_iff\n@[simp] lemma max_le_iff : max a b \u2264 c \u2194 a \u2264 c \u2227 b \u2264 c := sup_le_iff\n@[simp] lemma lt_min_iff : a < min b c \u2194 a < b \u2227 a < c := lt_inf_iff\n@[simp] lemma lt_max_iff : a < max b c \u2194 a < b \u2228 a < c := lt_sup_iff\n@[simp] lemma min_lt_iff : min a b < c \u2194 a < c \u2228 b < c := inf_lt_iff\n@[simp] lemma max_lt_iff : max a b < c \u2194 a < c \u2227 b < c := sup_lt_iff\nlemma max_le_max : a \u2264 c \u2192 b \u2264 d \u2192 max a b \u2264 max c d := sup_le_sup\nlemma min_le_min : a \u2264 c \u2192 b \u2264 d \u2192 min a b \u2264 min c d := inf_le_inf\nlemma le_max_of_le_left : a \u2264 b \u2192 a \u2264 max b c := le_sup_of_le_left\nlemma le_max_of_le_right : a \u2264 c \u2192 a \u2264 max b c := le_sup_of_le_right\nlemma lt_max_of_lt_left (h : a < b) : a < max b c := h.trans_le (le_max_left b c)\nlemma lt_max_of_lt_right (h : a < c) : a < max b c := h.trans_le (le_max_right b c)\nlemma min_le_of_left_le : a \u2264 c \u2192 min a b \u2264 c := inf_le_of_left_le\nlemma min_le_of_right_le : b \u2264 c \u2192 min a b \u2264 c := inf_le_of_right_le\nlemma min_lt_of_left_lt (h : a < c) : min a b < c := (min_le_left a b).trans_lt h\nlemma min_lt_of_right_lt (h : b < c) : min a b < c := (min_le_right a b).trans_lt h\nlemma max_min_distrib_left : max a (min b c) = min (max a b) (max a c) := sup_inf_left\nlemma max_min_distrib_right : max (min a b) c = min (max a c) (max b c) := sup_inf_right\nlemma min_max_distrib_left : min a (max b c) = max (min a b) (min a c) := inf_sup_left\nlemma min_max_distrib_right : min (max a b) c = max (min a c) (min b c) := inf_sup_right\nlemma min_le_max : min a b \u2264 max a b := le_trans (min_le_left a b) (le_max_left a b)\n\n@[simp] lemma min_eq_left_iff : min a b = a \u2194 a \u2264 b := inf_eq_left\n@[simp] lemma min_eq_right_iff : min a b = b \u2194 b \u2264 a := inf_eq_right\n@[simp] lemma max_eq_left_iff : max a b = a \u2194 b \u2264 a := sup_eq_left\n@[simp] lemma max_eq_right_iff : max a b = b \u2194 a \u2264 b := sup_eq_right\n\n/-- For elements `a` and `b` of a linear order, either `min a b = a` and `a \u2264 b`,\n    or `min a b = b` and `b < a`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma min_cases (a b : \u03b1) : min a b = a \u2227 a \u2264 b \u2228 min a b = b \u2227 b < a :=\nbegin\n  by_cases a \u2264 b,\n  { left,\n    exact \u27e8min_eq_left h, h\u27e9 },\n  { right,\n    exact \u27e8min_eq_right (le_of_lt (not_le.mp h)), (not_le.mp h)\u27e9 }\nend\n\n/-- For elements `a` and `b` of a linear order, either `max a b = a` and `b \u2264 a`,\n    or `max a b = b` and `a < b`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma max_cases (a b : \u03b1) : max a b = a \u2227 b \u2264 a \u2228 max a b = b \u2227 a < b := @min_cases \u03b1\u1d52\u1d48 _ a b\n\nlemma min_eq_iff : min a b = c \u2194 a = c \u2227 a \u2264 b \u2228 b = c \u2227 b \u2264 a :=\nbegin\n  split,\n  { intro h,\n    refine or.imp (\u03bb h', _) (\u03bb h', _) (le_total a b);\n    exact \u27e8by simpa [h'] using h, h'\u27e9 },\n  { rintro (\u27e8rfl, h\u27e9|\u27e8rfl, h\u27e9);\n    simp [h] }\nend\n\nlemma max_eq_iff : max a b = c \u2194 a = c \u2227 b \u2264 a \u2228 b = c \u2227 a \u2264 b := @min_eq_iff \u03b1\u1d52\u1d48 _ a b c\n\nlemma min_lt_min_left_iff : min a c < min b c \u2194 a < b \u2227 a < c :=\nby { simp_rw [lt_min_iff, min_lt_iff, or_iff_left (lt_irrefl _)],\n  exact and_congr_left (\u03bb h, or_iff_left_of_imp h.trans) }\n\nlemma min_lt_min_right_iff : min a b < min a c \u2194 b < c \u2227 b < a :=\nby simp_rw [min_comm a, min_lt_min_left_iff]\n\nlemma max_lt_max_left_iff : max a c < max b c \u2194 a < b \u2227 c < b := @min_lt_min_left_iff \u03b1\u1d52\u1d48 _ _ _ _\nlemma max_lt_max_right_iff : max a b < max a c \u2194 b < c \u2227 a < c := @min_lt_min_right_iff \u03b1\u1d52\u1d48 _ _ _ _\n\n/-- An instance asserting that `max a a = a` -/\ninstance max_idem : is_idempotent \u03b1 max := by apply_instance -- short-circuit type class inference\n\n/-- An instance asserting that `min a a = a` -/\ninstance min_idem : is_idempotent \u03b1 min := by apply_instance -- short-circuit type class inference\n\nlemma min_lt_max : min a b < max a b \u2194 a \u2260 b := inf_lt_sup\n\nlemma max_lt_max (h\u2081 : a < c) (h\u2082 : b < d) : max a b < max c d :=\nby simp [lt_max_iff, max_lt_iff, *]\n\nlemma min_lt_min (h\u2081 : a < c) (h\u2082 : b < d) : min a b < min c d := @max_lt_max \u03b1\u1d52\u1d48 _ _ _ _ _ h\u2081 h\u2082\n\ntheorem min_right_comm (a b c : \u03b1) : min (min a b) c = min (min a c) b :=\nright_comm min min_comm min_assoc a b c\n\ntheorem max.left_comm (a b c : \u03b1) : max a (max b c) = max b (max a c) :=\nleft_comm max max_comm max_assoc a b c\n\ntheorem max.right_comm (a b c : \u03b1) : max (max a b) c = max (max a c) b :=\nright_comm max max_comm max_assoc a b c\n\nlemma monotone_on.map_max (hf : monotone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (max a b) = max (f a) (f b) :=\nby cases le_total a b; simp only [max_eq_right, max_eq_left, hf ha hb, hf hb ha, h]\n\nlemma monotone_on.map_min (hf : monotone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (min a b) = min (f a) (f b) :=\nhf.dual.map_max ha hb\n\nlemma antitone_on.map_max (hf : antitone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (max a b) = min (f a) (f b) :=\nhf.dual_right.map_max ha hb\n\nlemma antitone_on.map_min (hf : antitone_on f s) (ha : a \u2208 s) (hb : b \u2208 s) :\n  f (min a b) = max (f a) (f b) :=\nhf.dual.map_max ha hb\n\nlemma monotone.map_max (hf : monotone f) : f (max a b) = max (f a) (f b) :=\nby cases le_total a b; simp [h, hf h]\n\nlemma monotone.map_min (hf : monotone f) : f (min a b) = min (f a) (f b) :=\nhf.dual.map_max\n\nlemma antitone.map_max (hf : antitone f) : f (max a b) = min (f a) (f b) :=\nby cases le_total a b; simp [h, hf h]\n\nlemma antitone.map_min (hf : antitone f) : f (min a b) = max (f a) (f b) :=\nhf.dual.map_max\n\ntheorem min_choice (a b : \u03b1) : min a b = a \u2228 min a b = b :=\nby cases le_total a b; simp *\n\ntheorem max_choice (a b : \u03b1) : max a b = a \u2228 max a b = b :=\n@min_choice \u03b1\u1d52\u1d48 _ a b\n\nlemma le_of_max_le_left {a b c : \u03b1} (h : max a b \u2264 c) : a \u2264 c :=\nle_trans (le_max_left _ _) h\n\nlemma le_of_max_le_right {a b c : \u03b1} (h : max a b \u2264 c) : b \u2264 c :=\nle_trans (le_max_right _ _) h\n\nlemma max_commutative : commutative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_comm\n\nlemma max_associative : associative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_assoc\n\nlemma max_left_commutative : left_commutative (max : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmax_left_comm\n\nlemma min_commutative : commutative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_comm\n\nlemma min_associative : associative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_assoc\n\nlemma min_left_commutative : left_commutative (min : \u03b1 \u2192 \u03b1 \u2192 \u03b1) :=\nmin_left_comm\n\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/min_max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7240904687202939}}
{"text": "/-\nCopyright (c) 2019 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n-/\nimport algebra.order.ring\nimport data.nat.basic\nimport data.set.lattice\nimport order.directed\nimport tactic.monotonicity.basic\n\nvariables {\u03b1 : Type*}\n\n@[mono]\nlemma mul_mono_nonneg {x y z : \u03b1} [ordered_semiring \u03b1]\n  (h' : 0 \u2264 z)\n  (h : x \u2264 y)\n: x * z \u2264 y * z :=\nby apply mul_le_mul_of_nonneg_right; assumption\n\nlemma lt_of_mul_lt_mul_neg_right {a b c : \u03b1}  [linear_ordered_ring \u03b1]\n  (h : a * c < b * c) (hc : c \u2264 0) : b < a :=\nhave nhc : -c \u2265 0, from neg_nonneg_of_nonpos hc,\nhave h2 : -(b * c) < -(a * c), from neg_lt_neg h,\nhave h3 : b * (-c) < a * (-c), from calc\n     b * (-c) = - (b * c)    : by rewrite neg_mul_eq_mul_neg\n          ... < - (a * c)    : h2\n          ... = a * (-c)     : by rewrite neg_mul_eq_mul_neg,\nlt_of_mul_lt_mul_right h3 nhc\n\n@[mono]\nlemma mul_mono_nonpos {x y z : \u03b1} [linear_ordered_ring \u03b1]\n  (h' : z \u2264 0) (h : y \u2264 x) : x * z \u2264 y * z :=\nbegin\n  classical,\n  by_contradiction h'',\n  revert h,\n  apply not_le_of_lt,\n  apply lt_of_mul_lt_mul_neg_right _ h',\n  apply lt_of_not_ge h''\nend\n\n@[mono]\nlemma nat.sub_mono_left_strict {x y z : \u2115}\n  (h' : z \u2264 x)\n  (h : x < y)\n: x - z < y - z :=\nbegin\n  have : z \u2264 y,\n  { transitivity, assumption, apply le_of_lt h, },\n  apply @nat.lt_of_add_lt_add_left z,\n  rw [add_tsub_cancel_of_le,add_tsub_cancel_of_le];\n    solve_by_elim\nend\n\n@[mono]\nlemma nat.sub_mono_right_strict {x y z : \u2115}\n  (h' : x \u2264 z)\n  (h : y < x)\n: z - x < z - y :=\nbegin\n  have h'' : y \u2264 z,\n  { transitivity, apply le_of_lt h, assumption },\n  apply @nat.lt_of_add_lt_add_right _ x,\n  rw [tsub_add_cancel_of_le h'],\n  apply @lt_of_le_of_lt _ _ _ (z - y + y),\n  rw [tsub_add_cancel_of_le h''],\n  apply nat.add_lt_add_left h\nend\n\nopen set\n\nattribute [mono] inter_subset_inter union_subset_union\n                 sUnion_mono bUnion_mono sInter_subset_sInter bInter_mono\n                 image_subset preimage_mono prod_mono monotone_prod seq_mono\n                 image2_subset order_embedding.monotone\nattribute [mono] upper_bounds_mono_set lower_bounds_mono_set\n                 upper_bounds_mono_mem  lower_bounds_mono_mem\n                 upper_bounds_mono  lower_bounds_mono\n                 bdd_above.mono bdd_below.mono\n\nattribute [mono] add_le_add mul_le_mul neg_le_neg\n         mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right\n         imp_imp_imp le_implies_le_of_le_of_le\n         sub_le_sub tsub_le_tsub tsub_le_tsub_right abs_le_abs sup_le_sup\n         inf_le_inf\nattribute [mono left] add_lt_add_of_le_of_lt mul_lt_mul'\nattribute [mono right] add_lt_add_of_lt_of_le mul_lt_mul\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/tactic/monotonicity/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740728, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7240696917748172}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.calculus.mean_value\nimport analysis.special_functions.pow_deriv\nimport analysis.special_functions.sqrt\n\n/-!\n# Collection of convex functions\n\nIn this file we prove that the following functions are convex:\n\n* `strict_convex_on_exp` : The exponential function is strictly convex.\n* `even.convex_on_pow`, `even.strict_convex_on_pow` : For an even `n : \u2115`, `\u03bb x, x ^ n` is convex\n  and strictly convex when `2 \u2264 n`.\n* `convex_on_pow`, `strict_convex_on_pow` : For `n : \u2115`, `\u03bb x, x ^ n` is convex on $[0, +\u221e)$ and\n  strictly convex when `2 \u2264 n`.\n* `convex_on_zpow`, `strict_convex_on_zpow` : For `m : \u2124`, `\u03bb x, x ^ m` is convex on $[0, +\u221e)$ and\n  strictly convex when `m \u2260 0, 1`.\n* `convex_on_rpow`, `strict_convex_on_rpow` : For `p : \u211d`, `\u03bb x, x ^ p` is convex on $[0, +\u221e)$ when\n  `1 \u2264 p` and strictly convex when `1 < p`.\n* `strict_concave_on_log_Ioi`, `strict_concave_on_log_Iio`: `real.log` is strictly concave on\n  $(0, +\u221e)$ and $(-\u221e, 0)$ respectively.\n\n## TODO\n\nFor `p : \u211d`, prove that `\u03bb x, x ^ p` is concave when `0 \u2264 p \u2264 1` and strictly concave when\n`0 < p < 1`.\n-/\n\nopen real set\nopen_locale big_operators\n\n/-- `exp` is strictly convex on the whole real line. -/\nlemma strict_convex_on_exp : strict_convex_on \u211d univ exp :=\nstrict_convex_on_univ_of_deriv2_pos differentiable_exp (\u03bb x, (iter_deriv_exp 2).symm \u25b8 exp_pos x)\n\n/-- `exp` is convex on the whole real line. -/\nlemma convex_on_exp : convex_on \u211d univ exp := strict_convex_on_exp.convex_on\n\n/-- `x^n`, `n : \u2115` is convex on the whole real line whenever `n` is even -/\nlemma even.convex_on_pow {n : \u2115} (hn : even n) : convex_on \u211d set.univ (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_univ_of_deriv2_nonneg (differentiable_pow n),\n  { simp only [deriv_pow', differentiable.mul, differentiable_const, differentiable_pow] },\n  { intro x,\n    obtain \u27e8k, hk\u27e9 := (hn.tsub $ even_bit0 _).exists_two_nsmul _,\n    rw [iter_deriv_pow, finset.prod_range_cast_nat_sub, hk, nsmul_eq_mul, pow_mul'],\n    exact mul_nonneg (nat.cast_nonneg _) (pow_two_nonneg _) }\nend\n\n/-- `x^n`, `n : \u2115` is strictly convex on the whole real line whenever `n \u2260 0` is even. -/\nlemma even.strict_convex_on_pow {n : \u2115} (hn : even n) (h : n \u2260 0) :\n  strict_convex_on \u211d set.univ (\u03bb x : \u211d, x^n) :=\nbegin\n  apply strict_mono.strict_convex_on_univ_of_deriv (differentiable_pow n),\n  rw deriv_pow',\n  replace h := nat.pos_of_ne_zero h,\n  exact strict_mono.const_mul (odd.strict_mono_pow $ nat.even.sub_odd h hn $ nat.odd_iff.2 rfl)\n    (nat.cast_pos.2 h),\nend\n\n/-- `x^n`, `n : \u2115` is convex on `[0, +\u221e)` for all `n` -/\nlemma convex_on_pow (n : \u2115) : convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_of_deriv2_nonneg (convex_Ici _) (continuous_pow n).continuous_on\n    (differentiable_on_pow n),\n  { simp only [deriv_pow'], exact (@differentiable_on_pow \u211d _ _ _).const_mul (n : \u211d) },\n  { intros x hx,\n    rw [iter_deriv_pow, finset.prod_range_cast_nat_sub],\n    exact mul_nonneg (nat.cast_nonneg _) (pow_nonneg (interior_subset hx) _) }\nend\n\n/-- `x^n`, `n : \u2115` is strictly convex on `[0, +\u221e)` for all `n` greater than `2`. -/\nlemma strict_convex_on_pow {n : \u2115} (hn : 2 \u2264 n) : strict_convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^n) :=\nbegin\n  apply strict_mono_on.strict_convex_on_of_deriv (convex_Ici _) (continuous_on_pow _)\n    (differentiable_on_pow n),\n  rw [deriv_pow', interior_Ici],\n  exact \u03bb x (hx : 0 < x) y hy hxy, mul_lt_mul_of_pos_left (pow_lt_pow_of_lt_left hxy hx.le $\n    nat.sub_pos_of_lt hn) (nat.cast_pos.2 $ zero_lt_two.trans_le hn),\nend\n\nlemma finset.prod_nonneg_of_card_nonpos_even\n  {\u03b1 \u03b2 : Type*} [linear_ordered_comm_ring \u03b2]\n  {f : \u03b1 \u2192 \u03b2} [decidable_pred (\u03bb x, f x \u2264 0)]\n  {s : finset \u03b1} (h0 : even (s.filter (\u03bb x, f x \u2264 0)).card) :\n  0 \u2264 \u220f x in s, f x :=\ncalc 0 \u2264 (\u220f x in s, ((if f x \u2264 0 then (-1:\u03b2) else 1) * f x)) :\n  finset.prod_nonneg (\u03bb x _, by\n    { split_ifs with hx hx, by simp [hx], simp at hx \u22a2, exact le_of_lt hx })\n... = _ : by rw [finset.prod_mul_distrib, finset.prod_ite, finset.prod_const_one,\n  mul_one, finset.prod_const, neg_one_pow_eq_pow_mod_two, nat.even_iff.1 h0, pow_zero, one_mul]\n\nlemma int_prod_range_nonneg (m : \u2124) (n : \u2115) (hn : even n) :\n  0 \u2264 \u220f k in finset.range n, (m - k) :=\nbegin\n  rcases hn with \u27e8n, rfl\u27e9,\n  induction n with n ihn, { simp },\n  rw \u2190 two_mul at ihn,\n  rw [\u2190 two_mul, nat.succ_eq_add_one, mul_add, mul_one, bit0, \u2190 add_assoc, finset.prod_range_succ,\n    finset.prod_range_succ, mul_assoc],\n  refine mul_nonneg ihn _, generalize : (1 + 1) * n = k,\n  cases le_or_lt m k with hmk hmk,\n  { have : m \u2264 k + 1, from hmk.trans (lt_add_one \u2191k).le,\n    exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) (sub_nonpos_of_le this) },\n  { exact mul_nonneg (sub_nonneg_of_le hmk.le) (sub_nonneg_of_le hmk) }\nend\n\nlemma int_prod_range_pos {m : \u2124} {n : \u2115} (hn : even n) (hm : m \u2209 Ico (0 : \u2124) n) :\n  0 < \u220f k in finset.range n, (m - k) :=\nbegin\n  refine (int_prod_range_nonneg m n hn).lt_of_ne (\u03bb h, hm _),\n  rw [eq_comm, finset.prod_eq_zero_iff] at h,\n  obtain \u27e8a, ha, h\u27e9 := h,\n  rw sub_eq_zero.1 h,\n  exact \u27e8int.coe_zero_le _, int.coe_nat_lt.2 $ finset.mem_range.1 ha\u27e9,\nend\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` -/\nlemma convex_on_zpow (m : \u2124) : convex_on \u211d (Ioi 0) (\u03bb x : \u211d, x^m) :=\nbegin\n  have : \u2200 n : \u2124, differentiable_on \u211d (\u03bb x, x ^ n) (Ioi (0 : \u211d)),\n    from \u03bb n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),\n  apply convex_on_of_deriv2_nonneg (convex_Ioi 0);\n    try { simp only [interior_Ioi, deriv_zpow'] },\n  { exact (this _).continuous_on },\n  { exact this _ },\n  { exact (this _).const_mul _ },\n  { intros x hx,\n    rw iter_deriv_zpow,\n    refine mul_nonneg _ (zpow_nonneg (le_of_lt hx) _),\n    exact_mod_cast int_prod_range_nonneg _ _ (even_bit0 1) }\nend\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` except `0` and `1`. -/\nlemma strict_convex_on_zpow {m : \u2124} (hm\u2080 : m \u2260 0) (hm\u2081 : m \u2260 1) :\n  strict_convex_on \u211d (Ioi 0) (\u03bb x : \u211d, x^m) :=\nbegin\n  have : \u2200 n : \u2124, differentiable_on \u211d (\u03bb x, x ^ n) (Ioi (0 : \u211d)),\n    from \u03bb n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),\n  apply strict_convex_on_of_deriv2_pos (convex_Ioi 0),\n  { exact (this _).continuous_on },\n   all_goals { rw interior_Ioi },\n  { exact this _ },\n  intros x hx,\n  rw iter_deriv_zpow,\n  refine mul_pos _ (zpow_pos_of_pos hx _),\n  exact_mod_cast int_prod_range_pos (even_bit0 1) (\u03bb hm, _),\n  norm_cast at hm,\n  rw \u2190 finset.coe_Ico at hm,\n  fin_cases hm; cc,\nend\n\nlemma convex_on_rpow {p : \u211d} (hp : 1 \u2264 p) : convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  have A : deriv (\u03bb (x : \u211d), x ^ p) = \u03bb x, p * x^(p-1), by { ext x, simp [hp] },\n  apply convex_on_of_deriv2_nonneg (convex_Ici 0),\n  { exact continuous_on_id.rpow_const (\u03bb x _, or.inr (zero_le_one.trans hp)) },\n  { exact (differentiable_rpow_const hp).differentiable_on },\n  { rw A,\n    assume x hx,\n    replace hx : x \u2260 0, by { simp at hx, exact ne_of_gt hx },\n    simp [differentiable_at.differentiable_within_at, hx] },\n  { assume x hx,\n    replace hx : 0 < x, by simpa using hx,\n    suffices : 0 \u2264 p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],\n    apply mul_nonneg (le_trans zero_le_one hp),\n    exact mul_nonneg (sub_nonneg_of_le hp) (rpow_nonneg_of_nonneg hx.le _) }\nend\n\nlemma strict_convex_on_rpow {p : \u211d} (hp : 1 < p) : strict_convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  have A : deriv (\u03bb (x : \u211d), x ^ p) = \u03bb x, p * x^(p-1), by { ext x, simp [hp.le] },\n  apply strict_convex_on_of_deriv2_pos (convex_Ici 0),\n  { exact continuous_on_id.rpow_const (\u03bb x _, or.inr (zero_le_one.trans hp.le)) },\n  { exact (differentiable_rpow_const hp.le).differentiable_on },\n  rw interior_Ici,\n  rintro x (hx : 0 < x),\n  suffices : 0 < p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],\n  exact mul_pos (zero_lt_one.trans hp) (mul_pos (sub_pos_of_lt hp) (rpow_pos_of_pos hx _)),\nend\n\nlemma strict_concave_on_log_Ioi : strict_concave_on \u211d (Ioi 0) log :=\nbegin\n  have h\u2081 : Ioi 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { exact \u03bb x (hx : 0 < x) (hx' : x = 0), hx.ne' hx' },\n  refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 0) is_open_Ioi\n    (differentiable_on_log.mono h\u2081) (\u03bb x (hx : 0 < x), _),\n  rw [function.iterate_succ, function.iterate_one],\n  change (deriv (deriv log)) x < 0,\n  rw [deriv_log', deriv_inv],\n  exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne'),\nend\n\nlemma strict_concave_on_log_Iio : strict_concave_on \u211d (Iio 0) log :=\nbegin\n  have h\u2081 : Iio 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { exact \u03bb x (hx : x < 0) (hx' : x = 0), hx.ne hx' },\n  refine strict_concave_on_open_of_deriv2_neg (convex_Iio 0) is_open_Iio\n    (differentiable_on_log.mono h\u2081) (\u03bb x (hx : x < 0), _),\n  rw [function.iterate_succ, function.iterate_one],\n  change (deriv (deriv log)) x < 0,\n  rw [deriv_log', deriv_inv],\n  exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne),\nend\n\nsection sqrt_mul_log\n\nlemma has_deriv_at_sqrt_mul_log {x : \u211d} (hx : x \u2260 0) :\n  has_deriv_at (\u03bb x, sqrt x * log x) ((2 + log x) / (2 * sqrt x)) x :=\nbegin\n  convert (has_deriv_at_sqrt hx).mul (has_deriv_at_log hx),\n  rw [add_div, div_mul_right (sqrt x) two_ne_zero, \u2190div_eq_mul_inv, sqrt_div_self',\n      add_comm, div_eq_mul_one_div, mul_comm],\nend\n\nlemma deriv_sqrt_mul_log (x : \u211d) : deriv (\u03bb x, sqrt x * log x) x = (2 + log x) / (2 * sqrt x) :=\nbegin\n  cases lt_or_le 0 x with hx hx,\n  { exact (has_deriv_at_sqrt_mul_log hx.ne').deriv },\n  { rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero],\n    refine has_deriv_within_at.deriv_eq_zero _ (unique_diff_on_Iic 0 x hx),\n    refine (has_deriv_within_at_const x _ 0).congr_of_mem (\u03bb x hx, _) hx,\n    rw [sqrt_eq_zero_of_nonpos hx, zero_mul] },\nend\n\nlemma deriv_sqrt_mul_log' : deriv (\u03bb x, sqrt x * log x) = \u03bb x, (2 + log x) / (2 * sqrt x) :=\nfunext deriv_sqrt_mul_log\n\nlemma deriv2_sqrt_mul_log (x : \u211d) :\n  deriv^[2] (\u03bb x, sqrt x * log x) x = -log x / (4 * sqrt x ^ 3) :=\nbegin\n  simp only [nat.iterate, deriv_sqrt_mul_log'],\n  cases le_or_lt x 0 with hx hx,\n  { rw [sqrt_eq_zero_of_nonpos hx, zero_pow zero_lt_three, mul_zero, div_zero],\n    refine has_deriv_within_at.deriv_eq_zero _ (unique_diff_on_Iic 0 x hx),\n    refine (has_deriv_within_at_const _ _ 0).congr_of_mem (\u03bb x hx, _) hx,\n    rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero] },\n  { have h\u2080 : sqrt x \u2260 0, from sqrt_ne_zero'.2 hx,\n    convert (((has_deriv_at_log hx.ne').const_add 2).div\n      ((has_deriv_at_sqrt hx.ne').const_mul 2) $ mul_ne_zero two_ne_zero h\u2080).deriv using 1,\n    nth_rewrite 2 [\u2190 mul_self_sqrt hx.le],\n    field_simp, ring },\nend\n\nlemma strict_concave_on_sqrt_mul_log_Ioi : strict_concave_on \u211d (set.Ioi 1) (\u03bb x, sqrt x * log x) :=\nbegin\n  refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 1) is_open_Ioi (\u03bb x hx, _) (\u03bb x hx, _),\n  { have h\u2080 : x \u2260 0, from (one_pos.trans hx.out).ne',\n    exact (has_deriv_at_sqrt_mul_log h\u2080).differentiable_at.differentiable_within_at },\n  { rw [deriv2_sqrt_mul_log x],\n    exact div_neg_of_neg_of_pos (neg_neg_of_pos (log_pos hx))\n      (mul_pos four_pos (pow_pos (sqrt_pos.mpr (zero_lt_one.trans hx)) 3)) },\nend\n\nend sqrt_mul_log\n\nopen_locale real\n\nlemma strict_concave_on_sin_Icc : strict_concave_on \u211d (Icc 0 \u03c0) sin :=\nbegin\n  apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_sin\n    differentiable_sin.differentiable_on (\u03bb x hx, _),\n  rw interior_Icc at hx,\n  simp [sin_pos_of_mem_Ioo hx],\nend\n\nlemma strict_concave_on_cos_Icc : strict_concave_on \u211d (Icc (-(\u03c0/2)) (\u03c0/2)) cos :=\nbegin\n  apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_cos\n    differentiable_cos.differentiable_on (\u03bb x hx, _),\n  rw interior_Icc at hx,\n  simp [cos_pos_of_mem_Ioo hx],\nend\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/analysis/convex/specific_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.724069690775463}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n\n! This file was ported from Lean 3 source module field_theory.fixed\n! leanprover-community/mathlib commit e7bab9a85e92cf46c02cb4725a7be2f04691e3a7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.GroupRingAction.Invariant\nimport Mathbin.Algebra.Polynomial.GroupRingAction\nimport Mathbin.FieldTheory.Normal\nimport Mathbin.FieldTheory.Separable\nimport Mathbin.FieldTheory.Tower\n\n/-!\n# Fixed field under a group action.\n\nThis is the basis of the Fundamental Theorem of Galois Theory.\nGiven a (finite) group `G` that acts on a field `F`, we define `fixed_points G F`,\nthe subfield consisting of elements of `F` fixed_points by every element of `G`.\n\nThis subfield is then normal and separable, and in addition (TODO) if `G` acts faithfully on `F`\nthen `finrank (fixed_points G F) F = fintype.card G`.\n\n## Main Definitions\n\n- `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of\n`G`, where `G` is a group that acts on `F`.\n\n-/\n\n\nnoncomputable section\n\nopen Classical BigOperators\n\nopen MulAction Finset FiniteDimensional\n\nuniverse u v w\n\nvariable {M : Type u} [Monoid M]\n\nvariable (G : Type u) [Group G]\n\nvariable (F : Type v) [Field F] [MulSemiringAction M F] [MulSemiringAction G F] (m : M)\n\n/-- The subfield of F fixed by the field endomorphism `m`. -/\ndef FixedBy.subfield : Subfield F where\n  carrier := fixedBy M F m\n  zero_mem' := smul_zero m\n  add_mem' x y hx hy := (smul_add m x y).trans <| congr_arg\u2082 _ hx hy\n  neg_mem' x hx := (smul_neg m x).trans <| congr_arg _ hx\n  one_mem' := smul_one m\n  mul_mem' x y hx hy := (smul_mul' m x y).trans <| congr_arg\u2082 _ hx hy\n  inv_mem' x hx := (smul_inv'' m x).trans <| congr_arg _ hx\n#align fixed_by.subfield FixedBy.subfield\n\nsection InvariantSubfields\n\nvariable (M) {F}\n\n/-- A typeclass for subrings invariant under a `mul_semiring_action`. -/\nclass IsInvariantSubfield (S : Subfield F) : Prop where\n  smul_mem : \u2200 (m : M) {x : F}, x \u2208 S \u2192 m \u2022 x \u2208 S\n#align is_invariant_subfield IsInvariantSubfield\n\nvariable (S : Subfield F)\n\ninstance IsInvariantSubfield.toMulSemiringAction [IsInvariantSubfield M S] : MulSemiringAction M S\n    where\n  smul m x := \u27e8m \u2022 x, IsInvariantSubfield.smul_mem m x.2\u27e9\n  one_smul s := Subtype.eq <| one_smul M s\n  mul_smul m\u2081 m\u2082 s := Subtype.eq <| mul_smul m\u2081 m\u2082 s\n  smul_add m s\u2081 s\u2082 := Subtype.eq <| smul_add m s\u2081 s\u2082\n  smul_zero m := Subtype.eq <| smul_zero m\n  smul_one m := Subtype.eq <| smul_one m\n  smul_mul m s\u2081 s\u2082 := Subtype.eq <| smul_mul' m s\u2081 s\u2082\n#align is_invariant_subfield.to_mul_semiring_action IsInvariantSubfield.toMulSemiringAction\n\ninstance [IsInvariantSubfield M S] : IsInvariantSubring M S.toSubring\n    where smul_mem := IsInvariantSubfield.smul_mem\n\nend InvariantSubfields\n\nnamespace FixedPoints\n\nvariable (M)\n\n-- we use `subfield.copy` so that the underlying set is `fixed_points M F`\n/-- The subfield of fixed points by a monoid action. -/\ndef subfield : Subfield F :=\n  Subfield.copy (\u2a05 m : M, FixedBy.subfield F m) (fixedPoints M F)\n    (by\n      ext z\n      simp [fixed_points, FixedBy.subfield, inf\u1d62, Subfield.mem_inf\u209b])\n#align fixed_points.subfield FixedPoints.subfield\n\ninstance : IsInvariantSubfield M (FixedPoints.subfield M F)\n    where smul_mem g x hx g' := by rw [hx, hx]\n\ninstance : SMulCommClass M (FixedPoints.subfield M F) F\n    where smul_comm m f f' := show m \u2022 (\u2191f * f') = f * m \u2022 f' by rw [smul_mul', f.prop m]\n\ninstance smul_comm_class' : SMulCommClass (FixedPoints.subfield M F) M F :=\n  SMulCommClass.symm _ _ _\n#align fixed_points.smul_comm_class' FixedPoints.smul_comm_class'\n\n@[simp]\ntheorem smul (m : M) (x : FixedPoints.subfield M F) : m \u2022 x = x :=\n  Subtype.eq <| x.2 m\n#align fixed_points.smul FixedPoints.smul\n\n-- Why is this so slow?\n@[simp]\ntheorem smul_polynomial (m : M) (p : Polynomial (FixedPoints.subfield M F)) : m \u2022 p = p :=\n  Polynomial.induction_on p (fun x => by rw [Polynomial.smul_C, smul])\n    (fun p q ihp ihq => by rw [smul_add, ihp, ihq]) fun n x ih => by\n    rw [smul_mul', Polynomial.smul_C, smul, smul_pow', Polynomial.smul_X]\n#align fixed_points.smul_polynomial FixedPoints.smul_polynomial\n\ninstance : Algebra (FixedPoints.subfield M F) F := by infer_instance\n\ntheorem coe_algebraMap :\n    algebraMap (FixedPoints.subfield M F) F = Subfield.subtype (FixedPoints.subfield M F) :=\n  rfl\n#align fixed_points.coe_algebra_map FixedPoints.coe_algebraMap\n\ntheorem linearIndependent_smul_of_linearIndependent {s : Finset F} :\n    (LinearIndependent (FixedPoints.subfield G F) fun i : (s : Set F) => (i : F)) \u2192\n      LinearIndependent F fun i : (s : Set F) => MulAction.toFun G F i :=\n  by\n  haveI : IsEmpty ((\u2205 : Finset F) : Set F) := \u27e8Subtype.prop\u27e9\n  refine' Finset.induction_on s (fun _ => linearIndependent_empty_type) fun a s has ih hs => _\n  rw [coe_insert] at hs\u22a2\n  rw [linearIndependent_insert (mt mem_coe.1 has)] at hs\n  rw [linearIndependent_insert' (mt mem_coe.1 has)]\n  refine' \u27e8ih hs.1, fun ha => _\u27e9\n  rw [Finsupp.mem_span_image_iff_total] at ha\n  rcases ha with \u27e8l, hl, hla\u27e9\n  rw [Finsupp.total_apply_of_mem_supported F hl] at hla\n  suffices \u2200 i \u2208 s, l i \u2208 FixedPoints.subfield G F\n    by\n    replace hla := (sum_apply _ _ fun i => l i \u2022 to_fun G F i).symm.trans (congr_fun hla 1)\n    simp_rw [Pi.smul_apply, to_fun_apply, one_smul] at hla\n    refine' hs.2 (hla \u25b8 Submodule.sum_mem _ fun c hcs => _)\n    change (\u27e8l c, this c hcs\u27e9 : FixedPoints.subfield G F) \u2022 c \u2208 _\n    exact Submodule.smul_mem _ _ (Submodule.subset_span <| mem_coe.2 hcs)\n  intro i his g\n  refine'\n    eq_of_sub_eq_zero\n      (linearIndependent_iff'.1 (ih hs.1) s.attach (fun i => g \u2022 l i - l i) _ \u27e8i, his\u27e9\n          (mem_attach _ _) :\n        _)\n  refine' (@sum_attach _ _ s _ fun i => (g \u2022 l i - l i) \u2022 MulAction.toFun G F i).trans _\n  ext g'\n  dsimp only\n  conv_lhs =>\n    rw [sum_apply]\n    congr\n    skip\n    ext\n    rw [Pi.smul_apply, sub_smul, smul_eq_mul]\n  rw [sum_sub_distrib, Pi.zero_apply, sub_eq_zero]\n  conv_lhs =>\n    congr\n    skip\n    ext\n    rw [to_fun_apply, \u2190 mul_inv_cancel_left g g', mul_smul, \u2190 smul_mul', \u2190 to_fun_apply _ x]\n  show\n    (\u2211 x in s, g \u2022 (fun y => l y \u2022 MulAction.toFun G F y) x (g\u207b\u00b9 * g')) =\n      \u2211 x in s, (fun y => l y \u2022 MulAction.toFun G F y) x g'\n  rw [\u2190 smul_sum, \u2190 sum_apply _ _ fun y => l y \u2022 to_fun G F y, \u2190\n    sum_apply _ _ fun y => l y \u2022 to_fun G F y]\n  dsimp only\n  rw [hla, to_fun_apply, to_fun_apply, smul_smul, mul_inv_cancel_left]\n#align fixed_points.linear_independent_smul_of_linear_independent FixedPoints.linearIndependent_smul_of_linearIndependent\n\nsection Fintype\n\nvariable [Fintype G] (x : F)\n\n/-- `minpoly G F x` is the minimal polynomial of `(x : F)` over `fixed_points G F`. -/\ndef minpoly : Polynomial (FixedPoints.subfield G F) :=\n  (prodXSubSmul G F x).toSubring (FixedPoints.subfield G F).toSubring fun c hc g =>\n    let \u27e8n, hc0, hn\u27e9 := Polynomial.mem_frange_iff.1 hc\n    hn.symm \u25b8 prodXSubSmul.coeff G F x g n\n#align fixed_points.minpoly FixedPoints.minpoly\n\nnamespace minpoly\n\ntheorem monic : (minpoly G F x).Monic :=\n  by\n  simp only [minpoly, Polynomial.monic_toSubring]\n  exact prodXSubSmul.monic G F x\n#align fixed_points.minpoly.monic FixedPoints.minpoly.monic\n\ntheorem eval\u2082 :\n    Polynomial.eval\u2082 (Subring.subtype <| (FixedPoints.subfield G F).toSubring) x (minpoly G F x) =\n      0 :=\n  by\n  rw [\u2190 prodXSubSmul.eval G F x, Polynomial.eval\u2082_eq_eval_map]\n  simp only [minpoly, Polynomial.map_toSubring]\n#align fixed_points.minpoly.eval\u2082 FixedPoints.minpoly.eval\u2082\n\ntheorem eval\u2082' :\n    Polynomial.eval\u2082 (Subfield.subtype <| FixedPoints.subfield G F) x (minpoly G F x) = 0 :=\n  eval\u2082 G F x\n#align fixed_points.minpoly.eval\u2082' FixedPoints.minpoly.eval\u2082'\n\ntheorem ne_one : minpoly G F x \u2260 (1 : Polynomial (FixedPoints.subfield G F)) := fun H =>\n  have := eval\u2082 G F x\n  (one_ne_zero : (1 : F) \u2260 0) <| by rwa [H, Polynomial.eval\u2082_one] at this\n#align fixed_points.minpoly.ne_one FixedPoints.minpoly.ne_one\n\ntheorem of_eval\u2082 (f : Polynomial (FixedPoints.subfield G F))\n    (hf : Polynomial.eval\u2082 (Subfield.subtype <| FixedPoints.subfield G F) x f = 0) :\n    minpoly G F x \u2223 f :=\n  by\n  erw [\u2190 Polynomial.map_dvd_map' (Subfield.subtype <| FixedPoints.subfield G F), minpoly,\n    Polynomial.map_toSubring _ (Subfield G F).toSubring, prodXSubSmul]\n  refine'\n    Fintype.prod_dvd_of_coprime\n      (Polynomial.pairwise_coprime_X_sub_C <| MulAction.injective_ofQuotientStabilizer G x) fun y =>\n      QuotientGroup.induction_on y fun g => _\n  rw [Polynomial.dvd_iff_isRoot, Polynomial.IsRoot.def, MulAction.ofQuotientStabilizer_mk,\n    Polynomial.eval_smul', \u2190 Subfield.toSubring_subtype_eq_subtype, \u2190\n    IsInvariantSubring.coe_subtypeHom' G (FixedPoints.subfield G F).toSubring, \u2190\n    MulSemiringActionHom.coe_polynomial, \u2190 MulSemiringActionHom.map_smul, smul_polynomial,\n    MulSemiringActionHom.coe_polynomial, IsInvariantSubring.coe_subtypeHom', Polynomial.eval_map,\n    Subfield.toSubring_subtype_eq_subtype, hf, smul_zero]\n#align fixed_points.minpoly.of_eval\u2082 FixedPoints.minpoly.of_eval\u2082\n\n-- Why is this so slow?\ntheorem irreducible_aux (f g : Polynomial (FixedPoints.subfield G F)) (hf : f.Monic) (hg : g.Monic)\n    (hfg : f * g = minpoly G F x) : f = 1 \u2228 g = 1 :=\n  by\n  have hf2 : f \u2223 minpoly G F x := by\n    rw [\u2190 hfg]\n    exact dvd_mul_right _ _\n  have hg2 : g \u2223 minpoly G F x := by\n    rw [\u2190 hfg]\n    exact dvd_mul_left _ _\n  have := eval\u2082 G F x\n  rw [\u2190 hfg, Polynomial.eval\u2082_mul, mul_eq_zero] at this\n  cases this\n  \u00b7 right\n    have hf3 : f = minpoly G F x :=\n      Polynomial.eq_of_monic_of_associated hf (monic G F x)\n        (associated_of_dvd_dvd hf2 <| @of_eval\u2082 G _ F _ _ _ x f this)\n    rwa [\u2190 mul_one (minpoly G F x), hf3, mul_right_inj' (monic G F x).NeZero] at hfg\n  \u00b7 left\n    have hg3 : g = minpoly G F x :=\n      Polynomial.eq_of_monic_of_associated hg (monic G F x)\n        (associated_of_dvd_dvd hg2 <| @of_eval\u2082 G _ F _ _ _ x g this)\n    rwa [\u2190 one_mul (minpoly G F x), hg3, mul_left_inj' (monic G F x).NeZero] at hfg\n#align fixed_points.minpoly.irreducible_aux FixedPoints.minpoly.irreducible_aux\n\ntheorem irreducible : Irreducible (minpoly G F x) :=\n  (Polynomial.irreducible_of_monic (monic G F x) (ne_one G F x)).2 (irreducible_aux G F x)\n#align fixed_points.minpoly.irreducible FixedPoints.minpoly.irreducible\n\nend minpoly\n\nend Fintype\n\ntheorem isIntegral [Finite G] (x : F) : IsIntegral (FixedPoints.subfield G F) x :=\n  by\n  cases nonempty_fintype G\n  exact \u27e8minpoly G F x, minpoly.monic G F x, minpoly.eval\u2082 G F x\u27e9\n#align fixed_points.is_integral FixedPoints.isIntegral\n\nsection Fintype\n\nvariable [Fintype G] (x : F)\n\ntheorem minpoly_eq_minpoly : minpoly G F x = minpoly (FixedPoints.subfield G F) x :=\n  minpoly.eq_of_irreducible_of_monic (minpoly.irreducible G F x) (minpoly.eval\u2082 G F x)\n    (minpoly.monic G F x)\n#align fixed_points.minpoly_eq_minpoly FixedPoints.minpoly_eq_minpoly\n\ntheorem dim_le_card : Module.rank (FixedPoints.subfield G F) F \u2264 Fintype.card G :=\n  dim_le fun s hs => by\n    simpa only [dim_fun', Cardinal.mk_coe_finset, Finset.coe_sort_coe, Cardinal.lift_natCast,\n      Cardinal.natCast_le] using\n      cardinal_lift_le_dim_of_linear_independent'\n        (linear_independent_smul_of_linear_independent G F hs)\n#align fixed_points.dim_le_card FixedPoints.dim_le_card\n\nend Fintype\n\nsection Finite\n\nvariable [Finite G]\n\ninstance normal : Normal (FixedPoints.subfield G F) F :=\n  \u27e8fun x => (isIntegral G F x).IsAlgebraic _, fun x =>\n    (Polynomial.splits_id_iff_splits _).1 <|\n      by\n      cases nonempty_fintype G\n      rw [\u2190 minpoly_eq_minpoly, minpoly, coe_algebra_map, \u2190 Subfield.toSubring_subtype_eq_subtype,\n        Polynomial.map_toSubring _ (Subfield G F).toSubring, prodXSubSmul]\n      exact Polynomial.splits_prod _ fun _ _ => Polynomial.splits_X_sub_C _\u27e9\n#align fixed_points.normal FixedPoints.normal\n\ninstance separable : IsSeparable (FixedPoints.subfield G F) F :=\n  \u27e8isIntegral G F, fun x => by\n    cases nonempty_fintype G\n    -- this was a plain rw when we were using unbundled subrings\n    erw [\u2190 minpoly_eq_minpoly, \u2190 Polynomial.separable_map (FixedPoints.subfield G F).Subtype,\n      minpoly, Polynomial.map_toSubring _ (Subfield G F).toSubring]\n    exact Polynomial.separable_prod_x_sub_c_iff.2 (injective_of_quotient_stabilizer G x)\u27e9\n#align fixed_points.separable FixedPoints.separable\n\ninstance : FiniteDimensional (subfield G F) F :=\n  by\n  cases nonempty_fintype G\n  exact\n    IsNoetherian.iff_fg.1\n      (IsNoetherian.iff_dim_lt_aleph0.2 <| (dim_le_card G F).trans_lt <| Cardinal.nat_lt_aleph0 _)\n\nend Finite\n\ntheorem finrank_le_card [Fintype G] : finrank (subfield G F) F \u2264 Fintype.card G :=\n  by\n  rw [\u2190 Cardinal.natCast_le, finrank_eq_dim]\n  apply dim_le_card\n#align fixed_points.finrank_le_card FixedPoints.finrank_le_card\n\nend FixedPoints\n\ntheorem linearIndependent_toLinearMap (R : Type u) (A : Type v) (B : Type w) [CommSemiring R]\n    [Ring A] [Algebra R A] [CommRing B] [IsDomain B] [Algebra R B] :\n    LinearIndependent B (AlgHom.toLinearMap : (A \u2192\u2090[R] B) \u2192 A \u2192\u2097[R] B) :=\n  have : LinearIndependent B (LinearMap.ltoFun R A B \u2218 AlgHom.toLinearMap) :=\n    ((linearIndependent_monoidHom A B).comp (coe : (A \u2192\u2090[R] B) \u2192 A \u2192* B) fun f g hfg =>\n        AlgHom.ext <| MonoidHom.ext_iff.1 hfg :\n      _)\n  this.of_comp _\n#align linear_independent_to_linear_map linearIndependent_toLinearMap\n\ntheorem cardinal_mk_algHom (K : Type u) (V : Type v) (W : Type w) [Field K] [Field V] [Algebra K V]\n    [FiniteDimensional K V] [Field W] [Algebra K W] [FiniteDimensional K W] :\n    Cardinal.mk (V \u2192\u2090[K] W) \u2264 finrank W (V \u2192\u2097[K] W) :=\n  cardinal_mk_le_finrank_of_linearIndependent <| linearIndependent_toLinearMap K V W\n#align cardinal_mk_alg_hom cardinal_mk_algHom\n\nnoncomputable instance AlgEquiv.fintype (K : Type u) (V : Type v) [Field K] [Field V] [Algebra K V]\n    [FiniteDimensional K V] : Fintype (V \u2243\u2090[K] V) :=\n  Fintype.ofEquiv (V \u2192\u2090[K] V) (algEquivEquivAlgHom K V).symm\n#align alg_equiv.fintype AlgEquiv.fintype\n\ntheorem finrank_algHom (K : Type u) (V : Type v) [Field K] [Field V] [Algebra K V]\n    [FiniteDimensional K V] : Fintype.card (V \u2192\u2090[K] V) \u2264 finrank V (V \u2192\u2097[K] V) :=\n  fintype_card_le_finrank_of_linearIndependent <| linearIndependent_toLinearMap K V V\n#align finrank_alg_hom finrank_algHom\n\nnamespace FixedPoints\n\ntheorem finrank_eq_card (G : Type u) (F : Type v) [Group G] [Field F] [Fintype G]\n    [MulSemiringAction G F] [FaithfulSMul G F] :\n    finrank (FixedPoints.subfield G F) F = Fintype.card G :=\n  le_antisymm (FixedPoints.finrank_le_card G F) <|\n    calc\n      Fintype.card G \u2264 Fintype.card (F \u2192\u2090[FixedPoints.subfield G F] F) :=\n        Fintype.card_le_of_injective _ (MulSemiringAction.toAlgHom_injective _ F)\n      _ \u2264 finrank F (F \u2192\u2097[FixedPoints.subfield G F] F) := (finrank_algHom (fixedPoints G F) F)\n      _ = finrank (FixedPoints.subfield G F) F := finrank_linear_map' _ _ _\n      \n#align fixed_points.finrank_eq_card FixedPoints.finrank_eq_card\n\n/-- `mul_semiring_action.to_alg_hom` is bijective. -/\ntheorem toAlgHom_bijective (G : Type u) (F : Type v) [Group G] [Field F] [Finite G]\n    [MulSemiringAction G F] [FaithfulSMul G F] :\n    Function.Bijective (MulSemiringAction.toAlgHom _ _ : G \u2192 F \u2192\u2090[subfield G F] F) :=\n  by\n  cases nonempty_fintype G\n  rw [Fintype.bijective_iff_injective_and_card]\n  constructor\n  \u00b7 exact MulSemiringAction.toAlgHom_injective _ F\n  \u00b7 apply le_antisymm\n    \u00b7 exact Fintype.card_le_of_injective _ (MulSemiringAction.toAlgHom_injective _ F)\n    \u00b7 rw [\u2190 finrank_eq_card G F]\n      exact LE.le.trans_eq (finrank_algHom _ F) (finrank_linear_map' _ _ _)\n#align fixed_points.to_alg_hom_bijective FixedPoints.toAlgHom_bijective\n\n/-- Bijection between G and algebra homomorphisms that fix the fixed points -/\ndef toAlgHomEquiv (G : Type u) (F : Type v) [Group G] [Field F] [Fintype G] [MulSemiringAction G F]\n    [FaithfulSMul G F] : G \u2243 (F \u2192\u2090[FixedPoints.subfield G F] F) :=\n  Equiv.ofBijective _ (toAlgHom_bijective G F)\n#align fixed_points.to_alg_hom_equiv FixedPoints.toAlgHomEquiv\n\nend FixedPoints\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/FieldTheory/Fixed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7240696848402008}}
{"text": "variables P Q R :  Prop\n\nexample : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n    intros h,\n    cases h with hpq hqr,\n    intro hp,\n    exact hqr (hpq hp),\nend\n\n/- Alternatively -/\n\nexample : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n    intro h,\n    cases h with hpq hqr,\n    intro hp,\n    apply hqr (hpq hp),\nend\n\n/- Alternatively -/\n\nexample : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\nintros h,\n    have hpq : P \u2192 Q,\n    exact h.left,\n    have hqr : Q \u2192 R,\n    exact h.right,\n    clear h,\n    intro hp,\n    have hq : Q,\n    exact hpq hp,\n    exact hqr hq,\nend", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.2_cases_conjunc/ex1_cases_imp_trans.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7240696764674179}}
{"text": "import Mathlib.Data.Real.Basic\nimport Mathlib.Algebra.Order.AbsoluteValue\nimport Mathlib.Tactic.Linarith\nimport Playground.Analysis.Topology\n\ndef Sequence := \u2115 \u2192 \u211d\n\nnamespace Sequence\ndef of (u : \u2115 \u2192 \u211d) : Sequence := u\n\nsection\n  variable (u : Sequence)\n  def TendsTo (l : \u211d) := \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5\n\n  def IsCauchy := \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, \u2200 m \u2265 N, |u n - u m| < \u03b5\n\n  def Increasing := \u2200 n, u n \u2264 u (n + 1)\n\n  def Decreasing := \u2200 n, u (n + 1) \u2264 u n\n\n  def image := Set.univ.image u\n\n  def BoundedAbove := BddAbove u.image\n\n  def BoundedBelow := BddBelow u.image\n\n  def Bounded := u.BoundedAbove \u2227 u.BoundedBelow\nend\n\nnamespace IsCauchy\nsection\n  variable {u : Sequence}\n  theorem boundedAbove : u.IsCauchy \u2192 u.BoundedAbove := \u03bb hu =>\n    let \u27e8N, h\u27e9 := hu 1 zero_lt_one\n    have h := h N (le_refl _)\n    let b := (u N) + 1\n    have hb := by\n      intro r \u27e8n, \u27e8_, hr\u27e9\u27e9\n      rw [\u2190hr]\n      dsimp; have h := h\n      sorry\n    \u27e8b, hb\u27e9\n\n  theorem boundedBelow : u.IsCauchy \u2192 u.BoundedAbove := sorry\n\n  theorem bounded : u.IsCauchy \u2192 u.Bounded := sorry\n\n  noncomputable def limit : u.IsCauchy \u2192 \u211d := sorry\n  \n  theorem tendsTo_limit (hu : u.IsCauchy) : u.TendsTo hu.limit := sorry\nend\nend IsCauchy\n\nsection\n  variable {u : Sequence}\n  theorem TendsTo.isCauchy {l} : u.TendsTo l \u2192 u.IsCauchy := sorry\n\n  theorem TendsTo.bounded {l} : u.TendsTo l \u2192 u.Bounded := \u03bb h => h.isCauchy.bounded\n\n  noncomputable def BoundedAbove.imageSup : u.BoundedAbove \u2192 \u211d := \u03bb h => \n    (Real.exists_isLUB u.image \u27e8u 0, \u27e80, \u27e8\u27e8\u27e9, rfl\u27e9\u27e9\u27e9 h).choose\n\n  theorem BoundedAbove.Increasing.tendsTo_imageSup (h : u.BoundedAbove) : u.Increasing \u2192\n    u.TendsTo h.imageSup := sorry\n\n  noncomputable def BoundedBelow.imageInf : u.BoundedBelow \u2192 \u211d := sorry\n\n  theorem BoundedBelow.Decreasing.tendsTo_imageInf (h : u.BoundedBelow) : u.Decreasing \u2192\n    u.TendsTo h.imageInf := sorry\nend\n\ndef Constant (c : \u211d) := of \u03bb _ => c\n\ndef le (u v : Sequence) := \u2200 n, u n \u2264 v n\ninstance : LE Sequence where le := le\n\n\nend Sequence\n\n\nnoncomputable def Set.closure.sequence {s : Set \u211d} {x : \u211d} (hx : s.closure x)\n  : Sequence :=\n  \u03bb n => \n    let r := (1 : \u211d) / n\n    (hx r sorry).choose\n\ntheorem Set.closure.sequence_tendsTo {s : Set \u211d} {x : \u211d} (hx : s.closure x)\n  : hx.sequence.TendsTo x :=\n  sorry\n", "meta": {"author": "michelsol", "repo": "lean-playground", "sha": "0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca", "save_path": "github-repos/lean/michelsol-lean-playground", "path": "github-repos/lean/michelsol-lean-playground/lean-playground-0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca/Playground/Analysis/Sequence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632234212403, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.724035376990209}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.invertible\nimport algebra.field.basic\nimport algebra.char_p.basic\n\n/-!\n# Invertibility of elements given a characteristic\n\nThis file includes some instances of `invertible` for specific numbers in\ncharacteristic zero. Some more cases are given as a `def`, to be included only\nwhen needed. To construct instances for concrete numbers,\n`invertible_of_nonzero` is a useful definition.\n-/\n\nvariables {K : Type*}\n\nsection field\nvariables [field K]\n\n/-- A natural number `t` is invertible in a field `K` if the charactistic of `K` does not divide\n`t`. -/\ndef invertible_of_ring_char_not_dvd\n  {t : \u2115} (not_dvd : \u00ac(ring_char K \u2223 t)) : invertible (t : K) :=\ninvertible_of_nonzero (\u03bb h, not_dvd ((ring_char.spec K t).mp h))\n\nlemma not_ring_char_dvd_of_invertible {t : \u2115} [invertible (t : K)] :\n  \u00ac(ring_char K \u2223 t) :=\nbegin\n  rw [\u2190 ring_char.spec, \u2190 ne.def],\n  exact nonzero_of_invertible (t : K)\nend\n\n/-- A natural number `t` is invertible in a field `K` of charactistic `p` if `p` does not divide\n`t`. -/\ndef invertible_of_char_p_not_dvd {p : \u2115} [char_p K p]\n  {t : \u2115} (not_dvd : \u00ac(p \u2223 t)) : invertible (t : K) :=\ninvertible_of_nonzero (\u03bb h, not_dvd ((char_p.cast_eq_zero_iff K p t).mp h))\n\ninstance invertible_of_pos [char_zero K] (n : \u2115) [h : fact (0 < n)] :\n  invertible (n : K) :=\ninvertible_of_nonzero $ by simpa [pos_iff_ne_zero] using h.out\n\nend field\n\nsection division_ring\nvariables [division_ring K] [char_zero K]\n\ninstance invertible_succ (n : \u2115) : invertible (n.succ : K) :=\ninvertible_of_nonzero (nat.cast_ne_zero.mpr (nat.succ_ne_zero _))\n\n/-!\nA few `invertible n` instances for small numerals `n`. Feel free to add your own\nnumber when you need its inverse.\n-/\n\ninstance invertible_two : invertible (2 : K) :=\ninvertible_of_nonzero (by exact_mod_cast (dec_trivial : 2 \u2260 0))\n\ninstance invertible_three : invertible (3 : K) :=\ninvertible_of_nonzero (by exact_mod_cast (dec_trivial : 3 \u2260 0))\n\nend division_ring\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/char_p/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8757869884059267, "lm_q1q2_score": 0.7240234324088157}}
{"text": "import chapter_1\nimport tactic.simps\n\nnamespace surreal\n\n/-\nThis chapter is mostly about the protagonists trying to make sense of the text they found my defining some cleaner mathematical notation.\n\nThey define surreals concisely like this: `x = (X\u2097, X\u1d63) where X\u2097 \u2271 X\u1d63`\nHere by `X\u2097 \u2271 X\u1d63` they mean that every `x\u2097 \u2271 x\u1d63` where `x\u2097 \u2208 X\u2097` and `x\u1d63 \u2208 X\u1d63`.\n\nCapitals are generally used to denote sets, and the same lowercase letters denote elements from those sets.\n\nIn our case, the equivalent of `X\u2097` is simply `x.left`, and `X\u1d63` is `x.right`. For elements of those\nsets, we tend to call them `xl` and `xr`, because it's just more confortable to read and write without those tiny subscripts.\n-/\n\n/-\nWe'll not take a small pause to define \u2271 both for surreals and sets of surreals, since Lean's `has_le` doesn't include this variant automatically, and it is used extensively moving forward. Note that < might not strictly equivalent to \u2271, we might prove it later on, but we shouldn't take it for granted.\n-/\n\n@[notation_class]\nclass has_nge (\u03b1 \u03b2: Type*) := (nge : \u03b1 \u2192 \u03b2 \u2192 Prop)\n\n/-\nLeft-binding power 50 is the same as other inequality operators.\nhttps://leanprover.github.io/theorem_proving_in_lean/interacting_with_lean.html#notation\nhttps://github.com/leanprover/lean/blob/master/library/init/core.lean#L50\n-/ \ninfix ` \u2271 `:50 := has_nge.nge\n\ndef nge_num_num (x y: surreal): Prop :=\n  \u00ac(x \u2265 y)\n@[simps] instance has_nge_num_num : has_nge surreal surreal := \u27e8nge_num_num\u27e9\n\ndef nge_set_set (X Y: set surreal): Prop :=\n  \u2200 x \u2208 X, \u2200 y \u2208 Y, x \u2271 y\n@[simps] instance has_nge_set_set : has_nge (set surreal) (set surreal) := \u27e8nge_set_set\u27e9\n\n/-\nLet's take a moment to consider `x = (X\u2097, X\u1d63) where X\u2097 \u2271 X\u1d63`. It is nice and concise, but in my opinion it doesn't exactly match the wording from the rules.\n\nIt says: `no member of the left is greater than or equal to any member of the right set`\n\nThis, to me, literally translates to something like: there doesn't exist a pair of members of the left and right sets that are greater than or equal to each other. Or in mathematical notation: `\u00ac\u2203 xl \u2208 x.left, \u2203 xr \u2208 x.right, xl \u2265 xr`, which is our definition for `valid`.\n\nWhereas `X\u2097 \u2271 X\u1d63` here implies `\u2200 xl \u2208 x.left, \u2200 xr \u2208 x.right, xl \u2271 xr`, which is intuitively equivalent, but we should prove it is, just to be safe.\n-/\n\n\nlemma rule_1_nge (x: surreal): valid x.left x.right \u2194 x.left \u2271 x.right :=\nbegin\n  simp [valid, nge_num_num, nge_set_set],\nend\n\n/-\nThen they redefine the numbers with the new notation: `0 = (\u2205,\u2205)`, `-1 = (\u2205, {0})`, `1 = ({0}, \u2205)`\n\nThen they check if they are valid, and they find out that:\n> If X\u2097 or X\u1d63 is empty, the condition X\u2097 \u2271 X\u1d63 is true no matter what is in the other set.\n-/\n\nlemma valid_empty (L R: set surreal): L = \u2205 \u2228 R = \u2205 \u2192 valid L R :=\nbegin\n  simp [valid],\n  intro h0,\n  apply or.elim h0,\n  begin\n    intro L0,\n    intros l lL r rR hge,\n    rw L0 at lL,\n    exact lL,\n  end,\n  begin\n    intro R0,\n    intros l lL r rR hge,\n    rw R0 at rR,\n    exact rR,\n  end\nend\n\n/-\nThey also express `rule_2` with the new notation: `x \u2264 y means X\u2097 \u2271 y and x \u2271 Y\u1d63`\n-/\n\n/-\nThey have now introduced \u2271 between sets and numbers and viceversa. Let's define those then.\n-/\n\ndef nge_set_num (X: set surreal) (y: surreal) :=\n  \u2200 x \u2208 X, x \u2271 y\n@[simps] instance has_nge_set_num : has_nge (set surreal) surreal := \u27e8nge_set_num\u27e9\n\n\ndef nge_num_set (x: surreal) (Y: set surreal) :=\n  \u2200 y \u2208 Y, x \u2271 y\n@[simps] instance has_nge_num_set : has_nge surreal (set surreal) := \u27e8nge_num_set\u27e9\n\n/-\nAgain, the semantics differ somewhat from the original wording, so let's check that they are indeed\nequivalent to our original definition from `rule_2`.\n-/\n\nlemma rule_2_nge (x y: surreal): x \u2264 y \u2194 x.left \u2271 y \u2227 x \u2271 y.right :=\nbegin\n  rw rule_2,\n  simp [nge_set_num, nge_num_set, nge_num_num],\nend\n\nend surreal", "meta": {"author": "oersted", "repo": "lean-surreal-numbers", "sha": "0320b05528622f72b515eb62957f459f1beb3fce", "save_path": "github-repos/lean/oersted-lean-surreal-numbers", "path": "github-repos/lean/oersted-lean-surreal-numbers/lean-surreal-numbers-0320b05528622f72b515eb62957f459f1beb3fce/src/legacy/chapter_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7240147327602807}}
{"text": "import .love02_backward_proofs_exercise_sheet\n\n\n/- # LoVe Homework 2: Backward Proofs\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace backward_proofs\n\n\n/- ## Question 1 (4 points): Connectives and Quantifiers\n\n1.1 (3 points). Complete the following proofs using basic tactics such as\n`intro`, `apply`, and `exact`.\n\nHint: Some strategies for carrying out such proofs are described at the end of\nSection 2.3 in the Hitchhiker's Guide. -/\n\nlemma B (a b c : Prop) :\n  (a \u2192 b) \u2192 (c \u2192 a) \u2192 c \u2192 b :=\nsorry\n\nlemma S (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 (a \u2192 b) \u2192 a \u2192 c :=\nsorry\n\nlemma more_nonsense (a b c : Prop) :\n  (c \u2192 (a \u2192 b) \u2192 a) \u2192 c \u2192 b \u2192 a :=\nsorry\n\nlemma even_more_nonsense (a b c : Prop) :\n  (a \u2192 a \u2192 b) \u2192 (b \u2192 c) \u2192 a \u2192 b \u2192 c :=\nsorry\n\n/- 1.2 (1 point). Prove the following lemma using basic tactics. -/\n\nlemma weak_peirce (a b : Prop) :\n  ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\n\n/- ## Question 2 (5 points): Logical Connectives\n\n2.1 (1 point). Prove the following property about implication using basic\ntactics.\n\nHints:\n\n* Keep in mind that `\u00ac a` is the same as `a \u2192 false`. You can start by invoking\n  `rw not_def` if this helps you.\n\n* You will need to apply the elimination rules for `\u2228` and `false` at some\n  point. -/\n\nlemma about_implication (a b : Prop) :\n  \u00ac a \u2228 b \u2192 a \u2192 b :=\nsorry\n\n/- 2.2 (2 points). Prove the missing link in our chain of classical axiom\nimplications.\n\nHints:\n\n* You can use `rw double_negation` to unfold the definition of\n  `double_negation`, and similarly for the other definitions.\n\n* You will need to apply the double negation hypothesis for `a \u2228 \u00ac a`. You will\n  also need the left and right introduction rules for `\u2228` at some point. -/\n\n#check excluded_middle\n#check peirce\n#check double_negation\n\nlemma em_of_dn :\n  double_negation \u2192 excluded_middle :=\nsorry\n\n/- 2.3 (2 points). We have proved three of the six possible implications\nbetween `excluded_middle`, `peirce`, and `double_negation`. State and prove the\nthree missing implications, exploiting the three theorems we already have. -/\n\n#check peirce_of_em\n#check dn_of_peirce\n#check em_of_dn\n\n-- enter your solution here\n\nend backward_proofs\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love02_backward_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.7240147166933429}}
{"text": "import tactic.induction\nimport tactic.ring_exp  -- for split_ifs\nimport .A_lists\n\n/-\n# 2. Trees\nWe'll prove CPS equivalences for the following tree functions:\n* `inord`\n* `fold`\n* `find`\n\nAll higher-order functions are written as \"fully-CPS\" HOFs -- in particular,\nany functional arguments must also be in CPS.\n-/\n\ninductive tree (\u03b1 : Sort _)\n| empty : tree\n| node : \u03b1 \u2192 tree \u2192 tree \u2192 tree\n\nnamespace tree\n\n-- ## 2.1. `inord`\n-- A basic inorder traversal of a tree\ndef inord {\u03b1 : Sort _} : tree \u03b1 \u2192 llist \u03b1\n| tree.empty := llist.nil\n| (tree.node x l r) := llist.append (inord l) (llist.cons x (inord r))\n\ndef inord_cps {\u03b1 \u03b2 : Sort _} : tree \u03b1 \u2192 (llist \u03b1 \u2192 \u03b2) \u2192 \u03b2\n| tree.empty k := k llist.nil\n| (tree.node x l r) k :=\n  inord_cps l (\u03bbll,\n    inord_cps r (\u03bblr,\n      llist.append_cps ll (llist.cons x lr) k\n    )\n  )\n\nlemma inord_cps_equiv_inord {\u03b1 \u03b2 : Sort _} :\n  \u2200 (t : tree \u03b1) (k : llist \u03b1 \u2192 \u03b2), inord_cps t k = k (inord t) :=\nbegin\n  intro t,\n  induction' t,\n  case empty {\n    intro k,\n    refl,\n  },\n  case node : x l r ihl ihr {\n    intro k,\n    rw inord_cps,\n    rw (ihl (\u03bb (ll : llist \u03b1), r.inord_cps (\u03bb (lr : llist \u03b1), ll.append_cps (llist.cons x lr) k))),\n    -- as advised by https://leanprover-community.github.io/extras/simp.html, we\n    -- avoid simp in the middle of a proof; this is merely to \u03b2-reduce\n    dsimp only,\n    rw (ihr (\u03bb (lr : llist \u03b1), l.inord.append_cps (llist.cons x lr) k)),\n    dsimp only,\n    rw llist.append_cps_equiv_append,\n    refl,  -- equivalently, rw \u2190inord\n  }\nend\n\n-- ## 2.2. `fold`\n-- A basic tree fold function\ndef fold {\u03b1 \u03b2 : Sort _} (f : \u03b1 \u2192 \u03b2 \u2192 \u03b2 \u2192 \u03b2) (z : \u03b2) : tree \u03b1 \u2192 \u03b2\n| tree.empty := z\n| (tree.node x l r) := f x (fold l) (fold r)\n\nuniverse u\n-- This has the same issue as the list foldr regarding type universes\n-- def fold_cps {\u03b1 : Sort _} {\u03b2 \u03b3 : Sort u} (f : \u03b1 \u2192 \u03b2 \u2192 \u03b2 \u2192 (\u03b2 \u2192 \u03b3) \u2192 \u03b3) (z : \u03b2) :\n--     tree \u03b1 \u2192 (\u03b2 \u2192 \u03b3) \u2192 \u03b3\n-- | tree.empty k := k z\n-- | (tree.node x l r) k := fold_cps l (\u03bbxl, fold_cps r (\u03bbxr, f x xl xr k))\n\ndef fold_cps {\u03b1 \u03b2 \u03b3 : Sort _} (f : \u03b1 \u2192 \u03b2 \u2192 \u03b2 \u2192 (\u03b2 \u2192 \u03b3) \u2192 \u03b3) (z : \u03b2) (t : tree \u03b1) :\n    (\u03b2 \u2192 \u03b3) \u2192 \u03b3 :=\n@tree.rec_on \u03b1 (\u03bb _, (\u03b2 \u2192 \u03b3) \u2192 \u03b3) t\n(\u03bbk, k z)\n(\u03bbx l r lrec rrec k, lrec (\u03bbxl, rrec (\u03bbxr, f x xl xr k)))\n\n-- Since using the recursor manually doesn't generate equation lemmas, we must\n-- provide them manually\nlemma fold_cps_eqn {\u03b1 \u03b2 \u03b3 : Sort _} (f : \u03b1 \u2192 \u03b2 \u2192 \u03b2 \u2192 (\u03b2 \u2192 \u03b3) \u2192 \u03b3) (z : \u03b2) (x l r) (k : \u03b2 \u2192 \u03b3) :\n  fold_cps f z (tree.node x l r) k = fold_cps f z l (\u03bbxl, fold_cps f z r (\u03bbxr, f x xl xr k)) := rfl\n\nlemma fold_cps_equiv_fold {\u03b1 \u03b2 \u03b3 : Sort _} :\n  \u2200 (f : \u03b1 \u2192 \u03b2 \u2192 \u03b2 \u2192 \u03b2) (z : \u03b2) (t : tree \u03b1) (k : \u03b2 \u2192 \u03b3),\n    fold_cps (\u03bbx l r k, k (f x l r)) z t k = k (fold f z t) :=\nbegin\n  intros f z t,\n  induction' t,\n  case empty {\n    intro k,\n    refl,\n  },\n  case node : x l r ihl ihr {\n    intro k,\n    let f_cps := (\u03bb(x : \u03b1) (l : \u03b2) (r : \u03b2) (k : \u03b2 \u2192 \u03b3), k (f x l r)),\n    rw fold_cps_eqn,  -- would be \"rw fold_cps\" if we'd defined fold_cps normally\n    rw (ihl f z (\u03bbxl, fold_cps f_cps z r (\u03bbxr, f_cps x xl xr k))),\n    dsimp only,\n    rw (ihr f z (\u03bb (xr : \u03b2), f_cps x (fold f z l) xr k)),\n    refl,\n  }\nend\n\n\n-- ## 2.3. `find`\n-- A basic find function on a tree: finds the first (preordered) element\n-- satisfying a decidable predicate p\ndef find {\u03b1 : Sort _} (p : \u03b1 \u2192 Prop) [decidable_pred p] : tree \u03b1 \u2192 option \u03b1\n| tree.empty := none\n| (tree.node x l r) :=\n  if p x\n  then x\n  else match find l with\n       | none := find r\n       | res := res\n       end\n\n/-\n A CPS version of find. We opt here for a simple success/failure continuation\n format; an alternative implementation might allow the predicate to pass\n \"evidence\" of success or failure to each continuation. For our purposes,\n however, this implementation seems reasonable (and already sufficiently\n complicated).\n-/\ndef find_cps {\u03b1 \u03b2 : Sort _} (p : \u03b1 \u2192 (unit \u2192 \u03b2) \u2192 (unit \u2192 \u03b2) \u2192 \u03b2) :\n  tree \u03b1 \u2192 (\u03b1 \u2192 \u03b2) \u2192 (unit \u2192 \u03b2) \u2192 \u03b2\n| tree.empty sk fk := fk ()\n| (tree.node x l r) sk fk := p x (\u03bb_, sk x)\n                                 (\u03bb_, find_cps l sk (\u03bb_, find_cps r sk fk))\n\n/-\n This helper lemma is slightly more general than the equivalence we want to\n prove because we need a more general induction hypothesis (namely, the failure\n continuation is not always (\u03bb_, none) in recursive calls, so we can't restrict\n ourselves to that in the general proposition); we'll recover\n find_cps_equiv_find as an instance of this.\n-/\nlemma find_cps_equiv_find_helper {\u03b1 : Sort _} (p : \u03b1 \u2192 Prop) [decidable_pred p]  :\n  \u2200 (t : tree \u03b1) (fk : unit \u2192 option \u03b1),\n    find_cps (\u03bbx sk fk, if p x then sk () else fk ())\n             t\n             some\n             fk\n    = (find p t <|> fk ()) :=\nbegin\n  intro t,\n  induction' t,\n  case empty {\n    intro fk,\n    rw [find_cps, find],\n    unfold has_orelse.orelse,\n    rw option.none_orelse',\n  },\n  case node : x l r ihl ihr {\n    intro fk,\n    rw find_cps,\n    -- Deal with bug in synthesis of decidability type-class by explicitly\n    -- resetting the index. Note that we need to do this here because otherwise\n    -- split_ifs is going to rely on classical.choice and a bunch of other\n    -- very non-constructive (and unnecessary) axioms\n    resetI,\n    split_ifs,\n    {\n      -- case p x true\n      rw find,\n      split_ifs,\n      exact with_top.some_eq_coe x,\n    },\n    {\n      -- case p x false\n      rw (ihr p fk),\n      rw (ihl p (\u03bb (_x : unit), find p r <|> fk ())),\n      rw find,\n      split_ifs, -- by case assumption, p x ==> false\n      cases' (find p l),\n      case some {\n        -- case find p l ==> some x\n        rw find._match_1,\n        refl,\n      },\n      case none {\n        -- case find p l ==> none\n        rw find._match_1,\n        unfold has_orelse.orelse,\n        cases' (find p r),\n        case some {\n          -- case find p l ==> none AND find p r ==> some x\n          rw option.none_orelse',\n        },\n        case none {\n          -- case find p r ==> none AND find p r ==> none\n          rw option.none_orelse',\n        }\n      }\n    }\n  }\nend\n\n-- We recover the desired equivalence as an instance of the helper\nlemma find_cps_equiv_find {\u03b1 : Sort _} (p : \u03b1 \u2192 Prop) [decidable_pred p]  :\n  \u2200 (t : tree \u03b1),\n    find_cps (\u03bbx sk fk, if p x then sk () else fk ())\n             t\n             some\n             (\u03bb_, none)\n    = find p t :=\nbegin\n  intro t,\n  have h := find_cps_equiv_find_helper p t (\u03bb_, none),\n  unfold has_orelse.orelse at h,\n  have h_orelse : \u2200(x : option \u03b1), option.orelse x none = x :=\n    \u03bbx, by cases' x; refl,\n  rw h_orelse at h,\n  exact h,\nend\n\nend tree\n", "meta": {"author": "jrr6", "repo": "fpv_final_project", "sha": "5a391008aee3a14fe83d628fb5805f1bec45e8ac", "save_path": "github-repos/lean/jrr6-fpv_final_project", "path": "github-repos/lean/jrr6-fpv_final_project/fpv_final_project-5a391008aee3a14fe83d628fb5805f1bec45e8ac/src/B_trees.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544824, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.7240147073193}}
{"text": "/-\nCopyright (c) 2021 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n-/\nimport algebra.lie.of_associative\nimport linear_algebra.matrix.reindex\nimport linear_algebra.matrix.to_linear_equiv\n\n/-!\n# Lie algebras of matrices\n\nAn important class of Lie algebras are those arising from the associative algebra structure on\nsquare matrices over a commutative ring. This file provides some very basic definitions whose\nprimary value stems from their utility when constructing the classical Lie algebras using matrices.\n\n## Main definitions\n\n  * `lie_equiv_matrix'`\n  * `matrix.lie_conj`\n  * `matrix.reindex_lie_equiv`\n\n## Tags\n\nlie algebra, matrix\n-/\n\nuniverses u v w w\u2081 w\u2082\n\nsection matrices\nopen_locale matrix\n\nvariables {R : Type u} [comm_ring R]\nvariables {n : Type w} [decidable_eq n] [fintype n]\n\n/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices\nis compatible with the Lie algebra structures. -/\ndef lie_equiv_matrix' : module.End R (n \u2192 R) \u2243\u2097\u2045R\u2046 matrix n n R :=\n{ map_lie' := \u03bb T S,\n  begin\n    let f := @linear_map.to_matrix' R _ n n _ _,\n    change f (T.comp S - S.comp T) = (f T) * (f S) - (f S) * (f T),\n    have h : \u2200 (T S : module.End R _), f (T.comp S) = (f T) \u2b1d (f S) := linear_map.to_matrix'_comp,\n    rw [linear_equiv.map_sub, h, h, matrix.mul_eq_mul, matrix.mul_eq_mul],\n  end,\n  ..linear_map.to_matrix' }\n\n@[simp] lemma lie_equiv_matrix'_apply (f : module.End R (n \u2192 R)) :\n  lie_equiv_matrix' f = f.to_matrix' := rfl\n\n@[simp] lemma lie_equiv_matrix'_symm_apply (A : matrix n n R) :\n  (@lie_equiv_matrix' R _ n _ _).symm A = A.to_lin' := rfl\n\n/-- An invertible matrix induces a Lie algebra equivalence from the space of matrices to itself. -/\ndef matrix.lie_conj (P : matrix n n R) (h : invertible P) :\n  matrix n n R \u2243\u2097\u2045R\u2046 matrix n n R :=\n((@lie_equiv_matrix' R _ n _ _).symm.trans (P.to_linear_equiv' h).lie_conj).trans lie_equiv_matrix'\n\n@[simp] lemma matrix.lie_conj_apply (P A : matrix n n R) (h : invertible P) :\n  P.lie_conj h A = P \u2b1d A \u2b1d P\u207b\u00b9 :=\nby simp [linear_equiv.conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,\n         linear_map.to_matrix'_to_lin']\n\n@[simp] lemma matrix.lie_conj_symm_apply (P A : matrix n n R) (h : invertible P) :\n  (P.lie_conj h).symm A = P\u207b\u00b9 \u2b1d A \u2b1d P :=\nby simp [linear_equiv.symm_conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,\n         linear_map.to_matrix'_to_lin']\n\nvariables {m : Type w\u2081} [decidable_eq m] [fintype m] (e : n \u2243 m)\n\n/-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent\ntypes, `matrix.reindex`, is an equivalence of Lie algebras. -/\ndef matrix.reindex_lie_equiv : matrix n n R \u2243\u2097\u2045R\u2046 matrix m m R :=\n{ to_fun := matrix.reindex e e,\n  map_lie' := \u03bb M N, by simp only [lie_ring.of_associative_ring_bracket, matrix.reindex_apply,\n    matrix.submatrix_mul_equiv, matrix.mul_eq_mul, matrix.submatrix_sub, pi.sub_apply],\n  ..(matrix.reindex_linear_equiv R R e e) }\n\n@[simp] lemma matrix.reindex_lie_equiv_apply (M : matrix n n R) :\n  matrix.reindex_lie_equiv e M = matrix.reindex e e M := rfl\n\n@[simp] lemma matrix.reindex_lie_equiv_symm :\n  (matrix.reindex_lie_equiv e : _ \u2243\u2097\u2045R\u2046 _).symm = matrix.reindex_lie_equiv e.symm := rfl\n\nend matrices\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/lie/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7240084394300935}}
{"text": "import Hm.Set\nimport Hm.Relation\n\nclass HasPrec (\u03b1 : Sort u) where\n  Prec : \u03b1 \u2192 \u03b1 \u2192 Sort v\n\nexport HasPrec (Prec)\n  \nclass HasPrecEq (\u03b1 : Sort u) where\n  PrecEq : \u03b1 \u2192 \u03b1 \u2192 Sort v\n  \nexport HasPrecEq (PrecEq)\n\ninfix:55 \" \u227a \" => HasPrec.Prec\ninfix:55 \" \u227c \" => HasPrecEq.PrecEq\n\nclass PartialOrder {\u03b1 : Type _} (rel : RelationOn \u03b1) where\n  reflexive : reflexive rel\n  antisymmetrical : antisymmetrical rel\n  transitive : transitive rel\n  \nclass StrictPartialOrder {\u03b1 : Type _} (rel : RelationOn \u03b1) where\n  irreflexive : irreflexive rel\n  asymmetrical : asymmetrical rel\n  transitive : transitive rel\n\n/-\nThese instances allow us to use \u227a and \u227c (denoted with \\prec \\preceq)\nwhen we know there exist PartialOrder Relations on a type \u03b1\n\nvariable (\u03b1 : Type u) (a b : \u03b1) (R : RelationOn \u03b1) [PartialOrder R]\n#check a \u227c b\n\nAnd\n\nvariable (\u03b1 : Type u) (a b : \u03b1) (R : RelationOn \u03b1) [StrictPartialOrder R]\n#check a \u227a b\n\nHowever you have to be careful about this in the presence of multiple\nPartialOrder / StrictPartialOrder relations at once since lean will\nautomatically pick one according to what it thinks is best. This might\nhowever not be what you think is best\n-/\n\ninstance {R : RelationOn \u03b1} [PartialOrder R] : HasPrecEq \u03b1 where\n  PrecEq := \u03bb a b => (a, b) \u2208 R\n\ninstance {R : RelationOn \u03b1} [StrictPartialOrder R] : HasPrec \u03b1 where\n  Prec := \u03bb a b => (a, b) \u2208 R\n\ndef comparable {\u03b1 : Type u} (R : RelationOn \u03b1) [PartialOrder R] (a : \u03b1) (b : \u03b1) : Prop := a \u227c b \u2228 b \u227c a\n\ndef strict_comparable {\u03b1 : Type u} (R : RelationOn \u03b1) [StrictPartialOrder R] (a : \u03b1) (b : \u03b1) : Prop := a \u227a b \u2228 b \u227a a\n\nclass TotalOrder {\u03b1 : Type _} (rel : RelationOn \u03b1) extends PartialOrder rel where\n  total : \u2200 a b, comparable rel a b\n\nclass StrictTotalOrder {\u03b1 : Type _} (rel : RelationOn \u03b1) extends StrictPartialOrder rel where\n  total : \u2200 a b, strict_comparable rel a b\n\nnamespace PartialOrder\n\ndef minimum (R : RelationOn \u03b1) [PartialOrder R] (x : \u03b1) : Prop := \u00ac(\u2203 y, y \u2260 x \u2227 y \u227c x)\ndef topoligical_sorting (TR : RelationOn \u03b1) [TotalOrder TR] (R : RelationOn \u03b1) [PartialOrder R] : Prop :=\n  R \u2286 TR\n  \ninductive Chain {\u03b1 : Type u} (R: RelationOn \u03b1) [PartialOrder R] : List \u03b1 \u2192 Prop where\n| single : Chain R [a]\n| cons_cons (preceq: a \u227c b) (neq: a \u2260 b) : Chain R (b :: l) \u2192 Chain R (a :: b :: l)\n\n-- A Tactic that can do stuff like this automatically might be interesting\nexample [PartialOrder (Nat.le : RelationOn Nat)]: Chain (Nat.le : RelationOn Nat) [0, 1, 2] := by\n  apply Chain.cons_cons\n  case preceq =>\n    exact Nat.le.step $ Nat.le.refl\n  case neq =>\n    intro h\n    injection h\n  case a =>\n    apply Chain.cons_cons\n    case preceq =>\n      exact Nat.le.step $ Nat.le.refl\n    case neq =>\n      intro h\n      injection h with h\n      injection h\n    case a =>\n      exact Chain.single\nend PartialOrder\n\nnamespace StrictPartialOrder\n\n\ndef minimum (R : RelationOn \u03b1) [StrictPartialOrder R] (x : \u03b1) : Prop := \u00ac(\u2203y, y \u2260 x \u2227 y \u227a x)\ndef topoligical_sorting (TR : RelationOn \u03b1) [StrictTotalOrder TR] (R : RelationOn \u03b1) [StrictPartialOrder R] : Prop :=\n  R \u2286 TR\n\ninductive Chain {\u03b1 : Type u} (R: RelationOn \u03b1) [StrictPartialOrder R] : List \u03b1 \u2192 Prop where\n| single : Chain R [a]\n| cons_cons (prec: a \u227a b) : Chain R (b :: l) \u2192 Chain R (a :: b :: l)\n\nexample [StrictPartialOrder (Nat.lt : RelationOn Nat)]: Chain (Nat.lt : RelationOn Nat) [0, 1, 2] := by\n  apply Chain.cons_cons\n  case prec =>\n    exact Nat.lt.base 0\n  case a =>\n    apply Chain.cons_cons\n    case prec =>\n      exact Nat.lt.base 1\n    case a =>\n      exact Chain.single\n\nend StrictPartialOrder\n\n", "meta": {"author": "hargoniX", "repo": "lean-hm", "sha": "950f020f7ce296e45a5e8ed638655f643be3d5e0", "save_path": "github-repos/lean/hargoniX-lean-hm", "path": "github-repos/lean/hargoniX-lean-hm/lean-hm-950f020f7ce296e45a5e8ed638655f643be3d5e0/Hm/Order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7240084389152615}}
{"text": "/-\nCopyright (c) 2023 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n\n! This file was ported from Lean 3 source module probability.kernel.invariance\n! leanprover-community/mathlib commit 97d1aa955750bd57a7eeef91de310e633881670b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Probability.Kernel.Composition\n\n/-!\n# Invariance of measures along a kernel\n\nWe define the push-forward of a measure along a kernel which results in another measure. In the\ncase that the push-forward measure is the same as the original measure, we say that the measure is\ninvariant with respect to the kernel.\n\n## Main definitions\n\n* `probability_theory.kernel.map_measure`: the push-forward of a measure along a kernel.\n* `probability_theory.kernel.invariant`: invariance of a given measure with respect to a kernel.\n\n## Useful lemmas\n\n* `probability_theory.kernel.comp_apply_eq_map_measure`,\n  `probability_theory.kernel.const_map_measure_eq_comp_const`, and\n  `probability_theory.kernel.comp_const_apply_eq_map_measure` established the relationship between\n  the push-forward measure and the composition of kernels.\n\n-/\n\n\nopen MeasureTheory\n\nopen MeasureTheory ENNReal ProbabilityTheory\n\nnamespace ProbabilityTheory\n\nvariable {\u03b1 \u03b2 \u03b3 : Type _} {m\u03b1 : MeasurableSpace \u03b1} {m\u03b2 : MeasurableSpace \u03b2} {m\u03b3 : MeasurableSpace \u03b3}\n\ninclude m\u03b1 m\u03b2\n\nnamespace Kernel\n\n/-! ### Push-forward of measures along a kernel -/\n\n\n/-- The push-forward of a measure along a kernel. -/\nnoncomputable def mapMeasure (\u03ba : kernel \u03b1 \u03b2) (\u03bc : Measure \u03b1) : Measure \u03b2 :=\n  Measure.ofMeasurable (fun s hs => \u222b\u207b x, \u03ba x s \u2202\u03bc)\n    (by simp only [measure_empty, lintegral_const, MulZeroClass.zero_mul])\n    (by\n      intro f hf\u2081 hf\u2082\n      simp_rw [measure_Union hf\u2082 hf\u2081,\n        lintegral_tsum fun i => (kernel.measurable_coe \u03ba (hf\u2081 i)).AeMeasurable])\n#align probability_theory.kernel.map_measure ProbabilityTheory.kernel.mapMeasure\n\n@[simp]\ntheorem mapMeasure_apply (\u03ba : kernel \u03b1 \u03b2) (\u03bc : Measure \u03b1) {s : Set \u03b2} (hs : MeasurableSet s) :\n    mapMeasure \u03ba \u03bc s = \u222b\u207b x, \u03ba x s \u2202\u03bc := by rw [map_measure, measure.of_measurable_apply s hs]\n#align probability_theory.kernel.map_measure_apply ProbabilityTheory.kernel.mapMeasure_apply\n\n@[simp]\ntheorem mapMeasure_zero (\u03ba : kernel \u03b1 \u03b2) : mapMeasure \u03ba 0 = 0 :=\n  by\n  ext1 s hs\n  rw [map_measure_apply \u03ba 0 hs, lintegral_zero_measure, measure.coe_zero, Pi.zero_apply]\n#align probability_theory.kernel.map_measure_zero ProbabilityTheory.kernel.mapMeasure_zero\n\n@[simp]\ntheorem mapMeasure_add (\u03ba : kernel \u03b1 \u03b2) (\u03bc \u03bd : Measure \u03b1) :\n    mapMeasure \u03ba (\u03bc + \u03bd) = mapMeasure \u03ba \u03bc + mapMeasure \u03ba \u03bd :=\n  by\n  ext1 s hs\n  rw [map_measure_apply \u03ba (\u03bc + \u03bd) hs, lintegral_add_measure, measure.coe_add, Pi.add_apply,\n    map_measure_apply \u03ba \u03bc hs, map_measure_apply \u03ba \u03bd hs]\n#align probability_theory.kernel.map_measure_add ProbabilityTheory.kernel.mapMeasure_add\n\n@[simp]\ntheorem mapMeasure_smul (\u03ba : kernel \u03b1 \u03b2) (\u03bc : Measure \u03b1) (r : \u211d\u22650\u221e) :\n    mapMeasure \u03ba (r \u2022 \u03bc) = r \u2022 mapMeasure \u03ba \u03bc :=\n  by\n  ext1 s hs\n  rw [map_measure_apply \u03ba (r \u2022 \u03bc) hs, lintegral_smul_measure, measure.coe_smul, Pi.smul_apply,\n    map_measure_apply \u03ba \u03bc hs, smul_eq_mul]\n#align probability_theory.kernel.map_measure_smul ProbabilityTheory.kernel.mapMeasure_smul\n\ninclude m\u03b3\n\ntheorem comp_apply_eq_mapMeasure (\u03b7 : kernel \u03b2 \u03b3) [IsSFiniteKernel \u03b7] (\u03ba : kernel \u03b1 \u03b2)\n    [IsSFiniteKernel \u03ba] (a : \u03b1) : (\u03b7 \u2218\u2096 \u03ba) a = mapMeasure \u03b7 (\u03ba a) :=\n  by\n  ext1 s hs\n  rw [comp_apply \u03b7 \u03ba a hs, map_measure_apply \u03b7 _ hs]\n#align probability_theory.kernel.comp_apply_eq_map_measure ProbabilityTheory.kernel.comp_apply_eq_mapMeasure\n\nomit m\u03b3\n\ntheorem const_mapMeasure_eq_comp_const (\u03ba : kernel \u03b1 \u03b2) [IsSFiniteKernel \u03ba] (\u03bc : Measure \u03b1)\n    [IsFiniteMeasure \u03bc] : const \u03b1 (mapMeasure \u03ba \u03bc) = \u03ba \u2218\u2096 const \u03b1 \u03bc :=\n  by\n  ext1 a; ext1 s hs\n  rw [const_apply, map_measure_apply _ _ hs, comp_apply _ _ _ hs, const_apply]\n#align probability_theory.kernel.const_map_measure_eq_comp_const ProbabilityTheory.kernel.const_mapMeasure_eq_comp_const\n\ntheorem comp_const_apply_eq_mapMeasure (\u03ba : kernel \u03b1 \u03b2) [IsSFiniteKernel \u03ba] (\u03bc : Measure \u03b1)\n    [IsFiniteMeasure \u03bc] (a : \u03b1) : (\u03ba \u2218\u2096 const \u03b1 \u03bc) a = mapMeasure \u03ba \u03bc := by\n  rw [\u2190 const_apply (map_measure \u03ba \u03bc) a, const_map_measure_eq_comp_const \u03ba \u03bc]\n#align probability_theory.kernel.comp_const_apply_eq_map_measure ProbabilityTheory.kernel.comp_const_apply_eq_mapMeasure\n\ntheorem lintegral_mapMeasure (\u03ba : kernel \u03b1 \u03b2) [IsSFiniteKernel \u03ba] (\u03bc : Measure \u03b1)\n    [IsFiniteMeasure \u03bc] {f : \u03b2 \u2192 \u211d\u22650\u221e} (hf : Measurable f) :\n    (\u222b\u207b b, f b \u2202mapMeasure \u03ba \u03bc) = \u222b\u207b a, \u222b\u207b b, f b \u2202\u03ba a \u2202\u03bc :=\n  by\n  by_cases h\u03b1 : Nonempty \u03b1\n  \u00b7 have := const_apply \u03bc h\u03b1.some\n    swap\n    infer_instance\n    conv_rhs => rw [\u2190 this]\n    rw [\u2190 lintegral_comp _ _ _ hf, \u2190 comp_const_apply_eq_map_measure \u03ba \u03bc h\u03b1.some]\n  \u00b7 haveI := not_nonempty_iff.1 h\u03b1\n    rw [\u03bc.eq_zero_of_is_empty, map_measure_zero, lintegral_zero_measure, lintegral_zero_measure]\n#align probability_theory.kernel.lintegral_map_measure ProbabilityTheory.kernel.lintegral_mapMeasure\n\nomit m\u03b2\n\n/-! ### Invariant measures of kernels -/\n\n\n/-- A measure `\u03bc` is invariant with respect to the kernel `\u03ba` if the push-forward measure of `\u03bc`\nalong `\u03ba` equals `\u03bc`. -/\ndef Invariant (\u03ba : kernel \u03b1 \u03b1) (\u03bc : Measure \u03b1) : Prop :=\n  mapMeasure \u03ba \u03bc = \u03bc\n#align probability_theory.kernel.invariant ProbabilityTheory.kernel.Invariant\n\nvariable {\u03ba \u03b7 : kernel \u03b1 \u03b1} {\u03bc : Measure \u03b1}\n\ntheorem Invariant.def (h\u03ba : Invariant \u03ba \u03bc) : mapMeasure \u03ba \u03bc = \u03bc :=\n  h\u03ba\n#align probability_theory.kernel.invariant.def ProbabilityTheory.kernel.Invariant.def\n\ntheorem Invariant.comp_const [IsSFiniteKernel \u03ba] [IsFiniteMeasure \u03bc] (h\u03ba : Invariant \u03ba \u03bc) :\n    \u03ba \u2218\u2096 const \u03b1 \u03bc = const \u03b1 \u03bc := by rw [\u2190 const_map_measure_eq_comp_const \u03ba \u03bc, h\u03ba.def]\n#align probability_theory.kernel.invariant.comp_const ProbabilityTheory.kernel.Invariant.comp_const\n\ntheorem Invariant.comp [IsSFiniteKernel \u03ba] [IsSFiniteKernel \u03b7] [IsFiniteMeasure \u03bc]\n    (h\u03ba : Invariant \u03ba \u03bc) (h\u03b7 : Invariant \u03b7 \u03bc) : Invariant (\u03ba \u2218\u2096 \u03b7) \u03bc :=\n  by\n  by_cases h\u03b1 : Nonempty \u03b1\n  \u00b7\n    simp_rw [invariant, \u2190 comp_const_apply_eq_map_measure (\u03ba \u2218\u2096 \u03b7) \u03bc h\u03b1.some, comp_assoc,\n      h\u03b7.comp_const, h\u03ba.comp_const, const_apply]\n  \u00b7 haveI := not_nonempty_iff.1 h\u03b1\n    exact Subsingleton.elim _ _\n#align probability_theory.kernel.invariant.comp ProbabilityTheory.kernel.Invariant.comp\n\nend Kernel\n\nend ProbabilityTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Probability/Kernel/Invariance.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7240084373854327}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.real.basic\nimport data.real.sqrt\nimport data.nat.prime\nimport number_theory.primes_congruent_one\nimport number_theory.legendre_symbol.quadratic_reciprocity\nimport tactic.linear_combination\n\n/-!\n# IMO 2008 Q3\nProve that there exist infinitely many positive integers `n` such that `n^2 + 1` has a prime\ndivisor which is greater than `2n + \u221a(2n)`.\n\n# Solution\nWe first prove the following lemma: for every prime `p > 20`, satisfying `p \u2261 1 [MOD 4]`,\nthere exists `n \u2208 \u2115` such that `p \u2223 n^2 + 1` and `p > 2n + \u221a(2n)`. Then the statement of the\nproblem follows from the fact that there exist infinitely many primes `p \u2261 1 [MOD 4]`.\n\nTo prove the lemma, notice that `p \u2261 1 [MOD 4]` implies `\u2203 n \u2208 \u2115` such that `n^2 \u2261 -1 [MOD p]`\nand we can take this `n` such that `n \u2264 p/2`. Let `k = p - 2n \u2265 0`. Then we have:\n`k^2 + 4 = (p - 2n)^2 + 4 \u2263 4n^2 + 4 \u2261 0 [MOD p]`. Then `k^2 + 4 \u2265 p` and so `k \u2265 \u221a(p - 4) > 4`.\nThen `p = 2n + k \u2265 2n + \u221a(p - 4) = 2n + \u221a(2n + k - 4) > \u221a(2n)` and we are done.\n-/\n\nopen real\n\nlemma p_lemma (p : \u2115) (hpp : nat.prime p) (hp_mod_4_eq_1 : p \u2261 1 [MOD 4]) (hp_gt_20 : p > 20) :\n  \u2203 n : \u2115, p \u2223 n ^ 2 + 1 \u2227 (p : \u211d) > 2 * n + sqrt(2 * n) :=\nbegin\n  haveI := fact.mk hpp,\n  have hp_mod_4_ne_3 : p % 4 \u2260 3, { linarith [(show p % 4 = 1, by exact hp_mod_4_eq_1)] },\n  obtain \u27e8y, hy\u27e9 := zmod.exists_sq_eq_neg_one_iff.mpr hp_mod_4_ne_3,\n\n  let m := zmod.val_min_abs y,\n  let n := int.nat_abs m,\n\n  have hnat\u2081 : p \u2223 n ^ 2 + 1,\n  { refine int.coe_nat_dvd.mp _,\n    simp only [int.nat_abs_sq, int.coe_nat_pow, int.coe_nat_succ, int.coe_nat_dvd.mp],\n    refine (zmod.int_coe_zmod_eq_zero_iff_dvd (m ^ 2 + 1) p).mp _,\n    simp only [int.cast_pow, int.cast_add, int.cast_one, zmod.coe_val_min_abs],\n    rw [pow_two, \u2190 hy], exact add_left_neg 1 },\n\n  have hnat\u2082 : n \u2264 p / 2 := zmod.nat_abs_val_min_abs_le y,\n  have hnat\u2083 : p \u2265 2 * n, { linarith [nat.div_mul_le_self p 2] },\n\n  set k : \u2115 := p - 2 * n with hnat\u2084,\n\n  have hnat\u2085 : p \u2223 k ^ 2 + 4,\n  { cases hnat\u2081 with x hx,\n    have : (p:\u2124) \u2223 k ^ 2 + 4,\n    { use (p:\u2124) - 4 * n + 4 * x,\n      have hcast\u2081 : (k:\u2124) = p - 2 * n, { assumption_mod_cast },\n      have hcast\u2082 : (n:\u2124) ^ 2 + 1 = p * x, { assumption_mod_cast },\n      linear_combination ((k:\u2124) + p - 2 * n)*hcast\u2081 + 4*hcast\u2082 },\n    assumption_mod_cast },\n\n  have hnat\u2086 : k ^ 2 + 4 \u2265 p := nat.le_of_dvd (k ^ 2 + 3).succ_pos hnat\u2085,\n\n  have hreal\u2081 : (k:\u211d) = p - 2 * n, { assumption_mod_cast },\n  have hreal\u2082 : (p:\u211d) > 20,        { assumption_mod_cast },\n  have hreal\u2083 : (k:\u211d) ^ 2 + 4 \u2265 p, { assumption_mod_cast },\n\n  have hreal\u2085 : (k:\u211d) > 4,\n  { refine lt_of_pow_lt_pow 2 k.cast_nonneg _,\n    linarith only [hreal\u2082, hreal\u2083] },\n\n  have hreal\u2086 : (k:\u211d) > sqrt (2 * n),\n  { refine lt_of_pow_lt_pow 2 k.cast_nonneg _,\n    rw sq_sqrt (mul_nonneg zero_le_two n.cast_nonneg),\n    linarith only [hreal\u2081, hreal\u2083, hreal\u2085] },\n\n  exact \u27e8n, hnat\u2081, by linarith only [hreal\u2086, hreal\u2081]\u27e9,\nend\n\ntheorem imo2008_q3 : \u2200 N : \u2115, \u2203 n : \u2115, n \u2265 N \u2227\n  \u2203 p : \u2115, nat.prime p \u2227 p \u2223 n ^ 2 + 1 \u2227 (p : \u211d) > 2 * n + sqrt(2 * n) :=\nbegin\n  intro N,\n  obtain \u27e8p, hpp, hineq\u2081, hpmod4\u27e9 := nat.exists_prime_gt_modeq_one (N ^ 2 + 20) four_ne_zero,\n  obtain \u27e8n, hnat, hreal\u27e9 := p_lemma p hpp hpmod4 (by linarith [hineq\u2081, nat.zero_le (N ^ 2)]),\n\n  have hineq\u2082  : n ^ 2 + 1 \u2265 p := nat.le_of_dvd (n ^ 2).succ_pos hnat,\n  have hineq\u2083  : n * n \u2265 N * N, { linarith [hineq\u2081, hineq\u2082] },\n  have hn_ge_N : n \u2265 N := nat.mul_self_le_mul_self_iff.mpr hineq\u2083,\n\n  exact \u27e8n, hn_ge_N, p, hpp, hnat, hreal\u27e9,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2008_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.7240084274048753}}
{"text": "/-\nCopyright (c) 2020 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\nPorted by: Anatole Dedecker\n\n! This file was ported from Lean 3 source module data.set.accumulate\n! leanprover-community/mathlib commit 207cfac9fcd06138865b5d04f7091e46d9320432\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Lattice\n\n/-!\n# Accumulate\n\nThe function `Accumulate` takes a set `s` and returns `\u22c3 y \u2264 x, s y`.\n-/\n\n\nvariable {\u03b1 \u03b2 \u03b3 : Type _} {s : \u03b1 \u2192 Set \u03b2} {t : \u03b1 \u2192 Set \u03b3}\n\nnamespace Set\n\n/-- `Accumulate s` is the union of `s y` for `y \u2264 x`. -/\ndef Accumulate [LE \u03b1] (s : \u03b1 \u2192 Set \u03b2) (x : \u03b1) : Set \u03b2 :=\n  \u22c3 y \u2264 x, s y\n#align set.accumulate Set.Accumulate\n\ntheorem accumulate_def [LE \u03b1] {x : \u03b1} : Accumulate s x = \u22c3 y \u2264 x, s y :=\n  rfl\n#align set.accumulate_def Set.accumulate_def\n\n@[simp]\ntheorem mem_accumulate [LE \u03b1] {x : \u03b1} {z : \u03b2} : z \u2208 Accumulate s x \u2194 \u2203 y \u2264 x, z \u2208 s y := by\n  simp_rw [accumulate_def, mem_union\u1d62\u2082, exists_prop]\n#align set.mem_accumulate Set.mem_accumulate\n\ntheorem subset_accumulate [Preorder \u03b1] {x : \u03b1} : s x \u2286 Accumulate s x := fun _ => mem_bunion\u1d62 le_rfl\n#align set.subset_accumulate Set.subset_accumulate\n\ntheorem monotone_accumulate [Preorder \u03b1] : Monotone (Accumulate s) := fun _ _ hxy =>\n  bunion\u1d62_subset_bunion\u1d62_left fun _ hz => le_trans hz hxy\n#align set.monotone_accumulate Set.monotone_accumulate\n\ntheorem bunion\u1d62_accumulate [Preorder \u03b1] (x : \u03b1) : (\u22c3 y \u2264 x, Accumulate s y) = \u22c3 y \u2264 x, s y := by\n  apply Subset.antisymm\n  \u00b7 exact union\u1d62\u2082_subset fun y hy => monotone_accumulate hy\n  \u00b7 exact union\u1d62\u2082_mono fun y _ => subset_accumulate\n#align set.bUnion_accumulate Set.bunion\u1d62_accumulate\n\ntheorem union\u1d62_accumulate [Preorder \u03b1] : (\u22c3 x, Accumulate s x) = \u22c3 x, s x := by\n  apply Subset.antisymm\n  \u00b7 simp only [subset_def, mem_union\u1d62, exists_imp, mem_accumulate]\n    intro z x x' \u27e8_, hz\u27e9\n    exact \u27e8x', hz\u27e9\n  \u00b7 exact union\u1d62_mono fun i => subset_accumulate\n#align set.Union_accumulate Set.union\u1d62_accumulate\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Accumulate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8459424450764199, "lm_q1q2_score": 0.7240008118869418}}
{"text": "import algebra.group_power\n\ntheorem nat.cast_pow {\u03b1 : Type*} [semiring \u03b1] (n : \u2115) : \u2200 m : \u2115, (n : \u03b1) ^ m = (n ^ m : \u2115)\n| 0 := nat.cast_one.symm\n| (d+1) := show \u2191n * \u2191n ^ d = \u2191(n ^ d * n), by rw [nat.cast_pow d,mul_comm,nat.cast_mul]\n\ntheorem int.cast_pow {\u03b1 : Type*} [ring \u03b1] (n : \u2124) : \u2200 m : \u2115, (n : \u03b1) ^ m = (n ^ m : \u2124)\n| 0 := nat.cast_one.symm\n| (d+1) := show \u2191n * \u2191n ^ d = \u2191(n * n ^ d), by rw [int.cast_pow d,int.cast_mul]\n\ntheorem nat.cast_pow' (n : \u2115) : \u2200 m : \u2115, (n : \u2124) ^ m = (n ^ m : \u2115)\n| 0 := nat.cast_one.symm\n| (d+1) := show \u2191n * \u2191n ^ d = \u2191(n ^ d * n),\nby rw [nat.cast_pow',mul_comm,int.coe_nat_mul]\n\ntheorem nat.pow_pow (n a : \u2115) : \u2200 b : \u2115, (n ^ a) ^ b = n ^ (a * b)\n| 0 := by rw mul_zero;refl\n| (d+1) := show (n^a)^d * n^a = _, by rw [mul_add,mul_one,nat.pow_add,nat.pow_pow]\n\ntheorem nat.mul_div {a b : \u2115} (Ha : a \u2260 0) (Hd :  a \u2223 b) : a * (b / a) = b :=\nby rw nat.dvd_iff_mod_eq_zero at Hd;exact zero_add (a * (b / a)) \u25b8 (Hd \u25b8 nat.mod_add_div b a)\n\ntheorem nat.pow_two (a : \u2115) : a ^ 2 = a * a := show (1 * a) * a = _, by rw one_mul\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/xenalib/nat_stuff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7239931278194565}}
{"text": "universe u\n\nexample {\u03b1 : Type u} [ring \u03b1] (a b c : \u03b1) : a * 0 + 0 * b + c * 0 + 0 * a = 0 :=\nbegin\n  rw [mul_zero, mul_zero, zero_mul, zero_mul],\n  repeat { rw add_zero }\nend\n\nexample {\u03b1 : Type u} [group \u03b1] {a b : \u03b1} (h : a * b = 1) : a\u207b\u00b9 = b :=\n  by rw [\u2190(mul_one a\u207b\u00b9), \u2190h, inv_mul_cancel_left]\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch5/ex0608.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218434359675, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7239931252934707}}
{"text": "import data.finset.basic\nimport data.fintype.basic\n\nnamespace finset\n\ntheorem ex_x_ne_y_of_card_ge_two {\u03b1 : Type*} [decidable_eq \u03b1] \n  {s : finset \u03b1} : s.card \u2265 2 \u2192 \u2203 x \u2208 s, \u2203 y \u2208 s, x \u2260 y :=\nbegin\n  intro h_card,\n  have hs : \u2203 n : \u2115, s.card = n + 2,\n  { use s.card - 2,\n    rw \u2190 nat.sub_eq_iff_eq_add,\n    exact h_card, },\n  cases hs with n hn,\n  rw finset.card_eq_succ at hn,\n  rcases hn with \u27e8x, s', hx, hs', hn'\u27e9, \n  rw finset.card_eq_succ at hn',\n  rcases hn' with \u27e8y, s'', _, hs'', _\u27e9,\n  have hy : y \u2208 s',\n  { rw \u2190 hs'',\n    exact finset.mem_insert_self y s'', },\n  use x,\n  split,\n  { rw \u2190 hs',\n    exact finset.mem_insert_self x s', },\n  { use y,\n    split,\n    apply finset.mem_of_subset,\n    { rw \u2190 hs',\n      exact finset.subset_insert x s', },\n    { exact hy, },\n    symmetry,\n    exact ne_of_mem_of_not_mem hy hx, },\nend\n\nend finset\n\nnamespace fintype\n\ntheorem ex_x_ne_y_of_card_ge_two {\u03b1 : Type*} \n  [decidable_eq \u03b1] [fintype \u03b1] : \nfintype.card \u03b1 \u2265 2 \u2192 \u2203 x y : \u03b1, x \u2260 y :=\nbegin\n  intro h_card,\n  rcases finset.ex_x_ne_y_of_card_ge_two \n    (show finset.univ.card \u2265 2, by {rw finset.card_univ, exact h_card})\n    with \u27e8x, _, y, _, hxy\u27e9,\n  exact \u27e8x, y, hxy\u27e9,\nend\n\nend fintype", "meta": {"author": "andrei232000", "repo": "4th_year_project", "sha": "8836b40a6470960c96de3deaa18754be4792ed0c", "save_path": "github-repos/lean/andrei232000-4th_year_project", "path": "github-repos/lean/andrei232000-4th_year_project/4th_year_project-8836b40a6470960c96de3deaa18754be4792ed0c/src/finset_fintype_aux.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.723993115185467}}
{"text": "import data.set.basic -- hide\nimport tactic -- hide\nopen set -- hide\n\nopen set function -- hide\n\nvariables {X Y I: Type} -- hide\n/-\n# Level 1: The image of an indexed union\n\nThis level is similar to the previous one. You can use a similar strategy.\n\n-/\n\n/- Lemma\nIf f is a function and A\u1d62 are sets, then f(\u22c3 A\u1d62) = \u22c3 f(A\u1d62)\n-/\nlemma image_Union (f: X \u2192 Y) ( A : I \u2192 set X) : f '' ( \u22c3 i, A i ) = \u22c3 i, f '' A i :=\nbegin \n  ext y,\n  split,\n  {\n    intro h1,\n    cases h1 with x hx, -- millor donar noms, per facilitar l'argument\n    cases hx with hx1 hx2, -- no tenia bons noms, per\u00f2 almenys s\u00f3n m\u00e9s curts\n    simp,\n    rw \u2190 hx2, --aqu\u00ed voldria combinar dues hipotesis per obtenir el goal\n    cases hx1 with U hU,\n    simp at hU,\n    cases hU with hU1 hU2,\n    cases hU1 with i hi,\n    -- Ara hem de fer servir les hip\u00f2tesis que tenim...\n    use i, -- l'index que busquem l'acabem d'obtenir al pas anterior\n    use x,\n    rw hi,\n    exact \u27e8hU2, rfl\u27e9,\n  },\n  {\n    intro h1,\n    simp at h1,\n    cases h1 with i hx,\n    simp,\n    cases hx with x hx2,\n    cases hx2 with hxA hxy,\n    use x,\n    use i, \n  {\n    exact hxA,\n  },\n  {\n    exact hxy,\n  },\n  },\nend\n", "meta": {"author": "mmasdeu", "repo": "topologygame", "sha": "0a1b868031919a5555e7b99efca66ece2f546ec7", "save_path": "github-repos/lean/mmasdeu-topologygame", "path": "github-repos/lean/mmasdeu-topologygame/topologygame-0a1b868031919a5555e7b99efca66ece2f546ec7/src/function_world/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7239748716223569}}
{"text": "import data.nat.basic \n\nnamespace nat\n\nlemma max_succ_succ {m n} : \n  max (succ m) (succ n) = succ (max m n) :=\nbegin\n  by_cases h1 : m \u2264 n, \n  rw [max_eq_right h1, max_eq_right (succ_le_succ h1)], \n  { rw not_le at h1, have h2 := le_of_lt h1,\n    rw [max_eq_left h2, max_eq_left (succ_le_succ h2)] }\nend\n\nend nat", "meta": {"author": "skbaek", "repo": "cvx", "sha": "c50c790c9116f9fac8dfe742903a62bdd7292c15", "save_path": "github-repos/lean/skbaek-cvx", "path": "github-repos/lean/skbaek-cvx/cvx-c50c790c9116f9fac8dfe742903a62bdd7292c15/src/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191322715435, "lm_q2_score": 0.7577943712746407, "lm_q1q2_score": 0.7239354612063497}}
{"text": "/-\nCopyright (c) 2022 Kevin H. Wilson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin H. Wilson\n\n! This file was ported from Lean 3 source module analysis.sum_integral_comparisons\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Integral.IntervalIntegral\nimport Mathbin.Data.Set.Function\nimport Mathbin.Analysis.SpecialFunctions.Integrals\n\n/-!\n# Comparing sums and integrals\n\n## Summary\n\nIt is often the case that error terms in analysis can be computed by comparing\nan infinite sum to the improper integral of an antitone function. This file will eventually enable\nthat.\n\nAt the moment it contains four lemmas in this direction: `antitone_on.integral_le_sum`,\n`antitone_on.sum_le_integral` and versions for monotone functions, which can all be paired\nwith a `filter.tendsto` to estimate some errors.\n\n`TODO`: Add more lemmas to the API to directly address limiting issues\n\n## Main Results\n\n* `antitone_on.integral_le_sum`: The integral of an antitone function is at most the sum of its\n  values at integer steps aligning with the left-hand side of the interval\n* `antitone_on.sum_le_integral`: The sum of an antitone function along integer steps aligning with\n  the right-hand side of the interval is at most the integral of the function along that interval\n* `monotone_on.integral_le_sum`: The integral of a monotone function is at most the sum of its\n  values at integer steps aligning with the right-hand side of the interval\n* `monotone_on.sum_le_integral`: The sum of a monotone function along integer steps aligning with\n  the left-hand side of the interval is at most the integral of the function along that interval\n\n## Tags\n\nanalysis, comparison, asymptotics\n-/\n\n\nopen Set MeasureTheory.MeasureSpace\n\nopen BigOperators\n\nvariable {x\u2080 : \u211d} {a b : \u2115} {f : \u211d \u2192 \u211d}\n\ntheorem AntitoneOn.integral_le_sum (hf : AntitoneOn f (Icc x\u2080 (x\u2080 + a))) :\n    (\u222b x in x\u2080..x\u2080 + a, f x) \u2264 \u2211 i in Finset.range a, f (x\u2080 + i) :=\n  by\n  have hint : \u2200 k : \u2115, k < a \u2192 IntervalIntegrable f volume (x\u2080 + k) (x\u2080 + (k + 1 : \u2115)) :=\n    by\n    intro k hk\n    refine' (hf.mono _).IntervalIntegrable\n    rw [uIcc_of_le]\n    \u00b7 apply Icc_subset_Icc\n      \u00b7 simp only [le_add_iff_nonneg_right, Nat.cast_nonneg]\n      \u00b7 simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk]\n    \u00b7 simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ]\n  calc\n    (\u222b x in x\u2080..x\u2080 + a, f x) = \u2211 i in Finset.range a, \u222b x in x\u2080 + i..x\u2080 + (i + 1 : \u2115), f x :=\n      by\n      convert(intervalIntegral.sum_integral_adjacent_intervals hint).symm\n      simp only [Nat.cast_zero, add_zero]\n    _ \u2264 \u2211 i in Finset.range a, \u222b x in x\u2080 + i..x\u2080 + (i + 1 : \u2115), f (x\u2080 + i) :=\n      by\n      apply Finset.sum_le_sum fun i hi => _\n      have ia : i < a := Finset.mem_range.1 hi\n      refine' intervalIntegral.integral_mono_on (by simp) (hint _ ia) (by simp) fun x hx => _\n      apply hf _ _ hx.1\n      \u00b7\n        simp only [ia.le, mem_Icc, le_add_iff_nonneg_right, Nat.cast_nonneg, add_le_add_iff_left,\n          Nat.cast_le, and_self_iff]\n      \u00b7 refine' mem_Icc.2 \u27e8le_trans (by simp) hx.1, le_trans hx.2 _\u27e9\n        simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt ia]\n    _ = \u2211 i in Finset.range a, f (x\u2080 + i) := by simp\n    \n#align antitone_on.integral_le_sum AntitoneOn.integral_le_sum\n\ntheorem AntitoneOn.integral_le_sum_Ico (hab : a \u2264 b) (hf : AntitoneOn f (Set.Icc a b)) :\n    (\u222b x in a..b, f x) \u2264 \u2211 x in Finset.Ico a b, f x :=\n  by\n  rw [(Nat.sub_add_cancel hab).symm, Nat.cast_add]\n  conv =>\n    congr\n    congr\n    skip\n    skip\n    rw [add_comm]\n    skip\n    skip\n    congr\n    congr\n    rw [\u2190 zero_add a]\n  rw [\u2190 Finset.sum_Ico_add, Nat.Ico_zero_eq_range]\n  conv =>\n    rhs\n    congr\n    skip\n    ext\n    rw [Nat.cast_add]\n  apply AntitoneOn.integral_le_sum\n  simp only [hf, hab, Nat.cast_sub, add_sub_cancel'_right]\n#align antitone_on.integral_le_sum_Ico AntitoneOn.integral_le_sum_Ico\n\ntheorem AntitoneOn.sum_le_integral (hf : AntitoneOn f (Icc x\u2080 (x\u2080 + a))) :\n    (\u2211 i in Finset.range a, f (x\u2080 + (i + 1 : \u2115))) \u2264 \u222b x in x\u2080..x\u2080 + a, f x :=\n  by\n  have hint : \u2200 k : \u2115, k < a \u2192 IntervalIntegrable f volume (x\u2080 + k) (x\u2080 + (k + 1 : \u2115)) :=\n    by\n    intro k hk\n    refine' (hf.mono _).IntervalIntegrable\n    rw [uIcc_of_le]\n    \u00b7 apply Icc_subset_Icc\n      \u00b7 simp only [le_add_iff_nonneg_right, Nat.cast_nonneg]\n      \u00b7 simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk]\n    \u00b7 simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ]\n  calc\n    (\u2211 i in Finset.range a, f (x\u2080 + (i + 1 : \u2115))) =\n        \u2211 i in Finset.range a, \u222b x in x\u2080 + i..x\u2080 + (i + 1 : \u2115), f (x\u2080 + (i + 1 : \u2115)) :=\n      by simp\n    _ \u2264 \u2211 i in Finset.range a, \u222b x in x\u2080 + i..x\u2080 + (i + 1 : \u2115), f x :=\n      by\n      apply Finset.sum_le_sum fun i hi => _\n      have ia : i + 1 \u2264 a := Finset.mem_range.1 hi\n      refine' intervalIntegral.integral_mono_on (by simp) (by simp) (hint _ ia) fun x hx => _\n      apply hf _ _ hx.2\n      \u00b7 refine'\n          mem_Icc.2\n            \u27e8le_trans ((le_add_iff_nonneg_right _).2 (Nat.cast_nonneg _)) hx.1, le_trans hx.2 _\u27e9\n        simp only [Nat.cast_le, add_le_add_iff_left, ia]\n      \u00b7 refine' mem_Icc.2 \u27e8(le_add_iff_nonneg_right _).2 (Nat.cast_nonneg _), _\u27e9\n        simp only [add_le_add_iff_left, Nat.cast_le, ia]\n    _ = \u222b x in x\u2080..x\u2080 + a, f x :=\n      by\n      convert intervalIntegral.sum_integral_adjacent_intervals hint\n      simp only [Nat.cast_zero, add_zero]\n    \n#align antitone_on.sum_le_integral AntitoneOn.sum_le_integral\n\ntheorem AntitoneOn.sum_le_integral_Ico (hab : a \u2264 b) (hf : AntitoneOn f (Set.Icc a b)) :\n    (\u2211 i in Finset.Ico a b, f (i + 1 : \u2115)) \u2264 \u222b x in a..b, f x :=\n  by\n  rw [(Nat.sub_add_cancel hab).symm, Nat.cast_add]\n  conv =>\n    congr\n    congr\n    congr\n    rw [\u2190 zero_add a]\n    skip\n    skip\n    skip\n    rw [add_comm]\n  rw [\u2190 Finset.sum_Ico_add, Nat.Ico_zero_eq_range]\n  conv =>\n    lhs\n    congr\n    congr\n    skip\n    ext\n    rw [add_assoc, Nat.cast_add]\n  apply AntitoneOn.sum_le_integral\n  simp only [hf, hab, Nat.cast_sub, add_sub_cancel'_right]\n#align antitone_on.sum_le_integral_Ico AntitoneOn.sum_le_integral_Ico\n\ntheorem MonotoneOn.sum_le_integral (hf : MonotoneOn f (Icc x\u2080 (x\u2080 + a))) :\n    (\u2211 i in Finset.range a, f (x\u2080 + i)) \u2264 \u222b x in x\u2080..x\u2080 + a, f x :=\n  by\n  rw [\u2190 neg_le_neg_iff, \u2190 Finset.sum_neg_distrib, \u2190 intervalIntegral.integral_neg]\n  exact hf.neg.integral_le_sum\n#align monotone_on.sum_le_integral MonotoneOn.sum_le_integral\n\ntheorem MonotoneOn.sum_le_integral_Ico (hab : a \u2264 b) (hf : MonotoneOn f (Set.Icc a b)) :\n    (\u2211 x in Finset.Ico a b, f x) \u2264 \u222b x in a..b, f x :=\n  by\n  rw [\u2190 neg_le_neg_iff, \u2190 Finset.sum_neg_distrib, \u2190 intervalIntegral.integral_neg]\n  exact hf.neg.integral_le_sum_Ico hab\n#align monotone_on.sum_le_integral_Ico MonotoneOn.sum_le_integral_Ico\n\ntheorem MonotoneOn.integral_le_sum (hf : MonotoneOn f (Icc x\u2080 (x\u2080 + a))) :\n    (\u222b x in x\u2080..x\u2080 + a, f x) \u2264 \u2211 i in Finset.range a, f (x\u2080 + (i + 1 : \u2115)) :=\n  by\n  rw [\u2190 neg_le_neg_iff, \u2190 Finset.sum_neg_distrib, \u2190 intervalIntegral.integral_neg]\n  exact hf.neg.sum_le_integral\n#align monotone_on.integral_le_sum MonotoneOn.integral_le_sum\n\ntheorem MonotoneOn.integral_le_sum_Ico (hab : a \u2264 b) (hf : MonotoneOn f (Set.Icc a b)) :\n    (\u222b x in a..b, f x) \u2264 \u2211 i in Finset.Ico a b, f (i + 1 : \u2115) :=\n  by\n  rw [\u2190 neg_le_neg_iff, \u2190 Finset.sum_neg_distrib, \u2190 intervalIntegral.integral_neg]\n  exact hf.neg.sum_le_integral_Ico hab\n#align monotone_on.integral_le_sum_Ico MonotoneOn.integral_le_sum_Ico\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/SumIntegralComparisons.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7238663026293582}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport data.fin.interval\n\n/-!\n# The structure of `fintype (fin n)`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains some basic results about the `fintype` instance for `fin`,\nespecially properties of `finset.univ : finset (fin n)`.\n-/\n\n\nopen finset\nopen fintype\n\nnamespace fin\n\nvariables {\u03b1 \u03b2 : Type*} {n : \u2115}\n\n-- TODO: replace `subtype` with `coe` in the name of this lemma and `fin.map_subtype_embedding_Iio` \nlemma map_subtype_embedding_univ :\n  (finset.univ : finset (fin n)).map fin.coe_embedding = Iio n :=\nbegin\n  ext,\n  simp [order_iso_subtype.symm.surjective.exists, order_iso.symm],\nend\n\n@[simp] lemma Ioi_zero_eq_map :\n  Ioi (0 : fin n.succ) = univ.map (fin.succ_embedding _).to_embedding :=\nbegin\n  ext i,\n  simp only [mem_Ioi, mem_map, mem_univ, function.embedding.coe_fn_mk, exists_true_left],\n  split,\n  { refine cases _ _ i,\n    { rintro \u27e8\u27e8\u27e9\u27e9 },\n    { intros j _, exact \u27e8j, rfl\u27e9 } },\n  { rintro \u27e8i, _, rfl\u27e9,\n    exact succ_pos _ },\nend\n\n@[simp] lemma Iio_last_eq_map :\n  Iio (fin.last n) = finset.univ.map fin.cast_succ.to_embedding :=\nbegin\n  apply finset.map_injective fin.coe_embedding,\n  rw [finset.map_map, fin.map_subtype_embedding_Iio, fin.coe_last],\n  exact map_subtype_embedding_univ.symm\nend\n\n@[simp] lemma Ioi_succ (i : fin n) :\n  Ioi i.succ = (Ioi i).map (fin.succ_embedding _).to_embedding :=\nbegin\n  ext i,\n  simp only [mem_filter, mem_Ioi, mem_map, mem_univ, true_and,\n  function.embedding.coe_fn_mk, exists_true_left],\n  split,\n  { refine cases _ _ i,\n    { rintro \u27e8\u27e8\u27e9\u27e9 },\n    { intros i hi,\n      refine \u27e8i, succ_lt_succ_iff.mp hi, rfl\u27e9 } },\n  { rintro \u27e8i, hi, rfl\u27e9, simpa },\nend\n\n@[simp] lemma Iio_cast_succ (i : fin n) :\n  Iio (cast_succ i) = (Iio i).map fin.cast_succ.to_embedding :=\nbegin\n  apply finset.map_injective fin.coe_embedding,\n  rw [finset.map_map, fin.map_subtype_embedding_Iio],\n  exact (fin.map_subtype_embedding_Iio i).symm,\nend\n\nlemma card_filter_univ_succ' (p : fin (n + 1) \u2192 Prop) [decidable_pred p] :\n  (univ.filter p).card = (ite (p 0) 1 0) + (univ.filter (p \u2218 fin.succ)).card :=\nbegin\n  rw [fin.univ_succ, filter_cons, card_disj_union, filter_map, card_map],\n  split_ifs; simp,\nend\n\nlemma card_filter_univ_succ (p : fin (n + 1) \u2192 Prop) [decidable_pred p] :\n  (univ.filter p).card =\n    if p 0 then (univ.filter (p \u2218 fin.succ)).card + 1 else (univ.filter (p \u2218 fin.succ)).card :=\n(card_filter_univ_succ' p).trans (by split_ifs; simp [add_comm 1])\n\nlemma card_filter_univ_eq_vector_nth_eq_count [decidable_eq \u03b1] (a : \u03b1) (v : vector \u03b1 n) :\n  (univ.filter $ \u03bb i, a = v.nth i).card = v.to_list.count a :=\nbegin\n  induction v using vector.induction_on with n x xs hxs,\n  { simp },\n  { simp_rw [card_filter_univ_succ', vector.nth_cons_zero, vector.to_list_cons,\n      function.comp, vector.nth_cons_succ, hxs, list.count_cons', add_comm (ite (a = x) 1 0)] }\nend\n\nend fin\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/fintype/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7238662917404787}}
{"text": "import ..prooflab\nimport lectures.lec6_proposition\nimport data.real.basic\nimport data.complex.exponential\n\n\n/-! # Homework 4: ...\nHomework must be done individually.\nReplace the placeholders (e.g., `:= sorry`) with your solutions.\n\nYou are allowed to use all the tactics we have learned so far. \n\nPro Tip: Don't forget you know the tactics `linarith` and `ring`! \n -/\n\n\n\n\n\nnamespace PROOFS\n\n\nvariables {P Q R : Prop}\n\n\n\n/-! ## Question 1 (20 points): \nGive a proof of the proposition `(P \u2227 R) \u2192 (R \u2192 P \u2192 Q) \u2192 Q`. \n-/\n\nexample : \n  (P \u2227 R) \u2192 (R \u2192 P \u2192 Q) \u2192 Q :=\nbegin\n  sorry, \nend \n\n\n\n\n\n\n/-! ## Question 2 (20 points): \nProve the implication \n`m * n - m - n + 1 = 1 \u2192 (m = 2) \u2227 (n = 2)` \nfor natural numbers `m` and `n` by filling in `sorry` placeholders below. \n\nYou need to use the lemma `mul_eq_one_of_pos_of_pos` in below which says if the multiplication of two positive integers is `1` then both of them must be `1`. Notice that we did not provide the proof of this lemma here, and __you don't need to provide it either__. We will construct a proof of this lemma in the next lecture. \n-/\n\n-- no need to solve the following, just use it in the next proof \nlemma mul_eq_one_of_pos_of_pos  (m n : \u2124) (h : m * n = 1) : \n  (0 < m \u2227 0 < n) \u2192 (m = 1 \u2227 n = 1) := \nbegin \n  sorry, \nend \n\n-- give a proof of this one using the lemma above. \nexample (m n : \u2124) : \n  m * n - m - n + 1 = 1 \u2192 (1 < m \u2227 1 < n) \u2192 (m = 2) \u2227 (n = 2) := \nbegin\n  sorry, \nend  \n\n \n\n\n\n\n/-! ## Question 3 (20 points): \nConstruct a proof of the proposition `abs (2 * x - 1) < 5 \u2192 -2 < x `. You are allowed to use the lemma `abs_lt`.  \n-/\n\nsection \nvariables a b : \u211d \n#check (abs_lt : |a| < b \u2194 -b < a \u2227 a < b)\n\nend \nexample (x y : \u211d) : abs (2 * x - 1) < 5 \u2192 -2 < x := \nbegin\n  sorry, \nend\n\n\n\n/-! ## Question 4 (20 points): \nFor `x : \u211d`, the term `real.exp x` encodes the exponential e^x. \n-/\n\nsection \nvariables a b c : \u211d\n#check (real.exp_le_exp.mpr : a \u2264 b \u2192 real.exp a \u2264 real.exp b)\nend \n\n\nexample (a b c : \u211d) (h : 1 \u2264 a \u2227 b \u2264 c) :\n  2 + a + real.exp b \u2264 3 * a + real.exp c :=\nbegin\n  sorry, \nend \n\n\n\n\n\n\n/-! ## Question 5 (20 points): \nProve the following statement. You might like to use any of the following lemmas (most likely you need only some of them not all.): \n- `abs_mul` \n- `abs_lt`.\n- `abs_nonneg`\n- `abs_pos`\n- `real_le_of_mul_nonneg_left`\n- `real_lt_of_mul_pos_right`\n- `real_le_mul_right`\n-/\n\nsection \nvariables a b : \u211d\n#check (abs_mul a b : |a * b| = |a| * |b|)\n#check (abs_lt : |a| < b \u2194 -b < a \u2227 a < b)\nend \n\n\nlemma real_le_of_mul_nonneg_left {a b c : \u211d} (h\u2080 : a < b) (h\u2081 : 0 \u2264 c): \n  c * a \u2264 c * b := \nbegin\n  apply mul_le_mul_of_nonneg_left, \n  {\n    apply le_of_lt,\n    apply h\u2080, \n  },\n  {\n     apply h\u2081, \n  },\nend   \n\n\nlemma real_lt_of_mul_pos_right {a b c : \u211d} (h\u2080 : a < b) (h\u2081 : 0 < c): \n  a * c < b * c := \nbegin\n  rw mul_comm a c,\n  rw mul_comm b c, \n  apply mul_lt_mul_of_pos_left, \n  assumption',\nend \n\n\nlemma real_le_mul_right {a b c : \u211d} (h\u2080 : a \u2264 b) (h\u2081 : 0 < c): \n  a * c \u2264 b * c := \nbegin\n  apply (mul_le_mul_right h\u2081).mpr,\n  assumption,  \nend \n\n#check abs_nonneg\n \n\n\n\n\nexample (x y \u03b5 : \u211d) : \n  (0 < \u03b5 \u2227 \u03b5 \u2264 1) \u2192 (abs x < \u03b5 \u2227 abs y < \u03b5) \u2192 abs (x * y) < \u03b5 :=\nbegin\n  sorry,  \nend   \n\n\n\n\nend PROOFS", "meta": {"author": "sinhp", "repo": "ProofLab", "sha": "f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2", "save_path": "github-repos/lean/sinhp-ProofLab", "path": "github-repos/lean/sinhp-ProofLab/ProofLab-f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2/src/homework/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7238662917404787}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport ring_theory.witt_vector.is_poly\n\n/-!\n## Multiplication by `n` in the ring of Witt vectors\n\nIn this file we show that multiplication by `n` in the ring of Witt vectors\nis a polynomial function. We then use this fact to show that the composition of Frobenius\nand Verschiebung is equal to multiplication by `p`.\n\n### Main declarations\n\n* `mul_n_is_poly`: multiplication by `n` is a polynomial function\n\n## References\n\n* [Hazewinkel, *Witt Vectors*][Haze09]\n\n* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]\n-/\n\nnamespace witt_vector\n\nvariables {p : \u2115} {R : Type*} [hp : fact p.prime] [comm_ring R]\nlocal notation `\ud835\udd4e` := witt_vector p -- type as `\\bbW`\n\nopen mv_polynomial\nnoncomputable theory\n\ninclude hp\n\nvariable (p)\n\n/-- `witt_mul_n p n` is the family of polynomials that computes\nthe coefficients of `x * n` in terms of the coefficients of the Witt vector `x`. -/\nnoncomputable\ndef witt_mul_n : \u2115 \u2192 \u2115 \u2192 mv_polynomial \u2115 \u2124\n| 0     := 0\n| (n+1) := \u03bb k, bind\u2081 (function.uncurry $ ![(witt_mul_n n), X]) (witt_add p k)\n\nvariable {p}\n\nlemma mul_n_coeff (n : \u2115) (x : \ud835\udd4e R) (k : \u2115) :\n  (x * n).coeff k = aeval x.coeff (witt_mul_n p n k) :=\nbegin\n  induction n with n ih generalizing k,\n  { simp only [nat.nat_zero_eq_zero, nat.cast_zero, mul_zero,\n      zero_coeff, witt_mul_n, alg_hom.map_zero, pi.zero_apply], },\n  { rw [witt_mul_n, nat.succ_eq_add_one, nat.cast_add, nat.cast_one, mul_add, mul_one,\n      aeval_bind\u2081, add_coeff],\n    apply eval\u2082_hom_congr (ring_hom.ext_int _ _) _ rfl,\n    ext1 \u27e8b, i\u27e9,\n    fin_cases b,\n    { simp only [function.uncurry, matrix.cons_val_zero, ih] },\n    { simp only [function.uncurry, matrix.cons_val_one, matrix.head_cons, aeval_X] } }\nend\n\nvariables (p)\n\n/-- Multiplication by `n` is a polynomial function. -/\n@[is_poly] lemma mul_n_is_poly (n : \u2115) : is_poly p (\u03bb R _Rcr x, by exactI x * n) :=\n\u27e8\u27e8witt_mul_n p n, \u03bb R _Rcr x, by { funext k, exactI mul_n_coeff n x k }\u27e9\u27e9\n\n@[simp] lemma bind\u2081_witt_mul_n_witt_polynomial (n k : \u2115) :\n  bind\u2081 (witt_mul_n p n) (witt_polynomial p \u2124 k) = n * witt_polynomial p \u2124 k :=\nbegin\n  induction n with n ih,\n  { simp only [witt_mul_n, nat.cast_zero, zero_mul, bind\u2081_zero_witt_polynomial] },\n  { rw [witt_mul_n, \u2190 bind\u2081_bind\u2081, witt_add, witt_structure_int_prop],\n    simp only [alg_hom.map_add, nat.cast_succ, bind\u2081_X_right],\n    rw [add_mul, one_mul, bind\u2081_rename, bind\u2081_rename],\n    simp only [ih, function.uncurry, function.comp, bind\u2081_X_left, alg_hom.id_apply,\n      matrix.cons_val_zero, matrix.head_cons, matrix.cons_val_one], }\nend\n\nend witt_vector\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/witt_vector/mul_p.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.7237669657331954}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.mean_inequalities\nimport analysis.mean_inequalities_pow\nimport analysis.normed.group.pointwise\nimport topology.algebra.order.liminf_limsup\n\n/-!\n# \u2113p space\n\nThis file describes properties of elements `f` of a pi-type `\u03a0 i, E i` with finite \"norm\",\ndefined for `p:\u211d\u22650\u221e` as the size of the support of `f` if `p=0`, `(\u2211' a, \u2225f a\u2225^p) ^ (1/p)` for\n`0 < p < \u221e` and `\u2a06 a, \u2225f a\u2225` for `p=\u221e`.\n\nThe Prop-valued `mem_\u2113p f p` states that a function `f : \u03a0 i, E i` has finite norm according\nto the above definition; that is, `f` has finite support if `p = 0`, `summable (\u03bb a, \u2225f a\u2225^p)` if\n`0 < p < \u221e`, and `bdd_above (norm '' (set.range f))` if `p = \u221e`.\n\nThe space `lp E p` is the subtype of elements of `\u03a0 i : \u03b1, E i` which satisfy `mem_\u2113p f p`. For\n`1 \u2264 p`, the \"norm\" is genuinely a norm and `lp` is a complete metric space.\n\n## Main definitions\n\n* `mem_\u2113p f p` : property that the function `f` satisfies, as appropriate, `f` finitely supported\n  if `p = 0`, `summable (\u03bb a, \u2225f a\u2225^p)` if `0 < p < \u221e`, and `bdd_above (norm '' (set.range f))` if\n  `p = \u221e`.\n* `lp E p` : elements of `\u03a0 i : \u03b1, E i` such that `mem_\u2113p f p`. Defined as an `add_subgroup` of\n  a type synonym `pre_lp` for `\u03a0 i : \u03b1, E i`, and equipped with a `normed_group` structure.\n  Under appropriate conditions, this is also equipped with the instances `lp.normed_space`,\n  `lp.complete_space`, and `lp.normed_ring`.\n\n## Main results\n\n* `mem_\u2113p.of_exponent_ge`: For `q \u2264 p`, a function which is `mem_\u2113p` for `q` is also `mem_\u2113p` for\n  `p`\n* `lp.mem_\u2113p_of_tendsto`, `lp.norm_le_of_tendsto`: A pointwise limit of functions in `lp`, all with\n  `lp` norm `\u2264 C`, is itself in `lp` and has `lp` norm `\u2264 C`.\n* `lp.tsum_mul_le_mul_norm`: basic form of H\u00f6lder's inequality\n\n## Implementation\n\nSince `lp` is defined as an `add_subgroup`, dot notation does not work. Use `lp.norm_neg f` to\nsay that `\u2225-f\u2225 = \u2225f\u2225`, instead of the non-working `f.norm_neg`.\n\n## TODO\n\n* More versions of H\u00f6lder's inequality (for example: the case `p = 1`, `q = \u221e`; a version for normed\n  rings which has `\u2225\u2211' i, f i * g i\u2225` rather than `\u2211' i, \u2225f i\u2225 * g i\u2225` on the RHS; a version for\n  three exponents satisfying `1 / r = 1 / p + 1 / q`)\n* Equivalence with `pi_Lp`, for `\u03b1` finite\n* Equivalence with `measure_theory.Lp`, for `f : \u03b1 \u2192 E` (i.e., functions rather than pi-types) and\n  the counting measure on `\u03b1`\n* Equivalence with `bounded_continuous_function`, for `f : \u03b1 \u2192 E` (i.e., functions rather than\n  pi-types) and `p = \u221e`, and the discrete topology on `\u03b1`\n\n-/\n\nnoncomputable theory\nopen_locale nnreal ennreal big_operators\n\nvariables {\u03b1 : Type*} {E : \u03b1 \u2192 Type*} {p q : \u211d\u22650\u221e} [\u03a0 i, normed_group (E i)]\n\n/-!\n### `mem_\u2113p` predicate\n\n-/\n\n/-- The property that `f : \u03a0 i : \u03b1, E i`\n* is finitely supported, if `p = 0`, or\n* admits an upper bound for `set.range (\u03bb i, \u2225f i\u2225)`, if `p = \u221e`, or\n* has the series `\u2211' i, \u2225f i\u2225 ^ p` be summable, if `0 < p < \u221e`. -/\ndef mem_\u2113p (f : \u03a0 i, E i) (p : \u211d\u22650\u221e) : Prop :=\nif p = 0 then (set.finite {i | f i \u2260 0}) else\n  (if p = \u221e then bdd_above (set.range (\u03bb i, \u2225f i\u2225)) else summable (\u03bb i, \u2225f i\u2225 ^ p.to_real))\n\nlemma mem_\u2113p_zero_iff {f : \u03a0 i, E i} : mem_\u2113p f 0 \u2194 set.finite {i | f i \u2260 0} :=\nby dsimp [mem_\u2113p]; rw [if_pos rfl]\n\nlemma mem_\u2113p_zero {f : \u03a0 i, E i} (hf : set.finite {i | f i \u2260 0}) : mem_\u2113p f 0 :=\nmem_\u2113p_zero_iff.2 hf\n\nlemma mem_\u2113p_infty_iff {f : \u03a0 i, E i} : mem_\u2113p f \u221e \u2194 bdd_above (set.range (\u03bb i, \u2225f i\u2225)) :=\nby dsimp [mem_\u2113p]; rw [if_neg ennreal.top_ne_zero, if_pos rfl]\n\nlemma mem_\u2113p_infty {f : \u03a0 i, E i} (hf : bdd_above (set.range (\u03bb i, \u2225f i\u2225))) : mem_\u2113p f \u221e :=\nmem_\u2113p_infty_iff.2 hf\n\nlemma mem_\u2113p_gen_iff (hp : 0 < p.to_real) {f : \u03a0 i, E i} :\n  mem_\u2113p f p \u2194 summable (\u03bb i, \u2225f i\u2225 ^ p.to_real) :=\nbegin\n  rw ennreal.to_real_pos_iff at hp,\n  dsimp [mem_\u2113p],\n  rw [if_neg hp.1.ne', if_neg hp.2.ne],\nend\n\nlemma mem_\u2113p_gen {f : \u03a0 i, E i} (hf : summable (\u03bb i, \u2225f i\u2225 ^ p.to_real)) :\n  mem_\u2113p f p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    have H : summable (\u03bb i : \u03b1, (1:\u211d)) := by simpa using hf,\n    exact (finite_of_summable_const (by norm_num) H).subset (set.subset_univ _) },\n  { apply mem_\u2113p_infty,\n    have H : summable (\u03bb i : \u03b1, (1:\u211d)) := by simpa using hf,\n    simpa using ((finite_of_summable_const (by norm_num) H).image (\u03bb i, \u2225f i\u2225)).bdd_above },\n  exact (mem_\u2113p_gen_iff hp).2 hf\nend\n\nlemma mem_\u2113p_gen' {C : \u211d} {f : \u03a0 i, E i} (hf : \u2200 s : finset \u03b1, \u2211 i in s, \u2225f i\u2225 ^ p.to_real \u2264 C) :\n  mem_\u2113p f p :=\nbegin\n  apply mem_\u2113p_gen,\n  use \u2a06 s : finset \u03b1, \u2211 i in s, \u2225f i\u2225 ^ p.to_real,\n  apply has_sum_of_is_lub_of_nonneg,\n  { intros b,\n    exact real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  apply is_lub_csupr,\n  use C,\n  rintros - \u27e8s, rfl\u27e9,\n  exact hf s\nend\n\nlemma zero_mem_\u2113p : mem_\u2113p (0 : \u03a0 i, E i) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    simp },\n  { apply mem_\u2113p_infty,\n    simp only [norm_zero, pi.zero_apply],\n    exact bdd_above_singleton.mono set.range_const_subset, },\n  { apply mem_\u2113p_gen,\n    simp [real.zero_rpow hp.ne', summable_zero], }\nend\n\nlemma zero_mem_\u2113p' : mem_\u2113p (\u03bb i : \u03b1, (0 : E i)) p := zero_mem_\u2113p\n\nnamespace mem_\u2113p\n\nlemma finite_dsupport {f : \u03a0 i, E i} (hf : mem_\u2113p f 0) : set.finite {i | f i \u2260 0} :=\nmem_\u2113p_zero_iff.1 hf\n\nlemma bdd_above {f : \u03a0 i, E i} (hf : mem_\u2113p f \u221e) : bdd_above (set.range (\u03bb i, \u2225f i\u2225)) :=\nmem_\u2113p_infty_iff.1 hf\n\nlemma summable (hp : 0 < p.to_real) {f : \u03a0 i, E i} (hf : mem_\u2113p f p) :\n  summable (\u03bb i, \u2225f i\u2225 ^ p.to_real) :=\n(mem_\u2113p_gen_iff hp).1 hf\n\nlemma neg {f : \u03a0 i, E i} (hf : mem_\u2113p f p) : mem_\u2113p (-f) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    simp [hf.finite_dsupport] },\n  { apply mem_\u2113p_infty,\n    simpa using hf.bdd_above },\n  { apply mem_\u2113p_gen,\n    simpa using hf.summable hp },\nend\n\n@[simp] lemma neg_iff {f : \u03a0 i, E i} : mem_\u2113p (-f) p \u2194 mem_\u2113p f p :=\n\u27e8\u03bb h, neg_neg f \u25b8 h.neg, mem_\u2113p.neg\u27e9\n\nlemma of_exponent_ge {p q : \u211d\u22650\u221e} {f : \u03a0 i, E i}\n  (hfq : mem_\u2113p f q) (hpq : q \u2264 p) :\n  mem_\u2113p f p :=\nbegin\n  rcases ennreal.trichotomy\u2082 hpq with \u27e8rfl, rfl\u27e9 | \u27e8rfl, rfl\u27e9 | \u27e8rfl, hp\u27e9 | \u27e8rfl, rfl\u27e9 | \u27e8hq, rfl\u27e9\n    | \u27e8hq, hp, hpq'\u27e9,\n  { exact hfq },\n  { apply mem_\u2113p_infty,\n    obtain \u27e8C, hC\u27e9 := (hfq.finite_dsupport.image (\u03bb i, \u2225f i\u2225)).bdd_above,\n    use max 0 C,\n    rintros x \u27e8i, rfl\u27e9,\n    by_cases hi : f i = 0,\n    { simp [hi] },\n    { exact (hC \u27e8i, hi, rfl\u27e9).trans (le_max_right _ _) } },\n  { apply mem_\u2113p_gen,\n    have : \u2200 i \u2209 hfq.finite_dsupport.to_finset, \u2225f i\u2225 ^ p.to_real = 0,\n    { intros i hi,\n      have : f i = 0 := by simpa using hi,\n      simp [this, real.zero_rpow hp.ne'] },\n    exact summable_of_ne_finset_zero this },\n  { exact hfq },\n  { apply mem_\u2113p_infty,\n    obtain \u27e8A, hA\u27e9 := (hfq.summable hq).tendsto_cofinite_zero.bdd_above_range_of_cofinite,\n    use A ^ (q.to_real\u207b\u00b9),\n    rintros x \u27e8i, rfl\u27e9,\n    have : 0 \u2264 \u2225f i\u2225 ^ q.to_real := real.rpow_nonneg_of_nonneg (norm_nonneg _) _,\n    simpa [\u2190 real.rpow_mul, mul_inv_cancel hq.ne'] using\n      real.rpow_le_rpow this (hA \u27e8i, rfl\u27e9) (inv_nonneg.mpr hq.le) },\n  { apply mem_\u2113p_gen,\n    have hf' := hfq.summable hq,\n    refine summable_of_norm_bounded_eventually _ hf' (@set.finite.subset _ {i | 1 \u2264 \u2225f i\u2225} _ _ _),\n    { have H : {x : \u03b1 | 1 \u2264 \u2225f x\u2225 ^ q.to_real}.finite,\n      { simpa using eventually_lt_of_tendsto_lt (by norm_num : (0:\u211d) < 1)\n          hf'.tendsto_cofinite_zero },\n      exact H.subset (\u03bb i hi, real.one_le_rpow hi hq.le) },\n    { show \u2200 i, \u00ac (|\u2225f i\u2225 ^ p.to_real| \u2264 \u2225f i\u2225 ^ q.to_real) \u2192 1 \u2264 \u2225f i\u2225,\n      intros i hi,\n      have : 0 \u2264 \u2225f i\u2225 ^ p.to_real := real.rpow_nonneg_of_nonneg (norm_nonneg _) p.to_real,\n      simp only [abs_of_nonneg, this] at hi,\n      contrapose! hi,\n      exact real.rpow_le_rpow_of_exponent_ge' (norm_nonneg _) hi.le hq.le hpq' } }\nend\n\nlemma add {f g : \u03a0 i, E i} (hf : mem_\u2113p f p) (hg : mem_\u2113p g p) : mem_\u2113p (f + g) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    refine (hf.finite_dsupport.union hg.finite_dsupport).subset (\u03bb i, _),\n    simp only [pi.add_apply, ne.def, set.mem_union_eq, set.mem_set_of_eq],\n    contrapose!,\n    rintros \u27e8hf', hg'\u27e9,\n    simp [hf', hg'] },\n  { apply mem_\u2113p_infty,\n    obtain \u27e8A, hA\u27e9 := hf.bdd_above,\n    obtain \u27e8B, hB\u27e9 := hg.bdd_above,\n    refine \u27e8A + B, _\u27e9,\n    rintros a \u27e8i, rfl\u27e9,\n    exact le_trans (norm_add_le _ _) (add_le_add (hA \u27e8i, rfl\u27e9) (hB \u27e8i, rfl\u27e9)) },\n  apply mem_\u2113p_gen,\n  let C : \u211d := if p.to_real < 1 then 1 else 2 ^ (p.to_real - 1),\n  refine summable_of_nonneg_of_le _ (\u03bb i, _) (((hf.summable hp).add (hg.summable hp)).mul_left C),\n  { exact \u03bb b, real.rpow_nonneg_of_nonneg (norm_nonneg (f b + g b)) p.to_real },\n  { refine (real.rpow_le_rpow (norm_nonneg _) (norm_add_le _ _) hp.le).trans _,\n    dsimp [C],\n    split_ifs with h h,\n    { simpa using nnreal.coe_le_coe.2 (nnreal.rpow_add_le_add_rpow (\u2225f i\u2225\u208a) (\u2225g i\u2225\u208a) hp h.le) },\n    { let F : fin 2 \u2192 \u211d\u22650 := ![\u2225f i\u2225\u208a, \u2225g i\u2225\u208a],\n      have : \u2200 i, (0:\u211d) \u2264 F i := \u03bb i, (F i).coe_nonneg,\n      simp only [not_lt] at h,\n      simpa [F, fin.sum_univ_succ] using\n        real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (finset.univ : finset (fin 2)) h\n        (\u03bb i _, (F i).coe_nonneg) } }\nend\n\nlemma sub {f g : \u03a0 i, E i} (hf : mem_\u2113p f p) (hg : mem_\u2113p g p) : mem_\u2113p (f - g) p :=\nby { rw sub_eq_add_neg, exact hf.add hg.neg }\n\nlemma finset_sum {\u03b9} (s : finset \u03b9) {f : \u03b9 \u2192 \u03a0 i, E i} (hf : \u2200 i \u2208 s, mem_\u2113p (f i) p) :\n  mem_\u2113p (\u03bb a, \u2211 i in s, f i a) p :=\nbegin\n  haveI : decidable_eq \u03b9 := classical.dec_eq _,\n  revert hf,\n  refine finset.induction_on s _ _,\n  { simp only [zero_mem_\u2113p', finset.sum_empty, implies_true_iff], },\n  { intros i s his ih hf,\n    simp only [his, finset.sum_insert, not_false_iff],\n    exact (hf i (s.mem_insert_self i)).add (ih (\u03bb j hj, hf j (finset.mem_insert_of_mem hj))), },\nend\n\nsection normed_space\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [\u03a0 i, normed_space \ud835\udd5c (E i)]\n\nlemma const_smul {f : \u03a0 i, E i} (hf : mem_\u2113p f p) (c : \ud835\udd5c) : mem_\u2113p (c \u2022 f) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_\u2113p_zero,\n    refine hf.finite_dsupport.subset (\u03bb i, (_ : \u00acc \u2022 f i = 0 \u2192 \u00acf i = 0)),\n    exact not_imp_not.mpr (\u03bb hf', hf'.symm \u25b8 (smul_zero c)) },\n  { obtain \u27e8A, hA\u27e9 := hf.bdd_above,\n    refine mem_\u2113p_infty \u27e8\u2225c\u2225 * A, _\u27e9,\n    rintros a \u27e8i, rfl\u27e9,\n    simpa [norm_smul] using mul_le_mul_of_nonneg_left (hA \u27e8i, rfl\u27e9) (norm_nonneg c) },\n  { apply mem_\u2113p_gen,\n    convert (hf.summable hp).mul_left (\u2225c\u2225 ^ p.to_real),\n    ext i,\n    simp [norm_smul, real.mul_rpow (norm_nonneg c) (norm_nonneg (f i))] },\nend\n\nlemma const_mul {f : \u03b1 \u2192 \ud835\udd5c} (hf : mem_\u2113p f p) (c : \ud835\udd5c) : mem_\u2113p (\u03bb x, c * f x) p :=\n@mem_\u2113p.const_smul \u03b1 (\u03bb i, \ud835\udd5c) _ _ \ud835\udd5c _ _ _ hf c\n\nend normed_space\n\nend mem_\u2113p\n\n/-!\n### lp space\n\nThe space of elements of `\u03a0 i, E i` satisfying the predicate `mem_\u2113p`.\n-/\n\n/-- We define `pre_lp E` to be a type synonym for `\u03a0 i, E i` which, importantly, does not inherit\nthe `pi` topology on `\u03a0 i, E i` (otherwise this topology would descend to `lp E p` and conflict\nwith the normed group topology we will later equip it with.)\n\nWe choose to deal with this issue by making a type synonym for `\u03a0 i, E i` rather than for the `lp`\nsubgroup itself, because this allows all the spaces `lp E p` (for varying `p`) to be subgroups of\nthe same ambient group, which permits lemma statements like `lp.monotone` (below). -/\n@[derive add_comm_group, nolint unused_arguments]\ndef pre_lp (E : \u03b1 \u2192 Type*) [\u03a0 i, normed_group (E i)] : Type* := \u03a0 i, E i\n\ninstance pre_lp.unique [is_empty \u03b1] : unique (pre_lp E) := pi.unique_of_is_empty E\n\n/-- lp space -/\ndef lp (E : \u03b1 \u2192 Type*) [\u03a0 i, normed_group (E i)]\n  (p : \u211d\u22650\u221e) : add_subgroup (pre_lp E) :=\n{ carrier := {f | mem_\u2113p f p},\n  zero_mem' := zero_mem_\u2113p,\n  add_mem' := \u03bb f g, mem_\u2113p.add,\n  neg_mem' := \u03bb f, mem_\u2113p.neg }\n\nnamespace lp\n\ninstance : has_coe (lp E p) (\u03a0 i, E i) := coe_subtype\ninstance : has_coe_to_fun (lp E p) (\u03bb _, \u03a0 i, E i) := \u27e8\u03bb f, ((f : \u03a0 i, E i) : \u03a0 i, E i)\u27e9\n\n@[ext] lemma ext {f g : lp E p} (h : (f : \u03a0 i, E i) = g) : f = g :=\nsubtype.ext h\n\nprotected lemma ext_iff {f g : lp E p} : f = g \u2194 (f : \u03a0 i, E i) = g :=\nsubtype.ext_iff\n\nlemma eq_zero' [is_empty \u03b1] (f : lp E p) : f = 0 := subsingleton.elim f 0\n\nprotected lemma monotone {p q : \u211d\u22650\u221e} (hpq : q \u2264 p) : lp E q \u2264 lp E p :=\n\u03bb f hf, mem_\u2113p.of_exponent_ge hf hpq\n\nprotected lemma mem_\u2113p (f : lp E p) : mem_\u2113p f p := f.prop\n\nvariables (E p)\n@[simp] lemma coe_fn_zero : \u21d1(0 : lp E p) = 0 := rfl\nvariables {E p}\n\n@[simp] lemma coe_fn_neg (f : lp E p) : \u21d1(-f) = -f := rfl\n\n@[simp] lemma coe_fn_add (f g : lp E p) : \u21d1(f + g) = f + g := rfl\n\n@[simp] lemma coe_fn_sum {\u03b9 : Type*} (f : \u03b9 \u2192 lp E p) (s : finset \u03b9) :\n  \u21d1(\u2211 i in s, f i) = \u2211 i in s, \u21d1(f i) :=\nbegin\n  classical,\n  refine finset.induction _ _ s,\n  { simp },\n  intros i s his,\n  simp [finset.sum_insert his],\nend\n\n@[simp] lemma coe_fn_sub (f g : lp E p) : \u21d1(f - g) = f - g := rfl\n\ninstance : has_norm (lp E p) :=\n{ norm := \u03bb f, if hp : p = 0 then by subst hp; exact (lp.mem_\u2113p f).finite_dsupport.to_finset.card\n   else (if p = \u221e then \u2a06 i, \u2225f i\u2225 else (\u2211' i, \u2225f i\u2225 ^ p.to_real) ^ (1/p.to_real)) }\n\nlemma norm_eq_card_dsupport (f : lp E 0) : \u2225f\u2225 = (lp.mem_\u2113p f).finite_dsupport.to_finset.card :=\ndif_pos rfl\n\nlemma norm_eq_csupr (f : lp E \u221e) : \u2225f\u2225 = \u2a06 i, \u2225f i\u2225 :=\nbegin\n  dsimp [norm],\n  rw [dif_neg ennreal.top_ne_zero, if_pos rfl]\nend\n\nlemma is_lub_norm [nonempty \u03b1] (f : lp E \u221e) : is_lub (set.range (\u03bb i, \u2225f i\u2225)) \u2225f\u2225 :=\nbegin\n  rw lp.norm_eq_csupr,\n  exact is_lub_csupr (lp.mem_\u2113p f)\nend\n\nlemma norm_eq_tsum_rpow (hp : 0 < p.to_real) (f : lp E p) :\n  \u2225f\u2225 = (\u2211' i, \u2225f i\u2225 ^ p.to_real) ^ (1/p.to_real) :=\nbegin\n  dsimp [norm],\n  rw ennreal.to_real_pos_iff at hp,\n  rw [dif_neg hp.1.ne', if_neg hp.2.ne],\nend\n\nlemma norm_rpow_eq_tsum (hp : 0 < p.to_real) (f : lp E p) :\n  \u2225f\u2225 ^ p.to_real = \u2211' i, \u2225f i\u2225 ^ p.to_real :=\nbegin\n  rw [norm_eq_tsum_rpow hp, \u2190 real.rpow_mul],\n  { field_simp [hp.ne'] },\n  apply tsum_nonneg,\n  intros i,\n  calc (0:\u211d) = 0 ^ p.to_real : by rw real.zero_rpow hp.ne'\n  ... \u2264 _ : real.rpow_le_rpow rfl.le (norm_nonneg (f i)) hp.le\nend\n\nlemma has_sum_norm (hp : 0 < p.to_real) (f : lp E p) :\n  has_sum (\u03bb i, \u2225f i\u2225 ^ p.to_real) (\u2225f\u2225 ^ p.to_real) :=\nbegin\n  rw norm_rpow_eq_tsum hp,\n  exact ((lp.mem_\u2113p f).summable hp).has_sum\nend\n\nlemma norm_nonneg' (f : lp E p) : 0 \u2264 \u2225f\u2225 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport f] },\n  { cases is_empty_or_nonempty \u03b1 with _i _i; resetI,\n    { rw lp.norm_eq_csupr,\n      simp [real.csupr_empty] },\n    inhabit \u03b1,\n    exact (norm_nonneg (f default)).trans ((lp.is_lub_norm f).1 \u27e8default, rfl\u27e9) },\n  { rw lp.norm_eq_tsum_rpow hp f,\n    refine real.rpow_nonneg_of_nonneg (tsum_nonneg _) _,\n    exact \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\nend\n\n@[simp] lemma norm_zero : \u2225(0 : lp E p)\u2225 = 0 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport] },\n  { simp [lp.norm_eq_csupr] },\n  { rw lp.norm_eq_tsum_rpow hp,\n    have hp' : 1 / p.to_real \u2260 0 := one_div_ne_zero hp.ne',\n    simpa [real.zero_rpow hp.ne'] using real.zero_rpow hp' }\nend\n\nlemma norm_eq_zero_iff \u2983f : lp E p\u2984 : \u2225f\u2225 = 0 \u2194 f = 0 :=\nbegin\n  classical,\n  refine \u27e8\u03bb h, _, by { rintros rfl, exact norm_zero }\u27e9,\n  rcases p.trichotomy with rfl | rfl | hp,\n  { ext i,\n    have : {i : \u03b1 | \u00acf i = 0} = \u2205 := by simpa [lp.norm_eq_card_dsupport f] using h,\n    have : (\u00ac (f i = 0)) = false := congr_fun this i,\n    tauto },\n  { cases is_empty_or_nonempty \u03b1 with _i _i; resetI,\n    { simp },\n    have H : is_lub (set.range (\u03bb i, \u2225f i\u2225)) 0,\n    { simpa [h] using lp.is_lub_norm f },\n    ext i,\n    have : \u2225f i\u2225 = 0 := le_antisymm (H.1 \u27e8i, rfl\u27e9) (norm_nonneg _),\n    simpa using this },\n  { have hf : has_sum (\u03bb (i : \u03b1), \u2225f i\u2225 ^ p.to_real) 0,\n    { have := lp.has_sum_norm hp f,\n      rwa [h, real.zero_rpow hp.ne'] at this },\n    have : \u2200 i, 0 \u2264 \u2225f i\u2225 ^ p.to_real := \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _,\n    rw has_sum_zero_iff_of_nonneg this at hf,\n    ext i,\n    have : f i = 0 \u2227 p.to_real \u2260 0,\n    { simpa [real.rpow_eq_zero_iff_of_nonneg (norm_nonneg (f i))] using congr_fun hf i },\n    exact this.1 },\nend\n\nlemma eq_zero_iff_coe_fn_eq_zero {f : lp E p} : f = 0 \u2194 \u21d1f = 0 :=\nby rw [lp.ext_iff, coe_fn_zero]\n\n@[simp] lemma norm_neg \u2983f : lp E p\u2984 : \u2225-f\u2225 = \u2225f\u2225 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport] },\n  { cases is_empty_or_nonempty \u03b1; resetI,\n    { simp [lp.eq_zero' f], },\n    apply (lp.is_lub_norm (-f)).unique,\n    simpa using lp.is_lub_norm f },\n  { suffices : \u2225-f\u2225 ^ p.to_real = \u2225f\u2225 ^ p.to_real,\n    { exact real.rpow_left_inj_on hp.ne' (norm_nonneg' _) (norm_nonneg' _) this },\n    apply (lp.has_sum_norm hp (-f)).unique,\n    simpa using lp.has_sum_norm hp f }\nend\n\ninstance [hp : fact (1 \u2264 p)] : normed_group (lp E p) :=\nnormed_group.of_core _\n{ norm_eq_zero_iff := norm_eq_zero_iff,\n  triangle := \u03bb f g, begin\n    unfreezingI { rcases p.dichotomy with rfl | hp' },\n    { cases is_empty_or_nonempty \u03b1; resetI,\n      { simp [lp.eq_zero' f] },\n      refine (lp.is_lub_norm (f + g)).2 _,\n      rintros x \u27e8i, rfl\u27e9,\n      refine le_trans _ (add_mem_upper_bounds_add (lp.is_lub_norm f).1 (lp.is_lub_norm g).1\n        \u27e8_, _, \u27e8i, rfl\u27e9, \u27e8i, rfl\u27e9, rfl\u27e9),\n      exact norm_add_le (f i) (g i) },\n    { have hp'' : 0 < p.to_real := zero_lt_one.trans_le hp',\n      have hf\u2081 : \u2200 i, 0 \u2264 \u2225f i\u2225 := \u03bb i, norm_nonneg _,\n      have hg\u2081 : \u2200 i, 0 \u2264 \u2225g i\u2225 := \u03bb i, norm_nonneg _,\n      have hf\u2082 := lp.has_sum_norm hp'' f,\n      have hg\u2082 := lp.has_sum_norm hp'' g,\n      -- apply Minkowski's inequality\n      obtain \u27e8C, hC\u2081, hC\u2082, hCfg\u27e9 :=\n        real.Lp_add_le_has_sum_of_nonneg hp' hf\u2081 hg\u2081 (norm_nonneg' _) (norm_nonneg' _) hf\u2082 hg\u2082,\n      refine le_trans _ hC\u2082,\n      rw \u2190 real.rpow_le_rpow_iff (norm_nonneg' (f + g)) hC\u2081 hp'',\n      refine has_sum_le _ (lp.has_sum_norm hp'' (f + g)) hCfg,\n      intros i,\n      exact real.rpow_le_rpow (norm_nonneg _) (norm_add_le _ _) hp''.le },\n  end,\n  norm_neg := norm_neg }\n\n-- TODO: define an `ennreal` version of `is_conjugate_exponent`, and then express this inequality\n-- in a better version which also covers the case `p = 1, q = \u221e`.\n/-- H\u00f6lder inequality -/\nprotected lemma tsum_mul_le_mul_norm {p q : \u211d\u22650\u221e}\n  (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p) (g : lp E q) :\n  summable (\u03bb i, \u2225f i\u2225 * \u2225g i\u2225) \u2227 \u2211' i, \u2225f i\u2225 * \u2225g i\u2225 \u2264 \u2225f\u2225 * \u2225g\u2225 :=\nbegin\n  have hf\u2081 : \u2200 i, 0 \u2264 \u2225f i\u2225 := \u03bb i, norm_nonneg _,\n  have hg\u2081 : \u2200 i, 0 \u2264 \u2225g i\u2225 := \u03bb i, norm_nonneg _,\n  have hf\u2082 := lp.has_sum_norm hpq.pos f,\n  have hg\u2082 := lp.has_sum_norm hpq.symm.pos g,\n  obtain \u27e8C, -, hC', hC\u27e9 :=\n    real.inner_le_Lp_mul_Lq_has_sum_of_nonneg hpq (norm_nonneg' _) (norm_nonneg' _) hf\u2081 hg\u2081 hf\u2082 hg\u2082,\n  rw \u2190 hC.tsum_eq at hC',\n  exact \u27e8hC.summable, hC'\u27e9\nend\n\nprotected lemma summable_mul {p q : \u211d\u22650\u221e}\n  (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p) (g : lp E q) :\n  summable (\u03bb i, \u2225f i\u2225 * \u2225g i\u2225) :=\n(lp.tsum_mul_le_mul_norm hpq f g).1\n\nprotected lemma tsum_mul_le_mul_norm' {p q : \u211d\u22650\u221e}\n  (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p) (g : lp E q) :\n  \u2211' i, \u2225f i\u2225 * \u2225g i\u2225 \u2264 \u2225f\u2225 * \u2225g\u2225 :=\n(lp.tsum_mul_le_mul_norm hpq f g).2\n\nsection compare_pointwise\n\nlemma norm_apply_le_norm (hp : p \u2260 0) (f : lp E p) (i : \u03b1) : \u2225f i\u2225 \u2264 \u2225f\u2225 :=\nbegin\n  rcases eq_or_ne p \u221e with rfl | hp',\n  { haveI : nonempty \u03b1 := \u27e8i\u27e9,\n    exact (is_lub_norm f).1 \u27e8i, rfl\u27e9 },\n  have hp'' : 0 < p.to_real := ennreal.to_real_pos hp hp',\n  have : \u2200 i, 0 \u2264 \u2225f i\u2225 ^ p.to_real,\n  { exact \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  rw \u2190 real.rpow_le_rpow_iff (norm_nonneg _) (norm_nonneg' _) hp'',\n  convert le_has_sum (has_sum_norm hp'' f) i (\u03bb i hi, this i),\nend\n\nlemma sum_rpow_le_norm_rpow (hp : 0 < p.to_real) (f : lp E p) (s : finset \u03b1) :\n  \u2211 i in s, \u2225f i\u2225 ^ p.to_real \u2264 \u2225f\u2225 ^ p.to_real :=\nbegin\n  rw lp.norm_rpow_eq_tsum hp f,\n  have : \u2200 i, 0 \u2264 \u2225f i\u2225 ^ p.to_real,\n  { exact \u03bb i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  refine sum_le_tsum _ (\u03bb i hi, this i) _,\n  exact (lp.mem_\u2113p f).summable hp\nend\n\nlemma norm_le_of_forall_le' [nonempty \u03b1] {f : lp E \u221e} (C : \u211d) (hCf : \u2200 i, \u2225f i\u2225 \u2264 C) : \u2225f\u2225 \u2264 C :=\nbegin\n  refine (is_lub_norm f).2 _,\n  rintros - \u27e8i, rfl\u27e9,\n  exact hCf i,\nend\n\nlemma norm_le_of_forall_le {f : lp E \u221e} {C : \u211d} (hC : 0 \u2264 C) (hCf : \u2200 i, \u2225f i\u2225 \u2264 C) : \u2225f\u2225 \u2264 C :=\nbegin\n  casesI is_empty_or_nonempty \u03b1,\n  { simpa [eq_zero' f] using hC, },\n  { exact norm_le_of_forall_le' C hCf },\nend\n\nlemma norm_le_of_tsum_le (hp : 0 < p.to_real) {C : \u211d} (hC : 0 \u2264 C) {f : lp E p}\n  (hf : \u2211' i, \u2225f i\u2225 ^ p.to_real \u2264 C ^ p.to_real) :\n  \u2225f\u2225 \u2264 C :=\nbegin\n  rw [\u2190 real.rpow_le_rpow_iff (norm_nonneg' _) hC hp, norm_rpow_eq_tsum hp],\n  exact hf,\nend\n\nlemma norm_le_of_forall_sum_le (hp : 0 < p.to_real) {C : \u211d} (hC : 0 \u2264 C) {f : lp E p}\n  (hf : \u2200 s : finset \u03b1, \u2211 i in s, \u2225f i\u2225 ^ p.to_real \u2264 C ^ p.to_real) :\n  \u2225f\u2225 \u2264 C :=\nnorm_le_of_tsum_le hp hC (tsum_le_of_sum_le ((lp.mem_\u2113p f).summable hp) hf)\n\nend compare_pointwise\n\nsection normed_space\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [\u03a0 i, normed_space \ud835\udd5c (E i)]\n\ninstance : module \ud835\udd5c (pre_lp E) := pi.module \u03b1 E \ud835\udd5c\n\nlemma mem_lp_const_smul (c : \ud835\udd5c) (f : lp E p) : c \u2022 (f : pre_lp E) \u2208 lp E p :=\n(lp.mem_\u2113p f).const_smul c\n\nvariables (E p \ud835\udd5c)\n\n/-- The `\ud835\udd5c`-submodule of elements of `\u03a0 i : \u03b1, E i` whose `lp` norm is finite.  This is `lp E p`,\nwith extra structure. -/\ndef lp_submodule : submodule \ud835\udd5c (pre_lp E) :=\n{ smul_mem' := \u03bb c f hf, by simpa using mem_lp_const_smul c \u27e8f, hf\u27e9,\n  .. lp E p }\n\nvariables {E p \ud835\udd5c}\n\nlemma coe_lp_submodule : (lp_submodule E p \ud835\udd5c).to_add_subgroup = lp E p := rfl\n\ninstance : module \ud835\udd5c (lp E p) :=\n{ .. (lp_submodule E p \ud835\udd5c).module }\n\n@[simp] lemma coe_fn_smul (c : \ud835\udd5c) (f : lp E p) : \u21d1(c \u2022 f) = c \u2022 f := rfl\n\nlemma norm_const_smul (hp : p \u2260 0) {c : \ud835\udd5c} (f : lp E p) : \u2225c \u2022 f\u2225 = \u2225c\u2225 * \u2225f\u2225 :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { exact absurd rfl hp },\n  { cases is_empty_or_nonempty \u03b1; resetI,\n    { simp [lp.eq_zero' f], },\n    apply (lp.is_lub_norm (c \u2022 f)).unique,\n    convert (lp.is_lub_norm f).mul_left (norm_nonneg c),\n    ext a,\n    simp [coe_fn_smul, norm_smul] },\n  { suffices : \u2225c \u2022 f\u2225 ^ p.to_real = (\u2225c\u2225 * \u2225f\u2225) ^ p.to_real,\n    { refine real.rpow_left_inj_on hp.ne' _ _ this,\n      { exact norm_nonneg' _ },\n      { exact mul_nonneg (norm_nonneg _) (norm_nonneg' _) } },\n    apply (lp.has_sum_norm hp (c \u2022 f)).unique,\n    convert (lp.has_sum_norm hp f).mul_left (\u2225c\u2225 ^ p.to_real),\n    { simp [coe_fn_smul, norm_smul, real.mul_rpow (norm_nonneg c) (norm_nonneg _)] },\n    have hf : 0 \u2264 \u2225f\u2225 := lp.norm_nonneg' f,\n    simp [coe_fn_smul, norm_smul, real.mul_rpow (norm_nonneg c) hf] }\nend\n\ninstance [fact (1 \u2264 p)] : normed_space \ud835\udd5c (lp E p) :=\n{ norm_smul_le := \u03bb c f, begin\n    have hp : 0 < p := ennreal.zero_lt_one.trans_le (fact.out _),\n    simp [norm_const_smul hp.ne']\n  end }\n\nvariables {\ud835\udd5c' : Type*} [normed_field \ud835\udd5c']\n\ninstance [\u03a0 i, normed_space \ud835\udd5c' (E i)] [has_smul \ud835\udd5c' \ud835\udd5c] [\u03a0 i, is_scalar_tower \ud835\udd5c' \ud835\udd5c (E i)] :\n  is_scalar_tower \ud835\udd5c' \ud835\udd5c (lp E p) :=\nbegin\n  refine \u27e8\u03bb r c f, _\u27e9,\n  ext1,\n  exact (lp.coe_fn_smul _ _).trans (smul_assoc _ _ _)\nend\n\nend normed_space\n\nsection non_unital_normed_ring\n\nvariables {I : Type*} {B : I \u2192 Type*} [\u03a0 i, non_unital_normed_ring (B i)]\n\nlemma _root_.mem_\u2113p.infty_mul {f g : \u03a0 i, B i} (hf : mem_\u2113p f \u221e) (hg : mem_\u2113p g \u221e) :\n  mem_\u2113p (f * g) \u221e :=\nbegin\n  rw mem_\u2113p_infty_iff,\n  obtain \u27e8\u27e8Cf, hCf\u27e9, \u27e8Cg, hCg\u27e9\u27e9 := \u27e8hf.bdd_above, hg.bdd_above\u27e9,\n  refine \u27e8Cf * Cg, _\u27e9,\n  rintros _ \u27e8i, rfl\u27e9,\n  calc \u2225(f * g) i\u2225 \u2264 \u2225f i\u2225 * \u2225g i\u2225 : norm_mul_le (f i) (g i)\n  ...             \u2264 Cf * Cg       : mul_le_mul (hCf \u27e8i, rfl\u27e9) (hCg \u27e8i, rfl\u27e9) (norm_nonneg _)\n                                      ((norm_nonneg _).trans (hCf \u27e8i, rfl\u27e9))\nend\n\ninstance : has_mul (lp B \u221e) :=\n{ mul := \u03bb f g, \u27e8(f  * g : \u03a0 i, B i) , f.property.infty_mul g.property\u27e9}\n\n@[simp] lemma infty_coe_fn_mul (f g : lp B \u221e) : \u21d1(f * g) = f * g := rfl\n\ninstance : non_unital_ring (lp B \u221e) :=\nfunction.injective.non_unital_ring lp.has_coe_to_fun.coe (subtype.coe_injective)\n  (lp.coe_fn_zero B \u221e) lp.coe_fn_add infty_coe_fn_mul lp.coe_fn_neg lp.coe_fn_sub\n  (\u03bb _ _, rfl) (\u03bb _ _,rfl)\n\ninstance : non_unital_normed_ring (lp B \u221e) :=\n{ norm_mul := \u03bb f g, lp.norm_le_of_forall_le (mul_nonneg (norm_nonneg f) (norm_nonneg g))\n    (\u03bb i, calc \u2225(f * g) i\u2225 \u2264 \u2225f i\u2225 * \u2225g i\u2225 : norm_mul_le _ _\n    ...                    \u2264 \u2225f\u2225 * \u2225g\u2225\n    : mul_le_mul (lp.norm_apply_le_norm ennreal.top_ne_zero f i)\n        (lp.norm_apply_le_norm ennreal.top_ne_zero g i) (norm_nonneg _) (norm_nonneg _)),\n  .. lp.normed_group }\n\n-- we also want a `non_unital_normed_comm_ring` instance, but this has to wait for #13719\n\nend non_unital_normed_ring\n\nsection normed_ring\n\nvariables {I : Type*} {B : I \u2192 Type*} [\u03a0 i, normed_ring (B i)] [\u03a0 i, norm_one_class (B i)]\n\nlemma _root_.one_mem_\u2113p_infty : mem_\u2113p (1 : \u03a0 i, B i) \u221e :=\n\u27e81, by { rintros i \u27e8i, rfl\u27e9, exact norm_one.le,}\u27e9\n\ninstance : has_one (lp B \u221e) :=\n{ one := \u27e8(1 : \u03a0 i, B i), one_mem_\u2113p_infty\u27e9 }\n\n@[simp] lemma infty_coe_fn_one : \u21d1(1 : lp B \u221e) = 1 := rfl\n\nlemma _root_.mem_\u2113p.infty_pow {f : \u03a0 i, B i} (hf : mem_\u2113p f \u221e) (n : \u2115) : mem_\u2113p (f ^ n) \u221e :=\nbegin\n  induction n with n hn,\n  { rw pow_zero,\n    exact one_mem_\u2113p_infty },\n  { rw pow_succ,\n    exact hf.infty_mul hn }\nend\n\ninstance [nonempty I] : norm_one_class (lp B \u221e) :=\n{ norm_one := by simp_rw [lp.norm_eq_csupr, infty_coe_fn_one, pi.one_apply, norm_one, csupr_const]}\n\ninstance : has_pow (lp B \u221e) \u2115 := { pow := \u03bb f n, \u27e8_, f.prop.infty_pow n\u27e9 }\n\n@[simp] lemma infty_coe_fn_pow (f : lp B \u221e) (n : \u2115) : \u21d1(f ^ n) = f ^ n := rfl\n\nlemma _root_.nat_cast_mem_\u2113p_infty : \u2200 (n : \u2115), mem_\u2113p (n : \u03a0 i, B i) \u221e\n| 0 := by { rw nat.cast_zero, exact zero_mem_\u2113p }\n| (n + 1) := by { rw nat.cast_succ, exact (_root_.nat_cast_mem_\u2113p_infty n).add one_mem_\u2113p_infty }\n\ninstance : has_nat_cast (lp B \u221e) := { nat_cast := \u03bb n, \u27e8(\u2191n : \u03a0 i, B i), nat_cast_mem_\u2113p_infty _\u27e9 }\n\n@[simp] lemma infty_coe_fn_nat_cast (n : \u2115) : \u21d1(n : lp B \u221e) = n := rfl\n\nlemma _root_.int_cast_mem_\u2113p_infty (z : \u2124) : mem_\u2113p (z : \u03a0 i, B i) \u221e :=\nbegin\n  obtain \u27e8n, rfl | rfl\u27e9 := z.eq_coe_or_neg,\n  { rw int.cast_coe_nat,\n    exact nat_cast_mem_\u2113p_infty n },\n  { rw [int.cast_neg, int.cast_coe_nat],\n    exact (nat_cast_mem_\u2113p_infty n).neg }\nend\n\ninstance : has_int_cast (lp B \u221e) := { int_cast := \u03bb z, \u27e8(\u2191z : \u03a0 i, B i), int_cast_mem_\u2113p_infty _\u27e9 }\n\n@[simp] lemma infty_coe_fn_int_cast (z : \u2124) : \u21d1(z : lp B \u221e) = z := rfl\n\ninstance : ring (lp B \u221e) :=\nfunction.injective.ring lp.has_coe_to_fun.coe subtype.coe_injective\n  (lp.coe_fn_zero B \u221e) (infty_coe_fn_one) lp.coe_fn_add infty_coe_fn_mul\n  lp.coe_fn_neg lp.coe_fn_sub (\u03bb _ _, rfl) (\u03bb _ _, rfl) infty_coe_fn_pow\n  infty_coe_fn_nat_cast infty_coe_fn_int_cast\n\ninstance : normed_ring (lp B \u221e) :=\n{ .. lp.ring, .. lp.non_unital_normed_ring }\n\nend normed_ring\n\nsection normed_comm_ring\n\nvariables {I : Type*} {B : I \u2192 Type*} [\u03a0 i, normed_comm_ring (B i)] [\u2200 i, norm_one_class (B i)]\n\ninstance : comm_ring (lp B \u221e) :=\n{ mul_comm := \u03bb f g, by { ext, simp only [lp.infty_coe_fn_mul, pi.mul_apply, mul_comm] },\n  .. lp.ring }\n\ninstance : normed_comm_ring (lp B \u221e) :=\n{ .. lp.comm_ring, .. lp.normed_ring }\n\nend normed_comm_ring\n\nsection single\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [\u03a0 i, normed_space \ud835\udd5c (E i)]\nvariables [decidable_eq \u03b1]\n\n/-- The element of `lp E p` which is `a : E i` at the index `i`, and zero elsewhere. -/\nprotected def single (p) (i : \u03b1) (a : E i) : lp E p :=\n\u27e8 \u03bb j, if h : j = i then eq.rec a h.symm else 0,\n  begin\n    refine (mem_\u2113p_zero _).of_exponent_ge (zero_le p),\n    refine (set.finite_singleton i).subset _,\n    intros j,\n    simp only [forall_exists_index, set.mem_singleton_iff, ne.def, dite_eq_right_iff,\n      set.mem_set_of_eq, not_forall],\n    rintros rfl,\n    simp,\n  end \u27e9\n\nprotected lemma single_apply (p) (i : \u03b1) (a : E i) (j : \u03b1) :\n  lp.single p i a j = if h : j = i then eq.rec a h.symm else 0 :=\nrfl\n\nprotected lemma single_apply_self (p) (i : \u03b1) (a : E i) :\n  lp.single p i a i = a :=\nby rw [lp.single_apply, dif_pos rfl]\n\nprotected lemma single_apply_ne (p) (i : \u03b1) (a : E i) {j : \u03b1} (hij : j \u2260 i) :\n  lp.single p i a j = 0 :=\nby rw [lp.single_apply, dif_neg hij]\n\n@[simp] protected lemma single_neg (p) (i : \u03b1) (a : E i) :\n  lp.single p i (- a) = - lp.single p i a :=\nbegin\n  ext j,\n  by_cases hi : j = i,\n  { subst hi,\n    simp [lp.single_apply_self] },\n  { simp [lp.single_apply_ne p i _ hi] }\nend\n\n@[simp] protected lemma single_smul (p) (i : \u03b1) (a : E i) (c : \ud835\udd5c) :\n  lp.single p i (c \u2022 a) = c \u2022 lp.single p i a :=\nbegin\n  ext j,\n  by_cases hi : j = i,\n  { subst hi,\n    simp [lp.single_apply_self] },\n  { simp [lp.single_apply_ne p i _ hi] }\nend\n\nprotected lemma norm_sum_single (hp : 0 < p.to_real) (f : \u03a0 i, E i) (s : finset \u03b1) :\n  \u2225\u2211 i in s, lp.single p i (f i)\u2225 ^ p.to_real = \u2211 i in s, \u2225f i\u2225 ^ p.to_real :=\nbegin\n  refine (has_sum_norm hp (\u2211 i in s, lp.single p i (f i))).unique _,\n  simp only [lp.single_apply, coe_fn_sum, finset.sum_apply, finset.sum_dite_eq],\n  have h : \u2200 i \u2209 s, \u2225ite (i \u2208 s) (f i) 0\u2225 ^ p.to_real = 0,\n  { intros i hi,\n    simp [if_neg hi, real.zero_rpow hp.ne'], },\n  have h' : \u2200 i \u2208 s, \u2225f i\u2225 ^ p.to_real = \u2225ite (i \u2208 s) (f i) 0\u2225 ^ p.to_real,\n  { intros i hi,\n    rw if_pos hi },\n  simpa [finset.sum_congr rfl h'] using has_sum_sum_of_ne_finset_zero h,\nend\n\nprotected lemma norm_single (hp : 0 < p.to_real) (f : \u03a0 i, E i) (i : \u03b1) :\n  \u2225lp.single p i (f i)\u2225 = \u2225f i\u2225 :=\nbegin\n  refine real.rpow_left_inj_on hp.ne' (norm_nonneg' _) (norm_nonneg _) _,\n  simpa using lp.norm_sum_single hp f {i},\nend\n\nprotected lemma norm_sub_norm_compl_sub_single (hp : 0 < p.to_real) (f : lp E p) (s : finset \u03b1) :\n  \u2225f\u2225 ^ p.to_real - \u2225f - \u2211 i in s, lp.single p i (f i)\u2225 ^ p.to_real = \u2211 i in s, \u2225f i\u2225 ^ p.to_real :=\nbegin\n  refine ((has_sum_norm hp f).sub (has_sum_norm hp (f - \u2211 i in s, lp.single p i (f i)))).unique _,\n  let F : \u03b1 \u2192 \u211d := \u03bb i, \u2225f i\u2225 ^ p.to_real - \u2225(f - \u2211 i in s, lp.single p i (f i)) i\u2225 ^ p.to_real,\n  have hF : \u2200 i \u2209 s, F i = 0,\n  { intros i hi,\n    suffices : \u2225f i\u2225 ^ p.to_real - \u2225f i - ite (i \u2208 s) (f i) 0\u2225 ^ p.to_real = 0,\n    { simpa [F, coe_fn_sum, lp.single_apply] using this, },\n    simp [if_neg hi] },\n  have hF' : \u2200 i \u2208 s, F i = \u2225f i\u2225 ^ p.to_real,\n  { intros i hi,\n    simp [F, coe_fn_sum, lp.single_apply, if_pos hi, real.zero_rpow hp.ne'] },\n  have : has_sum F (\u2211 i in s, F i) := has_sum_sum_of_ne_finset_zero hF,\n  rwa [finset.sum_congr rfl hF'] at this,\nend\n\nprotected lemma norm_compl_sum_single (hp : 0 < p.to_real) (f : lp E p) (s : finset \u03b1) :\n  \u2225f - \u2211 i in s, lp.single p i (f i)\u2225 ^ p.to_real = \u2225f\u2225 ^ p.to_real - \u2211 i in s, \u2225f i\u2225 ^ p.to_real :=\nby linarith [lp.norm_sub_norm_compl_sub_single hp f s]\n\n/-- The canonical finitely-supported approximations to an element `f` of `lp` converge to it, in the\n`lp` topology. -/\nprotected lemma has_sum_single [fact (1 \u2264 p)] (hp : p \u2260 \u22a4) (f : lp E p) :\n  has_sum (\u03bb i : \u03b1, lp.single p i (f i : E i)) f :=\nbegin\n  have hp\u2080 : 0 < p := ennreal.zero_lt_one.trans_le (fact.out _),\n  have hp' : 0 < p.to_real := ennreal.to_real_pos hp\u2080.ne' hp,\n  have := lp.has_sum_norm hp' f,\n  dsimp [has_sum] at this \u22a2,\n  rw metric.tendsto_nhds at this \u22a2,\n  intros \u03b5 h\u03b5,\n  refine (this _ (real.rpow_pos_of_pos h\u03b5 p.to_real)).mono _,\n  intros s hs,\n  rw \u2190 real.rpow_lt_rpow_iff dist_nonneg (le_of_lt h\u03b5) hp',\n  rw dist_comm at hs,\n  simp only [dist_eq_norm, real.norm_eq_abs] at hs \u22a2,\n  have H : \u2225\u2211 i in s, lp.single p i (f i : E i) - f\u2225 ^ p.to_real\n    = \u2225f\u2225 ^ p.to_real - \u2211 i in s, \u2225f i\u2225 ^ p.to_real,\n  { simpa using lp.norm_compl_sum_single hp' (-f) s },\n  rw \u2190 H at hs,\n  have : |\u2225\u2211 i in s, lp.single p i (f i : E i) - f\u2225 ^ p.to_real|\n    = \u2225\u2211 i in s, lp.single p i (f i : E i) - f\u2225 ^ p.to_real,\n  { simp [real.abs_rpow_of_nonneg (norm_nonneg _)] },\n  linarith\nend\n\nend single\n\nsection topology\n\nopen filter\nopen_locale topological_space uniformity\n\n/-- The coercion from `lp E p` to `\u03a0 i, E i` is uniformly continuous. -/\nlemma uniform_continuous_coe [_i : fact (1 \u2264 p)] : uniform_continuous (coe : lp E p \u2192 \u03a0 i, E i) :=\nbegin\n  have hp : p \u2260 0 := (ennreal.zero_lt_one.trans_le _i.elim).ne',\n  rw uniform_continuous_pi,\n  intros i,\n  rw normed_group.uniformity_basis_dist.uniform_continuous_iff normed_group.uniformity_basis_dist,\n  intros \u03b5 h\u03b5,\n  refine \u27e8\u03b5, h\u03b5, _\u27e9,\n  rintros f g (hfg : \u2225f - g\u2225 < \u03b5),\n  have : \u2225f i - g i\u2225 \u2264 \u2225f - g\u2225 := norm_apply_le_norm hp (f - g) i,\n  exact this.trans_lt hfg,\nend\n\nvariables {\u03b9 : Type*} {l : filter \u03b9} [filter.ne_bot l]\n\nlemma norm_apply_le_of_tendsto {C : \u211d} {F : \u03b9 \u2192 lp E \u221e} (hCF : \u2200\u1da0 k in l, \u2225F k\u2225 \u2264 C)\n  {f : \u03a0 a, E a} (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) (a : \u03b1) :\n  \u2225f a\u2225 \u2264 C :=\nbegin\n  have : tendsto (\u03bb k, \u2225F k a\u2225) l (\ud835\udcdd \u2225f a\u2225) :=\n    (tendsto.comp (continuous_apply a).continuous_at hf).norm,\n  refine le_of_tendsto this (hCF.mono _),\n  intros k hCFk,\n  exact (norm_apply_le_norm ennreal.top_ne_zero (F k) a).trans hCFk,\nend\n\nvariables [_i : fact (1 \u2264 p)]\n\ninclude _i\n\nlemma sum_rpow_le_of_tendsto (hp : p \u2260 \u221e) {C : \u211d} {F : \u03b9 \u2192 lp E p} (hCF : \u2200\u1da0 k in l, \u2225F k\u2225 \u2264 C)\n  {f : \u03a0 a, E a} (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) (s : finset \u03b1) :\n  \u2211 (i : \u03b1) in s, \u2225f i\u2225 ^ p.to_real \u2264 C ^ p.to_real :=\nbegin\n  have hp' : p \u2260 0 := (ennreal.zero_lt_one.trans_le _i.elim).ne',\n  have hp'' : 0 < p.to_real := ennreal.to_real_pos hp' hp,\n  let G : (\u03a0 a, E a) \u2192 \u211d := \u03bb f, \u2211 a in s, \u2225f a\u2225 ^ p.to_real,\n  have hG : continuous G,\n  { refine continuous_finset_sum s _,\n    intros a ha,\n    have : continuous (\u03bb f : \u03a0 a, E a, f a):= continuous_apply a,\n    exact this.norm.rpow_const (\u03bb _, or.inr hp''.le) },\n  refine le_of_tendsto (hG.continuous_at.tendsto.comp hf) _,\n  refine hCF.mono _,\n  intros k hCFk,\n  refine (lp.sum_rpow_le_norm_rpow hp'' (F k) s).trans _,\n  exact real.rpow_le_rpow (norm_nonneg _) hCFk hp''.le,\nend\n\n/-- \"Semicontinuity of the `lp` norm\": If all sufficiently large elements of a sequence in `lp E p`\n have `lp` norm `\u2264 C`, then the pointwise limit, if it exists, also has `lp` norm `\u2264 C`. -/\nlemma norm_le_of_tendsto {C : \u211d} {F : \u03b9 \u2192 lp E p} (hCF : \u2200\u1da0 k in l, \u2225F k\u2225 \u2264 C) {f : lp E p}\n  (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) :\n  \u2225f\u2225 \u2264 C :=\nbegin\n  obtain \u27e8i, hi\u27e9 := hCF.exists,\n  have hC : 0 \u2264 C := (norm_nonneg _).trans hi,\n  unfreezingI { rcases eq_top_or_lt_top p with rfl | hp },\n  { apply norm_le_of_forall_le hC,\n    exact norm_apply_le_of_tendsto hCF hf, },\n  { have : 0 < p := ennreal.zero_lt_one.trans_le _i.elim,\n    have hp' : 0 < p.to_real := ennreal.to_real_pos this.ne' hp.ne,\n    apply norm_le_of_forall_sum_le hp' hC,\n    exact sum_rpow_le_of_tendsto hp.ne hCF hf, }\nend\n\n/-- If `f` is the pointwise limit of a bounded sequence in `lp E p`, then `f` is in `lp E p`. -/\nlemma mem_\u2113p_of_tendsto {F : \u03b9 \u2192 lp E p} (hF : metric.bounded (set.range F)) {f : \u03a0 a, E a}\n  (hf : tendsto (id (\u03bb i, F i) : \u03b9 \u2192 \u03a0 a, E a) l (\ud835\udcdd f)) :\n  mem_\u2113p f p :=\nbegin\n  obtain \u27e8C, hC, hCF'\u27e9 := hF.exists_pos_norm_le,\n  have hCF : \u2200 k, \u2225F k\u2225 \u2264 C := \u03bb k, hCF' _ \u27e8k, rfl\u27e9,\n  unfreezingI { rcases eq_top_or_lt_top p with rfl | hp },\n  { apply mem_\u2113p_infty,\n    use C,\n    rintros _ \u27e8a, rfl\u27e9,\n    refine norm_apply_le_of_tendsto (eventually_of_forall hCF) hf a, },\n  { apply mem_\u2113p_gen',\n    exact sum_rpow_le_of_tendsto hp.ne (eventually_of_forall hCF) hf },\nend\n\n/-- If a sequence is Cauchy in the `lp E p` topology and pointwise convergent to a element `f` of\n`lp E p`, then it converges to `f` in the `lp E p` topology. -/\nlemma tendsto_lp_of_tendsto_pi {F : \u2115 \u2192 lp E p} (hF : cauchy_seq F) {f : lp E p}\n  (hf : tendsto (id (\u03bb i, F i) : \u2115 \u2192 \u03a0 a, E a) at_top (\ud835\udcdd f)) :\n  tendsto F at_top (\ud835\udcdd f) :=\nbegin\n  rw metric.nhds_basis_closed_ball.tendsto_right_iff,\n  intros \u03b5 h\u03b5,\n  have h\u03b5' : {p : (lp E p) \u00d7 (lp E p) | \u2225p.1 - p.2\u2225 < \u03b5} \u2208 \ud835\udce4 (lp E p),\n  { exact normed_group.uniformity_basis_dist.mem_of_mem h\u03b5 },\n  refine (hF.eventually_eventually h\u03b5').mono _,\n  rintros n (hn : \u2200\u1da0 l in at_top, \u2225(\u03bb f, F n - f) (F l)\u2225 < \u03b5),\n  refine norm_le_of_tendsto (hn.mono (\u03bb k hk, hk.le)) _,\n  rw tendsto_pi_nhds,\n  intros a,\n  exact (hf.apply a).const_sub (F n a),\nend\n\nvariables [\u03a0 a, complete_space (E a)]\n\ninstance : complete_space (lp E p) :=\nmetric.complete_of_cauchy_seq_tendsto\nbegin\n  intros F hF,\n  -- A Cauchy sequence in `lp E p` is pointwise convergent; let `f` be the pointwise limit.\n  obtain \u27e8f, hf\u27e9 := cauchy_seq_tendsto_of_complete (uniform_continuous_coe.comp_cauchy_seq hF),\n  -- Since the Cauchy sequence is bounded, its pointwise limit `f` is in `lp E p`.\n  have hf' : mem_\u2113p f p := mem_\u2113p_of_tendsto hF.bounded_range hf,\n  -- And therefore `f` is its limit in the `lp E p` topology as well as pointwise.\n  exact \u27e8\u27e8f, hf'\u27e9, tendsto_lp_of_tendsto_pi hF hf\u27e9\nend\n\nend topology\n\nend lp\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/analysis/normed_space/lp_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951579736619, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.7237669636105571}}
{"text": "import game.order.level04\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 5\n\nAnother well-known property of the absolute value.\n-/\n\nnotation `|` x `|` := abs x -- hide\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$| |a| - |b| | \u2264 |a - b|$$.\n-/\ntheorem abs_of_sub_le_abs (a b : \u211d) : | |a| - |b| | \u2264 |a - b| :=\nbegin\n    have h1 : a = (a - b) + b, norm_num,\n    have h2 : |a| = |(a-b) + b|, rw h1, simp,\n    have h3 : |(a-b) + b | \u2264 |a-b| + |b|, exact abs_add _ _,\n    rw \u2190 h2 at h3,\n    have h4a : |a| - |b| \u2264 |a - b|, linarith,\n    clear h1 h2 h3,\n    have h1 : b = (b - a) + a, norm_num,\n    have h2 : |b| = |(b-a) + a|, rw h1, simp,\n    have h3 : |(b-a) + a | \u2264 |b-a| + |a|, exact abs_add _ _,\n    rw \u2190 h2 at h3,\n    have h4b : |b| - |a| \u2264 |b - a|, linarith, \n    clear h1 h2 h3,\n    have h1 := eq.symm ( abs_neg (a-b) ),\n    have h2 : -(a-b) = b - a, norm_num,\n    rw h2 at h1, clear h2,\n    rw \u2190 h1 at h4b, clear h1,\n    have H : max ( |a| - |b| ) ( |b| - |a| ) \u2264 | a - b |, \n        simp, split, exact h4a, exact h4b,\n    unfold abs,\n    unfold abs at H, \n    have G: -(max a (-a) - max b (-b)) = max b (-b) - max a (-a),\n        norm_num,\n    rw G,\n    exact H, done,\nend\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.7236992459969823}}
{"text": "/-\nCopyright (c) 2021 Lu-Ming Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Lu-Ming Zhang\n\n! This file was ported from Lean 3 source module data.matrix.hadamard\n! leanprover-community/mathlib commit 3d7987cda72abc473c7cdbbb075170e9ac620042\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Matrix.Trace\n\n/-!\n# Hadamard product of matrices\n\nThis file defines the Hadamard product `matrix.hadamard`\nand contains basic properties about them.\n\n## Main definition\n\n- `matrix.hadamard`: defines the Hadamard product,\n  which is the pointwise product of two matrices of the same size.\n\n## Notation\n\n* `\u2299`: the Hadamard product `matrix.hadamard`;\n\n## References\n\n*  <https://en.wikipedia.org/wiki/hadamard_product_(matrices)>\n\n## Tags\n\nhadamard product, hadamard\n-/\n\n\nvariable {\u03b1 \u03b2 \u03b3 m n : Type _}\n\nvariable {R : Type _}\n\nnamespace Matrix\n\nopen Matrix BigOperators\n\n/-- `matrix.hadamard` defines the Hadamard product,\n    which is the pointwise product of two matrices of the same size.-/\n@[simp]\ndef hadamard [Mul \u03b1] (A : Matrix m n \u03b1) (B : Matrix m n \u03b1) : Matrix m n \u03b1\n  | i, j => A i j * B i j\n#align matrix.hadamard Matrix.hadamard\n\n-- mathport name: matrix.hadamard\nscoped infixl:100 \" \u2299 \" => Matrix.hadamard\n\nsection BasicProperties\n\nvariable (A : Matrix m n \u03b1) (B : Matrix m n \u03b1) (C : Matrix m n \u03b1)\n\n-- commutativity\ntheorem hadamard_comm [CommSemigroup \u03b1] : A \u2299 B = B \u2299 A :=\n  ext fun _ _ => mul_comm _ _\n#align matrix.hadamard_comm Matrix.hadamard_comm\n\n-- associativity\ntheorem hadamard_assoc [Semigroup \u03b1] : A \u2299 B \u2299 C = A \u2299 (B \u2299 C) :=\n  ext fun _ _ => mul_assoc _ _ _\n#align matrix.hadamard_assoc Matrix.hadamard_assoc\n\n-- distributivity\ntheorem hadamard_add [Distrib \u03b1] : A \u2299 (B + C) = A \u2299 B + A \u2299 C :=\n  ext fun _ _ => left_distrib _ _ _\n#align matrix.hadamard_add Matrix.hadamard_add\n\ntheorem add_hadamard [Distrib \u03b1] : (B + C) \u2299 A = B \u2299 A + C \u2299 A :=\n  ext fun _ _ => right_distrib _ _ _\n#align matrix.add_hadamard Matrix.add_hadamard\n\n-- scalar multiplication\nsection Scalar\n\n@[simp]\ntheorem smul_hadamard [Mul \u03b1] [SMul R \u03b1] [IsScalarTower R \u03b1 \u03b1] (k : R) : (k \u2022 A) \u2299 B = k \u2022 A \u2299 B :=\n  ext fun _ _ => smul_mul_assoc _ _ _\n#align matrix.smul_hadamard Matrix.smul_hadamard\n\n@[simp]\ntheorem hadamard_smul [Mul \u03b1] [SMul R \u03b1] [SMulCommClass R \u03b1 \u03b1] (k : R) : A \u2299 (k \u2022 B) = k \u2022 A \u2299 B :=\n  ext fun _ _ => mul_smul_comm _ _ _\n#align matrix.hadamard_smul Matrix.hadamard_smul\n\nend Scalar\n\nsection Zero\n\nvariable [MulZeroClass \u03b1]\n\n@[simp]\ntheorem hadamard_zero : A \u2299 (0 : Matrix m n \u03b1) = 0 :=\n  ext fun _ _ => MulZeroClass.mul_zero _\n#align matrix.hadamard_zero Matrix.hadamard_zero\n\n@[simp]\ntheorem zero_hadamard : (0 : Matrix m n \u03b1) \u2299 A = 0 :=\n  ext fun _ _ => MulZeroClass.zero_mul _\n#align matrix.zero_hadamard Matrix.zero_hadamard\n\nend Zero\n\nsection One\n\nvariable [DecidableEq n] [MulZeroOneClass \u03b1]\n\nvariable (M : Matrix n n \u03b1)\n\ntheorem hadamard_one : M \u2299 (1 : Matrix n n \u03b1) = diagonal fun i => M i i :=\n  by\n  ext\n  by_cases h : i = j <;> simp [h]\n#align matrix.hadamard_one Matrix.hadamard_one\n\ntheorem one_hadamard : (1 : Matrix n n \u03b1) \u2299 M = diagonal fun i => M i i :=\n  by\n  ext\n  by_cases h : i = j <;> simp [h]\n#align matrix.one_hadamard Matrix.one_hadamard\n\nend One\n\nsection Diagonal\n\nvariable [DecidableEq n] [MulZeroClass \u03b1]\n\ntheorem diagonal_hadamard_diagonal (v : n \u2192 \u03b1) (w : n \u2192 \u03b1) :\n    diagonal v \u2299 diagonal w = diagonal (v * w) :=\n  ext fun _ _ => (apply_ite\u2082 _ _ _ _ _ _).trans (congr_arg _ <| MulZeroClass.zero_mul 0)\n#align matrix.diagonal_hadamard_diagonal Matrix.diagonal_hadamard_diagonal\n\nend Diagonal\n\nsection trace\n\nvariable [Fintype m] [Fintype n]\n\nvariable (R) [Semiring \u03b1] [Semiring R] [Module R \u03b1]\n\ntheorem sum_hadamard_eq : (\u2211 (i : m) (j : n), (A \u2299 B) i j) = trace (A \u2b1d B\u1d40) :=\n  rfl\n#align matrix.sum_hadamard_eq Matrix.sum_hadamard_eq\n\ntheorem dotProduct_vecMul_hadamard [DecidableEq m] [DecidableEq n] (v : m \u2192 \u03b1) (w : n \u2192 \u03b1) :\n    dotProduct (vecMul v (A \u2299 B)) w = trace (diagonal v \u2b1d A \u2b1d (B \u2b1d diagonal w)\u1d40) :=\n  by\n  rw [\u2190 sum_hadamard_eq, Finset.sum_comm]\n  simp [dot_product, vec_mul, Finset.sum_mul, mul_assoc]\n#align matrix.dot_product_vec_mul_hadamard Matrix.dotProduct_vecMul_hadamard\n\nend trace\n\nend BasicProperties\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Matrix/Hadamard.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7236992393081799}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 4 : \"and\" (`\u2227`)\n\nWe learn about how to manipulate `P \u2227 Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following tactics:\n\n* `cases`\n* `split`\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : P \u2227 Q \u2192 P :=\nbegin\n  sorry\nend\n\nexample : P \u2227 Q \u2192 Q :=\nbegin\n  sorry\nend\n\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2227 Q \u2192 R) :=\nbegin\n  sorry\nend\n\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  sorry\nend\n\n/-- `\u2227` is symmetric -/\nexample : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  sorry\nend\n\nexample : P \u2192 P \u2227 true :=\nbegin\n  sorry\nend\n\nexample : false \u2192 P \u2227 false :=\nbegin\n  sorry\nend\n\n/-- `\u2227` is transitive -/\nexample : (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n  sorry,\nend\n\nexample : ((P \u2227 Q) \u2192 R) \u2192 (P \u2192 Q \u2192 R) :=\nbegin\n  sorry,\nend\n\n\n\n", "meta": {"author": "Sukkrivaa", "repo": "lean2022", "sha": "f00390aafca0faab674cbaff557835bc463c8691", "save_path": "github-repos/lean/Sukkrivaa-lean2022", "path": "github-repos/lean/Sukkrivaa-lean2022/lean2022-f00390aafca0faab674cbaff557835bc463c8691/src/section01logic/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.723691090460314}}
{"text": "/-\nCopyright (c) 2021 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport ring_theory.adjoin.polynomial\nimport data.mv_polynomial.variables\n\n/-!\n# Polynomials supported by a set of variables\n\nThis file contains the definition and lemmas about `mv_polynomial.supported`.\n\n## Main definitions\n\n* `mv_polynomial.supported` : Given a set `s : set \u03c3`, `supported R s` is the subalgebra of\n  `mv_polynomial \u03c3 R` consisting of polynomials whose set of variables is contained in `s`.\n  This subalgebra is isomorphic to `mv_polynomial s R`\n\n## Tags\nvariables, polynomial, vars\n-/\nuniverses u v w\n\nnamespace mv_polynomial\nvariables {\u03c3 \u03c4 : Type*} {R : Type u} {S : Type v} {r : R} {e : \u2115} {n m : \u03c3}\n\nsection comm_semiring\nvariables [comm_semiring R] {p q : mv_polynomial \u03c3 R}\n\nvariables (R)\n\n/-- The set of polynomials whose variables are contained in `s` as a `subalgebra` over `R`. -/\nnoncomputable def supported (s : set \u03c3) : subalgebra R (mv_polynomial \u03c3 R) :=\nalgebra.adjoin R (X '' s)\n\nvariables {\u03c3 R}\n\nopen_locale classical\nopen algebra\n\nlemma supported_eq_range_rename (s : set \u03c3) :\n  supported R s = (rename (coe : s \u2192 \u03c3)).range :=\nby rw [supported, set.image_eq_range, adjoin_range_eq_range_aeval, rename]\n\n/--The isomorphism between the subalgebra of polynomials supported by `s` and `mv_polynomial s R`-/\nnoncomputable def supported_equiv_mv_polynomial (s : set \u03c3) :\n  supported R s \u2243\u2090[R] mv_polynomial s R :=\n(subalgebra.equiv_of_eq _ _ (supported_eq_range_rename s)).trans\n(alg_equiv.of_injective (rename (coe : s \u2192 \u03c3))\n  (rename_injective _ subtype.val_injective)).symm\n\n@[simp] lemma supported_equiv_mv_polynomial_symm_C (s : set \u03c3) (x : R) :\n  (supported_equiv_mv_polynomial s).symm (C x) = algebra_map R (supported R s) x :=\nbegin\n  ext1,\n  simp [supported_equiv_mv_polynomial, mv_polynomial.algebra_map_eq],\nend\n\n@[simp] lemma supported_equiv_mv_polynomial_symm_X (s : set \u03c3) (i : s) :\n  (\u2191((supported_equiv_mv_polynomial s).symm (X i : mv_polynomial s R)) : mv_polynomial \u03c3 R) = X i :=\nby simp [supported_equiv_mv_polynomial]\n\nvariables {s t : set \u03c3}\n\nlemma mem_supported : p \u2208 (supported R s) \u2194 \u2191p.vars \u2286 s :=\nbegin\n  rw [supported_eq_range_rename, alg_hom.mem_range],\n  split,\n  { rintros \u27e8p, rfl\u27e9,\n    refine trans (finset.coe_subset.2 (vars_rename _ _)) _,\n    simp },\n  { intros hs,\n    exact exists_rename_eq_of_vars_subset_range p (coe : s \u2192 \u03c3) subtype.val_injective (by simpa) }\nend\n\nlemma supported_eq_vars_subset : (supported R s : set (mv_polynomial \u03c3 R)) = {p | \u2191p.vars \u2286 s} :=\nset.ext $ \u03bb _, mem_supported\n\n@[simp] lemma mem_supported_vars (p : mv_polynomial \u03c3 R) : p \u2208 supported R (\u2191p.vars : set \u03c3) :=\nby rw [mem_supported]\n\nvariable (s)\n\nlemma supported_eq_adjoin_X : supported R s = algebra.adjoin R (X '' s) := rfl\n\n@[simp] lemma supported_univ : supported R (set.univ : set \u03c3) = \u22a4 :=\nby simp [algebra.eq_top_iff, mem_supported]\n\n@[simp] lemma supported_empty : supported R (\u2205 : set \u03c3) = \u22a5 :=\nby simp [supported_eq_adjoin_X]\n\nvariables {s}\n\nlemma supported_mono (st : s \u2286 t) : supported R s \u2264 supported R t :=\nalgebra.adjoin_mono (set.image_subset _ st)\n\n@[simp] lemma X_mem_supported [nontrivial R] {i : \u03c3} : (X i) \u2208 supported R s \u2194 i \u2208 s :=\nby simp [mem_supported]\n\n@[simp] lemma supported_le_supported_iff [nontrivial R] :\n  supported R s \u2264 supported R t \u2194 s \u2286 t :=\nbegin\n  split,\n  { intros h i,\n    simpa using @h (X i) },\n  { exact supported_mono }\nend\n\nlemma supported_strict_mono [nontrivial R] :\n  strict_mono (supported R : set \u03c3 \u2192 subalgebra R (mv_polynomial \u03c3 R)) :=\nstrict_mono_of_le_iff_le (\u03bb _ _, supported_le_supported_iff.symm)\n\nend comm_semiring\n\nend mv_polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/mv_polynomial/supported.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.7236910823882805}}
{"text": "import super\nopen tactic\n\nset_option trace.super true\nset_option profiler true\n\ndef prime (n : \u2115) := \u2200 d, d \u2223 n \u2192 d = 1 \u2228 d = n\n\nset_option trace.check true\n\nlemma nat_mul_cancel_one {m n : \u2115} : m \u2260 0 \u2192 m * n = m \u2192 n = 1 :=\nby cases m; super [gt, nat.zero_lt_succ,\nnat.eq_of_mul_eq_mul_left, mul_one, zero_mul, nat.not_lt_zero]\n\nlemma not_prime_zero : \u00ac prime 0 :=\nby intro h; cases h 2 \u27e80, by simp\u27e9; cases h_1\n\n/-\nexample {m n : \u2115} : prime (m * n) \u2192 m = 1 \u2228 n = 1 :=\nby super [prime, dvd_refl, dvd_mul_right, dvd_mul_left,\nnat_mul_cancel_one, not_prime_zero, mul_zero, zero_mul]\n-/\n\nexample : nat.zero \u2260 nat.succ nat.zero := by super [nat.zero_lt_succ, ne_of_lt]\nexample (x y : \u2115) : nat.succ x = nat.succ y \u2192 x = y := by super [nat.succ.inj]\nexample (i) (a b c : i) : [a,b,c] = [b,c,a] -> a = b \u2227 b = c := by super [list.cons.inj]\n\ndefinition is_positive (n : \u2115) := n > 0\nexample (n : \u2115) : n > 0 \u2194 is_positive n := by super [is_positive]\n\nexample (m n : \u2115) : 0 + m = 0 + n \u2192 m = n :=\nby super [zero_add]\n\nexample : \u2200x y : \u2115, x + y = y + x :=\nbegin intros, have h : nat.zero = 0 := rfl, induction x,\n      super [add_zero, zero_add],\n      super [*, nat.add_succ, nat.succ_add] end\n\nexample (i) [inhabited i] : nonempty i := by super *\nexample (i) [nonempty i] : \u00ac(inhabited i \u2192 false) :=\nby super [classical.inhabited_of_nonempty]\n\nexample : nonempty \u2115 := by super\nexample : \u00ac(inhabited \u2115 \u2192 false) := by super\n\nexample {a b} : \u00ac(b \u2228 \u00aca) \u2228 (a \u2192 b) := by super\nexample {a} : a \u2228 \u00aca := by super\nexample {a} : (a \u2227 a) \u2228 (\u00aca \u2227 \u00aca) := by super\nexample {a} : \u00aca \u2192 (\u00aca \u2227 \u00aca) := by super\nexample {a} : a \u2228 a \u2192 a := by super\nexample (i) (c : i) (p : i \u2192 Prop) (f : i \u2192 i) :\n  p c \u2192 (\u2200x, p x \u2192 p (f x)) \u2192 p (f (f (f c))) := by super\n\nexample (i : Type) (p : i \u2192 Prop) : \u2200x, p x \u2192 \u2203x, p x := by super\n\nexample (i) [nonempty i] (p : i \u2192 i \u2192 Prop) : (\u2200x y, p x y) \u2192 \u2203x, \u2200z, p x z :=\nby super\n\nexample (i) [nonempty i] (p : i \u2192 Prop) : (\u2200x, p x) \u2192 \u00ac\u00ac\u2200x, p x := by super *\n\n-- Requires non-empty domain.\nexample {i} [nonempty i] (p : i \u2192 Prop) :\n  (\u2200x y, p x \u2228 p y) \u2192 \u2203x y, p x \u2227 p y := by super *\n\nexample (i) (a b : i) (p : i \u2192 Prop) (H : a = b) : p b \u2192 p a :=\nby super *\n\nexample (i) (a b : i) (p : i \u2192 Prop) (H : a = b) : p a \u2192 p b :=\nby super *\n\nexample (i) (a b : i) (p : i \u2192 Prop) (H : a = b) : p b = p a :=\nby super *\n\nexample (i) (c : i) (p : i \u2192 Prop) (f g : i \u2192 i) :\np c \u2192 (\u2200x, p x \u2192 p (f x)) \u2192 (\u2200x, p x \u2192 f x = g x) \u2192 f (f c) = g (g c) :=\nby super\n\n-- This example from Davis-Putnam actually requires a non-empty domain\n\nexample (i) [nonempty i] (f g : i \u2192 i \u2192 Prop) :\n  \u2203x y, \u2200z, (f x y \u2192 f y z \u2227 f z z) \u2227 (f x y \u2227 g x y \u2192 g x z \u2227 g z z) :=\nby super\n\nexample (person) [nonempty person] (drinks : person \u2192 Prop) :\n  \u2203canary, drinks canary \u2192 \u2200other, drinks other := by super\n\nexample {p q : \u2115 \u2192 Prop} {r} : (\u2200x y, p x \u2227 q y \u2227 r) -> \u2200x, (p x \u2227 r \u2227 q x) :=\nby super\n\nexample {\u03b1} [add_group \u03b1] (x : \u03b1) : 0 + 0 + x + 0 + 0 + 0 = x :=\nby super [add_zero, zero_add]\n", "meta": {"author": "gebner", "repo": "super2", "sha": "9bc5256c31750021ab97d6b59b7387773e54b384", "save_path": "github-repos/lean/gebner-super2", "path": "github-repos/lean/gebner-super2/super2-9bc5256c31750021ab97d6b59b7387773e54b384/test/super_examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7236910813440103}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 4 : \"and\" (`\u2227`)\n\nWe learn about how to manipulate `P \u2227 Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following tactics:\n\n* `cases`\n* `split`\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : P \u2227 Q \u2192 P :=\nbegin\n  sorry\nend\n\nexample : P \u2227 Q \u2192 Q :=\nbegin\n  sorry\nend\n\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2227 Q \u2192 R) :=\nbegin\n  sorry\nend\n\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  sorry\nend\n\n/-- `\u2227` is symmetric -/\nexample : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  sorry\nend\n\nexample : P \u2192 P \u2227 true :=\nbegin\n  sorry\nend\n\nexample : false \u2192 P \u2227 false :=\nbegin\n  sorry\nend\n\n/-- `\u2227` is transitive -/\nexample : (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n  sorry,\nend\n\nexample : ((P \u2227 Q) \u2192 R) \u2192 (P \u2192 Q \u2192 R) :=\nbegin\n  sorry,\nend\n\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section01logic/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.723691079674092}}
{"text": "import boolalg\nimport init.meta.interactive_base\n\nopen boolalg \n\nvariables {A : boolalg}\n\n----------------------------------------------\n\nlemma symm_diff_three (X Y Z : A) : symm_diff (symm_diff X Y) Z = X \u2229 Y\u1d9c \u2229 Z\u1d9c \u222a Y \u2229 X\u1d9c \u2229 Z\u1d9c \u222a (Z \u2229 (X\u1d9c \u2229 Y\u1d9c) \u222a Z \u2229 (Y \u2229 X)) :=\nbegin\n  unfold symm_diff,\n  repeat {rw diff_eq},\n  repeat {rw inter_distrib_right},\n  rw [compl_union, compl_inter, compl_inter, compl_compl, compl_compl], \n  repeat {rw inter_distrib_left},\n  repeat {rw inter_distrib_right},\n  rw [inter_compl_self Y, inter_comm X\u1d9c X, inter_compl_self X, bot_union, union_bot]\nend\n\nlemma symm_diff_comm (X Y : A) : symm_diff X Y = symm_diff Y X := \n  by {unfold symm_diff, rw union_comm}\n\n\nlemma symm_diff_assoc (X Y Z : A) : symm_diff (symm_diff X Y) Z = symm_diff X (symm_diff Y Z) := \nbegin\n  rw [symm_diff_three, symm_diff_comm, symm_diff_three],\n  rw [inter_comm Y X\u1d9c, inter_comm Z, inter_comm Z, inter_comm Y X, inter_right_comm Y, inter_assoc Z\n      , inter_comm Y, inter_comm Z, inter_comm Y\u1d9c, inter_comm Z Y],\n    nth_rewrite 1 \u2190union_assoc, \n    nth_rewrite 4 union_comm,  \n    repeat {rw \u2190union_assoc},\n    repeat {rw \u2190inter_assoc}\nend\n\nlemma symm_diff_distrib_inter_left (X Y Z : A) : X \u2229 (symm_diff Y Z)  = symm_diff (X \u2229 Y) (X \u2229 Z) := \n  by {unfold symm_diff, rw [inter_distrib_left, inter_distrib_diff, \u2190inter_distrib_diff, \u2190inter_distrib_diff]}\n\nlemma symm_diff_distrib_inter_right (X Y Z : A) : (symm_diff X Y) \u2229 Z  = symm_diff (X \u2229 Z) (Y \u2229 Z) := \n  by {rw [inter_comm, inter_comm X, inter_comm Y], apply symm_diff_distrib_inter_left}\n\nlemma symm_diff_inter (X Y : A) : \n  symm_diff X (X \u2229 Y) = X \\ Y := \n  by rw [symm_diff_alt, absorb_union_inter, diff_eq, compl_inter, inter_distrib_left,\n     union_comm, union_inter_compl_self, compl_inter, inter_distrib_left, union_comm, union_inter_compl_self, \u2190 diff_eq] -- inter_compl_self, bot_union, compl_inter, inter_distrib_left],  \n  \nlemma top_symm_diff (X : A) : \n  symm_diff \u22a4 X = X\u1d9c := \n  by {unfold symm_diff, simp only [top_diff, diff_top, union_bot]}\n-----------------------------------------------\n\n\n\n@[simp] instance to_comm_ring  : comm_ring A  := \n{ \n  add := \u03bb X Y, symm_diff X Y, \n  add_assoc := \u03bb X Y Z, symm_diff_assoc X Y Z,\n  zero := \u22a5,\n  zero_add := \u03bb X, by {simp only [has_add.add], unfold symm_diff, rw [bot_diff, diff_bot, bot_union]},--rw [bot_union, boolalg.compl_bot, top_union, inter_top]},\n  add_zero := \u03bb X, by {simp only [has_add.add], unfold symm_diff, rw [bot_diff, diff_bot, union_bot]},\n  neg := \u03bb X, X, \n  add_left_neg := \u03bb X, symm_diff_self X, \n  add_comm := \u03bb X Y, symm_diff_comm X Y, \n  mul := \u03bb X Y, X \u2229 Y,\n  mul_assoc := \u03bb X Y Z, inter_assoc X Y Z,\n  one := \u22a4,\n  one_mul := \u03bb X, top_inter X,\n  mul_one := \u03bb X, inter_top X,\n  left_distrib := \u03bb X Y Z, symm_diff_distrib_inter_left X Y Z,\n  right_distrib := \u03bb X Y Z, symm_diff_distrib_inter_right X Y Z, \n  mul_comm := \u03bb X Y, inter_comm X Y, \n}\n\n\nlemma one_plus (X : A) : 1 + X = X\u1d9c := \n  top_symm_diff X \n\nlemma plus_one (X : A) : X + 1 = X\u1d9c := \n  by {rw add_comm, from one_plus X} \n\nlemma top_to_boolalg : (\u22a4 : A) = (1 : A) := rfl\n\nlemma bot_to_boolalg : (\u22a5 : A) = (0 : A) := rfl\n\nlemma symm_diff_to_boolalg {X Y : A} :  (X \\ Y) \u222a (Y \\ X) = X + Y := rfl \n\nlemma inter_to_boolalg {X Y : A} : X \u2229 Y = X * Y := rfl \n\nlemma union_to_boolalg {X Y : A} : X \u222a Y = (X + Y) + X*Y := \n  begin \n    rw [add_assoc], \n    nth_rewrite 1 \u2190one_mul Y, \n    rw [\u2190right_distrib, one_plus, \u2190symm_diff_to_boolalg, \u2190inter_to_boolalg, diff_eq, diff_eq, inter_right_comm, compl_inter],\n    simp,\n  end \n\nlemma compl_to_boolalg {X : A} : X\u1d9c = X + 1 := \n  (plus_one X).symm \n\nlemma subset_to_boolalg {X Y : A} : X \u2286 Y \u2194 X*Y = X := \n  by {rw \u2190inter_to_boolalg, exact subset_iff_inter_eq_left X Y} \n\nlemma diff_to_boolalg {X Y : A} : X \\ Y = X*(Y + 1) := \n  by rw [plus_one, \u2190inter_to_boolalg, diff_eq]\n\n\n\n\nmk_simp_attribute ba_simp \"ba_simplg\"\n\n@[simp, ba_simp] lemma times_idem (X : A) : X*X = X := inter_idem X \n@[simp, ba_simp] lemma plus_zero (X : A) : X+0 = X := add_zero X \n@[simp, ba_simp] lemma zero_plus (X : A) : 0+X = X := zero_add X   \n@[simp, ba_simp] lemma times_zero (X : A) : X*0 = 0 := inter_bot X \n@[simp, ba_simp] lemma zero_times (X : A) : 0*X = 0 := bot_inter X\n@[simp, ba_simp] lemma times_one (X : A) : X*1 = X := inter_top X \n@[simp, ba_simp] lemma one_times (X : A) : 1*X = X := top_inter X \n@[simp, ba_simp] lemma times_comm (X Y : A) : X*Y = Y*X := mul_comm X Y \n@[simp, ba_simp] lemma times_assoc (X Y Z : A) : X*Y*Z = X*(Y*Z) := mul_assoc X Y Z\n@[simp, ba_simp] lemma plus_comm (X Y : A) : X+Y=Y+X := add_comm X Y\n@[simp, ba_simp] lemma plus_assoc (X Y Z : A) : X+Y+Z = X+(Y+Z)  := add_assoc X Y Z\n\n@[simp, ba_simp] lemma rmult_cancel (X Y : A) : X*(X*Y) = X*Y := \n  by rw [\u2190mul_assoc, times_idem]\n\n\n@[simp] lemma two_eq_zero : (2 : A) = (0 : A) := \n  begin\n    have : (1:A) + (1:A) = (2:A) := rfl, rw \u2190this,\n    rw [one_plus, \u2190top_to_boolalg, \u2190bot_to_boolalg],\n    simp, \n  end\n\n\n@[simp, ba_simp] lemma two_times (X : A) : 2*X = 0 := by simp\n\n@[simp, ba_simp] lemma times_two (X : A) : X*2 = 0 := by simp\n\n\nlemma neg_self (X : A) : X = -X := \n  by {have := calc X + X = X*2 : by ring ... = 0 : by simp, ring, }\n\n@[simp, ba_simp] lemma plus_self (X : A) : X + X = 0 := \n  by {ring SOP, rw two_eq_zero, ring}\n\n@[simp, ba_simp] lemma plus_self_left (X Y : A) : X + (X + Y )= Y := \n  by {ring, rw two_eq_zero, ring}\n\n@[simp, ba_simp] lemma power_cancel (X : A) (n : nat) : X^(n.succ) = X := \n  by {induction n with n IH, ring, rw [pow_succ' X (nat.succ n), IH, times_idem] }\n\n@[simp, ba_simp] lemma distrib_cancel (X Y : A) : X*Y + X*(Y+1) = X := \n  by {rw[\u2190left_distrib], simp only [plus_self_left, times_one]} \n\n\n--@[simp, ba_simp] lemma one_sandwich (X : A) : 1 + (X+1) = X := sorry \n\n\n--@[simp, ba_simp] lemma mul_cancel_left (S X: A) : S*(S*X) = S*X := sorry \n\n\n\nlemma one_side {X Y : A} : X = Y \u2194 X + Y = 0 := \n  by {refine \u27e8\u03bb h, by{rw h, simp}, \u03bb h, _\u27e9, rw (eq_neg_of_add_eq_zero h), exact (neg_self Y).symm }\n\n@[simp, ba_simp] lemma prod_comp_cancel (X : A) : X*(X+1) = 0 := \n  by {ring SOP, simp }\n  \nlemma expand_product {X\u2081 X\u2082 Y\u2081 Y\u2082 S : A} : (X\u2081 * S + X\u2082 * (S+1)) * (Y\u2081 * S + Y\u2082 * (S+1)) = X\u2081 * Y\u2081 * S + X\u2082 * Y\u2082 * (S+1) :=\n  by {apply one_side.mpr, ring, ring SOP, simp only with ba_simp, ring, simp}\n\n\nmeta def set_to_ring_eqn : tactic unit := do\n`[try {simp only\n    [top_to_boolalg, bot_to_boolalg, symm_diff_to_boolalg, inter_to_boolalg, union_to_boolalg, \n      diff_to_boolalg, compl_to_boolalg, subset_to_boolalg] at *}]\n\n/-\nmeta def normalize_boolalg_eqns : tactic unit := do\n  `[set_to_ring_eqn,\n    try {apply one_side.mpr},\n    ring SOP]\nmeta def simp_only_ba_simp : tactic unit :=\n  do `[simp only with ba_simp]\nmeta def simp_ba_simp : tactic unit :=\n  do `[simp with ba_simp]\n--meta def simp_ba_simp_hyp : tactic unit :=\n-/", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old/boolalg_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.723691074941895}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n\n! This file was ported from Lean 3 source module number_theory.divisors\n! leanprover-community/mathlib commit f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Data.Nat.Interval\nimport Mathlib.Data.Nat.Factors\n\n/-!\n# Divisor Finsets\n\nThis file defines sets of divisors of a natural number. This is particularly useful as background\nfor defining Dirichlet convolution.\n\n## Main Definitions\nLet `n : \u2115`. All of the following definitions are in the `Nat` namespace:\n * `divisors n` is the `Finset` of natural numbers that divide `n`.\n * `properDivisors n` is the `Finset` of natural numbers that divide `n`, other than `n`.\n * `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`.\n * `perfect n` is true when `n` is positive and the sum of `properDivisors n` is `n`.\n\n## Implementation details\n * `divisors 0`, `properDivisors 0`, and `divisorsAntidiagonal 0` are defined to be `\u2205`.\n\n## Tags\ndivisors, perfect numbers\n\n-/\n\n\nopen BigOperators Classical Finset\n\nnamespace Nat\n\nvariable (n : \u2115)\n\n/-- `divisors n` is the `Finset` of divisors of `n`. As a special case, `divisors 0 = \u2205`. -/\ndef divisors : Finset \u2115 :=\n  Finset.filter (fun x : \u2115 => x \u2223 n) (Finset.Ico 1 (n + 1))\n#align nat.divisors Nat.divisors\n\n/-- `properDivisors n` is the `Finset` of divisors of `n`, other than `n`.\n  As a special case, `properDivisors 0 = \u2205`. -/\ndef properDivisors : Finset \u2115 :=\n  Finset.filter (fun x : \u2115 => x \u2223 n) (Finset.Ico 1 n)\n#align nat.proper_divisors Nat.properDivisors\n\n/-- `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`.\n  As a special case, `divisorsAntidiagonal 0 = \u2205`. -/\ndef divisorsAntidiagonal : Finset (\u2115 \u00d7 \u2115) :=\n  Finset.filter (fun x => x.fst * x.snd = n) (Ico 1 (n + 1) \u00d7\u1da0 Ico 1 (n + 1))\n#align nat.divisors_antidiagonal Nat.divisorsAntidiagonal\n\nvariable {n}\n\n@[simp]\ntheorem filter_dvd_eq_divisors (h : n \u2260 0) : (Finset.range n.succ).filter (\u00b7 \u2223 n) = n.divisors := by\n  ext\n  simp only [divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]\n  exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)\n#align nat.filter_dvd_eq_divisors Nat.filter_dvd_eq_divisors\n\n@[simp]\ntheorem filter_dvd_eq_properDivisors (h : n \u2260 0) :\n    (Finset.range n).filter (\u00b7 \u2223 n) = n.properDivisors := by\n  ext\n  simp only [properDivisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]\n  exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)\n#align nat.filter_dvd_eq_proper_divisors Nat.filter_dvd_eq_properDivisors\n\ntheorem properDivisors.not_self_mem : \u00acn \u2208 properDivisors n := by simp [properDivisors]\n#align nat.proper_divisors.not_self_mem Nat.properDivisors.not_self_mem\n\n@[simp]\ntheorem mem_properDivisors {m : \u2115} : n \u2208 properDivisors m \u2194 n \u2223 m \u2227 n < m := by\n  rcases eq_or_ne m 0 with (rfl | hm); \u00b7 simp [properDivisors]\n  simp only [and_comm, \u2190 filter_dvd_eq_properDivisors hm, mem_filter, mem_range]\n#align nat.mem_proper_divisors Nat.mem_properDivisors\n\ntheorem insert_self_properDivisors (h : n \u2260 0) : insert n (properDivisors n) = divisors n := by\n  rw [divisors, properDivisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h),\n    Finset.filter_insert, if_pos (dvd_refl n)]\n#align nat.insert_self_proper_divisors Nat.insert_self_properDivisors\n\ntheorem cons_self_properDivisors (h : n \u2260 0) :\n    cons n (properDivisors n) properDivisors.not_self_mem = divisors n := by\n  rw [cons_eq_insert, insert_self_properDivisors h]\n#align nat.cons_self_proper_divisors Nat.cons_self_properDivisors\n\n@[simp]\ntheorem mem_divisors {m : \u2115} : n \u2208 divisors m \u2194 n \u2223 m \u2227 m \u2260 0 := by\n  rcases eq_or_ne m 0 with (rfl | hm); \u00b7 simp [divisors]\n  simp only [hm, Ne.def, not_false_iff, and_true_iff, \u2190 filter_dvd_eq_divisors hm, mem_filter,\n    mem_range, and_iff_right_iff_imp, lt_succ_iff]\n  exact le_of_dvd hm.bot_lt\n#align nat.mem_divisors Nat.mem_divisors\n\ntheorem one_mem_divisors : 1 \u2208 divisors n \u2194 n \u2260 0 := by simp\n#align nat.one_mem_divisors Nat.one_mem_divisors\n\ntheorem mem_divisors_self (n : \u2115) (h : n \u2260 0) : n \u2208 n.divisors :=\n  mem_divisors.2 \u27e8dvd_rfl, h\u27e9\n#align nat.mem_divisors_self Nat.mem_divisors_self\n\ntheorem dvd_of_mem_divisors {m : \u2115} (h : n \u2208 divisors m) : n \u2223 m := by\n  cases m\n  \u00b7 apply dvd_zero\n  \u00b7 simp [mem_divisors.1 h]\n#align nat.dvd_of_mem_divisors Nat.dvd_of_mem_divisors\n\n@[simp]\ntheorem mem_divisorsAntidiagonal {x : \u2115 \u00d7 \u2115} :\n    x \u2208 divisorsAntidiagonal n \u2194 x.fst * x.snd = n \u2227 n \u2260 0 := by\n  simp only [divisorsAntidiagonal, Finset.mem_Ico, Ne.def, Finset.mem_filter, Finset.mem_product]\n  rw [and_comm]\n  apply and_congr_right\n  rintro rfl\n  constructor <;> intro h\n  \u00b7 contrapose! h\n    simp [h]\n  \u00b7 rw [Nat.lt_add_one_iff, Nat.lt_add_one_iff]\n    rw [mul_eq_zero, not_or] at h\n    simp only [succ_le_of_lt (Nat.pos_of_ne_zero h.1), succ_le_of_lt (Nat.pos_of_ne_zero h.2),\n      true_and_iff]\n    exact\n      \u27e8le_mul_of_pos_right (Nat.pos_of_ne_zero h.2), le_mul_of_pos_left (Nat.pos_of_ne_zero h.1)\u27e9\n#align nat.mem_divisors_antidiagonal Nat.mem_divisorsAntidiagonal\n\n-- Porting note: Redundant binder annotation update\n-- variable {n}\n\ntheorem divisor_le {m : \u2115} : n \u2208 divisors m \u2192 n \u2264 m := by\n  cases' m with m\n  \u00b7 simp\n  \u00b7 simp only [mem_divisors, Nat.succ_ne_zero m, and_true_iff, Ne.def, not_false_iff]\n    exact Nat.le_of_dvd (Nat.succ_pos m)\n#align nat.divisor_le Nat.divisor_le\n\ntheorem divisors_subset_of_dvd {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) : divisors m \u2286 divisors n :=\n  Finset.subset_iff.2 fun _x hx => Nat.mem_divisors.mpr \u27e8(Nat.mem_divisors.mp hx).1.trans h, hzero\u27e9\n#align nat.divisors_subset_of_dvd Nat.divisors_subset_of_dvd\n\ntheorem divisors_subset_properDivisors {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) (hdiff : m \u2260 n) :\n    divisors m \u2286 properDivisors n := by\n  apply Finset.subset_iff.2\n  intro x hx\n  exact\n    Nat.mem_properDivisors.2\n      \u27e8(Nat.mem_divisors.1 hx).1.trans h,\n        lt_of_le_of_lt (divisor_le hx)\n          (lt_of_le_of_ne (divisor_le (Nat.mem_divisors.2 \u27e8h, hzero\u27e9)) hdiff)\u27e9\n#align nat.divisors_subset_proper_divisors Nat.divisors_subset_properDivisors\n\n@[simp]\ntheorem divisors_zero : divisors 0 = \u2205 := by\n  ext\n  simp\n#align nat.divisors_zero Nat.divisors_zero\n\n@[simp]\ntheorem properDivisors_zero : properDivisors 0 = \u2205 := by\n  ext\n  simp\n#align nat.proper_divisors_zero Nat.properDivisors_zero\n\ntheorem properDivisors_subset_divisors : properDivisors n \u2286 divisors n :=\n  filter_subset_filter _ <| Ico_subset_Ico_right n.le_succ\n#align nat.proper_divisors_subset_divisors Nat.properDivisors_subset_divisors\n\n@[simp]\ntheorem divisors_one : divisors 1 = {1} := by\n  ext\n  simp\n#align nat.divisors_one Nat.divisors_one\n\n@[simp]\n\n\ntheorem pos_of_mem_divisors {m : \u2115} (h : m \u2208 n.divisors) : 0 < m := by\n  cases m\n  \u00b7 rw [mem_divisors, zero_eq, zero_dvd_iff (a := n)] at h\n    cases h.2 h.1\n  apply Nat.succ_pos\n#align nat.pos_of_mem_divisors Nat.pos_of_mem_divisors\n\ntheorem pos_of_mem_properDivisors {m : \u2115} (h : m \u2208 n.properDivisors) : 0 < m :=\n  pos_of_mem_divisors (properDivisors_subset_divisors h)\n#align nat.pos_of_mem_proper_divisors Nat.pos_of_mem_properDivisors\n\ntheorem one_mem_properDivisors_iff_one_lt : 1 \u2208 n.properDivisors \u2194 1 < n := by\n  rw [mem_properDivisors, and_iff_right (one_dvd _)]\n#align nat.one_mem_proper_divisors_iff_one_lt Nat.one_mem_properDivisors_iff_one_lt\n\n@[simp]\ntheorem divisorsAntidiagonal_zero : divisorsAntidiagonal 0 = \u2205 := by\n  ext\n  simp\n#align nat.divisors_antidiagonal_zero Nat.divisorsAntidiagonal_zero\n\n@[simp]\ntheorem divisorsAntidiagonal_one : divisorsAntidiagonal 1 = {(1, 1)} := by\n  ext\n  simp [Nat.mul_eq_one_iff, Prod.ext_iff]\n#align nat.divisors_antidiagonal_one Nat.divisorsAntidiagonal_one\n\n/- Porting note: simpnf linter; added aux lemma below\nLeft-hand side simplifies from\n  Prod.swap x \u2208 Nat.divisorsAntidiagonal n\nto\n  x.snd * x.fst = n \u2227 \u00acn = 0-/\n-- @[simp]\ntheorem swap_mem_divisorsAntidiagonal {x : \u2115 \u00d7 \u2115} :\n    x.swap \u2208 divisorsAntidiagonal n \u2194 x \u2208 divisorsAntidiagonal n := by\n  rw [mem_divisorsAntidiagonal, mem_divisorsAntidiagonal, mul_comm, Prod.swap]\n#align nat.swap_mem_divisors_antidiagonal Nat.swap_mem_divisorsAntidiagonal\n\n-- Porting note: added below thm to replace the simp from the previous thm\n@[simp]\ntheorem swap_mem_divisorsAntidiagonal_aux {x : \u2115 \u00d7 \u2115} :\n    x.snd * x.fst = n \u2227 \u00acn = 0 \u2194 x \u2208 divisorsAntidiagonal n := by\n  rw [mem_divisorsAntidiagonal, mul_comm]\n\ntheorem fst_mem_divisors_of_mem_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisorsAntidiagonal n) :\n    x.fst \u2208 divisors n := by\n  rw [mem_divisorsAntidiagonal] at h\n  simp [Dvd.intro _ h.1, h.2]\n#align nat.fst_mem_divisors_of_mem_antidiagonal Nat.fst_mem_divisors_of_mem_antidiagonal\n\ntheorem snd_mem_divisors_of_mem_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisorsAntidiagonal n) :\n    x.snd \u2208 divisors n := by\n  rw [mem_divisorsAntidiagonal] at h\n  simp [Dvd.intro_left _ h.1, h.2]\n#align nat.snd_mem_divisors_of_mem_antidiagonal Nat.snd_mem_divisors_of_mem_antidiagonal\n\n@[simp]\ntheorem map_swap_divisorsAntidiagonal :\n    (divisorsAntidiagonal n).map (Equiv.prodComm _ _).toEmbedding = divisorsAntidiagonal n := by\n  rw [\u2190 coe_inj, coe_map, Equiv.coe_toEmbedding, Equiv.coe_prodComm,\n    Set.image_swap_eq_preimage_swap]\n  ext\n  exact swap_mem_divisorsAntidiagonal\n#align nat.map_swap_divisors_antidiagonal Nat.map_swap_divisorsAntidiagonal\n\n@[simp]\ntheorem image_fst_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.fst = divisors n := by\n  ext\n  simp [Dvd.dvd, @eq_comm _ n (_ * _)]\n#align nat.image_fst_divisors_antidiagonal Nat.image_fst_divisorsAntidiagonal\n\n@[simp]\ntheorem image_snd_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.snd = divisors n := by\n  rw [\u2190 map_swap_divisorsAntidiagonal, map_eq_image, image_image]\n  exact image_fst_divisorsAntidiagonal\n#align nat.image_snd_divisors_antidiagonal Nat.image_snd_divisorsAntidiagonal\n\ntheorem map_div_right_divisors :\n    n.divisors.map \u27e8fun d => (d, n / d), fun p\u2081 p\u2082 => congr_arg Prod.fst\u27e9 =\n      n.divisorsAntidiagonal := by\n  ext \u27e8d, nd\u27e9\n  simp only [mem_map, mem_divisorsAntidiagonal, Function.Embedding.coeFn_mk, mem_divisors,\n    Prod.ext_iff, exists_prop, and_left_comm, exists_eq_left]\n  constructor\n  \u00b7 rintro \u27e8\u27e8\u27e8k, rfl\u27e9, hn\u27e9, rfl\u27e9\n    rw [Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt]\n    exact \u27e8rfl, hn\u27e9\n  \u00b7 rintro \u27e8rfl, hn\u27e9\n    exact \u27e8\u27e8dvd_mul_right _ _, hn\u27e9, Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt\u27e9\n#align nat.map_div_right_divisors Nat.map_div_right_divisors\n\ntheorem map_div_left_divisors :\n    n.divisors.map \u27e8fun d => (n / d, d), fun p\u2081 p\u2082 => congr_arg Prod.snd\u27e9 =\n      n.divisorsAntidiagonal := by\n  apply Finset.map_injective (Equiv.prodComm _ _).toEmbedding\n  rw [map_swap_divisorsAntidiagonal, \u2190 map_div_right_divisors, Finset.map_map]\n  rfl\n#align nat.map_div_left_divisors Nat.map_div_left_divisors\n\ntheorem sum_divisors_eq_sum_properDivisors_add_self :\n    (\u2211 i in divisors n, i) = (\u2211 i in properDivisors n, i) + n := by\n  rcases Decidable.eq_or_ne n 0 with (rfl | hn)\n  \u00b7 simp\n  \u00b7 rw [\u2190 cons_self_properDivisors hn, Finset.sum_cons, add_comm]\n#align\n  nat.sum_divisors_eq_sum_proper_divisors_add_self\n  Nat.sum_divisors_eq_sum_properDivisors_add_self\n\n/-- `n : \u2115` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`\n  is positive. -/\ndef Perfect (n : \u2115) : Prop :=\n  (\u2211 i in properDivisors n, i) = n \u2227 0 < n\n#align nat.perfect Nat.Perfect\n\ntheorem perfect_iff_sum_properDivisors (h : 0 < n) : Perfect n \u2194 (\u2211 i in properDivisors n, i) = n :=\n  and_iff_left h\n#align nat.perfect_iff_sum_proper_divisors Nat.perfect_iff_sum_properDivisors\n\ntheorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) :\n    Perfect n \u2194 (\u2211 i in divisors n, i) = 2 * n := by\n  rw [perfect_iff_sum_properDivisors h, sum_divisors_eq_sum_properDivisors_add_self, two_mul]\n  constructor <;> intro h\n  \u00b7 rw [h]\n  \u00b7 apply add_right_cancel h\n#align nat.perfect_iff_sum_divisors_eq_two_mul Nat.perfect_iff_sum_divisors_eq_two_mul\n\ntheorem mem_divisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) {x : \u2115} :\n    x \u2208 divisors (p ^ k) \u2194 \u2203 (j : \u2115) (_ : j \u2264 k), x = p ^ j := by\n  rw [mem_divisors, Nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))]\n  simp\n#align nat.mem_divisors_prime_pow Nat.mem_divisors_prime_pow\n\ntheorem Prime.divisors {p : \u2115} (pp : p.Prime) : divisors p = {1, p} := by\n  ext\n  rw [mem_divisors, dvd_prime pp, and_iff_left pp.ne_zero, Finset.mem_insert, Finset.mem_singleton]\n#align nat.prime.divisors Nat.Prime.divisors\n\ntheorem Prime.properDivisors {p : \u2115} (pp : p.Prime) : properDivisors p = {1} := by\n  rw [\u2190 erase_insert properDivisors.not_self_mem, insert_self_properDivisors pp.ne_zero,\n    pp.divisors, pair_comm, erase_insert fun con => pp.ne_one (mem_singleton.1 con)]\n#align nat.prime.proper_divisors Nat.Prime.properDivisors\n\n-- Porting note: Specified pow to Nat.pow\ntheorem divisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) :\n    divisors (p ^ k) = (Finset.range (k + 1)).map \u27e8Nat.pow p, pow_right_injective pp.two_le\u27e9 := by\n  ext a\n  simp only [mem_divisors, mem_map, mem_range, lt_succ_iff, Function.Embedding.coeFn_mk, Nat.pow_eq,\n    mem_divisors_prime_pow pp k]\n  have := mem_divisors_prime_pow pp k (x := a)\n  rw [mem_divisors] at this\n  rw [this]\n  refine \u27e8?_, ?_\u27e9\n  \u00b7 intro h; rcases h with \u27e8x, hx, hap\u27e9; use x; tauto\n  \u00b7 tauto\n#align nat.divisors_prime_pow Nat.divisors_prime_pow\n\ntheorem eq_properDivisors_of_subset_of_sum_eq_sum {s : Finset \u2115} (hsub : s \u2286 n.properDivisors) :\n    ((\u2211 x in s, x) = \u2211 x in n.properDivisors, x) \u2192 s = n.properDivisors := by\n  cases n\n  \u00b7 rw [properDivisors_zero, subset_empty] at hsub\n    simp [hsub]\n  classical\n    rw [\u2190 sum_sdiff hsub]\n    intro h\n    apply Subset.antisymm hsub\n    rw [\u2190 sdiff_eq_empty_iff_subset]\n    contrapose h\n    rw [\u2190 Ne.def, \u2190 nonempty_iff_ne_empty] at h\n    apply ne_of_lt\n    rw [\u2190 zero_add (\u2211 x in s, x), \u2190 add_assoc, add_zero]\n    apply add_lt_add_right\n    have hlt :=\n      sum_lt_sum_of_nonempty h fun x hx => pos_of_mem_properDivisors (sdiff_subset _ _ hx)\n    simp only [sum_const_zero] at hlt\n    apply hlt\n#align nat.eq_proper_divisors_of_subset_of_sum_eq_sum Nat.eq_properDivisors_of_subset_of_sum_eq_sum\n\ntheorem sum_properDivisors_dvd (h : (\u2211 x in n.properDivisors, x) \u2223 n) :\n    (\u2211 x in n.properDivisors, x) = 1 \u2228 (\u2211 x in n.properDivisors, x) = n := by\n  cases' n with n\n  \u00b7 simp\n  \u00b7 cases' n with n\n    \u00b7 contrapose! h\n      simp\n    \u00b7 rw [or_iff_not_imp_right]\n      intro ne_n\n      have hlt : (\u2211 x in n.succ.succ.properDivisors, x) < n.succ.succ :=\n        lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h) ne_n\n      symm\n      rw [\u2190 mem_singleton,\n        eq_properDivisors_of_subset_of_sum_eq_sum\n          (singleton_subset_iff.2 (mem_properDivisors.2 \u27e8h, hlt\u27e9)) sum_singleton,\n        mem_properDivisors]\n      refine' \u27e8one_dvd _, Nat.succ_lt_succ (Nat.succ_pos _)\u27e9\n#align nat.sum_proper_divisors_dvd Nat.sum_properDivisors_dvd\n\n@[to_additive (attr := simp)]\ntheorem Prime.prod_properDivisors {\u03b1 : Type _} [CommMonoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.Prime) :\n    (\u220f x in p.properDivisors, f x) = f 1 := by simp [h.properDivisors]\n#align nat.prime.prod_proper_divisors Nat.Prime.prod_properDivisors\n#align nat.prime.sum_proper_divisors Nat.Prime.sum_properDivisors\n\n@[to_additive (attr := simp)]\ntheorem Prime.prod_divisors {\u03b1 : Type _} [CommMonoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.Prime) :\n    (\u220f x in p.divisors, f x) = f p * f 1 := by\n  rw [\u2190 cons_self_properDivisors h.ne_zero, prod_cons, h.prod_properDivisors]\n#align nat.prime.prod_divisors Nat.Prime.prod_divisors\n#align nat.prime.sum_divisors Nat.Prime.sum_divisors\n\ntheorem properDivisors_eq_singleton_one_iff_prime : n.properDivisors = {1} \u2194 n.Prime := by\n  refine \u27e8?_, ?_\u27e9\n  \u00b7 intro h\n    refine' Nat.prime_def_lt''.mpr \u27e8_, fun m hdvd => _\u27e9\n    \u00b7 match n with\n      | 0 => contradiction\n      | 1 => contradiction\n      | Nat.succ (Nat.succ n) => simp [succ_le_succ]\n    \u00b7 rw [\u2190 mem_singleton, \u2190 h, mem_properDivisors]\n      have := Nat.le_of_dvd ?_ hdvd\n      \u00b7 simp [hdvd, this]\n        exact (le_iff_eq_or_lt.mp this).symm\n      \u00b7 by_contra'\n        simp [nonpos_iff_eq_zero.mp this, this] at h\n  \u00b7 exact fun h => Prime.properDivisors h\n#align nat.proper_divisors_eq_singleton_one_iff_prime Nat.properDivisors_eq_singleton_one_iff_prime\n\ntheorem sum_properDivisors_eq_one_iff_prime : (\u2211 x in n.properDivisors, x) = 1 \u2194 n.Prime := by\n  cases' n with n\n  \u00b7 simp [Nat.not_prime_zero]\n  \u00b7 cases n\n    \u00b7 simp [Nat.not_prime_one]\n    \u00b7 rw [\u2190 properDivisors_eq_singleton_one_iff_prime]\n      refine' \u27e8fun h => _, fun h => h.symm \u25b8 sum_singleton\u27e9\n      rw [@eq_comm (Finset \u2115) _ _]\n      apply\n        eq_properDivisors_of_subset_of_sum_eq_sum\n          (singleton_subset_iff.2\n            (one_mem_properDivisors_iff_one_lt.2 (succ_lt_succ (Nat.succ_pos _))))\n          (Eq.trans sum_singleton h.symm)\n#align nat.sum_proper_divisors_eq_one_iff_prime Nat.sum_properDivisors_eq_one_iff_prime\n\ntheorem mem_properDivisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) {x : \u2115} :\n    x \u2208 properDivisors (p ^ k) \u2194 \u2203 (j : \u2115) (_ : j < k), x = p ^ j := by\n  rw [mem_properDivisors, Nat.dvd_prime_pow pp, \u2190 exists_and_right]\n  simp only [exists_prop, and_assoc]\n  apply exists_congr\n  intro a\n  constructor <;> intro h\n  \u00b7 rcases h with \u27e8_h_left, rfl, h_right\u27e9\n    rw [pow_lt_pow_iff pp.one_lt] at h_right\n    exact \u27e8h_right, by rfl\u27e9\n  \u00b7 rcases h with \u27e8h_left, rfl\u27e9\n    rw [pow_lt_pow_iff pp.one_lt]\n    simp [h_left, le_of_lt]\n#align nat.mem_proper_divisors_prime_pow Nat.mem_properDivisors_prime_pow\n\n-- Porting note: Specified pow to Nat.pow\ntheorem properDivisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) :\n    properDivisors (p ^ k) = (Finset.range k).map \u27e8Nat.pow p, pow_right_injective pp.two_le\u27e9 := by\n  ext a\n  simp only [mem_properDivisors, Nat.isUnit_iff, mem_map, mem_range, Function.Embedding.coeFn_mk,\n    pow_eq]\n  have := mem_properDivisors_prime_pow pp k (x := a)\n  rw [mem_properDivisors] at this\n  rw [this]\n  refine \u27e8?_, ?_\u27e9\n  \u00b7 intro h; rcases h with \u27e8j, hj, hap\u27e9; use j; tauto\n  \u00b7 tauto\n#align nat.proper_divisors_prime_pow Nat.properDivisors_prime_pow\n\n@[to_additive (attr := simp)]\ntheorem prod_properDivisors_prime_pow {\u03b1 : Type _} [CommMonoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1}\n    (h : p.Prime) : (\u220f x in (p ^ k).properDivisors, f x) = \u220f x in range k, f (p ^ x) := by\n  simp [h, properDivisors_prime_pow]\n#align nat.prod_proper_divisors_prime_pow Nat.prod_properDivisors_prime_pow\n#align nat.sum_proper_divisors_prime_nsmul Nat.sum_properDivisors_prime_nsmul\n\n@[to_additive (attr := simp) sum_divisors_prime_pow]\ntheorem prod_divisors_prime_pow {\u03b1 : Type _} [CommMonoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.Prime) :\n    (\u220f x in (p ^ k).divisors, f x) = \u220f x in range (k + 1), f (p ^ x) := by\n  simp [h, divisors_prime_pow]\n#align nat.prod_divisors_prime_pow Nat.prod_divisors_prime_pow\n#align nat.sum_divisors_prime_pow Nat.sum_divisors_prime_pow\n\n@[to_additive]\ntheorem prod_divisorsAntidiagonal {M : Type _} [CommMonoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n    (\u220f i in n.divisorsAntidiagonal, f i.1 i.2) = \u220f i in n.divisors, f i (n / i) := by\n  rw [\u2190 map_div_right_divisors, Finset.prod_map]\n  rfl\n#align nat.prod_divisors_antidiagonal Nat.prod_divisorsAntidiagonal\n#align nat.sum_divisors_antidiagonal Nat.sum_divisorsAntidiagonal\n\n@[to_additive]\ntheorem prod_divisorsAntidiagonal' {M : Type _} [CommMonoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n    (\u220f i in n.divisorsAntidiagonal, f i.1 i.2) = \u220f i in n.divisors, f (n / i) i := by\n  rw [\u2190 map_swap_divisorsAntidiagonal, Finset.prod_map]\n  exact prod_divisorsAntidiagonal fun i j => f j i\n#align nat.prod_divisors_antidiagonal' Nat.prod_divisorsAntidiagonal'\n#align nat.sum_divisors_antidiagonal' Nat.sum_divisorsAntidiagonal'\n\n/-- The factors of `n` are the prime divisors -/\ntheorem prime_divisors_eq_to_filter_divisors_prime (n : \u2115) :\n    n.factors.toFinset = (divisors n).filter Prime := by\n  rcases n.eq_zero_or_pos with (rfl | hn)\n  \u00b7 simp\n  \u00b7 ext q\n    simpa [hn, hn.ne', mem_factors] using and_comm\n#align nat.prime_divisors_eq_to_filter_divisors_prime Nat.prime_divisors_eq_to_filter_divisors_prime\n\n@[simp]\ntheorem image_div_divisors_eq_divisors (n : \u2115) :\n    image (fun x : \u2115 => n / x) n.divisors = n.divisors := by\n  by_cases hn : n = 0\n  \u00b7 simp [hn]\n  ext a\n  constructor\n  \u00b7 rw [mem_image]\n    rintro \u27e8x, hx1, hx2\u27e9\n    rw [mem_divisors] at *\n    refine' \u27e8_, hn\u27e9\n    rw [\u2190 hx2]\n    exact div_dvd_of_dvd hx1.1\n  \u00b7 rw [mem_divisors, mem_image]\n    rintro \u27e8h1, -\u27e9\n    exact \u27e8n / a, mem_divisors.mpr \u27e8div_dvd_of_dvd h1, hn\u27e9, Nat.div_div_self h1 hn\u27e9\n#align nat.image_div_divisors_eq_divisors Nat.image_div_divisors_eq_divisors\n\n/- Porting note: Removed simp; simp_nf linter:\nLeft-hand side does not simplify, when using the simp lemma on itself.\nThis usually means that it will never apply. -/\n@[to_additive sum_div_divisors]\ntheorem prod_div_divisors {\u03b1 : Type _} [CommMonoid \u03b1] (n : \u2115) (f : \u2115 \u2192 \u03b1) :\n    (\u220f d in n.divisors, f (n / d)) = n.divisors.prod f := by\n  by_cases hn : n = 0; \u00b7 simp [hn]\n  rw [\u2190 prod_image]\n  \u00b7 exact prod_congr (image_div_divisors_eq_divisors n) (by simp)\n  \u00b7 intro x hx y hy h\n    rw [mem_divisors] at hx hy\n    exact (div_eq_iff_eq_of_dvd_dvd hn hx.1 hy.1).mp h\n#align nat.prod_div_divisors Nat.prod_div_divisors\n#align nat.sum_div_divisors Nat.sum_div_divisors\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/NumberTheory/Divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7236910732719766}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module algebra.regular.basic\n! leanprover-community/mathlib commit 5cd3c25312f210fec96ba1edb2aebfb2ccf2010f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Commute\nimport Mathlib.Algebra.Order.Monoid.Lemmas\nimport Mathlib.Algebra.GroupWithZero.Basic\n\n/-!\n# Regular elements\n\nWe introduce left-regular, right-regular and regular elements, along with their `to_additive`\nanalogues add-left-regular, add-right-regular and add-regular elements.\n\nBy definition, a regular element in a commutative ring is a non-zero divisor.\nLemma `isRegular_of_ne_zero` implies that every non-zero element of an integral domain is regular.\nSince it assumes that the ring is a `CancelMonoidWithZero` it applies also, for instance, to `\u2115`.\n\nThe lemmas in Section `MulZeroClass` show that the `0` element is (left/right-)regular if and\nonly if the `MulZeroClass` is trivial.  This is useful when figuring out stopping conditions for\nregular sequences: if `0` is ever an element of a regular sequence, then we can extend the sequence\nby adding one further `0`.\n\nThe final goal is to develop part of the API to prove, eventually, results about non-zero-divisors.\n-/\n\n\nvariable {R : Type _}\n\nsection Mul\n\nvariable [Mul R]\n\n/-- A left-regular element is an element `c` such that multiplication on the left by `c`\nis injective. -/\n@[to_additive \"An add-left-regular element is an element `c` such that addition\n    on the left by `c` is injective.\"]\ndef IsLeftRegular (c : R) :=\n  (c * \u00b7).Injective\n#align is_left_regular IsLeftRegular\n#align is_add_left_regular IsAddLeftRegular\n\n/-- A right-regular element is an element `c` such that multiplication on the right by `c`\nis injective. -/\n@[to_additive \"An add-right-regular element is an element `c` such that addition\n    on the right by `c` is injective.\"]\ndef IsRightRegular (c : R) :=\n  (\u00b7 * c).Injective\n#align is_right_regular IsRightRegular\n#align is_add_right_regular IsAddRightRegular\n\n/-- An add-regular element is an element `c` such that addition by `c` both on the left and\non the right is injective. -/\nstructure IsAddRegular {R : Type _} [Add R] (c : R) : Prop where\n  /-- An add-regular element `c` is left-regular -/\n  left : IsAddLeftRegular c -- Porting note: It seems like to_additive is misbehaving\n  /-- An add-regular element `c` is right-regular -/\n  right : IsAddRightRegular c\n#align is_add_regular IsAddRegular\n\n/-- A regular element is an element `c` such that multiplication by `c` both on the left and\non the right is injective. -/\nstructure IsRegular (c : R) : Prop where\n  /-- A regular element `c` is left-regular -/\n  left : IsLeftRegular c\n  /-- A regular element `c` is right-regular -/\n  right : IsRightRegular c\n#align is_regular IsRegular\n\nattribute [to_additive] IsRegular\n\n@[to_additive]\nprotected theorem MulLECancellable.isLeftRegular [PartialOrder R] {a : R}\n    (ha : MulLECancellable a) : IsLeftRegular a :=\n  ha.Injective\n#align mul_le_cancellable.is_left_regular MulLECancellable.isLeftRegular\n#align add_le_cancellable.is_add_left_regular AddLECancellable.isAddLeftRegular\n\ntheorem IsLeftRegular.right_of_commute {a : R}\n    (ca : \u2200 b, Commute a b) (h : IsLeftRegular a) : IsRightRegular a :=\n  fun x y xy => h <| (ca x).trans <| xy.trans <| (ca y).symm\n#align is_left_regular.right_of_commute IsLeftRegular.right_of_commute\n\ntheorem Commute.isRegular_iff {a : R} (ca : \u2200 b, Commute a b) : IsRegular a \u2194 IsLeftRegular a :=\n  \u27e8fun h => h.left, fun h => \u27e8h, h.right_of_commute ca\u27e9\u27e9\n#align commute.is_regular_iff Commute.isRegular_iff\n\nend Mul\n\nsection Semigroup\n\nvariable [Semigroup R] {a b : R}\n\n/-- In a semigroup, the product of left-regular elements is left-regular. -/\n@[to_additive \"In an additive semigroup, the sum of add-left-regular elements is add-left.regular.\"]\ntheorem IsLeftRegular.mul (lra : IsLeftRegular a) (lrb : IsLeftRegular b) : IsLeftRegular (a * b) :=\n  show Function.Injective (((a * b) * \u00b7)) from comp_mul_left a b \u25b8 lra.comp lrb\n#align is_left_regular.mul IsLeftRegular.mul\n#align is_add_left_regular.add IsAddLeftRegular.add\n\n/-- In a semigroup, the product of right-regular elements is right-regular. -/\n@[to_additive \"In an additive semigroup, the sum of add-right-regular elements is\nadd-right-regular.\"]\ntheorem IsRightRegular.mul (rra : IsRightRegular a) (rrb : IsRightRegular b) :\n    IsRightRegular (a * b) :=\n  show Function.Injective (\u00b7 * (a * b)) from comp_mul_right b a \u25b8 rrb.comp rra\n#align is_right_regular.mul IsRightRegular.mul\n#align is_add_right_regular.add IsAddRightRegular.add\n\n/-- If an element `b` becomes left-regular after multiplying it on the left by a left-regular\nelement, then `b` is left-regular. -/\n@[to_additive \"If an element `b` becomes add-left-regular after adding to it on the left\na add-left-regular element, then `b` is add-left-regular.\"]\ntheorem IsLeftRegular.of_mul (ab : IsLeftRegular (a * b)) : IsLeftRegular b :=\n  Function.Injective.of_comp (by rwa [comp_mul_left a b])\n#align is_left_regular.of_mul IsLeftRegular.of_mul\n#align is_add_left_regular.of_add IsAddLeftRegular.of_add\n\n/-- An element is left-regular if and only if multiplying it on the left by a left-regular element\nis left-regular. -/\n@[to_additive (attr := simp) \"An element is add-left-regular if and only if adding to it on the left\na add-left-regular element is add-left-regular.\"]\ntheorem mul_isLeftRegular_iff (b : R) (ha : IsLeftRegular a) :\n    IsLeftRegular (a * b) \u2194 IsLeftRegular b :=\n  \u27e8fun ab => IsLeftRegular.of_mul ab, fun ab => IsLeftRegular.mul ha ab\u27e9\n#align mul_is_left_regular_iff mul_isLeftRegular_iff\n#align add_is_add_left_regular_iff add_isAddLeftRegular_iff\n\n/-- If an element `b` becomes right-regular after multiplying it on the right by a right-regular\nelement, then `b` is right-regular. -/\n@[to_additive \"If an element `b` becomes add-right-regular after adding to it on the right\na add-right-regular element, then `b` is add-right-regular.\"]\ntheorem IsRightRegular.of_mul (ab : IsRightRegular (b * a)) : IsRightRegular b := by\n  refine' fun x y xy => ab (_ : x * (b * a) = y * (b * a))\n  rw [\u2190 mul_assoc, \u2190 mul_assoc]\n  exact congr_fun (congr_arg (\u00b7 * \u00b7) xy) a\n#align is_right_regular.of_mul IsRightRegular.of_mul\n#align is_add_right_regular.of_add IsAddRightRegular.of_add\n\n/-- An element is right-regular if and only if multiplying it on the right with a right-regular\nelement is right-regular. -/\n@[to_additive (attr := simp)\n\"An element is add-right-regular if and only if adding it on the right to\na add-right-regular element is add-right-regular.\"]\ntheorem mul_isRightRegular_iff (b : R) (ha : IsRightRegular a) :\n    IsRightRegular (b * a) \u2194 IsRightRegular b :=\n  \u27e8fun ab => IsRightRegular.of_mul ab, fun ab => IsRightRegular.mul ab ha\u27e9\n#align mul_is_right_regular_iff mul_isRightRegular_iff\n#align add_is_add_right_regular_iff add_isAddRightRegular_iff\n\n/-- Two elements `a` and `b` are regular if and only if both products `a * b` and `b * a`\nare regular. -/\n@[to_additive \"Two elements `a` and `b` are add-regular if and only if both sums `a + b` and\n`b + a` are add-regular.\"]\ntheorem isRegular_mul_and_mul_iff :\n    IsRegular (a * b) \u2227 IsRegular (b * a) \u2194 IsRegular a \u2227 IsRegular b := by\n  refine' \u27e8_, _\u27e9\n  \u00b7 rintro \u27e8ab, ba\u27e9\n    exact\n      \u27e8\u27e8IsLeftRegular.of_mul ba.left, IsRightRegular.of_mul ab.right\u27e9,\n        \u27e8IsLeftRegular.of_mul ab.left, IsRightRegular.of_mul ba.right\u27e9\u27e9\n  \u00b7 rintro \u27e8ha, hb\u27e9\n    exact\n      \u27e8\u27e8(mul_isLeftRegular_iff _ ha.left).mpr hb.left,\n          (mul_isRightRegular_iff _ hb.right).mpr ha.right\u27e9,\n        \u27e8(mul_isLeftRegular_iff _ hb.left).mpr ha.left,\n          (mul_isRightRegular_iff _ ha.right).mpr hb.right\u27e9\u27e9\n#align is_regular_mul_and_mul_iff isRegular_mul_and_mul_iff\n#align is_add_regular_add_and_add_iff isAddRegular_add_and_add_iff\n\n/-- The \"most used\" implication of `mul_and_mul_iff`, with split hypotheses, instead of `\u2227`. -/\n@[to_additive \"The \\\"most used\\\" implication of `add_and_add_iff`, with split\nhypotheses, instead of `\u2227`.\"]\ntheorem IsRegular.and_of_mul_of_mul (ab : IsRegular (a * b)) (ba : IsRegular (b * a)) :\n    IsRegular a \u2227 IsRegular b :=\n  isRegular_mul_and_mul_iff.mp \u27e8ab, ba\u27e9\n#align is_regular.and_of_mul_of_mul IsRegular.and_of_mul_of_mul\n#align is_add_regular.and_of_add_of_add IsAddRegular.and_of_add_of_add\n\nend Semigroup\n\nsection MulZeroClass\n\nvariable [MulZeroClass R] {a b : R}\n\n/-- The element `0` is left-regular if and only if `R` is trivial. -/\ntheorem IsLeftRegular.subsingleton (h : IsLeftRegular (0 : R)) : Subsingleton R :=\n  \u27e8fun a b => h <| Eq.trans (zero_mul a) (zero_mul b).symm\u27e9\n#align is_left_regular.subsingleton IsLeftRegular.subsingleton\n\n/-- The element `0` is right-regular if and only if `R` is trivial. -/\ntheorem IsRightRegular.subsingleton (h : IsRightRegular (0 : R)) : Subsingleton R :=\n  \u27e8fun a b => h <| Eq.trans (mul_zero a) (mul_zero b).symm\u27e9\n#align is_right_regular.subsingleton IsRightRegular.subsingleton\n\n/-- The element `0` is regular if and only if `R` is trivial. -/\ntheorem IsRegular.subsingleton (h : IsRegular (0 : R)) : Subsingleton R :=\n  h.left.subsingleton\n#align is_regular.subsingleton IsRegular.subsingleton\n\n/-- The element `0` is left-regular if and only if `R` is trivial. -/\ntheorem isLeftRegular_zero_iff_subsingleton : IsLeftRegular (0 : R) \u2194 Subsingleton R :=\n  \u27e8fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b\u27e9\n#align is_left_regular_zero_iff_subsingleton isLeftRegular_zero_iff_subsingleton\n\n/-- In a non-trivial `MulZeroClass`, the `0` element is not left-regular. -/\ntheorem not_isLeftRegular_zero_iff : \u00acIsLeftRegular (0 : R) \u2194 Nontrivial R := by\n  rw [nontrivial_iff, not_iff_comm, isLeftRegular_zero_iff_subsingleton, subsingleton_iff]\n  push_neg\n  exact Iff.rfl\n#align not_is_left_regular_zero_iff not_isLeftRegular_zero_iff\n\n/-- The element `0` is right-regular if and only if `R` is trivial. -/\ntheorem isRightRegular_zero_iff_subsingleton : IsRightRegular (0 : R) \u2194 Subsingleton R :=\n  \u27e8fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b\u27e9\n#align is_right_regular_zero_iff_subsingleton isRightRegular_zero_iff_subsingleton\n\n/-- In a non-trivial `MulZeroClass`, the `0` element is not right-regular. -/\ntheorem not_isRightRegular_zero_iff : \u00acIsRightRegular (0 : R) \u2194 Nontrivial R := by\n  rw [nontrivial_iff, not_iff_comm, isRightRegular_zero_iff_subsingleton, subsingleton_iff]\n  push_neg\n  exact Iff.rfl\n#align not_is_right_regular_zero_iff not_isRightRegular_zero_iff\n\n/-- The element `0` is regular if and only if `R` is trivial. -/\ntheorem isRegular_iff_subsingleton : IsRegular (0 : R) \u2194 Subsingleton R :=\n  \u27e8fun h => h.left.subsingleton, fun h =>\n    \u27e8isLeftRegular_zero_iff_subsingleton.mpr h, isRightRegular_zero_iff_subsingleton.mpr h\u27e9\u27e9\n#align is_regular_iff_subsingleton isRegular_iff_subsingleton\n\n/-- A left-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/\ntheorem IsLeftRegular.ne_zero [Nontrivial R] (la : IsLeftRegular a) : a \u2260 0 := by\n  rintro rfl\n  rcases exists_pair_ne R with \u27e8x, y, xy\u27e9\n  refine' xy (la (_ : 0 * x = 0 * y)) -- Porting note: lean4 seems to need the type signature\n  rw [zero_mul, zero_mul]\n#align is_left_regular.ne_zero IsLeftRegular.ne_zero\n\n/-- A right-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/\ntheorem IsRightRegular.ne_zero [Nontrivial R] (ra : IsRightRegular a) : a \u2260 0 := by\n  rintro rfl\n  rcases exists_pair_ne R with \u27e8x, y, xy\u27e9\n  refine' xy (ra (_ : x * 0 = y * 0))\n  rw [mul_zero, mul_zero]\n#align is_right_regular.ne_zero IsRightRegular.ne_zero\n\n/-- A regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/\ntheorem IsRegular.ne_zero [Nontrivial R] (la : IsRegular a) : a \u2260 0 :=\n  la.left.ne_zero\n#align is_regular.ne_zero IsRegular.ne_zero\n\n/-- In a non-trivial ring, the element `0` is not left-regular -- with typeclasses. -/\ntheorem not_isLeftRegular_zero [nR : Nontrivial R] : \u00acIsLeftRegular (0 : R) :=\n  not_isLeftRegular_zero_iff.mpr nR\n#align not_is_left_regular_zero not_isLeftRegular_zero\n\n/-- In a non-trivial ring, the element `0` is not right-regular -- with typeclasses. -/\ntheorem not_isRightRegular_zero [nR : Nontrivial R] : \u00acIsRightRegular (0 : R) :=\n  not_isRightRegular_zero_iff.mpr nR\n#align not_is_right_regular_zero not_isRightRegular_zero\n\n/-- In a non-trivial ring, the element `0` is not regular -- with typeclasses. -/\ntheorem not_isRegular_zero [Nontrivial R] : \u00acIsRegular (0 : R) := fun h => IsRegular.ne_zero h rfl\n#align not_is_regular_zero not_isRegular_zero\n\nend MulZeroClass\n\nsection MulOneClass\n\nvariable [MulOneClass R]\n\n/-- If multiplying by `1` on either side is the identity, `1` is regular. -/\n@[to_additive \"If adding `0` on either side is the identity, `0` is regular.\"]\ntheorem isRegular_one : IsRegular (1 : R) :=\n  \u27e8fun a b ab => (one_mul a).symm.trans (Eq.trans ab (one_mul b)), fun a b ab =>\n    (mul_one a).symm.trans (Eq.trans ab (mul_one b))\u27e9\n#align is_regular_one isRegular_one\n#align is_add_regular_zero isAddRegular_zero\n\nend MulOneClass\n\nsection CommSemigroup\n\nvariable [CommSemigroup R] {a b : R}\n\n/-- A product is regular if and only if the factors are. -/\n@[to_additive \"A sum is add-regular if and only if the summands are.\"]\ntheorem isRegular_mul_iff : IsRegular (a * b) \u2194 IsRegular a \u2227 IsRegular b := by\n  refine' Iff.trans _ isRegular_mul_and_mul_iff\n  refine' \u27e8fun ab => \u27e8ab, by rwa [mul_comm]\u27e9, fun rab => rab.1\u27e9\n#align is_regular_mul_iff isRegular_mul_iff\n#align is_add_regular_add_iff isAddRegular_add_iff\n\nend CommSemigroup\n\nsection Monoid\n\nvariable [Monoid R] {a b : R}\n\n/-- An element admitting a left inverse is left-regular. -/\n@[to_additive \"An element admitting a left additive opposite is add-left-regular.\"]\ntheorem isLeftRegular_of_mul_eq_one (h : b * a = 1) : IsLeftRegular a :=\n  @IsLeftRegular.of_mul R _ _ _ (by rw [h]; exact isRegular_one.left)\n#align is_left_regular_of_mul_eq_one isLeftRegular_of_mul_eq_one\n#align is_add_left_regular_of_add_eq_zero isAddLeftRegular_of_add_eq_zero\n\n/-- An element admitting a right inverse is right-regular. -/\n@[to_additive \"An element admitting a right additive opposite is add-right-regular.\"]\ntheorem isRightRegular_of_mul_eq_one (h : a * b = 1) : IsRightRegular a :=\n  IsRightRegular.of_mul (by rw [h]; exact isRegular_one.right)\n#align is_right_regular_of_mul_eq_one isRightRegular_of_mul_eq_one\n#align is_add_right_regular_of_add_eq_zero isAddRightRegular_of_add_eq_zero\n\n/-- If `R` is a monoid, an element in `R\u02e3` is regular. -/\n@[to_additive \"If `R` is an additive monoid, an element in `add_units R` is add-regular.\"]\ntheorem Units.isRegular (a : R\u02e3) : IsRegular (a : R) :=\n  \u27e8isLeftRegular_of_mul_eq_one a.inv_mul, isRightRegular_of_mul_eq_one a.mul_inv\u27e9\n#align units.is_regular Units.isRegular\n#align add_units.is_add_regular AddUnits.isAddRegular\n\n/-- A unit in a monoid is regular. -/\n@[to_additive \"An additive unit in an additive monoid is add-regular.\"]\ntheorem IsUnit.isRegular (ua : IsUnit a) : IsRegular a := by\n  rcases ua with \u27e8a, rfl\u27e9\n  exact Units.isRegular a\n#align is_unit.is_regular IsUnit.isRegular\n#align is_add_unit.is_add_regular IsAddUnit.isAddRegular\n\nend Monoid\n\n/-- Elements of a left cancel semigroup are left regular. -/\n@[to_additive \"Elements of an add left cancel semigroup are add-left-regular.\"]\ntheorem isLeftRegular_of_leftCancelSemigroup [LeftCancelSemigroup R]\n    (g : R) : IsLeftRegular g :=\n  mul_right_injective g\n#align is_left_regular_of_left_cancel_semigroup isLeftRegular_of_leftCancelSemigroup\n#align is_add_left_regular_of_left_cancel_add_semigroup isAddLeftRegular_of_addLeftCancelSemigroup\n\n/-- Elements of a right cancel semigroup are right regular. -/\n@[to_additive \"Elements of an add right cancel semigroup are add-right-regular\"]\ntheorem isRightRegular_of_rightCancelSemigroup [RightCancelSemigroup R]\n    (g : R) : IsRightRegular g :=\n  mul_left_injective g\n#align is_right_regular_of_right_cancel_semigroup isRightRegular_of_rightCancelSemigroup\n#align is_add_right_regular_of_right_cancel_add_semigroup   isAddRightRegular_of_addRightCancelSemigroup\n\nsection CancelMonoid\n\nvariable [CancelMonoid R]\n\n/-- Elements of a cancel monoid are regular.  Cancel semigroups do not appear to exist. -/\n@[to_additive \"Elements of an add cancel monoid are regular.\nAdd cancel semigroups do not appear to exist.\"]\ntheorem isRegular_of_cancelMonoid (g : R) : IsRegular g :=\n  \u27e8mul_right_injective g, mul_left_injective g\u27e9\n#align is_regular_of_cancel_monoid isRegular_of_cancelMonoid\n#align is_add_regular_of_cancel_add_monoid isAddRegular_of_addCancelMonoid\n\nend CancelMonoid\n\nsection CancelMonoidWithZero\n\nvariable [CancelMonoidWithZero R] {a : R}\n\n/-- Non-zero elements of an integral domain are regular. -/\ntheorem isRegular_of_ne_zero (a0 : a \u2260 0) : IsRegular a :=\n  \u27e8fun _ _ => (mul_right_inj' a0).mp, fun _ _ => (mul_left_inj' a0).mp\u27e9\n#align is_regular_of_ne_zero isRegular_of_ne_zero\n\n/-- In a non-trivial integral domain, an element is regular iff it is non-zero. -/\ntheorem isRegular_iff_ne_zero [Nontrivial R] : IsRegular a \u2194 a \u2260 0 :=\n  \u27e8IsRegular.ne_zero, isRegular_of_ne_zero\u27e9\n#align is_regular_iff_ne_zero isRegular_iff_ne_zero\n\nend CancelMonoidWithZero\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Regular/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7236910725757963}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.basic\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Definitions and properties of `gcd`, `lcm`, and `coprime`\n\n-/\n\nnamespace nat\n\n\n/-! ### `gcd` -/\n\ntheorem gcd_dvd (m : \u2115) (n : \u2115) : gcd m n \u2223 m \u2227 gcd m n \u2223 n := sorry\n\ntheorem gcd_dvd_left (m : \u2115) (n : \u2115) : gcd m n \u2223 m := and.left (gcd_dvd m n)\n\ntheorem gcd_dvd_right (m : \u2115) (n : \u2115) : gcd m n \u2223 n := and.right (gcd_dvd m n)\n\ntheorem gcd_le_left {m : \u2115} (n : \u2115) (h : 0 < m) : gcd m n \u2264 m := le_of_dvd h (gcd_dvd_left m n)\n\ntheorem gcd_le_right (m : \u2115) {n : \u2115} (h : 0 < n) : gcd m n \u2264 n := le_of_dvd h (gcd_dvd_right m n)\n\ntheorem dvd_gcd {m : \u2115} {n : \u2115} {k : \u2115} : k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 gcd m n := sorry\n\ntheorem dvd_gcd_iff {m : \u2115} {n : \u2115} {k : \u2115} : k \u2223 gcd m n \u2194 k \u2223 m \u2227 k \u2223 n := sorry\n\ntheorem gcd_comm (m : \u2115) (n : \u2115) : gcd m n = gcd n m :=\n  dvd_antisymm (dvd_gcd (gcd_dvd_right m n) (gcd_dvd_left m n))\n    (dvd_gcd (gcd_dvd_right n m) (gcd_dvd_left n m))\n\ntheorem gcd_eq_left_iff_dvd {m : \u2115} {n : \u2115} : m \u2223 n \u2194 gcd m n = m := sorry\n\ntheorem gcd_eq_right_iff_dvd {m : \u2115} {n : \u2115} : m \u2223 n \u2194 gcd n m = m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (m \u2223 n \u2194 gcd n m = m)) (gcd_comm n m))) gcd_eq_left_iff_dvd\n\ntheorem gcd_assoc (m : \u2115) (n : \u2115) (k : \u2115) : gcd (gcd m n) k = gcd m (gcd n k) := sorry\n\n@[simp] theorem gcd_one_right (n : \u2115) : gcd n 1 = 1 := Eq.trans (gcd_comm n 1) (gcd_one_left n)\n\ntheorem gcd_mul_left (m : \u2115) (n : \u2115) (k : \u2115) : gcd (m * n) (m * k) = m * gcd n k := sorry\n\ntheorem gcd_mul_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd (m * n) (k * n) = gcd m k * n := sorry\n\ntheorem gcd_pos_of_pos_left {m : \u2115} (n : \u2115) (mpos : 0 < m) : 0 < gcd m n :=\n  pos_of_dvd_of_pos (gcd_dvd_left m n) mpos\n\ntheorem gcd_pos_of_pos_right (m : \u2115) {n : \u2115} (npos : 0 < n) : 0 < gcd m n :=\n  pos_of_dvd_of_pos (gcd_dvd_right m n) npos\n\ntheorem eq_zero_of_gcd_eq_zero_left {m : \u2115} {n : \u2115} (H : gcd m n = 0) : m = 0 :=\n  or.elim (eq_zero_or_pos m) id\n    fun (H1 : 0 < m) => absurd (Eq.symm H) (ne_of_lt (gcd_pos_of_pos_left n H1))\n\ntheorem eq_zero_of_gcd_eq_zero_right {m : \u2115} {n : \u2115} (H : gcd m n = 0) : n = 0 :=\n  eq_zero_of_gcd_eq_zero_left (eq.mp (Eq._oldrec (Eq.refl (gcd m n = 0)) (gcd_comm m n)) H)\n\ntheorem gcd_div {m : \u2115} {n : \u2115} {k : \u2115} (H1 : k \u2223 m) (H2 : k \u2223 n) :\n    gcd (m / k) (n / k) = gcd m n / k :=\n  sorry\n\ntheorem gcd_dvd_gcd_of_dvd_left {m : \u2115} {k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd m n \u2223 gcd k n :=\n  dvd_gcd (dvd.trans (gcd_dvd_left m n) H) (gcd_dvd_right m n)\n\ntheorem gcd_dvd_gcd_of_dvd_right {m : \u2115} {k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd n m \u2223 gcd n k :=\n  dvd_gcd (gcd_dvd_left n m) (dvd.trans (gcd_dvd_right n m) H)\n\ntheorem gcd_dvd_gcd_mul_left (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd (k * m) n :=\n  gcd_dvd_gcd_of_dvd_left n (dvd_mul_left m k)\n\ntheorem gcd_dvd_gcd_mul_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd (m * k) n :=\n  gcd_dvd_gcd_of_dvd_left n (dvd_mul_right m k)\n\ntheorem gcd_dvd_gcd_mul_left_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd m (k * n) :=\n  gcd_dvd_gcd_of_dvd_right m (dvd_mul_left n k)\n\ntheorem gcd_dvd_gcd_mul_right_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd m (n * k) :=\n  gcd_dvd_gcd_of_dvd_right m (dvd_mul_right n k)\n\ntheorem gcd_eq_left {m : \u2115} {n : \u2115} (H : m \u2223 n) : gcd m n = m :=\n  dvd_antisymm (gcd_dvd_left m n) (dvd_gcd (dvd_refl m) H)\n\ntheorem gcd_eq_right {m : \u2115} {n : \u2115} (H : n \u2223 m) : gcd m n = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd m n = n)) (gcd_comm m n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd n m = n)) (gcd_eq_left H))) (Eq.refl n))\n\n@[simp] theorem gcd_mul_left_left (m : \u2115) (n : \u2115) : gcd (m * n) n = n :=\n  dvd_antisymm (gcd_dvd_right (m * n) n) (dvd_gcd (dvd_mul_left n m) (dvd_refl n))\n\n@[simp] theorem gcd_mul_left_right (m : \u2115) (n : \u2115) : gcd n (m * n) = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd n (m * n) = n)) (gcd_comm n (m * n))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (m * n) n = n)) (gcd_mul_left_left m n))) (Eq.refl n))\n\n@[simp] theorem gcd_mul_right_left (m : \u2115) (n : \u2115) : gcd (n * m) n = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (n * m) n = n)) (mul_comm n m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (m * n) n = n)) (gcd_mul_left_left m n))) (Eq.refl n))\n\n@[simp] theorem gcd_mul_right_right (m : \u2115) (n : \u2115) : gcd n (n * m) = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd n (n * m) = n)) (gcd_comm n (n * m))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (n * m) n = n)) (gcd_mul_right_left m n))) (Eq.refl n))\n\n@[simp] theorem gcd_gcd_self_right_left (m : \u2115) (n : \u2115) : gcd m (gcd m n) = gcd m n :=\n  dvd_antisymm (gcd_dvd_right m (gcd m n)) (dvd_gcd (gcd_dvd_left m n) (dvd_refl (gcd m n)))\n\n@[simp] theorem gcd_gcd_self_right_right (m : \u2115) (n : \u2115) : gcd m (gcd n m) = gcd n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (gcd n m) = gcd n m)) (gcd_comm n m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (gcd m n) = gcd m n)) (gcd_gcd_self_right_left m n)))\n      (Eq.refl (gcd m n)))\n\n@[simp] theorem gcd_gcd_self_left_right (m : \u2115) (n : \u2115) : gcd (gcd n m) m = gcd n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (gcd n m) m = gcd n m)) (gcd_comm (gcd n m) m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (gcd n m) = gcd n m)) (gcd_gcd_self_right_right m n)))\n      (Eq.refl (gcd n m)))\n\n@[simp] theorem gcd_gcd_self_left_left (m : \u2115) (n : \u2115) : gcd (gcd m n) m = gcd m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (gcd m n) m = gcd m n)) (gcd_comm m n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (gcd n m) m = gcd n m)) (gcd_gcd_self_left_right m n)))\n      (Eq.refl (gcd n m)))\n\ntheorem gcd_add_mul_self (m : \u2115) (n : \u2115) (k : \u2115) : gcd m (n + k * m) = gcd m n := sorry\n\ntheorem gcd_eq_zero_iff {i : \u2115} {j : \u2115} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 := sorry\n\n/-! ### `lcm` -/\n\ntheorem lcm_comm (m : \u2115) (n : \u2115) : lcm m n = lcm n m :=\n  id\n    (eq.mpr (id (Eq._oldrec (Eq.refl (m * n / gcd m n = n * m / gcd n m)) (mul_comm m n)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (n * m / gcd m n = n * m / gcd n m)) (gcd_comm m n)))\n        (Eq.refl (n * m / gcd n m))))\n\n@[simp] theorem lcm_zero_left (m : \u2115) : lcm 0 m = 0 :=\n  id\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 * m / gcd 0 m = 0)) (zero_mul m)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 / gcd 0 m = 0)) (nat.zero_div (gcd 0 m)))) (Eq.refl 0)))\n\n@[simp] theorem lcm_zero_right (m : \u2115) : lcm m 0 = 0 := lcm_comm 0 m \u25b8 lcm_zero_left m\n\n@[simp] theorem lcm_one_left (m : \u2115) : lcm 1 m = m := sorry\n\n@[simp] theorem lcm_one_right (m : \u2115) : lcm m 1 = m := lcm_comm 1 m \u25b8 lcm_one_left m\n\n@[simp] theorem lcm_self (m : \u2115) : lcm m m = m := sorry\n\ntheorem dvd_lcm_left (m : \u2115) (n : \u2115) : m \u2223 lcm m n :=\n  dvd.intro (n / gcd m n) (Eq.symm (nat.mul_div_assoc m (gcd_dvd_right m n)))\n\ntheorem dvd_lcm_right (m : \u2115) (n : \u2115) : n \u2223 lcm m n := lcm_comm n m \u25b8 dvd_lcm_left n m\n\ntheorem gcd_mul_lcm (m : \u2115) (n : \u2115) : gcd m n * lcm m n = m * n := sorry\n\ntheorem lcm_dvd {m : \u2115} {n : \u2115} {k : \u2115} (H1 : m \u2223 k) (H2 : n \u2223 k) : lcm m n \u2223 k := sorry\n\ntheorem lcm_assoc (m : \u2115) (n : \u2115) (k : \u2115) : lcm (lcm m n) k = lcm m (lcm n k) := sorry\n\ntheorem lcm_ne_zero {m : \u2115} {n : \u2115} (hm : m \u2260 0) (hn : n \u2260 0) : lcm m n \u2260 0 := sorry\n\n/-!\n### `coprime`\n\nSee also `nat.coprime_of_dvd` and `nat.coprime_of_dvd'` to prove `nat.coprime m n`.\n-/\n\nprotected instance coprime.decidable (m : \u2115) (n : \u2115) : Decidable (coprime m n) :=\n  eq.mpr sorry (nat.decidable_eq (gcd m n) 1)\n\ntheorem coprime.gcd_eq_one {m : \u2115} {n : \u2115} : coprime m n \u2192 gcd m n = 1 := id\n\ntheorem coprime.symm {m : \u2115} {n : \u2115} : coprime n m \u2192 coprime m n := Eq.trans (gcd_comm m n)\n\ntheorem coprime.dvd_of_dvd_mul_right {m : \u2115} {n : \u2115} {k : \u2115} (H1 : coprime k n) (H2 : k \u2223 m * n) :\n    k \u2223 m :=\n  sorry\n\ntheorem coprime.dvd_of_dvd_mul_left {m : \u2115} {n : \u2115} {k : \u2115} (H1 : coprime k m) (H2 : k \u2223 m * n) :\n    k \u2223 n :=\n  coprime.dvd_of_dvd_mul_right H1 (eq.mp (Eq._oldrec (Eq.refl (k \u2223 m * n)) (mul_comm m n)) H2)\n\ntheorem coprime.gcd_mul_left_cancel {k : \u2115} (m : \u2115) {n : \u2115} (H : coprime k n) :\n    gcd (k * m) n = gcd m n :=\n  sorry\n\ntheorem coprime.gcd_mul_right_cancel (m : \u2115) {k : \u2115} {n : \u2115} (H : coprime k n) :\n    gcd (m * k) n = gcd m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (m * k) n = gcd m n)) (mul_comm m k)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (k * m) n = gcd m n)) (coprime.gcd_mul_left_cancel m H)))\n      (Eq.refl (gcd m n)))\n\ntheorem coprime.gcd_mul_left_cancel_right {k : \u2115} {m : \u2115} (n : \u2115) (H : coprime k m) :\n    gcd m (k * n) = gcd m n :=\n  sorry\n\ntheorem coprime.gcd_mul_right_cancel_right {k : \u2115} {m : \u2115} (n : \u2115) (H : coprime k m) :\n    gcd m (n * k) = gcd m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (n * k) = gcd m n)) (mul_comm n k)))\n    (eq.mpr\n      (id (Eq._oldrec (Eq.refl (gcd m (k * n) = gcd m n)) (coprime.gcd_mul_left_cancel_right n H)))\n      (Eq.refl (gcd m n)))\n\ntheorem coprime_div_gcd_div_gcd {m : \u2115} {n : \u2115} (H : 0 < gcd m n) :\n    coprime (m / gcd m n) (n / gcd m n) :=\n  sorry\n\ntheorem not_coprime_of_dvd_of_dvd {m : \u2115} {n : \u2115} {d : \u2115} (dgt1 : 1 < d) (Hm : d \u2223 m) (Hn : d \u2223 n) :\n    \u00accoprime m n :=\n  fun (co : gcd m n = 1) =>\n    not_lt_of_ge\n      (le_of_dvd zero_lt_one\n        (eq.mpr (id (Eq._oldrec (Eq.refl (d \u2223 1)) (Eq.symm co))) (dvd_gcd Hm Hn)))\n      dgt1\n\ntheorem exists_coprime {m : \u2115} {n : \u2115} (H : 0 < gcd m n) :\n    \u2203 (m' : \u2115), \u2203 (n' : \u2115), coprime m' n' \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n  sorry\n\ntheorem exists_coprime' {m : \u2115} {n : \u2115} (H : 0 < gcd m n) :\n    \u2203 (g : \u2115), \u2203 (m' : \u2115), \u2203 (n' : \u2115), 0 < g \u2227 coprime m' n' \u2227 m = m' * g \u2227 n = n' * g :=\n  sorry\n\ntheorem coprime.mul {m : \u2115} {n : \u2115} {k : \u2115} (H1 : coprime m k) (H2 : coprime n k) :\n    coprime (m * n) k :=\n  Eq.trans (coprime.gcd_mul_left_cancel n H1) H2\n\ntheorem coprime.mul_right {k : \u2115} {m : \u2115} {n : \u2115} (H1 : coprime k m) (H2 : coprime k n) :\n    coprime k (m * n) :=\n  coprime.symm (coprime.mul (coprime.symm H1) (coprime.symm H2))\n\ntheorem coprime.coprime_dvd_left {m : \u2115} {k : \u2115} {n : \u2115} (H1 : m \u2223 k) (H2 : coprime k n) :\n    coprime m n :=\n  sorry\n\ntheorem coprime.coprime_dvd_right {m : \u2115} {k : \u2115} {n : \u2115} (H1 : n \u2223 m) (H2 : coprime k m) :\n    coprime k n :=\n  coprime.symm (coprime.coprime_dvd_left H1 (coprime.symm H2))\n\ntheorem coprime.coprime_mul_left {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime (k * m) n) : coprime m n :=\n  coprime.coprime_dvd_left (dvd_mul_left m k) H\n\ntheorem coprime.coprime_mul_right {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime (m * k) n) : coprime m n :=\n  coprime.coprime_dvd_left (dvd_mul_right m k) H\n\ntheorem coprime.coprime_mul_left_right {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime m (k * n)) :\n    coprime m n :=\n  coprime.coprime_dvd_right (dvd_mul_left n k) H\n\ntheorem coprime.coprime_mul_right_right {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime m (n * k)) :\n    coprime m n :=\n  coprime.coprime_dvd_right (dvd_mul_right n k) H\n\ntheorem coprime.coprime_div_left {m : \u2115} {n : \u2115} {a : \u2115} (cmn : coprime m n) (dvd : a \u2223 m) :\n    coprime (m / a) n :=\n  sorry\n\ntheorem coprime.coprime_div_right {m : \u2115} {n : \u2115} {a : \u2115} (cmn : coprime m n) (dvd : a \u2223 n) :\n    coprime m (n / a) :=\n  coprime.symm (coprime.coprime_div_left (coprime.symm cmn) dvd)\n\ntheorem coprime_mul_iff_left {k : \u2115} {m : \u2115} {n : \u2115} :\n    coprime (m * n) k \u2194 coprime m k \u2227 coprime n k :=\n  sorry\n\ntheorem coprime_mul_iff_right {k : \u2115} {m : \u2115} {n : \u2115} :\n    coprime k (m * n) \u2194 coprime k m \u2227 coprime k n :=\n  sorry\n\ntheorem coprime.gcd_left (k : \u2115) {m : \u2115} {n : \u2115} (hmn : coprime m n) : coprime (gcd k m) n :=\n  coprime.coprime_dvd_left (gcd_dvd_right k m) hmn\n\ntheorem coprime.gcd_right (k : \u2115) {m : \u2115} {n : \u2115} (hmn : coprime m n) : coprime m (gcd k n) :=\n  coprime.coprime_dvd_right (gcd_dvd_right k n) hmn\n\ntheorem coprime.gcd_both (k : \u2115) (l : \u2115) {m : \u2115} {n : \u2115} (hmn : coprime m n) :\n    coprime (gcd k m) (gcd l n) :=\n  coprime.gcd_right l (coprime.gcd_left k hmn)\n\ntheorem coprime.mul_dvd_of_dvd_of_dvd {a : \u2115} {n : \u2115} {m : \u2115} (hmn : coprime m n) (hm : m \u2223 a)\n    (hn : n \u2223 a) : m * n \u2223 a :=\n  sorry\n\ntheorem coprime_one_left (n : \u2115) : coprime 1 n := gcd_one_left\n\ntheorem coprime_one_right (n : \u2115) : coprime n 1 := gcd_one_right\n\ntheorem coprime.pow_left {m : \u2115} {k : \u2115} (n : \u2115) (H1 : coprime m k) : coprime (m ^ n) k :=\n  nat.rec_on n (coprime_one_left k) fun (n : \u2115) (IH : coprime (m ^ n) k) => coprime.mul H1 IH\n\ntheorem coprime.pow_right {m : \u2115} {k : \u2115} (n : \u2115) (H1 : coprime k m) : coprime k (m ^ n) :=\n  coprime.symm (coprime.pow_left n (coprime.symm H1))\n\ntheorem coprime.pow {k : \u2115} {l : \u2115} (m : \u2115) (n : \u2115) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) :=\n  coprime.pow_right n (coprime.pow_left m H1)\n\ntheorem coprime.eq_one_of_dvd {k : \u2115} {m : \u2115} (H : coprime k m) (d : k \u2223 m) : k = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (k = 1)) (Eq.symm (coprime.gcd_eq_one H))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (k = gcd k m)) (gcd_eq_left d))) (Eq.refl k))\n\n@[simp] theorem coprime_zero_left (n : \u2115) : coprime 0 n \u2194 n = 1 := sorry\n\n@[simp] theorem coprime_zero_right (n : \u2115) : coprime n 0 \u2194 n = 1 := sorry\n\n@[simp] theorem coprime_one_left_iff (n : \u2115) : coprime 1 n \u2194 True := sorry\n\n@[simp] theorem coprime_one_right_iff (n : \u2115) : coprime n 1 \u2194 True := sorry\n\n@[simp] theorem coprime_self (n : \u2115) : coprime n n \u2194 n = 1 := sorry\n\n/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. -/\ndef prod_dvd_and_dvd_of_dvd_prod {m : \u2115} {n : \u2115} {k : \u2115} (H : k \u2223 m * n) :\n    Subtype\n        fun (d : (Subtype fun (m' : \u2115) => m' \u2223 m) \u00d7 Subtype fun (n' : \u2115) => n' \u2223 n) =>\n          k = \u2191(prod.fst d) * \u2191(prod.snd d) :=\n  (fun (_x : \u2115) (h0 : gcd k m = _x) =>\n      nat.cases_on _x\n        (fun (h0 : gcd k m = 0) =>\n          Eq._oldrec\n            (fun (H : 0 \u2223 m * n) (h0 : gcd 0 m = 0) =>\n              Eq._oldrec\n                (fun (H : 0 \u2223 0 * n) (h0 : gcd 0 0 = 0) =>\n                  { val := ({ val := 0, property := sorry }, { val := n, property := dvd_refl n }),\n                    property := sorry })\n                sorry H h0)\n            sorry H h0)\n        (fun (n_1 : \u2115) (h0 : gcd k m = Nat.succ n_1) =>\n          (fun (h0 : gcd k m = Nat.succ n_1) =>\n              { val :=\n                  ({ val := gcd k m, property := gcd_dvd_right k m },\n                  { val := k / gcd k m, property := sorry }),\n                property := sorry })\n            h0)\n        h0)\n    (gcd k m) sorry\n\ntheorem gcd_mul_dvd_mul_gcd (k : \u2115) (m : \u2115) (n : \u2115) : gcd k (m * n) \u2223 gcd k m * gcd k n := sorry\n\ntheorem coprime.gcd_mul (k : \u2115) {m : \u2115} {n : \u2115} (h : coprime m n) :\n    gcd k (m * n) = gcd k m * gcd k n :=\n  dvd_antisymm (gcd_mul_dvd_mul_gcd k m n)\n    (coprime.mul_dvd_of_dvd_of_dvd (coprime.gcd_both k k h) (gcd_dvd_gcd_mul_right_right k m n)\n      (gcd_dvd_gcd_mul_left_right k n m))\n\ntheorem pow_dvd_pow_iff {a : \u2115} {b : \u2115} {n : \u2115} (n0 : 0 < n) : a ^ n \u2223 b ^ n \u2194 a \u2223 b := sorry\n\ntheorem gcd_mul_gcd_of_coprime_of_mul_eq_mul {a : \u2115} {b : \u2115} {c : \u2115} {d : \u2115} (cop : coprime c d)\n    (h : a * b = c * d) : gcd a c * gcd b c = c :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/nat/gcd_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.723691072227706}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n\n! This file was ported from Lean 3 source module ring_theory.polynomial.content\n! leanprover-community/mathlib commit cb3ceec8485239a61ed51d944cb9a95b68c6bafc\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.GcdMonoid.Finset\nimport Mathbin.Data.Polynomial.FieldDivision\nimport Mathbin.Data.Polynomial.EraseLead\nimport Mathbin.Data.Polynomial.CancelLeads\n\n/-!\n# GCD structures on polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nDefinitions and basic results about polynomials over GCD domains, particularly their contents\nand primitive polynomials.\n\n## Main Definitions\nLet `p : R[X]`.\n - `p.content` is the `gcd` of the coefficients of `p`.\n - `p.is_primitive` indicates that `p.content = 1`.\n\n## Main Results\n - `polynomial.content_mul`:\n  If `p q : R[X]`, then `(p * q).content = p.content * q.content`.\n - `polynomial.normalized_gcd_monoid`:\n  The polynomial ring of a GCD domain is itself a GCD domain.\n\n-/\n\n\nnamespace Polynomial\n\nopen Polynomial\n\nsection Primitive\n\nvariable {R : Type _} [CommSemiring R]\n\n#print Polynomial.IsPrimitive /-\n/-- A polynomial is primitive when the only constant polynomials dividing it are units -/\ndef IsPrimitive (p : R[X]) : Prop :=\n  \u2200 r : R, C r \u2223 p \u2192 IsUnit r\n#align polynomial.is_primitive Polynomial.IsPrimitive\n-/\n\n/- warning: polynomial.is_primitive_iff_is_unit_of_C_dvd -> Polynomial.isPrimitive_iff_isUnit_of_c_dvd is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommSemiring.{u1} R] {p : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)}, Iff (Polynomial.IsPrimitive.{u1} R _inst_1 p) (forall (r : R), (Dvd.Dvd.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (semigroupDvd.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (SemigroupWithZero.toSemigroup.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (NonUnitalSemiring.toSemigroupWithZero.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (NonUnitalCommSemiring.toNonUnitalSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (CommSemiring.toNonUnitalCommSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.commSemiring.{u1} R _inst_1)))))) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => R -> (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (Polynomial.C.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) p) -> (IsUnit.{u1} R (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) r))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommSemiring.{u1} R] {p : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)}, Iff (Polynomial.IsPrimitive.{u1} R _inst_1 p) (forall (r : R), (Dvd.dvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) (semigroupDvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) (SemigroupWithZero.toSemigroup.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) (NonUnitalSemiring.toSemigroupWithZero.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) (NonUnitalCommSemiring.toNonUnitalSemiring.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) (CommSemiring.toNonUnitalCommSemiring.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) (Polynomial.commSemiring.{u1} R _inst_1)))))) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))))))) (Polynomial.C.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) r) p) -> (IsUnit.{u1} R (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) r))\nCase conversion may be inaccurate. Consider using '#align polynomial.is_primitive_iff_is_unit_of_C_dvd Polynomial.isPrimitive_iff_isUnit_of_c_dvd\u2093'. -/\ntheorem isPrimitive_iff_isUnit_of_c_dvd {p : R[X]} : p.IsPrimitive \u2194 \u2200 r : R, C r \u2223 p \u2192 IsUnit r :=\n  Iff.rfl\n#align polynomial.is_primitive_iff_is_unit_of_C_dvd Polynomial.isPrimitive_iff_isUnit_of_c_dvd\n\n#print Polynomial.isPrimitive_one /-\n@[simp]\ntheorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun r h =>\n  isUnit_C.mp (isUnit_of_dvd_one (C r) h)\n#align polynomial.is_primitive_one Polynomial.isPrimitive_one\n-/\n\n#print Polynomial.Monic.isPrimitive /-\ntheorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive :=\n  by\n  rintro r \u27e8q, h\u27e9\n  exact isUnit_of_mul_eq_one r (q.coeff p.nat_degree) (by rwa [\u2190 coeff_C_mul, \u2190 h])\n#align polynomial.monic.is_primitive Polynomial.Monic.isPrimitive\n-/\n\n#print Polynomial.IsPrimitive.ne_zero /-\ntheorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p \u2260 0 :=\n  by\n  rintro rfl\n  exact (hp 0 (dvd_zero (C 0))).NeZero rfl\n#align polynomial.is_primitive.ne_zero Polynomial.IsPrimitive.ne_zero\n-/\n\n#print Polynomial.isPrimitive_of_dvd /-\ntheorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q \u2223 p) : IsPrimitive q :=\n  fun a ha => isPrimitive_iff_isUnit_of_c_dvd.mp hp a (dvd_trans ha hq)\n#align polynomial.is_primitive_of_dvd Polynomial.isPrimitive_of_dvd\n-/\n\nend Primitive\n\nvariable {R : Type _} [CommRing R] [IsDomain R]\n\nsection NormalizedGCDMonoid\n\nvariable [NormalizedGCDMonoid R]\n\n#print Polynomial.content /-\n/-- `p.content` is the `gcd` of the coefficients of `p`. -/\ndef content (p : R[X]) : R :=\n  p.support.gcd p.coeff\n#align polynomial.content Polynomial.content\n-/\n\n#print Polynomial.content_dvd_coeff /-\ntheorem content_dvd_coeff {p : R[X]} (n : \u2115) : p.content \u2223 p.coeff n :=\n  by\n  by_cases h : n \u2208 p.support\n  \u00b7 apply Finset.gcd_dvd h\n  rw [mem_support_iff, Classical.not_not] at h\n  rw [h]\n  apply dvd_zero\n#align polynomial.content_dvd_coeff Polynomial.content_dvd_coeff\n-/\n\n/- warning: polynomial.content_C -> Polynomial.content_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {r : R}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r)) (coeFn.{succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (fun (_x : MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) => R -> R) (MonoidWithZeroHom.hasCoeToFun.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) r)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {r : R}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r)) (FunLike.coe.{succ u1, succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) _x) (MulHomClass.toFunLike.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MonoidHomClass.toMulHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MonoidWithZeroHomClass.toMonoidHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZeroHom.monoidWithZeroHomClass.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) r)\nCase conversion may be inaccurate. Consider using '#align polynomial.content_C Polynomial.content_C\u2093'. -/\n@[simp]\ntheorem content_C {r : R} : (C r).content = normalize r :=\n  by\n  rw [content]\n  by_cases h0 : r = 0\n  \u00b7 simp [h0]\n  have h : (C r).support = {0} := support_monomial _ h0\n  simp [h]\n#align polynomial.content_C Polynomial.content_C\n\n/- warning: polynomial.content_zero -> Polynomial.content_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)], Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (OfNat.mk.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.zero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)], Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (CommMonoidWithZero.toZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_zero Polynomial.content_zero\u2093'. -/\n@[simp]\ntheorem content_zero : content (0 : R[X]) = 0 := by rw [\u2190 C_0, content_C, normalize_zero]\n#align polynomial.content_zero Polynomial.content_zero\n\n/- warning: polynomial.content_one -> Polynomial.content_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)], Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 1 (OfNat.mk.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 1 (One.one.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.hasOne.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))))) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddGroupWithOne.toAddMonoidWithOne.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (CommRing.toRing.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)], Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 1 (One.toOfNat1.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.one.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (NonAssocRing.toOne.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_one Polynomial.content_one\u2093'. -/\n@[simp]\ntheorem content_one : content (1 : R[X]) = 1 := by rw [\u2190 C_1, content_C, normalize_one]\n#align polynomial.content_one Polynomial.content_one\n\n#print Polynomial.content_X_mul /-\ntheorem content_X_mul {p : R[X]} : content (X * p) = content p :=\n  by\n  rw [content, content, Finset.gcd_def, Finset.gcd_def]\n  refine' congr rfl _\n  have h : (X * p).support = p.support.map \u27e8Nat.succ, Nat.succ_injective\u27e9 :=\n    by\n    ext a\n    simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne.def, mem_support_iff]\n    cases a\n    \u00b7 simp [coeff_X_mul_zero, Nat.succ_ne_zero]\n    rw [mul_comm, coeff_mul_X]\n    constructor\n    \u00b7 intro h\n      use a\n      simp [h]\n    \u00b7 rintro \u27e8b, \u27e8h1, h2\u27e9\u27e9\n      rw [\u2190 Nat.succ_injective h2]\n      apply h1\n  rw [h]\n  simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map]\n  refine' congr (congr rfl _) rfl\n  ext a\n  rw [mul_comm]\n  simp [coeff_mul_X]\n#align polynomial.content_X_mul Polynomial.content_X_mul\n-/\n\n/- warning: polynomial.content_X_pow -> Polynomial.content_X_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {k : Nat}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) Nat (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHPow.{u1, 0} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Ring.toMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.ring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.X.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) k)) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddGroupWithOne.toAddMonoidWithOne.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (CommRing.toRing.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {k : Nat}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (HPow.hPow.{u1, 0, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) Nat (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHPow.{u1, 0} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) Nat (Monoid.Pow.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))))) (Polynomial.X.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) k)) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (NonAssocRing.toOne.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_X_pow Polynomial.content_X_pow\u2093'. -/\n@[simp]\ntheorem content_X_pow {k : \u2115} : content ((X : R[X]) ^ k) = 1 :=\n  by\n  induction' k with k hi\n  \u00b7 simp\n  rw [pow_succ, content_X_mul, hi]\n#align polynomial.content_X_pow Polynomial.content_X_pow\n\n/- warning: polynomial.content_X -> Polynomial.content_X is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)], Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (Polynomial.X.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddGroupWithOne.toAddMonoidWithOne.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (CommRing.toRing.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)], Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (Polynomial.X.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (NonAssocRing.toOne.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_X Polynomial.content_X\u2093'. -/\n@[simp]\ntheorem content_X : content (X : R[X]) = 1 := by rw [\u2190 mul_one X, content_X_mul, content_one]\n#align polynomial.content_X Polynomial.content_X\n\n/- warning: polynomial.content_C_mul -> Polynomial.content_C_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (r : R) (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) p)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (Ring.toDistrib.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (coeFn.{succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (fun (_x : MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) => R -> R) (MonoidWithZeroHom.hasCoeToFun.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) r) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (r : R) (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) p)) (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) r) R ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) r) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) r) (NonUnitalNonAssocRing.toMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) r) (NonAssocRing.toNonUnitalNonAssocRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) r) (Ring.toNonAssocRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) r) (CommRing.toRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) r) _inst_1))))) (FunLike.coe.{succ u1, succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) _x) (MulHomClass.toFunLike.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MonoidHomClass.toMulHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MonoidWithZeroHomClass.toMonoidHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZeroHom.monoidWithZeroHomClass.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) r) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_C_mul Polynomial.content_C_mul\u2093'. -/\ntheorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content :=\n  by\n  by_cases h0 : r = 0; \u00b7 simp [h0]\n  rw [content]; rw [content]; rw [\u2190 Finset.gcd_mul_left]\n  refine' congr (congr rfl _) _ <;> ext <;> simp [h0, mem_support_iff]\n#align polynomial.content_C_mul Polynomial.content_C_mul\n\n/- warning: polynomial.content_monomial -> Polynomial.content_monomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {r : R} {k : Nat}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.monomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) k) r)) (coeFn.{succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (fun (_x : MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) => R -> R) (MonoidWithZeroHom.hasCoeToFun.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) r)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {r : R} {k : Nat}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.module.{u1, u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Semiring.toModule.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.monomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) k) r)) (FunLike.coe.{succ u1, succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) _x) (MulHomClass.toFunLike.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MonoidHomClass.toMulHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MonoidWithZeroHomClass.toMonoidHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZeroHom.monoidWithZeroHomClass.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) r)\nCase conversion may be inaccurate. Consider using '#align polynomial.content_monomial Polynomial.content_monomial\u2093'. -/\n@[simp]\ntheorem content_monomial {r : R} {k : \u2115} : content (monomial k r) = normalize r := by\n  rw [\u2190 C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one]\n#align polynomial.content_monomial Polynomial.content_monomial\n\n/- warning: polynomial.content_eq_zero_iff -> Polynomial.content_eq_zero_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Iff (Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))))) (Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (OfNat.mk.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.zero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Iff (Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (CommMonoidWithZero.toZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_eq_zero_iff Polynomial.content_eq_zero_iff\u2093'. -/\ntheorem content_eq_zero_iff {p : R[X]} : content p = 0 \u2194 p = 0 :=\n  by\n  rw [content, Finset.gcd_eq_zero_iff]\n  constructor <;> intro h\n  \u00b7 ext n\n    by_cases h0 : n \u2208 p.support\n    \u00b7 rw [h n h0, coeff_zero]\n    \u00b7 rw [mem_support_iff] at h0\n      push_neg  at h0\n      simp [h0]\n  \u00b7 intro x h0\n    simp [h]\n#align polynomial.content_eq_zero_iff Polynomial.content_eq_zero_iff\n\n/- warning: polynomial.normalize_content -> Polynomial.normalize_content is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Eq.{succ u1} R (coeFn.{succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (fun (_x : MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) => R -> R) (MonoidWithZeroHom.hasCoeToFun.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (FunLike.coe.{succ u1, succ u1, succ u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => R) _x) (MulHomClass.toFunLike.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MulOneClass.toMul.{u1} R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))) (MonoidHomClass.toMulHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MulZeroOneClass.toMulOneClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) (MonoidWithZeroHomClass.toMonoidHomClass.{u1, u1, u1} (MonoidWithZeroHom.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))))) R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZeroHom.monoidWithZeroHomClass.{u1, u1} R R (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))) (MonoidWithZero.toMulZeroOneClass.{u1} R (CommMonoidWithZero.toMonoidWithZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)))))))) (normalize.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toNormalizationMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3)) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)\nCase conversion may be inaccurate. Consider using '#align polynomial.normalize_content Polynomial.normalize_content\u2093'. -/\n@[simp]\ntheorem normalize_content {p : R[X]} : normalize p.content = p.content :=\n  Finset.normalize_gcd\n#align polynomial.normalize_content Polynomial.normalize_content\n\n#print Polynomial.content_eq_gcd_range_of_lt /-\ntheorem content_eq_gcd_range_of_lt (p : R[X]) (n : \u2115) (h : p.natDegree < n) :\n    p.content = (Finset.range n).gcd p.coeff :=\n  by\n  apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd\n  \u00b7 rw [Finset.dvd_gcd_iff]\n    intro i hi\n    apply content_dvd_coeff _\n  \u00b7 apply Finset.gcd_mono\n    intro i\n    simp only [Nat.lt_succ_iff, mem_support_iff, Ne.def, Finset.mem_range]\n    contrapose!\n    intro h1\n    apply coeff_eq_zero_of_nat_degree_lt (lt_of_lt_of_le h h1)\n#align polynomial.content_eq_gcd_range_of_lt Polynomial.content_eq_gcd_range_of_lt\n-/\n\n#print Polynomial.content_eq_gcd_range_succ /-\ntheorem content_eq_gcd_range_succ (p : R[X]) :\n    p.content = (Finset.range p.natDegree.succ).gcd p.coeff :=\n  content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _)\n#align polynomial.content_eq_gcd_range_succ Polynomial.content_eq_gcd_range_succ\n-/\n\n#print Polynomial.content_eq_gcd_leadingCoeff_content_eraseLead /-\ntheorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) :\n    p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content :=\n  by\n  by_cases h : p = 0\n  \u00b7 simp [h]\n  rw [\u2190 leading_coeff_eq_zero, leading_coeff, \u2190 Ne.def, \u2190 mem_support_iff] at h\n  rw [content, \u2190 Finset.insert_erase h, Finset.gcd_insert, leading_coeff, content,\n    erase_lead_support]\n  refine' congr rfl (Finset.gcd_congr rfl fun i hi => _)\n  rw [Finset.mem_erase] at hi\n  rw [erase_lead_coeff, if_neg hi.1]\n#align polynomial.content_eq_gcd_leading_coeff_content_erase_lead Polynomial.content_eq_gcd_leadingCoeff_content_eraseLead\n-/\n\n/- warning: polynomial.dvd_content_iff_C_dvd -> Polynomial.dvd_content_iff_C_dvd is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {r : R}, Iff (Dvd.Dvd.{u1} R (semigroupDvd.{u1} R (SemigroupWithZero.toSemigroup.{u1} R (NonUnitalSemiring.toSemigroupWithZero.{u1} R (NonUnitalRing.toNonUnitalSemiring.{u1} R (NonUnitalCommRing.toNonUnitalRing.{u1} R (CommRing.toNonUnitalCommRing.{u1} R _inst_1)))))) r (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Dvd.Dvd.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (semigroupDvd.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (SemigroupWithZero.toSemigroup.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalSemiring.toSemigroupWithZero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalRing.toNonUnitalSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalCommRing.toNonUnitalRing.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (CommRing.toNonUnitalCommRing.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.commRing.{u1} R _inst_1))))))) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) p)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {r : R}, Iff (Dvd.dvd.{u1} R (semigroupDvd.{u1} R (SemigroupWithZero.toSemigroup.{u1} R (NonUnitalSemiring.toSemigroupWithZero.{u1} R (NonUnitalRing.toNonUnitalSemiring.{u1} R (NonUnitalCommRing.toNonUnitalRing.{u1} R (CommRing.toNonUnitalCommRing.{u1} R _inst_1)))))) r (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Dvd.dvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (semigroupDvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (SemigroupWithZero.toSemigroup.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (NonUnitalSemiring.toSemigroupWithZero.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (NonUnitalRing.toNonUnitalSemiring.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (NonUnitalCommRing.toNonUnitalRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (CommRing.toNonUnitalCommRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) (Polynomial.commRing.{u1} R _inst_1))))))) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r) p)\nCase conversion may be inaccurate. Consider using '#align polynomial.dvd_content_iff_C_dvd Polynomial.dvd_content_iff_C_dvd\u2093'. -/\ntheorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r \u2223 p.content \u2194 C r \u2223 p :=\n  by\n  rw [C_dvd_iff_dvd_coeff]\n  constructor\n  \u00b7 intro h i\n    apply h.trans (content_dvd_coeff _)\n  \u00b7 intro h\n    rw [content, Finset.dvd_gcd_iff]\n    intro i hi\n    apply h i\n#align polynomial.dvd_content_iff_C_dvd Polynomial.dvd_content_iff_C_dvd\n\n/- warning: polynomial.C_content_dvd -> Polynomial.C_content_dvd is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Dvd.Dvd.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (semigroupDvd.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (SemigroupWithZero.toSemigroup.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalSemiring.toSemigroupWithZero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalRing.toNonUnitalSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalCommRing.toNonUnitalRing.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (CommRing.toNonUnitalCommRing.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.commRing.{u1} R _inst_1))))))) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) p\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Dvd.dvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (semigroupDvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (SemigroupWithZero.toSemigroup.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (NonUnitalSemiring.toSemigroupWithZero.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (NonUnitalRing.toNonUnitalSemiring.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (NonUnitalCommRing.toNonUnitalRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (CommRing.toNonUnitalCommRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Polynomial.commRing.{u1} R _inst_1))))))) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) p\nCase conversion may be inaccurate. Consider using '#align polynomial.C_content_dvd Polynomial.C_content_dvd\u2093'. -/\ntheorem C_content_dvd (p : R[X]) : C p.content \u2223 p :=\n  dvd_content_iff_C_dvd.1 dvd_rfl\n#align polynomial.C_content_dvd Polynomial.C_content_dvd\n\n/- warning: polynomial.is_primitive_iff_content_eq_one -> Polynomial.isPrimitive_iff_content_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Iff (Polynomial.IsPrimitive.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) p) (Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddGroupWithOne.toAddMonoidWithOne.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Iff (Polynomial.IsPrimitive.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) p) (Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (NonAssocRing.toOne.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.is_primitive_iff_content_eq_one Polynomial.isPrimitive_iff_content_eq_one\u2093'. -/\ntheorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive \u2194 p.content = 1 :=\n  by\n  rw [\u2190 normalize_content, normalize_eq_one, is_primitive]\n  simp_rw [\u2190 dvd_content_iff_C_dvd]\n  exact \u27e8fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h\u27e9\n#align polynomial.is_primitive_iff_content_eq_one Polynomial.isPrimitive_iff_content_eq_one\n\n/- warning: polynomial.is_primitive.content_eq_one -> Polynomial.IsPrimitive.content_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, (Polynomial.IsPrimitive.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) p) -> (Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddGroupWithOne.toAddMonoidWithOne.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, (Polynomial.IsPrimitive.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) p) -> (Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (NonAssocRing.toOne.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.is_primitive.content_eq_one Polynomial.IsPrimitive.content_eq_one\u2093'. -/\ntheorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 :=\n  isPrimitive_iff_content_eq_one.mp hp\n#align polynomial.is_primitive.content_eq_one Polynomial.IsPrimitive.content_eq_one\n\nopen Classical\n\nnoncomputable section\n\nsection PrimPart\n\n#print Polynomial.primPart /-\n/-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by\n  `p.content`. If `p = 0`, then `p.prim_part = 1`.  -/\ndef primPart (p : R[X]) : R[X] :=\n  if p = 0 then 1 else Classical.choose (C_content_dvd p)\n#align polynomial.prim_part Polynomial.primPart\n-/\n\n/- warning: polynomial.eq_C_content_mul_prim_part -> Polynomial.eq_C_content_mul_primPart is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Eq.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.eq_C_content_mul_prim_part Polynomial.eq_C_content_mul_primPart\u2093'. -/\ntheorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart :=\n  by\n  by_cases h : p = 0; \u00b7 simp [h]\n  rw [prim_part, if_neg h, \u2190 Classical.choose_spec (C_content_dvd p)]\n#align polynomial.eq_C_content_mul_prim_part Polynomial.eq_C_content_mul_primPart\n\n#print Polynomial.primPart_zero /-\n@[simp]\ntheorem primPart_zero : primPart (0 : R[X]) = 1 :=\n  if_pos rfl\n#align polynomial.prim_part_zero Polynomial.primPart_zero\n-/\n\n#print Polynomial.isPrimitive_primPart /-\ntheorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive :=\n  by\n  by_cases h : p = 0; \u00b7 simp [h]\n  rw [\u2190 content_eq_zero_iff] at h\n  rw [is_primitive_iff_content_eq_one]\n  apply mul_left_cancel\u2080 h\n  conv_rhs => rw [p.eq_C_content_mul_prim_part, mul_one, content_C_mul, normalize_content]\n#align polynomial.is_primitive_prim_part Polynomial.isPrimitive_primPart\n-/\n\n/- warning: polynomial.content_prim_part -> Polynomial.content_primPart is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddGroupWithOne.toAddMonoidWithOne.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (CommRing.toRing.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))), Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (NonAssocRing.toOne.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_prim_part Polynomial.content_primPart\u2093'. -/\ntheorem content_primPart (p : R[X]) : p.primPart.content = 1 :=\n  p.isPrimitive_primPart.content_eq_one\n#align polynomial.content_prim_part Polynomial.content_primPart\n\n#print Polynomial.primPart_ne_zero /-\ntheorem primPart_ne_zero (p : R[X]) : p.primPart \u2260 0 :=\n  p.isPrimitive_primPart.NeZero\n#align polynomial.prim_part_ne_zero Polynomial.primPart_ne_zero\n-/\n\n#print Polynomial.natDegree_primPart /-\ntheorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree :=\n  by\n  by_cases h : C p.content = 0\n  \u00b7 rw [C_eq_zero, content_eq_zero_iff] at h\n    simp [h]\n  conv_rhs =>\n    rw [p.eq_C_content_mul_prim_part, nat_degree_mul h p.prim_part_ne_zero, nat_degree_C, zero_add]\n#align polynomial.nat_degree_prim_part Polynomial.natDegree_primPart\n-/\n\n#print Polynomial.IsPrimitive.primPart_eq /-\n@[simp]\ntheorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by\n  rw [\u2190 one_mul p.prim_part, \u2190 C_1, \u2190 hp.content_eq_one, \u2190 p.eq_C_content_mul_prim_part]\n#align polynomial.is_primitive.prim_part_eq Polynomial.IsPrimitive.primPart_eq\n-/\n\n/- warning: polynomial.is_unit_prim_part_C -> Polynomial.isUnit_primPart_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (r : R), IsUnit.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Ring.toMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.ring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] (r : R), IsUnit.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (MonoidWithZero.toMonoid.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toMonoidWithZero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) r))\nCase conversion may be inaccurate. Consider using '#align polynomial.is_unit_prim_part_C Polynomial.isUnit_primPart_C\u2093'. -/\ntheorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart :=\n  by\n  by_cases h0 : r = 0\n  \u00b7 simp [h0]\n  unfold IsUnit\n  refine'\n    \u27e8\u27e8C \u2191(norm_unit r)\u207b\u00b9, C \u2191(norm_unit r), by rw [\u2190 RingHom.map_mul, Units.inv_mul, C_1], by\n        rw [\u2190 RingHom.map_mul, Units.mul_inv, C_1]\u27e9,\n      _\u27e9\n  rw [\u2190 normalize_eq_zero, \u2190 C_eq_zero] at h0\n  apply mul_left_cancel\u2080 h0\n  conv_rhs => rw [\u2190 content_C, \u2190 (C r).eq_C_content_mul_primPart]\n  simp only [Units.val_mk, normalize_apply, RingHom.map_mul]\n  rw [mul_assoc, \u2190 RingHom.map_mul, Units.mul_inv, C_1, mul_one]\n#align polynomial.is_unit_prim_part_C Polynomial.isUnit_primPart_C\n\n#print Polynomial.primPart_dvd /-\ntheorem primPart_dvd (p : R[X]) : p.primPart \u2223 p :=\n  Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm\n#align polynomial.prim_part_dvd Polynomial.primPart_dvd\n-/\n\n/- warning: polynomial.aeval_prim_part_eq_zero -> Polynomial.aeval_primPart_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {S : Type.{u2}} [_inst_4 : Ring.{u2} S] [_inst_5 : IsDomain.{u2} S (Ring.toSemiring.{u2} S _inst_4)] [_inst_6 : Algebra.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4)] [_inst_7 : NoZeroSMulDivisors.{u1, u2} R S (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u2} S (NonAssocRing.toNonUnitalNonAssocRing.{u2} S (Ring.toNonAssocRing.{u2} S _inst_4))))) (SMulZeroClass.toHasSmul.{u1, u2} R S (AddZeroClass.toHasZero.{u2} S (AddMonoid.toAddZeroClass.{u2} S (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))))))) (SMulWithZero.toSmulZeroClass.{u1, u2} R S (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (AddZeroClass.toHasZero.{u2} S (AddMonoid.toAddZeroClass.{u2} S (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))))))) (MulActionWithZero.toSMulWithZero.{u1, u2} R S (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddZeroClass.toHasZero.{u2} S (AddMonoid.toAddZeroClass.{u2} S (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))))))) (Module.toMulActionWithZero.{u1, u2} R S (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))) (Algebra.toModule.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6)))))] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {s : S}, (Ne.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (OfNat.mk.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.zero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))))) -> (Eq.{succ u2} S (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (fun (_x : AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) => (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) -> S) ([anonymous].{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (Polynomial.aeval.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6 s) p) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u2} S (NonAssocRing.toNonUnitalNonAssocRing.{u2} S (Ring.toNonAssocRing.{u2} S _inst_4))))))))) -> (Eq.{succ u2} S (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (fun (_x : AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) => (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) -> S) ([anonymous].{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (Polynomial.aeval.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6 s) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u2} S (NonAssocRing.toNonUnitalNonAssocRing.{u2} S (Ring.toNonAssocRing.{u2} S _inst_4)))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {S : Type.{u2}} [_inst_4 : Ring.{u2} S] [_inst_5 : IsDomain.{u2} S (Ring.toSemiring.{u2} S _inst_4)] [_inst_6 : Algebra.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4)] [_inst_7 : NoZeroSMulDivisors.{u1, u2} R S (CommMonoidWithZero.toZero.{u1} R (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2))) (MonoidWithZero.toZero.{u2} S (Semiring.toMonoidWithZero.{u2} S (Ring.toSemiring.{u2} S _inst_4))) (Algebra.toSMul.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {s : S}, (Ne.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) -> (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) p) (FunLike.coe.{max (succ u2) (succ u1), succ u1, succ u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (fun (_x : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => (fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) _x) (SMulHomClass.toFunLike.{max u2 u1, u1, u1, u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (SMulZeroClass.toSMul.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddMonoid.toZero.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))))) (DistribSMul.toSMulZeroClass.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))))) (DistribMulAction.toDistribSMul.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))))) (Module.toDistribMulAction.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (Algebra.toModule.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))))) (SMulZeroClass.toSMul.{u1, u2} R S (AddMonoid.toZero.{u2} S (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))))) (DistribSMul.toSMulZeroClass.{u1, u2} R S (AddMonoid.toAddZeroClass.{u2} S (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))))) (DistribMulAction.toDistribSMul.{u1, u2} R S (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))))) (Module.toDistribMulAction.{u1, u2} R S (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))) (Algebra.toModule.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6))))) (DistribMulActionHomClass.toSMulHomClass.{max u2 u1, u1, u1, u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))))) (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))))) (Module.toDistribMulAction.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (Algebra.toModule.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))) (Module.toDistribMulAction.{u1, u2} R S (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))) (Algebra.toModule.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6)) (NonUnitalAlgHomClass.toDistribMulActionHomClass.{max u2 u1, u1, u1, u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))) (Module.toDistribMulAction.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (Algebra.toModule.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))) (Module.toDistribMulAction.{u1, u2} R S (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))) (Algebra.toModule.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6)) (AlgHom.instNonUnitalAlgHomClassToMonoidToMonoidWithZeroToSemiringToNonUnitalNonAssocSemiringToNonAssocSemiringToNonUnitalNonAssocSemiringToNonAssocSemiringToDistribMulActionToAddCommMonoidToModuleToDistribMulActionToAddCommMonoidToModule.{u1, u1, u2, max u2 u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6 (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (AlgHom.algHomClass.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6))))) (Polynomial.aeval.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6 s) p) (OfNat.ofNat.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) p) 0 (Zero.toOfNat0.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) p) (MonoidWithZero.toZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) p) (Semiring.toMonoidWithZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) p) (Ring.toSemiring.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) p) _inst_4)))))) -> (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (FunLike.coe.{max (succ u2) (succ u1), succ u1, succ u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (fun (_x : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => (fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) _x) (SMulHomClass.toFunLike.{max u2 u1, u1, u1, u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (SMulZeroClass.toSMul.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddMonoid.toZero.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))))) (DistribSMul.toSMulZeroClass.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddMonoid.toAddZeroClass.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))))) (DistribMulAction.toDistribSMul.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))))) (Module.toDistribMulAction.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (Algebra.toModule.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))))) (SMulZeroClass.toSMul.{u1, u2} R S (AddMonoid.toZero.{u2} S (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))))) (DistribSMul.toSMulZeroClass.{u1, u2} R S (AddMonoid.toAddZeroClass.{u2} S (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))))) (DistribMulAction.toDistribSMul.{u1, u2} R S (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))))) (Module.toDistribMulAction.{u1, u2} R S (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))) (Algebra.toModule.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6))))) (DistribMulActionHomClass.toSMulHomClass.{max u2 u1, u1, u1, u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (AddCommMonoid.toAddMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))))) (AddCommMonoid.toAddMonoid.{u2} S (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))))) (Module.toDistribMulAction.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (Algebra.toModule.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))) (Module.toDistribMulAction.{u1, u2} R S (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))) (Algebra.toModule.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6)) (NonUnitalAlgHomClass.toDistribMulActionHomClass.{max u2 u1, u1, u1, u2} (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4))) (Module.toDistribMulAction.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (Algebra.toModule.{u1, u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))))) (Module.toDistribMulAction.{u1, u2} R S (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S (Ring.toSemiring.{u2} S _inst_4)))) (Algebra.toModule.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6)) (AlgHom.instNonUnitalAlgHomClassToMonoidToMonoidWithZeroToSemiringToNonUnitalNonAssocSemiringToNonAssocSemiringToNonUnitalNonAssocSemiringToNonAssocSemiringToDistribMulActionToAddCommMonoidToModuleToDistribMulActionToAddCommMonoidToModule.{u1, u1, u2, max u2 u1} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6 (AlgHom.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6) (AlgHom.algHomClass.{u1, u1, u2} R (Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) S (CommRing.toCommSemiring.{u1} R _inst_1) (Polynomial.semiring.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (Ring.toSemiring.{u2} S _inst_4) (Polynomial.algebraOfAlgebra.{u1, u1} R R (CommRing.toCommSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (Algebra.id.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) _inst_6))))) (Polynomial.aeval.{u1, u2} R S (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} S _inst_4) _inst_6 s) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (OfNat.ofNat.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) 0 (Zero.toOfNat0.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (MonoidWithZero.toZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (Semiring.toMonoidWithZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (Ring.toSemiring.{u2} ((fun (x._@.Mathlib.Algebra.Hom.GroupAction._hyg.2186 : Polynomial.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) => S) (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) _inst_4))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.aeval_prim_part_eq_zero Polynomial.aeval_primPart_eq_zero\u2093'. -/\ntheorem aeval_primPart_eq_zero {S : Type _} [Ring S] [IsDomain S] [Algebra R S]\n    [NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p \u2260 0) (hp : aeval s p = 0) :\n    aeval s p.primPart = 0 :=\n  by\n  rw [eq_C_content_mul_prim_part p, map_mul, aeval_C] at hp\n  have hcont : p.content \u2260 0 := fun h => hpzero (content_eq_zero_iff.1 h)\n  replace hcont := Function.Injective.ne (NoZeroSMulDivisors.algebraMap_injective R S) hcont\n  rw [map_zero] at hcont\n  exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp\n#align polynomial.aeval_prim_part_eq_zero Polynomial.aeval_primPart_eq_zero\n\n/- warning: polynomial.eval\u2082_prim_part_eq_zero -> Polynomial.eval\u2082_primPart_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {S : Type.{u2}} [_inst_4 : CommRing.{u2} S] [_inst_5 : IsDomain.{u2} S (Ring.toSemiring.{u2} S (CommRing.toRing.{u2} S _inst_4))] {f : RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))}, (Function.Injective.{succ u1, succ u2} R S (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) (fun (_x : RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) => R -> S) (RingHom.hasCoeToFun.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) f)) -> (forall {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {s : S}, (Ne.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (OfNat.mk.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.zero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))))) -> (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u2} S (CommRing.toRing.{u2} S _inst_4)) f s p) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u2} S (NonAssocRing.toNonUnitalNonAssocRing.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))))))))) -> (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u2} S (CommRing.toRing.{u2} S _inst_4)) f s (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u2} S (NonAssocRing.toNonUnitalNonAssocRing.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {S : Type.{u2}} [_inst_4 : CommRing.{u2} S] [_inst_5 : IsDomain.{u2} S (Ring.toSemiring.{u2} S (CommRing.toRing.{u2} S _inst_4))] {f : RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))}, (Function.Injective.{succ u1, succ u2} R S (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) _x) (MulHomClass.toFunLike.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) R S (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4))))) (NonUnitalRingHomClass.toMulHomClass.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) R S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) (RingHomClass.toNonUnitalRingHomClass.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4)))) R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4))) (RingHom.instRingHomClassRingHom.{u1, u2} R S (NonAssocRing.toNonAssocSemiring.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocRing.toNonAssocSemiring.{u2} S (Ring.toNonAssocRing.{u2} S (CommRing.toRing.{u2} S _inst_4))))))) f)) -> (forall {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {s : S}, (Ne.{succ u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) p (OfNat.ofNat.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.zero.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) -> (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u2} S (CommRing.toRing.{u2} S _inst_4)) f s p) (OfNat.ofNat.{u2} S 0 (Zero.toOfNat0.{u2} S (CommMonoidWithZero.toZero.{u2} S (CancelCommMonoidWithZero.toCommMonoidWithZero.{u2} S (IsDomain.toCancelCommMonoidWithZero.{u2} S (CommRing.toCommSemiring.{u2} S _inst_4) _inst_5)))))) -> (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)) (Ring.toSemiring.{u2} S (CommRing.toRing.{u2} S _inst_4)) f s (Polynomial.primPart.{u1} R _inst_1 _inst_2 _inst_3 p)) (OfNat.ofNat.{u2} S 0 (Zero.toOfNat0.{u2} S (CommMonoidWithZero.toZero.{u2} S (CancelCommMonoidWithZero.toCommMonoidWithZero.{u2} S (IsDomain.toCancelCommMonoidWithZero.{u2} S (CommRing.toCommSemiring.{u2} S _inst_4) _inst_5)))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.eval\u2082_prim_part_eq_zero Polynomial.eval\u2082_primPart_eq_zero\u2093'. -/\ntheorem eval\u2082_primPart_eq_zero {S : Type _} [CommRing S] [IsDomain S] {f : R \u2192+* S}\n    (hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p \u2260 0) (hp : eval\u2082 f s p = 0) :\n    eval\u2082 f s p.primPart = 0 :=\n  by\n  rw [eq_C_content_mul_prim_part p, eval\u2082_mul, eval\u2082_C] at hp\n  have hcont : p.content \u2260 0 := fun h => hpzero (content_eq_zero_iff.1 h)\n  replace hcont := Function.Injective.ne hinj hcont\n  rw [map_zero] at hcont\n  exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp\n#align polynomial.eval\u2082_prim_part_eq_zero Polynomial.eval\u2082_primPart_eq_zero\n\nend PrimPart\n\n/- warning: polynomial.gcd_content_eq_of_dvd_sub -> Polynomial.gcd_content_eq_of_dvd_sub is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {a : R} {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {q : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, (Dvd.Dvd.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (semigroupDvd.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (SemigroupWithZero.toSemigroup.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalSemiring.toSemigroupWithZero.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalRing.toNonUnitalSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalCommRing.toNonUnitalRing.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (CommRing.toNonUnitalCommRing.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.commRing.{u1} R _inst_1))))))) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) => R -> (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.sub.{u1} R (CommRing.toRing.{u1} R _inst_1))) p q)) -> (Eq.{succ u1} R (GCDMonoid.gcd.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toGcdMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3) a (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (GCDMonoid.gcd.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toGcdMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3) a (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 q)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {a : R} {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {q : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, (Dvd.dvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (semigroupDvd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (SemigroupWithZero.toSemigroup.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (NonUnitalSemiring.toSemigroupWithZero.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (NonUnitalRing.toNonUnitalSemiring.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (NonUnitalCommRing.toNonUnitalRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (CommRing.toNonUnitalCommRing.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (Polynomial.commRing.{u1} R _inst_1))))))) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))))) R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.semiring.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))))))) (Polynomial.C.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) a) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.sub.{u1} R (CommRing.toRing.{u1} R _inst_1))) p q)) -> (Eq.{succ u1} R (GCDMonoid.gcd.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3) a (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p)) (GCDMonoid.gcd.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) (NormalizedGCDMonoid.toGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2) _inst_3) a (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 q)))\nCase conversion may be inaccurate. Consider using '#align polynomial.gcd_content_eq_of_dvd_sub Polynomial.gcd_content_eq_of_dvd_sub\u2093'. -/\ntheorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a \u2223 p - q) :\n    GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content :=\n  by\n  rw [content_eq_gcd_range_of_lt p (max p.nat_degree q.nat_degree).succ\n      (lt_of_le_of_lt (le_max_left _ _) (Nat.lt_succ_self _))]\n  rw [content_eq_gcd_range_of_lt q (max p.nat_degree q.nat_degree).succ\n      (lt_of_le_of_lt (le_max_right _ _) (Nat.lt_succ_self _))]\n  apply Finset.gcd_eq_of_dvd_sub\n  intro x hx\n  cases' h with w hw\n  use w.coeff x\n  rw [\u2190 coeff_sub, hw, coeff_C_mul]\n#align polynomial.gcd_content_eq_of_dvd_sub Polynomial.gcd_content_eq_of_dvd_sub\n\n#print Polynomial.content_mul_aux /-\ntheorem content_mul_aux {p q : R[X]} :\n    GCDMonoid.gcd (p * q).eraseLead.content p.leadingCoeff =\n      GCDMonoid.gcd (p.eraseLead * q).content p.leadingCoeff :=\n  by\n  rw [gcd_comm (content _) _, gcd_comm (content _) _]\n  apply gcd_content_eq_of_dvd_sub\n  rw [\u2190 self_sub_C_mul_X_pow, \u2190 self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,\n    sub_sub_cancel, leading_coeff_mul, RingHom.map_mul, mul_assoc, mul_assoc]\n  apply dvd_sub (Dvd.intro _ rfl) (Dvd.intro _ rfl)\n#align polynomial.content_mul_aux Polynomial.content_mul_aux\n-/\n\n/- warning: polynomial.content_mul -> Polynomial.content_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {q : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) p q)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (Ring.toDistrib.{u1} R (CommRing.toRing.{u1} R _inst_1)))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 q))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))] [_inst_3 : NormalizedGCDMonoid.{u1} R (IsDomain.toCancelCommMonoidWithZero.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1) _inst_2)] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))} {q : Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))}, Eq.{succ u1} R (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (instHMul.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1))) (Polynomial.mul'.{u1} R (Ring.toSemiring.{u1} R (CommRing.toRing.{u1} R _inst_1)))) p q)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocRing.toMul.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R (CommRing.toRing.{u1} R _inst_1))))) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 p) (Polynomial.content.{u1} R _inst_1 _inst_2 _inst_3 q))\nCase conversion may be inaccurate. Consider using '#align polynomial.content_mul Polynomial.content_mul\u2093'. -/\n@[simp]\ntheorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by\n  classical\n    suffices h :\n      \u2200 (n : \u2115) (p q : R[X]), (p * q).degree < n \u2192 (p * q).content = p.content * q.content\n    \u00b7 apply h\n      apply lt_of_le_of_lt degree_le_nat_degree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _))\n    intro n\n    induction' n with n ih\n    \u00b7 intro p q hpq\n      rw [WithBot.coe_zero, Nat.WithBot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq\n      rcases hpq with (rfl | rfl) <;> simp\n    intro p q hpq\n    by_cases p0 : p = 0\n    \u00b7 simp [p0]\n    by_cases q0 : q = 0\n    \u00b7 simp [q0]\n    rw [degree_eq_nat_degree (mul_ne_zero p0 q0), WithBot.coe_lt_coe, Nat.lt_succ_iff_lt_or_eq, \u2190\n      WithBot.coe_lt_coe, \u2190 degree_eq_nat_degree (mul_ne_zero p0 q0), nat_degree_mul p0 q0] at hpq\n    rcases hpq with (hlt | heq)\n    \u00b7 apply ih _ _ hlt\n    rw [\u2190 p.nat_degree_prim_part, \u2190 q.nat_degree_prim_part, \u2190 WithBot.coe_eq_coe, WithBot.coe_add, \u2190\n      degree_eq_nat_degree p.prim_part_ne_zero, \u2190 degree_eq_nat_degree q.prim_part_ne_zero] at heq\n    rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part]\n    suffices h : (q.prim_part * p.prim_part).content = 1\n    \u00b7\n      rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.prim_part, mul_assoc, content_C_mul,\n        content_C_mul, h, mul_one, content_prim_part, content_prim_part, mul_one, mul_one]\n    rw [\u2190 normalize_content, normalize_eq_one, isUnit_iff_dvd_one,\n      content_eq_gcd_leading_coeff_content_erase_lead, leading_coeff_mul, gcd_comm]\n    apply (gcd_mul_dvd_mul_gcd _ _ _).trans\n    rw [content_mul_aux, ih, content_prim_part, mul_one, gcd_comm, \u2190\n      content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part, one_mul,\n      mul_comm q.prim_part, content_mul_aux, ih, content_prim_part, mul_one, gcd_comm, \u2190\n      content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part]\n    \u00b7 rw [\u2190 HEq, degree_mul, WithBot.add_lt_add_iff_right]\n      \u00b7 apply degree_erase_lt p.prim_part_ne_zero\n      \u00b7 rw [Ne.def, degree_eq_bot]\n        apply q.prim_part_ne_zero\n    \u00b7 rw [mul_comm, \u2190 HEq, degree_mul, WithBot.add_lt_add_iff_left]\n      \u00b7 apply degree_erase_lt q.prim_part_ne_zero\n      \u00b7 rw [Ne.def, degree_eq_bot]\n        apply p.prim_part_ne_zero\n#align polynomial.content_mul Polynomial.content_mul\n\n#print Polynomial.IsPrimitive.mul /-\ntheorem IsPrimitive.mul {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :\n    (p * q).IsPrimitive := by\n  rw [is_primitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one]\n#align polynomial.is_primitive.mul Polynomial.IsPrimitive.mul\n-/\n\n#print Polynomial.primPart_mul /-\n@[simp]\ntheorem primPart_mul {p q : R[X]} (h0 : p * q \u2260 0) : (p * q).primPart = p.primPart * q.primPart :=\n  by\n  rw [Ne.def, \u2190 content_eq_zero_iff, \u2190 C_eq_zero] at h0\n  apply mul_left_cancel\u2080 h0\n  conv_lhs =>\n    rw [\u2190 (p * q).eq_C_content_mul_primPart, p.eq_C_content_mul_prim_part,\n      q.eq_C_content_mul_prim_part]\n  rw [content_mul, RingHom.map_mul]\n  ring\n#align polynomial.prim_part_mul Polynomial.primPart_mul\n-/\n\n#print Polynomial.IsPrimitive.dvd_primPart_iff_dvd /-\ntheorem IsPrimitive.dvd_primPart_iff_dvd {p q : R[X]} (hp : p.IsPrimitive) (hq : q \u2260 0) :\n    p \u2223 q.primPart \u2194 p \u2223 q :=\n  by\n  refine' \u27e8fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_prim_part.symm), fun h => _\u27e9\n  rcases h with \u27e8r, rfl\u27e9\n  apply Dvd.intro _\n  rw [prim_part_mul hq, hp.prim_part_eq]\n#align polynomial.is_primitive.dvd_prim_part_iff_dvd Polynomial.IsPrimitive.dvd_primPart_iff_dvd\n-/\n\n#print Polynomial.exists_primitive_lcm_of_isPrimitive /-\ntheorem exists_primitive_lcm_of_isPrimitive {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :\n    \u2203 r : R[X], r.IsPrimitive \u2227 \u2200 s : R[X], p \u2223 s \u2227 q \u2223 s \u2194 r \u2223 s := by\n  classical\n    have h : \u2203 (n : \u2115)(r : R[X]), r.natDegree = n \u2227 r.IsPrimitive \u2227 p \u2223 r \u2227 q \u2223 r :=\n      \u27e8(p * q).natDegree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _\u27e9\n    rcases Nat.find_spec h with \u27e8r, rdeg, rprim, pr, qr\u27e9\n    refine' \u27e8r, rprim, fun s => \u27e8_, fun rs => \u27e8pr.trans rs, qr.trans rs\u27e9\u27e9\u27e9\n    suffices hs : \u2200 (n : \u2115) (s : R[X]), s.natDegree = n \u2192 p \u2223 s \u2227 q \u2223 s \u2192 r \u2223 s\n    \u00b7 apply hs s.nat_degree s rfl\n    clear s\n    by_contra' con\n    rcases Nat.find_spec Con with \u27e8s, sdeg, \u27e8ps, qs\u27e9, rs\u27e9\n    have s0 : s \u2260 0 := by\n      contrapose! rs\n      simp [rs]\n    have hs :=\n      Nat.find_min' h\n        \u27e8_, s.nat_degree_prim_part, s.is_primitive_prim_part, (hp.dvd_prim_part_iff_dvd s0).2 ps,\n          (hq.dvd_prim_part_iff_dvd s0).2 qs\u27e9\n    rw [\u2190 rdeg] at hs\n    by_cases sC : s.nat_degree \u2264 0\n    \u00b7 rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), is_primitive_iff_content_eq_one, content_C,\n        normalize_eq_one] at rprim\n      rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), \u2190 dvd_content_iff_C_dvd] at rs\n      apply rs rprim.dvd\n    have hcancel := nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree hs (lt_of_not_ge sC)\n    rw [sdeg] at hcancel\n    apply Nat.find_min Con hcancel\n    refine'\n      \u27e8_, rfl, \u27e8dvd_cancel_leads_of_dvd_of_dvd pr ps, dvd_cancel_leads_of_dvd_of_dvd qr qs\u27e9,\n        fun rcs => rs _\u27e9\n    rw [\u2190 rprim.dvd_prim_part_iff_dvd s0]\n    rw [cancel_leads, tsub_eq_zero_iff_le.mpr hs, pow_zero, mul_one] at rcs\n    have h := dvd_add rcs (Dvd.intro_left _ rfl)\n    have hC0 := rprim.ne_zero\n    rw [Ne.def, \u2190 leading_coeff_eq_zero, \u2190 C_eq_zero] at hC0\n    rw [sub_add_cancel, \u2190 rprim.dvd_prim_part_iff_dvd (mul_ne_zero hC0 s0)] at h\n    rcases is_unit_prim_part_C r.leading_coeff with \u27e8u, hu\u27e9\n    apply h.trans (Associated.symm \u27e8u, _\u27e9).Dvd\n    rw [prim_part_mul (mul_ne_zero hC0 s0), hu, mul_comm]\n#align polynomial.exists_primitive_lcm_of_is_primitive Polynomial.exists_primitive_lcm_of_isPrimitive\n-/\n\n#print Polynomial.dvd_iff_content_dvd_content_and_primPart_dvd_primPart /-\ntheorem dvd_iff_content_dvd_content_and_primPart_dvd_primPart {p q : R[X]} (hq : q \u2260 0) :\n    p \u2223 q \u2194 p.content \u2223 q.content \u2227 p.primPart \u2223 q.primPart :=\n  by\n  constructor <;> intro h\n  \u00b7 rcases h with \u27e8r, rfl\u27e9\n    rw [content_mul, p.is_primitive_prim_part.dvd_prim_part_iff_dvd hq]\n    exact \u27e8Dvd.intro _ rfl, p.prim_part_dvd.trans (Dvd.intro _ rfl)\u27e9\n  \u00b7 rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part]\n    exact mul_dvd_mul (RingHom.map_dvd C h.1) h.2\n#align polynomial.dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part Polynomial.dvd_iff_content_dvd_content_and_primPart_dvd_primPart\n-/\n\n#print Polynomial.normalizedGcdMonoid /-\ninstance (priority := 100) normalizedGcdMonoid : NormalizedGCDMonoid R[X] :=\n  normalizedGCDMonoidOfExistsLCM fun p q =>\n    by\n    rcases exists_primitive_lcm_of_is_primitive p.is_primitive_prim_part\n        q.is_primitive_prim_part with\n      \u27e8r, rprim, hr\u27e9\n    refine' \u27e8C (lcm p.content q.content) * r, fun s => _\u27e9\n    by_cases hs : s = 0\n    \u00b7 simp [hs]\n    by_cases hpq : C (lcm p.content q.content) = 0\n    \u00b7 rw [C_eq_zero, lcm_eq_zero_iff, content_eq_zero_iff, content_eq_zero_iff] at hpq\n      rcases hpq with (hpq | hpq) <;> simp [hpq, hs]\n    iterate 3 rw [dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part hs]\n    rw [content_mul, rprim.content_eq_one, mul_one, content_C, normalize_lcm, lcm_dvd_iff,\n      prim_part_mul (mul_ne_zero hpq rprim.ne_zero), rprim.prim_part_eq,\n      IsUnit.mul_left_dvd _ _ _ (is_unit_prim_part_C (lcm p.content q.content)), \u2190 hr s.prim_part]\n    tauto\n#align polynomial.normalized_gcd_monoid Polynomial.normalizedGcdMonoid\n-/\n\n#print Polynomial.degree_gcd_le_left /-\ntheorem degree_gcd_le_left {p : R[X]} (hp : p \u2260 0) (q) : (gcd p q).degree \u2264 p.degree :=\n  by\n  have := nat_degree_le_iff_degree_le.mp (nat_degree_le_of_dvd (gcd_dvd_left p q) hp)\n  rwa [degree_eq_nat_degree hp]\n#align polynomial.degree_gcd_le_left Polynomial.degree_gcd_le_left\n-/\n\n#print Polynomial.degree_gcd_le_right /-\ntheorem degree_gcd_le_right (p) {q : R[X]} (hq : q \u2260 0) : (gcd p q).degree \u2264 q.degree :=\n  by\n  rw [gcd_comm]\n  exact degree_gcd_le_left hq p\n#align polynomial.degree_gcd_le_right Polynomial.degree_gcd_le_right\n-/\n\nend NormalizedGCDMonoid\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RingTheory/Polynomial/Content.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7236910688878696}}
{"text": "/-\nCopyright (c) 2020 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann\n-/\nimport algebra.order.floor\nimport algebra.continued_fractions.basic\n\n/-!\n# Computable Continued Fractions\n\n## Summary\n\nWe formalise the standard computation of (regular) continued fractions for linear ordered floor\nfields. The algorithm is rather simple. Here is an outline of the procedure adapted from Wikipedia:\n\nTake a value `v`. We call `\u230av\u230b` the *integer part* of `v` and `v - \u230av\u230b` the *fractional part* of\n`v`.  A continued fraction representation of `v` can then be given by `[\u230av\u230b; b\u2080, b\u2081, b\u2082,...]`, where\n`[b\u2080; b\u2081, b\u2082,...]` recursively is the continued fraction representation of `1 / (v - \u230av\u230b)`.  This\nprocess stops when the fractional part hits 0.\n\nIn other words: to calculate a continued fraction representation of a number `v`, write down the\ninteger part (i.e. the floor) of `v`. Subtract this integer part from `v`. If the difference is 0,\nstop; otherwise find the reciprocal of the difference and repeat. The procedure will terminate if\nand only if `v` is rational.\n\nFor an example, refer to `int_fract_pair.stream`.\n\n## Main definitions\n\n- `generalized_continued_fraction.int_fract_pair.stream`: computes the stream of integer and\n  fractional parts of a given value as described in the summary.\n- `generalized_continued_fraction.of`: computes the generalised continued fraction of a value `v`.\n  In fact, it computes a regular continued fraction that terminates if and only if `v` is rational.\n\n## Implementation Notes\n\nThere is an intermediate definition `generalized_continued_fraction.int_fract_pair.seq1` between\n`generalized_continued_fraction.int_fract_pair.stream` and `generalized_continued_fraction.of`\nto wire up things. User should not (need to) directly interact with it.\n\nThe computation of the integer and fractional pairs of a value can elegantly be\ncaptured by a recursive computation of a stream of option pairs. This is done in\n`int_fract_pair.stream`. However, the type then does not guarantee the first pair to always be\n`some` value, as expected by a continued fraction.\n\nTo separate concerns, we first compute a single head term that always exists in\n`generalized_continued_fraction.int_fract_pair.seq1` followed by the remaining stream of option\npairs. This sequence with a head term (`seq1`) is then transformed to a generalized continued\nfraction in `generalized_continued_fraction.of` by extracting the wanted integer parts of the\nhead term and the stream.\n\n## References\n\n- https://en.wikipedia.org/wiki/Continued_fraction\n\n## Tags\n\nnumerics, number theory, approximations, fractions\n-/\n\nnamespace generalized_continued_fraction\n\n-- Fix a carrier `K`.\nvariable (K : Type*)\n\n/--\nWe collect an integer part `b = \u230av\u230b` and fractional part `fr = v - \u230av\u230b` of a value `v` in a pair\n`\u27e8b, fr\u27e9`.\n-/\nstructure int_fract_pair := (b : \u2124) (fr : K)\n\nvariable {K}\n\n/-! Interlude: define some expected coercions and instances. -/\nnamespace int_fract_pair\n\n/-- Make an `int_fract_pair` printable. -/\ninstance [has_repr K] : has_repr (int_fract_pair K) :=\n\u27e8\u03bb p, \"(b : \" ++ (repr p.b) ++ \", fract : \" ++ (repr p.fr) ++ \")\"\u27e9\n\ninstance inhabited [inhabited K] : inhabited (int_fract_pair K) := \u27e8\u27e80, default\u27e9\u27e9\n\n/--\nMaps a function `f` on the fractional components of a given pair.\n-/\ndef mapFr {\u03b2 : Type*} (f : K \u2192 \u03b2) (gp : int_fract_pair K) : int_fract_pair \u03b2 :=\n\u27e8gp.b, f gp.fr\u27e9\n\nsection coe\n/-! Interlude: define some expected coercions. -/\n/- Fix another type `\u03b2` which we will convert to. -/\nvariables {\u03b2 : Type*} [has_coe K \u03b2]\n\n/-- Coerce a pair by coercing the fractional component. -/\ninstance has_coe_to_int_fract_pair : has_coe (int_fract_pair K) (int_fract_pair \u03b2) :=\n\u27e8mapFr coe\u27e9\n\n@[simp, norm_cast]\nlemma coe_to_int_fract_pair {b : \u2124} {fr : K} :\n  (\u2191(int_fract_pair.mk b fr) : int_fract_pair \u03b2) = int_fract_pair.mk b (\u2191fr : \u03b2) :=\nrfl\n\nend coe\n\n-- Note: this could be relaxed to something like `linear_ordered_division_ring` in the\n-- future.\n/- Fix a discrete linear ordered field with `floor` function. -/\nvariables [linear_ordered_field K] [floor_ring K]\n\n/-- Creates the integer and fractional part of a value `v`, i.e. `\u27e8\u230av\u230b, v - \u230av\u230b\u27e9`. -/\nprotected def of (v : K) : int_fract_pair K := \u27e8\u230av\u230b, int.fract v\u27e9\n\n/--\nCreates the stream of integer and fractional parts of a value `v` needed to obtain the continued\nfraction representation of `v` in `generalized_continued_fraction.of`. More precisely, given a value\n`v : K`, it recursively computes a stream of option `\u2124 \u00d7 K` pairs as follows:\n- `stream v 0 = some \u27e8\u230av\u230b, v - \u230av\u230b\u27e9`\n- `stream v (n + 1) = some \u27e8\u230afr\u2099\u207b\u00b9\u230b, fr\u2099\u207b\u00b9 - \u230afr\u2099\u207b\u00b9\u230b\u27e9`,\n    if `stream v n = some \u27e8_, fr\u2099\u27e9` and `fr\u2099 \u2260 0`\n- `stream v (n + 1) = none`, otherwise\n\nFor example, let `(v : \u211a) := 3.4`. The process goes as follows:\n- `stream v 0 = some \u27e8\u230av\u230b, v - \u230av\u230b\u27e9 = some \u27e83, 0.4\u27e9`\n- `stream v 1 = some \u27e8\u230a0.4\u207b\u00b9\u230b, 0.4\u207b\u00b9 - \u230a0.4\u207b\u00b9\u230b\u27e9 = some \u27e8\u230a2.5\u230b, 2.5 - \u230a2.5\u230b\u27e9 = some \u27e82, 0.5\u27e9`\n- `stream v 2 = some \u27e8\u230a0.5\u207b\u00b9\u230b, 0.5\u207b\u00b9 - \u230a0.5\u207b\u00b9\u230b\u27e9 = some \u27e8\u230a2\u230b, 2 - \u230a2\u230b\u27e9 = some \u27e82, 0\u27e9`\n- `stream v n = none`, for `n \u2265 3`\n-/\nprotected def stream (v : K) : stream $ option (int_fract_pair K)\n| 0 := some (int_fract_pair.of v)\n| (n + 1) := (stream n).bind $ \u03bb ap_n,\n  if ap_n.fr = 0 then none else some (int_fract_pair.of ap_n.fr\u207b\u00b9)\n\n\n/--\nShows that `int_fract_pair.stream` has the sequence property, that is once we return `none` at\nposition `n`, we also return `none` at `n + 1`.\n-/\nlemma stream_is_seq (v : K) : (int_fract_pair.stream v).is_seq :=\nby { assume _ hyp, simp [int_fract_pair.stream, hyp] }\n\n/--\nUses `int_fract_pair.stream` to create a sequence with head (i.e. `seq1`) of integer and fractional\nparts of a value `v`. The first value of `int_fract_pair.stream` is never `none`, so we can safely\nextract it and put the tail of the stream in the sequence part.\n\nThis is just an intermediate representation and users should not (need to) directly interact with\nit. The setup of rewriting/simplification lemmas that make the definitions easy to use is done in\n`algebra.continued_fractions.computation.translations`.\n-/\nprotected def seq1 (v : K) : stream.seq1 $ int_fract_pair K :=\n\u27e8 int_fract_pair.of v,--the head\n  stream.seq.tail -- take the tail of `int_fract_pair.stream` since the first element is already in\n  -- the head\n  -- create a sequence from `int_fract_pair.stream`\n  \u27e8 int_fract_pair.stream v, -- the underlying stream\n    @stream_is_seq _ _ _ v \u27e9 \u27e9 -- the proof that the stream is a sequence\n\nend int_fract_pair\n\n/--\nReturns the `generalized_continued_fraction` of a value. In fact, the returned gcf is also\na `continued_fraction` that terminates if and only if `v` is rational (those proofs will be\nadded in a future commit).\n\nThe continued fraction representation of `v` is given by `[\u230av\u230b; b\u2080, b\u2081, b\u2082,...]`, where\n`[b\u2080; b\u2081, b\u2082,...]` recursively is the continued fraction representation of `1 / (v - \u230av\u230b)`. This\nprocess stops when the fractional part `v - \u230av\u230b` hits 0 at some step.\n\nThe implementation uses `int_fract_pair.stream` to obtain the partial denominators of the continued\nfraction. Refer to said function for more details about the computation process.\n-/\nprotected def of [linear_ordered_field K] [floor_ring K] (v : K) :\n  generalized_continued_fraction K :=\nlet \u27e8h, s\u27e9 := int_fract_pair.seq1 v in -- get the sequence of integer and fractional parts.\n\u27e8 h.b, -- the head is just the first integer part\n  s.map (\u03bb p, \u27e81, p.b\u27e9) \u27e9 -- the sequence consists of the remaining integer parts as the partial\n                          -- denominators; all partial numerators are simply 1\n\n\nend generalized_continued_fraction\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/continued_fractions/computation/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.723658555642878}}
{"text": "import game.sup_inf.lub_rationals\nimport data.real.basic\n\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 12\n-/\n\ndef unboundedAbove (A : set \u211d) := \u2200 x : \u211d, x > 0 \u2192 \u2203 a \u2208 A, x < a\n-- Might want to make this into an axiom to be placed on the left\ndef archimPrinciple := \u2200 x : \u211d, x > 0 \u2192  \u2203 n : \u2115, n > 0 \u2227 (1/n : \u211d) < x \n\n/- Lemma\nThe Archimedean principle is equivalent to the set of natural numbers being unbounded above.\n-/\nlemma nats_unbounded_iff : \n    unboundedAbove {x : \u211d | \u2203 n : \u2115, x = n \u2227 n > 0} \u2194 archimPrinciple :=\nbegin\n    split,\n    -- left-right implication\n    intros unb x hx,\n    set A := {x : \u211d | \u2203 n : \u2115, x = n \u2227 x > 0} with hA,\n    have h1x : (1/x) > 0, from one_div_pos_of_pos hx,\n    have h1 := unb (1/x) h1x,\n    -- rcases h1 with \u27e8nx, \u27e8n, rfl\u27e9, h2\u27e9,\n    cases h1 with nx hnx,\n    cases hnx with h1 h2,\n    cases h1 with xn h12,\n    existsi xn, rw h12.left at h2, \n    have h0 : 0 < (1:\u211d), norm_num,\n    have h3 := div_lt_div_of_pos_of_lt_of_pos h1x h2 h0,\n    split, exact h12.right,\n    simp at h3, simp, \n    exact h3,\n    -- right-left implication\n    intros arc x hx,\n    have h1x : (1/x) > 0, from one_div_pos_of_pos hx,\n    have h1 := arc (1/x) h1x,\n    cases h1 with n hn,\n    use n, split, \n    existsi n, split, refl, exact hn.left,\n    set xn : \u211d := \u2191n with hxn, \n    have h2n : 0 < xn, \n        rw hxn, \n        have hn0 : 0 < n, from hn.left, simp, assumption,\n    exact lt_of_one_div_lt_one_div h2n hn.right,\n    done\nend\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sup_inf/unbdd_iff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7236585432844527}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,\nNeil Strickland\n-/\nimport algebra.divisibility\nimport algebra.regular.basic\n\n/-!\n# Properties and homomorphisms of semirings and rings\n\nThis file proves simple properties of semirings, rings and domains and their unit groups. It also\ndefines bundled homomorphisms of semirings and rings. As with monoid and groups, we use the same\nstructure `ring_hom a \u03b2`, a.k.a. `\u03b1 \u2192+* \u03b2`, for both homomorphism types.\n\nThe unbundled homomorphisms are defined in `deprecated/ring`. They are deprecated and the plan is to\nslowly remove them from mathlib.\n\n## Main definitions\n\nring_hom, nonzero, domain, is_domain\n\n## Notations\n\n\u2192+* for bundled ring homs (also use for semiring homs)\n\n## Implementation notes\n\n* There's a coercion from bundled homs to fun, and the canonical notation is to\n  use the bundled hom as a function via this coercion.\n\n* There is no `semiring_hom` -- the idea is that `ring_hom` is used.\n  The constructor for a `ring_hom` between semirings needs a proof of `map_zero`,\n  `map_one` and `map_add` as well as `map_mul`; a separate constructor\n  `ring_hom.mk'` will construct ring homs between rings from monoid homs given\n  only a proof that addition is preserved.\n\n## Tags\n\n`ring_hom`, `semiring_hom`, `semiring`, `comm_semiring`, `ring`, `comm_ring`, `domain`,\n`is_domain`, `nonzero`, `units`\n-/\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {R : Type x}\n\nset_option old_structure_cmd true\nopen function\n\n/-!\n### `distrib` class\n-/\n\n/-- A typeclass stating that multiplication is left and right distributive\nover addition. -/\n@[protect_proj, ancestor has_mul has_add]\nclass distrib (R : Type*) extends has_mul R, has_add R :=\n(left_distrib : \u2200 a b c : R, a * (b + c) = (a * b) + (a * c))\n(right_distrib : \u2200 a b c : R, (a + b) * c = (a * c) + (b * c))\n\nlemma left_distrib [distrib R] (a b c : R) : a * (b + c) = a * b + a * c :=\ndistrib.left_distrib a b c\n\nalias left_distrib \u2190 mul_add\n\nlemma right_distrib [distrib R] (a b c : R) : (a + b) * c = a * c + b * c :=\ndistrib.right_distrib a b c\n\nalias right_distrib \u2190 add_mul\n\n/-- Pullback a `distrib` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.distrib {S} [has_mul R] [has_add R] [distrib S]\n  (f : R \u2192 S) (hf : injective f) (add : \u2200 x y, f (x + y) = f x + f y)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  distrib R :=\n{ mul := (*),\n  add := (+),\n  left_distrib := \u03bb x y z, hf $ by simp only [*, left_distrib],\n  right_distrib := \u03bb x y z, hf $ by simp only [*, right_distrib] }\n\n/-- Pushforward a `distrib` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.distrib {S} [distrib R] [has_add S] [has_mul S]\n  (f : R \u2192 S) (hf : surjective f) (add : \u2200 x y, f (x + y) = f x + f y)\n  (mul : \u2200 x y, f (x * y) = f x * f y) :\n  distrib S :=\n{ mul := (*),\n  add := (+),\n  left_distrib := hf.forall\u2083.2 $ \u03bb x y z, by simp only [\u2190 add, \u2190 mul, left_distrib],\n  right_distrib := hf.forall\u2083.2 $ \u03bb x y z, by simp only [\u2190 add, \u2190 mul, right_distrib] }\n\n/-!\n### Semirings\n-/\n\n/-- A not-necessarily-unital, not-necessarily-associative semiring. -/\n@[protect_proj, ancestor add_comm_monoid distrib mul_zero_class]\nclass non_unital_non_assoc_semiring (\u03b1 : Type u) extends\n  add_comm_monoid \u03b1, distrib \u03b1, mul_zero_class \u03b1\n\n/-- An associative but not-necessarily unital semiring. -/\n@[protect_proj, ancestor non_unital_non_assoc_semiring semigroup_with_zero]\nclass non_unital_semiring (\u03b1 : Type u) extends\n  non_unital_non_assoc_semiring \u03b1, semigroup_with_zero \u03b1\n\n/-- A unital but not-necessarily-associative semiring. -/\n@[protect_proj, ancestor non_unital_non_assoc_semiring mul_zero_one_class]\nclass non_assoc_semiring (\u03b1 : Type u) extends\n  non_unital_non_assoc_semiring \u03b1, mul_zero_one_class \u03b1\n\n/-- A semiring is a type with the following structures: additive commutative monoid\n(`add_comm_monoid`), multiplicative monoid (`monoid`), distributive laws (`distrib`), and\nmultiplication by zero law (`mul_zero_class`). The actual definition extends `monoid_with_zero`\ninstead of `monoid` and `mul_zero_class`. -/\n@[protect_proj, ancestor non_unital_semiring non_assoc_semiring monoid_with_zero]\nclass semiring (\u03b1 : Type u) extends non_unital_semiring \u03b1, non_assoc_semiring \u03b1, monoid_with_zero \u03b1\n\nsection injective_surjective_maps\n\nvariables [has_zero \u03b2] [has_add \u03b2] [has_mul \u03b2]\n\n/-- Pullback a `non_unital_non_assoc_semiring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.non_unital_non_assoc_semiring\n  {\u03b1 : Type u} [non_unital_non_assoc_semiring \u03b1]\n  (f : \u03b2 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  non_unital_non_assoc_semiring \u03b2 :=\n{ .. hf.mul_zero_class f zero mul, .. hf.add_comm_monoid f zero add, .. hf.distrib f add mul }\n\n/-- Pullback a `non_unital_semiring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.non_unital_semiring\n  {\u03b1 : Type u} [non_unital_semiring \u03b1]\n  (f : \u03b2 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  non_unital_semiring \u03b2 :=\n{ .. hf.non_unital_non_assoc_semiring f zero add mul, .. hf.semigroup_with_zero f zero mul }\n\n/-- Pullback a `non_assoc_semiring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.non_assoc_semiring\n  {\u03b1 : Type u} [non_assoc_semiring \u03b1] [has_one \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  non_assoc_semiring \u03b2 :=\n{ .. hf.non_unital_non_assoc_semiring f zero add mul, .. hf.mul_one_class f one mul }\n\n/-- Pullback a `semiring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.semiring\n  {\u03b1 : Type u} [semiring \u03b1] [has_one \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  semiring \u03b2 :=\n{ .. hf.monoid_with_zero f zero one mul, .. hf.add_comm_monoid f zero add,\n  .. hf.distrib f add mul }\n\n/-- Pushforward a `non_unital_non_assoc_semiring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.non_unital_non_assoc_semiring\n  {\u03b1 : Type u} [non_unital_non_assoc_semiring \u03b1]\n  (f : \u03b1 \u2192 \u03b2) (hf : surjective f) (zero : f 0 = 0)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  non_unital_non_assoc_semiring \u03b2 :=\n{ .. hf.mul_zero_class f zero mul, .. hf.add_comm_monoid f zero add, .. hf.distrib f add mul }\n\n/-- Pushforward a `non_unital_semiring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.non_unital_semiring\n  {\u03b1 : Type u} [non_unital_semiring \u03b1]\n  (f : \u03b1 \u2192 \u03b2) (hf : surjective f) (zero : f 0 = 0)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  non_unital_semiring \u03b2 :=\n{ .. hf.non_unital_non_assoc_semiring f zero add mul, .. hf.semigroup_with_zero f zero mul }\n\n/-- Pushforward a `non_assoc_semiring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.non_assoc_semiring\n  {\u03b1 : Type u} [non_assoc_semiring \u03b1] [has_one \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  non_assoc_semiring \u03b2 :=\n{ .. hf.non_unital_non_assoc_semiring f zero add mul, .. hf.mul_one_class f one mul }\n\n/-- Pushforward a `semiring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.semiring\n  {\u03b1 : Type u} [semiring \u03b1] [has_one \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  semiring \u03b2 :=\n{ .. hf.monoid_with_zero f zero one mul, .. hf.add_comm_monoid f zero add,\n  .. hf.distrib f add mul }\n\nend injective_surjective_maps\n\nsection semiring\nvariables [semiring \u03b1]\n\nlemma one_add_one_eq_two : 1 + 1 = (2 : \u03b1) :=\nby unfold bit0\n\ntheorem two_mul (n : \u03b1) : 2 * n = n + n :=\neq.trans (right_distrib 1 1 n) (by simp)\n\nlemma distrib_three_right (a b c d : \u03b1) : (a + b + c) * d = a * d + b * d + c * d :=\nby simp [right_distrib]\n\ntheorem mul_two (n : \u03b1) : n * 2 = n + n :=\n(left_distrib n 1 1).trans (by simp)\n\ntheorem bit0_eq_two_mul (n : \u03b1) : bit0 n = 2 * n :=\n(two_mul _).symm\n\n@[to_additive] lemma mul_ite {\u03b1} [has_mul \u03b1] (P : Prop) [decidable P] (a b c : \u03b1) :\n  a * (if P then b else c) = if P then a * b else a * c :=\nby split_ifs; refl\n\n@[to_additive] lemma ite_mul {\u03b1} [has_mul \u03b1] (P : Prop) [decidable P] (a b c : \u03b1) :\n  (if P then a else b) * c = if P then a * c else b * c :=\nby split_ifs; refl\n\n-- We make `mul_ite` and `ite_mul` simp lemmas,\n-- but not `add_ite` or `ite_add`.\n-- The problem we're trying to avoid is dealing with\n-- summations of the form `\u2211 x in s, (f x + ite P 1 0)`,\n-- in which `add_ite` followed by `sum_ite` would needlessly slice up\n-- the `f x` terms according to whether `P` holds at `x`.\n-- There doesn't appear to be a corresponding difficulty so far with\n-- `mul_ite` and `ite_mul`.\nattribute [simp] mul_ite ite_mul\n\n@[simp] lemma mul_boole {\u03b1} [non_assoc_semiring \u03b1] (P : Prop) [decidable P] (a : \u03b1) :\n  a * (if P then 1 else 0) = if P then a else 0 :=\nby simp\n\n@[simp] lemma boole_mul {\u03b1} [non_assoc_semiring \u03b1] (P : Prop) [decidable P] (a : \u03b1) :\n  (if P then 1 else 0) * a = if P then a else 0 :=\nby simp\n\nlemma ite_mul_zero_left {\u03b1 : Type*} [mul_zero_class \u03b1] (P : Prop) [decidable P] (a b : \u03b1) :\n  ite P (a * b) 0 = ite P a 0 * b :=\nby { by_cases h : P; simp [h], }\n\nlemma ite_mul_zero_right {\u03b1 : Type*} [mul_zero_class \u03b1] (P : Prop) [decidable P] (a b : \u03b1) :\n  ite P (a * b) 0 = a * ite P b 0 :=\nby { by_cases h : P; simp [h], }\n\n/-- An element `a` of a semiring is even if there exists `k` such `a = 2*k`. -/\ndef even (a : \u03b1) : Prop := \u2203 k, a = 2*k\n\nlemma even_iff_two_dvd {a : \u03b1} : even a \u2194 2 \u2223 a := iff.rfl\n\n@[simp] lemma range_two_mul (\u03b1 : Type*) [semiring \u03b1] :\n  set.range (\u03bb x : \u03b1, 2 * x) = {a | even a} :=\nby { ext x, simp [even, eq_comm] }\n\n@[simp] lemma even_bit0 (a : \u03b1) : even (bit0 a) :=\n\u27e8a, by rw [bit0, two_mul]\u27e9\n\n/-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/\ndef odd (a : \u03b1) : Prop := \u2203 k, a = 2*k + 1\n\n@[simp] lemma odd_bit1 (a : \u03b1) : odd (bit1 a) :=\n\u27e8a, by rw [bit1, bit0, two_mul]\u27e9\n\n@[simp] lemma range_two_mul_add_one (\u03b1 : Type*) [semiring \u03b1] :\n  set.range (\u03bb x : \u03b1, 2 * x + 1) = {a | odd a} :=\nby { ext x, simp [odd, eq_comm] }\n\ntheorem dvd_add {a b c : \u03b1} (h\u2081 : a \u2223 b) (h\u2082 : a \u2223 c) : a \u2223 b + c :=\ndvd.elim h\u2081 (\u03bb d hd, dvd.elim h\u2082 (\u03bb e he, dvd.intro (d + e) (by simp [left_distrib, hd, he])))\n\nend semiring\n\nnamespace add_hom\n\n/-- Left multiplication by an element of a type with distributive multiplication is an `add_hom`. -/\n@[simps { fully_applied := ff}] def mul_left {R : Type*} [distrib R] (r : R) : add_hom R R :=\n\u27e8(*) r, mul_add r\u27e9\n\n/-- Left multiplication by an element of a type with distributive multiplication is an `add_hom`. -/\n@[simps { fully_applied := ff}] def mul_right {R : Type*} [distrib R] (r : R) : add_hom R R :=\n\u27e8\u03bb a, a * r, \u03bb _ _, add_mul _ _ r\u27e9\n\nend add_hom\n\nnamespace add_monoid_hom\n\n/-- Left multiplication by an element of a (semi)ring is an `add_monoid_hom` -/\ndef mul_left {R : Type*} [non_unital_non_assoc_semiring R] (r : R) : R \u2192+ R :=\n{ to_fun := (*) r,\n  map_zero' := mul_zero r,\n  map_add' := mul_add r }\n\n@[simp] lemma coe_mul_left {R : Type*} [non_unital_non_assoc_semiring R] (r : R) :\n  \u21d1(mul_left r) = (*) r := rfl\n\n/-- Right multiplication by an element of a (semi)ring is an `add_monoid_hom` -/\ndef mul_right {R : Type*} [non_unital_non_assoc_semiring R] (r : R) : R \u2192+ R :=\n{ to_fun := \u03bb a, a * r,\n  map_zero' := zero_mul r,\n  map_add' := \u03bb _ _, add_mul _ _ r }\n\n@[simp] lemma coe_mul_right {R : Type*} [non_unital_non_assoc_semiring R] (r : R) :\n  \u21d1(mul_right r) = (* r) := rfl\n\nlemma mul_right_apply {R : Type*} [non_unital_non_assoc_semiring R] (a r : R) :\n  mul_right r a = a * r := rfl\n\nend add_monoid_hom\n\n/-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too.\n\nThis extends from both `monoid_hom` and `monoid_with_zero_hom` in order to put the fields in a\nsensible order, even though `monoid_with_zero_hom` already extends `monoid_hom`. -/\nstructure ring_hom (\u03b1 : Type*) (\u03b2 : Type*) [non_assoc_semiring \u03b1] [non_assoc_semiring \u03b2]\n  extends \u03b1 \u2192* \u03b2, \u03b1 \u2192+ \u03b2, \u03b1 \u2192*\u2080 \u03b2\n\ninfixr ` \u2192+* `:25 := ring_hom\n\n/-- Reinterpret a ring homomorphism `f : R \u2192+* S` as a monoid with zero homomorphism `R \u2192*\u2080 S`.\nThe `simp`-normal form is `(f : R \u2192*\u2080 S)`. -/\nadd_decl_doc ring_hom.to_monoid_with_zero_hom\n\n/-- Reinterpret a ring homomorphism `f : R \u2192+* S` as a monoid homomorphism `R \u2192* S`.\nThe `simp`-normal form is `(f : R \u2192* S)`. -/\nadd_decl_doc ring_hom.to_monoid_hom\n\n/-- Reinterpret a ring homomorphism `f : R \u2192+* S` as an additive monoid homomorphism `R \u2192+ S`.\nThe `simp`-normal form is `(f : R \u2192+ S)`. -/\nadd_decl_doc ring_hom.to_add_monoid_hom\n\nsection ring_hom_class\n\n/-- `ring_hom_class F R S` states that `F` is a type of (semi)ring homomorphisms.\nYou should extend this class when you extend `ring_hom`.\n\nThis extends from both `monoid_hom_class` and `monoid_with_zero_hom_class` in\norder to put the fields in a sensible order, even though\n`monoid_with_zero_hom_class` already extends `monoid_hom_class`. -/\nclass ring_hom_class (F : Type*) (R S : out_param Type*)\n  [non_assoc_semiring R] [non_assoc_semiring S]\n  extends monoid_hom_class F R S, add_monoid_hom_class F R S, monoid_with_zero_hom_class F R S\n\nvariables {F : Type*} [non_assoc_semiring \u03b1] [non_assoc_semiring \u03b2] [ring_hom_class F \u03b1 \u03b2]\n\n/-- Ring homomorphisms preserve `bit0`. -/\n@[simp] lemma map_bit0 (f : F) (a : \u03b1) : (f (bit0 a) : \u03b2) = bit0 (f a) :=\nmap_add _ _ _\n\n/-- Ring homomorphisms preserve `bit1`. -/\n@[simp] lemma map_bit1 (f : F) (a : \u03b1) : (f (bit1 a) : \u03b2) = bit1 (f a) :=\nby simp [bit1]\n\nend ring_hom_class\n\nnamespace ring_hom\n\nsection coe\n\n/-!\nThroughout this section, some `semiring` arguments are specified with `{}` instead of `[]`.\nSee note [implicit instance arguments].\n-/\nvariables {r\u03b1 : non_assoc_semiring \u03b1} {r\u03b2 : non_assoc_semiring \u03b2}\n\ninclude r\u03b1 r\u03b2\n\ninstance : ring_hom_class (\u03b1 \u2192+* \u03b2) \u03b1 \u03b2 :=\n{ coe := ring_hom.to_fun,\n  coe_injective' := \u03bb f g h, by cases f; cases g; congr',\n  map_add := ring_hom.map_add',\n  map_zero := ring_hom.map_zero',\n  map_mul := ring_hom.map_mul',\n  map_one := ring_hom.map_one' }\n\n/-- Helper instance for when there's too many metavariables to apply `to_fun.to_coe_fn` directly.\n-/\ninstance : has_coe_to_fun (\u03b1 \u2192+* \u03b2) (\u03bb _, \u03b1 \u2192 \u03b2) := \u27e8ring_hom.to_fun\u27e9\n\ninitialize_simps_projections ring_hom (to_fun \u2192 apply)\n\n@[simp] lemma to_fun_eq_coe (f : \u03b1 \u2192+* \u03b2) : f.to_fun = f := rfl\n\n@[simp] lemma coe_mk (f : \u03b1 \u2192 \u03b2) (h\u2081 h\u2082 h\u2083 h\u2084) : \u21d1(\u27e8f, h\u2081, h\u2082, h\u2083, h\u2084\u27e9 : \u03b1 \u2192+* \u03b2) = f := rfl\n\ninstance has_coe_monoid_hom : has_coe (\u03b1 \u2192+* \u03b2) (\u03b1 \u2192* \u03b2) := \u27e8ring_hom.to_monoid_hom\u27e9\n\n@[simp, norm_cast] lemma coe_monoid_hom (f : \u03b1 \u2192+* \u03b2) : \u21d1(f : \u03b1 \u2192* \u03b2) = f := rfl\n\n@[simp] lemma to_monoid_hom_eq_coe (f : \u03b1 \u2192+* \u03b2) : f.to_monoid_hom = f := rfl\n@[simp] lemma to_monoid_with_zero_hom_eq_coe (f : \u03b1 \u2192+* \u03b2) :\n  (f.to_monoid_with_zero_hom : \u03b1 \u2192 \u03b2) = f := rfl\n\n@[simp] lemma coe_monoid_hom_mk (f : \u03b1 \u2192 \u03b2) (h\u2081 h\u2082 h\u2083 h\u2084) :\n  ((\u27e8f, h\u2081, h\u2082, h\u2083, h\u2084\u27e9 : \u03b1 \u2192+* \u03b2) : \u03b1 \u2192* \u03b2) = \u27e8f, h\u2081, h\u2082\u27e9 :=\nrfl\n\ninstance has_coe_add_monoid_hom : has_coe (\u03b1 \u2192+* \u03b2) (\u03b1 \u2192+ \u03b2) := \u27e8ring_hom.to_add_monoid_hom\u27e9\n\n@[simp, norm_cast] lemma coe_add_monoid_hom (f : \u03b1 \u2192+* \u03b2) : \u21d1(f : \u03b1 \u2192+ \u03b2) = f := rfl\n\n@[simp] lemma to_add_monoid_hom_eq_coe (f : \u03b1 \u2192+* \u03b2) : f.to_add_monoid_hom = f := rfl\n\n@[simp] lemma coe_add_monoid_hom_mk (f : \u03b1 \u2192 \u03b2) (h\u2081 h\u2082 h\u2083 h\u2084) :\n  ((\u27e8f, h\u2081, h\u2082, h\u2083, h\u2084\u27e9 : \u03b1 \u2192+* \u03b2) : \u03b1 \u2192+ \u03b2) = \u27e8f, h\u2083, h\u2084\u27e9 :=\nrfl\n\nend coe\n\nvariables [r\u03b1 : non_assoc_semiring \u03b1] [r\u03b2 : non_assoc_semiring \u03b2]\n\nsection\ninclude r\u03b1 r\u03b2\n\nvariables (f : \u03b1 \u2192+* \u03b2) {x y : \u03b1} {r\u03b1 r\u03b2}\n\ntheorem congr_fun {f g : \u03b1 \u2192+* \u03b2} (h : f = g) (x : \u03b1) : f x = g x :=\nfun_like.congr_fun h x\n\ntheorem congr_arg (f : \u03b1 \u2192+* \u03b2) {x y : \u03b1} (h : x = y) : f x = f y :=\nfun_like.congr_arg f h\n\ntheorem coe_inj \u2983f g : \u03b1 \u2192+* \u03b2\u2984 (h : (f : \u03b1 \u2192 \u03b2) = g) : f = g :=\nfun_like.coe_injective h\n\n@[ext] theorem ext \u2983f g : \u03b1 \u2192+* \u03b2\u2984 (h : \u2200 x, f x = g x) : f = g :=\nfun_like.ext _ _ h\n\ntheorem ext_iff {f g : \u03b1 \u2192+* \u03b2} : f = g \u2194 \u2200 x, f x = g x :=\nfun_like.ext_iff\n\n@[simp] lemma mk_coe (f : \u03b1 \u2192+* \u03b2) (h\u2081 h\u2082 h\u2083 h\u2084) : ring_hom.mk f h\u2081 h\u2082 h\u2083 h\u2084 = f :=\next $ \u03bb _, rfl\n\ntheorem coe_add_monoid_hom_injective : function.injective (coe : (\u03b1 \u2192+* \u03b2) \u2192 (\u03b1 \u2192+ \u03b2)) :=\n\u03bb f g h, ext (\u03bb x, add_monoid_hom.congr_fun h x)\n\ntheorem coe_monoid_hom_injective : function.injective (coe : (\u03b1 \u2192+* \u03b2) \u2192 (\u03b1 \u2192* \u03b2)) :=\n\u03bb f g h, ext (\u03bb x, monoid_hom.congr_fun h x)\n\n/-- Ring homomorphisms map zero to zero. -/\nprotected lemma map_zero (f : \u03b1 \u2192+* \u03b2) : f 0 = 0 := map_zero f\n\n/-- Ring homomorphisms map one to one. -/\nprotected lemma map_one (f : \u03b1 \u2192+* \u03b2) : f 1 = 1 := map_one f\n\n/-- Ring homomorphisms preserve addition. -/\nprotected lemma map_add (f : \u03b1 \u2192+* \u03b2) (a b : \u03b1) : f (a + b) = f a + f b := map_add f a b\n\n/-- Ring homomorphisms preserve multiplication. -/\nprotected lemma map_mul (f : \u03b1 \u2192+* \u03b2) (a b : \u03b1) : f (a * b) = f a * f b := map_mul f a b\n\n/-- Ring homomorphisms preserve `bit0`. -/\nprotected lemma map_bit0 (f : \u03b1 \u2192+* \u03b2) (a : \u03b1) : f (bit0 a) = bit0 (f a) := map_add _ _ _\n\n/-- Ring homomorphisms preserve `bit1`. -/\nprotected lemma map_bit1 (f : \u03b1 \u2192+* \u03b2) (a : \u03b1) : f (bit1 a) = bit1 (f a) :=\nby simp [bit1]\n\n/-- `f : R \u2192+* S` has a trivial codomain iff `f 1 = 0`. -/\nlemma codomain_trivial_iff_map_one_eq_zero : (0 : \u03b2) = 1 \u2194 f 1 = 0 :=\nby rw [map_one, eq_comm]\n\n/-- `f : R \u2192+* S` has a trivial codomain iff it has a trivial range. -/\nlemma codomain_trivial_iff_range_trivial : (0 : \u03b2) = 1 \u2194 (\u2200 x, f x = 0) :=\nf.codomain_trivial_iff_map_one_eq_zero.trans\n  \u27e8\u03bb h x, by rw [\u2190mul_one x, map_mul, h, mul_zero], \u03bb h, h 1\u27e9\n\n/-- `f : R \u2192+* S` has a trivial codomain iff its range is `{0}`. -/\nlemma codomain_trivial_iff_range_eq_singleton_zero : (0 : \u03b2) = 1 \u2194 set.range f = {0} :=\nf.codomain_trivial_iff_range_trivial.trans\n  \u27e8 \u03bb h, set.ext (\u03bb y, \u27e8\u03bb \u27e8x, hx\u27e9, by simp [\u2190hx, h x], \u03bb hy, \u27e80, by simpa using hy.symm\u27e9\u27e9),\n    \u03bb h x, set.mem_singleton_iff.mp (h \u25b8 set.mem_range_self x)\u27e9\n\n/-- `f : R \u2192+* S` doesn't map `1` to `0` if `S` is nontrivial -/\nlemma map_one_ne_zero [nontrivial \u03b2] : f 1 \u2260 0 :=\nmt f.codomain_trivial_iff_map_one_eq_zero.mpr zero_ne_one\n\n/-- If there is a homomorphism `f : R \u2192+* S` and `S` is nontrivial, then `R` is nontrivial. -/\nlemma domain_nontrivial [nontrivial \u03b2] : nontrivial \u03b1 :=\n\u27e8\u27e81, 0, mt (\u03bb h, show f 1 = 0, by rw [h, map_zero]) f.map_one_ne_zero\u27e9\u27e9\n\n\nend\n\nlemma is_unit_map [semiring \u03b1] [semiring \u03b2] (f : \u03b1 \u2192+* \u03b2) {a : \u03b1} (h : is_unit a) : is_unit (f a) :=\nh.map f.to_monoid_hom\n\n/-- The identity ring homomorphism from a semiring to itself. -/\ndef id (\u03b1 : Type*) [non_assoc_semiring \u03b1] : \u03b1 \u2192+* \u03b1 :=\nby refine {to_fun := id, ..}; intros; refl\n\ninclude r\u03b1\n\ninstance : inhabited (\u03b1 \u2192+* \u03b1) := \u27e8id \u03b1\u27e9\n\n@[simp] lemma id_apply (x : \u03b1) : ring_hom.id \u03b1 x = x := rfl\n@[simp] lemma coe_add_monoid_hom_id : (id \u03b1 : \u03b1 \u2192+ \u03b1) = add_monoid_hom.id \u03b1 := rfl\n@[simp] lemma coe_monoid_hom_id : (id \u03b1 : \u03b1 \u2192* \u03b1) = monoid_hom.id \u03b1 := rfl\n\nvariable {r\u03b3 : non_assoc_semiring \u03b3}\ninclude r\u03b2 r\u03b3\n\n/-- Composition of ring homomorphisms is a ring homomorphism. -/\ndef comp (hnp : \u03b2 \u2192+* \u03b3) (hmn : \u03b1 \u2192+* \u03b2) : \u03b1 \u2192+* \u03b3 :=\n{ to_fun := hnp \u2218 hmn,\n  map_zero' := by simp,\n  map_one' := by simp,\n  map_add' := \u03bb x y, by simp,\n  map_mul' := \u03bb x y, by simp}\n\n/-- Composition of semiring homomorphisms is associative. -/\nlemma comp_assoc {\u03b4} {r\u03b4: non_assoc_semiring \u03b4} (f : \u03b1 \u2192+* \u03b2) (g : \u03b2 \u2192+* \u03b3) (h : \u03b3 \u2192+* \u03b4) :\n  (h.comp g).comp f = h.comp (g.comp f) := rfl\n\n@[simp] lemma coe_comp (hnp : \u03b2 \u2192+* \u03b3) (hmn : \u03b1 \u2192+* \u03b2) : (hnp.comp hmn : \u03b1 \u2192 \u03b3) = hnp \u2218 hmn := rfl\n\nlemma comp_apply (hnp : \u03b2 \u2192+* \u03b3) (hmn : \u03b1 \u2192+* \u03b2) (x : \u03b1) : (hnp.comp hmn : \u03b1 \u2192 \u03b3) x =\n  (hnp (hmn x)) := rfl\n\nomit r\u03b3\n\n@[simp] lemma comp_id (f : \u03b1 \u2192+* \u03b2) : f.comp (id \u03b1) = f := ext $ \u03bb x, rfl\n\n@[simp] lemma id_comp (f : \u03b1 \u2192+* \u03b2) : (id \u03b2).comp f = f := ext $ \u03bb x, rfl\n\nomit r\u03b2\n\ninstance : monoid (\u03b1 \u2192+* \u03b1) :=\n{ one := id \u03b1,\n  mul := comp,\n  mul_one := comp_id,\n  one_mul := id_comp,\n  mul_assoc := \u03bb f g h, comp_assoc _ _ _ }\n\nlemma one_def : (1 : \u03b1 \u2192+* \u03b1) = id \u03b1 := rfl\n\n@[simp] lemma coe_one : \u21d1(1 : \u03b1 \u2192+* \u03b1) = _root_.id := rfl\n\nlemma mul_def (f g : \u03b1 \u2192+* \u03b1) : f * g = f.comp g := rfl\n\n@[simp] lemma coe_mul (f g : \u03b1 \u2192+* \u03b1) : \u21d1(f * g) = f \u2218 g := rfl\n\ninclude r\u03b2 r\u03b3\n\nlemma cancel_right {g\u2081 g\u2082 : \u03b2 \u2192+* \u03b3} {f : \u03b1 \u2192+* \u03b2} (hf : surjective f) :\n  g\u2081.comp f = g\u2082.comp f \u2194 g\u2081 = g\u2082 :=\n\u27e8\u03bb h, ring_hom.ext $ hf.forall.2 (ext_iff.1 h), \u03bb h, h \u25b8 rfl\u27e9\n\nlemma cancel_left {g : \u03b2 \u2192+* \u03b3} {f\u2081 f\u2082 : \u03b1 \u2192+* \u03b2} (hg : injective g) :\n  g.comp f\u2081 = g.comp f\u2082 \u2194 f\u2081 = f\u2082 :=\n\u27e8\u03bb h, ring_hom.ext $ \u03bb x, hg $ by rw [\u2190 comp_apply, h, comp_apply], \u03bb h, h \u25b8 rfl\u27e9\n\nomit r\u03b1 r\u03b2 r\u03b3\n\nend ring_hom\n\nsection semiring\n\nvariables [semiring \u03b1] {a : \u03b1}\n\n@[simp] theorem two_dvd_bit0 : 2 \u2223 bit0 a := \u27e8a, bit0_eq_two_mul _\u27e9\n\nlemma ring_hom.map_dvd [semiring \u03b2] (f : \u03b1 \u2192+* \u03b2) {a b : \u03b1} : a \u2223 b \u2192 f a \u2223 f b :=\nf.to_monoid_hom.map_dvd\n\nend semiring\n\n/-- A commutative semiring is a `semiring` with commutative multiplication. In other words, it is a\ntype with the following structures: additive commutative monoid (`add_comm_monoid`), multiplicative\ncommutative monoid (`comm_monoid`), distributive laws (`distrib`), and multiplication by zero law\n(`mul_zero_class`). -/\n@[protect_proj, ancestor semiring comm_monoid]\nclass comm_semiring (\u03b1 : Type u) extends semiring \u03b1, comm_monoid \u03b1\n\n@[priority 100] -- see Note [lower instance priority]\ninstance comm_semiring.to_comm_monoid_with_zero [comm_semiring \u03b1] : comm_monoid_with_zero \u03b1 :=\n{ .. comm_semiring.to_comm_monoid \u03b1, .. comm_semiring.to_semiring \u03b1 }\n\nsection comm_semiring\nvariables [comm_semiring \u03b1] [comm_semiring \u03b2] {a b c : \u03b1}\n\n/-- Pullback a `semiring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.comm_semiring [has_zero \u03b3] [has_one \u03b3] [has_add \u03b3] [has_mul \u03b3]\n  (f : \u03b3 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  comm_semiring \u03b3 :=\n{ .. hf.semiring f zero one add mul, .. hf.comm_semigroup f mul }\n\n/-- Pushforward a `semiring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.comm_semiring [has_zero \u03b3] [has_one \u03b3] [has_add \u03b3] [has_mul \u03b3]\n  (f : \u03b1 \u2192 \u03b3) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  comm_semiring \u03b3 :=\n{ .. hf.semiring f zero one add mul, .. hf.comm_semigroup f mul }\n\nlemma add_mul_self_eq (a b : \u03b1) : (a + b) * (a + b) = a*a + 2*a*b + b*b :=\nby simp only [two_mul, add_mul, mul_add, add_assoc, mul_comm b]\n\nlemma has_dvd.dvd.linear_comb {d x y : \u03b1} (hdx : d \u2223 x) (hdy : d \u2223 y) (a b : \u03b1) :\n  d \u2223 (a * x + b * y) :=\ndvd_add (hdx.mul_left a) (hdy.mul_left b)\n\nend comm_semiring\n\n/-!\n### Rings\n-/\n\n/-- A not-necessarily-unital, not-necessarily-associative ring. -/\n@[protect_proj, ancestor add_comm_group non_unital_non_assoc_semiring]\nclass non_unital_non_assoc_ring (\u03b1 : Type u) extends\n  add_comm_group \u03b1, non_unital_non_assoc_semiring \u03b1\n\nsection non_unital_non_assoc_ring\nvariables [non_unital_non_assoc_ring \u03b1]\n\n\n/-- Pullback a `non_unital_non_assoc_ring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.non_unital_non_assoc_ring\n  [has_zero \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  non_unital_non_assoc_ring \u03b2 :=\n{ .. hf.add_comm_group f zero add neg sub, ..hf.mul_zero_class f zero mul, .. hf.distrib f add mul }\n\n/-- Pushforward a `non_unital_non_assoc_ring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.non_unital_non_assoc_ring\n  [has_zero \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : surjective f) (zero : f 0 = 0)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  non_unital_non_assoc_ring \u03b2 :=\n{ .. hf.add_comm_group f zero add neg sub, .. hf.mul_zero_class f zero mul,\n  .. hf.distrib f add mul }\n\nend non_unital_non_assoc_ring\n\n/-- A ring is a type with the following structures: additive commutative group (`add_comm_group`),\nmultiplicative monoid (`monoid`), and distributive laws (`distrib`).  Equivalently, a ring is a\n`semiring` with a negation operation making it an additive group.  -/\n@[protect_proj, ancestor add_comm_group monoid distrib]\nclass ring (\u03b1 : Type u) extends add_comm_group \u03b1, monoid \u03b1, distrib \u03b1\n\nsection ring\nvariables [ring \u03b1] {a b c d e : \u03b1}\n\n/- A (unital, associative) ring is a not-necessarily-unital, not-necessarily-associative ring -/\n@[priority 100] -- see Note [lower instance priority]\ninstance ring.to_non_unital_non_assoc_ring :\n  non_unital_non_assoc_ring \u03b1 :=\n{ zero_mul := \u03bb a, add_left_cancel $ show 0 * a + 0 * a = 0 * a + 0,\n    by rw [\u2190 add_mul, zero_add, add_zero],\n  mul_zero := \u03bb a, add_left_cancel $ show a * 0 + a * 0 = a * 0 + 0,\n    by rw [\u2190 mul_add, add_zero, add_zero],\n  ..\u2039ring \u03b1\u203a }\n\n/- The instance from `ring` to `semiring` happens often in linear algebra, for which all the basic\ndefinitions are given in terms of semirings, but many applications use rings or fields. We increase\na little bit its priority above 100 to try it quickly, but remaining below the default 1000 so that\nmore specific instances are tried first. -/\n@[priority 200]\ninstance ring.to_semiring : semiring \u03b1 :=\n{ ..\u2039ring \u03b1\u203a, .. ring.to_non_unital_non_assoc_ring }\n\n/-- Pullback a `ring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.ring\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  ring \u03b2 :=\n{ .. hf.add_comm_group f zero add neg sub, .. hf.monoid f one mul, .. hf.distrib f add mul }\n\n/-- Pushforward a `ring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.ring\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  ring \u03b2 :=\n{ .. hf.add_comm_group f zero add neg sub, .. hf.monoid f one mul, .. hf.distrib f add mul }\n\nlemma neg_mul_eq_neg_mul (a b : \u03b1) : -(a * b) = -a * b :=\nneg_eq_of_add_eq_zero\n  begin rw [\u2190 right_distrib, add_right_neg, zero_mul] end\n\nlemma neg_mul_eq_mul_neg (a b : \u03b1) : -(a * b) = a * -b :=\nneg_eq_of_add_eq_zero\n  begin rw [\u2190 left_distrib, add_right_neg, mul_zero] end\n\n@[simp] lemma neg_mul_eq_neg_mul_symm (a b : \u03b1) : - a * b = - (a * b) :=\neq.symm (neg_mul_eq_neg_mul a b)\n\n@[simp] lemma mul_neg_eq_neg_mul_symm (a b : \u03b1) : a * - b = - (a * b) :=\neq.symm (neg_mul_eq_mul_neg a b)\n\nlemma neg_mul_neg (a b : \u03b1) : -a * -b = a * b :=\nby simp\n\nlemma neg_mul_comm (a b : \u03b1) : -a * b = a * -b :=\nby simp\n\ntheorem neg_eq_neg_one_mul (a : \u03b1) : -a = -1 * a :=\nby simp\n\nlemma mul_sub_left_distrib (a b c : \u03b1) : a * (b - c) = a * b - a * c :=\nby simpa only [sub_eq_add_neg, neg_mul_eq_mul_neg] using mul_add a b (-c)\n\nalias mul_sub_left_distrib \u2190 mul_sub\n\nlemma mul_sub_right_distrib (a b c : \u03b1) : (a - b) * c = a * c - b * c :=\nby simpa only [sub_eq_add_neg, neg_mul_eq_neg_mul] using add_mul a (-b) c\n\nalias mul_sub_right_distrib \u2190 sub_mul\n\n/-- An element of a ring multiplied by the additive inverse of one is the element's additive\n  inverse. -/\nlemma mul_neg_one (a : \u03b1) : a * -1 = -a := by simp\n\n/-- The additive inverse of one multiplied by an element of a ring is the element's additive\n  inverse. -/\nlemma neg_one_mul (a : \u03b1) : -1 * a = -a := by simp\n\n/-- An iff statement following from right distributivity in rings and the definition\n  of subtraction. -/\ntheorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d \u2194 (a - b) * e + c = d :=\ncalc\n  a * e + c = b * e + d \u2194 a * e + c = d + b * e : by simp [add_comm]\n    ... \u2194 a * e + c - b * e = d : iff.intro (\u03bb h, begin rw h, simp end) (\u03bb h,\n                                                  begin rw \u2190 h, simp end)\n    ... \u2194 (a - b) * e + c = d   : begin simp [sub_mul, sub_add_eq_add_sub] end\n\n/-- A simplification of one side of an equation exploiting right distributivity in rings\n  and the definition of subtraction. -/\ntheorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d \u2192 (a - b) * e + c = d :=\nassume h,\ncalc\n  (a - b) * e + c = (a * e + c) - b * e : begin simp [sub_mul, sub_add_eq_add_sub] end\n              ... = d                   : begin rw h, simp [@add_sub_cancel \u03b1] end\n\nend ring\n\nnamespace units\nvariables [ring \u03b1] {a b : \u03b1}\n\n/-- Each element of the group of units of a ring has an additive inverse. -/\ninstance : has_neg \u03b1\u02e3 := \u27e8\u03bbu, \u27e8-\u2191u, -\u2191u\u207b\u00b9, by simp, by simp\u27e9 \u27e9\n\n/-- Representing an element of a ring's unit group as an element of the ring commutes with\n    mapping this element to its additive inverse. -/\n@[simp, norm_cast] protected theorem coe_neg (u : \u03b1\u02e3) : (\u2191-u : \u03b1) = -u := rfl\n\n@[simp, norm_cast] protected theorem coe_neg_one : ((-1 : \u03b1\u02e3) : \u03b1) = -1 := rfl\n\n/-- Mapping an element of a ring's unit group to its inverse commutes with mapping this element\n    to its additive inverse. -/\n@[simp] protected theorem neg_inv (u : \u03b1\u02e3) : (-u)\u207b\u00b9 = -u\u207b\u00b9 := rfl\n\n/-- An element of a ring's unit group equals the additive inverse of its additive inverse. -/\n@[simp] protected theorem neg_neg (u : \u03b1\u02e3) : - -u = u :=\nunits.ext $ neg_neg _\n\n/-- Multiplication of elements of a ring's unit group commutes with mapping the first\n    argument to its additive inverse. -/\n@[simp] protected theorem neg_mul (u\u2081 u\u2082 : \u03b1\u02e3) : -u\u2081 * u\u2082 = -(u\u2081 * u\u2082) :=\nunits.ext $ neg_mul_eq_neg_mul_symm _ _\n\n/-- Multiplication of elements of a ring's unit group commutes with mapping the second argument\n    to its additive inverse. -/\n@[simp] protected theorem mul_neg (u\u2081 u\u2082 : \u03b1\u02e3) : u\u2081 * -u\u2082 = -(u\u2081 * u\u2082) :=\nunits.ext $ (neg_mul_eq_mul_neg _ _).symm\n\n/-- Multiplication of the additive inverses of two elements of a ring's unit group equals\n    multiplication of the two original elements. -/\n@[simp] protected theorem neg_mul_neg (u\u2081 u\u2082 : \u03b1\u02e3) : -u\u2081 * -u\u2082 = u\u2081 * u\u2082 := by simp\n\n/-- The additive inverse of an element of a ring's unit group equals the additive inverse of\n    one times the original element. -/\nprotected theorem neg_eq_neg_one_mul (u : \u03b1\u02e3) : -u = -1 * u := by simp\n\nend units\n\nlemma is_unit.neg [ring \u03b1] {a : \u03b1} : is_unit a \u2192 is_unit (-a)\n| \u27e8x, hx\u27e9 := hx \u25b8 (-x).is_unit\n\nlemma is_unit.neg_iff [ring \u03b1] (a : \u03b1) : is_unit (-a) \u2194 is_unit a :=\n\u27e8\u03bb h, neg_neg a \u25b8 h.neg, is_unit.neg\u27e9\n\nlemma is_unit.sub_iff [ring \u03b1] {x y : \u03b1} :\n  is_unit (x - y) \u2194 is_unit (y - x) :=\n(is_unit.neg_iff _).symm.trans $ neg_sub x y \u25b8 iff.rfl\n\nnamespace ring_hom\n\n/-- Ring homomorphisms preserve additive inverse. -/\nprotected theorem map_neg {\u03b1 \u03b2} [ring \u03b1] [ring \u03b2] (f : \u03b1 \u2192+* \u03b2) (x : \u03b1) : f (-x) = -(f x) :=\nmap_neg f x\n\n/-- Ring homomorphisms preserve subtraction. -/\nprotected theorem map_sub {\u03b1 \u03b2} [ring \u03b1] [ring \u03b2] (f : \u03b1 \u2192+* \u03b2) (x y : \u03b1) :\n  f (x - y) = (f x) - (f y) := map_sub f x y\n\n/-- A ring homomorphism is injective iff its kernel is trivial. -/\ntheorem injective_iff {\u03b1 \u03b2} [ring \u03b1] [non_assoc_semiring \u03b2] (f : \u03b1 \u2192+* \u03b2) :\n  function.injective f \u2194 (\u2200 a, f a = 0 \u2192 a = 0) :=\n(f : \u03b1 \u2192+ \u03b2).injective_iff\n\n/-- A ring homomorphism is injective iff its kernel is trivial. -/\ntheorem injective_iff' {\u03b1 \u03b2} [ring \u03b1] [non_assoc_semiring \u03b2] (f : \u03b1 \u2192+* \u03b2) :\n  function.injective f \u2194 (\u2200 a, f a = 0 \u2194 a = 0) :=\n(f : \u03b1 \u2192+ \u03b2).injective_iff'\n\n/-- Makes a ring homomorphism from a monoid homomorphism of rings which preserves addition. -/\ndef mk' {\u03b3} [non_assoc_semiring \u03b1] [ring \u03b3] (f : \u03b1 \u2192* \u03b3)\n  (map_add : \u2200 a b : \u03b1, f (a + b) = f a + f b) :\n  \u03b1 \u2192+* \u03b3 :=\n{ to_fun := f,\n  .. add_monoid_hom.mk' f map_add, .. f }\n\nend ring_hom\n\n/-- A commutative ring is a `ring` with commutative multiplication. -/\n@[protect_proj, ancestor ring comm_semigroup]\nclass comm_ring (\u03b1 : Type u) extends ring \u03b1, comm_monoid \u03b1\n\n@[priority 100] -- see Note [lower instance priority]\ninstance comm_ring.to_comm_semiring [s : comm_ring \u03b1] : comm_semiring \u03b1 :=\n{ mul_zero := mul_zero, zero_mul := zero_mul, ..s }\n\nsection ring\nvariables [ring \u03b1] {a b c : \u03b1}\n\ntheorem dvd_neg_of_dvd (h : a \u2223 b) : (a \u2223 -b) :=\ndvd.elim h\n  (assume c, assume : b = a * c,\n    dvd.intro (-c) (by simp [this]))\n\ntheorem dvd_of_dvd_neg (h : a \u2223 -b) : (a \u2223 b) :=\nlet t := dvd_neg_of_dvd h in by rwa neg_neg at t\n\n/-- An element a of a ring divides the additive inverse of an element b iff a divides b. -/\n@[simp] lemma dvd_neg (a b : \u03b1) : (a \u2223 -b) \u2194 (a \u2223 b) :=\n\u27e8dvd_of_dvd_neg, dvd_neg_of_dvd\u27e9\n\ntheorem neg_dvd_of_dvd (h : a \u2223 b) : -a \u2223 b :=\ndvd.elim h\n  (assume c, assume : b = a * c,\n    dvd.intro (-c) (by simp [this]))\n\ntheorem dvd_of_neg_dvd (h : -a \u2223 b) : a \u2223 b :=\nlet t := neg_dvd_of_dvd h in by rwa neg_neg at t\n\n/-- The additive inverse of an element a of a ring divides another element b iff a divides b. -/\n@[simp] lemma neg_dvd (a b : \u03b1) : (-a \u2223 b) \u2194 (a \u2223 b) :=\n\u27e8dvd_of_neg_dvd, neg_dvd_of_dvd\u27e9\n\ntheorem dvd_sub (h\u2081 : a \u2223 b) (h\u2082 : a \u2223 c) : a \u2223 b - c :=\nby { rw sub_eq_add_neg, exact dvd_add h\u2081 (dvd_neg_of_dvd h\u2082) }\n\ntheorem dvd_add_iff_left (h : a \u2223 c) : a \u2223 b \u2194 a \u2223 b + c :=\n\u27e8\u03bbh\u2082, dvd_add h\u2082 h, \u03bbH, by have t := dvd_sub H h; rwa add_sub_cancel at t\u27e9\n\ntheorem dvd_add_iff_right (h : a \u2223 b) : a \u2223 c \u2194 a \u2223 b + c :=\nby rw add_comm; exact dvd_add_iff_left h\n\ntheorem two_dvd_bit1 : 2 \u2223 bit1 a \u2194 (2 : \u03b1) \u2223 1 := (dvd_add_iff_right (@two_dvd_bit0 _ _ a)).symm\n\n/-- If an element a divides another element c in a commutative ring, a divides the sum of another\n  element b with c iff a divides b. -/\ntheorem dvd_add_left (h : a \u2223 c) : a \u2223 b + c \u2194 a \u2223 b :=\n(dvd_add_iff_left h).symm\n\n/-- If an element a divides another element b in a commutative ring, a divides the sum of b and\n  another element c iff a divides c. -/\ntheorem dvd_add_right (h : a \u2223 b) : a \u2223 b + c \u2194 a \u2223 c :=\n(dvd_add_iff_right h).symm\n\n/-- An element a divides the sum a + b if and only if a divides b.-/\n@[simp] lemma dvd_add_self_left {a b : \u03b1} : a \u2223 a + b \u2194 a \u2223 b :=\ndvd_add_right (dvd_refl a)\n\n/-- An element a divides the sum b + a if and only if a divides b.-/\n@[simp] lemma dvd_add_self_right {a b : \u03b1} : a \u2223 b + a \u2194 a \u2223 b :=\ndvd_add_left (dvd_refl a)\n\nlemma dvd_iff_dvd_of_dvd_sub {a b c : \u03b1} (h : a \u2223 (b - c)) : (a \u2223 b \u2194 a \u2223 c) :=\nbegin\n  split,\n  { intro h',\n    convert dvd_sub h' h,\n    exact eq.symm (sub_sub_self b c) },\n  { intro h',\n    convert dvd_add h h',\n    exact eq_add_of_sub_eq rfl }\nend\n\n@[simp] theorem even_neg (a : \u03b1) : even (-a) \u2194 even a :=\ndvd_neg _ _\n\nlemma odd.neg {a : \u03b1} (hp : odd a) : odd (-a) :=\nbegin\n  obtain \u27e8k, hk\u27e9 := hp,\n  use -(k + 1),\n  rw [mul_neg_eq_neg_mul_symm, mul_add, neg_add, add_assoc, two_mul (1 : \u03b1), neg_add,\n    neg_add_cancel_right, \u2190neg_add, hk],\nend\n\n@[simp] lemma odd_neg (a : \u03b1) : odd (-a) \u2194 odd a :=\n\u27e8\u03bb h, neg_neg a \u25b8 h.neg, odd.neg\u27e9\n\nend ring\n\nsection comm_ring\nvariables [comm_ring \u03b1] {a b c : \u03b1}\n\n/-- Pullback a `comm_ring` instance along an injective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.injective.comm_ring\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  comm_ring \u03b2 :=\n{ .. hf.ring f zero one add mul neg sub, .. hf.comm_semigroup f mul }\n\n/-- Pushforward a `comm_ring` instance along a surjective function.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def function.surjective.comm_ring\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  comm_ring \u03b2 :=\n{ .. hf.ring f zero one add mul neg sub, .. hf.comm_semigroup f mul }\n\nlocal attribute [simp] add_assoc add_comm add_left_comm mul_comm\n\n/-- Representation of a difference of two squares in a commutative ring as a product. -/\ntheorem mul_self_sub_mul_self (a b : \u03b1) : a * a - b * b = (a + b) * (a - b) :=\nby rw [add_mul, mul_sub, mul_sub, mul_comm a b, sub_add_sub_cancel]\n\nlemma mul_self_sub_one (a : \u03b1) : a * a - 1 = (a + 1) * (a - 1) :=\nby rw [\u2190 mul_self_sub_mul_self, mul_one]\n\n/-- Vieta's formula for a quadratic equation, relating the coefficients of the polynomial with\n  its roots. This particular version states that if we have a root `x` of a monic quadratic\n  polynomial, then there is another root `y` such that `x + y` is negative the `a_1` coefficient\n  and `x * y` is the `a_0` coefficient. -/\nlemma Vieta_formula_quadratic {b c x : \u03b1} (h : x * x - b * x + c = 0) :\n  \u2203 y : \u03b1, y * y - b * y + c = 0 \u2227 x + y = b \u2227 x * y = c :=\nbegin\n  have : c = -(x * x - b * x) := (neg_eq_of_add_eq_zero h).symm,\n  have : c = x * (b - x), by subst this; simp [mul_sub, mul_comm],\n  refine \u27e8b - x, _, by simp, by rw this\u27e9,\n  rw [this, sub_add, \u2190 sub_mul, sub_self]\nend\n\nlemma dvd_mul_sub_mul {k a b x y : \u03b1} (hab : k \u2223 a - b) (hxy : k \u2223 x - y) :\n  k \u2223 a * x - b * y :=\nbegin\n  convert dvd_add (hxy.mul_left a) (hab.mul_right y),\n  rw [mul_sub_left_distrib, mul_sub_right_distrib],\n  simp only [sub_eq_add_neg, add_assoc, neg_add_cancel_left],\nend\n\nend comm_ring\n\nlemma succ_ne_self [ring \u03b1] [nontrivial \u03b1] (a : \u03b1) : a + 1 \u2260 a :=\n\u03bb h, one_ne_zero ((add_right_inj a).mp (by simp [h]))\n\nlemma pred_ne_self [ring \u03b1] [nontrivial \u03b1] (a : \u03b1) : a - 1 \u2260 a :=\n\u03bb h, one_ne_zero (neg_injective ((add_right_inj a).mp (by simpa [sub_eq_add_neg] using h)))\n\n/-- Left `mul` by a `k : \u03b1` over `[ring \u03b1]` is injective, if `k` is not a zero divisor.\nThe typeclass that restricts all terms of `\u03b1` to have this property is `no_zero_divisors`. -/\nlemma is_left_regular_of_non_zero_divisor [ring \u03b1] (k : \u03b1)\n  (h : \u2200 (x : \u03b1), k * x = 0 \u2192 x = 0) : is_left_regular k :=\nbegin\n  intros x y h',\n  rw \u2190sub_eq_zero,\n  refine h _ _,\n  rw [mul_sub, sub_eq_zero, h']\nend\n\n/-- Right `mul` by a `k : \u03b1` over `[ring \u03b1]` is injective, if `k` is not a zero divisor.\nThe typeclass that restricts all terms of `\u03b1` to have this property is `no_zero_divisors`. -/\nlemma is_right_regular_of_non_zero_divisor [ring \u03b1] (k : \u03b1)\n  (h : \u2200 (x : \u03b1), x * k = 0 \u2192 x = 0) : is_right_regular k :=\nbegin\n  intros x y h',\n  simp only at h',\n  rw \u2190sub_eq_zero,\n  refine h _ _,\n  rw [sub_mul, sub_eq_zero, h']\nend\n\nlemma is_regular_of_ne_zero' [ring \u03b1] [no_zero_divisors \u03b1] {k : \u03b1} (hk : k \u2260 0) :\n  is_regular k :=\n\u27e8is_left_regular_of_non_zero_divisor k\n  (\u03bb x h, (no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left hk),\n is_right_regular_of_non_zero_divisor k\n  (\u03bb x h, (no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hk)\u27e9\n\n/-- A ring with no zero divisors is a cancel_monoid_with_zero.\n\nNote this is not an instance as it forms a typeclass loop. -/\n@[reducible]\ndef no_zero_divisors.to_cancel_monoid_with_zero [ring \u03b1] [no_zero_divisors \u03b1] :\n  cancel_monoid_with_zero \u03b1 :=\n{ mul_left_cancel_of_ne_zero := \u03bb a b c ha,\n    @is_regular.left _ _ _ (is_regular_of_ne_zero' ha) _ _,\n  mul_right_cancel_of_ne_zero := \u03bb a b c hb,\n    @is_regular.right _ _ _ (is_regular_of_ne_zero' hb) _ _,\n  .. (infer_instance : semiring \u03b1) }\n\n/-- A domain is a nontrivial ring with no zero divisors, i.e. satisfying\n  the condition `a * b = 0 \u2194 a = 0 \u2228 b = 0`.\n\n  This is implemented as a mixin for `ring \u03b1`.\n  To obtain an integral domain use `[comm_ring \u03b1] [is_domain \u03b1]`. -/\n@[protect_proj] class is_domain (\u03b1 : Type u) [ring \u03b1]\n  extends no_zero_divisors \u03b1, nontrivial \u03b1 : Prop\n\nsection is_domain\nsection ring\n\nvariables [ring \u03b1] [is_domain \u03b1]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_domain.to_cancel_monoid_with_zero : cancel_monoid_with_zero \u03b1 :=\nno_zero_divisors.to_cancel_monoid_with_zero\n\n/-- Pullback an `is_domain` instance along an injective function. -/\nprotected theorem function.injective.is_domain [ring \u03b2] (f : \u03b2 \u2192+* \u03b1) (hf : injective f) :\n  is_domain \u03b2 :=\n{ .. pullback_nonzero f f.map_zero f.map_one,\n  .. hf.no_zero_divisors f f.map_zero f.map_mul }\n\nend ring\n\nsection comm_ring\n\nvariables [comm_ring \u03b1] [is_domain \u03b1]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_domain.to_cancel_comm_monoid_with_zero : cancel_comm_monoid_with_zero \u03b1 :=\n{ ..comm_semiring.to_comm_monoid_with_zero, ..is_domain.to_cancel_monoid_with_zero }\n\nlemma mul_self_eq_mul_self_iff {a b : \u03b1} : a * a = b * b \u2194 a = b \u2228 a = -b :=\nby rw [\u2190 sub_eq_zero, mul_self_sub_mul_self, mul_eq_zero, or_comm, sub_eq_zero,\n  add_eq_zero_iff_eq_neg]\n\nlemma mul_self_eq_one_iff {a : \u03b1} : a * a = 1 \u2194 a = 1 \u2228 a = -1 :=\nby rw [\u2190 mul_self_eq_mul_self_iff, one_mul]\n\n/-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or\n  one's additive inverse. -/\nlemma units.inv_eq_self_iff (u : \u03b1\u02e3) : u\u207b\u00b9 = u \u2194 u = 1 \u2228 u = -1 :=\nby { rw inv_eq_iff_mul_eq_one, simp only [units.ext_iff], push_cast, exact mul_self_eq_one_iff }\n\n/--\nMakes a ring homomorphism from an additive group homomorphism from a commutative ring to an integral\ndomain that commutes with self multiplication, assumes that two is nonzero and one is sent to one.\n-/\ndef add_monoid_hom.mk_ring_hom_of_mul_self_of_two_ne_zero [comm_ring \u03b2] (f : \u03b2 \u2192+ \u03b1)\n  (h : \u2200 x, f (x * x) = f x * f x) (h_two : (2 : \u03b1) \u2260 0) (h_one : f 1 = 1) : \u03b2 \u2192+* \u03b1 :=\n{ map_one' := h_one,\n  map_mul' := begin\n    intros x y,\n    have hxy := h (x + y),\n    rw [mul_add, add_mul, add_mul, f.map_add, f.map_add, f.map_add, f.map_add, h x, h y, add_mul,\n      mul_add, mul_add, \u2190 sub_eq_zero, add_comm, \u2190 sub_sub, \u2190 sub_sub, \u2190 sub_sub,\n      mul_comm y x, mul_comm (f y) (f x)] at hxy,\n    simp only [add_assoc, add_sub_assoc, add_sub_cancel'_right] at hxy,\n    rw [sub_sub, \u2190 two_mul, \u2190 add_sub_assoc, \u2190 two_mul, \u2190 mul_sub, mul_eq_zero, sub_eq_zero,\n      or_iff_not_imp_left] at hxy,\n    exact hxy h_two,\n  end,\n  ..f }\n\n@[simp]\nlemma add_monoid_hom.coe_fn_mk_ring_hom_of_mul_self_of_two_ne_zero [comm_ring \u03b2] (f : \u03b2 \u2192+ \u03b1)\n  (h h_two h_one) :\n  (f.mk_ring_hom_of_mul_self_of_two_ne_zero h h_two h_one : \u03b2 \u2192 \u03b1) = f := rfl\n\n@[simp]\nlemma add_monoid_hom.coe_add_monoid_hom_mk_ring_hom_of_mul_self_of_two_ne_zero [comm_ring \u03b2]\n  (f : \u03b2 \u2192+ \u03b1) (h h_two h_one) :\n  (f.mk_ring_hom_of_mul_self_of_two_ne_zero h h_two h_one : \u03b2 \u2192+ \u03b1) = f := by {ext, simp}\n\nend comm_ring\n\nend is_domain\n\nnamespace semiconj_by\n\n@[simp] lemma add_right [distrib R] {a x y x' y' : R}\n  (h : semiconj_by a x y) (h' : semiconj_by a x' y') :\n  semiconj_by a (x + x') (y + y') :=\nby simp only [semiconj_by, left_distrib, right_distrib, h.eq, h'.eq]\n\n@[simp] lemma add_left [distrib R] {a b x y : R}\n  (ha : semiconj_by a x y) (hb : semiconj_by b x y) :\n  semiconj_by (a + b) x y :=\nby simp only [semiconj_by, left_distrib, right_distrib, ha.eq, hb.eq]\n\nvariables [ring R] {a b x y x' y' : R}\n\nlemma neg_right (h : semiconj_by a x y) : semiconj_by a (-x) (-y) :=\nby simp only [semiconj_by, h.eq, neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm]\n\n@[simp] lemma neg_right_iff : semiconj_by a (-x) (-y) \u2194 semiconj_by a x y :=\n\u27e8\u03bb h, neg_neg x \u25b8 neg_neg y \u25b8 h.neg_right, semiconj_by.neg_right\u27e9\n\nlemma neg_left (h : semiconj_by a x y) : semiconj_by (-a) x y :=\nby simp only [semiconj_by, h.eq, neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm]\n\n@[simp] lemma neg_left_iff : semiconj_by (-a) x y \u2194 semiconj_by a x y :=\n\u27e8\u03bb h, neg_neg a \u25b8 h.neg_left, semiconj_by.neg_left\u27e9\n\n@[simp] lemma neg_one_right (a : R) : semiconj_by a (-1) (-1) :=\n(one_right a).neg_right\n\n@[simp] lemma neg_one_left (x : R) : semiconj_by (-1) x x :=\n(semiconj_by.one_left x).neg_left\n\n@[simp] lemma sub_right (h : semiconj_by a x y) (h' : semiconj_by a x' y') :\n  semiconj_by a (x - x') (y - y') :=\nby simpa only [sub_eq_add_neg] using h.add_right h'.neg_right\n\n@[simp] lemma sub_left (ha : semiconj_by a x y) (hb : semiconj_by b x y) :\n  semiconj_by (a - b) x y :=\nby simpa only [sub_eq_add_neg] using ha.add_left hb.neg_left\n\nend semiconj_by\n\nnamespace commute\n\n@[simp] theorem add_right [distrib R] {a b c : R} :\n  commute a b \u2192 commute a c \u2192 commute a (b + c) :=\nsemiconj_by.add_right\n\n@[simp] theorem add_left [distrib R] {a b c : R} :\n  commute a c \u2192 commute b c \u2192 commute (a + b) c :=\nsemiconj_by.add_left\n\nlemma bit0_right [distrib R] {x y : R} (h : commute x y) : commute x (bit0 y) :=\nh.add_right h\n\nlemma bit0_left [distrib R] {x y : R} (h : commute x y) : commute (bit0 x) y :=\nh.add_left h\n\nlemma bit1_right [semiring R] {x y : R} (h : commute x y) : commute x (bit1 y) :=\nh.bit0_right.add_right (commute.one_right x)\n\nlemma bit1_left [semiring R] {x y : R} (h : commute x y) : commute (bit1 x) y :=\nh.bit0_left.add_left (commute.one_left y)\n\nvariables [ring R] {a b c : R}\n\ntheorem neg_right : commute a b \u2192 commute a (- b) := semiconj_by.neg_right\n@[simp] theorem neg_right_iff : commute a (-b) \u2194 commute a b := semiconj_by.neg_right_iff\n\ntheorem neg_left : commute a b \u2192 commute (- a) b := semiconj_by.neg_left\n@[simp] theorem neg_left_iff : commute (-a) b \u2194 commute a b := semiconj_by.neg_left_iff\n\n@[simp] theorem neg_one_right (a : R) : commute a (-1) := semiconj_by.neg_one_right a\n@[simp] theorem neg_one_left (a : R): commute (-1) a := semiconj_by.neg_one_left a\n\n@[simp] theorem sub_right : commute a b \u2192 commute a c \u2192 commute a (b - c) := semiconj_by.sub_right\n@[simp] theorem sub_left : commute a c \u2192 commute b c \u2192 commute (a - b) c := semiconj_by.sub_left\n\nend commute\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/ring/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.7235908674284209}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.big_operators.order\nimport Mathlib.tactic.default\nimport Mathlib.data.nat.prime\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Divisor finsets\n\nThis file defines sets of divisors of a natural number. This is particularly useful as background\nfor defining Dirichlet convolution.\n\n## Main Definitions\nLet `n : \u2115`. All of the following definitions are in the `nat` namespace:\n * `divisors n` is the `finset` of natural numbers that divide `n`.\n * `proper_divisors n` is the `finset` of natural numbers that divide `n`, other than `n`.\n * `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n * `perfect n` is true when `n` is positive and the sum of `proper_divisors n` is `n`.\n\n## Implementation details\n * `divisors 0`, `proper_divisors 0`, and `divisors_antidiagonal 0` are defined to be `\u2205`.\n\n## Tags\ndivisors, perfect numbers\n\n-/\n\nnamespace nat\n\n\n/-- `divisors n` is the `finset` of divisors of `n`. As a special case, `divisors 0 = \u2205`. -/\ndef divisors (n : \u2115) : finset \u2115 := finset.filter (fun (x : \u2115) => x \u2223 n) (finset.Ico 1 (n + 1))\n\n/-- `proper_divisors n` is the `finset` of divisors of `n`, other than `n`.\n  As a special case, `proper_divisors 0 = \u2205`. -/\ndef proper_divisors (n : \u2115) : finset \u2115 := finset.filter (fun (x : \u2115) => x \u2223 n) (finset.Ico 1 n)\n\n/-- `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n  As a special case, `divisors_antidiagonal 0 = \u2205`. -/\ndef divisors_antidiagonal (n : \u2115) : finset (\u2115 \u00d7 \u2115) :=\n  finset.filter (fun (x : \u2115 \u00d7 \u2115) => prod.fst x * prod.snd x = n)\n    (finset.product (finset.Ico 1 (n + 1)) (finset.Ico 1 (n + 1)))\n\ntheorem proper_divisors.not_self_mem {n : \u2115} : \u00acn \u2208 proper_divisors n := sorry\n\n@[simp] theorem mem_proper_divisors {n : \u2115} {m : \u2115} : n \u2208 proper_divisors m \u2194 n \u2223 m \u2227 n < m := sorry\n\ntheorem divisors_eq_proper_divisors_insert_self_of_pos {n : \u2115} (h : 0 < n) :\n    divisors n = insert n (proper_divisors n) :=\n  sorry\n\n@[simp] theorem mem_divisors {n : \u2115} {m : \u2115} : n \u2208 divisors m \u2194 n \u2223 m \u2227 m \u2260 0 := sorry\n\ntheorem dvd_of_mem_divisors {n : \u2115} {m : \u2115} (h : n \u2208 divisors m) : n \u2223 m := sorry\n\n@[simp] theorem mem_divisors_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} :\n    x \u2208 divisors_antidiagonal n \u2194 prod.fst x * prod.snd x = n \u2227 n \u2260 0 :=\n  sorry\n\ntheorem divisor_le {n : \u2115} {m : \u2115} : n \u2208 divisors m \u2192 n \u2264 m := sorry\n\ntheorem divisors_subset_of_dvd {n : \u2115} {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) :\n    divisors m \u2286 divisors n :=\n  iff.mpr finset.subset_iff\n    fun (x : \u2115) (hx : x \u2208 divisors m) =>\n      iff.mpr mem_divisors\n        { left := dvd.trans (and.left (iff.mp mem_divisors hx)) h, right := hzero }\n\ntheorem divisors_subset_proper_divisors {n : \u2115} {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n)\n    (hdiff : m \u2260 n) : divisors m \u2286 proper_divisors n :=\n  sorry\n\n@[simp] theorem divisors_zero : divisors 0 = \u2205 := sorry\n\n@[simp] theorem proper_divisors_zero : proper_divisors 0 = \u2205 := sorry\n\ntheorem proper_divisors_subset_divisors {n : \u2115} : proper_divisors n \u2286 divisors n := sorry\n\n@[simp] theorem divisors_one : divisors 1 = singleton 1 := sorry\n\n@[simp] theorem proper_divisors_one : proper_divisors 1 = \u2205 := sorry\n\ntheorem pos_of_mem_divisors {n : \u2115} {m : \u2115} (h : m \u2208 divisors n) : 0 < m := sorry\n\ntheorem pos_of_mem_proper_divisors {n : \u2115} {m : \u2115} (h : m \u2208 proper_divisors n) : 0 < m :=\n  pos_of_mem_divisors (proper_divisors_subset_divisors h)\n\ntheorem one_mem_proper_divisors_iff_one_lt {n : \u2115} : 1 \u2208 proper_divisors n \u2194 1 < n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 \u2208 proper_divisors n \u2194 1 < n)) (propext mem_proper_divisors)))\n    (eq.mpr\n      (id (Eq._oldrec (Eq.refl (1 \u2223 n \u2227 1 < n \u2194 1 < n)) (propext (and_iff_right (one_dvd n)))))\n      (iff.refl (1 < n)))\n\n@[simp] theorem divisors_antidiagonal_zero : divisors_antidiagonal 0 = \u2205 := sorry\n\n@[simp] theorem divisors_antidiagonal_one : divisors_antidiagonal 1 = singleton (1, 1) := sorry\n\ntheorem swap_mem_divisors_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n    prod.swap x \u2208 divisors_antidiagonal n :=\n  sorry\n\ntheorem fst_mem_divisors_of_mem_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n    prod.fst x \u2208 divisors n :=\n  sorry\n\ntheorem snd_mem_divisors_of_mem_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n    prod.snd x \u2208 divisors n :=\n  sorry\n\n@[simp] theorem map_swap_divisors_antidiagonal {n : \u2115} :\n    finset.map\n          (function.embedding.mk prod.swap\n            (function.right_inverse.injective prod.swap_right_inverse))\n          (divisors_antidiagonal n) =\n        divisors_antidiagonal n :=\n  sorry\n\ntheorem sum_divisors_eq_sum_proper_divisors_add_self {n : \u2115} :\n    (finset.sum (divisors n) fun (i : \u2115) => i) =\n        (finset.sum (proper_divisors n) fun (i : \u2115) => i) + n :=\n  sorry\n\n/-- `n : \u2115` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`\n  is positive. -/\ndef perfect (n : \u2115) := (finset.sum (proper_divisors n) fun (i : \u2115) => i) = n \u2227 0 < n\n\ntheorem perfect_iff_sum_proper_divisors {n : \u2115} (h : 0 < n) :\n    perfect n \u2194 (finset.sum (proper_divisors n) fun (i : \u2115) => i) = n :=\n  and_iff_left h\n\ntheorem perfect_iff_sum_divisors_eq_two_mul {n : \u2115} (h : 0 < n) :\n    perfect n \u2194 (finset.sum (divisors n) fun (i : \u2115) => i) = bit0 1 * n :=\n  sorry\n\ntheorem mem_divisors_prime_pow {p : \u2115} (pp : prime p) (k : \u2115) {x : \u2115} :\n    x \u2208 divisors (p ^ k) \u2194 \u2203 (j : \u2115), \u2203 (H : j \u2264 k), x = p ^ j :=\n  sorry\n\ntheorem prime.divisors {p : \u2115} (pp : prime p) : divisors p = insert 1 (singleton p) := sorry\n\ntheorem prime.proper_divisors {p : \u2115} (pp : prime p) : proper_divisors p = singleton 1 := sorry\n\ntheorem divisors_prime_pow {p : \u2115} (pp : prime p) (k : \u2115) :\n    divisors (p ^ k) =\n        finset.map (function.embedding.mk (pow p) (pow_right_injective (prime.two_le pp)))\n          (finset.range (k + 1)) :=\n  sorry\n\ntheorem eq_proper_divisors_of_subset_of_sum_eq_sum {n : \u2115} {s : finset \u2115}\n    (hsub : s \u2286 proper_divisors n) :\n    ((finset.sum s fun (x : \u2115) => x) = finset.sum (proper_divisors n) fun (x : \u2115) => x) \u2192\n        s = proper_divisors n :=\n  sorry\n\ntheorem sum_proper_divisors_dvd {n : \u2115}\n    (h : (finset.sum (proper_divisors n) fun (x : \u2115) => x) \u2223 n) :\n    (finset.sum (proper_divisors n) fun (x : \u2115) => x) = 1 \u2228\n        (finset.sum (proper_divisors n) fun (x : \u2115) => x) = n :=\n  sorry\n\n@[simp] theorem prime.sum_proper_divisors {\u03b1 : Type u_1} [add_comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1}\n    (h : prime p) : (finset.sum (proper_divisors p) fun (x : \u2115) => f x) = f 1 :=\n  sorry\n\n@[simp] theorem prime.sum_divisors {\u03b1 : Type u_1} [add_comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1}\n    (h : prime p) : (finset.sum (divisors p) fun (x : \u2115) => f x) = f p + f 1 :=\n  sorry\n\ntheorem proper_divisors_eq_singleton_one_iff_prime {n : \u2115} :\n    proper_divisors n = singleton 1 \u2194 prime n :=\n  sorry\n\ntheorem sum_proper_divisors_eq_one_iff_prime {n : \u2115} :\n    (finset.sum (proper_divisors n) fun (x : \u2115) => x) = 1 \u2194 prime n :=\n  sorry\n\n@[simp] theorem prod_divisors_prime {\u03b1 : Type u_1} [comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1}\n    (h : prime p) : (finset.prod (divisors p) fun (x : \u2115) => f x) = f p * f 1 :=\n  prime.sum_divisors h\n\n@[simp] theorem sum_divisors_prime_pow {\u03b1 : Type u_1} [add_comm_monoid \u03b1] {k : \u2115} {p : \u2115}\n    {f : \u2115 \u2192 \u03b1} (h : prime p) :\n    (finset.sum (divisors (p ^ k)) fun (x : \u2115) => f x) =\n        finset.sum (finset.range (k + 1)) fun (x : \u2115) => f (p ^ x) :=\n  sorry\n\n@[simp] theorem prod_divisors_prime_pow {\u03b1 : Type u_1} [comm_monoid \u03b1] {k : \u2115} {p : \u2115} {f : \u2115 \u2192 \u03b1}\n    (h : prime p) :\n    (finset.prod (divisors (p ^ k)) fun (x : \u2115) => f x) =\n        finset.prod (finset.range (k + 1)) fun (x : \u2115) => f (p ^ x) :=\n  sum_divisors_prime_pow h\n\n@[simp] theorem filter_dvd_eq_divisors {n : \u2115} (h : n \u2260 0) :\n    finset.filter (fun (x : \u2115) => x \u2223 n) (finset.range (Nat.succ n)) = divisors n :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/number_theory/divisors_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7234967341423094}}
{"text": "/-\nCopyright (c) 2020 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.calculus.iterated_deriv\nimport analysis.inner_product_space.euclidean_dist\n\n/-!\n# Infinitely smooth bump function\n\nIn this file we construct several infinitely smooth functions with properties that an analytic\nfunction cannot have:\n\n* `exp_neg_inv_glue` is equal to zero for `x \u2264 0` and is strictly positive otherwise; it is given by\n  `x \u21a6 exp (-1/x)` for `x > 0`;\n\n* `real.smooth_transition` is equal to zero for `x \u2264 0` and is equal to one for `x \u2265 1`; it is given\n  by `exp_neg_inv_glue x / (exp_neg_inv_glue x + exp_neg_inv_glue (1 - x))`;\n\n* `f : cont_diff_bump_of_inner c`, where `c` is a point in an inner product space, is\n  a bundled smooth function such that\n\n  - `f` is equal to `1` in `metric.closed_ball c f.r`;\n  - `support f = metric.ball c f.R`;\n  - `0 \u2264 f x \u2264 1` for all `x`.\n\n  The structure `cont_diff_bump_of_inner` contains the data required to construct the\n  function: real numbers `r`, `R`, and proofs of `0 < r < R`. The function itself is available\n  through `coe_fn`.\n\n* `f : cont_diff_bump c`, where `c` is a point in a finite dimensional real vector space, is a\n  bundled smooth function such that\n\n  - `f` is equal to `1` in `euclidean.closed_ball c f.r`;\n  - `support f = euclidean.ball c f.R`;\n  - `0 \u2264 f x \u2264 1` for all `x`.\n\n  The structure `cont_diff_bump` contains the data required to construct the function: real\n  numbers `r`, `R`, and proofs of `0 < r < R`. The function itself is available through `coe_fn`.\n-/\n\nnoncomputable theory\nopen_locale classical topological_space\n\nopen polynomial real filter set function\n\n/-- `exp_neg_inv_glue` is the real function given by `x \u21a6 exp (-1/x)` for `x > 0` and `0`\nfor `x \u2264 0`. It is a basic building block to construct smooth partitions of unity. Its main property\nis that it vanishes for `x \u2264 0`, it is positive for `x > 0`, and the junction between the two\nbehaviors is flat enough to retain smoothness. The fact that this function is `C^\u221e` is proved in\n`exp_neg_inv_glue.smooth`. -/\ndef exp_neg_inv_glue (x : \u211d) : \u211d := if x \u2264 0 then 0 else exp (-x\u207b\u00b9)\n\nnamespace exp_neg_inv_glue\n\n/-- Our goal is to prove that `exp_neg_inv_glue` is `C^\u221e`. For this, we compute its successive\nderivatives for `x > 0`. The `n`-th derivative is of the form `P_aux n (x) exp(-1/x) / x^(2 n)`,\nwhere `P_aux n` is computed inductively. -/\nnoncomputable def P_aux : \u2115 \u2192 polynomial \u211d\n| 0 := 1\n| (n+1) := X^2 * (P_aux n).derivative  + (1 - C \u2191(2 * n) * X) * (P_aux n)\n\n/-- Formula for the `n`-th derivative of `exp_neg_inv_glue`, as an auxiliary function `f_aux`. -/\ndef f_aux (n : \u2115) (x : \u211d) : \u211d :=\nif x \u2264 0 then 0 else (P_aux n).eval x * exp (-x\u207b\u00b9) / x^(2 * n)\n\n/-- The `0`-th auxiliary function `f_aux 0` coincides with `exp_neg_inv_glue`, by definition. -/\nlemma f_aux_zero_eq : f_aux 0 = exp_neg_inv_glue :=\nbegin\n  ext x,\n  by_cases h : x \u2264 0,\n  { simp [exp_neg_inv_glue, f_aux, h] },\n  { simp [h, exp_neg_inv_glue, f_aux, ne_of_gt (not_le.1 h), P_aux] }\nend\n\n/-- For positive values, the derivative of the `n`-th auxiliary function `f_aux n`\n(given in this statement in unfolded form) is the `n+1`-th auxiliary function, since\nthe polynomial `P_aux (n+1)` was chosen precisely to ensure this. -/\nlemma f_aux_deriv (n : \u2115) (x : \u211d) (hx : x \u2260 0) :\n  has_deriv_at (\u03bbx, (P_aux n).eval x * exp (-x\u207b\u00b9) / x^(2 * n))\n    ((P_aux (n+1)).eval x * exp (-x\u207b\u00b9) / x^(2 * (n + 1))) x :=\nbegin\n  have A : \u2200 k : \u2115, 2 * (k + 1) - 1 = 2 * k + 1 := \u03bb k, rfl,\n  convert (((P_aux n).has_deriv_at x).mul\n               (((has_deriv_at_exp _).comp x (has_deriv_at_inv hx).neg))).div\n            (has_deriv_at_pow (2 * n) x) (pow_ne_zero _ hx) using 1,\n  field_simp [hx, P_aux],\n  -- `ring_exp` can't solve `p \u2228 q` goal generated by `mul_eq_mul_right_iff`\n  cases n; simp [nat.succ_eq_add_one, A, -mul_eq_mul_right_iff]; ring_exp\nend\n\n/-- For positive values, the derivative of the `n`-th auxiliary function `f_aux n`\nis the `n+1`-th auxiliary function. -/\nlemma f_aux_deriv_pos (n : \u2115) (x : \u211d) (hx : 0 < x) :\n  has_deriv_at (f_aux n) ((P_aux (n+1)).eval x * exp (-x\u207b\u00b9) / x^(2 * (n + 1))) x :=\nbegin\n  apply (f_aux_deriv n x (ne_of_gt hx)).congr_of_eventually_eq,\n  filter_upwards [lt_mem_nhds hx] with _ hy,\n  simp [f_aux, hy.not_le]\nend\n\n/-- To get differentiability at `0` of the auxiliary functions, we need to know that their limit\nis `0`, to be able to apply general differentiability extension theorems. This limit is checked in\nthis lemma. -/\nlemma f_aux_limit (n : \u2115) :\n  tendsto (\u03bbx, (P_aux n).eval x * exp (-x\u207b\u00b9) / x^(2 * n)) (\ud835\udcdd[>] 0) (\ud835\udcdd 0) :=\nbegin\n  have A : tendsto (\u03bbx, (P_aux n).eval x) (\ud835\udcdd[>] 0) (\ud835\udcdd ((P_aux n).eval 0)) :=\n  (P_aux n).continuous_within_at,\n  have B : tendsto (\u03bbx, exp (-x\u207b\u00b9) / x^(2 * n)) (\ud835\udcdd[>] 0) (\ud835\udcdd 0),\n  { convert (tendsto_pow_mul_exp_neg_at_top_nhds_0 (2 * n)).comp tendsto_inv_zero_at_top,\n    ext x,\n    field_simp },\n  convert A.mul B;\n  simp [mul_div_assoc]\nend\n\n/-- Deduce from the limiting behavior at `0` of its derivative and general differentiability\nextension theorems that the auxiliary function `f_aux n` is differentiable at `0`,\nwith derivative `0`. -/\nlemma f_aux_deriv_zero (n : \u2115) : has_deriv_at (f_aux n) 0 0 :=\nbegin\n  -- we check separately differentiability on the left and on the right\n  have A : has_deriv_within_at (f_aux n) (0 : \u211d) (Iic 0) 0,\n  { apply (has_deriv_at_const (0 : \u211d) (0 : \u211d)).has_deriv_within_at.congr,\n    { assume y hy,\n      simp at hy,\n      simp [f_aux, hy] },\n    { simp [f_aux, le_refl] } },\n  have B : has_deriv_within_at (f_aux n) (0 : \u211d) (Ici 0) 0,\n  { have diff : differentiable_on \u211d (f_aux n) (Ioi 0) :=\n      \u03bbx hx, (f_aux_deriv_pos n x hx).differentiable_at.differentiable_within_at,\n    -- next line is the nontrivial bit of this proof, appealing to differentiability\n    -- extension results.\n    apply has_deriv_at_interval_left_endpoint_of_tendsto_deriv diff _ self_mem_nhds_within,\n    { refine (f_aux_limit (n+1)).congr' _,\n      apply mem_of_superset self_mem_nhds_within (\u03bbx hx, _),\n      simp [(f_aux_deriv_pos n x hx).deriv] },\n    { have : f_aux n 0 = 0, by simp [f_aux, le_refl],\n      simp only [continuous_within_at, this],\n      refine (f_aux_limit n).congr' _,\n      apply mem_of_superset self_mem_nhds_within (\u03bbx hx, _),\n      have : \u00ac(x \u2264 0), by simpa using hx,\n      simp [f_aux, this] } },\n  simpa using A.union B,\nend\n\n/-- At every point, the auxiliary function `f_aux n` has a derivative which is\nequal to `f_aux (n+1)`. -/\nlemma f_aux_has_deriv_at (n : \u2115) (x : \u211d) : has_deriv_at (f_aux n) (f_aux (n+1) x) x :=\nbegin\n  -- check separately the result for `x < 0`, where it is trivial, for `x > 0`, where it is done\n  -- in `f_aux_deriv_pos`, and for `x = 0`, done in\n  -- `f_aux_deriv_zero`.\n  rcases lt_trichotomy x 0 with hx|hx|hx,\n  { have : f_aux (n+1) x = 0, by simp [f_aux, le_of_lt hx],\n    rw this,\n    apply (has_deriv_at_const x (0 : \u211d)).congr_of_eventually_eq,\n    filter_upwards [gt_mem_nhds hx] with _ hy,\n    simp [f_aux, hy.le] },\n  { have : f_aux (n + 1) 0 = 0, by simp [f_aux, le_refl],\n    rw [hx, this],\n    exact f_aux_deriv_zero n },\n  { have : f_aux (n+1) x = (P_aux (n+1)).eval x * exp (-x\u207b\u00b9) / x^(2 * (n+1)),\n      by simp [f_aux, not_le_of_gt hx],\n    rw this,\n    exact f_aux_deriv_pos n x hx },\nend\n\n/-- The successive derivatives of the auxiliary function `f_aux 0` are the\nfunctions `f_aux n`, by induction. -/\nlemma f_aux_iterated_deriv (n : \u2115) : iterated_deriv n (f_aux 0) = f_aux n :=\nbegin\n  induction n with n IH,\n  { simp },\n  { simp [iterated_deriv_succ, IH],\n    ext x,\n    exact (f_aux_has_deriv_at n x).deriv }\nend\n\n/-- The function `exp_neg_inv_glue` is smooth. -/\nprotected theorem cont_diff {n} : cont_diff \u211d n exp_neg_inv_glue :=\nbegin\n  rw \u2190 f_aux_zero_eq,\n  apply cont_diff_of_differentiable_iterated_deriv (\u03bb m hm, _),\n  rw f_aux_iterated_deriv m,\n  exact \u03bb x, (f_aux_has_deriv_at m x).differentiable_at\nend\n\n/-- The function `exp_neg_inv_glue` vanishes on `(-\u221e, 0]`. -/\nlemma zero_of_nonpos {x : \u211d} (hx : x \u2264 0) : exp_neg_inv_glue x = 0 :=\nby simp [exp_neg_inv_glue, hx]\n\n/-- The function `exp_neg_inv_glue` is positive on `(0, +\u221e)`. -/\nlemma pos_of_pos {x : \u211d} (hx : 0 < x) : 0 < exp_neg_inv_glue x :=\nby simp [exp_neg_inv_glue, not_le.2 hx, exp_pos]\n\n/-- The function exp_neg_inv_glue` is nonnegative. -/\nlemma nonneg (x : \u211d) : 0 \u2264 exp_neg_inv_glue x :=\nbegin\n  cases le_or_gt x 0,\n  { exact ge_of_eq (zero_of_nonpos h) },\n  { exact le_of_lt (pos_of_pos h) }\nend\n\nend exp_neg_inv_glue\n\n/-- An infinitely smooth function `f : \u211d \u2192 \u211d` such that `f x = 0` for `x \u2264 0`,\n`f x = 1` for `1 \u2264 x`, and `0 < f x < 1` for `0 < x < 1`. -/\ndef real.smooth_transition (x : \u211d) : \u211d :=\nexp_neg_inv_glue x / (exp_neg_inv_glue x + exp_neg_inv_glue (1 - x))\n\nnamespace real\n\nnamespace smooth_transition\n\nvariables {x : \u211d}\n\nopen exp_neg_inv_glue\n\nlemma pos_denom (x) : 0 < exp_neg_inv_glue x + exp_neg_inv_glue (1 - x) :=\n((@zero_lt_one \u211d _ _).lt_or_lt x).elim\n  (\u03bb hx, add_pos_of_pos_of_nonneg (pos_of_pos hx) (nonneg _))\n  (\u03bb hx, add_pos_of_nonneg_of_pos (nonneg _) (pos_of_pos $ sub_pos.2 hx))\n\nlemma one_of_one_le (h : 1 \u2264 x) : smooth_transition x = 1 :=\n(div_eq_one_iff_eq $ (pos_denom x).ne').2 $ by rw [zero_of_nonpos (sub_nonpos.2 h), add_zero]\n\nlemma zero_of_nonpos (h : x \u2264 0) : smooth_transition x = 0 :=\nby rw [smooth_transition, zero_of_nonpos h, zero_div]\n\nlemma le_one (x : \u211d) : smooth_transition x \u2264 1 :=\n(div_le_one (pos_denom x)).2 $ le_add_of_nonneg_right (nonneg _)\n\nlemma nonneg (x : \u211d) : 0 \u2264 smooth_transition x :=\ndiv_nonneg (exp_neg_inv_glue.nonneg _) (pos_denom x).le\n\nlemma lt_one_of_lt_one (h : x < 1) : smooth_transition x < 1 :=\n(div_lt_one $ pos_denom x).2 $ lt_add_of_pos_right _ $ pos_of_pos $ sub_pos.2 h\n\nlemma pos_of_pos (h : 0 < x) : 0 < smooth_transition x :=\ndiv_pos (exp_neg_inv_glue.pos_of_pos h) (pos_denom x)\n\nprotected lemma cont_diff {n} : cont_diff \u211d n smooth_transition :=\nexp_neg_inv_glue.cont_diff.div\n  (exp_neg_inv_glue.cont_diff.add $ exp_neg_inv_glue.cont_diff.comp $\n    cont_diff_const.sub cont_diff_id) $\n  \u03bb x, (pos_denom x).ne'\n\nprotected lemma cont_diff_at {x n} : cont_diff_at \u211d n smooth_transition x :=\nsmooth_transition.cont_diff.cont_diff_at\n\nend smooth_transition\n\nend real\n\nvariable {E : Type*}\n\n/-- `f : cont_diff_bump_of_inner c`, where `c` is a point in an inner product space, is a\nbundled smooth function such that\n\n- `f` is equal to `1` in `metric.closed_ball c f.r`;\n- `support f = metric.ball c f.R`;\n- `0 \u2264 f x \u2264 1` for all `x`.\n\nThe structure `cont_diff_bump_of_inner` contains the data required to construct the function:\nreal numbers `r`, `R`, and proofs of `0 < r < R`. The function itself is available through\n`coe_fn`. -/\nstructure cont_diff_bump_of_inner (c : E) :=\n(r R : \u211d)\n(r_pos : 0 < r)\n(r_lt_R : r < R)\n\nnamespace cont_diff_bump_of_inner\n\nlemma R_pos {c : E} (f : cont_diff_bump_of_inner c) : 0 < f.R := f.r_pos.trans f.r_lt_R\n\ninstance (c : E) : inhabited (cont_diff_bump_of_inner c) := \u27e8\u27e81, 2, zero_lt_one, one_lt_two\u27e9\u27e9\n\nvariables [inner_product_space \u211d E] {c : E} (f : cont_diff_bump_of_inner c) {x : E}\n\n/-- The function defined by `f : cont_diff_bump_of_inner c`. Use automatic coercion to\nfunction instead. -/\ndef to_fun (f : cont_diff_bump_of_inner c) : E \u2192 \u211d :=\n\u03bb x, real.smooth_transition ((f.R - dist x c) / (f.R - f.r))\n\ninstance : has_coe_to_fun (cont_diff_bump_of_inner c) (\u03bb _, E \u2192 \u211d) := \u27e8to_fun\u27e9\n\nopen real (smooth_transition) real.smooth_transition metric\n\nlemma one_of_mem_closed_ball (hx : x \u2208 closed_ball c f.r) :\n  f x = 1 :=\none_of_one_le $ (one_le_div (sub_pos.2 f.r_lt_R)).2 $ sub_le_sub_left hx _\n\nlemma nonneg : 0 \u2264 f x := nonneg _\n\nlemma le_one : f x \u2264 1 := le_one _\n\nlemma pos_of_mem_ball (hx : x \u2208 ball c f.R) : 0 < f x :=\npos_of_pos $ div_pos (sub_pos.2 hx) (sub_pos.2 f.r_lt_R)\n\nlemma lt_one_of_lt_dist (h : f.r < dist x c) : f x < 1 :=\nlt_one_of_lt_one $ (div_lt_one (sub_pos.2 f.r_lt_R)).2 $ sub_lt_sub_left h _\n\nlemma zero_of_le_dist (hx : f.R \u2264 dist x c) : f x = 0 :=\nzero_of_nonpos $ div_nonpos_of_nonpos_of_nonneg (sub_nonpos.2 hx) (sub_nonneg.2 f.r_lt_R.le)\n\nlemma support_eq : support (f : E \u2192 \u211d) = metric.ball c f.R :=\nbegin\n  ext x,\n  suffices : f x \u2260 0 \u2194 dist x c < f.R, by simpa [mem_support],\n  cases lt_or_le (dist x c) f.R with hx hx,\n  { simp [hx, (f.pos_of_mem_ball hx).ne'] },\n  { simp [hx.not_lt, f.zero_of_le_dist hx] }\nend\n\nlemma eventually_eq_one_of_mem_ball (h : x \u2208 ball c f.r) :\n  f =\u1da0[\ud835\udcdd x] 1 :=\n((is_open_lt (continuous_id.dist continuous_const) continuous_const).eventually_mem h).mono $\n  \u03bb z hz, f.one_of_mem_closed_ball (le_of_lt hz)\n\nlemma eventually_eq_one : f =\u1da0[\ud835\udcdd c] 1 :=\nf.eventually_eq_one_of_mem_ball (mem_ball_self f.r_pos)\n\nprotected lemma cont_diff_at {n} :\n  cont_diff_at \u211d n f x :=\nbegin\n  rcases em (x = c) with rfl|hx,\n  { refine cont_diff_at.congr_of_eventually_eq _ f.eventually_eq_one,\n    rw pi.one_def,\n    exact cont_diff_at_const },\n  { exact real.smooth_transition.cont_diff_at.comp x\n      (cont_diff_at.div_const $ cont_diff_at_const.sub $\n        cont_diff_at_id.dist cont_diff_at_const hx) }\nend\n\nprotected lemma cont_diff {n} :\n  cont_diff \u211d n f :=\ncont_diff_iff_cont_diff_at.2 $ \u03bb y, f.cont_diff_at\n\nprotected lemma cont_diff_within_at {s n} :\n  cont_diff_within_at \u211d n f s x :=\nf.cont_diff_at.cont_diff_within_at\n\nend cont_diff_bump_of_inner\n\n/-- `f : cont_diff_bump c`, where `c` is a point in a finite dimensional real vector space, is\na bundled smooth function such that\n\n  - `f` is equal to `1` in `euclidean.closed_ball c f.r`;\n  - `support f = euclidean.ball c f.R`;\n  - `0 \u2264 f x \u2264 1` for all `x`.\n\nThe structure `cont_diff_bump` contains the data required to construct the function: real\nnumbers `r`, `R`, and proofs of `0 < r < R`. The function itself is available through `coe_fn`.-/\nstructure cont_diff_bump [normed_group E] [normed_space \u211d E] [finite_dimensional \u211d E] (c : E)\n  extends cont_diff_bump_of_inner (to_euclidean c)\n\nnamespace cont_diff_bump\n\nvariables [normed_group E] [normed_space \u211d E] [finite_dimensional \u211d E] {c x : E}\n  (f : cont_diff_bump c)\n\n/-- The function defined by `f : cont_diff_bump c`. Use automatic coercion to function\ninstead. -/\ndef to_fun (f : cont_diff_bump c) : E \u2192 \u211d := f.to_cont_diff_bump_of_inner \u2218 to_euclidean\n\ninstance : has_coe_to_fun (cont_diff_bump c) (\u03bb _, E \u2192 \u211d) := \u27e8to_fun\u27e9\n\ninstance (c : E) : inhabited (cont_diff_bump c) := \u27e8\u27e8default\u27e9\u27e9\n\nlemma R_pos : 0 < f.R := f.to_cont_diff_bump_of_inner.R_pos\n\nlemma coe_eq_comp : \u21d1f = f.to_cont_diff_bump_of_inner \u2218 to_euclidean := rfl\n\nlemma one_of_mem_closed_ball (hx : x \u2208 euclidean.closed_ball c f.r) :\n  f x = 1 :=\nf.to_cont_diff_bump_of_inner.one_of_mem_closed_ball hx\n\nlemma nonneg : 0 \u2264 f x := f.to_cont_diff_bump_of_inner.nonneg\n\nlemma le_one : f x \u2264 1 := f.to_cont_diff_bump_of_inner.le_one\n\nlemma pos_of_mem_ball (hx : x \u2208 euclidean.ball c f.R) : 0 < f x :=\nf.to_cont_diff_bump_of_inner.pos_of_mem_ball hx\n\nlemma lt_one_of_lt_dist (h : f.r < euclidean.dist x c) : f x < 1 :=\nf.to_cont_diff_bump_of_inner.lt_one_of_lt_dist h\n\nlemma zero_of_le_dist (hx : f.R \u2264 euclidean.dist x c) : f x = 0 :=\nf.to_cont_diff_bump_of_inner.zero_of_le_dist hx\n\nlemma support_eq : support (f : E \u2192 \u211d) = euclidean.ball c f.R :=\nby rw [euclidean.ball_eq_preimage, \u2190 f.to_cont_diff_bump_of_inner.support_eq,\n  \u2190 support_comp_eq_preimage, coe_eq_comp]\n\nlemma tsupport_eq : tsupport f = euclidean.closed_ball c f.R :=\nby rw [tsupport, f.support_eq, euclidean.closure_ball _ f.R_pos.ne']\n\nprotected lemma has_compact_support : has_compact_support f :=\nby simp_rw [has_compact_support, f.tsupport_eq, euclidean.is_compact_closed_ball]\n\nlemma eventually_eq_one_of_mem_ball (h : x \u2208 euclidean.ball c f.r) :\n  f =\u1da0[\ud835\udcdd x] 1 :=\nto_euclidean.continuous_at (f.to_cont_diff_bump_of_inner.eventually_eq_one_of_mem_ball h)\n\nlemma eventually_eq_one : f =\u1da0[\ud835\udcdd c] 1 :=\nf.eventually_eq_one_of_mem_ball $ euclidean.mem_ball_self f.r_pos\n\nprotected lemma cont_diff {n} :\n  cont_diff \u211d n f :=\nf.to_cont_diff_bump_of_inner.cont_diff.comp (to_euclidean : E \u2243L[\u211d] _).cont_diff\n\nprotected lemma cont_diff_at {n} :\n  cont_diff_at \u211d n f x :=\nf.cont_diff.cont_diff_at\n\nprotected lemma cont_diff_within_at {s n} :\n  cont_diff_within_at \u211d n f s x :=\nf.cont_diff_at.cont_diff_within_at\n\nlemma exists_tsupport_subset {s : set E} (hs : s \u2208 \ud835\udcdd c) :\n  \u2203 f : cont_diff_bump c, tsupport f \u2286 s :=\nlet \u27e8R, h0, hR\u27e9 := euclidean.nhds_basis_closed_ball.mem_iff.1 hs\nin \u27e8\u27e8\u27e8R / 2, R, half_pos h0, half_lt_self h0\u27e9\u27e9, by rwa tsupport_eq\u27e9\n\nlemma exists_closure_subset {R : \u211d} (hR : 0 < R)\n  {s : set E} (hs : is_closed s) (hsR : s \u2286 euclidean.ball c R) :\n  \u2203 f : cont_diff_bump c, f.R = R \u2227 s \u2286 euclidean.ball c f.r :=\nbegin\n  rcases euclidean.exists_pos_lt_subset_ball hR hs hsR with \u27e8r, hr, hsr\u27e9,\n  exact \u27e8\u27e8\u27e8r, R, hr.1, hr.2\u27e9\u27e9, rfl, hsr\u27e9\nend\n\nend cont_diff_bump\n\nopen finite_dimensional metric\n\n/-- If `E` is a finite dimensional normed space over `\u211d`, then for any point `x : E` and its\nneighborhood `s` there exists an infinitely smooth function with the following properties:\n\n* `f y = 1` in a neighborhood of `x`;\n* `f y = 0` outside of `s`;\n*  moreover, `tsupport f \u2286 s` and `f` has compact support;\n* `f y \u2208 [0, 1]` for all `y`.\n\nThis lemma is a simple wrapper around lemmas about bundled smooth bump functions, see\n`cont_diff_bump`. -/\nlemma exists_cont_diff_bump_function_of_mem_nhds [normed_group E] [normed_space \u211d E]\n  [finite_dimensional \u211d E] {x : E} {s : set E} (hs : s \u2208 \ud835\udcdd x) :\n  \u2203 f : E \u2192 \u211d, f =\u1da0[\ud835\udcdd x] 1 \u2227 (\u2200 y, f y \u2208 Icc (0 : \u211d) 1) \u2227 cont_diff \u211d \u22a4 f \u2227\n    has_compact_support f \u2227 tsupport f \u2286 s :=\nlet \u27e8f, hf\u27e9 := cont_diff_bump.exists_tsupport_subset hs in\n\u27e8f, f.eventually_eq_one, \u03bb y, \u27e8f.nonneg, f.le_one\u27e9, f.cont_diff,\n  f.has_compact_support, hf\u27e9\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/calculus/specific_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7234967263754318}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.filter.bases\nimport Mathlib.data.finset.preimage\nimport Mathlib.PostPort\n\nuniverses u_3 u_1 u_4 u_5 u_2 u_6 \n\nnamespace Mathlib\n\n/-!\n# `at_top` and `at_bot` filters on preorded sets, monoids and groups.\n\nIn this file we define the filters\n\n* `at_top`: corresponds to `n \u2192 +\u221e`;\n* `at_bot`: corresponds to `n \u2192 -\u221e`.\n\nThen we prove many lemmas like \u201cif `f \u2192 +\u221e`, then `f \u00b1 c \u2192 +\u221e`\u201d.\n-/\n\nnamespace filter\n\n\n/-- `at_top` is the filter representing the limit `\u2192 \u221e` on an ordered set.\n  It is generated by the collection of up-sets `{b | a \u2264 b}`.\n  (The preorder need not have a top element for this to be well defined,\n  and indeed is trivial when a top element exists.) -/\ndef at_top {\u03b1 : Type u_3} [preorder \u03b1] : filter \u03b1 := infi fun (a : \u03b1) => principal (set.Ici a)\n\n/-- `at_bot` is the filter representing the limit `\u2192 -\u221e` on an ordered set.\n  It is generated by the collection of down-sets `{b | b \u2264 a}`.\n  (The preorder need not have a bottom element for this to be well defined,\n  and indeed is trivial when a bottom element exists.) -/\ndef at_bot {\u03b1 : Type u_3} [preorder \u03b1] : filter \u03b1 := infi fun (a : \u03b1) => principal (set.Iic a)\n\ntheorem mem_at_top {\u03b1 : Type u_3} [preorder \u03b1] (a : \u03b1) : (set_of fun (b : \u03b1) => a \u2264 b) \u2208 at_top :=\n  mem_infi_sets a (set.subset.refl (set.Ici a))\n\ntheorem Ioi_mem_at_top {\u03b1 : Type u_3} [preorder \u03b1] [no_top_order \u03b1] (x : \u03b1) : set.Ioi x \u2208 at_top :=\n  sorry\n\ntheorem mem_at_bot {\u03b1 : Type u_3} [preorder \u03b1] (a : \u03b1) : (set_of fun (b : \u03b1) => b \u2264 a) \u2208 at_bot :=\n  mem_infi_sets a (set.subset.refl (set.Iic a))\n\ntheorem Iio_mem_at_bot {\u03b1 : Type u_3} [preorder \u03b1] [no_bot_order \u03b1] (x : \u03b1) : set.Iio x \u2208 at_bot :=\n  sorry\n\ntheorem at_top_basis {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_sup \u03b1] :\n    has_basis at_top (fun (_x : \u03b1) => True) set.Ici :=\n  has_basis_infi_principal (directed_of_sup fun (a b : \u03b1) => iff.mpr set.Ici_subset_Ici)\n\ntheorem at_top_basis' {\u03b1 : Type u_3} [semilattice_sup \u03b1] (a : \u03b1) :\n    has_basis at_top (fun (x : \u03b1) => a \u2264 x) set.Ici :=\n  sorry\n\ntheorem at_bot_basis {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_inf \u03b1] :\n    has_basis at_bot (fun (_x : \u03b1) => True) set.Iic :=\n  at_top_basis\n\ntheorem at_bot_basis' {\u03b1 : Type u_3} [semilattice_inf \u03b1] (a : \u03b1) :\n    has_basis at_bot (fun (x : \u03b1) => x \u2264 a) set.Iic :=\n  at_top_basis' a\n\ninstance at_top_ne_bot {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_sup \u03b1] : ne_bot at_top :=\n  iff.mpr (has_basis.ne_bot_iff at_top_basis) fun (a : \u03b1) (_x : True) => set.nonempty_Ici\n\ninstance at_bot_ne_bot {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_inf \u03b1] : ne_bot at_bot :=\n  at_top_ne_bot\n\n@[simp] theorem mem_at_top_sets {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_sup \u03b1] {s : set \u03b1} :\n    s \u2208 at_top \u2194 \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2265 a \u2192 b \u2208 s :=\n  iff.trans (has_basis.mem_iff at_top_basis) (exists_congr fun (_x : \u03b1) => exists_const True)\n\n@[simp] theorem mem_at_bot_sets {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_inf \u03b1] {s : set \u03b1} :\n    s \u2208 at_bot \u2194 \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2264 a \u2192 b \u2208 s :=\n  mem_at_top_sets\n\n@[simp] theorem eventually_at_top {\u03b1 : Type u_3} [semilattice_sup \u03b1] [Nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n    filter.eventually (fun (x : \u03b1) => p x) at_top \u2194 \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2265 a \u2192 p b :=\n  mem_at_top_sets\n\n@[simp] theorem eventually_at_bot {\u03b1 : Type u_3} [semilattice_inf \u03b1] [Nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n    filter.eventually (fun (x : \u03b1) => p x) at_bot \u2194 \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2264 a \u2192 p b :=\n  mem_at_bot_sets\n\ntheorem eventually_ge_at_top {\u03b1 : Type u_3} [preorder \u03b1] (a : \u03b1) :\n    filter.eventually (fun (x : \u03b1) => a \u2264 x) at_top :=\n  mem_at_top a\n\ntheorem eventually_le_at_bot {\u03b1 : Type u_3} [preorder \u03b1] (a : \u03b1) :\n    filter.eventually (fun (x : \u03b1) => x \u2264 a) at_bot :=\n  mem_at_bot a\n\ntheorem eventually_gt_at_top {\u03b1 : Type u_3} [preorder \u03b1] [no_top_order \u03b1] (a : \u03b1) :\n    filter.eventually (fun (x : \u03b1) => a < x) at_top :=\n  Ioi_mem_at_top a\n\ntheorem eventually_lt_at_bot {\u03b1 : Type u_3} [preorder \u03b1] [no_bot_order \u03b1] (a : \u03b1) :\n    filter.eventually (fun (x : \u03b1) => x < a) at_bot :=\n  Iio_mem_at_bot a\n\ntheorem at_top_basis_Ioi {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_sup \u03b1] [no_top_order \u03b1] :\n    has_basis at_top (fun (_x : \u03b1) => True) set.Ioi :=\n  sorry\n\ntheorem at_top_countable_basis {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_sup \u03b1] [encodable \u03b1] :\n    has_countable_basis at_top (fun (_x : \u03b1) => True) set.Ici :=\n  has_countable_basis.mk (has_basis.mk (has_basis.mem_iff' at_top_basis))\n    (set.countable_encodable (set_of fun (_x : \u03b1) => True))\n\ntheorem at_bot_countable_basis {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_inf \u03b1] [encodable \u03b1] :\n    has_countable_basis at_bot (fun (_x : \u03b1) => True) set.Iic :=\n  has_countable_basis.mk (has_basis.mk (has_basis.mem_iff' at_bot_basis))\n    (set.countable_encodable (set_of fun (_x : \u03b1) => True))\n\ntheorem is_countably_generated_at_top {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_sup \u03b1]\n    [encodable \u03b1] : is_countably_generated at_top :=\n  has_countable_basis.is_countably_generated at_top_countable_basis\n\ntheorem is_countably_generated_at_bot {\u03b1 : Type u_3} [Nonempty \u03b1] [semilattice_inf \u03b1]\n    [encodable \u03b1] : is_countably_generated at_bot :=\n  has_countable_basis.is_countably_generated at_bot_countable_basis\n\ntheorem order_top.at_top_eq (\u03b1 : Type u_1) [order_top \u03b1] : at_top = pure \u22a4 :=\n  le_antisymm\n    (iff.mpr le_pure_iff (eventually.mono (eventually_ge_at_top \u22a4) fun (b : \u03b1) => top_unique))\n    (le_infi fun (b : \u03b1) => iff.mpr le_principal_iff le_top)\n\ntheorem order_bot.at_bot_eq (\u03b1 : Type u_1) [order_bot \u03b1] : at_bot = pure \u22a5 :=\n  order_top.at_top_eq (order_dual \u03b1)\n\ntheorem subsingleton.at_top_eq (\u03b1 : Type u_1) [subsingleton \u03b1] [preorder \u03b1] : at_top = \u22a4 := sorry\n\ntheorem subsingleton.at_bot_eq (\u03b1 : Type u_1) [subsingleton \u03b1] [preorder \u03b1] : at_bot = \u22a4 :=\n  subsingleton.at_top_eq (order_dual \u03b1)\n\ntheorem tendsto_at_top_pure {\u03b1 : Type u_3} {\u03b2 : Type u_4} [order_top \u03b1] (f : \u03b1 \u2192 \u03b2) :\n    tendsto f at_top (pure (f \u22a4)) :=\n  Eq.symm (order_top.at_top_eq \u03b1) \u25b8 tendsto_pure_pure f \u22a4\n\ntheorem tendsto_at_bot_pure {\u03b1 : Type u_3} {\u03b2 : Type u_4} [order_bot \u03b1] (f : \u03b1 \u2192 \u03b2) :\n    tendsto f at_bot (pure (f \u22a5)) :=\n  tendsto_at_top_pure f\n\ntheorem eventually.exists_forall_of_at_top {\u03b1 : Type u_3} [semilattice_sup \u03b1] [Nonempty \u03b1]\n    {p : \u03b1 \u2192 Prop} (h : filter.eventually (fun (x : \u03b1) => p x) at_top) :\n    \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2265 a \u2192 p b :=\n  iff.mp eventually_at_top h\n\ntheorem eventually.exists_forall_of_at_bot {\u03b1 : Type u_3} [semilattice_inf \u03b1] [Nonempty \u03b1]\n    {p : \u03b1 \u2192 Prop} (h : filter.eventually (fun (x : \u03b1) => p x) at_bot) :\n    \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2264 a \u2192 p b :=\n  iff.mp eventually_at_bot h\n\ntheorem frequently_at_top {\u03b1 : Type u_3} [semilattice_sup \u03b1] [Nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n    filter.frequently (fun (x : \u03b1) => p x) at_top \u2194 \u2200 (a : \u03b1), \u2203 (b : \u03b1), \u2203 (H : b \u2265 a), p b :=\n  sorry\n\ntheorem frequently_at_bot {\u03b1 : Type u_3} [semilattice_inf \u03b1] [Nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n    filter.frequently (fun (x : \u03b1) => p x) at_bot \u2194 \u2200 (a : \u03b1), \u2203 (b : \u03b1), \u2203 (H : b \u2264 a), p b :=\n  frequently_at_top\n\ntheorem frequently_at_top' {\u03b1 : Type u_3} [semilattice_sup \u03b1] [Nonempty \u03b1] [no_top_order \u03b1]\n    {p : \u03b1 \u2192 Prop} :\n    filter.frequently (fun (x : \u03b1) => p x) at_top \u2194 \u2200 (a : \u03b1), \u2203 (b : \u03b1), \u2203 (H : b > a), p b :=\n  sorry\n\ntheorem frequently_at_bot' {\u03b1 : Type u_3} [semilattice_inf \u03b1] [Nonempty \u03b1] [no_bot_order \u03b1]\n    {p : \u03b1 \u2192 Prop} :\n    filter.frequently (fun (x : \u03b1) => p x) at_bot \u2194 \u2200 (a : \u03b1), \u2203 (b : \u03b1), \u2203 (H : b < a), p b :=\n  frequently_at_top'\n\ntheorem frequently.forall_exists_of_at_top {\u03b1 : Type u_3} [semilattice_sup \u03b1] [Nonempty \u03b1]\n    {p : \u03b1 \u2192 Prop} (h : filter.frequently (fun (x : \u03b1) => p x) at_top) (a : \u03b1) :\n    \u2203 (b : \u03b1), \u2203 (H : b \u2265 a), p b :=\n  iff.mp frequently_at_top h\n\ntheorem frequently.forall_exists_of_at_bot {\u03b1 : Type u_3} [semilattice_inf \u03b1] [Nonempty \u03b1]\n    {p : \u03b1 \u2192 Prop} (h : filter.frequently (fun (x : \u03b1) => p x) at_bot) (a : \u03b1) :\n    \u2203 (b : \u03b1), \u2203 (H : b \u2264 a), p b :=\n  iff.mp frequently_at_bot h\n\ntheorem map_at_top_eq {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} :\n    map f at_top = infi fun (a : \u03b1) => principal (f '' set_of fun (a' : \u03b1) => a \u2264 a') :=\n  has_basis.eq_infi (has_basis.map f at_top_basis)\n\ntheorem map_at_bot_eq {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2} :\n    map f at_bot = infi fun (a : \u03b1) => principal (f '' set_of fun (a' : \u03b1) => a' \u2264 a) :=\n  map_at_top_eq\n\ntheorem tendsto_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n    tendsto m f at_top \u2194 \u2200 (b : \u03b2), filter.eventually (fun (a : \u03b1) => b \u2264 m a) f :=\n  sorry\n\ntheorem tendsto_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n    tendsto m f at_bot \u2194 \u2200 (b : \u03b2), filter.eventually (fun (a : \u03b1) => m a \u2264 b) f :=\n  tendsto_at_top\n\ntheorem tendsto_at_top_mono' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2] (l : filter \u03b1) {f\u2081 : \u03b1 \u2192 \u03b2}\n    {f\u2082 : \u03b1 \u2192 \u03b2} (h : eventually_le l f\u2081 f\u2082) : tendsto f\u2081 l at_top \u2192 tendsto f\u2082 l at_top :=\n  sorry\n\ntheorem tendsto_at_bot_mono' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2] (l : filter \u03b1) {f\u2081 : \u03b1 \u2192 \u03b2}\n    {f\u2082 : \u03b1 \u2192 \u03b2} (h : eventually_le l f\u2081 f\u2082) : tendsto f\u2082 l at_bot \u2192 tendsto f\u2081 l at_bot :=\n  tendsto_at_top_mono' l h\n\ntheorem tendsto_at_top_mono {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2}\n    {g : \u03b1 \u2192 \u03b2} (h : \u2200 (n : \u03b1), f n \u2264 g n) : tendsto f l at_top \u2192 tendsto g l at_top :=\n  tendsto_at_top_mono' l (eventually_of_forall h)\n\ntheorem tendsto_at_bot_mono {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2}\n    {g : \u03b1 \u2192 \u03b2} (h : \u2200 (n : \u03b1), f n \u2264 g n) : tendsto g l at_bot \u2192 tendsto f l at_bot :=\n  tendsto_at_top_mono h\n\n/-!\n### Sequences\n-/\n\ntheorem inf_map_at_top_ne_bot_iff {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] [Nonempty \u03b1]\n    {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n    ne_bot (F \u2293 map u at_top) \u2194\n        \u2200 (U : set \u03b2) (H : U \u2208 F) (N : \u03b1), \u2203 (n : \u03b1), \u2203 (H : n \u2265 N), u n \u2208 U :=\n  sorry\n\ntheorem inf_map_at_bot_ne_bot_iff {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_inf \u03b1] [Nonempty \u03b1]\n    {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n    ne_bot (F \u2293 map u at_bot) \u2194\n        \u2200 (U : set \u03b2) (H : U \u2208 F) (N : \u03b1), \u2203 (n : \u03b1), \u2203 (H : n \u2264 N), u n \u2208 U :=\n  inf_map_at_top_ne_bot_iff\n\ntheorem extraction_of_frequently_at_top' {P : \u2115 \u2192 Prop}\n    (h : \u2200 (N : \u2115), \u2203 (n : \u2115), \u2203 (H : n > N), P n) :\n    \u2203 (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 \u2200 (n : \u2115), P (\u03c6 n) :=\n  sorry\n\ntheorem extraction_of_frequently_at_top {P : \u2115 \u2192 Prop}\n    (h : filter.frequently (fun (n : \u2115) => P n) at_top) :\n    \u2203 (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 \u2200 (n : \u2115), P (\u03c6 n) :=\n  extraction_of_frequently_at_top'\n    (eq.mp\n      (Eq._oldrec (Eq.refl (filter.frequently (fun (n : \u2115) => P n) at_top))\n        (propext frequently_at_top'))\n      h)\n\ntheorem extraction_of_eventually_at_top {P : \u2115 \u2192 Prop}\n    (h : filter.eventually (fun (n : \u2115) => P n) at_top) :\n    \u2203 (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 \u2200 (n : \u2115), P (\u03c6 n) :=\n  extraction_of_frequently_at_top (eventually.frequently h)\n\ntheorem exists_le_of_tendsto_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] [preorder \u03b2]\n    {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) :\n    \u2203 (a' : \u03b1), \u2203 (H : a' \u2265 a), b \u2264 u a' :=\n  sorry\n\ntheorem exists_le_of_tendsto_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] [preorder \u03b2]\n    {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_bot) (a : \u03b1) (b : \u03b2) :\n    \u2203 (a' : \u03b1), \u2203 (H : a' \u2265 a), u a' \u2264 b :=\n  exists_le_of_tendsto_at_top h\n\ntheorem exists_lt_of_tendsto_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] [preorder \u03b2]\n    [no_top_order \u03b2] {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) :\n    \u2203 (a' : \u03b1), \u2203 (H : a' \u2265 a), b < u a' :=\n  sorry\n\ntheorem exists_lt_of_tendsto_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] [preorder \u03b2]\n    [no_bot_order \u03b2] {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_bot) (a : \u03b1) (b : \u03b2) :\n    \u2203 (a' : \u03b1), \u2203 (H : a' \u2265 a), u a' < b :=\n  exists_lt_of_tendsto_at_top h\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen after any point, it reaches a value strictly greater than all previous values.\n-/\ntheorem high_scores {\u03b2 : Type u_4} [linear_order \u03b2] [no_top_order \u03b2] {u : \u2115 \u2192 \u03b2}\n    (hu : tendsto u at_top at_top) (N : \u2115) :\n    \u2203 (n : \u2115), \u2203 (H : n \u2265 N), \u2200 (k : \u2115), k < n \u2192 u k < u n :=\n  sorry\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen after any point, it reaches a value strictly smaller than all previous values.\n-/\ntheorem low_scores {\u03b2 : Type u_4} [linear_order \u03b2] [no_bot_order \u03b2] {u : \u2115 \u2192 \u03b2}\n    (hu : tendsto u at_top at_bot) (N : \u2115) :\n    \u2203 (n : \u2115), \u2203 (H : n \u2265 N), \u2200 (k : \u2115), k < n \u2192 u n < u k :=\n  high_scores hu\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen it `frequently` reaches a value strictly greater than all previous values.\n-/\ntheorem frequently_high_scores {\u03b2 : Type u_4} [linear_order \u03b2] [no_top_order \u03b2] {u : \u2115 \u2192 \u03b2}\n    (hu : tendsto u at_top at_top) :\n    filter.frequently (fun (n : \u2115) => \u2200 (k : \u2115), k < n \u2192 u k < u n) at_top :=\n  sorry\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen it `frequently` reaches a value strictly smaller than all previous values.\n-/\ntheorem frequently_low_scores {\u03b2 : Type u_4} [linear_order \u03b2] [no_bot_order \u03b2] {u : \u2115 \u2192 \u03b2}\n    (hu : tendsto u at_top at_bot) :\n    filter.frequently (fun (n : \u2115) => \u2200 (k : \u2115), k < n \u2192 u n < u k) at_top :=\n  frequently_high_scores hu\n\ntheorem strict_mono_subseq_of_tendsto_at_top {\u03b2 : Type u_1} [linear_order \u03b2] [no_top_order \u03b2]\n    {u : \u2115 \u2192 \u03b2} (hu : tendsto u at_top at_top) :\n    \u2203 (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\n  sorry\n\ntheorem strict_mono_subseq_of_id_le {u : \u2115 \u2192 \u2115} (hu : \u2200 (n : \u2115), n \u2264 u n) :\n    \u2203 (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\n  strict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono hu tendsto_id)\n\ntheorem strict_mono_tendsto_at_top {\u03c6 : \u2115 \u2192 \u2115} (h : strict_mono \u03c6) : tendsto \u03c6 at_top at_top :=\n  tendsto_at_top_mono (strict_mono.id_le h) tendsto_id\n\ntheorem tendsto_at_top_add_nonneg_left' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : filter.eventually (fun (x : \u03b1) => 0 \u2264 f x) l)\n    (hg : tendsto g l at_top) : tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  tendsto_at_top_mono' l (eventually.mono hf fun (x : \u03b1) => le_add_of_nonneg_left) hg\n\ntheorem tendsto_at_bot_add_nonpos_left' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : filter.eventually (fun (x : \u03b1) => f x \u2264 0) l)\n    (hg : tendsto g l at_bot) : tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_nonneg_left' hf hg\n\ntheorem tendsto_at_top_add_nonneg_left {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : \u2200 (x : \u03b1), 0 \u2264 f x) (hg : tendsto g l at_top) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  tendsto_at_top_add_nonneg_left' (eventually_of_forall hf) hg\n\ntheorem tendsto_at_bot_add_nonpos_left {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : \u2200 (x : \u03b1), f x \u2264 0) (hg : tendsto g l at_bot) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_nonneg_left hf hg\n\ntheorem tendsto_at_top_add_nonneg_right' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_top)\n    (hg : filter.eventually (fun (x : \u03b1) => 0 \u2264 g x) l) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  tendsto_at_top_mono' l (monotone_mem_sets (fun (x : \u03b1) => le_add_of_nonneg_right) hg) hf\n\ntheorem tendsto_at_bot_add_nonpos_right' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_bot)\n    (hg : filter.eventually (fun (x : \u03b1) => g x \u2264 0) l) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_nonneg_right' hf hg\n\ntheorem tendsto_at_top_add_nonneg_right {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_top) (hg : \u2200 (x : \u03b1), 0 \u2264 g x) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  tendsto_at_top_add_nonneg_right' hf (eventually_of_forall hg)\n\ntheorem tendsto_at_bot_add_nonpos_right {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_bot) (hg : \u2200 (x : \u03b1), g x \u2264 0) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_nonneg_right hf hg\n\ntheorem tendsto_at_top_add {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2] {l : filter \u03b1}\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  tendsto_at_top_add_nonneg_left' (iff.mp tendsto_at_top hf 0) hg\n\ntheorem tendsto_at_bot_add {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2] {l : filter \u03b1}\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add hf hg\n\ntheorem tendsto.nsmul_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_top) {n : \u2115} (hn : 0 < n) :\n    tendsto (fun (x : \u03b1) => n \u2022\u2115 f x) l at_top :=\n  sorry\n\ntheorem tendsto.nsmul_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2]\n    {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : tendsto f l at_bot) {n : \u2115} (hn : 0 < n) :\n    tendsto (fun (x : \u03b1) => n \u2022\u2115 f x) l at_bot :=\n  tendsto.nsmul_at_top hf hn\n\ntheorem tendsto_bit0_at_top {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2] :\n    tendsto bit0 at_top at_top :=\n  tendsto_at_top_add tendsto_id tendsto_id\n\ntheorem tendsto_bit0_at_bot {\u03b2 : Type u_4} [ordered_add_comm_monoid \u03b2] :\n    tendsto bit0 at_bot at_bot :=\n  tendsto_at_bot_add tendsto_id tendsto_id\n\ntheorem tendsto_at_top_of_add_const_left {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hf : tendsto (fun (x : \u03b1) => C + f x) l at_top) : tendsto f l at_top :=\n  iff.mpr tendsto_at_top\n    fun (b : \u03b2) =>\n      eventually.mono (iff.mp tendsto_at_top hf (C + b)) fun (x : \u03b1) => le_of_add_le_add_left\n\ntheorem tendsto_at_bot_of_add_const_left {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hf : tendsto (fun (x : \u03b1) => C + f x) l at_bot) : tendsto f l at_bot :=\n  tendsto_at_top_of_add_const_left C hf\n\ntheorem tendsto_at_top_of_add_const_right {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hf : tendsto (fun (x : \u03b1) => f x + C) l at_top) : tendsto f l at_top :=\n  iff.mpr tendsto_at_top\n    fun (b : \u03b2) =>\n      eventually.mono (iff.mp tendsto_at_top hf (b + C)) fun (x : \u03b1) => le_of_add_le_add_right\n\ntheorem tendsto_at_bot_of_add_const_right {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hf : tendsto (fun (x : \u03b1) => f x + C) l at_bot) : tendsto f l at_bot :=\n  tendsto_at_top_of_add_const_right C hf\n\ntheorem tendsto_at_top_of_add_bdd_above_left' {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : filter.eventually (fun (x : \u03b1) => f x \u2264 C) l)\n    (h : tendsto (fun (x : \u03b1) => f x + g x) l at_top) : tendsto g l at_top :=\n  tendsto_at_top_of_add_const_left C\n    (tendsto_at_top_mono' l\n      (eventually.mono hC fun (x : \u03b1) (hx : f x \u2264 C) => add_le_add_right hx (g x)) h)\n\ntheorem tendsto_at_bot_of_add_bdd_below_left' {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : filter.eventually (fun (x : \u03b1) => C \u2264 f x) l)\n    (h : tendsto (fun (x : \u03b1) => f x + g x) l at_bot) : tendsto g l at_bot :=\n  tendsto_at_top_of_add_bdd_above_left' C hC h\n\ntheorem tendsto_at_top_of_add_bdd_above_left {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : \u2200 (x : \u03b1), f x \u2264 C) : tendsto (fun (x : \u03b1) => f x + g x) l at_top \u2192 tendsto g l at_top :=\n  tendsto_at_top_of_add_bdd_above_left' C (univ_mem_sets' hC)\n\ntheorem tendsto_at_bot_of_add_bdd_below_left {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : \u2200 (x : \u03b1), C \u2264 f x) : tendsto (fun (x : \u03b1) => f x + g x) l at_bot \u2192 tendsto g l at_bot :=\n  tendsto_at_top_of_add_bdd_above_left C hC\n\ntheorem tendsto_at_top_of_add_bdd_above_right' {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : filter.eventually (fun (x : \u03b1) => g x \u2264 C) l)\n    (h : tendsto (fun (x : \u03b1) => f x + g x) l at_top) : tendsto f l at_top :=\n  tendsto_at_top_of_add_const_right C\n    (tendsto_at_top_mono' l\n      (eventually.mono hC fun (x : \u03b1) (hx : g x \u2264 C) => add_le_add_left hx (f x)) h)\n\ntheorem tendsto_at_bot_of_add_bdd_below_right' {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : filter.eventually (fun (x : \u03b1) => C \u2264 g x) l)\n    (h : tendsto (fun (x : \u03b1) => f x + g x) l at_bot) : tendsto f l at_bot :=\n  tendsto_at_top_of_add_bdd_above_right' C hC h\n\ntheorem tendsto_at_top_of_add_bdd_above_right {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : \u2200 (x : \u03b1), g x \u2264 C) : tendsto (fun (x : \u03b1) => f x + g x) l at_top \u2192 tendsto f l at_top :=\n  tendsto_at_top_of_add_bdd_above_right' C (univ_mem_sets' hC)\n\ntheorem tendsto_at_bot_of_add_bdd_below_right {\u03b1 : Type u_3} {\u03b2 : Type u_4}\n    [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hC : \u2200 (x : \u03b1), C \u2264 g x) : tendsto (fun (x : \u03b1) => f x + g x) l at_bot \u2192 tendsto f l at_bot :=\n  tendsto_at_top_of_add_bdd_above_right C hC\n\ntheorem tendsto_at_top_add_left_of_le' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hf : filter.eventually (fun (x : \u03b1) => C \u2264 f x) l) (hg : tendsto g l at_top) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  sorry\n\ntheorem tendsto_at_bot_add_left_of_ge' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2)\n    (hf : filter.eventually (fun (x : \u03b1) => f x \u2264 C) l) (hg : tendsto g l at_bot) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_left_of_le' l C hf hg\n\ntheorem tendsto_at_top_add_left_of_le {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : \u2200 (x : \u03b1), C \u2264 f x)\n    (hg : tendsto g l at_top) : tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  tendsto_at_top_add_left_of_le' l C (univ_mem_sets' hf) hg\n\ntheorem tendsto_at_bot_add_left_of_ge {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : \u2200 (x : \u03b1), f x \u2264 C)\n    (hg : tendsto g l at_bot) : tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_left_of_le l C hf hg\n\ntheorem tendsto_at_top_add_right_of_le' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_top)\n    (hg : filter.eventually (fun (x : \u03b1) => C \u2264 g x) l) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  sorry\n\ntheorem tendsto_at_bot_add_right_of_ge' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_bot)\n    (hg : filter.eventually (fun (x : \u03b1) => g x \u2264 C) l) :\n    tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_right_of_le' l C hf hg\n\ntheorem tendsto_at_top_add_right_of_le {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_top)\n    (hg : \u2200 (x : \u03b1), C \u2264 g x) : tendsto (fun (x : \u03b1) => f x + g x) l at_top :=\n  tendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' hg)\n\ntheorem tendsto_at_bot_add_right_of_ge {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_bot)\n    (hg : \u2200 (x : \u03b1), g x \u2264 C) : tendsto (fun (x : \u03b1) => f x + g x) l at_bot :=\n  tendsto_at_top_add_right_of_le l C hf hg\n\ntheorem tendsto_at_top_add_const_left {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_top) :\n    tendsto (fun (x : \u03b1) => C + f x) l at_top :=\n  tendsto_at_top_add_left_of_le' l C (univ_mem_sets' fun (_x : \u03b1) => le_refl C) hf\n\ntheorem tendsto_at_bot_add_const_left {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_bot) :\n    tendsto (fun (x : \u03b1) => C + f x) l at_bot :=\n  tendsto_at_top_add_const_left l C hf\n\ntheorem tendsto_at_top_add_const_right {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_top) :\n    tendsto (fun (x : \u03b1) => f x + C) l at_top :=\n  tendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' fun (_x : \u03b1) => le_refl C)\n\ntheorem tendsto_at_bot_add_const_right {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2]\n    (l : filter \u03b1) {f : \u03b1 \u2192 \u03b2} (C : \u03b2) (hf : tendsto f l at_bot) :\n    tendsto (fun (x : \u03b1) => f x + C) l at_bot :=\n  tendsto_at_top_add_const_right l C hf\n\ntheorem tendsto_neg_at_top_at_bot {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2] :\n    tendsto Neg.neg at_top at_bot :=\n  sorry\n\ntheorem tendsto_neg_at_bot_at_top {\u03b2 : Type u_4} [ordered_add_comm_group \u03b2] :\n    tendsto Neg.neg at_bot at_top :=\n  tendsto_neg_at_top_at_bot\n\ntheorem tendsto_bit1_at_top {\u03b1 : Type u_3} [ordered_semiring \u03b1] : tendsto bit1 at_top at_top :=\n  tendsto_at_top_add_nonneg_right tendsto_bit0_at_top fun (_x : \u03b1) => zero_le_one\n\ntheorem tendsto.at_top_mul_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_semiring \u03b1] {l : filter \u03b2}\n    {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n    tendsto (fun (x : \u03b2) => f x * g x) l at_top :=\n  sorry\n\ntheorem tendsto_mul_self_at_top {\u03b1 : Type u_3} [ordered_semiring \u03b1] :\n    tendsto (fun (x : \u03b1) => x * x) at_top at_top :=\n  tendsto.at_top_mul_at_top tendsto_id tendsto_id\n\n/-- The monomial function `x^n` tends to `+\u221e` at `+\u221e` for any positive natural `n`.\nA version for positive real powers exists as `tendsto_rpow_at_top`. -/\ntheorem tendsto_pow_at_top {\u03b1 : Type u_3} [ordered_semiring \u03b1] {n : \u2115} (hn : 1 \u2264 n) :\n    tendsto (fun (x : \u03b1) => x ^ n) at_top at_top :=\n  sorry\n\ntheorem zero_pow_eventually_eq {\u03b1 : Type u_3} [monoid_with_zero \u03b1] :\n    eventually_eq at_top (fun (n : \u2115) => 0 ^ n) fun (n : \u2115) => 0 :=\n  iff.mpr eventually_at_top\n    (Exists.intro 1 fun (n : \u2115) (hn : n \u2265 1) => zero_pow (has_lt.lt.trans_le zero_lt_one hn))\n\ntheorem tendsto.at_top_mul_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_ring \u03b1] {l : filter \u03b2}\n    {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : tendsto f l at_top) (hg : tendsto g l at_bot) :\n    tendsto (fun (x : \u03b2) => f x * g x) l at_bot :=\n  sorry\n\ntheorem tendsto.at_bot_mul_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_ring \u03b1] {l : filter \u03b2}\n    {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : tendsto f l at_bot) (hg : tendsto g l at_top) :\n    tendsto (fun (x : \u03b2) => f x * g x) l at_bot :=\n  sorry\n\ntheorem tendsto.at_bot_mul_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [ordered_ring \u03b1] {l : filter \u03b2}\n    {f : \u03b2 \u2192 \u03b1} {g : \u03b2 \u2192 \u03b1} (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n    tendsto (fun (x : \u03b2) => f x * g x) l at_top :=\n  sorry\n\n/-- $\\lim_{x\\to+\\infty}|x|=+\\infty$ -/\ntheorem tendsto_abs_at_top_at_top {\u03b1 : Type u_3} [linear_ordered_add_comm_group \u03b1] :\n    tendsto abs at_top at_top :=\n  tendsto_at_top_mono le_abs_self tendsto_id\n\n/-- $\\lim_{x\\to-\\infty}|x|=+\\infty$ -/\ntheorem tendsto_abs_at_bot_at_top {\u03b1 : Type u_3} [linear_ordered_add_comm_group \u03b1] :\n    tendsto abs at_bot at_top :=\n  tendsto_at_top_mono neg_le_abs_self tendsto_neg_at_bot_at_top\n\ntheorem tendsto.at_top_of_const_mul {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_semiring \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {c : \u03b1} (hc : 0 < c)\n    (hf : tendsto (fun (x : \u03b2) => c * f x) l at_top) : tendsto f l at_top :=\n  iff.mpr tendsto_at_top\n    fun (b : \u03b1) =>\n      eventually.mono (iff.mp tendsto_at_top hf (c * b))\n        fun (x : \u03b2) (hx : c * b \u2264 c * f x) => le_of_mul_le_mul_left hx hc\n\ntheorem tendsto.at_top_of_mul_const {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_semiring \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {c : \u03b1} (hc : 0 < c)\n    (hf : tendsto (fun (x : \u03b2) => f x * c) l at_top) : tendsto f l at_top :=\n  sorry\n\ntheorem nonneg_of_eventually_pow_nonneg {\u03b1 : Type u_3} [linear_ordered_ring \u03b1] {a : \u03b1}\n    (h : filter.eventually (fun (n : \u2115) => 0 \u2264 a ^ n) at_top) : 0 \u2264 a :=\n  (fun (_a : \u2203 (x : \u2115), (fun (x : \u2115) => 0 \u2264 a ^ bit1 x) x) =>\n      Exists.dcases_on _a\n        fun (w : \u2115) (h_1 : 0 \u2264 a ^ bit1 w) => idRhs (0 \u2264 a) (iff.mp pow_bit1_nonneg_iff h_1))\n    (eventually.exists (tendsto.eventually tendsto_bit1_at_top h))\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the left) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.const_mul_at_top'` instead. -/\ntheorem tendsto.const_mul_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : 0 < r) (hf : tendsto f l at_top) :\n    tendsto (fun (x : \u03b2) => r * f x) l at_top :=\n  sorry\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the right) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.at_top_mul_const'` instead. -/\ntheorem tendsto.at_top_mul_const {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : 0 < r) (hf : tendsto f l at_top) :\n    tendsto (fun (x : \u03b2) => f x * r) l at_top :=\n  sorry\n\n/-- If a function tends to infinity along a filter, then this function divided by a positive\nconstant also tends to infinity. -/\ntheorem tendsto.at_top_div_const {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : 0 < r) (hf : tendsto f l at_top) :\n    tendsto (fun (x : \u03b2) => f x / r) l at_top :=\n  tendsto.at_top_mul_const (iff.mpr inv_pos hr) hf\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the left) tends to negative infinity. -/\ntheorem tendsto.neg_const_mul_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : r < 0) (hf : tendsto f l at_top) :\n    tendsto (fun (x : \u03b2) => r * f x) l at_bot :=\n  sorry\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the right) tends to negative infinity. -/\ntheorem tendsto.at_top_mul_neg_const {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : r < 0) (hf : tendsto f l at_top) :\n    tendsto (fun (x : \u03b2) => f x * r) l at_bot :=\n  sorry\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the left) also tends to negative infinity. -/\ntheorem tendsto.const_mul_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : 0 < r) (hf : tendsto f l at_bot) :\n    tendsto (fun (x : \u03b2) => r * f x) l at_bot :=\n  sorry\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the right) also tends to negative infinity. -/\ntheorem tendsto.at_bot_mul_const {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : 0 < r) (hf : tendsto f l at_bot) :\n    tendsto (fun (x : \u03b2) => f x * r) l at_bot :=\n  sorry\n\n/-- If a function tends to negative infinity along a filter, then this function divided by\na positive constant also tends to negative infinity. -/\ntheorem tendsto.at_bot_div_const {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : 0 < r) (hf : tendsto f l at_bot) :\n    tendsto (fun (x : \u03b2) => f x / r) l at_bot :=\n  tendsto.at_bot_mul_const (iff.mpr inv_pos hr) hf\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the left) tends to positive infinity. -/\ntheorem tendsto.neg_const_mul_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : r < 0) (hf : tendsto f l at_bot) :\n    tendsto (fun (x : \u03b2) => r * f x) l at_top :=\n  sorry\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the right) tends to positive infinity. -/\ntheorem tendsto.at_bot_mul_neg_const {\u03b1 : Type u_3} {\u03b2 : Type u_4} [linear_ordered_field \u03b1]\n    {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1} (hr : r < 0) (hf : tendsto f l at_bot) :\n    tendsto (fun (x : \u03b2) => f x * r) l at_top :=\n  sorry\n\ntheorem tendsto_at_top' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2}\n    {l : filter \u03b2} :\n    tendsto f at_top l \u2194 \u2200 (s : set \u03b2), s \u2208 l \u2192 \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2265 a \u2192 f b \u2208 s :=\n  sorry\n\ntheorem tendsto_at_bot' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2}\n    {l : filter \u03b2} :\n    tendsto f at_bot l \u2194 \u2200 (s : set \u03b2), s \u2208 l \u2192 \u2203 (a : \u03b1), \u2200 (b : \u03b1), b \u2264 a \u2192 f b \u2208 s :=\n  tendsto_at_top'\n\ntheorem tendsto_at_top_principal {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b2] [semilattice_sup \u03b2]\n    {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n    tendsto f at_top (principal s) \u2194 \u2203 (N : \u03b2), \u2200 (n : \u03b2), n \u2265 N \u2192 f n \u2208 s :=\n  sorry\n\ntheorem tendsto_at_bot_principal {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b2] [semilattice_inf \u03b2]\n    {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n    tendsto f at_bot (principal s) \u2194 \u2203 (N : \u03b2), \u2200 (n : \u03b2), n \u2264 N \u2192 f n \u2208 s :=\n  tendsto_at_top_principal\n\n/-- A function `f` grows to `+\u221e` independent of an order-preserving embedding `e`. -/\ntheorem tendsto_at_top_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_sup \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n    tendsto f at_top at_top \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), i \u2264 a \u2192 b \u2264 f a :=\n  iff.trans tendsto_infi (forall_congr fun (b : \u03b2) => tendsto_at_top_principal)\n\ntheorem tendsto_at_top_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_sup \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n    tendsto f at_top at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), i \u2264 a \u2192 f a \u2264 b :=\n  tendsto_at_top_at_top\n\ntheorem tendsto_at_bot_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_inf \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n    tendsto f at_bot at_top \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 b \u2264 f a :=\n  tendsto_at_top_at_top\n\ntheorem tendsto_at_bot_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_inf \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n    tendsto f at_bot at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 f a \u2264 b :=\n  tendsto_at_top_at_top\n\ntheorem tendsto_at_top_at_top_of_monotone {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} (hf : monotone f) (h : \u2200 (b : \u03b2), \u2203 (a : \u03b1), b \u2264 f a) : tendsto f at_top at_top :=\n  sorry\n\ntheorem tendsto_at_bot_at_bot_of_monotone {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} (hf : monotone f) (h : \u2200 (b : \u03b2), \u2203 (a : \u03b1), f a \u2264 b) : tendsto f at_bot at_bot :=\n  sorry\n\ntheorem tendsto_at_top_at_top_iff_of_monotone {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1]\n    [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n    tendsto f at_top at_top \u2194 \u2200 (b : \u03b2), \u2203 (a : \u03b1), b \u2264 f a :=\n  sorry\n\ntheorem tendsto_at_bot_at_bot_iff_of_monotone {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1]\n    [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n    tendsto f at_bot at_bot \u2194 \u2200 (b : \u03b2), \u2203 (a : \u03b1), f a \u2264 b :=\n  sorry\n\ntheorem Mathlib.monotone.tendsto_at_top_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f) (h : \u2200 (b : \u03b2), \u2203 (a : \u03b1), b \u2264 f a) :\n    tendsto f at_top at_top :=\n  tendsto_at_top_at_top_of_monotone\n\ntheorem Mathlib.monotone.tendsto_at_bot_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f) (h : \u2200 (b : \u03b2), \u2203 (a : \u03b1), f a \u2264 b) :\n    tendsto f at_bot at_bot :=\n  tendsto_at_bot_at_bot_of_monotone\n\ntheorem Mathlib.monotone.tendsto_at_top_at_top_iff {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1]\n    [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n    tendsto f at_top at_top \u2194 \u2200 (b : \u03b2), \u2203 (a : \u03b1), b \u2264 f a :=\n  tendsto_at_top_at_top_iff_of_monotone\n\ntheorem Mathlib.monotone.tendsto_at_bot_at_bot_iff {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1]\n    [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n    tendsto f at_bot at_bot \u2194 \u2200 (b : \u03b2), \u2203 (a : \u03b1), f a \u2264 b :=\n  tendsto_at_bot_at_bot_iff_of_monotone\n\ntheorem tendsto_at_top_embedding {\u03b1 : Type u_3} {\u03b2 : Type u_4} {\u03b3 : Type u_5} [preorder \u03b2]\n    [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1} (hm : \u2200 (b\u2081 b\u2082 : \u03b2), e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082)\n    (hu : \u2200 (c : \u03b3), \u2203 (b : \u03b2), c \u2264 e b) : tendsto (e \u2218 f) l at_top \u2194 tendsto f l at_top :=\n  sorry\n\n/-- A function `f` goes to `-\u221e` independent of an order-preserving embedding `e`. -/\ntheorem tendsto_at_bot_embedding {\u03b1 : Type u_3} {\u03b2 : Type u_4} {\u03b3 : Type u_5} [preorder \u03b2]\n    [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1} (hm : \u2200 (b\u2081 b\u2082 : \u03b2), e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082)\n    (hu : \u2200 (c : \u03b3), \u2203 (b : \u03b2), e b \u2264 c) : tendsto (e \u2218 f) l at_bot \u2194 tendsto f l at_bot :=\n  tendsto_at_top_embedding (function.swap hm) hu\n\ntheorem tendsto_finset_range : tendsto finset.range at_top at_top :=\n  monotone.tendsto_at_top_at_top finset.range_mono finset.exists_nat_subset_range\n\ntheorem at_top_finset_eq_infi {\u03b1 : Type u_3} :\n    at_top = infi fun (x : \u03b1) => principal (set.Ici (singleton x)) :=\n  sorry\n\n/-- If `f` is a monotone sequence of `finset`s and each `x` belongs to one of `f n`, then\n`tendsto f at_top at_top`. -/\ntheorem tendsto_at_top_finset_of_monotone {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2]\n    {f : \u03b2 \u2192 finset \u03b1} (h : monotone f) (h' : \u2200 (x : \u03b1), \u2203 (n : \u03b2), x \u2208 f n) :\n    tendsto f at_top at_top :=\n  sorry\n\ntheorem Mathlib.monotone.tendsto_at_top_finset {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b2]\n    {f : \u03b2 \u2192 finset \u03b1} (h : monotone f) (h' : \u2200 (x : \u03b1), \u2203 (n : \u03b2), x \u2208 f n) :\n    tendsto f at_top at_top :=\n  tendsto_at_top_finset_of_monotone\n\ntheorem tendsto_finset_image_at_top_at_top {\u03b2 : Type u_4} {\u03b3 : Type u_5} {i : \u03b2 \u2192 \u03b3} {j : \u03b3 \u2192 \u03b2}\n    (h : function.left_inverse j i) : tendsto (finset.image j) at_top at_top :=\n  sorry\n\ntheorem tendsto_finset_preimage_at_top_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} {f : \u03b1 \u2192 \u03b2}\n    (hf : function.injective f) :\n    tendsto (fun (s : finset \u03b2) => finset.preimage s f (function.injective.inj_on hf (f \u207b\u00b9' \u2191s)))\n        at_top at_top :=\n  monotone.tendsto_at_top_finset (finset.monotone_preimage hf)\n    fun (x : \u03b1) =>\n      Exists.intro (singleton (f x)) (iff.mpr finset.mem_preimage (finset.mem_singleton_self (f x)))\n\ntheorem prod_at_top_at_top_eq {\u03b2\u2081 : Type u_1} {\u03b2\u2082 : Type u_2} [semilattice_sup \u03b2\u2081]\n    [semilattice_sup \u03b2\u2082] : filter.prod at_top at_top = at_top :=\n  sorry\n\ntheorem prod_at_bot_at_bot_eq {\u03b2\u2081 : Type u_1} {\u03b2\u2082 : Type u_2} [semilattice_inf \u03b2\u2081]\n    [semilattice_inf \u03b2\u2082] : filter.prod at_bot at_bot = at_bot :=\n  prod_at_top_at_top_eq\n\ntheorem prod_map_at_top_eq {\u03b1\u2081 : Type u_1} {\u03b1\u2082 : Type u_2} {\u03b2\u2081 : Type u_3} {\u03b2\u2082 : Type u_4}\n    [semilattice_sup \u03b2\u2081] [semilattice_sup \u03b2\u2082] (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n    filter.prod (map u\u2081 at_top) (map u\u2082 at_top) = map (prod.map u\u2081 u\u2082) at_top :=\n  sorry\n\ntheorem prod_map_at_bot_eq {\u03b1\u2081 : Type u_1} {\u03b1\u2082 : Type u_2} {\u03b2\u2081 : Type u_3} {\u03b2\u2082 : Type u_4}\n    [semilattice_inf \u03b2\u2081] [semilattice_inf \u03b2\u2082] (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n    filter.prod (map u\u2081 at_bot) (map u\u2082 at_bot) = map (prod.map u\u2081 u\u2082) at_bot :=\n  prod_map_at_top_eq u\u2081 u\u2082\n\n/-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a\nGalois insertion. The Galois \"insertion\" and \"connection\" is weakened to only require it to be an\ninsertion and a connetion above `b'`. -/\ntheorem map_at_top_eq_of_gc {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] [semilattice_sup \u03b2]\n    {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2) (hf : monotone f)\n    (gc : \u2200 (a : \u03b1) (b : \u03b2), b \u2265 b' \u2192 (f a \u2264 b \u2194 a \u2264 g b)) (hgi : \u2200 (b : \u03b2), b \u2265 b' \u2192 b \u2264 f (g b)) :\n    map f at_top = at_top :=\n  sorry\n\ntheorem map_at_bot_eq_of_gc {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_inf \u03b1] [semilattice_inf \u03b2]\n    {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2) (hf : monotone f)\n    (gc : \u2200 (a : \u03b1) (b : \u03b2), b \u2264 b' \u2192 (b \u2264 f a \u2194 g b \u2264 a)) (hgi : \u2200 (b : \u03b2), b \u2264 b' \u2192 f (g b) \u2264 b) :\n    map f at_bot = at_bot :=\n  map_at_top_eq_of_gc (fun (b : \u03b2) => g b) b' (monotone.order_dual hf) gc hgi\n\ntheorem map_coe_at_top_of_Ici_subset {\u03b1 : Type u_3} [semilattice_sup \u03b1] {a : \u03b1} {s : set \u03b1}\n    (h : set.Ici a \u2286 s) : map coe at_top = at_top :=\n  sorry\n\n/-- The image of the filter `at_top` on `Ici a` under the coercion equals `at_top`. -/\n@[simp] theorem map_coe_Ici_at_top {\u03b1 : Type u_3} [semilattice_sup \u03b1] (a : \u03b1) :\n    map coe at_top = at_top :=\n  map_coe_at_top_of_Ici_subset (set.subset.refl (set.Ici a))\n\n/-- The image of the filter `at_top` on `Ioi a` under the coercion equals `at_top`. -/\n@[simp] theorem map_coe_Ioi_at_top {\u03b1 : Type u_3} [semilattice_sup \u03b1] [no_top_order \u03b1] (a : \u03b1) :\n    map coe at_top = at_top :=\n  Exists.dcases_on (no_top a)\n    fun (b : \u03b1) (hb : a < b) => map_coe_at_top_of_Ici_subset (iff.mpr set.Ici_subset_Ioi hb)\n\n/-- The `at_top` filter for an open interval `Ioi a` comes from the `at_top` filter in the ambient\norder. -/\ntheorem at_top_Ioi_eq {\u03b1 : Type u_3} [semilattice_sup \u03b1] (a : \u03b1) : at_top = comap coe at_top :=\n  sorry\n\n/-- The `at_top` filter for an open interval `Ici a` comes from the `at_top` filter in the ambient\norder. -/\ntheorem at_top_Ici_eq {\u03b1 : Type u_3} [semilattice_sup \u03b1] (a : \u03b1) : at_top = comap coe at_top :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (at_top = comap coe at_top)) (Eq.symm (map_coe_Ici_at_top a))))\n    (eq.mpr\n      (id\n        (Eq._oldrec (Eq.refl (at_top = comap coe (map coe at_top)))\n          (comap_map subtype.coe_injective)))\n      (Eq.refl at_top))\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] theorem map_coe_Iio_at_bot {\u03b1 : Type u_3} [semilattice_inf \u03b1] [no_bot_order \u03b1] (a : \u03b1) :\n    map coe at_bot = at_bot :=\n  map_coe_Ioi_at_top a\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\ntheorem at_bot_Iio_eq {\u03b1 : Type u_3} [semilattice_inf \u03b1] (a : \u03b1) : at_bot = comap coe at_bot :=\n  at_top_Ioi_eq a\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] theorem map_coe_Iic_at_bot {\u03b1 : Type u_3} [semilattice_inf \u03b1] (a : \u03b1) :\n    map coe at_bot = at_bot :=\n  map_coe_Ici_at_top a\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\ntheorem at_bot_Iic_eq {\u03b1 : Type u_3} [semilattice_inf \u03b1] (a : \u03b1) : at_bot = comap coe at_bot :=\n  at_top_Ici_eq a\n\ntheorem tendsto_Ioi_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] {a : \u03b1}\n    {f : \u03b2 \u2192 \u21a5(set.Ioi a)} {l : filter \u03b2} :\n    tendsto f l at_top \u2194 tendsto (fun (x : \u03b2) => \u2191(f x)) l at_top :=\n  sorry\n\ntheorem tendsto_Iio_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_inf \u03b1] {a : \u03b1}\n    {f : \u03b2 \u2192 \u21a5(set.Iio a)} {l : filter \u03b2} :\n    tendsto f l at_bot \u2194 tendsto (fun (x : \u03b2) => \u2191(f x)) l at_bot :=\n  sorry\n\ntheorem tendsto_Ici_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1] {a : \u03b1}\n    {f : \u03b2 \u2192 \u21a5(set.Ici a)} {l : filter \u03b2} :\n    tendsto f l at_top \u2194 tendsto (fun (x : \u03b2) => \u2191(f x)) l at_top :=\n  sorry\n\ntheorem tendsto_Iic_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_inf \u03b1] {a : \u03b1}\n    {f : \u03b2 \u2192 \u21a5(set.Iic a)} {l : filter \u03b2} :\n    tendsto f l at_bot \u2194 tendsto (fun (x : \u03b2) => \u2191(f x)) l at_bot :=\n  sorry\n\n@[simp] theorem tendsto_comp_coe_Ioi_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1]\n    [no_top_order \u03b1] {a : \u03b1} {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n    tendsto (fun (x : \u21a5(set.Ioi a)) => f \u2191x) at_top l \u2194 tendsto f at_top l :=\n  sorry\n\n@[simp] theorem tendsto_comp_coe_Ici_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_sup \u03b1]\n    {a : \u03b1} {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n    tendsto (fun (x : \u21a5(set.Ici a)) => f \u2191x) at_top l \u2194 tendsto f at_top l :=\n  sorry\n\n@[simp] theorem tendsto_comp_coe_Iio_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_inf \u03b1]\n    [no_bot_order \u03b1] {a : \u03b1} {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n    tendsto (fun (x : \u21a5(set.Iio a)) => f \u2191x) at_bot l \u2194 tendsto f at_bot l :=\n  sorry\n\n@[simp] theorem tendsto_comp_coe_Iic_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [semilattice_inf \u03b1]\n    {a : \u03b1} {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n    tendsto (fun (x : \u21a5(set.Iic a)) => f \u2191x) at_bot l \u2194 tendsto f at_bot l :=\n  sorry\n\ntheorem map_add_at_top_eq_nat (k : \u2115) : map (fun (a : \u2115) => a + k) at_top = at_top :=\n  map_at_top_eq_of_gc (fun (a : \u2115) => a - k) k (fun (a b : \u2115) (h : a \u2264 b) => add_le_add_right h k)\n    (fun (a b : \u2115) (h : b \u2265 k) => iff.symm (nat.le_sub_right_iff_add_le h))\n    fun (a : \u2115) (h : a \u2265 k) =>\n      eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 a - k + k)) (nat.sub_add_cancel h))) (le_refl a)\n\ntheorem map_sub_at_top_eq_nat (k : \u2115) : map (fun (a : \u2115) => a - k) at_top = at_top :=\n  map_at_top_eq_of_gc (fun (a : \u2115) => a + k) 0\n    (fun (a b : \u2115) (h : a \u2264 b) => nat.sub_le_sub_right h k)\n    (fun (a b : \u2115) (_x : b \u2265 0) => nat.sub_le_right_iff_le_add)\n    fun (b : \u2115) (_x : b \u2265 0) =>\n      eq.mpr (id (Eq._oldrec (Eq.refl (b \u2264 b + k - k)) (nat.add_sub_cancel b k))) (le_refl b)\n\ntheorem tendsto_add_at_top_nat (k : \u2115) : tendsto (fun (a : \u2115) => a + k) at_top at_top :=\n  le_of_eq (map_add_at_top_eq_nat k)\n\ntheorem tendsto_sub_at_top_nat (k : \u2115) : tendsto (fun (a : \u2115) => a - k) at_top at_top :=\n  le_of_eq (map_sub_at_top_eq_nat k)\n\ntheorem tendsto_add_at_top_iff_nat {\u03b1 : Type u_3} {f : \u2115 \u2192 \u03b1} {l : filter \u03b1} (k : \u2115) :\n    tendsto (fun (n : \u2115) => f (n + k)) at_top l \u2194 tendsto f at_top l :=\n  sorry\n\ntheorem map_div_at_top_eq_nat (k : \u2115) (hk : 0 < k) : map (fun (a : \u2115) => a / k) at_top = at_top :=\n  sorry\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nabove, then `tendsto u at_top at_top`. -/\ntheorem tendsto_at_top_at_top_of_monotone' {\u03b9 : Type u_1} {\u03b1 : Type u_3} [preorder \u03b9]\n    [linear_order \u03b1] {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_above (set.range u)) :\n    tendsto u at_top at_top :=\n  sorry\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nbelow, then `tendsto u at_bot at_bot`. -/\ntheorem tendsto_at_bot_at_bot_of_monotone' {\u03b9 : Type u_1} {\u03b1 : Type u_3} [preorder \u03b9]\n    [linear_order \u03b1] {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_below (set.range u)) :\n    tendsto u at_bot at_bot :=\n  tendsto_at_top_at_top_of_monotone' (monotone.order_dual h) H\n\ntheorem unbounded_of_tendsto_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_sup \u03b1]\n    [preorder \u03b2] [no_top_order \u03b2] {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_top) :\n    \u00acbdd_above (set.range f) :=\n  sorry\n\ntheorem unbounded_of_tendsto_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_sup \u03b1]\n    [preorder \u03b2] [no_bot_order \u03b2] {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_bot) :\n    \u00acbdd_below (set.range f) :=\n  unbounded_of_tendsto_at_top h\n\ntheorem unbounded_of_tendsto_at_top' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_inf \u03b1]\n    [preorder \u03b2] [no_top_order \u03b2] {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_top) :\n    \u00acbdd_above (set.range f) :=\n  unbounded_of_tendsto_at_top h\n\ntheorem unbounded_of_tendsto_at_bot' {\u03b1 : Type u_3} {\u03b2 : Type u_4} [Nonempty \u03b1] [semilattice_inf \u03b1]\n    [preorder \u03b2] [no_bot_order \u03b2] {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_bot) :\n    \u00acbdd_below (set.range f) :=\n  unbounded_of_tendsto_at_top h\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_top` along *some* non-trivial filter `l`, then\nit tends to `at_top` along `at_top`. -/\ntheorem tendsto_at_top_of_monotone_of_filter {\u03b9 : Type u_1} {\u03b1 : Type u_3} [preorder \u03b9] [preorder \u03b1]\n    {l : filter \u03b9} {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_top) :\n    tendsto u at_top at_top :=\n  monotone.tendsto_at_top_at_top h\n    fun (b : \u03b1) => eventually.exists (tendsto.eventually hu (mem_at_top b))\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_bot` along *some* non-trivial filter `l`, then\nit tends to `at_bot` along `at_bot`. -/\ntheorem tendsto_at_bot_of_monotone_of_filter {\u03b9 : Type u_1} {\u03b1 : Type u_3} [preorder \u03b9] [preorder \u03b1]\n    {l : filter \u03b9} {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_bot) :\n    tendsto u at_bot at_bot :=\n  tendsto_at_top_of_monotone_of_filter (monotone.order_dual h) hu\n\ntheorem tendsto_at_top_of_monotone_of_subseq {\u03b9 : Type u_1} {\u03b9' : Type u_2} {\u03b1 : Type u_3}\n    [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1} {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n    (H : tendsto (u \u2218 \u03c6) l at_top) : tendsto u at_top at_top :=\n  tendsto_at_top_of_monotone_of_filter h (tendsto_map' H)\n\ntheorem tendsto_at_bot_of_monotone_of_subseq {\u03b9 : Type u_1} {\u03b9' : Type u_2} {\u03b1 : Type u_3}\n    [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1} {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n    (H : tendsto (u \u2218 \u03c6) l at_bot) : tendsto u at_bot at_bot :=\n  tendsto_at_bot_of_monotone_of_filter h (tendsto_map' H)\n\n/-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient\ncondition for comparison of the filter `at_top.map (\u03bb s, \u220f b in s, f b)` with\n`at_top.map (\u03bb s, \u220f b in s, g b)`. This is useful to compare the set of limit points of\n`\u03a0 b in s, f b` as `s \u2192 at_top` with the similar set for `g`. -/\ntheorem map_at_top_finset_prod_le_of_prod_eq {\u03b1 : Type u_3} {\u03b2 : Type u_4} {\u03b3 : Type u_5}\n    [comm_monoid \u03b1] {f : \u03b2 \u2192 \u03b1} {g : \u03b3 \u2192 \u03b1}\n    (h_eq :\n      \u2200 (u : finset \u03b3),\n        \u2203 (v : finset \u03b2),\n          \u2200 (v' : finset \u03b2),\n            v \u2286 v' \u2192\n              \u2203 (u' : finset \u03b3),\n                u \u2286 u' \u2227 (finset.prod u' fun (x : \u03b3) => g x) = finset.prod v' fun (b : \u03b2) => f b) :\n    map (fun (s : finset \u03b2) => finset.prod s fun (b : \u03b2) => f b) at_top \u2264\n        map (fun (s : finset \u03b3) => finset.prod s fun (x : \u03b3) => g x) at_top :=\n  sorry\n\ntheorem has_antimono_basis.tendsto {\u03b9 : Type u_1} {\u03b1 : Type u_3} [semilattice_sup \u03b9] [Nonempty \u03b9]\n    {l : filter \u03b1} {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 set \u03b1} (hl : has_antimono_basis l p s) {\u03c6 : \u03b9 \u2192 \u03b1}\n    (h : \u2200 (i : \u03b9), \u03c6 i \u2208 s i) : tendsto \u03c6 at_top l :=\n  sorry\n\nnamespace is_countably_generated\n\n\n/-- An abstract version of continuity of sequentially continuous functions on metric spaces:\nif a filter `k` is countably generated then `tendsto f k l` iff for every sequence `u`\nconverging to `k`, `f \u2218 u` tends to `l`. -/\ntheorem tendsto_iff_seq_tendsto {\u03b1 : Type u_3} {\u03b2 : Type u_4} {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1}\n    {l : filter \u03b2} (hcb : is_countably_generated k) :\n    tendsto f k l \u2194 \u2200 (x : \u2115 \u2192 \u03b1), tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l :=\n  sorry\n\ntheorem tendsto_of_seq_tendsto {\u03b1 : Type u_3} {\u03b2 : Type u_4} {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1}\n    {l : filter \u03b2} (hcb : is_countably_generated k) :\n    (\u2200 (x : \u2115 \u2192 \u03b1), tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) \u2192 tendsto f k l :=\n  iff.mpr (tendsto_iff_seq_tendsto hcb)\n\ntheorem subseq_tendsto {\u03b1 : Type u_3} {f : filter \u03b1} (hf : is_countably_generated f) {u : \u2115 \u2192 \u03b1}\n    (hx : ne_bot (f \u2293 map u at_top)) : \u2203 (\u03b8 : \u2115 \u2192 \u2115), strict_mono \u03b8 \u2227 tendsto (u \u2218 \u03b8) at_top f :=\n  sorry\n\nend is_countably_generated\n\n\nend filter\n\n\ntheorem exists_lt_mul_self {R : Type u_6} [linear_ordered_semiring R] (a : R) :\n    \u2203 (x : R), \u2203 (H : x \u2265 0), a < x * x :=\n  sorry\n\ntheorem exists_le_mul_self {R : Type u_6} [linear_ordered_semiring R] (a : R) :\n    \u2203 (x : R), \u2203 (H : x \u2265 0), a \u2264 x * x :=\n  sorry\n\nnamespace order_iso\n\n\n@[simp] theorem comap_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2] (e : \u03b1 \u2243o \u03b2) :\n    filter.comap (\u21d1e) filter.at_top = filter.at_top :=\n  sorry\n\n@[simp] theorem comap_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2] (e : \u03b1 \u2243o \u03b2) :\n    filter.comap (\u21d1e) filter.at_bot = filter.at_bot :=\n  comap_at_top (order_iso.dual e)\n\n@[simp] theorem map_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2] (e : \u03b1 \u2243o \u03b2) :\n    filter.map (\u21d1e) filter.at_top = filter.at_top :=\n  sorry\n\n@[simp] theorem map_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2] (e : \u03b1 \u2243o \u03b2) :\n    filter.map (\u21d1e) filter.at_bot = filter.at_bot :=\n  map_at_top (order_iso.dual e)\n\ntheorem tendsto_at_top {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2] (e : \u03b1 \u2243o \u03b2) :\n    filter.tendsto (\u21d1e) filter.at_top filter.at_top :=\n  eq.le (map_at_top e)\n\ntheorem tendsto_at_bot {\u03b1 : Type u_3} {\u03b2 : Type u_4} [preorder \u03b1] [preorder \u03b2] (e : \u03b1 \u2243o \u03b2) :\n    filter.tendsto (\u21d1e) filter.at_bot filter.at_bot :=\n  eq.le (map_at_bot e)\n\n@[simp] theorem tendsto_at_top_iff {\u03b1 : Type u_3} {\u03b2 : Type u_4} {\u03b3 : Type u_5} [preorder \u03b1]\n    [preorder \u03b2] {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n    filter.tendsto (fun (x : \u03b3) => coe_fn e (f x)) l filter.at_top \u2194\n        filter.tendsto f l filter.at_top :=\n  sorry\n\n@[simp] theorem tendsto_at_bot_iff {\u03b1 : Type u_3} {\u03b2 : Type u_4} {\u03b3 : Type u_5} [preorder \u03b1]\n    [preorder \u03b2] {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n    filter.tendsto (fun (x : \u03b3) => coe_fn e (f x)) l filter.at_bot \u2194\n        filter.tendsto f l filter.at_bot :=\n  tendsto_at_top_iff (order_iso.dual e)\n\nend order_iso\n\n\n/-- Let `g : \u03b3 \u2192 \u03b2` be an injective function and `f : \u03b2 \u2192 \u03b1` be a function from the codomain of `g`\nto a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters\n`at_top.map (\u03bb s, \u220f i in s, f (g i))` and `at_top.map (\u03bb s, \u220f i in s, f i)` coincide.\n\nThe additive version of this lemma is used to prove the equality `\u2211' x, f (g x) = \u2211' y, f y` under\nthe same assumptions.-/\ntheorem function.injective.map_at_top_finset_sum_eq {\u03b1 : Type u_3} {\u03b2 : Type u_4} {\u03b3 : Type u_5}\n    [add_comm_monoid \u03b1] {g : \u03b3 \u2192 \u03b2} (hg : function.injective g) {f : \u03b2 \u2192 \u03b1}\n    (hf : \u2200 (x : \u03b2), \u00acx \u2208 set.range g \u2192 f x = 0) :\n    filter.map (fun (s : finset \u03b3) => finset.sum s fun (i : \u03b3) => f (g i)) filter.at_top =\n        filter.map (fun (s : finset \u03b2) => finset.sum s fun (i : \u03b2) => f i) filter.at_top :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/filter/at_top_bot_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.723496720873569}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n-/\nimport analysis.normed_space.basic\nimport number_theory.padics.padic_norm\n\n/-!\n# p-adic numbers\n\nThis file defines the p-adic numbers (rationals) `\u211a_p` as\nthe completion of `\u211a` with respect to the p-adic norm.\nWe show that the p-adic norm on \u211a extends to `\u211a_p`, that `\u211a` is embedded in `\u211a_p`,\nand that `\u211a_p` is Cauchy complete.\n\n## Important definitions\n\n* `padic` : the type of p-adic numbers\n* `padic_norm_e` : the rational valued p-adic norm on `\u211a_p`\n\n## Notation\n\nWe introduce the notation `\u211a_[p]` for the p-adic numbers.\n\n## Implementation notes\n\nMuch, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically\nby taking `[fact (prime p)]` as a type class argument.\n\nWe use the same concrete Cauchy sequence construction that is used to construct \u211d.\n`\u211a_p` inherits a field structure from this construction.\nThe extension of the norm on \u211a to `\u211a_p` is *not* analogous to extending the absolute value to \u211d,\nand hence the proof that `\u211a_p` is complete is different from the proof that \u211d is complete.\n\nA small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence\nindices in the proof that the norm extends.\n\n`padic_norm_e` is the rational-valued p-adic norm on `\u211a_p`.\nTo instantiate `\u211a_p` as a normed field, we must cast this into a \u211d-valued norm.\nThe `\u211d`-valued norm, using notation `\u2225 \u2225` from normed spaces,\nis the canonical representation of this norm.\n\n`simp` prefers `padic_norm` to `padic_norm_e` when possible.\nSince `padic_norm_e` and `\u2225 \u2225` have different types, `simp` does not rewrite one to the other.\n\nCoercions from `\u211a` to `\u211a_p` are set up to work with the `norm_cast` tactic.\n\n## References\n\n* [F. Q. Gou\u00eava, *p-adic numbers*][gouvea1997]\n* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]\n* <https://en.wikipedia.org/wiki/P-adic_number>\n\n## Tags\n\np-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion\n-/\n\nnoncomputable theory\nopen_locale classical\n\nopen nat multiplicity padic_norm cau_seq cau_seq.completion metric\n\n/-- The type of Cauchy sequences of rationals with respect to the p-adic norm. -/\n@[reducible] def padic_seq (p : \u2115) := cau_seq _ (padic_norm p)\n\nnamespace padic_seq\n\nsection\nvariables {p : \u2115} [fact p.prime]\n\n/-- The p-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually\nconstant. -/\nlemma stationary {f : cau_seq \u211a (padic_norm p)} (hf : \u00ac f \u2248 0) :\n  \u2203 N, \u2200 m n, N \u2264 m \u2192 N \u2264 n \u2192 padic_norm p (f n) = padic_norm p (f m) :=\nhave \u2203 \u03b5 > 0, \u2203 N1, \u2200 j \u2265 N1, \u03b5 \u2264 padic_norm p (f j),\n  from cau_seq.abv_pos_of_not_lim_zero $ not_lim_zero_of_not_congr_zero hf,\nlet \u27e8\u03b5, h\u03b5, N1, hN1\u27e9 := this,\n    \u27e8N2, hN2\u27e9 := cau_seq.cauchy\u2082 f h\u03b5 in\n\u27e8 max N1 N2,\n  \u03bb n m hn hm,\n  have padic_norm p (f n - f m) < \u03b5, from hN2 _ _ (max_le_iff.1 hn).2 (max_le_iff.1 hm).2,\n  have padic_norm p (f n - f m) < padic_norm p (f n),\n    from lt_of_lt_of_le this $ hN1 _ (max_le_iff.1 hn).1,\n  have  padic_norm p (f n - f m) < max (padic_norm p (f n)) (padic_norm p (f m)),\n    from lt_max_iff.2 (or.inl this),\n  begin\n    by_contradiction hne,\n    rw \u2190padic_norm.neg p (f m) at hne,\n    have hnam := add_eq_max_of_ne p hne,\n    rw [padic_norm.neg, max_comm] at hnam,\n    rw [\u2190hnam, sub_eq_add_neg, add_comm] at this,\n    apply _root_.lt_irrefl _ this\n  end \u27e9\n\n/-- For all n \u2265 stationary_point f hf, the p-adic norm of f n is the same. -/\ndef stationary_point {f : padic_seq p} (hf : \u00ac f \u2248 0) : \u2115 :=\nclassical.some $ stationary hf\n\nlemma stationary_point_spec {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  \u2200 {m n}, stationary_point hf \u2264 m \u2192 stationary_point hf \u2264 n \u2192\n    padic_norm p (f n) = padic_norm p (f m) :=\nclassical.some_spec $ stationary hf\n\n/-- Since the norm of the entries of a Cauchy sequence is eventually stationary,\nwe can lift the norm to sequences. -/\ndef norm (f : padic_seq p) : \u211a :=\nif hf : f \u2248 0 then 0 else padic_norm p (f (stationary_point hf))\n\nlemma norm_zero_iff (f : padic_seq p) : f.norm = 0 \u2194 f \u2248 0 :=\nbegin\n  constructor,\n  { intro h,\n    by_contradiction hf,\n    unfold norm at h, split_ifs at h,\n    apply hf,\n    intros \u03b5 h\u03b5,\n    existsi stationary_point hf,\n    intros j hj,\n    have heq := stationary_point_spec hf (le_refl _) hj,\n    simpa [h, heq] },\n  { intro h,\n    simp [norm, h] }\nend\n\nend\n\nsection embedding\nopen cau_seq\nvariables {p : \u2115} [fact p.prime]\n\nlemma equiv_zero_of_val_eq_of_equiv_zero {f g : padic_seq p}\n  (h : \u2200 k, padic_norm p (f k) = padic_norm p (g k)) (hf : f \u2248 0) : g \u2248 0 :=\n\u03bb \u03b5 h\u03b5, let \u27e8i, hi\u27e9 := hf _ h\u03b5 in\n\u27e8i, \u03bb j hj, by simpa [h] using hi _ hj\u27e9\n\nlemma norm_nonzero_of_not_equiv_zero {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  f.norm \u2260 0 :=\nhf \u2218 f.norm_zero_iff.1\n\nlemma norm_eq_norm_app_of_nonzero {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  \u2203 k, f.norm = padic_norm p k \u2227 k \u2260 0 :=\nhave heq : f.norm = padic_norm p (f $ stationary_point hf), by simp [norm, hf],\n\u27e8f $ stationary_point hf, heq,\n  \u03bb h, norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)\u27e9\n\nlemma not_lim_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac lim_zero (const (padic_norm p) q) :=\n\u03bb h', hq $ const_lim_zero.1 h'\n\nlemma not_equiv_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac (const (padic_norm p) q) \u2248 0 :=\n\u03bb h : lim_zero (const (padic_norm p) q - 0), not_lim_zero_const_of_nonzero hq $ by simpa using h\n\nlemma norm_nonneg (f : padic_seq p) : 0 \u2264 f.norm :=\nif hf : f \u2248 0 then by simp [hf, norm]\nelse by simp [norm, hf, padic_norm.nonneg]\n\n/-- An auxiliary lemma for manipulating sequence indices. -/\nlemma lift_index_left_left {f : padic_seq p} (hf : \u00ac f \u2248 0) (v2 v3 : \u2115) :\n  padic_norm p (f (stationary_point hf)) =\n    padic_norm p (f (max (stationary_point hf) (max v2 v3))) :=\nbegin\n  apply stationary_point_spec hf,\n  { apply le_max_left },\n  { apply le_refl }\nend\n\n/-- An auxiliary lemma for manipulating sequence indices. -/\nlemma lift_index_left {f : padic_seq p} (hf : \u00ac f \u2248 0) (v1 v3 : \u2115) :\n  padic_norm p (f (stationary_point hf)) =\n    padic_norm p (f (max v1 (max (stationary_point hf) v3))) :=\nbegin\n  apply stationary_point_spec hf,\n  { apply le_trans,\n    { apply le_max_left _ v3 },\n    { apply le_max_right } },\n  { apply le_refl }\nend\n\n/-- An auxiliary lemma for manipulating sequence indices. -/\nlemma lift_index_right {f : padic_seq p} (hf : \u00ac f \u2248 0) (v1 v2 : \u2115) :\n  padic_norm p (f (stationary_point hf)) =\n    padic_norm p (f (max v1 (max v2 (stationary_point hf)))) :=\nbegin\n  apply stationary_point_spec hf,\n  { apply le_trans,\n    { apply le_max_right v2 },\n    { apply le_max_right } },\n  { apply le_refl }\nend\n\nend embedding\n\nsection valuation\nopen cau_seq\nvariables {p : \u2115} [fact p.prime]\n\n/-! ### Valuation on `padic_seq` -/\n\n/--\nThe `p`-adic valuation on `\u211a` lifts to `padic_seq p`.\n`valuation f` is defined to be the valuation of the (`\u211a`-valued) stationary point of `f`.\n-/\ndef valuation (f : padic_seq p) : \u2124 :=\nif hf : f \u2248 0 then 0 else padic_val_rat p (f (stationary_point hf))\n\nlemma norm_eq_pow_val {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  f.norm = p^(-f.valuation : \u2124) :=\nbegin\n  rw [norm, valuation, dif_neg hf, dif_neg hf, padic_norm, if_neg],\n  intro H,\n  apply cau_seq.not_lim_zero_of_not_congr_zero hf,\n  intros \u03b5 h\u03b5,\n  use (stationary_point hf),\n  intros n hn,\n  rw stationary_point_spec hf (le_refl _) hn,\n  simpa [H] using h\u03b5,\nend\n\nlemma val_eq_iff_norm_eq {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) :\n  f.valuation = g.valuation \u2194 f.norm = g.norm :=\nbegin\n  rw [norm_eq_pow_val hf, norm_eq_pow_val hg, \u2190 neg_inj, zpow_inj],\n  { exact_mod_cast (fact.out p.prime).pos },\n  { exact_mod_cast (fact.out p.prime).ne_one },\nend\n\nend valuation\n\nend padic_seq\n\nsection\nopen padic_seq\n\nprivate meta def index_simp_core (hh hf hg : expr)\n  (at_ : interactive.loc := interactive.loc.ns [none]) : tactic unit :=\ndo [v1, v2, v3] \u2190 [hh, hf, hg].mmap\n     (\u03bb n, tactic.mk_app ``stationary_point [n] <|> return n),\n   e1 \u2190 tactic.mk_app ``lift_index_left_left [hh, v2, v3] <|> return `(true),\n   e2 \u2190 tactic.mk_app ``lift_index_left [hf, v1, v3] <|> return `(true),\n   e3 \u2190 tactic.mk_app ``lift_index_right [hg, v1, v2] <|> return `(true),\n   sl \u2190 [e1, e2, e3].mfoldl (\u03bb s e, simp_lemmas.add s e) simp_lemmas.mk,\n   when at_.include_goal (tactic.simp_target sl >> tactic.skip),\n   hs \u2190 at_.get_locals, hs.mmap' (tactic.simp_hyp sl [])\n\n/--\n  This is a special-purpose tactic that lifts padic_norm (f (stationary_point f)) to\n  padic_norm (f (max _ _ _)).\n-/\nmeta def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)\n  (at_ : interactive.parse interactive.types.location) : tactic unit :=\ndo [h, f, g] \u2190 l.mmap tactic.i_to_expr,\n   index_simp_core h f g at_\nend\n\nnamespace padic_seq\nsection embedding\n\nopen cau_seq\nvariables {p : \u2115} [hp : fact p.prime]\ninclude hp\n\nlemma norm_mul (f g : padic_seq p) : (f * g).norm = f.norm * g.norm :=\nif hf : f \u2248 0 then\n  have hg : f * g \u2248 0, from mul_equiv_zero' _ hf,\n  by simp only [hf, hg, norm, dif_pos, zero_mul]\nelse if hg : g \u2248 0 then\n  have hf : f * g \u2248 0, from mul_equiv_zero _ hg,\n  by simp only [hf, hg, norm, dif_pos, mul_zero]\nelse\n  have hfg : \u00ac f * g \u2248 0, by apply mul_not_equiv_zero; assumption,\n  begin\n    unfold norm,\n    split_ifs,\n    padic_index_simp [hfg, hf, hg],\n    apply padic_norm.mul\n  end\n\nlemma eq_zero_iff_equiv_zero (f : padic_seq p) : mk f = 0 \u2194 f \u2248 0 :=\nmk_eq\n\nlemma ne_zero_iff_nequiv_zero (f : padic_seq p) : mk f \u2260 0 \u2194 \u00ac f \u2248 0 :=\nnot_iff_not.2 (eq_zero_iff_equiv_zero _)\n\nlemma norm_const (q : \u211a) : norm (const (padic_norm p) q) = padic_norm p q :=\nif hq : q = 0 then\n  have (const (padic_norm p) q) \u2248 0,\n    by simp [hq]; apply setoid.refl (const (padic_norm p) 0),\n  by subst hq; simp [norm, this]\nelse\n  have \u00ac (const (padic_norm p) q) \u2248 0, from not_equiv_zero_const_of_nonzero hq,\n  by simp [norm, this]\n\nlemma norm_values_discrete (a : padic_seq p) (ha : \u00ac a \u2248 0) :\n  (\u2203 (z : \u2124), a.norm = \u2191p ^ (-z)) :=\nlet \u27e8k, hk, hk'\u27e9 := norm_eq_norm_app_of_nonzero ha in\nby simpa [hk] using padic_norm.values_discrete p hk'\n\nlemma norm_one : norm (1 : padic_seq p) = 1 :=\nhave h1 : \u00ac (1 : padic_seq p) \u2248 0, from one_not_equiv_zero _,\nby simp [h1, norm, hp.1.one_lt]\n\nprivate lemma norm_eq_of_equiv_aux {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g)\n  (h : padic_norm p (f (stationary_point hf)) \u2260 padic_norm p (g (stationary_point hg)))\n  (hlt : padic_norm p (g (stationary_point hg)) < padic_norm p (f (stationary_point hf))) :\n  false :=\nbegin\n  have hpn : 0 < padic_norm p (f (stationary_point hf)) - padic_norm p (g (stationary_point hg)),\n    from sub_pos_of_lt hlt,\n  cases hfg _ hpn with N hN,\n  let i := max N (max (stationary_point hf) (stationary_point hg)),\n  have hi : N \u2264 i, from le_max_left _ _,\n  have hN' := hN _ hi,\n  padic_index_simp [N, hf, hg] at hN' h hlt,\n  have hpne : padic_norm p (f i) \u2260 padic_norm p (-(g i)),\n    by rwa [ \u2190padic_norm.neg p (g i)] at h,\n  let hpnem := add_eq_max_of_ne p hpne,\n  have hpeq : padic_norm p ((f - g) i) = max (padic_norm p (f i)) (padic_norm p (g i)),\n  { rwa padic_norm.neg at hpnem },\n  rw [hpeq, max_eq_left_of_lt hlt] at hN',\n  have : padic_norm p (f i) < padic_norm p (f i),\n  { apply lt_of_lt_of_le hN', apply sub_le_self, apply padic_norm.nonneg },\n  exact lt_irrefl _ this\nend\n\nprivate lemma norm_eq_of_equiv {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g) :\n  padic_norm p (f (stationary_point hf)) = padic_norm p (g (stationary_point hg)) :=\nbegin\n  by_contradiction h,\n  cases (decidable.em (padic_norm p (g (stationary_point hg)) <\n          padic_norm p (f (stationary_point hf))))\n      with hlt hnlt,\n  { exact norm_eq_of_equiv_aux hf hg hfg h hlt },\n  { apply norm_eq_of_equiv_aux hg hf (setoid.symm hfg) (ne.symm h),\n    apply lt_of_le_of_ne,\n    apply le_of_not_gt hnlt,\n    apply h }\nend\n\ntheorem norm_equiv {f g : padic_seq p} (hfg : f \u2248 g) : f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from setoid.trans (setoid.symm hfg) hf,\n  by simp [norm, hf, hg]\nelse have hg : \u00ac g \u2248 0, from hf \u2218 setoid.trans hfg,\nby unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg\n\nprivate lemma norm_nonarchimedean_aux {f g : padic_seq p}\n  (hfg : \u00ac f + g \u2248 0) (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) : (f + g).norm \u2264 max (f.norm) (g.norm) :=\nbegin\n  unfold norm, split_ifs,\n  padic_index_simp [hfg, hf, hg],\n  apply padic_norm.nonarchimedean\nend\n\ntheorem norm_nonarchimedean (f g : padic_seq p) : (f + g).norm \u2264 max (f.norm) (g.norm) :=\nif hfg : f + g \u2248 0 then\n  have 0 \u2264 max (f.norm) (g.norm), from le_max_of_le_left (norm_nonneg _),\n  by simpa only [hfg, norm, ne.def, le_max_iff, cau_seq.add_apply, not_true, dif_pos]\nelse if hf : f \u2248 0 then\n  have hfg' : f + g \u2248 g,\n  { change lim_zero (f - 0) at hf,\n    show lim_zero (f + g - g), by simpa only [sub_zero, add_sub_cancel] using hf },\n  have hcfg : (f + g).norm = g.norm, from norm_equiv hfg',\n  have hcl : f.norm = 0, from (norm_zero_iff f).2 hf,\n  have max (f.norm) (g.norm) = g.norm,\n    by rw hcl; exact max_eq_right (norm_nonneg _),\n  by rw [this, hcfg]\nelse if hg : g \u2248 0 then\n  have hfg' : f + g \u2248 f,\n  { change lim_zero (g - 0) at hg,\n    show lim_zero (f + g - f), by simpa only [add_sub_cancel', sub_zero] using hg },\n  have hcfg : (f + g).norm = f.norm, from norm_equiv hfg',\n  have hcl : g.norm = 0, from (norm_zero_iff g).2 hg,\n  have max (f.norm) (g.norm) = f.norm,\n    by rw hcl; exact max_eq_left (norm_nonneg _),\n  by rw [this, hcfg]\nelse norm_nonarchimedean_aux hfg hf hg\n\nlemma norm_eq {f g : padic_seq p} (h : \u2200 k, padic_norm p (f k) = padic_norm p (g k)) :\n  f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from equiv_zero_of_val_eq_of_equiv_zero h hf,\n  by simp only [hf, hg, norm, dif_pos]\nelse\n  have hg : \u00ac g \u2248 0, from \u03bb hg, hf $ equiv_zero_of_val_eq_of_equiv_zero\n    (by simp only [h, forall_const, eq_self_iff_true]) hg,\n  begin\n    simp only [hg, hf, norm, dif_neg, not_false_iff],\n    let i := max (stationary_point hf) (stationary_point hg),\n    have hpf : padic_norm p (f (stationary_point hf)) = padic_norm p (f i),\n    { apply stationary_point_spec, apply le_max_left, apply le_refl },\n    have hpg : padic_norm p (g (stationary_point hg)) = padic_norm p (g i),\n    { apply stationary_point_spec, apply le_max_right, apply le_refl },\n    rw [hpf, hpg, h]\n  end\n\nlemma norm_neg (a : padic_seq p) : (-a).norm = a.norm :=\nnorm_eq $ by simp\n\nlemma norm_eq_of_add_equiv_zero {f g : padic_seq p} (h : f + g \u2248 0) : f.norm = g.norm :=\nhave lim_zero (f + g - 0), from h,\nhave f \u2248 -g, from show lim_zero (f - (-g)), by simpa only [sub_zero, sub_neg_eq_add],\nhave f.norm = (-g).norm, from norm_equiv this,\nby simpa only [norm_neg] using this\n\nlemma add_eq_max_of_ne {f g : padic_seq p} (hfgne : f.norm \u2260 g.norm) :\n  (f + g).norm = max f.norm g.norm :=\nhave hfg : \u00acf + g \u2248 0, from mt norm_eq_of_add_equiv_zero hfgne,\nif hf : f \u2248 0 then\n  have lim_zero (f - 0), from hf,\n  have f + g \u2248 g, from show lim_zero ((f + g) - g), by simpa only [sub_zero, add_sub_cancel],\n  have h1 : (f+g).norm = g.norm, from norm_equiv this,\n  have h2 : f.norm = 0, from (norm_zero_iff _).2 hf,\n  by rw [h1, h2]; rw max_eq_right (norm_nonneg _)\nelse if hg : g \u2248 0 then\n  have lim_zero (g - 0), from hg,\n  have f + g \u2248 f, from show lim_zero ((f + g) - f), by rw [add_sub_cancel']; simpa only [sub_zero],\n  have h1 : (f+g).norm = f.norm, from norm_equiv this,\n  have h2 : g.norm = 0, from (norm_zero_iff _).2 hg,\n  by rw [h1, h2]; rw max_eq_left (norm_nonneg _)\nelse\nbegin\n  unfold norm at \u22a2 hfgne, split_ifs at \u22a2 hfgne,\n  padic_index_simp [hfg, hf, hg] at \u22a2 hfgne,\n  exact padic_norm.add_eq_max_of_ne p hfgne\nend\n\nend embedding\nend padic_seq\n\n/-- The p-adic numbers `Q_[p]` are the Cauchy completion of `\u211a` with respect to the p-adic norm. -/\ndef padic (p : \u2115) [fact p.prime] := @cau_seq.completion.Cauchy _ _ _ _ (padic_norm p) _\nnotation `\u211a_[` p `]` := padic p\n\nnamespace padic\n\nsection completion\nvariables {p : \u2115} [fact p.prime]\n\n/-- The discrete field structure on `\u211a_p` is inherited from the Cauchy completion construction. -/\ninstance field : field (\u211a_[p]) :=\ncau_seq.completion.field\n\ninstance : inhabited \u211a_[p] := \u27e80\u27e9\n\n-- short circuits\n\ninstance : has_zero \u211a_[p] := by apply_instance\ninstance : has_one \u211a_[p] := by apply_instance\ninstance : has_add \u211a_[p] := by apply_instance\ninstance : has_mul \u211a_[p] := by apply_instance\ninstance : has_sub \u211a_[p] := by apply_instance\ninstance : has_neg \u211a_[p] := by apply_instance\ninstance : has_div \u211a_[p] := by apply_instance\ninstance : add_comm_group \u211a_[p] := by apply_instance\ninstance : comm_ring \u211a_[p] := by apply_instance\n\n/-- Builds the equivalence class of a Cauchy sequence of rationals. -/\ndef mk : padic_seq p \u2192 \u211a_[p] := quotient.mk\nend completion\n\nsection completion\nvariables (p : \u2115) [fact p.prime]\n\nlemma mk_eq {f g : padic_seq p} : mk f = mk g \u2194 f \u2248 g := quotient.eq\n\n/-- Embeds the rational numbers in the p-adic numbers. -/\ndef of_rat : \u211a \u2192 \u211a_[p] := cau_seq.completion.of_rat\n\n@[simp] lemma of_rat_add : \u2200 (x y : \u211a), of_rat p (x + y) = of_rat p x + of_rat p y :=\ncau_seq.completion.of_rat_add\n\n@[simp] lemma of_rat_neg : \u2200 (x : \u211a), of_rat p (-x) = -of_rat p x :=\ncau_seq.completion.of_rat_neg\n\n@[simp] lemma of_rat_mul : \u2200 (x y : \u211a), of_rat p (x * y) = of_rat p x * of_rat p y :=\ncau_seq.completion.of_rat_mul\n\n@[simp] lemma of_rat_sub : \u2200 (x y : \u211a), of_rat p (x - y) = of_rat p x - of_rat p y :=\ncau_seq.completion.of_rat_sub\n\n@[simp] lemma of_rat_div : \u2200 (x y : \u211a), of_rat p (x / y) = of_rat p x / of_rat p y :=\ncau_seq.completion.of_rat_div\n\n@[simp] lemma of_rat_one : of_rat p 1 = 1 := rfl\n\n@[simp] lemma of_rat_zero : of_rat p 0 = 0 := rfl\n\nlemma cast_eq_of_rat_of_nat (n : \u2115) : (\u2191n : \u211a_[p]) = of_rat p n :=\nbegin\n  induction n with n ih,\n  { refl },\n  { simpa using ih }\nend\n\nlemma cast_eq_of_rat_of_int (n : \u2124) : \u2191n = of_rat p n :=\nby induction n; simp [cast_eq_of_rat_of_nat]\n\nlemma cast_eq_of_rat : \u2200 (q : \u211a), (\u2191q : \u211a_[p]) = of_rat p q\n| \u27e8n, d, h1, h2\u27e9 :=\n  show \u2191n / \u2191d = _, from\n    have (\u27e8n, d, h1, h2\u27e9 : \u211a) = rat.mk n d, from rat.num_denom',\n    by simp [this, rat.mk_eq_div, of_rat_div, cast_eq_of_rat_of_int, cast_eq_of_rat_of_nat]\n\n@[norm_cast] lemma coe_add : \u2200 {x y : \u211a}, (\u2191(x + y) : \u211a_[p]) = \u2191x + \u2191y := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_neg : \u2200 {x : \u211a}, (\u2191(-x) : \u211a_[p]) = -\u2191x := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_mul : \u2200 {x y : \u211a}, (\u2191(x * y) : \u211a_[p]) = \u2191x * \u2191y := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_sub : \u2200 {x y : \u211a}, (\u2191(x - y) : \u211a_[p]) = \u2191x - \u2191y := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_div : \u2200 {x y : \u211a}, (\u2191(x / y) : \u211a_[p]) = \u2191x / \u2191y := by simp [cast_eq_of_rat]\n\n@[norm_cast] lemma coe_one : (\u21911 : \u211a_[p]) = 1 := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_zero : (\u21910 : \u211a_[p]) = 0 := rfl\n\nlemma const_equiv {q r : \u211a} : const (padic_norm p) q \u2248 const (padic_norm p) r \u2194 q = r :=\n\u27e8 \u03bb heq : lim_zero (const (padic_norm p) (q - r)),\n    eq_of_sub_eq_zero $ const_lim_zero.1 heq,\n  \u03bb heq, by rw heq; apply setoid.refl _ \u27e9\n\nlemma of_rat_eq {q r : \u211a} : of_rat p q = of_rat p r \u2194 q = r :=\n\u27e8(const_equiv p).1 \u2218 quotient.eq.1, \u03bb h, by rw h\u27e9\n\n@[norm_cast] lemma coe_inj {q r : \u211a} : (\u2191q : \u211a_[p]) = \u2191r \u2194 q = r :=\nby simp [cast_eq_of_rat, of_rat_eq]\n\ninstance : char_zero \u211a_[p] :=\n\u27e8\u03bb m n, by { rw \u2190 rat.cast_coe_nat, norm_cast, exact id }\u27e9\n\nend completion\nend padic\n\n/-- The rational-valued p-adic norm on `\u211a_p` is lifted from the norm on Cauchy sequences. The\ncanonical form of this function is the normed space instance, with notation `\u2225 \u2225`. -/\ndef padic_norm_e {p : \u2115} [hp : fact p.prime] : \u211a_[p] \u2192 \u211a :=\nquotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _\n\nnamespace padic_norm_e\nsection embedding\nopen padic_seq\nvariables {p : \u2115} [fact p.prime]\n\nlemma defn (f : padic_seq p) {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) : \u2203 N, \u2200 i \u2265 N, padic_norm_e (\u27e6f\u27e7 - f i) < \u03b5 :=\nbegin\n  simp only [padic.cast_eq_of_rat],\n  change \u2203 N, \u2200 i \u2265 N, (f - const _ (f i)).norm < \u03b5,\n  by_contradiction h,\n  cases cauchy\u2082 f h\u03b5 with N hN,\n  have : \u2200 N, \u2203 i \u2265 N, \u03b5 \u2264 (f - const _ (f i)).norm,\n    by simpa only [not_forall, not_exists, not_lt] using h,\n  rcases this N with \u27e8i, hi, hge\u27e9,\n  have hne : \u00ac (f - const (padic_norm p) (f i)) \u2248 0,\n  { intro h, unfold padic_seq.norm at hge; split_ifs at hge, exact not_lt_of_ge hge h\u03b5 },\n  unfold padic_seq.norm at hge; split_ifs at hge,\n  apply not_le_of_gt _ hge,\n  cases decidable.em (N \u2264 stationary_point hne) with hgen hngen,\n  { apply hN; assumption },\n  { have := stationary_point_spec hne (le_refl _) (le_of_not_le hngen),\n    rw \u2190this,\n    apply hN,\n    apply le_refl, assumption }\nend\n\nprotected lemma nonneg (q : \u211a_[p]) : 0 \u2264 padic_norm_e q :=\nquotient.induction_on q $ norm_nonneg\n\nlemma zero_def : (0 : \u211a_[p]) = \u27e60\u27e7 := rfl\n\nlemma zero_iff (q : \u211a_[p]) : padic_norm_e q = 0 \u2194 q = 0 :=\nquotient.induction_on q $\n  by simpa only [zero_def, quotient.eq] using norm_zero_iff\n\n@[simp] protected lemma zero : padic_norm_e (0 : \u211a_[p]) = 0 :=\n(zero_iff _).2 rfl\n\n/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the\nequivalent theorems about `norm` (`\u2225 \u2225`). -/\n@[simp] protected lemma one' : padic_norm_e (1 : \u211a_[p]) = 1 :=\nnorm_one\n\n@[simp] protected lemma neg (q : \u211a_[p]) : padic_norm_e (-q) = padic_norm_e q :=\nquotient.induction_on q $ norm_neg\n\n/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the\nequivalent theorems about `norm` (`\u2225 \u2225`). -/\ntheorem nonarchimedean' (q r : \u211a_[p]) :\n  padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_nonarchimedean\n\n/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the\nequivalent theorems about `norm` (`\u2225 \u2225`). -/\ntheorem add_eq_max_of_ne' {q r : \u211a_[p]} :\n  padic_norm_e q \u2260 padic_norm_e r \u2192 padic_norm_e (q + r) = max (padic_norm_e q) (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ \u03bb _ _, padic_seq.add_eq_max_of_ne\n\nlemma triangle_ineq (x y z : \u211a_[p]) :\n  padic_norm_e (x - z) \u2264 padic_norm_e (x - y) + padic_norm_e (y - z) :=\ncalc padic_norm_e (x - z) = padic_norm_e ((x - y) + (y - z)) : by rw sub_add_sub_cancel\n  ... \u2264 max (padic_norm_e (x - y)) (padic_norm_e (y - z)) : padic_norm_e.nonarchimedean' _ _\n  ... \u2264 padic_norm_e (x - y) + padic_norm_e (y - z) :\n    max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)\n\nprotected lemma add (q r : \u211a_[p]) : padic_norm_e (q + r) \u2264 (padic_norm_e q) + (padic_norm_e r) :=\ncalc\n  padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) : nonarchimedean' _ _\n                      ... \u2264 (padic_norm_e q) + (padic_norm_e r) :\n                              max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)\n\nprotected lemma mul' (q r : \u211a_[p]) : padic_norm_e (q * r) = (padic_norm_e q) * (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_mul\n\ninstance : is_absolute_value (@padic_norm_e p _) :=\n{ abv_nonneg := padic_norm_e.nonneg,\n  abv_eq_zero := zero_iff,\n  abv_add := padic_norm_e.add,\n  abv_mul := padic_norm_e.mul' }\n\n@[simp] lemma eq_padic_norm' (q : \u211a) : padic_norm_e (padic.of_rat p q) = padic_norm p q :=\nnorm_const _\n\nprotected theorem image' {q : \u211a_[p]} : q \u2260 0 \u2192 \u2203 n : \u2124, padic_norm_e q = p ^ (-n) :=\nquotient.induction_on q $ \u03bb f hf,\n  have \u00ac f \u2248 0, from (ne_zero_iff_nequiv_zero f).1 hf,\n  norm_values_discrete f this\n\nlemma sub_rev (q r : \u211a_[p]) : padic_norm_e (q - r) = padic_norm_e (r - q) :=\nby rw \u2190(padic_norm_e.neg); simp\n\nend embedding\nend padic_norm_e\n\nnamespace padic\n\nsection complete\nopen padic_seq padic\n\ntheorem rat_dense' {p : \u2115} [fact p.prime] (q : \u211a_[p]) {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) :\n  \u2203 r : \u211a, padic_norm_e (q - r) < \u03b5 :=\nquotient.induction_on q $ \u03bb q',\n  have \u2203 N, \u2200 m n \u2265 N, padic_norm p (q' m - q' n) < \u03b5, from cauchy\u2082 _ h\u03b5,\n  let \u27e8N, hN\u27e9 := this in\n  \u27e8q' N,\n    begin\n      simp only [padic.cast_eq_of_rat],\n      change padic_seq.norm (q' - const _ (q' N)) < \u03b5,\n      cases decidable.em ((q' - const (padic_norm p) (q' N)) \u2248 0) with heq hne',\n      { simpa only [heq, padic_seq.norm, dif_pos] },\n      { simp only [padic_seq.norm, dif_neg hne'],\n        change padic_norm p (q' _ - q' _) < \u03b5,\n        have := stationary_point_spec hne',\n        cases decidable.em (stationary_point hne' \u2264 N) with hle hle,\n        { have := eq.symm (this (le_refl _) hle),\n          simp only [const_apply, sub_apply, padic_norm.zero, sub_self] at this,\n          simpa only [this] },\n        { apply hN,\n          apply le_of_lt, apply lt_of_not_ge, apply hle, apply le_refl }}\n    end\u27e9\n\nvariables {p : \u2115} [fact p.prime] (f : cau_seq _ (@padic_norm_e p _))\nopen classical\n\nprivate lemma div_nat_pos (n : \u2115) : 0 < (1 / ((n + 1): \u211a)) :=\ndiv_pos zero_lt_one (by exact_mod_cast succ_pos _)\n\n/-- `lim_seq f`, for `f` a Cauchy sequence of `p`-adic numbers,\nis a sequence of rationals with the same limit point as `f`. -/\ndef lim_seq : \u2115 \u2192 \u211a := \u03bb n, classical.some (rat_dense' (f n) (div_nat_pos n))\n\nlemma exi_rat_seq_conv {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) :\n  \u2203 N, \u2200 i \u2265 N, padic_norm_e (f i - ((lim_seq f) i : \u211a_[p])) < \u03b5 :=\nbegin\n  refine (exists_nat_gt (1/\u03b5)).imp (\u03bb N hN i hi, _),\n  have h := classical.some_spec (rat_dense' (f i) (div_nat_pos i)),\n  refine lt_of_lt_of_le h ((div_le_iff' $ by exact_mod_cast succ_pos _).mpr _),\n  rw right_distrib,\n  apply le_add_of_le_of_nonneg,\n  { exact (div_le_iff h\u03b5).mp (le_trans (le_of_lt hN) (by exact_mod_cast hi)) },\n  { apply le_of_lt, simpa }\nend\n\nlemma exi_rat_seq_conv_cauchy : is_cau_seq (padic_norm p) (lim_seq f) :=\nassume \u03b5 h\u03b5,\nhave h\u03b53 : 0 < \u03b5 / 3, from div_pos h\u03b5 (by norm_num),\nlet \u27e8N, hN\u27e9 := exi_rat_seq_conv f h\u03b53,\n    \u27e8N2, hN2\u27e9 := f.cauchy\u2082 h\u03b53 in\nbegin\n  existsi max N N2,\n  intros j hj,\n  suffices :\n    padic_norm_e ((\u2191(lim_seq f j) - f (max N N2)) + (f (max N N2) - lim_seq f (max N N2))) < \u03b5,\n  { ring_nf at this \u22a2,\n    rw [\u2190 padic_norm_e.eq_padic_norm', \u2190 padic.cast_eq_of_rat],\n    exact_mod_cast this },\n  { apply lt_of_le_of_lt,\n    { apply padic_norm_e.add },\n    { have : (3 : \u211a) \u2260 0, by norm_num,\n      have : \u03b5 = \u03b5 / 3 + \u03b5 / 3 + \u03b5 / 3,\n      { field_simp [this], simp only [bit0, bit1, mul_add, mul_one] },\n      rw this,\n      apply add_lt_add,\n      { suffices : padic_norm_e ((\u2191(lim_seq f j) - f j) + (f j - f (max N N2))) < \u03b5 / 3 + \u03b5 / 3,\n          by simpa only [sub_add_sub_cancel],\n        apply lt_of_le_of_lt,\n        { apply padic_norm_e.add },\n        { apply add_lt_add,\n          { rw [padic_norm_e.sub_rev],\n            apply_mod_cast hN,\n            exact le_of_max_le_left hj },\n          { apply hN2,\n            exact le_of_max_le_right hj,\n            apply le_max_right }}},\n      { apply_mod_cast hN,\n        apply le_max_left }}}\nend\n\nprivate def lim' : padic_seq p := \u27e8_, exi_rat_seq_conv_cauchy f\u27e9\n\nprivate def lim : \u211a_[p] := \u27e6lim' f\u27e7\n\n\n\nend complete\n\nsection normed_space\nvariables (p : \u2115) [fact p.prime]\n\ninstance : has_dist \u211a_[p] := \u27e8\u03bb x y, padic_norm_e (x - y)\u27e9\n\ninstance : metric_space \u211a_[p] :=\n{ dist_self := by simp [dist],\n  dist_comm := \u03bb x y, by unfold dist; rw \u2190padic_norm_e.neg (x - y); simp,\n  dist_triangle :=\n    begin\n      intros, unfold dist,\n      exact_mod_cast padic_norm_e.triangle_ineq _ _ _,\n    end,\n  eq_of_dist_eq_zero :=\n    begin\n      unfold dist, intros _ _ h,\n      apply eq_of_sub_eq_zero,\n      apply (padic_norm_e.zero_iff _).1,\n      exact_mod_cast h\n    end }\n\ninstance : has_norm \u211a_[p] := \u27e8\u03bb x, padic_norm_e x\u27e9\n\ninstance : normed_field \u211a_[p] :=\n{ dist_eq := \u03bb _ _, rfl,\n  norm_mul' := by simp [has_norm.norm, padic_norm_e.mul'] }\n\ninstance is_absolute_value : is_absolute_value (\u03bb a : \u211a_[p], \u2225a\u2225) :=\n{ abv_nonneg := norm_nonneg,\n  abv_eq_zero := \u03bb _, norm_eq_zero,\n  abv_add := norm_add_le,\n  abv_mul := by simp [has_norm.norm, padic_norm_e.mul'] }\n\ntheorem rat_dense {p : \u2115} {hp : fact p.prime} (q : \u211a_[p]) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n        \u2203 r : \u211a, \u2225q - r\u2225 < \u03b5 :=\nlet \u27e8\u03b5', h\u03b5'l, h\u03b5'r\u27e9 := exists_rat_btwn h\u03b5,\n    \u27e8r, hr\u27e9 := rat_dense' q (by simpa using h\u03b5'l)  in\n\u27e8r, lt_trans (by simpa [has_norm.norm] using hr) h\u03b5'r\u27e9\n\nend normed_space\nend padic\n\nnamespace padic_norm_e\nsection normed_space\nvariables {p : \u2115} [hp : fact p.prime]\ninclude hp\n\n@[simp] protected lemma mul (q r : \u211a_[p]) : \u2225q * r\u2225 = \u2225q\u2225 * \u2225r\u2225 :=\nby simp [has_norm.norm, padic_norm_e.mul']\n\nprotected lemma is_norm (q : \u211a_[p]) : \u2191(padic_norm_e q) = \u2225q\u2225 := rfl\n\ntheorem nonarchimedean (q r : \u211a_[p]) : \u2225q + r\u2225 \u2264 max (\u2225q\u2225) (\u2225r\u2225) :=\nbegin\n  unfold has_norm.norm,\n  exact_mod_cast nonarchimedean' _ _\nend\n\ntheorem add_eq_max_of_ne {q r : \u211a_[p]} (h : \u2225q\u2225 \u2260 \u2225r\u2225) : \u2225q+r\u2225 = max (\u2225q\u2225) (\u2225r\u2225) :=\nbegin\n  unfold has_norm.norm,\n  apply_mod_cast add_eq_max_of_ne',\n  intro h',\n  apply h,\n  unfold has_norm.norm,\n  exact_mod_cast h'\nend\n\n@[simp] lemma eq_padic_norm (q : \u211a) : \u2225(\u2191q : \u211a_[p])\u2225 = padic_norm p q :=\nbegin\n  unfold has_norm.norm,\n  rw [\u2190 padic_norm_e.eq_padic_norm', \u2190 padic.cast_eq_of_rat]\nend\n\n@[simp] lemma norm_p : \u2225(p : \u211a_[p])\u2225 = p\u207b\u00b9 :=\nbegin\n  have p\u2080 : p \u2260 0 := hp.1.ne_zero,\n  have p\u2081 : p \u2260 1 := hp.1.ne_one,\n  simp [p\u2080, p\u2081, norm, padic_norm, padic_val_rat, zpow_neg, padic.cast_eq_of_rat_of_nat],\nend\n\nlemma norm_p_lt_one : \u2225(p : \u211a_[p])\u2225 < 1 :=\nbegin\n  rw norm_p,\n  apply inv_lt_one,\n  exact_mod_cast hp.1.one_lt\nend\n\n@[simp] lemma norm_p_pow (n : \u2124) : \u2225(p^n : \u211a_[p])\u2225 = p^-n :=\nby rw [normed_field.norm_zpow, norm_p]; field_simp\n\ninstance : nondiscrete_normed_field \u211a_[p] :=\n{ non_trivial := \u27e8p\u207b\u00b9, begin\n    rw [normed_field.norm_inv, norm_p, inv_inv\u2080],\n    exact_mod_cast hp.1.one_lt\n  end\u27e9 }\n\nprotected theorem image {q : \u211a_[p]} : q \u2260 0 \u2192 \u2203 n : \u2124, \u2225q\u2225 = \u2191((\u2191p : \u211a) ^ (-n)) :=\nquotient.induction_on q $ \u03bb f hf,\n  have \u00ac f \u2248 0, from (padic_seq.ne_zero_iff_nequiv_zero f).1 hf,\n  let \u27e8n, hn\u27e9 := padic_seq.norm_values_discrete f this in\n  \u27e8n, congr_arg coe hn\u27e9\n\nprotected lemma is_rat (q : \u211a_[p]) : \u2203 q' : \u211a, \u2225q\u2225 = \u2191q' :=\nif h : q = 0 then \u27e80, by simp [h]\u27e9\nelse let \u27e8n, hn\u27e9 := padic_norm_e.image h in \u27e8_, hn\u27e9\n\n/--`rat_norm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number.\n\nThe lemma `padic_norm_e.eq_rat_norm` asserts `\u2225q\u2225 = rat_norm q`. -/\ndef rat_norm (q : \u211a_[p]) : \u211a := classical.some (padic_norm_e.is_rat q)\n\nlemma eq_rat_norm (q : \u211a_[p]) : \u2225q\u2225 = rat_norm q := classical.some_spec (padic_norm_e.is_rat q)\n\ntheorem norm_rat_le_one : \u2200 {q : \u211a} (hq : \u00ac p \u2223 q.denom), \u2225(q : \u211a_[p])\u2225 \u2264 1\n| \u27e8n, d, hn, hd\u27e9 := \u03bb hq : \u00ac p \u2223 d,\n  if hnz : n = 0 then\n    have (\u27e8n, d, hn, hd\u27e9 : \u211a) = 0,\n    from rat.zero_iff_num_zero.mpr hnz,\n    by norm_num [this]\n  else\n    begin\n      have hnz' : { rat . num := n, denom := d, pos := hn, cop := hd } \u2260 0,\n        from mt rat.zero_iff_num_zero.1 hnz,\n      rw [padic_norm_e.eq_padic_norm],\n      norm_cast,\n      rw [padic_norm.eq_zpow_of_nonzero p hnz', padic_val_rat_def p hnz'],\n      have h : (multiplicity p d).get _ = 0, by simp [multiplicity_eq_zero_of_not_dvd, hq],\n      simp only, norm_cast,\n      rw_mod_cast [h, sub_zero],\n      apply zpow_le_one_of_nonpos,\n      { exact_mod_cast le_of_lt hp.1.one_lt, },\n      { apply neg_nonpos_of_nonneg, norm_cast, simp, }\n    end\n\ntheorem norm_int_le_one (z : \u2124) : \u2225(z : \u211a_[p])\u2225 \u2264 1 :=\nsuffices \u2225((z : \u211a) : \u211a_[p])\u2225 \u2264 1, by simpa,\nnorm_rat_le_one $ by simp [hp.1.ne_one]\n\nlemma norm_int_lt_one_iff_dvd (k : \u2124) : \u2225(k : \u211a_[p])\u2225 < 1 \u2194 \u2191p \u2223 k :=\nbegin\n  split,\n  { intro h,\n    contrapose! h,\n    apply le_of_eq,\n    rw eq_comm,\n    calc \u2225(k : \u211a_[p])\u2225 = \u2225((k : \u211a) : \u211a_[p])\u2225 : by { norm_cast }\n    ... = padic_norm p k : padic_norm_e.eq_padic_norm _\n    ... = 1 : _,\n    rw padic_norm,\n    split_ifs with H,\n    { exfalso,\n      apply h,\n      norm_cast at H,\n      rw H,\n      apply dvd_zero },\n    { norm_cast at H \u22a2,\n      convert zpow_zero _,\n      simp only [neg_eq_zero],\n      rw padic_val_rat.padic_val_rat_of_int _ hp.1.ne_one H,\n      norm_cast,\n      rw [\u2190 enat.coe_inj, enat.coe_get, nat.cast_zero],\n      apply multiplicity.multiplicity_eq_zero_of_not_dvd h } },\n  { rintro \u27e8x, rfl\u27e9,\n    push_cast,\n    rw padic_norm_e.mul,\n    calc _ \u2264 \u2225(p : \u211a_[p])\u2225 * 1 : mul_le_mul (le_refl _) (by simpa using norm_int_le_one _)\n                                            (norm_nonneg _) (norm_nonneg _)\n    ... < 1 : _,\n    { rw [mul_one, padic_norm_e.norm_p],\n      apply inv_lt_one,\n      exact_mod_cast hp.1.one_lt }, },\nend\n\nlemma norm_int_le_pow_iff_dvd (k : \u2124) (n : \u2115) : \u2225(k : \u211a_[p])\u2225 \u2264 ((\u2191p)^(-n : \u2124)) \u2194 \u2191(p^n) \u2223 k :=\nbegin\n  have : (p : \u211d) ^ (-n : \u2124) = \u2191((p ^ (-n : \u2124) : \u211a)), {simp},\n  rw [show (k : \u211a_[p]) = ((k : \u211a) : \u211a_[p]), by norm_cast, eq_padic_norm, this],\n  norm_cast,\n  rw padic_norm.dvd_iff_norm_le,\nend\n\nlemma eq_of_norm_add_lt_right {p : \u2115} {hp : fact p.prime} {z1 z2 : \u211a_[p]}\n  (h : \u2225z1 + z2\u2225 < \u2225z2\u2225) : \u2225z1\u2225 = \u2225z2\u2225 :=\nby_contradiction $ \u03bb hne,\n  not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_right) h\n\nlemma eq_of_norm_add_lt_left {p : \u2115} {hp : fact p.prime} {z1 z2 : \u211a_[p]}\n  (h : \u2225z1 + z2\u2225 < \u2225z1\u2225) : \u2225z1\u2225 = \u2225z2\u2225 :=\nby_contradiction $ \u03bb hne,\n  not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_left) h\n\nend normed_space\nend padic_norm_e\n\nnamespace padic\nvariables {p : \u2115} [hp_prime : fact p.prime]\ninclude hp_prime\n\nset_option eqn_compiler.zeta true\ninstance complete : cau_seq.is_complete \u211a_[p] norm :=\nbegin\n  split, intro f,\n  have cau_seq_norm_e : is_cau_seq padic_norm_e f,\n  { intros \u03b5 h\u03b5,\n    let h := is_cau f \u03b5 (by exact_mod_cast h\u03b5),\n    unfold norm at h,\n    apply_mod_cast h },\n  cases padic.complete' \u27e8f, cau_seq_norm_e\u27e9 with q hq,\n  existsi q,\n  intros \u03b5 h\u03b5,\n  cases exists_rat_btwn h\u03b5 with \u03b5' h\u03b5',\n  norm_cast at h\u03b5',\n  cases hq \u03b5' h\u03b5'.1 with N hN, existsi N,\n  intros i hi, let h := hN i hi,\n  unfold norm,\n  rw_mod_cast [cau_seq.sub_apply, padic_norm_e.sub_rev],\n  refine lt_trans _ h\u03b5'.2,\n  exact_mod_cast hN i hi\nend\n\nlemma padic_norm_e_lim_le {f : cau_seq \u211a_[p] norm} {a : \u211d} (ha : 0 < a)\n      (hf : \u2200 i, \u2225f i\u2225 \u2264 a) : \u2225f.lim\u2225 \u2264 a :=\nlet \u27e8N, hN\u27e9 := setoid.symm (cau_seq.equiv_lim f) _ ha in\ncalc \u2225f.lim\u2225 = \u2225f.lim - f N + f N\u2225 : by simp\n                ... \u2264 max (\u2225f.lim - f N\u2225) (\u2225f N\u2225) : padic_norm_e.nonarchimedean _ _\n                ... \u2264 a : max_le (le_of_lt (hN _ (le_refl _))) (hf _)\n\n/-!\n### Valuation on `\u211a_[p]`\n-/\n\n/--\n`padic.valuation` lifts the p-adic valuation on rationals to `\u211a_[p]`.\n-/\ndef valuation : \u211a_[p] \u2192 \u2124 :=\nquotient.lift (@padic_seq.valuation p _) (\u03bb f g h,\nbegin\n  by_cases hf : f \u2248 0,\n  { have hg : g \u2248 0, from setoid.trans (setoid.symm h) hf,\n    simp [hf, hg, padic_seq.valuation] },\n  { have hg : \u00ac g \u2248 0, from (\u03bb hg, hf (setoid.trans h hg)),\n    rw padic_seq.val_eq_iff_norm_eq hf hg,\n    exact padic_seq.norm_equiv h },\nend)\n\n@[simp] lemma valuation_zero : valuation (0 : \u211a_[p]) = 0 :=\ndif_pos ((const_equiv p).2 rfl)\n\n@[simp] lemma valuation_one : valuation (1 : \u211a_[p]) = 0 :=\nbegin\n  change dite (cau_seq.const (padic_norm p) 1 \u2248 _) _ _ = _,\n  have h : \u00ac cau_seq.const (padic_norm p) 1 \u2248 0,\n  { assume H, erw const_equiv p at H, exact one_ne_zero H },\n  rw dif_neg h,\n  simp,\nend\n\nlemma norm_eq_pow_val {x : \u211a_[p]} : x \u2260 0 \u2192 \u2225x\u2225 = p^(-x.valuation) :=\nbegin\n  apply quotient.induction_on' x, clear x,\n  intros f hf,\n  change (padic_seq.norm _ : \u211d) = (p : \u211d) ^ -padic_seq.valuation _,\n  rw padic_seq.norm_eq_pow_val,\n  change \u2191((p : \u211a) ^ -padic_seq.valuation f) = (p : \u211d) ^ -padic_seq.valuation f,\n  { rw rat.cast_zpow,\n    congr' 1,\n    norm_cast },\n  { apply cau_seq.not_lim_zero_of_not_congr_zero,\n    contrapose! hf,\n    apply quotient.sound,\n    simpa using hf, }\nend\n\n@[simp] lemma valuation_p : valuation (p : \u211a_[p]) = 1 :=\nbegin\n  have h : (1 : \u211d) < p := by exact_mod_cast (fact.out p.prime).one_lt,\n  rw \u2190 neg_inj,\n  apply (zpow_strict_mono h).injective,\n  dsimp only,\n  rw \u2190 norm_eq_pow_val,\n  { simp },\n  { exact_mod_cast (fact.out p.prime).ne_zero }\nend\n\nsection norm_le_iff\n/-! ### Various characterizations of open unit balls -/\nlemma norm_le_pow_iff_norm_lt_pow_add_one (x : \u211a_[p]) (n : \u2124) :\n  \u2225x\u2225 \u2264 p ^ n \u2194 \u2225x\u2225 < p ^ (n + 1) :=\nbegin\n  have aux : \u2200 n : \u2124, 0 < (p ^ n : \u211d),\n  { apply nat.zpow_pos_of_pos, exact hp_prime.1.pos },\n  by_cases hx0 : x = 0, { simp [hx0, norm_zero, aux, le_of_lt (aux _)], },\n  rw norm_eq_pow_val hx0,\n  have h1p : 1 < (p : \u211d), { exact_mod_cast hp_prime.1.one_lt },\n  have H := zpow_strict_mono h1p,\n  rw [H.le_iff_le, H.lt_iff_lt, int.lt_add_one_iff],\nend\n\nlemma norm_lt_pow_iff_norm_le_pow_sub_one (x : \u211a_[p]) (n : \u2124) :\n  \u2225x\u2225 < p ^ n \u2194 \u2225x\u2225 \u2264 p ^ (n - 1) :=\nby rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel]\n\nend norm_le_iff\nend padic\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/padics/padic_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.7234967169901304}}
{"text": "/-\nCopyright (c) 2021 Vladimir Goryachev. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Vladimir Goryachev, Kyle Miller, Scott Morrison, Eric Rodriguez\n-/\nimport data.list.basic\nimport data.nat.prime\nimport set_theory.cardinal.finite\n\n/-!\n# Counting on \u2115\n\nThis file defines the `count` function, which gives, for any predicate on the natural numbers,\n\"how many numbers under `k` satisfy this predicate?\".\nWe then prove several expected lemmas about `count`, relating it to the cardinality of other\nobjects, and helping to evaluate it for specific `k`.\n\n-/\n\nopen finset\n\nnamespace nat\nvariable (p : \u2115 \u2192 Prop)\n\nsection count\nvariable [decidable_pred p]\n\n/-- Count the number of naturals `k < n` satisfying `p k`. -/\ndef count (n : \u2115) : \u2115 := (list.range n).countp p\n\n@[simp] lemma count_zero : count p 0 = 0 :=\nby rw [count, list.range_zero, list.countp]\n\n/-- A fintype instance for the set relevant to `nat.count`. Locally an instance in locale `count` -/\ndef count_set.fintype (n : \u2115) : fintype {i // i < n \u2227 p i} :=\nbegin\n  apply fintype.of_finset ((finset.range n).filter p),\n  intro x,\n  rw [mem_filter, mem_range],\n  refl,\nend\n\nlocalized \"attribute [instance] nat.count_set.fintype\" in count\n\nlemma count_eq_card_filter_range (n : \u2115) : count p n = ((range n).filter p).card :=\nby { rw [count, list.countp_eq_length_filter], refl, }\n\n/-- `count p n` can be expressed as the cardinality of `{k // k < n \u2227 p k}`. -/\nlemma count_eq_card_fintype (n : \u2115) : count p n = fintype.card {k : \u2115 // k < n \u2227 p k} :=\nby { rw [count_eq_card_filter_range, \u2190fintype.card_of_finset, \u2190count_set.fintype], refl, }\n\nlemma count_succ (n : \u2115) : count p (n + 1) = count p n + (if p n then 1 else 0) :=\nby split_ifs; simp [count, list.range_succ, h]\n\n@[mono] lemma count_monotone : monotone (count p) :=\nmonotone_nat_of_le_succ $ \u03bb n, by by_cases h : p n; simp [count_succ, h]\n\nlemma count_add (a b : \u2115) : count p (a + b) = count p a + count (\u03bb k, p (a + k)) b :=\nbegin\n  have : disjoint ((range a).filter p) (((range b).map $ add_left_embedding a).filter p),\n  { intros x hx,\n    simp_rw [inf_eq_inter, mem_inter, mem_filter, mem_map, mem_range] at hx,\n    obtain \u27e8\u27e8hx, _\u27e9, \u27e8c, _, rfl\u27e9, _\u27e9 := hx,\n    exact (self_le_add_right _ _).not_lt hx },\n  simp_rw [count_eq_card_filter_range, range_add, filter_union, card_disjoint_union this,\n    map_filter, add_left_embedding, card_map], refl,\nend\n\nlemma count_add' (a b : \u2115) : count p (a + b) = count (\u03bb k, p (k + b)) a + count p b :=\nby { rw [add_comm, count_add, add_comm], simp_rw [add_comm b] }\n\nlemma count_one : count p 1 = if p 0 then 1 else 0 := by simp [count_succ]\n\nlemma count_succ' (n : \u2115) : count p (n + 1) = count (\u03bb k, p (k + 1)) n + if p 0 then 1 else 0 :=\nby rw [count_add', count_one]\n\nvariables {p}\n\n@[simp] lemma count_lt_count_succ_iff {n : \u2115} : count p n < count p (n + 1) \u2194 p n :=\nby by_cases h : p n; simp [count_succ, h]\n\nlemma count_succ_eq_succ_count_iff {n : \u2115} : count p (n + 1) = count p n + 1 \u2194 p n :=\nby by_cases h : p n; simp [h, count_succ]\n\nlemma count_succ_eq_count_iff {n : \u2115} : count p (n + 1) = count p n \u2194 \u00acp n :=\nby by_cases h : p n; simp [h, count_succ]\n\nalias count_succ_eq_succ_count_iff \u2194 _ count_succ_eq_succ_count\nalias count_succ_eq_count_iff \u2194 _ count_succ_eq_count\n\nlemma count_le_cardinal (n : \u2115) : (count p n : cardinal) \u2264 cardinal.mk {k | p k} :=\nbegin\n  rw [count_eq_card_fintype, \u2190 cardinal.mk_fintype],\n  exact cardinal.mk_subtype_mono (\u03bb x hx, hx.2),\nend\n\nlemma lt_of_count_lt_count {a b : \u2115} (h : count p a < count p b) : a < b :=\n(count_monotone p).reflect_lt h\n\nlemma count_strict_mono {m n : \u2115} (hm : p m) (hmn : m < n) : count p m < count p n :=\n(count_lt_count_succ_iff.2 hm).trans_le $ count_monotone _ (nat.succ_le_iff.2 hmn)\n\nlemma count_injective {m n : \u2115} (hm : p m) (hn : p n) (heq : count p m = count p n) : m = n :=\nbegin\n  by_contra,\n  wlog hmn : m < n,\n  { exact ne.lt_or_lt h },\n  { simpa [heq] using count_strict_mono hm hmn }\nend\n\nlemma count_le_card (hp : (set_of p).finite) (n : \u2115) : count p n \u2264 hp.to_finset.card :=\nbegin\n  rw count_eq_card_filter_range,\n  exact finset.card_mono (\u03bb x hx, hp.mem_to_finset.2 (mem_filter.1 hx).2)\nend\n\nlemma count_lt_card {n : \u2115} (hp : (set_of p).finite) (hpn : p n) :\n  count p n < hp.to_finset.card :=\n(count_lt_count_succ_iff.2 hpn).trans_le (count_le_card hp _)\n\nvariable {q : \u2115 \u2192 Prop}\nvariable [decidable_pred q]\n\n\n\nend count\n\nend nat\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/nat/count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7234628951339016}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Floris van Doorn.\n\nA lecture on library-building.\n-/\nimport algebra.group order.boolean_algebra tactic.library_search\ndata.vector\n\nset_option old_structure_cmd true\nuniverse variable u\n\n/-\n  Best practices:\n-/\n\n/-\n  Use good names: https://github.com/leanprover-community/mathlib/blob/master/docs/contribute/naming.md\n-/\n\n#print nat.succ_ne_zero\n#print mul_zero -- the name could be mul_zero_eq, but we shorten it\n#print mul_one\n#print le_iff_lt_or_eq\n#print neg_neg\n#print add_lt_add_of_lt_of_le\n#print mul_assoc\n\nexample {p q : Prop} (h : p \u2227 q) :\n  p :=\nh.left -- and.left h\n\nopen nat\nexample (n : \u2115) : succ n > 0 :=\nby library_search\n-- library_search is useful to find a lemma in the library. You need to know the exact conclusion of the lemma (and import tactic.library_search).\n\n/-\n  Use good style: https://github.com/leanprover-community/mathlib/blob/master/docs/contribute/style.md\n-/\n\n/-\n  Good proving practice\n    * Try to work in great generality (c.f. Fr\u00e9chet derivative)\n    * Use bi-implications whenever possible\n    * Write equations and bi-implications so that the RHS is simpler than the LHS (if possible)\n-/\n\n/-\n  IMPORTANT: Copy-paste from a similar development:\n    - The existing library probably used the right explicit/implicit arguments\n    - The existing library probably used the right style\n    - The existing library probably made good design decisions\n-/\n\n/-\n  Look through mathlib to see what parts already exists\n-/\n\n/-\n  After you complete a lemma, clean up the proof afterwards:\n    * replace `intro x, intro y` by `intros x y`\n    * remove `simp` (or other automation) if it didn't close  goal\n    * If the proof fits on one line, replace `begin ... end` with `by { ... }`\n    * etc.\n-/\n\n/-\n  As a demo, let's build a little library of quasigroups:\n  https://en.wikipedia.org/wiki/Quasigroup\n-/\n\n/-\n  From Wikipedia:\n  A quasigroup (Q, \u2217, \\, /) is a type (2,2,2) algebra (i.e., equipped with three binary operations) satisfying the identities:\n  y = x \u2217 (x \\ y),\n  y = x \\ (x \u2217 y),\n  y = (y / x) \u2217 x,\n  y = (y \u2217 x) / x.\n-/\n\n#print semigroup -- we use a definition similar to semigroup\n-- \\ is left division, abbreviated as ldiv\n-- / right division, abbreviated as rdiv\nclass quasigroup (\u03b1 : Type u) extends has_mul \u03b1, has_div \u03b1, has_sdiff \u03b1 :=\n(mul_ldiv : \u2200 x y : \u03b1, x * (x \\ y) = y)\n(ldiv_mul : \u2200 x y : \u03b1, x \\ (x * y) = y)\n(rdiv_mul : \u2200 x y : \u03b1, (x / y) * y = x)\n(mul_rdiv : \u2200 x y : \u03b1, (x * y) / y = x)\n\n-- x \\ y is the unique element z such that x * z = y\n\nvariables {\u03b1 : Type u} [quasigroup \u03b1]\n\nlemma mul_ldiv (x y : \u03b1) : x * (x \\ y) = y :=\nquasigroup.mul_ldiv x y\nlemma ldiv_mul (x y : \u03b1) : x \\ (x * y) = y :=\nquasigroup.ldiv_mul x y\nlemma mul_rdiv (x y : \u03b1) : (x * y) / y = x :=\nquasigroup.mul_rdiv x y\nlemma rdiv_mul (x y : \u03b1) : (x / y) * y = x :=\nquasigroup.rdiv_mul x y\n\n@[simp] lemma ldiv_eq_iff_mul_eq {x y z : \u03b1} :\n  x \\ y = z \u2194 x * z = y :=\nbegin\n  split,\n  { intro h, rw [\u2190 h, mul_ldiv] },\n  { intro h, rw [\u2190 h, ldiv_mul] }\nend\n\n@[simp] lemma rdiv_eq_iff_mul_eq {x y z : \u03b1} :\n  x / y = z \u2194 z * y = x :=\nbegin\n  split,\n  { intro h, rw [\u2190 h, rdiv_mul] },\n  { intro h, rw [\u2190 h, mul_rdiv] }\nend\n\n/-\n  Given an abelian group, (A, +), taking its subtraction operation as quasigroup multiplication yields a quasigroup (A, \u2212)\n-/\n\n@[simp] lemma add_add_neg_cancel {\u03b1} [add_comm_group \u03b1] (x y : \u03b1) : x + (y + -x) = y :=\nby { rw [add_comm], simp }\n\ndef sub_quasigroup (\u03b1 : Type u) := \u03b1\ninstance {\u03b1} [add_comm_group \u03b1] : quasigroup (sub_quasigroup \u03b1) :=\n{ mul := \u03bb x y, (x - y : \u03b1),\n  div := \u03bb x y, (x + y : \u03b1),\n  sdiff := \u03bb x y, (x - y : \u03b1),\n  ldiv_mul := by { intros, simp },\n  mul_ldiv := by { intros, simp },\n  mul_rdiv := by { intros, simp },\n  rdiv_mul := by { intros, simp } }\n\n/-\n  A loop is a quasigroup with an identity element; that is, an element, e, such that\n  x \u2217 e = x and e \u2217 x = x for all x in Q.\n  It follows that the identity element, e, is unique, and that every element of Q has unique left and right inverses (which need not be the same).\n-/\n#print monoid -- we use a definition similar to monoid.\n\nclass loop (\u03b1 : Type u) extends quasigroup \u03b1, has_one \u03b1 :=\n(one_mul : \u2200 a : \u03b1, 1 * a = a) (mul_one : \u2200 a : \u03b1, a * 1 = a)\n\n\n\n/-\n  Every group is a loop.\n-/\n#print group\ninstance group.to_loop {\u03b1 : Type u}\n  [h : group \u03b1] : loop \u03b1 :=\n{ mul := (*),\n  div := \u03bb x y, x * y\u207b\u00b9,\n  sdiff := \u03bb x y, x\u207b\u00b9 * y,\n  mul_ldiv := by { intros, simp },\n  ldiv_mul := by { intros, simp },\n  rdiv_mul := by { intros, simp },\n  mul_rdiv := by { intros, simp },\n  ..h }\n\n\n\n/-\n  A loop that is associative is a group\n-/\n\ndef loop.to_group {\u03b1} [h : loop \u03b1] (h_assoc : \u2200 x y z : \u03b1, (x * y) * z = x * (y * z)) : group \u03b1 :=\n{ mul := (*),\n  mul_assoc := h_assoc,\n  inv := \u03bb x, 1 / x,\n  mul_left_inv := \u03bb x, by apply rdiv_mul,\n  ..h }\n\n------------- Q&A -------------\n\n/- It is better not to put `quasigroup \u03b1` as an argument.\n  If we did that, we would have to specify two arguments to state that \u03b1 has a loop structure -/\nclass loop' (\u03b1 : Type u) [quasigroup \u03b1] extends has_one \u03b1 :=\n(one_mul : \u2200 a : \u03b1, 1 * a = a) (mul_one : \u2200 a : \u03b1, a * 1 = a)\n\ndef loop'.to_group {\u03b1} [quasigroup \u03b1] [h : loop' \u03b1] (h_assoc : \u2200 x y z : \u03b1, (x * y) * z = x * (y * z)) : group \u03b1 :=\nsorry\n\ninstance group.to_quasigroup {\u03b1 : Type u}\n  [h : group \u03b1] : quasigroup \u03b1 :=\n  sorry\n\n/- The following instance doesn't type-check if we remove the previous instance. -/\ninstance group.to_loop' {\u03b1 : Type u}\n  [h : group \u03b1] : loop' \u03b1 :=\nsorry\n\n/- If you want to use the notation * for an operation of type\n  \u03b1 \u2192 \u03b1 \u2192 \u03b1 (for some \u03b1), you can should make an instance of has_mul. Example: -/\n\ninstance list.has_mul {\u03b1 : Type u} : has_mul (list \u03b1) :=\n{ mul := list.append }\n\n/- If you want to make it a local notation (for only this file), use: -/\ndef list.has_mul' {\u03b1 : Type u} : has_mul (list \u03b1) :=\n{ mul := list.append }\nlocal attribute [instance] list.has_mul'\n\n/- if you have an operation with a different type, define (local) notation for it, and use a symbol other than *\n  -/\nconstant inner_product {n : \u2115} : vector \u2115 n \u2192 vector \u2115 n \u2192 \u2115\nlocal infix \u2b1d := inner_product", "meta": {"author": "jesse-michael-han", "repo": "hanoi-lean-2019", "sha": "a5a9f368e394d563bfcc13e3773863924505b1ce", "save_path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019", "path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019/hanoi-lean-2019-a5a9f368e394d563bfcc13e3773863924505b1ce/src/floris/lecture-library-building.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7234628886930684}}
{"text": "/-\nCopyright (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.data.nat.basic\n \n\nuniverses u \n\nnamespace Mathlib\n\n/-- `fin n` is the subtype of `\u2115` consisting of natural numbers strictly smaller than `n`. -/\ndef fin (n : \u2115) :=\n  Subtype fun (i : \u2115) => i < n\n\nnamespace fin\n\n\n/-- Backwards-compatible constructor for `fin n`. -/\ndef mk {n : \u2115} (i : \u2115) (h : i < n) : fin n :=\n  { val := i, property := h }\n\nprotected def lt {n : \u2115} (a : fin n) (b : fin n) :=\n  subtype.val a < subtype.val b\n\nprotected def le {n : \u2115} (a : fin n) (b : fin n) :=\n  subtype.val a \u2264 subtype.val b\n\nprotected instance has_lt {n : \u2115} : HasLess (fin n) :=\n  { Less := fin.lt }\n\nprotected instance has_le {n : \u2115} : HasLessEq (fin n) :=\n  { LessEq := fin.le }\n\nprotected instance decidable_lt {n : \u2115} (a : fin n) (b : fin n) : Decidable (a < b) :=\n  nat.decidable_lt (subtype.val a) (subtype.val b)\n\nprotected instance decidable_le {n : \u2115} (a : fin n) (b : fin n) : Decidable (a \u2264 b) :=\n  nat.decidable_le (subtype.val a) (subtype.val b)\n\ndef elim0 {\u03b1 : fin 0 \u2192 Sort u} (x : fin 0) : \u03b1 x :=\n  sorry\n\ntheorem eq_of_veq {n : \u2115} {i : fin n} {j : fin n} : subtype.val i = subtype.val j \u2192 i = j := sorry\n\ntheorem veq_of_eq {n : \u2115} {i : fin n} {j : fin n} : i = j \u2192 subtype.val i = subtype.val j := sorry\n\ntheorem ne_of_vne {n : \u2115} {i : fin n} {j : fin n} (h : subtype.val i \u2260 subtype.val j) : i \u2260 j :=\n  fun (h' : i = j) => absurd (veq_of_eq h') h\n\ntheorem vne_of_ne {n : \u2115} {i : fin n} {j : fin n} (h : i \u2260 j) : subtype.val i \u2260 subtype.val j :=\n  fun (h' : subtype.val i = subtype.val j) => absurd (eq_of_veq h') h\n\nend fin\n\n\nprotected instance fin.decidable_eq (n : \u2115) : DecidableEq (fin n) :=\n  fun (i j : fin n) => decidable_of_decidable_of_iff (nat.decidable_eq (subtype.val i) (subtype.val j)) sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/Lean3Lib/init/data/fin/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7234462074475886}}
{"text": "import ring_theory.ideal_operations -- PRs mostly go there\n\n-- PR directly to ring_theory.ideals\nlemma ideal.one_mem_of_unit_mem {R : Type*} [comm_ring R] {I : ideal R} {u : units R} (h : (u : R) \u2208 I) :\n(1 : R) \u2208 I :=\nbegin\n  have : (u : R)*(u\u207b\u00b9 : units R) \u2208 I, from I.mul_mem_right h,\n  rwa u.mul_inv at this\nend\n\nlemma ideal.span_singleton_mul {R : Type*} [comm_ring R] (x y : R) :\n(ideal.span ({x} : set R)) * (ideal.span {y}) = ideal.span {x*y} :=\nby simp [ideal.span_mul_span]\n\nlemma ideal.span_singleton_pow {R : Type*} [comm_ring R] (x : R) (n : \u2115) :\n(ideal.span ({x} : set R))^n = ideal.span {x^n} :=\nbegin\n  induction n with n ih,\n  { simp },\n  { rw [pow_succ, ih, ideal.span_singleton_mul, pow_succ] }\nend\n\nlemma ideal.eq_bot_iff_zero {R : Type*} [comm_ring R] {I : ideal R} : I = \u22a5 \u2194 (I : set R) = {0} :=\nbegin\n  split ; intro h,\n  { simp [h] },\n  { ext,\n    change x \u2208 (I : set R) \u2194 _,\n    simp [h] },\nend\n\n@[simp] lemma ideal.span_empty {R : Type*} [comm_ring R] : ideal.span (\u2205 : set R) = \u22a5 :=\nideal.span_eq_bot.mpr (\u03bb x h, false.elim h)\n\n@[simp] lemma ideal.span_zero {R : Type*} [comm_ring R] : ideal.span ({0} : set R) = \u22a5 :=\nideal.span_eq_bot.mpr $ \u03bb x, set.mem_singleton_iff.mp\n", "meta": {"author": "leanprover-community", "repo": "lean-perfectoid-spaces", "sha": "95a6520ce578b30a80b4c36e36ab2d559a842690", "save_path": "github-repos/lean/leanprover-community-lean-perfectoid-spaces", "path": "github-repos/lean/leanprover-community-lean-perfectoid-spaces/lean-perfectoid-spaces-95a6520ce578b30a80b4c36e36ab2d559a842690/src/for_mathlib/ideal_operations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.723446191991416}}
{"text": "import .to_permutation\nimport .to_sum\nopen equiv\n\nuniverse u \n/--\n    For a group `G` and an element `g : G`,  `to equiv g` is the permutation (i.e `equiv G G`) define \n    by : `s \u21a6 s * g\u207b\u00b9` \n-/\ndef to_equiv {G : Type u}[group G](g : G) : perm G := { to_fun := \u03bb s :G , s * g\u207b\u00b9 ,\n  inv_fun := \u03bb s : G , s * g,\n  left_inv := begin \n   intros x,dsimp,\n   rw mul_assoc, rw inv_mul_self,rw mul_one, end,\n  right_inv :=  begin  intros x,dsimp,rw  mul_assoc, rw mul_inv_self, rw mul_one, end}\n\nlemma to_equiv_ext {G : Type u}[group G](g : G) (s : G) : to_equiv g s = s * g\u207b\u00b9  := rfl\nuniverse v \n/--\n    Let `\u03c6 : G \u2192 X` with `fintype G` and `add_comm_monoid X`. \n    For `\u03c3 : perm X` we have : `\u2211 \u03c6 = \u2211 \u03c6 \u2218 \u03c3`.   \n-/\ndef Sum_equiv {G :Type u}{X : Type v}[fintype G](g : G)(\u03c6 :  G \u2192 X)[add_comm_monoid X] (\u03c3 : equiv.perm G) : \n            finset.sum finset.univ \u03c6 = finset.sum finset.univ (\u03bb s, \u03c6 (\u03c3 s))\n:= Sum_permutation \u03c6  \u03c3 \n\nvariables (G : Type)[group G](g : G)(X :Type) (\u03c6 : G \u2192 X)(hyp : fintype G)[add_comm_monoid X]\n#check @Sum_equiv G X hyp g \u03c6 _ (to_equiv g) \n/-\ntheorem Per (f : M\u2192\u2097[R]M') (g : G) : \u03a3 (mixte_conj \u03c1 \u03c0 f) = \u03a3 (\u03bb s, mixte_conj \u03c1 \u03c0 f (s * g\u207b\u00b9)) := begin \n    sorry, \nend \n-/", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep1/Tools/sum_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.927363299661721, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7233367896923641}}
{"text": "import Mathbin.Data.Set.Basic\nimport Mathbin.Data.Complex.Exponential\nimport CvxLean.Lib.Missing.Mathlib\nimport Mathbin.Algebra.GroupWithZero.Basic\n\nattribute [-simp] Set.inj_on_empty Set.inj_on_singleton Quot.lift_on\u2082_mk Quot.lift_on_mk Quot.lift\u2082_mk\n\nnamespace Real\n\ndef expCone (x y z : \u211d) : Prop :=\n  (0 < y \u2227 y * exp (x / y) \u2264 z) \u2228 (y = 0 \u2227 0 \u2264 z \u2227 x \u2264 0)\n\ndef Vec.expCone (x y z : Fin\u2093 n \u2192 \u211d) : Prop :=\n  \u2200 i, Real.expCone (x i) (y i) (z i)\n\ntheorem exp_iff_expCone (t x : \u211d) : exp x \u2264 t \u2194 expCone x 1 t := by\n  unfold expCone\n  rw [iff_def]\n  apply And.intro\n  \u00b7 intro hexp\n    apply Or.intro_left\n    apply And.intro\n    apply zero_lt_one\n    change One.one * exp (x / One.one) \u2264 t\n    rw [@div_one \u211d (@GroupWithZero\u2093.toDivisionMonoid Real\n      (@DivisionSemiring.toGroupWithZero Real (@DivisionRing.toDivisionSemiring Real Real.divisionRing)))]\n    rw [one_mul\u2093]\n    assumption\n  \u00b7 intro h\n    cases h with\n    | inl h =>\n      have h : One.one * exp (x / One.one) \u2264 t := h.2\n      rwa [@div_one \u211d (@GroupWithZero\u2093.toDivisionMonoid Real\n        (@DivisionSemiring.toGroupWithZero Real (@DivisionRing.toDivisionSemiring Real Real.divisionRing))),\n        one_mul\u2093] at h\n    | inr h =>\n      exfalso\n      apply @one_ne_zero Real\n      apply h.1\n\nend Real\n", "meta": {"author": "verified-optimization", "repo": "CvxLean", "sha": "fc2996519f0fca96f5ab48a5a1479c6a8024f733", "save_path": "github-repos/lean/verified-optimization-CvxLean", "path": "github-repos/lean/verified-optimization-CvxLean/CvxLean-fc2996519f0fca96f5ab48a5a1479c6a8024f733/CvxLean/Lib/ExpCone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7232911309990134}}
{"text": "import algebra.parity\nimport data.nat.parity\nimport data.nat.prime\nimport data.rat\n\n\nopen nat \n\nlemma rat_pow_denom_lemma : \n      \u2200 a b : \u211a, coprime a.num.nat_abs b.denom \u2192 \n        coprime b.num.nat_abs a.denom \u2192 \n        (a * b).denom = a.denom * b.denom :=\n  begin\n    introv,\n    intros a_num_cop_b_denom b_num_cop_a_denom,\n    cases a,\n    cases b,\n    rw rat.mul_num_denom,\n    simp only [cast_mul] at *,\n    norm_cast,\n    have h\u2081 : (\u2191(a_denom * b_denom) : \u2124) > 0,\n    {\n      norm_cast,\n      rw canonically_ordered_comm_semiring.mul_pos,\n      exact \u27e8a_pos, b_pos\u27e9,\n    },\n    have h\u2082 : coprime (a_num * b_num).nat_abs (\u2191(a_denom * b_denom) : \u2124).nat_abs,\n    {\n      norm_cast,\n      have h\u2083 := nat.coprime.mul a_cop b_num_cop_a_denom,\n      have h\u2084 := nat.coprime.mul b_cop a_num_cop_b_denom,\n      rw \u2190int.nat_abs_mul at h\u2083,\n      rw [\u2190int.nat_abs_mul, int.mul_comm] at h\u2084,\n      exact nat.coprime.mul_right h\u2083 h\u2084,\n    },\n    apply int.coe_nat_inj,\n    cases \u2191(a_denom * b_denom),\n    {\n      delta rat.mk,\n      simp only [int.of_nat_eq_coe, nat.cast_inj],\n      delta id_rhs,\n      unfold rat.mk_nat,\n      split_ifs,\n      {\n        exfalso,\n        rw [h, int.of_nat_eq_coe, cast_zero, gt_iff_lt, lt_self_iff_false] at h\u2081,\n        exact h\u2081,\n      },\n      {\n        unfold rat.mk_pnat,\n        simp only,\n        unfold coprime at h\u2082,\n        rw int.nat_abs_of_nat_core at h\u2082,\n        rw h\u2082,\n        exact nat.div_one _,\n      },\n    },\n    {\n      exfalso,\n      rw [gt_iff_lt, int.neg_succ_not_pos] at h\u2081,\n      exact h\u2081,\n    },\n  end\n\nlemma rat_pow_num_lemma : \n      \u2200 a b : \u211a, coprime a.num.nat_abs b.denom \u2192 \n        coprime b.num.nat_abs a.denom \u2192 \n        (a * b).num = a.num * b.num :=\n  begin\n    introv,\n    intros h h',\n    cases a,\n    cases b,\n    rw rat.mul_num_denom,\n    simp only [cast_mul] at *,\n    norm_cast,\n    have h\u2081 : (\u2191(a_denom * b_denom) : \u2124) > 0,\n    {\n      norm_cast,\n      rw [canonically_ordered_comm_semiring.mul_pos],\n      exact \u27e8a_pos, b_pos\u27e9,\n    },\n    have h\u2082 : coprime (a_num * b_num).nat_abs (\u2191(a_denom * b_denom) : \u2124).nat_abs,\n    {\n      norm_cast,\n      have h\u2083 := nat.coprime.mul a_cop h',\n      have h\u2084 := nat.coprime.mul b_cop h,\n      rw \u2190int.nat_abs_mul at h\u2083,\n      rw [\u2190int.nat_abs_mul, int.mul_comm] at h\u2084,\n      exact nat.coprime.mul_right h\u2083 h\u2084,\n    }, \n    cases \u2191(a_denom * b_denom),\n    {\n      rw int.nat_abs_of_nat_core at h\u2082,\n      delta rat.mk,\n      simp only,\n      delta id_rhs,\n      unfold rat.mk_nat,\n      split_ifs,\n      {\n        exfalso,\n        rw [h_1, int.of_nat_eq_coe, cast_zero, gt_iff_lt, lt_self_iff_false] at h\u2081,\n        exact h\u2081,\n      },\n      {\n        unfold rat.mk_pnat,\n        simp only,\n        unfold coprime at h\u2082,\n        rw [h\u2082, cast_one, int.div_one],\n      },\n    },\n    {\n      exfalso,\n      rw [gt_iff_lt, int.neg_succ_not_pos] at h\u2081,\n      exact h\u2081,\n    },\n  end\n\nlemma rat_pow_lemma (q : \u211a) (e : \u2115) : \n  (q ^ e).num = q.num ^ e \u2227 (q ^ e).denom = q.denom ^ e :=\n  begin\n    induction e,\n    {\n      simp,\n    },\n    {\n      repeat { rw pow_succ, },\n      rw [\u2190e_ih.1, \u2190e_ih.2, rat_pow_denom_lemma, rat_pow_num_lemma],\n      split,\n      repeat { refl, },\n      repeat {\n        rw e_ih.2,\n        exact nat.coprime.pow_right _ q.cop,\n      },\n      repeat {\n        rw [e_ih.1, int.nat_abs_pow],\n        exact nat.coprime.pow_left _ q.cop,\n      },\n    },\n  end\n\nlemma abs_pow_eq_pow_of_even_exp : \n  \u2200 {i : \u2124} {e : \u2115}, even e \u2192 \u2191i.nat_abs ^ e = i ^ e :=\n  begin\n    intros i _ h,\n    rw \u2190int.abs_eq_nat_abs,\n    exact even.pow_abs h i,\n  end\n\nlemma pow_ord_lemma : \u2200 (e \u2265 1), \u2200 {a b : \u2115}, a ^ e < b ^ e \u2192 a < b :=\n  begin\n    intros e e_ge_1 a b h',\n    by_contra' h\u2081,\n    cases eq_or_lt_of_le h\u2081 with h\u2081 h\u2081,\n    {\n      rw [\u2190 h\u2081, lt_self_iff_false (b ^ e)] at h',\n      exact h',\n    },\n    {\n      exact (lt_self_iff_false (a ^ e)).1 (lt_trans h' (nat.pow_lt_pow_of_lt_left h\u2081 e_ge_1)),\n    },\n  end\n\nlemma ord_lemma : \u2200 n : \u2115, \u00ac \u2203 m : \u2115, n < m \u2227 m < n + 1 :=\n  begin\n    rintros n \u27e8m, h\u27e9,\n    exact (lt_self_iff_false (n + 1)).1 (lt_of_le_of_lt (by linarith : n + 1 \u2264 m) h.2),\n  end\n\n  lemma sord_mul_lem : \u2200 {a b c d : \u2115}, a < c \u2192 b < d \u2192 a * b < c * d :=\n  begin\n    intros a b c d,\n    revert a b c,\n    induction d,\n    {\n      introv,\n      intros _ h,\n      exfalso,\n      exact not_lt_zero' h,\n    },\n    {\n      introv,\n      intros h\u2081 h\u2082,\n      by_cases h\u2083 : b < d_n,\n      {\n        have i : c * d_n.succ = c * d_n + c,\n        refl,\n        rw i,\n        apply lt_trans (d_ih h\u2081 h\u2083),\n        rw lt_add_iff_pos_right (c * d_n),\n        cases c,\n        {\n          exfalso,\n          exact not_lt_zero' h\u2081,\n        },\n        {\n          exact succ_pos',\n        },\n      },\n      {\n        cases eq_or_lt_of_le ((lt_succ_iff.mp h\u2082) : b \u2264 d_n) with h h,\n        {\n          rw \u2190h,\n          induction c,\n          {\n            exfalso,\n            exact not_lt_zero' h\u2081,\n          },\n          {\n            by_cases h\u2084 : a < c_n,\n            {\n              rw add_one_mul,\n              exact lt_trans (c_ih h\u2084) (lt_add_of_pos_right _ succ_pos'),\n            },\n            {\n              cases eq_or_lt_of_le ((lt_succ_iff.mp h\u2081) : a \u2264 c_n) with h' h',\n              {   \n                rw [\u2190h', add_one_mul, (_ : a * b.succ = a * b + a), nat.add_assoc (a * b) a b.succ],\n                apply lt_add_of_pos_right,\n                simp only [add_pos_iff, succ_pos', or_true],\n                refl,\n              },\n              {\n                exfalso,\n                exact h\u2084 h',\n              }\n            },\n          }\n        },\n        {\n          exfalso,\n          exact h\u2083 h,\n        },\n      },\n    },\n  end\n\nlemma ord_mul_lem : \u2200 {a b c d : \u2115}, a \u2265 b \u2192 c \u2265 d \u2192 a * c \u2265 b * d :=\n  begin\n    introv,\n    intros h h',\n    cases eq_or_lt_of_le h with h\u2081 h\u2081;\n    cases eq_or_lt_of_le h' with h\u2082 h\u2082,\n    repeat {\n      rw h\u2081,\n      exact nat.mul_le_mul_left _ h',\n    },\n    repeat {\n      rw h\u2082,\n      exact nat.mul_le_mul_right _ h,\n    },\n    have := sord_mul_lem h\u2081 h\u2082,\n    linarith,\n  end\n\nlemma neg_odd_pow_lemma {q : \u211a} {e\u2081 : \u2115} : q < 0 \u2192 odd e\u2081 \u2192 q ^ e\u2081 < 0 :=\n  begin\n    intros q_le_0 e\u2081_odd,\n\n    induction e\u2081 using nat.strong_induction_on with e\u2081 ih,\n    {\n      simp only [odd_iff_not_even] at ih,\n      unfold odd at e\u2081_odd,\n      rcases e\u2081_odd with \u27e8k,h'\u27e9,\n      rw h',\n      cases k,\n      {\n        rw [mul_zero, pow_one],\n        exact q_le_0,\n      },\n      {\n        rw \n          [\n            \u2190nat.add_one, nat.left_distrib, mul_one,\n            pow_succ, pow_succ, \u2190rat.mul_assoc, mul_neg_iff\n          ],\n        left,\n        split,\n        {\n          rw mul_self_pos,\n          linarith,\n        },\n        {\n          apply ih (2 * k + 1),\n          {\n            rw [h', add_lt_add_iff_right, mul_lt_mul_left succ_pos'],\n            exact lt_add_one k,\n          },\n          {\n            rw \u2190nat.odd_iff_not_even,\n            unfold odd,\n            use k,\n          },\n        },\n      },\n    },\n  end", "meta": {"author": "Julek", "repo": "lean-sqrt-2-irrational", "sha": "434de488a719932dc5760c4d199a1c780811f7cb", "save_path": "github-repos/lean/Julek-lean-sqrt-2-irrational", "path": "github-repos/lean/Julek-lean-sqrt-2-irrational/lean-sqrt-2-irrational-434de488a719932dc5760c4d199a1c780811f7cb/src/helper.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.8031738057795402, "lm_q1q2_score": 0.7232819355341435}}
{"text": "import topology.constructions\n\n/-\nIn this file, we define notation `X^n` to take powers of types.\nBy definition, `X^n` is modelled as functions from `fin n` to `X`.\n-/\n\n/-- A definition of powers of a type. -/\ndef type_pow : has_pow (Type*) \u2115 := \u27e8\u03bb A n, fin n \u2192 A\u27e9\n\n\nnamespace type_pow_topology\n\nlocal attribute [instance] type_pow\n\nvariables (z : \u2124) (A : Type) [add_comm_group A] (n : \u2115) (x : A^n)\n\ninstance topological_space {n : \u2115} {\u03b1 : Type*} [topological_space \u03b1] : topological_space (\u03b1^n) :=\n  Pi.topological_space\n\n--instance {n : \u2115} {\u03b1 : Type*} [topological_space \u03b1] [discrete_topology \u03b1]\u00a0: discrete_topology (\u03b1^n) := admit\n\nend type_pow_topology\n\nnamespace add_monoid_hom\n\nuniverses u v\n\nlocal attribute [instance] type_pow\n\n/-- The group homomorphism `A^n \u2192+ B^n` induced by a group homomorphism `A \u2192+ B`. -/\ndef pow {A : Type u} [add_comm_group A] {B : Type u} [add_comm_group B]\n  (\u03c6 : A \u2192+ B) (n : \u2115) : A^n \u2192+ B^n :=\n{ to_fun := (\u2218) \u03c6,\n  map_zero' := funext (\u03bb _, \u03c6.map_zero),\n  map_add' := \u03bb _ _, funext (\u03bb _, \u03c6.map_add _ _) }\n\nlemma pow_eval {A : Type u} [add_comm_group A] {B : Type u} [add_comm_group B]\n  (\u03c6 : A \u2192+ B) (n : \u2115) (as : A ^ n) (i : fin n) : \u03c6.pow n as i = \u03c6 (as i) := rfl\n\nopen_locale big_operators\n\n/-- The group homomorphism `A^n \u2192+ B` induced by `n` group homs `A \u2192+ B` -/\ndef pow_hom {A : Type u} [add_comm_group A] {B : Type u} [add_comm_group B]\n  {n : \u2115} (\u03c6 : fin n \u2192 A \u2192+ B) : (A^n \u2192+ B) :=\n{ to_fun := \u03bb z, \u2211 (i : fin n), \u03c6 i (z i),\n  map_zero' := by simp only [pi.zero_apply, finset.sum_const_zero, map_zero],\n  map_add' := \u03bb x y, begin\n    rw [\u2190 finset.sum_add_distrib],\n    simp,\n  end }\n\nend add_monoid_hom\n\nlocal attribute [instance] type_pow\n\n/-- The natural bijection `(A^m)^n \u2243 (A^n)^m`. -/\ndef pow_pow {A : Type*} {m n : \u2115} : (A^m)^n \u2243 (A^n)^m :=\n{ to_fun := \u03bb f i j, f j i,\n  inv_fun := \u03bb f j i, f i j,\n  left_inv := \u03bb _, rfl,\n  right_inv := \u03bb _, rfl }\n\n/-- The natural bijection `A^n \u2243 B^n` induced by a bijection `A \u2243 B`.-/\ndef pow_equiv {A B : Type*} (e : A \u2243 B) {n : \u2115} : A^n \u2243 B^n :=\n{ to_fun := \u03bb f i, e (f i),\n  inv_fun := \u03bb g i, e.symm (g i),\n  left_inv := \u03bb f, funext (\u03bb i, equiv.symm_apply_apply _ _),\n  right_inv := \u03bb g, funext (\u03bb i, equiv.apply_symm_apply _ _) }\n\n#lint- only unused_arguments def_lemma doc_blame\n", "meta": {"author": "leanprover-community", "repo": "lean-liquid", "sha": "92f188bd17f34dbfefc92a83069577f708851aec", "save_path": "github-repos/lean/leanprover-community-lean-liquid", "path": "github-repos/lean/leanprover-community-lean-liquid/lean-liquid-92f188bd17f34dbfefc92a83069577f708851aec/src/hacks_and_tricks/type_pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8031737987125613, "lm_q1q2_score": 0.7232819248818617}}
{"text": "-- This file is for undergraduate mathematicians who want to see the \n-- proof that one of the axioms that Lean uses to define a group\n-- actually follows from the others.\n\n-- G comes with notation * (group law) 1 (identiy) and a\u207b\u00b9 (inverse)\n-- mul : G \u2192 G \u2192 G := \u03bb g h, g * h\n-- one : G := 1\n-- inv : G \u2192 G := \u03bb a, a\u207b\u00b9\n\nclass has_group_notation (G : Type) extends has_mul G, has_one G, has_inv G\n\n-- definition of the group' structure\nclass group' (G : Type) extends has_group_notation G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n-- Lean 3.4.1 also uses mul_one : \u2200 (a : G), a * 1 = a , but we'll see we can deduce it!\n-- Note : this doesn't matter at all :-)\n\nnamespace group'\nvariables {G : Type} [group' G]  \n\n-- We prove left_mul_cancel for group'\n\nlemma mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c := \n\u03bb (a b c : G) (Habac : a * b = a * c), -- got to deduce b = c.\n calc b = 1 * b         : by rw one_mul\n    ... = (a\u207b\u00b9 * a) * b : by rw mul_left_inv\n    ... = a\u207b\u00b9 * (a * b) : by rw mul_assoc\n    ... = a\u207b\u00b9 * (a * c) : by rw Habac\n    ... = (a\u207b\u00b9 * a) * c : by rw mul_assoc\n    ... = 1 * c         : by rw mul_left_inv\n                ... = c : by rw one_mul\n\ntheorem mul_one : \u2200 (a : G), a * 1 = a :=\nbegin\nintro a, -- goal is a * 1 = a\n apply mul_left_cancel a\u207b\u00b9, -- goal now a\u207b\u00b9 * (a * 1) = a\u207b\u00b9 * a\n exact calc a\u207b\u00b9 * (a * 1) = (a\u207b\u00b9 * a) * 1 : by rw mul_assoc\n ...                      = 1 * 1         : by rw mul_left_inv\n ...                      = 1             : by rw one_mul\n ...                      = a\u207b\u00b9 * a       : by rw mul_left_inv\n end\n\n\n-- when you're better at driving this thing you just write this:\ntheorem group'.mul_one' : \u2200 (a : G), a * 1 = a :=\n\u03bb a, mul_left_cancel a\u207b\u00b9 _ _ (by rw [\u2190mul_assoc,mul_left_inv,one_mul]) \n\nend group'\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/blog/group_axioms_class.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7232819206619647}}
{"text": "variables p q r : Prop\n\n-- * commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := iff.intro\n(assume h\u2081: p \u2227 q,\n show q \u2227 p, from \u27e8h\u2081.right, h\u2081.left\u27e9)\n(assume h\u2082: q \u2227 p,\nshow p \u2227 q, from  \u27e8h\u2082.right, h\u2082.left\u27e9)\n\nexample : p \u2228 q \u2194 q \u2228 p := iff.intro\n(assume h1: p \u2228 q,\n  or.elim h1\n    (assume hp : p,\n    show q \u2228 p, from or.inr hp) -- I do think this is way more readable\n    (assume hq : q,\n    show q \u2228 p, from or.inl hq))\n(assume h2: q \u2228 p,\n  or.elim h2\n    (assume hq : q, or.inr hq) -- Than this\n    (assume hp : p, or.inl  hp))\n\n\n-- * associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := iff.intro\n(assume h1 :(p \u2227 q) \u2227 r,\n\u27e8h1.left.left, h1.left.right, h1.right\u27e9)\n(assume h2 : p \u2227 (q \u2227 r),\n\u27e8\u27e8h2.left, h2.right.left\u27e9, h2.right.right\u27e9)\n\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := iff.intro\n(assume h1,\nor.elim h1\n  (assume hpq,\n     or.elim hpq\n       (assume hp, or.inl hp)\n       (assume hq, or.inr (or.inl hq))) -- that was tricky wtf\n  (assume hr, or.inr (or.inr hr)))\n(assume h2,\n  h2.elim\n  (assume hp, or.inl (or.inl hp) )\n  (assume hqr, hqr.elim\n    (assume hq, or.inl (or.inr hq))\n    (assume hr, or.inr hr)))\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := iff.intro\n(assume h1,\n  have hp:p, from h1.left,\n  h1.right.elim\n    (assume hq, or.inl \u27e8hp,hq\u27e9)\n    (assume hr, or.inr \u27e8hp, hr\u27e9))\n(assume h2, h2.elim\n  (assume hpq,\n    \u27e8hpq.left, or.inl hpq.right\u27e9)\n  (assume hpr, \u27e8hpr.left, or.inr hpr.right\u27e9))\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := iff.intro\n(assume h1, h1.elim\n  (assume hp, \u27e8or.inl hp, or.inl hp\u27e9)\n  (assume hqr,\u27e8or.inr hqr.left, or.inr hqr.right\u27e9)) --\n(assume h2,\n  h2.left.elim\n    (assume hp, or.inl hp)\n    (assume hq,\n      h2.right.elim\n        (assume hp,or.inl hp )\n        (assume hr, or.inr \u27e8hq,hr\u27e9)))\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := iff.intro\n  (assume h1,\n    assume pq,\n      h1 pq.left pq.right) -- (assume h1, \u03bb pq, (h1 pq.1 pq.2 )) was my first try.\n  (assume h2, assume ifp, assume ifq, h2 \u27e8ifp, ifq\u27e9)\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\n  iff.intro\n    (assume h1,\n      and.intro   -- this one is very relevant, I had\n          (assume hp, h1 (or.inl hp)) -- gotten stuck with the and in the goal!\n          (assume hq, h1 (or.inr hq)))\n    (assume h2,\n      assume porq,\n        porq.elim\n          (assume hp, h2.left hp)\n          (assume hq, h2.right hq))\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n  iff.intro\n    (assume h1,\n      and.intro\n        (assume hp, h1 (or.inl hp))\n        (assume hq, h1 (or.inr hq)))\n    (assume h2,\n      assume porq,\n             porq.elim\n               (assume hp, h2.left hp)\n               (assume hq, h2.right hq))\n\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n  assume h1,\n  assume h2,\n  h1.elim\n    (assume notp, notp h2.left)\n    (assume notq, notq h2.right)\n\nexample : \u00ac(p \u2227 \u00acp) :=\n  assume h1, absurd h1.left h1.right\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n  assume hp_and_nq,\n  assume hp_then_q,\n    hp_and_nq.right (hp_then_q hp_and_nq.left)\n\nexample : \u00acp \u2192 (p \u2192 q) :=\n  assume hnotp,\n  assume hp,\n    absurd hp hnotp\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n  assume hnotp_or_q,\n  assume hp,\n    hnotp_or_q.elim\n      (assume hnotp, absurd hp hnotp)\n      (assume hq, hq)\n\nexample : p \u2228 false \u2194 p :=\n  iff.intro\n  (assume hp_or_false, hp_or_false.elim\n    (assume hp,hp)\n    (assume f, f.elim))\n  (assume hp, or.inl hp)\n\nexample : p \u2227 false \u2194 false :=\n  iff.intro\n  (assume hp_and_false, hp_and_false.right)\n  (assume f, f.elim)\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n  assume hifp_then_q,\n  assume hnot_q,\n  assume hp,  absurd (hifp_then_q hp) hnot_q\n\n-- couldnt do this one\n -- example : \u00ac(p \u2194 \u00acp) := assume h,\n\n\n\nopen classical\n\nvariables  s : Prop\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n  assume h, or.elim (em p)\n    (assume hp, (h hp).elim\n      (assume hr,\n        have hpr : p \u2192 r, from \u03bb _:p, hr,\n        or.inl hpr)\n      (assume hs,\n        have hps : p \u2192 s, from \u03bb _:p, hs,\n        or.inr hps ))\n    (assume hnotp,\n    suffices hp_then_r : p \u2192 r,\n    from or.inl hp_then_r, -- I still dont get this completely\n      assume hp:p, absurd hp hnotp)\n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n  assume h, or.elim (em p)\n  (assume hp,\n    or.elim (em q) -- that was tricky again\n      (assume hq, (h \u27e8hp, hq\u27e9).elim)\n      (assume hnotq,or.inr hnotq))\n  (assume hnotp, or.inl hnotp)\n\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nassume h,\n    or.elim (em q )\n      (assume hq,\n        have hpq : p \u2192 q, from \u03bb _:p, hq,\n        absurd hpq h)\n      (assume hnotq,\n        or.elim (em p)\n          (assume hp, \u27e8hp, hnotq\u27e9 )\n          (assume hnotp,\n            suffices hptoq : p \u2192 q, from  (h hptoq).elim,\n              assume hpagain:p, absurd hpagain hnotp))\n            -- not happy with this suffices dark magic\n\n\n-- got bored\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := sorry\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := sorry\n\nexample : p \u2228 \u00acp :=\nor.elim (em p)\n(assume hp, or.inl hp) (assume hnotp, or.inr hnotp)\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\n  assume h, or.elim (em p )\n    (assume hp, hp)\n    (assume hnotp,\n    have hpq : p \u2192 q, from (assume hp : p, absurd hp hnotp),\n    absurd (h hpq) hnotp) -- this \u2191\u2191 i got from the internet, it is ridiculous\n\n\n-- All in all, I'm not happy with my understanding of have and suffices;\n-- suffices is even worse gotta unerstand this fucker\n", "meta": {"author": "marcelovmaciel", "repo": "learning_lean", "sha": "0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4", "save_path": "github-repos/lean/marcelovmaciel-learning_lean", "path": "github-repos/lean/marcelovmaciel-learning_lean/learning_lean-0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4/theorem_proving_with_lean/second_notes_exercies.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.723281918540623}}
{"text": "import logic.basic\nimport algebra.order\nimport data.nat.basic\n\nlemma ne_self_imp_false : \u2200 (a : \u2115), a \u2260 a \u2192 false :=\nbegin\n    intro a,\n    intro h,\n    rw ne.def at h,\n    rw ne_self_iff_false at h,\n    exact h,\nend\n\nlemma gt_zero_of_ne_zero : \u2200 (a : \u2115), a \u2260 0 \u2192 0 < a :=\nbegin\n    intro a,\n    intro h,\n    induction a with d hd,\n    {\n        exfalso,\n        apply ne.irrefl,\n        exact h,\n    },\n    {\n        apply lt_of_le_not_le,\n        {\n            apply nat.le.intro,\n            apply zero_add,\n        },\n        {\n            intro h2,\n            have h3 := nat.le.dest h2,\n            cases h3 with n hn,\n            have h4 := nat.eq_zero_of_add_eq_zero hn,\n            have h5 := h4.left,\n            have h6 := nat.succ_ne_zero d,\n            rw \u2190 h5 at h6,\n            apply ne_self_imp_false,\n            exact h6,\n        },\n    },\nend\n\nlemma ne_zero_iff_gt_zero : \u2200 (a : \u2115), a \u2260 0 \u2194 0 < a :=\nbegin\n    intro a,\n    split,\n    {\n        apply gt_zero_of_ne_zero,\n    },\n    {\n        intro h,\n        apply ne_of_gt,\n        exact h,\n    },\nend\n\nlemma mul_left_cancel_0 (a b c : \u2115) (h: c \u2260 0) : a * c = b * c \u2192 a = b :=\nbegin\n    have hc := gt_zero_of_ne_zero c h,\n    intro h2,\n    by_contradiction hab,\n    rw \u2190 ne.def at hab,\n    rw ne_iff_lt_or_gt at hab,\n    cases hab,\n    repeat {\n        have h3 := mul_lt_mul_of_pos_right hab hc,\n        have h4 := ne_of_lt h3,\n        rw h2 at h4,\n        apply ne_self_imp_false,\n        exact h4,\n    },\nend\n\nlemma ge_zero (n : \u2115) : 0 \u2264 n :=\nbegin\n    apply @nat.le.intro 0 n n,\n    rw zero_add,\nend\n\nlemma one_or_two (n : \u2115) (h: 0 < n \u2227 n \u2264 2) : n = 1 \u2228 n = 2 :=\nbegin\n    have h2 := @classical.or_not (n \u2265 2),\n    cases h2,\n    {\n        right,\n        apply eq_iff_le_not_lt.2,\n        split,\n        {\n            exact and.right h,\n        },\n        {\n            apply not_lt_of_ge,\n            exact h2,\n        },\n    },\n    {\n        left,\n        apply eq_iff_le_not_lt.2,\n        split,\n        {\n            apply nat.le_of_lt_succ,\n            apply lt_of_not_ge,\n            exact h2,\n        },\n        {\n            apply not_lt_of_ge,\n            apply nat.le_of_lt_succ,\n            apply nat.succ_lt_succ,\n            exact and.left h,\n        },\n    },\nend\n\nlemma zero_or_one (a : \u2115) : a = 0 \u2228 a = 1 \u2194 a < 2 :=\nbegin\n    split,\n    {\n        intro h,\n        cases h,\n        {\n            rw h,\n            apply nat.lt_of_succ_le,\n            apply le_of_lt,\n            apply nat.lt_of_succ_le,\n            refl,\n        },\n        {\n            rw h,\n            apply nat.lt_of_succ_le,\n            refl,\n        },\n    },\n    {\n        intro h,\n        cases (@classical.or_not (a \u2265 1)) with h2 h2n,\n        {\n            right,\n            apply eq_iff_le_not_lt.2,\n            split,\n            {\n                apply nat.le_of_lt_succ,\n                exact h,\n            },\n            {\n                apply not_lt_of_ge,\n                exact h2\n            },\n        },\n        {\n            left,\n            apply eq_iff_le_not_lt.2,\n            split,\n            {\n                apply nat.le_of_lt_succ,\n                apply lt_of_not_ge,\n                exact h2n,\n            },\n            {\n                apply not_lt_of_ge,\n                apply ge_zero,\n            },\n        },\n    },\nend\n\nlemma gt_zero_of_eq_one (n : \u2115) : n = 1 \u2192 0 < n :=\nbegin\n    intro h,\n    rw h,\n    apply lt_add_one,\nend", "meta": {"author": "nomoid", "repo": "lean-proofs", "sha": "b9f03a24623d1a1d111d6c2bbf53c617e2596d6a", "save_path": "github-repos/lean/nomoid-lean-proofs", "path": "github-repos/lean/nomoid-lean-proofs/lean-proofs-b9f03a24623d1a1d111d6c2bbf53c617e2596d6a/src/custom/util.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7232780095005268}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport tactic.abel\nimport data.polynomial.eval\n\n/-!\n# The Pochhammer polynomials\n\nWe define and prove some basic relations about\n`pochhammer S n : polynomial S := X * (X + 1) * ... * (X + n - 1)`\nwhich is also known as the rising factorial. A version of this definition\nthat is focused on `nat` can be found in `data.nat.factorial` as `nat.asc_factorial`.\n\n## Implementation\n\nAs with many other families of polynomials, even though the coefficients are always in `\u2115`,\nwe define the polynomial with coefficients in any `[semiring S]`.\n\n## TODO\n\nThere is lots more in this direction:\n* q-factorials, q-binomials, q-Pochhammer.\n-/\n\nuniverses u v\n\nopen polynomial\n\nsection semiring\nvariables (S : Type u) [semiring S]\n\n/--\n`pochhammer S n` is the polynomial `X * (X+1) * ... * (X + n - 1)`,\nwith coefficients in the semiring `S`.\n-/\nnoncomputable def pochhammer : \u2115 \u2192 polynomial S\n| 0 := 1\n| (n+1) := X * (pochhammer n).comp (X + 1)\n\n@[simp] lemma pochhammer_zero : pochhammer S 0 = 1 := rfl\n@[simp] lemma pochhammer_one : pochhammer S 1 = X := by simp [pochhammer]\n\nlemma pochhammer_succ_left (n : \u2115) : pochhammer S (n+1) = X * (pochhammer S n).comp (X+1) :=\nby rw pochhammer\n\nsection\nvariables {S} {T : Type v} [semiring T]\n@[simp] lemma pochhammer_map (f : S \u2192+* T) (n : \u2115) : (pochhammer S n).map f = pochhammer T n :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih, pochhammer_succ_left, map_comp], },\nend\n\nend\n\n@[simp, norm_cast] lemma pochhammer_eval_cast (n k : \u2115) :\n  ((pochhammer \u2115 n).eval k : S) = (pochhammer S n).eval k :=\nbegin\n  rw [\u2190pochhammer_map (algebra_map \u2115 S), eval_map, \u2190eq_nat_cast (algebra_map \u2115 S),\n    eval\u2082_at_nat_cast, nat.cast_id, eq_nat_cast],\nend\n\nlemma pochhammer_eval_zero {n : \u2115} : (pochhammer S n).eval 0 = if n = 0 then 1 else 0 :=\nbegin\n  cases n,\n  { simp, },\n  { simp [X_mul, nat.succ_ne_zero, pochhammer_succ_left], }\nend\n\nlemma pochhammer_zero_eval_zero : (pochhammer S 0).eval 0 = 1 :=\nby simp\n\n@[simp] lemma pochhammer_ne_zero_eval_zero {n : \u2115} (h : n \u2260 0) : (pochhammer S n).eval 0 = 0 :=\nby simp [pochhammer_eval_zero, h]\n\nlemma pochhammer_succ_right (n : \u2115) : pochhammer S (n+1) = pochhammer S n * (X + n) :=\nbegin\n  suffices h : pochhammer \u2115 (n+1) = pochhammer \u2115 n * (X + n),\n  { apply_fun polynomial.map (algebra_map \u2115 S) at h,\n    simpa only [pochhammer_map, polynomial.map_mul, polynomial.map_add,\n                map_X, polynomial.map_nat_cast] using h },\n  induction n with n ih,\n  { simp, },\n  { conv_lhs\n  { rw [pochhammer_succ_left, ih, mul_comp, \u2190mul_assoc, \u2190pochhammer_succ_left, add_comp, X_comp,\n      nat_cast_comp, add_assoc, add_comm (1 : polynomial \u2115)], },\n    refl, },\nend\n\nlemma polynomial.mul_X_add_nat_cast_comp {p q : polynomial S} {n : \u2115} :\n  (p * (X + n)).comp q = (p.comp q) * (q + n) :=\nby rw [mul_add, add_comp, mul_X_comp, \u2190nat.cast_comm, nat_cast_mul_comp, nat.cast_comm, mul_add]\n\nlemma pochhammer_mul (n m : \u2115) :\n  pochhammer S n * (pochhammer S m).comp (X + n) = pochhammer S (n + m) :=\nbegin\n  induction m with m ih,\n  { simp, },\n  { rw [pochhammer_succ_right, polynomial.mul_X_add_nat_cast_comp, \u2190mul_assoc, ih,\n      nat.succ_eq_add_one, \u2190add_assoc, pochhammer_succ_right, nat.cast_add, add_assoc], }\nend\n\nlemma pochhammer_nat_eq_asc_factorial (n : \u2115) :\n  \u2200 k, (pochhammer \u2115 k).eval (n + 1) = n.asc_factorial k\n| 0 := by erw [eval_one]; refl\n| (t + 1) := begin\n  rw [pochhammer_succ_right, eval_mul, pochhammer_nat_eq_asc_factorial t],\n  suffices : n.asc_factorial t * (n + 1 + t) = n.asc_factorial (t + 1), by simpa,\n  rw [nat.asc_factorial_succ, add_right_comm, mul_comm]\nend\n\nlemma pochhammer_nat_eq_desc_factorial (a b : \u2115) :\n  (pochhammer \u2115 b).eval a = (a + b - 1).desc_factorial b :=\nbegin\n  cases b,\n  { rw [nat.desc_factorial_zero, pochhammer_zero, polynomial.eval_one] },\n  rw [nat.add_succ, nat.succ_sub_succ, tsub_zero],\n  cases a,\n  { rw [pochhammer_ne_zero_eval_zero _ b.succ_ne_zero, zero_add,\n    nat.desc_factorial_of_lt b.lt_succ_self] },\n  { rw [nat.succ_add, \u2190nat.add_succ, nat.add_desc_factorial_eq_asc_factorial,\n      pochhammer_nat_eq_asc_factorial] }\nend\n\nend semiring\n\nsection comm_semiring\nvariables {S : Type*} [comm_semiring S]\n\nlemma pochhammer_succ_eval (n : \u2115) (k : S) :\n  (pochhammer S n.succ).eval k = (pochhammer S n).eval k * (k + \u2191n) :=\nby rw [pochhammer_succ_right, polynomial.eval_mul, polynomial.eval_add, polynomial.eval_X,\n    polynomial.eval_nat_cast]\n\nend comm_semiring\n\nsection ordered_semiring\nvariables {S : Type*} [ordered_semiring S] [nontrivial S]\n\nlemma pochhammer_pos (n : \u2115) (s : S) (h : 0 < s) : 0 < (pochhammer S n).eval s :=\nbegin\n  induction n with n ih,\n  { simp only [nat.nat_zero_eq_zero, pochhammer_zero, eval_one], exact zero_lt_one, },\n  { rw [pochhammer_succ_right, mul_add, eval_add, \u2190nat.cast_comm, eval_nat_cast_mul, eval_mul_X,\n      nat.cast_comm, \u2190mul_add],\n    exact mul_pos ih\n      (lt_of_lt_of_le h ((le_add_iff_nonneg_right _).mpr (nat.cast_nonneg n))), }\nend\n\nend ordered_semiring\n\nsection factorial\n\nopen_locale nat\n\nvariables (S : Type*) [semiring S] (r n : \u2115)\n\n@[simp]\nlemma pochhammer_eval_one (S : Type*) [semiring S] (n : \u2115) :\n  (pochhammer S n).eval (1 : S) = (n! : S) :=\nby rw_mod_cast [pochhammer_nat_eq_asc_factorial, nat.zero_asc_factorial]\n\nlemma factorial_mul_pochhammer (S : Type*) [semiring S] (r n : \u2115) :\n  (r! : S) * (pochhammer S n).eval (r + 1) = (r + n)! :=\nby rw_mod_cast [pochhammer_nat_eq_asc_factorial, nat.factorial_mul_asc_factorial]\n\nlemma pochhammer_nat_eval_succ (r : \u2115) :\n  \u2200 n : \u2115, n * (pochhammer \u2115 r).eval (n + 1) = (n + r) * (pochhammer \u2115 r).eval n\n| 0 := begin\n  by_cases h : r = 0,\n  { simp only [h, zero_mul, zero_add], },\n  { simp only [pochhammer_eval_zero, zero_mul, if_neg h, mul_zero], }\nend\n| (k + 1) := by simp only [pochhammer_nat_eq_asc_factorial, nat.succ_asc_factorial, add_right_comm]\n\nlemma pochhammer_eval_succ (r n : \u2115) :\n  (n : S) * (pochhammer S r).eval (n + 1 : S) = (n + r) * (pochhammer S r).eval n :=\nby exact_mod_cast congr_arg nat.cast (pochhammer_nat_eval_succ r n)\n\nend factorial\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/ring_theory/polynomial/pochhammer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.723277999775142}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module data.polynomial.hasse_deriv\n! leanprover-community/mathlib commit 10bf4f825ad729c5653adc039dafa3622e7f93c9\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Polynomial.BigOperators\nimport Mathbin.Data.Nat.Choose.Cast\nimport Mathbin.Data.Nat.Choose.Vandermonde\nimport Mathbin.Data.Polynomial.Derivative\n\n/-!\n# Hasse derivative of polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt is a variant of the usual derivative, and satisfies `k! * (hasse_deriv k f) = derivative^[k] f`.\nThe main benefit is that is gives an atomic way of talking about expressions such as\n`(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example.\n\n## Main declarations\n\nIn the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`.\n\n* `polynomial.hasse_deriv`: the `k`-th Hasse derivative of a polynomial\n* `polynomial.hasse_deriv_zero`: the `0`th Hasse derivative is the identity\n* `polynomial.hasse_deriv_one`: the `1`st Hasse derivative is the usual derivative\n* `polynomial.factorial_smul_hasse_deriv`: the identity `k! \u2022 (D k f) = derivative^[k] f`\n* `polynomial.hasse_deriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k \u2022 D (k+l)`\n* `polynomial.hasse_deriv_mul`:\n  the \"Leibniz rule\" `D k (f * g) = \u2211 ij in antidiagonal k, D ij.1 f * D ij.2 g`\n\nFor the identity principle, see `polynomial.eq_zero_of_hasse_deriv_eq_zero`\nin `data/polynomial/taylor.lean`.\n\n## Reference\n\nhttps://math.fontein.de/2009/08/12/the-hasse-derivative/\n\n-/\n\n\nnoncomputable section\n\nnamespace Polynomial\n\nopen Nat BigOperators Polynomial\n\nopen Function\n\nopen Nat hiding nsmul_eq_mul\n\nvariable {R : Type _} [Semiring R] (k : \u2115) (f : R[X])\n\n#print Polynomial.hasseDeriv /-\n/-- The `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/\ndef hasseDeriv (k : \u2115) : R[X] \u2192\u2097[R] R[X] :=\n  lsum fun i => monomial (i - k) \u2218\u2097 DistribMulAction.toLinearMap R R (i.choose k)\n#align polynomial.hasse_deriv Polynomial.hasseDeriv\n-/\n\n/- warning: polynomial.hasse_deriv_apply -> Polynomial.hasseDeriv_apply is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) f) (Polynomial.sum.{u1, u1} R _inst_1 (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) f (fun (i : Nat) (r : R) => coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) i k)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTC\u2093.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))) (Nat.choose i k)) r)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) f) (Polynomial.sum.{u1, u1} R _inst_1 (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) f (fun (i : Nat) (r : R) => FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) i k)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Nat.cast.{u1} R (Semiring.toNatCast.{u1} R _inst_1) (Nat.choose i k)) r)))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_apply Polynomial.hasseDeriv_apply\u2093'. -/\ntheorem hasseDeriv_apply : hasseDeriv k f = f.Sum fun i r => monomial (i - k) (\u2191(i.choose k) * r) :=\n  by simpa only [\u2190 nsmul_eq_mul]\n#align polynomial.hasse_deriv_apply Polynomial.hasseDeriv_apply\n\n/- warning: polynomial.hasse_deriv_coeff -> Polynomial.hasseDeriv_coeff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (f : Polynomial.{u1} R _inst_1) (n : Nat), Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) f) n) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTC\u2093.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))) (Nat.choose (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n k) k)) (Polynomial.coeff.{u1} R _inst_1 f (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n k)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (f : Polynomial.{u1} R _inst_1) (n : Nat), Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) f) n) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Nat.cast.{u1} R (Semiring.toNatCast.{u1} R _inst_1) (Nat.choose (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n k) k)) (Polynomial.coeff.{u1} R _inst_1 f (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n k)))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_coeff Polynomial.hasseDeriv_coeff\u2093'. -/\ntheorem hasseDeriv_coeff (n : \u2115) : (hasseDeriv k f).coeff n = (n + k).choose k * f.coeff (n + k) :=\n  by\n  rw [hasse_deriv_apply, coeff_sum, sum_def, Finset.sum_eq_single (n + k), coeff_monomial]\n  \u00b7 simp only [if_true, add_tsub_cancel_right, eq_self_iff_true]\n  \u00b7 intro i hi hink\n    rw [coeff_monomial]\n    by_cases hik : i < k\n    \u00b7 simp only [Nat.choose_eq_zero_of_lt hik, if_t_t, Nat.cast_zero, MulZeroClass.zero_mul]\n    \u00b7 push_neg  at hik\n      rw [if_neg]\n      contrapose! hink\n      exact (tsub_eq_iff_eq_add_of_le hik).mp hink\n  \u00b7 intro h\n    simp only [not_mem_support_iff.mp h, monomial_zero_right, MulZeroClass.mul_zero, coeff_zero]\n#align polynomial.hasse_deriv_coeff Polynomial.hasseDeriv_coeff\n\n/- warning: polynomial.hasse_deriv_zero' -> Polynomial.hasseDeriv_zero' is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) f) f\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) f) f\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_zero' Polynomial.hasseDeriv_zero'\u2093'. -/\ntheorem hasseDeriv_zero' : hasseDeriv 0 f = f := by\n  simp only [hasse_deriv_apply, tsub_zero, Nat.choose_zero_right, Nat.cast_one, one_mul,\n    sum_monomial_eq]\n#align polynomial.hasse_deriv_zero' Polynomial.hasseDeriv_zero'\n\n#print Polynomial.hasseDeriv_zero /-\n@[simp]\ntheorem hasseDeriv_zero : @hasseDeriv R _ 0 = LinearMap.id :=\n  LinearMap.ext <| hasseDeriv_zero'\n#align polynomial.hasse_deriv_zero Polynomial.hasseDeriv_zero\n-/\n\n/- warning: polynomial.hasse_deriv_eq_zero_of_lt_nat_degree -> Polynomial.hasseDeriv_eq_zero_of_lt_natDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (p : Polynomial.{u1} R _inst_1) (n : Nat), (LT.lt.{0} Nat Nat.hasLt (Polynomial.natDegree.{u1} R _inst_1 p) n) -> (Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 n) p) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (p : Polynomial.{u1} R _inst_1) (n : Nat), (LT.lt.{0} Nat instLTNat (Polynomial.natDegree.{u1} R _inst_1 p) n) -> (Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) p) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 n) p) (OfNat.ofNat.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) p) 0 (Zero.toOfNat0.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) p) (Polynomial.zero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_eq_zero_of_lt_nat_degree Polynomial.hasseDeriv_eq_zero_of_lt_natDegree\u2093'. -/\ntheorem hasseDeriv_eq_zero_of_lt_natDegree (p : R[X]) (n : \u2115) (h : p.natDegree < n) :\n    hasseDeriv n p = 0 := by\n  rw [hasse_deriv_apply, sum_def]\n  refine' Finset.sum_eq_zero fun x hx => _\n  simp [Nat.choose_eq_zero_of_lt ((le_nat_degree_of_mem_supp _ hx).trans_lt h)]\n#align polynomial.hasse_deriv_eq_zero_of_lt_nat_degree Polynomial.hasseDeriv_eq_zero_of_lt_natDegree\n\n/- warning: polynomial.hasse_deriv_one' -> Polynomial.hasseDeriv_one' is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) f) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.derivative.{u1} R _inst_1) f)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1), Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) f) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.derivative.{u1} R _inst_1) f)\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_one' Polynomial.hasseDeriv_one'\u2093'. -/\ntheorem hasseDeriv_one' : hasseDeriv 1 f = derivative f := by\n  simp only [hasse_deriv_apply, derivative_apply, \u2190 C_mul_X_pow_eq_monomial, Nat.choose_one_right,\n    (Nat.cast_commute _ _).Eq]\n#align polynomial.hasse_deriv_one' Polynomial.hasseDeriv_one'\n\n#print Polynomial.hasseDeriv_one /-\n@[simp]\ntheorem hasseDeriv_one : @hasseDeriv R _ 1 = derivative :=\n  LinearMap.ext <| hasseDeriv_one'\n#align polynomial.hasse_deriv_one Polynomial.hasseDeriv_one\n-/\n\n/- warning: polynomial.hasse_deriv_monomial -> Polynomial.hasseDeriv_monomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (n : Nat) (r : R), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) r)) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n k)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTC\u2093.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))) (Nat.choose n k)) r))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (n : Nat) (r : R), Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (a : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) a) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) r)) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 n) r)) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R R (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R _inst_1) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.monomial.{u1} R _inst_1 (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n k)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Nat.cast.{u1} R (Semiring.toNatCast.{u1} R _inst_1) (Nat.choose n k)) r))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_monomial Polynomial.hasseDeriv_monomial\u2093'. -/\n@[simp]\ntheorem hasseDeriv_monomial (n : \u2115) (r : R) :\n    hasseDeriv k (monomial n r) = monomial (n - k) (\u2191(n.choose k) * r) :=\n  by\n  ext i\n  simp only [hasse_deriv_coeff, coeff_monomial]\n  by_cases hnik : n = i + k\n  \u00b7 rw [if_pos hnik, if_pos, \u2190 hnik]\n    apply tsub_eq_of_eq_add_rev\n    rwa [add_comm]\n  \u00b7 rw [if_neg hnik, MulZeroClass.mul_zero]\n    by_cases hkn : k \u2264 n\n    \u00b7 rw [\u2190 tsub_eq_iff_eq_add_of_le hkn] at hnik\n      rw [if_neg hnik]\n    \u00b7 push_neg  at hkn\n      rw [Nat.choose_eq_zero_of_lt hkn, Nat.cast_zero, MulZeroClass.zero_mul, if_t_t]\n#align polynomial.hasse_deriv_monomial Polynomial.hasseDeriv_monomial\n\n/- warning: polynomial.hasse_deriv_C -> Polynomial.hasseDeriv_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (r : R), (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) k) -> (Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) r)) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (r : R), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) k) -> (Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (a : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) r)) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) r)) (OfNat.ofNat.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (a : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) r)) 0 (Zero.toOfNat0.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (a : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) r)) (Polynomial.zero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_C Polynomial.hasseDeriv_C\u2093'. -/\ntheorem hasseDeriv_C (r : R) (hk : 0 < k) : hasseDeriv k (C r) = 0 := by\n  rw [\u2190 monomial_zero_left, hasse_deriv_monomial, Nat.choose_eq_zero_of_lt hk, Nat.cast_zero,\n    MulZeroClass.zero_mul, monomial_zero_right]\n#align polynomial.hasse_deriv_C Polynomial.hasseDeriv_C\n\n/- warning: polynomial.hasse_deriv_apply_one -> Polynomial.hasseDeriv_apply_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat), (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) k) -> (Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 1 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 1 (One.one.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.hasOne.{u1} R _inst_1))))) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) k) -> (Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 1 (One.toOfNat1.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.one.{u1} R _inst_1)))) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 1 (One.toOfNat1.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.one.{u1} R _inst_1)))) (OfNat.ofNat.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 1 (One.toOfNat1.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.one.{u1} R _inst_1)))) 0 (Zero.toOfNat0.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 1 (One.toOfNat1.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.one.{u1} R _inst_1)))) (Polynomial.zero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_apply_one Polynomial.hasseDeriv_apply_one\u2093'. -/\ntheorem hasseDeriv_apply_one (hk : 0 < k) : hasseDeriv k (1 : R[X]) = 0 := by\n  rw [\u2190 C_1, hasse_deriv_C k _ hk]\n#align polynomial.hasse_deriv_apply_one Polynomial.hasseDeriv_apply_one\n\n/- warning: polynomial.hasse_deriv_X -> Polynomial.hasseDeriv_X is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat), (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) k) -> (Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (Polynomial.X.{u1} R _inst_1)) (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) k) -> (Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (Polynomial.X.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (Polynomial.X.{u1} R _inst_1)) (OfNat.ofNat.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (Polynomial.X.{u1} R _inst_1)) 0 (Zero.toOfNat0.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (Polynomial.X.{u1} R _inst_1)) (Polynomial.zero.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_X Polynomial.hasseDeriv_X\u2093'. -/\ntheorem hasseDeriv_X (hk : 1 < k) : hasseDeriv k (X : R[X]) = 0 := by\n  rw [\u2190 monomial_one_one_eq_X, hasse_deriv_monomial, Nat.choose_eq_zero_of_lt hk, Nat.cast_zero,\n    MulZeroClass.zero_mul, monomial_zero_right]\n#align polynomial.hasse_deriv_X Polynomial.hasseDeriv_X\n\n/- warning: polynomial.factorial_smul_hasse_deriv -> Polynomial.factorial_smul_hasseDeriv is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat), Eq.{succ u1} ((Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (SMul.smul.{0, u1} Nat (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (LinearMap.hasSmul.{u1, u1, 0, u1, u1} R R Nat (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) Nat.monoid (Polynomial.distribMulAction.{u1, 0} R _inst_1 Nat Nat.monoid (Module.toDistribMulAction.{0, u1} Nat R Nat.semiring (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (AddCommMonoid.natModule.{u1} R (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))) (Polynomial.smulCommClass.{u1, u1, 0} R _inst_1 R Nat (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) Nat.monoid (Module.toDistribMulAction.{u1, u1} R R _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Semiring.toModule.{u1} R _inst_1)) (Module.toDistribMulAction.{0, u1} Nat R Nat.semiring (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (AddCommMonoid.natModule.{u1} R (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (AddMonoid.nat_smulCommClass'.{u1, u1} R R (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoidWithOne.toAddMonoid.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Module.toDistribMulAction.{u1, u1} R R _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Semiring.toModule.{u1} R _inst_1))))) (Nat.factorial k) (Polynomial.hasseDeriv.{u1} R _inst_1 k))) (Nat.iterate.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.derivative.{u1} R _inst_1)) k)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat), Eq.{succ u1} (forall (\u1fb0 : Polynomial.{u1} R _inst_1), (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) \u1fb0) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (HSMul.hSMul.{0, u1, u1} Nat (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (instHSMul.{0, u1} Nat (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (AddMonoid.SMul.{u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (AddMonoidWithOne.toAddMonoid.{u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (NonAssocSemiring.toAddCommMonoidWithOne.{u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Semiring.toNonAssocSemiring.{u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Module.End.semiring.{u1, u1} R (Polynomial.{u1} R _inst_1) _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))))))))) (Nat.factorial k) (Polynomial.hasseDeriv.{u1} R _inst_1 k))) (Nat.iterate.{succ u1} (Polynomial.{u1} R _inst_1) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.derivative.{u1} R _inst_1)) k)\nCase conversion may be inaccurate. Consider using '#align polynomial.factorial_smul_hasse_deriv Polynomial.factorial_smul_hasseDeriv\u2093'. -/\ntheorem factorial_smul_hasseDeriv : \u21d1(k ! \u2022 @hasseDeriv R _ k) = @derivative R _^[k] :=\n  by\n  induction' k with k ih\n  \u00b7 rw [hasse_deriv_zero, factorial_zero, iterate_zero, one_smul, LinearMap.id_coe]\n  ext (f n) : 2\n  rw [iterate_succ_apply', \u2190 ih]\n  simp only [LinearMap.smul_apply, coeff_smul, LinearMap.map_smul_of_tower, coeff_derivative,\n    hasse_deriv_coeff, \u2190 @choose_symm_add _ k]\n  simp only [nsmul_eq_mul, factorial_succ, mul_assoc, succ_eq_add_one, \u2190 add_assoc,\n    add_right_comm n 1 k, \u2190 cast_succ]\n  rw [\u2190 (cast_commute (n + 1) (f.coeff (n + k + 1))).Eq]\n  simp only [\u2190 mul_assoc]\n  norm_cast\n  congr 2\n  apply @cast_injective \u211a\n  have h1 : n + 1 \u2264 n + k + 1 := succ_le_succ le_self_add\n  have h2 : k + 1 \u2264 n + k + 1 := succ_le_succ le_add_self\n  have H : \u2200 n : \u2115, (n ! : \u211a) \u2260 0 := by exact_mod_cast factorial_ne_zero\n  -- why can't `field_simp` help me here?\n  simp only [cast_mul, cast_choose \u211a, h1, h2, -one_div, -mul_eq_zero, succ_sub_succ_eq_sub,\n    add_tsub_cancel_right, add_tsub_cancel_left, field_simps]\n  rw [eq_div_iff_mul_eq (mul_ne_zero (H _) (H _)), eq_comm, div_mul_eq_mul_div,\n    eq_div_iff_mul_eq (mul_ne_zero (H _) (H _))]\n  norm_cast\n  simp only [factorial_succ, succ_eq_add_one]\n  ring\n#align polynomial.factorial_smul_hasse_deriv Polynomial.factorial_smul_hasseDeriv\n\n#print Polynomial.hasseDeriv_comp /-\ntheorem hasseDeriv_comp (k l : \u2115) :\n    (@hasseDeriv R _ k).comp (hasseDeriv l) = (k + l).choose k \u2022 hasseDeriv (k + l) :=\n  by\n  ext i : 2\n  simp only [LinearMap.smul_apply, comp_app, LinearMap.coe_comp, smul_monomial, hasse_deriv_apply,\n    mul_one, monomial_eq_zero_iff, sum_monomial_index, MulZeroClass.mul_zero, \u2190\n    tsub_add_eq_tsub_tsub, add_comm l k]\n  rw_mod_cast [nsmul_eq_mul]\n  congr 2\n  by_cases hikl : i < k + l\n  \u00b7 rw [choose_eq_zero_of_lt hikl, MulZeroClass.mul_zero]\n    by_cases hil : i < l\n    \u00b7 rw [choose_eq_zero_of_lt hil, MulZeroClass.mul_zero]\n    \u00b7 push_neg  at hil\n      rw [\u2190 tsub_lt_iff_right hil] at hikl\n      rw [choose_eq_zero_of_lt hikl, MulZeroClass.zero_mul]\n  push_neg  at hikl\n  apply @cast_injective \u211a\n  have h1 : l \u2264 i := le_of_add_le_right hikl\n  have h2 : k \u2264 i - l := le_tsub_of_add_le_right hikl\n  have h3 : k \u2264 k + l := le_self_add\n  have H : \u2200 n : \u2115, (n ! : \u211a) \u2260 0 := by exact_mod_cast factorial_ne_zero\n  -- why can't `field_simp` help me here?\n  simp only [cast_mul, cast_choose \u211a, h1, h2, h3, hikl, -one_div, -mul_eq_zero,\n    succ_sub_succ_eq_sub, add_tsub_cancel_right, add_tsub_cancel_left, field_simps]\n  rw [eq_div_iff_mul_eq, eq_comm, div_mul_eq_mul_div, eq_div_iff_mul_eq, \u2190 tsub_add_eq_tsub_tsub,\n    add_comm l k]\n  \u00b7 ring\n  all_goals apply_rules [mul_ne_zero, H]\n#align polynomial.hasse_deriv_comp Polynomial.hasseDeriv_comp\n-/\n\n/- warning: polynomial.nat_degree_hasse_deriv_le -> Polynomial.natDegree_hasseDeriv_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (p : Polynomial.{u1} R _inst_1) (n : Nat), LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 n) p)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (Polynomial.natDegree.{u1} R _inst_1 p) n)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (p : Polynomial.{u1} R _inst_1) (n : Nat), LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 n) p)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) (Polynomial.natDegree.{u1} R _inst_1 p) n)\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_hasse_deriv_le Polynomial.natDegree_hasseDeriv_le\u2093'. -/\ntheorem natDegree_hasseDeriv_le (p : R[X]) (n : \u2115) : natDegree (hasseDeriv n p) \u2264 natDegree p - n :=\n  by\n  classical\n    rw [hasse_deriv_apply, sum_def]\n    refine' (nat_degree_sum_le _ _).trans _\n    simp_rw [Function.comp, nat_degree_monomial]\n    rw [Finset.fold_ite, Finset.fold_const]\n    \u00b7 simp only [if_t_t, max_eq_right, zero_le', Finset.fold_max_le, true_and_iff, and_imp,\n        tsub_le_iff_right, mem_support_iff, Ne.def, Finset.mem_filter]\n      intro x hx hx'\n      have hxp : x \u2264 p.nat_degree := le_nat_degree_of_ne_zero hx\n      have hxn : n \u2264 x := by\n        contrapose! hx'\n        simp [Nat.choose_eq_zero_of_lt hx']\n      rwa [tsub_add_cancel_of_le (hxn.trans hxp)]\n    \u00b7 simp\n#align polynomial.nat_degree_hasse_deriv_le Polynomial.natDegree_hasseDeriv_le\n\n/- warning: polynomial.nat_degree_hasse_deriv -> Polynomial.natDegree_hasseDeriv is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroSMulDivisors.{0, u1} Nat R Nat.hasZero (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (AddMonoid.SMul.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))] (p : Polynomial.{u1} R _inst_1) (n : Nat), Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 n) p)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (Polynomial.natDegree.{u1} R _inst_1 p) n)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroSMulDivisors.{0, u1} Nat R (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.SMul.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))] (p : Polynomial.{u1} R _inst_1) (n : Nat), Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 n) p)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) (Polynomial.natDegree.{u1} R _inst_1 p) n)\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_hasse_deriv Polynomial.natDegree_hasseDeriv\u2093'. -/\ntheorem natDegree_hasseDeriv [NoZeroSMulDivisors \u2115 R] (p : R[X]) (n : \u2115) :\n    natDegree (hasseDeriv n p) = natDegree p - n :=\n  by\n  cases' lt_or_le p.nat_degree n with hn hn\n  \u00b7 simpa [hasse_deriv_eq_zero_of_lt_nat_degree, hn] using (tsub_eq_zero_of_le hn.le).symm\n  \u00b7 refine' map_nat_degree_eq_sub _ _\n    \u00b7 exact fun h => hasse_deriv_eq_zero_of_lt_nat_degree _ _\n    \u00b7\n      classical\n        simp only [ite_eq_right_iff, Ne.def, nat_degree_monomial, hasse_deriv_monomial]\n        intro k c c0 hh\n        -- this is where we use the `smul_eq_zero` from `no_zero_smul_divisors`\n        rw [\u2190 nsmul_eq_mul, smul_eq_zero, Nat.choose_eq_zero_iff] at hh\n        exact (tsub_eq_zero_of_le (Or.resolve_right hh c0).le).symm\n#align polynomial.nat_degree_hasse_deriv Polynomial.natDegree_hasseDeriv\n\nsection\n\nopen AddMonoidHom Finset.Nat\n\n/- warning: polynomial.hasse_deriv_mul -> Polynomial.hasseDeriv_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (f : Polynomial.{u1} R _inst_1) (g : Polynomial.{u1} R _inst_1), Eq.{succ u1} (Polynomial.{u1} R _inst_1) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) f g)) (Finset.sum.{u1, 0} (Polynomial.{u1} R _inst_1) (Prod.{0, 0} Nat Nat) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Finset.Nat.antidiagonal k) (fun (ij : Prod.{0, 0} Nat Nat) => HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (Prod.fst.{0, 0} Nat Nat ij)) f) (coeFn.{succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (fun (_x : LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) => (Polynomial.{u1} R _inst_1) -> (Polynomial.{u1} R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (Prod.snd.{0, 0} Nat Nat ij)) g)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (k : Nat) (f : Polynomial.{u1} R _inst_1) (g : Polynomial.{u1} R _inst_1), Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) f g)) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 k) (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) f g)) (Finset.sum.{u1, 0} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (Prod.{0, 0} Nat Nat) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (Semiring.toNonAssocSemiring.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (Polynomial.semiring.{u1} R _inst_1)))) (Finset.Nat.antidiagonal k) (fun (ij : Prod.{0, 0} Nat Nat) => HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) g) ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) f) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (Prod.fst.{0, 0} Nat Nat ij)) f) (FunLike.coe.{succ u1, succ u1, succ u1} (LinearMap.{u1, u1, u1, u1} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1))) (Polynomial.{u1} R _inst_1) (fun (_x : Polynomial.{u1} R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : Polynomial.{u1} R _inst_1) => Polynomial.{u1} R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, u1} R R (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) _inst_1 _inst_1 (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (Polynomial.module.{u1, u1} R _inst_1 R _inst_1 (Semiring.toModule.{u1} R _inst_1)) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Polynomial.hasseDeriv.{u1} R _inst_1 (Prod.snd.{0, 0} Nat Nat ij)) g)))\nCase conversion may be inaccurate. Consider using '#align polynomial.hasse_deriv_mul Polynomial.hasseDeriv_mul\u2093'. -/\ntheorem hasseDeriv_mul (f g : R[X]) :\n    hasseDeriv k (f * g) = \u2211 ij in antidiagonal k, hasseDeriv ij.1 f * hasseDeriv ij.2 g :=\n  by\n  let D k := (@hasse_deriv R _ k).toAddMonoidHom\n  let \u03a6 := @AddMonoidHom.mul R[X] _\n  show\n    (comp_hom (D k)).comp \u03a6 f g =\n      \u2211 ij : \u2115 \u00d7 \u2115 in antidiagonal k, ((comp_hom.comp ((comp_hom \u03a6) (D ij.1))).flip (D ij.2) f) g\n  simp only [\u2190 finset_sum_apply]\n  congr 2\n  clear f g\n  ext (m r n s) : 4\n  simp only [finset_sum_apply, coe_mul_left, coe_comp, flip_apply, comp_app, hasse_deriv_monomial,\n    LinearMap.toAddMonoidHom_coe, comp_hom_apply_apply, coe_mul, monomial_mul_monomial]\n  have aux :\n    \u2200 x : \u2115 \u00d7 \u2115,\n      x \u2208 antidiagonal k \u2192\n        monomial (m - x.1 + (n - x.2)) (\u2191(m.choose x.1) * r * (\u2191(n.choose x.2) * s)) =\n          monomial (m + n - k) (\u2191(m.choose x.1) * \u2191(n.choose x.2) * (r * s)) :=\n    by\n    intro x hx\n    rw [Finset.Nat.mem_antidiagonal] at hx\n    subst hx\n    by_cases hm : m < x.1\n    \u00b7\n      simp only [Nat.choose_eq_zero_of_lt hm, Nat.cast_zero, MulZeroClass.zero_mul,\n        monomial_zero_right]\n    by_cases hn : n < x.2\n    \u00b7\n      simp only [Nat.choose_eq_zero_of_lt hn, Nat.cast_zero, MulZeroClass.zero_mul,\n        MulZeroClass.mul_zero, monomial_zero_right]\n    push_neg  at hm hn\n    rw [tsub_add_eq_add_tsub hm, \u2190 add_tsub_assoc_of_le hn, \u2190 tsub_add_eq_tsub_tsub,\n      add_comm x.2 x.1, mul_assoc, \u2190 mul_assoc r, \u2190 (Nat.cast_commute _ r).Eq, mul_assoc, mul_assoc]\n  conv_rhs =>\n    apply_congr\n    skip\n    rw [aux _ H]\n  rw_mod_cast [\u2190 LinearMap.map_sum, \u2190 Finset.sum_mul, \u2190 Nat.add_choose_eq]\n#align polynomial.hasse_deriv_mul Polynomial.hasseDeriv_mul\n\nend\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Polynomial/HasseDeriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7232779982237572}}
{"text": "/-\nCredit to Markus Himmel for the corresponding file about `Module` in mathlib\n-/\nimport for_mathlib.AddCommGroup.epi\n\nopen category_theory\nopen category_theory.limits\nopen category_theory.limits.walking_parallel_pair\n\nuniverses u\n\nnamespace AddCommGroup\n\nvariables {M N : AddCommGroup.{u}} (f : M \u27f6 N)\n\n/-- The kernel cone induced by the concrete kernel. -/\ndef kernel_cone : kernel_fork f :=\n@kernel_fork.of_\u03b9 AddCommGroup _ _ M N f (of f.ker) (f.ker.subtype : of f.ker \u27f6 M) $\nby { ext1, cases x, assumption }\n\n/-- The kernel of a linear map is a kernel in the categorical sense. -/\ndef kernel_is_limit : is_limit (kernel_cone f) :=\nfork.is_limit.mk _\n  (\u03bb s : fork f 0, add_monoid_hom.cod_restrict (fork.\u03b9 s) f.ker $\n    \u03bb c, (add_monoid_hom.mem_ker _).2 $\n    by { rw [\u2190@function.comp_apply _ _ _ f s.\u03b9 c, \u2190coe_comp, fork.condition,\n      has_zero_morphisms.comp_zero (fork.\u03b9 s) N], refl })\n  (\u03bb s, by { ext, simp only [comp_apply, add_monoid_hom.cod_restrict_apply], refl })\n  (\u03bb s m h, add_monoid_hom.ext $ \u03bb x, subtype.ext_iff_val.2 $\n    have h\u2081 : (m \u226b (kernel_cone f).\u03c0.app zero).to_fun = (s.\u03c0.app zero).to_fun,\n      by { congr, exact h },\n    by convert @congr_fun _ _ _ _ h\u2081 x )\n\n/-- The cokernel cocone induced by the projection onto the quotient. -/\ndef cokernel_cocone : cokernel_cofork f :=\n@cokernel_cofork.of_\u03c0 AddCommGroup _ _ M N f (of $ N \u29f8 f.range) (quotient_add_group.mk' f.range) $\nby { ext1, simp only [comp_apply, quotient_add_group.mk'_apply, zero_apply,\n  quotient_add_group.eq_zero_iff, add_monoid_hom.mem_range, exists_apply_eq_apply], }\n\n/-- The projection onto the quotient is a cokernel in the categorical sense. -/\ndef cokernel_is_colimit : is_colimit (cokernel_cocone f) :=\ncofork.is_colimit.mk _\n  (\u03bb s : cofork f 0, quotient_add_group.lift _ s.\u03c0 $\n  by { rintro _ \u27e8x, rfl\u27e9, have := add_monoid_hom.congr_fun s.condition x,\n    simpa only [comp_apply, zero_apply, map_zero] using this, })\n  (\u03bb s, by { ext, simp only [comp_apply], refl })\n  (\u03bb s m h,\n  begin\n    let g : N \u27f6 (of $ N \u29f8 f.range) := (quotient_add_group.mk' f.range),\n    haveI : epi g := (epi_iff_range_eq_top _).mpr _,\n    swap, { ext \u27e8x\u27e9, simp only [add_monoid_hom.mem_range, quotient_add_group.mk'_apply,\n      add_subgroup.mem_top, iff_true], exact \u27e8x, rfl\u27e9 },\n    apply (cancel_epi g).1,\n    convert h,\n    ext, refl,\n  end)\n\n-- We now show this isomorphism commutes with the inclusion of the kernel into the source.\n\n-- TODO: the next two already exist: add `elementwise` to those lemmas in mathlib\n\n@[simp, elementwise] lemma kernel_iso_ker_inv_kernel_\u03b9 :\n  (kernel_iso_ker f).inv \u226b kernel.\u03b9 f = f.ker.subtype :=\nkernel_iso_ker_inv_comp_\u03b9 _\n\n@[simp, elementwise] lemma kernel_iso_ker_hom_ker_subtype :\n  (kernel_iso_ker f).hom \u226b f.ker.subtype = kernel.\u03b9 f :=\nkernel_iso_ker_hom_comp_subtype _\n\n/--\nThe categorical cokernel of a morphism in `Module`\nagrees with the usual module-theoretical quotient.\n-/\nnoncomputable def cokernel_iso_range_quotient : cokernel f \u2245 of (N \u29f8 f.range) :=\ncolimit.iso_colimit_cocone \u27e8_, cokernel_is_colimit f\u27e9\n\n-- We now show this isomorphism commutes with the projection of target to the cokernel.\n\n@[simp, elementwise] lemma cokernel_\u03c0_cokernel_iso_range_quotient_hom :\n  cokernel.\u03c0 f \u226b (cokernel_iso_range_quotient f).hom = quotient_add_group.mk' f.range :=\nby { convert colimit.iso_colimit_cocone_\u03b9_hom _ _; refl, }\n\n@[simp, elementwise] lemma range_mkq_cokernel_iso_range_quotient_inv :\n  (by exact quotient_add_group.mk' f.range : _) \u226b (cokernel_iso_range_quotient f).inv = cokernel.\u03c0 f :=\nby { convert colimit.iso_colimit_cocone_\u03b9_inv \u27e8_, cokernel_is_colimit f\u27e9 _; refl, }\n\nend AddCommGroup\n", "meta": {"author": "leanprover-community", "repo": "lean-liquid", "sha": "92f188bd17f34dbfefc92a83069577f708851aec", "save_path": "github-repos/lean/leanprover-community-lean-liquid", "path": "github-repos/lean/leanprover-community-lean-liquid/lean-liquid-92f188bd17f34dbfefc92a83069577f708851aec/src/for_mathlib/AddCommGroup/kernels.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7232604491225275}}
{"text": "import game.world_08_advanced_addition\nnamespace mynat\n\ntheorem mul_pos (a b : mynat) : a \u2260 0 \u2192 b \u2260 0 \u2192 a * b \u2260 0 := begin[nat_num_game]\n  intros anz bnz f,\n  cases b, {\n    apply bnz,\n    refl\n  }, {\n    rw mul_succ at f,\n    apply anz,\n    induction a,\n    refl, {\n      apply add_left_eq_zero,\n      rwa f,\n    }\n  }\nend\n\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero (a b : mynat) (h : a * b = 0) : a = 0 \u2228 b = 0 := begin[nat_num_game]\n  induction b, {\n    right,\n    refl\n  }, {\n    left,\n    rw mul_succ at h,\n    apply add_left_eq_zero,\n    apply h\n  }\nend\n\ntheorem mul_eq_zero_iff (a b : mynat): a * b = 0 \u2194 a = 0 \u2228 b = 0 := begin[nat_num_game]\n  split,\n  apply eq_zero_or_eq_zero_of_mul_eq_zero, {\n    intro or_eq_zero,\n    cases or_eq_zero,\n    rwa [or_eq_zero, zero_mul],\n    rwa [or_eq_zero, mul_zero],\n  }\nend\n\ntheorem mul_left_cancel (a b c : mynat) (ha : a \u2260 0) : a * b = a * c \u2192 b = c := begin[nat_num_game]\n  induction c generalizing b, {\n    rw mul_zero,\n    intro h,\n    cases eq_zero_or_eq_zero_of_mul_eq_zero _ _ h, {\n      exfalso,\n      exact ha h_1\n    }, exact h_1\n  }, {\n    intro eq,\n    cases b, {\n      rw mul_zero at eq,\n      exfalso,\n      apply ha,\n      symmetry at eq,\n      cases eq_zero_or_eq_zero_of_mul_eq_zero _ _ eq,\n      exact h, {\n        exfalso,\n        exact succ_ne_zero _ h,\n      }\n    },{\n      have hyp : b = c_n, {\n        apply c_ih,\n        rw mul_succ at eq,\n        rw mul_succ at eq,\n        apply add_right_cancel _ _ _ eq,\n      },\n      rwa hyp,\n    }\n  }\nend\n\nend mynat\n", "meta": {"author": "lacrosse", "repo": "natural_number_game", "sha": "400179cde1d3fcc9744901dabff98813ba2b544f", "save_path": "github-repos/lean/lacrosse-natural_number_game", "path": "github-repos/lean/lacrosse-natural_number_game/natural_number_game-400179cde1d3fcc9744901dabff98813ba2b544f/src/game/world_09_advanced_multiplication.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7232569557772481}}
{"text": "import data.polynomial.basic\nimport data.polynomial.eval\nimport data.real.basic\nimport algebra.ring.basic\nimport ring_theory.derivation\n\nnoncomputable theory\nopen finset\nopen_locale big_operators polynomial\nuniverses u v\nvariables {R : Type} {a b : R} {m n : \u2115} [field R] [nontrivial R]\n\nnamespace umbral_calculus\n\n  -- Describe binomial polynomial sequences\n  class binomial_polynomial_sequence (ps : \u2115 \u2192 R[X]) :=\n    (to_poly : \u2115 \u2192 R[X])\n    (degree_matches : \u2200 (n : \u2115), \u2191n = (to_poly n).degree)\n    (is_binomial : \u2200 (n : \u2115) (x y : R), (ps n).eval (x + y) = \n      \u2211 (k : \u2115) in range (n + 1), ((ps k).eval x) * ((ps (n - k)).eval y) * n.choose k)\n  \n  -- Define the shift operator\n  def shift_operator (ps : R[X]) : R[X] :=\n    polynomial.comp ps (polynomial.X + polynomial.C 1)\n\n  def shift_a_operator (a : R) (ps : R[X]) : R[X] :=\n    polynomial.comp ps (polynomial.X + polynomial.C a)\n\n  @[simp] lemma shift_x_by_a {a : R} :\n    shift_a_operator a polynomial.X = polynomial.X + polynomial.C a := \n      by rw [shift_a_operator, polynomial.X_comp]\n\n  @[simp] lemma shift_monomial_by_a {a : R} :\n    shift_a_operator a ((polynomial.X) ^ n) = (polynomial.X + polynomial.C a) ^ n := \n    by rw [shift_a_operator, polynomial.X_pow_comp]\n  \n  def shift_one_op_eq_shift_op :\n    (shift_operator : R[X] \u2192 R[X]) = shift_a_operator 1 :=\n  begin\n    ext,\n    rw [shift_operator, shift_a_operator],\n  end\n\n  theorem shift_ab_operator_add (a b : R) (p : R[X]) : \n    (shift_a_operator a) ((shift_a_operator b) p) = shift_a_operator (a + b) p :=\n  begin\n    repeat {rw shift_a_operator},\n    ext,\n    rw [polynomial.comp_assoc, polynomial.add_comp],\n    simp,\n    rw add_assoc,\n  end\n\n  def shift_ring_hom (a : R) : ring_hom R[X] R[X] :=\n  {\n    to_fun := shift_a_operator a,\n    map_one' := by rw [shift_a_operator, polynomial.one_comp],\n    map_mul' := begin\n      intros a b,\n      repeat {rw shift_a_operator},\n      simp,\n    end,\n    map_zero' := by rw [shift_a_operator, polynomial.zero_comp],\n    map_add' := begin\n      intros a b,\n      repeat {rw shift_a_operator},\n      simp,\n    end,\n  }\n\n  def shift_linear_map (a : R) : linear_map (shift_ring_hom a : R[X] \u2192+* R[X]) R[X] R[X] :=\n  {\n    to_fun := shift_ring_hom a,\n    map_add' := begin\n      intros x y,\n      repeat {rw shift_a_operator},\n      have := (shift_ring_hom a).map_add' x y,\n      simp,\n    end,\n    map_smul' := begin\n      intros x y,\n      repeat {rw shift_a_operator},\n      have := (shift_ring_hom a).map_mul' x y,\n      simp,\n    end,\n  }\n\n  -- Show that the single variable monomials indexed by power are a binomial polynomial sequence\n  instance monomial_is_bps : binomial_polynomial_sequence (\u03bb (n : \u2115), polynomial.monomial n (1 : \u211d)) :=\n  {\n    to_poly := (\u03bb (n : \u2115), polynomial.monomial n (1 : \u211d)),\n    degree_matches := begin\n      intro n,\n      simp,\n    end,\n    is_binomial := begin\n      intros n x y,\n      simp,\n      exact add_pow x y n,\n    end\n  }\n\n  class shift_invariant_op (op : R[X] \u2192+* R[X]) :=\n    (is_shift_invariant : \u2200 (a : R), ring_hom.comp \n      op (shift_ring_hom a) = ring_hom.comp (shift_ring_hom a) op)\n\n  -- The shift operators are shift invariant\n  instance shift_a_operator_is_shift_invariant_op (a : R) : \n    shift_invariant_op (shift_ring_hom a) :=\n  {\n    is_shift_invariant := begin\n      intros b,\n      repeat {rw shift_ring_hom},\n      repeat {rw ring_hom.comp},\n      simp,\n      repeat {rw function.comp},\n      ext,\n      repeat {rw shift_a_operator},\n      repeat {rw polynomial.comp_assoc},\n      repeat {rw polynomial.add_comp},\n      simp,\n      rw [add_assoc, add_comm (polynomial.C a), \u2190 add_assoc],\n    end,\n  }\n\n  class delta_op (op : R[X] \u2192+* R[X]) extends shift_invariant_op op :=\n    (is_delta : \u2203 (c : R), op polynomial.X = polynomial.C c \u2227 c \u2260 0)\n\n  /- This lemma specifically requires a ring structure on R \n     so that we can use the additive group property add_right_inj.\n     The previous theorems only require a semiring.\n  -/\n  lemma delta_constant_is_zero (op : R[X] \u2192+* R[X]) [delta_op op] :\n    \u2200 (a : R), op (polynomial.C a) = 0 :=\n  begin\n    intro a,\n    have q\u2081 := _inst_3.is_shift_invariant a,\n    have q\u2082 := _inst_3.is_delta,\n    cases q\u2082 with c q\u2083,\n    repeat {rw ring_hom.comp at q\u2081},\n    simp at q\u2081,\n    repeat {rw function.comp at q\u2081},\n    replace q\u2081 : (\u03bb (x : R[X]), op ((shift_ring_hom a) x)) (polynomial.X) = \n      (\u03bb (x : R[X]), (shift_ring_hom a) (op x)) (polynomial.X) := by rw q\u2081,\n    simp at q\u2081,\n    repeat {rw shift_ring_hom at q\u2081},\n    simp at q\u2081,\n    repeat {rw shift_a_operator at q\u2081},\n    rw q\u2083.1 at q\u2081,\n    rw polynomial.C_comp at q\u2081,\n    nth_rewrite_rhs 0 \u2190 add_zero (polynomial.C c) at q\u2081,\n    rw add_right_inj at q\u2081,\n    exact q\u2081,\n  end\n\n  lemma delta_op_comm_shift_pow (n : \u2115)\n    (op : R[X] \u2192+* R[X])\n    [delta_op op]\n    (a : R) :\n    op ((polynomial.X + polynomial.C a) ^ (n + 1)) =\n      shift_a_operator a (op polynomial.X ^ (n + 1)) :=\n  begin\n    have q' := _inst_3.is_shift_invariant a,\n    repeat {rw ring_hom.comp at q'},\n    simp at q',\n    repeat {rw function.comp at q'},\n    replace q' : (\u03bb (x : R[X]), op ((shift_ring_hom a) x)) (polynomial.X ^ (n + 1)) = \n      (\u03bb (x : R[X]), (shift_ring_hom a) (op x)) (polynomial.X ^ (n + 1)) := by rw q',\n    dsimp at q',\n    rw \u2190 shift_monomial_by_a,\n    repeat {rw shift_ring_hom at q'},\n    simp at q',\n    simp,\n    exact q',\n  end\n\n  lemma delta_op_is_linear_map (op : R[X] \u2192+* R[X]) [delta_op op] :\n    linear_map op R[X] R[X] :=\n  {\n    to_fun := op,\n    map_add' := begin\n      intros x y,\n      simp,\n    end,\n    map_smul' := begin\n      intros r x,\n      simp,\n    end,\n  }\n\n  instance delta_op.has_smul (op : R[X] \u2192+* R[X]) [delta_op op] : has_smul R R[X] :=\n  {\n    smul := (\u03bb (r: R) (x : R[X]), polynomial.C r * op x),\n  }\n\n  theorem delta_op.is_derivation (op : R[X] \u2192+* R[X]) [delta_op op] \n    (n : \u2115) : (op (polynomial.X ^ (n + 1))).degree = \n    ((op polynomial.X ^ n) * polynomial.X + polynomial.X ^ (n + 1) * op polynomial.X).degree \n    :=\n  begin\n    have q\u2081 := _inst_3.is_delta,\n    cases q\u2081 with a q\u2081,\n    cases q\u2081 with b c,\n  /-\n    induction n with n ih,\n    {\n      simp,\n      have q\u2081 := _inst_3.is_delta,\n      cases q\u2081 with a h,\n      have q\u2082 : (polynomial.X : R[X]).degree = 1 := polynomial.degree_X,\n      rw h.1,\n      rw polynomial.degree_C h.2,\n\n      /-\n      have : (0 : with_bot \u2115) < (polynomial.X : R[X]).degree :=\n      begin\n        have : 0 < 1, by norm_num,\n        rw \u2190 with_bot.coe_lt_coe at this,\n        simp,\n        exact this,\n      end,\n      rw [h.1, polynomial.degree_add_C this],\n      -/\n    },\n    {\n      \n    },\n  -/\n  end\n\n  lemma delta_decreases_degree (n : \u2115) (op : R[X] \u2192+* R[X]) [delta_op op] \n    : (op (polynomial.X ^ (n + 1))).degree = \u2191n :=\n  begin\n    induction n with n ih,\n    {\n      simp,\n      have q\u2081 := _inst_3.is_delta,\n      cases q\u2081 with a q\u2081,\n      have q\u2082 := q\u2081.1,\n      have := congr_arg polynomial.degree q\u2082,\n      rw polynomial.degree_C q\u2081.2 at this,\n      exact this,\n    },\n    {\n      \n    },\n\n/-\n    have q\u2081 := _inst_3.is_delta,\n    cases q\u2081 with a q\u2081,\n    have := add_pow (polynomial.C a) polynomial.X (n + 1),\n    have q\u2082 : op ((polynomial.X + polynomial.C a) ^ (n + 1)) = op (\u2211 (m : \u2115) in range (n + 1 + 1), polynomial.C a ^ m * polynomial.X ^ (n + 1 - m) * \u2191((n + 1).choose m)) := begin\n      rw add_comm,\n      rw this,\n    end,\n    clear this,\n    -- linearity of ring homomorphisms\n    rw ring_hom.map_sum at q\u2082,\n    /-simp at q\u2082,\n    have : a = (polynomial.X : R[X]).eval a, by simp,\n    rw this at q\u2082,-/\n\n    have := delta_op_comm_shift_pow n op a,\n    rw this at q\u2082,\n-/\n  /-\n    have q\u2083 : ((op polynomial.X + op (polynomial.C a)) ^ (n + 1)).eval 0 = (\u2211 (x : \u2115) in range (n + 1 + 1), op polynomial.X ^ x * op (polynomial.C a) ^ (n + 1 - x) * \u2191((n + 1).choose x)).eval 0, by rw q\u2082,\n    simp at q\u2083,\n    rw [q\u2081.1, polynomial.eval_C, delta_constant_is_zero, polynomial.eval_zero, add_zero] at q\u2083,\n  -/\n\n/-\n    rw delta_constant_is_zero at q\u2082,\n    simp at q\u2082,\n-/\n/-\n    have := add_pow polynomial.X (polynomial.C a) (n + 1),\n    have q\u2082 : op ((polynomial.X + polynomial.C a) ^ (n + 1)) = op (\u2211 (m : \u2115) in range (n + 1 + 1), polynomial.X ^ m * polynomial.C a ^ (n + 1 - m) * \u2191((n + 1).choose m)), by rw this,\n    clear this,\n    -- linearity of ring homomorphisms\n    rw ring_hom.map_sum at q\u2082,\n    simp at q\u2082,\n    rw delta_constant_is_zero at q\u2082,\n    simp at q\u2082,\n\n    have q\u2083 := delta_op_comm_shift_pow n op a,\n    have q\u2084 : (0 : R[X]) ^ 0 = 1, by norm_num,\n-/\n  end\n\nend umbral_calculus", "meta": {"author": "mikesha2", "repo": "identitylib", "sha": "6fb9c7913b0b85fafb14f1f34bca0f7af47fa190", "save_path": "github-repos/lean/mikesha2-identitylib", "path": "github-repos/lean/mikesha2-identitylib/identitylib-6fb9c7913b0b85fafb14f1f34bca0f7af47fa190/src/umbral_calculus.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7232569498511414}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n-/\nimport tactic.ring\nimport data.pnat.prime\n\n/-!\n# Euclidean algorithm for \u2115\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file sets up a version of the Euclidean algorithm that only works with natural numbers.\nGiven `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold:\n* `a = (w + x) d`\n* `b = (y + z) d`\n* `w * z = x * y + 1`\n`d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime.\n\nThis story is closely related to the structure of SL\u2082(\u2115) (as a free monoid on two generators) and\nthe theory of continued fractions.\n\n## Main declarations\n\n* `xgcd_type`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp`\n  `zp`, `ap`, `bp` are the variables getting changed through the algorithm.\n* `is_special`: States `wp * zp = x * y + 1`\n* `is_reduced`: States `ap = a \u2227 bp = b`\n\n## Notes\n\nSee `nat.xgcd` for a very similar algorithm allowing values in `\u2124`.\n-/\n\nopen nat\n\nnamespace pnat\n\n/-- A term of xgcd_type is a system of six naturals.  They should\n be thought of as representing the matrix\n [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]\n together with the vector [a, b] = [ap + 1, bp + 1].\n-/\n@[derive inhabited]\nstructure xgcd_type :=\n(wp x y zp ap bp : \u2115)\n\nnamespace xgcd_type\n\nvariable (u : xgcd_type)\n\ninstance : has_sizeof xgcd_type := \u27e8\u03bb u, u.bp\u27e9\n\n/-- The has_repr instance converts terms to strings in a way that\n reflects the matrix/vector interpretation as above. -/\ninstance : has_repr xgcd_type :=\n\u27e8\u03bb u, \"[[[\" ++ (repr (u.wp + 1)) ++ \", \" ++ (repr u.x) ++\n      \"], [\" ++ (repr u.y) ++ \", \" ++ (repr (u.zp + 1)) ++ \"]], [\" ++\n      (repr (u.ap + 1)) ++ \", \" ++ (repr (u.bp + 1)) ++ \"]]\"\u27e9\n\ndef mk' (w : \u2115+) (x : \u2115) (y : \u2115) (z : \u2115+) (a : \u2115+) (b : \u2115+) : xgcd_type :=\nmk w.val.pred x y z.val.pred a.val.pred b.val.pred\n\ndef w : \u2115+ := succ_pnat u.wp\ndef z : \u2115+ := succ_pnat u.zp\ndef a : \u2115+ := succ_pnat u.ap\ndef b : \u2115+ := succ_pnat u.bp\ndef r : \u2115 := (u.ap + 1) % (u.bp + 1)\ndef q : \u2115 := (u.ap + 1) / (u.bp + 1)\ndef qp : \u2115 := u.q - 1\n\n/-- The map v gives the product of the matrix\n [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]\n and the vector [a, b] = [ap + 1, bp + 1].  The map\n vp gives [sp, tp] such that v = [sp + 1, tp + 1].\n-/\ndef vp : \u2115 \u00d7 \u2115 :=\n\u27e8 u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp,\n  u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp \u27e9\n\ndef v : \u2115 \u00d7 \u2115 := \u27e8u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.b\u27e9\ndef succ\u2082 (t : \u2115 \u00d7 \u2115) : \u2115 \u00d7 \u2115 := \u27e8t.1.succ, t.2.succ\u27e9\n\ntheorem v_eq_succ_vp : u.v = succ\u2082 u.vp :=\nby { ext; dsimp [v, vp, w, z, a, b, succ\u2082];\n     repeat { rw [nat.succ_eq_add_one] }; ring }\n\n/-- is_special holds if the matrix has determinant one. -/\ndef is_special : Prop := u.wp + u.zp + u.wp * u.zp = u.x * u.y\ndef is_special' : Prop := u.w * u.z = succ_pnat (u.x * u.y)\n\ntheorem is_special_iff : u.is_special \u2194 u.is_special' :=\nbegin\n  dsimp [is_special, is_special'],\n  split; intro h,\n  { apply eq, dsimp [w, z, succ_pnat], rw [\u2190 h],\n    repeat { rw [nat.succ_eq_add_one] }, ring },\n  { apply nat.succ.inj,\n    replace h := congr_arg (coe : \u2115+ \u2192 \u2115) h,\n    rw [mul_coe, w, z] at h,\n    repeat { rw [succ_pnat_coe, nat.succ_eq_add_one] at h },\n    repeat { rw [nat.succ_eq_add_one] }, rw [\u2190 h], ring }\nend\n\n/-- is_reduced holds if the two entries in the vector are the\n same.  The reduction algorithm will produce a system with this\n property, whose product vector is the same as for the original\n system. -/\ndef is_reduced : Prop := u.ap = u.bp\ndef is_reduced' : Prop := u.a = u.b\n\ntheorem is_reduced_iff : u.is_reduced \u2194 u.is_reduced' := succ_pnat_inj.symm\n\ndef flip : xgcd_type :=\n{ wp := u.zp, x := u.y, y := u.x, zp := u.wp, ap := u.bp, bp := u.ap }\n\n@[simp] theorem flip_w : (flip u).w = u.z := rfl\n@[simp] theorem flip_x : (flip u).x = u.y := rfl\n@[simp] theorem flip_y : (flip u).y = u.x := rfl\n@[simp] theorem flip_z : (flip u).z = u.w := rfl\n@[simp] theorem flip_a : (flip u).a = u.b := rfl\n@[simp] theorem flip_b : (flip u).b = u.a := rfl\n\ntheorem flip_is_reduced : (flip u).is_reduced \u2194 u.is_reduced :=\nby { dsimp [is_reduced, flip], split; intro h; exact h.symm }\n\ntheorem flip_is_special : (flip u).is_special \u2194 u.is_special :=\nby { dsimp [is_special, flip], rw[mul_comm u.x, mul_comm u.zp, add_comm u.zp] }\n\ntheorem flip_v : (flip u).v = (u.v).swap :=\nby { dsimp [v], ext, { simp only, ring }, { simp only, ring } }\n\n/-- Properties of division with remainder for a / b.  -/\ntheorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 :=\nnat.mod_add_div (u.ap + 1) (u.bp + 1)\n\ntheorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 :=\nbegin\n  by_cases hq : u.q = 0,\n  { let h := u.rq_eq, rw [hr, hq, mul_zero, add_zero] at h, cases h },\n  { exact (nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero hq)).symm }\nend\n\n/-- The following function provides the starting point for\n our algorithm.  We will apply an iterative reduction process\n to it, which will produce a system satisfying is_reduced.\n The gcd can be read off from this final system.\n-/\ndef start (a b : \u2115+) : xgcd_type := \u27e80, 0, 0, 0, a - 1, b - 1\u27e9\n\ntheorem start_is_special (a b : \u2115+) : (start a b).is_special :=\nby { dsimp [start, is_special], refl }\n\ntheorem start_v (a b : \u2115+) : (start a b).v = \u27e8a, b\u27e9 :=\nbegin\n  dsimp [start, v, xgcd_type.a, xgcd_type.b, w, z],\n  rw [one_mul, one_mul, zero_mul, zero_mul, zero_add, add_zero],\n  rw [\u2190 nat.pred_eq_sub_one, \u2190 nat.pred_eq_sub_one],\n  rw [nat.succ_pred_eq_of_pos a.pos, nat.succ_pred_eq_of_pos b.pos]\nend\n\ndef finish : xgcd_type :=\nxgcd_type.mk u.wp ((u.wp + 1) * u.qp + u.x) u.y (u.y * u.qp + u.zp) u.bp u.bp\n\ntheorem finish_is_reduced : u.finish.is_reduced :=\nby { dsimp [is_reduced], refl }\n\ntheorem finish_is_special (hs : u.is_special) : u.finish.is_special :=\nbegin\n  dsimp [is_special, finish] at hs \u22a2,\n  rw [add_mul _ _ u.y, add_comm _ (u.x * u.y), \u2190 hs],\n  ring\nend\n\ntheorem finish_v (hr : u.r = 0) : u.finish.v = u.v :=\nbegin\n  let ha : u.r + u.b * u.q = u.a := u.rq_eq,\n  rw [hr, zero_add] at ha,\n  ext,\n  { change (u.wp + 1) * u.b + ((u.wp + 1) * u.qp + u.x) * u.b = u.w * u.a + u.x * u.b,\n    have : u.wp + 1 = u.w := rfl, rw [this, \u2190 ha, u.qp_eq hr], ring },\n  { change u.y * u.b + (u.y * u.qp + u.z) * u.b = u.y * u.a + u.z * u.b,\n    rw [\u2190 ha, u.qp_eq hr], ring }\nend\n\n/-- This is the main reduction step, which is used when u.r \u2260 0, or\n equivalently b does not divide a. -/\ndef step : xgcd_type :=\nxgcd_type.mk (u.y * u.q + u.zp) u.y ((u.wp + 1) * u.q + u.x) u.wp u.bp (u.r - 1)\n\n/-- We will apply the above step recursively.  The following result\n is used to ensure that the process terminates. -/\ntheorem step_wf (hr : u.r \u2260 0) : sizeof u.step < sizeof u :=\nbegin\n  change u.r - 1 < u.bp,\n  have h\u2080 : (u.r - 1) + 1 = u.r := nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero hr),\n  have h\u2081 : u.r < u.bp + 1 := nat.mod_lt (u.ap + 1) u.bp.succ_pos,\n  rw[\u2190 h\u2080] at h\u2081,\n  exact lt_of_succ_lt_succ h\u2081,\nend\n\ntheorem step_is_special (hs : u.is_special) : u.step.is_special :=\nbegin\n  dsimp [is_special, step] at hs \u22a2,\n  rw [mul_add, mul_comm u.y u.x, \u2190 hs],\n  ring\nend\n\n/-- The reduction step does not change the product vector. -/\ntheorem step_v (hr : u.r \u2260 0) : u.step.v = (u.v).swap :=\nbegin\n  let ha : u.r + u.b * u.q = u.a := u.rq_eq,\n  let hr : (u.r - 1) + 1 = u.r :=\n    (add_comm _ 1).trans (add_tsub_cancel_of_le (nat.pos_of_ne_zero hr)),\n  ext,\n  { change ((u.y * u.q + u.z) * u.b + u.y * (u.r - 1 + 1) : \u2115) = u.y * u.a + u.z * u.b,\n    rw [\u2190 ha, hr], ring },\n  { change ((u.w * u.q + u.x) * u.b + u.w * (u.r - 1 + 1) : \u2115) = u.w * u.a + u.x * u.b,\n    rw [\u2190 ha, hr], ring }\nend\n\n/-- We can now define the full reduction function, which applies\n step as long as possible, and then applies finish. Note that the\n \"have\" statement puts a fact in the local context, and the\n equation compiler uses this fact to help construct the full\n definition in terms of well-founded recursion.  The same fact\n needs to be introduced in all the inductive proofs of properties\n given below. -/\ndef reduce : xgcd_type \u2192 xgcd_type\n| u := dite (u.r = 0)\n    (\u03bb h, u.finish)\n    (\u03bb h, have sizeof u.step < sizeof u, from u.step_wf h,\n     flip (reduce u.step))\n\ntheorem reduce_a {u : xgcd_type} (h : u.r = 0) :\nu.reduce = u.finish := by { rw [reduce], simp only, rw [if_pos h] }\n\ntheorem reduce_b {u : xgcd_type} (h : u.r \u2260 0) :\nu.reduce = u.step.reduce.flip := by { rw [reduce], simp only, rw [if_neg h, step] }\n\ntheorem reduce_reduced : \u2200 (u : xgcd_type), u.reduce.is_reduced\n| u := dite (u.r = 0) (\u03bb h, by { rw [reduce_a h], exact u.finish_is_reduced })\n    (\u03bb h,  have sizeof u.step < sizeof u, from u.step_wf h,\n     by { rw [reduce_b h, flip_is_reduced], apply reduce_reduced })\n\ntheorem reduce_reduced' (u : xgcd_type) : u.reduce.is_reduced' :=\n(is_reduced_iff _).mp u.reduce_reduced\n\ntheorem reduce_special : \u2200 (u : xgcd_type), u.is_special \u2192 u.reduce.is_special\n| u := dite (u.r = 0)\n    (\u03bb h hs, by { rw [reduce_a h], exact u.finish_is_special hs })\n    (\u03bb h hs, have sizeof u.step < sizeof u, from u.step_wf h,\n     by { rw [reduce_b h],\n          exact (flip_is_special _).mpr (reduce_special _ (u.step_is_special hs)) })\n\ntheorem reduce_special' (u : xgcd_type) (hs : u.is_special) : u.reduce.is_special' :=\n(is_special_iff _).mp (u.reduce_special hs)\n\ntheorem reduce_v : \u2200 (u : xgcd_type), u.reduce.v = u.v\n| u := dite (u.r = 0)\n (\u03bb h, by {rw[reduce_a h, finish_v u h]})\n (\u03bb h, have sizeof u.step < sizeof u, from u.step_wf h,\n       by { rw[reduce_b h, flip_v, reduce_v (step u), step_v u h, prod.swap_swap] })\n\nend xgcd_type\n\nsection gcd\n\nvariables (a b : \u2115+)\n\ndef xgcd : xgcd_type := (xgcd_type.start a b).reduce\n\ndef gcd_d : \u2115+ := (xgcd a b).a\ndef gcd_w : \u2115+ := (xgcd a b).w\ndef gcd_x : \u2115  := (xgcd a b).x\ndef gcd_y : \u2115  := (xgcd a b).y\ndef gcd_z : \u2115+ := (xgcd a b).z\n\ndef gcd_a' : \u2115+ := succ_pnat ((xgcd a b).wp + (xgcd a b).x)\ndef gcd_b' : \u2115+ := succ_pnat ((xgcd a b).y + (xgcd a b).zp)\n\ntheorem gcd_a'_coe : ((gcd_a' a b) : \u2115) = (gcd_w a b) + (gcd_x a b) :=\nby { dsimp [gcd_a', gcd_x, gcd_w, xgcd_type.w],\n     rw [nat.succ_eq_add_one, nat.succ_eq_add_one, add_right_comm] }\n\ntheorem gcd_b'_coe : ((gcd_b' a b) : \u2115) = (gcd_y a b) + (gcd_z a b) :=\nby { dsimp [gcd_b', gcd_y, gcd_z, xgcd_type.z],\n     rw [nat.succ_eq_add_one, nat.succ_eq_add_one, add_assoc] }\n\ntheorem gcd_props :\n let d := gcd_d a b,\n  w := gcd_w a b, x := gcd_x a b, y := gcd_y a b, z := gcd_z a b,\n  a' := gcd_a' a b, b' := gcd_b' a b in\n (w * z = succ_pnat (x * y) \u2227\n  (a = a' * d) \u2227 (b = b' * d) \u2227\n  z * a' = succ_pnat (x * b') \u2227 w * b' = succ_pnat (y * a') \u2227\n  (z * a : \u2115) = x * b + d \u2227 (w * b : \u2115) = y * a + d\n ) :=\nbegin\n  intros,\n  let u := (xgcd_type.start a b),\n  let ur := u.reduce,\n  have ha : d = ur.a := rfl,\n  have hb : d = ur.b := u.reduce_reduced',\n  have ha' : (a' : \u2115) = w + x := gcd_a'_coe a b,\n  have hb' : (b' : \u2115) = y + z := gcd_b'_coe a b,\n  have hdet : w * z = succ_pnat (x * y) := u.reduce_special' rfl,\n  split, exact hdet,\n  have hdet' : ((w * z) : \u2115) = x * y + 1 :=\n    by { rw [\u2190 mul_coe, hdet, succ_pnat_coe] },\n  have huv : u.v = \u27e8a, b\u27e9 := (xgcd_type.start_v a b),\n  let hv : prod.mk (w * d + x * ur.b : \u2115) (y * d + z * ur.b : \u2115) = \u27e8a, b\u27e9 :=\n   u.reduce_v.trans (xgcd_type.start_v a b),\n  rw [\u2190 hb, \u2190 add_mul, \u2190 add_mul, \u2190 ha', \u2190 hb'] at hv,\n  have ha'' : (a : \u2115) = a' * d := (congr_arg prod.fst hv).symm,\n  have hb'' : (b : \u2115) = b' * d := (congr_arg prod.snd hv).symm,\n  split, exact eq ha'', split, exact eq hb'',\n  have hza' : (z * a' : \u2115) = x * b' + 1,\n  by { rw [ha', hb', mul_add, mul_add, mul_comm (z : \u2115), hdet'], ring },\n  have hwb' : (w * b' : \u2115) = y * a' + 1,\n  by { rw [ha', hb', mul_add, mul_add, hdet'], ring },\n  split,\n  { apply eq, rw [succ_pnat_coe, nat.succ_eq_add_one, mul_coe, hza'] },\n  split,\n  { apply eq, rw [succ_pnat_coe, nat.succ_eq_add_one, mul_coe, hwb'] },\n  rw [ha'', hb''], repeat { rw [\u2190 mul_assoc] }, rw [hza', hwb'],\n  split; ring,\nend\n\ntheorem gcd_eq : gcd_d a b = gcd a b :=\nbegin\n  rcases gcd_props a b with \u27e8h\u2080, h\u2081, h\u2082, h\u2083, h\u2084, h\u2085, h\u2086\u27e9,\n  apply dvd_antisymm,\n  { apply dvd_gcd,\n    exact dvd.intro (gcd_a' a b) (h\u2081.trans (mul_comm _ _)).symm,\n    exact dvd.intro (gcd_b' a b) (h\u2082.trans (mul_comm _ _)).symm},\n  { have h\u2087 : (gcd a b : \u2115) \u2223 (gcd_z a b) * a :=\n      (nat.gcd_dvd_left a b).trans (dvd_mul_left _ _),\n    have h\u2088 : (gcd a b : \u2115) \u2223 (gcd_x a b) * b :=\n      (nat.gcd_dvd_right a b).trans (dvd_mul_left _ _),\n    rw[h\u2085] at h\u2087, rw dvd_iff,\n    exact (nat.dvd_add_iff_right h\u2088).mpr h\u2087,}\nend\n\ntheorem gcd_det_eq :\n  (gcd_w a b) * (gcd_z a b) = succ_pnat ((gcd_x a b) * (gcd_y a b)) :=\n(gcd_props a b).1\n\n\n\ntheorem gcd_b_eq : b = (gcd_b' a b) * (gcd a b) :=\n(gcd_eq a b) \u25b8 (gcd_props a b).2.2.1\n\ntheorem gcd_rel_left' :\n  (gcd_z a b) * (gcd_a' a b) = succ_pnat ((gcd_x a b) * (gcd_b' a b)) :=\n(gcd_props a b).2.2.2.1\n\ntheorem gcd_rel_right' :\n  (gcd_w a b) * (gcd_b' a b) = succ_pnat ((gcd_y a b) * (gcd_a' a b)) :=\n(gcd_props a b).2.2.2.2.1\n\ntheorem gcd_rel_left :\n  ((gcd_z a b) * a : \u2115) = (gcd_x a b) * b + (gcd a b) :=\n(gcd_eq a b) \u25b8 (gcd_props a b).2.2.2.2.2.1\n\ntheorem gcd_rel_right :\n  ((gcd_w a b) * b : \u2115) = (gcd_y a b) * a + (gcd a b) :=\n(gcd_eq a b) \u25b8 (gcd_props a b).2.2.2.2.2.2\n\nend gcd\nend pnat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/pnat/xgcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.723256944912833}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport category_theory.elements\nimport category_theory.is_connected\nimport category_theory.single_obj\nimport group_theory.group_action.quotient\nimport group_theory.semidirect_product\n\n/-!\n# Actions as functors and as categories\n\nFrom a multiplicative action M \u21bb X, we can construct a functor from M to the category of\ntypes, mapping the single object of M to X and an element `m : M` to map `X \u2192 X` given by\nmultiplication by `m`.\n  This functor induces a category structure on X -- a special case of the category of elements.\nA morphism `x \u27f6 y` in this category is simply a scalar `m : M` such that `m \u2022 x = y`. In the case\nwhere M is a group, this category is a groupoid -- the `action groupoid'.\n-/\n\nopen mul_action semidirect_product\nnamespace category_theory\n\nuniverses u\n\nvariables (M : Type*) [monoid M] (X : Type u) [mul_action M X]\n\n/-- A multiplicative action M \u21bb X viewed as a functor mapping the single object of M to X\n  and an element `m : M` to the map `X \u2192 X` given by multiplication by `m`. -/\n@[simps]\ndef action_as_functor : single_obj M \u2964 Type u :=\n{ obj := \u03bb _, X,\n  map := \u03bb _ _, (\u2022),\n  map_id' := \u03bb _, funext $ mul_action.one_smul,\n  map_comp' := \u03bb _ _ _ f g, funext $ \u03bb x, (smul_smul g f x).symm }\n\n/-- A multiplicative action M \u21bb X induces a category strucure on X, where a morphism\n from x to y is a scalar taking x to y. Due to implementation details, the object type\n of this category is not equal to X, but is in bijection with X. -/\n@[derive category]\ndef action_category := (action_as_functor M X).elements\n\nnamespace action_category\n\n/-- The projection from the action category to the monoid, mapping a morphism to its\n  label. -/\ndef \u03c0 : action_category M X \u2964 single_obj M :=\ncategory_of_elements.\u03c0 _\n\n@[simp]\nlemma \u03c0_map (p q : action_category M X) (f : p \u27f6 q) : (\u03c0 M X).map f = f.val := rfl\n\n@[simp]\nlemma \u03c0_obj (p : action_category M X) : (\u03c0 M X).obj p = single_obj.star M :=\nunit.ext\n\nvariables {M X}\n/-- The canonical map `action_category M X \u2192 X`. It is given by `\u03bb x, x.snd`, but\n  has a more explicit type. -/\nprotected def back : action_category M X \u2192 X :=\n\u03bb x, x.snd\n\ninstance : has_coe_t X (action_category M X) :=\n\u27e8\u03bb x, \u27e8(), x\u27e9\u27e9\n\n@[simp] lemma coe_back (x : X) : (\u2191x : action_category M X).back = x := rfl\n@[simp] lemma back_coe (x : action_category M X) : \u2191(x.back) = x := by ext; refl\n\nvariables (M X)\n\n/-- An object of the action category given by M \u21bb X corresponds to an element of X. -/\ndef obj_equiv : X \u2243 action_category M X :=\n{ to_fun := coe,\n  inv_fun := \u03bb x, x.back,\n  left_inv := coe_back,\n  right_inv := back_coe }\n\nlemma hom_as_subtype (p q : action_category M X) :\n  (p \u27f6 q) = { m : M // m \u2022 p.back = q.back } := rfl\n\ninstance [inhabited X] : inhabited (action_category M X) := \u27e8show X, from default\u27e9\n\ninstance [nonempty X] : nonempty (action_category M X) :=\nnonempty.map (obj_equiv M X) infer_instance\n\nvariables {X} (x : X)\n/-- The stabilizer of a point is isomorphic to the endomorphism monoid at the\n  corresponding point. In fact they are definitionally equivalent. -/\ndef stabilizer_iso_End : stabilizer.submonoid M x \u2243* End (\u2191x : action_category M X) :=\nmul_equiv.refl _\n\n@[simp]\nlemma stabilizer_iso_End_apply (f : stabilizer.submonoid M x) :\n  (stabilizer_iso_End M x).to_fun f = f := rfl\n\n@[simp]\nlemma stabilizer_iso_End_symm_apply (f : End _) :\n  (stabilizer_iso_End M x).inv_fun f = f := rfl\n\nvariables {M X}\n\n@[simp] protected \n\n@[simp] protected lemma comp_val {x y z : action_category M X}\n  (f : x \u27f6 y) (g : y \u27f6 z) : (f \u226b g).val = g.val * f.val := rfl\n\ninstance [is_pretransitive M X] [nonempty X] : is_connected (action_category M X) :=\nzigzag_is_connected $ \u03bb x y, relation.refl_trans_gen.single $ or.inl $\n  nonempty_subtype.mpr (show _, from exists_smul_eq M x.back y.back)\n\nsection group\n\nvariables {G : Type*} [group G] [mul_action G X]\n\nnoncomputable instance : groupoid (action_category G X) :=\ncategory_theory.groupoid_of_elements _\n\n/-- Any subgroup of `G` is a vertex group in its action groupoid. -/\ndef End_mul_equiv_subgroup (H : subgroup G) :\n  End (obj_equiv G (G \u29f8 H) \u2191(1 : G)) \u2243* H :=\nmul_equiv.trans\n  (stabilizer_iso_End G ((1 : G) : G \u29f8 H)).symm\n  (mul_equiv.subgroup_congr $ stabilizer_quotient H)\n\n/-- A target vertex `t` and a scalar `g` determine a morphism in the action groupoid. -/\ndef hom_of_pair (t : X) (g : G) : \u2191(g\u207b\u00b9 \u2022 t) \u27f6 (t : action_category G X) :=\nsubtype.mk g (smul_inv_smul g t)\n\n@[simp] lemma hom_of_pair.val (t : X) (g : G) : (hom_of_pair t g).val = g := rfl\n\n/-- Any morphism in the action groupoid is given by some pair. -/\nprotected def cases {P : \u03a0 \u2983a b : action_category G X\u2984, (a \u27f6 b) \u2192 Sort*}\n  (hyp : \u2200 t g, P (hom_of_pair t g)) \u2983a b\u2984 (f : a \u27f6 b) : P f :=\nbegin\n  refine cast _ (hyp b.back f.val),\n  rcases a with \u27e8\u27e8\u27e9, a : X\u27e9,\n  rcases b with \u27e8\u27e8\u27e9, b : X\u27e9,\n  rcases f with \u27e8g : G, h : g \u2022 a = b\u27e9,\n  cases (inv_smul_eq_iff.mpr h.symm),\n  refl\nend\n\nvariables {H : Type*} [group H]\n\n/-- Given `G` acting on `X`, a functor from the corresponding action groupoid to a group `H`\n    can be curried to a group homomorphism `G \u2192* (X \u2192 H) \u22ca G`. -/\n@[simps] def curry (F : action_category G X \u2964 single_obj H) :\n  G \u2192* (X \u2192 H) \u22ca[mul_aut_arrow] G :=\nhave F_map_eq : \u2200 {a b} {f : a \u27f6 b}, F.map f = (F.map (hom_of_pair b.back f.val) : H) :=\n  action_category.cases (\u03bb _ _, rfl),\n{ to_fun := \u03bb g, \u27e8\u03bb b, F.map (hom_of_pair b g), g\u27e9,\n  map_one' := by { congr, funext, exact F_map_eq.symm.trans (F.map_id b) },\n  map_mul' := begin\n    intros g h,\n    congr, funext,\n    exact F_map_eq.symm.trans (F.map_comp (hom_of_pair (g\u207b\u00b9 \u2022 b) h) (hom_of_pair b g)),\n  end }\n\n/-- Given `G` acting on `X`, a group homomorphism `\u03c6 : G \u2192* (X \u2192 H) \u22ca G` can be uncurried to\n    a functor from the action groupoid to `H`, provided that `\u03c6 g = (_, g)` for all `g`. -/\n@[simps] def uncurry (F : G \u2192* (X \u2192 H) \u22ca[mul_aut_arrow] G) (sane : \u2200 g, (F g).right = g) :\n  action_category G X \u2964 single_obj H :=\n{ obj := \u03bb _, (),\n  map := \u03bb a b f, ((F f.val).left b.back),\n  map_id' := by { intro x, rw [action_category.id_val, F.map_one], refl },\n  map_comp' := begin\n    intros x y z f g, revert y z g,\n    refine action_category.cases _,\n    simp [single_obj.comp_as_mul, sane],\n  end }\n\nend group\n\nend action_category\nend category_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/category_theory/action.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7232569271345121}}
{"text": "structure Category :=\n  ( Obj : Type )\n  ( Hom : Obj \u2192 Obj \u2192 Type )\n  ( identity : \u03a0 X : Obj, Hom X X )\n  ( compose  : \u03a0 { X Y Z : Obj }, Hom X Y \u2192 Hom Y Z \u2192 Hom X Z )\n    \nstructure Functor (C : Category) (D : Category) :=\n  (onObjects   : C.Obj \u2192 D.Obj)\n  (onMorphisms : \u03a0 { X Y : C.Obj },\n                C.Hom X Y \u2192 D.Hom (onObjects X) (onObjects Y))\n\ndefinition ProductCategory (C D : Category) :\n  Category :=\n  {\n    Obj      := C.Obj \u00d7 D.Obj,\n    Hom      := (\u03bb X Y : C.Obj \u00d7 D.Obj, C.Hom (X.fst) (Y.fst) \u00d7 D.Hom (X.snd) (Y.snd)),\n    identity := \u03bb X, \u27e8 C.identity (X.fst), D.identity (X.snd) \u27e9,\n    compose  := \u03bb _ _ _ f g, (C.compose (f.fst) (g.fst), D.compose (f.snd) (g.snd))\n  }\n\nlemma Bifunctor_diagonal_identities_1\n  { C : Category }\n  ( F : Functor (ProductCategory C C) C )\n  ( X : C.Obj )\n  ( f g : C.Hom X X )\n  : C.compose (@Functor.onMorphisms _ _ F (X, X) (X, X) (C.identity X, g)) (@Functor.onMorphisms _ _ F (X, X) (X, X) (f, C.identity X)) =\n   @Functor.onMorphisms _ _ F (X, X) (X, X) (f, g) :=\nbegin\n  -- simp {single_pass := tt}, -- fails with 'simplify tactic failed to simplify'\n  simp {max_steps := 20},   -- fails with 'simplify failed, maximum number of steps exceeded'\n\n  -- neither should not suffice to finish the proof!\nend", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/20170706-simp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582554941718, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7232450776246291}}
{"text": "/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport algebra.order.module\nimport linear_algebra.affine_space.affine_map\nimport tactic.field_simp\n\n/-!\n# Slope of a function\n\nIn this file we define the slope of a function `f : k \u2192 PE` taking values in an affine space over\n`k` and prove some basic theorems about `slope`. The `slope` function naturally appears in the Mean\nValue Theorem, and in the proof of the fact that a function with nonnegative second derivative on an\ninterval is convex on this interval.\n\n## Tags\n\naffine space, slope\n-/\n\nopen affine_map\nvariables {k E PE : Type*} [field k] [add_comm_group E] [module k E] [add_torsor E PE]\n\ninclude E\n\n/-- `slope f a b = (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a)` is the slope of a function `f` on the interval\n`[a, b]`. Note that `slope f a a = 0`, not the derivative of `f` at `a`. -/\ndef slope (f : k \u2192 PE) (a b : k) : E := (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a)\n\nlemma slope_fun_def (f : k \u2192 PE) : slope f = \u03bb a b, (b - a)\u207b\u00b9 \u2022 (f b -\u1d65 f a) := rfl\n\nomit E\n\nlemma slope_def_field (f : k \u2192 k) (a b : k) : slope f a b = (f b - f a) / (b - a) :=\n(div_eq_inv_mul _ _).symm\n\n@[simp] lemma slope_same (f : k \u2192 PE) (a : k) : (slope f a a : E) = 0 :=\nby rw [slope, sub_self, inv_zero, zero_smul]\n\ninclude E\n\nlemma slope_def_module (f : k \u2192 E) (a b : k) : slope f a b = (b - a)\u207b\u00b9 \u2022 (f b - f a) := rfl\n\n@[simp] lemma sub_smul_slope (f : k \u2192 PE) (a b : k) : (b - a) \u2022 slope f a b = f b -\u1d65 f a :=\nbegin\n  rcases eq_or_ne a b with rfl | hne,\n  { rw [sub_self, zero_smul, vsub_self] },\n  { rw [slope, smul_inv_smul\u2080 (sub_ne_zero.2 hne.symm)] }\nend\n\nlemma sub_smul_slope_vadd (f : k \u2192 PE) (a b : k) : (b - a) \u2022 slope f a b +\u1d65 f a = f b :=\nby rw [sub_smul_slope, vsub_vadd]\n\n@[simp] lemma slope_vadd_const (f : k \u2192 E) (c : PE) :\n  slope (\u03bb x, f x +\u1d65 c) = slope f :=\nbegin\n  ext a b,\n  simp only [slope, vadd_vsub_vadd_cancel_right, vsub_eq_sub]\nend\n\n@[simp] lemma slope_sub_smul (f : k \u2192 E) {a b : k} (h : a \u2260 b):\n  slope (\u03bb x, (x - a) \u2022 f x) a b = f b :=\nby simp [slope, inv_smul_smul\u2080 (sub_ne_zero.2 h.symm)]\n\nlemma eq_of_slope_eq_zero {f : k \u2192 PE} {a b : k} (h : slope f a b = (0:E)) : f a = f b :=\nby rw [\u2190 sub_smul_slope_vadd f a b, h, smul_zero, zero_vadd]\n\nlemma affine_map.slope_comp {F PF : Type*} [add_comm_group F] [module k F] [add_torsor F PF]\n  (f : PE \u2192\u1d43[k] PF) (g : k \u2192 PE) (a b : k) :\n  slope (f \u2218 g) a b = f.linear (slope g a b) :=\nby simp only [slope, (\u2218), f.linear.map_smul, f.linear_map_vsub]\n\nlemma linear_map.slope_comp {F : Type*} [add_comm_group F] [module k F]\n  (f : E \u2192\u2097[k] F) (g : k \u2192 E) (a b : k) :\n  slope (f \u2218 g) a b = f (slope g a b) :=\nf.to_affine_map.slope_comp g a b\n\nlemma slope_comm (f : k \u2192 PE) (a b : k) : slope f a b = slope f b a :=\nby rw [slope, slope, \u2190 neg_vsub_eq_vsub_rev, smul_neg, \u2190 neg_smul, neg_inv, neg_sub]\n\n/-- `slope f a c` is a linear combination of `slope f a b` and `slope f b c`. This version\nexplicitly provides coefficients. If `a \u2260 c`, then the sum of the coefficients is `1`, so it is\nactually an affine combination, see `line_map_slope_slope_sub_div_sub`. -/\nlemma sub_div_sub_smul_slope_add_sub_div_sub_smul_slope (f : k \u2192 PE) (a b c : k) :\n  ((b - a) / (c - a)) \u2022 slope f a b + ((c - b) / (c - a)) \u2022 slope f b c = slope f a c :=\nbegin\n  by_cases hab : a = b,\n  { subst hab,\n    rw [sub_self, zero_div, zero_smul, zero_add],\n    by_cases hac : a = c,\n    { simp [hac] },\n    { rw [div_self (sub_ne_zero.2 $ ne.symm hac), one_smul] } },\n  by_cases hbc : b = c, { subst hbc, simp [sub_ne_zero.2 (ne.symm hab)] },\n  rw [add_comm],\n  simp_rw [slope, div_eq_inv_mul, mul_smul, \u2190 smul_add,\n    smul_inv_smul\u2080 (sub_ne_zero.2 $ ne.symm hab), smul_inv_smul\u2080 (sub_ne_zero.2 $ ne.symm hbc),\n    vsub_add_vsub_cancel],\nend\n\n/-- `slope f a c` is an affine combination of `slope f a b` and `slope f b c`. This version uses\n`line_map` to express this property. -/\nlemma line_map_slope_slope_sub_div_sub (f : k \u2192 PE) (a b c : k) (h : a \u2260 c) :\n  line_map (slope f a b) (slope f b c) ((c - b) / (c - a)) = slope f a c :=\nby  field_simp [sub_ne_zero.2 h.symm, \u2190 sub_div_sub_smul_slope_add_sub_div_sub_smul_slope f a b c,\n  line_map_apply_module]\n\n/-- `slope f a b` is an affine combination of `slope f a (line_map a b r)` and\n`slope f (line_map a b r) b`. We use `line_map` to express this property. -/\nlemma line_map_slope_line_map_slope_line_map (f : k \u2192 PE) (a b r : k) :\n  line_map (slope f (line_map a b r) b) (slope f a (line_map a b r)) r = slope f a b :=\nbegin\n  obtain (rfl|hab) : a = b \u2228 a \u2260 b := classical.em _, { simp },\n  rw [slope_comm _ a, slope_comm _ a, slope_comm _ _ b],\n  convert line_map_slope_slope_sub_div_sub f b (line_map a b r) a hab.symm using 2,\n  rw [line_map_apply_ring, eq_div_iff (sub_ne_zero.2 hab), sub_mul, one_mul, mul_sub, \u2190 sub_sub,\n    sub_sub_cancel]\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/affine_space/slope.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.72321222332898}}
{"text": "import tactic.finish\nimport algebra.group algebra.big_operators\n\nnoncomputable theory\nlocal attribute [instance] classical.prop_decidable\nlocal attribute [simp] mul_assoc\n\nopen list\n\nvariables {\u03b1 \u03b2 : Type} [group \u03b1] [group \u03b2] {a b g h : \u03b1}\n\n\n-- Conjuguation in a group\n--------------------------\n\ndef conj (a b : \u03b1) := a*b*a\u207b\u00b9\n\n@[simp] lemma conj_action : conj (g * h) a = conj g (conj h a) :=\nby simp[conj]\n\n@[simp] lemma conj_by_one : conj 1 a = a :=\nby simp[conj]\n\ninstance conj.is_group_hom : is_group_hom (conj a) :=\n\u27e8\u03bb x y, by simp [conj, mul_assoc]\u27e9\n\nlemma inv_conj : conj a (b\u207b\u00b9) = (conj a b)\u207b\u00b9 :=\nis_group_hom.inv (conj a) b\n\nlemma conj_mul : conj g (a * b) = conj g a * conj g b :=\nis_group_hom.mul _ _ _\n\n@[simp] lemma conj_one : conj a 1 = 1 :=\nis_group_hom.one (conj a)\n\n-- Products\n-----------\n\n/- \"is_product S n a\" means a can be written as a product of n elements of S or S\u207b\u00b9 -/\ndef is_product (S : set \u03b1) (n : \u2115) (g : \u03b1) : Prop :=\n\u2203 l : list \u03b1, g = prod l \u2227 (\u2200 x \u2208 l, x \u2208 S \u2228 x\u207b\u00b9 \u2208 S) \u2227 l.length = n\n\nlemma is_product_mul {S : set \u03b1} {m n a b}\n  (h\u2081 : is_product S m a) (h\u2082 : is_product S n b) : is_product S (m + n) (a * b) :=\nbegin\n  rcases h\u2081 with \u27e8l\u2081, prod\u2081, inS\u2081, len\u2081\u27e9,\n  rcases h\u2082 with \u27e8l\u2082, prod\u2082, inS\u2082, len\u2082\u27e9,\n\n  existsi l\u2081 ++ l\u2082, -- denoted by l in comments\n  repeat {split},\n  { -- prove a*b = prod l\n    simp [prod\u2081,prod\u2082] },\n  { -- prove elements of l are in S or S\u207b\u00b9\n    simpa,\n    intros x x_in_l\u2081_or_l\u2082,\n    cases x_in_l\u2081_or_l\u2082,\n    { apply inS\u2081 x, assumption },\n    { apply inS\u2082 x, assumption },\n  },\n  { -- prove length l is m + n\n  simp [len\u2081, len\u2082] }\nend\n\nlemma is_product_inv (S : set \u03b1) {n a} (h : is_product S n a) : is_product S n (a\u207b\u00b9) :=\nbegin\n  rcases h with \u27e8l, product, inS, len\u27e9,\n  existsi map (\u03bb x, x\u207b\u00b9) (reverse l),\n  repeat {split},\n  { rw product,\n    apply inv_prod },\n  { simpa,\n    intros,\n    have H := (inS x_1) a_1,\n    have H' : x_1 = x\u207b\u00b9 := eq_inv_of_eq_inv (eq.symm a_2),\n    simp[H'] at H,\n    exact or.symm H },\n  { simpa }\nend\n\n\nlemma is_product_conj {S T : set \u03b1} (g) (H : \u2200 a, a \u2208 S \u2192 conj g a \u2208 T)\n  {n a} (h : is_product S n a) : is_product T n (conj g a) :=\nbegin\n  rcases h with \u27e8l, prod, inS, len\u27e9,\n  existsi (map (conj g) l),\n  repeat {split},\n  { rw prod,\n    apply is_group_hom.prod },\n  { clear prod a len n,\n    intros x x_in_conj_l,\n    rw mem_map at x_in_conj_l,\n    rcases x_in_conj_l with \u27e8b, b_in_l, conj_b_x\u27e9,\n    specialize inS b b_in_l, clear b_in_l l,\n    cases inS,\n    { have conj_in_T := H b inS,\n      rw conj_b_x at conj_in_T,\n      exact or.inl conj_in_T},\n    { have conj_in_T := H b\u207b\u00b9 inS, \n      rw [inv_conj, conj_b_x] at conj_in_T,\n      exact or.inr conj_in_T } },\n  { simp[len] }\nend\n\n--- Generating sets\n-------------------\n\ndef is_generating (S : set \u03b1) : Prop := \n\u2200 g : \u03b1, \u2203 n : \u2115, is_product S n g\n\nstructure generating_set :=\n(set : set \u03b1)\n(gen : is_generating set)\n\n-- Invariant norms on a group\n-----------------------------\n\nstructure is_invariant_norm (\u03bd : \u03b1 \u2192 \u2115) : Prop :=\n  (nonneg : \u2200 g : \u03b1, 0 \u2264 \u03bd g) -- this is silly but ultimately the target will be \u211d\n  (eq_zero : \u2200 g : \u03b1, \u03bd g = 0 \u2192 g = 1)\n  (mul : \u2200 g h : \u03b1, \u03bd (g*h) \u2264 \u03bd g + \u03bd h)\n  (inv : \u2200 g : \u03b1, \u03bd g\u207b\u00b9 = \u03bd g)\n  (conj : \u2200 g h : \u03b1, \u03bd (conj h g) = \u03bd g)\n     \ndef is_conj_invariant_set (S : set \u03b1) : Prop :=\n   \u2200 g s : \u03b1, s \u2208 S \u2192 conj g s \u2208 S\n     \n\n/- Given a generating set S and an alement a,\n   gen_norm S a is the minimal number of elements of S or S\u207b\u00b9 \n   required to write a as a product. \n   The next two lemma prove the definition is what it should be -/\ndef gen_norm (S : generating_set) (a : \u03b1) := nat.find (S.gen a)\n\nlemma is_product_norm (S : generating_set) (g : \u03b1) :\nis_product S.set (gen_norm S g) g :=\nnat.find_spec (S.gen g)\n\nlemma norm_min (S : generating_set) {a : \u03b1} {n} :\nis_product S.set n a \u2192 gen_norm S a \u2264 n :=\nby apply nat.find_min' (S.gen a) \n\n\nlemma inv_norm_of_inv_set [str : group \u03b1] (S : @generating_set \u03b1 str) :\nis_conj_invariant_set S.set \u2192 is_invariant_norm (gen_norm S) :=\nbegin\n  intro inv_hyp,\n  constructor; intros,\n  { apply nat.zero_le },\n  { have H' := is_product_norm S g,\n    rw a at H',\n    rcases H' with \u27e8l, prod, inS, len\u27e9,\n    rw [eq_nil_of_length_eq_zero len] at prod,\n    simp at prod,\n    assumption },\n  { have g_prod := is_product_norm S g,\n    have h_prod := is_product_norm S h,\n    have estimate := is_product_mul g_prod h_prod,\n    exact norm_min S estimate },\n  { apply le_antisymm,\n    { apply norm_min,\n      exact is_product_inv S.set (is_product_norm S g) },\n    { apply norm_min,\n      simpa using is_product_inv S.set  (is_product_norm S g\u207b\u00b9) } },\n  { apply le_antisymm ; apply norm_min,\n    { exact is_product_conj h (inv_hyp h) (is_product_norm S g) },\n    { have prod := is_product_conj h\u207b\u00b9 (inv_hyp h\u207b\u00b9) (is_product_norm S (conj h g)),\n      rw [\u2190conj_action] at prod,\n      simp[conj_by_one] at prod,\n      exact prod } },\nend\n\n-- Commutators\n--------------\n\ndef comm (a b : \u03b1) := a*b*a\u207b\u00b9*b\u207b\u00b9\nlocal notation `[[`a, b`]]` := comm a b\n\nlemma commuting : [[a, b]] = 1 \u2194 a*b = b*a :=\nby simp [comm, -mul_assoc, mul_inv_eq_iff_eq_mul]\n\nlemma commutator_trading (comm_hyp : [[a, conj g b]] = 1) :\n\u2203 c d e f : \u03b1, [[a, b]] = (conj c g\u207b\u00b9)*(conj d g)*(conj e g\u207b\u00b9)*(conj f g) :=\nbegin\n  unfold conj at comm_hyp,\n  let b':= g*b*g\u207b\u00b9,\n\n  exact \u27e8_, _, _, _, calc \n   [[a, b]] = a * b * a\u207b\u00b9 * b\u207b\u00b9 : rfl\n      ...  = a * (g\u207b\u00b9  * b' * g)  * a\u207b\u00b9 * (g\u207b\u00b9 * b'\u207b\u00b9 * g)  : by simp\n      ...  = a * g\u207b\u00b9 * (a\u207b\u00b9 * a) * b' * g  * a\u207b\u00b9 * (b'\u207b\u00b9 * b') * g\u207b\u00b9 * b'\u207b\u00b9 * g  : by simp\n      ...  = a * g\u207b\u00b9 * (a\u207b\u00b9 * a) * b' * g  * (b'*a)\u207b\u00b9 * b' * g\u207b\u00b9 * b'\u207b\u00b9 * g  : by simp\n      ...  = a * g\u207b\u00b9 * (a\u207b\u00b9 * a) * b' * g  * (a*b')\u207b\u00b9 * b' * g\u207b\u00b9 * b'\u207b\u00b9 * g  : by simp [commuting.1 comm_hyp]\n      ...  = (conj a g\u207b\u00b9) * (conj (a*b') g) * (conj b' g\u207b\u00b9) * (conj 1 g) : by simp [conj]\u27e9\nend", "meta": {"author": "PatrickMassot", "repo": "lean-scratchpad", "sha": "03eec3bfabfc218b79dcbe7c7712bfa024a02625", "save_path": "github-repos/lean/PatrickMassot-lean-scratchpad", "path": "github-repos/lean/PatrickMassot-lean-scratchpad/lean-scratchpad-03eec3bfabfc218b79dcbe7c7712bfa024a02625/src/invariant_norms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7232122210135946}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Antoine Labelle\n-/\n\nimport algebra.module.basic\nimport linear_algebra.finsupp\nimport linear_algebra.free_module.basic\n\n/-!\n\n# Projective modules\n\nThis file contains a definition of a projective module, the proof that\nour definition is equivalent to a lifting property, and the\nproof that all free modules are projective.\n\n## Main definitions\n\nLet `R` be a ring (or a semiring) and let `M` be an `R`-module.\n\n* `is_projective R M` : the proposition saying that `M` is a projective `R`-module.\n\n## Main theorems\n\n* `is_projective.lifting_property` : a map from a projective module can be lifted along\n  a surjection.\n\n* `is_projective.of_lifting_property` : If for all R-module surjections `A \u2192\u2097 B`, all\n  maps `M \u2192\u2097 B` lift to `M \u2192\u2097 A`, then `M` is projective.\n\n* `is_projective.of_free` : Free modules are projective\n\n## Implementation notes\n\nThe actual definition of projective we use is that the natural R-module map\nfrom the free R-module on the type M down to M splits. This is more convenient\nthan certain other definitions which involve quantifying over universes,\nand also universe-polymorphic (the ring and module can be in different universes).\n\nWe require that the module sits in at least as high a universe as the ring:\nwithout this, free modules don't even exist,\nand it's unclear if projective modules are even a useful notion.\n\n## References\n\nhttps://en.wikipedia.org/wiki/Projective_module\n\n## TODO\n\n- Direct sum of two projective modules is projective.\n- Arbitrary sum of projective modules is projective.\n\nAll of these should be relatively straightforward.\n\n## Tags\n\nprojective module\n\n-/\n\nuniverses u v\n\nopen linear_map finsupp\n\n/- The actual implementation we choose: `P` is projective if the natural surjection\n   from the free `R`-module on `P` to `P` splits. -/\n/-- An R-module is projective if it is a direct summand of a free module, or equivalently\n  if maps from the module lift along surjections. There are several other equivalent\n  definitions. -/\nclass module.projective (R : Type*) [semiring R] (P : Type*) [add_comm_monoid P]\n  [module R P] : Prop :=\n(out : \u2203 s : P \u2192\u2097[R] (P \u2192\u2080 R), function.left_inverse (finsupp.total P P R id) s)\n\nnamespace module\n\nsection semiring\n\nvariables {R : Type*} [semiring R] {P : Type*} [add_comm_monoid P] [module R P]\n  {M : Type*} [add_comm_monoid M] [module R M] {N : Type*} [add_comm_monoid N] [module R N]\n\nlemma projective_def : projective R P \u2194\n  (\u2203 s : P \u2192\u2097[R] (P \u2192\u2080 R), function.left_inverse (finsupp.total P P R id) s) :=\n\u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\ntheorem projective_def' : projective R P \u2194\n  (\u2203 s : P \u2192\u2097[R] (P \u2192\u2080 R), (finsupp.total P P R id) \u2218\u2097 s = id) :=\nby simp_rw [projective_def, fun_like.ext_iff, function.left_inverse, coe_comp, id_coe, id.def]\n\n/-- A projective R-module has the property that maps from it lift along surjections. -/\ntheorem projective_lifting_property [h : projective R P] (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N)\n  (hf : function.surjective f) : \u2203 (h : P \u2192\u2097[R] M), f.comp h = g :=\nbegin\n  /-\n  Here's the first step of the proof.\n  Recall that `X \u2192\u2080 R` is Lean's way of talking about the free `R`-module\n  on a type `X`. The universal property `finsupp.total` says that to a map\n  `X \u2192 N` from a type to an `R`-module, we get an associated R-module map\n  `(X \u2192\u2080 R) \u2192\u2097 N`. Apply this to a (noncomputable) map `P \u2192 M` coming from the map\n  `P \u2192\u2097 N` and a random splitting of the surjection `M \u2192\u2097 N`, and we get\n  a map `\u03c6 : (P \u2192\u2080 R) \u2192\u2097 M`.\n  -/\n  let \u03c6 : (P \u2192\u2080 R) \u2192\u2097[R] M := finsupp.total _ _ _ (\u03bb p, function.surj_inv hf (g p)),\n  -- By projectivity we have a map `P \u2192\u2097 (P \u2192\u2080 R)`;\n  cases h.out with s hs,\n  -- Compose to get `P \u2192\u2097 M`. This works.\n  use \u03c6.comp s,\n  ext p,\n  conv_rhs {rw \u2190 hs p},\n  simp [\u03c6, finsupp.total_apply, function.surj_inv_eq hf],\nend\n\nvariables {Q : Type*} [add_comm_monoid Q] [module R Q]\n\ninstance [hP : projective R P] [hQ : projective R Q] : projective R (P \u00d7 Q) :=\nbegin\n  rw module.projective_def',\n  cases hP.out with sP hsP,\n  cases hQ.out with sQ hsQ,\n  use coprod (lmap_domain R R (inl R P Q)) (lmap_domain R R (inr R P Q)) \u2218\u2097 sP.prod_map sQ,\n  ext; simp only [coe_inl, coe_inr, coe_comp, function.comp_app, prod_map_apply, map_zero,\n    coprod_apply, lmap_domain_apply, map_domain_zero, add_zero, zero_add, id_comp,\n    total_map_domain],\n\n  { rw [\u2190fst_apply _, apply_total R], exact hsP x, },\n  { rw [\u2190snd_apply _, apply_total R], exact finsupp.total_zero_apply _ (sP x), },\n  { rw [\u2190fst_apply _, apply_total R], exact finsupp.total_zero_apply _ (sQ x), },\n  { rw [\u2190snd_apply _, apply_total R], exact hsQ x, },\nend\n\nvariables {\u03b9 : Type*} (A : \u03b9 \u2192 Type*) [\u03a0 (i : \u03b9), add_comm_monoid (A i)]\n  [\u03a0 (i : \u03b9), module R (A i)]\n\ninstance [h : \u03a0 (i : \u03b9), projective R (A i)] : projective R (\u03a0\u2080 i, A i) :=\nbegin\n  classical,\n  rw module.projective_def',\n  simp_rw projective_def at h, choose s hs using h,\n\n  letI : \u03a0 (i : \u03b9), add_comm_monoid (A i \u2192\u2080 R) := \u03bb i, by apply_instance,\n  letI : \u03a0 (i : \u03b9), module R (A i \u2192\u2080 R) := \u03bb i, by apply_instance,\n  letI : add_comm_monoid (\u03a0\u2080 (i : \u03b9), A i \u2192\u2080 R) := @dfinsupp.add_comm_monoid \u03b9 (\u03bb i, A i \u2192\u2080 R) _,\n  letI : module R (\u03a0\u2080 (i : \u03b9), A i \u2192\u2080 R) := @dfinsupp.module \u03b9 R (\u03bb i, A i \u2192\u2080 R) _ _ _,\n\n  let f := \u03bb i, lmap_domain R R (dfinsupp.single i : A i \u2192 \u03a0\u2080 i, A i),\n  use dfinsupp.coprod_map f \u2218\u2097 dfinsupp.map_range.linear_map s,\n\n  ext i x j,\n  simp only [dfinsupp.coprod_map, direct_sum.lof, total_map_domain,\n    coe_comp, coe_lsum, id_coe, linear_equiv.coe_to_linear_map, finsupp_lequiv_dfinsupp_symm_apply,\n    function.comp_app, dfinsupp.lsingle_apply, dfinsupp.map_range.linear_map_apply,\n    dfinsupp.map_range_single, lmap_domain_apply, dfinsupp.to_finsupp_single,\n    finsupp.sum_single_index, id.def, function.comp.left_id, dfinsupp.single_apply],\n  rw [\u2190dfinsupp.lapply_apply j, apply_total R],\n\n  obtain rfl | hij := eq_or_ne i j,\n\n  { convert (hs i) x,\n    { ext, simp },\n    { simp } },\n  { convert finsupp.total_zero_apply _ ((s i) x),\n    { ext, simp [hij] },\n    { simp [hij] } }\nend\n\nend semiring\n\nsection ring\n\nvariables {R : Type*} [ring R] {P : Type*} [add_comm_group P] [module R P]\n\n/-- Free modules are projective. -/\ntheorem projective_of_basis {\u03b9 : Type*} (b : basis \u03b9 R P) : projective R P :=\nbegin\n  -- need P \u2192\u2097 (P \u2192\u2080 R) for definition of projective.\n  -- get it from `\u03b9 \u2192 (P \u2192\u2080 R)` coming from `b`.\n  use b.constr \u2115 (\u03bb i, finsupp.single (b i) (1 : R)),\n  intro m,\n  simp only [b.constr_apply, mul_one, id.def, finsupp.smul_single', finsupp.total_single,\n    linear_map.map_finsupp_sum],\n  exact b.total_repr m,\nend\n\n@[priority 100]\ninstance projective_of_free [module.free R P] : module.projective R P :=\nprojective_of_basis $ module.free.choose_basis R P\n\nend ring\n\n--This is in a different section because special universe restrictions are required.\nsection of_lifting_property\n\n/-- A module which satisfies the universal property is projective. Note that the universe variables\nin `huniv` are somewhat restricted. -/\ntheorem projective_of_lifting_property'\n  {R : Type u} [semiring R] {P : Type (max u v)} [add_comm_monoid P] [module R P]\n  -- If for all surjections of `R`-modules `M \u2192\u2097 N`, all maps `P \u2192\u2097 N` lift to `P \u2192\u2097 M`,\n  (huniv : \u2200 {M : Type (max v u)} {N : Type (max u v)} [add_comm_monoid M] [add_comm_monoid N],\n    by exactI\n    \u2200 [module R M] [module R N],\n    by exactI\n    \u2200 (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N),\n  function.surjective f \u2192 \u2203 (h : P \u2192\u2097[R] M), f.comp h = g) :\n  -- then `P` is projective.\n  projective R P :=\nbegin\n  -- let `s` be the universal map `(P \u2192\u2080 R) \u2192\u2097 P` coming from the identity map `P \u2192\u2097 P`.\n  obtain \u27e8s, hs\u27e9 : \u2203 (s : P \u2192\u2097[R] P \u2192\u2080 R),\n    (finsupp.total P P R id).comp s = linear_map.id :=\n    huniv (finsupp.total P P R (id : P \u2192 P)) (linear_map.id : P \u2192\u2097[R] P) _,\n  -- This `s` works.\n  { use s,\n    rwa linear_map.ext_iff at hs },\n  { intro p,\n    use finsupp.single p 1,\n    simp },\nend\n\n/-- A variant of `of_lifting_property'` when we're working over a `[ring R]`,\nwhich only requires quantifying over modules with an `add_comm_group` instance. -/\ntheorem projective_of_lifting_property\n  {R : Type u} [ring R] {P : Type (max u v)} [add_comm_group P] [module R P]\n  -- If for all surjections of `R`-modules `M \u2192\u2097 N`, all maps `P \u2192\u2097 N` lift to `P \u2192\u2097 M`,\n  (huniv : \u2200 {M : Type (max v u)} {N : Type (max u v)} [add_comm_group M] [add_comm_group N],\n    by exactI\n    \u2200 [module R M] [module R N],\n    by exactI\n    \u2200 (f : M \u2192\u2097[R] N) (g : P \u2192\u2097[R] N),\n  function.surjective f \u2192 \u2203 (h : P \u2192\u2097[R] M), f.comp h = g) :\n  -- then `P` is projective.\n  projective R P :=\n-- We could try and prove this *using* `of_lifting_property`,\n-- but this quickly leads to typeclass hell,\n-- so we just prove it over again.\nbegin\n  -- let `s` be the universal map `(P \u2192\u2080 R) \u2192\u2097 P` coming from the identity map `P \u2192\u2097 P`.\n  obtain \u27e8s, hs\u27e9 : \u2203 (s : P \u2192\u2097[R] P \u2192\u2080 R),\n    (finsupp.total P P R id).comp s = linear_map.id :=\n    huniv (finsupp.total P P R (id : P \u2192 P)) (linear_map.id : P \u2192\u2097[R] P) _,\n  -- This `s` works.\n  { use s,\n    rwa linear_map.ext_iff at hs },\n  { intro p,\n    use finsupp.single p 1,\n    simp },\nend\n\nend of_lifting_property\n\nend module\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/module/projective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7232122186982091}}
{"text": "import tactic\n\n/-!\n# Dirichlet density of primes \u2261 1 and primes \u2261 3 mod 4\n\nThe goal of this project is to prove\n\n**Theorem.** The sets of primes p \u2261 1 mod 4 and of primes p \u2261 3 mod 4 both have \nDirichlet density 1/2.\n\nThis is covered in Ireland-Rosen, \u00a716.1-2:\n\n## \u00a71 The Zeta Function\n\nThe Riemann zeta function \u03b6(s) is defined by \u03b6(s) = \u2211_{n=1}^\u221e n\u207b\u02e2.\nIt converges for s > 1 and converges uniformly for s \u2265 1 + \u03b4 > 1, for each \u03b4 > O.\n\n**Proposition 16.1.1.** For s > 1.\n  \u03b6(s) = \u220f\u209a (1 - p\u207b\u02e2)\u207b\u00b9,\nwhere the product is over all primes p > 0.\n\nPROOF. For s > 1, p\u207b\u02e2 < 1, so we have (1 - p\u207b\u02e2)\u207b\u00b9 = \u2211_{m=0}^\u221e p\u207b\u1d50\u02e2.\nBy the theorem of unique factorization\n  \u220f_{p \u2264 N} (1 - p\u207b\u02e2)\u207b\u00b9 = \u2211_{n \u2264 N} n\u207b\u02e2 + R_N(s) .\nClearly, R_N(s) \u2264 \u2211_{n=N+1}^\u221e n\u207b\u02e2. Since \u03b6(s) converges, R_N(s) \u2192 0 as N \u2192 \u221e. The\nresult follows. QED\n\nThe behavior of \u03b6(s) as s \u2192 1 is very important. Since \u2211_{n=1}^\u221e n\u207b\u00b9 diverges,\nwe, of course, suspect \u03b6(s) \u2192 \u221e as s \u2192 1. In fact,\n\n**Proposition 16.1.2.** Assume s > 1. Then\n  lim_{s \u2192 1} (s - l) \u03b6(s) = 1.\n\nPROOF. For fixed s, t\u207b\u02e2 is a monotone decreasing function of t. Thus,\n  (n + 1)\u207b\u02e2 < \u222b_n^{n+1} t\u207b\u02e2 dt < n\u207b\u02e2 .\nSumming from n = 1 to \u221e,\n  \u03b6(s) - 1 < \u222b_1^\u221e t\u207b\u02e2 dt < \u03b6(s) .\nThe value of the integral is (s - 1)\u207b\u00b9. It follows that 1 < (s - 1) \u03b6(s) < s.\nTaking the limit as s \u2192 1 gives the result. QED\n\n**Corollary.** As s \u2192 1 we have\n  (ln \u03b6(s))/(ln (s-1)\u207b\u00b9) \u2192 1 .\n\nPROOF. Let (s - 1) \u03b6(s) = \u03c1(s). Then ln(s - 1) + ln \u03b6(s) = ln \u03c1(s), so we have\nln \u03b6(s)/ln(s - 1)\u207b\u00b9 = 1 + (ln \u03c1(s))/ln(s - 1)^\u207b\u00b9.\nAs s \u2192 1, \u03c1(s) \u2192 1 by the proposition. Therefore, ln \u03c1(s) \u2192 0, and the\nresult follows. QED\n\n**Proposition 16.1.3.** ln \u03b6(s) = \u2211\u209a p\u207b\u02e2 + R(s), where R(s) remains bounded as\ns \u2192 1.\n\nPROOF. We use the formula -ln(1 - x) = x + x\u00b2/2 + x\u00b3/3 + ..., which is\nvalid for -1 < x < 1.\nBy Proposition 16.1.1 we have\n  \u03b6(s) = \u220f_{p \u2264 N} (1 - p\u207b\u02e2)\u207b\u00b9 \u03bb_N(s) ,\nwhere \u03bb_N(S) \u2192 1 as N \u2192 \u221e. Taking the logarithm of both sides yields\nln \u03b6(s) = \u2211_{p \u2264 N} \u2211_{m=1}^\u221e m\u207b\u00b9 p\u207b\u1d50\u02e2 + ln \u03bb_N(s).\nTaking the limit as N \u2192 \u221e\n  ln \u03b6(s) = \u2211\u209a \u2211_{m=1}^\u221e m\u207b\u00b9 p\u207b\u1d50\u02e2 = \u2211\u209a p\u207b\u02e2 + \u2211\u209a \u2211_{m=2}^\u221e m\u207b\u00b9 p\u207b\u1d50\u02e2 .\nThe second sum is less than\n  \u2211\u209a \u2211_{m=2}^\u221e p\u207b\u1d50\u02e2 = \u2211\u209a p\u207b\u00b2\u02e2 (1 - p\u207b\u02e2)\u207b\u00b9 \u2264 (1 - 2\u207b\u02e2)\u207b\u00b9 \u2211\u209a p\u207b\u00b2\u02e2 \u2264 2 \u03b6(2).\nThroughout we have used the assumption that s > 1. QED\n\n**Definition.** A set of positive primes \ud835\udcab is said to have *Dirichlet density* if\n  lim_{s \u2192 1} (\u2211_{p \u2208 \ud835\udcab} p\u207b\u02e2)/ln (s-1)\u207b\u00b9\nexists. If the limit exists we set it equal to d(\ud835\udcab) and call d(\ud835\udcab) the\n*Dirichlet density* of \ud835\udcab.\n\n**Proposition 16.1.4.** Let \ud835\udcab be a set of positive prime numbers. Then\n(a) If \ud835\udcab is finite, then d(\ud835\udcab) = 0.\n(b) If \ud835\udcab consists of all but finitely many positive primes, then d(\ud835\udcab) = 1.\n(c) If \ud835\udcab = \ud835\udcab\u2081 \u222a \ud835\udcab\u2082 where \ud835\udcab\u2081 and \ud835\udcab\u2082 are disjoint and d(\ud835\udcab\u2081) and d(\ud835\udcab\u2082) both\nexist, then d(\ud835\udcab) = d(\ud835\udcab\u2081) + d(\ud835\udcab\u2082).\n\nPROOF. Parts (a) and (c) are clear from the definition of Dirichlet density.\nPart (b) follows quickly from the corollary to Proposition 16.1.2 and Proposition 16.1.3.\nQED\n\nWe are now in a position to state the main theorem of this chapter. The\nproof will be spread out over the next three sections.\n\n**Theorem 1** (L. Dirichlet). Suppose a, m \u2208 \u2124, with gcd(a, m) = 1. Let \ud835\udcab(a; m) be the\nset of positive primes p such that p \u2261 a mod m. Then d(\ud835\udcab(a; m)) = 1/\u03d5(m).\n\nNote that Theorem 1 certainly implies \ud835\udcab(a; m) is infinite, since if it were\nfinite, its density would be zero.\n\n\n## \u00a72 A Special Case\n\nWe will first prove Theorem 1 in the case where m = 4. The basic ideas of the\nproof are all present in this special case, but the details are more transparent.\nDefine a function \u03c7 from \u2124 to {0, \u00b11} as follows; \u03c7(n) = 0 if n is even,\n\u03c7(n) = 1 if n \u2261 1 mod 4, and \u03c7(n) = -1 if n \u2261 3 mod 4. It is easily seen that\n\u03c7(m n) = \u03c7(m) \u03c7(n) for all m, n \u2208 \u2124.\n\nDefine L(s, \u03c7) = \u2211_{n=1}^\u221e \u03c7(n) n\u207b\u02e2 = 1 - 3\u207b\u02e2 + 5\u207b\u02e2 - 7\u207b\u02e2 + ... . For all n\nwe have |\u03c7(n) n\u207b\u02e2| \u2264 n\u207b\u02e2. It follows that the terms of L(s, \u03c7) are dominated in\nabsolute value by the terms of \u03b6(s). Thus L(s, \u03c7) converges and is continuous\nfor s > 1. Since \u03c7 is completely multiplicative, the proof of Proposition 16.1.1.\nshows that\n  L(s, \u03c7) = \u220f\u209a (1 - \u03c7(p) p\u207b\u02e2)^\u207b\u00b9 .\nIt is useful to modify \u03b6(s) so as to suppress the even terms. Define \u03b6*(s) = \u2211{n odd} n\u207b\u02e2.\nSince\n  \u03b6(s) = \u2211_{n=1}^\u221e n\u207b\u02e2 = \u2211_{n odd} n\u207b\u02e2 + \u2211_{n even} n\u207b\u02e2 = \u03b6*(s) + 2\u207b\u02e2 \u03b6(s)\nwe have \u03b6*(s) = (1 - 2\u207b\u02e2) \u03b6(s) and so\n  \u03b6*(s) = \u220f_{p odd} (1 - p\u207b\u02e2)\u207b\u00b9 .\nUsing the method of proof of Proposition 16.1.3 we find\n  ln L(s, \u03c7) = \u2211_{p odd} \u03c7(p) p\u207b\u02e2 + R\u2081(s)                            (i)\n    ln \u03b6*(s) = \u2211_{p odd} p\u207b\u02e2 + R\u2082(s)                                (ii)\nwhere R\u2081(s) and R\u2082(s) remain bounded as s \u2192 1.\n\nWe have 1 + \u03c7(p) = 2 if p \u2261 1 mod 4 and 1 + \u03c7(p) = 0 if p \u2261 3 mod 4. Similarly,\n1 - \u03c7(p) = 2 if p \u2261 3 mod 4 and 1 - \u03c7(p) = 0 if p \u2261 1 mod 4.  From (i) and (ii) we\ndeduce\n  ln \u03b6*(s) + ln L(s, \u03c7) = 2 \u2211_{p \u2261 1 mod 4} p\u207b\u02e2 + R\u2083(s)            (iii)\n  ln \u03b6*(s) - ln L(s, \u03c7) = 2 \u2211_{p \u2261 3 mod 4} p\u207b\u02e2 + R\u2084(s)             (iv)\n where R\u2083(s) and R\u2084(s) remain bounded as s \u2192 1.\n\nThe next step is to show that ln L(s, \u03c7) remains bounded as s \u2192 1. To see\nthis, write\n  L(s, \u03c7) = (1 - 3\u207b\u02e2) + (5\u207b\u02e2 - 7\u207b\u02e2) + ... = 1 - (3\u207b\u02e2 - 5\u207b\u02e2) - (7\u207b\u02e2 - 9\u207b\u02e2) - ... .\nIt follows that for all s > 1 we have 2/3 < L(s, \u03c7) < 1. Thus, for s > 1 we have\nln 2/3 < ln L(s, \u03c7) < ln 1 = 0.\n\nAs a final preparatory step we note that ln \u03b6*(s) = ln(1 - 2\u207b\u02e2) + ln \u03b6(s), so\nby the corollary to Proposition 16.1.2. we have ln \u03b6*(s)/ln(s - 1)\u207b\u00b9 \u2192 1 as s \u2192 1.\n\nNow divide each term of Equations (iii) and (iv) by ln(s - 1)\u207b\u00b9 and take\nthe limit as s \u2192 1. The result is\n\n**Proposition 16.2.1.** d(\ud835\udcab(1; 4)) = 1/2 and d(\ud835\udcab(3; 4)) = 1/2.\n\n-/", "meta": {"author": "MichaelStollBayreuth", "repo": "seminar-bayreuth-2022", "sha": "1e5accbfb6054c8ca4b6d3b192818fdbb90ed841", "save_path": "github-repos/lean/MichaelStollBayreuth-seminar-bayreuth-2022", "path": "github-repos/lean/MichaelStollBayreuth-seminar-bayreuth-2022/seminar-bayreuth-2022-1e5accbfb6054c8ca4b6d3b192818fdbb90ed841/src/primes_in_arithmetic_progression.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199592797929, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7231940422444512}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\nimport data.list.of_fn\nimport data.list.perm\n\n/-!\n# Sorting algorithms on lists\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define `list.sorted r l` to be an alias for `pairwise r l`. This alias is preferred\nin the case that `r` is a `<` or `\u2264`-like relation. Then we define two sorting algorithms:\n`list.insertion_sort` and `list.merge_sort`, and prove their correctness.\n-/\n\nopen list.perm\n\nuniverse uu\n\nnamespace list\n\n/-!\n### The predicate `list.sorted`\n-/\n\nsection sorted\n\nvariables {\u03b1 : Type uu} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {a : \u03b1} {l : list \u03b1}\n\n/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`\n  is a `<` or `\u2264`-like relation (transitive and antisymmetric or asymmetric) -/\ndef sorted := @pairwise\n\ninstance decidable_sorted [decidable_rel r] (l : list \u03b1) : decidable (sorted r l) :=\nlist.decidable_pairwise _\n\n@[simp] theorem sorted_nil : sorted r [] := pairwise.nil\n\nlemma sorted.of_cons : sorted r (a :: l) \u2192 sorted r l := pairwise.of_cons\n\ntheorem sorted.tail {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {l : list \u03b1} (h : sorted r l) : sorted r l.tail :=\nh.tail\n\ntheorem rel_of_sorted_cons {a : \u03b1} {l : list \u03b1} : sorted r (a :: l) \u2192\n  \u2200 b \u2208 l, r a b :=\nrel_of_pairwise_cons\n\n@[simp] theorem sorted_cons {a : \u03b1} {l : list \u03b1} :\n  sorted r (a :: l) \u2194 (\u2200 b \u2208 l, r a b) \u2227 sorted r l :=\npairwise_cons\n\nprotected theorem sorted.nodup {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_irrefl \u03b1 r] {l : list \u03b1} (h : sorted r l) :\n  nodup l :=\nh.nodup\n\ntheorem eq_of_perm_of_sorted [is_antisymm \u03b1 r]\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 ~ l\u2082) (s\u2081 : sorted r l\u2081) (s\u2082 : sorted r l\u2082) : l\u2081 = l\u2082 :=\nbegin\n  induction s\u2081 with a l\u2081 h\u2081 s\u2081 IH generalizing l\u2082,\n  { exact p.nil_eq },\n  { have : a \u2208 l\u2082 := p.subset (mem_cons_self _ _),\n    rcases mem_split this with \u27e8u\u2082, v\u2082, rfl\u27e9,\n    have p' := (perm_cons a).1 (p.trans perm_middle),\n    obtain rfl := IH p' (s\u2082.sublist $ by simp),\n    change a::u\u2082 ++ v\u2082 = u\u2082 ++ ([a] ++ v\u2082), rw \u2190 append_assoc, congr,\n    have : \u2200 (x : \u03b1) (h : x \u2208 u\u2082), x = a := \u03bb x m,\n      antisymm ((pairwise_append.1 s\u2082).2.2 _ m a (mem_cons_self _ _))\n        (h\u2081 _ (by simp [m])),\n    rw [(@eq_replicate _ a (length u\u2082 + 1) (a::u\u2082)).2,\n        (@eq_replicate _ a (length u\u2082 + 1) (u\u2082++[a])).2];\n    split; simp [iff_true_intro this, or_comm] }\nend\n\ntheorem sublist_of_subperm_of_sorted [is_antisymm \u03b1 r]\n  {l\u2081 l\u2082 : list \u03b1} (p : l\u2081 <+~ l\u2082) (s\u2081 : l\u2081.sorted r) (s\u2082 : l\u2082.sorted r) : l\u2081 <+ l\u2082 :=\nlet \u27e8_, h, h'\u27e9 := p in by rwa \u2190eq_of_perm_of_sorted h (s\u2082.sublist h') s\u2081\n\n@[simp] theorem sorted_singleton (a : \u03b1) : sorted r [a] := pairwise_singleton _ _\n\nlemma sorted.rel_nth_le_of_lt {l : list \u03b1}\n  (h : l.sorted r) {a b : \u2115} (ha : a < l.length) (hb : b < l.length) (hab : a < b) :\n  r (l.nth_le a ha) (l.nth_le b hb) :=\nlist.pairwise_iff_nth_le.1 h a b hb hab\n\nlemma sorted.rel_nth_le_of_le [is_refl \u03b1 r] {l : list \u03b1}\n  (h : l.sorted r) {a b : \u2115} (ha : a < l.length) (hb : b < l.length) (hab : a \u2264 b) :\n  r (l.nth_le a ha) (l.nth_le b hb) :=\nbegin\n  cases eq_or_lt_of_le hab with H H,\n  { subst H, exact refl _ },\n  { exact h.rel_nth_le_of_lt _ _ H }\nend\n\nlemma sorted.rel_of_mem_take_of_mem_drop {l : list \u03b1} (h : list.sorted r l)\n  {k : \u2115} {x y : \u03b1} (hx : x \u2208 list.take k l) (hy : y \u2208 list.drop k l) :\n  r x y :=\nbegin\n  obtain \u27e8iy, hiy, rfl\u27e9 := nth_le_of_mem hy,\n  obtain \u27e8ix, hix, rfl\u27e9 := nth_le_of_mem hx,\n  rw [nth_le_take', nth_le_drop'],\n  rw length_take at hix,\n  exact h.rel_nth_le_of_lt _ _ (ix.lt_add_right _ _ (lt_min_iff.mp hix).left)\nend\n\nend sorted\n\nsection monotone\n\nvariables {n : \u2115} {\u03b1 : Type uu} [preorder \u03b1] {f : fin n \u2192 \u03b1}\n\n/-- A tuple is monotone if and only if the list obtained from it is sorted. -/\nlemma monotone_iff_of_fn_sorted : monotone f \u2194 (of_fn f).sorted (\u2264) :=\nbegin\n  simp_rw [sorted, pairwise_iff_nth_le, length_of_fn, nth_le_of_fn', monotone_iff_forall_lt],\n  exact \u27e8\u03bb h i j hj hij, h $ fin.mk_lt_mk.mpr hij, \u03bb h \u27e8i, _\u27e9 \u27e8j, hj\u27e9 hij, h i j hj hij\u27e9,\nend\n\n/-- The list obtained from a monotone tuple is sorted. -/\nlemma monotone.of_fn_sorted (h : monotone f) : (of_fn f).sorted (\u2264) :=\nmonotone_iff_of_fn_sorted.1 h\n\nend monotone\n\nsection sort\nvariables {\u03b1 : Type uu} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [decidable_rel r]\nlocal infix ` \u227c ` : 50 := r\n\n/-! ### Insertion sort -/\n\nsection insertion_sort\n\n/-- `ordered_insert a l` inserts `a` into `l` at such that\n  `ordered_insert a l` is sorted if `l` is. -/\n@[simp] def ordered_insert (a : \u03b1) : list \u03b1 \u2192 list \u03b1\n| []       := [a]\n| (b :: l) := if a \u227c b then a :: b :: l else b :: ordered_insert l\n\n/-- `insertion_sort l` returns `l` sorted using the insertion sort algorithm. -/\n@[simp] def insertion_sort : list \u03b1 \u2192 list \u03b1\n| []       := []\n| (b :: l) := ordered_insert r b (insertion_sort l)\n\n@[simp] lemma ordered_insert_nil (a : \u03b1) : [].ordered_insert r a = [a] := rfl\n\ntheorem ordered_insert_length : \u03a0 (L : list \u03b1) (a : \u03b1), (L.ordered_insert r a).length = L.length + 1\n| [] a := rfl\n| (hd :: tl) a := by { dsimp [ordered_insert], split_ifs; simp [ordered_insert_length], }\n\n/-- An alternative definition of `ordered_insert` using `take_while` and `drop_while`. -/\nlemma ordered_insert_eq_take_drop (a : \u03b1) : \u2200 l : list \u03b1,\n  l.ordered_insert r a = l.take_while (\u03bb b, \u00ac(a \u227c b)) ++ (a :: l.drop_while (\u03bb b, \u00ac(a \u227c b)))\n| [] := rfl\n| (b :: l) := by { dsimp only [ordered_insert], split_ifs; simp [take_while, drop_while, *] }\n\nlemma insertion_sort_cons_eq_take_drop (a : \u03b1) (l : list \u03b1) :\n  insertion_sort r (a :: l) = (insertion_sort r l).take_while (\u03bb b, \u00ac(a \u227c b)) ++\n    (a :: (insertion_sort r l).drop_while (\u03bb b, \u00ac(a \u227c b))) :=\nordered_insert_eq_take_drop r a _\n\nsection correctness\nopen perm\n\ntheorem perm_ordered_insert (a) : \u2200 l : list \u03b1, ordered_insert r a l ~ a :: l\n| []       := perm.refl _\n| (b :: l) := by by_cases a \u227c b; [simp [ordered_insert, h],\n  simpa [ordered_insert, h] using\n    ((perm_ordered_insert l).cons _).trans (perm.swap _ _ _)]\n\ntheorem ordered_insert_count [decidable_eq \u03b1] (L : list \u03b1) (a b : \u03b1) :\n  count a (L.ordered_insert r b) = count a L + if (a = b) then 1 else 0 :=\nbegin\n  rw [(L.perm_ordered_insert r b).count_eq, count_cons],\n  split_ifs; simp only [nat.succ_eq_add_one, add_zero],\nend\n\ntheorem perm_insertion_sort : \u2200 l : list \u03b1, insertion_sort r l ~ l\n| []       := perm.nil\n| (b :: l) := by simpa [insertion_sort] using\n  (perm_ordered_insert _ _ _).trans ((perm_insertion_sort l).cons b)\n\nvariable {r}\n\n/-- If `l` is already `list.sorted` with respect to `r`, then `insertion_sort` does not change\nit. -/\nlemma sorted.insertion_sort_eq : \u2200 {l : list \u03b1} (h : sorted r l), insertion_sort r l = l\n| [] _ := rfl\n| [a] _ := rfl\n| (a :: b :: l) h :=\n  begin\n    rw [insertion_sort, sorted.insertion_sort_eq, ordered_insert, if_pos],\n    exacts [rel_of_sorted_cons h _ (or.inl rfl), h.tail]\n  end\n\nsection total_and_transitive\nvariables [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted.ordered_insert (a : \u03b1) : \u2200 l, sorted r l \u2192 sorted r (ordered_insert r a l)\n| []       h := sorted_singleton a\n| (b :: l) h := begin\n  by_cases h' : a \u227c b,\n  { simpa [ordered_insert, h', h] using \u03bb b' bm, trans h' (rel_of_sorted_cons h _ bm) },\n  { suffices : \u2200 (b' : \u03b1), b' \u2208 ordered_insert r a l \u2192 r b b',\n    { simpa [ordered_insert, h', h.of_cons.ordered_insert l] },\n    intros b' bm,\n    cases (show b' = a \u2228 b' \u2208 l, by simpa using\n      (perm_ordered_insert _ _ _).subset bm) with be bm,\n    { subst b', exact (total_of r _ _).resolve_left h' },\n    { exact rel_of_sorted_cons h _ bm } }\nend\n\nvariable (r)\n\n/-- The list `list.insertion_sort r l` is `list.sorted` with respect to `r`. -/\ntheorem sorted_insertion_sort : \u2200 l, sorted r (insertion_sort r l)\n| []       := sorted_nil\n| (a :: l) := (sorted_insertion_sort l).ordered_insert a _\n\nend total_and_transitive\nend correctness\nend insertion_sort\n\n/-! ### Merge sort -/\n\nsection merge_sort\n\n-- TODO(Jeremy): observation: if instead we write (a :: (split l).1, b :: (split l).2), the\n-- equation compiler can't prove the third equation\n\n/-- Split `l` into two lists of approximately equal length.\n\n     split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) -/\n@[simp] def split : list \u03b1 \u2192 list \u03b1 \u00d7 list \u03b1\n| []       := ([], [])\n| (a :: l) := let (l\u2081, l\u2082) := split l in (a :: l\u2082, l\u2081)\n\ntheorem split_cons_of_eq (a : \u03b1) {l l\u2081 l\u2082 : list \u03b1} (h : split l = (l\u2081, l\u2082)) :\n  split (a :: l) = (a :: l\u2082, l\u2081) :=\nby rw [split, h]; refl\n\ntheorem length_split_le : \u2200 {l l\u2081 l\u2082 : list \u03b1},\n  split l = (l\u2081, l\u2082) \u2192 length l\u2081 \u2264 length l \u2227 length l\u2082 \u2264 length l\n| []     ._  ._  rfl := \u27e8nat.le_refl 0, nat.le_refl 0\u27e9\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ h\u2082, nat.le_succ_of_le h\u2081\u27e9\nend\n\ntheorem length_split_lt {a b} {l l\u2081 l\u2082 : list \u03b1} (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  length l\u2081 < length (a::b::l) \u2227 length l\u2082 < length (a::b::l) :=\nbegin\n  cases e : split l with l\u2081' l\u2082',\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l\u2081 l\u2082,\n  cases length_split_le e with h\u2081 h\u2082,\n  exact \u27e8nat.succ_le_succ (nat.succ_le_succ h\u2081), nat.succ_le_succ (nat.succ_le_succ h\u2082)\u27e9\nend\n\ntheorem perm_split : \u2200 {l l\u2081 l\u2082 : list \u03b1}, split l = (l\u2081, l\u2082) \u2192 l ~ l\u2081 ++ l\u2082\n| []     ._  ._  rfl := perm.refl _\n| (a::l) l\u2081' l\u2082' h   := begin\n  cases e : split l with l\u2081 l\u2082,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l\u2081' l\u2082',\n  exact ((perm_split e).trans perm_append_comm).cons a,\nend\n\n/-- Merge two sorted lists into one in linear time.\n\n     merge [1, 2, 4, 5] [0, 1, 3, 4] = [0, 1, 1, 2, 3, 4, 4, 5] -/\ndef merge : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| []       l'        := l'\n| l        []        := l\n| (a :: l) (b :: l') := if a \u227c b then a :: merge l (b :: l') else b :: merge (a :: l) l'\n\ninclude r\n/-- Implementation of a merge sort algorithm to sort a list. -/\ndef merge_sort : list \u03b1 \u2192 list \u03b1\n| []        := []\n| [a]       := [a]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  exact merge r (merge_sort l\u2081) (merge_sort l\u2082)\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_cons_cons {a b} {l l\u2081 l\u2082 : list \u03b1}\n  (h : split (a::b::l) = (l\u2081, l\u2082)) :\n  merge_sort r (a::b::l) = merge r (merge_sort r l\u2081) (merge_sort r l\u2082) :=\nbegin\n  suffices : \u2200 (L : list \u03b1) h1, @@and.rec\n    (\u03bb a a (_ : length l\u2081 < length l + 1 + 1 \u2227\n      length l\u2082 < length l + 1 + 1), L) h1 h1 = L,\n  { simp [merge_sort, h], apply this },\n  intros, cases h1, refl\nend\n\nsection correctness\n\ntheorem perm_merge : \u2200 (l l' : list \u03b1), merge r l l' ~ l ++ l'\n| []       []        := by simp [merge]\n| []       (b :: l') := by simp [merge]\n| (a :: l) []        := by simp [merge]\n| (a :: l) (b :: l') := begin\n  by_cases a \u227c b,\n  { simpa [merge, h] using perm_merge _ _ },\n  { suffices : b :: merge r (a :: l) l' ~ a :: (l ++ b :: l'), {simpa [merge, h]},\n    exact ((perm_merge _ _).cons _).trans ((swap _ _ _).trans (perm_middle.symm.cons _)) }\nend\n\ntheorem perm_merge_sort : \u2200 l : list \u03b1, merge_sort r l ~ l\n| []        := by simp [merge_sort]\n| [a]       := by simp [merge_sort]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  apply (perm_merge r _ _).trans,\n  exact ((perm_merge_sort l\u2081).append (perm_merge_sort l\u2082)).trans (perm_split e).symm\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\n@[simp] lemma length_merge_sort (l : list \u03b1) : (merge_sort r l).length = l.length :=\n(perm_merge_sort r _).length_eq\n\nsection total_and_transitive\nvariables {r} [is_total \u03b1 r] [is_trans \u03b1 r]\n\ntheorem sorted.merge : \u2200 {l l' : list \u03b1}, sorted r l \u2192 sorted r l' \u2192 sorted r (merge r l l')\n| []       []        h\u2081 h\u2082 := by simp [merge]\n| []       (b :: l') h\u2081 h\u2082 := by simpa [merge] using h\u2082\n| (a :: l) []        h\u2081 h\u2082 := by simpa [merge] using h\u2081\n| (a :: l) (b :: l') h\u2081 h\u2082 := begin\n  by_cases a \u227c b,\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r l (b :: l')), r a b',\n    { simpa [merge, h, h\u2081.of_cons.merge h\u2082] },\n    intros b' bm,\n    rcases (show b' = b \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa [or.left_comm] using\n      (perm_merge _ _ _).subset bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact rel_of_sorted_cons h\u2081 _ bl },\n    { exact trans h (rel_of_sorted_cons h\u2082 _ bl') } },\n  { suffices : \u2200 (b' : \u03b1) (_ : b' \u2208 merge r (a :: l) l'), r b b',\n    { simpa [merge, h, h\u2081.merge h\u2082.of_cons] },\n    intros b' bm,\n    have ba : b \u227c a := (total_of r _ _).resolve_left h,\n    rcases (show b' = a \u2228 b' \u2208 l \u2228 b' \u2208 l', by simpa using\n      (perm_merge _ _ _).subset bm) with be | bl | bl',\n    { subst b', assumption },\n    { exact trans ba (rel_of_sorted_cons h\u2081 _ bl) },\n    { exact rel_of_sorted_cons h\u2082 _ bl' } }\nend\n\nvariable (r)\n\ntheorem sorted_merge_sort : \u2200 l : list \u03b1, sorted r (merge_sort r l)\n| []        := by simp [merge_sort]\n| [a]       := by simp [merge_sort]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l\u2081 l\u2082,\n  cases length_split_lt e with h\u2081 h\u2082,\n  rw [merge_sort_cons_cons r e],\n  exact (sorted_merge_sort l\u2081).merge (sorted_merge_sort l\u2082)\nend\nusing_well_founded\n{ rel_tac := \u03bb_ _, `[exact \u27e8_, inv_image.wf length nat.lt_wf\u27e9],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_eq_self [is_antisymm \u03b1 r] {l : list \u03b1} : sorted r l \u2192 merge_sort r l = l :=\neq_of_perm_of_sorted (perm_merge_sort _ _) (sorted_merge_sort _ _)\n\ntheorem merge_sort_eq_insertion_sort [is_antisymm \u03b1 r] (l : list \u03b1) :\n  merge_sort r l = insertion_sort r l :=\neq_of_perm_of_sorted ((perm_merge_sort r l).trans (perm_insertion_sort r l).symm)\n  (sorted_merge_sort r l) (sorted_insertion_sort r l)\n\nend total_and_transitive\nend correctness\n\n@[simp] theorem merge_sort_nil : [].merge_sort r = [] :=\nby rw list.merge_sort\n\n@[simp] theorem merge_sort_singleton (a : \u03b1) : [a].merge_sort r = [a] :=\nby rw list.merge_sort\n\nend merge_sort\nend sort\n\n/- try them out! -/\n\n--#eval insertion_sort (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\n--#eval merge_sort     (\u03bb m n : \u2115, m \u2264 n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\nend list\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/list/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7231940328560927}}
{"text": "/-\nCopyright (c) 2022 Matthias Uschold. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Matthias Uschold.\n-/\nimport .def_amenable\nimport topology.continuous_function.bounded\nimport topology.continuous_function.basic\n\n\n/-!\n# Quotients of Amenable groups \n\nIn this file, we prove that quotients of amenable groups are again amenable \n\n## Main Statements\n- `amenable_of_quotient'`  : If G \u2192* H is a surjective group homomorphism and G is amenable,\n                            then so is H. \n- `amenable_of_quotient`   : If G is amenable, then so is G/N for every normal subgroup N.\n- `amenable_of_iso`        : Amenability is preserved under (multiplicative) isomorphisms.\n\n\n## References \n* [C. L\u00f6h, *Geometric Group Theory*, Proposition 9.1.6 (2)][loeh17]\n* [A.L.T. Paterson, *Amenability*, Proposition 0.16 (2)][Paterson1988]\n\n\n## Tags\nquotients, amenable, amenability\n-/\n\n\n\nopen classical\nopen function \n\n\n\nvariables \n{G:Type*}\n[group G] \n\n{H:Type*}\n[group H] \n\n(\u03c0: G \u2192* H)\n(pi_surj : surjective \u03c0)\n\n\nnamespace amenable_quotient\n\nopen mean \n\n/--The pushforward mean is left-invariant if the \nmap is surjective-/\nlemma mean_pushforward_leftinv \n  (m : left_invariant_mean G)\n  (pi_surj : surjective \u03c0)\n  : \u2200(h:H), \u2200(f: bounded_continuous_function H \u211d), \n        (mean_pushforward \u03c0 m) (left_translate h f) \n      = (mean_pushforward \u03c0 m) f\n:= begin \n  assume h : H,\n  assume f : bounded_continuous_function H \u211d,\n\n  -- h has a preimage under \u03c0 \n  have : \u2203 (g:G), \u03c0 g = h \n        := by tauto,\n  rcases this with \u27e8g, pi_gh\u27e9,\n\n  --main step: The pullback of (left_translate h f) \n  -- is the left_translate of (via g) the pullback of f\n  have translate_pullback:\n      pull_bcont \u03c0 (left_translate h f) = left_translate g (pull_bcont \u03c0 f),\n  {\n    ext (x:G),\n    calc  pull_bcont \u03c0 (left_translate h f) x \n        = (left_translate h f) (\u03c0 x)\n          : by tauto \n    ... = f (h\u207b\u00b9*(\u03c0 x))\n          : by tauto \n    ... = f ((\u03c0 g)\u207b\u00b9 * (\u03c0 x))\n          : by rw pi_gh\n    ... = f ((\u03c0 (g\u207b\u00b9)) * (\u03c0 x))\n          : by norm_num\n    ... = f (\u03c0 (g\u207b\u00b9 * x))\n          : by simp[mul_hom.map_mul]\n    ... = (pull_bcont \u03c0 f) (g\u207b\u00b9 * x)\n          : by tauto\n    ... = (left_translate g (pull_bcont \u03c0 f)) x\n          : by tauto,\n  },\n  \n  calc  (mean_pushforward \u03c0 m) (left_translate h f)\n      = m (pull_bcont \u03c0 (left_translate h f))\n        : by tauto \n  ... = m (left_translate g (pull_bcont \u03c0 f))\n        : by rw translate_pullback \n  ... = m (pull_bcont \u03c0 f)\n        : by exact m.left_invariance _ _\n  ... = (mean_pushforward \u03c0 m) f\n        : by tauto,\nend\n\n/-- pushforward invariant mean-/\n@[simp]\nnoncomputable def inv_mean_pushforward \n  (m : left_invariant_mean G)\n  (pi_surj : surjective \u03c0)\n  : left_invariant_mean H \n:= left_invariant_mean.mk (mean_pushforward \u03c0 m) \n                  (mean_pushforward_leftinv \u03c0  m pi_surj)\n\n\nend amenable_quotient\n\n\n/--The target group is amenable if \u03c0 is surjective -/\ntheorem amenable_of_quotient'  \n  (pi_surj : surjective \u03c0)\n  (G_am: amenable G)\n  : amenable H \n:= amenable_of_invmean (amenable_quotient.inv_mean_pushforward \u03c0 (invmean_of_amenable G_am) pi_surj)\n\n/--Formulation with quotients-/\ntheorem amenable_of_quotient \n  {N : subgroup G}\n  (nN : N.normal)\n  (G_am: amenable G)\n  : amenable (G\u29f8N)\n:= amenable_of_quotient' _ (quotient_group.mk'_surjective N) G_am\n\n\n\n-- preparations for amenable of iso \n\n\n\n\n/--a multiplicative homomorphism between groups is a monoid homomorphism-/\ndef monoidhom_of_mulhom \n  (f: mul_hom G H)\n  : G \u2192* H \n:= monoid_hom.mk f.to_fun \n      (begin \n        have : f.to_fun 1 * f.to_fun 1 = f.to_fun 1,\n        {\n          calc  f.to_fun 1 * f.to_fun 1 \n              = f.to_fun (1*1) \n                : by rw f.map_mul'\n          ... = f.to_fun 1 \n                : by congr'; by group,\n        },\n        by finish,\n      end)\n    f.map_mul'\n\n@[simp]\nlemma monoidhom_of_mulhom_to_fun\n   {f: mul_hom G H}\n  : (monoidhom_of_mulhom f).to_fun = f.to_fun  \n:= by refl\n\n/--Amenability is preserved under (multiplicative) isomorphisms-/\ntheorem amenable_of_iso \n  {H : Type*} [group H]\n  (i : G \u2243* H)\n  (G_am : amenable G)\n  : amenable H \n:= begin \n  -- we obtain a surjective group hom G \u2192* H \n  let p: G \u2192* H := monoidhom_of_mulhom i.to_mul_hom, \n  have p_surj : surjective p,\n  {\n    dsimp[p],\n    change surjective (monoidhom_of_mulhom i.to_mul_hom).to_fun,\n    rw monoidhom_of_mulhom_to_fun,\n    exact mul_equiv.surjective i,\n  },\n  exact amenable_of_quotient' p p_surj G_am,\nend \n\n\n\n", "meta": {"author": "matthias567", "repo": "lean-amenable-release", "sha": "32ea6fdbada245e334d6c20288691b454e3922a9", "save_path": "github-repos/lean/matthias567-lean-amenable-release", "path": "github-repos/lean/matthias567-lean-amenable-release/lean-amenable-release-32ea6fdbada245e334d6c20288691b454e3922a9/src/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7231490807684227}}
{"text": "import data.list.basic data.list.big_operators logic.embedding\nimport tactic.squeeze\n\nnamespace list\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}\n\nopen list\n\ndef all_prop {\u03b1 : Type*} (p : \u03b1 \u2192 Prop) : \u2200 (l : list \u03b1), Prop\n| nil := true\n| (a :: l) := (p a) \u2227 (all_prop l)\n\nlemma all_prop_iff {\u03b1 : Type*} {p : \u03b1 \u2192 Prop} : \u2200 {l : list \u03b1},\n all_prop p l \u2194 \u2200 a, a \u2208 l \u2192 p a \n| nil := by {rw[all_prop,true_iff],intros a ha,cases ha,}\n| (cons m l) := \nby {rw[all_prop],split,\n {rintro \u27e8hm,hl\u27e9 a ha,rcases ha,exact ha.symm \u25b8 hm,\n  exact (all_prop_iff.mp hl) a ha},\n {intro h,split,\n  exact h m (mem_cons_self m l),\n  apply all_prop_iff.mpr,intros a ha,\n  exact h a (mem_cons_of_mem m ha),\n }\n}\n\n\ndef cons_embedding (a : \u03b1) : list \u03b1 \u21aa list \u03b1 := \u27e8cons a,cons_injective\u27e9\n\ndef concat_embedding (a : \u03b1) : list \u03b1 \u21aa list \u03b1 := \n \u27e8\u03bb l, l ++ [a],\u03bb l\u2081 l\u2082 e, append_right_cancel e\u27e9\n\ndef rtake (n : \u2115) (l : list \u03b1) := l.drop (l.length - n)\n\ndef rdrop (n : \u2115) (l : list \u03b1) := l.take (l.length - n)\n\nlemma eq_singleton : \u2200 (l : list \u03b1) (h : l.length = 1),\n l = [l.nth_le 0 (by {rw[h],exact nat.lt_succ_self 0})]\n| [] h := by {cases h}\n| [a] h := rfl\n| (_ :: _ :: _) h := by {cases h}\n\nlemma nth_le_congr (l : list \u03b1) {n\u2081 n\u2082 : \u2115} (h\u2081 : n\u2081 < l.length) (e : n\u2081 = n\u2082) : \n l.nth_le n\u2081 h\u2081 = l.nth_le n\u2082 (e \u25b8 h\u2081) := by {cases e,refl}\n\nlemma nth_le_append' : \u2200 (l\u2081 : list \u03b1) {l\u2082 : list \u03b1} {n : \u2115} (hn : n < l\u2082.length),\n (l\u2081 ++ l\u2082).nth_le (l\u2081.length + n) ((list.length_append l\u2081 l\u2082).symm \u25b8 (nat.add_lt_add_left hn l\u2081.length)) = l\u2082.nth_le n hn \n| list.nil l\u2082 n hn := by {congr,dsimp[length],rw[zero_add]}\n| (a :: l\u2081) l\u2082 n hn := begin \n let h := nth_le_append' l\u2081 hn,\n dsimp[append],rw[h.symm],\n have : l\u2081.length + 1 + n = (l\u2081.length + n) + 1 := by {rw[add_assoc,add_comm 1,\u2190 add_assoc],},\n rw[nth_le_congr _ _ this,nth_le],refl,  \nend\n\n#check list.nth_le_take \n\nlemma nth_le_take_old : \u2200 {n m : \u2115} {l : list \u03b1} (hn : n < m) (hm : m \u2264 l.length),\n (l.take m).nth_le n (by {rw[length_take,min_eq_left hm], exact hn}) = \n   l.nth_le n (lt_of_lt_of_le hn hm)\n| n 0 l hn hm := by {cases hn}\n| n (m + 1) [] hn hm := by {cases hm}\n| 0 (m + 1) (a :: l) hn hm := rfl\n| (n + 1) (m + 1) (a :: l) hn hm := \n   nth_le_take_old (nat.lt_of_succ_lt_succ hn) (nat.le_of_succ_le_succ hm)\n\n#check list.nth_le_drop\n\nlemma nth_le_drop_old : \u2200 {n m : \u2115} {l : list \u03b1} (h : m + n < l.length),\n (l.drop m).nth_le n (by {rw[length_drop],rw[add_comm] at h,exact lt_tsub_iff_right.mpr h}) =\n  l.nth_le (m + n) h \n| n 0 l h := (nth_le_congr l h (zero_add n)).symm\n| n (m + 1) [] h := by {cases h}\n| n (m + 1) (a :: l) h := begin \n   dsimp[drop],\n   have : m + 1 + n = (m + n) + 1 := by {rw[add_assoc,add_comm 1,\u2190 add_assoc],},\n   rw[this] at h,\n   rw[nth_le_congr _ _ this],dsimp[nth_le],apply nth_le_drop_old,\nend\n\nlemma drop_eq_last {n : \u2115} {l : list \u03b1} (h : l.length = n + 1) :\n  (l.drop n) = [l.nth_le n (h.symm \u25b8 n.lt_succ_self)] := \nbegin\n let t := l.drop n,\n let a := l.nth_le n (h.symm \u25b8 n.lt_succ_self),\n change t = [a],\n let a' := t.nth_le 0 _,\n have : a = a' := begin\n  dsimp[a,a',last],\n  let h := @list.nth_le_drop_old \u03b1 0 n l (by {rw[h,add_zero],exact n.lt_succ_self}), \n  rw[list.nth_le_congr _ _ (add_zero n)] at h,\n  exact h.symm,\n end,\n rw[this],\n have t_len : t.length = 1 := by { rw[list.length_drop,h,nat.add_sub_cancel_left]},\n exact eq_singleton t t_len,\nend\n\n#check list.sum_singleton\n\nlemma sum_singleton_old [add_monoid \u03b1] (a : \u03b1) : [a].sum = a := \n by {rw[list.sum_cons,sum_nil,add_zero]}\n \nend list", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/data/list_extra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7231225978023249}}
{"text": "import data.real.basic\n\ndef odd_fun (f : \u211d \u2192 \u211d) := \u2200 x, f (-x) = -f x\n\nexample (f g : \u211d \u2192 \u211d) : odd_fun f \u2192 odd_fun g \u2192  odd_fun (g \u2218 f) :=\nbegin\n  intros hf hg x,\n  calc (g \u2218 f) (-x)\n      = g (f (-x)) : rfl\n  ... = g (-f x)   : by rw hf\n  ... =-g (f x)    : by rw hg\n  ... = -(g \u2218 f) x : rfl,\nend\n", "meta": {"author": "saradiazr11", "repo": "IMO_en_Lean", "sha": "d8fb219af4d0c1afaecb36556ac5ecf8dd03b453", "save_path": "github-repos/lean/saradiazr11-IMO_en_Lean", "path": "github-repos/lean/saradiazr11-IMO_en_Lean/IMO_en_Lean-d8fb219af4d0c1afaecb36556ac5ecf8dd03b453/src/Elementos/Composicion_Funciones_Impares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.7853085884247212, "lm_q1q2_score": 0.7231040474379851}}
{"text": "variables x y z w : \u2115\n\nexample (h\u2081 : x = y) (h\u2082 : y = z) (h\u2083 : z = w) : x = w :=\nbegin\n  apply eq.trans h\u2081,\n  apply eq.trans h\u2082,\n  assumption\nend\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch5/ex0204.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7231040324573955}}
{"text": "/-\nThis is a sorry-free file covering the material on Wednesday afternoon\nat LFTCM2020. It's how to build some algebraic structures in Lean\n-/\n\nimport data.rat.defs -- we'll need the rationals at the end of this file\n\n/-\nAs a mathematician I essentially always start my Lean files with the following line:\n-/\nimport tactic\n\n/- That gives me access to all Lean's tactics\n(see https://leanprover-community.github.io/mathlib_docs/tactics.html)\n-/\n\n/-\n\n## The point of this file\n\nThe idea of this file is to show how to build in Lean what the computer scientists call\n\"an algebraic heirarchy\", and what mathematicians call \"groups, rings, fields, modules etc\".\n\nFirstly, we will define groups, and develop a basic interface for groups.\n\nThen we will define rings, fields, modules, vector spaces, and just demonstrate\nthat they are usable, rather than making a complete interface for all of them.\n\nLet's start with the theory of groups. Unfortunately Lean has groups already,\nso we will have to do everything in a namespace\n-/\n\n\nnamespace lftcm\n\n/-\n\n... which means that now when we define `group`, it will actually be called `lftcm.group`.\n\n## Notation typeclasses\n\nTo make a term of type `has_mul G`, you need to give a map G^2 \u2192 G (or\nmore precisely, a map `has_mul.mul : G \u2192 G \u2192 G`. Lean's notation `g * h`\nis notation for `has_mul.mul g h`. Furthermore, `has_mul` is a class.\n\nIn short, this means that if you write `[has_mul G]` then `G` will\nmagically have a multiplication called `*` (satisfying no axioms).\n\nSimilarly `[has_one G]` gives you `has_one.one : G` with notation `1 : G`,\nand `[has_inv G]` gives you `has_inv.inv : G \u2192 G` with notation `g\u207b\u00b9 : G`\n\n## Definition of a group\n\nIf `G` is a type, equipped with `* : G^2 \u2192 G`, `1 : G` and `\u207b\u00b9 : G \u2192 G`\nthen it's a group if it satisfies the group axioms.\n\n-/\n\n-- `group G` is the type of group structures on a type `G`.\n-- first we ask for the structure\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n-- and then we ask for the axioms\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\n/-\n\nAdvantages of this approach: axioms look lovely.\n\nDisadvantage: what if I want the group law to be `+`?? I have embedded `has_mul`\nin the definition.\n\nLean's solution: develop a `to_additive` metaprogram which translates all theorems about\n`group`s (with group law `*`) to theorems about `add_group`s (with group law `+`). We will\nnot go into details here.\n\n-/\n\nnamespace group\n\n-- let G be a group\n\nvariables {G : Type} [group G]\n\n/-\nLemmas about groups are proved in this namespace. We already have some!\nAll the group axioms are theorems in this namespace. Indeed we have just defined\n\n`group.mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c)`\n`group.one_mul : \u2200 (a : G), 1 * a = a`\n`group.mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1`\n\nBecause we are in the `group` namespace, we don't need to write `group.`\neverywhere.\n\nLet's put some more theorems into the `group` namespace.\n\nWe definitely need `mul_one` and `mul_right_inv`, and it's a fun exercise to\nget them. Here is a route:\n\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n-/\n\nlemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c :=\n calc b = 1 * b         : by rw one_mul\n    ... = (a\u207b\u00b9 * a) * b : sorry\n    ... = a\u207b\u00b9 * (a * b) : sorry\n    ... = a\u207b\u00b9 * (a * c) : sorry\n    ... = (a\u207b\u00b9 * a) * c : sorry\n    ... = 1 * c         : sorry\n    ... = c             : sorry\n\n-- more mathlib-ish proof:\nlemma mul_left_cancel' (a b c : G) (Habac : a * b = a * c) : b = c :=\nbegin\n  rw [\u2190one_mul b, \u2190mul_left_inv a, mul_assoc, Habac, \u2190mul_assoc, mul_left_inv, one_mul],\nend\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  -- \u22a2 a\u207b\u00b9 * (a * x) = a\u207b\u00b9 * y\n  sorry\nend\n\n-- The same proof\nlemma mul_eq_of_eq_inv_mul' {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nmul_left_cancel a\u207b\u00b9 _ _ $ by rwa [\u2190mul_assoc, mul_left_inv, one_mul]\n\n/-\n\nSo now we can finally prove `mul_one` and `mul_right_inv`.\n\nBut before we start, let's learn a little bit about the simplifier.\n\n## The `simp` tactic -- Lean's simplifier\n\nWe have the theorems (axioms) `one_mul g : 1 * g = g` and\n`mul_left_inv g : g\u207b\u00b9 * g = 1`. Both of these theorems are of\nthe form `A = B`, with `A` more complicated than `B`. This means\nthat they are *perfect* theorems for the simplifier. Let's teach\nthose theorems to the simplifier, by adding the `@[simp]` attribute to them.\nAn \"attribute\" is just a tag which we attach to a theorem (or definition).\n-/\n\nattribute [simp] one_mul mul_left_inv\n\n/-\n\nNow let's prove `mul_one` using the simplifier. This also a perfect\n`simp` lemma, so let's also add the `simp` tag to it.\n\n-/\n\n@[simp] theorem mul_one (a : G) : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  -- \u22a2 1 = a\u207b\u00b9 * a\n  simp,\nend\n\n/-\nThe simplifier solved `1 = a\u207b\u00b9 * a` because it knew `mul_left_inv`.\nFeel free to comment out the `attribute [simp] one_mul mul_left_inv` line\nabove, and observe that the proof breaks.\n\n-/\n\n-- term mode proof\ntheorem mul_one' (a : G) : a * 1 = a :=\nmul_eq_of_eq_inv_mul $ by simp\n\n-- see if you can get the simplifier to do this one too\n@[simp] theorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1 :=\nbegin\n  sorry\nend\n\n-- Now here's a question. Can we train the simplifier to solve the following problem:\n\n--example (a b c d : G) :\n--  ((a * b)\u207b\u00b9 * a * 1\u207b\u00b9\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * b * b * 1 * 1\u207b\u00b9)\u207b\u00b9 = (c\u207b\u00b9\u207b\u00b9 * d * d\u207b\u00b9 * 1\u207b\u00b9\u207b\u00b9 * c\u207b\u00b9\u207b\u00b9\u207b\u00b9)\u207b\u00b9\u207b\u00b9 :=\n--by simp\n\n-- Remove the --'s and see that it fails. Let's see if we can get it to work.\n\n-- We start with two very natural `simp` lemmas.\n\n@[simp] lemma one_inv : (1 : G)\u207b\u00b9 = 1 :=\nbegin\n  sorry\nend\n\n@[simp] lemma inv_inv (a : G) : a\u207b\u00b9\u207b\u00b9 = a :=\nbegin\n  sorry\nend\n\n-- Here is a riskier looking `[simp]` lemma.\n\nattribute [simp] mul_assoc -- recall this says (a * b) * c = a * (b * c)\n\n-- The simplifier will now push all brackets to the right, which means\n-- that it's worth proving the following two lemmas and tagging\n-- them `[simp]`, so that we can still cancel a with a\u207b\u00b9 in these situations.\n\n@[simp] lemma inv_mul_cancel_left (a b : G) : a\u207b\u00b9 * (a * b) = b :=\nbegin\n  sorry\nend\n\n@[simp] lemma mul_inv_cancel_left (a b : G) : a * (a\u207b\u00b9 * b) = b :=\nbegin\n  sorry\nend\n\n-- Finally, let's make a `simp` lemma which enables us to\n-- reduce all inverses to inverses of variables\n@[simp] lemma mul_inv_rev (a b : G) : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  sorry\nend\n\n/-\n\nIf you solved them all -- congratulations!\nYou have just turned Lean's simplifier into a normalising confluent\nrewriting system for groups, following Knuth-Bendix.\n\nhttps://en.wikipedia.org/wiki/Confluence_(abstract_rewriting)#Motivating_examples\n\nIn other words, the simplifier will now put any element of a free group\ninto a canonical normal form, and can hence solve the word problem\nfor free groups.\n\n-/\nexample (a b c d : G) :\n  ((a * b)\u207b\u00b9 * a * 1\u207b\u00b9\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * b * b * 1 * 1\u207b\u00b9)\u207b\u00b9 = (c\u207b\u00b9\u207b\u00b9 * d * d\u207b\u00b9 * 1\u207b\u00b9\u207b\u00b9 * c\u207b\u00b9\u207b\u00b9\u207b\u00b9)\u207b\u00b9\u207b\u00b9 :=\nby simp\n\n-- Abstract example of the power of classes: we can define products of groups with instances\n\ninstance (G : Type) [group G] (H : Type) [group H] : group (G \u00d7 H) :=\n{ mul := \u03bb k l, (k.1*l.1, k.2*l.2),\n  one := (1,1),\n  inv := \u03bb k, (k.1\u207b\u00b9, k.2\u207b\u00b9),\n  mul_assoc := begin\n    intros a b c,\n    cases a, cases b, cases c,\n    ext;\n    simp,\n  end,\n  one_mul := begin\n    sorry\n  end,\n  mul_left_inv := begin\n    sorry\n  end }\n\n-- the type class inference system now knows that products of groups are groups\nexample (G H K : Type) [group G] [group H] [group K] : group (G \u00d7 H \u00d7 K) :=\nby apply_instance\n\nend group\n\n-- let's make a group of order two.\n\n-- First the elements {+1, -1}\ninductive mu2\n| p1 : mu2\n| m1 : mu2\n\nnamespace mu2\n\n-- Now let's do some CS stuff:\n\n-- 1) prove it has decidable equality\nattribute [derive decidable_eq] mu2\n\n-- 2) prove it is finite\ninstance : fintype mu2 := \u27e8\u27e8[mu2.p1, mu2.m1], by simp\u27e9, \u03bb x, by cases x; simp\u27e9\n\n-- now back to the maths.\n\n-- Define multiplication by doing all cases\ndef mul : mu2 \u2192 mu2 \u2192 mu2\n| p1 p1 := p1\n| p1 m1 := m1\n| m1 p1 := m1\n| m1 m1 := p1\n\ninstance : has_mul mu2 := \u27e8mul\u27e9\n\n-- identity\ndef one : mu2 := p1\n\n-- notation\ninstance : has_one mu2 := \u27e8one\u27e9\n\n-- inverse\ndef inv : mu2 \u2192 mu2 := id\n\n-- notation\ninstance : has_inv mu2 := \u27e8inv\u27e9\n\n-- currently we have notation but no axioms\n\nexample : p1 * m1 * m1 = p1\u207b\u00b9 * p1 := rfl -- all true by definition\n\n-- now let's make it a group\ninstance : group mu2 :=\nbegin\n  -- first define the structure\n  refine_struct { mul := mul, one := one, inv := inv },\n  -- now we have three goals (the axioms)\n  all_goals {exact dec_trivial}\nend\n\nend mu2\n\n\n-- Now let's build rings and modules and stuff (via monoids and add_comm_groups)\n\n-- a monoid is a group without inverses\nclass monoid (M : Type) extends has_mul M, has_one M :=\n(mul_assoc : \u2200 (a b c : M), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : M), 1 * a = a)\n(mul_one : \u2200 (a : M), a * 1 = a)\n\n-- additive commutative groups from first principles\nclass add_comm_group (A : Type) extends has_add A, has_zero A, has_neg A :=\n(add_assoc : \u2200 (a b c : A), a + b + c = a + (b + c))\n(zero_add : \u2200 (a : A), 0 + a = a)\n(add_left_neg : \u2200 (a : A), -a + a = 0)\n(add_comm : \u2200 a b : A, a + b = b + a)\n\n-- Notation for subtraction is handy to have; define a - b to be a + (-b)\ninstance (A : Type) [add_comm_group A] : has_sub A := \u27e8\u03bb a b, a + -b\u27e9\n\n-- rings are additive abelian groups and multiplicative monoids,\n-- with distributivity\nclass ring (R : Type) extends monoid R, add_comm_group R :=\n(mul_add : \u2200 (a b c : R), a * (b + c) = a * b + a * c)\n(add_mul : \u2200 (a b c : R), (a + b) * c = a * c + b * c)\n\n-- for commutative rings, add commutativity of multiplication\nclass comm_ring (R : Type) extends ring R :=\n(mul_comm : \u2200 a b : R, a * b = b * a)\n\n/-- Typeclass for types with a scalar multiplication operation, denoted `\u2022` (`\\bu`) -/\nclass has_scalar (R : Type) (M : Type) := (smul : R \u2192 M \u2192 M)\n\ninfixr (name:=lftcm_smul) ` \u2022 `:73 := has_scalar.smul\n\n-- modules for a ring\nclass module (R : Type) [ring R] (M : Type) [add_comm_group M]\nextends has_scalar R M :=\n(smul_add : \u2200(r : R) (x y : M), r \u2022 (x + y) = r \u2022 x + r \u2022 y)\n(add_smul : \u2200(r s : R) (x : M), (r + s) \u2022 x = r \u2022 x + s \u2022 x)\n(mul_smul : \u2200 (r s : R) (x : M), (r * s) \u2022 x = r \u2022 s \u2022 x)\n(one_smul : \u2200 x : M, (1 : R) \u2022 x = x)\n\n-- for fields we let \u207b\u00b9 be defined on the entire field, and demand 0\u207b\u00b9 = 0\n-- and that a\u207b\u00b9 * a = 1 for non-zero a. This is merely for convenience;\n-- one can easily check that it's mathematically equivalent to the usual\n-- definition of a field.\nclass field (K : Type) extends comm_ring K, has_inv K :=\n(zero_ne_one : (0 : K) \u2260 1)\n(mul_inv_cancel : \u2200 {a : K}, a \u2260 0 \u2192 a * a\u207b\u00b9 = 1)\n(inv_zero : (0 : K)\u207b\u00b9 = 0)\n\n-- the type of vector spaces\ndef vector_space (K : Type) [field K] (V : Type) [add_comm_group V] := module K V\n\n/-\nExercise for the reader: define manifolds, schemes, perfectoid spaces in Lean.\nAll have been done! As you can see, it is clearly *feasible*, although it does\nsometimes take time to get it right. It is all very much work in progress.\n\nThe extraordinary thing is that although these computer theorem\nprovers have been around for about 50 years, there has never been a serious\neffort to make the standard definitions used all over modern mathematics in\none of them, and this is why these systems are rarely used in mathematics departments.\nChanging this is one of the goals of the Leanprover community.\n-/\n\n/-\n\nLet's check that we can make the rational numbers into a field. Of course\nthey are already a field in Lean, but remember that when we say `field`\nbelow, we mean our just-defined structure `lftcm.field`.\n\n-/\n\n-- the rationals are a field (easy because all the work is done in the import)\ninstance : field \u211a :=\n{ mul := (*),\n  one := 1,\n  mul_assoc := rat.mul_assoc,\n  one_mul := rat.one_mul,\n  mul_one := rat.mul_one,\n  add := (+),\n  zero := 0,\n  neg := has_neg.neg, -- no () trickery for unary operators\n  add_assoc := rat.add_assoc,\n  zero_add := rat.zero_add,\n  add_left_neg := rat.add_left_neg,\n  add_comm := rat.add_comm,\n  mul_add := rat.mul_add,\n  add_mul := rat.add_mul,\n  mul_comm := rat.mul_comm,\n  inv := has_inv.inv, -- see neg\n  zero_ne_one := rat.zero_ne_one,\n  mul_inv_cancel := rat.mul_inv_cancel,\n  inv_zero := inv_zero -- I don't know why rat.inv_zero was never explicitly defined\n  }\n\n/-\nBelow is evidence that we can prove basic theorems about these structures.\nNote however that it is a *complete pain* because we are *re-implementing*\neverything; `add_comm` defaults to Lean's version for Lean's `add_comm_group`s, so we\nhave to explicitly write `add_comm_group.add_comm` to use our own version.\nThe mathlib versions of these proofs are less ugly.\n-/\n\nvariables {A : Type} [add_comm_group A]\n\nlemma add_comm_group.add_left_cancel (a b c : A) (Habac : a + b = a + c) : b = c :=\nbegin\n  rw \u2190add_comm_group.zero_add b,\n  rw \u2190add_comm_group.add_left_neg a,\n  rw add_comm_group.add_assoc,\n  rw Habac,\n  rw \u2190add_comm_group.add_assoc,\n  rw add_comm_group.add_left_neg,\n  rw add_comm_group.zero_add,\nend\n\nlemma add_comm_group.add_right_neg (a : A) : a + -a = 0 :=\nbegin\n  rw add_comm_group.add_comm,\n  rw add_comm_group.add_left_neg,\nend\n\nlemma add_comm_group.sub_eq_add_neg (a b : A) :\n  a - b = a + -b :=\nbegin\n  -- this is just our definition of subtraction\n  refl\nend\n\nlemma add_comm_group.sub_self (a : A) : a - a = 0 :=\nbegin\n  rw add_comm_group.sub_eq_add_neg,\n  rw add_comm_group.add_comm,\n  rw add_comm_group.add_left_neg,\nend\n\nlemma add_comm_group.neg_eq_of_add_eq_zero (a b : A) (h : a + b = 0) : -a = b :=\nbegin\n  apply add_comm_group.add_left_cancel a,\n  rw h,\n  rw add_comm_group.add_right_neg,\nend\n\nlemma add_comm_group.add_zero (a : A) : a + 0 = a :=\nbegin\n  rw add_comm_group.add_comm,\n  rw add_comm_group.zero_add,\nend\n\nvariables {R : Type} [ring R]\n\nlemma ring.mul_zero (r : R) : r * 0 = 0 :=\nbegin\n  apply add_comm_group.add_left_cancel (r * 0),\n  rw \u2190ring.mul_add,\n  rw add_comm_group.add_zero,\n  rw add_comm_group.add_zero,\nend\n\nlemma ring.mul_neg (a b : R) : a * -b = -(a * b) :=\nbegin\n  sorry\nend\n\nlemma ring.mul_sub (R : Type) [comm_ring R] (r a b : R) : r * (a - b) = r * a - r * b :=\nbegin\n  sorry\nend\n\nlemma comm_ring.sub_mul (R : Type) [comm_ring R] (r a b : R) : (a - b) * r = a * r - b * r :=\nbegin\n  sorry\nend\n\n\n-- etc etc, for thousands of lines of mathlib, which develop the interface\n-- abelian groups, rings, commutative rings, modules, fields, vector spaces etc.\n\nend lftcm\n\n/-\n\n## Advertisement\n\nFinished the natural number game? Have Lean installed? Want more games/exercises?\nTake a look at the following projects, many of which are ongoing but\nthe first three of which are pretty much ready:\n\n*) The complex number game (complete, needs to be played within VS Code)\n\nhttps://github.com/ImperialCollegeLondon/complex-number-game\n\nTo install, type\n`leanproject get ImperialCollegeLondon/complex-number-game`\nand then just open the levels in `src/complex`.\n\n*) Undergraduate level mathematics Lean puzzles (plenty of stuff here,\nand more appearing over the summer):\n\nhttps://github.com/ImperialCollegeLondon/Example-Lean-Projects\n\n`leanproject get ImperialCollegeLondon/Example-Lean-Projects`\n\n*) The max mini-game (a simple browser game like the natural number game)\n\nhttp://wwwf.imperial.ac.uk/~buzzard/xena/max_minigame/\n\n(this is part of what will become the real number game, a game to teach\nseries, sequences and limits etc like the natural number game):\n\n`leanproject get ImperialCollegeLondon/real-number-game`\n\n*) Some commutative algebra experiments (ongoing work to prove the Nullstellensatz,\ngoing slowly because I'm busy):\n\nhttps://github.com/ImperialCollegeLondon/M4P33/blob/1a179372db71ad6802d11eacbc1f02f327d55f8f/src/for_mathlib/commutative_algebra/Zariski_lemma.lean#L80-L81\n\n`leanproject get ImperialCollegeLondon/M4P33`\n\n*) The group theory game (work in progress, expect more progress over the summer,\nas a couple of undergraduates are working on it)\n\nhttps://github.com/ImperialCollegeLondon/group-theory-game\n\n`leanproject get ImperialCollegeLondon/group-theory-game`\n\n*) Galois theory experiments\n\nhttps://github.com/ImperialCollegeLondon/P11-Galois-Theory\n\n`leanproject get ImperialCollegeLondon/P11-Galois-Theory`\n\n*) Beginnings of the theory of condensed sets (currently on hold because\nwe need a good interface for abelian categories in mathlib)\n\nhttps://github.com/ImperialCollegeLondon/condensed-sets\n\n`leanproject get ImperialCollegeLondon/condensed-sets`\n\n## The Xena Project\n\nWhy do these projects exist? I (Kevin Buzzard) am interested in teaching\nundergraduates how to use Lean. I have been running a club at Imperial College London\ncalled the Xena Project for the last three years, I am proud that many Imperial\nmathematics undegraduates have contributed to Lean's maths library, and three of them\n(Chris Hughes, Kenny Lau, Amelia Livingston) have each contributed over 5,000 lines of\ncode. It is non-trivial to get your work into such a polished state that it\nis acceptable to the mathlib maintainers. It is also very good practice.\n\nI am running Lean summer projects this summer, on a Discord server. If you\nknow of any undergraduates who you think might be interested in Lean, please\ndirect them to the Xena Project Discord!\n\nhttps://discord.gg/BgyVYgJ\n\nUndergraduates use Discord for lots of things, and seem to be more likely\nto use a Discord server than the Zulip chat. The Discord server is chaotic and\nfull of off-topic material -- quite unlike the Lean Zulip server, which is\nprofessional and focussed. If you have a serious question about Lean,\nask it on the Zulip chat! But if you know an undergraduate who is interested\nin Lean, they might be interested in the Discord server. We have meetings\nevery Thursday evening (UK time), with live Lean coding and streaming, speedruns,\nthere is music, people posting pictures of cats, Haikus, and so on. To a large\nextent it is run by undergraduates and PhD students. Over the summer (July\nand August 2020) there are also live Twitch talks at https://www.twitch.tv/kbuzzard ,\non Tuesdays 10am and Thursdays 4pm UK time (UTC+1), aimed at mathematics\nundergraduates. It is an informal place for undergraduates to hang out and\nmeet other undergraduates who are interested in Lean.\n\nI believe that it is crucial to make undergraduates aware of computer proof\nverification systems, because one day (possibly a long time in the future,\nbut one day) these things will cause a paradigm shift in the way mathematics\nis done, and the sooner young mathematicians learn about them, the sooner it will happen.\n\nProve a theorem. Write a function. @XenaProject\n\nhttps://twitter.com/XenaProject\n\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "lftcm2020", "sha": "cc683e2b074b61909310746d6acc1fb3d42d6ee2", "save_path": "github-repos/lean/leanprover-community-lftcm2020", "path": "github-repos/lean/leanprover-community-lftcm2020/lftcm2020-cc683e2b074b61909310746d6acc1fb3d42d6ee2/src/exercises_sources/wednesday/algebraic_hierarchy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7231040290434021}}
{"text": "import data.list.basic\nimport tactic\nimport old.extras\n\nopen list \n\nuniverse u \nvariables {\u03b1 : Type u} {L L\u2081 L\u2082 : list (\u03b1)} \n\nnamespace list\n/-\n\nlemma append_singleton_iff {x : \u03b1} : \nL ++ L\u2081 = [x] \u2194 (L = [] \u2227 L\u2081 = [x]) \u2228 (L\u2081 = [] \u2227 L = [x]) :=\nbegin\n  split,\n  { intro h,\n    induction L,\n    left,\n    simp at *,\n    exact h,\n    simp at *,\n    exact \u27e8h.2.2, h.1, h.2.1\u27e9 },\n  { intro h,\n    induction h,\n    { rw [h.1, h.2], tauto },\n    { rw [h.1, h.2], tauto } }\nend   \n-/\n\nlemma singleton_eq_append_iff {x : \u03b1}:\n[x] = L ++ L\u2081 \u2194  (L = [] \u2227 L\u2081 = [x]) \u2228 (L\u2081 = [] \u2227 L = [x])  :=\nbegin\n  split,\n  intro h,\n  exact append_singleton_iff.mp h.symm,\n  intro h,\n  exact (append_singleton_iff.mpr h).symm,\nend\n\nlemma last_split (H : L \u2260 []): \u2203 L\u2081, L = L\u2081 ++ [(L.last H)] := \nbegin\n  have h\u2081 := mem_split (last_mem H),\n  rcases h\u2081 with \u27e8s, t, h\u2081\u27e9,\n  use s,\n  have h\u2082 : t = [], {\n    cases t,\n    refl,\n    simp at *,\n    have h\u2082 : s ++ L.last H :: t_hd :: t_tl \u2260 [] := by simp,\n    have h\u2083 := last_congr H h\u2082 h\u2081,\n    have h\u2084 : L.last H :: t_hd :: t_tl \u2260 [] := by simp,\n    rw last_append (s) (L.last H :: t_hd :: t_tl) h\u2084 at *,\n    simp at *,\n    sorry,\n  },\n  subst_vars,\n  exact h\u2081,\nend\n\nlemma append_singleton_eq_append_singleton {x y : \u03b1} :\nL ++ [x] = L\u2081 ++ [y] \u2192 x = y :=\nbegin\n  intro h,\n  rw append_eq_append_iff at h,\n  cases h,\n  {\n    rcases h with \u27e8a', hl, hr\u27e9,\n    rw singleton_eq_append_iff at hr,\n    cases hr,\n    {\n      cases hr with hrl hrr,\n      simp at *,\n      exact hrr.symm,\n    },\n    {\n      cases hr,\n      subst_vars,\n      contradiction,\n    }\n  },\n  {\n    rcases h with \u27e8c', hl, hr\u27e9,\n    rw singleton_eq_append_iff at hr,\n    cases hr,\n    {\n      cases hr,\n      simp at *,\n      exact hr_right,\n    },\n    {\n      cases hr,\n      subst_vars,\n      contradiction,\n    }\n  }\nend \n\nlemma prefix_append_singleton_iff {x} : \nL\u2081 <+: L ++ [x] \u2194 L\u2081 <+: L \u2228 L\u2081 = L ++ [x] :=\nbegin\n  split,\n  { intro h,\n    rcases h with \u27e8t, ht\u27e9,\n    rw append_eq_append_iff at ht,\n    cases ht,\n    { rcases ht with \u27e8a, hl, hr\u27e9,\n      subst_vars,\n      left,\n      exact prefix_append L\u2081 a },\n    { rcases ht with \u27e8c, hl, hr\u27e9,\n      have h\u2081 := append_singleton_iff.mp hr.symm,\n      cases h\u2081,\n      { cases h\u2081 with hll hlr,\n        subst_vars,\n        left,\n        simp },\n      { cases h\u2081 with hll hlr,\n        subst_vars,\n        right,\n        simp } } },\n  { intro h,\n    cases h,\n    { rcases h with \u27e8t, ht\u27e9,\n      use (t ++ [x]),\n      rw \u2190 ht,\n      simp },\n    { rw h } }\nend\n\nlemma max_prefix {p : list \u03b1 \u2192 Prop} : \nL\u2081 <+: L \u2192 p L\u2081 \u2192 \u2203 L\u2082, L\u2082 <+: L \u2227 p L\u2082 \u2227 (\u2200 L\u2083, L\u2083 <+: L \u2192 p L\u2083 \u2192 L\u2083.length \u2264 L\u2082.length) :=\nbegin\n  apply L.reverse_rec_on,\n  { intro h,\n    simp at *,\n    intro h\u2081,\n    subst_vars,\n    exact h\u2081 },\n  { intros l a ih h h\u2081,\n    rw prefix_append_singleton_iff at *,\n    cases h,\n    { by_cases h' : p (l ++ [a]),\n      use (l ++ [a]),\n      split,\n      { refl },\n      { split,\n        exact h',\n        { intros L\u2083 h\u2082 h\u2083,\n          exact is_prefix.length_le h\u2082 } },\n      specialize ih h h\u2081,\n      rcases ih with \u27e8L\u2082, h\u2082, h\u2083, h\u2084\u27e9,\n      use L\u2082,\n      split,\n      { rw prefix_append_singleton_iff,\n        left,\n        exact h\u2082 },\n      { split,\n        { exact h\u2083 },\n        { intros L\u2083 h\u2085 h\u2086,\n          rw prefix_append_singleton_iff at *,\n          cases h\u2085,\n          { specialize h\u2084 L\u2083 h\u2085 h\u2086,\n            exact h\u2084 },\n          { subst_vars,\n            simp at *,\n            contradiction } } } },\n    { use (l ++ [a]),\n      split,\n      { refl },\n      split,\n      { rw \u2190 h, exact h\u2081 },\n      { intros L\u2083 h\u2082 h\u2083,\n        rw prefix_append_singleton_iff at *,\n        cases h\u2082,\n        simp,\n        exact le_add_right (is_prefix.length_le h\u2082),\n        rw h\u2082 } } }\nend\n\n\n\nlemma min_prefix {p : list \u03b1 \u2192 Prop} : \nL\u2081 <+: L \u2192 p L\u2081 \u2192 \u2203 L\u2082, L\u2082 <+: L \u2227 p L\u2082 \u2227 (\u2200 L\u2083, L\u2083 <+: L \u2192 p L\u2083 \u2192 L\u2082.length \u2264 L\u2083.length) :=\nbegin\n  apply L.reverse_rec_on,\n  {\n    intros h,\n    simp at *,\n    subst_vars,\n    simp,\n  },\n  {\n    intros l a ih h h\u2081,\n    rw prefix_append_singleton_iff at *,\n    cases h,\n    {\n      specialize ih h h\u2081,\n      rcases ih with \u27e8L\u2082, h\u2081, h\u2082, h\u2083\u27e9,\n      use L\u2082,\n      split,\n      rw prefix_append_singleton_iff,\n      left,\n      exact h\u2081,\n      split,\n      exact h\u2082,\n      intros L\u2083 h\u2084 h\u2085,\n      rw prefix_append_singleton_iff at h\u2084,\n      cases h\u2084,\n      {\n        specialize h\u2083 L\u2083 h\u2084 h\u2085,\n        exact h\u2083,\n      } ,\n      {\n        subst_vars,\n      }\n    },\n    {\n\n    }\n  }\nend\n\n\nlemma reduce_option_nil_iff {L : list (option \u03b1)} : (\u2200 x : option \u03b1, x \u2208 L \u2192 x = none) \u2194 reduce_option L = [] :=\nbegin\n  induction L,\n  simp,\n  cases L_hd,\n  simp,\n  exact L_ih,\n  simp,\nend\n\n\nend list", "meta": {"author": "koly777", "repo": "chomsky-schutzenberger-lean", "sha": "cdad7293d28d23ca5373805f1d1cfb38ca46f7f6", "save_path": "github-repos/lean/koly777-chomsky-schutzenberger-lean", "path": "github-repos/lean/koly777-chomsky-schutzenberger-lean/chomsky-schutzenberger-lean-cdad7293d28d23ca5373805f1d1cfb38ca46f7f6/src/extras/list_extras.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7230500283227095}}
{"text": "/- Propositional tableaux prover from Jeremy Avigad's lecture notes. -/\n\nopen expr tactic classical\n\nvariables {p q r s : Prop}\nvariables {a b c d e : Prop}\n\nsection\n\nlocal attribute [instance] classical.prop_decidable\n\n  theorem not_or_of_imp (h : a \u2192 b) : \u00ac a \u2228 b :=\n  if ha : a then or.inr (h ha) else or.inl ha\n\n  theorem imp_iff_not_or : (a \u2192 b) \u2194 (\u00ac a \u2228 b) :=\n  \u27e8not_or_of_imp, or.neg_resolve_left\u27e9\n\n  theorem iff_def : (a \u2194 b) \u2194 (a \u2192 b) \u2227 (b \u2192 a) :=\n  iff_iff_implies_and_implies _ _\n\n  theorem not_not : \u00ac\u00aca \u2194 a :=\n  iff.intro by_contradiction not_not_intro\n\n  theorem not_or_distrib : \u00ac (a \u2228 b) \u2194 \u00ac a \u2227 \u00ac b :=\n  \u27e8\u03bb h, \u27e8\u03bb ha, h (or.inl ha), \u03bb hb, h (or.inr hb)\u27e9,\n   \u03bb \u27e8h\u2081, h\u2082\u27e9 h, or.elim h h\u2081 h\u2082\u27e9\n\n  theorem not_and_of_not_or_not (h : \u00ac a \u2228 \u00ac b) : \u00ac (a \u2227 b)\n  | \u27e8ha, hb\u27e9 := or.elim h (absurd ha) (absurd hb)\n\n  theorem not_and_distrib : \u00ac (a \u2227 b) \u2194 \u00aca \u2228 \u00acb :=\n  \u27e8\u03bb h, if ha : a then or.inr (\u03bb hb, h \u27e8ha, hb\u27e9) else or.inl ha, not_and_of_not_or_not\u27e9\n\nend\n\nmeta def normalize : tactic unit :=\n`[ try { simp only\n   [ not_or_distrib,\n     not_and_distrib,\n     not_not,\n     imp_iff_not_or,\n     not_true_iff,\n     not_false_iff,\n     iff_def ] at *} ]\n\nmeta def find_conj : list expr \u2192 tactic expr\n| []        := failed\n| (e :: es) := do t \u2190 infer_type e,\n                  match t with\n                  | `(%%a \u2227 %%b) := return e\n                  | _            := find_conj es\n                  end\n\nmeta def find_disj : list expr \u2192 tactic expr\n| []        := failed\n| (e :: es) := do t \u2190 infer_type e,\n                  match t with\n                  | `(%%a \u2228 %%b) := return e\n                  | _            := find_disj es\n                  end\n\nmeta def split_conj : tactic unit :=\ndo l \u2190 local_context,\n   e \u2190 find_conj l,\n   cases e,\n   skip\n\nmeta def split_conjs : tactic unit :=\nrepeat split_conj\n\nmeta def split_disj : tactic unit :=\ndo l \u2190 local_context,\n   e \u2190 find_disj l,\n   cases e,\n   skip\n\nmeta def proof_by_contradiction : tactic unit :=\ndo refine ``(classical.by_contradiction _),\n   intro `_,\n   skip\n\nmeta def tab_aux : tactic unit :=\ndo split_conjs,\n   contradiction <|>\n     (split_disj >> tab_aux >> tab_aux)\n\nmeta def tab : tactic unit :=\ndo proof_by_contradiction,\n   normalize,\n   tab_aux\n\nexample : a \u2227 b \u2192 b \u2227 a := by tab\nexample : a \u2227 (a \u2192 b) \u2192 b := by tab\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := by tab\nexample : p \u2228 q \u2194 q \u2228 p := by tab\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := by tab\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := by tab\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by tab\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := by tab\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := by tab\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := by tab\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := by tab\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := by tab\nexample : \u00ac(p \u2227 \u00acp) := by tab\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := by tab\nexample : \u00acp \u2192 (p \u2192 q) := by tab\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := by tab\nexample : p \u2228 false \u2194 p := by tab\nexample : p \u2227 false \u2194 false := by tab\nexample : \u00ac(p \u2194 \u00acp) := by tab\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := by tab\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := by tab\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := by tab\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := by tab\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := by tab\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := by tab\nexample : p \u2228 \u00acp := by tab\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := by tab\n\nexample (h\u2081 : a \u2227 b) (h\u2082 : b \u2227 \u00ac c) : a \u2228 c := by tab\n\nexample (h\u2081 : a \u2227 b) (h\u2082 : b \u2227 \u00ac c) : a \u2227 \u00ac c := by tab\n\nexample : ((a \u2192 b) \u2192 a) \u2192 a := by tab\n\nexample : (a \u2192 b) \u2227 (b \u2192 c) \u2192 a \u2192 c := by tab\n\nexample (\u03b1 : Type) (x y z w : \u03b1) :\n  x = y \u2227 (x = y \u2192 z = w) \u2192 z = w := by tab\n\nexample : \u00ac (a \u2194 \u00ac a) := by tab\n", "meta": {"author": "skbaek", "repo": "tab", "sha": "70909a69464a8713412d640ac630e5e6ef4e43e8", "save_path": "github-repos/lean/skbaek-tab", "path": "github-repos/lean/skbaek-tab/tab-70909a69464a8713412d640ac630e5e6ef4e43e8/tab.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.723050026453969}}
{"text": "variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\n  \u27e8\u03bb h, \u27e8\u03bb x, (h x).left, \u03bb x, (h x).right\u27e9, \u03bb \u27e8hup, huq\u27e9 x, \u27e8hup x, huq x\u27e9\u27e9\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\n  assume hpq hp x,\n  hpq x (hp x)\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\n  assume : (\u2200 x, p x) \u2228 (\u2200 x, q x),\n  this.elim\n    (assume : \u2200 x, p x,\n      assume : \u03b1,\n      or.inl (\u2039\u2200 x, p x\u203a (by assumption)))\n    (assume : \u2200 x, q x,\n      assume : \u03b1,\n      or.inr (\u2039\u2200 x, q x\u203a (by assumption)))\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0601.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7230200013482417}}
{"text": "import data.polynomial\nimport analysis.complex.polynomial -- just a sanity check, probably shouldn't be imported\n\nopen polynomial\n\nclass algebraically_closed_field (k : Type*) extends discrete_field k :=\n(exists_root' : \u2200 (f : polynomial k) (hf : 0 < degree f),\n   \u2203 z : k, is_root f z)\n\nnamespace algebraically_closed_field\n\nvariables {k : Type*} [algebraically_closed_field k]\n\ndef exists_root {f : polynomial k} (hf : 0 < degree f) := \u2203 z : k, is_root f z\n\n-- sanity check\nnoncomputable example : algebraically_closed_field \u2102 :=\n{exists_root' := \u03bb f hf, complex.exists_root hf,\n..complex.discrete_field}\n\nend algebraically_closed_field\n\ndef is_algebraically_closed (k : Type*) [discrete_field k] : Prop :=\n  \u2200 {f : polynomial k} (hf : 0 < degree f), \u2203 z : k, is_root f z\n\n-- sanity check\nexample : is_algebraically_closed \u2102 := \u03bb hf, complex.exists_root\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M4P33", "sha": "1a179372db71ad6802d11eacbc1f02f327d55f8f", "save_path": "github-repos/lean/ImperialCollegeLondon-M4P33", "path": "github-repos/lean/ImperialCollegeLondon-M4P33/M4P33-1a179372db71ad6802d11eacbc1f02f327d55f8f/src/for_mathlib/algebraically_closed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073575, "lm_q2_score": 0.7956581097540518, "lm_q1q2_score": 0.7229492003311553}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Yury Kudryashov\n-/\nimport algebra.group.prod\nimport algebra.group.type_tags\nimport algebra.group.pi\nimport algebra.pointwise\nimport data.equiv.basic\nimport data.set.finite\n\n/-!\n# Torsors of additive group actions\n\nThis file defines torsors of additive group actions.\n\n## Notations\n\nThe group elements are referred to as acting on points.  This file\ndefines the notation `+\u1d65` for adding a group element to a point and\n`-\u1d65` for subtracting two points to produce a group element.\n\n## Implementation notes\n\nAffine spaces are the motivating example of torsors of additive group actions. It may be appropriate\nto refactor in terms of the general definition of group actions, via `to_additive`, when there is a\nuse for multiplicative torsors (currently mathlib only develops the theory of group actions for\nmultiplicative group actions).\n\n## Notations\n\n* `v +\u1d65 p` is a notation for `has_vadd.vadd`, the left action of an additive monoid;\n\n* `p\u2081 -\u1d65 p\u2082` is a notation for `has_vsub.vsub`, difference between two points in an additive torsor\n  as an element of the corresponding additive group;\n\n## References\n\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n* https://en.wikipedia.org/wiki/Affine_space\n\n-/\n\n/-- An `add_torsor G P` gives a structure to the nonempty type `P`,\nacted on by an `add_group G` with a transitive and free action given\nby the `+\u1d65` operation and a corresponding subtraction given by the\n`-\u1d65` operation. In the case of a vector space, it is an affine\nspace. -/\nclass add_torsor (G : out_param Type*) (P : Type*) [out_param $ add_group G]\n  extends add_action G P, has_vsub G P :=\n[nonempty : nonempty P]\n(vsub_vadd' : \u2200 (p1 p2 : P), (p1 -\u1d65 p2 : G) +\u1d65 p2 = p1)\n(vadd_vsub' : \u2200 (g : G) (p : P), g +\u1d65 p -\u1d65 p = g)\n\nattribute [instance, priority 100, nolint dangerous_instance] add_torsor.nonempty\nattribute [nolint dangerous_instance] add_torsor.to_has_vsub\n\n/-- An `add_group G` is a torsor for itself. -/\n@[nolint instance_priority]\ninstance add_group_is_add_torsor (G : Type*) [add_group G] :\n  add_torsor G G :=\n{ vsub := has_sub.sub,\n  vsub_vadd' := sub_add_cancel,\n  vadd_vsub' := add_sub_cancel }\n\n/-- Simplify subtraction for a torsor for an `add_group G` over\nitself. -/\n@[simp] lemma vsub_eq_sub {G : Type*} [add_group G] (g1 g2 : G) : g1 -\u1d65 g2 = g1 - g2 :=\nrfl\n\nsection general\n\nvariables {G : Type*} {P : Type*} [add_group G] [T : add_torsor G P]\ninclude T\n\n/-- Adding the result of subtracting from another point produces that\npoint. -/\n@[simp] lemma vsub_vadd (p1 p2 : P) : p1 -\u1d65 p2 +\u1d65 p2 = p1 :=\nadd_torsor.vsub_vadd' p1 p2\n\n/-- Adding a group element then subtracting the original point\nproduces that group element. -/\n@[simp] lemma vadd_vsub (g : G) (p : P) : g +\u1d65 p -\u1d65 p = g :=\nadd_torsor.vadd_vsub' g p\n\n/-- If the same point added to two group elements produces equal\nresults, those group elements are equal. -/\nlemma vadd_right_cancel {g1 g2 : G} (p : P) (h : g1 +\u1d65 p = g2 +\u1d65 p) : g1 = g2 :=\nby rw [\u2190vadd_vsub g1, h, vadd_vsub]\n\n@[simp] lemma vadd_right_cancel_iff {g1 g2 : G} (p : P) :  g1 +\u1d65 p = g2 +\u1d65 p \u2194 g1 = g2 :=\n\u27e8vadd_right_cancel p, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Adding a group element to the point `p` is an injective\nfunction. -/\nlemma vadd_right_injective (p : P) : function.injective ((+\u1d65 p) : G \u2192 P) :=\n\u03bb g1 g2, vadd_right_cancel p\n\n/-- Adding a group element to a point, then subtracting another point,\nproduces the same result as subtracting the points then adding the\ngroup element. -/\nlemma vadd_vsub_assoc (g : G) (p1 p2 : P) : g +\u1d65 p1 -\u1d65 p2 = g + (p1 -\u1d65 p2) :=\nbegin\n  apply vadd_right_cancel p2,\n  rw [vsub_vadd, add_vadd, vsub_vadd]\nend\n\n/-- Subtracting a point from itself produces 0. -/\n@[simp] lemma vsub_self (p : P) : p -\u1d65 p = (0 : G) :=\nby rw [\u2190zero_add (p -\u1d65 p), \u2190vadd_vsub_assoc, vadd_vsub]\n\n/-- If subtracting two points produces 0, they are equal. -/\nlemma eq_of_vsub_eq_zero {p1 p2 : P} (h : p1 -\u1d65 p2 = (0 : G)) : p1 = p2 :=\nby rw [\u2190vsub_vadd p1 p2, h, zero_vadd]\n\n/-- Subtracting two points produces 0 if and only if they are\nequal. -/\n@[simp] lemma vsub_eq_zero_iff_eq {p1 p2 : P} : p1 -\u1d65 p2 = (0 : G) \u2194 p1 = p2 :=\niff.intro eq_of_vsub_eq_zero (\u03bb h, h \u25b8 vsub_self _)\n\n/-- Cancellation adding the results of two subtractions. -/\n@[simp] lemma vsub_add_vsub_cancel (p1 p2 p3 : P) : p1 -\u1d65 p2 + (p2 -\u1d65 p3) = (p1 -\u1d65 p3) :=\nbegin\n  apply vadd_right_cancel p3,\n  rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd]\nend\n\n/-- Subtracting two points in the reverse order produces the negation\nof subtracting them. -/\n@[simp] lemma neg_vsub_eq_vsub_rev (p1 p2 : P) : -(p1 -\u1d65 p2) = (p2 -\u1d65 p1) :=\nbegin\n  refine neg_eq_of_add_eq_zero (vadd_right_cancel p1 _),\n  rw [vsub_add_vsub_cancel, vsub_self],\nend\n\n/-- Subtracting the result of adding a group element produces the same result\nas subtracting the points and subtracting that group element. -/\nlemma vsub_vadd_eq_vsub_sub (p1 p2 : P) (g : G) : p1 -\u1d65 (g +\u1d65 p2) = (p1 -\u1d65 p2) - g :=\nby rw [\u2190add_right_inj (p2 -\u1d65 p1 : G), vsub_add_vsub_cancel, \u2190neg_vsub_eq_vsub_rev, vadd_vsub,\n       \u2190add_sub_assoc, \u2190neg_vsub_eq_vsub_rev, neg_add_self, zero_sub]\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_right (p1 p2 p3 : P) :\n  (p1 -\u1d65 p3) - (p2 -\u1d65 p3) = (p1 -\u1d65 p2) :=\nby rw [\u2190vsub_vadd_eq_vsub_sub, vsub_vadd]\n\n/-- Convert between an equality with adding a group element to a point\nand an equality of a subtraction of two points with a group\nelement. -/\nlemma eq_vadd_iff_vsub_eq (p1 : P) (g : G) (p2 : P) : p1 = g +\u1d65 p2 \u2194 p1 -\u1d65 p2 = g :=\n\u27e8\u03bb h, h.symm \u25b8 vadd_vsub _ _, \u03bb h, h \u25b8 (vsub_vadd _ _).symm\u27e9\n\nlemma vadd_eq_vadd_iff_neg_add_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 - v\u2081 + v\u2082 = p\u2081 -\u1d65 p\u2082 :=\nby rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, \u2190 add_right_inj (-v\u2081), neg_add_cancel_left, eq_comm]\n\nnamespace set\nopen_locale pointwise\n\n@[simp] lemma singleton_vsub_self (p : P) : ({p} : set P) -\u1d65 {p} = {(0:G)} :=\nby rw [set.singleton_vsub_singleton, vsub_self]\n\ninstance add_action : add_action (set G) (set P) :=\n{ zero_vadd := \u03bb s, by simp [has_vadd.vadd, \u2190singleton_zero, image2_singleton_left],\n  add_vadd := \u03bb s t p, by { apply image2_assoc, intros, apply add_vadd },\n  ..(show has_vadd (set G) (set P), by apply_instance) }\n\nend set\n\n@[simp] lemma vadd_vsub_vadd_cancel_right (v\u2081 v\u2082 : G) (p : P) :\n  (v\u2081 +\u1d65 p) -\u1d65 (v\u2082 +\u1d65 p) = v\u2081 - v\u2082 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero]\n\n/-- If the same point subtracted from two points produces equal\nresults, those points are equal. -/\nlemma vsub_left_cancel {p1 p2 p : P} (h : p1 -\u1d65 p = p2 -\u1d65 p) : p1 = p2 :=\nby rwa [\u2190sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h\n\n/-- The same point subtracted from two points produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_left_cancel_iff {p1 p2 p : P} : (p1 -\u1d65 p) = p2 -\u1d65 p \u2194 p1 = p2 :=\n\u27e8vsub_left_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting the point `p` is an injective function. -/\nlemma vsub_left_injective (p : P) : function.injective ((-\u1d65 p) : P \u2192 G) :=\n\u03bb p2 p3, vsub_left_cancel\n\n/-- If subtracting two points from the same point produces equal\nresults, those points are equal. -/\nlemma vsub_right_cancel {p1 p2 p : P} (h : p -\u1d65 p1 = p -\u1d65 p2) : p1 = p2 :=\nbegin\n  refine vadd_left_cancel (p -\u1d65 p2) _,\n  rw [vsub_vadd, \u2190 h, vsub_vadd]\nend\n\n/-- Subtracting two points from the same point produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_right_cancel_iff {p1 p2 p : P} : p -\u1d65 p1 = p -\u1d65 p2 \u2194 p1 = p2 :=\n\u27e8vsub_right_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting a point from the point `p` is an injective\nfunction. -/\nlemma vsub_right_injective (p : P) : function.injective ((-\u1d65) p : P \u2192 G) :=\n\u03bb p2 p3, vsub_right_cancel\n\nend general\n\nsection comm\n\nvariables {G : Type*} {P : Type*} [add_comm_group G] [add_torsor G P]\n\ninclude G\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_left (p1 p2 p3 : P) :\n  (p3 -\u1d65 p2) - (p3 -\u1d65 p1) = (p1 -\u1d65 p2) :=\nby rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]\n\n@[simp] lemma vadd_vsub_vadd_cancel_left (v : G) (p1 p2 : P) :\n  (v +\u1d65 p1) -\u1d65 (v +\u1d65 p2) = p1 -\u1d65 p2 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel']\n\nlemma vsub_vadd_comm (p1 p2 p3 : P) : (p1 -\u1d65 p2 : G) +\u1d65 p3 = p3 -\u1d65 p2 +\u1d65 p1 :=\nbegin\n  rw [\u2190@vsub_eq_zero_iff_eq G, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub],\n  simp\nend\n\nlemma vadd_eq_vadd_iff_sub_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 v\u2082 - v\u2081 = p\u2081 -\u1d65 p\u2082 :=\nby rw [vadd_eq_vadd_iff_neg_add_eq_vsub, neg_add_eq_sub]\n\nlemma vsub_sub_vsub_comm (p\u2081 p\u2082 p\u2083 p\u2084 : P) :\n  (p\u2081 -\u1d65 p\u2082) - (p\u2083 -\u1d65 p\u2084) = (p\u2081 -\u1d65 p\u2083) - (p\u2082 -\u1d65 p\u2084) :=\nby rw [\u2190 vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub]\n\nend comm\n\nnamespace prod\n\nvariables {G : Type*} {P : Type*} {G' : Type*} {P' : Type*} [add_group G] [add_group G']\n  [add_torsor G P] [add_torsor G' P']\n\ninstance : add_torsor (G \u00d7 G') (P \u00d7 P') :=\n{ vadd := \u03bb v p, (v.1 +\u1d65 p.1, v.2 +\u1d65 p.2),\n  zero_vadd := \u03bb p, by simp,\n  add_vadd := by simp [add_vadd],\n  vsub := \u03bb p\u2081 p\u2082, (p\u2081.1 -\u1d65 p\u2082.1, p\u2081.2 -\u1d65 p\u2082.2),\n  nonempty := prod.nonempty,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, show (p\u2081.1 -\u1d65 p\u2082.1 +\u1d65 p\u2082.1, _) = p\u2081, by simp,\n  vadd_vsub' := \u03bb v p, show (v.1 +\u1d65 p.1 -\u1d65 p.1, v.2 +\u1d65 p.2 -\u1d65 p.2)  =v, by simp }\n\n@[simp] lemma fst_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).1 = v.1 +\u1d65 p.1 := rfl\n@[simp] lemma snd_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).2 = v.2 +\u1d65 p.2 := rfl\n@[simp] lemma mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') :\n  (v, v') +\u1d65 (p, p') = (v +\u1d65 p, v' +\u1d65 p') := rfl\n\n@[simp] lemma fst_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').1 = p\u2081.1 -\u1d65 p\u2082.1 := rfl\n@[simp] lemma snd_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').2 = p\u2081.2 -\u1d65 p\u2082.2 := rfl\n@[simp] lemma mk_vsub_mk (p\u2081 p\u2082 : P) (p\u2081' p\u2082' : P') :\n  ((p\u2081, p\u2081') -\u1d65 (p\u2082, p\u2082') : G \u00d7 G') = (p\u2081 -\u1d65 p\u2082, p\u2081' -\u1d65 p\u2082') := rfl\n\nend prod\n\nnamespace pi\n\nuniverses u v w\nvariables {I : Type u} {fg : I \u2192 Type v} [\u2200 i, add_group (fg i)] {fp : I \u2192 Type w}\n\nopen add_action add_torsor\n\n/-- A product of `add_torsor`s is an `add_torsor`. -/\ninstance [T : \u2200 i, add_torsor (fg i) (fp i)] : add_torsor (\u03a0 i, fg i) (\u03a0 i, fp i) :=\n{ vadd := \u03bb g p, \u03bb i, g i +\u1d65 p i,\n  zero_vadd := \u03bb p, funext $ \u03bb i, zero_vadd (fg i) (p i),\n  add_vadd := \u03bb g\u2081 g\u2082 p, funext $ \u03bb i, add_vadd (g\u2081 i) (g\u2082 i) (p i),\n  vsub := \u03bb p\u2081 p\u2082, \u03bb i, p\u2081 i -\u1d65 p\u2082 i,\n  nonempty := \u27e8\u03bb i, classical.choice (T i).nonempty\u27e9,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, funext $ \u03bb i, vsub_vadd (p\u2081 i) (p\u2082 i),\n  vadd_vsub' := \u03bb g p, funext $ \u03bb i, vadd_vsub (g i) (p i) }\n\nend pi\n\nnamespace equiv\n\nvariables {G : Type*} {P : Type*} [add_group G] [add_torsor G P]\n\ninclude G\n\n/-- `v \u21a6 v +\u1d65 p` as an equivalence. -/\ndef vadd_const (p : P) : G \u2243 P :=\n{ to_fun := \u03bb v, v +\u1d65 p,\n  inv_fun := \u03bb p', p' -\u1d65 p,\n  left_inv := \u03bb v, vadd_vsub _ _,\n  right_inv := \u03bb p', vsub_vadd _ _ }\n\n@[simp] lemma coe_vadd_const (p : P) : \u21d1(vadd_const p) = \u03bb v, v+\u1d65 p := rfl\n\n@[simp] lemma coe_vadd_const_symm (p : P) : \u21d1(vadd_const p).symm = \u03bb p', p' -\u1d65 p := rfl\n\n/-- `p' \u21a6 p -\u1d65 p'` as an equivalence. -/\ndef const_vsub (p : P) : P \u2243 G :=\n{ to_fun := (-\u1d65) p,\n  inv_fun := \u03bb v, -v +\u1d65 p,\n  left_inv := \u03bb p', by simp,\n  right_inv := \u03bb v, by simp [vsub_vadd_eq_vsub_sub] }\n\n@[simp] lemma coe_const_vsub (p : P) : \u21d1(const_vsub p) = (-\u1d65) p := rfl\n\n@[simp] lemma coe_const_vsub_symm (p : P) : \u21d1(const_vsub p).symm = \u03bb v, -v +\u1d65 p := rfl\n\nvariables (P)\n\n/-- The permutation given by `p \u21a6 v +\u1d65 p`. -/\ndef const_vadd (v : G) : equiv.perm P :=\n{ to_fun := (+\u1d65) v,\n  inv_fun := (+\u1d65) (-v),\n  left_inv := \u03bb p, by simp [vadd_vadd],\n  right_inv := \u03bb p, by simp [vadd_vadd] }\n\n@[simp] lemma coe_const_vadd (v : G) : \u21d1(const_vadd P v) = (+\u1d65) v := rfl\n\nvariable (G)\n\n@[simp] lemma const_vadd_zero : const_vadd P (0:G) = 1 := ext $ zero_vadd G\n\nvariable {G}\n\n@[simp] lemma const_vadd_add (v\u2081 v\u2082 : G) :\n  const_vadd P (v\u2081 + v\u2082) = const_vadd P v\u2081 * const_vadd P v\u2082 :=\next $ add_vadd v\u2081 v\u2082\n\n/-- `equiv.const_vadd` as a homomorphism from `multiplicative G` to `equiv.perm P` -/\ndef const_vadd_hom : multiplicative G \u2192* equiv.perm P :=\n{ to_fun := \u03bb v, const_vadd P v.to_add,\n  map_one' := const_vadd_zero G P,\n  map_mul' := const_vadd_add P }\n\nvariable {P}\n\nopen function\n\n/-- Point reflection in `x` as a permutation. -/\ndef point_reflection (x : P) : perm P := (const_vsub x).trans (vadd_const x)\n\nlemma point_reflection_apply (x y : P) : point_reflection x y = x -\u1d65 y +\u1d65 x := rfl\n\n@[simp] lemma point_reflection_symm (x : P) : (point_reflection x).symm = point_reflection x :=\next $ by simp [point_reflection]\n\n@[simp] lemma point_reflection_self (x : P) : point_reflection x x = x := vsub_vadd _ _\n\nlemma point_reflection_involutive (x : P) : involutive (point_reflection x : P \u2192 P) :=\n\u03bb y, (equiv.apply_eq_iff_eq_symm_apply _).2 $ by rw point_reflection_symm\n\n/-- `x` is the only fixed point of `point_reflection x`. This lemma requires\n`x + x = y + y \u2194 x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/\nlemma point_reflection_fixed_iff_of_injective_bit0 {x y : P} (h : injective (bit0 : G \u2192 G)) :\n  point_reflection x y = y \u2194 y = x :=\nby rw [point_reflection_apply, eq_comm, eq_vadd_iff_vsub_eq, \u2190 neg_vsub_eq_vsub_rev,\n  neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero, h.eq_iff, vsub_eq_zero_iff_eq, eq_comm]\n\nomit G\n\nlemma injective_point_reflection_left_of_injective_bit0 {G P : Type*} [add_comm_group G]\n  [add_torsor G P] (h : injective (bit0 : G \u2192 G)) (y : P) :\n  injective (\u03bb x : P, point_reflection x y) :=\n\u03bb x\u2081 x\u2082 (hy : point_reflection x\u2081 y = point_reflection x\u2082 y),\n  by rwa [point_reflection_apply, point_reflection_apply, vadd_eq_vadd_iff_sub_eq_vsub,\n    vsub_sub_vsub_cancel_right, \u2190 neg_vsub_eq_vsub_rev, neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero,\n    h.eq_iff, vsub_eq_zero_iff_eq] at hy\n\nend equiv\n\nlemma add_torsor.subsingleton_iff (G P : Type*) [add_group G] [add_torsor G P] :\n  subsingleton G \u2194 subsingleton P :=\nbegin\n  inhabit P,\n  exact (equiv.vadd_const default).subsingleton_congr,\nend\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/add_torsor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073575, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7229491981298245}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function world.\n\n## Level 9: a big maze.\n\nIn [Proposition World](../PropositionWorld.lean.md) you will see a variant of this example\nwhich can be solved by a tactic. It would be an interesting project to make a tactic\nwhich could automatically solve this sort of level in Lean.\n\nYou can of course work both forwards and backwards, or you could crack and draw a picture.\n\n## Definition\nGiven a bunch of functions, we can define another one.\n-/\nexample (A B C D E F G H I J K L : Type)\n(f1 : A \u2192 B) (f2 : B \u2192 E) (f3 : E \u2192 D) (f4 : D \u2192 A) (f5 : E \u2192 F)\n(f6 : F \u2192 C) (f7 : B \u2192 C) (f8 : F \u2192 G) (f9 : G \u2192 J) (f10 : I \u2192 J)\n(f11 : J \u2192 I) (f12 : I \u2192 H) (f13 : E \u2192 H) (f14 : H \u2192 K) (f15 : I \u2192 L)\n : A \u2192 L := by\n  intro a\n  apply f15\n  apply f11\n  apply f9\n  apply f8\n  apply f5\n  apply f2\n  apply f1\n  assumption\n\n\n/-!\nHere we finish this proof with a new tactic `assumption` instead of `exact a`.\nThe [`assumption` tactic](../Tactics/assumption.lean.md) tries to solve the goal using a\nhypothesis of compatible type.  Since we have the hypothesis named `a` it finds\nit and completes the proof.\n\nThat's the end of Function World! Next it's [Proposition World](../PropositionWorld.lean.md), and\nthe tactics you've learnt in Function World are enough to solve all nine levels! In fact, the levels\nin [Proposition World](../PropositionWorld.lean.md) might look strangely familiar...\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/FunctionWorld/Level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7228804891534489}}
{"text": "/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Leonardo de Moura\n\n! This file was ported from Lean 3 source module init.data.nat.basic\n! leanprover-community/mathlib commit 4a03bdeb31b3688c31d02d7ff8e0ff2e5d6174db\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nprelude\nimport Leanbin.Init.Logic\n\nnamespace Nat\n\n#print Nat.le /-\ninductive le (a : \u2115) : \u2115 \u2192 Prop\n  | refl : less_than_or_equal a\n  | step : \u2200 {b}, less_than_or_equal b \u2192 less_than_or_equal (succ b)\n#align nat.less_than_or_equal Nat.le\n-/\n\ninstance : LE \u2115 :=\n  \u27e8Nat.le\u27e9\n\n/- warning: nat.le clashes with nat.less_than_or_equal -> Nat.le\nCase conversion may be inaccurate. Consider using '#align nat.le Nat.le\u2093'. -/\n#print Nat.le /-\n@[reducible]\nprotected def le (n m : \u2115) :=\n  Nat.le n m\n#align nat.le Nat.le\n-/\n\n#print Nat.lt /-\n@[reducible]\nprotected def lt (n m : \u2115) :=\n  Nat.le (succ n) m\n#align nat.lt Nat.lt\n-/\n\ninstance : LT \u2115 :=\n  \u27e8Nat.lt\u27e9\n\n#print Nat.pred /-\ndef pred : \u2115 \u2192 \u2115\n  | 0 => 0\n  | a + 1 => a\n#align nat.pred Nat.pred\n-/\n\n#print Nat.sub /-\nprotected def sub : \u2115 \u2192 \u2115 \u2192 \u2115\n  | a, 0 => a\n  | a, b + 1 => pred (sub a b)\n#align nat.sub Nat.sub\n-/\n\n#print Nat.mul /-\nprotected def mul : Nat \u2192 Nat \u2192 Nat\n  | a, 0 => 0\n  | a, b + 1 => mul a b + a\n#align nat.mul Nat.mul\n-/\n\ninstance : Sub \u2115 :=\n  \u27e8Nat.sub\u27e9\n\ninstance : Mul \u2115 :=\n  \u27e8Nat.mul\u27e9\n\n-- defeq to the instance provided by comm_semiring\ninstance : Dvd \u2115 :=\n  Dvd.mk fun a b => \u2203 c, b = a * c\n\ninstance : DecidableEq \u2115\n  | zero, zero => isTrue rfl\n  | succ x, zero => isFalse fun h => Nat.noConfusion h\n  | zero, succ y => isFalse fun h => Nat.noConfusion h\n  | succ x, succ y =>\n    match DecidableEq x y with\n    | is_true xeqy => isTrue (xeqy \u25b8 Eq.refl (succ x))\n    | is_false xney => isFalse fun h => Nat.noConfusion h fun xeqy => absurd xeqy xney\n\ndef repeat.{u} {\u03b1 : Type u} (f : \u2115 \u2192 \u03b1 \u2192 \u03b1) : \u2115 \u2192 \u03b1 \u2192 \u03b1\n  | 0, a => a\n  | succ n, a => f n (repeat n a)\n#align nat.repeat Nat.repeat\u2093\n\ninstance : Inhabited \u2115 :=\n  \u27e8Nat.zero\u27e9\n\n#print Nat.zero_eq /-\n@[simp]\ntheorem zero_eq : Nat.zero = 0 :=\n  rfl\n#align nat.nat_zero_eq_zero Nat.zero_eq\n-/\n\n/-! properties of inequality -/\n\n\n#print Nat.le_refl /-\n@[refl]\nprotected theorem le_refl (a : \u2115) : a \u2264 a :=\n  le.refl\n#align nat.le_refl Nat.le_refl\n-/\n\n#print Nat.le_succ /-\ntheorem le_succ (n : \u2115) : n \u2264 succ n :=\n  le.step (Nat.le_refl n)\n#align nat.le_succ Nat.le_succ\n-/\n\n#print Nat.succ_le_succ /-\ntheorem succ_le_succ {n m : \u2115} : n \u2264 m \u2192 succ n \u2264 succ m := fun h =>\n  le.ndrec (Nat.le_refl (succ n)) (fun a b => le.step) h\n#align nat.succ_le_succ Nat.succ_le_succ\n-/\n\n#print Nat.zero_le /-\nprotected theorem zero_le : \u2200 n : \u2115, 0 \u2264 n\n  | 0 => Nat.le_refl 0\n  | n + 1 => le.step (zero_le n)\n#align nat.zero_le Nat.zero_le\n-/\n\n#print Nat.zero_lt_succ /-\ntheorem zero_lt_succ (n : \u2115) : 0 < succ n :=\n  succ_le_succ n.zero_le\n#align nat.zero_lt_succ Nat.zero_lt_succ\n-/\n\n#print Nat.succ_pos /-\ntheorem succ_pos (n : \u2115) : 0 < succ n :=\n  zero_lt_succ n\n#align nat.succ_pos Nat.succ_pos\n-/\n\n#print Nat.not_succ_le_zero /-\ntheorem not_succ_le_zero : \u2200 n : \u2115, succ n \u2264 0 \u2192 False :=\n  fun.\n#align nat.not_succ_le_zero Nat.not_succ_le_zero\n-/\n\n#print Nat.not_lt_zero /-\nprotected theorem not_lt_zero (a : \u2115) : \u00aca < 0 :=\n  not_succ_le_zero a\n#align nat.not_lt_zero Nat.not_lt_zero\n-/\n\n#print Nat.pred_le_pred /-\ntheorem pred_le_pred {n m : \u2115} : n \u2264 m \u2192 pred n \u2264 pred m := fun h =>\n  le.rec_on h (Nat.le_refl (pred n)) fun n => Nat.rec (fun a b => b) (fun a b c => le.step) n\n#align nat.pred_le_pred Nat.pred_le_pred\n-/\n\n#print Nat.le_of_succ_le_succ /-\ntheorem le_of_succ_le_succ {n m : \u2115} : succ n \u2264 succ m \u2192 n \u2264 m :=\n  pred_le_pred\n#align nat.le_of_succ_le_succ Nat.le_of_succ_le_succ\n-/\n\ninstance decidableLe : \u2200 a b : \u2115, Decidable (a \u2264 b)\n  | 0, b => isTrue b.zero_le\n  | a + 1, 0 => isFalse (not_succ_le_zero a)\n  | a + 1, b + 1 =>\n    match decidable_le a b with\n    | is_true h => isTrue (succ_le_succ h)\n    | is_false h => isFalse fun a => h (le_of_succ_le_succ a)\n#align nat.decidable_le Nat.decidableLe\n\ninstance decidableLt : \u2200 a b : \u2115, Decidable (a < b) := fun a b => Nat.decidableLe (succ a) b\n#align nat.decidable_lt Nat.decidableLt\n\n#print Nat.eq_or_lt_of_le /-\nprotected theorem eq_or_lt_of_le {a b : \u2115} (h : a \u2264 b) : a = b \u2228 a < b :=\n  le.cases_on h (Or.inl rfl) fun n h => Or.inr (succ_le_succ h)\n#align nat.eq_or_lt_of_le Nat.eq_or_lt_of_le\n-/\n\n#print Nat.lt_succ_of_le /-\ntheorem lt_succ_of_le {a b : \u2115} : a \u2264 b \u2192 a < succ b :=\n  succ_le_succ\n#align nat.lt_succ_of_le Nat.lt_succ_of_le\n-/\n\n#print Nat.succ_sub_succ_eq_sub /-\n@[simp]\ntheorem succ_sub_succ_eq_sub (a b : \u2115) : succ a - succ b = a - b :=\n  Nat.recOn b (show succ a - succ zero = a - zero from Eq.refl (succ a - succ zero)) fun b =>\n    congr_arg pred\n#align nat.succ_sub_succ_eq_sub Nat.succ_sub_succ_eq_sub\n-/\n\n#print Nat.not_succ_le_self /-\ntheorem not_succ_le_self : \u2200 n : \u2115, \u00acsucc n \u2264 n := fun n =>\n  Nat.rec (not_succ_le_zero 0) (fun a b c => b (le_of_succ_le_succ c)) n\n#align nat.not_succ_le_self Nat.not_succ_le_self\n-/\n\n#print Nat.lt_irrefl /-\nprotected theorem lt_irrefl (n : \u2115) : \u00acn < n :=\n  not_succ_le_self n\n#align nat.lt_irrefl Nat.lt_irrefl\n-/\n\n#print Nat.le_trans /-\nprotected theorem le_trans {n m k : \u2115} (h1 : n \u2264 m) : m \u2264 k \u2192 n \u2264 k :=\n  le.ndrec h1 fun p h2 => le.step\n#align nat.le_trans Nat.le_trans\n-/\n\n#print Nat.pred_le /-\ntheorem pred_le : \u2200 n : \u2115, pred n \u2264 n\n  | 0 => le.refl\n  | succ a => le.step le.refl\n#align nat.pred_le Nat.pred_le\n-/\n\n#print Nat.pred_lt /-\ntheorem pred_lt : \u2200 {n : \u2115}, n \u2260 0 \u2192 pred n < n\n  | 0, h => absurd rfl h\n  | succ a, h => lt_succ_of_le le.refl\n#align nat.pred_lt Nat.pred_lt\n-/\n\n#print Nat.sub_le /-\nprotected theorem sub_le (a b : \u2115) : a - b \u2264 a :=\n  Nat.recOn b (Nat.le_refl (a - 0)) fun b\u2081 => Nat.le_trans (pred_le (a - b\u2081))\n#align nat.sub_le Nat.sub_le\n-/\n\n#print Nat.sub_lt /-\nprotected theorem sub_lt : \u2200 {a b : \u2115}, 0 < a \u2192 0 < b \u2192 a - b < a\n  | 0, b, h1, h2 => absurd h1 (Nat.lt_irrefl 0)\n  | a + 1, 0, h1, h2 => absurd h2 (Nat.lt_irrefl 0)\n  | a + 1, b + 1, h1, h2 =>\n    Eq.symm (succ_sub_succ_eq_sub a b) \u25b8 show a - b < succ a from lt_succ_of_le (a.sub_le b)\n#align nat.sub_lt Nat.sub_lt\n-/\n\n#print Nat.lt_of_lt_of_le /-\nprotected theorem lt_of_lt_of_le {n m k : \u2115} : n < m \u2192 m \u2264 k \u2192 n < k :=\n  Nat.le_trans\n#align nat.lt_of_lt_of_le Nat.lt_of_lt_of_le\n-/\n\n/-! Basic nat.add lemmas -/\n\n\n#print Nat.zero_add /-\nprotected theorem zero_add : \u2200 n : \u2115, 0 + n = n\n  | 0 => rfl\n  | n + 1 => congr_arg succ (zero_add n)\n#align nat.zero_add Nat.zero_add\n-/\n\n#print Nat.succ_add /-\ntheorem succ_add : \u2200 n m : \u2115, succ n + m = succ (n + m)\n  | n, 0 => rfl\n  | n, m + 1 => congr_arg succ (succ_add n m)\n#align nat.succ_add Nat.succ_add\n-/\n\n#print Nat.add_succ /-\ntheorem add_succ (n m : \u2115) : n + succ m = succ (n + m) :=\n  rfl\n#align nat.add_succ Nat.add_succ\n-/\n\n/- warning: nat.add_zero clashes with nat_add_zero -> Nat.add_zero\nCase conversion may be inaccurate. Consider using '#align nat.add_zero Nat.add_zero\u2093'. -/\n#print Nat.add_zero /-\nprotected theorem add_zero (n : \u2115) : n + 0 = n :=\n  rfl\n#align nat.add_zero Nat.add_zero\n-/\n\n#print Nat.add_one /-\ntheorem add_one (n : \u2115) : n + 1 = succ n :=\n  rfl\n#align nat.add_one Nat.add_one\n-/\n\n#print Nat.succ_eq_add_one /-\ntheorem succ_eq_add_one (n : \u2115) : succ n = n + 1 :=\n  rfl\n#align nat.succ_eq_add_one Nat.succ_eq_add_one\n-/\n\n/-! Basic lemmas for comparing numerals -/\n\n\n#print Nat.bit0_succ_eq /-\nprotected theorem bit0_succ_eq (n : \u2115) : bit0 (succ n) = succ (succ (bit0 n)) :=\n  show succ (succ n + n) = succ (succ (n + n)) from congr_arg succ (succ_add n n)\n#align nat.bit0_succ_eq Nat.bit0_succ_eq\n-/\n\n#print Nat.zero_lt_bit0 /-\nprotected theorem zero_lt_bit0 : \u2200 {n : Nat}, n \u2260 0 \u2192 0 < bit0 n\n  | 0, h => absurd rfl h\n  | succ n, h =>\n    calc\n      0 < succ (succ (bit0 n)) := zero_lt_succ _\n      _ = bit0 (succ n) := (Nat.bit0_succ_eq n).symm\n      \n#align nat.zero_lt_bit0 Nat.zero_lt_bit0\n-/\n\n#print Nat.zero_lt_bit1 /-\nprotected theorem zero_lt_bit1 (n : Nat) : 0 < bit1 n :=\n  zero_lt_succ _\n#align nat.zero_lt_bit1 Nat.zero_lt_bit1\n-/\n\n#print Nat.bit0_ne_zero /-\nprotected theorem bit0_ne_zero : \u2200 {n : \u2115}, n \u2260 0 \u2192 bit0 n \u2260 0\n  | 0, h => absurd rfl h\n  | n + 1, h =>\n    suffices n + 1 + (n + 1) \u2260 0 from this\n    suffices succ (n + 1 + n) \u2260 0 from this\n    fun h => Nat.noConfusion h\n#align nat.bit0_ne_zero Nat.bit0_ne_zero\n-/\n\n#print Nat.bit1_ne_zero /-\nprotected theorem bit1_ne_zero (n : \u2115) : bit1 n \u2260 0 :=\n  show succ (n + n) \u2260 0 from fun h => Nat.noConfusion h\n#align nat.bit1_ne_zero Nat.bit1_ne_zero\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "lean3port", "sha": "9ed1898f23e4379865ee93d62cb6353e5ed6c270", "save_path": "github-repos/lean/leanprover-community-lean3port", "path": "github-repos/lean/leanprover-community-lean3port/lean3port-9ed1898f23e4379865ee93d62cb6353e5ed6c270/Leanbin/Init/Data/Nat/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7228804786706758}}
{"text": "import .love01_definitions_and_statements_demo\n\n\n/-! # LoVe Demo 3: Forward Proofs\n\nWhen developing a proof, often it makes sense to work __forward__: to start with\nwhat we already know and proceed step by step towards our goal. Lean's\nstructured proofs and raw proof terms are two style that support forward\nreasoning. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace forward_proofs\n\n\n/-! ## Structured Constructs\n\nStructured proofs are syntactic sugar sprinkled on top of Lean's\n__proof terms__.\n\nThe simplest kind of structured proof is the name of a lemma, possibly with\narguments. -/\n\nlemma add_comm (m n : \u2115) :\n  add m n = add n m :=\nsorry\n\nlemma add_comm_zero_left (n : \u2115) :\n  add 0 n = add n 0 :=\nadd_comm 0 n\n\nlemma add_comm_zero_left\u2082 (n : \u2115) :\n  add 0 n = add n 0 :=\nby exact add_comm 0 n\n\n/-! `fix` and `assume` move `\u2200`-quantified variables and assumptions from the\ngoal into the local context. They can be seen as structured versions of the\n`intros` tactic.\n\n`show` repeats the goal to prove. It is useful as documentation or to rephrase\nthe goal (up to computation). -/\n\nlemma fst_of_two_props :\n  \u2200a b : Prop, a \u2192 b \u2192 a :=\nfix a b : Prop,\nassume ha : a,\nassume hb : b,\nshow a, from\n  ha\n\nlemma fst_of_two_props\u2082 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nshow a, from\n  begin\n    exact ha\n  end\n\nlemma fst_of_two_props\u2083 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nha\n\n/-! `have` proves an intermediate lemma, which can refer to the local context. -/\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nhave hb : b :=\n  hab ha,\nhave hc : c :=\n  hbc hb,\nshow c, from\n  hc\n\nlemma prop_comp\u2082 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha : a,\nshow c, from\n  hbc (hab ha)\n\n\n/-! ## Forward Reasoning about Connectives and Quantifiers -/\n\nlemma and_swap (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nassume hab : a \u2227 b,\nhave ha : a :=\n  and.elim_left hab,\nhave hb : b :=\n  and.elim_right hab,\nshow b \u2227 a, from\n  and.intro hb ha\n\nlemma or_swap (a b : Prop) :\n  a \u2228 b \u2192 b \u2228 a :=\nassume hab : a \u2228 b,\nshow b \u2228 a, from\n  or.elim hab\n    (assume ha : a,\n     show b \u2228 a, from\n       or.intro_right b ha)\n    (assume hb : b,\n     show b \u2228 a, from\n       or.intro_left a hb)\n\ndef double (n : \u2115) : \u2115 :=\nn + n\n\nlemma nat_exists_double_iden :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0\n  (show double 0 = 0, from\n     by refl)\n\nlemma nat_exists_double_iden\u2082 :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0 (by refl)\n\nlemma modus_ponens (a b : Prop) :\n  (a \u2192 b) \u2192 a \u2192 b :=\nassume hab : a \u2192 b,\nassume ha : a,\nshow b, from\n  hab ha\n\nlemma not_not_intro (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nassume ha : a,\nassume hna : \u00ac a,\nshow false, from\n  hna ha\n\nlemma forall.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2200x, x = t \u2192 p x) \u2194 p t :=\niff.intro\n  (assume hall : \u2200x, x = t \u2192 p x,\n   show p t, from\n     begin\n       apply hall t,\n       refl\n     end)\n  (assume hp : p t,\n   fix x,\n   assume heq : x = t,\n   show p x, from\n     begin\n       rw heq,\n       exact hp\n     end)\n\nlemma beast_666 (beast : \u2115) :\n  (\u2200n, n = 666 \u2192 beast \u2265 n) \u2194 beast \u2265 666 :=\nforall.one_point _ _\n\n#print beast_666\n\nlemma exists.one_point {\u03b1 : Type} (t : \u03b1) (p : \u03b1 \u2192 Prop) :\n  (\u2203x : \u03b1, x = t \u2227 p x) \u2194 p t :=\niff.intro\n  (assume hex : \u2203x, x = t \u2227 p x,\n   show p t, from\n     exists.elim hex\n       (fix x,\n        assume hand : x = t \u2227 p x,\n        show p t, from\n          by cc))\n  (assume hp : p t,\n   show \u2203x : \u03b1, x = t \u2227 p x, from\n     exists.intro t\n       (show t = t \u2227 p t, from\n          by cc))\n\n\n/-! ## Calculational Proofs\n\nIn informal mathematics, we often use transitive chains of equalities,\ninequalities, or equivalences (e.g., `a \u2265 b \u2265 c`). In Lean, such calculational\nproofs are supported by `calc`.\n\nSyntax:\n\n    calc      _term\u2080_\n        _op\u2081_ _term\u2081_ :\n      _proof\u2081_\n    ... _op\u2082_ _term\u2082_ :\n      _proof\u2082_\n     \u22ee\n    ... _opN_ _termN_ :\n      _proofN_ -/\n\nlemma two_mul_example (m n : \u2115) :\n  2 * m + n = m + n + m :=\ncalc  2 * m + n\n    = (m + m) + n :\n  by rw two_mul\n... = m + n + m :\n  by cc\n\n/-! `calc` saves some repetition, some `have` labels, and some transitive\nreasoning: -/\n\nlemma two_mul_example\u2082 (m n : \u2115) :\n  2 * m + n = m + n + m :=\nhave h\u2081 : 2 * m + n = (m + m) + n :=\n  by rw two_mul,\nhave h\u2082 : (m + m) + n = m + n + m :=\n  by cc,\nshow _, from\n  eq.trans h\u2081 h\u2082\n\n\n/-! ## Forward Reasoning with Tactics\n\nThe `have`, `let`, and `calc` structured proof commands are also available as a\ntactic. Even in tactic mode, it can be useful to state intermediate results and\ndefinitions in a forward fashion.\n\nObserve that the syntax for the tactic `let` is slightly different than for the\nstructured proof command `let`, with `,` instead of `in`. -/\n\nlemma prop_comp\u2083 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  have hb : b :=\n    hab ha,\n  let c' := c,\n  have hc : c' :=\n    hbc hb,\n  exact hc\nend\n\n\n/-! ## Dependent Types\n\nDependent types are the defining feature of the dependent type theory family of\nlogics.\n\nConsider a function `pick` that take a number `n : \u2115` and that returns a number\nbetween 0 and `n`. Conceptually, `pick` has a dependent type, namely\n\n    `(n : \u2115) \u2192 {i : \u2115 // i \u2264 n}`\n\nWe can think of this type as a `\u2115`-indexed family, where each member's type may\ndepend on the index:\n\n    `pick n : {i : \u2115 // i \u2264 n}`\n\nBut a type may also depend on another type, e.g., `list` (or `\u03bb\u03b1, list \u03b1`) and\n`\u03bb\u03b1, \u03b1 \u2192 \u03b1`.\n\nA term may depend on a type, e.g., `\u03bb\u03b1, \u03bbx : \u03b1, x` (a polymorphic identity\nfunction).\n\nOf course, a term may also depend on a term.\n\nUnless otherwise specified, a __dependent type__ means a type depending on a\nterm. This is what we mean when we say that simple type theory does not support\ndependent types.\n\nIn summary, there are four cases for `\u03bbx, t` in the calculus of inductive\nconstructions (cf. Barendregt's `\u03bb`-cube):\n\nBody (`t`) |              | Argument (`x`) | Description\n---------- | ------------ | -------------- | ------------------------------\nA term     | depending on | a term         | Simply typed `\u03bb`-expression\nA type     | depending on | a term         | Dependent type (strictly speaking)\nA term     | depending on | a type         | Polymorphic term\nA type     | depending on | a type         | Type constructor\n\nRevised typing rules:\n\n    C \u22a2 t : (x : \u03c3) \u2192 \u03c4[x]    C \u22a2 u : \u03c3\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    C \u22a2 t u : \u03c4[u]\n\n    C, x : \u03c3 \u22a2 t : \u03c4[x]\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    C \u22a2 (\u03bbx : \u03c3, t) : (x : \u03c3) \u2192 \u03c4[x]\n\nThese two rules degenerate to `App` and `Lam` if `x` does not occur in `\u03c4[x]`\n\nExample of `App'`:\n\n    \u22a2 pick : (x : \u2115) \u2192 {y : \u2115 // y \u2264 x}    \u22a2 5 : \u2115\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 App'\n    \u22a2 pick 5 : {y : \u2115 // y \u2264 5}\n\nExample of `Lam'`:\n\n    \u03b1 : Type, x : \u03b1 \u22a2 x : \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam or Lam'\n    \u03b1 : Type \u22a2 (\u03bbx : \u03b1, x) : \u03b1 \u2192 \u03b1\n    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 Lam'\n    \u22a2 (\u03bb\u03b1 : Type, \u03bbx : \u03b1, x) : (\u03b1 : Type) \u2192 \u03b1 \u2192 \u03b1\n\nRegrettably, the intuitive syntax `(x : \u03c3) \u2192 \u03c4` is not available in Lean.\nInstead, we must write `\u2200x : \u03c3, \u03c4` to specify a dependent type.\n\nAliases:\n\n    `\u03c3 \u2192 \u03c4` := `\u2200_ : \u03c3, \u03c4`\n    `\u03a0`     := `\u2200`\n\n\n## The PAT Principle\n\n`\u2192` is used both as the implication symbol and as the type constructor of\nfunctions. Similarly, `\u2200` is used both as a quantifier and in dependent types.\n\nThe two pairs of concepts not only look the same, they are the same, by the PAT\nprinciple:\n\n* PAT = propositions as types;\n* PAT = proofs as terms.\n\nTypes:\n\n* `\u03c3 \u2192 \u03c4` is the type of total functions from `\u03c3` to `\u03c4`;\n* `\u2200x : \u03c3, \u03c4[x]` is the dependent function type from `x : \u03c3` to `\u03c4[x]`.\n\nPropositions:\n\n* `P \u2192 Q` can be read as \"`P` implies `Q`\", or as the type of functions mapping\n  proofs of `P` to proofs of `Q`.\n* `\u2200x : \u03c3, Q[x]` can be read as \"for all `x`, `Q[x]`\", or as the type of\n  functions mapping values `x` of type `\u03c3` to proofs of `Q[x]`.\n\nTerms:\n\n* A constant is a term.\n* A variable is a term.\n* `t u` is the application of function `t` to value `u`.\n* `\u03bbx, t[x]` is a function mapping `x` to `t[x]`.\n\nProofs:\n\n* A lemma or hypothesis name is a proof.\n* `H t`, which instantiates the leading parameter or quantifier of proof `H`'\n  statement with term `t`, is a proof.\n* `H G`, which discharges the leading assumption of `H`'s statement with\n  proof `G`, is a proof.\n* `\u03bbh : P, H[h]` is a proof of `P \u2192 Q`, assuming `H[h]` is a proof of `Q`\n  for `h : P`.\n* `\u03bbx : \u03c3, H[x]` is a proof of `\u2200x : \u03c3, Q[x]`, assuming `H[x]` is a proof of\n  `Q[x]` for `x : \u03c3`. -/\n\nlemma and_swap\u2083 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\n\u03bbhab : a \u2227 b, and.intro (and.elim_right hab) (and.elim_left hab)\n\nlemma and_swap\u2084 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intro hab,\n  apply and.intro,\n  apply and.elim_right,\n  exact hab,\n  apply and.elim_left,\n  exact hab\nend\n\n/-! Tactical proofs are reduced to proof terms. -/\n\n#print and_swap\u2083\n#print and_swap\u2084\n\nend forward_proofs\n\n\n/-! ## Induction by Pattern Matching\n\nBy the PAT principle, a proof by induction is the same as a recursively\nspecified proof term. Thus, as alternative to the `induction'` tactic, induction\ncan also be done by pattern matching:\n\n * the induction hypothesis is then available under the name of the lemma we are\n   proving;\n\n * well-foundedness of the argument is often proved automatically. -/\n\n#check reverse\n\nlemma reverse_append {\u03b1 : Type} :\n  \u2200xs ys : list \u03b1,\n    reverse (xs ++ ys) = reverse ys ++ reverse xs\n| []        ys := by simp [reverse]\n| (x :: xs) ys := by simp [reverse, reverse_append xs]\n\nlemma reverse_append\u2082 {\u03b1 : Type} (xs ys : list \u03b1) :\n  reverse (xs ++ ys) = reverse ys ++ reverse xs :=\nbegin\n  induction' xs,\n  { simp [reverse] },\n  { simp [reverse, ih] }\nend\n\nlemma reverse_reverse {\u03b1 : Type} :\n  \u2200xs : list \u03b1, reverse (reverse xs) = xs\n| []        := by refl\n| (x :: xs) :=\n  by simp [reverse, reverse_append, reverse_reverse xs]\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2021", "sha": "23b469c79afd482fa66da82e4726a317e3a7b5d5", "save_path": "github-repos/lean/blanchette-logical_verification_2021", "path": "github-repos/lean/blanchette-logical_verification_2021/logical_verification_2021-23b469c79afd482fa66da82e4726a317e3a7b5d5/lean/love03_forward_proofs_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7228804733542809}}
{"text": "import data.set.intervals data.nat.parity\nimport tactic \n\nuniverses u v w \nopen_locale classical \n\n/-! Some simple additions to the api -/\n\nopen set \n\nnamespace int \n\n\nlemma le_sub_one_of_le_of_ne {x y : \u2124} : \n  x \u2264 y \u2192 x \u2260 y \u2192 x \u2264 y - 1 :=\n  \u03bb h h', int.le_sub_one_of_lt (lt_of_le_of_ne h h')\n\nlemma le_of_not_gt' {x y : \u2124} : \n  \u00ac (y < x) \u2192 x \u2264 y := \n  not_lt.mp\n\nlemma nonneg_le_one_iff {x : \u2124} (h0 : 0 \u2264 x) (h1 : x \u2264 1) :\n  x = 0 \u2228 x = 1 :=\nby {by_cases h : x \u2264 0, left, apply le_antisymm h h0, \n    push_neg at h, rw int.le_sub_one_iff.symm at h, \n    right, linarith, }\n\nlemma nat_le_two_iff {x : \u2115} (h2 : x \u2264 2) : \n  x = 0 \u2228 x = 1 \u2228 x = 2 :=\nby {cases x, tauto, cases x, tauto, cases x, tauto, repeat {rw nat.succ_eq_add_one at h2}, linarith} \n\nlemma nonneg_le_two_iff {x : \u2124} (h0 : 0 \u2264 x) (h2 : x \u2264 2) :\n  x = 0 \u2228 x = 1 \u2228 x = 2 :=\nbegin\n  by_cases h2' : 2 \u2264 x, right, right, apply le_antisymm h2 h2', \n  push_neg at h2', rw int.le_sub_one_iff.symm at h2', \n  cases nonneg_le_one_iff h0 h2', {left, exact h}, {right, left, exact h},\nend \n\nlemma to_nat_zero_of_nonpos {x : \u2124} (hx : x \u2264 0): \n  x.to_nat = 0 := \nby {rcases em (x = 0) with (rfl | hx'), simp, apply to_nat_zero_of_neg (lt_of_le_of_ne hx hx'), }\n\nend int\n\n\n\nnamespace nat\n\nlemma lt_iff_succ_le {a b : \u2115} : \n  a < b \u2194 a.succ \u2264 b := \n\u27e8\u03bb h, succ_le_of_lt h, \u03bb h, lt_of_succ_le h\u27e9 \n\nend nat \n\n\n\nsection order\n\nvariables {\u03b1 : Type*} [partial_order \u03b1] {a b c : \u03b1}\n\nlemma squeeze_le_trans_left (hab : a \u2264 b) (hbc : b \u2264 c) (hac : a = c):\n  a = b := \nle_antisymm hab (hbc.trans hac.symm.le)\n\nlemma squeeze_le_trans_right (hab : a \u2264 b) (hbc : b \u2264 c) (hac : a = c):\n  b = c := \nle_antisymm hbc (hac.symm.le.trans hab)\n\nlemma squeeze_le_trans (hab : a \u2264 b) (hbc : b \u2264 c) (hac : a = c):\n  a = b \u2227 b = c := \n\u27e8squeeze_le_trans_left hab hbc hac, squeeze_le_trans_right hab hbc hac\u27e9 \n\nend order \n\nsection neg_one_pow\n\n\nlemma nat.neg_one_pow_sum_eq_zero_of_sum_odd {n m : \u2115} (h : odd (n+m)) : \n  (-1 :\u2124)^m + (-1)^n = 0 :=\nbegin\n  obtain \u27e8 (\u27e8k,rfl\u27e9 | \u27e8k,rfl\u27e9), (\u27e8j,rfl\u27e9 | \u27e8j,rfl\u27e9)\u27e9 := \u27e8nat.even_or_odd n, nat.even_or_odd m\u27e9, \n  { exfalso, apply nat.odd_iff_not_even.mp h \u27e8k+j, by {rw mul_add}\u27e9, },\n  { simp [nat.neg_one_pow_of_odd \u27e8j,rfl\u27e9, nat.neg_one_pow_of_even \u27e8k,rfl\u27e9]},\n  { simp [nat.neg_one_pow_of_even \u27e8j,rfl\u27e9, nat.neg_one_pow_of_odd \u27e8k,rfl\u27e9]}, \n  { exfalso, apply nat.odd_iff_not_even.mp h \u27e8j+k+1, by linarith\u27e9}, \nend\n \ndef int.neg_one_pow (n : \u2124) : \u2124 := @gpow (units \u2124) _ (-1) n \n\nlemma int.neg_one_pow_eq_neg_one_pow_neg (n : \u2124) :\n  int.neg_one_pow n = int.neg_one_pow (-n) :=\nbegin\n  unfold int.neg_one_pow, \n  simp only [gpow_neg, group.gpow_eq_has_pow], \n  rw [eq_comm], \n  apply units.inv_eq_of_mul_eq_one,\n  simp, \nend\n\nlemma int.neg_one_pow_eq_abs (n : \u2124):\n  int.neg_one_pow n = (-1)^(n.nat_abs) :=\nbegin\n  unfold int.neg_one_pow, \n  rcases int.nat_abs_eq n with (h | h), rw h, simp, \n  rw h, \n  simp only [int.nat_abs_of_nat, gpow_neg, int.nat_abs_neg, group.gpow_eq_has_pow, gpow_coe_nat], \n  apply units.inv_eq_of_mul_eq_one, \n  simp only [units.coe_neg_one, units.coe_pow, \u2190 pow_add, \u2190 two_mul],  \n  apply nat.neg_one_pow_of_even, \n  exact \u27e8_, rfl\u27e9, \nend\n\nlemma int.neg_one_pow_coe {n : \u2115}: int.neg_one_pow n = (-1)^n := \nby {rw int.neg_one_pow_eq_abs, congr', }\n\nlemma neg_one_pow_of_even {n : \u2124} (hn : even n) : int.neg_one_pow n = 1 := \nbegin\n  obtain \u27e8k,rfl\u27e9 := hn, \n  obtain \u27e8a, (rfl | rfl)\u27e9 := k.eq_coe_or_neg, swap,\n  rw [(by simp : ((2 : \u2124) * - (a : \u2124) = - (2*a ))), int.neg_one_pow_eq_neg_one_pow_neg, neg_neg],\n  all_goals\n  { rw [\u2190 (by simp: ((2 * a : \u2115) : \u2124) = ((2 : \u2124)* (a : \u2124))), int.neg_one_pow_coe, \n    nat.neg_one_pow_of_even \u27e8_, rfl\u27e9]}, \nend\n/-\nlemma neg_one_pow_of_odd {n : \u2124} (hn : odd n) : int.neg_one_pow n = -1 := \nbegin\n  obtain \u27e8k,rfl\u27e9 := hn, \n  rw [int.neg_one_pow], convert gpow_add_one (-1 : units \u2124) (2*k), \nend\n-/\nend neg_one_pow", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_aux/prelim/num_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7228804710914495}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n\n! This file was ported from Lean 3 source module geometry.euclidean.sphere.basic\n! leanprover-community/mathlib commit 46b633fd842bef9469441c0209906f6dddd2b4f5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Convex.StrictConvexBetween\nimport Mathbin.Geometry.Euclidean.Basic\n\n/-!\n# Spheres\n\nThis file defines and proves basic results about spheres and cospherical sets of points in\nEuclidean affine spaces.\n\n## Main definitions\n\n* `euclidean_geometry.sphere` bundles a `center` and a `radius`.\n\n* `euclidean_geometry.cospherical` is the property of a set of points being equidistant from some\n  point.\n\n* `euclidean_geometry.concyclic` is the property of a set of points being cospherical and\n  coplanar.\n\n-/\n\n\nnoncomputable section\n\nopen RealInnerProductSpace\n\nnamespace EuclideanGeometry\n\nvariable {V : Type _} (P : Type _)\n\nopen FiniteDimensional\n\n/-- A `sphere P` bundles a `center` and `radius`. This definition does not require the radius to\nbe positive; that should be given as a hypothesis to lemmas that require it. -/\n@[ext]\nstructure Sphere [MetricSpace P] where\n  center : P\n  radius : \u211d\n#align euclidean_geometry.sphere EuclideanGeometry.Sphere\n\nvariable {P}\n\nsection MetricSpace\n\nvariable [MetricSpace P]\n\ninstance [Nonempty P] : Nonempty (Sphere P) :=\n  \u27e8\u27e8Classical.arbitrary P, 0\u27e9\u27e9\n\ninstance : Coe (Sphere P) (Set P) :=\n  \u27e8fun s => Metric.sphere s.center s.radius\u27e9\n\ninstance : Membership P (Sphere P) :=\n  \u27e8fun p s => p \u2208 (s : Set P)\u27e9\n\ntheorem Sphere.mk_center (c : P) (r : \u211d) : (\u27e8c, r\u27e9 : Sphere P).center = c :=\n  rfl\n#align euclidean_geometry.sphere.mk_center EuclideanGeometry.Sphere.mk_center\n\ntheorem Sphere.mk_radius (c : P) (r : \u211d) : (\u27e8c, r\u27e9 : Sphere P).radius = r :=\n  rfl\n#align euclidean_geometry.sphere.mk_radius EuclideanGeometry.Sphere.mk_radius\n\n@[simp]\ntheorem Sphere.mk_center_radius (s : Sphere P) : (\u27e8s.center, s.radius\u27e9 : Sphere P) = s := by\n  ext <;> rfl\n#align euclidean_geometry.sphere.mk_center_radius EuclideanGeometry.Sphere.mk_center_radius\n\ntheorem Sphere.coe_def (s : Sphere P) : (s : Set P) = Metric.sphere s.center s.radius :=\n  rfl\n#align euclidean_geometry.sphere.coe_def EuclideanGeometry.Sphere.coe_def\n\n@[simp]\ntheorem Sphere.coe_mk (c : P) (r : \u211d) : \u2191(\u27e8c, r\u27e9 : Sphere P) = Metric.sphere c r :=\n  rfl\n#align euclidean_geometry.sphere.coe_mk EuclideanGeometry.Sphere.coe_mk\n\n@[simp]\ntheorem Sphere.mem_coe {p : P} {s : Sphere P} : p \u2208 (s : Set P) \u2194 p \u2208 s :=\n  Iff.rfl\n#align euclidean_geometry.sphere.mem_coe EuclideanGeometry.Sphere.mem_coe\n\ntheorem mem_sphere {p : P} {s : Sphere P} : p \u2208 s \u2194 dist p s.center = s.radius :=\n  Iff.rfl\n#align euclidean_geometry.mem_sphere EuclideanGeometry.mem_sphere\n\ntheorem mem_sphere' {p : P} {s : Sphere P} : p \u2208 s \u2194 dist s.center p = s.radius :=\n  Metric.mem_sphere'\n#align euclidean_geometry.mem_sphere' EuclideanGeometry.mem_sphere'\n\ntheorem subset_sphere {ps : Set P} {s : Sphere P} : ps \u2286 s \u2194 \u2200 p \u2208 ps, p \u2208 s :=\n  Iff.rfl\n#align euclidean_geometry.subset_sphere EuclideanGeometry.subset_sphere\n\ntheorem dist_of_mem_subset_sphere {p : P} {ps : Set P} {s : Sphere P} (hp : p \u2208 ps)\n    (hps : ps \u2286 (s : Set P)) : dist p s.center = s.radius :=\n  mem_sphere.1 (Sphere.mem_coe.1 (Set.mem_of_mem_of_subset hp hps))\n#align euclidean_geometry.dist_of_mem_subset_sphere EuclideanGeometry.dist_of_mem_subset_sphere\n\ntheorem dist_of_mem_subset_mk_sphere {p c : P} {ps : Set P} {r : \u211d} (hp : p \u2208 ps)\n    (hps : ps \u2286 \u2191(\u27e8c, r\u27e9 : Sphere P)) : dist p c = r :=\n  dist_of_mem_subset_sphere hp hps\n#align euclidean_geometry.dist_of_mem_subset_mk_sphere EuclideanGeometry.dist_of_mem_subset_mk_sphere\n\ntheorem Sphere.ne_iff {s\u2081 s\u2082 : Sphere P} :\n    s\u2081 \u2260 s\u2082 \u2194 s\u2081.center \u2260 s\u2082.center \u2228 s\u2081.radius \u2260 s\u2082.radius := by\n  rw [\u2190 not_and_or, \u2190 sphere.ext_iff]\n#align euclidean_geometry.sphere.ne_iff EuclideanGeometry.Sphere.ne_iff\n\ntheorem Sphere.center_eq_iff_eq_of_mem {s\u2081 s\u2082 : Sphere P} {p : P} (hs\u2081 : p \u2208 s\u2081) (hs\u2082 : p \u2208 s\u2082) :\n    s\u2081.center = s\u2082.center \u2194 s\u2081 = s\u2082 :=\n  by\n  refine' \u27e8fun h => sphere.ext _ _ h _, fun h => h \u25b8 rfl\u27e9\n  rw [mem_sphere] at hs\u2081 hs\u2082\n  rw [\u2190 hs\u2081, \u2190 hs\u2082, h]\n#align euclidean_geometry.sphere.center_eq_iff_eq_of_mem EuclideanGeometry.Sphere.center_eq_iff_eq_of_mem\n\ntheorem Sphere.center_ne_iff_ne_of_mem {s\u2081 s\u2082 : Sphere P} {p : P} (hs\u2081 : p \u2208 s\u2081) (hs\u2082 : p \u2208 s\u2082) :\n    s\u2081.center \u2260 s\u2082.center \u2194 s\u2081 \u2260 s\u2082 :=\n  (Sphere.center_eq_iff_eq_of_mem hs\u2081 hs\u2082).Not\n#align euclidean_geometry.sphere.center_ne_iff_ne_of_mem EuclideanGeometry.Sphere.center_ne_iff_ne_of_mem\n\ntheorem dist_center_eq_dist_center_of_mem_sphere {p\u2081 p\u2082 : P} {s : Sphere P} (hp\u2081 : p\u2081 \u2208 s)\n    (hp\u2082 : p\u2082 \u2208 s) : dist p\u2081 s.center = dist p\u2082 s.center := by\n  rw [mem_sphere.1 hp\u2081, mem_sphere.1 hp\u2082]\n#align euclidean_geometry.dist_center_eq_dist_center_of_mem_sphere EuclideanGeometry.dist_center_eq_dist_center_of_mem_sphere\n\ntheorem dist_center_eq_dist_center_of_mem_sphere' {p\u2081 p\u2082 : P} {s : Sphere P} (hp\u2081 : p\u2081 \u2208 s)\n    (hp\u2082 : p\u2082 \u2208 s) : dist s.center p\u2081 = dist s.center p\u2082 := by\n  rw [mem_sphere'.1 hp\u2081, mem_sphere'.1 hp\u2082]\n#align euclidean_geometry.dist_center_eq_dist_center_of_mem_sphere' EuclideanGeometry.dist_center_eq_dist_center_of_mem_sphere'\n\n/-- A set of points is cospherical if they are equidistant from some\npoint.  In two dimensions, this is the same thing as being\nconcyclic. -/\ndef Cospherical (ps : Set P) : Prop :=\n  \u2203 (center : P)(radius : \u211d), \u2200 p \u2208 ps, dist p center = radius\n#align euclidean_geometry.cospherical EuclideanGeometry.Cospherical\n\n/-- The definition of `cospherical`. -/\ntheorem cospherical_def (ps : Set P) :\n    Cospherical ps \u2194 \u2203 (center : P)(radius : \u211d), \u2200 p \u2208 ps, dist p center = radius :=\n  Iff.rfl\n#align euclidean_geometry.cospherical_def EuclideanGeometry.cospherical_def\n\n/-- A set of points is cospherical if and only if they lie in some sphere. -/\ntheorem cospherical_iff_exists_sphere {ps : Set P} :\n    Cospherical ps \u2194 \u2203 s : Sphere P, ps \u2286 (s : Set P) :=\n  by\n  refine' \u27e8fun h => _, fun h => _\u27e9\n  \u00b7 rcases h with \u27e8c, r, h\u27e9\n    exact \u27e8\u27e8c, r\u27e9, h\u27e9\n  \u00b7 rcases h with \u27e8s, h\u27e9\n    exact \u27e8s.center, s.radius, h\u27e9\n#align euclidean_geometry.cospherical_iff_exists_sphere EuclideanGeometry.cospherical_iff_exists_sphere\n\n/-- The set of points in a sphere is cospherical. -/\ntheorem Sphere.cospherical (s : Sphere P) : Cospherical (s : Set P) :=\n  cospherical_iff_exists_sphere.2 \u27e8s, Set.Subset.rfl\u27e9\n#align euclidean_geometry.sphere.cospherical EuclideanGeometry.Sphere.cospherical\n\n/-- A subset of a cospherical set is cospherical. -/\ntheorem Cospherical.subset {ps\u2081 ps\u2082 : Set P} (hs : ps\u2081 \u2286 ps\u2082) (hc : Cospherical ps\u2082) :\n    Cospherical ps\u2081 := by\n  rcases hc with \u27e8c, r, hcr\u27e9\n  exact \u27e8c, r, fun p hp => hcr p (hs hp)\u27e9\n#align euclidean_geometry.cospherical.subset EuclideanGeometry.Cospherical.subset\n\n/-- The empty set is cospherical. -/\ntheorem cospherical_empty [Nonempty P] : Cospherical (\u2205 : Set P) :=\n  let \u27e8p\u27e9 := \u2039Nonempty P\u203a\n  \u27e8p, 0, fun p => False.elim\u27e9\n#align euclidean_geometry.cospherical_empty EuclideanGeometry.cospherical_empty\n\n/-- A single point is cospherical. -/\ntheorem cospherical_singleton (p : P) : Cospherical ({p} : Set P) :=\n  by\n  use p\n  simp\n#align euclidean_geometry.cospherical_singleton EuclideanGeometry.cospherical_singleton\n\nend MetricSpace\n\nsection NormedSpace\n\nvariable [NormedAddCommGroup V] [NormedSpace \u211d V] [MetricSpace P] [NormedAddTorsor V P]\n\ninclude V\n\n/-- Two points are cospherical. -/\ntheorem cospherical_pair (p\u2081 p\u2082 : P) : Cospherical ({p\u2081, p\u2082} : Set P) :=\n  \u27e8midpoint \u211d p\u2081 p\u2082, \u2016(2 : \u211d)\u2016\u207b\u00b9 * dist p\u2081 p\u2082,\n    by\n    rintro p (rfl | rfl | _)\n    \u00b7 rw [dist_comm, dist_midpoint_left]\n    \u00b7 rw [dist_comm, dist_midpoint_right]\u27e9\n#align euclidean_geometry.cospherical_pair EuclideanGeometry.cospherical_pair\n\n/-- A set of points is concyclic if it is cospherical and coplanar. (Most results are stated\ndirectly in terms of `cospherical` instead of using `concyclic`.) -/\nstructure Concyclic (ps : Set P) : Prop where\n  Cospherical : Cospherical ps\n  Coplanar : Coplanar \u211d ps\n#align euclidean_geometry.concyclic EuclideanGeometry.Concyclic\n\n/-- A subset of a concyclic set is concyclic. -/\ntheorem Concyclic.subset {ps\u2081 ps\u2082 : Set P} (hs : ps\u2081 \u2286 ps\u2082) (h : Concyclic ps\u2082) : Concyclic ps\u2081 :=\n  \u27e8h.1.Subset hs, h.2.Subset hs\u27e9\n#align euclidean_geometry.concyclic.subset EuclideanGeometry.Concyclic.subset\n\n/-- The empty set is concyclic. -/\ntheorem concyclic_empty : Concyclic (\u2205 : Set P) :=\n  \u27e8cospherical_empty, coplanar_empty \u211d P\u27e9\n#align euclidean_geometry.concyclic_empty EuclideanGeometry.concyclic_empty\n\n/-- A single point is concyclic. -/\ntheorem concyclic_singleton (p : P) : Concyclic ({p} : Set P) :=\n  \u27e8cospherical_singleton p, coplanar_singleton \u211d p\u27e9\n#align euclidean_geometry.concyclic_singleton EuclideanGeometry.concyclic_singleton\n\n/-- Two points are concyclic. -/\ntheorem concyclic_pair (p\u2081 p\u2082 : P) : Concyclic ({p\u2081, p\u2082} : Set P) :=\n  \u27e8cospherical_pair p\u2081 p\u2082, coplanar_pair \u211d p\u2081 p\u2082\u27e9\n#align euclidean_geometry.concyclic_pair EuclideanGeometry.concyclic_pair\n\nend NormedSpace\n\nsection EuclideanSpace\n\nvariable [NormedAddCommGroup V] [InnerProductSpace \u211d V] [MetricSpace P] [NormedAddTorsor V P]\n\ninclude V\n\n/-- Any three points in a cospherical set are affinely independent. -/\ntheorem Cospherical.affineIndependent {s : Set P} (hs : Cospherical s) {p : Fin 3 \u2192 P}\n    (hps : Set.range p \u2286 s) (hpi : Function.Injective p) : AffineIndependent \u211d p :=\n  by\n  rw [affineIndependent_iff_not_collinear]\n  intro hc\n  rw [collinear_iff_of_mem (Set.mem_range_self (0 : Fin 3))] at hc\n  rcases hc with \u27e8v, hv\u27e9\n  rw [Set.forall_range_iff] at hv\n  have hv0 : v \u2260 0 := by\n    intro h\n    have he : p 1 = p 0 := by simpa [h] using hv 1\n    exact (by decide : (1 : Fin 3) \u2260 0) (hpi he)\n  rcases hs with \u27e8c, r, hs\u27e9\n  have hs' := fun i => hs (p i) (Set.mem_of_mem_of_subset (Set.mem_range_self _) hps)\n  choose f hf using hv\n  have hsd : \u2200 i, dist (f i \u2022 v +\u1d65 p 0) c = r :=\n    by\n    intro i\n    rw [\u2190 hf]\n    exact hs' i\n  have hf0 : f 0 = 0 := by\n    have hf0' := hf 0\n    rw [eq_comm, \u2190 @vsub_eq_zero_iff_eq V, vadd_vsub, smul_eq_zero] at hf0'\n    simpa [hv0] using hf0'\n  have hfi : Function.Injective f := by\n    intro i j h\n    have hi := hf i\n    rw [h, \u2190 hf j] at hi\n    exact hpi hi\n  simp_rw [\u2190 hsd 0, hf0, zero_smul, zero_vadd, dist_smul_vadd_eq_dist (p 0) c hv0] at hsd\n  have hfn0 : \u2200 i, i \u2260 0 \u2192 f i \u2260 0 := fun i => (hfi.ne_iff' hf0).2\n  have hfn0' : \u2200 i, i \u2260 0 \u2192 f i = -2 * \u27eav, p 0 -\u1d65 c\u27eb / \u27eav, v\u27eb :=\n    by\n    intro i hi\n    have hsdi := hsd i\n    simpa [hfn0, hi] using hsdi\n  have hf12 : f 1 = f 2 := by rw [hfn0' 1 (by decide), hfn0' 2 (by decide)]\n  exact (by decide : (1 : Fin 3) \u2260 2) (hfi hf12)\n#align euclidean_geometry.cospherical.affine_independent EuclideanGeometry.Cospherical.affineIndependent\n\n/-- Any three points in a cospherical set are affinely independent. -/\ntheorem Cospherical.affineIndependent_of_mem_of_ne {s : Set P} (hs : Cospherical s) {p\u2081 p\u2082 p\u2083 : P}\n    (h\u2081 : p\u2081 \u2208 s) (h\u2082 : p\u2082 \u2208 s) (h\u2083 : p\u2083 \u2208 s) (h\u2081\u2082 : p\u2081 \u2260 p\u2082) (h\u2081\u2083 : p\u2081 \u2260 p\u2083) (h\u2082\u2083 : p\u2082 \u2260 p\u2083) :\n    AffineIndependent \u211d ![p\u2081, p\u2082, p\u2083] :=\n  by\n  refine' hs.affine_independent _ _\n  \u00b7 simp [h\u2081, h\u2082, h\u2083, Set.insert_subset]\n  \u00b7 erw [Fin.cons_injective_iff, Fin.cons_injective_iff]\n    simp [h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, Function.Injective]\n#align euclidean_geometry.cospherical.affine_independent_of_mem_of_ne EuclideanGeometry.Cospherical.affineIndependent_of_mem_of_ne\n\n/-- The three points of a cospherical set are affinely independent. -/\ntheorem Cospherical.affineIndependent_of_ne {p\u2081 p\u2082 p\u2083 : P} (hs : Cospherical ({p\u2081, p\u2082, p\u2083} : Set P))\n    (h\u2081\u2082 : p\u2081 \u2260 p\u2082) (h\u2081\u2083 : p\u2081 \u2260 p\u2083) (h\u2082\u2083 : p\u2082 \u2260 p\u2083) : AffineIndependent \u211d ![p\u2081, p\u2082, p\u2083] :=\n  hs.affineIndependent_of_mem_of_ne (Set.mem_insert _ _)\n    (Set.mem_insert_of_mem _ (Set.mem_insert _ _))\n    (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _))) h\u2081\u2082 h\u2081\u2083 h\u2082\u2083\n#align euclidean_geometry.cospherical.affine_independent_of_ne EuclideanGeometry.Cospherical.affineIndependent_of_ne\n\n/-- Suppose that `p\u2081` and `p\u2082` lie in spheres `s\u2081` and `s\u2082`.  Then the vector between the centers\nof those spheres is orthogonal to that between `p\u2081` and `p\u2082`; this is a version of\n`inner_vsub_vsub_of_dist_eq_of_dist_eq` for bundled spheres.  (In two dimensions, this says that\nthe diagonals of a kite are orthogonal.) -/\ntheorem inner_vsub_vsub_of_mem_sphere_of_mem_sphere {p\u2081 p\u2082 : P} {s\u2081 s\u2082 : Sphere P} (hp\u2081s\u2081 : p\u2081 \u2208 s\u2081)\n    (hp\u2082s\u2081 : p\u2082 \u2208 s\u2081) (hp\u2081s\u2082 : p\u2081 \u2208 s\u2082) (hp\u2082s\u2082 : p\u2082 \u2208 s\u2082) :\n    \u27eas\u2082.center -\u1d65 s\u2081.center, p\u2082 -\u1d65 p\u2081\u27eb = 0 :=\n  inner_vsub_vsub_of_dist_eq_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere hp\u2081s\u2081 hp\u2082s\u2081)\n    (dist_center_eq_dist_center_of_mem_sphere hp\u2081s\u2082 hp\u2082s\u2082)\n#align euclidean_geometry.inner_vsub_vsub_of_mem_sphere_of_mem_sphere EuclideanGeometry.inner_vsub_vsub_of_mem_sphere_of_mem_sphere\n\n/-- Two spheres intersect in at most two points in a two-dimensional subspace containing their\ncenters; this is a version of `eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two` for bundled\nspheres. -/\ntheorem eq_of_mem_sphere_of_mem_sphere_of_mem_of_finrank_eq_two {s : AffineSubspace \u211d P}\n    [FiniteDimensional \u211d s.direction] (hd : finrank \u211d s.direction = 2) {s\u2081 s\u2082 : Sphere P}\n    {p\u2081 p\u2082 p : P} (hs\u2081 : s\u2081.center \u2208 s) (hs\u2082 : s\u2082.center \u2208 s) (hp\u2081s : p\u2081 \u2208 s) (hp\u2082s : p\u2082 \u2208 s)\n    (hps : p \u2208 s) (hs : s\u2081 \u2260 s\u2082) (hp : p\u2081 \u2260 p\u2082) (hp\u2081s\u2081 : p\u2081 \u2208 s\u2081) (hp\u2082s\u2081 : p\u2082 \u2208 s\u2081) (hps\u2081 : p \u2208 s\u2081)\n    (hp\u2081s\u2082 : p\u2081 \u2208 s\u2082) (hp\u2082s\u2082 : p\u2082 \u2208 s\u2082) (hps\u2082 : p \u2208 s\u2082) : p = p\u2081 \u2228 p = p\u2082 :=\n  eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd hs\u2081 hs\u2082 hp\u2081s hp\u2082s hps\n    ((Sphere.center_ne_iff_ne_of_mem hps\u2081 hps\u2082).2 hs) hp hp\u2081s\u2081 hp\u2082s\u2081 hps\u2081 hp\u2081s\u2082 hp\u2082s\u2082 hps\u2082\n#align euclidean_geometry.eq_of_mem_sphere_of_mem_sphere_of_mem_of_finrank_eq_two EuclideanGeometry.eq_of_mem_sphere_of_mem_sphere_of_mem_of_finrank_eq_two\n\n/-- Two spheres intersect in at most two points in two-dimensional space; this is a version of\n`eq_of_dist_eq_of_dist_eq_of_finrank_eq_two` for bundled spheres. -/\ntheorem eq_of_mem_sphere_of_mem_sphere_of_finrank_eq_two [FiniteDimensional \u211d V]\n    (hd : finrank \u211d V = 2) {s\u2081 s\u2082 : Sphere P} {p\u2081 p\u2082 p : P} (hs : s\u2081 \u2260 s\u2082) (hp : p\u2081 \u2260 p\u2082)\n    (hp\u2081s\u2081 : p\u2081 \u2208 s\u2081) (hp\u2082s\u2081 : p\u2082 \u2208 s\u2081) (hps\u2081 : p \u2208 s\u2081) (hp\u2081s\u2082 : p\u2081 \u2208 s\u2082) (hp\u2082s\u2082 : p\u2082 \u2208 s\u2082)\n    (hps\u2082 : p \u2208 s\u2082) : p = p\u2081 \u2228 p = p\u2082 :=\n  eq_of_dist_eq_of_dist_eq_of_finrank_eq_two hd ((Sphere.center_ne_iff_ne_of_mem hps\u2081 hps\u2082).2 hs) hp\n    hp\u2081s\u2081 hp\u2082s\u2081 hps\u2081 hp\u2081s\u2082 hp\u2082s\u2082 hps\u2082\n#align euclidean_geometry.eq_of_mem_sphere_of_mem_sphere_of_finrank_eq_two EuclideanGeometry.eq_of_mem_sphere_of_mem_sphere_of_finrank_eq_two\n\n/-- Given a point on a sphere and a point not outside it, the inner product between the\ndifference of those points and the radius vector is positive unless the points are equal. -/\ntheorem inner_pos_or_eq_of_dist_le_radius {s : Sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n    (hp\u2082 : dist p\u2082 s.center \u2264 s.radius) : 0 < \u27eap\u2081 -\u1d65 p\u2082, p\u2081 -\u1d65 s.center\u27eb \u2228 p\u2081 = p\u2082 :=\n  by\n  by_cases h : p\u2081 = p\u2082; \u00b7 exact Or.inr h\n  refine' Or.inl _\n  rw [mem_sphere] at hp\u2081\n  rw [\u2190 vsub_sub_vsub_cancel_right p\u2081 p\u2082 s.center, inner_sub_left,\n    real_inner_self_eq_norm_mul_norm,--, \u2190dist_eq_norm_vsub, hp\u2081\n    sub_pos]\n  refine'\n    lt_of_le_of_ne ((real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right _ (norm_nonneg _))) _\n  \u00b7 rwa [\u2190 dist_eq_norm_vsub, \u2190 dist_eq_norm_vsub, hp\u2081]\n  \u00b7 rcases hp\u2082.lt_or_eq with (hp\u2082' | hp\u2082')\n    \u00b7 refine' ((real_inner_le_norm _ _).trans_lt (mul_lt_mul_of_pos_right _ _)).Ne\n      \u00b7 rwa [\u2190 hp\u2081, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp\u2082'\n      \u00b7 rw [norm_pos_iff, vsub_ne_zero]\n        rintro rfl\n        rw [\u2190 hp\u2081] at hp\u2082'\n        refine' (dist_nonneg.not_lt : \u00acdist p\u2082 s.center < 0) _\n        simpa using hp\u2082'\n    \u00b7 rw [\u2190 hp\u2081, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp\u2082'\n      nth_rw 1 [\u2190 hp\u2082']\n      rw [Ne.def, inner_eq_norm_mul_iff_real, hp\u2082', \u2190 sub_eq_zero, \u2190 smul_sub,\n        vsub_sub_vsub_cancel_right, \u2190 Ne.def, smul_ne_zero_iff, vsub_ne_zero,\n        and_iff_left (Ne.symm h), norm_ne_zero_iff, vsub_ne_zero]\n      rintro rfl\n      refine' h (Eq.symm _)\n      simpa using hp\u2082'\n#align euclidean_geometry.inner_pos_or_eq_of_dist_le_radius EuclideanGeometry.inner_pos_or_eq_of_dist_le_radius\n\n/-- Given a point on a sphere and a point not outside it, the inner product between the\ndifference of those points and the radius vector is nonnegative. -/\ntheorem inner_nonneg_of_dist_le_radius {s : Sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n    (hp\u2082 : dist p\u2082 s.center \u2264 s.radius) : 0 \u2264 \u27eap\u2081 -\u1d65 p\u2082, p\u2081 -\u1d65 s.center\u27eb :=\n  by\n  rcases inner_pos_or_eq_of_dist_le_radius hp\u2081 hp\u2082 with (h | rfl)\n  \u00b7 exact h.le\n  \u00b7 simp\n#align euclidean_geometry.inner_nonneg_of_dist_le_radius EuclideanGeometry.inner_nonneg_of_dist_le_radius\n\n/-- Given a point on a sphere and a point inside it, the inner product between the difference of\nthose points and the radius vector is positive. -/\ntheorem inner_pos_of_dist_lt_radius {s : Sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n    (hp\u2082 : dist p\u2082 s.center < s.radius) : 0 < \u27eap\u2081 -\u1d65 p\u2082, p\u2081 -\u1d65 s.center\u27eb :=\n  by\n  by_cases h : p\u2081 = p\u2082\n  \u00b7 rw [h, mem_sphere] at hp\u2081\n    exact False.elim (hp\u2082.ne hp\u2081)\n  exact (inner_pos_or_eq_of_dist_le_radius hp\u2081 hp\u2082.le).resolve_right h\n#align euclidean_geometry.inner_pos_of_dist_lt_radius EuclideanGeometry.inner_pos_of_dist_lt_radius\n\n/-- Given three collinear points, two on a sphere and one not outside it, the one not outside it\nis weakly between the other two points. -/\ntheorem wbtw_of_collinear_of_dist_center_le_radius {s : Sphere P} {p\u2081 p\u2082 p\u2083 : P}\n    (h : Collinear \u211d ({p\u2081, p\u2082, p\u2083} : Set P)) (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : dist p\u2082 s.center \u2264 s.radius)\n    (hp\u2083 : p\u2083 \u2208 s) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) : Wbtw \u211d p\u2081 p\u2082 p\u2083 :=\n  h.wbtw_of_dist_eq_of_dist_le hp\u2081 hp\u2082 hp\u2083 hp\u2081p\u2083\n#align euclidean_geometry.wbtw_of_collinear_of_dist_center_le_radius EuclideanGeometry.wbtw_of_collinear_of_dist_center_le_radius\n\n/-- Given three collinear points, two on a sphere and one inside it, the one inside it is\nstrictly between the other two points. -/\ntheorem sbtw_of_collinear_of_dist_center_lt_radius {s : Sphere P} {p\u2081 p\u2082 p\u2083 : P}\n    (h : Collinear \u211d ({p\u2081, p\u2082, p\u2083} : Set P)) (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : dist p\u2082 s.center < s.radius)\n    (hp\u2083 : p\u2083 \u2208 s) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) : Sbtw \u211d p\u2081 p\u2082 p\u2083 :=\n  h.sbtw_of_dist_eq_of_dist_lt hp\u2081 hp\u2082 hp\u2083 hp\u2081p\u2083\n#align euclidean_geometry.sbtw_of_collinear_of_dist_center_lt_radius EuclideanGeometry.sbtw_of_collinear_of_dist_center_lt_radius\n\nend EuclideanSpace\n\nend EuclideanGeometry\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Geometry/Euclidean/Sphere/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.7228249169186013}}
{"text": "/-\nCopyright (c) 2022 Andrew Yang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Andrew Yang\n-/\nimport algebra.gcd_monoid.basic\nimport ring_theory.integrally_closed\nimport ring_theory.polynomial.eisenstein.basic\n\n/-!\n\n# GCD domains are integrally closed\n\n-/\n\nopen_locale big_operators polynomial\n\nvariables {R A : Type*} [comm_ring R] [is_domain R] [gcd_monoid R] [comm_ring A] [algebra R A]\n\nlemma is_localization.surj_of_gcd_domain (M : submonoid R) [is_localization M A] (z : A) :\n  \u2203 a b : R, is_unit (gcd a b) \u2227 z * algebra_map R A b = algebra_map R A a :=\nbegin\n  obtain \u27e8x, \u27e8y, hy\u27e9, rfl\u27e9 := is_localization.mk'_surjective M z,\n  obtain \u27e8x', y', hx', hy', hu\u27e9 := extract_gcd x y,\n  use [x', y', hu],\n  rw [mul_comm, is_localization.mul_mk'_eq_mk'_of_mul],\n  convert is_localization.mk'_mul_cancel_left _ _ using 2,\n  { rw [subtype.coe_mk, hy', \u2190 mul_comm y', mul_assoc], conv_lhs { rw hx' } },\n  { apply_instance },\nend\n\n@[priority 100]\ninstance gcd_monoid.to_is_integrally_closed : is_integrally_closed R :=\n\u27e8\u03bb X \u27e8p, hp\u2081, hp\u2082\u27e9, begin\n  obtain \u27e8x, y, hg, he\u27e9 := is_localization.surj_of_gcd_domain (non_zero_divisors R) X,\n  have := polynomial.dvd_pow_nat_degree_of_eval\u2082_eq_zero\n    (is_fraction_ring.injective R $ fraction_ring R) hp\u2081 y x _ hp\u2082 (by rw [mul_comm, he]),\n  have : is_unit y,\n  { rw [is_unit_iff_dvd_one, \u2190 one_pow],\n    exact (dvd_gcd this $ dvd_refl y).trans (gcd_pow_left_dvd_pow_gcd.trans $\n      pow_dvd_pow_of_dvd (is_unit_iff_dvd_one.1 hg) _) },\n  use x * (this.unit\u207b\u00b9 : _),\n  erw [map_mul, \u2190 units.coe_map_inv, eq_comm, units.eq_mul_inv_iff_mul_eq],\n  exact he,\nend\u27e9\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/gcd_monoid/integrally_closed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7227940536313501}}
{"text": "import tactic.norm_num chris_hughes_various.zmod data.nat.prime data.nat.basic data.int.modeq algebra.group_power group_theory.subgroup algebra.group data.set.basic group_theory.order_of_element\nopen nat \n\nuniverses u v w x\nvariables m p : \u2115 \nvariables {G : Type u} {H : Type v} \nvariables [group G] [group H] [group (zmod 11)] [add_group (zmod m)] [group (zmod p)]\n\ndefinition is_cyclic (G : Type*) [group G] := \u2203 x : G, gpowers x = set.univ\n-- *1. Suppose that G is a finite group which contains elements of each of the orders 1, 2, . . . , 10. What is the smallest possible value of |G|? Find a group of this size which does have elements of each of these orders.\n--theorem sheet07_q1 (G : Type*) (g : group) : := sorry\n\n-- 2. What is the largest order of an element of S\u2088?\n    -- Ans: 15\n-- theorem sheet07_q2:\n\n-- 3. Let G be a cyclic group of order n, and g a generator. Show that gk is a generator for G if and only if hcf(k, n) = 1.\n-- theorem sheet07_q3:\n\n-- 4. Let G and H be finite groups. Let G\u00d7H be the set {(g,h)|g\u2208G,h\u2208H} with the binary operation (g1, h1) \u2217 (g2, h2) = (g1g2, h1h2).\ndefinition Cart_prod := prod G H \n--definition bin_op (G : Type*) (H : Type*) (g\u2081 g\u2082 : prod G H) := prod (g\u2081.1 * g\u2082.1) (g1.2 * g2.2)\n\n-- (a) Show that (G\u00d7H,\u2217) is a group.\n-- theorem sheet07_q4a:\n\n-- (b) Show that if g \u2208 G and h \u2208 H have orders a, b respectively, then the order of (g,h) in G\u00d7H is the lowest common multiple of a and b.\n-- theorem sheet07_q4b:\n\n-- (c) Show that G \u00d7 H is cyclic if and only if G and H are both cyclic, and hcf(|G|,|H|) = 1.\n-- theorem sheet07_q4c:\n\n-- 5. Say whether each of the following statements is true or false, giving a counterexample or a brief proof.\n    -- all these are true lmao\n\n-- (a) For any positive integer m, the group (\u2124_m,+) is cyclic.\n--theorem sheet07_q5a (m : \u2115) : is_cyclic (zmod m) \u2192 true := sorry\n\n-- (b) \u2124_11 is a cyclic group.\ntheorem sheet07_q5b : is_cyclic (zmod 11) \u2192 true := sorry\n\n-- (c) If p is an odd prime, then \u2124_p has exactly one element of order 2.\n--theorem sheet07_q5c (p : \u2115) (hp : prime p) (x : zmod p) : \u2203! x \u2208 zmod p := sorry\n\n-- (d) If p is a prime number with p \u2261 4 mod 5,then the inverse of [5] in \u2124_p is \udbff\udc00p+1\udbff\udc01.\ntheorem sheet07_q5d (p x : \u2115) (hp : prime p) (hq : p \u2261 4 [MOD 5]) : 5*x \u2261 1 [MOD p] \u2192 x = p+1 := sorry\n\ntheorem flittle_thm (n p : \u2115) (hp : prime p) : n ^ (p-1) \u2261 1 [MOD p] := sorry\n-- 6. (a) Find the remainder when 5^110 is divided by 13.\n    -- Ans: 12.\n\ninstance (n : \u2115) : pos_nat (succ n) := \u27e8succ_pos _ \u27e9 \n\ntheorem sheet07_q6a: 5^110 \u2261 12 [MOD 13] := sorry\n--begin \n--rw \u2190 @zmod.cast_val_of_lt 5 13 dec_trivial,\n--rw \u2190 @zmod.cast_val_of_lt 12 13 dec_trivial,\n--end\n\n-- (b) Find the inverses of [2] and of [120] in \u2124_9871. (The number 9871 is prime.)\n    -- Ans: 4936, 7321 respectively\ntheorem sheet07_q6bi (x : \u2115) : 2*x \u2261 1 [MOD 9871] \u2192 x = 4936 := sorry\ntheorem sheet07_q6bii (x : \u2115) : 120*x \u2261 1 [MOD 9871] \u2192 x = 7321 := sorry\n\n-- (c) Use Fermat\u2019s Little Theorem to show that n^17 \u2261 n mod 255 for all n \u2208 \u2124. \ntheorem sheet07_q6c (n : \u2115) : n^17 \u2261 n [MOD 255] := sorry\n\n-- (d) Prove that if p and q are distinct prime numbers then p^(q-1) + q^(p\u22121) \u2261 1 mod pq.\ntheorem sheet07_q6d (p q : \u2115) (hp: prime p) (hq: prime q) : p^(q-1) + q^(p-1) \u2261 1 [MOD p*q] := sorry\n\n-- 7. Let p be an odd prime.\n\n-- (a) Prove that (p \u2212 1)! \u2261 \u22121 mod p (Wilson\u2019s Theorem).\ntheorem sheet07_q7a (p : \u2115) (hp : prime p) : fact (p-1) \u2261 -1 [ZMOD p] := sorry \n\n-- (b) Show that if p \u2261 1 mod 4,then there is x \u2208 Z with x^2 \u2261 \u22121 (mod p).\ntheorem sheet07_q7b (p : \u2115) (hp : prime p) (x : \u2124): p \u2261 1 [ZMOD 4] \u2192 x^2 \u2261 -1 [ZMOD p] := sorry\n\n-- (c) Show that if p \u2260 2 and there is x\u2208Z with x^2 \u2261\u22121 modp,then p \u2261 1 mod 4.\ntheorem sheet07_q7c (p : \u2115) (hp : prime p) (x : \u2124) : p \u2260 2 \u2227 x^2 \u2261 -1 [ZMOD p] \u2192 p \u2261 1 [ZMOD 4] := sorry\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1P2/sheet_7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.7227940515901188}}
{"text": "/-\nCopyright (c) 2020 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Anatole Dedecker\n-/\nimport topology.separation\n\n/-!\n# Extending a function from a subset\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe main definition of this file is `extend_from A f` where `f : X \u2192 Y`\nand `A : set X`. This defines a new function `g : X \u2192 Y` which maps any\n`x\u2080 : X` to the limit of `f` as `x` tends to `x\u2080`, if such a limit exists.\n\nThis is analoguous to the way `dense_inducing.extend` \"extends\" a function\n`f : X \u2192 Z` to a function `g : Y \u2192 Z` along a dense inducing `i : X \u2192 Y`.\n\nThe main theorem we prove about this definition is `continuous_on_extend_from`\nwhich states that, for `extend_from A f` to be continuous on a set `B \u2286 closure A`,\nit suffices that `f` converges within `A` at any point of `B`, provided that\n`f` is a function to a T\u2083 space.\n\n-/\n\nnoncomputable theory\n\nopen_locale topology\nopen filter set\n\nvariables {X Y : Type*} [topological_space X] [topological_space Y]\n\n/-- Extend a function from a set `A`. The resulting function `g` is such that\nat any `x\u2080`, if `f` converges to some `y` as `x` tends to `x\u2080` within `A`,\nthen `g x\u2080` is defined to be one of these `y`. Else, `g x\u2080` could be anything. -/\ndef extend_from (A : set X) (f : X \u2192 Y) : X \u2192 Y :=\n\u03bb x, @@lim _ \u27e8f x\u27e9 (\ud835\udcdd[A] x) f\n\n/-- If `f` converges to some `y` as `x` tends to `x\u2080` within `A`,\nthen `f` tends to `extend_from A f x` as `x` tends to `x\u2080`. -/\nlemma tendsto_extend_from {A : set X} {f : X \u2192 Y} {x : X}\n  (h : \u2203 y, tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd $ extend_from A f x) :=\ntendsto_nhds_lim h\n\nlemma extend_from_eq [t2_space Y] {A : set X} {f : X \u2192 Y} {x : X} {y : Y} (hx : x \u2208 closure A)\n  (hf : tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : extend_from A f x = y :=\nbegin\n  haveI := mem_closure_iff_nhds_within_ne_bot.mp hx,\n  exact tendsto_nhds_unique (tendsto_nhds_lim \u27e8y, hf\u27e9) hf,\nend\n\nlemma extend_from_extends [t2_space Y] {f : X \u2192 Y} {A : set X} (hf : continuous_on f A) :\n  \u2200 x \u2208 A, extend_from A f x = f x :=\n\u03bb x x_in, extend_from_eq (subset_closure x_in) (hf x x_in)\n\n/-- If `f` is a function to a T\u2083 space `Y` which has a limit within `A` at any\npoint of a set `B \u2286 closure A`, then `extend_from A f` is continuous on `B`. -/\nlemma continuous_on_extend_from [regular_space Y] {f : X \u2192 Y} {A B : set X} (hB : B \u2286 closure A)\n  (hf : \u2200 x \u2208 B, \u2203 y, tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : continuous_on (extend_from A f) B :=\nbegin\n  set \u03c6 := extend_from A f,\n  intros x x_in,\n  suffices : \u2200 V' \u2208 \ud835\udcdd (\u03c6 x), is_closed V' \u2192 \u03c6 \u207b\u00b9' V' \u2208 \ud835\udcdd[B] x,\n    by simpa [continuous_within_at, (closed_nhds_basis _).tendsto_right_iff],\n  intros V' V'_in V'_closed,\n  obtain \u27e8V, V_in, V_op, hV\u27e9 : \u2203 V \u2208 \ud835\udcdd x, is_open V \u2227 V \u2229 A \u2286 f \u207b\u00b9' V',\n  { have := tendsto_extend_from (hf x x_in),\n    rcases (nhds_within_basis_open x A).tendsto_left_iff.mp this V' V'_in with \u27e8V, \u27e8hxV, V_op\u27e9, hV\u27e9,\n    use [V, is_open.mem_nhds V_op hxV, V_op, hV] },\n  suffices : \u2200 y \u2208 V \u2229 B, \u03c6 y \u2208 V',\n    from mem_of_superset (inter_mem_inf V_in $ mem_principal_self B) this,\n  rintros y \u27e8hyV, hyB\u27e9,\n  haveI := mem_closure_iff_nhds_within_ne_bot.mp (hB hyB),\n  have limy : tendsto f (\ud835\udcdd[A] y) (\ud835\udcdd $ \u03c6 y) := tendsto_extend_from (hf y hyB),\n  have hVy : V \u2208 \ud835\udcdd y := is_open.mem_nhds V_op hyV,\n  have : V \u2229 A \u2208 (\ud835\udcdd[A] y),\n    by simpa [inter_comm] using inter_mem_nhds_within _ hVy,\n  exact V'_closed.mem_of_tendsto limy (mem_of_superset this hV)\nend\n\n/-- If a function `f` to a T\u2083 space `Y` has a limit within a\ndense set `A` for any `x`, then `extend_from A f` is continuous. -/\nlemma continuous_extend_from [regular_space Y] {f : X \u2192 Y} {A : set X} (hA : dense A)\n  (hf : \u2200 x, \u2203 y, tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : continuous (extend_from A f) :=\nbegin\n  rw continuous_iff_continuous_on_univ,\n  exact continuous_on_extend_from (\u03bb x _, hA x) (by simpa using hf)\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/extend_from.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7227940443093824}}
{"text": "\ndef f ( x : \u2115 ) := x + 1\n\nlemma p : f 3 = 4 := begin unfold f, trivial end\n\nstructure X ( n : \u2115 ) :=\n  ( m : \u2115 )\n\n@[reducible] def g ( x : X (f 3) ) : X 4 :=\nbegin\n  pose y := @X.mk (f 3) x.m, \n  refine (cast _ x),\n  rewrite p\nend\n\nlemma h ( x : X (f 3) ) ( h : x.m = 0 ) : (g x).m = 0 :=\nbegin\n-- https://groups.google.com/d/msg/lean-user/HVHlA4eXtxw/G0GUtjPGDAAJ\n-- Jeremy suggests using:\n  rewrite -h,\n  reflexivity,\n  \n  -- I had tried:\n--   dsimp,\n--   unfold g._proof_1,\n  -- What can I do with this?\n  --   \u22a2 (eq.rec x (eq.rec (eq.refl (X 4)) (eq.symm _root_.p))).m = 0\nend", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/20170405-eq.rec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7879312031126511, "lm_q1q2_score": 0.7227713917484566}}
{"text": "\nimport algebra.ordered_ring\n\nimport tactic\n\n---------------------\n---------------------\n---------------------\n\n-- Ex 1\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := iff.intro\n(\u03bb h, \n  have h' : (\u2200 x : \u03b1, p x), from (assume y : \u03b1, (h y).1),\n  have h'' : (\u2200 x : \u03b1, q x), from (assume y : \u03b1, (h y).2),\n  and.intro h' h'')\n(\u03bb h y, and.intro (h.1 y) (h.2 y))\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := \n(\u03bb x y, assume s : \u03b1, ((x s) (y s)))\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := \n(\u03bb h, assume s:\u03b1, h.elim \n  (\u03bb h', or.inl (h' s))\n  (\u03bb h', or.inr (h' s))\n)\n\n-- Ex 2 \nvariable r : Prop\n\nexample : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) := (\u03bb t, iff.intro\n  (\u03bb f, f t)\n  (\u03bb s _, s)\n)\n\nsection LEM\nopen classical -- Need LEM for half of this\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r := iff.intro\n  (by_cases \n    (assume s : r, \u03bb _, or.inr s) \n    (assume s: \u00acr, \u03bb h, or.inl (assume z : \u03b1, (h z).elim \n      (\u03bb w, w) \n      (\u03bb h', absurd h' s)\n    ))\n  )\n  (\u03bb h, assume y : \u03b1, h.elim (\u03bb t, or.inl (t y)) (or.inr))\n\nend LEM\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) := iff.intro \n  (\u03bb h a, assume s : \u03b1, (h s a)) \n  (\u03bb h, assume s:\u03b1, \u03bb t, (h t s))\n\n-- Ex 3\nvariables (men : Type) (barber : men)\nvariable  (shaves : men \u2192 men \u2192 Prop)\n\n-- Used the solver because I already solved this essentially\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) :\n  false :=  have p: (shaves barber barber \u2194 \u00acshaves barber barber), from h barber,\n  (not_iff_self (shaves barber barber)).mp (iff.symm (h barber))\n\n-- Ex 4\nnamespace hidden\n\ndef divides (m n : \u2115) : Prop := \u2203 k, m * k = n\n\ninstance : has_dvd nat := \u27e8divides\u27e9\n\ndef even (n : \u2115) : Prop := 2 \u2223 n -- You can enter the '\u2223' character by typing \\mid\n\nsection\n  variables m n : \u2115\n\n  #check m \u2223 n\n  #check m^n\n  #check even (m^n +3)\nend\n\nend hidden\n\ndef prime (n : \u2115) : Prop := \u2200 a b : \u2115, (hidden.divides n (a*b) \u2192 (hidden.divides n a \u2228 hidden.divides n b))\n\ndef infinitely_many_primes : Prop := (\u2200 p : \u2115, (prime p) \u2192 (\u2203 m : \u2115, (p < m) \u2227 prime m))\n\ndef Fermat_prime (n : \u2115) : Prop := \u2203 k : \u2115, (n = 2^(2^k)) \u2227 prime n\n\ndef infinitely_many_Fermat_primes : Prop := (\u2200 p : \u2115, (Fermat_prime p) \u2192 (\u2203 m : \u2115, (p < m) \u2227 Fermat_prime m))\n\ndef goldbach_conjecture : Prop := \u2200 n : \u2115, (3 \u2264 n) \u2192 (\u2203 p q :\u2115, (prime p) \u2227 (prime q) \u2227 (n = p + q))\n\ndef Goldbach's_weak_conjecture : Prop := \u2200 k, (2\u2264 k) \u2192 (\u2203 p q r : \u2115, (prime p) \u2227 (prime q) \u2227 (prime r) \u2227 (2*k+1=p+q+r))\n\ndef Fermat's_last_theorem : Prop := \u2200 n : \u2115, 3 \u2264 n \u2192 \u00ac\u2203 a b c :\u2115, a^n+b^n=c^n\n\n-- Ex 5\n\nsection EX5\nopen classical\n\nvariable a : \u03b1\n\nexample : (\u2203 x : \u03b1, r) \u2192 r := assume \u27e8 x, hr \u27e9, hr \n\nexample : r \u2192 (\u2203 x : \u03b1, r) := \u03bb h, exists.intro a h \n\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := iff.intro\n(\u03bb h, exists.elim h (\u03bb a b, and.intro \u27e8a, b.1\u27e9  b.2))\n(\u03bb h, exists.elim h.1 (\u03bb b h', \u27e8b,and.intro h' h.2\u27e9))\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := sorry\n\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := sorry\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := sorry\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) := sorry\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := sorry\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := sorry\nexample : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := sorry\nexample : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := sorry\n\nend EX5\n\n\n-- Ex 6\n\nvariables (real : Type) [ordered_ring real]\nvariables (log exp : real \u2192 real)\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y := calc\n  log (x * y) = log (exp (log x) * exp (log y))     : by rw [exp_log_eq hx, exp_log_eq hy]\n          ... = log (exp (log x + log y))           : by rw [exp_add (log x) (log y)]\n          ... = log x + log y                       : by rw [log_exp_eq]\n\n-- Ex 7\n#check sub_self\n\nexample (x : \u2124) : x * 0 = 0 := calc\n  x * 0 = x * (1 - 1)   : by rw sub_self\n   ...  = x * 1 - x * 1 : by rw mul_sub\n   ...  = x - x         : by rw mul_one\n   ...  = 0             : by rw sub_self\n", "meta": {"author": "NicoCourts", "repo": "learning-lean", "sha": "02aba16b52adf541f8ebce5da38309ef2b7fcdfb", "save_path": "github-repos/lean/NicoCourts-learning-lean", "path": "github-repos/lean/NicoCourts-learning-lean/learning-lean-02aba16b52adf541f8ebce5da38309ef2b7fcdfb/src/doc_examples/section4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7227713846231659}}
{"text": "open classical\n\nvariables p q r s : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := \n\u27e8\u03bbh, \u27e8h.right, h.left\u27e9, \u03bbh, \u27e8h.right, h.left\u27e9\u27e9\n\nexample : p \u2228 q \u2194 q \u2228 p :=\n\u27e8\u03bbh, h.elim (\u03bbh\u2081, or.inr h\u2081) (\u03bbh\u2081, or.inl h\u2081),\n\u03bbh, h.elim (\u03bbh\u2081, or.inr h\u2081) (\u03bbh\u2081, or.inl h\u2081)\u27e9 \n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n\u27e8\u03bbh, \u27e8h.left.left, \u27e8h.left.right, h.right\u27e9\u27e9,\n\u03bbh, \u27e8\u27e8h.left, h.right.left\u27e9, h.right.right\u27e9\u27e9\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n\u27e8\u03bbh, h.elim \n    (\u03bbh\u2081, h\u2081.elim (or.inl) (\u03bbh\u2082, or.inr (or.inl h\u2082))) \n    (\u03bbh\u2081, or.inr (or.inr h\u2081)),\n\u03bbh, h.elim \n    (\u03bbh\u2081, or.inl (or.inl h\u2081))\n    (\u03bbh\u2081, h\u2081.elim (\u03bbh\u2082, or.inl (or.inr h\u2082)) (or.inr))\u27e9\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := \n\u27e8\u03bbh, (h.right).elim\n    (\u03bbh\u2081, or.inl \u27e8h.left, h\u2081\u27e9)\n    (\u03bbh\u2081, or.inr \u27e8h.left, h\u2081\u27e9),\n\u03bbh, h.elim\n    (\u03bbh\u2081, \u27e8h\u2081.left, or.inl (h\u2081.right)\u27e9)\n    (\u03bbh\u2081, \u27e8h\u2081.left, or.inr (h\u2081.right)\u27e9)\u27e9\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n\u27e8\u03bbh, h.elim\n    (\u03bbh\u2081, \u27e8or.inl h\u2081, or.inl h\u2081\u27e9)\n    (\u03bbh\u2081, \u27e8or.inr (h\u2081.left), or.inr (h\u2081.right)\u27e9),\n\u03bbh, (h.left).elim \n    (or.inl)\n    (\u03bbh\u2081, (h.right.elim (or.inl) (\u03bbh\u2082, or.inr \u27e8h\u2081, h\u2082\u27e9)))\u27e9\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n\u27e8\u03bbh, \u03bbh\u2081, h (h\u2081.left) (h\u2081.right), \n\u03bbh, \u03bbh\u2081, \u03bbh\u2082, h \u27e8h\u2081, h\u2082\u27e9\u27e9\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := \n\u27e8\u03bbh, \u27e8\u03bbh\u2081, h (or.inl h\u2081), \u03bbh\u2081, h (or.inr h\u2081)\u27e9, \n\u03bbh, \u03bbh\u2081, h\u2081.elim (h.left) (h.right)\u27e9\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n\u27e8\u03bbh, \u27e8\u03bbh\u2081, h (or.inl h\u2081), \u03bbh\u2081, h (or.inr h\u2081)\u27e9,  \n\u03bbh, \u03bbh\u2081, h\u2081.elim (h.left) (h.right)\u27e9\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n\u03bbh, \u03bbh\u2081, h.elim (\u03bbh\u2082, h\u2082 h\u2081.left) (\u03bbh\u2082, h\u2082 h\u2081.right)\n\nexample : \u00ac(p \u2227 \u00acp) := \n\u03bbh, (h.right) (h.left)\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n\u03bbh, \u03bbh\u2081, (h.right) (h\u2081 (h.left)) \n\nexample : \u00acp \u2192 (p \u2192 q) :=\n\u03bbh, \u03bbh\u2081, absurd h\u2081 h \n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n\u03bbh, \u03bbh\u2081, h.elim (absurd h\u2081 h\u2082=) id\n\nexample : p \u2228 false \u2194 p := \n\u27e8\u03bbh, h.elim id (false.elim), or.inl\u27e9\n\nexample : p \u2227 false \u2194 false := \n\u27e8and.right, false.elim\u27e9\n\nexample : \u00ac(p \u2194 \u00acp) := \n\u03bbh, by_cases (\u03bbh\u2081, (h.mp h\u2081) h\u2081) (\u03bbh\u2081, h\u2081 (h.mpr h\u2081))\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n\u03bbh, \u03bbh\u2081, \u03bbh\u2082, h\u2081 (h h\u2082)\n\n-- these require classical reasoning\nopen classical \nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n\u03bbh, by_cases \n    (\u03bbh\u2081, (h h\u2081).elim (\u03bbh\u2082, or.inl (\u03bbh\u2081, h\u2082)) (\u03bbh\u2082, or.inr (\u03bbh\u2081, h\u2082))) \n    (\u03bbh\u2081, or.inl (\u03bbh\u2082, absurd h\u2082 h\u2081)) \n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := \n\u03bbh, by_cases (\u03bbh\u2081, or.inr (\u03bbh\u2082, h \u27e8h\u2081, h\u2082\u27e9)) (or.inl)\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := \n\u03bbh, by_cases\n    (\u03bbh\u2081, by_cases (\u03bbh\u2082, absurd (\u03bbh\u2081, h\u2082) h) (and.intro h\u2081))\n    (\u03bbh\u2081, absurd (\u03bbh\u2082, absurd h\u2082 h\u2081) h)\n/- em q\n\u03bbh, by_cases\n    (\u03bbh\u2081, absurd (\u03bbh\u2082, h\u2081) h)\n    (\u03bbh\u2081, by_cases (\u03bbh\u2082, \u27e8h\u2082, h\u2081\u27e9) (\u03bbh\u2082, absurd (\u03bbh\u2083, absurd h\u2083 h\u2082) h))\n-/\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := \n\u03bbh, by_cases (\u03bbh\u2081, or.inr (h h\u2081)) (or.inl)\n\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := \n\u03bbh, \u03bbh\u2081, by_contradiction (\u03bbh\u2082, (h h\u2082) h\u2081)\n\nexample : p \u2228 \u00acp := \nem p \n--by_cases (or.inl) (or.inr)\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\n\u03bbh, by_contradiction (\u03bbh\u2081, h\u2081 (h (\u03bbh\u2083, absurd h\u2083 h\u2081)))", "meta": {"author": "hieule3004", "repo": "Imperial", "sha": "829d0d96603ff3e68ede818873db4931b8d854da", "save_path": "github-repos/lean/hieule3004-Imperial", "path": "github-repos/lean/hieule3004-Imperial/Imperial-829d0d96603ff3e68ede818873db4931b8d854da/Imperial/prop_example.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7227713813337838}}
{"text": "/- \nCopyright (c) 2018 Blair Shi. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Kevin Buzzard, Blair Shi\n\nThis file is inspired by Johannes H\u00f6lzl's implementation of linear algebra in mathlib.\n\nThe thing we improved is this file describes finite dimentional vector spaces\n-/\n\nimport algebra.module -- for definition of vector_space  \nimport linear_algebra.basic -- for definition of is_basis \nimport data.list.basic\nimport analysis.real\nuniverses u v \n\nclass finite_dimensional_vector_space (k : Type u) (V : Type v) [field k] \n  extends vector_space k V :=\n(ordered_basis : list V)\n(is_ordered_basis : is_basis {v : V | v \u2208 ordered_basis})\n\n\nvariables {k : Type u} {V : Type v}\nvariable [field k]\nvariable [module k V]\nvariables {a : k} {b : V}\nvariable [decidable_eq V]\ninclude k \n#check list.has_union \n#check finset \ndefinition dimension (fvs : finite_dimensional_vector_space k V) : \u2115 :=\nfvs.ordered_basis.length\ntheorem Steinitz_exchange_lemma  (fvs : finite_dimensional_vector_space k V) {S T: list V}\n (SLD: linear_independent {v : V | v \u2208 S}) (TSS: span{v : V | v \u2208 T} = set.univ) : \u2203 T': list V, \n T' \u2286 T \u2227  T'.length =T.length \u2227 \n span {v:V | v \u2208 list.diff T  T' \u222a S} = (set.univ : set V) := \n  begin \n   \n  end\n\n \n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/xenalib/Keji_finite_dim_vector_spaces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7227713777711383}}
{"text": "import Mathlib\n/-!\n## Linear Diaphontine Equations\n\nWe solve linear diaphontine equations of the form `a * x + b * y = c` where `a`, `b`, `c` are integers if they have a solution with proof. Otherwise, we return a proof that there is no solution.\n-/\n\n/--\nSolution of the linear diaphontine equation `a * x + b * y = c` where `a`, `b`, `c` are integers or a proof that there is no solution.\n-/\ninductive DiaphontineSolution (a b c : \u2124) where\n    | solution : (x y : \u2124) \u2192  a * x + b * y = c \u2192 DiaphontineSolution a b c\n    | unsolvable : (\u2200 x y : \u2124, \u00ac (a * x + b * y = c)) \u2192 DiaphontineSolution a b c\n\n/-!\nThis has a solution if and only if the gcd of `a` and `b` divides `c`.\n* If the gcd of `a` and `b` divides `c`, by Bezout's Lemma there are integers `x` and `y` such that `a * x + b * y = gcd a b`. Further, as `gcd a b` divides `c`, we have an integer `d` such that `(gcd a b) * d = c`. Then `x * d` and `y * d` are integers such that `a * (x * d) + b * (y * d) = c`.\n* The converse follows as `gcd a b` divides `a` and `b`, hence `c = a * x + b * y`.\n\nThe main results we need are in the library. Here are most of them:\n\n```lean\n#check Int.gcd_dvd_left -- \u2200 (i j : \u2124), \u2191(Int.gcd i j) \u2223 i\n#check Int.emod_add_ediv -- \u2200 (a b : \u2124), a % b + b * (a / b) = a\n#check Int.emod_eq_zero_of_dvd -- \u2200 {a b : \u2124}, a \u2223 b \u2192 b % a = 0\n#check Int.dvd_mul_right -- \u2200 (a b : \u2124), a \u2223 a * b\n#check Int.gcd_eq_gcd_ab -- \u2200 (x y : \u2124), \u2191(Int.gcd x y) = x * Int.gcdA x y + y * Int.gcdB x y\n#check dvd_add /-\u2200 {\u03b1 : Type u_1} [inst : Add \u03b1] [inst_1 : Semigroup \u03b1] [inst_2 : LeftDistribClass \u03b1] {a b c : \u03b1},\n  a \u2223 b \u2192 a \u2223 c \u2192 a \u2223 b + c-/\n```\n-/\n\n#check Int.gcd_dvd_left -- \u2200 (i j : \u2124), \u2191(Int.gcd i j) \u2223 i\n#check Int.emod_add_ediv -- \u2200 (a b : \u2124), a % b + b * (a / b) = a\n#check Int.emod_eq_zero_of_dvd -- \u2200 {a b : \u2124}, a \u2223 b \u2192 b % a = 0\n#check Int.dvd_mul_right -- \u2200 (a b : \u2124), a \u2223 a * b\n#check Int.gcd_eq_gcd_ab -- \u2200 (x y : \u2124), \u2191(Int.gcd x y) = x * Int.gcdA x y + y * Int.gcdB x y\n#check dvd_add /-\u2200 {\u03b1 : Type u_1} [inst : Add \u03b1] [inst_1 : Semigroup \u03b1] [inst_2 : LeftDistribClass \u03b1] {a b c : \u03b1},\n  a \u2223 b \u2192 a \u2223 c \u2192 a \u2223 b + c-/\n\n/--\nGiven `a b : \u2124` such that `b \u2223 a`, we return an integer `q` such that `a = b * q`.\n-/\ndef dvdQuotient (a b: Int)(h : b \u2223 a) : {q : Int // a = b * q} := \n    let q := a / b\n    \u27e8q, by \n        rw [\u2190 Int.emod_add_ediv a b, Int.emod_eq_zero_of_dvd h, zero_add]\n        \u27e9\n\n/-- If `a * x + b * y = c` has a solution, then `gcd a b` divides `c`.\n-/\nlemma eqn_solvable_divides (a b c : \u2124) :\n    (\u2203 x : \u2124, \u2203 y : \u2124,  a * x + b * y = c) \u2192  \u2191(Int.gcd a b) \u2223 c := by\n    intro \u27e8x, y, h\u27e9\n    rw [\u2190 h]\n    apply dvd_add\n    \u00b7 trans a\n      \u00b7 apply Int.gcd_dvd_left  \n      \u00b7 apply Int.dvd_mul_right\n    \u00b7 trans b\n      \u00b7 apply Int.gcd_dvd_right  \n      \u00b7 apply Int.dvd_mul_right\n\n/-- Solution or proof there is no solution for `a * x + b * y = c`  -/\ndef DiaphontineSolution.solve (a b c : \u2124) : DiaphontineSolution a b c := \n    if h : \u2191(Int.gcd a b) \u2223 c  \n    then \n    by\n        let \u27e8d, h'\u27e9 := dvdQuotient (c: Int) (Int.gcd a b)  h \n        rw [Int.gcd_eq_gcd_ab a b] at h'\n        rw [add_mul, mul_assoc, mul_assoc] at h'\n        let x := (Int.gcdA a b * d)\n        let y := (Int.gcdB a b * d)\n        exact DiaphontineSolution.solution x y h'.symm         \n    else\n        by  \n        apply DiaphontineSolution.unsolvable\n        intro x y contra\n        apply h\n        apply eqn_solvable_divides a b c\n        use x, y\n        assumption   \n", "meta": {"author": "siddhartha-gadgil", "repo": "proofs-and-programs-2023", "sha": "9d95a5396c018b9a26ed0d27c52cd446794cd1aa", "save_path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023", "path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023/proofs-and-programs-2023-9d95a5396c018b9a26ed0d27c52cd446794cd1aa/PnP2023/Lec_03_08/Diaphontine.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7227713749844425}}
{"text": "/-\nCopyright (c) 2022 Pim Otte. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller, Pim Otte\n\n! This file was ported from Lean 3 source module data.nat.factorial.big_operators\n! leanprover-community/mathlib commit 327c3c0d9232d80e250dc8f65e7835b82b266ea5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Factorial.Basic\nimport Mathbin.Algebra.BigOperators.Order\n\n/-!\n# Factorial with big operators\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains some lemmas on factorials in combination with big operators.\n\nWhile in terms of semantics they could be in the `basic.lean` file, importing \n`algebra.big_operators.basic` leads to a cyclic import.\n\n-/\n\n\nopen Nat BigOperators\n\nnamespace Nat\n\nvariable {\u03b1 : Type _} (s : Finset \u03b1) (f : \u03b1 \u2192 \u2115)\n\n#print Nat.prod_factorial_pos /-\ntheorem prod_factorial_pos : 0 < \u220f i in s, (f i)! :=\n  Finset.prod_pos fun i _ => factorial_pos (f i)\n#align nat.prod_factorial_pos Nat.prod_factorial_pos\n-/\n\n#print Nat.prod_factorial_dvd_factorial_sum /-\ntheorem prod_factorial_dvd_factorial_sum : (\u220f i in s, (f i)!) \u2223 (\u2211 i in s, f i)! := by\n  classical\n    induction' s using Finset.induction with a' s' has ih\n    \u00b7 simp only [Finset.sum_empty, Finset.prod_empty, factorial]\n    \u00b7 simp only [Finset.prod_insert has, Finset.sum_insert has]\n      refine' dvd_trans (mul_dvd_mul_left (f a')! ih) _\n      apply Nat.factorial_mul_factorial_dvd_factorial_add\n#align nat.prod_factorial_dvd_factorial_sum Nat.prod_factorial_dvd_factorial_sum\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Factorial/BigOperators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7227679616332192}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.set_theory.pgame\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Basic definitions about who has a winning stratergy\n\nWe define `G.first_loses`, `G.first_wins`, `G.left_wins` and `G.right_wins` for a pgame `G`, which\nmeans the second, first, left and right players have a winning strategy respectively.\nThese are defined by inequalities which can be unfolded with `pgame.lt_def` and `pgame.le_def`.\n-/\n\nnamespace pgame\n\n\n/-- The player who goes first loses -/\ndef first_loses (G : pgame) := G \u2264 0 \u2227 0 \u2264 G\n\n/-- The player who goes first wins -/\ndef first_wins (G : pgame) := 0 < G \u2227 G < 0\n\n/-- The left player can always win -/\ndef left_wins (G : pgame) := 0 < G \u2227 0 \u2264 G\n\n/-- The right player can always win -/\ndef right_wins (G : pgame) := G \u2264 0 \u2227 G < 0\n\ntheorem zero_first_loses : first_loses 0 := { left := le_refl 0, right := le_refl 0 }\n\ntheorem one_left_wins : left_wins 1 := sorry\n\ntheorem star_first_wins : first_wins star := { left := zero_lt_star, right := star_lt_zero }\n\ntheorem omega_left_wins : left_wins omega := sorry\n\ntheorem winner_cases (G : pgame) : left_wins G \u2228 right_wins G \u2228 first_loses G \u2228 first_wins G :=\n  sorry\n\ntheorem first_loses_is_zero {G : pgame} : first_loses G \u2194 equiv G 0 := iff.refl (first_loses G)\n\ntheorem first_loses_of_equiv {G : pgame} {H : pgame} (h : equiv G H) :\n    first_loses G \u2192 first_loses H :=\n  fun (hGp : first_loses G) =>\n    { left := le_of_equiv_of_le (and.symm h) (and.left hGp),\n      right := le_of_le_of_equiv (and.right hGp) h }\n\ntheorem first_wins_of_equiv {G : pgame} {H : pgame} (h : equiv G H) : first_wins G \u2192 first_wins H :=\n  fun (hGn : first_wins G) =>\n    { left := lt_of_lt_of_equiv (and.left hGn) h,\n      right := lt_of_equiv_of_lt (and.symm h) (and.right hGn) }\n\ntheorem left_wins_of_equiv {G : pgame} {H : pgame} (h : equiv G H) : left_wins G \u2192 left_wins H :=\n  fun (hGl : left_wins G) =>\n    { left := lt_of_lt_of_equiv (and.left hGl) h, right := le_of_le_of_equiv (and.right hGl) h }\n\ntheorem right_wins_of_equiv {G : pgame} {H : pgame} (h : equiv G H) : right_wins G \u2192 right_wins H :=\n  fun (hGr : right_wins G) =>\n    { left := le_of_equiv_of_le (and.symm h) (and.left hGr),\n      right := lt_of_equiv_of_lt (and.symm h) (and.right hGr) }\n\ntheorem first_loses_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) :\n    first_loses G \u2194 first_loses H :=\n  { mp := first_loses_of_equiv h, mpr := first_loses_of_equiv (and.symm h) }\n\ntheorem first_wins_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) :\n    first_wins G \u2194 first_wins H :=\n  { mp := first_wins_of_equiv h, mpr := first_wins_of_equiv (and.symm h) }\n\ntheorem left_wins_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) :\n    left_wins G \u2194 left_wins H :=\n  { mp := left_wins_of_equiv h, mpr := left_wins_of_equiv (and.symm h) }\n\ntheorem right_wins_of_equiv_iff {G : pgame} {H : pgame} (h : equiv G H) :\n    right_wins G \u2194 right_wins H :=\n  { mp := right_wins_of_equiv h, mpr := right_wins_of_equiv (and.symm h) }\n\ntheorem not_first_wins_of_first_loses {G : pgame} : first_loses G \u2192 \u00acfirst_wins G := sorry\n\ntheorem not_first_loses_of_first_wins {G : pgame} : first_wins G \u2192 \u00acfirst_loses G :=\n  iff.mp imp_not_comm not_first_wins_of_first_loses\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/set_theory/game/winner_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7227679561045186}}
{"text": "-- 1\nsection\n  variable A : Type\n  variable f : A \u2192 A\n  variable P : A \u2192 Prop\n  variable  h : \u2200x, P x \u2192 P (f x)\n\n  example : \u2200y, P y \u2192 P (f (f y)) :=\n  assume y,\n    assume Py, have Pfy : P (f y), from h y Py,\n    show P (f (f y)), from h (f y) Pfy\nend\n\n-- 2\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2200x, A x \u2227 B x) \u2192 \u2200x, A x :=\n      assume allXwAandB : (\u2200 x, A x \u2227 B x), assume x,\n    have AAndB : A x \u2227 B x, from allXwAandB x, show A x, from and.elim_left AAndB\nend\n\n-- 3\nsection\n  variable U : Type\n  variables A B C : U \u2192 Prop\n\n  variable h1 : \u2200x, A x \u2228 B x\n  variable h2 : \u2200x, A x \u2192 C x\n  variable h3 : \u2200x, B x \u2192 C x\n\n  example : \u2200x, C x :=\n  assume x,\n  or.elim (h1 x) (assume Ax, h2 x Ax) (assume Bx, h3 x Bx)\nend\n\n-- 4\nopen classical\n\naxiom not_iff_not_self (P : Prop) : \u00ac(P \u2194 \u00acP)\n\nexample (Q : Prop) : \u00ac(Q \u2194 \u00acQ) :=\nnot_iff_not_self Q\n\nsection\n  variable Person : Type\n  variable shaves : Person \u2192 Person \u2192 Prop\n  variable barber : Person\n  variable h : \u2200x, shaves barber x \u2194 \u00acshaves x x\n\n  example : false :=\n  (not_iff_not_self (shaves barber barber)) (h barber)\nend\n\n-- 5\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2203x, A x) \u2192 \u2203x, A x \u2228 B x :=\n  assume existentialAx, exists.elim existentialAx $\n  assume x Ax, have A x \u2228 B x, from or.inl Ax, exists.intro x \u2039A x \u2228 B x\u203a\nend\n\n-- 6\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  variable h1 : \u2200x, A x \u2192 B x\n  variable h2 : \u2203x, A x\n\n  example : \u2203x, B x :=\n   exists.elim h2 $\n  assume x Ax, exists.intro x (h1 x Ax)\nend\n\n-- 7\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example (h1 : \u2203x, A x \u2227 B x) (h2 : \u2200x, B x \u2192 C x) :\n    \u2203x, A x \u2227 C x :=\n    exists.elim h1 $\n    assume x AxBx, have A x, from and.elim_left AxBx, have B x, from and.elim_right AxBx, have C x, from h2 x \u2039B x\u203a,\n    exists.intro x \u27e8\u2039A x\u203a, \u2039C x\u203a\u27e9\nend\n\n-- 8\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example : (\u00ac\u2203x, A x) \u2192 \u2200x, \u00acA x :=\n  assume notexAx : \u00ac \u2203 x, A x,\n    assume x, assume : A x,\n    have exAx : \u2203 x, A x, from exists.intro x \u2039A x\u203a,\n    show false, from notexAx exAx\n\nend\n\n-- 9\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example : (\u2200x, \u00acA x) \u2192 \u00ac\u2203x, A x :=\n  assume axnotAx : \u2200 x, \u00ac A x,\n  assume exAx : \u2203 x, A x, exists.elim exAx $\n  assume x (_ : A x), have \u00ac A x, from axnotAx x, show false, from \u2039\u00ac A x\u203a \u2039A x\u203a\nend\n\n-- 10\nsection\n  variable  U : Type\n  variables R : U \u2192 U \u2192 Prop\n\n  example : (\u2203x, \u2200y, R x y) \u2192 \u2200y, \u2203x, R x y :=\n  assume exAyRxy : \u2203 x, \u2200 y, R x y, exists.elim exAyRxy $\n  assume x (h2 : \u2200 y, R x y), assume y, have R x y, from h2 y,exists.intro x \u2039R x y\u203a\nend\n", "meta": {"author": "Eemkayy", "repo": "discrete205", "sha": "73cd7e1973b054612363ca6cd149b183ad58a9fb", "save_path": "github-repos/lean/Eemkayy-discrete205", "path": "github-repos/lean/Eemkayy-discrete205/discrete205-73cd7e1973b054612363ca6cd149b183ad58a9fb/HW2/hw2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7227679462808295}}
{"text": "-- a^7 = b^7 syss a = b\n-- ====================\n\nimport tactic\nimport algebra.order.ring\n\ntheorem ex_1_3_5\n  {\u03b1}\n  [linear_ordered_ring \u03b1]\n  (a b : \u03b1)\n  (h : a^7 = b^7)\n  : a = b :=\n(@strict_mono_pow_bit1 \u03b1 _ 3).injective h\n\n-- Referencia\n-- ==========\n\n-- Mario Carneiro \"if a^7=b^7 then a=b\" https://bit.ly/3oyBS6M\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/a^7~b^7_syss_a~b.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.946596665680527, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.722711184881713}}
{"text": "import Aesop\nimport Duck.Math.CategoryTheory\nopen Math.CategoryTheory\n\nnamespace Math.GroupTheory\n\nuniverse u v\n\nclass Group (G : Type u) where\n  mul : G \u2192 G \u2192 G\n  unit : G\n  mul_assoc : \u2200 (x y z : G), mul x (mul y z) = mul (mul x y) z\n  mul_unit : \u2200 (x : G), mul x unit = x\n  unit_mul : \u2200 (x : G), mul unit x = x\n  inv : G \u2192 G\n  mul_inv : \u2200 (x : G), mul x (inv x) = unit\n  inv_mul : \u2200 (x : G), mul (inv x) x = unit\n\ninfixr:80 \" \u2b1d \" => Group.mul\n\nstructure GroupHom (G H : Type u) (cG : Group G) (cH : Group H) where\n  f : G \u2192 H\n  hf : \u2200 (x y : G), f (x \u2b1d y) = (f x) \u2b1d (f y)\n\ninstance : Category (Bundle Group) where\n  Hom B\u2081 B\u2082 := GroupHom B\u2081.\u03b1 B\u2082.\u03b1 B\u2081.str B\u2082.str;\n  id B := { f := id, hf := by intros; unfold id; rfl; }\n  comp f g := { f := f.f \u2218 g.f, hf := by intros; unfold Function.comp; rw [g.hf, f.hf]; }\n  comp_assoc f g h := by rfl;\n  comp_id f := by rfl;\n  id_comp f := by rfl;\n\nnamespace Group\n-- A group is trivial if it has one element.\ndef trivial (G : Type u) [Group G] := \u2200 (x : G), x = unit\n-- A group is abelian if $xy = yx$ for all $x, y \\in G$.\ndef abelian (G : Type u) [Group G] := \u2200 (x y : G), x \u2b1d y = y \u2b1d x\naxiom solvable (G : Type u) [Group G] : Prop\naxiom finitely_generated (G : Type u) [Group G] : Prop\n-- A group is a torsion group if every element has finite order.\naxiom torsion (G : Type u) [Group G] : Prop\n-- A group $G$ is simple if its only normal subgroups are $\\{ 1 \\}$ and $G$ itself.\naxiom simple (G : Type u) [Group G] : Prop\n-- A subgroup $H \\subset G$ is normal if $g H g^{-1} = H$ for all $g \\in G$.\n-- axiom normal {G H : Type u} [Group G] [Group H] (i : H \u27f6 G) : Prop\n-- A subgroup $H \\subset G$ is central if it lies in the center of $G$.\n-- axiom central {G H : Group} (i : H \u27f6 G) : Prop\n-- Whenever $N \\subset G$ is a normal subgroup, one can form the quotient group $G/N$.\n-- axiom quotient {G N : Group} {i : N \u27f6 G} (h : normal i) : Group\nend Group\n\nvariable {G : Type u} [Group G]\n\ntheorem mul_right {x y : G} (z : G) (h : x = y) : x \u2b1d z = y \u2b1d z := by rw [h];\ntheorem mul_left {x y : G} (z : G) (h : x = y) : z \u2b1d x = z \u2b1d y := by rw [h];\n\ntheorem inv_inv (x : G) : Group.inv (Group.inv x) = x := by {\n  have q := mul_right x $ Group.inv_mul (Group.inv x);\n  rw [\u2190 Group.mul_assoc, Group.inv_mul, Group.mul_unit, Group.unit_mul] at q;\n  exact q;\n}\n\nend Math.GroupTheory\n", "meta": {"author": "jessetvogel", "repo": "duck", "sha": "4ab46eb4099ef5a827112d5ac217f9e649946796", "save_path": "github-repos/lean/jessetvogel-duck", "path": "github-repos/lean/jessetvogel-duck/duck-4ab46eb4099ef5a827112d5ac217f9e649946796/Duck/Math/GroupTheory/Group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7226654902692463}}
{"text": "variable f : \u2115 \u2192 \u2115\nvariable h : \u2200 x : \u2115, f x \u2264 f (x + 1)\n\nexample : f 0 \u2264 f 3 :=\n  have f 0 \u2264 f 1, from h 0,\n  have f 1 \u2264 f 2, from h 1,\n  have f 2 \u2264 f 3, from h 2,\n  show f 0 \u2264 f 3, from\n    le_trans \u2039f 0 \u2264 f 1\u203a\n      (le_trans \u2039f 1 \u2264 f 2\u203a \u2039f 2 \u2264 f 3\u203a)\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0504.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9572778036723354, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7226633658663804}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n\n! This file was ported from Lean 3 source module set_theory.ordinal.principal\n! leanprover-community/mathlib commit 9b2660e1b25419042c8da10bf411aa3c67f14383\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.SetTheory.Ordinal.FixedPoint\n\n/-!\n### Principal ordinals\n\nWe define principal or indecomposable ordinals, and we prove the standard properties about them.\n\n### Main definitions and results\n* `Principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and\n  any other typically excluded edge cases for simplicity.\n* `unbounded_principal`: Principal ordinals are unbounded.\n* `principal_add_iff_zero_or_omega_opow`: The main characterization theorem for additive principal\n  ordinals.\n* `principal_mul_iff_le_two_or_omega_opow_opow`: The main characterization theorem for\n  multiplicative principal ordinals.\n\n### Todo\n* Prove that exponential principal ordinals are 0, 1, 2, \u03c9, or epsilon numbers, i.e. fixed points\n  of `\u03bb x, \u03c9 ^ x`.\n-/\n\nuniverse u v w\n\nnoncomputable section\n\nopen Order\n\nnamespace Ordinal\n\n-- Porting note: commented out, doesn't seem necessary\n--local infixr:0 \"^\" => @pow Ordinal Ordinal Ordinal.hasPow\n\n/-! ### Principal ordinals -/\n\n\n/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of\nordinals less than it is closed under that operation. In standard mathematical usage, this term is\nalmost exclusively used for additive and multiplicative principal ordinals.\n\nFor simplicity, we break usual convention and regard 0 as principal. -/\ndef Principal (op : Ordinal \u2192 Ordinal \u2192 Ordinal) (o : Ordinal) : Prop :=\n  \u2200 \u2983a b\u2984, a < o \u2192 b < o \u2192 op a b < o\n#align ordinal.principal Ordinal.Principal\n\ntheorem principal_iff_principal_swap {op : Ordinal \u2192 Ordinal \u2192 Ordinal} {o : Ordinal} :\n    Principal op o \u2194 Principal (Function.swap op) o := by\n  constructor <;> exact fun h a b ha hb => h hb ha\n#align ordinal.principal_iff_principal_swap Ordinal.principal_iff_principal_swap\n\ntheorem principal_zero {op : Ordinal \u2192 Ordinal \u2192 Ordinal} : Principal op 0 := fun a _ h =>\n  (Ordinal.not_lt_zero a h).elim\n#align ordinal.principal_zero Ordinal.principal_zero\n\n@[simp]\ntheorem principal_one_iff {op : Ordinal \u2192 Ordinal \u2192 Ordinal} : Principal op 1 \u2194 op 0 0 = 0 := by\n  refine' \u27e8fun h => _, fun h a b ha hb => _\u27e9\n  \u00b7 rw [\u2190 lt_one_iff_zero]\n    exact h zero_lt_one zero_lt_one\n  \u00b7 rwa [lt_one_iff_zero, ha, hb] at *\n#align ordinal.principal_one_iff Ordinal.principal_one_iff\n\ntheorem Principal.iterate_lt {op : Ordinal \u2192 Ordinal \u2192 Ordinal} {a o : Ordinal} (hao : a < o)\n    (ho : Principal op o) (n : \u2115) : (op a^[n]) a < o := by\n  induction' n with n hn\n  \u00b7 rwa [Function.iterate_zero]\n  \u00b7 rw [Function.iterate_succ']\n    exact ho hao hn\n#align ordinal.principal.iterate_lt Ordinal.Principal.iterate_lt\n\ntheorem op_eq_self_of_principal {op : Ordinal \u2192 Ordinal \u2192 Ordinal} {a o : Ordinal.{u}} (hao : a < o)\n    (H : IsNormal (op a)) (ho : Principal op o) (ho' : IsLimit o) : op a o = o := by\n  refine' le_antisymm _ (H.self_le _)\n  rw [\u2190 IsNormal.bsup_eq.{u, u} H ho', bsup_le_iff]\n  exact fun b hbo => (ho hao hbo).le\n#align ordinal.op_eq_self_of_principal Ordinal.op_eq_self_of_principal\n\ntheorem nfp_le_of_principal {op : Ordinal \u2192 Ordinal \u2192 Ordinal} {a o : Ordinal} (hao : a < o)\n    (ho : Principal op o) : nfp (op a) a \u2264 o :=\n  nfp_le fun n => (ho.iterate_lt hao n).le\n#align ordinal.nfp_le_of_principal Ordinal.nfp_le_of_principal\n\n/-! ### Principal ordinals are unbounded -/\n\n\n/-- The least strict upper bound of `op` applied to all pairs of ordinals less than `o`. This is\nessentially a two-argument version of `Ordinal.blsub`. -/\ndef blsub\u2082 (op : Ordinal \u2192 Ordinal \u2192 Ordinal) (o : Ordinal) : Ordinal :=\n  lsub fun x : o.out.\u03b1 \u00d7 o.out.\u03b1 => op (typein LT.lt x.1) (typein LT.lt x.2)\n#align ordinal.blsub\u2082 Ordinal.blsub\u2082\n\ntheorem lt_blsub\u2082 (op : Ordinal.{u} \u2192 Ordinal.{u} \u2192 Ordinal.{max u v})\n  {o a b : Ordinal.{u}} (ha : a < o)\n    (hb : b < o) : op a b < blsub\u2082.{u, v} op o := by\n  convert lt_lsub.{v, u}\n      (fun x : (Quotient.out.{u+2} o).\u03b1 \u00d7 (Quotient.out.{u+2} o).\u03b1 =>\n        op (typein.{u} LT.lt x.fst) (typein.{u} LT.lt x.snd))\n      (Prod.mk.{u, u} (enum.{u} LT.lt a (by rwa [type_lt])) (enum.{u} LT.lt b (by rwa [type_lt])))\n  <;> simp only [typein_enum]\n#align ordinal.lt_blsub\u2082 Ordinal.lt_blsub\u2082\n\ntheorem principal_nfp_blsub\u2082 (op : Ordinal \u2192 Ordinal \u2192 Ordinal) (o : Ordinal) :\n    Principal op (nfp (blsub\u2082.{u, u} op) o) := fun a b ha hb => by\n  rw [lt_nfp] at *\n  cases' ha with m hm\n  cases' hb with n hn\n  cases' le_total ((blsub\u2082.{u, u} op^[m]) o) ((blsub\u2082.{u, u} op^[n]) o) with h h\n  \u00b7 use n + 1\n    rw [Function.iterate_succ']\n    exact lt_blsub\u2082 op (hm.trans_le h) hn\n  \u00b7 use m + 1\n    rw [Function.iterate_succ']\n    exact lt_blsub\u2082 op hm (hn.trans_le h)\n#align ordinal.principal_nfp_blsub\u2082 Ordinal.principal_nfp_blsub\u2082\n\ntheorem unbounded_principal (op : Ordinal \u2192 Ordinal \u2192 Ordinal) :\n    Set.Unbounded (\u00b7 < \u00b7) { o | Principal op o } := fun o =>\n  \u27e8_, principal_nfp_blsub\u2082 op o, (le_nfp _ o).not_lt\u27e9\n#align ordinal.unbounded_principal Ordinal.unbounded_principal\n\n/-! #### Additive principal ordinals -/\n\n\ntheorem principal_add_one : Principal (\u00b7 + \u00b7) 1 :=\n  principal_one_iff.2 <| zero_add 0\n#align ordinal.principal_add_one Ordinal.principal_add_one\n\ntheorem principal_add_of_le_one {o : Ordinal} (ho : o \u2264 1) : Principal (\u00b7 + \u00b7) o := by\n  rcases le_one_iff.1 ho with (rfl | rfl)\n  \u00b7 exact principal_zero\n  \u00b7 exact principal_add_one\n#align ordinal.principal_add_of_le_one Ordinal.principal_add_of_le_one\n\ntheorem principal_add_isLimit {o : Ordinal} (ho\u2081 : 1 < o) (ho : Principal (\u00b7 + \u00b7) o) : o.IsLimit :=\n  by\n  refine' \u27e8fun ho\u2080 => _, fun a hao => _\u27e9\n  \u00b7 rw [ho\u2080] at ho\u2081\n    exact not_lt_of_gt zero_lt_one ho\u2081\n  \u00b7 cases' eq_or_ne a 0 with ha ha\n    \u00b7 rw [ha, succ_zero]\n      exact ho\u2081\n    \u00b7 refine' lt_of_le_of_lt _ (ho hao hao)\n      rwa [\u2190 add_one_eq_succ, add_le_add_iff_left, one_le_iff_ne_zero]\n#align ordinal.principal_add_is_limit Ordinal.principal_add_isLimit\n\ntheorem principal_add_iff_add_left_eq_self {o : Ordinal} :\n    Principal (\u00b7 + \u00b7) o \u2194 \u2200 a < o, a + o = o := by\n  refine' \u27e8fun ho a hao => _, fun h a b hao hbo => _\u27e9\n  \u00b7 cases' lt_or_le 1 o with ho\u2081 ho\u2081\n    \u00b7 exact op_eq_self_of_principal hao (add_isNormal a) ho (principal_add_isLimit ho\u2081 ho)\n    \u00b7 rcases le_one_iff.1 ho\u2081 with (rfl | rfl)\n      \u00b7 exact (Ordinal.not_lt_zero a hao).elim\n      \u00b7 rw [lt_one_iff_zero] at hao\n        rw [hao, zero_add]\n  \u00b7 rw [\u2190 h a hao]\n    exact (add_isNormal a).strictMono hbo\n#align ordinal.principal_add_iff_add_left_eq_self Ordinal.principal_add_iff_add_left_eq_self\n\ntheorem exists_lt_add_of_not_principal_add {a} (ha : \u00acPrincipal (\u00b7 + \u00b7) a) :\n    \u2203 (b c : _) (_ : b < a)(_ : c < a), b + c = a := by\n  unfold Principal at ha\n  push_neg  at ha\n  rcases ha with \u27e8b, c, hb, hc, H\u27e9\n  refine'\n    \u27e8b, _, hb, lt_of_le_of_ne (sub_le_self a b) fun hab => _, Ordinal.add_sub_cancel_of_le hb.le\u27e9\n  rw [\u2190 sub_le, hab] at H\n  exact H.not_lt hc\n#align ordinal.exists_lt_add_of_not_principal_add Ordinal.exists_lt_add_of_not_principal_add\n\ntheorem principal_add_iff_add_lt_ne_self {a} :\n    Principal (\u00b7 + \u00b7) a \u2194 \u2200 \u2983b c\u2984, b < a \u2192 c < a \u2192 b + c \u2260 a :=\n  \u27e8fun ha b c hb hc => (ha hb hc).ne, fun H =>\n    by\n    by_contra' ha\n    rcases exists_lt_add_of_not_principal_add ha with \u27e8b, c, hb, hc, rfl\u27e9\n    exact (H hb hc).irrefl\u27e9\n#align ordinal.principal_add_iff_add_lt_ne_self Ordinal.principal_add_iff_add_lt_ne_self\n\ntheorem add_omega {a : Ordinal} (h : a < omega) : a + omega = omega := by\n  rcases lt_omega.1 h with \u27e8n, rfl\u27e9\n  clear h; induction' n with n IH\n  \u00b7 rw [Nat.cast_zero, zero_add]\n  \u00b7 rwa [Nat.cast_succ, add_assoc, one_add_of_omega_le (le_refl _)]\n#align ordinal.add_omega Ordinal.add_omega\n\ntheorem principal_add_omega : Principal (\u00b7 + \u00b7) omega :=\n  principal_add_iff_add_left_eq_self.2 fun _ => add_omega\n#align ordinal.principal_add_omega Ordinal.principal_add_omega\n\ntheorem add_omega_opow {a b : Ordinal} (h : a < (omega^b)) : a + (omega^b) = (omega^b) := by\n  refine' le_antisymm _ (le_add_left _ _)\n  induction' b using limitRecOn with b _ b l IH\n  \u00b7 rw [opow_zero, \u2190 succ_zero, lt_succ_iff, Ordinal.le_zero] at h\n    rw [h, zero_add]\n  \u00b7 rw [opow_succ] at h\n    rcases(lt_mul_of_limit omega_isLimit).1 h with \u27e8x, xo, ax\u27e9\n    refine' le_trans (add_le_add_right (le_of_lt ax) _) _\n    rw [opow_succ, \u2190 mul_add, add_omega xo]\n  \u00b7 rcases(lt_opow_of_limit omega_ne_zero l).1 h with \u27e8x, xb, ax\u27e9\n    exact\n      (((add_isNormal a).trans (opow_isNormal one_lt_omega)).limit_le l).2 fun y yb =>\n        (add_le_add_left (opow_le_opow_right omega_pos (le_max_right _ _)) _).trans\n          (le_trans\n            (IH _ (max_lt xb yb) (ax.trans_le <| opow_le_opow_right omega_pos (le_max_left _ _)))\n            (opow_le_opow_right omega_pos <| le_of_lt <| max_lt xb yb))\n#align ordinal.add_omega_opow Ordinal.add_omega_opow\n\ntheorem principal_add_omega_opow (o : Ordinal) : Principal (\u00b7 + \u00b7) (omega^o) :=\n  principal_add_iff_add_left_eq_self.2 fun _ => add_omega_opow\n#align ordinal.principal_add_omega_opow Ordinal.principal_add_omega_opow\n\n/-- The main characterization theorem for additive principal ordinals. -/\ntheorem principal_add_iff_zero_or_omega_opow {o : Ordinal} :\n    Principal (\u00b7 + \u00b7) o \u2194 o = 0 \u2228 \u2203 a, o = (omega^a) := by\n  rcases eq_or_ne o 0 with (rfl | ho)\n  \u00b7 simp only [principal_zero, Or.inl]\n  \u00b7 rw [principal_add_iff_add_left_eq_self]\n    simp only [ho, false_or_iff]\n    refine'\n      \u27e8fun H => \u27e8_, ((lt_or_eq_of_le (opow_log_le_self _ ho)).resolve_left fun h => _).symm\u27e9,\n        fun \u27e8b, e\u27e9 => e.symm \u25b8 fun a => add_omega_opow\u27e9\n    have := H _ h\n    have := lt_opow_succ_log_self one_lt_omega o\n    rw [opow_succ, lt_mul_of_limit omega_isLimit] at this\n    rcases this with \u27e8a, ao, h'\u27e9\n    rcases lt_omega.1 ao with \u27e8n, rfl\u27e9\n    clear ao\n    revert h'\n    apply not_lt_of_le\n    suffices e : (omega^log omega o) * \u2191n + o = o\n    \u00b7 simpa only [e] using le_add_right ((omega^log omega o) * \u2191n) o\n    induction' n with n IH\n    \u00b7 simp [Nat.cast_zero, mul_zero, zero_add]\n    simp only [Nat.cast_succ, mul_add_one, add_assoc, this, IH]\n#align ordinal.principal_add_iff_zero_or_omega_opow Ordinal.principal_add_iff_zero_or_omega_opow\n\ntheorem opow_principal_add_of_principal_add {a} (ha : Principal (\u00b7 + \u00b7) a) (b : Ordinal) :\n    Principal (\u00b7 + \u00b7) (a^b) := by\n  rcases principal_add_iff_zero_or_omega_opow.1 ha with (rfl | \u27e8c, rfl\u27e9)\n  \u00b7 rcases eq_or_ne b 0 with (rfl | hb)\n    \u00b7 rw [opow_zero]\n      exact principal_add_one\n    \u00b7 rwa [zero_opow hb]\n  \u00b7 rw [\u2190 opow_mul]\n    exact principal_add_omega_opow _\n#align ordinal.opow_principal_add_of_principal_add Ordinal.opow_principal_add_of_principal_add\n\ntheorem add_absorp {a b c : Ordinal} (h\u2081 : a < (omega^b)) (h\u2082 : (omega^b) \u2264 c) : a + c = c := by\n  rw [\u2190 Ordinal.add_sub_cancel_of_le h\u2082, \u2190 add_assoc, add_omega_opow h\u2081]\n#align ordinal.add_absorp Ordinal.add_absorp\n\ntheorem mul_principal_add_is_principal_add (a : Ordinal.{u}) {b : Ordinal.{u}} (hb\u2081 : b \u2260 1)\n    (hb : Principal (\u00b7 + \u00b7) b) : Principal (\u00b7 + \u00b7) (a * b) := by\n  rcases eq_zero_or_pos a with (rfl | _)\n  \u00b7 rw [zero_mul]\n    exact principal_zero\n  \u00b7 rcases eq_zero_or_pos b with (rfl | hb\u2081')\n    \u00b7 rw [mul_zero]\n      exact principal_zero\n    \u00b7 rw [\u2190 succ_le_iff, succ_zero] at hb\u2081'\n      intro c d hc hd\n      rw [lt_mul_of_limit (principal_add_isLimit (lt_of_le_of_ne hb\u2081' hb\u2081.symm) hb)] at *\n      \u00b7 rcases hc with \u27e8x, hx, hx'\u27e9\n        rcases hd with \u27e8y, hy, hy'\u27e9\n        use x + y, hb hx hy\n        rw [mul_add]\n        exact Left.add_lt_add hx' hy'\n#align ordinal.mul_principal_add_is_principal_add Ordinal.mul_principal_add_is_principal_add\n\n/-! #### Multiplicative principal ordinals -/\n\n\ntheorem principal_mul_one : Principal (\u00b7 * \u00b7) 1 := by\n  rw [principal_one_iff]\n  exact zero_mul _\n#align ordinal.principal_mul_one Ordinal.principal_mul_one\n\ntheorem principal_mul_two : Principal (\u00b7 * \u00b7) 2 := fun a b ha hb => by\n  have h\u2082 : succ (1 : Ordinal) = 2 := by simp\n  dsimp only\n  rw [\u2190 h\u2082, lt_succ_iff] at ha hb \u22a2\n  convert mul_le_mul' ha hb\n  exact (mul_one 1).symm\n#align ordinal.principal_mul_two Ordinal.principal_mul_two\n\ntheorem principal_mul_of_le_two {o : Ordinal} (ho : o \u2264 2) : Principal (\u00b7 * \u00b7) o := by\n  rcases lt_or_eq_of_le ho with (ho | rfl)\n  \u00b7 have h\u2082 : succ (1 : Ordinal) = 2 := by simp\n    rw [\u2190 h\u2082, lt_succ_iff] at ho\n    rcases lt_or_eq_of_le ho with (ho | rfl)\n    \u00b7 rw [lt_one_iff_zero.1 ho]\n      exact principal_zero\n    \u00b7 exact principal_mul_one\n  \u00b7 exact principal_mul_two\n#align ordinal.principal_mul_of_le_two Ordinal.principal_mul_of_le_two\n\ntheorem principal_add_of_principal_mul {o : Ordinal} (ho : Principal (\u00b7 * \u00b7) o) (ho\u2082 : o \u2260 2) :\n    Principal (\u00b7 + \u00b7) o := by\n  cases' lt_or_gt_of_ne ho\u2082 with ho\u2081 ho\u2082\n  \u00b7 replace ho\u2081 : o < succ 1 := by simpa using ho\u2081\n    rw [lt_succ_iff] at ho\u2081\n    exact principal_add_of_le_one ho\u2081\n  \u00b7 refine' fun a b hao hbo => lt_of_le_of_lt _ (ho (max_lt hao hbo) ho\u2082)\n    dsimp only\n    rw [\u2190 one_add_one_eq_two, mul_add, mul_one]\n    exact add_le_add (le_max_left a b) (le_max_right a b)\n#align ordinal.principal_add_of_principal_mul Ordinal.principal_add_of_principal_mul\n\ntheorem principal_mul_isLimit {o : Ordinal.{u}} (ho\u2082 : 2 < o) (ho : Principal (\u00b7 * \u00b7) o) :\n    o.IsLimit :=\n  principal_add_isLimit ((lt_succ 1).trans (by simpa using ho\u2082))\n    (principal_add_of_principal_mul ho (ne_of_gt ho\u2082))\n#align ordinal.principal_mul_is_limit Ordinal.principal_mul_isLimit\n\ntheorem principal_mul_iff_mul_left_eq {o : Ordinal} :\n    Principal (\u00b7 * \u00b7) o \u2194 \u2200 a, 0 < a \u2192 a < o \u2192 a * o = o := by\n  refine' \u27e8fun h a ha\u2080 hao => _, fun h a b hao hbo => _\u27e9\n  \u00b7 cases' le_or_gt o 2 with ho ho\n    \u00b7 convert one_mul o\n      apply le_antisymm\n      \u00b7 have : a < succ 1 := hao.trans_le (by simpa using ho)\n        rwa [lt_succ_iff] at this\n      \u00b7 rwa [\u2190 succ_le_iff, succ_zero] at ha\u2080\n    \u00b7 exact op_eq_self_of_principal hao (mul_isNormal ha\u2080) h (principal_mul_isLimit ho h)\n  \u00b7 rcases eq_or_ne a 0 with (rfl | ha)\n    \u00b7 dsimp only; rwa [zero_mul]\n    rw [\u2190 Ordinal.pos_iff_ne_zero] at ha\n    rw [\u2190 h a ha hao]\n    exact (mul_isNormal ha).strictMono hbo\n#align ordinal.principal_mul_iff_mul_left_eq Ordinal.principal_mul_iff_mul_left_eq\n\ntheorem principal_mul_omega : Principal (\u00b7 * \u00b7) omega := fun a b ha hb =>\n  match a, b, lt_omega.1 ha, lt_omega.1 hb with\n  | _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 => by\n    dsimp only; rw [\u2190 nat_cast_mul]\n    apply nat_lt_omega\n#align ordinal.principal_mul_omega Ordinal.principal_mul_omega\n\ntheorem mul_omega {a : Ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega :=\n  principal_mul_iff_mul_left_eq.1 principal_mul_omega a a0 ha\n#align ordinal.mul_omega Ordinal.mul_omega\n\ntheorem mul_lt_omega_opow {a b c : Ordinal} (c0 : 0 < c) (ha : a < (omega^c)) (hb : b < omega) :\n    a * b < (omega^c) := by\n  rcases zero_or_succ_or_limit c with (rfl | \u27e8c, rfl\u27e9 | l)\n  \u00b7 exact (lt_irrefl _).elim c0\n  \u00b7 rw [opow_succ] at ha\n    rcases((mul_isNormal <| opow_pos _ omega_pos).limit_lt omega_isLimit).1 ha with \u27e8n, hn, an\u27e9\n    apply (mul_le_mul_right' (le_of_lt an) _).trans_lt\n    rw [opow_succ, mul_assoc, mul_lt_mul_iff_left (opow_pos _ omega_pos)]\n    exact principal_mul_omega hn hb\n  \u00b7 rcases((opow_isNormal one_lt_omega).limit_lt l).1 ha with \u27e8x, hx, ax\u27e9\n    refine' (mul_le_mul' (le_of_lt ax) (le_of_lt hb)).trans_lt _\n    rw [\u2190 opow_succ, opow_lt_opow_iff_right one_lt_omega]\n    exact l.2 _ hx\n#align ordinal.mul_lt_omega_opow Ordinal.mul_lt_omega_opow\n\ntheorem mul_omega_opow_opow {a b : Ordinal} (a0 : 0 < a) (h : a < (omega^omega^b)) :\n    a * (omega^omega^b) = (omega^omega^b) := by\n  by_cases b0 : b = 0;\n  \u00b7 rw [b0, opow_zero, opow_one] at h\u22a2\n    exact mul_omega a0 h\n  refine'\n    le_antisymm _\n      (by simpa only [one_mul] using mul_le_mul_right' (one_le_iff_pos.2 a0) (omega^omega^b))\n  rcases(lt_opow_of_limit omega_ne_zero (opow_isLimit_left omega_isLimit b0)).1 h with \u27e8x, xb, ax\u27e9\n  apply (mul_le_mul_right' (le_of_lt ax) _).trans\n  rw [\u2190 opow_add, add_omega_opow xb]\n#align ordinal.mul_omega_opow_opow Ordinal.mul_omega_opow_opow\n\ntheorem principal_mul_omega_opow_opow (o : Ordinal) : Principal (\u00b7 * \u00b7) (omega^omega^o) :=\n  principal_mul_iff_mul_left_eq.2 fun _ => mul_omega_opow_opow\n#align ordinal.principal_mul_omega_opow_opow Ordinal.principal_mul_omega_opow_opow\n\n\n\n/-- The main characterization theorem for multiplicative principal ordinals. -/\ntheorem principal_mul_iff_le_two_or_omega_opow_opow {o : Ordinal} :\n    Principal (\u00b7 * \u00b7) o \u2194 o \u2264 2 \u2228 \u2203 a, o = (omega^omega^a) := by\n  refine' \u27e8fun ho => _, _\u27e9\n  \u00b7 cases' le_or_lt o 2 with ho\u2082 ho\u2082\n    \u00b7 exact Or.inl ho\u2082\n    rcases principal_add_iff_zero_or_omega_opow.1 (principal_add_of_principal_mul ho ho\u2082.ne') with\n      (rfl | \u27e8a, rfl\u27e9)\n    \u00b7 exact (Ordinal.not_lt_zero 2 ho\u2082).elim\n    rcases principal_add_iff_zero_or_omega_opow.1\n        (principal_add_of_principal_mul_opow one_lt_omega ho) with\n      (rfl | \u27e8b, rfl\u27e9)\n    \u00b7 left\n      simpa using one_le_two\n    exact Or.inr \u27e8b, rfl\u27e9\n  \u00b7 rintro (ho\u2082 | \u27e8a, rfl\u27e9)\n    \u00b7 exact principal_mul_of_le_two ho\u2082\n    \u00b7 exact principal_mul_omega_opow_opow a\n#align ordinal.principal_mul_iff_le_two_or_omega_opow_opow Ordinal.principal_mul_iff_le_two_or_omega_opow_opow\n\ntheorem mul_omega_dvd {a : Ordinal} (a0 : 0 < a) (ha : a < omega) : \u2200 {b}, omega \u2223 b \u2192 a * b = b\n  | _, \u27e8b, rfl\u27e9 => by rw [\u2190 mul_assoc, mul_omega a0 ha]\n#align ordinal.mul_omega_dvd Ordinal.mul_omega_dvd\n\ntheorem mul_eq_opow_log_succ {a b : Ordinal.{u}} (ha : a \u2260 0) (hb : Principal (\u00b7 * \u00b7) b)\n    (hb\u2082 : 2 < b) : a * b = (b^succ (log b a)) := by\n  apply le_antisymm\n  \u00b7 have hbl := principal_mul_isLimit hb\u2082 hb\n    have := IsNormal.bsup_eq.{u, u} (mul_isNormal (Ordinal.pos_iff_ne_zero.2 ha)) hbl\n    dsimp at this\n    rw [\u2190 this, bsup_le_iff]\n    intro c hcb\n    have hb\u2081 : 1 < b := (lt_succ 1).trans (by simpa using hb\u2082)\n    have hbo\u2080 : (b^b.log a) \u2260 0 := Ordinal.pos_iff_ne_zero.1 (opow_pos _ (zero_lt_one.trans hb\u2081))\n    apply le_trans (mul_le_mul_right' (le_of_lt (lt_mul_succ_div a hbo\u2080)) c)\n    rw [mul_assoc, opow_succ]\n    refine' mul_le_mul_left' (le_of_lt (hb (hbl.2 _ _) hcb)) _\n    rw [div_lt hbo\u2080, \u2190 opow_succ]\n    exact lt_opow_succ_log_self hb\u2081 _\n  \u00b7 rw [opow_succ]\n    exact mul_le_mul_right' (opow_log_le_self b ha) b\n#align ordinal.mul_eq_opow_log_succ Ordinal.mul_eq_opow_log_succ\n\n/-! #### Exponential principal ordinals -/\n\n\ntheorem principal_opow_omega : Principal (\u00b7^\u00b7) omega := fun a b ha hb =>\n  match a, b, lt_omega.1 ha, lt_omega.1 hb with\n  | _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 => by\n    simp_rw [\u2190 nat_cast_opow]\n    apply nat_lt_omega\n#align ordinal.principal_opow_omega Ordinal.principal_opow_omega\n\ntheorem opow_omega {a : Ordinal} (a1 : 1 < a) (h : a < omega) : (a^omega) = omega :=\n  le_antisymm\n    ((opow_le_of_limit (one_le_iff_ne_zero.1 <| le_of_lt a1) omega_isLimit).2 fun _ hb =>\n      (principal_opow_omega h hb).le)\n    (right_le_opow _ a1)\n#align ordinal.opow_omega Ordinal.opow_omega\n\nend Ordinal\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/SetTheory/Ordinal/Principal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.722662044239787}}
{"text": "-- Imagen_de_la_imagen_inversa.lean\n-- Imagen de la imagen inversa\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 10 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    f '' (f\u207b\u00b9' u) \u2286 u\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariable  u : set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  intros y h,\n  cases h with x h2,\n  cases h2 with hx fxy,\n  rw \u2190 fxy,\n  exact hx,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  intros y h,\n  rcases h with \u27e8x, hx, fxy\u27e9,\n  rw \u2190 fxy,\n  exact hx,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  rintros y \u27e8x, hx, fxy\u27e9,\n  rw \u2190 fxy,\n  exact hx,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  rintros y \u27e8x, hx, rfl\u27e9,\n  exact hx,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nimage_preimage_subset f u\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Imagen_de_la_imagen_inversa.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7226099592394817}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro\n-/\n\nimport algebra.order.ring.defs\nimport algebra.ring.divisibility\nimport algebra.order.group.abs\n\n/-!\n# Absolute values in linear ordered rings.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {\u03b1 : Type*}\n\nsection linear_ordered_ring\nvariables [linear_ordered_ring \u03b1] {a b c : \u03b1}\n\n@[simp] lemma abs_one : |(1 : \u03b1)| = 1 := abs_of_pos zero_lt_one\n@[simp] lemma abs_two : |(2 : \u03b1)| = 2 := abs_of_pos zero_lt_two\n\nlemma abs_mul (a b : \u03b1) : |a * b| = |a| * |b| :=\nbegin\n  rw [abs_eq (mul_nonneg (abs_nonneg a) (abs_nonneg b))],\n  cases le_total a 0 with ha ha; cases le_total b 0 with hb hb;\n    simp only [abs_of_nonpos, abs_of_nonneg, true_or, or_true, eq_self_iff_true,\n      neg_mul, mul_neg, neg_neg, *]\nend\n\n/-- `abs` as a `monoid_with_zero_hom`. -/\ndef abs_hom : \u03b1 \u2192*\u2080 \u03b1 := \u27e8abs, abs_zero, abs_one, abs_mul\u27e9\n\n@[simp] lemma abs_mul_abs_self (a : \u03b1) : |a| * |a| = a * a :=\nabs_by_cases (\u03bb x, x * x = a * a) rfl (neg_mul_neg a a)\n\n@[simp] lemma abs_mul_self (a : \u03b1) : |a * a| = a * a :=\nby rw [abs_mul, abs_mul_abs_self]\n\n@[simp] lemma abs_eq_self : |a| = a \u2194 0 \u2264 a := by simp [abs_eq_max_neg]\n\n@[simp] lemma abs_eq_neg_self : |a| = -a \u2194 a \u2264 0 := by simp [abs_eq_max_neg]\n\n/-- For an element `a` of a linear ordered ring, either `abs a = a` and `0 \u2264 a`,\n    or `abs a = -a` and `a < 0`.\n    Use cases on this lemma to automate linarith in inequalities -/\nlemma abs_cases (a : \u03b1) : (|a| = a \u2227 0 \u2264 a) \u2228 (|a| = -a \u2227 a < 0) :=\nbegin\n  by_cases 0 \u2264 a,\n  { left,\n    exact \u27e8abs_eq_self.mpr h, h\u27e9 },\n  { right,\n    push_neg at h,\n    exact \u27e8abs_eq_neg_self.mpr (le_of_lt h), h\u27e9 }\nend\n\n@[simp] lemma max_zero_add_max_neg_zero_eq_abs_self (a : \u03b1) :\n  max a 0 + max (-a) 0 = |a| :=\nbegin\n  symmetry,\n  rcases le_total 0 a with ha|ha;\n  simp [ha],\nend\n\nlemma abs_eq_iff_mul_self_eq : |a| = |b| \u2194 a * a = b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm,\nend\n\nlemma abs_lt_iff_mul_self_lt : |a| < |b| \u2194 a * a < b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)\nend\n\nlemma abs_le_iff_mul_self_le : |a| \u2264 |b| \u2194 a * a \u2264 b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)\nend\n\nlemma abs_le_one_iff_mul_self_le_one : |a| \u2264 1 \u2194 a * a \u2264 1 :=\nby simpa only [abs_one, one_mul] using @abs_le_iff_mul_self_le \u03b1 _ a 1\n\nend linear_ordered_ring\n\nsection linear_ordered_comm_ring\n\nvariables [linear_ordered_comm_ring \u03b1] {a b c d : \u03b1}\n\nlemma abs_sub_sq (a b : \u03b1) : |a - b| * |a - b| = a * a + b * b - (1 + 1) * a * b :=\nbegin\n  rw abs_mul_abs_self,\n  simp only [mul_add, add_comm, add_left_comm, mul_comm, sub_eq_add_neg,\n    mul_one, mul_neg, neg_add_rev, neg_neg],\nend\n\nend linear_ordered_comm_ring\n\nsection\nvariables [ring \u03b1] [linear_order \u03b1] {a b : \u03b1}\n\n@[simp] lemma abs_dvd (a b : \u03b1) : |a| \u2223 b \u2194 a \u2223 b :=\nby { cases abs_choice a with h h; simp only [h, neg_dvd] }\n\nlemma abs_dvd_self (a : \u03b1) : |a| \u2223 a :=\n(abs_dvd a a).mpr (dvd_refl a)\n\n@[simp] lemma dvd_abs (a b : \u03b1) : a \u2223 |b| \u2194 a \u2223 b :=\nby { cases abs_choice b with h h; simp only [h, dvd_neg] }\n\nlemma self_dvd_abs (a : \u03b1) : a \u2223 |a| :=\n(dvd_abs a a).mpr (dvd_refl a)\n\nlemma abs_dvd_abs (a b : \u03b1) : |a| \u2223 |b| \u2194 a \u2223 b :=\n(abs_dvd _ _).trans (dvd_abs _ _)\n\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/ring/abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7226099582194452}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\n\nimport data.list.rotate\nimport group_theory.perm.support\n\n/-!\n# Permutations from a list\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA list `l : list \u03b1` can be interpreted as a `equiv.perm \u03b1` where each element in the list\nis permuted to the next one, defined as `form_perm`. When we have that `nodup l`,\nwe prove that `equiv.perm.support (form_perm l) = l.to_finset`, and that\n`form_perm l` is rotationally invariant, in `form_perm_rotate`.\n\nWhen there are duplicate elements in `l`, how and in what arrangement with respect to the other\nelements they appear in the list determines the formed permutation.\nThis is because `list.form_perm` is implemented as a product of `equiv.swap`s.\nThat means that presence of a sublist of two adjacent duplicates like `[..., x, x, ...]`\nwill produce the same permutation as if the adjacent duplicates were not present.\n\nThe `list.form_perm` definition is meant to primarily be used with `nodup l`, so that\nthe resulting permutation is cyclic (if `l` has at least two elements).\nThe presence of duplicates in a particular placement can lead `list.form_perm` to produce a\nnontrivial permutation that is noncyclic.\n-/\n\nnamespace list\n\nvariables {\u03b1 \u03b2 : Type*}\n\nsection form_perm\n\nvariables [decidable_eq \u03b1] (l : list \u03b1)\n\nopen equiv equiv.perm\n\n/--\nA list `l : list \u03b1` can be interpreted as a `equiv.perm \u03b1` where each element in the list\nis permuted to the next one, defined as `form_perm`. When we have that `nodup l`,\nwe prove that `equiv.perm.support (form_perm l) = l.to_finset`, and that\n`form_perm l` is rotationally invariant, in `form_perm_rotate`.\n-/\ndef form_perm : equiv.perm \u03b1 :=\n(zip_with equiv.swap l l.tail).prod\n\n@[simp] lemma form_perm_nil : form_perm ([] : list \u03b1) = 1 := rfl\n\n@[simp] lemma form_perm_singleton (x : \u03b1) : form_perm [x] = 1 := rfl\n\n@[simp] lemma form_perm_cons_cons (x y : \u03b1) (l : list \u03b1) :\n  form_perm (x :: y :: l) = swap x y * form_perm (y :: l) :=\nprod_cons\n\nlemma form_perm_pair (x y : \u03b1) : form_perm [x, y] = swap x y := rfl\n\nvariables {l} {x : \u03b1}\n\nlemma form_perm_apply_of_not_mem (x : \u03b1) (l : list \u03b1) (h : x \u2209 l) :\n  form_perm l x = x :=\nbegin\n  cases l with y l,\n  { simp },\n  induction l with z l IH generalizing x y,\n  { simp },\n  { specialize IH x z (mt (mem_cons_of_mem y) h),\n    simp only [not_or_distrib, mem_cons_iff] at h,\n    simp [IH, swap_apply_of_ne_of_ne, h] }\nend\n\nlemma mem_of_form_perm_apply_ne (x : \u03b1) (l : list \u03b1) : l.form_perm x \u2260 x \u2192 x \u2208 l :=\nnot_imp_comm.2 $ list.form_perm_apply_of_not_mem _ _\n\nlemma form_perm_apply_mem_of_mem (x : \u03b1) (l : list \u03b1) (h : x \u2208 l) :\n  form_perm l x \u2208 l :=\nbegin\n  cases l with y l,\n  { simpa },\n  induction l with z l IH generalizing x y,\n  { simpa using h },\n  { by_cases hx : x \u2208 z :: l,\n    { rw [form_perm_cons_cons, mul_apply, swap_apply_def],\n      split_ifs;\n      simp [IH _ _ hx] },\n    { replace h : x = y := or.resolve_right h hx,\n      simp [form_perm_apply_of_not_mem _ _ hx, \u2190h] } }\nend\n\nlemma mem_of_form_perm_apply_mem (x : \u03b1) (l : list \u03b1) (h : l.form_perm x \u2208 l) : x \u2208 l :=\nbegin\n  cases l with y l,\n  { simpa },\n  induction l with z l IH generalizing x y,\n  { simpa using h },\n  { by_cases hx : (z :: l).form_perm x \u2208 z :: l,\n    { rw [list.form_perm_cons_cons, mul_apply, swap_apply_def] at h,\n      split_ifs at h;\n      simp [IH _ _ hx] },\n    { replace hx := (function.injective.eq_iff (equiv.injective _)).mp\n        (list.form_perm_apply_of_not_mem _ _ hx),\n      simp only [list.form_perm_cons_cons, hx, equiv.perm.coe_mul, function.comp_app,\n        list.mem_cons_iff, swap_apply_def, ite_eq_left_iff] at h,\n      simp only [list.mem_cons_iff],\n      obtain h | h | h := h;\n      { split_ifs at h;\n        cc }}}\nend\n\nlemma form_perm_mem_iff_mem : l.form_perm x \u2208 l \u2194 x \u2208 l :=\n\u27e8l.mem_of_form_perm_apply_mem x, l.form_perm_apply_mem_of_mem x\u27e9\n\n@[simp] lemma form_perm_cons_concat_apply_last (x y : \u03b1) (xs : list \u03b1) :\n  form_perm (x :: (xs ++ [y])) y = x :=\nbegin\n  induction xs with z xs IH generalizing x y,\n  { simp },\n  { simp [IH] }\nend\n\n@[simp] lemma form_perm_apply_last (x : \u03b1) (xs : list \u03b1) :\n  form_perm (x :: xs) ((x :: xs).last (cons_ne_nil x xs)) = x :=\nbegin\n  induction xs using list.reverse_rec_on with xs y IH generalizing x;\n  simp\nend\n\n@[simp] lemma form_perm_apply_nth_le_length (x : \u03b1) (xs : list \u03b1) :\n  form_perm (x :: xs) ((x :: xs).nth_le xs.length (by simp)) = x :=\nby rw [nth_le_cons_length, form_perm_apply_last]; refl\n\nlemma form_perm_apply_head (x y : \u03b1) (xs : list \u03b1) (h : nodup (x :: y :: xs)) :\n  form_perm (x :: y :: xs) x = y :=\nby simp [form_perm_apply_of_not_mem _ _ h.not_mem]\n\nlemma form_perm_apply_nth_le_zero (l : list \u03b1) (h : nodup l) (hl : 1 < l.length) :\n  form_perm l (l.nth_le 0 (zero_lt_one.trans hl)) = l.nth_le 1 hl :=\nbegin\n  rcases l with (_|\u27e8x, _|\u27e8y, tl\u27e9\u27e9),\n  { simp },\n  { simp },\n  { simpa using form_perm_apply_head _ _ _ h }\nend\n\nvariables (l)\n\nlemma form_perm_eq_head_iff_eq_last (x y : \u03b1) :\n  form_perm (y :: l) x = y \u2194 x = last (y :: l) (cons_ne_nil _ _) :=\niff.trans (by rw form_perm_apply_last) (form_perm (y :: l)).injective.eq_iff\n\nlemma zip_with_swap_prod_support' (l l' : list \u03b1) :\n  {x | (zip_with swap l l').prod x \u2260 x} \u2264 l.to_finset \u2294 l'.to_finset :=\nbegin\n  simp only [set.sup_eq_union, set.le_eq_subset],\n  induction l with y l hl generalizing l',\n  { simp },\n  { cases l' with z l',\n    { simp },\n    { intro x,\n      simp only [set.union_subset_iff, mem_cons_iff, zip_with_cons_cons, foldr, prod_cons,\n                 mul_apply],\n      intro hx,\n      by_cases h : x \u2208 {x | (zip_with swap l l').prod x \u2260 x},\n      { specialize hl l' h,\n        refine set.mem_union.elim hl (\u03bb hm, _) (\u03bb hm, _);\n        { simp only [finset.coe_insert, set.mem_insert_iff, finset.mem_coe, to_finset_cons,\n                     mem_to_finset] at hm \u22a2,\n          simp [hm] } },\n      { simp only [not_not, set.mem_set_of_eq] at h,\n        simp only [h, set.mem_set_of_eq] at hx,\n        rw swap_apply_ne_self_iff at hx,\n        rcases hx with \u27e8hyz, rfl|rfl\u27e9;\n        simp } } }\nend\n\nlemma zip_with_swap_prod_support [fintype \u03b1] (l l' : list \u03b1) :\n  (zip_with swap l l').prod.support \u2264 l.to_finset \u2294 l'.to_finset :=\nbegin\n  intros x hx,\n  have hx' : x \u2208 {x | (zip_with swap l l').prod x \u2260 x} := by simpa using hx,\n  simpa using zip_with_swap_prod_support' _ _ hx'\nend\n\nlemma support_form_perm_le' : {x | form_perm l x \u2260 x} \u2264 l.to_finset :=\nbegin\n  refine (zip_with_swap_prod_support' l l.tail).trans _,\n  simpa [finset.subset_iff] using tail_subset l\nend\n\nlemma support_form_perm_le [fintype \u03b1] : support (form_perm l) \u2264 l.to_finset :=\nbegin\n  intros x hx,\n  have hx' : x \u2208 {x | form_perm l x \u2260 x} := by simpa using hx,\n  simpa using support_form_perm_le' _ hx'\nend\n\nlemma form_perm_apply_lt (xs : list \u03b1) (h : nodup xs) (n : \u2115) (hn : n + 1 < xs.length) :\n  form_perm xs (xs.nth_le n ((nat.lt_succ_self n).trans hn)) = xs.nth_le (n + 1) hn :=\nbegin\n  induction n with n IH generalizing xs,\n  { simpa using form_perm_apply_nth_le_zero _ h _ },\n  { rcases xs with (_|\u27e8x, _|\u27e8y, l\u27e9\u27e9),\n    { simp },\n    { simp },\n    { specialize IH (y :: l) h.of_cons _,\n      { simpa [nat.succ_lt_succ_iff] using hn },\n      simp only [swap_apply_eq_iff, coe_mul, form_perm_cons_cons, nth_le],\n      generalize_proofs at IH,\n      rw [IH, swap_apply_of_ne_of_ne, nth_le];\n      { rintro rfl,\n        simpa [nth_le_mem _ _ _] using h } } }\nend\n\nlemma form_perm_apply_nth_le (xs : list \u03b1) (h : nodup xs) (n : \u2115) (hn : n < xs.length) :\n  form_perm xs (xs.nth_le n hn) = xs.nth_le ((n + 1) % xs.length)\n    (nat.mod_lt _ (n.zero_le.trans_lt hn)) :=\nbegin\n  cases xs with x xs,\n  { simp },\n  { have : n \u2264 xs.length,\n    { refine nat.le_of_lt_succ _,\n      simpa using hn },\n    rcases this.eq_or_lt with rfl|hn',\n    { simp },\n    { simp [form_perm_apply_lt, h, nat.mod_eq_of_lt, nat.succ_lt_succ hn'] } }\nend\n\nlemma support_form_perm_of_nodup' (l : list \u03b1) (h : nodup l) (h' : \u2200 (x : \u03b1), l \u2260 [x]) :\n  {x | form_perm l x \u2260 x} = l.to_finset :=\nbegin\n  apply le_antisymm,\n  { exact support_form_perm_le' l },\n  { intros x hx,\n    simp only [finset.mem_coe, mem_to_finset] at hx,\n    obtain \u27e8n, hn, rfl\u27e9 := nth_le_of_mem hx,\n    rw [set.mem_set_of_eq, form_perm_apply_nth_le _ h],\n    intro H,\n    rw nodup_iff_nth_le_inj at h,\n    specialize h _ _ _ _ H,\n    cases (nat.succ_le_of_lt hn).eq_or_lt with hn' hn',\n    { simp only [\u2190hn', nat.mod_self] at h,\n      refine not_exists.mpr h' _,\n      simpa [\u2190h, eq_comm, length_eq_one] using hn' },\n    { simpa [nat.mod_eq_of_lt hn'] using h } }\nend\n\nlemma support_form_perm_of_nodup [fintype \u03b1] (l : list \u03b1) (h : nodup l) (h' : \u2200 (x : \u03b1), l \u2260 [x]) :\n  support (form_perm l) = l.to_finset :=\nbegin\n  rw \u2190finset.coe_inj,\n  convert support_form_perm_of_nodup' _ h h',\n  simp [set.ext_iff]\nend\n\nlemma form_perm_rotate_one (l : list \u03b1) (h : nodup l) :\n  form_perm (l.rotate 1) = form_perm l :=\nbegin\n  have h' : nodup (l.rotate 1),\n  { simpa using h },\n  ext x,\n  by_cases hx : x \u2208 l.rotate 1,\n  { obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx,\n    rw [form_perm_apply_nth_le _ h', nth_le_rotate l, nth_le_rotate l,\n      form_perm_apply_nth_le _ h],\n    simp },\n  { rw [form_perm_apply_of_not_mem _ _ hx, form_perm_apply_of_not_mem],\n    simpa using hx }\nend\n\nlemma form_perm_rotate (l : list \u03b1) (h : nodup l) (n : \u2115) :\n  form_perm (l.rotate n) = form_perm l :=\nbegin\n  induction n with n hn,\n  { simp },\n  { rw [nat.succ_eq_add_one, \u2190rotate_rotate, form_perm_rotate_one, hn],\n    rwa is_rotated.nodup_iff,\n    exact is_rotated.forall l n }\nend\n\nlemma form_perm_eq_of_is_rotated {l l' : list \u03b1} (hd : nodup l) (h : l ~r l') :\n  form_perm l = form_perm l' :=\nbegin\n  obtain \u27e8n, rfl\u27e9 := h,\n  exact (form_perm_rotate l hd n).symm\nend\n\nlemma form_perm_reverse (l : list \u03b1) (h : nodup l) :\n  form_perm l.reverse = (form_perm l)\u207b\u00b9 :=\nbegin\n  -- Let's show `form_perm l` is an inverse to `form_perm l.reverse`.\n  rw [eq_comm, inv_eq_iff_mul_eq_one],\n  ext x,\n  -- We only have to check for `x \u2208 l` that `form_perm l (form_perm l.reverse x)`\n  rw [mul_apply, one_apply],\n  by_cases hx : x \u2208 l,\n  swap,\n  { rw [form_perm_apply_of_not_mem x l.reverse, form_perm_apply_of_not_mem _ _ hx],\n    simpa using hx },\n  { obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem (mem_reverse.mpr hx),\n    rw [form_perm_apply_nth_le l.reverse (nodup_reverse.mpr h),\n        nth_le_reverse', form_perm_apply_nth_le _ h, nth_le_reverse'],\n    { congr,\n      rw [length_reverse, \u2190nat.succ_le_iff, nat.succ_eq_add_one] at hk,\n      cases hk.eq_or_lt with hk' hk',\n      { simp [\u2190hk'] },\n      { rw [length_reverse, nat.mod_eq_of_lt hk', tsub_add_eq_add_tsub (nat.le_pred_of_lt hk'),\n            nat.mod_eq_of_lt],\n        { simp },\n        { rw tsub_add_cancel_of_le,\n          refine tsub_lt_self _ (nat.zero_lt_succ _),\n          all_goals { simpa using (nat.zero_le _).trans_lt hk' } } } },\n    all_goals { rw [\u2190 tsub_add_eq_tsub_tsub, \u2190length_reverse],\n      refine tsub_lt_self _ (zero_lt_one.trans_le (le_add_right le_rfl)),\n      exact k.zero_le.trans_lt hk } },\nend\n\nlemma form_perm_pow_apply_nth_le (l : list \u03b1) (h : nodup l) (n k : \u2115) (hk : k < l.length) :\n  (form_perm l ^ n) (l.nth_le k hk) = l.nth_le ((k + n) % l.length)\n    (nat.mod_lt _ (k.zero_le.trans_lt hk)) :=\nbegin\n  induction n with n hn,\n  { simp [nat.mod_eq_of_lt hk] },\n  { simp [pow_succ, mul_apply, hn, form_perm_apply_nth_le _ h, nat.succ_eq_add_one,\n          \u2190nat.add_assoc] }\nend\n\n\n\nlemma form_perm_ext_iff {x y x' y' : \u03b1} {l l' : list \u03b1}\n  (hd : nodup (x :: y :: l)) (hd' : nodup (x' :: y' :: l')) :\n  form_perm (x :: y :: l) = form_perm (x' :: y' :: l') \u2194 (x :: y :: l) ~r (x' :: y' :: l') :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb hr, form_perm_eq_of_is_rotated hd hr\u27e9,\n  rw equiv.perm.ext_iff at h,\n  have hx : x' \u2208 (x :: y :: l),\n  { have : x' \u2208 {z | form_perm (x :: y :: l) z \u2260 z},\n    { rw [set.mem_set_of_eq, h x', form_perm_apply_head _ _ _ hd'],\n      simp only [mem_cons_iff, nodup_cons] at hd',\n      push_neg at hd',\n      exact hd'.left.left.symm },\n    simpa using support_form_perm_le' _ this },\n  obtain \u27e8n, hn, hx'\u27e9 := nth_le_of_mem hx,\n  have hl : (x :: y :: l).length = (x' :: y' :: l').length,\n  { rw [\u2190dedup_eq_self.mpr hd, \u2190dedup_eq_self.mpr hd',\n        \u2190card_to_finset, \u2190card_to_finset],\n    refine congr_arg finset.card _,\n    rw [\u2190finset.coe_inj, \u2190support_form_perm_of_nodup' _ hd (by simp),\n        \u2190support_form_perm_of_nodup' _ hd' (by simp)],\n    simp only [h] },\n  use n,\n  apply list.ext_le,\n  { rw [length_rotate, hl] },\n  { intros k hk hk',\n    rw nth_le_rotate,\n    induction k with k IH,\n    { simp_rw [nat.zero_add, nat.mod_eq_of_lt hn],\n      simpa },\n    { have : k.succ = (k + 1) % (x' :: y' :: l').length,\n      { rw [\u2190nat.succ_eq_add_one, nat.mod_eq_of_lt hk'] },\n      simp_rw this,\n      rw [\u2190form_perm_apply_nth_le _ hd' k (k.lt_succ_self.trans hk'),\n          \u2190IH (k.lt_succ_self.trans hk), \u2190h, form_perm_apply_nth_le _ hd],\n      congr' 1,\n      have h1 : 1 = 1 % (x' :: y' :: l').length := by simp,\n      rw [hl, nat.mod_eq_of_lt hk', h1, \u2190nat.add_mod, nat.succ_add] } }\nend\n\nlemma form_perm_apply_mem_eq_self_iff (hl : nodup l) (x : \u03b1) (hx : x \u2208 l) :\n  form_perm l x = x \u2194 length l \u2264 1 :=\nbegin\n  obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx,\n  rw [form_perm_apply_nth_le _ hl, hl.nth_le_inj_iff],\n  cases hn : l.length,\n  { exact absurd k.zero_le (hk.trans_le hn.le).not_le },\n  { rw hn at hk,\n    cases (nat.le_of_lt_succ hk).eq_or_lt with hk' hk',\n    { simp [\u2190hk', nat.succ_le_succ_iff, eq_comm] },\n    { simpa [nat.mod_eq_of_lt (nat.succ_lt_succ hk'), nat.succ_lt_succ_iff]\n        using k.zero_le.trans_lt hk' } }\nend\n\nlemma form_perm_apply_mem_ne_self_iff (hl : nodup l) (x : \u03b1) (hx : x \u2208 l) :\n  form_perm l x \u2260 x \u2194 2 \u2264 l.length :=\nbegin\n  rw [ne.def, form_perm_apply_mem_eq_self_iff _ hl x hx, not_le],\n  exact \u27e8nat.succ_le_of_lt, nat.lt_of_succ_le\u27e9\nend\n\nlemma mem_of_form_perm_ne_self (l : list \u03b1) (x : \u03b1) (h : form_perm l x \u2260 x) :\n  x \u2208 l :=\nbegin\n  suffices : x \u2208 {y | form_perm l y \u2260 y},\n  { rw \u2190mem_to_finset,\n    exact support_form_perm_le' _ this },\n  simpa using h\nend\n\nlemma form_perm_eq_self_of_not_mem (l : list \u03b1) (x : \u03b1) (h : x \u2209 l) :\n  form_perm l x = x :=\nby_contra (\u03bb H, h $ mem_of_form_perm_ne_self _ _ H)\n\nlemma form_perm_eq_one_iff (hl : nodup l) :\n  form_perm l = 1 \u2194 l.length \u2264 1 :=\nbegin\n  cases l with hd tl,\n  { simp },\n  { rw \u2190form_perm_apply_mem_eq_self_iff _ hl hd (mem_cons_self _ _),\n    split,\n    { simp {contextual := tt} },\n    { intro h,\n      simp only [(hd :: tl).form_perm_apply_mem_eq_self_iff hl hd (mem_cons_self hd tl),\n                 add_le_iff_nonpos_left, length, nonpos_iff_eq_zero, length_eq_zero] at h,\n      simp [h] } }\nend\n\nlemma form_perm_eq_form_perm_iff {l l' : list \u03b1} (hl : l.nodup) (hl' : l'.nodup) :\n  l.form_perm = l'.form_perm \u2194 l ~r l' \u2228 l.length \u2264 1 \u2227 l'.length \u2264 1 :=\nbegin\n  rcases l with (_ | \u27e8x, _ | \u27e8y, l\u27e9\u27e9),\n  { suffices : l'.length \u2264 1 \u2194 l' = nil \u2228 l'.length \u2264 1,\n    { simpa [eq_comm, form_perm_eq_one_iff, hl, hl', length_eq_zero] },\n    refine \u27e8\u03bb h, or.inr h, _\u27e9,\n    rintro (rfl | h),\n    { simp },\n    { exact h } },\n  { suffices : l'.length \u2264 1 \u2194 [x] ~r l' \u2228 l'.length \u2264 1,\n    { simpa [eq_comm, form_perm_eq_one_iff, hl, hl', length_eq_zero, le_rfl] },\n    refine \u27e8\u03bb h, or.inr h, _\u27e9,\n    rintro (h | h),\n    { simp [\u2190h.perm.length_eq] },\n    { exact h } },\n  { rcases l' with (_ | \u27e8x', _ | \u27e8y', l'\u27e9\u27e9),\n    { simp [form_perm_eq_one_iff, hl, -form_perm_cons_cons] },\n    { suffices : \u00ac (x :: y :: l) ~r [x'],\n      { simp [form_perm_eq_one_iff, hl, -form_perm_cons_cons] },\n      intro h,\n      simpa using h.perm.length_eq },\n    { simp [-form_perm_cons_cons, form_perm_ext_iff hl hl'] } }\nend\n\nlemma form_perm_zpow_apply_mem_imp_mem (l : list \u03b1) (x : \u03b1) (hx : x \u2208 l) (n : \u2124) :\n  ((form_perm l) ^ n) x \u2208 l :=\nbegin\n  by_cases h : (l.form_perm ^ n) x = x,\n  { simpa [h] using hx },\n  { have : x \u2208 {x | (l.form_perm ^ n) x \u2260 x} := h,\n    rw \u2190set_support_apply_mem at this,\n    replace this := set_support_zpow_subset _ _ this,\n    simpa using support_form_perm_le' _ this }\nend\n\nlemma form_perm_pow_length_eq_one_of_nodup (hl : nodup l) :\n  (form_perm l) ^ (length l) = 1 :=\nbegin\n  ext x,\n  by_cases hx : x \u2208 l,\n  { obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx,\n    simp [form_perm_pow_apply_nth_le _ hl, nat.mod_eq_of_lt hk] },\n  { have : x \u2209 {x | (l.form_perm ^ l.length) x \u2260 x},\n    { intros H,\n      refine hx _,\n      replace H := set_support_zpow_subset l.form_perm l.length H,\n      simpa using support_form_perm_le' _ H },\n    simpa }\nend\n\nend form_perm\n\nend list\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/perm/list.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7226099536417211}}
{"text": "/-\nCopyright (c) 2022 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport data.polynomial.unit_trinomial\nimport ring_theory.polynomial.gauss_lemma\nimport tactic.linear_combination\n\n/-!\n# Irreducibility of Selmer Polynomials\n\nThis file proves irreducibility of the Selmer polynomials `X ^ n - X - 1`.\n\n## Main results\n\n- `polynomial.selmer_irreducible`: The Selmer polynomials `X ^ n - X - 1` are irreducible.\n\nTODO: Show that the Selmer polynomials have full Galois group.\n-/\n\nnamespace polynomial\nopen_locale polynomial\n\nvariables {n : \u2115}\n\nlemma X_pow_sub_X_sub_one_irreducible_aux (z : \u2102) : \u00ac (z ^ n = z + 1 \u2227 z ^ n + z ^ 2 = 0) :=\nbegin\n  rintros \u27e8h1, h2\u27e9,\n  replace h3 : z ^ 3 = 1,\n  { linear_combination (1 - z - z ^ 2 - z ^ n) * h1 + (z ^ n - 2) * h2 }, -- thanks polyrith!\n  have key : z ^ n = 1 \u2228 z ^ n = z \u2228 z ^ n = z ^ 2,\n  { rw [\u2190nat.mod_add_div n 3, pow_add, pow_mul, h3, one_pow, mul_one],\n    have : n % 3 < 3 := nat.mod_lt n zero_lt_three,\n    interval_cases n % 3; simp only [h, pow_zero, pow_one, eq_self_iff_true, or_true, true_or] },\n  have z_ne_zero : z \u2260 0 :=\n  \u03bb h, zero_ne_one ((zero_pow zero_lt_three).symm.trans (show (0 : \u2102) ^ 3 = 1, from h \u25b8 h3)),\n  rcases key with key | key | key,\n  { exact z_ne_zero (by rwa [key, self_eq_add_left] at h1) },\n  { exact one_ne_zero (by rwa [key, self_eq_add_right] at h1) },\n  { exact z_ne_zero (pow_eq_zero (by rwa [key, add_self_eq_zero] at h2)) },\nend\n\nlemma X_pow_sub_X_sub_one_irreducible (hn1 : n \u2260 1) : irreducible (X ^ n - X - 1 : \u2124[X]) :=\nbegin\n  by_cases hn0 : n = 0,\n  { rw [hn0, pow_zero, sub_sub, add_comm, \u2190sub_sub, sub_self, zero_sub],\n    exact associated.irreducible \u27e8-1, mul_neg_one X\u27e9 irreducible_X },\n  have hn : 1 < n := nat.one_lt_iff_ne_zero_and_ne_one.mpr \u27e8hn0, hn1\u27e9,\n  have hp : (X ^ n - X - 1 : \u2124[X]) = trinomial 0 1 n (-1) (-1) 1 :=\n    by simp only [trinomial, C_neg, C_1]; ring,\n  rw hp,\n  apply is_unit_trinomial.irreducible_of_coprime' \u27e80, 1, n, zero_lt_one, hn, -1, -1, 1, rfl\u27e9,\n  rintros z \u27e8h1, h2\u27e9,\n  apply X_pow_sub_X_sub_one_irreducible_aux z,\n  rw [trinomial_mirror zero_lt_one hn (-1 : \u2124\u02e3).ne_zero (1 : \u2124\u02e3).ne_zero] at h2,\n  simp_rw [trinomial, aeval_add, aeval_mul, aeval_X_pow, aeval_C] at h1 h2,\n  simp_rw [units.coe_neg, units.coe_one, map_neg, map_one] at h1 h2,\n  replace h1 : z ^ n = z + 1 := by linear_combination h1,\n  replace h2 := mul_eq_zero_of_left h2 z,\n  rw [add_mul, add_mul, add_zero, mul_assoc (-1 : \u2102), \u2190pow_succ', nat.sub_add_cancel hn.le] at h2,\n  rw h1 at h2 \u22a2,\n  exact \u27e8rfl, by linear_combination -h2\u27e9,\nend\n\nlemma X_pow_sub_X_sub_one_irreducible_rat (hn1 : n \u2260 1) : irreducible (X ^ n - X - 1 : \u211a[X]) :=\nbegin\n  by_cases hn0 : n = 0,\n  { rw [hn0, pow_zero, sub_sub, add_comm, \u2190sub_sub, sub_self, zero_sub],\n    exact associated.irreducible \u27e8-1, mul_neg_one X\u27e9 irreducible_X },\n  have hp : (X ^ n - X - 1 : \u2124[X]) = trinomial 0 1 n (-1) (-1) 1 :=\n  by simp only [trinomial, C_neg, C_1]; ring,\n  have hn : 1 < n := nat.one_lt_iff_ne_zero_and_ne_one.mpr \u27e8hn0, hn1\u27e9,\n  have h := (is_primitive.int.irreducible_iff_irreducible_map_cast _).mp\n    (X_pow_sub_X_sub_one_irreducible hn1),\n  { rwa [polynomial.map_sub, polynomial.map_sub, polynomial.map_pow, polynomial.map_one,\n      polynomial.map_X] at h },\n  { exact hp.symm \u25b8 (trinomial_monic zero_lt_one hn).is_primitive },\nend\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/polynomial/selmer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846387, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7226099527958374}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\n-/\n\nimport data.fintype.basic \nimport combinatorics.fibonacci\n\ndef nat.succ_emb : \u2115 \u21aa \u2115 :=\n  \u27e8nat.succ, \u03bb i j e, nat.succ.inj e\u27e9\n\ndef fin.succ_emb (n : \u2115) : (fin n) \u21aa (fin n.succ) := \n  \u27e8fin.succ, \u03bb i j e, fin.succ_inj.mp e\u27e9 \n\ndef fin.val_emb (n : \u2115) : (fin n) \u21aa \u2115 := \n  \u27e8coe, \u03bb i j e, fin.eq_of_veq e\u27e9\n\nnamespace combinatorics\n\ndef shift {n : \u2115} (s : finset (fin n)) : finset (fin n.succ) := \n s.map (fin.succ_emb n)\n\n/- Given a set s \u2286 {0,..,n}, we can shift it to the left \n   to get a set (unshift s) = {i : i + 1 \u2208 s} \u2286 {0,..,n-1}\n-/\ndef unshift {n : \u2115} (s : finset (fin n.succ)) : finset (fin n) := \n finset.univ.filter (\u03bb a, a.succ \u2208 s)\n\nlemma mem_shift {n : \u2115} (s : finset (fin n)) (a : fin n.succ) :\n a \u2208 shift s \u2194 \u2203 b : fin n, b \u2208 s \u2227 b.succ = a := \nbegin\n rw[shift],split,\n {intro a_in_shift,\n  rcases finset.mem_map.mp a_in_shift with \u27e8b,\u27e8b_in_s,e\u27e9\u27e9,\n  use b,\n  exact \u27e8b_in_s,e\u27e9, \n },{\n  rintro \u27e8b,\u27e8b_in_s,e\u27e9\u27e9,\n  exact finset.mem_map.mpr \u27e8b,\u27e8b_in_s,e\u27e9\u27e9, \n }\nend\n\nlemma zero_not_mem_shift {n : \u2115} (s : finset (fin n)) : \n (0 : (fin n.succ)) \u2209 shift s := \nbegin\n intro h0,\n rcases ((mem_shift s) 0).mp h0 with \u27e8\u27e8b,hb\u27e9,\u27e8b_in_s,e\u27e9\u27e9,\n cases e\nend\n\nlemma succ_mem_shift_iff {n : \u2115} (s : finset (fin n)) (a : fin n) : \n a.succ \u2208 shift s \u2194 a \u2208 s := \nbegin\n rw[mem_shift s a.succ],\n split,{\n   rintro \u27e8b,\u27e8b_in_s,u\u27e9\u27e9,\n   rw[(fin.succ_inj.mp u).symm],\n   exact b_in_s,\n },{\n   intro a_in_s,use a,exact \u27e8a_in_s,rfl\u27e9,\n }\nend\n\nlemma mem_unshift {n : \u2115} (s : finset (fin n.succ)) (a : fin n) :\n a \u2208 unshift s \u2194 a.succ \u2208 s := \nbegin\n rw[unshift,finset.mem_filter],\n split,\n {intro h,exact h.right},\n {intro h,exact \u27e8finset.mem_univ a,h\u27e9 }\nend\n\nlemma unshift_shift {n : \u2115} (s : finset (fin n)) : \n unshift (shift s) = s := \nbegin\n ext,rw[mem_unshift (shift s) a],rw[succ_mem_shift_iff],\nend\n\nlemma unshift_insert {n : \u2115} (s : finset (fin n.succ)) : \n unshift (insert (0 : (fin n.succ)) s) = unshift s := \nbegin\n ext \u27e8i,hi\u27e9,rw[mem_unshift,mem_unshift,finset.mem_insert],\n split,\n {intro h,rcases h with h0 | h1,\n  {cases h0},\n  {exact h1} },\n {exact \u03bb h,or.inr h}\nend\n\nlemma shift_unshift0 {n : \u2115} (s : finset (fin n.succ)) \n  (h : (0 : (fin n.succ)) \u2209 s) : shift (unshift s) = s := \nbegin\n ext \u27e8_ | a,a_is_lt\u27e9, \n { have e : (0 : fin n.succ) = \u27e80,a_is_lt\u27e9 := fin.eq_of_veq rfl,\n   rw[\u2190 e],simp only[zero_not_mem_shift,h] },\n { let b : fin n := \u27e8a,nat.lt_of_succ_lt_succ a_is_lt\u27e9,\n   have e : b.succ = \u27e8a.succ,a_is_lt\u27e9 := \n    by { apply fin.eq_of_veq, refl, },\n   rw[\u2190 e,succ_mem_shift_iff (unshift s) b,mem_unshift s b] }\nend\n\nlemma shift_unshift1 {n : \u2115} (s : finset (fin n.succ))\n (h : (0 : fin n.succ) \u2208 s) : insert (0 : fin n.succ) (shift (unshift s)) = s :=\nbegin\n  ext \u27e8_ | a,a_is_lt\u27e9;\n  rw[finset.mem_insert],\n  { have e : (0 : fin n.succ) = \u27e80,a_is_lt\u27e9 := fin.eq_of_veq rfl,\n    rw [\u2190 e], simp only[h,eq_self_iff_true,true_or] },\n  { let b : fin n := \u27e8a,nat.lt_of_succ_lt_succ a_is_lt\u27e9,\n    have e : b.succ = \u27e8a.succ,a_is_lt\u27e9 := \n      by { apply fin.eq_of_veq,refl, },\n    rw [\u2190 e, succ_mem_shift_iff (unshift s) b, mem_unshift s b],\n    split,\n    { rintro (u0 | u1),\n      { cases fin.veq_of_eq u0 },\n      { exact u1 } } ,\n    { intro h, right, exact h } }\nend\n\nlemma shift_card {n : \u2115} (s : finset (fin n)) : (shift s).card = s.card := \n by { apply finset.card_map, }\n\nlemma finset_fin_zero_empty (s : finset (fin 0)) : s = \u2205 :=\n  finset.eq_empty_of_forall_not_mem (\u03bb i, fin.elim0 i)\n\nlemma finset_fin_zero_card (s : finset (fin 0)) : s.card = 0 :=\n  by { rw [finset_fin_zero_empty s, finset.card_empty] }\n\nlemma unshift_card0 {n : \u2115} {s : finset (fin n.succ)} \n  (h : (0 : fin n.succ) \u2209 s) : s.card = (unshift s).card := \nbegin\n  let t := unshift s,\n  change s.card = t.card, \n  have : s = (shift t) := (shift_unshift0 s h).symm,\n  rw [this, shift_card]\nend\n\nlemma unshift_card1 {n : \u2115} {s : finset (fin n.succ)} \n  (h : (0 : fin n.succ) \u2208 s) : s.card = (unshift s).card.succ := \nbegin\n  let t := unshift s,\n  change s.card = t.card.succ, \n  have : s = insert 0 (shift t) := (shift_unshift1 s h).symm,\n  rw [this],\n  rw [finset.card_insert_of_not_mem (zero_not_mem_shift t), shift_card]\nend\n\nlemma unshift_card {n : \u2115} (s : finset (fin n.succ)) : \n  s.card = \n   (if (0 : fin n.succ) \u2208 s then (unshift s).card.succ else (unshift s).card) :=\nbegin\n  split_ifs, apply unshift_card1 h, apply unshift_card0 h\nend\n\ndef emb_nat_finset {n : \u2115} : (finset (fin n)) \u21aa finset \u2115  :=\n  \u27e8\u03bb s, s.map \u27e8coe, \u03bb i j e, fin.eq_of_veq e\u27e9,\n   \u03bb s t e, finset.map_inj.mp e\u27e9 \n\nlemma emb_nat_finset_shift {n : \u2115} (s : finset (fin n)) :\n  emb_nat_finset.to_fun (shift s) = \n   (emb_nat_finset.to_fun s).map nat.succ_emb :=\nbegin\n  ext i, rw[emb_nat_finset, finset.mem_map, finset.mem_map],\n  split,\n  { rintro \u27e8\u27e8j,j_is_lt\u27e9,\u27e8hm,he\u27e9\u27e9, change j = i at he, \n    rcases (mem_shift s \u27e8j,_\u27e9).mp hm with \u27e8\u27e8k,k_is_lt\u27e9,\u27e8hk,hsk\u27e9\u27e9,\n    use k,\n    have : k \u2208 emb_nat_finset.to_fun s := \n      by { rw [emb_nat_finset, finset.mem_map], use \u27e8k,k_is_lt\u27e9, use hk, refl },\n    use this,\n    exact (fin.veq_of_eq hsk).trans he},\n  { rintro \u27e8j,\u27e8hj,he\u27e9\u27e9, change j.succ = i at he,\n    rcases finset.mem_map.mp hj with \u27e8\u27e8k,k_is_lt\u27e9,\u27e8hk,hv\u27e9\u27e9,\n    change k = j at hv,\n    use fin.succ \u27e8k,k_is_lt\u27e9,\n    use (succ_mem_shift_iff s \u27e8k,k_is_lt\u27e9).mpr hk,\n    change k.succ = i,\n    rw [hv, he] }\nend\n\nlemma emb_nat_finset_unshift {n : \u2115} (s : finset (fin n.succ)) :\n  emb_nat_finset.to_fun (unshift s) = \n   (finset.range n).filter (\u03bb i, i.succ \u2208 emb_nat_finset.to_fun s) :=\nbegin\n  ext i,\n  rw [finset.mem_filter, finset.mem_range,\n      emb_nat_finset, emb_nat_finset, \n      finset.mem_map, finset.mem_map],\n  split,\n  { rintro \u27e8\u27e8j,j_is_lt\u27e9,\u27e8hm,he\u27e9\u27e9, change j = i at he, rw[mem_unshift] at hm,\n    split,\n    { rw[\u2190 he], exact j_is_lt },\n    { use fin.succ \u27e8j,j_is_lt\u27e9, use hm, change j.succ = i.succ, rw[he]} },\n  { rintro \u27e8hi,\u27e8\u27e8j,j_is_lt\u27e9,\u27e8hm,he\u27e9\u27e9\u27e9, change j = i.succ at he,\n    let i0 : fin n := \u27e8i,hi\u27e9,\n    have hj : (\u27e8j,j_is_lt\u27e9 : (fin n.succ)) = i0.succ := fin.eq_of_veq he,\n    rw [hj] at hm,\n    use i0, use (mem_unshift s i0).mpr hm, refl }\nend\n\nend combinatorics", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/combinatorics/shift.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.722609950929917}}
{"text": "\ntheorem smaller_than2 {a b x y: \u2115}\n (h1: a \u2264 x)\n (h2: b \u2264 y) :\n (a + b \u2264 x + y) := begin\n  exact add_le_add h1 h2\n end\n\ntheorem smaller_than3 {a b c x y z: \u2115}\n (h1: a \u2264 x)\n (h2: b \u2264 y)\n (h3: c \u2264 z) :\n  a + (b + c) \u2264 x + (y + z) := begin\n  generalize hbc : b + c = bc,\n  generalize hyz : y + z = yz,\n  refine add_le_add h1 _,\n  rw [\u2190hbc, \u2190hyz],\n  refine add_le_add h2 h3,\n end", "meta": {"author": "alcides", "repo": "untyped3", "sha": "e488f48617c052b4c35c6d7167b4ddcf79dd75ab", "save_path": "github-repos/lean/alcides-untyped3", "path": "github-repos/lean/alcides-untyped3/untyped3-e488f48617c052b4c35c6d7167b4ddcf79dd75ab/src/utils.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7225103409959126}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\nTheory of complete separated uniform spaces.\n\nThis file is for elementary lemmas that depend on both Cauchy filters and separation.\n-/\nimport topology.uniform_space.cauchy topology.uniform_space.separation\n\nopen filter\nvariables {\u03b1 : Type*} [uniform_space \u03b1]\n\n/-In a separated space, a complete set is closed -/\nlemma is_closed_of_is_complete [separated \u03b1] {s : set \u03b1} (h : is_complete s) : is_closed s :=\nis_closed_iff_nhds.2 $ \u03bb a ha, begin\n  let f := nhds a \u2293 principal s,\n  have : cauchy f := cauchy_downwards (cauchy_nhds) ha (lattice.inf_le_left),\n  rcases h f this (lattice.inf_le_right) with \u27e8y, ys, fy\u27e9,\n  rwa (tendsto_nhds_unique ha lattice.inf_le_left fy : a = y)\nend\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/topology/uniform_space/complete_separated.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7224538998921758}}
{"text": "\nvariables p q : Prop\n\n#check p \u2192 q \u2192 p \u2227 q\n#check \u00acp -> p \u2194 false\n#check p \u2228 q \u2192 q \u2228 p\n\nnamespace conjunction\n\n    example (hp : p) (hq : q) : p \u2227 q := and.intro hp hq\n    #check assume (hp : p) (hq : q), and.intro hp hq\n\n    example (h : p \u2227 q) : p := and.elim_left h\n    example (h : p \u2227 q) : q := and.elim_right h\n\n    -- Equivilant\n    example (h : p \u2227 q) : q \u2227 p := and.intro (and.right h) (and.left h)\n    example (h : p \u2227 q) : q \u2227 p := \u27e8h.right, h.left\u27e9\n\n    variables (hp : p) (hq : q)\n    #check (\u27e8hp, hq\u27e9 : p \u2227 q)\n\nend conjunction\n\nnamespace disjunction\n    example (hp : p) : p \u2228 q := or.intro_left q hp\n    example (hq : q) : p \u2228 q := or.intro_right p hq\n\n    -- Equivilant\n    example (h : p \u2228 q) : q \u2228 p :=\n        or.elim h\n            (assume hp : p,\n                show q \u2228 p, from or.intro_right q hp)\n            $ assume hq : q,\n                 or.intro_left p hq\n    example (h : p \u2228 q) : q \u2228 p :=\n        or.elim h (\u03bb hp : p, or.inr hp) (\u03bb hq : q, or.inl hq)\n    example (h : p \u2228 q) : q \u2228 p :=\n        h.elim (assume hp : p, or.inr hp) (assume hq : q, or.inl hq)\n\n    namespace neg\n        example (hpq : p \u2192 q) (hnq : \u00acq) : \u00acp :=\n        \u03bb hp : p,\n        show false, from hnq $ hpq hp\n\n        -- Equivilant\n        example (hp : p) (hnp : \u00acp) : q := false.elim $ hnp hp\n        example (hp : p) (hnp : \u00acp) : q := absurd hp hnp\n    end neg\n\n    theorem and_swap : p \u2227 q \u2194 q \u2227 p :=\n    iff.intro \n        (\u03bb h : p \u2227 q,\n            show q \u2227 p, from \u27e8h.right, h.left\u27e9)\n        (\u03bb h : q \u2227 p,\n            show p \u2227 q, from \u27e8h.right, h.left\u27e9)\n    #check and_swap p q\n\n    variable h : p \u2227 q\n    variable j : q \u2227 p\n    example : q \u2227 p := iff.mp (and_swap p q) h\n    example : p \u2227 q := iff.mpr (and_swap p q) j\n\n    theorem short_and_swap : p \u2227 q \u2194 q \u2227 p :=\n    \u27e8\u03bb h, \u27e8h.right, h.left\u27e9, \u03bb h, \u27e8h.right, h.left\u27e9\u27e9\n    example (h : p \u2227 q) : q \u2227 p := (short_and_swap p q).mp h\n            \nend disjunction", "meta": {"author": "robkorn", "repo": "theorem-proving-in-lean-exercises", "sha": "9c51da587105ee047a9db55d52709d881a39be7a", "save_path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises", "path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises/theorem-proving-in-lean-exercises-9c51da587105ee047a9db55d52709d881a39be7a/Chapter3/3-3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.722442979826944}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n-/\nimport analysis.normed_space.basic\nimport number_theory.padics.padic_norm\n\n/-!\n# p-adic numbers\n\nThis file defines the p-adic numbers (rationals) `\u211a_p` as\nthe completion of `\u211a` with respect to the p-adic norm.\nWe show that the p-adic norm on \u211a extends to `\u211a_p`, that `\u211a` is embedded in `\u211a_p`,\nand that `\u211a_p` is Cauchy complete.\n\n## Important definitions\n\n* `padic` : the type of p-adic numbers\n* `padic_norm_e` : the rational valued p-adic norm on `\u211a_p`\n* `padic.add_valuation` : the additive `p`-adic valuation on `\u211a_p`, with values in `with_top \u2124`.\n\n## Notation\n\nWe introduce the notation `\u211a_[p]` for the p-adic numbers.\n\n## Implementation notes\n\nMuch, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically\nby taking `[fact (prime p)]` as a type class argument.\n\nWe use the same concrete Cauchy sequence construction that is used to construct \u211d.\n`\u211a_p` inherits a field structure from this construction.\nThe extension of the norm on \u211a to `\u211a_p` is *not* analogous to extending the absolute value to \u211d,\nand hence the proof that `\u211a_p` is complete is different from the proof that \u211d is complete.\n\nA small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence\nindices in the proof that the norm extends.\n\n`padic_norm_e` is the rational-valued p-adic norm on `\u211a_p`.\nTo instantiate `\u211a_p` as a normed field, we must cast this into a \u211d-valued norm.\nThe `\u211d`-valued norm, using notation `\u2225 \u2225` from normed spaces,\nis the canonical representation of this norm.\n\n`simp` prefers `padic_norm` to `padic_norm_e` when possible.\nSince `padic_norm_e` and `\u2225 \u2225` have different types, `simp` does not rewrite one to the other.\n\nCoercions from `\u211a` to `\u211a_p` are set up to work with the `norm_cast` tactic.\n\n## References\n\n* [F. Q. Gouv\u00eaa, *p-adic numbers*][gouvea1997]\n* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]\n* <https://en.wikipedia.org/wiki/P-adic_number>\n\n## Tags\n\np-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion\n-/\n\nnoncomputable theory\nopen_locale classical\n\nopen nat multiplicity padic_norm cau_seq cau_seq.completion metric\n\n/-- The type of Cauchy sequences of rationals with respect to the p-adic norm. -/\n@[reducible] def padic_seq (p : \u2115) := cau_seq _ (padic_norm p)\n\nnamespace padic_seq\n\nsection\nvariables {p : \u2115} [fact p.prime]\n\n/-- The p-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually\nconstant. -/\nlemma stationary {f : cau_seq \u211a (padic_norm p)} (hf : \u00ac f \u2248 0) :\n  \u2203 N, \u2200 m n, N \u2264 m \u2192 N \u2264 n \u2192 padic_norm p (f n) = padic_norm p (f m) :=\nhave \u2203 \u03b5 > 0, \u2203 N1, \u2200 j \u2265 N1, \u03b5 \u2264 padic_norm p (f j),\n  from cau_seq.abv_pos_of_not_lim_zero $ not_lim_zero_of_not_congr_zero hf,\nlet \u27e8\u03b5, h\u03b5, N1, hN1\u27e9 := this,\n    \u27e8N2, hN2\u27e9 := cau_seq.cauchy\u2082 f h\u03b5 in\n\u27e8 max N1 N2,\n  \u03bb n m hn hm,\n  have padic_norm p (f n - f m) < \u03b5, from hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2,\n  have padic_norm p (f n - f m) < padic_norm p (f n),\n    from lt_of_lt_of_le this $ hN1 _ (max_le_iff.1 hn).1,\n  have  padic_norm p (f n - f m) < max (padic_norm p (f n)) (padic_norm p (f m)),\n    from lt_max_iff.2 (or.inl this),\n  begin\n    by_contradiction hne,\n    rw \u2190padic_norm.neg p (f m) at hne,\n    have hnam := add_eq_max_of_ne p hne,\n    rw [padic_norm.neg, max_comm] at hnam,\n    rw [\u2190hnam, sub_eq_add_neg, add_comm] at this,\n    apply _root_.lt_irrefl _ this\n  end \u27e9\n\n/-- For all n \u2265 stationary_point f hf, the p-adic norm of f n is the same. -/\ndef stationary_point {f : padic_seq p} (hf : \u00ac f \u2248 0) : \u2115 :=\nclassical.some $ stationary hf\n\nlemma stationary_point_spec {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  \u2200 {m n}, stationary_point hf \u2264 m \u2192 stationary_point hf \u2264 n \u2192\n    padic_norm p (f n) = padic_norm p (f m) :=\nclassical.some_spec $ stationary hf\n\n/-- Since the norm of the entries of a Cauchy sequence is eventually stationary,\nwe can lift the norm to sequences. -/\ndef norm (f : padic_seq p) : \u211a :=\nif hf : f \u2248 0 then 0 else padic_norm p (f (stationary_point hf))\n\nlemma norm_zero_iff (f : padic_seq p) : f.norm = 0 \u2194 f \u2248 0 :=\nbegin\n  constructor,\n  { intro h,\n    by_contradiction hf,\n    unfold norm at h, split_ifs at h,\n    apply hf,\n    intros \u03b5 h\u03b5,\n    existsi stationary_point hf,\n    intros j hj,\n    have heq := stationary_point_spec hf le_rfl hj,\n    simpa [h, heq] },\n  { intro h,\n    simp [norm, h] }\nend\n\nend\n\nsection embedding\nopen cau_seq\nvariables {p : \u2115} [fact p.prime]\n\nlemma equiv_zero_of_val_eq_of_equiv_zero {f g : padic_seq p}\n  (h : \u2200 k, padic_norm p (f k) = padic_norm p (g k)) (hf : f \u2248 0) : g \u2248 0 :=\n\u03bb \u03b5 h\u03b5, let \u27e8i, hi\u27e9 := hf _ h\u03b5 in\n\u27e8i, \u03bb j hj, by simpa [h] using hi _ hj\u27e9\n\nlemma norm_nonzero_of_not_equiv_zero {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  f.norm \u2260 0 :=\nhf \u2218 f.norm_zero_iff.1\n\nlemma norm_eq_norm_app_of_nonzero {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  \u2203 k, f.norm = padic_norm p k \u2227 k \u2260 0 :=\nhave heq : f.norm = padic_norm p (f $ stationary_point hf), by simp [norm, hf],\n\u27e8f $ stationary_point hf, heq,\n  \u03bb h, norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)\u27e9\n\nlemma not_lim_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac lim_zero (const (padic_norm p) q) :=\n\u03bb h', hq $ const_lim_zero.1 h'\n\nlemma not_equiv_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac (const (padic_norm p) q) \u2248 0 :=\n\u03bb h : lim_zero (const (padic_norm p) q - 0), not_lim_zero_const_of_nonzero hq $ by simpa using h\n\nlemma norm_nonneg (f : padic_seq p) : 0 \u2264 f.norm :=\nif hf : f \u2248 0 then by simp [hf, norm]\nelse by simp [norm, hf, padic_norm.nonneg]\n\n/-- An auxiliary lemma for manipulating sequence indices. -/\nlemma lift_index_left_left {f : padic_seq p} (hf : \u00ac f \u2248 0) (v2 v3 : \u2115) :\n  padic_norm p (f (stationary_point hf)) =\n    padic_norm p (f (max (stationary_point hf) (max v2 v3))) :=\nbegin\n  apply stationary_point_spec hf,\n  { apply le_max_left },\n  { exact le_rfl }\nend\n\n/-- An auxiliary lemma for manipulating sequence indices. -/\nlemma lift_index_left {f : padic_seq p} (hf : \u00ac f \u2248 0) (v1 v3 : \u2115) :\n  padic_norm p (f (stationary_point hf)) =\n    padic_norm p (f (max v1 (max (stationary_point hf) v3))) :=\nbegin\n  apply stationary_point_spec hf,\n  { apply le_trans,\n    { apply le_max_left _ v3 },\n    { apply le_max_right } },\n  { exact le_rfl }\nend\n\n/-- An auxiliary lemma for manipulating sequence indices. -/\nlemma lift_index_right {f : padic_seq p} (hf : \u00ac f \u2248 0) (v1 v2 : \u2115) :\n  padic_norm p (f (stationary_point hf)) =\n    padic_norm p (f (max v1 (max v2 (stationary_point hf)))) :=\nbegin\n  apply stationary_point_spec hf,\n  { apply le_trans,\n    { apply le_max_right v2 },\n    { apply le_max_right } },\n  { exact le_rfl }\nend\n\nend embedding\n\nsection valuation\nopen cau_seq\nvariables {p : \u2115} [fact p.prime]\n\n/-! ### Valuation on `padic_seq` -/\n\n/--\nThe `p`-adic valuation on `\u211a` lifts to `padic_seq p`.\n`valuation f` is defined to be the valuation of the (`\u211a`-valued) stationary point of `f`.\n-/\ndef valuation (f : padic_seq p) : \u2124 :=\nif hf : f \u2248 0 then 0 else padic_val_rat p (f (stationary_point hf))\n\nlemma norm_eq_pow_val {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  f.norm = p^(-f.valuation : \u2124) :=\nbegin\n  rw [norm, valuation, dif_neg hf, dif_neg hf, padic_norm, if_neg],\n  intro H,\n  apply cau_seq.not_lim_zero_of_not_congr_zero hf,\n  intros \u03b5 h\u03b5,\n  use (stationary_point hf),\n  intros n hn,\n  rw stationary_point_spec hf le_rfl hn,\n  simpa [H] using h\u03b5,\nend\n\nlemma val_eq_iff_norm_eq {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) :\n  f.valuation = g.valuation \u2194 f.norm = g.norm :=\nbegin\n  rw [norm_eq_pow_val hf, norm_eq_pow_val hg, \u2190 neg_inj, zpow_inj],\n  { exact_mod_cast (fact.out p.prime).pos },\n  { exact_mod_cast (fact.out p.prime).ne_one },\nend\n\nend valuation\n\nend padic_seq\n\nsection\nopen padic_seq\n\nprivate meta def index_simp_core (hh hf hg : expr)\n  (at_ : interactive.loc := interactive.loc.ns [none]) : tactic unit :=\ndo [v1, v2, v3] \u2190 [hh, hf, hg].mmap\n     (\u03bb n, tactic.mk_app ``stationary_point [n] <|> return n),\n   e1 \u2190 tactic.mk_app ``lift_index_left_left [hh, v2, v3] <|> return `(true),\n   e2 \u2190 tactic.mk_app ``lift_index_left [hf, v1, v3] <|> return `(true),\n   e3 \u2190 tactic.mk_app ``lift_index_right [hg, v1, v2] <|> return `(true),\n   sl \u2190 [e1, e2, e3].mfoldl (\u03bb s e, simp_lemmas.add s e) simp_lemmas.mk,\n   when at_.include_goal (tactic.simp_target sl >> tactic.skip),\n   hs \u2190 at_.get_locals, hs.mmap' (tactic.simp_hyp sl [])\n\n/--\n  This is a special-purpose tactic that lifts padic_norm (f (stationary_point f)) to\n  padic_norm (f (max _ _ _)).\n-/\nmeta def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)\n  (at_ : interactive.parse interactive.types.location) : tactic unit :=\ndo [h, f, g] \u2190 l.mmap tactic.i_to_expr,\n   index_simp_core h f g at_\nend\n\nnamespace padic_seq\nsection embedding\n\nopen cau_seq\nvariables {p : \u2115} [hp : fact p.prime]\ninclude hp\n\nlemma norm_mul (f g : padic_seq p) : (f * g).norm = f.norm * g.norm :=\nif hf : f \u2248 0 then\n  have hg : f * g \u2248 0, from mul_equiv_zero' _ hf,\n  by simp only [hf, hg, norm, dif_pos, zero_mul]\nelse if hg : g \u2248 0 then\n  have hf : f * g \u2248 0, from mul_equiv_zero _ hg,\n  by simp only [hf, hg, norm, dif_pos, mul_zero]\nelse\n  have hfg : \u00ac f * g \u2248 0, by apply mul_not_equiv_zero; assumption,\n  begin\n    unfold norm,\n    split_ifs,\n    padic_index_simp [hfg, hf, hg],\n    apply padic_norm.mul\n  end\n\nlemma eq_zero_iff_equiv_zero (f : padic_seq p) : mk f = 0 \u2194 f \u2248 0 :=\nmk_eq\n\nlemma ne_zero_iff_nequiv_zero (f : padic_seq p) : mk f \u2260 0 \u2194 \u00ac f \u2248 0 :=\nnot_iff_not.2 (eq_zero_iff_equiv_zero _)\n\nlemma norm_const (q : \u211a) : norm (const (padic_norm p) q) = padic_norm p q :=\nif hq : q = 0 then\n  have (const (padic_norm p) q) \u2248 0,\n    by simp [hq]; apply setoid.refl (const (padic_norm p) 0),\n  by subst hq; simp [norm, this]\nelse\n  have \u00ac (const (padic_norm p) q) \u2248 0, from not_equiv_zero_const_of_nonzero hq,\n  by simp [norm, this]\n\nlemma norm_values_discrete (a : padic_seq p) (ha : \u00ac a \u2248 0) :\n  (\u2203 (z : \u2124), a.norm = \u2191p ^ (-z)) :=\nlet \u27e8k, hk, hk'\u27e9 := norm_eq_norm_app_of_nonzero ha in\nby simpa [hk] using padic_norm.values_discrete p hk'\n\nlemma norm_one : norm (1 : padic_seq p) = 1 :=\nhave h1 : \u00ac (1 : padic_seq p) \u2248 0, from one_not_equiv_zero _,\nby simp [h1, norm, hp.1.one_lt]\n\nprivate lemma norm_eq_of_equiv_aux {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g)\n  (h : padic_norm p (f (stationary_point hf)) \u2260 padic_norm p (g (stationary_point hg)))\n  (hlt : padic_norm p (g (stationary_point hg)) < padic_norm p (f (stationary_point hf))) :\n  false :=\nbegin\n  have hpn : 0 < padic_norm p (f (stationary_point hf)) - padic_norm p (g (stationary_point hg)),\n    from sub_pos_of_lt hlt,\n  cases hfg _ hpn with N hN,\n  let i := max N (max (stationary_point hf) (stationary_point hg)),\n  have hi : N \u2264 i, from le_max_left _ _,\n  have hN' := hN _ hi,\n  padic_index_simp [N, hf, hg] at hN' h hlt,\n  have hpne : padic_norm p (f i) \u2260 padic_norm p (-(g i)),\n    by rwa [ \u2190padic_norm.neg p (g i)] at h,\n  let hpnem := add_eq_max_of_ne p hpne,\n  have hpeq : padic_norm p ((f - g) i) = max (padic_norm p (f i)) (padic_norm p (g i)),\n  { rwa padic_norm.neg at hpnem },\n  rw [hpeq, max_eq_left_of_lt hlt] at hN',\n  have : padic_norm p (f i) < padic_norm p (f i),\n  { apply lt_of_lt_of_le hN', apply sub_le_self, apply padic_norm.nonneg },\n  exact lt_irrefl _ this\nend\n\nprivate lemma norm_eq_of_equiv {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g) :\n  padic_norm p (f (stationary_point hf)) = padic_norm p (g (stationary_point hg)) :=\nbegin\n  by_contradiction h,\n  cases (decidable.em (padic_norm p (g (stationary_point hg)) <\n          padic_norm p (f (stationary_point hf))))\n      with hlt hnlt,\n  { exact norm_eq_of_equiv_aux hf hg hfg h hlt },\n  { apply norm_eq_of_equiv_aux hg hf (setoid.symm hfg) (ne.symm h),\n    apply lt_of_le_of_ne,\n    apply le_of_not_gt hnlt,\n    apply h }\nend\n\ntheorem norm_equiv {f g : padic_seq p} (hfg : f \u2248 g) : f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from setoid.trans (setoid.symm hfg) hf,\n  by simp [norm, hf, hg]\nelse have hg : \u00ac g \u2248 0, from hf \u2218 setoid.trans hfg,\nby unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg\n\nprivate lemma norm_nonarchimedean_aux {f g : padic_seq p}\n  (hfg : \u00ac f + g \u2248 0) (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) : (f + g).norm \u2264 max (f.norm) (g.norm) :=\nbegin\n  unfold norm, split_ifs,\n  padic_index_simp [hfg, hf, hg],\n  apply padic_norm.nonarchimedean\nend\n\ntheorem norm_nonarchimedean (f g : padic_seq p) : (f + g).norm \u2264 max (f.norm) (g.norm) :=\nif hfg : f + g \u2248 0 then\n  have 0 \u2264 max (f.norm) (g.norm), from le_max_of_le_left (norm_nonneg _),\n  by simpa only [hfg, norm, ne.def, le_max_iff, cau_seq.add_apply, not_true, dif_pos]\nelse if hf : f \u2248 0 then\n  have hfg' : f + g \u2248 g,\n  { change lim_zero (f - 0) at hf,\n    show lim_zero (f + g - g), by simpa only [sub_zero, add_sub_cancel] using hf },\n  have hcfg : (f + g).norm = g.norm, from norm_equiv hfg',\n  have hcl : f.norm = 0, from (norm_zero_iff f).2 hf,\n  have max (f.norm) (g.norm) = g.norm,\n    by rw hcl; exact max_eq_right (norm_nonneg _),\n  by rw [this, hcfg]\nelse if hg : g \u2248 0 then\n  have hfg' : f + g \u2248 f,\n  { change lim_zero (g - 0) at hg,\n    show lim_zero (f + g - f), by simpa only [add_sub_cancel', sub_zero] using hg },\n  have hcfg : (f + g).norm = f.norm, from norm_equiv hfg',\n  have hcl : g.norm = 0, from (norm_zero_iff g).2 hg,\n  have max (f.norm) (g.norm) = f.norm,\n    by rw hcl; exact max_eq_left (norm_nonneg _),\n  by rw [this, hcfg]\nelse norm_nonarchimedean_aux hfg hf hg\n\nlemma norm_eq {f g : padic_seq p} (h : \u2200 k, padic_norm p (f k) = padic_norm p (g k)) :\n  f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from equiv_zero_of_val_eq_of_equiv_zero h hf,\n  by simp only [hf, hg, norm, dif_pos]\nelse\n  have hg : \u00ac g \u2248 0, from \u03bb hg, hf $ equiv_zero_of_val_eq_of_equiv_zero\n    (by simp only [h, forall_const, eq_self_iff_true]) hg,\n  begin\n    simp only [hg, hf, norm, dif_neg, not_false_iff],\n    let i := max (stationary_point hf) (stationary_point hg),\n    have hpf : padic_norm p (f (stationary_point hf)) = padic_norm p (f i),\n    { apply stationary_point_spec, apply le_max_left, exact le_rfl },\n    have hpg : padic_norm p (g (stationary_point hg)) = padic_norm p (g i),\n    { apply stationary_point_spec, apply le_max_right, exact le_rfl },\n    rw [hpf, hpg, h]\n  end\n\nlemma norm_neg (a : padic_seq p) : (-a).norm = a.norm :=\nnorm_eq $ by simp\n\nlemma norm_eq_of_add_equiv_zero {f g : padic_seq p} (h : f + g \u2248 0) : f.norm = g.norm :=\nhave lim_zero (f + g - 0), from h,\nhave f \u2248 -g, from show lim_zero (f - (-g)), by simpa only [sub_zero, sub_neg_eq_add],\nhave f.norm = (-g).norm, from norm_equiv this,\nby simpa only [norm_neg] using this\n\nlemma add_eq_max_of_ne {f g : padic_seq p} (hfgne : f.norm \u2260 g.norm) :\n  (f + g).norm = max f.norm g.norm :=\nhave hfg : \u00acf + g \u2248 0, from mt norm_eq_of_add_equiv_zero hfgne,\nif hf : f \u2248 0 then\n  have lim_zero (f - 0), from hf,\n  have f + g \u2248 g, from show lim_zero ((f + g) - g), by simpa only [sub_zero, add_sub_cancel],\n  have h1 : (f+g).norm = g.norm, from norm_equiv this,\n  have h2 : f.norm = 0, from (norm_zero_iff _).2 hf,\n  by rw [h1, h2]; rw max_eq_right (norm_nonneg _)\nelse if hg : g \u2248 0 then\n  have lim_zero (g - 0), from hg,\n  have f + g \u2248 f, from show lim_zero ((f + g) - f), by rw [add_sub_cancel']; simpa only [sub_zero],\n  have h1 : (f+g).norm = f.norm, from norm_equiv this,\n  have h2 : g.norm = 0, from (norm_zero_iff _).2 hg,\n  by rw [h1, h2]; rw max_eq_left (norm_nonneg _)\nelse\nbegin\n  unfold norm at \u22a2 hfgne, split_ifs at \u22a2 hfgne,\n  padic_index_simp [hfg, hf, hg] at \u22a2 hfgne,\n  exact padic_norm.add_eq_max_of_ne p hfgne\nend\n\nend embedding\nend padic_seq\n\n/-- The p-adic numbers `Q_[p]` are the Cauchy completion of `\u211a` with respect to the p-adic norm. -/\ndef padic (p : \u2115) [fact p.prime] := @cau_seq.completion.Cauchy _ _ _ _ (padic_norm p) _\nnotation `\u211a_[` p `]` := padic p\n\nnamespace padic\n\nsection completion\nvariables {p : \u2115} [fact p.prime]\n\n/-- The discrete field structure on `\u211a_p` is inherited from the Cauchy completion construction. -/\ninstance field : field (\u211a_[p]) :=\ncau_seq.completion.field\n\ninstance : inhabited \u211a_[p] := \u27e80\u27e9\n\n-- short circuits\n\ninstance : has_zero \u211a_[p] := by apply_instance\ninstance : has_one \u211a_[p] := by apply_instance\ninstance : has_add \u211a_[p] := by apply_instance\ninstance : has_mul \u211a_[p] := by apply_instance\ninstance : has_sub \u211a_[p] := by apply_instance\ninstance : has_neg \u211a_[p] := by apply_instance\ninstance : has_div \u211a_[p] := by apply_instance\ninstance : add_comm_group \u211a_[p] := by apply_instance\ninstance : comm_ring \u211a_[p] := by apply_instance\n\n/-- Builds the equivalence class of a Cauchy sequence of rationals. -/\ndef mk : padic_seq p \u2192 \u211a_[p] := quotient.mk\nend completion\n\nsection completion\nvariables (p : \u2115) [fact p.prime]\n\nlemma mk_eq {f g : padic_seq p} : mk f = mk g \u2194 f \u2248 g := quotient.eq\n\n/-- Embeds the rational numbers in the p-adic numbers. -/\ndef of_rat : \u211a \u2192 \u211a_[p] := cau_seq.completion.of_rat\n\n@[simp] lemma of_rat_add : \u2200 (x y : \u211a), of_rat p (x + y) = of_rat p x + of_rat p y :=\ncau_seq.completion.of_rat_add\n\n@[simp] lemma of_rat_neg : \u2200 (x : \u211a), of_rat p (-x) = -of_rat p x :=\ncau_seq.completion.of_rat_neg\n\n@[simp] lemma of_rat_mul : \u2200 (x y : \u211a), of_rat p (x * y) = of_rat p x * of_rat p y :=\ncau_seq.completion.of_rat_mul\n\n@[simp] lemma of_rat_sub : \u2200 (x y : \u211a), of_rat p (x - y) = of_rat p x - of_rat p y :=\ncau_seq.completion.of_rat_sub\n\n@[simp] lemma of_rat_div : \u2200 (x y : \u211a), of_rat p (x / y) = of_rat p x / of_rat p y :=\ncau_seq.completion.of_rat_div\n\n@[simp] lemma of_rat_one : of_rat p 1 = 1 := rfl\n\n@[simp] lemma of_rat_zero : of_rat p 0 = 0 := rfl\n\nlemma cast_eq_of_rat_of_nat (n : \u2115) : (\u2191n : \u211a_[p]) = of_rat p n :=\nbegin\n  induction n with n ih,\n  { refl },\n  { simpa using ih }\nend\n\nlemma cast_eq_of_rat_of_int (n : \u2124) : \u2191n = of_rat p n :=\nby induction n; simp [cast_eq_of_rat_of_nat]\n\nlemma cast_eq_of_rat : \u2200 (q : \u211a), (\u2191q : \u211a_[p]) = of_rat p q\n| \u27e8n, d, h1, h2\u27e9 :=\n  show \u2191n / \u2191d = _, from\n    have (\u27e8n, d, h1, h2\u27e9 : \u211a) = rat.mk n d, from rat.num_denom',\n    by simp [this, rat.mk_eq_div, of_rat_div, cast_eq_of_rat_of_int, cast_eq_of_rat_of_nat]\n\n@[norm_cast] lemma coe_add : \u2200 {x y : \u211a}, (\u2191(x + y) : \u211a_[p]) = \u2191x + \u2191y := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_neg : \u2200 {x : \u211a}, (\u2191(-x) : \u211a_[p]) = -\u2191x := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_mul : \u2200 {x y : \u211a}, (\u2191(x * y) : \u211a_[p]) = \u2191x * \u2191y := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_sub : \u2200 {x y : \u211a}, (\u2191(x - y) : \u211a_[p]) = \u2191x - \u2191y := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_div : \u2200 {x y : \u211a}, (\u2191(x / y) : \u211a_[p]) = \u2191x / \u2191y := by simp [cast_eq_of_rat]\n\n@[norm_cast] lemma coe_one : (\u21911 : \u211a_[p]) = 1 := by simp [cast_eq_of_rat]\n@[norm_cast] lemma coe_zero : (\u21910 : \u211a_[p]) = 0 := rfl\n\nlemma const_equiv {q r : \u211a} : const (padic_norm p) q \u2248 const (padic_norm p) r \u2194 q = r :=\n\u27e8 \u03bb heq : lim_zero (const (padic_norm p) (q - r)),\n    eq_of_sub_eq_zero $ const_lim_zero.1 heq,\n  \u03bb heq, by rw heq; apply setoid.refl _ \u27e9\n\nlemma of_rat_eq {q r : \u211a} : of_rat p q = of_rat p r \u2194 q = r :=\n\u27e8(const_equiv p).1 \u2218 quotient.eq.1, \u03bb h, by rw h\u27e9\n\n@[norm_cast] lemma coe_inj {q r : \u211a} : (\u2191q : \u211a_[p]) = \u2191r \u2194 q = r :=\nby simp [cast_eq_of_rat, of_rat_eq]\n\ninstance : char_zero \u211a_[p] :=\n\u27e8\u03bb m n, by { rw \u2190 rat.cast_coe_nat, norm_cast, exact id }\u27e9\n\nend completion\nend padic\n\n/-- The rational-valued p-adic norm on `\u211a_p` is lifted from the norm on Cauchy sequences. The\ncanonical form of this function is the normed space instance, with notation `\u2225 \u2225`. -/\ndef padic_norm_e {p : \u2115} [hp : fact p.prime] : \u211a_[p] \u2192 \u211a :=\nquotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _\n\nnamespace padic_norm_e\nsection embedding\nopen padic_seq\nvariables {p : \u2115} [fact p.prime]\n\nlemma defn (f : padic_seq p) {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) : \u2203 N, \u2200 i \u2265 N, padic_norm_e (\u27e6f\u27e7 - f i) < \u03b5 :=\nbegin\n  simp only [padic.cast_eq_of_rat],\n  change \u2203 N, \u2200 i \u2265 N, (f - const _ (f i)).norm < \u03b5,\n  by_contra' h,\n  cases cauchy\u2082 f h\u03b5 with N hN,\n  rcases h N with \u27e8i, hi, hge\u27e9,\n  have hne : \u00ac (f - const (padic_norm p) (f i)) \u2248 0,\n  { intro h, unfold padic_seq.norm at hge; split_ifs at hge, exact not_lt_of_ge hge h\u03b5 },\n  unfold padic_seq.norm at hge; split_ifs at hge,\n  apply not_le_of_gt _ hge,\n  cases em (N \u2264 stationary_point hne) with hgen hngen,\n  { apply hN _ hgen _ hi },\n  { have := stationary_point_spec hne le_rfl (le_of_not_le hngen),\n    rw \u2190this,\n    exact hN _ le_rfl _ hi },\nend\n\nprotected lemma nonneg (q : \u211a_[p]) : 0 \u2264 padic_norm_e q :=\nquotient.induction_on q $ norm_nonneg\n\nlemma zero_def : (0 : \u211a_[p]) = \u27e60\u27e7 := rfl\n\nlemma zero_iff (q : \u211a_[p]) : padic_norm_e q = 0 \u2194 q = 0 :=\nquotient.induction_on q $\n  by simpa only [zero_def, quotient.eq] using norm_zero_iff\n\n@[simp] protected lemma zero : padic_norm_e (0 : \u211a_[p]) = 0 :=\n(zero_iff _).2 rfl\n\n/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the\nequivalent theorems about `norm` (`\u2225 \u2225`). -/\n@[simp] protected lemma one' : padic_norm_e (1 : \u211a_[p]) = 1 :=\nnorm_one\n\n@[simp] protected lemma neg (q : \u211a_[p]) : padic_norm_e (-q) = padic_norm_e q :=\nquotient.induction_on q $ norm_neg\n\n/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the\nequivalent theorems about `norm` (`\u2225 \u2225`). -/\ntheorem nonarchimedean' (q r : \u211a_[p]) :\n  padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_nonarchimedean\n\n/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the\nequivalent theorems about `norm` (`\u2225 \u2225`). -/\ntheorem add_eq_max_of_ne' {q r : \u211a_[p]} :\n  padic_norm_e q \u2260 padic_norm_e r \u2192 padic_norm_e (q + r) = max (padic_norm_e q) (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ \u03bb _ _, padic_seq.add_eq_max_of_ne\n\nlemma triangle_ineq (x y z : \u211a_[p]) :\n  padic_norm_e (x - z) \u2264 padic_norm_e (x - y) + padic_norm_e (y - z) :=\ncalc padic_norm_e (x - z) = padic_norm_e ((x - y) + (y - z)) : by rw sub_add_sub_cancel\n  ... \u2264 max (padic_norm_e (x - y)) (padic_norm_e (y - z)) : padic_norm_e.nonarchimedean' _ _\n  ... \u2264 padic_norm_e (x - y) + padic_norm_e (y - z) :\n    max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)\n\nprotected lemma add (q r : \u211a_[p]) : padic_norm_e (q + r) \u2264 (padic_norm_e q) + (padic_norm_e r) :=\ncalc\n  padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) : nonarchimedean' _ _\n                      ... \u2264 (padic_norm_e q) + (padic_norm_e r) :\n                              max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)\n\nprotected lemma mul' (q r : \u211a_[p]) : padic_norm_e (q * r) = (padic_norm_e q) * (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_mul\n\ninstance : is_absolute_value (@padic_norm_e p _) :=\n{ abv_nonneg := padic_norm_e.nonneg,\n  abv_eq_zero := zero_iff,\n  abv_add := padic_norm_e.add,\n  abv_mul := padic_norm_e.mul' }\n\n@[simp] lemma eq_padic_norm' (q : \u211a) : padic_norm_e (padic.of_rat p q) = padic_norm p q :=\nnorm_const _\n\nprotected theorem image' {q : \u211a_[p]} : q \u2260 0 \u2192 \u2203 n : \u2124, padic_norm_e q = p ^ (-n) :=\nquotient.induction_on q $ \u03bb f hf,\n  have \u00ac f \u2248 0, from (ne_zero_iff_nequiv_zero f).1 hf,\n  norm_values_discrete f this\n\nlemma sub_rev (q r : \u211a_[p]) : padic_norm_e (q - r) = padic_norm_e (r - q) :=\nby rw \u2190(padic_norm_e.neg); simp\n\nend embedding\nend padic_norm_e\n\nnamespace padic\n\nsection complete\nopen padic_seq padic\n\ntheorem rat_dense' {p : \u2115} [fact p.prime] (q : \u211a_[p]) {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) :\n  \u2203 r : \u211a, padic_norm_e (q - r) < \u03b5 :=\nquotient.induction_on q $ \u03bb q',\n  have \u2203 N, \u2200 m n \u2265 N, padic_norm p (q' m - q' n) < \u03b5, from cauchy\u2082 _ h\u03b5,\n  let \u27e8N, hN\u27e9 := this in\n  \u27e8q' N,\n    begin\n      simp only [padic.cast_eq_of_rat],\n      change padic_seq.norm (q' - const _ (q' N)) < \u03b5,\n      cases decidable.em ((q' - const (padic_norm p) (q' N)) \u2248 0) with heq hne',\n      { simpa only [heq, padic_seq.norm, dif_pos] },\n      { simp only [padic_seq.norm, dif_neg hne'],\n        change padic_norm p (q' _ - q' _) < \u03b5,\n        have := stationary_point_spec hne',\n        cases decidable.em (stationary_point hne' \u2264 N) with hle hle,\n        { have := eq.symm (this le_rfl hle),\n          simp only [const_apply, sub_apply, padic_norm.zero, sub_self] at this,\n          simpa only [this] },\n        { exact hN _ (lt_of_not_ge hle).le _ le_rfl } }\n    end\u27e9\n\nvariables {p : \u2115} [fact p.prime] (f : cau_seq _ (@padic_norm_e p _))\nopen classical\n\nprivate lemma div_nat_pos (n : \u2115) : 0 < (1 / ((n + 1): \u211a)) :=\ndiv_pos zero_lt_one (by exact_mod_cast succ_pos _)\n\n/-- `lim_seq f`, for `f` a Cauchy sequence of `p`-adic numbers,\nis a sequence of rationals with the same limit point as `f`. -/\ndef lim_seq : \u2115 \u2192 \u211a := \u03bb n, classical.some (rat_dense' (f n) (div_nat_pos n))\n\nlemma exi_rat_seq_conv {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) :\n  \u2203 N, \u2200 i \u2265 N, padic_norm_e (f i - ((lim_seq f) i : \u211a_[p])) < \u03b5 :=\nbegin\n  refine (exists_nat_gt (1/\u03b5)).imp (\u03bb N hN i hi, _),\n  have h := classical.some_spec (rat_dense' (f i) (div_nat_pos i)),\n  refine lt_of_lt_of_le h ((div_le_iff' $ by exact_mod_cast succ_pos _).mpr _),\n  rw right_distrib,\n  apply le_add_of_le_of_nonneg,\n  { exact (div_le_iff h\u03b5).mp (le_trans (le_of_lt hN) (by exact_mod_cast hi)) },\n  { apply le_of_lt, simpa }\nend\n\nlemma exi_rat_seq_conv_cauchy : is_cau_seq (padic_norm p) (lim_seq f) :=\nassume \u03b5 h\u03b5,\nhave h\u03b53 : 0 < \u03b5 / 3, from div_pos h\u03b5 (by norm_num),\nlet \u27e8N, hN\u27e9 := exi_rat_seq_conv f h\u03b53,\n    \u27e8N2, hN2\u27e9 := f.cauchy\u2082 h\u03b53 in\nbegin\n  existsi max N N2,\n  intros j hj,\n  suffices :\n    padic_norm_e ((\u2191(lim_seq f j) - f (max N N2)) + (f (max N N2) - lim_seq f (max N N2))) < \u03b5,\n  { ring_nf at this \u22a2,\n    rw [\u2190 padic_norm_e.eq_padic_norm', \u2190 padic.cast_eq_of_rat],\n    exact_mod_cast this },\n  { apply lt_of_le_of_lt,\n    { apply padic_norm_e.add },\n    { have : (3 : \u211a) \u2260 0, by norm_num,\n      have : \u03b5 = \u03b5 / 3 + \u03b5 / 3 + \u03b5 / 3,\n      { field_simp [this], simp only [bit0, bit1, mul_add, mul_one] },\n      rw this,\n      apply add_lt_add,\n      { suffices : padic_norm_e ((\u2191(lim_seq f j) - f j) + (f j - f (max N N2))) < \u03b5 / 3 + \u03b5 / 3,\n          by simpa only [sub_add_sub_cancel],\n        apply lt_of_le_of_lt,\n        { apply padic_norm_e.add },\n        { apply add_lt_add,\n          { rw [padic_norm_e.sub_rev],\n            apply_mod_cast hN,\n            exact le_of_max_le_left hj },\n          { exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _) } } },\n      { apply_mod_cast hN,\n        apply le_max_left }}}\nend\n\nprivate def lim' : padic_seq p := \u27e8_, exi_rat_seq_conv_cauchy f\u27e9\n\nprivate def lim : \u211a_[p] := \u27e6lim' f\u27e7\n\n\n\nend complete\n\nsection normed_space\nvariables (p : \u2115) [fact p.prime]\n\ninstance : has_dist \u211a_[p] := \u27e8\u03bb x y, padic_norm_e (x - y)\u27e9\n\ninstance : metric_space \u211a_[p] :=\n{ dist_self := by simp [dist],\n  dist := dist,\n  dist_comm := \u03bb x y, by unfold dist; rw \u2190padic_norm_e.neg (x - y); simp,\n  dist_triangle :=\n    begin\n      intros, unfold dist,\n      exact_mod_cast padic_norm_e.triangle_ineq _ _ _,\n    end,\n  eq_of_dist_eq_zero :=\n    begin\n      unfold dist, intros _ _ h,\n      apply eq_of_sub_eq_zero,\n      apply (padic_norm_e.zero_iff _).1,\n      exact_mod_cast h\n    end }\n\ninstance : has_norm \u211a_[p] := \u27e8\u03bb x, padic_norm_e x\u27e9\n\ninstance : normed_field \u211a_[p] :=\n{ dist_eq := \u03bb _ _, rfl,\n  norm_mul' := by simp [has_norm.norm, padic_norm_e.mul'],\n  norm := norm, .. padic.field, .. padic.metric_space p }\n\ninstance is_absolute_value : is_absolute_value (\u03bb a : \u211a_[p], \u2225a\u2225) :=\n{ abv_nonneg := norm_nonneg,\n  abv_eq_zero := \u03bb _, norm_eq_zero,\n  abv_add := norm_add_le,\n  abv_mul := by simp [has_norm.norm, padic_norm_e.mul'] }\n\ntheorem rat_dense {p : \u2115} {hp : fact p.prime} (q : \u211a_[p]) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n        \u2203 r : \u211a, \u2225q - r\u2225 < \u03b5 :=\nlet \u27e8\u03b5', h\u03b5'l, h\u03b5'r\u27e9 := exists_rat_btwn h\u03b5,\n    \u27e8r, hr\u27e9 := rat_dense' q (by simpa using h\u03b5'l)  in\n\u27e8r, lt_trans (by simpa [has_norm.norm] using hr) h\u03b5'r\u27e9\n\nend normed_space\nend padic\n\nnamespace padic_norm_e\nsection normed_space\nvariables {p : \u2115} [hp : fact p.prime]\ninclude hp\n\n@[simp] protected lemma mul (q r : \u211a_[p]) : \u2225q * r\u2225 = \u2225q\u2225 * \u2225r\u2225 :=\nby simp [has_norm.norm, padic_norm_e.mul']\n\nprotected lemma is_norm (q : \u211a_[p]) : \u2191(padic_norm_e q) = \u2225q\u2225 := rfl\n\ntheorem nonarchimedean (q r : \u211a_[p]) : \u2225q + r\u2225 \u2264 max (\u2225q\u2225) (\u2225r\u2225) :=\nbegin\n  unfold has_norm.norm,\n  exact_mod_cast nonarchimedean' _ _\nend\n\ntheorem add_eq_max_of_ne {q r : \u211a_[p]} (h : \u2225q\u2225 \u2260 \u2225r\u2225) : \u2225q+r\u2225 = max (\u2225q\u2225) (\u2225r\u2225) :=\nbegin\n  unfold has_norm.norm,\n  apply_mod_cast add_eq_max_of_ne',\n  intro h',\n  apply h,\n  unfold has_norm.norm,\n  exact_mod_cast h'\nend\n\n@[simp] lemma eq_padic_norm (q : \u211a) : \u2225(\u2191q : \u211a_[p])\u2225 = padic_norm p q :=\nbegin\n  unfold has_norm.norm,\n  rw [\u2190 padic_norm_e.eq_padic_norm', \u2190 padic.cast_eq_of_rat]\nend\n\n@[simp] lemma norm_p : \u2225(p : \u211a_[p])\u2225 = p\u207b\u00b9 :=\nbegin\n  have p\u2080 : p \u2260 0 := hp.1.ne_zero,\n  have p\u2081 : p \u2260 1 := hp.1.ne_one,\n  simp [p\u2080, p\u2081, norm, padic_norm, padic_val_rat, padic_val_int, zpow_neg,\n    padic.cast_eq_of_rat_of_nat],\nend\n\nlemma norm_p_lt_one : \u2225(p : \u211a_[p])\u2225 < 1 :=\nbegin\n  rw norm_p,\n  apply inv_lt_one,\n  exact_mod_cast hp.1.one_lt\nend\n\n@[simp] lemma norm_p_pow (n : \u2124) : \u2225(p^n : \u211a_[p])\u2225 = p^-n :=\nby rw [norm_zpow, norm_p]; field_simp\n\ninstance : nondiscrete_normed_field \u211a_[p] :=\n{ non_trivial := \u27e8p\u207b\u00b9, begin\n    rw [norm_inv, norm_p, inv_inv],\n    exact_mod_cast hp.1.one_lt\n  end\u27e9,\n  .. padic.normed_field p }\n\nprotected theorem image {q : \u211a_[p]} : q \u2260 0 \u2192 \u2203 n : \u2124, \u2225q\u2225 = \u2191((\u2191p : \u211a) ^ (-n)) :=\nquotient.induction_on q $ \u03bb f hf,\n  have \u00ac f \u2248 0, from (padic_seq.ne_zero_iff_nequiv_zero f).1 hf,\n  let \u27e8n, hn\u27e9 := padic_seq.norm_values_discrete f this in\n  \u27e8n, congr_arg coe hn\u27e9\n\nprotected lemma is_rat (q : \u211a_[p]) : \u2203 q' : \u211a, \u2225q\u2225 = \u2191q' :=\nif h : q = 0 then \u27e80, by simp [h]\u27e9\nelse let \u27e8n, hn\u27e9 := padic_norm_e.image h in \u27e8_, hn\u27e9\n\n/--`rat_norm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number.\n\nThe lemma `padic_norm_e.eq_rat_norm` asserts `\u2225q\u2225 = rat_norm q`. -/\ndef rat_norm (q : \u211a_[p]) : \u211a := classical.some (padic_norm_e.is_rat q)\n\nlemma eq_rat_norm (q : \u211a_[p]) : \u2225q\u2225 = rat_norm q := classical.some_spec (padic_norm_e.is_rat q)\n\ntheorem norm_rat_le_one : \u2200 {q : \u211a} (hq : \u00ac p \u2223 q.denom), \u2225(q : \u211a_[p])\u2225 \u2264 1\n| \u27e8n, d, hn, hd\u27e9 := \u03bb hq : \u00ac p \u2223 d,\n  if hnz : n = 0 then\n    have (\u27e8n, d, hn, hd\u27e9 : \u211a) = 0,\n    from rat.zero_iff_num_zero.mpr hnz,\n    by norm_num [this]\n  else\n    begin\n      have hnz' : { rat . num := n, denom := d, pos := hn, cop := hd } \u2260 0,\n        from mt rat.zero_iff_num_zero.1 hnz,\n      rw [padic_norm_e.eq_padic_norm],\n      norm_cast,\n      rw [padic_norm.eq_zpow_of_nonzero p hnz', padic_val_rat, neg_sub,\n        padic_val_nat.eq_zero_of_not_dvd hq],\n      norm_cast,\n      rw [zero_sub, zpow_neg, zpow_coe_nat],\n      apply inv_le_one,\n      { norm_cast,\n        apply one_le_pow,\n        exact hp.1.pos, },\n    end\n\ntheorem norm_int_le_one (z : \u2124) : \u2225(z : \u211a_[p])\u2225 \u2264 1 :=\nsuffices \u2225((z : \u211a) : \u211a_[p])\u2225 \u2264 1, by simpa,\nnorm_rat_le_one $ by simp [hp.1.ne_one]\n\nlemma norm_int_lt_one_iff_dvd (k : \u2124) : \u2225(k : \u211a_[p])\u2225 < 1 \u2194 \u2191p \u2223 k :=\nbegin\n  split,\n  { intro h,\n    contrapose! h,\n    apply le_of_eq,\n    rw eq_comm,\n    calc \u2225(k : \u211a_[p])\u2225 = \u2225((k : \u211a) : \u211a_[p])\u2225 : by { norm_cast }\n    ... = padic_norm p k : padic_norm_e.eq_padic_norm _\n    ... = 1 : _,\n    rw padic_norm,\n    split_ifs with H,\n    { exfalso,\n      apply h,\n      norm_cast at H,\n      rw H,\n      apply dvd_zero },\n    { norm_cast at H \u22a2,\n      convert zpow_zero _,\n      rw [neg_eq_zero, padic_val_rat.of_int],\n      norm_cast,\n      apply padic_val_int.eq_zero_of_not_dvd h, } },\n  { rintro \u27e8x, rfl\u27e9,\n    push_cast,\n    rw padic_norm_e.mul,\n    calc _ \u2264 \u2225(p : \u211a_[p])\u2225 * 1 : mul_le_mul le_rfl (by simpa using norm_int_le_one _)\n                                            (norm_nonneg _) (norm_nonneg _)\n    ... < 1 : _,\n    { rw [mul_one, padic_norm_e.norm_p],\n      apply inv_lt_one,\n      exact_mod_cast hp.1.one_lt }, },\nend\n\nlemma norm_int_le_pow_iff_dvd (k : \u2124) (n : \u2115) : \u2225(k : \u211a_[p])\u2225 \u2264 ((\u2191p)^(-n : \u2124)) \u2194 \u2191(p^n) \u2223 k :=\nbegin\n  have : (p : \u211d) ^ (-n : \u2124) = \u2191((p ^ (-n : \u2124) : \u211a)), {simp},\n  rw [show (k : \u211a_[p]) = ((k : \u211a) : \u211a_[p]), by norm_cast, eq_padic_norm, this],\n  norm_cast,\n  rw padic_norm.dvd_iff_norm_le,\nend\n\nlemma eq_of_norm_add_lt_right {p : \u2115} {hp : fact p.prime} {z1 z2 : \u211a_[p]}\n  (h : \u2225z1 + z2\u2225 < \u2225z2\u2225) : \u2225z1\u2225 = \u2225z2\u2225 :=\nby_contradiction $ \u03bb hne,\n  not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_right) h\n\nlemma eq_of_norm_add_lt_left {p : \u2115} {hp : fact p.prime} {z1 z2 : \u211a_[p]}\n  (h : \u2225z1 + z2\u2225 < \u2225z1\u2225) : \u2225z1\u2225 = \u2225z2\u2225 :=\nby_contradiction $ \u03bb hne,\n  not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_left) h\n\nend normed_space\nend padic_norm_e\n\nnamespace padic\nvariables {p : \u2115} [hp_prime : fact p.prime]\ninclude hp_prime\n\nset_option eqn_compiler.zeta true\ninstance complete : cau_seq.is_complete \u211a_[p] norm :=\nbegin\n  split, intro f,\n  have cau_seq_norm_e : is_cau_seq padic_norm_e f,\n  { intros \u03b5 h\u03b5,\n    let h := is_cau f \u03b5 (by exact_mod_cast h\u03b5),\n    unfold norm at h,\n    apply_mod_cast h },\n  cases padic.complete' \u27e8f, cau_seq_norm_e\u27e9 with q hq,\n  existsi q,\n  intros \u03b5 h\u03b5,\n  cases exists_rat_btwn h\u03b5 with \u03b5' h\u03b5',\n  norm_cast at h\u03b5',\n  cases hq \u03b5' h\u03b5'.1 with N hN, existsi N,\n  intros i hi, let h := hN i hi,\n  unfold norm,\n  rw_mod_cast [cau_seq.sub_apply, padic_norm_e.sub_rev],\n  refine lt_trans _ h\u03b5'.2,\n  exact_mod_cast hN i hi\nend\n\nlemma padic_norm_e_lim_le {f : cau_seq \u211a_[p] norm} {a : \u211d} (ha : 0 < a)\n      (hf : \u2200 i, \u2225f i\u2225 \u2264 a) : \u2225f.lim\u2225 \u2264 a :=\nlet \u27e8N, hN\u27e9 := setoid.symm (cau_seq.equiv_lim f) _ ha in\ncalc \u2225f.lim\u2225 = \u2225f.lim - f N + f N\u2225 : by simp\n                ... \u2264 max (\u2225f.lim - f N\u2225) (\u2225f N\u2225) : padic_norm_e.nonarchimedean _ _\n                ... \u2264 a : max_le (le_of_lt (hN _ le_rfl)) (hf _)\n\nopen filter set\n\ninstance : complete_space \u211a_[p] :=\nbegin\n  apply complete_of_cauchy_seq_tendsto,\n  intros u hu,\n  let c : cau_seq \u211a_[p] norm := \u27e8u, metric.cauchy_seq_iff'.mp hu\u27e9,\n  refine \u27e8c.lim, \u03bb s h, _\u27e9,\n  rcases metric.mem_nhds_iff.1 h with \u27e8\u03b5, \u03b50, h\u03b5\u27e9,\n  have := c.equiv_lim \u03b5 \u03b50,\n  simp only [mem_map, mem_at_top_sets, mem_set_of_eq],\n  exact this.imp (\u03bb N hN n hn, h\u03b5 (hN n hn))\nend\n\n/-!\n### Valuation on `\u211a_[p]`\n-/\n\n/--\n`padic.valuation` lifts the p-adic valuation on rationals to `\u211a_[p]`.\n-/\ndef valuation : \u211a_[p] \u2192 \u2124 :=\nquotient.lift (@padic_seq.valuation p _) (\u03bb f g h,\nbegin\n  by_cases hf : f \u2248 0,\n  { have hg : g \u2248 0, from setoid.trans (setoid.symm h) hf,\n    simp [hf, hg, padic_seq.valuation] },\n  { have hg : \u00ac g \u2248 0, from (\u03bb hg, hf (setoid.trans h hg)),\n    rw padic_seq.val_eq_iff_norm_eq hf hg,\n    exact padic_seq.norm_equiv h },\nend)\n\n@[simp] lemma valuation_zero : valuation (0 : \u211a_[p]) = 0 :=\ndif_pos ((const_equiv p).2 rfl)\n\n@[simp] lemma valuation_one : valuation (1 : \u211a_[p]) = 0 :=\nbegin\n  change dite (cau_seq.const (padic_norm p) 1 \u2248 _) _ _ = _,\n  have h : \u00ac cau_seq.const (padic_norm p) 1 \u2248 0,\n  { assume H, erw const_equiv p at H, exact one_ne_zero H },\n  rw dif_neg h,\n  simp,\nend\n\nlemma norm_eq_pow_val {x : \u211a_[p]} : x \u2260 0 \u2192 \u2225x\u2225 = p^(-x.valuation) :=\nbegin\n  apply quotient.induction_on' x, clear x,\n  intros f hf,\n  change (padic_seq.norm _ : \u211d) = (p : \u211d) ^ -padic_seq.valuation _,\n  rw padic_seq.norm_eq_pow_val,\n  change \u2191((p : \u211a) ^ -padic_seq.valuation f) = (p : \u211d) ^ -padic_seq.valuation f,\n  { rw rat.cast_zpow,\n    congr' 1,\n    norm_cast },\n  { apply cau_seq.not_lim_zero_of_not_congr_zero,\n    contrapose! hf,\n    apply quotient.sound,\n    simpa using hf, }\nend\n\n@[simp] lemma valuation_p : valuation (p : \u211a_[p]) = 1 :=\nbegin\n  have h : (1 : \u211d) < p := by exact_mod_cast (fact.out p.prime).one_lt,\n  rw \u2190 neg_inj,\n  apply (zpow_strict_mono h).injective,\n  dsimp only,\n  rw \u2190 norm_eq_pow_val,\n  { simp },\n  { exact_mod_cast (fact.out p.prime).ne_zero }\nend\n\nlemma valuation_map_add {x y : \u211a_[p]} (hxy : x + y \u2260 0) :\n  min (valuation x) (valuation y) \u2264 valuation (x + y) :=\nbegin\n  by_cases hx : x = 0,\n  { rw [hx, zero_add],\n    exact min_le_right _ _ },\n  { by_cases hy : y = 0,\n    { rw [hy, add_zero],\n      exact min_le_left _ _ },\n    { have h_norm : \u2225x + y\u2225 \u2264 (max \u2225x\u2225 \u2225y\u2225) := padic_norm_e.nonarchimedean x y,\n      have hp_one : (1 : \u211d) < p,\n      { rw [\u2190 nat.cast_one, nat.cast_lt],\n        exact nat.prime.one_lt hp_prime.elim, },\n      rw [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val hxy] at h_norm,\n      exact min_le_of_zpow_le_max hp_one h_norm }}\nend\n\n@[simp] lemma valuation_map_mul {x y : \u211a_[p]} (hx : x \u2260 0) (hy : y \u2260 0) :\n  valuation (x * y) = valuation x + valuation y :=\nbegin\n  have h_norm : \u2225x * y\u2225 = \u2225x\u2225 * \u2225y\u2225 := norm_mul x y,\n  have hp_ne_one : (p : \u211d) \u2260 1,\n  { rw [\u2190 nat.cast_one, ne.def, nat.cast_inj],\n    exact nat.prime.ne_one hp_prime.elim, },\n  have hp_pos : (0 : \u211d) < p,\n  { rw [\u2190 nat.cast_zero, nat.cast_lt],\n    exact nat.prime.pos hp_prime.elim },\n  rw [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val (mul_ne_zero hx hy),\n    \u2190 zpow_add\u2080 (ne_of_gt hp_pos), zpow_inj hp_pos hp_ne_one, \u2190 neg_add, neg_inj] at h_norm,\n  exact h_norm,\nend\n\n/-- The additive p-adic valuation on `\u211a_p`, with values in `with_top \u2124`. -/\ndef add_valuation_def : \u211a_[p] \u2192 (with_top \u2124) :=\n\u03bb x, if x = 0 then \u22a4 else x.valuation\n\n@[simp] lemma add_valuation.map_zero : add_valuation_def (0 : \u211a_[p]) = \u22a4 :=\nby simp only [add_valuation_def, if_pos (eq.refl _)]\n\n@[simp] lemma add_valuation.map_one : add_valuation_def (1 : \u211a_[p]) = 0 :=\nby simp only [add_valuation_def, if_neg (one_ne_zero), valuation_one,\n  with_top.coe_zero]\n\nlemma add_valuation.map_mul (x y : \u211a_[p]) :\n  add_valuation_def (x * y) = add_valuation_def x + add_valuation_def y :=\nbegin\n  simp only [add_valuation_def],\n  by_cases hx : x = 0,\n  { rw [hx, if_pos (eq.refl _), zero_mul, if_pos (eq.refl _), with_top.top_add] },\n  { by_cases hy : y = 0,\n    { rw [hy, if_pos (eq.refl _), mul_zero, if_pos (eq.refl _), with_top.add_top] },\n    { rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), \u2190 with_top.coe_add,\n        with_top.coe_eq_coe, valuation_map_mul hx hy] }}\nend\n\nlemma add_valuation.map_add (x y : \u211a_[p]) :\n  min (add_valuation_def x) (add_valuation_def y) \u2264 add_valuation_def (x + y) :=\nbegin\n  simp only [add_valuation_def],\n  by_cases hxy : x + y = 0,\n  { rw [hxy, if_pos (eq.refl _)],\n    exact le_top, },\n  { by_cases hx : x = 0,\n    { simp only [hx, if_pos (eq.refl _), min_eq_right, le_top, zero_add, le_refl] },\n    { by_cases hy : y = 0,\n      { simp only [hy, if_pos (eq.refl _), min_eq_left, le_top, add_zero, le_refl], },\n      { rw [if_neg hx, if_neg hy, if_neg hxy, \u2190 with_top.coe_min, with_top.coe_le_coe],\n        exact valuation_map_add hxy }}}\nend\n\n/-- The additive `p`-adic valuation on `\u211a_p`, as an `add_valuation`. -/\ndef add_valuation : add_valuation \u211a_[p] (with_top \u2124) :=\nadd_valuation.of add_valuation_def add_valuation.map_zero add_valuation.map_one\n  add_valuation.map_add add_valuation.map_mul\n\n@[simp] lemma add_valuation.apply {x : \u211a_[p]} (hx : x \u2260 0) :\n  x.add_valuation = x.valuation :=\nby simp only [add_valuation, add_valuation.of_apply, add_valuation_def, if_neg hx]\n\nsection norm_le_iff\n/-! ### Various characterizations of open unit balls -/\nlemma norm_le_pow_iff_norm_lt_pow_add_one (x : \u211a_[p]) (n : \u2124) :\n  \u2225x\u2225 \u2264 p ^ n \u2194 \u2225x\u2225 < p ^ (n + 1) :=\nbegin\n  have aux : \u2200 n : \u2124, 0 < (p ^ n : \u211d),\n  { apply nat.zpow_pos_of_pos, exact hp_prime.1.pos },\n  by_cases hx0 : x = 0, { simp [hx0, norm_zero, aux, le_of_lt (aux _)], },\n  rw norm_eq_pow_val hx0,\n  have h1p : 1 < (p : \u211d), { exact_mod_cast hp_prime.1.one_lt },\n  have H := zpow_strict_mono h1p,\n  rw [H.le_iff_le, H.lt_iff_lt, int.lt_add_one_iff],\nend\n\nlemma norm_lt_pow_iff_norm_le_pow_sub_one (x : \u211a_[p]) (n : \u2124) :\n  \u2225x\u2225 < p ^ n \u2194 \u2225x\u2225 \u2264 p ^ (n - 1) :=\nby rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel]\n\nend norm_le_iff\nend padic\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/number_theory/padics/padic_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.7224429779242024}}
{"text": "import data.real.basic\n\n/-!\n\n# Q3 \n\nTake bounded, nonempty `S, T \u2286 \u211d`.\nDefine `S + T := { s + t : s \u2208 S, t \u2208 T}`.\nProve `sup(S+T)  =  sup(S)+ sup(T)`\n\n-/\n\ntheorem is_lub_def {S : set \u211d} {a : \u211d} :\n  is_lub S a \u2194 a \u2208 upper_bounds S \u2227 \u2200 x, x \u2208 upper_bounds S \u2192 a \u2264 x :=\nbegin\n  refl\nend\n\n#check mem_upper_bounds -- a \u2208 upper_bounds S \u2194 \u2200 x, x \u2208 S \u2192 x \u2264 a\n\nexample (P Q : Prop) : P \u2192 Q \u2194 \u00ac Q \u2192 \u00ac P :=\nby library_search\n\ntheorem useful_lemma {S : set \u211d} {a : \u211d} (haS : is_lub S a) (t : \u211d)\n  (ht : t < a) : \u2203 s, s \u2208 S \u2227 t < s :=\nbegin\n  rw is_lub_def at haS,\n  cases haS with haS1 haS2,\n  specialize haS2 t,\n  replace haS2 := mt haS2,\n  push_neg at haS2,\n  specialize haS2 ht,\n  rw mem_upper_bounds at haS2, \n  push_neg at haS2,\n  exact haS2,\nend\n\n\nexample (S T : set \u211d) (a b : \u211d) :\n  is_lub S a \u2192 is_lub T b \u2192 is_lub (S + T) (a + b) :=\nbegin\n  intros hSa hTb,\n  rw is_lub_def,\n  split,\n  { rw mem_upper_bounds,\n    intro x,\n    intro hx,\n    rcases hx with \u27e8s, t, hsS, htT, rfl\u27e9,\n    rw is_lub_def at hSa hTb,\n    rcases hSa with \u27e8ha1, ha2\u27e9,\n    rcases hTb with \u27e8hb1, hb2\u27e9,\n    rw mem_upper_bounds at ha1 hb1,\n    specialize ha1 s hsS,\n    specialize hb1 t htT,\n    linarith,\n  },\n  { intro x,\n    intro hx,\n    rw mem_upper_bounds at hx,\n    by_contra,\n    push_neg at h,\n    set \u03b5 := a + b - x with h\u03b5,\n    have h\u03b52 : 0 < \u03b5,\n      linarith,\n    set a' := a - \u03b5/2 with ha',\n    set b' := b - \u03b5/2 with hb',\n    rcases useful_lemma hSa a' (by linarith) with \u27e8s', hs', hs'2\u27e9,\n    rcases useful_lemma hTb b' (by linarith) with \u27e8t', ht', ht'2\u27e9,\n    specialize hx (s' + t') \u27e8s', t', hs', ht', rfl\u27e9,\n    linarith,\n  }\nend\n\n/-!\n\n# Q6\n\n-/\n\n-- We introduce the usual mathematical notation for absolute value\nlocal notation `|` x `|` := abs x\n\ntheorem Q6a (x y : \u211d) : | x + y | \u2264 | x | + | y | :=\nbegin\n  -- Lean's definition of abs is abs x = max (x, -x)\n  -- [or max x (-x), as the computer scientists would write it]\n  unfold abs,\n  -- lean's definition of max a b is \"if a<=b then b else a\"\n  unfold max,\n  -- We now have a complicated statement with three \"if\"s in.\n  split_ifs,\n  -- We now have 2^3=8 goals corresponding to all the possibilities\n  -- x>=0 or x<0, y>=0 or y<0, (x+y)>=0 or (x+y)<0.\n  repeat {linarith},\n  -- all of them are easily solvable using the linarith tactic.\nend\n\n-- We can solve the remaining parts using part (a).\ntheorem Q6b (x y : \u211d) : |x + y| \u2265 |x| - |y| :=\nbegin\n  -- Apply Q6a to x+y and -y, then follow your nose.\n  have h := Q6a (x + y) (-y),\n  simp at h,\n  linarith,\nend\n\ntheorem Q6c (x y : \u211d) : |x + y| \u2265 |y| - |x| :=\nbegin\n  -- Apply Q6a to x+y and -x, then follow your nose.\n  have h := Q6a (x + y) (-x),\n  simp at h,\n  linarith,\nend\n\ntheorem Q6d (x y : \u211d) : |x - y| \u2265 | |x| - |y| | :=\nbegin\n  -- Lean prefers \u2264 to \u2265\n  show _ \u2264 _,\n  -- for this one we need to apply the result that |X| \u2264 B \u2194 -B \u2264 X and X \u2264 B \n  rw abs_le,\n  -- Now we have two goals:\n  -- first -|x - y| \u2264 |x| - |y|\n  -- and second |x| - |y| \u2264 |x - y|.\n  -- So we need to split.\n  split,\n  { -- -|x - y| \u2264 |x| - |y|\n    have h := Q6a (x - y) (-x),\n    simp [sub_eq_add_neg] at *,\n    linarith },\n  { -- |x| - |y| \u2264 |x - y|\n    have h := Q6a (x - y) y,\n    simp at *,\n    linarith}\nend\n\ntheorem Q6e (x y : \u211d) : |x| \u2264 |y| + |x - y| :=\nbegin\n  have h := Q6a y (x - y),\n  simp * at *,\nend\n\ntheorem Q6f (x y : \u211d) : |x| \u2265 |y| - |x - y| :=\nbegin\n  have h := Q6a (x - y) (-x),\n  simp [*, sub_eq_add_neg] at *,\nend\n\ntheorem Q1g (x y z : \u211d) : |x - y| \u2264 |x - z| + |y - z| :=\nbegin\n  have h := Q6a (x - z) (z - y),\n  -- Lean needs more hints with this one.\n  -- First let's change that y - z into z - y,\n  rw \u2190abs_neg (y - z),\n  -- now use automation\n  simp * at *,\n  convert h,\n  ring,\nend\n\n\n\n/-!\n\n# Q4\n\nFix `a \u2208 (0,\u221e)` and `n : \u2115`. We will prove\n`\u2203 x : \u211d, x^n = a`. \n\n-/\n\nsection Q4\n\nnoncomputable theory\n\nparameters {a : \u211d} (ha : 0 < a) {n : \u2115} (hn : 0 < n)\n\n/-\n1) Set `S\u2090 := {s \u2208 [0,\u221e) : s^n < a}` and show `S\u2090` is nonempty and\nbounded above, so we may define `x := sup S\u2090`.\n-/\n\ndef S := {s : \u211d | 0 \u2264 s \u2227 s ^ n < a}\n\ninclude ha hn\n\ntheorem part1 : (\u2203 s : \u211d, s \u2208 S) \u2227 (\u2203 B : \u211d, \u2200 s \u2208 S, s \u2264 B ) :=\nsorry\n\ndef x := Sup S\n\ntheorem is_lub_x : is_lub S x :=\nbegin\n  cases part1 with nonempty bdd,\n  cases nonempty with x hx,\n  cases bdd with y hy,\n  exact real.is_lub_Sup hx hy,\nend\n\n/-\n2) For `\u03b5 \u2208 (0,1)` show `(x+\u03b5)\u207f \u2264 x^n + \u03b5[(x + 1)\u207f \u2212 x\u207f].`\n(Hint: multiply out.)\n-/\n\nlemma x_nonneg : 0 \u2264 x :=\nbegin\n  rcases is_lub_x with \u27e8h, -\u27e9,\n  apply h,\n  split, refl,\n  convert ha,\n  simp [hn],\nend\n\ntheorem part2 (\u03b5 : \u211d) (h\u03b50 : 0 < \u03b5) (h\u03b51 : \u03b5 < 1) : (x + \u03b5)^n \u2264 x^n + \u03b5*((x+1)^n - x^n) :=\nbegin\n  sorry\nend\n\n/-\n3) Hence show that if `x\u207f < a` then\n`\u2203 \u03b5 \u2208 (0,1)` such that `(x+\u03b5)\u207f < a.` (*)\n-/\n\ntheorem part3 (h : x ^ n < a) : \u2203 \u03b5 : \u211d, 0 < \u03b5 \u2227 \u03b5 < 1 \u2227 (x+\u03b5)^n < a :=\nbegin\n  sorry\nend\n\n/-\n4) If `x\u207f > a`, deduce from (\u2217) that\n`\u2203 \u03b5 \u2208 (0,1)` such that `(1/x+\u03b5)\u207f < 1/a`. (\u2217\u2217)\n-/\n\n-- part 4 doesn't quite make sense because we didn't show x \u2260 0 yet\n\nlemma easy (h : a < x^n) : x \u2260 0 :=\nbegin\n  intro hx,\n  rw hx at h,\n  suffices : a < 0,\n    linarith,\n  convert h,\n  symmetry, -- ??\n  simp [hn],\nend\n\ntheorem part4 (h : a < x^n) : \u2203 \u03b5 : \u211d, 0 < \u03b5 \u2227 \u03b5 < 1 \u2227 (1/x + \u03b5)^n < 1/a :=\nbegin\n  sorry\nend\n\n/-\n5) Deduce contradictions from (\u2217) and (\u2217\u2217) to show that `x\u207f = a`.\n-/\n\ntheorem part5 : x^n = a :=\nbegin\n  sorry\nend\n\nend Q4", "meta": {"author": "ImperialCollegeLondon", "repo": "M40002", "sha": "a499db70323bd5ccae954c680ec9afbf15ffacca", "save_path": "github-repos/lean/ImperialCollegeLondon-M40002", "path": "github-repos/lean/ImperialCollegeLondon-M40002/M40002-a499db70323bd5ccae954c680ec9afbf15ffacca/src/solutions_sheet_two_old.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7224429778124158}}
{"text": "/-\nCopyright (c) 2022 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n\n! This file was ported from Lean 3 source module probability.conditional_expectation\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Probability.Notation\nimport Mathbin.Probability.Independence\nimport Mathbin.MeasureTheory.Function.ConditionalExpectation.Basic\n\n/-!\n\n# Probabilistic properties of the conditional expectation\n\nThis file contains some properties about the conditional expectation which does not belong in\nthe main conditional expectation file.\n\n## Main result\n\n* `measure_theory.condexp_indep_eq`: If `m\u2081, m\u2082` are independent \u03c3-algebras and `f` is a\n  `m\u2081`-measurable function, then `\ud835\udd3c[f | m\u2082] = \ud835\udd3c[f]` almost everywhere.\n\n-/\n\n\nopen TopologicalSpace Filter\n\nopen NNReal ENNReal MeasureTheory ProbabilityTheory BigOperators\n\nnamespace MeasureTheory\n\nopen ProbabilityTheory\n\nvariable {\u03a9 E : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] [CompleteSpace E]\n  {m\u2081 m\u2082 m : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} {f : \u03a9 \u2192 E}\n\n/-- If `m\u2081, m\u2082` are independent \u03c3-algebras and `f` is `m\u2081`-measurable, then `\ud835\udd3c[f | m\u2082] = \ud835\udd3c[f]`\nalmost everywhere. -/\ntheorem condexp_indepCat_eq (hle\u2081 : m\u2081 \u2264 m) (hle\u2082 : m\u2082 \u2264 m) [SigmaFinite (\u03bc.trim hle\u2082)]\n    (hf : strongly_measurable[m\u2081] f) (hindp : IndepCat m\u2081 m\u2082 \u03bc) : \u03bc[f|m\u2082] =\u1d50[\u03bc] fun x => \u03bc[f] :=\n  by\n  by_cases hfint : integrable f \u03bc\n  swap;\n  \u00b7 rw [condexp_undef hfint, integral_undef hfint]\n    rfl\n  have hfint\u2081 := hfint.trim hle\u2081 hf\n  refine'\n    (ae_eq_condexp_of_forall_set_integral_eq hle\u2082 hfint\n        (fun s _ hs => integrable_on_const.2 (Or.inr hs)) (fun s hms hs => _)\n        strongly_measurable_const.ae_strongly_measurable').symm\n  rw [set_integral_const]\n  rw [\u2190 mem_\u2112p_one_iff_integrable] at hfint\n  refine' hfint.induction_strongly_measurable hle\u2081 ENNReal.one_ne_top _ _ _ _ _ _\n  \u00b7 intro c t hmt ht\n    rw [integral_indicator (hle\u2081 _ hmt), set_integral_const, smul_smul, \u2190 ENNReal.toReal_mul,\n      mul_comm, \u2190 hindp _ _ hmt hms, set_integral_indicator (hle\u2081 _ hmt), set_integral_const,\n      Set.inter_comm]\n  \u00b7 intro u v hdisj huint hvint hu hv hu_eq hv_eq\n    rw [mem_\u2112p_one_iff_integrable] at huint hvint\n    rw [integral_add' huint hvint, smul_add, hu_eq, hv_eq,\n      integral_add' huint.integrable_on hvint.integrable_on]\n  \u00b7 have heq\u2081 :\n      (fun f : Lp_meas E \u211d m\u2081 1 \u03bc => \u222b x, f x \u2202\u03bc) =\n        (fun f : Lp E 1 \u03bc => \u222b x, f x \u2202\u03bc) \u2218 Submodule.subtypeL _ :=\n      by\n      refine' funext fun f => integral_congr_ae _\n      simp_rw [Submodule.coe_subtypeL', Submodule.coeSubtype, \u2190 coeFn_coeBase]\n    have heq\u2082 :\n      (fun f : Lp_meas E \u211d m\u2081 1 \u03bc => \u222b x in s, f x \u2202\u03bc) =\n        (fun f : Lp E 1 \u03bc => \u222b x in s, f x \u2202\u03bc) \u2218 Submodule.subtypeL _ :=\n      by\n      refine' funext fun f => integral_congr_ae (ae_restrict_of_ae _)\n      simp_rw [Submodule.coe_subtypeL', Submodule.coeSubtype, \u2190 coeFn_coeBase]\n      exact eventually_of_forall fun _ => rfl\n    refine' isClosed_eq (Continuous.const_smul _ _) _\n    \u00b7 rw [heq\u2081]\n      exact continuous_integral.comp (ContinuousLinearMap.continuous _)\n    \u00b7 rw [heq\u2082]\n      exact (continuous_set_integral _).comp (ContinuousLinearMap.continuous _)\n  \u00b7 intro u v huv huint hueq\n    rwa [\u2190 integral_congr_ae huv, \u2190\n      (set_integral_congr_ae (hle\u2082 _ hms) _ : (\u222b x in s, u x \u2202\u03bc) = \u222b x in s, v x \u2202\u03bc)]\n    filter_upwards [huv]with x hx _ using hx\n  \u00b7 exact \u27e8f, hf, eventually_eq.rfl\u27e9\n#align measure_theory.condexp_indep_eq MeasureTheory.condexp_indepCat_eq\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Probability/ConditionalExpectation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7224429774318677}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport logic.encodable.basic\nimport order.atoms\n\n/-!\n# Order ideals, cofinal sets, and the Rasiowa\u2013Sikorski lemma\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections require more\nstructure, such as a bottom element, a top element, or a join-semilattice structure.\n- `order.ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.\n  Dual to the notion of a filter on a preorder.\n- `order.is_ideal P`: a predicate for when a `set P` is an ideal.\n- `order.ideal.principal p`: the principal ideal generated by `p : P`.\n- `order.ideal.is_proper P`: a predicate for proper ideals.\n  Dual to the notion of a proper filter.\n- `order.ideal.is_maximal`: a predicate for maximal ideals.\n  Dual to the notion of an ultrafilter.\n- `ideal_Inter_nonempty P`: a predicate for when the intersection of all ideals of\n  `P` is nonempty.\n- `order.cofinal P`: the type of subsets of `P` containing arbitrarily large elements.\n  Dual to the notion of 'dense set' used in forcing.\n- `order.ideal_of_cofinals p \ud835\udc9f`, where `p : P`, and `\ud835\udc9f` is a countable family of cofinal\n  subsets of P: an ideal in `P` which contains `p` and intersects every set in `\ud835\udc9f`. (This a form\n  of the Rasiowa\u2013Sikorski lemma.)\n\n## References\n\n- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>\n- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>\n- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>\n\nNote that for the Rasiowa\u2013Sikorski lemma, Wikipedia uses the opposite ordering on `P`,\nin line with most presentations of forcing.\n\n## TODO\n\n`order.ideal.ideal_Inter_nonempty` is a complicated way to say that `P` has a bottom element. It\nshould be replaced by this clearer condition, which could be called strong directedness and which\nis a Prop version of `order_bot`.\n\n## Tags\n\nideal, cofinal, dense, countable, generic\n\n-/\n\nopen function\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- An ideal on an order `P` is a subset of `P` that is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\nstructure ideal (P) [has_le P] :=\n(carrier   : set P)\n(nonempty  : carrier.nonempty)\n(directed  : directed_on (\u2264) carrier)\n(mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 y \u2208 carrier \u2192 x \u2208 carrier)\n\n/-- A subset of a preorder `P` is an ideal if it is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\n@[mk_iff] structure is_ideal {P} [has_le P] (I : set P) : Prop :=\n(nonempty : I.nonempty)\n(directed : directed_on (\u2264) I)\n(mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 y \u2208 I \u2192 x \u2208 I)\n\nattribute [protected] ideal.nonempty ideal.directed is_ideal.nonempty is_ideal.directed\n\n/-- Create an element of type `order.ideal` from a set satisfying the predicate\n`order.is_ideal`. -/\ndef is_ideal.to_ideal [has_le P] {I : set P} (h : is_ideal I) : ideal P :=\n\u27e8I, h.1, h.2, h.3\u27e9\n\nnamespace ideal\nsection has_le\nvariables [has_le P] {I J : ideal P} {x y : P}\n\n/-- An ideal of `P` can be viewed as a subset of `P`. -/\ninstance : has_coe (ideal P) (set P) := \u27e8carrier\u27e9\n\n/-- For the notation `x \u2208 I`. -/\ninstance : has_mem P (ideal P) := \u27e8\u03bb x I, x \u2208 (I : set P)\u27e9\n\n@[simp] lemma mem_coe : x \u2208 (I : set P) \u2194 x \u2208 I := iff_of_eq rfl\n\n/-- Two ideals are equal when their underlying sets are equal. -/\n@[ext] lemma ext : \u2200 {I J : ideal P}, (I : set P) = J \u2192 I = J\n| \u27e8_, _, _, _\u27e9 \u27e8_, _, _, _\u27e9 rfl := rfl\n\nlemma coe_injective : injective (coe : ideal P \u2192 set P) := \u03bb _ _, ext\n\n@[simp, norm_cast] lemma coe_inj : (I : set P) = J \u2194 I = J := \u27e8by ext, congr_arg _\u27e9\n\nlemma ext_iff : I = J \u2194 (I : set P) = J := coe_inj.symm\n\nprotected lemma is_ideal (I : ideal P) : is_ideal (I : set P) := \u27e8I.2, I.3, I.4\u27e9\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (ideal P) := partial_order.lift coe coe_injective\n\n@[trans] lemma mem_of_mem_of_le : x \u2208 I \u2192 I \u2264 J \u2192 x \u2208 J :=\n@set.mem_of_mem_of_subset P x I J\n\n/-- A proper ideal is one that is not the whole set.\n    Note that the whole set might not be an ideal. -/\n@[mk_iff] class is_proper (I : ideal P) : Prop := (ne_univ : (I : set P) \u2260 set.univ)\n\nlemma is_proper_of_not_mem {I : ideal P} {p : P} (nmem : p \u2209 I) : is_proper I :=\n\u27e8\u03bb hp, begin\n  change p \u2209 \u2191I at nmem,\n  rw hp at nmem,\n  exact nmem (set.mem_univ p),\nend\u27e9\n\n/-- An ideal is maximal if it is maximal in the collection of proper ideals.\n\nNote that `is_coatom` is less general because ideals only have a top element when `P` is directed\nand nonempty. -/\n@[mk_iff] class is_maximal (I : ideal P) extends is_proper I : Prop :=\n(maximal_proper : \u2200 \u2983J : ideal P\u2984, I < J \u2192 (J : set P) = set.univ)\n\nvariable (P)\n\n/-- An order `P` has the `ideal_Inter_nonempty` property if the intersection of all ideals is\nnonempty. Most importantly, the ideals of a `semilattice_sup` with this property form a complete\nlattice.\n\nTODO: This is equivalent to the existence of a bottom element and shouldn't be specialized to\nideals. -/\nclass ideal_Inter_nonempty : Prop :=\n(Inter_nonempty : (\u22c2 (I : ideal P), (I : set P)).nonempty)\n\nvariable {P}\n\nlemma Inter_nonempty [ideal_Inter_nonempty P] :\n  (\u22c2 (I : ideal P), (I : set P)).nonempty :=\nideal_Inter_nonempty.Inter_nonempty\n\nlemma ideal_Inter_nonempty.exists_all_mem [ideal_Inter_nonempty P] :\n  \u2203 a : P, \u2200 I : ideal P, a \u2208 I :=\nbegin\n  change \u2203 (a : P), \u2200 (I : ideal P), a \u2208 (I : set P),\n  rw \u2190 set.nonempty_Inter,\n  exact Inter_nonempty,\nend\n\nlemma ideal_Inter_nonempty_of_exists_all_mem (h : \u2203 a : P, \u2200 I : ideal P, a \u2208 I) :\n  ideal_Inter_nonempty P :=\n{ Inter_nonempty := by rwa set.nonempty_Inter }\n\nlemma ideal_Inter_nonempty_iff :\n  ideal_Inter_nonempty P \u2194 \u2203 a : P, \u2200 I : ideal P, a \u2208 I :=\n\u27e8\u03bb _, by exactI ideal_Inter_nonempty.exists_all_mem, ideal_Inter_nonempty_of_exists_all_mem\u27e9\n\nlemma inter_nonempty [is_directed P (swap (\u2264))] (I J : ideal P) : (I \u2229 J : set P).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 := I.nonempty,\n  obtain \u27e8b, hb\u27e9 := J.nonempty,\n  obtain \u27e8c, hac, hbc\u27e9 := directed_of (swap (\u2264)) a b,\n  exact \u27e8c, I.mem_of_le hac ha, J.mem_of_le hbc hb\u27e9,\nend\n\nend has_le\n\nsection preorder\nvariables [preorder P] {I J : ideal P} {x y : P}\n\n/-- The smallest ideal containing a given element. -/\ndef principal (p : P) : ideal P :=\n{ carrier   := { x | x \u2264 p },\n  nonempty  := \u27e8p, le_rfl\u27e9,\n  directed  := \u03bb x hx y hy, \u27e8p, le_rfl, hx, hy\u27e9,\n  mem_of_le := \u03bb x y hxy hy, le_trans hxy hy, }\n\ninstance [inhabited P] : inhabited (ideal P) := \u27e8ideal.principal default\u27e9\n\n@[simp] lemma principal_le_iff : principal x \u2264 I \u2194 x \u2208 I :=\n\u27e8\u03bb (h : \u2200 {y}, y \u2264 x \u2192 y \u2208 I), h (le_refl x),\n \u03bb h_mem y (h_le : y \u2264 x), I.mem_of_le h_le h_mem\u27e9\n\n@[simp] lemma mem_principal : x \u2208 principal y \u2194 x \u2264 y := iff.rfl\n\nlemma mem_compl_of_ge {x y : P} : x \u2264 y \u2192 x \u2208 (I : set P)\u1d9c \u2192 y \u2208 (I : set P)\u1d9c :=\n\u03bb h, mt (I.mem_of_le h)\n\nend preorder\n\nsection order_bot\n\n/-- A specific witness of `I.nonempty` when `P` has a bottom element. -/\n@[simp] lemma bot_mem [has_le P] [order_bot P] {I : ideal P} : \u22a5 \u2208 I :=\nI.mem_of_le bot_le I.nonempty.some_mem\n\nvariables [preorder P] [order_bot P] {I : ideal P}\n\n/-- There is a bottom ideal when `P` has a bottom element. -/\ninstance : order_bot (ideal P) :=\n{ bot := principal \u22a5,\n  bot_le := by simp }\n\n@[priority 100]\ninstance order_bot.ideal_Inter_nonempty : ideal_Inter_nonempty P :=\nby { rw ideal_Inter_nonempty_iff, exact \u27e8\u22a5, \u03bb I, bot_mem\u27e9 }\n\nend order_bot\n\nsection directed\nvariables [has_le P] [is_directed P (\u2264)] [nonempty P] {I : ideal P}\n\n/-- In a directed and nonempty order, the top ideal of a is `set.univ`. -/\ninstance : order_top (ideal P) :=\n{ top := { carrier := set.univ,\n           nonempty := set.univ_nonempty,\n           directed := directed_on_univ,\n           mem_of_le := \u03bb _ _ _ _, trivial },\n  le_top := \u03bb I, le_top }\n\n@[simp] lemma coe_top : ((\u22a4 : ideal P) : set P) = set.univ := rfl\n\nlemma is_proper_of_ne_top (ne_top : I \u2260 \u22a4) : is_proper I := \u27e8\u03bb h, ne_top $ ext h\u27e9\n\nlemma is_proper.ne_top (hI : is_proper I) : I \u2260 \u22a4 :=\nbegin\n  intro h,\n  rw [ext_iff, coe_top] at h,\n  apply hI.ne_univ,\n  assumption,\nend\n\nlemma _root_.is_coatom.is_proper (hI : is_coatom I) : is_proper I := is_proper_of_ne_top hI.1\n\nlemma is_proper_iff_ne_top : is_proper I \u2194 I \u2260 \u22a4 := \u27e8\u03bb h, h.ne_top, \u03bb h, is_proper_of_ne_top h\u27e9\n\nlemma is_maximal.is_coatom (h : is_maximal I) : is_coatom I :=\n\u27e8is_maximal.to_is_proper.ne_top,\n  \u03bb _ _, by { rw [ext_iff, coe_top], exact is_maximal.maximal_proper \u2039_\u203a }\u27e9\n\nlemma is_maximal.is_coatom' [is_maximal I] : is_coatom I := is_maximal.is_coatom \u2039_\u203a\n\nlemma _root_.is_coatom.is_maximal (hI : is_coatom I) : is_maximal I :=\n{ maximal_proper := \u03bb _ _, by simp [hI.2 _ \u2039_\u203a],\n  ..is_coatom.is_proper \u2039_\u203a }\n\nlemma is_maximal_iff_is_coatom : is_maximal I \u2194 is_coatom I := \u27e8\u03bb h, h.is_coatom, \u03bb h, h.is_maximal\u27e9\n\nend directed\n\nsection order_top\nvariables [has_le P] [order_top P] {I : ideal P}\n\nlemma top_of_top_mem (hI : \u22a4 \u2208 I) : I = \u22a4 :=\nby { ext, exact iff_of_true (I.mem_of_le le_top hI) trivial }\n\nlemma is_proper.top_not_mem (hI : is_proper I) : \u22a4 \u2209 I := \u03bb h, hI.ne_top $ top_of_top_mem h\n\nend order_top\n\nsection semilattice_sup\nvariables [semilattice_sup P] {x y : P} {I : ideal P}\n\n/-- A specific witness of `I.directed` when `P` has joins. -/\nlemma sup_mem (x y \u2208 I) : x \u2294 y \u2208 I :=\nlet \u27e8z, h_mem, hx, hy\u27e9 := I.directed x \u2039_\u203a y \u2039_\u203a in\nI.mem_of_le (sup_le hx hy) h_mem\n\n@[simp] lemma sup_mem_iff : x \u2294 y \u2208 I \u2194 x \u2208 I \u2227 y \u2208 I :=\n\u27e8\u03bb h, \u27e8I.mem_of_le le_sup_left h, I.mem_of_le le_sup_right h\u27e9,\n \u03bb h, sup_mem x h.left y h.right\u27e9\n\nend semilattice_sup\n\nsection semilattice_sup_directed\nvariables [semilattice_sup P] [is_directed P (swap (\u2264))] {x : P} {I J K : ideal P}\n\n/-- The infimum of two ideals of a co-directed order is their intersection. -/\ninstance : has_inf (ideal P) :=\n\u27e8\u03bb I J, { carrier   := I \u2229 J,\n  nonempty  := inter_nonempty I J,\n  directed  := \u03bb x \u27e8_, _\u27e9 y \u27e8_, _\u27e9, \u27e8x \u2294 y, \u27e8sup_mem x \u2039_\u203a y \u2039_\u203a, sup_mem x \u2039_\u203a y \u2039_\u203a\u27e9, by simp\u27e9,\n  mem_of_le := \u03bb x y h \u27e8_, _\u27e9, \u27e8mem_of_le I h \u2039_\u203a, mem_of_le J h \u2039_\u203a\u27e9 }\u27e9\n\n/-- The supremum of two ideals of a co-directed order is the union of the down sets of the pointwise\nsupremum of `I` and `J`. -/\ninstance : has_sup (ideal P) :=\n\u27e8\u03bb I J, { carrier   := {x | \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j},\n  nonempty  := by { cases inter_nonempty I J, exact \u27e8w, w, h.1, w, h.2, le_sup_left\u27e9 },\n  directed  := \u03bb x \u27e8xi, _, xj, _, _\u27e9 y \u27e8yi, _, yj, _, _\u27e9,\n    \u27e8x \u2294 y,\n     \u27e8xi \u2294 yi, sup_mem xi \u2039_\u203a yi \u2039_\u203a,\n      xj \u2294 yj, sup_mem xj \u2039_\u203a yj \u2039_\u203a,\n      sup_le\n        (calc x \u2264 xi \u2294 xj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_left le_sup_left)\n        (calc y \u2264 yi \u2294 yj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_right le_sup_right)\u27e9,\n     le_sup_left, le_sup_right\u27e9,\n  mem_of_le := \u03bb x y _ \u27e8yi, _, yj, _, _\u27e9, \u27e8yi, \u2039_\u203a, yj, \u2039_\u203a, le_trans \u2039x \u2264 y\u203a \u2039_\u203a\u27e9 }\u27e9\n\ninstance : lattice (ideal P) :=\n{ sup          := (\u2294),\n  le_sup_left  := \u03bb I J (i \u2208 I), by { cases J.nonempty, exact \u27e8i, \u2039_\u203a, w, \u2039_\u203a, le_sup_left\u27e9 },\n  le_sup_right := \u03bb I J (j \u2208 J), by { cases I.nonempty, exact \u27e8w, \u2039_\u203a, j, \u2039_\u203a, le_sup_right\u27e9 },\n  sup_le       := \u03bb I J K hIK hJK a \u27e8i, hi, j, hj, ha\u27e9,\n    K.mem_of_le ha $ sup_mem i (mem_of_mem_of_le hi hIK) j (mem_of_mem_of_le hj hJK),\n  inf          := (\u2293),\n  inf_le_left  := \u03bb I J, set.inter_subset_left I J,\n  inf_le_right := \u03bb I J, set.inter_subset_right I J,\n  le_inf       := \u03bb I J K, set.subset_inter,\n  .. ideal.partial_order }\n\n@[simp] lemma mem_inf : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J := iff.rfl\n@[simp] lemma mem_sup : x \u2208 I \u2294 J \u2194 \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j := iff.rfl\n\nlemma lt_sup_principal_of_not_mem (hx : x \u2209 I) : I < I \u2294 principal x :=\nle_sup_left.lt_of_ne $ \u03bb h, hx $ by simpa only [left_eq_sup, principal_le_iff] using h\n\nend semilattice_sup_directed\n\nsection ideal_Inter_nonempty\n\nvariables [preorder P] [ideal_Inter_nonempty P]\n\n@[priority 100]\ninstance ideal_Inter_nonempty.to_directed_ge : is_directed P (swap (\u2264)) :=\n\u27e8\u03bb a b, begin\n    obtain \u27e8c, hc\u27e9 : \u2203 a, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n    exact \u27e8c, hc (principal a), hc (principal b)\u27e9,\n  end\u27e9\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*} {\u03b9 : Sort*}\n\nlemma ideal_Inter_nonempty.all_Inter_nonempty {f : \u03b9 \u2192 ideal P} :\n  (\u22c2 x, (f x : set P)).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 : \u2203 a : P, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n  exact \u27e8a, by simp [ha]\u27e9\nend\n\nlemma ideal_Inter_nonempty.all_bInter_nonempty {f : \u03b1 \u2192 ideal P} {s : set \u03b1} :\n  (\u22c2 x \u2208 s, (f x : set P)).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 : \u2203 a : P, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n  exact \u27e8a, by simp [ha]\u27e9\nend\n\nend ideal_Inter_nonempty\n\nsection semilattice_sup_ideal_Inter_nonempty\n\nvariables [semilattice_sup P] [ideal_Inter_nonempty P] {x : P} {I J K : ideal P}\n\ninstance : has_Inf (ideal P) :=\n{ Inf := \u03bb s, { carrier := \u22c2 (I \u2208 s), (I : set P),\n  nonempty := ideal_Inter_nonempty.all_bInter_nonempty,\n  directed := \u03bb x hx y hy, \u27e8x \u2294 y, \u27e8\u03bb S \u27e8I, hS\u27e9,\n    begin\n      simp only [\u2190hS, sup_mem_iff, mem_coe, set.mem_Inter],\n      intro hI,\n      rw set.mem_Inter\u2082 at *,\n      exact \u27e8hx _ hI, hy _ hI\u27e9\n    end,\n    le_sup_left, le_sup_right\u27e9\u27e9,\n  mem_of_le := \u03bb x y hxy hy,\n    begin\n      rw set.mem_Inter\u2082 at *,\n      exact \u03bb I hI, mem_of_le I \u2039_\u203a (hy I hI)\n    end } }\n\nvariables {s : set (ideal P)}\n\n@[simp] lemma mem_Inf : x \u2208 Inf s \u2194 \u2200 I \u2208 s, x \u2208 I :=\nby { change x \u2208 (\u22c2 (I \u2208 s), (I : set P)) \u2194 \u2200 I \u2208 s, x \u2208 I, simp }\n\n@[simp] lemma coe_Inf : \u2191(Inf s) = \u22c2 (I \u2208 s), (I : set P) := rfl\n\nlemma Inf_le (hI : I \u2208 s) : Inf s \u2264 I :=\n\u03bb _ hx, hx I \u27e8I, by simp [hI]\u27e9\n\nlemma le_Inf (h : \u2200 J \u2208 s, I \u2264 J) : I \u2264 Inf s :=\n\u03bb _ _, by { simp only [mem_coe, coe_Inf, set.mem_Inter], tauto }\n\nlemma is_glb_Inf : is_glb s (Inf s) := \u27e8\u03bb _, Inf_le, \u03bb _, le_Inf\u27e9\n\ninstance : complete_lattice (ideal P) :=\n{ ..ideal.lattice,\n  ..complete_lattice_of_Inf (ideal P) (\u03bb _, @is_glb_Inf _ _ _ _) }\n\nend semilattice_sup_ideal_Inter_nonempty\n\nsection distrib_lattice\n\nvariables [distrib_lattice P]\nvariables {I J : ideal P}\n\nlemma eq_sup_of_le_sup {x i j: P} (hi : i \u2208 I) (hj : j \u2208 J) (hx : x \u2264 i \u2294 j) :\n  \u2203 (i' \u2208 I) (j' \u2208 J), x = i' \u2294 j' :=\nbegin\n  refine \u27e8x \u2293 i, I.mem_of_le inf_le_right hi, x \u2293 j, J.mem_of_le inf_le_right hj, _\u27e9,\n  calc\n  x    = x \u2293 (i \u2294 j)       : left_eq_inf.mpr hx\n  ...  = (x \u2293 i) \u2294 (x \u2293 j) : inf_sup_left,\nend\n\nlemma coe_sup_eq : \u2191(I \u2294 J) = {x | \u2203 i \u2208 I, \u2203 j \u2208 J, x = i \u2294 j} :=\nbegin\n  ext,\n  rw [mem_coe, mem_sup],\n  exact \u27e8\u03bb \u27e8_, _, _, _, _\u27e9, eq_sup_of_le_sup \u2039_\u203a \u2039_\u203a \u2039_\u203a,\n  \u03bb \u27e8i, _, j, _, _\u27e9, \u27e8i, \u2039_\u203a, j, \u2039_\u203a, le_of_eq \u2039_\u203a\u27e9\u27e9\nend\n\nend distrib_lattice\n\nsection boolean_algebra\n\nvariables [boolean_algebra P] {x : P} {I : ideal P}\n\nlemma is_proper.not_mem_of_compl_mem (hI : is_proper I) (hxc : x\u1d9c \u2208 I) : x \u2209 I :=\nbegin\n  intro hx,\n  apply hI.top_not_mem,\n  have ht : x \u2294 x\u1d9c \u2208 I := sup_mem _ \u2039_\u203a _ \u2039_\u203a,\n  rwa sup_compl_eq_top at ht,\nend\n\nlemma is_proper.not_mem_or_compl_not_mem (hI : is_proper I) : x \u2209 I \u2228 x\u1d9c \u2209 I :=\nhave h : x\u1d9c \u2208 I \u2192 x \u2209 I := hI.not_mem_of_compl_mem, by tauto\n\nend boolean_algebra\n\nend ideal\n\n/-- For a preorder `P`, `cofinal P` is the type of subsets of `P`\n  containing arbitrarily large elements. They are the dense sets in\n  the topology whose open sets are terminal segments. -/\nstructure cofinal (P) [preorder P] :=\n(carrier : set P)\n(mem_gt  : \u2200 x : P, \u2203 y \u2208 carrier, x \u2264 y)\n\nnamespace cofinal\n\nvariables [preorder P]\n\ninstance : inhabited (cofinal P) :=\n\u27e8{ carrier := set.univ, mem_gt := \u03bb x, \u27e8x, trivial, le_rfl\u27e9 }\u27e9\n\ninstance : has_mem P (cofinal P) := \u27e8\u03bb x D, x \u2208 D.carrier\u27e9\n\nvariables (D : cofinal P) (x : P)\n/-- A (noncomputable) element of a cofinal set lying above a given element. -/\nnoncomputable def above : P := classical.some $ D.mem_gt x\n\nlemma above_mem : D.above x \u2208 D :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb a _, a\n\nlemma le_above : x \u2264 D.above x :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb _ b, b\n\nend cofinal\n\nsection ideal_of_cofinals\n\nvariables [preorder P] (p : P) {\u03b9 : Type*} [encodable \u03b9] (\ud835\udc9f : \u03b9 \u2192 cofinal P)\n\n/-- Given a starting point, and a countable family of cofinal sets,\n  this is an increasing sequence that intersects each cofinal set. -/\nnoncomputable def sequence_of_cofinals : \u2115 \u2192 P\n| 0 := p\n| (n+1) := match encodable.decode \u03b9 n with\n           | none   := sequence_of_cofinals n\n           | some i := (\ud835\udc9f i).above (sequence_of_cofinals n)\n           end\n\nlemma sequence_of_cofinals.monotone : monotone (sequence_of_cofinals p \ud835\udc9f) :=\nby { apply monotone_nat_of_le_succ, intros n, dunfold sequence_of_cofinals,\n  cases encodable.decode \u03b9 n, { refl }, { apply cofinal.le_above }, }\n\nlemma sequence_of_cofinals.encode_mem (i : \u03b9) :\n  sequence_of_cofinals p \ud835\udc9f (encodable.encode i + 1) \u2208 \ud835\udc9f i :=\nby { dunfold sequence_of_cofinals, rw encodable.encodek, apply cofinal.above_mem, }\n\n/-- Given an element `p : P` and a family `\ud835\udc9f` of cofinal subsets of a preorder `P`,\n  indexed by a countable type, `ideal_of_cofinals p \ud835\udc9f` is an ideal in `P` which\n  - contains `p`, according to `mem_ideal_of_cofinals p \ud835\udc9f`, and\n  - intersects every set in `\ud835\udc9f`, according to `cofinal_meets_ideal_of_cofinals p \ud835\udc9f`.\n\n  This proves the Rasiowa\u2013Sikorski lemma. -/\ndef ideal_of_cofinals : ideal P :=\n{ carrier   := { x : P | \u2203 n, x \u2264 sequence_of_cofinals p \ud835\udc9f n },\n  nonempty  := \u27e8p, 0, le_rfl\u27e9,\n  directed  := \u03bb x \u27e8n, hn\u27e9 y \u27e8m, hm\u27e9,\n               \u27e8_, \u27e8max n m, le_rfl\u27e9,\n               le_trans hn $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_left _ _),\n               le_trans hm $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_right _ _) \u27e9,\n  mem_of_le := \u03bb x y hxy \u27e8n, hn\u27e9, \u27e8n, le_trans hxy hn\u27e9, }\n\nlemma mem_ideal_of_cofinals : p \u2208 ideal_of_cofinals p \ud835\udc9f := \u27e80, le_rfl\u27e9\n\n/-- `ideal_of_cofinals p \ud835\udc9f` is `\ud835\udc9f`-generic. -/\nlemma cofinal_meets_ideal_of_cofinals (i : \u03b9) : \u2203 x : P, x \u2208 \ud835\udc9f i \u2227 x \u2208 ideal_of_cofinals p \ud835\udc9f :=\n\u27e8_, sequence_of_cofinals.encode_mem p \ud835\udc9f i, _, le_rfl\u27e9\n\nend ideal_of_cofinals\n\nend order\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/order/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7224429754173397}}
{"text": "-- Las_clases_de_equivalencia_son_no_vacias.lean\n-- Las clases de equivalencia son no vac\u00edas\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 5 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Este ejercicio es el 6\u00ba de una serie, que comenz\u00f3 con el [ejercicio\n-- del 30 de septiembre](https://bit.ly/2YfsvBZ), cuyo objetivo es\n-- demostrar que el tipo de las particiones de un conjunto `X` es\n-- isomorfo al tipo de las relaciones de equivalencia sobre `X`.\n--\n-- El conjuntos de las clases correspondientes a una relaci\u00f3n R se\n-- define en Lean por\n --    def clases : (A \u2192 A \u2192 Prop) \u2192 set (set A) :=\n --      \u03bb R, {B : set A | \u2203 x : A, B = clase R x}\n--\n-- El ejercicio consiste en demostrar que si C es una clase de\n-- equivalencia de R, entonces C es no vac\u00eda.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\nvariable {A : Type}\nvariable (R : A \u2192 A \u2192 Prop)\n\ndef clase (a : A) :=\n  {b : A | R b a}\n\ndef clases : (A \u2192 A \u2192 Prop) \u2192 set (set A) :=\n  \u03bb R, {B : set A | \u2203 x : A, B = clase R x}\n\n-- Se usar\u00e1 el siguientes lema auxiliar\nlemma pertenece_clase_syss\n  {a b : A}\n  : b \u2208 clase R a \u2194 R b a :=\nby refl\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (hR: equivalence R)\n  : \u2200 (X : set A), X \u2208 clases R \u2192 X.nonempty :=\nbegin\n  intros X hX,\n  unfold clases at hX,\n  dsimp at hX,\n  cases hX with a ha,\n  rw ha,\n  rw set.nonempty_def,\n  use a,\n  rw pertenece_clase_syss,\n  rcases hR with \u27e8hrefl, -, -\u27e9,\n  exact hrefl a,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (hR: equivalence R)\n  : \u2200 (X : set A), X \u2208 clases R \u2192 X.nonempty :=\nbegin\n  rintros _ \u27e8a, rfl\u27e9,\n  use a,\n  rw pertenece_clase_syss,\n  exact hR.1 a,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (hR: equivalence R)\n  : \u2200 (X : set A), X \u2208 clases R \u2192 X.nonempty :=\nbegin\n  rintros _ \u27e8a, rfl\u27e9,\n  use a,\n  rw pertenece_clase_syss,\n  apply hR.1,\nend\n\n-- 4\u00aa demostraci\u00f3n\nlemma clases_no_vacias\n  (hR: equivalence R)\n  : \u2200 (X : set A), X \u2208 clases R \u2192 X.nonempty :=\nbegin\n  rintros _ \u27e8a, rfl\u27e9,\n  use a,\n  exact (pertenece_clase_syss R).mpr (hR.1 a),\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Las_clases_de_equivalencia_son_no_vacias.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516187, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7224284931277968}}
{"text": "import data.real.basic\n\ntheorem BMO_Problem_2_2007.lean (f : \u211d -> \u211d) : (\u2200 x y : \u211d, f(f(x)+y) = f(f(x) -y) + 4*f(x)*y) \n\u2192 (f = 0 \u2228 (\u2203 c : \u211d, \u2200 x : \u211d, f(x) = x^2 +c)) := sorry", "meta": {"author": "ahayat16", "repo": "lean_exos", "sha": "682f2552d5b04a8c8eb9e4ab15f875a91b03845c", "save_path": "github-repos/lean/ahayat16-lean_exos", "path": "github-repos/lean/ahayat16-lean_exos/lean_exos-682f2552d5b04a8c8eb9e4ab15f875a91b03845c/src_icannos_totilas/aops/2007-BMO-Problem_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7224281271326738}}
{"text": "import data.real.basic\n\n\ndef fn_lb (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, a \u2264 f x\ndef fn_has_lb (f : \u211d \u2192 \u211d) := \u2203 a, fn_lb f a\n\nvariable f : \u211d \u2192 \u211d\n\n-- BEGIN\nexample (h : \u2200 a, \u2203 x, f x < a) : \u00ac fn_has_lb f :=\nbegin\n  intro fnlb,\n  cases fnlb with a fnlba,\n  cases h a with x hx,\n  have : f x \u2265 a,\n    from fnlba x,\n  linarith,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.1_cases_exist/ex5_cases_not_fn_has_lb.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7224281251840805}}
{"text": "import data.real.basic tactic.norm_num data.nat.basic data.complex algebra.big_operators data.set.finite tactic.ring\nopen real nat\nnoncomputable theory\nlocal attribute [instance, priority 0] classical.prop_decidable\nuniverse u\n\nlemma pow_inv' {\u03b1 : Type u} [discrete_field \u03b1] (a : \u03b1) (n : \u2115) : (monoid.pow a n)\u207b\u00b9 = monoid.pow a\u207b\u00b9 n := begin\n  induction n with n' hi,\n  simp[monoid.pow],\n  simp[monoid.pow],rw [mul_inv',mul_comm,hi],\nend\n\nlemma pow_abs {\u03b1 : Type u} [decidable_linear_ordered_comm_ring \u03b1] (a : \u03b1) (n : \u2115) : monoid.pow (abs a) n = abs (monoid.pow a n) := begin\n  induction n with n' hi,\n  simp!, simp!,rw [hi,abs_mul],\nend\n\nlemma pow_incrs_of_gt_one {\u03b1 : Type u}  [linear_ordered_semiring \u03b1] {x : \u03b1} {n m : \u2115} : 1 < x \u2192 n < m \u2192 monoid.pow x n < monoid.pow x m := begin\n  assume x1 nm,revert n,\n  induction m with m' hi,assume n nm,\n  exact absurd nm (not_lt_of_ge (zero_le n)),assume n nm,\n  cases m' with m'',\n  rw eq_zero_of_le_zero (le_of_lt_succ nm),simpa!,\n  cases n with n',\n  simp!, simp! at hi,\n  rw \u2190one_mul (1 : \u03b1),\n  refine mul_lt_mul x1 (le_of_lt (@hi 0 dec_trivial)) (by norm_num) (le_of_lt(lt_trans (by norm_num) x1)),\n  have hi' := @hi n' (lt_of_succ_lt_succ nm),\n  suffices : x * monoid.pow x n' < x * monoid.pow x (succ m''),\n    simpa [monoid.pow],\n  refine mul_lt_mul' (le_refl x) hi' _ (lt_trans (by norm_num) x1),\n  clear hi hi' nm m'',\n  induction n' with n'' hi,\n  simp!,norm_num,\n  simp!,refine mul_nonneg (le_of_lt (lt_trans (by norm_num) x1)) hi,\nend\n\nlemma pow_dcrs_of_lt_one_of_pos {\u03b1 : Type u}  [discrete_linear_ordered_field \u03b1] {x : \u03b1} {n m : \u2115} : x < 1 \u2192 0 < x \u2192 n < m \u2192 monoid.pow x m < monoid.pow x n := begin\n  assume x1 x0 nm,rw [\u2190inv_lt_inv,pow_inv',pow_inv'],\n  have x11 : 1 < x\u207b\u00b9 ,rw lt_inv,simpa,{norm_num},exact x0,\n  refine pow_incrs_of_gt_one x11 nm,\n  refine pow_pos x0 _,refine pow_pos x0 _,\nend\n\nlemma pow_unbounded_of_gt_one {x : \u211d} (y : \u211d) : 1 < x \u2192 \u2203 n : \u2115, y < monoid.pow x n := begin\n  assume x1,\n  have : \u2200 m : \u2115, (x - 1) * m < monoid.pow x m \u2227 1 \u2264 monoid.pow x m,\n    assume m, induction m with m' hi,\n    simp,{norm_num},\n    rw [\u2190add_one,nat.cast_add,nat.cast_one], simp only [mul_add,monoid.pow],rw mul_one,\n    have : x * monoid.pow x m' = monoid.pow x m' + (x - 1) * monoid.pow x m',\n      rw add_comm,simp[mul_add,add_mul],\n    rw this,split,\n    refine add_lt_add_of_lt_of_le hi.left _,rw \u2190sub_pos at x1,\n    have :=mul_le_mul (le_refl (x - 1)) hi.right (by norm_num) (le_of_lt x1),rwa mul_one at this,\n    rw [\u2190this, \u2190one_mul (1 : \u211d)],\n    exact mul_le_mul (le_of_lt x1) hi.right (by norm_num) (le_of_lt (lt_trans (by norm_num) x1)),\n  cases exists_nat_gt (y / (x - 1)) with n hn,\n  existsi n,rw [div_lt_iff,mul_comm] at hn,\n  exact lt_trans hn (this n).left,rwa sub_pos,\nend\n\ndef sum_lt_nat {\u03b1 : Type u} [has_add \u03b1] [has_zero \u03b1] (f : \u2115 \u2192 \u03b1) : \u2115 \u2192 \u03b1 \n| 0        := 0\n| (succ n) := sum_lt_nat n + f n\n\nlemma sum_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {f : \u2115 \u2192 \u03b1} (n : \u2115) : (\u2200 m : \u2115, 0 \u2264 f m) \u2192 0 \u2264 sum_lt_nat f n := begin\n  assume h,induction n with n' hi,\n  simp!,simp!,exact add_nonneg (h n') hi,\nend\n#print mul_zero\nlemma sum_lt_nat_mul {\u03b1 : Type u} [semiring \u03b1] (f : \u2115 \u2192 \u03b1) (a : \u03b1) (n : \u2115) : a * sum_lt_nat f n = sum_lt_nat (\u03bb m, a * f m) n := begin\n  induction n with n' hi,\n  simp!,simp!,rw [mul_add,hi],\nend\n\nlemma sum_incrs_of_nonneg {\u03b1 : Type u} [linear_ordered_semiring \u03b1] {f : \u2115 \u2192 \u03b1} (i j : \u2115) : (\u2200 m \u2265 i, 0 \u2264 f m) \u2192 i \u2264 j \u2192 sum_lt_nat f i \u2264 sum_lt_nat f j := begin\n  assume h ij,\n  generalize hk : j - i = k,revert i j,\n  induction k with k' hi,\n  assume i j h ij hk,\n  rw nat.sub_eq_zero_iff_le at hk, replace ij := le_antisymm hk ij,rw ij,\n  assume i j h ij hk,have ik : i \u2264 k' + i,rw \u2190zero_add i,refine add_le_add _ _,exact zero_le _,simp,\n  have := hi i (k' + i) h ik (by rw nat.add_sub_cancel),\n  rw [nat.sub_eq_iff_eq_add ij,succ_add] at hk,rw hk,simp!,\n  refine le_trans this _,\n  rw \u2190zero_add (sum_lt_nat f (k' + i)),refine add_le_add _ _,refine h _ ik,simp,\nend\n\n\nlemma geometric_series_l (n : \u2115) (x : \u211d) : x \u2260 1 \u2192 sum_lt_nat (monoid.pow x) n = (1 - monoid.pow x n) / (1 - x) := begin\n  assume x1,have x1' : 1 + -x \u2260 0,assume h,rw [eq_comm, \u2190sub_eq_iff_eq_add] at h,simp at h,trivial,\n  induction n with n' hi,\n  simp!,rw eq_div_iff_mul_eq,simpa,\n  simp!,rw hi,simp, rw [add_mul,div_mul_cancel _ x1',mul_add],ring,simp [x1'],\nend\n\nlemma geometric_series_cauchy (x : \u211d) : abs x < 1 \u2192 is_cau_seq abs (sum_lt_nat (monoid.pow x)):= begin\n  assume x1, have : sum_lt_nat (monoid.pow x) = \u03bb n,(1 - monoid.pow x n) / (1 - x),\n    apply funext,assume n,refine geometric_series_l n x _ ,assume h, rw h at x1,exact absurd x1 (by norm_num),rw this,\n  have absx : 0 < abs (1 - x),refine abs_pos_of_ne_zero _,assume h,rw sub_eq_zero_iff_eq at h,rw \u2190h at x1,\n  have : \u00acabs (1 : \u211d) < 1,norm_num,trivial,simp at absx,\n  cases classical.em (x = 0),rw h,simp[monoid.pow],assume \u03b5 \u03b50,existsi 1,assume j j1,simpa!,\n  cases j,exact absurd j1 dec_trivial,simpa!,\n  have x2: 1 < (abs x)\u207b\u00b9,rw lt_inv,simpa,{norm_num},exact abs_pos_of_ne_zero h,\n  assume \u03b5 \u03b50,cases pow_unbounded_of_gt_one (2 / (\u03b5 * abs (1 - x))) x2 with i hi,\n  rw [\u2190pow_inv',lt_inv] at hi,\n  existsi i,assume j ji,rw [inv_eq_one_div,div_div_eq_mul_div,one_mul,lt_div_iff (by norm_num : (0 : \u211d) < 2)] at hi,\n  rw [div_sub_div_same,abs_div,div_lt_iff],\n  refine lt_of_le_of_lt _ hi,\n  simp,\n  refine le_trans (abs_add _ _) _,\n  have : monoid.pow (abs x) i * 2 = monoid.pow (abs x) i + monoid.pow (abs x) i,ring,\n  rw this,\n  refine add_le_add _ _,rw \u2190pow_abs,\n  rw [abs_neg,\u2190pow_abs],\n  cases lt_or_eq_of_le ji,\n  refine le_of_lt (pow_dcrs_of_lt_one_of_pos x1 (abs_pos_of_ne_zero h) h_1),\n  rw h_1,assumption,\n  refine div_pos _ _,{norm_num},\n  refine mul_pos \u03b50 _,simpa,\n  refine pow_pos (abs_pos_of_ne_zero h) _,\nend\nlemma geometric_series_const (a x : \u211d) : abs x < 1 \u2192 is_cau_seq abs (sum_lt_nat (\u03bb n, a * monoid.pow x n)) := begin\n  assume x1 \u03b5 \u03b50,\n  cases classical.em (a = 0),\n  existsi 0,intros,rw [\u2190sum_lt_nat_mul],induction j,simp!,assumption,rw h,simpa!,\n  cases geometric_series_cauchy x x1 (\u03b5 / abs a) (div_pos \u03b50 (abs_pos_of_ne_zero h)) with i hi,\n  existsi i,assume j ji,rw [\u2190sum_lt_nat_mul,\u2190sum_lt_nat_mul,\u2190mul_sub,abs_mul,mul_comm,\u2190lt_div_iff],exact hi j ji,exact abs_pos_of_ne_zero h,\nend\nlemma le_test (f g : \u2115 \u2192 \u211d) (n : \u2115) : (\u2200 m \u2265 n, abs (f m) \u2264 g m) \u2192 is_cau_seq abs (sum_lt_nat g) \u2192 is_cau_seq abs (sum_lt_nat f) := begin\n  assume hm hg \u03b5 \u03b50,cases hg (\u03b5 / 2) (div_pos \u03b50 (by norm_num)) with i hi,\n  existsi max n i,\n  assume j ji,\n  have hi\u2081 := hi j (le_trans (le_max_right n i) ji),\n  have hi\u2082 := hi (max n i) (le_max_right n i),\n  have sub_le := abs_sub_le (sum_lt_nat g j) (sum_lt_nat g i) (sum_lt_nat g (max n i)),\n  have := add_lt_add hi\u2081 hi\u2082,rw abs_sub (sum_lt_nat g (max n i)) at this,\n  have \u03b52 : \u03b5 / 2 + \u03b5 / 2 = \u03b5,rw [\u2190add_div,(by ring : \u03b5 + \u03b5 = \u03b5 * 2),mul_div_cancel],{norm_num},\n  rw \u03b52 at this,\n  refine lt_of_le_of_lt _ this,\n  refine le_trans _ sub_le,\n  refine le_trans _ (le_abs_self _),\n  have hmi : \u2200 m : \u2115, m \u2265 max n i \u2192 f m \u2264 abs (f m),assume m h, exact le_abs_self _,\n  have := sum_le_of_terms_le\u2082 (max n i) j ji hmi,\n  refine abs_sub_le_iff.mpr _,split,\n  refine le_trans this _,\n  refine sum_le_of_terms_le\u2082 _ _ _ _,exact ji,\n  assume m h,exact hm m (le_trans (le_max_left n i) h),\n  have : sum_lt_nat f (max n i) - sum_lt_nat f j = -1 * sum_lt_nat f j - -1 * sum_lt_nat f (max n i),ring,\n  rw [this,sum_lt_nat_mul,sum_lt_nat_mul],\n  refine sum_le_of_terms_le\u2082 _ _ _ _,exact ji,\n  assume m h,\n  have := hm m (le_trans (le_max_left n i) h),\n  refine le_trans _ this,simp,rw \u2190abs_neg, exact le_abs_self _,\nend\n\nlemma exp_series_cau (x : \u211d) : is_cau_seq abs (sum_lt_nat (\u03bb m, monoid.pow x m / fact m)) := begin\n  have nat_nonneg : \u2200 n : \u2115, 0 \u2264 (n : \u211d),assume n,rw [\u2190nat.cast_zero,nat.cast_le],exact zero_le _,\n  cases exists_nat_gt (abs x) with n nx,\n  have xn : abs (x / n) < 1,rw [abs_div,div_lt_iff,@abs_of_nonneg _ _ (n : \u211d)],simpa,\n  rw [\u2190nat.cast_zero,(\u03bb x y, by simp : \u2200 x y : \u211d, x \u2265 y \u2194 y \u2264 x ),nat.cast_le],exact zero_le _,\n  refine abs_pos_of_ne_zero _,assume hn,rw hn at nx,exact not_lt_of_ge (abs_nonneg _) nx,\n  refine le_test _ _ n _ (geometric_series_const (monoid.pow n n) (abs (x / \u2191n)) _),\n  assume m mn,\n  generalize hk : m - n = k,\n  have :  monoid.pow (abs (x / \u2191n)) m = monoid.pow (abs x) m * (monoid.pow (n : \u211d) m)\u207b\u00b9,\n    clear mn hk nx xn k,induction m with m hi,\n    simp!,unfold monoid.pow,rw mul_inv',\n    have : abs x * monoid.pow (abs x) m * ((monoid.pow \u2191n m)\u207b\u00b9 * (\u2191n)\u207b\u00b9) = (abs x * (n : \u211d)\u207b\u00b9) * ((monoid.pow n m)\u207b\u00b9 * monoid.pow (abs x) m),ring,\n    rw this,rw [\u2190div_eq_mul_inv,hi,abs_div],have : abs (n : \u211d) = n,rw abs_of_nonneg,rw[\u2190 nat.cast_zero,(\u03bb x y, by simp : \u03a0 x y : \u211d, x \u2265 y \u2194 y \u2264 x),nat.cast_le],exact zero_le _,\n    rw this,ring,\n  rw [this,mul_left_comm,abs_div,div_eq_mul_inv,\u2190pow_abs],\n  refine mul_le_mul _ _ _ _,trivial,clear this,\n  rw nat.sub_eq_iff_eq_add at hk,rw hk,simp,clear xn,revert m n,\n  induction k with k' hi,\n  assume m n nx mn hk,\n  simp,rw [mul_inv_cancel,inv_le],simp,\n  clear hk mn nx m x,\n  induction n with n hi,simp,\n  unfold fact,rw[nat.cast_mul,abs_mul,\u2190one_mul (1 : \u211d)],refine mul_le_mul _ _ _ _,\n  rw [\u2190nat.cast_one],refine le_trans _ (le_abs_self _),\n  rw nat.cast_le,exact dec_trivial,exact hi,{norm_num},exact abs_nonneg _,\n  refine lt_of_lt_of_le _ (le_abs_self _),rw [\u2190nat.cast_zero,nat.cast_lt],exact fact_pos _,\n  {norm_num},\n  refine (ne_of_lt _).symm,\n  refine pow_pos _ _,refine lt_of_le_of_lt _ nx,exact abs_nonneg _,\n  assume m n nx mn hk,\n  have : k' + n \u2265 n,rw \u2190zero_add n,refine add_le_add _ _,exact zero_le _,rw zero_add,\n  replace hi := hi (k' + n) n nx this rfl,\n  rw add_succ,unfold fact monoid.pow,\n  rw [mul_inv',nat.cast_mul,abs_mul,mul_inv',\u2190mul_assoc],\n  refine mul_le_mul _ _ _ _,assumption,\n  rw inv_le_inv,refine le_trans _ (le_abs_self _),\n  rw [nat.cast_le,\u2190add_succ,\u2190add_zero n],refine add_le_add _ _,\n  simp,exact zero_le _,\n  refine abs_pos_of_ne_zero _,\n  rw [\u2190nat.cast_zero,ne.def,nat.cast_inj],exact dec_trivial,\n  refine lt_of_le_of_lt _ nx,exact abs_nonneg _,\n  rw \u2190abs_inv,exact abs_nonneg _,\n  refine mul_nonneg _ _,\n  refine pow_nonneg _ _,rw [\u2190 nat.cast_zero,(\u03bb x y,by simp : \u03a0 x y : \u211d, x \u2265 y \u2194 y \u2264 x), nat.cast_le],exact zero_le _,\n  rw [(\u03bb x y,by simp : \u03a0 x y : \u211d, x \u2265 y \u2194 y \u2264 x),inv_nonneg],\n  refine pow_nonneg _ _,exact nat_nonneg _,\n  exact mn,rw inv_nonneg,exact abs_nonneg _,rw pow_abs,exact abs_nonneg _,\n  rwa abs_abs,\nend\n\ndef exp (x : \u211d) : \u211d := lim \u27e8(sum_lt_nat (\u03bb m, monoid.pow x m / fact m)), exp_series_cau x\u27e9", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7224281191394504}}
{"text": "/-\nCOMP2009-ACE\n\nExercise 02 (Predicate logic) (20)\n\n    This exercise has 2 parts. In the 1st part you are supposed to\n    formally define what certain relation bewteen humans are (like\n    Father, brother-in-law etc). Here we use Lean only as a syntax  \n    and type checker. \n    In the 2nd part we play logic poker again :-) but this time for\n    predicate logic. \n\n-/\n\n-- part 1 (10)\nnamespace family\n\n-- Given the following type, predicates and relations:\n\nconstant People : Type\nconstants Male Female : People \u2192 Prop\n-- Male x means x is male\n-- Female x means x is fmeale\nconstant Parent : People \u2192 People \u2192 Prop\n-- Parent x y means x is a parent of y\nconstant Married : People \u2192 People \u2192 Prop\n-- Married x y means x is married to y\n\n/-\nDefine the following relations (People \u2192 People \u2192 Prop) \nusing the predicates and relations above:\n\n- Father x y = x is the father of y\n- Brother x y = x is the brother of y\n- Grandmother x y = x is the grandmother of y\n- FatherInLaw x y = x is the father-in-law of y\n- SisterInLaw x y = x is the sister in law of y\n- Uncle x y = x is the uncle of y\n\nIf you are not sure about the definition of these terms, check them \nin wikipedia. If there is more than one option choose one.\n-/\n\n/- As an example: here is the definition of Father: -/\n\ndef Father (x y : People) : Prop\n  := Parent x y \u2227 Male x\n\n-- add your definitions here!\n\nend family\n\n-- part 2 (10)\nnamespace poker\n/-\n   We play the game of logic poker - but this time with predicate logic :-)\n\n    You have to classify the propositions into\n    a) provable intuitionistically (i.e. in plain lean)\n    b) provable classically (using em : P \u2228 \u00ac P or raa : \u00ac\u00ac P \u2192 P).\n    c) not provable classically.\n    and then you have to prove the propositions in a) and b) accordingly.\n\n    Here is how you score:\n    We start with 10 points :-)\n    For any proposition which you didn't classify correctly (or not at all)\n    you loose 1 point. :-(\n    For any proposition which is provable but you didn't prove you loose\n    1 point. :-(\n    We stop subtracting points at 0. :-)\n\n    Write the classification as a comment using -- after the proposition.\n\n    You are only allowed to use the tactics introduced in the lecture\n    (i.e. assume, exact, apply, constructor, cases, left, right, have, \n    trivial, existsi, reflexivity, rewrite)\n\n    Please only use the tactics in the way indicated in the script,\n    otherwise you may lose upto 2 style points. \n\n    For propositions classified into c) just keep \"sorry,\" as the proof.\n-/\n\nvariable A : Type\nvariables PP QQ : A \u2192 Prop\nvariables RR : A \u2192 A \u2192 Prop\nvariables P Q R : Prop\n\nopen classical\n\ntheorem raa : \u00ac \u00ac P \u2192 P := \nbegin\n  assume nnp,\n  cases (em P) with p np,\n    exact p,\n    have f : false,\n      apply nnp,\n      exact np,\n    cases f,\nend\n\ntheorem ex01 : (\u2200 x:A, \u2203 y : A , RR x y) \u2192 (\u2203 y : A, \u2200 x : A, RR x y) :=\nbegin \n    -- Not provable (c)\n    sorry,\nend\n\ntheorem ex02 :  (\u2203 y : A, \u2200 x : A, RR x y) \u2192 (\u2200 x:A, \u2203 y : A , RR x y) :=\nbegin \n    assume a b,\n    /-\n        a : \u2203 y : A, \u2200 x : A, RR x y \n        b : A\n        \u22a2  \u2203 y : A , RR x y\n    -/    \n    cases a with c d,\n    /-\n        b c : A\n        d : \u2200 x : A, RR x y \n        \u22a2  \u2203 y : A , RR x y\n    -/\n    existsi c,\n    /-\n        b c : A\n        d : \u2200 x : A, RR x y\n        \u22a2  RR x c\n    -/\n    apply d,\n    /-\n        No goals\n    -/\nend\n\ntheorem ex03 : \u2200 x y : A, x = y \u2192 RR x y \u2192 RR x x :=\nbegin \n    assume x y a,\n    /-\n        x y : A\n        a : x = y\n        \u22a2 RR x y \u2192 RR x x\n    -/ \n    rewrite a,\n    /-\n        x y : A\n        a : x = y\n        \u22a2 RR y y \u2192 RR y y\n    -/ \n    assume b,\n    /-\n        x y : A\n        a : x = y\n        b : RR y y\n        \u22a2 RR y y\n    -/ \n    exact b,\n    /-\n        No goals\n    -/\nend\n\ntheorem ex04 : \u2200 x y z : A, x \u2260 y \u2192 x \u2260 z \u2192 y \u2260 z :=\nbegin \n    sorry\n    -- Not provable\nend\n\ntheorem ex05 : \u2200 x y z : A, x = y \u2192 x \u2260 z \u2192 y \u2260 z :=\nbegin \n    assume x y z xy xz yz,\n    /-\n        x y z : A\n        xy : x = y\n        xz : x \u2260 z\n        yz : y = z\n        \u22a2 false\n    -/\n    apply xz,\n    /-\n        x y z : A\n        xy : x = y\n        xz : x \u2260 z\n        yz : y = z\n        \u22a2 x = z\n    -/\n    rewrite xy,\n    /-\n        x y z : A\n        xy : x = y\n        xz : x \u2260 z\n        yz : y = z\n        \u22a2 y = z\n    -/\n    exact yz,\n    /-\n        No goals\n    -/\nend\n\ntheorem ex06 : \u2200 x y z : A, x \u2260 y \u2192 (x \u2260 z \u2228 y \u2260 z) :=\nbegin \n    assume x y z xy,\n    /-\n        x y z : A\n        xy : x \u2260 y\n        \u22a2  x \u2260 z \u2228 y \u2260 z\n    -/\n    cases em (y = z) with h nh,\n    /-\n        (Case 1)\n        x y z : A\n        xy : x \u2260 y\n        h : y = z\n        \u22a2  x \u2260 z \u2228 y \u2260 z\n\n        (Case 2)\n        x y z : A\n        xy : x \u2260 y\n        h : y \u2260 z\n        \u22a2  x \u2260 z \u2228 y \u2260 z\n    -/\n    left,\n    /-\n        (Case 1)\n        x y z : A\n        xy : x \u2260 y\n        h : y = z\n        \u22a2  x \u2260 z\n\n        (Case 2)\n        x y z : A\n        xy : x \u2260 y\n        h : y \u2260 z\n        \u22a2  x \u2260 z \u2228 y \u2260 z\n    -/\n    rewrite\u2190 h,\n    /-\n        (Case 1)\n        x y z : A\n        xy : x \u2260 y\n        h : y = z\n        \u22a2  x \u2260 y\n\n        (Case 2)\n        x y z : A\n        xy : x \u2260 y\n        h : y \u2260 z\n        \u22a2  x \u2260 z \u2228 y \u2260 z\n    -/\n    exact xy,\n    /-\n        Gets rid of Case 1\n    -/\n    right,\n    /-\n         (Case 2)\n        x y z : A\n        xy : x \u2260 y\n        h : y \u2260 z\n        \u22a2 y \u2260 z \n    -/\n    exact nh,\n    /-\n        No goals (Gets rid of Case 2)\n    -/\nend\n\ntheorem ex07 : \u00ac \u00ac (\u2200 x : A, PP x) \u2192 \u2200 x : A, \u00ac \u00ac PP x :=\nbegin \n    assume x y z,\n    /-\n        x : \u00ac \u00ac \u2200 x : A, PP x\n        y : A\n        z : \u00acPP x\n        \u22a2   false\n    -/\n    apply x,\n    /-\n        x : \u00ac \u00ac \u2200 x : A, PP x\n        y : A\n        z : \u00acPP x\n        \u22a2  \u00ac \u2200 x : A, PP x\n    -/\n    assume a,\n    /-\n        x : \u00ac \u00ac \u2200 x : A, PP x\n        y : A\n        z : \u00acPP x\n        a : \u2200 x : A, PP x\n        \u22a2  false\n    -/\n    apply z,\n    /-\n        x : \u00ac \u00ac \u2200 x : A, PP x\n        y : A\n        z : \u00acPP x\n        a : \u2200 x : A, PP x\n        \u22a2  PP x\n    -/ \n    apply a, \n    /-\n        No goals\n    -/\nend\n\ntheorem ex08 : (\u2200 x : A, \u00ac \u00ac PP x) \u2192 \u00ac \u00ac \u2200 x : A, PP x :=\nbegin \n    assume x y,\n    /-\n        x : \u2200 x : A, \u00ac \u00ac PP x\n        y : \u00ac \u2200 x : A, PP x\n        \u22a2 false\n    -/\n    apply y\n    /-\n        x : \u2200 x : A, \u00ac \u00ac PP x\n        y : \u00ac \u2200 x : A, PP x\n        \u22a2 \u2200 x : A, PP x\n    -/\n    assume z,\n    /-\n        x : \u2200 x : A, \u00ac \u00ac PP x\n        y : \u00ac \u2200 x : A, PP x\n        z : A\n        \u22a2 PP x\n    -/   \n    apply raa,\n    /-\n        x : \u2200 x : A, \u00ac \u00ac PP x\n        y : \u00ac \u2200 x : A, PP x\n        z : A\n        \u22a2 \u00ac\u00ac PP x\n    -/   \n    apply x,\n    /-\n        No goals\n    -/\nend\n\ntheorem ex09 : (\u2203 x : A, true) \u2192 (\u2203 x:A, PP x) \u2192 \u2200 x : A,PP x :=\nbegin \n    sorry,\nend\n\ntheorem ex10 : (\u2203 x : A, true) \u2192 (\u2203 x:A, PP x \u2192 \u2200 x : A,PP x) :=\nbegin \n  sorry\nend\n\nend poker\n\n", "meta": {"author": "BraxWong", "repo": "lean_Rev", "sha": "c626bda0d38477f95ba4edaf20b9eaa034375c48", "save_path": "github-repos/lean/BraxWong-lean_Rev", "path": "github-repos/lean/BraxWong-lean_Rev/lean_Rev-c626bda0d38477f95ba4edaf20b9eaa034375c48/ex02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7223610307633308}}
{"text": "/-\nCopyright (c) 2020 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport topology.algebra.ring.ideal\nimport analysis.specific_limits.normed\n\n/-!\n# The group of units of a complete normed ring\n\nThis file contains the basic theory for the group of units (invertible elements) of a complete\nnormed ring (Banach algebras being a notable special case).\n\n## Main results\n\nThe constructions `one_sub`, `add` and `unit_of_nearby` state, in varying forms, that perturbations\nof a unit are units.  The latter two are not stated in their optimal form; more precise versions\nwould use the spectral radius.\n\nThe first main result is `is_open`:  the group of units of a complete normed ring is an open subset\nof the ring.\n\nThe function `inverse` (defined in `algebra.ring`), for a ring `R`, sends `a : R` to `a\u207b\u00b9` if `a` is\na unit and 0 if not.  The other major results of this file (notably `inverse_add`,\n`inverse_add_norm` and `inverse_add_norm_diff_nth_order`) cover the asymptotic properties of\n`inverse (x + t)` as `t \u2192 0`.\n\n-/\n\nnoncomputable theory\nopen_locale topology\nvariables {R : Type*} [normed_ring R] [complete_space R]\n\nnamespace units\n\n/-- In a complete normed ring, a perturbation of `1` by an element `t` of distance less than `1`\nfrom `1` is a unit.  Here we construct its `units` structure.  -/\n@[simps coe]\ndef one_sub (t : R) (h : \u2016t\u2016 < 1) : R\u02e3 :=\n{ val := 1 - t,\n  inv := \u2211' n : \u2115, t ^ n,\n  val_inv := mul_neg_geom_series t h,\n  inv_val := geom_series_mul_neg t h }\n\n/-- In a complete normed ring, a perturbation of a unit `x` by an element `t` of distance less than\n`\u2016x\u207b\u00b9\u2016\u207b\u00b9` from `x` is a unit.  Here we construct its `units` structure. -/\n@[simps coe]\ndef add (x : R\u02e3) (t : R) (h : \u2016t\u2016 < \u2016(\u2191x\u207b\u00b9 : R)\u2016\u207b\u00b9) : R\u02e3 :=\nunits.copy  -- to make `coe_add` true definitionally, for convenience\n  (x * (units.one_sub (-(\u2191x\u207b\u00b9 * t)) begin\n      nontriviality R using [zero_lt_one],\n      have hpos : 0 < \u2016(\u2191x\u207b\u00b9 : R)\u2016 := units.norm_pos x\u207b\u00b9,\n      calc \u2016-(\u2191x\u207b\u00b9 * t)\u2016\n          = \u2016\u2191x\u207b\u00b9 * t\u2016                    : by { rw norm_neg }\n      ... \u2264 \u2016(\u2191x\u207b\u00b9 : R)\u2016 * \u2016t\u2016            : norm_mul_le \u2191x\u207b\u00b9 _\n      ... < \u2016(\u2191x\u207b\u00b9 : R)\u2016 * \u2016(\u2191x\u207b\u00b9 : R)\u2016\u207b\u00b9 : by nlinarith only [h, hpos]\n      ... = 1                             : mul_inv_cancel (ne_of_gt hpos)\n    end))\n  (x + t) (by simp [mul_add]) _ rfl\n\n/-- In a complete normed ring, an element `y` of distance less than `\u2016x\u207b\u00b9\u2016\u207b\u00b9` from `x` is a unit.\nHere we construct its `units` structure. -/\n@[simps coe]\ndef unit_of_nearby (x : R\u02e3) (y : R) (h : \u2016y - x\u2016 < \u2016(\u2191x\u207b\u00b9 : R)\u2016\u207b\u00b9) : R\u02e3 :=\nunits.copy (x.add (y - x : R) h) y (by simp) _ rfl\n\n/-- The group of units of a complete normed ring is an open subset of the ring. -/\nprotected lemma is_open : is_open {x : R | is_unit x} :=\nbegin\n  nontriviality R,\n  apply metric.is_open_iff.mpr,\n  rintros x' \u27e8x, rfl\u27e9,\n  refine \u27e8\u2016(\u2191x\u207b\u00b9 : R)\u2016\u207b\u00b9, _root_.inv_pos.mpr (units.norm_pos x\u207b\u00b9), _\u27e9,\n  intros y hy,\n  rw [metric.mem_ball, dist_eq_norm] at hy,\n  exact (x.unit_of_nearby y hy).is_unit\nend\n\nprotected lemma nhds (x : R\u02e3) : {x : R | is_unit x} \u2208 \ud835\udcdd (x : R) :=\nis_open.mem_nhds units.is_open x.is_unit\n\nend units\n\nnamespace nonunits\n\n/-- The `nonunits` in a complete normed ring are contained in the complement of the ball of radius\n`1` centered at `1 : R`. -/\nlemma subset_compl_ball : nonunits R \u2286 (metric.ball (1 : R) 1)\u1d9c :=\nset.subset_compl_comm.mp $ \u03bb x hx, by simpa [sub_sub_self, units.coe_one_sub] using\n  (units.one_sub (1 - x) (by rwa [metric.mem_ball, dist_eq_norm, norm_sub_rev] at hx)).is_unit\n\n/- The `nonunits` in a complete normed ring are a closed set -/\nprotected lemma is_closed : is_closed (nonunits R) := units.is_open.is_closed_compl\n\nend nonunits\n\nnamespace normed_ring\nopen_locale classical big_operators\nopen asymptotics filter metric finset ring\n\nlemma inverse_one_sub (t : R) (h : \u2016t\u2016 < 1) : inverse (1 - t) = \u2191(units.one_sub t h)\u207b\u00b9 :=\nby rw [\u2190 inverse_unit (units.one_sub t h), units.coe_one_sub]\n\n/-- The formula `inverse (x + t) = inverse (1 + x\u207b\u00b9 * t) * x\u207b\u00b9` holds for `t` sufficiently small. -/\nlemma inverse_add (x : R\u02e3) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((x : R) + t) = inverse (1 + \u2191x\u207b\u00b9 * t) * \u2191x\u207b\u00b9 :=\nbegin\n  nontriviality R,\n  rw [eventually_iff, metric.mem_nhds_iff],\n  have hinv : 0 < \u2016(\u2191x\u207b\u00b9 : R)\u2016\u207b\u00b9, by cancel_denoms,\n  use [\u2016(\u2191x\u207b\u00b9 : R)\u2016\u207b\u00b9, hinv],\n  intros t ht,\n  simp only [mem_ball, dist_zero_right] at ht,\n  have ht' : \u2016-\u2191x\u207b\u00b9 * t\u2016 < 1,\n  { refine lt_of_le_of_lt (norm_mul_le _ _) _,\n    rw norm_neg,\n    refine lt_of_lt_of_le (mul_lt_mul_of_pos_left ht x\u207b\u00b9.norm_pos) _,\n    cancel_denoms },\n  have hright := inverse_one_sub (-\u2191x\u207b\u00b9 * t) ht',\n  have hleft := inverse_unit (x.add t ht),\n  simp only [neg_mul, sub_neg_eq_add] at hright,\n  simp only [units.coe_add] at hleft,\n  simp [hleft, hright, units.add]\nend\n\nlemma inverse_one_sub_nth_order (n : \u2115) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((1:R) - t) = (\u2211 i in range n, t ^ i) + (t ^ n) * inverse (1 - t) :=\nbegin\n  simp only [eventually_iff, metric.mem_nhds_iff],\n  use [1, by norm_num],\n  intros t ht,\n  simp only [mem_ball, dist_zero_right] at ht,\n  simp only [inverse_one_sub t ht, set.mem_set_of_eq],\n  have h : 1 = ((range n).sum (\u03bb i, t ^ i)) * (units.one_sub t ht) + t ^ n,\n  { simp only [units.coe_one_sub],\n    rw [geom_sum_mul_neg],\n    simp },\n  rw [\u2190 one_mul \u2191(units.one_sub t ht)\u207b\u00b9, h, add_mul],\n  congr,\n  { rw [mul_assoc, (units.one_sub t ht).mul_inv],\n    simp },\n  { simp only [units.coe_one_sub],\n    rw [\u2190 add_mul, geom_sum_mul_neg],\n    simp }\nend\n\n/-- The formula\n`inverse (x + t) = (\u2211 i in range n, (- x\u207b\u00b9 * t) ^ i) * x\u207b\u00b9 + (- x\u207b\u00b9 * t) ^ n * inverse (x + t)`\nholds for `t` sufficiently small. -/\nlemma inverse_add_nth_order (x : R\u02e3) (n : \u2115) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((x : R) + t)\n  = (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9 + (- \u2191x\u207b\u00b9 * t) ^ n * inverse (x + t) :=\nbegin\n  refine (inverse_add x).mp _,\n  have hzero : tendsto (\u03bb (t : R), - \u2191x\u207b\u00b9 * t) (\ud835\udcdd 0) (\ud835\udcdd 0),\n  { convert ((mul_left_continuous (- (\u2191x\u207b\u00b9 : R))).tendsto 0).comp tendsto_id,\n    simp },\n  refine (hzero.eventually (inverse_one_sub_nth_order n)).mp (eventually_of_forall _),\n  simp only [neg_mul, sub_neg_eq_add],\n  intros t h1 h2,\n  have h := congr_arg (\u03bb (a : R), a * \u2191x\u207b\u00b9) h1,\n  dsimp at h,\n  convert h,\n  rw [add_mul, mul_assoc],\n  simp [h2.symm]\nend\n\nlemma inverse_one_sub_norm : (\u03bb t : R, inverse (1 - t)) =O[\ud835\udcdd 0] (\u03bb t, 1 : R \u2192 \u211d) :=\nbegin\n  simp only [is_O, is_O_with, eventually_iff, metric.mem_nhds_iff],\n  refine \u27e8\u2016(1:R)\u2016 + 1, (2:\u211d)\u207b\u00b9, by norm_num, _\u27e9,\n  intros t ht,\n  simp only [ball, dist_zero_right, set.mem_set_of_eq] at ht,\n  have ht' : \u2016t\u2016 < 1,\n  { have : (2:\u211d)\u207b\u00b9 < 1 := by cancel_denoms,\n    linarith },\n  simp only [inverse_one_sub t ht', norm_one, mul_one, set.mem_set_of_eq],\n  change \u2016\u2211' n : \u2115, t ^ n\u2016 \u2264 _,\n  have := normed_ring.tsum_geometric_of_norm_lt_1 t ht',\n  have : (1 - \u2016t\u2016)\u207b\u00b9 \u2264 2,\n  { rw \u2190 inv_inv (2:\u211d),\n    refine inv_le_inv_of_le (by norm_num) _,\n    have : (2:\u211d)\u207b\u00b9 + (2:\u211d)\u207b\u00b9 = 1 := by ring,\n    linarith },\n  linarith\nend\n\n/-- The function `\u03bb t, inverse (x + t)` is O(1) as `t \u2192 0`. -/\nlemma inverse_add_norm (x : R\u02e3) : (\u03bb t : R, inverse (\u2191x + t)) =O[\ud835\udcdd 0] (\u03bb t, (1:\u211d)) :=\nbegin\n  simp only [is_O_iff, norm_one, mul_one],\n  cases is_O_iff.mp (@inverse_one_sub_norm R _ _) with C hC,\n  use C * \u2016((x\u207b\u00b9:R\u02e3):R)\u2016,\n  have hzero : tendsto (\u03bb t, - (\u2191x\u207b\u00b9 : R) * t) (\ud835\udcdd 0) (\ud835\udcdd 0),\n  { convert ((mul_left_continuous (-\u2191x\u207b\u00b9 : R)).tendsto 0).comp tendsto_id,\n    simp },\n  refine (inverse_add x).mp ((hzero.eventually hC).mp (eventually_of_forall _)),\n  intros t bound iden,\n  rw iden,\n  simp at bound,\n  have hmul := norm_mul_le (inverse (1 + \u2191x\u207b\u00b9 * t)) \u2191x\u207b\u00b9,\n  nlinarith [norm_nonneg (\u2191x\u207b\u00b9 : R)]\nend\n\n/-- The function\n`\u03bb t, inverse (x + t) - (\u2211 i in range n, (- x\u207b\u00b9 * t) ^ i) * x\u207b\u00b9`\nis `O(t ^ n)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_nth_order (x : R\u02e3) (n : \u2115) :\n  (\u03bb t : R, inverse (\u2191x + t) - (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9) =O[\ud835\udcdd (0:R)]\n  (\u03bb t, \u2016t\u2016 ^ n) :=\nbegin\n  by_cases h : n = 0,\n  { simpa [h] using inverse_add_norm x },\n  have hn : 0 < n := nat.pos_of_ne_zero h,\n  simp [is_O_iff],\n  cases (is_O_iff.mp (inverse_add_norm x)) with C hC,\n  use C * \u2016(1:\u211d)\u2016 * \u2016(\u2191x\u207b\u00b9 : R)\u2016 ^ n,\n  have h : eventually_eq (\ud835\udcdd (0:R))\n    (\u03bb t, inverse (\u2191x + t) - (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9)\n    (\u03bb t, ((- \u2191x\u207b\u00b9 * t) ^ n) * inverse (x + t)),\n  { refine (inverse_add_nth_order x n).mp (eventually_of_forall _),\n    intros t ht,\n    convert congr_arg (\u03bb a, a - (range n).sum (pow (-\u2191x\u207b\u00b9 * t)) * \u2191x\u207b\u00b9) ht,\n    simp },\n  refine h.mp (hC.mp (eventually_of_forall _)),\n  intros t _ hLHS,\n  simp only [neg_mul] at hLHS,\n  rw hLHS,\n  refine le_trans (norm_mul_le _ _ ) _,\n  have h' : \u2016(-(\u2191x\u207b\u00b9 * t)) ^ n\u2016 \u2264 \u2016(\u2191x\u207b\u00b9 : R)\u2016 ^ n * \u2016t\u2016 ^ n,\n  { calc \u2016(-(\u2191x\u207b\u00b9 * t)) ^ n\u2016 \u2264 \u2016(-(\u2191x\u207b\u00b9 * t))\u2016 ^ n : norm_pow_le' _ hn\n    ... = \u2016\u2191x\u207b\u00b9 * t\u2016 ^ n : by rw norm_neg\n    ... \u2264 (\u2016(\u2191x\u207b\u00b9 : R)\u2016 * \u2016t\u2016) ^ n : _\n    ... =  \u2016(\u2191x\u207b\u00b9 : R)\u2016 ^ n * \u2016t\u2016 ^ n : mul_pow _ _ n,\n    exact pow_le_pow_of_le_left (norm_nonneg _) (norm_mul_le \u2191x\u207b\u00b9 t) n },\n  have h'' : 0 \u2264 \u2016(\u2191x\u207b\u00b9 : R)\u2016 ^ n * \u2016t\u2016 ^ n,\n  { refine mul_nonneg _ _;\n    exact pow_nonneg (norm_nonneg _) n },\n  nlinarith [norm_nonneg (inverse (\u2191x + t))],\nend\n\n/-- The function `\u03bb t, inverse (x + t) - x\u207b\u00b9` is `O(t)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_first_order (x : R\u02e3) :\n  (\u03bb t : R, inverse (\u2191x + t) - \u2191x\u207b\u00b9) =O[\ud835\udcdd 0] (\u03bb t, \u2016t\u2016) :=\nby simpa using inverse_add_norm_diff_nth_order x 1\n\n/-- The function\n`\u03bb t, inverse (x + t) - x\u207b\u00b9 + x\u207b\u00b9 * t * x\u207b\u00b9`\nis `O(t ^ 2)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_second_order (x : R\u02e3) :\n  (\u03bb t : R, inverse (\u2191x + t) - \u2191x\u207b\u00b9 + \u2191x\u207b\u00b9 * t * \u2191x\u207b\u00b9) =O[\ud835\udcdd 0] (\u03bb t, \u2016t\u2016 ^ 2) :=\nbegin\n  convert inverse_add_norm_diff_nth_order x 2,\n  ext t,\n  simp only [range_succ, range_one, sum_insert, mem_singleton, sum_singleton, not_false_iff,\n    one_ne_zero, pow_zero, add_mul, pow_one, one_mul, neg_mul,\n    sub_add_eq_sub_sub_swap, sub_neg_eq_add],\nend\n\n/-- The function `inverse` is continuous at each unit of `R`. -/\nlemma inverse_continuous_at (x : R\u02e3) : continuous_at inverse (x : R) :=\nbegin\n  have h_is_o : (\u03bb t : R, inverse (\u2191x + t) - \u2191x\u207b\u00b9) =o[\ud835\udcdd 0] (\u03bb _, 1 : R \u2192 \u211d) :=\n    (inverse_add_norm_diff_first_order x).trans_is_o (is_o.norm_left $ is_o_id_const one_ne_zero),\n  have h_lim : tendsto (\u03bb (y:R), y - x) (\ud835\udcdd x) (\ud835\udcdd 0),\n  { refine tendsto_zero_iff_norm_tendsto_zero.mpr _,\n    exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },\n  rw [continuous_at, tendsto_iff_norm_tendsto_zero, inverse_unit],\n  simpa [(\u2218)] using h_is_o.norm_left.tendsto_div_nhds_zero.comp h_lim\nend\n\nend normed_ring\n\nnamespace units\nopen mul_opposite filter normed_ring\n\n/-- In a normed ring, the coercion from `R\u02e3` (equipped with the induced topology from the\nembedding in `R \u00d7 R`) to `R` is an open map. -/\nlemma is_open_map_coe : is_open_map (coe : R\u02e3 \u2192 R) :=\nbegin\n  rw is_open_map_iff_nhds_le,\n  intros x s,\n  rw [mem_map, mem_nhds_induced],\n  rintros \u27e8t, ht, hts\u27e9,\n  obtain \u27e8u, hu, v, hv, huvt\u27e9 :\n    \u2203 (u : set R), u \u2208 \ud835\udcdd \u2191x \u2227 \u2203 (v : set R\u1d50\u1d52\u1d56), v \u2208 \ud835\udcdd (op \u2191x\u207b\u00b9) \u2227 u \u00d7\u02e2 v \u2286 t,\n  { simpa [embed_product, mem_nhds_prod_iff] using ht },\n  have : u \u2229 (op \u2218 ring.inverse) \u207b\u00b9' v \u2229 (set.range (coe : R\u02e3 \u2192 R)) \u2208 \ud835\udcdd \u2191x,\n  { refine inter_mem (inter_mem hu _) (units.nhds x),\n    refine (continuous_op.continuous_at.comp (inverse_continuous_at x)).preimage_mem_nhds _,\n    simpa using hv },\n  refine mem_of_superset this _,\n  rintros _ \u27e8\u27e8huy, hvy\u27e9, \u27e8y, rfl\u27e9\u27e9,\n  have : embed_product R y \u2208 u \u00d7\u02e2 v := \u27e8huy, by simpa using hvy\u27e9,\n  simpa using hts (huvt this)\nend\n\n/-- In a normed ring, the coercion from `R\u02e3` (equipped with the induced topology from the\nembedding in `R \u00d7 R`) to `R` is an open embedding. -/\nlemma open_embedding_coe : open_embedding (coe : R\u02e3 \u2192 R) :=\nopen_embedding_of_continuous_injective_open continuous_coe ext is_open_map_coe\n\nend units\n\nnamespace ideal\n\n/-- An ideal which contains an element within `1` of `1 : R` is the unit ideal. -/\nlemma eq_top_of_norm_lt_one (I : ideal R) {x : R} (hxI : x \u2208 I) (hx : \u20161 - x\u2016 < 1) : I = \u22a4 :=\nlet u := units.one_sub (1 - x) hx in (I.eq_top_iff_one.mpr $\n  by simpa only [show u.inv * x = 1, by simp] using I.mul_mem_left u.inv hxI)\n\n/-- The `ideal.closure` of a proper ideal in a complete normed ring is proper. -/\nlemma closure_ne_top (I : ideal R) (hI : I \u2260 \u22a4) : I.closure \u2260 \u22a4 :=\nhave h : _ := closure_minimal (coe_subset_nonunits hI) nonunits.is_closed,\n  by simpa only [I.closure.eq_top_iff_one, ne.def] using mt (@h 1) one_not_mem_nonunits\n\n/-- The `ideal.closure` of a maximal ideal in a complete normed ring is the ideal itself. -/\nlemma is_maximal.closure_eq {I : ideal R} (hI : I.is_maximal) : I.closure = I :=\n(hI.eq_of_le (I.closure_ne_top hI.ne_top) subset_closure).symm\n\n/-- Maximal ideals in complete normed rings are closed. -/\ninstance is_maximal.is_closed {I : ideal R} [hI : I.is_maximal] : is_closed (I : set R) :=\nis_closed_of_closure_subset $ eq.subset $ congr_arg (coe : ideal R \u2192 set R) hI.closure_eq\n\nend ideal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7222889898951979}}
{"text": "import Approx.Dyadic\n\nstructure Interval where\n  lb : Dyadic\n  ub : Dyadic\n  lb_le_ub : lb \u2264 ub\n  deriving DecidableEq\n\ninstance : Membership Dyadic Interval where\n  mem x i := i.lb \u2264 x \u2227 x \u2264 i.ub\n\ndef Interval.add (i\u2081 i\u2082 : Interval) : Interval where\n  lb := i\u2081.lb + i\u2082.lb\n  ub := i\u2081.ub + i\u2082.ub\n  lb_le_ub := sorry\n\ninstance : Add Interval where\n  add := Interval.add\n\ndef Interval.mul (i\u2081 i\u2082 : Interval) : Interval where\n  lb := min (min (i\u2081.lb * i\u2082.lb) (i\u2081.lb * i\u2082.ub)) (min (i\u2081.ub * i\u2082.lb) (i\u2081.ub * i\u2082.ub))\n  ub := max (max (i\u2081.lb * i\u2082.lb) (i\u2081.lb * i\u2082.ub)) (max (i\u2081.ub * i\u2082.lb) (i\u2081.ub * i\u2082.ub))\n  lb_le_ub := sorry\n\ninstance : Mul Interval where\n  mul := Interval.mul\n\ndef Interval.sub (i\u2081 i\u2082 : Interval) : Interval where\n  lb := i\u2081.lb - i\u2082.ub\n  ub := i\u2081.ub - i\u2082.lb\n  lb_le_ub := sorry\n\ninstance : Sub Interval where\n  sub := Interval.sub\n\ndef length (i : Interval) : Dyadic := i.ub - i.lb\n\n/-\nCorrectness of the interval operations\n-/\n\nnamespace Interval\n\nlemma mem_add {i\u2081 i\u2082 : Interval} {a\u2081 a\u2082 : Dyadic} (h\u2081 : a\u2081 \u2208 i\u2081) (h\u2082 : a\u2082 \u2208 i\u2082) : \na\u2081 + a\u2082 \u2208 i\u2081 + i\u2082 := sorry\n\nlemma mem_mul {i\u2081 i\u2082 : Interval} {a\u2081 a\u2082 : Dyadic} (h\u2081 : a\u2081 \u2208 i\u2081) (h\u2082 : a\u2082 \u2208 i\u2082) :\na\u2081 * a\u2082 \u2208 i\u2081 * i\u2082 := sorry\n\nend Interval\n", "meta": {"author": "shingtaklam1324", "repo": "approx", "sha": "872d0a2fc1d420f742650e79dccbfc9a13ddc209", "save_path": "github-repos/lean/shingtaklam1324-approx", "path": "github-repos/lean/shingtaklam1324-approx/approx-872d0a2fc1d420f742650e79dccbfc9a13ddc209/Approx/Interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765304654121, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7222889897717824}}
{"text": "import algebra.module group_theory.subgroup\n\nclass group_module (G : Type*) [group G] (M : Type*) [add_comm_group M] extends has_scalar G M :=\n(one_smul : \u2200 m : M, (1 : G) \u2022 m = m)\n(smul_smul : \u2200 g h : G, \u2200 m : M, g \u2022 (h \u2022 m) = (g * h) \u2022 m)\n(smul_add : \u2200 g : G, \u2200 m n : M, g \u2022 (m + n) = g \u2022 m + g \u2022 n)\n\nnamespace group_module\n\nvariables {G : Type*} [group G] {M : Type*} [add_comm_group M] [group_module G M]\n\nvariables (M)\ninstance is_add_group_hom_smul (g : G) : is_add_group_hom ((\u2022) g : M \u2192 M) :=\n\u27e8group_module.smul_add g\u27e9\n\nlemma smul_zero (g : G) : g \u2022 (0 : M) = 0 :=\nis_add_group_hom.zero _\nvariables {M}\n\nlemma smul_neg (g : G) (m : M) : g \u2022 (-m) = -(g \u2022 m) :=\nis_add_group_hom.neg _ _\n\ndefinition fixed_points (G : Type*) [group G] (M : Type*) [add_comm_group M] [group_module G M] : set M :=\n{m : M | \u2200 g : G, g \u2022 m = m}\n\ninstance fixed_points.is_add_subgroup : is_add_subgroup (fixed_points G M) :=\n{ add_mem := \u03bb m n hm hn g, by rw [smul_add, hm g, hn g],\n  zero_mem := smul_zero M,\n  neg_mem := \u03bb m hm g, by rw [smul_neg, hm g] }\n\ndefinition H0 (G : Type*) [group G] (M : Type*) [add_comm_group M] [group_module G M] :=\nfixed_points G M\n\ninstance H0.add_comm_group : add_comm_group (H0 G M) :=\n{ add_comm := \u03bb m n, subtype.eq $ add_comm _ _,\n  .. @subtype.add_group _ _ _ fixed_points.is_add_subgroup }\n\nend group_module\n\nvariables {G : Type*} [group G] {M : Type*} [add_comm_group M] [group_module G M]\nvariables {N : Type*} [add_comm_group N] [group_module G N]\n\nvariable (G)\n\ndef is_group_module_hom (f : M \u2192 N) : Prop :=\n\u2200 g : G, \u2200 m : M, f (g \u2022 m) = g \u2022 (f m)\n\nnamespace is_group_module_hom\nopen group_module\n\ndef map_H0 (f : M \u2192 N) (hf : is_group_module_hom G f) (x : H0 G M) : H0 G N :=\n\u27e8f x.1, \u03bb g, by rw [\u2190 hf, x.2]\u27e9\n\nlemma id.group_module_hom : is_group_module_hom G (id : M \u2192 M) :=\n\u03bb g m, rfl\n\nend is_group_module_hom", "meta": {"author": "anca797", "repo": "group-cohomology", "sha": "f896dfa5057bd70c6fbb09ee6fdc26a7ffab5e5d", "save_path": "github-repos/lean/anca797-group-cohomology", "path": "github-repos/lean/anca797-group-cohomology/group-cohomology-f896dfa5057bd70c6fbb09ee6fdc26a7ffab5e5d/src/h0reviewed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7222889872443664}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.sqrt\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\nnamespace int\n\n\n/-- `sqrt n` is the square root of an integer `n`. If `n` is not a\n  perfect square, and is positive, it returns the largest `k:\u2124` such\n  that `k*k \u2264 n`. If it is negative, it returns 0. For example,\n  `sqrt 2 = 1` and `sqrt 1 = 1` and `sqrt (-1) = 0` -/\ndef sqrt (n : \u2124) : \u2124 :=\n  \u2191(nat.sqrt (to_nat n))\n\ntheorem sqrt_eq (n : \u2124) : sqrt (n * n) = \u2191(nat_abs n) := sorry\n\ntheorem exists_mul_self (x : \u2124) : (\u2203 (n : \u2124), n * n = x) \u2194 sqrt x * sqrt x = x := sorry\n\ntheorem sqrt_nonneg (n : \u2124) : 0 \u2264 sqrt n :=\n  coe_nat_nonneg (nat.sqrt (to_nat n))\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/int/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.7222628458589139}}
{"text": "import algebra.ring\n\nnamespace my_ring\n\nvariables {R : Type*} [ring R]\n\n#check add_zero\n#check zero_add\n#check add_mul\n#check add_right_cancel\n\n-- BEGIN\ntheorem zero_mul (a : R) : 0 * a = 0 :=\nbegin \n  have h : 0 * a + 0 * a = 0 + 0 * a,\n    { rw [\u2190 add_mul, add_zero,zero_add] },\n  rw add_right_cancel h,\nend\n-- END\n\n#check zero_mul\n\nend my_ring", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/1_rw/ex12_rw_zero_mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7222628414970639}}
{"text": "-- Pruebas_de_take_n_xs_++_drop_n_xs_Ig_xs.lean\n-- Pruebas de take n xs ++ drop n xs = xs\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 10 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean est\u00e1n definidas las funciones\n--    take : nat \u2192 list \u03b1 \u2192 nat\n--    drop : nat \u2192 list \u03b1 \u2192 nat\n--    (++) : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n-- tales que\n-- + (take n xs) es la lista formada por los n primeros elementos de\n--   xs. Por ejemplo,\n--      take 2 [3,5,1,9,7] = [3,5]\n-- + (drop n xs) es la lista formada eliminando los n primeros elementos\n--   de xs. Por ejemplo,\n--      drop 2 [3,5,1,9,7] = [1,9,7]\n-- + (xs ++ ys) es la lista obtenida concatenando xs e ys. Por ejemplo.\n--      [3,5] ++ [1,9,7] = [3,5,1,9,7]\n-- Dichas funciones est\u00e1n caracterizadas por los siguientes lemas:\n--    take_zero   : take 0 xs = []\n--    take_nil    : take n [] = []\n--    take_cons   : take (succ n) (x :: xs) = x :: take n xs\n--    drop_zero   : drop 0 xs = xs\n--    drop_nil    : drop n [] = []\n--    drop_cons   : drop (succ n) (x :: xs) = drop n xs := rfl\n--    nil_append  : [] ++ ys = ys\n--    cons_append : (x :: xs) ++ y = x :: (xs ++ ys)\n--\n-- Demostrar que\n--    take n xs ++ drop n xs = xs\n-- ---------------------------------------------------------------------\n\nimport data.list.basic\nimport tactic\nopen list\nopen nat\n\nvariable {\u03b1 : Type}\nvariable (n : \u2115)\nvariable (x : \u03b1)\nvariable (xs : list \u03b1)\n\nlemma drop_zero : drop 0 xs = xs := rfl\nlemma drop_cons : drop (succ n) (x :: xs) = drop n xs := rfl\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  take n xs ++ drop n xs = xs :=\nbegin\n  induction n with m HI1 generalizing xs,\n  { rw take_zero,\n    rw drop_zero,\n    rw nil_append, },\n  { induction xs with a as HI2,\n    { rw take_nil,\n      rw drop_nil,\n      rw nil_append, },\n    { rw take_cons,\n      rw drop_cons,\n      rw cons_append,\n      rw (HI1 as), }, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  take n xs ++ drop n xs = xs :=\nbegin\n  induction n with m HI1 generalizing xs,\n  { calc take 0 xs ++ drop 0 xs\n         = [] ++ drop 0 xs        : by rw take_zero\n     ... = [] ++ xs               : by rw drop_zero\n     ... = xs                     : by rw nil_append, },\n  { induction xs with a as HI2,\n    { calc take (succ m) [] ++ drop (succ m) []\n           = ([] : list \u03b1) ++ drop (succ m) [] : by rw take_nil\n       ... = [] ++ []                          : by rw drop_nil\n       ... = []                                : by rw nil_append, },\n    { calc take (succ m) (a :: as) ++ drop (succ m) (a :: as)\n           = (a :: take m as) ++ drop (succ m) (a :: as) : by rw take_cons\n       ... = (a :: take m as) ++ drop m as               : by rw drop_cons\n       ... = a :: (take m as ++ drop m as)               : by rw cons_append\n       ... = a :: as                                     : by rw (HI1 as), }, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  take n xs ++ drop n xs = xs :=\nbegin\n  induction n with m HI1 generalizing xs,\n  { simp, },\n  { induction xs with a as HI2,\n    { simp, },\n    { simp [HI1 as], }, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nlemma conc_take_drop_1 :\n  \u2200 (n : \u2115) (xs : list \u03b1), take n xs ++ drop n xs = xs\n| 0 xs := by calc\n    take 0 xs ++ drop 0 xs\n        = [] ++ drop 0 xs   : by rw take_zero\n    ... = [] ++ xs          : by rw drop_zero\n    ... = xs                : by rw nil_append\n| (succ m) [] := by calc\n    take (succ m) [] ++ drop (succ m) []\n        = ([] : list \u03b1) ++ drop (succ m) [] : by rw take_nil\n    ... = [] ++ []                          : by rw drop_nil\n    ... = []                                : by rw nil_append\n| (succ m) (a :: as) := by calc\n    take (succ m) (a :: as) ++ drop (succ m) (a :: as)\n        = (a :: take m as) ++ drop (succ m) (a :: as)    : by rw take_cons\n    ... = (a :: take m as) ++ drop m as                  : by rw drop_cons\n    ... = a :: (take m as ++ drop m as)                  : by rw cons_append\n    ... = a :: as                                        : by rw conc_take_drop_1\n\n-- 5\u00aa demostraci\u00f3n\nlemma conc_take_drop_2 :\n  \u2200 (n : \u2115) (xs : list \u03b1), take n xs ++ drop n xs = xs\n| 0        xs        := by simp\n| (succ m) []        := by simp\n| (succ m) (a :: as) := by simp [conc_take_drop_2]\n\n-- 6\u00aa demostraci\u00f3n\nlemma conc_take_drop_3 :\n  \u2200 (n : \u2115) (xs : list \u03b1), take n xs ++ drop n xs = xs\n| 0        xs        := rfl\n| (succ m) []        := rfl\n| (succ m) (a :: as) := congr_arg (cons a) (conc_take_drop_3 m as)\n\n-- 7\u00aa demostraci\u00f3n\nexample : take n xs ++ drop n xs = xs :=\n-- by library_search\ntake_append_drop n xs\n\n-- 8\u00aa demostraci\u00f3n\nexample : take n xs ++ drop n xs = xs :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Pruebas_de_take_n_xs_++_drop_n_xs_Ig_xs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024556, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.7222485878238992}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Kudzo Ahegbebu, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport minif2f_import\n\nopen_locale big_operators\nopen_locale nat\nopen_locale real\nopen_locale rat\n\ntheorem mathd_algebra_478\n  (b h v : \u211d)\n  (h\u2080 : 0 < b \u2227 0 < h \u2227 0 < v)\n  (h\u2081 : v = 1 / 3 * (b * h))\n  (h\u2082 : b = 30)\n  (h\u2083 : h = 13 / 2) :\n  v = 65 :=\nbegin\n  rw [h\u2082, h\u2083] at h\u2081,\n  rw h\u2081,\n  norm_num,\nend\n\ntheorem numbertheory_4x3m7y3neq2003\n  (x y : \u2124) :\n  4 * x^3 - 7 * y^3 \u2260 2003 :=\nbegin\n  intro hneq,\n  apply_fun (coe : \u2124 \u2192 zmod 7) at hneq,\n  push_cast at hneq,\n  have : (2003 : zmod 7) = (1 : zmod 7),\n    dec_trivial,\n  rw this at hneq,\n  have : (7 : zmod 7) = (0 : zmod 7),\n    dec_trivial,\n  rw this at hneq,\n  rw zero_mul at hneq,\n  rw sub_zero at hneq,\n  have main : \u2200 (x : zmod 7), x^3 \u2208 [(0 : zmod 7), 1, -1],\n    dec_trivial,\n  rcases main x with h' | h' | h' | h,\n  iterate 3 {\n    rw h' at hneq,\n    revert hneq,\n    dec_trivial,\n  },\n  exact h,\nend\n\ntheorem aime_1983_p1\n  (x y z w : \u2115)\n  (ht : 1 < x \u2227 1 < y \u2227 1 < z)\n  (hw : 0 \u2264 w)\n  (h0 : real.log w / real.log x = 24)\n  (h1 : real.log w / real.log y = 40)\n  (h2 : real.log w / real.log (x * y * z) = 12):\n  real.log w / real.log z = 60 :=\nbegin\n  sorry\nend\n\ntheorem amc12_2001_p5 :\n  finset.prod (finset.filter (\u03bb x, \u00ac even x) (finset.range 10000)) (id : \u2115 \u2192 \u2115) = (10000!) / ((2^5000) * 5000!) :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_141\n  (a b : \u211d)\n  (h\u2081 : (a * b)=180)\n  (h\u2082 : 2 * (a + b)=54) :\n  (a^2 + b^2) = 369 :=\nbegin\n  replace h\u2082 : (a + b) = 27 , linarith,\n  have h\u2083 : a^2 + b^2 = (a + b)^2 - 2 * (a * b), by ring,\n  rw [h\u2083, h\u2082, h\u2081],\n  norm_num,\nend\n\ntheorem mathd_numbertheory_3 :\n  (\u2211 x in finset.range 10, ((x + 1)^2)) % 10 = 5 :=\nbegin\n  dec_trivial!,\nend\n\ntheorem imo_1969_p2\n  (m n : \u211d)\n  (k : \u2115)\n  (a : \u2115 \u2192 \u211d)\n  (y : \u211d \u2192 \u211d)\n  (h\u2080 : 0 < k)\n  (h\u2081 : \u2200 x, y x = \u2211 i in finset.range k, ((real.cos (a i + x)) / (2^i)))\n  (h\u2082 : y m = 0)\n  (h\u2083 : y n = 0) :\n  \u2203 t : \u2124, m - n = t * \u03c0 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_209\n  (\u03c3 : equiv \u211d \u211d)\n  (h\u2080 : \u03c3.2 2 = 10)\n  (h\u2081 : \u03c3.2 10 = 1)\n  (h\u2082 : \u03c3.2 1 = 2) :\n  \u03c3.1 (\u03c3.1 10) = 1 :=\nbegin\n  rw [\u2190 h\u2080, \u2190 h\u2082],\n  simp,\nend\n\ntheorem mathd_numbertheory_1124\n  (n : \u2115)\n  (h\u2080 : n \u2264 9)\n  (h\u2081 : 18\u2223374 * 10 + n) :\n  n = 4 :=\nbegin\n  sorry\nend\n\ntheorem imo_1983_p6\n  (a b c : \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c)\n  (h\u2081 : c < a + b)\n  (h\u2082 : b < a + c)\n  (h\u2083 : a < b + c) :\n  0 \u2264 a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a) :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_237 :\n  (\u2211 k in (finset.range 101), k) % 6 = 4 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_33\n  (x y z : \u211d)\n  (h\u2080 : x \u2260 0)\n  (h\u2081 : 2 * x = 5 * y)\n  (h\u2082 : 7 * y = 10 * z) :\n  z / x = 7 / 25 :=\nbegin\n  field_simp,\n  nlinarith,\nend\n\ntheorem amc12b_2021_p3\n  (x : \u211d)\n  (h\u2080 : 2 + 1 / (1 + 1 / (2 + 2 / (3 + x))) = 144 / 53) :\n  x = 3 / 4 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_299 :\n  (1 * 3 * 5 * 7 * 9 * 11 * 13) % 10 = 5 :=\nbegin\n  norm_num,\nend\n\ntheorem amc12b_2020_p2 :\n  ((100 ^ 2 - 7 ^ 2):\u211d) / (70 ^ 2 - 11 ^ 2) * ((70 - 11) * (70 + 11) / ((100 - 7) * (100 + 7))) = 1 :=\nbegin\n  norm_num,\nend\n\ntheorem algebra_sqineq_unitcircatbpabsamblt1\n  (a b: \u211d)\n  (h\u2080 : a^2 + b^2 = 1) :\n  a * b + \u2225a - b\u2225 \u2264 1 :=\nbegin\n  sorry\nend\n\ntheorem imo_1977_p6\n  (f : \u2115+ \u2192 \u2115+)\n  (h\u2080 : \u2200 n, f (f n) < f (n + 1)) :\n  \u2200 n, f n = n :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_419\n  (a b : \u211d)\n  (h\u2080 : a = -1)\n  (h\u2081 : b = 5) :\n  -a - b^2 + 3 * (a * b) = -39 :=\nbegin\n  rw [h\u2080, h\u2081],\n  norm_num,\nend\n\ntheorem amc12a_2020_p10\n  (n : \u2115+)\n  (h\u2080 : real.log (real.log n / real.log 16) / real.log 2 = real.log (real.log n / real.log 4) / real.log 4) :\n  n = 256 :=\nbegin\n  sorry\nend\n\ntheorem imo_1960_p2\n  (x : \u211d)\n  (h\u2080 : 0 \u2264 1 + 2 * x)\n  (h\u2081 : (1 - real.sqrt (1 + 2 * x))^2 \u2260 0)\n  (h\u2082 : (4 * x^2) / (1 - real.sqrt (1 + 2*x))^2 < 2*x + 9) :\n  -(1 / 2) \u2264 x \u2227 x < 45 / 8 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_427\n  (a : \u2115)\n  (h\u2080 : a = (\u2211 k in (nat.divisors 500), k)) :\n  \u2211 k in finset.filter (\u03bb x, nat.prime x) (nat.divisors a), k = 25 :=\nbegin\n  sorry\nend\n\ntheorem numbertheory_x5neqy2p4\n  (x y : \u2124) :\n  x^5 \u2260 y^2 + 4 :=\nbegin\n  sorry\nend\n\ntheorem imo_2007_p6\n  (a : \u2115 \u2192 nnreal)\n  (h\u2080 : \u2211 x in finset.range 100, ((a (x + 1))^2) = 1) :\n  \u2211 x in finset.range 99, ((a (x + 1))^2 * a (x + 2)) + (a 100)^2 * a 1 < 12 / 25 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_398\n  (a b c : \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c)\n  (h\u2081 : 9 * b = 20 * c)\n  (h\u2082 : 7 * a = 4 * b) :\n  63 * a = 80 * c :=\nbegin\n  linarith,\nend\n\ntheorem imo_1963_p5 :\n  real.cos (\u03c0 / 7) - real.cos (2 * \u03c0 / 7) + real.cos (3 * \u03c0 / 7) = 1 / 2 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_430\n  (a b c : \u2115)\n  (h\u2080 : 1 \u2264 a \u2227 a \u2264 9)\n  (h\u2081 : 1 \u2264 b \u2227 b \u2264 9)\n  (h\u2082 : 1 \u2264 c \u2227 c \u2264 9)\n  (h\u2083 : a \u2260 b)\n  (h\u2084 : a \u2260 c)\n  (h\u2085 : b \u2260 c)\n  (h\u2086 : a + b = c)\n  (h\u2087 : 10 * a + a - b = 2 * c)\n  (h\u2088 : c * b = 10 * a + a + a) :\n  a + b + c = 8 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_459\n  (a b c d : \u211a)\n  (h\u2080 : 3 * a = b + c + d)\n  (h\u2081 : 4 * b = a + c + d)\n  (h\u2082 : 2 * c = a + b + d)\n  (h\u2083 : 8 * a + 10 * b + 6 * c = 24) :\n  \u2191d.denom + d.num = 28 :=\nbegin\n  have h\u2084: d = 13/15, linarith,\n  sorry\nend\n\ntheorem induction_12dvd4expnp1p20\n  (n : \u2115) :\n  12 \u2223 4^(n+1) + 20 :=\nbegin\n  have dvd_of_dvd_add_mul_left : \u2200 (a b n : \u2115), a \u2223 b + a * n \u2192 a \u2223 b :=\n  begin\n    intros a b n,\n    refine (nat.dvd_add_left _).mp,\n    exact (dvd_mul_right a n),\n  end,\n  induction n with k IH,\n  { dec_trivial },\n  {\n    rw pow_succ,\n    -- If we add 60 to RHS, then we can factor the 4 to use IH\n    apply dvd_of_dvd_add_mul_left 12 (4 * 4 ^ k.succ + 20) 5,\n    exact dvd_mul_of_dvd_right IH 4,\n  }\nend\n\ntheorem mathd_algebra_320\n  (x : nnreal)\n  (a b c : \u2115+)\n  (h\u2080 : 2 * x^2 = 4 * x + 9)\n  (h\u2081 : x = (a + nnreal.sqrt b) / c) :\n  a + b + c = 26 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_137\n  (x : \u2115)\n  (h\u2080 : \u2191x + (4:\u211d) / (100:\u211d) * \u2191x = 598) :\n  x = 575 :=\nbegin\n  have h\u2081 : \u2191x = (575:\u211d), linarith,\n  assumption_mod_cast,\nend\n\ntheorem imo_1997_p5\n  (x y : \u2115)\n  (h\u2080 : 0 < x \u2227 0 < y)\n  (h\u2081 : x^(y^2) = y^x) :\n  (x, y) = (1, 1) \u2228 (x, y) = (16, 2) \u2228 (x, y) = (27, 3) :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_277\n  (m n : \u2115)\n  (h\u2080 : nat.gcd m n = 6)\n  (h\u2081 : nat.lcm m n = 126) :\n  60 \u2264 m + n :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_559\n  (x y : \u2115)\n  (h\u2080 : x % 3 = 2)\n  (h\u2081 : y % 5 = 4)\n  (h\u2082 : x % 10 = y % 10) :\n  14 \u2264 x :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_160\n  (n x : \u211d)\n  (h\u2080 : n + x = 97)\n  (h\u2081 : n + 5 * x = 265) :\n  n + 2 * x = 139 :=\nbegin\n  linarith,\nend\n\ntheorem mathd_algebra_24\n  (x : \u211d)\n  (h\u2080 : x / 50 = 40) :\n  x = 2000 :=\nbegin\n  nlinarith,\nend\n\ntheorem mathd_algebra_176\n  (x : \u211d) :\n  (x + 1)^2 * x = x^3 + 2 * x^2 + x :=\nbegin\n  ring_nf,\nend\n\ntheorem induction_nfactltnexpnm1ngt3\n  (n : \u2115)\n  (h\u2080 : 3 \u2264 n) :\n  nat.factorial n < n^(n - 1) :=\nbegin\n  induction h\u2080 with k h\u2080 IH,\n  { norm_num },\n  {\n    have k_ge_one : 1 \u2264 k := le_trans dec_trivial h\u2080,\n    calc k.succ.factorial = k.succ * k.factorial : rfl\n                      ... < k.succ * k ^ (k-1) : (mul_lt_mul_left (nat.succ_pos k)).mpr IH\n                      ... \u2264 k.succ * (k.succ) ^ (k-1): nat.mul_le_mul_left _ $ nat.pow_le_pow_of_le_left (nat.le_succ k) (k-1)\n                      ... = k.succ ^ (k-1 + 1): by rw \u2190 (pow_succ k.succ (k-1))\n                      ... = k.succ ^ k: by rw nat.sub_add_cancel k_ge_one,\n  }\nend\n\ntheorem mathd_algebra_208 :\n  real.sqrt 1000000 - 1000000^((1:\u211d)/3) = 900 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_353\n  (s : \u2115)\n  (h\u2080 : s = \u2211 k in finset.range 4019 \\ finset.range 2010, k) :\n  s % 2009 = 0 :=\nbegin\n  sorry\nend\n\ntheorem numbertheory_notequiv2i2jasqbsqdiv8\n  (a b : \u2124) :\n  \u00ac ((\u2203 i j, a = 2*i \u2227 b=2*j) \u2194 (\u2203 k, a^2 + b^2 = 8*k)) :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_156\n  (x y : \u211d)\n  (f g : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200t, f t = t^4)\n  (h\u2081 : \u2200t, g t = 5 * t^2 - 6)\n  (h\u2082 : f x = g x)\n  (h\u2083 : f y = g y)\n  (h\u2084 : x^2 < y^2) :\n  y^2 - x^2 = 1 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_12 :\n  finset.card (finset.filter (\u03bb x, 20\u2223x) (finset.range 86 \\ finset.range 15)) = 4 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_345 :\n  (2000 + 2001 + 2002 + 2003 + 2004 + 2005 + 2006) % 7 = 0 :=\nbegin\n  norm_num,\nend\n\ntheorem mathd_numbertheory_447 :\n  \u2211 k in finset.filter (\u03bb x, 3\u2223x) (finset.erase (finset.range 50) 0), (k % 10) = 78 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_328 :\n  (5^999999) % 7 = 6 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_451\n  (h\u2080 : fintype {n : \u2115 | 2010 \u2264 n \u2227 n \u2264 2019 \u2227 \u2203 m, (finset.card (nat.divisors m) = 4 \u2227 \u2211 p in (nat.divisors m), p = n)}) :\n  \u2211 k in {n : \u2115 | 2010 \u2264 n \u2227 n \u2264 2019 \u2227 \u2203 m, (finset.card (nat.divisors m) = 4 \u2227 \u2211 p in (nat.divisors m), p = n)}.to_finset, k = 2016 :=\nbegin\n  sorry\nend\n\ntheorem aime_1997_p9\n  (a : \u211d)\n  (h\u2080 : 0 < a)\n  (h\u2081 : 1 / a - int.floor (1 / a) = a^2 - int.floor (a^2))\n  (h\u2082 : 2 < a^2)\n  (h\u2083 : a^2 < 3) :\n  a^12 - 144 * (1 / a) = 233 :=\nbegin\n  sorry\nend\n\ntheorem algebra_sqineq_at2malt1\n  (a : \u211d) :\n  a * (2 - a) \u2264 1 :=\nbegin\n  suffices: 0 \u2264 a^2 - 2*a + 1, nlinarith,\n  suffices: 0 \u2264 (a - 1)^2, nlinarith,\n  nlinarith,\nend\n\ntheorem algebra_apbmpcneq0_aeq0anbeq0anceq0\n  (a b c : \u211a)\n  (m n : \u211d)\n  (h\u2080 : 0 < m \u2227 0 < n)\n  (h\u2081 : m^3 = 2)\n  (h\u2082 : n^3 = 4)\n  (h\u2083 : (a:\u211d) + b * m + c * n = 0) :\n  a = 0 \u2227 b = 0 \u2227 c = 0 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_171\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200x, f x = 5 * x + 4) :\n  f 1 = 9 :=\nbegin\n  rw h\u2080,\n  linarith,\nend\n\ntheorem mathd_numbertheory_227\n  (x y n : \u2115+)\n  (h\u2080 : \u2191x / (4:\u211d) + y / 6 = (x + y) / n) :\n  n = 5 :=\nbegin\n  field_simp at h\u2080,\n  have h\u2082 : (6:\u211d) * x * (n - 4) = 4 * y * (6 - n), {\n    field_simp,\n    ring_nf,\n    linarith[h\u2080],\n  },\n  have p\u2081 : (0:\u211d) < y, norm_num,\n  have p\u2082 : (0:\u211d) < x, norm_num,\n  have repl\u2081: \u2191(6:\u2115+) = (6:\u2115), {\n    apply @pnat.to_pnat'_coe 6,\n    norm_num,\n  },\n  have repl\u2082: \u2191(4:\u2115+) = (4:\u2115), {\n    apply @pnat.to_pnat'_coe 4,\n    norm_num,\n  },\n  by_contradiction h,\n  change n \u2260 5 at h,\n  by_cases b\u2080 : n < 5,\n  {\n    have k\u2081 : (0:\u211d) < 4 * \u2191y * (6 - \u2191n), {\n      suffices: (0:\u211d) < (6 - \u2191n), {\n        nlinarith [this, p\u2081],\n      },\n      norm_num [b\u2080],\n      norm_cast,\n      rw \u2190 repl\u2081,\n      norm_cast,\n      clear h\u2080 h\u2082 h repl\u2081,\n      suffices: (5:\u2115+) < 6, {\n        exact lt_trans b\u2080 this,\n      },\n      dec_trivial!,\n    },\n    rw \u2190 h\u2082 at k\u2081,\n    have k\u2082 : 6 * \u2191x * (\u2191n - 4) \u2264 (0:\u211d), {\n      suffices: (\u2191n - 4) \u2264 (0:\u211d), {\n        nlinarith [this, p\u2082],\n      },\n      norm_num,\n      norm_cast,\n      rw \u2190 repl\u2082,\n      norm_cast,\n      apply pnat.lt_add_one_iff.mp,\n      suffices : (4 + 1) = (5:\u2115+), {\n        rwa this,\n      },\n      dec_trivial!,\n    },\n    revert k\u2082,\n    contrapose!,\n    intro k\u2083,\n    exact k\u2081,\n  },\n  {\n    have b\u2081: 5 < n, {\n      push_neg at b\u2080,\n      exact (ne.symm h).le_iff_lt.mp b\u2080,\n    },\n    have k\u2081 : 4 * \u2191y * (6 - \u2191n) \u2264 (0:\u211d), {\n      suffices: (6 - \u2191n) \u2264 (0:\u211d), {\n        nlinarith [this, p\u2081],\n      },\n      norm_num,\n      norm_cast,\n      rw \u2190 repl\u2081,\n      norm_cast,\n      exact b\u2081,\n    },\n    have k\u2082 : (0:\u211d) < 6 * \u2191x * (\u2191n - 4), {\n      suffices : (0: \u211d) < (\u2191n - 4), {\n        nlinarith [this, p\u2082],\n      },\n      norm_num,\n      norm_cast,  \n      rw \u2190 repl\u2082,\n      norm_cast,\n      refine lt_trans _ b\u2081,\n      dec_trivial!,\n    },\n    rw \u2190 h\u2082 at k\u2081,\n    revert k\u2082,\n    contrapose!,\n    intro k\u2083,\n    exact k\u2081,\n  },\nend\n\ntheorem mathd_algebra_188\n  (\u03c3 : equiv \u211d \u211d)\n  (h : \u03c3.1 2 = \u03c3.2 2) :\n  \u03c3.1 (\u03c3.1 2) = 2 :=\nbegin\n  simp [h]\nend\n\ntheorem mathd_numbertheory_765\n  (x : \u2124)\n  (h\u2080 : x < 0)\n  (h\u2081 : (24 * x) % 1199 = 15) :\n  x \u2264 -449 :=\nbegin\n  sorry\nend\n\ntheorem imo_1959_p1\n  (n : \u2115+) :\n  nat.gcd (21*n + 4) (14*n + 3) = 1 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_175 :\n  (2^2010) % 10 = 4 :=\nbegin\n  sorry\nend\n\ntheorem induction_sumkexp3eqsumksq\n  (n : \u2115) :\n  \u2211 k in finset.range n, k^3 = (\u2211 k in finset.range n, k)^2 :=\nbegin\n  symmetry,\n  induction n with j IH,\n  {\n    refl,\n  },\n  {\n    calc (\u2211 (k : \u2115) in finset.range j.succ, k)^2 = ((\u2211 (k : \u2115) in finset.range j, k) + j)^2 : by rw finset.sum_range_succ\n   ... = (\u2211 (k : \u2115) in finset.range j, k)^2 + 2 * (\u2211 (k : \u2115) in finset.range j, k) * j + j^2 : by rw add_sq _ _\n   ... = (\u2211 (k : \u2115) in finset.range j, k)^2 +  (\u2211 (k : \u2115) in finset.range j, k) * 2 * j + j^2 : by ring\n   ... = (\u2211 (k : \u2115) in finset.range j, k)^2 + (j * (j-1)) * j + j^2 : by rw finset.sum_range_id_mul_two j\n   ... = (\u2211 (k : \u2115) in finset.range j, k^3) + (j * (j-1)) * j + j^2 : by rw IH\n   ... = (\u2211 (k : \u2115) in finset.range j, k^3) + j^2 * (j-1) + j^2 : by ring_nf\n   ... = (\u2211 (k : \u2115) in finset.range j, k^3) + j^3 : by cases j ; [norm_num, ring_nf]\n   ... = (\u2211 (k : \u2115) in finset.range j.succ, k^3) : by rw \u2190 finset.sum_range_succ,\n  }\nend\n\ntheorem numbertheory_fxeq4powxp6powxp9powx_f2powmdvdf2pown\n  (m n : \u2115)\n  (f : \u2115 \u2192 \u2115)\n  (h\u2080 : \u2200 x, f x = 4^x + 6^x + 9^x)\n  (h\u2081 : 0 < m \u2227 0 < n)\n  (h\u2082 : m \u2264 n) :\n  f (2^m)\u2223f (2^n) :=\nbegin\n  sorry\nend\n\ntheorem imo_1992_p1\n  (p q r : \u2124)\n  (h\u2080 : 1 < p \u2227 p < q \u2227 q < r)\n  (h\u2081 : (p - 1) * (q - 1) * (r - 1)\u2223(p * q * r - 1)) :\n  (p, q, r) = (2, 4, 8) \u2228 (p, q, r) = (3, 5, 15) :=\nbegin\n  sorry\nend\n\ntheorem imo_1982_p1\n  (f : \u2115+ \u2192 \u2115)\n  (h\u2080 : \u2200 m n, f (m + n) - f m - f n = 0 \u2228 f (m + n) - f m - f n = 1)\n  (h\u2081 : f 2 = 0)\n  (h\u2082 : 0 < f 3)\n  (h\u2083 : f 9999 = 3333) :\n  f 1982 = 660 :=\nbegin\n  sorry\nend\n\ntheorem aime_1987_p5\n  (x y : \u2124)\n  (h\u2080 : y^2 + 3 * (x^2 * y^2) = 30 * x^2 + 517):\n  3 * (x^2 * y^2) = 588 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_346\n  (f g : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = 2 * x - 3)\n  (h\u2081 : \u2200 x, g x = x + 1) :\n  g (f 5 - 1) = 7 :=\nbegin\n  rw [h\u2080, h\u2081],\n  norm_num,\nend\n\ntheorem mathd_algebra_487\n  (a b c d : \u211d)\n  (h\u2080 : b = a^2)\n  (h\u2081 : a + b = 1)\n  (h\u2082 : d = c^2)\n  (h\u2083 : c + d = 1) :\n  real.sqrt ((a - c)^2 + (b - d)^2)= real.sqrt 10 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_728 :\n  (29^13 - 5^13) % 7 = 0 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_184\n  (a b : nnreal)\n  (h\u2080 : 0 < a \u2227 0 < b)\n  (h\u2081 : (a^2) = 6*b)\n  (h\u2082 : (a^2) = 54/b) :\n  a = 3 * nnreal.sqrt 2 :=\nbegin\n  have key\u2081 : b \u2260 0 := ne_of_gt h\u2080.2,\n  have h\u2084 : 0 \u2264 a, { exact zero_le _ },\n\n  suffices : a^2=18,\n  {\n    rw eq_comm,\n    have h\u2085 : 3 * nnreal.sqrt 2 = nnreal.sqrt 18,\n    {\n      calc 3 * nnreal.sqrt 2 = (nnreal.sqrt 9) * (nnreal.sqrt 2) : by {rw eq_comm, simp, rw nnreal.sqrt_eq_iff_sq_eq, ring}\n                          ...= nnreal.sqrt (9 * 2): by {rw \u2190 nnreal.sqrt_mul}\n                          ...= nnreal.sqrt 18: by{ring_nf},\n    },\n    rw [h\u2085, nnreal.sqrt_eq_iff_sq_eq],\n    rw \u2190 this,\n    ring,\n  },\n\n  have key\u2082 : (6 * b * b) = 54,\n  {\n    rw h\u2081 at h\u2082,\n    exact (eq_div_iff key\u2081).mp h\u2082,\n  },\n\n  have key\u2083 : b = 3,\n  {\n    have key\u2085 : (6 : nnreal) \u2260 0,\n    {\n      refine nnreal.ne_iff.mp _,\n      norm_num,\n    },\n    calc b = nnreal.sqrt (b * b) : by { rw eq_comm, apply nnreal.sqrt_mul_self}\n          ... = nnreal.sqrt ((6*b*b)/6) : by {refine congr_arg \u21d1nnreal.sqrt _, ring_nf, refine (eq_div_iff _).mpr _,\n          {exact key\u2085},\n          rw mul_comm,\n          }\n          ... = nnreal.sqrt (54/6): by {rw key\u2082}\n          ... = nnreal.sqrt(9) : by {refine congr_arg \u21d1nnreal.sqrt _, refine (div_eq_iff key\u2085).mpr _, ring,}\n          ... = 3 : by {rw nnreal.sqrt_eq_iff_sq_eq, ring},\n  },\n  rw key\u2083 at h\u2081,\n  rw h\u2081,\n  ring,\nend\n\ntheorem mathd_numbertheory_552\n  (f g h : \u2115+ \u2192 \u2115)\n  (h\u2080 : \u2200 x, f x = 12 * x + 7)\n  (h\u2081 : \u2200 x, g x = 5 * x + 2)\n  (h\u2082 : \u2200 x, h x = nat.gcd (f x) (g x))\n  (h\u2083 : fintype (h '' {x : \u2115+ | true})) :\n  \u2211 k in (h '' {x : \u2115+ | true}).to_finset, k = 12 :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2021_p9 :\n  (real.log 80 / real.log 2) / (real.log 2 / real.log 40) - (real.log 160 / real.log 2) / (real.log 2 / real.log 20) = 2 :=\nbegin\n  sorry\nend\n\ntheorem aime_1994_p3\n  (x : \u2124)\n  (f : \u2124 \u2192 \u2124)\n  (h0 : f x + f (x-1) = x^2)\n  (h1 : f 19 = 94):\n  f (94) % 1000 = 561 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_44\n  (s t : \u211d)\n  (h\u2080 : s = 9 - 2 * t)\n  (h\u2081 : t = 3 * s + 1) :\n  s = 1 \u2227 t = 4 :=\nbegin\n  split; linarith,\nend\n\ntheorem mathd_algebra_215\n  (h\u2080 : fintype {x : \u211d | (x + 3)^2 = 121}) :\n  \u2211 k in {x : \u211d | (x + 3)^2 = 121}.to_finset, k = -6 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_293\n  (n : \u2115)\n  (h\u2080 : n \u2264 9)\n  (h\u2081 : 11\u222320 * 100 + 10 * n + 7) :\n  n = 5 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_769 :\n  (129^34 + 96^38) % 11 = 9 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_452\n  (a : \u2115+ \u2192 \u211d)\n  (h\u2080 : \u2200 n, a (n + 2) - a (n + 1) = a (n + 1) - a n)\n  (h\u2081 : a 1 = 2 / 3)\n  (h\u2082 : a 2 = 4 / 5) :\n  a 5 = 11 / 15 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_5\n  (n : \u2115)\n  (h\u2080 : 10 \u2264 n)\n  (h\u2081 : \u2203 x, x^2 = n)\n  (h\u2082 : \u2203 t, t^3 = n) :\n  64 \u2264 n :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_207 :\n  8 * 9^2 + 5 * 9 + 2 = 695 :=\nbegin\n  norm_num,\nend\n\ntheorem mathd_numbertheory_342 :\n  54 % 6 = 0 :=\nbegin\n  norm_num,\nend\n\ntheorem mathd_numbertheory_483\n  (a : \u2115+ \u2192 \u2115+)\n  (h\u2080 : a 1 = 1)\n  (h\u2081 : a 2 = 1)\n  (h\u2082 : \u2200 n, a (n + 2) = a (n + 1) + a n) :\n  ((a 100):\u2115) % 4 = 3 :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2020_p21\n  (h\u2080 : fintype {n : \u2115+ | (\u2191n + (1000:\u211d)) / (70:\u211d) = int.floor (real.sqrt n)}) :\n  finset.card {n : \u2115+ | (\u2191n + (1000:\u211d)) / (70:\u211d) = int.floor (real.sqrt n)}.to_finset = 6 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2003_p5\n  (a m c : \u2115)\n  (h\u2080 : a \u2264 9 \u2227 m \u2264 9 \u2227 c \u2264 9)\n  (h\u2081 : 10*(10*(10*(10*a + m) + c) + 1) + 0 + (10*(10*(10*(10*a + m) + c) + 1) + 2) = 123422) :\n  a + m + c = 14 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_495\n  (a b : \u2115)\n  (h\u2080 : 0 < a \u2227 0 < b)\n  (h\u2081 : a % 10 = 2)\n  (h\u2082 : b % 10 = 4)\n  (h\u2083 : nat.gcd a b = 6) :\n  108 \u2264 nat.lcm a b :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_296 :\n  abs (((3491 - 60) * (3491 + 60) - 3491^2):\u2124) = 3600 :=\nbegin\n  rw abs_of_nonpos,\n  norm_num,\n  norm_num,\nend\n\ntheorem algebra_abpbcpcageq3_sumaonsqrtapbgeq3onsqrt2\n  (a b c : \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c)\n  (h\u2081 : 3 \u2264 a * b + b * c + c * a) :\n  3 / real.sqrt 2 \u2264 a / real.sqrt (a + b) + b / real.sqrt (b + c) + c / real.sqrt (c + a) :=\nbegin\n  sorry\nend\n\ntheorem algebra_2varlineareq_fp3zeq11_3tfm1m5zeqn68_feqn10_zeq7\n  (f z: \u2102)\n  (h\u2080 : f + 3*z = 11)\n  (h\u2081 : 3*(f - 1) - 5*z = -68) :\n  f = -10 \u2227 z = 7 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_247\n  (n : \u2115)\n  (h\u2080 : (3 * n) % 2 = 11) :\n  n % 11 = 8 :=\nbegin\n  sorry\nend\n\ntheorem induction_pord1p1on2powklt5on2\n  (n : \u2115)\n  (h\u2080 : 0 < n) :\n  \u220f k in finset.range (n + 1) \\ finset.range 1, (1 + (1:\u211d) / 2^k) < 5 / 2 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_107\n  (x y : \u211d)\n  (h\u2080 : x^2 + 8 * x + y^2 - 6 * y = 0) :\n  (x + 4)^2 + (y-3)^2 = 5^2 :=\nbegin\n  linarith,\nend\n\ntheorem numbertheory_2pownm1prime_nprime\n  (n : \u2115)\n  (h\u2080 : 0 < n)\n  (h\u2081 : nat.prime (2^n - 1)) :\n  nat.prime n :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_412\n  (x y : \u211d)\n  (h\u2080 : x + y = 25)\n  (h\u2081 : x - y = 11) :\n  x = 18 :=\nbegin\n  linarith,\nend\n\ntheorem amc12a_2013_p4 :\n  (2^2014 + 2^2012) / (2^2014 - 2^2012) = (5:\u211d) / 3 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_392\n  (n : \u2115)\n  (h\u2080 : even n)\n  (h\u2081 : (\u2191n - 2)^2 + \u2191n^2 + (\u2191n + 2)^2 = (12296:\u2124)) :\n  ((\u2191n - 2) * \u2191n * (\u2191n + 2)) / 8 = (32736:\u2124) :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_314\n  (r n : \u2115)\n  (h\u2080 : r = 1342 % 13)\n  (h\u2081 : 0 < n)\n  (h\u2082 : 1342\u2223n)\n  (h\u2083 : n % 13 < r) :\n  6710 \u2264 n :=\nbegin\n  sorry\nend\n\ntheorem induction_prod1p1onk3le3m1onn\n  (n : \u2115)\n  (h\u2080 : 0 < n) :\n  \u220f k in finset.range (n + 1) \\ finset.range 1, (1 + (1:\u211d) / k^3) \u2264 (3:\u211d) - 1 / \u2191n :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_343 :\n  (\u220f k in finset.range 6, (2 * k + 1)) % 10 = 5 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_756\n  (a b : \u211d)\n  (h\u2080 : (2:\u211d)^a = 32)\n  (h\u2081 : a^b = 125) :\n  b^a = 243 :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2002_p7\n  (a b c : \u2115+)\n  (h\u2080 : b = a + 1)\n  (h\u2081 : c = b + 1)\n  (h\u2082 : a * b * c = 8 * (a + b + c)) :\n  a^2 + (b^2 + c^2) = 77 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_80\n  (x : \u211d)\n  (h\u2080 : x \u2260 -1)\n  (h\u2081 : (x - 9) / (x + 1) = 2) :\n  x = -11 :=\nbegin\n  revert x h\u2080 h\u2081,\n  norm_num,\n  intros _ hx,\n  simp [hx, two_mul, sub_eq_add_neg],\n  intro H,\n  rwa [div_eq_iff_mul_eq] at H,\n  linarith,\n  norm_num,\n  intro h,\n  exact hx (add_eq_zero_iff_eq_neg.1 h),\nend\n\ntheorem mathd_numbertheory_457\n  (n : \u2115)\n  (h\u2080 : 0 < n)\n  (h\u2081 : 80325\u2223(n!)) :\n  17 \u2264 n :=\nbegin\n  sorry\nend\n\ntheorem amc12_2000_p12\n  (a m c : \u2115)\n  (h\u2080 : a + m + c = 12) :\n  a*m*c + a*m + m*c + a*c \u2264 112 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_135\n  (n a b c: \u2115)\n  (h\u2080 : n = 3^17 + 3^10)\n  (h\u2081 : 11 \u2223 (n + 1))\n  (h\u2082 : odd a \u2227 odd c)\n  (h\u2083 : \u00ac 3 \u2223 b)\n  (h\u2084 : n = 10*(10*(10*(10*(10*(10*(10*(10*a +b) +c) +a) +c) +c) +b) +a) +b) :\n  10*(10 * a + b) + c = 129 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_275\n  (x : \u211d)\n  (h : ((11:\u211d)^(1 / 4))^(3 * x - 3) = 1 / 5) :\n  ((11:\u211d)^(1 / 4))^(6 * x + 2) = 121 / 25 :=\nbegin\n  revert x h,\n  norm_num,\nend\n\ntheorem mathd_algebra_388\n  (x y z : \u211d)\n  (h\u2080 : 3 * x + 4 * y - 12 * z = 10)\n  (h\u2081 : -2 * x - 3 * y + 9 * z = -4) :\n  x = 14 :=\nbegin\n  linarith,\nend\n\ntheorem amc12a_2020_p7\n  (a : \u2115 \u2192 \u2115)\n  (h\u2080 : (a 0)^3 = 1)\n  (h\u2081 : (a 1)^3 = 8)\n  (h\u2082 : (a 2)^3 = 27)\n  (h\u2083 : (a 3)^3 = 64)\n  (h\u2084 : (a 4)^3 = 125)\n  (h\u2085 : (a 5)^3 = 216)\n  (h\u2086 : (a 6)^3 = 343) :\n  \u2191\u2211 k in finset.range 7, (6 * (a k)^2) - \u2191(2 * \u2211 k in finset.range 6, (a k)^2) = (658:\u2124) :=\nbegin\n  sorry\nend\n\ntheorem imo_1981_p6\n  (f : \u2115 \u2192 \u2115 \u2192 \u2115)\n  (h\u2080 : \u2200 y, f 0 y = y + 1)\n  (h\u2081 : \u2200 x, f (x + 1) 0 = f x 1)\n  (h\u2082 : \u2200 x y, f (x + 1) (y + 1) = f x (f (x + 1) y)) :\n  \u2200 y, f 4 (y + 1) = 2^(f 4 y + 3) - 3 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_263\n  (y : \u211d)\n  (h\u2080 : 0 \u2264 19 + 3 * y)\n  (h\u2081 : real.sqrt (19 + 3 * y) = 7) :\n  y = 10 :=\nbegin\n  revert y h\u2080 h\u2081,\n  intros x hx,\n  rw real.sqrt_eq_iff_sq_eq hx,\n  swap,\n  norm_num,\n  intro h,\n  nlinarith,\nend\n\ntheorem mathd_numbertheory_34\n  (x: \u2115)\n  (h\u2080 : x < 100)\n  (h\u2081 : x*9 % 100 = 1) :\n  x = 89 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_764\n  (p : \u2115)\n  (h\u2080 : nat.prime p)\n  (h\u2081 : 7 \u2264 p) :\n  \u2211 k in finset.erase (finset.range (p - 1)) 0, ((k:zmod p)\u207b\u00b9 * ((k:zmod p) + 1)\u207b\u00b9) = 2 :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2021_p4\n  (m a : \u2115+)\n  (h\u2080 : \u2191m / \u2191a = (3:\u211d) / 4) :\n  (84 * \u2191m + 70 * \u2191a) / (\u2191m + \u2191a) = (76:\u211d) :=\nbegin\n  sorry\nend\n\ntheorem imo_1962_p2\n  (x : \u211d)\n  (h\u2080 : 0 \u2264 3 - x)\n  (h\u2081 : 0 \u2264 x + 1)\n  (h\u2082 : 1 / 2 < real.sqrt (3 - x) - real.sqrt (x + 1)) :\n  -1 \u2264 x \u2227 x < 1 - real.sqrt 31 / 8 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_170\n  (h\u2080 : fintype {n : \u2124 | abs (n - 2) \u2264 5 + 6 / 10}) :\n  finset.card { n : \u2124 | abs (n - 2) \u2264 5 + 6 / 10}.to_finset = 11 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_432\n  (x : \u211d) :\n  (x + 3) * (2 * x - 6) = 2 * x^2 - 18 :=\nbegin\n  linarith,\nend\n\ntheorem mathd_algebra_598\n  (a b c d : \u211d)\n  (h\u2081 : ((4:\u211d)^a) = 5)\n  (h\u2082 : ((5:\u211d)^b) = 6)\n  (h\u2083 : ((6:\u211d)^c) = 7)\n  (h\u2084 : ((7:\u211d)^d) = 8) :\n  a * b * c * d = 3 / 2 :=\nbegin\n  sorry\nend\n\ntheorem algebra_bleqa_apbon2msqrtableqambsqon8b\n  (a b : \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b)\n  (h\u2081 : b \u2264 a) :\n  (a + b) / 2 - real.sqrt (a * b) \u2264 (a - b)^2 / (8 * b) :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_276\n  (a b : \u2124)\n  (h\u2080 : \u2200 x : \u211d, 10 * x^2 - x - 24 = (a * x - 8) * (b * x + 3)) :\n  a + b = 12 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2021_p14 :\n  (\u2211 k in (finset.erase (finset.range 21) 0), (real.log (3^(k^2)) / real.log (5^k))) * \u2211 k in (finset.erase (finset.range 101) 0), (real.log (25^k) / real.log (9^k)) = 21000 :=\nbegin\n  sorry\nend\n\ntheorem algebra_sum1onsqrt2to1onsqrt10000lt198 :\n  \u2211 k in finset.range 10001 \\ finset.range 2, (1 / real.sqrt k) < 198 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_618\n  (n : \u2115)\n  (p : \u2115 \u2192 \u2115)\n  (h\u2080 : \u2200 x, p x = x^2 - x + 41)\n  (h\u2081 : 1 < nat.gcd (p n) (p (n+1))) :\n  41 \u2264 n :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2020_p4\n  (a b c d : \u2115)\n  (h\u2080 : 1 \u2264 a \u2227 a \u2264 9 \u2227 even a)\n  (h\u2081 : 0 \u2264 b \u2227 b \u2264 9 \u2227 even b)\n  (h\u2082 : 0 \u2264 c \u2227 c \u2264 9 \u2227 even c)\n  (h\u2083 : 0 \u2264 d \u2227 d \u2264 9 \u2227 even d)\n  (h\u2084 : fintype {n : \u2115 | n = 10 * (10*(10*a + b) + c) + d \u2227 5\u2223n}) :\n  finset.card {n : \u2115 | n = 10 * (10*(10*a + b) + c) + d \u2227 5\u2223n}.to_finset = 100 :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2020_p6\n  (n : \u2115)\n  (h\u2080 : 9 \u2264 n) :\n  \u2203 x : \u2115, (x:\u211d)^2 = (nat.factorial (n + 2) - nat.factorial (n + 1)) / nat.factorial n :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_435\n  (k : \u2115)\n  (h\u2080 : 0 < k)\n  (h\u2081 : \u2200 n, gcd (6 * n + k) (6 * n + 3) = 1)\n  (h\u2082 : \u2200 n, gcd (6 * n + k) (6 * n + 2) = 1)\n  (h\u2083 : \u2200 n, gcd (6 * n + k) (6 * n + 1) = 1) :\n  5 \u2264 k :=\nbegin\n  sorry\nend\n\ntheorem algebra_others_exirrpowirrrat :\n  \u2203 a b, irrational a \u2227 irrational b \u2227 \u00ac irrational (a^b) :=\nbegin\n  let sqrt_2 :=  real.sqrt 2,\n  by_cases irrational (sqrt_2^sqrt_2),\n  {\n    have h': \u00ac irrational ((sqrt_2^sqrt_2)^sqrt_2),\n    {\n     intro h,\n     rw \u2190 (real.rpow_mul (real.sqrt_nonneg 2) (real.sqrt 2) (real.sqrt 2)) at h,\n     have zlet : 0 \u2264 (2 : \u211d), by norm_num,\n     rw \u2190 (real.sqrt_mul zlet 2) at h,\n     rw real.sqrt_mul_self zlet at h,\n     have x : (real.sqrt 2)^(2 : \u2115) = (real.sqrt 2)^(2 : \u211d), by norm_cast,\n     rw \u2190 x at h,\n     rw real.sq_sqrt zlet at h,\n     have tnotira : \u00ac irrational 2,\n     {\n        convert rat.not_irrational 2,\n        norm_cast,\n     },\n     exact tnotira h,\n    },\n    exact \u27e8(sqrt_2^sqrt_2), sqrt_2, h, irrational_sqrt_two, h'\u27e9,\n  },\n  {\n     exact \u27e8sqrt_2, sqrt_2, irrational_sqrt_two, irrational_sqrt_two, h\u27e9,\n  }\nend\n\ntheorem mathd_algebra_427\n  (x y z : \u211d)\n  (h\u2080 : 3 * x + y = 17)\n  (h\u2081 : 5 * y + z = 14)\n  (h\u2082 : 3 * x + 5 * z = 41) :\n  x + y + z = 12 :=\nbegin\n  have h\u2083 := congr (congr_arg has_add.add h\u2080) h\u2081,\n  linarith,\nend\n\ntheorem mathd_algebra_76\n  (f : \u2124 \u2192 \u2124)\n  (h\u2080 : \u2200n, odd n \u2192 f n = n^2)\n  (h\u2081 : \u2200 n, even n \u2192 f n = n^2 - 4*n -1) :\n  f 4 = -1 :=\nbegin\n  suffices : f 4 = 4^2 - 4*4 - 1, rw this; ring_nf,\n  apply h\u2081,\n  refine even_iff_two_dvd.mpr _,\n  exact two_dvd_bit0,\nend\n\ntheorem mathd_numbertheory_99\n  (n : \u2115)\n  (h\u2080 : (2 * n) % 47 = 15) :\n  n % 47 = 31 :=\nbegin\n  sorry\nend\n\ntheorem algebra_9onxpypzleqsum2onxpy\n  (x y z : \u211d)\n  (h\u2080 : 0 < x \u2227 0 < y \u2227 0 < z) :\n  9 / (x + y + z) \u2264 2 / (x + y) + 2 / (y + z) + 2 / (z + x) :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_233\n  (b : zmod (11^2))\n  (h\u2080 : b = 24\u207b\u00b9) :\n  b = 116 :=\nbegin\n  sorry\nend\n\ntheorem algebra_absapbon1pabsapbleqsumabsaon1pabsa\n  (a b : \u211d) :\n  abs (a + b) / (1 + abs (a + b)) \u2264 abs a / (1 + abs a) + abs b / (1 + abs b) :=\nbegin\n  sorry\nend\n\ntheorem imo_1984_p6\n  (a b c d k m : \u2115)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c \u2227 0 < d)\n  (h\u2081 : odd a \u2227 odd b \u2227 odd c \u2227 odd d)\n  (h\u2082 : a < b \u2227 b < c \u2227 c < d)\n  (h\u2083 : a * d = b * c)\n  (h\u2084 : a + d = 2^k)\n  (h\u2085 : b + c = 2^m) :\n  a = 1 :=\nbegin\n  sorry\nend\n\ntheorem imo_2001_p6\n  (a b c d : \u2115)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c \u2227 0 < d)\n  (h\u2081 : d < c)\n  (h\u2082 : c < b)\n  (h\u2083 : b < a)\n  (h\u2084 : a * c + b * d = (b + d + a - c) * (b + d - a + c)) :\n  \u00ac nat.prime (a * b + c * d) :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_321\n  (n : zmod 1399)\n  (h\u2081 : n = 160\u207b\u00b9) :\n  n = 1058 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_17\n  (a : \u211d)\n  (h\u2080 : real.sqrt (4 + real.sqrt (16 + 16 * a)) + real.sqrt (1 + real.sqrt (1 + a)) = 6) :\n  a = 8 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_153\n  (n : \u211d)\n  (h\u2080 : n = 1 / 3) :\n  int.floor (10 * n) + int.floor (100 * n) + int.floor (1000 * n) + int.floor (10000 * n) = 3702 :=\nbegin\n  sorry\nend\n\ntheorem algebra_sqineq_unitcircatbpamblt1\n  (a b: \u211d)\n  (h\u2080 : a^2 + b^2 = 1) :\n  a * b + (a - b) \u2264 1 :=\nbegin\n  nlinarith [sq_nonneg (a - b)],\nend\n\ntheorem amc12a_2021_p18\n  (f : \u211a \u2192 \u211d)\n  (h\u2080 : \u2200x>0, \u2200y>0, f (x * y) = f x + f y)\n  (h\u2081 : \u2200p, nat.prime p \u2192 f p = p) :\n  f (25 /. 11) < 0 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_329\n  (x y : \u211d)\n  (h\u2080 : 3 * y = x)\n  (h\u2081 : 2 * x + 5 * y = 11) :\n  x + y = 4 :=\nbegin\n  linarith,\nend\n\ntheorem induction_pprime_pdvdapowpma\n  (p a : \u2115)\n  (h\u2080 : 0 < a)\n  (h\u2081 : nat.prime p) :\n  p \u2223 (a^p - a) :=\nbegin\n  sorry,\nend\n\ntheorem amc12a_2021_p9 :\n  \u220f k in finset.range 7, (2^(2^k) + 3^(2^k)) = 3^128 - 2^128 :=\nbegin\n  simp only [finset.prod_range_succ],\n  norm_num,\nend\n\n-- Sum a sequence by grouping adjacent terms.\nlemma sum_pairs (n : \u2115) (f : \u2115 \u2192 \u211a) :\n  \u2211 k in (finset.range (2 * n)), f k = \u2211 k in (finset.range n), (f (2 * k) + f (2 * k + 1)) :=\nbegin\n  induction n with pn hpn,\n  { simp only [finset.sum_empty, finset.range_zero, mul_zero] },\n  { have hs: (2 * pn.succ) = (2 * pn).succ.succ := rfl,\n    rw [finset.sum_range_succ, \u2190hpn, hs, finset.sum_range_succ, finset.sum_range_succ],\n    ring },\nend\n\ntheorem aime_1984_p1\n  (u : \u2115 \u2192 \u211a)\n  (h\u2080 : \u2200 n, u (n + 1) = u n + 1)\n  (h\u2081 : \u2211 k in finset.range 98, u k.succ = 137) :\n  \u2211 k in finset.range 49, u (2 * k.succ) = 93 :=\nbegin\n  -- We will use sum_pairs and h\u2080 to rewrite h\u2081 and the goal in terms of the quantity\n  -- \u2211 k in finset.range 49, u (2 * k + 1).\n\n  have h\u2082 : \u2200 k, k \u2208 finset.range 49 \u2192 u (2 * k + 1 + 1) = u (2 * k + 1) + 1 :=\n  by { intros k hk, exact h\u2080 (2 * k + 1) },\n\n  have h\u2083: \u2211 (x : \u2115) in finset.range 49, (1:\u211a) = 49 := by simp only [mul_one, nat.cast_bit0, finset.sum_const, nsmul_eq_mul, nat.cast_bit1, finset.card_range, nat.cast_one],\n\n  have h98 : 98 = 2 * 49 := by norm_num,\n\n  rw [h98, sum_pairs, finset.sum_add_distrib, finset.sum_congr rfl h\u2082,\n     finset.sum_add_distrib, h\u2083, \u2190add_assoc] at h\u2081,\n\n  have h\u2084 : \u2211 (k : \u2115) in finset.range 49, u (2 * k.succ)\n          = \u2211 (k : \u2115) in finset.range 49, (u (2 * k + 1) + 1) :=\n    finset.sum_congr rfl h\u2082,\n  rw [h\u2084, finset.sum_add_distrib, h\u2083],\n\n  linarith,\nend\n\ntheorem amc12a_2021_p22\n  (a b c : \u211d)\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = x^3 + a * x^2 + b * x + c)\n  (h\u2081 : f\u207b\u00b9' {0} = {real.cos (2 * real.pi / 7), real.cos (4 * real.pi / 7), real.cos (6 * real.pi / 7)}) :\n  a * b * c = 1 / 32 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_229 :\n  (5^30) % 7 = 1 :=\nbegin\n  have five_to_thirty_is_one :\n    (5^30 : zmod 7) = 1 :=\n  begin\n    have five_to_the_six_is_one : (5^6 : zmod 7) = 1, by dec_trivial,\n    have break_power : (5^30 : zmod 7) = (5^6)^5, by norm_num,\n    rw break_power,\n    rw five_to_the_six_is_one,\n    norm_num,\n  end,\n  change 5^30 \u2261 1 [MOD 7],\n  rw \u2190zmod.eq_iff_modeq_nat,\n  exact_mod_cast five_to_thirty_is_one,\nend\n\ntheorem mathd_numbertheory_100\n  (n : \u2115+)\n  (h\u2080 : nat.gcd n 40 = 10)\n  (h\u2081 : nat.lcm n 40 = 280) :\n  n = 70 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_313\n  (v i z : \u2102)\n  (h\u2080 : v = i * z)\n  (h\u2081 : v = 1 + complex.I)\n  (h\u2082 : z = 2 - complex.I) :\n  i = 1/5 + 3/5 * complex.I :=\nbegin\n  rw [h\u2081, h\u2082] at h\u2080,\n  rw eq_comm at h\u2080,\n  have h\u2083 : (2 - complex.I) \u2260 0, {\n    sorry\n  },\n  have h\u2084 := (eq_div_iff h\u2083).mpr h\u2080,\n  rw h\u2084,\n  rw eq_comm,\n  apply (eq_div_iff h\u2083).mpr,\n  sorry\nend\n\ntheorem amc12b_2002_p4\n  (n : \u2115+)\n  (h\u2080 : (1 /. 2 + 1 /. 3 + 1 /. 7 + 1 /. \u2191n).denom = 1) :\n  n = 42 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2002_p6\n  (n : \u2115+) :\n  \u2203 m, (m > n \u2227 \u2203 p, m * p \u2264 m + p) :=\nbegin\n  use (n : \u2115).succ,\n  { apply nat.succ_pos },\n  norm_num,\n  split,\n  { exact_mod_cast (nat.lt_succ_self _) },\n  use 1,\n  rw mul_one,\n  apply nat.succ_le_succ,\n  exact le_of_lt (nat.lt_succ_self n),\nend\n\ntheorem amc12a_2003_p23\n  (h\u2080 : fintype {k : \u2115+ | ((k * k):\u2115) \u2223 (\u220f i in (finset.erase (finset.range 10) 0), i!)}) :\n  finset.card {k : \u2115+ | ((k * k):\u2115) \u2223 (\u220f i in (finset.erase (finset.range 10) 0), i!)}.to_finset = 672 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_129\n  (a : \u211d)\n  (h\u2080 : a \u2260 0)\n  (h\u2081 : 8\u207b\u00b9 / 4\u207b\u00b9 - a\u207b\u00b9 = 1) :\n  a = -2 :=\nbegin\n  field_simp at h\u2081,\n  linarith,\nend\n\ntheorem amc12b_2021_p18\n  (z : \u2102)\n  (h\u2080 : 12 * complex.norm_sq z = 2 * complex.norm_sq (z + 2) + complex.norm_sq (z^2 + 1) + 31) :\n  z + 6 / z = -2 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_484 :\n  real.log 27 / real.log 3 = 3 :=\nbegin\n  rw real.log_div_log,\n  have three_to_three : (27 : \u211d) = (3 : \u211d)^(3 : \u211d), by norm_num,\n  rw three_to_three,\n  have trivial_ineq: (0 : \u211d) < (3 : \u211d), by norm_num,\n  have trivial_neq: (3: \u211d) \u2260 (1 : \u211d), by norm_num,\n  exact real.logb_rpow trivial_ineq trivial_neq,\nend\n\ntheorem mathd_numbertheory_551 :\n  1529 % 6 = 5 :=\nbegin\n  norm_num,\nend\n\ntheorem mathd_algebra_304 :\n  91^2 = 8281 :=\nbegin\n  norm_num,\nend\n\ntheorem amc12a_2021_p8\n  (d : \u2115 \u2192 \u2115)\n  (h\u2080 : d 0 = 0)\n  (h\u2081 : d 1 = 0)\n  (h\u2082 : d 2 = 1)\n  (h\u2083 : \u2200 n\u22653, d n = d (n - 1) + d (n - 3)) :\n  even (d 2021) \u2227 odd (d 2022) \u2227 even (d 2023) :=\nbegin\n  sorry\nend\n\ntheorem algebra_ineq_nto1onlt2m1on\n  (n : \u2115) :\n  (n:\u211d)^((1:\u211d) / n) < 2 - 1 / n :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2002_p19\n  (a b c: \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c)\n  (h\u2081 : a * (b + c) = 152)\n  (h\u2082 : b * (c + a) = 162)\n  (h\u2083 : c * (a + b) = 170) :\n  a * b * c = 720 :=\nbegin\n  nlinarith,\nend\n\ntheorem mathd_numbertheory_341\n  (a b c : \u2115)\n  (h\u2080 : a \u2264 9 \u2227 b \u2264 9 \u2227 c \u2264 9)\n  (h\u2081 : (5^100) % 1000 = 10*(10*a + b) + c) :\n  a + b + c = 13 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_711\n  (m n : \u2115)\n  (h\u2080 : 0 < m \u2227 0 < n)\n  (h\u2081 : gcd m n = 8)\n  (h\u2082 : lcm m n = 112) :\n  72 \u2264 m + n :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2020_p22\n  (t : \u211d) :\n  ((2^t - 3 * t) * t) / (4^t) \u2264 1 / 12 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_113\n  (x : \u211d) :\n  x^2 - 14 * x + 3 \u2265 7^2 - 14 * 7 + 3 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2020_p9\n  (h\u2080 : fintype {x : \u211d | 0 \u2264 x \u2227 x \u2264 2 * real.pi \u2227 real.tan (2 * x) = real.cos (x / 2)}) :\n  finset.card { x : \u211d | 0 \u2264 x \u2227 x \u2264 2 * real.pi \u2227 real.tan (2 * x) = real.cos (x / 2)}.to_finset = 5 :=\nbegin\n  sorry\nend\n\ntheorem amc12_2000_p1\n  (i m o : \u2115)\n  (h\u2080 : i \u2260 0 \u2227 m \u2260 0 \u2227 o \u2260 0)\n  (h\u2081 : i*m*o = 2001) :\n  i+m+o \u2264 671 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2021_p19\n  (h\u2080 : fintype {x : \u211d | 0 \u2264 x \u2227 x \u2264 real.pi \u2227 real.sin (real.pi / 2 * real.cos x) = real.cos (real.pi / 2 * real.sin x)}) :\n  finset.card {x : \u211d | 0 \u2264 x \u2227 x \u2264 real.pi \u2227 real.sin (real.pi / 2 * real.cos x) = real.cos (real.pi / 2 * real.sin x)}.to_finset = 2 :=\nbegin\n  sorry\nend\n\ntheorem algebra_amgm_sumasqdivbgeqsuma\n  (a b c d : \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c \u2227 0 < d) :\n  a^2 / b + b^2 / c + c^2 / d + d^2 / a \u2265 a + b + c + d :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_212 :\n  (16^17 * 17^18 * 18^19) % 10 = 8 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_320\n  (n : \u2115)\n  (h\u2080 : n < 101)\n  (h\u2081 : 101 \u2223 (123456 - n)) :\n  n = 34 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_125\n  (x y : \u2115+)\n  (h\u2080 : 5 * x = y)\n  (h\u2081 : (\u2191x - (3:\u2124)) + (y - (3:\u2124)) = 30) :\n  x = 6 :=\nbegin\n  sorry\nend\n\ntheorem induction_1pxpownlt1pnx\n  (x : \u211d)\n  (n : \u2115+)\n  (h\u2080 : -1 < x) :\n  (1 + \u2191n*x) \u2264 (1 + x)^(n:\u2115) :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_148\n  (c : \u211d)\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = c * x^3 - 9 * x + 3)\n  (h\u2081 : f 2 = 9) :\n  c = 3 :=\nbegin\n  rw h\u2080 at h\u2081,\n  linarith,\nend\n\ntheorem amc12a_2019_p12\n  (x y : \u211d)\n  (h\u2080 : x \u2260 1 \u2227 y \u2260 1)\n  (h\u2081 : real.log x / real.log 2 = real.log 16 / real.log y)\n  (h\u2082 : x * y = 64) :\n  real.log (x / y) / real.log 2 = 20 :=\nbegin\n  sorry\nend\n\ntheorem induction_11div10tonmn1ton\n  (n : \u2115) :\n  11 \u2223 (10^n - (-1 : \u2124)^n) :=\nbegin\n  sorry\nend\n\ntheorem algebra_amgm_sum1toneqn_prod1tonleq1\n  (a : \u2115 \u2192 nnreal)\n  (n : \u2115)\n  (h\u2080 : \u2211 x in finset.range n, a x = n) :\n  \u220f x in finset.range n, a x \u2264 1 :=\nbegin\n  sorry\nend\n\ntheorem imo_1985_p6\n  (f : \u2115+ \u2192 nnreal \u2192 \u211d)\n  (h\u2080 : \u2200 x, f 1 x = x)\n  (h\u2081 : \u2200 x n, f (n + 1) x = f n x * (f n x + 1 / n)) :\n  \u2203! a, \u2200 n, 0 < f n a \u2227 f n a < f (n + 1) a \u2227 f (n + 1) a < 1 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2020_p15\n  (a b : \u2102)\n  (h\u2080 : a^3 - 8 = 0)\n  (h\u2081 : b^3 - 8 * b^2 - 8 * b + 64 = 0) :\n  complex.abs (a - b) \u2264 2 * real.sqrt 21 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_332\n  (x y : nnreal)\n  (h\u2080 : (x + y) / 2 = 7)\n  (h\u2081 : real.sqrt (x * y) = real.sqrt 19) :\n  x^2 * y^2 = 158 :=\nbegin\n  sorry\nend\n\ntheorem algebra_cubrtrp1oncubrtreq3_rcubp1onrcubeq5778\n  (r : \u211d)\n  (h\u2080 : r^((1:\u211d) / 3) + 1 / r^((1:\u211d) / 3) = 3) :\n  r^3 + 1 / r^3 = 5778 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_293\n  (x : nnreal) :\n  real.sqrt (60 * x) * real.sqrt (12 * x) * real.sqrt (63 * x) = 36 * x * real.sqrt (35 * x) :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_440\n  (x : \u211d)\n  (h\u2080 : 3 / 2 / 3 = x / 10) :\n  x = 5 :=\nbegin\n  field_simp at h\u2080,\n  linarith,\nend\n\ntheorem mathd_numbertheory_254 :\n  (239 + 174 + 83) % 10 = 6 :=\nbegin\n  norm_num,\nend\n\ntheorem amc12_2000_p6\n  (p q : \u2115)\n  (h\u2080 : nat.prime p \u2227 nat.prime q)\n  (h\u2081 : 4 \u2264 p \u2227 p \u2264 18)\n  (h\u2082 : 4 \u2264 q \u2227 q \u2264 18) :\n  \u2191p * \u2191q - (\u2191p + \u2191q) \u2260 (194:\u2124) :=\nbegin\n  revert p q h\u2080 h\u2081 h\u2082,\n  intros p q hpq,\n  rintros \u27e8hp, hq\u27e9,\n  rintro \u27e8h, h\u27e9,\n  intro h,\n  have h\u2081 := nat.prime.ne_zero hpq.1,\n  have h\u2082 : q \u2260 0,\n  { rintro rfl, simp * at * },\n  apply h\u2081,\n  revert hpq,\n  intro h,\n  simp * at *,\n  apply h\u2081,\n  have h\u2083 : q = 10 * q,\n  apply eq.symm,\n  all_goals { dec_trivial! },\nend\n\ntheorem aime_1988_p8\n  (f : \u2115+ \u2192 \u2115+ \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x x = x)\n  (h\u2081 : \u2200 x y, f x y = f y x)\n  (h\u2082 : \u2200 x y, (\u2191x + \u2191y) * f x y = y * (f x (x + y))) :\n  f 14 52 = 364 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_114\n  (a : \u211d)\n  (h\u2080 : a = 8) :\n  (16 * (a^2)^((1:\u211d) / 3))^((1:\u211d) / 3) = 4 :=\nbegin\n  rw h\u2080,\n  have k\u2081 : 0 \u2264 (4:\u211d), linarith,\n  have k\u2082 : 0 < 3, linarith,\n  have k\u2083 : (64:\u211d) = 4^(3:\u211d), {\n    suffices : (64:\u211d) = 4^((3:\u2115):\u211d), {\n      rw this,\n      norm_cast,\n    },\n    suffices : (64:\u211d) = 4^(3:\u2115), {\n        rw this,\n        rw eq_comm,\n        exact real.rpow_nat_cast (4:\u211d) 3,\n    },\n    norm_num,\n  },\n  have k\u2084 : (16:\u211d) = 4^2, linarith,\n  have k\u2086 : 0 \u2264 (64:\u211d), linarith,\n  have k\u2087 : ((1:\u211d)/3) = (\u21913)\u207b\u00b9,\n  {\n    norm_cast,\n    exact one_div 3,\n  },\n  have k\u2088 : ((4:\u211d)^(3:\u211d)) = (4:\u211d)^(3:\u2115), {\n    suffices : ((4:\u211d)^((3:\u2115):\u211d)) = ((4:\u211d)^(3:\u2115)), {\n      rw \u2190 this,\n      norm_num,\n    },\n    exact real.rpow_nat_cast (4:\u211d) 3,\n  },\n  have k\u2085 : ((4:\u211d)^(3:\u211d))^((1:\u211d)/3) = (4:\u211d), {\n    rw k\u2087,\n    rw k\u2088,\n    refine real.pow_nat_rpow_nat_inv k\u2081 k\u2082,\n  },\n  norm_num,\n  rw k\u2083,\n  rw k\u2084,\n  rw k\u2085,\n  suffices : (4:\u211d)^2 * (4:\u211d) = 4^3, {\n    rw this,\n    rw k\u2087,\n    refine real.pow_nat_rpow_nat_inv k\u2081 k\u2082,\n  },\n  norm_num,\nend\n\ntheorem imo_2019_p1\n  (f : \u2124 \u2192 \u2124) :\n  (\u2200 a b, f (2 * a) + (2 * f b) = f (f (a + b)) \u2194 (\u2200 z, f z = 0 \\/ \u2203 c, \u2200 z, f z = 2 * z + c)) :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_513\n  (a b : \u211d)\n  (h\u2080 : 3 * a + 2 * b = 5)\n  (h\u2081 : a + b = 2) :\n  a = 1 \u2227 b = 1 :=\nbegin\n  split; linarith,\nend\n\ntheorem mathd_algebra_143\n  (f g : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = x + 1)\n  (h\u2081 : \u2200 x, g x = x^2 + 3) :\n  f (g 2) = 8 :=\nbegin\n  rw [h\u2080, h\u2081],\n  norm_num,\nend\n\ntheorem mathd_algebra_354\n  (a d : \u211d)\n  (h\u2080 : a + 6 * d = 30)\n  (h\u2081 : a + 10 * d = 60) :\n  a + 20 * d = 135 :=\nbegin\n  linarith,\nend\n\ntheorem aime_1984_p7\n  (f : \u2115+ \u2192 \u2115+)\n  (h\u2080 : \u2200 n, 1000 \u2264 n \u2192 f n = n - 3)\n  (h\u2081 : \u2200 n, n < 1000 \u2192 f n = f (f (n + 5))) :\n  f 84 = 997 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_246\n  (a b : \u211d)\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = a * x^4 - b * x^2 + x + 5)\n  (h\u2082 : f (-3) = 2) :\n  f 3 = 8 :=\nbegin\n  rw h\u2080 at h\u2082,\n  simp at h\u2082,\n  rw h\u2080,\n  linarith,\nend\n\ntheorem aime_1983_p3\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = (x^2 + (18 * x +  30) - 2 * real.sqrt (x^2 + (18 * x + 45))))\n  (h\u2081 : fintype (f\u207b\u00b9' {0})) :\n  \u220f x in (f\u207b\u00b9' {0}).to_finset, x = 20 :=\nbegin\n  sorry\nend\n\ntheorem numbertheory_3pow2pownm1mod2pownp3eq2pownp2\n  (n : \u2115)\n  (h\u2080 : 0 < n) :\n  (3^(2^n) - 1) % (2^(n + 3)) = 2^(n + 2) :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_85 :\n  1 * 3^3 + 2 * 3^2 + 2*3 + 2 = 53 :=\nbegin\n  norm_num,\nend\n\ntheorem amc12_2001_p21\n  (a b c d : \u2115)\n  (h\u2080 : a*b*c*d = nat.factorial 8)\n  (h\u2081 : a*b + a + b = 524)\n  (h\u2082 : b*c + b + c = 146)\n  (h\u2083 : c*d + c + d = 104) :\n  \u2191a - \u2191d = (10:\u2124) :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_239 :\n  (\u2211 k in finset.erase (finset.range 13) 0, k) % 4 = 2 :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2002_p2\n  (x : \u2124)\n  (h\u2080 : x = 4) :\n  (3 * x - 2) * (4 * x + 1) - (3 * x - 2) * (4 * x) + 1 = 11 :=\nbegin\n  rw h\u2080,\n  linarith,\nend\n\ntheorem mathd_algebra_196\n  (h\u2080 : fintype {x : \u211d | abs (2 - x) = 3}) :\n  \u2211 k in {x : \u211d | abs (2 - x) = 3}.to_finset, k = 4 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_342\n  (a d: \u211d)\n  (h\u2080 : \u2211 k in (finset.range 5), (a + k * d) = 70)\n  (h\u2081 : \u2211 k in (finset.range 10), (a + k * d) = 210) :\n  a = 42/5 :=\nbegin\n  revert h\u2080 h\u2081,\n  simp [finset.sum_range_succ, mul_comm d],\n  intros,\n  linarith,\nend\n\ntheorem mathd_numbertheory_517 :\n  (121 * 122 * 123) % 4 = 2 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2009_p7\n  (x : \u211d)\n  (n : \u2115+)\n  (a : \u2115+ \u2192 \u211d)\n  (h\u2081 : \u2200 n, a (n + 1) - a n = a (n + 2) - a (n + 1))\n  (h\u2082 : a 1 = 2 * x - 3)\n  (h\u2083 : a 2 = 5 * x - 11)\n  (h\u2084 : a 3 = 3 * x + 1)\n  (h\u2085 : a n = 2009) :\n  n = 502 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_270\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x \u2260 -2, f x = 1 / (x + 2)) :\n  f (f 1) = 3/7 :=\nbegin\n  rw [h\u2080, h\u2080],\n  norm_num,\n  linarith,\n  rw h\u2080,\n  norm_num,\n  linarith,\nend\n\ntheorem amc12a_2021_p12\n  (a b c d : \u211d)\n  (f : \u2102 \u2192 \u2102)\n  (h\u2080 : \u2200 z, f z = z^6 - 10 * z^5 + a * z^4 + b * z^3 + c * z^2 + d * z + 16)\n  (h\u2081 : \u2200 z, f z = 0 \u2192 (z.im = 0 \u2227 0 < z.re \u2227 \u2191(int.floor z.re) = z.re)) :\n  b = 88 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_362\n  (a b : \u211d)\n  (h\u2080 : a^2 * b^3 = 32 / 27)\n  (h\u2081 : a / b^3 = 27 / 4) :\n  a + b = 8 / 3 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_521\n  (m n : \u2115)\n  (h\u2080 : even m)\n  (h\u2081 : even n)\n  (h\u2082 : m - n = 2)\n  (h\u2083 : m * n = 288) :\n  m = 18 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2002_p13\n  (a b : \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b)\n  (h\u2081 : a \u2260 b)\n  (h\u2082 : abs (a - 1/a) = 1)\n  (h\u2083 : abs (b - 1/b) = 1) :\n  a + b = real.sqrt 5 :=\nbegin\n  sorry\nend\n\ntheorem imo_1964_p2\n  (a b c : \u211d)\n  (h\u2080 : 0 < a \u2227 0 < b \u2227 0 < c)\n  (h\u2081 : c < a + b)\n  (h\u2082 : b < a + c)\n  (h\u2083 : a < b + c) :\n  a^2 * (b + c - a) + b^2 * (c + a - b) + c^2 * (a + b - c) \u2264 3 * a * b * c :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_289\n  (k t m n : \u2115)\n  (h\u2080 : nat.prime m \u2227 nat.prime n)\n  (h\u2081 : t < k)\n  (h\u2082 : (k^2 : \u2124) - m * k + n = 0)\n  (h\u2083 : (t^2 : \u2124) - m * t + n = 0) :\n  m^n + n^m + k^t + t^k = 20 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2021_p3\n  (x y : \u2115)\n  (h\u2080 : x + y = 17402)\n  (h\u2081 : 10\u2223x)\n  (h\u2082 : x / 10 = y) :\n  \u2191x - \u2191y = (14238:\u2124) :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2008_p25\n  (a b : \u2115+ \u2192 \u211d)\n  (h\u2080 : \u2200 n, a (n + 1) = real.sqrt 3 * a n - b n)\n  (h\u2081 : \u2200 n, b (n + 1) = real.sqrt 3 * b n + a n)\n  (h\u2082 : a 100 = 2)\n  (h\u2083 : b 100 = 4) :\n  a 1 + b 1 = 1 / (2^98) :=\nbegin\n  sorry\nend\n\ntheorem algebra_apbpceq2_abpbcpcaeq1_aleq1on3anbleq1ancleq4on3\n  (a b c : \u211d)\n  (h\u2080 : a \u2264 b \u2227 b \u2264 c)\n  (h\u2081 : a + b + c = 2)\n  (h\u2082 : a * b + b * c + c * a = 1) :\n  0 \u2264 a \u2227 a \u2264 1 / 3 \u2227 1 / 3 \u2264 b \u2227 b \u2264 1 \u2227 1 \u2264 c \u2227 c \u2264 4 / 3 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_66 :\n  194 % 11 = 7 :=\nbegin\n  exact rfl,\nend\n\ntheorem amc12b_2021_p1\n  (h\u2080 : fintype {x : \u2124 | \u2191(abs x) < 3 * real.pi}):\n  finset.card {x : \u2124 | \u2191(abs x) < 3 * real.pi}.to_finset = 19 :=\nbegin\n  sorry\nend\n\ntheorem algebra_apbon2pownleqapownpbpowon2\n  (a b : \u211d)\n  (n : \u2115)\n  (h\u2080 : 0 < a \u2227 0 < b)\n  (h\u2081 : 0 < n) :\n  ((a + b) / 2)^n \u2264 (a^n + b^n) / 2 :=\nbegin\n  sorry\nend\n\ntheorem imo_1968_p5_1\n  (a : \u211d)\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : 0 < a)\n  (h\u2081 : \u2200 x, f (x + a) = 1 / 2 + real.sqrt (f x - (f x)^2)) :\n  \u2203 b > 0, \u2200 x, f (x + b) = f x :=\nbegin\n  sorry\nend\n\ntheorem aime_1990_p15\n  (a b x y : \u211d)\n  (h\u2080 : a * x + b * y = 3)\n  (h\u2081 : a * x^2 + b * y^2 = 7)\n  (h\u2082 : a * x^3 + b * y^3 = 16)\n  (h\u2083 : a * x^4 + b * y^4 = 42) :\n  a * x^5 + b * y^5 = 20 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_235 :\n  (29 * 79 + 31 * 81) % 10 = 2 :=\nbegin\n  norm_num,\nend\n\ntheorem amc12b_2020_p13 :\n  real.sqrt (real.log 6 / real.log 2 + real.log 6 / real.log 3) = real.sqrt (real.log 3 / real.log 2) + real.sqrt (real.log 2 / real.log 3) :=\nbegin\n  sorry\nend\n\ntheorem amc12b_2021_p13\n  (h\u2080 : fintype {x : \u211d | 0 < x \u2227 x \u2264 2 * real.pi \u2227 1 - 3 * real.sin x + 5 * real.cos (3 * x) = 0}) :\n  finset.card {x : \u211d | 0 < x \u2227 x \u2264 2 * real.pi \u2227 1 - 3 * real.sin x + 5 * real.cos (3 * x) = 0}.to_finset = 6 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_234\n  (a b : \u2115)\n  (h\u2080 : 1 \u2264 a \u2227 a \u2264 9 \u2227 b \u2264 9)\n  (h\u2081 : (10 * a + b)^3 = 912673) :\n  a + b = 16 :=\nbegin\n  sorry\nend\n\ntheorem numbertheory_aoddbdiv4asqpbsqmod8eq1\n  (a : \u2124)\n  (b : \u2115)\n  (h\u2080 : odd a)\n  (h\u2081 : 4 \u2223 b) :\n  (a^2 + b^2) % 8 = 1 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_222\n  (b : \u2115)\n  (h\u2080 : nat.lcm 120 b = 3720)\n  (h\u2081 : nat.gcd 120 b = 8) :\n  b = 248 :=\nbegin\n  sorry\nend\n\ntheorem aime_1999_p11\n  (m : \u211a)\n  (h\u2080 : \u2211 k in finset.erase (finset.range 36) 0, real.sin (5 * k * \u03c0 / 180) = real.tan (m * \u03c0 / 180))\n  (h\u2081 : (m.denom:\u211d) / m.num < 90) :\n  \u2191m.denom + m.num = 177 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_359\n  (y : \u211d)\n  (h\u2080 : y + 6 + y = 2 * 12) :\n  y = 9 :=\nbegin\n  linarith,\nend\n\ntheorem imo_1965_p2\n  (x y z : \u211d)\n  (a : \u2115 \u2192 \u211d)\n  (h\u2080 : 0 < a 0 \u2227 0 < a 4 \u2227 0 < a 8)\n  (h\u2081 : a 1 < 0 \u2227 a 2 < 0)\n  (h\u2082 : a 3 < 0 \u2227 a 5 < 0)\n  (h\u2083 : a 7 < 0 \u2227 a 9 < 0)\n  (h\u2084 : 0 < a 0 + a 1 + a 2)\n  (h\u2085 : 0 < a 3 + a 4 + a 5)\n  (h\u2086 : 0 < a 6 + a 7 + a 8)\n  (h\u2087 : a 0 * x + a 1 * y + a 2 * z = 0)\n  (h\u2088 : a 3 * x + a 4 * y + a 5 * z = 0)\n  (h\u2089 : a 6 * x + a 7 * y + a 8 * z = 0) :\n  x = 0 \u2227 y = 0 \u2227 z = 0 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_288\n  (x y : \u211d)\n  (n : nnreal)\n  (h\u2080 : x < 0 \u2227 y < 0)\n  (h\u2081 : abs x = 6)\n  (h\u2082 : real.sqrt ((x - 8)^2 + (y - 3)^2) = 15)\n  (h\u2083 : real.sqrt (x^2 + y^2) = real.sqrt n) :\n  n = 52 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_127 :\n  (\u2211 k in (finset.range 101), 2^k) % 7 = 3 :=\nbegin\n  sorry\nend\n\ntheorem imo_1974_p3\n  (n : \u2115) :\n  \u00ac 5\u2223\u2211 k in finset.range n, (nat.choose (2 * n + 1) (2 * k + 1)) * (2^(3 * k)) :=\nbegin\n  sorry\nend\n\ntheorem aime_1991_p9\n  (x : \u211d)\n  (m : \u211a)\n  (h\u2080 : 1 / real.cos x + real.tan x = 22 / 7)\n  (h\u2081 : 1 / real.sin x + 1 / real.tan x = m) :\n  \u2191m.denom + m.num = 44 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2009_p6\n  (m n p q : \u211d)\n  (h\u2080 : p = 2 ^ m)\n  (h\u2081 : q = 3 ^ n) :\n  p^(2 * n) * (q^m) = 12^(m * n) :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_158\n  (a : \u2115)\n  (h\u2080 : even a)\n  (h\u2081 : \u2191\u2211 k in finset.range 8, (2 * k + 1) - \u2191\u2211 k in finset.range 5, (a + 2 * k) = (4:\u2124)) :\n  a = 8 :=\nbegin\n  sorry\nend\n\ntheorem algebra_absxm1pabsxpabsxp1eqxp2_0leqxleq1\n  (x : \u211d)\n  (h\u2080 : abs (x - 1) + abs x + abs (x + 1) = x + 2) :\n  0 \u2264 x \u2227 x \u2264 1 :=\nbegin\n  sorry\nend\n\ntheorem aime_1990_p4\n  (x : \u211d)\n  (h\u2080 : 0 < x)\n  (h\u2081 : x^2 - 10 * x - 29 \u2260 0)\n  (h\u2082 : x^2 - 10 * x - 45 \u2260 0)\n  (h\u2083 : x^2 - 10 * x - 69 \u2260 0)\n  (h\u2084 : 1 / (x^2 - 10 * x - 29) + 1 / (x^2 - 10 * x - 45) - 2 / (x^2 - 10 * x - 69) = 0) :\n  x = 13 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_541\n  (m n : \u2115)\n  (h\u2080 : 1 < m)\n  (h\u2081 : 1 < n)\n  (h\u2082 : m * n = 2005) :\n  m + n = 406 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_314\n  (n : \u2115)\n  (h\u2080 : n = 11) :\n  (1 / 4)^(n + 1) * 2^(2 * n) = 1 / 4 :=\nbegin\n  rw h\u2080,\n  norm_num,\nend\n\ntheorem amc12_2000_p20\n  (x y z : \u211d)\n  (h\u2080 : 0 < x \u2227 0 < y \u2227 0 < z)\n  (h\u2081 : x + 1/y = 4)\n  (h\u2082 : y + 1/z = 1)\n  (h\u2083 : z + 1/x = 7/3) :\n  x*y*z = 1 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_302 :\n  (complex.I / 2)^2 = -(1 / 4) :=\nbegin\n  norm_num,\nend\n\ntheorem aime_1983_p2\n  (x p : \u211d)\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : 0 < p \u2227 p < 15)\n  (h\u2081 : p \u2264 x \u2227 x \u2264 15)\n  (h\u2082 : f x = abs (x - p) + abs (x - 15) + abs (x - p - 15)) :\n  15 \u2264 f x :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_139\n  (s : \u211d \u2192 \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x\u22600, \u2200y\u22600, s x y = (1/y - 1/x) / (x-y)) :\n  s 3 11 = 1/33 :=\nbegin\n  norm_num [h\u2080],\nend\n\ntheorem amc12a_2021_p25\n  (n : \u2115+)\n  (f : \u2115+ \u2192 \u211d)\n  (h\u2080 : \u2200 n, f n = (\u2211 k in (nat.divisors n), 1)/(n^((1:\u211d)/3)))\n  (h\u2081 : \u2200 p \u2260 n, f p < f n) :\n  n = 2520 :=\nbegin\n  sorry\nend\n\ntheorem amc12a_2020_p25\n  (a : \u211a)\n  (h\u2080 : fintype {x : \u211d | \u2191\u230ax\u230b * (x - \u2191\u230ax\u230b) = \u2191a * x ^ 2})\n  (h\u2081 : \u2211 k in {x : \u211d | \u2191\u230ax\u230b * (x - \u2191\u230ax\u230b) = \u2191a * x^2}.to_finset, k = 420) :\n  \u2191a.denom + a.num = 929 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_150\n  (n : \u2115)\n  (h\u2080 : \u00ac nat.prime (7 + 30 * n)) :\n  6 \u2264 n :=\nbegin\n  sorry\nend\n\ntheorem aime_1989_p8\n  (a b c d e f g : \u211d)\n  (h\u2080 : a + 4 * b + 9 * c + 16 * d + 25 * e + 36 * f + 49 * g = 1)\n  (h\u2081 : 4 * a + 9 * b + 16 * c + 25 * d + 36 * e + 49 * f + 64 * g = 12)\n  (h\u2082 : 9 * a + 16 * b + 25 * c + 36 * d + 49 * e + 64 * f + 81 * g = 123) :\n  16 * a + 25 * b + 36 * c + 49 * d + 64 * e + 81 * f + 100 * g = 334 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_296\n  (n : \u2115)\n  (h\u2080 : 2 \u2264 n)\n  (h\u2081 : \u2203 x, x^3 = n)\n  (h\u2082 : \u2203 t, t^4 = n) :\n  4096 \u2264 n :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_142\n  (m b : \u211d)\n  (h\u2080 : m * 7 + b = -1)\n  (h\u2081 : m * (-1) + b = 7) :\n  m + b = 5 :=\nbegin\n  linarith,\nend\n\ntheorem numbertheory_exk2powkeqapb2mulbpa2_aeq1\n  (a b : \u2115+)\n  (h\u2080 : \u2203 k > 0, 2^k = (a + b^2) * (b + a^2)) :\n  a = 1 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_400\n  (x : \u211d)\n  (h\u2080 : 5 + 500 / 100 * 10 = 110 / 100 * x) :\n  x = 50 :=\nbegin\n  linarith,\nend\n\ntheorem aime_1995_p7\n  (k m n : \u2115+)\n  (t : \u211d)\n  (h0 : nat.gcd m n = 1)\n  (h1 : (1 + real.sin t) * (1 + real.cos t) = 5/4)\n  (h2 : (1 - real.sin t) * (1- real.cos t) = m/n - real.sqrt k):\n  k + m + n = 27 :=\nbegin\n  sorry\nend\n\ntheorem mathd_numbertheory_185\n  (n : \u2115)\n  (h\u2080 : n % 5 = 3) :\n  (2 * n) % 5 = 1 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_441\n  (x : \u211d)\n  (h\u2080 : x \u2260 0) :\n  12 / (x * x) * (x^4 / (14 * x)) * (35 / (3 * x)) = 10 :=\nbegin\n  field_simp,\n  ring_nf,\nend\n\ntheorem mathd_numbertheory_582\n  (n : \u2115)\n  (h\u2080 : 0 < n)\n  (h\u2081 : 3\u2223n) :\n  ((n + 4) + (n + 6) + (n + 8)) % 9 = 0 :=\nbegin\n  sorry\nend\n\ntheorem mathd_algebra_338\n  (a b c : \u211d)\n  (h\u2080 : 3 * a + b + c = -3)\n  (h\u2081 : a + 3 * b + c = 9)\n  (h\u2082 : a + b + 3 * c = 19) :\n  a * b * c = -56 :=\nbegin\n  have ha : a = -4, linarith,\n  have hb : b = 2, linarith,\n  have hc : c = 7, linarith,\n  rw [ha, hb, hc],\n  norm_num,\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/miniF2F/lean/src/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7222031722450118}}
{"text": "import algebra.comm_rings.ideals.basic\nimport algebra.comm_rings.ideals.instances\nimport misc.set\nimport misc.function\n\nuniverses u v\n\nopen function\n\nnamespace comm_ring\n\nlemma product_in_product_of_ideals {R : Type u} [comm_ring R] {I\u2081 I\u2082 : ideal R} \n  : \u2200 {x y : R}, x \u2208 I\u2081.body \u2192 y \u2208 I\u2082.body \u2192 (x * y) \u2208 (I\u2081 * I\u2082).body :=\nbegin\n  intros x y hx hy,\n  apply linear_combination.add_term,\n  exact hx,\n  exact hy,\n  apply linear_combination.empty_sum,\n  rw add_zero,\nend\n\nlemma product_of_ideals_in_intersection {R : Type u} [comm_ring R] {I\u2081 I\u2082 : ideal R}\n  : (\u2191(I\u2081 * I\u2082) : set R) \u2286 \u2191(I\u2081 \u2229 I\u2082) :=\nbegin\n  intros x hx,\n  induction hx with x i\u2081 i\u2082 l hi\u2081 hi\u2082 hl\u2081 hx hl\u2082,\n  exact (I\u2081 \u2229 I\u2082).contains_zero,\n  rw hx,\n  apply (I\u2081 \u2229 I\u2082).add_closure,\n  have trv\u2081 : \u2191(I\u2081 \u2229 I\u2082) = (I\u2081 \u2229 I\u2082).body := rfl, \n  rw [\u2190trv\u2081,ideal_pairwise_inter_set],\n  split,\n  rw mul_comm,\n  apply I\u2081.mul_absorb,\n  exact hi\u2081,\n  apply I\u2082.mul_absorb,\n  exact hi\u2082,\n  exact hl\u2082,\nend\n\nlemma product_of_ideal_extension {R : Type u} [comm_ring R] {I : ideal R}\n  : \u2200 {x y : R}, ((I + princple_ideal x) * (I + princple_ideal y)).body \u2286 (I + princple_ideal (x * y)).body :=\nbegin\n  intros x y z hz,\n  induction hz with z s\u2081 s\u2082 l hs\u2081 hs\u2082 hlcom hz hl,\n  apply ideal.contains_zero,\n  rw hz,\n  apply ideal.add_closure,\n  cases hs\u2081 with i\u2081 rest,\n  cases rest with int\u2081 rest,\n  cases rest with hi\u2081 hint\u2081,\n  cases hint\u2081 with prin\u2081 hrw\u2081,\n  cases (elements_of_princple_ideal prin\u2081) with a\u2081 ha\u2081,\n  cases hs\u2082 with i\u2082 rest,\n  cases rest with int\u2082 rest,\n  cases rest with hi\u2082 hint\u2082,\n  cases hint\u2082 with prin\u2082 hrw\u2082,\n  cases (elements_of_princple_ideal prin\u2082) with a\u2082 ha\u2082,\n  rw [hrw\u2081,hrw\u2082,ha\u2081,ha\u2082],\n  rw mul_dis,\n  apply ideal.add_closure,\n  apply ideal.mul_absorb,\n  existsi i\u2082,\n  existsi (0:R),\n  split,\n  exact hi\u2082,\n  split,\n  apply ideal.contains_zero,\n  rw add_zero,\n  rw [mul_comm,mul_dis],\n  apply ideal.add_closure,\n  apply ideal.mul_absorb,\n  existsi i\u2081,\n  existsi (0:R),\n  split,\n  exact hi\u2081,\n  split,\n  apply ideal.contains_zero,\n  rw add_zero,\n  existsi (0: R),\n  existsi (a\u2081*a\u2082) *(x*y),\n  split,\n  exact I.contains_zero,\n  split,\n  apply princple_ideal_membership,\n  existsi (a\u2081 * a\u2082),\n  refl,\n  rw [add_comm,add_zero],\n  rw mul_assoc,\n  rw mul_comm,\n  rw \u2190 mul_comm y,\n  rw mul_assoc,\n  rw mul_assoc,\n  rw mul_comm,\n  rw mul_comm,\n  rw mul_comm a\u2081 a\u2082,\n  rw mul_comm (a\u2082 * a\u2081),\n  simp [mul_assoc],\n  exact hl,\nend\n\nlemma ideal_extension_proper {R : Type u} [comm_ring R] {I : ideal R} {x : R} \n  : x \u2209 I.body \u2192 I + princple_ideal x \u2260 I :=\nbegin\n  intro hxninI,\n  intro ab,\n  apply hxninI,\n  rw \u2190 ab,\n  existsi (0:R),\n  existsi (x:R),\n  split,\n  apply ideal.contains_zero,\n  split,\n  apply princple_ideal_membership,\n  existsi (1:R),\n  rw [mul_comm,mul_one],\n  rw [add_comm,add_zero],\nend\n\nlemma proper_ext_ideal_not_mem {R : Type u} [comm_ring R] {I : ideal R} {x : R} \n  : I + princple_ideal x \u2260 I \u2192 x \u2209 I.body :=\nbegin\n  intro hpropex,\n  intro ab,\n  apply hpropex,\n  apply ideal_equality,\n  apply set.subset_antisymmetric,\n  split,\n  intros y hy,\n  cases hy with i\u2081 rest,\n  cases rest with i\u2082 rest,\n  cases rest with hi\u2081 rest,\n  cases rest with hi\u2082 hrw,\n  rw hrw,\n  apply ideal.add_closure,\n  exact hi\u2081,\n  cases elements_of_princple_ideal hi\u2082,\n  rw h,\n  apply ideal.mul_absorb,\n  exact ab,\n  intros y hy,\n  existsi y, \n  existsi (0:R),\n  split,\n  exact hy,\n  split,\n  apply ideal.contains_zero,\n  rw add_zero,\nend\n\n\ntheorem elements_of_preimage {R\u2081 : Type u} [l:comm_ring R\u2081] {R\u2082 : Type v} [comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082) (I : ideal R\u2082)\n  : \u2200 {x : R\u2081}, x \u2208 (preimage_of_ideal \u03c6 I).body \u2194 \u03c6 x \u2208 I.body :=\nbegin\n  intro x,\n  split,\n  intro h,\n  exact h,\n  intro h,\n  exact h,\nend\n\ntheorem elements_of_kernel {R\u2081 : Type u} [l:comm_ring R\u2081] {R\u2082 : Type v} [comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082) \n  : \u2200 {x : R\u2081}, x \u2208 (ker \u03c6).body \u2194 \u03c6 x = 0  := \nbegin\n  intro x,\n  have trv : ker \u03c6 = preimage_of_ideal \u03c6 (zero_ideal R\u2082) := rfl,\n  rw trv,\n  rw elements_of_preimage,\n  split,\n  apply zero_ideal_is_just_zero,\n  intro hrw,\n  rw hrw,\n  apply linear_combination.empty_sum,\nend\n\n\ntheorem zero_kernel_injective {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] {\u03c6 : R\u2081 \u2192\u1d63 R\u2082}\n  : ker \u03c6 = zero_ideal R\u2081 \u2192 injective \u21d1\u03c6 :=\nbegin\n  intro h,\n  intros x y hxy,\n  have hxyink\u03c6 : (x + -y) \u2208 (ker \u03c6).body,\n    have sub\u2081 : \u03c6 (x + -y) = 0,\n      have trv : \u03c6.map = \u21d1\u03c6 := rfl,\n      rw \u2190 trv, \n      rw \u03c6.prevs_add,\n      rw trv,\n      rw minus_commutes_with_hom,\n      rw hxy,\n      rw minus_inverse,\n    have sub\u2082 : \u03c6 (x + -y) \u2208 (zero_ideal R\u2082).body,\n      rw sub\u2081,\n      apply linear_combination.empty_sum,\n    exact sub\u2082,\n    apply zero_diff_equal,\n    apply zero_ideal_is_just_zero,\n    rw \u2190 h,\n    assumption,\nend\n\ntheorem zero_ideal_in_all_ideals {R : Type u} [comm_ring R] : \u2200 I : ideal R, (zero_ideal R).body \u2286 I :=\nbegin\n  intros I x hx,\n  have hrw := zero_ideal_is_just_zero hx,\n  rw hrw,\n  apply ideal.contains_zero,\nend  \n\ntheorem set_in_ideal_gen_by_set {R : Type u} [comm_ring R] (S : set R) \n  : S \u2286 ideal_generated_by_set S :=\nbegin\n  intros s hs,\n  apply linear_combination.add_term,\n  trivial,\n  exact hs,\n  apply linear_combination.empty_sum,\n  rw add_zero,\n  rw mul_comm,\n  rw mul_one,\nend\n\n\nend comm_ring", "meta": {"author": "CameronTorrance", "repo": "Schemes", "sha": "f407ce80b8407101231170680b03b55984c42496", "save_path": "github-repos/lean/CameronTorrance-Schemes", "path": "github-repos/lean/CameronTorrance-Schemes/Schemes-f407ce80b8407101231170680b03b55984c42496/src/algebra/comm_rings/ideals/identities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7222031705154512}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport AdvancedAdditionWorld.Level11 -- add_right_eq_zero\nnamespace MyNat\nopen MyNat\n/-!\n# Inequality world\n\n## Level 7: `le_zero`\n\nWe proved `add_right_eq_zero` back in advanced addition world.\nRemember that you can do things like `have h2 := add_right_eq_zero h1`\nif `h1 : a + c = 0`.\n\n### Lemma : le_zero\nFor all naturals `a`, if `a \u2264 0` then `a = 0`.\n-/\nlemma le_zero (a : MyNat) (h : a \u2264 0) : a = 0 := by\n  cases h with\n  | _ c hc =>\n    have hc := hc.symm\n    exact add_right_eq_zero hc\n\n/-!\nNext up [Level 8](./Level8.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.722185424233273}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n\n! This file was ported from Lean 3 source module linear_algebra.free_module.finite.basic\n! leanprover-community/mathlib commit bf2a9e0156cc11bf44893ea1b4b2da8ae655c901\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.FreeModule.Basic\nimport Mathbin.RingTheory.Finiteness\n\n/-!\n# Finite and free modules\n\nWe provide some instances for finite and free modules.\n\n## Main results\n\n* `module.free.choose_basis_index.fintype` : If a free module is finite, then any basis is\n  finite.\n* `module.free.linear_map.free ` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N` is free.\n* `module.free.linear_map.module.finite` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N`\n  is finite.\n-/\n\n\nuniverse u v w\n\nvariable (R : Type u) (M : Type v) (N : Type w)\n\nnamespace Module.Free\n\nsection Ring\n\nvariable [Ring R] [AddCommGroup M] [Module R M] [Module.Free R M]\n\n/-- If a free module is finite, then any basis is finite. -/\nnoncomputable instance [Nontrivial R] [Module.Finite R M] :\n    Fintype (Module.Free.ChooseBasisIndex R M) :=\n  by\n  obtain \u27e8h\u27e9 := id \u2039Module.Finite R M\u203a\n  choose s hs using h\n  exact basisFintypeOfFiniteSpans (\u2191s) hs (choose_basis _ _)\n\nend Ring\n\nsection CommRing\n\nvariable [CommRing R] [AddCommGroup M] [Module R M] [Module.Free R M]\n\nvariable [AddCommGroup N] [Module R N] [Module.Free R N]\n\nvariable {R}\n\n/-- A free module with a basis indexed by a `fintype` is finite. -/\ntheorem Module.Finite.of_basis {R M \u03b9 : Type _} [CommRing R] [AddCommGroup M] [Module R M]\n    [Finite \u03b9] (b : Basis \u03b9 R M) : Module.Finite R M :=\n  by\n  cases nonempty_fintype \u03b9\n  classical\n    refine' \u27e8\u27e8finset.univ.image b, _\u27e9\u27e9\n    simp only [Set.image_univ, Finset.coe_univ, Finset.coe_image, Basis.span_eq]\n#align module.finite.of_basis Module.Finite.of_basis\n\ninstance Module.Finite.matrix {\u03b9\u2081 \u03b9\u2082 : Type _} [Finite \u03b9\u2081] [Finite \u03b9\u2082] :\n    Module.Finite R (Matrix \u03b9\u2081 \u03b9\u2082 R) :=\n  by\n  cases nonempty_fintype \u03b9\u2081\n  cases nonempty_fintype \u03b9\u2082\n  exact Module.Finite.of_basis (Pi.basis fun i => Pi.basisFun R _)\n#align module.finite.matrix Module.Finite.matrix\n\nend CommRing\n\nend Module.Free\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/FreeModule/Finite/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.722159654526181}}
{"text": "-- Teorema del emparedado\n-- ======================\n\nimport data.real.basic\n\nvariables (u v w : \u2115 \u2192 \u211d)\nvariable  (a : \u211d)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la notaci\u00f3n |x| para el valor\n-- absoluto de x.\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Definir la funci\u00f3n\n--    limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop\n-- tal que (limite u c) expresa que c es el l\u00edmite de\n-- la sucesi\u00f3n u.\n-- ----------------------------------------------------\n\ndef limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n\u03bb u c, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - c| \u2264 \u03b5\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Demostrar que si dos sucesiones tienen\n-- el mismo l\u00edmite, entonces las sucesiones que est\u00e1n\n-- comprendidas entre \u00e9stas tambi\u00e9n tienen el mismo\n-- l\u00edmite.\n-- ----------------------------------------------------\n\n-- Nota. En la demostraci\u00f3n se usar\u00e1 el siguiente lema:\nlemma max_ge_iff\n  {p q r : \u2115}\n  : r \u2265 max p q \u2194 r \u2265 p \u2227 r \u2265 q :=\nmax_le_iff\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (hu : limite u a)\n  (hw : limite w a)\n  (h : \u2200 n, u n \u2264 v n)\n  (h' : \u2200 n, v n \u2264 w n) :\n  limite v a :=\nbegin\n  intros \u03b5 h\u03b5,\n  cases hu \u03b5 h\u03b5 with N hN, clear hu,\n  cases hw \u03b5 h\u03b5 with N' hN', clear hw h\u03b5,\n  use max N N',\n  intros n hn,\n  rw max_ge_iff at hn,\n  specialize hN n hn.1,\n  specialize hN' n hn.2,\n  specialize h n,\n  specialize h' n,\n  clear hn,\n  rw abs_le at *,\n  split,\n  { calc -\u03b5\n         \u2264 u n - a : hN.1\n     ... \u2264 v n - a : by linarith, },\n  { calc v n - a\n         \u2264 w n - a : by linarith\n     ... \u2264 \u03b5       : hN'.2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (hu : limite u a)\n  (hw : limite w a)\n  (h : \u2200 n, u n \u2264 v n)\n  (h' : \u2200 n, v n \u2264 w n) :\n  limite v a :=\nbegin\n  intros \u03b5 h\u03b5,\n  cases hu \u03b5 h\u03b5 with N hN, clear hu,\n  cases hw \u03b5 h\u03b5 with N' hN', clear hw h\u03b5,\n  use max N N',\n  intros n hn,\n  rw max_ge_iff at hn,\n  specialize hN n (by linarith),\n  specialize hN' n (by linarith),\n  specialize h n,\n  specialize h' n,\n  rw abs_le at *,\n  split,\n  { linarith, },\n  { linarith, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (hu : limite u a)\n  (hw : limite w a)\n  (h : \u2200 n, u n \u2264 v n)\n  (h' : \u2200 n, v n \u2264 w n) :\n  limite v a :=\nbegin\n  intros \u03b5 h\u03b5,\n  cases hu \u03b5 h\u03b5 with N hN, clear hu,\n  cases hw \u03b5 h\u03b5 with N' hN', clear hw h\u03b5,\n  use max N N',\n  intros n hn,\n  rw max_ge_iff at hn,\n  specialize hN n (by linarith),\n  specialize hN' n (by linarith),\n  specialize h n,\n  specialize h' n,\n  rw abs_le at *,\n  split ; linarith,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (hu : limite u a)\n  (hw : limite w a)\n  (h : \u2200 n, u n \u2264 v n)\n  (h' : \u2200 n, v n \u2264 w n) :\n  limite v a :=\nassume \u03b5,\nassume h\u03b5 : \u03b5 > 0,\nexists.elim (hu \u03b5 h\u03b5)\n  ( assume N,\n    assume hN : \u2200 (n : \u2115), n \u2265 N \u2192 |u n - a| \u2264 \u03b5,\n    exists.elim (hw \u03b5 h\u03b5)\n      ( assume N',\n        assume hN' : \u2200 (n : \u2115), n \u2265 N' \u2192 |w n - a| \u2264 \u03b5,\n        show \u2203 N, \u2200 n, n \u2265 N \u2192 |v n - a| \u2264 \u03b5, from\n          exists.intro (max N N')\n            ( assume n,\n              assume hn : n \u2265 max N N',\n              have h1 : n \u2265 N \u2227 n \u2265 N',\n                from max_ge_iff.mp hn,\n              have h2 : -\u03b5 \u2264 v n - a,\n                { have h2a : |u n - a| \u2264 \u03b5,\n                    from hN n h1.1,\n                  calc -\u03b5\n                       \u2264 u n - a : and.left (abs_le.mp h2a)\n                   ... \u2264 v n - a : by linarith [h n], },\n              have h3 : v n - a \u2264 \u03b5,\n                { have h3a : |w n - a| \u2264 \u03b5,\n                    from hN' n h1.2,\n                  calc v n - a\n                       \u2264 w n - a : by linarith [h' n]\n                   ... \u2264 \u03b5       : and.right (abs_le.mp h3a), },\n              show |v n - a| \u2264 \u03b5,\n                from abs_le.mpr (and.intro h2 h3))))\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/5_Limites/Teorema_del_emparedado.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7221507319263829}}
{"text": "/-\nCopyright (c) 2021 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n-/\nimport measure_theory.constructions.borel_space\n\n/-!\n# Filtration and stopping time\n\nThis file defines some standard definition from the theory of stochastic processes including\nfiltrations and stopping times. These definitions are used to model the amount of information\nat a specific time and is the first step in formalizing stochastic processes.\n\n## Main definitions\n\n* `measure_theory.filtration`: a filtration on a measurable space\n* `measure_theory.adapted`: a sequence of functions `u` is said to be adapted to a\n  filtration `f` if at each point in time `i`, `u i` is `f i`-measurable\n* `measure_theory.filtration.natural`: the natural filtration with respect to a sequence of\n  measurable functions is the smallest filtration to which it is adapted to\n* `measure_theory.stopping_time`: a stopping time with respect to some filtration `f` is a\n  function `\u03c4` such that for all `i`, the preimage of `{j | j \u2264 i}` along `\u03c4` is\n  `f i`-measurable\n* `measure_theory.stopping_time.measurable_space`: the \u03c3-algebra associated with a stopping time\n\n## Tags\n\nfiltration, stopping time, stochastic process\n\n-/\n\nnoncomputable theory\nopen_locale classical measure_theory nnreal ennreal topological_space\n\nnamespace measure_theory\n\n/-- A `filtration` on measurable space `\u03b1` with \u03c3-algebra `m` is a monotone\nsequence of of sub-\u03c3-algebras of `m`. -/\nstructure filtration {\u03b1 : Type*} (\u03b9 : Type*) [preorder \u03b9] (m : measurable_space \u03b1) :=\n(seq : \u03b9 \u2192 measurable_space \u03b1)\n(mono : monotone seq)\n(le : \u2200 i : \u03b9, seq i \u2264 m)\n\nvariables {\u03b1 \u03b2 \u03b9 : Type*} {m : measurable_space \u03b1} [measurable_space \u03b2]\n\nopen topological_space\n\nsection preorder\n\nvariables [preorder \u03b9]\n\ninstance : has_coe_to_fun (filtration \u03b9 m) (\u03bb _, \u03b9 \u2192 measurable_space \u03b1) :=\n\u27e8\u03bb f, f.seq\u27e9\n\n/-- The constant filtration which is equal to `m` for all `i : \u03b9`. -/\ndef const_filtration (m : measurable_space \u03b1) : filtration \u03b9 m :=\n\u27e8\u03bb _, m, monotone_const, \u03bb _, le_rfl\u27e9\n\ninstance : inhabited (filtration \u03b9 m) :=\n\u27e8const_filtration m\u27e9\n\nlemma measurable_set_of_filtration {f : filtration \u03b9 m} {s : set \u03b1} {i : \u03b9}\n  (hs : measurable_set[f i] s) : measurable_set[m] s :=\nf.le i s hs\n\n/-- A measure is \u03c3-finite with respect to filtration if it is \u03c3-finite with respect\nto all the sub-\u03c3-algebra of the filtration. -/\nclass sigma_finite_filtration (\u03bc : measure \u03b1) (f : filtration \u03b9 m) : Prop :=\n(sigma_finite : \u2200 i : \u03b9, sigma_finite (\u03bc.trim (f.le i)))\n\ninstance sigma_finite_of_sigma_finite_filtration (\u03bc : measure \u03b1) (f : filtration \u03b9 m)\n  [hf : sigma_finite_filtration \u03bc f] (i : \u03b9) :\n  sigma_finite (\u03bc.trim (f.le i)) :=\nby apply hf.sigma_finite -- can't exact here\n\n/-- A sequence of functions `u` is adapted to a filtration `f` if for all `i`,\n`u i` is `f i`-measurable. -/\ndef adapted (f : filtration \u03b9 m) (u : \u03b9 \u2192 \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 i : \u03b9, measurable[f i] (u i)\n\nnamespace adapted\n\nlemma add [has_add \u03b2] [has_measurable_add\u2082 \u03b2] {u v : \u03b9 \u2192 \u03b1 \u2192 \u03b2} {f : filtration \u03b9 m}\n  (hu : adapted f u) (hv : adapted f v) : adapted f (u + v):=\n\u03bb i, @measurable.add _ _ _ _ (f i) _ _ _ (hu i) (hv i)\n\nlemma neg [has_neg \u03b2] [has_measurable_neg \u03b2] {u : \u03b9 \u2192 \u03b1 \u2192 \u03b2} {f : filtration \u03b9 m}\n  (hu : adapted f u) : adapted f (-u) :=\n\u03bb i, @measurable.neg _ \u03b1 _ _ _ (f i) _ (hu i)\n\nlemma smul [has_scalar \u211d \u03b2] [has_measurable_smul \u211d \u03b2] {u : \u03b9 \u2192 \u03b1 \u2192 \u03b2} {f : filtration \u03b9 m}\n  (c : \u211d) (hu : adapted f u) : adapted f (c \u2022 u) :=\n\u03bb i, @measurable.const_smul \u211d \u03b2 \u03b1 _ _ _ (f i) _ _ (hu i) c\n\nend adapted\n\nvariable (\u03b2)\n\nlemma adapted_zero [has_zero \u03b2] (f : filtration \u03b9 m) : adapted f (0 : \u03b9 \u2192 \u03b1 \u2192 \u03b2) :=\n\u03bb i, @measurable_zero \u03b2 \u03b1 _ (f i) _\n\nvariable {\u03b2}\n\nnamespace filtration\n\n/-- Given a sequence of functions, the natural filtration is the smallest sequence\nof \u03c3-algebras such that that sequence of functions is measurable with respect to\nthe filtration. -/\ndef natural (u : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (hum : \u2200 i, measurable (u i)) : filtration \u03b9 m :=\n{ seq := \u03bb i, \u2a06 j \u2264 i, measurable_space.comap (u j) infer_instance,\n  mono := \u03bb i j hij, bsupr_le_bsupr' $ \u03bb k hk, le_trans hk hij,\n  le := \u03bb i, bsupr_le (\u03bb j hj s hs, let \u27e8t, ht, ht'\u27e9 := hs in ht' \u25b8 hum j ht) }\n\nlemma adapted_natural {u : \u03b9 \u2192 \u03b1 \u2192 \u03b2} (hum : \u2200 i, measurable[m] (u i)) :\n  adapted (natural u hum) u :=\n\u03bb i, measurable.le (le_bsupr_of_le i (le_refl i) (le_refl _)) (\u03bb s hs, \u27e8s, hs, rfl\u27e9)\n\nend filtration\n\nvariables {\u03bc : measure \u03b1} {f : filtration \u03b9 m}\n\n/-- A stopping time with respect to some filtration `f` is a function\n`\u03c4` such that for all `i`, the preimage of `{j | j \u2264 i}` along `\u03c4` is measurable\nwith respect to `f i`.\n\nIntuitively, the stopping time `\u03c4` describes some stopping rule such that at time\n`i`, we may determine it with the information we have at time `i`. -/\ndef is_stopping_time (f : filtration \u03b9 m) (\u03c4 : \u03b1 \u2192 \u03b9) :=\n\u2200 i : \u03b9, measurable_set[f i] $ {x | \u03c4 x \u2264 i}\n\nlemma is_stopping_time.measurable_set_eq\n  {f : filtration \u2115 m} {\u03c4 : \u03b1 \u2192 \u2115} (h\u03c4 : is_stopping_time f \u03c4) (i : \u2115) :\n  measurable_set[f i] $ {x | \u03c4 x = i} :=\nbegin\n  cases i,\n  { convert (h\u03c4 0),\n    simp only [set.set_of_eq_eq_singleton, le_zero_iff] },\n  { rw (_ : {x | \u03c4 x = i + 1} = {x | \u03c4 x \u2264 i + 1} \\ {x | \u03c4 x \u2264 i}),\n    { exact @measurable_set.diff _ (f (i + 1)) _ _ (h\u03c4 (i + 1))\n        (f.mono (nat.le_succ _) _ (h\u03c4 i)) },\n    { ext, simp only [set.mem_diff, not_le, set.mem_set_of_eq],\n      split,\n      { intro h, simp [h] },\n      { rintro \u27e8h\u2081, h\u2082\u27e9,\n        linarith } } }\nend\n\nlemma is_stopping_time.measurable_set_eq_le\n  {f : filtration \u2115 m} {\u03c4 : \u03b1 \u2192 \u2115} (h\u03c4 : is_stopping_time f \u03c4) {i j : \u2115} (hle : i \u2264 j) :\n  measurable_set[f j] $ {x | \u03c4 x = i} :=\nf.mono hle _ $ h\u03c4.measurable_set_eq i\n\nlemma is_stopping_time_of_measurable_set_eq\n  {f : filtration \u2115 m} {\u03c4 : \u03b1 \u2192 \u2115} (h\u03c4 : \u2200 i, measurable_set[f i] $ {x | \u03c4 x = i}) :\n  is_stopping_time f \u03c4 :=\nbegin\n  intro i,\n  rw show {x | \u03c4 x \u2264 i} = \u22c3 k \u2264 i, {x | \u03c4 x = k}, by { ext, simp },\n  refine @measurable_set.bUnion _ _ (f i) _ _ (set.countable_encodable _) (\u03bb k hk, _),\n  exact f.mono hk _ (h\u03c4 k),\nend\n\nlemma is_stopping_time_const {f : filtration \u03b9 m} (i : \u03b9) :\n  is_stopping_time f (\u03bb x, i) :=\n\u03bb j, by simp\n\nend preorder\n\nnamespace is_stopping_time\n\nlemma max [linear_order \u03b9] {f : filtration \u03b9 m} {\u03c4 \u03c0 : \u03b1 \u2192 \u03b9}\n  (h\u03c4 : is_stopping_time f \u03c4) (h\u03c0 : is_stopping_time f \u03c0) :\n  is_stopping_time f (\u03bb x, max (\u03c4 x) (\u03c0 x)) :=\nbegin\n  intro i,\n  simp_rw [max_le_iff, set.set_of_and],\n  exact @measurable_set.inter _ (f i) _ _ (h\u03c4 i) (h\u03c0 i),\nend\n\nlemma min [linear_order \u03b9] {f : filtration \u03b9 m} {\u03c4 \u03c0 : \u03b1 \u2192 \u03b9}\n  (h\u03c4 : is_stopping_time f \u03c4) (h\u03c0 : is_stopping_time f \u03c0) :\n  is_stopping_time f (\u03bb x, min (\u03c4 x) (\u03c0 x)) :=\nbegin\n  intro i,\n  simp_rw [min_le_iff, set.set_of_or],\n  exact @measurable_set.union _ (f i) _ _ (h\u03c4 i) (h\u03c0 i),\nend\n\nlemma add_const\n  [add_group \u03b9] [preorder \u03b9] [covariant_class \u03b9 \u03b9 (function.swap (+)) (\u2264)]\n  [covariant_class \u03b9 \u03b9 (+) (\u2264)]\n  {f : filtration \u03b9 m} {\u03c4 : \u03b1 \u2192 \u03b9} (h\u03c4 : is_stopping_time f \u03c4) {i : \u03b9} (hi : 0 \u2264 i) :\n  is_stopping_time f (\u03bb x, \u03c4 x + i) :=\nbegin\n  intro j,\n  simp_rw [\u2190 le_sub_iff_add_le],\n  exact f.mono (sub_le_self j hi) _ (h\u03c4 (j - i)),\nend\n\nsection preorder\n\nvariables [preorder \u03b9] {f : filtration \u03b9 m}\n\n/-- The associated \u03c3-algebra with a stopping time. -/\nprotected def measurable_space\n  {\u03c4 : \u03b1 \u2192 \u03b9} (h\u03c4 : is_stopping_time f \u03c4) : measurable_space \u03b1 :=\n{ measurable_set' := \u03bb s, \u2200 i : \u03b9, measurable_set[f i] (s \u2229 {x | \u03c4 x \u2264 i}),\n  measurable_set_empty :=\n    \u03bb i, (set.empty_inter {x | \u03c4 x \u2264 i}).symm \u25b8 @measurable_set.empty _ (f i),\n  measurable_set_compl := \u03bb s hs i,\n    begin\n      rw (_ : s\u1d9c \u2229 {x | \u03c4 x \u2264 i} = (s\u1d9c \u222a {x | \u03c4 x \u2264 i}\u1d9c) \u2229 {x | \u03c4 x \u2264 i}),\n      { refine @measurable_set.inter _ (f i) _ _ _ _,\n        { rw \u2190 set.compl_inter,\n          exact @measurable_set.compl _ _ (f i) (hs i) },\n        { exact h\u03c4 i} },\n      { rw set.union_inter_distrib_right,\n        simp only [set.compl_inter_self, set.union_empty] }\n    end,\n  measurable_set_Union := \u03bb s hs i,\n    begin\n      rw forall_swap at hs,\n      rw set.Union_inter,\n      exact @measurable_set.Union _ _ (f i) _ _ (hs i),\n    end }\n\n@[protected]\nlemma measurable_set {\u03c4 : \u03b1 \u2192 \u03b9} (h\u03c4 : is_stopping_time f \u03c4) (s : set \u03b1) :\n  measurable_set[h\u03c4.measurable_space] s \u2194\n  \u2200 i : \u03b9, measurable_set[f i] (s \u2229 {x | \u03c4 x \u2264 i}) :=\niff.rfl\n\nlemma measurable_space_mono\n  {\u03c4 \u03c0 : \u03b1 \u2192 \u03b9} (h\u03c4 : is_stopping_time f \u03c4) (h\u03c0 : is_stopping_time f \u03c0) (hle : \u03c4 \u2264 \u03c0) :\n  h\u03c4.measurable_space \u2264 h\u03c0.measurable_space :=\nbegin\n  intros s hs i,\n  rw (_ : s \u2229 {x | \u03c0 x \u2264 i} = s \u2229 {x | \u03c4 x \u2264 i} \u2229 {x | \u03c0 x \u2264 i}),\n  { exact @measurable_set.inter _ (f i) _ _ (hs i) (h\u03c0 i) },\n  { ext,\n    simp only [set.mem_inter_eq, iff_self_and, and.congr_left_iff, set.mem_set_of_eq],\n    intros hle' _,\n    exact le_trans (hle _) hle' },\nend\n\nlemma measurable_space_le [encodable \u03b9] {\u03c4 : \u03b1 \u2192 \u03b9} (h\u03c4 : is_stopping_time f \u03c4) :\n  h\u03c4.measurable_space \u2264 m :=\nbegin\n  intros s hs,\n  change \u2200 i, measurable_set[f i] (s \u2229 {x | \u03c4 x \u2264 i}) at hs,\n  rw (_ : s = \u22c3 i, s \u2229 {x | \u03c4 x \u2264 i}),\n  { exact measurable_set.Union (\u03bb i, f.le i _ (hs i)) },\n  { ext x, split; rw set.mem_Union,\n    { exact \u03bb hx, \u27e8\u03c4 x, hx, le_refl _\u27e9 },\n    { rintro \u27e8_, hx, _\u27e9,\n      exact hx } }\nend\n\nsection nat\n\nlemma measurable_set_eq_const {f : filtration \u2115 m}\n  {\u03c4 : \u03b1 \u2192 \u2115} (h\u03c4 : is_stopping_time f \u03c4) (i : \u2115) :\n  measurable_set[h\u03c4.measurable_space] {x | \u03c4 x = i} :=\nbegin\n  rw h\u03c4.measurable_set,\n  intro j,\n  by_cases i \u2264 j,\n  { rw (_ : {x | \u03c4 x = i} \u2229 {x | \u03c4 x \u2264 j} = {x | \u03c4 x = i}),\n    { exact h\u03c4.measurable_set_eq_le h },\n    { ext,\n      simp only [set.mem_inter_eq, and_iff_left_iff_imp, set.mem_set_of_eq],\n      rintro rfl,\n      assumption } },\n  { rw (_ : {x | \u03c4 x = i} \u2229 {x | \u03c4 x \u2264 j} = \u2205),\n    { exact @measurable_set.empty _ (f j) },\n    { ext,\n      simp only [set.mem_empty_eq, set.mem_inter_eq, not_and, not_le, set.mem_set_of_eq, iff_false],\n      rintro rfl,\n      rwa not_le at h } }\nend\n\nend nat\n\nend preorder\n\nsection linear_order\n\nvariable [linear_order \u03b9]\n\nlemma measurable [topological_space \u03b9] [measurable_space \u03b9]\n  [borel_space \u03b9] [order_topology \u03b9] [second_countable_topology \u03b9]\n  {f : filtration \u03b9 m} {\u03c4 : \u03b1 \u2192 \u03b9} (h\u03c4 : is_stopping_time f \u03c4) :\n  measurable[h\u03c4.measurable_space] \u03c4 :=\nbegin\n  refine @measurable_of_Iic \u03b9 \u03b1 _ _ _ h\u03c4.measurable_space _ _ _ _ _,\n  simp_rw [h\u03c4.measurable_set, set.preimage, set.mem_Iic],\n  intros i j,\n  rw (_ : {x | \u03c4 x \u2264 i} \u2229 {x | \u03c4 x \u2264 j} = {x | \u03c4 x \u2264 linear_order.min i j}),\n  { exact f.mono (min_le_right i j) _ (h\u03c4 (linear_order.min i j)) },\n  { ext,\n    simp only [set.mem_inter_eq, iff_self, le_min_iff, set.mem_set_of_eq] }\nend\n\nend linear_order\n\nend is_stopping_time\n\nend measure_theory\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/probability_theory/stopping.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7221507277433975}}
{"text": "constant mynat : Type\n-- https://leanprover.github.io/reference/declarations.html?highlight=assume\n-- (Remember that \u2200 is syntactic sugar for \u03a0, and assume is syntactic sugar for \u03bb.)\nlemma func : nat \u2192 nat :=\nbegin\n  intro n,\n  exact 3*n+2,\nend\n\n#reduce func 5 -- 17\n#reduce func 1 -- 5\n#check func -- func : \u2115 \u2192 \u2115\n-- #eval func 7 -- code generation failed, VM does not have code for 'func'\n\n-- level 3\nlemma example2 (P Q R S T U: Type)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U :=\nbegin\n  suffices q : Q,\n    -- have q := h p,\n    have t := j q, -- <=> have t : T, from j q,\n    have u := l t,\n    show U, from u,\n  show Q, from h p, -- <=> exact h p,\nend\n\n#print example2\n/-\n\u03bb (P Q R S T U : Type) \n(p : P) (h : P \u2192 Q) (i : Q \u2192 R) \n(j : Q \u2192 T) (k : S \u2192 T) (l : T \u2192 U), \n  l (j (h p))\n-/\n\n-- level 4\nexample (P Q R S T U: Type)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U :=\nbegin\n  -- exact l (j (h p)),\n  apply l,\n -- exact j (h p),\n  apply j,\n  -- exact h p,\n  apply h,\n  exact p,\nend\n\n-- level 5\nexample (P Q : Type) : P \u2192 (Q \u2192 P) :=\nbegin\n  intro p, -- let p element in set P\n  intro q, -- let q some element in set Q\n  exact p, -- we already know that p is element in P, from hypothesis \"p\"\nend\n\n-- level 6\nexample (P Q R : Type) : (P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R)) :=\nbegin\n  intros f h p,\n  apply f,\n  -- first case P:\n  exact p,\n  -- second case Q:\n  exact h p,\nend\n-- with refine\nlemma example_refine (P Q R : Type) : (P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R)) :=\nbegin\n  intros f h p,\n  -- refine f p _, exact h p, => goals accomplished\n  -- refine f p (h p), -- => goals accomplished\n  exact f p (h p),\nend\n\n#print example_refine\n-- \u03bb (P Q R : Type) (f : P \u2192 Q \u2192 R) (h : P \u2192 Q) (p : P), f p (h p)\n\n-- with assume\nlemma example_assume (P Q R : Type) : (P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R)) :=\nbegin\n  assume (f' : P \u2192 Q \u2192 R) (h' : P \u2192 Q) (p' : P),\n  exact f' p' (h' p'),\nend\n\n#print example_assume\n-- \u03bb (P Q R : Type) (f' : P \u2192 Q \u2192 R) (h' : P \u2192 Q) (p' : P), f' p' (h' p')\n\n\n-- level 8\nexample (P Q : Type) : (P \u2192 Q) \u2192 ((Q \u2192 empty) \u2192 (P \u2192 empty)) :=\nbegin\n  intros f g h,\n  -- apply g (f _),\n  -- apply h,\n  -- <=>\n  exact g (f h),\nend\n\n-- level 9\nexample (A B C D E F G H I J K L : Type)\n(f1 : A \u2192 B) (f2 : B \u2192 E) (f3 : E \u2192 D) (f4 : D \u2192 A) (f5 : E \u2192 F)\n(f6 : F \u2192 C) (f7 : B \u2192 C) (f8 : F \u2192 G) (f9 : G \u2192 J) (f10 : I \u2192 J)\n(f11 : J \u2192 I) (f12 : I \u2192 H) (f13 : E \u2192 H) (f14 : H \u2192 K) (f15 : I \u2192 L)\n : A \u2192 L :=\n begin\n  intro a,\n  apply f15, -- I\n  -- apply f11, apply f10, -- I <=> same state as in previos row\n  sorry,\n end\n\n -- Advanced proposition world.\n--  Level 9: exfalso and proof by contradiction.\nlemma contra (P Q : Prop) : (P \u2227 \u00ac P) \u2192 Q :=\nbegin\n  sorry,\n  have h : (P \u2227 \u00ac P) \u2192 false, \n  begin\n    rw not_iff_imp_false,\n    intro f,\n    cases p with pt pf,\n  end,\nend\n\n", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/function_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7221507236134743}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module algebra.group_with_zero.semiconj\n! leanprover-community/mathlib commit 70d50ecfd4900dd6d328da39ab7ebd516abe4025\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.GroupWithZero.Units.Basic\nimport Mathlib.Algebra.Group.Semiconj\nimport Mathlib.Init.Classical\n\n/-!\n# Lemmas about semiconjugate elements in a `GroupWithZero`.\n\n-/\n\n\nvariable {\u03b1 M\u2080 G\u2080 M\u2080' G\u2080' F F' : Type _}\n\nnamespace SemiconjBy\n\n@[simp]\ntheorem zero_right [MulZeroClass G\u2080] (a : G\u2080) : SemiconjBy a 0 0 := by\n  simp only [SemiconjBy, mul_zero, zero_mul]\n#align semiconj_by.zero_right SemiconjBy.zero_right\n\n@[simp]\ntheorem zero_left [MulZeroClass G\u2080] (x y : G\u2080) : SemiconjBy 0 x y := by\n  simp only [SemiconjBy, mul_zero, zero_mul]\n#align semiconj_by.zero_left SemiconjBy.zero_left\n\nvariable [GroupWithZero G\u2080] {a x y x' y' : G\u2080}\n\n@[simp]\ntheorem inv_symm_left_iff\u2080 : SemiconjBy a\u207b\u00b9 x y \u2194 SemiconjBy a y x :=\n  Classical.by_cases (fun ha : a = 0 => by simp only [ha, inv_zero, SemiconjBy.zero_left]) fun ha =>\n    @units_inv_symm_left_iff _ _ (Units.mk0 a ha) _ _\n#align semiconj_by.inv_symm_left_iff\u2080 SemiconjBy.inv_symm_left_iff\u2080\n\ntheorem inv_symm_left\u2080 (h : SemiconjBy a x y) : SemiconjBy a\u207b\u00b9 y x :=\n  SemiconjBy.inv_symm_left_iff\u2080.2 h\n#align semiconj_by.inv_symm_left\u2080 SemiconjBy.inv_symm_left\u2080\n\ntheorem inv_right\u2080 (h : SemiconjBy a x y) : SemiconjBy a x\u207b\u00b9 y\u207b\u00b9 := by\n  by_cases ha : a = 0\n  \u00b7 simp only [ha, zero_left]\n  by_cases hx : x = 0\n  \u00b7 subst x\n    simp only [SemiconjBy, mul_zero, @eq_comm _ _ (y * a), mul_eq_zero] at h\n    simp [h.resolve_right ha]\n  \u00b7 have := mul_ne_zero ha hx\n    rw [h.eq, mul_ne_zero_iff] at this\n    exact @units_inv_right _ _ _ (Units.mk0 x hx) (Units.mk0 y this.1) h\n#align semiconj_by.inv_right\u2080 SemiconjBy.inv_right\u2080\n\n@[simp]\ntheorem inv_right_iff\u2080 : SemiconjBy a x\u207b\u00b9 y\u207b\u00b9 \u2194 SemiconjBy a x y :=\n  \u27e8fun h => inv_inv x \u25b8 inv_inv y \u25b8 h.inv_right\u2080, inv_right\u2080\u27e9\n#align semiconj_by.inv_right_iff\u2080 SemiconjBy.inv_right_iff\u2080\n\ntheorem div_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') :\n    SemiconjBy a (x / x') (y / y') := by\n  rw [div_eq_mul_inv, div_eq_mul_inv]\n  exact h.mul_right h'.inv_right\u2080\n#align semiconj_by.div_right SemiconjBy.div_right\n\nend SemiconjBy\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/GroupWithZero/Semiconj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7221193403144338}}
{"text": "/- LoVe Exercise 8: Operational Semantics -/\n\nimport .love08_operational_semantics_demo\n\nnamespace LoVe\n\n\n/- Question 1: Program Equivalence -/\n\n/- For this question, we introduce the notation of program equivalence\n`p\u2081 \u2248 p\u2082`. -/\n\ndef program_equiv (S\u2081 S\u2082 : program) : Prop :=\n\u2200s t, (S\u2081, s) \u27f9 t \u2194 (S\u2082, s) \u27f9 t\n\nlocal infix ` \u2248 ` := program_equiv\n\n/- Program equivalence is a equivalence relation, i.e., it is reflexive,\nsymmetric, and transitive. -/\n\n@[refl] lemma program_equiv.refl {S} :\n  S \u2248 S :=\nassume s t,\nshow (S, s) \u27f9 t \u2194 (S, s) \u27f9 t,\n  by refl\n\n@[symm] lemma program_equiv.symm {S\u2081 S\u2082}:\n  S\u2081 \u2248 S\u2082 \u2192 S\u2082 \u2248 S\u2081 :=\nassume h s t,\nshow (S\u2082, s) \u27f9 t \u2194 (S\u2081, s) \u27f9 t,\n  from iff.symm (h s t)\n\n@[trans] lemma program_equiv.trans {S\u2081 S\u2082 S\u2083} (h\u2081\u2082 : S\u2081 \u2248 S\u2082) (h\u2082\u2083 : S\u2082 \u2248 S\u2083) :\n  S\u2081 \u2248 S\u2083 :=\nassume s t,\nshow (S\u2081, s) \u27f9 t \u2194 (S\u2083, s) \u27f9 t,\n  from iff.trans (h\u2081\u2082 s t) (h\u2082\u2083 s t)\n\n\n/- 1.1. Prove the following program equivalences. -/\n\nlemma program_equiv.seq_skip_left {S} :\n  skip ;; S \u2248 S :=\nbegin\n  intros s t,\n  apply iff.intro,\n  { intro h,\n    cases h,\n    cases h_h\u2081,\n    assumption },\n  { intro h,\n    exact big_step.seq big_step.skip h }\nend\n\nlemma program_equiv.seq_skip_right {S} :\n  S ;; skip \u2248 S :=\nbegin\n  intros s t,\n  apply iff.intro,\n  { intro h,\n    cases h,\n    cases h_h\u2082,\n    assumption },\n  { intro h,\n    exact big_step.seq h big_step.skip }\nend\n\nlemma program_equiv.seq_congr {S\u2081 S\u2082 T\u2081 T\u2082} (hS : S\u2081 \u2248 S\u2082) (hT : T\u2081 \u2248 T\u2082) :\n  S\u2081 ;; T\u2081 \u2248 S\u2082 ;; T\u2082 :=\nbegin\n  intros s t,\n  apply iff.intro,\n  { intros seq,\n    cases seq,\n    exact big_step.seq ((hS _ _).1 seq_h\u2081) ((hT _ _).1 seq_h\u2082) },\n  { intros seq,\n    cases seq,\n    exact big_step.seq ((hS _ _).2 seq_h\u2081) ((hT _ _).2 seq_h\u2082) }\nend\n\nlemma program_equiv.ite_seq_while {b S} :\n  ite b (S ;; while b S) skip \u2248 while b S :=\nbegin\n  intros s t,\n  apply iff.intro,\n  { intro ite,\n    cases ite,\n    { cases ite_hbody,\n      apply big_step.while_true,\n      repeat { assumption } },\n    { cases ite_hbody,\n      apply big_step.while_false,\n      repeat { assumption } } },\n  { intro while,\n    cases while,\n    { apply big_step.ite_true while_hcond,\n      apply big_step.seq,\n      repeat { assumption } },\n    { apply big_step.ite_false while_hcond,\n      exact big_step.skip } }\nend\n\n/- 1.2. Prove one more equivalence. -/\n\nlemma program_equiv.skip_assign_id {x} :\n  assign x (\u03bbs, s x) \u2248 skip :=\nbegin\n  intros s t,\n  apply iff.intro,\n  { intro asn,\n    cases asn,\n    simp * at * },\n  { intro sk,\n    cases sk,\n    simp * at * }\nend\n\n\n/- Question 2: Guarded Command Language (GCL) -/\n\n/- In 1976, E. W. Dijkstra introduced the guarded command language, a\nminimalistic imperative language with built-in nondeterminism. A grammar for one\nof its variants is given below:\n\n    S  ::=  x := e       -- assignment\n         |  assert b     -- assertion\n         |  S ; S        -- sequential composition\n         |  S | \u22ef | S    -- nondeterministic choice\n         |  loop S       -- nondeterministic iteration\n\nAssignment and sequential composition are as in the WHILE language. The other\nstatements have the following semantics:\n\n* `assert b` aborts if `b` evaluates to false; otherwise, the command is a\n  no-op.\n\n* `S | \u22ef | S` chooses **any** of the branches and executes it, ignoring the\n  other branches.\n\n* `loop S` executes `S` **any** number of times.\n\nIn Lean, GCL is captured by the following inductive type: -/\n\ninductive gcl (\u03c3 : Type) : Type\n| assign : string \u2192 (\u03c3 \u2192 \u2115) \u2192 gcl\n| assert : (\u03c3 \u2192 Prop) \u2192 gcl\n| seq    : gcl \u2192 gcl \u2192 gcl\n| choice : list gcl \u2192 gcl\n| loop   : gcl \u2192 gcl\n\ninfixr ` ;; `:90 := gcl.seq\n\nnamespace gcl\n\n/- The parameter `\u03c3` abstracts over the state type. It is necessary to work\naround a bug in Lean.\n\nThe big-step semantics is defined as follows: -/\n\ninductive big_step : (gcl state \u00d7 state) \u2192 state \u2192 Prop\n| assign {x a s} :\n  big_step (assign x a, s) (s{x \u21a6 a s})\n| assert {b : state \u2192 Prop} {s} (hcond : b s) :\n  big_step (assert b, s) s\n| seq {S T s t u} (h\u2081 : big_step (S, s) t) (h\u2082 : big_step (T, t) u) :\n  big_step (S ;; T, s) u\n| choice {Ss : list (gcl state)} {s t} (i : \u2115) (hless : i < list.length Ss)\n    (hbody : big_step (list.nth_le Ss i hless, s) t) :\n  big_step (choice Ss, s) t\n| loop_base {S s} :\n  big_step (loop S, s) s\n| loop_step {S s u} (t) (hbody : big_step (S, s) t)\n    (hrest : big_step (loop S, t) u) :\n  big_step (loop S, s) u\n\n/- Convenience syntax: -/\n\ninfix ` ~~> `:110 := big_step\n\n/- 2.1. Prove the following inversion rules, as we did in the lecture for the\nWHILE language. -/\n\n@[simp] lemma big_step_assign_iff {x a s t} :\n  (assign x a, s) ~~> t \u2194 t = s{x \u21a6 a s} :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases h,\n    refl },\n  { intro h,\n    rw h,\n    exact big_step.assign }\nend\n\n@[simp] lemma big_step_assert {b s t} :\n  (assert b, s) ~~> t \u2194 t = s \u2227 b s :=\nbegin\n  apply iff.intro,\n  { intro as,\n    cases as,\n    simp * at * },\n  { intros h,\n    cases h,\n    rw h_left,\n    apply big_step.assert h_right }\nend\n\n@[simp] lemma big_step_seq_iff {S\u2081 S\u2082 s t} :\n  (S\u2081 ;; S\u2082, s) ~~> t \u2194 (\u2203u, (S\u2081, s) ~~> u \u2227 (S\u2082, u) ~~> t) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases h,\n    apply exists.intro,\n    apply and.intro,\n    repeat { assumption } },\n  { intro h,\n    cases h,\n    cases h_h,\n    apply big_step.seq,\n    repeat { assumption } }\nend\n\nlemma big_step_loop {S s u} :\n  (loop S, s) ~~> u \u2194 (s = u \u2228 (\u2203t, (S, s) ~~> t \u2227 (loop S, t) ~~> u)) :=\nbegin\n  apply iff.intro,\n  { intro lo,\n    cases lo,\n    { apply or.intro_left,\n      refl },\n    { apply or.intro_right,\n      apply exists.intro lo_t,\n      apply and.intro,\n      repeat { assumption } } },\n  { intro h,\n    cases h,\n    { rw h,\n      apply big_step.loop_base },\n    { cases h,\n      cases h_h,\n      apply big_step.loop_step,\n      repeat { assumption } } }\nend\n\n@[simp] lemma big_step_choice {Ss s t} :\n  (choice Ss, s) ~~> t \u2194\n  (\u2203(i : \u2115) (hless : i < list.length Ss),\n    (list.nth_le Ss i hless, s) ~~> t) :=\nbegin\n  apply iff.intro,\n  { intro ch,\n    cases ch,\n    apply exists.intro ch_i,\n    apply exists.intro ch_hless,\n    assumption },\n  { intro h,\n    cases h,\n    cases h_h,\n    apply big_step.choice,\n    repeat { assumption } }\nend\n\n/- 2.2. Complete the translation below of a deterministic program to a GCL\nprogram, by filling in the `sorry` placeholders below. -/\n\ndef of_program : program \u2192 gcl state\n| program.skip          := assert (\u03bb_, true)\n| (program.assign x f)  :=\n  assign x f\n| (program.seq S\u2081 S\u2082)   :=\n  of_program S\u2081 ;; of_program S\u2082\n| (program.ite b S\u2081 S\u2082) :=\n  choice [seq (assert b) (of_program S\u2081),\n    seq (assert (\u03bbs, \u00ac b s)) (of_program S\u2082)]\n| (program.while b S)   :=\n  seq (loop (seq (assert b) (of_program S))) (assert (\u03bbs, \u00ac b s))\n\n/- 2.3. In the definition of `of_program` above, `skip` is translated to\n`assert (\u03bb_, true)`. Looking at the big-step semantics of both constructs, we\ncan convince ourselves that it makes sense. Can you think of other correct ways\nto define the `skip` case? -/\n\n/- Here are two other possibilities:\n\n  * `loop (assert (\u03bb_, false))`\n  * `assign \"x\" (\u03bbs, s \"x\")`\n\nThere are of course infinitely many variants, e.g. `seq` of the above two\nsolutions. -/\n\nend gcl\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love08_operational_semantics_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346598, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7221193395034484}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n\n! This file was ported from Lean 3 source module data.rat.denumerable\n! leanprover-community/mathlib commit 34ee86e6a59d911a8e4f89b68793ee7577ae79c7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.SetTheory.Cardinal.Basic\n\n/-!\n# Denumerability of \u211a\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves that \u211a is infinite, denumerable, and deduces that it has cardinality `omega`.\n-/\n\n\nnamespace Rat\n\nopen Denumerable\n\ninstance : Infinite \u211a :=\n  Infinite.of_injective (coe : \u2115 \u2192 \u211a) Nat.cast_injective\n\nprivate def denumerable_aux : \u211a \u2243 { x : \u2124 \u00d7 \u2115 // 0 < x.2 \u2227 x.1.natAbs.coprime x.2 }\n    where\n  toFun x := \u27e8\u27e8x.1, x.2\u27e9, x.3, x.4\u27e9\n  invFun x := \u27e8x.1.1, x.1.2, x.2.1, x.2.2\u27e9\n  left_inv := fun \u27e8_, _, _, _\u27e9 => rfl\n  right_inv := fun \u27e8\u27e8_, _\u27e9, _, _\u27e9 => rfl\n#align rat.denumerable_aux rat.denumerable_aux\n\n/-- **Denumerability of the Rational Numbers** -/\ninstance : Denumerable \u211a :=\n  by\n  let T := { x : \u2124 \u00d7 \u2115 // 0 < x.2 \u2227 x.1.natAbs.coprime x.2 }\n  letI : Infinite T := Infinite.of_injective _ denumerable_aux.injective\n  letI : Encodable T := Encodable.Subtype.encodable\n  letI : Denumerable T := of_encodable_of_infinite T\n  exact Denumerable.ofEquiv T denumerable_aux\n\nend Rat\n\nopen Cardinal\n\n#print Cardinal.mkRat /-\ntheorem Cardinal.mkRat : (#\u211a) = \u2135\u2080 := by simp\n#align cardinal.mk_rat Cardinal.mkRat\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Rat/Denumerable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7221193386924631}}
{"text": "import tactic\nimport data.equiv.ring\n\n\nnamespace uwyo\n\n-- Creating the integers starting from the natural numbers.\n-- Peter J. Cameron: \"Sets, Logic and Categories\"\n--                    section 1.8, page 29\n-- In this construction, think of an integer x as the solution to the equation:\n--    x + natnat.snd = natnat.fst\n-- So that x = fst - snd effectively, \n-- but avoiding subtraction, which is not defined everywhere\n@[ext] structure natnat := \n( fst : \u2115 )\n( snd : \u2115 ) \n\nnamespace natnat\n\nnotation `\u21152` := natnat\n\ndef \u21152_zero : \u21152 := \u27e8 0, 0 \u27e9 \ninstance : has_zero \u21152 := \u27e8 \u21152_zero \u27e9\n-- these may be useful later on\n@[simp] lemma fst_zero : (0 : \u21152).1 = 0 := by refl\n@[simp] lemma snd_zero : (0 : \u21152).2 = 0 := by refl\n\n-- let's play a little \ndef \u21152_minus_three : \u21152 := \u27e8 0, 3 \u27e9 \ndef \u21152_another_zero : \u21152 := \u27e8 3, 3 \u27e9 \n\n-- this is our canonical \"one\"\ndef \u21152_one : \u21152 := \u27e8 1, 0 \u27e9 \ndef \u21152_another_one : \u21152 := \u27e8 3, 2 \u27e9 \ninstance : has_one \u21152 := \u27e8 \u21152_one \u27e9\n-- these may be useful later on\n@[simp] lemma fst_one : (1 : \u21152).1 = 1 := by refl\n@[simp] lemma snd_one : (1 : \u21152).2 = 0 := by refl\n\n-- OK, let's get to business\n-- Here is the equivalence relation that defines our integers as equivalence classes.\ndef same (a b : \u21152) : Prop := a.1 + b.2 = a.2 + b.1 \nnotation a `~` b := same a b  -- we shouldn't really need this\ninstance : has_equiv \u21152 := \u27e8 same \u27e9   -- equivalence relation on \u21152; should \u2243 work as notation???\n\ntheorem same_equiv : equivalence same := \nbegin\n    split,\n    { -- reflexive:\n        intros x, unfold same, rw add_comm, \n    },\n    split,\n    { -- symmetric\n        intros x y hxy, unfold same at *,\n        rw [add_comm, add_comm y.snd _],\n        exact hxy.symm,\n    },\n    { -- transitive\n        intros x y z H G, \n        unfold same at *, linarith,\n    }\nend\n-- let's check that both our `one`s are in the same equivalence class\nlemma check_same_one : \u21152_one ~ \u21152_another_one := \nbegin\n    unfold same, refl,\nend\nexample : \u21152_zero ~ \u21152_another_zero := by {unfold same, refl}\n\n-- time to bundle together the set \u2115 \u00d7 \u2115 with the equivalence relation \"~\"\ninstance : setoid \u21152 :=\n{ \n    r := same,\n    iseqv := same_equiv \n}\n\nend natnat \n\n-- Define the integers\n\nnotation `my\u2124` := quotient natnat.setoid \n#check my\u2124\n\n-- Let's first check the equivalence classes that we set up.\n\ndef zero : my\u2124 := \u27e60\u27e7  --what 0 is the one in between the brackets? Should come from \u21152.\ndef another_zero : my\u2124 := \u27e6 natnat.\u21152_another_zero \u27e7\nexample : zero = another_zero :=\nbegin\n  apply quot.sound,\n  -- \u22a2 setoid.r \u21152_zero \u21152_another_zero\n  -- simp only [setoid.r] is helpful with a goal like this\n  show natnat.same natnat.\u21152_zero natnat.\u21152_another_zero,\n  show 0 + 3 = 3 + 0,\n  norm_num, done\nend\nexample : zero = another_zero := \nbegin\n    apply quot.sound,\n    dsimp [setoid.r],\n    unfold natnat.same,\n    rw [natnat.\u21152_another_zero],  -- can't rw natnat.\u21152_zero here, so...\n    simp, \n    done\nend\nexample : \u27e6 natnat.\u21152_zero \u27e7 = another_zero := \nbegin\n    apply quot.sound,\n    dsimp [setoid.r],\n    unfold natnat.same,\n    rw [natnat.\u21152_zero, natnat.\u21152_another_zero],  -- now I can rw natnat.\u21152_zero\n    done\nend\nexample : \u27e6 natnat.\u21152_one \u27e7 = \u27e6 natnat.\u21152_another_one \u27e7 := \nbegin\n    apply quot.sound,\n    exact natnat.check_same_one,\nend\n\n-- So now the task is to prove that `my\u2124` forms a commutative ring with identity and \n-- has no (non-trivial) divisors of zero.\n-- First we have to define its operations, addition and multiplication,\n-- together with their identity elements. We'll also define order.\n-- The operations should work in the following way:\n-- Addition: [a,b] + [c,d] = [a+b,c+d]               (check it)\n-- Multiplication: [a,b] * [c,d] = [ac+bd, ad + bc]  (check it)\n-- Less or equal: [a,b] \u2264 [c,d]  \u2194  a + d \u2264 b + c    (check it)\ndef our_zero : my\u2124 := \u27e6 natnat.\u21152_zero \u27e7  \ninstance : has_zero my\u2124 := \u27e8 our_zero \u27e9\n@[simp] lemma zero_thing : (0 : my\u2124) = \u27e60\u27e7 := rfl   -- \u27e6 0 \u27e7 was defined above\n\ndef our_one : my\u2124 := \u27e6 natnat.\u21152_one \u27e7\ninstance : has_one my\u2124 := \u27e8our_one\u27e9\n@[simp] lemma one_thing : (1 : my\u2124) = \u27e61\u27e7 := rfl  --and this?\n\nopen natnat\n\n-- Let us define an additional simplification lemma:\n@[simp] lemma same_thing (a b : \u21152) : a \u2248 b \u2194 a.fst + b.snd = a.snd + b.fst := iff.rfl\n\n--protected def add (a b : my\u2124) : my\u2124 :=  sorry  -- these will probably need `quotient.lift` \n--protected def mul (a b : my\u2124) : my\u2124 :=  sorry\n--protected def le (a b : my\u2124) : Prop :=  sorry\n\n-- Lean help us be certain our definitions make sense\n-- For example for addition: if a1, a2, b1 and b2 are of type `natnat`\n-- And:     a1 ~ b1 and a2 ~ b2\n-- Then our definition of addition should be such that:\n--          a1 + a2 ~ b1 + b2 \n-- This is what `quotient.lift_on\u2082` is designed to take care of:\n@[simp] def add (a b : my\u2124) : my\u2124 := quotient.lift_on\u2082 a b \n    ( \u03bb z w, \u27e6 natnat.mk (z.fst + w.fst) (z.snd + w.snd) \u27e7  ) \nbegin\n    intros a1 a2 b1 b2 hab1 hab2,\n    change a1.1 + b1.2 = a1.2 + b1.1 at hab1, \n    change a2.1 + b2.2 = a2.2 + b2.1 at hab2, \n    simp at *, \n    set A1 := a1.fst + a2.fst with hA1,\n    set A2 := a1.snd + a2.snd with hA2, \n    set B1 := b1.fst + b2.fst with hB1,\n    set B2 := b1.snd + b2.snd with hB2,\n    change A1 + B2 = A2 + B1,\n    linarith,\nend\n-- one thing that I'm still not certain of is whether we want \"protected\" or not\n-- for these definitions\n-- Now we can declare the addition operation on our integers:\ninstance : has_add my\u2124 := \u27e8 add \u27e9\n\n-- Now that we have addition we can also define the additive inverse;\n-- Again, Lean allows us to make sure the inverse is correctly defined:\n-- If a1 and b1 are of type `natnat` and a1 ~ b1 \n-- Then (- a1) ~ (- b1)\n@[simp] def neg (a : my\u2124) : my\u2124 := \n    quotient.lift_on a ( \u03bb b, \u27e6 natnat.mk b.snd b.fst \u27e7 )\nbegin\n  intros a1 b1 hab1,\n  change a1.1 + b1.2 = a1.2 + b1.1 at hab1, \n  simp at *,\n  change a1.snd + b1.fst = a1.fst + b1.snd, \n  omega,  -- another tactic that can be used with nat/int\nend\n-- So now we can also declare the additive inverse (negation)\ninstance : has_neg my\u2124 := \u27e8 neg \u27e9\n-- With these two instances we can now use our usual notation for addition and inverse:\n@[simp] lemma add_thing (a b : my\u2124) : a + b = add a b := rfl\n@[simp] lemma neg_thing (a   : my\u2124) : - a   = neg a   := rfl\n\n----- an important simp lemma (original idea due to Kenny Lau) that rewrites quotient terms\n----- this has been incorporated in `mathlib` now\n--@[simp] theorem quotient.lift_on_beta\u2082 {\u03b1 : Type} {\u03b2 : Type} [setoid \u03b1] (f : \u03b1 \u2192 \u03b1 \u2192 \u03b2) (h)\n--  (x y : \u03b1) : \u27e6x\u27e7.lift_on\u2082 \u27e6y\u27e7 f h = f x y := rfl\n----- this is my rewriting of it in mathlib style\n--@[simp] theorem quotient.lift_on_beta_v2 {\u03b1 : Type} {\u03b2 : Type} [setoid \u03b1] (f : \u03b1 \u2192 \u03b1 \u2192 \u03b2) (h) \n--  (x y : \u03b1) : quotient.lift_on\u2082 (quotient.mk x) (quotient.mk y) f h = f x y := rfl\n----- this is the `mathlib` style proof\n--@[simp] theorem quotient.lift_on_beta\u2082 {\u03b1 : Type} {\u03b2 : Type} [setoid \u03b1] (f : \u03b1 \u2192 \u03b1 \u2192 \u03b2) \n--  (h : \u2200 (a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1), a\u2081 \u2248 b\u2081 \u2192 a\u2082 \u2248 b\u2082 \u2192 f a\u2081 a\u2082 = f b\u2081 b\u2082) (x y : \u03b1) : \n--  quotient.lift_on\u2082 (quotient.mk x) (quotient.mk y) f h = f x y := rfl\n\n-- Which brings us to the point where we can show that our integers form an additive\n-- group under addition as defined above:\ninstance : add_comm_group my\u2124 :=\n{ add := has_add.add,\n  add_assoc := begin\n    intros a b c, \n    apply quotient.induction_on\u2083 a b c,\n    intros a b c,\n    simp * at *,\n    omega, done\n  end,\n  zero := has_zero.zero,\n  zero_add := begin\n    intros a,\n    apply quotient.induction_on a,\n    simp * at *, \n    intros, omega, done\n  end,\n  add_zero := begin\n    intros a,\n    apply quotient.induction_on a,\n    intros,\n    simp * at *,\n    omega, done\n  end,\n  neg := has_neg.neg,\n  add_left_neg := begin\n    intro z, apply quotient.induction_on z,\n    intro a,\n    simp * at *, -- uses quotient.lift_on_beta\u2082 to simplify\n    exact add_comm _ _, done\n  end,\n  add_comm := begin\n    intros a b,\n    apply quotient.induction_on\u2082 a b,\n    simp * at *,\n    intros, \n    omega, done\n  end \n}\n\n-- So let's move on to multiplication. First we have to define it\n-- This is a little on the long side.\n@[simp] def mul (a b : my\u2124) : my\u2124 := quotient.lift_on\u2082 a b ( \u03bb z w, \n  \u27e6 natnat.mk (z.fst * w.fst + z.snd * w.snd ) (z.fst * w.snd + z.snd * w.fst) \u27e7  ) \nbegin\n  intros a1 a2 b1 b2 hab1 hab2,\n  simp * at *,\n  nlinarith, done\nend\ninstance : has_mul my\u2124 := \u27e8mul\u27e9\n@[simp] lemma mul_thing (a b : my\u2124) : a * b = mul a b := rfl \n\n-- So we're ready to go for the full structure on the integers:\ninstance : comm_ring my\u2124 :=\n{ mul := has_mul.mul,\n  mul_assoc := begin \n    intros a b c,\n    apply quotient.induction_on\u2083 a b c,\n    intros a1 b1 c1,\n    simp only [mul, mul_thing, quotient.lift_on_beta\u2082, same_thing, quotient.eq],\n    ring, done\n  end,\n  one := has_one.one,\n  one_mul := begin \n    intro a,\n    apply quotient.induction_on a,\n    intros,\n    simp only [mul, mul_thing, add_zero, one_mul, fst_one, zero_mul, snd_one, \n               one_thing, quotient.lift_on_beta\u2082, same_thing, quotient.eq],\n    ring,\n  end,\n  mul_one := begin \n    intro a,\n    apply quotient.induction_on a,\n    intros,\n    simp,\n    ring,\n  end,\n  left_distrib := begin \n    intros a b c,\n    apply quotient.induction_on\u2083 a b c,\n    intros,\n    apply quotient.sound,\n    simp,\n    ring,\n  end,\n  right_distrib := begin\n    intros a b c,\n    apply quotient.induction_on\u2083 a b c,\n    intros,\n    apply quotient.sound,\n    simp,\n    ring,\n  end,\n  mul_comm := begin \n    intros a b,\n    apply quotient.induction_on\u2082 a b,\n    intros,\n    simp,\n    ring,\n  end,\n  ..uwyo.add_comm_group }\n\n-------------------------------------------------------------------------------\n-- Work in progress below this line:\n#check quotient.eq  -- this could be used instead of quotient.sound\n#check quotient.sound\n#check quotient.lift_on our_one --\n#check quotient.lift_beta --\n#check quotient.lift_on_beta --\n#check quotient.lift_on_beta\u2082\n#check quotient.lift_on\u2082 --\n#check quotient.lift\n#check quot.map\n-------------------------------------------------------------------------------\n\nend uwyo", "meta": {"author": "stanescuUW", "repo": "integer-number-game", "sha": "fced68b04a59ef0f4ea41b5beb2df87e0428c761", "save_path": "github-repos/lean/stanescuUW-integer-number-game", "path": "github-repos/lean/stanescuUW-integer-number-game/integer-number-game-fced68b04a59ef0f4ea41b5beb2df87e0428c761/src/game/basic/my-integers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346598, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7221193376864774}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.equiv.basic\nimport Mathlib.algebra.group.basic\nimport Mathlib.algebra.group.hom\nimport Mathlib.algebra.group.pi\nimport Mathlib.algebra.group.prod\nimport Mathlib.PostPort\n\nuniverses u u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# The group of permutations (self-equivalences) of a type `\u03b1`\n\nThis file defines the `group` structure on `equiv.perm \u03b1`.\n-/\n\nnamespace equiv\n\n\nnamespace perm\n\n\nprotected instance perm_group {\u03b1 : Type u} : group (perm \u03b1) :=\n  group.mk (fun (f g : perm \u03b1) => equiv.trans g f) sorry (equiv.refl \u03b1) sorry sorry equiv.symm\n    (div_inv_monoid.div._default (fun (f g : perm \u03b1) => equiv.trans g f) sorry (equiv.refl \u03b1) sorry\n      sorry equiv.symm)\n    sorry\n\ntheorem mul_apply {\u03b1 : Type u} (f : perm \u03b1) (g : perm \u03b1) (x : \u03b1) :\n    coe_fn (f * g) x = coe_fn f (coe_fn g x) :=\n  trans_apply g f x\n\ntheorem one_apply {\u03b1 : Type u} (x : \u03b1) : coe_fn 1 x = x := rfl\n\n@[simp] theorem inv_apply_self {\u03b1 : Type u} (f : perm \u03b1) (x : \u03b1) : coe_fn (f\u207b\u00b9) (coe_fn f x) = x :=\n  symm_apply_apply f x\n\n@[simp] theorem apply_inv_self {\u03b1 : Type u} (f : perm \u03b1) (x : \u03b1) : coe_fn f (coe_fn (f\u207b\u00b9) x) = x :=\n  apply_symm_apply f x\n\ntheorem one_def {\u03b1 : Type u} : 1 = equiv.refl \u03b1 := rfl\n\ntheorem mul_def {\u03b1 : Type u} (f : perm \u03b1) (g : perm \u03b1) : f * g = equiv.trans g f := rfl\n\ntheorem inv_def {\u03b1 : Type u} (f : perm \u03b1) : f\u207b\u00b9 = equiv.symm f := rfl\n\n@[simp] theorem coe_mul {\u03b1 : Type u} (f : perm \u03b1) (g : perm \u03b1) : \u21d1(f * g) = \u21d1f \u2218 \u21d1g := rfl\n\n@[simp] theorem coe_one {\u03b1 : Type u} : \u21d11 = id := rfl\n\ntheorem eq_inv_iff_eq {\u03b1 : Type u} {f : perm \u03b1} {x : \u03b1} {y : \u03b1} :\n    x = coe_fn (f\u207b\u00b9) y \u2194 coe_fn f x = y :=\n  eq_symm_apply f\n\ntheorem inv_eq_iff_eq {\u03b1 : Type u} {f : perm \u03b1} {x : \u03b1} {y : \u03b1} :\n    coe_fn (f\u207b\u00b9) x = y \u2194 x = coe_fn f y :=\n  symm_apply_eq f\n\n/-! Lemmas about mixing `perm` with `equiv`. Because we have multiple ways to express\n`equiv.refl`, `equiv.symm`, and `equiv.trans`, we want simp lemmas for every combination.\nThe assumption made here is that if you're using the group structure, you want to preserve it after\nsimp. -/\n\n@[simp] theorem trans_one {\u03b1 : Sort u_1} {\u03b2 : Type u_2} (e : \u03b1 \u2243 \u03b2) : equiv.trans e 1 = e :=\n  trans_refl e\n\n@[simp] theorem mul_refl {\u03b1 : Type u} (e : perm \u03b1) : e * equiv.refl \u03b1 = e := trans_refl e\n\n@[simp] theorem one_symm {\u03b1 : Type u} : equiv.symm 1 = 1 := refl_symm\n\n@[simp] theorem refl_inv {\u03b1 : Type u} : equiv.refl \u03b1\u207b\u00b9 = 1 := refl_symm\n\n@[simp] theorem one_trans {\u03b1 : Type u_1} {\u03b2 : Sort u_2} (e : \u03b1 \u2243 \u03b2) : equiv.trans 1 e = e :=\n  refl_trans e\n\n@[simp] theorem refl_mul {\u03b1 : Type u} (e : perm \u03b1) : equiv.refl \u03b1 * e = e := refl_trans e\n\n@[simp] theorem inv_trans {\u03b1 : Type u} (e : perm \u03b1) : equiv.trans (e\u207b\u00b9) e = 1 := symm_trans e\n\n@[simp] theorem mul_symm {\u03b1 : Type u} (e : perm \u03b1) : e * equiv.symm e = 1 := symm_trans e\n\n@[simp] theorem trans_inv {\u03b1 : Type u} (e : perm \u03b1) : equiv.trans e (e\u207b\u00b9) = 1 := trans_symm e\n\n@[simp] theorem symm_mul {\u03b1 : Type u} (e : perm \u03b1) : equiv.symm e * e = 1 := trans_symm e\n\n/-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/\n\n@[simp] theorem sum_congr_mul {\u03b1 : Type u_1} {\u03b2 : Type u_2} (e : perm \u03b1) (f : perm \u03b2) (g : perm \u03b1)\n    (h : perm \u03b2) : sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) :=\n  sum_congr_trans g h e f\n\n@[simp] theorem sum_congr_inv {\u03b1 : Type u_1} {\u03b2 : Type u_2} (e : perm \u03b1) (f : perm \u03b2) :\n    sum_congr e f\u207b\u00b9 = sum_congr (e\u207b\u00b9) (f\u207b\u00b9) :=\n  sum_congr_symm e f\n\n@[simp] theorem sum_congr_one {\u03b1 : Type u_1} {\u03b2 : Type u_2} : sum_congr 1 1 = 1 := sum_congr_refl\n\n/-- `equiv.perm.sum_congr` as a `monoid_hom`, with its two arguments bundled into a single `prod`.\n\nThis is particularly useful for its `monoid_hom.range` projection, which is the subgroup of\npermutations which do not exchange elements between `\u03b1` and `\u03b2`. -/\ndef sum_congr_hom (\u03b1 : Type u_1) (\u03b2 : Type u_2) : perm \u03b1 \u00d7 perm \u03b2 \u2192* perm (\u03b1 \u2295 \u03b2) :=\n  monoid_hom.mk (fun (a : perm \u03b1 \u00d7 perm \u03b2) => sum_congr (prod.fst a) (prod.snd a)) sum_congr_one\n    sorry\n\ntheorem sum_congr_hom_injective {\u03b1 : Type u_1} {\u03b2 : Type u_2} :\n    function.injective \u21d1(sum_congr_hom \u03b1 \u03b2) :=\n  sorry\n\n@[simp] theorem sum_congr_swap_one {\u03b1 : Type u_1} {\u03b2 : Type u_2} [DecidableEq \u03b1] [DecidableEq \u03b2]\n    (i : \u03b1) (j : \u03b1) : sum_congr (swap i j) 1 = swap (sum.inl i) (sum.inl j) :=\n  sum_congr_swap_refl i j\n\n@[simp] theorem sum_congr_one_swap {\u03b1 : Type u_1} {\u03b2 : Type u_2} [DecidableEq \u03b1] [DecidableEq \u03b2]\n    (i : \u03b2) (j : \u03b2) : sum_congr 1 (swap i j) = swap (sum.inr i) (sum.inr j) :=\n  sum_congr_refl_swap i j\n\n/-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/\n\n@[simp] theorem sigma_congr_right_mul {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} (F : (a : \u03b1) \u2192 perm (\u03b2 a))\n    (G : (a : \u03b1) \u2192 perm (\u03b2 a)) :\n    sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) :=\n  sigma_congr_right_trans G F\n\n@[simp] theorem sigma_congr_right_inv {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} (F : (a : \u03b1) \u2192 perm (\u03b2 a)) :\n    sigma_congr_right F\u207b\u00b9 = sigma_congr_right fun (a : \u03b1) => F a\u207b\u00b9 :=\n  sigma_congr_right_symm F\n\n@[simp] theorem sigma_congr_right_one {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} : sigma_congr_right 1 = 1 :=\n  sigma_congr_right_refl\n\n/-- `equiv.perm.sigma_congr_right` as a `monoid_hom`.\n\nThis is particularly useful for its `monoid_hom.range` projection, which is the subgroup of\npermutations which do not exchange elements between fibers. -/\ndef sigma_congr_right_hom {\u03b1 : Type u_1} (\u03b2 : \u03b1 \u2192 Type u_2) :\n    ((a : \u03b1) \u2192 perm (\u03b2 a)) \u2192* perm (sigma fun (a : \u03b1) => \u03b2 a) :=\n  monoid_hom.mk sigma_congr_right sorry sorry\n\ntheorem sigma_congr_right_hom_injective {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} :\n    function.injective \u21d1(sigma_congr_right_hom \u03b2) :=\n  sorry\n\nend perm\n\n\n@[simp] theorem swap_inv {\u03b1 : Type u} [DecidableEq \u03b1] (x : \u03b1) (y : \u03b1) : swap x y\u207b\u00b9 = swap x y := rfl\n\n@[simp] theorem swap_mul_self {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) :\n    swap i j * swap i j = 1 :=\n  swap_swap i j\n\ntheorem swap_mul_eq_mul_swap {\u03b1 : Type u} [DecidableEq \u03b1] (f : perm \u03b1) (x : \u03b1) (y : \u03b1) :\n    swap x y * f = f * swap (coe_fn (f\u207b\u00b9) x) (coe_fn (f\u207b\u00b9) y) :=\n  sorry\n\ntheorem mul_swap_eq_swap_mul {\u03b1 : Type u} [DecidableEq \u03b1] (f : perm \u03b1) (x : \u03b1) (y : \u03b1) :\n    f * swap x y = swap (coe_fn f x) (coe_fn f y) * f :=\n  sorry\n\n/-- Left-multiplying a permutation with `swap i j` twice gives the original permutation.\n\n  This specialization of `swap_mul_self` is useful when using cosets of permutations.\n-/\n@[simp] theorem swap_mul_self_mul {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) (\u03c3 : perm \u03b1) :\n    swap i j * (swap i j * \u03c3) = \u03c3 :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (swap i j * (swap i j * \u03c3) = \u03c3))\n        (Eq.symm (mul_assoc (swap i j) (swap i j) \u03c3))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (swap i j * swap i j * \u03c3 = \u03c3)) (swap_mul_self i j)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (1 * \u03c3 = \u03c3)) (one_mul \u03c3))) (Eq.refl \u03c3)))\n\n/-- Right-multiplying a permutation with `swap i j` twice gives the original permutation.\n\n  This specialization of `swap_mul_self` is useful when using cosets of permutations.\n-/\n@[simp] theorem mul_swap_mul_self {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) (\u03c3 : perm \u03b1) :\n    \u03c3 * swap i j * swap i j = \u03c3 :=\n  eq.mpr\n    (id (Eq._oldrec (Eq.refl (\u03c3 * swap i j * swap i j = \u03c3)) (mul_assoc \u03c3 (swap i j) (swap i j))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u03c3 * (swap i j * swap i j) = \u03c3)) (swap_mul_self i j)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (\u03c3 * 1 = \u03c3)) (mul_one \u03c3))) (Eq.refl \u03c3)))\n\n/-- A stronger version of `mul_right_injective` -/\n@[simp] theorem swap_mul_involutive {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) :\n    function.involutive (Mul.mul (swap i j)) :=\n  swap_mul_self_mul i j\n\n/-- A stronger version of `mul_left_injective` -/\n@[simp] theorem mul_swap_involutive {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) :\n    function.involutive fun (_x : perm \u03b1) => _x * swap i j :=\n  mul_swap_mul_self i j\n\ntheorem swap_mul_eq_iff {\u03b1 : Type u} [DecidableEq \u03b1] {i : \u03b1} {j : \u03b1} {\u03c3 : perm \u03b1} :\n    swap i j * \u03c3 = \u03c3 \u2194 i = j :=\n  sorry\n\ntheorem mul_swap_eq_iff {\u03b1 : Type u} [DecidableEq \u03b1] {i : \u03b1} {j : \u03b1} {\u03c3 : perm \u03b1} :\n    \u03c3 * swap i j = \u03c3 \u2194 i = j :=\n  sorry\n\ntheorem swap_mul_swap_mul_swap {\u03b1 : Type u} [DecidableEq \u03b1] {x : \u03b1} {y : \u03b1} {z : \u03b1} (hwz : x \u2260 y)\n    (hxz : x \u2260 z) : swap y z * swap x y * swap y z = swap z x :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/group_theory/perm/basic_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7221193374914766}}
{"text": "/-\nCopyright (c) 2020 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n-/\nimport data.set.finite\n\n/-!\n# Infinitude of intervals\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nBounded intervals in dense orders are infinite, as are unbounded intervals\nin orders that are unbounded on the appropriate side. We also prove that an unbounded\npreorder is an infinite type.\n-/\n\nvariables {\u03b1 : Type*} [preorder \u03b1]\n\n/-- A nonempty preorder with no maximal element is infinite. This is not an instance to avoid\na cycle with `infinite \u03b1 \u2192 nontrivial \u03b1 \u2192 nonempty \u03b1`. -/\nlemma no_max_order.infinite [nonempty \u03b1] [no_max_order \u03b1] : infinite \u03b1 :=\nlet \u27e8f, hf\u27e9 := nat.exists_strict_mono \u03b1 in infinite.of_injective f hf.injective\n\n/-- A nonempty preorder with no minimal element is infinite. This is not an instance to avoid\na cycle with `infinite \u03b1 \u2192 nontrivial \u03b1 \u2192 nonempty \u03b1`. -/\nlemma no_min_order.infinite [nonempty \u03b1] [no_min_order \u03b1] : infinite \u03b1 :=\n@no_max_order.infinite \u03b1\u1d52\u1d48 _ _ _\n\nnamespace set\n\nsection densely_ordered\n\nvariables [densely_ordered \u03b1] {a b : \u03b1} (h : a < b)\n\nlemma Ioo.infinite : infinite (Ioo a b) := @no_max_order.infinite _ _ (nonempty_Ioo_subtype h) _\nlemma Ioo_infinite : (Ioo a b).infinite := infinite_coe_iff.1 $ Ioo.infinite h\n\nlemma Ico_infinite : (Ico a b).infinite := (Ioo_infinite h).mono Ioo_subset_Ico_self\n\n\nlemma Ioc_infinite : (Ioc a b).infinite := (Ioo_infinite h).mono Ioo_subset_Ioc_self\nlemma Ioc.infinite : infinite (Ioc a b) := infinite_coe_iff.2 $ Ioc_infinite h\n\nlemma Icc_infinite : (Icc a b).infinite := (Ioo_infinite h).mono Ioo_subset_Icc_self\nlemma Icc.infinite : infinite (Icc a b) := infinite_coe_iff.2 $ Icc_infinite h\n\nend densely_ordered\n\ninstance [no_min_order \u03b1] {a : \u03b1} : infinite (Iio a) := no_min_order.infinite\nlemma Iio_infinite [no_min_order \u03b1] (a : \u03b1) : (Iio a).infinite := infinite_coe_iff.1 Iio.infinite\n\ninstance [no_min_order \u03b1] {a : \u03b1} : infinite (Iic a) := no_min_order.infinite\nlemma Iic_infinite [no_min_order \u03b1] (a : \u03b1) : (Iic a).infinite := infinite_coe_iff.1 Iic.infinite\n\ninstance [no_max_order \u03b1] {a : \u03b1} : infinite (Ioi a) := no_max_order.infinite\nlemma Ioi_infinite [no_max_order \u03b1] (a : \u03b1) : (Ioi a).infinite := infinite_coe_iff.1 Ioi.infinite\n\ninstance [no_max_order \u03b1] {a : \u03b1} : infinite (Ici a) := no_max_order.infinite\nlemma Ici_infinite [no_max_order \u03b1] (a : \u03b1) : (Ici a).infinite := infinite_coe_iff.1 Ici.infinite\n\nend set\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/set/intervals/infinite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7220912022602747}}
{"text": "/-\nCopyright 2020 Google LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n      http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n -/\nimport tactic.simp_rw\n\n\nnamespace exists_unique\n@[simp]\nlemma proof_iff {P Q:Prop}:\n  (\u2203! (H:P), Q) \u2194 (P \u2227 Q) :=\nbegin\n  split;intros h,\n  have h_exists := exists_of_exists_unique h,\n  cases h_exists with hP hQ,\n  apply and.intro hP hQ,\n  cases h with hP hQ,\n  apply exists_unique.intro hP hQ,\n  intros hP' hQ',\n  refl,\nend\n\n@[simp]\nlemma in_set_iff {\u03b1:Type*} {s:set \u03b1} \n  {P:\u03b1 \u2192 Prop}:\n  (\u2203! a\u2208s, P a) \u2194 (\u2203! a, a\u2208s \u2227 P a) :=\nbegin\n  simp_rw [exists_unique.proof_iff],\nend\n\n/--Technically, `\u2203! (b\u2208s), P s` reads \"there exists a unique b such that\n   there exists a unique proof of `(b\u2208s)` such that `P s`.\"\n   A more natural interpretation is there exists a unique b such that \n   b\u2208s and P s. This performs the translation. -/\nlemma intro_set {\u03b1:Type*} {s:set \u03b1} \n  {P:\u03b1 \u2192 Prop} (a : \u03b1) (h : a\u2208 s) (hPa : P a) (h_unique: \u2200 b\u2208 s, P b \u2192 b = a):\n  \u2203! c\u2208s, P c :=\nbegin\n  rw exists_unique.in_set_iff,\n  apply exists_unique.intro a (and.intro h hPa),\n  intros y hy_in_s_and_Py,\n  apply h_unique y hy_in_s_and_Py.left hy_in_s_and_Py.right,\nend\n\nend exists_unique\n\n", "meta": {"author": "google", "repo": "formal-ml", "sha": "630011d19fdd9539c8d6493a69fe70af5d193590", "save_path": "github-repos/lean/google-formal-ml", "path": "github-repos/lean/google-formal-ml/formal-ml-630011d19fdd9539c8d6493a69fe70af5d193590/src/formal_ml/exists_unique.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7220911908612081}}
{"text": "------------------------------------------------\n-- Axiomas:\n------------------------------------------------\n  axiom ZA_Ass (a b c: \u2124) : (a + b) + c = a + (b + c)\n  axiom ZA_idR (a : \u2124) : a = a + 0\n  axiom ZA_invR (a : \u2124) : 0 = a + (-a)\n  axiom ZA_Com (a b : \u2124) : a + b = b + a\n\n  axiom ZM_Ass (a b c : \u2124) : (a * b) * c = a * (b * c)\n  axiom ZM_idR (a : \u2124) : a = a * 1\n  axiom ZM_Com (a b : \u2124) : a * b = b * a\n\n  axiom Z_DistR (a b c : \u2124) : (a + b) * c = a * c + b * c\n  axiom Z_NZD (a b : \u2124) : (a * b) = 0 \u2192 a = 0 \u2228 b = 0\n\n  axiom ZP_A (a b > 0) : a + b > 0\n  axiom ZP_M (a b > 0) : a * b > 0\n  axiom ZP_Tri (a : \u2124) : (a = 0) \u2228 (a > 0) \u2228 (a < 0)\n  axiom ZP_Tri' (a : \u2124) : (a = 0 \u2227 \u00ac(a < 0) \u2227 \u00ac(a > 0)) \u2228 (a > 0 \u2227 \u00ac(a < 0) \u2227 \u00ac(a = 0)) \u2228 (a < 0 \u2227 \u00ac(a > 0) \u2227 \u00ac(a = 0))\n\n------------------------------------------------\n-- Defini\u00e7\u00f5es:\n------------------------------------------------\n  \n  def abs (x : \u2124) := if (x > 0 \u2228 x = 0) then x else -x\n  notation | x | := abs x\n  def applyabs (x : \u2124) := | x | = abs x\n  notation x < y := 0 < (y + (-x))\n  def unit' (x : \u2124) := \u2203 k : \u2124, x * k = 1\n  def is_ZM_idR (w : \u2124) := \u2200 (a : \u2124), a * w = a\n  \n------------------------------------------------\n-- Lemmas da Esquerda:\n------------------------------------------------\n  lemma ZA_idL: \u2200 (a : \u2124), a = 0 + a :=\n    begin\n      intro a,\n      have h : a = a + 0 := ZA_idR a,\n      rw ZA_Com a 0 at h,\n      exact h,\n    end\n  lemma ZA_invL: \u2200 (a : \u2124), 0 = (-a) + a :=\n    begin\n      intro a,\n      have h : 0 = a + (-a) := ZA_invR a,\n      rw ZA_Com a (-a) at h,\n      exact h,\n    end\n  lemma ZM_idL: \u2200 (a : \u2124), a = 1 * a :=\n    begin\n      intro a,\n      have h : a = a * 1 := ZM_idR a,\n      rw ZM_Com a 1 at h,\n      exact h,\n    end\n  lemma Z_DistL: \u2200 (a b c : \u2124), c * (a + b) = c * a + c * b:=\n    begin\n      intros a b c,\n      have h : (a + b) * c = a * c + b * c := Z_DistR a b c,\n      rw ZM_Com (a + b) c at h,\n      rw ZM_Com a c at h,\n      rw ZM_Com b c at h,\n      exact h,\n    end\n------------------------------------------------\n-- Lemmas Extras:\n------------------------------------------------\n  lemma ZA_PF: \u2200 (a b u : \u2124), a = b \u2192 a + u = b + u :=\n    begin\n      intros a b u h,\n      have h1: a + u = a + u,\n      refl,\n      conv{\n        to_rhs,\n        rw \u2190h,\n      },\n    end\n  lemma Z_Trans: \u2200 (a b c : \u2124), (a = c \u2227 b = c) \u2192 a = b :=\n    begin\n      intros a b c,\n      intro h,\n      cases h with h1 h2,\n      conv{\n        to_lhs,\n        rw h1,\n      },\n      conv{\n        to_rhs,\n        rw h2,\n      },\n    end\n------------------------------------------------\n-- Teoremas de Anulamento:\n------------------------------------------------\n  theorem ZM_AnR: \u2200 (a : \u2124), a * 0 = 0 :=\n    begin\n      intro a,\n      have h: a + (a * 0) = a,\n      conv{\n        to_rhs,\n        rw ZM_idR a,\n        rw ZA_idR 1,\n        rw Z_DistL 1 0 a,\n        congr,\n        rw \u2190ZM_idR a,\n        skip,\n        skip,\n      },\n      have h1: (a + (a * 0)) = a \u2192 (a + (a * 0)) + (-a) = a + (-a) := ZA_PF (a + (a * 0)) a (-a),\n      have h2: (a + (a * 0)) + (-a) = a + (-a) := h1 h,\n      rw ZA_Ass a (a * 0) (-a) at h2,\n      rw ZA_Com (a * 0) (-a) at h2,\n      rw \u2190ZA_Ass a (-a) (a * 0) at h2,\n      rw \u2190ZA_invR a at h2,\n      rw \u2190ZA_idL (a * 0) at h2,\n      exact h2,\n    end\n  theorem ZM_AnL: \u2200 (a : \u2124), 0 * a = 0 :=\n    begin\n      intro a,\n      have h: a * 0 = 0 := ZM_AnR a,\n      rw ZM_Com a 0 at h,\n      exact h,\n    end\n------------------------------------------------\n-- Teoremas de Nega\u00e7\u00e3o:\n------------------------------------------------\n  theorem ZS_Neg: \u2200 (x : \u2124), (-1) * x = -x :=\n    begin\n      intro x,\n      have h: x + (-1) * x = 0,\n      have h1: x * 0 = 0 := ZM_AnR x,\n      conv{\n        to_rhs,\n        rw \u2190h1,\n        rw ZA_invR 1,\n        rw Z_DistL 1 (-1) x,\n        rw \u2190ZM_idR x,\n        rw ZM_Com x (-1),\n      },\n      have h2: (x + (-1) * x) = 0 \u2192 (x + (-1) * x) + (-x) = 0 + (-x) := ZA_PF (x + (-1) * x) 0 (-x),\n      have h3: (x + (-1) * x) + (-x) = 0 + (-x) := h2 h,\n      rw ZA_Ass x ((-1) * x) (-x) at h3,\n      rw ZA_Com ((-1) * x) (-x) at h3,\n      rw \u2190ZA_Ass x (-x) ((-1) * x) at h3,\n      rw \u2190ZA_invR x at h3,\n      rw \u2190ZA_idL ((-1) * x) at h3,\n      rw \u2190ZA_idL (-x) at h3,\n      exact h3,\n    end\n  theorem ZS_DNeg: \u2200 (x : \u2124), -(-x) = x :=\n    begin\n      intro x,\n      conv{\n        to_lhs,\n        rw ZA_idR (-(-x)),\n        rw ZA_invL x,\n        rw \u2190ZA_Ass (-(-x)) (-x) x,\n        rw \u2190ZA_invL (-x),\n        rw \u2190ZA_idL x,\n      },\n    end\n  theorem ZS_MNegU: \u2200 (x y : \u2124), -x * y = -(x * y) :=\n    begin\n      intros x y,\n      have h: x * y + (-x) * y = 0,\n      conv{\n        to_lhs,\n        rw \u2190Z_DistR x (-x) y,\n        rw \u2190ZA_invR x,\n        rw ZM_AnL y,\n      },\n      have h1: (x * y + (-x) * y) = 0 \u2192 (x * y + (-x) * y) + -(x * y) = 0 + -(x * y) := ZA_PF (x * y + (-x) * y) 0 (-(x * y)),\n      have h2: (x * y + (-x) * y) + -(x * y) = 0 + -(x * y) := h1 h,\n      rw ZA_Ass (x * y) (-x * y) (-(x * y)) at h2,\n      rw \u2190ZA_Com (-(x * y)) (-x * y) at h2,\n      rw \u2190ZA_Ass (x * y) (-(x * y)) (-x * y) at h2,\n      rw \u2190ZA_invR (x * y) at h2,\n      rw \u2190ZA_idL (-x * y) at h2,\n      rw \u2190ZA_idL (-(x * y)) at h2,\n      exact h2,\n    end\n  theorem ZS_MNegD: \u2200 (x y : \u2124), x * (-y) = -(x * y) :=\n    begin\n      intros x y,\n      have h: x * y + x * (-y) = 0,\n      conv{\n        to_lhs,\n        rw \u2190Z_DistL y (-y) x,\n        rw \u2190ZA_invR y,\n        rw ZM_AnR x,\n      },\n      have h1: (x * y + x * (-y)) = 0 \u2192 (x * y + x * (-y)) + -(x * y) = 0 + - (x * y) := ZA_PF (x * y + x * (-y)) 0 (-(x * y)),\n      have h2: (x * y + x * (-y)) + -(x * y) = 0 + - (x * y) := h1 h,\n      rw ZA_Ass (x * y) (x * -y) (-(x * y)) at h2,\n      rw ZA_Com (x * -y) (-(x * y)) at h2,\n      rw \u2190ZA_Ass (x * y) (-(x * y)) (x * -y) at h2,\n      rw \u2190ZA_invR (x * y) at h2,\n      rw \u2190ZA_idL (x * -y) at h2,\n      rw \u2190ZA_idL (-(x * y)) at h2,\n      exact h2,\n    end\n  theorem ZS_MNegT: \u2200 (x y : \u2124), (-x) * y = x * (-y) :=\n    begin\n      intros x y,\n      conv{\n        to_rhs,\n        rw ZS_MNegD x y,\n        rw \u2190ZS_MNegU x y,\n      },\n    end\n  theorem ZS_PNeg: \u2200 (x y : \u2124), (-x) * (-y) = x * y :=\n    begin\n      intros x y,\n      conv{\n        to_lhs,\n        rw \u2190ZS_Neg x,\n        rw ZM_Ass (-1) x (-y),\n        rw ZS_Neg (x * (-y)),\n        rw ZS_MNegD x y,\n        rw ZS_DNeg,\n      },\n    end\n  theorem ZS_TNegU: \u2200 (x y : \u2124), -(x + (-y)) = y + (-x) :=\n    begin\n      intros x y,\n      conv{\n        to_lhs,\n        rw \u2190ZS_Neg,\n        rw Z_DistL x (-y) (-1),\n        rw ZS_Neg x,\n        rw ZS_Neg (-y),\n        rw ZS_DNeg,\n        rw ZA_Com,\n      },\n    end\n  theorem ZS_TNegD: \u2200 (x y : \u2124), -(x + y) = -x + (-y) :=\n    begin\n      intros x y,\n      conv{\n        to_lhs,\n        rw \u2190ZS_Neg,\n        rw Z_DistL x y (-1),\n        rw ZS_Neg x,\n        rw ZS_Neg y,\n      },\n    end\n------------------------------------------------\n-- Teoremas de Passar pro Outro Lado:\n------------------------------------------------\n  theorem ZA_polu: \u2200 (a b c : \u2124), a + b = c \u2194 a = c + (-b) :=\n    begin\n      intros a b c,\n      split,\n      intro h,\n      conv{\n        to_lhs,\n        rw ZA_idR a,\n        rw ZA_invR c,\n        congr,\n        skip,\n        congr,\n        skip,\n        rw \u2190h,\n        rw ZS_TNegD,\n      },\n      conv{\n        to_lhs,\n        rw \u2190ZA_Ass c (-a) (-b),\n        rw ZA_Com c (-a),\n        rw ZA_Ass (-a) c (-b),\n        rw \u2190ZA_Ass a (-a) (c + (-b)),\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idL,\n      },\n      intro h,\n      conv{\n        to_rhs,\n        rw ZA_idR c,\n        rw ZA_invR a,\n        congr,\n        skip,\n        congr,\n        skip,\n        rw h,\n        rw ZS_TNegU,\n        rw ZA_Com,\n      },\n      conv{\n        to_rhs,\n        rw \u2190ZA_Ass a (-c) b,\n        rw ZA_Com a (-c),\n        rw ZA_Ass (-c) a b,\n        rw \u2190ZA_Ass c (-c) (a + b),\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idL,\n      },\n    end\n  theorem ZA_pold: \u2200 (a b c : \u2124), a + b = c \u2194 b = c + (-a) :=\n    begin\n      intros a b c,\n      split,\n      intro h,\n      conv{\n        to_lhs,\n        rw ZA_idR b,\n        rw ZA_invR c,\n        congr,\n        skip,\n        congr,\n        skip,\n        rw \u2190h,\n        rw ZS_TNegD,\n        rw ZA_Com,\n      },\n      conv{\n        to_lhs,\n        rw \u2190ZA_Ass c (-b) (-a),\n        rw ZA_Com c (-b),\n        rw ZA_Ass (-b) c (-a),\n        rw \u2190ZA_Ass b (-b) (c + (-a)),\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idL,\n      },\n      intro h,\n      conv{\n        to_rhs,\n        rw ZA_idR c,\n        rw ZA_invR b,\n        congr,\n        skip,\n        congr,\n        skip,\n        rw h,\n        rw ZS_TNegU,\n        rw ZA_Com,\n      },\n      conv{\n        to_rhs,\n        rw \u2190ZA_Ass b (-c) a,\n        rw ZA_Com b (-c),\n        rw ZA_Ass (-c) b a,\n        rw \u2190ZA_Ass c (-c) (b + a),\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idL,\n        rw ZA_Com,\n      },\n    end\n  theorem ZA_polt: \u2200 (a b : \u2124), a = b \u2194 a + (-b) = 0 :=\n    begin\n      intros a b,\n      split,\n      intro h,\n      conv{\n        to_lhs,\n        rw h,\n        rw \u2190ZA_invR,\n      },\n      intro h,\n      conv{\n        to_rhs,\n        rw ZA_idR b,\n        rw \u2190h,\n        rw ZA_Com a (-b),\n        rw \u2190ZA_Ass b (-b) (a),\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idL,\n      },\n    end\n------------------------------------------------\n-- Teoremas de Cancelamento:\n------------------------------------------------\n  theorem ZA_CanR: \u2200 (a b c : \u2124), a + c = b + c \u2192 a = b :=\n    begin\n      intros a b c h,\n      conv{\n        to_lhs,\n        rw ZA_idR a,\n        rw ZA_invR c,\n        rw \u2190ZA_Ass a c (-c),\n        rw h,\n        rw ZA_Ass b c (-c),\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idR,\n      },\n    end\n  theorem ZA_CanL: \u2200 (a b c : \u2124), c + a = c + b \u2192 a = b :=\n    begin\n      intros a b c h,\n      have h1: a + c = b + c \u2192 a = b := ZA_CanR a b c,\n      rw \u2190ZA_Com a c at h,\n      rw \u2190ZA_Com b c at h,\n      have h2: a = b := h1 h,\n      exact h2,\n    end\n  theorem ZM_CanR: \u2200 (a b c : \u2124), a * c = b * c \u2192 c = 0 \u2228 a = b :=\n    begin\n      intros a b c h,\n      have h1: (a + (-b)) * c = 0,\n      conv{\n        to_lhs,\n        rw Z_DistR,\n        rw h,\n        rw ZS_MNegU,\n        rw \u2190ZA_invR,\n      },\n      have h2: (a + (-b)) * c = 0 \u2192 (a + (-b)) = 0 \u2228 c = 0 := Z_NZD (a + (-b)) c,\n      have h3: (a + (-b)) = 0 \u2228 c = 0 := h2 h1,\n      cases h3 with hig hc,\n      right,\n      have h4: a = b \u2194 a + (-b) = 0 := ZA_polt a b,\n      cases h4,\n      have h5: a = b := h4_mpr hig,\n      exact h5,\n      left,\n      exact hc,\n    end\n  theorem ZM_CanL: \u2200 (a b c : \u2124), c * a = c * b \u2192 c = 0 \u2228 a = b :=\n    begin\n      intros a b c h,\n      have h1: a * c = b * c \u2192 c = 0 \u2228 a = b := ZM_CanR a b c,\n      rw \u2190ZM_Com a c at h,\n      rw \u2190ZM_Com b c at h,\n      have h2: c = 0 \u2228 a = b := h1 h,\n      exact h2,\n    end\n------------------------------------------------\n-- Exist\u00eancias e Unicidades:\n------------------------------------------------\n  theorem ZA_ResExi: \u2200 (a b: \u2124), (\u2203 x : \u2124, a + x = b) :=\n    begin\n      intros a b,\n      existsi (-a + b),\n      rw \u2190ZA_Ass a (-a) b,\n      rw \u2190ZA_invR,\n      rw \u2190ZA_idL,\n    end\n  theorem ZA_ResUni: \u2200 (a b x y: \u2124), ((a + x = b) \u2227 (a + y = b)) \u2192 x = y :=\n    begin\n      intros a b x y h,\n      cases h,\n      have h: a + x = a + y,\n      conv{\n        to_lhs,\n        rw h_left,\n        rw \u2190h_right,\n      },\n      have h1: a + x = a + y \u2192 x = y := ZA_CanL x y a,\n      have h2: x = y := h1 h,\n      exact h2,\n    end\n  theorem ZA_IdExi: \u2200 (a : \u2124), \u2203 x : \u2124, a + x = a:=\n    begin\n      intro a,\n      existsi (a + (-a)),\n      rw \u2190ZA_invR,\n      rw \u2190ZA_idR,\n    end\n  theorem ZA_IdUni: \u2200 (a b: \u2124), ((a + b = a) \u2227 (b + a = a)) \u2192 b = 0 :=\n    begin\n      intros a b h,\n      cases h with hab hba,\n      have h: a + 0 = a,\n      have h1: a = a + 0 := ZA_idR a,\n      conv{\n        to_lhs,\n        rw \u2190ZA_idR,\n      },\n      have h1: ((a + b = a) \u2227 (a + 0 = a)) \u2192 b = 0 := ZA_ResUni a a b 0,\n      have h2: (a + b = a) \u2227 (a + 0 = a),\n      split,\n      exact hab,\n      exact h,\n      have h3: (b = 0) := h1 h2,\n      exact h3,\n    end\n  theorem ZM_IdExi: \u2200 (a : \u2124), \u2203 x : \u2124, a * x = a:=\n    begin\n      intro a,\n      existsi (1 + (a + (-a))),\n      conv{\n        to_lhs,\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idR,\n        rw \u2190ZM_idR,\n      },\n    end\n  theorem ZM_IdUni: \u2200 (a u v: \u2124), (is_ZM_idR u \u2227 is_ZM_idR v) \u2192 u = v :=\n    begin\n      intros a u v h,\n      cases h with hu hv,\n      calc\n        u = u * v : by rw [hv u]\n      ... = v * u : by rw [ZM_Com v u]\n      ... = v : by rw [hu v],\n    end\n  theorem ZA_InvExi: \u2200 (x : \u2124), (\u2203 k : \u2124, x + k = 0) :=\n    begin\n      intro x,\n      existsi (0 + (-x)),\n      conv{\n        to_lhs,\n        rw \u2190ZA_idL (-x),\n        rw \u2190ZA_invR x,\n      },\n    end\n  theorem ZA_InvUni: \u2200 (x u : \u2124), ((u + x = 0) \u2227 (x + u = 0)) \u2192 u = -x :=\n    begin\n      intros x u h,\n      cases h with ux xu,\n      have h: (x + u) = 0 \u2192 (x + u) + (-x) = 0 + (-x) := ZA_PF (x + u) 0 (-x),\n      have h1: (x + u) + (-x) = 0 + (-x) := h xu,\n      rw ZA_Ass x u (-x) at h1,\n      rw ZA_Com u (-x) at h1,\n      rw \u2190ZA_Ass x (-x) u at h1,\n      rw \u2190ZA_invR x at h1,\n      rw \u2190ZA_idL u at h1,\n      rw \u2190ZA_idL (-x) at h1,\n      exact h1,\n    end\n------------------------------------------------\n-- Z_NZD pelo ZM_CanR:\n------------------------------------------------\n  theorem Z_NZD': \u2200 (a b : \u2124), a * b = 0 \u2192 a = 0 \u2228 b = 0 :=\n    begin\n      intros a b h,\n      have h1: a * b = 0 * b \u2192 b = 0 \u2228 a = 0 := ZM_CanR a 0 b,\n      rw \u2190ZM_AnL b at h,\n      have h2: b = 0 \u2228 a = 0 := h1 h,\n      cases h2,\n      right,\n      exact h2,\n      left,\n      exact h2,\n    end\n------------------------------------------------\n-- Propriedades divisibilidade:\n------------------------------------------------\n  theorem ZD_p1: \u2200 (a : \u2124), \u2203 x : \u2124, a = x * 1 :=\n    begin\n      intro a,\n      existsi a,\n      conv{\n        to_rhs,\n        rw \u2190ZM_idR,\n      },\n    end\n  theorem ZD_p2: \u2200 (a : \u2124), \u2203 x : \u2124, 0 = x * a :=\n    begin\n      intro a,\n      existsi (a * 0),\n      rw ZM_AnR,\n      rw ZM_AnL,\n    end\n  theorem ZD_p3: \u2200 (a b x : \u2124), (\u2203 k : \u2124, b = k * a) \u2192 (\u2203 l : \u2124, b * x = l * a) :=\n    begin\n      intros a b x,\n      intro h,\n      cases h with k hb,\n      existsi (k * x),\n      conv{\n        to_lhs,\n        rw hb,\n        rw ZM_Ass,\n        rw ZM_Com a x,\n        rw \u2190ZM_Ass,\n      },\n    end\n  theorem ZD_p4: \u2200 (a b : \u2124), (\u2203 k : \u2124, b = a * k) \u2192 (\u2203 l : \u2124, (-b) = a * l) \u2227 (\u2203 m : \u2124, b = (-a) * m) :=\n    begin\n      intros a b h,\n      cases h with k h,\n      split,\n      existsi (-k),\n      conv{\n        to_rhs,\n        rw ZS_MNegD,\n        rw \u2190h,\n      },\n      existsi (-k),\n      conv{\n        to_rhs,\n        rw ZS_PNeg,\n        rw \u2190h,\n      },\n    end\n  theorem ZD_p5: \u2200 (a b c: \u2124), (\u2203 k : \u2124, b = a * k) \u2227 (\u2203 l : \u2124, c = a * l) \u2192 (\u2203 m : \u2124, b + c = a * m) :=\n    begin\n      intros a b c h,\n      cases h with hek hel,\n      cases hek with k hk,\n      cases hel with l hl,\n      existsi (k + l),\n      conv{\n        to_rhs,\n        rw Z_DistL,\n        rw \u2190hk,\n        rw \u2190hl,\n      },\n    end\n  theorem ZD_p6: \u2200 (a b c x y: \u2124), (\u2203 k : \u2124, b = a * k) \u2227 (\u2203 l : \u2124, c = a * l) \u2192 (\u2203 m : \u2124, b * x + c * y = a * m) :=\n    begin\n      intros a b c x y h,\n      cases h with hek hel,\n      cases hek with k hk,\n      cases hel with l hl,\n      existsi (k * x + l * y),\n      conv{\n        to_rhs,\n        rw Z_DistL,\n        congr,\n        rw ZM_Com k x,\n        rw \u2190ZM_Ass,\n        rw ZM_Com,\n        skip,\n        rw ZM_Com l y,\n        rw \u2190ZM_Ass,\n        rw ZM_Com,\n      },\n      conv{\n        to_lhs,\n        congr,\n        rw hk,\n        rw ZM_Com a k,\n        rw ZM_Ass,\n        skip,\n        rw hl,\n        rw ZM_Com a l,\n        rw ZM_Ass,\n      },\n    end\n  theorem ZD_p7: \u2200 (a b: \u2124), ((\u2203 k : \u2124, b = a * k) \u2227 (b = 0 \u2192 false)) \u2192 (|a|) < (|b|) \u2228 (|a|) = (|b|) :=\n    begin\n      intros a b h,\n      cases h,\n      cases h_left with k hk,\n      have h: (a = 0) \u2228 (a > 0) \u2228 (a < 0) := ZP_Tri a,\n      have h1: (b = 0) \u2228 (b > 0) \u2228 (b < 0) := ZP_Tri b,\n      cases h,\n      cases h1,\n      contradiction,\n      cases h1,\n      have h2: a > 0 \u2228 a = 0,\n      right,\n      exact h,\n      left,\n      show (|a|) < (|b|),\n    end\n  theorem ZD_p8: \u2200 (a b c: \u2124), ((c = 0) \u2192 false) \u2192 ((\u2203 k : \u2124, b = a * k) \u2194 (\u2203 l : \u2124, c * b = (c * a) * l)) :=\n    begin\n      intros a b c hnc,\n      split,\n      intro hek,\n      cases hek with k hk,\n      existsi (k),\n      conv{\n        to_lhs,\n        rw hk,\n        rw \u2190ZM_Ass,\n      },\n      intro hel,\n      cases hel with l hl,\n      have h: c * (b + -(a * l)) = 0,\n      conv{\n        to_lhs,\n        rw Z_DistL,\n        rw ZS_MNegD,\n        rw \u2190ZM_Ass,\n        rw hl,\n        rw \u2190ZA_invR,\n      },\n      have h1: (c * (b + -(a * l))) = 0 \u2192 c = 0 \u2228 (b + -(a * l)) = 0 := Z_NZD c (b + -(a * l)),\n      have h2: c = 0 \u2228 (b + -(a * l)) = 0 := h1 h,\n      cases h2,\n      contradiction,\n      existsi l,\n      conv{\n        to_rhs,\n        rw ZA_idR (a * l),\n        rw \u2190h2,\n        rw ZA_Com b (-(a * l)),\n        rw \u2190ZA_Ass (a * l) (-(a * l)) (b),\n        rw \u2190ZA_invR,\n        rw \u2190ZA_idL b,\n      },\n    end\n  theorem ZD_Refl: \u2200 (a: \u2124), (\u2203 k : \u2124, a = a * k) :=\n    begin\n      intro a,\n      existsi (1 + (a +(-a))),\n      conv{\n        to_rhs,\n        rw \u2190ZA_invR a,\n        rw \u2190ZA_idR 1,\n        rw \u2190ZM_idR a,\n      },\n    end\n  theorem ZD_Trans: \u2200 (a b c: \u2124), (\u2203 k : \u2124, b = a * k) \u2227 (\u2203 l : \u2124, c = b * l) \u2192 (\u2203 m : \u2124, c = a * m) :=\n    begin\n      intros a b c h,\n      cases h with hek hel,\n      cases hek with k hk,\n      cases hel with l hl,\n      have h1: c = a * (k * l),\n      conv{\n        to_rhs,\n        rw \u2190ZM_Ass,\n        rw \u2190hk,\n        rw \u2190hl,\n      },\n      existsi (k * l),\n      exact h1,\n    end\n------------------------------------------------\n-- Teoremas de Ordem:\n------------------------------------------------\n------------------------------------------------\n-- Irredut\u00edvel, Primo e Prime:\n------------------------------------------------\n  theorem Z_IrredPrime: \u2200 (a b p : \u2124), (p = 0 \u2192 false) \u2192 ((p = a * b \u2192 (unit' a \u2228 unit' b)) \u2194 ((\u2203 k : \u2124, a * b = p * k) \u2192 unit' a \u2228 unit' b)) :=\n    begin\n      intros a b p hnp0,\n      split,\n      intro h,\n      intro hek,\n      cases hek with k hk,\n      apply h,\n      sorry,\n      intro h,\n      intro h1,\n      apply h,\n      existsi (1 + (a + (-a))),\n      conv{\n        to_rhs,\n        rw \u2190ZA_invR a,\n        rw \u2190ZA_idR 1,\n        rw \u2190ZM_idR p,\n        rw h1,\n      },\n    end\n  theorem Z_IrredPrimo: \u2200 (a b p : \u2124), (p = 0 \u2192 false) \u2192 ((p = a * b \u2192 (unit' a \u2228 unit' b)) \u2194 (\u2200 (x : \u2124), (\u2203 k : \u2124, p = x * k))) :=\n    begin\n      intros a b p hnp0,\n      split,\n      intros h x,\n\n    end", "meta": {"author": "Minobarbarian", "repo": "fmc1repo", "sha": "1856c18dc57a2d041a553bd3cb7dceb3ec386176", "save_path": "github-repos/lean/Minobarbarian-fmc1repo", "path": "github-repos/lean/Minobarbarian-fmc1repo/fmc1repo-1856c18dc57a2d041a553bd3cb7dceb3ec386176/ints/ints.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7220800994572044}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n-/\nimport algebra.group_power.basic\nimport algebra.group_with_zero.divisibility\nimport data.nat.order.lemmas\n\n/-!\n# Definitions and properties of `nat.gcd`, `nat.lcm`, and `nat.coprime`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGeneralizations of these are provided in a later file as `gcd_monoid.gcd` and\n`gcd_monoid.lcm`.\n\nNote that the global `is_coprime` is not a straightforward generalization of `nat.coprime`, see\n`nat.is_coprime_iff_coprime` for the connection between the two.\n\n-/\n\nnamespace nat\n\n/-! ### `gcd` -/\n\ntheorem gcd_dvd (m n : \u2115) : (gcd m n \u2223 m) \u2227 (gcd m n \u2223 n) :=\ngcd.induction m n\n  (\u03bbn, by rw gcd_zero_left; exact \u27e8dvd_zero n, dvd_refl n\u27e9)\n  (\u03bbm n npos, by rw \u2190gcd_rec; exact \u03bb \u27e8IH\u2081, IH\u2082\u27e9, \u27e8IH\u2082, (dvd_mod_iff IH\u2082).1 IH\u2081\u27e9)\n\ntheorem gcd_dvd_left (m n : \u2115) : gcd m n \u2223 m := (gcd_dvd m n).left\n\ntheorem gcd_dvd_right (m n : \u2115) : gcd m n \u2223 n := (gcd_dvd m n).right\n\ntheorem gcd_le_left {m} (n) (h : 0 < m) : gcd m n \u2264 m := le_of_dvd h $ gcd_dvd_left m n\n\ntheorem gcd_le_right (m) {n} (h : 0 < n) : gcd m n \u2264 n := le_of_dvd h $ gcd_dvd_right m n\n\ntheorem dvd_gcd {m n k : \u2115} : k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 gcd m n :=\ngcd.induction m n (\u03bbn _ kn, by rw gcd_zero_left; exact kn)\n  (\u03bbn m mpos IH H1 H2, by rw gcd_rec; exact IH ((dvd_mod_iff H1).2 H2) H1)\n\ntheorem dvd_gcd_iff {m n k : \u2115} : k \u2223 gcd m n \u2194 k \u2223 m \u2227 k \u2223 n :=\niff.intro (\u03bb h, \u27e8h.trans (gcd_dvd m n).left, h.trans (gcd_dvd m n).right\u27e9)\n          (\u03bb h, dvd_gcd h.left h.right)\n\ntheorem gcd_comm (m n : \u2115) : gcd m n = gcd n m :=\ndvd_antisymm\n  (dvd_gcd (gcd_dvd_right m n) (gcd_dvd_left m n))\n  (dvd_gcd (gcd_dvd_right n m) (gcd_dvd_left n m))\n\ntheorem gcd_eq_left_iff_dvd {m n : \u2115} : m \u2223 n \u2194 gcd m n = m :=\n\u27e8\u03bb h, by rw [gcd_rec, mod_eq_zero_of_dvd h, gcd_zero_left],\n \u03bb h, h \u25b8 gcd_dvd_right m n\u27e9\n\ntheorem gcd_eq_right_iff_dvd {m n : \u2115} : m \u2223 n \u2194 gcd n m = m :=\nby rw gcd_comm; apply gcd_eq_left_iff_dvd\n\ntheorem gcd_assoc (m n k : \u2115) : gcd (gcd m n) k = gcd m (gcd n k) :=\ndvd_antisymm\n  (dvd_gcd\n    ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n))\n    (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n))\n      (gcd_dvd_right (gcd m n) k)))\n  (dvd_gcd\n    (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k)))\n    ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k)))\n\n@[simp] theorem gcd_one_right (n : \u2115) : gcd n 1 = 1 :=\neq.trans (gcd_comm n 1) $ gcd_one_left n\n\ntheorem gcd_mul_left (m n k : \u2115) : gcd (m * n) (m * k) = m * gcd n k :=\ngcd.induction n k\n  (\u03bbk, by repeat {rw mul_zero <|> rw gcd_zero_left})\n  (\u03bbk n H IH, by rwa [\u2190mul_mod_mul_left, \u2190gcd_rec, \u2190gcd_rec] at IH)\n\ntheorem gcd_mul_right (m n k : \u2115) : gcd (m * n) (k * n) = gcd m k * n :=\nby rw [mul_comm m n, mul_comm k n, mul_comm (gcd m k) n, gcd_mul_left]\n\ntheorem gcd_pos_of_pos_left {m : \u2115} (n : \u2115) (mpos : 0 < m) : 0 < gcd m n :=\npos_of_dvd_of_pos (gcd_dvd_left m n) mpos\n\ntheorem gcd_pos_of_pos_right (m : \u2115) {n : \u2115} (npos : 0 < n) : 0 < gcd m n :=\npos_of_dvd_of_pos (gcd_dvd_right m n) npos\n\ntheorem eq_zero_of_gcd_eq_zero_left {m n : \u2115} (H : gcd m n = 0) : m = 0 :=\nor.elim (nat.eq_zero_or_pos m) id\n  (assume H1 : 0 < m, absurd (eq.symm H) (ne_of_lt (gcd_pos_of_pos_left _ H1)))\n\ntheorem eq_zero_of_gcd_eq_zero_right {m n : \u2115} (H : gcd m n = 0) : n = 0 :=\nby rw gcd_comm at H; exact eq_zero_of_gcd_eq_zero_left H\n\n@[simp] theorem gcd_eq_zero_iff {i j : \u2115} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 :=\nbegin\n  split,\n  { intro h,\n    exact \u27e8eq_zero_of_gcd_eq_zero_left h, eq_zero_of_gcd_eq_zero_right h\u27e9, },\n  { rintro \u27e8rfl, rfl\u27e9,\n    exact nat.gcd_zero_right 0 }\nend\n\ntheorem gcd_div {m n k : \u2115} (H1 : k \u2223 m) (H2 : k \u2223 n) :\n  gcd (m / k) (n / k) = gcd m n / k :=\n(decidable.eq_or_ne k 0).elim\n  (\u03bbk0, by rw [k0, nat.div_zero, nat.div_zero, nat.div_zero, gcd_zero_right])\n  (\u03bbH3, mul_right_cancel\u2080 H3 $ by rw [\n    nat.div_mul_cancel (dvd_gcd H1 H2), \u2190gcd_mul_right,\n    nat.div_mul_cancel H1, nat.div_mul_cancel H2])\n\ntheorem gcd_greatest {a b d : \u2115} (hda : d \u2223 a) (hdb : d \u2223 b)\n  (hd : \u2200 e : \u2115, e \u2223 a \u2192 e \u2223 b \u2192 e \u2223 d) : d = a.gcd b :=\n(dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm\n\ntheorem gcd_dvd_gcd_of_dvd_left {m k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd m n \u2223 gcd k n :=\ndvd_gcd ((gcd_dvd_left m n).trans H) (gcd_dvd_right m n)\n\ntheorem gcd_dvd_gcd_of_dvd_right {m k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd n m \u2223 gcd n k :=\ndvd_gcd (gcd_dvd_left n m) ((gcd_dvd_right n m).trans H)\n\ntheorem gcd_dvd_gcd_mul_left (m n k : \u2115) : gcd m n \u2223 gcd (k * m) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (m n k : \u2115) : gcd m n \u2223 gcd (m * k) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (m n k : \u2115) : gcd m n \u2223 gcd m (k * n) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (m n k : \u2115) : gcd m n \u2223 gcd m (n * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {m n : \u2115} (H : m \u2223 n) : gcd m n = m :=\ndvd_antisymm (gcd_dvd_left _ _) (dvd_gcd dvd_rfl H)\n\ntheorem gcd_eq_right {m n : \u2115} (H : n \u2223 m) : gcd m n = n :=\nby rw [gcd_comm, gcd_eq_left H]\n\n-- Lemmas where one argument is a multiple of the other\n\n@[simp] lemma gcd_mul_left_left (m n : \u2115) : gcd (m * n) n = n :=\ndvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (dvd_mul_left _ _) dvd_rfl)\n\n@[simp] lemma gcd_mul_left_right (m n : \u2115) : gcd n (m * n) = n :=\nby rw [gcd_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_left (m n : \u2115) : gcd (n * m) n = n :=\nby rw [mul_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_right (m n : \u2115) : gcd n (n * m) = n :=\nby rw [gcd_comm, gcd_mul_right_left]\n\n-- Lemmas for repeated application of `gcd`\n\n@[simp] lemma gcd_gcd_self_right_left (m n : \u2115) : gcd m (gcd m n) = gcd m n :=\ndvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (gcd_dvd_left _ _) dvd_rfl)\n\n@[simp] lemma gcd_gcd_self_right_right (m n : \u2115) : gcd m (gcd n m) = gcd n m :=\nby rw [gcd_comm n m, gcd_gcd_self_right_left]\n\n@[simp] lemma gcd_gcd_self_left_right (m n : \u2115) : gcd (gcd n m) m = gcd n m :=\nby rw [gcd_comm, gcd_gcd_self_right_right]\n\n@[simp] lemma gcd_gcd_self_left_left (m n : \u2115) : gcd (gcd m n) m = gcd m n :=\nby rw [gcd_comm m n, gcd_gcd_self_left_right]\n\n-- Lemmas where one argument consists of addition of a multiple of the other\n\n@[simp] lemma gcd_add_mul_right_right (m n k : \u2115) : gcd m (n + k * m) = gcd m n :=\nby simp [gcd_rec m (n + k * m), gcd_rec m n]\n\n@[simp] lemma gcd_add_mul_left_right (m n k : \u2115) : gcd m (n + m * k) = gcd m n :=\nby simp [gcd_rec m (n + m * k), gcd_rec m n]\n\n@[simp] lemma gcd_mul_right_add_right (m n k : \u2115) : gcd m (k * m + n) = gcd m n :=\nby simp [add_comm _ n]\n\n@[simp] lemma gcd_mul_left_add_right (m n k : \u2115) : gcd m (m * k + n) = gcd m n :=\nby simp [add_comm _ n]\n\n@[simp] lemma gcd_add_mul_right_left (m n k : \u2115) : gcd (m + k * n) n = gcd m n :=\nby rw [gcd_comm, gcd_add_mul_right_right, gcd_comm]\n\n@[simp] lemma gcd_add_mul_left_left (m n k : \u2115) : gcd (m + n * k) n = gcd m n :=\nby rw [gcd_comm, gcd_add_mul_left_right, gcd_comm]\n\n@[simp] lemma gcd_mul_right_add_left (m n k : \u2115) : gcd (k * n + m) n = gcd m n :=\nby rw [gcd_comm, gcd_mul_right_add_right, gcd_comm]\n\n@[simp] lemma gcd_mul_left_add_left (m n k : \u2115) : gcd (n * k + m) n = gcd m n :=\nby rw [gcd_comm, gcd_mul_left_add_right, gcd_comm]\n\n-- Lemmas where one argument consists of an addition of the other\n\n@[simp] lemma gcd_add_self_right (m n : \u2115) : gcd m (n + m) = gcd m n :=\neq.trans (by rw one_mul) (gcd_add_mul_right_right m n 1)\n\n@[simp] lemma gcd_add_self_left (m n : \u2115) : gcd (m + n) n = gcd m n :=\nby rw [gcd_comm, gcd_add_self_right, gcd_comm]\n\n@[simp] lemma gcd_self_add_left (m n : \u2115) : gcd (m + n) m = gcd n m :=\nby rw [add_comm, gcd_add_self_left]\n\n@[simp] lemma gcd_self_add_right (m n : \u2115) : gcd m (m + n) = gcd m n :=\nby rw [add_comm, gcd_add_self_right]\n\n/-! ### `lcm` -/\n\ntheorem lcm_comm (m n : \u2115) : lcm m n = lcm n m :=\nby delta lcm; rw [mul_comm, gcd_comm]\n\n@[simp]\ntheorem lcm_zero_left (m : \u2115) : lcm 0 m = 0 :=\nby delta lcm; rw [zero_mul, nat.zero_div]\n\n@[simp]\ntheorem lcm_zero_right (m : \u2115) : lcm m 0 = 0 := lcm_comm 0 m \u25b8 lcm_zero_left m\n\n@[simp]\ntheorem lcm_one_left (m : \u2115) : lcm 1 m = m :=\nby delta lcm; rw [one_mul, gcd_one_left, nat.div_one]\n\n@[simp]\ntheorem lcm_one_right (m : \u2115) : lcm m 1 = m := lcm_comm 1 m \u25b8 lcm_one_left m\n\n@[simp]\ntheorem lcm_self (m : \u2115) : lcm m m = m :=\nor.elim (nat.eq_zero_or_pos m)\n  (\u03bbh, by rw [h, lcm_zero_left])\n  (\u03bbh, by delta lcm; rw [gcd_self, nat.mul_div_cancel _ h])\n\ntheorem dvd_lcm_left (m n : \u2115) : m \u2223 lcm m n :=\ndvd.intro (n / gcd m n) (nat.mul_div_assoc _ $ gcd_dvd_right m n).symm\n\ntheorem dvd_lcm_right (m n : \u2115) : n \u2223 lcm m n :=\nlcm_comm n m \u25b8 dvd_lcm_left n m\n\ntheorem gcd_mul_lcm (m n : \u2115) : gcd m n * lcm m n = m * n :=\nby delta lcm; rw [nat.mul_div_cancel' ((gcd_dvd_left m n).trans (dvd_mul_right m n))]\n\ntheorem lcm_dvd {m n k : \u2115} (H1 : m \u2223 k) (H2 : n \u2223 k) : lcm m n \u2223 k :=\nor.elim (nat.eq_zero_or_pos k)\n  (\u03bbh, by rw h; exact dvd_zero _)\n  (\u03bbkpos, dvd_of_mul_dvd_mul_left (gcd_pos_of_pos_left n (pos_of_dvd_of_pos H1 kpos)) $\n    by rw [gcd_mul_lcm, \u2190gcd_mul_right, mul_comm n k];\n       exact dvd_gcd (mul_dvd_mul_left _ H2) (mul_dvd_mul_right H1 _))\n\ntheorem lcm_dvd_mul (m n : \u2115) : lcm m n \u2223 m * n :=\nlcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _)\n\nlemma lcm_dvd_iff {m n k : \u2115} : lcm m n \u2223 k \u2194 m \u2223 k \u2227 n \u2223 k :=\n\u27e8\u03bb h, \u27e8(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h\u27e9,\n  and_imp.2 lcm_dvd\u27e9\n\ntheorem lcm_assoc (m n k : \u2115) : lcm (lcm m n) k = lcm m (lcm n k) :=\ndvd_antisymm\n  (lcm_dvd\n    (lcm_dvd (dvd_lcm_left m (lcm n k)) ((dvd_lcm_left n k).trans (dvd_lcm_right m (lcm n k))))\n    ((dvd_lcm_right n k).trans (dvd_lcm_right m (lcm n k))))\n  (lcm_dvd\n    ((dvd_lcm_left m n).trans (dvd_lcm_left (lcm m n) k))\n    (lcm_dvd ((dvd_lcm_right m n).trans (dvd_lcm_left (lcm m n) k))\n      (dvd_lcm_right (lcm m n) k)))\n\ntheorem lcm_ne_zero {m n : \u2115} (hm : m \u2260 0) (hn : n \u2260 0) : lcm m n \u2260 0 :=\nby { intro h, simpa [h, hm, hn] using gcd_mul_lcm m n, }\n\n/-!\n### `coprime`\n\nSee also `nat.coprime_of_dvd` and `nat.coprime_of_dvd'` to prove `nat.coprime m n`.\n-/\n\ninstance (m n : \u2115) : decidable (coprime m n) := by unfold coprime; apply_instance\n\ntheorem coprime_iff_gcd_eq_one {m n : \u2115} : coprime m n \u2194 gcd m n = 1 := iff.rfl\n\ntheorem coprime.gcd_eq_one {m n : \u2115} (h : coprime m n) : gcd m n = 1 := h\n\ntheorem coprime.lcm_eq_mul {m n : \u2115} (h : coprime m n) : lcm m n = m * n :=\nby rw [\u2190one_mul (lcm m n), \u2190h.gcd_eq_one, gcd_mul_lcm]\n\ntheorem coprime.symm {m n : \u2115} : coprime n m \u2192 coprime m n := (gcd_comm m n).trans\n\ntheorem coprime_comm {m n : \u2115} : coprime n m \u2194 coprime m n := \u27e8coprime.symm, coprime.symm\u27e9\n\ntheorem coprime.symmetric : symmetric coprime := \u03bb m n, coprime.symm\n\ntheorem coprime.dvd_of_dvd_mul_right {m n k : \u2115} (H1 : coprime k n) (H2 : k \u2223 m * n) : k \u2223 m :=\nlet t := dvd_gcd (dvd_mul_left k m) H2 in\nby rwa [gcd_mul_left, H1.gcd_eq_one, mul_one] at t\n\n\n\ntheorem coprime.dvd_mul_right {m n k : \u2115} (H : coprime k n) : k \u2223 m * n \u2194 k \u2223 m :=\n\u27e8H.dvd_of_dvd_mul_right, \u03bb h, dvd_mul_of_dvd_left h n\u27e9\n\ntheorem coprime.dvd_mul_left {m n k : \u2115} (H : coprime k m) : k \u2223 m * n \u2194 k \u2223 n :=\n\u27e8H.dvd_of_dvd_mul_left, \u03bb h, dvd_mul_of_dvd_right h m\u27e9\n\ntheorem coprime.gcd_mul_left_cancel {k : \u2115} (m : \u2115) {n : \u2115} (H : coprime k n) :\n   gcd (k * m) n = gcd m n :=\nhave H1 : coprime (gcd (k * m) n) k,\nby rw [coprime, gcd_assoc, H.symm.gcd_eq_one, gcd_one_right],\ndvd_antisymm\n  (dvd_gcd (H1.dvd_of_dvd_mul_left (gcd_dvd_left _ _)) (gcd_dvd_right _ _))\n  (gcd_dvd_gcd_mul_left _ _ _)\n\ntheorem coprime.gcd_mul_right_cancel (m : \u2115) {k n : \u2115} (H : coprime k n) :\n   gcd (m * k) n = gcd m n :=\nby rw [mul_comm m k, H.gcd_mul_left_cancel m]\n\ntheorem coprime.gcd_mul_left_cancel_right {k m : \u2115} (n : \u2115) (H : coprime k m) :\n   gcd m (k * n) = gcd m n :=\nby rw [gcd_comm m n, gcd_comm m (k * n), H.gcd_mul_left_cancel n]\n\ntheorem coprime.gcd_mul_right_cancel_right {k m : \u2115} (n : \u2115) (H : coprime k m) :\n   gcd m (n * k) = gcd m n :=\nby rw [mul_comm n k, H.gcd_mul_left_cancel_right n]\n\ntheorem coprime_div_gcd_div_gcd {m n : \u2115} (H : 0 < gcd m n) :\n  coprime (m / gcd m n) (n / gcd m n) :=\nby rw [coprime_iff_gcd_eq_one, gcd_div (gcd_dvd_left m n) (gcd_dvd_right m n), nat.div_self H]\n\ntheorem not_coprime_of_dvd_of_dvd {m n d : \u2115} (dgt1 : 1 < d) (Hm : d \u2223 m) (Hn : d \u2223 n) :\n  \u00ac coprime m n :=\n\u03bb co, not_lt_of_ge (le_of_dvd zero_lt_one $ by rw [\u2190co.gcd_eq_one]; exact dvd_gcd Hm Hn) dgt1\n\ntheorem exists_coprime {m n : \u2115} (H : 0 < gcd m n) :\n  \u2203 m' n', coprime m' n' \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n\u27e8_, _, coprime_div_gcd_div_gcd H,\n  (nat.div_mul_cancel (gcd_dvd_left m n)).symm,\n  (nat.div_mul_cancel (gcd_dvd_right m n)).symm\u27e9\n\ntheorem exists_coprime' {m n : \u2115} (H : 0 < gcd m n) :\n  \u2203 g m' n', 0 < g \u2227 coprime m' n' \u2227 m = m' * g \u2227 n = n' * g :=\nlet \u27e8m', n', h\u27e9 := exists_coprime H in \u27e8_, m', n', H, h\u27e9\n\n@[simp] theorem coprime_add_self_right {m n : \u2115} : coprime m (n + m) \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_add_self_right]\n\n@[simp] theorem coprime_self_add_right {m n : \u2115} : coprime m (m + n) \u2194 coprime m n :=\nby rw [add_comm, coprime_add_self_right]\n\n@[simp] theorem coprime_add_self_left {m n : \u2115} : coprime (m + n) n \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_add_self_left]\n\n@[simp] theorem coprime_self_add_left {m n : \u2115} : coprime (m + n) m \u2194 coprime n m :=\nby rw [coprime, coprime, gcd_self_add_left]\n\n@[simp] lemma coprime_add_mul_right_right (m n k : \u2115) : coprime m (n + k * m) \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_right_right]\n\n@[simp] lemma coprime_add_mul_left_right (m n k : \u2115) : coprime m (n + m * k) \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_left_right]\n\n@[simp] lemma coprime_mul_right_add_right (m n k : \u2115) : coprime m (k * m + n) \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_mul_right_add_right]\n\n@[simp] lemma coprime_mul_left_add_right (m n k : \u2115) : coprime m (m * k + n) \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_mul_left_add_right]\n\n@[simp] lemma coprime_add_mul_right_left (m n k : \u2115) : coprime (m + k * n) n \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_right_left]\n\n@[simp] lemma coprime_add_mul_left_left (m n k : \u2115) : coprime (m + n * k) n \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_left_left]\n\n@[simp] lemma coprime_mul_right_add_left (m n k : \u2115) : coprime (k * n + m) n \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_mul_right_add_left]\n\n@[simp] lemma coprime_mul_left_add_left (m n k : \u2115) : coprime (n * k + m) n \u2194 coprime m n :=\nby rw [coprime, coprime, gcd_mul_left_add_left]\n\ntheorem coprime.mul {m n k : \u2115} (H1 : coprime m k) (H2 : coprime n k) : coprime (m * n) k :=\n(H1.gcd_mul_left_cancel n).trans H2\n\ntheorem coprime.mul_right {k m n : \u2115} (H1 : coprime k m) (H2 : coprime k n) : coprime k (m * n) :=\n(H1.symm.mul H2.symm).symm\n\ntheorem coprime.coprime_dvd_left {m k n : \u2115} (H1 : m \u2223 k) (H2 : coprime k n) : coprime m n :=\neq_one_of_dvd_one (by delta coprime at H2; rw \u2190 H2; exact gcd_dvd_gcd_of_dvd_left _ H1)\n\ntheorem coprime.coprime_dvd_right {m k n : \u2115} (H1 : n \u2223 m) (H2 : coprime k m) : coprime k n :=\n(H2.symm.coprime_dvd_left H1).symm\n\ntheorem coprime.coprime_mul_left {k m n : \u2115} (H : coprime (k * m) n) : coprime m n :=\nH.coprime_dvd_left (dvd_mul_left _ _)\n\ntheorem coprime.coprime_mul_right {k m n : \u2115} (H : coprime (m * k) n) : coprime m n :=\nH.coprime_dvd_left (dvd_mul_right _ _)\n\ntheorem coprime.coprime_mul_left_right {k m n : \u2115} (H : coprime m (k * n)) : coprime m n :=\nH.coprime_dvd_right (dvd_mul_left _ _)\n\ntheorem coprime.coprime_mul_right_right {k m n : \u2115} (H : coprime m (n * k)) : coprime m n :=\nH.coprime_dvd_right (dvd_mul_right _ _)\n\ntheorem coprime.coprime_div_left {m n a : \u2115} (cmn : coprime m n) (dvd : a \u2223 m) :\n  coprime (m / a) n :=\nbegin\n  by_cases a_split : (a = 0),\n  { subst a_split,\n    rw zero_dvd_iff at dvd,\n    simpa [dvd] using cmn, },\n  { rcases dvd with \u27e8k, rfl\u27e9,\n    rw nat.mul_div_cancel_left _ (nat.pos_of_ne_zero a_split),\n    exact coprime.coprime_mul_left cmn, },\nend\n\ntheorem coprime.coprime_div_right {m n a : \u2115} (cmn : coprime m n) (dvd : a \u2223 n) :\n  coprime m (n / a) :=\n(coprime.coprime_div_left cmn.symm dvd).symm\n\nlemma coprime_mul_iff_left {k m n : \u2115} : coprime (m * n) k \u2194 coprime m k \u2227 coprime n k :=\n\u27e8\u03bb h, \u27e8coprime.coprime_mul_right h, coprime.coprime_mul_left h\u27e9,\n  \u03bb \u27e8h, _\u27e9, by rwa [coprime_iff_gcd_eq_one, coprime.gcd_mul_left_cancel n h]\u27e9\n\nlemma coprime_mul_iff_right {k m n : \u2115} : coprime k (m * n) \u2194 coprime k m \u2227 coprime k n :=\nby simpa only [coprime_comm] using coprime_mul_iff_left\n\nlemma coprime.gcd_left (k : \u2115) {m n : \u2115} (hmn : coprime m n) : coprime (gcd k m) n :=\nhmn.coprime_dvd_left $ gcd_dvd_right k m\n\nlemma coprime.gcd_right (k : \u2115) {m n : \u2115} (hmn : coprime m n) : coprime m (gcd k n) :=\nhmn.coprime_dvd_right $ gcd_dvd_right k n\n\nlemma coprime.gcd_both (k l : \u2115) {m n : \u2115} (hmn : coprime m n) : coprime (gcd k m) (gcd l n) :=\n(hmn.gcd_left k).gcd_right l\n\nlemma coprime.mul_dvd_of_dvd_of_dvd {a n m : \u2115} (hmn : coprime m n)\n  (hm : m \u2223 a) (hn : n \u2223 a) : m * n \u2223 a :=\nlet \u27e8k, hk\u27e9 := hm in hk.symm \u25b8 mul_dvd_mul_left _ (hmn.symm.dvd_of_dvd_mul_left (hk \u25b8 hn))\n\ntheorem coprime_one_left : \u2200 n, coprime 1 n := gcd_one_left\n\ntheorem coprime_one_right : \u2200 n, coprime n 1 := gcd_one_right\n\ntheorem coprime.pow_left {m k : \u2115} (n : \u2115) (H1 : coprime m k) : coprime (m ^ n) k :=\nnat.rec_on n (coprime_one_left _) (\u03bbn IH, H1.mul IH)\n\ntheorem coprime.pow_right {m k : \u2115} (n : \u2115) (H1 : coprime k m) : coprime k (m ^ n) :=\n(H1.symm.pow_left n).symm\n\ntheorem coprime.pow {k l : \u2115} (m n : \u2115) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) :=\n(H1.pow_left _).pow_right _\n\n@[simp] lemma coprime_pow_left_iff {n : \u2115} (hn : 0 < n) (a b : \u2115)  :\n  nat.coprime (a ^ n) b \u2194 nat.coprime a b :=\nbegin\n  obtain \u27e8n, rfl\u27e9 := exists_eq_succ_of_ne_zero hn.ne',\n  rw [pow_succ, nat.coprime_mul_iff_left],\n  exact \u27e8and.left, \u03bb hab, \u27e8hab, hab.pow_left _\u27e9\u27e9\nend\n\n@[simp] lemma coprime_pow_right_iff {n : \u2115} (hn : 0 < n) (a b : \u2115)  :\n  nat.coprime a (b ^ n) \u2194 nat.coprime a b :=\nby rw [nat.coprime_comm, coprime_pow_left_iff hn, nat.coprime_comm]\n\ntheorem coprime.eq_one_of_dvd {k m : \u2115} (H : coprime k m) (d : k \u2223 m) : k = 1 :=\nby rw [\u2190 H.gcd_eq_one, gcd_eq_left d]\n\n@[simp] theorem coprime_zero_left (n : \u2115) : coprime 0 n \u2194 n = 1 :=\nby simp [coprime]\n\n@[simp] theorem coprime_zero_right (n : \u2115) : coprime n 0 \u2194 n = 1 :=\nby simp [coprime]\n\ntheorem not_coprime_zero_zero : \u00ac coprime 0 0 := by simp\n\n@[simp] theorem coprime_one_left_iff (n : \u2115) : coprime 1 n \u2194 true :=\nby simp [coprime]\n\n@[simp] theorem coprime_one_right_iff (n : \u2115) : coprime n 1 \u2194 true :=\nby simp [coprime]\n\n@[simp] theorem coprime_self (n : \u2115) : coprime n n \u2194 n = 1 :=\nby simp [coprime]\n\nlemma gcd_mul_of_coprime_of_dvd {a b c : \u2115} (hac : coprime a c) (b_dvd_c : b \u2223 c) :\n  gcd (a * b) c = b :=\nbegin\n  rcases exists_eq_mul_left_of_dvd b_dvd_c with \u27e8d, rfl\u27e9,\n  rw [gcd_mul_right],\n  convert one_mul b,\n  exact coprime.coprime_mul_right_right hac,\nend\n\nlemma coprime.eq_of_mul_eq_zero {m n : \u2115} (h : m.coprime n) (hmn : m * n = 0) :\n  m = 0 \u2227 n = 1 \u2228 m = 1 \u2227 n = 0 :=\n(nat.eq_zero_of_mul_eq_zero hmn).imp\n  (\u03bb hm, \u27e8hm, n.coprime_zero_left.mp $ hm \u25b8 h\u27e9)\n  (\u03bb hn, \u27e8m.coprime_zero_left.mp $ hn \u25b8 h.symm, hn\u27e9)\n\n/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`.\n\nSee `exists_dvd_and_dvd_of_dvd_mul` for the more general but less constructive version for other\n`gcd_monoid`s. -/\ndef prod_dvd_and_dvd_of_dvd_prod {m n k : \u2115} (H : k \u2223 m * n) :\n  { d : {m' // m' \u2223 m} \u00d7 {n' // n' \u2223 n} // k = d.1 * d.2 } :=\nbegin\n  cases h0 : (gcd k m),\n  case nat.zero\n  { obtain rfl : k = 0 := eq_zero_of_gcd_eq_zero_left h0,\n    obtain rfl : m = 0 := eq_zero_of_gcd_eq_zero_right h0,\n    exact \u27e8\u27e8\u27e80, dvd_refl 0\u27e9, \u27e8n, dvd_refl n\u27e9\u27e9, (zero_mul n).symm\u27e9 },\n  case nat.succ : tmp\n  { have hpos : 0 < gcd k m := h0.symm \u25b8 nat.zero_lt_succ _; clear h0 tmp,\n    have hd : gcd k m * (k / gcd k m) = k := (nat.mul_div_cancel' (gcd_dvd_left k m)),\n    refine \u27e8\u27e8\u27e8gcd k m,  gcd_dvd_right k m\u27e9, \u27e8k / gcd k m, _\u27e9\u27e9, hd.symm\u27e9,\n    apply dvd_of_mul_dvd_mul_left hpos,\n    rw [hd, \u2190 gcd_mul_right],\n    exact dvd_gcd (dvd_mul_right _ _) H }\nend\n\nlemma dvd_mul {x m n : \u2115} :\n  x \u2223 (m * n) \u2194 \u2203 y z, y \u2223 m \u2227 z \u2223 n \u2227 y * z = x :=\nbegin\n  split,\n  { intro h,\n    obtain \u27e8\u27e8\u27e8y, hy\u27e9, \u27e8z, hz\u27e9\u27e9, rfl\u27e9 := prod_dvd_and_dvd_of_dvd_prod h,\n    exact \u27e8y, z, hy, hz, rfl\u27e9, },\n  { rintro \u27e8y, z, hy, hz, rfl\u27e9,\n    exact mul_dvd_mul hy hz },\nend\n\ntheorem gcd_mul_dvd_mul_gcd (k m n : \u2115) : gcd k (m * n) \u2223 gcd k m * gcd k n :=\nbegin\n  rcases (prod_dvd_and_dvd_of_dvd_prod $ gcd_dvd_right k (m * n)) with \u27e8\u27e8\u27e8m', hm'\u27e9, \u27e8n', hn'\u27e9\u27e9, h\u27e9,\n  replace h : gcd k (m * n) = m' * n' := h,\n  rw h,\n  have hm'n' : m' * n' \u2223 k := h \u25b8 gcd_dvd_left _ _,\n  apply mul_dvd_mul,\n  { have hm'k : m' \u2223 k := (dvd_mul_right m' n').trans hm'n',\n    exact dvd_gcd hm'k hm' },\n  { have hn'k : n' \u2223 k := (dvd_mul_left n' m').trans hm'n',\n    exact dvd_gcd hn'k hn' }\nend\n\ntheorem coprime.gcd_mul (k : \u2115) {m n : \u2115} (h : coprime m n) : gcd k (m * n) = gcd k m * gcd k n :=\ndvd_antisymm\n  (gcd_mul_dvd_mul_gcd k m n)\n  ((h.gcd_both k k).mul_dvd_of_dvd_of_dvd\n    (gcd_dvd_gcd_mul_right_right _ _ _)\n    (gcd_dvd_gcd_mul_left_right _ _ _))\n\ntheorem pow_dvd_pow_iff {a b n : \u2115} (n0 : 0 < n) : a ^ n \u2223 b ^ n \u2194 a \u2223 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, pow_dvd_pow_of_dvd h _\u27e9,\n  cases nat.eq_zero_or_pos (gcd a b) with g0 g0,\n  { simp [eq_zero_of_gcd_eq_zero_right g0] },\n  rcases exists_coprime' g0 with \u27e8g, a', b', g0', co, rfl, rfl\u27e9,\n  rw [mul_pow, mul_pow] at h,\n  replace h := dvd_of_mul_dvd_mul_right (pow_pos g0' _) h,\n  have := pow_dvd_pow a' n0,\n  rw [pow_one, (co.pow n n).eq_one_of_dvd h] at this,\n  simp [eq_one_of_dvd_one this]\nend\n\nlemma gcd_mul_gcd_of_coprime_of_mul_eq_mul {a b c d : \u2115} (cop : c.coprime d) (h : a * b = c * d) :\n  a.gcd c * b.gcd c = c :=\nbegin\n  apply dvd_antisymm,\n  { apply nat.coprime.dvd_of_dvd_mul_right (nat.coprime.mul (cop.gcd_left _) (cop.gcd_left _)),\n    rw \u2190 h,\n    apply mul_dvd_mul (gcd_dvd _ _).1 (gcd_dvd _ _).1 },\n  { rw [gcd_comm a _, gcd_comm b _],\n    transitivity c.gcd (a * b),\n    rw [h, gcd_mul_right_right d c],\n    apply gcd_mul_dvd_mul_gcd }\nend\n\n/-- If `k:\u2115` divides coprime `a` and `b` then `k = 1` -/\nlemma eq_one_of_dvd_coprimes {a b k : \u2115} (h_ab_coprime : coprime a b)\n  (hka : k \u2223 a) (hkb : k \u2223 b) : k = 1  :=\nbegin\n  rw coprime_iff_gcd_eq_one at h_ab_coprime,\n  have h1 := dvd_gcd hka hkb,\n  rw h_ab_coprime at h1,\n  exact nat.dvd_one.mp h1,\nend\n\nlemma coprime.mul_add_mul_ne_mul {m n a b : \u2115} (cop : coprime m n) (ha : a \u2260 0) (hb : b \u2260 0) :\n  a * m + b * n \u2260 m * n :=\nbegin\n  intro h,\n  obtain \u27e8x, rfl\u27e9 : n \u2223 a := cop.symm.dvd_of_dvd_mul_right\n    ((nat.dvd_add_iff_left (dvd_mul_left n b)).mpr ((congr_arg _ h).mpr (dvd_mul_left n m))),\n  obtain \u27e8y, rfl\u27e9 : m \u2223 b := cop.dvd_of_dvd_mul_right\n    ((nat.dvd_add_iff_right (dvd_mul_left m (n*x))).mpr ((congr_arg _ h).mpr (dvd_mul_right m n))),\n  rw [mul_comm, mul_ne_zero_iff, \u2190one_le_iff_ne_zero] at ha hb,\n  refine mul_ne_zero hb.2 ha.2 (eq_zero_of_mul_eq_self_left (ne_of_gt (add_le_add ha.1 hb.1)) _),\n  rw [\u2190 mul_assoc, \u2190 h, add_mul, add_mul, mul_comm _ n, \u2190mul_assoc, mul_comm y]\nend\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/gcd/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7220800869066984}}
{"text": "/-\nCopyright (c) 2021 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta, Alena Gusakov, Ya\u00ebl Dillies\n-/\nimport data.finset.lattice\n\n/-!\n# Shadows\n\nThis file defines shadows of a set family. The shadow of a set family is the set family of sets we\nget by removing any element from any set of the original family. If one pictures `finset \u03b1` as a big\nhypercube (each dimension being membership of a given element), then taking the shadow corresponds\nto projecting each finset down once in all available directions.\n\n## Main definitions\n\nThe `shadow` of a set family is everything we can get by removing an element from each set.\n\n## Notation\n\n`\u2202 \ud835\udc9c` is notation for `shadow \ud835\udc9c`. It is situated in locale `finset_family`.\n\nWe also maintain the convention that `a, b : \u03b1` are elements of the ground type, `s, t : finset \u03b1`\nare finsets, and `\ud835\udc9c, \u212c : finset (finset \u03b1)` are finset families.\n\n## References\n\n* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf\n* http://discretemath.imp.fu-berlin.de/DMII-2015-16/kruskal.pdf\n\n## Tags\n\nshadow, set family\n-/\n\nopen finset nat\n\nvariables {\u03b1 : Type*}\n\nnamespace finset\nvariables [decidable_eq \u03b1] {\ud835\udc9c : finset (finset \u03b1)} {s t : finset \u03b1} {a : \u03b1} {k : \u2115}\n\n/-- The shadow of a set family `\ud835\udc9c` is all sets we can get by removing one element from any set in\n`\ud835\udc9c`, and the (`k` times) iterated shadow (`shadow^[k]`) is all sets we can get by removing `k`\nelements from any set in `\ud835\udc9c`. -/\ndef shadow (\ud835\udc9c : finset (finset \u03b1)) : finset (finset \u03b1) := \ud835\udc9c.sup (\u03bb s, s.image (erase s))\n\nlocalized \"notation `\u2202 `:90 := finset.shadow\" in finset_family\n\n/-- The shadow of the empty set is empty. -/\n@[simp] lemma shadow_empty : \u2202 (\u2205 : finset (finset \u03b1)) = \u2205 := rfl\n\n/-- The shadow is monotone. -/\n@[mono] lemma shadow_monotone : monotone (shadow : finset (finset \u03b1) \u2192 finset (finset \u03b1)) :=\n\u03bb \ud835\udc9c \u212c, sup_mono\n\n/-- `s` is in the shadow of `\ud835\udc9c` iff there is an `t \u2208 \ud835\udc9c` from which we can remove one element to\nget `s`. -/\nlemma mem_shadow_iff : s \u2208 \u2202 \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, \u2203 a \u2208 t, erase t a = s :=\nby simp only [shadow, mem_sup, mem_image]\n\nlemma erase_mem_shadow (hs : s \u2208 \ud835\udc9c) (ha : a \u2208 s) : erase s a \u2208 \u2202 \ud835\udc9c :=\nmem_shadow_iff.2 \u27e8s, hs, a, ha, rfl\u27e9\n\n/-- `t` is in the shadow of `\ud835\udc9c` iff we can add an element to it so that the resulting finset is in\n`\ud835\udc9c`. -/\nlemma mem_shadow_iff_insert_mem : s \u2208 \u2202 \ud835\udc9c \u2194 \u2203 a \u2209 s, insert a s \u2208 \ud835\udc9c :=\nbegin\n  refine mem_shadow_iff.trans \u27e8_, _\u27e9,\n  { rintro \u27e8s, hs, a, ha, rfl\u27e9,\n    refine \u27e8a, not_mem_erase a s, _\u27e9,\n    rwa insert_erase ha },\n  { rintro \u27e8a, ha, hs\u27e9,\n    exact \u27e8insert a s, hs, a, mem_insert_self _ _, erase_insert ha\u27e9 }\nend\n\n/-- `s \u2208 \u2202 \ud835\udc9c` iff `s` is exactly one element less than something from `\ud835\udc9c` -/\nlemma mem_shadow_iff_exists_mem_card_add_one :\n  s \u2208 \u2202 \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, s \u2286 t \u2227 t.card = s.card + 1 :=\nbegin\n  refine mem_shadow_iff_insert_mem.trans \u27e8_, _\u27e9,\n  { rintro \u27e8a, ha, hs\u27e9,\n    exact \u27e8insert a s, hs, subset_insert _ _, card_insert_of_not_mem ha\u27e9 },\n  { rintro \u27e8t, ht, hst, h\u27e9,\n    obtain \u27e8a, ha\u27e9 : \u2203 a, t \\ s = {a} :=\n      card_eq_one.1 (by rw [card_sdiff hst, h, add_tsub_cancel_left]),\n    exact \u27e8a, \u03bb hat,\n      not_mem_sdiff_of_mem_right hat ((ha.ge : _ \u2286 _) $ mem_singleton_self a),\n      by rwa [insert_eq a s, \u2190ha, sdiff_union_of_subset hst]\u27e9 }\nend\n\n/-- Being in the shadow of `\ud835\udc9c` means we have a superset in `\ud835\udc9c`. -/\nlemma exists_subset_of_mem_shadow (hs : s \u2208 \u2202 \ud835\udc9c) : \u2203 t \u2208 \ud835\udc9c, s \u2286 t :=\nlet \u27e8t, ht, hst\u27e9 := mem_shadow_iff_exists_mem_card_add_one.1 hs in \u27e8t, ht, hst.1\u27e9\n\n/-- `t \u2208 \u2202^k \ud835\udc9c` iff `t` is exactly `k` elements less than something in `\ud835\udc9c`. -/\nlemma mem_shadow_iff_exists_mem_card_add :\n  s \u2208 (\u2202^[k]) \ud835\udc9c \u2194 \u2203 t \u2208 \ud835\udc9c, s \u2286 t \u2227 t.card = s.card + k :=\nbegin\n  induction k with k ih generalizing \ud835\udc9c s,\n  { refine \u27e8\u03bb hs, \u27e8s, hs, subset.refl _, rfl\u27e9, _\u27e9,\n    rintro \u27e8t, ht, hst, hcard\u27e9,\n    rwa eq_of_subset_of_card_le hst hcard.le },\n  simp only [exists_prop, function.comp_app, function.iterate_succ],\n  refine ih.trans _,\n  clear ih,\n  split,\n  { rintro \u27e8t, ht, hst, hcardst\u27e9,\n    obtain \u27e8u, hu, htu, hcardtu\u27e9 := mem_shadow_iff_exists_mem_card_add_one.1 ht,\n    refine \u27e8u, hu, hst.trans htu, _\u27e9,\n    rw [hcardtu, hcardst],\n    refl },\n  { rintro \u27e8t, ht, hst, hcard\u27e9,\n    obtain \u27e8u, hsu, hut, hu\u27e9 := finset.exists_intermediate_set k\n      (by { rw [add_comm, hcard], exact le_succ _ }) hst,\n    rw add_comm at hu,\n    refine \u27e8u, mem_shadow_iff_exists_mem_card_add_one.2 \u27e8t, ht, hut, _\u27e9, hsu, hu\u27e9,\n    rw [hcard, hu],\n    refl }\nend\n\nend finset\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/combinatorics/set_family/shadow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.722053036359684}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Ya\u00ebl Dillies\n-/\nimport order.complete_lattice\nimport order.directed\n\n/-!\n# Frames, completely distributive lattices and Boolean algebras\n\nIn this file we define and provide API for frames, completely distributive lattices and completely\ndistributive Boolean algebras.\n\n## Typeclasses\n\n* `order.frame`: Frame: A complete lattice whose `\u2293` distributes over `\u2a06`.\n* `order.coframe`: Coframe: A complete lattice whose `\u2294` distributes over `\u2a05`.\n* `complete_distrib_lattice`: Completely distributive lattices: A complete lattice whose `\u2293` and `\u2294`\n  distribute over `\u2a06` and `\u2a05` respectively.\n* `complete_boolean_algebra`: Completely distributive Boolean algebra: A Boolean algebra whose `\u2293`\n  and `\u2294` distribute over `\u2a06` and `\u2a05` respectively.\n\nA set of opens gives rise to a topological space precisely if it forms a frame. Such a frame is also\ncompletely distributive, but not all frames are. `filter` is a coframe but not a completely\ndistributive lattice.\n\n## TODO\n\nAdd instances for `prod`\n\n## References\n\n* [Wikipedia, *Complete Heyting algebra*](https://en.wikipedia.org/wiki/Complete_Heyting_algebra)\n* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]\n-/\n\nset_option old_structure_cmd true\n\nopen function set\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b9 : Sort w} {\u03ba : \u03b9 \u2192 Sort*}\n\n/-- A frame, aka complete Heyting algebra, is a complete lattice whose `\u2293` distributes over `\u2a06`. -/\nclass order.frame (\u03b1 : Type*) extends complete_lattice \u03b1 :=\n(inf_Sup_le_supr_inf (a : \u03b1) (s : set \u03b1) : a \u2293 Sup s \u2264 \u2a06 b \u2208 s, a \u2293 b)\n\n/-- A coframe, aka complete Brouwer algebra or complete co-Heyting algebra, is a complete lattice\nwhose `\u2294` distributes over `\u2a05`. -/\nclass order.coframe (\u03b1 : Type*) extends complete_lattice \u03b1 :=\n(infi_sup_le_sup_Inf (a : \u03b1) (s : set \u03b1) : (\u2a05 b \u2208 s, a \u2294 b) \u2264 a \u2294 Inf s)\n\nopen order\n\n/-- A completely distributive lattice is a complete lattice whose `\u2294` and `\u2293` respectively\ndistribute over `\u2a05` and `\u2a06`. -/\nclass complete_distrib_lattice (\u03b1 : Type*) extends frame \u03b1 :=\n(infi_sup_le_sup_Inf : \u2200 a s, (\u2a05 b \u2208 s, a \u2294 b) \u2264 a \u2294 Inf s)\n\n@[priority 100] -- See note [lower instance priority]\ninstance complete_distrib_lattice.to_coframe [complete_distrib_lattice \u03b1] : coframe \u03b1 :=\n{ .. \u2039complete_distrib_lattice \u03b1\u203a }\n\nsection frame\nvariables [frame \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\ninstance order_dual.coframe : coframe \u03b1\u1d52\u1d48 :=\n{ infi_sup_le_sup_Inf := frame.inf_Sup_le_supr_inf, ..order_dual.complete_lattice \u03b1 }\n\nlemma inf_Sup_eq : a \u2293 Sup s = \u2a06 b \u2208 s, a \u2293 b :=\n(frame.inf_Sup_le_supr_inf _ _).antisymm supr_inf_le_inf_Sup\n\nlemma Sup_inf_eq : Sup s \u2293 b = \u2a06 a \u2208 s, a \u2293 b :=\nby simpa only [inf_comm] using @inf_Sup_eq \u03b1 _ s b\n\nlemma supr_inf_eq (f : \u03b9 \u2192 \u03b1) (a : \u03b1) : (\u2a06 i, f i) \u2293 a = \u2a06 i, f i \u2293 a :=\nby rw [supr, Sup_inf_eq, supr_range]\n\nlemma inf_supr_eq (a : \u03b1) (f : \u03b9 \u2192 \u03b1) : a \u2293 (\u2a06 i, f i) = \u2a06 i, a \u2293 f i :=\nby simpa only [inf_comm] using supr_inf_eq f a\n\nlemma bsupr_inf_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : (\u2a06 i j, f i j) \u2293 a = \u2a06 i j, f i j \u2293 a :=\nby simp only [supr_inf_eq]\n\nlemma inf_bsupr_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : a \u2293 (\u2a06 i j, f i j) = \u2a06 i j, a \u2293 f i j :=\nby simp only [inf_supr_eq]\n\nlemma supr_inf_supr {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} :\n  (\u2a06 i, f i) \u2293 (\u2a06 j, g j) = \u2a06 i : \u03b9 \u00d7 \u03b9', f i.1 \u2293 g i.2 :=\nby simp only [inf_supr_eq, supr_inf_eq, supr_prod]\n\nlemma bsupr_inf_bsupr {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} {s : set \u03b9} {t : set \u03b9'} :\n  (\u2a06 i \u2208 s, f i) \u2293 (\u2a06 j \u2208 t, g j) = \u2a06 p \u2208 s \u00d7\u02e2 t, f (p : \u03b9 \u00d7 \u03b9').1 \u2293 g p.2 :=\nbegin\n  simp only [supr_subtype', supr_inf_supr],\n  exact (equiv.surjective _).supr_congr (equiv.set.prod s t).symm (\u03bb x, rfl)\nend\n\nlemma Sup_inf_Sup : Sup s \u2293 Sup t = \u2a06 p \u2208 s \u00d7\u02e2 t, (p : \u03b1 \u00d7 \u03b1).1 \u2293 p.2 :=\nby simp only [Sup_eq_supr, bsupr_inf_bsupr]\n\nlemma supr_disjoint_iff {f : \u03b9 \u2192 \u03b1} : disjoint (\u2a06 i, f i) a \u2194 \u2200 i, disjoint (f i) a :=\nby simp only [disjoint_iff, supr_inf_eq, supr_eq_bot]\n\nlemma disjoint_supr_iff {f : \u03b9 \u2192 \u03b1} : disjoint a (\u2a06 i, f i) \u2194 \u2200 i, disjoint a (f i) :=\nby simpa only [disjoint.comm] using supr_disjoint_iff\n\nlemma Sup_disjoint_iff {s : set \u03b1} : disjoint (Sup s) a \u2194 \u2200 b \u2208 s, disjoint b a :=\nby simp only [disjoint_iff, Sup_inf_eq, supr_eq_bot]\n\nlemma disjoint_Sup_iff {s : set \u03b1} : disjoint a (Sup s) \u2194 \u2200 b \u2208 s, disjoint a b :=\nby simpa only [disjoint.comm] using Sup_disjoint_iff\n\nlemma supr_inf_of_monotone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (\u2264)] {f g : \u03b9 \u2192 \u03b1}\n  (hf : monotone f) (hg : monotone g) :\n  (\u2a06 i, f i \u2293 g i) = (\u2a06 i, f i) \u2293 (\u2a06 i, g i) :=\nbegin\n  refine (le_supr_inf_supr f g).antisymm _,\n  rw [supr_inf_supr],\n  refine supr_mono' (\u03bb i, _),\n  rcases directed_of (\u2264) i.1 i.2 with \u27e8j, h\u2081, h\u2082\u27e9,\n  exact \u27e8j, inf_le_inf (hf h\u2081) (hg h\u2082)\u27e9\nend\n\nlemma supr_inf_of_antitone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (swap (\u2264))] {f g : \u03b9 \u2192 \u03b1}\n  (hf : antitone f) (hg : antitone g) :\n  (\u2a06 i, f i \u2293 g i) = (\u2a06 i, f i) \u2293 (\u2a06 i, g i) :=\n@supr_inf_of_monotone \u03b1 _ \u03b9\u1d52\u1d48 _ _ f g hf.dual_left hg.dual_left\n\ninstance pi.frame {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*} [\u03a0 i, frame (\u03c0 i)] : frame (\u03a0 i, \u03c0 i) :=\n{ inf_Sup_le_supr_inf := \u03bb a s i,\n    by simp only [complete_lattice.Sup, Sup_apply, supr_apply, pi.inf_apply, inf_supr_eq,\n      \u2190 supr_subtype''],\n  ..pi.complete_lattice }\n\nend frame\n\nsection coframe\nvariables [coframe \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\ninstance order_dual.frame : frame \u03b1\u1d52\u1d48 :=\n{ inf_Sup_le_supr_inf := coframe.infi_sup_le_sup_Inf, ..order_dual.complete_lattice \u03b1 }\n\nlemma sup_Inf_eq : a \u2294 Inf s = \u2a05 b \u2208 s, a \u2294 b := @inf_Sup_eq \u03b1\u1d52\u1d48 _ _ _\nlemma Inf_sup_eq : Inf s \u2294 b = \u2a05 a \u2208 s, a \u2294 b := @Sup_inf_eq \u03b1\u1d52\u1d48 _ _ _\n\nlemma infi_sup_eq (f : \u03b9 \u2192 \u03b1) (a : \u03b1) : (\u2a05 i, f i) \u2294 a = \u2a05 i, f i \u2294 a := @supr_inf_eq \u03b1\u1d52\u1d48 _ _ _ _\nlemma sup_infi_eq (a : \u03b1) (f : \u03b9 \u2192 \u03b1) : a \u2294 (\u2a05 i, f i) = \u2a05 i, a \u2294 f i := @inf_supr_eq \u03b1\u1d52\u1d48 _ _ _ _\n\nlemma binfi_sup_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : (\u2a05 i j, f i j) \u2294 a = \u2a05 i j, f i j \u2294 a :=\n@bsupr_inf_eq \u03b1\u1d52\u1d48 _ _ _ _ _\n\nlemma sup_binfi_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : a \u2294 (\u2a05 i j, f i j) = \u2a05 i j, a \u2294 f i j :=\n@inf_bsupr_eq \u03b1\u1d52\u1d48 _ _ _ _ _\n\nlemma infi_sup_infi {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} :\n  (\u2a05 i, f i) \u2294 (\u2a05 i, g i) = \u2a05 i : \u03b9 \u00d7 \u03b9', f i.1 \u2294 g i.2 :=\n@supr_inf_supr \u03b1\u1d52\u1d48 _ _ _ _ _\n\nlemma binfi_sup_binfi {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} {s : set \u03b9} {t : set \u03b9'} :\n  (\u2a05 i \u2208 s, f i) \u2294 (\u2a05 j \u2208 t, g j) = \u2a05 p \u2208 s \u00d7\u02e2 t, f (p : \u03b9 \u00d7 \u03b9').1 \u2294 g p.2 :=\n@bsupr_inf_bsupr \u03b1\u1d52\u1d48 _ _ _ _ _ _ _\n\ntheorem Inf_sup_Inf : Inf s \u2294 Inf t = (\u2a05 p \u2208 s \u00d7\u02e2 t, (p : \u03b1 \u00d7 \u03b1).1 \u2294 p.2) :=\n@Sup_inf_Sup \u03b1\u1d52\u1d48 _ _ _\n\nlemma infi_sup_of_monotone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (swap (\u2264))] {f g : \u03b9 \u2192 \u03b1}\n  (hf : monotone f) (hg : monotone g) :\n  (\u2a05 i, f i \u2294 g i) = (\u2a05 i, f i) \u2294 (\u2a05 i, g i) :=\nsupr_inf_of_antitone hf.dual_right hg.dual_right\n\nlemma infi_sup_of_antitone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (\u2264)] {f g : \u03b9 \u2192 \u03b1}\n  (hf : antitone f) (hg : antitone g) :\n  (\u2a05 i, f i \u2294 g i) = (\u2a05 i, f i) \u2294 (\u2a05 i, g i) :=\nsupr_inf_of_monotone hf.dual_right hg.dual_right\n\ninstance pi.coframe {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*} [\u03a0 i, coframe (\u03c0 i)] : coframe (\u03a0 i, \u03c0 i) :=\n{ Inf := Inf,\n  infi_sup_le_sup_Inf := \u03bb a s i,\n    by simp only [\u2190sup_infi_eq, Inf_apply, \u2190infi_subtype'', infi_apply, pi.sup_apply],\n  ..pi.complete_lattice }\n\nend coframe\n\nsection complete_distrib_lattice\nvariables [complete_distrib_lattice \u03b1] {a b : \u03b1} {s t : set \u03b1}\n\ninstance : complete_distrib_lattice \u03b1\u1d52\u1d48 := { ..order_dual.frame, ..order_dual.coframe }\n\ninstance pi.complete_distrib_lattice {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*}\n  [\u03a0 i, complete_distrib_lattice (\u03c0 i)] : complete_distrib_lattice (\u03a0 i, \u03c0 i) :=\n{ ..pi.frame, ..pi.coframe }\n\nend complete_distrib_lattice\n\n@[priority 100] -- see Note [lower instance priority]\ninstance complete_distrib_lattice.to_distrib_lattice [d : complete_distrib_lattice \u03b1] :\n  distrib_lattice \u03b1 :=\n{ le_sup_inf := \u03bb x y z, by rw [\u2190 Inf_pair, \u2190 Inf_pair, sup_Inf_eq, \u2190 Inf_image, set.image_pair],\n  ..d }\n\n/-- A complete Boolean algebra is a completely distributive Boolean algebra. -/\nclass complete_boolean_algebra \u03b1 extends boolean_algebra \u03b1, complete_distrib_lattice \u03b1\n\ninstance pi.complete_boolean_algebra {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*}\n  [\u2200 i, complete_boolean_algebra (\u03c0 i)] : complete_boolean_algebra (\u03a0 i, \u03c0 i) :=\n{ .. pi.boolean_algebra, .. pi.complete_distrib_lattice }\n\ninstance Prop.complete_boolean_algebra : complete_boolean_algebra Prop :=\n{ infi_sup_le_sup_Inf := \u03bb p s, iff.mp $\n    by simp only [forall_or_distrib_left, complete_lattice.Inf, infi_Prop_eq, sup_Prop_eq],\n  inf_Sup_le_supr_inf := \u03bb p s, iff.mp $\n    by simp only [complete_lattice.Sup, exists_and_distrib_left, inf_Prop_eq, supr_Prop_eq],\n  .. Prop.boolean_algebra, .. Prop.complete_lattice }\n\nsection complete_boolean_algebra\nvariables [complete_boolean_algebra \u03b1] {a b : \u03b1} {s : set \u03b1} {f : \u03b9 \u2192 \u03b1}\n\ntheorem compl_infi : (infi f)\u1d9c = (\u2a06 i, (f i)\u1d9c) :=\nle_antisymm\n  (compl_le_of_compl_le $ le_infi $ \u03bb i, compl_le_of_compl_le $ le_supr (compl \u2218 f) i)\n  (supr_le $ \u03bb i, compl_le_compl $ infi_le _ _)\n\ntheorem compl_supr : (supr f)\u1d9c = (\u2a05 i, (f i)\u1d9c) :=\ncompl_injective (by simp [compl_infi])\n\nlemma compl_Inf : (Inf s)\u1d9c = (\u2a06 i \u2208 s, i\u1d9c) := by simp only [Inf_eq_infi, compl_infi]\nlemma compl_Sup : (Sup s)\u1d9c = (\u2a05 i \u2208 s, i\u1d9c) := by simp only [Sup_eq_supr, compl_supr]\nlemma compl_Inf' : (Inf s)\u1d9c = Sup (compl '' s) := compl_Inf.trans Sup_image.symm\nlemma compl_Sup' : (Sup s)\u1d9c = Inf (compl '' s) := compl_Sup.trans Inf_image.symm\n\nend complete_boolean_algebra\n\nsection lift\n\n/-- Pullback an `order.frame` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.frame [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1] [has_Inf \u03b1] [has_top \u03b1]\n  [has_bot \u03b1] [frame \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5) :\n  frame \u03b1 :=\n{ inf_Sup_le_supr_inf := \u03bb a s, begin\n    change f (a \u2293 Sup s) \u2264 f _,\n    rw [\u2190Sup_image, map_inf, map_Sup s, inf_bsupr_eq],\n    simp_rw \u2190map_inf,\n    exact ((map_Sup _).trans supr_image).ge,\n  end,\n  ..hf.complete_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot }\n\n/-- Pullback an `order.coframe` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.coframe [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1] [has_Inf \u03b1] [has_top \u03b1]\n  [has_bot \u03b1] [coframe \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5) :\n  coframe \u03b1 :=\n{ infi_sup_le_sup_Inf := \u03bb a s, begin\n    change f _ \u2264 f (a \u2294 Inf s),\n    rw [\u2190Inf_image, map_sup, map_Inf s, sup_binfi_eq],\n    simp_rw \u2190map_sup,\n    exact ((map_Inf _).trans infi_image).le,\n  end,\n  ..hf.complete_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot }\n\n/-- Pullback a `complete_distrib_lattice` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.complete_distrib_lattice [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1]\n  [has_Inf \u03b1] [has_top \u03b1] [has_bot \u03b1] [complete_distrib_lattice \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : function.injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5) :\n  complete_distrib_lattice \u03b1 :=\n{ ..hf.frame f map_sup map_inf map_Sup map_Inf map_top map_bot,\n  ..hf.coframe f map_sup map_inf map_Sup map_Inf map_top map_bot }\n\n/-- Pullback a `complete_boolean_algebra` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.complete_boolean_algebra [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1]\n  [has_Inf \u03b1] [has_top \u03b1] [has_bot \u03b1] [has_compl \u03b1] [has_sdiff \u03b1] [complete_boolean_algebra \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : function.injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5)\n  (map_compl : \u2200 a, f a\u1d9c = (f a)\u1d9c) (map_sdiff : \u2200 a b, f (a \\ b) = f a \\ f b) :\n  complete_boolean_algebra \u03b1 :=\n{ ..hf.complete_distrib_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot,\n  ..hf.boolean_algebra f map_sup map_inf map_top map_bot map_compl map_sdiff }\n\nend lift\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/complete_boolean_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7220489600801728}}
{"text": "/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad\n\nGeneral properties of binary operations.\n-/\nopen eq.ops function\n\nnamespace binary\n  section\n    variable {A : Type}\n    variables (op\u2081 : A \u2192 A \u2192 A) (inv : A \u2192 A) (one : A)\n\n    local notation a * b := op\u2081 a b\n    local notation a \u207b\u00b9  := inv a\n\n    definition commutative [reducible]       := \u2200a b, a * b = b * a\n    definition associative [reducible]       := \u2200a b c, (a * b) * c = a * (b * c)\n    definition left_identity [reducible]     := \u2200a, one * a = a\n    definition right_identity [reducible]    := \u2200a, a * one = a\n    definition left_inverse [reducible]      := \u2200a, a\u207b\u00b9 * a = one\n    definition right_inverse [reducible]     := \u2200a, a * a\u207b\u00b9 = one\n    definition left_cancelative [reducible]  := \u2200a b c, a * b = a * c \u2192 b = c\n    definition right_cancelative [reducible] := \u2200a b c, a * b = c * b \u2192 a = c\n\n    definition inv_op_cancel_left [reducible] := \u2200a b, a\u207b\u00b9 * (a * b) = b\n    definition op_inv_cancel_left [reducible] := \u2200a b, a * (a\u207b\u00b9 * b) = b\n    definition inv_op_cancel_right [reducible] := \u2200a b, a * b\u207b\u00b9 * b =  a\n    definition op_inv_cancel_right [reducible] := \u2200a b, a * b * b\u207b\u00b9 = a\n\n    variable (op\u2082 : A \u2192 A \u2192 A)\n\n    local notation a + b := op\u2082 a b\n\n    definition left_distributive [reducible] := \u2200a b c, a * (b + c) = a * b + a * c\n    definition right_distributive [reducible] := \u2200a b c, (a + b) * c = a * c + b * c\n\n    definition right_commutative [reducible] {B : Type} (f : B \u2192 A \u2192 B) := \u2200 b a\u2081 a\u2082, f (f b a\u2081) a\u2082 = f (f b a\u2082) a\u2081\n    definition left_commutative [reducible] {B : Type}  (f : A \u2192 B \u2192 B) := \u2200 a\u2081 a\u2082 b, f a\u2081 (f a\u2082 b) = f a\u2082 (f a\u2081 b)\n  end\n\n  section\n    variable {A : Type}\n    variable {f : A \u2192 A \u2192 A}\n    variable H_comm : commutative f\n    variable H_assoc : associative f\n    local infixl `*` := f\n    theorem left_comm : left_commutative f :=\n    take a b c, calc\n      a*(b*c) = (a*b)*c  : H_assoc\n        ...   = (b*a)*c  : H_comm\n        ...   = b*(a*c)  : H_assoc\n\n    theorem right_comm : right_commutative f :=\n    take a b c, calc\n      (a*b)*c = a*(b*c) : H_assoc\n        ...   = a*(c*b) : H_comm\n        ...   = (a*c)*b : H_assoc\n\n    theorem comm4 (a b c d : A) : a*b*(c*d) = a*c*(b*d) :=\n    calc\n      a*b*(c*d) = a*b*c*d   : H_assoc\n        ...     = a*c*b*d   : right_comm H_comm H_assoc\n        ...     = a*c*(b*d) : H_assoc\n  end\n\n  section\n    variable {A : Type}\n    variable {f : A \u2192 A \u2192 A}\n    variable H_assoc : associative f\n    local infixl `*` := f\n    theorem assoc4helper (a b c d) : (a*b)*(c*d) = a*((b*c)*d) :=\n    calc\n      (a*b)*(c*d) = a*(b*(c*d)) : H_assoc\n              ... = a*((b*c)*d) : H_assoc\n  end\n\n  definition right_commutative_comp_right [reducible]\n    {A B : Type} (f : A \u2192 A \u2192 A) (g : B \u2192 A) (rcomm : right_commutative f) : right_commutative (comp_right f g) :=\n  \u03bb a b\u2081 b\u2082, !rcomm\n\n  definition left_commutative_compose_left [reducible]\n    {A B : Type} (f : A \u2192 A \u2192 A) (g : B \u2192 A) (lcomm : left_commutative f) : left_commutative (comp_left f g) :=\n  \u03bb a b\u2081 b\u2082, !lcomm\nend binary\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/algebra/binary.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7220489581301625}}
{"text": "import data.vector data.nat.basic data.pnat.prime data.list.of_fn\n\ndef blocks {n:\u2115}(b k:\u2115) (x : vector (fin b) n): \u2115 :=\n  fintype.card {y : vector (fin b) k // \n  \u2203 i : fin n,  y.1 = ((x.1++x.1).drop i).take k}\n\ndef complexity_function {n:\u2115}(b:\u2115) (x : vector (fin b) n)\n--: vector \u2115 x.length.succ\n: list \u2115\n:= list.of_fn (\u03bb k:fin n.succ, blocks b k x)\n\n#eval complexity_function 2 \u27e8[0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0],rfl\u27e9\n\n#eval complexity_function 2 \u27e8[0,1,1,0,1,0,0,1],rfl\u27e9\n\nexample : complexity_function 2 \u27e8[0,1,1,0,1,0,0,1],rfl\u27e9 = [1, 2, 4, 6, 8, 8, 8, 8, 8] :=\ndec_trivial\n\n-- example : complexity_function 2 \u27e8[0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0],rfl\u27e9\n-- = [1, 2, 4, 6, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]\n-- := dec_trivial\n\ntheorem fintype_card_fin {n:\u2115} : fintype.card (fin n) = n:=  finset.card_fin n\n\ntheorem card_vector_fin (b n:\u2115) : fintype.card (vector (fin b) n) = b ^ n :=\n            calc _ = fintype.card (fin b) ^ n: card_vector n\n               ... = b                    ^ n: by rw fintype_card_fin\n\ntheorem bound {n:\u2115}(b:\u2115) (x : vector (fin b.succ) n):\n\u2200 k:fin n, blocks b.succ k.1 x \u2264 b.succ ^ k.1 :=\n\u03bb k, calc _ \u2264 fintype.card (vector (fin b.succ) k.1): fintype.card_le_of_injective (\u03bb y: {y : vector (fin b.succ) k.1 //  \u2203 i : fin n,  y.1 = ((x.1++x.1).drop i).take k.1},\ny.1) (\u03bb u v huv, subtype.eq huv)\n        ... = fintype.card (fin b.succ) ^ k.1     : card_vector k.1\n        ... = b.succ                    ^ k.1     : by rw fintype_card_fin\n", "meta": {"author": "bjoernkjoshanssen", "repo": "diophantine-lemma", "sha": "50bd6972254f156d40fe2a4ad9e7bc4df9cbc8e0", "save_path": "github-repos/lean/bjoernkjoshanssen-diophantine-lemma", "path": "github-repos/lean/bjoernkjoshanssen-diophantine-lemma/diophantine-lemma-50bd6972254f156d40fe2a4ad9e7bc4df9cbc8e0/complexity-function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7220489581301623}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.filter.extr\nimport Mathlib.topology.continuous_on\nimport Mathlib.PostPort\n\nuniverses u v w x \n\nnamespace Mathlib\n\n/-!\n# Local extrema of functions on topological spaces\n\n## Main definitions\n\nThis file defines special versions of `is_*_filter f a l`, `*=min/max/extr`,\nfrom `order/filter/extr` for two kinds of filters: `nhds_within` and `nhds`.\nThese versions are called `is_local_*_on` and `is_local_*`, respectively.\n\n## Main statements\n\nMany lemmas in this file restate those from `order/filter/extr`, and you can find\na detailed documentation there. These convenience lemmas are provided only to make the dot notation\nreturn propositions of expected types, not just `is_*_filter`.\n\nHere is the list of statements specific to these two types of filters:\n\n* `is_local_*.on`, `is_local_*_on.on_subset`: restrict to a subset;\n* `is_local_*_on.inter` : intersect the set with another one;\n* `is_*_on.localize` : a global extremum is a local extremum too.\n* `is_[local_]*_on.is_local_*` : if we have `is_local_*_on f s a` and `s \u2208 \ud835\udcdd a`,\n  then we have `is_local_* f a`.\n\n-/\n\n/-- `is_local_min_on f s a` means that `f a \u2264 f x` for all `x \u2208 s` in some neighborhood of `a`. -/\ndef is_local_min_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2)\n    (s : set \u03b1) (a : \u03b1) :=\n  is_min_filter f (nhds_within a s) a\n\n/-- `is_local_max_on f s a` means that `f x \u2264 f a` for all `x \u2208 s` in some neighborhood of `a`. -/\ndef is_local_max_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2)\n    (s : set \u03b1) (a : \u03b1) :=\n  is_max_filter f (nhds_within a s) a\n\n/-- `is_local_extr_on f s a` means `is_local_min_on f s a \u2228 is_local_max_on f s a`. -/\ndef is_local_extr_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2)\n    (s : set \u03b1) (a : \u03b1) :=\n  is_extr_filter f (nhds_within a s) a\n\n/-- `is_local_min f a` means that `f a \u2264 f x` for all `x` in some neighborhood of `a`. -/\ndef is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :=\n  is_min_filter f (nhds a) a\n\n/-- `is_local_max f a` means that `f x \u2264 f a` for all `x \u2208 s` in some neighborhood of `a`. -/\ndef is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :=\n  is_max_filter f (nhds a) a\n\n/-- `is_local_extr_on f s a` means `is_local_min_on f s a \u2228 is_local_max_on f s a`. -/\ndef is_local_extr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] (f : \u03b1 \u2192 \u03b2)\n    (a : \u03b1) :=\n  is_extr_filter f (nhds a) a\n\ntheorem is_local_extr_on.elim {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {p : Prop} :\n    is_local_extr_on f s a \u2192 (is_local_min_on f s a \u2192 p) \u2192 (is_local_max_on f s a \u2192 p) \u2192 p :=\n  or.elim\n\ntheorem is_local_extr.elim {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {a : \u03b1} {p : Prop} : is_local_extr f a \u2192 (is_local_min f a \u2192 p) \u2192 (is_local_max f a \u2192 p) \u2192 p :=\n  or.elim\n\n/-! ### Restriction to (sub)sets -/\n\ntheorem is_local_min.on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {a : \u03b1} (h : is_local_min f a) (s : set \u03b1) : is_local_min_on f s a :=\n  is_min_filter.filter_inf h (filter.principal s)\n\ntheorem is_local_max.on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {a : \u03b1} (h : is_local_max f a) (s : set \u03b1) : is_local_max_on f s a :=\n  is_max_filter.filter_inf h (filter.principal s)\n\ntheorem is_local_extr.on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {a : \u03b1} (h : is_local_extr f a) (s : set \u03b1) : is_local_extr_on f s a :=\n  is_extr_filter.filter_inf h (filter.principal s)\n\ntheorem is_local_min_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_local_min_on f t a) (h : s \u2286 t) :\n    is_local_min_on f s a :=\n  is_min_filter.filter_mono hf (nhds_within_mono a h)\n\ntheorem is_local_max_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_local_max_on f t a) (h : s \u2286 t) :\n    is_local_max_on f s a :=\n  is_max_filter.filter_mono hf (nhds_within_mono a h)\n\ntheorem is_local_extr_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_local_extr_on f t a) (h : s \u2286 t) :\n    is_local_extr_on f s a :=\n  is_extr_filter.filter_mono hf (nhds_within_mono a h)\n\ntheorem is_local_min_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a) (t : set \u03b1) :\n    is_local_min_on f (s \u2229 t) a :=\n  is_local_min_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_local_max_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a) (t : set \u03b1) :\n    is_local_max_on f (s \u2229 t) a :=\n  is_local_max_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_local_extr_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a) (t : set \u03b1) :\n    is_local_extr_on f (s \u2229 t) a :=\n  is_local_extr_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_min_on.localize {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {s : set \u03b1} {a : \u03b1} (hf : is_min_on f s a) : is_local_min_on f s a :=\n  is_min_filter.filter_mono hf inf_le_right\n\ntheorem is_max_on.localize {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {s : set \u03b1} {a : \u03b1} (hf : is_max_on f s a) : is_local_max_on f s a :=\n  is_max_filter.filter_mono hf inf_le_right\n\ntheorem is_extr_on.localize {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {s : set \u03b1} {a : \u03b1} (hf : is_extr_on f s a) : is_local_extr_on f s a :=\n  is_extr_filter.filter_mono hf inf_le_right\n\ntheorem is_local_min_on.is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a) (hs : s \u2208 nhds a) :\n    is_local_min f a :=\n  (fun (this : nhds a \u2264 filter.principal s) =>\n      is_min_filter.filter_mono hf (le_inf (le_refl (nhds a)) this))\n    (iff.mpr filter.le_principal_iff hs)\n\ntheorem is_local_max_on.is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a) (hs : s \u2208 nhds a) :\n    is_local_max f a :=\n  (fun (this : nhds a \u2264 filter.principal s) =>\n      is_max_filter.filter_mono hf (le_inf (le_refl (nhds a)) this))\n    (iff.mpr filter.le_principal_iff hs)\n\ntheorem is_local_extr_on.is_local_extr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a) (hs : s \u2208 nhds a) :\n    is_local_extr f a :=\n  is_local_extr_on.elim hf\n    (fun (hf : is_local_min_on f s a) => is_min_filter.is_extr (is_local_min_on.is_local_min hf hs))\n    fun (hf : is_local_max_on f s a) => is_max_filter.is_extr (is_local_max_on.is_local_max hf hs)\n\ntheorem is_min_on.is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_min_on f s a) (hs : s \u2208 nhds a) : is_local_min f a :=\n  is_local_min_on.is_local_min (is_min_on.localize hf) hs\n\ntheorem is_max_on.is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_max_on f s a) (hs : s \u2208 nhds a) : is_local_max f a :=\n  is_local_max_on.is_local_max (is_max_on.localize hf) hs\n\ntheorem is_extr_on.is_local_extr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_extr_on f s a) (hs : s \u2208 nhds a) : is_local_extr f a :=\n  is_local_extr_on.is_local_extr (is_extr_on.localize hf) hs\n\n/-! ### Constant -/\n\ntheorem is_local_min_on_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_local_min_on (fun (_x : \u03b1) => b) s a :=\n  is_min_filter_const\n\ntheorem is_local_max_on_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_local_max_on (fun (_x : \u03b1) => b) s a :=\n  is_max_filter_const\n\ntheorem is_local_extr_on_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_local_extr_on (fun (_x : \u03b1) => b) s a :=\n  is_extr_filter_const\n\ntheorem is_local_min_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {a : \u03b1}\n    {b : \u03b2} : is_local_min (fun (_x : \u03b1) => b) a :=\n  is_min_filter_const\n\ntheorem is_local_max_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {a : \u03b1}\n    {b : \u03b2} : is_local_max (fun (_x : \u03b1) => b) a :=\n  is_max_filter_const\n\ntheorem is_local_extr_const {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {a : \u03b1}\n    {b : \u03b2} : is_local_extr (fun (_x : \u03b1) => b) a :=\n  is_extr_filter_const\n\n/-! ### Composition with (anti)monotone functions -/\n\ntheorem is_local_min.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) {g : \u03b2 \u2192 \u03b3}\n    (hg : monotone g) : is_local_min (g \u2218 f) a :=\n  is_min_filter.comp_mono hf hg\n\ntheorem is_local_max.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) {g : \u03b2 \u2192 \u03b3}\n    (hg : monotone g) : is_local_max (g \u2218 f) a :=\n  is_max_filter.comp_mono hf hg\n\ntheorem is_local_extr.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_extr f a) {g : \u03b2 \u2192 \u03b3}\n    (hg : monotone g) : is_local_extr (g \u2218 f) a :=\n  is_extr_filter.comp_mono hf hg\n\ntheorem is_local_min.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) {g : \u03b2 \u2192 \u03b3}\n    (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_max (g \u2218 f) a :=\n  is_min_filter.comp_antimono hf hg\n\ntheorem is_local_max.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) {g : \u03b2 \u2192 \u03b3}\n    (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_min (g \u2218 f) a :=\n  is_max_filter.comp_antimono hf hg\n\ntheorem is_local_extr.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_extr f a) {g : \u03b2 \u2192 \u03b3}\n    (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_extr (g \u2218 f) a :=\n  is_extr_filter.comp_antimono hf hg\n\ntheorem is_local_min_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a)\n    {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_min_on (g \u2218 f) s a :=\n  is_min_filter.comp_mono hf hg\n\ntheorem is_local_max_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a)\n    {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_max_on (g \u2218 f) s a :=\n  is_max_filter.comp_mono hf hg\n\ntheorem is_local_extr_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a)\n    {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_local_extr_on (g \u2218 f) s a :=\n  is_extr_filter.comp_mono hf hg\n\ntheorem is_local_min_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_min_on f s a)\n    {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_max_on (g \u2218 f) s a :=\n  is_min_filter.comp_antimono hf hg\n\ntheorem is_local_max_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_max_on f s a)\n    {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_min_on (g \u2218 f) s a :=\n  is_max_filter.comp_antimono hf hg\n\ntheorem is_local_extr_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [topological_space \u03b1]\n    [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_local_extr_on f s a)\n    {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_local_extr_on (g \u2218 f) s a :=\n  is_extr_filter.comp_antimono hf hg\n\ntheorem is_local_min.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} [preorder \u03b4]\n    {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_local_min f a)\n    {g : \u03b1 \u2192 \u03b3} (hg : is_local_min g a) : is_local_min (fun (x : \u03b1) => op (f x) (g x)) a :=\n  is_min_filter.bicomp_mono hop hf hg\n\ntheorem is_local_max.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} [preorder \u03b4]\n    {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_local_max f a)\n    {g : \u03b1 \u2192 \u03b3} (hg : is_local_max g a) : is_local_max (fun (x : \u03b1) => op (f x) (g x)) a :=\n  is_max_filter.bicomp_mono hop hf hg\n\n-- No `extr` version because we need `hf` and `hg` to be of the same kind\n\ntheorem is_local_min_on.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} [preorder \u03b4]\n    {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op)\n    (hf : is_local_min_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_local_min_on g s a) :\n    is_local_min_on (fun (x : \u03b1) => op (f x) (g x)) s a :=\n  is_min_filter.bicomp_mono hop hf hg\n\ntheorem is_local_max_on.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} [preorder \u03b4]\n    {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op)\n    (hf : is_local_max_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_local_max_on g s a) :\n    is_local_max_on (fun (x : \u03b1) => op (f x) (g x)) s a :=\n  is_max_filter.bicomp_mono hop hf hg\n\n/-! ### Composition with `continuous_at` -/\n\ntheorem is_local_min.comp_continuous {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_min f (g b))\n    (hg : continuous_at g b) : is_local_min (f \u2218 g) b :=\n  hg hf\n\ntheorem is_local_max.comp_continuous {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_max f (g b))\n    (hg : continuous_at g b) : is_local_max (f \u2218 g) b :=\n  hg hf\n\ntheorem is_local_extr.comp_continuous {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_extr f (g b))\n    (hg : continuous_at g b) : is_local_extr (f \u2218 g) b :=\n  is_extr_filter.comp_tendsto hf hg\n\ntheorem is_local_min.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {s : set \u03b4} {g : \u03b4 \u2192 \u03b1} {b : \u03b4}\n    (hf : is_local_min f (g b)) (hg : continuous_on g s) (hb : b \u2208 s) :\n    is_local_min_on (f \u2218 g) s b :=\n  is_min_filter.comp_tendsto hf (hg b hb)\n\ntheorem is_local_max.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {s : set \u03b4} {g : \u03b4 \u2192 \u03b1} {b : \u03b4}\n    (hf : is_local_max f (g b)) (hg : continuous_on g s) (hb : b \u2208 s) :\n    is_local_max_on (f \u2218 g) s b :=\n  is_max_filter.comp_tendsto hf (hg b hb)\n\ntheorem is_local_extr.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {s : set \u03b4} (g : \u03b4 \u2192 \u03b1)\n    {b : \u03b4} (hf : is_local_extr f (g b)) (hg : continuous_on g s) (hb : b \u2208 s) :\n    is_local_extr_on (f \u2218 g) s b :=\n  is_local_extr.elim hf\n    (fun (hf : is_local_min f (g b)) =>\n      is_min_filter.is_extr (is_local_min.comp_continuous_on hf hg hb))\n    fun (hf : is_local_max f (g b)) =>\n      is_max_filter.is_extr (is_local_max.comp_continuous_on hf hg hb)\n\ntheorem is_local_min_on.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {t : set \u03b1} {s : set \u03b4}\n    {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_min_on f t (g b)) (hst : s \u2286 g \u207b\u00b9' t)\n    (hg : continuous_on g s) (hb : b \u2208 s) : is_local_min_on (f \u2218 g) s b :=\n  is_min_filter.comp_tendsto hf\n    (tendsto_nhds_within_mono_right (iff.mpr set.image_subset_iff hst)\n      (continuous_within_at.tendsto_nhds_within_image (hg b hb)))\n\ntheorem is_local_max_on.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {t : set \u03b1} {s : set \u03b4}\n    {g : \u03b4 \u2192 \u03b1} {b : \u03b4} (hf : is_local_max_on f t (g b)) (hst : s \u2286 g \u207b\u00b9' t)\n    (hg : continuous_on g s) (hb : b \u2208 s) : is_local_max_on (f \u2218 g) s b :=\n  is_max_filter.comp_tendsto hf\n    (tendsto_nhds_within_mono_right (iff.mpr set.image_subset_iff hst)\n      (continuous_within_at.tendsto_nhds_within_image (hg b hb)))\n\ntheorem is_local_extr_on.comp_continuous_on {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x}\n    [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} [topological_space \u03b4] {t : set \u03b1} {s : set \u03b4}\n    (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_local_extr_on f t (g b)) (hst : s \u2286 g \u207b\u00b9' t)\n    (hg : continuous_on g s) (hb : b \u2208 s) : is_local_extr_on (f \u2218 g) s b :=\n  is_local_extr_on.elim hf\n    (fun (hf : is_local_min_on f t (g b)) =>\n      is_min_filter.is_extr (is_local_min_on.comp_continuous_on hf hst hg hb))\n    fun (hf : is_local_max_on f t (g b)) =>\n      is_max_filter.is_extr (is_local_max_on.comp_continuous_on hf hst hg hb)\n\n/-! ### Pointwise addition -/\n\ntheorem is_local_min.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_monoid \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) :\n    is_local_min (fun (x : \u03b1) => f x + g x) a :=\n  is_min_filter.add hf hg\n\ntheorem is_local_max.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_monoid \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) :\n    is_local_max (fun (x : \u03b1) => f x + g x) a :=\n  is_max_filter.add hf hg\n\ntheorem is_local_min_on.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1}\n    (hf : is_local_min_on f s a) (hg : is_local_min_on g s a) :\n    is_local_min_on (fun (x : \u03b1) => f x + g x) s a :=\n  is_min_filter.add hf hg\n\ntheorem is_local_max_on.add {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1}\n    (hf : is_local_max_on f s a) (hg : is_local_max_on g s a) :\n    is_local_max_on (fun (x : \u03b1) => f x + g x) s a :=\n  is_max_filter.add hf hg\n\n/-! ### Pointwise negation and subtraction -/\n\ntheorem is_local_min.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) : is_local_max (fun (x : \u03b1) => -f x) a :=\n  is_min_filter.neg hf\n\ntheorem is_local_max.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) : is_local_min (fun (x : \u03b1) => -f x) a :=\n  is_max_filter.neg hf\n\ntheorem is_local_extr.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_extr f a) : is_local_extr (fun (x : \u03b1) => -f x) a :=\n  is_extr_filter.neg hf\n\ntheorem is_local_min_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a) :\n    is_local_max_on (fun (x : \u03b1) => -f x) s a :=\n  is_min_filter.neg hf\n\ntheorem is_local_max_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a) :\n    is_local_min_on (fun (x : \u03b1) => -f x) s a :=\n  is_max_filter.neg hf\n\ntheorem is_local_extr_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_extr_on f s a) :\n    is_local_extr_on (fun (x : \u03b1) => -f x) s a :=\n  is_extr_filter.neg hf\n\ntheorem is_local_min.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_max g a) :\n    is_local_min (fun (x : \u03b1) => f x - g x) a :=\n  is_min_filter.sub hf hg\n\ntheorem is_local_max.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [ordered_add_comm_group \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_min g a) :\n    is_local_max (fun (x : \u03b1) => f x - g x) a :=\n  is_max_filter.sub hf hg\n\ntheorem is_local_min_on.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1}\n    (hf : is_local_min_on f s a) (hg : is_local_max_on g s a) :\n    is_local_min_on (fun (x : \u03b1) => f x - g x) s a :=\n  is_min_filter.sub hf hg\n\ntheorem is_local_max_on.sub {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1}\n    (hf : is_local_max_on f s a) (hg : is_local_min_on g s a) :\n    is_local_max_on (fun (x : \u03b1) => f x - g x) s a :=\n  is_max_filter.sub hf hg\n\n/-! ### Pointwise `sup`/`inf` -/\n\ntheorem is_local_min.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) :\n    is_local_min (fun (x : \u03b1) => f x \u2294 g x) a :=\n  is_min_filter.sup hf hg\n\ntheorem is_local_max.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) :\n    is_local_max (fun (x : \u03b1) => f x \u2294 g x) a :=\n  is_max_filter.sup hf hg\n\ntheorem is_local_min_on.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a)\n    (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => f x \u2294 g x) s a :=\n  is_min_filter.sup hf hg\n\ntheorem is_local_max_on.sup {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_sup \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a)\n    (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => f x \u2294 g x) s a :=\n  is_max_filter.sup hf hg\n\ntheorem is_local_min.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) :\n    is_local_min (fun (x : \u03b1) => f x \u2293 g x) a :=\n  is_min_filter.inf hf hg\n\ntheorem is_local_max.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) :\n    is_local_max (fun (x : \u03b1) => f x \u2293 g x) a :=\n  is_max_filter.inf hf hg\n\ntheorem is_local_min_on.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a)\n    (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => f x \u2293 g x) s a :=\n  is_min_filter.inf hf hg\n\ntheorem is_local_max_on.inf {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [semilattice_inf \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a)\n    (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => f x \u2293 g x) s a :=\n  is_max_filter.inf hf hg\n\n/-! ### Pointwise `min`/`max` -/\n\ntheorem is_local_min.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) :\n    is_local_min (fun (x : \u03b1) => min (f x) (g x)) a :=\n  is_min_filter.min hf hg\n\ntheorem is_local_max.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) :\n    is_local_max (fun (x : \u03b1) => min (f x) (g x)) a :=\n  is_max_filter.min hf hg\n\ntheorem is_local_min_on.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a)\n    (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => min (f x) (g x)) s a :=\n  is_min_filter.min hf hg\n\ntheorem is_local_max_on.min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a)\n    (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => min (f x) (g x)) s a :=\n  is_max_filter.min hf hg\n\ntheorem is_local_min.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_min f a) (hg : is_local_min g a) :\n    is_local_min (fun (x : \u03b1) => max (f x) (g x)) a :=\n  is_min_filter.max hf hg\n\ntheorem is_local_max.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hf : is_local_max f a) (hg : is_local_max g a) :\n    is_local_max (fun (x : \u03b1) => max (f x) (g x)) a :=\n  is_max_filter.max hf hg\n\ntheorem is_local_min_on.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_min_on f s a)\n    (hg : is_local_min_on g s a) : is_local_min_on (fun (x : \u03b1) => max (f x) (g x)) s a :=\n  is_min_filter.max hf hg\n\ntheorem is_local_max_on.max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [linear_order \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_local_max_on f s a)\n    (hg : is_local_max_on g s a) : is_local_max_on (fun (x : \u03b1) => max (f x) (g x)) s a :=\n  is_max_filter.max hf hg\n\n/-! ### Relation with `eventually` comparisons of two functions -/\n\ntheorem filter.eventually_le.is_local_max_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n    (hle : filter.eventually_le (nhds_within a s) g f) (hfga : f a = g a)\n    (h : is_local_max_on f s a) : is_local_max_on g s a :=\n  filter.eventually_le.is_max_filter hle hfga h\n\ntheorem is_local_max_on.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_max_on f s a)\n    (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_max_on g s a :=\n  is_max_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_eq.is_local_max_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n    (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) :\n    is_local_max_on f s a \u2194 is_local_max_on g s a :=\n  filter.eventually_eq.is_max_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_le.is_local_min_on {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n    (hle : filter.eventually_le (nhds_within a s) f g) (hfga : f a = g a)\n    (h : is_local_min_on f s a) : is_local_min_on g s a :=\n  filter.eventually_le.is_min_filter hle hfga h\n\ntheorem is_local_min_on.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_min_on f s a)\n    (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_min_on g s a :=\n  is_min_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_eq.is_local_min_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n    (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) :\n    is_local_min_on f s a \u2194 is_local_min_on g s a :=\n  filter.eventually_eq.is_min_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem is_local_extr_on.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2]\n    {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_extr_on f s a)\n    (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) : is_local_extr_on g s a :=\n  is_extr_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_eq.is_local_extr_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {s : set \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n    (heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a \u2208 s) :\n    is_local_extr_on f s a \u2194 is_local_extr_on g s a :=\n  filter.eventually_eq.is_extr_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)\n\ntheorem filter.eventually_le.is_local_max {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hle : filter.eventually_le (nhds a) g f)\n    (hfga : f a = g a) (h : is_local_max f a) : is_local_max g a :=\n  filter.eventually_le.is_max_filter hle hfga h\n\ntheorem is_local_max.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_max f a) (heq : filter.eventually_eq (nhds a) f g) :\n    is_local_max g a :=\n  is_max_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_eq.is_local_max_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds a) f g) :\n    is_local_max f a \u2194 is_local_max g a :=\n  filter.eventually_eq.is_max_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_le.is_local_min {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (hle : filter.eventually_le (nhds a) f g)\n    (hfga : f a = g a) (h : is_local_min f a) : is_local_min g a :=\n  filter.eventually_le.is_min_filter hle hfga h\n\ntheorem is_local_min.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_min f a) (heq : filter.eventually_eq (nhds a) f g) :\n    is_local_min g a :=\n  is_min_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_eq.is_local_min_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds a) f g) :\n    is_local_min f a \u2194 is_local_min g a :=\n  filter.eventually_eq.is_min_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem is_local_extr.congr {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (h : is_local_extr f a) (heq : filter.eventually_eq (nhds a) f g) :\n    is_local_extr g a :=\n  is_extr_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)\n\ntheorem filter.eventually_eq.is_local_extr_iff {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n    [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} (heq : filter.eventually_eq (nhds a) f g) :\n    is_local_extr f a \u2194 is_local_extr g a :=\n  filter.eventually_eq.is_extr_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/topology/local_extr_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7220489425023873}}
{"text": "import tidy.tidy\nimport tactic.ring\n\nimport .number\nimport .binary_op\nimport .order\nimport .facts\n\n--define pairs and the rational equality law\n\nstructure pair := mk ::\n  ( x y : \u2124 )\n  ( non_zero : y \u2260 0)\n\ndef q_law : pair \u2192 pair \u2192 Prop := \u03bb a b : pair, a.1 * b.2 = b.1 * a.2\n\ntheorem q_refl : \u2200 ( a : pair ), q_law a a\n    := by unfold q_law; intro a; refl\ntheorem q_symm : \u2200 ( a b : pair ), q_law a b \u2192 q_law b a\n    := by unfold q_law; intros a b; tidy\ntheorem q_trans : \u2200 (a b c : pair), (q_law a b) \u2192 (q_law b c) \u2192 (q_law a c) := begin\n    intros a b c,\n    unfold q_law,\n    intros h1 h2,\n    have hr : b.2 * (c.1 * a.2) = b.2 * (a.1 * c.2), from calc\n        b.2 * (c.1 * a.2) = a.2 * (c.1 * b.2) : by ring\n                    ... = a.2 * (b.1 * c.2) : by rw h2\n                    ... = (b.1 * a.2) * c.2 : by ring\n                    ... = (a.1 * b.2) * c.2 : by rw h1\n                    ... = b.2 * (a.1 * c.2) : by ring,\n    exact eq.symm (cancellation_law b.non_zero hr),\nend\n\ninstance pair_setoid := setoid.mk q_law (mk_equivalence q_law q_refl q_symm q_trans)\n\ndef pair_add : bop pair\n    := \u03bb a b : pair, pair.mk (a.1 * b.2 + b.1 * a.2) (a.2 * b.2)\n        (nonzero_mul a.non_zero b.non_zero)\n\ndef pair_mul : bop pair\n    := \u03bb a b : pair, pair.mk (a.1 * b.1) (a.2 * b.2)\n        (nonzero_mul a.non_zero b.non_zero)\n\n--proving well-definedness, and then commutativity\n\nlemma pair_add_assoc : bop_rel_assoc q_law pair_add\n    := by intros a b c; unfold q_law; unfold pair_add; simp; ring\nlemma pair_mul_assoc : bop_rel_assoc q_law pair_mul\n    := by intros a b c; unfold q_law; unfold pair_mul; simp; ring\n\nlemma pair_add_comm : bop_rel_comm q_law pair_add\n    := by intros a b; unfold q_law; unfold pair_add; simp; ring\nlemma pair_mul_comm : bop_rel_comm q_law pair_mul\n    := by intros a b; unfold q_law; unfold pair_mul; simp; ring\n\nlemma pair_add_invar_first : bop_rel_invar_first q_law pair_add :=\nbegin\n   intros a b c h,\n   unfold q_law,\n--FIXME these three lines are need because obviously is really slow without\n   unfold pair_add,\n   simp,\n   ring,\n   have hh : a.x * b.y = b.x * a.y, by apply h,\n   obviously,\nend\n\nlemma pair_mul_invar_first : bop_rel_invar_first q_law pair_mul :=\nbegin\n   intros a b c h,\n   unfold q_law,\n   have hh : a.x * b.y = b.x * a.y, by apply h,\n   obviously,\nend\n\nlemma pair_add_invar : bop_rel_invar q_law pair_add\n:= bop_comm_easy_invar pair_add_comm pair_add_invar_first\nlemma pair_mul_invar : bop_rel_invar q_law pair_mul\n:= bop_comm_easy_invar pair_mul_comm pair_mul_invar_first\n\ndef pair_add_l := liftable_bop.mk pair_setoid pair_add pair_add_invar\ndef pair_mul_l := liftable_bop.mk pair_setoid pair_mul pair_mul_invar\n\n-- lift the above construction to give the rationals\n\ndef \u211a\u211a := quotient pair_setoid\ndef \u211a\u211a.mk (p : pair) : \u211a\u211a := quot.mk q_law p\ndef \u211a\u211a.divide (a b : \u2124) (h : b \u2260 0) : \u211a\u211a := \u211a\u211a.mk (pair.mk a b h)\ndef \u211a\u211a.from_int (n : \u2124) : \u211a\u211a := \u211a\u211a.mk (pair.mk n 1 one_ne_zero)\n\ndef rat_add : bop \u211a\u211a := lift_bop pair_add_l\ndef rat_mul : bop \u211a\u211a := lift_bop pair_mul_l\n\n-- addition and multiplication are associative and commutative\n\ntheorem rat_add_assoc : bop_assoc rat_add\n    := lift_assoc pair_add_l pair_add_assoc\ntheorem rat_add_comm : bop_comm rat_add\n    := lift_comm pair_add_l pair_add_comm\n\ntheorem rat_mul_assoc : bop_assoc rat_mul\n    := lift_assoc pair_mul_l pair_mul_assoc\ntheorem rat_mul_comm : bop_comm rat_mul\n    := lift_comm pair_mul_l pair_mul_comm\n\n--example of the equivalence of the general construction above to the ``direct way''\n\ndef pair_add_rat_direct : pair \u2192 pair \u2192 \u211a\u211a\n:= \u03bb a b : pair, (\u211a\u211a.mk (pair_add a b))\nexample : \u2200 a b : pair, pair_add_rat_direct a b = (induced_quobop pair_setoid pair_add) a b := by tidy\n\n--order\n\ndef rat_leq_rel (a b : \u211a\u211a) : Prop := (quot.out a).1 * (quot.out b).2 \u2264 (quot.out b).1 * (quot.out a).2\n\nlemma rat_req_refl : \u2200 a : \u211a\u211a, rat_leq_rel a a := by unfold rat_leq_rel; tidy\nlemma rat_req_antisymm : \u2200 a b : \u211a\u211a, rat_leq_rel a b \u2192 rat_leq_rel b a \u2192 a = b :=\nbegin\n    intros a b h1 h2,\n    have hm : (quot.out b).x * (quot.out a).y = (quot.out a).x * (quot.out b).y,\n        unfold rat_leq_rel at *,\n        apply eq.symm (leq_fact h1 h2),\n    clear h1 h2,\n    have hn : \u211a\u211a.mk (quot.out a) = \u211a\u211a.mk (quot.out b),\n        have hl : q_law (quot.out a) (quot.out b),\n            unfold q_law,\n            apply eq.symm hm,\n        apply (@quotient_fact pair pair_setoid (quot.out a) (quot.out b)),\n        exact hl,\n    transitivity,\n    apply eq.symm (quotient.out_eq a),\n    transitivity,\n    apply hn,\n    apply quotient.out_eq,\nend\n\n#check quotient pair_setoid\n#check @quotient.out_eq pair pair_setoid \n\nlemma rat_req_trans : \u2200 a b c : \u211a\u211a, rat_leq_rel a b \u2192 rat_leq_rel b c \u2192 rat_leq_rel a c :=\nbegin\n    intros a b c h1 h2,\n    unfold rat_leq_rel at *,\n    admit\nend\n\n#check rat_leq_rel\n\n-- Scott: Why is this definition of rat_leq okay? Even though it secretly is, it\n-- may not even be well-defined in the sense which I intend. I suppose the \n-- ``constructive'' interpretation is that there is some distinguished function \n-- quot.out : \u211a\u211a \u2192 pair which can reliably give the same element for each \n-- equivalence class. This is still very strange to me! Am I really just \n-- thinking that the Axiom of Choice is strange?", "meta": {"author": "khoek", "repo": "lmath", "sha": "a4f35205e6b5a3f16926234bf8eb7f7b5f56e47f", "save_path": "github-repos/lean/khoek-lmath", "path": "github-repos/lean/khoek-lmath/lmath-a4f35205e6b5a3f16926234bf8eb7f7b5f56e47f/rational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7219955599467188}}
{"text": "import logic.basic --hide\n\n/-\n## Exact\n\nSometimes after rewriting the hypotheses and goal enough we reach a point where the goal is\nexactly the same as one of the hypothesis.\nIn this case we want to tell Lean that we are finished, one of our hypotheses now matches\nthe conclusion we needed to get to.\n\nThe tactic to do this is called `exact`, and to use it we just need to supply the name of\nthe hypothesis we want to use.\n\nFor example if we were trying to prove that 3 divides some natural number `n` and we\nended up with the goal state:\n```\nn : \u2115\nh : 3 \u2223 n\n\u22a2 3 \u2223 n\n```\nthen `exact h,` would complete the proof.\n\n-/\n\n/- Tactic : exact\n\n## Summary\n\nIf the goal is `\u22a2 X` then `exact x` will close the goal if\nand only if `x` is a term of type `X`.\n\n## Details\n\nSay $P$, $Q$ and $R$ are types (i.e., what a mathematician\nmight think of as either sets or propositions),\nand the local context looks like this:\n\n```\np : P,\nh : P \u2192 Q,\nj : Q \u2192 R\n\u22a2 R\n```\n\nIf you can spot how to make a term of type `R`, then you\ncan just make it and say you're done using the `exact` tactic\ntogether with the formula you have spotted. For example the\nabove goal could be solved with\n\n`exact j(h(p)),`\n\nbecause $j(h(p))$ is easily checked to be a term of type $R$\n(i.e., an element of the set $R$, or a proof of the proposition $R$).\n\n-/\n\n/- Axiom :\nor_and_distrib_right : \u2200 {a b c : Prop}, (a \u2228 b) \u2227 c \u2194 a \u2227 c \u2228 b \u2227 c\n-/\n\n/- Axiom :\nnot_and_self (a : Prop) : (\u00aca \u2227 a) \u2194 false\n-/\n\n/- Axiom :\nor_false (a : Prop) : (a \u2228 false) \u2194 a\n-/\n\n/- Axiom :\nand_comm : \u2200 (a b : Prop), a \u2227 b \u2194 b \u2227 a\n-/\n\n/- Axiom :\nand_assoc : \u2200 {c : Prop} (a b : Prop), (a \u2227 b) \u2227 c \u2194 a \u2227 b \u2227 c\n-/\n\n/- Axiom :\nand_self : \u2200 (a : Prop), a \u2227 a \u2194 a\n-/\n\n/- Lemma : no-side-bar\n-/\nlemma prop_prop (P Q : Prop) (h : Q \u2227 P \u2227 Q) :\n  (P \u2228 \u00ac Q) \u2227 Q :=\nbegin\n  rw or_and_distrib_right,\n  rw not_and_self,\n  rw or_false,\n  rw and_comm at h,\n  rw and_assoc at h,\n  rw and_self at h,\n  exact h,\nend\n", "meta": {"author": "alexjbest", "repo": "CAP-game", "sha": "d823def7325d7142d61e766b2e027f936685a8ff", "save_path": "github-repos/lean/alexjbest-CAP-game", "path": "github-repos/lean/alexjbest-CAP-game/CAP-game-d823def7325d7142d61e766b2e027f936685a8ff/src/intro/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7219955559710496}}
{"text": "/-\nATTENTION: This file got long and is now obsolete. \nPlease see it broken into individual sections in the\nInference_Rules directory. We'll leave the original \ncontent in place below for reference in case you need\nto look back.\n-/\n\n/-\nAs a reminder, here are the inference rules (and a few\n\"logical fallacies\" that you tested for validity in the\nsetting of propositional logic, where the variables are\nall Boolean, and where logical connectives correspond to\nBoolean operations, such as &&, ||, and ! (C, C++, etc.) \n\n1. X \u2228 Y, X \u22a2 \u00acY             -- affirming the disjunct\n2. X, Y \u22a2 X \u2227 Y              -- and introduction\n3. X \u2227 Y \u22a2 X                 -- and elimination left\n4. X \u2227 Y \u22a2 Y                 -- and elimination right\n5. \u00ac\u00acX \u22a2 X                   -- negation elimination \n6. \u00ac(X \u2227 \u00acX)                 -- no contradiction\n7. X \u22a2 X \u2228 Y                 -- or introduction left\n8. Y \u22a2 X \u2228 Y                 -- or introduction right\n9. X \u2192 Y, \u00acX \u22a2 \u00ac Y           -- denying the antecedent\n10. X \u2192 Y, Y \u2192 X \u22a2 X \u2194 Y      -- iff introduction\n11. X \u2194 Y \u22a2 X \u2192 Y            -- iff elimination left\n12. X \u2194 Y \u22a2 Y \u2192 X            -- iff elimination right\n13. X \u2228 Y, X \u2192 Z, Y \u2192 Z \u22a2 Z  -- or elimination\n14. X \u2192 Y, Y \u22a2 X             -- affirming the conclusion\n15. X \u2192 Y, X \u22a2 Y             -- arrow elimination\n16. X \u2192 Y, Y \u2192 Z \u22a2 X \u2192 Z     -- transitivity of \u2192 \n17. X \u2192 Y \u22a2 Y \u2192 X            -- converse\n18. X \u2192 Y \u22a2 \u00acY \u2192 \u00acX          -- contrapositive\n19. \u00ac(X \u2228 Y) \u2194 \u00acX \u2227 \u00acY       -- DeMorgan #1 (\u00ac distributes over \u2228)\n20. \u00ac(X \u2227 Y) \u2194 \u00acX \u2228 \u00acY       -- Demorgan #2 (\u00ac distributes over \u2227)\n-/\n\n/-\nHere we present the familiar inference rules above but \nnow in the context of the more expressive, higher-order\npredicate logic of the Lean Prover tool. A big benefit \nis that \"Lean\" checks the syntax of our expressions.\n\nNote that we've reordered the inference rules you've already\nseen, putting all of the inference rules related to any given\nconnective or quantifier together.\n\nWe've also added inference rules for the quantifiers, \u2200 and\n\u2203, which of course are not relevant in propositional logic \nbut that are essential in predicate logic (whether first- or\nhigher-order).\n\nWe've also separate out, and present first, the fundamental\ninference rules from \"inference rules\" that are can be proved\nusing the fundamental rules. These rules are thus \"theorems,\"\nnot \"axioms.\" \n-/\n\n/-\nOk. So each of the following lines does the following. As you\nread this, look at the first definition, of and_introduction.\n\nIn Lean, we can use \"def,\" a Lean keywork, to start to define\nthe meaning/value of a variable. After \"def\" comes the name of\nthe variable. Here it's and_introduction. Next comes what we\nhave already seen, albeit briefly: a type judgment, comprising\na colon followed by a type name. The type name in this case is\n\"Prop,\" which is the type of all *propositions* in Lean. So far\nthen we've told Lean that we're going to define and_introduction\nto be a variable the value of which is a proposition. Next is \na :=, which is the Lean operator for binding a value to a name.\nFinally, the value to be bound is to the right. In this case,\nas expected, it's a proposition. \n\nThe particular proposition in this case is what we can call a \n\"universal generalization\" in that it starts with a \u2200. The \u2200 \nintroduces two new variable names, X and Y, with a type judgment\nstating that their values are propositions, indeed they can be\n*any* propositions whatsoever. Finally, in the context of the\nassumption that X and Y are arbitrary (any) proposition, the\nrule states that if we assume that we are given a proof of X\n(the analog of the assumption that X is true in propositional\nor first-order predicate logic), and if in that context we then\nfurther assume that we have a proof of Y (and thus that Y is \nalso true), then in that context, we can construct a proof of\nX \u2227 Y, thus concluding that it, too, must be true.  \n-/\n\n/- *** AND *** -/\n\n-- \u2227 \ndef and_introduction  : Prop  := \u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y)\ndef and_elim_left     : Prop  := \u2200 (X Y : Prop), X \u2227 Y \u2192 X  \ndef and_elim_right    : Prop  := \u2200 (X Y : Prop), X \u2227 Y \u2192 Y  \n\n/-\nNote that we are able to express these rules of logic very\nnaturally in higher-order constructive logic because we can\nquantify over propositions. You cannot write these definitions\nin first-order logic because it doesn't allow you to do this.\nSuch an expression is a syntax error in first-order logic. \n-/\n\n/- A LEAN DETAIL and IMPORTANT LANGUAGE DESIGN CONCEPT\nA good language gives you good ways not to repeat yourself.\nWe can avoid having to repeatedly write \"\u2200 (X Y : Prop),\"\nby creating a \"section\" in a Lean file, and declaring the\ncommon variables once at the top. Lean then implicitly adds\na \"\u2200 (X : Prop)\" at the beginning of any expression that has\nan X in it (and the same goes for Y and Z in this file).\nI\n-/\n\nsection pred_logic\n\nvariables X Y Z : Prop\n\n/-\nIn your mind, be sure to recognize that every one of the\nfollowing propositions now has an implicit \u2200 in front. The\nor_intro_left definition that comes next, for example, means \ndef or_intro_left : Prop := \u2200 (X Y : Prop), X \u2192 X \u2228 Y. \n-/\n\n\n/- *** OR *** -/\n\n-- \u2228 \ndef or_intro_left : Prop    := X \u2192 X \u2228 Y\ndef or_intro_right : Prop   := Y \u2192 X \u2228 Y\ndef or_elim : Prop          := (X \u2228 Y) \u2192 (X \u2192 Z) \u2192 (Y \u2192 Z) \u2192 Z\n\n/-\nLean, and other languages like it, also allow you to drop\nexplicit type judgments when they can be inferred from the\ncontext. In the rest of this file, we also drop the \": Prop\"\nexplicit type judgments because Lean can figure our from the\nvalues that follow the :='s that type types of the variables\nhere just have to be Prop.\n-/\n\n/-\nQuiz questions. \n\nSuppose you know that (X \u2192 Z) and (Y \u2192 Z) are true and you \nwant to prove Z. To be able to prove Z it will *suffice* to \nprove ______; for then you will need only to apply the ______\nrule to deduce that Z is true.\n\nSuppose you know that (X \u2192 Z), (Y \u2192 Z), and Z are all true.\nIs it necessarily that case that (X \u2228 Y) is also true? Defend\nyou answer.\n\nSuppose it's raining OR the sprinkler is running, and that in\neither case the grass is wet. Is the grass wet? How would you\nprove it?\n-/\n\n\n/- *** IFF *** -/\n\n-- \u2194 \ndef iff_intro         := (X \u2192 Y) \u2192 (Y \u2192 X) \u2192 X \u2194 Y\n\n/-\nYou can read this rule both forward (left to right) and \nbackwards. Reading forwards, it says that if you have a\nproof (or know the truth) of X \u2192 Y, and you have a proof\n(or know the truth) of Y \u2192 X, then you can derive of a proof\n(deduce the truth) of X \u2194 Y.\n\nThe more important direction in practice is to read it\nfrom right to left. What it says in this reading is that\nif you want to prove X \u2194 Y, then it will suffice to have\ntwo \"smaller\" proofs: one of X \u2192 Y and one of Y \u2192 X. \n\nFrom now on, whenever you're asked to prove equivalence\nof two propositions, X and Y, you'll thus start by saying,\n\"It will suffice to prove the implication in each direction.\"\nThen you end up with two smaller goals to prove, one in \neach direction. So, \"We first consider X \u2192 Y.\" Then give\na proof of it. Then, \"Next we consider Y \u2192 X.\" Then give\na proof of it. And finally, \"Having proven the implication\nin each direction (by application of the rule of \u2194 intro)\nwe've completed our proof. QED.\"\n-/\n\ndef iff_elim_left     := X \u2194 Y \u2192 (X \u2192 Y)\ndef iff_elim_right    := X \u2194 Y \u2192 (Y \u2192 X)\n\n/-\nThe elimination rules are also easy. Given X \u2194 Y, you can\nimmediately deduce X \u2192 Y and Y \u2192 X.\n-/\n\n/- *** FORALL and ARROW *** -/\n\n-- \u2192 and \u2200 \ndef arrow_all_equiv   := (\u2200 (x : X), Y) \u2194 (X \u2192 Y)\n\n/-\nTo prove either (\u2200 (x : X), Y) or (X \u2192 Y), you first assume  \nthat you're given an arbitrary but specific proof of X, and\nin that context, you show that you can derive a proof (thus \ndeducing the truth) of Y. It's exactly the same reasoning in\neach case. This is the *introduction* rule for \u2200 and \u2192. \n-/\n\n/-\nIn fact, in constructive logic, X \u2192 Y is simply a notation\n*defined* as \u2200 (x : X), Y. What each of these propositions \nstates in constructive logic is that \"From *any* proof, x, \nof X, we can derive a proof of Y.\" In fact, in Lean, these\npropositions are not only equivalent but equal. \n-/\n\n#check X \u2192 Y          -- Lean confirms this is a proposition\n#check \u2200 (x : X), Y   -- Lean understands this to say X \u2192 Y!\n\n\n\n/- OPTIONAL\nAs an aside, here's a proof that these propositions are \nactually equal. This proof uses an inference rule, rfl, for \nequality that we've not yet studied. Don't worry about the \n\"rfl\" for now, but trust that we're giving a correct proof\nof the equality of these two propositions in Lean\n-/\ntheorem all_imp_equal : (\u2200 (x : X), Y) = (X \u2192 Y) := rfl \n\n/-\nThe reason it's super-helpful to know these propositions \nare equivalent is that it tells you that you can *use* a \nproof of a \u2200 proposition or of a \u2192 proposition in exactly\nthe same way. So let's turn to the *elimination* rules for\n\u2192 and \u2200. \n-/\n\ndef arrow_elim        := (X \u2192 Y)        \u2192 X   \u2192 Y\ndef all_elim          := (\u2200 (x : X), Y) \u2192 X   \u2192 Y\n\n/-\nThe idea underlying these rules date to ancient times. \nThey both say \"if from the truth or a proof of X you \ncan derive a proof or the truth of Y, and if you also \nhave a proof, or know the truth, of X, then you can (in\nconstructive logic) derive a proof of Y (or deduce the\ntruth of Y.\" \n\nHere's an example. What we want to say in logic is\nthat if every ball is blue and b is some specific \nball then b is blue. The elimination rule for \u2200 and\n\u2192 applies a generalization to a specific instance to\ndeduce that the generalized statement specialized to\na particular instance is true.\n\nNote: In this example, Y is a proposition obtained by \nplugging \"x\" into a one-argument predicate. So suppose \n(\u2200 (x : X), Y) is read as \"for any Ball x, x is blue.\"  \nHere X is \"Ball;\" x is an arbitrary but specific Ball; \nand Y is read as \"x is blue.\" \n  \nNow suppose that, in this context, you're given a \n*particular* ball, (b : X). What the overall rules\nsays is that you now conclude that \"b is blue.\"\n\nThe elimination rule works by *applying* a proof of\na universal generalization (showing that something\nis true of *every* object of a particular kind) to \na *specific* object of that kind, to deduce that the \ngeneralized statement is also true of that specific\nobject.\n\nIf every ball is blue, and if b is a ball, then b\nmust be blue. Another way to say it that makes a\nbit more sense for the (X \u2192 Y) notation is that \n\"if being any ball, x, implies that x is blue, and \nif b is some particular ball, then b is blue.\n-/\n\n/-\nAs an example, consider a predicate, (isBlue _), where you can fill\nin the blank/argument with any Ball-type object. If b is a specific\nBall-type object, then (isBlue b) is a proposition, representing the\nEnglish-language claim that b is blue. Here's how we represent this\npredicate in Lean.\n-/\n\nvariable Ball : Type            -- Ball is a type of object\nvariable isBlue : Ball \u2192 Prop\n/-\nFirst we Ball to be the name of a type of object (like int or \nbool). Then we define isBlue to be a construct (think function!)\nthat when given any object of type Ball as an argument yields a\nproposition. To see how this works, suppose we have some specific\nballs, b1 and b2.\n-/\nvariables (b1 b2 : Ball)\n/-\nNow let's use isBlue to make some propositions!\n-/\n#check isBlue                               -- a predicate\n#check isBlue b1                            -- a proposition about b1\n#check isBlue b2                            -- a proposition about b2\n#check (\u2200 (x : Ball), isBlue x)             -- generalization\nvariable all_balls_blue : (\u2200 (x : Ball), isBlue x)   -- proof of it\n#check all_balls_blue b1                    -- proof b1 is blue\n#check all_balls_blue b2                    -- proof b2 is blue\n\n/-\nHere's an English-language version.\n\nSuppose b1 and b2 are objects of some type, Ball, and that isBlue \nis one-place predicate taking any Ball, b, as an argument, and that\nreduces to a proposition, denoted (isBlue b), that we understand as\nasserting that the particular ball, b, is blue. Next (295), we take\nall_balls_blue as a proof that all balls are blue. Finally (296 and\n297), we see that we can can use this proof/truth by *applying* it\nto any particular ball, b, to obtain a proof/truth that b is blue. \n\nFor any type S, given any X: (\u2200 s : S), T and any s : S, the \u2200 \nand \u2192 elimination rule(s) say that you can derive a value/proof of \ntype T; moreover this operation is basically done by *applying* ,\nviewed as a function from parameter value to proposition, to the \nactual parameter, s (in Lean denoted as (X s)), to obtain a value\n(proof) of (type) T. Modus ponens is like function application. In\nconstructive logic, a proof of the \u2200 proposition *is* a function.\nHere you begin to see how profound is that proofs in constructive \nlogic tell you not only that a proposition is true but why. Here a\nproof of X \u2192 Y or of \u2200 (x : X), Y, is a program that when given any\nvalue/proof of X as an argument returns a value/proof of Y. If you \ncan produce a function that turns any proof of X into a proof of Y,\nthen you've shown that whenever X is true, so is Y; and that's just\nwhat X \u2192 Y is meant to say (similarly for \u2200 (x : X), Y). \n-/\n\n/-\nWalk-away message: Applying a proof/truth of a universal\ngeneralization to a specific object yields a proof of the\ngeneralization *specialized* to that particular object. That\nis in the higher-order predicate logic of Lean. \n-/\n\n/-\nFinally, let's compare our elimination rule, in the higher-order\npredicate logic of Lean, with its first-order logic counterpart.\n\nThere are two big differences, first, in first-order logic, you \nhave to present the rule outside of the logic: you can't write \nrules like this, \u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y), in first-order\nlogic because in first order logic you can't quantify over types,\npropositions, predicates, functions. Here we do just this with the\n\"\u2200 (X Y : Prop).\" By contrast, in the higher-order logic of Lean,\nwe can represent the rules of first-order logic with no problem: \ne.g., \"\u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y).\"\n\nSecond, as we've discussed, using Lean's higher-order logic, you\ncan think of a proof of \"\u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y)\" as a \nfunction. Each variable bound by a \u2200 and each implication premise\nis an argument, with the type of the return value at the end of \nthe line. So, here, a proof of this proposition can be taken as \na function that takes two propositions, X and Y as arguments, then\na proof (value) of (type) X, then a proof (value) of type Y, and\nthat finally returns a proof (value) X \u2227 Y. Whereas the proof of\n\u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y) is a function the returned proof\nof (X \u2227 Y) is a pair-like data structure. Proofs in constructive\nlogic are *computational*, and you can even compute with them, as\nyou do when you *apply* a proof of a certain kind to an argument\nto obtain a resulting proof/value.\n-/\n\n/-\nQuiz questions:\n\nFirst-order logic. I know that every natural number is\nbeautiful (\u2200 n, NaturalNumber(n) \u2192 Beautiful(n) : true), \nand I want to prove (7 is beautiful : true). Prove it.\nName the inference rule and identify the arguments you\ngive it to prove it.\n\nConstructive logic. Suppose I have a proof, pf, that every \nnatural number is beautiful (\u2200 (n : \u2115), beautiful n), and I \nneed a proof that 7 is beautiful. How can I get the proof \nI need? Answer in both English and with a Lean expression.\n\nFormalize this story: All people are mortal, and Plato \nis a person, therefore Plato is Mortal.\n-/\n\nvariable Person : Type\nvariable Plato : Person\nvariable isMortal : Person \u2192 Prop\nvariable everyoneIsMortal : \u2200 (p : Person), isMortal p\n#check (everyoneIsMortal Plato)   -- \u2200 elimination!\n\n\n/- *** TRUE AND FALSE *** -/\n\n/-\nIn propositional logic, the literal expressions, true\nand false, are part of the syntax of the logic, with\nobvious interpretations. The \"true\" expression always\nevaluates to Boolean true, and the \"false\" expression\nto Boolean false. We could thus write expressions such\nas (X \u2228 false) and (X \u2227 true).\n\nIn predicate logic we have the same concepts exactly. \nIn first order predicate logic, true is a proposition\nthat is invariably judged to be true, and false is a\nproposition that is invariable false. \n\nIn the higher-order predicate logic defined in Lean,\ntrue and false are also propositions, as we can see\nwith the following checks and an example.\n-/\n\n#check true\n#check false\n#check \u2200 (P : Prop), P \u2228 true\n\n/-\nAs with all of the basic connectives and quantifiers,\nthe *meanings* of these terms are established by their\ninference rules. We address the rules for each one now.\n-/\n\n/-\nWe want \"true\" to be a proposition that is always true.\nIn constructive logic, that means there's always a proof\nof it. Indeed, in Lean, that proof is called true.intro. \nThe way to prove that \"true\" is true is by giving this\nproof as evidence.\n-/\n\ntheorem true_is_true : true := true.intro\n\n/-\nIn other words, there's always a trivial proof lying\naround to prove that the proposition, \"true,\" is true.\nLet's decode that theorem:\n- \"theorem\" says we're about to prove a proposition\n- the proposition in this case is \"true\"\n- and the proof is true.intro\nThe Lean prover accepts this proof as correct. It is.\nSimply put, true.intro is the introduction rule for the\nproposition, \"true,\" in Lean.\n-/\n\n/-\nWhat about the elimination rule for true? Well, having\na proof of true gives you essentially zero information,\nso there's nothing useful you can really do with a proof\nof true. Thus there is no elimination rule for true. \n-/\n\n/-\nNext, we want the inference rules for the proposition,\n\"false\" to capture two ideas. First, the proposition\n\"false\" must always be logically false. In first-order\nlogic, that's all there is to it. In the constructive\nlogic of Lean, the proposition \"false,\" is logically\nfalse *because it is defined to be a proposition that\nhas no proofs.* Because it has no proofs, there is no\nintroduction rule for \"false.\" If there were, then we\nwould be able to use it to construct a proof of false,\nwhich can't exist.\" There is thus *no possible way* to\ncomplete the following definition.\n-/\n\ntheorem a_proof_of_false : false := _   -- no can do!\n\n/-\nNow we get to the most interesting and important rule:\nfalse elimination, or the elimination rule for \"false.\"\n\nAs you recall, in propositional logic, false \u2192 X is\nalways true, no matter whether X is true or false.\nSo, false \u2192 false is true, and false \u2192 true is true.\n\nNow suppose P is any proposition in first-order logic.\nThe elimination rule for \"false\" is false \u22a2 P. In\nother words, if you assume or have somehow proven \nfalse (which is possible from a false premise), then \nyou can deduce that anything at all is true: including\nP, no matter what proposition it is, even if it's a\nfalse proposition. As they say, \"from false anything\nfollows,\" or, in Latin, \"ex falso quodlibet.\"\n\nThis principle makes good sense, because if false is\ntrue (the premise), then even if a proposition, P, is \nfalse, false is true, so P is true (too)!\n-/\n\n/-\nA little practice. Which of the following propositions\nin predicate logic is true?\n-/\n\ndef p1 : Prop := false \u2192 false\ndef p2 : Prop := false \u2192 true\ndef p3 : Prop := true \u2192 true\ndef p4 : Prop := true \u2192 false\ndef p5 : Prop := false \u2192 2 = 3\ndef p6 : Prop := false \u2192 0 = 0\ndef p7 : Prop := \u2200 (P : Prop), true \u2192 P\ndef p8 : Prop := \u2200 (P : Prop), false \u2192 P \n\ntheorem p8_is_true : p8 := \nbegin\nunfold p8,\nassume P,\nassume f,\napply false.elim f,\nend \n\n/-\nFor each proposition, state whether it's true or false\nthen give a proof of it (in English). Here are some formal\nproofs to help.\n-/\n\n-- def p1 : Prop := false \u2192 false\ntheorem x : p1 := \nbegin\n  unfold p1,\n  assume f : false,\n  exact f,\nend\n\n-- false \u2192 true\nexample : p2 := \nbegin\n  unfold p2,\n  assume f,           -- move premise into context\n  --exact true.intro,   -- don't have to use assumption\n  -- apply false.elim f,\n  contradiction,\nend\n\nexample : p3 := \nbegin\nunfold p3,\nassume t,\nexact t,    -- exact true.intro also works\nend\n\nexample : p4 := \nbegin\nunfold p4,\nassume t,\nend\n\nexample : p5 := \nbegin\nunfold p5,\nassume f,\ncases f,\nend\n\nexample : p6 := \nbegin\nunfold p6,\nassume f,\ncases f,\n-- exact rfl,\nend\n/-\nWhat? The cases tactic applies the elimination rule to\nan assumed or derived proof of false. For each of the \nways that the proof, f, could have been constructed,\nyou have a case to consider; but there are no ways a\nproof of false can be constructed so you have no cases\nto consider, so the proof is done! This is another way\nto understand how/why false elimination works in the\nconstructive logic of Lean and other similar tools. \n-/\n\nexample : p7 := \nbegin\nunfold p7,\nintro P,\nassume t,\n-- stuck\nend\n\nexample : p8 := \nbegin\nunfold p8,\nassume P f,\ncases f,\nend\n\n/- *** NOT *** -/\n\n\n-- \u00ac \n/-\nWith an understanding of \"false\" and its elimination rule, we\ncan now talk about the inference rules for negation. \n-/\n\n/-\nRecall that if P is any proposition, then (not P), generally \nwritten as \u00acP, is also a proposition. when is \u00acP true? It's\ntrue in first-order logic if P is false. It's also true in\nconstructive logic when P is false, which is to say, *when \nthere is no proof of P*. \n\nNow here's the slightly tricky way that we show that there can\nbe no proof of P. We show (P \u2192 false). What this proposition\nsays is that \"If there is a proof of P, then from it we can\nderive a proof of false.\" But a proof of false doesn't exist,\nso if we prove (P \u2192 false) is true then there must be no proof\nof P. In other words, to prove there is no proof of P, we prove\nP \u2192 false! And that leads to our definition of \u00acP. What it means\nis *exactly* P \u2192 false. \n-/\ndef not_ (X : Prop) := X \u2192 false  -- the definition of \"not\" (\u00ac)\n\n/-\nExamples\n-/\n\nexample : 0 = 1 \u2192 false :=\nbegin\nassume h,   -- suppose 0 = 1\ncases h,    -- that can't happen, no cases, we've proved \u00ac(0=1)\nend \n\nexample : \u00ac(0 = 1) :=\nbegin \nassume h,\ncases h,\n/-\nRemember!!!  0 \u2260 1 means \u00ac(0 = 1) means 0 = 1 \u2192 false. You \nmust remember that when you want to prove \u00acP, that means you\nneed to prove P \u2192 false: that a proof of P is a contradiction.  \nto remember this, because it tells you how to prove it. To\nshow it, assume the premise, 0 = 1, then show that in this\ncontext, there is a contradiction ---given our intuitive\ngrasp of equality and the natural numbers. \n\nIf you can derive a contradiction, that is tantamount to a \nproof of false, and from a proof of false, f, the truth of\nany other proposition follows. Put another way, in terms of\nLean's formal logic, the term, (false.elim f), where f is a\nproof of false, serves is a formal proof of any proposition.\n-/\nend\n\n/- PROOF BY NEGATION \n\nWhat we have now seen is a crucial \"proof strategy\" often \ncalled proof by negation. To show \u00acP, that the statement, \nP is false, is true, prove P \u2192 false. First assume that \nP is true (you have a proof of it) and show that in this\ncontext, you can derive a proof of false. You will often\ndo this by producing a contradiction, which is proofs of\nboth X and \u00acX for some proposition, from which, as we will\nsee shortly, you can derive a proof of false by applying\nthe rule of arrow elimination (function application!).  \n-/\n\n/-\nHW #3 Exercise: state and prove the rule (the \"theorem\") \nof \"no contradiction:\" first in English and then in the\npredicate logic of Lean. Or if you prefer, work it out \nin Lean and the write it in English. The formal statement\nof the proposition is in the partially completed theorem \nbelow. \n-/\n\ntheorem no_contra : \u00ac(X \u2227 \u00acX) :=\nbegin\nend\n\n/-\nHint: The proof uses arrow introduction (you have to prove an\nimplication), \"and\" elimination (you need separate proofs of X\nand \u00acX; try using cases in Lean), and arrow elimination (you\nneed to *use* these proofs, one of which, remember, is a proof\nof an implication; so what can you do with that?). \n-/\n\n\n/- COMING SOON -/\n\n\ndef excluded_middle   := X \u2228 \u00acX   -- not an axiom in CL\ndef neg_elim          := \u00ac\u00acX \u2192 X  -- depends on axiom of e.m.\n\n\n\n\n/- Under Construction -/\n\n/-\nAnd for this explanation, we need to be precise about what it means\nto be a predicate in predicate logic. As we've exaplained before, \na predicate is a proposition with one or more parameters. Think of\nparameters as blanks in the reading of a proposition that you can\nfill in with any value of the right type for that slot. When you \nfill in all the blanks, which you do by by applying the predicate\nto actual parameter values, you get back a proposition: a specific\nstatement about specific objects with no remaining parameters to\nbe filled in. A predicate thus gives rise to a whole *family* of \npropositions, one for each possible combination of argument values. \nOnce all the parameters in a predicate are fixed to actual values,\nyou've no longer got a predicate but just a proposition. \n-/\n\n\n-- \u2203\ndef exists_intro := \u2200 {P : X \u2192 Prop} (w : X), P w \u2192 (\u2203 (x : X), P x) \ndef exists_elim := \u2200 {P : X \u2192 Prop}, (\u2203 (x : X), P x) \u2192 (\u2200 (x : X), P x \u2192 Y) \u2192 Y \n\n/-\nThat's it for the fundamental rules of higher-order predicate\nlogic. The constructive logic versions of the remaining inference\nrules we saw in propositional logic are actually theorems, which\nmeans that they can be proved using only the fundamental rules,\nwhich we accept as axioms. An axiom is a proposition accepted as\ntrue without a proof. The inference rules of a logic are accepted\nas axioms. The truth of any other proposition in predicate logic\n(the foundation for most of mathematics) is proved by applying \nfundamental axioms and previously proved theorems..  \n-/\n\n-- theorems\ndef arrow_trans       := (X \u2192 Y) \u2192 (Y \u2192 Z) \u2192 (X \u2192 Z)\ndef contrapostitive   := (X \u2192 Y) \u2192 (\u00acY \u2192 \u00acX)\ndef demorgan1         := \u00ac(X \u2228 Y) \u2194 \u00acX \u2227 \u00acY\ndef demorgan2         := \u00ac(X \u2227 Y) \u2194 \u00acX \u2228 \u00acY\ndef no_contradiction  := \u00ac(X \u2227 \u00acX)\n\n\n/-\nHere are the logical fallacies we first met in propositional\nlogic, now presented in the much richer context of constructive\nlogic. You might guess that it will be impossible to construct\nproofs of these fallacies, and you would be correct, as we will\nsee going forward.\n-/\n-- fallacies\ndef converse          := (X \u2192 Y) \u2192 (Y \u2192 X)\ndef deny_antecedent   := (X \u2192 Y) \u2192 \u00acX \u2192  \u00acY\ndef affirm_conclusion := (X \u2192 Y) \u2192 (Y \u2192 X)\ndef affirm_disjunct   := X \u2228 Y \u2192 (X \u2192 \u00acY)\n\nend pred_logic", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/02_Predicate_Logic/00_Introduction/99_obsolete_09_20_22_inference_rules.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.8152324871074607, "lm_q1q2_score": 0.7219955416787944}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport computability.DFA\nimport data.set.functor\n\n/-!\n# Nondeterministic Finite Automata\nThis file contains the definition of a Nondeterministic Finite Automaton (NFA), a state machine\nwhich determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular\nset by evaluating the string over every possible path.\nWe show that DFA's are equivalent to NFA's however the construction from NFA to DFA uses an\nexponential number of states.\nNote that this definition allows for Automaton with infinite states, a `fintype` instance must be\nsupplied for true NFA's.\n-/\n\nopen set\n\nuniverses u v\n\n/-- An NFA is a set of states (`\u03c3`), a transition function from state to state labelled by the\n  alphabet (`step`), a starting state (`start`) and a set of acceptance states (`accept`).\n  Note the transition function sends a state to a `set` of states. These are the states that it\n  may be sent to. -/\nstructure NFA (\u03b1 : Type u) (\u03c3 : Type v) :=\n(step : \u03c3 \u2192 \u03b1 \u2192 set \u03c3)\n(start : set \u03c3)\n(accept : set \u03c3)\n\nvariables {\u03b1 : Type u} {\u03c3 \u03c3' : Type v} (M : NFA \u03b1 \u03c3)\n\nnamespace NFA\n\ninstance : inhabited (NFA \u03b1 \u03c3) := \u27e8 NFA.mk (\u03bb _ _, \u2205) \u2205 \u2205 \u27e9\n\n/-- `M.step_set S a` is the union of `M.step s a` for all `s \u2208 S`. -/\ndef step_set (S : set \u03c3) (a : \u03b1) : set \u03c3 := \u22c3 s \u2208 S, M.step s a\n\n\n\n@[simp] lemma step_set_empty (a : \u03b1) : M.step_set \u2205 a = \u2205 :=\nby simp_rw [step_set, Union_false, Union_empty]\n\n/-- `M.eval_from S x` computes all possible paths though `M` with input `x` starting at an element\n  of `S`. -/\ndef eval_from (start : set \u03c3) : list \u03b1 \u2192 set \u03c3 :=\nlist.foldl M.step_set start\n\n@[simp] lemma eval_from_nil (S : set \u03c3) : M.eval_from S [] = S := rfl\n@[simp] lemma eval_from_singleton (S : set \u03c3) (a : \u03b1) : M.eval_from S [a] = M.step_set S a := rfl\n@[simp] lemma eval_from_append_singleton (S : set \u03c3) (x : list \u03b1) (a : \u03b1) :\n  M.eval_from S (x ++ [a]) = M.step_set (M.eval_from S x) a :=\nby simp only [eval_from, list.foldl_append, list.foldl_cons, list.foldl_nil]\n\n/-- `M.eval x` computes all possible paths though `M` with input `x` starting at an element of\n  `M.start`. -/\ndef eval : list \u03b1 \u2192 set \u03c3 := M.eval_from M.start\n\n@[simp] lemma eval_nil : M.eval [] = M.start := rfl\n@[simp] lemma eval_singleton (a : \u03b1) : M.eval [a] = M.step_set M.start a := rfl\n@[simp] lemma eval_append_singleton (x : list \u03b1) (a : \u03b1) :\n  M.eval (x ++ [a]) = M.step_set (M.eval x) a :=\neval_from_append_singleton _ _ _ _\n\n/-- `M.accepts` is the language of `x` such that there is an accept state in `M.eval x`. -/\ndef accepts : language \u03b1 :=\n\u03bb x, \u2203 S \u2208 M.accept, S \u2208 M.eval x\n\n/-- `M.to_DFA` is an `DFA` constructed from a `NFA` `M` using the subset construction. The\n  states is the type of `set`s of `M.state` and the step function is `M.step_set`. -/\ndef to_DFA : DFA \u03b1 (set \u03c3) :=\n{ step := M.step_set,\n  start := M.start,\n  accept := {S | \u2203 s \u2208 S, s \u2208 M.accept} }\n\n@[simp] lemma to_DFA_correct :\n  M.to_DFA.accepts = M.accepts :=\nbegin\n  ext x,\n  rw [accepts, DFA.accepts, eval, DFA.eval],\n  change list.foldl _ _ _ \u2208 {S | _} \u2194 _,\n  split; { exact \u03bb \u27e8w, h2, h3\u27e9, \u27e8w, h3, h2\u27e9 },\nend\n\nlemma pumping_lemma [fintype \u03c3] {x : list \u03b1} (hx : x \u2208 M.accepts)\n  (hlen : fintype.card (set \u03c3) \u2264 list.length x) :\n  \u2203 a b c, x = a ++ b ++ c \u2227 a.length + b.length \u2264 fintype.card (set \u03c3) \u2227 b \u2260 [] \u2227\n  {a} * language.star {b} * {c} \u2264 M.accepts :=\nbegin\n  rw \u2190to_DFA_correct at hx \u22a2,\n  exact M.to_DFA.pumping_lemma hx hlen\nend\n\nend NFA\n\nnamespace DFA\n\n/-- `M.to_NFA` is an `NFA` constructed from a `DFA` `M` by using the same start and accept\n  states and a transition function which sends `s` with input `a` to the singleton `M.step s a`. -/\ndef to_NFA (M : DFA \u03b1 \u03c3') : NFA \u03b1 \u03c3' :=\n{ step := \u03bb s a, {M.step s a},\n  start := {M.start},\n  accept := M.accept }\n\n@[simp] lemma to_NFA_eval_from_match (M : DFA \u03b1 \u03c3) (start : \u03c3) (s : list \u03b1) :\n  M.to_NFA.eval_from {start} s = {M.eval_from start s} :=\nbegin\n  change list.foldl M.to_NFA.step_set {start} s = {list.foldl M.step start s},\n  induction s with a s ih generalizing start,\n  { tauto },\n  { rw [list.foldl, list.foldl,\n        show M.to_NFA.step_set {start} a = {M.step start a}, by simpa [NFA.step_set]],\n    tauto }\nend\n\n@[simp] lemma to_NFA_correct (M : DFA \u03b1 \u03c3) :\n  M.to_NFA.accepts = M.accepts :=\nbegin\n  ext x,\n  change (\u2203 S H, S \u2208 M.to_NFA.eval_from {M.start} x) \u2194 _,\n  rw to_NFA_eval_from_match,\n  split,\n  { rintro \u27e8 S, hS\u2081, hS\u2082 \u27e9,\n    rwa set.mem_singleton_iff.mp hS\u2082 at hS\u2081 },\n  { exact \u03bb h, \u27e8M.eval x, h, rfl\u27e9 }\nend\n\nend DFA\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/computability/NFA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7219103307887988}}
{"text": "import tactic \nimport tactic.induction\n\nnamespace pred_logic \n\nuniverse u\n\nstructure language (\u03b1 \u03b2 : Type u) :=\n(h\u03b1\u03b2 : \u03b1 \u2260 \u03b2)\n(rel_symbols : set \u03b1)\n(func_symbols : set \u03b2)\n(rel_arity : \u03b1 \u2192 \u2115)\n(func_arity : \u03b2 \u2192 \u2115)\n\ninductive term {\u03b1 \u03b2 : Type u} (\ud835\udcdb : language \u03b1 \u03b2)\n| var : \u2115 \u2192 term \n| func {f : \u03b2} (f \u2208 \ud835\udcdb.func_symbols) : (fin (\ud835\udcdb.func_arity f) \u2192 term) \u2192 term\n\ninductive formula {\u03b1 \u03b2 : Type u} (\ud835\udcdb : language \u03b1 \u03b2)\n| bot : formula\n| relation {R : \u03b1} (R \u2208 \ud835\udcdb.rel_symbols) : (fin (\ud835\udcdb.rel_arity R) \u2192 term \ud835\udcdb) \u2192 formula\n| Exists : \u2115 \u2192 formula \u2192 formula \n| imp : formula \u2192 formula \u2192 formula\n\nvariables {\u03b1 \u03b2 : Type u} {\ud835\udcdb : language \u03b1 \u03b2}\n\ndef term_vars : term \ud835\udcdb \u2192 \u2115 \u2192 Prop \n| (term.var m) n := m = n \n| (term.func f hf terms) n := \u2203m : (fin (\ud835\udcdb.func_arity f)), term_vars (terms m) n\n\ndef free_vars : formula \ud835\udcdb  \u2192 \u2115 \u2192 Prop\n| formula.bot m := false\n| (formula.Exists n \u03c6) m := m \u2260 n \u2227 free_vars \u03c6 m\n| (formula.imp \u03c6 \u03c8) m := free_vars \u03c6 m \u2228 free_vars \u03c8 m\n| (formula.relation R hR terms) m := \u2203n : (fin (\ud835\udcdb.rel_arity R)), term_vars (terms n) m\n\nstructure interpretation (\ud835\udcdb : language \u03b1 \u03b2) :=\n(domain : Type)\n(to_func : \u2200{f}, f \u2208 \ud835\udcdb.func_symbols \u2192 (fin (\ud835\udcdb.func_arity f) \u2192 domain) \u2192 domain)\n(to_rel : \u2200{R}, R \u2208 \ud835\udcdb.rel_symbols \u2192 (fin (\ud835\udcdb.rel_arity R) \u2192 domain) \u2192 Prop)\n\nvariable {M : interpretation \ud835\udcdb}\n\ndef assignment (M : interpretation \ud835\udcdb) := \u2115 \u2192 M.domain\n\ndef replace (s : assignment M) (n : \u2115) (m : M.domain) : assignment M :=\n\u03bbk, if k = n then m else s k\n\nlemma replace_pos {s : assignment M} {n : \u2115} {m : M.domain}\n: replace s n m n = m := if_pos rfl\n\nlemma replace_neg {s : assignment M} {n : \u2115} {m : M.domain} {k : \u2115}\n: k \u2260 n \u2192 replace s n m k = s k := \u03bbhk, if_neg hk\n\ndef value (s : assignment M) : term \ud835\udcdb \u2192 M.domain\n| (term.var n) := s n\n| (term.func f hf terms) := let v := \u03bbk, value (terms k) in M.to_func hf v\n\ndef satisfies : assignment M \u2192  formula \ud835\udcdb \u2192 Prop\n| s (formula.bot) := false\n| s (formula.relation R hR terms) := M.to_rel hR (value s \u2218 terms)\n| s (formula.imp \u03c6 \u03c8) := satisfies s \u03c6 \u2192 satisfies s \u03c8\n| s (formula.Exists n \u03c6) := \u2203(m : M.domain), satisfies (replace s n m) \u03c6\n\nexample {s s' : assignment M} {u : term \ud835\udcdb} :\n(\u2200n, term_vars u n \u2192 s n = s' n) \u2192 value s u = value s' u :=\nbegin \n\tintro h,\n\tinduction' u with u f g g_func g_args ih,\n\t{exact h u rfl},\n\t{\n\t\tunfold value,\n\t\tsimp,\n\t\tapply congr_arg,\n\t\tsorry,\n\t},\nend\n\nlemma satisfies_of_agree_free {s s' : assignment M} (\u03c6 : formula \ud835\udcdb) : \n(\u2200{n}, free_vars \u03c6 n \u2192 s n = s' n) \u2192 satisfies s \u03c6 \u2192 satisfies s' \u03c6 :=\nbegin \n\tintros agree_free hs\u03c6,\n\tinduction' \u03c6,\n\t{exfalso,exact hs\u03c6},\n\t{\n\t\tunfold satisfies at *,\n\t\tsorry,\n\t}, repeat {sorry},\nend\n\nend pred_logic", "meta": {"author": "duduFreire", "repo": "formal_logic", "sha": "d7977f4bc03267b56c2a694595c4654eaef84f42", "save_path": "github-repos/lean/duduFreire-formal_logic", "path": "github-repos/lean/duduFreire-formal_logic/formal_logic-d7977f4bc03267b56c2a694595c4654eaef84f42/src/pred_logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.721910315605653}}
{"text": "import data.set\nnoncomputable theory\nlocal attribute [instance] classical.prop_decidable\nuniverse u\nnamespace add_comm_group\n\n\nclass is_add_subgroup {M : Type u} [add_comm_group M] (N : set M) : Prop :=\n(zero : (0:M) \u2208 N)\n(add  : \u2200 {x y:M}, x \u2208 N \u2192 y \u2208 N \u2192 x + y \u2208 N)\n(neg : \u2200 {x:M}, x \u2208 N \u2192 -x \u2208 N)\n\nvariables {M : Type u} (N : set M)\nvariables [add_comm_group M] [HMN : is_add_subgroup N]\ninclude N HMN\n\n@[reducible] def add_quot_group_reln (x y : M) := x - y \u2208 N\n\n--variables (M : Type*) [add_comm_group M] (N : set M) [is_add_subgroup N]\n\ndef add_group_setoid  \n  : setoid M :=\n{ r:= \u03bb x y, x - y \u2208 N,\n  iseqv := \u27e8\u03bb x,by simp [is_add_subgroup.zero],\n            \u03bb x y Hxy,\n              have -(x-y) \u2208 N:=is_add_subgroup.neg Hxy,\n              by simpa using this,\n            \u03bb x y z Hxy Hyz,\n              have (x-y)+(y-z) \u2208 N := is_add_subgroup.add Hxy Hyz,\n              by simpa using this\u27e9\n}\n\nlocal attribute [instance] add_group_setoid\n\nlemma quotient_rel_eq {a b : M}\n-- (M : Type*) [add_comm_group M] (N : set M) [is_add_subgroup N] {a b : M} \n: (a \u2248 b) = (a - b \u2208 N) := rfl\n\n#check add_group_setoid \n--@[reducible] def add_quot_group (M : Type u) [add_comm_group M] (N : set M) [is_add_subgroup N] := quot (add_quot_group_reln M N)\nsection\nvariable (M)\n@[reducible] def add_quot_group \n--(M : Type u) [add_comm_group M] (N : set M) [is_add_subgroup N] \n:= quotient (add_group_setoid N)\nend \n\n#check add_quot_group \n\nlocal notation ` Qu ` := add_quot_group M N \n\ninstance quotient_has_zero : has_zero (Qu) := \u27e8\u27e60\u27e7\u27e9--\u27e6 ]]\n\ninstance quotient_has_add : has_add (Qu) := \u27e8\n    quot.lift (\u03bb m\u2081 : M,\n      quot.lift (\u03bb m\u2082 : M, quot.mk setoid.r (m\u2081 + m\u2082)) \n      ( begin\n          intros a b HabN,\n          apply quot.sound,\n          show ((m\u2081 + a) - (m\u2081 + b) \u2208 N),\n          suffices : a + -b \u2208 N,by simp [this],\n          rw [\u2190sub_eq_add_neg],\n          exact HabN,\n        end)\n    )\n    ( begin\n        intros a b HabN,\n        funext q,\n        apply congr_fun,\n        suffices : (\u03bb (m\u2082 : M), quot.mk setoid.r (a + m\u2082)) = (\u03bb (m\u2082 : M), quot.mk setoid.r (b + m\u2082)),\n          simp [this],\n        funext m,\n        apply quot.sound,\n        show (a+m) - (b+m) \u2208 N,\n        suffices : a + -b \u2208 N,by simp [this],\n        rw [\u2190sub_eq_add_neg],\n        exact HabN\n      end )\n  \u27e9\n    \ninstance quotient_has_neg : has_neg (Qu) := \u27e8quot.lift (\u03bb m : M, quot.mk setoid.r (-m)) (begin\n      intros a b HabN,\n      apply quot.sound,\n      show (-a - (-b) \u2208  N),\n      have H : -(a-b) \u2208 N := is_add_subgroup.neg HabN,\n      have H2 : -a - -b = -(a-b) := by simp,\n      rwa [H2],\n    end)\u27e9\n\ntheorem quot_map_add \n--(M : Type u) [add_comm_group M] (N : set M) [is_add_subgroup N] \n(a b : M) :\n  \u27e6a+b\u27e7 = \u27e6a\u27e7 + \u27e6b\u27e7 := \nbegin\n  apply quot.sound,\n  unfold setoid.r add_quot_group_reln,\n  simp [is_add_subgroup.zero],\nend \n\ninstance add_quot_group_is_group \n  : add_comm_group (Qu) :=\n  { add := (+),\n    add_assoc := begin\n      refine quot.ind _,\n      intro a,\n      refine quot.ind _,\n      intro b,\n      refine quot.ind _,\n      intro c,\n--      dunfold add_quot_group_add,\n      show \u27e6a + b + c\u27e7 = \u27e6a + (b + c)\u27e7,\n      rw [add_assoc],\n      refl,\n    end,\n    zero := (0),\n    zero_add := begin\n      refine quot.ind _,\n      intro a,\n      apply quot.sound,\n      unfold setoid.r add_quot_group_reln,\n      simp [sub_self],\n      exact is_add_subgroup.zero _,\n    end,\n    add_zero := begin\n      refine quot.ind _,\n      intro a,\n      apply quot.sound,\n      unfold setoid.r add_quot_group_reln,\n      simp [sub_self],\n      exact is_add_subgroup.zero _,\n    end,\n    neg := has_neg.neg,\n    add_left_neg := begin\n      refine quot.ind _,\n      intro a,\n      apply quot.sound,\n      rw neg_add_self,\n      unfold setoid.r add_quot_group_reln,\n      rw sub_self,\n      exact is_add_subgroup.zero _,\n    end,\n    add_comm := begin\n      refine quot.ind _,\n      intro a,\n      refine quot.ind _,\n      intro b,\n      show \u27e6a\u27e7 + \u27e6b\u27e7 = \u27e6b\u27e7 + \u27e6a\u27e7, \n      rw [eq.symm (quot_map_add N a b)],\n      rw [eq.symm (quot_map_add N b a)],\n      rw [add_comm]\n    end,\n  }\n\nlemma quot_map_zero : \u27e60\u27e7 = (0:Qu) := rfl\n\n--set_option trace.class_instances true\n\nlemma quot_map_neg (a : M) : \n--(M : Type u) [add_comm_group M] (N : set M) [is_add_subgroup N] (a : M) :\n  \u27e6-a\u27e7 = -\u27e6a\u27e7 := --@add_comm_group.neg _ H ((quot.mk r a):(add_quot_group M N)) :=  \n--  quot.mk r (-a) = -((quot.mk r a):(add_quot_group M N)) := \n  begin\n--  simp,\n  apply eq_neg_of_add_eq_zero,\n  rw [eq.symm (quot_map_add N _ _)],\n  rw [neg_add_eq_sub,sub_self],\n  exact quot_map_zero _,\nend \n\ndef subgroup_to_quot_subgroup (I : set M)\n  : set (Qu) :=\n  set.image (\u03bb b, \u27e6b\u27e7) I\n\ninstance image_of_subgroup_is_subgroup \n--{M : Type*} [add_comm_group M] {N : set M} [is_add_subgroup N] \n(I : set M) [is_add_subgroup I]\n  : is_add_subgroup (subgroup_to_quot_subgroup N I) := \n{ zero := begin\n    existsi (0:M),\n    split,\n    { exact is_add_subgroup.zero I },\n    { exact quot_map_zero N\n    },\n  end,\n  add := begin\n    intros x y Hx Hy,\n    cases Hx with a Ha,\n    cases Hy with b Hb,\n    existsi (a+b),\n    split,\n    { exact is_add_subgroup.add Ha.1 Hb.1 },\n    { rw \u2190Ha.2,rw \u2190Hb.2,\n      exact quot_map_add N a b },\n  end,\n  neg := begin\n    intros x Hx,\n    cases Hx with a Ha,\n    existsi (-a),\n    split,\n    { exact is_add_subgroup.neg Ha.1},\n    { rw \u2190Ha.2,\n      exact quot_map_neg _ _\n    }\n  end\n}\n\ndef quot_subgroup_to_subgroup\n --{M : Type*} [add_comm_group M] {N : set M} [is_add_subgroup N] \n (Ibar : set (Qu))\n  [is_add_subgroup Ibar] : set M :=\n  set.preimage (\u03bb (x:M), (\u27e6x\u27e7:Qu)) Ibar\n--  set.preimage (quot.mk (add_quot_group_reln N)) Ibar\n\n--set_option pp.all true\ninstance preimage_of_subgroup_is_subgroup \n--{M : Type*} [add_comm_group M] {N : set M} [is_add_subgroup N] \n  (Ibar : set (Qu)) [is_add_subgroup Ibar] \n  : is_add_subgroup (quot_subgroup_to_subgroup N Ibar) := \n{\n  zero := begin\n    show (0:Qu) \u2208 Ibar,\n    exact is_add_subgroup.zero Ibar,\n  end,\n  add := begin\n    intros x y Hx Hy,\n    have Hx2 : \u27e6x\u27e7 \u2208 Ibar := Hx,\n    have Hy2 : \u27e6y\u27e7 \u2208 Ibar := Hy,\n    \n    show \u27e6x+y\u27e7 \u2208 Ibar,\n--    suffices : add_quot_group_add (quot.mk (add_quot_group_reln M N) x) (quot.mk (add_quot_group_reln M N) y) \u2208 Ibar,\n--      have H:quot.mk (add_quot_group_reln M N) (x + y) =\n--        add_quot_group_add (quot.mk (add_quot_group_reln M N) x) (quot.mk (add_quot_group_reln M N) y) := (quot_map_add M N x y),\n--      simp [this,H],\n--    show (quot.mk (add_quot_group_reln M N) x) + (quot.mk (add_quot_group_reln M N) y) \u2208 Ibar,\n    rw quot_map_add,\n    apply is_add_subgroup.add,\n      exact Hx,\n      exact Hy,\n  end,\n  neg := begin\n    intros x Hx,\n    show \u27e6-x\u27e7 \u2208 Ibar,\n    rw quot_map_neg,\n    apply is_add_subgroup.neg,\n    exact Hx,\n  end\n}\n\n#check @quotient.mk \n#check @setoid.r \n#check @quotient.exact\n#print notation \u27e6 \n--set_option pp.all true\ntheorem eq_preimage_of_image\n --{M : Type*} [add_comm_group M] {N : set M} [is_add_subgroup N] \n (I : set M) [is_add_subgroup I]\n  : N \u2286 I \u2192 quot_subgroup_to_subgroup N (subgroup_to_quot_subgroup N I) = I :=\nbegin\n  intro H,\n  apply set.eq_of_subset_of_subset,\n  { intros x Hx,\n    cases Hx with y H2,\n    have H3 : @setoid.r _ (add_group_setoid N) y x := \n      @quotient.exact _ (add_group_setoid N) _ _ H2.2,\n    have H4 : y-x \u2208 I := H H3,\n    have H5 : x = -(y-x) + y := by simp,\n    rw H5,\n    refine is_add_subgroup.add _ _,\n      refine is_add_subgroup.neg _,assumption,\n    exact H2.1\n  },\n  { intros x Hx,\n    show @quotient.mk M (add_group_setoid N) x \u2208 subgroup_to_quot_subgroup N I,\n    existsi x,\n    split,exact Hx,\n    refl\n  }\nend\n\n#check quot.exists_rep\n\ntheorem eq_image_of_preimage\n --{M : Type*} [add_comm_group M] {N : set M} [is_add_subgroup N] \n (Ibar : set Qu) [is_add_subgroup Ibar] :\n  subgroup_to_quot_subgroup N (quot_subgroup_to_subgroup N Ibar) = Ibar :=\nbegin\n  apply set.eq_of_subset_of_subset,\n  { intros xbar Hxbar,\n    cases Hxbar with y Hy,\n    rw [\u2190Hy.2],\n    exact Hy.1\n  },\n  { intros xbar Hxbar,\n    unfold subgroup_to_quot_subgroup,\n    unfold set.image,\n    have H := quot.exists_rep xbar,\n    cases H with a Ha,\n    existsi a,\n    split,\n    { show Ibar (quot.mk setoid.r a),\n      rw Ha,\n      exact Hxbar\n    },\n    { exact Ha,\n    },\n  }\nend\n\nend add_comm_group\n\nnamespace comm_ring\n\nclass is_ideal {R : Type*} [comm_ring R] (J : set R) : Prop :=\n(zero : (0:R) \u2208 J)\n(add  : \u2200 {x y}, x \u2208 J \u2192 y \u2208 J \u2192 x + y \u2208 J)\n(mul : \u2200 r x : R, x \u2208 J \u2192 r * x \u2208 J)\n\n-- now add\n-- structure ideal...\n\nend comm_ring\n/-\nSo it would be reasonable to have both definitions in a commutative algebra file?\nMario Carneiro\n@digama0\n21:55\nyes\nI would use is_ideal in the definition of ideal to avoid repeating myself\nKevin Buzzard\n@kbuzzard\n21:56\nOh! Great. but then don't I now have 100 questions about how to formulate 100 lemmas about ideals?\ni.e. which one to use?\nMario Carneiro\n@digama0\n21:56\nUse is_ideal when it makes sense, use ideal for the rest\n\n\n-/", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/xenalib/Atiyah_Macdonald.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7219103156056529}}
{"text": "import data.real.basic\n\n#check pow_two \n\nvariables (x y : \u211d)\n\n-- BEGIN\nexample (h : x^2 = 1) : x = 1 \u2228 x = -1 :=\nbegin\n  have h' : (x + 1) * (x - 1) = 0,\n  calc (x + 1) * (x - 1) = x^2 - 1 : by ring\n  ...                    = 1 - 1 : by rw h\n  ...                    = 0 : by norm_num,\n  have h'' : x + 1 = 0 \u2228 x - 1 = 0 := mul_eq_zero.mp h',\n    cases h'',\n    right,\n    exact add_eq_zero_iff_eq_neg.mp h'',\n    left,\n    exact sub_eq_zero.mp h'',\nend\n\nexample (h : x^2 = y^2) : x = y \u2228 x = -y :=\nbegin\n  have h' : (x + y) * (x - y) = 0,\n  calc (x + y) * (x - y) = x^2 - y^2 : by ring\n  ...                    = y^2 - y^2 : by rw h\n  ...                    = 0 : sub_self (y ^ 2),\n  have h'' : x + y = 0 \u2228 x - y = 0 := mul_eq_zero.mp h',\n    cases h'',\n    right,\n    exact add_eq_zero_iff_eq_neg.mp h'',\n    left,\n    exact sub_eq_zero.mp h'',\nend\n\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/6_left_right/ex6_pow_two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7219103100312837}}
{"text": "-- 1\ndef nandb : bool \u2192 bool \u2192 bool\n| tt tt := ff\n| a b := tt\n\ndef is_correct : (bool \u2192 bool \u2192 bool) \u2192 bool := \n\u03bb a, (a (ff) (ff) = tt) && (a (ff) (tt) = tt) && (a (tt) (ff) = tt) &&(a (tt) (tt) = ff)\n\ninductive naat: Type\n| zro : naat\n| suc : naat \u2192 naat\n\ndef is_even : naat \u2192 bool\n| naat.zro := tt\n| (naat.suc naat.zro) := ff\n| (naat.suc (naat.suc n)) := is_even n\n\ndef nat_add : naat \u2192 naat \u2192 naat\n| naat.zro x := x\n| (naat.suc a) b := naat.suc (nat_add a b)\n\ndef nat_double : naat \u2192 naat\n| naat.zro := naat.zro\n| (naat.suc n) := nat_add (naat.suc (naat.suc naat.zro)) (nat_double n)\n\ntheorem easy : \u2200 n : nat, 2 * (1 + n) = 2 + 2 * n :=\nbegin\nintro n,\nrewrite mul_add,\nrewrite mul_one,\nend \n\n\ndef nat_eq : naat \u2192 naat \u2192 bool\n| naat.zro naat.zro := tt\n| (naat.suc a) (naat.suc b) := nat_eq a b\n| _ _ := ff\n\ndef a_bigger_than_b : naat \u2192 naat \u2192 bool\n| naat.zro naat.zro := ff\n| naat.zro a := ff\n| a naat.zro := tt\n| (naat.suc a) (naat.suc b) := a_bigger_than_b a b\n\ndef factorial : \u2115 \u2192 \u2115\n| 0 := 1\n| (nat.succ n) := nat.succ n * factorial n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "SF-solns-zak", "sha": "7edc4424938e01a6ef4bb518fa8ec1757a2226b1", "save_path": "github-repos/lean/ImperialCollegeLondon-SF-solns-zak", "path": "github-repos/lean/ImperialCollegeLondon-SF-solns-zak/SF-solns-zak-7edc4424938e01a6ef4bb518fa8ec1757a2226b1/lean_answers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.72191030144264}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro\n-/\nimport data.prod.basic\nimport data.subtype\n\n/-!\n# Basic definitions about `\u2264` and `<`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves basic results about orders, provides extensive dot notation, defines useful order\nclasses and allows to transfer order instances.\n\n## Type synonyms\n\n* `order_dual \u03b1` : A type synonym reversing the meaning of all inequalities, with notation `\u03b1\u1d52\u1d48`.\n* `as_linear_order \u03b1`: A type synonym to promote `partial_order \u03b1` to `linear_order \u03b1` using\n  `is_total \u03b1 (\u2264)`.\n\n### Transfering orders\n\n- `order.preimage`, `preorder.lift`: Transfers a (pre)order on `\u03b2` to an order on `\u03b1`\n  using a function `f : \u03b1 \u2192 \u03b2`.\n- `partial_order.lift`, `linear_order.lift`: Transfers a partial (resp., linear) order on `\u03b2` to a\n  partial (resp., linear) order on `\u03b1` using an injective function `f`.\n\n### Extra class\n\n* `has_sup`: type class for the `\u2294` notation\n* `has_inf`: type class for the `\u2293` notation\n* `has_compl`: type class for the `\u1d9c` notation\n* `densely_ordered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such\n  that `a < c < b`.\n\n## Notes\n\n`\u2264` and `<` are highly favored over `\u2265` and `>` in mathlib. The reason is that we can formulate all\nlemmas using `\u2264`/`<`, and `rw` has trouble unifying `\u2264` and `\u2265`. Hence choosing one direction spares\nus useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.\n\nDot notation is particularly useful on `\u2264` (`has_le.le`) and `<` (`has_lt.lt`). To that end, we\nprovide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with\n`has_le.le.trans` and can be used to construct `hab.trans hbc : a \u2264 c` when `hab : a \u2264 b`,\n`hbc : b \u2264 c`, `lt_of_le_of_lt` is aliased as `has_le.le.trans_lt` and can be used to construct\n`hab.trans hbc : a < c` when `hab : a \u2264 b`, `hbc : b < c`.\n\n## TODO\n\n- expand module docs\n- automatic construction of dual definitions / theorems\n\n## Tags\n\npreorder, order, partial order, poset, linear order, chain\n-/\n\nopen function\n\nuniverses u v w\nvariables {\u03b9 : Type*} {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03c0 : \u03b9 \u2192 Type*} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nsection preorder\nvariables [preorder \u03b1] {a b c : \u03b1}\n\nlemma le_trans' : b \u2264 c \u2192 a \u2264 b \u2192 a \u2264 c := flip le_trans\nlemma lt_trans' : b < c \u2192 a < b \u2192 a < c := flip lt_trans\nlemma lt_of_le_of_lt' : b \u2264 c \u2192 a < b \u2192 a < c := flip lt_of_lt_of_le\nlemma lt_of_lt_of_le' : b < c \u2192 a \u2264 b \u2192 a < c := flip lt_of_le_of_lt\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] {a b : \u03b1}\n\nlemma ge_antisymm : a \u2264 b \u2192 b \u2264 a \u2192 b = a := flip le_antisymm\nlemma lt_of_le_of_ne' : a \u2264 b \u2192 b \u2260 a \u2192 a < b := \u03bb h\u2081 h\u2082, lt_of_le_of_ne h\u2081 h\u2082.symm\nlemma ne.lt_of_le : a \u2260 b \u2192 a \u2264 b \u2192 a < b := flip lt_of_le_of_ne\nlemma ne.lt_of_le' : b \u2260 a \u2192 a \u2264 b \u2192 a < b := flip lt_of_le_of_ne'\n\nend partial_order\n\nattribute [simp] le_refl\nattribute [ext] has_le\n\nalias le_trans        \u2190 has_le.le.trans\nalias le_trans'       \u2190 has_le.le.trans'\nalias lt_of_le_of_lt  \u2190 has_le.le.trans_lt\nalias lt_of_le_of_lt' \u2190 has_le.le.trans_lt'\nalias le_antisymm     \u2190 has_le.le.antisymm\nalias ge_antisymm     \u2190 has_le.le.antisymm'\nalias lt_of_le_of_ne  \u2190 has_le.le.lt_of_ne\nalias lt_of_le_of_ne' \u2190 has_le.le.lt_of_ne'\nalias lt_of_le_not_le \u2190 has_le.le.lt_of_not_le\nalias lt_or_eq_of_le  \u2190 has_le.le.lt_or_eq\nalias decidable.lt_or_eq_of_le \u2190 has_le.le.lt_or_eq_dec\n\nalias le_of_lt        \u2190 has_lt.lt.le\nalias lt_trans        \u2190 has_lt.lt.trans\nalias lt_trans'       \u2190 has_lt.lt.trans'\nalias lt_of_lt_of_le  \u2190 has_lt.lt.trans_le\nalias lt_of_lt_of_le' \u2190 has_lt.lt.trans_le'\nalias ne_of_lt        \u2190 has_lt.lt.ne\nalias lt_asymm        \u2190 has_lt.lt.asymm has_lt.lt.not_lt\n\nalias le_of_eq        \u2190 eq.le\n\nattribute [nolint decidable_classical] has_le.le.lt_or_eq_dec\n\nsection\nvariables [preorder \u03b1] {a b c : \u03b1}\n\n/-- A version of `le_refl` where the argument is implicit -/\nlemma le_rfl : a \u2264 a := le_refl a\n\n@[simp] lemma lt_self_iff_false (x : \u03b1) : x < x \u2194 false := \u27e8lt_irrefl x, false.elim\u27e9\n\nlemma le_of_le_of_eq (hab : a \u2264 b) (hbc : b = c) : a \u2264 c := hab.trans hbc.le\nlemma le_of_eq_of_le (hab : a = b) (hbc : b \u2264 c) : a \u2264 c := hab.le.trans hbc\nlemma lt_of_lt_of_eq (hab : a < b) (hbc : b = c) : a < c := hab.trans_le hbc.le\nlemma lt_of_eq_of_lt (hab : a = b) (hbc : b < c) : a < c := hab.le.trans_lt hbc\nlemma le_of_le_of_eq' : b \u2264 c \u2192 a = b \u2192 a \u2264 c := flip le_of_eq_of_le\nlemma le_of_eq_of_le' : b = c \u2192 a \u2264 b \u2192 a \u2264 c := flip le_of_le_of_eq\nlemma lt_of_lt_of_eq' : b < c \u2192 a = b \u2192 a < c := flip lt_of_eq_of_lt\nlemma lt_of_eq_of_lt' : b = c \u2192 a < b \u2192 a < c := flip lt_of_lt_of_eq\n\nalias le_of_le_of_eq  \u2190 has_le.le.trans_eq\nalias le_of_le_of_eq' \u2190 has_le.le.trans_eq'\nalias lt_of_lt_of_eq  \u2190 has_lt.lt.trans_eq\nalias lt_of_lt_of_eq' \u2190 has_lt.lt.trans_eq'\nalias le_of_eq_of_le  \u2190 eq.trans_le\nalias le_of_eq_of_le' \u2190 eq.trans_ge\nalias lt_of_eq_of_lt  \u2190 eq.trans_lt\nalias lt_of_eq_of_lt' \u2190 eq.trans_gt\n\nend\n\nnamespace eq\nvariables [preorder \u03b1] {x y z : \u03b1}\n\n/-- If `x = y` then `y \u2264 x`. Note: this lemma uses `y \u2264 x` instead of `x \u2265 y`, because `le` is used\nalmost exclusively in mathlib. -/\nprotected \n\nlemma not_lt (h : x = y) : \u00ac x < y := \u03bb h', h'.ne h\nlemma not_gt (h : x = y) : \u00ac y < x := h.symm.not_lt\n\nend eq\n\nnamespace has_le.le\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma ge [has_le \u03b1] {x y : \u03b1} (h : x \u2264 y) : y \u2265 x := h\n\nsection partial_order\nvariables [partial_order \u03b1] {a b : \u03b1}\n\nlemma lt_iff_ne (h : a \u2264 b) : a < b \u2194 a \u2260 b := \u27e8\u03bb h, h.ne, h.lt_of_ne\u27e9\nlemma gt_iff_ne (h : a \u2264 b) : a < b \u2194 b \u2260 a := \u27e8\u03bb h, h.ne.symm, h.lt_of_ne'\u27e9\nlemma not_lt_iff_eq (h : a \u2264 b) : \u00ac a < b \u2194 a = b := h.lt_iff_ne.not_left\nlemma not_gt_iff_eq (h : a \u2264 b) : \u00ac a < b \u2194 b = a := h.gt_iff_ne.not_left\n\nlemma le_iff_eq (h : a \u2264 b) : b \u2264 a \u2194 b = a := \u27e8\u03bb h', h'.antisymm h, eq.le\u27e9\nlemma ge_iff_eq (h : a \u2264 b) : b \u2264 a \u2194 a = b := \u27e8h.antisymm, eq.ge\u27e9\n\nend partial_order\n\nlemma lt_or_le [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a < c \u2228 c \u2264 b :=\n(lt_or_ge a c).imp id $ \u03bb hc, le_trans hc h\n\nlemma le_or_lt [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a \u2264 c \u2228 c < b :=\n(le_or_gt a c).imp id $ \u03bb hc, lt_of_lt_of_le hc h\n\nlemma le_or_le [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a \u2264 c \u2228 c \u2264 b :=\n(h.le_or_lt c).elim or.inl (\u03bb h, or.inr $ le_of_lt h)\n\nend has_le.le\n\nnamespace has_lt.lt\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma gt [has_lt \u03b1] {x y : \u03b1} (h : x < y) : y > x := h\nprotected lemma false [preorder \u03b1] {x : \u03b1} : x < x \u2192 false := lt_irrefl x\n\nlemma ne' [preorder \u03b1] {x y : \u03b1} (h : x < y) : y \u2260 x := h.ne.symm\n\nlemma lt_or_lt [linear_order \u03b1] {x y : \u03b1} (h : x < y) (z : \u03b1) : x < z \u2228 z < y :=\n(lt_or_ge z y).elim or.inr (\u03bb hz, or.inl $ h.trans_le hz)\n\nend has_lt.lt\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma ge.le [has_le \u03b1] {x y : \u03b1} (h : x \u2265 y) : y \u2264 x := h\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma gt.lt [has_lt \u03b1] {x y : \u03b1} (h : x > y) : y < x := h\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\ntheorem ge_of_eq [preorder \u03b1] {a b : \u03b1} (h : a = b) : a \u2265 b := h.ge\n\n@[simp, nolint ge_or_gt] -- see Note [nolint_ge]\nlemma ge_iff_le [has_le \u03b1] {a b : \u03b1} : a \u2265 b \u2194 b \u2264 a := iff.rfl\n@[simp, nolint ge_or_gt] -- see Note [nolint_ge]\nlemma gt_iff_lt [has_lt \u03b1] {a b : \u03b1} : a > b \u2194 b < a := iff.rfl\n\nlemma not_le_of_lt [preorder \u03b1] {a b : \u03b1} (h : a < b) : \u00ac b \u2264 a := (le_not_le_of_lt h).right\n\nalias not_le_of_lt \u2190 has_lt.lt.not_le\n\nlemma not_lt_of_le [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) : \u00ac b < a := \u03bb hba, hba.not_le h\n\nalias not_lt_of_le \u2190 has_le.le.not_lt\n\nlemma ne_of_not_le [preorder \u03b1] {a b : \u03b1} (h : \u00ac a \u2264 b) : a \u2260 b :=\n\u03bb hab, h (le_of_eq hab)\n\n-- See Note [decidable namespace]\nprotected lemma decidable.le_iff_eq_or_lt [partial_order \u03b1] [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} : a \u2264 b \u2194 a = b \u2228 a < b := decidable.le_iff_lt_or_eq.trans or.comm\n\nlemma le_iff_eq_or_lt [partial_order \u03b1] {a b : \u03b1} : a \u2264 b \u2194 a = b \u2228 a < b :=\nle_iff_lt_or_eq.trans or.comm\n\nlemma lt_iff_le_and_ne [partial_order \u03b1] {a b : \u03b1} : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\n\u27e8\u03bb h, \u27e8le_of_lt h, ne_of_lt h\u27e9, \u03bb \u27e8h1, h2\u27e9, h1.lt_of_ne h2\u27e9\n\nlemma eq_iff_not_lt_of_le {\u03b1} [partial_order \u03b1] {x y : \u03b1} : x \u2264 y \u2192 y = x \u2194 \u00ac x < y :=\nby rw [lt_iff_le_and_ne, not_and, not_not, eq_comm]\n\n-- See Note [decidable namespace]\nprotected lemma decidable.eq_iff_le_not_lt [partial_order \u03b1] [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 \u00ac a < b :=\n\u27e8\u03bb h, \u27e8h.le, h \u25b8 lt_irrefl _\u27e9, \u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.antisymm $\n  decidable.by_contradiction $ \u03bb h\u2083, h\u2082 (h\u2081.lt_of_not_le h\u2083)\u27e9\n\nlemma eq_iff_le_not_lt [partial_order \u03b1] {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 \u00ac a < b :=\nby haveI := classical.dec; exact decidable.eq_iff_le_not_lt\n\nlemma eq_or_lt_of_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2264 b) : a = b \u2228 a < b := h.lt_or_eq.symm\nlemma eq_or_gt_of_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2264 b) : b = a \u2228 a < b :=\nh.lt_or_eq.symm.imp eq.symm id\nlemma gt_or_eq_of_le [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) : a < b \u2228 b = a :=\n(eq_or_gt_of_le hab).symm\n\nalias decidable.eq_or_lt_of_le \u2190 has_le.le.eq_or_lt_dec\nalias eq_or_lt_of_le \u2190 has_le.le.eq_or_lt\nalias eq_or_gt_of_le \u2190 has_le.le.eq_or_gt\nalias gt_or_eq_of_le \u2190 has_le.le.gt_or_eq\n\nattribute [nolint decidable_classical] has_le.le.eq_or_lt_dec\n\nlemma eq_of_le_of_not_lt [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) (hba : \u00ac a < b) : a = b :=\nhab.eq_or_lt.resolve_right hba\n\nlemma eq_of_ge_of_not_gt [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) (hba : \u00ac a < b) : b = a :=\n(hab.eq_or_lt.resolve_right hba).symm\n\nalias eq_of_le_of_not_lt \u2190 has_le.le.eq_of_not_lt\nalias eq_of_ge_of_not_gt \u2190 has_le.le.eq_of_not_gt\n\nlemma ne.le_iff_lt [partial_order \u03b1] {a b : \u03b1} (h : a \u2260 b) : a \u2264 b \u2194 a < b :=\n\u27e8\u03bb h', lt_of_le_of_ne h' h, \u03bb h, h.le\u27e9\n\nlemma ne.not_le_or_not_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2260 b) : \u00ac a \u2264 b \u2228 \u00ac b \u2264 a :=\nnot_and_distrib.1 $ le_antisymm_iff.not.1 h\n\n-- See Note [decidable namespace]\nprotected lemma decidable.ne_iff_lt_iff_le [partial_order \u03b1] [decidable_eq \u03b1] {a b : \u03b1} :\n  (a \u2260 b \u2194 a < b) \u2194 a \u2264 b :=\n\u27e8\u03bb h, decidable.by_cases le_of_eq (le_of_lt \u2218 h.mp), \u03bb h, \u27e8lt_of_le_of_ne h, ne_of_lt\u27e9\u27e9\n\n@[simp] lemma ne_iff_lt_iff_le [partial_order \u03b1] {a b : \u03b1} : (a \u2260 b \u2194 a < b) \u2194 a \u2264 b :=\nby haveI := classical.dec; exact decidable.ne_iff_lt_iff_le\n\n-- Variant of `min_def` with the branches reversed.\nlemma min_def' [linear_order \u03b1] (a b : \u03b1) : min a b = if b \u2264 a then b else a :=\nbegin\n  rw [min_def],\n  rcases lt_trichotomy a b with lt | eq | gt,\n  { rw [if_pos lt.le, if_neg (not_le.mpr lt)], },\n  { rw [if_pos eq.le, if_pos eq.ge, eq], },\n  { rw [if_neg (not_le.mpr gt), if_pos gt.le], }\nend\n-- Variant of `min_def` with the branches reversed.\n-- This is sometimes useful as it used to be the default.\nlemma max_def' [linear_order \u03b1] (a b : \u03b1) : max a b = if b \u2264 a then a else b :=\nbegin\n  rw [max_def],\n  rcases lt_trichotomy a b with lt | eq | gt,\n  { rw [if_pos lt.le, if_neg (not_le.mpr lt)], },\n  { rw [if_pos eq.le, if_pos eq.ge, eq], },\n  { rw [if_neg (not_le.mpr gt), if_pos gt.le], }\nend\n\nlemma lt_of_not_le [linear_order \u03b1] {a b : \u03b1} (h : \u00ac b \u2264 a) : a < b :=\n((le_total _ _).resolve_right h).lt_of_not_le h\n\nlemma lt_iff_not_le [linear_order \u03b1] {x y : \u03b1} : x < y \u2194 \u00ac y \u2264 x := \u27e8not_le_of_lt, lt_of_not_le\u27e9\n\nlemma ne.lt_or_lt [linear_order \u03b1] {x y : \u03b1} (h : x \u2260 y) : x < y \u2228 y < x := lt_or_gt_of_ne h\n\n/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/\n@[simp] lemma lt_or_lt_iff_ne [linear_order \u03b1] {x y : \u03b1} : x < y \u2228 y < x \u2194 x \u2260 y :=\nne_iff_lt_or_gt.symm\n\nlemma not_lt_iff_eq_or_lt [linear_order \u03b1] {a b : \u03b1} : \u00ac a < b \u2194 a = b \u2228 b < a :=\nnot_lt.trans $ decidable.le_iff_eq_or_lt.trans $ or_congr eq_comm iff.rfl\n\nlemma exists_ge_of_linear [linear_order \u03b1] (a b : \u03b1) : \u2203 c, a \u2264 c \u2227 b \u2264 c :=\nmatch le_total a b with\n| or.inl h := \u27e8_, h, le_rfl\u27e9\n| or.inr h := \u27e8_, le_rfl, h\u27e9\nend\n\nlemma lt_imp_lt_of_le_imp_le {\u03b2} [linear_order \u03b1] [preorder \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2192 c \u2264 d) (h : d < c) : b < a :=\nlt_of_not_le $ \u03bb h', (H h').not_lt h\n\nlemma le_imp_le_iff_lt_imp_lt {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2} :\n  (a \u2264 b \u2192 c \u2264 d) \u2194 (d < c \u2192 b < a) :=\n\u27e8lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt\u27e9\n\nlemma lt_iff_lt_of_le_iff_le' {\u03b2} [preorder \u03b1] [preorder \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2194 c \u2264 d) (H' : b \u2264 a \u2194 d \u2264 c) : b < a \u2194 d < c :=\nlt_iff_le_not_le.trans $ (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm\n\nlemma lt_iff_lt_of_le_iff_le {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2194 c \u2264 d) : b < a \u2194 d < c :=\nnot_le.symm.trans $ (not_congr H).trans $ not_le\n\nlemma le_iff_le_iff_lt_iff_lt {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2} :\n  (a \u2264 b \u2194 c \u2264 d) \u2194 (b < a \u2194 d < c) :=\n\u27e8lt_iff_lt_of_le_iff_le, \u03bb H, not_lt.symm.trans $ (not_congr H).trans $ not_lt\u27e9\n\nlemma eq_of_forall_le_iff [partial_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c \u2264 a \u2194 c \u2264 b) : a = b :=\n((H _).1 le_rfl).antisymm ((H _).2 le_rfl)\n\nlemma le_of_forall_le [preorder \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c \u2264 a \u2192 c \u2264 b) : a \u2264 b :=\nH _ le_rfl\n\nlemma le_of_forall_le' [preorder \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a \u2264 c \u2192 b \u2264 c) : b \u2264 a :=\nH _ le_rfl\n\nlemma le_of_forall_lt [linear_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c < a \u2192 c < b) : a \u2264 b :=\nle_of_not_lt $ \u03bb h, lt_irrefl _ (H _ h)\n\nlemma forall_lt_iff_le [linear_order \u03b1] {a b : \u03b1} :\n  (\u2200 \u2983c\u2984, c < a \u2192 c < b) \u2194 a \u2264 b :=\n\u27e8le_of_forall_lt, \u03bb h c hca, lt_of_lt_of_le hca h\u27e9\n\nlemma le_of_forall_lt' [linear_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a < c \u2192 b < c) : b \u2264 a :=\nle_of_not_lt $ \u03bb h, lt_irrefl _ (H _ h)\n\nlemma forall_lt_iff_le' [linear_order \u03b1] {a b : \u03b1} :\n  (\u2200 \u2983c\u2984, a < c \u2192 b < c) \u2194 b \u2264 a :=\n\u27e8le_of_forall_lt', \u03bb h c hac, lt_of_le_of_lt h hac\u27e9\n\nlemma eq_of_forall_ge_iff [partial_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a \u2264 c \u2194 b \u2264 c) : a = b :=\n((H _).2 le_rfl).antisymm ((H _).1 le_rfl)\n\nlemma eq_of_forall_lt_iff [linear_order \u03b1] {a b : \u03b1} (h : \u2200 c, c < a \u2194 c < b) : a = b :=\n(le_of_forall_lt $ \u03bb _, (h _).1).antisymm $ le_of_forall_lt $ \u03bb _, (h _).2\n\nlemma eq_of_forall_gt_iff [linear_order \u03b1] {a b : \u03b1} (h : \u2200 c, a < c \u2194 b < c) : a = b :=\n(le_of_forall_lt' $ \u03bb _, (h _).2).antisymm $ le_of_forall_lt' $ \u03bb _, (h _).1\n\n/-- A symmetric relation implies two values are equal, when it implies they're less-equal.  -/\nlemma rel_imp_eq_of_rel_imp_le [partial_order \u03b2] (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_symm \u03b1 r] {f : \u03b1 \u2192 \u03b2}\n  (h : \u2200 a b, r a b \u2192 f a \u2264 f b) {a b : \u03b1} : r a b \u2192 f a = f b :=\n\u03bb hab, le_antisymm (h a b hab) (h b a $ symm hab)\n\n/-- monotonicity of `\u2264` with respect to `\u2192` -/\nlemma le_implies_le_of_le_of_le {a b c d : \u03b1} [preorder \u03b1] (hca : c \u2264 a) (hbd : b \u2264 d) :\n  a \u2264 b \u2192 c \u2264 d :=\n\u03bb hab, (hca.trans hab).trans hbd\n\nsection partial_order\nvariables [partial_order \u03b1]\n\n/-- To prove commutativity of a binary operation `\u25cb`, we only to check `a \u25cb b \u2264 b \u25cb a` for all `a`,\n`b`. -/\nlemma commutative_of_le {f : \u03b2 \u2192 \u03b2 \u2192 \u03b1} (comm : \u2200 a b, f a b \u2264 f b a) : \u2200 a b, f a b = f b a :=\n\u03bb a b, (comm _ _).antisymm $ comm _ _\n\n/-- To prove associativity of a commutative binary operation `\u25cb`, we only to check\n`(a \u25cb b) \u25cb c \u2264 a \u25cb (b \u25cb c)` for all `a`, `b`, `c`. -/\nlemma associative_of_commutative_of_le {f : \u03b1 \u2192 \u03b1 \u2192 \u03b1} (comm : commutative f)\n  (assoc : \u2200 a b c, f (f a b) c \u2264 f a (f b c)) :\n  associative f :=\n\u03bb a b c, le_antisymm (assoc _ _ _) $ by { rw [comm, comm b, comm _ c, comm a], exact assoc _ _ _ }\n\nend partial_order\n\n@[ext]\nlemma preorder.to_has_le_injective {\u03b1 : Type*} :\n  function.injective (@preorder.to_has_le \u03b1) :=\n\u03bb A B h, begin\n  cases A, cases B,\n  injection h with h_le,\n  have : A_lt = B_lt,\n  { funext a b,\n    dsimp [(\u2264)] at A_lt_iff_le_not_le B_lt_iff_le_not_le h_le,\n    simp [A_lt_iff_le_not_le, B_lt_iff_le_not_le, h_le], },\n  congr',\nend\n\n@[ext]\nlemma partial_order.to_preorder_injective {\u03b1 : Type*} :\n  function.injective (@partial_order.to_preorder \u03b1) :=\n\u03bb A B h, by { cases A, cases B, injection h, congr' }\n\n@[ext]\nlemma linear_order.to_partial_order_injective {\u03b1 : Type*} :\n  function.injective (@linear_order.to_partial_order \u03b1) :=\nbegin\n  intros A B h,\n  cases A, cases B, injection h,\n  obtain rfl : A_le = B_le := \u2039_\u203a, obtain rfl : A_lt = B_lt := \u2039_\u203a,\n  obtain rfl : A_decidable_le = B_decidable_le := subsingleton.elim _ _,\n  obtain rfl : A_max = B_max := A_max_def.trans B_max_def.symm,\n  obtain rfl : A_min = B_min := A_min_def.trans B_min_def.symm,\n  congr\nend\n\ntheorem preorder.ext {\u03b1} {A B : preorder \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\ntheorem partial_order.ext {\u03b1} {A B : partial_order \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\ntheorem linear_order.ext {\u03b1} {A B : linear_order \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\n/-- Given a relation `R` on `\u03b2` and a function `f : \u03b1 \u2192 \u03b2`, the preimage relation on `\u03b1` is defined\nby `x \u2264 y \u2194 f x \u2264 f y`. It is the unique relation on `\u03b1` making `f` a `rel_embedding` (assuming `f`\nis injective). -/\n@[simp] def order.preimage {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) (x y : \u03b1) : Prop := s (f x) (f y)\n\ninfix ` \u207b\u00b9'o `:80 := order.preimage\n\n/-- The preimage of a decidable order is decidable. -/\ninstance order.preimage.decidable {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) [H : decidable_rel s] :\n  decidable_rel (f \u207b\u00b9'o s) :=\n\u03bb x y, H _ _\n\n/-! ### Order dual -/\n\n/-- Type synonym to equip a type with the dual order: `\u2264` means `\u2265` and `<` means `>`. `\u03b1\u1d52\u1d48` is\nnotation for `order_dual \u03b1`. -/\ndef order_dual (\u03b1 : Type*) : Type* := \u03b1\n\nnotation \u03b1 `\u1d52\u1d48`:std.prec.max_plus := order_dual \u03b1\n\nnamespace order_dual\n\ninstance (\u03b1 : Type*) [h : nonempty \u03b1] : nonempty \u03b1\u1d52\u1d48 := h\ninstance (\u03b1 : Type*) [h : subsingleton \u03b1] : subsingleton \u03b1\u1d52\u1d48 := h\ninstance (\u03b1 : Type*) [has_le \u03b1] : has_le \u03b1\u1d52\u1d48 := \u27e8\u03bb x y : \u03b1, y \u2264 x\u27e9\ninstance (\u03b1 : Type*) [has_lt \u03b1] : has_lt \u03b1\u1d52\u1d48 := \u27e8\u03bb x y : \u03b1, y < x\u27e9\n\ninstance (\u03b1 : Type*) [preorder \u03b1] : preorder \u03b1\u1d52\u1d48 :=\n{ le_refl          := le_refl,\n  le_trans         := \u03bb a b c hab hbc, hbc.trans hab,\n  lt_iff_le_not_le := \u03bb _ _, lt_iff_le_not_le,\n  .. order_dual.has_le \u03b1,\n  .. order_dual.has_lt \u03b1 }\n\ninstance (\u03b1 : Type*) [partial_order \u03b1] : partial_order \u03b1\u1d52\u1d48 :=\n{ le_antisymm := \u03bb a b hab hba, @le_antisymm \u03b1 _ a b hba hab, .. order_dual.preorder \u03b1 }\n\ninstance (\u03b1 : Type*) [linear_order \u03b1] : linear_order \u03b1\u1d52\u1d48 :=\n{ le_total     := \u03bb a b : \u03b1, le_total b a,\n  decidable_le := (infer_instance : decidable_rel (\u03bb a b : \u03b1, b \u2264 a)),\n  decidable_lt := (infer_instance : decidable_rel (\u03bb a b : \u03b1, b < a)),\n  min := @max \u03b1 _,\n  max := @min \u03b1 _,\n  min_def := funext\u2082 $ @max_def' \u03b1 _,\n  max_def := funext\u2082 $ @min_def' \u03b1 _,\n  .. order_dual.partial_order \u03b1 }\n\ninstance : \u03a0 [inhabited \u03b1], inhabited \u03b1\u1d52\u1d48 := id\n\ntheorem preorder.dual_dual (\u03b1 : Type*) [H : preorder \u03b1] :\n  order_dual.preorder \u03b1\u1d52\u1d48 = H :=\npreorder.ext $ \u03bb _ _, iff.rfl\n\ntheorem partial_order.dual_dual (\u03b1 : Type*) [H : partial_order \u03b1] :\n  order_dual.partial_order \u03b1\u1d52\u1d48 = H :=\npartial_order.ext $ \u03bb _ _, iff.rfl\n\ntheorem linear_order.dual_dual (\u03b1 : Type*) [H : linear_order \u03b1] :\n  order_dual.linear_order \u03b1\u1d52\u1d48 = H :=\nlinear_order.ext $ \u03bb _ _, iff.rfl\n\nend order_dual\n\n/-! ### `has_compl` -/\n\n/-- Set / lattice complement -/\n@[notation_class] class has_compl (\u03b1 : Type*) := (compl : \u03b1 \u2192 \u03b1)\n\nexport has_compl (compl)\n\npostfix `\u1d9c`:(max+1) := compl\n\ninstance Prop.has_compl : has_compl Prop := \u27e8not\u27e9\n\ninstance pi.has_compl {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_compl (\u03b1 i)] :\n  has_compl (\u03a0 i, \u03b1 i) :=\n\u27e8\u03bb x i, (x i)\u1d9c\u27e9\n\nlemma pi.compl_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_compl (\u03b1 i)] (x : \u03a0 i, \u03b1 i) :\n  x\u1d9c = \u03bb i, (x i)\u1d9c := rfl\n\n@[simp]\nlemma pi.compl_apply {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_compl (\u03b1 i)] (x : \u03a0 i, \u03b1 i) (i : \u03b9)  :\n  x\u1d9c i = (x i)\u1d9c := rfl\n\ninstance is_irrefl.compl (r) [is_irrefl \u03b1 r] : is_refl \u03b1 r\u1d9c := \u27e8@irrefl \u03b1 r _\u27e9\ninstance is_refl.compl (r) [is_refl \u03b1 r] : is_irrefl \u03b1 r\u1d9c := \u27e8\u03bb a, not_not_intro (refl a)\u27e9\n\n/-! ### Order instances on the function space -/\n\ninstance pi.has_le {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_le (\u03b1 i)] : has_le (\u03a0 i, \u03b1 i) :=\n{ le       := \u03bb x y, \u2200 i, x i \u2264 y i }\n\nlemma pi.le_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_le (\u03b1 i)] {x y : \u03a0 i, \u03b1 i} :\n  x \u2264 y \u2194 \u2200 i, x i \u2264 y i :=\niff.rfl\n\ninstance pi.preorder {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] : preorder (\u03a0 i, \u03b1 i) :=\n{ le_refl  := \u03bb a i, le_refl (a i),\n  le_trans := \u03bb a b c h\u2081 h\u2082 i, le_trans (h\u2081 i) (h\u2082 i),\n  ..pi.has_le }\n\nlemma pi.lt_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] {x y : \u03a0 i, \u03b1 i} :\n  x < y \u2194 x \u2264 y \u2227 \u2203 i, x i < y i :=\nby simp [lt_iff_le_not_le, pi.le_def] {contextual := tt}\n\ninstance pi.partial_order [\u03a0 i, partial_order (\u03c0 i)] : partial_order (\u03a0 i, \u03c0 i) :=\n{ le_antisymm := \u03bb f g h1 h2, funext $ \u03bb b, (h1 b).antisymm (h2 b),\n  ..pi.preorder }\n\nsection pi\n\n/-- A function `a` is strongly less than a function `b`  if `a i < b i` for all `i`. -/\ndef strong_lt [\u03a0 i, has_lt (\u03c0 i)] (a b : \u03a0 i, \u03c0 i) : Prop := \u2200 i, a i < b i\n\nlocal infix ` \u227a `:50 := strong_lt\n\nvariables [\u03a0 i, preorder (\u03c0 i)] {a b c : \u03a0 i, \u03c0 i}\n\nlemma le_of_strong_lt (h : a \u227a b) : a \u2264 b := \u03bb i, (h _).le\n\nlemma lt_of_strong_lt [nonempty \u03b9] (h : a \u227a b) : a < b :=\nby { inhabit \u03b9, exact pi.lt_def.2 \u27e8le_of_strong_lt h, default, h _\u27e9 }\n\nlemma strong_lt_of_strong_lt_of_le (hab : a \u227a b) (hbc : b \u2264 c) : a \u227a c :=\n\u03bb i, (hab _).trans_le $ hbc _\n\nlemma strong_lt_of_le_of_strong_lt (hab : a \u2264 b) (hbc : b \u227a c) : a \u227a c :=\n\u03bb i, (hab _).trans_lt $ hbc _\n\nalias le_of_strong_lt \u2190 strong_lt.le\nalias lt_of_strong_lt \u2190 strong_lt.lt\nalias strong_lt_of_strong_lt_of_le \u2190 strong_lt.trans_le\nalias strong_lt_of_le_of_strong_lt \u2190 has_le.le.trans_strong_lt\n\nend pi\n\nsection function\nvariables [decidable_eq \u03b9] [\u03a0 i, preorder (\u03c0 i)] {x y : \u03a0 i, \u03c0 i} {i : \u03b9} {a b : \u03c0 i}\n\nlemma le_update_iff : x \u2264 function.update y i a \u2194 x i \u2264 a \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nfunction.forall_update_iff _ (\u03bb j z, x j \u2264 z)\n\nlemma update_le_iff : function.update x i a \u2264 y \u2194 a \u2264 y i \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nfunction.forall_update_iff _ (\u03bb j z, z \u2264 y j)\n\nlemma update_le_update_iff :\n  function.update x i a \u2264 function.update y i b \u2194 a \u2264 b \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nby simp [update_le_iff] {contextual := tt}\n\n@[simp] lemma le_update_self_iff : x \u2264 update x i a \u2194 x i \u2264 a := by simp [le_update_iff]\n@[simp] lemma update_le_self_iff : update x i a \u2264 x \u2194 a \u2264 x i := by simp [update_le_iff]\n@[simp] lemma lt_update_self_iff : x < update x i a \u2194 x i < a := by simp [lt_iff_le_not_le]\n@[simp] lemma update_lt_self_iff : update x i a < x \u2194 a < x i := by simp [lt_iff_le_not_le]\n\nend function\n\ninstance pi.has_sdiff {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_sdiff (\u03b1 i)] :\n  has_sdiff (\u03a0 i, \u03b1 i) :=\n\u27e8\u03bb x y i, x i \\ y i\u27e9\n\nlemma pi.sdiff_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_sdiff (\u03b1 i)] (x y : \u03a0 i, \u03b1 i) :\n  (x \\ y) = \u03bb i, x i \\ y i := rfl\n\n@[simp]\nlemma pi.sdiff_apply {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_sdiff (\u03b1 i)] (x y : \u03a0 i, \u03b1 i) (i : \u03b9) :\n  (x \\ y) i = x i \\ y i := rfl\n\nnamespace function\nvariables [preorder \u03b1] [nonempty \u03b2] {a b : \u03b1}\n\n@[simp] lemma const_le_const : const \u03b2 a \u2264 const \u03b2 b \u2194 a \u2264 b := by simp [pi.le_def]\n@[simp] lemma const_lt_const : const \u03b2 a < const \u03b2 b \u2194 a < b := by simpa [pi.lt_def] using le_of_lt\n\nend function\n\n/-! ### `min`/`max` recursors -/\n\nsection min_max_rec\n\nvariables [linear_order \u03b1] {p : \u03b1 \u2192 Prop} {x y : \u03b1}\n\nlemma min_rec (hx : x \u2264 y \u2192 p x) (hy : y \u2264 x \u2192 p y) : p (min x y) :=\n(le_total x y).rec (\u03bb h, (min_eq_left h).symm.subst (hx h))\n  (\u03bb h, (min_eq_right h).symm.subst (hy h))\n\nlemma max_rec (hx : y \u2264 x \u2192 p x) (hy : x \u2264 y \u2192 p y) : p (max x y) := @min_rec \u03b1\u1d52\u1d48 _ _ _ _ hx hy\nlemma min_rec' (p : \u03b1 \u2192 Prop) (hx : p x) (hy : p y) : p (min x y) := min_rec (\u03bb _, hx) (\u03bb _, hy)\nlemma max_rec' (p : \u03b1 \u2192 Prop) (hx : p x) (hy : p y) : p (max x y) := max_rec (\u03bb _, hx) (\u03bb _, hy)\n\nlemma min_def_lt (x y : \u03b1) : min x y = if x < y then x else y :=\nbegin\n  rw [min_comm, min_def, \u2190 ite_not],\n  simp only [not_le],\nend\n\nlemma max_def_lt (x y : \u03b1) : max x y = if x < y then y else x :=\nbegin\n  rw [max_comm, max_def, \u2190 ite_not],\n  simp only [not_le],\nend\n\nend min_max_rec\n\n/-! ### `has_sup` and `has_inf` -/\n\n/-- Typeclass for the `\u2294` (`\\lub`) notation -/\n@[notation_class] class has_sup (\u03b1 : Type u) := (sup : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n/-- Typeclass for the `\u2293` (`\\glb`) notation -/\n@[notation_class] class has_inf (\u03b1 : Type u) := (inf : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n\ninfix ` \u2294 ` := has_sup.sup\ninfix ` \u2293 ` := has_inf.inf\n\n/-! ### Lifts of order instances -/\n\n/-- Transfer a `preorder` on `\u03b2` to a `preorder` on `\u03b1` using a function `f : \u03b1 \u2192 \u03b2`.\nSee note [reducible non-instances]. -/\n@[reducible] def preorder.lift {\u03b1 \u03b2} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) : preorder \u03b1 :=\n{ le               := \u03bb x y, f x \u2264 f y,\n  le_refl          := \u03bb a, le_rfl,\n  le_trans         := \u03bb a b c, le_trans,\n  lt               := \u03bb x y, f x < f y,\n  lt_iff_le_not_le := \u03bb a b, lt_iff_le_not_le }\n\n/-- Transfer a `partial_order` on `\u03b2` to a `partial_order` on `\u03b1` using an injective\nfunction `f : \u03b1 \u2192 \u03b2`. See note [reducible non-instances]. -/\n@[reducible] def partial_order.lift {\u03b1 \u03b2} [partial_order \u03b2] (f : \u03b1 \u2192 \u03b2) (inj : injective f) :\n  partial_order \u03b1 :=\n{ le_antisymm := \u03bb a b h\u2081 h\u2082, inj (h\u2081.antisymm h\u2082), .. preorder.lift f }\n\n/-- Transfer a `linear_order` on `\u03b2` to a `linear_order` on `\u03b1` using an injective\nfunction `f : \u03b1 \u2192 \u03b2`. This version takes `[has_sup \u03b1]` and `[has_inf \u03b1]` as arguments, then uses\nthem for `max` and `min` fields. See `linear_order.lift'` for a version that autogenerates `min` and\n`max` fields. See note [reducible non-instances]. -/\n@[reducible] def linear_order.lift {\u03b1 \u03b2} [linear_order \u03b2] [has_sup \u03b1] [has_inf \u03b1] (f : \u03b1 \u2192 \u03b2)\n  (inj : injective f) (hsup : \u2200 x y, f (x \u2294 y) = max (f x) (f y))\n  (hinf : \u2200 x y, f (x \u2293 y) = min (f x) (f y)) :\n  linear_order \u03b1 :=\n{ le_total     := \u03bb x y, le_total (f x) (f y),\n  decidable_le := \u03bb x y, (infer_instance : decidable (f x \u2264 f y)),\n  decidable_lt := \u03bb x y, (infer_instance : decidable (f x < f y)),\n  decidable_eq := \u03bb x y, decidable_of_iff (f x = f y) inj.eq_iff,\n  min := (\u2293),\n  max := (\u2294),\n  min_def := by { ext x y, apply inj, rw [hinf, min_def, min_default, apply_ite f], refl },\n  max_def := by { ext x y, apply inj, rw [hsup, max_def, max_default, apply_ite f], refl },\n  .. partial_order.lift f inj }\n\n/-- Transfer a `linear_order` on `\u03b2` to a `linear_order` on `\u03b1` using an injective\nfunction `f : \u03b1 \u2192 \u03b2`. This version autogenerates `min` and `max` fields. See `linear_order.lift`\nfor a version that takes `[has_sup \u03b1]` and `[has_inf \u03b1]`, then uses them as `max` and `min`.\nSee note [reducible non-instances]. -/\n@[reducible] def linear_order.lift' {\u03b1 \u03b2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (inj : injective f) :\n  linear_order \u03b1 :=\n@linear_order.lift \u03b1 \u03b2 _ \u27e8\u03bb x y, if f x \u2264 f y then y else x\u27e9 \u27e8\u03bb x y, if f x \u2264 f y then x else y\u27e9\n  f inj (\u03bb x y, (apply_ite f _ _ _).trans (max_def _ _).symm)\n  (\u03bb x y, (apply_ite f _ _ _).trans (min_def _ _).symm)\n\n/-! ### Subtype of an order -/\n\nnamespace subtype\n\ninstance [has_le \u03b1] {p : \u03b1 \u2192 Prop} : has_le (subtype p) := \u27e8\u03bb x y, (x : \u03b1) \u2264 y\u27e9\ninstance [has_lt \u03b1] {p : \u03b1 \u2192 Prop} : has_lt (subtype p) := \u27e8\u03bb x y, (x : \u03b1) < y\u27e9\n\n@[simp] lemma mk_le_mk [has_le \u03b1] {p : \u03b1 \u2192 Prop} {x y : \u03b1} {hx : p x} {hy : p y} :\n  (\u27e8x, hx\u27e9 : subtype p) \u2264 \u27e8y, hy\u27e9 \u2194 x \u2264 y :=\niff.rfl\n\n@[simp] lemma mk_lt_mk [has_lt \u03b1] {p : \u03b1 \u2192 Prop} {x y : \u03b1} {hx : p x} {hy : p y} :\n  (\u27e8x, hx\u27e9 : subtype p) < \u27e8y, hy\u27e9 \u2194 x < y :=\niff.rfl\n\n@[simp, norm_cast]\nlemma coe_le_coe [has_le \u03b1] {p : \u03b1 \u2192 Prop} {x y : subtype p} : (x : \u03b1) \u2264 y \u2194 x \u2264 y := iff.rfl\n\n@[simp, norm_cast]\nlemma coe_lt_coe [has_lt \u03b1] {p : \u03b1 \u2192 Prop} {x y : subtype p} : (x : \u03b1) < y \u2194 x < y := iff.rfl\n\ninstance [preorder \u03b1] (p : \u03b1 \u2192 Prop) : preorder (subtype p) := preorder.lift (coe : subtype p \u2192 \u03b1)\n\ninstance partial_order [partial_order \u03b1] (p : \u03b1 \u2192 Prop) :\n  partial_order (subtype p) :=\npartial_order.lift coe subtype.coe_injective\n\ninstance decidable_le [preorder \u03b1] [h : @decidable_rel \u03b1 (\u2264)] {p : \u03b1 \u2192 Prop} :\n  @decidable_rel (subtype p) (\u2264) :=\n\u03bb a b, h a b\n\ninstance decidable_lt [preorder \u03b1] [h : @decidable_rel \u03b1 (<)] {p : \u03b1 \u2192 Prop} :\n  @decidable_rel (subtype p) (<) :=\n\u03bb a b, h a b\n\n/-- A subtype of a linear order is a linear order. We explicitly give the proofs of decidable\nequality and decidable order in order to ensure the decidability instances are all definitionally\nequal. -/\ninstance [linear_order \u03b1] (p : \u03b1 \u2192 Prop) : linear_order (subtype p) :=\n@linear_order.lift (subtype p) _ _ \u27e8\u03bb x y, \u27e8max x y, max_rec' _ x.2 y.2\u27e9\u27e9\n  \u27e8\u03bb x y, \u27e8min x y, min_rec' _ x.2 y.2\u27e9\u27e9 coe subtype.coe_injective (\u03bb _ _, rfl) (\u03bb _ _, rfl)\n\nend subtype\n\n/-!\n### Pointwise order on `\u03b1 \u00d7 \u03b2`\n\nThe lexicographic order is defined in `data.prod.lex`, and the instances are available via the\ntype synonym `\u03b1 \u00d7\u2097 \u03b2 = \u03b1 \u00d7 \u03b2`.\n-/\n\nnamespace prod\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [has_le \u03b1] [has_le \u03b2] : has_le (\u03b1 \u00d7 \u03b2) :=\n\u27e8\u03bb p q, p.1 \u2264 q.1 \u2227 p.2 \u2264 q.2\u27e9\n\nlemma le_def [has_le \u03b1] [has_le \u03b2] {x y : \u03b1 \u00d7 \u03b2} : x \u2264 y \u2194 x.1 \u2264 y.1 \u2227 x.2 \u2264 y.2 := iff.rfl\n\n@[simp] lemma mk_le_mk [has_le \u03b1] [has_le \u03b2] {x\u2081 x\u2082 : \u03b1} {y\u2081 y\u2082 : \u03b2} :\n  (x\u2081, y\u2081) \u2264 (x\u2082, y\u2082) \u2194 x\u2081 \u2264 x\u2082 \u2227 y\u2081 \u2264 y\u2082 :=\niff.rfl\n\n@[simp] lemma swap_le_swap [has_le \u03b1] [has_le \u03b2] {x y : \u03b1 \u00d7 \u03b2} : x.swap \u2264 y.swap \u2194 x \u2264 y :=\nand_comm _ _\n\nsection preorder\nvariables [preorder \u03b1] [preorder \u03b2] {a a\u2081 a\u2082 : \u03b1} {b b\u2081 b\u2082 : \u03b2} {x y : \u03b1 \u00d7 \u03b2}\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [preorder \u03b1] [preorder \u03b2] : preorder (\u03b1 \u00d7 \u03b2) :=\n{ le_refl  := \u03bb \u27e8a, b\u27e9, \u27e8le_refl a, le_refl b\u27e9,\n  le_trans := \u03bb \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9 \u27e8hac, hbd\u27e9 \u27e8hce, hdf\u27e9,\n    \u27e8le_trans hac hce, le_trans hbd hdf\u27e9,\n  .. prod.has_le \u03b1 \u03b2 }\n\n@[simp] lemma swap_lt_swap : x.swap < y.swap \u2194 x < y :=\nand_congr swap_le_swap (not_congr swap_le_swap)\n\nlemma mk_le_mk_iff_left : (a\u2081, b) \u2264 (a\u2082, b) \u2194 a\u2081 \u2264 a\u2082 := and_iff_left le_rfl\nlemma mk_le_mk_iff_right : (a, b\u2081) \u2264 (a, b\u2082) \u2194 b\u2081 \u2264 b\u2082 := and_iff_right le_rfl\n\nlemma mk_lt_mk_iff_left : (a\u2081, b) < (a\u2082, b) \u2194 a\u2081 < a\u2082 :=\nlt_iff_lt_of_le_iff_le' mk_le_mk_iff_left mk_le_mk_iff_left\n\nlemma mk_lt_mk_iff_right : (a, b\u2081) < (a, b\u2082) \u2194 b\u2081 < b\u2082 :=\nlt_iff_lt_of_le_iff_le' mk_le_mk_iff_right mk_le_mk_iff_right\n\nlemma lt_iff : x < y \u2194 x.1 < y.1 \u2227 x.2 \u2264 y.2 \u2228 x.1 \u2264 y.1 \u2227 x.2 < y.2 :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { by_cases h\u2081 : y.1 \u2264 x.1,\n    { exact or.inr \u27e8h.1.1, h.1.2.lt_of_not_le $ \u03bb h\u2082, h.2 \u27e8h\u2081, h\u2082\u27e9\u27e9 },\n    { exact or.inl \u27e8h.1.1.lt_of_not_le h\u2081, h.1.2\u27e9 } },\n  { rintro (\u27e8h\u2081, h\u2082\u27e9 | \u27e8h\u2081, h\u2082\u27e9),\n    { exact \u27e8\u27e8h\u2081.le, h\u2082\u27e9, \u03bb h, h\u2081.not_le h.1\u27e9 },\n    { exact \u27e8\u27e8h\u2081, h\u2082.le\u27e9, \u03bb h, h\u2082.not_le h.2\u27e9 } }\nend\n\n@[simp] lemma mk_lt_mk : (a\u2081, b\u2081) < (a\u2082, b\u2082) \u2194 a\u2081 < a\u2082 \u2227 b\u2081 \u2264 b\u2082 \u2228 a\u2081 \u2264 a\u2082 \u2227 b\u2081 < b\u2082 := lt_iff\n\nend preorder\n\n/-- The pointwise partial order on a product.\n    (The lexicographic ordering is defined in order/lexicographic.lean, and the instances are\n    available via the type synonym `\u03b1 \u00d7\u2097 \u03b2 = \u03b1 \u00d7 \u03b2`.) -/\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [partial_order \u03b1] [partial_order \u03b2] :\n  partial_order (\u03b1 \u00d7 \u03b2) :=\n{ le_antisymm := \u03bb \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8hac, hbd\u27e9 \u27e8hca, hdb\u27e9,\n    prod.ext (hac.antisymm hca) (hbd.antisymm hdb),\n  .. prod.preorder \u03b1 \u03b2 }\n\nend prod\n\n/-! ### Additional order classes -/\n\n/-- An order is dense if there is an element between any pair of distinct comparable elements. -/\nclass densely_ordered (\u03b1 : Type u) [has_lt \u03b1] : Prop :=\n(dense : \u2200 a\u2081 a\u2082 : \u03b1, a\u2081 < a\u2082 \u2192 \u2203 a, a\u2081 < a \u2227 a < a\u2082)\n\nlemma exists_between [has_lt \u03b1] [densely_ordered \u03b1] :\n  \u2200 {a\u2081 a\u2082 : \u03b1}, a\u2081 < a\u2082 \u2192 \u2203 a, a\u2081 < a \u2227 a < a\u2082 :=\ndensely_ordered.dense\n\ninstance order_dual.densely_ordered (\u03b1 : Type u) [has_lt \u03b1] [densely_ordered \u03b1] :\n  densely_ordered \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a\u2081 a\u2082 ha, (@exists_between \u03b1 _ _ _ _ ha).imp $ \u03bb a, and.symm\u27e9\n\n@[simp] lemma densely_ordered_order_dual [has_lt \u03b1] : densely_ordered \u03b1\u1d52\u1d48 \u2194 densely_ordered \u03b1 :=\n\u27e8by { convert @order_dual.densely_ordered \u03b1\u1d52\u1d48 _, casesI \u2039has_lt \u03b1\u203a, refl },\n  @order_dual.densely_ordered \u03b1 _\u27e9\n\ninstance [preorder \u03b1] [preorder \u03b2] [densely_ordered \u03b1] [densely_ordered \u03b2] :\n  densely_ordered (\u03b1 \u00d7 \u03b2) :=\n\u27e8\u03bb a b, begin\n  simp_rw prod.lt_iff,\n  rintro (\u27e8h\u2081, h\u2082\u27e9 | \u27e8h\u2081, h\u2082\u27e9),\n  { obtain \u27e8c, ha, hb\u27e9 := exists_between h\u2081,\n    exact \u27e8(c, _), or.inl \u27e8ha, h\u2082\u27e9, or.inl \u27e8hb, le_rfl\u27e9\u27e9 },\n  { obtain \u27e8c, ha, hb\u27e9 := exists_between h\u2082,\n    exact \u27e8(_, c), or.inr \u27e8h\u2081, ha\u27e9, or.inr \u27e8le_rfl, hb\u27e9\u27e9 }\nend\u27e9\n\ninstance {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, densely_ordered (\u03b1 i)] :\n  densely_ordered (\u03a0 i, \u03b1 i) :=\n\u27e8\u03bb a b, begin\n  classical,\n  simp_rw pi.lt_def,\n  rintro \u27e8hab, i, hi\u27e9,\n  obtain \u27e8c, ha, hb\u27e9 := exists_between hi,\n  exact \u27e8a.update i c, \u27e8le_update_iff.2 \u27e8ha.le, \u03bb _ _, le_rfl\u27e9, i, by rwa update_same\u27e9,\n    update_le_iff.2 \u27e8hb.le, \u03bb _ _, hab _\u27e9, i, by rwa update_same\u27e9,\nend\u27e9\n\nlemma le_of_forall_le_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h : \u2200 a, a\u2082 < a \u2192 a\u2081 \u2264 a) :\n  a\u2081 \u2264 a\u2082 :=\nle_of_not_gt $ \u03bb ha,\n  let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between ha in\n  lt_irrefl a $ lt_of_lt_of_le \u2039a < a\u2081\u203a (h _ \u2039a\u2082 < a\u203a)\n\nlemma eq_of_le_of_forall_le_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : \u2200 a, a\u2082 < a \u2192 a\u2081 \u2264 a) : a\u2081 = a\u2082 :=\nle_antisymm (le_of_forall_le_of_dense h\u2082) h\u2081\n\nlemma le_of_forall_ge_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h : \u2200 a\u2083 < a\u2081, a\u2083 \u2264 a\u2082) :\n  a\u2081 \u2264 a\u2082 :=\nle_of_not_gt $ \u03bb ha,\n  let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between ha in\n  lt_irrefl a $ lt_of_le_of_lt (h _ \u2039a < a\u2081\u203a) \u2039a\u2082 < a\u203a\n\nlemma eq_of_le_of_forall_ge_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : \u2200 a\u2083 < a\u2081, a\u2083 \u2264 a\u2082) : a\u2081 = a\u2082 :=\n(le_of_forall_ge_of_dense h\u2082).antisymm h\u2081\n\nlemma dense_or_discrete [linear_order \u03b1] (a\u2081 a\u2082 : \u03b1) :\n  (\u2203 a, a\u2081 < a \u2227 a < a\u2082) \u2228 ((\u2200 a, a\u2081 < a \u2192 a\u2082 \u2264 a) \u2227 (\u2200 a < a\u2082, a \u2264 a\u2081)) :=\nor_iff_not_imp_left.2 $ \u03bb h,\n  \u27e8\u03bb a ha\u2081, le_of_not_gt $ \u03bb ha\u2082, h \u27e8a, ha\u2081, ha\u2082\u27e9,\n    \u03bb a ha\u2082, le_of_not_gt $ \u03bb ha\u2081, h \u27e8a, ha\u2081, ha\u2082\u27e9\u27e9\n\n/-- If a linear order has no elements `x < y < z`, then it has at most two elements. -/\nlemma eq_or_eq_or_eq_of_forall_not_lt_lt {\u03b1 : Type*} [linear_order \u03b1]\n  (h : \u2200 \u2983x y z : \u03b1\u2984, x < y \u2192 y < z \u2192 false) (x y z : \u03b1) : x = y \u2228 y = z \u2228 x = z :=\nbegin\n  by_contra hne, push_neg at hne,\n  cases hne.1.lt_or_lt with h\u2081 h\u2081; cases hne.2.1.lt_or_lt with h\u2082 h\u2082;\n    cases hne.2.2.lt_or_lt with h\u2083 h\u2083,\n  exacts [h h\u2081 h\u2082, h h\u2082 h\u2083, h h\u2083 h\u2082, h h\u2083 h\u2081, h h\u2081 h\u2083, h h\u2082 h\u2083, h h\u2081 h\u2083, h h\u2082 h\u2081]\nend\n\nnamespace punit\nvariables (a b : punit.{u+1})\n\ninstance : linear_order punit :=\nby refine_struct\n{ le := \u03bb _ _, true,\n  lt := \u03bb _ _, false,\n  max := \u03bb _ _, star,\n  min := \u03bb _ _, star,\n  decidable_eq := punit.decidable_eq,\n  decidable_le := \u03bb _ _, decidable.true,\n  decidable_lt := \u03bb _ _, decidable.false };\n    intros; trivial <|> simp only [eq_iff_true_of_subsingleton, not_true, and_false] <|>\n      exact or.inl trivial\n\nlemma max_eq : max a b = star := rfl\nlemma min_eq : min a b = star := rfl\n@[simp] protected lemma le : a \u2264 b := trivial\n@[simp] lemma not_lt : \u00ac a < b := not_false\n\ninstance : densely_ordered punit := \u27e8\u03bb _ _, false.elim\u27e9\n\nend punit\n\nsection prop\n\n/-- Propositions form a complete boolean algebra, where the `\u2264` relation is given by implication. -/\ninstance Prop.has_le : has_le Prop := \u27e8(\u2192)\u27e9\n\n@[simp] lemma le_Prop_eq : ((\u2264) : Prop \u2192 Prop \u2192 Prop) = (\u2192) := rfl\n\nlemma subrelation_iff_le {r s : \u03b1 \u2192 \u03b1 \u2192 Prop} : subrelation r s \u2194 r \u2264 s := iff.rfl\n\ninstance Prop.partial_order : partial_order Prop :=\n{ le_refl      := \u03bb _, id,\n  le_trans     := \u03bb a b c f g, g \u2218 f,\n  le_antisymm  := \u03bb a b Hab Hba, propext \u27e8Hab, Hba\u27e9,\n  ..Prop.has_le }\n\nend prop\n\nvariables {s : \u03b2 \u2192 \u03b2 \u2192 Prop} {t : \u03b3 \u2192 \u03b3 \u2192 Prop}\n\n/-! ### Linear order from a total partial order -/\n\n/-- Type synonym to create an instance of `linear_order` from a `partial_order` and\n`is_total \u03b1 (\u2264)` -/\ndef as_linear_order (\u03b1 : Type u) := \u03b1\n\ninstance {\u03b1} [inhabited \u03b1] : inhabited (as_linear_order \u03b1) :=\n\u27e8 (default : \u03b1) \u27e9\n\nnoncomputable instance as_linear_order.linear_order {\u03b1} [partial_order \u03b1] [is_total \u03b1 (\u2264)] :\n  linear_order (as_linear_order \u03b1) :=\n{ le_total     := @total_of \u03b1 (\u2264) _,\n  decidable_le := classical.dec_rel _,\n  .. (_ : partial_order \u03b1) }\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915616, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7218888693283827}}
{"text": "/- Even more induction! -/\nset_option trace.Meta.Tactic.simp true\n\nvariable (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n-- The reflexive transitive closure of `r` as an inductive predicate\ninductive RTC : \u03b1 \u2192 \u03b1 \u2192 Prop where\n  -- Notice how declaring `r` as a `variable` instead of as a parameter instead of declaring it\n  -- directly as a parameter of `RTC` means we don't have to write `RTC r a a` inside the\n  -- declaration of `RTC`. This also works with recursive `def`s!\n  | refl : RTC a a\n  | trans : r a b \u2192 RTC b c \u2192 RTC a c\n\n-- We have arbitrarily chosen a \"left-biased\" definition of `RTC.trans`, but can easily show the\n-- mirror version by induction on the predicate\ntheorem RTC.trans' : RTC r a b \u2192 r b c \u2192 RTC r a c := by\n  intros hab hbc\n  induction hab with\n  | refl => exact RTC.trans hbc RTC.refl\n  -- `a/b/c` in the constructor `RTC.trans` are marked as *implicit* because we didn't specify them\n  -- explicitly.\n  -- Just like in other contexts, we can use `@` to specify/match implicit parameters in `induction`.\n  | @trans a a' b haa' ha'b ih => \n    apply RTC.trans \n    exact haa' \n    exact (ih hbc)   \n\nopen Nat\n\n-- By the way, we can leave out `:= fun p1 ... => match p1, ... with` at `def`\ndef double : Nat \u2192 Nat\n  | zero   => 0\n  | succ n => succ (succ (double n))\n\n-- The tactic injection proves that constructors like succ are injective and that they are distinct\ntheorem double.inj : double n = double m \u2192 n = m := by\n  intro h\n  -- Try to finish this proof. You might find that the inductive case is impossible to solve!\n  -- Do you see a different approach? If not, read on!\n  induction n generalizing m with\n  | zero => cases m <;> trivial\n  | succ n h1 => \n    cases m with \n    | zero => contradiction\n    | succ m => \n      rw [double] at h\n      -- h: succ (succ (double n)) = double (succ m)\n      injection h with h -- h: succ (double n) = succ (double m)\n      injection h with h -- double n = double m\n      rw [h1 h]\n\n-- The issue with the above approach is that our inductive hypothesis is not sufficiently general!\n-- When we begin induction, we have already fixed (introduced) a particular `m`, but for the inductive\n-- step we need the inductive hypothesis for a *different* m.\n-- We could avoid this by carefully introducing `m` (and `h`, which depends on it) only after `induction`:\n-- ```\n-- theorem double.inj : \u2200 m, double n = double m \u2192 n = m := by\n--   induction n with\n--   | zero => intro m h; ...\n--   ...\n-- ```\n-- `induction` even allows us to apply a tactic before *each* case:\n-- ```\n-- theorem double.inj : \u2200 m, double n = double m \u2192 n = m := by\n--   induction n with\n--       intro m h\n--   | zero => ...\n--   ...\n-- ```\n-- However, it turns out that we do not have to change the theorem statement at all: if we simply say\n-- ```\n-- induction n generalizing m with\n-- ```\n-- then `induction` will automatically `revert` (yes, that's also a tactic) and re`intro`duce the variable(s)\n-- before/after induction for us! So add `generalizing m` above, see how the inductive hypothesis is\n-- affected, and then go finish that proof!\n\n\n/- Partial & dependent maps -/\n\n-- *Partial maps* are a useful data type for the semantics project and many other topics.\n-- They map *some* keys of one type to values of another type.\nabbrev Map (\u03b1 \u03b2 : Type) := \u03b1 \u2192 Option \u03b2\n-- We express partiality via the `Option` type, which either holds `some b` for `b : \u03b2`, or `none`.\n-- Ctrl+click it for the whole definition.\n\nnamespace Map\n\ndef empty : Map \u03b1 \u03b2 := fun k => none\n\n-- If we wanted a partial map for programming, we might choose a more efficient implementation such\n-- as a search tree or a hash map. If, on the other hand, we are only interested in using it in a\n-- formalization, a simple function like above is usually the better solution. For example, a\n-- simple typing context `\u0393` can be formalized as a partial map from variable names to their types.\n\n-- The function-based definition makes defining operations such as a map update quite easy:\n\n/-- Set the entry `k` of the map `m` to the value `v`. All other entries are unchanged. -/\ndef update [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) (k : \u03b1) (v : Option \u03b2) : Map \u03b1 \u03b2 := \n  fun x => if k = x then v else m x\n\n-- def update [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) (k : \u03b1) (v : Option \u03b2) : Map \u03b1 \u03b2 := \n--   fun k' => if k = k' then v else m k'\n\n-- A `scoped` notation is activated only when opening/inside the current namespace\nscoped notation:max m \"[\" k \" \u21a6 \" v \"]\" => update m k v\n\ntheorem apply_update [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) : m[k \u21a6 v] k = v := by simp [update]  \n\n-- hint: use function extensionality (`apply funext`)\ntheorem update_self [DecidableEq \u03b1] (m : Map \u03b1 \u03b2) : m[k \u21a6 m k] = m := by\n-- funext {f\u2081 f\u2082 : \u2200 (x : \u03b1), \u03b2 x} (h : \u2200 x, f\u2081 x = f\u2082 x) : f\u2081 = f\u2082\n  funext k'  -- an abbreviation for `apply funext; intro k'`\n  by_cases h : k = k' <;> simp [update, h]\n\nend Map\n\n-- One interesting generalization of partial maps we can express in Lean are *dependent maps* where\n-- the *type* of the value may depend on the key:\nabbrev DepMap (\u03b1 : Type) (\u03b2 : \u03b1 \u2192 Type) := (k : \u03b1) \u2192 Option (\u03b2 k)\n\nnamespace DepMap\n\ndef empty : DepMap \u03b1 \u03b2 := fun k => none\n\n-- If we try to define `update` as above, it turns out that we run into a type error!\n-- You may want to use the \"dependent if\" `if h : p then t else e` that makes a *proof* of\n-- the condition `p` available in each branch: `h : p` in the `then` branch and `h : \u00acp` in the\n-- `else` branch. You should then be able to use rewriting (e.g. `\u25b8`) to fix the type error.\ndef update [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) (k : \u03b1) (v : Option (\u03b2 k)) : DepMap \u03b1 \u03b2 :=\n  fun x => if h : k = x then h \u25b8 v else m x\n    -- fun x => if k = x then v else m x\n\nscoped notation:max m \"[\" k \" \u21a6 \" v \"]\" => update m k v\n\n-- This one should be as before...\ntheorem apply_update [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) : m[k \u21a6 v] k = v := by simp [update]\n\n-- ...but this one is where the fun starts: try replicating the corresponding `Map` proof...\ntheorem update_self [DecidableEq \u03b1] (m : DepMap \u03b1 \u03b2) : m[k \u21a6 m k] = m := by\n  funext k'  -- an abbreviation for `apply funext; intro k'`\n  by_cases h : k = k' \n  case inl => \n    rw [h]\n    simp [update]\n  case inr => \n    simp [h, update]\n-- and you should end up with an unsolved goal containing a subterm of the shape `(_ : a = b) \u25b8 c`. This\n-- is the rewrite from `update`; the proof is elided as `_` by default because, as we said in week 1, Lean\n-- considers all proofs of a proposition as equal, so we really don't care what proof is displayed there.\n-- So how do we get rid of the `\u25b8`? We know it is something like a match  on `Eq.refl`; more formally,\n-- both `\u25b8` and such a match compile down to an application of `Eq`'s *recursor* (week 3).\n-- We know matches/recursors reduce (\"go away\") when applied to a matching constructor application,\n-- i.e. for `\u25b8` we have `(rfl \u25b8 c) \u2261 c`.\n-- So why didn't `simp` reduce away `(_ : a = b) \u25b8` if it works for `rfl` and all proofs are the same?\n-- Well, all proofs of a *single* proposition are the same, but `rfl` is not a proof of `a = b` unless\n-- `a` and `b` are in fact the same term! Thus the general way to get rid of `(_ : a = b) \u25b8` is to\n-- first rewrite the goal with a proof of the very equality `a = b`. After that, `simp`, or definitional\n-- equality in general, will get rid of the `\u25b8`.\n-- Now, for technical reasons we should use `rw` instead of `simp` itself to do this rewrite. The short\n-- answer as to why that is is that `simp` tries to be *too clever* in this case: it will rewrite `a = b`\n-- on both sides of the `\u25b8` individually, which usually makes it more flexible (week 4, slide pages 17 & 21),\n-- but in this case unfortunately leads to a type-incorrect proof. The \"naive\" strategy of `rw`, which will\n-- simply replace all `a` with `b` everywhere simultaneously by applying the `Eq` recursor once at the root,\n-- turns out to be the better approach in this case.\n-- Phew, that was a lot of typing (in the theoretic sense and on my keyboard). If you can't get the proof to\n-- work, don't worry about it, we will not bother you with this kind of \"esoteric\" proof again. If, on the\n-- other hand, you are interested in this kind of strong dependent typing, we may have an interesting variant\n-- of the semantics project to offer you next week!\n\nend DepMap\n\nopen List Nat\n\n/- Insertion Sort -/\n\n-- Let's implement insertion sort in Lean and show that the resulting `List` is indeed sorted.\n-- To that end, we first assume that the type `\u03b1` is of the type class `LE`, meaning that we can use\n-- the symbol `\u2264` (\\le) as notation.\n-- We also assume (notice that cool dot notation) that this relation is decidable:\nvariable [LE \u03b1] [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n\n-- First, we want to define a predicate that holds if a list is sorted.\n-- The predicate should have three constructors:\n-- The empty list `[]` and the single element list `[a]` are sorted,\n-- and we can add `a` to the front of a sorted list `b :: l`, if `a \u2264 b`.\ninductive Sorted : List \u03b1 \u2192 Prop where \n  | nil : Sorted []\n  | single : Sorted [a]\n  | cons_cons : a \u2264 b \u2192 Sorted (b::l) \u2192 Sorted (a::b::l) \n\n-- The main ingredient to insertion sort is a function `insertInOrder` which inserts\n-- a single element `a` before the first entry `x` of a list for which `a \u2264 x` holds.\n-- Define that function by recursion on the list. Remember that `\u2264` is decidable.\n-- def insertInOrder (a : \u03b1) (xs : List \u03b1) : List \u03b1 := \n--   let rec helper (a : \u03b1) (xs : List \u03b1) (ys : List \u03b1) : List \u03b1 := \n--     match xs with  \n--     | [] => ys ++ [a]\n--     | x :: xs => if a \u2264 x then ys ++ (a::x::xs) else helper a xs (ys ++ [x])\n--   helper a xs []\n\ndef insertInOrder (a : \u03b1) (xs : List \u03b1) : List \u03b1 := \n  match xs with\n  | [] => [a]\n  | x :: xs =>\n    if a \u2264 x then\n      a :: x :: xs\n    else\n      x :: insertInOrder a xs\n\n-- Now, check whether the function actually does what it should do.\n#eval insertInOrder 4 [1, 3, 4, 6, 7]\n#eval insertInOrder 4 [1, 2, 3]\n\n-- Defining `insertionSort` itself is now an easy recursion.\n-- def insertionSort (xs : List \u03b1) : List \u03b1 := \n--   let rec helper (xs : List \u03b1) (ys : List \u03b1) : List \u03b1 := \n--     match xs with \n--     | [] => ys\n--     | x :: xs => helper xs (insertInOrder x ys)\n--   helper xs []\n\ndef insertionSort (xs : List \u03b1) : List \u03b1 := \n  match xs with\n  | []      => []\n  | x :: xs => insertInOrder x (insertionSort xs)\n\n-- Let's test the sorting algorithm next.\n#eval insertionSort [6, 2, 4, 4, 1, 3, 64]\n#eval insertionSort [1, 2, 3]\n#eval insertionSort (Nat.repeat (fun xs => xs.length :: xs) 500 [])\n\n-- Now we want to move on to actually verify that the algorithm does what it claims to do!\n-- To prove this, we don't need the relation to be transitive, but we need to assume the following property:\nvariable (antisymm : \u2200 {x y : \u03b1}, \u00ac (x \u2264 y) \u2192 y \u2264 x)\n\n-- Okay, now prove the statement itself!\n-- Hints:\n--   * You might at one point have the choice to either apply induction on a list or on a witness of `Sorted`.\n--     Choose wisely.\n--   * Remember the tactic `by_cases` from the fifth exercise!\ntheorem sorted_insertInOrder {xs : List \u03b1} (h : Sorted xs) : Sorted (insertInOrder x xs) := by\n  induction h with\n  | nil => exact Sorted.single\n  | @single a => \n    simp only [insertInOrder]\n    by_cases hxa : x \u2264 a <;> simp only [hxa]\n    case inl => exact Sorted.cons_cons hxa Sorted.single\n    case inr => exact Sorted.cons_cons (antisymm hxa) Sorted.single\n  | @cons_cons a b l hab hbl ih => \n    simp only [insertInOrder]\n    by_cases hxa : x \u2264 a <;> simp only [hxa]\n    case inl => exact Sorted.cons_cons hxa (Sorted.cons_cons hab hbl)\n    case inr => \n      by_cases hxb : x \u2264 b <;> simp only [hxb]\n      case inl => exact Sorted.cons_cons (antisymm hxa) (Sorted.cons_cons hxb hbl)\n      case inr =>\n        simp only [insertInOrder, hxb] at ih\n        exact Sorted.cons_cons hab ih\n\ntheorem sorted_insertionSort (as : List \u03b1) : Sorted (insertionSort as) := \n  match as with \n  | nil => Sorted.nil\n  | x :: xs => sorted_insertInOrder antisymm (sorted_insertionSort xs)\n\n-- Here's a \"soft\" question: Have we now fully verified that `insertionSort` is a sorting algorithm?\n-- What other property would be an obvious one to verify (which you don't have to do here)?\n\n", "meta": {"author": "vanessa-rodrigues", "repo": "lean-books", "sha": "dcadc8b3f665eda5c6d7153384bd152a9c1ca483", "save_path": "github-repos/lean/vanessa-rodrigues-lean-books", "path": "github-repos/lean/vanessa-rodrigues-lean-books/lean-books-dcadc8b3f665eda5c6d7153384bd152a9c1ca483/IPDSnelting/Exercises/Exercise6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.721888860270816}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura\n\nList permutations.\n-/\nimport data.list.basic data.list.set\nopen list setoid nat binary\n\nvariables {A B : Type}\n\ninductive perm : list A \u2192 list A \u2192 Prop :=\n| nil   : perm [] []\n| skip  : \u03a0 (x : A) {l\u2081 l\u2082 : list A}, perm l\u2081 l\u2082 \u2192 perm (x::l\u2081) (x::l\u2082)\n| swap  : \u03a0 (x y : A) (l : list A), perm (y::x::l) (x::y::l)\n| trans : \u03a0 {l\u2081 l\u2082 l\u2083 : list A}, perm l\u2081 l\u2082 \u2192 perm l\u2082 l\u2083 \u2192 perm l\u2081 l\u2083\n\nnamespace perm\ninfix ~ := perm\ntheorem eq_nil_of_perm_nil {l\u2081 : list A} (p : [] ~ l\u2081) : l\u2081 = [] :=\nhave gen : \u2200 (l\u2082 : list A) (p : l\u2082 ~ l\u2081), l\u2082 = [] \u2192 l\u2081 = [], from\n  take l\u2082 p, perm.induction_on p\n    (\u03bb h, h)\n    (by contradiction)\n    (by contradiction)\n    (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082 e, r\u2082 (r\u2081 e)),\ngen [] p rfl\n\ntheorem not_perm_nil_cons (x : A) (l : list A) : \u00ac [] ~ (x::l) :=\nhave gen : \u2200 (l\u2081 l\u2082 : list A) (p : l\u2081 ~ l\u2082), l\u2081 = [] \u2192 l\u2082 = (x::l) \u2192 false, from\n  take l\u2081 l\u2082 p, perm.induction_on p\n    (by contradiction)\n    (by contradiction)\n    (by contradiction)\n    (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082 e\u2081 e\u2082,\n      begin\n        rewrite [e\u2082 at *, e\u2081 at *],\n        have e\u2083 : l\u2082 = [], from eq_nil_of_perm_nil p\u2081,\n        exact (r\u2082 e\u2083 rfl)\n      end),\nassume p, gen [] (x::l) p rfl rfl\n\nprotected theorem refl [refl] : \u2200 (l : list A), l ~ l\n| []      := nil\n| (x::xs) := skip x (refl xs)\n\nprotected theorem symm [symm] : \u2200 {l\u2081 l\u2082 : list A}, l\u2081 ~ l\u2082 \u2192 l\u2082 ~ l\u2081 :=\ntake l\u2081 l\u2082 p, perm.induction_on p\n  nil\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, skip x r\u2081)\n  (\u03bb x y l, swap y x l)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2082 r\u2081)\n\nattribute perm.trans [trans]\n\ntheorem eqv (A : Type) : equivalence (@perm A) :=\nmk_equivalence (@perm A) (@perm.refl A) (@perm.symm A) (@perm.trans A)\n\nprotected definition is_setoid [instance] (A : Type) : setoid (list A) :=\nsetoid.mk (@perm A) (perm.eqv A)\n\ntheorem mem_perm {a : A} {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 a \u2208 l\u2081 \u2192 a \u2208 l\u2082 :=\nassume p, perm.induction_on p\n  (\u03bb h, h)\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081 i, or.elim (eq_or_mem_of_mem_cons i)\n    (suppose a = x,  by rewrite this; apply !mem_cons)\n    (suppose a \u2208 l\u2081, or.inr (r\u2081 this)))\n  (\u03bb x y l ainyxl, or.elim (eq_or_mem_of_mem_cons ainyxl)\n    (suppose a = y, by rewrite this; exact (or.inr !mem_cons))\n    (suppose a \u2208 x::l, or.elim (eq_or_mem_of_mem_cons this)\n      (suppose a = x, or.inl this)\n      (suppose a \u2208 l, or.inr (or.inr this))))\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082 ainl\u2081, r\u2082 (r\u2081 ainl\u2081))\n\ntheorem not_mem_perm {a : A} {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 a \u2209 l\u2081 \u2192 a \u2209 l\u2082 :=\nassume p nainl\u2081 ainl\u2082, absurd (mem_perm (perm.symm p) ainl\u2082) nainl\u2081\n\ntheorem perm_app_left {l\u2081 l\u2082 : list A} (t\u2081 : list A) : l\u2081 ~ l\u2082 \u2192 (l\u2081++t\u2081) ~ (l\u2082++t\u2081) :=\nassume p, perm.induction_on p\n  !perm.refl\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, skip x r\u2081)\n  (\u03bb x y l, !swap)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\ntheorem perm_app_right (l : list A) {t\u2081 t\u2082 : list A} : t\u2081 ~ t\u2082 \u2192 (l++t\u2081) ~ (l++t\u2082) :=\nlist.induction_on l\n  (\u03bb p, p)\n  (\u03bb x xs r p, skip x (r p))\n\ntheorem perm_app [congr] {l\u2081 l\u2082 t\u2081 t\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 t\u2081 ~ t\u2082 \u2192 (l\u2081++t\u2081) ~ (l\u2082++t\u2082) :=\nassume p\u2081 p\u2082, trans (perm_app_left t\u2081 p\u2081) (perm_app_right l\u2082 p\u2082)\n\ntheorem perm_app_cons (a : A) {h\u2081 h\u2082 t\u2081 t\u2082 : list A} : h\u2081 ~ h\u2082 \u2192 t\u2081 ~ t\u2082 \u2192 (h\u2081 ++ (a::t\u2081)) ~ (h\u2082 ++ (a::t\u2082)) :=\nassume p\u2081 p\u2082, perm_app p\u2081 (skip a p\u2082)\n\ntheorem perm_cons_app (a : A) : \u2200 (l : list A), (a::l) ~ (l ++ [a])\n| []      := !perm.refl\n| (x::xs) := calc\n  a::x::xs ~ x::a::xs     : swap x a xs\n       ... ~ x::(xs++[a]) : skip x (perm_cons_app xs)\n\ntheorem perm_cons_app_simp [simp] (a : A) : \u2200 (l : list A), (l ++ [a]) ~ (a::l) :=\ntake l, perm.symm !perm_cons_app\n\ntheorem perm_app_comm [simp] {l\u2081 l\u2082 : list A} : (l\u2081++l\u2082) ~ (l\u2082++l\u2081) :=\nlist.induction_on l\u2081\n  (by rewrite [append_nil_right, append_nil_left])\n  (\u03bb a t r, calc\n    a::(t++l\u2082) ~ a::(l\u2082++t)   : skip a r\n          ...  ~ l\u2082++t++[a]   : perm_cons_app\n          ...  = l\u2082++(t++[a]) : append.assoc\n          ...  ~ l\u2082++(a::t)   : perm_app_right l\u2082 (perm.symm (perm_cons_app a t)))\n\ntheorem length_eq_length_of_perm {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 length l\u2081 = length l\u2082 :=\nassume p, perm.induction_on p\n  rfl\n  (\u03bb x l\u2081 l\u2082 p r, by rewrite [*length_cons, r])\n  (\u03bb x y l, by rewrite *length_cons)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, eq.trans r\u2081 r\u2082)\n\ntheorem eq_singleton_of_perm_inv (a : A) {l : list A} : [a] ~ l \u2192 l = [a] :=\nhave gen : \u2200 l\u2082, perm l\u2082 l \u2192 l\u2082 = [a] \u2192 l = [a], from\n  take l\u2082, assume p, perm.induction_on p\n    (\u03bb e, e)\n    (\u03bb x l\u2081 l\u2082 p r e,\n      begin\n        injection e with e\u2081 e\u2082,\n        rewrite [e\u2081, e\u2082 at p],\n        have h\u2081 : l\u2082 = [], from eq_nil_of_perm_nil p,\n        substvars\n      end)\n    (\u03bb x y l e, by injection e; contradiction)\n    (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082 e, r\u2082 (r\u2081 e)),\nassume p, gen [a] p rfl\n\ntheorem eq_singleton_of_perm (a b : A) : [a] ~ [b] \u2192 a = b :=\nassume p,\nbegin\n  injection eq_singleton_of_perm_inv a p with e\u2081,\n  rewrite e\u2081\nend\n\ntheorem perm_rev : \u2200 (l : list A), l ~ (reverse l)\n| []      := nil\n| (x::xs) := calc\n  x::xs ~ xs++[x]           : perm_cons_app x xs\n    ... ~ reverse xs ++ [x] : perm_app_left [x] (perm_rev xs)\n    ... = reverse (x::xs)   : by rewrite [reverse_cons, concat_eq_append]\n\ntheorem perm_rev_simp [simp] : \u2200 (l : list A), (reverse l) ~ l :=\ntake l, perm.symm (perm_rev l)\n\ntheorem perm_middle (a : A) (l\u2081 l\u2082 : list A) : (a::l\u2081)++l\u2082 ~ l\u2081++(a::l\u2082) :=\ncalc\n  (a::l\u2081) ++ l\u2082 = a::(l\u2081++l\u2082)   : rfl\n           ...  ~ l\u2081++l\u2082++[a]   : perm_cons_app\n           ...  = l\u2081++(l\u2082++[a]) : append.assoc\n           ...  ~ l\u2081++(a::l\u2082)   : perm_app_right l\u2081 (perm.symm (perm_cons_app a l\u2082))\n\ntheorem perm_middle_simp [simp] (a : A) (l\u2081 l\u2082 : list A) : l\u2081++(a::l\u2082) ~ (a::l\u2081)++l\u2082 :=\nperm.symm !perm_middle\n\ntheorem perm_cons_app_cons {l l\u2081 l\u2082 : list A} (a : A) : l ~ l\u2081++l\u2082 \u2192 a::l ~ l\u2081++(a::l\u2082) :=\nassume p, calc\n  a::l ~ l++[a]        : perm_cons_app\n   ... ~ l\u2081++l\u2082++[a]   : perm_app_left [a] p\n   ... = l\u2081++(l\u2082++[a]) : append.assoc\n   ... ~ l\u2081++(a::l\u2082)   : perm_app_right l\u2081 (perm.symm (perm_cons_app a l\u2082))\n\nopen decidable\ntheorem perm_erase [decidable_eq A] {a : A} : \u2200 {l : list A}, a \u2208 l \u2192 l ~ a::(erase a l)\n| []     h := absurd h !not_mem_nil\n| (x::t) h :=\n  by_cases\n    (assume aeqx  : a = x, by rewrite [aeqx, erase_cons_head])\n    (assume naeqx : a \u2260 x,\n      have aint : a \u2208 t,             from mem_of_ne_of_mem naeqx h,\n      have aux : t ~ a :: erase a t, from perm_erase aint,\n      calc x::t ~ x::a::(erase a t)   : skip x aux\n            ... ~ a::x::(erase a t)   : swap\n            ... = a::(erase a (x::t)) : by rewrite [!erase_cons_tail naeqx])\n\ntheorem erase_perm_erase_of_perm [congr] [decidable_eq A] (a : A) {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 erase a l\u2081 ~ erase a l\u2082 :=\nassume p, perm.induction_on p\n  nil\n  (\u03bb x t\u2081 t\u2082 p r,\n    by_cases\n      (assume aeqx  : a = x, by rewrite [aeqx, *erase_cons_head]; exact p)\n      (assume naeqx : a \u2260 x, by rewrite [*erase_cons_tail _ naeqx]; exact (skip x r)))\n  (\u03bb x y l,\n    by_cases\n      (assume aeqx : a = x,\n        by_cases\n          (assume aeqy  : a = y, by rewrite [-aeqx, -aeqy])\n          (assume naeqy : a \u2260 y, by rewrite [-aeqx, erase_cons_tail _ naeqy, *erase_cons_head]))\n      (assume naeqx : a \u2260 x,\n        by_cases\n          (assume aeqy  : a = y, by rewrite [-aeqy, erase_cons_tail _ naeqx, *erase_cons_head])\n          (assume naeqy : a \u2260 y, by rewrite[erase_cons_tail _ naeqx, *erase_cons_tail _ naeqy, erase_cons_tail _ naeqx];\n                                    exact !swap)))\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\ntheorem perm_induction_on {P : list A \u2192 list A \u2192 Prop} {l\u2081 l\u2082 : list A} (p : l\u2081 ~ l\u2082)\n   (h\u2081 : P [] [])\n   (h\u2082 : \u2200 x l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 P l\u2081 l\u2082 \u2192 P (x::l\u2081) (x::l\u2082))\n   (h\u2083 : \u2200 x y l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 P l\u2081 l\u2082 \u2192 P (y::x::l\u2081) (x::y::l\u2082))\n   (h\u2084 : \u2200 l\u2081 l\u2082 l\u2083, l\u2081 ~ l\u2082 \u2192 l\u2082 ~ l\u2083 \u2192 P l\u2081 l\u2082 \u2192 P l\u2082 l\u2083 \u2192 P l\u2081 l\u2083)\n   : P l\u2081 l\u2082 :=\nhave P_refl : \u2200 l, P l l\n  | []      := h\u2081\n  | (x::xs) := h\u2082 x xs xs !perm.refl (P_refl xs),\nperm.induction_on p h\u2081 h\u2082 (\u03bb x y l, h\u2083 x y l l !perm.refl !P_refl) h\u2084\n\ntheorem xswap {l\u2081 l\u2082 : list A} (x y : A) : l\u2081 ~ l\u2082 \u2192 x::y::l\u2081 ~ y::x::l\u2082 :=\nassume p, calc\n  x::y::l\u2081  ~  y::x::l\u2081  : swap\n        ... ~  y::x::l\u2082  : skip y (skip x p)\n\ntheorem perm_map [congr] (f : A \u2192 B) {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 map f l\u2081 ~ map f l\u2082 :=\nassume p, perm_induction_on p\n  nil\n  (\u03bb x l\u2081 l\u2082 p r, skip (f x) r)\n  (\u03bb x y l\u2081 l\u2082 p r, xswap (f y) (f x) r)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\nlemma perm_of_qeq {a : A} {l\u2081 l\u2082 : list A} : l\u2081\u2248a|l\u2082 \u2192 l\u2081~a::l\u2082 :=\nassume q, qeq.induction_on q\n  (\u03bb h, !perm.refl)\n  (\u03bb b t\u2081 t\u2082 q\u2081 r\u2081, calc\n     b::t\u2082 ~ b::a::t\u2081 : skip b r\u2081\n       ... ~ a::b::t\u2081 : swap)\n\n/- permutation is decidable if A has decidable equality -/\nsection dec\nopen decidable\nvariable [Ha : decidable_eq A]\ninclude Ha\n\ndefinition decidable_perm_aux : \u2200 (n : nat) (l\u2081 l\u2082 : list A), length l\u2081 = n \u2192 length l\u2082 = n \u2192 decidable (l\u2081 ~ l\u2082)\n| 0     l\u2081      l\u2082 H\u2081 H\u2082 :=\n  have l\u2081n : l\u2081 = [], from eq_nil_of_length_eq_zero H\u2081,\n  have l\u2082n : l\u2082 = [], from eq_nil_of_length_eq_zero H\u2082,\n  by rewrite [l\u2081n, l\u2082n]; exact (inl perm.nil)\n| (n+1) (x::t\u2081) l\u2082 H\u2081 H\u2082 :=\n  by_cases\n    (assume xinl\u2082 : x \u2208 l\u2082,\n      let t\u2082 : list A := erase x l\u2082 in\n      have len_t\u2081 : length t\u2081 = n,         begin injection H\u2081 with e, exact e end,\n      have length t\u2082 = pred (length l\u2082), from length_erase_of_mem xinl\u2082,\n      have length t\u2082 = n,                by rewrite [this, H\u2082],\n      match decidable_perm_aux n t\u2081 t\u2082 len_t\u2081 this with\n      | inl p  := inl (calc\n          x::t\u2081 ~ x::(erase x l\u2082) : skip x p\n           ...  ~ l\u2082              : perm_erase xinl\u2082)\n      | inr np := inr (\u03bb p : x::t\u2081 ~ l\u2082,\n        have erase x (x::t\u2081) ~ erase x l\u2082, from erase_perm_erase_of_perm x p,\n        have t\u2081 ~ erase x l\u2082, by rewrite [erase_cons_head at this]; exact this,\n        absurd this np)\n      end)\n    (assume nxinl\u2082 : x \u2209 l\u2082,\n      inr (\u03bb p : x::t\u2081 ~ l\u2082, absurd (mem_perm p !mem_cons) nxinl\u2082))\n\ndefinition decidable_perm [instance] : \u2200 (l\u2081 l\u2082 : list A), decidable (l\u2081 ~ l\u2082) :=\n\u03bb l\u2081 l\u2082,\nby_cases\n  (assume eql : length l\u2081 = length l\u2082,\n    decidable_perm_aux (length l\u2082) l\u2081 l\u2082 eql rfl)\n  (assume neql : length l\u2081 \u2260 length l\u2082,\n    inr (\u03bb p : l\u2081 ~ l\u2082, absurd (length_eq_length_of_perm p) neql))\nend dec\n\n-- Auxiliary theorem for performing cases-analysis on l\u2082.\n-- We use it to prove perm_inv_core.\nprivate theorem discr {P : Prop} {a b : A} {l\u2081 l\u2082 l\u2083 : list A} :\n    a::l\u2081 = l\u2082++(b::l\u2083)                    \u2192\n    (l\u2082 = [] \u2192 a = b \u2192 l\u2081 = l\u2083 \u2192 P)        \u2192\n    (\u2200 t, l\u2082 = a::t \u2192 l\u2081 = t++(b::l\u2083) \u2192 P) \u2192 P :=\nmatch l\u2082 with\n| []   := \u03bb e h\u2081 h\u2082, by injection e with e\u2081 e\u2082; exact h\u2081 rfl e\u2081 e\u2082\n| h::t := \u03bb e h\u2081 h\u2082,\n  begin\n    injection e with e\u2081 e\u2082,\n    rewrite e\u2081 at h\u2082,\n    exact h\u2082 t rfl e\u2082\n  end\nend\n\n-- Auxiliary theorem for performing cases-analysis on l\u2082.\n-- We use it to prove perm_inv_core.\nprivate theorem discr\u2082 {P : Prop} {a b c : A} {l\u2081 l\u2082 l\u2083 : list A} :\n    a::b::l\u2081 = l\u2082++(c::l\u2083)                     \u2192\n    (l\u2082 = [] \u2192 l\u2083 = b::l\u2081 \u2192 a = c \u2192 P)         \u2192\n    (l\u2082 = [a] \u2192 b = c \u2192 l\u2081 = l\u2083 \u2192 P)           \u2192\n    (\u2200 t, l\u2082 = a::b::t \u2192 l\u2081 = t++(c::l\u2083) \u2192 P)  \u2192 P :=\nmatch l\u2082 with\n| []   := \u03bb e H\u2081 H\u2082 H\u2083,\n  begin\n    injection e with a_eq_c b_l\u2081_eq_l\u2083,\n    exact H\u2081 rfl (eq.symm b_l\u2081_eq_l\u2083) a_eq_c\n  end\n| [h\u2081] := \u03bb e H\u2081 H\u2082 H\u2083,\n  begin\n    rewrite [append_cons at e, append_nil_left at e],\n    injection e  with a_eq_h\u2081 b_eq_c l\u2081_eq_l\u2083,\n    rewrite [a_eq_h\u2081 at H\u2082, b_eq_c at H\u2082, l\u2081_eq_l\u2083 at H\u2082],\n    exact H\u2082 rfl rfl rfl\n  end\n| h\u2081::h\u2082::t\u2082 := \u03bb e H\u2081 H\u2082 H\u2083,\n  begin\n    injection e with a_eq_h\u2081 b_eq_h\u2082 l\u2081_eq,\n    rewrite [a_eq_h\u2081 at H\u2083, b_eq_h\u2082 at H\u2083],\n    exact H\u2083 t\u2082 rfl l\u2081_eq\n  end\nend\n\n/- permutation inversion -/\ntheorem perm_inv_core {l\u2081 l\u2082 : list A} (p' : l\u2081 ~ l\u2082) : \u2200 {a s\u2081 s\u2082}, l\u2081\u2248a|s\u2081 \u2192 l\u2082\u2248a|s\u2082 \u2192 s\u2081 ~ s\u2082 :=\nperm_induction_on p'\n  (\u03bb a s\u2081 s\u2082 e\u2081 e\u2082,\n    have innil : a \u2208 [], from mem_head_of_qeq e\u2081,\n    absurd innil !not_mem_nil)\n  (\u03bb x t\u2081 t\u2082 p (r : \u2200{a s\u2081 s\u2082}, t\u2081\u2248a|s\u2081 \u2192 t\u2082\u2248a|s\u2082 \u2192 s\u2081 ~ s\u2082) a s\u2081 s\u2082 e\u2081 e\u2082,\n    obtain (s\u2081\u2081 s\u2081\u2082 : list A) (C\u2081\u2081 : s\u2081 = s\u2081\u2081 ++ s\u2081\u2082) (C\u2081\u2082 : x::t\u2081 = s\u2081\u2081++(a::s\u2081\u2082)), from qeq_split e\u2081,\n    obtain (s\u2082\u2081 s\u2082\u2082 : list A) (C\u2082\u2081 : s\u2082 = s\u2082\u2081 ++ s\u2082\u2082) (C\u2082\u2082 : x::t\u2082 = s\u2082\u2081++(a::s\u2082\u2082)), from qeq_split e\u2082,\n    discr C\u2081\u2082\n      (\u03bb (s\u2081\u2081_eq : s\u2081\u2081 = []) (x_eq_a : x = a) (t\u2081_eq : t\u2081 = s\u2081\u2082),\n        have s\u2081_p : s\u2081 ~ t\u2082, from calc\n            s\u2081  = s\u2081\u2081 ++ s\u2081\u2082 : C\u2081\u2081\n            ... = t\u2081         : by rewrite [-t\u2081_eq, s\u2081\u2081_eq, append_nil_left]\n            ... ~ t\u2082         : p,\n        discr C\u2082\u2082\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = []) (x_eq_a : x = a) (t\u2082_eq: t\u2082 = s\u2082\u2082),\n            proof calc\n              s\u2081  ~ t\u2082         : s\u2081_p\n              ... = s\u2082\u2081 ++ s\u2082\u2082 : by rewrite [-t\u2082_eq, s\u2082\u2081_eq, append_nil_left]\n              ... = s\u2082         : by rewrite C\u2082\u2081\n            qed)\n          (\u03bb (ts\u2082\u2081 : list A) (s\u2082\u2081_eq : s\u2082\u2081 = x::ts\u2082\u2081) (t\u2082_eq : t\u2082 = ts\u2082\u2081++(a::s\u2082\u2082)),\n            proof calc\n              s\u2081  ~ t\u2082             : s\u2081_p\n              ... = ts\u2082\u2081++(a::s\u2082\u2082) : t\u2082_eq\n              ... ~ (a::ts\u2082\u2081)++s\u2082\u2082 : !perm_middle\n              ... = s\u2082\u2081 ++ s\u2082\u2082     : by rewrite [-x_eq_a, -s\u2082\u2081_eq]\n              ... = s\u2082             : by rewrite C\u2082\u2081\n            qed))\n      (\u03bb (ts\u2081\u2081 : list A) (s\u2081\u2081_eq : s\u2081\u2081 = x::ts\u2081\u2081) (t\u2081_eq : t\u2081 = ts\u2081\u2081++(a::s\u2081\u2082)),\n        have t\u2081_qeq : t\u2081 \u2248 a|(ts\u2081\u2081++s\u2081\u2082), by rewrite t\u2081_eq; exact !qeq_app,\n        have s\u2081_eq : s\u2081 = x::(ts\u2081\u2081++s\u2081\u2082), from calc\n          s\u2081  = s\u2081\u2081 ++ s\u2081\u2082       : C\u2081\u2081\n          ... = x::(ts\u2081\u2081++ s\u2081\u2082)  : by rewrite s\u2081\u2081_eq,\n        discr C\u2082\u2082\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = []) (x_eq_a : x = a) (t\u2082_eq: t\u2082 = s\u2082\u2082),\n            proof calc\n              s\u2081  = a::(ts\u2081\u2081++s\u2081\u2082) : by rewrite [s\u2081_eq, x_eq_a]\n              ... ~ ts\u2081\u2081++(a::s\u2081\u2082) : !perm_middle\n              ... = t\u2081             : t\u2081_eq\n              ... ~ t\u2082             : p\n              ... = s\u2082             : by rewrite [t\u2082_eq, C\u2082\u2081, s\u2082\u2081_eq, append_nil_left]\n            qed)\n          (\u03bb (ts\u2082\u2081 : list A) (s\u2082\u2081_eq : s\u2082\u2081 = x::ts\u2082\u2081) (t\u2082_eq : t\u2082 = ts\u2082\u2081++(a::s\u2082\u2082)),\n            have t\u2082_qeq : t\u2082 \u2248 a|(ts\u2082\u2081++s\u2082\u2082), by rewrite t\u2082_eq; exact !qeq_app,\n            proof calc\n              s\u2081  = x::(ts\u2081\u2081++s\u2081\u2082) : s\u2081_eq\n              ... ~ x::(ts\u2082\u2081++s\u2082\u2082) : skip x (r t\u2081_qeq t\u2082_qeq)\n              ... = s\u2082             : by rewrite [-append_cons, -s\u2082\u2081_eq, C\u2082\u2081]\n            qed)))\n  (\u03bb x y t\u2081 t\u2082 p (r : \u2200{a s\u2081 s\u2082}, t\u2081\u2248a|s\u2081 \u2192 t\u2082\u2248a|s\u2082 \u2192 s\u2081 ~ s\u2082) a s\u2081 s\u2082 e\u2081 e\u2082,\n    obtain (s\u2081\u2081 s\u2081\u2082 : list A) (C\u2081\u2081 : s\u2081 = s\u2081\u2081 ++ s\u2081\u2082) (C\u2081\u2082 : y::x::t\u2081 = s\u2081\u2081++(a::s\u2081\u2082)), from qeq_split e\u2081,\n    obtain (s\u2082\u2081 s\u2082\u2082 : list A) (C\u2082\u2081 : s\u2082 = s\u2082\u2081 ++ s\u2082\u2082) (C\u2082\u2082 : x::y::t\u2082 = s\u2082\u2081++(a::s\u2082\u2082)), from qeq_split e\u2082,\n    discr\u2082 C\u2081\u2082\n      (\u03bb (s\u2081\u2081_eq : s\u2081\u2081 = [])  (s\u2081\u2082_eq : s\u2081\u2082 = x::t\u2081) (y_eq_a : y = a),\n        have s\u2081_p : s\u2081 ~ x::t\u2082, from calc\n            s\u2081  = s\u2081\u2081 ++ s\u2081\u2082 : C\u2081\u2081\n            ... = x::t\u2081      : by rewrite [s\u2081\u2082_eq, s\u2081\u2081_eq, append_nil_left]\n            ... ~ x::t\u2082      : skip x p,\n        discr\u2082 C\u2082\u2082\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = [])  (s\u2082\u2082_eq : s\u2082\u2082 = y::t\u2082) (x_eq_a : x = a),\n            proof calc\n              s\u2081  ~ x::t\u2082      : s\u2081_p\n              ... = s\u2082\u2081 ++ s\u2082\u2082 : by rewrite [x_eq_a, -y_eq_a, -s\u2082\u2082_eq, s\u2082\u2081_eq, append_nil_left]\n              ... = s\u2082         : by rewrite C\u2082\u2081\n            qed)\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = [x]) (y_eq_a : y = a) (t\u2082_eq : t\u2082 = s\u2082\u2082),\n            proof calc\n              s\u2081  ~ x::t\u2082      : s\u2081_p\n              ... = s\u2082\u2081 ++ s\u2082\u2082 : by rewrite [t\u2082_eq, s\u2082\u2081_eq, append_cons]\n              ... = s\u2082         : by rewrite C\u2082\u2081\n            qed)\n          (\u03bb (ts\u2082\u2081 : list A) (s\u2082\u2081_eq : s\u2082\u2081 = x::y::ts\u2082\u2081) (t\u2082_eq : t\u2082 = ts\u2082\u2081++(a::s\u2082\u2082)),\n            proof calc\n              s\u2081  ~ x::t\u2082               : s\u2081_p\n              ... = x::(ts\u2082\u2081++(y::s\u2082\u2082)) : by rewrite [t\u2082_eq, -y_eq_a]\n              ... ~ x::y::(ts\u2082\u2081++s\u2082\u2082)   : skip x !perm_middle\n              ... = s\u2082\u2081 ++ s\u2082\u2082          : by rewrite [s\u2082\u2081_eq, append_cons]\n              ... = s\u2082                  : by rewrite C\u2082\u2081\n            qed))\n      (\u03bb (s\u2081\u2081_eq : s\u2081\u2081 = [y]) (x_eq_a : x = a) (t\u2081_eq : t\u2081 = s\u2081\u2082),\n        have s\u2081_p : s\u2081 ~ y::t\u2082, from calc\n             s\u2081  = y::t\u2081 : by rewrite [C\u2081\u2081, s\u2081\u2081_eq, t\u2081_eq]\n             ... ~ y::t\u2082 : skip y p,\n        discr\u2082 C\u2082\u2082\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = [])  (s\u2082\u2082_eq : s\u2082\u2082 = y::t\u2082) (x_eq_a : x = a),\n            proof calc\n              s\u2081  ~ y::t\u2082      : s\u2081_p\n              ... = s\u2082\u2081 ++ s\u2082\u2082 : by rewrite [s\u2082\u2081_eq, s\u2082\u2082_eq]\n              ... = s\u2082         : by rewrite C\u2082\u2081\n            qed)\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = [x]) (y_eq_a : y = a) (t\u2082_eq : t\u2082 = s\u2082\u2082),\n            proof calc\n              s\u2081  ~ y::t\u2082      : s\u2081_p\n              ... = s\u2082\u2081 ++ s\u2082\u2082 : by rewrite [s\u2082\u2081_eq, t\u2082_eq, y_eq_a, -x_eq_a]\n              ... = s\u2082         : by rewrite C\u2082\u2081\n            qed)\n          (\u03bb (ts\u2082\u2081 : list A) (s\u2082\u2081_eq : s\u2082\u2081 = x::y::ts\u2082\u2081) (t\u2082_eq : t\u2082 = ts\u2082\u2081++(a::s\u2082\u2082)),\n            proof calc\n              s\u2081  ~ y::t\u2082               : s\u2081_p\n              ... = y::(ts\u2082\u2081++(x::s\u2082\u2082)) : by rewrite [t\u2082_eq, -x_eq_a]\n              ... ~ y::x::(ts\u2082\u2081++s\u2082\u2082)   : skip y !perm_middle\n              ... ~ x::y::(ts\u2082\u2081++s\u2082\u2082)   : swap\n              ... = s\u2082\u2081 ++ s\u2082\u2082          : by rewrite [s\u2082\u2081_eq]\n              ... = s\u2082                  : by rewrite C\u2082\u2081\n            qed))\n      (\u03bb (ts\u2081\u2081 : list A) (s\u2081\u2081_eq : s\u2081\u2081 = y::x::ts\u2081\u2081) (t\u2081_eq : t\u2081 = ts\u2081\u2081++(a::s\u2081\u2082)),\n        have s\u2081_eq  : s\u2081 = y::x::(ts\u2081\u2081++s\u2081\u2082), by rewrite [C\u2081\u2081, s\u2081\u2081_eq],\n        discr\u2082 C\u2082\u2082\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = [])  (s\u2082\u2082_eq : s\u2082\u2082 = y::t\u2082) (x_eq_a : x = a),\n            proof calc\n              s\u2081  = y::a::(ts\u2081\u2081++s\u2081\u2082)   : by rewrite [s\u2081_eq, x_eq_a]\n              ... ~ y::(ts\u2081\u2081++(a::s\u2081\u2082)) : skip y !perm_middle\n              ... = y::t\u2081               : by rewrite t\u2081_eq\n              ... ~ y::t\u2082               : skip y p\n              ... = s\u2082\u2081 ++ s\u2082\u2082          : by rewrite [s\u2082\u2081_eq, s\u2082\u2082_eq]\n              ... = s\u2082                  : by rewrite C\u2082\u2081\n            qed)\n          (\u03bb (s\u2082\u2081_eq : s\u2082\u2081 = [x]) (y_eq_a : y = a) (t\u2082_eq : t\u2082 = s\u2082\u2082),\n            proof calc\n              s\u2081  = y::x::(ts\u2081\u2081++s\u2081\u2082)   : by rewrite s\u2081_eq\n              ... ~ x::y::(ts\u2081\u2081++s\u2081\u2082)   : swap\n              ... = x::a::(ts\u2081\u2081++s\u2081\u2082)   : by rewrite y_eq_a\n              ... ~ x::(ts\u2081\u2081++(a::s\u2081\u2082)) : skip x !perm_middle\n              ... = x::t\u2081               : by rewrite t\u2081_eq\n              ... ~ x::t\u2082               : skip x p\n              ... = s\u2082\u2081 ++ s\u2082\u2082          : by rewrite [t\u2082_eq, s\u2082\u2081_eq]\n              ... = s\u2082                  : by rewrite C\u2082\u2081\n            qed)\n          (\u03bb (ts\u2082\u2081 : list A) (s\u2082\u2081_eq : s\u2082\u2081 = x::y::ts\u2082\u2081) (t\u2082_eq : t\u2082 = ts\u2082\u2081++(a::s\u2082\u2082)),\n            have t\u2081_qeq : t\u2081 \u2248 a|(ts\u2081\u2081++s\u2081\u2082),    by rewrite t\u2081_eq; exact !qeq_app,\n            have t\u2082_qeq : t\u2082 \u2248 a|(ts\u2082\u2081++s\u2082\u2082),    by rewrite t\u2082_eq; exact !qeq_app,\n            have p_aux  : ts\u2081\u2081++s\u2081\u2082 ~ ts\u2082\u2081++s\u2082\u2082, from r t\u2081_qeq t\u2082_qeq,\n            proof calc\n              s\u2081  = y::x::(ts\u2081\u2081++s\u2081\u2082)   : by rewrite s\u2081_eq\n              ... ~ y::x::(ts\u2082\u2081++s\u2082\u2082)   : skip y (skip x p_aux)\n              ... ~ x::y::(ts\u2082\u2081++s\u2082\u2082)   : swap\n              ... = s\u2082\u2081 ++ s\u2082\u2082          : by rewrite s\u2082\u2081_eq\n              ... = s\u2082                  : by rewrite C\u2082\u2081\n            qed)))\n  (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082\n     (r\u2081 : \u2200{a s\u2081 s\u2082}, t\u2081 \u2248 a|s\u2081 \u2192 t\u2082\u2248a|s\u2082 \u2192 s\u2081 ~ s\u2082)\n     (r\u2082 : \u2200{a s\u2081 s\u2082}, t\u2082 \u2248 a|s\u2081 \u2192 t\u2083\u2248a|s\u2082 \u2192 s\u2081 ~ s\u2082)\n     a s\u2081 s\u2082 e\u2081 e\u2082,\n    have a \u2208 t\u2081, from mem_head_of_qeq e\u2081,\n    have a \u2208 t\u2082, from mem_perm p\u2081 this,\n    obtain (t\u2082' : list A) (e\u2082' : t\u2082\u2248a|t\u2082'), from qeq_of_mem this,\n    calc s\u2081  ~ t\u2082' : r\u2081 e\u2081 e\u2082'\n        ...  ~ s\u2082  : r\u2082 e\u2082' e\u2082)\n\ntheorem perm_cons_inv {a : A} {l\u2081 l\u2082 : list A} : a::l\u2081 ~ a::l\u2082 \u2192 l\u2081 ~ l\u2082 :=\nassume p, perm_inv_core p (qeq.qhead a l\u2081) (qeq.qhead a l\u2082)\n\ntheorem perm_app_inv {a : A} {l\u2081 l\u2082 l\u2083 l\u2084 : list A} : l\u2081++(a::l\u2082) ~ l\u2083++(a::l\u2084) \u2192 l\u2081++l\u2082 ~ l\u2083++l\u2084 :=\nassume p : l\u2081++(a::l\u2082) ~ l\u2083++(a::l\u2084),\n  have p' : a::(l\u2081++l\u2082) ~ a::(l\u2083++l\u2084), from calc\n    a::(l\u2081++l\u2082) ~ l\u2081++(a::l\u2082) : perm_middle\n          ...   ~ l\u2083++(a::l\u2084) : p\n          ...   ~ a::(l\u2083++l\u2084) : perm.symm (!perm_middle),\n  perm_cons_inv p'\n\nsection foldl\n  variables {f : B \u2192 A \u2192 B} {l\u2081 l\u2082 : list A}\n  variable rcomm : right_commutative f\n  include  rcomm\n\n  theorem foldl_eq_of_perm : l\u2081 ~ l\u2082 \u2192 \u2200 b, foldl f b l\u2081 = foldl f b l\u2082 :=\n  assume p, perm_induction_on p\n    (\u03bb b, by rewrite *foldl_nil)\n    (\u03bb x t\u2081 t\u2082 p r b, calc\n       foldl f b (x::t\u2081) = foldl f (f b x) t\u2081 : foldl_cons\n               ...       = foldl f (f b x) t\u2082 : r (f b x)\n               ...       = foldl f b (x::t\u2082)  : foldl_cons)\n    (\u03bb x y t\u2081 t\u2082 p r b, calc\n       foldl f b (y :: x :: t\u2081) = foldl f (f (f b y) x) t\u2081 : by rewrite foldl_cons\n                     ...        = foldl f (f (f b x) y) t\u2081 : by rewrite rcomm\n                     ...        = foldl f (f (f b x) y) t\u2082 : r (f (f b x) y)\n                     ...        = foldl f b (x :: y :: t\u2082) : by rewrite foldl_cons)\n    (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 r\u2081 r\u2082 b, eq.trans (r\u2081 b) (r\u2082 b))\nend foldl\n\nsection foldr\n  variables {f : A \u2192 B \u2192 B} {l\u2081 l\u2082 : list A}\n  variable lcomm : left_commutative f\n  include  lcomm\n\n  theorem foldr_eq_of_perm : l\u2081 ~ l\u2082 \u2192 \u2200 b, foldr f b l\u2081 = foldr f b l\u2082 :=\n  assume p, perm_induction_on p\n    (\u03bb b, by rewrite *foldl_nil)\n    (\u03bb x t\u2081 t\u2082 p r b, calc\n       foldr f b (x::t\u2081) = f x (foldr f b t\u2081) : foldr_cons\n               ...       = f x (foldr f b t\u2082) : by rewrite [r b]\n               ...       = foldr f b (x::t\u2082)  : foldr_cons)\n    (\u03bb x y t\u2081 t\u2082 p r b, calc\n       foldr f b (y :: x :: t\u2081) = f y (f x (foldr f b t\u2081)) : by rewrite foldr_cons\n                  ...           = f x (f y (foldr f b t\u2081)) : by rewrite lcomm\n                  ...           = f x (f y (foldr f b t\u2082)) : by rewrite [r b]\n                  ...           = foldr f b (x :: y :: t\u2082) : by rewrite foldr_cons)\n    (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 r\u2081 r\u2082 a, eq.trans (r\u2081 a) (r\u2082 a))\nend foldr\n\ntheorem perm_erase_dup_of_perm [congr] [H : decidable_eq A] {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 erase_dup l\u2081 ~ erase_dup l\u2082 :=\nassume p, perm_induction_on p\n  nil\n  (\u03bb x t\u2081 t\u2082 p r, by_cases\n    (\u03bb xint\u2081  : x \u2208 t\u2081,\n      have xint\u2082 : x \u2208 t\u2082, from mem_of_mem_erase_dup (mem_perm r (mem_erase_dup xint\u2081)),\n      by rewrite [erase_dup_cons_of_mem xint\u2081, erase_dup_cons_of_mem xint\u2082]; exact r)\n    (\u03bb nxint\u2081 : x \u2209 t\u2081,\n      have nxint\u2082 : x \u2209 t\u2082, from\n         assume xint\u2082 : x \u2208 t\u2082, absurd (mem_of_mem_erase_dup (mem_perm (perm.symm r) (mem_erase_dup xint\u2082))) nxint\u2081,\n      by rewrite [erase_dup_cons_of_not_mem nxint\u2082, erase_dup_cons_of_not_mem nxint\u2081]; exact (skip x r)))\n  (\u03bb y x t\u2081 t\u2082 p r, by_cases\n    (\u03bb xinyt\u2081  : x \u2208 y::t\u2081, by_cases\n      (\u03bb yint\u2081  : y \u2208 t\u2081,\n        have yint\u2082  : y \u2208 t\u2082,    from mem_of_mem_erase_dup (mem_perm r (mem_erase_dup yint\u2081)),\n        have yinxt\u2082 : y \u2208 x::t\u2082, from or.inr (yint\u2082),\n        or.elim (eq_or_mem_of_mem_cons xinyt\u2081)\n          (\u03bb xeqy  : x = y,\n            have xint\u2082 : x \u2208 t\u2082, by rewrite [-xeqy at yint\u2082]; exact yint\u2082,\n            begin\n              rewrite [erase_dup_cons_of_mem xinyt\u2081, erase_dup_cons_of_mem yinxt\u2082,\n                       erase_dup_cons_of_mem yint\u2081, erase_dup_cons_of_mem xint\u2082],\n              exact r\n            end)\n          (\u03bb xint\u2081 : x \u2208 t\u2081,\n            have xint\u2082 : x \u2208 t\u2082, from mem_of_mem_erase_dup (mem_perm r (mem_erase_dup xint\u2081)),\n            begin\n              rewrite [erase_dup_cons_of_mem xinyt\u2081, erase_dup_cons_of_mem yinxt\u2082,\n                       erase_dup_cons_of_mem yint\u2081, erase_dup_cons_of_mem xint\u2082],\n              exact r\n            end))\n      (\u03bb nyint\u2081 : y \u2209 t\u2081,\n        have nyint\u2082 : y \u2209 t\u2082, from\n          assume yint\u2082 : y \u2208 t\u2082, absurd (mem_of_mem_erase_dup (mem_perm (perm.symm r) (mem_erase_dup yint\u2082))) nyint\u2081,\n        by_cases\n          (\u03bb xeqy  : x = y,\n            have nxint\u2082 : x \u2209 t\u2082, by rewrite [-xeqy at nyint\u2082]; exact nyint\u2082,\n            have yinxt\u2082 : y \u2208 x::t\u2082, by rewrite [xeqy]; exact !mem_cons,\n            begin\n              rewrite [erase_dup_cons_of_mem xinyt\u2081, erase_dup_cons_of_mem yinxt\u2082,\n                       erase_dup_cons_of_not_mem nyint\u2081, erase_dup_cons_of_not_mem nxint\u2082, xeqy],\n              exact skip y r\n            end)\n          (\u03bb xney : x \u2260 y,\n            have x \u2208 t\u2081, from or_resolve_right xinyt\u2081 xney,\n            have x \u2208 t\u2082, from mem_of_mem_erase_dup (mem_perm r (mem_erase_dup this)),\n            have y \u2209 x::t\u2082, from\n              suppose y \u2208 x::t\u2082, or.elim (eq_or_mem_of_mem_cons this)\n                (\u03bb h, absurd h (ne.symm xney))\n                (\u03bb h, absurd h nyint\u2082),\n            begin\n              rewrite [erase_dup_cons_of_mem xinyt\u2081, erase_dup_cons_of_not_mem `y \u2209 x::t\u2082`,\n                       erase_dup_cons_of_not_mem nyint\u2081, erase_dup_cons_of_mem `x \u2208 t\u2082`],\n              exact skip y r\n            end)))\n    (\u03bb nxinyt\u2081 : x \u2209 y::t\u2081,\n      have xney    : x \u2260 y,  from ne_of_not_mem_cons nxinyt\u2081,\n      have nxint\u2081  : x \u2209 t\u2081, from not_mem_of_not_mem_cons nxinyt\u2081,\n      have nxint\u2082  : x \u2209 t\u2082, from\n        assume xint\u2082 : x \u2208 t\u2082, absurd (mem_of_mem_erase_dup (mem_perm (perm.symm r) (mem_erase_dup xint\u2082))) nxint\u2081,\n      by_cases\n        (\u03bb yint\u2081  : y \u2208 t\u2081,\n          have yinxt\u2082 : y \u2208 x::t\u2082, from or.inr (mem_of_mem_erase_dup (mem_perm r (mem_erase_dup yint\u2081))),\n          begin\n            rewrite [erase_dup_cons_of_not_mem nxinyt\u2081, erase_dup_cons_of_mem yinxt\u2082,\n                     erase_dup_cons_of_mem yint\u2081, erase_dup_cons_of_not_mem nxint\u2082],\n            exact skip x r\n          end)\n        (\u03bb nyint\u2081 : y \u2209 t\u2081,\n          have nyinxt\u2082 : y \u2209 x::t\u2082, from\n            assume yinxt\u2082 : y \u2208 x::t\u2082, or.elim (eq_or_mem_of_mem_cons yinxt\u2082)\n              (\u03bb h, absurd h (ne.symm xney))\n              (\u03bb h, absurd (mem_of_mem_erase_dup (mem_perm (perm.symm r) (mem_erase_dup h))) nyint\u2081),\n          begin\n            rewrite [erase_dup_cons_of_not_mem nxinyt\u2081, erase_dup_cons_of_not_mem nyinxt\u2082,\n                     erase_dup_cons_of_not_mem nyint\u2081, erase_dup_cons_of_not_mem nxint\u2082],\n            exact xswap x y r\n          end)))\n  (\u03bb t\u2081 t\u2082 t\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\nsection perm_union\nvariable [H : decidable_eq A]\ninclude H\n\ntheorem perm_union_left {l\u2081 l\u2082 : list A} (t\u2081 : list A) : l\u2081 ~ l\u2082 \u2192 (union l\u2081 t\u2081) ~ (union l\u2082 t\u2081) :=\nassume p, perm.induction_on p\n  (by rewrite [nil_union])\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, by_cases\n     (\u03bb xint\u2081  : x \u2208 t\u2081, by rewrite [*union_cons_of_mem _ xint\u2081]; exact r\u2081)\n     (\u03bb nxint\u2081 : x \u2209 t\u2081, by rewrite [*union_cons_of_not_mem _ nxint\u2081]; exact (skip _ r\u2081)))\n  (\u03bb x y l, by_cases\n    (\u03bb yint  : y \u2208 t\u2081, by_cases\n      (\u03bb xint  : x \u2208 t\u2081,\n        by rewrite [*union_cons_of_mem _ xint, *union_cons_of_mem _ yint, *union_cons_of_mem _ xint])\n      (\u03bb nxint : x \u2209 t\u2081,\n        by rewrite [*union_cons_of_mem _ yint, *union_cons_of_not_mem _ nxint, union_cons_of_mem _ yint]))\n    (\u03bb nyint : y \u2209 t\u2081, by_cases\n      (\u03bb xint  : x \u2208 t\u2081,\n        by rewrite [*union_cons_of_mem _ xint, *union_cons_of_not_mem _ nyint, union_cons_of_mem _ xint])\n      (\u03bb nxint : x \u2209 t\u2081,\n        by rewrite [*union_cons_of_not_mem _ nxint, *union_cons_of_not_mem _ nyint, union_cons_of_not_mem _ nxint]; exact !swap)))\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\ntheorem perm_union_right (l : list A) {t\u2081 t\u2082 : list A} : t\u2081 ~ t\u2082 \u2192 (union l t\u2081) ~ (union l t\u2082) :=\nlist.induction_on l\n  (\u03bb p, by rewrite [*union_nil]; exact p)\n  (\u03bb x xs r p, by_cases\n    (\u03bb xint\u2081  : x \u2208 t\u2081,\n      have xint\u2082 : x \u2208 t\u2082, from mem_perm p xint\u2081,\n      by rewrite [union_cons_of_mem _ xint\u2081, union_cons_of_mem _ xint\u2082]; exact (r p))\n    (\u03bb nxint\u2081 : x \u2209 t\u2081,\n      have nxint\u2082 : x \u2209 t\u2082, from not_mem_perm p nxint\u2081,\n      by rewrite [union_cons_of_not_mem _ nxint\u2081, union_cons_of_not_mem _ nxint\u2082]; exact (skip _ (r p))))\n\ntheorem perm_union [congr] {l\u2081 l\u2082 t\u2081 t\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 t\u2081 ~ t\u2082 \u2192 (union l\u2081 t\u2081) ~ (union l\u2082 t\u2082) :=\nassume p\u2081 p\u2082, trans (perm_union_left t\u2081 p\u2081) (perm_union_right l\u2082 p\u2082)\nend perm_union\n\nsection perm_insert\nvariable [H : decidable_eq A]\ninclude H\n\ntheorem perm_insert [congr] (a : A) {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 (insert a l\u2081) ~ (insert a l\u2082) :=\nassume p, by_cases\n (\u03bb ainl\u2081  : a \u2208 l\u2081,\n   have ainl\u2082 : a \u2208 l\u2082, from mem_perm p ainl\u2081,\n   by rewrite [insert_eq_of_mem ainl\u2081, insert_eq_of_mem ainl\u2082]; exact p)\n (\u03bb nainl\u2081 : a \u2209 l\u2081,\n   have nainl\u2082 : a \u2209 l\u2082, from not_mem_perm p nainl\u2081,\n   by rewrite [insert_eq_of_not_mem nainl\u2081, insert_eq_of_not_mem nainl\u2082]; exact (skip _ p))\nend perm_insert\n\nsection perm_inter\nvariable [H : decidable_eq A]\ninclude H\n\ntheorem perm_inter_left {l\u2081 l\u2082 : list A} (t\u2081 : list A) : l\u2081 ~ l\u2082 \u2192 (inter l\u2081 t\u2081) ~ (inter l\u2082 t\u2081) :=\nassume p, perm.induction_on p\n  !perm.refl\n  (\u03bb x l\u2081 l\u2082 p\u2081 r\u2081, by_cases\n    (\u03bb xint\u2081  : x \u2208 t\u2081, by rewrite [*inter_cons_of_mem _ xint\u2081]; exact (skip x r\u2081))\n    (\u03bb nxint\u2081 : x \u2209 t\u2081, by rewrite [*inter_cons_of_not_mem _ nxint\u2081]; exact r\u2081))\n  (\u03bb x y l, by_cases\n    (\u03bb yint  : y \u2208 t\u2081, by_cases\n      (\u03bb xint  : x \u2208 t\u2081,\n        by rewrite [*inter_cons_of_mem _ xint, *inter_cons_of_mem _ yint, *inter_cons_of_mem _ xint];\n           exact !swap)\n      (\u03bb nxint : x \u2209 t\u2081,\n        by rewrite [*inter_cons_of_mem _ yint, *inter_cons_of_not_mem _ nxint, inter_cons_of_mem _ yint]))\n    (\u03bb nyint : y \u2209 t\u2081, by_cases\n      (\u03bb xint  : x \u2208 t\u2081,\n        by rewrite [*inter_cons_of_mem _ xint, *inter_cons_of_not_mem _ nyint, inter_cons_of_mem _ xint])\n      (\u03bb nxint : x \u2209 t\u2081,\n        by rewrite [*inter_cons_of_not_mem _ nxint, *inter_cons_of_not_mem _ nyint,\n                     inter_cons_of_not_mem _ nxint])))\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\ntheorem perm_inter_right (l : list A) {t\u2081 t\u2082 : list A} : t\u2081 ~ t\u2082 \u2192 (inter l t\u2081) ~ (inter l t\u2082) :=\nlist.induction_on l\n  (\u03bb p, by rewrite [*inter_nil])\n  (\u03bb x xs r p, by_cases\n    (\u03bb xint\u2081  : x \u2208 t\u2081,\n      have xint\u2082 : x \u2208 t\u2082, from mem_perm p xint\u2081,\n      by rewrite [inter_cons_of_mem _ xint\u2081, inter_cons_of_mem _ xint\u2082]; exact (skip _ (r p)))\n    (\u03bb nxint\u2081 : x \u2209 t\u2081,\n      have nxint\u2082 : x \u2209 t\u2082, from not_mem_perm p nxint\u2081,\n      by rewrite [inter_cons_of_not_mem _ nxint\u2081, inter_cons_of_not_mem _ nxint\u2082]; exact (r p)))\n\ntheorem perm_inter [congr] {l\u2081 l\u2082 t\u2081 t\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 t\u2081 ~ t\u2082 \u2192 (inter l\u2081 t\u2081) ~ (inter l\u2082 t\u2082) :=\nassume p\u2081 p\u2082, trans (perm_inter_left t\u2081 p\u2081) (perm_inter_right l\u2082 p\u2082)\nend perm_inter\n\n/- extensionality -/\nsection ext\nopen eq.ops\n\ntheorem perm_ext : \u2200 {l\u2081 l\u2082 : list A}, nodup l\u2081 \u2192 nodup l\u2082 \u2192 (\u2200a, a \u2208 l\u2081 \u2194 a \u2208 l\u2082) \u2192 l\u2081 ~ l\u2082\n| []       []       d\u2081 d\u2082 e := !perm.nil\n| []       (a\u2082::t\u2082) d\u2081 d\u2082 e := absurd (iff.mpr (e a\u2082) !mem_cons) (not_mem_nil a\u2082)\n| (a\u2081::t\u2081) []       d\u2081 d\u2082 e := absurd (iff.mp (e a\u2081) !mem_cons) (not_mem_nil a\u2081)\n| (a\u2081::t\u2081) (a\u2082::t\u2082) d\u2081 d\u2082 e :=\n  have a\u2081 \u2208 a\u2082::t\u2082, from iff.mp (e a\u2081) !mem_cons,\n  have \u2203 s\u2081 s\u2082, a\u2082::t\u2082 = s\u2081++(a\u2081::s\u2082), from mem_split this,\n  obtain (s\u2081 s\u2082 : list A) (t\u2082_eq : a\u2082::t\u2082 = s\u2081++(a\u2081::s\u2082)), from this,\n  have dt\u2082'     : nodup (a\u2081::(s\u2081++s\u2082)), from nodup_head (by rewrite [t\u2082_eq at d\u2082]; exact d\u2082),\n  have eqv      : \u2200a, a \u2208 t\u2081 \u2194 a \u2208 s\u2081++s\u2082, from\n    take a, iff.intro\n      (suppose  a \u2208 t\u2081,\n         have a \u2208 a\u2082::t\u2082,       from iff.mp (e a) (mem_cons_of_mem _ this),\n         have a \u2208 s\u2081++(a\u2081::s\u2082), by rewrite [t\u2082_eq at this]; exact this,\n         or.elim (mem_or_mem_of_mem_append this)\n           (suppose a \u2208 s\u2081, mem_append_left s\u2082 this)\n           (suppose a \u2208 a\u2081::s\u2082, or.elim (eq_or_mem_of_mem_cons this)\n             (suppose a = a\u2081,\n               have a\u2081 \u2209 t\u2081, from not_mem_of_nodup_cons d\u2081,\n               by subst a; contradiction)\n             (suppose a \u2208 s\u2082, mem_append_right s\u2081 this)))\n      (suppose a \u2208 s\u2081 ++ s\u2082, or.elim (mem_or_mem_of_mem_append this)\n        (suppose a \u2208 s\u2081,\n           have a \u2208 a\u2082::t\u2082, from by rewrite [t\u2082_eq]; exact (mem_append_left _ this),\n           have a \u2208 a\u2081::t\u2081, from iff.mpr (e a) this,\n           or.elim (eq_or_mem_of_mem_cons this)\n             (suppose a = a\u2081,\n                have a\u2081 \u2209 s\u2081++s\u2082, from not_mem_of_nodup_cons dt\u2082',\n                have a\u2081 \u2209 s\u2081,     from not_mem_of_not_mem_append_left this,\n                by subst a; contradiction)\n             (suppose a \u2208 t\u2081, this))\n        (suppose a \u2208 s\u2082,\n           have a \u2208 a\u2082::t\u2082, from by rewrite [t\u2082_eq]; exact (mem_append_right _ (mem_cons_of_mem _ this)),\n           have a \u2208 a\u2081::t\u2081, from iff.mpr (e a) this,\n           or.elim (eq_or_mem_of_mem_cons this)\n             (suppose a = a\u2081,\n               have a\u2081 \u2209 s\u2081++s\u2082, from not_mem_of_nodup_cons dt\u2082',\n               have a\u2081 \u2209 s\u2082, from not_mem_of_not_mem_append_right this,\n               by subst a; contradiction)\n             (suppose a \u2208 t\u2081, this))),\n  have ds\u2081s\u2082 : nodup (s\u2081++s\u2082), from nodup_of_nodup_cons dt\u2082',\n  have nodup t\u2081, from nodup_of_nodup_cons d\u2081,\n  calc a\u2081::t\u2081 ~ a\u2081::(s\u2081++s\u2082) : skip a\u2081 (perm_ext this ds\u2081s\u2082 eqv)\n         ...  ~ s\u2081++(a\u2081::s\u2082) : !perm_middle\n         ...  = a\u2082::t\u2082       : by rewrite t\u2082_eq\nend ext\n\ntheorem nodup_of_perm_of_nodup {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 nodup l\u2081 \u2192 nodup l\u2082 :=\nassume h, perm.induction_on h\n  (\u03bb h, h)\n  (\u03bb a l\u2081 l\u2082 p ih nd,\n    have nodup l\u2081, from nodup_of_nodup_cons nd,\n    have nodup l\u2082, from ih this,\n    have a \u2209 l\u2081,   from not_mem_of_nodup_cons nd,\n    have a \u2209 l\u2082,   from suppose a \u2208 l\u2082, absurd (mem_perm (perm.symm p) this) `a \u2209 l\u2081`,\n    nodup_cons `a \u2209 l\u2082` `nodup l\u2082`)\n  (\u03bb x y l\u2081 nd,\n    have nodup (x::l\u2081),    from nodup_of_nodup_cons nd,\n    have nodup l\u2081,         from nodup_of_nodup_cons this,\n    have x \u2209 l\u2081,           from not_mem_of_nodup_cons `nodup (x::l\u2081)`,\n    have y \u2209 x::l\u2081,        from not_mem_of_nodup_cons nd,\n    have x \u2260 y,            from suppose x = y, begin subst x, exact absurd !mem_cons `y \u2209 y::l\u2081` end,\n    have y \u2209 l\u2081,           from not_mem_of_not_mem_cons `y \u2209 x::l\u2081`,\n    have x \u2209 y::l\u2081,        from not_mem_cons_of_ne_of_not_mem `x \u2260 y` `x \u2209 l\u2081`,\n    have nodup (y::l\u2081),    from nodup_cons `y \u2209 l\u2081` `nodup l\u2081`,\n    show nodup (x::y::l\u2081), from nodup_cons `x \u2209 y::l\u2081` `nodup (y::l\u2081)`)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 ih\u2081 ih\u2082 nd, ih\u2082 (ih\u2081 nd))\n\n/- product -/\nsection product\ntheorem perm_product_left {l\u2081 l\u2082 : list A} (t\u2081 : list B) : l\u2081 ~ l\u2082 \u2192 (product l\u2081 t\u2081) ~ (product l\u2082 t\u2081) :=\nassume p : l\u2081 ~ l\u2082, perm.induction_on p\n  !perm.refl\n  (\u03bb x l\u2081 l\u2082 p r, perm_app (perm.refl (map _ t\u2081)) r)\n  (\u03bb x y l,\n    let m\u2081 := map (\u03bb b, (x, b)) t\u2081 in\n    let m\u2082 := map (\u03bb b, (y, b)) t\u2081 in\n    let c  := product l t\u2081 in\n    calc m\u2082 ++ (m\u2081 ++ c) = (m\u2082 ++ m\u2081) ++ c  : by rewrite append.assoc\n                     ... ~ (m\u2081 ++ m\u2082) ++ c  : perm_app !perm_app_comm !perm.refl\n                     ... =  m\u2081 ++ (m\u2082 ++ c) : by rewrite append.assoc)\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\ntheorem perm_product_right (l : list A) {t\u2081 t\u2082 : list B} : t\u2081 ~ t\u2082 \u2192 (product l t\u2081) ~ (product l t\u2082) :=\nlist.induction_on l\n  (\u03bb p, by rewrite [*nil_product])\n  (\u03bb a t r p,\n    perm_app (perm_map _ p) (r p))\n\ntheorem perm_product [congr] {l\u2081 l\u2082 : list A} {t\u2081 t\u2082 : list B} : l\u2081 ~ l\u2082 \u2192 t\u2081 ~ t\u2082 \u2192 (product l\u2081 t\u2081) ~ (product l\u2082 t\u2082) :=\nassume p\u2081 p\u2082, trans (perm_product_left t\u2081 p\u2081) (perm_product_right l\u2082 p\u2082)\nend product\n\n/- filter -/\ntheorem perm_filter [congr] {l\u2081 l\u2082 : list A} {p : A \u2192 Prop} [decidable_pred p] :\n  l\u2081 ~ l\u2082 \u2192 (filter p l\u2081) ~ (filter p l\u2082) :=\nassume u, perm.induction_on u\n  perm.nil\n  (take x l\u2081' l\u2082',\n    assume u' : l\u2081' ~ l\u2082',\n    assume u'' : filter p l\u2081' ~ filter p l\u2082',\n    decidable.by_cases\n      (suppose p x, by rewrite [*filter_cons_of_pos _ this]; apply perm.skip; apply u'')\n      (suppose \u00ac p x, by rewrite [*filter_cons_of_neg _ this]; apply u''))\n  (take x y l,\n    decidable.by_cases\n      (assume H1 : p x,\n        decidable.by_cases\n          (assume H2 : p y,\n             begin\n               rewrite [filter_cons_of_pos _ H1, *filter_cons_of_pos _ H2, filter_cons_of_pos _ H1],\n               apply perm.swap\n             end)\n          (assume H2 : \u00ac p y,\n             by rewrite [filter_cons_of_pos _ H1, *filter_cons_of_neg _ H2, filter_cons_of_pos _ H1]))\n      (assume H1 : \u00ac p x,\n        decidable.by_cases\n          (assume H2 : p y,\n             by rewrite [filter_cons_of_neg _ H1, *filter_cons_of_pos _ H2, filter_cons_of_neg _ H1])\n          (assume H2 : \u00ac p y,\n             by rewrite [filter_cons_of_neg _ H1, *filter_cons_of_neg _ H2, filter_cons_of_neg _ H1])))\n    (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 r\u2081 r\u2082, trans r\u2081 r\u2082)\n\nsection count\nvariable [decA : decidable_eq A]\ninclude decA\n\ntheorem count_eq_of_perm {l\u2081 l\u2082 : list A} : l\u2081 ~ l\u2082 \u2192 \u2200 a, count a l\u2081 = count a l\u2082 :=\nsuppose l\u2081 ~ l\u2082, perm.induction_on this\n  (\u03bb a, rfl)\n  (\u03bb x l\u2081 l\u2082 p h a, by rewrite [*count_cons, *h a])\n  (\u03bb x y l a, by_cases\n     (suppose a = x, by_cases\n       (suppose a = y, begin subst x, subst y end)\n       (suppose a \u2260 y, begin subst x, rewrite [count_cons_of_ne this, *count_cons_eq, count_cons_of_ne this] end))\n     (suppose a \u2260 x, by_cases\n       (suppose a = y, begin subst y, rewrite [count_cons_of_ne this, *count_cons_eq, count_cons_of_ne this] end)\n       (suppose a \u2260 y, begin rewrite [count_cons_of_ne `a\u2260x`, *count_cons_of_ne `a\u2260y`, count_cons_of_ne `a\u2260x`] end)))\n  (\u03bb l\u2081 l\u2082 l\u2083 p\u2081 p\u2082 h\u2081 h\u2082 a, eq.trans (h\u2081 a) (h\u2082 a))\nend count\nend perm\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/list/perm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7218888581180684}}
{"text": "import game.max.level08 -- hide\n\nopen_locale classical -- hide\n\nnoncomputable theory -- hide\n\nnamespace xena -- hide\n\n/-\n# Chapter ? : Max\n\n## Level 9\n\nWe've done `max_le_iff`; here is `le_max_iff`. \n-/\n\n/- Lemma\nIf $a$, $b$, $c$ are real numbers,\nthen $a\\leq\\max(b,c)$ iff ($a\\leq b$ or $a\\leq c$).\n-/\n\ntheorem le_max_iff {a b c : \u211d} : a \u2264 max b c \u2194 a \u2264 b \u2228 a \u2264 c :=\nbegin\n  split,\n  { intro ha,\n    cases le_total b c with hbc hcb,\n    { rw max_eq_right hbc at ha,\n      right,\n      assumption,\n    },\n    { rw max_eq_left hcb at ha,\n      left,\n      assumption\n    }\n  },\n  { intro habc,\n    cases habc with hab hac,\n    { apply le_trans hab,\n      apply le_max_left},\n    { apply le_trans hac,\n      apply le_max_right},\n  }\nend\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/max/level09.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615412, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.7218553093781477}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.polynomial.ring_division\nimport tactic.zify\nimport field_theory.separable\nimport data.zmod.basic\nimport ring_theory.integral_domain\nimport number_theory.divisors\nimport field_theory.finite.basic\nimport group_theory.specific_groups.cyclic\nimport algebra.char_p.two\n\n/-!\n# Roots of unity and primitive roots of unity\n\nWe define roots of unity in the context of an arbitrary commutative monoid,\nas a subgroup of the group of units. We also define a predicate `is_primitive_root` on commutative\nmonoids, expressing that an element is a primitive root of unity.\n\n## Main definitions\n\n* `roots_of_unity n M`, for `n : \u2115+` is the subgroup of the units of a commutative monoid `M`\n  consisting of elements `x` that satisfy `x ^ n = 1`.\n* `is_primitive_root \u03b6 k`: an element `\u03b6` is a primitive `k`-th root of unity if `\u03b6 ^ k = 1`,\n  and if `l` satisfies `\u03b6 ^ l = 1` then `k \u2223 l`.\n* `primitive_roots k R`: the finset of primitive `k`-th roots of unity in an integral domain `R`.\n* `is_primitive_root.aut_to_pow`: the monoid hom that takes an automorphism of a ring to the power\n  it sends that specific primitive root, as a member of `(zmod n)\u02e3`.\n\n## Main results\n\n* `roots_of_unity.is_cyclic`: the roots of unity in an integral domain form a cyclic group.\n* `is_primitive_root.zmod_equiv_zpowers`: `zmod k` is equivalent to\n  the subgroup generated by a primitive `k`-th root of unity.\n* `is_primitive_root.zpowers_eq`: in an integral domain, the subgroup generated by\n  a primitive `k`-th root of unity is equal to the `k`-th roots of unity.\n* `is_primitive_root.card_primitive_roots`: if an integral domain\n   has a primitive `k`-th root of unity, then it has `\u03c6 k` of them.\n\n## Implementation details\n\nIt is desirable that `roots_of_unity` is a subgroup,\nand it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields.\nWe therefore implement it as a subgroup of the units of a commutative monoid.\n\nWe have chosen to define `roots_of_unity n` for `n : \u2115+`, instead of `n : \u2115`,\nbecause almost all lemmas need the positivity assumption,\nand in particular the type class instances for `fintype` and `is_cyclic`.\n\nOn the other hand, for primitive roots of unity, it is desirable to have a predicate\nnot just on units, but directly on elements of the ring/field.\nFor example, we want to say that `exp (2 * pi * I / n)` is a primitive `n`-th root of unity\nin the complex numbers, without having to turn that number into a unit first.\n\nThis creates a little bit of friction, but lemmas like `is_primitive_root.is_unit` and\n`is_primitive_root.coe_units_iff` should provide the necessary glue.\n\n-/\n\nopen_locale classical big_operators polynomial\nnoncomputable theory\n\nopen polynomial\nopen finset\n\nvariables {M N G G\u2080 R S F : Type*}\nvariables [comm_monoid M] [comm_monoid N] [comm_group G] [comm_group_with_zero G\u2080]\n\nsection roots_of_unity\n\nvariables {k l : \u2115+}\n\n/-- `roots_of_unity k M` is the subgroup of elements `m : M\u02e3` that satisfy `m ^ k = 1` -/\ndef roots_of_unity (k : \u2115+) (M : Type*) [comm_monoid M] : subgroup M\u02e3 :=\n{ carrier := { \u03b6 | \u03b6 ^ (k : \u2115) = 1 },\n  one_mem' := one_pow _,\n  mul_mem' := \u03bb \u03b6 \u03be h\u03b6 h\u03be, by simp only [*, set.mem_set_of_eq, mul_pow, one_mul] at *,\n  inv_mem' := \u03bb \u03b6 h\u03b6, by simp only [*, set.mem_set_of_eq, inv_pow, one_inv] at * }\n\n@[simp] lemma mem_roots_of_unity (k : \u2115+) (\u03b6 : M\u02e3) :\n  \u03b6 \u2208 roots_of_unity k M \u2194 \u03b6 ^ (k : \u2115) = 1 := iff.rfl\n\nlemma roots_of_unity.coe_injective {n : \u2115+} : function.injective (coe : (roots_of_unity n M) \u2192 M) :=\nunits.ext.comp (\u03bb x y, subtype.ext)\n\n/-- Make an element of `roots_of_unity` from a member of the base ring, and a proof that it has\na positive power equal to one. -/\n@[simps coe_coe] def roots_of_unity.mk_of_pow_eq (\u03b6 : M) {n : \u2115+} (h : \u03b6 ^ (n : \u2115) = 1) :\n  roots_of_unity n M :=\n\u27e8units.mk_of_mul_eq_one \u03b6 (\u03b6 ^ n.nat_pred) $\n  by rwa [\u2190pow_one \u03b6, \u2190pow_mul, \u2190pow_add, one_mul, pnat.one_add_nat_pred],\nunits.ext $ by simpa\u27e9\n\n@[simp] lemma roots_of_unity.coe_mk_of_pow_eq {\u03b6 : M} {n : \u2115+}\n  (h : \u03b6 ^ (n : \u2115) = 1) : (roots_of_unity.mk_of_pow_eq _ h : M) = \u03b6 := rfl\n\nlemma roots_of_unity_le_of_dvd (h : k \u2223 l) : roots_of_unity k M \u2264 roots_of_unity l M :=\nbegin\n  obtain \u27e8d, rfl\u27e9 := h,\n  intros \u03b6 h,\n  simp only [mem_roots_of_unity, pnat.mul_coe, pow_mul, one_pow, *] at *,\nend\n\nlemma map_roots_of_unity (f : M\u02e3 \u2192* N\u02e3) (k : \u2115+) :\n  (roots_of_unity k M).map f \u2264 roots_of_unity k N :=\nbegin\n  rintros _ \u27e8\u03b6, h, rfl\u27e9,\n  simp only [\u2190map_pow, *, mem_roots_of_unity, set_like.mem_coe, monoid_hom.map_one] at *\nend\n\nvariables [comm_ring R]\n\n@[norm_cast]\nlemma roots_of_unity.coe_pow (\u03b6 : roots_of_unity k R) (m : \u2115) : \u2191(\u03b6 ^ m) = (\u03b6 ^ m : R) :=\nbegin\n  change \u2191(\u2191(\u03b6 ^ m) : R\u02e3) = \u2191(\u03b6 : R\u02e3) ^ m,\n  rw [subgroup.coe_pow, units.coe_pow],\nend\n\nvariables [comm_ring S]\n\n/-- Restrict a ring homomorphism between integral domains to the nth roots of unity -/\ndef restrict_roots_of_unity [ring_hom_class F R S] (\u03c3 : F) (n : \u2115+) :\n  roots_of_unity n R \u2192* roots_of_unity n S :=\nlet h : \u2200 \u03be : roots_of_unity n R, (\u03c3 \u03be) ^ (n : \u2115) = 1 := \u03bb \u03be, by\n{ change (\u03c3 (\u03be : R\u02e3)) ^ (n : \u2115) = 1,\n  rw [\u2190map_pow, \u2190units.coe_pow, show ((\u03be : R\u02e3) ^ (n : \u2115) = 1), from \u03be.2,\n      units.coe_one, map_one \u03c3] } in\n{ to_fun := \u03bb \u03be, \u27e8@unit_of_invertible _ _ _ (invertible_of_pow_eq_one _ _ (h \u03be) n.2),\n    by { ext, rw units.coe_pow, exact h \u03be }\u27e9,\n  map_one' := by { ext, exact map_one \u03c3 },\n  map_mul' := \u03bb \u03be\u2081 \u03be\u2082, by { ext, rw [subgroup.coe_mul, units.coe_mul], exact map_mul \u03c3 _ _ } }\n\n@[simp] lemma restrict_roots_of_unity_coe_apply [ring_hom_class F R S] (\u03c3 : F)\n  (\u03b6 : roots_of_unity k R) : \u2191(restrict_roots_of_unity \u03c3 k \u03b6) = \u03c3 \u2191\u03b6 :=\nrfl\n\n/-- Restrict a ring isomorphism between integral domains to the nth roots of unity -/\ndef ring_equiv.restrict_roots_of_unity (\u03c3 : R \u2243+* S) (n : \u2115+) :\n  roots_of_unity n R \u2243* roots_of_unity n S :=\n{ to_fun := restrict_roots_of_unity \u03c3.to_ring_hom n,\n  inv_fun :=restrict_roots_of_unity \u03c3.symm.to_ring_hom n,\n  left_inv := \u03bb \u03be, by { ext, exact \u03c3.symm_apply_apply \u03be },\n  right_inv := \u03bb \u03be, by { ext, exact \u03c3.apply_symm_apply \u03be },\n  map_mul' := (restrict_roots_of_unity _ n).map_mul }\n\n@[simp] lemma ring_equiv.restrict_roots_of_unity_coe_apply (\u03c3 : R \u2243+* S) (\u03b6 : roots_of_unity k R) :\n  \u2191(\u03c3.restrict_roots_of_unity k \u03b6) = \u03c3 \u2191\u03b6 :=\nrfl\n\n@[simp] lemma ring_equiv.restrict_roots_of_unity_symm (\u03c3 : R \u2243+* S) :\n  (\u03c3.restrict_roots_of_unity k).symm = \u03c3.symm.restrict_roots_of_unity k :=\nrfl\n\nvariables [is_domain R]\n\nlemma mem_roots_of_unity_iff_mem_nth_roots {\u03b6 : R\u02e3} :\n  \u03b6 \u2208 roots_of_unity k R \u2194 (\u03b6 : R) \u2208 nth_roots k (1 : R) :=\nby simp only [mem_roots_of_unity, mem_nth_roots k.pos, units.ext_iff, units.coe_one, units.coe_pow]\n\nvariables (k R)\n\n/-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`.\n\nThis is implemented as equivalence of subtypes,\nbecause `roots_of_unity` is a subgroup of the group of units,\nwhereas `nth_roots` is a multiset. -/\ndef roots_of_unity_equiv_nth_roots :\n  roots_of_unity k R \u2243 {x // x \u2208 nth_roots k (1 : R)} :=\nbegin\n  refine\n  { to_fun := \u03bb x, \u27e8x, mem_roots_of_unity_iff_mem_nth_roots.mp x.2\u27e9,\n    inv_fun := \u03bb x, \u27e8\u27e8x, x ^ (k - 1 : \u2115), _, _\u27e9, _\u27e9,\n    left_inv := _,\n    right_inv := _ },\n  swap 4, { rintro \u27e8x, hx\u27e9, ext, refl },\n  swap 4, { rintro \u27e8x, hx\u27e9, ext, refl },\n  all_goals\n  { rcases x with \u27e8x, hx\u27e9, rw [mem_nth_roots k.pos] at hx,\n    simp only [subtype.coe_mk, \u2190 pow_succ, \u2190 pow_succ', hx,\n      tsub_add_cancel_of_le (show 1 \u2264 (k : \u2115), from k.one_le)] },\n  { show (_ : R\u02e3) ^ (k : \u2115) = 1,\n    simp only [units.ext_iff, hx, units.coe_mk, units.coe_one, subtype.coe_mk, units.coe_pow] }\nend\n\nvariables {k R}\n\n@[simp] lemma roots_of_unity_equiv_nth_roots_apply (x : roots_of_unity k R) :\n  (roots_of_unity_equiv_nth_roots R k x : R) = x :=\nrfl\n\n@[simp] lemma roots_of_unity_equiv_nth_roots_symm_apply (x : {x // x \u2208 nth_roots k (1 : R)}) :\n  ((roots_of_unity_equiv_nth_roots R k).symm x : R) = x :=\nrfl\n\nvariables (k R)\n\ninstance roots_of_unity.fintype : fintype (roots_of_unity k R) :=\nfintype.of_equiv {x // x \u2208 nth_roots k (1 : R)} $ (roots_of_unity_equiv_nth_roots R k).symm\n\ninstance roots_of_unity.is_cyclic : is_cyclic (roots_of_unity k R) :=\nis_cyclic_of_subgroup_is_domain ((units.coe_hom R).comp (roots_of_unity k R).subtype)\n  (units.ext.comp subtype.val_injective)\n\nlemma card_roots_of_unity : fintype.card (roots_of_unity k R) \u2264 k :=\ncalc  fintype.card (roots_of_unity k R)\n    = fintype.card {x // x \u2208 nth_roots k (1 : R)} :\n          fintype.card_congr (roots_of_unity_equiv_nth_roots R k)\n... \u2264 (nth_roots k (1 : R)).attach.card           : multiset.card_le_of_le (multiset.dedup_le _)\n... = (nth_roots k (1 : R)).card                  : multiset.card_attach\n... \u2264 k                                           : card_nth_roots k 1\n\nvariables {k R}\n\nlemma map_root_of_unity_eq_pow_self [ring_hom_class F R R] (\u03c3 : F) (\u03b6 : roots_of_unity k R) :\n  \u2203 m : \u2115, \u03c3 \u03b6 = \u03b6 ^ m :=\nbegin\n  obtain \u27e8m, hm\u27e9 := monoid_hom.map_cyclic (restrict_roots_of_unity \u03c3 k),\n  rw [\u2190restrict_roots_of_unity_coe_apply, hm, zpow_eq_mod_order_of, \u2190int.to_nat_of_nonneg\n      (m.mod_nonneg (int.coe_nat_ne_zero.mpr (pos_iff_ne_zero.mp (order_of_pos \u03b6)))),\n      zpow_coe_nat, roots_of_unity.coe_pow],\n  exact \u27e8(m % (order_of \u03b6)).to_nat, rfl\u27e9,\nend\n\nend roots_of_unity\n\n/-- An element `\u03b6` is a primitive `k`-th root of unity if `\u03b6 ^ k = 1`,\nand if `l` satisfies `\u03b6 ^ l = 1` then `k \u2223 l`. -/\nstructure is_primitive_root (\u03b6 : M) (k : \u2115) : Prop :=\n(pow_eq_one : \u03b6 ^ (k : \u2115) = 1)\n(dvd_of_pow_eq_one : \u2200 l : \u2115, \u03b6 ^ l = 1 \u2192 k \u2223 l)\n\n/-- Turn a primitive root \u03bc into a member of the `roots_of_unity` subgroup. -/\n@[simps] def is_primitive_root.to_roots_of_unity {\u03bc : M} {n : \u2115+} (h : is_primitive_root \u03bc n) :\n  roots_of_unity n M := roots_of_unity.mk_of_pow_eq \u03bc h.pow_eq_one\n\nsection primitive_roots\nvariables {k : \u2115}\n\n/-- `primitive_roots k R` is the finset of primitive `k`-th roots of unity\nin the integral domain `R`. -/\ndef primitive_roots (k : \u2115) (R : Type*) [comm_ring R] [is_domain R] : finset R :=\n(nth_roots k (1 : R)).to_finset.filter (\u03bb \u03b6, is_primitive_root \u03b6 k)\n\nvariables [comm_ring R] [is_domain R]\n\n@[simp] lemma mem_primitive_roots {\u03b6 : R} (h0 : 0 < k) :\n  \u03b6 \u2208 primitive_roots k R \u2194 is_primitive_root \u03b6 k :=\nbegin\n  rw [primitive_roots, mem_filter, multiset.mem_to_finset, mem_nth_roots h0, and_iff_right_iff_imp],\n  exact is_primitive_root.pow_eq_one\nend\n\nend primitive_roots\n\nnamespace is_primitive_root\n\nvariables {k l : \u2115}\n\nlemma iff_def (\u03b6 : M) (k : \u2115) :\n  is_primitive_root \u03b6 k \u2194 (\u03b6 ^ k = 1) \u2227 (\u2200 l : \u2115, \u03b6 ^ l = 1 \u2192 k \u2223 l) :=\n\u27e8\u03bb \u27e8h1, h2\u27e9, \u27e8h1, h2\u27e9, \u03bb \u27e8h1, h2\u27e9, \u27e8h1, h2\u27e9\u27e9\n\nlemma mk_of_lt (\u03b6 : M) (hk : 0 < k) (h1 : \u03b6 ^ k = 1) (h : \u2200 l : \u2115, 0 < l \u2192  l < k \u2192 \u03b6 ^ l \u2260 1) :\n  is_primitive_root \u03b6 k :=\nbegin\n  refine \u27e8h1, _\u27e9,\n  intros l hl,\n  apply dvd_trans _ (k.gcd_dvd_right l),\n  suffices : k.gcd l = k, { rw this },\n  rw eq_iff_le_not_lt,\n  refine \u27e8nat.le_of_dvd hk (k.gcd_dvd_left l), _\u27e9,\n  intro h', apply h _ (nat.gcd_pos_of_pos_left _ hk) h',\n  exact pow_gcd_eq_one _ h1 hl\nend\n\nsection comm_monoid\n\nvariables {\u03b6 : M} (h : is_primitive_root \u03b6 k)\n\n@[nontriviality] lemma of_subsingleton [subsingleton M] (x : M) : is_primitive_root x 1 :=\n\u27e8subsingleton.elim _ _, \u03bb _ _, one_dvd _\u27e9\n\nlemma pow_eq_one_iff_dvd (l : \u2115) : \u03b6 ^ l = 1 \u2194 k \u2223 l :=\n\u27e8h.dvd_of_pow_eq_one l,\nby { rintro \u27e8i, rfl\u27e9, simp only [pow_mul, h.pow_eq_one, one_pow, pnat.mul_coe] }\u27e9\n\nlemma is_unit (h : is_primitive_root \u03b6 k) (h0 : 0 < k) : is_unit \u03b6 :=\nbegin\n  apply is_unit_of_mul_eq_one \u03b6 (\u03b6 ^ (k - 1)),\n  rw [\u2190 pow_succ, tsub_add_cancel_of_le h0.nat_succ_le, h.pow_eq_one]\nend\n\nlemma pow_ne_one_of_pos_of_lt (h0 : 0 < l) (hl : l < k) : \u03b6 ^ l \u2260 1 :=\nmt (nat.le_of_dvd h0 \u2218 h.dvd_of_pow_eq_one _) $ not_le_of_lt hl\n\nlemma pow_inj (h : is_primitive_root \u03b6 k) \u2983i j : \u2115\u2984 (hi : i < k) (hj : j < k) (H : \u03b6 ^ i = \u03b6 ^ j) :\n  i = j :=\nbegin\n  wlog hij : i \u2264 j,\n  apply le_antisymm hij,\n  rw \u2190 tsub_eq_zero_iff_le,\n  apply nat.eq_zero_of_dvd_of_lt _ (lt_of_le_of_lt tsub_le_self hj),\n  apply h.dvd_of_pow_eq_one,\n  rw [\u2190 ((h.is_unit (lt_of_le_of_lt (nat.zero_le _) hi)).pow i).mul_left_inj,\n      \u2190 pow_add, tsub_add_cancel_of_le hij, H, one_mul]\nend\n\nlemma one : is_primitive_root (1 : M) 1 :=\n{ pow_eq_one := pow_one _,\n  dvd_of_pow_eq_one := \u03bb l hl, one_dvd _ }\n\n@[simp] lemma one_right_iff : is_primitive_root \u03b6 1 \u2194 \u03b6 = 1 :=\nbegin\n  split,\n  { intro h, rw [\u2190 pow_one \u03b6, h.pow_eq_one] },\n  { rintro rfl, exact one }\nend\n\n@[simp] lemma coe_units_iff {\u03b6 : M\u02e3} :\n  is_primitive_root (\u03b6 : M) k \u2194 is_primitive_root \u03b6 k :=\nby simp only [iff_def, units.ext_iff, units.coe_pow, units.coe_one]\n\nlemma pow_of_coprime (h : is_primitive_root \u03b6 k) (i : \u2115) (hi : i.coprime k) :\n  is_primitive_root (\u03b6 ^ i) k :=\nbegin\n  by_cases h0 : k = 0,\n  { subst k, simp only [*, pow_one, nat.coprime_zero_right] at * },\n  rcases h.is_unit (nat.pos_of_ne_zero h0) with \u27e8\u03b6, rfl\u27e9,\n  rw [\u2190 units.coe_pow],\n  rw coe_units_iff at h \u22a2,\n  refine\n  { pow_eq_one := by rw [\u2190 pow_mul', pow_mul, h.pow_eq_one, one_pow],\n    dvd_of_pow_eq_one := _ },\n  intros l hl,\n  apply h.dvd_of_pow_eq_one,\n  rw [\u2190 pow_one \u03b6, \u2190 zpow_coe_nat \u03b6, \u2190 hi.gcd_eq_one, nat.gcd_eq_gcd_ab, zpow_add,\n      mul_pow, \u2190 zpow_coe_nat, \u2190 zpow_mul, mul_right_comm],\n  simp only [zpow_mul, hl, h.pow_eq_one, one_zpow, one_pow, one_mul, zpow_coe_nat]\nend\n\nlemma pow_of_prime (h : is_primitive_root \u03b6 k) {p : \u2115} (hprime : nat.prime p) (hdiv : \u00ac p \u2223 k) :\n  is_primitive_root (\u03b6 ^ p) k :=\nh.pow_of_coprime p (hprime.coprime_iff_not_dvd.2 hdiv)\n\nlemma pow_iff_coprime (h : is_primitive_root \u03b6 k) (h0 : 0 < k) (i : \u2115) :\n  is_primitive_root (\u03b6 ^ i) k \u2194 i.coprime k :=\nbegin\n  refine \u27e8_, h.pow_of_coprime i\u27e9,\n  intro hi,\n  obtain \u27e8a, ha\u27e9 := i.gcd_dvd_left k,\n  obtain \u27e8b, hb\u27e9 := i.gcd_dvd_right k,\n  suffices : b = k,\n  { rwa [this, \u2190 one_mul k, nat.mul_left_inj h0, eq_comm] at hb { occs := occurrences.pos [1] } },\n  rw [ha] at hi,\n  rw [mul_comm] at hb,\n  apply nat.dvd_antisymm \u27e8i.gcd k, hb\u27e9 (hi.dvd_of_pow_eq_one b _),\n  rw [\u2190 pow_mul', \u2190 mul_assoc, \u2190 hb, pow_mul, h.pow_eq_one, one_pow]\nend\n\nprotected lemma order_of (\u03b6 : M) : is_primitive_root \u03b6 (order_of \u03b6) :=\n\u27e8pow_order_of_eq_one \u03b6, \u03bb l, order_of_dvd_of_pow_eq_one\u27e9\n\nlemma unique {\u03b6 : M} (hk : is_primitive_root \u03b6 k) (hl : is_primitive_root \u03b6 l) : k = l :=\nbegin\n  wlog hkl : k \u2264 l,\n  rcases hkl.eq_or_lt with rfl | hkl,\n  { refl },\n  rcases k.eq_zero_or_pos with rfl | hk',\n  { exact (zero_dvd_iff.mp $ hk.dvd_of_pow_eq_one l hl.pow_eq_one).symm },\n  exact absurd hk.pow_eq_one (hl.pow_ne_one_of_pos_of_lt hk' hkl)\nend\n\nlemma eq_order_of : k = order_of \u03b6 := h.unique (is_primitive_root.order_of \u03b6)\n\nprotected lemma iff (hk : 0 < k) :\n  is_primitive_root \u03b6 k \u2194 \u03b6 ^ k = 1 \u2227 \u2200 l : \u2115, 0 < l \u2192 l < k \u2192 \u03b6 ^ l \u2260 1 :=\nbegin\n  refine \u27e8\u03bb h, \u27e8h.pow_eq_one, \u03bb l hl' hl, _\u27e9, \u03bb \u27e8h\u03b6, hl\u27e9, is_primitive_root.mk_of_lt \u03b6 hk h\u03b6 hl\u27e9,\n  rw h.eq_order_of at hl,\n  exact pow_ne_one_of_lt_order_of' hl'.ne' hl,\nend\n\nprotected lemma not_iff : \u00ac is_primitive_root \u03b6 k \u2194 order_of \u03b6 \u2260 k :=\n\u27e8\u03bb h hk, h $ hk \u25b8 is_primitive_root.order_of \u03b6,\n \u03bb h hk, h.symm $ hk.unique $ is_primitive_root.order_of \u03b6\u27e9\n\nlemma pow_of_dvd (h : is_primitive_root \u03b6 k) {p : \u2115} (hp : p \u2260 0) (hdiv : p \u2223 k) :\n  is_primitive_root (\u03b6 ^ p) (k / p) :=\nbegin\n  suffices : order_of (\u03b6 ^ p) = k / p,\n  { exact this \u25b8 is_primitive_root.order_of (\u03b6 ^ p) },\n  rw [order_of_pow' _ hp, \u2190 eq_order_of h, nat.gcd_eq_right hdiv]\nend\n\nend comm_monoid\n\nsection comm_monoid_with_zero\n\nvariables {M\u2080 : Type*} [comm_monoid_with_zero M\u2080]\n\nlemma zero [nontrivial M\u2080] : is_primitive_root (0 : M\u2080) 0 :=\n\u27e8pow_zero 0, \u03bb l hl, by simpa [zero_pow_eq, show \u2200 p, \u00acp \u2192 false \u2194 p, from @not_not] using hl\u27e9\n\nend comm_monoid_with_zero\n\nsection comm_group\n\nvariables {\u03b6 : G}\n\nlemma zpow_eq_one (h : is_primitive_root \u03b6 k) : \u03b6 ^ (k : \u2124) = 1 :=\nby { rw zpow_coe_nat, exact h.pow_eq_one }\n\nlemma zpow_eq_one_iff_dvd (h : is_primitive_root \u03b6 k) (l : \u2124) :\n  \u03b6 ^ l = 1 \u2194 (k : \u2124) \u2223 l :=\nbegin\n  by_cases h0 : 0 \u2264 l,\n  { lift l to \u2115 using h0, rw [zpow_coe_nat], norm_cast, exact h.pow_eq_one_iff_dvd l },\n  { have : 0 \u2264 -l, { simp only [not_le, neg_nonneg] at h0 \u22a2, exact le_of_lt h0 },\n    lift -l to \u2115 using this with l' hl',\n    rw [\u2190 dvd_neg, \u2190 hl'],\n    norm_cast,\n    rw [\u2190 h.pow_eq_one_iff_dvd, \u2190 inv_inj, \u2190 zpow_neg, \u2190 hl', zpow_coe_nat, one_inv] }\nend\n\nlemma inv (h : is_primitive_root \u03b6 k) : is_primitive_root \u03b6\u207b\u00b9 k :=\n{ pow_eq_one := by simp only [h.pow_eq_one, one_inv, eq_self_iff_true, inv_pow],\n  dvd_of_pow_eq_one :=\n  begin\n    intros l hl,\n    apply h.dvd_of_pow_eq_one l,\n    rw [\u2190 inv_inj, \u2190 inv_pow, hl, one_inv]\n  end }\n\n@[simp] lemma inv_iff : is_primitive_root \u03b6\u207b\u00b9 k \u2194 is_primitive_root \u03b6 k :=\nby { refine \u27e8_, \u03bb h, inv h\u27e9, intro h, rw [\u2190 inv_inv \u03b6], exact inv h }\n\nlemma zpow_of_gcd_eq_one (h : is_primitive_root \u03b6 k) (i : \u2124) (hi : i.gcd k = 1) :\n  is_primitive_root (\u03b6 ^ i) k :=\nbegin\n  by_cases h0 : 0 \u2264 i,\n  { lift i to \u2115 using h0,\n    rw zpow_coe_nat,\n    exact h.pow_of_coprime i hi },\n  have : 0 \u2264 -i, { simp only [not_le, neg_nonneg] at h0 \u22a2, exact le_of_lt h0 },\n  lift -i to \u2115 using this with i' hi',\n  rw [\u2190 inv_iff, \u2190 zpow_neg, \u2190 hi', zpow_coe_nat],\n  apply h.pow_of_coprime,\n  rw [int.gcd, \u2190 int.nat_abs_neg, \u2190 hi'] at hi,\n  exact hi\nend\n\n@[simp] lemma coe_subgroup_iff (H : subgroup G) {\u03b6 : H} :\n  is_primitive_root (\u03b6 : G) k \u2194 is_primitive_root \u03b6 k :=\nby simp only [iff_def, \u2190 subgroup.coe_pow, \u2190 H.coe_one, \u2190 subtype.ext_iff]\n\nend comm_group\n\nsection comm_group_with_zero\n\nvariables {\u03b6 : G\u2080}\n\nlemma zpow_eq_one\u2080 (h : is_primitive_root \u03b6 k) : \u03b6 ^ (k : \u2124) = 1 :=\nby { rw zpow_coe_nat, exact h.pow_eq_one }\n\nlemma zpow_eq_one_iff_dvd\u2080 (h : is_primitive_root \u03b6 k) (l : \u2124) :\n  \u03b6 ^ l = 1 \u2194 (k : \u2124) \u2223 l :=\nbegin\n  by_cases h0 : 0 \u2264 l,\n  { lift l to \u2115 using h0, rw [zpow_coe_nat], norm_cast, exact h.pow_eq_one_iff_dvd l },\n  { have : 0 \u2264 -l, { simp only [not_le, neg_nonneg] at h0 \u22a2, exact le_of_lt h0 },\n    lift -l to \u2115 using this with l' hl',\n    rw [\u2190 dvd_neg, \u2190 hl'],\n    norm_cast,\n    rw [\u2190 h.pow_eq_one_iff_dvd, \u2190 inv_inj, \u2190 zpow_neg\u2080, \u2190 hl', zpow_coe_nat, inv_one] }\nend\n\nlemma inv' (h : is_primitive_root \u03b6 k) : is_primitive_root \u03b6\u207b\u00b9 k :=\n{ pow_eq_one := by simp only [h.pow_eq_one, inv_one, eq_self_iff_true, inv_pow\u2080],\n  dvd_of_pow_eq_one :=\n  begin\n    intros l hl,\n    apply h.dvd_of_pow_eq_one l,\n    rw [\u2190 inv_inj, \u2190 inv_pow\u2080, hl, inv_one]\n  end }\n\n@[simp] lemma inv_iff' : is_primitive_root \u03b6\u207b\u00b9 k \u2194 is_primitive_root \u03b6 k :=\nby { refine \u27e8_, \u03bb h, inv' h\u27e9, intro h, rw [\u2190 inv_inv \u03b6], exact inv' h }\n\nlemma zpow_of_gcd_eq_one\u2080 (h : is_primitive_root \u03b6 k) (i : \u2124) (hi : i.gcd k = 1) :\n  is_primitive_root (\u03b6 ^ i) k :=\nbegin\n  by_cases h0 : 0 \u2264 i,\n  { lift i to \u2115 using h0,\n    rw zpow_coe_nat,\n    exact h.pow_of_coprime i hi },\n  have : 0 \u2264 -i, { simp only [not_le, neg_nonneg] at h0 \u22a2, exact le_of_lt h0 },\n  lift -i to \u2115 using this with i' hi',\n  rw [\u2190 inv_iff', \u2190 zpow_neg\u2080, \u2190 hi', zpow_coe_nat],\n  apply h.pow_of_coprime,\n  rw [int.gcd, \u2190 int.nat_abs_neg, \u2190 hi'] at hi,\n  exact hi\nend\n\nend comm_group_with_zero\n\nsection comm_semiring\n\nvariables [comm_semiring R] [comm_semiring S] {f : F} {\u03b6 : R}\n\nopen function\n\nlemma map_of_injective [monoid_hom_class F R S] (h : is_primitive_root \u03b6 k) (hf : injective f) :\n  is_primitive_root (f \u03b6) k :=\n{ pow_eq_one := by rw [\u2190map_pow, h.pow_eq_one, _root_.map_one],\n  dvd_of_pow_eq_one := begin\n    rw h.eq_order_of,\n    intros l hl,\n    rw [\u2190map_pow, \u2190map_one f] at hl,\n    exact order_of_dvd_of_pow_eq_one (hf hl)\n  end }\n\nlemma of_map_of_injective [monoid_hom_class F R S] (h : is_primitive_root (f \u03b6) k)\n  (hf : injective f) : is_primitive_root \u03b6 k :=\n{ pow_eq_one := by { apply_fun f, rw [map_pow, _root_.map_one, h.pow_eq_one] },\n  dvd_of_pow_eq_one := begin\n    rw h.eq_order_of,\n    intros l hl,\n    apply_fun f at hl,\n    rw [map_pow, _root_.map_one] at hl,\n    exact order_of_dvd_of_pow_eq_one hl\n  end }\n\nlemma map_iff_of_injective [monoid_hom_class F R S] (hf : injective f) :\n  is_primitive_root (f \u03b6) k \u2194 is_primitive_root \u03b6 k :=\n\u27e8\u03bb h, h.of_map_of_injective hf, \u03bb h, h.map_of_injective hf\u27e9\n\nend comm_semiring\n\nsection is_domain\n\nvariables {\u03b6 : R}\nvariables [comm_ring R] [is_domain R]\n\n@[simp] lemma primitive_roots_zero : primitive_roots 0 R = \u2205 :=\nbegin\n  rw [\u2190 finset.val_eq_zero, \u2190 multiset.subset_zero, \u2190 nth_roots_zero (1 : R), primitive_roots],\n    simp only [finset.not_mem_empty, forall_const, forall_prop_of_false, multiset.to_finset_zero,\n    finset.filter_true_of_mem, finset.empty_val, not_false_iff,\n    multiset.zero_subset, nth_roots_zero]\nend\n\n@[simp] lemma primitive_roots_one : primitive_roots 1 R = {(1 : R)} :=\nbegin\n  apply finset.eq_singleton_iff_unique_mem.2,\n  split,\n  { simp only [is_primitive_root.one_right_iff, mem_primitive_roots zero_lt_one] },\n  { intros x hx,\n    rw [mem_primitive_roots zero_lt_one, is_primitive_root.one_right_iff] at hx,\n    exact hx }\nend\n\nlemma eq_neg_one_of_two_right (h : is_primitive_root \u03b6 2) : \u03b6 = -1 :=\nbegin\n  apply (eq_or_eq_neg_of_sq_eq_sq \u03b6 1 _).resolve_left,\n  { rw [\u2190 pow_one \u03b6], apply h.pow_ne_one_of_pos_of_lt; dec_trivial },\n  { simp only [h.pow_eq_one, one_pow] }\nend\n\nend is_domain\n\nsection is_domain\n\nvariables [comm_ring R]\nvariables {\u03b6 : R\u02e3} (h : is_primitive_root \u03b6 k)\n\nlemma neg_one (p : \u2115) [nontrivial R] [h : char_p R p] (hp : p \u2260 2) : is_primitive_root (-1 : R) 2 :=\nbegin\n  convert is_primitive_root.order_of (-1 : R),\n  rw [order_of_neg_one, if_neg],\n  rwa ring_char.eq_iff.mpr h\nend\n\nprotected\nlemma mem_roots_of_unity {n : \u2115+} (h : is_primitive_root \u03b6 n) : \u03b6 \u2208 roots_of_unity n R :=\nh.pow_eq_one\n\n/-- The (additive) monoid equivalence between `zmod k`\nand the powers of a primitive root of unity `\u03b6`. -/\ndef zmod_equiv_zpowers (h : is_primitive_root \u03b6 k) : zmod k \u2243+ additive (subgroup.zpowers \u03b6) :=\nadd_equiv.of_bijective\n  (add_monoid_hom.lift_of_right_inverse (int.cast_add_hom $ zmod k) _ zmod.int_cast_right_inverse\n    \u27e8{ to_fun := \u03bb i, additive.of_mul (\u27e8_, i, rfl\u27e9 : subgroup.zpowers \u03b6),\n      map_zero' := by { simp only [zpow_zero], refl },\n      map_add' := by { intros i j, simp only [zpow_add], refl } },\n    (\u03bb i hi,\n    begin\n      simp only [add_monoid_hom.mem_ker, char_p.int_cast_eq_zero_iff (zmod k) k,\n        add_monoid_hom.coe_mk, int.coe_cast_add_hom] at hi \u22a2,\n      obtain \u27e8i, rfl\u27e9 := hi,\n      simp only [zpow_mul, h.pow_eq_one, one_zpow, zpow_coe_nat],\n      refl\n    end)\u27e9)\n  begin\n    split,\n    { rw add_monoid_hom.injective_iff,\n      intros i hi,\n      rw subtype.ext_iff at hi,\n      have := (h.zpow_eq_one_iff_dvd _).mp hi,\n      rw [\u2190 (char_p.int_cast_eq_zero_iff (zmod k) k _).mpr this, eq_comm],\n      exact zmod.int_cast_right_inverse i },\n    { rintro \u27e8\u03be, i, rfl\u27e9,\n      refine \u27e8int.cast_add_hom _ i, _\u27e9,\n      rw [add_monoid_hom.lift_of_right_inverse_comp_apply],\n      refl }\n  end\n\n@[simp] lemma zmod_equiv_zpowers_apply_coe_int (i : \u2124) :\n  h.zmod_equiv_zpowers i = additive.of_mul (\u27e8\u03b6 ^ i, i, rfl\u27e9 : subgroup.zpowers \u03b6) :=\nadd_monoid_hom.lift_of_right_inverse_comp_apply _ _ zmod.int_cast_right_inverse _ _\n\n@[simp] lemma zmod_equiv_zpowers_apply_coe_nat (i : \u2115) :\n  h.zmod_equiv_zpowers i = additive.of_mul (\u27e8\u03b6 ^ i, i, rfl\u27e9 : subgroup.zpowers \u03b6) :=\nbegin\n  have : (i : zmod k) = (i : \u2124), by norm_cast,\n  simp only [this, zmod_equiv_zpowers_apply_coe_int, zpow_coe_nat],\n  refl\nend\n\n@[simp] lemma zmod_equiv_zpowers_symm_apply_zpow (i : \u2124) :\n  h.zmod_equiv_zpowers.symm (additive.of_mul (\u27e8\u03b6 ^ i, i, rfl\u27e9 : subgroup.zpowers \u03b6)) = i :=\nby rw [\u2190 h.zmod_equiv_zpowers.symm_apply_apply i, zmod_equiv_zpowers_apply_coe_int]\n\n@[simp] lemma zmod_equiv_zpowers_symm_apply_zpow' (i : \u2124) :\n  h.zmod_equiv_zpowers.symm \u27e8\u03b6 ^ i, i, rfl\u27e9 = i :=\nh.zmod_equiv_zpowers_symm_apply_zpow i\n\n@[simp] lemma zmod_equiv_zpowers_symm_apply_pow (i : \u2115) :\n  h.zmod_equiv_zpowers.symm (additive.of_mul (\u27e8\u03b6 ^ i, i, rfl\u27e9 : subgroup.zpowers \u03b6)) = i :=\nby rw [\u2190 h.zmod_equiv_zpowers.symm_apply_apply i, zmod_equiv_zpowers_apply_coe_nat]\n\n@[simp] lemma zmod_equiv_zpowers_symm_apply_pow' (i : \u2115) :\n  h.zmod_equiv_zpowers.symm \u27e8\u03b6 ^ i, i, rfl\u27e9 = i :=\nh.zmod_equiv_zpowers_symm_apply_pow i\n\n/-- If there is a `n`-th primitive root of unity in `R` and `b` divides `n`,\nthen there is a `b`-th primitive root of unity in `R`. -/\nlemma pow {\u03b6 : R} {n : \u2115} {a b : \u2115}\n  (hn : 0 < n) (h : is_primitive_root \u03b6 n) (hprod : n = a * b) :\n  is_primitive_root (\u03b6 ^ a) b :=\nbegin\n  subst n,\n  simp only [iff_def, \u2190 pow_mul, h.pow_eq_one, eq_self_iff_true, true_and],\n  intros l hl,\n  have ha0 : a \u2260 0, { rintro rfl, simpa only [nat.not_lt_zero, zero_mul] using hn },\n  rwa \u2190 mul_dvd_mul_iff_left ha0,\n  exact h.dvd_of_pow_eq_one _ hl\nend\n\nvariables [is_domain R]\n\nlemma zpowers_eq {k : \u2115+} {\u03b6 : R\u02e3} (h : is_primitive_root \u03b6 k) :\n  subgroup.zpowers \u03b6 = roots_of_unity k R :=\nbegin\n  apply set_like.coe_injective,\n  haveI : fact (0 < (k : \u2115)) := \u27e8k.pos\u27e9,\n  haveI F : fintype (subgroup.zpowers \u03b6) := fintype.of_equiv _ (h.zmod_equiv_zpowers).to_equiv,\n  refine @set.eq_of_subset_of_card_le R\u02e3 (subgroup.zpowers \u03b6) (roots_of_unity k R)\n    F (roots_of_unity.fintype R k)\n    (subgroup.zpowers_subset $ show \u03b6 \u2208 roots_of_unity k R, from h.pow_eq_one) _,\n  calc fintype.card (roots_of_unity k R)\n      \u2264 k                                 : card_roots_of_unity R k\n  ... = fintype.card (zmod k)             : (zmod.card k).symm\n  ... = fintype.card (subgroup.zpowers \u03b6) : fintype.card_congr (h.zmod_equiv_zpowers).to_equiv\nend\n\nlemma eq_pow_of_mem_roots_of_unity {k : \u2115+} {\u03b6 \u03be : R\u02e3}\n  (h : is_primitive_root \u03b6 k) (h\u03be : \u03be \u2208 roots_of_unity k R) :\n  \u2203 (i : \u2115) (hi : i < k), \u03b6 ^ i = \u03be :=\nbegin\n  obtain \u27e8n, rfl\u27e9 : \u2203 n : \u2124, \u03b6 ^ n = \u03be, by rwa [\u2190 h.zpowers_eq] at h\u03be,\n  have hk0 : (0 : \u2124) < k := by exact_mod_cast k.pos,\n  let i := n % k,\n  have hi0 : 0 \u2264 i := int.mod_nonneg _ (ne_of_gt hk0),\n  lift i to \u2115 using hi0 with i\u2080 hi\u2080,\n  refine \u27e8i\u2080, _, _\u27e9,\n  { zify, rw [hi\u2080], exact int.mod_lt_of_pos _ hk0 },\n  { have aux := h.zpow_eq_one, rw [\u2190 coe_coe] at aux,\n    rw [\u2190 zpow_coe_nat, hi\u2080, \u2190 int.mod_add_div n k, zpow_add, zpow_mul,\n        aux, one_zpow, mul_one] }\nend\n\nlemma eq_pow_of_pow_eq_one {k : \u2115} {\u03b6 \u03be : R}\n  (h : is_primitive_root \u03b6 k) (h\u03be : \u03be ^ k = 1) (h0 : 0 < k) :\n  \u2203 i < k, \u03b6 ^ i = \u03be :=\nbegin\n  obtain \u27e8\u03b6, rfl\u27e9 := h.is_unit h0,\n  obtain \u27e8\u03be, rfl\u27e9 := is_unit_of_pow_eq_one \u03be k h\u03be h0,\n  obtain \u27e8k, rfl\u27e9 : \u2203 k' : \u2115+, k = k' := \u27e8\u27e8k, h0\u27e9, rfl\u27e9,\n  simp only [\u2190 units.coe_pow, \u2190 units.ext_iff],\n  rw coe_units_iff at h,\n  apply h.eq_pow_of_mem_roots_of_unity,\n  rw [mem_roots_of_unity, units.ext_iff, units.coe_pow, h\u03be, units.coe_one]\nend\n\nlemma is_primitive_root_iff' {k : \u2115+} {\u03b6 \u03be : R\u02e3} (h : is_primitive_root \u03b6 k) :\n  is_primitive_root \u03be k \u2194 \u2203 (i < (k : \u2115)) (hi : i.coprime k), \u03b6 ^ i = \u03be :=\nbegin\n  split,\n  { intro h\u03be,\n    obtain \u27e8i, hik, rfl\u27e9 := h.eq_pow_of_mem_roots_of_unity h\u03be.pow_eq_one,\n    rw h.pow_iff_coprime k.pos at h\u03be,\n    exact \u27e8i, hik, h\u03be, rfl\u27e9 },\n  { rintro \u27e8i, -, hi, rfl\u27e9, exact h.pow_of_coprime i hi }\nend\n\nlemma is_primitive_root_iff {k : \u2115} {\u03b6 \u03be : R} (h : is_primitive_root \u03b6 k) (h0 : 0 < k) :\n  is_primitive_root \u03be k \u2194 \u2203 (i < k) (hi : i.coprime k), \u03b6 ^ i = \u03be :=\nbegin\n  split,\n  { intro h\u03be,\n    obtain \u27e8i, hik, rfl\u27e9 := h.eq_pow_of_pow_eq_one h\u03be.pow_eq_one h0,\n    rw h.pow_iff_coprime h0 at h\u03be,\n    exact \u27e8i, hik, h\u03be, rfl\u27e9 },\n  { rintro \u27e8i, -, hi, rfl\u27e9, exact h.pow_of_coprime i hi }\nend\n\nlemma card_roots_of_unity' {n : \u2115+} (h : is_primitive_root \u03b6 n) :\n  fintype.card (roots_of_unity n R) = n :=\nbegin\n  haveI : fact (0 < \u2191n) := \u27e8n.pos\u27e9,\n  let e := h.zmod_equiv_zpowers,\n  haveI F : fintype (subgroup.zpowers \u03b6) := fintype.of_equiv _ e.to_equiv,\n  calc fintype.card (roots_of_unity n R)\n      = fintype.card (subgroup.zpowers \u03b6) : fintype.card_congr $ by rw h.zpowers_eq\n  ... = fintype.card (zmod n)             : fintype.card_congr e.to_equiv.symm\n  ... = n                                 : zmod.card n\nend\n\nlemma card_roots_of_unity {\u03b6 : R} {n : \u2115+} (h : is_primitive_root \u03b6 n) :\n  fintype.card (roots_of_unity n R) = n :=\nbegin\n  obtain \u27e8\u03b6, h\u03b6\u27e9 := h.is_unit n.pos,\n  rw [\u2190 h\u03b6, is_primitive_root.coe_units_iff] at h,\n  exact h.card_roots_of_unity'\nend\n\n/-- The cardinality of the multiset `nth_roots \u2191n (1 : R)` is `n`\nif there is a primitive root of unity in `R`. -/\nlemma card_nth_roots {\u03b6 : R} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  (nth_roots n (1 : R)).card = n :=\nbegin\n  cases nat.eq_zero_or_pos n with hzero hpos,\n  { simp only [hzero, multiset.card_zero, nth_roots_zero] },\n  rw eq_iff_le_not_lt,\n  use card_nth_roots n 1,\n  { rw [not_lt],\n    have hcard : fintype.card {x // x \u2208 nth_roots n (1 : R)}\n      \u2264 (nth_roots n (1 : R)).attach.card := multiset.card_le_of_le (multiset.dedup_le _),\n    rw multiset.card_attach at hcard,\n    rw \u2190 pnat.to_pnat'_coe hpos at hcard h \u22a2,\n    set m := nat.to_pnat' n,\n    rw [\u2190 fintype.card_congr (roots_of_unity_equiv_nth_roots R m), card_roots_of_unity h] at hcard,\n    exact hcard }\nend\n\n/-- The multiset `nth_roots \u2191n (1 : R)` has no repeated elements\nif there is a primitive root of unity in `R`. -/\nlemma nth_roots_nodup {\u03b6 : R} {n : \u2115} (h : is_primitive_root \u03b6 n) : (nth_roots n (1 : R)).nodup :=\nbegin\n  cases nat.eq_zero_or_pos n with hzero hpos,\n  { simp only [hzero, multiset.nodup_zero, nth_roots_zero] },\n  apply (@multiset.dedup_eq_self R _ _).1,\n  rw eq_iff_le_not_lt,\n  split,\n  { exact multiset.dedup_le (nth_roots n (1 : R)) },\n  { by_contra ha,\n    replace ha := multiset.card_lt_of_lt ha,\n    rw card_nth_roots h at ha,\n    have hrw : (nth_roots n (1 : R)).dedup.card =\n      fintype.card {x // x \u2208 (nth_roots n (1 : R))},\n    { set fs := (\u27e8(nth_roots n (1 : R)).dedup, multiset.nodup_dedup _\u27e9 : finset R),\n      rw [\u2190 finset.card_mk, \u2190 fintype.card_of_subtype fs _],\n      intro x,\n      simp only [multiset.mem_dedup, finset.mem_mk] },\n    rw \u2190 pnat.to_pnat'_coe hpos at h hrw ha,\n    set m := nat.to_pnat' n,\n    rw [hrw, \u2190 fintype.card_congr (roots_of_unity_equiv_nth_roots R m),\n        card_roots_of_unity h] at ha,\n    exact nat.lt_asymm ha ha }\nend\n\n@[simp] lemma card_nth_roots_finset {\u03b6 : R} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  (nth_roots_finset n R).card = n :=\nby rw [nth_roots_finset, \u2190 multiset.to_finset_eq (nth_roots_nodup h), card_mk, h.card_nth_roots]\n\nopen_locale nat\n\n/-- If an integral domain has a primitive `k`-th root of unity, then it has `\u03c6 k` of them. -/\nlemma card_primitive_roots {\u03b6 : R} {k : \u2115} (h : is_primitive_root \u03b6 k) :\n  (primitive_roots k R).card = \u03c6 k :=\nbegin\n  by_cases h0 : k = 0,\n  { simp [h0], },\n  symmetry,\n  refine finset.card_congr (\u03bb i _, \u03b6 ^ i) _ _ _,\n  { simp only [true_and, and_imp, mem_filter, mem_range, mem_univ],\n    rintro i - hi,\n    rw mem_primitive_roots (nat.pos_of_ne_zero h0),\n    exact h.pow_of_coprime i hi.symm },\n  { simp only [true_and, and_imp, mem_filter, mem_range, mem_univ],\n    rintro i j hi - hj - H,\n    exact h.pow_inj hi hj H },\n  { simp only [exists_prop, true_and, mem_filter, mem_range, mem_univ],\n    intros \u03be h\u03be,\n    rw [mem_primitive_roots (nat.pos_of_ne_zero h0),\n      h.is_primitive_root_iff (nat.pos_of_ne_zero h0)] at h\u03be,\n    rcases h\u03be with \u27e8i, hin, hi, H\u27e9,\n    exact \u27e8i, \u27e8hin, hi.symm\u27e9, H\u27e9 }\nend\n\n/-- The sets `primitive_roots k R` are pairwise disjoint. -/\nlemma disjoint {k l : \u2115} (h : k \u2260 l) :\n  disjoint (primitive_roots k R) (primitive_roots l R) :=\nbegin\n  by_cases hk : k = 0, { simp [hk], },\n  by_cases hl : l = 0, { simp [hl], },\n  intro z,\n  simp only [finset.inf_eq_inter, finset.mem_inter, mem_primitive_roots,\n    nat.pos_of_ne_zero hk, nat.pos_of_ne_zero hl, iff_def],\n  rintro \u27e8\u27e8hzk, Hzk\u27e9, \u27e8hzl, Hzl\u27e9\u27e9,\n  apply_rules [h, nat.dvd_antisymm, Hzk, Hzl, hzk, hzl]\nend\n\n/-- `nth_roots n` as a `finset` is equal to the union of `primitive_roots i R` for `i \u2223 n`\nif there is a primitive root of unity in `R`.\nThis holds for any `nat`, not just `pnat`, see `nth_roots_one_eq_bUnion_primitive_roots`. -/\nlemma nth_roots_one_eq_bUnion_primitive_roots' {\u03b6 : R} {n : \u2115+} (h : is_primitive_root \u03b6 n) :\n  nth_roots_finset n R = (nat.divisors \u2191n).bUnion (\u03bb i, (primitive_roots i R)) :=\nbegin\n  symmetry,\n  apply finset.eq_of_subset_of_card_le,\n  { intros x,\n    simp only [nth_roots_finset, \u2190 multiset.to_finset_eq (nth_roots_nodup h),\n      exists_prop, finset.mem_bUnion, finset.mem_filter, finset.mem_range, mem_nth_roots,\n      finset.mem_mk, nat.mem_divisors, and_true, ne.def, pnat.ne_zero, pnat.pos, not_false_iff],\n    rintro \u27e8a, \u27e8d, hd\u27e9, ha\u27e9,\n    have hazero : 0 < a,\n    { contrapose! hd with ha0,\n      simp only [nonpos_iff_eq_zero, zero_mul, *] at *,\n      exact n.ne_zero },\n    rw mem_primitive_roots hazero at ha,\n    rw [hd, pow_mul, ha.pow_eq_one, one_pow] },\n  { apply le_of_eq,\n    rw [h.card_nth_roots_finset, finset.card_bUnion],\n    { rw [\u2190 nat.sum_totient n, nat.filter_dvd_eq_divisors (pnat.ne_zero n), sum_congr rfl]\n        { occs := occurrences.pos [1] },\n      simp only [finset.mem_filter, finset.mem_range, nat.mem_divisors],\n      rintro k \u27e8H, hk\u27e9,\n      have hdvd := H,\n      rcases H with \u27e8d, hd\u27e9,\n      rw mul_comm at hd,\n      rw (h.pow n.pos hd).card_primitive_roots },\n    { intros i hi j hj hdiff,\n      exact disjoint hdiff } }\nend\n\n/-- `nth_roots n` as a `finset` is equal to the union of `primitive_roots i R` for `i \u2223 n`\nif there is a primitive root of unity in `R`. -/\nlemma nth_roots_one_eq_bUnion_primitive_roots {\u03b6 : R} {n : \u2115}\n  (h : is_primitive_root \u03b6 n) :\n  nth_roots_finset n R = (nat.divisors n).bUnion (\u03bb i, (primitive_roots i R)) :=\nbegin\n  by_cases hn : n = 0,\n  { simp [hn], },\n  exact @nth_roots_one_eq_bUnion_primitive_roots' _ _ _ _ \u27e8n, nat.pos_of_ne_zero hn\u27e9 h\nend\n\nend is_domain\n\nsection minpoly\n\nopen minpoly\n\nsection comm_ring\nvariables {n : \u2115} {K : Type*} [comm_ring K] {\u03bc : K} (h : is_primitive_root \u03bc n) (hpos : 0 < n)\n\ninclude n \u03bc h hpos\n\n/--`\u03bc` is integral over `\u2124`. -/\nlemma is_integral : is_integral \u2124 \u03bc :=\nbegin\n  use (X ^ n - 1),\n  split,\n  { exact (monic_X_pow_sub_C 1 (ne_of_lt hpos).symm) },\n  { simp only [((is_primitive_root.iff_def \u03bc n).mp h).left, eval\u2082_one, eval\u2082_X_pow, eval\u2082_sub,\n      sub_self] }\nend\nend comm_ring\n\nvariables {n : \u2115} {K : Type*} [field K] {\u03bc : K} (h : is_primitive_root \u03bc n) (hpos : 0 < n)\n\ninclude n \u03bc h hpos\n\nvariables [char_zero K]\n\nomit hpos\n/--The minimal polynomial of a root of unity `\u03bc` divides `X ^ n - 1`. -/\nlemma minpoly_dvd_X_pow_sub_one : minpoly \u2124 \u03bc \u2223 X ^ n - 1 :=\nbegin\n  by_cases hpos : n = 0, { simp [hpos], },\n  apply minpoly.gcd_domain_dvd \u211a (is_integral h (nat.pos_of_ne_zero hpos))\n    (polynomial.monic.is_primitive (monic_X_pow_sub_C 1 (ne_of_lt (nat.pos_of_ne_zero hpos)).symm)),\n  simp only [((is_primitive_root.iff_def \u03bc n).mp h).left, aeval_X_pow, ring_hom.eq_int_cast,\n  int.cast_one, aeval_one, alg_hom.map_sub, sub_self]\nend\n\n/-- The reduction modulo `p` of the minimal polynomial of a root of unity `\u03bc` is separable. -/\nlemma separable_minpoly_mod {p : \u2115} [fact p.prime] (hdiv : \u00acp \u2223 n) :\n  separable (map (int.cast_ring_hom (zmod p)) (minpoly \u2124 \u03bc)) :=\nbegin\n  have hdvd : (map (int.cast_ring_hom (zmod p))\n    (minpoly \u2124 \u03bc)) \u2223 X ^ n - 1,\n  { simpa [polynomial.map_pow, map_X, polynomial.map_one, polynomial.map_sub] using\n      ring_hom.map_dvd (map_ring_hom (int.cast_ring_hom (zmod p)))\n        (minpoly_dvd_X_pow_sub_one h) },\n  refine separable.of_dvd (separable_X_pow_sub_C 1 _ one_ne_zero) hdvd,\n  by_contra hzero,\n  exact hdiv ((zmod.nat_coe_zmod_eq_zero_iff_dvd n p).1 hzero)\nend\n\n/-- The reduction modulo `p` of the minimal polynomial of a root of unity `\u03bc` is squarefree. -/\nlemma squarefree_minpoly_mod {p : \u2115} [fact p.prime] (hdiv : \u00ac p \u2223 n) :\n  squarefree (map (int.cast_ring_hom (zmod p)) (minpoly \u2124 \u03bc)) :=\n(separable_minpoly_mod h hdiv).squarefree\n\n/- Let `P` be the minimal polynomial of a root of unity `\u03bc` and `Q` be the minimal polynomial of\n`\u03bc ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `expand \u2124 p Q`. -/\nlemma minpoly_dvd_expand {p : \u2115} (hprime : nat.prime p) (hdiv : \u00ac p \u2223 n) :\n  minpoly \u2124 \u03bc \u2223\n  expand \u2124 p (minpoly \u2124 (\u03bc ^ p)) :=\nbegin\n  by_cases hn : n = 0, { simp * at *, },\n  have hpos := nat.pos_of_ne_zero hn,\n  apply minpoly.gcd_domain_dvd \u211a (h.is_integral hpos),\n  { apply monic.is_primitive,\n    rw [polynomial.monic, leading_coeff, nat_degree_expand, mul_comm, coeff_expand_mul'\n        (nat.prime.pos hprime), \u2190 leading_coeff, \u2190 polynomial.monic],\n    exact minpoly.monic (is_integral (pow_of_prime h hprime hdiv) hpos) },\n  { rw [aeval_def, coe_expand, \u2190 comp, eval\u2082_eq_eval_map, map_comp, polynomial.map_pow, map_X,\n        eval_comp, eval_pow, eval_X, \u2190 eval\u2082_eq_eval_map, \u2190 aeval_def],\n    exact minpoly.aeval _ _ }\nend\n\n/- Let `P` be the minimal polynomial of a root of unity `\u03bc` and `Q` be the minimal polynomial of\n`\u03bc ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q ^ p` modulo `p`. -/\nlemma minpoly_dvd_pow_mod {p : \u2115} [hprime : fact p.prime] (hdiv : \u00ac p \u2223 n) :\n  map (int.cast_ring_hom (zmod p)) (minpoly \u2124 \u03bc) \u2223\n  map (int.cast_ring_hom (zmod p)) (minpoly \u2124 (\u03bc ^ p)) ^ p :=\nbegin\n  set Q := minpoly \u2124 (\u03bc ^ p),\n  have hfrob : map (int.cast_ring_hom (zmod p)) Q ^ p =\n    map (int.cast_ring_hom (zmod p)) (expand \u2124 p Q),\n  by rw [\u2190 zmod.expand_card, map_expand],\n  rw [hfrob],\n  apply ring_hom.map_dvd (map_ring_hom (int.cast_ring_hom (zmod p))),\n  exact minpoly_dvd_expand h hprime.1 hdiv\nend\n\n/- Let `P` be the minimal polynomial of a root of unity `\u03bc` and `Q` be the minimal polynomial of\n`\u03bc ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q` modulo `p`. -/\nlemma minpoly_dvd_mod_p {p : \u2115} [hprime : fact p.prime] (hdiv : \u00ac p \u2223 n) :\n  map (int.cast_ring_hom (zmod p)) (minpoly \u2124 \u03bc) \u2223\n  map (int.cast_ring_hom (zmod p)) (minpoly \u2124 (\u03bc ^ p)) :=\n(unique_factorization_monoid.dvd_pow_iff_dvd_of_squarefree (squarefree_minpoly_mod h\n  hdiv) hprime.1.ne_zero).1 (minpoly_dvd_pow_mod h hdiv)\n\n/-- If `p` is a prime that does not divide `n`,\nthen the minimal polynomials of a primitive `n`-th root of unity `\u03bc`\nand of `\u03bc ^ p` are the same. -/\nlemma minpoly_eq_pow {p : \u2115} [hprime : fact p.prime] (hdiv : \u00ac p \u2223 n) :\n  minpoly \u2124 \u03bc = minpoly \u2124 (\u03bc ^ p) :=\nbegin\n  by_cases hn : n = 0, { simp * at *, },\n  have hpos := nat.pos_of_ne_zero hn,\n  by_contra hdiff,\n  set P := minpoly \u2124 \u03bc,\n  set Q := minpoly \u2124 (\u03bc ^ p),\n  have Pmonic : P.monic := minpoly.monic (h.is_integral hpos),\n  have Qmonic : Q.monic := minpoly.monic ((h.pow_of_prime hprime.1 hdiv).is_integral hpos),\n  have Pirr : irreducible P := minpoly.irreducible (h.is_integral hpos),\n  have Qirr : irreducible Q :=\n    minpoly.irreducible ((h.pow_of_prime hprime.1 hdiv).is_integral hpos),\n  have PQprim : is_primitive (P * Q) := Pmonic.is_primitive.mul Qmonic.is_primitive,\n  have prod : P * Q \u2223 X ^ n - 1,\n  { rw [(is_primitive.int.dvd_iff_map_cast_dvd_map_cast (P * Q) (X ^ n - 1) PQprim\n      (monic_X_pow_sub_C (1 : \u2124) (ne_of_gt hpos)).is_primitive), polynomial.map_mul],\n    refine is_coprime.mul_dvd _ _ _,\n    { have aux := is_primitive.int.irreducible_iff_irreducible_map_cast Pmonic.is_primitive,\n      refine (dvd_or_coprime _ _ (aux.1 Pirr)).resolve_left _,\n      rw map_dvd_map (int.cast_ring_hom \u211a) int.cast_injective Pmonic,\n      intro hdiv,\n      refine hdiff (eq_of_monic_of_associated Pmonic Qmonic _),\n      exact associated_of_dvd_dvd hdiv (Pirr.dvd_symm Qirr hdiv) },\n    { apply (map_dvd_map (int.cast_ring_hom \u211a) int.cast_injective Pmonic).2,\n      exact minpoly_dvd_X_pow_sub_one h },\n    { apply (map_dvd_map (int.cast_ring_hom \u211a) int.cast_injective Qmonic).2,\n      exact minpoly_dvd_X_pow_sub_one (pow_of_prime h hprime.1 hdiv) } },\n  replace prod := ring_hom.map_dvd ((map_ring_hom (int.cast_ring_hom (zmod p)))) prod,\n  rw [coe_map_ring_hom, polynomial.map_mul, polynomial.map_sub,\n      polynomial.map_one, polynomial.map_pow, map_X] at prod,\n  obtain \u27e8R, hR\u27e9 := minpoly_dvd_mod_p h hdiv,\n  rw [hR, \u2190 mul_assoc, \u2190 polynomial.map_mul, \u2190 sq, polynomial.map_pow] at prod,\n  have habs : map (int.cast_ring_hom (zmod p)) P ^ 2 \u2223 map (int.cast_ring_hom (zmod p)) P ^ 2 * R,\n  { use R },\n  replace habs := lt_of_lt_of_le (enat.coe_lt_coe.2 one_lt_two)\n    (multiplicity.le_multiplicity_of_pow_dvd (dvd_trans habs prod)),\n  have hfree : squarefree (X ^ n - 1 : (zmod p)[X]),\n  { exact (separable_X_pow_sub_C 1\n          (\u03bb h, hdiv $ (zmod.nat_coe_zmod_eq_zero_iff_dvd n p).1 h) one_ne_zero).squarefree },\n  cases (multiplicity.squarefree_iff_multiplicity_le_one (X ^ n - 1)).1 hfree\n    (map (int.cast_ring_hom (zmod p)) P) with hle hunit,\n  { rw nat.cast_one at habs, exact hle.not_lt habs },\n  { replace hunit := degree_eq_zero_of_is_unit hunit,\n    rw degree_map_eq_of_leading_coeff_ne_zero (int.cast_ring_hom (zmod p)) _ at hunit,\n    { exact (minpoly.degree_pos (is_integral h hpos)).ne' hunit },\n    simp only [Pmonic, ring_hom.eq_int_cast, monic.leading_coeff, int.cast_one, ne.def,\n      not_false_iff, one_ne_zero] }\nend\n\n/-- If `m : \u2115` is coprime with `n`,\nthen the minimal polynomials of a primitive `n`-th root of unity `\u03bc`\nand of `\u03bc ^ m` are the same. -/\nlemma minpoly_eq_pow_coprime {m : \u2115} (hcop : nat.coprime m n) :\n  minpoly \u2124 \u03bc = minpoly \u2124 (\u03bc ^ m) :=\nbegin\n  revert n hcop,\n  refine unique_factorization_monoid.induction_on_prime m _ _ _,\n  { intros n hn h,\n    congr,\n    simpa [(nat.coprime_zero_left n).mp hn] using h },\n  { intros u hunit n hcop h,\n    congr,\n    simp [nat.is_unit_iff.mp hunit] },\n  { intros a p ha hprime hind n hcop h,\n    rw hind (nat.coprime.coprime_mul_left hcop) h, clear hind,\n    replace hprime := nat.prime_iff.2 hprime,\n    have hdiv := (nat.prime.coprime_iff_not_dvd hprime).1 (nat.coprime.coprime_mul_right hcop),\n    haveI := fact.mk hprime,\n    rw [minpoly_eq_pow (h.pow_of_coprime a (nat.coprime.coprime_mul_left hcop)) hdiv],\n    congr' 1,\n    ring_exp }\nend\n\n/-- If `m : \u2115` is coprime with `n`,\nthen the minimal polynomial of a primitive `n`-th root of unity `\u03bc`\nhas `\u03bc ^ m` as root. -/\nlemma pow_is_root_minpoly {m : \u2115} (hcop : nat.coprime m n) :\n  is_root (map (int.cast_ring_hom K) (minpoly \u2124 \u03bc)) (\u03bc ^ m) :=\nby simpa [minpoly_eq_pow_coprime h hcop, eval_map, aeval_def (\u03bc ^ m) _]\n  using minpoly.aeval \u2124 (\u03bc ^ m)\n\n/-- `primitive_roots n K` is a subset of the roots of the minimal polynomial of a primitive\n`n`-th root of unity `\u03bc`. -/\nlemma is_roots_of_minpoly : primitive_roots n K \u2286 (map (int.cast_ring_hom K)\n  (minpoly \u2124 \u03bc)).roots.to_finset :=\nbegin\n  by_cases hn : n = 0, { simp * at *, },\n  have hpos := nat.pos_of_ne_zero hn,\n  intros x hx,\n  obtain \u27e8m, hle, hcop, rfl\u27e9 := (is_primitive_root_iff h hpos).1 ((mem_primitive_roots hpos).1 hx),\n  simpa [multiset.mem_to_finset,\n    mem_roots (map_monic_ne_zero $ minpoly.monic $ is_integral h hpos)]\n    using pow_is_root_minpoly h hcop\nend\n\n/-- The degree of the minimal polynomial of `\u03bc` is at least `totient n`. -/\nlemma totient_le_degree_minpoly : nat.totient n \u2264 (minpoly \u2124 \u03bc).nat_degree :=\nlet P : \u2124[X] := minpoly \u2124 \u03bc,-- minimal polynomial of `\u03bc`\n    P_K : K[X] := map (int.cast_ring_hom K) P -- minimal polynomial of `\u03bc` sent to `K[X]`\nin calc\nn.totient = (primitive_roots n K).card : h.card_primitive_roots.symm\n... \u2264 P_K.roots.to_finset.card : finset.card_le_of_subset (is_roots_of_minpoly h)\n... \u2264 P_K.roots.card : multiset.to_finset_card_le _\n... \u2264 P_K.nat_degree : card_roots' _\n... \u2264 P.nat_degree : nat_degree_map_le _ _\n\nend minpoly\n\nsection automorphisms\n\nvariables {S} [comm_ring S] [is_domain S] {\u03bc : S} {n : \u2115+} (h\u03bc : is_primitive_root \u03bc n)\n          (R) [comm_ring R] [algebra R S]\n\n/-- The `monoid_hom` that takes an automorphism to the power of \u03bc that \u03bc gets mapped to under it. -/\n@[simps {attrs := []}] noncomputable def aut_to_pow : (S \u2243\u2090[R] S) \u2192* (zmod n)\u02e3 :=\nlet \u03bc' := h\u03bc.to_roots_of_unity in\nhave ho : order_of \u03bc' = n :=\n  by rw [h\u03bc.eq_order_of, \u2190h\u03bc.coe_to_roots_of_unity_coe, order_of_units, order_of_subgroup],\nmonoid_hom.to_hom_units\n{ to_fun := \u03bb \u03c3, (map_root_of_unity_eq_pow_self \u03c3.to_alg_hom \u03bc').some,\n  map_one' := begin\n    generalize_proofs h1,\n    have h := h1.some_spec,\n    dsimp only [alg_equiv.one_apply, alg_equiv.to_ring_equiv_eq_coe, ring_equiv.to_ring_hom_eq_coe,\n                ring_equiv.coe_to_ring_hom, alg_equiv.coe_ring_equiv] at *,\n    replace h : \u03bc' = \u03bc' ^ h1.some := roots_of_unity.coe_injective\n                 (by simpa only [roots_of_unity.coe_pow] using h),\n    rw \u2190pow_one \u03bc' at h {occs := occurrences.pos [1]},\n    rw [\u2190@nat.cast_one $ zmod n, zmod.nat_coe_eq_nat_coe_iff, \u2190ho, \u2190pow_eq_pow_iff_modeq \u03bc', h]\n  end,\n  map_mul' := begin\n    generalize_proofs hxy' hx' hy',\n    have hxy := hxy'.some_spec,\n    have hx := hx'.some_spec,\n    have hy := hy'.some_spec,\n    dsimp only [alg_equiv.to_ring_equiv_eq_coe, ring_equiv.to_ring_hom_eq_coe,\n                ring_equiv.coe_to_ring_hom, alg_equiv.coe_ring_equiv, alg_equiv.mul_apply] at *,\n    replace hxy : x (\u2191\u03bc' ^ hy'.some) = \u2191\u03bc' ^ hxy'.some := hy \u25b8 hxy,\n    rw x.map_pow at hxy,\n    replace hxy : ((\u03bc' : S) ^ hx'.some) ^ hy'.some = \u03bc' ^ hxy'.some := hx \u25b8 hxy,\n    rw \u2190pow_mul at hxy,\n    replace hxy : \u03bc' ^ (hx'.some * hy'.some) = \u03bc' ^ hxy'.some := roots_of_unity.coe_injective\n                                           (by simpa only [roots_of_unity.coe_pow] using hxy),\n    rw [\u2190nat.cast_mul, zmod.nat_coe_eq_nat_coe_iff, \u2190ho, \u2190pow_eq_pow_iff_modeq \u03bc', hxy]\n  end }\n\n@[simp] lemma aut_to_pow_spec (f : S \u2243\u2090[R] S) :\n  \u03bc ^ (h\u03bc.aut_to_pow R f : zmod n).val = f \u03bc :=\nbegin\n  rw is_primitive_root.coe_aut_to_pow_apply,\n  generalize_proofs h,\n  have := h.some_spec,\n  dsimp only [alg_equiv.to_alg_hom_eq_coe, alg_equiv.coe_alg_hom] at this,\n  refine (_ : \u2191h\u03bc.to_roots_of_unity ^ _ = _).trans this.symm,\n  rw [\u2190roots_of_unity.coe_pow, \u2190roots_of_unity.coe_pow],\n  congr' 1,\n  rw [pow_eq_pow_iff_modeq, \u2190order_of_subgroup, \u2190order_of_units, h\u03bc.coe_to_roots_of_unity_coe,\n      \u2190h\u03bc.eq_order_of, zmod.val_nat_cast],\n  exact nat.mod_modeq _ _\nend\n\nend automorphisms\n\nend is_primitive_root\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/roots_of_unity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7218540533748193}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Eric Wieser\n-/\nimport algebra.order.module\nimport data.real.basic\n\n/-!\n# Pointwise operations on sets of reals\n\nThis file relates `Inf (a \u2022 s)`/`Sup (a \u2022 s)` with `a \u2022 Inf s`/`a \u2022 Sup s` for `s : set \u211d`.\n\nFrom these, it relates `\u2a05 i, a \u2022 f i` / `\u2a06 i, a \u2022 f i` with `a \u2022 (\u2a05 i, f i)` / `a \u2022 (\u2a06 i, f i)`,\nand provides lemmas about distributing `*` over `\u2a05` and `\u2a06`.\n\n# TODO\n\nThis is true more generally for conditionally complete linear order whose default value is `0`. We\ndon't have those yet.\n-/\n\nopen set\nopen_locale pointwise\n\nvariables {\u03b9 : Sort*} {\u03b1 : Type*} [linear_ordered_field \u03b1]\n\nsection mul_action_with_zero\nvariables [mul_action_with_zero \u03b1 \u211d] [ordered_smul \u03b1 \u211d] {a : \u03b1}\n\nlemma real.Inf_smul_of_nonneg (ha : 0 \u2264 a) (s : set \u211d) : Inf (a \u2022 s) = a \u2022 Inf s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Inf_empty, smul_zero'] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cInf_singleton 0 },\n  by_cases bdd_below s,\n  { exact ((order_iso.smul_left \u211d ha').map_cInf' hs h).symm },\n  { rw [real.Inf_of_not_bdd_below (mt (bdd_below_smul_iff_of_pos ha').1 h),\n      real.Inf_of_not_bdd_below h, smul_zero'] }\nend\n\nlemma real.smul_infi_of_nonneg (ha : 0 \u2264 a) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a05 i, f i) = \u2a05 i, a \u2022 f i :=\n(real.Inf_smul_of_nonneg ha _).symm.trans $ congr_arg Inf $ (range_comp _ _).symm\n\nlemma real.Sup_smul_of_nonneg (ha : 0 \u2264 a) (s : set \u211d) : Sup (a \u2022 s) = a \u2022 Sup s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Sup_empty, smul_zero'] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cSup_singleton 0 },\n  by_cases bdd_above s,\n  { exact ((order_iso.smul_left \u211d ha').map_cSup' hs h).symm },\n  { rw [real.Sup_of_not_bdd_above (mt (bdd_above_smul_iff_of_pos ha').1 h),\n      real.Sup_of_not_bdd_above h, smul_zero'] }\nend\n\nlemma real.smul_supr_of_nonneg (ha : 0 \u2264 a) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a06 i, f i) = \u2a06 i, a \u2022 f i :=\n(real.Sup_smul_of_nonneg ha _).symm.trans $ congr_arg Sup $ (range_comp _ _).symm\n\nend mul_action_with_zero\n\nsection module\nvariables [module \u03b1 \u211d] [ordered_smul \u03b1 \u211d] {a : \u03b1}\n\nlemma real.Inf_smul_of_nonpos (ha : a \u2264 0) (s : set \u211d) : Inf (a \u2022 s) = a \u2022 Sup s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Inf_empty, real.Sup_empty, smul_zero'] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cInf_singleton 0 },\n  by_cases bdd_above s,\n  { exact ((order_iso.smul_left_dual \u211d ha').map_cSup' hs h).symm },\n  { rw [real.Inf_of_not_bdd_below (mt (bdd_below_smul_iff_of_neg ha').1 h),\n      real.Sup_of_not_bdd_above h, smul_zero'] }\nend\n\nlemma real.smul_supr_of_nonpos (ha : a \u2264 0) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a06 i, f i) = \u2a05 i, a \u2022 f i :=\n(real.Inf_smul_of_nonpos ha _).symm.trans $ congr_arg Inf $ (range_comp _ _).symm\n\nlemma real.Sup_smul_of_nonpos (ha : a \u2264 0) (s : set \u211d) : Sup (a \u2022 s) = a \u2022 Inf s :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { rw [smul_set_empty, real.Sup_empty, real.Inf_empty, smul_zero] },\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul_set hs, zero_smul],\n    exact cSup_singleton 0 },\n  by_cases bdd_below s,\n  { exact ((order_iso.smul_left_dual \u211d ha').map_cInf' hs h).symm },\n  { rw [real.Sup_of_not_bdd_above (mt (bdd_above_smul_iff_of_neg ha').1 h),\n      real.Inf_of_not_bdd_below h, smul_zero] }\nend\n\nlemma real.smul_infi_of_nonpos (ha : a \u2264 0) (f : \u03b9 \u2192 \u211d) :\n  a \u2022 (\u2a05 i, f i) = \u2a06 i, a \u2022 f i :=\n(real.Sup_smul_of_nonpos ha _).symm.trans $ congr_arg Sup $ (range_comp _ _).symm\n\nend module\n\n/-! ## Special cases for real multiplication -/\n\nsection mul\n\nvariables {r : \u211d}\n\nlemma real.mul_infi_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : r * (\u2a05 i, f i) = \u2a05 i, r * f i :=\nreal.smul_infi_of_nonneg ha f\n\nlemma real.mul_supr_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : r * (\u2a06 i, f i) = \u2a06 i, r * f i :=\nreal.smul_supr_of_nonneg ha f\n\nlemma real.mul_infi_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : r * (\u2a05 i, f i) = \u2a06 i, r * f i :=\nreal.smul_infi_of_nonpos ha f\n\nlemma real.mul_supr_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : r * (\u2a06 i, f i) = \u2a05 i, r * f i :=\nreal.smul_supr_of_nonpos ha f\n\nlemma real.infi_mul_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : (\u2a05 i, f i) * r = \u2a05 i, f i * r :=\nby simp only [real.mul_infi_of_nonneg ha, mul_comm]\n\nlemma real.supr_mul_of_nonneg (ha : 0 \u2264 r) (f : \u03b9 \u2192 \u211d) : (\u2a06 i, f i) * r = \u2a06 i, f i * r :=\nby simp only [real.mul_supr_of_nonneg ha, mul_comm]\n\nlemma real.infi_mul_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : (\u2a05 i, f i) * r = \u2a06 i, f i * r :=\nby simp only [real.mul_infi_of_nonpos ha, mul_comm]\n\nlemma real.supr_mul_of_nonpos (ha : r \u2264 0) (f : \u03b9 \u2192 \u211d) : (\u2a06 i, f i) * r = \u2a05 i, f i * r :=\nby simp only [real.mul_supr_of_nonpos ha, mul_comm]\n\nend mul\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/real/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7218540444246205}}
{"text": "import measure_theory.integration\nimport measure_theory.bochner_integration\nimport measure_theory.lebesgue_measure\nimport measure_theory.interval_integral\n\nopen measure_theory filter set\nopen_locale ennreal nnreal topological_space\n\nsection growing_family\n\nvariables {\u03b1 : Type*} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n\nstructure growing_family (\u03c6 : \u2115 \u2192 set \u03b1) : Prop :=\n(ae_eventually_mem : \u2200\u1d50 x \u2202\u03bc, \u2200\u1da0 n in at_top, x \u2208 \u03c6 n)\n(mono : monotone \u03c6)\n(measurable : \u2200 n, measurable_set $ \u03c6 n)\n\nvariables {\u03bc}\n\nsection Icc\n\nvariables [preorder \u03b1] [topological_space \u03b1] [order_closed_topology \u03b1] [opens_measurable_space \u03b1]\n  {a b : \u2115 \u2192 \u03b1} (ha\u2081 : \u2200 \u2983x y\u2984, x \u2264 y \u2192 a y \u2264 a x) (ha\u2082 : tendsto a at_top at_bot) \n  (hb\u2081 : monotone b) (hb\u2082 : tendsto b at_top at_top)\n\nlemma growing_family_Icc : growing_family \u03bc (\u03bb n, Icc (a n) (b n)) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_le_at_bot x).mp $ \n    (hb\u2082.eventually $ eventually_ge_at_top x).mono $\n    \u03bb n hbn han, \u27e8han, hbn\u27e9 ),\n  mono := \u03bb i j hij, Icc_subset_Icc (ha\u2081 hij) (hb\u2081 hij),\n  measurable := \u03bb n, measurable_set_Icc }\n\nend Icc\n\nsection Ixx\n\nvariables [linear_order \u03b1] [topological_space \u03b1] [order_closed_topology \u03b1] [opens_measurable_space \u03b1]\n  {a b : \u2115 \u2192 \u03b1} (ha\u2081 : \u2200 \u2983x y\u2984, x \u2264 y \u2192 a y \u2264 a x) (ha\u2082 : tendsto a at_top at_bot) \n  (hb\u2081 : monotone b) (hb\u2082 : tendsto b at_top at_top)\n\nlemma growing_family_Ioo [no_bot_order \u03b1] [no_top_order \u03b1] : \n  growing_family \u03bc (\u03bb n, Ioo (a n) (b n)) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_lt_at_bot x).mp $ \n    (hb\u2082.eventually $ eventually_gt_at_top x).mono $\n    \u03bb n hbn han, \u27e8han, hbn\u27e9 ),\n  mono := \u03bb i j hij, Ioo_subset_Ioo (ha\u2081 hij) (hb\u2081 hij),\n  measurable := \u03bb n, measurable_set_Ioo }\n\nlemma growing_family_Ioc [no_bot_order \u03b1] : growing_family \u03bc (\u03bb n, Ioc (a n) (b n)) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_lt_at_bot x).mp $ \n    (hb\u2082.eventually $ eventually_ge_at_top x).mono $\n    \u03bb n hbn han, \u27e8han, hbn\u27e9 ),\n  mono := \u03bb i j hij, Ioc_subset_Ioc (ha\u2081 hij) (hb\u2081 hij),\n  measurable := \u03bb n, measurable_set_Ioc }\n\nlemma growing_family_Ico [no_top_order \u03b1] : growing_family \u03bc (\u03bb n, Ico (a n) (b n)) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_le_at_bot x).mp $ \n    (hb\u2082.eventually $ eventually_gt_at_top x).mono $\n    \u03bb n hbn han, \u27e8han, hbn\u27e9 ),\n  mono := \u03bb i j hij, Ico_subset_Ico (ha\u2081 hij) (hb\u2081 hij),\n  measurable := \u03bb n, measurable_set_Ico }\n\nend Ixx\n\nsection Ixi_Iix\n\nlemma growing_family_Ici [preorder \u03b1] [topological_space \u03b1] [order_closed_topology \u03b1] \n  [opens_measurable_space \u03b1] {a : \u2115 \u2192 \u03b1} (ha\u2081 : \u2200 \u2983x y\u2984, x \u2264 y \u2192 a y \u2264 a x) \n  (ha\u2082 : tendsto a at_top at_bot) : \n  growing_family \u03bc (\u03bb n, Ici $ a n) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_le_at_bot x).mono $ \n    \u03bb n han, han ),\n  mono := \u03bb i j hij, Ici_subset_Ici.mpr (ha\u2081 hij),\n  measurable := \u03bb n, measurable_set_Ici }\n\nlemma growing_family_Ioi [linear_order \u03b1] [topological_space \u03b1] [order_closed_topology \u03b1] \n  [opens_measurable_space \u03b1] {a : \u2115 \u2192 \u03b1} (ha\u2081 : \u2200 \u2983x y\u2984, x \u2264 y \u2192 a y \u2264 a x) \n  (ha\u2082 : tendsto a at_top at_bot) [no_bot_order \u03b1] : \n  growing_family \u03bc (\u03bb n, Ioi $ a n) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_lt_at_bot x).mono $ \n    \u03bb n han, han ),\n  mono := \u03bb i j hij, Ioi_subset_Ioi (ha\u2081 hij),\n  measurable := \u03bb n, measurable_set_Ioi }\n\nlemma growing_family_Iic [preorder \u03b1] [topological_space \u03b1] [order_closed_topology \u03b1] \n  [opens_measurable_space \u03b1] {a : \u2115 \u2192 \u03b1} (ha\u2081 : monotone a) \n  (ha\u2082 : tendsto a at_top at_top) : \n  growing_family \u03bc (\u03bb n, Iic $ a n) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_ge_at_top x).mono $ \n    \u03bb n han, han ),\n  mono := \u03bb i j hij, Iic_subset_Iic.mpr (ha\u2081 hij),\n  measurable := \u03bb n, measurable_set_Iic }\n\nlemma growing_family_Iio [linear_order \u03b1] [topological_space \u03b1] [order_closed_topology \u03b1] \n  [opens_measurable_space \u03b1] {a : \u2115 \u2192 \u03b1} (ha\u2081 : monotone a) \n  (ha\u2082 : tendsto a at_top at_top) [no_top_order \u03b1] : \n  growing_family \u03bc (\u03bb n, Iio $ a n) :=\n{ ae_eventually_mem := ae_of_all \u03bc (\u03bb x, \n    (ha\u2082.eventually $ eventually_gt_at_top x).mono $ \n    \u03bb n han, han ),\n  mono := \u03bb i j hij, Iio_subset_Iio (ha\u2081 hij),\n  measurable := \u03bb n, measurable_set_Iio }\n\nend Ixi_Iix\n\nlemma growing_family.ae_tendsto_indicator {\u03b2 : Type*} [has_zero \u03b2] [topological_space \u03b2] \n  {f : \u03b1 \u2192 \u03b2} {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : growing_family \u03bc \u03c6) : \n  \u2200\u1d50 x \u2202\u03bc, tendsto (\u03bb n, (\u03c6 n).indicator f x) at_top (\ud835\udcdd $ f x) :=\nh\u03c6.ae_eventually_mem.mono (\u03bb x hx, tendsto_const_nhds.congr' $\n  hx.mono $ \u03bb n hn, (indicator_of_mem hn _).symm)\n\nlemma growing_family_restrict_of_ae_imp {s : set \u03b1} {\u03c6 : \u2115 \u2192 set \u03b1} \n  (hs : measurable_set s) (ae_eventually_mem : \u2200\u1d50 x \u2202\u03bc, x \u2208 s \u2192 \u2200\u1da0 n in at_top, x \u2208 \u03c6 n)\n  (mono : monotone \u03c6) (measurable : \u2200 n, measurable_set $ \u03c6 n) :\n  growing_family (\u03bc.restrict s) \u03c6 :=\n{ ae_eventually_mem := by rwa ae_restrict_iff' hs,\n  mono := mono,\n  measurable := measurable }\n\nlemma growing_family.inter_restrict {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : growing_family \u03bc \u03c6) \n  {s : set \u03b1} (hs : measurable_set s) :\n  growing_family (\u03bc.restrict s) (\u03bb n, \u03c6 n \u2229 s) :=\ngrowing_family_restrict_of_ae_imp hs \n  (h\u03c6.ae_eventually_mem.mono (\u03bb x hx hxs, hx.mono $ \u03bb n hn, \u27e8hn, hxs\u27e9))\n  (\u03bb i j hij, inter_subset_inter_left s (h\u03c6.mono hij))\n  (\u03bb n, (h\u03c6.measurable n).inter hs)\n\nend growing_family\n\nsection integral_limits\n\nvariables {\u03b1 : Type*} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n\nlemma lintegral_eq_supr {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 \u211d\u22650\u221e}\n  (hfm : measurable f) :\n  \u222b\u207b x, f x \u2202\u03bc = \u2a06 (n : \u2115), \u222b\u207b x in \u03c6 n, f x \u2202\u03bc :=\nbegin\n  let F := \u03bb n, indicator (\u03c6 n) f, \n  have F_tendsto : \u2200\u1d50 x \u2202\u03bc, tendsto (\u03bb n, F n x) at_top (\ud835\udcdd $ f x) :=\n    h\u03c6.ae_tendsto_indicator,\n  have F_mono : \u2200 x, monotone (\u03bb n, F n x) :=\n    \u03bb x i j hij, indicator_le_indicator_of_subset (h\u03c6.mono hij) (\u03bb _, zero_le _) x,\n  have f_eq_supr_F : \u2200\u1d50 x \u2202\u03bc, f x = \u2a06 (n : \u2115), F n x :=\n    F_tendsto.mono (\u03bb x hx, tendsto_nhds_unique hx \n      (tendsto_at_top_csupr (F_mono x) \u27e8\u22a4, \u03bb _ _, le_top\u27e9)),\n  have lintegral_F_eq : \u2200 n, \u222b\u207b (x : \u03b1), F n x \u2202\u03bc = \u222b\u207b x in \u03c6 n, f x \u2202\u03bc :=\n    \u03bb n, lintegral_indicator _ (h\u03c6.measurable n),\n  rw lintegral_congr_ae f_eq_supr_F,\n  conv_rhs {congr, funext, rw \u2190 lintegral_F_eq},\n  exact lintegral_supr (\u03bb n, hfm.indicator $ h\u03c6.measurable n) (\u03bb i j hij x, F_mono x hij)\nend\n\nlemma tendsto_set_lintegral_of_monotone_set {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : monotone \u03c6) {f : \u03b1 \u2192 \u211d\u22650\u221e} :\n  tendsto (\u03bb n, \u222b\u207b x in \u03c6 n, f x \u2202\u03bc) at_top (\ud835\udcdd $ \u2a06 (n : \u2115), \u222b\u207b x in \u03c6 n, f x \u2202\u03bc) :=\ntendsto_at_top_csupr \n  (\u03bb i j hij, lintegral_mono' (measure.restrict_mono (h\u03c6 hij) (le_refl _)) (le_refl _)) \n  \u27e8\u22a4, \u03bb _ _, le_top\u27e9\n\nlemma lintegral_eq_of_tendsto_lintegral {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 \u211d\u22650\u221e} (I : \u211d\u22650\u221e) \n  (hfm : measurable f) (h : tendsto (\u03bb n, \u222b\u207b x in \u03c6 n, f x \u2202\u03bc) at_top (\ud835\udcdd I)) :\n  \u222b\u207b x, f x \u2202\u03bc = I :=\nbegin\n  convert lintegral_eq_supr h\u03c6 hfm,\n  refine tendsto_nhds_unique h (tendsto_set_lintegral_of_monotone_set h\u03c6.mono)\nend\n\nlemma eventually_ne_of_tendsto_nhds {\u03b2 : Type*} [topological_space \u03b2] [t1_space \u03b2] {f : \u03b1 \u2192 \u03b2} {b b' : \u03b2}\n  (hbb' : b \u2260 b') {l : filter \u03b1} (hf : tendsto f l (\ud835\udcdd b)) : \u2200\u1da0 x in l, f x \u2260 b' :=\nhf (compl_singleton_mem_nhds hbb')\n\nlemma eventually_le_of_tendsto_of_tendsto_of_lt {\u03b2 : Type*} [linear_order \u03b2] [topological_space \u03b2] \n  [order_topology \u03b2] {f g : \u03b1 \u2192 \u03b2} {b b' : \u03b2} (hbb' : b < b') {l : filter \u03b1} \n  (hf : tendsto f l (\ud835\udcdd b)) (hg : tendsto g l (\ud835\udcdd b')) : \n  f \u2264\u1da0[l] g :=\nbegin\n  rcases order_separated hbb' with \u27e8u, v, hu, hv, hub, hvb', huv\u27e9,\n  have hfu : f \u207b\u00b9' u \u2208 l := hf (mem_nhds_sets hu hub),\n  have hgv : g \u207b\u00b9' v \u2208 l := hg (mem_nhds_sets hv hvb'),\n  exact eventually_of_mem (inter_mem_sets hfu hgv) (\u03bb x \u27e8hxu, hxv\u27e9, (huv _ hxu _ hxv).le),\nend\n\nlemma le_of_tendsto_of_monotone {\u03b2 : Type*} [preorder \u03b1] [linear_order \u03b2] [topological_space \u03b2] \n  [order_closed_topology \u03b2] {f : \u2115 \u2192 \u03b2} {b : \u03b2} (hmono : monotone f) \n  (hf : tendsto f at_top (\ud835\udcdd b)) : \n  \u2200 x, f x \u2264 b :=\n\u03bb x, ge_of_tendsto hf ((eventually_ge_at_top x).mono $ \u03bb _ h, hmono h)\n\nlemma ge_of_tendsto_of_antimono {\u03b2 : Type*} [preorder \u03b1] [linear_order \u03b2] [topological_space \u03b2] \n  [order_closed_topology \u03b2] {f : \u2115 \u2192 \u03b2} {b : \u03b2} (hanti : \u2200 \u2983x y\u2984, x \u2264 y \u2192 f y \u2264 f x) \n  (hf : tendsto f at_top (\ud835\udcdd b)) : \n  \u2200 x, b \u2264 f x :=\n\u03bb x, le_of_tendsto hf ((eventually_ge_at_top x).mono $ \u03bb _ h, hanti h)\n\nvariables {E : Type*} [normed_group E] [topological_space.second_countable_topology E] [normed_space \u211d E] \n  [complete_space E] [measurable_space E] [borel_space E]\n\nlemma integrable_of_tendsto_lintegral_nnnorm {\u03c6 : \u2115 \u2192 set \u03b1} \n  (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 E} (I : \u211d) (hfm : measurable f) \n  (h : tendsto (\u03bb n, \u222b\u207b x in \u03c6 n, nnnorm (f x) \u2202\u03bc) at_top (\ud835\udcdd $ ennreal.of_real I)) :\n  integrable f \u03bc :=\nbegin\n  refine \u27e8hfm.ae_measurable, _\u27e9,\n  unfold has_finite_integral,\n  rw lintegral_eq_of_tendsto_lintegral h\u03c6 _ \n    (measurable_ennreal_coe_iff.mpr (measurable_nnnorm.comp hfm)) h,\n  exact ennreal.of_real_lt_top\nend\n\nlemma integrable_of_tendsto_lintegral_nnnorm' {\u03c6 : \u2115 \u2192 set \u03b1} \n  (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 E} (I : \u211d\u22650) (hfm : measurable f) \n  (h : tendsto (\u03bb n, \u222b\u207b x in \u03c6 n, nnnorm (f x) \u2202\u03bc) at_top (\ud835\udcdd I)) :\n  integrable f \u03bc :=\nbegin\n  refine integrable_of_tendsto_lintegral_nnnorm h\u03c6 (I : \u211d) hfm _,\n  convert h,\n  exact ennreal.of_real_coe_nnreal\nend\n\nlemma integrable_of_tendsto_integral_norm {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 E} (I : \u211d) (hfm : measurable f) \n  (hfi : \u2200 n, integrable_on f (\u03c6 n) \u03bc) \n  (h : tendsto (\u03bb n, \u222b x in \u03c6 n, \u2225f x\u2225 \u2202\u03bc) at_top (\ud835\udcdd I)) :\n  integrable f \u03bc :=\nbegin\n  conv at h in (integral _ _) \n  { rw integral_eq_lintegral_of_nonneg_ae (ae_of_all _ (\u03bb x, @norm_nonneg E _ (f x))) \n    hfm.norm.ae_measurable },\n  conv at h in (ennreal.of_real _) { dsimp, rw \u2190 coe_nnnorm, rw ennreal.of_real_coe_nnreal },\n  have h' : tendsto (\u03bb (n : \u2115), (\u222b\u207b (a : \u03b1) in \u03c6 n, nnnorm (f a) \u2202\u03bc)) at_top (\ud835\udcdd $ ennreal.of_real I),\n  { convert ennreal.tendsto_of_real h,\n    ext n : 1,\n    rw ennreal.of_real_to_real _, \n    exact ne_top_of_lt (hfi n).2 },\n  exact integrable_of_tendsto_lintegral_nnnorm h\u03c6 I hfm h'\nend\n\nlemma integrable_of_tendsto_integral_of_nonneg_ae {\u03c6 : \u2115 \u2192 set \u03b1} \n  (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 \u211d} (I : \u211d) (hf : 0 \u2264\u1d50[\u03bc] f) (hfm : measurable f) (hfi : \u2200 n, integrable_on f (\u03c6 n) \u03bc) \n  (h : tendsto (\u03bb n, \u222b x in \u03c6 n, f x \u2202\u03bc) at_top (\ud835\udcdd I)) : integrable f \u03bc :=\nintegrable_of_tendsto_integral_norm h\u03c6 I hfm hfi \n  (h.congr $ \u03bb n, integral_congr_ae $ ae_restrict_of_ae $ hf.mono $ \n    \u03bb x hx, (real.norm_of_nonneg hx).symm)\n\nlemma integral_eq_supr_max_sub_supr_min {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 \u211d}\n  (hfm : measurable f) (hfi : integrable f \u03bc) :\n  \u222b x, f x \u2202\u03bc = (\u2a06 (n : \u2115), \u222b\u207b x in \u03c6 n, ennreal.of_real (max (f x) 0) \u2202\u03bc).to_real - \n    (\u2a06 (n : \u2115), \u222b\u207b x in \u03c6 n, ennreal.of_real (- min (f x) 0) \u2202\u03bc).to_real :=\nbegin\n  rw [integral_eq_lintegral_max_sub_lintegral_min hfi, \n      lintegral_eq_supr h\u03c6 _, lintegral_eq_supr h\u03c6 _],\n  { exact ennreal.measurable_of_real.comp (measurable_neg.comp $ hfm.min measurable_zero) },\n  { exact ennreal.measurable_of_real.comp (hfm.max measurable_zero) }\nend\n\nlemma integral_eq_of_tendsto_integral {\u03c6 : \u2115 \u2192 set \u03b1} (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 E} (I : E)\n  (hfm : measurable f) (hfi : integrable f \u03bc) \n  (h : tendsto (\u03bb n, \u222b x in \u03c6 n, f x \u2202\u03bc) at_top (\ud835\udcdd I)) :\n  \u222b x, f x \u2202\u03bc = I :=\nbegin\n  refine tendsto_nhds_unique _ h,\n  suffices : tendsto (\u03bb (n : \u2115), \u222b (x : \u03b1), (\u03c6 n).indicator f x \u2202\u03bc) at_top (\ud835\udcdd (\u222b (x : \u03b1), f x \u2202\u03bc)),\n  { convert this,\n    ext n,\n    rw integral_indicator (h\u03c6.measurable n) },\n  exact tendsto_integral_of_dominated_convergence (\u03bb x, \u2225f x\u2225) \n    (\u03bb n, (hfm.indicator $ h\u03c6.measurable n).ae_measurable) hfm.ae_measurable hfi.norm \n    (\u03bb n, ae_of_all _ $ norm_indicator_le_norm_self f) h\u03c6.ae_tendsto_indicator\nend\n\nlemma integral_eq_of_tendsto_integral_of_nonneg_ae {\u03c6 : \u2115 \u2192 set \u03b1} \n  (h\u03c6 : growing_family \u03bc \u03c6) {f : \u03b1 \u2192 \u211d} (I : \u211d) (hf : 0 \u2264\u1d50[\u03bc] f) (hfm : measurable f) (hfi : \u2200 n, integrable_on f (\u03c6 n) \u03bc) \n  (h : tendsto (\u03bb n, \u222b x in \u03c6 n, f x \u2202\u03bc) at_top (\ud835\udcdd I)) :\n  \u222b x, f x \u2202\u03bc = I :=\nhave hfi' : integrable f \u03bc,\n  from integrable_of_tendsto_integral_of_nonneg_ae h\u03c6 I hf hfm hfi h,\nintegral_eq_of_tendsto_integral h\u03c6 I hfm hfi' h\n\nend integral_limits\n\nsection interval_integral\n\nvariables {\u03b1 : Type*} {E : Type*} [topological_space \u03b1] [linear_order \u03b1] [order_closed_topology \u03b1]\n  [measurable_space \u03b1] [no_bot_order \u03b1] [opens_measurable_space \u03b1] [measurable_space E] \n  [normed_group E] [topological_space.second_countable_topology E] [complete_space E] \n  [normed_space \u211d E] [borel_space E] {\u03bc : measure \u03b1} {a b : \u2115 \u2192 \u03b1} \n  (ha\u2081 : \u2200 \u2983x y\u2984, x \u2264 y \u2192 a y \u2264 a x) (hb\u2081 : monotone b) {f : \u03b1 \u2192 E} (hfm : measurable f)\n\ninclude ha\u2081 hb\u2081\n\nlemma monotone_ite_le_interval :\n  monotone (\u03bb n, if a n \u2264 b n then Ioc (a n) (b n) else \u2205) :=\nbegin\n  intros i j hij,\n  by_cases hi : a i \u2264 b i,\n  { have hj : a j \u2264 b j := (ha\u2081 hij).trans (hi.trans (hb\u2081 hij)),\n    simp [hi, hj, Ioc_subset_Ioc (ha\u2081 hij) (hb\u2081 hij)] },\n  { by_cases hj : a j \u2264 b j;\n    simp[hi, hj] }\nend\n\ninclude hfm\n\n-- TODO : unduplicate proofs\n\nlemma integral_eq_of_tendsto_interval_integral (I : E)\n  (hfi : integrable f \u03bc) (ha\u2082 : tendsto a at_top at_bot) (hb\u2082 : tendsto b at_top at_top) \n  (h : tendsto (\u03bb n, \u222b x in a n .. b n, f x \u2202\u03bc) at_top (\ud835\udcdd $ I)) :\n  \u222b x, f x \u2202\u03bc = I :=\nbegin\n  let \u03c6 := \u03bb n, Ioc (a n) (b n),\n  have h\u03c6 : growing_family \u03bc \u03c6 := growing_family_Ioc ha\u2081 ha\u2082 hb\u2081 hb\u2082,\n  refine integral_eq_of_tendsto_integral h\u03c6 _ hfm hfi (h.congr' _),\n  filter_upwards [ha\u2082.eventually (eventually_le_at_bot $ b 0)],\n  intros n han, \n  have : a n \u2264 b n := han.trans (hb\u2081 $ zero_le n),\n  exact interval_integral.integral_of_le this\nend\n\nlemma integrable_of_tendsto_interval_integral_norm (I : \u211d)\n  (hfi : \u2200 n, integrable_on f (Ioc (a n) (b n)) \u03bc)\n  (ha\u2082 : tendsto a at_top at_bot) (hb\u2082 : tendsto b at_top at_top) \n  (h : tendsto (\u03bb n, \u222b x in a n .. b n, \u2225f x\u2225 \u2202\u03bc) at_top (\ud835\udcdd $ I)) :\n  integrable f \u03bc :=\nbegin\n  let \u03c6 := \u03bb n, Ioc (a n) (b n),\n  have h\u03c6 : growing_family \u03bc \u03c6 := growing_family_Ioc ha\u2081 ha\u2082 hb\u2081 hb\u2082,\n  refine integrable_of_tendsto_integral_norm h\u03c6 _ hfm hfi (h.congr' _),\n  filter_upwards [ha\u2082.eventually (eventually_le_at_bot $ b 0)],\n  intros n han, \n  have : a n \u2264 b n := han.trans (hb\u2081 $ zero_le n),\n  exact interval_integral.integral_of_le this\nend\n\nomit hb\u2081\n\nlemma integral_Iic_eq_of_tendsto_interval_integral (I : E) (b : \u03b1)\n  (hfi : integrable_on f (Iic b) \u03bc) (ha\u2082 : tendsto a at_top at_bot) \n  (h : tendsto (\u03bb n, \u222b x in a n .. b, f x \u2202\u03bc) at_top (\ud835\udcdd $ I)) :\n  \u222b x in Iic b, f x \u2202\u03bc = I :=\nbegin\n  let \u03c6 := \u03bb n, Ioi (a n),\n  have h\u03c6 : growing_family (\u03bc.restrict $ Iic b) \u03c6 := growing_family_Ioi ha\u2081 ha\u2082,\n  refine integral_eq_of_tendsto_integral h\u03c6 _ hfm hfi (h.congr' _),\n  filter_upwards [ha\u2082.eventually (eventually_le_at_bot $ b)],\n  intros n han, \n  rw [interval_integral.integral_of_le han, measure.restrict_restrict (h\u03c6.measurable n)],\n  refl\nend\n\nlemma integrable_on_Iic_of_tendsto_interval_integral_norm (I : \u211d) (b : \u03b1)\n  (hfi : \u2200 n, integrable_on f (Ioc (a n) b) \u03bc) (ha\u2082 : tendsto a at_top at_bot) \n  (h : tendsto (\u03bb n, \u222b x in a n .. b, \u2225f x\u2225 \u2202\u03bc) at_top (\ud835\udcdd $ I)) :\n  integrable_on f (Iic b) \u03bc :=\nbegin\n  let \u03c6 := \u03bb n, Ioi (a n),\n  have h\u03c6 : growing_family (\u03bc.restrict $ Iic b) \u03c6 := growing_family_Ioi ha\u2081 ha\u2082,\n  have hfi : \u2200 n, integrable_on f (\u03c6 n) (\u03bc.restrict $ Iic b),\n  { intro n, \n    rw [integrable_on, measure.restrict_restrict (h\u03c6.measurable n)],\n    exact hfi n },\n  refine integrable_of_tendsto_integral_norm h\u03c6 _ hfm hfi (h.congr' _),\n  filter_upwards [ha\u2082.eventually (eventually_le_at_bot $ b)],\n  intros n han, \n  rw [interval_integral.integral_of_le han, measure.restrict_restrict (h\u03c6.measurable n)],\n  refl\nend\n\nomit ha\u2081\ninclude hb\u2081\n\nlemma integral_Ioi_eq_of_tendsto_interval_integral (I : E) (a : \u03b1)\n  (hfi : integrable_on f (Ioi a) \u03bc) (hb\u2082 : tendsto b at_top at_top) \n  (h : tendsto (\u03bb n, \u222b x in a .. b n, f x \u2202\u03bc) at_top (\ud835\udcdd $ I)) :\n  \u222b x in Ioi a, f x \u2202\u03bc = I :=\nbegin\n  let \u03c6 := \u03bb n, Iic (b n),\n  have h\u03c6 : growing_family (\u03bc.restrict $ Ioi a) \u03c6 := growing_family_Iic hb\u2081 hb\u2082,\n  refine integral_eq_of_tendsto_integral h\u03c6 _ hfm hfi (h.congr' _),\n  filter_upwards [hb\u2082.eventually (eventually_ge_at_top $ a)],\n  intros n hbn, \n  rw [interval_integral.integral_of_le hbn, measure.restrict_restrict (h\u03c6.measurable n), \n      inter_comm],\n  refl\nend\n\nlemma integrable_on_Ioi_of_tendsto_interval_integral_norm (I : \u211d) (a : \u03b1)\n  (hfi : \u2200 n, integrable_on f (Ioc a (b n)) \u03bc) (hb\u2082 : tendsto b at_top at_top) \n  (h : tendsto (\u03bb n, \u222b x in a .. b n, \u2225f x\u2225 \u2202\u03bc) at_top (\ud835\udcdd $ I)) :\n  integrable_on f (Ioi a) \u03bc :=\nbegin\n  let \u03c6 := \u03bb n, Iic (b n),\n  have h\u03c6 : growing_family (\u03bc.restrict $ Ioi a) \u03c6 := growing_family_Iic hb\u2081 hb\u2082,\n  have hfi : \u2200 n, integrable_on f (\u03c6 n) (\u03bc.restrict $ Ioi a),\n  { intro n, \n    rw [integrable_on, measure.restrict_restrict (h\u03c6.measurable n), inter_comm],\n    exact hfi n },\n  refine integrable_of_tendsto_integral_norm h\u03c6 _ hfm hfi (h.congr' _),\n  filter_upwards [hb\u2082.eventually (eventually_ge_at_top $ a)],\n  intros n hbn, \n  rw [interval_integral.integral_of_le hbn, measure.restrict_restrict (h\u03c6.measurable n), \n      inter_comm],\n  refl\nend\n\n--lemma interval_integral_eq_of_tendsto_interval_integral [order_topology \u03b1] \n--  [has_no_atoms \u03bc] {la lb : \u03b1} (hl : la < lb)\n--  (hfi : interval_integrable f \u03bc la lb) (ha\u2082 : tendsto a at_top (\ud835\udcdd la)) \n--  (hb\u2082 : tendsto b at_top (\ud835\udcdd lb)) \n--  (h : tendsto (\u03bb n, \u222b x in a n .. b n, f x \u2202\u03bc) at_top (\ud835\udcdd $ I)) :\n--  \u222b x in la..lb, f x \u2202\u03bc = I :=\n--begin\n--  let \u03c6 := \u03bb n, if a n \u2264 b n then Ioc (a n) (b n) else \u2205,\n--  have h\u03c6 : growing_family (\u03bc.restrict $ Ioc la lb) \u03c6 :=\n--    growing_family_restrict_of_ae_imp measurable_set_Ioc\n--      (\n--        begin\n--          refine Ioo_ae_eq_Ioc.mono (\u03bb x (heq : (x \u2208 Ioo la lb) = (x \u2208 Ioc la lb)) hx, _),\n--          have hx : x \u2208 Ioo la lb := heq.symm \u25b8 hx,\n--          refine (eventually_le_of_tendsto_lt hx.1 ha\u2082).mp _,\n--          refine (eventually_ge_of_tendsto_gt hx.2 hb\u2082).mono _,\n--          intros n hbx hax,\n--          dsimp only [\u03c6],\n--          split_ifs,\n--        end\n--      )\n--      (monotone_ite_le_interval ha\u2081 hb\u2081)\n--      _,\n--  rw interval_integral.integral_of_le hl.le,\n--  refine integral_eq_of_tendsto_integral h\u03c6 _ hfm hfi.1 (h.congr' _),\n--  filter_upwards [eventually_le_of_tendsto_of_tendsto_of_lt hl ha\u2082 hb\u2082],\n--  intros n han, \n--  have h\u03c6\u2082 : \u03c6 n = Ioc (a n) (b n),\n--  { dsimp only [\u03c6],\n--    split_ifs,\n--    refl }, \n--  have ha\u2083 := ge_of_tendsto_of_antimono ha\u2081 ha\u2082 n,\n--  have hb\u2083 := le_of_tendsto_of_monotone hb\u2081 hb\u2082 n,\n--  have : \u03c6 n \u2286 Ioc la lb := h\u03c6\u2082.symm \u25b8 Ioc_subset_Ioc ha\u2083 hb\u2083,\n--  rw [measure.restrict_restrict, inter_eq_self_of_subset_left this, h\u03c6\u2082],\n--  exact interval_integral.integral_of_le han,\n--end\n\nend interval_integral", "meta": {"author": "ADedecker", "repo": "gauss", "sha": "d44d482d49d4755b1d238f3e8a67d22a605970a9", "save_path": "github-repos/lean/ADedecker-gauss", "path": "github-repos/lean/ADedecker-gauss/gauss-d44d482d49d4755b1d238f3e8a67d22a605970a9/src/integral_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7218540366279662}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Junyan Xu\n-/\nimport analysis.complex.liouville\nimport field_theory.is_alg_closed.basic\n\n/-!\n# The fundamental theorem of algebra\n\nThis file proves that every nonconstant complex polynomial has a root using Liouville's theorem.\n\nAs a consequence, the complex numbers are algebraically closed.\n-/\n\nopen polynomial\nopen_locale polynomial\n\nnamespace complex\n\n/-- **Fundamental theorem of algebra**: every non constant complex polynomial\n  has a root -/\nlemma exists_root {f : \u2102[X]} (hf : 0 < degree f) : \u2203 z : \u2102, is_root f z :=\nbegin\n  contrapose! hf,\n  obtain \u27e8c, hc\u27e9 := (f.differentiable.inv hf).exists_const_forall_eq_of_bounded _,\n  { obtain rfl : f = C c\u207b\u00b9 := polynomial.funext (\u03bb z, by rw [eval_C, \u2190 hc z, inv_inv]),\n    exact degree_C_le },\n  { obtain \u27e8z\u2080, h\u2080\u27e9 := f.exists_forall_norm_le,\n    simp only [bounded_iff_forall_norm_le, set.forall_range_iff, norm_inv],\n    exact \u27e8\u2016eval z\u2080 f\u2016\u207b\u00b9, \u03bb z, inv_le_inv_of_le (norm_pos_iff.2 $ hf z\u2080) (h\u2080 z)\u27e9 },\nend\n\ninstance is_alg_closed : is_alg_closed \u2102 :=\nis_alg_closed.of_exists_root _ $ \u03bb p _ hp, complex.exists_root $ degree_pos_of_irreducible hp\n\nend complex\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/complex/polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7218540361665485}}
{"text": "/-\nCopyright (c) 2021 Andrew Yang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Andrew Yang\n\n! This file was ported from Lean 3 source module topology.sober\n! leanprover-community/mathlib commit 0a0ec35061ed9960bf0e7ffb0335f44447b58977\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.Separation\n\n/-!\n# Sober spaces\n\nA quasi-sober space is a topological space where every\nirreducible closed subset has a generic point.\nA sober space is a quasi-sober space where every irreducible closed subset\nhas a *unique* generic point. This is if and only if the space is T0, and thus sober spaces can be\nstated via `[QuasiSober \u03b1] [T0Space \u03b1]`.\n\n## Main definition\n\n* `IsGenericPoint` : `x` is the generic point of `S` if `S` is the closure of `x`.\n* `QuasiSober` : A space is quasi-sober if every irreducible closed subset has a generic point.\n\n-/\n\n\nopen Set\n\nvariable {\u03b1 \u03b2 : Type _} [TopologicalSpace \u03b1] [TopologicalSpace \u03b2]\n\nsection genericPoint\n\n/-- `x` is a generic point of `S` if `S` is the closure of `x`. -/\ndef IsGenericPoint (x : \u03b1) (S : Set \u03b1) : Prop :=\n  closure ({x} : Set \u03b1) = S\n#align is_generic_point IsGenericPoint\n\ntheorem isGenericPoint_def {x : \u03b1} {S : Set \u03b1} : IsGenericPoint x S \u2194 closure ({x} : Set \u03b1) = S :=\n  Iff.rfl\n#align is_generic_point_def isGenericPoint_def\n\ntheorem IsGenericPoint.def {x : \u03b1} {S : Set \u03b1} (h : IsGenericPoint x S) :\n    closure ({x} : Set \u03b1) = S :=\n  h\n#align is_generic_point.def IsGenericPoint.def\n\ntheorem isGenericPoint_closure {x : \u03b1} : IsGenericPoint x (closure ({x} : Set \u03b1)) :=\n  refl _\n#align is_generic_point_closure isGenericPoint_closure\n\nvariable {x y : \u03b1} {S U Z : Set \u03b1}\n\ntheorem isGenericPoint_iff_specializes : IsGenericPoint x S \u2194 \u2200 y, x \u2933 y \u2194 y \u2208 S := by\n  simp only [specializes_iff_mem_closure, IsGenericPoint, Set.ext_iff]\n#align is_generic_point_iff_specializes isGenericPoint_iff_specializes\n\nnamespace IsGenericPoint\n\ntheorem specializes_iff_mem (h : IsGenericPoint x S) : x \u2933 y \u2194 y \u2208 S :=\n  isGenericPoint_iff_specializes.1 h y\n#align is_generic_point.specializes_iff_mem IsGenericPoint.specializes_iff_mem\n\nprotected theorem specializes (h : IsGenericPoint x S) (h' : y \u2208 S) : x \u2933 y :=\n  h.specializes_iff_mem.2 h'\n#align is_generic_point.specializes IsGenericPoint.specializes\n\nprotected theorem mem (h : IsGenericPoint x S) : x \u2208 S :=\n  h.specializes_iff_mem.1 specializes_rfl\n#align is_generic_point.mem IsGenericPoint.mem\n\nprotected theorem isClosed (h : IsGenericPoint x S) : IsClosed S :=\n  h.def \u25b8 isClosed_closure\n#align is_generic_point.is_closed IsGenericPoint.isClosed\n\nprotected theorem isIrreducible (h : IsGenericPoint x S) : IsIrreducible S :=\n  h.def \u25b8 isIrreducible_singleton.closure\n#align is_generic_point.is_irreducible IsGenericPoint.isIrreducible\n\nprotected theorem inseparable (h : IsGenericPoint x S) (h' : IsGenericPoint y S) :\n    Inseparable x y :=\n  (h.specializes h'.mem).antisymm (h'.specializes h.mem)\n\n/-- In a T\u2080 space, each set has at most one generic point. -/\nprotected theorem eq [T0Space \u03b1] (h : IsGenericPoint x S) (h' : IsGenericPoint y S) : x = y :=\n  (h.inseparable h').eq\n#align is_generic_point.eq IsGenericPoint.eq\n\ntheorem mem_open_set_iff (h : IsGenericPoint x S) (hU : IsOpen U) : x \u2208 U \u2194 (S \u2229 U).Nonempty :=\n  \u27e8fun h' => \u27e8x, h.mem, h'\u27e9, fun \u27e8_y, hyS, hyU\u27e9 => (h.specializes hyS).mem_open hU hyU\u27e9\n#align is_generic_point.mem_open_set_iff IsGenericPoint.mem_open_set_iff\n\n\n\ntheorem mem_closed_set_iff (h : IsGenericPoint x S) (hZ : IsClosed Z) : x \u2208 Z \u2194 S \u2286 Z := by\n  rw [\u2190 h.def, hZ.closure_subset_iff, singleton_subset_iff]\n#align is_generic_point.mem_closed_set_iff IsGenericPoint.mem_closed_set_iff\n\nprotected theorem image (h : IsGenericPoint x S) {f : \u03b1 \u2192 \u03b2} (hf : Continuous f) :\n    IsGenericPoint (f x) (closure (f '' S)) := by\n  rw [isGenericPoint_def, \u2190 h.def, \u2190 image_singleton, closure_image_closure hf]\n#align is_generic_point.image IsGenericPoint.image\n\nend IsGenericPoint\n\ntheorem isGenericPoint_iff_forall_closed (hS : IsClosed S) (hxS : x \u2208 S) :\n    IsGenericPoint x S \u2194 \u2200 Z : Set \u03b1, IsClosed Z \u2192 x \u2208 Z \u2192 S \u2286 Z := by\n  have : closure {x} \u2286 S := closure_minimal (singleton_subset_iff.2 hxS) hS\n  simp_rw [IsGenericPoint, subset_antisymm_iff, this, true_and_iff, closure, subset_inter\u209b_iff,\n    mem_setOf_eq, and_imp, singleton_subset_iff]\n#align is_generic_point_iff_forall_closed isGenericPoint_iff_forall_closed\n\nend genericPoint\n\nsection Sober\n\n/-- A space is sober if every irreducible closed subset has a generic point. -/\n@[mk_iff quasiSober_iff]\nclass QuasiSober (\u03b1 : Type _) [TopologicalSpace \u03b1] : Prop where\n  sober : \u2200 {S : Set \u03b1}, IsIrreducible S \u2192 IsClosed S \u2192 \u2203 x, IsGenericPoint x S\n#align quasi_sober QuasiSober\n\n/-- A generic point of the closure of an irreducible space. -/\nnoncomputable def IsIrreducible.genericPoint [QuasiSober \u03b1] {S : Set \u03b1} (hS : IsIrreducible S) :\n    \u03b1 :=\n  (QuasiSober.sober hS.closure isClosed_closure).choose\n#align is_irreducible.generic_point IsIrreducible.genericPoint\n\ntheorem IsIrreducible.genericPoint_spec [QuasiSober \u03b1] {S : Set \u03b1} (hS : IsIrreducible S) :\n    IsGenericPoint hS.genericPoint (closure S) :=\n  (QuasiSober.sober hS.closure isClosed_closure).choose_spec\n#align is_irreducible.generic_point_spec IsIrreducible.genericPoint_spec\n\n@[simp]\ntheorem IsIrreducible.genericPoint_closure_eq [QuasiSober \u03b1] {S : Set \u03b1} (hS : IsIrreducible S) :\n    closure ({hS.genericPoint} : Set \u03b1) = closure S :=\n  hS.genericPoint_spec\n#align is_irreducible.generic_point_closure_eq IsIrreducible.genericPoint_closure_eq\n\nvariable (\u03b1)\n\n/-- A generic point of a sober irreducible space. -/\nnoncomputable def genericPoint [QuasiSober \u03b1] [IrreducibleSpace \u03b1] : \u03b1 :=\n  (IrreducibleSpace.isIrreducible_univ \u03b1).genericPoint\n#align generic_point genericPoint\n\ntheorem genericPoint_spec [QuasiSober \u03b1] [IrreducibleSpace \u03b1] : IsGenericPoint (genericPoint \u03b1) \u22a4 :=\n  by simpa using (IrreducibleSpace.isIrreducible_univ \u03b1).genericPoint_spec\n#align generic_point_spec genericPoint_spec\n\n@[simp]\ntheorem genericPoint_closure [QuasiSober \u03b1] [IrreducibleSpace \u03b1] :\n    closure ({genericPoint \u03b1} : Set \u03b1) = \u22a4 :=\n  genericPoint_spec \u03b1\n#align generic_point_closure genericPoint_closure\n\nvariable {\u03b1}\n\ntheorem genericPoint_specializes [QuasiSober \u03b1] [IrreducibleSpace \u03b1] (x : \u03b1) : genericPoint \u03b1 \u2933 x :=\n  (IsIrreducible.genericPoint_spec _).specializes (by simp)\n#align generic_point_specializes genericPoint_specializes\n\nattribute [local instance] specializationOrder\n\n/-- The closed irreducible subsets of a sober space bijects with the points of the space. -/\nnoncomputable def irreducibleSetEquivPoints [QuasiSober \u03b1] [T0Space \u03b1] :\n    { s : Set \u03b1 | IsIrreducible s \u2227 IsClosed s } \u2243o \u03b1 where\n  toFun s := s.prop.1.genericPoint\n  invFun x := \u27e8closure ({x} : Set \u03b1), isIrreducible_singleton.closure, isClosed_closure\u27e9\n  left_inv s := Subtype.eq <| Eq.trans s.prop.1.genericPoint_spec <|\n    closure_eq_iff_isClosed.mpr s.2.2\n  right_inv x := isIrreducible_singleton.closure.genericPoint_spec.eq\n      (by rw [closure_closure]; exact isGenericPoint_closure)\n  map_rel_iff' := by\n    rintro \u27e8s, hs\u27e9 \u27e8t, ht\u27e9\n    refine specializes_iff_closure_subset.trans ?_\n    simp [hs.2.closure_eq, ht.2.closure_eq]\n#align irreducible_set_equiv_points irreducibleSetEquivPoints\n\ntheorem ClosedEmbedding.quasiSober {f : \u03b1 \u2192 \u03b2} (hf : ClosedEmbedding f) [QuasiSober \u03b2] :\n    QuasiSober \u03b1 where\n  sober hS hS' := by\n    have hS'' := hS.image f hf.continuous.continuousOn\n    obtain \u27e8x, hx\u27e9 := QuasiSober.sober hS'' (hf.isClosedMap _ hS')\n    obtain \u27e8y, -, rfl\u27e9 := hx.mem\n    use y\n    apply image_injective.mpr hf.inj\n    rw [\u2190 hx.def, \u2190 hf.closure_image_eq, image_singleton]\n#align closed_embedding.quasi_sober ClosedEmbedding.quasiSober\n\ntheorem OpenEmbedding.quasiSober {f : \u03b1 \u2192 \u03b2} (hf : OpenEmbedding f) [QuasiSober \u03b2] :\n    QuasiSober \u03b1 where\n  sober hS hS' := by\n    have hS'' := hS.image f hf.continuous.continuousOn\n    obtain \u27e8x, hx\u27e9 := QuasiSober.sober hS''.closure isClosed_closure\n    obtain \u27e8T, hT, rfl\u27e9 := hf.toInducing.isClosed_iff.mp hS'\n    rw [image_preimage_eq_inter_range] at hx hS''\n    have hxT : x \u2208 T := by\n      rw [\u2190 hT.closure_eq]\n      exact closure_mono (inter_subset_left _ _) hx.mem\n    obtain \u27e8y, rfl\u27e9 : x \u2208 range f := by\n      rw [hx.mem_open_set_iff hf.open_range]\n      refine' Nonempty.mono _ hS''.1\n      simpa using subset_closure\n    use y\n    change _ = _\n    rw [hf.toEmbedding.closure_eq_preimage_closure_image, image_singleton, show _ = _ from hx]\n    apply image_injective.mpr hf.inj\n    ext z\n    simp only [image_preimage_eq_inter_range, mem_inter_iff, and_congr_left_iff]\n    exact fun hy => \u27e8fun h => hT.closure_eq \u25b8 closure_mono (inter_subset_left _ _) h,\n      fun h => subset_closure \u27e8h, hy\u27e9\u27e9\n#align open_embedding.quasi_sober OpenEmbedding.quasiSober\n\n/-- A space is quasi sober if it can be covered by open quasi sober subsets. -/\ntheorem quasiSober_of_open_cover (S : Set (Set \u03b1)) (hS : \u2200 s : S, IsOpen (s : Set \u03b1))\n    [hS' : \u2200 s : S, QuasiSober s] (hS'' : \u22c3\u2080 S = \u22a4) : QuasiSober \u03b1 := by\n  rw [quasiSober_iff]\n  intro t h h'\n  obtain \u27e8x, hx\u27e9 := h.1\n  obtain \u27e8U, hU, hU'\u27e9 : x \u2208 \u22c3\u2080 S := by\n    rw [hS'']\n    trivial\n  haveI : QuasiSober U := hS' \u27e8U, hU\u27e9\n  have H : IsPreirreducible ((\u2191) \u207b\u00b9' t : Set U) :=\n    h.2.preimage (hS \u27e8U, hU\u27e9).openEmbedding_subtype_val\n  replace H : IsIrreducible ((\u2191) \u207b\u00b9' t : Set U) := \u27e8\u27e8\u27e8x, hU'\u27e9, by simpa using hx\u27e9, H\u27e9\n  use H.genericPoint\n  have := continuous_subtype_val.closure_preimage_subset _ H.genericPoint_spec.mem\n  rw [h'.closure_eq] at this\n  apply le_antisymm\n  \u00b7 apply h'.closure_subset_iff.mpr\n    simpa using this\n  rw [\u2190 image_singleton, \u2190 closure_image_closure continuous_subtype_val, H.genericPoint_spec.def]\n  refine' (subset_closure_inter_of_isPreirreducible_of_isOpen h.2 (hS \u27e8U, hU\u27e9) \u27e8x, hx, hU'\u27e9).trans\n    (closure_mono _)\n  rw [\u2190 Subtype.image_preimage_coe]\n  exact Set.image_subset _ subset_closure\n#align quasi_sober_of_open_cover quasiSober_of_open_cover\n\n/-- Any Hausdorff space is a quasi-sober space because any irreducible set is a singleton. -/\ninstance (priority := 100) T2Space.quasiSober [T2Space \u03b1] : QuasiSober \u03b1 where\n  sober h _ := by\n    obtain \u27e8x, rfl\u27e9 := isIrreducible_iff_singleton.mp h\n    exact \u27e8x, closure_singleton\u27e9\n#align t2_space.quasi_sober T2Space.quasiSober\n\nend Sober\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/Sober.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7218540338713215}}
{"text": "import function.bijection data.list.set data.fin\nopen fin function\n\n\nnamespace fin\nprotected\nlemma le_refl {n} (a : fin n) : a \u2264 a := fin.cases_on a (\u03bb a _, nat.le_refl a)\nprotected\nlemma le_trans {n} {a b c : fin n} : a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c := \nfin.cases_on a (\u03bb _ _, \nfin.cases_on b (\u03bb _ _,\nfin.cases_on c (\u03bb _ _,\n  assume Hab Hbc,\n  nat.le_trans Hab Hbc\n)\n)\n)\n\nprotected \nlemma le_antisymm {n}{a b : fin n} : a \u2264 b \u2192 b \u2264 a \u2192 a = b :=\nfin.cases_on a (\u03bb _ _,\nfin.cases_on b (\u03bb _ _,\n  assume Hab Hba,\n  fin.eq_of_veq (nat.le_antisymm Hab Hba)\n)\n)\n\ninstance {n} : decidable_linear_order (fin n) :=\n{\n  lt := fin.lt,\n  le := fin.le,\n  le_refl := fin.le_refl,\n  le_trans := @fin.le_trans _,\n  le_antisymm := @fin.le_antisymm _,\n  le_iff_lt_or_eq := \u03bb a b, \n    fin.cases_on a (\u03bb i _,\n    fin.cases_on b (\u03bb j _,\n     iff.intro (assume H, or.elim (nat.lt_or_eq_of_le H) or.inl (assume Heq, or.inr (fin.eq_of_veq Heq))) \n       (assume H, nat.le_of_lt_or_eq (or.imp id (begin intro heq, apply (fin.veq_of_eq heq) end) H))\n    )\n    ),\n  lt_irrefl := \u03bb a, fin.cases_on a (\u03bb _ _, \n    nat.lt_irrefl _\n  ),\n  le_total := \u03bb a b, fin.cases_on a (\u03bb _ _, fin.cases_on b (\u03bb _ _, nat.le_total)),\n  decidable_lt := fin.decidable_lt,\n  decidable_le := fin.decidable_le,\n  decidable_eq := fin.decidable_eq _\n}\ndef swap {n} (k : fin (n+1)) : fin (n+1) \u2192 fin (n+1) := take i, if i = k then 0 else if i = 0 then k else i\n\nnamespace swap\nvariables {n : \u2115 } {k : fin (n+1)}\nlemma idem : \u2200 i, swap k (swap k i) = i\n:= take i, if Hik : i = k then \n             if Hkz : k = 0 then by simp [Hik, Hkz, swap] else \n                begin \n                 simp_using_hs [swap],\n                 apply if_neg,\n                 intro H,\n                 apply Hkz,\n                 symmetry,\n                 assumption\n                end\n           else if Hiz : i = 0 then \n                begin \n                 rw Hiz,\n                 simp [swap],\n                 apply if_pos,\n                 apply if_neg,\n                 intro H,\n                 apply Hik,\n                 rw Hiz,\n                 assumption\n                end else \n                by\n                simp [swap];\n                cc\n\nlemma has_left_inverse  : has_left_inverse (swap k) := \u27e8 swap k, idem \u27e9         \nlemma has_right_inverse  :  has_right_inverse (swap k) := \u27e8 swap k, idem \u27e9  \nlemma has_isomorphism : has_bijection(swap k) := \u27e8 swap k,  idem , idem \u27e9 \n\nlemma injective : injective (swap k) := injective_of_has_left_inverse has_left_inverse\nlemma surjective : surjective (swap k) := surjective_of_has_right_inverse has_right_inverse\n\ninstance : bijection (swap k) := \u27e8 swap k, idem , idem \u27e9 \n\nlemma k_eq_zero : swap k k = 0 := by simp [swap]\nlemma zero_eq_k : swap k 0 = k := if H : 0 = k then by simp_using_hs [swap] else by simp_using_hs [swap]\nlemma id_of_zero : swap 0 = @id (fin (n+1)) := \n  begin\n  apply funext,\n  intro i,\n  simp_using_hs [swap],\n  cases (fin.decidable_eq _ i 0) with H H,\n  repeat {simp_using_hs}\n  end\nend swap\n\nlemma ne_zero_of_succ {n} : \u2200 i : fin n, fin.succ i \u2260 0 :=\n begin\n  intros i, \n  cases i, \n  unfold fin.succ,\n  intro H,\n  apply (nat.succ_ne_zero val),\n  apply (fin.veq_of_eq H),\n end \nlemma succ.injective {n} : injective (@fin.succ n) := \nbegin\n intros fi fj H,\n cases fi with i ilt,\n cases fj with j jlt,\n simp [fin.succ] at H,\n apply fin.eq_of_veq,\n apply nat.succ.inj,\n simp,\n exact (fin.veq_of_eq H)\nend\n\nlemma pred.injective {n} {i j : fin (n + 1)} { ine0 : i \u2260 0} { jne0 : j \u2260 0} : fin.pred i ine0 = fin.pred j jne0 \u2192 i = j\n:= \nbegin \ncases i with ival ilt,\ncases j with jval jlt,\nsimp [fin.pred],\nintro H,\napply fin.eq_of_veq,\nsimp,\napply nat.pred_inj,\n{\n  -- ival > 0\n  apply nat.pos_of_ne_zero,\n  exact (fin.vne_of_ne ine0)\n},\n{\n  -- jval > 0\n  apply nat.pos_of_ne_zero,\n  exact (fin.vne_of_ne jne0)\n},\n{\n  exact (fin.veq_of_eq H)\n}\nend\n\n/--\n A proof of pigeonhole principle.\n-/\ntheorem not_injective_of_gt {m n} (f : fin m \u2192 fin n) : m > n \u2192 \u00ac injective f := \nbegin\n  revert m,\n  induction n with n iH,\n  {\n      intros m f H Hinj,\n      cases (f \u27e80, H\u27e9 ) with val is_lt,\n      exact (absurd is_lt (nat.not_lt_zero _))\n  },\n  {\n      intros m f Hmn Hinj,\n      pose pred_m := nat.pred m,\n      assert Hm : m = nat.succ pred_m, {\n          symmetry,\n          apply nat.succ_pred_eq_of_pos,\n          transitivity,\n          exact Hmn,\n          apply nat.zero_lt_succ\n      },\n      revert f Hmn,\n      rw Hm,\n      intros f Hpmn Hinj,\n      pose g := swap (f 0) \u2218 f \u2218 fin.succ,\n      assert Hgnz : \u2200 i, g i \u2260 0,\n      {\n        intros i Hgz,\n        apply (ne_zero_of_succ i),\n        apply Hinj,\n        apply (@swap.injective _ (f 0)),\n        rw swap.k_eq_zero,\n        assumption\n      },\n      pose h := \u03bb i, fin.pred (g i) (Hgnz i),\n      apply (iH h),\n        {\n          apply nat.le_of_succ_le_succ,\n          apply Hpmn,\n        },\n        {\n            intros i\u2081 i\u2082 Heq,\n            apply succ.injective,\n            apply Hinj,\n            apply swap.injective,\n            apply pred.injective,\n            assumption\n        }\n  }\nend\n\n\ndef elems : \u2200 n : \u2115, list (fin n)\n| 0 := []\n| (n+1) := 0 :: list.map fin.succ (elems n)\n\nlemma succ_ne_zero {n} (i : fin n) : fin.succ i \u2260 0 :=\nbegin\ncases i,\nsimp [fin.succ],\napply fin.ne_of_vne,\nrw fin.val_zero,\nsimp,\napply nat.succ_ne_zero\nend\n\n/-\nlemma nodup_elems : \u2200 n, list.nodup (elems n) \n| 0     := list.nodup_nil\n| (n+1) := list.nodup_cons (\u03bb h, exists.elim (list.exists_of_mem_map h) (\u03bb i hp, succ_ne_zero _ hp.right)) \n    (list.nodup_map succ.injective (nodup_elems n))\n-/\n\ndef mem_elems : \u2200 {n} (i : fin n), i \u2208 elems n \n| 0     \u27e8_ , is_lt\u27e9 := absurd is_lt (nat.not_lt_zero _)\n| (n+1) \u27e80 , _\u27e9 := list.mem_cons_self _ _\n| (n+1) \u27e8i + 1, is_lt\u27e9 := list.mem_cons_of_mem _ (list.mem_map fin.succ (mem_elems \u27e8i, nat.le_of_succ_le_succ is_lt\u27e9))\n\n\n\ndef {u} nth { \u03b1 : Type u} : \u03a0 (l : list \u03b1), fin (list.length l) \u2192 \u03b1 \n| [] \u27e8_, is_lt\u27e9  := absurd is_lt (nat.not_lt_zero _)\n| (x :: xs) \u27e80, _\u27e9  := x \n| (_ :: xs) \u27e8n+1, is_lt\u27e9 := nth xs \u27e8n, nat.le_of_succ_le_succ is_lt\u27e9 \n\nlemma {u} mem_nth {\u03b1 : Type u} : \u2200 (l : list \u03b1) i, nth l i \u2208 l\n| [] \u27e8_, is_lt\u27e9  := absurd is_lt (nat.not_lt_zero _)\n| (x :: xs) \u27e80, _\u27e9 := list.mem_cons_self _ _\n| (_ :: xs) \u27e8i+1, is_lt\u27e9 := list.mem_cons_of_mem _ $ mem_nth xs \u27e8i, nat.le_of_succ_le_succ is_lt\u27e9 \n\ndef {u} left_index {\u03b1 : Type u}[decidable_eq \u03b1]{a} : \u03a0 {l : list \u03b1}, a \u2208 l \u2192 fin (list.length l)\n| []      h := absurd h (list.not_mem_nil _)\n| (x::xs) h := if H : a = x then (0 : fin ((list.length xs) + 1)) \n               else fin.succ $ left_index $ or.resolve_left h H\n\ndef {u} nth_left_index_left_inverse {\u03b1 : Type u} [deq : decidable_eq \u03b1] {l : list \u03b1} {a} (h : a \u2208 l) : nth l (left_index h) = a := \nbegin\ninduction l with x xs iH,\n{\n  exact (absurd h (list.not_mem_nil _))\n},\n{\n  unfold left_index,\n  cases (deq a x) with Hne Heq,\n  {\n    rw dif_neg,\n    assert Hmem : a \u2208 xs, apply or.resolve_left, assumption, assumption,\n    change nth (x :: xs) (fin.succ (left_index Hmem)) = a,\n    assert Lem : \u2200 a x (xs : list \u03b1)(H : a \u2208 xs), nth (x :: xs) (fin.succ (left_index H)) = nth xs (left_index H),\n    {\n      intros a x xs H,\n      generalize (left_index H) i,\n      intro i,\n      cases i,\n      simp [fin.succ, nth],\n      refl\n    },\n    rw Lem,\n    apply iH,\n    assumption \n  },\n  {\n    rw dif_pos,\n    rw Heq,\n    refl,\n    assumption\n  }\n}\nend\n\n\nlemma {u} nth_ne_nth_of_nodup_of_lt {\u03b1 : Type u} {l : list \u03b1}  : \u03a0 {i j : fin (list.length l)}, list.nodup l \u2192 i < j \u2192 nth l i \u2260 nth l j :=\nbegin\ninduction l with x xs iH,\n{\n  intro i,\n  exact (absurd i.is_lt (nat.not_lt_zero _))\n},\n{\n  intros i j Hdis Hlt Heq,\n  cases i with i ilt,\n  cases j with j jlt,\n  assert Hj : j = nat.succ (nat.pred j),\n  {\n    symmetry,\n    apply nat.succ_pred_eq_of_pos,\n    apply nat.lt_of_le_of_lt,\n    apply nat.zero_le,\n    assumption\n  },\n  revert jlt,\n  rw Hj,\n  intros jlt Hlt Heq,\n  cases i with i,\n  {\n    simp [nth] at Heq,\n    \n    apply (list.not_mem_of_nodup_cons Hdis),\n    rw Heq,\n    apply mem_nth\n  },\n  {\n    simp [nth] at Heq,\n    apply (@iH \u27e8i, nat.lt_of_succ_lt_succ ilt\u27e9 \u27e8nat.pred j, nat.lt_of_succ_lt_succ jlt\u27e9 ),\n    apply list.nodup_of_nodup_cons,\n    assumption,\n    exact (nat.lt_of_succ_lt_succ Hlt),\n    assumption\n  }\n}\nend\n\nlemma {u} left_index_mem_nth_left_inverse_of_nodup {\u03b1 : Type u}[decidable_eq \u03b1]{l : list \u03b1} : list.nodup l \u2192 \u2200 i, left_index (mem_nth l i) = i :=\nbegin\nintros Hdis i,\ninduction Hdis with x xs Hx dxs iH,\n{\n  exact (absurd i.is_lt (nat.not_lt_zero _))\n},\n{\n  cases i with i ilt,\n  cases i with i,\n  {\n    change left_index (list.mem_cons_self x xs) = \u27e80, _\u27e9,\n    simp [left_index],\n    rw dif_pos,\n    refl,\n    refl\n  },\n  {\n    simp [left_index, mem_nth],\n    rw dif_neg,\n    assert Lem : \u2200 {n}(i : fin n), (fin.succ i).val = nat.succ i.val, \n    {\n      intros n i,\n      cases i,\n      simp [fin.succ]\n    },\n    apply fin.eq_of_veq,\n    rw Lem,\n    simp,\n    apply (congr_arg nat.succ),\n    pose j : fin (list.length xs) := \u27e8i, nat.lt_of_succ_lt_succ ilt\u27e9, \n    change (left_index (mem_nth xs j)).val = j.val,\n    apply fin.veq_of_eq,\n    apply iH,\n    simp [nth],\n    intro H,\n    apply Hx,\n    rw -H,\n    apply mem_nth\n  }\n}\nend\nlemma {u} injective_nth_of_nodup {\u03b1 : Type u}{l : list \u03b1} : list.nodup l \u2192 injective (nth l) :=\n  assume Hdis, take i j, assume H, \n      if Heq : i = j then Heq\n      else if Hlt : i < j then absurd H (nth_ne_nth_of_nodup_of_lt Hdis Hlt) \n      else have j < i, from or.resolve_left (lt_or_gt_of_ne Heq) Hlt,\n           absurd (eq.symm H) (nth_ne_nth_of_nodup_of_lt Hdis this)\n\nlemma length_le_of_nodup_fin {n} {l : list (fin n)} : list.nodup l \u2192 list.length l \u2264 n :=\nbegin\n intro Hdis,\n induction l with x xs iH, \n {\n   exact (nat.zero_le _)\n },\n {\n    apply le_of_not_gt,\n    unfold list.length,\n    intro Hgt,\n    pose f : fin (list.length xs + 1) \u2192 fin n := nth (x::xs),\n    apply not_injective_of_gt f Hgt,\n    intros i j Hf,\n    cases (fin.decidable_eq _ i j) with Hne Heq,\n      {\n        assert Ho : i < j \u2228 i > j,\n        {\n          cases i with i ilt,\n          cases j with j jlt,\n          change (i < j \u2228 i > j),\n          apply lt_or_gt_of_ne,\n          apply (fin.vne_of_ne Hne)\n        },\n       cases Ho with Hlt Hgt,\n       {\n          exact (absurd Hf (nth_ne_nth_of_nodup_of_lt Hdis Hlt))\n       },\n       {\n         exact (absurd (eq.symm Hf) (nth_ne_nth_of_nodup_of_lt Hdis Hgt))\n       }\n       \n      },\n      {\n        exact Heq\n      }\n }\nend\nend fin", "meta": {"author": "tizmd", "repo": "lean-finitary", "sha": "8958fdb3fa3d9fcc304e116fd339448875025e95", "save_path": "github-repos/lean/tizmd-lean-finitary", "path": "github-repos/lean/tizmd-lean-finitary/lean-finitary-8958fdb3fa3d9fcc304e116fd339448875025e95/data/fin/misc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7218313446045646}}
{"text": "import examples.automata\n\n\n\nnamespace Automata\n\n    variables {Sigma : Type}       -- The alphabet\n              {D : Type}            -- Output\n    open word \n\n    structure Automaton    :=         \n            (State : Type)                 -- Set of States\n            (\u03b4 : State \u2192 Sigma \u2192 State)    -- \u03b4: S \u00d7 \u03a3 \u2192 S\n            (\u03b3 : State \u2192 D)                -- Output of a state\n\n    /-\n    Given a morphism \u03c4 between two Automates A and B\n    determines if \u03c4 is a homomorphism\n    -/\n\n    def is_homomorphism_Automaton                \n        {A B : @Automaton Sigma D} (\u03c4 : A.State \u2192 B.State) : Prop :=   \n            \u2200 a : A.State ,                     -- \u2200 states (a) in A\n                A.\u03b3 a  = B.\u03b3 (\u03c4 a) \u2227            -- a \u2208 T_A iff \u03c4(a) \u2208 T_B\n            \u2200 e : Sigma ,                       -- and \u2200 e \u2208 \u03a3\n                \u03c4 (A.\u03b4 a e) = (B.\u03b4 (\u03c4 a) e)     -- \u03c4(\u03b4_A(a , e)) = \u03b4_B(\u03c4(a) , e)\n\n\n    def deltaStar {A : @Automaton Sigma D} (s : A.State): word Sigma \u2192 A.State \n        | \u03b5           :=  s \n        | (e\u2022v)       :=  A.\u03b4 (deltaStar v) e\n\n\n    def state_output \n        {A : Automaton} \n        (s : A.State) \n        (w : @word Sigma) : D :=\n        A.\u03b3 (deltaStar s w)\n\n\n    \n\n    inductive T_tree : Type \n        | node : D \u2192 (Sigma \u2192 T_tree) \u2192 T_tree\n\n    notation  d ` - ` \u03c6  := T_tree.node d \u03c6\n\n    def delta : @T_tree Sigma D \u2192 Sigma \u2192 @T_tree Sigma D\n        | (d - \u03c6) e := \u03c6 e\n\n    def gamma : @T_tree Sigma D \u2192 D\n        | (d - \u03c6) := d\n\n    def Tree_Automaton : Automaton :=\n    {\n        State       := @T_tree Sigma D,\n        \u03b4           := delta ,\n        \u03b3           := gamma\n    }\n\n    def Terminal_Automaton : Automaton :=\n    {\n        State       := word Sigma \u2192 D ,\n        \u03b4           := \u03bb \u03c4 e , \u03bb w , \u03c4 (e \u2022 w)  , \n        \u03b3           := \u03bb \u03c4 , \u03c4 word.\u03b5\n    }\n\n\n    def \u03c6 (A : @Automaton Sigma D) : \n          A.State \u2192 (@Terminal_Automaton Sigma D).State\n        | a word.\u03b5      := A.\u03b3 a\n        | a (e \u2022 w)     := \u03c6 (A.\u03b4 a e) w\n\n    theorem Terminal_is_Automaton (A : @Automaton Sigma D) :\n            is_homomorphism_Automaton (\u03c6 A) := \n            assume a : A.State , \n            and.intro\n                begin\n                    apply rfl,\n                end\n                begin\n                    intro e,\n                    apply rfl\n                end\n\nend Automata\n\n\n\n\n\n\n\n", "meta": {"author": "QaisHamarneh", "repo": "Coalgebra-in-Lean", "sha": "bd0452df98bc64b608e5dfd7babc42c301bb6a46", "save_path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean", "path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean/Coalgebra-in-Lean-bd0452df98bc64b608e5dfd7babc42c301bb6a46/src/examples/terminal_automata.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7216727993348677}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module topology.metric_space.completion\n! leanprover-community/mathlib commit 69c6a5a12d8a2b159f20933e60115a4f2de62b58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.UniformSpace.Completion\nimport Mathbin.Topology.MetricSpace.Isometry\nimport Mathbin.Topology.Instances.Real\n\n/-!\n# The completion of a metric space\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nCompletion of uniform spaces are already defined in `topology.uniform_space.completion`. We show\nhere that the uniform space completion of a metric space inherits a metric space structure,\nby extending the distance to the completion and checking that it is indeed a distance, and that\nit defines the same uniformity as the already defined uniform structure on the completion\n-/\n\n\nopen Set Filter UniformSpace Metric\n\nopen Filter Topology uniformity\n\nnoncomputable section\n\nuniverse u v\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} [PseudoMetricSpace \u03b1]\n\nnamespace UniformSpace.Completion\n\n/-- The distance on the completion is obtained by extending the distance on the original space,\nby uniform continuity. -/\ninstance : Dist (Completion \u03b1) :=\n  \u27e8Completion.extension\u2082 dist\u27e9\n\n/- warning: uniform_space.completion.uniform_continuous_dist -> UniformSpace.Completion.uniformContinuous_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], UniformContinuous.{u1, 0} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) Real (Prod.uniformSpace.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (PseudoMetricSpace.toUniformSpace.{0} Real Real.pseudoMetricSpace) (fun (p : Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) => Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) (Prod.fst.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p) (Prod.snd.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], UniformContinuous.{u1, 0} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) Real (instUniformSpaceProd.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (PseudoMetricSpace.toUniformSpace.{0} Real Real.pseudoMetricSpace) (fun (p : Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) => Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) (Prod.fst.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p) (Prod.snd.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p))\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.uniform_continuous_dist UniformSpace.Completion.uniformContinuous_dist\u2093'. -/\n/-- The new distance is uniformly continuous. -/\nprotected theorem uniformContinuous_dist :\n    UniformContinuous fun p : Completion \u03b1 \u00d7 Completion \u03b1 => dist p.1 p.2 :=\n  uniformContinuous_extension\u2082 dist\n#align uniform_space.completion.uniform_continuous_dist UniformSpace.Completion.uniformContinuous_dist\n\n#print UniformSpace.Completion.continuous_dist /-\n/-- The new distance is continuous. -/\nprotected theorem continuous_dist [TopologicalSpace \u03b2] {f g : \u03b2 \u2192 Completion \u03b1} (hf : Continuous f)\n    (hg : Continuous g) : Continuous fun x => dist (f x) (g x) :=\n  Completion.uniformContinuous_dist.Continuous.comp (hf.prod_mk hg : _)\n#align uniform_space.completion.continuous_dist UniformSpace.Completion.continuous_dist\n-/\n\n/- warning: uniform_space.completion.dist_eq -> UniformSpace.Completion.dist_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : \u03b1) (y : \u03b1), Eq.{1} Real (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (HasLiftT.mk.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (CoeTC\u2093.coe.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasCoeT.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) x) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (HasLiftT.mk.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (CoeTC\u2093.coe.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasCoeT.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) y)) (Dist.dist.{u1} \u03b1 (PseudoMetricSpace.toHasDist.{u1} \u03b1 _inst_1) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : \u03b1) (y : \u03b1), Eq.{1} Real (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) (UniformSpace.Completion.coe'.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1) x) (UniformSpace.Completion.coe'.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1) y)) (Dist.dist.{u1} \u03b1 (PseudoMetricSpace.toDist.{u1} \u03b1 _inst_1) x y)\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.dist_eq UniformSpace.Completion.dist_eq\u2093'. -/\n/-- The new distance is an extension of the original distance. -/\n@[simp]\nprotected theorem dist_eq (x y : \u03b1) : dist (x : Completion \u03b1) y = dist x y :=\n  Completion.extension\u2082_coe_coe uniformContinuous_dist _ _\n#align uniform_space.completion.dist_eq UniformSpace.Completion.dist_eq\n\n/- warning: uniform_space.completion.dist_self -> UniformSpace.Completion.dist_self is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)), Eq.{1} Real (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) x x) (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)), Eq.{1} Real (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) x x) (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.dist_self UniformSpace.Completion.dist_self\u2093'. -/\n/- Let us check that the new distance satisfies the axioms of a distance, by starting from the\nproperties on \u03b1 and extending them to `completion \u03b1` by continuity. -/\nprotected theorem dist_self (x : Completion \u03b1) : dist x x = 0 :=\n  by\n  apply induction_on x\n  \u00b7 refine' isClosed_eq _ continuous_const\n    exact completion.continuous_dist continuous_id continuous_id\n  \u00b7 intro a\n    rw [completion.dist_eq, dist_self]\n#align uniform_space.completion.dist_self UniformSpace.Completion.dist_self\n\n#print UniformSpace.Completion.dist_comm /-\nprotected theorem dist_comm (x y : Completion \u03b1) : dist x y = dist y x :=\n  by\n  apply induction_on\u2082 x y\n  \u00b7\n    exact\n      isClosed_eq (completion.continuous_dist continuous_fst continuous_snd)\n        (completion.continuous_dist continuous_snd continuous_fst)\n  \u00b7 intro a b\n    rw [completion.dist_eq, completion.dist_eq, dist_comm]\n#align uniform_space.completion.dist_comm UniformSpace.Completion.dist_comm\n-/\n\n/- warning: uniform_space.completion.dist_triangle -> UniformSpace.Completion.dist_triangle is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (y : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (z : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)), LE.le.{0} Real Real.hasLe (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) x z) (HAdd.hAdd.{0, 0, 0} Real Real Real (instHAdd.{0} Real Real.hasAdd) (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) x y) (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) y z))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (y : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (z : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)), LE.le.{0} Real Real.instLEReal (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) x z) (HAdd.hAdd.{0, 0, 0} Real Real Real (instHAdd.{0} Real Real.instAddReal) (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) x y) (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) y z))\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.dist_triangle UniformSpace.Completion.dist_triangle\u2093'. -/\nprotected theorem dist_triangle (x y z : Completion \u03b1) : dist x z \u2264 dist x y + dist y z :=\n  by\n  apply induction_on\u2083 x y z\n  \u00b7\n    refine' isClosed_le _ (Continuous.add _ _) <;>\n      apply_rules [completion.continuous_dist, Continuous.fst, Continuous.snd, continuous_id]\n  \u00b7 intro a b c\n    rw [completion.dist_eq, completion.dist_eq, completion.dist_eq]\n    exact dist_triangle a b c\n#align uniform_space.completion.dist_triangle UniformSpace.Completion.dist_triangle\n\n/- warning: uniform_space.completion.mem_uniformity_dist -> UniformSpace.Completion.mem_uniformity_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (s : Set.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))), Iff (Membership.Mem.{u1, u1} (Set.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.hasMem.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) s (uniformity.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Exists.{1} Real (fun (\u03b5 : Real) => Exists.{0} (GT.gt.{0} Real Real.hasLt \u03b5 (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) (fun (H : GT.gt.{0} Real Real.hasLt \u03b5 (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) => forall {a : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)} {b : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)}, (LT.lt.{0} Real Real.hasLt (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) a b) \u03b5) -> (Membership.Mem.{u1, u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (Set.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Set.hasMem.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Prod.mk.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) a b) s))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (s : Set.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))), Iff (Membership.mem.{u1, u1} (Set.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (instMembershipSetFilter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) s (uniformity.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Exists.{1} Real (fun (\u03b5 : Real) => And (GT.gt.{0} Real Real.instLTReal \u03b5 (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) (forall {a : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)} {b : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)}, (LT.lt.{0} Real Real.instLTReal (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) a b) \u03b5) -> (Membership.mem.{u1, u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (Set.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Set.instMembershipSet.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Prod.mk.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) a b) s))))\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.mem_uniformity_dist UniformSpace.Completion.mem_uniformity_dist\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/-- Elements of the uniformity (defined generally for completions) can be characterized in terms\nof the distance. -/\nprotected theorem mem_uniformity_dist (s : Set (Completion \u03b1 \u00d7 Completion \u03b1)) :\n    s \u2208 \ud835\udce4 (Completion \u03b1) \u2194 \u2203 \u03b5 > 0, \u2200 {a b}, dist a b < \u03b5 \u2192 (a, b) \u2208 s :=\n  by\n  constructor\n  \u00b7 /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in `\u03b1` is an\n        entourage, so it contains an `\u03b5`-neighborhood of the diagonal by definition of the entourages\n        in metric spaces. Then `t` contains an `\u03b5`-neighborhood of the diagonal in `completion \u03b1`, as\n        closed properties pass to the completion. -/\n    intro hs\n    rcases mem_uniformity_isClosed hs with \u27e8t, ht, \u27e8tclosed, ts\u27e9\u27e9\n    have A : { x : \u03b1 \u00d7 \u03b1 | (coe x.1, coe x.2) \u2208 t } \u2208 uniformity \u03b1 :=\n      uniformContinuous_def.1 (uniform_continuous_coe \u03b1) t ht\n    rcases mem_uniformity_dist.1 A with \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9\n    refine' \u27e8\u03b5, \u03b5pos, fun x y hxy => _\u27e9\n    have : \u03b5 \u2264 dist x y \u2228 (x, y) \u2208 t := by\n      apply induction_on\u2082 x y\n      \u00b7 have :\n          { x : completion \u03b1 \u00d7 completion \u03b1 | \u03b5 \u2264 dist x.fst x.snd \u2228 (x.fst, x.snd) \u2208 t } =\n            { p : completion \u03b1 \u00d7 completion \u03b1 | \u03b5 \u2264 dist p.1 p.2 } \u222a t :=\n          by ext <;> simp\n        rw [this]\n        apply IsClosed.union _ tclosed\n        exact isClosed_le continuous_const completion.uniform_continuous_dist.continuous\n      \u00b7 intro x y\n        rw [completion.dist_eq]\n        by_cases h : \u03b5 \u2264 dist x y\n        \u00b7 exact Or.inl h\n        \u00b7 have Z := h\u03b5 (not_le.1 h)\n          simp only [Set.mem_setOf_eq] at Z\n          exact Or.inr Z\n    simp only [not_le.mpr hxy, false_or_iff, not_le] at this\n    exact ts this\n  \u00b7 /- Start from a set `s` containing an \u03b5-neighborhood of the diagonal in `completion \u03b1`. To show\n        that it is an entourage, we use the fact that `dist` is uniformly continuous on\n        `completion \u03b1 \u00d7 completion \u03b1` (this is a general property of the extension of uniformly\n        continuous functions). Therefore, the preimage of the \u03b5-neighborhood of the diagonal in \u211d\n        is an entourage in `completion \u03b1 \u00d7 completion \u03b1`. Massaging this property, it follows that\n        the \u03b5-neighborhood of the diagonal is an entourage in `completion \u03b1`, and therefore this is\n        also the case of `s`. -/\n    rintro \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9\n    let r : Set (\u211d \u00d7 \u211d) := { p | dist p.1 p.2 < \u03b5 }\n    have : r \u2208 uniformity \u211d := Metric.dist_mem_uniformity \u03b5pos\n    have T := uniformContinuous_def.1 (@completion.uniform_continuous_dist \u03b1 _) r this\n    simp only [uniformity_prod_eq_prod, mem_prod_iff, exists_prop, Filter.mem_map,\n      Set.mem_setOf_eq] at T\n    rcases T with \u27e8t1, ht1, t2, ht2, ht\u27e9\n    refine' mem_of_superset ht1 _\n    have A : \u2200 a b : completion \u03b1, (a, b) \u2208 t1 \u2192 dist a b < \u03b5 :=\n      by\n      intro a b hab\n      have : ((a, b), (a, a)) \u2208 t1 \u00d7\u02e2 t2 := \u27e8hab, refl_mem_uniformity ht2\u27e9\n      have I := ht this\n      simp [completion.dist_self, Real.dist_eq, completion.dist_comm] at I\n      exact lt_of_le_of_lt (le_abs_self _) I\n    show t1 \u2286 s\n    \u00b7 rintro \u27e8a, b\u27e9 hp\n      have : dist a b < \u03b5 := A a b hp\n      exact h\u03b5 this\n#align uniform_space.completion.mem_uniformity_dist UniformSpace.Completion.mem_uniformity_dist\n\n/- warning: uniform_space.completion.eq_of_dist_eq_zero -> UniformSpace.Completion.eq_of_dist_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (y : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)), (Eq.{1} Real (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) x y) (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (Eq.{succ u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (y : UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)), (Eq.{1} Real (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) x y) (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (Eq.{succ u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) x y)\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.eq_of_dist_eq_zero UniformSpace.Completion.eq_of_dist_eq_zero\u2093'. -/\n/-- If two points are at distance 0, then they coincide. -/\nprotected theorem eq_of_dist_eq_zero (x y : Completion \u03b1) (h : dist x y = 0) : x = y :=\n  by\n  /- This follows from the separation of `completion \u03b1` and from the description of\n    entourages in terms of the distance. -/\n  have : SeparatedSpace (completion \u03b1) := by infer_instance\n  refine' separated_def.1 this x y fun s hs => _\n  rcases(completion.mem_uniformity_dist s).1 hs with \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9\n  rw [\u2190 h] at \u03b5pos\n  exact h\u03b5 \u03b5pos\n#align uniform_space.completion.eq_of_dist_eq_zero UniformSpace.Completion.eq_of_dist_eq_zero\n\n/- warning: uniform_space.completion.uniformity_dist' -> UniformSpace.Completion.uniformity_dist' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], Eq.{succ u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (uniformity.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (inf\u1d62.{u1, 1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (ConditionallyCompleteLattice.toHasInf.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.completeLattice.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))))) (Subtype.{1} Real (fun (\u03b5 : Real) => LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) \u03b5)) (fun (\u03b5 : Subtype.{1} Real (fun (\u03b5 : Real) => LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) \u03b5)) => Filter.principal.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (setOf.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (fun (p : Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) => LT.lt.{0} Real Real.hasLt (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) (Prod.fst.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p) (Prod.snd.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p)) (Subtype.val.{1} Real (fun (\u03b5 : Real) => LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) \u03b5) \u03b5)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], Eq.{succ u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (uniformity.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (inf\u1d62.{u1, 1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (ConditionallyCompleteLattice.toInfSet.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.instCompleteLatticeFilter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))))) (Subtype.{1} Real (fun (\u03b5 : Real) => LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) \u03b5)) (fun (\u03b5 : Subtype.{1} Real (fun (\u03b5 : Real) => LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) \u03b5)) => Filter.principal.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (setOf.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (fun (p : Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) => LT.lt.{0} Real Real.instLTReal (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) (Prod.fst.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p) (Prod.snd.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p)) (Subtype.val.{1} Real (fun (\u03b5 : Real) => LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) \u03b5) \u03b5)))))\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.uniformity_dist' UniformSpace.Completion.uniformity_dist'\u2093'. -/\n/-- Reformulate `completion.mem_uniformity_dist` in terms that are suitable for the definition\nof the metric space structure. -/\nprotected theorem uniformity_dist' :\n    \ud835\udce4 (Completion \u03b1) = \u2a05 \u03b5 : { \u03b5 : \u211d // 0 < \u03b5 }, \ud835\udcdf { p | dist p.1 p.2 < \u03b5.val } :=\n  by\n  ext s; rw [mem_infi_of_directed]\n  \u00b7 simp [completion.mem_uniformity_dist, subset_def]\n  \u00b7 rintro \u27e8r, hr\u27e9 \u27e8p, hp\u27e9\n    use \u27e8min r p, lt_min hr hp\u27e9\n    simp (config := { contextual := true }) [lt_min_iff, (\u00b7 \u2265 \u00b7)]\n#align uniform_space.completion.uniformity_dist' UniformSpace.Completion.uniformity_dist'\n\n/- warning: uniform_space.completion.uniformity_dist -> UniformSpace.Completion.uniformity_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], Eq.{succ u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (uniformity.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (inf\u1d62.{u1, 1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (ConditionallyCompleteLattice.toHasInf.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.completeLattice.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))))) Real (fun (\u03b5 : Real) => inf\u1d62.{u1, 0} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (ConditionallyCompleteLattice.toHasInf.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.completeLattice.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))))) (GT.gt.{0} Real Real.hasLt \u03b5 (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) (fun (H : GT.gt.{0} Real Real.hasLt \u03b5 (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) => Filter.principal.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (setOf.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (fun (p : Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) => LT.lt.{0} Real Real.hasLt (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasDist.{u1} \u03b1 _inst_1) (Prod.fst.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p) (Prod.snd.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p)) \u03b5)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], Eq.{succ u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (uniformity.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.uniformSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (inf\u1d62.{u1, 1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (ConditionallyCompleteLattice.toInfSet.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.instCompleteLatticeFilter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))))) Real (fun (\u03b5 : Real) => inf\u1d62.{u1, 0} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (ConditionallyCompleteLattice.toInfSet.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Filter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) (Filter.instCompleteLatticeFilter.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))))) (GT.gt.{0} Real Real.instLTReal \u03b5 (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) (fun (H : GT.gt.{0} Real Real.instLTReal \u03b5 (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) => Filter.principal.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (setOf.{u1} (Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) (fun (p : Prod.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))) => LT.lt.{0} Real Real.instLTReal (Dist.dist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instDistCompletionToUniformSpace.{u1} \u03b1 _inst_1) (Prod.fst.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p) (Prod.snd.{u1, u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) p)) \u03b5)))))\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.uniformity_dist UniformSpace.Completion.uniformity_dist\u2093'. -/\nprotected theorem uniformity_dist : \ud835\udce4 (Completion \u03b1) = \u2a05 \u03b5 > 0, \ud835\udcdf { p | dist p.1 p.2 < \u03b5 } := by\n  simpa [inf\u1d62_subtype] using @completion.uniformity_dist' \u03b1 _\n#align uniform_space.completion.uniformity_dist UniformSpace.Completion.uniformity_dist\n\n/-- Metric space structure on the completion of a pseudo_metric space. -/\ninstance : MetricSpace (Completion \u03b1)\n    where\n  dist_self := Completion.dist_self\n  eq_of_dist_eq_zero := Completion.eq_of_dist_eq_zero\n  dist_comm := Completion.dist_comm\n  dist_triangle := Completion.dist_triangle\n  dist := dist\n  toUniformSpace := by infer_instance\n  uniformity_dist := Completion.uniformity_dist\n\n/- warning: uniform_space.completion.coe_isometry -> UniformSpace.Completion.coe_isometry is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], Isometry.{u1, u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (MetricSpace.toPseudoMetricSpace.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.metricSpace.{u1} \u03b1 _inst_1))) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (HasLiftT.mk.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (CoeTC\u2093.coe.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasCoeT.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1], Isometry.{u1, u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (EMetricSpace.toPseudoEMetricSpace.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (MetricSpace.toEMetricSpace.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instMetricSpaceCompletionToUniformSpace.{u1} \u03b1 _inst_1))) (UniformSpace.Completion.coe'.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1))\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.coe_isometry UniformSpace.Completion.coe_isometry\u2093'. -/\n/-- The embedding of a metric space in its completion is an isometry. -/\ntheorem coe_isometry : Isometry (coe : \u03b1 \u2192 Completion \u03b1) :=\n  Isometry.of_dist_eq Completion.dist_eq\n#align uniform_space.completion.coe_isometry UniformSpace.Completion.coe_isometry\n\n/- warning: uniform_space.completion.edist_eq -> UniformSpace.Completion.edist_eq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : \u03b1) (y : \u03b1), Eq.{1} ENNReal (EDist.edist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (PseudoMetricSpace.toEDist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (MetricSpace.toPseudoMetricSpace.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.metricSpace.{u1} \u03b1 _inst_1))) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (HasLiftT.mk.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (CoeTC\u2093.coe.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasCoeT.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) x) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (HasLiftT.mk.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (CoeTC\u2093.coe.{succ u1, succ u1} \u03b1 (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.hasCoeT.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))) y)) (EDist.edist.{u1} \u03b1 (PseudoMetricSpace.toEDist.{u1} \u03b1 _inst_1) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] (x : \u03b1) (y : \u03b1), Eq.{1} ENNReal (EDist.edist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (PseudoEMetricSpace.toEDist.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (EMetricSpace.toPseudoEMetricSpace.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (MetricSpace.toEMetricSpace.{u1} (UniformSpace.Completion.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.Completion.instMetricSpaceCompletionToUniformSpace.{u1} \u03b1 _inst_1)))) (UniformSpace.Completion.coe'.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1) x) (UniformSpace.Completion.coe'.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1) y)) (EDist.edist.{u1} \u03b1 (PseudoEMetricSpace.toEDist.{u1} \u03b1 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1)) x y)\nCase conversion may be inaccurate. Consider using '#align uniform_space.completion.edist_eq UniformSpace.Completion.edist_eq\u2093'. -/\n@[simp]\nprotected theorem edist_eq (x y : \u03b1) : edist (x : Completion \u03b1) y = edist x y :=\n  coe_isometry x y\n#align uniform_space.completion.edist_eq UniformSpace.Completion.edist_eq\n\nend UniformSpace.Completion\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/MetricSpace/Completion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7216727913868223}}
{"text": "theorem t (p q r:Prop) : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\niff.intro\n    ( assume Hpqr : (p \u2228 q) \u2228 r,\n        or.elim Hpqr\n            ( assume Hpq : p \u2228 q,\n                or.elim Hpq\n                    ( assume Hp : p,\n                        or.intro_left (q \u2228 r) Hp)\n                    ( assume Hq : q,\n                        or.intro_right p (or.intro_left r Hq))\n            )\n            ( assume Hr : r,\n                or.intro_right p (or.intro_right q Hr)\n            )\n    )\n    ( assume Hpqr : p \u2228 (q \u2228 r),\n        or.elim Hpqr\n            ( assume Hp : p,\n                or.intro_left r (or.intro_left q Hp)\n            )\n            ( assume Hqr : q \u2228 r,\n                or.elim Hqr\n                    ( assume Hq : q,\n                        or.intro_left r (or.intro_right p Hq))\n                    ( assume Hr : r,\n                        or.intro_right (p \u2228 q) Hr)\n            )\n    )\ncheck t  -- t : \u2200 p q r, (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r)\n", "meta": {"author": "gagansh7171", "repo": "Automated-Theorem-Proving-Codes", "sha": "88a12ff4fafc6b746412f1ee7086cbf471daae88", "save_path": "github-repos/lean/gagansh7171-Automated-Theorem-Proving-Codes", "path": "github-repos/lean/gagansh7171-Automated-Theorem-Proving-Codes/Automated-Theorem-Proving-Codes-88a12ff4fafc6b746412f1ee7086cbf471daae88/proof-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7216727880780378}}
{"text": "/-\n  Definitions\n-/\n\ndef square (m : \u2115) : \u2115 :=\nm * m\n\n-- We can write the same function as a lambda\ndef square' : \u2115 \u2192 \u2115 :=\n\u03bb (m : \u2115), m * m\n\n-- ... or using pattern matching\ndef square'' : \u2115 \u2192 \u2115\n| 0     := 0\n| (m+1) := square'' m + 2 * m + 1\n\n\n\n/-\n  Interactive commands\n-/\n\n#print square'\n\n#eval square' 12\n\n#check square\n#check \u03bb x, square (string.length x)\n\nexample (x : \u2115) : \u2115 := square'' (2*x)\n\n#check \u2115 \u2192 \u2115\n#check \u2200 x : \u2115, x = x\n#check \u03a0 n : \u2115, array n \u2115\n\n\n/-\n  Polymorphic definitions\n-/\n\n#check \u2115\n#check Type\n#check Type 1\n#check Type 2\n\nuniverses u v\n#check Type u\n\n-- polymorphic functions take the type as an extra argument\ndef injective (\u03b1 : Type u) (\u03b2 : Type v) (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200 x y, f x = f y \u2192 x = y\n\n#check injective \u2115 \u2115 nat.succ\n\n-- using curly braces, Lean will fill in the type automatically (\"implicit argument\")\ndef injective' {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) : Prop :=\ninjective \u03b1 \u03b2 f\n\n#check injective \u2115 \u2115 nat.succ\n#check injective' nat.succ\n\n\n/-\n  Inductive types (\u2243 free algebras)\n-/\n\n-- \"Let mynat be the smallest set containing zero and succ x for every x \u2208 mynat\"\ninductive mynat : Type\n| zero : mynat\n| succ (x : mynat) : mynat\n\n#check mynat\n#check mynat.zero\n#check mynat.succ\n#check mynat.rec\n\n\n\n/-\n  Inductive predicates\n-/\n\n-- The same mechanism can also define predicates\n\n-- \"Let le be the smallest relation containg ...\"\ninductive mynat.le : mynat \u2192 mynat \u2192 Prop\n| refl {a} : mynat.le a a\n| step {a b} : mynat.le a b \u2192 mynat.le a (mynat.succ b)\n\n\n\n/-\n  Recursion\n-/\n\ndef mynat.add (m : mynat) : mynat \u2192 mynat\n-- pattern matching only applies to the arguments after the colon\n| mynat.zero := m\n| (mynat.succ x) := mynat.succ (mynat.add x)\n\n\n\n/-\n  Namespaces\n-/\n\n-- names in lean are separated by . (like / for file names)\n#check mynat.add\n\n-- after open, we no longer need to write the prefix\nopen mynat\n#check add\n#eval add (succ zero) (succ zero)\n\n-- adds the prefix to all definitions\nnamespace mynat.foo\nnamespace bar\ndef baz := succ zero\nend bar\nend mynat.foo\n#check mynat.foo.bar.baz\n\n\n#print prefix mynat\n\n\n\n/-\n  Structures\n-/\n\nstructure point (\u03b1 : Type u) :=\n(x : \u03b1)\n(y : \u03b1)\n\ndef pt : point \u2115 := { y := 1, x := 2 }\n\n#eval pt.y\n#eval point.y pt\n\nexample : point \u2115 := point.mk 1 2\nexample : point \u2115 := \u27e81, 2\u27e9\nexample := { point . x := 1, y := 2 }\nexample : point \u2115 := { x := 1, y := 2 }\n\nexample := { pt with x := 5 }\n\nstructure point3 (\u03b1 : Type u) extends point \u03b1 :=\n(z : \u03b1)\n\nexample : point3 \u2115 := { pt with z := 3 }\n\n\n\n/-\n  Type classes\n-/\n\n-- type classes allow us to define 0, 1, +, etc. for arbitrary objects\n#check (0 : mynat)\n#check (1 : mynat)\n#check zero + zero\n\n-- type class instances are just structures:\ninstance : has_zero mynat :=\n{ zero := mynat.zero }\n\n#print instances has_zero\n\n#check (0 : mynat)\n\ninstance : has_add mynat :=\n{ add := mynat.add }\n\n#check (0 + 0 : mynat)\n\n@[instance] -- instances are just definitions with the [instance] \"attribute\"\ndef mynat.has_one : has_one mynat :=\n\u27e8succ zero\u27e9 -- any structure instance syntax works\n\n-- now numerals work!\n#check (7 : mynat)\n\n-- type class arguments are written in square brackets\ndef double {\u03b1 : Type u} [has_add \u03b1] (x : \u03b1) :=\nx + x\n\n#check double (7 : mynat)\n\n\n\n/-\n  Logical connectives\n-/\n\nsection\n-- Variables in a section are implicitly added\n-- to all definitions/theorems/etc. (as needed)\nvariables (p q : Prop) (r : mynat \u2192 Prop)\n\n#check p \u2192 q\n#check \u2200 x, r x\n\n#check true\n#check false\n#check 0 = 1\n#check 0 = (1 : mynat)\n#check p \u2228 q\n#check \u00acq\n#check p \u2227 q\n#check p \u2194 q\n#check \u2203 x, r x\n\n#check \u2200 x < 100, \u2203 y > 20, \u2203 z \u2208 {0,1,2,3}, \u2203 w, x+y = z+w\n\nend\n\n\n\n/-\n  Tactics produce either a single new tactic state, or fail.\n\n  A tactic state is essentially a list of goals.\n-/\n\nlemma p1_1 {a b : Prop} : a \u2192 b \u2192 b \u2227 a :=\nbegin\n  intros ha hb,\n  apply and.intro,\n  assumption,\n  assumption,\nend\n\n-- we can freely mix tactics and expressions\n#check fin.mk -- (fin n) are the natural numbers less than n\nexample (n : \u2115) : fin (2*n + 7) :=\nfin.mk n (begin end)  -- failing tactics are underlined in red\n\nlemma p1_2 {a b : Prop} : a \u2192 b \u2192 b \u2227 a :=\nbegin\n  intros ha hb,\n  apply and.intro,\n  -- repeats a tactic until it fails\n  repeat { assumption },\nend\n\nlemma p1_6 {a b : Prop} : a \u2192 b \u2192 b \u2227 a :=\n-- ; executes the right tactic on all new goals\nby intros ha hb; apply and.intro; assumption\n\nlemma p2 (x : \u2115) : true \u2227 x = x :=\n-- the orelse (<|>) operator allows backtracking\nby constructor; trivial <|> refl\n\n/-\n  Rewriting\n-/\n\nlemma p3 (f : \u2115 \u2192 \u2115) (a b : \u2115) (h : f (1 * (0 + a)) = f b) : f a = f (0 + b) :=\nbegin\n-- The `rw` tactic takes a (quantified) equation and rewrites the goal using it\n  rw zero_add,\n-- You can also pass it multiple equations, and/or rewrite hypotheses\n  rw [zero_add, one_mul] at h,\n  assumption,\nend\n\n/-\n  Induction\n-/\n\nlemma mynat.zero_add {a : mynat} : 0 + a = a :=\nbegin\n  induction a,\nend\n\n\n\n/-\n  Theorems\n-/\n\nlemma mynat.add_comm (a b : mynat) : a + b = b + a :=\nbegin\nend\n\nlemma mynat.add_assoc (a b c : mynat) : a + b + c = a + (b + c) :=\nbegin\nend\n\n-- It's boring to write (a b c : mynat) every time.\nsection\nvariables (a b c : mynat)\n\nlemma mynat.eq_iff_succ_eq_succ : succ a = succ b \u2192 a = b :=\nbegin\nend\n\nlemma mynat.add_cancel_right : a + c = b + c \u2192 a = b :=\nbegin\nend\n\nend\n\n\n\n/-\n  Notations\n-/\n\nnotation `\u2115'` := mynat\n\n#check (5 : \u2115')\n\n\n-- supports various fancy stuff, e.g. mixfix operators and binders\ndef mysum {\u03b1} [has_add \u03b1] : mynat \u2192 (mynat \u2192 \u03b1) \u2192 \u03b1\n| 0 f := f 0\n| (succ a) f := mysum a f + f (succ a)\n\nlocal notation `sum` binder `until` b `of` f:(scoped x, x) :=\nmysum b f\n\n#check sum i until 10 of i+20\n#eval  sum i until 10 of i+20\n\n\n\n\n/-\n  There are two different kinds of \"truth values\":\n\n   - Prop: types, erased at runtime\n     ^^^^ this is what you use to state theorems\n\n   - bool: inductive type with values tt/ff, computable\n-/\n\n#check true \u2227 false \u2228 true\n#check tt && ff || tt\n\n-- Lean automatically converts (\"coerces\") bools into Props\n-- x  is coerced into  x = tt\nexample : (tt : Prop) := rfl\n\n-- We can convert a Prop p into a bool if it is \"decidable\",\n-- i.e. there is a function that computes whether p is true or not\n#eval (\u2200 x \u2208 [1,2,3,4], x^2 < x + 10 : bool)\n\n-- decidable is implemented as a typeclass, and you can add your own instances\n#print instances decidable\n\n-- Many definitions in Lean use decidable propositions instead of bool:\n#eval if \u2200 x \u2208 [1,2,3,4], x^2 < x + 10 then \"ok\" else \"ko\"\n#check guard $ \u2200 x \u2208 [1,2,3,4], x^2 < x + 10\n#check list.filter (\u03bb x, x^2 < x + 10)\n\n-- Choice implies that all propositions are decidable.\n-- If we mark `classical.prop_decidable` as a type-class instance,\n-- then if-then-else works on all propositions.\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n-- However we cannot execute definitions that use choice to\n-- construct data, such definitions are then marked as \"noncomputable\".\nnoncomputable def find_zero (f : \u2115 \u2192 \u2115) : \u2115 :=\nif h : \u2203 i, f i = 0 then classical.some h else 0\n\n#eval find_zero (\u03bb x, 1)\n\n\n\n/-\n  Definitional equality\n-/\n\n-- the free monoid generated by \u2115'\n#check list mynat\n#check ([1,4,3] : list mynat)\n\n-- the free monoid generated by the carrier of the free monoid generated by \u2115'\n#check list (list mynat)\n\ndef nested_list (\u03b1 : Type u) : \u2115 \u2192 Type u\n| 0     := \u03b1\n-- recursive calls only have arguments from after the colon\n| (n+1) := list (nested_list n)\n\n#reduce nested_list \u2115' 5\n\n-- Why does this work?\nexample (n : \u2115) (xs : nested_list \u2115' (n+1)) :=\nlist.length xs -- xs needs to be a (list _) here, but it's a nested_list!\n\n-- (nested_list _ (n+1)) reduces to a (list _):\n#reduce \u03bb n, nested_list \u2115' (n+1)\n-- This is called \"definitional equality\".\n-- In the underlying logic of Lean, both terms can be used interchangeably*.\n\n#reduce \u03bb n, n+1\n#reduce \u03bb n, 1+n\n\n-- We can of course write functions that return nested_list\ndef n_singleton {\u03b1 : Type u} : \u2200 n, \u03b1 \u2192 nested_list \u03b1 n\n-- in the base case, the return type is (nested_list \u03b1 0) =def= \u03b1\n| 0     a := a\n-- in the step case, the return type is\n-- (nested_list \u03b1 (n+1)) =def= (list (nested_list \u03b1 n))\n| (n+1) a := [n_singleton n a]\n\n", "meta": {"author": "gebner", "repo": "leantogether2019_tutorial", "sha": "21b4dc890f964fc98837129094b8bab68363349f", "save_path": "github-repos/lean/gebner-leantogether2019_tutorial", "path": "github-repos/lean/gebner-leantogether2019_tutorial/leantogether2019_tutorial-21b4dc890f964fc98837129094b8bab68363349f/src/01_basics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7216718695605026}}
{"text": "/-\nCopyright (c) 2022 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky, Floris van Doorn\n-/\nimport data.pnat.basic\n\n/-!\n# Explicit least witnesses to existentials on positive natural numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nImplemented via calling out to `nat.find`.\n\n-/\n\nnamespace pnat\n\nvariables {p q : \u2115+ \u2192 Prop} [decidable_pred p] [decidable_pred q] (h : \u2203 n, p n)\n\ninstance decidable_pred_exists_nat :\n  decidable_pred (\u03bb n' : \u2115, \u2203 (n : \u2115+) (hn : n' = n), p n) := \u03bb n',\ndecidable_of_iff' (\u2203 (h : 0 < n'), p \u27e8n', h\u27e9) $ subtype.exists.trans $\n  by simp_rw [subtype.coe_mk, @exists_comm (_ < _) (_ = _), exists_prop, exists_eq_left']\n\n\ninclude h\n\n/-- The `pnat` version of `nat.find_x` -/\nprotected def find_x : {n // p n \u2227 \u2200 m : \u2115+, m < n \u2192 \u00acp m} :=\nbegin\n  have : \u2203 (n' : \u2115) (n : \u2115+) (hn' : n' = n), p n, from exists.elim h (\u03bb n hn, \u27e8n, n, rfl, hn\u27e9),\n  have n := nat.find_x this,\n  refine \u27e8\u27e8n, _\u27e9, _, \u03bb m hm pm, _\u27e9,\n  { obtain \u27e8n', hn', -\u27e9 := n.prop.1,\n    rw hn',\n    exact n'.prop },\n  { obtain \u27e8n', hn', pn'\u27e9 := n.prop.1,\n    simpa [hn', subtype.coe_eta] using pn' },\n  { exact n.prop.2 m hm \u27e8m, rfl, pm\u27e9 }\nend\n\n/--\nIf `p` is a (decidable) predicate on `\u2115+` and `hp : \u2203 (n : \u2115+), p n` is a proof that\nthere exists some positive natural number satisfying `p`, then `pnat.find hp` is the\nsmallest positive natural number satisfying `p`. Note that `pnat.find` is protected,\nmeaning that you can't just write `find`, even if the `pnat` namespace is open.\n\nThe API for `pnat.find` is:\n\n* `pnat.find_spec` is the proof that `pnat.find hp` satisfies `p`.\n* `pnat.find_min` is the proof that if `m < pnat.find hp` then `m` does not satisfy `p`.\n* `pnat.find_min'` is the proof that if `m` does satisfy `p` then `pnat.find hp \u2264 m`.\n-/\nprotected def find : \u2115+ :=\npnat.find_x h\n\nprotected \n\nprotected theorem find_min : \u2200 {m : \u2115+}, m < pnat.find h \u2192 \u00acp m :=\n(pnat.find_x h).prop.right\n\nprotected theorem find_min' {m : \u2115+} (hm : p m) : pnat.find h \u2264 m :=\nle_of_not_lt (\u03bb l, pnat.find_min h l hm)\n\nvariables {n m : \u2115+}\n\nlemma find_eq_iff : pnat.find h = m \u2194 p m \u2227 \u2200 n < m, \u00ac p n :=\nbegin\n  split,\n  { rintro rfl, exact \u27e8pnat.find_spec h, \u03bb _, pnat.find_min h\u27e9 },\n  { rintro \u27e8hm, hlt\u27e9,\n    exact le_antisymm (pnat.find_min' h hm) (not_lt.1 $ imp_not_comm.1 (hlt _) $ pnat.find_spec h) }\nend\n\n@[simp] lemma find_lt_iff (n : \u2115+) : pnat.find h < n \u2194 \u2203 m < n, p m :=\n\u27e8\u03bb h2, \u27e8pnat.find h, h2, pnat.find_spec h\u27e9, \u03bb \u27e8m, hmn, hm\u27e9, (pnat.find_min' h hm).trans_lt hmn\u27e9\n\n@[simp] lemma find_le_iff (n : \u2115+) : pnat.find h \u2264 n \u2194 \u2203 m \u2264 n, p m :=\nby simp only [exists_prop, \u2190 lt_add_one_iff, find_lt_iff]\n\n@[simp] lemma le_find_iff (n : \u2115+) : n \u2264 pnat.find h \u2194 \u2200 m < n, \u00ac p m :=\nby simp_rw [\u2190 not_lt, find_lt_iff, not_exists]\n\n@[simp] lemma lt_find_iff (n : \u2115+) : n < pnat.find h \u2194 \u2200 m \u2264 n, \u00ac p m :=\nby simp only [\u2190 add_one_le_iff, le_find_iff, add_le_add_iff_right]\n\n@[simp] lemma find_eq_one : pnat.find h = 1 \u2194 p 1 :=\nby simp [find_eq_iff]\n\n@[simp] lemma one_le_find : 1 < pnat.find h \u2194 \u00ac p 1 :=\nnot_iff_not.mp $ by simp\n\ntheorem find_mono (h : \u2200 n, q n \u2192 p n)\n  {hp : \u2203 n, p n} {hq : \u2203 n, q n} :\n  pnat.find hp \u2264 pnat.find hq :=\npnat.find_min' _ (h _ (pnat.find_spec hq))\n\nlemma find_le {h : \u2203 n, p n} (hn : p n) : pnat.find h \u2264 n :=\n(pnat.find_le_iff _ _).2 \u27e8n, le_rfl, hn\u27e9\n\nlemma find_comp_succ (h : \u2203 n, p n) (h\u2082 : \u2203 n, p (n + 1)) (h1 : \u00ac p 1) :\n  pnat.find h = pnat.find h\u2082 + 1 :=\nbegin\n  refine (find_eq_iff _).2 \u27e8pnat.find_spec h\u2082, \u03bb n, pnat.rec_on n _ _\u27e9,\n  { simp [h1] },\n  intros m IH hm,\n  simp only [add_lt_add_iff_right, lt_find_iff] at hm,\n  exact hm _ le_rfl\nend\n\nend pnat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/pnat/find.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8289388167733099, "lm_q1q2_score": 0.7216718695605024}}
{"text": "import .src_field tactic\n\nnamespace mth1001\n\nnamespace myreal\n\nsection grouplaws\n\nvariables {R : Type} [comm_group R]\n\nlemma add_comm (x y : R) : x + y = y + x := comm_group.add_comm x y\nlemma add_assoc (x y z : R) : (x + y) + z = x + (y + z) := comm_group.add_assoc x y z\nlemma add_zero (x : R) : x + 0 = x := comm_group.add_zero x\nlemma zero_add (x : R) : 0 + x = x := by {rw [add_comm, add_zero]}\nlemma add_neg' (x : R) : x + (-x) = 0 := comm_group.add_inv x\nlemma neg_add (x : R) : (-x) + x = 0 := by {rw [add_comm, add_neg']}\n\ndef add_identity (u : R) := \u2200 x : R, (x + u = x) \u2227 (u + x = x)\n\nlemma add_left_eq_self_mp {x a : R} : x + a = a \u2192 x = 0 :=\nby { intro h, rw [\u2190(add_zero x), \u2190(add_neg' a), \u2190add_assoc, h] }\n\nlemma add_left_eq_self_mpr {x a : R} : x = 0 \u2192 x + a = a :=\nby { intro h, rw [h, zero_add] }\n\ntheorem add_left_eq_self (x a : R) : x + a = a \u2194 x = 0:=\niff.intro add_left_eq_self_mp add_left_eq_self_mpr\n\ntheorem add_left_inj  (x a b : R) : a + x = b + x \u2194 a = b :=\n\u27e8 \u03bb h, by rw [\u2190(add_zero a), \u2190(add_neg' x), \u2190add_assoc, h, add_assoc, add_neg' x, add_zero],\n  \u03bb h, h \u25b8 rfl\u27e9\n\nlemma sub_eq_add_neg' (x y : R) : x - y = x + (-y) := rfl \n\nlemma neg_zero : -(0 : R) = 0 :=\nby rw [\u2190add_zero (-(0 : R)), neg_add]\n\nlemma sub_zero (a : R) : a - 0 = a :=\nby rw [sub_eq_add_neg', neg_zero, add_zero]\n\ntheorem sub_eq_zero_iff_eq (x y : R) : x - y = 0 \u2194 x = y :=\nby rw [\u2190add_left_inj (y) _ _, zero_add, sub_eq_add_neg', add_assoc, neg_add, add_zero]\n\ntheorem neg_neg (x : R) : - - x = x :=\nby rw [\u2190(zero_add (- - x)), \u2190(add_neg' x), add_assoc, add_neg', add_zero]\n\nlemma neg_add_eq_neg_add_neg' (x y : R) : -(x + y) = -y + - x :=\nbegin\n  rw [\u2190add_zero (-(x+y)), \u2190add_neg' x],\n  conv in (x + -x) { congr, rw \u2190add_zero x, skip },\n  rw [\u2190add_neg' y, \u2190add_assoc x y _, add_assoc (x+y) _ _, \u2190add_assoc, neg_add, zero_add],\nend\n\nend grouplaws\n\nsection fieldlaws\n\nvariables {R : Type} [myfield R]\n\nlemma mul_comm (x y : R) : x * y = y * x := myfield.mul_comm x y\nlemma mul_assoc (x y z : R) : (x * y) * z = x * (y * z) := myfield.mul_assoc x y z\nlemma mul_one (x : R) : x * 1 = x := myfield.mul_one x\nlemma one_mul (x : R) : 1 * x = x := by { rw [mul_comm, mul_one] }\nlemma mul_inv (x : R) : x \u2260 0 \u2192 x * x\u207b\u00b9  = 1 := myfield.mul_inv x\nlemma inv_mul (x : R) : x \u2260 0 \u2192 x\u207b\u00b9 * x = 1 := by {intro h, rw [mul_comm, mul_inv x h], }\nlemma mul_add (x y z : R) : x * (y + z) = x * y + x * z := myfield.mul_add x y z\nlemma zero_ne_one : (0 : R) \u2260 (1 : R) := myfield.zero_ne_one\nlemma exists_pair_ne : \u2203 x y : R, x \u2260 y := \u27e8(0 : R), (1 : R), zero_ne_one\u27e9\n\ndef mul_identity (u : R) := \u2200 x : R, (x * u = x) \u2227 (u * x = x)\n\ntheorem add_mul (x y z : R) : (x + y) * z = x * z + y * z :=\nby { rw [mul_comm, mul_add], repeat { rw mul_comm z _ }, }\n\ntheorem mul_identity_unique {a b : R} (h\u2081 : mul_identity a) (h\u2082 : mul_identity b)  : a = b :=\nby rw [(h\u2082 a).left.symm, (h\u2081 b).right]\n\ndef mul_inverse (y x : R) := (x * y = 1) \u2227 (y * x = 1)\n\ntheorem mul_inverse_unique {a b x : R} (h\u2081 : mul_inverse a x) (h\u2082 : mul_inverse b x) : a = b :=\nby rw [\u2190mul_one a, \u2190h\u2082.left, \u2190mul_assoc, h\u2081.right, one_mul]\n\ntheorem mul_zero {x : R} : x * (0 : R) = (0 : R) :=\nbegin\n  conv {to_rhs, rw \u2190add_neg' (x*0)},\n  conv {to_rhs, congr, rw [\u2190add_zero (0 : R), mul_add], skip},\n  rw [add_assoc, add_neg', add_zero],\nend\n\ntheorem zero_mul {x : R} : (0 : R) * x = (0 : R) := (mul_comm x 0) \u25b8 mul_zero\n\ntheorem neg_one_mul (x : R) : (-1) * x = -x :=\nbegin\n  conv in ((-1)* x) { rw \u2190(add_zero ((-1)*x)) },\n  rw [\u2190(add_neg' x), \u2190add_assoc],\n  conv in ((-1)*x + x) { congr, skip, rw \u2190(one_mul x) },\n  rw [\u2190add_mul, neg_add, zero_mul, zero_add],\nend\n\nlemma neg_one_mul_neg_one : (-(1 : R)) * (-1) = 1 :=\nby rw [neg_one_mul, neg_neg]\n\nlemma neg_mul_eq_mul_neg (x y : R) : -(x * y) = x * (-y) :=\nby rw [\u2190add_zero (x * -y), \u2190add_neg' (x*y), \u2190add_assoc, \u2190mul_add, neg_add, mul_zero, zero_add]\n\nlemma neg_mul_neg_self (x : R) : (-x)*(-x) = x * x :=\nby rw [\u2190neg_one_mul, mul_assoc, mul_comm x _, \u2190mul_assoc, \u2190mul_assoc, neg_one_mul_neg_one, one_mul]\n\nlemma neg_mul_neg (x y : R) : (-x) * (-y) = x * y :=\nbegin\n  rw [\u2190neg_one_mul, mul_assoc, \u2190neg_mul_eq_mul_neg, \u2190neg_one_mul (x*y)], \n  rw [\u2190mul_assoc, neg_one_mul_neg_one, one_mul],\nend\n\nlemma one_inv : (1 : R)\u207b\u00b9 = (1 : R) :=\nby rw [\u2190(mul_one (1 : R)\u207b\u00b9), inv_mul (1 : R) (zero_ne_one.symm)]\n\ntheorem mul_sub (x y z : R) : x * (y - z) = x * y - x * z :=\nbegin\n  repeat {rw sub_eq_add_neg'},\n  rw [mul_add, neg_mul_eq_mul_neg],\nend\n\ntheorem mul_left_inj' (x a b : R) (h\u2081 : x \u2260 0): a * x = b * x \u2194 a = b :=\n\u27e8\u03bb h, by rw [\u2190(mul_one a), \u2190(mul_inv x h\u2081), \u2190mul_assoc, h, mul_assoc, mul_inv x h\u2081, mul_one],\n\u03bb h, h \u25b8 rfl \u27e9 \n\nopen_locale classical\n\nlemma eq_zero_of_not_eq_zero_of_mul_not_eq_zero (x b : R) (h\u2081 : b \u2260 0) (h\u2082 : x * b = 0) : x = 0 :=\nbegin\n  by_cases h : x = 0,\n  { exact h },\n  { rw [\u2190mul_one x, \u2190mul_inv x h, mul_comm x x\u207b\u00b9, \u2190mul_one (x * (x\u207b\u00b9 * x)), \u2190mul_inv b h\u2081],\n    rw [mul_assoc, mul_assoc, \u2190mul_assoc x b _, h\u2082, zero_mul, mul_zero, mul_zero], }\nend\n\nlemma eq_zero_or_eq_zero_of_mul_eq_zero (x y : R) (h : x * y = 0) : x = 0 \u2228 y = 0 :=\nbegin\n  by_cases k : y = 0,\n  { exact or.inr k },\n  { exact or.inl (eq_zero_of_not_eq_zero_of_mul_not_eq_zero x y k h), },\nend\n\nlemma mul_inv' (x y : R) (h\u2081 : x \u2260 0) (h\u2082 : y \u2260 0) : (x * y)\u207b\u00b9 = y\u207b\u00b9 * x\u207b\u00b9 :=\nbegin\n  have h : x * y \u2260 0 := \u03bb h, h\u2081 (eq_zero_of_not_eq_zero_of_mul_not_eq_zero _ _ h\u2082 h), \n  rw [\u2190(mul_left_inj' _ _ _ h\u2081), \u2190(mul_left_inj' _ _ _ h\u2082)],\n  rw [mul_assoc, inv_mul (x * y) h, mul_assoc _ _ x, inv_mul x h\u2081, mul_one, inv_mul y h\u2082],\nend\n\ntheorem inv_ne_zero {a : R} : a \u2260 0 \u2192 a\u207b\u00b9 \u2260 0 :=\nbegin\n  intros ane0 ainv0,\n  have : (1 : R) = (0 : R),\n  { rw [\u2190mul_inv a ane0, ainv0, mul_zero], },\n  exact zero_ne_one this.symm,\nend\n\ntheorem inv_inv' (a : R) (h : a \u2260 0 ) : (a\u207b\u00b9)\u207b\u00b9 = a :=\nby rw [\u2190one_mul (a\u207b\u00b9)\u207b\u00b9, \u2190mul_inv a h, mul_assoc, mul_inv a\u207b\u00b9 (inv_ne_zero h), mul_one]\n\nend fieldlaws\n\nsection powers\n\nvariables {R : Type} [myfield R]\n\nlemma pow_succ (x : R) (n : \u2115) : x^(n+1) = x * x^n := rfl\nlemma pow_zero (x : R) : x ^ 0 = 1 := rfl\nlemma pow_one (x : R) : x ^ 1 = x := by rw [pow_succ, pow_zero, mul_one]\nlemma pow_succ' (x : R) (n : \u2115) : x^(n+1) = x^n * x := by rw [pow_succ, mul_comm]\n\ntheorem pow_two (x : R) : x ^ 2 = x * x := by rw [pow_succ, pow_one]\n\ntheorem pow_ne_zero {x : R} (n : \u2115) (h : x \u2260 0) : x ^ n \u2260 0 :=\nbegin\n  induction n with k hk,\n  { exact (zero_ne_one.symm), },\n  { rw pow_succ',\n    intro k,\n    apply hk,\n    exact eq_zero_of_not_eq_zero_of_mul_not_eq_zero _ _ h k, },\nend\n\ntheorem pow_add (x : R) (m n : \u2115) : x ^ (m + n) = (x ^ m) * (x ^ n) :=\nbegin\n  induction n with k hk,\n  { rw [nat.add_zero, pow_zero, mul_one], },\n  { rw [nat.add_succ, pow_succ', pow_succ', hk, \u2190mul_assoc]}, \nend\n\ntheorem pow_mul (x : R) (m n : \u2115) : x ^ (m*n) = (x ^ m) ^ n :=\nbegin\n  induction n with k hk,\n  { rw [nat.mul_zero, pow_zero, pow_zero], },\n  { rw [nat.succ_eq_add_one, left_distrib, nat.mul_one, pow_add, hk,  pow_succ'], },\nend\n\ntheorem pow_sub_mul_pow (x : R) {m n : \u2115} (h : m \u2264 n) : x ^ (n - m) * x ^ m = x ^ n :=\nby rw [\u2190pow_add, nat.sub_add_cancel h]\n\ntheorem pow_sub' (x : R) (m n : \u2115) (h : m \u2264 n) (ne0 : x \u2260 0) : x ^ (n - m) = (x ^ n) * (x ^ m)\u207b\u00b9 :=\nbegin\n  have h\u2082 : x^m \u2260 0, from pow_ne_zero m ne0,\n  rw [\u2190mul_left_inj' (x^m) _ _ h\u2082, mul_assoc, inv_mul _ h\u2082, mul_one, pow_sub_mul_pow x h],\nend\n\nend powers\n\nend myreal\n\nend mth1001", "meta": {"author": "gihanmarasingha", "repo": "ems_reals", "sha": "9df527742db69d0a389add44b506538fdb4d0800", "save_path": "github-repos/lean/gihanmarasingha-ems_reals", "path": "github-repos/lean/gihanmarasingha-ems_reals/ems_reals-9df527742db69d0a389add44b506538fdb4d0800/src/library/src_field_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7216718668249843}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis is about the obvious bijection (X \\ {x}) \u2210 1 \u2243 X, or\n(option (erase a)) \u2243 \u03b1 in Lean notation.\n-/\n\nimport data.fintype.basic\n\nnamespace combinatorics\n\nvariables {\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1]\n\ndef erase (a : \u03b1) := {b : \u03b1 // b \u2260 a}\n\nnamespace erase\n\ninstance (a : \u03b1) : decidable_eq (erase a) := by { apply_instance }\ninstance (a : \u03b1) : fintype (erase a) := by { dsimp[erase], apply_instance }\n\ndef option_equiv (a : \u03b1) : option (erase a) \u2243 \u03b1 := begin\n let to_fun : option (erase a) \u2192 \u03b1 :=\n   \u03bb x, @option.cases_on (erase a) (\u03bb _, \u03b1) x a (\u03bb b,b.val),\n have to_fun_none : to_fun none = a := rfl,\n have to_fun_some : \u2200 b, to_fun (some b) = b.val := \u03bb b,rfl,\n let inv_fun : \u2200 b : \u03b1, option (erase a) := \n  \u03bb b, (if h : b = a then none else (some \u27e8b,h\u27e9)),\n have inv_fun_a : inv_fun a = none := dif_pos rfl,\n have inv_fun_not_a : \u2200 (b : \u03b1) (h : b \u2260 a), inv_fun b = some \u27e8b,h\u27e9 :=\n  \u03bb b h,dif_neg h,\n have left_inv : function.left_inverse inv_fun to_fun := \n  begin \n   rintro (_ | \u27e8b,b_ne_a\u27e9),\n   {rw[to_fun_none,inv_fun_a],},\n   {rw[to_fun_some,inv_fun_not_a],}\n  end,\n have right_inv : function.right_inverse inv_fun to_fun := \n  begin\n   intro b,\n   by_cases h : b = a,\n   {rw[h,inv_fun_a]},\n   {rw[inv_fun_not_a b h]}\n  end,\n exact \u27e8to_fun,inv_fun,left_inv,right_inv\u27e9,\nend\n\nlemma card (a : \u03b1) : fintype.card (erase a) + 1 = fintype.card \u03b1 := \n (@fintype.card_option (erase a) _).symm.trans\n   (fintype.card_congr (option_equiv a))\n\ndef inc {a : \u03b1} (b : erase a) : \u03b1 := b.val\n\ndef inc_inj (a : \u03b1) : function.injective (@inc \u03b1 _ _ a) := \n \u03bb b\u2081 b\u2082 e, subtype.eq e\n\nend erase\n\nend combinatorics", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/combinatorics/erase.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7216526470879179}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,\nNeil Strickland, Aaron Anderson\n-/\n\nimport algebra.group_with_zero.basic\n\n/-!\n# Divisibility\n\nThis file defines the basics of the divisibility relation in the context of `(comm_)` `monoid`s\n`(_with_zero)`.\n\n## Main definitions\n\n * `monoid.has_dvd`\n\n## Implementation notes\n\nThe divisibility relation is defined for all monoids, and as such, depends on the order of\n  multiplication if the monoid is not commutative. There are two possible conventions for\n  divisibility in the noncommutative context, and this relation follows the convention for ordinals,\n  so `a | b` is defined as `\u2203 c, b = a * c`.\n\n## Tags\n\ndivisibility, divides\n-/\n\nvariables {\u03b1 : Type*}\n\nsection semigroup\n\nvariables [semigroup \u03b1] {a b c : \u03b1}\n\n/-- There are two possible conventions for divisibility, which coincide in a `comm_monoid`.\n    This matches the convention for ordinals. -/\n@[priority 100]\ninstance semigroup_has_dvd : has_dvd \u03b1 :=\nhas_dvd.mk (\u03bb a b, \u2203 c, b = a * c)\n\n-- TODO: this used to not have `c` explicit, but that seems to be important\n--       for use with tactics, similar to `exists.intro`\ntheorem dvd.intro (c : \u03b1) (h : a * c = b) : a \u2223 b :=\nexists.intro c h^.symm\n\nalias dvd.intro \u2190 dvd_of_mul_right_eq\n\ntheorem exists_eq_mul_right_of_dvd (h : a \u2223 b) : \u2203 c, b = a * c := h\n\ntheorem dvd.elim {P : Prop} {a b : \u03b1} (H\u2081 : a \u2223 b) (H\u2082 : \u2200 c, b = a * c \u2192 P) : P :=\nexists.elim H\u2081 H\u2082\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\n@[trans] theorem dvd_trans : a \u2223 b \u2192 b \u2223 c \u2192 a \u2223 c\n| \u27e8d, h\u2081\u27e9 \u27e8e, h\u2082\u27e9 := \u27e8d * e, h\u2081 \u25b8 h\u2082.trans $ mul_assoc a d e\u27e9\n\nalias dvd_trans \u2190 has_dvd.dvd.trans\n\ninstance : is_trans \u03b1 (\u2223) := \u27e8\u03bb a b c, dvd_trans\u27e9\n\n@[simp] theorem dvd_mul_right (a b : \u03b1) : a \u2223 a * b := dvd.intro b rfl\n\ntheorem dvd_mul_of_dvd_left (h : a \u2223 b) (c : \u03b1) : a \u2223 b * c :=\nh.trans (dvd_mul_right b c)\n\nalias dvd_mul_of_dvd_left \u2190 has_dvd.dvd.mul_right\n\ntheorem dvd_of_mul_right_dvd (h : a * b \u2223 c) : a \u2223 c :=\n(dvd_mul_right a b).trans h\n\nsection map_dvd\n\nvariables {M N : Type*} [monoid M] [monoid N]\n\nlemma map_dvd {F : Type*} [mul_hom_class F M N] (f : F) {a b} : a \u2223 b \u2192 f a \u2223 f b\n| \u27e8c, h\u27e9 := \u27e8f c, h.symm \u25b8 map_mul f a c\u27e9\n\nlemma mul_hom.map_dvd (f : M \u2192\u2099* N) {a b} : a \u2223 b \u2192 f a \u2223 f b := map_dvd f\n\nlemma monoid_hom.map_dvd (f : M \u2192* N) {a b} : a \u2223 b \u2192 f a \u2223 f b := map_dvd f\n\nend map_dvd\n\nend semigroup\n\nsection monoid\n\nvariables [monoid \u03b1]\n\n@[refl, simp] theorem dvd_refl (a : \u03b1) : a \u2223 a := dvd.intro 1 (mul_one a)\ntheorem dvd_rfl : \u2200 {a : \u03b1}, a \u2223 a := dvd_refl\ninstance : is_refl \u03b1 (\u2223) := \u27e8dvd_refl\u27e9\n\ntheorem one_dvd (a : \u03b1) : 1 \u2223 a := dvd.intro a (one_mul a)\n\nend monoid\n\nsection comm_semigroup\n\nvariables [comm_semigroup \u03b1] {a b c : \u03b1}\n\ntheorem dvd.intro_left (c : \u03b1) (h : c * a = b) : a \u2223 b :=\ndvd.intro _ (begin rewrite mul_comm at h, apply h end)\n\nalias dvd.intro_left \u2190 dvd_of_mul_left_eq\n\ntheorem exists_eq_mul_left_of_dvd (h : a \u2223 b) : \u2203 c, b = c * a :=\ndvd.elim h (assume c, assume H1 : b = a * c, exists.intro c (eq.trans H1 (mul_comm a c)))\n\nlemma dvd_iff_exists_eq_mul_left : a \u2223 b \u2194 \u2203 c, b = c * a :=\n\u27e8exists_eq_mul_left_of_dvd, by { rintro \u27e8c, rfl\u27e9, exact \u27e8c, mul_comm _ _\u27e9, }\u27e9\n\ntheorem dvd.elim_left {P : Prop} (h\u2081 : a \u2223 b) (h\u2082 : \u2200 c, b = c * a \u2192 P) : P :=\nexists.elim (exists_eq_mul_left_of_dvd h\u2081) (assume c, assume h\u2083 : b = c * a, h\u2082 c h\u2083)\n\n@[simp] theorem dvd_mul_left (a b : \u03b1) : a \u2223 b * a := dvd.intro b (mul_comm a b)\n\ntheorem dvd_mul_of_dvd_right (h : a \u2223 b) (c : \u03b1) : a \u2223 c * b :=\nbegin rw mul_comm, exact h.mul_right _ end\n\nalias dvd_mul_of_dvd_right \u2190 has_dvd.dvd.mul_left\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\ntheorem mul_dvd_mul : \u2200 {a b c d : \u03b1}, a \u2223 b \u2192 c \u2223 d \u2192 a * c \u2223 b * d\n| a ._ c ._ \u27e8e, rfl\u27e9 \u27e8f, rfl\u27e9 := \u27e8e * f, by simp\u27e9\n\ntheorem dvd_of_mul_left_dvd (h : a * b \u2223 c) : b \u2223 c :=\ndvd.elim h (\u03bb d ceq, dvd.intro (a * d) (by simp [ceq]))\n\nend comm_semigroup\n\nsection comm_monoid\n\nvariables [comm_monoid \u03b1] {a b : \u03b1}\n\ntheorem mul_dvd_mul_left (a : \u03b1) {b c : \u03b1} (h : b \u2223 c) : a * b \u2223 a * c :=\nmul_dvd_mul (dvd_refl a) h\n\ntheorem mul_dvd_mul_right (h : a \u2223 b) (c : \u03b1) : a * c \u2223 b * c :=\nmul_dvd_mul h (dvd_refl c)\n\nend comm_monoid\n\nsection semigroup_with_zero\n\nvariables [semigroup_with_zero \u03b1] {a : \u03b1}\n\ntheorem eq_zero_of_zero_dvd (h : 0 \u2223 a) : a = 0 :=\ndvd.elim h (\u03bb c H', H'.trans (zero_mul c))\n\n/-- Given an element `a` of a commutative semigroup with zero, there exists another element whose\n    product with zero equals `a` iff `a` equals zero. -/\n@[simp] lemma zero_dvd_iff : 0 \u2223 a \u2194 a = 0 :=\n\u27e8eq_zero_of_zero_dvd, \u03bb h, by { rw h, use 0, simp }\u27e9\n\n@[simp] theorem dvd_zero (a : \u03b1) : a \u2223 0 := dvd.intro 0 (by simp)\n\nend semigroup_with_zero\n\n/-- Given two elements `b`, `c` of a `cancel_monoid_with_zero` and a nonzero element `a`,\n `a*b` divides `a*c` iff `b` divides `c`. -/\ntheorem mul_dvd_mul_iff_left [cancel_monoid_with_zero \u03b1] {a b c : \u03b1}\n  (ha : a \u2260 0) : a * b \u2223 a * c \u2194 b \u2223 c :=\nexists_congr $ \u03bb d, by rw [mul_assoc, mul_right_inj' ha]\n\n/-- Given two elements `a`, `b` of a commutative `cancel_monoid_with_zero` and a nonzero\n  element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/\ntheorem mul_dvd_mul_iff_right [cancel_comm_monoid_with_zero \u03b1] {a b c : \u03b1} (hc : c \u2260 0) :\n  a * c \u2223 b * c \u2194 a \u2223 b :=\nexists_congr $ \u03bb d, by rw [mul_right_comm, mul_left_inj' hc]\n\n/-!\n### Units in various monoids\n-/\n\nnamespace units\n\nsection monoid\nvariables [monoid \u03b1] {a b : \u03b1} {u : \u03b1\u02e3}\n\n/-- Elements of the unit group of a monoid represented as elements of the monoid\n    divide any element of the monoid. -/\nlemma coe_dvd : \u2191u \u2223 a := \u27e8\u2191u\u207b\u00b9 * a, by simp\u27e9\n\n/-- In a monoid, an element `a` divides an element `b` iff `a` divides all\n    associates of `b`. -/\nlemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\niff.intro\n  (assume \u27e8c, eq\u27e9, \u27e8c * \u2191u\u207b\u00b9, by rw [\u2190 mul_assoc, \u2190 eq, units.mul_inv_cancel_right]\u27e9)\n  (assume \u27e8c, eq\u27e9, eq.symm \u25b8 (dvd_mul_right _ _).mul_right _)\n\n/-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/\nlemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\niff.intro\n  (\u03bb \u27e8c, eq\u27e9, \u27e8\u2191u * c, eq.trans (mul_assoc _ _ _)\u27e9)\n  (\u03bb h, dvd_trans (dvd.intro \u2191u\u207b\u00b9 (by rw [mul_assoc, u.mul_inv, mul_one])) h)\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] {a b : \u03b1} {u : \u03b1\u02e3}\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\nlemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b := by { rw mul_comm, apply dvd_mul_right }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\nlemma mul_left_dvd : \u2191u * a \u2223 b \u2194 a \u2223 b :=\nby { rw mul_comm, apply mul_right_dvd }\n\nend comm_monoid\n\nend units\n\nnamespace is_unit\n\nsection monoid\n\nvariables [monoid \u03b1] {a b u : \u03b1} (hu : is_unit u)\ninclude hu\n\n/-- Units of a monoid divide any element of the monoid. -/\n@[simp] lemma dvd : u \u2223 a := by { rcases hu with \u27e8u, rfl\u27e9, apply units.coe_dvd, }\n\n@[simp] lemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_right, }\n\n/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/\n@[simp] lemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_right_dvd, }\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] (a b u : \u03b1) (hu : is_unit u)\ninclude hu\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\n@[simp] lemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_left, }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\n@[simp] lemma mul_left_dvd : u * a \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_left_dvd, }\n\nend comm_monoid\n\nend is_unit\n\nsection comm_monoid\nvariables [comm_monoid \u03b1]\n\ntheorem is_unit_iff_dvd_one {x : \u03b1} : is_unit x \u2194 x \u2223 1 :=\n\u27e8by rintro \u27e8u, rfl\u27e9; exact \u27e8_, u.mul_inv.symm\u27e9,\n \u03bb \u27e8y, h\u27e9, \u27e8\u27e8x, y, h.symm, by rw [h, mul_comm]\u27e9, rfl\u27e9\u27e9\n\ntheorem is_unit_iff_forall_dvd {x : \u03b1} :\n  is_unit x \u2194 \u2200 y, x \u2223 y :=\nis_unit_iff_dvd_one.trans \u27e8\u03bb h y, h.trans (one_dvd _), \u03bb h, h _\u27e9\n\ntheorem is_unit_of_dvd_unit {x y : \u03b1}\n  (xy : x \u2223 y) (hu : is_unit y) : is_unit x :=\nis_unit_iff_dvd_one.2 $ xy.trans $ is_unit_iff_dvd_one.1 hu\n\nlemma is_unit_of_dvd_one : \u2200a \u2223 1, is_unit (a:\u03b1)\n| a \u27e8b, eq\u27e9 := \u27e8units.mk_of_mul_eq_one a b eq.symm, rfl\u27e9\n\nlemma not_is_unit_of_not_is_unit_dvd {a b : \u03b1} (ha : \u00acis_unit a) (hb : a \u2223 b) :\n  \u00ac is_unit b :=\nmt (is_unit_of_dvd_unit hb) ha\n\nend comm_monoid\n\nsection comm_monoid_with_zero\n\nvariable [comm_monoid_with_zero \u03b1]\n\n/-- `dvd_not_unit a b` expresses that `a` divides `b` \"strictly\", i.e. that `b` divided by `a`\nis not a unit. -/\ndef dvd_not_unit (a b : \u03b1) : Prop := a \u2260 0 \u2227 \u2203 x, \u00acis_unit x \u2227 b = a * x\n\nlemma dvd_not_unit_of_dvd_of_not_dvd {a b : \u03b1} (hd : a \u2223 b) (hnd : \u00ac b \u2223 a) :\n  dvd_not_unit a b :=\nbegin\n  split,\n  { rintro rfl, exact hnd (dvd_zero _) },\n  { rcases hd with \u27e8c, rfl\u27e9,\n    refine \u27e8c, _, rfl\u27e9,\n    rintro \u27e8u, rfl\u27e9,\n    simpa using hnd }\nend\n\nend comm_monoid_with_zero\n\nlemma dvd_and_not_dvd_iff [cancel_comm_monoid_with_zero \u03b1] {x y : \u03b1} :\n  x \u2223 y \u2227 \u00acy \u2223 x \u2194 dvd_not_unit x y :=\n\u27e8\u03bb \u27e8\u27e8d, hd\u27e9, hyx\u27e9, \u27e8\u03bb hx0, by simpa [hx0] using hyx, \u27e8d,\n    mt is_unit_iff_dvd_one.1 (\u03bb \u27e8e, he\u27e9, hyx \u27e8e, by rw [hd, mul_assoc, \u2190 he, mul_one]\u27e9), hd\u27e9\u27e9,\n  \u03bb \u27e8hx0, d, hdu, hdx\u27e9, \u27e8\u27e8d, hdx\u27e9, \u03bb \u27e8e, he\u27e9, hdu (is_unit_of_dvd_one _\n    \u27e8e, mul_left_cancel\u2080 hx0 $ by conv {to_lhs, rw [he, hdx]};simp [mul_assoc]\u27e9)\u27e9\u27e9\n\nsection monoid_with_zero\n\nvariable [monoid_with_zero \u03b1]\n\ntheorem ne_zero_of_dvd_ne_zero {p q : \u03b1} (h\u2081 : q \u2260 0)\n  (h\u2082 : p \u2223 q) : p \u2260 0 :=\nbegin\n  rcases h\u2082 with \u27e8u, rfl\u27e9,\n  exact left_ne_zero_of_mul h\u2081,\nend\n\nend monoid_with_zero\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.721641597438168}}
{"text": "/-\nAbove, we used the example vec \u03b1 n for vectors of elements of type \u03b1 of length n. \nDeclare a constant vec_add that could represent a function that adds two vectors of natural numbers of the same length, \nand a constant vec_reverse that can represent a function that reverses its argument. \nUse implicit arguments for parameters that can be inferred. \nDeclare some variables and check some expressions involving the constants that you have declared.\n-/\n\nuniverse u\nconstant vec : Type u \u2192 \u2115 \u2192 Type u\n\nnamespace vec\n  constant empty : \u03a0 \u03b1 : Type u, vec \u03b1 0\n  constant cons :\n    \u03a0 (\u03b1 : Type u) (n : \u2115), \u03b1 \u2192 vec \u03b1 n \u2192 vec \u03b1 (n + 1)\n  constant append :\n    \u03a0 (\u03b1 : Type u) (n m : \u2115),  vec \u03b1 m \u2192 vec \u03b1 n \u2192 vec \u03b1 (n + m)\n  constant add :\n    \u03a0 (\u03b1 : Type u) (n : \u2115), vec \u03b1 n \u2192 vec \u03b1 n \u2192 vec \u03b1 n\n  const reverse :\n    \u03a0 (\u03b1 : Type u) (n : \u2115), vec \u03b1 n \u2192 vec \u03b1 n\nend vec\n", "meta": {"author": "ndcroos", "repo": "lean-snippets", "sha": "b66736347cd80a4143e43397f359dbdf9cbcd491", "save_path": "github-repos/lean/ndcroos-lean-snippets", "path": "github-repos/lean/ndcroos-lean-snippets/lean-snippets-b66736347cd80a4143e43397f359dbdf9cbcd491/theorem-proving-in-lean/2.10.3 vector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7215836000888803}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module data.set.intervals.ord_connected_component\n! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Intervals.OrdConnected\nimport Mathlib.Tactic.SwapVar\n/-!\n# Order connected components of a set\n\nIn this file we define `Set.ordConnectedComponent s x` to be the set of `y` such that\n`Set.uIcc x y \u2286 s` and prove some basic facts about this definition. At the moment of writing,\nthis construction is used only to prove that any linear order with order topology is a T\u2085 space,\nso we only add API needed for this lemma.\n-/\n\n\nopen Interval Function OrderDual\n\nnamespace Set\n\nvariable {\u03b1 : Type _} [LinearOrder \u03b1] {s t : Set \u03b1} {x y z : \u03b1}\n\n/-- Order-connected component of a point `x` in a set `s`. It is defined as the set of `y` such that\n`Set.uIcc x y \u2286 s`. Note that it is empty if and only if `x \u2209 s`. -/\ndef ordConnectedComponent (s : Set \u03b1) (x : \u03b1) : Set \u03b1 :=\n  { y | [[x, y]] \u2286 s }\n#align set.ord_connected_component Set.ordConnectedComponent\n\ntheorem mem_ordConnectedComponent : y \u2208 ordConnectedComponent s x \u2194  [[x, y]] \u2286 s :=\n  Iff.rfl\n#align set.mem_ord_connected_component Set.mem_ordConnectedComponent\n\ntheorem dual_ordConnectedComponent :\n    ordConnectedComponent (ofDual \u207b\u00b9' s) (toDual x) = ofDual \u207b\u00b9' ordConnectedComponent s x :=\n  ext <|\n      (Surjective.forall toDual.surjective).2 fun x =>\n      by\n      rw [mem_ordConnectedComponent, dual_uIcc]\n      rfl\n#align set.dual_ord_connected_component Set.dual_ordConnectedComponent\n\ntheorem ordConnectedComponent_subset : ordConnectedComponent s x \u2286 s := fun _ hy =>\n  hy right_mem_uIcc\n#align set.ord_connected_component_subset Set.ordConnectedComponent_subset\n\ntheorem subset_ordConnectedComponent {t} [h : OrdConnected s] (hs : x \u2208 s) (ht : s \u2286 t) :\n    s \u2286 ordConnectedComponent t x := fun _ hy => (h.uIcc_subset hs hy).trans ht\n#align set.subset_ord_connected_component Set.subset_ordConnectedComponent\n\n@[simp]\ntheorem self_mem_ordConnectedComponent : x \u2208 ordConnectedComponent s x \u2194 x \u2208 s := by\n  rw [mem_ordConnectedComponent, uIcc_self, singleton_subset_iff]\n#align set.self_mem_ord_connected_component Set.self_mem_ordConnectedComponent\n\n@[simp]\ntheorem nonempty_ordConnectedComponent : (ordConnectedComponent s x).Nonempty \u2194 x \u2208 s :=\n  \u27e8fun \u27e8_, hy\u27e9 => hy <| left_mem_uIcc, fun h => \u27e8x, self_mem_ordConnectedComponent.2 h\u27e9\u27e9\n#align set.nonempty_ord_connected_component Set.nonempty_ordConnectedComponent\n\n@[simp]\n\n\n@[simp]\ntheorem ordConnectedComponent_empty : ordConnectedComponent \u2205 x = \u2205 :=\n  ordConnectedComponent_eq_empty.2 (not_mem_empty x)\n#align set.ord_connected_component_empty Set.ordConnectedComponent_empty\n\n@[simp]\ntheorem ordConnectedComponent_univ : ordConnectedComponent univ x = univ := by\n  simp [ordConnectedComponent]\n#align set.ord_connected_component_univ Set.ordConnectedComponent_univ\n\ntheorem ordConnectedComponent_inter (s t : Set \u03b1) (x : \u03b1) :\n    ordConnectedComponent (s \u2229 t) x = ordConnectedComponent s x \u2229 ordConnectedComponent t x := by\n  simp [ordConnectedComponent, setOf_and]\n#align set.ord_connected_component_inter Set.ordConnectedComponent_inter\n\ntheorem mem_ordConnectedComponent_comm :\n    y \u2208 ordConnectedComponent s x \u2194 x \u2208 ordConnectedComponent s y := by\n  rw [mem_ordConnectedComponent, mem_ordConnectedComponent, uIcc_comm]\n#align set.mem_ord_connected_component_comm Set.mem_ordConnectedComponent_comm\n\ntheorem mem_ordConnectedComponent_trans (hxy : y \u2208 ordConnectedComponent s x)\n    (hyz : z \u2208 ordConnectedComponent s y) : z \u2208 ordConnectedComponent s x :=\n  calc\n    [[x, z]] \u2286 [[x, y]] \u222a [[y, z]] := uIcc_subset_uIcc_union_uIcc\n    _ \u2286 s := union_subset hxy hyz\n\n#align set.mem_ord_connected_component_trans Set.mem_ordConnectedComponent_trans\n\ntheorem ordConnectedComponent_eq (h : [[x, y]] \u2286 s) :\n    ordConnectedComponent s x = ordConnectedComponent s y :=\n  ext fun _ =>\n    \u27e8mem_ordConnectedComponent_trans (mem_ordConnectedComponent_comm.2 h),\n      mem_ordConnectedComponent_trans h\u27e9\n#align set.ord_connected_component_eq Set.ordConnectedComponent_eq\n\ninstance : OrdConnected (ordConnectedComponent s x) :=\n  ordConnected_of_uIcc_subset_left fun _ hy _ hz => (uIcc_subset_uIcc_left hz).trans hy\n\n/-- Projection from `s : Set \u03b1` to `\u03b1` sending each order connected component of `s` to a single\npoint of this component. -/\nnoncomputable def ordConnectedProj (s : Set \u03b1) : s \u2192 \u03b1 := fun x : s =>\n  (nonempty_ordConnectedComponent.2 x.2).some\n#align set.ord_connected_proj Set.ordConnectedProj\n\ntheorem ordConnectedProj_mem_ordConnectedComponent (s : Set \u03b1) (x : s) :\n    ordConnectedProj s x \u2208 ordConnectedComponent s x :=\n  Nonempty.some_mem _\n#align set.ord_connected_proj_mem_ord_connected_component Set.ordConnectedProj_mem_ordConnectedComponent\n\ntheorem mem_ordConnectedComponent_ordConnectedProj (s : Set \u03b1) (x : s) :\n    \u2191x \u2208 ordConnectedComponent s (ordConnectedProj s x) :=\n  mem_ordConnectedComponent_comm.2 <| ordConnectedProj_mem_ordConnectedComponent s x\n#align set.mem_ord_connected_component_ord_connected_proj Set.mem_ordConnectedComponent_ordConnectedProj\n\n@[simp]\ntheorem ordConnectedComponent_ordConnectedProj (s : Set \u03b1) (x : s) :\n    ordConnectedComponent s (ordConnectedProj s x) = ordConnectedComponent s x :=\n  ordConnectedComponent_eq <| mem_ordConnectedComponent_ordConnectedProj _ _\n#align set.ord_connected_component_ord_connected_proj Set.ordConnectedComponent_ordConnectedProj\n\n@[simp]\ntheorem ordConnectedProj_eq {x y : s} :\n    ordConnectedProj s x = ordConnectedProj s y \u2194 [[(x : \u03b1), y]] \u2286 s := by\n  constructor <;> intro h\n  \u00b7 rw [\u2190 mem_ordConnectedComponent, \u2190 ordConnectedComponent_ordConnectedProj, h,\n      ordConnectedComponent_ordConnectedProj, self_mem_ordConnectedComponent]\n    exact y.2\n  \u00b7 simp only [ordConnectedProj, ordConnectedComponent_eq h]\n#align set.ord_connected_proj_eq Set.ordConnectedProj_eq\n\n/-- A set that intersects each order connected component of a set by a single point. Defined as the\nrange of `Set.ordConnectedProj s`. -/\ndef ordConnectedSection (s : Set \u03b1) : Set \u03b1 :=\n  range <| ordConnectedProj s\n#align set.ord_connected_section Set.ordConnectedSection\n\ntheorem dual_ordConnectedSection (s : Set \u03b1) :\n    ordConnectedSection (ofDual \u207b\u00b9' s) = ofDual \u207b\u00b9' ordConnectedSection s := by\n  simp_rw [ordConnectedSection, ordConnectedProj]\n  ext x\n  simp [dual_ordConnectedComponent]\n  tauto\n\n#align set.dual_ord_connected_section Set.dual_ordConnectedSection\n\ntheorem ordConnectedSection_subset : ordConnectedSection s \u2286 s :=\n  range_subset_iff.2 fun _ => ordConnectedComponent_subset <| Nonempty.some_mem _\n#align set.ord_connected_section_subset Set.ordConnectedSection_subset\n\ntheorem eq_of_mem_ordConnectedSection_of_uIcc_subset (hx : x \u2208 ordConnectedSection s)\n    (hy : y \u2208 ordConnectedSection s) (h : [[x, y]] \u2286 s) : x = y := by\n  rcases hx with \u27e8x, rfl\u27e9; rcases hy with \u27e8y, rfl\u27e9\n  exact\n    ordConnectedProj_eq.2\n      (mem_ordConnectedComponent_trans\n        (mem_ordConnectedComponent_trans (ordConnectedProj_mem_ordConnectedComponent _ _) h)\n        (mem_ordConnectedComponent_ordConnectedProj _ _))\n#align set.eq_of_mem_ord_connected_section_of_uIcc_subset\n  Set.eq_of_mem_ordConnectedSection_of_uIcc_subset\n\n/-- Given two sets `s t : Set \u03b1`, the set `Set.orderSeparatingSet s t` is the set of points that\nbelong both to some `Set.ordConnectedComponent t\u1d9c x`, `x \u2208 s`, and to some\n`Set.ordConnectedComponent s\u1d9c x`, `x \u2208 t`. In the case of two disjoint closed sets, this is the\nunion of all open intervals $(a, b)$ such that their endpoints belong to different sets. -/\ndef ordSeparatingSet (s t : Set \u03b1) : Set \u03b1 :=\n  (\u22c3 x \u2208 s, ordConnectedComponent (t\u1d9c) x) \u2229 \u22c3 x \u2208 t, ordConnectedComponent (s\u1d9c) x\n#align set.ord_separating_set Set.ordSeparatingSet\n\ntheorem ordSeparatingSet_comm (s t : Set \u03b1) : ordSeparatingSet s t = ordSeparatingSet t s :=\n  inter_comm _ _\n#align set.ord_separating_set_comm Set.ordSeparatingSet_comm\n\ntheorem disjoint_left_ordSeparatingSet : Disjoint s (ordSeparatingSet s t) :=\n  Disjoint.inter_right' _ <|\n    disjoint_union\u1d62\u2082_right.2 fun _ _ =>\n      disjoint_compl_right.mono_right <| ordConnectedComponent_subset\n#align set.disjoint_left_ord_separating_set Set.disjoint_left_ordSeparatingSet\n\ntheorem disjoint_right_ordSeparatingSet : Disjoint t (ordSeparatingSet s t) :=\n  ordSeparatingSet_comm t s \u25b8 disjoint_left_ordSeparatingSet\n#align set.disjoint_right_ord_separating_set Set.disjoint_right_ordSeparatingSet\n\ntheorem dual_ordSeparatingSet :\n    ordSeparatingSet (ofDual \u207b\u00b9' s) (ofDual \u207b\u00b9' t) = ofDual \u207b\u00b9' ordSeparatingSet s t := by\n  simp only [ordSeparatingSet, mem_preimage, \u2190 toDual.surjective.union\u1d62_comp, ofDual_toDual,\n    dual_ordConnectedComponent, \u2190 preimage_compl, preimage_inter, preimage_union\u1d62]\n#align set.dual_ord_separating_set Set.dual_ordSeparatingSet\n\n/-- An auxiliary neighborhood that will be used in the proof of `OrderTopology.t5Space`. -/\ndef ordT5Nhd (s t : Set \u03b1) : Set \u03b1 :=\n  \u22c3 x \u2208 s, ordConnectedComponent (t\u1d9c \u2229 (ordConnectedSection <| ordSeparatingSet s t)\u1d9c) x\n#align set.ord_t5_nhd Set.ordT5Nhd\n\ntheorem disjoint_ordT5Nhd : Disjoint (ordT5Nhd s t) (ordT5Nhd t s) := by\n  rw [disjoint_iff_inf_le]\n  rintro x \u27e8hx\u2081, hx\u2082\u27e9\n  rcases mem_union\u1d62\u2082.1 hx\u2081 with \u27e8a, has, ha\u27e9\n  clear hx\u2081\n  rcases mem_union\u1d62\u2082.1 hx\u2082 with \u27e8b, hbt, hb\u27e9\n  clear hx\u2082\n  rw [mem_ordConnectedComponent, subset_inter_iff] at ha hb\n  cases' le_total a b with hab hab\n  on_goal 2 => swap_var a \u2194 b, s \u2194 t, ha \u2194 hb, has \u2194 hbt\n  all_goals\n-- porting note: wlog not implemented yet, the following replaces the three previous lines\n-- wlog (discharger := tactic.skip) hab : a \u2264 b := le_total a b using a b s t, b a t s\n    cases' ha with ha ha'\n    cases' hb with hb hb'\n    have hsub : [[a, b]] \u2286 (ordSeparatingSet s t).ordConnectedSection\u1d9c :=\n      by\n      rw [ordSeparatingSet_comm, uIcc_comm] at hb'\n      calc\n        [[a, b]] \u2286 [[a, x]] \u222a [[x, b]] := uIcc_subset_uIcc_union_uIcc\n        _ \u2286 (ordSeparatingSet s t).ordConnectedSection\u1d9c := union_subset ha' hb'\n    clear ha' hb'\n    cases' le_total x a with hxa hax\n    \u00b7 exact hb (Icc_subset_uIcc' \u27e8hxa, hab\u27e9) has\n    cases' le_total b x with hbx hxb\n    \u00b7 exact ha (Icc_subset_uIcc \u27e8hab, hbx\u27e9) hbt\n    have h' : x \u2208 ordSeparatingSet s t := \u27e8mem_union\u1d62\u2082.2 \u27e8a, has, ha\u27e9, mem_union\u1d62\u2082.2 \u27e8b, hbt, hb\u27e9\u27e9\n    -- porting note: lift not implemented yet\n    -- lift x to ordSeparatingSet s t using this\n    suffices : ordConnectedComponent (ordSeparatingSet s t) x \u2286 [[a, b]]\n    exact hsub (this <| ordConnectedProj_mem_ordConnectedComponent _ \u27e8x, h'\u27e9) (mem_range_self _)\n    rintro y (hy : [[x, y]] \u2286 ordSeparatingSet s t)\n    rw [uIcc_of_le hab, mem_Icc, \u2190 not_lt, \u2190 not_lt]\n    have sol1 := fun (hya : y < a) =>\n        (disjoint_left (t := ordSeparatingSet s t)).1 disjoint_left_ordSeparatingSet has\n          (hy <| Icc_subset_uIcc' \u27e8hya.le, hax\u27e9)\n    have sol2 := fun (hby : b < y) =>\n        (disjoint_left (t := ordSeparatingSet s t)).1 disjoint_right_ordSeparatingSet hbt\n          (hy <| Icc_subset_uIcc \u27e8hxb, hby.le\u27e9)\n    exact \u27e8sol1, sol2\u27e9\n#align set.disjoint_ord_t5_nhd Set.disjoint_ordT5Nhd\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Intervals/OrdConnectedComponent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7215646968583906}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport data.int.basic\nimport tactic.linear_combination\nimport tactic.linarith\n\n/- \n# Quotients in Lean \n\nUpon request, let's try to see how to construct number systems like the integers or the \nrational numbers in Lean. Note that this is again some mathematical way to do this, not the \nactual way, e.g. integers are defined as the disjoint union of \u2115 with itself, where the first \ncopy is interpreted as the usual natural numbers while the second copy is interpreted as the \nnumbers `1-n` where `n : \u2115`. Similarly, \u211a is contructed as pairs of coprime integers (p,q). \nThis makes them computationally a bit better behaved than our quotient way. \n\n## Equivalence relations in Lean\n\nLean knows what an equivalence relation is. It is a reflexive, symmetric and transitive relation. \nA relation on a set `X` is a function `X \u2192 X \u2192 Prop`, i.e. a function that takes two elements \nof a set `X` and outputs a truth value depending whether they are related or not. \n\n```\ndef reflexive := \u2200 x, x \u223c x\n\ndef symmetric := \u2200 \u2983x y\u2984, x \u223c y \u2192 y \u223c x\n\ndef transitive := \u2200 \u2983x y z\u2984, x \u223c y \u2192 y \u223c m z \u2192 x \u223c z\n\ndef equivalence := reflexive r \u2227 symmetric r \u2227 transitive r\n```\n\n-/\n\ndef R (r s : \u2115 \u00d7 \u2115 ) : Prop := \nr.1+s.2=s.1+r.2\n\nlemma R_def (r s : \u2115 \u00d7 \u2115) :\nR r s \u2194 r.1 + s.2 = s.1 + r.2 := by refl\n\nlemma R_refl : reflexive R :=\n\u03bb r, by rw R_def\n\nlemma R_symm : symmetric R :=\nbegin\n  intros r s hrs,\n  rw R_def at *,\n  exact hrs.symm,\nend \n\nlemma R_trans : transitive R :=\nbegin\n  intros r s t hrs hst,\n  rw R_def at *,\n  rw \u2190 add_right_inj s.snd,\n  linarith,\nend \n\nlemma R_equiv : equivalence R :=\nbegin \n  exact \u27e8R_refl, R_symm, R_trans\u27e9,\nend\n\n\n/- A setoid on a Type is a relation together with the fact that \n  this relation is an equivalence relation. -/\ninstance s : setoid (\u2115 \u00d7 \u2115) :=\n{ r := R,\n  iseqv := R_equiv }\n\nstructure int_plane_non_zero :=\n(fst : \u2124) (snd : \u2124) (non_zero : snd \u2260 0)\n\ndef S (r s : int_plane_non_zero) : Prop :=\nr.1 * s.2 = s.1 * r.2\n\nlemma S_def (r s : int_plane_non_zero) : \nS r s \u2194 r.1 * s.2 = s.1 * r.2 := by refl\n\nlemma S_refl : reflexive S :=\n\u03bb r, by rw S_def\n\nlemma S_symm : symmetric S :=\nbegin\n  intros r s hrs,\n  rw S_def at *,\n  exact hrs.symm,\nend\n\nlemma S_trans : transitive S :=\nbegin\n  intros r s t hrs hst,\n  rw S_def at *,\n  rw \u2190 mul_right_inj' (s.non_zero),\n  linear_combination t.snd * hrs + r.snd * hst,\nend \n\nlemma S_equiv : equivalence S := \nbegin \n  exact \u27e8S_refl, S_symm, S_trans\u27e9, \nend\n\ninstance t : setoid (int_plane_non_zero) :=\n{ r := S,\n  iseqv := S_equiv }", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/solutions/sheet07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.7215646901023384}}
{"text": "import data.nat.basic\nimport data.nat.modeq\n\nimport ent.basic\nimport ent.gcd\nimport ent.modeq\nimport ent.parity\n\nset_option max_memory 4096\n\nopen nat\n\nsection pyth\n  parameters a b c : \u2115\n  parameter py : a^2 + b^2 = c^2\n  include a b c py\n\n  lemma not_both_odd : not (odd a \u2227 odd b) :=\n    begin\n      intro oab,\n      cases oab with oa ob,\n      have ha : a^2 \u2261 1 [MOD 4] := odd_square_mod_four oa,\n      have hb : b^2 \u2261 1 [MOD 4] := odd_square_mod_four ob,\n      have hc : c^2 \u2261 2 [MOD 4] := begin\n        rw \u2190py, apply modeq.modeq_add; assumption end,\n      apply (@square_two_mod_four c), assumption\n    end\n\n  lemma at_least_one_even : even a \u2228 even b :=\n    begin\n      cases even_or_odd a,\n      { apply or.inl, assumption },\n      { cases even_or_odd b,\n        { apply or.inr, assumption },\n        { have := and.intro \u2039odd a\u203a \u2039odd b\u203a,\n          have := not_both_odd,\n          contradiction } }\n    end\n\n  parameter a_b : coprime a b\n  include a_b\n\n  lemma not_both_even : \u00ac (even a \u2227 even b) := begin\n    intros H,\n    cases H with a_even b_even,\n    rw even_iff_two_dvd at a_even b_even,\n    have := not_coprime_of_dvd_of_dvd dec_trivial a_even b_even,\n    contradiction\n  end\n\n  -- Need this later, so prove it before assumption \"even b\"\n  lemma c_odd : odd c := begin\n    have : odd (a^2 + b^2) := begin\n      cases even_or_odd a with a_even a_odd,\n      { cases even_or_odd b with b_even b_odd,\n        { have := not_both_even,\n          have := and.intro a_even b_even,\n          contradiction },\n        { apply even_plus_odd_is_odd,\n          apply even_square_is_even, assumption,\n          apply odd_square_is_odd, assumption } },\n      { cases even_or_odd b with b_even b_odd,\n        { apply odd_plus_even_is_odd,\n          apply odd_square_is_odd, assumption,\n          apply even_square_is_even, assumption },\n        { have := not_both_odd,\n          have := and.intro a_odd b_odd,\n          contradiction } }\n    end,\n    rw py at this,\n    cases even_or_odd c with c_even c_odd,\n    { exact absurd (and.intro (even_square_is_even c_even) this)\n                   (not_even_and_odd _) },\n    { assumption }\n  end\n\n  parameter b_even : even b\n  include b_even\n\n  lemma a_odd : odd a := begin\n    cases even_or_odd a with a_even _,\n    { have := and.intro a_even b_even,\n      have := not_both_even,\n      contradiction },\n    assumption\n  end\n\n/-\n  lemma c_odd : odd c := begin\n    cases even_or_odd c with c_even _,\n    { refine absurd (and.intro _ _) (not_even_and_odd (c^2)),\n      exact even_square_is_even c_even,\n      rw \u2190py,\n      apply odd_plus_even_is_odd,\n      exact odd_square_is_odd a_odd,\n      exact even_square_is_even b_even\n    },\n    assumption\n  end\n-/\n\n  lemma a_c : coprime a c :=\n    -- a^2 _|_ b^2 and so a^2 _|_ a^2 + b^2 = c^2 and then a _|_ c by divisibility.\n    begin\n      have a2_c2 : gcd (a*a) (c*c) = 1 := calc\n        gcd (a*a) (c*c) = gcd (a^2) (c^2)           : by rw [nat.pow_two, nat.pow_two]\n        ...             = gcd (a^2) (a^2 + b^2)     : by rw py\n        ...             = gcd (a^2) (a^2 * 1 + b^2) : by simp\n        ...             = gcd (a^2) (b^2)           : by rw gcd.gcd_row_op (a^2) (b^2) 1\n        ...             = 1                         : coprime.pow 2 2 a_b,\n      exact coprime.coprime_mul_left (coprime.coprime_mul_left_right a2_c2)\n    end\n\n  parameter pos : a > 0 \u2227 b > 0 \u2227 c > 0\n  include pos\n\n  lemma a_lt_c : a < c := begin\n    cases nat.lt_or_ge a c with _ ge,\n    { assumption },\n    { have b2pos : b^2 > 0 := begin\n        rw nat.pow_two,\n        exact nat.mul_self_lt_mul_self_iff.mp pos.2.1\n      end,\n      have : a^2 < a^2 :=\n      calc a^2 < a^2 + b^2  : nat.lt_add_of_pos_right b2pos\n           ... = c^2        : by rw py\n           ... = c*c        : by rw nat.pow_two\n           ... \u2264 a*a        : nat.mul_self_le_mul_self_iff.mp ge\n           ... = a^2        : by rw nat.pow_two,\n      exact absurd this (not_lt_of_ge (le_refl (a^2)))\n      }\n  end\n  lemma a_le_c : a \u2264 c := le_of_lt a_lt_c\n\n  lemma cma_cpa_b2 : (c - a) * (c + a) = b^2 :=\n    calc (c - a) * (c + a) = c^2 - a^2  : by rw [mul_comm, \u2190nat.mul_self_sub_mul_self_eq, nat.pow_two, nat.pow_two]\n         ...               = a^2 + b^2 - a^2  : by rw py\n         ...               = b^2  : by rw nat.add_sub_cancel_left\n\n  -- local attribute [simp] add_comm add_left_comm add_assoc\n  local attribute [simp] mul_comm mul_left_comm mul_assoc\n\n  -- XXX: m > n?\n  lemma ex : \u2203 m n : \u2115, m > 0 \u2227 n > 0 \u2227 n < m \u2227 coprime m n \u2227\n                        a = m^2 - n^2 \u2227 b = 2 * m * n \u2227 c = m^2 + n^2 :=\n  begin\n    have gac : gcd (c - a) (c + a) = 2 :=\n      gcd.sum_difference_of_coprime_odd a c a_le_c a_c a_odd c_odd,\n/-\n    cases @exists_coprime (c - a) (c + a) (gac.symm \u25b8 (dec_trivial : 2 > 0)) with x H,\n    cases H with y H',\n    cases H' with x_y H'',\n    cases H'' with hx hy,\n-/\n    rcases @exists_coprime (c - a) (c + a) (gac.symm \u25b8 (dec_trivial : 2 > 0)) with \u27e8x, y, x_y, hx, hy\u27e9,\n    have g := cma_cpa_b2,\n    rw gac at hx hy,\n    rw [hx, hy] at g,\n    cases modeq.rep_of_modeq b_even dec_trivial with half_b Hb,\n    simp at Hb,\n    have : 2 * 2 * (x * y) = 2 * 2 * half_b^2 :=\n      calc 2 * 2 * (x * y) = x * 2 * (y * 2)  : by simp\n           ...             = b^2              : g\n           ...             = (half_b * 2)^2   : by rw Hb\n           ...             = (half_b * 2) * (half_b * 2)  : by rw nat.pow_two\n           ...             = 2 * 2 * half_b^2 : by simp [nat.pow_two],\n    have xyb : x * y = half_b^2 := nat.eq_of_mul_eq_mul_left dec_trivial this,\n    cases coprime_square_product xyb x_y with n H5,\n    cases H5 with m H6,\n    cases H6 with xn2 ym2,\n    existsi [m, n],\n    have cma : c - a = 2 * n^2 := by rw [hx, mul_comm, xn2],\n    have cpa : c + a = 2 * m^2 := by rw [hy, mul_comm, ym2],\n    have twoa : 2 * a = 2 * (m^2 - n^2) :=\n    calc 2 * a = (c + a) - (c - a)  : by rw gcd.sum_difference_difference a_le_c\n         ...   = 2 * (m^2 - n^2)    : by simp [cma, cpa, nat.mul_sub_left_distrib],\n    have twoc : 2 * c = 2 * (m^2 + n^2) :=\n    calc 2 * c = (c - a) + (c + a)  : by rw gcd.sum_difference_sum a_le_c\n         ...   = 2 * (m^2 + n^2)    : by simp [cma, cpa, left_distrib],\n    repeat { split },\n    { apply pos_iff_ne_zero.mpr, intro m0,\n      have :=\n      calc 0 = 0^2  : rfl\n         ... = m^2  : by rw m0\n         ... = y    : ym2.symm,\n      have :=\n      calc 0 = x * 2 * (0 * 2)  : by simp\n         ... = x * 2 * (y * 2)  : by rw this\n         ... = b^2  : g\n         ... > 0    : pow_lt_pow_of_lt_left pos.2.1 (dec_trivial : 2 > 0),\n      exact absurd this (lt_irrefl _)\n    },\n    { apply pos_iff_ne_zero.mpr, intro n0,\n      have :=\n      calc 0 = 0^2  : rfl\n         ... = n^2  : by rw n0\n         ... = x    : xn2.symm,\n      have :=\n      calc 0 = 0 * 2 * (y * 2)  : by simp\n         ... = x * 2 * (y * 2)  : by rw this\n         ... = b^2  : g\n         ... > 0    : pow_lt_pow_of_lt_left pos.2.1 (dec_trivial : 2 > 0),\n      exact absurd this (lt_irrefl _)\n    },\n    { apply lt_of_not_ge, intro n_ge_m,\n      have :=\n      calc c - a = 2 * n^2  : cma\n           ...   \u2265 2 * m^2  : mul_le_mul_left 2 (pow_le_pow_of_le_left n_ge_m 2)\n           ...   = c + a    : cpa.symm\n           ...   > c        : nat.lt_add_of_pos_right pos.1\n           ...   \u2265 c - a    : nat.sub_le _ _,\n      exact absurd this (lt_irrefl _)\n    },\n    { exact gcd.coprime_iff_squares_coprime.mp (ym2 \u25b8 xn2 \u25b8 x_y.symm) },\n    { exact eq_of_mul_eq_mul_left dec_trivial twoa },\n    {\n      rw nat.pow_two at xyb xn2 ym2,\n      have : b * b = (2 * m * n) * (2 * m * n) :=\n      calc b * b = 2 * 2 * (half_b * half_b)    : by simp [*, Hb]\n           ...   = 2 * 2 * (x * y)              : by rw \u2190xyb\n           ...   = 2 * 2 * ((n * n) * (m * m))  : by rw [xn2, ym2]\n           ...   = (2 * m * n) * (2 * m * n)    : by simp,\n      exact sqrt_eq this\n    },\n    { exact eq_of_mul_eq_mul_left dec_trivial twoc }\n  end\nend pyth\n\n/-\n#check not_both_odd\n#check not_both_even\n#check c_odd\n#check ex\n#print axioms not_both_odd\n-/\n", "meta": {"author": "rwbarton", "repo": "lean-elementary-number-theory", "sha": "fabef0737fd2486e3f24f9e04652db4c182d5425", "save_path": "github-repos/lean/rwbarton-lean-elementary-number-theory", "path": "github-repos/lean/rwbarton-lean-elementary-number-theory/lean-elementary-number-theory-fabef0737fd2486e3f24f9e04652db4c182d5425/src/pyth.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.7690802264851918, "lm_q1q2_score": 0.7214926333622593}}
{"text": "import .src_13_applications_to_even_and_odd\n\nnamespace mth1001\n\nsection even_odd_further\n\n/-\nWe round of this part of the module by proving a further series of results on even and odd numbers.\nWe begin with a relatively straightforward result.\n-/\n\n-- Exercise 093:\nexample : \u2203 m n, odd (m + n) :=\nbegin \n  sorry    \nend\n\n-- Exercise 094:\ntheorem even_sub_of_even_of_even : \u2200 m n, even m \u2192 even n \u2192 even (m - n) :=\nbegin \n  sorry    \nend\n\n/- \nThe next examples require a bit more work. You may wish to review the section on application\nto even and odd numbers. Remmember that the `ring` tactic can simplify some algebraic expressions.\n-/\n\n-- Exercise 095:\nexample : \u00ac(\u2200 m n, odd (m + n)) :=\nbegin \n  sorry  \nend\n\n\n-- Exercise 096:\nexample : \u2203 m, \u2200 n, even n \u2228 even (m + n) :=\nbegin\n  sorry  \nend\n\n-- Exercise 097:\nexample : \u2200 m n, even ( (n + m) * (n - m + 1)) :=\nbegin \n  sorry  \nend \n\n-- Exercise 098:\nexample : \u2200 m, \u2203 n, even (m + n) :=\nbegin\n  sorry  \nend\n\n-- Exercise 099:\nexample : \u00ac(\u2203 m, \u2200 n, even (m + n)) :=\nbegin\n  sorry  \nend\n\nend even_odd_further\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_17_even_odd_further.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7214518879562694}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport data.real.basic -- imports the real numbers\nimport solutions.section02reals.sheet5 -- import a bunch of previous stuff\n\n/-\n\n# Harder questions\n\nHere are some harder questions. Don't feel like you have\nto do them. We've seen enough techniques to be able to do\nall of these, but the truth is that we've seen a ton of stuff\nin this course already, so probably you're not on top of all of\nit yet, and furthermore we have not seen\nsome techniques which will enable you to cut corners. If you\nwant to become a real Lean expert then see how many of these\nyou can do. I will go through them all in a solutions video,\nso if you like you can try some of them and then watch me\nsolving them.\n\nGood luck! \n-/\n\n\n/-- If `a(n)` tends to `t` then `37 * a(n)` tends to `37 * t`-/\ntheorem tends_to_thirtyseven_mul (a : \u2115 \u2192 \u211d) (t : \u211d) (h : tends_to a t) :\n  tends_to (\u03bb n, 37 * a n) (37 * t) :=\nbegin\n  have : (0 : \u211d) < 37 := begin norm_num end, -- what is the nice way to switch to tactic mode?\n  rw tends_to at *,\n  intros \u03b5 h\u03b5,\n  cases (h (\u03b5/37) (div_pos h\u03b5 this)) with k h,\n  use k,\n  intros n hn,\n  rw [(mul_sub 37 (a n) t).symm, abs_mul, abs_of_pos this],\n  exact (lt_div_iff' this).mp (h n hn),\nend\n\n/-- If `a(n)` tends to `t` and `c` is a positive constant then\n`c * a(n)` tends to `c * t`. -/\ntheorem tends_to_pos_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (h : tends_to a t)\n  {c : \u211d} (hc : 0 < c) : tends_to (\u03bb n, c * a n) (c * t) :=\nbegin\n  rw tends_to at *,\n  intros \u03b5 h\u03b5,\n  cases (h (\u03b5/c) (div_pos h\u03b5 hc)) with k h,\n  use k,\n  intros n hn,\n  rw [(mul_sub c (a n) t).symm, abs_mul, abs_of_pos hc, \u2190(lt_div_iff' hc)],\n  exact h n hn,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a negative constant then\n`c * a(n)` tends to `c * t`. -/\ntheorem tends_to_neg_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (h : tends_to a t)\n  {c : \u211d} (hc : c < 0) : tends_to (\u03bb n, c * a n) (c * t) :=\nbegin\n  rw tends_to at *,\n  intros \u03b5 h\u03b5,\n  cases (h (- \u03b5 / c) (div_pos_of_neg_of_neg (neg_lt_zero.mpr h\u03b5) hc)) with k h,\n  use k,\n  intros n hn,\n  rw [(mul_sub c (a n) t).symm, abs_mul, \u2190(lt_div_iff' (abs_pos_of_neg hc))],\n  rw [(abs_of_neg hc), div_neg, \u2190neg_div],\n  exact h n hn,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a constant then `c * a(n)` tends\nto `c * t`. -/\ntheorem tends_to_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (c : \u211d) (h : tends_to a t) :\n  tends_to (\u03bb n, c * a n) (c * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a constant then `a(n) * c` tends\nto `t * c`. -/\ntheorem tends_to_mul_const {a : \u2115 \u2192 \u211d} {t : \u211d} (c : \u211d) (h : tends_to a t) :\n  tends_to (\u03bb n, a n * c) (t * c) :=\nbegin\n  sorry\nend\n\n-- another proof of this result, showcasing some tactics\n-- which I've not covered yet.\ntheorem tends_to_neg' {a : \u2115 \u2192 \u211d} {t : \u211d} (ha : tends_to a t) :\n  tends_to (\u03bb n, - a n) (-t) :=\nbegin\n  convert tends_to_const_mul (-1) ha, -- read about the `convert` tactic in the course notes!\n  { ext, simp }, -- ext is a generic extensionality tactic. Here it's being\n                 -- used to deduce that two functions are the same if they take\n                 -- the same values everywhere\n  { simp },\nend\n\n/-- If `a(n)-b(n)` tends to `t` and `b(n)` tends to `u` then\n`a(n)` tends to `t + u`. -/\ntheorem tends_to_of_tends_to_sub {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (h1 : tends_to (\u03bb n, a n - b n) t) (h2 : tends_to b u) :\n  tends_to a (t+u) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` then `a(n)-t` tends to `0`. -/\ntheorem tends_to_sub_lim {a : \u2115 \u2192 \u211d} {t : \u211d}\n  (h : tends_to a t) : tends_to (\u03bb n, a n - t) 0 :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` and `b(n)` both tend to zero, then their product tends\nto zero. -/\ntheorem tends_to_zero_mul_tends_to_zero\n  {a b : \u2115 \u2192 \u211d} (ha : tends_to a 0) (hb : tends_to b 0) :\n  tends_to (\u03bb n, a n * b n) 0 :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `b(n)` tends to `u` then\n`a(n)*b(n)` tends to `t*u`. -/\ntheorem tends_to_mul (a b : \u2115 \u2192 \u211d) (t u : \u211d) (ha : tends_to a t)\n  (hb : tends_to b u) : tends_to (\u03bb n, a n * b n) (t * u) :=\nbegin\n  sorry,\nend\n\n-- something we never used!\n/-- A sequence has at most one limit. -/\ntheorem tends_to_unique (a : \u2115 \u2192 \u211d) (s t : \u211d)\n  (hs : tends_to a s) (ht : tends_to a t) : s = t :=\nbegin\n  sorry,\nend\n", "meta": {"author": "ineswright", "repo": "formalising-maths-2023", "sha": "d29dee07d9d55e96bcfd3d783d6f56943d61d8b6", "save_path": "github-repos/lean/ineswright-formalising-maths-2023", "path": "github-repos/lean/ineswright-formalising-maths-2023/formalising-maths-2023-d29dee07d9d55e96bcfd3d783d6f56943d61d8b6/src/section02reals/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.7214518728728965}}
{"text": "/-\nCopyright (c) 2021 Lu-Ming Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Lu-Ming Zhang\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.symmetric\n! leanprover-community/mathlib commit 55e2dfde0cff928ce5c70926a3f2c7dee3e2dd99\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Matrix.Block\n\n/-!\n# Symmetric matrices\n\nThis file contains the definition and basic results about symmetric matrices.\n\n## Main definition\n\n * `matrix.is_symm `: a matrix `A : matrix n n \u03b1` is \"symmetric\" if `A\u1d40 = A`.\n\n## Tags\n\nsymm, symmetric, matrix\n-/\n\n\nvariable {\u03b1 \u03b2 n m R : Type _}\n\nnamespace Matrix\n\nopen Matrix\n\n/-- A matrix `A : matrix n n \u03b1` is \"symmetric\" if `A\u1d40 = A`. -/\ndef IsSymm (A : Matrix n n \u03b1) : Prop :=\n  A\u1d40 = A\n#align matrix.is_symm Matrix.IsSymm\n\ntheorem IsSymm.eq {A : Matrix n n \u03b1} (h : A.IsSymm) : A\u1d40 = A :=\n  h\n#align matrix.is_symm.eq Matrix.IsSymm.eq\n\n/-- A version of `matrix.ext_iff` that unfolds the `matrix.transpose`. -/\ntheorem IsSymm.ext_iff {A : Matrix n n \u03b1} : A.IsSymm \u2194 \u2200 i j, A j i = A i j :=\n  Matrix.ext_iff.symm\n#align matrix.is_symm.ext_iff Matrix.IsSymm.ext_iff\n\n/-- A version of `matrix.ext` that unfolds the `matrix.transpose`. -/\n@[ext]\ntheorem IsSymm.ext {A : Matrix n n \u03b1} : (\u2200 i j, A j i = A i j) \u2192 A.IsSymm :=\n  Matrix.ext\n#align matrix.is_symm.ext Matrix.IsSymm.ext\n\ntheorem IsSymm.apply {A : Matrix n n \u03b1} (h : A.IsSymm) (i j : n) : A j i = A i j :=\n  IsSymm.ext_iff.1 h i j\n#align matrix.is_symm.apply Matrix.IsSymm.apply\n\ntheorem isSymm_mul_transpose_self [Fintype n] [CommSemiring \u03b1] (A : Matrix n n \u03b1) :\n    (A \u2b1d A\u1d40).IsSymm :=\n  transpose_mul _ _\n#align matrix.is_symm_mul_transpose_self Matrix.isSymm_mul_transpose_self\n\ntheorem isSymm_transpose_mul_self [Fintype n] [CommSemiring \u03b1] (A : Matrix n n \u03b1) :\n    (A\u1d40 \u2b1d A).IsSymm :=\n  transpose_mul _ _\n#align matrix.is_symm_transpose_mul_self Matrix.isSymm_transpose_mul_self\n\ntheorem isSymm_add_transpose_self [AddCommSemigroup \u03b1] (A : Matrix n n \u03b1) : (A + A\u1d40).IsSymm :=\n  add_comm _ _\n#align matrix.is_symm_add_transpose_self Matrix.isSymm_add_transpose_self\n\ntheorem isSymm_transpose_add_self [AddCommSemigroup \u03b1] (A : Matrix n n \u03b1) : (A\u1d40 + A).IsSymm :=\n  add_comm _ _\n#align matrix.is_symm_transpose_add_self Matrix.isSymm_transpose_add_self\n\n@[simp]\ntheorem isSymm_zero [Zero \u03b1] : (0 : Matrix n n \u03b1).IsSymm :=\n  transpose_zero\n#align matrix.is_symm_zero Matrix.isSymm_zero\n\n@[simp]\ntheorem isSymm_one [DecidableEq n] [Zero \u03b1] [One \u03b1] : (1 : Matrix n n \u03b1).IsSymm :=\n  transpose_one\n#align matrix.is_symm_one Matrix.isSymm_one\n\n@[simp]\ntheorem IsSymm.map {A : Matrix n n \u03b1} (h : A.IsSymm) (f : \u03b1 \u2192 \u03b2) : (A.map f).IsSymm :=\n  transpose_map.symm.trans (h.symm \u25b8 rfl)\n#align matrix.is_symm.map Matrix.IsSymm.map\n\n@[simp]\ntheorem IsSymm.transpose {A : Matrix n n \u03b1} (h : A.IsSymm) : A\u1d40.IsSymm :=\n  congr_arg _ h\n#align matrix.is_symm.transpose Matrix.IsSymm.transpose\n\n@[simp]\ntheorem IsSymm.conjTranspose [Star \u03b1] {A : Matrix n n \u03b1} (h : A.IsSymm) : A\u1d34.IsSymm :=\n  h.transpose.map _\n#align matrix.is_symm.conj_transpose Matrix.IsSymm.conjTranspose\n\n@[simp]\ntheorem IsSymm.neg [Neg \u03b1] {A : Matrix n n \u03b1} (h : A.IsSymm) : (-A).IsSymm :=\n  (transpose_neg _).trans (congr_arg _ h)\n#align matrix.is_symm.neg Matrix.IsSymm.neg\n\n@[simp]\ntheorem IsSymm.add {A B : Matrix n n \u03b1} [Add \u03b1] (hA : A.IsSymm) (hB : B.IsSymm) : (A + B).IsSymm :=\n  (transpose_add _ _).trans (hA.symm \u25b8 hB.symm \u25b8 rfl)\n#align matrix.is_symm.add Matrix.IsSymm.add\n\n@[simp]\ntheorem IsSymm.sub {A B : Matrix n n \u03b1} [Sub \u03b1] (hA : A.IsSymm) (hB : B.IsSymm) : (A - B).IsSymm :=\n  (transpose_sub _ _).trans (hA.symm \u25b8 hB.symm \u25b8 rfl)\n#align matrix.is_symm.sub Matrix.IsSymm.sub\n\n@[simp]\ntheorem IsSymm.smul [SMul R \u03b1] {A : Matrix n n \u03b1} (h : A.IsSymm) (k : R) : (k \u2022 A).IsSymm :=\n  (transpose_smul _ _).trans (congr_arg _ h)\n#align matrix.is_symm.smul Matrix.IsSymm.smul\n\n@[simp]\ntheorem IsSymm.submatrix {A : Matrix n n \u03b1} (h : A.IsSymm) (f : m \u2192 n) : (A.submatrix f f).IsSymm :=\n  (transpose_submatrix _ _ _).trans (h.symm \u25b8 rfl)\n#align matrix.is_symm.submatrix Matrix.IsSymm.submatrix\n\n/-- The diagonal matrix `diagonal v` is symmetric. -/\n@[simp]\ntheorem isSymm_diagonal [DecidableEq n] [Zero \u03b1] (v : n \u2192 \u03b1) : (diagonal v).IsSymm :=\n  diagonal_transpose _\n#align matrix.is_symm_diagonal Matrix.isSymm_diagonal\n\n/-- A block matrix `A.from_blocks B C D` is symmetric,\n    if `A` and `D` are symmetric and `B\u1d40 = C`. -/\ntheorem IsSymm.fromBlocks {A : Matrix m m \u03b1} {B : Matrix m n \u03b1} {C : Matrix n m \u03b1}\n    {D : Matrix n n \u03b1} (hA : A.IsSymm) (hBC : B\u1d40 = C) (hD : D.IsSymm) :\n    (A.fromBlocks B C D).IsSymm :=\n  by\n  have hCB : C\u1d40 = B := by\n    rw [\u2190 hBC]\n    simp\n  unfold Matrix.IsSymm\n  rw [from_blocks_transpose]\n  congr <;> assumption\n#align matrix.is_symm.from_blocks Matrix.IsSymm.fromBlocks\n\n/-- This is the `iff` version of `matrix.is_symm.from_blocks`. -/\ntheorem isSymm_fromBlocks_iff {A : Matrix m m \u03b1} {B : Matrix m n \u03b1} {C : Matrix n m \u03b1}\n    {D : Matrix n n \u03b1} : (A.fromBlocks B C D).IsSymm \u2194 A.IsSymm \u2227 B\u1d40 = C \u2227 C\u1d40 = B \u2227 D.IsSymm :=\n  \u27e8fun h =>\n    \u27e8congr_arg toBlocks\u2081\u2081 h, congr_arg toBlocks\u2082\u2081 h, congr_arg toBlocks\u2081\u2082 h,\n      congr_arg toBlocks\u2082\u2082 h\u27e9,\n    fun \u27e8hA, hBC, hCB, hD\u27e9 => IsSymm.fromBlocks hA hBC hD\u27e9\n#align matrix.is_symm_from_blocks_iff Matrix.isSymm_fromBlocks_iff\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/Symmetric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88242786954645, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7214505032231118}}
{"text": "constant ax : nat\nnoncomputable def test : nat \u2192 nat\n| 0     := ax\n| (n+1) := test n\n\n---\n\nconstant f : nat \u2192 nat\nnoncomputable def test' : nat \u2192 nat\n| 0     := ax\n| (n+1) := f (test' n)\n\n#reduce test' 0 -- ax\n#reduce test' 1 -- f ax\n#reduce test' 2 -- f (f ax)\n#reduce test' 3 -- f (f (f ax))\n\nconstant h : \u2200 n, ax = n \u2192 f (f ax) = n \n\nexample : test' 3 = f (f (f ax)) := rfl\n\nset_option trace.simplify.rewrite true\n\nlemma ex1 : test' 2 = ax :=\nbegin\n  simp [test'],\n-- [test'.equations._eqn_2]: test' 2 ==> f (test' 1)\n-- [test'.equations._eqn_2]: test' 1 ==> f (test' 0)\n-- [test'.equations._eqn_1]: test' 0 ==> ax  \n  apply (h ax),\n  refl,\nend\n\nlemma ex2 : test' 2 = ax :=\nbegin\n  simp [test', h ax],\n-- [test'.equations._eqn_2]: test' 2 ==> f (test' 1)\n-- [test'.equations._eqn_2]: test' 1 ==> f (test' 0)\n-- [test'.equations._eqn_1]: test' 0 ==> ax\n-- [eq_self_iff_true]: ax = ax ==> true\n-- [[h ax]]: f (f ax) ==> ax\n-- [eq_self_iff_true]: ax = ax ==> true\nend\n\nlemma ex3 : test' 3 = f ax :=\nbegin\n  simp [test', h ax],\n-- [test'.equations._eqn_2]: test' 3 ==> f (test' 2)\n-- [test'.equations._eqn_2]: test' 2 ==> f (test' 1)\n-- [test'.equations._eqn_2]: test' 1 ==> f (test' 0)\n-- [test'.equations._eqn_1]: test' 0 ==> ax\n-- [eq_self_iff_true]: ax = ax ==> true\n-- [[h ax]]: f (f ax) ==> ax\n-- [eq_self_iff_true]: f ax = f ax ==> true\nend", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/tests/axiom_code.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7214504917170785}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.set.function\nimport Mathlib.logic.function.iterate\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\n\n/-!\n# Fixed points of a self-map\n\nIn this file we define\n\n* the predicate `is_fixed_pt f x := f x = x`;\n* the set `fixed_points f` of fixed points of a self-map `f`.\n\nWe also prove some simple lemmas about `is_fixed_pt` and `\u2218`, `iterate`, and `semiconj`.\n\n## Tags\n\nfixed point\n-/\n\nnamespace function\n\n\n/-- A point `x` is a fixed point of `f : \u03b1 \u2192 \u03b1` if `f x = x`. -/\ndef is_fixed_pt {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1) (x : \u03b1) :=\n  f x = x\n\n/-- Every point is a fixed point of `id`. -/\ntheorem is_fixed_pt_id {\u03b1 : Type u} (x : \u03b1) : is_fixed_pt id x :=\n  rfl\n\nnamespace is_fixed_pt\n\n\nprotected instance decidable {\u03b1 : Type u} [h : DecidableEq \u03b1] {f : \u03b1 \u2192 \u03b1} {x : \u03b1} : Decidable (is_fixed_pt f x) :=\n  h (f x) x\n\n/-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`.-/\nprotected theorem eq {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x) : f x = x :=\n  hf\n\n/-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f \u2218 g`. -/\nprotected theorem comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x) (hg : is_fixed_pt g x) : is_fixed_pt (f \u2218 g) x :=\n  Eq.trans (congr_arg f hg) hf\n\n/-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/\nprotected theorem iterate {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x) (n : \u2115) : is_fixed_pt (nat.iterate f n) x :=\n  iterate_fixed hf n\n\n/-- If `x` is a fixed point of `f \u2218 g` and `g`, then it is a fixed point of `f`. -/\ntheorem left_of_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} {x : \u03b1} (hfg : is_fixed_pt (f \u2218 g) x) (hg : is_fixed_pt g x) : is_fixed_pt f x :=\n  Eq.trans (congr_arg f (Eq.symm hg)) hfg\n\n/-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed\npoint of `g`. -/\ntheorem to_left_inverse {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x) (h : left_inverse g f) : is_fixed_pt g x :=\n  Eq.trans (congr_arg g (Eq.symm hf)) (h x)\n\n/-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\nprotected theorem map {\u03b1 : Type u} {\u03b2 : Type v} {fa : \u03b1 \u2192 \u03b1} {fb : \u03b2 \u2192 \u03b2} {x : \u03b1} (hx : is_fixed_pt fa x) {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) : is_fixed_pt fb (g x) :=\n  Eq.trans (Eq.symm (semiconj.eq h x)) (congr_arg g hx)\n\nend is_fixed_pt\n\n\n/-- The set of fixed points of a map `f : \u03b1 \u2192 \u03b1`. -/\ndef fixed_points {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1) : set \u03b1 :=\n  set_of fun (x : \u03b1) => is_fixed_pt f x\n\nprotected instance fixed_points.decidable {\u03b1 : Type u} [DecidableEq \u03b1] (f : \u03b1 \u2192 \u03b1) (x : \u03b1) : Decidable (x \u2208 fixed_points f) :=\n  is_fixed_pt.decidable\n\n@[simp] theorem mem_fixed_points {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {x : \u03b1} : x \u2208 fixed_points f \u2194 is_fixed_pt f x :=\n  iff.rfl\n\n/-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\ntheorem semiconj.maps_to_fixed_pts {\u03b1 : Type u} {\u03b2 : Type v} {fa : \u03b1 \u2192 \u03b1} {fb : \u03b2 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) : set.maps_to g (fixed_points fa) (fixed_points fb) :=\n  fun (x : \u03b1) (hx : x \u2208 fixed_points fa) => is_fixed_pt.map hx h\n\n/-- Any two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1` are inverse of each other on the sets of fixed points\nof `f \u2218 g` and `g \u2218 f`, respectively. -/\ntheorem inv_on_fixed_pts_comp {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) : set.inv_on f g (fixed_points (f \u2218 g)) (fixed_points (g \u2218 f)) :=\n  { left := fun (x : \u03b2) => id, right := fun (x : \u03b1) => id }\n\n/-- Any map `f` sends fixed points of `g \u2218 f` to fixed points of `f \u2218 g`. -/\ntheorem maps_to_fixed_pts_comp {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) : set.maps_to f (fixed_points (g \u2218 f)) (fixed_points (f \u2218 g)) :=\n  fun (x : \u03b1) (hx : x \u2208 fixed_points (g \u2218 f)) => is_fixed_pt.map hx fun (x : \u03b1) => rfl\n\n/-- Given two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1`, `g` is a bijective map between the fixed points\nof `f \u2218 g` and the fixed points of `g \u2218 f`. The inverse map is `f`, see `inv_on_fixed_pts_comp`. -/\ntheorem bij_on_fixed_pts_comp {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) : set.bij_on g (fixed_points (f \u2218 g)) (fixed_points (g \u2218 f)) :=\n  set.inv_on.bij_on (inv_on_fixed_pts_comp f g) (maps_to_fixed_pts_comp g f) (maps_to_fixed_pts_comp f g)\n\n/-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points\nof `f \u2218 g`. This is a particular case of `function.inv_on_fixed_pts_comp`. -/\ntheorem commute.inv_on_fixed_pts_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} (h : commute f g) : set.inv_on f g (fixed_points (f \u2218 g)) (fixed_points (f \u2218 g)) := sorry\n\n/-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\ntheorem commute.left_bij_on_fixed_pts_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} (h : commute f g) : set.bij_on f (fixed_points (f \u2218 g)) (fixed_points (f \u2218 g)) := sorry\n\n/-- If self-maps `f` and `g` commute, then `g` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\ntheorem commute.right_bij_on_fixed_pts_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} (h : commute f g) : set.bij_on g (fixed_points (f \u2218 g)) (fixed_points (f \u2218 g)) := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/dynamics/fixed_points/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7213494873850443}}
{"text": "-- Conmutadores_en_grupos.lean\n-- Conmutadores en grupos.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 9-julio-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Importar la liber\u00eda de t\u00e1ctica.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Import la liber\u00eda b\u00e1sica de grupos.\n-- ---------------------------------------------------------------------\n\nimport algebra.group.basic \n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Habilitar la l\u00f3gica cl\u00e1sica.\n-- ---------------------------------------------------------------------\n\nopen classical\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar G y H como variables sobre grupos.\n-- ---------------------------------------------------------------------\n\nvariables {G : Type*} [group G]\nvariables {H : Type*} [group H]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar g y h como variables sobre elementos de G.\n-- ---------------------------------------------------------------------\n\nvariables (g h : G)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la funci\u00f3n\n--    conmutador : G \u2192 G \u2192 G\n-- tal que (gonmutador g h) es es conmutador de g y h; es decir, \n--    g * h * g\u207b\u00b9 * h\u207b\u00b9\n-- ---------------------------------------------------------------------\n\ndef conmutador \n  (g : G)\n  (h : G) \n:= g * h * g\u207b\u00b9 * h\u207b\u00b9\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que las im\u00e1genes por homorfismo de conmutadores\n-- son conmutadores.\n-- ---------------------------------------------------------------------\n\nlemma conmutador_hom\n  (f : monoid_hom G H)\n  : f (conmutador g h) = conmutador (f g) (f h) := \nbegin\n  calc f (conmutador g h) \n       = f (g * h * g\u207b\u00b9 * h\u207b\u00b9) \n       : by simp [conmutador]\n  ... = f g * f h * f (g\u207b\u00b9) * f (h\u207b\u00b9) \n      : by simp [mul_hom.map_mul]\n  ... = f g * f h * (f g)\u207b\u00b9 * (f h)\u207b\u00b9 \n      : by {congr; simp only [monoid_hom.map_inv]}\n  ... = conmutador (f g) (f h) \n      : by simp [conmutador],\nend      \n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    g^3 = g * g * g\n-- ---------------------------------------------------------------------\n\nlemma cubo : \n  g^3 = g * g * g := \nby group\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el cubo de un conmutador se puede escribir\n-- como el producto de dos conmutadores.\n-- ---------------------------------------------------------------------\n\nlemma cubo_de_conmutador\n  (a : G) {A : G} {A_def : A = a\u207b\u00b9}\n  (b : G) {B : G} {B_def : B = b\u207b\u00b9}\n  : (conmutador a b)^3 = \n    conmutador (a*b*A) (B*a*b*A^2) * conmutador (B*a*b) (b^2) :=\nbegin\n  unfold conmutador,\n  simp [cubo, A_def, B_def], \n  group,\nend\n\n-- Referencia\n-- ==========\n\n-- Basado en commutator.lean de Clara L\u00f6h que se encuentra en\n-- https://bit.ly/3uApeua\n", "meta": {"author": "jaalonso", "repo": "Explorando-con-Lean", "sha": "c40c7e84e33c3f269b6adbdac816a9d0233f5ab2", "save_path": "github-repos/lean/jaalonso-Explorando-con-Lean", "path": "github-repos/lean/jaalonso-Explorando-con-Lean/Explorando-con-Lean-c40c7e84e33c3f269b6adbdac816a9d0233f5ab2/src/Conmutadores_en_grupos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.721349485616666}}
{"text": "/-\nCopyright (c) 2021 Jakob Scholbach. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jakob Scholbach\n\n! This file was ported from Lean 3 source module algebra.char_p.exp_char\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.CharP.Basic\nimport Mathlib.Data.Nat.Prime\n\n/-!\n# Exponential characteristic\n\nThis file defines the exponential characteristic, which is defined to be 1 for a ring with\ncharacteristic 0 and the same as the ordinary characteristic, if the ordinary characteristic is\nprime. This concept is useful to simplify some theorem statements.\nThis file establishes a few basic results relating it to the (ordinary characteristic).\nThe definition is stated for a semiring, but the actual results are for nontrivial rings\n(as far as exponential characteristic one is concerned), respectively a ring without zero-divisors\n(for prime characteristic).\n\n## Main results\n- `ExpChar`: the definition of exponential characteristic\n- `expChar_is_prime_or_one`: the exponential characteristic is a prime or one\n- `char_eq_expChar_iff`: the characteristic equals the exponential characteristic iff the\n  characteristic is prime\n\n## Tags\nexponential characteristic, characteristic\n-/\n\n\nuniverse u\n\nvariable (R : Type u)\n\nsection Semiring\n\nvariable [Semiring R]\n\n/-- The definition of the exponential characteristic of a semiring. -/\nclass inductive ExpChar (R : Type u) [Semiring R] : \u2115 \u2192 Prop\n  | zero [CharZero R] : ExpChar R 1\n  | prime {q : \u2115} (hprime : q.Prime) [hchar : CharP R q] : ExpChar R q\n#align exp_char ExpChar\n#align exp_char.prime ExpChar.prime\n\n/-- The exponential characteristic is one if the characteristic is zero. -/\ntheorem expChar_one_of_char_zero (q : \u2115) [hp : CharP R 0] [hq : ExpChar R q] : q = 1 := by\n  cases' hq with q hq_one hq_prime hq_hchar\n  \u00b7 rfl\n  \u00b7 exact False.elim (lt_irrefl _ ((hp.eq R hq_hchar).symm \u25b8 hq_prime : (0 : \u2115).Prime).pos)\n#align exp_char_one_of_char_zero expChar_one_of_char_zero\n\n/-- The characteristic equals the exponential characteristic iff the former is prime. -/\ntheorem char_eq_expChar_iff (p q : \u2115) [hp : CharP R p] [hq : ExpChar R q] : p = q \u2194 p.Prime := by\n  cases' hq with q hq_one hq_prime hq_hchar\n  \u00b7 rw [(CharP.eq R hp inferInstance : p = 0)]\n    decide\n  \u00b7 exact \u27e8fun hpq => hpq.symm \u25b8 hq_prime, fun _ => CharP.eq R hp hq_hchar\u27e9\n#align char_eq_exp_char_iff char_eq_expChar_iff\n\nsection Nontrivial\n\nvariable [Nontrivial R]\n\n/-- The exponential characteristic is one if the characteristic is zero. -/\ntheorem char_zero_of_expChar_one (p : \u2115) [hp : CharP R p] [hq : ExpChar R 1] : p = 0 := by\n  cases hq\n  \u00b7 exact CharP.eq R hp inferInstance\n  \u00b7 exact False.elim (CharP.char_ne_one R 1 rfl)\n#align char_zero_of_exp_char_one char_zero_of_expChar_one\n\n-- see Note [lower instance priority]\n/-- The characteristic is zero if the exponential characteristic is one. -/\ninstance (priority := 100) charZero_of_expChar_one' [hq : ExpChar R 1] : CharZero R := by\n  cases hq\n  \u00b7 assumption\n  \u00b7 exact False.elim (CharP.char_ne_one R 1 rfl)\n#align char_zero_of_exp_char_one' charZero_of_expChar_one'\n\n/-- The exponential characteristic is one iff the characteristic is zero. -/\ntheorem expChar_one_iff_char_zero (p q : \u2115) [CharP R p] [ExpChar R q] : q = 1 \u2194 p = 0 := by\n  constructor\n  \u00b7 rintro rfl\n    exact char_zero_of_expChar_one R p\n  \u00b7 rintro rfl\n    exact expChar_one_of_char_zero R q\n#align exp_char_one_iff_char_zero expChar_one_iff_char_zero\n\nsection NoZeroDivisors\n\nvariable [NoZeroDivisors R]\n\n/-- A helper lemma: the characteristic is prime if it is non-zero. -/\ntheorem char_prime_of_ne_zero {p : \u2115} [hp : CharP R p] (p_ne_zero : p \u2260 0) : Nat.Prime p := by\n  cases' CharP.char_is_prime_or_zero R p with h h\n  \u00b7 exact h\n  \u00b7 contradiction\n#align char_prime_of_ne_zero char_prime_of_ne_zero\n\n/-- The exponential characteristic is a prime number or one. -/\ntheorem expChar_is_prime_or_one (q : \u2115) [hq : ExpChar R q] : Nat.Prime q \u2228 q = 1 := by\n  cases hq\n  case zero => exact .inr rfl\n  case prime hp _ => exact .inl hp\n#align exp_char_is_prime_or_one expChar_is_prime_or_one\n\nend NoZeroDivisors\n\nend Nontrivial\n\nend Semiring\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/CharP/ExpChar.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916170039421, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7213494750063956}}
{"text": "/-\nCopyright (c) 2022 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n-/\nimport linear_algebra.multilinear.basic\nimport linear_algebra.free_module.finite.basic\n\n/-! # Multilinear maps over finite dimensional spaces\n\nThe main results are that multilinear maps over finitely-generated, free modules are\nfinitely-generated and free.\n\n* `module.finite.multilinear_map`\n* `module.free.multilinear_map`\n\nWe do not put this in `linear_algebra/multilinear_map/basic` to avoid making the imports too large\nthere.\n-/\n\nnamespace multilinear_map\n\nvariables {\u03b9 R M\u2082 : Type*} {M\u2081 : \u03b9 \u2192 Type*}\nvariables [decidable_eq \u03b9]\nvariables [fintype \u03b9] [comm_ring R] [add_comm_group M\u2082] [module R M\u2082]\nvariables [\u03a0 i, add_comm_group (M\u2081 i)] [\u03a0 i, module R (M\u2081 i)]\nvariables [module.finite R M\u2082] [module.free R M\u2082]\nvariables [\u2200 i, module.finite R (M\u2081 i)] [\u2200 i, module.free R (M\u2081 i)]\n\n-- the induction requires us to show both at once\nprivate lemma free_and_finite :\n  module.free R (multilinear_map R M\u2081 M\u2082) \u2227 module.finite R (multilinear_map R M\u2081 M\u2082) :=\nbegin\n  -- the `fin n` case is sufficient\n  suffices : \u2200 n (N : fin n \u2192 Type*) [\u03a0 i, add_comm_group (N i)],\n    by exactI \u2200 [\u03a0 i, module R (N i)],\n    by exactI \u2200 [\u2200 i, module.finite R (N i)] [\u2200 i, module.free R (N i)],\n      module.free R (multilinear_map R N M\u2082) \u2227 module.finite R (multilinear_map R N M\u2082),\n  { casesI this _ (M\u2081 \u2218 (fintype.equiv_fin \u03b9).symm),\n    have e := dom_dom_congr_linear_equiv' R M\u2081 M\u2082 (fintype.equiv_fin \u03b9),\n    exact \u27e8module.free.of_equiv e.symm, module.finite.equiv e.symm\u27e9, },\n  introsI n N _ _ _ _,\n  unfreezingI { induction n with n ih },\n  { exact \u27e8module.free.of_equiv (const_linear_equiv_of_is_empty R N M\u2082),\n           module.finite.equiv (const_linear_equiv_of_is_empty R N M\u2082)\u27e9 },\n  { suffices :\n      module.free R (N 0 \u2192\u2097[R] multilinear_map R (\u03bb (i : fin n), N i.succ) M\u2082) \u2227\n      module.finite R (N 0 \u2192\u2097[R] multilinear_map R (\u03bb (i : fin n), N i.succ) M\u2082),\n    { casesI this,\n      exact \u27e8module.free.of_equiv (multilinear_curry_left_equiv R N M\u2082),\n            module.finite.equiv (multilinear_curry_left_equiv R N M\u2082)\u27e9 },\n    casesI ih (\u03bb i, N i.succ),\n    exact \u27e8module.free.linear_map _ _ _, module.finite.linear_map _ _\u27e9 },\nend\n\ninstance _root_.module.finite.multilinear_map : module.finite R (multilinear_map R M\u2081 M\u2082) :=\nfree_and_finite.2\n\ninstance _root_.module.free.multilinear_map : module.free R (multilinear_map R M\u2081 M\u2082) :=\nfree_and_finite.1\n\nend multilinear_map\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/multilinear/finite_dimensional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064587, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7213494715011548}}
{"text": "/-\nCopyright (c) 2020 Yury Kudriashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudriashov, Ya\u00ebl Dillies\n-/\nimport analysis.convex.basic\nimport order.closure\n\n/-!\n# Convex hull\n\nThis file defines the convex hull of a set `s` in a module. `convex_hull \ud835\udd5c s` is the smallest convex\nset containing `s`. In order theory speak, this is a closure operator.\n\n## Implementation notes\n\n`convex_hull` is defined as a closure operator. This gives access to the `closure_operator` API\nwhile the impact on writing code is minimal as `convex_hull \ud835\udd5c s` is automatically elaborated as\n`\u21d1(convex_hull \ud835\udd5c) s`.\n-/\n\nopen set\nopen_locale pointwise\n\nvariables {\ud835\udd5c E F : Type*}\n\nsection convex_hull\nsection ordered_semiring\nvariables [ordered_semiring \ud835\udd5c]\n\nsection add_comm_monoid\nvariables (\ud835\udd5c) [add_comm_monoid E] [add_comm_monoid F] [module \ud835\udd5c E] [module \ud835\udd5c F]\n\n/-- The convex hull of a set `s` is the minimal convex set that includes `s`. -/\ndef convex_hull : closure_operator (set E) :=\nclosure_operator.mk\u2083\n  (\u03bb s, \u22c2 (t : set E) (hst : s \u2286 t) (ht : convex \ud835\udd5c t), t)\n  (convex \ud835\udd5c)\n  (\u03bb s, set.subset_Inter (\u03bb t, set.subset_Inter $ \u03bb hst, set.subset_Inter $ \u03bb ht, hst))\n  (\u03bb s, convex_Inter $ \u03bb t, convex_Inter $ \u03bb ht, convex_Inter id)\n  (\u03bb s t hst ht, set.Inter_subset_of_subset t $ set.Inter_subset_of_subset hst $\n  set.Inter_subset _ ht)\n\nvariables (s : set E)\n\nlemma subset_convex_hull : s \u2286 convex_hull \ud835\udd5c s := (convex_hull \ud835\udd5c).le_closure s\n\nlemma convex_convex_hull : convex \ud835\udd5c (convex_hull \ud835\udd5c s) := closure_operator.closure_mem_mk\u2083 s\n\nlemma convex_hull_eq_Inter : convex_hull \ud835\udd5c s = \u22c2 (t : set E) (hst : s \u2286 t) (ht : convex \ud835\udd5c t), t :=\nrfl\n\nvariables {\ud835\udd5c s} {t : set E} {x y : E}\n\nlemma mem_convex_hull_iff : x \u2208 convex_hull \ud835\udd5c s \u2194 \u2200 t, s \u2286 t \u2192 convex \ud835\udd5c t \u2192 x \u2208 t :=\nby simp_rw [convex_hull_eq_Inter, mem_Inter]\n\nlemma convex_hull_min (hst : s \u2286 t) (ht : convex \ud835\udd5c t) : convex_hull \ud835\udd5c s \u2286 t :=\nclosure_operator.closure_le_mk\u2083_iff (show s \u2264 t, from hst) ht\n\nlemma convex.convex_hull_subset_iff (ht : convex \ud835\udd5c t) : convex_hull \ud835\udd5c s \u2286 t \u2194 s \u2286 t :=\n\u27e8(subset_convex_hull _ _).trans, \u03bb h, convex_hull_min h ht\u27e9\n\n@[mono] lemma convex_hull_mono (hst : s \u2286 t) : convex_hull \ud835\udd5c s \u2286 convex_hull \ud835\udd5c t :=\n(convex_hull \ud835\udd5c).monotone hst\n\nlemma convex.convex_hull_eq (hs : convex \ud835\udd5c s) : convex_hull \ud835\udd5c s = s :=\nclosure_operator.mem_mk\u2083_closed hs\n\n@[simp] lemma convex_hull_univ : convex_hull \ud835\udd5c (univ : set E) = univ :=\nclosure_operator.closure_top (convex_hull \ud835\udd5c)\n\n@[simp] lemma convex_hull_empty : convex_hull \ud835\udd5c (\u2205 : set E) = \u2205 := convex_empty.convex_hull_eq\n\n@[simp] lemma convex_hull_empty_iff : convex_hull \ud835\udd5c s = \u2205 \u2194 s = \u2205 :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190set.subset_empty_iff, \u2190h],\n    exact subset_convex_hull \ud835\udd5c _ },\n  { rintro rfl,\n    exact convex_hull_empty }\nend\n\n@[simp] lemma convex_hull_nonempty_iff : (convex_hull \ud835\udd5c s).nonempty \u2194 s.nonempty :=\nbegin\n  rw [nonempty_iff_ne_empty, nonempty_iff_ne_empty, ne.def, ne.def],\n  exact not_congr convex_hull_empty_iff,\nend\n\nalias convex_hull_nonempty_iff \u2194 _ set.nonempty.convex_hull\n\nattribute [protected] set.nonempty.convex_hull\n\nlemma segment_subset_convex_hull (hx : x \u2208 s) (hy : y \u2208 s) : segment \ud835\udd5c x y \u2286 convex_hull \ud835\udd5c s :=\n(convex_convex_hull _ _).segment_subset (subset_convex_hull _ _ hx) (subset_convex_hull _ _ hy)\n\n@[simp] lemma convex_hull_singleton (x : E) : convex_hull \ud835\udd5c ({x} : set E) = {x} :=\n(convex_singleton x).convex_hull_eq\n\n@[simp] lemma convex_hull_pair (x y : E) : convex_hull \ud835\udd5c {x, y} = segment \ud835\udd5c x y :=\nbegin\n  refine (convex_hull_min _ $ convex_segment _ _).antisymm\n    (segment_subset_convex_hull (mem_insert _ _) $ mem_insert_of_mem _ $ mem_singleton _),\n  rw [insert_subset, singleton_subset_iff],\n  exact \u27e8left_mem_segment _ _ _, right_mem_segment _ _ _\u27e9,\nend\n\nlemma convex_hull_convex_hull_union_left (s t : set E) :\n  convex_hull \ud835\udd5c (convex_hull \ud835\udd5c s \u222a t) = convex_hull \ud835\udd5c (s \u222a t) :=\nclosure_operator.closure_sup_closure_left _ _ _\n\nlemma convex_hull_convex_hull_union_right (s t : set E) :\n  convex_hull \ud835\udd5c (s \u222a convex_hull \ud835\udd5c t) = convex_hull \ud835\udd5c (s \u222a t) :=\nclosure_operator.closure_sup_closure_right _ _ _\n\nlemma convex.convex_remove_iff_not_mem_convex_hull_remove {s : set E} (hs : convex \ud835\udd5c s) (x : E) :\n  convex \ud835\udd5c (s \\ {x}) \u2194 x \u2209 convex_hull \ud835\udd5c (s \\ {x}) :=\nbegin\n  split,\n  { rintro hsx hx,\n    rw hsx.convex_hull_eq at hx,\n    exact hx.2 (mem_singleton _) },\n  rintro hx,\n  suffices h : s \\ {x} = convex_hull \ud835\udd5c (s \\ {x}), { convert convex_convex_hull \ud835\udd5c _ },\n  exact subset.antisymm (subset_convex_hull \ud835\udd5c _) (\u03bb y hy, \u27e8convex_hull_min (diff_subset _ _) hs hy,\n    by { rintro (rfl : y = x), exact hx hy }\u27e9),\nend\n\nlemma is_linear_map.convex_hull_image {f : E \u2192 F} (hf : is_linear_map \ud835\udd5c f) (s : set E) :\n  convex_hull \ud835\udd5c (f '' s) = f '' convex_hull \ud835\udd5c s :=\nset.subset.antisymm (convex_hull_min (image_subset _ (subset_convex_hull \ud835\udd5c s)) $\n  (convex_convex_hull \ud835\udd5c s).is_linear_image hf)\n  (image_subset_iff.2 $ convex_hull_min\n    (image_subset_iff.1 $ subset_convex_hull \ud835\udd5c _)\n    ((convex_convex_hull \ud835\udd5c _).is_linear_preimage hf))\n\nlemma linear_map.convex_hull_image (f : E \u2192\u2097[\ud835\udd5c] F) (s : set E) :\n  convex_hull \ud835\udd5c (f '' s) = f '' convex_hull \ud835\udd5c s :=\nf.is_linear.convex_hull_image s\n\nend add_comm_monoid\nend ordered_semiring\n\nsection ordered_comm_semiring\nvariables [ordered_comm_semiring \ud835\udd5c] [add_comm_monoid E] [module \ud835\udd5c E]\n\nlemma convex_hull_smul (a : \ud835\udd5c) (s : set E) : convex_hull \ud835\udd5c (a \u2022 s) = a \u2022 convex_hull \ud835\udd5c s :=\n(linear_map.lsmul _ _ a).convex_hull_image _\n\nend ordered_comm_semiring\n\nsection ordered_ring\nvariables [ordered_ring \ud835\udd5c]\n\nsection add_comm_group\nvariables [add_comm_group E] [add_comm_group F] [module \ud835\udd5c E] [module \ud835\udd5c F] (s : set E)\n\nlemma affine_map.image_convex_hull (f : E \u2192\u1d43[\ud835\udd5c] F) :\n  f '' convex_hull \ud835\udd5c s = convex_hull \ud835\udd5c (f '' s) :=\nbegin\n  apply set.subset.antisymm,\n  { rw set.image_subset_iff,\n    refine convex_hull_min _ ((convex_convex_hull \ud835\udd5c (\u21d1f '' s)).affine_preimage f),\n    rw \u2190 set.image_subset_iff,\n    exact subset_convex_hull \ud835\udd5c (f '' s) },\n  { exact convex_hull_min (set.image_subset _ (subset_convex_hull \ud835\udd5c s))\n    ((convex_convex_hull \ud835\udd5c s).affine_image f) }\nend\n\nlemma convex_hull_subset_affine_span : convex_hull \ud835\udd5c s \u2286 (affine_span \ud835\udd5c s : set E) :=\nconvex_hull_min (subset_affine_span \ud835\udd5c s) (affine_span \ud835\udd5c s).convex\n\n@[simp] lemma affine_span_convex_hull : affine_span \ud835\udd5c (convex_hull \ud835\udd5c s) = affine_span \ud835\udd5c s :=\nbegin\n  refine le_antisymm _ (affine_span_mono \ud835\udd5c (subset_convex_hull \ud835\udd5c s)),\n  rw affine_span_le,\n  exact convex_hull_subset_affine_span s,\nend\n\nlemma convex_hull_neg (s : set E) : convex_hull \ud835\udd5c (-s) = -convex_hull \ud835\udd5c s :=\nby { simp_rw \u2190image_neg, exact (affine_map.image_convex_hull _ $ -1).symm }\n\nend add_comm_group\nend ordered_ring\nend convex_hull\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/convex/hull.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7213494591540213}}
{"text": "import tactic\nimport data.zmod.basic\n\n/-\n\n# Prove that 19 \u2223 2^(2^(6k+2)) + 3 for k = 0,1,2,... \n\n\nThis is the fifth question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\nthoughts\n\nif a(k)=2^(2^(6k+2))\nthen a(k+1)=2^(2^6*2^(6k+2))=a(k)^64\n\nNote that 16^64 is 16 mod 19 according to a brute force calculation\nand so all of the a(k) are 16 mod 19 and we're done\n\n-/\n\nlemma sixteen_pow_sixtyfour_mod_nineteen : (16 : zmod 19)^64 = 16 :=\nbegin\n  refl,\nend.\n\nexample (a b : zmod 19) : (a + b = 0) \u2194 a = -b := add_eq_zero_iff_eq_neg\nexample (k : \u2115) : 19 \u2223 2^(2^(6*k+2))+3 :=\nbegin\n  induction k with d hd,\n  { refl },\n  have h : 2 ^ 2 ^ (6 * d.succ + 2) = (2 ^ 2 ^ (6 * d + 2)) ^ 64,\n  { ring_exp },\n  rw [\u2190 zmod.nat_coe_zmod_eq_zero_iff_dvd, nat.cast_add, add_eq_zero_iff_eq_neg] at hd \u22a2,\n  rw h,\n  rw nat.cast_pow,\n  rw hd,\n  convert sixteen_pow_sixtyfour_mod_nineteen,\nend\n\n\n\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section08numbertheory/examples/example05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7213084539854433}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Kenny Lau\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.complete_lattice\nimport Mathlib.dynamics.fixed_points.basic\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\n\n/-!\n# Fixed point construction on complete lattices\n-/\n\n/-- Least fixed point of a monotone function -/\n/-- Greatest fixed point of a monotone function -/\ndef lfp {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) : \u03b1 :=\n  Inf (set_of fun (a : \u03b1) => f a \u2264 a)\n\ndef gfp {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) : \u03b1 :=\n  Sup (set_of fun (a : \u03b1) => a \u2264 f a)\n\ntheorem lfp_le {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {a : \u03b1} (h : f a \u2264 a) : lfp f \u2264 a :=\n  Inf_le h\n\ntheorem le_lfp {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {a : \u03b1} (h : \u2200 (b : \u03b1), f b \u2264 b \u2192 a \u2264 b) : a \u2264 lfp f :=\n  le_Inf h\n\ntheorem lfp_eq {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} (m : monotone f) : lfp f = f (lfp f) :=\n  (fun (this : f (lfp f) \u2264 lfp f) => le_antisymm (lfp_le (m this)) this)\n    (le_lfp fun (b : \u03b1) (h : f b \u2264 b) => le_trans (m (lfp_le h)) h)\n\ntheorem lfp_induct {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {p : \u03b1 \u2192 Prop} (m : monotone f) (step : \u2200 (a : \u03b1), p a \u2192 a \u2264 lfp f \u2192 p (f a)) (sup : \u2200 (s : set \u03b1), (\u2200 (a : \u03b1), a \u2208 s \u2192 p a) \u2192 p (Sup s)) : p (lfp f) := sorry\n\ntheorem monotone_lfp {\u03b1 : Type u} [complete_lattice \u03b1] : monotone lfp :=\n  fun (f g : \u03b1 \u2192 \u03b1) (this : f \u2264 g) => le_lfp fun (a : \u03b1) (this_1 : g a \u2264 a) => lfp_le (le_trans (this a) this_1)\n\ntheorem le_gfp {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {a : \u03b1} (h : a \u2264 f a) : a \u2264 gfp f :=\n  le_Sup h\n\ntheorem gfp_le {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {a : \u03b1} (h : \u2200 (b : \u03b1), b \u2264 f b \u2192 b \u2264 a) : gfp f \u2264 a :=\n  Sup_le h\n\ntheorem gfp_eq {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} (m : monotone f) : gfp f = f (gfp f) :=\n  (fun (this : gfp f \u2264 f (gfp f)) => le_antisymm this (le_gfp (m this)))\n    (gfp_le fun (b : \u03b1) (h : b \u2264 f b) => le_trans h (m (le_gfp h)))\n\ntheorem gfp_induct {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {p : \u03b1 \u2192 Prop} (m : monotone f) (step : \u2200 (a : \u03b1), p a \u2192 gfp f \u2264 a \u2192 p (f a)) (inf : \u2200 (s : set \u03b1), (\u2200 (a : \u03b1), a \u2208 s \u2192 p a) \u2192 p (Inf s)) : p (gfp f) := sorry\n\ntheorem monotone_gfp {\u03b1 : Type u} [complete_lattice \u03b1] : monotone gfp :=\n  fun (f g : \u03b1 \u2192 \u03b1) (this : f \u2264 g) => gfp_le fun (a : \u03b1) (this_1 : a \u2264 f a) => le_gfp (le_trans this_1 (this a))\n\n-- Rolling rule\n\ntheorem lfp_comp {\u03b1 : Type u} {\u03b2 : Type v} [complete_lattice \u03b1] [complete_lattice \u03b2] {f : \u03b2 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b2} (m_f : monotone f) (m_g : monotone g) : lfp (f \u2218 g) = f (lfp (g \u2218 f)) := sorry\n\ntheorem gfp_comp {\u03b1 : Type u} {\u03b2 : Type v} [complete_lattice \u03b1] [complete_lattice \u03b2] {f : \u03b2 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b2} (m_f : monotone f) (m_g : monotone g) : gfp (f \u2218 g) = f (gfp (g \u2218 f)) := sorry\n\n-- Diagonal rule\n\ntheorem lfp_lfp {\u03b1 : Type u} [complete_lattice \u03b1] {h : \u03b1 \u2192 \u03b1 \u2192 \u03b1} (m : \u2200 {a b c d : \u03b1}, a \u2264 b \u2192 c \u2264 d \u2192 h a c \u2264 h b d) : lfp (lfp \u2218 h) = lfp fun (x : \u03b1) => h x x := sorry\n\ntheorem gfp_gfp {\u03b1 : Type u} [complete_lattice \u03b1] {h : \u03b1 \u2192 \u03b1 \u2192 \u03b1} (m : \u2200 {a b c d : \u03b1}, a \u2264 b \u2192 c \u2264 d \u2192 h a c \u2264 h b d) : gfp (gfp \u2218 h) = gfp fun (x : \u03b1) => h x x := sorry\n\n/- The complete lattice of fixed points of a function f -/\n\nnamespace fixed_points\n\n\ndef prev {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) (x : \u03b1) : \u03b1 :=\n  gfp fun (z : \u03b1) => x \u2293 f z\n\ndef next {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) (x : \u03b1) : \u03b1 :=\n  lfp fun (z : \u03b1) => x \u2294 f z\n\ntheorem prev_le {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {x : \u03b1} : prev f x \u2264 x :=\n  gfp_le fun (z : \u03b1) (hz : z \u2264 x \u2293 f z) => le_trans hz inf_le_left\n\ntheorem prev_eq {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} (hf : monotone f) {a : \u03b1} (h : f a \u2264 a) : prev f a = f (prev f a) := sorry\n\ndef prev_fixed {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} (hf : monotone f) (a : \u03b1) (h : f a \u2264 a) : \u21a5(function.fixed_points f) :=\n  { val := prev f a, property := sorry }\n\ntheorem next_le {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} {x : \u03b1} : x \u2264 next f x :=\n  le_lfp fun (z : \u03b1) (hz : x \u2294 f z \u2264 z) => le_trans le_sup_left hz\n\ntheorem next_eq {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} (hf : monotone f) {a : \u03b1} (h : a \u2264 f a) : next f a = f (next f a) := sorry\n\ndef next_fixed {\u03b1 : Type u} [complete_lattice \u03b1] {f : \u03b1 \u2192 \u03b1} (hf : monotone f) (a : \u03b1) (h : a \u2264 f a) : \u21a5(function.fixed_points f) :=\n  { val := next f a, property := sorry }\n\ntheorem sup_le_f_of_fixed_points {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) (hf : monotone f) (x : \u21a5(function.fixed_points f)) (y : \u21a5(function.fixed_points f)) : subtype.val x \u2294 subtype.val y \u2264 f (subtype.val x \u2294 subtype.val y) := sorry\n\ntheorem f_le_inf_of_fixed_points {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) (hf : monotone f) (x : \u21a5(function.fixed_points f)) (y : \u21a5(function.fixed_points f)) : f (subtype.val x \u2293 subtype.val y) \u2264 subtype.val x \u2293 subtype.val y := sorry\n\ntheorem Sup_le_f_of_fixed_points {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) (hf : monotone f) (A : set \u03b1) (HA : A \u2286 function.fixed_points f) : Sup A \u2264 f (Sup A) :=\n  Sup_le fun (x : \u03b1) (hxA : x \u2208 A) => HA hxA \u25b8 hf (le_Sup hxA)\n\ntheorem f_le_Inf_of_fixed_points {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) (hf : monotone f) (A : set \u03b1) (HA : A \u2286 function.fixed_points f) : f (Inf A) \u2264 Inf A :=\n  le_Inf fun (x : \u03b1) (hxA : x \u2208 A) => HA hxA \u25b8 hf (Inf_le hxA)\n\n/-- The fixed points of `f` form a complete lattice.\nThis cannot be an instance, since it depends on the monotonicity of `f`. -/\nprotected def complete_lattice {\u03b1 : Type u} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) (hf : monotone f) : complete_lattice \u21a5(function.fixed_points f) :=\n  complete_lattice.mk\n    (fun (x y : \u21a5(function.fixed_points f)) =>\n      next_fixed hf (subtype.val x \u2294 subtype.val y) (sup_le_f_of_fixed_points f hf x y))\n    (fun (x y : \u21a5(function.fixed_points f)) => subtype.val x \u2264 subtype.val y)\n    (bounded_lattice.lt._default fun (x y : \u21a5(function.fixed_points f)) => subtype.val x \u2264 subtype.val y) sorry sorry\n    sorry sorry sorry sorry\n    (fun (x y : \u21a5(function.fixed_points f)) =>\n      prev_fixed hf (subtype.val x \u2293 subtype.val y) (f_le_inf_of_fixed_points f hf x y))\n    sorry sorry sorry (prev_fixed hf \u22a4 sorry) sorry (next_fixed hf \u22a5 sorry) sorry\n    (fun (A : set \u21a5(function.fixed_points f)) => next_fixed hf (Sup (subtype.val '' A)) sorry)\n    (fun (A : set \u21a5(function.fixed_points f)) => prev_fixed hf (Inf (subtype.val '' A)) sorry) sorry sorry sorry sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/fixed_points.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7213084468252402}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\n\nimport algebra.group_power\nimport algebra.group_power.basic\nimport logic.function.iterate\nimport group_theory.perm.basic\n\n/-!\n# Iterates of monoid and ring homomorphisms\n\nIterate of a monoid/ring homomorphism is a monoid/ring homomorphism but it has a wrong type, so Lean\ncan't apply lemmas like `monoid_hom.map_one` to `f^[n] 1`. Though it is possible to define\na monoid structure on the endomorphisms, quite often we do not want to convert from\n`M \u2192* M` to (not yet defined) `monoid.End M` and from `f^[n]` to `f^n` just to apply a simple lemma.\n\nSo, we restate standard `*_hom.map_*` lemmas under names `*_hom.iterate_map_*`.\n\nWe also prove formulas for iterates of add/mul left/right.\n\n## Tags\n\nhomomorphism, iterate\n-/\n\nopen function\n\nvariables {M : Type*} {N : Type*} {G : Type*} {H : Type*}\n\n/-- An auxiliary lemma that can be used to prove `\u21d1(f ^ n) = (\u21d1f^[n])`. -/\nlemma hom_coe_pow {F : Type*} [monoid F] (c : F \u2192 M \u2192 M) (h1 : c 1 = id)\n  (hmul : \u2200 f g, c (f * g) = c f \u2218 c g) (f : F) : \u2200 n, c (f ^ n) = (c f^[n])\n| 0 := by { rw [pow_zero, h1], refl }\n| (n + 1) := by rw [pow_succ, iterate_succ', hmul, hom_coe_pow]\n\nnamespace monoid_hom\n\nsection\n\nvariables [mul_one_class M] [mul_one_class N]\n\n@[simp, to_additive]\ntheorem iterate_map_one (f : M \u2192* M) (n : \u2115) : f^[n] 1 = 1 :=\niterate_fixed f.map_one n\n\n@[simp, to_additive]\ntheorem iterate_map_mul (f : M \u2192* M) (n : \u2115) (x y) :\n  f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nsemiconj\u2082.iterate f.map_mul n x y\n\nend\n\nvariables [monoid M] [monoid N] [group G] [group H]\n\n@[simp, to_additive]\ntheorem iterate_map_inv (f : G \u2192* G) (n : \u2115) (x) :\n  f^[n] (x\u207b\u00b9) = (f^[n] x)\u207b\u00b9 :=\ncommute.iterate_left f.map_inv n x\n\ntheorem iterate_map_pow (f : M \u2192* M) (a) (n m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_pow x m) n a\n\ntheorem iterate_map_gpow (f : G \u2192* G) (a) (n : \u2115) (m : \u2124) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_gpow x m) n a\n\nlemma coe_pow {M} [comm_monoid M] (f : monoid.End M) (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) _ _\n\nend monoid_hom\n\nnamespace add_monoid_hom\n\nvariables [add_monoid M] [add_monoid N] [add_group G] [add_group H]\n\n@[simp]\ntheorem iterate_map_sub (f : G \u2192+ G) (n : \u2115) (x y) :\n  f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=\nsemiconj\u2082.iterate f.map_sub n x y\n\ntheorem iterate_map_smul (f : M \u2192+ M) (n m : \u2115) (x : M) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_pow x n m\n\ntheorem iterate_map_gsmul (f : G \u2192+ G) (n : \u2115) (m : \u2124) (x : G) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_gpow x n m\n\nend add_monoid_hom\n\nnamespace ring_hom\n\nsection semiring\n\nvariables {R : Type*} [semiring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\nlemma coe_pow (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) f n\n\ntheorem iterate_map_one : f^[n] 1 = 1 := f.to_monoid_hom.iterate_map_one n\n\ntheorem iterate_map_zero : f^[n] 0 = 0 := f.to_add_monoid_hom.iterate_map_zero n\n\ntheorem iterate_map_add : f^[n] (x + y) = (f^[n] x) + (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_add n x y\n\ntheorem iterate_map_mul : f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nf.to_monoid_hom.iterate_map_mul n x y\n\ntheorem iterate_map_pow (a) (n m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\nf.to_monoid_hom.iterate_map_pow a n m\n\ntheorem iterate_map_smul (n m : \u2115) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_smul n m x\n\nend semiring\n\nvariables {R : Type*} [ring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\ntheorem iterate_map_sub : f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_sub n x y\n\ntheorem iterate_map_neg : f^[n] (-x) = -(f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_neg n x\n\ntheorem iterate_map_gsmul (n : \u2115) (m : \u2124) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_gsmul n m x\n\nend ring_hom\n\nlemma equiv.perm.coe_pow {\u03b1 : Type*} (f : equiv.perm \u03b1) (n : \u2115) : \u21d1(f ^ n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb _ _, rfl) _ _\n\n--what should be the namespace for this section?\nsection monoid\n\nvariables [monoid G] (a : G) (n : \u2115)\n\n@[simp] lemma mul_left_iterate : ((*) a)^[n] = (*) (a^n) :=\nnat.rec_on n (funext $ \u03bb x, by simp) $ \u03bb n ihn,\nfunext $ \u03bb x, by simp [iterate_succ, ihn, pow_succ', mul_assoc]\n\n@[simp] lemma mul_right_iterate : (* a)^[n] = (* a ^ n) :=\nbegin\n  induction n with d hd,\n  { simpa },\n  { simp [\u2190 pow_succ, hd] }\nend\n\nlemma mul_right_iterate_apply_one : (* a)^[n] 1 = a ^ n :=\nby simp [mul_right_iterate]\n\nend monoid\n\nsection semigroup\n\nvariables [semigroup G] {a b c : G}\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_left (h : semiconj_by a b c) :\n  function.semiconj ((*)a) ((*)b) ((*)c) :=\n\u03bb j, by rw [\u2190 mul_assoc, h.eq, mul_assoc]\n\n@[to_additive]\nlemma commute.function_commute_mul_left (h : commute a b) :\n  function.commute ((*)a) ((*)b) :=\nsemiconj_by.function_semiconj_mul_left h\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_right_swap (h : semiconj_by a b c) :\n  function.semiconj (*a) (*c) (*b) :=\n\u03bb j, by simp_rw [mul_assoc, \u2190 h.eq]\n\n@[to_additive]\nlemma commute.function_commute_mul_right (h : commute a b) :\n  function.commute (*a) (*b) :=\nsemiconj_by.function_semiconj_mul_right_swap h\n\nend semigroup\n\n--what should be the namespace for this section?\nsection add_monoid\n\nvariables [add_monoid M] (a : M) (n : \u2115)\n\n@[simp] lemma add_left_iterate : ((+) a)^[n] = (+) (n \u2022 a) :=\n@mul_left_iterate (multiplicative M) _ a n\n\n@[simp] lemma add_right_iterate : (+ a)^[n] = (+ n \u2022 a) :=\nbegin\n  induction n with d hd,\n  { simp [zero_nsmul, id_def] },\n  { simp [hd, add_assoc, succ_nsmul] }\nend\n\nlemma add_right_iterate_apply_zero : (+ a)^[n] 0 = n \u2022 a :=\nby simp [add_right_iterate]\n\nend add_monoid\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/iterate_hom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7212904163668917}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport data.polynomial.degree.definitions\n\n/-!\n# Trailing degree of univariate polynomials\n\n## Main definitions\n\n* `trailing_degree p`: the multiplicity of `X` in the polynomial `p`\n* `nat_trailing_degree`: a variant of `trailing_degree` that takes values in the natural numbers\n* `trailing_coeff`: the coefficient at index `nat_trailing_degree p`\n\nConverts most results about `degree`, `nat_degree` and `leading_coeff` to results about the bottom\nend of a polynomial\n-/\n\nnoncomputable theory\nlocal attribute [instance, priority 100] classical.prop_decidable\n\nopen function polynomial finsupp finset\nopen_locale big_operators\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b : R} {n m : \u2115}\n\nsection semiring\nvariables [semiring R] {p q r : polynomial R}\n\n/-- `trailing_degree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest\n`X`-exponent in `p`.\n`trailing_degree p = some n` when `p \u2260 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailing_degree 0 = \u22a4`. -/\ndef trailing_degree (p : polynomial R) : with_top \u2115 := p.support.inf some\n\nlemma trailing_degree_lt_wf : well_founded\n(\u03bbp q : polynomial R, trailing_degree p < trailing_degree q) :=\ninv_image.wf trailing_degree (with_top.well_founded_lt nat.lt_wf)\n\n/-- `nat_trailing_degree p` forces `trailing_degree p` to `\u2115`, by defining\n`nat_trailing_degree \u22a4 = 0`. -/\ndef nat_trailing_degree (p : polynomial R) : \u2115 := (trailing_degree p).get_or_else 0\n\n/-- `trailing_coeff p` gives the coefficient of the smallest power of `X` in `p`-/\ndef trailing_coeff (p : polynomial R) : R := coeff p (nat_trailing_degree p)\n\n/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/\ndef trailing_monic (p : polynomial R) := trailing_coeff p = (1 : R)\n\nlemma trailing_monic.def : trailing_monic p \u2194 trailing_coeff p = 1 := iff.rfl\n\ninstance trailing_monic.decidable [decidable_eq R] : decidable (trailing_monic p) :=\nby unfold trailing_monic; apply_instance\n\n@[simp] lemma trailing_monic.trailing_coeff {p : polynomial R} (hp : p.trailing_monic) :\n  trailing_coeff p = 1 := hp\n\n@[simp] lemma trailing_degree_zero : trailing_degree (0 : polynomial R) = \u22a4 := rfl\n\n@[simp] lemma nat_trailing_degree_zero : nat_trailing_degree (0 : polynomial R) = 0 := rfl\n\nlemma trailing_degree_eq_top : trailing_degree p = \u22a4 \u2194 p = 0 :=\n\u27e8\u03bb h, by rw [trailing_degree, \u2190 min_eq_inf_with_top] at h;\n  exact support_eq_empty.1 (min_eq_none.1 h),\n\u03bb h, h.symm \u25b8 rfl\u27e9\n\nlemma trailing_degree_eq_nat_trailing_degree (hp : p \u2260 0) :\n  trailing_degree p = (nat_trailing_degree p : with_top \u2115) :=\nlet \u27e8n, hn\u27e9 :=\n  not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt trailing_degree_eq_top.1 hp)) in\nhave hn : trailing_degree p = some n := not_not.1 hn,\nby rw [nat_trailing_degree, hn]; refl\n\nlemma trailing_degree_eq_iff_nat_trailing_degree_eq {p : polynomial R} {n : \u2115} (hp : p \u2260 0) :\n  p.trailing_degree = n \u2194 p.nat_trailing_degree = n :=\nby rw [trailing_degree_eq_nat_trailing_degree hp, with_top.coe_eq_coe]\n\nlemma trailing_degree_eq_iff_nat_trailing_degree_eq_of_pos {p : polynomial R} {n : \u2115} (hn : 0 < n) :\n  p.trailing_degree = n \u2194 p.nat_trailing_degree = n :=\nbegin\n  split,\n  { intro H, rwa \u2190 trailing_degree_eq_iff_nat_trailing_degree_eq, rintro rfl,\n    rw trailing_degree_zero at H, exact option.no_confusion H },\n  { intro H, rwa trailing_degree_eq_iff_nat_trailing_degree_eq, rintro rfl,\n    rw nat_trailing_degree_zero at H, rw H at hn, exact lt_irrefl _ hn }\nend\n\nlemma nat_trailing_degree_eq_of_trailing_degree_eq_some {p : polynomial R} {n : \u2115}\n  (h : trailing_degree p = n) : nat_trailing_degree p = n :=\nhave hp0 : p \u2260 0, from \u03bb hp0, by rw hp0 at h; exact option.no_confusion h,\noption.some_inj.1 $ show (nat_trailing_degree p : with_top \u2115) = n,\n  by rwa [\u2190 trailing_degree_eq_nat_trailing_degree hp0]\n\n@[simp] lemma nat_trailing_degree_le_trailing_degree :\n  \u2191(nat_trailing_degree p) \u2264 trailing_degree p :=\nbegin\n  by_cases hp : p = 0, { rw hp, exact le_top },\n  rw [trailing_degree_eq_nat_trailing_degree hp],\n  exact le_refl _\nend\n\nlemma nat_trailing_degree_eq_of_trailing_degree_eq [semiring S] {q : polynomial S}\n  (h : trailing_degree p = trailing_degree q) :\nnat_trailing_degree p = nat_trailing_degree q :=\nby unfold nat_trailing_degree; rw h\n\nlemma le_trailing_degree_of_ne_zero (h : coeff p n \u2260 0) : trailing_degree p \u2264 n :=\nshow @has_le.le (with_top \u2115) _ (p.support.inf some : with_top \u2115) (some n : with_top \u2115),\nfrom finset.inf_le (finsupp.mem_support_iff.2 h)\n\nlemma nat_trailing_degree_le_of_ne_zero (h : coeff p n \u2260 0) : nat_trailing_degree p \u2264 n :=\nbegin\n  rw [\u2190 with_top.coe_le_coe, \u2190 trailing_degree_eq_nat_trailing_degree],\n  { exact le_trailing_degree_of_ne_zero h, },\n  { assume h, subst h, exact h rfl }\nend\n\nlemma trailing_degree_le_trailing_degree (h : coeff q (nat_trailing_degree p) \u2260 0) :\n  trailing_degree q \u2264 trailing_degree p :=\nbegin\n  by_cases hp : p = 0,\n  { rw hp, exact le_top },\n  { rw trailing_degree_eq_nat_trailing_degree hp, exact le_trailing_degree_of_ne_zero h }\nend\n\nlemma trailing_degree_ne_of_nat_trailing_degree_ne {n : \u2115} :\n  p.nat_trailing_degree \u2260 n \u2192 trailing_degree p \u2260 n :=\nmt $ \u03bb h, by rw [nat_trailing_degree, h, option.get_or_else_coe]\n\ntheorem nat_trailing_degree_le_of_trailing_degree_le {n : \u2115} {hp : p \u2260 0}\n  (H : (n : with_top \u2115) \u2264 trailing_degree p) : n \u2264 nat_trailing_degree p :=\nbegin\n  rw trailing_degree_eq_nat_trailing_degree hp at H,\n  exact with_top.coe_le_coe.mp H,\nend\n\n\n\n@[simp] lemma trailing_degree_monomial (ha : a \u2260 0) : trailing_degree (monomial n a) = n :=\nby rw [trailing_degree, support_monomial _ _ ha, inf_singleton, with_top.some_eq_coe]\n\nlemma nat_trailing_degree_monomial (ha : a \u2260 0) : nat_trailing_degree (monomial n a) = n :=\nby rw [nat_trailing_degree, trailing_degree_monomial ha]; refl\n\nlemma nat_trailing_degree_monomial_le : nat_trailing_degree (monomial n a) \u2264 n :=\nif ha : a = 0 then by simp [ha] else (nat_trailing_degree_monomial ha).le\n\nlemma le_trailing_degree_monomial : \u2191n \u2264 trailing_degree (monomial n a) :=\nif ha : a = 0 then by simp [ha] else (trailing_degree_monomial ha).ge\n\n@[simp] lemma trailing_degree_C (ha : a \u2260 0) : trailing_degree (C a) = (0 : with_top \u2115) :=\ntrailing_degree_monomial ha\n\nlemma le_trailing_degree_C : (0 : with_top \u2115) \u2264 trailing_degree (C a) :=\nle_trailing_degree_monomial\n\nlemma trailing_degree_one_le : (0 : with_top \u2115) \u2264 trailing_degree (1 : polynomial R) :=\nby rw [\u2190 C_1]; exact le_trailing_degree_C\n\n@[simp] lemma nat_trailing_degree_C (a : R) : nat_trailing_degree (C a) = 0 :=\nnonpos_iff_eq_zero.1 nat_trailing_degree_monomial_le\n\n@[simp] lemma nat_trailing_degree_one : nat_trailing_degree (1 : polynomial R) = 0 :=\nnat_trailing_degree_C 1\n\n@[simp] lemma nat_trailing_degree_nat_cast (n : \u2115) : nat_trailing_degree (n : polynomial R) = 0 :=\nby simp only [\u2190C_eq_nat_cast, nat_trailing_degree_C]\n\n@[simp] lemma trailing_degree_C_mul_X_pow (n : \u2115) (ha : a \u2260 0) :\n  trailing_degree (C a * X ^ n) = n :=\nby rw [C_mul_X_pow_eq_monomial, trailing_degree_monomial ha]\n\nlemma le_trailing_degree_C_mul_X_pow (n : \u2115) (a : R) :\n  (n : with_top \u2115) \u2264 trailing_degree (C a * X ^ n) :=\nby { rw C_mul_X_pow_eq_monomial, exact le_trailing_degree_monomial }\n\nlemma coeff_eq_zero_of_trailing_degree_lt (h : (n : with_top \u2115) < trailing_degree p) :\n  coeff p n = 0 :=\nnot_not.1 (mt le_trailing_degree_of_ne_zero (not_le_of_gt h))\n\nlemma coeff_eq_zero_of_lt_nat_trailing_degree {p : polynomial R} {n : \u2115}\n  (h : n < p.nat_trailing_degree) :\n  p.coeff n = 0 :=\nbegin\n  apply coeff_eq_zero_of_trailing_degree_lt,\n  by_cases hp : p = 0,\n  { subst hp, exact with_top.coe_lt_top n, },\n  { rwa [trailing_degree_eq_nat_trailing_degree hp, with_top.coe_lt_coe] },\nend\n\n@[simp] lemma coeff_nat_trailing_degree_pred_eq_zero {p : polynomial R}\n  {hp : (0 : with_top \u2115) < nat_trailing_degree p} : p.coeff (p.nat_trailing_degree - 1) = 0 :=\ncoeff_eq_zero_of_lt_nat_trailing_degree $ nat.sub_lt\n  ((with_top.zero_lt_coe (nat_trailing_degree p)).mp hp) nat.one_pos\n\ntheorem le_trailing_degree_X_pow (n : \u2115) :\n  (n : with_top \u2115) \u2264 trailing_degree (X^n : polynomial R) :=\nby simpa only [C_1, one_mul] using le_trailing_degree_C_mul_X_pow n (1:R)\n\ntheorem le_trailing_degree_X : (1 : with_top \u2115) \u2264 trailing_degree (X : polynomial R) :=\nle_trailing_degree_monomial\n\nlemma nat_trailing_degree_X_le : (X : polynomial R).nat_trailing_degree \u2264 1 :=\nnat_trailing_degree_monomial_le\n\n@[simp] lemma trailing_coeff_eq_zero : trailing_coeff p = 0 \u2194 p = 0 :=\n\u27e8\u03bb h, by_contradiction $ \u03bb hp, mt mem_support_iff.1\n  (not_not.2 h) (mem_of_min (trailing_degree_eq_nat_trailing_degree hp)),\n\u03bb h, h.symm \u25b8 leading_coeff_zero\u27e9\n\nlemma trailing_coeff_nonzero_iff_nonzero : trailing_coeff p \u2260 0 \u2194 p \u2260 0 :=\nnot_congr trailing_coeff_eq_zero\n\nlemma nat_trailing_degree_mem_support_of_nonzero : p \u2260 0 \u2192 nat_trailing_degree p \u2208 p.support :=\n(mem_support_iff.mpr \u2218 trailing_coeff_nonzero_iff_nonzero.mpr)\n\nlemma nat_trailing_degree_le_of_mem_supp (a : \u2115) :\n  a \u2208 p.support \u2192 nat_trailing_degree p \u2264 a:=\nnat_trailing_degree_le_of_ne_zero \u2218 mem_support_iff.mp\n\nlemma nat_trailing_degree_eq_support_min' (h : p \u2260 0) :\n  nat_trailing_degree p = p.support.min' (nonempty_support_iff.mpr h) :=\nbegin\n  apply le_antisymm,\n  { apply le_min',\n    intros y hy,\n    exact nat_trailing_degree_le_of_mem_supp y hy },\n  { apply finset.min'_le,\n    exact mem_support_iff.mpr (trailing_coeff_nonzero_iff_nonzero.mpr h), },\nend\n\nlemma nat_trailing_degree_le_nat_degree (p : polynomial R) :\n  p.nat_trailing_degree \u2264 p.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, nat_degree_zero, nat_trailing_degree_zero] },\n  { exact le_nat_degree_of_ne_zero (mt trailing_coeff_eq_zero.mp hp) },\nend\n\nlemma nat_trailing_degree_mul_X_pow {p : polynomial R} (hp : p \u2260 0) (n : \u2115) :\n  (p * X ^ n).nat_trailing_degree = p.nat_trailing_degree + n :=\nbegin\n  apply le_antisymm,\n  { refine nat_trailing_degree_le_of_ne_zero (\u03bb h, mt trailing_coeff_eq_zero.mp hp _),\n    rwa [trailing_coeff, \u2190coeff_mul_X_pow] },\n  { rw [nat_trailing_degree_eq_support_min' (\u03bb h, hp (mul_X_pow_eq_zero h)), finset.le_min'_iff],\n    intros y hy,\n    have key : n \u2264 y,\n    { rw [mem_support_iff, coeff_mul_X_pow'] at hy,\n      exact by_contra (\u03bb h, hy (if_neg h)) },\n    rw [mem_support_iff, coeff_mul_X_pow', if_pos key] at hy,\n    exact (nat.add_le_to_le_sub _ key).mpr (nat_trailing_degree_le_of_ne_zero hy) },\nend\n\nend semiring\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : polynomial R}\n\n@[simp] lemma trailing_degree_one : trailing_degree (1 : polynomial R) = (0 : with_top \u2115) :=\ntrailing_degree_C one_ne_zero\n\n@[simp] lemma trailing_degree_X : trailing_degree (X : polynomial R) = 1 :=\ntrailing_degree_monomial one_ne_zero\n\n@[simp] lemma nat_trailing_degree_X : (X : polynomial R).nat_trailing_degree = 1 :=\nnat_trailing_degree_monomial one_ne_zero\n\nend nonzero_semiring\n\nsection ring\nvariables [ring R]\n\n@[simp] lemma trailing_degree_neg (p : polynomial R) : trailing_degree (-p) = trailing_degree p :=\nby unfold trailing_degree; rw support_neg\n\n@[simp] lemma nat_trailing_degree_neg (p : polynomial R) :\n  nat_trailing_degree (-p) = nat_trailing_degree p :=\nby simp [nat_trailing_degree]\n\n@[simp] lemma nat_trailing_degree_int_cast (n : \u2124) : nat_trailing_degree (n : polynomial R) = 0 :=\nby simp only [\u2190C_eq_int_cast, nat_trailing_degree_C]\n\nend ring\n\nsection semiring\nvariables [semiring R]\n\n/-- The second-lowest coefficient, or 0 for constants -/\ndef next_coeff_up (p : polynomial R) : R :=\nif p.nat_trailing_degree = 0 then 0 else p.coeff (p.nat_trailing_degree + 1)\n\n@[simp]\nlemma next_coeff_up_C_eq_zero (c : R) :\n  next_coeff_up (C c) = 0 := by { rw next_coeff_up, simp }\n\nlemma next_coeff_up_of_pos_nat_trailing_degree (p : polynomial R) (hp : 0 < p.nat_trailing_degree) :\n  next_coeff_up p = p.coeff (p.nat_trailing_degree + 1) :=\nby { rw [next_coeff_up, if_neg], contrapose! hp, simpa }\n\nend semiring\n\nsection semiring\nvariables [semiring R] {p q : polynomial R} {\u03b9 : Type*}\n\nlemma coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt\n  (h : trailing_degree p < trailing_degree q) :\n  coeff q (nat_trailing_degree p) = 0 :=\ncoeff_eq_zero_of_trailing_degree_lt $ nat_trailing_degree_le_trailing_degree.trans_lt h\n\nlemma ne_zero_of_trailing_degree_lt {n : with_top \u2115} (h : trailing_degree p < n) : p \u2260 0 :=\n\u03bb h\u2080, h.not_le (by simp [h\u2080])\n\nend semiring\nend polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/polynomial/degree/trailing_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.7212904025217881}}
{"text": "/-\nCopyright (c) 2021 Chris Birkbeck. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Birkbeck\n-/\nimport linear_algebra.general_linear_group\nimport linear_algebra.matrix.nonsingular_inverse\nimport linear_algebra.matrix.special_linear_group\n\n/-!\n# The General Linear group $GL(n, R)$\n\nThis file defines the elements of the General Linear group `general_linear_group n R`,\nconsisting of all invertible `n` by `n` `R`-matrices.\n\n## Main definitions\n\n* `matrix.general_linear_group` is the type of matrices over R which are units in the matrix ring.\n* `matrix.GL_pos` gives the subgroup of matrices with\n  positive determinant (over a linear ordered ring).\n\n## Tags\n\nmatrix group, group, matrix inverse\n-/\n\nnamespace matrix\nuniverses u v\nopen_locale matrix\nopen linear_map\n\n-- disable this instance so we do not accidentally use it in lemmas.\nlocal attribute [-instance] special_linear_group.has_coe_to_fun\n\n/-- `GL n R` is the group of `n` by `n` `R`-matrices with unit determinant.\nDefined as a subtype of matrices-/\nabbreviation general_linear_group (n : Type u) (R : Type v)\n  [decidable_eq n] [fintype n] [comm_ring R] : Type* := (matrix n n R)\u02e3\n\nnotation `GL` := general_linear_group\n\nnamespace general_linear_group\n\nvariables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]\n\n/-- The determinant of a unit matrix is itself a unit. -/\n@[simps]\ndef det : GL n R \u2192* R\u02e3 :=\n{ to_fun := \u03bb A,\n  { val := (\u2191A : matrix n n R).det,\n    inv := (\u2191(A\u207b\u00b9) : matrix n n R).det,\n    val_inv := by rw [\u2190det_mul, \u2190mul_eq_mul, A.mul_inv, det_one],\n    inv_val := by rw [\u2190det_mul, \u2190mul_eq_mul, A.inv_mul, det_one]},\n  map_one' := units.ext det_one,\n  map_mul' := \u03bb A B, units.ext $ det_mul _ _ }\n\n/--The `GL n R` and `general_linear_group R n` groups are multiplicatively equivalent-/\ndef to_lin : (GL n R) \u2243* (linear_map.general_linear_group R (n \u2192 R)) :=\nunits.map_equiv to_lin_alg_equiv'.to_mul_equiv\n\n/--Given a matrix with invertible determinant we get an element of `GL n R`-/\ndef mk' (A : matrix n n R) (h : invertible (matrix.det A)) : GL n R :=\nunit_of_det_invertible A\n\n/--Given a matrix with unit determinant we get an element of `GL n R`-/\nnoncomputable def mk'' (A : matrix n n R) (h : is_unit (matrix.det A)) : GL n R :=\nnonsing_inv_unit A h\n\n/--Given a matrix with non-zero determinant over a field, we get an element of `GL n K`-/\ndef mk_of_det_ne_zero {K : Type*} [field K] (A : matrix n n K) (h : matrix.det A \u2260 0) :\n  GL n K :=\nmk' A (invertible_of_nonzero h)\n\nlemma ext_iff (A B : GL n R) : A = B \u2194 (\u2200 i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :=\nunits.ext_iff.trans matrix.ext_iff.symm\n\n/-- Not marked `@[ext]` as the `ext` tactic already solves this. -/\nlemma ext \u2983A B : GL n R\u2984 (h : \u2200 i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :\n  A = B :=\nunits.ext $ matrix.ext h\n\nsection coe_lemmas\n\nvariables (A B : GL n R)\n\n@[simp] lemma coe_mul : \u2191(A * B) = (\u2191A : matrix n n R) \u2b1d (\u2191B : matrix n n R) := rfl\n\n@[simp] lemma coe_one : \u2191(1 : GL n R) = (1 : matrix n n R) := rfl\n\nlemma coe_inv : \u2191(A\u207b\u00b9) = (\u2191A : matrix n n R)\u207b\u00b9 :=\nbegin\n  letI := A.invertible,\n  exact inv_of_eq_nonsing_inv (\u2191A : matrix n n R),\nend\n\n/-- An element of the matrix general linear group on `(n) [fintype n]` can be considered as an\nelement of the endomorphism general linear group on `n \u2192 R`. -/\ndef to_linear : general_linear_group n R \u2243* linear_map.general_linear_group R (n \u2192 R) :=\nunits.map_equiv matrix.to_lin_alg_equiv'.to_ring_equiv.to_mul_equiv\n\n-- Note that without the `@` and `\u2039_\u203a`, lean infers `\u03bb a b, _inst a b` instead of `_inst` as the\n-- decidability argument, which prevents `simp` from obtaining the instance by unification.\n-- These `\u03bb a b, _inst a b` terms also appear in the type of `A`, but simp doesn't get confused by\n-- them so for now we do not care.\n@[simp] lemma coe_to_linear :\n  (@to_linear n \u2039_\u203a \u2039_\u203a _ _ A : (n \u2192 R) \u2192\u2097[R] (n \u2192 R)) = matrix.mul_vec_lin A :=\nrfl\n\n@[simp] lemma to_linear_apply (v : n \u2192 R) :\n  (@to_linear n \u2039_\u203a \u2039_\u203a _ _ A) v = matrix.mul_vec_lin \u2191A v :=\nrfl\n\nend coe_lemmas\n\nend general_linear_group\n\nnamespace special_linear_group\n\nvariables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]\n\ninstance has_coe_to_general_linear_group : has_coe (special_linear_group n R) (GL n R) :=\n\u27e8\u03bb A, \u27e8\u2191A, \u2191(A\u207b\u00b9), congr_arg coe (mul_right_inv A), congr_arg coe (mul_left_inv A)\u27e9\u27e9\n\n@[simp] lemma coe_to_GL_det (g : special_linear_group n R) : (g : GL n R).det = 1 :=\nunits.ext g.prop\n\nend special_linear_group\n\nsection\n\nvariables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]\n\nsection\nvariables (n R)\n\n/-- This is the subgroup of `nxn` matrices with entries over a\nlinear ordered ring and positive determinant. -/\ndef GL_pos : subgroup (GL n R) :=\n(units.pos_subgroup R).comap general_linear_group.det\nend\n\n@[simp] lemma mem_GL_pos (A : GL n R) : A \u2208 GL_pos n R \u2194 0 < (A.det : R) := iff.rfl\n\nlemma GL_pos.det_ne_zero (A : GL_pos n R) : (A : matrix n n R).det \u2260 0 := ne_of_gt A.prop\n\nend\n\nsection has_neg\n\nvariables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]\n[fact (even (fintype.card n))]\n\n/-- Formal operation of negation on general linear group on even cardinality `n` given by negating\neach element. -/\ninstance : has_neg (GL_pos n R) :=\n\u27e8\u03bb g, \u27e8-g, begin\n    rw [mem_GL_pos, general_linear_group.coe_det_apply, units.coe_neg, det_neg,\n      (fact.out $ even $ fintype.card n).neg_one_pow, one_mul],\n    exact g.prop,\n  end\u27e9\u27e9\n\n@[simp] lemma GL_pos.coe_neg_GL (g : GL_pos n R) : \u2191(-g) = -(g : GL n R) := rfl\n@[simp] lemma GL_pos.coe_neg (g : GL_pos n R) : \u2191(-g) = -(g : matrix n n R) := rfl\n\n@[simp] lemma GL_pos.coe_neg_apply (g : GL_pos n R) (i j : n) :\n  (\u2191(-g) : matrix n n R) i j = -((\u2191g : matrix n n R) i j) :=\nrfl\n\ninstance : has_distrib_neg (GL_pos n R) :=\nsubtype.coe_injective.has_distrib_neg _ GL_pos.coe_neg_GL (GL_pos n R).coe_mul\n\nend has_neg\n\nnamespace special_linear_group\n\nvariables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [linear_ordered_comm_ring R]\n\n/-- `special_linear_group n R` embeds into `GL_pos n R` -/\ndef to_GL_pos : special_linear_group n R \u2192* GL_pos n R :=\n{ to_fun := \u03bb A, \u27e8(A : GL n R), show 0 < (\u2191A : matrix n n R).det, from A.prop.symm \u25b8 zero_lt_one\u27e9,\n  map_one' := subtype.ext $ units.ext $ rfl,\n  map_mul' := \u03bb A\u2081 A\u2082, subtype.ext $ units.ext $ rfl }\n\ninstance : has_coe (special_linear_group n R) (GL_pos n R) := \u27e8to_GL_pos\u27e9\n\nlemma coe_eq_to_GL_pos : (coe : special_linear_group n R \u2192 GL_pos n R) = to_GL_pos := rfl\n\nlemma to_GL_pos_injective :\n  function.injective (to_GL_pos : special_linear_group n R \u2192 GL_pos n R) :=\n(show function.injective ((coe : GL_pos n R \u2192 matrix n n R) \u2218 to_GL_pos),\n from subtype.coe_injective).of_comp\n\n/-- Coercing a `special_linear_group` via `GL_pos` and `GL` is the same as coercing striaght to a\nmatrix. -/\n@[simp]\nlemma coe_GL_pos_coe_GL_coe_matrix (g : special_linear_group n R) :\n    (\u2191(\u2191(\u2191g : GL_pos n R) : GL n R) : matrix n n R) = \u2191g := rfl\n\n@[simp] lemma coe_to_GL_pos_to_GL_det (g : special_linear_group n R) :\n  ((g : GL_pos n R) : GL n R).det = 1 :=\nunits.ext g.prop\n\nvariable [fact (even (fintype.card n))]\n\n@[norm_cast] lemma coe_GL_pos_neg (g : special_linear_group n R) :\n  \u2191(-g) = -(\u2191g : GL_pos n R) := subtype.ext $ units.ext rfl\n\nend special_linear_group\n\nsection examples\n\n/-- The matrix [a, -b; b, a] (inspired by multiplication by a complex number); it is an element of\n$GL_2(R)$ if `a ^ 2 + b ^ 2` is nonzero. -/\n@[simps coe {fully_applied := ff}]\ndef plane_conformal_matrix {R} [field R] (a b : R) (hab : a ^ 2 + b ^ 2 \u2260 0) :\n  matrix.general_linear_group (fin 2) R :=\ngeneral_linear_group.mk_of_det_ne_zero !![a, -b; b, a]\n  (by simpa [det_fin_two, sq] using hab)\n\n/- TODO: Add Iwasawa matrices `n_x=!![1,x; 0,1]`, `a_t=!![exp(t/2),0;0,exp(-t/2)]` and\n  `k_\u03b8=!![cos \u03b8, sin \u03b8; -sin \u03b8, cos \u03b8]`\n-/\n\nend examples\n\nnamespace general_linear_group\nvariables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]\n\n-- this section should be last to ensure we do not use it in lemmas\nsection coe_fn_instance\n\n/-- This instance is here for convenience, but is not the simp-normal form. -/\ninstance : has_coe_to_fun (GL n R) (\u03bb _, n \u2192 n \u2192 R) :=\n{ coe := \u03bb A, A.val }\n\n@[simp] lemma coe_fn_eq_coe (A : GL n R) : \u21d1A = (\u2191A : matrix n n R) := rfl\n\nend coe_fn_instance\n\nend general_linear_group\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/general_linear_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.721179853961376}}
{"text": "-- Introduccion_de_la_conjuncion.lean\n-- Introducci\u00f3n de la conjunci\u00f3n.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 12 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- En este relaci\u00f3n se muestra distintas formas de demostrar un teorema\n-- con introducci\u00f3n de la conjunci\u00f3n.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones:\n-- 1. Importar la librer\u00eda de t\u00e1cticas.\n-- 2. Declarar P y Q como variables sobre proposiciones. \n-- ----------------------------------------------------------------------\n\nimport tactic            -- 1\nvariables (P Q : Prop)   -- 2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que de P y (P \u2192 Q) se deduce P \u2227 Q\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nbegin\n  split,\n  { exact hP },\n  { apply hPQ,\n    exact hP },\nend\n\n-- Comentario\n-- ----------\n\n-- La t\u00e1ctica split, cuando la conclusi\u00f3n es una conjunci\u00f3n, aplica la\n-- regla de eliminaci\u00f3n de la conjunci\u00f3n; es decir, si la conclusi\u00f3n es \n-- (P \u2227 Q), entonces crea dos subojetivos: el primero en el que la\n-- conclusi\u00f3n es P y el segundo donde es Q.\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nbegin\n  split,\n  { exact hP },\n  { exact hPQ hP },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nbegin\n  have hQ : Q := hPQ hP,\n  show P \u2227 Q, by exact \u27e8hP, hQ\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nbegin\n  show P \u2227 Q, by exact \u27e8hP, hPQ hP\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nbegin\n  exact \u27e8hP, hPQ hP\u27e9,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nby exact \u27e8hP, hPQ hP\u27e9\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\n\u27e8hP, hPQ hP\u27e9\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nand.intro hP (hPQ hP)\n\n-- Comentario: Se ha usado el lema\n-- + and.intro : P \u2192 Q \u2192 P \u2227 Q \n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (hP : P) \n  (hPQ : P \u2192 Q) \n  : P \u2227 Q :=\nby tauto\n\n\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/2_Conectivas/Introduccion_de_la_conjuncion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8723473697001441, "lm_q1q2_score": 0.7211798516087295}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\n-- Sum a sequence by grouping adjacent terms.\n-- TODO: move to mathlib.\nlemma sum_pairs (n : \u2115) (f : \u2115 \u2192 \u211a) :\n  \u2211 k in (finset.range (2 * n)), f k = \u2211 k in (finset.range n), (f (2 * k) + f (2 * k + 1)) :=\nbegin\n  induction n with pn hpn,\n  { simp only [finset.sum_empty, finset.range_zero, mul_zero] },\n  { have hs: (2 * pn.succ) = (2 * pn).succ.succ := rfl,\n    rw [finset.sum_range_succ, \u2190hpn, hs, finset.sum_range_succ, finset.sum_range_succ],\n    ring },\nend\n\ntheorem aime_1984_p1\n  (u : \u2115 \u2192 \u211a)\n  (h\u2080 : \u2200 n, u (n + 1) = u n + 1)\n  (h\u2081 : \u2211 k in finset.range 98, u k.succ = 137) :\n  \u2211 k in finset.range 49, u (2 * k.succ) = 93 :=\nbegin\n  -- We will use sum_pairs and h\u2080 to rewrite h\u2081 and the goal in terms of the quantity\n  -- \u2211 k in finset.range 49, u (2 * k + 1).\n\n  have h\u2082 : \u2200 k, k \u2208 finset.range 49 \u2192 u (2 * k + 1 + 1) = u (2 * k + 1) + 1 :=\n  by { intros k hk, exact h\u2080 (2 * k + 1) },\n\n  have h\u2083: \u2211 (x : \u2115) in finset.range 49, (1:\u211a) = 49 := by simp only [mul_one, nat.cast_bit0, finset.sum_const, nsmul_eq_mul, nat.cast_bit1, finset.card_range, nat.cast_one],\n\n  have h98 : 98 = 2 * 49 := by norm_num,\n\n  rw [h98, sum_pairs, finset.sum_add_distrib, finset.sum_congr rfl h\u2082,\n     finset.sum_add_distrib, h\u2083, \u2190add_assoc] at h\u2081,\n\n  have h\u2084 : \u2211 (k : \u2115) in finset.range 49, u (2 * k.succ)\n          = \u2211 (k : \u2115) in finset.range 49, (u (2 * k + 1) + 1) :=\n    finset.sum_congr rfl h\u2082,\n  rw [h\u2084, finset.sum_add_distrib, h\u2083],\n\n  linarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/aime/1984/p1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7211796269253065}}
{"text": "/-\nCopyright (c) 2021 Martin Zinkevich. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Martin Zinkevich, R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module measure_theory.pi_system\n! leanprover-community/mathlib commit 98e83c3d541c77cdb7da20d79611a780ff8e7d90\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Logic.Encodable.Lattice\nimport Mathlib.MeasureTheory.MeasurableSpaceDef\n\n/-!\n# Induction principles for measurable sets, related to \u03c0-systems and \u03bb-systems.\n\n## Main statements\n\n* The main theorem of this file is Dynkin's \u03c0-\u03bb theorem, which appears\n  here as an induction principle `induction_on_inter`. Suppose `s` is a\n  collection of subsets of `\u03b1` such that the intersection of two members\n  of `s` belongs to `s` whenever it is nonempty. Let `m` be the \u03c3-algebra\n  generated by `s`. In order to check that a predicate `C` holds on every\n  member of `m`, it suffices to check that `C` holds on the members of `s` and\n  that `C` is preserved by complementation and *disjoint* countable\n  unions.\n\n* The proof of this theorem relies on the notion of `IsPiSystem`, i.e., a collection of sets\n  which is closed under binary non-empty intersections. Note that this is a small variation around\n  the usual notion in the literature, which often requires that a \u03c0-system is non-empty, and closed\n  also under disjoint intersections. This variation turns out to be convenient for the\n  formalization.\n\n* The proof of Dynkin's \u03c0-\u03bb theorem also requires the notion of `DynkinSystem`, i.e., a collection\n  of sets which contains the empty set, is closed under complementation and under countable union\n  of pairwise disjoint sets. The disjointness condition is the only difference with `\u03c3`-algebras.\n\n* `generatePiSystem g` gives the minimal \u03c0-system containing `g`.\n  This can be considered a Galois insertion into both measurable spaces and sets.\n\n* `generateFrom_generatePiSystem_eq` proves that if you start from a collection of sets `g`,\n  take the generated \u03c0-system, and then the generated \u03c3-algebra, you get the same result as\n  the \u03c3-algebra generated from `g`. This is useful because there are connections between\n  independent sets that are \u03c0-systems and the generated independent spaces.\n\n* `mem_generatePiSystem_union\u1d62_elim` and `mem_generatePiSystem_union\u1d62_elim'` show that any\n  element of the \u03c0-system generated from the union of a set of \u03c0-systems can be\n  represented as the intersection of a finite number of elements from these sets.\n\n* `piUnion\u1d62Inter` defines a new \u03c0-system from a family of \u03c0-systems `\u03c0 : \u03b9 \u2192 Set (Set \u03b1)` and a\n  set of indices `S : Set \u03b9`. `piUnion\u1d62Inter \u03c0 S` is the set of sets that can be written\n  as `\u22c2 x \u2208 t, f x` for some finset `t \u2208 S` and sets `f x \u2208 \u03c0 x`.\n\n## Implementation details\n\n* `IsPiSystem` is a predicate, not a type. Thus, we don't explicitly define the galois\n  insertion, nor do we define a complete lattice. In theory, we could define a complete\n  lattice and galois insertion on the subtype corresponding to `IsPiSystem`.\n-/\n\n\nopen MeasurableSpace Set\n\nopen Classical MeasureTheory\n\n/-- A \u03c0-system is a collection of subsets of `\u03b1` that is closed under binary intersection of\n  non-disjoint sets. Usually it is also required that the collection is nonempty, but we don't do\n  that here. -/\ndef IsPiSystem {\u03b1} (C : Set (Set \u03b1)) : Prop :=\n  \u2200\u1d49 (s \u2208 C) (t \u2208 C), (s \u2229 t : Set \u03b1).Nonempty \u2192 s \u2229 t \u2208 C\n#align is_pi_system IsPiSystem\n\nnamespace MeasurableSpace\n\ntheorem isPiSystem_measurableSet {\u03b1 : Type _} [MeasurableSpace \u03b1] :\n    IsPiSystem { s : Set \u03b1 | MeasurableSet s } := fun _ hs _ ht _ => hs.inter ht\n#align measurable_space.is_pi_system_measurable_set MeasurableSpace.isPiSystem_measurableSet\n\nend MeasurableSpace\n\ntheorem IsPiSystem.singleton {\u03b1} (S : Set \u03b1) : IsPiSystem ({S} : Set (Set \u03b1)) := by\n  intro s h_s t h_t _\n  rw [Set.mem_singleton_iff.1 h_s, Set.mem_singleton_iff.1 h_t, Set.inter_self,\n    Set.mem_singleton_iff]\n#align is_pi_system.singleton IsPiSystem.singleton\n\ntheorem IsPiSystem.insert_empty {\u03b1} {S : Set (Set \u03b1)} (h_pi : IsPiSystem S) :\n    IsPiSystem (insert \u2205 S) := by\n  intro s hs t ht hst\n  cases' hs with hs hs\n  \u00b7 simp [hs]\n  \u00b7 cases' ht with ht ht\n    \u00b7 simp [ht]\n    \u00b7 exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst)\n#align is_pi_system.insert_empty IsPiSystem.insert_empty\n\ntheorem IsPiSystem.insert_univ {\u03b1} {S : Set (Set \u03b1)} (h_pi : IsPiSystem S) :\n    IsPiSystem (insert Set.univ S) := by\n  intro s hs t ht hst\n  cases' hs with hs hs\n  \u00b7 cases' ht with ht ht <;> simp [hs, ht]\n  \u00b7 cases' ht with ht ht\n    \u00b7 simp [hs, ht]\n    \u00b7 exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst)\n#align is_pi_system.insert_univ IsPiSystem.insert_univ\n\ntheorem IsPiSystem.comap {\u03b1 \u03b2} {S : Set (Set \u03b2)} (h_pi : IsPiSystem S) (f : \u03b1 \u2192 \u03b2) :\n    IsPiSystem { s : Set \u03b1 | \u2203 t \u2208 S, f \u207b\u00b9' t = s } := by\n  rintro _ \u27e8s, hs_mem, rfl\u27e9 _ \u27e8t, ht_mem, rfl\u27e9 hst\n  rw [\u2190 Set.preimage_inter] at hst\u22a2\n  refine' \u27e8s \u2229 t, h_pi s hs_mem t ht_mem _, rfl\u27e9\n  by_contra h\n  rw [Set.not_nonempty_iff_eq_empty] at h\n  rw [h] at hst\n  simp at hst\n#align is_pi_system.comap IsPiSystem.comap\n\ntheorem isPiSystem_union\u1d62_of_directed_le {\u03b1 \u03b9} (p : \u03b9 \u2192 Set (Set \u03b1))\n    (hp_pi : \u2200 n, IsPiSystem (p n)) (hp_directed : Directed (\u00b7 \u2264 \u00b7) p) :\n    IsPiSystem (\u22c3 n, p n) := by\n  intro t1 ht1 t2 ht2 h\n  rw [Set.mem_union\u1d62] at ht1 ht2\u22a2\n  cases' ht1 with n ht1\n  cases' ht2 with m ht2\n  obtain \u27e8k, hpnk, hpmk\u27e9 : \u2203 k, p n \u2264 p k \u2227 p m \u2264 p k := hp_directed n m\n  exact \u27e8k, hp_pi k t1 (hpnk ht1) t2 (hpmk ht2) h\u27e9\n#align is_pi_system_Union_of_directed_le isPiSystem_union\u1d62_of_directed_le\n\ntheorem isPiSystem_union\u1d62_of_monotone {\u03b1 \u03b9} [SemilatticeSup \u03b9] (p : \u03b9 \u2192 Set (Set \u03b1))\n    (hp_pi : \u2200 n, IsPiSystem (p n)) (hp_mono : Monotone p) : IsPiSystem (\u22c3 n, p n) :=\n  isPiSystem_union\u1d62_of_directed_le p hp_pi (Monotone.directed_le hp_mono)\n#align is_pi_system_Union_of_monotone isPiSystem_union\u1d62_of_monotone\n\nsection Order\n\nvariable {\u03b1 : Type _} {\u03b9 \u03b9' : Sort _} [LinearOrder \u03b1]\n\ntheorem isPiSystem_image_Iio (s : Set \u03b1) : IsPiSystem (Iio '' s) := by\n  rintro _ \u27e8a, ha, rfl\u27e9 _ \u27e8b, hb, rfl\u27e9 -\n  exact \u27e8a \u2293 b, inf_ind a b ha hb, Iio_inter_Iio.symm\u27e9\n#align is_pi_system_image_Iio isPiSystem_image_Iio\n\ntheorem isPiSystem_Iio : IsPiSystem (range Iio : Set (Set \u03b1)) :=\n  @image_univ \u03b1 _ Iio \u25b8 isPiSystem_image_Iio univ\n#align is_pi_system_Iio isPiSystem_Iio\n\ntheorem isPiSystem_image_Ioi (s : Set \u03b1) : IsPiSystem (Ioi '' s) :=\n  @isPiSystem_image_Iio \u03b1\u1d52\u1d48 _ s\n#align is_pi_system_image_Ioi isPiSystem_image_Ioi\n\ntheorem isPiSystem_Ioi : IsPiSystem (range Ioi : Set (Set \u03b1)) :=\n  @image_univ \u03b1 _ Ioi \u25b8 isPiSystem_image_Ioi univ\n#align is_pi_system_Ioi isPiSystem_Ioi\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ixx_mem {Ixx : \u03b1 \u2192 \u03b1 \u2192 Set \u03b1} {p : \u03b1 \u2192 \u03b1 \u2192 Prop}\n    (Hne : \u2200 {a b}, (Ixx a b).Nonempty \u2192 p a b)\n    (Hi : \u2200 {a\u2081 b\u2081 a\u2082 b\u2082}, Ixx a\u2081 b\u2081 \u2229 Ixx a\u2082 b\u2082 = Ixx (max a\u2081 a\u2082) (min b\u2081 b\u2082)) (s t : Set \u03b1) :\n    IsPiSystem { S | \u2203\u1d49 (l \u2208 s) (u \u2208 t), p l u \u2227 Ixx l u = S } := by\n  rintro _ \u27e8l\u2081, hls\u2081, u\u2081, hut\u2081, _, rfl\u27e9 _ \u27e8l\u2082, hls\u2082, u\u2082, hut\u2082, _, rfl\u27e9\n  simp only [Hi]\n  exact fun H => \u27e8l\u2081 \u2294 l\u2082, sup_ind l\u2081 l\u2082 hls\u2081 hls\u2082, u\u2081 \u2293 u\u2082, inf_ind u\u2081 u\u2082 hut\u2081 hut\u2082, Hne H, rfl\u27e9\n#align is_pi_system_Ixx_mem isPiSystem_Ixx_mem\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ixx {Ixx : \u03b1 \u2192 \u03b1 \u2192 Set \u03b1} {p : \u03b1 \u2192 \u03b1 \u2192 Prop}\n    (Hne : \u2200 {a b}, (Ixx a b).Nonempty \u2192 p a b)\n    (Hi : \u2200 {a\u2081 b\u2081 a\u2082 b\u2082}, Ixx a\u2081 b\u2081 \u2229 Ixx a\u2082 b\u2082 = Ixx (max a\u2081 a\u2082) (min b\u2081 b\u2082)) (f : \u03b9 \u2192 \u03b1)\n    (g : \u03b9' \u2192 \u03b1) : @IsPiSystem \u03b1 { S | \u2203 i j, p (f i) (g j) \u2227 Ixx (f i) (g j) = S } := by\n  simpa only [exists_range_iff] using isPiSystem_Ixx_mem (@Hne) (@Hi) (range f) (range g)\n#align is_pi_system_Ixx isPiSystem_Ixx\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ioo_mem (s t : Set \u03b1) :\n    IsPiSystem { S | \u2203\u1d49 (l \u2208 s) (u \u2208 t), l < u \u2227 Ioo l u = S } :=\n  isPiSystem_Ixx_mem (Ixx := Ioo) (fun \u27e8_, hax, hxb\u27e9 => hax.trans hxb) Ioo_inter_Ioo s t\n#align is_pi_system_Ioo_mem isPiSystem_Ioo_mem\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ioo (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n    @IsPiSystem \u03b1 { S | \u2203 l u, f l < g u \u2227 Ioo (f l) (g u) = S } :=\n  isPiSystem_Ixx (Ixx := Ioo) (fun \u27e8_, hax, hxb\u27e9 => hax.trans hxb) Ioo_inter_Ioo f g\n#align is_pi_system_Ioo isPiSystem_Ioo\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ioc_mem (s t : Set \u03b1) :\n    IsPiSystem { S | \u2203\u1d49 (l \u2208 s) (u \u2208 t), l < u \u2227 Ioc l u = S } :=\n  isPiSystem_Ixx_mem (Ixx := Ioc) (fun \u27e8_, hax, hxb\u27e9 => hax.trans_le hxb) Ioc_inter_Ioc s t\n#align is_pi_system_Ioc_mem isPiSystem_Ioc_mem\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ioc (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n    @IsPiSystem \u03b1 { S | \u2203 i j, f i < g j \u2227 Ioc (f i) (g j) = S } :=\n  isPiSystem_Ixx (Ixx := Ioc) (fun \u27e8_, hax, hxb\u27e9 => hax.trans_le hxb) Ioc_inter_Ioc f g\n#align is_pi_system_Ioc isPiSystem_Ioc\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ico_mem (s t : Set \u03b1) :\n    IsPiSystem { S | \u2203\u1d49 (l \u2208 s) (u \u2208 t), l < u \u2227 Ico l u = S } :=\n  isPiSystem_Ixx_mem (Ixx := Ico) (fun \u27e8_, hax, hxb\u27e9 => hax.trans_lt hxb) Ico_inter_Ico s t\n#align is_pi_system_Ico_mem isPiSystem_Ico_mem\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Ico (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n    @IsPiSystem \u03b1 { S | \u2203 i j, f i < g j \u2227 Ico (f i) (g j) = S } :=\n  isPiSystem_Ixx (Ixx := Ico) (fun \u27e8_, hax, hxb\u27e9 => hax.trans_lt hxb) Ico_inter_Ico f g\n#align is_pi_system_Ico isPiSystem_Ico\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Icc_mem (s t : Set \u03b1) :\n    IsPiSystem { S | \u2203\u1d49 (l \u2208 s) (u \u2208 t), l \u2264 u \u2227 Icc l u = S } :=\n  isPiSystem_Ixx_mem (Ixx := Icc) nonempty_Icc.1 (by exact Icc_inter_Icc) s t\n#align is_pi_system_Icc_mem isPiSystem_Icc_mem\n\n-- porting note: change `\u2203 (_ : p l u), _` to `_ \u2227 _`\ntheorem isPiSystem_Icc (f : \u03b9 \u2192 \u03b1) (g : \u03b9' \u2192 \u03b1) :\n    @IsPiSystem \u03b1 { S | \u2203 i j, f i \u2264 g j \u2227 Icc (f i) (g j) = S } :=\n  isPiSystem_Ixx (Ixx := Icc) nonempty_Icc.1 (by exact Icc_inter_Icc) f g\n#align is_pi_system_Icc isPiSystem_Icc\n\nend Order\n\n/-- Given a collection `S` of subsets of `\u03b1`, then `generatePiSystem S` is the smallest\n\u03c0-system containing `S`. -/\ninductive generatePiSystem {\u03b1} (S : Set (Set \u03b1)) : Set (Set \u03b1)\n  | base {s : Set \u03b1} (h_s : s \u2208 S) : generatePiSystem S s\n  | inter {s t : Set \u03b1} (h_s : generatePiSystem S s) (h_t : generatePiSystem S t)\n    (h_nonempty : (s \u2229 t).Nonempty) : generatePiSystem S (s \u2229 t)\n#align generate_pi_system generatePiSystem\n\ntheorem isPiSystem_generatePiSystem {\u03b1} (S : Set (Set \u03b1)) : IsPiSystem (generatePiSystem S) :=\n  fun _ h_s _ h_t h_nonempty => generatePiSystem.inter h_s h_t h_nonempty\n#align is_pi_system_generate_pi_system isPiSystem_generatePiSystem\n\ntheorem subset_generatePiSystem_self {\u03b1} (S : Set (Set \u03b1)) : S \u2286 generatePiSystem S := fun _ =>\n  generatePiSystem.base\n#align subset_generate_pi_system_self subset_generatePiSystem_self\n\ntheorem generatePiSystem_subset_self {\u03b1} {S : Set (Set \u03b1)} (h_S : IsPiSystem S) :\n    generatePiSystem S \u2286 S := fun x h => by\n  induction' h with _ h_s s u _ _ h_nonempty h_s h_u\n  \u00b7 exact h_s\n  \u00b7 exact h_S _ h_s _ h_u h_nonempty\n#align generate_pi_system_subset_self generatePiSystem_subset_self\n\ntheorem generatePiSystem_eq {\u03b1} {S : Set (Set \u03b1)} (h_pi : IsPiSystem S) : generatePiSystem S = S :=\n  Set.Subset.antisymm (generatePiSystem_subset_self h_pi) (subset_generatePiSystem_self S)\n#align generate_pi_system_eq generatePiSystem_eq\n\ntheorem generatePiSystem_mono {\u03b1} {S T : Set (Set \u03b1)} (hST : S \u2286 T) :\n    generatePiSystem S \u2286 generatePiSystem T := fun t ht => by\n  induction' ht with s h_s s u _ _ h_nonempty h_s h_u\n  \u00b7 exact generatePiSystem.base (Set.mem_of_subset_of_mem hST h_s)\n  \u00b7 exact isPiSystem_generatePiSystem T _ h_s _ h_u h_nonempty\n#align generate_pi_system_mono generatePiSystem_mono\n\ntheorem generatePiSystem_measurableSet {\u03b1} [M : MeasurableSpace \u03b1] {S : Set (Set \u03b1)}\n    (h_meas_S : \u2200 s \u2208 S, MeasurableSet s) (t : Set \u03b1) (h_in_pi : t \u2208 generatePiSystem S) :\n    MeasurableSet t := by\n  induction' h_in_pi with s h_s s u _ _ _ h_s h_u\n  \u00b7 apply h_meas_S _ h_s\n  \u00b7 apply MeasurableSet.inter h_s h_u\n#align generate_pi_system_measurable_set generatePiSystem_measurableSet\n\ntheorem generateFrom_measurableSet_of_generatePiSystem {\u03b1} {g : Set (Set \u03b1)} (t : Set \u03b1)\n    (ht : t \u2208 generatePiSystem g) : MeasurableSet[generateFrom g] t :=\n  @generatePiSystem_measurableSet \u03b1 (generateFrom g) g\n    (fun _ h_s_in_g => measurableSet_generateFrom h_s_in_g) t ht\n#align generate_from_measurable_set_of_generate_pi_system generateFrom_measurableSet_of_generatePiSystem\n\ntheorem generateFrom_generatePiSystem_eq {\u03b1} {g : Set (Set \u03b1)} :\n    generateFrom (generatePiSystem g) = generateFrom g := by\n  apply le_antisymm <;> apply generateFrom_le\n  \u00b7 exact fun t h_t => generateFrom_measurableSet_of_generatePiSystem t h_t\n  \u00b7 exact fun t h_t => measurableSet_generateFrom (generatePiSystem.base h_t)\n#align generate_from_generate_pi_system_eq generateFrom_generatePiSystem_eq\n\n/- Every element of the \u03c0-system generated by the union of a family of \u03c0-systems\nis a finite intersection of elements from the \u03c0-systems.\nFor an indexed union version, see `mem_generatePiSystem_union\u1d62_elim'`. -/\ntheorem mem_generatePiSystem_union\u1d62_elim {\u03b1 \u03b2} {g : \u03b2 \u2192 Set (Set \u03b1)} (h_pi : \u2200 b, IsPiSystem (g b))\n    (t : Set \u03b1) (h_t : t \u2208 generatePiSystem (\u22c3 b, g b)) :\n    \u2203 (T : Finset \u03b2) (f : \u03b2 \u2192 Set \u03b1), (t = \u22c2 b \u2208 T, f b) \u2227 \u2200 b \u2208 T, f b \u2208 g b := by\n  induction' h_t with s h_s s t' h_gen_s h_gen_t' h_nonempty h_s h_t'\n  \u00b7 rcases h_s with \u27e8t', \u27e8\u27e8b, rfl\u27e9, h_s_in_t'\u27e9\u27e9\n    refine' \u27e8{b}, fun _ => s, _\u27e9\n    simpa using h_s_in_t'\n  \u00b7 rcases h_t' with \u27e8T_t', \u27e8f_t', \u27e8rfl, h_t'\u27e9\u27e9\u27e9\n    rcases h_s with \u27e8T_s, \u27e8f_s, \u27e8rfl, h_s\u27e9\u27e9\u27e9\n    use T_s \u222a T_t', fun b : \u03b2 =>\n      if b \u2208 T_s then if b \u2208 T_t' then f_s b \u2229 f_t' b else f_s b\n      else if b \u2208 T_t' then f_t' b else (\u2205 : Set \u03b1)\n    constructor\n    \u00b7 ext a\n      simp_rw [Set.mem_inter_iff, Set.mem_inter\u1d62, Finset.mem_union, or_imp]\n      rw [\u2190 forall_and]\n      constructor <;> intro h1 b <;> by_cases hbs : b \u2208 T_s <;> by_cases hbt : b \u2208 T_t' <;>\n          specialize h1 b <;>\n        simp only [hbs, hbt, if_true, if_false, true_imp_iff, and_self_iff, false_imp_iff,\n          and_true_iff, true_and_iff] at h1\u22a2\n      all_goals exact h1\n    intro b h_b\n    -- Porting note: `simp only` required for a beta reduction\n    simp only []\n    split_ifs with hbs hbt hbt\n    \u00b7 refine' h_pi b (f_s b) (h_s b hbs) (f_t' b) (h_t' b hbt) (Set.Nonempty.mono _ h_nonempty)\n      exact Set.inter_subset_inter (Set.binter\u1d62_subset_of_mem hbs) (Set.binter\u1d62_subset_of_mem hbt)\n    \u00b7 exact h_s b hbs\n    \u00b7 exact h_t' b hbt\n    \u00b7 rw [Finset.mem_union] at h_b\n      apply False.elim (h_b.elim hbs hbt)\n#align mem_generate_pi_system_Union_elim mem_generatePiSystem_union\u1d62_elim\n\n/- Every element of the \u03c0-system generated by an indexed union of a family of \u03c0-systems\nis a finite intersection of elements from the \u03c0-systems.\nFor a total union version, see `mem_generatePiSystem_union\u1d62_elim`. -/\ntheorem mem_generatePiSystem_union\u1d62_elim' {\u03b1 \u03b2} {g : \u03b2 \u2192 Set (Set \u03b1)} {s : Set \u03b2}\n    (h_pi : \u2200 b \u2208 s, IsPiSystem (g b)) (t : Set \u03b1) (h_t : t \u2208 generatePiSystem (\u22c3 b \u2208 s, g b)) :\n    \u2203 (T : Finset \u03b2) (f : \u03b2 \u2192 Set \u03b1), \u2191T \u2286 s \u2227 (t = \u22c2 b \u2208 T, f b) \u2227 \u2200 b \u2208 T, f b \u2208 g b := by\n  have : t \u2208 generatePiSystem (\u22c3 b : Subtype s, (g \u2218 Subtype.val) b) :=\n    by\n    suffices h1 : (\u22c3 b : Subtype s, (g \u2218 Subtype.val) b) = \u22c3 b \u2208 s, g b\n    \u00b7 rwa [h1]\n    ext x\n    simp only [exists_prop, Set.mem_union\u1d62, Function.comp_apply, Subtype.exists, Subtype.coe_mk]\n    rfl\n  rcases @mem_generatePiSystem_union\u1d62_elim \u03b1 (Subtype s) (g \u2218 Subtype.val)\n      (fun b => h_pi b.val b.property) t this with\n    \u27e8T, \u27e8f, \u27e8rfl, h_t'\u27e9\u27e9\u27e9\n  refine'\n    \u27e8T.image (fun x : s => (x : \u03b2)),\n      Function.extend (fun x : s => (x : \u03b2)) f fun _ : \u03b2 => (\u2205 : Set \u03b1), by simp, _, _\u27e9\n  \u00b7 ext a\n    constructor <;>\n      \u00b7 simp (config := { proj := false }) only\n          [Set.mem_inter\u1d62, Subtype.forall, Finset.set_binter\u1d62_finset_image]\n        intro h1 b h_b h_b_in_T\n        have h2 := h1 b h_b h_b_in_T\n        revert h2\n        rw [Subtype.val_injective.extend_apply]\n        apply id\n  \u00b7 intros b h_b\n    simp_rw [Finset.mem_image, exists_prop, Subtype.exists, exists_and_right, exists_eq_right]\n      at h_b\n    cases' h_b with h_b_w h_b_h\n    have h_b_alt : b = (Subtype.mk b h_b_w).val := rfl\n    rw [h_b_alt, Subtype.val_injective.extend_apply]\n    apply h_t'\n    apply h_b_h\n#align mem_generate_pi_system_Union_elim' mem_generatePiSystem_union\u1d62_elim'\n\nsection UnionInter\n\nvariable {\u03b1 \u03b9 : Type _}\n\n/-! ### \u03c0-system generated by finite intersections of sets of a \u03c0-system family -/\n\n\n/-- From a set of indices `S : Set \u03b9` and a family of sets of sets `\u03c0 : \u03b9 \u2192 Set (Set \u03b1)`,\ndefine the set of sets that can be written as `\u22c2 x \u2208 t, f x` for some finset `t \u2286 S` and sets\n`f x \u2208 \u03c0 x`. If `\u03c0` is a family of \u03c0-systems, then it is a \u03c0-system. -/\ndef piUnion\u1d62Inter (\u03c0 : \u03b9 \u2192 Set (Set \u03b1)) (S : Set \u03b9) : Set (Set \u03b1) :=\n  { s : Set \u03b1 |\n    \u2203 (t : Finset \u03b9) (_ : \u2191t \u2286 S) (f : \u03b9 \u2192 Set \u03b1) (_ : \u2200 x, x \u2208 t \u2192 f x \u2208 \u03c0 x), s = \u22c2 x \u2208 t, f x }\n#align pi_Union_Inter piUnion\u1d62Inter\n\ntheorem piUnion\u1d62Inter_singleton (\u03c0 : \u03b9 \u2192 Set (Set \u03b1)) (i : \u03b9) :\n    piUnion\u1d62Inter \u03c0 {i} = \u03c0 i \u222a {univ} := by\n  ext1 s\n  simp only [piUnion\u1d62Inter, exists_prop, mem_union]\n  refine' \u27e8_, fun h => _\u27e9\n  \u00b7 rintro \u27e8t, hti, f, hf\u03c0, rfl\u27e9\n    simp only [subset_singleton_iff, Finset.mem_coe] at hti\n    by_cases hi : i \u2208 t\n    \u00b7 have ht_eq_i : t = {i} := by\n        ext1 x\n        rw [Finset.mem_singleton]\n        exact \u27e8fun h => hti x h, fun h => h.symm \u25b8 hi\u27e9\n      simp only [ht_eq_i, Finset.mem_singleton, inter\u1d62_inter\u1d62_eq_left]\n      exact Or.inl (hf\u03c0 i hi)\n    \u00b7 have ht_empty : t = \u2205 := by\n        ext1 x\n        simp only [Finset.not_mem_empty, iff_false_iff]\n        exact fun hx => hi (hti x hx \u25b8 hx)\n      -- Porting note: `Finset.not_mem_empty` required\n      simp [ht_empty, Finset.not_mem_empty, inter\u1d62_false, inter\u1d62_univ, Set.mem_singleton univ,\n        or_true_iff]\n  \u00b7 cases' h with hs hs\n    \u00b7 refine' \u27e8{i}, _, fun _ => s, \u27e8fun x hx => _, _\u27e9\u27e9\n      \u00b7 rw [Finset.coe_singleton]\n      \u00b7 rw [Finset.mem_singleton] at hx\n        rwa [hx]\n      \u00b7 simp only [Finset.mem_singleton, inter\u1d62_inter\u1d62_eq_left]\n    \u00b7 refine' \u27e8\u2205, _\u27e9\n      simpa only [Finset.coe_empty, subset_singleton_iff, mem_empty_iff_false, IsEmpty.forall_iff,\n        imp_true_iff, Finset.not_mem_empty, inter\u1d62_false, inter\u1d62_univ, true_and_iff,\n        exists_const] using hs\n#align pi_Union_Inter_singleton piUnion\u1d62Inter_singleton\n\ntheorem piUnion\u1d62Inter_singleton_left (s : \u03b9 \u2192 Set \u03b1) (S : Set \u03b9) :\n    piUnion\u1d62Inter (fun i => ({s i} : Set (Set \u03b1))) S =\n      { s' : Set \u03b1 | \u2203 (t : Finset \u03b9) (_ : \u2191t \u2286 S), s' = \u22c2 i \u2208 t, s i } := by\n  ext1 s'\n  simp_rw [piUnion\u1d62Inter, Set.mem_singleton_iff, exists_prop, Set.mem_setOf_eq]\n  refine' \u27e8fun h => _, fun \u27e8t, htS, h_eq\u27e9 => \u27e8t, htS, s, fun _ _ => rfl, h_eq\u27e9\u27e9\n  obtain \u27e8t, htS, f, hft_eq, rfl\u27e9 := h\n  refine' \u27e8t, htS, _\u27e9\n  congr! 3\n  apply hft_eq\n  assumption\n#align pi_Union_Inter_singleton_left piUnion\u1d62Inter_singleton_left\n\ntheorem generateFrom_piUnion\u1d62Inter_singleton_left (s : \u03b9 \u2192 Set \u03b1) (S : Set \u03b9) :\n    generateFrom (piUnion\u1d62Inter (fun k => {s k}) S) = generateFrom { t | \u2203 k \u2208 S, s k = t } := by\n  refine' le_antisymm (generateFrom_le _) (generateFrom_mono _)\n  \u00b7 rintro _ \u27e8I, hI, f, hf, rfl\u27e9\n    refine' Finset.measurableSet_binter\u1d62 _ fun m hm => measurableSet_generateFrom _\n    exact \u27e8m, hI hm, (hf m hm).symm\u27e9\n  \u00b7 rintro _ \u27e8k, hk, rfl\u27e9\n    refine' \u27e8{k}, fun m hm => _, s, fun i _ => _, _\u27e9\n    \u00b7 rw [Finset.mem_coe, Finset.mem_singleton] at hm\n      rwa [hm]\n    \u00b7 exact Set.mem_singleton _\n    \u00b7 simp only [Finset.mem_singleton, Set.inter\u1d62_inter\u1d62_eq_left]\n#align generate_from_pi_Union_Inter_singleton_left generateFrom_piUnion\u1d62Inter_singleton_left\n\n/-- If `\u03c0` is a family of \u03c0-systems, then `piUnion\u1d62Inter \u03c0 S` is a \u03c0-system. -/\ntheorem isPiSystem_piUnion\u1d62Inter (\u03c0 : \u03b9 \u2192 Set (Set \u03b1)) (hpi : \u2200 x, IsPiSystem (\u03c0 x)) (S : Set \u03b9) :\n    IsPiSystem (piUnion\u1d62Inter \u03c0 S) := by\n  rintro t1 \u27e8p1, hp1S, f1, hf1m, ht1_eq\u27e9 t2 \u27e8p2, hp2S, f2, hf2m, ht2_eq\u27e9 h_nonempty\n  simp_rw [piUnion\u1d62Inter, Set.mem_setOf_eq]\n  let g n := ite (n \u2208 p1) (f1 n) Set.univ \u2229 ite (n \u2208 p2) (f2 n) Set.univ\n  have hp_union_ss : \u2191(p1 \u222a p2) \u2286 S := by\n    simp only [hp1S, hp2S, Finset.coe_union, union_subset_iff, and_self_iff]\n  use p1 \u222a p2, hp_union_ss, g\n  have h_inter_eq : t1 \u2229 t2 = \u22c2 i \u2208 p1 \u222a p2, g i :=\n    by\n    rw [ht1_eq, ht2_eq]\n    simp_rw [\u2190 Set.inf_eq_inter]\n    ext1 x\n    simp only [inf_eq_inter, mem_inter_iff, mem_inter\u1d62, Finset.mem_union]\n    refine' \u27e8fun h i _ => _, fun h => \u27e8fun i hi1 => _, fun i hi2 => _\u27e9\u27e9\n    \u00b7 split_ifs with h_1 h_2 h_2\n      exacts[\u27e8h.1 i h_1, h.2 i h_2\u27e9, \u27e8h.1 i h_1, Set.mem_univ _\u27e9, \u27e8Set.mem_univ _, h.2 i h_2\u27e9,\n        \u27e8Set.mem_univ _, Set.mem_univ _\u27e9]\n    \u00b7 specialize h i (Or.inl hi1)\n      rw [if_pos hi1] at h\n      exact h.1\n    \u00b7 specialize h i (Or.inr hi2)\n      rw [if_pos hi2] at h\n      exact h.2\n  refine' \u27e8fun n hn => _, h_inter_eq\u27e9\n  simp only []\n  split_ifs with hn1 hn2 h\n  \u00b7 refine' hpi n (f1 n) (hf1m n hn1) (f2 n) (hf2m n hn2) (Set.nonempty_iff_ne_empty.2 fun h => _)\n    rw [h_inter_eq] at h_nonempty\n    suffices h_empty : (\u22c2 i \u2208 p1 \u222a p2, g i) = \u2205\n    exact (Set.not_nonempty_iff_eq_empty.mpr h_empty) h_nonempty\n    refine' le_antisymm (Set.inter\u1d62_subset_of_subset n _) (Set.empty_subset _)\n    refine' Set.inter\u1d62_subset_of_subset hn _\n    simp_rw [if_pos hn1, if_pos hn2]\n    exact h.subset\n  \u00b7 simp [hf1m n hn1]\n  \u00b7 simp [hf2m n h]\n  \u00b7 exact absurd hn (by simp [hn1, h])\n#align is_pi_system_pi_Union_Inter isPiSystem_piUnion\u1d62Inter\n\ntheorem piUnion\u1d62Inter_mono_left {\u03c0 \u03c0' : \u03b9 \u2192 Set (Set \u03b1)} (h_le : \u2200 i, \u03c0 i \u2286 \u03c0' i) (S : Set \u03b9) :\n    piUnion\u1d62Inter \u03c0 S \u2286 piUnion\u1d62Inter \u03c0' S := fun _ \u27e8t, ht_mem, ft, hft_mem_pi, h_eq\u27e9 =>\n  \u27e8t, ht_mem, ft, fun x hxt => h_le x (hft_mem_pi x hxt), h_eq\u27e9\n#align pi_Union_Inter_mono_left piUnion\u1d62Inter_mono_left\n\ntheorem piUnion\u1d62Inter_mono_right {\u03c0 : \u03b9 \u2192 Set (Set \u03b1)} {S T : Set \u03b9} (hST : S \u2286 T) :\n    piUnion\u1d62Inter \u03c0 S \u2286 piUnion\u1d62Inter \u03c0 T := fun _ \u27e8t, ht_mem, ft, hft_mem_pi, h_eq\u27e9 =>\n  \u27e8t, ht_mem.trans hST, ft, hft_mem_pi, h_eq\u27e9\n#align pi_Union_Inter_mono_right piUnion\u1d62Inter_mono_right\n\ntheorem generateFrom_piUnion\u1d62Inter_le {m : MeasurableSpace \u03b1} (\u03c0 : \u03b9 \u2192 Set (Set \u03b1))\n    (h : \u2200 n, generateFrom (\u03c0 n) \u2264 m) (S : Set \u03b9) : generateFrom (piUnion\u1d62Inter \u03c0 S) \u2264 m := by\n  refine' generateFrom_le _\n  rintro t \u27e8ht_p, _, ft, hft_mem_pi, rfl\u27e9\n  refine' Finset.measurableSet_binter\u1d62 _ fun x hx_mem => (h x) _ _\n  exact measurableSet_generateFrom (hft_mem_pi x hx_mem)\n#align generate_from_pi_Union_Inter_le generateFrom_piUnion\u1d62Inter_le\n\ntheorem subset_piUnion\u1d62Inter {\u03c0 : \u03b9 \u2192 Set (Set \u03b1)} {S : Set \u03b9} {i : \u03b9} (his : i \u2208 S) :\n    \u03c0 i \u2286 piUnion\u1d62Inter \u03c0 S := by\n  have h_ss : {i} \u2286 S := by\n    intro j hj\n    rw [mem_singleton_iff] at hj\n    rwa [hj]\n  refine' Subset.trans _ (piUnion\u1d62Inter_mono_right h_ss)\n  rw [piUnion\u1d62Inter_singleton]\n  exact subset_union_left _ _\n#align subset_pi_Union_Inter subset_piUnion\u1d62Inter\n\ntheorem mem_piUnion\u1d62Inter_of_measurableSet (m : \u03b9 \u2192 MeasurableSpace \u03b1) {S : Set \u03b9} {i : \u03b9}\n    (hiS : i \u2208 S) (s : Set \u03b1) (hs : MeasurableSet[m i] s) :\n    s \u2208 piUnion\u1d62Inter (fun n => { s | MeasurableSet[m n] s }) S :=\n  subset_piUnion\u1d62Inter hiS hs\n#align mem_pi_Union_Inter_of_measurable_set mem_piUnion\u1d62Inter_of_measurableSet\n\ntheorem le_generateFrom_piUnion\u1d62Inter {\u03c0 : \u03b9 \u2192 Set (Set \u03b1)} (S : Set \u03b9) {x : \u03b9} (hxS : x \u2208 S) :\n    generateFrom (\u03c0 x) \u2264 generateFrom (piUnion\u1d62Inter \u03c0 S) :=\n  generateFrom_mono (subset_piUnion\u1d62Inter hxS)\n#align le_generate_from_pi_Union_Inter le_generateFrom_piUnion\u1d62Inter\n\ntheorem measurableSet_sup\u1d62_of_mem_piUnion\u1d62Inter (m : \u03b9 \u2192 MeasurableSpace \u03b1) (S : Set \u03b9) (t : Set \u03b1)\n    (ht : t \u2208 piUnion\u1d62Inter (fun n => { s | MeasurableSet[m n] s }) S) :\n    MeasurableSet[\u2a06 i \u2208 S, m i] t := by\n  rcases ht with \u27e8pt, hpt, ft, ht_m, rfl\u27e9\n  refine' pt.measurableSet_binter\u1d62 fun i hi => _\n  suffices h_le : m i \u2264 \u2a06 i \u2208 S, m i; exact h_le (ft i) (ht_m i hi)\n  have hi' : i \u2208 S := hpt hi\n  exact le_sup\u1d62\u2082 (f := fun i (_ : i \u2208 S) => m i) i hi'\n#align measurable_set_supr_of_mem_pi_Union_Inter measurableSet_sup\u1d62_of_mem_piUnion\u1d62Inter\n\ntheorem generateFrom_piUnion\u1d62Inter_measurableSet (m : \u03b9 \u2192 MeasurableSpace \u03b1) (S : Set \u03b9) :\n    generateFrom (piUnion\u1d62Inter (fun n => { s | MeasurableSet[m n] s }) S) = \u2a06 i \u2208 S, m i := by\n  refine' le_antisymm _ _\n  \u00b7 rw [\u2190 @generateFrom_measurableSet \u03b1 (\u2a06 i \u2208 S, m i)]\n    exact generateFrom_mono (measurableSet_sup\u1d62_of_mem_piUnion\u1d62Inter m S)\n  \u00b7 refine' sup\u1d62\u2082_le fun i hi => _\n    rw [\u2190 @generateFrom_measurableSet \u03b1 (m i)]\n    exact generateFrom_mono (mem_piUnion\u1d62Inter_of_measurableSet m hi)\n#align generate_from_pi_Union_Inter_measurable_set generateFrom_piUnion\u1d62Inter_measurableSet\n\nend UnionInter\n\nnamespace MeasurableSpace\n\nvariable {\u03b1 : Type _}\n\n/-! ## Dynkin systems and \u03a0-\u03bb theorem -/\n\n\n/-- A Dynkin system is a collection of subsets of a type `\u03b1` that contains the empty set,\n  is closed under complementation and under countable union of pairwise disjoint sets.\n  The disjointness condition is the only difference with `\u03c3`-algebras.\n\n  The main purpose of Dynkin systems is to provide a powerful induction rule for \u03c3-algebras\n  generated by a collection of sets which is stable under intersection.\n\n  A Dynkin system is also known as a \"\u03bb-system\" or a \"d-system\".\n-/\nstructure DynkinSystem (\u03b1 : Type _) where\n  /-- Predicate saying that a given set is contained in the Dynkin system. -/\n  Has : Set \u03b1 \u2192 Prop\n  /-- A Dynkin system contains the empty set. -/\n  has_empty : Has \u2205\n  /-- A Dynkin system is closed under complementation. -/\n  has_compl : \u2200 {a}, Has a \u2192 Has (a\u1d9c)\n  /-- A Dynkin system is closed under countable union of pairwise disjoint sets. Use a more general\n  `MeasurableSpace.DynkinSystem.has_union\u1d62` instead.-/\n  has_union\u1d62_nat : \u2200 {f : \u2115 \u2192 Set \u03b1}, Pairwise (Disjoint on f) \u2192 (\u2200 i, Has (f i)) \u2192 Has (\u22c3 i, f i)\n#align measurable_space.dynkin_system MeasurableSpace.DynkinSystem\n\nnamespace DynkinSystem\n\n@[ext]\ntheorem ext : \u2200 {d\u2081 d\u2082 : DynkinSystem \u03b1}, (\u2200 s : Set \u03b1, d\u2081.Has s \u2194 d\u2082.Has s) \u2192 d\u2081 = d\u2082\n  | \u27e8s\u2081, _, _, _\u27e9, \u27e8s\u2082, _, _, _\u27e9, h => by\n    have : s\u2081 = s\u2082 := funext fun x => propext <| h x\n    subst this\n    rfl\n#align measurable_space.dynkin_system.ext MeasurableSpace.DynkinSystem.ext\n\nvariable (d : DynkinSystem \u03b1)\n\ntheorem has_compl_iff {a} : d.Has (a\u1d9c) \u2194 d.Has a :=\n  \u27e8fun h => by simpa using d.has_compl h, fun h => d.has_compl h\u27e9\n#align measurable_space.dynkin_system.has_compl_iff MeasurableSpace.DynkinSystem.has_compl_iff\n\ntheorem has_univ : d.Has univ := by simpa using d.has_compl d.has_empty\n#align measurable_space.dynkin_system.has_univ MeasurableSpace.DynkinSystem.has_univ\n\ntheorem has_union\u1d62 {\u03b2} [Countable \u03b2] {f : \u03b2 \u2192 Set \u03b1} (hd : Pairwise (Disjoint on f))\n    (h : \u2200 i, d.Has (f i)) : d.Has (\u22c3 i, f i) := by\n  cases nonempty_encodable \u03b2\n  rw [\u2190 Encodable.union\u1d62_decode\u2082]\n  exact\n    d.has_union\u1d62_nat (Encodable.union\u1d62_decode\u2082_disjoint_on hd) fun n =>\n      Encodable.union\u1d62_decode\u2082_cases d.has_empty h\n#align measurable_space.dynkin_system.has_Union MeasurableSpace.DynkinSystem.has_union\u1d62\n\ntheorem has_union {s\u2081 s\u2082 : Set \u03b1} (h\u2081 : d.Has s\u2081) (h\u2082 : d.Has s\u2082) (h : Disjoint s\u2081 s\u2082) :\n    d.Has (s\u2081 \u222a s\u2082) := by\n  rw [union_eq_union\u1d62]\n  exact d.has_union\u1d62 (pairwise_disjoint_on_bool.2 h) (Bool.forall_bool.2 \u27e8h\u2082, h\u2081\u27e9)\n#align measurable_space.dynkin_system.has_union MeasurableSpace.DynkinSystem.has_union\n\ntheorem has_diff {s\u2081 s\u2082 : Set \u03b1} (h\u2081 : d.Has s\u2081) (h\u2082 : d.Has s\u2082) (h : s\u2082 \u2286 s\u2081) : d.Has (s\u2081 \\ s\u2082) :=\n  by\n  apply d.has_compl_iff.1\n  simp [diff_eq, compl_inter]\n  exact d.has_union (d.has_compl h\u2081) h\u2082 (disjoint_compl_left.mono_right h)\n#align measurable_space.dynkin_system.has_diff MeasurableSpace.DynkinSystem.has_diff\n\ninstance : LE (DynkinSystem \u03b1) where le m\u2081 m\u2082 := m\u2081.Has \u2264 m\u2082.Has\n\ntheorem le_def {\u03b1} {a b : DynkinSystem \u03b1} : a \u2264 b \u2194 a.Has \u2264 b.Has :=\n  Iff.rfl\n#align measurable_space.dynkin_system.le_def MeasurableSpace.DynkinSystem.le_def\n\ninstance : PartialOrder (DynkinSystem \u03b1) :=\n  { DynkinSystem.instLEDynkinSystem with\n    le_refl := fun a b => le_rfl\n    le_trans := fun a b c hab hbc => le_def.mpr (le_trans hab hbc)\n    le_antisymm := fun a b h\u2081 h\u2082 => ext fun s => \u27e8h\u2081 s, h\u2082 s\u27e9 }\n\n/-- Every measurable space (\u03c3-algebra) forms a Dynkin system -/\ndef ofMeasurableSpace (m : MeasurableSpace \u03b1) : DynkinSystem \u03b1\n    where\n  Has := m.MeasurableSet'\n  has_empty := m.measurableSet_empty\n  has_compl {a} := m.measurableSet_compl a\n  has_union\u1d62_nat {f} _ hf := m.measurableSet_union\u1d62 f hf\n#align measurable_space.dynkin_system.of_measurable_space MeasurableSpace.DynkinSystem.ofMeasurableSpace\n\ntheorem ofMeasurableSpace_le_ofMeasurableSpace_iff {m\u2081 m\u2082 : MeasurableSpace \u03b1} :\n    ofMeasurableSpace m\u2081 \u2264 ofMeasurableSpace m\u2082 \u2194 m\u2081 \u2264 m\u2082 :=\n  Iff.rfl\n#align measurable_space.dynkin_system.of_measurable_space_le_of_measurable_space_iff MeasurableSpace.DynkinSystem.ofMeasurableSpace_le_ofMeasurableSpace_iff\n\n/-- The least Dynkin system containing a collection of basic sets.\n  This inductive type gives the underlying collection of sets. -/\ninductive GenerateHas (s : Set (Set \u03b1)) : Set \u03b1 \u2192 Prop\n  | basic : \u2200 t \u2208 s, GenerateHas s t\n  | empty : GenerateHas s \u2205\n  | compl : \u2200 {a}, GenerateHas s a \u2192 GenerateHas s (a\u1d9c)\n  | union\u1d62 : \u2200 {f : \u2115 \u2192 Set \u03b1},\n    Pairwise (Disjoint on f) \u2192 (\u2200 i, GenerateHas s (f i)) \u2192 GenerateHas s (\u22c3 i, f i)\n#align measurable_space.dynkin_system.generate_has MeasurableSpace.DynkinSystem.GenerateHas\n\ntheorem generateHas_compl {C : Set (Set \u03b1)} {s : Set \u03b1} : GenerateHas C (s\u1d9c) \u2194 GenerateHas C s := by\n  refine' \u27e8_, GenerateHas.compl\u27e9\n  intro h\n  convert GenerateHas.compl h\n  simp\n#align measurable_space.dynkin_system.generate_has_compl MeasurableSpace.DynkinSystem.generateHas_compl\n\n/-- The least Dynkin system containing a collection of basic sets. -/\ndef generate (s : Set (Set \u03b1)) : DynkinSystem \u03b1\n    where\n  Has := GenerateHas s\n  has_empty := GenerateHas.empty\n  has_compl {_} := GenerateHas.compl\n  has_union\u1d62_nat {_} := GenerateHas.union\u1d62\n#align measurable_space.dynkin_system.generate MeasurableSpace.DynkinSystem.generate\n\ntheorem generateHas_def {C : Set (Set \u03b1)} : (generate C).Has = GenerateHas C :=\n  rfl\n#align measurable_space.dynkin_system.generate_has_def MeasurableSpace.DynkinSystem.generateHas_def\n\ninstance : Inhabited (DynkinSystem \u03b1) :=\n  \u27e8generate univ\u27e9\n\n/-- If a Dynkin system is closed under binary intersection, then it forms a `\u03c3`-algebra. -/\ndef toMeasurableSpace (h_inter : \u2200 s\u2081 s\u2082, d.Has s\u2081 \u2192 d.Has s\u2082 \u2192 d.Has (s\u2081 \u2229 s\u2082)) :\n    MeasurableSpace \u03b1 where\n  MeasurableSet' := d.Has\n  measurableSet_empty := d.has_empty\n  measurableSet_compl s h := d.has_compl h\n  measurableSet_union\u1d62 f hf := by\n    rw [\u2190 union\u1d62_disjointed]\n    exact\n      d.has_union\u1d62 (disjoint_disjointed _) fun n =>\n        disjointedRec (fun (t : Set \u03b1) i h => h_inter _ _ h <| d.has_compl <| hf i) (hf n)\n#align measurable_space.dynkin_system.to_measurable_space MeasurableSpace.DynkinSystem.toMeasurableSpace\n\ntheorem ofMeasurableSpace_toMeasurableSpace\n    (h_inter : \u2200 s\u2081 s\u2082, d.Has s\u2081 \u2192 d.Has s\u2082 \u2192 d.Has (s\u2081 \u2229 s\u2082)) :\n    ofMeasurableSpace (d.toMeasurableSpace h_inter) = d :=\n  ext fun _ => Iff.rfl\n#align measurable_space.dynkin_system.of_measurable_space_to_measurable_space MeasurableSpace.DynkinSystem.ofMeasurableSpace_toMeasurableSpace\n\n/-- If `s` is in a Dynkin system `d`, we can form the new Dynkin system `{s \u2229 t | t \u2208 d}`. -/\ndef restrictOn {s : Set \u03b1} (h : d.Has s) : DynkinSystem \u03b1 where\n  -- Porting note: `simp only []` required for a beta reduction\n  Has t := d.Has (t \u2229 s)\n  has_empty := by simp [d.has_empty]\n  has_compl {t} hts := by\n    simp only []\n    have : t\u1d9c \u2229 s = (t \u2229 s)\u1d9c \\ s\u1d9c := Set.ext fun x => by by_cases h : x \u2208 s <;> simp [h]\n    rw [this]\n    exact\n      d.has_diff (d.has_compl hts) (d.has_compl h)\n        (compl_subset_compl.mpr <| inter_subset_right _ _)\n  has_union\u1d62_nat {f} hd hf := by\n    simp only []\n    rw [union\u1d62_inter]\n    refine' d.has_union\u1d62_nat _ hf\n    exact hd.mono fun i j => Disjoint.mono (inter_subset_left _ _) (inter_subset_left _ _)\n#align measurable_space.dynkin_system.restrict_on MeasurableSpace.DynkinSystem.restrictOn\n\ntheorem generate_le {s : Set (Set \u03b1)} (h : \u2200 t \u2208 s, d.Has t) : generate s \u2264 d := fun _ ht =>\n  ht.recOn h d.has_empty (fun {_} _ h => d.has_compl h) fun {_} hd _ hf => d.has_union\u1d62 hd hf\n#align measurable_space.dynkin_system.generate_le MeasurableSpace.DynkinSystem.generate_le\n\ntheorem generate_has_subset_generate_measurable {C : Set (Set \u03b1)} {s : Set \u03b1}\n    (hs : (generate C).Has s) : MeasurableSet[generateFrom C] s :=\n  generate_le (ofMeasurableSpace (generateFrom C)) (fun _ => measurableSet_generateFrom) s hs\n#align measurable_space.dynkin_system.generate_has_subset_generate_measurable MeasurableSpace.DynkinSystem.generate_has_subset_generate_measurable\n\ntheorem generate_inter {s : Set (Set \u03b1)} (hs : IsPiSystem s) {t\u2081 t\u2082 : Set \u03b1}\n    (ht\u2081 : (generate s).Has t\u2081) (ht\u2082 : (generate s).Has t\u2082) : (generate s).Has (t\u2081 \u2229 t\u2082) :=\n  have : generate s \u2264 (generate s).restrictOn ht\u2082 :=\n    generate_le _ fun s\u2081 hs\u2081 =>\n      have : (generate s).Has s\u2081 := GenerateHas.basic s\u2081 hs\u2081\n      have : generate s \u2264 (generate s).restrictOn this :=\n        generate_le _ fun s\u2082 hs\u2082 =>\n          show (generate s).Has (s\u2082 \u2229 s\u2081) from\n            (s\u2082 \u2229 s\u2081).eq_empty_or_nonempty.elim (fun h => h.symm \u25b8 GenerateHas.empty) fun h =>\n              GenerateHas.basic _ <| hs _ hs\u2082 _ hs\u2081 h\n      have : (generate s).Has (t\u2082 \u2229 s\u2081) := this _ ht\u2082\n      show (generate s).Has (s\u2081 \u2229 t\u2082) by rwa [inter_comm]\n  this _ ht\u2081\n#align measurable_space.dynkin_system.generate_inter MeasurableSpace.DynkinSystem.generate_inter\n\n/-- **Dynkin's \u03c0-\u03bb theorem**:\n  Given a collection of sets closed under binary intersections, then the Dynkin system it\n  generates is equal to the \u03c3-algebra it generates.\n  This result is known as the \u03c0-\u03bb theorem.\n  A collection of sets closed under binary intersection is called a \u03c0-system (often requiring\n  additionnally that is is non-empty, but we drop this condition in the formalization).\n-/\ntheorem generateFrom_eq {s : Set (Set \u03b1)} (hs : IsPiSystem s) :\n    generateFrom s = (generate s).toMeasurableSpace fun t\u2081 t\u2082 => generate_inter hs :=\n  le_antisymm (generateFrom_le fun t ht => GenerateHas.basic t ht)\n    (ofMeasurableSpace_le_ofMeasurableSpace_iff.mp <| by\n      rw [ofMeasurableSpace_toMeasurableSpace]\n      exact generate_le _ fun t ht => measurableSet_generateFrom ht)\n#align measurable_space.dynkin_system.generate_from_eq MeasurableSpace.DynkinSystem.generateFrom_eq\n\nend DynkinSystem\n\ntheorem induction_on_inter {C : Set \u03b1 \u2192 Prop} {s : Set (Set \u03b1)} [m : MeasurableSpace \u03b1]\n    (h_eq : m = generateFrom s) (h_inter : IsPiSystem s) (h_empty : C \u2205) (h_basic : \u2200 t \u2208 s, C t)\n    (h_compl : \u2200 t, MeasurableSet t \u2192 C t \u2192 C (t\u1d9c))\n    (h_union :\n      \u2200 f : \u2115 \u2192 Set \u03b1,\n        Pairwise (Disjoint on f) \u2192 (\u2200 i, MeasurableSet (f i)) \u2192 (\u2200 i, C (f i)) \u2192 C (\u22c3 i, f i)) :\n    \u2200 \u2983t\u2984, MeasurableSet t \u2192 C t :=\n  have eq : MeasurableSet = DynkinSystem.GenerateHas s := by\n    rw [h_eq, DynkinSystem.generateFrom_eq h_inter]\n    rfl\n  fun t ht =>\n  have : DynkinSystem.GenerateHas s t := by rwa [eq] at ht\n  this.recOn h_basic h_empty\n    (fun {t} ht =>\n      h_compl t <| by\n        rw [eq]\n        exact ht)\n    fun {f} hf ht =>\n    h_union f hf fun i => by\n      rw [eq]\n      exact ht _\n#align measurable_space.induction_on_inter MeasurableSpace.induction_on_inter\n\nend MeasurableSpace\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/MeasureTheory/PiSystem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7210469909812681}}
{"text": "import algebra.order.positive.ring algebra.group_power.order data.nat.basic tactic.by_contra\n\n/-! # IMO 2008 A1 (P4), Ring Version -/\n\nnamespace IMOSL\nnamespace IMO2008A1\n\nlemma positive_pow_eq_pow {R : Type*} [linear_ordered_ring R]\n  {n : \u2115} (h : 0 < n) {a b : {x : R // 0 < x}} : a ^ n = b ^ n \u2194 a = b :=\n  by simp_rw [\u2190 subtype.coe_inj, positive.coe_pow];\n    exact pow_left_inj (le_of_lt a.2) (le_of_lt b.2) h\n\n\n\n/-- Final solution, general ring version -/\ntheorem final_solution_general_ring {R : Type*} [linear_ordered_comm_ring R] :\n  \u2200 f : {x : R // 0 < x} \u2192 {x : R // 0 < x}, (\u2200 p q r s, p * q = r * s \u2192\n    (f p ^ 2 + f q ^ 2) * (r ^ 2 + s ^ 2) = (p ^ 2 + q ^ 2) * (f (r ^ 2) + f (s ^ 2)))\n      \u2194 (f = \u03bb x, x) \u2228 \u2200 x, x * f x = 1 :=\nbegin\n  ---- First deal with the `\u2190` direction.\n  intros f; symmetry; refine \u27e8\u03bb h p q r s h0, _, \u03bb h, _\u27e9,\n  { rcases h with rfl | h,\n    refl,\n    rw [\u2190 mul_right_inj (p ^ 2 * q ^ 2), \u2190 mul_assoc, mul_add _ (f p ^ 2), mul_right_comm,\n        \u2190 mul_pow, h, mul_assoc, \u2190 mul_pow q, h, one_pow, mul_one, one_mul, add_comm,\n        mul_left_comm, mul_right_inj, \u2190 mul_pow, h0, mul_pow, mul_add, mul_right_comm,\n        h, one_mul, mul_assoc, h, mul_one, add_comm] },\n  \n  ---- Deduce `f(x^2) = f(x)^2` and `f(x) = x` or `x f(x) = 1`\n  have h0 : \u2200 x, f (x ^ 2) = f x ^ 2 :=\n    \u03bb x, by replace h := h x x x x rfl;\n      rwa [mul_comm, mul_right_inj, \u2190 two_mul, \u2190 two_mul, mul_right_inj, eq_comm] at h,\n  replace h := \u03bb x y, h (x ^ 2) (y ^ 2) (x * y) (x * y) (by rw [\u2190 sq, mul_pow]),\n  simp_rw [h0, \u2190 mul_two, \u2190 mul_assoc, mul_left_inj, \u2190 pow_mul, two_mul] at h,\n  replace h0 := h0 1,\n  rw [one_pow, sq, self_eq_mul_left] at h0,\n  have h1 : \u2200 x, f x = x \u2228 x * f x = 1 :=\n  begin\n    intros x; replace h := h x 1,\n    rw [mul_one, h0, one_pow, mul_comm, mul_add_one, add_one_mul, pow_add,\n        pow_add, mul_assoc, \u2190 mul_assoc, \u2190 mul_pow, mul_comm] at h,\n    simp_rw [\u2190 subtype.coe_inj, positive.coe_add, positive.coe_mul] at h,\n    rw [\u2190 eq_sub_iff_add_eq, add_sub_right_comm, \u2190 sub_eq_iff_eq_add, \u2190 mul_sub_one,\n        \u2190 mul_sub_one, \u2190 sub_eq_zero, \u2190 sub_mul, mul_eq_zero] at h,\n    simp_rw [sub_eq_zero, subtype.coe_inj, positive_pow_eq_pow two_pos] at h,\n    revert h; refine or.imp_right (\u03bb h, _),\n    rwa [eq_comm, \u2190 positive.coe_one, subtype.coe_inj,\n         \u2190 one_pow 2, eq_comm, positive_pow_eq_pow two_pos] at h\n  end,\n\n  ---- Finishing\n  rw function.funext_iff; by_contra' h2,\n  rcases h2 with \u27e8\u27e8a, h2\u27e9, b, h3\u27e9,\n  have h4 := h1 b; rw or_iff_left h3 at h4,\n  replace h := h a b; rw h4 at h,\n  replace h4 := h1 (a * b); cases h4 with h4,\n  rw [h4, mul_left_inj, add_left_inj, positive_pow_eq_pow four_pos] at h,\n  exact h2 h,\n  replace h1 := h1 a; rw or_iff_right h2 at h1,\n  rw [\u2190 mul_right_inj ((a * b) ^ 2), mul_left_comm _ _ (f _ ^ 2), \u2190 mul_pow,\n      h4, one_pow, mul_one, mul_comm _ ((a * b) ^ 2), \u2190 mul_assoc, \u2190 pow_add,\n      mul_pow, mul_add, mul_right_comm, \u2190 mul_pow, h1, one_pow, one_mul, add_comm,\n      add_left_inj, \u2190 mul_pow, \u2190 mul_pow, positive_pow_eq_pow four_pos, mul_assoc,\n      mul_right_eq_self, \u2190 sq, eq_comm, \u2190 one_pow 2, positive_pow_eq_pow two_pos] at h,\n  apply h3; subst h; rw [one_mul, h0]\nend\n\nend IMO2008A1\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2008/A1/A1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7210053507870922}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro\n-/\n\nimport algebra.algebra.basic\nimport algebra.category.CommRing.basic\nimport ring_theory.ideal.operations\n\n/-!\n\n# Local rings\n\nDefine local rings as commutative rings having a unique maximal ideal.\n\n## Main definitions\n\n* `local_ring`: A predicate on commutative rings, stating that every element `a` is either a unit\n  or `1 - a` is a unit. This is shown to be equivalent to the condition that there exists a unique\n  maximal ideal.\n* `local_ring.maximal_ideal`: The unique maximal ideal for a local rings. Its carrier set is the set\n  of non units.\n* `is_local_ring_hom`: A predicate on semiring homomorphisms, requiring that it maps nonunits\n  to nonunits. For local rings, this means that the image of the unique maximal ideal is again\n  contained in the unique maximal ideal.\n* `local_ring.residue_field`: The quotient of a local ring by its maximal ideal.\n\n-/\n\nuniverses u v w\n\n/-- A commutative ring is local if it has a unique maximal ideal. Note that\n  `local_ring` is a predicate. -/\nclass local_ring (R : Type u) [comm_ring R] extends nontrivial R : Prop :=\n(is_local : \u2200 (a : R), (is_unit a) \u2228 (is_unit (1 - a)))\n\nnamespace local_ring\n\nvariables {R : Type u} [comm_ring R] [local_ring R]\n\nlemma is_unit_or_is_unit_one_sub_self (a : R) :\n  (is_unit a) \u2228 (is_unit (1 - a)) :=\nis_local a\n\nlemma is_unit_of_mem_nonunits_one_sub_self (a : R) (h : (1 - a) \u2208 nonunits R) :\n  is_unit a :=\nor_iff_not_imp_right.1 (is_local a) h\n\nlemma is_unit_one_sub_self_of_mem_nonunits (a : R) (h : a \u2208 nonunits R) :\n  is_unit (1 - a) :=\nor_iff_not_imp_left.1 (is_local a) h\n\nlemma nonunits_add {x y} (hx : x \u2208 nonunits R) (hy : y \u2208 nonunits R) :\n  x + y \u2208 nonunits R :=\nbegin\n  rintros \u27e8u, hu\u27e9,\n  apply hy,\n  suffices : is_unit ((\u2191u\u207b\u00b9 : R) * y),\n  { rcases this with \u27e8s, hs\u27e9,\n    use u * s,\n    convert congr_arg (\u03bb z, (u : R) * z) hs,\n    rw \u2190 mul_assoc, simp },\n  rw show (\u2191u\u207b\u00b9 * y) = (1 - \u2191u\u207b\u00b9 * x),\n  { rw eq_sub_iff_add_eq,\n    replace hu := congr_arg (\u03bb z, (\u2191u\u207b\u00b9 : R) * z) hu.symm,\n    simpa [mul_add, add_comm] using hu },\n  apply is_unit_one_sub_self_of_mem_nonunits,\n  exact mul_mem_nonunits_right hx\nend\n\nvariable (R)\n\n/-- The ideal of elements that are not units. -/\ndef maximal_ideal : ideal R :=\n{ carrier := nonunits R,\n  zero_mem' := zero_mem_nonunits.2 $ zero_ne_one,\n  add_mem' := \u03bb x y hx hy, nonunits_add hx hy,\n  smul_mem' := \u03bb a x, mul_mem_nonunits_right }\n\ninstance maximal_ideal.is_maximal : (maximal_ideal R).is_maximal :=\nbegin\n  rw ideal.is_maximal_iff,\n  split,\n  { intro h, apply h, exact is_unit_one },\n  { intros I x hI hx H,\n    erw not_not at hx,\n    rcases hx with \u27e8u,rfl\u27e9,\n    simpa using I.mul_mem_left \u2191u\u207b\u00b9 H }\nend\n\nlemma maximal_ideal_unique :\n  \u2203! I : ideal R, I.is_maximal :=\n\u27e8maximal_ideal R, maximal_ideal.is_maximal R,\n  \u03bb I hI, hI.eq_of_le (maximal_ideal.is_maximal R).1.1 $\n  \u03bb x hx, hI.1.1 \u2218 I.eq_top_of_is_unit_mem hx\u27e9\n\nvariable {R}\n\nlemma eq_maximal_ideal {I : ideal R} (hI : I.is_maximal) : I = maximal_ideal R :=\nunique_of_exists_unique (maximal_ideal_unique R) hI $ maximal_ideal.is_maximal R\n\nlemma le_maximal_ideal {J : ideal R} (hJ : J \u2260 \u22a4) : J \u2264 maximal_ideal R :=\nbegin\n  rcases ideal.exists_le_maximal J hJ with \u27e8M, hM1, hM2\u27e9,\n  rwa \u2190eq_maximal_ideal hM1\nend\n\n@[simp] lemma mem_maximal_ideal (x) :\n  x \u2208 maximal_ideal R \u2194 x \u2208 nonunits R := iff.rfl\n\nend local_ring\n\nvariables {R : Type u} {S : Type v} {T : Type w}\n\nlemma local_of_nonunits_ideal [comm_ring R] (hnze : (0:R) \u2260 1)\n  (h : \u2200 x y \u2208 nonunits R, x + y \u2208 nonunits R) : local_ring R :=\n{ exists_pair_ne := \u27e80, 1, hnze\u27e9,\n  is_local := \u03bb x, or_iff_not_imp_left.mpr $ \u03bb hx,\n  begin\n    by_contra H,\n    apply h _ _ hx H,\n    simp [-sub_eq_add_neg, add_sub_cancel'_right]\n  end }\n\nlemma local_of_unique_max_ideal [comm_ring R] (h : \u2203! I : ideal R, I.is_maximal) :\n  local_ring R :=\nlocal_of_nonunits_ideal\n(let \u27e8I, Imax, _\u27e9 := h in (\u03bb (H : 0 = 1), Imax.1.1 $ I.eq_top_iff_one.2 $ H \u25b8 I.zero_mem))\n$ \u03bb x y hx hy H,\nlet \u27e8I, Imax, Iuniq\u27e9 := h in\nlet \u27e8Ix, Ixmax, Hx\u27e9 := exists_max_ideal_of_mem_nonunits hx in\nlet \u27e8Iy, Iymax, Hy\u27e9 := exists_max_ideal_of_mem_nonunits hy in\nhave xmemI : x \u2208 I, from ((Iuniq Ix Ixmax) \u25b8 Hx),\nhave ymemI : y \u2208 I, from ((Iuniq Iy Iymax) \u25b8 Hy),\nImax.1.1 $ I.eq_top_of_is_unit_mem (I.add_mem xmemI ymemI) H\n\nlemma local_of_unique_nonzero_prime (R : Type u) [comm_ring R]\n  (h : \u2203! P : ideal R, P \u2260 \u22a5 \u2227 ideal.is_prime P) : local_ring R :=\nlocal_of_unique_max_ideal begin\n  rcases h with \u27e8P, \u27e8hPnonzero, hPnot_top, _\u27e9, hPunique\u27e9,\n  refine \u27e8P, \u27e8\u27e8hPnot_top, _\u27e9\u27e9, \u03bb M hM, hPunique _ \u27e8_, ideal.is_maximal.is_prime hM\u27e9\u27e9,\n  { refine ideal.maximal_of_no_maximal (\u03bb M hPM hM, ne_of_lt hPM _),\n    exact (hPunique _ \u27e8ne_bot_of_gt hPM, ideal.is_maximal.is_prime hM\u27e9).symm },\n  { rintro rfl,\n    exact hPnot_top (hM.1.2 P (bot_lt_iff_ne_bot.2 hPnonzero)) },\nend\n\nlemma local_of_surjective [comm_ring R] [local_ring R] [comm_ring S] [nontrivial S]\n  (f : R \u2192+* S) (hf : function.surjective f) :\n  local_ring S :=\n{ is_local :=\n  begin\n    intros b,\n    obtain \u27e8a, rfl\u27e9 := hf b,\n    apply (local_ring.is_unit_or_is_unit_one_sub_self a).imp f.is_unit_map _,\n    rw [\u2190 f.map_one, \u2190 f.map_sub],\n    apply f.is_unit_map,\n  end,\n  .. \u2039nontrivial S\u203a }\n\n/-- A local ring homomorphism is a homomorphism between local rings\n  such that the image of the maximal ideal of the source is contained within\n  the maximal ideal of the target. -/\nclass is_local_ring_hom [semiring R] [semiring S] (f : R \u2192+* S) : Prop :=\n(map_nonunit : \u2200 a, is_unit (f a) \u2192 is_unit a)\n\ninstance is_local_ring_hom_id (R : Type*) [semiring R] : is_local_ring_hom (ring_hom.id R) :=\n{ map_nonunit := \u03bb a, id }\n\n@[simp] lemma is_unit_map_iff [semiring R] [semiring S] (f : R \u2192+* S)\n  [is_local_ring_hom f] (a) :\n  is_unit (f a) \u2194 is_unit a :=\n\u27e8is_local_ring_hom.map_nonunit a, f.is_unit_map\u27e9\n\ninstance is_local_ring_hom_comp [semiring R] [semiring S] [semiring T]\n  (g : S \u2192+* T) (f : R \u2192+* S) [is_local_ring_hom g] [is_local_ring_hom f] :\n  is_local_ring_hom (g.comp f) :=\n{ map_nonunit := \u03bb a, is_local_ring_hom.map_nonunit a \u2218 is_local_ring_hom.map_nonunit (f a) }\n\ninstance is_local_ring_hom_equiv [semiring R] [semiring S] (f : R \u2243+* S) :\n  is_local_ring_hom f.to_ring_hom :=\n{ map_nonunit := \u03bb a ha,\n  begin\n    convert f.symm.to_ring_hom.is_unit_map ha,\n    rw ring_equiv.symm_to_ring_hom_apply_to_ring_hom_apply,\n  end }\n\n@[simp] lemma is_unit_of_map_unit [semiring R] [semiring S] (f : R \u2192+* S) [is_local_ring_hom f]\n  (a) (h : is_unit (f a)) : is_unit a :=\nis_local_ring_hom.map_nonunit a h\n\ntheorem of_irreducible_map [semiring R] [semiring S] (f : R \u2192+* S) [h : is_local_ring_hom f] {x : R}\n  (hfx : irreducible (f x)) : irreducible x :=\n\u27e8\u03bb h, hfx.not_unit $ is_unit.map f.to_monoid_hom h, \u03bb p q hx, let \u27e8H\u27e9 := h in\nor.imp (H p) (H q) $ hfx.is_unit_or_is_unit $ f.map_mul p q \u25b8 congr_arg f hx\u27e9\n\nsection\nopen category_theory\n\nlemma is_local_ring_hom_of_iso {R S : CommRing} (f : R \u2245 S) : is_local_ring_hom f.hom :=\n{ map_nonunit := \u03bb a ha,\n  begin\n    convert f.inv.is_unit_map ha,\n    rw category_theory.coe_hom_inv_id,\n  end }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_local_ring_hom_of_is_iso {R S : CommRing} (f : R \u27f6 S) [is_iso f] :\n  is_local_ring_hom f :=\nis_local_ring_hom_of_iso (as_iso f)\n\nend\n\nsection\nopen local_ring\nvariables [comm_ring R] [local_ring R] [comm_ring S] [local_ring S]\nvariables (f : R \u2192+* S) [is_local_ring_hom f]\n\nlemma map_nonunit (a : R) (h : a \u2208 maximal_ideal R) : f a \u2208 maximal_ideal S :=\n\u03bb H, h $ is_unit_of_map_unit f a H\n\nend\n\nnamespace local_ring\nvariables [comm_ring R] [local_ring R] [comm_ring S] [local_ring S]\n\n/--\nA ring homomorphism between local rings is a local ring hom iff it reflects units,\ni.e. any preimage of a unit is still a unit. https://stacks.math.columbia.edu/tag/07BJ\n-/\ntheorem local_hom_tfae (f : R \u2192+* S) :\n  tfae [is_local_ring_hom f,\n        f '' (maximal_ideal R).1 \u2286 maximal_ideal S,\n        (maximal_ideal R).map f \u2264 maximal_ideal S,\n        maximal_ideal R \u2264 (maximal_ideal S).comap f,\n        (maximal_ideal S).comap f = maximal_ideal R] :=\nbegin\n  tfae_have : 1 \u2192 2, rintros _ _ \u27e8a,ha,rfl\u27e9,\n    resetI, exact map_nonunit f a ha,\n  tfae_have : 2 \u2192 4, exact set.image_subset_iff.1,\n  tfae_have : 3 \u2194 4, exact ideal.map_le_iff_le_comap,\n  tfae_have : 4 \u2192 1, intro h, fsplit, exact \u03bb x, not_imp_not.1 (@h x),\n  tfae_have : 1 \u2192 5, intro, resetI, ext,\n    exact not_iff_not.2 (is_unit_map_iff f x),\n  tfae_have : 5 \u2192 4, exact \u03bb h, le_of_eq h.symm,\n  tfae_finish,\nend\n\nvariable (R)\n/-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/\ndef residue_field := R \u29f8 maximal_ideal R\n\nnoncomputable instance residue_field.field : field (residue_field R) :=\nideal.quotient.field (maximal_ideal R)\n\nnoncomputable instance : inhabited (residue_field R) := \u27e837\u27e9\n\n/-- The quotient map from a local ring to its residue field. -/\ndef residue : R \u2192+* (residue_field R) :=\nideal.quotient.mk _\n\nnoncomputable instance residue_field.algebra : algebra R (residue_field R) := (residue R).to_algebra\n\nnamespace residue_field\n\n\nvariables {R S}\n/-- The map on residue fields induced by a local homomorphism between local rings -/\nnoncomputable def map (f : R \u2192+* S) [is_local_ring_hom f] :\n  residue_field R \u2192+* residue_field S :=\nideal.quotient.lift (maximal_ideal R) ((ideal.quotient.mk _).comp f) $\n\u03bb a ha,\nbegin\n  erw ideal.quotient.eq_zero_iff_mem,\n  exact map_nonunit f a ha\nend\n\nend residue_field\n\nvariables {R}\n\nlemma ker_eq_maximal_ideal {K : Type*} [field K]\n  (\u03c6 : R \u2192+* K) (h\u03c6 : function.surjective \u03c6) : \u03c6.ker = maximal_ideal R :=\nlocal_ring.eq_maximal_ideal $ \u03c6.ker_is_maximal_of_surjective h\u03c6\n\nend local_ring\n\nnamespace field\nvariables [field R]\n\nopen_locale classical\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : local_ring R :=\n{ is_local := \u03bb a,\n  if h : a = 0\n  then or.inr (by rw [h, sub_zero]; exact is_unit_one)\n  else or.inl $ is_unit.mk0 a h }\n\nend field\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/ideal/local_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7210053359008182}}
{"text": "import data.real.basic\n\n-- BEGIN\nexample {x y : \u211d} (h : x \u2264 y) : \u00ac y \u2264 x \u2194 x \u2260 y :=\nbegin\n  split,\n    intro h1,\n    intro h2,\n    rw h2 at h1,\n    rw h2 at h,\n    exact h1 h,\n  intro h1,\n  contrapose! h1,\n  exact le_antisymm h h1,\nend\n\n-- Alternatively\nexample {x y : \u211d} (h : x \u2264 y) : \u00ac y \u2264 x \u2194 x \u2260 y :=\nbegin\n  split,\n    intro h1,\n    push_neg at h1,\n    intro h2,\n    rw h2 at h1,\n    exact (lt_irrefl y) h1,\n  intro h1,\n  contrapose! h1,\n  exact le_antisymm h h1,\nend\n\n-- Alternatively\nexample {x y : \u211d} (h : x \u2264 y) : \u00ac y \u2264 x \u2194 x \u2260 y :=\nbegin\n  split,\n  { contrapose!,\n    rintro rfl,\n    reflexivity },\n  contrapose!,\n  exact le_antisymm h,\nend\n\nexample {x y : \u211d} (h : x \u2264 y) : \u00ac y \u2264 x \u2194 x \u2260 y :=\n\u27e8\u03bb h\u2080 h\u2081, h\u2080 (by rw h\u2081), \u03bb h\u2080 h\u2081, h\u2080 (le_antisymm h h\u2081)\u27e9\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/5_split/5.2_iff/ex3_split_iff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7210053336189108}}
{"text": "theorem mul_left_cancel (a b c : mynat) (ha : a \u2260 0) : a * b = a * c \u2192 b = c :=\nbegin\ninduction c with d hd generalizing b,\nrw mul_zero,\nintro h,\ncases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ h) with h1 h2,\nexfalso,\napply ha,\nexact h1,\nexact h2,\nintro hb,\ncases b,\nrw mul_zero at hb,\nexfalso,\napply ha,\nsymmetry at hb,\ncases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ hb) with h1 h2,\nexact h1,\nexfalso,\nexact succ_ne_zero _ h2,\nhave h : b = d,\napply hd,\nrw mul_succ at hb,\nrw mul_succ at hb,\nexact add_right_cancel _ _ _ hb,\nrwa h,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world09/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.7210053336189107}}
{"text": "inductive naravno : Type    -- type naravno = \n| nic : naravno             -- | Nic\n| nasl : naravno -> naravno -- | Nasl of naravno\n\ndef plus : naravno -> naravno -> naravno\n| naravno.nic      m := m\n| (naravno.nasl m) n := naravno.nasl (plus m n)\n\ntheorem plus_assoc : forall m n p, plus (plus m n) p = plus m (plus n p) :=\n  begin\n    intros,\n    induction m,\n    case naravno.nic {\n      unfold plus,\n    },\n    case naravno.nasl {\n      unfold plus,\n      rewrite m_ih,\n    }\n  end\n\n-- P /\\ Q  ... p * q\n-- je_sodo 4 ... izjava\n-- je_sodo  ... funkcija iz naravnih \u0161tevil v izjave\n\ninductive je_sodo : naravno -> Prop\n| nic : je_sodo naravno.nic\n| nasl_nasl {n} : je_sodo n -> je_sodo (naravno.nasl (naravno.nasl n))\n\n#check je_sodo.nasl_nasl je_sodo.nic\n\nlemma stiri_je_sodo : je_sodo (naravno.nasl (naravno.nasl (naravno.nasl (naravno.nasl naravno.nic)))) := begin\n  apply je_sodo.nasl_nasl,\n  apply je_sodo.nasl_nasl,\n  apply je_sodo.nic,\nend\n\ntheorem sodo_plus_sodo : forall m n, je_sodo m -> je_sodo n -> je_sodo (plus m n) :=\nbegin\n  intros m n h_m h_n,\n  induction h_m,\n  case je_sodo.nic {\n    unfold plus,\n    assumption,\n  },\n  case je_sodo.nasl_nasl {\n    rename h_m_n m',\n    unfold plus,\n    apply je_sodo.nasl_nasl,\n    assumption,\n  }\nend\n\ninductive manj_enako : naravno -> naravno -> Prop\n| nic : forall m, manj_enako naravno.nic m\n| nasl {m n} : manj_enako m n -> manj_enako (naravno.nasl m) (naravno.nasl n)\n\ninductive manj_enako' : naravno -> naravno -> Prop\n| refl : forall m, manj_enako' m m\n| nasl : forall m n, manj_enako' m n -> manj_enako' m (naravno.nasl n)\n\ntheorem manj_enako_refl : forall m, manj_enako m m :=\nbegin\n  intros,\n  induction m,\n  case naravno.nic {exact (manj_enako.nic naravno.nic)},\n  case naravno.nasl {exact (manj_enako.nasl m_ih)},\nend\n\n\ntheorem manj_enako_trans : forall m n, manj_enako m n -> forall p, manj_enako n p -> manj_enako m p :=\nbegin\n  intros m n p h_m_manjse_n h_n_manjse_p,\n  induction h_m_manjse_n,\n  case manj_enako.nic {exact (manj_enako.nic p)},\n  case manj_enako.nasl {\n    rename h_m_manjse_n_m m',\n    rename h_m_manjse_n_n n',\n    cases h_n_manjse_p,\n    rename h_n_manjse_p_n p',\n\n\n  }\nend\n\ntheorem manj_enako_refl' : forall m, manj_enako' m m :=\nbegin\n  exact manj_enako'.refl\nend\n", "meta": {"author": "tadejpetric", "repo": "tpj-coq", "sha": "dda9fb2e635f9a1302739e34d8692a4252066b76", "save_path": "github-repos/lean/tadejpetric-tpj-coq", "path": "github-repos/lean/tadejpetric-tpj-coq/tpj-coq-dda9fb2e635f9a1302739e34d8692a4252066b76/06-formalizacija-dokazov/naravna.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7209974944583213}}
{"text": "import data.set\nimport logic.basic\n\nopen set \n\nnamespace mth1001\n\nsection cartesian_product\n-- In this file, we'll deal with two types, `U` and `V`.\nvariables (U : Type*) (V : Type*)\nvariables (S T : set U) (A B : set V)\n\n\n/-\n`U \u00d7 V` is the (Cartesian) product type of `U` and `V`. It is the type of all pairs `(u,v)`, where\n`u : U` and `v : V`.\n-/\n#check U \u00d7 V\n\n/-\nWARNING: In Lean, the `\u00d7` symbol denotes the Cartesian product of types, not sets. However, we\ncan use the following special command to make Lean temporarily treat `\u00d7` as a set product.\n-/\nlocal notation a `\u00d7` b := set.prod a b\n\n-- In addition to the results `mem_inter_iff`, `mem_union_eq`, `mem_diff` introduced in\n-- the previous files, we'll use `mem_prod` to rewrite a product of two sets.\n\nexample (x : prod U V) : x \u2208 (S \u00d7 A) \u2194 x.fst \u2208 S \u2227 x.snd \u2208 A := by rw mem_prod\n\nexample : (S \u00d7 (A \u222a B)) = (S \u00d7 A) \u222a (S \u00d7 B) :=\nbegin\n  ext, -- Assume `x : U \u00d7 V`. It suffices to prove `x \u2208 (S \u00d7 (A \u222a B)) \u2194 x \u2208 (S \u00d7 A) \u222a (S \u00d7 B)`.\n  rw [mem_prod, mem_union_eq, mem_union_eq, mem_prod, mem_prod],\n  rw and_or_distrib_left, -- Complete using left distributivity of `\u2227` over `\u2228`.\nend\n\n-- Exercise 139:\n-- In this example, feel free to use the `tauto` tactic to finish the 'logic' part of the proof.\nexample : (S \u00d7 (A \u2229 B)) = (S \u00d7 A) \u2229  (S \u00d7 B) :=\nbegin\n  sorry  \nend\n\n-- Exercise 140:\n-- For this example, you'll either need De Morgan's law or the `tauto!` tactic which,\n-- unlike `tauto`, is permitted to use classical reasoning.\nexample : (S \u00d7 (A \\ B)) = (S \u00d7 A) \\  (S \u00d7 B) :=\nbegin\n  sorry  \nend\n\n\nend cartesian_product\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_27_cartesian_product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942093072239, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7209974921095712}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies, Ella Yu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Ella Yu\n-/\nimport data.finset.prod\nimport data.fintype.prod\n\n/-!\n# Additive energy\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the additive energy of two finsets of a group. This is a central quantity in\nadditive combinatorics.\n\n## TODO\n\nIt's possibly interesting to have\n`(s \u00d7\u02e2 s) \u00d7\u02e2 t \u00d7\u02e2 t).filter (\u03bb x : (\u03b1 \u00d7 \u03b1) \u00d7 \u03b1 \u00d7 \u03b1, x.1.1 * x.2.1 = x.1.2 * x.2.2)` (whose `card` is\n`multiplicative_energy s t`) as a standalone definition.\n-/\n\nsection\nvariables {\u03b1 : Type*} [partial_order \u03b1] {x y : \u03b1}\n\nend\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1]\n\nnamespace finset\nsection has_mul\nvariables [has_mul \u03b1] {s s\u2081 s\u2082 t t\u2081 t\u2082 : finset \u03b1}\n\n/-- The multiplicative energy of two finsets `s` and `t` in a group is the number of quadruples\n`(a\u2081, a\u2082, b\u2081, b\u2082) \u2208 s \u00d7 s \u00d7 t \u00d7 t` such that `a\u2081 * b\u2081 = a\u2082 * b\u2082`. -/\n@[to_additive additive_energy \"The additive energy of two finsets `s` and `t` in a group is the\nnumber of quadruples `(a\u2081, a\u2082, b\u2081, b\u2082) \u2208 s \u00d7 s \u00d7 t \u00d7 t` such that `a\u2081 + b\u2081 = a\u2082 + b\u2082`.\"]\ndef multiplicative_energy (s t : finset \u03b1) : \u2115 :=\n(((s \u00d7\u02e2 s) \u00d7\u02e2 t \u00d7\u02e2 t).filter $ \u03bb x : (\u03b1 \u00d7 \u03b1) \u00d7 \u03b1 \u00d7 \u03b1, x.1.1 * x.2.1 = x.1.2 * x.2.2).card\n\n@[to_additive additive_energy_mono]\nlemma multiplicative_energy_mono (hs : s\u2081 \u2286 s\u2082) (ht : t\u2081 \u2286 t\u2082) :\n  multiplicative_energy s\u2081 t\u2081 \u2264 multiplicative_energy s\u2082 t\u2082 :=\ncard_le_of_subset $ filter_subset_filter _ $ product_subset_product (product_subset_product hs hs) $\n  product_subset_product ht ht\n\n@[to_additive additive_energy_mono_left]\nlemma multiplicative_energy_mono_left (hs : s\u2081 \u2286 s\u2082) :\n  multiplicative_energy s\u2081 t \u2264 multiplicative_energy s\u2082 t :=\nmultiplicative_energy_mono hs subset.rfl\n\n@[to_additive additive_energy_mono_right]\nlemma multiplicative_energy_mono_right (ht : t\u2081 \u2286 t\u2082) :\n  multiplicative_energy s t\u2081 \u2264 multiplicative_energy s t\u2082 :=\nmultiplicative_energy_mono subset.rfl ht\n\n@[to_additive le_additive_energy]\nlemma le_multiplicative_energy : s.card * t.card \u2264 multiplicative_energy s t :=\nbegin\n  rw \u2190card_product,\n  refine card_le_card_of_inj_on (\u03bb x, ((x.1, x.1), x.2, x.2)) (by simp [\u2190and_imp]) (\u03bb a _ b _, _),\n  simp only [prod.mk.inj_iff, and_self, and_imp],\n  exact prod.ext,\nend\n\n@[to_additive additive_energy_pos]\nlemma multiplicative_energy_pos (hs : s.nonempty) (ht : t.nonempty) :\n  0 < multiplicative_energy s t :=\n(mul_pos hs.card_pos ht.card_pos).trans_le le_multiplicative_energy\n\nvariables (s t)\n\n@[simp, to_additive additive_energy_empty_left]\nlemma multiplicative_energy_empty_left : multiplicative_energy \u2205 t = 0 :=\nby simp [multiplicative_energy]\n\n@[simp, to_additive additive_energy_empty_right]\nlemma multiplicative_energy_empty_right : multiplicative_energy s \u2205 = 0 :=\nby simp [multiplicative_energy]\n\nvariables {s t}\n\n@[simp, to_additive additive_energy_pos_iff]\nlemma multiplicative_energy_pos_iff : 0 < multiplicative_energy s t \u2194 s.nonempty \u2227 t.nonempty :=\n\u27e8\u03bb h, of_not_not $ \u03bb H, begin\n  simp_rw [not_and_distrib, not_nonempty_iff_eq_empty] at H,\n  obtain rfl | rfl := H; simpa [nat.not_lt_zero] using h,\nend, \u03bb h, multiplicative_energy_pos h.1 h.2\u27e9\n\n@[simp, to_additive additive_energy_eq_zero_iff]\nlemma multiplicative_energy_eq_zero_iff : multiplicative_energy s t = 0 \u2194 s = \u2205 \u2228 t = \u2205 :=\nby simp [\u2190(nat.zero_le _).not_gt_iff_eq, not_and_distrib]\n\nend has_mul\n\nsection comm_monoid\nvariables [comm_monoid \u03b1]\n\n@[to_additive additive_energy_comm]\nlemma multiplicative_energy_comm (s t : finset \u03b1) :\n  multiplicative_energy s t = multiplicative_energy t s :=\nbegin\n  rw [multiplicative_energy, \u2190finset.card_map (equiv.prod_comm _ _).to_embedding, map_filter],\n  simp [-finset.card_map, eq_comm, multiplicative_energy, mul_comm, map_eq_image, function.comp],\nend\n\nend comm_monoid\n\nsection comm_group\nvariables [comm_group \u03b1] [fintype \u03b1] (s t : finset \u03b1)\n\n@[simp, to_additive additive_energy_univ_left]\nlemma multiplicative_energy_univ_left :\n  multiplicative_energy univ t = fintype.card \u03b1 * t.card ^ 2 :=\nbegin\n  simp only [multiplicative_energy, univ_product_univ, fintype.card, sq, \u2190card_product],\n  set f : \u03b1 \u00d7 \u03b1 \u00d7 \u03b1 \u2192 (\u03b1 \u00d7 \u03b1) \u00d7 \u03b1 \u00d7 \u03b1 := \u03bb x, ((x.1 * x.2.2, x.1 * x.2.1), x.2) with hf,\n  have : (\u2191((univ : finset \u03b1) \u00d7\u02e2 t \u00d7\u02e2 t) : set (\u03b1 \u00d7 \u03b1 \u00d7 \u03b1)).inj_on f,\n  { rintro \u27e8a\u2081, b\u2081, c\u2081\u27e9 h\u2081 \u27e8a\u2082, b\u2082, c\u2082\u27e9 h\u2082 h,\n    simp_rw prod.ext_iff at h,\n    obtain \u27e8h, rfl, rfl\u27e9 := h,\n    rw mul_right_cancel h.1 },\n  rw [\u2190card_image_of_inj_on this],\n  congr' with a,\n  simp only [hf, mem_filter, mem_product, mem_univ, true_and, mem_image, exists_prop, prod.exists],\n  refine \u27e8\u03bb h, \u27e8a.1.1 * a.2.2\u207b\u00b9, _, _, h.1, by simp [mul_right_comm, h.2]\u27e9, _\u27e9,\n  rintro \u27e8b, c, d, hcd, rfl\u27e9,\n  simpa [mul_right_comm],\nend\n\n@[simp, to_additive additive_energy_univ_right]\nlemma multiplicative_energy_univ_right :\n  multiplicative_energy s univ = fintype.card \u03b1 * s.card ^ 2 :=\nby rw [multiplicative_energy_comm, multiplicative_energy_univ_left]\n\nend comm_group\nend finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/additive/energy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7209974920193065}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen\n-/\nimport ring_theory.localization.basic\n\n/-!\n# Integer elements of a localization\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\n * `is_localization.is_integer` is a predicate stating that `x : S` is in the image of `R`\n\n## Implementation notes\n\nSee `src/ring_theory/localization/basic.lean` for a design overview.\n\n## Tags\nlocalization, ring localization, commutative ring localization, characteristic predicate,\ncommutative ring, field of fractions\n-/\n\nvariables {R : Type*} [comm_ring R] {M : submonoid R} {S : Type*} [comm_ring S]\nvariables [algebra R S] {P : Type*} [comm_ring P]\n\nopen function\nopen_locale big_operators\n\nnamespace is_localization\n\nsection\n\nvariables (R) {M S}\n\n-- TODO: define a subalgebra of `is_integer`s\n/-- Given `a : S`, `S` a localization of `R`, `is_integer R a` iff `a` is in the image of\nthe localization map from `R` to `S`. -/\ndef is_integer (a : S) : Prop := a \u2208 (algebra_map R S).range\n\nend\n\nlemma is_integer_zero : is_integer R (0 : S) := subring.zero_mem _\nlemma is_integer_one : is_integer R (1 : S) := subring.one_mem _\n\nlemma is_integer_add {a b : S} (ha : is_integer R a) (hb : is_integer R b) :\n  is_integer R (a + b) :=\nsubring.add_mem _ ha hb\n\nlemma is_integer_mul {a b : S} (ha : is_integer R a) (hb : is_integer R b) :\n  is_integer R (a * b) :=\nsubring.mul_mem _ ha hb\n\nlemma is_integer_smul {a : R} {b : S} (hb : is_integer R b) :\n  is_integer R (a \u2022 b) :=\nbegin\n  rcases hb with \u27e8b', hb\u27e9,\n  use a * b',\n  rw [\u2190hb, (algebra_map R S).map_mul, algebra.smul_def]\nend\n\nvariables (M) {S} [is_localization M S]\n\n/-- Each element `a : S` has an `M`-multiple which is an integer.\n\nThis version multiplies `a` on the right, matching the argument order in `localization_map.surj`.\n-/\nlemma exists_integer_multiple' (a : S) :\n  \u2203 (b : M), is_integer R (a * algebra_map R S b) :=\nlet \u27e8\u27e8num, denom\u27e9, h\u27e9 := is_localization.surj _ a in \u27e8denom, set.mem_range.mpr \u27e8num, h.symm\u27e9\u27e9\n\n/-- Each element `a : S` has an `M`-multiple which is an integer.\n\nThis version multiplies `a` on the left, matching the argument order in the `has_smul` instance.\n-/\nlemma exists_integer_multiple (a : S) :\n  \u2203 (b : M), is_integer R ((b : R) \u2022 a) :=\nby { simp_rw [algebra.smul_def, mul_comm _ a], apply exists_integer_multiple' }\n\n/-- We can clear the denominators of a `finset`-indexed family of fractions. -/\nlemma exist_integer_multiples {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 S) :\n  \u2203 (b : M), \u2200 i \u2208 s, is_localization.is_integer R ((b : R) \u2022 f i) :=\nbegin\n  haveI := classical.prop_decidable,\n  refine \u27e8\u220f i in s, (sec M (f i)).2, \u03bb i hi, \u27e8_, _\u27e9\u27e9,\n  { exact (\u220f j in s.erase i, (sec M (f j)).2) * (sec M (f i)).1 },\n  rw [ring_hom.map_mul, sec_spec', \u2190mul_assoc, \u2190(algebra_map R S).map_mul, \u2190 algebra.smul_def],\n  congr' 2,\n  refine trans _ ((submonoid.subtype M).map_prod _ _).symm,\n  rw [mul_comm, \u2190finset.prod_insert (s.not_mem_erase i), finset.insert_erase hi],\n  refl\nend\n\n/-- We can clear the denominators of a finite indexed family of fractions. -/\nlemma exist_integer_multiples_of_finite {\u03b9 : Type*} [finite \u03b9] (f : \u03b9 \u2192 S) :\n  \u2203 (b : M), \u2200 i, is_localization.is_integer R ((b : R) \u2022 f i) :=\nbegin\n  casesI nonempty_fintype \u03b9,\n  obtain \u27e8b, hb\u27e9 := exist_integer_multiples M finset.univ f,\n  exact \u27e8b, \u03bb i, hb i (finset.mem_univ _)\u27e9\nend\n\n/-- We can clear the denominators of a finite set of fractions. -/\nlemma exist_integer_multiples_of_finset (s : finset S) :\n  \u2203 (b : M), \u2200 a \u2208 s, is_integer R ((b : R) \u2022 a) :=\nexist_integer_multiples M s id\n\n/-- A choice of a common multiple of the denominators of a `finset`-indexed family of fractions. -/\nnoncomputable\ndef common_denom {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 S) : M :=\n(exist_integer_multiples M s f).some\n\n/-- The numerator of a fraction after clearing the denominators\nof a `finset`-indexed family of fractions. -/\nnoncomputable\ndef integer_multiple {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 S) (i : s) : R :=\n((exist_integer_multiples M s f).some_spec i i.prop).some\n\n@[simp]\nlemma map_integer_multiple {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 S) (i : s) :\n  algebra_map R S (integer_multiple M s f i) = common_denom M s f \u2022 f i :=\n((exist_integer_multiples M s f).some_spec _ i.prop).some_spec\n\n/-- A choice of a common multiple of the denominators of a finite set of fractions. -/\nnoncomputable\ndef common_denom_of_finset (s : finset S) : M :=\ncommon_denom M s id\n\n/-- The finset of numerators after clearing the denominators of a finite set of fractions. -/\nnoncomputable\ndef finset_integer_multiple [decidable_eq R] (s : finset S) : finset R :=\ns.attach.image (\u03bb t, integer_multiple M s id t)\n\nopen_locale pointwise\n\nlemma finset_integer_multiple_image [decidable_eq R] (s : finset S) :\n  algebra_map R S '' (finset_integer_multiple M s) =\n    common_denom_of_finset M s \u2022 s :=\nbegin\n  delta finset_integer_multiple common_denom,\n  rw finset.coe_image,\n  ext,\n  split,\n  { rintro \u27e8_, \u27e8x, -, rfl\u27e9, rfl\u27e9,\n    rw map_integer_multiple,\n    exact set.mem_image_of_mem _ x.prop },\n  { rintro \u27e8x, hx, rfl\u27e9,\n    exact \u27e8_, \u27e8\u27e8x, hx\u27e9, s.mem_attach _, rfl\u27e9, map_integer_multiple M s id _\u27e9 }\nend\n\nend is_localization\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/localization/integer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7209974858757033}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\n\nimport algebra.group_power.basic\nimport logic.function.iterate\nimport group_theory.perm.basic\nimport group_theory.group_action.opposite\n\n/-!\n# Iterates of monoid and ring homomorphisms\n\nIterate of a monoid/ring homomorphism is a monoid/ring homomorphism but it has a wrong type, so Lean\ncan't apply lemmas like `monoid_hom.map_one` to `f^[n] 1`. Though it is possible to define\na monoid structure on the endomorphisms, quite often we do not want to convert from\n`M \u2192* M` to `monoid.End M` and from `f^[n]` to `f^n` just to apply a simple lemma.\n\nSo, we restate standard `*_hom.map_*` lemmas under names `*_hom.iterate_map_*`.\n\nWe also prove formulas for iterates of add/mul left/right.\n\n## Tags\n\nhomomorphism, iterate\n-/\n\nopen function\n\nvariables {M : Type*} {N : Type*} {G : Type*} {H : Type*}\n\n/-- An auxiliary lemma that can be used to prove `\u21d1(f ^ n) = (\u21d1f^[n])`. -/\nlemma hom_coe_pow {F : Type*} [monoid F] (c : F \u2192 M \u2192 M) (h1 : c 1 = id)\n  (hmul : \u2200 f g, c (f * g) = c f \u2218 c g) (f : F) : \u2200 n, c (f ^ n) = (c f^[n])\n| 0 := by { rw [pow_zero, h1], refl }\n| (n + 1) := by rw [pow_succ, iterate_succ', hmul, hom_coe_pow]\n\nnamespace monoid_hom\n\nsection\n\nvariables [mul_one_class M] [mul_one_class N]\n\n@[simp, to_additive]\ntheorem iterate_map_one (f : M \u2192* M) (n : \u2115) : f^[n] 1 = 1 :=\niterate_fixed f.map_one n\n\n@[simp, to_additive]\ntheorem iterate_map_mul (f : M \u2192* M) (n : \u2115) (x y) :\n  f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nsemiconj\u2082.iterate f.map_mul n x y\n\nend\n\nvariables [monoid M] [monoid N] [group G] [group H]\n\n@[simp, to_additive]\ntheorem iterate_map_inv (f : G \u2192* G) (n : \u2115) (x) :\n  f^[n] (x\u207b\u00b9) = (f^[n] x)\u207b\u00b9 :=\ncommute.iterate_left f.map_inv n x\n\n@[simp, to_additive]\ntheorem iterate_map_div (f : G \u2192* G) (n : \u2115) (x y) :\n  f^[n] (x / y) = (f^[n] x) / (f^[n] y) :=\nsemiconj\u2082.iterate f.map_div n x y\n\ntheorem iterate_map_pow (f : M \u2192* M) (n : \u2115) (a) (m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_pow x m) n a\n\ntheorem iterate_map_zpow (f : G \u2192* G) (n : \u2115) (a) (m : \u2124) : f^[n] (a^m) = (f^[n] a)^m :=\ncommute.iterate_left (\u03bb x, f.map_zpow x m) n a\n\n\n\nend monoid_hom\n\nlemma monoid.End.coe_pow {M} [monoid M] (f : monoid.End M) (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) _ _\n\n-- we define these manually so that we can pick a better argument order\nnamespace add_monoid_hom\nvariables [add_monoid M] [add_group G]\n\ntheorem iterate_map_smul (f : M \u2192+ M) (n m : \u2115) (x : M) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_pow n x m\n\nattribute [to_additive, to_additive_reorder 5] monoid_hom.iterate_map_pow\n\ntheorem iterate_map_zsmul (f : G \u2192+ G) (n : \u2115) (m : \u2124) (x : G) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_multiplicative.iterate_map_zpow n x m\n\nattribute [to_additive, to_additive_reorder 5] monoid_hom.iterate_map_zpow\n\nend add_monoid_hom\n\nlemma add_monoid.End.coe_pow {A} [add_monoid A] (f : add_monoid.End A) (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) _ _\n\nnamespace ring_hom\n\nsection semiring\n\nvariables {R : Type*} [semiring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\nlemma coe_pow (n : \u2115) : \u21d1(f^n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb f g, rfl) f n\n\ntheorem iterate_map_one : f^[n] 1 = 1 := f.to_monoid_hom.iterate_map_one n\n\ntheorem iterate_map_zero : f^[n] 0 = 0 := f.to_add_monoid_hom.iterate_map_zero n\n\ntheorem iterate_map_add : f^[n] (x + y) = (f^[n] x) + (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_add n x y\n\ntheorem iterate_map_mul : f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=\nf.to_monoid_hom.iterate_map_mul n x y\n\ntheorem iterate_map_pow (a) (n m : \u2115) : f^[n] (a^m) = (f^[n] a)^m :=\nf.to_monoid_hom.iterate_map_pow n a m\n\ntheorem iterate_map_smul (n m : \u2115) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_smul n m x\n\nend semiring\n\nvariables {R : Type*} [ring R] (f : R \u2192+* R) (n : \u2115) (x y : R)\n\ntheorem iterate_map_sub : f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=\nf.to_add_monoid_hom.iterate_map_sub n x y\n\ntheorem iterate_map_neg : f^[n] (-x) = -(f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_neg n x\n\ntheorem iterate_map_zsmul (n : \u2115) (m : \u2124) (x : R) :\n  f^[n] (m \u2022 x) = m \u2022 (f^[n] x) :=\nf.to_add_monoid_hom.iterate_map_zsmul n m x\n\nend ring_hom\n\nlemma equiv.perm.coe_pow {\u03b1 : Type*} (f : equiv.perm \u03b1) (n : \u2115) : \u21d1(f ^ n) = (f^[n]) :=\nhom_coe_pow _ rfl (\u03bb _ _, rfl) _ _\n\n--what should be the namespace for this section?\nsection monoid\n\nvariables [monoid G] (a : G) (n : \u2115)\n\n@[simp, to_additive] lemma smul_iterate [mul_action G H] :\n  ((\u2022) a : H \u2192 H)^[n] = (\u2022) (a^n) :=\nfunext (\u03bb b, nat.rec_on n (by rw [iterate_zero, id.def, pow_zero, one_smul])\n  (\u03bb n ih, by rw [iterate_succ', comp_app, ih, pow_succ, mul_smul]))\n\n@[simp, to_additive] lemma mul_left_iterate : ((*) a)^[n] = (*) (a^n) :=\nsmul_iterate a n\n\n@[simp, to_additive] lemma mul_right_iterate : (* a)^[n] = (* a ^ n) :=\nsmul_iterate (mul_opposite.op a) n\n\n@[to_additive]\nlemma mul_right_iterate_apply_one : (* a)^[n] 1 = a ^ n :=\nby simp [mul_right_iterate]\n\nend monoid\n\nsection semigroup\n\nvariables [semigroup G] {a b c : G}\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_left (h : semiconj_by a b c) :\n  function.semiconj ((*)a) ((*)b) ((*)c) :=\n\u03bb j, by rw [\u2190 mul_assoc, h.eq, mul_assoc]\n\n@[to_additive]\nlemma commute.function_commute_mul_left (h : commute a b) :\n  function.commute ((*)a) ((*)b) :=\nsemiconj_by.function_semiconj_mul_left h\n\n@[to_additive]\nlemma semiconj_by.function_semiconj_mul_right_swap (h : semiconj_by a b c) :\n  function.semiconj (*a) (*c) (*b) :=\n\u03bb j, by simp_rw [mul_assoc, \u2190 h.eq]\n\n@[to_additive]\nlemma commute.function_commute_mul_right (h : commute a b) :\n  function.commute (*a) (*b) :=\nsemiconj_by.function_semiconj_mul_right_swap h\n\nend semigroup\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/hom/iterate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.7208790161310744}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport analysis.specific_limits.basic\nimport data.rat.denumerable\nimport data.set.intervals.image_preimage\nimport set_theory.cardinal.continuum\n\n/-!\n# The cardinality of the reals\n\nThis file shows that the real numbers have cardinality continuum, i.e. `#\u211d = \ud835\udd20`.\n\nWe show that `#\u211d \u2264 \ud835\udd20` by noting that every real number is determined by a Cauchy-sequence of the\nform `\u2115 \u2192 \u211a`, which has cardinality `\ud835\udd20`. To show that `#\u211d \u2265 \ud835\udd20` we define an injection from\n`{0, 1} ^ \u2115` to `\u211d` with `f \u21a6 \u03a3 n, f n * (1 / 3) ^ n`.\n\nWe conclude that all intervals with distinct endpoints have cardinality continuum.\n\n## Main definitions\n\n* `cardinal.cantor_function` is the function that sends `f` in `{0, 1} ^ \u2115` to `\u211d` by\n  `f \u21a6 \u03a3' n, f n * (1 / 3) ^ n`\n\n## Main statements\n\n* `cardinal.mk_real : #\u211d = \ud835\udd20`: the reals have cardinality continuum.\n* `cardinal.not_countable_real`: the universal set of real numbers is not countable.\n  We can use this same proof to show that all the other sets in this file are not countable.\n* 8 lemmas of the form `mk_Ixy_real` for `x,y \u2208 {i,o,c}` state that intervals on the reals\n  have cardinality continuum.\n\n## Notation\n\n* `\ud835\udd20` : notation for `cardinal.continuum` in locale `cardinal`, defined in `set_theory.continuum`.\n\n## Tags\ncontinuum, cardinality, reals, cardinality of the reals\n-/\n\nopen nat set\nopen_locale cardinal\nnoncomputable theory\n\nnamespace cardinal\n\nvariables {c : \u211d} {f g : \u2115 \u2192 bool} {n : \u2115}\n\n/-- The body of the sum in `cantor_function`.\n`cantor_function_aux c f n = c ^ n` if `f n = tt`;\n`cantor_function_aux c f n = 0` if `f n = ff`. -/\ndef cantor_function_aux (c : \u211d) (f : \u2115 \u2192 bool) (n : \u2115) : \u211d := cond (f n) (c ^ n) 0\n\n@[simp] lemma cantor_function_aux_tt (h : f n = tt) : cantor_function_aux c f n = c ^ n :=\nby simp [cantor_function_aux, h]\n\n@[simp] lemma cantor_function_aux_ff (h : f n = ff) : cantor_function_aux c f n = 0 :=\nby simp [cantor_function_aux, h]\n\nlemma cantor_function_aux_nonneg (h : 0 \u2264 c) : 0 \u2264 cantor_function_aux c f n :=\nby { cases h' : f n; simp [h'], apply pow_nonneg h }\n\nlemma cantor_function_aux_eq (h : f n = g n) :\n  cantor_function_aux c f n = cantor_function_aux c g n :=\nby simp [cantor_function_aux, h]\n\nlemma cantor_function_aux_succ (f : \u2115 \u2192 bool) :\n  (\u03bb n, cantor_function_aux c f (n + 1)) = \u03bb n, c * cantor_function_aux c (\u03bb n, f (n + 1)) n :=\nby { ext n, cases h : f (n + 1); simp [h, pow_succ] }\n\nlemma summable_cantor_function (f : \u2115 \u2192 bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n  summable (cantor_function_aux c f) :=\nbegin\n  apply (summable_geometric_of_lt_1 h1 h2).summable_of_eq_zero_or_self,\n  intro n, cases h : f n; simp [h]\nend\n\n/-- `cantor_function c (f : \u2115 \u2192 bool)` is `\u03a3 n, f n * c ^ n`, where `tt` is interpreted as `1` and\n`ff` is interpreted as `0`. It is implemented using `cantor_function_aux`. -/\ndef cantor_function (c : \u211d) (f : \u2115 \u2192 bool) : \u211d := \u2211' n, cantor_function_aux c f n\n\nlemma cantor_function_le (h1 : 0 \u2264 c) (h2 : c < 1) (h3 : \u2200 n, f n \u2192 g n) :\n  cantor_function c f \u2264 cantor_function c g :=\nbegin\n  apply tsum_le_tsum _ (summable_cantor_function f h1 h2) (summable_cantor_function g h1 h2),\n  intro n, cases h : f n, simp [h, cantor_function_aux_nonneg h1],\n  replace h3 : g n = tt := h3 n h, simp [h, h3]\nend\n\nlemma cantor_function_succ (f : \u2115 \u2192 bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n  cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (\u03bb n, f (n+1)) :=\nbegin\n  rw [cantor_function, tsum_eq_zero_add (summable_cantor_function f h1 h2)],\n  rw [cantor_function_aux_succ, tsum_mul_left, cantor_function_aux, pow_zero],\n  refl\nend\n\n/-- `cantor_function c` is strictly increasing with if `0 < c < 1/2`, if we endow `\u2115 \u2192 bool` with a\nlexicographic order. The lexicographic order doesn't exist for these infinitary products, so we\nexplicitly write out what it means. -/\nlemma increasing_cantor_function (h1 : 0 < c) (h2 : c < 1 / 2) {n : \u2115} {f g : \u2115 \u2192 bool}\n  (hn : \u2200(k < n), f k = g k) (fn : f n = ff) (gn : g n = tt) :\n  cantor_function c f < cantor_function c g :=\nbegin\n  have h3 : c < 1, { apply h2.trans, norm_num },\n  induction n with n ih generalizing f g,\n  { let f_max : \u2115 \u2192 bool := \u03bb n, nat.rec ff (\u03bb _ _, tt) n,\n    have hf_max : \u2200n, f n \u2192 f_max n,\n    { intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl },\n    let g_min : \u2115 \u2192 bool := \u03bb n, nat.rec tt (\u03bb _ _, ff) n,\n    have hg_min : \u2200n, g_min n \u2192 g n,\n    { intros n hn, cases n, rw [gn], apply rfl, contradiction },\n    apply (cantor_function_le (le_of_lt h1) h3 hf_max).trans_lt,\n    refine lt_of_lt_of_le _ (cantor_function_le (le_of_lt h1) h3 hg_min),\n    have : c / (1 - c) < 1,\n    { rw [div_lt_one, lt_sub_iff_add_lt],\n      { convert add_lt_add h2 h2, norm_num },\n      rwa sub_pos },\n    convert this,\n    { rw [cantor_function_succ _ (le_of_lt h1) h3, div_eq_mul_inv,\n          \u2190tsum_geometric_of_lt_1 (le_of_lt h1) h3],\n      apply zero_add },\n    { convert tsum_eq_single 0 _,\n      { apply_instance },\n      { intros n hn, cases n, contradiction, refl } } },\n  rw [cantor_function_succ f (le_of_lt h1) h3, cantor_function_succ g (le_of_lt h1) h3],\n  rw [hn 0 $ zero_lt_succ n],\n  apply add_lt_add_left, rw mul_lt_mul_left h1, exact ih (\u03bb k hk, hn _ $ nat.succ_lt_succ hk) fn gn\nend\n\n/-- `cantor_function c` is injective if `0 < c < 1/2`. -/\nlemma cantor_function_injective (h1 : 0 < c) (h2 : c < 1 / 2) :\n  function.injective (cantor_function c) :=\nbegin\n  intros f g hfg, classical, by_contra h, revert hfg,\n  have : \u2203n, f n \u2260 g n,\n  { rw [\u2190not_forall], intro h', apply h, ext, apply h' },\n  let n := nat.find this,\n  have hn : \u2200 (k : \u2115), k < n \u2192 f k = g k,\n  { intros k hk, apply of_not_not, exact nat.find_min this hk },\n  cases fn : f n,\n  { apply ne_of_lt, refine increasing_cantor_function h1 h2 hn fn _,\n    apply eq_tt_of_not_eq_ff, rw [\u2190fn], apply ne.symm, exact nat.find_spec this },\n  { apply ne_of_gt, refine increasing_cantor_function h1 h2 (\u03bb k hk, (hn k hk).symm) _ fn,\n    apply eq_ff_of_not_eq_tt, rw [\u2190fn], apply ne.symm, exact nat.find_spec this }\nend\n\n/-- The cardinality of the reals, as a type. -/\nlemma mk_real : #\u211d = \ud835\udd20 :=\nbegin\n  apply le_antisymm,\n  { rw real.equiv_Cauchy.cardinal_eq,\n    apply mk_quotient_le.trans, apply (mk_subtype_le _).trans_eq,\n    rw [\u2190 power_def, mk_nat, mk_rat, aleph_0_power_aleph_0] },\n  { convert mk_le_of_injective (cantor_function_injective _ _),\n    rw [\u2190power_def, mk_bool, mk_nat, two_power_aleph_0], exact 1 / 3, norm_num, norm_num }\nend\n\n/-- The cardinality of the reals, as a set. -/\nlemma mk_univ_real : #(set.univ : set \u211d) = \ud835\udd20 :=\nby rw [mk_univ, mk_real]\n\n/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/\nlemma not_countable_real : \u00ac (set.univ : set \u211d).countable :=\nby { rw [\u2190 mk_set_le_aleph_0, not_le, mk_univ_real], apply cantor }\n\n/-- The cardinality of the interval (a, \u221e). -/\nlemma mk_Ioi_real (a : \u211d) : #(Ioi a) = \ud835\udd20 :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  rw [\u2190 not_lt], intro h,\n  refine ne_of_lt _ mk_univ_real,\n  have hu : Iio a \u222a {a} \u222a Ioi a = set.univ,\n  { convert Iic_union_Ioi, exact Iio_union_right },\n  rw \u2190 hu,\n  refine lt_of_le_of_lt (mk_union_le _ _) _,\n  refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) _,\n  have h2 : (\u03bb x, a + a - x) '' Ioi a = Iio a,\n  { convert image_const_sub_Ioi _ _, simp },\n  rw \u2190 h2,\n  refine add_lt_of_lt (cantor _).le _ h,\n  refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) _,\n  rw mk_singleton,\n  exact one_lt_aleph_0.trans (cantor _)\nend\n\n/-- The cardinality of the interval [a, \u221e). -/\nlemma mk_Ici_real (a : \u211d) : #(Ici a) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioi_real a \u25b8 mk_le_mk_of_subset Ioi_subset_Ici_self)\n\n/-- The cardinality of the interval (-\u221e, a). -/\nlemma mk_Iio_real (a : \u211d) : #(Iio a) = \ud835\udd20 :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  have h2 : (\u03bb x, a + a - x) '' Iio a = Ioi a,\n  { convert image_const_sub_Iio _ _, simp },\n  exact mk_Ioi_real a \u25b8 h2 \u25b8 mk_image_le\nend\n\n/-- The cardinality of the interval (-\u221e, a]. -/\nlemma mk_Iic_real (a : \u211d) : #(Iic a) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Iio_real a \u25b8 mk_le_mk_of_subset Iio_subset_Iic_self)\n\n/-- The cardinality of the interval (a, b). -/\nlemma mk_Ioo_real {a b : \u211d} (h : a < b) : #(Ioo a b) = \ud835\udd20 :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  have h1 : #((\u03bb x, x - a) '' Ioo a b) \u2264 #(Ioo a b) := mk_image_le,\n  refine le_trans _ h1,\n  rw [image_sub_const_Ioo, sub_self],\n  replace h := sub_pos_of_lt h,\n  have h2 : #(has_inv.inv '' Ioo 0 (b - a)) \u2264 #(Ioo 0 (b - a)) := mk_image_le,\n  refine le_trans _ h2,\n  rw [image_inv, inv_Ioo_0_left h, mk_Ioi_real]\nend\n\n/-- The cardinality of the interval [a, b). -/\n\n\n/-- The cardinality of the interval [a, b]. -/\nlemma mk_Icc_real {a b : \u211d} (h : a < b) : #(Icc a b) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Icc_self)\n\n/-- The cardinality of the interval (a, b]. -/\nlemma mk_Ioc_real {a b : \u211d} (h : a < b) : #(Ioc a b) = \ud835\udd20 :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Ioc_self)\n\nend cardinal\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/real/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7208790060902462}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Johan Commelin\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.group_theory.free_abelian_group\nimport Mathlib.ring_theory.subring\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\n\n/-!\n# Free rings\n\nThe theory of the free ring over a type.\n\n## Main definitions\n\n* `free_ring \u03b1` : the free (not commutative in general) ring over a type.\n* `lift (f : \u03b1 \u2192 R)` : the ring hom `free_ring \u03b1 \u2192+* R` induced by `f`.\n* `map (f : \u03b1 \u2192 \u03b2)` : the ring hom `free_ring \u03b1 \u2192+* free_ring \u03b2` induced by `f`.\n\n## Implementation details\n\n`free_ring \u03b1` is implemented as the free abelian group over the free monoid on `\u03b1`.\n\n## Tags\n\nfree ring\n\n-/\n\n/-- The free ring over a type `\u03b1`. -/\ndef free_ring (\u03b1 : Type u) :=\n  free_abelian_group (free_monoid \u03b1)\n\nnamespace free_ring\n\n\nprotected instance ring (\u03b1 : Type u) : ring (free_ring \u03b1) :=\n  free_abelian_group.ring (free_monoid \u03b1)\n\nprotected instance inhabited (\u03b1 : Type u) : Inhabited (free_ring \u03b1) :=\n  { default := 0 }\n\n/-- The canonical map from \u03b1 to `free_ring \u03b1`. -/\ndef of {\u03b1 : Type u} (x : \u03b1) : free_ring \u03b1 :=\n  free_abelian_group.of [x]\n\ntheorem of_injective {\u03b1 : Type u} : function.injective of :=\n  function.injective.comp free_abelian_group.of_injective free_monoid.of_injective\n\nprotected theorem induction_on {\u03b1 : Type u} {C : free_ring \u03b1 \u2192 Prop} (z : free_ring \u03b1) (hn1 : C (-1)) (hb : \u2200 (b : \u03b1), C (of b)) (ha : \u2200 (x y : free_ring \u03b1), C x \u2192 C y \u2192 C (x + y)) (hm : \u2200 (x y : free_ring \u03b1), C x \u2192 C y \u2192 C (x * y)) : C z := sorry\n\n/-- The ring homomorphism `free_ring \u03b1 \u2192+* R` induced from a map `\u03b1 \u2192 R`. -/\ndef lift {\u03b1 : Type u} {R : Type v} [ring R] (f : \u03b1 \u2192 R) : free_ring \u03b1 \u2192+* R :=\n  ring_hom.mk (add_monoid_hom.to_fun (free_abelian_group.lift fun (L : List \u03b1) => list.prod (list.map f L))) sorry sorry\n    sorry sorry\n\n@[simp] theorem lift_of {\u03b1 : Type u} {R : Type v} [ring R] (f : \u03b1 \u2192 R) (x : \u03b1) : coe_fn (lift f) (of x) = f x :=\n  Eq.trans (free_abelian_group.lift.of (fun (L : List \u03b1) => list.prod (list.map f L)) [x]) (one_mul (f x))\n\n@[simp] theorem lift_comp_of {\u03b1 : Type u} {R : Type v} [ring R] (f : free_ring \u03b1 \u2192+* R) : lift (\u21d1f \u2218 of) = f := sorry\n\n/-- The canonical ring homomorphism `free_ring \u03b1 \u2192+* free_ring \u03b2` generated by a map `\u03b1 \u2192 \u03b2`. -/\ndef map {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) : free_ring \u03b1 \u2192+* free_ring \u03b2 :=\n  lift (of \u2218 f)\n\n@[simp] theorem map_of {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (x : \u03b1) : coe_fn (map f) (of x) = of (f x) :=\n  lift_of (of \u2218 f) x\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/ring_theory/free_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929799, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7208790056404739}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport number_theory.arithmetic_function\nimport number_theory.lucas_lehmer\nimport algebra.geom_sum\nimport ring_theory.multiplicity\n\n/-!\n# Perfect Numbers\n\nThis file proves Theorem 70 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).\n\nThe theorem characterizes even perfect numbers.\n\nEuclid proved that if `2 ^ (k + 1) - 1` is prime (these primes are known as Mersenne primes),\n  then `2 ^ k * 2 ^ (k + 1) - 1` is perfect.\n\nEuler proved the converse, that if `n` is even and perfect, then there exists `k` such that\n  `n = 2 ^ k * 2 ^ (k + 1) - 1` and `2 ^ (k + 1) - 1` is prime.\n\n## References\nhttps://en.wikipedia.org/wiki/Euclid%E2%80%93Euler_theorem\n-/\n\nlemma odd_mersenne_succ (k : \u2115) : \u00ac 2 \u2223 mersenne (k + 1) :=\nby simp [\u2190 even_iff_two_dvd, \u2190 nat.even_add_one] with parity_simps\n\nnamespace nat\nopen arithmetic_function finset\nopen_locale arithmetic_function\n\nlemma sigma_two_pow_eq_mersenne_succ (k : \u2115) : \u03c3 1 (2 ^ k) = mersenne (k + 1) :=\nby simp [sigma_one_apply, mersenne, prime_two, \u2190 geom_sum_mul_add 1 (k+1)]\n\n/-- Euclid's theorem that Mersenne primes induce perfect numbers -/\ntheorem perfect_two_pow_mul_mersenne_of_prime (k : \u2115) (pr : (mersenne (k + 1)).prime) :\n  perfect ((2 ^ k) * mersenne (k + 1)) :=\nbegin\n  rw [perfect_iff_sum_divisors_eq_two_mul, \u2190 mul_assoc, \u2190 pow_succ, \u2190 sigma_one_apply, mul_comm,\n    is_multiplicative_sigma.map_mul_of_coprime\n        (nat.prime_two.coprime_pow_of_not_dvd (odd_mersenne_succ _)),\n    sigma_two_pow_eq_mersenne_succ],\n  { simp [pr, nat.prime_two, sigma_one_apply] },\n  { apply mul_pos (pow_pos _ k) (mersenne_pos (nat.succ_pos k)),\n    norm_num }\nend\n\nlemma ne_zero_of_prime_mersenne (k : \u2115) (pr : (mersenne (k + 1)).prime) :\n  k \u2260 0 :=\nbegin\n  intro H,\n  simpa [H, mersenne, not_prime_one] using pr,\nend\n\ntheorem even_two_pow_mul_mersenne_of_prime (k : \u2115) (pr : (mersenne (k + 1)).prime) :\n  even ((2 ^ k) * mersenne (k + 1)) :=\nby simp [ne_zero_of_prime_mersenne k pr] with parity_simps\n\nlemma eq_two_pow_mul_odd {n : \u2115} (hpos : 0 < n) :\n  \u2203 (k m : \u2115), n = 2 ^ k * m \u2227 \u00ac even m :=\nbegin\n  have h := (multiplicity.finite_nat_iff.2 \u27e8nat.prime_two.ne_one, hpos\u27e9),\n  cases multiplicity.pow_multiplicity_dvd h with m hm,\n  use [(multiplicity 2 n).get h, m],\n  refine \u27e8hm, _\u27e9,\n  rw even_iff_two_dvd,\n  have hg := multiplicity.is_greatest' h (nat.lt_succ_self _),\n  contrapose! hg,\n  rcases hg with \u27e8k, rfl\u27e9,\n  apply dvd.intro k,\n  rw [pow_succ', mul_assoc, \u2190 hm],\nend\n\n/-- **Perfect Number Theorem**: Euler's theorem that even perfect numbers can be factored as a\n  power of two times a Mersenne prime. -/\ntheorem eq_two_pow_mul_prime_mersenne_of_even_perfect {n : \u2115} (ev : even n) (perf : perfect n) :\n  \u2203 (k : \u2115), prime (mersenne (k + 1)) \u2227 n = 2 ^ k * mersenne (k + 1) :=\nbegin\n  have hpos := perf.2,\n  rcases eq_two_pow_mul_odd hpos with \u27e8k, m, rfl, hm\u27e9,\n  use k,\n  rw even_iff_two_dvd at hm,\n  rw [perfect_iff_sum_divisors_eq_two_mul hpos, \u2190 sigma_one_apply,\n    is_multiplicative_sigma.map_mul_of_coprime (nat.prime_two.coprime_pow_of_not_dvd hm).symm,\n    sigma_two_pow_eq_mersenne_succ, \u2190 mul_assoc, \u2190 pow_succ] at perf,\n  rcases nat.coprime.dvd_of_dvd_mul_left\n    (nat.prime_two.coprime_pow_of_not_dvd (odd_mersenne_succ _)) (dvd.intro _ perf) with \u27e8j, rfl\u27e9,\n  rw [\u2190 mul_assoc, mul_comm _ (mersenne _), mul_assoc] at perf,\n  have h := mul_left_cancel\u2080 (ne_of_gt (mersenne_pos (nat.succ_pos _))) perf,\n  rw [sigma_one_apply, sum_divisors_eq_sum_proper_divisors_add_self, \u2190 succ_mersenne, add_mul,\n    one_mul, add_comm] at h,\n  have hj := add_left_cancel h,\n  cases sum_proper_divisors_dvd (by { rw hj, apply dvd.intro_left (mersenne (k + 1)) rfl }),\n  { have j1 : j = 1 := eq.trans hj.symm h_1,\n    rw [j1, mul_one, sum_proper_divisors_eq_one_iff_prime] at h_1,\n    simp [h_1, j1] },\n  { have jcon := eq.trans hj.symm h_1,\n    rw [\u2190 one_mul j, \u2190 mul_assoc, mul_one] at jcon,\n    have jcon2 := mul_right_cancel\u2080 _ jcon,\n    { exfalso,\n      cases k,\n      { apply hm,\n        rw [\u2190 jcon2, pow_zero, one_mul, one_mul] at ev,\n        rw [\u2190 jcon2, one_mul],\n        exact even_iff_two_dvd.mp ev },\n      apply ne_of_lt _ jcon2,\n      rw [mersenne, \u2190 nat.pred_eq_sub_one, lt_pred_iff, \u2190 pow_one (nat.succ 1)],\n      apply pow_lt_pow (nat.lt_succ_self 1) (nat.succ_lt_succ (nat.succ_pos k)) },\n    contrapose! hm,\n    simp [hm] }\nend\n\n/-- The Euclid-Euler theorem characterizing even perfect numbers -/\ntheorem even_and_perfect_iff {n : \u2115} :\n  (even n \u2227 perfect n) \u2194 \u2203 (k : \u2115), prime (mersenne (k + 1)) \u2227 n = 2 ^ k * mersenne (k + 1) :=\nbegin\n  split,\n  { rintro \u27e8ev, perf\u27e9,\n    exact eq_two_pow_mul_prime_mersenne_of_even_perfect ev perf },\n  { rintro \u27e8k, pr, rfl\u27e9,\n    exact \u27e8even_two_pow_mul_mersenne_of_prime k pr, perfect_two_pow_mul_mersenne_of_prime k pr\u27e9 }\nend\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/100-theorems-list/70_perfect_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7208712030344742}}
{"text": "import tactic.basic\nimport algebra.order.monoid\nimport order.succ_pred.basic\nopen function\n\nuniverse u\nvariable {\u03b1 : Type u}\n\nnamespace with_top\nvariables {a b c d : with_top \u03b1}\n\n-- Generalisations that are possible.\n\nlemma not_top_le_coe' [has_le \u03b1] (a : \u03b1) : \u00ac (\u22a4 : with_top \u03b1) \u2264 \u2191a :=\nby simp [has_le.le, some_eq_coe]\n\nlemma ne_top_of_lt' [has_lt \u03b1] (h : a < b) : a \u2260 \u22a4 :=\nby { rintro rfl, simpa [has_lt.lt, some_eq_coe] using h }\n\nlemma lt_top_of_ne_top [has_lt \u03b1] (h : a \u2260 \u22a4) : a < \u22a4 :=\nby { cases a, exact (h rfl).elim, exact some_lt_none _ }\n\nlemma lt_top_iff_ne_top' [has_lt \u03b1] : a < \u22a4 \u2194 a \u2260 \u22a4 := \u27e8\u03bb H, ne_top_of_lt' H, lt_top_of_ne_top\u27e9\n\n-- add_lt_add lemmas. Many, MANY options.\n\ntheorem add_lt_add_of_lt_of_lt_of_ne_left_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hb : b \u2260 \u22a4) (hab : a < b) (hcd : c < d) : a + c < b + d :=\ncalc  a + c < b + c : with_top.add_lt_add_right (ne_top_of_lt hcd) hab\n      ...   < b + d : with_top.add_lt_add_left hb hcd\n\ntheorem add_lt_add_of_lt_of_lt_of_ne_right_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hd : d \u2260 \u22a4) (hab : a < b) (hcd : c < d) : a + c < b + d :=\ncalc  a + c < a + d : with_top.add_lt_add_left (ne_top_of_lt hab) hcd\n      ...   < b + d : with_top.add_lt_add_right hd hab\n\ntheorem add_lt_add_of_lt_of_lt_of_cov_lt_cov_swap_lt [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hab : a < b) (hcd : c < d) : a + c < b + d :=\nbegin\n  cases b,\n  { cases d,\n    { rw [none_eq_top, add_top, \u2190 @top_add _ _ c],\n      exact with_top.add_lt_add_right (ne_top_of_lt' hcd) hab },\n    { exact add_lt_add_of_lt_of_lt_of_ne_right_top (coe_ne_top) hab hcd }\n  },  exact add_lt_add_of_lt_of_lt_of_ne_left_top (coe_ne_top) hab hcd\nend\n\ntheorem add_lt_add_of_lt_of_lt_cov_lt [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n(hab : a < b) (hcd : c < d) : a + c < b + d :=\ncalc  a + c < a + d : with_top.add_lt_add_left (ne_top_of_lt hab) hcd\n      ...   \u2264 b + d : add_le_add_right hab.le _\n\ntheorem add_lt_add_of_lt_of_lt_cov_swap_lt [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hab : a < b) (hcd : c < d) : a + c < b + d :=\ncalc  a + c < b + c : with_top.add_lt_add_right (ne_top_of_lt hcd) hab\n      ...   \u2264 b + d : add_le_add_left hcd.le b\n\ntheorem add_lt_add_of_le_of_lt_of_left_ne_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n(ha : a \u2260 \u22a4) (hab : a \u2264 b) (hcd : c < d) : a + c < b + d :=\ncalc  a + c < a + d : with_top.add_lt_add_left ha hcd\n      ...   \u2264 b + d : add_le_add_right hab _\n\ntheorem add_lt_add_of_le_of_lt_of_right_ne_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n(hb : b \u2260 \u22a4) (hab : a \u2264 b) (hcd : c < d) : a + c < b + d :=\ncalc  a + c \u2264 b + c : add_le_add_right hab _\n      ...   < b + d : with_top.add_lt_add_left hb hcd\n\ntheorem add_lt_add_of_lt_of_le_of_left_ne_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hc : c \u2260 \u22a4) (hab : a < b) (hcd : c \u2264 d) : a + c < b + d :=\ncalc  a + c < b + c : with_top.add_lt_add_right hc hab\n      ...   \u2264 b + d : add_le_add_left hcd _\n\ntheorem add_lt_add_of_lt_of_le_of_right_ne_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hd : d \u2260 \u22a4) (hab : a < b) (hcd : c \u2264 d) : a + c < b + d :=\ncalc  a + c \u2264 a + d : add_le_add_left hcd _\n      ...   < b + d : with_top.add_lt_add_right hd hab\n\nend with_top\n\nnamespace with_bot\nvariables {a b c d : with_bot \u03b1}\n\nlemma not_coe'_le_bot [has_le \u03b1] (a : \u03b1) : \u00ac \u2191a \u2264 (\u22a5 : with_bot \u03b1) :=\n@with_top.not_top_le_coe' (order_dual \u03b1) _ _\n\nlemma ne_bot_of_gt' [has_lt \u03b1] (h : a < b) : b \u2260 \u22a5 :=\n@with_top.ne_top_of_lt' (order_dual \u03b1) _ _ _ h\n\nlemma lt_top_of_ne_top [has_lt \u03b1] (h : a \u2260 \u22a5) : \u22a5 < a :=\n@with_top.lt_top_of_ne_top (order_dual \u03b1) _ _ h\n\nlemma lt_top_iff_ne_top' [has_lt \u03b1] : \u22a5 < a \u2194 a \u2260 \u22a5 := \n@with_top.lt_top_iff_ne_top' (order_dual \u03b1) _ _\n\n-- add_lt_add lemmas. Many, MANY options.\n\ntheorem add_lt_add_of_lt_of_lt_of_ne_left_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(ha : a \u2260 \u22a5) (hab : a < b) (hcd : c < d) : a + c < b + d :=\n@with_top.add_lt_add_of_lt_of_lt_of_ne_left_top (order_dual \u03b1) _ _ _ _ _ _ _ _ ha hab hcd\n\ntheorem add_lt_add_of_lt_of_lt_of_ne_right_top [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hc : c \u2260 \u22a5) (hab : a < b) (hcd : c < d) : a + c < b + d :=\n@with_top.add_lt_add_of_lt_of_lt_of_ne_right_top (order_dual \u03b1) _ _ _ _ _ _ _ _ hc hab hcd\n\ntheorem add_lt_add_of_lt_of_lt_of_cov_lt_cov_swap_lt [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hab : a < b) (hcd : c < d) : a + c < b + d :=\n@with_top.add_lt_add_of_lt_of_lt_of_cov_lt_cov_swap_lt (order_dual \u03b1) _ _ _ _ _ _ _ _ hab hcd\n\ntheorem add_lt_add_of_lt_of_lt_cov_lt [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n(hab : a < b) (hcd : c < d) : a + c < b + d :=\n@with_top.add_lt_add_of_lt_of_lt_cov_lt (order_dual \u03b1) _ _ _ _ _ _ _ _ hab hcd\n\ntheorem add_lt_add_of_lt_of_lt_cov_swap_lt [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hab : a < b) (hcd : c < d) : a + c < b + d :=\n@with_top.add_lt_add_of_lt_of_lt_cov_swap_lt (order_dual \u03b1) _ _ _ _ _ _ _ _ hab hcd\n\ntheorem add_lt_add_of_le_of_lt_of_left_ne_bot [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n(ha : a \u2260 \u22a5) (hab : a \u2264 b) (hcd : c < d) : a + c < b + d :=\n@with_top.add_lt_add_of_le_of_lt_of_right_ne_top (order_dual \u03b1) _ _ _ _ _ _ _ _ ha hab hcd\n\ntheorem add_lt_add_of_le_of_lt_of_right_ne_bot [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n(hb : b \u2260 \u22a5) (hab : a \u2264 b) (hcd : c < d) : a + c < b + d :=\n@with_top.add_lt_add_of_le_of_lt_of_left_ne_top (order_dual \u03b1) _ _ _ _ _ _ _ _ hb hab hcd\n\ntheorem add_lt_add_of_lt_of_le_of_left_ne_bot [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hc : c \u2260 \u22a5) (hab : a < b) (hcd : c \u2264 d) : a + c < b + d :=\n@with_top.add_lt_add_of_lt_of_le_of_right_ne_top (order_dual \u03b1) _ _ _ _ _ _ _ _ hc hab hcd\n\ntheorem add_lt_add_of_lt_of_le_of_right_ne_bot [has_add \u03b1] [preorder \u03b1]\n[covariant_class \u03b1 \u03b1 (+) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)]\n(hd : d \u2260 \u22a5) (hab : a < b) (hcd : c \u2264 d) : a + c < b + d :=\n@with_top.add_lt_add_of_lt_of_le_of_left_ne_top (order_dual \u03b1) _ _ _ _ _ _ _ _ hd hab hcd\n\nend with_bot", "meta": {"author": "linesthatinterlace", "repo": "goppadecoding", "sha": "294f31a0dd56ad9497f3a9585190cdd54f064d7f", "save_path": "github-repos/lean/linesthatinterlace-goppadecoding", "path": "github-repos/lean/linesthatinterlace-goppadecoding/goppadecoding-294f31a0dd56ad9497f3a9585190cdd54f064d7f/src/to_mathlib/with_bot_top.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.720871187557223}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n\n! This file was ported from Lean 3 source module data.polynomial.hasse_deriv\n! leanprover-community/mathlib commit a148d797a1094ab554ad4183a4ad6f130358ef64\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Polynomial.BigOperators\nimport Mathlib.Data.Nat.Choose.Cast\nimport Mathlib.Data.Nat.Choose.Vandermonde\nimport Mathlib.Data.Polynomial.Derivative\nimport Mathlib.Tactic.FieldSimp\n\n/-!\n# Hasse derivative of polynomials\n\nThe `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt is a variant of the usual derivative, and satisfies `k! * (hasseDeriv k f) = derivative^[k] f`.\nThe main benefit is that is gives an atomic way of talking about expressions such as\n`(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example.\n\n## Main declarations\n\nIn the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`.\n\n* `Polynomial.hasseDeriv`: the `k`-th Hasse derivative of a polynomial\n* `Polynomial.hasseDeriv_zero`: the `0`th Hasse derivative is the identity\n* `Polynomial.hasseDeriv_one`: the `1`st Hasse derivative is the usual derivative\n* `Polynomial.factorial_smul_hasseDeriv`: the identity `k! \u2022 (D k f) = derivative^[k] f`\n* `Polynomial.hasseDeriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k \u2022 D (k+l)`\n* `Polynomial.hasseDeriv_mul`:\n  the \"Leibniz rule\" `D k (f * g) = \u2211 ij in antidiagonal k, D ij.1 f * D ij.2 g`\n\nFor the identity principle, see `Polynomial.eq_zero_of_hasseDeriv_eq_zero`\nin `Data/Polynomial/Taylor.lean`.\n\n## Reference\n\nhttps://math.fontein.de/2009/08/12/the-hasse-derivative/\n\n-/\n\n\nnoncomputable section\n\nnamespace Polynomial\n\nopen Nat BigOperators Polynomial\n\nopen Function\n\nopen Nat hiding nsmul_eq_mul\n\nvariable {R : Type _} [Semiring R] (k : \u2115) (f : R[X])\n\n/-- The `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/\ndef hasseDeriv (k : \u2115) : R[X] \u2192\u2097[R] R[X] :=\n  lsum fun i => monomial (i - k) \u2218\u2097 DistribMulAction.toLinearMap R R (i.choose k)\n#align polynomial.hasse_deriv Polynomial.hasseDeriv\n\ntheorem hasseDeriv_apply :\n    hasseDeriv k f = f.sum fun i r => monomial (i - k) (\u2191(i.choose k) * r) := by\n  dsimp [hasseDeriv]\n  congr; ext; congr\n  apply nsmul_eq_mul\n#align polynomial.hasse_deriv_apply Polynomial.hasseDeriv_apply\n\ntheorem hasseDeriv_coeff (n : \u2115) : (hasseDeriv k f).coeff n = (n + k).choose k * f.coeff (n + k) :=\n  by\n  rw [hasseDeriv_apply, coeff_sum, sum_def, Finset.sum_eq_single (n + k), coeff_monomial]\n  \u00b7 simp only [if_true, add_tsub_cancel_right, eq_self_iff_true]\n  \u00b7 intro i _hi hink\n    rw [coeff_monomial]\n    by_cases hik : i < k\n    \u00b7 simp only [Nat.choose_eq_zero_of_lt hik, ite_self, Nat.cast_zero, MulZeroClass.zero_mul]\n    \u00b7 push_neg at hik\n      rw [if_neg]\n      contrapose! hink\n      exact (tsub_eq_iff_eq_add_of_le hik).mp hink\n  \u00b7 intro h\n    simp only [not_mem_support_iff.mp h, monomial_zero_right, MulZeroClass.mul_zero, coeff_zero]\n#align polynomial.hasse_deriv_coeff Polynomial.hasseDeriv_coeff\n\ntheorem hasseDeriv_zero' : hasseDeriv 0 f = f := by\n  simp only [hasseDeriv_apply, tsub_zero, Nat.choose_zero_right, Nat.cast_one, one_mul,\n    sum_monomial_eq]\n#align polynomial.hasse_deriv_zero' Polynomial.hasseDeriv_zero'\n\n@[simp]\ntheorem hasseDeriv_zero : @hasseDeriv R _ 0 = LinearMap.id :=\n  LinearMap.ext <| hasseDeriv_zero'\n#align polynomial.hasse_deriv_zero Polynomial.hasseDeriv_zero\n\ntheorem hasseDeriv_eq_zero_of_lt_natDegree (p : R[X]) (n : \u2115) (h : p.natDegree < n) :\n    hasseDeriv n p = 0 := by\n  rw [hasseDeriv_apply, sum_def]\n  refine' Finset.sum_eq_zero fun x hx => _\n  simp [Nat.choose_eq_zero_of_lt ((le_natDegree_of_mem_supp _ hx).trans_lt h)]\n#align polynomial.hasse_deriv_eq_zero_of_lt_nat_degree Polynomial.hasseDeriv_eq_zero_of_lt_natDegree\n\ntheorem hasseDeriv_one' : hasseDeriv 1 f = derivative f := by\n  simp only [hasseDeriv_apply, derivative_apply, \u2190 C_mul_X_pow_eq_monomial, Nat.choose_one_right,\n    (Nat.cast_commute _ _).eq]\n#align polynomial.hasse_deriv_one' Polynomial.hasseDeriv_one'\n\n@[simp]\ntheorem hasseDeriv_one : @hasseDeriv R _ 1 = derivative :=\n  LinearMap.ext <| hasseDeriv_one'\n#align polynomial.hasse_deriv_one Polynomial.hasseDeriv_one\n\n@[simp]\ntheorem hasseDeriv_monomial (n : \u2115) (r : R) :\n    hasseDeriv k (monomial n r) = monomial (n - k) (\u2191(n.choose k) * r) := by\n  ext i\n  simp only [hasseDeriv_coeff, coeff_monomial]\n  by_cases hnik : n = i + k\n  \u00b7 rw [if_pos hnik, if_pos, \u2190 hnik]\n    apply tsub_eq_of_eq_add_rev\n    rwa [add_comm]\n  \u00b7 rw [if_neg hnik, MulZeroClass.mul_zero]\n    by_cases hkn : k \u2264 n\n    \u00b7 rw [\u2190 tsub_eq_iff_eq_add_of_le hkn] at hnik\n      rw [if_neg hnik]\n    \u00b7 push_neg  at hkn\n      rw [Nat.choose_eq_zero_of_lt hkn, Nat.cast_zero, MulZeroClass.zero_mul, ite_self]\n#align polynomial.hasse_deriv_monomial Polynomial.hasseDeriv_monomial\n\n\n\ntheorem hasseDeriv_apply_one (hk : 0 < k) : hasseDeriv k (1 : R[X]) = 0 := by\n  rw [\u2190 C_1, hasseDeriv_C k _ hk]\n#align polynomial.hasse_deriv_apply_one Polynomial.hasseDeriv_apply_one\n\ntheorem hasseDeriv_X (hk : 1 < k) : hasseDeriv k (X : R[X]) = 0 := by\n  rw [\u2190 monomial_one_one_eq_X, hasseDeriv_monomial, Nat.choose_eq_zero_of_lt hk, Nat.cast_zero,\n    MulZeroClass.zero_mul, monomial_zero_right]\nset_option linter.uppercaseLean3 false in\n#align polynomial.hasse_deriv_X Polynomial.hasseDeriv_X\n\ntheorem factorial_smul_hasseDeriv : \u21d1(k ! \u2022 @hasseDeriv R _ k) = @derivative R _^[k] := by\n  induction' k with k ih\n  \u00b7 rw [hasseDeriv_zero, factorial_zero, iterate_zero, one_smul, LinearMap.id_coe]\n  ext (f n) : 2\n  rw [iterate_succ_apply', \u2190 ih]\n  simp only [LinearMap.smul_apply, coeff_smul, LinearMap.map_smul_of_tower, coeff_derivative,\n    hasseDeriv_coeff, \u2190 @choose_symm_add _ k]\n  simp only [nsmul_eq_mul, factorial_succ, mul_assoc, succ_eq_add_one, \u2190 add_assoc,\n    add_right_comm n 1 k, \u2190 cast_succ]\n  rw [\u2190 (cast_commute (n + 1) (f.coeff (n + k + 1))).eq]\n  simp only [\u2190 mul_assoc]\n  norm_cast\n  congr 2\n  rw [mul_comm (k+1) _, mul_assoc, mul_assoc]\n  congr 1\n  have : n + k + 1 = n + (k + 1) := by apply add_assoc\n  rw [\u2190choose_symm_of_eq_add this, choose_succ_right_eq, mul_comm]\n  congr\n  rw [add_assoc, add_tsub_cancel_left]\n#align polynomial.factorial_smul_hasse_deriv Polynomial.factorial_smul_hasseDeriv\n\ntheorem hasseDeriv_comp (k l : \u2115) :\n    (@hasseDeriv R _ k).comp (hasseDeriv l) = (k + l).choose k \u2022 hasseDeriv (k + l) := by\n  ext i : 2\n  simp only [LinearMap.smul_apply, comp_apply, LinearMap.coe_comp, smul_monomial, hasseDeriv_apply,\n    mul_one, monomial_eq_zero_iff, sum_monomial_index, mul_zero, \u2190\n    tsub_add_eq_tsub_tsub, add_comm l k]\n  rw_mod_cast [nsmul_eq_mul]\n  rw [\u2190Nat.cast_mul]\n  congr 2\n  by_cases hikl : i < k + l\n  \u00b7 rw [choose_eq_zero_of_lt hikl, mul_zero]\n    by_cases hil : i < l\n    \u00b7 rw [choose_eq_zero_of_lt hil, mul_zero]\n    \u00b7 push_neg at hil\n      rw [\u2190 tsub_lt_iff_right hil] at hikl\n      rw [choose_eq_zero_of_lt hikl, zero_mul]\n  push_neg at hikl\n  apply @cast_injective \u211a\n  have h1 : l \u2264 i := le_of_add_le_right hikl\n  have h2 : k \u2264 i - l := le_tsub_of_add_le_right hikl\n  have h3 : k \u2264 k + l := le_self_add\n  push_cast\n  rw [cast_choose \u211a h1, cast_choose \u211a h2, cast_choose \u211a h3, cast_choose \u211a hikl]\n  rw [show i - (k + l) = i - l - k by rw [add_comm]; apply tsub_add_eq_tsub_tsub]\n  simp only [add_tsub_cancel_left]\n  have H : \u2200 n : \u2115, (n ! : \u211a) \u2260 0 := by exact_mod_cast factorial_ne_zero\n  field_simp [H]\n  ring\n#align polynomial.hasse_deriv_comp Polynomial.hasseDeriv_comp\n\ntheorem natDegree_hasseDeriv_le (p : R[X]) (n : \u2115) : natDegree (hasseDeriv n p) \u2264 natDegree p - n :=\n  by\n  classical\n    rw [hasseDeriv_apply, sum_def]\n    refine' (natDegree_sum_le _ _).trans _\n    simp_rw [Function.comp, natDegree_monomial]\n    rw [Finset.fold_ite, Finset.fold_const]\n    \u00b7 simp only [ite_self, max_eq_right, zero_le', Finset.fold_max_le, true_and_iff, and_imp,\n        tsub_le_iff_right, mem_support_iff, Ne.def, Finset.mem_filter]\n      intro x hx hx'\n      have hxp : x \u2264 p.natDegree := le_natDegree_of_ne_zero hx\n      have hxn : n \u2264 x := by\n        contrapose! hx'\n        simp [Nat.choose_eq_zero_of_lt hx']\n      rwa [tsub_add_cancel_of_le (hxn.trans hxp)]\n    \u00b7 simp\n#align polynomial.nat_degree_hasse_deriv_le Polynomial.natDegree_hasseDeriv_le\n\ntheorem natDegree_hasseDeriv [NoZeroSMulDivisors \u2115 R] (p : R[X]) (n : \u2115) :\n    natDegree (hasseDeriv n p) = natDegree p - n := by\n  cases' lt_or_le p.natDegree n with hn hn\n  \u00b7 simpa [hasseDeriv_eq_zero_of_lt_natDegree, hn] using (tsub_eq_zero_of_le hn.le).symm\n  \u00b7 refine' map_natDegree_eq_sub _ _\n    \u00b7 exact fun h => hasseDeriv_eq_zero_of_lt_natDegree _ _\n    \u00b7 classical\n        simp only [ite_eq_right_iff, Ne.def, natDegree_monomial, hasseDeriv_monomial]\n        intro k c c0 hh\n        -- this is where we use the `smul_eq_zero` from `NoZeroSMulDivisors`\n        rw [\u2190 nsmul_eq_mul, smul_eq_zero, Nat.choose_eq_zero_iff] at hh\n        exact (tsub_eq_zero_of_le (Or.resolve_right hh c0).le).symm\n#align polynomial.nat_degree_hasse_deriv Polynomial.natDegree_hasseDeriv\n\nsection\n\nopen AddMonoidHom Finset.Nat\n\ntheorem hasseDeriv_mul (f g : R[X]) :\n    hasseDeriv k (f * g) = \u2211 ij in antidiagonal k, hasseDeriv ij.1 f * hasseDeriv ij.2 g := by\n  let D k := (@hasseDeriv R _ k).toAddMonoidHom\n  let \u03a6 := @AddMonoidHom.mul R[X] _\n  show\n    (compHom (D k)).comp \u03a6 f g =\n      \u2211 ij : \u2115 \u00d7 \u2115 in antidiagonal k, ((compHom.comp ((compHom \u03a6) (D ij.1))).flip (D ij.2) f) g\n  simp only [\u2190 finset_sum_apply]\n  congr 2\n  clear f g\n  ext (m r n s) : 4\n  simp only [finset_sum_apply, coe_mul_left, coe_comp, flip_apply, Function.comp_apply,\n             hasseDeriv_monomial, LinearMap.toAddMonoidHom_coe, compHom_apply_apply,\n             coe_mul, monomial_mul_monomial]\n  have aux :\n    \u2200 x : \u2115 \u00d7 \u2115,\n      x \u2208 antidiagonal k \u2192\n        monomial (m - x.1 + (n - x.2)) (\u2191(m.choose x.1) * r * (\u2191(n.choose x.2) * s)) =\n          monomial (m + n - k) (\u2191(m.choose x.1) * \u2191(n.choose x.2) * (r * s)) :=\n    by\n    intro x hx\n    rw [Finset.Nat.mem_antidiagonal] at hx\n    subst hx\n    by_cases hm : m < x.1\n    \u00b7 simp only [Nat.choose_eq_zero_of_lt hm, Nat.cast_zero, MulZeroClass.zero_mul,\n                 monomial_zero_right]\n    by_cases hn : n < x.2\n    \u00b7 simp only [Nat.choose_eq_zero_of_lt hn, Nat.cast_zero, MulZeroClass.zero_mul,\n                 MulZeroClass.mul_zero, monomial_zero_right]\n    push_neg at hm hn\n    rw [tsub_add_eq_add_tsub hm, \u2190 add_tsub_assoc_of_le hn, \u2190 tsub_add_eq_tsub_tsub,\n      add_comm x.2 x.1, mul_assoc, \u2190 mul_assoc r, \u2190 (Nat.cast_commute _ r).eq, mul_assoc, mul_assoc]\n  rw [Finset.sum_congr rfl aux]\n  rw [\u2190 LinearMap.map_sum, \u2190 Finset.sum_mul]\n  congr\n  rw_mod_cast [\u2190Nat.add_choose_eq]\n#align polynomial.hasse_deriv_mul Polynomial.hasseDeriv_mul\n\nend\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/HasseDeriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7208581369678727}}
{"text": "/-\nCopyright (c) 2021 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n-/\nimport linear_algebra.affine_space.basis\nimport linear_algebra.determinant\n\n/-!\n# Matrix results for barycentric co-ordinates\n\nResults about the matrix of barycentric co-ordinates for a family of points in an affine space, with\nrespect to some affine basis.\n-/\n\nopen_locale affine big_operators matrix\nopen set\n\nuniverses u\u2081 u\u2082 u\u2083 u\u2084\n\nvariables {\u03b9 : Type u\u2081} {k : Type u\u2082} {V : Type u\u2083} {P : Type u\u2084}\nvariables [add_comm_group V] [affine_space V P]\n\nnamespace affine_basis\n\nsection ring\n\nvariables [ring k] [module k V] (b : affine_basis \u03b9 k P)\n\n/-- Given an affine basis `p`, and a family of points `q : \u03b9' \u2192 P`, this is the matrix whose\nrows are the barycentric coordinates of `q` with respect to `p`.\n\nIt is an affine equivalent of `basis.to_matrix`. -/\nnoncomputable def to_matrix {\u03b9' : Type*} (q : \u03b9' \u2192 P) : matrix \u03b9' \u03b9 k :=\n\u03bb i j, b.coord j (q i)\n\n@[simp] lemma to_matrix_apply {\u03b9' : Type*} (q : \u03b9' \u2192 P) (i : \u03b9') (j : \u03b9) :\n  b.to_matrix q i j = b.coord j (q i) :=\nrfl\n\n@[simp] \n\nvariables {\u03b9' : Type*} [fintype \u03b9'] [fintype \u03b9] (b\u2082 : affine_basis \u03b9 k P)\n\nlemma to_matrix_row_sum_one {\u03b9' : Type*} (q : \u03b9' \u2192 P) (i : \u03b9') :\n  \u2211 j, b.to_matrix q i j = 1 :=\nby simp\n\n/-- Given a family of points `p : \u03b9' \u2192 P` and an affine basis `b`, if the matrix whose rows are the\ncoordinates of `p` with respect `b` has a right inverse, then `p` is affine independent. -/\nlemma affine_independent_of_to_matrix_right_inv [decidable_eq \u03b9']\n  (p : \u03b9' \u2192 P) {A : matrix \u03b9 \u03b9' k} (hA : (b.to_matrix p) \u2b1d A = 1) : affine_independent k p :=\nbegin\n  rw affine_independent_iff_eq_of_fintype_affine_combination_eq,\n  intros w\u2081 w\u2082 hw\u2081 hw\u2082 hweq,\n  have hweq' : (b.to_matrix p).vec_mul w\u2081 = (b.to_matrix p).vec_mul w\u2082,\n  { ext j,\n    change \u2211 i, (w\u2081 i) \u2022 (b.coord j (p i)) = \u2211 i, (w\u2082 i) \u2022 (b.coord j (p i)),\n    rw [\u2190 finset.univ.affine_combination_eq_linear_combination _ _ hw\u2081,\n        \u2190 finset.univ.affine_combination_eq_linear_combination _ _ hw\u2082,\n        \u2190 finset.univ.map_affine_combination p w\u2081 hw\u2081,\n        \u2190 finset.univ.map_affine_combination p w\u2082 hw\u2082, hweq], },\n  replace hweq' := congr_arg (\u03bb w, A.vec_mul w) hweq',\n  simpa only [matrix.vec_mul_vec_mul, \u2190 matrix.mul_eq_mul, hA, matrix.vec_mul_one] using hweq',\nend\n\n/-- Given a family of points `p : \u03b9' \u2192 P` and an affine basis `b`, if the matrix whose rows are the\ncoordinates of `p` with respect `b` has a left inverse, then `p` spans the entire space. -/\nlemma affine_span_eq_top_of_to_matrix_left_inv [decidable_eq \u03b9] [nontrivial k]\n  (p : \u03b9' \u2192 P) {A : matrix \u03b9 \u03b9' k} (hA : A \u2b1d b.to_matrix p = 1) : affine_span k (range p) = \u22a4 :=\nbegin\n  suffices : \u2200 i, b i \u2208 affine_span k (range p),\n  { rw [eq_top_iff, \u2190 b.tot, affine_span_le],\n    rintros q \u27e8i, rfl\u27e9,\n    exact this i, },\n  intros i,\n  have hAi : \u2211 j, A i j = 1,\n  { calc \u2211 j, A i j = \u2211 j, (A i j) * \u2211 l, b.to_matrix p j l : by simp\n                ... = \u2211 j, \u2211 l, (A i j) * b.to_matrix p j l : by simp_rw finset.mul_sum\n                ... = \u2211 l, \u2211 j, (A i j) * b.to_matrix p j l : by rw finset.sum_comm\n                ... = \u2211 l, (A \u2b1d b.to_matrix p) i l : rfl\n                ... = 1 : by simp [hA, matrix.one_apply, finset.filter_eq], },\n  have hbi : b i = finset.univ.affine_combination k p (A i),\n  { apply b.ext_elem,\n    intros j,\n    rw [b.coord_apply, finset.univ.map_affine_combination _ _ hAi,\n      finset.univ.affine_combination_eq_linear_combination _ _ hAi],\n    change _ = (A \u2b1d b.to_matrix p) i j,\n    simp_rw [hA, matrix.one_apply, @eq_comm _ i j] },\n  rw hbi,\n  exact affine_combination_mem_affine_span hAi p,\nend\n\n/-- A change of basis formula for barycentric coordinates.\n\nSee also `affine_basis.to_matrix_inv_mul_affine_basis_to_matrix`. -/\n@[simp] lemma to_matrix_vec_mul_coords (x : P) :\n  (b.to_matrix b\u2082).vec_mul (b\u2082.coords x) = b.coords x :=\nbegin\n  ext j,\n  change _ = b.coord j x,\n  conv_rhs { rw \u2190 b\u2082.affine_combination_coord_eq_self x, },\n  rw finset.map_affine_combination _ _ _ (b\u2082.sum_coord_apply_eq_one x),\n  simp [matrix.vec_mul, matrix.dot_product, to_matrix_apply, coords],\nend\n\nvariables [decidable_eq \u03b9]\n\nlemma to_matrix_mul_to_matrix :\n  (b.to_matrix b\u2082) \u2b1d (b\u2082.to_matrix b) = 1 :=\nbegin\n  ext l m,\n  change (b\u2082.to_matrix b).vec_mul (b.coords (b\u2082 l)) m = _,\n  rw [to_matrix_vec_mul_coords, coords_apply, \u2190 to_matrix_apply, to_matrix_self],\nend\n\nlemma is_unit_to_matrix :\n  is_unit (b.to_matrix b\u2082) :=\n\u27e8{ val     := b.to_matrix b\u2082,\n   inv     := b\u2082.to_matrix b,\n   val_inv := b.to_matrix_mul_to_matrix b\u2082,\n   inv_val := b\u2082.to_matrix_mul_to_matrix b, }, rfl\u27e9\n\nlemma is_unit_to_matrix_iff [nontrivial k] (p : \u03b9 \u2192 P) :\n  is_unit (b.to_matrix p) \u2194 affine_independent k p \u2227 affine_span k (range p) = \u22a4 :=\nbegin\n  split,\n  { rintros \u27e8\u27e8B, A, hA, hA'\u27e9, (rfl : B = b.to_matrix p)\u27e9,\n    rw matrix.mul_eq_mul at hA hA',\n    exact \u27e8b.affine_independent_of_to_matrix_right_inv p hA,\n           b.affine_span_eq_top_of_to_matrix_left_inv p hA'\u27e9, },\n  { rintros \u27e8h_tot, h_ind\u27e9,\n    let b' : affine_basis \u03b9 k P := \u27e8p, h_tot, h_ind\u27e9,\n    change is_unit (b.to_matrix b'),\n    exact b.is_unit_to_matrix b', },\nend\n\nend ring\n\nsection comm_ring\nvariables [comm_ring k] [module k V] [decidable_eq \u03b9] [fintype \u03b9]\nvariables (b b\u2082 : affine_basis \u03b9 k P)\n\n/-- A change of basis formula for barycentric coordinates.\n\nSee also `affine_basis.to_matrix_vec_mul_coords`. -/\n@[simp] lemma to_matrix_inv_vec_mul_to_matrix (x : P) :\n  (b.to_matrix b\u2082)\u207b\u00b9.vec_mul (b.coords x) = b\u2082.coords x :=\nbegin\n  have hu := b.is_unit_to_matrix b\u2082,\n  rw matrix.is_unit_iff_is_unit_det at hu,\n  rw [\u2190 b.to_matrix_vec_mul_coords b\u2082, matrix.vec_mul_vec_mul, matrix.mul_nonsing_inv _ hu,\n    matrix.vec_mul_one],\nend\n\n/-- If we fix a background affine basis `b`, then for any other basis `b\u2082`, we can characterise\nthe barycentric coordinates provided by `b\u2082` in terms of determinants relative to `b`. -/\nlemma det_smul_coords_eq_cramer_coords (x : P) :\n  (b.to_matrix b\u2082).det \u2022 b\u2082.coords x = (b.to_matrix b\u2082)\u1d40.cramer (b.coords x) :=\nbegin\n  have hu := b.is_unit_to_matrix b\u2082,\n  rw matrix.is_unit_iff_is_unit_det at hu,\n  rw [\u2190 b.to_matrix_inv_vec_mul_to_matrix, matrix.det_smul_inv_vec_mul_eq_cramer_transpose _ _ hu],\nend\nend comm_ring\n\nend affine_basis\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/affine_space/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7208581367925528}}
{"text": "import data.polynomial\nopen finset\nuniverses u v \nvariables \n          {R : Type u}[nonzero_comm_ring R]\n          {A : Type v} [fintype A][decidable_eq A] \n          (M : matrix A A R)\n          (N : matrix A A (polynomial R))   \nnamespace tools\nopen polynomial \nopen with_bot \nnotation `\u03a3` := finset.sum finset.univ\nopen_locale big_operators\n/-!\n    We start by explaining the strategy.\n    Let :  \n    `(s : finset A)(\u03c6 :A \u2192 polynomial R)(a : A)`\n    `(hyp : \u2200 b : A, a \u2260 b \u2192  degree (\u03c6 b) < degree (\u03c6 a) )`\n    `(hyp_not_nul : \u22a5  < degree (\u03c6 a))`:        \n    Then \n    `if a \u2208 s then (degree (finset.sum s \u03c6 ) =  degree (\u03c6 a))`\n            ` else degree (finset.sum s \u03c6 ) < (degree (\u03c6 a))` \n    The caracteristic polynomial is constuct as a product over permutation. \n    We analyse each term of the sum. \n        If `\u03c3 = id ` then the degree of the polynomial is `card A` else the degre is less (`<`) than `card A` \n    That permit to apply the next lemma.  \n-/\n\n\nnamespace with_bot\n\nend with_bot\n\n\nlemma \u03c7_degree_strategy (s : finset A)(\u03c6 :A \u2192 polynomial R)(a : A)\n(hyp : \u2200 b : A, a \u2260 b \u2192  degree (\u03c6 b) < degree (\u03c6 a) ) (hyp_not_nul : \u22a5  < degree (\u03c6 a)):        \n\n        if a \u2208 s then (degree (finset.sum s \u03c6 ) =  degree (\u03c6 a)) else degree (finset.sum s \u03c6 ) < (degree (\u03c6 a)) :=\nbegin \n    apply (finset.induction_on s), {\n        intros, let F :=  not_mem_empty a, split_ifs,\n        rw finset.sum_empty, rw degree_zero, assumption,\n    },\n    {{\n        intros \u2113 s hyp_\u2113 hyp_rec,\n        let p1 := \u03c6 a,\n        let p2 := finset.sum s \u03c6 ,\n        split_ifs with H, \n            by_cases a = \u2113,\n                {\n                    rw sum_insert (by assumption),\n                    rw \u2190 h,\n                    split_ifs at hyp_rec,\n                        {\n                            rw h at h_1, trivial,\n                            },\n                        {   rw add_comm,\n                            apply degree_add_eq_of_degree_lt,exact hyp_rec,\n                            },\n                          \n                },\n                {\n                    split_ifs at hyp_rec,\n                    {\n                        rw sum_insert (by assumption),rw \u2190 hyp_rec,\n                        apply degree_add_eq_of_degree_lt, rw hyp_rec,\n                        exact hyp \u2113 h,\n                        },\n                    {\n                        rw sum_insert (by assumption),\n                        let g := mem_of_mem_insert_of_ne H h, trivial,\n                        },\n                },\n            split_ifs at hyp_rec,\n            {   have : a \u2208 insert \u2113 s,\n                    apply  mem_insert_of_mem  h, trivial,\n                \n            },\n            {\n                rw sum_insert (by assumption),\n                have : a \u2260 \u2113,\n                    let g := mem_insert_self \u2113 s,\n                    intro, rw a_1 at H, trivial,\n                specialize hyp \u2113 this,\n                apply lt_of_le_of_lt (degree_add_le (\u03c6 \u2113 ) p2),\n                apply  max_lt (hyp)(hyp_rec),\n            },\n    }},\nend\n\n\n/--\n    A friend version. \n-/\nlemma proof_strategy.car_pol_degree  (\u03c6 :A \u2192 polynomial R)(a : A)\n(hyp : \u2200 b : A, a \u2260 b \u2192  degree (\u03c6 b) < degree (\u03c6 a) ) \n(hyp_not_nul : \u22a5  < degree (\u03c6 a)):        \n       (degree (\u03a3  \u03c6 ) =  degree (\u03c6 a))  :=\nbegin \n    let g := \u03c7_degree_strategy (finset.univ) \u03c6 a hyp hyp_not_nul,\n    split_ifs at g, assumption,\n    let h := mem_univ a, trivial,\nend\n\n\n\ntheorem my_theo (a b : with_bot \u2115  ) : a \u2264 b \u2192 a+1 \u2264 b+1 := begin \n    intros,\n    rcases  b, intros, rcases a,\n    exact le_refl (none +1), \n    erw  le_bot_iff at a_1, rw a_1, \n    refine le_refl _, \n    rcases a, \n    exact bot_le,\n    apply  some_le_some.mpr, apply add_le_add,\n    apply some_le_some.mp a_1, exact le_refl 1,\nend \n#check with_bot.some_lt_some\n\n\nlemma  zero_le_one' :  (0 : with_bot \u2115 )  \u2264 1 :=\n        begin     apply coe_le_coe.mpr,\n            exact zero_le_one,\nend\n\n\n\nlemma prod_monic (s : finset A)(\u03c6 : A \u2192 polynomial R)  (hyp : \u2200 a : A, monic (\u03c6 a)) : \n                monic (finset.prod s  (\u03bb x : A, \u03c6 x))  :=\n begin \n    apply (finset.induction_on s), { \n      erw prod_empty at  *, \n      exact leading_coeff_C _,\n    },\n    {\n        intros \u2113  s hyp' hyp_rec,\n        rw finset.prod_insert (by assumption),\n        apply monic_mul, exact hyp \u2113, exact hyp_rec,\n    },\n end\n\n\nlemma degree_prod_monic (s : finset A)(\u03c6 : A \u2192 polynomial R)\n(hyp_lc : \u2200 \u2113 : A, monic (\u03c6 \u2113 )) :   \n  degree (finset.prod s  (\u03bb x : A, \u03c6 x)) =  finset.sum s ( \u03bb x : A, degree (\u03c6 x)) := \n  begin \n        apply (finset.induction_on s), {\n          rw prod_empty,\n          exact degree_C (one_ne_zero), \n    },\n    {\n        intros \u2113  s hyp' hyp_rec,\n        rw finset.prod_insert (by assumption), \n        rw finset.sum_insert (by assumption),\n        let g := monic_mul (hyp_lc \u2113 ) (prod_monic s \u03c6 hyp_lc) ,\n        rw \u2190 hyp_rec,\n        apply degree_mul_eq',\n        conv_lhs {\n            erw  monic.def.mp (hyp_lc \u2113), rw one_mul,\n            erw  monic.def.mp (prod_monic s \u03c6 hyp_lc),\n        },\n        exact one_ne_zero,\n    },\n  end   \n\ntheorem cast_with_bot   (a  : \u2115 ) :  nat.cast (a) = (a: with_bot \u2115 ) := begin \n    apply (nat.rec_on a),  {\n        exact rfl,\n    },\n    intros \u2113  hyp_rec,\n    change _ = \u2191\u2113 + \u21911,\n    erw \u2190 hyp_rec, exact rfl,\nend\nlemma prod_monic_one  (s : finset A)(\u03c6 : A \u2192 polynomial R)(hyp : \u2200 \u2113 : A, degree(\u03c6 \u2113 ) = 1 ) \n(hyp_lc : \u2200 \u2113 : A, monic(\u03c6 \u2113) ) :   -- monic ! \n  degree (finset.prod s  (\u03bb x : A, \u03c6 x)) =  card s :=\n begin \n    rw degree_prod_monic s \u03c6  hyp_lc,\n    let g := @finset.sum_const _ _ s _ 1,\n    conv_lhs{\n        apply_congr, skip,\n        rw hyp x,\n    },\n    rw finset.sum_const,  rw add_monoid.smul_one, unfold_coes, rw some_eq_coe, refine cast_with_bot  _ ,\n\n    \nend \n\n\nlemma degree_prod_le_sum_degree (s : finset A)(\u03c6 : A \u2192 polynomial R)  : \n                degree (finset.prod s  (\u03bb x : A, \u03c6 x)) \u2264 finset.sum s ( \u03bb x : A, degree (\u03c6 x)) :=\n begin apply (finset.induction_on s), {\n          rw prod_empty, rw sum_empty,\n          rw degree_one, exact le_refl 0,\n          },\n        intros \u2113 s hyp_\u2113 hyp_rec,\n        rw sum_insert (by assumption), rw prod_insert (by assumption),\n        exact le_trans (degree_mul_le _ _) (add_le_add_left' (hyp_rec)),\n end\n\n\n\n\ntheorem sum_le (s : finset A) (\u03c6 : A \u2192 (with_bot \u2115) ) (hyp : \u2200 \u2113 : A, \u03c6 \u2113 \u2264 1)  :  \n        finset.sum s \u03c6 \u2264  card s := \nbegin \n    apply (finset.induction_on s), {\n        rw sum_empty, rw card_empty, exact le_refl 0,\n    },\n    intros \u2113 s hyp_l hyp_rec,\n    rw sum_insert (by assumption), rw card_insert_of_not_mem(by assumption), rw coe_add, rw add_comm,\n    apply add_le_add' hyp_rec (hyp \u2113 ),\nend\n\nlemma prod_degree_one_le_card (s : finset A)(\u03c6 : A \u2192 polynomial R) (hyp : \u2200 \u2113 : A, degree(\u03c6 \u2113 ) \u2264  1 ) :\n    degree (finset.prod s  (\u03bb x : A, \u03c6 x)) \u2264 card s := begin \n        apply le_trans (degree_prod_le_sum_degree s \u03c6),\n        apply sum_le  , exact hyp,\nend \n\n\n\nlemma le_add_compensation (a : \u2115) { b c d : with_bot \u2115} : (a : with_bot \u2115 ) + c \u2264  b +d  \u2192  b \u2264 a \u2192  c \u2264 d := \nbegin \n    intros hyp1 hyp2 , \n    have r : b+d \u2264  a + d,\n        exact add_le_add_right' hyp2,\n    have : (a : with_bot \u2115 ) + c \u2264  a + d, \n        apply le_trans (hyp1) (r),\n    rcases c, exact bot_le,\n    rcases d, erw le_bot_iff at this, trivial,\n    rw \u2190 some_eq_coe at  * ,\n    erw \u2190 coe_add at this, erw \u2190 coe_add at this,\n    let F := coe_le_coe.mp this,\n    apply coe_le_coe.mpr,\n    exact (add_le_add_iff_left a).mp F,\nend\n/-!\n    The last technical lemma \n-/\nexample (a b: \u2115 ): a = b \u2192  a \u2264 b := begin \nlibrary_search,\nend\nlemma add_eq_bot (a : \u2115 ) (b : with_bot \u2115 ) : (a : with_bot \u2115 ) + b = \u22a5  \u2192   b = \u22a5  :=\nbegin \n    cases b, intros,  rw none_eq_bot, intros, rw some_eq_coe at a_1, rw \u2190 coe_add at a_1,  finish,\nend\n#check with_bot.\n--by cases a; cases b; simp [none_eq_bot, some_eq_coe, coe_add.symm]\nlemma ert (a b : \u2115) : (a = b ) \u2192 (a : with_bot \u2115 ) = b := begin \n  intros,exact congr_arg coe a_1,\nend\n\nlemma tre (a b : \u2115 ) : (a : with_bot \u2115 ) = b \u2192 a = b := begin \n  intros,exact option.some_inj.mp a_1,\nend\nlemma left_cancel ( a : \u2115 ) {b c : with_bot \u2115 } : \u2191a + b = a + c \u2192 b = c := begin \n    intros, \n    rcases b, rcases c, exact rfl, rw none_eq_bot  at a_1,\n    rw add_bot at a_1, rw some_eq_coe at a_1, let g := (add_eq_bot a) c, \n    let h :=  eq.symm a_1,\n    specialize g h, trivial, rw some_eq_coe at a_1, rw \u2190 coe_add at a_1,cases c, finish, \n    rw some_eq_coe at a_1, rw \u2190 coe_add at a_1, let k := tre (a+b) (a+c) a_1,\n    rw some_eq_coe , rw some_eq_coe,\n    apply ert,\n    apply eq_of_add_eq_add_left k,\nend \ntheorem proof_stra (a : \u2115) { b c d : \u2115} :   a \u2264 c \u2192 b \u2264 d \u2192  (a+ b = c +d \u2192 (a=c \u2227 b = d)) :=\nbegin\n    intros,split, apply le_antisymm, assumption,\n    apply (add_le_add_iff_left b).mp, \n    conv_rhs {\n        rw add_comm,\n        rw a_3, rw add_comm,\n    },\n    apply (add_le_add_iff_right c).mpr , assumption,\n    apply le_antisymm, assumption,\n    apply (add_le_add_iff_left a).mp,\n    conv_rhs  {\n        rw a_3,\n    },\n    apply (add_le_add_iff_right d).mpr , assumption,\nend  \n\n\n/--\n        I use proof_strategy 2 \n-/\ntheorem q_card_insert_eq_card (s : finset A) (\u03c6 : A \u2192 (with_bot \u2115) )  \n(hyp : \u2200 \u2113 : A, \u03c6 \u2113 \u2264 1) (\u21130 \u2209 s ):  \n finset.sum (insert \u21130 s)  \u03c6 = card (insert \u21130 s) \u2192 finset.sum s  \u03c6 = card  s := \n begin \n     rw sum_insert(by assumption),\n    rw card_insert_of_not_mem(by assumption), rw [coe_add, add_comm], intros  hyp_s,\n    apply le_antisymm( sum_le s \u03c6 hyp),\n    have pre_strat :  \u21911 + \u2191(card s)   =   \u03c6 \u21130 + finset.sum s (\u03bb (x : A), \u03c6 x),\n        rw add_comm, rw \u2190 hyp_s, rw add_comm,\n    apply  le_add_compensation 1 (le_of_eq (pre_strat)),\n    exact (hyp \u21130), \n end\n\n\n\ntheorem jenesaispas (s : finset A) (\u03c6 : A \u2192 (with_bot \u2115) )  \n(hyp : \u2200 \u2113 : A, \u03c6 \u2113 \u2264 1) : \n finset.sum s \u03c6 = card s \u2192 (\u2200 \u2113 : A, \u2113 \u2208 s \u2192 \u03c6 \u2113 = 1) := \n begin \n    apply (finset.induction_on s), {\n        rw sum_empty, intros, let g := not_mem_empty \u2113 , trivial,\n    },\n    {   \n        intros \u2113 s hyp_l hyp_rec,intros,\n        \n        by_cases \u2113_1 = \u2113,{ let h' := h,\n            by_cases (finset.sum s \u03c6 = \u2191(card s)),{\n                rw [sum_insert(by assumption),card_insert_of_not_mem(by assumption), coe_add] at a,\n            intros,rw h',\n                rw h at a, rw add_comm at a, refine left_cancel (card s) a ,\n            },\n            let pre_strat := q_card_insert_eq_card s \u03c6 hyp \u2113 hyp_l a,trivial,\n            },\n        {\n            let  p := mem_of_mem_insert_of_ne a_1 h,\n            let pre_strat := q_card_insert_eq_card s \u03c6 hyp \u2113 hyp_l a,\n            specialize hyp_rec pre_strat, exact hyp_rec \u2113_1 p,\n        },\n    },\n end\n\n\n\n\n\ntheorem det_card_term_'11 ( s: finset A) (\u03c6 : A \u2192 polynomial R)\n(hyp : \u2200 \u2113 : A, degree(\u03c6 \u2113 ) \u2264 (1 : with_bot \u2115  ))  :\n    degree (finset.prod s  (\u03bb x :A, \u03c6 x)) =  card s \u2192 (\u2200 \u2113 : A, \u2113 \u2208 s \u2192 degree (\u03c6 \u2113 ) = 1)  :=\nbegin \n    let je := jenesaispas s (\u03bb x, degree (\u03c6 x)) hyp,\n    intros,\n    have rr :  finset.sum s (\u03bb x, degree (\u03c6 x))  = card s,\n        apply le_antisymm,{\n            apply sum_le s , exact hyp,\n        },\n        {\n            rw \u2190 a,      \n            exact degree_prod_le_sum_degree s \u03c6,\n        },\n    exact je rr \u2113  a_1,\n end\n\n\ntheorem degree_prod_le_one_lt_card (\u03c6 : A \u2192 polynomial R)\n(hyp : \u2200 \u2113 : A, degree(\u03c6 \u2113 ) \u2264 1 ) \n(hyp_lc : \u2203  \u21130 : A, degree (\u03c6 \u21130) < 1) :\n    \n    degree (finset.prod finset.univ  (\u03bb x :A, \u03c6 x)) <  fintype.card A := \n\nbegin \n    by_contradiction contra, push_neg at contra,\n    let g := det_card_term_'11 (finset.univ) \u03c6 hyp,\n    have : \u2191(fintype.card A) = degree (finset.prod univ (\u03bb (x : A), \u03c6 x)),\n        apply le_antisymm (by assumption),\n            apply le_trans (degree_prod_le_sum_degree (finset.univ) \u03c6),\n            apply sum_le ,\n            exact hyp,\n        rcases hyp_lc with \u27e8 \u03b6, j\u27e9, \n        specialize g (eq.symm this) \u03b6 (mem_univ _),\n        rw g at j,exact lt_irrefl 1 j,\nend\n\n\n\nend tools\n\n\n\n\n\n\n\n\n\n/-\n  unfold car_matrix, split_ifs, rw eval_add, rw eval_C, rw eval_X, rw h, rw add_val, rw smul_val, rw one_val, rw mul_ite,\n     rw mul_one, rw mul_zero,simp, rw eval_C,rw add_val, rw smul_val, rw one_val, rw mul_ite,split_ifs, rw mul_zero,rw add_zero,\n-/\n", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep1/caracteristique_pol/tools.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.720839364188462}}
{"text": "import data.nat.gcd\nopen nat\n/-2\u2217. True or false?\n(i) If a and b are positive integers, and there exist integers \u03bb and \u03bc such that \u03bba + \u03bcb = 1, then\ngcd(a, b) = 1.\n(ii) If a and b are positive integers, and there exist integers \u03bb and \u03bc such that \u03bba + \u03bcb = 7,\nthen gcd(a, b) = 7.-/\nvariables {a b \u03bc \u03bd: \u2115}\n\ntheorem Q0802i : \u2203 \u03bc, \u2203 \u03bd, \u03bc*a + \u03bd*b = 1 \u2192 gcd a b = 1 := sorry\n\ntheorem Q0802ii : \u2203 \u03bc, \u2203 \u03bd, \u03bc*a + \u03bd*b = 7 \u2192 gcd a b = 7 := sorry \n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/problem_bank/PB0802/Q0802.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7208393467150065}}
{"text": "import interior_world.level4 --hide\n/-\n\n# Level 5: Characterization of the interior\n\n\n\n-/\nvariables {X : Type} -- hide\nvariables [topological_space X] (x : X)  (A B : set X) -- hide\n\nnamespace topological_space -- hide\n\n/- Lemma\nThe interior of a set A is the biggest subset satisfying:\n - It is contained in A\n - It is open.\n-/\nlemma interior_def'': is_open B \u2227 B \u2286 A \u2227 (\u2200 U, U \u2286 A \u2192 is_open U \u2192 U \u2286 B) \u2194 B = interior A :=   \nbegin\n  split,\n  {\n    rintros \u27e8is_open_B, \u27e8B_subset_A, B_is_biggest_open\u27e9\u27e9,\n    ext1,\n    split,\n    {\n      apply interior_maximal A B B_subset_A is_open_B,\n    },\n    {\n      intro ha,\n      exact B_is_biggest_open (interior A) (interior_is_subset A) (interior_is_open A) ha,\n    },\n  },\n  {\n    intro,\n    subst B,\n    exact \u27e8interior_is_open A, \u27e8interior_is_subset A, interior_maximal A\u27e9\u27e9,\n  },\n\n\n\n\n\n\n\n\n\n\n\nend \n\nend topological_space -- hide\n", "meta": {"author": "mmasdeu", "repo": "topologygame", "sha": "0a1b868031919a5555e7b99efca66ece2f546ec7", "save_path": "github-repos/lean/mmasdeu-topologygame", "path": "github-repos/lean/mmasdeu-topologygame/topologygame-0a1b868031919a5555e7b99efca66ece2f546ec7/src/interior_world/level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7208240598783762}}
{"text": "import tactic\nimport data.nat.basic\nimport data.real.basic\n \nopen_locale classical\nnoncomputable theory\n\n\nopen_locale big_operators\nopen finset\n\ntheorem cauchy_induction {P : \u2115 \u2192 Prop} (h1 : \u03a0 (n : \u2115), P (n + 1) \u2192 P n) (h2 : \u03a0 (n : \u2115), P n \u2192 P (2 * n)) \n{m : \u2115} (hm : 0 < m) (hp : P m) : \n\u2200 (n : \u2115), P n :=\n\nbegin\n  intro n,\n  have lt_pow_two := nat.lt_two_pow n,\n  have le_m_pow_two : n <= 2 ^ n * m,\n  {\n    have le_pow_two := nat.le_of_lt lt_pow_two,\n    have hm' := nat.succ_le_of_lt hm,\n    have target_times_one := nat.mul_le_mul le_pow_two hm',\n    rw mul_one at target_times_one,\n    refine target_times_one,\n  },\n  have two_pow_k_times_m : (\u2200 k : \u2115, P (2 ^ k * m)),\n  {\n    intro k,\n    induction k with i hi,\n    {\n      rw [pow_zero, one_mul],\n      refine hp,\n    },\n    {\n      rw [pow_succ, mul_assoc],\n      refine h2 (2 ^ i * m) hi,\n    },\n  },\n  have two_pow_n_times_m := two_pow_k_times_m n,\n  refine nat.decreasing_induction h1 le_m_pow_two two_pow_n_times_m,\nend", "meta": {"author": "awainverse", "repo": "mc_shimon", "sha": "17ce6950dd610b09422d6309182311fd48a806ad", "save_path": "github-repos/lean/awainverse-mc_shimon", "path": "github-repos/lean/awainverse-mc_shimon/mc_shimon-17ce6950dd610b09422d6309182311fd48a806ad/src/cauchy_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7208240582487732}}
{"text": "/-\nCopyright (c) 2021 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n\n! This file was ported from Lean 3 source module topology.algebra.order.left_right\n! leanprover-community/mathlib commit bcfa726826abd57587355b4b5b7e78ad6527b7e4\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.ContinuousOn\n\n/-!\n# Left and right continuity\n\nIn this file we prove a few lemmas about left and right continuous functions:\n\n* `continuousWithinAt_Ioi_iff_Ici`: two definitions of right continuity\n  (with `(a, \u221e)` and with `[a, \u221e)`) are equivalent;\n* `continuousWithinAt_Iio_iff_Iic`: two definitions of left continuity\n  (with `(-\u221e, a)` and with `(-\u221e, a]`) are equivalent;\n* `continuousAt_iff_continuous_left_right`, `continuousAt_iff_continuous_left'_right'` :\n  a function is continuous at `a` if and only if it is left and right continuous at `a`.\n\n## Tags\n\nleft continuous, right continuous\n-/\n\n\nopen Set Filter Topology\n\nsection PartialOrder\n\nvariable {\u03b1 \u03b2 : Type _} [TopologicalSpace \u03b1] [PartialOrder \u03b1] [TopologicalSpace \u03b2]\n\ntheorem continuousWithinAt_Ioi_iff_Ici {a : \u03b1} {f : \u03b1 \u2192 \u03b2} :\n    ContinuousWithinAt f (Ioi a) a \u2194 ContinuousWithinAt f (Ici a) a := by\n  simp only [\u2190 Ici_diff_left, continuousWithinAt_diff_self]\n#align continuous_within_at_Ioi_iff_Ici continuousWithinAt_Ioi_iff_Ici\n\ntheorem continuousWithinAt_Iio_iff_Iic {a : \u03b1} {f : \u03b1 \u2192 \u03b2} :\n    ContinuousWithinAt f (Iio a) a \u2194 ContinuousWithinAt f (Iic a) a :=\n  @continuousWithinAt_Ioi_iff_Ici \u03b1\u1d52\u1d48 _ _ _ _ _ f\n#align continuous_within_at_Iio_iff_Iic continuousWithinAt_Iio_iff_Iic\n\ntheorem nhds_left'_le_nhds_ne (a : \u03b1) : \ud835\udcdd[<] a \u2264 \ud835\udcdd[\u2260] a :=\n  nhdsWithin_mono a fun _ => ne_of_lt\n#align nhds_left'_le_nhds_ne nhds_left'_le_nhds_ne\n\ntheorem nhds_right'_le_nhds_ne (a : \u03b1) : \ud835\udcdd[>] a \u2264 \ud835\udcdd[\u2260] a :=\n  nhdsWithin_mono a fun _ => ne_of_gt\n#align nhds_right'_le_nhds_ne nhds_right'_le_nhds_ne\n\nend PartialOrder\n\nsection TopologicalSpace\n\nvariable {\u03b1 \u03b2 : Type _} [TopologicalSpace \u03b1] [LinearOrder \u03b1] [TopologicalSpace \u03b2]\n\ntheorem nhds_left_sup_nhds_right (a : \u03b1) : \ud835\udcdd[\u2264] a \u2294 \ud835\udcdd[\u2265] a = \ud835\udcdd a := by\n  rw [\u2190 nhdsWithin_union, Iic_union_Ici, nhdsWithin_univ]\n#align nhds_left_sup_nhds_right nhds_left_sup_nhds_right\n\ntheorem nhds_left'_sup_nhds_right (a : \u03b1) : \ud835\udcdd[<] a \u2294 \ud835\udcdd[\u2265] a = \ud835\udcdd a := by\n  rw [\u2190 nhdsWithin_union, Iio_union_Ici, nhdsWithin_univ]\n#align nhds_left'_sup_nhds_right nhds_left'_sup_nhds_right\n\ntheorem nhds_left_sup_nhds_right' (a : \u03b1) : \ud835\udcdd[\u2264] a \u2294 \ud835\udcdd[>] a = \ud835\udcdd a := by\n  rw [\u2190 nhdsWithin_union, Iic_union_Ioi, nhdsWithin_univ]\n#align nhds_left_sup_nhds_right' nhds_left_sup_nhds_right'\n\ntheorem nhds_left'_sup_nhds_right' (a : \u03b1) : \ud835\udcdd[<] a \u2294 \ud835\udcdd[>] a = \ud835\udcdd[\u2260] a := by\n  rw [\u2190 nhdsWithin_union, Iio_union_Ioi]\n#align nhds_left'_sup_nhds_right' nhds_left'_sup_nhds_right'\n\ntheorem continuousAt_iff_continuous_left_right {a : \u03b1} {f : \u03b1 \u2192 \u03b2} :\n    ContinuousAt f a \u2194 ContinuousWithinAt f (Iic a) a \u2227 ContinuousWithinAt f (Ici a) a := by\n  simp only [ContinuousWithinAt, ContinuousAt, \u2190 tendsto_sup, nhds_left_sup_nhds_right]\n#align continuous_at_iff_continuous_left_right continuousAt_iff_continuous_left_right\n\ntheorem continuousAt_iff_continuous_left'_right' {a : \u03b1} {f : \u03b1 \u2192 \u03b2} :\n    ContinuousAt f a \u2194 ContinuousWithinAt f (Iio a) a \u2227 ContinuousWithinAt f (Ioi a) a := by\n  rw [continuousWithinAt_Ioi_iff_Ici, continuousWithinAt_Iio_iff_Iic,\n    continuousAt_iff_continuous_left_right]\n#align continuous_at_iff_continuous_left'_right' continuousAt_iff_continuous_left'_right'\n\nend TopologicalSpace\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/Algebra/Order/LeftRight.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7208065914973901}}
{"text": "import tactic.tidy\n\nimport set_category.diagram_lemmas\nimport help_functions\n\n\n\n\nnamespace Product\n\nopen set \n     diagram_lemmas\n     classical\n     function\n     help_functions\n     category_theory\n\n\nuniverses v u\n\nlocal notation f ` \u229a `:80 g:80 := category_struct.comp g f\n\ndef is_product {X : Type v} [category X]\n    (A B : X)\n    {P : X} (\u03c0\u2081 : P \u27f6 A) (\u03c0\u2082 : P \u27f6 B): Prop := \n    \u03a0 (Q : X) (q\u2081 : Q \u27f6 A) (q\u2082 : Q \u27f6 B),\n            \u2203! p : Q \u27f6 P, q\u2081 = \u03c0\u2081 \u229a p \u2227 q\u2082 = \u03c0\u2082 \u229a p\n\n\nvariables (A B : Type u)\n\n\nlemma cartesian_product_is_product : \n    is_product A B prod.fst prod.snd :=\n    begin\n        intros Q q\u2081 q\u2082,\n        let p : Q \u2192 (A \u00d7 B) := \u03bb k, \u27e8q\u2081 k,q\u2082 k\u27e9,\n        use p,\n        tidy\n    end\n\nlemma jointly_mono\n    {X : Type v} [category X]\n    (A B P : X) {Q: X} (\u03c0\u2081 : P \u27f6 A) (\u03c0\u2082 : P \u27f6 B)\n        (prod: is_product A B \u03c0\u2081 \u03c0\u2082)\n        {s s\u2081: Q \u27f6 P} \n        (h1 : \u03c0\u2081 \u229a s\u2081 = \u03c0\u2081 \u229a s)\n        (h2 : \u03c0\u2082 \u229a s\u2081 = \u03c0\u2082 \u229a s):\n        s\u2081 = s :=\n    begin\n        have prod_Q := prod Q (\u03c0\u2081 \u229a s\u2081) (\u03c0\u2082 \u229a s\u2081),\n        cases prod_Q with p spec_p,\n        have spec_s1 : \u03c0\u2081 \u229a s = \u03c0\u2081 \u229a p := \n            h1 \u25b8 spec_p.1.1,\n        have spec_s2 : \u03c0\u2082 \u229a s = \u03c0\u2082 \u229a p := \n            h2 \u25b8 spec_p.1.2,\n        rw spec_p.2 s \u27e8h1, h2\u27e9,\n        exact spec_p.2 s\u2081 \u27e8rfl, rfl\u27e9,\n    end\n\nopen prod\n\nlemma jointly_mono_set\n        {Q : Type u}\n        {f g: Q \u2192 (A \u00d7 B)} \n        (h1 : fst \u2218 f = fst \u2218 g)\n        (h2 : snd \u2218 f = snd \u2218 g):\n        f = g :=\n        have elements : \u2200 q : Q , f q = g q :=\n            assume q,\n            have \u03c0\u2081 : (f q).1 = (g q).1 := \n                 have f1 : (prod.fst \u2218 f) q = (prod.fst \u2218 g) q := by rw h1,\n                 f1,\n            have \u03c0\u2082 : prod.snd (f q) = prod.snd (g q) := \n                 have s1 : (prod.snd \u2218 f) q = (prod.snd \u2218 g) q := by rw h2,\n                 s1,\n            by {\n                ext1,\n                exact \u03c0\u2081, exact \u03c0\u2082\n            },\n        funext elements\n\n\n\nend Product", "meta": {"author": "QaisHamarneh", "repo": "Coalgebra-in-Lean", "sha": "bd0452df98bc64b608e5dfd7babc42c301bb6a46", "save_path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean", "path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean/Coalgebra-in-Lean-bd0452df98bc64b608e5dfd7babc42c301bb6a46/src/set_category/limits/Product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.7208065837089881}}
{"text": "/-\nCopyright (c) 2021 Chris Hughes, Junyan Xu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Junyan Xu\n-/\nimport data.finsupp.fintype\nimport data.mv_polynomial.equiv\nimport set_theory.cardinal.ordinal\n/-!\n# Cardinality of Multivariate Polynomial Ring\n\nThe main result in this file is `mv_polynomial.cardinal_mk_le_max`, which says that\nthe cardinality of `mv_polynomial \u03c3 R` is bounded above by the maximum of `#R`, `#\u03c3`\nand `\u2135\u2080`.\n-/\nuniverses u v\n\nopen cardinal\nopen_locale cardinal\n\nnamespace mv_polynomial\n\nsection two_universes\n\nvariables {\u03c3 : Type u} {R : Type v} [comm_semiring R]\n\n@[simp] lemma cardinal_mk_eq_max_lift [nonempty \u03c3] [nontrivial R] :\n  #(mv_polynomial \u03c3 R) = max (max (cardinal.lift.{u} $ #R) $ cardinal.lift.{v} $ #\u03c3) \u2135\u2080 :=\n(mk_finsupp_lift_of_infinite _ R).trans $\nby rw [mk_finsupp_nat, max_assoc, lift_max, lift_aleph_0, max_comm]\n\n@[simp] lemma cardinal_mk_eq_lift [is_empty \u03c3] : #(mv_polynomial \u03c3 R) = cardinal.lift.{u} (#R) :=\n((is_empty_ring_equiv R \u03c3).to_equiv.trans equiv.ulift.{u}.symm).cardinal_eq\n\n\n\nend two_universes\n\nvariables {\u03c3 R : Type u} [comm_semiring R]\n\nlemma cardinal_mk_eq_max [nonempty \u03c3] [nontrivial R] :\n  #(mv_polynomial \u03c3 R) = max (max (#R) (#\u03c3)) \u2135\u2080 := by simp\n\n/-- The cardinality of the multivariate polynomial ring, `mv_polynomial \u03c3 R` is at most the maximum\nof `#R`, `#\u03c3` and `\u2135\u2080` -/\nlemma cardinal_mk_le_max : #(mv_polynomial \u03c3 R) \u2264 max (max (#R) (#\u03c3)) \u2135\u2080 :=\ncardinal_lift_mk_le_max.trans $ by rw [lift_id, lift_id]\n\nend mv_polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/mv_polynomial/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7208065759709898}}
{"text": "import game.order.level05\nimport data.real.basic\nopen real\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 6\n\nAn interesting result to prove.\n-/\n\n\n\n/- Lemma\nFor any two non-negative real numbers $a$ and $b$, we have that\n$$a \\le b \\iff a^2 \\le b^2 $$.\n-/\ntheorem le_iff_sq_le (a b : \u211d) (ha : 0 \u2264 a) (hb : 0 \u2264 b): a \u2264 b \u2194 a^2 \u2264 b^2:=\nbegin\n    split,\n    intro h,\n    have h1 : a^2 \u2264 a * b, \n        have h11 : a \u2264 a, linarith,\n        have h12 := mul_le_mul h11 h ha ha,\n        have h13 : a * a = a^2, ring,\n        rw h13 at h12, exact h12,\n    have h2 : a * b \u2264 b^2, \n        have h21 : b \u2264 b, linarith,\n        have h22 := mul_le_mul h21 h ha hb,\n        rw mul_comm at h22,\n        have h23 : b * b = b^2, ring,\n        rw h23 at h22, exact h22,\n    exact le_trans h1 h2,\n    intro h,\n    have ha2 : 0 \u2264 a^2, exact pow_nonneg ha 2,\n    have hb2 : 0 \u2264 b^2, exact pow_nonneg hb 2,\n    have h1 := (sqrt_le ha2 hb2).mpr h,\n    have h2a := sqrt_sqr ha, \n    have h2b := sqrt_sqr hb,\n    rw h2a at h1, rw h2b at h1, exact h1, done\n\nend\n\nend xena -- hide", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422172230208, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.7207702132905579}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n-/\nimport data.nat.basic\n\n/-!\n# `nat.upto`\n\n`nat.upto p`, with `p` a predicate on `\u2115`, is a subtype of elements `n : \u2115` such that no value\n(strictly) below `n` satisfies `p`.\n\nThis type has the property that `>` is well-founded when `\u2203 i, p i`, which allows us to implement\nsearches on `\u2115`, starting at `0` and with an unknown upper-bound.\n\nIt is similar to the well founded relation constructed to define `nat.find` with\nthe difference that, in `nat.upto p`, `p` does not need to be decidable. In fact,\n`nat.find` could be slightly altered to factor decidability out of its\nwell founded relation and would then fulfill the same purpose as this file.\n-/\n\nnamespace nat\n\n/-- The subtype of natural numbers `i` which have the property that\nno `j` less than `i` satisfies `p`. This is an initial segment of the\nnatural numbers, up to and including the first value satisfying `p`.\n\nWe will be particularly interested in the case where there exists a value\nsatisfying `p`, because in this case the `>` relation is well-founded.  -/\n@[reducible]\ndef upto (p : \u2115 \u2192 Prop) : Type := {i : \u2115 // \u2200 j < i, \u00ac p j}\n\nnamespace upto\n\nvariable {p : \u2115 \u2192 Prop}\n\n/-- Lift the \"greater than\" relation on natural numbers to `nat.upto`. -/\nprotected def gt (p) (x y : upto p) : Prop := x.1 > y.1\n\ninstance : has_lt (upto p) := \u27e8\u03bb x y, x.1 < y.1\u27e9\n\n/-- The \"greater than\" relation on `upto p` is well founded if (and only if) there exists a value\nsatisfying `p`. -/\nprotected lemma wf : (\u2203 x, p x) \u2192 well_founded (upto.gt p)\n| \u27e8x, h\u27e9 := begin\n  suffices : upto.gt p = measure (\u03bb y : nat.upto p, x - y.val),\n  { rw this, apply measure_wf },\n  ext \u27e8a, ha\u27e9 \u27e8b, _\u27e9,\n  dsimp [measure, inv_image, upto.gt],\n  rw nat.sub_lt_sub_left_iff,\n  exact le_of_not_lt (\u03bb h', ha _ h' h),\nend\n\n/-- Zero is always a member of `nat.upto p` because it has no predecessors. -/\ndef zero : nat.upto p := \u27e80, \u03bb j h, false.elim (nat.not_lt_zero _ h)\u27e9\n\n/-- The successor of `n` is in `nat.upto p` provided that `n` doesn't satisfy `p`. -/\ndef succ (x : nat.upto p) (h : \u00ac p x.val) : nat.upto p :=\n\u27e8x.val.succ, \u03bb j h', begin\n  rcases nat.lt_succ_iff_lt_or_eq.1 h' with h' | rfl;\n  [exact x.2 _ h', exact h]\nend\u27e9\n\nend upto\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/upto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7207481540763927}}
{"text": "/-\nCopyright (c) 2022 James Gallicchio.\n\nAuthors: James Gallicchio\n-/\n\n@[reducible]\ndef Tuple (\u03b1 : Type u) : Nat \u2192 Type u\n| 0   => PUnit\n| 1   => \u03b1\n| (n+1)+1 => \u03b1 \u00d7 Tuple \u03b1 (Nat.succ n)\n\nnamespace Tuple\n\n@[inline]\ndef toList (t : Tuple \u03b1 n) : List \u03b1 :=\n  match n, t with\n  | 0,   ()     => []\n  | 1,   a      => [a]\n  | _+2, (a,as) => a :: toList as\n\n@[simp]\ntheorem length_toList (t : Tuple \u03b1 n)\n  : t.toList.length = n\n  := by\n  induction n with\n  | zero => simp [toList]\n  | succ n ih =>\n    cases n <;> simp [toList, ih]\n\n@[inline]\ndef ofList (L : List \u03b1) : Tuple \u03b1 L.length :=\n  match L with\n  | []        => ()\n  | [x]       => x\n  | x::y::xs  => (x, ofList (y::xs))\n\nend Tuple\n\n/-! ## List.choose\n\nReturns list of all ways of choosing `n` elements from `L`.\nThis is equivalent to the list of all `(L[i1], ... L[in])`\nfor `0 \u2264 i1 < i2 < ... < in < L.length`.\n-/\ndef List.chooseSucc : (n : Nat) \u2192 List \u03b1 \u2192 List (Tuple \u03b1 n.succ)\n| 0  , L     => L\n| _+1, []    => []\n| n+1, x::xs =>\n  -- Either x is in the tuple,\n  (List.chooseSucc n xs |>.map ((x, \u00b7))) ++\n  -- or it is not.\n  (List.chooseSucc (n+1) xs)\n\ndef List.choose (n : Nat) (h_n : n = n.pred.succ := by decide)\n  : List \u03b1 \u2192 List (Tuple \u03b1 n) :=\n  h_n \u25b8 List.chooseSucc n.pred\n", "meta": {"author": "JamesGallicchio", "repo": "LeanColls", "sha": "9cb0a0c9a838bea24be80eace168bcc5f9481596", "save_path": "github-repos/lean/JamesGallicchio-LeanColls", "path": "github-repos/lean/JamesGallicchio-LeanColls/LeanColls-9cb0a0c9a838bea24be80eace168bcc5f9481596/LeanColls/Tuple.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7207481476741973}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro\n-/\nimport data.int.order.basic\n\n/-! # Least upper bound and greatest lower bound properties for integers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove that a bounded above nonempty set of integers has the greatest element, and a\ncounterpart of this statement for the least element.\n\n## Main definitions\n\n* `int.least_of_bdd`: if `P : \u2124 \u2192 Prop` is a decidable predicate, `b` is a lower bound of the set\n  `{m | P m}`, and there exists `m : \u2124` such that `P m` (this time, no witness is required), then\n  `int.least_of_bdd` returns the least number `m` such that `P m`, together with proofs of `P m` and\n  of the minimality. This definition is computable and does not rely on the axiom of choice.\n* `int.greatest_of_bdd`: a similar definition with all inequalities reversed.\n\n## Main statements\n\n* `int.exists_least_of_bdd`: if `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is\n  bounded below and nonempty, then this set has the least element. This lemma uses classical logic\n  to avoid assumption `[decidable_pred P]`. See `int.least_of_bdd` for a constructive counterpart.\n\n* `int.coe_least_of_bdd_eq`: `(int.least_of_bdd b Hb Hinh : \u2124)` does not depend on `b`.\n\n* `int.exists_greatest_of_bdd`, `int.coe_greatest_of_bdd_eq`: versions of the above lemmas with all\n  inequalities reversed.\n\n## Tags\n\ninteger numbers, least element, greatest element\n-/\n\nnamespace int\n\n/-- A computable version of `exists_least_of_bdd`: given a decidable predicate on the\nintegers, with an explicit lower bound and a proof that it is somewhere true, return\nthe least value for which the predicate is true. -/\ndef least_of_bdd {P : \u2124 \u2192 Prop} [decidable_pred P]\n  (b : \u2124) (Hb : \u2200 z : \u2124, P z \u2192 b \u2264 z) (Hinh : \u2203 z : \u2124, P z) :\n  {lb : \u2124 // P lb \u2227 (\u2200 z : \u2124, P z \u2192 lb \u2264 z)} :=\nhave EX : \u2203 n : \u2115, P (b + n), from\n  let \u27e8elt, Helt\u27e9 := Hinh in\n  match elt, le.dest (Hb _ Helt), Helt with\n  | ._, \u27e8n, rfl\u27e9, Hn := \u27e8n, Hn\u27e9\n  end,\n\u27e8b + (nat.find EX : \u2124), nat.find_spec EX, \u03bb z h,\n  match z, le.dest (Hb _ h), h with\n  | ._, \u27e8n, rfl\u27e9, h := add_le_add_left\n    (int.coe_nat_le.2 $ nat.find_min' _ h) _\n  end\u27e9\n\n/-- If `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is bounded below and nonempty,\nthen this set has the least element. This lemma uses classical logic to avoid assumption\n`[decidable_pred P]`. See `int.least_of_bdd` for a constructive counterpart. -/\ntheorem exists_least_of_bdd {P : \u2124 \u2192 Prop}\n  (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 b \u2264 z) (Hinh : \u2203 z : \u2124, P z) :\n  \u2203 lb : \u2124, P lb \u2227 (\u2200 z : \u2124, P z \u2192 lb \u2264 z) :=\nby classical; exact let \u27e8b, Hb\u27e9 := Hbdd, \u27e8lb, H\u27e9 := least_of_bdd b Hb Hinh in \u27e8lb, H\u27e9\n\nlemma coe_least_of_bdd_eq {P : \u2124 \u2192 Prop} [decidable_pred P]\n  {b b' : \u2124} (Hb : \u2200 z : \u2124, P z \u2192 b \u2264 z) (Hb' : \u2200 z : \u2124, P z \u2192 b' \u2264 z) (Hinh : \u2203 z : \u2124, P z) :\n  (least_of_bdd b Hb Hinh : \u2124) = least_of_bdd b' Hb' Hinh :=\nbegin\n  rcases least_of_bdd b Hb Hinh with \u27e8n, hn, h2n\u27e9,\n  rcases least_of_bdd b' Hb' Hinh with \u27e8n', hn', h2n'\u27e9,\n  exact le_antisymm (h2n _ hn') (h2n' _ hn),\nend\n\n/-- A computable version of `exists_greatest_of_bdd`: given a decidable predicate on the\nintegers, with an explicit upper bound and a proof that it is somewhere true, return\nthe greatest value for which the predicate is true. -/\ndef greatest_of_bdd {P : \u2124 \u2192 Prop} [decidable_pred P]\n  (b : \u2124) (Hb : \u2200 z : \u2124, P z \u2192 z \u2264 b) (Hinh : \u2203 z : \u2124, P z) :\n  {ub : \u2124 // P ub \u2227 (\u2200 z : \u2124, P z \u2192 z \u2264 ub)} :=\nhave Hbdd' : \u2200 (z : \u2124), P (-z) \u2192 -b \u2264 z, from \u03bb z h, neg_le.1 (Hb _ h),\nhave Hinh' : \u2203 z : \u2124, P (-z), from\nlet \u27e8elt, Helt\u27e9 := Hinh in \u27e8-elt, by rw [neg_neg]; exact Helt\u27e9,\nlet \u27e8lb, Plb, al\u27e9 := least_of_bdd (-b) Hbdd' Hinh' in\n\u27e8-lb, Plb, \u03bb z h, le_neg.1 $ al _ $ by rwa neg_neg\u27e9\n\n/-- If `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is bounded above and nonempty,\nthen this set has the greatest element. This lemma uses classical logic to avoid assumption\n`[decidable_pred P]`. See `int.greatest_of_bdd` for a constructive counterpart. -/\ntheorem exists_greatest_of_bdd {P : \u2124 \u2192 Prop}\n  (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 z \u2264 b) (Hinh : \u2203 z : \u2124, P z) :\n  \u2203 ub : \u2124, P ub \u2227 (\u2200 z : \u2124, P z \u2192 z \u2264 ub) :=\nby classical; exact let \u27e8b, Hb\u27e9 := Hbdd, \u27e8lb, H\u27e9 := greatest_of_bdd b Hb Hinh in \u27e8lb, H\u27e9\n\nlemma coe_greatest_of_bdd_eq {P : \u2124 \u2192 Prop} [decidable_pred P]\n  {b b' : \u2124} (Hb : \u2200 z : \u2124, P z \u2192 z \u2264 b) (Hb' : \u2200 z : \u2124, P z \u2192 z \u2264 b') (Hinh : \u2203 z : \u2124, P z) :\n  (greatest_of_bdd b Hb Hinh : \u2124) = greatest_of_bdd b' Hb' Hinh :=\nbegin\n  rcases greatest_of_bdd b Hb Hinh with \u27e8n, hn, h2n\u27e9,\n  rcases greatest_of_bdd b' Hb' Hinh with \u27e8n', hn', h2n'\u27e9,\n  exact le_antisymm (h2n' _ hn) (h2n _ hn'),\nend\n\nend int\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/least_greatest.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7207481475881304}}
{"text": "/-\nCopyright (c) 2020 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Devon Tuma\n-/\nimport ring_theory.ideal.quotient\nimport ring_theory.polynomial.basic\n\n/-!\n# Jacobson radical\n\nThe Jacobson radical of a ring `R` is defined to be the intersection of all maximal ideals of `R`.\nThis is similar to how the nilradical is equal to the intersection of all prime ideals of `R`.\n\nWe can extend the idea of the nilradical to ideals of `R`,\nby letting the radical of an ideal `I` be the intersection of prime ideals containing `I`.\nUnder this extension, the original nilradical is the radical of the zero ideal `\u22a5`.\nHere we define the Jacobson radical of an ideal `I` in a similar way,\nas the intersection of maximal ideals containing `I`.\n\n## Main definitions\n\nLet `R` be a commutative ring, and `I` be an ideal of `R`\n\n* `jacobson I` is the jacobson radical, i.e. the infimum of all maximal ideals containing I.\n\n* `is_local I` is the proposition that the jacobson radical of `I` is itself a maximal ideal\n\n## Main statements\n\n* `mem_jacobson_iff` gives a characterization of members of the jacobson of I\n\n* `is_local_of_is_maximal_radical`: if the radical of I is maximal then so is the jacobson radical\n\n## Tags\n\nJacobson, Jacobson radical, Local Ideal\n\n-/\n\nuniverses u v\n\nnamespace ideal\nvariables {R : Type u} {S : Type v}\nopen_locale polynomial\n\nsection jacobson\n\nsection ring\nvariables [ring R] [ring S] {I : ideal R}\n\n/-- The Jacobson radical of `I` is the infimum of all maximal (left) ideals containing `I`. -/\ndef jacobson (I : ideal R) : ideal R :=\nInf {J : ideal R | I \u2264 J \u2227 is_maximal J}\n\nlemma le_jacobson : I \u2264 jacobson I :=\n\u03bb x hx, mem_Inf.mpr (\u03bb J hJ, hJ.left hx)\n\n@[simp] lemma jacobson_idem : jacobson (jacobson I) = jacobson I :=\nle_antisymm (Inf_le_Inf (\u03bb J hJ, \u27e8Inf_le hJ, hJ.2\u27e9)) le_jacobson\n\n@[simp] lemma jacobson_top : jacobson (\u22a4 : ideal R) = \u22a4 :=\neq_top_iff.2 le_jacobson\n\n@[simp] theorem jacobson_eq_top_iff : jacobson I = \u22a4 \u2194 I = \u22a4 :=\n\u27e8\u03bb H, classical.by_contradiction $ \u03bb hi, let \u27e8M, hm, him\u27e9 := exists_le_maximal I hi in\n  lt_top_iff_ne_top.1\n    (lt_of_le_of_lt (show jacobson I \u2264 M, from Inf_le \u27e8him, hm\u27e9) $\n      lt_top_iff_ne_top.2 hm.ne_top) H,\n\u03bb H, eq_top_iff.2 $ le_Inf $ \u03bb J \u27e8hij, hj\u27e9, H \u25b8 hij\u27e9\n\nlemma jacobson_eq_bot : jacobson I = \u22a5 \u2192 I = \u22a5 :=\n\u03bb h, eq_bot_iff.mpr (h \u25b8 le_jacobson)\n\nlemma jacobson_eq_self_of_is_maximal [H : is_maximal I] : I.jacobson = I :=\nle_antisymm (Inf_le \u27e8le_of_eq rfl, H\u27e9) le_jacobson\n\n@[priority 100]\ninstance jacobson.is_maximal [H : is_maximal I] : is_maximal (jacobson I) :=\n\u27e8\u27e8\u03bb htop, H.1.1 (jacobson_eq_top_iff.1 htop),\n  \u03bb J hJ, H.1.2 _ (lt_of_le_of_lt le_jacobson hJ)\u27e9\u27e9\n\ntheorem mem_jacobson_iff {x : R} : x \u2208 jacobson I \u2194 \u2200 y, \u2203 z, z * y * x + z - 1 \u2208 I :=\n\u27e8\u03bb hx y, classical.by_cases\n  (assume hxy : I \u2294 span {y * x + 1} = \u22a4,\n    let \u27e8p, hpi, q, hq, hpq\u27e9 := submodule.mem_sup.1 ((eq_top_iff_one _).1 hxy) in\n    let \u27e8r, hr\u27e9 := mem_span_singleton'.1 hq in\n    \u27e8r, by rw [mul_assoc, \u2190mul_add_one, hr, \u2190 hpq, \u2190 neg_sub, add_sub_cancel]; exact I.neg_mem hpi\u27e9)\n  (assume hxy : I \u2294 span {y * x + 1} \u2260 \u22a4,\n    let \u27e8M, hm1, hm2\u27e9 := exists_le_maximal _ hxy in\n    suffices x \u2209 M, from (this $ mem_Inf.1 hx \u27e8le_trans le_sup_left hm2, hm1\u27e9).elim,\n    \u03bb hxm, hm1.1.1 $ (eq_top_iff_one _).2 $ add_sub_cancel' (y * x) 1 \u25b8 M.sub_mem\n      (le_sup_right.trans hm2 $ subset_span rfl)\n      (M.mul_mem_left _ hxm)),\n\u03bb hx, mem_Inf.2 $ \u03bb M \u27e8him, hm\u27e9, classical.by_contradiction $ \u03bb hxm,\n  let \u27e8y, i, hi, df\u27e9 := hm.exists_inv hxm, \u27e8z, hz\u27e9 := hx (-y) in\n  hm.1.1 $ (eq_top_iff_one _).2 $ sub_sub_cancel (z * -y * x + z) 1 \u25b8 M.sub_mem\n    (by { rw [mul_assoc, \u2190mul_add_one, neg_mul, \u2190 (sub_eq_iff_eq_add.mpr df.symm), neg_sub,\n            sub_add_cancel],\n          exact M.mul_mem_left _ hi }) (him hz)\u27e9\n\nlemma exists_mul_sub_mem_of_sub_one_mem_jacobson {I : ideal R} (r : R)\n  (h : r - 1 \u2208 jacobson I) : \u2203 s, s * r - 1 \u2208 I :=\nbegin\n  cases mem_jacobson_iff.1 h 1 with s hs,\n  use s,\n  simpa [mul_sub] using hs\nend\n\n/-- An ideal equals its Jacobson radical iff it is the intersection of a set of maximal ideals.\nAllowing the set to include \u22a4 is equivalent, and is included only to simplify some proofs. -/\ntheorem eq_jacobson_iff_Inf_maximal :\n  I.jacobson = I \u2194 \u2203 M : set (ideal R), (\u2200 J \u2208 M, is_maximal J \u2228 J = \u22a4) \u2227 I = Inf M :=\nbegin\n  use \u03bb hI, \u27e8{J : ideal R | I \u2264 J \u2227 J.is_maximal}, \u27e8\u03bb _ hJ, or.inl hJ.right, hI.symm\u27e9\u27e9,\n  rintros \u27e8M, hM, hInf\u27e9,\n  refine le_antisymm (\u03bb x hx, _) le_jacobson,\n  rw [hInf, mem_Inf],\n  intros I hI,\n  cases hM I hI with is_max is_top,\n  { exact (mem_Inf.1 hx) \u27e8le_Inf_iff.1 (le_of_eq hInf) I hI, is_max\u27e9 },\n  { exact is_top.symm \u25b8 submodule.mem_top }\nend\n\ntheorem eq_jacobson_iff_Inf_maximal' :\n  I.jacobson = I \u2194 \u2203 M : set (ideal R), (\u2200 (J \u2208 M) (K : ideal R), J < K \u2192 K = \u22a4) \u2227 I = Inf M :=\neq_jacobson_iff_Inf_maximal.trans\n  \u27e8\u03bb h, let \u27e8M, hM\u27e9 := h in \u27e8M, \u27e8\u03bb J hJ K hK, or.rec_on (hM.1 J hJ) (\u03bb h, h.1.2 K hK)\n    (\u03bb h, eq_top_iff.2 (le_of_lt (h \u25b8 hK))), hM.2\u27e9\u27e9,\n  \u03bb h, let \u27e8M, hM\u27e9 := h in \u27e8M, \u27e8\u03bb J hJ, or.rec_on (classical.em (J = \u22a4)) (\u03bb h, or.inr h)\n    (\u03bb h, or.inl \u27e8\u27e8h, hM.1 J hJ\u27e9\u27e9), hM.2\u27e9\u27e9\u27e9\n\n/-- An ideal `I` equals its Jacobson radical if and only if every element outside `I`\nalso lies outside of a maximal ideal containing `I`. -/\nlemma eq_jacobson_iff_not_mem :\n  I.jacobson = I \u2194 \u2200 x \u2209 I, \u2203 M : ideal R, (I \u2264 M \u2227 M.is_maximal) \u2227 x \u2209 M :=\nbegin\n  split,\n  { intros h x hx,\n    erw [\u2190 h, mem_Inf] at hx,\n    push_neg at hx,\n    exact hx },\n  { refine \u03bb h, le_antisymm (\u03bb x hx, _) le_jacobson,\n    contrapose hx,\n    erw mem_Inf,\n    push_neg,\n    exact h x hx }\nend\n\ntheorem map_jacobson_of_surjective {f : R \u2192+* S} (hf : function.surjective f) :\n  ring_hom.ker f \u2264 I \u2192 map f (I.jacobson) = (map f I).jacobson :=\nbegin\n  intro h,\n  unfold ideal.jacobson,\n  have : \u2200 J \u2208 {J : ideal R | I \u2264 J \u2227 J.is_maximal}, f.ker \u2264 J := \u03bb J hJ, le_trans h hJ.left,\n  refine trans (map_Inf hf this) (le_antisymm _ _),\n  { refine Inf_le_Inf (\u03bb J hJ, \u27e8comap f J, \u27e8\u27e8le_comap_of_map_le hJ.1, _\u27e9,\n    map_comap_of_surjective f hf J\u27e9\u27e9),\n    haveI : J.is_maximal := hJ.right,\n    exact comap_is_maximal_of_surjective f hf },\n  { refine Inf_le_Inf_of_subset_insert_top (\u03bb j hj, hj.rec_on (\u03bb J hJ, _)),\n    rw \u2190 hJ.2,\n    cases map_eq_top_or_is_maximal_of_surjective f hf hJ.left.right with htop hmax,\n    { exact htop.symm \u25b8 set.mem_insert \u22a4 _ },\n    { exact set.mem_insert_of_mem \u22a4 \u27e8map_mono hJ.1.1, hmax\u27e9 } },\nend\n\nlemma map_jacobson_of_bijective {f : R \u2192+* S} (hf : function.bijective f) :\n  map f (I.jacobson) = (map f I).jacobson :=\nmap_jacobson_of_surjective hf.right\n  (le_trans (le_of_eq (f.injective_iff_ker_eq_bot.1 hf.left)) bot_le)\n\nlemma comap_jacobson {f : R \u2192+* S} {K : ideal S} :\n  comap f (K.jacobson) = Inf (comap f '' {J : ideal S | K \u2264 J \u2227 J.is_maximal}) :=\ntrans (comap_Inf' f _) (Inf_eq_infi).symm\n\ntheorem comap_jacobson_of_surjective {f : R \u2192+* S} (hf : function.surjective f) {K : ideal S} :\n  comap f (K.jacobson) = (comap f K).jacobson :=\nbegin\n  unfold ideal.jacobson,\n  refine le_antisymm _ _,\n  { refine le_trans (comap_mono (le_of_eq (trans top_inf_eq.symm Inf_insert.symm))) _,\n    rw [comap_Inf', Inf_eq_infi],\n    refine infi_le_infi_of_subset (\u03bb J hJ, _),\n    have : comap f (map f J) = J := trans (comap_map_of_surjective f hf J)\n      (le_antisymm (sup_le_iff.2 \u27e8le_of_eq rfl, le_trans (comap_mono bot_le) hJ.left\u27e9) le_sup_left),\n    cases map_eq_top_or_is_maximal_of_surjective _ hf hJ.right with htop hmax,\n    { refine \u27e8\u22a4, \u27e8set.mem_insert \u22a4 _, htop \u25b8 this\u27e9\u27e9 },\n    { refine \u27e8map f J, \u27e8set.mem_insert_of_mem _\n        \u27e8le_map_of_comap_le_of_surjective f hf hJ.1, hmax\u27e9, this\u27e9\u27e9 } },\n  { rw comap_Inf,\n    refine le_infi_iff.2 (\u03bb J, (le_infi_iff.2 (\u03bb hJ, _))),\n    haveI : J.is_maximal := hJ.right,\n    refine Inf_le \u27e8comap_mono hJ.left, comap_is_maximal_of_surjective _ hf\u27e9 }\nend\n\n@[mono] lemma jacobson_mono {I J : ideal R} : I \u2264 J \u2192 I.jacobson \u2264 J.jacobson :=\nbegin\n  intros h x hx,\n  erw mem_Inf at \u22a2 hx,\n  exact \u03bb K \u27e8hK, hK_max\u27e9, hx \u27e8trans h hK, hK_max\u27e9\nend\n\nend ring\n\nsection comm_ring\nvariables [comm_ring R] [comm_ring S] {I : ideal R}\n\nlemma radical_le_jacobson : radical I \u2264 jacobson I :=\nle_Inf (\u03bb J hJ, (radical_eq_Inf I).symm \u25b8 Inf_le \u27e8hJ.left, is_maximal.is_prime hJ.right\u27e9)\n\nlemma eq_radical_of_eq_jacobson : jacobson I = I \u2192 radical I = I :=\n\u03bb h, le_antisymm (le_trans radical_le_jacobson (le_of_eq h)) le_radical\n\nlemma is_unit_of_sub_one_mem_jacobson_bot (r : R)\n  (h : r - 1 \u2208 jacobson (\u22a5 : ideal R)) : is_unit r :=\nbegin\n  cases exists_mul_sub_mem_of_sub_one_mem_jacobson r h with s hs,\n  rw [mem_bot, sub_eq_zero, mul_comm] at hs,\n  exact is_unit_of_mul_eq_one _ _ hs\nend\n\nlemma mem_jacobson_bot {x : R} : x \u2208 jacobson (\u22a5 : ideal R) \u2194 \u2200 y, is_unit (x * y + 1) :=\n\u27e8\u03bb hx y, let \u27e8z, hz\u27e9 := (mem_jacobson_iff.1 hx) y in\n  is_unit_iff_exists_inv.2 \u27e8z, by rwa [add_mul, one_mul, \u2190 sub_eq_zero, mul_right_comm,\n    mul_comm _ z, mul_right_comm]\u27e9,\n\u03bb h, mem_jacobson_iff.mpr (\u03bb y, (let \u27e8b, hb\u27e9 := is_unit_iff_exists_inv.1 (h y) in\n  \u27e8b, (submodule.mem_bot R).2 (hb \u25b8 (by ring))\u27e9))\u27e9\n\n/-- An ideal `I` of `R` is equal to its Jacobson radical if and only if\nthe Jacobson radical of the quotient ring `R/I` is the zero ideal -/\ntheorem jacobson_eq_iff_jacobson_quotient_eq_bot :\n  I.jacobson = I \u2194 jacobson (\u22a5 : ideal (R \u29f8 I)) = \u22a5 :=\nbegin\n  have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I,\n  split,\n  { intro h,\n    replace h := congr_arg (map (quotient.mk I)) h,\n    rw map_jacobson_of_surjective hf (le_of_eq mk_ker) at h,\n    simpa using h },\n  { intro h,\n    replace h := congr_arg (comap (quotient.mk I)) h,\n    rw [comap_jacobson_of_surjective hf, \u2190 (quotient.mk I).ker_eq_comap_bot] at h,\n    simpa using h }\nend\n\n/-- The standard radical and Jacobson radical of an ideal `I` of `R` are equal if and only if\nthe nilradical and Jacobson radical of the quotient ring `R/I` coincide -/\ntheorem radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot :\n  I.radical = I.jacobson \u2194 radical (\u22a5 : ideal (R \u29f8 I)) = jacobson \u22a5 :=\nbegin\n  have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I,\n  split,\n  { intro h,\n    have := congr_arg (map (quotient.mk I)) h,\n    rw [map_radical_of_surjective hf (le_of_eq mk_ker),\n      map_jacobson_of_surjective hf (le_of_eq mk_ker)] at this,\n    simpa using this },\n  { intro h,\n    have := congr_arg (comap (quotient.mk I)) h,\n    rw [comap_radical, comap_jacobson_of_surjective hf, \u2190 (quotient.mk I).ker_eq_comap_bot] at this,\n    simpa using this }\nend\n\nlemma jacobson_radical_eq_jacobson :\n  I.radical.jacobson = I.jacobson :=\nle_antisymm (le_trans (le_of_eq (congr_arg jacobson (radical_eq_Inf I)))\n  (Inf_le_Inf (\u03bb J hJ, \u27e8Inf_le \u27e8hJ.1, hJ.2.is_prime\u27e9, hJ.2\u27e9))) (jacobson_mono le_radical)\n\nend comm_ring\n\nend jacobson\n\nsection polynomial\nopen polynomial\n\nvariables [comm_ring R]\n\nlemma jacobson_bot_polynomial_le_Inf_map_maximal :\n  jacobson (\u22a5 : ideal R[X]) \u2264 Inf (map (C : R \u2192+* R[X]) '' {J : ideal R | J.is_maximal}) :=\nbegin\n  refine le_Inf (\u03bb J, exists_imp_distrib.2 (\u03bb j hj, _)),\n  haveI : j.is_maximal := hj.1,\n  refine trans (jacobson_mono bot_le) (le_of_eq _ : J.jacobson \u2264 J),\n  suffices : (\u22a5 : ideal (polynomial (R \u29f8 j))).jacobson = \u22a5,\n  { rw [\u2190 hj.2, jacobson_eq_iff_jacobson_quotient_eq_bot],\n    replace this :=\n    congr_arg (map (polynomial_quotient_equiv_quotient_polynomial j).to_ring_hom) this,\n    rwa [map_jacobson_of_bijective _, map_bot] at this,\n    exact (ring_equiv.bijective (polynomial_quotient_equiv_quotient_polynomial j)) },\n  refine eq_bot_iff.2 (\u03bb f hf, _),\n  simpa [(\u03bb hX, by simpa using congr_arg (\u03bb f, coeff f 1) hX : (X : (R \u29f8 j)[X]) \u2260 0)]\n    using eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit ((mem_jacobson_bot.1 hf) X)),\nend\n\nlemma jacobson_bot_polynomial_of_jacobson_bot (h : jacobson (\u22a5 : ideal R) = \u22a5) :\n  jacobson (\u22a5 : ideal R[X]) = \u22a5 :=\nbegin\n  refine eq_bot_iff.2 (le_trans jacobson_bot_polynomial_le_Inf_map_maximal _),\n  refine (\u03bb f hf, ((submodule.mem_bot _).2 (polynomial.ext (\u03bb n, trans _ (coeff_zero n).symm)))),\n  suffices : f.coeff n \u2208 ideal.jacobson \u22a5, by rwa [h, submodule.mem_bot] at this,\n  exact mem_Inf.2 (\u03bb j hj, (mem_map_C_iff.1 ((mem_Inf.1 hf) \u27e8j, \u27e8hj.2, rfl\u27e9\u27e9)) n),\nend\n\nend polynomial\n\nsection is_local\n\nvariables [comm_ring R]\n\n/-- An ideal `I` is local iff its Jacobson radical is maximal. -/\nclass is_local (I : ideal R) : Prop := (out : is_maximal (jacobson I))\n\ntheorem is_local_iff {I : ideal R} : is_local I \u2194 is_maximal (jacobson I) :=\n\u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\ntheorem is_local_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) : is_local I :=\n\u27e8have radical I = jacobson I,\nfrom le_antisymm (le_Inf $ \u03bb M \u27e8him, hm\u27e9, hm.is_prime.radical_le_iff.2 him)\n  (Inf_le \u27e8le_radical, hi\u27e9),\nshow is_maximal (jacobson I), from this \u25b8 hi\u27e9\n\ntheorem is_local.le_jacobson {I J : ideal R} (hi : is_local I) (hij : I \u2264 J) (hj : J \u2260 \u22a4) :\n  J \u2264 jacobson I :=\nlet \u27e8M, hm, hjm\u27e9 := exists_le_maximal J hj in\nle_trans hjm $ le_of_eq $ eq.symm $ hi.1.eq_of_le hm.1.1 $ Inf_le \u27e8le_trans hij hjm, hm\u27e9\n\ntheorem is_local.mem_jacobson_or_exists_inv {I : ideal R} (hi : is_local I) (x : R) :\n  x \u2208 jacobson I \u2228 \u2203 y, y * x - 1 \u2208 I :=\nclassical.by_cases\n  (assume h : I \u2294 span {x} = \u22a4,\n    let \u27e8p, hpi, q, hq, hpq\u27e9 := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in\n    let \u27e8r, hr\u27e9 := mem_span_singleton.1 hq in\n    or.inr \u27e8r, by rw [\u2190 hpq, mul_comm, \u2190 hr, \u2190 neg_sub, add_sub_cancel]; exact I.neg_mem hpi\u27e9)\n  (assume h : I \u2294 span {x} \u2260 \u22a4,\n    or.inl $ le_trans le_sup_right (hi.le_jacobson le_sup_left h) $ mem_span_singleton.2 $\n      dvd_refl x)\n\nend is_local\n\ntheorem is_primary_of_is_maximal_radical [comm_ring R] {I : ideal R} (hi : is_maximal (radical I)) :\n  is_primary I :=\nhave radical I = jacobson I,\nfrom le_antisymm (le_Inf $ \u03bb M \u27e8him, hm\u27e9, hm.is_prime.radical_le_iff.2 him)\n  (Inf_le \u27e8le_radical, hi\u27e9),\n\u27e8ne_top_of_lt $ lt_of_le_of_lt le_radical (lt_top_iff_ne_top.2 hi.1.1),\n\u03bb x y hxy, ((is_local_of_is_maximal_radical hi).mem_jacobson_or_exists_inv y).symm.imp\n  (\u03bb \u27e8z, hz\u27e9, by rw [\u2190 mul_one x, \u2190 sub_sub_cancel (z * y) 1, mul_sub, mul_left_comm]; exact\n    I.sub_mem (I.mul_mem_left _ hxy) (I.mul_mem_left _ hz))\n  (this \u25b8 id)\u27e9\n\n\nend ideal\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/ring_theory/jacobson_ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7207481460198566}}
{"text": "/-\nCopyright (c) 2019 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou, S\u00e9bastien Gou\u00ebzel, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport algebra.direct_sum.module\nimport analysis.complex.basic\nimport analysis.normed_space.bounded_linear_maps\nimport linear_algebra.bilinear_form\nimport linear_algebra.sesquilinear_form\n\n/-!\n# Inner product space\n\nThis file defines inner product spaces and proves the basic properties.  We do not formally\ndefine Hilbert spaces, but they can be obtained using the pair of assumptions\n`[inner_product_space E] [complete_space E]`.\n\nAn inner product space is a vector space endowed with an inner product. It generalizes the notion of\ndot product in `\u211d^n` and provides the means of defining the length of a vector and the angle between\ntwo vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero.\nWe define both the real and complex cases at the same time using the `is_R_or_C` typeclass.\n\nThis file proves general results on inner product spaces. For the specific construction of an inner\nproduct structure on `n \u2192 \ud835\udd5c` for `\ud835\udd5c = \u211d` or `\u2102`, see `euclidean_space` in\n`analysis.inner_product_space.pi_L2`.\n\n## Main results\n\n- We define the class `inner_product_space \ud835\udd5c E` extending `normed_space \ud835\udd5c E` with a number of basic\n  properties, most notably the Cauchy-Schwarz inequality. Here `\ud835\udd5c` is understood to be either `\u211d`\n  or `\u2102`, through the `is_R_or_C` typeclass.\n- We show that the inner product is continuous, `continuous_inner`.\n- We define `orthonormal`, a predicate on a function `v : \u03b9 \u2192 E`, and prove the existence of a\n  maximal orthonormal set, `exists_maximal_orthonormal`.  Bessel's inequality,\n  `orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`,\n  the sum of the norm-squares of the inner products `\u27eav i, x\u27eb` is no more than the norm-square of\n  `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file\n  `analysis.inner_product_space.projection`.\n- The `orthogonal_complement` of a submodule `K` is defined, and basic API established.  Some of\n  the more subtle results about the orthogonal complement are delayed to\n  `analysis.inner_product_space.projection`.\n\n## Notation\n\nWe globally denote the real and complex inner products by `\u27ea\u00b7, \u00b7\u27eb_\u211d` and `\u27ea\u00b7, \u00b7\u27eb_\u2102` respectively.\nWe also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,\nwhich respectively introduce the plain notation `\u27ea\u00b7, \u00b7\u27eb` for the real and complex inner product.\n\nThe orthogonal complement of a submodule `K` is denoted by `K\u15ee`.\n\n## Implementation notes\n\nWe choose the convention that inner products are conjugate linear in the first argument and linear\nin the second.\n\n## Tags\n\ninner product space, Hilbert space, norm\n\n## References\n*  [Cl\u00e9ment & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]\n*  [Cl\u00e9ment & Martin, *A Coq formal proof of the Lax\u2013Milgram theorem*]\n\nThe Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>\n-/\n\nnoncomputable theory\n\nopen is_R_or_C real filter\nopen_locale big_operators classical topological_space complex_conjugate\n\nvariables {\ud835\udd5c E F : Type*} [is_R_or_C \ud835\udd5c]\n\n/-- Syntactic typeclass for types endowed with an inner product -/\nclass has_inner (\ud835\udd5c E : Type*) := (inner : E \u2192 E \u2192 \ud835\udd5c)\n\nexport has_inner (inner)\n\nnotation `\u27ea`x`, `y`\u27eb_\u211d` := @inner \u211d _ _ x y\nnotation `\u27ea`x`, `y`\u27eb_\u2102` := @inner \u2102 _ _ x y\n\nsection notations\n\nlocalized \"notation `\u27ea`x`, `y`\u27eb` := @inner \u211d _ _ x y\" in real_inner_product_space\nlocalized \"notation `\u27ea`x`, `y`\u27eb` := @inner \u2102 _ _ x y\" in complex_inner_product_space\n\nend notations\n\n/--\nAn inner product space is a vector space with an additional operation called inner product.\nThe norm could be derived from the inner product, instead we require the existence of a norm and\nthe fact that `\u2225x\u2225^2 = re \u27eax, x\u27eb` to be able to put instances on `\ud835\udd42` or product\nspaces.\n\nTo construct a norm from an inner product, see `inner_product_space.of_core`.\n-/\nclass inner_product_space (\ud835\udd5c : Type*) (E : Type*) [is_R_or_C \ud835\udd5c]\n  extends normed_group E, normed_space \ud835\udd5c E, has_inner \ud835\udd5c E :=\n(norm_sq_eq_inner : \u2200 (x : E), \u2225x\u2225^2 = re (inner x x))\n(conj_sym  : \u2200 x y, conj (inner y x) = inner x y)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\nattribute [nolint dangerous_instance] inner_product_space.to_normed_group\n-- note [is_R_or_C instance]\n\n/-!\n### Constructing a normed space structure from an inner product\n\nIn the definition of an inner product space, we require the existence of a norm, which is equal\n(but maybe not defeq) to the square root of the scalar product. This makes it possible to put\nan inner product space structure on spaces with a preexisting norm (for instance `\u211d`), with good\nproperties. However, sometimes, one would like to define the norm starting only from a well-behaved\nscalar product. This is what we implement in this paragraph, starting from a structure\n`inner_product_space.core` stating that we have a nice scalar product.\n\nOur goal here is not to develop a whole theory with all the supporting API, as this will be done\nbelow for `inner_product_space`. Instead, we implement the bare minimum to go as directly as\npossible to the construction of the norm and the proof of the triangular inequality.\n\nWarning: Do not use this `core` structure if the space you are interested in already has a norm\ninstance defined on it, otherwise this will create a second non-defeq norm instance!\n-/\n\n/-- A structure requiring that a scalar product is positive definite and symmetric, from which one\ncan construct an `inner_product_space` instance in `inner_product_space.of_core`. -/\n@[nolint has_inhabited_instance]\nstructure inner_product_space.core\n  (\ud835\udd5c : Type*) (F : Type*)\n  [is_R_or_C \ud835\udd5c] [add_comm_group F] [module \ud835\udd5c F] :=\n(inner     : F \u2192 F \u2192 \ud835\udd5c)\n(conj_sym  : \u2200 x y, conj (inner y x) = inner x y)\n(nonneg_re : \u2200 x, 0 \u2264 re (inner x x))\n(definite  : \u2200 x, inner x x = 0 \u2192 x = 0)\n(add_left  : \u2200 x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : \u2200 x y r, inner (r \u2022 x) y = (conj r) * inner x y)\n\n/- We set `inner_product_space.core` to be a class as we will use it as such in the construction\nof the normed space structure that it produces. However, all the instances we will use will be\nlocal to this proof. -/\nattribute [class] inner_product_space.core\n\nnamespace inner_product_space.of_core\n\nvariables [add_comm_group F] [module \ud835\udd5c F] [c : inner_product_space.core \ud835\udd5c F]\ninclude c\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c F _ x y\nlocal notation `norm_sqK` := @is_R_or_C.norm_sq \ud835\udd5c _\nlocal notation `reK` := @is_R_or_C.re \ud835\udd5c _\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal notation `ext_iff` := @is_R_or_C.ext_iff \ud835\udd5c _\nlocal postfix `\u2020`:90 := star_ring_aut\n\n/-- Inner product defined by the `inner_product_space.core` structure. -/\ndef to_has_inner : has_inner \ud835\udd5c F := { inner := c.inner }\nlocal attribute [instance] to_has_inner\n\n/-- The norm squared function for `inner_product_space.core` structure. -/\ndef norm_sq (x : F) := reK \u27eax, x\u27eb\n\nlocal notation `norm_sqF` := @norm_sq \ud835\udd5c F _ _ _ _\n\nlemma inner_conj_sym (x y : F) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := c.conj_sym x y\n\nlemma inner_self_nonneg {x : F} : 0 \u2264 re \u27eax, x\u27eb := c.nonneg_re _\n\nlemma inner_self_nonneg_im {x : F} : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp [inner_conj_sym]\n\nlemma inner_self_im_zero {x : F} : im \u27eax, x\u27eb = 0 :=\ninner_self_nonneg_im\n\nlemma inner_add_left {x y z : F} : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\nc.add_left _ _ _\n\nlemma inner_add_right {x y z : F} : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby rw [\u2190inner_conj_sym, inner_add_left, ring_equiv.map_add]; simp only [inner_conj_sym]\n\nlemma inner_norm_sq_eq_inner_self (x : F) : (norm_sqF x : \ud835\udd5c) = \u27eax, x\u27eb :=\nbegin\n  rw ext_iff,\n  exact \u27e8by simp only [of_real_re]; refl, by simp only [inner_self_nonneg_im, of_real_im]\u27e9\nend\n\nlemma inner_re_symm {x y : F} : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : F} : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : F} {r : \ud835\udd5c} : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\nc.smul_left _ _ _\n\nlemma inner_smul_right {x y : F} {r : \ud835\udd5c} : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_smul_left]; simp only [conj_conj, inner_conj_sym, ring_equiv.map_mul]\n\nlemma inner_zero_left {x : F} : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190zero_smul \ud835\udd5c (0 : F), inner_smul_left]; simp only [zero_mul, ring_equiv.map_zero]\n\nlemma inner_zero_right {x : F} : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_sym, inner_zero_left]; simp only [ring_equiv.map_zero]\n\nlemma inner_self_eq_zero {x : F} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\niff.intro (c.definite _) (by { rintro rfl, exact inner_zero_left })\n\nlemma inner_self_re_to_K {x : F} : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby norm_num [ext_iff, inner_self_nonneg_im]\n\nlemma inner_abs_conj_sym {x y : F} : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\n  by rw [\u2190inner_conj_sym, abs_conj]\n\nlemma inner_neg_left {x y : F} : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\nlemma inner_neg_right {x y : F} : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_neg_left]; simp only [ring_equiv.map_neg, inner_conj_sym]\n\nlemma inner_sub_left {x y z : F} : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left, inner_neg_left] }\n\nlemma inner_sub_right {x y z : F} : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right, inner_neg_right] }\n\nlemma inner_mul_conj_re_abs {x y : F} : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw [\u2190inner_conj_sym, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `inner (x + y) (x + y)` -/\nlemma inner_add_add_self {x y : F} : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/- Expand `inner (x - y) (x - y)` -/\nlemma inner_sub_sub_self {x y : F} : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/--\n**Cauchy\u2013Schwarz inequality**. This proof follows \"Proof 2\" on Wikipedia.\nWe need this for the `core` structure to prove the triangle inequality below when\nshowing the core is a normed group.\n-/\nlemma inner_mul_inner_self_le (x y : F) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { change y \u2260 0 at hy,\n    have hy' : \u27eay, y\u27eb \u2260 0 := \u03bb h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := by simp only [inner_self_re_to_K],\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw ext_iff,\n      exact \u27e8by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082,\n                      neg_mul_eq_neg_mul_symm, add_monoid_hom.map_add, mul_re,\n                      conj_im, add_monoid_hom.map_sub, mul_neg_eq_neg_mul_symm, conj_re, neg_neg]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by field_simp [-mul_re, inner_conj_sym, hT, ring_equiv.map_div, h\u2081, h\u2083]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw [div_mul_eq_mul_div_comm, \u2190mul_div_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Norm constructed from a `inner_product_space.core` structure, defined to be the square root\nof the scalar product. -/\ndef to_has_norm : has_norm F :=\n{ norm := \u03bb x, sqrt (re \u27eax, x\u27eb) }\n\nlocal attribute [instance] to_has_norm\n\nlemma norm_eq_sqrt_inner (x : F) : \u2225x\u2225 = sqrt (re \u27eax, x\u27eb) := rfl\n\nlemma inner_self_eq_norm_mul_norm (x : F) : re \u27eax, x\u27eb = \u2225x\u2225 * \u2225x\u2225 :=\nby rw [norm_eq_sqrt_inner, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma sqrt_norm_sq_eq_norm {x : F} : sqrt (norm_sqF x) = \u2225x\u2225 := rfl\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : F) : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _))\nbegin\n  have H : \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225) = re \u27eay, y\u27eb * re \u27eax, x\u27eb,\n  { simp only [inner_self_eq_norm_mul_norm], ring, },\n  rw H,\n  conv\n  begin\n    to_lhs, congr, rw [inner_abs_conj_sym],\n  end,\n  exact inner_mul_inner_self_le y x,\nend\n\n/-- Normed group structure constructed from an `inner_product_space.core` structure -/\ndef to_normed_group : normed_group F :=\nnormed_group.of_core F\n{ norm_eq_zero_iff := assume x,\n  begin\n    split,\n    { intro H,\n      change sqrt (re \u27eax, x\u27eb) = 0 at H,\n      rw [sqrt_eq_zero inner_self_nonneg] at H,\n      apply (inner_self_eq_zero : \u27eax, x\u27eb = 0 \u2194 x = 0).mp,\n      rw ext_iff,\n      exact \u27e8by simp [H], by simp [inner_self_im_zero]\u27e9 },\n    { rintro rfl,\n      change sqrt (re \u27ea0, 0\u27eb) = 0,\n      simp only [sqrt_zero, inner_zero_right, add_monoid_hom.map_zero] }\n  end,\n  triangle := assume x y,\n  begin\n    have h\u2081 : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := abs_inner_le_norm _ _,\n    have h\u2082 : re \u27eax, y\u27eb \u2264 abs \u27eax, y\u27eb := re_le_abs _,\n    have h\u2083 : re \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := by linarith,\n    have h\u2084 : re \u27eay, x\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 := by rwa [\u2190inner_conj_sym, conj_re],\n    have : \u2225x + y\u2225 * \u2225x + y\u2225 \u2264 (\u2225x\u2225 + \u2225y\u2225) * (\u2225x\u2225 + \u2225y\u2225),\n    { simp [\u2190inner_self_eq_norm_mul_norm, inner_add_add_self, add_mul, mul_add, mul_comm],\n      linarith },\n    exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this\n  end,\n  norm_neg := \u03bb x, by simp only [norm, inner_neg_left, neg_neg, inner_neg_right] }\n\nlocal attribute [instance] to_normed_group\n\n/-- Normed space structure constructed from a `inner_product_space.core` structure -/\ndef to_normed_space : normed_space \ud835\udd5c F :=\n{ norm_smul_le := assume r x,\n  begin\n    rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, \u2190mul_assoc],\n    rw [conj_mul_eq_norm_sq_left, of_real_mul_re, sqrt_mul, \u2190inner_norm_sq_eq_inner_self,\n        of_real_re],\n    { simp [sqrt_norm_sq_eq_norm, is_R_or_C.sqrt_norm_sq_eq_norm] },\n    { exact norm_sq_nonneg r }\n  end }\n\nend inner_product_space.of_core\n\n/-- Given a `inner_product_space.core` structure on a space, one can use it to turn\nthe space into an inner product space, constructing the norm out of the inner product -/\ndef inner_product_space.of_core [add_comm_group F] [module \ud835\udd5c F]\n  (c : inner_product_space.core \ud835\udd5c F) : inner_product_space \ud835\udd5c F :=\nbegin\n  letI : normed_group F := @inner_product_space.of_core.to_normed_group \ud835\udd5c F _ _ _ c,\n  letI : normed_space \ud835\udd5c F := @inner_product_space.of_core.to_normed_space \ud835\udd5c F _ _ _ c,\n  exact { norm_sq_eq_inner := \u03bb x,\n    begin\n      have h\u2081 : \u2225x\u2225^2 = (sqrt (re (c.inner x x))) ^ 2 := rfl,\n      have h\u2082 : 0 \u2264 re (c.inner x x) := inner_product_space.of_core.inner_self_nonneg,\n      simp [h\u2081, sq_sqrt, h\u2082],\n    end,\n    ..c }\nend\n\n/-! ### Properties of inner product spaces -/\n\nvariables [inner_product_space \ud835\udd5c E] [inner_product_space \u211d F]\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\nlocal notation `IK` := @is_R_or_C.I \ud835\udd5c _\nlocal notation `absR` := has_abs.abs\nlocal notation `absK` := @is_R_or_C.abs \ud835\udd5c _\nlocal postfix `\u2020`:90 := star_ring_aut\n\nexport inner_product_space (norm_sq_eq_inner)\n\nsection basic_properties\n\n@[simp] lemma inner_conj_sym (x y : E) : \u27eay, x\u27eb\u2020 = \u27eax, y\u27eb := inner_product_space.conj_sym _ _\nlemma real_inner_comm (x y : F) : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := @inner_conj_sym \u211d _ _ _ x y\n\nlemma inner_eq_zero_sym {x y : E} : \u27eax, y\u27eb = 0 \u2194 \u27eay, x\u27eb = 0 :=\n\u27e8\u03bb h, by simp [\u2190inner_conj_sym, h], \u03bb h, by simp [\u2190inner_conj_sym, h]\u27e9\n\n@[simp] lemma inner_self_nonneg_im {x : E} : im \u27eax, x\u27eb = 0 :=\nby rw [\u2190 @of_real_inj \ud835\udd5c, im_eq_conj_sub]; simp\n\nlemma inner_self_im_zero {x : E} : im \u27eax, x\u27eb = 0 := inner_self_nonneg_im\n\nlemma inner_add_left {x y z : E} : \u27eax + y, z\u27eb = \u27eax, z\u27eb + \u27eay, z\u27eb :=\ninner_product_space.add_left _ _ _\n\nlemma inner_add_right {x y z : E} : \u27eax, y + z\u27eb = \u27eax, y\u27eb + \u27eax, z\u27eb :=\nby { rw [\u2190inner_conj_sym, inner_add_left, ring_equiv.map_add], simp only [inner_conj_sym] }\n\nlemma inner_re_symm {x y : E} : re \u27eax, y\u27eb = re \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : E} : im \u27eax, y\u27eb = -im \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : E} {r : \ud835\udd5c} : \u27ear \u2022 x, y\u27eb = r\u2020 * \u27eax, y\u27eb :=\ninner_product_space.smul_left _ _ _\nlemma real_inner_smul_left {x y : F} {r : \u211d} : \u27ear \u2022 x, y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d := inner_smul_left\n\nlemma inner_smul_real_left {x y : E} {r : \u211d} : \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_left, conj_of_real, algebra.smul_def], refl }\n\nlemma inner_smul_right {x y : E} {r : \ud835\udd5c} : \u27eax, r \u2022 y\u27eb = r * \u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_smul_left, ring_equiv.map_mul, conj_conj, inner_conj_sym]\nlemma real_inner_smul_right {x y : F} {r : \u211d} : \u27eax, r \u2022 y\u27eb_\u211d = r * \u27eax, y\u27eb_\u211d := inner_smul_right\n\nlemma inner_smul_real_right {x y : E} {r : \u211d} : \u27eax, (r : \ud835\udd5c) \u2022 y\u27eb = r \u2022 \u27eax, y\u27eb :=\nby { rw [inner_smul_right, algebra.smul_def], refl }\n\n/-- The inner product as a sesquilinear form. -/\n@[simps]\ndef sesq_form_of_inner : sesq_form \ud835\udd5c E (conj_to_ring_equiv \ud835\udd5c) :=\n{ sesq := \u03bb x y, \u27eay, x\u27eb,    -- Note that sesquilinear forms are linear in the first argument\n  sesq_add_left := \u03bb x y z, inner_add_right,\n  sesq_add_right := \u03bb x y z, inner_add_left,\n  sesq_smul_left := \u03bb r x y, inner_smul_right,\n  sesq_smul_right := \u03bb r x y, inner_smul_left }\n\n/-- The real inner product as a bilinear form. -/\n@[simps]\ndef bilin_form_of_real_inner : bilin_form \u211d F :=\n{ bilin := inner,\n  bilin_add_left := \u03bb x y z, inner_add_left,\n  bilin_smul_left := \u03bb a x y, inner_smul_left,\n  bilin_add_right := \u03bb x y z, inner_add_right,\n  bilin_smul_right := \u03bb a x y, inner_smul_right }\n\n/-- An inner product with a sum on the left. -/\nlemma sum_inner {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27ea\u2211 i in s, f i, x\u27eb = \u2211 i in s, \u27eaf i, x\u27eb :=\nsesq_form.sum_right (sesq_form_of_inner) _ _ _\n\n/-- An inner product with a sum on the right. -/\nlemma inner_sum {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) :\n  \u27eax, \u2211 i in s, f i\u27eb = \u2211 i in s, \u27eax, f i\u27eb :=\nsesq_form.sum_left (sesq_form_of_inner) _ _ _\n\n/-- An inner product with a sum on the left, `finsupp` version. -/\nlemma finsupp.sum_inner {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eal.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i), x\u27eb\n  = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), (conj a) \u2022 \u27eav i, x\u27eb) :=\nby { convert sum_inner l.support (\u03bb a, l a \u2022 v a) x, simp [inner_smul_left, finsupp.sum] }\n\n/-- An inner product with a sum on the right, `finsupp` version. -/\nlemma finsupp.inner_sum {\u03b9 : Type*} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) :\n  \u27eax, l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 v i)\u27eb = l.sum (\u03bb (i : \u03b9) (a : \ud835\udd5c), a \u2022 \u27eax, v i\u27eb) :=\nby { convert inner_sum l.support (\u03bb a, l a \u2022 v a) x, simp [inner_smul_right, finsupp.sum] }\n\n@[simp] lemma inner_zero_left {x : E} : \u27ea0, x\u27eb = 0 :=\nby rw [\u2190 zero_smul \ud835\udd5c (0:E), inner_smul_left, ring_equiv.map_zero, zero_mul]\n\nlemma inner_re_zero_left {x : E} : re \u27ea0, x\u27eb = 0 :=\nby simp only [inner_zero_left, add_monoid_hom.map_zero]\n\n@[simp] lemma inner_zero_right {x : E} : \u27eax, 0\u27eb = 0 :=\nby rw [\u2190inner_conj_sym, inner_zero_left, ring_equiv.map_zero]\n\nlemma inner_re_zero_right {x : E} : re \u27eax, 0\u27eb = 0 :=\nby simp only [inner_zero_right, add_monoid_hom.map_zero]\n\nlemma inner_self_nonneg {x : E} : 0 \u2264 re \u27eax, x\u27eb :=\nby rw [\u2190norm_sq_eq_inner]; exact pow_nonneg (norm_nonneg x) 2\nlemma real_inner_self_nonneg {x : F} : 0 \u2264 \u27eax, x\u27eb_\u211d := @inner_self_nonneg \u211d F _ _ x\n\n@[simp] lemma inner_self_eq_zero {x : E} : \u27eax, x\u27eb = 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    have h\u2081 : re \u27eax, x\u27eb = 0 := by rw is_R_or_C.ext_iff at h; simp [h.1],\n    rw [\u2190norm_sq_eq_inner x] at h\u2081,\n    rw [\u2190norm_eq_zero],\n    exact pow_eq_zero h\u2081 },\n  { rintro rfl,\n    exact inner_zero_left }\nend\n\n@[simp] lemma inner_self_nonpos {x : E} : re \u27eax, x\u27eb \u2264 0 \u2194 x = 0 :=\nbegin\n  split,\n  { intro h,\n    rw \u2190inner_self_eq_zero,\n    have H\u2081 : re \u27eax, x\u27eb \u2265 0, exact inner_self_nonneg,\n    have H\u2082 : re \u27eax, x\u27eb = 0, exact le_antisymm h H\u2081,\n    rw is_R_or_C.ext_iff,\n    exact \u27e8by simp [H\u2082], by simp [inner_self_nonneg_im]\u27e9 },\n  { rintro rfl,\n    simp only [inner_zero_left, add_monoid_hom.map_zero] }\nend\n\nlemma real_inner_self_nonpos {x : F} : \u27eax, x\u27eb_\u211d \u2264 0 \u2194 x = 0 :=\nby { have h := @inner_self_nonpos \u211d F _ _ x, simpa using h }\n\n@[simp] lemma inner_self_re_to_K {x : E} : (re \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby rw is_R_or_C.ext_iff; exact \u27e8by simp, by simp [inner_self_nonneg_im]\u27e9\n\nlemma inner_self_eq_norm_sq_to_K (x : E) : \u27eax, x\u27eb = (\u2225x\u2225 ^ 2 : \ud835\udd5c) :=\nbegin\n  suffices : (is_R_or_C.re \u27eax, x\u27eb : \ud835\udd5c) = \u2225x\u2225 ^ 2,\n  { simpa [inner_self_re_to_K] using this },\n  exact_mod_cast (norm_sq_eq_inner x).symm\nend\n\nlemma inner_self_re_abs {x : E} : re \u27eax, x\u27eb = abs \u27eax, x\u27eb :=\nbegin\n  conv_rhs { rw [\u2190inner_self_re_to_K] },\n  symmetry,\n  exact is_R_or_C.abs_of_nonneg inner_self_nonneg,\nend\n\nlemma inner_self_abs_to_K {x : E} : (absK \u27eax, x\u27eb : \ud835\udd5c) = \u27eax, x\u27eb :=\nby { rw [\u2190inner_self_re_abs], exact inner_self_re_to_K }\n\nlemma real_inner_self_abs {x : F} : absR \u27eax, x\u27eb_\u211d = \u27eax, x\u27eb_\u211d :=\nby { have h := @inner_self_abs_to_K \u211d F _ _ x, simpa using h }\n\nlemma inner_abs_conj_sym {x y : E} : abs \u27eax, y\u27eb = abs \u27eay, x\u27eb :=\nby rw [\u2190inner_conj_sym, abs_conj]\n\n@[simp] lemma inner_neg_left {x y : E} : \u27ea-x, y\u27eb = -\u27eax, y\u27eb :=\nby { rw [\u2190 neg_one_smul \ud835\udd5c x, inner_smul_left], simp }\n\n@[simp] lemma inner_neg_right {x y : E} : \u27eax, -y\u27eb = -\u27eax, y\u27eb :=\nby rw [\u2190inner_conj_sym, inner_neg_left]; simp only [ring_equiv.map_neg, inner_conj_sym]\n\nlemma inner_neg_neg {x y : E} : \u27ea-x, -y\u27eb = \u27eax, y\u27eb := by simp\n\n@[simp] lemma inner_self_conj {x : E} : \u27eax, x\u27eb\u2020 = \u27eax, x\u27eb :=\nby rw [is_R_or_C.ext_iff]; exact \u27e8by rw [conj_re], by rw [conj_im, inner_self_im_zero, neg_zero]\u27e9\n\nlemma inner_sub_left {x y z : E} : \u27eax - y, z\u27eb = \u27eax, z\u27eb - \u27eay, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_left] }\n\nlemma inner_sub_right {x y z : E} : \u27eax, y - z\u27eb = \u27eax, y\u27eb - \u27eax, z\u27eb :=\nby { simp [sub_eq_add_neg, inner_add_right] }\n\nlemma inner_mul_conj_re_abs {x y : E} : re (\u27eax, y\u27eb * \u27eay, x\u27eb) = abs (\u27eax, y\u27eb * \u27eay, x\u27eb) :=\nby { rw [\u2190inner_conj_sym, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `\u27eax + y, x + y\u27eb` -/\nlemma inner_add_add_self {x y : E} : \u27eax + y, x + y\u27eb = \u27eax, x\u27eb + \u27eax, y\u27eb + \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/-- Expand `\u27eax + y, x + y\u27eb_\u211d` -/\nlemma real_inner_add_add_self {x y : F} : \u27eax + y, x + y\u27eb_\u211d = \u27eax, x\u27eb_\u211d + 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  simp [inner_add_add_self, this],\n  ring,\nend\n\n/- Expand `\u27eax - y, x - y\u27eb` -/\nlemma inner_sub_sub_self {x y : E} : \u27eax - y, x - y\u27eb = \u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/-- Expand `\u27eax - y, x - y\u27eb_\u211d` -/\nlemma real_inner_sub_sub_self {x y : F} : \u27eax - y, x - y\u27eb_\u211d = \u27eax, x\u27eb_\u211d - 2 * \u27eax, y\u27eb_\u211d + \u27eay, y\u27eb_\u211d :=\nbegin\n  have : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  simp [inner_sub_sub_self, this],\n  ring,\nend\n\n/-- Parallelogram law -/\nlemma parallelogram_law {x y : E} :\n  \u27eax + y, x + y\u27eb + \u27eax - y, x - y\u27eb = 2 * (\u27eax, x\u27eb + \u27eay, y\u27eb) :=\nby simp [inner_add_add_self, inner_sub_sub_self, two_mul, sub_eq_add_neg, add_comm, add_left_comm]\n\n/-- Cauchy\u2013Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia. -/\nlemma inner_mul_inner_self_le (x y : E) : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb \u2264 re \u27eax, x\u27eb * re \u27eay, y\u27eb :=\nbegin\n  by_cases hy : y = 0,\n  { rw [hy], simp only [is_R_or_C.abs_zero, inner_zero_left, mul_zero, add_monoid_hom.map_zero] },\n  { change y \u2260 0 at hy,\n    have hy' : \u27eay, y\u27eb \u2260 0 := \u03bb h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := \u27eay, x\u27eb / \u27eay, y\u27eb with hT,\n    have h\u2081 : re \u27eay, x\u27eb = re \u27eax, y\u27eb := inner_re_symm,\n    have h\u2082 : im \u27eay, x\u27eb = -im \u27eax, y\u27eb := inner_im_symm,\n    have h\u2083 : \u27eay, x\u27eb * \u27eax, y\u27eb * \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = \u27eay, x\u27eb * \u27eax, y\u27eb / \u27eay, y\u27eb,\n    { rw [mul_div_assoc],\n      have : \u27eay, y\u27eb / (\u27eay, y\u27eb * \u27eay, y\u27eb) = 1 / \u27eay, y\u27eb :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, \u2190div_eq_mul_inv] },\n    have h\u2084 : \u27eay, y\u27eb = re \u27eay, y\u27eb := by simp,\n    have h\u2085 : re \u27eay, y\u27eb > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw is_R_or_C.ext_iff,\n      exact \u27e8by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]\u27e9 },\n    have h\u2086 : re \u27eay, y\u27eb \u2260 0 := ne_of_gt h\u2085,\n    have hmain := calc\n      0   \u2264 re \u27eax - T \u2022 y, x - T \u2022 y\u27eb\n                  : inner_self_nonneg\n      ... = re \u27eax, x\u27eb - re \u27eaT \u2022 y, x\u27eb - re \u27eax, T \u2022 y\u27eb + re \u27eaT \u2022 y, T \u2022 y\u27eb\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h\u2081, h\u2082,\n                      neg_mul_eq_neg_mul_symm, add_monoid_hom.map_add, conj_im,\n                      add_monoid_hom.map_sub, mul_neg_eq_neg_mul_symm, conj_re, neg_neg, mul_re]\n      ... = re \u27eax, x\u27eb - re (T\u2020 * \u27eay, x\u27eb) - re (T * \u27eax, y\u27eb) + re (T * T\u2020 * \u27eay, y\u27eb)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb / \u27eay, y\u27eb * \u27eay, x\u27eb)\n                  : by field_simp [-mul_re, hT, ring_equiv.map_div, h\u2081, h\u2083, inner_conj_sym]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / \u27eay, y\u27eb)\n                  : by rw [div_mul_eq_mul_div_comm, \u2190mul_div_assoc]\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb / re \u27eay, y\u27eb)\n                  : by conv_lhs { rw [h\u2084] }\n      ... = re \u27eax, x\u27eb - re (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [div_re_of_real]\n      ... = re \u27eax, x\u27eb - abs (\u27eax, y\u27eb * \u27eay, x\u27eb) / re \u27eay, y\u27eb\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re \u27eax, x\u27eb - abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs \u27eax, y\u27eb * abs \u27eay, x\u27eb / re \u27eay, y\u27eb \u2264 re \u27eax, x\u27eb := by linarith,\n    have := (mul_le_mul_right h\u2085).mpr hmain',\n    rwa [div_mul_cancel (abs \u27eax, y\u27eb * abs \u27eay, x\u27eb) h\u2086] at this }\nend\n\n/-- Cauchy\u2013Schwarz inequality for real inner products. -/\nlemma real_inner_mul_inner_self_le (x y : F) : \u27eax, y\u27eb_\u211d * \u27eax, y\u27eb_\u211d \u2264 \u27eax, x\u27eb_\u211d * \u27eay, y\u27eb_\u211d :=\nbegin\n  have h\u2081 : \u27eay, x\u27eb_\u211d = \u27eax, y\u27eb_\u211d := by rw [\u2190inner_conj_sym]; refl,\n  have h\u2082 := @inner_mul_inner_self_le \u211d F _ _ x y,\n  dsimp at h\u2082,\n  have h\u2083 := abs_mul_abs_self \u27eax, y\u27eb_\u211d,\n  rw [h\u2081] at h\u2082,\n  simpa [h\u2083] using h\u2082,\nend\n\n/-- A family of vectors is linearly independent if they are nonzero\nand orthogonal. -/\nlemma linear_independent_of_ne_zero_of_inner_eq_zero {\u03b9 : Type*} {v : \u03b9 \u2192 E}\n  (hz : \u2200 i, v i \u2260 0) (ho : \u2200 i j, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0) : linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff',\n  intros s g hg i hi,\n  have h' : g i * inner (v i) (v i) = inner (v i) (\u2211 j in s, g j \u2022 v j),\n  { rw inner_sum,\n    symmetry,\n    convert finset.sum_eq_single i _ _,\n    { rw inner_smul_right },\n    { intros j hj hji,\n      rw [inner_smul_right, ho i j hji.symm, mul_zero] },\n    { exact \u03bb h, false.elim (h hi) } },\n  simpa [hg, hz] using h'\nend\n\nend basic_properties\n\nsection orthonormal_sets\nvariables {\u03b9 : Type*} (\ud835\udd5c)\n\ninclude \ud835\udd5c\n\n/-- An orthonormal set of vectors in an `inner_product_space` -/\ndef orthonormal (v : \u03b9 \u2192 E) : Prop :=\n(\u2200 i, \u2225v i\u2225 = 1) \u2227 (\u2200 {i j}, i \u2260 j \u2192 \u27eav i, v j\u27eb = 0)\n\nomit \ud835\udd5c\n\nvariables {\ud835\udd5c}\n\n/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal.  (Inner\nproduct equals Kronecker delta.) -/\nlemma orthonormal_iff_ite {v : \u03b9 \u2192 E} :\n  orthonormal \ud835\udd5c v \u2194 \u2200 i j, \u27eav i, v j\u27eb = if i = j then (1:\ud835\udd5c) else (0:\ud835\udd5c) :=\nbegin\n  split,\n  { intros hv i j,\n    split_ifs,\n    { simp [h, inner_self_eq_norm_sq_to_K, hv.1] },\n    { exact hv.2 h } },\n  { intros h,\n    split,\n    { intros i,\n      have h' : \u2225v i\u2225 ^ 2 = 1 ^ 2 := by simp [norm_sq_eq_inner, h i i],\n      have h\u2081 : 0 \u2264 \u2225v i\u2225 := norm_nonneg _,\n      have h\u2082 : (0:\u211d) \u2264 1 := zero_le_one,\n      rwa sq_eq_sq h\u2081 h\u2082 at h' },\n    { intros i j hij,\n      simpa [hij] using h i j } }\nend\n\n/-- `if ... then ... else` characterization of a set of vectors being orthonormal.  (Inner product\nequals Kronecker delta.) -/\ntheorem orthonormal_subtype_iff_ite {s : set E} :\n  orthonormal \ud835\udd5c (coe : s \u2192 E) \u2194\n  (\u2200 v \u2208 s, \u2200 w \u2208 s, \u27eav, w\u27eb = if v = w then 1 else 0) :=\nbegin\n  rw orthonormal_iff_ite,\n  split,\n  { intros h v hv w hw,\n    convert h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9 using 1,\n    simp },\n  { rintros h \u27e8v, hv\u27e9 \u27e8w, hw\u27e9,\n    convert h v hv w hw using 1,\n    simp }\nend\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = l i :=\nby simp [finsupp.total_apply, finsupp.inner_sum, orthonormal_iff_ite.mp hv]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_right_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27eav i, \u2211 i : \u03b9, (l i) \u2022 (v i)\u27eb = l i :=\nby simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_finsupp {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = conj (l i) :=\nby rw [\u2190 inner_conj_sym, hv.inner_right_finsupp]\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\nlemma orthonormal.inner_left_fintype [fintype \u03b9]\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192 \ud835\udd5c) (i : \u03b9) :\n  \u27ea\u2211 i : \u03b9, (l i) \u2022 (v i), v i\u27eb = conj (l i) :=\nby simp [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv]\n\n/--\nThe double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the\nsum of the weights.\n-/\nlemma orthonormal.inner_left_right_finset {s : finset \u03b9}  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v)\n  {a : \u03b9 \u2192 \u03b9 \u2192 \ud835\udd5c} : \u2211 i in s, \u2211 j in s, (a i j) \u2022 \u27eav j, v i\u27eb = \u2211 k in s, a k k :=\nby simp [orthonormal_iff_ite.mp hv, finset.sum_ite_of_true]\n\n/-- An orthonormal set is linearly independent. -/\nlemma orthonormal.linear_independent {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) :\n  linear_independent \ud835\udd5c v :=\nbegin\n  rw linear_independent_iff,\n  intros l hl,\n  ext i,\n  have key : \u27eav i, finsupp.total \u03b9 E \ud835\udd5c v l\u27eb = \u27eav i, 0\u27eb := by rw hl,\n  simpa [hv.inner_right_finsupp] using key\nend\n\n/-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an\northonormal family. -/\nlemma orthonormal.comp\n  {\u03b9' : Type*} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (f : \u03b9' \u2192 \u03b9) (hf : function.injective f) :\n  orthonormal \ud835\udd5c (v \u2218 f) :=\nbegin\n  rw orthonormal_iff_ite at \u22a2 hv,\n  intros i j,\n  convert hv (f i) (f j) using 1,\n  simp [hf.eq_iff]\nend\n\n/-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the\nset. -/\nlemma orthonormal.inner_finsupp_eq_zero\n  {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) {s : set \u03b9} {i : \u03b9} (hi : i \u2209 s) {l : \u03b9 \u2192\u2080 \ud835\udd5c}\n  (hl : l \u2208 finsupp.supported \ud835\udd5c \ud835\udd5c s) :\n  \u27eafinsupp.total \u03b9 E \ud835\udd5c v l, v i\u27eb = 0 :=\nbegin\n  rw finsupp.mem_supported' at hl,\n  simp [hv.inner_left_finsupp, hl i hi],\nend\n\n/- The material that follows, culminating in the existence of a maximal orthonormal subset, is\nadapted from the corresponding development of the theory of linearly independents sets.  See\n`exists_linear_independent` in particular. -/\n\nvariables (\ud835\udd5c E)\nlemma orthonormal_empty : orthonormal \ud835\udd5c (\u03bb x, x : (\u2205 : set E) \u2192 E) :=\nby simp [orthonormal_subtype_iff_ite]\nvariables {\ud835\udd5c E}\n\nlemma orthonormal_Union_of_directed\n  {\u03b7 : Type*} {s : \u03b7 \u2192 set E} (hs : directed (\u2286) s) (h : \u2200 i, orthonormal \ud835\udd5c (\u03bb x, x : s i \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3 i, s i) \u2192 E) :=\nbegin\n  rw orthonormal_subtype_iff_ite,\n  rintros x \u27e8_, \u27e8i, rfl\u27e9, hxi\u27e9 y \u27e8_, \u27e8j, rfl\u27e9, hyj\u27e9,\n  obtain \u27e8k, hik, hjk\u27e9 := hs i j,\n  have h_orth : orthonormal \ud835\udd5c (\u03bb x, x : (s k) \u2192 E) := h k,\n  rw orthonormal_subtype_iff_ite at h_orth,\n  exact h_orth x (hik hxi) y (hjk hyj)\nend\n\nlemma orthonormal_sUnion_of_directed\n  {s : set (set E)} (hs : directed_on (\u2286) s)\n  (h : \u2200 a \u2208 s, orthonormal \ud835\udd5c (\u03bb x, x : (a : set E) \u2192 E)) :\n  orthonormal \ud835\udd5c (\u03bb x, x : (\u22c3\u2080 s) \u2192 E) :=\nby rw set.sUnion_eq_Union; exact orthonormal_Union_of_directed hs.directed_coe (by simpa using h)\n\n/-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set\ncontaining it. -/\nlemma exists_maximal_orthonormal {s : set E} (hs : orthonormal \ud835\udd5c (coe : s \u2192 E)) :\n  \u2203 w \u2287 s, orthonormal \ud835\udd5c (coe : w \u2192 E) \u2227 \u2200 u \u2287 w, orthonormal \ud835\udd5c (coe : u \u2192 E) \u2192 u = w :=\nbegin\n  rcases zorn.zorn_subset_nonempty {b | orthonormal \ud835\udd5c (coe : b \u2192 E)} _ _ hs  with \u27e8b, bi, sb, h\u27e9,\n  { refine \u27e8b, sb, bi, _\u27e9,\n    exact \u03bb u hus hu, h u hu hus },\n  { refine \u03bb c hc cc c0, \u27e8\u22c3\u2080 c, _, _\u27e9,\n    { exact orthonormal_sUnion_of_directed cc.directed_on (\u03bb x xc, hc xc) },\n    { exact \u03bb _, set.subset_sUnion_of_mem } }\nend\n\nlemma orthonormal.ne_zero {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (i : \u03b9) : v i \u2260 0 :=\nbegin\n  have : \u2225v i\u2225 \u2260 0,\n  { rw hv.1 i,\n    norm_num },\n  simpa using this\nend\n\nopen finite_dimensional\n\n/-- A family of orthonormal vectors with the correct cardinality forms a basis. -/\ndef basis_of_orthonormal_of_card_eq_finrank [fintype \u03b9] [nonempty \u03b9] {v : \u03b9 \u2192 E}\n  (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finrank \ud835\udd5c E) :\n  basis \u03b9 \ud835\udd5c E :=\nbasis_of_linear_independent_of_card_eq_finrank hv.linear_independent card_eq\n\n@[simp] lemma coe_basis_of_orthonormal_of_card_eq_finrank [fintype \u03b9] [nonempty \u03b9] {v : \u03b9 \u2192 E}\n  (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finrank \ud835\udd5c E) :\n  (basis_of_orthonormal_of_card_eq_finrank hv card_eq : \u03b9 \u2192 E) = v :=\ncoe_basis_of_linear_independent_of_card_eq_finrank _ _\n\nend orthonormal_sets\n\nsection norm\n\nlemma norm_eq_sqrt_inner (x : E) : \u2225x\u2225 = sqrt (re \u27eax, x\u27eb) :=\nbegin\n  have h\u2081 : \u2225x\u2225^2 = re \u27eax, x\u27eb := norm_sq_eq_inner x,\n  have h\u2082 := congr_arg sqrt h\u2081,\n  simpa using h\u2082,\nend\n\nlemma norm_eq_sqrt_real_inner (x : F) : \u2225x\u2225 = sqrt \u27eax, x\u27eb_\u211d :=\nby { have h := @norm_eq_sqrt_inner \u211d F _ _ x, simpa using h }\n\nlemma inner_self_eq_norm_mul_norm (x : E) : re \u27eax, x\u27eb = \u2225x\u2225 * \u2225x\u2225 :=\nby rw [norm_eq_sqrt_inner, \u2190sqrt_mul inner_self_nonneg (re \u27eax, x\u27eb),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma inner_self_eq_norm_sq (x : E) : re \u27eax, x\u27eb = \u2225x\u2225^2 :=\nby rw [pow_two, inner_self_eq_norm_mul_norm]\n\nlemma real_inner_self_eq_norm_mul_norm (x : F) : \u27eax, x\u27eb_\u211d = \u2225x\u2225 * \u2225x\u2225 :=\nby { have h := @inner_self_eq_norm_mul_norm \u211d F _ _ x, simpa using h }\n\nlemma real_inner_self_eq_norm_sq (x : F) : \u27eax, x\u27eb_\u211d = \u2225x\u2225^2 :=\nby rw [pow_two, real_inner_self_eq_norm_mul_norm]\n\n/-- Expand the square -/\nlemma norm_add_sq {x y : E} : \u2225x + y\u2225^2 = \u2225x\u2225^2 + 2 * (re \u27eax, y\u27eb) + \u2225y\u2225^2 :=\nbegin\n  repeat {rw [sq, \u2190inner_self_eq_norm_mul_norm]},\n  rw [inner_add_add_self, two_mul],\n  simp only [add_assoc, add_left_inj, add_right_inj, add_monoid_hom.map_add],\n  rw [\u2190inner_conj_sym, conj_re],\nend\n\nalias norm_add_sq \u2190 norm_add_pow_two\n\n/-- Expand the square -/\nlemma norm_add_sq_real {x y : F} : \u2225x + y\u2225^2 = \u2225x\u2225^2 + 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225^2 :=\nby { have h := @norm_add_sq \u211d F _ _, simpa using h }\n\nalias norm_add_sq_real \u2190 norm_add_pow_two_real\n\n/-- Expand the square -/\nlemma norm_add_mul_self {x y : E} : \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + 2 * (re \u27eax, y\u27eb) + \u2225y\u2225 * \u2225y\u2225 :=\nby { repeat {rw [\u2190 sq]}, exact norm_add_sq }\n\n/-- Expand the square -/\nlemma norm_add_mul_self_real {x y : F} : \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225 * \u2225y\u2225 :=\nby { have h := @norm_add_mul_self \u211d F _ _, simpa using h }\n\n/-- Expand the square -/\nlemma norm_sub_sq {x y : E} : \u2225x - y\u2225^2 = \u2225x\u2225^2 - 2 * (re \u27eax, y\u27eb) + \u2225y\u2225^2 :=\nbegin\n  repeat {rw [sq, \u2190inner_self_eq_norm_mul_norm]},\n  rw [inner_sub_sub_self],\n  calc\n    re (\u27eax, x\u27eb - \u27eax, y\u27eb - \u27eay, x\u27eb + \u27eay, y\u27eb)\n        = re \u27eax, x\u27eb - re \u27eax, y\u27eb - re \u27eay, x\u27eb + re \u27eay, y\u27eb  : by simp\n    ... = -re \u27eay, x\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb  : by ring\n    ... = -re (\u27eax, y\u27eb\u2020) - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw [inner_conj_sym]\n    ... = -re \u27eax, y\u27eb - re \u27eax, y\u27eb + re \u27eax, x\u27eb + re \u27eay, y\u27eb : by rw [conj_re]\n    ... = re \u27eax, x\u27eb - 2*re \u27eax, y\u27eb + re \u27eay, y\u27eb : by ring\nend\n\nalias norm_sub_sq \u2190 norm_sub_pow_two\n\n/-- Expand the square -/\nlemma norm_sub_sq_real {x y : F} : \u2225x - y\u2225^2 = \u2225x\u2225^2 - 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225^2 :=\nnorm_sub_sq\n\nalias norm_sub_sq_real \u2190 norm_sub_pow_two_real\n\n/-- Expand the square -/\nlemma norm_sub_mul_self {x y : E} : \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 - 2 * re \u27eax, y\u27eb + \u2225y\u2225 * \u2225y\u2225 :=\nby { repeat {rw [\u2190 sq]}, exact norm_sub_sq }\n\n/-- Expand the square -/\nlemma norm_sub_mul_self_real {x y : F} : \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 - 2 * \u27eax, y\u27eb_\u211d + \u2225y\u2225 * \u2225y\u2225 :=\nby { have h := @norm_sub_mul_self \u211d F _ _, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : E) : abs \u27eax, y\u27eb \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _))\nbegin\n  have : \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225) = (re \u27eax, x\u27eb) * (re \u27eay, y\u27eb),\n    simp only [inner_self_eq_norm_mul_norm], ring,\n  rw this,\n  conv_lhs { congr, skip, rw [inner_abs_conj_sym] },\n  exact inner_mul_inner_self_le _ _\nend\n\nlemma norm_inner_le_norm (x y : E) : \u2225\u27eax, y\u27eb\u2225 \u2264 \u2225x\u2225 * \u2225y\u2225 :=\n(is_R_or_C.norm_eq_abs _).le.trans (abs_inner_le_norm x y)\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma abs_real_inner_le_norm (x y : F) : absR \u27eax, y\u27eb_\u211d \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nby { have h := @abs_inner_le_norm \u211d F _ _ x y, simpa using h }\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\nlemma real_inner_le_norm (x y : F) : \u27eax, y\u27eb_\u211d \u2264 \u2225x\u2225 * \u2225y\u2225 :=\nle_trans (le_abs_self _) (abs_real_inner_le_norm _ _)\n\ninclude \ud835\udd5c\nlemma parallelogram_law_with_norm {x y : E} :\n  \u2225x + y\u2225 * \u2225x + y\u2225 + \u2225x - y\u2225 * \u2225x - y\u2225 = 2 * (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225) :=\nbegin\n  simp only [\u2190 inner_self_eq_norm_mul_norm],\n  rw [\u2190 re.map_add, parallelogram_law, two_mul, two_mul],\n  simp only [re.map_add],\nend\nomit \ud835\udd5c\n\nlemma parallelogram_law_with_norm_real {x y : F} :\n  \u2225x + y\u2225 * \u2225x + y\u2225 + \u2225x - y\u2225 * \u2225x - y\u2225 = 2 * (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225) :=\nby { have h := @parallelogram_law_with_norm \u211d F _ _ x y, simpa using h }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x\u2225 * \u2225x\u2225 - \u2225y\u2225 * \u2225y\u2225) / 2 :=\nby { rw norm_add_mul_self, ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 2 :=\nby { rw [norm_sub_mul_self], ring }\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\nlemma re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :\n  re \u27eax, y\u27eb = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 4 :=\nby { rw [norm_add_mul_self, norm_sub_mul_self], ring }\n\n/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/\nlemma im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four (x y : E) :\n  im \u27eax, y\u27eb = (\u2225x - IK \u2022 y\u2225 * \u2225x - IK \u2022 y\u2225 - \u2225x + IK \u2022 y\u2225 * \u2225x + IK \u2022 y\u2225) / 4 :=\nby { simp only [norm_add_mul_self, norm_sub_mul_self, inner_smul_right, I_mul_re], ring }\n\n/-- Polarization identity: The inner product, in terms of the norm. -/\nlemma inner_eq_sum_norm_sq_div_four (x y : E) :\n  \u27eax, y\u27eb = (\u2225x + y\u2225 ^ 2 - \u2225x - y\u2225 ^ 2 + (\u2225x - IK \u2022 y\u2225 ^ 2 - \u2225x + IK \u2022 y\u2225 ^ 2) * IK) / 4 :=\nbegin\n  rw [\u2190 re_add_im \u27eax, y\u27eb, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,\n    im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four],\n  push_cast,\n  simp only [sq, \u2190 mul_div_right_comm, \u2190 add_div]\nend\n\nsection\n\nvariables {E' : Type*} [inner_product_space \ud835\udd5c E']\n\n/-- A linear isometry preserves the inner product. -/\n@[simp] lemma linear_isometry.inner_map_map (f : E \u2192\u2097\u1d62[\ud835\udd5c] E') (x y : E) : \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nby simp [inner_eq_sum_norm_sq_div_four, \u2190 f.norm_map]\n\n/-- A linear isometric equivalence preserves the inner product. -/\n@[simp] lemma linear_isometry_equiv.inner_map_map (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') (x y : E) :\n  \u27eaf x, f y\u27eb = \u27eax, y\u27eb :=\nf.to_linear_isometry.inner_map_map x y\n\n/-- A linear map that preserves the inner product is a linear isometry. -/\ndef linear_map.isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) : E \u2192\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, \u03bb x, by simp only [norm_eq_sqrt_inner, h]\u27e9\n\n@[simp] lemma linear_map.coe_isometry_of_inner (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_map.isometry_of_inner_to_linear_map (f : E \u2192\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_map = f := rfl\n\n/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/\ndef linear_equiv.isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h : \u2200 x y, \u27eaf x, f y\u27eb = \u27eax, y\u27eb) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] E' :=\n\u27e8f, ((f : E \u2192\u2097[\ud835\udd5c] E').isometry_of_inner h).norm_map\u27e9\n\n@[simp] lemma linear_equiv.coe_isometry_of_inner (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  \u21d1(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_equiv.isometry_of_inner_to_linear_equiv (f : E \u2243\u2097[\ud835\udd5c] E') (h) :\n  (f.isometry_of_inner h).to_linear_equiv = f := rfl\n\nend\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2225x + y\u2225 * \u2225x + y\u2225 - \u2225x\u2225 * \u2225x\u2225 - \u2225y\u2225 * \u2225y\u2225) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\nlemma real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :\n  \u27eax, y\u27eb_\u211d = (\u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 - \u2225x - y\u2225 * \u2225x - y\u2225) / 2 :=\nre_to_real.symm.trans $\n  re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y\n\n/-- Pythagorean theorem, if-and-only-if vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [norm_add_mul_self, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : \u27eax, y\u27eb = 0) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\nbegin\n  rw [norm_add_mul_self, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],\n  apply or.inr,\n  simp only [h, zero_re'],\nend\n\n/-- Pythagorean theorem, vector inner product form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2225x + y\u2225 * \u2225x + y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\n(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector\ninner product form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n  \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 \u2194 \u27eax, y\u27eb_\u211d = 0 :=\nbegin\n  rw [norm_sub_mul_self, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero,\n      mul_eq_zero],\n  norm_num\nend\n\n/-- Pythagorean theorem, subtracting vectors, vector inner product\nform. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : \u27eax, y\u27eb_\u211d = 0) :\n  \u2225x - y\u2225 * \u2225x - y\u2225 = \u2225x\u2225 * \u2225x\u2225 + \u2225y\u2225 * \u2225y\u2225 :=\n(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n\n/-- The sum and difference of two vectors are orthogonal if and only\nif they have the same norm. -/\nlemma real_inner_add_sub_eq_zero_iff (x y : F) : \u27eax + y, x - y\u27eb_\u211d = 0 \u2194 \u2225x\u2225 = \u2225y\u2225 :=\nbegin\n  conv_rhs { rw \u2190mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _) },\n  simp only [\u2190inner_self_eq_norm_mul_norm, inner_add_left, inner_sub_right,\n            real_inner_comm y x, sub_eq_zero, re_to_real],\n  split,\n  { intro h,\n    rw [add_comm] at h,\n    linarith },\n  { intro h,\n    linarith }\nend\n\n/-- Given two orthogonal vectors, their sum and difference have equal norms. -/\nlemma norm_sub_eq_norm_add {v w : E} (h : \u27eav, w\u27eb = 0) : \u2225w - v\u2225 = \u2225w + v\u2225 :=\nbegin\n  rw \u2190mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _),\n  simp [h, \u2190inner_self_eq_norm_mul_norm, inner_add_left, inner_add_right, inner_sub_left,\n    inner_sub_right, inner_re_symm]\nend\n\n/-- The real inner product of two vectors, divided by the product of their\nnorms, has absolute value at most 1. -/\nlemma abs_real_inner_div_norm_mul_norm_le_one (x y : F) : absR (\u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225)) \u2264 1 :=\nbegin\n  rw _root_.abs_div,\n  by_cases h : 0 = absR (\u2225x\u2225 * \u2225y\u2225),\n  { rw [\u2190h, div_zero],\n    norm_num },\n  { change 0 \u2260 absR (\u2225x\u2225 * \u2225y\u2225) at h,\n    rw div_le_iff' (lt_of_le_of_ne (ge_iff_le.mp (_root_.abs_nonneg (\u2225x\u2225 * \u2225y\u2225))) h),\n    convert abs_real_inner_le_norm x y using 1,\n    rw [_root_.abs_mul, _root_.abs_of_nonneg (norm_nonneg x), _root_.abs_of_nonneg (norm_nonneg y),\n        mul_one] }\nend\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_left (x : F) (r : \u211d) : \u27ear \u2022 x, x\u27eb_\u211d = r * (\u2225x\u2225 * \u2225x\u2225) :=\nby rw [real_inner_smul_left, \u2190real_inner_self_eq_norm_mul_norm]\n\n/-- The inner product of a vector with a multiple of itself. -/\nlemma real_inner_smul_self_right (x : F) (r : \u211d) : \u27eax, r \u2022 x\u27eb_\u211d = r * (\u2225x\u2225 * \u2225x\u2225) :=\nby rw [inner_smul_right, \u2190real_inner_self_eq_norm_mul_norm]\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : E} {r : \ud835\udd5c} (hx : x \u2260 0) (hr : r \u2260 0) : abs \u27eax, r \u2022 x\u27eb / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  have hx' : \u2225x\u2225 \u2260 0 := by simp [norm_eq_zero, hx],\n  have hr' : abs r \u2260 0 := by simp [is_R_or_C.abs_eq_zero, hr],\n  rw [inner_smul_right, is_R_or_C.abs_mul, \u2190inner_self_re_abs, inner_self_eq_norm_mul_norm,\n      norm_smul],\n  rw [is_R_or_C.norm_eq_abs, \u2190mul_assoc, \u2190div_div_eq_div_mul, mul_div_cancel _ hx',\n     \u2190div_div_eq_div_mul, mul_comm, mul_div_cancel _ hr', div_self hx'],\nend\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r \u2260 0) : absR \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  rw \u2190 abs_to_real,\n  exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr\nend\n\n/-- The inner product of a nonzero vector with a positive multiple of\nitself, divided by the product of their norms, has value 1. -/\nlemma real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : 0 < r) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = 1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2225x\u2225, mul_comm _ (absR r),\n      mul_assoc, _root_.abs_of_nonneg (le_of_lt hr), div_self],\n  exact mul_ne_zero (ne_of_gt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of a nonzero vector with a negative multiple of\nitself, divided by the product of their norms, has value -1. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul\n  {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r < 0) : \u27eax, r \u2022 x\u27eb_\u211d / (\u2225x\u2225 * \u2225r \u2022 x\u2225) = -1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, \u2190mul_assoc \u2225x\u2225, mul_comm _ (absR r),\n      mul_assoc, abs_of_neg hr, \u2190neg_mul_eq_neg_mul, div_neg_eq_neg_div, div_self],\n  exact mul_ne_zero (ne_of_lt hr)\n    (\u03bb h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_inner_div_norm_mul_norm_eq_one_iff (x y : E) :\n  abs (\u27eax, y\u27eb / (\u2225x\u2225 * \u2225y\u2225)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have hx0 : x \u2260 0,\n    { intro hx0,\n      rw [hx0, inner_zero_left, zero_div] at h,\n      norm_num at h, },\n    refine and.intro hx0 _,\n    set r := \u27eax, y\u27eb / (\u2225x\u2225 * \u2225x\u2225) with hr,\n    use r,\n    set t := y - r \u2022 x with ht,\n    have ht0 : \u27eax, t\u27eb = 0,\n    { rw [ht, inner_sub_right, inner_smul_right, hr],\n      norm_cast,\n      rw [\u2190inner_self_eq_norm_mul_norm, inner_self_re_to_K,\n          div_mul_cancel _ (\u03bb h, hx0 (inner_self_eq_zero.1 h)), sub_self] },\n    replace h : \u2225r \u2022 x\u2225 / \u2225t + r \u2022 x\u2225 = 1,\n    { rw [\u2190sub_add_cancel y (r \u2022 x), \u2190ht, inner_add_right, ht0, zero_add, inner_smul_right,\n        is_R_or_C.abs_div, is_R_or_C.abs_mul, \u2190inner_self_re_abs,\n        inner_self_eq_norm_mul_norm] at h,\n      norm_cast at h,\n      rwa [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm, \u2190mul_assoc, mul_comm,\n        mul_div_mul_left _ _ (\u03bb h, hx0 (norm_eq_zero.1 h)), \u2190is_R_or_C.norm_eq_abs,\n        \u2190norm_smul] at h },\n    have hr0 : r \u2260 0,\n    { intro hr0,\n      rw [hr0, zero_smul, norm_zero, zero_div] at h,\n      norm_num at h },\n    refine and.intro hr0 _,\n    have h2 : \u2225r \u2022 x\u2225 ^ 2 = \u2225t + r \u2022 x\u2225 ^ 2,\n    { rw [eq_of_div_eq_one h] },\n    replace h2 : \u27ear \u2022 x, r \u2022 x\u27eb = \u27eat, t\u27eb + \u27eat, r \u2022 x\u27eb + \u27ear \u2022 x, t\u27eb + \u27ear \u2022 x, r \u2022 x\u27eb,\n    { rw [sq, sq, \u2190inner_self_eq_norm_mul_norm, \u2190inner_self_eq_norm_mul_norm ] at h2,\n      have h2' := congr_arg (\u03bb z : \u211d, (z : \ud835\udd5c)) h2,\n      simp_rw [inner_self_re_to_K, inner_add_add_self] at h2',\n      exact h2' },\n    conv at h2 in \u27ear \u2022 x, t\u27eb { rw [inner_smul_left, ht0, mul_zero] },\n    symmetry' at h2,\n    have h\u2081 : \u27eat, r \u2022 x\u27eb = 0 := by { rw [inner_smul_right, \u2190inner_conj_sym, ht0], simp },\n    rw [add_zero, h\u2081, add_left_eq_self, add_zero, inner_self_eq_zero] at h2,\n    rw h2 at ht,\n    exact eq_of_sub_eq_zero ht.symm },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw [hy, is_R_or_C.abs_div],\n    norm_cast,\n    rw [_root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm],\n    exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\nlemma abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  absR (\u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225)) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r \u2260 0 \u2227 y = r \u2022 x) :=\nbegin\n  have := @abs_inner_div_norm_mul_norm_eq_one_iff \u211d F _ _ x y,\n  simpa [coe_real_eq_id] using this,\nend\n\n/--\nIf the inner product of two vectors is equal to the product of their norms, then the two vectors\nare multiples of each other. One form of the equality case for Cauchy-Schwarz.\nCompare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma abs_inner_eq_norm_iff (x y : E) (hx0 : x \u2260 0) (hy0 : y \u2260 0):\n  abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225 \u2194 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x :=\nbegin\n  have hx0' : \u2225x\u2225 \u2260 0 := by simp [norm_eq_zero, hx0],\n  have hy0' : \u2225y\u2225 \u2260 0 := by simp [norm_eq_zero, hy0],\n  have hxy0 : \u2225x\u2225 * \u2225y\u2225 \u2260 0 := by simp [hx0', hy0'],\n  have h\u2081 : abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225 \u2194 abs (\u27eax, y\u27eb / (\u2225x\u2225 * \u2225y\u2225)) = 1,\n  { refine \u27e8_ ,_\u27e9,\n    { intro h,\n      norm_cast,\n      rw [is_R_or_C.abs_div, h, abs_of_real, _root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm],\n      exact div_self hxy0 },\n    { intro h,\n      norm_cast at h,\n      rwa [is_R_or_C.abs_div, abs_of_real, _root_.abs_mul, abs_norm_eq_norm, abs_norm_eq_norm,\n          div_eq_one_iff_eq hxy0] at h } },\n  rw [h\u2081, abs_inner_div_norm_mul_norm_eq_one_iff x y],\n  have : x \u2260 0 := \u03bb h, (hx0' $ norm_eq_zero.mpr h),\n  simp [this]\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value 1 if and only if they are nonzero and one is\na positive multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225) = 1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), 0 < r \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrneg,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrneg) hr) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr }\nend\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value -1 if and only if they are nonzero and one is\na negative multiple of the other. -/\nlemma real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :\n  \u27eax, y\u27eb_\u211d / (\u2225x\u2225 * \u2225y\u2225) = -1 \u2194 (x \u2260 0 \u2227 \u2203 (r : \u211d), r < 0 \u2227 y = r \u2022 x) :=\nbegin\n  split,\n  { intro h,\n    have ha := h,\n    apply_fun absR at ha,\n    norm_num at ha,\n    rcases (abs_real_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    use [hx, r],\n    refine and.intro _ hy,\n    by_contradiction hrpos,\n    rw hy at h,\n    rw real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx\n      (lt_of_le_of_ne (le_of_not_lt hrpos) hr.symm) at h,\n    norm_num at h },\n  { intro h,\n    rcases h with \u27e8hx, \u27e8r, \u27e8hr, hy\u27e9\u27e9\u27e9,\n    rw hy,\n    exact real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx hr }\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma inner_eq_norm_mul_iff {x y : E} :\n  \u27eax, y\u27eb = (\u2225x\u2225 : \ud835\udd5c) * \u2225y\u2225 \u2194 (\u2225y\u2225 : \ud835\udd5c) \u2022 x = (\u2225x\u2225 : \ud835\udd5c) \u2022 y :=\nbegin\n  by_cases h : (x = 0 \u2228 y = 0), -- WLOG `x` and `y` are nonzero\n  { cases h; simp [h] },\n  calc \u27eax, y\u27eb = (\u2225x\u2225 : \ud835\udd5c) * \u2225y\u2225 \u2194 \u2225x\u2225 * \u2225y\u2225 = re \u27eax, y\u27eb :\n  begin\n    norm_cast,\n    split,\n    { intros h',\n      simp [h'] },\n    { have cauchy_schwarz := abs_inner_le_norm x y,\n      intros h',\n      rw h' at \u22a2 cauchy_schwarz,\n      rwa re_eq_self_of_le }\n  end\n  ... \u2194 2 * \u2225x\u2225 * \u2225y\u2225 * (\u2225x\u2225 * \u2225y\u2225 - re \u27eax, y\u27eb) = 0 :\n    by simp [h, show (2:\u211d) \u2260 0, by norm_num, sub_eq_zero]\n  ... \u2194 \u2225(\u2225y\u2225:\ud835\udd5c) \u2022 x - (\u2225x\u2225:\ud835\udd5c) \u2022 y\u2225 * \u2225(\u2225y\u2225:\ud835\udd5c) \u2022 x - (\u2225x\u2225:\ud835\udd5c) \u2022 y\u2225 = 0 :\n  begin\n    simp only [norm_sub_mul_self, inner_smul_left, inner_smul_right, norm_smul, conj_of_real,\n      is_R_or_C.norm_eq_abs, abs_of_real, of_real_im, of_real_re, mul_re, abs_norm_eq_norm],\n    refine eq.congr _ rfl,\n    ring\n  end\n  ... \u2194 (\u2225y\u2225 : \ud835\udd5c) \u2022 x = (\u2225x\u2225 : \ud835\udd5c) \u2022 y : by simp [norm_sub_eq_zero_iff]\nend\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\nlemma inner_eq_norm_mul_iff_real {x y : F} : \u27eax, y\u27eb_\u211d = \u2225x\u2225 * \u2225y\u2225 \u2194 \u2225y\u2225 \u2022 x = \u2225x\u2225 \u2022 y :=\ninner_eq_norm_mul_iff\n\n/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of\nthe equality case for Cauchy-Schwarz. -/\nlemma inner_eq_norm_mul_iff_of_norm_one {x y : E} (hx : \u2225x\u2225 = 1) (hy : \u2225y\u2225 = 1) :\n  \u27eax, y\u27eb = 1 \u2194 x = y :=\nby { convert inner_eq_norm_mul_iff using 2; simp [hx, hy] }\n\nlemma inner_lt_norm_mul_iff_real {x y : F} :\n  \u27eax, y\u27eb_\u211d < \u2225x\u2225 * \u2225y\u2225 \u2194 \u2225y\u2225 \u2022 x \u2260 \u2225x\u2225 \u2022 y :=\ncalc \u27eax, y\u27eb_\u211d < \u2225x\u2225 * \u2225y\u2225\n    \u2194 \u27eax, y\u27eb_\u211d \u2260 \u2225x\u2225 * \u2225y\u2225 : \u27e8ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)\u27e9\n... \u2194 \u2225y\u2225 \u2022 x \u2260 \u2225x\u2225 \u2022 y : not_congr inner_eq_norm_mul_iff_real\n\n/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are\ndistinct. One form of the equality case for Cauchy-Schwarz. -/\nlemma inner_lt_one_iff_real_of_norm_one {x y : F} (hx : \u2225x\u2225 = 1) (hy : \u2225y\u2225 = 1) :\n  \u27eax, y\u27eb_\u211d < 1 \u2194 x \u2260 y :=\nby { convert inner_lt_norm_mul_iff_real; simp [hx, hy] }\n\n/-- The inner product of two weighted sums, where the weights in each\nsum add to 0, in terms of the norms of pairwise differences. -/\nlemma inner_sum_smul_sum_smul_of_sum_eq_zero {\u03b9\u2081 : Type*} {s\u2081 : finset \u03b9\u2081} {w\u2081 : \u03b9\u2081 \u2192 \u211d}\n    (v\u2081 : \u03b9\u2081 \u2192 F) (h\u2081 : \u2211 i in s\u2081, w\u2081 i = 0) {\u03b9\u2082 : Type*} {s\u2082 : finset \u03b9\u2082} {w\u2082 : \u03b9\u2082 \u2192 \u211d}\n    (v\u2082 : \u03b9\u2082 \u2192 F) (h\u2082 : \u2211 i in s\u2082, w\u2082 i = 0) :\n  \u27ea(\u2211 i\u2081 in s\u2081, w\u2081 i\u2081 \u2022 v\u2081 i\u2081), (\u2211 i\u2082 in s\u2082, w\u2082 i\u2082 \u2022 v\u2082 i\u2082)\u27eb_\u211d =\n    (-\u2211 i\u2081 in s\u2081, \u2211 i\u2082 in s\u2082, w\u2081 i\u2081 * w\u2082 i\u2082 * (\u2225v\u2081 i\u2081 - v\u2082 i\u2082\u2225 * \u2225v\u2081 i\u2081 - v\u2082 i\u2082\u2225)) / 2 :=\nby simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,\n            real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two,\n            \u2190div_sub_div_same, \u2190div_add_div_same, mul_sub_left_distrib, left_distrib,\n            finset.sum_sub_distrib, finset.sum_add_distrib, \u2190finset.mul_sum, \u2190finset.sum_mul,\n            h\u2081, h\u2082, zero_mul, mul_zero, finset.sum_const_zero, zero_add, zero_sub, finset.mul_sum,\n            neg_div, finset.sum_div, mul_div_assoc, mul_assoc]\n\n/-- The inner product with a fixed left element, as a continuous linear map.  This can be upgraded\nto a continuous map which is jointly conjugate-linear in the left argument and linear in the right\nargument, once (TODO) conjugate-linear maps have been defined. -/\ndef inner_right (v : E) : E \u2192L[\ud835\udd5c] \ud835\udd5c :=\nlinear_map.mk_continuous\n  { to_fun := \u03bb w, \u27eav, w\u27eb,\n    map_add' := \u03bb x y, inner_add_right,\n    map_smul' := \u03bb c x, inner_smul_right }\n  \u2225v\u2225\n  (by simpa using norm_inner_le_norm v)\n\n@[simp] lemma inner_right_coe (v : E) : (inner_right v : E \u2192 \ud835\udd5c) = \u03bb w, \u27eav, w\u27eb := rfl\n\n@[simp] lemma inner_right_apply (v w : E) : inner_right v w = \u27eav, w\u27eb := rfl\n\n/-- When an inner product space `E` over `\ud835\udd5c` is considered as a real normed space, its inner\nproduct satisfies `is_bounded_bilinear_map`.\n\nIn order to state these results, we need a `normed_space \u211d E` instance. We will later establish\nsuch an instance by restriction-of-scalars, `inner_product_space.is_R_or_C_to_real \ud835\udd5c E`, but this\ninstance may be not definitionally equal to some other \u201cnatural\u201d instance. So, we assume\n`[normed_space \u211d E]` and `[is_scalar_tower \u211d \ud835\udd5c E]`. In both interesting cases `\ud835\udd5c = \u211d` and `\ud835\udd5c = \u2102`\nwe have these instances.\n-/\nlemma is_bounded_bilinear_map_inner [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] :\n  is_bounded_bilinear_map \u211d (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\n{ add_left := \u03bb _ _ _, inner_add_left,\n  smul_left := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r x, algebra_map_eq_of_real, inner_smul_real_left],\n  add_right := \u03bb _ _ _, inner_add_right,\n  smul_right := \u03bb r x y,\n    by simp only [\u2190 algebra_map_smul \ud835\udd5c r y, algebra_map_eq_of_real, inner_smul_real_right],\n  bound := \u27e81, zero_lt_one, \u03bb x y,\n    by { rw [one_mul], exact norm_inner_le_norm x y, }\u27e9 }\nend norm\n\nsection bessels_inequality\n\nvariables {\u03b9: Type*} (x : E) {v : \u03b9 \u2192 E}\n\n/-- Bessel's inequality for finite sums. -/\nlemma orthonormal.sum_inner_products_le {s : finset \u03b9} (hv : orthonormal \ud835\udd5c v) :\n  \u2211 i in s, \u2225\u27eav i, x\u27eb\u2225 ^ 2 \u2264 \u2225x\u2225 ^ 2 :=\nbegin\n  have h\u2082 : \u2211 i in s, \u2211 j in s, \u27eav i, x\u27eb * \u27eax, v j\u27eb * \u27eav j, v i\u27eb\n    = (\u2211 k in s, (\u27eav k, x\u27eb * \u27eax, v k\u27eb) : \ud835\udd5c),\n  { exact hv.inner_left_right_finset },\n  have h\u2083 : \u2200 z : \ud835\udd5c, re (z * conj (z)) = \u2225z\u2225 ^ 2,\n  { intro z,\n    simp only [mul_conj, norm_sq_eq_def'],\n    norm_cast, },\n  suffices hbf: \u2225x -  \u2211 i in s, \u27eav i, x\u27eb \u2022 (v i)\u2225 ^ 2 = \u2225x\u2225 ^ 2 - \u2211 i in s, \u2225\u27eav i, x\u27eb\u2225 ^ 2,\n  { rw [\u2190sub_nonneg, \u2190hbf],\n    simp only [norm_nonneg, pow_nonneg], },\n  rw [norm_sub_sq, sub_add],\n  simp only [inner_product_space.norm_sq_eq_inner, inner_sum],\n  simp only [sum_inner, two_mul, inner_smul_right, inner_conj_sym, \u2190mul_assoc, h\u2082, \u2190h\u2083,\n  inner_conj_sym, add_monoid_hom.map_sum, finset.mul_sum, \u2190finset.sum_sub_distrib, inner_smul_left,\n  add_sub_cancel'],\nend\n\n/-- Bessel's inequality. -/\nlemma orthonormal.tsum_inner_products_le (hv : orthonormal \ud835\udd5c v) :\n  \u2211' i, \u2225\u27eav i, x\u27eb\u2225 ^ 2 \u2264 \u2225x\u2225 ^ 2 :=\nbegin\n  refine tsum_le_of_sum_le' _ (\u03bb s, hv.sum_inner_products_le x),\n  simp only [norm_nonneg, pow_nonneg]\nend\n\n/-- The sum defined in Bessel's inequality is summable. -/\nlemma orthonormal.inner_products_summable (hv : orthonormal \ud835\udd5c v) : summable (\u03bb i, \u2225\u27eav i, x\u27eb\u2225 ^ 2) :=\nbegin\n  use \u2a06 s : finset \u03b9, \u2211 i in s, \u2225\u27eav i, x\u27eb\u2225 ^ 2,\n  apply has_sum_of_is_lub_of_nonneg,\n  { intro b,\n    simp only [norm_nonneg, pow_nonneg], },\n  { refine is_lub_csupr _,\n    use \u2225x\u2225 ^ 2,\n    rintro y \u27e8s, rfl\u27e9,\n    exact hv.sum_inner_products_le x }\nend\n\nend bessels_inequality\n\n/-- A field `\ud835\udd5c` satisfying `is_R_or_C` is itself a `\ud835\udd5c`-inner product space. -/\ninstance is_R_or_C.inner_product_space : inner_product_space \ud835\udd5c \ud835\udd5c :=\n{ inner := (\u03bb x y, (conj x) * y),\n  norm_sq_eq_inner := \u03bb x,\n    by { unfold inner, rw [mul_comm, mul_conj, of_real_re, norm_sq_eq_def'] },\n  conj_sym := \u03bb x y, by simp [mul_comm],\n  add_left := \u03bb x y z, by simp [inner, add_mul],\n  smul_left := \u03bb x y z, by simp [inner, mul_assoc] }\n\n@[simp] lemma is_R_or_C.inner_apply (x y : \ud835\udd5c) : \u27eax, y\u27eb = (conj x) * y := rfl\n\n/-! ### Inner product space structure on subspaces -/\n\n/-- Induced inner product on a submodule. -/\ninstance submodule.inner_product_space (W : submodule \ud835\udd5c E) : inner_product_space \ud835\udd5c W :=\n{ inner             := \u03bb x y, \u27ea(x:E), (y:E)\u27eb,\n  conj_sym          := \u03bb _ _, inner_conj_sym _ _ ,\n  norm_sq_eq_inner  := \u03bb _, norm_sq_eq_inner _,\n  add_left          := \u03bb _ _ _ , inner_add_left,\n  smul_left         := \u03bb _ _ _, inner_smul_left,\n  ..submodule.normed_space W }\n\n/-- The inner product on submodules is the same as on the ambient space. -/\n@[simp] lemma submodule.coe_inner (W : submodule \ud835\udd5c E) (x y : W) : \u27eax, y\u27eb = \u27ea(x:E), \u2191y\u27eb := rfl\n\n/-! ### Families of mutually-orthogonal subspaces of an inner product space -/\n\nsection orthogonal_family\nvariables {\u03b9 : Type*} [dec_\u03b9 : decidable_eq \u03b9] (\ud835\udd5c)\nopen_locale direct_sum\n\n/-- An indexed family of mutually-orthogonal subspaces of an inner product space `E`. -/\ndef orthogonal_family (V : \u03b9 \u2192 submodule \ud835\udd5c E) : Prop :=\n\u2200 \u2983i j\u2984, i \u2260 j \u2192 \u2200 {v : E} (hv : v \u2208 V i) {w : E} (hw : w \u2208 V j), \u27eav, w\u27eb = 0\n\nvariables {\ud835\udd5c} {V : \u03b9 \u2192 submodule \ud835\udd5c E}\n\ninclude dec_\u03b9\nlemma orthogonal_family.eq_ite (hV : orthogonal_family \ud835\udd5c V) {i j : \u03b9} (v : V i) (w : V j) :\n  \u27ea(v:E), w\u27eb = ite (i = j) \u27ea(v:E), w\u27eb 0 :=\nbegin\n  split_ifs,\n  { refl },\n  { exact hV h v.prop w.prop }\nend\n\nlemma orthogonal_family.inner_right_dfinsupp (hV : orthogonal_family \ud835\udd5c V)\n  (l : \u03a0\u2080 i, V i) (i : \u03b9) (v : V i) :\n  \u27ea(v : E), dfinsupp.lsum \u2115 (\u03bb i, (V i).subtype) l\u27eb = \u27eav, l i\u27eb :=\ncalc \u27ea(v : E), dfinsupp.lsum \u2115 (\u03bb i, (V i).subtype) l\u27eb\n    = l.sum (\u03bb j, \u03bb w, \u27ea(v:E), w\u27eb) :\nbegin\n  let F : E \u2192+ \ud835\udd5c := (@inner_right \ud835\udd5c E _ _ v).to_linear_map.to_add_monoid_hom,\n  have hF := congr_arg add_monoid_hom.to_fun\n    (dfinsupp.comp_sum_add_hom F (\u03bb j, (V j).subtype.to_add_monoid_hom)),\n  convert congr_fun hF l using 1,\n  simp only [dfinsupp.sum_add_hom_apply, continuous_linear_map.to_linear_map_eq_coe,\n    add_monoid_hom.coe_comp, inner_right_coe, add_monoid_hom.to_fun_eq_coe,\n    linear_map.to_add_monoid_hom_coe, continuous_linear_map.coe_coe],\n  congr\nend\n... = l.sum (\u03bb j, \u03bb w, ite (i=j) \u27ea(v:E), w\u27eb 0) :\n  congr_arg l.sum $ funext $ \u03bb j, funext $ hV.eq_ite v\n... = \u27eav, l i\u27eb :\nbegin\n  simp only [dfinsupp.sum, submodule.coe_inner, finset.sum_ite_eq, ite_eq_left_iff,\n    dfinsupp.mem_support_to_fun, not_not],\n  intros h,\n  simp [h]\nend\nomit dec_\u03b9\n\nlemma orthogonal_family.inner_right_fintype\n  [fintype \u03b9] (hV : orthogonal_family \ud835\udd5c V) (l : \u03a0 i, V i) (i : \u03b9) (v : V i) :\n  \u27ea(v : E), \u2211 j : \u03b9, l j\u27eb = \u27eav, l i\u27eb :=\ncalc \u27ea(v : E), \u2211 j : \u03b9, l j\u27eb\n    = \u2211 j : \u03b9, \u27ea(v : E), l j\u27eb: by rw inner_sum\n... = \u2211 j, ite (i = j) \u27ea(v : E), l j\u27eb 0 :\n  congr_arg (finset.sum finset.univ) $ funext $ \u03bb j, (hV.eq_ite v (l j))\n... = \u27eav, l i\u27eb : by simp\n\n/-- An orthogonal family forms an independent family of subspaces; that is, any collection of\nelements each from a different subspace in the family is linearly independent. In particular, the\npairwise intersections of elements of the family are 0. -/\nlemma orthogonal_family.independent (hV : orthogonal_family \ud835\udd5c V) :\n  complete_lattice.independent V :=\nbegin\n  apply complete_lattice.independent_of_dfinsupp_lsum_injective,\n  rw [\u2190 @linear_map.ker_eq_bot _ _ _ _ _ _ (direct_sum.add_comm_group (\u03bb i, V i)),\n    submodule.eq_bot_iff],\n  intros v hv,\n  rw linear_map.mem_ker at hv,\n  ext i,\n  have : \u27ea(v i : E), dfinsupp.lsum \u2115 (\u03bb i, (V i).subtype) v\u27eb = 0,\n  { simp [hv] },\n  simpa only [submodule.coe_zero, submodule.coe_eq_zero, direct_sum.zero_apply, inner_self_eq_zero,\n    hV.inner_right_dfinsupp] using this,\nend\n\n/-- The composition of an orthogonal family of subspaces with an injective function is also an\northogonal family. -/\nlemma orthogonal_family.comp (hV : orthogonal_family \ud835\udd5c V) {\u03b3 : Type*} {f : \u03b3 \u2192 \u03b9}\n  (hf : function.injective f) :\n  orthogonal_family \ud835\udd5c (V \u2218 f) :=\n\u03bb i j hij v hv w hw, hV (hf.ne hij) hv hw\n\nlemma orthogonal_family.orthonormal_sigma_orthonormal (hV : orthogonal_family \ud835\udd5c V) {\u03b1 : \u03b9 \u2192 Type*}\n  {v_family : \u03a0 i, (\u03b1 i) \u2192 V i} (hv_family : \u2200 i, orthonormal \ud835\udd5c (v_family i)) :\n  orthonormal \ud835\udd5c (\u03bb a : \u03a3 i, \u03b1 i, (v_family a.1 a.2 : E)) :=\nbegin\n  split,\n  { rintros \u27e8i, vi\u27e9,\n    exact (hv_family i).1 vi },\n  rintros \u27e8i, vi\u27e9 \u27e8j, vj\u27e9 hvij,\n  by_cases hij : i = j,\n  { subst hij,\n    have : vi \u2260 vj := by simpa using hvij,\n    exact (hv_family i).2 this },\n  { exact hV hij (v_family i vi : V i).prop (v_family j vj : V j).prop }\nend\n\ninclude dec_\u03b9\nlemma direct_sum.submodule_is_internal.collected_basis_orthonormal (hV : orthogonal_family \ud835\udd5c V)\n  (hV_sum : direct_sum.submodule_is_internal V) {\u03b1 : \u03b9 \u2192 Type*}\n  {v_family : \u03a0 i, basis (\u03b1 i) \ud835\udd5c (V i)} (hv_family : \u2200 i, orthonormal \ud835\udd5c (v_family i)) :\n  orthonormal \ud835\udd5c (hV_sum.collected_basis v_family) :=\nby simpa using hV.orthonormal_sigma_orthonormal hv_family\nomit dec_\u03b9\n\nend orthogonal_family\n\nsection is_R_or_C_to_real\n\nvariables {G : Type*}\n\nvariables (\ud835\udd5c E)\ninclude \ud835\udd5c\n\n/-- A general inner product implies a real inner product. This is not registered as an instance\nsince it creates problems with the case `\ud835\udd5c = \u211d`. -/\ndef has_inner.is_R_or_C_to_real : has_inner \u211d E :=\n{ inner := \u03bb x y, re \u27eax, y\u27eb }\n\n/-- A general inner product space structure implies a real inner product structure. This is not\nregistered as an instance since it creates problems with the case `\ud835\udd5c = \u211d`, but in can be used in a\nproof to obtain a real inner product space structure from a given `\ud835\udd5c`-inner product space\nstructure. -/\ndef inner_product_space.is_R_or_C_to_real : inner_product_space \u211d E :=\n{ norm_sq_eq_inner := norm_sq_eq_inner,\n  conj_sym := \u03bb x y, inner_re_symm,\n  add_left := \u03bb x y z, by\n  { change re \u27eax + y, z\u27eb = re \u27eax, z\u27eb + re \u27eay, z\u27eb,\n    simp [inner_add_left] },\n  smul_left := \u03bb x y r, by\n  { change re \u27ea(r : \ud835\udd5c) \u2022 x, y\u27eb = r * re \u27eax, y\u27eb,\n    simp [inner_smul_left] },\n  ..has_inner.is_R_or_C_to_real \ud835\udd5c E,\n  ..normed_space.restrict_scalars \u211d \ud835\udd5c E }\n\nvariable {E}\n\nlemma real_inner_eq_re_inner (x y : E) :\n  @has_inner.inner \u211d E (has_inner.is_R_or_C_to_real \ud835\udd5c E) x y = re \u27eax, y\u27eb := rfl\n\nlemma real_inner_I_smul_self (x : E) :\n  @has_inner.inner \u211d E (has_inner.is_R_or_C_to_real \ud835\udd5c E) x ((I : \ud835\udd5c) \u2022 x) = 0 :=\nby simp [real_inner_eq_re_inner, inner_smul_right]\n\nomit \ud835\udd5c\n\n/-- A complex inner product implies a real inner product -/\ninstance inner_product_space.complex_to_real [inner_product_space \u2102 G] : inner_product_space \u211d G :=\ninner_product_space.is_R_or_C_to_real \u2102 G\n\nend is_R_or_C_to_real\n\nsection continuous\n\n/-!\n### Continuity of the inner product\n-/\n\nlemma continuous_inner : continuous (\u03bb p : E \u00d7 E, \u27eap.1, p.2\u27eb) :=\nbegin\n  letI : inner_product_space \u211d E := inner_product_space.is_R_or_C_to_real \ud835\udd5c E,\n  letI : is_scalar_tower \u211d \ud835\udd5c E := restrict_scalars.is_scalar_tower _ _ _,\n  exact is_bounded_bilinear_map_inner.continuous\nend\n\nvariables {\u03b1 : Type*}\n\nlemma filter.tendsto.inner {f g : \u03b1 \u2192 E} {l : filter \u03b1} {x y : E} (hf : tendsto f l (\ud835\udcdd x))\n  (hg : tendsto g l (\ud835\udcdd y)) :\n  tendsto (\u03bb t, \u27eaf t, g t\u27eb) l (\ud835\udcdd \u27eax, y\u27eb) :=\n(continuous_inner.tendsto _).comp (hf.prod_mk_nhds hg)\n\nvariables [topological_space \u03b1] {f g : \u03b1 \u2192 E} {x : \u03b1} {s : set \u03b1}\n\ninclude \ud835\udd5c\n\nlemma continuous_within_at.inner (hf : continuous_within_at f s x)\n  (hg : continuous_within_at g s x) :\n  continuous_within_at (\u03bb t, \u27eaf t, g t\u27eb) s x :=\nhf.inner hg\n\nlemma continuous_at.inner (hf : continuous_at f x) (hg : continuous_at g x) :\n  continuous_at (\u03bb t, \u27eaf t, g t\u27eb) x :=\nhf.inner hg\n\nlemma continuous_on.inner (hf : continuous_on f s) (hg : continuous_on g s) :\n  continuous_on (\u03bb t, \u27eaf t, g t\u27eb) s :=\n\u03bb x hx, (hf x hx).inner (hg x hx)\n\nlemma continuous.inner (hf : continuous f) (hg : continuous g) : continuous (\u03bb t, \u27eaf t, g t\u27eb) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, hf.continuous_at.inner hg.continuous_at\n\nend continuous\n\nsection re_apply_inner_self\n\n/-- Extract a real bilinear form from an operator `T`, by taking the pairing `\u03bb x, re \u27eaT x, x\u27eb`. -/\ndef continuous_linear_map.re_apply_inner_self (T : E \u2192L[\ud835\udd5c] E) (x : E) : \u211d := re \u27eaT x, x\u27eb\n\nlemma continuous_linear_map.re_apply_inner_self_apply (T : E \u2192L[\ud835\udd5c] E) (x : E) :\n  T.re_apply_inner_self x = re \u27eaT x, x\u27eb :=\nrfl\n\nlemma continuous_linear_map.re_apply_inner_self_continuous (T : E \u2192L[\ud835\udd5c] E) :\n  continuous T.re_apply_inner_self :=\nre_clm.continuous.comp $ T.continuous.inner continuous_id\n\nlemma continuous_linear_map.re_apply_inner_self_smul (T : E \u2192L[\ud835\udd5c] E) (x : E) {c : \ud835\udd5c} :\n  T.re_apply_inner_self (c \u2022 x) = \u2225c\u2225 ^ 2 * T.re_apply_inner_self x :=\nby simp only [continuous_linear_map.map_smul, continuous_linear_map.re_apply_inner_self_apply,\n  inner_smul_left, inner_smul_right, \u2190 mul_assoc, mul_conj, norm_sq_eq_def', \u2190 smul_re,\n  algebra.smul_def (\u2225c\u2225 ^ 2) \u27eaT x, x\u27eb, algebra_map_eq_of_real]\n\nend re_apply_inner_self\n\n/-! ### The orthogonal complement -/\n\nsection orthogonal\nvariables (K : submodule \ud835\udd5c E)\n\n/-- The subspace of vectors orthogonal to a given subspace. -/\ndef submodule.orthogonal : submodule \ud835\udd5c E :=\n{ carrier := {v | \u2200 u \u2208 K, \u27eau, v\u27eb = 0},\n  zero_mem' := \u03bb _ _, inner_zero_right,\n  add_mem' := \u03bb x y hx hy u hu, by rw [inner_add_right, hx u hu, hy u hu, add_zero],\n  smul_mem' := \u03bb c x hx u hu, by rw [inner_smul_right, hx u hu, mul_zero] }\n\nnotation K`\u15ee`:1200 := submodule.orthogonal K\n\n/-- When a vector is in `K\u15ee`. -/\nlemma submodule.mem_orthogonal (v : E) : v \u2208 K\u15ee \u2194 \u2200 u \u2208 K, \u27eau, v\u27eb = 0 := iff.rfl\n\n/-- When a vector is in `K\u15ee`, with the inner product the\nother way round. -/\nlemma submodule.mem_orthogonal' (v : E) : v \u2208 K\u15ee \u2194 \u2200 u \u2208 K, \u27eav, u\u27eb = 0 :=\nby simp_rw [submodule.mem_orthogonal, inner_eq_zero_sym]\n\nvariables {K}\n\n/-- A vector in `K` is orthogonal to one in `K\u15ee`. -/\nlemma submodule.inner_right_of_mem_orthogonal {u v : E} (hu : u \u2208 K) (hv : v \u2208 K\u15ee) : \u27eau, v\u27eb = 0 :=\n(K.mem_orthogonal v).1 hv u hu\n\n/-- A vector in `K\u15ee` is orthogonal to one in `K`. -/\nlemma submodule.inner_left_of_mem_orthogonal {u v : E} (hu : u \u2208 K) (hv : v \u2208 K\u15ee) : \u27eav, u\u27eb = 0 :=\nby rw [inner_eq_zero_sym]; exact submodule.inner_right_of_mem_orthogonal hu hv\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\nlemma inner_right_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v \u2208 (\ud835\udd5c \u2219 u)\u15ee) : \u27eau, v\u27eb = 0 :=\nsubmodule.inner_right_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\nlemma inner_left_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v \u2208 (\ud835\udd5c \u2219 u)\u15ee) : \u27eav, u\u27eb = 0 :=\nsubmodule.inner_left_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector orthogonal to `u` lies in `(\ud835\udd5c \u2219 u)\u15ee`. -/\nlemma mem_orthogonal_singleton_of_inner_right (u : E) {v : E} (hv : \u27eau, v\u27eb = 0) : v \u2208 (\ud835\udd5c \u2219 u)\u15ee :=\nbegin\n  intros w hw,\n  rw submodule.mem_span_singleton at hw,\n  obtain \u27e8c, rfl\u27e9 := hw,\n  simp [inner_smul_left, hv],\nend\n\n/-- A vector orthogonal to `u` lies in `(\ud835\udd5c \u2219 u)\u15ee`. -/\nlemma mem_orthogonal_singleton_of_inner_left (u : E) {v : E} (hv : \u27eav, u\u27eb = 0) : v \u2208 (\ud835\udd5c \u2219 u)\u15ee :=\nmem_orthogonal_singleton_of_inner_right u $ inner_eq_zero_sym.2 hv\n\nvariables (K)\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\nlemma submodule.inf_orthogonal_eq_bot : K \u2293 K\u15ee = \u22a5 :=\nbegin\n  rw submodule.eq_bot_iff,\n  intros x,\n  rw submodule.mem_inf,\n  exact \u03bb \u27e8hx, ho\u27e9, inner_self_eq_zero.1 (ho x hx)\nend\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\nlemma submodule.orthogonal_disjoint : disjoint K K\u15ee :=\nby simp [disjoint_iff, K.inf_orthogonal_eq_bot]\n\n/-- `K\u15ee` can be characterized as the intersection of the kernels of the operations of\ninner product with each of the elements of `K`. -/\nlemma orthogonal_eq_inter : K\u15ee = \u2a05 v : K, (inner_right (v:E)).ker :=\nbegin\n  apply le_antisymm,\n  { rw le_infi_iff,\n    rintros \u27e8v, hv\u27e9 w hw,\n    simpa using hw _ hv },\n  { intros v hv w hw,\n    simp only [submodule.mem_infi] at hv,\n    exact hv \u27e8w, hw\u27e9 }\nend\n\n/-- The orthogonal complement of any submodule `K` is closed. -/\nlemma submodule.is_closed_orthogonal : is_closed (K\u15ee : set E) :=\nbegin\n  rw orthogonal_eq_inter K,\n  convert is_closed_Inter (\u03bb v : K, (inner_right (v:E)).is_closed_ker),\n  simp\nend\n\n/-- In a complete space, the orthogonal complement of any submodule `K` is complete. -/\ninstance [complete_space E] : complete_space K\u15ee := K.is_closed_orthogonal.complete_space_coe\n\nvariables (\ud835\udd5c E)\n\n/-- `submodule.orthogonal` gives a `galois_connection` between\n`submodule \ud835\udd5c E` and its `order_dual`. -/\nlemma submodule.orthogonal_gc :\n  @galois_connection (submodule \ud835\udd5c E) (order_dual $ submodule \ud835\udd5c E) _ _\n    submodule.orthogonal submodule.orthogonal :=\n\u03bb K\u2081 K\u2082, \u27e8\u03bb h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu),\n          \u03bb h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu)\u27e9\n\nvariables {\ud835\udd5c E}\n\n/-- `submodule.orthogonal` reverses the `\u2264` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_le {K\u2081 K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) : K\u2082\u15ee \u2264 K\u2081\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).monotone_l h\n\n/-- `submodule.orthogonal.orthogonal` preserves the `\u2264` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_orthogonal_monotone {K\u2081 K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) :\n  K\u2081\u15ee\u15ee \u2264 K\u2082\u15ee\u15ee :=\nsubmodule.orthogonal_le (submodule.orthogonal_le h)\n\n/-- `K` is contained in `K\u15ee\u15ee`. -/\nlemma submodule.le_orthogonal_orthogonal : K \u2264 K\u15ee\u15ee := (submodule.orthogonal_gc \ud835\udd5c E).le_u_l _\n\n/-- The inf of two orthogonal subspaces equals the subspace orthogonal\nto the sup. -/\nlemma submodule.inf_orthogonal (K\u2081 K\u2082 : submodule \ud835\udd5c E) : K\u2081\u15ee \u2293 K\u2082\u15ee = (K\u2081 \u2294 K\u2082)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_sup.symm\n\n/-- The inf of an indexed family of orthogonal subspaces equals the\nsubspace orthogonal to the sup. -/\nlemma submodule.infi_orthogonal {\u03b9 : Type*} (K : \u03b9 \u2192 submodule \ud835\udd5c E) : (\u2a05 i, (K i)\u15ee) = (supr K)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_supr.symm\n\n/-- The inf of a set of orthogonal subspaces equals the subspace orthogonal to the sup. -/\nlemma submodule.Inf_orthogonal (s : set $ submodule \ud835\udd5c E) : (\u2a05 K \u2208 s, K\u15ee) = (Sup s)\u15ee :=\n(submodule.orthogonal_gc \ud835\udd5c E).l_Sup.symm\n\n@[simp] lemma submodule.top_orthogonal_eq_bot : (\u22a4 : submodule \ud835\udd5c E)\u15ee = \u22a5 :=\nbegin\n  ext,\n  rw [submodule.mem_bot, submodule.mem_orthogonal],\n  exact \u27e8\u03bb h, inner_self_eq_zero.mp (h x submodule.mem_top), by { rintro rfl, simp }\u27e9\nend\n\n@[simp] lemma submodule.bot_orthogonal_eq_top : (\u22a5 : submodule \ud835\udd5c E)\u15ee = \u22a4 :=\nbegin\n  rw [\u2190 submodule.top_orthogonal_eq_bot, eq_top_iff],\n  exact submodule.le_orthogonal_orthogonal \u22a4\nend\n\n@[simp] lemma submodule.orthogonal_eq_top_iff : K\u15ee = \u22a4 \u2194 K = \u22a5 :=\nbegin\n  refine \u27e8_, by { rintro rfl, exact submodule.bot_orthogonal_eq_top }\u27e9,\n  intro h,\n  have : K \u2293 K\u15ee = \u22a5 := K.orthogonal_disjoint.eq_bot,\n  rwa [h, inf_comm, top_inf_eq] at this\nend\n\nend orthogonal\n\n/-! ### Self-adjoint operators -/\n\nsection is_self_adjoint\n\n/-- A (not necessarily bounded) operator on an inner product space is self-adjoint, if for all\n`x`, `y`, we have `\u27eaT x, y\u27eb = \u27eax, T y\u27eb`. -/\ndef is_self_adjoint (T : E \u2192\u2097[\ud835\udd5c] E) : Prop := \u2200 x y, \u27eaT x, y\u27eb = \u27eax, T y\u27eb\n\n/-- An operator `T` on a `\u211d`-inner product space is self-adjoint if and only if it is\n`bilin_form.is_self_adjoint` with respect to the bilinear form given by the inner product. -/\nlemma is_self_adjoint_iff_bilin_form (T : F \u2192\u2097[\u211d] F) :\n  is_self_adjoint T \u2194 bilin_form_of_real_inner.is_self_adjoint T :=\nby simp [is_self_adjoint, bilin_form.is_self_adjoint, bilin_form.is_adjoint_pair]\n\nlemma is_self_adjoint.conj_inner_sym {T : E \u2192\u2097[\ud835\udd5c] E} (hT : is_self_adjoint T) (x y : E) :\n  conj \u27eaT x, y\u27eb = \u27eaT y, x\u27eb :=\nby rw [hT x y, inner_conj_sym]\n\n@[simp] lemma is_self_adjoint.apply_clm {T : E \u2192L[\ud835\udd5c] E} (hT : is_self_adjoint (T : E \u2192\u2097[\ud835\udd5c] E))\n  (x y : E) :\n  \u27eaT x, y\u27eb = \u27eax, T y\u27eb :=\nhT x y\n\n/-- For a self-adjoint operator `T`, the function `\u03bb x, \u27eaT x, x\u27eb` is real-valued. -/\n@[simp] lemma is_self_adjoint.coe_re_apply_inner_self_apply\n  {T : E \u2192L[\ud835\udd5c] E} (hT : is_self_adjoint (T : E \u2192\u2097[\ud835\udd5c] E)) (x : E) :\n  (T.re_apply_inner_self x : \ud835\udd5c) = \u27eaT x, x\u27eb :=\nbegin\n  suffices : \u2203 r : \u211d, \u27eaT x, x\u27eb = r,\n  { obtain \u27e8r, hr\u27e9 := this,\n    simp [hr, T.re_apply_inner_self_apply] },\n  rw \u2190 eq_conj_iff_real,\n  exact hT.conj_inner_sym x x\nend\n\n/-- If a self-adjoint operator preserves a submodule, its restriction to that submodule is\nself-adjoint. -/\nlemma is_self_adjoint.restrict_invariant {T : E \u2192\u2097[\ud835\udd5c] E} (hT : is_self_adjoint T)\n  {V : submodule \ud835\udd5c E} (hV : \u2200 v \u2208 V, T v \u2208 V) :\n  is_self_adjoint (T.restrict hV) :=\n\u03bb v w, hT v w\n\nend is_self_adjoint\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/inner_product_space/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.7207174998837934}}
{"text": "/-\nCopyright (c) 2022 Junyan Xu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa, Junyan Xu\n-/\nimport data.dfinsupp.basic\n\n/-!\n# Locus of unequal values of finitely supported dependent functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nLet `N : \u03b1 \u2192 Type*` be a type family, assume that `N a` has a `0` for all `a : \u03b1` and let\n`f g : \u03a0\u2080 a, N a` be finitely supported dependent functions.\n\n## Main definition\n\n* `dfinsupp.ne_locus f g : finset \u03b1`, the finite subset of `\u03b1` where `f` and `g` differ.\nIn the case in which `N a` is an additive group for all `a`, `dfinsupp.ne_locus f g` coincides with\n`dfinsupp.support (f - g)`.\n-/\n\nvariables {\u03b1 : Type*} {N : \u03b1 \u2192 Type*}\n\nnamespace dfinsupp\nvariable [decidable_eq \u03b1]\n\nsection N_has_zero\nvariables [\u03a0 a, decidable_eq (N a)] [\u03a0 a, has_zero (N a)] (f g : \u03a0\u2080 a, N a)\n\n/--  Given two finitely supported functions `f g : \u03b1 \u2192\u2080 N`, `finsupp.ne_locus f g` is the `finset`\nwhere `f` and `g` differ. This generalizes `(f - g).support` to situations without subtraction. -/\ndef ne_locus (f g : \u03a0\u2080 a, N a) : finset \u03b1 :=\n(f.support \u222a g.support).filter (\u03bb x, f x \u2260 g x)\n\n@[simp] lemma mem_ne_locus {f g : \u03a0\u2080 a, N a} {a : \u03b1} : a \u2208 f.ne_locus g \u2194 f a \u2260 g a :=\nby simpa only [ne_locus, finset.mem_filter, finset.mem_union, mem_support_iff,\n    and_iff_right_iff_imp] using ne.ne_or_ne _\n\nlemma not_mem_ne_locus {f g : \u03a0\u2080 a, N a} {a : \u03b1} : a \u2209 f.ne_locus g \u2194 f a = g a :=\nmem_ne_locus.not.trans not_ne_iff\n\n@[simp] lemma coe_ne_locus : \u2191(f.ne_locus g) = {x | f x \u2260 g x} :=\nset.ext $ \u03bb x, mem_ne_locus\n\n@[simp] lemma ne_locus_eq_empty {f g : \u03a0\u2080 a, N a} : f.ne_locus g = \u2205 \u2194 f = g :=\n\u27e8\u03bb h, ext (\u03bb a, not_not.mp (mem_ne_locus.not.mp (finset.eq_empty_iff_forall_not_mem.mp h a))),\n  \u03bb h, h \u25b8 by simp only [ne_locus, ne.def, eq_self_iff_true, not_true, finset.filter_false]\u27e9\n\n@[simp] lemma nonempty_ne_locus_iff {f g : \u03a0\u2080 a, N a} : (f.ne_locus g).nonempty \u2194 f \u2260 g :=\nfinset.nonempty_iff_ne_empty.trans ne_locus_eq_empty.not\n\nlemma ne_locus_comm : f.ne_locus g = g.ne_locus f :=\nby simp_rw [ne_locus, finset.union_comm, ne_comm]\n\n@[simp]\nlemma ne_locus_zero_right : f.ne_locus 0 = f.support :=\nby { ext, rw [mem_ne_locus, mem_support_iff, coe_zero, pi.zero_apply] }\n\n@[simp]\nlemma ne_locus_zero_left : (0 : \u03a0\u2080 a, N a).ne_locus f = f.support :=\n(ne_locus_comm _ _).trans (ne_locus_zero_right _)\n\nend N_has_zero\n\nsection ne_locus_and_maps\n\nvariables {M P : \u03b1 \u2192 Type*} [\u03a0 a, has_zero (N a)] [\u03a0 a, has_zero (M a)] [\u03a0 a, has_zero (P a)]\n\nlemma subset_map_range_ne_locus [\u03a0 a, decidable_eq (N a)] [\u03a0 a, decidable_eq (M a)]\n  (f g : \u03a0\u2080 a, N a) {F : \u03a0 a, N a \u2192 M a} (F0 : \u2200 a, F a 0 = 0) :\n  (f.map_range F F0).ne_locus (g.map_range F F0) \u2286 f.ne_locus g :=\n\u03bb a, by simpa only [mem_ne_locus, map_range_apply, not_imp_not] using congr_arg (F a)\n\nlemma zip_with_ne_locus_eq_left [\u03a0 a, decidable_eq (N a)] [\u03a0 a, decidable_eq (P a)]\n  {F : \u03a0 a, M a \u2192 N a \u2192 P a} (F0 : \u2200 a, F a 0 0 = 0)\n  (f : \u03a0\u2080 a, M a) (g\u2081 g\u2082 : \u03a0\u2080 a, N a) (hF : \u2200 a f, function.injective (\u03bb g, F a f g)) :\n  (zip_with F F0 f g\u2081).ne_locus (zip_with F F0 f g\u2082) = g\u2081.ne_locus g\u2082 :=\nby { ext, simpa only [mem_ne_locus] using (hF a _).ne_iff }\n\nlemma zip_with_ne_locus_eq_right [\u03a0 a, decidable_eq (M a)] [\u03a0 a, decidable_eq (P a)]\n  {F : \u03a0 a, M a \u2192 N a \u2192 P a} (F0 : \u2200 a, F a 0 0 = 0)\n  (f\u2081 f\u2082 : \u03a0\u2080 a, M a) (g : \u03a0\u2080 a, N a) (hF : \u2200 a g, function.injective (\u03bb f, F a f g)) :\n  (zip_with F F0 f\u2081 g).ne_locus (zip_with F F0 f\u2082 g) = f\u2081.ne_locus f\u2082 :=\nby { ext, simpa only [mem_ne_locus] using (hF a _).ne_iff }\n\n\n\nend ne_locus_and_maps\n\nvariables [\u03a0 a, decidable_eq (N a)]\n\n@[simp] lemma ne_locus_add_left [\u03a0 a, add_left_cancel_monoid (N a)] (f g h : \u03a0\u2080 a, N a) :\n  (f + g).ne_locus (f + h) = g.ne_locus h  :=\nzip_with_ne_locus_eq_left _ _ _ _ $ \u03bb a, add_right_injective\n\n@[simp] lemma ne_locus_add_right [\u03a0 a, add_right_cancel_monoid (N a)] (f g h : \u03a0\u2080 a, N a) :\n  (f + h).ne_locus (g + h) = f.ne_locus g  :=\nzip_with_ne_locus_eq_right _ _ _ _ $ \u03bb a, add_left_injective\n\nsection add_group\nvariables [\u03a0 a, add_group (N a)] (f f\u2081 f\u2082 g g\u2081 g\u2082 : \u03a0\u2080 a, N a)\n\n@[simp] lemma ne_locus_neg_neg : ne_locus (-f) (-g) = f.ne_locus g :=\nmap_range_ne_locus_eq _ _ (\u03bb a, neg_zero) (\u03bb a, neg_injective)\n\nlemma ne_locus_neg : ne_locus (-f) g = f.ne_locus (-g) := by rw [\u2190ne_locus_neg_neg, neg_neg]\n\nlemma ne_locus_eq_support_sub : f.ne_locus g = (f - g).support :=\nby rw [\u2190@ne_locus_add_right \u03b1 N _ _ _ _ _ (-g), add_right_neg, ne_locus_zero_right, sub_eq_add_neg]\n\n@[simp] lemma ne_locus_sub_left : ne_locus (f - g\u2081) (f - g\u2082) = ne_locus g\u2081 g\u2082 :=\nby simp only [sub_eq_add_neg, @ne_locus_add_left \u03b1 N _ _ _, ne_locus_neg_neg]\n\n@[simp] lemma ne_locus_sub_right : ne_locus (f\u2081 - g) (f\u2082 - g) = ne_locus f\u2081 f\u2082 :=\nby simpa only [sub_eq_add_neg] using @ne_locus_add_right \u03b1 N _ _ _ _ _ _\n\n@[simp] lemma ne_locus_self_add_right : ne_locus f (f + g) = g.support :=\nby rw [\u2190ne_locus_zero_left, \u2190@ne_locus_add_left \u03b1 N _ _ _ f 0 g, add_zero]\n\n@[simp] lemma ne_locus_self_add_left : ne_locus (f + g) f = g.support :=\nby rw [ne_locus_comm, ne_locus_self_add_right]\n\n@[simp] lemma ne_locus_self_sub_right : ne_locus f (f - g) = g.support :=\nby rw [sub_eq_add_neg, ne_locus_self_add_right, support_neg]\n\n@[simp] lemma ne_locus_self_sub_left : ne_locus (f - g) f = g.support :=\nby rw [ne_locus_comm, ne_locus_self_sub_right]\n\nend add_group\nend dfinsupp\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/dfinsupp/ne_locus.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7207030250636627}}
{"text": "/-\n2006 STEP 3 Question 8\n-/\n\nimport data.polynomial\n       data.real.basic\n       tactic\n\nopen polynomial\n\n/-\n\u0394 is a function takes takes polynomials in x to polynomials in x; that is, given\nany polynomial h(x), there is a polynomial called \u0394h(x) which is obtained from\nh(x) using the rules that define \u0394.\n-/\n\nvariable \u0394 : polynomial \u211d \u2192 polynomial \u211d\ninclude \u0394\n\n/-\nThese rules are as follows\n-/\n\nvariable \u03941 : \u0394 X = C 1\nvariable \u03942 : \u2200 (f g : polynomial \u211d), \u0394(f + g) = \u0394 f + \u0394 g\nvariable \u03943 : \u2200 (k : \u211d) (f : polynomial \u211d), \u0394(C k * f) = C k * \u0394 f\nvariable \u03944 : \u2200 (f g : polynomial \u211d), \u0394(f * g) = f * \u0394 g + g * \u0394 f\ninclude \u03941 \u03942 \u03943 \u03944\n\n/-\nUsing these rules show that, if f(x) is a polynomial of degree zero (that is, a\nconstant), then \u0394 f(x) = 0.\n-/\n\n-- First, show that \u0394 1 is 0\nlemma \u0394_one : \u0394 (C 1) = 0 := begin\n-- If we can prove that \u0394 1 + \u0394 1 = \u0394 1, then \u0394 1 = 0 follows\n-- Therefore we have a proof of \u0394 1 = 0 if we have a proof of \u0394 1 + \u0394 1 = \u0394 1\n suffices H : \u0394 1 + \u0394 1 = \u0394 1,\n    rwa add_left_eq_self at H,\n-- \u0394 1 + \u0394 1 = \u0394 (1 * 1)\n  conv begin to_rhs,\n    rw (show (1 : polynomial \u211d) = 1 * 1, by ring),\n  end,\n-- By rule 4, this expands\n  rw \u03944,\n-- This then simplifies down to our desired result\n  ring,\nend\n\n-- Having shown that \u0394 1 is 0, \u0394 c (for c \u2208 \u211d), is also 0\nlemma \u0394_const (a : \u211d) : \u0394 (C a) = 0 := begin\n-- \u0394 c = \u0394 (c * 1)\n  rw (show (C a) = (C a) * (C 1), by rw [<-C_mul,mul_one]),\n-- By rule 3 we can expand this\n  rw \u03943,\n-- We know from above that \u0394 1 is 0\n  rw \u0394_one \u0394, simp,\n-- Therefore \u0394 c must be 0\n  repeat {assumption}\nend\n\n/-\nCalculate \u0394x^2 and \u0394x^3\n-/\n\nlemma \u0394Xsquared : \u0394 (X^2) = 2*X := begin\n-- \u0394 (x^2) = \u0394 (x*x)\n  rw pow_two,\n-- By rule 4, this is the same as X * \u0394 X + X * \u0394 X\n  rw \u03944,\n-- By rule 1, this is just X * 1 + X * 1\n  rw \u03941,\n-- Which is 2*X\n  rw mul_comm,\n  rw <-add_mul,\n  norm_num,\nend\n\nlemma \u0394Xcubed : \u0394 (X^3) = 3*X^2 := begin\n-- \u0394 (x^3) = \u0394 (x * x^2)\n  rw (show (X:polynomial \u211d)^3 = X * X^2, by ring),\n-- Use rule 4 to expand this\n  rw \u03944,\n-- Then use the result for \u0394x^2\n  rw \u0394Xsquared \u0394, rw <-mul_assoc, rw \u03941, rw mul_comm, rw <-mul_assoc,\n  rw <-pow_two, rw <-mul_add, rw mul_comm, refl,\n\n  repeat {assumption},\nend\n\n/-\nProve that \u0394h(x) \u2261 dh(x)/dx for any polynomial h(x). You should make it clear\nwhenever you use one of the above rules in your proof.\n-/\n\nlemma \u0394Xn (n : \u2115) : \u0394 (X^(n+1)) = C (n+1)*X^n := begin\n    induction n with d hd,\n  { -- base case\n    rw [pow_one, \u03941, nat.cast_zero],\n    simp,\n  },\n  rw [nat.succ_eq_add_one, pow_succ, \u03944, \u03941, hd, pow_succ,\n    nat.cast_add, nat.cast_one],\n  rw (show C (1:\u211d) = 1, by simp),\n  simp,\n  ring,\nend\n\nlemma \u0394_is_derivative (p : polynomial \u211d) : \u0394 p = derivative p :=\nbegin\n  apply p.induction_on,\n  { intro a, rw \u0394_const \u0394, simp, repeat {assumption}},\n  { intros p q hp hq, rw \u03942, rw hp, rw hq, simp,},\n  intros a n IH,\n  rw [\u03944, \u0394_const \u0394, \u0394Xn \u0394, mul_zero, add_zero, derivative_monomial, <-mul_assoc],\n  simp,\n  repeat {assumption},\nend", "meta": {"author": "shingtaklam1324", "repo": "step3-06-q8-lean", "sha": "20e5161fab8b5c3c2dd051bd707a26f1dc50dac2", "save_path": "github-repos/lean/shingtaklam1324-step3-06-q8-lean", "path": "github-repos/lean/shingtaklam1324-step3-06-q8-lean/step3-06-q8-lean-20e5161fab8b5c3c2dd051bd707a26f1dc50dac2/src/step3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.7206975622424466}}
{"text": "/-\nCopyright (c) 2020 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n\n! This file was ported from Lean 3 source module data.polynomial.lifts\n! leanprover-community/mathlib commit 63417e01fbc711beaf25fa73b6edb395c0cfddd0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.AlgebraMap\nimport Mathlib.Data.Polynomial.Monic\n\n/-!\n# Polynomials that lift\n\nGiven semirings `R` and `S` with a morphism `f : R \u2192+* S`, we define a subsemiring `lifts` of\n`S[X]` by the image of `RingHom.of (map f)`.\nThen, we prove that a polynomial that lifts can always be lifted to a polynomial of the same degree\nand that a monic polynomial that lifts can be lifted to a monic polynomial (of the same degree).\n\n## Main definition\n\n* `lifts (f : R \u2192+* S)` : the subsemiring of polynomials that lift.\n\n## Main results\n\n* `lifts_and_degree_eq` : A polynomial lifts if and only if it can be lifted to a polynomial\nof the same degree.\n* `lifts_and_degree_eq_and_monic` : A monic polynomial lifts if and only if it can be lifted to a\nmonic polynomial of the same degree.\n* `lifts_iff_alg` : if `R` is commutative, a polynomial lifts if and only if it is in the image of\n`mapAlg`, where `mapAlg : R[X] \u2192\u2090[R] S[X]` is the only `R`-algebra map\nthat sends `X` to `X`.\n\n## Implementation details\n\nIn general `R` and `S` are semiring, so `lifts` is a semiring. In the case of rings, see\n`lifts_iff_lifts_ring`.\n\nSince we do not assume `R` to be commutative, we cannot say in general that the set of polynomials\nthat lift is a subalgebra. (By `lift_iff` this is true if `R` is commutative.)\n\n-/\n\n\nopen Classical BigOperators Polynomial\n\nnoncomputable section\n\nnamespace Polynomial\n\nuniverse u v w\n\nsection Semiring\n\nvariable {R : Type u} [Semiring R] {S : Type v} [Semiring S] {f : R \u2192+* S}\n\n/-- We define the subsemiring of polynomials that lifts as the image of `RingHom.of (map f)`. -/\ndef lifts (f : R \u2192+* S) : Subsemiring S[X] :=\n  RingHom.rangeS (mapRingHom f)\n#align polynomial.lifts Polynomial.lifts\n\ntheorem mem_lifts (p : S[X]) : p \u2208 lifts f \u2194 \u2203 q : R[X], map f q = p := by\n  simp only [coe_mapRingHom, lifts, RingHom.mem_rangeS]\n#align polynomial.mem_lifts Polynomial.mem_lifts\n\ntheorem lifts_iff_set_range (p : S[X]) : p \u2208 lifts f \u2194 p \u2208 Set.range (map f) := by\n  simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS]\n#align polynomial.lifts_iff_set_range Polynomial.lifts_iff_set_range\n\ntheorem lifts_iff_ringHom_rangeS (p : S[X]) : p \u2208 lifts f \u2194 p \u2208 (mapRingHom f).rangeS := by\n  simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS]\n#align polynomial.lifts_iff_ring_hom_srange Polynomial.lifts_iff_ringHom_rangeS\n\ntheorem lifts_iff_coeff_lifts (p : S[X]) : p \u2208 lifts f \u2194 \u2200 n : \u2115, p.coeff n \u2208 Set.range f := by\n  rw [lifts_iff_ringHom_rangeS, mem_map_rangeS f]\n  rfl\n#align polynomial.lifts_iff_coeff_lifts Polynomial.lifts_iff_coeff_lifts\n\n/-- If `(r : R)`, then `C (f r)` lifts. -/\ntheorem C_mem_lifts (f : R \u2192+* S) (r : R) : C (f r) \u2208 lifts f :=\n  \u27e8C r, by\n    simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true,\n      and_self_iff]\u27e9\nset_option linter.uppercaseLean3 false in\n#align polynomial.C_mem_lifts Polynomial.C_mem_lifts\n\n/-- If `(s : S)` is in the image of `f`, then `C s` lifts. -/\ntheorem C'_mem_lifts {f : R \u2192+* S} {s : S} (h : s \u2208 Set.range f) : C s \u2208 lifts f := by\n  obtain \u27e8r, rfl\u27e9 := Set.mem_range.1 h\n  use C r\n  simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true,\n    and_self_iff]\nset_option linter.uppercaseLean3 false in\n#align polynomial.C'_mem_lifts Polynomial.C'_mem_lifts\n\n/-- The polynomial `X` lifts. -/\ntheorem X_mem_lifts (f : R \u2192+* S) : (X : S[X]) \u2208 lifts f :=\n  \u27e8X, by\n    simp only [coe_mapRingHom, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, map_X,\n      and_self_iff]\u27e9\nset_option linter.uppercaseLean3 false in\n#align polynomial.X_mem_lifts Polynomial.X_mem_lifts\n\n/-- The polynomial `X ^ n` lifts. -/\ntheorem X_pow_mem_lifts (f : R \u2192+* S) (n : \u2115) : (X ^ n : S[X]) \u2208 lifts f :=\n  \u27e8X ^ n, by\n    simp only [coe_mapRingHom, map_pow, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true,\n      map_X, and_self_iff]\u27e9\nset_option linter.uppercaseLean3 false in\n#align polynomial.X_pow_mem_lifts Polynomial.X_pow_mem_lifts\n\n/-- If `p` lifts and `(r : R)` then `r * p` lifts. -/\ntheorem base_mul_mem_lifts {p : S[X]} (r : R) (hp : p \u2208 lifts f) : C (f r) * p \u2208 lifts f := by\n  simp only [lifts, RingHom.mem_rangeS] at hp\u22a2\n  obtain \u27e8p\u2081, rfl\u27e9 := hp\n  use C r * p\u2081\n  simp only [coe_mapRingHom, map_C, map_mul]\n#align polynomial.base_mul_mem_lifts Polynomial.base_mul_mem_lifts\n\n/-- If `(s : S)` is in the image of `f`, then `monomial n s` lifts. -/\ntheorem monomial_mem_lifts {s : S} (n : \u2115) (h : s \u2208 Set.range f) : monomial n s \u2208 lifts f := by\n  obtain \u27e8r, rfl\u27e9 := Set.mem_range.1 h\n  use monomial n r\n  simp only [coe_mapRingHom, Set.mem_univ, map_monomial, Subsemiring.coe_top, eq_self_iff_true,\n    and_self_iff]\n#align polynomial.monomial_mem_lifts Polynomial.monomial_mem_lifts\n\n/-- If `p` lifts then `p.erase n` lifts. -/\ntheorem erase_mem_lifts {p : S[X]} (n : \u2115) (h : p \u2208 lifts f) : p.erase n \u2208 lifts f := by\n  rw [lifts_iff_ringHom_rangeS, mem_map_rangeS] at h\u22a2\n  intro k\n  by_cases hk : k = n\n  \u00b7 use 0\n    simp only [hk, RingHom.map_zero, erase_same]\n  obtain \u27e8i, hi\u27e9 := h k\n  use i\n  simp only [hi, hk, erase_ne, Ne.def, not_false_iff]\n#align polynomial.erase_mem_lifts Polynomial.erase_mem_lifts\n\nsection LiftDeg\n\ntheorem monomial_mem_lifts_and_degree_eq {s : S} {n : \u2115} (hl : monomial n s \u2208 lifts f) :\n    \u2203 q : R[X], map f q = monomial n s \u2227 q.degree = (monomial n s).degree := by\n  by_cases hzero : s = 0\n  \u00b7 use 0\n    simp only [hzero, degree_zero, eq_self_iff_true, and_self_iff, monomial_zero_right,\n      Polynomial.map_zero]\n  rw [lifts_iff_set_range] at hl\n  obtain \u27e8q, hq\u27e9 := hl\n  replace hq := (ext_iff.1 hq) n\n  have hcoeff : f (q.coeff n) = s := by\n    simp [coeff_monomial] at hq\n    exact hq\n  use monomial n (q.coeff n)\n  constructor\n  \u00b7 simp only [hcoeff, map_monomial]\n  have hqzero : q.coeff n \u2260 0 := by\n    intro habs\n    simp only [habs, RingHom.map_zero] at hcoeff\n    exact hzero hcoeff.symm\n  rw [\u2190 C_mul_X_pow_eq_monomial]\n  rw [\u2190 C_mul_X_pow_eq_monomial]\n  simp only [hzero, hqzero, Ne.def, not_false_iff, degree_C_mul_X_pow]\n#align polynomial.monomial_mem_lifts_and_degree_eq Polynomial.monomial_mem_lifts_and_degree_eq\n\n/-- A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. -/\ntheorem mem_lifts_and_degree_eq {p : S[X]} (hlifts : p \u2208 lifts f) :\n    \u2203 q : R[X], map f q = p \u2227 q.degree = p.degree := by\n  generalize hd : p.natDegree = d\n  revert hd p\n  induction' d using Nat.strong_induction_on with n hn\n  intros p hlifts hdeg\n  by_cases erase_zero : p.eraseLead = 0\n  \u00b7 rw [\u2190 eraseLead_add_monomial_natDegree_leadingCoeff p, erase_zero, zero_add, leadingCoeff]\n    exact\n      monomial_mem_lifts_and_degree_eq\n        (monomial_mem_lifts p.natDegree ((lifts_iff_coeff_lifts p).1 hlifts p.natDegree))\n  have deg_erase := Or.resolve_right (eraseLead_natDegree_lt_or_eraseLead_eq_zero p) erase_zero\n  have pzero : p \u2260 0 := by\n    intro habs\n    exfalso\n    rw [habs, eraseLead_zero, eq_self_iff_true, not_true] at erase_zero\n    exact erase_zero\n  have lead_zero : p.coeff p.natDegree \u2260 0 := by\n    rw [\u2190 leadingCoeff, Ne.def, leadingCoeff_eq_zero] ; exact pzero\n  obtain \u27e8lead, hlead\u27e9 :=\n    monomial_mem_lifts_and_degree_eq\n      (monomial_mem_lifts p.natDegree ((lifts_iff_coeff_lifts p).1 hlifts p.natDegree))\n  have deg_lead : lead.degree = p.natDegree := by\n    rw [hlead.2, \u2190 C_mul_X_pow_eq_monomial, degree_C_mul_X_pow p.natDegree lead_zero]\n  rw [hdeg] at deg_erase\n  obtain \u27e8erase, herase\u27e9 :=\n    hn p.eraseLead.natDegree deg_erase (erase_mem_lifts p.natDegree hlifts)\n      (refl p.eraseLead.natDegree)\n  use erase + lead\n  constructor\n  \u00b7 simp only [hlead, herase, Polynomial.map_add]\n    rw [\u2190eraseLead, \u2190leadingCoeff]\n    rw [eraseLead_add_monomial_natDegree_leadingCoeff p]\n  rw [degree_eq_natDegree pzero, \u2190deg_lead]\n  apply degree_add_eq_right_of_degree_lt\n  rw [herase.2, deg_lead, \u2190degree_eq_natDegree pzero]\n  exact degree_erase_lt pzero\n#align polynomial.mem_lifts_and_degree_eq Polynomial.mem_lifts_and_degree_eq\n\nend LiftDeg\n\nsection Monic\n\n/-- A monic polynomial lifts if and only if it can be lifted to a monic polynomial\nof the same degree. -/\ntheorem lifts_and_degree_eq_and_monic [Nontrivial S] {p : S[X]} (hlifts : p \u2208 lifts f)\n    (hp : p.Monic) : \u2203 q : R[X], map f q = p \u2227 q.degree = p.degree \u2227 q.Monic := by\n  cases' subsingleton_or_nontrivial R with hR hR\n  \u00b7 obtain \u27e8q, hq\u27e9 := mem_lifts_and_degree_eq hlifts\n    exact \u27e8q, hq.1, hq.2, monic_of_subsingleton _\u27e9\n  have H : erase p.natDegree p + X ^ p.natDegree = p := by\n    simpa only [hp.leadingCoeff, C_1, one_mul, eraseLead] using eraseLead_add_C_mul_X_pow p\n  by_cases h0 : erase p.natDegree p = 0\n  \u00b7 rw [\u2190 H, h0, zero_add]\n    refine' \u27e8X ^ p.natDegree, _, _, monic_X_pow p.natDegree\u27e9\n    \u00b7 rw [Polynomial.map_pow, map_X]\n    \u00b7 rw [degree_X_pow, degree_X_pow]\n  obtain \u27e8q, hq\u27e9 := mem_lifts_and_degree_eq (erase_mem_lifts p.natDegree hlifts)\n  have p_neq_0 : p \u2260 0 := by intro hp; apply h0; rw [hp]; simp only [natDegree_zero, erase_zero]\n  have hdeg : q.degree < (X ^ p.natDegree).degree := by\n    rw [@degree_X_pow R, hq.2, \u2190degree_eq_natDegree p_neq_0]\n    exact degree_erase_lt p_neq_0\n  refine' \u27e8q + X ^ p.natDegree, _, _, (monic_X_pow _).add_of_right hdeg\u27e9\n  \u00b7 rw [Polynomial.map_add, hq.1, Polynomial.map_pow, map_X, H]\n  \u00b7 rw [degree_add_eq_right_of_degree_lt hdeg, degree_X_pow, degree_eq_natDegree hp.ne_zero]\n#align polynomial.lifts_and_degree_eq_and_monic Polynomial.lifts_and_degree_eq_and_monic\n\ntheorem lifts_and_natDegree_eq_and_monic {p : S[X]} (hlifts : p \u2208 lifts f) (hp : p.Monic) :\n    \u2203 q : R[X], map f q = p \u2227 q.natDegree = p.natDegree \u2227 q.Monic := by\n  cases' subsingleton_or_nontrivial S with hR hR\n  \u00b7 obtain rfl : p = 1 := Subsingleton.elim _ _\n    refine' \u27e81, Subsingleton.elim _ _, by simp, by simp\u27e9\n  obtain \u27e8p', h\u2081, h\u2082, h\u2083\u27e9 := lifts_and_degree_eq_and_monic hlifts hp\n  exact \u27e8p', h\u2081, natDegree_eq_of_degree_eq h\u2082, h\u2083\u27e9\n#align polynomial.lifts_and_nat_degree_eq_and_monic Polynomial.lifts_and_natDegree_eq_and_monic\n\nend Monic\n\nend Semiring\n\nsection Ring\n\nvariable {R : Type u} [Ring R] {S : Type v} [Ring S] (f : R \u2192+* S)\n\n/-- The subring of polynomials that lift. -/\ndef liftsRing (f : R \u2192+* S) : Subring S[X] :=\n  RingHom.range (mapRingHom f)\n#align polynomial.lifts_ring Polynomial.liftsRing\n\n/-- If `R` and `S` are rings, `p` is in the subring of polynomials that lift if and only if it is in\nthe subsemiring of polynomials that lift. -/\ntheorem lifts_iff_liftsRing (p : S[X]) : p \u2208 lifts f \u2194 p \u2208 liftsRing f := by\n  simp only [lifts, liftsRing, RingHom.mem_range, RingHom.mem_rangeS]\n#align polynomial.lifts_iff_lifts_ring Polynomial.lifts_iff_liftsRing\n\nend Ring\n\nsection Algebra\n\nvariable {R : Type u} [CommSemiring R] {S : Type v} [Semiring S] [Algebra R S]\n\n/-- The map `R[X] \u2192 S[X]` as an algebra homomorphism. -/\ndef mapAlg (R : Type u) [CommSemiring R] (S : Type v) [Semiring S] [Algebra R S] :\n    R[X] \u2192\u2090[R] S[X] :=\n  @aeval _ S[X] _ _ _ (X : S[X])\n#align polynomial.map_alg Polynomial.mapAlg\n\n/-- `mapAlg` is the morphism induced by `R \u2192 S`. -/\ntheorem mapAlg_eq_map (p : R[X]) : mapAlg R S p = map (algebraMap R S) p := by\n  simp only [mapAlg, aeval_def, eval\u2082_eq_sum, map, algebraMap_apply, RingHom.coe_comp]\n  ext; congr\n#align polynomial.map_alg_eq_map Polynomial.mapAlg_eq_map\n\n/-- A polynomial `p` lifts if and only if it is in the image of `mapAlg`. -/\ntheorem mem_lifts_iff_mem_alg (R : Type u) [CommSemiring R] {S : Type v} [Semiring S] [Algebra R S]\n    (p : S[X]) : p \u2208 lifts (algebraMap R S) \u2194 p \u2208 AlgHom.range (@mapAlg R _ S _ _) := by\n  simp only [coe_mapRingHom, lifts, mapAlg_eq_map, AlgHom.mem_range, RingHom.mem_rangeS]\n#align polynomial.mem_lifts_iff_mem_alg Polynomial.mem_lifts_iff_mem_alg\n\n/-- If `p` lifts and `(r : R)` then `r \u2022 p` lifts. -/\ntheorem smul_mem_lifts {p : S[X]} (r : R) (hp : p \u2208 lifts (algebraMap R S)) :\n    r \u2022 p \u2208 lifts (algebraMap R S) := by\n  rw [mem_lifts_iff_mem_alg] at hp\u22a2\n  exact Subalgebra.smul_mem (mapAlg R S).range hp r\n#align polynomial.smul_mem_lifts Polynomial.smul_mem_lifts\n\nend Algebra\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Lifts.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7206975508019522}}
{"text": "-- a \"possible world\" is just a non-negative integer w, representing\n-- the number of blue-eyed islanders in that world.\n\n-- If d (the day) and s (the number of are also non-negative integers, the function thinks(d,s,w) represents an\n-- islander's opinion of possible world w on day d, given that they can \n-- see s blue-eyed islanders and we have made it to day d without anyone leaving.\n-- The output of the function is either \"true\",\n-- meaning \"I think that this is still logically possible\", or \"false\", meaning \"this\n-- world is not possible any more\". \n\ndef thinks : \u2115 \u2192 \u2115 \u2192 \u2115 \u2192 Prop \n-- on day zero...\n| 0 s w := \n              -- \"my eyes are either blue or brown, and...\"\n              (w = s \u2228 w = s + 1) \u2227 \n              -- \"the traveller said there is a blue-eyed islander so w=0 is not a possible world\" \n              (w \u2260 0)\n-- on day d+1, if nobody left on day d,\n| (d+1) s w := \n          -- \"I still know everything that I knew yesterday, and...\"\n              (thinks d s w) \u2227 \n                -- I also know that whatever colour my eyes _actually_ are,\n                -- the blue-eyed islanders could not work out their eye colour yesterday.\n                -- Hence one of the following is true:\n                ( -- either I have blue eyes and I couldn't work this out yesterday\n                  -- because I couldn't rule out having brown eyes\n                  (w=s+1 \u2227 thinks d s s)\n                  -- or\n                  \u2228 \n                  -- I have brown eyes and the blue-eyed Islanders could not \n                  -- figure out their eye colour because there was more than one possibility\n                  (w=s \u2227 s \u2260 0 \u2227 thinks d (s-1) (s-1) \u2227 thinks d (s-1) s)\n                )\n--test suite\n\n-- if there are 3 blue-eyed islanders then even on day 0 they\n-- must believe that there are either 3 or 4 blue eyed islanders.\nexample : thinks 0 3 0 \u2192 false := by unfold thinks;simp\n\nexample : thinks 0 3 7 \u2192 false := begin\nunfold thinks,\nexact dec_trivial,\nend \n\n-- If there is one blue-eyed islander then on day 1 he leaves so we cannot find\n-- islanders (with blue or brown eyes) mulling this situation over on day 2\n\n-- Here's what this looks like as a brown-eyed islander:\nexample : thinks 2 1 1 \u2192 false := begin\nunfold thinks,\nsimp,exact dec_trivial,\nend\n\n-- Here's what this looks like to a blue-eyed islander:\n\nexample : thinks 2 0 1 \u2192 false := begin\nunfold thinks,\nsimp,\nend \n\n-- So in general we cannot get to day 2 with no leavers if there is one blue-eyed islander.\n\nexample : \u2200 s, thinks 2 s 1 \u2192 false := begin\nintro s,cases s with t,\nunfold thinks,simp,\ncases t with u,\nunfold thinks,simp,exact dec_trivial,\nunfold thinks,intro H,\nhave H2:= H.left.left.left,\nrevert H2,\nexact dec_trivial,\nend\n\n-- Basic lemma with easy induction proof: if (on any day at all) an Islander\n-- can see s blue-eyed islanders, then the only possible worlds have\n-- w=s or w=s+1.\n\nlemma blue_or_brown (d s w) : thinks d s w \u2192 w = s \u2228 w = s + 1 :=\nbegin\ninduction d with d Hd,\n{ exact and.elim_left },\nintro H,\napply Hd,\nexact H.left\nend \n\n-- The general theorem is that for all worlds w, we cannot make it to day w+1\n\ntheorem blue_eyed_islanders_leave : \u2200 w, \u2200 s, thinks (w+1) s w \u2192 false := begin\nintro w,\ninduction w with w Hw,\n-- base case easy\n{ intros s H,\n  unfold thinks at H,\n  let H3 : 0 \u2260 0 := H.left.right,\n  apply H3,simp,\n},\n-- inductive step\nintros s H, -- H : thinks (nat.succ w + 1) s (nat.succ w)\n-- d=w+1,w=w+1\nhave H2 : thinks (w+1) s (w+1) \n          \u2227 ((w+1=s+1 \u2227 thinks (w+1) s s) \n           \u2228 (w+1=s \u2227 s\u22600 \u2227 thinks (w+1) (s-1) (s-1) \u2227 thinks (w+1) (s-1) s)),\n  exact H,\nclear H,\nhave H3 : ((w+1=s+1 \u2227 thinks (w+1) s s) \n           \u2228 (w+1=s \u2227 s\u22600 \u2227 thinks (w+1) (s-1) (s-1) \u2227 thinks (w+1) (s-1) s)),\nexact H2.right,\nclear H2,\ncases H3 with H4 H5,\n{ apply (Hw s),\n  have H6 : w = s := nat.succ_inj H4.1,\n  have H7 : thinks (w+1) s s = thinks (w+1) s w := congr_arg (\u03bb t, thinks (w+1) s t) (eq.symm H6),\n  rw eq.symm H7,\n  exact H4.right\n},\n{ have H1 : w=s-1,rw H5.left.symm,simp,\n  apply Hw (s-1),\n  have H2 : thinks (w + 1) (s - 1) w = thinks (w + 1) (s - 1) (s - 1) :=\n    congr_arg _ H1,\n  rw H2,\n  exact H5.right.right.left\n}\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/2017-18/Example_Sheet_05/KB_islander_ideas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7206975483526205}}
{"text": "import .src_ordered_field tactic\n\nnamespace mth1001\n\nnamespace myreal\n\nsection ordered\n\nvariables {R : Type} [myordered_field R]\n\nopen_locale classical\n\nopen myordered_field\n\nlemma pos_one : pos (1 : R) :=\nbegin\n  rcases trichotomy (1 : R) with \u27e8hpo, _, _ \u27e9 | \u27e8_, hoe, _ \u27e9  | \u27e8hnpo, hnoe, hpno\u27e9 ,\n  { exact hpo, },\n  { exact absurd hoe zero_ne_one.symm, },\n  { exfalso, apply hnpo,\n    convert pos_mul_of_pos_of_pos _ _ hpno hpno,\n    rw [neg_mul_neg_self, one_mul], },\nend\n\nlemma pos_nat (n : \u2115) : n \u2260 0 \u2192 pos (n : R) :=\nbegin\n  induction n with k hk,\n  { intro _, contradiction, },\n  { intro _,\n    rw coe_nat_succ,\n    by_cases h\u2081 : k = 0,\n    { rw h\u2081,\n      change pos((0 : R) + (1 : R)),\n      rw zero_add,\n      exact pos_one, },\n    { exact pos_add_of_pos_of_pos _ _ (hk h\u2081) pos_one }, },\nend\n\nlemma lt_iff_pos_sub (x y : R) : x < y \u2194 pos (y -x) := by refl\n\nlemma lt_iff_pos_neg (x y : R) : x < y \u2194 pos (y + -x) := by refl\n\nlemma zero_lt_one' : (0 : R) < (1 : R) :=\nbegin\n  rw [lt_iff_pos_sub, sub_zero],\n  exact pos_one,\nend\n\n\nlemma gt_zero_mul_of_gt_zero_of_gt_zero {a b : R} (h\u2081 : 0 < a) (h\u2082 : 0 < b) : 0 < a * b :=\nbegin\n  rw [lt_iff_pos_sub, sub_zero] at *,\n  exact pos_mul_of_pos_of_pos a b h\u2081 h\u2082,\nend\n\nlemma mul_pos (a b : R) : 0 < a \u2192 0 < b \u2192 0 < a * b :=\nbegin\n  intros h\u2081 h\u2082,\n  rw [lt_iff_pos_sub, sub_zero] at *,\n  exact pos_mul_of_pos_of_pos a b h\u2081 h\u2082,\nend\n\nlemma neg_pos {x : R} : 0 < -x \u2194 x < 0:=\nbegin\n  repeat {rw lt_iff_pos_neg},\n  rw zero_add,\n  have : -(0 : R) = (0 : R),\n  { rw [\u2190add_zero (-(0 : R) : R), neg_add], },\n  rw [this, add_zero],\nend\n\nlemma trichotomy' (x y: R) : x < y \u2227 \u00acx = y \u2227 \u00acy < x \u2228\n                               \u00acx < y \u2227 x = y \u2227 \u00acy < x \u2228\n                               \u00acx < y \u2227 \u00acx = y \u2227 y < x :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  have : x - y = -(y - x),\n  { rw [sub_eq_add_neg', sub_eq_add_neg', neg_add_eq_neg_add_neg', neg_neg], },\n  rw this,\n  rw [@eq_comm _ x y, (sub_eq_zero_iff_eq y x).symm],\n  exact trichotomy (y + -x),\nend\n\nlemma lt_trans {x y z : R} : x < y \u2192 y < z \u2192 x < z :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  intros pyx pzy,\n  have : z - x = (z - y) + (y - x),\n  { repeat {rw sub_eq_add_neg'},\n    rw [\u2190add_assoc, add_assoc z _ _, neg_add, add_zero], },\n  rw this,\n  exact pos_add_of_pos_of_pos _ _ pzy pyx,\nend\n\nlemma add_lt_add_iff_right_mpr {x y : R} (z : R) : x < y \u2192 x + z < y + z :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  apply eq.substr,\n  rw [sub_eq_add_neg', neg_add_eq_neg_add_neg', \u2190add_assoc],\n  rw [add_assoc y, add_neg', add_zero, sub_eq_add_neg'],\nend\n\nlemma add_lt_add_iff_right_mp {x y : R} (z : R) : x + z < y + z \u2192 x < y :=\nbegin\n  intro h,\n  convert add_lt_add_iff_right_mpr (-z) h;\n  rw [add_assoc, add_neg', add_zero],\nend\n\nlemma add_lt_add_iff_right {x y : R} (z : R) : x + z < y + z \u2194 x < y :=\niff.intro (add_lt_add_iff_right_mp z) (add_lt_add_iff_right_mpr z)\n\ntheorem neg_lt_neg_iff  {a b : R} : -a < -b \u2194 b < a :=\nbegin\n  have h\u2081 : -a < -b \u2194 -a + a < -b + a, from (add_lt_add_iff_right a).symm,\n  have h\u2082 : b < a \u2194 b + -a < a + -a, from (add_lt_add_iff_right (-a)).symm,\n  have h\u2083 : -b + a = - (b + -a), \n  { rw [neg_add_eq_neg_add_neg', neg_neg, add_comm], },\n  rw [h\u2081, h\u2082, neg_add, add_neg', h\u2083, neg_pos],\nend\n\nlemma mul_lt_mul_left_mpr {x y z : R} : 0 < z \u2192 x < y \u2192 z * x < z * y :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  rw [\u2190mul_sub, sub_zero],\n  exact pos_mul_of_pos_of_pos _ _,\nend\n\ntheorem add_lt_add {a b c d : R} : a < b \u2192 c < d \u2192 a + c < b + d :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  intros h\u2081 h\u2082, \n  convert pos_add_of_pos_of_pos _ _ h\u2081 h\u2082,\n  repeat {rw sub_eq_add_neg'},\n  rw neg_add_eq_neg_add_neg',\n  rw [add_assoc, add_comm (-c) (-a), \u2190add_assoc d, add_comm d (-a), add_assoc (-a), \u2190add_assoc],\nend\n\nlemma lt_irrefl {x : R} : \u00acx < x :=\nbegin\n  rcases (trichotomy' x x) with \u27e8_, _, nxx\u27e9 | \u27e8nxx, _\u27e9 | \u27e8nxx, _\u27e9;\n  exact nxx,\nend\n\ntheorem ne_of_gt {a b : R} (h : b < a) : a \u2260 b :=\n\u03bb k, lt_irrefl (@eq.subst _ (\u03bb x, b < x) a b k h)\n\nlemma le_iff_lt_or_eq {x y : R} : x \u2264 y \u2194 ((x < y) \u2228 x = y) := by refl\n\nlemma zero_le_one : (0 : R) \u2264 1 :=\nbegin\n  rw le_iff_lt_or_eq,\n  exact or.inl zero_lt_one',\nend\n\nlemma le_refl (x : R) : x \u2264 x := or.inr rfl\n\nlemma not_le_iff_lt (x y : R) : \u00ac(x \u2264 y) \u2194 (y < x) :=\nbegin\n  rw le_iff_lt_or_eq,\n  push_neg,\n  rcases trichotomy' x y with \u27e8hxlty, _, _\u27e9 | \u27e8_, hxy, hnyltx \u27e9  | \u27e8hnxlty, hnxy, hxlty \u27e9 ,\n  { split,\n    { rintro \u27e8hnxy, _\u27e9,\n      contradiction, },\n    { intros hyltx, exfalso,\n      exact lt_irrefl (lt_trans hxlty hyltx), }, },\n  { split,\n    { rintro \u27e8_, hnxy\u27e9,\n      contradiction, },\n    { intro hyltx, contradiction, }, },\n  { split,\n    { intro _, exact hxlty, },\n    { intro _, exact \u27e8hnxlty, hnxy\u27e9, }, },\nend\n\nlemma not_lt_iff_le (x y : R) : \u00ac(x < y) \u2194 (y \u2264 x) :=\nby rw [\u2190not_le_iff_lt, not_not]\n\n\nlemma lt_iff_le_not_le (a b : R) : a < b \u2194 a \u2264 b \u2227 \u00acb \u2264 a :=\nbegin\n  rw [not_le_iff_lt, le_iff_lt_or_eq, or_and_distrib_right, and_self],\n  exact \u27e8\u03bb h, or.inl h, \u03bb h, or.elim h id (\u03bb k, k.2)\u27e9,\nend\n\nlemma neg_nonneg {x : R} : 0 \u2264 -x \u2194 x \u2264 0 :=\nbegin\n  repeat {rw le_iff_lt_or_eq},\n  have k : 0 < -x \u2194 x < 0, from neg_pos,\n  split,\n  { rintro (h\u2081 | h\u2082),\n    { left, rwa \u2190k, },\n    { right, rw [\u2190neg_neg x, \u2190h\u2082, neg_zero], } },\n  { rintro (h | rfl), \n    { left, rwa k, },\n    { right, rw neg_zero, }, },\nend\n\nlemma le_trans (x y z : R) : x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z :=\nbegin\n  rintro (h\u2081 | rfl) (h\u2082 | rfl),\n  { left, exact lt_trans h\u2081 h\u2082},\n  { left, exact h\u2081 },\n  { left, exact h\u2082, },\n  { right, refl, },\nend\n\nlemma lt_of_le_of_lt {a b c : R} (h\u2081 : a \u2264 b) (h\u2082 : b < c) : a < c :=\nbegin\n  cases h\u2081 with altb aeqb,\n  { exact lt_trans altb h\u2082, },\n  { rw aeqb, exact h\u2082, }, \nend\n\nlemma le_total (x y : R) : x \u2264 y \u2228 y \u2264 x :=\nbegin\n  rcases trichotomy' x y with \u27e8xltx, _\u27e9 | \u27e8_, xeqy, _\u27e9 | \u27e8_, _, yltx\u27e9,\n  { left, left, exact xltx, },\n  { left, right, exact xeqy, },\n  { right, left, exact yltx, },\nend\n\nlemma anti_symm (x y : R) : x \u2264 y \u2192 y \u2264 x \u2192 x = y :=\nbegin\n  intros h\u2081 h\u2082,\n  have h : (x \u2260 y \u2192 false), -- Could do this using `by_contra`, but that's slow.\n  { intro h,\n    have h\u2083 : y < x := or.elim h\u2082 id (\u03bb k, absurd k.symm h),\n    have h\u2084 : x < y := or.elim h\u2081 id (\u03bb k, absurd k h),\n    exact lt_irrefl (lt_trans h\u2083 h\u2084), },\n  rw [\u2190(@not_not (x=y))],\n  exact h,\nend\n\ntheorem neg_le_neg_iff {a b : R} : -a \u2264 -b \u2194 b \u2264 a :=\nbegin\n  repeat {rw le_iff_lt_or_eq},\n  split,\n  { rintro (hlt | heq),\n    { left, rwa \u2190neg_lt_neg_iff, },\n    { right, rw [\u2190neg_neg a, heq, neg_neg], }, },\n  { rintro (hlt | heq),\n    { left, rwa neg_lt_neg_iff, },\n    { right, rw heq, }, },\nend\n\ntheorem add_le_add {a b c d : R} : a \u2264 b \u2192 c \u2264 d \u2192 a + c \u2264 b + d :=\nbegin\n  rintro (h\u2081| rfl) (h\u2082 | rfl),\n  { left, exact add_lt_add h\u2081 h\u2082 },\n  { left, exact add_lt_add_iff_right_mpr c h\u2081, },\n  { left, repeat {rw add_comm a _},\n    exact add_lt_add_iff_right_mpr a h\u2082, },\n  { exact le_refl _, },\nend\n\ntheorem add_le_add_left (a b: R) : a \u2264 b \u2192  \u2200 (c : R), c + a \u2264 c + b :=\n\u03bb aleb c, add_le_add (le_refl c) aleb\n\ntheorem mul_self_non_neg (a : R) : 0 \u2264 a * a:=\nbegin\n  rcases trichotomy' 0 a with \u27e8posa, _\u27e9 | \u27e8_, eq0, _\u27e9 | \u27e8_, _, nega\u27e9,\n  { left,\n    convert mul_lt_mul_left_mpr posa posa,\n    rw mul_zero, },\n  { right,\n    rw [\u2190eq0, mul_zero], },\n  { left,\n    rw \u2190neg_pos at nega,\n    rw \u2190neg_mul_neg_self,\n    convert mul_lt_mul_left_mpr nega nega,\n    rw mul_zero, },\nend\n\nlemma non_neg_mul_of_non_neg_of_non_neg {a b : R} (h\u2081 : 0 \u2264 a) (h\u2082 : 0 \u2264 b) : 0 \u2264 a * b :=\nbegin\n  cases h\u2081 with apos aeq0,\n  { cases h\u2082 with bpos beq0,\n    { left, exact gt_zero_mul_of_gt_zero_of_gt_zero apos bpos, },\n    { right, rw [\u2190beq0, mul_zero], }, },\n  { right,\n    rw [\u2190aeq0, zero_mul], },\nend\n\nlemma non_neg_of_non_neg_mul_of_pos {x y : R} (h\u2081 : 0 \u2264 x * y) (h\u2082 : 0 < x) : 0 \u2264 y :=\nbegin\n  cases h\u2081 with xlty xyeq0,\n  { by_contra h\u2083,\n    rw [not_le_iff_lt, \u2190neg_pos] at h\u2083,\n    have h\u2084 : 0 < x * -y, from gt_zero_mul_of_gt_zero_of_gt_zero h\u2082 h\u2083,\n    rw [\u2190neg_mul_eq_mul_neg, neg_pos] at h\u2084,\n    exact lt_irrefl (lt_trans h\u2084 xlty), },\n  { right,\n    rw mul_comm at xyeq0,\n    symmetry,\n    apply eq_zero_of_not_eq_zero_of_mul_not_eq_zero _ _ (ne_of_gt h\u2082) (xyeq0.symm), },\nend\n\nlemma non_neg_mul_iff_non_neg_and_non_neg_or_non_pos_and_non_pos (a b : R)\n  : 0 \u2264 a * b \u2194 (0 \u2264 a \u2227 0 \u2264 b) \u2228 (a \u2264 0 \u2227 b \u2264 0) :=\nbegin\n  split,\n  { intro h\u2081,\n    by_cases h\u2082 : 0 \u2264 a,\n    { by_cases h\u2083 : a = 0,\n      { rw h\u2083,\n        exact or.elim (le_total b 0) (\u03bb h\u2084, or.inr \u27e8le_refl 0, h\u2084\u27e9) (\u03bb h\u2084, or.inl \u27e8le_refl 0, h\u2084\u27e9), },\n      { have h\u2084 : 0 < a, from or.elim h\u2082 id (\u03bb aeq0, absurd aeq0.symm h\u2083), \n        have h\u2085 : 0 \u2264 b, from non_neg_of_non_neg_mul_of_pos h\u2081 h\u2084,\n        exact or.inl \u27e8or.inl h\u2084, h\u2085\u27e9, }, },\n    { rw not_le_iff_lt at h\u2082,\n      right,\n      have k : b \u2264 0,\n      { by_contra h\u2083,\n        rw not_le_iff_lt at h\u2083,\n        rw \u2190neg_pos at h\u2082,\n        have h\u2084 : 0 < b * -a, from gt_zero_mul_of_gt_zero_of_gt_zero h\u2083 h\u2082,\n        rw [\u2190neg_mul_eq_mul_neg, mul_comm, neg_pos] at h\u2084,\n        exact lt_irrefl (lt_of_le_of_lt h\u2081 h\u2084), },\n      exact \u27e8or.inl h\u2082, k\u27e9, }, },\n  { rintro (\u27e8h\u2081, h\u2082\u27e9 | \u27e8h\u2081, h\u2082\u27e9),\n    { exact non_neg_mul_of_non_neg_of_non_neg h\u2081 h\u2082, },\n    { rw \u2190neg_mul_neg a b,\n      rw \u2190neg_nonneg at h\u2081 h\u2082,\n      exact non_neg_mul_of_non_neg_of_non_neg h\u2081 h\u2082, }, },\nend\n\ntheorem inv_pos {a : R}  (h : a \u2260 0) : 0 < a\u207b\u00b9 \u2194 0 < a :=\nbegin\n  split,\n  { intro k,\n    have h\u2082 : 0 \u2264 a * a, from mul_self_non_neg a,\n    cases h\u2082 with posaa eq0,\n    { convert mul_lt_mul_left_mpr k posaa,\n      { rw mul_zero, },\n      { rw [\u2190mul_assoc, inv_mul a h, one_mul], }, },\n    { have h\u2083 : a = 0,\n      { cases eq_zero_or_eq_zero_of_mul_eq_zero a a eq0.symm;\n        assumption, },\n      exact absurd h\u2083 h, }, },\n  { intro k,\n    have h\u2082 : 0 \u2264 (a\u207b\u00b9 * a\u207b\u00b9), from mul_self_non_neg a\u207b\u00b9,\n    cases h\u2082 with posainvsq eq0,\n    { convert mul_lt_mul_left_mpr k posainvsq,\n      { rw mul_zero, },\n      { rw [\u2190mul_assoc, mul_inv a h, one_mul], }, },\n    { have h\u2083 : a\u207b\u00b9 = 0,\n      { cases eq_zero_or_eq_zero_of_mul_eq_zero _ _ eq0.symm;\n        assumption, },\n      exact absurd h\u2083 (inv_ne_zero h), }, },\nend\n\ntheorem inv_lt_inv {a b : R} (h\u2081 : 0  < a) (h\u2082 : 0 < b) : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nbegin\n  split,\n  { intro h\u2083,\n    have h\u2084 : a * a\u207b\u00b9 < a * b\u207b\u00b9, from mul_lt_mul_left_mpr h\u2081 h\u2083, \n    have h\u2085 : a \u2260 0, from ne_of_gt h\u2081,\n    rw (mul_inv a h\u2085) at h\u2084,\n    have h\u2086 : b * 1 < b * (a * b\u207b\u00b9), from mul_lt_mul_left_mpr h\u2082 h\u2084,\n    have h\u2087 : b \u2260 0, from ne_of_gt h\u2082,\n    rw [mul_one, mul_comm, mul_assoc, inv_mul b h\u2087, mul_one] at h\u2086,\n    exact h\u2086, },\n  { intro h\u2083,\n    have h\u2085 : a \u2260 0, from ne_of_gt h\u2081,\n    have k\u2081 : a\u207b\u00b9 > 0, from (inv_pos h\u2085).mpr h\u2081,\n    have h\u2084 : a\u207b\u00b9 * b < a\u207b\u00b9 * a, from mul_lt_mul_left_mpr k\u2081 h\u2083, \n    rw inv_mul a h\u2085 at h\u2084,\n    have h\u2087 : b \u2260 0, from ne_of_gt h\u2082,\n    have k\u2082 : b\u207b\u00b9 > 0, from (inv_pos h\u2087).mpr h\u2082,\n    have h\u2086 :  b\u207b\u00b9 * (a\u207b\u00b9 * b) < b\u207b\u00b9 * 1, from mul_lt_mul_left_mpr k\u2082 h\u2084,\n    rw [mul_comm, mul_assoc, mul_inv b h\u2087, mul_one, mul_one] at h\u2086,\n    exact h\u2086, },\nend\n\nend ordered\n\nsection max_abs\n\nvariables {R : Type} [myordered_field R]\n\nopen_locale classical\n\nopen myordered_field\n\nlemma le_max_right (a b : R) : b \u2264 max a b :=\nbegin\n  unfold max,\n  by_cases h : b \u2264 a,\n  { rwa (if_pos h), },\n  { rw (if_neg h),\n    exact le_refl b, },\nend\n\nlemma le_max_left (a b : R) : a \u2264 max a b :=\nbegin\n  unfold max,\n  by_cases h : b \u2264 a,\n  { rw (if_pos h),\n    exact le_refl a, },\n  { rw (if_neg h),\n    rw not_le_iff_lt at h,\n    left, exact h, },\nend\n\nlemma max_choice (a b : R) : max a b = a \u2228 max a b = b :=\nbegin\n  unfold max,\n  by_cases h : b \u2264 a,\n  { rw (if_pos h), left, refl, },\n  { rw (if_neg h),\n    right, refl, },\nend\n\nlemma neg_le_abs (a : R) : -a \u2264 abs a :=\nbegin\n  unfold abs max,\n  by_cases h : -a \u2264 a,\n  { rw (if_pos h), exact h, },\n  { rw (if_neg h), exact le_refl (-a), },\nend\n\nlemma le_abs_self (a : R) : a \u2264 abs a :=\nbegin\n  unfold abs max,\n  by_cases h : -a \u2264 a,\n  { rw (if_pos h), right, refl, },\n  { rw (if_neg h), left,\n    rw le_iff_lt_or_eq at h,\n    push_neg at h,\n    rw [not_lt_iff_le, le_iff_lt_or_eq, or_and_distrib_right] at h,\n    rcases h with \u27e8haltma, _\u27e9 | \u27e8hama, hnama\u27e9,\n    { exact haltma, },\n    { exact absurd hama hnama.symm, }, },\nend\n\ntheorem triangle_inequality (x y : R) : abs (x + y) \u2264 abs x + abs y :=\nbegin\n  by_cases h : -(x+y) \u2264 x+y,\n  { have : abs (x+y) = x + y,\n    { unfold abs max,\n      rw (if_pos h), },\n    rw this,\n    have h\u2081 : x \u2264 abs x, from le_abs_self x,\n    have h\u2082 : y \u2264 abs y, from le_abs_self y,\n    exact add_le_add h\u2081 h\u2082, },\n  { have : abs (x+y) = -(x+y),\n    { unfold abs max,\n      rw (if_neg h), },\n    rw this,\n    rw [neg_add_eq_neg_add_neg', add_comm],\n    have h\u2081 : -x \u2264 abs x, from neg_le_abs x,\n    have h\u2082 : -y \u2264 abs y, from neg_le_abs y,\n    exact add_le_add h\u2081 h\u2082, },\nend\n\nend max_abs\n\nsection upper_bounds\n\nvariables {R : Type} [myordered_field R]\n\ntheorem sup_uniqueness (S : set R) (a b : R) (h\u2081 : is_sup a S) (h\u2082 : is_sup b S) : a = b :=\nanti_symm _ _ (h\u2081.right b h\u2082.left) (h\u2082.right a h\u2081.left)\n\ntheorem empty_set_upper_bound (u : R) : upper_bound u \u2205 :=\n\u03bb s, (set.mem_empty_eq s) \u25b8 false.elim\n\nend upper_bounds\n\nsection instance_linear_ordered_comm_ring\n\nopen_locale classical\n\nnoncomputable theory\n\nvariables {R : Type} [myordered_field R]\n\ninstance : linear_ordered_comm_ring R :=\n{ add               := comm_group.add,\n  add_assoc         := comm_group.add_assoc,\n  zero              := comm_group.zero,\n  zero_add          := zero_add,\n  add_zero          := add_zero,\n  neg               := comm_group.neg,\n  add_left_neg      := neg_add,\n  add_comm          := comm_group.add_comm,\n  mul               := myfield.mul,\n  mul_assoc         := myfield.mul_assoc,\n  one               := myfield.one,\n  one_mul           := one_mul,\n  mul_one           := myfield.mul_one,\n  left_distrib      := myfield.mul_add,\n  right_distrib     := add_mul,\n  le                := le,\n  lt                := lt,\n  lt_iff_le_not_le  := lt_iff_le_not_le,\n  le_refl           := le_refl,\n  le_trans          := le_trans,\n  le_antisymm       := anti_symm,\n  add_le_add_left   := add_le_add_left,\n  mul_pos           := mul_pos,\n  le_total          := le_total,\n  mul_comm          := myfield.mul_comm,\n  zero_lt_one       := zero_lt_one',\n  zero_ne_one       := zero_ne_one,\n}\n\nend instance_linear_ordered_comm_ring\n\nend myreal\n\nend mth1001", "meta": {"author": "gihanmarasingha", "repo": "ems_reals", "sha": "9df527742db69d0a389add44b506538fdb4d0800", "save_path": "github-repos/lean/gihanmarasingha-ems_reals", "path": "github-repos/lean/gihanmarasingha-ems_reals/ems_reals-9df527742db69d0a389add44b506538fdb4d0800/src/library/src_ordered_field_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7206975463270336}}
{"text": "import propositional_logic.and_swap -- hide\n\n/-\n# Propositional logic\n## Level 4: Implication elimination\n\nGiven proofs of $p \\to q$ ($p$ implies $q$) and $p$, you know $q$. This is *implication elimination*,\nsometimes called *modus ponens*.\n\nIn Lean, if `h\u2081 : p \u2192 q` is a proof of `p \u2192 q` and `h\u2082 : p` is a proof of `p`, then `h\u2081 h\u2082` is a proof\nof `q`.\n\n**Notation**: The symbol `\u2192` is typed `\\r`.\n-/\n\nvariables (p q r : Prop) -- hide\n\nexample (h\u2081 : p \u2192 q) (h\u2082 : p) : q :=\nbegin\n  from h\u2081 h\u2082\nend\n\n/-\nAs an example, we'll prove $r$ on the assumptions $h_1 : p \\to (q \\land r)$ and $h_2 : p$.\n-/\n\nexample (h\u2081 : p \u2192 (q \u2227 r)) (h\u2082 : p) : r :=\nbegin\n  have h\u2083 : q \u2227 r, from h\u2081 h\u2082,\n  show r, from h\u2083.right,\nend\n\nnamespace exlean -- hide\n/-\n## Task\n\nProve the following result in Lean.\n-/\n\n\n/- Theorem : no-side-bar\nLet $p$, $q$, and $r$ be propositions. Assuming $h_1 : p \\to q \\land r$ and $h_2 : p$, we have $q$.\n-/\ntheorem imp_elim_example (h\u2081 : p \u2192 q \u2227 r) (h\u2082 : p) : q :=\nbegin\n  have h\u2083 : q \u2227 r, from h\u2081 h\u2082,\n  show q, from h\u2083.left,\n\n\n\n\n\n\n\n\nend\n\nend exlean -- hide", "meta": {"author": "gihanmarasingha", "repo": "lean-game-template", "sha": "75bb3c4cd17afb31062d74eb9b2ab9b232e49719", "save_path": "github-repos/lean/gihanmarasingha-lean-game-template", "path": "github-repos/lean/gihanmarasingha-lean-game-template/lean-game-template-75bb3c4cd17afb31062d74eb9b2ab9b232e49719/src/propositional_logic/imp_elim.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7206975343801414}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\n\nimport data.polynomial.basic\nimport data.finset.nat_antidiagonal\nimport data.nat.choose.sum\n\n/-!\n# Theory of univariate polynomials\n\nThe theorems include formulas for computing coefficients, such as\n`coeff_add`, `coeff_sum`, `coeff_mul`\n\n-/\n\nnoncomputable theory\n\nopen finsupp finset add_monoid_algebra\nopen_locale big_operators polynomial\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b : R} {n m : \u2115}\n\nvariables [semiring R] {p q r : R[X]}\n\nsection coeff\n\nlemma coeff_one (n : \u2115) : coeff (1 : R[X]) n = if 0 = n then 1 else 0 :=\ncoeff_monomial\n\n@[simp]\nlemma coeff_add (p q : R[X]) (n : \u2115) : coeff (p + q) n = coeff p n + coeff q n :=\nby { rcases p, rcases q, simp_rw [\u2190of_finsupp_add, coeff], exact finsupp.add_apply _ _ _ }\n\n@[simp] lemma coeff_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) (n : \u2115) :\n  coeff (r \u2022 p) n = r \u2022 coeff p n :=\nby { rcases p, simp_rw [\u2190of_finsupp_smul, coeff], exact finsupp.smul_apply _ _ _ }\n\nlemma support_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) :\n  support (r \u2022 p) \u2286 support p :=\nbegin\n  assume i hi,\n  simp [mem_support_iff] at hi \u22a2,\n  contrapose! hi,\n  simp [hi]\nend\n\n/-- `polynomial.sum` as a linear map. -/\n@[simps] def lsum {R A M : Type*} [semiring R] [semiring A] [add_comm_monoid M]\n  [module R A] [module R M] (f : \u2115 \u2192 A \u2192\u2097[R] M) :\n  polynomial A \u2192\u2097[R] M :=\n{ to_fun := \u03bb p, p.sum (\u03bb n r, f n r),\n  map_add' := \u03bb p q, sum_add_index p q _ (\u03bb n, (f n).map_zero) (\u03bb n _ _, (f n).map_add _ _),\n  map_smul' := \u03bb c p,\n  begin\n    rw [sum_eq_of_subset _ (\u03bb n r, f n r) (\u03bb n, (f n).map_zero) _ (support_smul c p)],\n    simp only [sum_def, finset.smul_sum, coeff_smul, linear_map.map_smul, ring_hom.id_apply]\n  end }\n\nvariable (R)\n/-- The nth coefficient, as a linear map. -/\ndef lcoeff (n : \u2115) : R[X] \u2192\u2097[R] R :=\n{ to_fun := \u03bb p, coeff p n,\n  map_add' := \u03bb p q, coeff_add p q n,\n  map_smul' := \u03bb r p, coeff_smul r p n }\n\nvariable {R}\n\n@[simp] lemma lcoeff_apply (n : \u2115) (f : R[X]) : lcoeff R n f = coeff f n := rfl\n\n@[simp] lemma finset_sum_coeff {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 R[X]) (n : \u2115) :\n  coeff (\u2211 b in s, f b) n = \u2211 b in s, coeff (f b) n :=\n(lcoeff R n).map_sum\n\nlemma coeff_sum [semiring S] (n : \u2115) (f : \u2115 \u2192 R \u2192 S[X]) :\n  coeff (p.sum f) n = p.sum (\u03bb a b, coeff (f a b) n) :=\nby { rcases p, simp [polynomial.sum, support, coeff] }\n\n/-- Decomposes the coefficient of the product `p * q` as a sum\nover `nat.antidiagonal`. A version which sums over `range (n + 1)` can be obtained\nby using `finset.nat.sum_antidiagonal_eq_sum_range_succ`. -/\nlemma coeff_mul (p q : R[X]) (n : \u2115) :\n  coeff (p * q) n = \u2211 x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 :=\nbegin\n  rcases p, rcases q,\n  simp_rw [\u2190of_finsupp_mul, coeff],\n  exact add_monoid_algebra.mul_apply_antidiagonal p q n _ (\u03bb x, nat.mem_antidiagonal)\nend\n\n@[simp] lemma mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 :=\nby simp [coeff_mul]\n\nlemma coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 :=\nby simp\n\nlemma coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 :=\nby simp\n\nlemma coeff_C_mul_X_pow (x : R) (k n : \u2115) :\n  coeff (C x * X^k : R[X]) n = if n = k then x else 0 :=\nby { rw [\u2190 monomial_eq_C_mul_X, coeff_monomial], congr' 1, simp [eq_comm] }\n\nlemma coeff_C_mul_X (x : R) (n : \u2115) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 :=\nby rw [\u2190 pow_one X, coeff_C_mul_X_pow]\n\n@[simp] lemma coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n :=\nbegin\n  rcases p,\n  simp_rw [\u2190monomial_zero_left, \u2190of_finsupp_single, \u2190of_finsupp_mul, coeff],\n  exact add_monoid_algebra.single_zero_mul_apply p a n\nend\n\nlemma C_mul' (a : R) (f : R[X]) : C a * f = a \u2022 f :=\nby { ext, rw [coeff_C_mul, coeff_smul, smul_eq_mul] }\n\n@[simp] lemma coeff_mul_C (p : R[X]) (n : \u2115) (a : R) :\n  coeff (p * C a) n = coeff p n * a :=\nbegin\n  rcases p,\n  simp_rw [\u2190monomial_zero_left, \u2190of_finsupp_single, \u2190of_finsupp_mul, coeff],\n  exact add_monoid_algebra.mul_single_zero_apply p a n\nend\n\nlemma coeff_X_pow (k n : \u2115) :\n  coeff (X^k : R[X]) n = if n = k then 1 else 0 :=\nby simp only [one_mul, ring_hom.map_one, \u2190 coeff_C_mul_X_pow]\n\n@[simp]\nlemma coeff_X_pow_self (n : \u2115) :\n  coeff (X^n : R[X]) n = 1 :=\nby simp [coeff_X_pow]\n\n@[simp]\ntheorem coeff_mul_X_pow (p : R[X]) (n d : \u2115) :\n  coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=\nbegin\n  rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one],\n  { rintros \u27e8i,j\u27e9 h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,\n    rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },\n  { exact \u03bb h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }\nend\n\n@[simp]\ntheorem coeff_X_pow_mul (p : R[X]) (n d : \u2115) :\n  coeff (polynomial.X ^ n * p) (d + n) = coeff p d :=\nby rw [(commute_X_pow p n).eq, coeff_mul_X_pow]\n\nlemma coeff_mul_X_pow' (p : R[X]) (n d : \u2115) :\n  (p * X ^ n).coeff d = ite (n \u2264 d) (p.coeff (d - n)) 0 :=\nbegin\n  split_ifs,\n  { rw [\u2190 tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] },\n  { refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (\u03bb x hx, _)),\n    rw [coeff_X_pow, if_neg, mul_zero],\n    exact ne_of_lt (lt_of_le_of_lt (nat.le_of_add_le_right\n      (le_of_eq (finset.nat.mem_antidiagonal.mp hx))) (not_le.mp h)) },\nend\n\nlemma coeff_X_pow_mul' (p : R[X]) (n d : \u2115) :\n  (X ^ n * p).coeff d = ite (n \u2264 d) (p.coeff (d - n)) 0 :=\nby rw [(commute_X_pow p n).eq, coeff_mul_X_pow']\n\n@[simp] theorem coeff_mul_X (p : R[X]) (n : \u2115) :\n  coeff (p * X) (n + 1) = coeff p n :=\nby simpa only [pow_one] using coeff_mul_X_pow p 1 n\n\n@[simp] theorem coeff_X_mul (p : R[X]) (n : \u2115) :\n  coeff (X * p) (n + 1) = coeff p n := by rw [(commute_X p).eq, coeff_mul_X]\n\ntheorem mul_X_pow_eq_zero {p : R[X]} {n : \u2115}\n  (H : p * X ^ n = 0) : p = 0 :=\next $ \u03bb k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n)\n\nlemma mul_X_pow_injective (n : \u2115) : function.injective (\u03bb P : R[X], X ^ n * P) :=\nbegin\n  intros P Q hPQ,\n  simp only at hPQ,\n  ext i,\n  rw [\u2190 coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i]\nend\n\nlemma mul_X_injective : function.injective (\u03bb P : R[X], X * P) :=\npow_one (X : R[X]) \u25b8 mul_X_pow_injective 1\n\nlemma C_mul_X_pow_eq_monomial (c : R) (n : \u2115) : C c * X^n = monomial n c :=\nby { ext1, rw [monomial_eq_smul_X, coeff_smul, coeff_C_mul, smul_eq_mul] }\n\nlemma support_mul_X_pow (c : R) (n : \u2115) (H : c \u2260 0) : (C c * X^n).support = singleton n :=\nby rw [C_mul_X_pow_eq_monomial, support_monomial n c H]\n\nlemma support_C_mul_X_pow' {c : R} {n : \u2115} : (C c * X^n).support \u2286 singleton n :=\nby { rw [C_mul_X_pow_eq_monomial], exact support_monomial' n c }\n\nlemma coeff_X_add_C_pow (r : R) (n k : \u2115) :\n  ((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) :=\nbegin\n  rw [(commute_X (C r : R[X])).add_pow, \u2190 lcoeff_apply, linear_map.map_sum],\n  simp only [one_pow, mul_one, lcoeff_apply, \u2190 C_eq_nat_cast, \u2190C_pow, coeff_mul_C, nat.cast_id],\n  rw [finset.sum_eq_single k, coeff_X_pow_self, one_mul],\n  { intros _ _ h,\n    simp [coeff_X_pow, h.symm] },\n  { simp only [coeff_X_pow_self, one_mul, not_lt, finset.mem_range],\n    intro h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero] }\nend\n\nlemma coeff_X_add_one_pow (R : Type*) [semiring R] (n k : \u2115) :\n  ((X + 1) ^ n).coeff k = (n.choose k : R) :=\nby rw [\u2190C_1, coeff_X_add_C_pow, one_pow, one_mul]\n\nlemma coeff_one_add_X_pow (R : Type*) [semiring R] (n k : \u2115) :\n  ((1 + X) ^ n).coeff k = (n.choose k : R) :=\nby rw [add_comm _ X, coeff_X_add_one_pow]\n\nlemma C_dvd_iff_dvd_coeff (r : R) (\u03c6 : R[X]) :\n  C r \u2223 \u03c6 \u2194 \u2200 i, r \u2223 \u03c6.coeff i :=\nbegin\n  split,\n  { rintros \u27e8\u03c6, rfl\u27e9 c, rw coeff_C_mul, apply dvd_mul_right },\n  { intro h,\n    choose c hc using h,\n    classical,\n    let c' : \u2115 \u2192 R := \u03bb i, if i \u2208 \u03c6.support then c i else 0,\n    let \u03c8 : R[X] := \u2211 i in \u03c6.support, monomial i (c' i),\n    use \u03c8,\n    ext i,\n    simp only [\u03c8, c', coeff_C_mul, mem_support_iff, coeff_monomial,\n               finset_sum_coeff, finset.sum_ite_eq'],\n    split_ifs with hi hi,\n    { rw hc },\n    { rw [not_not] at hi, rwa mul_zero } },\nend\n\nlemma coeff_bit0_mul (P Q : R[X]) (n : \u2115) :\n  coeff (bit0 P * Q) n = 2 * coeff (P * Q) n :=\nby simp [bit0, add_mul]\n\n\n\nlemma smul_eq_C_mul (a : R) : a \u2022 p = C a * p := by simp [ext_iff]\n\nlemma update_eq_add_sub_coeff {R : Type*} [ring R] (p : R[X]) (n : \u2115) (a : R) :\n  p.update n a = p + (polynomial.C (a - p.coeff n) * polynomial.X ^ n) :=\nbegin\n  ext,\n  rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow],\n  split_ifs with h;\n  simp [h]\nend\n\nend coeff\n\nsection cast\n\n@[simp] lemma nat_cast_coeff_zero {n : \u2115} {R : Type*} [semiring R] :\n  (n : R[X]).coeff 0 = n :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih], },\nend\n\n@[simp, norm_cast] theorem nat_cast_inj\n  {m n : \u2115} {R : Type*} [semiring R] [char_zero R] : (\u2191m : R[X]) = \u2191n \u2194 m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (\u03bb p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\n@[simp] lemma int_cast_coeff_zero {i : \u2124} {R : Type*} [ring R] :\n  (i : R[X]).coeff 0 = i :=\nby cases i; simp\n\n@[simp, norm_cast] theorem int_cast_inj\n  {m n : \u2124} {R : Type*} [ring R] [char_zero R] : (\u2191m : R[X]) = \u2191n \u2194 m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (\u03bb p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\nend cast\n\ninstance [char_zero R] : char_zero R[X] :=\n{ cast_injective := \u03bb x y, nat_cast_inj.mp }\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/polynomial/coeff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7206975334086747}}
{"text": "import data.finset\n\nuniverses u\n\nopen finset\n\nvariables {\u03b1 : Type u} [decidable_eq \u03b1] [fintype \u03b1]\n\n/- A matroid M is an ordered pair `(E, \u2110)` consisting of a finite set `E` and \na collection `\u2110` of subsets of `E` having the following three properties:\n  (I1) `\u2205 \u2208 \u2110`.\n  (I2) If `I \u2208 \u2110` and `I' \u2286 I`, then `I' \u2208 \u2110`.\n  (I3) If `I\u2081` and `I\u2082` are in `I` and `|I\u2081| < |I\u2082|`, then there is an element `e` of `I\u2082 \u2212 I\u2081`\n    such that `I\u2081 \u222a {e} \u2208 I`.-/\n\n-- could i define independence inductively?\n-- in linear_independent.lean, independence is defined w.r.t. finsupp and the kernel, interesting\ndef can_exchange (\u2110 : finset \u03b1 \u2192 Prop) : Prop := \n\u2200 I\u2081 I\u2082, \u2110 I\u2081 \u2227 \u2110 I\u2082 \u2192 finset.card I\u2081 < finset.card I\u2082 \u2192 \u2203 (e \u2208 I\u2082 \\ I\u2081), (\u2110 (insert e I\u2081))\n\n@[ext]\nstructure matroid (\u03b1 : Type u) [fintype \u03b1] [decidable_eq \u03b1] :=\n(\u2110 : finset \u03b1 \u2192 Prop)\n(empty : \u2110 \u2205) -- (I1)\n(hereditary : \u2200 (I\u2081 : finset \u03b1), \u2110 I\u2081 \u2192 \u2200 (I\u2082 : finset \u03b1), I\u2082 \u2286 I\u2081 \u2192 \u2110 I\u2082) -- (I2)\n(ind : can_exchange \u2110) -- (I3)\n\n\nnamespace matroid\n\nvariables (M : matroid \u03b1) [decidable_pred M.\u2110]\n\n/- A subset of `E` that is not in `\u2110` is called dependent. -/ \ndef dependent_sets : finset (finset \u03b1) := filter (\u03bb s, \u00ac M.\u2110 s) univ.powerset\n\n-- (C1)\nlemma empty_not_dependent : \u2205 \u2209 M.dependent_sets :=\nbegin\n  have h1 := M.empty,\n  rw dependent_sets,\n  simp,\n  exact h1,\nend\n\nvariables [decidable_pred (\u03bb (D : finset \u03b1), can_exchange (\u03bb (_x : finset \u03b1), _x \u2208 D.powerset.erase D))]\n\ndef circuit : finset (finset \u03b1) :=\n  finset.filter (\u03bb (D : finset \u03b1), (\u2200 (S \u2208 (erase D.powerset D)), M.\u2110 S)) (M.dependent_sets)\n\n\n@[simp]\nlemma mem_circuit (C\u2081 : finset \u03b1) : \n  C\u2081 \u2208 M.circuit \u2194 C\u2081 \u2208 M.dependent_sets \u2227 (\u2200 (C\u2082 \u2208 (erase C\u2081.powerset C\u2081)), M.\u2110 C\u2082) :=\nbegin\n  rw circuit,\n  rw dependent_sets,\n  rw mem_filter,\nend\n\n/- `(C2)` if C\u2081 and C\u2082 are members of C and C\u2081 \u2286 C\u2082, then C\u2082 = C\u2082. \nIn other words, C forms an antichain. -/\nlemma circuit_antichain (C\u2081 C\u2082 : finset \u03b1) (h\u2081 : C\u2081 \u2208 M.circuit) (h\u2082 : C\u2082 \u2208 M.circuit) : C\u2081 \u2286 C\u2082 \u2192 C\u2081 = C\u2082 :=\nbegin\n  intros h,\n  -- every proper subset of C\u2082 is independent\n  -- then either C\u2081 is independent or C\u2081 = C\u2082\n  rw circuit at h\u2082,\n  simp at h\u2082,\n  have h2 := h\u2082.2,\n  by_contra h3,\n  specialize h2 C\u2081 h3 h,\n  rw circuit at h\u2081,\n  rw mem_filter at h\u2081,\n  have h1 := h\u2081.1,\n  rw dependent_sets at h1,\n  rw mem_filter at h1,\n  apply h1.2,\n  exact h2,\nend \n\n/- `(C3)` If C\u2081 and C\u2082 are distinct members of M.circuit and e \u2208 C\u2081 \u2229 C\u2082, then\nthere is a member C\u2083 of M.circuit such that C\u2083 \u2286 (C\u2081 \u222a C\u2082) - e.   -/\nlemma circuit_dependence (C\u2081 C\u2082 : finset \u03b1) (h\u2081 : C\u2081 \u2208 M.circuit) (h\u2082 : C\u2082 \u2208 M.circuit) (h : C\u2081 \u2260 C\u2082) (e : \u03b1) :\n  e \u2208 C\u2081 \u2229 C\u2082 \u2192 \u2203 C\u2083 \u2208 M.circuit, C\u2083 \u2286 (C\u2081 \u222a C\u2082) \\ {e} :=\nbegin\n  intros h,\n  sorry,\nend\n\nend matroid", "meta": {"author": "agusakov", "repo": "matroids", "sha": "a95393f6321ccbdf12fafecc788c8bfb20928c3f", "save_path": "github-repos/lean/agusakov-matroids", "path": "github-repos/lean/agusakov-matroids/matroids-a95393f6321ccbdf12fafecc788c8bfb20928c3f/src/definitions2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.720667532028348}}
{"text": "/- LoVe Demo 3: Structured Proofs and Proof Terms -/\n\nimport .love01_definitions_and_lemma_statements_demo\n\nnamespace LoVe\n\n\n/- Structured Proofs -/\n\nlemma add_comm_zero_left (n : \u2115):\n  add 0 n = add n 0 :=\nadd_comm 0 n\n\nlemma add_comm_zero_left\u2082 (n : \u2115):\n  add 0 n = add n 0 :=\nby exact add_comm 0 n\n\nlemma fst_of_two_props :\n  \u2200a b : Prop, a \u2192 b \u2192 a :=\nassume a b ha hb,\nshow a, from ha\n\nlemma fst_of_two_props\u2082 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nshow a,\nbegin\n  exact ha\nend\n\nlemma fst_of_two_props\u2083 (a b : Prop) (ha : a) (hb : b) :\n  a :=\nha\n\nlemma prop_comp (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nassume ha,\nhave hb : b := hab ha,\nhave hc : c := hbc hb,\nshow c, from hc\n\nlemma \u03b2_example {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :\n  (\u03bbx, f x) a = f a :=\nrfl\n\ndef double (n : \u2115) : \u2115 :=\nn + n\n\nlemma nat_exists_double_iden :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0\n  (show double 0 = 0, from rfl)\n\nlemma nat_exists_double_iden\u2082 :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0 rfl\n\nlemma nat_exists_double_iden\u2083 :\n  \u2203n : \u2115, double n = n :=\nexists.intro 0 (by refl)\n\nlemma and_swap (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nassume hab : a \u2227 b,\nhave ha : a := and.elim_left hab,\nhave hb : b := and.elim_right hab,\nshow b \u2227 a, from and.intro hb ha\n\nlemma and_swap\u2082 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nassume hab : a \u2227 b,\nhave ha : a := and.elim_left hab,\nhave hb : b := and.elim_right hab,\nbegin\n  apply and.intro,\n  { exact hb },\n  { exact ha }\nend\n\nlemma or_swap (a b : Prop) :\n  a \u2228 b \u2192 b \u2228 a :=\nassume hab : a \u2228 b,\nshow b \u2228 a, from or.elim hab\n  (assume ha,\n   show b \u2228 a, from or.intro_right b ha)\n  (assume hb,\n   show b \u2228 a, from or.intro_left a hb)\n\nlemma modus_ponens (a b : Prop) :\n  (a \u2192 b) \u2192 a \u2192 b :=\nassume (hab : a \u2192 b) (ha : a),\nshow b, from hab ha\n\nlemma proof_of_negation (a : Prop) :\n  a \u2192 \u00ac\u00ac a :=\nassume ha hna,\nshow false, from hna ha\n\n#check classical.by_contradiction\n\nlemma proof_by_contradiction (a : Prop) :\n  \u00ac\u00ac a \u2192 a :=\nassume hnna,\nshow a, from classical.by_contradiction hnna\n\nlemma exists_or {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2203x, p x \u2228 q x) \u2194 (\u2203x, p x) \u2228 (\u2203x, q x) :=\niff.intro\n  (assume hxpq,\n   match hxpq with\n   | Exists.intro x hpq :=\n     match hpq with\n     | or.inl hp := or.intro_left _ (exists.intro x hp)\n     | or.inr hq := or.intro_right _ (exists.intro x hq)\n     end\n   end)\n  (assume hxpq,\n   match hxpq with\n   | or.inl hxp :=\n     match hxp with\n     | Exists.intro x hp := exists.intro x (or.intro_left _ hp)\n     end\n   | or.inr hxq :=\n     match hxq with\n     | Exists.intro x hq := exists.intro x (or.intro_right _ hq)\n     end\n   end)\n\n\n/- Calculational Proofs -/\n\nlemma two_mul_example (m n : \u2115) :\n  2 * m + n = m + n + m :=\ncalc 2 * m + n = (m + m) + n : by rw two_mul\n... = m + n + m : by ac_refl\n\nlemma two_mul_example\u2082 (m n : \u2115) :\n  2 * m + n = m + n + m :=\nhave h\u2081 : 2 * m + n = (m + m) + n := by rw two_mul,\nhave h\u2082 : (m + m) + n = m + n + m := by ac_refl,\nshow _, from eq.trans h\u2081 h\u2082\n\n\n/- Induction by Pattern Matching -/\n\nlemma add_zero :\n  \u2200n : \u2115, add 0 n = n\n| 0            := by refl\n| (nat.succ m) := by simp [add, add_zero m]\n\nlemma add_succ :\n  \u2200m n : \u2115, add (nat.succ m) n = nat.succ (add m n)\n| m 0            := by refl\n| m (nat.succ n) := by simp [add, add_succ m n]\n\nlemma add_comm :\n  \u2200m n : \u2115, add m n = add n m\n| m 0            := by simp [add, add_zero]\n| m (nat.succ n) := by simp [add, add_succ, add_comm m n]\n\nlemma add_comm\u2082 :\n  \u2200m n : \u2115, add m n = add n m\n| m 0            := by simp [add, add_zero]\n| m (nat.succ n) :=\n  have ih : _ := add_comm\u2082 m n,\n  by simp [add, add_succ, ih]\n\nlemma add_assoc :\n  \u2200l m n : \u2115, add (add l m) n = add l (add m n)\n| l m 0            := by refl\n| l m (nat.succ n) := by simp [add, add_assoc l m n]\n\n-- type classes (useful for `ac_refl` below)\ninstance : is_commutative \u2115 add := \u27e8add_comm\u27e9\ninstance : is_associative \u2115 add := \u27e8add_assoc\u27e9\n\nlemma mul_add (l m : \u2115) :\n  \u2200n : \u2115, mul l (add m n) = add (mul l m) (mul l n)\n| 0            := by refl\n| (nat.succ l) := by simp [add, mul, mul_add l]; ac_refl\n\n\n/- The Curry\u2013Howard Correspondence -/\n\nlemma and_swap\u2083 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\n\u03bbhab : a \u2227 b, and.intro (and.elim_right hab) (and.elim_left hab)\n\nlemma and_swap\u2084 (a b : Prop) :\n  a \u2227 b \u2192 b \u2227 a :=\nbegin\n  intro hab,\n  apply and.intro,\n  apply and.elim_right,\n  exact hab,\n  apply and.elim_left,\n  exact hab\nend\n\n#print and_swap\u2083\n#print and_swap\u2084\n\n\n/- Forward Tactics -/\n\nlemma prop_comp\u2082 (a b c : Prop) (hab : a \u2192 b) (hbc : b \u2192 c) :\n  a \u2192 c :=\nbegin\n  intro ha,\n  have hb : b := hab ha,\n  have hc : c := hbc hb,\n  exact hc\nend\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love03_structured_proofs_and_proof_terms_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7206432683011575}}
{"text": "/-\nCopyright (c) 2022 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n\n! This file was ported from Lean 3 source module number_theory.von_mangoldt\n! leanprover-community/mathlib commit c946d6097a6925ad16d7ec55677bbc977f9846de\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.IsPrimePow\nimport Mathbin.NumberTheory.ArithmeticFunction\nimport Mathbin.Analysis.SpecialFunctions.Log.Basic\n\n/-!\n# The von Mangoldt Function\n\nIn this file we define the von Mangoldt function: the function on natural numbers that returns\n`log p` if the input can be expressed as `p^k` for a prime `p`.\n\n## Main Results\n\nThe main definition for this file is\n\n- `nat.arithmetic_function.von_mangoldt`: The von Mangoldt function `\u039b`.\n\nWe then prove the classical summation property of the von Mangoldt function in\n`nat.arithmetic_function.von_mangoldt_sum`, that `\u2211 i in n.divisors, \u039b i = real.log n`, and use this\nto deduce alternative expressions for the von Mangoldt function via M\u00f6bius inversion, see\n`nat.arithmetic_function.sum_moebius_mul_log_eq`.\n\n## Notation\n\nWe use the standard notation `\u039b` to represent the von Mangoldt function.\n\n-/\n\n\nnamespace Nat\n\nnamespace ArithmeticFunction\n\nopen Finset\n\nopen ArithmeticFunction\n\n/-- `log` as an arithmetic function `\u2115 \u2192 \u211d`. Note this is in the `nat.arithmetic_function`\nnamespace to indicate that it is bundled as an `arithmetic_function` rather than being the usual\nreal logarithm. -/\nnoncomputable def log : ArithmeticFunction \u211d :=\n  \u27e8fun n => Real.log n, by simp\u27e9\n#align nat.arithmetic_function.log Nat.ArithmeticFunction.log\n\n@[simp]\ntheorem log_apply {n : \u2115} : log n = Real.log n :=\n  rfl\n#align nat.arithmetic_function.log_apply Nat.ArithmeticFunction.log_apply\n\n/--\nThe `von_mangoldt` function is the function on natural numbers that returns `log p` if the input can\nbe expressed as `p^k` for a prime `p`.\nIn the case when `n` is a prime power, `min_fac` will give the appropriate prime, as it is the\nsmallest prime factor.\n\nIn the `arithmetic_function` locale, we have the notation `\u039b` for this function.\n-/\nnoncomputable def vonMangoldt : ArithmeticFunction \u211d :=\n  \u27e8fun n => if IsPrimePow n then Real.log (minFac n) else 0, if_neg not_isPrimePow_zero\u27e9\n#align nat.arithmetic_function.von_mangoldt Nat.ArithmeticFunction.vonMangoldt\n\n-- mathport name: von_mangoldt\nscoped[ArithmeticFunction] notation \"\u039b\" => Nat.ArithmeticFunction.vonMangoldt\n\ntheorem vonMangoldt_apply {n : \u2115} : \u039b n = if IsPrimePow n then Real.log (minFac n) else 0 :=\n  rfl\n#align nat.arithmetic_function.von_mangoldt_apply Nat.ArithmeticFunction.vonMangoldt_apply\n\n@[simp]\ntheorem vonMangoldt_apply_one : \u039b 1 = 0 := by simp [von_mangoldt_apply]\n#align nat.arithmetic_function.von_mangoldt_apply_one Nat.ArithmeticFunction.vonMangoldt_apply_one\n\n@[simp]\ntheorem vonMangoldt_nonneg {n : \u2115} : 0 \u2264 \u039b n :=\n  by\n  rw [von_mangoldt_apply]\n  split_ifs\n  \u00b7 exact Real.log_nonneg (one_le_cast.2 (Nat.minFac_pos n))\n  rfl\n#align nat.arithmetic_function.von_mangoldt_nonneg Nat.ArithmeticFunction.vonMangoldt_nonneg\n\ntheorem vonMangoldt_apply_pow {n k : \u2115} (hk : k \u2260 0) : \u039b (n ^ k) = \u039b n := by\n  simp only [von_mangoldt_apply, isPrimePow_pow_iff hk, pow_min_fac hk]\n#align nat.arithmetic_function.von_mangoldt_apply_pow Nat.ArithmeticFunction.vonMangoldt_apply_pow\n\ntheorem vonMangoldt_apply_prime {p : \u2115} (hp : p.Prime) : \u039b p = Real.log p := by\n  rw [von_mangoldt_apply, prime.min_fac_eq hp, if_pos hp.prime.is_prime_pow]\n#align nat.arithmetic_function.von_mangoldt_apply_prime Nat.ArithmeticFunction.vonMangoldt_apply_prime\n\ntheorem vonMangoldt_ne_zero_iff {n : \u2115} : \u039b n \u2260 0 \u2194 IsPrimePow n :=\n  by\n  rcases eq_or_ne n 1 with (rfl | hn); \u00b7 simp [not_isPrimePow_one]\n  exact (Real.log_pos (one_lt_cast.2 (min_fac_prime hn).one_lt)).ne'.ite_ne_right_iff\n#align nat.arithmetic_function.von_mangoldt_ne_zero_iff Nat.ArithmeticFunction.vonMangoldt_ne_zero_iff\n\ntheorem vonMangoldt_pos_iff {n : \u2115} : 0 < \u039b n \u2194 IsPrimePow n :=\n  vonMangoldt_nonneg.lt_iff_ne.trans (ne_comm.trans vonMangoldt_ne_zero_iff)\n#align nat.arithmetic_function.von_mangoldt_pos_iff Nat.ArithmeticFunction.vonMangoldt_pos_iff\n\ntheorem vonMangoldt_eq_zero_iff {n : \u2115} : \u039b n = 0 \u2194 \u00acIsPrimePow n :=\n  vonMangoldt_ne_zero_iff.not_right\n#align nat.arithmetic_function.von_mangoldt_eq_zero_iff Nat.ArithmeticFunction.vonMangoldt_eq_zero_iff\n\nopen BigOperators\n\ntheorem vonMangoldt_sum {n : \u2115} : (\u2211 i in n.divisors, \u039b i) = Real.log n :=\n  by\n  refine' rec_on_prime_coprime _ _ _ n\n  \u00b7 simp\n  \u00b7 intro p k hp\n    rw [sum_divisors_prime_pow hp, cast_pow, Real.log_pow, Finset.sum_range_succ', pow_zero,\n      von_mangoldt_apply_one]\n    simp [von_mangoldt_apply_pow (Nat.succ_ne_zero _), von_mangoldt_apply_prime hp]\n  intro a b ha' hb' hab ha hb\n  simp only [von_mangoldt_apply, \u2190 sum_filter] at ha hb\u22a2\n  rw [mul_divisors_filter_prime_pow hab, filter_union,\n    sum_union (disjoint_divisors_filter_prime_pow hab), ha, hb, Nat.cast_mul,\n    Real.log_mul (cast_ne_zero.2 (pos_of_gt ha').ne') (cast_ne_zero.2 (pos_of_gt hb').ne')]\n#align nat.arithmetic_function.von_mangoldt_sum Nat.ArithmeticFunction.vonMangoldt_sum\n\n@[simp]\ntheorem vonMangoldt_mul_zeta : \u039b * \u03b6 = log := by\n  ext n\n  rw [coe_mul_zeta_apply, von_mangoldt_sum]\n  rfl\n#align nat.arithmetic_function.von_mangoldt_mul_zeta Nat.ArithmeticFunction.vonMangoldt_mul_zeta\n\n@[simp]\ntheorem zeta_mul_vonMangoldt : (\u03b6 : ArithmeticFunction \u211d) * \u039b = log :=\n  by\n  rw [mul_comm]\n  simp\n#align nat.arithmetic_function.zeta_mul_von_mangoldt Nat.ArithmeticFunction.zeta_mul_vonMangoldt\n\n@[simp]\ntheorem log_mul_moebius_eq_vonMangoldt : log * \u03bc = \u039b := by\n  rw [\u2190 von_mangoldt_mul_zeta, mul_assoc, coe_zeta_mul_coe_moebius, mul_one]\n#align nat.arithmetic_function.log_mul_moebius_eq_von_mangoldt Nat.ArithmeticFunction.log_mul_moebius_eq_vonMangoldt\n\n@[simp]\ntheorem moebius_mul_log_eq_vonMangoldt : (\u03bc : ArithmeticFunction \u211d) * log = \u039b :=\n  by\n  rw [mul_comm]\n  simp\n#align nat.arithmetic_function.moebius_mul_log_eq_von_mangoldt Nat.ArithmeticFunction.moebius_mul_log_eq_vonMangoldt\n\ntheorem sum_moebius_mul_log_eq {n : \u2115} : (\u2211 d in n.divisors, (\u03bc d : \u211d) * log d) = -\u039b n :=\n  by\n  simp only [\u2190 log_mul_moebius_eq_von_mangoldt, mul_comm log, mul_apply, log_apply, int_coe_apply, \u2190\n    Finset.sum_neg_distrib, neg_mul_eq_mul_neg]\n  rw [sum_divisors_antidiagonal fun i j => (\u03bc i : \u211d) * -Real.log j]\n  have :\n    (\u2211 i : \u2115 in n.divisors, (\u03bc i : \u211d) * -Real.log (n / i : \u2115)) =\n      \u2211 i : \u2115 in n.divisors, (\u03bc i : \u211d) * Real.log i - \u03bc i * Real.log n :=\n    by\n    apply sum_congr rfl\n    simp only [and_imp, Int.cast_eq_zero, mul_eq_mul_left_iff, Ne.def, neg_inj, mem_divisors]\n    intro m mn hn\n    have : (m : \u211d) \u2260 0 := by\n      rw [cast_ne_zero]\n      rintro rfl\n      exact hn (by simpa using mn)\n    rw [Nat.cast_div mn this, Real.log_div (cast_ne_zero.2 hn) this, neg_sub, mul_sub]\n  rw [this, sum_sub_distrib, \u2190 sum_mul, \u2190 Int.cast_sum, \u2190 coe_mul_zeta_apply, eq_comm, sub_eq_self,\n    moebius_mul_coe_zeta, mul_eq_zero, Int.cast_eq_zero]\n  rcases eq_or_ne n 1 with (hn | hn) <;> simp [hn]\n#align nat.arithmetic_function.sum_moebius_mul_log_eq Nat.ArithmeticFunction.sum_moebius_mul_log_eq\n\ntheorem vonMangoldt_le_log : \u2200 {n : \u2115}, \u039b n \u2264 Real.log (n : \u211d)\n  | 0 => by simp\n  | n + 1 => by\n    rw [\u2190 von_mangoldt_sum]\n    exact single_le_sum (fun _ _ => von_mangoldt_nonneg) (mem_divisors_self _ n.succ_ne_zero)\n#align nat.arithmetic_function.von_mangoldt_le_log Nat.ArithmeticFunction.vonMangoldt_le_log\n\nend ArithmeticFunction\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/VonMangoldt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7206432665026046}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.erase_lead\nimport Mathlib.data.polynomial.degree.default\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Reverse of a univariate polynomial\n\nThe main definition is `reverse`.  Applying `reverse` to a polynomial `f : polynomial R` produces\nthe polynomial with a reversed list of coefficients, equivalent to `X^f.nat_degree * f(1/X)`.\n\nThe main result is that `reverse (f * g) = reverse (f) * reverse (g)`, provided the leading\ncoefficients of `f` and `g` do not multiply to zero.\n-/\n\nnamespace polynomial\n\n\n/-- If `i \u2264 N`, then `rev_at_fun N i` returns `N - i`, otherwise it returns `i`.\nThis is the map used by the embedding `rev_at`.\n-/\ndef rev_at_fun (N : \u2115) (i : \u2115) : \u2115 := ite (i \u2264 N) (N - i) i\n\ntheorem rev_at_fun_invol {N : \u2115} {i : \u2115} : rev_at_fun N (rev_at_fun N i) = i := sorry\n\ntheorem rev_at_fun_inj {N : \u2115} : function.injective (rev_at_fun N) := sorry\n\n/-- If `i \u2264 N`, then `rev_at N i` returns `N - i`, otherwise it returns `i`.\nEssentially, this embedding is only used for `i \u2264 N`.\nThe advantage of `rev_at N i` over `N - i` is that `rev_at` is an involution.\n-/\ndef rev_at (N : \u2115) : \u2115 \u21aa \u2115 :=\n  function.embedding.mk (fun (i : \u2115) => ite (i \u2264 N) (N - i) i) rev_at_fun_inj\n\n/-- We prefer to use the bundled `rev_at` over unbundled `rev_at_fun`. -/\n@[simp] theorem rev_at_fun_eq (N : \u2115) (i : \u2115) : rev_at_fun N i = coe_fn (rev_at N) i := rfl\n\n@[simp] theorem rev_at_invol {N : \u2115} {i : \u2115} : coe_fn (rev_at N) (coe_fn (rev_at N) i) = i :=\n  rev_at_fun_invol\n\n@[simp] theorem rev_at_le {N : \u2115} {i : \u2115} (H : i \u2264 N) : coe_fn (rev_at N) i = N - i := if_pos H\n\ntheorem rev_at_add {N : \u2115} {O : \u2115} {n : \u2115} {o : \u2115} (hn : n \u2264 N) (ho : o \u2264 O) :\n    coe_fn (rev_at (N + O)) (n + o) = coe_fn (rev_at N) n + coe_fn (rev_at O) o :=\n  sorry\n\n/-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (rev_at N i)`.\nIn other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`.\n\nIn practice, `reflect` is only used when `N` is at least as large as the degree of `f`.\n\nEventually, it will be used with `N` exactly equal to the degree of `f`.  -/\ndef reflect {R : Type u_1} [semiring R] (N : \u2115) (f : polynomial R) : polynomial R :=\n  finsupp.emb_domain (rev_at N) f\n\ntheorem reflect_support {R : Type u_1} [semiring R] (N : \u2115) (f : polynomial R) :\n    finsupp.support (reflect N f) = finset.image (\u21d1(rev_at N)) (finsupp.support f) :=\n  sorry\n\n@[simp] theorem coeff_reflect {R : Type u_1} [semiring R] (N : \u2115) (f : polynomial R) (i : \u2115) :\n    coeff (reflect N f) i = coeff f (coe_fn (rev_at N) i) :=\n  sorry\n\n@[simp] theorem reflect_zero {R : Type u_1} [semiring R] {N : \u2115} : reflect N 0 = 0 := rfl\n\n@[simp] theorem reflect_eq_zero_iff {R : Type u_1} [semiring R] {N : \u2115} {f : polynomial R} :\n    reflect N f = 0 \u2194 f = 0 :=\n  sorry\n\n@[simp] theorem reflect_add {R : Type u_1} [semiring R] (f : polynomial R) (g : polynomial R)\n    (N : \u2115) : reflect N (f + g) = reflect N f + reflect N g :=\n  sorry\n\n@[simp] theorem reflect_C_mul {R : Type u_1} [semiring R] (f : polynomial R) (r : R) (N : \u2115) :\n    reflect N (coe_fn C r * f) = coe_fn C r * reflect N f :=\n  sorry\n\n@[simp] theorem reflect_C_mul_X_pow {R : Type u_1} [semiring R] (N : \u2115) (n : \u2115) {c : R} :\n    reflect N (coe_fn C c * X ^ n) = coe_fn C c * X ^ coe_fn (rev_at N) n :=\n  sorry\n\n@[simp] theorem reflect_monomial {R : Type u_1} [semiring R] (N : \u2115) (n : \u2115) :\n    reflect N (X ^ n) = X ^ coe_fn (rev_at N) n :=\n  sorry\n\ntheorem reflect_mul_induction {R : Type u_1} [semiring R] (cf : \u2115) (cg : \u2115) (N : \u2115) (O : \u2115)\n    (f : polynomial R) (g : polynomial R) :\n    finset.card (finsupp.support f) \u2264 Nat.succ cf \u2192\n        finset.card (finsupp.support g) \u2264 Nat.succ cg \u2192\n          nat_degree f \u2264 N \u2192\n            nat_degree g \u2264 O \u2192 reflect (N + O) (f * g) = reflect N f * reflect O g :=\n  sorry\n\n@[simp] theorem reflect_mul {R : Type u_1} [semiring R] (f : polynomial R) (g : polynomial R)\n    {F : \u2115} {G : \u2115} (Ff : nat_degree f \u2264 F) (Gg : nat_degree g \u2264 G) :\n    reflect (F + G) (f * g) = reflect F f * reflect G g :=\n  reflect_mul_induction (finset.card (finsupp.support f)) (finset.card (finsupp.support g)) F G f g\n    (nat.le_succ (finset.card (finsupp.support f))) (nat.le_succ (finset.card (finsupp.support g)))\n    Ff Gg\n\n/-- The reverse of a polynomial f is the polynomial obtained by \"reading f backwards\".\nEven though this is not the actual definition, reverse f = f (1/X) * X ^ f.nat_degree. -/\ndef reverse {R : Type u_1} [semiring R] (f : polynomial R) : polynomial R :=\n  reflect (nat_degree f) f\n\n@[simp] theorem reverse_zero {R : Type u_1} [semiring R] : reverse 0 = 0 := rfl\n\ntheorem reverse_mul {R : Type u_1} [semiring R] {f : polynomial R} {g : polynomial R}\n    (fg : leading_coeff f * leading_coeff g \u2260 0) : reverse (f * g) = reverse f * reverse g :=\n  sorry\n\n@[simp] theorem reverse_mul_of_domain {R : Type u_1} [domain R] (f : polynomial R)\n    (g : polynomial R) : reverse (f * g) = reverse f * reverse g :=\n  sorry\n\n@[simp] theorem coeff_zero_reverse {R : Type u_1} [semiring R] (f : polynomial R) :\n    coeff (reverse f) 0 = leading_coeff f :=\n  sorry\n\n@[simp] theorem coeff_one_reverse {R : Type u_1} [semiring R] (f : polynomial R) :\n    coeff (reverse f) 1 = next_coeff f :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/polynomial/reverse_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7206432662401024}}
{"text": "-- ereal facts\n\nimport analysis.special_functions.log.basic\nimport data.real.basic\nimport data.real.ennreal\nimport data.real.ereal\nimport topology.instances.ereal\n\nimport simple\n\nopen linear_order (min)\nopen_locale nnreal ennreal\nnoncomputable theory\n\n-- log : ereal \u2192 ereal, turning nonpositives to -\u221e and preserving \u221e\ndef ereal.log : ereal \u2192 ereal\n| \u22a5 := \u22a5\n| (x : \u211d) := if x \u2264 0 then \u22a5 else \u2191(x.log)\n| \u22a4 := \u22a4\n\n-- exp : ereal \u2192 ereal, turning -\u221e into 0 and preserving \u221e\ndef ereal.exp : ereal \u2192 ereal\n| \u22a5 := 0\n| (x : \u211d) := \u2191(x.exp)\n| \u22a4 := \u22a4\n\n-- Is an ereal finite?\ndef ereal.is_finite (x : ereal) := \u2203 y : \u211d, x = \u2191y\n\n@[simp] lemma ereal.coe_finite {x : \u211d} : ereal.is_finite (x : ereal) := by simp [ereal.is_finite]\nlemma ereal.bot_infinite : \u00acereal.is_finite \u22a5 := by simp [ereal.is_finite]\nlemma ereal.top_infinite : \u00acereal.is_finite \u22a4 := by simp [ereal.is_finite]\nlemma ereal.is_finite.ne_bot {x : ereal} : ereal.is_finite x \u2192 x \u2260 \u22a5 := begin\n  intro f, by_contradiction, rw h at f, have nf := ereal.bot_infinite, finish\nend\n\ninstance : densely_ordered ereal := \u27e8begin\n  intros x y xy,\n  induction x using ereal.rec,\n  induction y using ereal.rec, finish,\n  existsi \u2191(y - 1), simp, apply_instance,\n  existsi (0 : ereal), simp,\n  induction y using ereal.rec, finish,\n  simp at xy, rcases exists_between xy with \u27e8a,lo,hi\u27e9, existsi \u2191a, simp, finish, apply_instance,\n  existsi \u2191(x + 1), rw ereal.coe_lt_coe_iff, simp, rw \u2190ereal.coe_one, exact ereal.coe_lt_top _,\n  simp at xy, finish,\nend\u27e9\n\n@[simp] lemma ereal.log_zero : ereal.log 0 = \u22a5 := by { rw [\u2190ereal.coe_zero, ereal.log], simp }\n@[simp] lemma ereal.log_bot : ereal.log \u22a5 = \u22a5 := by simp [ereal.log]\n@[simp] lemma ereal.log_top : ereal.log \u22a4 = \u22a4 := by simp [ereal.log]\n@[simp] lemma ereal.exp_bot : ereal.exp \u22a5 = 0 := by simp [ereal.exp]\n@[simp] lemma ereal.exp_top : ereal.exp \u22a4 = \u22a4 := by simp [ereal.exp]\n@[simp] lemma ereal.log_coe {x : \u211d} (h : x > 0) : ereal.log x = \u2191(x.log) := begin rw ereal.log, simp, exact not_le_of_gt h end\n@[simp] lemma ereal.exp_coe {x : \u211d} : ereal.exp x = \u2191(x.exp) := rfl\n\n@[simp] lemma ereal.log_exp {x : ereal} : x.exp.log = x := begin\n  induction x using ereal.rec, simp, simp [ereal.log], apply not_le_of_gt, exact real.exp_pos _, simp,\nend\n\n@[simp] lemma ereal.exp_log {x : ereal} (h : x \u2265 0) : x.log.exp = x := begin\n  induction x using ereal.rec, simp at h, finish, swap, simp,\n  simp at h, rw [\u2190ereal.coe_zero, ereal.coe_le_coe_iff] at h,\n  by_cases z : x = 0, { rw z, simp },\n  simp [lt_of_le_of_ne h (ne.symm z), real.exp_log],\nend\n\nlemma ereal.log_lt_top_iff {x : ereal} : x.log < \u22a4 \u2194 x < \u22a4 := begin\n  induction x using ereal.rec, simp, simp [ereal.log], by_cases x0 : x \u2264 0, simp [x0], simp [x0], simp,\nend\n\nlemma ereal.exp_pos_iff {x : ereal} : 0 < x.exp \u2194 \u22a5 < x := begin\n  induction x using ereal.rec,\n  simp, simp, rw [\u2190ereal.coe_zero, ereal.coe_lt_coe_iff], simp [real.exp_pos], simp,\nend\n\nlemma ereal.log_eq_iff_eq_exp {x y : ereal} (h : x \u2265 0) : x.log = y \u2194 x = y.exp := begin\n  constructor, { intro e, rw \u2190e, simp [h] }, { intro e, rw e, simp }\nend\n\nlemma ereal.log_lt_iff_lt_exp {x y : ereal} (h : x \u2265 0) : x.log < y \u2194 x < y.exp := begin\n  induction x using ereal.rec, finish, swap, simp,\n  rw \u2190ereal.coe_zero at h,\n  have h' := ereal.coe_le_coe_iff.mp h,\n  by_cases x0 : x = 0, { rw x0, simp [real.exp_pos], exact ereal.exp_pos_iff.symm },\n  have xp := lt_of_le_of_ne h' (ne.symm x0),\n  induction y using ereal.rec, simp, assumption,\n  simp [ereal.exp_coe, ereal.coe_lt_coe_iff],\n  rw [ereal.log_coe xp, ereal.coe_lt_coe_iff],\n  exact real.log_lt_iff_lt_exp xp,\n  rw ereal.log_coe xp, simp,\nend\n\nlemma ereal.log_le_iff_le_exp {x y : ereal} (h : x \u2265 0) : x.log \u2264 y \u2194 x \u2264 y.exp := begin\n  by_cases e : x = y.exp, { rw e, simp },\n  constructor, {\n    intro w, rw \u2190ereal.log_eq_iff_eq_exp h at e,\n    have s := lt_of_le_of_ne w e,\n    rw ereal.log_lt_iff_lt_exp h at s,\n    exact le_of_lt s,\n  }, {\n    intro w,\n    have s := lt_of_le_of_ne w e,\n    rw \u2190ereal.log_lt_iff_lt_exp h at s,\n    exact le_of_lt s,\n  }\nend\n\nlemma ereal.coe_sub {x y : \u211d} : ((x - y : \u211d) : ereal) = (x : ereal) - (y : ereal) := rfl\n\nlemma monotone_ereal_log : monotone ereal.log := begin\n  intros x y,\n  induction x using ereal.rec, simp,\n  induction y using ereal.rec, simp,\n  simp [ereal.log], intro xy,\n  by_cases y0 : y \u2264 0, { simp [y0], exact not_lt_of_ge (trans y0 xy) },\n  by_cases x0 : x \u2264 0, { simp [x0] },\n  simp [x0, y0], simp at x0 y0, rwa real.log_le_log x0 y0,\n  simp, simp, intro e, rw e, simp,\nend\n\nlemma ereal.log_surjective : function.surjective ereal.log := begin\n  rw function.surjective, intro x, existsi x.exp, simp,\nend\n\nlemma continuous_ereal_log : continuous ereal.log :=\n  monotone_ereal_log.continuous_of_surjective ereal.log_surjective\n\n-- Clamp x into the interval [lo, hi]\ndef clamp {X : Type} [linear_order X] (x lo hi : X) : X := max lo (min hi x)\n\n-- Simple facts about clamp\n@[simp] lemma clamp_bot {X : Type} [linear_order X] [order_bot X] {lo hi : X} : clamp \u22a5 lo hi = lo := by simp [clamp]\n@[simp] lemma clamp_top {X : Type} [linear_order X] [order_top X] {lo hi : X} : clamp \u22a4 lo hi = max lo hi := by simp [clamp]\nlemma le_clamp {X : Type} [linear_order X] (x lo hi : X) : lo \u2264 clamp x lo hi := by simp [clamp, le_max_left]\nlemma clamp_le {X : Type} [linear_order X] (x lo hi : X) : clamp x lo hi \u2264 max lo hi := by simp [clamp]\nlemma monotone.clamp {X : Type} [linear_order X] (lo hi : X) : monotone (\u03bb x, clamp x lo hi) :=\n  monotone.comp (monotone.max monotone_const monotone_id) (monotone.min monotone_const monotone_id)\nlemma le_clamp_of_le_hi {X : Type} [linear_order X] (x lo hi : X) : x \u2264 hi \u2192 x \u2264 clamp x lo hi := \u03bb h, by simp [clamp, h]\nlemma clamp_le_lox {X : Type} [linear_order X] (x lo hi : X) : clamp x lo hi \u2264 max lo x := by simp [clamp, max_le_iff]\n\n-- Clamp is the identity inside the bounds\nlemma clamp_inv {X : Type} [linear_order X] (x y : X) {lo hi : X} (y0 : lo < y) (y1 : y < hi) : clamp x lo hi = y \u2194 x = y := begin\n  rw clamp, constructor, {\n    intro h,\n    by_cases x1 : x < hi, {\n      simp [le_of_lt x1] at h,\n      by_cases x0 : lo < x, simp [le_of_lt x0] at h, exact h, simp at x0, simp [x0] at h, rw h at y0, finish, \n    }, {\n      simp at x1, simp [x1] at h, rw \u2190h at y1, simp at y1, finish,\n    }\n  }, {\n    intro h, rw h, simp [le_of_lt y0, le_of_lt y1],\n  },\nend\n\n-- Clamp is continuous\nlemma continuous_clamp {X : Type} [linear_order X] [topological_space X] [order_topology X]\n    (lo hi : X) : continuous (\u03bb x, clamp x lo hi) :=\n  continuous.comp (continuous.max continuous_const continuous_id) (continuous.min continuous_const continuous_id)\n \n-- Simple facts about min, max, and ereal coe\n@[simp] lemma ereal.min_coe {x y : \u211d} : min (x : ereal) y = \u2191(min x y) := begin\n  by_cases h : x \u2264 y, simp [h], simp at h, simp [le_of_lt h],\nend\n@[simp] lemma ereal.max_coe {x y : \u211d} : max (x : ereal) y = \u2191(max x y) := begin\n  by_cases h : x \u2264 y, simp [h], simp at h, simp [le_of_lt h],\nend\n@[simp] lemma clamp_ereal_coe {x lo hi : \u211d} : clamp (x : ereal) lo hi = \u2191(clamp x lo hi) := by simp [clamp]\n@[simp] lemma ereal.min_coe_finite {x y : \u211d} : (min (x : ereal) y).is_finite := \u27e8min x y, by simp\u27e9\n@[simp] lemma ereal.max_coe_finite {x y : \u211d} : (max (x : ereal) y).is_finite := \u27e8max x y, by simp\u27e9\n\n-- Clamping ereals produces reals for real intervals\nlemma ereal_clamp_finite (x : ereal) (lo hi : \u211d) : (clamp x \u2191lo \u2191hi).is_finite := begin\n  rw clamp, induction x using ereal.rec, simp, simp, simp,\nend\n@[simp] lemma ereal.clamp_ne_bot {x : ereal} {lo hi : \u211d} : clamp x lo hi \u2260 \u22a5 :=\n  ne_of_gt (lt_of_lt_of_le (by simp) (le_clamp x lo hi))\n@[simp] lemma ereal.clamp_ne_top {x : ereal} {lo hi : \u211d} : clamp x lo hi \u2260 \u22a4 :=\n  ne_of_lt (lt_of_le_of_lt (clamp_le x lo hi) (by simp))\n\n-- Clamp an ereal to be between two real values\ndef ereal.clamp (x : ereal) (lo hi : \u211d) : \u211d := (clamp x \u2191lo \u2191hi).to_real\n\n-- Facts about ereal.clamp\n@[simp] lemma ereal.clamp_bot {lo hi : \u211d} : ereal.clamp \u22a5 lo hi = lo := by simp [ereal.clamp]\n@[simp] lemma ereal.clamp_top {lo hi : \u211d} : ereal.clamp \u22a4 lo hi = max lo hi := by simp [ereal.clamp]\n@[simp] lemma ereal.clamp_coe {x lo hi : \u211d} : ereal.clamp x lo hi = clamp x lo hi := by simp [ereal.clamp]\nlemma ereal.le_clamp {x : ereal} {lo hi : \u211d} : lo \u2264 x.clamp lo hi :=\n  ereal.to_real_le_to_real (le_clamp x lo hi) (by simp) (by simp)\nlemma ereal.clamp_le (x : ereal) (lo hi : \u211d) : x.clamp lo hi \u2264 max lo hi :=\n  ereal.to_real_le_to_real (clamp_le x lo hi) (by simp) (by simp)\nlemma monotone.ereal_clamp (lo hi : \u211d) : monotone (\u03bb x, ereal.clamp x lo hi) :=\n  \u03bb x y xy, ereal.to_real_le_to_real (monotone.clamp (lo : ereal) hi xy) (by simp) (by simp)\nlemma ereal.le_clamp_of_le_hi (x : ereal) (lo hi : \u211d) : x \u2264 hi \u2192 x \u2264 x.clamp lo hi := begin\n  intro h, rw ereal.clamp,\n  rcases ereal_clamp_finite x lo hi with \u27e8y,hy\u27e9, rw hy, simp, rw \u2190hy,\n  exact le_clamp_of_le_hi x lo hi h,\nend\nlemma ereal.clamp_le_lox (x : ereal) (lo hi : \u211d) : \u2191(x.clamp lo hi) \u2264 max \u2191lo x := begin\n  rw ereal.clamp, have h := clamp_le_lox x lo hi,\n  rcases ereal_clamp_finite x lo hi with \u27e8y,hy\u27e9, rw hy at \u22a2 h, exact trans (by simp) h,\nend\n\n-- ereal.clamp is the identity inside the bounds\nlemma ereal.clamp_inv {x : ereal} {lo hi y : \u211d} (y0 : lo < y) (y1 : y < hi) : x.clamp lo hi = y \u2194 x = y := begin\n  have h := clamp_inv x y (ereal.coe_lt_coe_iff.mpr y0) (ereal.coe_lt_coe_iff.mpr y1),\n  simp [ereal.clamp], rcases ereal_clamp_finite x lo hi with \u27e8z,cz\u27e9, simp [cz] at h \u22a2, assumption,\nend\n\n-- ereal.clamp is continuous in x\nlemma continuous.ereal_clamp {lo hi : \u211d} : continuous (\u03bb x, ereal.clamp x lo hi) := begin\n  simp_rw ereal.clamp,\n  apply ereal.continuous_on_to_real.comp_continuous (continuous_clamp _ _),\n  simp,\nend\n\n-- Convert from ereal to ennreal, clamping negative values to 0\ndef ereal.to_ennreal : ereal \u2192 ennreal\n| \u22a4 := \u22a4\n| (x : \u211d) := ennreal.of_real x\n| \u22a5 := 0\n\nlemma ereal.to_ennreal_neg {x : ereal} (h : x \u2264 0) : x.to_ennreal = 0 := begin\n  induction x using ereal.rec,\n  simp [ereal.to_ennreal],\n  simp [ereal.to_ennreal],\n  have e : (0 : ereal) = ((0 : \u211d) : ereal) := by simp,\n  rw [e, ereal.coe_le_coe_iff] at h, exact h,\n  simp at h, finish,\nend\n\n@[simp] lemma ereal.to_real_to_ennreal {x : ereal} : x.to_ennreal.to_real = max 0 x.to_real := begin\n  by_cases h : x < 0, {\n    simp [ereal.to_ennreal_neg (le_of_lt h)],\n    induction x using ereal.rec, simp,\n    have e : (0 : ereal) = ((0 : \u211d) : ereal) := by simp,\n    rw [e, ereal.coe_lt_coe_iff] at h, simp [le_of_lt h],\n    simp,\n  }, {\n    simp at h,\n    induction x using ereal.rec,\n    simp [ereal.to_ennreal], swap, simp [ereal.to_ennreal],\n    simp [ereal.to_ennreal],\n    have e : (0 : ereal) = ((0 : \u211d) : ereal) := by simp,\n    rw [e, ereal.coe_le_coe_iff] at h, simp [ennreal.to_real_of_real h, h],\n  }\nend\n\nlemma ereal.to_ennreal_ne_top_iff {x : ereal} : x.to_ennreal \u2260 \u22a4 \u2194 x \u2260 \u22a4 := begin\n  induction x using ereal.rec, simp [ereal.to_ennreal], simp [ereal.to_ennreal], simp [ereal.to_ennreal],\nend\n\n@[simp] lemma ereal.to_ennreal_coe {x : ennreal} : (x : ereal).to_ennreal = x := begin\n  induction x using with_top.rec_top_coe,\n  simp [ereal.to_ennreal],\n  rw \u2190ennreal.to_real_eq_to_real,\n  simp, swap, simp,\n  rw ereal.to_ennreal_ne_top_iff, simp,\nend\n\nlemma ereal.coe_to_ennreal {x : ereal} (h : x \u2265 0) : \u2191(x.to_ennreal) = x := begin\n  induction x using ereal.rec,\n  simp at h, simp [h], swap, simp [ereal.to_ennreal],\n  simp [ereal.to_ennreal],\n  have e : (0 : ereal) = ((0 : \u211d) : ereal) := by simp,\n  have h' := simple.ge_to_le h,\n  rw [e, ereal.coe_le_coe_iff] at h',\n  rw \u2190real.coe_to_nnreal _ h',\n  generalize hy : x.to_nnreal = y,\n  rw \u2190ereal.coe_nnreal_eq_coe_real,\n  simp,\nend", "meta": {"author": "girving", "repo": "ray", "sha": "e0c501756e067711e2d3667d4b1d18045d83a313", "save_path": "github-repos/lean/girving-ray", "path": "github-repos/lean/girving-ray/ray-e0c501756e067711e2d3667d4b1d18045d83a313/src/ereal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.720643265715098}}
{"text": "/-\nCopyright (c) 2021 Sara D\u00edaz Real. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sara D\u00edaz Real\n-/\nimport data.int.basic\nimport algebra.associated\nimport tactic.linarith\nimport tactic.linear_combination\n\n/-!\n# IMO 2001 Q6\nLet $a$, $b$, $c$, $d$ be integers with $a > b > c > d > 0$. Suppose that\n\n$$ a*c + b*d = (a + b - c + d) * (-a + b + c + d). $$\n\nProve that $a*b + c*d$ is not prime.\n\n-/\n\nvariables {a b c d : \u2124}\n\ntheorem imo2001_q6 (hd : 0 < d) (hdc : d < c) (hcb : c < b) (hba : b < a)\n  (h : a*c + b*d = (a + b - c + d) * (-a + b + c + d)) :\n  \u00ac prime (a*b + c*d) :=\nbegin\n  assume h0 : prime (a*b + c*d),\n  have ha : 0 < a, { linarith },\n  have hb : 0 < b, { linarith },\n  have hc : 0 < c, { linarith },\n  -- the key step is to show that `a*c + b*d` divides the product `(a*b + c*d) * (a*d + b*c)`\n  have dvd_mul : a*c + b*d \u2223 (a*b + c*d) * (a*d + b*c),\n  { use b^2 + b*d + d^2,\n    linear_combination (h, b*d) },\n  -- since `a*b + c*d` is prime (by assumption), it must divide `a*c + b*d` or `a*d + b*c`\n  obtain (h1 : a*b + c*d \u2223 a*c + b*d) | (h2 : a*c + b*d \u2223 a*d + b*c) :=\n    h0.left_dvd_or_dvd_right_of_dvd_mul dvd_mul,\n  -- in both cases, we derive a contradiction\n  { have aux : 0 < a*c + b*d,         { nlinarith only [ha, hb, hc, hd] },\n    have : a*b + c*d \u2264 a*c + b*d,     { from int.le_of_dvd aux h1 },\n    nlinarith only [hba, hcb, hdc, h, this] },\n  { have aux : 0 < a*d + b*c,         { nlinarith only [ha, hb, hc, hd] },\n    have : a*c + b*d \u2264 a*d + b*c,     { from int.le_of_dvd aux h2 },\n    nlinarith only [hba, hdc, h, this] },\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/archive/imo/imo2001_q6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8080672043084051, "lm_q1q2_score": 0.7206432582583837}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport field_theory.intermediate_field\nimport ring_theory.adjoin.field\n\n/-!\n# Splitting fields\n\nThis file introduces the notion of a splitting field of a polynomial and provides an embedding from\na splitting field to any field that splits the polynomial. A polynomial `f : K[X]` splits\nover a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have\ndegree `1`. A field extension of `K` of a polynomial `f : K[X]` is called a splitting field\nif it is the smallest field extension of `K` such that `f` splits.\n\n## Main definitions\n\n* `polynomial.splitting_field f`: A fixed splitting field of the polynomial `f`.\n* `polynomial.is_splitting_field`: A predicate on a field to be a splitting field of a polynomial\n  `f`.\n\n## Main statements\n\n* `polynomial.is_splitting_field.lift`: An embedding of a splitting field of the polynomial `f` into\n  another field such that `f` splits.\n* `polynomial.is_splitting_field.alg_equiv`: Every splitting field of a polynomial `f` is isomorphic\n  to `splitting_field f` and thus, being a splitting field is unique up to isomorphism.\n\n-/\n\nnoncomputable theory\nopen_locale classical big_operators polynomial\n\nuniverses u v w\n\nvariables {F : Type u} {K : Type v} {L : Type w}\n\nnamespace polynomial\n\nvariables [field K] [field L] [field F]\nopen polynomial\n\nsection splitting_field\n\n/-- Non-computably choose an irreducible factor from a polynomial. -/\ndef factor (f : K[X]) : K[X] :=\nif H : \u2203 g, irreducible g \u2227 g \u2223 f then classical.some H else X\n\nlemma irreducible_factor (f : K[X]) : irreducible (factor f) :=\nbegin\n  rw factor, split_ifs with H, { exact (classical.some_spec H).1 }, { exact irreducible_X }\nend\n\n/-- See note [fact non-instances]. -/\nlemma fact_irreducible_factor (f : K[X]) : fact (irreducible (factor f)) :=\n\u27e8irreducible_factor f\u27e9\n\nlocal attribute [instance] fact_irreducible_factor\n\ntheorem factor_dvd_of_not_is_unit {f : K[X]} (hf1 : \u00acis_unit f) : factor f \u2223 f :=\nbegin\n  by_cases hf2 : f = 0, { rw hf2, exact dvd_zero _ },\n  rw [factor, dif_pos (wf_dvd_monoid.exists_irreducible_factor hf1 hf2)],\n  exact (classical.some_spec $ wf_dvd_monoid.exists_irreducible_factor hf1 hf2).2\nend\n\ntheorem factor_dvd_of_degree_ne_zero {f : K[X]} (hf : f.degree \u2260 0) : factor f \u2223 f :=\nfactor_dvd_of_not_is_unit (mt degree_eq_zero_of_is_unit hf)\n\ntheorem factor_dvd_of_nat_degree_ne_zero {f : K[X]} (hf : f.nat_degree \u2260 0) :\n  factor f \u2223 f :=\nfactor_dvd_of_degree_ne_zero (mt nat_degree_eq_of_degree_eq_some hf)\n\n/-- Divide a polynomial f by X - C r where r is a root of f in a bigger field extension. -/\ndef remove_factor (f : K[X]) : polynomial (adjoin_root $ factor f) :=\nmap (adjoin_root.of f.factor) f /\u2098 (X - C (adjoin_root.root f.factor))\n\ntheorem X_sub_C_mul_remove_factor (f : K[X]) (hf : f.nat_degree \u2260 0) :\n  (X - C (adjoin_root.root f.factor)) * f.remove_factor = map (adjoin_root.of f.factor) f :=\nlet \u27e8g, hg\u27e9 := factor_dvd_of_nat_degree_ne_zero hf in\nmul_div_by_monic_eq_iff_is_root.2 $ by rw [is_root.def, eval_map, hg, eval\u2082_mul, \u2190 hg,\n    adjoin_root.eval\u2082_root, zero_mul]\n\ntheorem nat_degree_remove_factor (f : K[X]) :\n  f.remove_factor.nat_degree = f.nat_degree - 1 :=\nby rw [remove_factor, nat_degree_div_by_monic _ (monic_X_sub_C _), nat_degree_map,\n       nat_degree_X_sub_C]\n\ntheorem nat_degree_remove_factor' {f : K[X]} {n : \u2115} (hfn : f.nat_degree = n+1) :\n  f.remove_factor.nat_degree = n :=\nby rw [nat_degree_remove_factor, hfn, n.add_sub_cancel]\n\n/-- Auxiliary construction to a splitting field of a polynomial, which removes\n`n` (arbitrarily-chosen) factors.\n\nUses recursion on the degree. For better definitional behaviour, structures\nincluding `splitting_field_aux` (such as instances) should be defined using\nthis recursion in each field, rather than defining the whole tuple through\nrecursion.\n-/\ndef splitting_field_aux (n : \u2115) : \u03a0 {K : Type u} [field K], by exactI \u03a0 (f : K[X]), Type u :=\nnat.rec_on n (\u03bb K _ _, K) $ \u03bb n ih K _ f, by exactI\nih f.remove_factor\n\nnamespace splitting_field_aux\n\ntheorem succ (n : \u2115) (f : K[X]) :\n  splitting_field_aux (n+1) f = splitting_field_aux n f.remove_factor := rfl\n\ninstance field (n : \u2115) : \u03a0 {K : Type u} [field K], by exactI\n  \u03a0 {f : K[X]}, field (splitting_field_aux n f) :=\nnat.rec_on n (\u03bb K _ _, \u2039field K\u203a) $ \u03bb n ih K _ f, ih\n\ninstance inhabited {n : \u2115} {f : K[X]} :\n  inhabited (splitting_field_aux n f) := \u27e837\u27e9\n\n/-\nNote that the recursive nature of this definition and `splitting_field_aux.field` creates\nnon-definitionally-equal diamonds in the `\u2115`- and `\u2124`- actions.\n```lean\nexample (n : \u2115) {K : Type u} [field K] {f : K[X]} (hfn : f.nat_degree = n) :\n    (add_comm_monoid.nat_module : module \u2115 (splitting_field_aux n f hfn)) =\n  @algebra.to_module _ _ _ _ (splitting_field_aux.algebra n _ hfn) :=\nrfl  -- fails\n```\nIt's not immediately clear whether this _can_ be fixed; the failure is much the same as the reason\nthat the following fails:\n```lean\ndef cases_twice {\u03b1} (a\u2080 a\u2099 : \u03b1) : \u2115 \u2192 \u03b1 \u00d7 \u03b1\n| 0 := (a\u2080, a\u2080)\n| (n + 1) := (a\u2099, a\u2099)\n\nexample (x : \u2115) {\u03b1} (a\u2080 a\u2099 : \u03b1) : (cases_twice a\u2080 a\u2099 x).1 = (cases_twice a\u2080 a\u2099 x).2 := rfl  -- fails\n```\nWe don't really care at this point because this is an implementation detail (which is why this is\nnot a docstring), but we do in `splitting_field.algebra'` below. -/\ninstance algebra (n : \u2115) : \u03a0 (R : Type*) {K : Type u} [comm_semiring R] [field K],\n  by exactI \u03a0 [algebra R K] {f : K[X]},\n    algebra R (splitting_field_aux n f) :=\nnat.rec_on n (\u03bb R K _ _ _ _, by exactI \u2039algebra R K\u203a) $\n         \u03bb n ih R K _ _ _ f, by exactI ih R\n\ninstance is_scalar_tower (n : \u2115) : \u03a0 (R\u2081 R\u2082 : Type*) {K : Type u}\n  [comm_semiring R\u2081] [comm_semiring R\u2082] [has_smul R\u2081 R\u2082] [field K],\n  by exactI \u03a0 [algebra R\u2081 K] [algebra R\u2082 K],\n  by exactI \u03a0 [is_scalar_tower R\u2081 R\u2082 K] {f : K[X]},\n    is_scalar_tower R\u2081 R\u2082 (splitting_field_aux n f) :=\nnat.rec_on n (\u03bb R\u2081 R\u2082 K _ _ _ _ _ _ _ _, by exactI \u2039is_scalar_tower R\u2081 R\u2082 K\u203a) $\n         \u03bb n ih R\u2081 R\u2082 K _ _ _ _ _ _ _ f, by exactI ih R\u2081 R\u2082\n\ninstance algebra''' {n : \u2115} {f : K[X]} :\n  algebra (adjoin_root f.factor)\n    (splitting_field_aux n f.remove_factor) :=\nsplitting_field_aux.algebra n _\n\ninstance algebra' {n : \u2115} {f : K[X]} :\n  algebra (adjoin_root f.factor) (splitting_field_aux n.succ f) :=\nsplitting_field_aux.algebra'''\n\ninstance algebra'' {n : \u2115} {f : K[X]} :\n  algebra K (splitting_field_aux n f.remove_factor) :=\nsplitting_field_aux.algebra n K\n\ninstance scalar_tower' {n : \u2115} {f : K[X]} :\n  is_scalar_tower K (adjoin_root f.factor)\n    (splitting_field_aux n f.remove_factor) :=\nbegin\n  -- finding this instance ourselves makes things faster\n  haveI : is_scalar_tower K (adjoin_root f.factor) (adjoin_root f.factor) :=\n    is_scalar_tower.right,\n  exact\n    splitting_field_aux.is_scalar_tower n K (adjoin_root f.factor),\nend\n\ninstance scalar_tower {n : \u2115} {f : K[X]} :\n  is_scalar_tower K (adjoin_root f.factor) (splitting_field_aux (n + 1) f) :=\nsplitting_field_aux.scalar_tower'\n\ntheorem algebra_map_succ (n : \u2115) (f : K[X]) :\n  by exact algebra_map K (splitting_field_aux (n+1) f) =\n    (algebra_map (adjoin_root f.factor)\n        (splitting_field_aux n f.remove_factor)).comp\n      (adjoin_root.of f.factor) :=\nis_scalar_tower.algebra_map_eq _ _ _\n\nprotected theorem splits (n : \u2115) : \u2200 {K : Type u} [field K], by exactI\n  \u2200 (f : K[X]) (hfn : f.nat_degree = n),\n    splits (algebra_map K $ splitting_field_aux n f) f :=\nnat.rec_on n (\u03bb K _ _ hf, by exactI splits_of_degree_le_one _\n  (le_trans degree_le_nat_degree $ hf.symm \u25b8 with_bot.coe_le_coe.2 zero_le_one)) $ \u03bb n ih K _ f hf,\nby { resetI, rw [\u2190 splits_id_iff_splits, algebra_map_succ, \u2190 map_map, splits_id_iff_splits,\n    \u2190 X_sub_C_mul_remove_factor f (\u03bb h, by { rw h at hf, cases hf })],\nexact splits_mul _ (splits_X_sub_C _) (ih _ (nat_degree_remove_factor' hf)) }\n\ntheorem exists_lift (n : \u2115) : \u2200 {K : Type u} [field K], by exactI\n  \u2200 (f : K[X]) (hfn : f.nat_degree = n) {L : Type*} [field L], by exactI\n    \u2200 (j : K \u2192+* L) (hf : splits j f), \u2203 k : splitting_field_aux n f \u2192+* L,\n      k.comp (algebra_map _ _) = j :=\nnat.rec_on n (\u03bb K _ _ _ L _ j _, by exactI \u27e8j, j.comp_id\u27e9) $ \u03bb n ih K _ f hf L _ j hj, by exactI\nhave hndf : f.nat_degree \u2260 0, by { intro h, rw h at hf, cases hf },\nhave hfn0 : f \u2260 0, by { intro h, rw h at hndf, exact hndf rfl },\nlet \u27e8r, hr\u27e9 := exists_root_of_splits _ (splits_of_splits_of_dvd j hfn0 hj\n  (factor_dvd_of_nat_degree_ne_zero hndf))\n  (mt is_unit_iff_degree_eq_zero.2 f.irreducible_factor.1) in\nhave hmf0 : map (adjoin_root.of f.factor) f \u2260 0, from map_ne_zero hfn0,\nhave hsf : splits (adjoin_root.lift j r hr) f.remove_factor,\nby { rw \u2190 X_sub_C_mul_remove_factor _ hndf at hmf0, refine (splits_of_splits_mul _ hmf0 _).2,\n  rwa [X_sub_C_mul_remove_factor _ hndf, \u2190 splits_id_iff_splits, map_map, adjoin_root.lift_comp_of,\n      splits_id_iff_splits] },\nlet \u27e8k, hk\u27e9 := ih f.remove_factor (nat_degree_remove_factor' hf) (adjoin_root.lift j r hr) hsf in\n\u27e8k, by rw [algebra_map_succ, \u2190 ring_hom.comp_assoc, hk, adjoin_root.lift_comp_of]\u27e9\n\ntheorem adjoin_roots (n : \u2115) : \u2200 {K : Type u} [field K], by exactI\n  \u2200 (f : K[X]) (hfn : f.nat_degree = n),\n    algebra.adjoin K (\u2191(f.map $ algebra_map K $ splitting_field_aux n f).roots.to_finset :\n      set (splitting_field_aux n f)) = \u22a4 :=\nnat.rec_on n (\u03bb K _ f hf, by exactI algebra.eq_top_iff.2 (\u03bb x, subalgebra.range_le _ \u27e8x, rfl\u27e9)) $\n\u03bb n ih K _ f hfn, by exactI\nhave hndf : f.nat_degree \u2260 0, by { intro h, rw h at hfn, cases hfn },\nhave hfn0 : f \u2260 0, by { intro h, rw h at hndf, exact hndf rfl },\nhave hmf0 : map (algebra_map K (splitting_field_aux n.succ f)) f \u2260 0 := map_ne_zero hfn0,\nby { rw [algebra_map_succ, \u2190 map_map, \u2190 X_sub_C_mul_remove_factor _ hndf,\n         polynomial.map_mul] at hmf0 \u22a2,\nrw [roots_mul hmf0, polynomial.map_sub, map_X, map_C, roots_X_sub_C, multiset.to_finset_add,\n    finset.coe_union, multiset.to_finset_singleton, finset.coe_singleton,\n    algebra.adjoin_union_eq_adjoin_adjoin, \u2190 set.image_singleton,\n    algebra.adjoin_algebra_map K (adjoin_root f.factor)\n      (splitting_field_aux n f.remove_factor),\n    adjoin_root.adjoin_root_eq_top, algebra.map_top,\n    is_scalar_tower.adjoin_range_to_alg_hom K (adjoin_root f.factor)\n      (splitting_field_aux n f.remove_factor),\n    ih _ (nat_degree_remove_factor' hfn), subalgebra.restrict_scalars_top] }\n\nend splitting_field_aux\n\n/-- A splitting field of a polynomial. -/\ndef splitting_field (f : K[X]) :=\nsplitting_field_aux f.nat_degree f\n\nnamespace splitting_field\n\nvariables (f : K[X])\n\ninstance : field (splitting_field f) :=\nsplitting_field_aux.field _\n\ninstance inhabited : inhabited (splitting_field f) := \u27e837\u27e9\n\n/-- This should be an instance globally, but it creates diamonds with the `\u2115`, `\u2124`, and `\u211a` algebras\n(via their `smul` and `to_fun` fields):\n\n```lean\nexample :\n  (algebra_nat : algebra \u2115 (splitting_field f)) = splitting_field.algebra' f :=\nrfl  -- fails\n\nexample :\n  (algebra_int _ : algebra \u2124 (splitting_field f)) = splitting_field.algebra' f :=\nrfl  -- fails\n\nexample [char_zero K] [char_zero (splitting_field f)] :\n  (algebra_rat : algebra \u211a (splitting_field f)) = splitting_field.algebra' f :=\nrfl  -- fails\n```\n\nUntil we resolve these diamonds, it's more convenient to only turn this instance on with\n`local attribute [instance]` in places where the benefit of having the instance outweighs the cost.\n\nIn the meantime, the `splitting_field.algebra` instance below is immune to these particular diamonds\nsince `K = \u2115` and `K = \u2124` are not possible due to the `field K` assumption. Diamonds in\n`algebra \u211a (splitting_field f)` instances are still possible via this instance unfortunately, but\nthese are less common as they require suitable `char_zero` instances to be present.\n-/\ninstance algebra' {R} [comm_semiring R] [algebra R K] : algebra R (splitting_field f) :=\nsplitting_field_aux.algebra _ _\n\ninstance : algebra K (splitting_field f) :=\nsplitting_field_aux.algebra _ _\n\nprotected theorem splits : splits (algebra_map K (splitting_field f)) f :=\nsplitting_field_aux.splits _ _ rfl\n\nvariables [algebra K L] (hb : splits (algebra_map K L) f)\n\n/-- Embeds the splitting field into any other field that splits the polynomial. -/\ndef lift : splitting_field f \u2192\u2090[K] L :=\n{ commutes' := \u03bb r, by { have := classical.some_spec (splitting_field_aux.exists_lift _ _ rfl _ hb),\n    exact ring_hom.ext_iff.1 this r },\n  .. classical.some (splitting_field_aux.exists_lift _ _ _ _ hb) }\n\ntheorem adjoin_roots : algebra.adjoin K\n    (\u2191(f.map (algebra_map K $ splitting_field f)).roots.to_finset : set (splitting_field f)) = \u22a4 :=\nsplitting_field_aux.adjoin_roots _ _ rfl\n\ntheorem adjoin_root_set : algebra.adjoin K (f.root_set f.splitting_field) = \u22a4 :=\nadjoin_roots f\n\nend splitting_field\n\nvariables (K L) [algebra K L]\n/-- Typeclass characterising splitting fields. -/\nclass is_splitting_field (f : K[X]) : Prop :=\n(splits [] : splits (algebra_map K L) f)\n(adjoin_roots [] : algebra.adjoin K (\u2191(f.map (algebra_map K L)).roots.to_finset : set L) = \u22a4)\n\nnamespace is_splitting_field\n\nvariables {K}\ninstance splitting_field (f : K[X]) : is_splitting_field K (splitting_field f) f :=\n\u27e8splitting_field.splits f, splitting_field.adjoin_roots f\u27e9\n\nsection scalar_tower\n\nvariables {K L F} [algebra F K] [algebra F L] [is_scalar_tower F K L]\n\nvariables {K}\ninstance map (f : F[X]) [is_splitting_field F L f] :\n  is_splitting_field K L (f.map $ algebra_map F K) :=\n\u27e8by { rw [splits_map_iff, \u2190 is_scalar_tower.algebra_map_eq], exact splits L f },\n subalgebra.restrict_scalars_injective F $\n  by { rw [map_map, \u2190 is_scalar_tower.algebra_map_eq, subalgebra.restrict_scalars_top,\n    eq_top_iff, \u2190 adjoin_roots L f, algebra.adjoin_le_iff],\n  exact \u03bb x hx, @algebra.subset_adjoin K _ _ _ _ _ _ hx }\u27e9\n\nvariables {K} (L)\ntheorem splits_iff (f : K[X]) [is_splitting_field K L f] :\n  polynomial.splits (ring_hom.id K) f \u2194 (\u22a4 : subalgebra K L) = \u22a5 :=\n\u27e8\u03bb h, eq_bot_iff.2 $ adjoin_roots L f \u25b8 (roots_map (algebra_map K L) h).symm \u25b8\n  algebra.adjoin_le_iff.2 (\u03bb y hy,\n    let \u27e8x, hxs, hxy\u27e9 := finset.mem_image.1 (by rwa multiset.to_finset_map at hy) in\n    hxy \u25b8 set_like.mem_coe.2 $ subalgebra.algebra_map_mem _ _),\n \u03bb h, @ring_equiv.to_ring_hom_refl K _ \u25b8\n  ring_equiv.self_trans_symm (ring_equiv.of_bijective _ $ algebra.bijective_algebra_map_iff.2 h) \u25b8\n  by { rw ring_equiv.to_ring_hom_trans, exact splits_comp_of_splits _ _ (splits L f) }\u27e9\n\ntheorem mul (f g : F[X]) (hf : f \u2260 0) (hg : g \u2260 0) [is_splitting_field F K f]\n  [is_splitting_field K L (g.map $ algebra_map F K)] :\n  is_splitting_field F L (f * g) :=\n\u27e8(is_scalar_tower.algebra_map_eq F K L).symm \u25b8 splits_mul _\n  (splits_comp_of_splits _ _ (splits K f))\n  ((splits_map_iff _ _).1 (splits L $ g.map $ algebra_map F K)),\n by rw [polynomial.map_mul, roots_mul (mul_ne_zero (map_ne_zero hf : f.map (algebra_map F L) \u2260 0)\n        (map_ne_zero hg)), multiset.to_finset_add, finset.coe_union,\n      algebra.adjoin_union_eq_adjoin_adjoin,\n      is_scalar_tower.algebra_map_eq F K L, \u2190 map_map,\n      roots_map (algebra_map K L) ((splits_id_iff_splits $ algebra_map F K).2 $ splits K f),\n      multiset.to_finset_map, finset.coe_image, algebra.adjoin_algebra_map, adjoin_roots,\n      algebra.map_top, is_scalar_tower.adjoin_range_to_alg_hom, \u2190 map_map, adjoin_roots,\n      subalgebra.restrict_scalars_top]\u27e9\n\nend scalar_tower\n\n/-- Splitting field of `f` embeds into any field that splits `f`. -/\ndef lift [algebra K F] (f : K[X]) [is_splitting_field K L f]\n  (hf : polynomial.splits (algebra_map K F) f) : L \u2192\u2090[K] F :=\nif hf0 : f = 0 then (algebra.of_id K F).comp $\n  (algebra.bot_equiv K L : (\u22a5 : subalgebra K L) \u2192\u2090[K] K).comp $\n  by { rw \u2190 (splits_iff L f).1 (show f.splits (ring_hom.id K), from hf0.symm \u25b8 splits_zero _),\n  exact algebra.to_top } else\nalg_hom.comp (by { rw \u2190 adjoin_roots L f, exact classical.choice (lift_of_splits _ $ \u03bb y hy,\n    have aeval y f = 0, from (eval\u2082_eq_eval_map _).trans $\n      (mem_roots $ by exact map_ne_zero hf0).1 (multiset.mem_to_finset.mp hy),\n    \u27e8is_algebraic_iff_is_integral.1 \u27e8f, hf0, this\u27e9,\n      splits_of_splits_of_dvd _ hf0 hf $ minpoly.dvd _ _ this\u27e9) })\n  algebra.to_top\n\ntheorem finite_dimensional (f : K[X]) [is_splitting_field K L f] : finite_dimensional K L :=\n\u27e8@algebra.top_to_submodule K L _ _ _ \u25b8 adjoin_roots L f \u25b8\n  fg_adjoin_of_finite (finset.finite_to_set _) (\u03bb y hy,\n  if hf : f = 0\n  then by { rw [hf, polynomial.map_zero, roots_zero] at hy, cases hy }\n  else is_algebraic_iff_is_integral.1 \u27e8f, hf, (eval\u2082_eq_eval_map _).trans $\n    (mem_roots $ by exact map_ne_zero hf).1 (multiset.mem_to_finset.mp hy)\u27e9)\u27e9\n\ninstance (f : K[X]) : _root_.finite_dimensional K f.splitting_field :=\nfinite_dimensional f.splitting_field f\n\n/-- Any splitting field is isomorphic to `splitting_field f`. -/\ndef alg_equiv (f : K[X]) [is_splitting_field K L f] : L \u2243\u2090[K] splitting_field f :=\nbegin\n  refine alg_equiv.of_bijective (lift L f $ splits (splitting_field f) f)\n    \u27e8ring_hom.injective (lift L f $ splits (splitting_field f) f).to_ring_hom, _\u27e9,\n  haveI := finite_dimensional (splitting_field f) f,\n  haveI := finite_dimensional L f,\n  have : finite_dimensional.finrank K L = finite_dimensional.finrank K (splitting_field f) :=\n  le_antisymm\n    (linear_map.finrank_le_finrank_of_injective\n      (show function.injective (lift L f $ splits (splitting_field f) f).to_linear_map, from\n        ring_hom.injective (lift L f $ splits (splitting_field f) f : L \u2192+* f.splitting_field)))\n    (linear_map.finrank_le_finrank_of_injective\n      (show function.injective (lift (splitting_field f) f $ splits L f).to_linear_map, from\n        ring_hom.injective (lift (splitting_field f) f $ splits L f : f.splitting_field \u2192+* L))),\n  change function.surjective (lift L f $ splits (splitting_field f) f).to_linear_map,\n  refine (linear_map.injective_iff_surjective_of_finrank_eq_finrank this).1 _,\n  exact ring_hom.injective (lift L f $ splits (splitting_field f) f : L \u2192+* f.splitting_field)\nend\n\nlemma of_alg_equiv [algebra K F] (p : K[X]) (f : F \u2243\u2090[K] L) [is_splitting_field K F p] :\n  is_splitting_field K L p :=\nbegin\n  split,\n  { rw \u2190 f.to_alg_hom.comp_algebra_map,\n    exact splits_comp_of_splits _ _ (splits F p) },\n  { rw [\u2190(algebra.range_top_iff_surjective f.to_alg_hom).mpr f.surjective,\n        \u2190root_set, adjoin_root_set_eq_range (splits F p), root_set, adjoin_roots F p] },\nend\n\nend is_splitting_field\n\nend splitting_field\n\nend polynomial\n\nnamespace intermediate_field\n\nopen polynomial\n\nvariables [field K] [field L] [algebra K L] {p : K[X]}\n\nlemma splits_of_splits {F : intermediate_field K L} (h : p.splits (algebra_map K L))\n  (hF : \u2200 x \u2208 p.root_set L, x \u2208 F) : p.splits (algebra_map K F) :=\nbegin\n  simp_rw [root_set, finset.mem_coe, multiset.mem_to_finset] at hF,\n  rw splits_iff_exists_multiset,\n  refine \u27e8multiset.pmap subtype.mk _ hF, map_injective _ (algebra_map F L).injective _\u27e9,\n  conv_lhs { rw [polynomial.map_map, \u2190is_scalar_tower.algebra_map_eq,\n    eq_prod_roots_of_splits h, \u2190multiset.pmap_eq_map _ _ _ hF] },\n  simp_rw [polynomial.map_mul, polynomial.map_multiset_prod,\n    multiset.map_pmap, polynomial.map_sub, map_C, map_X],\n  refl,\nend\n\nend intermediate_field\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/field_theory/splitting_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7206432554098224}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp, Yury Kudriashov\n-/\nimport analysis.convex.basic\nimport analysis.normed_space.finite_dimension\nimport topology.path_connected\n\n/-!\n# Topological and metric properties of convex sets\n\nWe prove the following facts:\n\n* `convex.interior` : interior of a convex set is convex;\n* `convex.closure` : closure of a convex set is convex;\n* `set.finite.compact_convex_hull` : convex hull of a finite set is compact;\n* `set.finite.is_closed_convex_hull` : convex hull of a finite set is closed;\n* `convex_on_dist` : distance to a fixed point is convex on any convex set;\n* `convex_hull_ediam`, `convex_hull_diam` : convex hull of a set has the same (e)metric diameter\n  as the original set;\n* `bounded_convex_hull` : convex hull of a set is bounded if and only if the original set\n  is bounded.\n* `bounded_std_simplex`, `is_closed_std_simplex`, `compact_std_simplex`: topological properties\n  of the standard simplex;\n-/\n\nvariables {\u03b9 : Type*} {E : Type*}\n\nopen set\n\nlemma real.convex_iff_is_preconnected {s : set \u211d} : convex s \u2194 is_preconnected s :=\nreal.convex_iff_ord_connected.trans is_preconnected_iff_ord_connected.symm\n\nalias real.convex_iff_is_preconnected \u2194 convex.is_preconnected is_preconnected.convex\n\n/-! ### Standard simplex -/\n\nsection std_simplex\n\nvariables [fintype \u03b9]\n\n/-- Every vector in `std_simplex \u03b9` has `max`-norm at most `1`. -/\nlemma std_simplex_subset_closed_ball :\n  std_simplex \u03b9 \u2286 metric.closed_ball 0 1 :=\nbegin\n  assume f hf,\n  rw [metric.mem_closed_ball, dist_zero_right],\n  refine (nnreal.coe_one \u25b8 nnreal.coe_le_coe.2 $ finset.sup_le $ \u03bb x hx, _),\n  change abs (f x) \u2264 1,\n  rw [abs_of_nonneg $ hf.1 x],\n  exact (mem_Icc_of_mem_std_simplex hf x).2\nend\n\nvariable (\u03b9)\n\n/-- `std_simplex \u03b9` is bounded. -/\nlemma bounded_std_simplex : metric.bounded (std_simplex \u03b9) :=\n(metric.bounded_iff_subset_ball 0).2 \u27e81, std_simplex_subset_closed_ball\u27e9\n\n/-- `std_simplex \u03b9` is closed. -/\nlemma is_closed_std_simplex : is_closed (std_simplex \u03b9) :=\n(std_simplex_eq_inter \u03b9).symm \u25b8 is_closed_inter\n  (is_closed_Inter $ \u03bb i, is_closed_le continuous_const (continuous_apply i))\n  (is_closed_eq (continuous_finset_sum _ $ \u03bb x _, continuous_apply x) continuous_const)\n\n/-- `std_simplex \u03b9` is compact. -/\nlemma compact_std_simplex : is_compact (std_simplex \u03b9) :=\nmetric.compact_iff_closed_bounded.2 \u27e8is_closed_std_simplex \u03b9, bounded_std_simplex \u03b9\u27e9\n\nend std_simplex\n\n/-! ### Topological vector space -/\n\nsection has_continuous_smul\n\nvariables [add_comm_group E] [module \u211d E] [topological_space E]\n  [topological_add_group E] [has_continuous_smul \u211d E]\n\n/-- In a topological vector space, the interior of a convex set is convex. -/\nlemma convex.interior {s : set E} (hs : convex s) : convex (interior s) :=\nconvex_iff_pointwise_add_subset.mpr $ \u03bb a b ha hb hab,\n  have h : is_open (a \u2022 interior s + b \u2022 interior s), from\n  or.elim (classical.em (a = 0))\n  (\u03bb heq,\n    have hne : b \u2260 0, by { rw [heq, zero_add] at hab, rw hab, exact one_ne_zero },\n    by { rw \u2190 image_smul,\n         exact (is_open_map_smul' hne _ is_open_interior).add_left } )\n  (\u03bb hne,\n    by { rw \u2190 image_smul,\n         exact (is_open_map_smul' hne _ is_open_interior).add_right }),\n  (subset_interior_iff_subset_of_open h).mpr $ subset.trans\n    (by { simp only [\u2190 image_smul], apply add_subset_add; exact image_subset _ interior_subset })\n    (convex_iff_pointwise_add_subset.mp hs ha hb hab)\n\n/-- In a topological vector space, the closure of a convex set is convex. -/\nlemma convex.closure {s : set E} (hs : convex s) : convex (closure s) :=\n\u03bb x y hx hy a b ha hb hab,\nlet f : E \u2192 E \u2192 E := \u03bb x' y', a \u2022 x' + b \u2022 y' in\nhave hf : continuous (\u03bb p : E \u00d7 E, f p.1 p.2), from\n  (continuous_const.smul continuous_fst).add (continuous_const.smul continuous_snd),\nshow f x y \u2208 closure s, from\n  mem_closure_of_continuous2 hf hx hy (\u03bb x' hx' y' hy', subset_closure\n  (hs hx' hy' ha hb hab))\n\n/-- Convex hull of a finite set is compact. -/\nlemma set.finite.compact_convex_hull {s : set E} (hs : finite s) :\n  is_compact (convex_hull s) :=\nbegin\n  rw [hs.convex_hull_eq_image],\n  apply (compact_std_simplex _).image,\n  haveI := hs.fintype,\n  apply linear_map.continuous_on_pi\nend\n\n/-- Convex hull of a finite set is closed. -/\nlemma set.finite.is_closed_convex_hull [t2_space E] {s : set E} (hs : finite s) :\n  is_closed (convex_hull s) :=\nhs.compact_convex_hull.is_closed\n\nend has_continuous_smul\n\n/-! ### Normed vector space -/\n\nsection normed_space\nvariables [normed_group E] [normed_space \u211d E]\n\nlemma convex_on_dist (z : E) (s : set E) (hs : convex s) :\n  convex_on s (\u03bbz', dist z' z) :=\nand.intro hs $\nassume x y hx hy a b ha hb hab,\ncalc\n  dist (a \u2022 x + b \u2022 y) z = \u2225 (a \u2022 x + b \u2022 y) - (a + b) \u2022 z \u2225 :\n    by rw [hab, one_smul, normed_group.dist_eq]\n  ... = \u2225a \u2022 (x - z) + b \u2022 (y - z)\u2225 :\n    by rw [add_smul, smul_sub, smul_sub, sub_eq_add_neg, sub_eq_add_neg, sub_eq_add_neg, neg_add,\n           \u2190add_assoc, add_assoc (a \u2022 x), add_comm (b \u2022 y)]; simp only [add_assoc]\n  ... \u2264 \u2225a \u2022 (x - z)\u2225 + \u2225b \u2022 (y - z)\u2225 :\n    norm_add_le (a \u2022 (x - z)) (b \u2022 (y - z))\n  ... = a * dist x z + b * dist y z :\n    by simp [norm_smul, normed_group.dist_eq, real.norm_eq_abs, abs_of_nonneg ha, abs_of_nonneg hb]\n\nlemma convex_ball (a : E) (r : \u211d) : convex (metric.ball a r) :=\nby simpa only [metric.ball, sep_univ] using (convex_on_dist a _ convex_univ).convex_lt r\n\nlemma convex_closed_ball (a : E) (r : \u211d) : convex (metric.closed_ball a r) :=\nby simpa only [metric.closed_ball, sep_univ] using (convex_on_dist a _ convex_univ).convex_le r\n\n/-- Given a point `x` in the convex hull of `s` and a point `y`, there exists a point\nof `s` at distance at least `dist x y` from `y`. -/\nlemma convex_hull_exists_dist_ge {s : set E} {x : E} (hx : x \u2208 convex_hull s) (y : E) :\n  \u2203 x' \u2208 s, dist x y \u2264 dist x' y :=\n(convex_on_dist y _ (convex_convex_hull _)).exists_ge_of_mem_convex_hull hx\n\n/-- Given a point `x` in the convex hull of `s` and a point `y` in the convex hull of `t`,\nthere exist points `x' \u2208 s` and `y' \u2208 t` at distance at least `dist x y`. -/\nlemma convex_hull_exists_dist_ge2 {s t : set E} {x y : E}\n  (hx : x \u2208 convex_hull s) (hy : y \u2208 convex_hull t) :\n  \u2203 (x' \u2208 s) (y' \u2208 t), dist x y \u2264 dist x' y' :=\nbegin\n  rcases convex_hull_exists_dist_ge hx y with \u27e8x', hx', Hx'\u27e9,\n  rcases convex_hull_exists_dist_ge hy x' with \u27e8y', hy', Hy'\u27e9,\n  use [x', hx', y', hy'],\n  exact le_trans Hx' (dist_comm y x' \u25b8 dist_comm y' x' \u25b8 Hy')\nend\n\n/-- Emetric diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/\n@[simp] lemma convex_hull_ediam (s : set E) :\n  emetric.diam (convex_hull s) = emetric.diam s :=\nbegin\n  refine (emetric.diam_le $ \u03bb x hx y hy, _).antisymm (emetric.diam_mono $ subset_convex_hull s),\n  rcases convex_hull_exists_dist_ge2 hx hy with \u27e8x', hx', y', hy', H\u27e9,\n  rw edist_dist,\n  apply le_trans (ennreal.of_real_le_of_real H),\n  rw \u2190 edist_dist,\n  exact emetric.edist_le_diam_of_mem hx' hy'\nend\n\n/-- Diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/\n@[simp] lemma convex_hull_diam (s : set E) :\n  metric.diam (convex_hull s) = metric.diam s :=\nby simp only [metric.diam, convex_hull_ediam]\n\n/-- Convex hull of `s` is bounded if and only if `s` is bounded. -/\n@[simp] lemma bounded_convex_hull {s : set E} :\n  metric.bounded (convex_hull s) \u2194 metric.bounded s :=\nby simp only [metric.bounded_iff_ediam_ne_top, convex_hull_ediam]\n\nlemma convex.is_path_connected {s : set E} (hconv : convex s) (hne : s.nonempty) :\n  is_path_connected s :=\nbegin\n  refine is_path_connected_iff.mpr \u27e8hne, _\u27e9,\n  intros x y x_in y_in,\n  let f := \u03bb \u03b8 : \u211d, x + \u03b8 \u2022 (y - x),\n  have hf : continuous f, by continuity,\n  have h\u2080 : f 0 = x, by simp [f],\n  have h\u2081 : f 1 = y, by { dsimp [f], rw one_smul, abel },\n  have H := hconv.segment_subset x_in y_in,\n  rw segment_eq_image' at H,\n  exact joined_in.of_line hf.continuous_on h\u2080 h\u2081 H\nend\n\n@[priority 100]\ninstance normed_space.path_connected : path_connected_space E :=\npath_connected_space_iff_univ.mpr $ convex_univ.is_path_connected \u27e8(0 : E), trivial\u27e9\n\n@[priority 100]\ninstance normed_space.loc_path_connected : loc_path_connected_space E :=\nloc_path_connected_of_bases (\u03bb x, metric.nhds_basis_ball)\n  (\u03bb x r r_pos, (convex_ball x r).is_path_connected $ by simp [r_pos])\n\nend normed_space\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/convex/topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7206307499868602}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen, Kexing Ying, Eric Wieser\n-/\nimport linear_algebra.quadratic_form.isometry\nimport analysis.special_functions.pow\nimport data.real.sign\n\n/-!\n# Real quadratic forms\n\nSylvester's law of inertia `equivalent_one_neg_one_weighted_sum_squared`:\nA real quadratic form is equivalent to a weighted\nsum of squares with the weights being \u00b11 or 0.\n\nWhen the real quadratic form is nondegerate we can take the weights to be \u00b11,\nas in `equivalent_one_zero_neg_one_weighted_sum_squared`.\n\n-/\n\nnamespace quadratic_form\n\nopen_locale big_operators\nopen real finset\n\nvariables {\u03b9 : Type*} [fintype \u03b9]\n\n/-- The isometry between a weighted sum of squares with weights `u` on the\n(non-zero) real numbers and the weighted sum of squares with weights `sign \u2218 u`. -/\nnoncomputable def isometry_sign_weighted_sum_squares\n  [decidable_eq \u03b9] (w : \u03b9 \u2192 \u211d) :\n  isometry (weighted_sum_squares \u211d w) (weighted_sum_squares \u211d (sign \u2218 w)) :=\nbegin\n  let u := \u03bb i, if h : w i = 0 then (1 : \u211d\u02e3) else units.mk0 (w i) h,\n  have hu' : \u2200 i : \u03b9, (sign (u i) * u i) ^ - (1 / 2 : \u211d) \u2260 0,\n  { intro i, refine (ne_of_lt (real.rpow_pos_of_pos\n      (sign_mul_pos_of_ne_zero _ $ units.ne_zero _) _)).symm},\n  convert ((weighted_sum_squares \u211d w).isometry_basis_repr\n    ((pi.basis_fun \u211d \u03b9).units_smul (\u03bb i, (is_unit_iff_ne_zero.2 $ hu' i).unit))),\n  ext1 v,\n  rw [basis_repr_apply, weighted_sum_squares_apply, weighted_sum_squares_apply],\n  refine sum_congr rfl (\u03bb j hj, _),\n  have hsum : (\u2211 (i : \u03b9), v i \u2022 ((is_unit_iff_ne_zero.2 $ hu' i).unit : \u211d) \u2022\n    (pi.basis_fun \u211d \u03b9) i) j = v j \u2022 (sign (u j) * u j) ^ - (1 / 2 : \u211d),\n  { rw [finset.sum_apply, sum_eq_single j, pi.basis_fun_apply, is_unit.unit_spec,\n        linear_map.std_basis_apply, pi.smul_apply, pi.smul_apply, function.update_same,\n        smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_one],\n    intros i _ hij,\n    rw [pi.basis_fun_apply, linear_map.std_basis_apply, pi.smul_apply, pi.smul_apply,\n        function.update_noteq hij.symm, pi.zero_apply, smul_eq_mul, smul_eq_mul,\n        mul_zero, mul_zero],\n    intro hj', exact false.elim (hj' hj) },\n  simp_rw basis.units_smul_apply,\n  erw [hsum],\n  simp only [u, function.comp, smul_eq_mul],\n  split_ifs,\n  { simp only [h, zero_smul, zero_mul, real.sign_zero] },\n  have hwu : w j = u j,\n  { simp only [u, dif_neg h, units.coe_mk0] },\n  simp only [hwu, units.coe_mk0],\n  suffices : (u j : \u211d).sign * v j * v j = (sign (u j) * u j) ^ - (1 / 2 : \u211d) *\n    (sign (u j) * u j) ^ - (1 / 2 : \u211d) * u j * v j * v j,\n  { erw [\u2190 mul_assoc, this], ring },\n  rw [\u2190 real.rpow_add (sign_mul_pos_of_ne_zero _ $ units.ne_zero _),\n      show - (1 / 2 : \u211d) + - (1 / 2) = -1, by ring, real.rpow_neg_one, mul_inv,\n      inv_sign, mul_assoc (sign (u j)) (u j)\u207b\u00b9,\n      inv_mul_cancel (units.ne_zero _), mul_one],\n  apply_instance\nend\n\n/-- **Sylvester's law of inertia**: A nondegenerate real quadratic form is equivalent to a weighted\nsum of squares with the weights being \u00b11. -/\ntheorem equivalent_one_neg_one_weighted_sum_squared\n  {M : Type*} [add_comm_group M] [module \u211d M] [finite_dimensional \u211d M]\n  (Q : quadratic_form \u211d M) (hQ : (associated Q).nondegenerate) :\n  \u2203 w : fin (finite_dimensional.finrank \u211d M) \u2192 \u211d,\n  (\u2200 i, w i = -1 \u2228 w i = 1) \u2227 equivalent Q (weighted_sum_squares \u211d w) :=\nlet \u27e8w, \u27e8hw\u2081\u27e9\u27e9 := Q.equivalent_weighted_sum_squares_units_of_nondegenerate' hQ in\n  \u27e8sign \u2218 coe \u2218 w,\n   \u03bb i, sign_apply_eq_of_ne_zero (w i) (w i).ne_zero,\n   \u27e8hw\u2081.trans (isometry_sign_weighted_sum_squares (coe \u2218 w))\u27e9\u27e9\n\n/-- **Sylvester's law of inertia**: A real quadratic form is equivalent to a weighted\nsum of squares with the weights being \u00b11 or 0. -/\ntheorem equivalent_one_zero_neg_one_weighted_sum_squared\n  {M : Type*} [add_comm_group M] [module \u211d M] [finite_dimensional \u211d M]\n  (Q : quadratic_form \u211d M) :\n  \u2203 w : fin (finite_dimensional.finrank \u211d M) \u2192 \u211d,\n  (\u2200 i, w i = -1 \u2228 w i = 0 \u2228 w i = 1) \u2227 equivalent Q (weighted_sum_squares \u211d w) :=\nlet \u27e8w, \u27e8hw\u2081\u27e9\u27e9 := Q.equivalent_weighted_sum_squares in\n  \u27e8sign \u2218 coe \u2218 w,\n   \u03bb i, sign_apply_eq (w i),\n   \u27e8hw\u2081.trans (isometry_sign_weighted_sum_squares w)\u27e9\u27e9\n\nend quadratic_form\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/quadratic_form/real.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.720630747131258}}
{"text": "/- Universe polymorphism\n\nType universes as you know them so far:\n\n  Sort 0    Sort 1    Sort 2    Sort 3 ...\n  Prop      Type      Type 1    Type 2 ...\n\nType is short for Type 0 and for Sort 1. \n\nProp is special. Types in Prop specify\npropositions. All values of such a type \nare considered equal and equally good as\nproofs. \n\n\nSometimes we want to be able to specify that \nany sort (whether Prop, Type, or some higher\ntype Universe) will do as the value of some \ntype parameter. The utility is that we extend\nthe notion of polymorphism across all universe \nlevels: 0, 1, 2, ... (all natural numbers).\n\nIn cases where we want definitions with this \nhigher level of generality, we can declare a\n\"universe variable\" and use it as an explicit\nuniverse level parameter to Sort or Type.\n-/\n\nuniverse u      -- universe variable\n#check Sort 0\n#check Sort 1\n#check Sort u   -- used here\n#check Type 0\n#check Type\n\n/-\nAs an example, here's a super-general definition\nof the identity function. For any type universe u\n(from above) and any (implicit) \"type\" \u03b1, funk will\ntake and then just return any value a of type \u03b1. We\ngive a few example expressions\n-/\ndef funk {\u03b1 : Sort u} (a : \u03b1) : \u03b1 := a\n#reduce funk 1            -- a is 1, so \u03b1 = \u2115, so u = 1\n#reduce funk (1 = 1)\n#reduce funk nat          --\n#reduce funk Prop         --\n#reduce funk Type         --\n#reduce funk (Type 0)     --\n#reduce funk (Sort 1)     --\n#reduce funk (Sort 2)     -- etc.\n\n\n\n/-\nContinuing with our example, it should now be clear that\nthe \"funk\" function is really just the identity function\non objects of any types in any type universe, from Prop\nthrough Type on up. \n-/\n\nexample : funk (1 = 1)  = (1 = 1) := rfl  --\nexample : funk nat      = nat     := rfl  --\nexample : funk (Sort 0) = Prop    := rfl  --\nexample : funk (Type 0) = Type    := rfl  --\nexample : funk (Sort 1) = Type    := rfl  --\nexample : funk (Sort 2) = Type 1  := rfl  -- etc.\nexample : funk (Sort 2) = Type 2  := rfl  -- nope\n\n/-\nTakeaway I: If you want maximally general parametric\npolymorphism, generalize over universe levels, as in\nthe preceding example. When you see an argument of type, \nSort u, you're looking at parametric polymorphism, with\ntype arguments from any universe level. \n-/\n\n\n\n/- Optional\n\nHigher-universe types, by the way, have values \nthat themselves contain types as \"field values.\" \nThe type of a type-containing object will inhabit\nthe universe one higher than that of the highest\nuniverse levels of any of its contained types.\n-/\n\n\n", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/03_Sets_and_Relations/99_universe_polymorphism.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7206307429617508}}
{"text": "instance {T} {S : set T} [h : decidable_pred S]\n  : decidable_pred (set.compl S) :=\n  \u03bb x, decidable.cases_on (h x)\n          (\u03bb h, is_true h)\n          (\u03bb h, is_false (\u03bb h', h' h))\n\nlemma and.distrib_left (P Q R : Prop) : P \u2227 (Q \u2228 R) \u2194 (P \u2227 Q) \u2228 (P \u2227 R) :=\niff.intro\n  (assume h : P \u2227 (Q \u2228 R),\n   have hp : P := and.left h,\n   show (P \u2227 Q) \u2228 (P \u2227 R),\n   from h.right.cases_on\n          (\u03bb hq, or.inl (and.intro hp hq))\n          (\u03bb hr, or.inr (and.intro hp hr)))\n  (assume h : (P \u2227 Q) \u2228 (P \u2227 R),\n   show P \u2227 (Q \u2228 R),\n   from or.cases_on h\n        (\u03bb hpq : P \u2227 Q, and.intro hpq.left (or.inl hpq.right))\n        (\u03bb hpr : P \u2227 R, and.intro hpr.left (or.inr hpr.right)))\n\nlemma and.distrib_right (P Q R : Prop) : (Q \u2228 R) \u2227 P \u2194 (Q \u2227 P) \u2228 (R \u2227 P) :=\nby { rw and_comm, rw and.distrib_left,\n     rw and_comm P Q, rw and_comm P R, }\n\nlemma or.distrib_left (P Q R : Prop) : P \u2228 (Q \u2227 R) \u2194 (P \u2228 Q) \u2227 (P \u2228 R) :=\niff.intro\n  (assume h : P \u2228 (Q \u2227 R),\n   show (P \u2228 Q) \u2227 (P \u2228 R),\n   from h.cases_on\n          (\u03bb hp, and.intro (or.inl hp) (or.inl hp))\n          (\u03bb hqr, and.intro (or.inr hqr.left) (or.inr hqr.right)))\n  (by {\n    intro h,\n    cases h,\n    cases h_left,\n    { exact or.inl h_left },\n    { cases h_right,\n      { exact or.inl h_right },\n      { apply or.inr, constructor; assumption } } })\n\nlemma or.distrib_right (P Q R : Prop) : (Q \u2227 R) \u2228 P \u2194 (Q \u2228 P) \u2227 (R \u2228 P) :=\nby { rw or_comm, rw or.distrib_left,\n     rw or_comm P Q, rw or_comm P R }\n\nlemma not_or_iff_and_not (p q : Prop) : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\nbegin\n  constructor; intro h,\n  { constructor; intro h'; apply h,\n    { apply or.inl, assumption }, { apply or.inr, assumption } },\n  { intro h', cases h, cases h',\n    { exact h_left h' }, { exact h_right h' } }\nend\n\nlemma and_not_and (p q : Prop) : p \u2227 \u00ac(p \u2227 q) \u2194 p \u2227 \u00acq :=\nbegin\n  constructor; intro h; cases h,\n  { constructor, assumption,\n    intro hp, apply h_right, \n    constructor; assumption },\n  { constructor, assumption,\n    intro hpq, apply h_right, cases hpq, assumption }\nend\n\nlemma classical.exists_of_not_forall {T} {P : T \u2192 Prop}\n  : (\u00ac \u2200 x : T, P x) \u2192 \u2203 x : T, \u00ac P x :=\nbegin\n  intro, apply classical.by_contradiction, intro h,\n  apply a, intro x, cases classical.em (P x),\n  { assumption },\n  { exfalso, apply h, existsi x, assumption }\nend\n\nlemma classical.implies_iff_or {P Q : Prop} : (P \u2192 Q) \u2194 (\u00ac P \u2228 Q) :=\nbegin\n  constructor, \n  { intro h, cases classical.em P,\n    exact or.inr (h h_1), exact or.inl h_1 },\n  { intro h, cases h, exact false.elim \u2218 h, exact \u03bb _, h }\nend\n\nlemma classical.dne (P) : P \u2194 \u00ac \u00ac P :=\niff.intro (\u03bb h h', h' h)\n  $ by { intro h, cases classical.em P, assumption, trivial }\n\nlemma subset_of_empty_iff_empty {T} {A : set T}  : A \u2286 \u2205 \u2194 A = \u2205 :=\nby { simp [(\u2286), set.subset], constructor,\n     { intro h, funext, apply propext,\n      constructor, { apply h }, { intro h, cases h } },\n     { intro h, rw h, intro, exact id } }\n\nlemma inter_subset_l {T} (A B : set T) : A \u2229 B \u2286 A := \u03bb _, and.left\nlemma inter_subset_r {T} (A B : set T) : A \u2229 B \u2286 B := \u03bb _, and.right\nlemma subset_union_l {T} (A B : set T) : A \u2286 A \u222a B := \u03bb _, or.inl\nlemma subset_union_r {T} (A B : set T) : B \u2286 A \u222a B := \u03bb _, or.inr\n\ndef fun.im {A B : Type _} (f : A \u2192 B) :=\n  { b : B | \u2203 a : A, f a = b }\n\n@[reducible]\ndef disjoint {T} (A B : set T) := A \u2229 B = \u2205\n\nlemma mk_disjoint {T} (A B : set T)\n  : (\u2200 x : T, \u00ac (A x \u2227 B x)) \u2192 disjoint A B :=\nby { intro h, dunfold disjoint, rw \u2190 subset_of_empty_iff_empty, exact h }\n\nlemma elim_disjoint {T} {A B : set T}\n  : disjoint A B \u2192 \u2200 x : T, A x \u2192 B x \u2192 false :=\nby { dunfold disjoint, intros h x ha hb,\n     refine (_ : (\u2205 : set T) x), rw \u2190 h, \n     constructor; assumption }\n\nlemma disjoint_compl {T} (A : set T) : disjoint A (-A) :=\nby { apply mk_disjoint, intros x h, exact h.right h.left  }\n\nlemma disjoint_implies_disjoint_subset {T} {A B A' : set T}\n  : A' \u2286 A \u2192 disjoint A B \u2192 disjoint A' B :=\nby { intros, apply mk_disjoint, intros x h,\n     apply elim_disjoint a_1 x (a h.left) h.right }\n\nlemma inter_comm {T} (A B : set T) : A \u2229 B = B \u2229 A :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u2229 B) a \u2194 A a \u2227 B a),\n  rw (_ : (B \u2229 A) a \u2194 B a \u2227 A a),\n  rw and_comm,\n  all_goals {refl}\nend\n\nlemma disjoint_symm {T} (A B : set T) : disjoint A B \u2194 disjoint B A :=\nby { dunfold disjoint, rw inter_comm }\n\nlemma union_comm {T} (A B : set T) : A \u222a B = B \u222a A :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u222a B) a \u2194 A a \u2228 B a),\n  rw (_ : (B \u222a A) a \u2194 B a \u2228 A a),\n  rw or_comm,\n  all_goals {refl}\nend\n\nlemma inter_assoc {T} (A B C : set T) : (A \u2229 B) \u2229 C = A \u2229 (B \u2229 C) :=\nbegin\n  funext, apply propext,\n  rw (_ : ((A \u2229 B) \u2229 C) a \u2194 (A a \u2227 B a) \u2227 C a),\n  rw (_ : (A \u2229 (B \u2229 C)) a \u2194 A a \u2227 (B a \u2227 C a)),\n  rw and_assoc,\n  all_goals {refl}\nend\n\nlemma union_assoc {T} (A B C : set T) : (A \u222a B) \u222a C = A \u222a (B \u222a C) :=\nbegin\n  funext, apply propext,\n  rw (_ : ((A \u222a B) \u222a C) a \u2194 (A a \u2228 B a) \u2228 C a),\n  rw (_ : (A \u222a (B \u222a C)) a \u2194 A a \u2228 (B a \u2228 C a)),\n  rw or_assoc,\n  all_goals {refl}\nend\n\nlemma compl_union {T} (A B : set T) : -(A \u222a B) = -A \u2229 -B :=\nbegin\n  funext, apply propext,\n  rw (_ : (-(A \u222a B)) a \u2194 \u00ac (A a \u2228 B a)),\n  rw (_ : (- A \u2229 - B) a \u2194 \u00ac (A a) \u2227 \u00ac (B a)),\n  rw not_or_iff_and_not,\n  all_goals {refl}\nend\n\nlemma compl_inter {T} (A B : set T) \n  [decidable_pred A] [decidable_pred B]\n  : -(A \u2229 B) = -A \u222a -B :=\nbegin\n  funext, apply propext,\n  rw (_ : (-(A \u2229 B)) a \u2194 \u00ac (A a \u2227 B a)),\n  rw (_ : (- A \u222a - B) a \u2194 \u00ac (A a) \u2228 \u00ac (B a)),\n  rw decidable.not_and_iff_or_not,\n  all_goals {refl}\nend\n\nlemma union_empty {T} (A : set T) : A \u222a \u2205 = A :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u222a \u2205) a \u2194 A a \u2228 false),\n  rw or_false,\n  refl\nend\n\nlemma inter_univ {T} (A : set T) : A \u2229 set.univ = A :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u2229 set.univ) a \u2194 A a \u2227 true),\n  rw and_true,\n  refl\nend\n\nlemma inter_empty {T} (A : set T) : A \u2229 \u2205 = \u2205 :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u2229 \u2205) a \u2194 A a \u2227 false),\n  rw and_false, refl, refl,\nend\n\nlemma union_self {T} (A : set T) : A \u222a A = A :=\nbegin\n  funext, apply propext, rw (_ : (A \u222a A) a \u2194 A a \u2228 A a), \n  rw or_self, refl\nend\n\nlemma inter_self {T} (A : set T) : A \u2229 A = A :=\nbegin\n  funext, apply propext, rw (_ : (A \u2229 A) a \u2194 A a \u2227 A a), \n  rw and_self, refl\nend\n\nlemma elem_singleton {T} (x : T) : {x} = { y : T | y = x } :=\nby { rw (_ : {x} = {y : T | y = x} \u222a \u2205), apply union_empty, refl }\n\nlemma compl_compl {T} (A : set T)\n  [decidable_pred A]\n  : - (- A) = A :=\nbegin\n  funext, apply propext,\n  rw (_ : (- (- A)) a = \u00ac (\u00ac (A a))),\n  rw decidable.not_not_iff,\n  refl\nend\n\nlemma inter.distrib_left {T} (A B C : set T) : A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u2229 (B \u222a C)) a \u2194 A a \u2227 (B a \u2228 C a)),\n  rw (_ : ((A \u2229 B) \u222a (A \u2229 C)) a \u2194 (A a \u2227 B a) \u2228 (A a \u2227 C a)),\n  { rw and.distrib_left },\n  all_goals {refl}\nend\n\nlemma inter.distrib_right {T} (A B C : set T) : (B \u222a C) \u2229 A = (B \u2229 A) \u222a (C \u2229 A) :=\nby { rw inter_comm, rw inter.distrib_left,\n     rw inter_comm A B, rw inter_comm A C }\n\nlemma union.distrib_left {T} (A B C : set T) : A \u222a (B \u2229 C) = (A \u222a B) \u2229 (A \u222a C) :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u222a (B \u2229 C)) a \u2194 A a \u2228 (B a \u2227 C a)),\n  rw (_ : ((A \u222a B) \u2229 (A \u222a C)) a \u2194 (A a \u2228 B a) \u2227 (A a \u2228 C a)),\n  { rw or.distrib_left },\n  all_goals {refl}\nend\n\nlemma union.distrib_right {T} (A B C : set T) : (B \u2229 C) \u222a A = (B \u222a A) \u2229 (C \u222a A) :=\nby { rw union_comm, rw union.distrib_left,\n     rw union_comm A B, rw union_comm A C }\n\nlemma set.FOIL1 {T} (A B C D : set T)\n  : (A \u222a B) \u2229 (C \u222a D) = (A \u2229 C) \u222a (B \u2229 C) \u222a (A \u2229 D) \u222a (B \u2229 D) :=\nbegin\n  rw inter.distrib_left,\n  rw inter.distrib_right,\n  rw inter.distrib_right,\n  repeat { rw union_assoc },\nend\n\nlemma set.FOIL2 {T} (A B C D : set T)\n  : (A \u2229 B) \u222a (C \u2229 D) = (A \u222a C) \u2229 (B \u222a C) \u2229 (A \u222a D) \u2229 (B \u222a D) :=\nbegin\n  rw union.distrib_left,\n  rw union.distrib_right,\n  rw union.distrib_right,\n  repeat { rw inter_assoc },\nend\n\ndef set_minus {T} (A B : set T) : set T := { x \u2208 A | x \u2209 B }\ninfix `\u2216`:80 := set_minus\n\nlemma minus_is_subset {T} (A B : set T) : A \u2216 B \u2286 A := \u03bb _ h, h.left\n\nlemma minus_eq_inter_compl {T} (A B : set T) : A \u2216 B = A \u2229 (-B) :=\nbegin\n  funext, apply propext,\n  rw (_ : (A \u2216 B) a \u2194 A a \u2227 \u00ac (B a)),\n  rw (_ : (A \u2229 -B) a \u2194 A a \u2227 \u00ac (B a)),\n  refl, refl,\nend\n\nlemma minus_disj {T} (A B : set T) : disjoint (A \u2216 B) B :=\nbegin\n  rw [minus_eq_inter_compl],\n  apply disjoint_implies_disjoint_subset,\n  apply inter_subset_r, rw disjoint_symm, apply disjoint_compl\nend\n\nlemma union_minus {T} (A B C : set T) : (A \u222a B) \u2216 C = (A \u2216 C) \u222a (B \u2216 C) :=\nbegin\n  funext, apply propext,\n  rw (_ : (((A \u222a B)\u2216C) a \u2194 (A a \u2228 B a) \u2227 \u00ac (C a))),\n  rw (_ : ((A\u2216C) \u222a (B\u2216C)) a \u2194 (A a \u2227 \u00ac(C a)) \u2228 (B a \u2227 \u00ac(C a))),\n  apply and.distrib_right,\n  all_goals {refl}\nend\n\nlemma minus_subset_union_subset {T} {A A' : set T}\n  [decidable_pred A]\n  : A \u2286 A' \u2192 (A' \u2216 A) \u222a A = A' :=\nbegin\n  intros hsub, funext, apply propext, constructor,\n  { intro h, cases h,\n    { exact h.left },\n    { apply hsub, assumption } },\n  { intro h, by_cases h' : A a,\n    { exact or.inr h' },\n    { exact or.inl \u27e8h, h'\u27e9 } }\nend\n\nlemma minus_inter {T} (A B C : set T)\n  [decidable_pred B] [decidable_pred C]\n  : A \u2216 (B \u2229 C) = (A \u2216 B) \u222a (A \u2216 C) :=\nbegin\n  funext, apply propext,\n  rw (_ : (A\u2216(B \u2229 C)) a \u2194 A a \u2227 \u00ac (B a \u2227 C a)),\n  rw (_ : ((A\u2216B) \u222a (A\u2216C)) a \u2194 (A a \u2227 \u00ac (B a)) \u2228 (A a \u2227 \u00ac (C a))),\n  { rw decidable.not_and_iff_or_not,\n    apply and.distrib_left },\n  all_goals {refl}\nend\n\nlemma minus_union {T} (A B C : set T)\n  : A \u2216 (B \u222a C) = (A \u2216 B) \u2229 (A \u2216 C) :=\nbegin\n  funext, apply propext,\n  rw (_ : (A\u2216(B \u222a C)) a \u2194 A a \u2227 \u00ac (B a \u2228 C a)),\n  rw (_ : ((A\u2216B) \u2229 (A\u2216C)) a \u2194 (A a \u2227 \u00ac (B a)) \u2227 (A a \u2227 \u00ac (C a))),\n  rw [not_or_iff_and_not\n     , and_assoc\n     , \u2190 and_assoc (\u00ac (B a)) (A a)\n     , and_comm (\u00ac (B a)) (A a)\n     , and_assoc\n     , \u2190 and_assoc (A a) (A a)\n     , and_self\n     ],\n  all_goals {refl}\nend\n\nlemma minus_eq_minus_inter {T} (A B : set T) : A \u2216 B = A \u2216 (A \u2229 B) :=\nbegin\n  funext, apply propext,\n  rw (_ : (A\u2216B) a \u2194 A a \u2227 \u00ac B a),\n  rw (_ : (A\u2216(A \u2229 B)) a \u2194 A a \u2227 \u00ac (A a \u2227 B a)),\n  { constructor;\n    intro h; cases h;\n    apply and.intro h_left; intro h'; apply h_right,\n    { exact h'.right },\n    { exact and.intro h_left h' } },\n  all_goals {refl}\nend\n\nlemma minus_self {T} (A : set T) : A \u2216 A = \u2205 :=\nbegin\n  funext, apply propext, constructor;\n  intro h; exfalso,\n  { have : A a \u2227 \u00ac (A a) := h,\n    exact this.right this.left },\n  { exact h }\nend\n\nlemma minus_empty {T} (A : set T) : A\u2216\u2205 = A :=\nbegin\n  funext, apply propext, \n  rw (_ : (A \u2216 \u2205) a \u2194 A a \u2227 \u00ac false),\n  { rw [not_false_iff, and_true] }, refl\nend\n\nlemma minus_minus_eq_minus_union {T} (A B C : set T) : (A \u2216 B) \u2216 C = A \u2216 (B \u222a C) :=\nbegin\n  funext, apply propext,\n  rw (_ : (A\u2216B\u2216C) a \u2194 (A a \u2227 \u00ac (B a)) \u2227 \u00ac (C a)),\n  rw (_ : (A \u2216 (B \u222a C)) a \u2194 A a \u2227 \u00ac (B a \u2228 C a)),\n  { rw and_assoc, rw not_or_iff_and_not },\n  all_goals {refl}\nend\n\nlemma minus_of_minus {T} (A B C : set T)\n  [decidable_pred B] [decidable_pred C]\n  : A \u2216 (B \u2216 C) = (A \u2216 B) \u222a (A \u2229 C) :=\nbegin\n  rw minus_eq_inter_compl A B,\n  rw \u2190 inter.distrib_left,\n  rw minus_eq_inter_compl A,\n  rw minus_eq_inter_compl B,\n  rw compl_inter B (-C),\n  rw compl_compl\nend\n\ndef symm_diff {T} (A B : set T) : set T := (A \u222a B) \u2216 (A \u2229 B)\ninfix `\u0394`:60 := symm_diff\n\nlemma symm_diff_def2 {T} (A B : set T) : A \u0394 B = (A \u2216 B) \u222a (B \u2216 A) := by {\n  dsimp [(\u0394)],\n  rw union_minus,\n  apply congr,\n  { apply congr_arg, rw \u2190 minus_eq_minus_inter },\n  { rw inter_comm, rw \u2190 minus_eq_minus_inter }\n}\n\nlemma symm_diff_comm {T} (A B : set T) : A \u0394 B = B \u0394 A :=\n  by dsimp [(\u0394)]; rw [inter_comm, union_comm]\n\nlemma minus_inter_inter_eq_empty {T} (A B : set T) : A\u2216B \u2229 (A \u2229 B) = \u2205 :=\nbegin\n  rw minus_eq_inter_compl,\n  rw inter_assoc,\n  rw \u2190 inter_assoc (- B),\n  rw inter_comm (-B),\n  rw inter_assoc A (-B),\n  rw inter_comm (-B),\n  rw \u2190 minus_eq_inter_compl,\n  rw minus_self,\n  rw inter_empty, rw inter_empty\nend\n\nlemma minus_of_symm_diff {T} (A B C : set T)\n  [decidable_pred A] [decidable_pred B] [decidable_pred C]\n  : C \u2216 (A \u0394 B) = ((C \u2216 A) \u2229 (C \u2216 B)) \u222a (C \u2229 A \u2229 B) :=\nbegin\n  rw symm_diff_def2, rw \u2190 minus_union,\n  rw minus_union,\n  rw [minus_of_minus, minus_of_minus],\n  rw set.FOIL1,\n  rw (_ : C \u2229 B \u2229 C\u2216B = \u2205),\n  rw (_ : C\u2216A \u2229 (C \u2229 A) = \u2205),\n  rw union_empty, rw union_empty,\n  rw minus_union,\n  have : C \u2229 B \u2229 (C \u2229 A) = C \u2229 A \u2229 B,\n  { rw \u2190 inter_assoc,\n    rw inter_comm C B,\n    rw inter_assoc B C C,\n    rw inter_self,\n    rw inter_assoc,\n    rw inter_comm },\n  rw this,\n  { apply minus_inter_inter_eq_empty },\n  { rw inter_comm, apply minus_inter_inter_eq_empty }\nend\n\nlemma symm_diff_assoc {T} (A B C : set T) \n  [decidable_pred A] [decidable_pred B] [decidable_pred C]\n  : (A \u0394 B) \u0394 C = A \u0394 (B \u0394 C) :=\nbegin\n  rw symm_diff_def2,\n  rw minus_of_symm_diff,\n  rw symm_diff_def2,\n  rw symm_diff_def2,\n  rw minus_of_symm_diff,\n  rw symm_diff_def2,\n\n  rw union_minus,\n  rw minus_minus_eq_minus_union,\n  rw minus_union,\n  rw minus_minus_eq_minus_union,\n  rw minus_union,\n\n  rw union_minus,\n  rw minus_minus_eq_minus_union,\n  rw minus_union,\n  rw minus_minus_eq_minus_union,\n  rw minus_union,\n\n  suffices : B\u2216A \u2229 B\u2216C \u222a (C\u2216A \u2229 C\u2216B \u222a C \u2229 A \u2229 B)\n           = A \u2229 B \u2229 C \u222a (B\u2216C \u2229 B\u2216A \u222a C\u2216B \u2229 C\u2216A),\n  { rw union_assoc, rw this, rw \u2190 union_assoc },\n\n  rw \u2190 union_assoc,\n  rw \u2190 union_assoc,\n  rw union_comm,\n  rw \u2190 union_assoc,\n  rw (_ : C \u2229 A \u2229 B = A \u2229 B \u2229 C),\n  rw (_ : B\u2216A \u2229 B\u2216C = B\u2216C \u2229 B\u2216A),\n  rw (_ : C\u2216A \u2229 C\u2216B = C\u2216B \u2229 C\u2216A),\n  rw inter_comm, rw inter_comm,\n  rw inter_assoc, rw inter_comm\nend\n\nlemma empty_symm_diff {T} (A : set T) : \u2205 \u0394 A = A :=\nby { intros, simp [(\u0394)],\n     rw [union_comm, inter_comm],\n     rw [union_empty, inter_empty, minus_empty] } \n\nlemma symm_diff_self {T} (A : set T) : A \u0394 A = \u2205 :=\nby { dsimp [(\u0394)], rw union_self, rw inter_self, apply minus_self }\n\nlemma left_distrib_inter_symm_diff {T} (A B C : set T)\n  : A \u2229 (B \u0394 C) = (A \u2229 B) \u0394 (A \u2229 C) :=\nbegin\n  rw symm_diff_def2, rw symm_diff_def2,\n  rw inter.distrib_left,\n  have : \u2200 A' B' C' : set T, A' \u2229 B'\u2216C' = (A' \u2229 B')\u2216(A' \u2229 C'),\n  { intros, rw minus_eq_inter_compl,\n    rw minus_eq_inter_compl,\n    suffices : A' \u2229 -C' = A' \u2229 -(A' \u2229 C'),\n    { rw \u2190 inter_assoc,\n      rw inter_comm,\n      rw \u2190 inter_assoc,\n      rw inter_comm (-C'),\n      rw this,\n      rw inter_assoc,\n      rw inter_assoc,\n      rw inter_comm B' },\n    { funext, apply propext,\n      rw (_ : (A' \u2229 -C') a \u2194 A' a \u2227 \u00ac (C' a)),\n      rw (_ : (A' \u2229 -(A' \u2229 C')) a \u2194 A' a \u2227 \u00ac (A' a \u2227 C' a)),\n      { rw and_not_and }, \n      all_goals {refl} } },\n  rw \u2190 this,\n  rw \u2190 this\nend\n\nlemma union_decomp_symm {T} (A B : set T)\n  [decidable_pred A] [decidable_pred B]\n : A \u222a B = (A \u0394 B) \u222a (A \u2229 B) :=\nbegin\n  dsimp [(\u0394)], symmetry,\n  apply @minus_subset_union_subset _ _ _ _,\n  exact \u03bb _, or.inl \u2218 and.left,\n  intro x, \n  by_cases h : A x; by_cases h' : B x,\n  { apply decidable.is_true,\n    constructor; assumption },\n  { apply decidable.is_false,\n    intro h'', cases h'',\n    apply h', assumption },\n  all_goals \n  { apply decidable.is_false,\n    intro h'', cases h'',\n    apply h, assumption }\nend\n\nlemma union_decomp_l {T} (A B : set T)\n  [decidable_pred A]\n : A \u222a B = A \u222a (B \u2216 A) :=\nbegin\n  funext x, apply propext,\n  constructor; intro h, \n  { by_cases h' : A x,\n    { exact or.inl h' },\n    { cases h, { exfalso, apply h', assumption },\n      apply or.inr, constructor; assumption } },\n  { cases h, exact or.inl h, exact or.inr (minus_is_subset _ _ h) }\nend\n\nlemma union_decomp_r {T} (A B : set T)\n  [decidable_pred B]\n : A \u222a B = (A \u2216 B) \u222a B :=\nbegin\n  transitivity B \u222a A, apply union_comm,\n  transitivity B \u222a (A \u2216 B), apply union_decomp_l,\n  apply union_comm\nend\n\nlemma symm_diff_disj_inter {T} (A B : set T)\n  : disjoint (A \u0394 B) (A \u2229 B) := minus_disj (A \u222a B) (A \u2229 B)\n\nlemma decomp {T} (A B : set T) [decidable_pred B]\n  : A = (A \u2216 B) \u222a (A \u2229 B) :=\nbegin\n  funext, apply propext,\n  constructor,\n  { intro h, by_cases h' : B x,\n    { apply or.inr, constructor; assumption },\n    { apply or.inl, constructor; assumption } },\n  { intro h, cases h; cases h; assumption }\nend\n\ndef subset_of_subtype_to_subset {A : Type _} {P : A \u2192 Prop}\n  : set (subtype P) \u2192 set A :=\n  \u03bb S, { a : A | \u2203 h : P a, S \u27e8a, h\u27e9 } ", "meta": {"author": "Shamrock-Frost", "repo": "boolean_rings", "sha": "5da11beeaa37ec186c1deff946f2dbf7594fceb4", "save_path": "github-repos/lean/Shamrock-Frost-boolean_rings", "path": "github-repos/lean/Shamrock-Frost-boolean_rings/boolean_rings-5da11beeaa37ec186c1deff946f2dbf7594fceb4/logic_util.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7206127883334226}}
{"text": "import Lean\n\nabbrev \u2115 := Nat\nabbrev BaseType := {n: Nat // n > 1}\nabbrev PositionalNotation {b: BaseType} := {d: List (Fin b) // d \u2260 []}\ndef PositionalNotation.toNat {b: BaseType} (pn: PositionalNotation) :=\n  List.foldr (\u03bb (a:Fin b) (n:Nat) => a + n * b) 0 pn.val\n\ntheorem nand_iff: \u2200 p q, \u00ac(p \u2227 q) \u2194 (p \u2192 \u00acq) := by {\n  intro p q;\n  apply Iff.intro;\n  intro h1 wp wq;\n  exact absurd \u27e8wp, wq\u27e9 h1;\n  intro h1 wpq;\n  exact h1 wpq.left wpq.right;\n}\n\ntheorem hodai1: \u2200x y:Nat, x \u2265 2 \u2192 y \u2265 2 \u2192 y \u2264 x \u2192 x - y + 1 < x := by {\n  intro x;\n  induction x;\n  simp;\n  case succ x x_ih => {\n    intro y;\n    induction y;\n    simp;\n    case succ y y_ih => {\n      intro h1 h2 h3;\n      specialize y_ih h1;\n      simp [Nat.succ_sub_succ];\n      by_cases h4: x = 1;\n      all_goals by_cases h5: y = 1;\n      simp_all;\n      simp [h4] at h3;\n      have h6 := Nat.le_antisymm h2 h3;\n      have h7 := Eq.symm (Nat.succ.inj h6);\n      contradiction;\n      simp [h5];\n      have h6 := Nat.lt_of_le_of_ne (Nat.le_of_succ_le_succ h1) (Ne.symm h4);\n      apply Nat.add_lt_add_right;\n      apply Nat.sub_lt;\n      apply @Nat.lt_trans 0 1;\n      simp;\n      assumption;\n      simp;\n      have h6 := Nat.lt_of_le_of_ne (Nat.le_of_succ_le_succ h1) (Ne.symm h4);\n      have h7 := Nat.succ_le_of_lt h6;\n      have h8 := Nat.lt_of_le_of_ne (Nat.le_of_succ_le_succ h2) (Ne.symm h5);\n      have h9 := Nat.succ_le_of_lt h8;\n      specialize x_ih y h7 h9 (Nat.le_of_succ_le_succ h3);\n      apply @Nat.lt_trans (x - y + 1) x;\n      assumption;\n      exact Nat.lt.base x;\n    }\n  }\n}\n\ntheorem hodai2: \u2200n m: Nat,  n > 0 \u2192 m \u2265 2 \u2192 n / m < n := by {\n  intros n m h0 h1;\n  induction n, m using Nat.div.inductionOn;\n  case ind x y h2 h3 => {\n    have po := Nat.eq_or_lt_of_le h2.right;\n    have h4 := Nat.div_eq x y;\n    apply Or.elim po;\n    intro pu;\n    rw [\u2190pu];\n    have pi := Nat.div_eq y y;\n    have pe: 0 < y := by {\n      apply @Nat.lt_of_lt_of_le 0 2;\n      simp;\n      assumption;\n    };\n    have q := Nat.le_refl y;\n    simp [pe, q, pi, Nat.sub_self];\n    have w := Nat.div_eq 0 y;\n    simp [pe];\n    simp [(Nat.not_le_of_gt pe)];\n    rw [w];\n    simp [h2];\n    have := Nat.not_eq_zero_of_lt pe;\n    simp [this];\n    exact Nat.lt_of_succ_le h1;\n    intro hh;\n    have hod := Nat.zero_lt_sub_of_lt hh;\n    specialize h3 hod h1;\n    simp [h4, h2];\n    have h5 := Nat.add_lt_add_right h3 1;\n    apply @Nat.lt_trans ((x - y) / y + 1) (x - y + 1);\n    assumption;\n    apply hodai1;\n    exact Nat.le_trans h1 h2.right;\n    assumption;\n    exact h2.right;\n  }\n  case base x y h => {\n    have h4 := Nat.div_eq x y;\n    simp [h] at h4;\n    rw [h4];\n    assumption;\n  }\n}\n\ntheorem hodai3: \u2200n: Nat, 0 / n = 0 := by {\n  intro n;\n  have h2 := Nat.div_eq 0 n;\n  cases n;\n  rw [h2];\n  simp;\n  case succ n => {\n    rw [h2];\n    have h3 := Nat.succ_pos n |> Nat.not_le_of_gt;\n    simp [h3];\n  }\n}\n\ntheorem hodai4: \u2200n: Nat, n > 0 \u2192 n / n = 1 := by {\n  intro n h1;\n  have h2 := Nat.div_eq n n;\n  simp [h1, Nat.le_refl] at h2;\n  simp [h2, Nat.sub_self, hodai3];\n}\n\ntheorem hodai5: \u2200n m k: Nat, m \u2264 n \u2192 n + k - m = n - m + k := by {\n  intro n m k;\n  revert n m;\n  induction k;\n  simp;\n  case succ k ih1 => {\n    simp [Nat.add_succ];\n    intro n m;\n    revert n;\n    induction m;\n    simp;\n    case succ m ih2 => {\n      intro n;\n      induction n;\n      simp;\n      --intro h1;\n      --have h5 := Nat.eq_zero_of_le_zero h1;\n      --contradiction;\n      case succ n ih3 => {\n        intro h1;\n        simp [Nat.succ_sub_succ];\n        have h2 := Nat.le_of_succ_le_succ h1;\n        have h3 := ih1 (Nat.succ n) m (Nat.le_step h2);\n        have h4 := ih2 n h2;\n        simp [\u2190h4, Nat.succ_add];\n        \n      };\n    };\n  };\n}\n\ntheorem hodai6: \u2200n b, b > 1 \u2192 n % b < b := by {\n  intro n b h1;\n  apply Nat.mod_lt;\n  apply Nat.lt_of_le_and_ne;\n  exact Nat.zero_le b;\n  apply Ne.symm;\n  intro h3;\n  rw [h3] at h1;\n  contradiction;\n}\n\ntheorem hodai7: \u2200n m: Nat, n \u2265 m \u2192 \u00acm > n := by {\n  intro n m h1;\n  apply Or.elim $ Nat.eq_or_lt_of_le h1;\n  all_goals intro h2;\n  rw [h2];\n  exact Nat.lt_irrefl n;\n  intro h3;\n  exact absurd (Nat.lt_trans h2 h3) (Nat.lt_irrefl m);\n}\n\ntheorem hodai8: \u2200n m: Nat, n % m + n / m * m = n := by {\n  intro n m;\n  induction n, m using Nat.div.inductionOn;\n  case ind x y ih1 ih2 => {\n    have h1 := Nat.div_eq x y;\n    simp [h1, ih1, Nat.mod_eq_sub_mod, Nat.add_mul, \u2190Nat.add_assoc, ih2, \u2190hodai5, Nat.add_sub_self_right];\n  };\n  case base x y ih1 => {\n    have h1 := Nat.div_eq x y;\n    simp [h1, ih1];\n    have h2 := Nat.mod_eq x y;\n    simp [h2, ih1];\n  };\n}\n\ntheorem hodai9: \u2200n m k: Nat, (n + m) % k = ((n % k) + (m % k)) % k := by {\n  intro n m k;\n  revert m;\n  induction n,k using Nat.mod.inductionOn;\n  case ind x y prems ih => {\n    intro m;\n    have h1 := Nat.mod_eq x y;\n    simp [prems] at h1;\n    simp [h1, \u2190ih];\n    have h2: y \u2264 x + m := Nat.add_le_add prems.right (Nat.zero_le m);\n    have h3 := Nat.mod_eq_sub_mod h2;\n    simp [h3];\n    have h4 := hodai5 x y m prems.right;\n    simp [h4];\n  };\n  case base x y prems => {\n    intro m;\n    have h1 := Nat.mod_eq x y;\n    simp [prems] at h1;\n    simp [h1];\n    induction m,y using Nat.mod.inductionOn;\n    case ind x' y prems' ih => {\n      have h2 := Nat.mod_eq x' y;\n      simp [prems'] at h2;\n      simp [h2];\n      specialize ih prems h1;\n      simp [\u2190ih, Nat.add_comm x (x' - y)];\n      have h3 := hodai5 x' y x prems'.right;\n      simp [\u2190h3];\n      have h4 := Nat.add_le_add prems'.right (Nat.zero_le x);\n      simp [Nat.add_comm] at h4;\n      have h5 := Nat.mod_eq_sub_mod h4;\n      simp [h5, Nat.add_comm];\n    };\n    case base x' y prems' => {\n      have h1 := Nat.mod_eq x' y;\n      simp [prems'] at h1;\n      simp [h1];\n    };\n  };\n}\n\ntheorem hodai10: \u2200n, n / 1 = n := by {\n  intro n;\n  induction n;\n  simp;\n  case succ n ih => {\n    have h1 := Nat.div_eq (Nat.succ n) 1;\n    have h2: 1 \u2264 Nat.succ n := Nat.succ_le_succ $ Nat.zero_le n;\n    simp [h2, Nat.sub_succ, Nat.pred, ih] at h1;\n    assumption;\n  };\n}\n\ntheorem hodai10_1: \u2200n m k: Nat, m \u2264 k \u2192 n - (k - m) = n + m - k := by {\n  intro n m;\n  revert n;\n  induction m;\n  simp;\n  case succ m ih => {\n    intro n k;\n    revert n;\n    induction k;\n    intros n h;\n    have h1 := Nat.not_succ_le_zero m h;\n    contradiction;\n    case succ k ih2 => {\n      intro n h;\n      simp [Nat.succ_sub_succ, Nat.add_succ];\n      have h2 := Nat.le_of_succ_le_succ h;\n      exact ih n k h2;\n    };\n  };\n}\n\ntheorem hodai10_2: \u2200 n m, n = n - m \u2192 n = 0 \u2228 m = 0 := by {\n  intro n m;\n  revert n;\n  induction m;\n  simp;\n  case succ m ih => {\n    intro n h;\n    induction n;\n    simp;\n    case succ n ih2 => {\n      rw [Nat.succ_sub_succ] at h;\n      have h1 := congrArg Nat.pred h;\n      simp at h1;\n      simp [Nat.sub_succ] at ih2;\n      specialize ih2 h1;\n      simp [ih2] at h;\n    };\n  };\n}\n\ntheorem hodai10_3: \u2200n m: Nat, n < n - m \u2192 False := by {\n  intros n m;\n  apply hodai7 n (n - m);\n  exact Nat.sub_le n m;\n}\n\ntheorem hodai10_5: \u2200n m: Nat, n % m \u2260 0 \u2192 m - n % m = ((n / m * m + m) - n) % m := by {\n  intro n m;\n  induction n, m using Nat.mod.inductionOn;\n  case ind x y prems ih => {\n    have h1 := Nat.mod_eq x y;\n    simp [prems] at h1;\n    have h2 := Nat.div_eq x y;\n    simp [prems] at h2;\n    intro h;\n    simp [h1, h2];\n    simp [h1] at h;\n    simp [ih h];\n    rw [\n      Nat.add_mul,\n      Nat.one_mul,\n      Nat.add_assoc _ y _,\n      \u2190Nat.add_assoc];\n      generalize h3: (x - y) / y * y + y = z;\n      rw [hodai10_1];\n      exact prems.right;\n  };\n  case base x y prems => {\n    have h1 := Nat.mod_eq x y;\n    simp [prems] at h1;\n    have h2 := Nat.div_eq x y;\n    simp [prems] at h2;\n    simp [h1, h2];\n    rw [nand_iff] at prems;\n    apply Or.elim $ Nat.eq_or_lt_of_le $ Nat.zero_le y;\n    intro a;\n    simp [\u2190a];\n    intro a;\n    specialize prems a;\n    have h3 := Nat.mod_eq (y - x) y;\n    have h4 := Nat.gt_of_not_le prems;\n    by_cases h5: y \u2264 y - x;\n    apply Or.elim $ Nat.eq_or_lt_of_le h5;\n    intro b;\n    simp [\u2190b];\n    intro h;\n    have h6: x = 0 := by {\n      apply Or.elim $ hodai10_2 y x b;\n      intro b;\n      rw [b] at a;\n      exact absurd a (Nat.lt_irrefl 0);\n      intro;\n      contradiction;\n    };\n    contradiction;\n    intro b c;\n    have := hodai10_3 y x b;\n    contradiction;\n    intro h6;\n    simp [a, h5] at h3;\n    rw [h3];\n  };\n}\n\ntheorem hodai10_6: \u2200n m: Nat, n % m = 0 \u2192 m - n % m = m := by {\n  intro n m h1;\n  simp [*];\n}\n\n/-\ntheorem hodai11: \u2200n m k: Nat, n > m \u2192 (n - m) % k = ((n % k) + (k - (m % k))) % k := by {\n  intro n m k h1;\n}\n\ntheorem hodai12: \u2200n m k: Nat, (n * m) % k = ((n % k) * (m % k)) % k := by {\n  intro n m k;\n}\n-/\n\ntheorem hodai12_1: \u2200n m, m > 0 \u2192 n \u2265 m \u2192 (n - m) % (m - 1) = (n - 1) % (m - 1) := by {\n  intro n m h' h;\n  have h1 := Nat.mod_eq (n - 1) (m - 1);\n  by_cases h2: 0 < m - 1 \u2227 m - 1 \u2264 n - 1;\n  simp [h2] at h1;\n  simp [Nat.sub_sub] at h1;\n  have h3: 1 + (m - 1) = m := by {\n    simp [Nat.sub_succ];\n    induction m;\n    simp at h2;\n    case succ m ih => {\n      simp [Nat.add_comm];\n    };\n  };\n  simp [h3] at h1;\n  rw [h1];\n  --\n  simp [h2] at h1;\n  rw [nand_iff] at h2;\n  by_cases h3: 0 < m - 1;\n  specialize h2 h3;\n  have h6 := Nat.gt_of_not_le h2;\n  have h7 := Nat.add_lt_add_right h6 1;\n  have h10 := Nat.sub_add_cancel h';\n  rw [h10] at h7;\n  have h11: n > 0 := Nat.lt_of_lt_of_le h' h;\n  have h12 := Nat.sub_add_cancel h11;\n  rw [h12] at h7;\n  apply Or.elim $ Nat.eq_or_lt_of_le h;\n  intro a;\n  simp [a];\n  --\n  intro a;\n  have h13 := Nat.lt_trans a h7;\n  exact absurd h13 $ Nat.lt_irrefl m;\n  --\n  have h4 := Nat.ge_of_not_lt h3 |> Nat.eq_zero_of_le_zero;\n  simp [h4, Nat.mod_zero];\n  have h5: m = 1 := by {\n    have h6 := Nat.succ_le_of_lt h';\n    have h7 := Nat.eq_add_of_sub_eq h6 h4;\n    simp at h7;\n    assumption;\n  };\n  simp [h5];\n}\n\ntheorem hodai13: \u2200n m k, m > 1 \u2192 (n + k) % (m - 1) = (n / m + n % m + k) % (m - 1) := by {\n  intro n m;\n  induction n,m using Nat.mod.inductionOn;\n  case ind x y prems ih => {\n    intro k h;\n    specialize ih k h;\n    have h1 := Nat.div_eq x y;\n    have h2 := Nat.mod_eq x y;\n    simp [prems] at h1;\n    simp [prems] at h2;\n    simp [h1, h2];\n    simp [Nat.add_assoc, Nat.add_comm 1];\n    simp [\u2190Nat.add_assoc];\n    rw [hodai9 _ 1, \u2190ih];\n    by_cases h3: y > 2;\n    have h4: y - 1 > 1 := by {\n      have h5 := Nat.zero_lt_sub_of_lt h3;\n      have h6 := Nat.succ_lt_succ h5;\n      have h7 := hodai5 y 2 1 (Nat.le_of_lt h3);\n      simp [Nat.add_succ] at h7;\n      rw [\u2190h7] at h6;\n      simp [Nat.sub_succ];\n      assumption;\n    };\n    have h5 := Nat.mod_eq_of_lt h4;\n    rw [\u2190hodai5 x y k prems.right];\n    have h6 := hodai12_1 (x + k) y prems.left (Nat.add_le_add prems.right (Nat.zero_le k));\n    simp [h6];\n    rw [\u2190hodai9];\n    have h7 := Nat.lt_of_lt_of_le prems.left prems.right |> Nat.succ_le_of_lt;\n    have h8 := Nat.add_le_add h7 (Nat.zero_le k);\n    simp at h8;\n    have h9 := hodai5 (x + k) 1 1 h8;\n    rw [\u2190h9, Nat.add_sub_self_right];\n    --\n    have h4 := Nat.ge_of_not_lt h3;\n    have h5 := Nat.succ_le_of_lt h;\n    have h6 := Nat.le_antisymm h4 h5;\n    simp [h6, Nat.sub_succ, Nat.mod_one];\n  };\n  case base x y prems => {\n    intro k h;\n    have h1 := Nat.div_eq x y;\n    simp [prems] at h1;\n    simp [h1];\n    have h2 := Nat.mod_eq x y;\n    simp [prems] at h2;\n    simp [h2];\n  };\n}\n\ntheorem ornot_then_nand: \u2200p q, \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := by {\n  intro p q wor wpq;\n  apply Or.elim wor;\n  all_goals {\n    intros;\n    have \u27e8wp, wq\u27e9 := wpq;\n    contradiction;\n  }\n}\n\ndef toPositionalNotation {base: BaseType} (n: \u2115) : @PositionalNotation base :=\n  if h': n < base then \n    by {\n      let ret := [Fin.mk n h'];\n      have h: ret \u2260 [] := by simp;\n      exact \u27e8ret, h\u27e9;\n    }\n  else \n    by {\n      have h1 := hodai6 n base base.property;\n      have h2: n / base < n := by {\n        apply hodai2;\n        apply Or.elim $ Nat.lt_or_ge n base;\n        intro;\n        contradiction;\n        intro h3;\n        apply @Nat.lt_of_lt_of_le 0 base;\n        apply @Nat.lt_trans 0 1;\n        simp;\n        exact base.property;\n        assumption;\n        apply Nat.succ_le_of_lt;\n        exact base.property;\n      };\n      let ret := Fin.mk (n % base.val) h1 :: (toPositionalNotation (n / base)).val;\n      have h: ret \u2260 [] := by {simp;};\n      exact \u27e8ret, h\u27e9;\n    }\n  termination_by _ n => n\n\ntheorem PositionalNotation.induction.F.{u} {b: BaseType}\n  (C : Nat \u2192 Sort u)\n  (ind: \u2200n, n \u2265 b.val \u2192 C (n / b) \u2192 C n)\n  (base: \u2200n, \u00acn \u2265 b.val \u2192 C n)\n  (n: Nat) (f: \u2200x', x' < n \u2192 C x') : C n :=\n  if h: n \u2265 b then\n    have h1: n / b < n := by {\n      apply hodai2;\n      apply Or.elim $ Nat.lt_or_ge n b;\n      intro a;\n      exact absurd h (Nat.not_le_of_gt a);\n      intro;\n      apply @Nat.lt_of_lt_of_le 0 b;\n      apply @Nat.lt_trans 0 1;\n      simp;\n      exact b.property;\n      assumption;\n      apply Nat.succ_le_of_lt;\n      exact b.property;\n    };\n    ind n h (f (n / b) h1)\n  else base n h\n\ntheorem PositionalNotation.inductionOn.{u}\n  (motive: Nat \u2192 Sort u)\n  (x: Nat)\n  (b: BaseType) -- koko hontou ha implicit ni sitai\n  (ind: \u2200x, x \u2265 b.val \u2192 motive (x / b) \u2192 motive x)\n  (base: \u2200x, \u00acx \u2265 b.val \u2192 motive x)\n  : motive x :=\n  WellFounded.fix (measure id).wf (PositionalNotation.induction.F motive ind base) x\n\ntheorem toNat_toPosNot_eq_Nat {b: BaseType} : \u2200n, (@toPositionalNotation b n).toNat = n := by {\n  intro n;\n  induction n using PositionalNotation.inductionOn;\n  assumption;\n  case ind n ih1 ih2 => {\n    unfold toPositionalNotation;\n    apply Or.elim $ Nat.lt_or_ge n b;\n    intro h2;\n    simp [h2, PositionalNotation.toNat, List.foldr];\n    intro h2;\n    have h3 := hodai7 n b h2;\n    simp [PositionalNotation.toNat] at ih2;\n    simp [h3, PositionalNotation.toNat, List.foldr, ih2];\n    simp [hodai8];\n  };\n  case base x prems => {\n    unfold toPositionalNotation;\n    have h1 := Nat.gt_of_not_le prems;\n    simp [h1, PositionalNotation.toNat, List.foldr];\n  };\n}\n\ntheorem keta_no_wa_no_amari_eq_moto_no_kazu_no_amari {b: {n: Nat // n > 1}} : \u2200n m, (n + m) % (b.val - 1) = (List.foldl (\u03bb(a: Nat) (b: Fin b) => a + b) m (toPositionalNotation n).val) % (b.val - 1) := by {\n  intro n;\n  induction n using PositionalNotation.inductionOn;\n  assumption;\n  case ind x prems ih => {\n    unfold toPositionalNotation;\n    have h1 := hodai7 x b prems;\n    all_goals simp [List.foldl, h1, Nat.add_comm];\n    intro m;\n    specialize ih (m + x % b.val);\n    simp [\u2190ih];\n    rw [(Nat.add_comm m), \u2190Nat.add_assoc];\n    have h2 := hodai13 x b m b.property;\n    assumption;\n  };\n  case base x prems => {\n    unfold toPositionalNotation;\n    have h1 := Nat.gt_of_not_le prems;\n    simp [h1, List.foldl];\n    intro;\n    simp [Nat.add_comm];\n  };\n}\n\n#eval Lean.versionString", "meta": {"author": "amamama", "repo": "fuzzy-octo-palm-tree", "sha": "12685c23ab4a5bcf3187fe87594a629dbb1d1288", "save_path": "github-repos/lean/amamama-fuzzy-octo-palm-tree", "path": "github-repos/lean/amamama-fuzzy-octo-palm-tree/fuzzy-octo-palm-tree-12685c23ab4a5bcf3187fe87594a629dbb1d1288/src/posnot.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7206127850884931}}
{"text": "/-\nCopyright (c) 2021 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport data.finset.card\n\n/-!\n# UV-compressions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines UV-compression. It is an operation on a set family that reduces its shadow.\n\nUV-compressing `a : \u03b1` along `u v : \u03b1` means replacing `a` by `(a \u2294 u) \\ v` if `a` and `u` are\ndisjoint and `v \u2264 a`. In some sense, it's moving `a` from `v` to `u`.\n\nUV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that\ncompressing a set family might decrease the size of its shadow, so iterated compressions hopefully\nminimise the shadow.\n\n## Main declarations\n\n* `uv.compress`: `compress u v a` is `a` compressed along `u` and `v`.\n* `uv.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`.\n  It is the compressions of the elements of `s` whose compression is not already in `s` along with\n  the element whose compression is already in `s`. This way of splitting into what moves and what\n  does not ensures the compression doesn't squash the set family, which is proved by\n  `uv.card_compress`.\n\n## Notation\n\n`\ud835\udcd2` (typed with `\\MCC`) is notation for `uv.compression` in locale `finset_family`.\n\n## Notes\n\nEven though our emphasis is on `finset \u03b1`, we define UV-compressions more generally in a generalized\nboolean algebra, so that one can use it for `set \u03b1`.\n\n## TODO\n\nProve that compressing reduces the size of shadow. This result and some more already exist on the\nbranch `combinatorics`.\n\n## References\n\n* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf\n\n## Tags\n\ncompression, UV-compression, shadow\n-/\n\nopen finset\n\nvariable {\u03b1 : Type*}\n\n/-- UV-compression is injective on the elements it moves. See `uv.compress`. -/\nlemma sup_sdiff_inj_on [generalized_boolean_algebra \u03b1] (u v : \u03b1) :\n  {x | disjoint u x \u2227 v \u2264 x}.inj_on (\u03bb x, (x \u2294 u) \\ v) :=\nbegin\n  rintro a ha b hb hab,\n  have h : (a \u2294 u) \\ v \\ u \u2294 v = (b \u2294 u) \\ v \\ u \u2294 v,\n  { dsimp at hab,\n    rw hab },\n  rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm,\n    hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h,\nend\n\n-- The namespace is here to distinguish from other compressions.\nnamespace uv\n\n/-! ### UV-compression in generalized boolean algebras -/\n\nsection generalized_boolean_algebra\nvariables [generalized_boolean_algebra \u03b1] [decidable_rel (@disjoint \u03b1 _ _)]\n  [decidable_rel ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)] {s : finset \u03b1} {u v a b : \u03b1}\n\nlocal attribute [instance] decidable_eq_of_decidable_le\n\n/-- To UV-compress `a`, if it doesn't touch `U` and does contain `V`, we remove `V` and\nput `U` in. We'll only really use this when `|U| = |V|` and `U \u2229 V = \u2205`. -/\ndef compress (u v a : \u03b1) : \u03b1 := if disjoint u a \u2227 v \u2264 a then (a \u2294 u) \\ v else a\n\n/-- To UV-compress a set family, we compress each of its elements, except that we don't want to\nreduce the cardinality, so we keep all elements whose compression is already present. -/\ndef compression (u v : \u03b1) (s : finset \u03b1) :=\ns.filter (\u03bb a, compress u v a \u2208 s) \u222a (s.image $ compress u v).filter (\u03bb a, a \u2209 s)\n\nlocalized \"notation (name := uv.compression) `\ud835\udcd2 ` := uv.compression\" in finset_family\n\n/-- `is_compressed u v s` expresses that `s` is UV-compressed. -/\ndef is_compressed (u v : \u03b1) (s : finset \u03b1) := \ud835\udcd2 u v s = s\n\n\n\n/-- `a` is in the UV-compressed family iff it's in the original and its compression is in the\noriginal, or it's not in the original but it's the compression of something in the original. -/\nlemma mem_compression :\n  a \u2208 \ud835\udcd2 u v s \u2194 a \u2208 s \u2227 compress u v a \u2208 s \u2228 a \u2209 s \u2227 \u2203 b \u2208 s, compress u v b = a :=\nby simp_rw [compression, mem_union, mem_filter, mem_image, and_comm (a \u2209 s)]\n\n@[simp] lemma compress_self (u a : \u03b1) : compress u u a = a :=\nbegin\n  unfold compress,\n  split_ifs,\n  { exact h.1.symm.sup_sdiff_cancel_right },\n  { refl }\nend\n\n@[simp] lemma compression_self (u : \u03b1) (s : finset \u03b1) : \ud835\udcd2 u u s = s :=\nbegin\n  unfold compression,\n  convert union_empty s,\n  { ext a,\n    rw [mem_filter, compress_self, and_self] },\n  { refine eq_empty_of_forall_not_mem (\u03bb a ha, _),\n    simp_rw [mem_filter, mem_image, compress_self] at ha,\n    obtain \u27e8\u27e8b, hb, rfl\u27e9, hb'\u27e9 := ha,\n    exact hb' hb }\nend\n\n/-- Any family is compressed along two identical elements. -/\nlemma is_compressed_self (u : \u03b1) (s : finset \u03b1) : is_compressed u u s := compression_self u s\n\nlemma compress_disjoint (u v : \u03b1) :\n  disjoint (s.filter (\u03bb a, compress u v a \u2208 s)) ((s.image $ compress u v).filter (\u03bb a, a \u2209 s)) :=\ndisjoint_left.2 $ \u03bb a ha\u2081 ha\u2082, (mem_filter.1 ha\u2082).2 (mem_filter.1 ha\u2081).1\n\n/-- Compressing an element is idempotent. -/\n@[simp] lemma compress_idem (u v a : \u03b1) : compress u v (compress u v a) = compress u v a :=\nbegin\n  unfold compress,\n  split_ifs with h h',\n  { rw [le_sdiff_iff.1 h'.2, sdiff_bot, sdiff_bot, sup_assoc, sup_idem] },\n  { refl },\n  { refl }\nend\n\nlemma compress_mem_compression (ha : a \u2208 s) : compress u v a \u2208 \ud835\udcd2 u v s :=\nbegin\n  rw mem_compression,\n  by_cases compress u v a \u2208 s,\n  { rw compress_idem,\n    exact or.inl \u27e8h, h\u27e9 },\n  { exact or.inr \u27e8h, a, ha, rfl\u27e9 }\nend\n\n-- This is a special case of `compress_mem_compression` once we have `compression_idem`.\nlemma compress_mem_compression_of_mem_compression (ha : a \u2208 \ud835\udcd2 u v s) : compress u v a \u2208 \ud835\udcd2 u v s :=\nbegin\n  rw mem_compression at \u22a2 ha,\n  simp only [compress_idem, exists_prop],\n  obtain \u27e8_, ha\u27e9 | \u27e8_, b, hb, rfl\u27e9 := ha,\n  { exact or.inl \u27e8ha, ha\u27e9 },\n  { exact or.inr \u27e8by rwa compress_idem, b, hb, (compress_idem _ _ _).symm\u27e9 }\nend\n\n/-- Compressing a family is idempotent. -/\n@[simp] lemma compression_idem (u v : \u03b1) (s : finset \u03b1) : \ud835\udcd2 u v (\ud835\udcd2 u v s) = \ud835\udcd2 u v s :=\nbegin\n  have h : filter (\u03bb a, compress u v a \u2209 \ud835\udcd2 u v s) (\ud835\udcd2 u v s) = \u2205 :=\n    filter_false_of_mem (\u03bb a ha h, h $ compress_mem_compression_of_mem_compression ha),\n  rw [compression, image_filter, h, image_empty, \u2190h],\n  exact filter_union_filter_neg_eq _ (compression u v s),\nend\n\n/-- Compressing a family doesn't change its size. -/\nlemma card_compression (u v : \u03b1) (s : finset \u03b1) : (\ud835\udcd2 u v s).card = s.card :=\nbegin\n  rw [compression, card_disjoint_union (compress_disjoint _ _), image_filter, card_image_of_inj_on,\n    \u2190card_disjoint_union, filter_union_filter_neg_eq],\n  { rw disjoint_iff_inter_eq_empty,\n    exact filter_inter_filter_neg_eq _ _ _ },\n  intros a ha b hb hab,\n  dsimp at hab,\n  rw [mem_coe, mem_filter, function.comp_app] at ha hb,\n  rw compress at ha hab,\n  split_ifs at ha hab with has,\n  { rw compress at hb hab,\n    split_ifs at hb hab with hbs,\n    { exact sup_sdiff_inj_on u v has hbs hab },\n    { exact (hb.2 hb.1).elim } },\n  { exact (ha.2 ha.1).elim }\nend\n\n/-- If `a` is in the family compression and can be compressed, then its compression is in the\noriginal family. -/\nlemma sup_sdiff_mem_of_mem_compression (ha : a \u2208 \ud835\udcd2 u v s) (hva : v \u2264 a) (hua : disjoint u a) :\n  (a \u2294 u) \\ v \u2208 s :=\nbegin\n  rw [mem_compression, compress_of_disjoint_of_le hua hva] at ha,\n  obtain \u27e8_, ha\u27e9 | \u27e8_, b, hb, rfl\u27e9 := ha,\n  { exact ha },\n  have hu : u = \u22a5,\n  { suffices : disjoint u (u \\ v),\n    { rwa [(hua.mono_right hva).sdiff_eq_left, disjoint_self] at this },\n    refine hua.mono_right _,\n    rw [\u2190compress_idem, compress_of_disjoint_of_le hua hva],\n    exact sdiff_le_sdiff_right le_sup_right },\n  have hv : v = \u22a5,\n  { rw \u2190disjoint_self,\n    apply disjoint.mono_right hva,\n    rw [\u2190compress_idem, compress_of_disjoint_of_le hua hva],\n    exact disjoint_sdiff_self_right },\n  rwa [hu, hv, compress_self, sup_bot_eq, sdiff_bot],\nend\n\n/-- If `a` is in the `u, v`-compression but `v \u2264 a`, then `a` must have been in the original\nfamily. -/\nlemma mem_of_mem_compression (ha : a \u2208 \ud835\udcd2 u v s) (hva : v \u2264 a) (hvu : v = \u22a5 \u2192 u = \u22a5) : a \u2208 s :=\nbegin\n  rw mem_compression at ha,\n  obtain ha | \u27e8_, b, hb, h\u27e9 := ha,\n  { exact ha.1 },\n  unfold compress at h,\n  split_ifs at h,\n  { rw [\u2190h, le_sdiff_iff] at hva,\n    rw [hvu hva, hva, sup_bot_eq, sdiff_bot] at h,\n    rwa \u2190h },\n  { rwa \u2190h }\nend\n\nend generalized_boolean_algebra\n\n/-! ### UV-compression on finsets -/\n\nopen_locale finset_family\n\nvariables [decidable_eq \u03b1] {\ud835\udc9c : finset (finset \u03b1)} {U V A : finset \u03b1}\n\n/-- Compressing a finset doesn't change its size. -/\nlemma card_compress (hUV : U.card = V.card) (A : finset \u03b1) : (compress U V A).card = A.card :=\nbegin\n  unfold compress,\n  split_ifs,\n  { rw [card_sdiff (h.2.trans le_sup_left), sup_eq_union, card_disjoint_union h.1.symm, hUV,\n    add_tsub_cancel_right] },\n  { refl }\nend\n\nend uv\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/set_family/compression/uv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7204774539363161}}
{"text": "/-\nCopyright (c) 2018 Rohan Mitta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes H\u00f6lzl\n\nLipschitz functions and the Banach fixed-point theorem\n-/\nimport topology.metric_space.basic analysis.specific_limits\nopen filter\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\n\nlemma fixed_point_of_tendsto_iterate [topological_space \u03b1] [t2_space \u03b1] {f : \u03b1 \u2192 \u03b1} {x : \u03b1}\n  (hf : tendsto f (nhds x) (nhds (f x))) (hx : \u2203 x\u2080 : \u03b1, tendsto (\u03bb n, f^[n] x\u2080) at_top (nhds x)) :\n  f x = x :=\nbegin\n  rcases hx with \u27e8x\u2080, hx\u27e9,\n  refine tendsto_nhds_unique at_top_ne_bot _ hx,\n  rw [\u2190 tendsto_add_at_top_iff_nat 1, funext (assume n, nat.iterate_succ' f n x\u2080)],\n  exact hx.comp hf\nend\n\n/-- A Lipschitz function is uniformly continuous -/\nlemma uniform_continuous_of_lipschitz [metric_space \u03b1] [metric_space \u03b2] {K : \u211d}\n  {f : \u03b1 \u2192 \u03b2} (H : \u2200x y, dist (f x) (f y) \u2264 K * dist x y) : uniform_continuous f :=\nbegin\n  have : 0 < max K 1 := lt_of_lt_of_le zero_lt_one (le_max_right K 1),\n  refine metric.uniform_continuous_iff.2 (\u03bb\u03b5 \u03b5pos, _),\n  exact \u27e8\u03b5/max K 1, div_pos \u03b5pos this, assume y x Dyx, calc\n    dist (f y) (f x) \u2264 K * dist y x : H y x\n    ... \u2264 max K 1 * dist y x : mul_le_mul_of_nonneg_right (le_max_left K 1) (dist_nonneg)\n    ... < max K 1 * (\u03b5/max K 1) : mul_lt_mul_of_pos_left Dyx this\n    ... = \u03b5 : mul_div_cancel' _ (ne_of_gt this)\u27e9\nend\n\n/-- A Lipschitz function is continuous -/\nlemma continuous_of_lipschitz [metric_space \u03b1] [metric_space \u03b2] {K : \u211d}\n  {f : \u03b1 \u2192 \u03b2} (H : \u2200x y, dist (f x) (f y) \u2264 K * dist x y) : continuous f :=\nuniform_continuous.continuous (uniform_continuous_of_lipschitz H)\n\nlemma uniform_continuous_of_le_add [metric_space \u03b1] {f : \u03b1 \u2192 \u211d} (K : \u211d)\n  (h : \u2200x y, f x \u2264 f y + K * dist x y) : uniform_continuous f :=\nbegin\n  have I : \u2200 (x y : \u03b1), f x - f y \u2264 K * dist x y := \u03bbx y, calc\n    f x - f y \u2264 (f y + K * dist x y) - f y : add_le_add (h x y) (le_refl _)\n    ... = K * dist x y : by ring,\n  refine @uniform_continuous_of_lipschitz _ _ _ _ K _ (\u03bbx y, _),\n  rw real.dist_eq,\n  refine abs_sub_le_iff.2 \u27e8_, _\u27e9,\n  { exact I x y },\n  { rw dist_comm, exact I y x }\nend\n\n/-- `lipschitz_with K f`: the function `f` is Lipschitz continuous w.r.t. the Lipschitz\nconstant `K`. -/\ndef lipschitz_with [metric_space \u03b1] [metric_space \u03b2] (K : \u211d) (f : \u03b1 \u2192 \u03b2) :=\n0 \u2264 K \u2227 \u2200x y, dist (f x) (f y) \u2264 K * dist x y\n\nnamespace lipschitz_with\n\nvariables [metric_space \u03b1] [metric_space \u03b2] [metric_space \u03b3] {K : \u211d}\n\nprotected lemma weaken (K' : \u211d) {f : \u03b1 \u2192 \u03b2} (hf : lipschitz_with K f) (h : K \u2264 K') :\n  lipschitz_with K' f :=\n\u27e8le_trans hf.1 h, assume x y, le_trans (hf.2 x y) $ mul_le_mul_of_nonneg_right h dist_nonneg\u27e9\n\nprotected lemma to_uniform_continuous {f : \u03b1 \u2192 \u03b2} (hf : lipschitz_with K f) : uniform_continuous f :=\nuniform_continuous_of_lipschitz hf.2\n\nprotected lemma to_continuous {f : \u03b1 \u2192 \u03b2} (hf : lipschitz_with K f) : continuous f :=\ncontinuous_of_lipschitz hf.2\n\nprotected lemma const (b : \u03b2) : lipschitz_with 0 (\u03bba:\u03b1, b) :=\n\u27e8le_refl 0, assume x y, by simp\u27e9\n\nprotected lemma id : lipschitz_with 1 (@id \u03b1) :=\n\u27e8zero_le_one, by simp [le_refl]\u27e9\n\nprotected lemma comp {Kf Kg : \u211d} {f : \u03b2 \u2192 \u03b3} {g : \u03b1 \u2192 \u03b2}\n  (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf * Kg) (f \u2218 g) :=\n\u27e8mul_nonneg hf.1 hg.1, assume x y,\n  calc dist (f (g x)) (f (g y)) \u2264 Kf * dist (g x) (g y) : hf.2 _ _\n    ... \u2264 Kf * (Kg * dist x y) : mul_le_mul_of_nonneg_left (hg.2 _ _) hf.1\n    ... = (Kf * Kg) * dist x y : by rw mul_assoc\u27e9\n\nprotected lemma iterate {f : \u03b1 \u2192 \u03b1} (hf : lipschitz_with K f) : \u2200n, lipschitz_with (K ^ n) (f^[n])\n| 0       := lipschitz_with.id\n| (n + 1) := by rw [\u2190 nat.succ_eq_add_one, pow_succ, mul_comm]; exact (iterate n).comp hf\n\nsection contraction\nvariables {f : \u03b1 \u2192 \u03b1} {x y : \u03b1}\n\nlemma dist_inequality_of_contraction (hK\u2081 : K < 1) (hf : lipschitz_with K f) :\n   dist x y \u2264 (dist x (f x) + dist y (f y)) / (1 - K) :=\nsuffices dist x y \u2264 dist x (f x) + (dist y (f y) + K * dist x y),\n  by rwa [le_div_iff (sub_pos_of_lt hK\u2081), mul_comm, sub_mul, one_mul, sub_le_iff_le_add, add_assoc],\ncalc dist x y \u2264 dist x (f x) + dist y (f x) :\n    dist_triangle_right x y (f x)\n  ... \u2264 dist x (f x) + (dist y (f y) + dist (f x) (f y)) :\n    add_le_add_left (dist_triangle_right y (f x) (f y)) _\n  ... \u2264 dist x (f x) + (dist y (f y) + K * dist x y) :\n    add_le_add_left (add_le_add_left (hf.2 _ _) _) _\n\ntheorem fixed_point_unique_of_contraction (hK : K < 1) (hf : lipschitz_with K f)\n  (hx : f x = x) (hy : f y = y) : x = y :=\ndist_le_zero.1 $ le_trans (dist_inequality_of_contraction hK hf) $\n  by rewrite [iff.mpr dist_eq_zero hx.symm, iff.mpr dist_eq_zero hy.symm]; simp\n\n/-- Banach fixed-point theorem, contraction mapping theorem -/\ntheorem exists_fixed_point_of_contraction [h\u03b1 : nonempty \u03b1] [complete_space \u03b1]\n  (hK : K < 1) (hf : lipschitz_with K f) : \u2203x, f x = x :=\nlet \u27e8x\u2080\u27e9 := h\u03b1 in\nhave cauchy_seq (\u03bb n, f^[n] x\u2080) := begin\n  refine cauchy_seq_of_le_geometric K (dist x\u2080 (f x\u2080)) hK (\u03bbn, _),\n  rw [nat.iterate_succ f n x\u2080, mul_comm],\n  exact and.right (hf.iterate n) x\u2080 (f x\u2080)\nend,\nlet \u27e8x, hx\u27e9 := cauchy_seq_tendsto_of_complete this in\n\u27e8x, fixed_point_of_tendsto_iterate (hf.to_uniform_continuous.continuous.tendsto x) \u27e8x\u2080, hx\u27e9\u27e9\n\nend contraction\n\nend lipschitz_with\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/topology/metric_space/lipschitz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.7204774457467104}}
{"text": "import week_8.Part_A_G_modules\n\n/-\n\n# Making the API for H\u2070(G,M)\n\nIf G is a group and M is a G-module then H\u2070(G,M), or `H0 G M`, is the abelian\ngroup of G-invariant elements of `M`. We make the definition so we have\nto make the interface too. We show that `H0 G M` is an abelian group,\ndefine a coercion to `M` sending `m` to `\u2191m`, and define `m.spec` to be\nthe statement that `\u2191m` is G-invariant.\n\nLet's start by giving a preliminary definition of H\u2070 as an additive\nsubgroup of `M`.\n\n-/\n\nopen set\n\n/-- `H0 G M` is the type of G-invariant elements of M. -/\ndef H0_subgroup (G M : Type)\n  [monoid G] [add_comm_group M] [distrib_mul_action G M] : add_subgroup M :=\n{ carrier := {m | \u2200 g : G, g \u2022 m = m },\n  -- Need to check it's a subgroup.\n  -- Axiom 1: zero in (\"closed under `0`\")\n  zero_mem' := begin\n    -- you can start with this\n    rw mem_set_of_eq, -- says that `a \u2208 { x | p x}` is the same as `p a`.\n    -- can you take it from there?\n    sorry\n  end,\n  -- Axiom 2 : closed under `+`\n  add_mem' := begin\n    intros a b ha hb g,\n    rw mem_set_of_eq at *, -- that's how I'd start\n    sorry,\n  end,\n  -- Axiom 3 : closed under `-`\n  neg_mem' := begin\n    sorry\n  end }\n\n/-\n\nThis makes `H0_subgroup G M`, a term (an additive subgroup of `M`, and\nhence a term of type `add_subgroup M`). But this is no good -- we want\nto consider functions `H\u2070(G,M) \u2192 H\u2070(G,N)` so we need a *type* `H0 G M`.\nWe need to promote the term to a type. We do this by using Lean's\ntheory of subtypes, with notation `{ x // P x }` (a type) as oppposed to \nthe set-theoretic `{ x | P x }` (a term)\n\n-/\n\n/-- Group cohomology `H\u2070(G,M)` as a type. -/\ndef H0 (G M : Type)\n  [monoid G] [add_comm_group M] [distrib_mul_action G M] : Type :=\n{m : M // \u2200 g : G, g \u2022 m = m }\n\n-- let's make an API and prove stuff about `H0 G M` in the `H0` namespace.\nnamespace H0\n\n-- let `G` be a group (or a monoid) and let `M` be a `G`-module.\nvariables {G M : Type}\n  [monoid G] [add_comm_group M] [distrib_mul_action G M]\n\n/-\nWe have defined `H0 G M` to be a type, a so-called subtype of `M`,\nbut a type in its own right. It has terms of its own (unlike `S : set M`\nor `A : sub_distrib_mul_action M`)\n\nSo how does this work? A term `m` of type `H0 G M` is a *package* consisting\nof a term `m.1 : M` and a proof `m.2 : \u2200 g, g \u2022 m.1 = m.1`. We do not\nwant to use these internal computer science terms for this package\nof information, we want a nice interface. Below we use coercion, to turn\na term `m : H0 G M` into a term `\u2191m : M`.  \n\n-/\n\n/-- set up coercion from `H\u2070(G,M) to M`, sending `m` to `\u2191m` -/\ninstance : has_coe (H0 G M) M :=\n-- this is the last time we see `m.1`\n\u27e8\u03bb m, m.1\u27e9\n\n-- That's a definition, so we need to make a little API.\n\n/-- If `a : M` then `\u2191\u27e8a, ha\u27e9 = a` -/\n@[simp] lemma coe_def (a : M) (ha : \u2200(g : G), g \u2022 a = a) :\n  ((\u27e8a, ha\u27e9 : H0 G M) : M) = a := rfl\n\n-- this is our nice interface\nlemma spec (m : H0 G M) : \u2200 (g : G), g \u2022 (m : M) = m :=\n-- this is the last time we see `m.2`\nm.2\n\n/-\n\nThe idea now is that we should avoid `m.1` and `m.2` completely,\nand use `m : M` or `\u2191m` for the element of the module, and `m.spec` for\nthe proof that it is `G`-invariant.\n\n## Basic Infrastructure\n\nWe have made a new definition, `H0`, and now we need to make it easier\nto use. Things we do here: \n\n* We want to get (for free) that `H0 G M` is a group (so we need to put\n  this fact into the type class mechanism).\n\n* We want to know that two terms of type `H0 G M` are equal if\n  and only if the corresponding terms of type `M` are equal (so we want to\n  prove an extensionality lemma).\n\n* We want to know that things like 0 and addition coincide in `M`\n  and `H0 G M` (the coercion is a group homomorphism)\n\nLet's start by making H\u2070(G, M) a.k.a. `H0 G M` into a group. This is easy\nbecause `H0 G M` is the type corresponding to the term `H0_subgroup G M`\nwhich is a subgroup, hence a group.\n\n-/\n\n-- tell type class inference that `H0 G M` is a group\ninstance : add_comm_group (H0 G M) :=\nadd_subgroup.to_add_comm_group (H0_subgroup G M)\n\n-- Let's now prove an ext_iff lemma (useful for rewriting)\nlemma ext_iff (m\u2081 m\u2082 : H0 G M) : m\u2081 = m\u2082 \u2194 (m\u2081 : M) = (m\u2082 : M) := \nbegin\n  split,\n  { -- one way uses a rewrite\n    rintro rfl, refl },\n  { -- the other way is just set extensionality\n    ext }\nend\n\n-- Let's tell the simplifier how the group structure (addition, 0, negation\n-- and subtraction) works with respect to the coercion. All the proofs\n-- are true by definition\n\n@[simp] lemma coe_add (a b : H0 G M) :\n  ((a + b : H0 G M) : M) = a + b :=\nbegin\n  -- true by definition\n  refl\nend\n\n@[simp] lemma coe_zero : ((0 : H0 G M) : M) = 0 := rfl -- true by definition\n\n@[simp] lemma coe_neg (a : H0 G M) :\n  ((-a : H0 G M) : M) = -a := rfl\n\n@[simp] lemma coe_sub (a b : H0 G M) :\n  ((a - b : H0 G M) : M) = a - b := rfl\n\n-- try these\nexample (m\u2081 m\u2082 m\u2083 : H0 G M) : m\u2081 + (m\u2082 - m\u2081 + m\u2083) = m\u2083 + m\u2082 :=\nbegin\n  -- which tactic?\n  sorry\nend\n\nexample (g : G) (m : H0 G M) : g \u2022 (m + m : M) = m + m :=\nbegin\n  -- can you help the simplifier?\n  sorry\nend\n\nend H0\n\n/-\n\n## Definition of `\u03c6.H0 : H0 G M \u2192+ H0 G N`\n\nNow let's prove that a G-module map `\u03c6 : M \u2192+[G] N` induces a natural\nabelian group hom `\u03c6.H0 : H\u2070(G,M) \u2192+ H\u2070(G,N)`. I would rather do this in\n`\u03c6`'s namespace, which is `distrib_mul_action_hom`, because then\nI can write `\u03c6.H0` directly. This is definitions so it's a bit messy.\nI left you one sorry -- prove that if `m \u2208 H\u2070(G,M)` then `\u03c6(m)` is actually\n`G`-invariant.\n-/\n\nnamespace distrib_mul_action_hom\n\nvariables {G M N : Type}\n  [monoid G] [add_comm_group M] [add_comm_group N]\n  [distrib_mul_action G M] [distrib_mul_action G N]\n  (a : M) (b : N)\n\n-- Let's first define the group homomorphism `H0 G M \u2192+ H0 G N` induced by `\u03c6`.\n-- Recall that the constructor of `H0 G N` needs as input a pair consisting\n-- of `b : N` and `hb : \u2200 g, g \u2022 b = b`, and we make the element of `H0 G N`\n-- using the `\u27e8b, hb\u27e9` notation. I am playing with the idea of\n-- distinguishing `n : H0 G N` and `b = \u2191n` when we're taking these\n-- things apart explicitly. \n\n/- The function underlying the group homomorphism `H\u2070(G,M) \u2192 H\u2070(G,N)`\n   induced by a `G`-equivariant group homomorphism `\u03c6 : M \u2192+[G] N` -/\ndef H0_underlying_function (\u03c6 : M \u2192+[G] N) (a : H0 G M) : H0 G N :=\n\u27e8\u03c6 a, begin\n  -- use \u03c6.map_smul and a.spec to prove that this map is well-defined.\n  -- Remember that `rw` doesn't work under binders, and \u2200 is a binder, so start\n  -- with `intros`.\n  sorry\nend\u27e9\n\n/-- The group homomorphism  `H\u2070(G,M) \u2192+ H\u2070(G,N)`\n   induced by a `G`-equivariant group homomorphism `\u03c6 : M \u2192+[G] N` -/\ndef H0 (\u03c6 : M \u2192+[G] N) : H0 G M \u2192+ H0 G N :=\n-- to make a group homomorphism we need apply a constructor\nadd_monoid_hom.mk'\n-- to the function we just made\n(H0_underlying_function \u03c6)\n-- and then prove that this function preserves addition.\nbegin\n  -- this is a bit of a mess, I'll do it.\n  intros a b,\n  simp only [H0_underlying_function],\n  ext,\n  simp,\nend\n\nend distrib_mul_action_hom\n\n-- The API for `\u03c6.H0` starts here\n\nnamespace H0\n\nvariables {G M N : Type}\n  [monoid G] [add_comm_group M] [add_comm_group N]\n  [distrib_mul_action G M] [distrib_mul_action G N]\n  (a : M) (b : N)\n\n/-\n\n## An API for `\u03c6.H0`\n\nSo now if `\u03c6 : M \u2192+[G] N` is a G-module homomorphism, we can talk\nabout `\u03c6.H0 : H0 G M \u2192+ H0 G N`, an abelian group homomorphism \nfrom H\u2070(G,M) to H\u2070(G,N).\n\nAs ever, this is a definition so we need to make a little API.\nWe start with the following handy fact:\n\nGiven a G-module map `\u03c6 : M \u2192+[G] N`, The following diagram commutes:\n\n            \u03c6\n  M ----------------> N\n  /\\                  /\\\n  | coercion \u2191        | coercion \u2191\n  |                   |\n  |                   |\nH\u2070(G,M) ---------> H\u2070(G,N)\n-/\n@[simp] lemma coe_apply (m : H0 G M) (\u03c6 : M \u2192+[G] N) :\n  ((\u03c6.H0 m) : N) = \u03c6 m :=\nbegin\n  -- Look at the goal the way I have written it.\n  -- Unfold the definitions. It's true by definition.\n  -- Look at the goal the way Lean is displaying it\n  -- right now. It's just coercions everywhere. Ignore them.\n  sorry\nend\n\nopen distrib_mul_action_hom\n\n-- If you're in to that sort of thing, you can prove that `\u03c6.H0`\n-- is functorial. That's it and comp.\ndef id_apply (m : H0 G M) :\n  (distrib_mul_action_hom.id G).H0 m = m :=\nbegin\n  -- remember extensionality. \n  sorry,\nend\n\nvariables {P : Type} [add_comm_group P] [distrib_mul_action G P]\n\ndef comp (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) :\n  (\u03c8 \u2218\u1d4d \u03c6).H0 = \u03c8.H0.comp \u03c6.H0 := \nbegin\n  -- be sure to check out the proof in the solutions.\n  sorry\nend\n\nend H0\n\n/-\n\n## First exactness result\n\nIf 0 \u2192 M \u2192 N \u2192 P \u2192 0 is a short exact sequence, then there\nis a long exact sequence\n\n0 \u2192 H\u2070(G,M) \u2192 H\u2070(G,N) \u2192 H\u2070(G,P)\n\nand we can't go any further because we haven't defined H\u00b9! This boils\ndown to two theorems; let's prove them.\n\n-/\nopen function\n\nopen distrib_mul_action_hom\n\nvariables {G M N P : Type}\n  [monoid G] [add_comm_group M] [add_comm_group N] [add_comm_group P]\n  [distrib_mul_action G M] [distrib_mul_action G N] [distrib_mul_action G P]\n  (a : M) (b : N)\n\n\n-- 0 \u2192 H\u2070(G,M) \u2192 H\u2070(G,N) is exact, i.e. \u03c6.H0 is injective\ntheorem H0_hom.left_exact (\u03c6 : M \u2192+[G] N) (h\u03c6 : injective \u03c6) : \n  injective \u03c6.H0 :=\nbegin\n  sorry\nend\n\n\n-- H\u2070(G,M) \u2192 H\u2070(G,N) \u2192 H\u2070(G,P) is exact, i.e. an image equals a kernel.\ntheorem H0_hom.middle_exact (\u03c6 : M \u2192+[G] N)\n  (\u03c8 : N \u2192+[G] P) (h : is_short_exact \u03c6 \u03c8) : \n  \u03c6.H0.range = \u03c8.H0.ker :=\nbegin\n  sorry,\nend\n\n-- Do you think we should prove something weaker? I quite\n-- like the API we have for short exact sequences.", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_8/Part_B_H0.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7204774429527143}}
{"text": "import tactic\n\nvariables {\u03b1 : Type*} [comm_ring \u03b1]\n\ndef sum_of_squares (x : \u03b1) := \u2203 a b, x = a^2 + b^2\n\ntheorem sum_of_squares_mul {x y : \u03b1}\n    (sosx : sum_of_squares x) (sosy : sum_of_squares y) :\n  sum_of_squares (x * y) :=\nbegin\n  rcases sosx with \u27e8a, b, xeq\u27e9,\n  rcases sosy with \u27e8c, d, yeq\u27e9,\n  rw [xeq, yeq],\n  use [a*c - b*d, a*d + b*c],\n  ring,\nend\n\n/- using the cases tactic recursively -/\nexample {x y : \u03b1}\n    (sosx : sum_of_squares x) (sosy : sum_of_squares y) :\n  sum_of_squares (x * y) :=\nbegin\n  cases sosx with a xeq,\n  cases xeq with b xeqab,\n    cases sosy with c yeq,\n    cases yeq with d yeqcd,\n    rw [xeqab, yeqcd],\n    use [a*c - b*d, a*d + b*c],\n    ring,\nend", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.4_rcases/ex4_rcases_sum_of_sqr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7204624980954168}}
{"text": "import data.real.basic\n\nvariables a b c : \u211d\n\n#check le_antisymm\n#check le_min\n#check le_trans\n#check min_le_right a b \n#check min_le_left b c\n\n-- BEGIN\n\nexample : min (min a b) c = min a (min b c) :=\nbegin\n  apply le_antisymm, \n  { apply le_min,\n    exact le_trans (min_le_left (min a b) c) (min_le_left a b),\n    apply le_min,\n    exact le_trans (min_le_left (min a b) c) (min_le_right a b),\n    exact min_le_right (min a b) c,\n  },\n  { apply le_min,\n    apply le_min,\n    exact min_le_left a (min b c),\n    exact le_trans (min_le_right a (min b c)) (min_le_left b c),\n    exact le_trans (min_le_right a (min b c)) (min_le_right b c),\n  },\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.2_exact/ex8_exact_min_min.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026641072385, "lm_q2_score": 0.7853085884247212, "lm_q1q2_score": 0.7203656603082916}}
{"text": "import tactic\nimport data.finmap\nopen tactic\n\nnamespace start\ninductive aexp\n| ANum (n : \u2115)\n| APlus (a\u2081 a\u2082 : aexp)\n| AMinus (a\u2081 a\u2082 : aexp)\n| AMult (a\u2081 a\u2082 : aexp)\nopen aexp\n\ninductive bexp\n| BTrue\n| BFalse\n| BEq (a\u2081 a\u2082 : aexp)\n| BLe (a\u2082 a\u2082 : aexp)\n| BNot (b : bexp)\n| BAnd (b\u2081 b\u2082 : bexp)\nopen bexp\n\ndef aeval : aexp \u2192 \u2115\n| (ANum n) := n\n| (APlus a\u2081 a\u2082) := aeval a\u2081 + aeval a\u2082\n| (AMinus a\u2081 a\u2082) := aeval a\u2081 - aeval a\u2082\n| (AMult a\u2081 a\u2082) := aeval a\u2081 * aeval a\u2082\n\nexample : aeval (APlus (ANum 2) (ANum 2)) = 4 := rfl\n\ndef beval : bexp \u2192 bool\n| BTrue := true\n| BFalse := false\n| (BEq a\u2081 a\u2082) := aeval a\u2081 = aeval a\u2082\n| (BLe a\u2081 a\u2082) := aeval a\u2081 \u2264 aeval a\u2082\n| (BNot b\u2081) := \u00acbeval b\u2081\n| (BAnd b\u2081 b\u2082) := beval b\u2081 \u2227 beval b\u2082\n\ndef optimize_zero_plus : aexp \u2192 aexp\n| (ANum n) := ANum n\n| (APlus (ANum 0) e\u2082) := optimize_zero_plus e\u2082\n| (APlus e\u2081 e\u2082) := APlus (optimize_zero_plus e\u2081) (optimize_zero_plus e\u2082)\n| (AMinus e\u2081 e\u2082) := AMinus (optimize_zero_plus e\u2081) (optimize_zero_plus e\u2082)\n| (AMult e\u2081 e\u2082) := AMult (optimize_zero_plus e\u2081) (optimize_zero_plus e\u2082)\n\nexample : optimize_zero_plus (APlus (ANum 2)\n                                    (APlus (ANum 0)\n                                           (APlus (ANum 0) (ANum 1))))\n        = APlus (ANum 2) (ANum 1) := rfl\n\ntheorem optimize_zero_plus_sound : \u2200 a, aeval (optimize_zero_plus a) = aeval a :=\nbegin\n    intros a, induction a;\n    try { simp [optimize_zero_plus, aeval, a_ih_a\u2081, a_ih_a\u2082] <|> refl },\n    rcases a_a\u2081 with \u27e8_|n\u27e9;\n    simp [optimize_zero_plus, a_ih_a\u2082, a_ih_a\u2081, aeval] at *; assumption\nend\n\n\ninductive aevalR : aexp \u2192 \u2115 \u2192 Prop\n| E_ANum {n} : aevalR (ANum n) n \n| E_APlus {e\u2081 e\u2082 n\u2081 n\u2082} : \n    aevalR e\u2081 n\u2081 \u2192 aevalR e\u2082 n\u2082 \u2192 aevalR (APlus e\u2081 e\u2082) (n\u2081 + n\u2082)\n| E_AMinus {e\u2081 e\u2082 n\u2081 n\u2082} : \n    aevalR e\u2081 n\u2081 \u2192 aevalR e\u2082 n\u2082 \u2192 aevalR (AMinus e\u2081 e\u2082) (n\u2081 - n\u2082)\n| E_AMult {e\u2081 e\u2082 n\u2081 n\u2082} : \n    aevalR e\u2081 n\u2081 \u2192 aevalR e\u2082 n\u2082 \u2192 aevalR (AMult e\u2081 e\u2082) (n\u2081 * n\u2082)\n\nlocal notation e ` \\\\ ` n := aevalR e n \n\ntheorem aeval_iff_aevalR : \u2200 a n, (a \\\\ n) \u2194 aeval a = n :=\nbegin\n    intros, split, \n    { intro h, induction h; subst_vars; refl },\n    revert n, induction a; intros; subst_vars; constructor; simp only [a_ih_a\u2081, a_ih_a\u2082],\nend\n\nend start\n\nnamespace extended_aexp\ninductive aexp\n| ANum (n : \u2115)\n| AId (x : string)\n| APlus (a\u2081 a\u2082 : aexp)\n| AMinus (a\u2081 a\u2082 : aexp)\n| AMult (a\u2081 a\u2082 : aexp)\nopen aexp\n\ninductive bexp\n| BTrue\n| BFalse\n| BEq (a1 a2 : aexp)\n| BLe (a1 a2 : aexp)\n| BNot (b : bexp)\n| BAnd (b1 b2 : bexp)\nopen bexp\n\ninductive com\n| CSkip\n| CAss (x : string) (a : aexp)\n| CSeq (c\u2081 c\u2082 : com)\n| CIf (b : bexp) (c\u2081 c\u2082 : com)\n| CWhile (b : bexp) (c : com)\nopen com\n\nlocal infixr `;; `:40 := CSeq\nlocal infix ` ::= `:60 := CAss\nlocal notation ` SKIP ` := CSkip\nlocal notation ` WHILE ` b ` DO ` c ` END ` := CWhile b c\nlocal notation ` TEST ` c\u2081 ` THEN ` c\u2082 ` ELSE ` c\u2083 ` FI ` := CIf c\u2081 c\u2082 c\u2083\n\ndef W := \"W\"\ndef X := \"X\"\ndef Y := \"Y\"\ndef Z := \"Z\"\n\ninstance has_coe_str_aexp : has_coe string aexp := \u27e8AId\u27e9\ninstance has_coe_nat_aexp : has_coe \u2115 aexp := \u27e8ANum\u27e9\ninstance has_one_aexp : has_one aexp := \u27e8ANum 1\u27e9\ninstance has_zero_aexp : has_zero aexp := \u27e8ANum 0\u27e9\ninstance has_add_aexp : has_add aexp := \u27e8APlus\u27e9\ninstance has_mul_aexp : has_mul aexp := \u27e8AMult\u27e9\ninstance has_sub_aexp : has_sub aexp := \u27e8AMinus\u27e9\nlocal prefix `!` := BNot\nlocal infix ` === `:50 := BEq\n\ndef fact_in_lean :=\n    Z ::= X;;\n    Z ::= 1;;\n    WHILE !Z === 0 DO\n        Y ::= Y * Z;;\n        Z ::= Z - 1\n    END\n\n\ndef program_state := finmap (\u03bb (v:string), \u2115)\n\nlocal notation x ` \u21a6 `:50 y `; `:1 m := finmap.insert x y m\n\n\nlemma program_state_insert_eq (x) (v : \u2115) (s : program_state) : \n    (x \u21a6 v; s).lookup x = some v := by simp\n\nlemma program_state_insert_neq (x\u2081 x\u2082) (v : \u2115) (s : program_state) (h : x\u2081 \u2260 x\u2082) : \n    (x\u2081 \u21a6 v; s).lookup x\u2082 = s.lookup x\u2082 := finmap.lookup_insert_of_ne s h.symm\n\nlemma program_state_shadow (x) (v\u2081 v\u2082 : \u2115) (s : program_state) :\n    (x \u21a6 v\u2081; x \u21a6 v\u2082; s) = (x \u21a6 v\u2081; s) := by simp\n\nlemma program_state_insert_same (x) (s : program_state) {v} (h : s.lookup x = some v) :\n    (x \u21a6 v; s) = s := \nbegin\n    apply finmap.ext_lookup, intro y,\n    cases dec_em (x = y) with hxy hnxy,\n    { rw \u2190hxy, symmetry, simpa, },\n    apply program_state_insert_neq, assumption,\nend\n\nlemma program_state_permute (x\u2081 x\u2082) (v\u2081 v\u2082 : \u2115) (s : program_state) (h : x\u2081 \u2260 x\u2082) :\n    (x\u2081 \u21a6 v\u2081; x\u2082 \u21a6 v\u2082; s) = (x\u2082 \u21a6 v\u2082; x\u2081 \u21a6 v\u2081; s) := finmap.insert_insert_of_ne s h.symm \n\ndef aeval (st : program_state) : aexp \u2192 \u2115\n| (ANum n) := n\n| (AId x) := (st.lookup x).get_or_else 0\n| (APlus a\u2081 a\u2082) := aeval a\u2081 + aeval a\u2082\n| (AMinus a\u2081 a\u2082) := aeval a\u2081 - aeval a\u2082\n| (AMult a\u2081 a\u2082) := aeval a\u2081 * aeval a\u2082\n\ndef beval (st : program_state) : bexp \u2192 bool \n| BTrue := true\n| BFalse := false\n| (BEq a\u2081 a\u2082) := aeval st a\u2081 = aeval st a\u2082\n| (BLe a\u2081 a\u2082) := aeval st a\u2081 \u2264 aeval st a\u2082\n| (BNot b\u2081) := \u00ac(beval b\u2081)\n| (BAnd b\u2081 b\u2082) := beval b\u2081 && beval b\u2082\n\ninductive ceval : com \u2192 program_state \u2192 program_state \u2192 Prop\n| E_Skip {st} : ceval SKIP st st\n| E_Ass {st a\u2081 n x} : \n    aeval st a\u2081 = n \u2192 \n    ceval (x ::= a\u2081) st (x \u21a6 n; st)\n| E_Seq {c\u2081 c\u2082 st st' st''} :\n    ceval c\u2081 st st' \u2192\n    ceval c\u2082 st' st'' \u2192\n    ceval (c\u2081;; c\u2082) st st''\n| E_IfTrue {st st' b c\u2081 c\u2082} :\n    beval st b = true \u2192\n    ceval c\u2081 st st' \u2192\n    ceval TEST b THEN c\u2081 ELSE c\u2082 FI st st'\n| E_IfFalse {st st' b c\u2081 c\u2082} :\n    beval st b = false \u2192\n    ceval c\u2082 st st' \u2192\n    ceval TEST b THEN c\u2081 ELSE c\u2082 FI st st'\n| E_WhileFalse {b st c} :\n    beval st b = false \u2192\n    ceval WHILE b DO c END st st\n| E_WhileTrue {st st' st'' b c} :\n    beval st b = true \u2192\n    ceval c st st' \u2192\n    ceval WHILE b DO c END st' st'' \u2192\n    ceval WHILE b DO c END st st'' \n\nnotation st ` =[ ` c ` ]=> ` st' := ceval c st st'\n\ntheorem ceval_deterministic {c st st\u2081 st\u2082} (h\u2081 : st =[ c ]=> st\u2081) (h\u2082 : st =[ c ]=> st\u2082) : st\u2081 = st\u2082 :=\nbegin\n    intros, revert st\u2082, induction h\u2081; intros; cases h\u2082; subst_vars; try {solve_by_elim},\n    { apply_assumption, specialize h\u2081_ih_a h\u2082_a, subst_vars, assumption },\n    all_goals { rw h\u2081_a at h\u2082_a, injections },\n    specialize h\u2081_ih_a h\u2082_a_1, subst_vars, repeat {apply_assumption}\nend\n\nend extended_aexp\n", "meta": {"author": "alashworth", "repo": "sf-lean", "sha": "bec3ef4ffbe1fcd83772570b84ac3ff074bb7476", "save_path": "github-repos/lean/alashworth-sf-lean", "path": "github-repos/lean/alashworth-sf-lean/sf-lean-bec3ef4ffbe1fcd83772570b84ac3ff074bb7476/src/imp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7203202566671251}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n-/\nimport algebra.order.absolute_value\nimport algebra.field_power\nimport ring_theory.int.basic\nimport tactic.basic\nimport tactic.ring_exp\nimport number_theory.divisors\nimport data.nat.factorization\n\n/-!\n# p-adic norm\n\nThis file defines the p-adic valuation and the p-adic norm on \u211a.\n\nThe p-adic valuation on \u211a is the difference of the multiplicities of `p` in the numerator and\ndenominator of `q`. This function obeys the standard properties of a valuation, with the appropriate\nassumptions on p.\n\nThe valuation induces a norm on \u211a. This norm is a nonarchimedean absolute value.\nIt takes values in {0} \u222a {1/p^k | k \u2208 \u2124}.\n\n## Notations\n\nThis file uses the local notation `/.` for `rat.mk`.\n\n## Implementation notes\n\nMuch, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically\nby taking `[fact (prime p)]` as a type class argument.\n\n## References\n\n* [F. Q. Gouv\u00eaa, *p-adic numbers*][gouvea1997]\n* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]\n* <https://en.wikipedia.org/wiki/P-adic_number>\n\n## Tags\n\np-adic, p adic, padic, norm, valuation\n-/\n\nuniverse u\n\nopen nat\n\nopen_locale rat\n\nopen multiplicity\n\n/--\nFor `p \u2260 1`, the p-adic valuation of an integer `z \u2260 0` is the largest natural number `n` such that\np^n divides z.\n\n`padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the\nvaluation of `q.denom`.\nIf `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to 0.\n-/\ndef padic_val_rat (p : \u2115) (q : \u211a) : \u2124 :=\nif h : q \u2260 0 \u2227 p \u2260 1\nthen (multiplicity (p : \u2124) q.num).get\n    (multiplicity.finite_int_iff.2 \u27e8h.2, rat.num_ne_zero_of_ne_zero h.1\u27e9) -\n  (multiplicity (p : \u2124) q.denom).get\n    (multiplicity.finite_int_iff.2 \u27e8h.2, by exact_mod_cast rat.denom_ne_zero _\u27e9)\nelse 0\n\n/--\nA simplification of the definition of `padic_val_rat p q` when `q \u2260 0` and `p` is prime.\n-/\nlemma padic_val_rat_def (p : \u2115) [hp : fact p.prime] {q : \u211a} (hq : q \u2260 0) : padic_val_rat p q =\n  (multiplicity (p : \u2124) q.num).get (finite_int_iff.2 \u27e8hp.1.ne_one, rat.num_ne_zero_of_ne_zero hq\u27e9) -\n  (multiplicity (p : \u2124) q.denom).get\n    (finite_int_iff.2 \u27e8hp.1.ne_one, by exact_mod_cast rat.denom_ne_zero _\u27e9) :=\ndif_pos \u27e8hq, hp.1.ne_one\u27e9\n\nnamespace padic_val_rat\nopen multiplicity\nvariables {p : \u2115}\n\n/--\n`padic_val_rat p q` is symmetric in `q`.\n-/\n@[simp] protected lemma neg (q : \u211a) : padic_val_rat p (-q) = padic_val_rat p q :=\nbegin\n  unfold padic_val_rat,\n  split_ifs,\n  { simp [-add_comm]; refl },\n  { exfalso, simp * at * },\n  { exfalso, simp * at * },\n  { refl }\nend\n\n/--\n`padic_val_rat p 0` is 0 for any `p`.\n-/\n@[simp]\nprotected lemma zero (m : nat) : padic_val_rat m 0 = 0 := rfl\n\n/--\n`padic_val_rat p 1` is 0 for any `p`.\n-/\n@[simp] protected lemma one : padic_val_rat p 1 = 0 :=\nby unfold padic_val_rat; split_ifs; simp *\n\n/--\nFor `p \u2260 0, p \u2260 1, `padic_val_rat p p` is 1.\n-/\n@[simp] lemma padic_val_rat_self (hp : 1 < p) : padic_val_rat p p = 1 :=\nby unfold padic_val_rat; split_ifs; simp [*, nat.one_lt_iff_ne_zero_and_ne_one] at *\n\n/--\nThe p-adic value of an integer `z \u2260 0` is the multiplicity of `p` in `z`.\n-/\nlemma padic_val_rat_of_int (z : \u2124) (hp : p \u2260 1) (hz : z \u2260 0) :\n  padic_val_rat p (z : \u211a) = (multiplicity (p : \u2124) z).get\n    (finite_int_iff.2 \u27e8hp, hz\u27e9) :=\nby rw [padic_val_rat, dif_pos]; simp *; refl\n\nend padic_val_rat\n\n/--\nA convenience function for the case of `padic_val_rat` when both inputs are natural numbers.\n-/\ndef padic_val_nat (p : \u2115) (n : \u2115) : \u2115 :=\nint.to_nat (padic_val_rat p n)\n\nsection padic_val_nat\n\n/--\n`padic_val_nat` is defined as an `int.to_nat` cast;\nthis lemma ensures that the cast is well-behaved.\n-/\nlemma zero_le_padic_val_rat_of_nat (p n : \u2115) : 0 \u2264 padic_val_rat p n :=\nbegin\n  unfold padic_val_rat,\n  split_ifs,\n  { simp, },\n  { trivial, },\nend\n\n/--\n`padic_val_rat` coincides with `padic_val_nat`.\n-/\n@[simp, norm_cast] lemma padic_val_rat_of_nat (p n : \u2115) :\n  \u2191(padic_val_nat p n) = padic_val_rat p n :=\nbegin\n  unfold padic_val_nat,\n  rw int.to_nat_of_nonneg (zero_le_padic_val_rat_of_nat p n),\nend\n\n/--\nA simplification of `padic_val_nat` when one input is prime, by analogy with `padic_val_rat_def`.\n-/\nlemma padic_val_nat_def {p : \u2115} [hp : fact p.prime] {n : \u2115} (hn : n \u2260 0) :\n  padic_val_nat p n =\n  (multiplicity p n).get\n    (multiplicity.finite_nat_iff.2 \u27e8nat.prime.ne_one hp.1, bot_lt_iff_ne_bot.mpr hn\u27e9) :=\nbegin\n  have n_nonzero : (n : \u211a) \u2260 0, by simpa only [cast_eq_zero, ne.def],\n  -- Infinite loop with @simp padic_val_rat_of_nat unless we restrict the available lemmas here,\n  -- hence the very long list\n  simpa only\n    [ int.coe_nat_multiplicity p n, rat.coe_nat_denom n, (padic_val_rat_of_nat p n).symm,\n      int.coe_nat_zero, int.coe_nat_inj', sub_zero, get_one_right, int.coe_nat_succ, zero_add,\n      rat.coe_nat_num ]\n    using padic_val_rat_def p n_nonzero,\nend\n\n@[simp] lemma padic_val_nat_self (p : \u2115) [fact p.prime] : padic_val_nat p p = 1 :=\nby simp [padic_val_nat_def (fact.out p.prime).ne_zero]\n\nlemma one_le_padic_val_nat_of_dvd\n  {n p : nat} [prime : fact p.prime] (nonzero : n \u2260 0) (div : p \u2223 n) :\n  1 \u2264 padic_val_nat p n :=\nbegin\n  rw @padic_val_nat_def _ prime _ nonzero,\n  let one_le_mul : _ \u2264 multiplicity p n :=\n    @multiplicity.le_multiplicity_of_pow_dvd _ _ _ p n 1 (begin norm_num, exact div end),\n  simp only [nat.cast_one] at one_le_mul,\n  rcases one_le_mul with \u27e8_, q\u27e9,\n  dsimp at q,\n  solve_by_elim,\nend\n\n@[simp]\nlemma padic_val_nat_zero (m : nat) : padic_val_nat m 0 = 0 := rfl\n\n@[simp]\nlemma padic_val_nat_one (m : nat) : padic_val_nat m 1 = 0 := by simp [padic_val_nat]\n\nend padic_val_nat\n\nnamespace padic_val_rat\nopen multiplicity\nvariables (p : \u2115) [p_prime : fact p.prime]\ninclude p_prime\n\n/--\nThe multiplicity of `p : \u2115` in `a : \u2124` is finite exactly when `a \u2260 0`.\n-/\nlemma finite_int_prime_iff {p : \u2115} [p_prime : fact p.prime] {a : \u2124} : finite (p : \u2124) a \u2194 a \u2260 0 :=\nby simp [finite_int_iff, ne.symm (ne_of_lt (p_prime.1.one_lt))]\n\n/--\nA rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`.\n-/\nprotected lemma defn {q : \u211a} {n d : \u2124} (hqz : q \u2260 0) (qdf : q = n /. d) :\n  padic_val_rat p q = (multiplicity (p : \u2124) n).get (finite_int_iff.2\n    \u27e8ne.symm $ ne_of_lt p_prime.1.one_lt, \u03bb hn, by simp * at *\u27e9) -\n  (multiplicity (p : \u2124) d).get (finite_int_iff.2 \u27e8ne.symm $ ne_of_lt p_prime.1.one_lt,\n    \u03bb hd, by simp * at *\u27e9) :=\nhave hn : n \u2260 0, from rat.mk_num_ne_zero_of_ne_zero hqz qdf,\nhave hd : d \u2260 0, from rat.mk_denom_ne_zero_of_ne_zero hqz qdf,\nlet \u27e8c, hc1, hc2\u27e9 := rat.num_denom_mk hn hd qdf in\nby rw [padic_val_rat, dif_pos];\n  simp [hc1, hc2, multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1),\n    (ne.symm (ne_of_lt p_prime.1.one_lt)), hqz]\n\n/--\nA rewrite lemma for `padic_val_rat p (q * r)` with conditions `q \u2260 0`, `r \u2260 0`.\n-/\nprotected lemma mul {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_rat p (q * r) = padic_val_rat p q + padic_val_rat p r :=\nhave q*r = (q.num * r.num) /. (\u2191q.denom * \u2191r.denom), by rw_mod_cast rat.mul_num_denom,\nhave hq' : q.num /. q.denom \u2260 0, by rw rat.num_denom; exact hq,\nhave hr' : r.num /. r.denom \u2260 0, by rw rat.num_denom; exact hr,\nhave hp' : _root_.prime (p : \u2124), from nat.prime_iff_prime_int.1 p_prime.1,\nbegin\n  rw [padic_val_rat.defn p (mul_ne_zero hq hr) this],\n  conv_rhs { rw [\u2190(@rat.num_denom q), padic_val_rat.defn p hq',\n    \u2190(@rat.num_denom r), padic_val_rat.defn p hr'] },\n  rw [multiplicity.mul' hp', multiplicity.mul' hp']; simp [add_comm, add_left_comm, sub_eq_add_neg]\nend\n\n/--\nA rewrite lemma for `padic_val_rat p (q^k)` with condition `q \u2260 0`.\n-/\nprotected lemma pow {q : \u211a} (hq : q \u2260 0) {k : \u2115} :\n    padic_val_rat p (q ^ k) = k * padic_val_rat p q :=\nby induction k; simp [*, padic_val_rat.mul _ hq (pow_ne_zero _ hq),\n  pow_succ, add_mul, add_comm]\n\n/--\nA rewrite lemma for `padic_val_rat p (q\u207b\u00b9)` with condition `q \u2260 0`.\n-/\nprotected lemma inv {q : \u211a} (hq : q \u2260 0) :\n  padic_val_rat p (q\u207b\u00b9) = -padic_val_rat p q :=\nby rw [eq_neg_iff_add_eq_zero, \u2190 padic_val_rat.mul p (inv_ne_zero hq) hq,\n    inv_mul_cancel hq, padic_val_rat.one]\n\n/--\nA rewrite lemma for `padic_val_rat p (q / r)` with conditions `q \u2260 0`, `r \u2260 0`.\n-/\nprotected lemma div {q r : \u211a} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_rat p (q / r) = padic_val_rat p q - padic_val_rat p r :=\nby rw [div_eq_mul_inv, padic_val_rat.mul p hq (inv_ne_zero hr),\n    padic_val_rat.inv p hr, sub_eq_add_neg]\n\n/--\nA condition for `padic_val_rat p (n\u2081 / d\u2081) \u2264 padic_val_rat p (n\u2082 / d\u2082),\nin terms of divisibility by `p^n`.\n-/\nlemma padic_val_rat_le_padic_val_rat_iff {n\u2081 n\u2082 d\u2081 d\u2082 : \u2124}\n  (hn\u2081 : n\u2081 \u2260 0) (hn\u2082 : n\u2082 \u2260 0) (hd\u2081 : d\u2081 \u2260 0) (hd\u2082 : d\u2082 \u2260 0) :\n  padic_val_rat p (n\u2081 /. d\u2081) \u2264 padic_val_rat p (n\u2082 /. d\u2082) \u2194\n  \u2200 (n : \u2115), \u2191p ^ n \u2223 n\u2081 * d\u2082 \u2192 \u2191p ^ n \u2223 n\u2082 * d\u2081 :=\nhave hf1 : finite (p : \u2124) (n\u2081 * d\u2082),\n  from finite_int_prime_iff.2 (mul_ne_zero hn\u2081 hd\u2082),\nhave hf2 : finite (p : \u2124) (n\u2082 * d\u2081),\n  from finite_int_prime_iff.2 (mul_ne_zero hn\u2082 hd\u2081),\n  by conv\n  { to_lhs,\n    rw [padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn\u2081 hd\u2081) rfl,\n      padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn\u2082 hd\u2082) rfl,\n      sub_le_iff_le_add',\n      \u2190 add_sub_assoc,\n      le_sub_iff_add_le],\n    norm_cast,\n    rw [\u2190 multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf1, add_comm,\n      \u2190 multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf2,\n      enat.get_le_get, multiplicity_le_multiplicity_iff] }\n\n/--\nSufficient conditions to show that the p-adic valuation of `q` is less than or equal to the\np-adic vlauation of `q + r`.\n-/\ntheorem le_padic_val_rat_add_of_le {q r : \u211a}\n  (hqr : q + r \u2260 0)\n  (h : padic_val_rat p q \u2264 padic_val_rat p r) :\n  padic_val_rat p q \u2264 padic_val_rat p (q + r) :=\nif hq : q = 0 then by simpa [hq] using h else\nif hr : r = 0 then by simp [hr] else\nhave hqn : q.num \u2260 0, from rat.num_ne_zero_of_ne_zero hq,\nhave hqd : (q.denom : \u2124) \u2260 0, by exact_mod_cast rat.denom_ne_zero _,\nhave hrn : r.num \u2260 0, from rat.num_ne_zero_of_ne_zero hr,\nhave hrd : (r.denom : \u2124) \u2260 0, by exact_mod_cast rat.denom_ne_zero _,\nhave hqreq : q + r = (((q.num * r.denom + q.denom * r.num : \u2124)) /. (\u2191q.denom * \u2191r.denom : \u2124)),\n  from rat.add_num_denom _ _,\nhave hqrd : q.num * \u2191(r.denom) + \u2191(q.denom) * r.num \u2260 0,\n  from rat.mk_num_ne_zero_of_ne_zero hqr hqreq,\nbegin\n  conv_lhs { rw \u2190(@rat.num_denom q) },\n  rw [hqreq, padic_val_rat_le_padic_val_rat_iff p hqn hqrd hqd (mul_ne_zero hqd hrd),\n    \u2190 multiplicity_le_multiplicity_iff, mul_left_comm,\n    multiplicity.mul (nat.prime_iff_prime_int.1 p_prime.1), add_mul],\n  rw [\u2190(@rat.num_denom q), \u2190(@rat.num_denom r),\n    padic_val_rat_le_padic_val_rat_iff p hqn hrn hqd hrd, \u2190 multiplicity_le_multiplicity_iff] at h,\n  calc _ \u2264 min (multiplicity \u2191p (q.num * \u2191(r.denom) * \u2191(q.denom)))\n    (multiplicity \u2191p (\u2191(q.denom) * r.num * \u2191(q.denom))) : (le_min\n    (by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (nat.prime_iff_prime_int.1 p_prime.1), add_comm])\n    (by rw [mul_assoc, @multiplicity.mul _ _ _ _ (q.denom : \u2124)\n        (_ * _) (nat.prime_iff_prime_int.1 p_prime.1)];\n      exact add_le_add_left h _))\n    ... \u2264 _ : min_le_multiplicity_add\nend\n\n/--\nThe minimum of the valuations of `q` and `r` is less than or equal to the valuation of `q + r`.\n-/\ntheorem min_le_padic_val_rat_add {q r : \u211a} (hqr : q + r \u2260 0) :\n  min (padic_val_rat p q) (padic_val_rat p r) \u2264 padic_val_rat p (q + r) :=\n(le_total (padic_val_rat p q) (padic_val_rat p r)).elim\n  (\u03bb h, by rw [min_eq_left h]; exact le_padic_val_rat_add_of_le _ hqr h)\n  (\u03bb h, by rw [min_eq_right h, add_comm]; exact le_padic_val_rat_add_of_le _\n    (by rwa add_comm) h)\n\nopen_locale big_operators\n\n/-- A finite sum of rationals with positive p-adic valuation has positive p-adic valuation\n  (if the sum is non-zero). -/\ntheorem sum_pos_of_pos {n : \u2115} {F : \u2115 \u2192 \u211a}\n  (hF : \u2200 i, i < n \u2192 0 < padic_val_rat p (F i)) (hn0 : \u2211 i in finset.range n, F i \u2260 0) :\n  0 < padic_val_rat p (\u2211 i in finset.range n, F i) :=\nbegin\n  induction n with d hd,\n  { exact false.elim (hn0 rfl) },\n  { rw finset.sum_range_succ at hn0 \u22a2,\n    by_cases h : \u2211 (x : \u2115) in finset.range d, F x = 0,\n    { rw [h, zero_add],\n      exact hF d (lt_add_one _) },\n    { refine lt_of_lt_of_le _ (min_le_padic_val_rat_add p hn0),\n      { refine lt_min (hd (\u03bb i hi, _) h) (hF d (lt_add_one _)),\n        exact hF _ (lt_trans hi (lt_add_one _)) }, } }\nend\n\nend padic_val_rat\n\nnamespace padic_val_nat\n\n/--\nA rewrite lemma for `padic_val_nat p (q * r)` with conditions `q \u2260 0`, `r \u2260 0`.\n-/\nprotected lemma mul (p : \u2115) [p_prime : fact p.prime] {q r : \u2115} (hq : q \u2260 0) (hr : r \u2260 0) :\n  padic_val_nat p (q * r) = padic_val_nat p q + padic_val_nat p r :=\nbegin\n  apply int.coe_nat_inj,\n  simp only [padic_val_rat_of_nat, nat.cast_mul],\n  rw padic_val_rat.mul,\n  norm_cast,\n  exact cast_ne_zero.mpr hq,\n  exact cast_ne_zero.mpr hr,\nend\n\nprotected lemma div_of_dvd (p : \u2115) [hp : fact p.prime] {a b : \u2115} (h : b \u2223 a) :\n  padic_val_nat p (a / b) = padic_val_nat p a - padic_val_nat p b :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simp },\n  obtain \u27e8k, rfl\u27e9 := h,\n  obtain \u27e8hb, hk\u27e9 := mul_ne_zero_iff.mp ha,\n  rw [mul_comm, k.mul_div_cancel hb.bot_lt, padic_val_nat.mul p hk hb, nat.add_sub_cancel]\nend\n\n/--\nDividing out by a prime factor reduces the padic_val_nat by 1.\n-/\nprotected lemma div {p : \u2115} [p_prime : fact p.prime] {b : \u2115} (dvd : p \u2223 b) :\n  (padic_val_nat p (b / p)) = (padic_val_nat p b) - 1 :=\nbegin\n  convert padic_val_nat.div_of_dvd p dvd,\n  rw padic_val_nat_self p\nend\n\n/-- A version of `padic_val_rat.pow` for `padic_val_nat` -/\nprotected lemma pow (p q n : \u2115) [fact p.prime] (hq : q \u2260 0) :\n  padic_val_nat p (q ^ n) = n * padic_val_nat p q :=\nbegin\n  apply @nat.cast_injective \u2124,\n  push_cast,\n  exact padic_val_rat.pow _ (cast_ne_zero.mpr hq),\nend\n\n@[simp] protected lemma prime_pow (p n : \u2115) [fact p.prime] : padic_val_nat p (p ^ n) = n :=\nby rw [padic_val_nat.pow p _ _ (fact.out p.prime).ne_zero, padic_val_nat_self p, mul_one]\n\nprotected lemma div_pow {p : \u2115} [p_prime : fact p.prime] {b k : \u2115} (dvd : p ^ k \u2223 b) :\n  (padic_val_nat p (b / p ^ k)) = (padic_val_nat p b) - k :=\nbegin\n  convert padic_val_nat.div_of_dvd p dvd,\n  rw padic_val_nat.prime_pow\nend\n\nend padic_val_nat\n\nsection padic_val_nat\n\n/--\nIf a prime doesn't appear in `n`, `padic_val_nat p n` is `0`.\n-/\nlemma padic_val_nat_of_not_dvd {p : \u2115} [fact p.prime] {n : \u2115} (not_dvd : \u00ac(p \u2223 n)) :\n  padic_val_nat p n = 0 :=\nbegin\n  by_cases hn : n = 0,\n  { subst hn, simp at not_dvd, trivial, },\n  { rw padic_val_nat_def hn,\n    exact (@multiplicity.unique' _ _ _ p n 0 (by simp) (by simpa using not_dvd)).symm,\n    assumption, },\nend\n\nlemma dvd_of_one_le_padic_val_nat {n p : nat} [prime : fact p.prime] (hp : 1 \u2264 padic_val_nat p n) :\n  p \u2223 n :=\nbegin\n  by_contra h,\n  rw padic_val_nat_of_not_dvd h at hp,\n  exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp),\nend\n\nlemma pow_padic_val_nat_dvd {p n : \u2115} [fact (nat.prime p)] : p ^ (padic_val_nat p n) \u2223 n :=\nbegin\n  cases nat.eq_zero_or_pos n with hn hn,\n  { rw hn, exact dvd_zero (p ^ padic_val_nat p 0) },\n  { rw multiplicity.pow_dvd_iff_le_multiplicity,\n    apply le_of_eq,\n    rw padic_val_nat_def (ne_of_gt hn),\n    { apply enat.coe_get },\n    { apply_instance } }\nend\n\nlemma pow_succ_padic_val_nat_not_dvd {p n : \u2115} [hp : fact (nat.prime p)] (hn : 0 < n) :\n  \u00ac p ^ (padic_val_nat p n + 1) \u2223 n :=\nbegin\n  rw multiplicity.pow_dvd_iff_le_multiplicity,\n  rw padic_val_nat_def (ne_of_gt hn),\n  { rw [nat.cast_add, enat.coe_get],\n    simp only [nat.cast_one, not_le],\n    apply enat.lt_add_one (ne_top_iff_finite.2 (finite_nat_iff.2 \u27e8hp.elim.ne_one, hn\u27e9)) },\n  { apply_instance }\nend\n\nlemma padic_val_nat_primes {p q : \u2115} [p_prime : fact p.prime] [q_prime : fact q.prime]\n  (neq : p \u2260 q) : padic_val_nat p q = 0 :=\n@padic_val_nat_of_not_dvd p p_prime q $\n(not_congr (iff.symm (prime_dvd_prime_iff_eq p_prime.1 q_prime.1))).mp neq\n\nprotected lemma padic_val_nat.div' {p : \u2115} [p_prime : fact p.prime] :\n  \u2200 {m : \u2115} (cpm : coprime p m) {b : \u2115} (dvd : m \u2223 b), padic_val_nat p (b / m) = padic_val_nat p b\n| 0 := \u03bb cpm b dvd, by { rw zero_dvd_iff at dvd, rw [dvd, nat.zero_div], }\n| (n + 1) :=\n  \u03bb cpm b dvd,\n  begin\n    rcases dvd with \u27e8c, rfl\u27e9,\n    rw [mul_div_right c (nat.succ_pos _)],by_cases hc : c = 0,\n    { rw [hc, mul_zero] },\n    { rw padic_val_nat.mul,\n      { suffices : \u00ac p \u2223 (n+1),\n        { rw [padic_val_nat_of_not_dvd this, zero_add] },\n        contrapose! cpm,\n        exact p_prime.1.dvd_iff_not_coprime.mp cpm },\n      { exact nat.succ_ne_zero _ },\n      { exact hc } },\n  end\n\nlemma padic_val_nat_eq_factorization (p n : \u2115) [hp : fact p.prime] :\n  padic_val_nat p n = n.factorization p :=\nbegin\n  by_cases hn : n = 0, { subst hn, simp },\n  rw @padic_val_nat_def p _ n hn,\n  simp [@multiplicity_eq_factorization n p hp.elim hn],\nend\n\nopen_locale big_operators\n\nlemma prod_pow_prime_padic_val_nat (n : nat) (hn : n \u2260 0) (m : nat) (pr : n < m) :\n  \u220f p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n :=\nbegin\n  nth_rewrite_rhs 0 \u2190factorization_prod_pow_eq_self hn,\n  rw eq_comm,\n  apply finset.prod_subset_one_on_sdiff,\n  { exact \u03bb p hp, finset.mem_filter.mpr\n      \u27e8finset.mem_range.mpr (gt_of_gt_of_ge pr (le_of_mem_factorization hp)),\n       prime_of_mem_factorization hp\u27e9 },\n  { intros p hp,\n    cases finset.mem_sdiff.mp hp with hp1 hp2,\n    haveI := fact_iff.mpr (finset.mem_filter.mp hp1).2,\n    rw padic_val_nat_eq_factorization p n,\n    simp [finsupp.not_mem_support_iff.mp hp2] },\n  { intros p hp,\n    haveI := fact_iff.mpr (prime_of_mem_factorization hp),\n    simp [padic_val_nat_eq_factorization] }\nend\n\nlemma range_pow_padic_val_nat_subset_divisors {n : \u2115} (p : \u2115) [fact p.prime] (hn : n \u2260 0) :\n  (finset.range (padic_val_nat p n + 1)).image (pow p) \u2286 n.divisors :=\nbegin\n  intros t ht,\n  simp only [exists_prop, finset.mem_image, finset.mem_range] at ht,\n  obtain \u27e8k, hk, rfl\u27e9 := ht,\n  rw nat.mem_divisors,\n  exact \u27e8(pow_dvd_pow p $ by linarith).trans pow_padic_val_nat_dvd, hn\u27e9\nend\n\nlemma range_pow_padic_val_nat_subset_divisors' {n : \u2115} (p : \u2115) [h : fact p.prime] :\n  (finset.range (padic_val_nat p n)).image (\u03bb t, p ^ (t + 1)) \u2286 (n.divisors \\ {1}) :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  intros t ht,\n  simp only [exists_prop, finset.mem_image, finset.mem_range] at ht,\n  obtain \u27e8k, hk, rfl\u27e9 := ht,\n  rw [finset.mem_sdiff, nat.mem_divisors],\n  refine \u27e8\u27e8(pow_dvd_pow p $ by linarith).trans pow_padic_val_nat_dvd, hn\u27e9, _\u27e9,\n  rw [finset.mem_singleton],\n  nth_rewrite 1 \u2190one_pow (k + 1),\n  exact (nat.pow_lt_pow_of_lt_left h.1.one_lt $ nat.succ_pos k).ne',\nend\n\nend padic_val_nat\n\n/--\nIf `q \u2260 0`, the p-adic norm of a rational `q` is `p ^ (-(padic_val_rat p q))`.\nIf `q = 0`, the p-adic norm of `q` is 0.\n-/\ndef padic_norm (p : \u2115) (q : \u211a) : \u211a :=\nif q = 0 then 0 else (\u2191p : \u211a) ^ (-(padic_val_rat p q))\n\nnamespace padic_norm\n\nsection padic_norm\nopen padic_val_rat\nvariables (p : \u2115)\n\n/--\nUnfolds the definition of the p-adic norm of `q` when `q \u2260 0`.\n-/\n@[simp] protected lemma eq_zpow_of_nonzero {q : \u211a} (hq : q \u2260 0) :\n  padic_norm p q = p ^ (-(padic_val_rat p q)) :=\nby simp [hq, padic_norm]\n\n/--\nThe p-adic norm is nonnegative.\n-/\nprotected lemma nonneg (q : \u211a) : 0 \u2264 padic_norm p q :=\nif hq : q = 0 then by simp [hq, padic_norm]\nelse\n  begin\n    unfold padic_norm; split_ifs,\n    apply zpow_nonneg,\n    exact_mod_cast nat.zero_le _\n  end\n\n/--\nThe p-adic norm of 0 is 0.\n-/\n@[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm]\n\n/--\nThe p-adic norm of 1 is 1.\n-/\n@[simp] protected lemma one : padic_norm p 1 = 1 := by simp [padic_norm]\n\n/--\nThe p-adic norm of `p` is `1/p` if `p > 1`.\n\nSee also `padic_norm.padic_norm_p_of_prime` for a version that assumes `p` is prime.\n-/\nlemma padic_norm_p {p : \u2115} (hp : 1 < p) : padic_norm p p = 1 / p :=\nby simp [padic_norm, (show p \u2260 0, by linarith), padic_val_rat.padic_val_rat_self hp]\n\n/--\nThe p-adic norm of `p` is `1/p` if `p` is prime.\n\nSee also `padic_norm.padic_norm_p` for a version that assumes `1 < p`.\n-/\n@[simp] lemma padic_norm_p_of_prime (p : \u2115) [fact p.prime] : padic_norm p p = 1 / p :=\npadic_norm_p $ nat.prime.one_lt (fact.out _)\n\n/-- The p-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/\nlemma padic_norm_of_prime_of_ne {p q : \u2115} [p_prime : fact p.prime] [q_prime : fact q.prime]\n  (neq : p \u2260 q) : padic_norm p q = 1 :=\nbegin\n  have p : padic_val_rat p q = 0,\n  { exact_mod_cast @padic_val_nat_primes p q p_prime q_prime neq },\n  simp [padic_norm, p, q_prime.1.1, q_prime.1.ne_zero],\nend\n\n/--\nThe p-adic norm of `p` is less than 1 if `1 < p`.\n\nSee also `padic_norm.padic_norm_p_lt_one_of_prime` for a version assuming `prime p`.\n-/\nlemma padic_norm_p_lt_one {p : \u2115} (hp : 1 < p) : padic_norm p p < 1 :=\nbegin\n  rw [padic_norm_p hp, div_lt_iff, one_mul],\n  { exact_mod_cast hp },\n  { exact_mod_cast zero_lt_one.trans hp },\nend\n\n/--\nThe p-adic norm of `p` is less than 1 if `p` is prime.\n\nSee also `padic_norm.padic_norm_p_lt_one` for a version assuming `1 < p`.\n-/\nlemma padic_norm_p_lt_one_of_prime (p : \u2115) [fact p.prime] : padic_norm p p < 1 :=\npadic_norm_p_lt_one $ nat.prime.one_lt (fact.out _)\n\n/--\n`padic_norm p q` takes discrete values `p ^ -z` for `z : \u2124`.\n-/\nprotected theorem values_discrete {q : \u211a} (hq : q \u2260 0) : \u2203 z : \u2124, padic_norm p q = p ^ (-z) :=\n\u27e8 (padic_val_rat p q), by simp [padic_norm, hq] \u27e9\n\n/--\n`padic_norm p` is symmetric.\n-/\n@[simp] protected lemma neg (q : \u211a) : padic_norm p (-q) = padic_norm p q :=\nif hq : q = 0 then by simp [hq]\nelse by simp [padic_norm, hq]\n\nvariable [hp : fact p.prime]\ninclude hp\n\n/--\nIf `q \u2260 0`, then `padic_norm p q \u2260 0`.\n-/\nprotected lemma nonzero {q : \u211a} (hq : q \u2260 0) : padic_norm p q \u2260 0 :=\nbegin\n  rw padic_norm.eq_zpow_of_nonzero p hq,\n  apply zpow_ne_zero_of_ne_zero,\n  exact_mod_cast ne_of_gt hp.1.pos\nend\n\n/--\nIf the p-adic norm of `q` is 0, then `q` is 0.\n-/\nlemma zero_of_padic_norm_eq_zero {q : \u211a} (h : padic_norm p q = 0) : q = 0 :=\nbegin\n  apply by_contradiction, intro hq,\n  unfold padic_norm at h, rw if_neg hq at h,\n  apply absurd h,\n  apply zpow_ne_zero_of_ne_zero,\n  exact_mod_cast hp.1.ne_zero\nend\n\n/--\nThe p-adic norm is multiplicative.\n-/\n@[simp] protected theorem mul (q r : \u211a) : padic_norm p (q*r) = padic_norm p q * padic_norm p r :=\nif hq : q = 0 then\n  by simp [hq]\nelse if hr : r = 0 then\n  by simp [hr]\nelse\n  have q*r \u2260 0, from mul_ne_zero hq hr,\n  have (\u2191p : \u211a) \u2260 0, by simp [hp.1.ne_zero],\n  by simp [padic_norm, *, padic_val_rat.mul, zpow_add\u2080 this, mul_comm]\n\n/--\nThe p-adic norm respects division.\n-/\n@[simp] protected theorem div (q r : \u211a) : padic_norm p (q / r) = padic_norm p q / padic_norm p r :=\nif hr : r = 0 then by simp [hr] else\neq_div_of_mul_eq (padic_norm.nonzero _ hr) (by rw [\u2190padic_norm.mul, div_mul_cancel _ hr])\n\n/--\nThe p-adic norm of an integer is at most 1.\n-/\nprotected theorem of_int (z : \u2124) : padic_norm p \u2191z \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one] else\nbegin\n  unfold padic_norm,\n  rw [if_neg _],\n  { refine zpow_le_one_of_nonpos _ _,\n    { exact_mod_cast le_of_lt hp.1.one_lt, },\n    { rw [padic_val_rat_of_int _ hp.1.ne_one hz, neg_nonpos],\n      norm_cast, simp }},\n  exact_mod_cast hz\nend\n\nprivate lemma nonarchimedean_aux {q r : \u211a} (h : padic_val_rat p q \u2264 padic_val_rat p r) :\n  padic_norm p (q + r) \u2264 max (padic_norm p q) (padic_norm p r) :=\nhave hnqp : padic_norm p q \u2265 0, from padic_norm.nonneg _ _,\nhave hnrp : padic_norm p r \u2265 0, from padic_norm.nonneg _ _,\nif hq : q = 0 then\n  by simp [hq, max_eq_right hnrp, le_max_right]\nelse if hr : r = 0 then\n  by simp [hr, max_eq_left hnqp, le_max_left]\nelse if hqr : q + r = 0 then\n  le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)\nelse\n  begin\n    unfold padic_norm, split_ifs,\n    apply le_max_iff.2,\n    left,\n    apply zpow_le_of_le,\n    { exact_mod_cast le_of_lt hp.1.one_lt },\n    { apply neg_le_neg,\n      have : padic_val_rat p q =\n              min (padic_val_rat p q) (padic_val_rat p r),\n        from (min_eq_left h).symm,\n      rw this,\n      apply min_le_padic_val_rat_add; assumption }\n  end\n\n/--\nThe p-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p` and\nthe norm of `q`.\n-/\nprotected theorem nonarchimedean {q r : \u211a} :\n  padic_norm p (q + r) \u2264 max (padic_norm p q) (padic_norm p r) :=\nbegin\n    wlog hle := le_total (padic_val_rat p q) (padic_val_rat p r) using [q r],\n    exact nonarchimedean_aux p hle\nend\n\n/--\nThe p-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of `p`\nplus the norm of `q`.\n-/\ntheorem triangle_ineq (q r : \u211a) : padic_norm p (q + r) \u2264 padic_norm p q + padic_norm p r :=\ncalc padic_norm p (q + r) \u2264 max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean p\n                       ... \u2264 padic_norm p q + padic_norm p r :\n                         max_le_add_of_nonneg (padic_norm.nonneg p _) (padic_norm.nonneg p _)\n\n/--\nThe p-adic norm of a difference is at most the max of each component. Restates the archimedean\nproperty of the p-adic norm.\n-/\nprotected theorem sub {q r : \u211a} : padic_norm p (q - r) \u2264 max (padic_norm p q) (padic_norm p r) :=\nby rw [sub_eq_add_neg, \u2190padic_norm.neg p r]; apply padic_norm.nonarchimedean\n\n/--\nIf the p-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max of\nthe norms of `q` and `r`.\n-/\nlemma add_eq_max_of_ne {q r : \u211a} (hne : padic_norm p q \u2260 padic_norm p r) :\n  padic_norm p (q + r) = max (padic_norm p q) (padic_norm p r) :=\nbegin\n  wlog hle := le_total (padic_norm p r) (padic_norm p q) using [q r],\n  have hlt : padic_norm p r < padic_norm p q, from lt_of_le_of_ne hle hne.symm,\n  have : padic_norm p q \u2264 max (padic_norm p (q + r)) (padic_norm p r), from calc\n   padic_norm p q = padic_norm p (q + r - r) : by congr; ring\n               ... \u2264 max (padic_norm p (q + r)) (padic_norm p (-r)) : padic_norm.nonarchimedean p\n               ... = max (padic_norm p (q + r)) (padic_norm p r) : by simp,\n  have hnge : padic_norm p r \u2264 padic_norm p (q + r),\n  { apply le_of_not_gt,\n    intro hgt,\n    rw max_eq_right_of_lt hgt at this,\n    apply not_lt_of_ge this,\n    assumption },\n  have : padic_norm p q \u2264 padic_norm p (q + r), by rwa [max_eq_left hnge] at this,\n  apply _root_.le_antisymm,\n  { apply padic_norm.nonarchimedean p },\n  { rw max_eq_left_of_lt hlt,\n    assumption }\nend\n\n/--\nThe p-adic norm is an absolute value: positive-definite and multiplicative, satisfying the triangle\ninequality.\n-/\ninstance : is_absolute_value (padic_norm p) :=\n{ abv_nonneg := padic_norm.nonneg p,\n  abv_eq_zero :=\n    begin\n      intros,\n      constructor; intro,\n      { apply zero_of_padic_norm_eq_zero p, assumption },\n      { simp [*] }\n    end,\n  abv_add := padic_norm.triangle_ineq p,\n  abv_mul := padic_norm.mul p }\n\nvariable {p}\n\nlemma dvd_iff_norm_le {n : \u2115} {z : \u2124} : \u2191(p^n) \u2223 z \u2194 padic_norm p z \u2264 \u2191p ^ (-n : \u2124) :=\nbegin\n  unfold padic_norm, split_ifs with hz,\n  { norm_cast at hz,\n    have : 0 \u2264 (p^n : \u211a), {apply pow_nonneg, exact_mod_cast le_of_lt hp.1.pos },\n    simp [hz, this] },\n  { rw [zpow_le_iff_le, neg_le_neg_iff, padic_val_rat_of_int _ hp.1.ne_one _],\n    { norm_cast,\n      rw [\u2190 enat.coe_le_coe, enat.coe_get, \u2190 multiplicity.pow_dvd_iff_le_multiplicity],\n      simp },\n    { exact_mod_cast hz },\n    { exact_mod_cast hp.1.one_lt } }\nend\n\nend padic_norm\nend padic_norm\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/number_theory/padics/padic_norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7203202529524286}}
{"text": "universes u v \n\nnamespace function\n\nopen classical\n\ndef inverse {X : Type u} {Y : Type v} (g : Y \u2192 X) (f : X \u2192 Y) := (f \u2218 g = id) \u2227 (g \u2218 f = id)\n\nsection\n\nlocal attribute [instance, priority 10] classical.prop_decidable\n\ntheorem injective_has_left_inverse {X :Type u} [inhabited X] {Y : Type v}  {f : X \u2192 Y} \n  : injective f \u2192 has_left_inverse f :=\nbegin\n  intro hf,\n  let g := \u03bb y : Y, if h : \u2203 x, f x = y then some h else default,\n  let hg  :  \u03a0 ( y : Y) ( h : \u2203 x, f x = y), f (g y) = y,\n    intros y hy,\n    simp [g,dif_pos hy,some_spec hy],\n  existsi g,\n  intro x,\n  apply hf,\n  apply hg,\n  exact \u27e8x,rfl\u27e9,\nend\n\nend\n\ntheorem surjective_has_right_inverse {X : Type u} {Y : Type v} {f : X \u2192 Y}\n  : surjective f \u2192 has_right_inverse f :=\nbegin\n  intro hf,\n  let g := \u03bb y, some (hf y),\n  let hg : \u2200 y : Y , f (g y) = y := \u03bb y, some_spec(hf y),\n  existsi g,\n  apply hg,\nend\n\ntheorem left_inverse_equals_right_inverse {X : Type u} {Y : Type v} {f : X \u2192 Y} \n  : \u2200 g\u2081 g\u2082 : Y \u2192 X, right_inverse g\u2081 f \u2192 left_inverse g\u2082 f \u2192 g\u2081 = g\u2082 :=\nbegin\n  intros g\u2081 g\u2082 hg\u2081 hg\u2082,\n  apply funext,\n  intro y,\n  exact calc g\u2081 y = g\u2082 (f (g\u2081 y)) : by rw hg\u2082\n              ... = g\u2082 y          : by rw hg\u2081,\nend\n\ntheorem bijection_has_inverse {X: Type u} {Y : Type v} [inhabited X] {f : X \u2192 Y}\n  : bijective f \u2192 \u2203 g : Y \u2192 X, inverse g f :=\nbegin\n  intro hf,\n  cases hf with finj fsur,\n  cases injective_has_left_inverse finj with g\u2082 hg\u2082,\n  cases surjective_has_right_inverse fsur with g\u2081 hg\u2081,\n  have hrw : g\u2081 = g\u2082,\n    apply left_inverse_equals_right_inverse,\n    exact hg\u2081,\n    exact hg\u2082,\n  existsi g\u2081,\n  split,\n  apply funext,\n  apply hg\u2081,\n  rw hrw,\n  apply funext,\n  apply hg\u2082,\nend\n\ntheorem inverse.injective {X: Type u} {Y : Type v} {f : X \u2192 Y} {g : Y \u2192 X} \n  : inverse g f \u2192 injective f :=\nbegin\n  intro h,\n  cases h with h\u2081 h\u2082,\n  apply left_inverse.injective,\n  have gli : left_inverse g f,\n    intro y,\n    rw [\u2190 comp_app g f, h\u2082],\n    refl,\n  exact gli, \nend\n\nend function", "meta": {"author": "CameronTorrance", "repo": "Schemes", "sha": "f407ce80b8407101231170680b03b55984c42496", "save_path": "github-repos/lean/CameronTorrance-Schemes", "path": "github-repos/lean/CameronTorrance-Schemes/Schemes-f407ce80b8407101231170680b03b55984c42496/src/misc/function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7203202522448408}}
{"text": "theorem le_antisymm (a b : mynat) (hab : a \u2264 b) (hba : b \u2264 a) : a = b :=\nbegin\ncases hab with c hc,\ncases hba with d hd,\nrw hd at hc,\nsymmetry at hc,\nrw add_assoc at hc,\nhave s := eq_zero_of_add_right_eq_self hc,\nhave t := add_right_eq_zero s,\nrw t at hd,\nexact hd,\nend\n", "meta": {"author": "chanha-park", "repo": "naturalNumberGame", "sha": "4e0d7100ce4575e1add92feefa38b1250431b879", "save_path": "github-repos/lean/chanha-park-naturalNumberGame", "path": "github-repos/lean/chanha-park-naturalNumberGame/naturalNumberGame-4e0d7100ce4575e1add92feefa38b1250431b879/Inequality/6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7203151846142759}}
{"text": "import neater_proof.ideal_definitions\nimport neater_proof.ring_finite_sums\n\nlocal infixr ` + ` : 80 := plus\nlocal infixr ` * ` : 80 := mult\n\n/-- Definitions and lemmas we will need for proving that the Ideals of a Ring form a Semi-Ring -/\n\ndef Ideal_one {R : Ring} : Ideal R :=\n{ I := \u03bb x, true, -- every element of the ring is in this ideal\n  ideal_axioms :=\n  begin\n   unfold set.mem,\n   simp,\n   cc,\n  end\n}\n\ndef Ideal_zero {R : Ring} : Ideal R :=\n{ I := {x | x = zero}, -- this ideal has only one element, zero\n  ideal_axioms :=\n  begin\n   unfold set.mem,\n   split,\n   { split,\n     { exact rfl, },\n     { split,\n       { intros x y hx hy,\n         calc\n          x + y = zero : by { cases hx, cases hy, exact zero_plus_neutral zero },\n        },\n        { intros x x' hxx' hx,\n          apply plus_inv_unique zero,\n          cases hx,\n          split,\n          { exact hxx', },\n          { exact zero_plus_neutral zero, }, }, }, },\n     { split,\n       { intros x y hx,\n         cases hx, \n         exact zero_annihilates_left y, },\n       { intros x y hx,\n         cases hx,\n         exact zero_annihilates_right y, }, },\n  end /- should i have done more calcs in here? -/ }\n\n/- Apparently i found this saved some work in full_proof, using the \u2208 symbol in the type\n   specification meant that the system couldn't follow what the implicit Ring was  -/\nlemma Ideal_zero_mems_are_zero {R : Ring} : \u2200 x : R.R, Ideal_zero.I x \u2192 x = zero :=\nbegin\n intros x hx,\n exact hx,\nend\n\n-- more or less: the total intersection of all members of a set of ideals is also an ideal \ndef min_ideal {R : Ring} (IS : set (Ideal R)) : Ideal R :=\n{ I := {x | \u2200 (Id : Ideal R), Id \u2208 IS \u2192 x \u2208 Id.I},\n  ideal_axioms :=\n  begin\n   split,\n   { split,\n     { intros Id hId,\n       exact zero_mem_Ideal Id, },\n     { split,\n       { intros x y hx hy Id hId,\n         specialize hx Id hId,\n         specialize hy Id hId,\n         exact (subgroup_under_addition Id).2.1 x y hx hy, },\n       { intros x x' hxx' hx Id hId,\n         specialize hx Id hId,\n         exact (subgroup_under_addition Id).2.2 x x' hxx' hx }, }, },\n   { split,\n     { intros x y hx Id hId,\n       specialize hx Id hId,\n       exact (multiplication_conditions Id).1 x y hx, },\n     { intros x y hx Id hId,\n       specialize hx Id hId, \n       exact (multiplication_conditions Id).2 x y hx, }, },\n  end }\n\n-- the set of all ideals that contain (left) products of elements of two given ideals\ndef mult_set {R : Ring} (I I' : Ideal R) : set (Ideal R) :=\n{Id | \u2200 x y : R.R, x \u2208 I.I \u2192 y \u2208 I'.I \u2192 x * y \u2208 Id.I}\n\n/-- Ideals are always in their own mult sets -/\n\nlemma mult_set_self_left {R : Ring} (I : Ideal R) : \u2200 I' : Ideal R, I \u2208 mult_set I I' :=\nbegin\n intros I' x y hx hy,\n exact (multiplication_conditions I).1 x y hx,\nend\n\nlemma mult_set_self_right {R : Ring} (I : Ideal R) : \u2200 I' : Ideal R, I \u2208 mult_set I' I :=\nbegin\n intros I' x y hx hy,\n exact (multiplication_conditions I).2 y x hy\nend\n\n/- Here is where we begin to make use of the finite sum file -/\n\n-- gives a sufficient condition for the value of a finite sum to be in an Ideal\nlemma fin_sum_member_condition {R : Ring} (I : Ideal R) (f : \u2115 \u2192 R.R) (m : \u2115) :\n(\u2200 n : \u2115, f n \u2208 I.I) \u2192 fin_sum f m \u2208 I.I :=\nbegin\n intro hn,\n induction m with m indh,\n { specialize hn 0,\n   exact hn, },\n { rw fin_sum,\n   apply (subgroup_under_addition I).2.1, -- if two elements are in an ideal, their sum is as well\n   { exact hn (nat.succ m), },\n   { exact indh }, },\nend\n\n-- the set of finite sums of multiples of elements of a nonempty subset of a Ring forms an Ideal\ndef fin_sum_ideal {R : Ring} (X : set R.R) (H : \u2203 x : R.R, x \u2208 X) : Ideal R :=\n{ I := {p | \u2203 n : \u2115, \u2203 f : \u2115 \u2192 R.R, \n            p = fin_sum f n \u2227 \u2200 n : \u2115, \u2203 x \u2208 X, \u2203 y z : R.R, f n = y * x * z},\n  ideal_axioms :=\n  begin\n   unfold set.mem,\n   split,\n   { split,\n     { existsi 0,\n       existsi \u03bb n, zero,\n       split,\n       { exact rfl, },\n       { intro n,\n         cases H with x hx,\n         existsi x,\n         existsi hx, \n         existsi zero,\n         existsi zero,\n         symmetry,\n         calc\n          zero * x * zero = zero : by { rw zero_annihilates_right, rw zero_annihilates_left },\n       }, },\n     { split,\n       { intros x y hx hy,\n         cases hx with nx hx,\n         cases hx with fx hx,\n         cases hx with eqx hx,\n         cases hy with ny hy,\n         cases hy with fy hy,\n         cases hy with eqy hy,\n         existsi nat.succ (nat.add nx ny),\n         existsi add_fun nx fx fy,\n         split,\n         { calc\n            x + y = (fin_sum fx nx) + fin_sum fy ny : by { rw eqx, rw eqy }\n              ... = (fin_sum_sum nx fx fy) (nat.succ (nat.add nx ny)) \n                                                    : by rw \u2190 add_fin_sum.sum_is_sum\n              ... = fin_sum (add_fun nx fx fy) (nat.succ (nat.add nx ny)) \n                                                    : by { symmetry, \n                                                           exact add_fin_sum.add_fin_sum nx fx fy\n                                                                  (nat.succ (nat.add nx ny)) }, \n         },\n         {intro n,\n          induction n with n indh,\n          { specialize hx 0,\n            exact hx, },\n          { have dec := lt_decidable nx n,\n            have h : add_fun nx fx fy (nat.succ n) = ite (n < nx) (fx (nat.succ n))\n                                                         (fy (nat.succ n - nat.succ nx)),\n            { exact rfl, },\n            cases dec,\n            { specialize hx (nat.succ n),\n              cases hx with x' hx,\n              cases hx with hx' hx,\n              cases hx with xl hx,\n              cases hx with xr hx,\n              existsi x',\n              existsi hx',\n              existsi xl,\n              existsi xr,\n              calc\n               add_fun nx fx fy (nat.succ n) = fx (nat.succ n) : by simp [h, dec]\n                                         ... = xl * x' * xr    : by exact hx, },\n            { specialize hy (nat.succ n - nat.succ nx),\n              have h' : add_fun nx fx fy (nat.succ n) = fy (nat.succ n - nat.succ nx),\n              { simp [h, dec] },\n              rw h',\n              exact hy, -- these last two blocks essentially shows two different methods for\n                        -- arriving at the same result: that the terms of the sum of finite sums\n                        -- of multiples of elements of X are multiples of elements of X\n                        -- themselves, one might be clearer, the other is definitely shorter\n            }, }, }, },\n       { intros x x' hxx' hx,\n         cases hx with nx hx,\n         cases hx with fx hx,\n         cases hx with eqx hx,\n         have n_one : \u2203 neg_one : R.R, one + neg_one = zero,\n         { exact plus_inv one, },\n         cases n_one with neg_one n_one,\n         existsi nx,\n         existsi mul_fun neg_one fx,\n         split,\n         { apply plus_inv_unique x,\n           split,\n           { exact hxx' },\n           { calc\n              x + fin_sum (mul_fun neg_one fx) nx \n                  = x + neg_one * (fin_sum fx nx) : by rw \u2190 mul_fin_sum.mul_fin_sum neg_one fx nx\n              ... = x + neg_one * x               : by rw \u2190 eqx\n              ... = zero                          : by exact negative_one neg_one x n_one, }, },\n         { intro n,\n           specialize hx n,\n           cases hx with x' hx,\n           cases hx with hx' hx,\n           cases hx with xl hx,\n           cases hx with xr hx,\n           existsi x',\n           existsi hx',\n           existsi neg_one * xl,\n           existsi xr,\n           calc\n            mul_fun neg_one fx n = neg_one * fx n : by exact rfl\n                             ... = neg_one * xl * x' * xr : by rw hx\n                             ... = (neg_one * xl) * x' * xr \n                                                  : by exact mult_assoc neg_one xl (x' * xr) },\n   }, }, },\n   { split,\n     { intros x y hx,\n       cases hx with nx hx,\n       cases hx with fx hx,\n       cases hx with eqx hx,\n       existsi nx,\n       existsi mul_fun' y fx,\n       split,\n       { calc\n          x * y = (fin_sum fx nx) * y : by rw eqx\n            ... = fin_sum (mul_fun' y fx) nx : by exact mul_fin_sum.mul_fin_sum' y fx nx, },\n       { intro n,\n         specialize hx n,\n         cases hx with x' hx,\n         cases hx with hx' hx,\n         cases hx with xl hx,\n         cases hx with xr hx,\n         existsi x',\n         existsi hx',\n         existsi xl,\n         existsi xr * y,\n         calc\n          mul_fun' y fx n = (fx n) * y : by exact rfl\n                      ... = (xl * x' * xr) * y : by rw hx\n                      ... = xl * (x' * xr) * y : by { symmetry, exact mult_assoc xl (x' * xr) y }\n                      ... = xl * x' * xr * y   : by rw \u2190 mult_assoc x' xr y, }, },\n     { intros x y hx,\n       cases hx with nx hx,\n       cases hx with fx hx,\n       cases hx with eqx hx,\n       existsi nx,\n       existsi mul_fun y fx,\n       split,\n       { calc\n          y * x = y * fin_sum fx nx : by rw eqx\n            ... = fin_sum (mul_fun y fx) nx : by exact mul_fin_sum.mul_fin_sum y fx nx, },\n       { intro n,\n         specialize hx n,\n         cases hx with x' hx,\n         cases hx with hx' hx,\n         cases hx with xl hx,\n         cases hx with xr hx,\n         existsi x',\n         existsi hx',\n         existsi y * xl,\n         existsi xr,\n         calc\n          mul_fun y fx n = y * fx n : by exact rfl\n                     ... = y * (xl * x' * xr) : by rw hx\n                     ... = (y * xl) * x' * xr : by exact mult_assoc y xl (x' * xr), }, }, },\n  end }\n\n-- every element of the set is in the ideal of finite sums of multiples of its elements\nlemma set_in_fin_sum_ideal {R : Ring} (X : set R.R) (H : \u2203 x : R.R, x \u2208 X) :\n\u2200 x : R.R, x \u2208 X \u2192 x \u2208 (fin_sum_ideal X H).I :=\nbegin\n intros x hx,\n existsi 0,\n existsi \u03bb n, x,\n split,\n { exact rfl, },\n { intro n,\n   existsi x,\n   existsi hx,\n   existsi one,\n   existsi one,\n   symmetry,\n   calc\n    one * x * one = x : by { rw one_mult_neutral_right, exact one_mult_neutral_left x }, },\nend\n\n-- these next two terms may be out of place here\n\ndef set_ideal_mult {R : Ring} (I I' : Ideal R) : set R.R :=\n{z | \u2203 x \u2208 I.I, \u2203 y \u2208 I'.I, z = x * y} -- the set of products whose first element in one ideal, \n                                        -- second element in the other.\n-- and this set is not empty\nlemma nonempty_set_ideal_mult {R : Ring} (I I' : Ideal R) : \u2203 x : R.R, x \u2208 set_ideal_mult I I' :=\nbegin\n existsi zero,\n existsi zero,\n existsi zero_mem_Ideal I,\n existsi zero,\n existsi zero_mem_Ideal I',\n symmetry,\n exact zero_annihilates_left zero,\nend\n\n/- since the set of those products is not empty, we can talk about the ideal of finite sums of \n   multiples of its elements, and, in particular, we can prove that this ideal is in the mult_set\n   from above -/\nlemma set_ideal_mult_in_mult_set {R : Ring} (I I' : Ideal R) :\n(fin_sum_ideal (set_ideal_mult I I') (nonempty_set_ideal_mult I I')) \u2208 mult_set I I' :=\nbegin\n intros x y hx hy,\n apply set_in_fin_sum_ideal (set_ideal_mult I I') (nonempty_set_ideal_mult I I') (x * y),\n existsi x,\n existsi hx,\n existsi y,\n existsi hy,\n exact rfl,\nend\n\n-- this will be used, as mentioned in ring_finite_sums, when we prove that Ideal multiplication\n-- is associative\n\n/-- Next come the operations, they can be found on the wikipedia page, another important source \n   for me was this webpage: https://equatorialmaths.wordpress.com/2008/04/04/operations-on-ideals/\n-/\n\ndef Ideal_plus {R : Ring} (I I' : Ideal R) : Ideal R :=\n{ I := {z | \u2203 (x y : R.R), x \u2208 I.I \u2227 y \u2208 I'.I \u2227 z = x + y},\n  ideal_axioms :=\n  begin\n   split,\n   { split,\n     { existsi zero,\n       existsi zero,\n       split,\n       { exact zero_mem_Ideal I, },\n       { split,\n         { exact zero_mem_Ideal I', },\n         { calc\n            zero = zero + zero : by { symmetry, exact zero_plus_neutral zero, }, }, }, },\n     split,\n     { intros x y hx hy,\n       -- the last time i tried to import tactics i ran out of memory, and i'm not sure how to \n       -- more specifically just import rcases\n       cases hx with x' hx,\n       cases hx with x'' hx,\n       cases hx with hx' hx,\n       cases hx with hx'' hx,\n       cases hy with y' hy,\n       cases hy with y'' hy,\n       cases hy with hy' hy,\n       cases hy with hy'' hy,\n       existsi (x' + y'),\n       existsi (x'' + y''),\n       split,\n       { exact (subgroup_under_addition I).2.1 x' y' hx' hy' },\n       { split,\n         { exact (subgroup_under_addition I').2.1 x'' y'' hx'' hy'' },\n         { calc\n            x + y    = (x' + x'') + (y' + y'') : by { rw hx, rw hy }\n                 ... = x' + x'' + y' + y''     : by rw \u2190 plus_assoc\n                 ... = x' + (y' + y'') + x''   : by rw plus_comm x'' (y' + y'')\n                 ... = x' + y' + y'' + x''     : by rw \u2190 plus_assoc\n                 ... = (x' + y') + x'' + y''   : by { rw plus_assoc, rw plus_comm y'' x'' },\n         }, }, },\n     intros x x' hxx' hx,\n     cases hx with y' hx,\n     cases hx with y'' hx,\n     cases hx with hy' hx,\n     cases hx with hy'' hx,\n     have H : \u2203 a' : R.R, y' + a' = zero,\n     { exact plus_inv y', },\n     cases H with a' ha',\n     have H : \u2203 a'' : R.R, y'' + a'' = zero,\n     { exact plus_inv y'', },\n     cases H with a'' ha'',\n     have h : x + a' + a'' = zero,\n     { calc\n        x + a' + a''     = y' + y'' + a' + a''   : by { rw hx, rw \u2190 plus_assoc }\n                     ... = y' + (y'' + a'') + a' : by { rw plus_comm a' a'', \n                                                        rw plus_assoc y'' a'' a' }\n                     ... = y' + zero + a'        : by rw ha''\n                     ... = y' + a' + zero        : by rw plus_comm zero a'\n                     ... = (y' + a') + zero      : by exact plus_assoc y' a' zero\n                     ... = zero + zero           : by rw ha'\n                     ... = zero                  : by exact zero_plus_neutral zero, },\n     existsi a',\n     existsi a'',\n     split,\n     { exact (subgroup_under_addition I).2.2 y' a' ha' hy', },\n     split,\n     { exact (subgroup_under_addition I').2.2 y'' a'' ha'' hy'', },\n     apply plus_inv_unique x,\n     exact \u27e8hxx', h\u27e9, },\n   { split,\n     { intros x y hx,\n       cases hx with x' hx,\n       cases hx with x'' hx,\n       cases hx with hx' hx,\n       cases hx with hx'' hx,\n       existsi x' * y,\n       existsi x'' * y,\n       split,\n       { exact (multiplication_conditions I).1 x' y hx', },\n       { split,\n         { exact (multiplication_conditions I').1 x'' y hx'', },\n         { calc\n            x * y     = (x' + x'') * y : by rw hx\n                  ... = (x' * y) + x'' * y : by exact right_distributivity x' x'' y }, }, },\n     { intros x y hx,\n       cases hx with x' hx,\n       cases hx with x'' hx,\n       cases hx with hx' hx,\n       cases hx with hx'' hx,\n       existsi (y * x'),\n       existsi (y * x''),\n       split,\n       { exact (multiplication_conditions I).2 x' y hx', },\n       { split,\n         { exact (multiplication_conditions I').2 x'' y hx'', },\n         { calc\n            y * x     = y * (x' + x'') : by rw hx\n                  ... = (y * x') + y * x'' : by exact left_distributivity y x' x'', }, }, }, },\n  end }\nlocal infixr ` \u2a01 ` : 80 := Ideal_plus\n\ndef Ideal_mult {R : Ring} (I I' : Ideal R) : Ideal R := min_ideal (mult_set I I')\nlocal infixr ` \u2a02 ` : 80 := Ideal_mult\n\n", "meta": {"author": "owen-fool", "repo": "ring_ideals_form_a_semiring_lean", "sha": "d2b7a4b5b72702c7d242d85704bcc7c3ed1f9eb2", "save_path": "github-repos/lean/owen-fool-ring_ideals_form_a_semiring_lean", "path": "github-repos/lean/owen-fool-ring_ideals_form_a_semiring_lean/ring_ideals_form_a_semiring_lean-d2b7a4b5b72702c7d242d85704bcc7c3ed1f9eb2/src/neater_proof/ideal_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7203151775275881}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Callum Sutton, Yury Kudryashov\n\n! This file was ported from Lean 3 source module algebra.hom.equiv.units.group_with_zero\n! leanprover-community/mathlib commit 655994e298904d7e5bbd1e18c95defd7b543eb94\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Hom.Equiv.Units.Basic\nimport Mathlib.Algebra.GroupWithZero.Units.Basic\n\n/-!\n# Multiplication by a nonzero element in a `GroupWithZero` is a permutation.\n-/\n\n\nvariable {G : Type _}\n\nnamespace Equiv\n\nsection GroupWithZero\n\nvariable [GroupWithZero G]\n\n/-- Left multiplication by a nonzero element in a `GroupWithZero` is a permutation of the\nunderlying type. -/\n@[simps! (config := { fullyApplied := false })]\nprotected def mulLeft\u2080 (a : G) (ha : a \u2260 0) : Perm G :=\n  (Units.mk0 a ha).mulLeft\n#align equiv.mul_left\u2080 Equiv.mulLeft\u2080\n#align equiv.mul_left\u2080_symm_apply Equiv.mulLeft\u2080_symm_apply\n#align equiv.mul_left\u2080_apply Equiv.mulLeft\u2080_apply\n\ntheorem mulLeft_bijective\u2080 (a : G) (ha : a \u2260 0) : Function.Bijective ((\u00b7 * \u00b7) a : G \u2192 G) :=\n  (Equiv.mulLeft\u2080 a ha).bijective\n#align mul_left_bijective\u2080 Equiv.mulLeft_bijective\u2080\n\n/-- Right multiplication by a nonzero element in a `GroupWithZero` is a permutation of the\nunderlying type. -/\n@[simps! (config := { fullyApplied := false })]\nprotected def mulRight\u2080 (a : G) (ha : a \u2260 0) : Perm G :=\n  (Units.mk0 a ha).mulRight\n#align equiv.mul_right\u2080 Equiv.mulRight\u2080\n#align equiv.mul_right\u2080_symm_apply Equiv.mulRight\u2080_symm_apply\n#align equiv.mul_right\u2080_apply Equiv.mulRight\u2080_apply\n\ntheorem mulRight_bijective\u2080 (a : G) (ha : a \u2260 0) : Function.Bijective ((\u00b7 * a) : G \u2192 G) :=\n  (Equiv.mulRight\u2080 a ha).bijective\n#align mul_right_bijective\u2080 Equiv.mulRight_bijective\u2080\n\nend GroupWithZero\n\nend Equiv\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Hom/Equiv/Units/GroupWithZero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768108626046, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7202970137589073}}
{"text": "import .exam1_key\n\n/- *******\nAUTOGRADER\n******* -/\n\ndef x : nat := 5\n\n-- #1 [5 points]\n#check (from_a_eq_b_prove_b_eq_a : \u2200 (T : Type) (a b : T), a = b \u2192 b = a)\n\n-- #2 [5 points] (check for lambda expression)\n#check (from_a_eq_b_prove_b_eq_a' : \u2200 (T :Type), \u2200 (a b : T), a = b \u2192 b = a)\n\n-- #3 [10 points]\n#check (t1 : forall P Q: Prop, P \u2192 Q \u2192 P \u2227 Q)\n\n-- #4 [10 points]\n#check (t2 : \u2200 P Q : Prop, (P \u2227 Q) \u2192 (Q \u2227 P))\n\n-- #5 [10 points]\n-- \n#check (arrow_trans : \u2200 P Q R : Prop, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R))\n\n-- #6 [10 points]\ntheorem foo : square = \u03bb n, n * n := rfl\n\n-- #7 -- check manually that they used a lambda expr\n\n-- #8 [10 points] One or the other of the following is good\ntheorem quadRight : quad = \u03bb a b c x, a * x * x + b * x + c := rfl\ntheorem quadRight' : quad = \u03bb a b c x, a * x^2 + b * x + c := rfl\n\n-- #9 [10 points]\n#check (noContra : \u2200 Q : Prop, (Q \u2227 \u00ac Q) \u2192 false)\n\n-- #10 [10 points] read the answers in English\n-- \n#check (contraPos : \u2200 P Q : Prop, (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P))\n\n\n-- #11 [10 points] -- read manually\n\n-- Extra credit [5 points] \n#check (double_negation_elim : \u2200 (P : Prop), \u00ac\u00acP \u2192 P)\n\ntheorem \ndisjunctiveSyllogism :\nforall P Q : Prop, P \u2228 Q \u2192 \u00acQ \u2192 P \n:=\nbegin\nintros P Q porq nq, -- assumptions\ncases porq with p q, -- now by cases\nassumption, -- case where p is true,\nexact false.elim (nq q) -- or q true\nend\n\ntheorem resolution :\nforall P Q R : Prop,\n    (P \u2228 Q) \u2227 (\u00ac Q \u2228 R) \u2192 (P \u2228 R)\n:=\nbegin\n-- introduce assumptions\nintros,\n-- get individual disjunctions\nhave pq := a.left,\nhave nqr := a.right,\n-- pf by case analysis on P \u2228 Q\ncases pq with p q,\n-- case where p is true\nfrom or.inl p,\n-- case where q is true\ncases nqr with nq r,\nexact false.elim (nq q),\nfrom or.inr r,\n-- qed\nend\n\n\n-- Socrates' MP (with predicates)\n-- for presentation in predicate unit\ntheorem modpon: \n\u2200 Being : Prop,\n\u2200 isPerson : Being \u2192 Prop,\n\u2200 isMortal : Being \u2192 Prop,\n\u2200 (p : Being), \n    (isPerson p \u2192 isMortal p) \u2192 \n    \u2200 socrates : Being, \n    isPerson socrates \u2192 isMortal socrates\n:=\nbegin\nintro Being,\nintro isPerson,\nintro isMortal,\nintro aBeing,\nintro peopleAreMortal,\nintro socrates,\nintro socratesIsAPerson,\nshow isMortal socrates,\nfrom peopleAreMortal socratesIsAPerson,\nend\n\ntheorem modpon': \n\u2200 Being : Prop,    -- Type doesn't work\n\u2200 isPerson : Being \u2192 Prop,\n\u2200 isMortal : Being \u2192 Prop,\n\u2200 (p : Being), \n    (isPerson p \u2192 isMortal p) \u2192 \n    (\u2200 socrates : Being, \n        isPerson socrates \u2192 \n        isMortal socrates)\n:=\nbegin\nintro Being,\nintro isPerson,\nintro isMortal,\nintro aBeing,\nintro peopleAreMortal,\nintro socrates,\nintro isPersonSocrates,\nshow isMortal socrates,\nfrom peopleAreMortal isPersonSocrates,\nend\n\ntheorem foo :\n\u2200 T : Type,\n\u2200 P : T \u2192 Prop,\n\u2200 M : T \u2192 Prop,\n(\u2200 t : T, P t \u2192 M t) -> \n(\u2203 u : T, P u)z \u2192 M u :=\nbegin\nintros,\nexact (a a_1)\nend\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm", "sha": "bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c", "save_path": "github-repos/lean/kevinsullivan-cs-dm", "path": "github-repos/lean/kevinsullivan-cs-dm/cs-dm-bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c/EXAMS/exam1_autograde.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7202970097597661}}
{"text": "universe u\n\ninductive Vec (\u03b1 : Type u) : Nat \u2192 Type u\n| nil  : Vec \u03b1 0\n| cons : \u03b1 \u2192 {n : Nat} \u2192 Vec \u03b1 n \u2192 Vec \u03b1 (n+1)\n\ndef Vec.append1 {\u03b1} : {m n : Nat} \u2192 Vec \u03b1 m \u2192 Vec \u03b1 n \u2192 Vec \u03b1 (n + m)\n| _, m,  nil,      ys => ys\n| _, m, cons x xs, ys => cons x (append1 xs ys)\n\ndef Vec.append2 {\u03b1} : {m n : Nat} \u2192 Vec \u03b1 m \u2192 Vec \u03b1 n \u2192 Vec \u03b1 (n + m)\n| _, _,  nil,      ys => ys\n| _, _, cons x xs, ys => cons x (append2 xs ys)\n\ndef Vec.append3 {\u03b1} : {m n : Nat} \u2192 Vec \u03b1 m \u2192 Vec \u03b1 n \u2192 Vec \u03b1 (n + m)\n| .(_), m,  nil,      ys => ys\n| .(_), m, cons x xs, ys => cons x (append3 xs ys)\n\ninductive F : Nat \u2192 Type\n| fzero : {n : Nat} \u2192 F (n+1)\n\nnamespace F\n\ndef fmin1 : {n : Nat} \u2192 (x y : F n) \u2192 F n\n| .(_), fzero, fzero => fzero\n\ndef fmin2 : {n : Nat} \u2192 (x y : F n) \u2192 F n\n| _, fzero, fzero => fzero\n\n-- TODO: uncomment after we implement smart unfolding\n-- def fmin3 : {n : Nat} \u2192 (x y : F n) \u2192 F n\n-- | n+1, fzero, fzero => fzero\n\ndef fmin4 : {n : Nat} \u2192 (x y : F n) \u2192 F n\n| .(n+1), @fzero n, @fzero .(n) => fzero\n\ndef fmin5 : {n : Nat} \u2192 (x y : F n) \u2192 F n\n| .(Nat.succ n), @fzero .(n), @fzero n => fzero\n\ndef fmin6 : {n : Nat} \u2192 (x y : F n) \u2192 F n\n| .(Nat.succ _), fzero, fzero => fzero\n\ntheorem ex1 (n : Nat) (x y : F n) : fmin1 x y = fmin2 x y :=\nrfl\n\n-- TODO: see comment above\n-- theorem ex2 (n : Nat) (x y : F n) : fmin1 x y = fmin3 x y := by\n-- cases x; exact rfl\n\ntheorem ex3 (n : Nat) (x y : F n) : fmin1 x y = fmin4 x y :=\nrfl\n\ntheorem ex4 (n : Nat) (x y : F n) : fmin1 x y = fmin4 x y :=\nrfl\n\ntheorem ex5 (n : Nat) (x y : F n) : fmin1 x y = fmin5 x y :=\nrfl\n\ntheorem ex6 (n : Nat) (x y : F n) : fmin1 x y = fmin6 x y :=\nrfl\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/def19.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7202970076524587}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  calc \n    (a / (b + c)) + (b / (a + c)) + (c / (a + b))\n      \u2265 \u27e8(a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b), by sorry\u27e9 : by sorry\n  ... \u2265 \u27e89 / 2, by sorry\u27e9 : by sorry,\nend\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by sorry ...\n  ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by sorry ...\n  ... = (a + b + c) / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry ...\n  ... = 9 / ((b + c) + (a + c) + (a + b)) : by sorry,\nend\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = ((a / (b + c)) + (b / (a + c)) + (c / (a + b))) + (3 : \u211d) : by sorry\n  ... = ((a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (3 : \u211d)) + ((3 : \u211d)) : by sorry\n  ... \u2265 (9 : \u211d) / (2 : \u211d) + ((3 : \u211d)) : by sorry\n  ... = (9 : \u211d) / (2 : \u211d) + (3 : \u211d) / (2 : \u211d) : by sorry\n  ... = (3 : \u211d) * (3 : \u211d) / (2 : \u211d) : by sorry\n  ... = (3 : \u211d) * ((3 : \u211d) / (2 : \u211d)) : by sorry\n  ... = (3 : \u211d) * (3 / 2) : by sorry\n  ... = (3 : \u211d) * (3 / 2) : by sorry\n  ... = (3 : \u211d) * (3 / 2) : by sorry\n  ... = 3 / 2 : by sorry,\nend\n\n--OUTPUT 4\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  show (a/(b+c)) + (b/(a+c)) + (c/(a+b)) \u2265 3/2, from by {\n    calc (a/(b+c)) + (b/(a+c)) + (c/(a+b)) \u2265 (a/(b+c)) + (b/(a+c)) + (c/(a+b)) + 3 : by sorry\n    ... = (a/(b+c) + b/(a+c) + c/(a+b)) + 3 : by sorry\n    ... = (a + b + c)/(b+c) + (a + b + c)/(a+c) + (a + b + c)/(a+b) + 3 : by sorry\n    ... = 3*(a + b + c)/(b+c) + (a + b + c)/(a+c) + (a + b + c)/(a+b) + 3 : by sorry\n    ... = 3*(a + b + c)/(b+c) + 3*(a + b + c)/(a+c) + 3*(a + b + c)/(a+b) : by sorry\n    ... = (a + b + c)/(b+c + a+c + a+b) + (a + b + c)/(a+c + b+c + a+b) + (a + b + c)/(a+b + b+c + a+c) + 9 : by sorry\n    ... = 3*(a + b + c)/(b+c + a+c + a+b) : by sorry\n    ... \u2265 3*1/(1/(b+c) + 1/(a+c) + 1/(a+b)) : by sorry\n    ... = 3*1/(1/3) : by sorry\n    ... = 3/2 : by sorry\n  },\nend\n\n--OUTPUT 5\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 / 2), from sorry,\n  have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (3 * (a + b + c)) / ((b + c) + (a + c) + (a + b)), from sorry,\n  have h3 : (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 3 \u2265 (3 / ((b + c) + (a + c) + (a + b))), from sorry,\n  --show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from sorry,\nend\n\n--OUTPUT 6\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  calc a / (b + c) + b / (a + c) + c / (a + b) \u2265 3/2 : sorry,\nend\n\n--OUTPUT 7\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : a + b + c > 0, from sorry,\n\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) : by {\n    have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)), from sorry,\n    rw h2,\n    have h3 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 / 2), from sorry,\n    have h4 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 / 2) * ((b + c) + (a + c) + (a + b)) / (b + c) + (a + c) + (a + b), from sorry,\n    have h5 : ((a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b)) * (2 / (b + c) + (a + c) + (a + b))  \u2265 (9 / 2) * ((b + c) + (a + c) + (a + b)), from sorry,\n    have h6 : ((a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b)) * (2 / (b + c) + (a + c) + (a + b))  \u2265 (9 / 2) * (2), from sorry,\n    exact sorry,\n  },\nend\n\n--OUTPUT 8\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) : by sorry\nend\n\n--OUTPUT 9\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) := \nbegin\n  calc ((a / (b + c)) + (b / (a + c)) + (c / (a + b))) \u2265 ... : by {\n    calc ((a / (b + c)) + (b / (a + c)) + (c / (a + b))) \u2265 ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) : by {sorry},\n    calc ... \u2265 (9 / (2 * ((b + c) + (a + c) + (a + b)))) : by sorry,\n    calc ... \u2265 (3 / ((b + c) + (a + c) + (a + b))) : by sorry,\n  },\n  show ((a / (b + c)) + (b / (a + c)) + (c / (a + b))) \u2265 (3 / 2), from sorry,\nend\n\n--OUTPUT 10\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) := \nbegin\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (a / (b + c)) + (b / (a + c)) + (c / (a + b)) + (3 / (a + b + c)) : sorry\n  ... \u2265 (3 / (b + c)) + (3 / (a + c)) + (3 / (a + b)) : sorry\n  ... \u2265 (9 / (b + c + a + c + a + b)) : sorry,\nend\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from sorry,\n  have h2 : (A \u2229 B) \u2286 A, from sorry,\n  have h3 : (A \u2229 B) \u2286 S, from sorry,\n  show (A \u2229 B) \u2208  \ud835\udcab S, from sorry,\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  calc (x + y)^2 = (x+y)*(x+y) : by sorry\n  ... = x*(x+y) + y*(x+y) : by sorry\n  ... = x*x + x*y + y*x + y*y : by sorry\n  ... = x^2 + 2*x*y + y^2 : by sorry,\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from sorry,\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from sorry,\n\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from sorry,\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from sorry,\n\n  have h5 : \u2200 a : G, classical.some (h3 a) = (1 : G), from sorry,\n  have h6 : \u2200 a : G, classical.some (h4 a) = (1 : G), from sorry,\n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by {\n    use (1 : G),\n    have h7 : \u2200 e : G, (\u2200 a : G, e * a = a \u2227 a * e = a) \u2192 e = 1, from by {\n      assume (e : G) (h7 : \u2200 a : G, e * a = a \u2227 a * e = a),\n      have h8 : \u2200 a : G, e = classical.some (h3 a), from sorry,\n      have h9 : \u2200 a : G, e = classical.some (h4 a), from sorry,\n      show e = (1 : G), from sorry,     \n    },\n    sorry,\n  }\nend\n\n/--`theorem`\nNesbitt's inequality\nLet $a$, $b$ and $c$ be positive real numbers.\n\nThen:\n:$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n\n`proof`\n{{begin-eqn}}\n{{eqn | l = \\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}\n      | o = \\ge\n      | r = \\dfrac 3 2\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac 9 2\n      | c = by adding $3$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3\n      | o = \\ge\n      | r = \\frac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = dividing by $3 \\paren {a + b + c}$\n}}\n{{end-eqn}}\nThese are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n\nFrom Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n\nThus Nesbitt's Inequality holds.\n{{qed}}\n\n-/\ntheorem  nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_outline-Natural-Language-Proof-Translation/Correct_statement-lean_proof_outline-3_few_shot_temperature_0.8_max_tokens_2000_n_10/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993028, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7202305605263767}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module group_theory.subgroup.actions\n! leanprover-community/mathlib commit f93c11933efbc3c2f0299e47b8ff83e9b539cbf6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.GroupTheory.Subgroup.Basic\n\n/-!\n# Actions by `Subgroup`s\n\nThese are just copies of the definitions about `Submonoid` starting from `Submonoid.mulAction`.\n\n## Tags\nsubgroup, subgroups\n\n-/\n\n\nnamespace Subgroup\n\nvariable {G : Type _} [Group G]\n\nvariable {\u03b1 \u03b2 : Type _}\n\n/-- The action by a subgroup is the action by the underlying group. -/\n@[to_additive \"The additive action by an add_subgroup is the action by the underlying `AddGroup`. \"]\ninstance [MulAction G \u03b1] (S : Subgroup G) : MulAction S \u03b1 :=\n  inferInstanceAs (MulAction S.toSubmonoid \u03b1)\n\n@[to_additive]\ntheorem smul_def [MulAction G \u03b1] {S : Subgroup G} (g : S) (m : \u03b1) : g \u2022 m = (g : G) \u2022 m :=\n  rfl\n#align subgroup.smul_def Subgroup.smul_def\n#align add_subgroup.vadd_def AddSubgroup.vadd_def\n\n@[to_additive]\ninstance smulCommClass_left [MulAction G \u03b2] [SMul \u03b1 \u03b2] [SMulCommClass G \u03b1 \u03b2] (S : Subgroup G) :\n    SMulCommClass S \u03b1 \u03b2 :=\n  S.toSubmonoid.smulCommClass_left\n#align subgroup.smul_comm_class_left Subgroup.smulCommClass_left\n#align add_subgroup.vadd_comm_class_left AddSubgroup.vaddCommClass_left\n\n@[to_additive]\ninstance smulCommClass_right [SMul \u03b1 \u03b2] [MulAction G \u03b2] [SMulCommClass \u03b1 G \u03b2] (S : Subgroup G) :\n    SMulCommClass \u03b1 S \u03b2 :=\n  S.toSubmonoid.smulCommClass_right\n#align subgroup.smul_comm_class_right Subgroup.smulCommClass_right\n#align add_subgroup.vadd_comm_class_right AddSubgroup.vaddCommClass_right\n\n/-- Note that this provides `IsScalarTower S G G` which is needed by `smul_mul_assoc`. -/\ninstance [SMul \u03b1 \u03b2] [MulAction G \u03b1] [MulAction G \u03b2] [IsScalarTower G \u03b1 \u03b2] (S : Subgroup G) :\n    IsScalarTower S \u03b1 \u03b2 :=\n  inferInstanceAs (IsScalarTower S.toSubmonoid \u03b1 \u03b2)\n\ninstance [MulAction G \u03b1] [FaithfulSMul G \u03b1] (S : Subgroup G) : FaithfulSMul S \u03b1 :=\n  inferInstanceAs (FaithfulSMul S.toSubmonoid \u03b1)\n\n/-- The action by a subgroup is the action by the underlying group. -/\ninstance [AddMonoid \u03b1] [DistribMulAction G \u03b1] (S : Subgroup G) : DistribMulAction S \u03b1 :=\n  inferInstanceAs (DistribMulAction S.toSubmonoid \u03b1)\n\n/-- The action by a subgroup is the action by the underlying group. -/\ninstance [Monoid \u03b1] [MulDistribMulAction G \u03b1] (S : Subgroup G) : MulDistribMulAction S \u03b1 :=\n  inferInstanceAs (MulDistribMulAction S.toSubmonoid \u03b1)\n\n/-- The center of a group acts commutatively on that group. -/\ninstance center.smulCommClass_left : SMulCommClass (center G) G G :=\n  Submonoid.center.smulCommClass_left\n#align subgroup.center.smul_comm_class_left Subgroup.center.smulCommClass_left\n\n/-- The center of a group acts commutatively on that group. -/\ninstance center.smulCommClass_right : SMulCommClass G (center G) G :=\n  Submonoid.center.smulCommClass_right\n#align subgroup.center.smul_comm_class_right Subgroup.center.smulCommClass_right\n\nend Subgroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/Subgroup/Actions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7202042446506449}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Kenny Lau, Robert Y. Lewis\n\n! This file was ported from Lean 3 source module group_theory.eckmann_hilton\n! leanprover-community/mathlib commit 41cf0cc2f528dd40a8f2db167ea4fb37b8fde7f3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Defs\n\n/-!\n# Eckmann-Hilton argument\n\nThe Eckmann-Hilton argument says that if a type carries two monoid structures that distribute\nover one another, then they are equal, and in addition commutative.\nThe main application lies in proving that higher homotopy groups (`\u03c0\u2099` for `n \u2265 2`) are commutative.\n\n## Main declarations\n\n* `EckmannHilton.commMonoid`: If a type carries a unital magma structure that distributes\n  over a unital binary operation, then the magma is a commutative monoid.\n* `EckmannHilton.commGroup`: If a type carries a group structure that distributes\n  over a unital binary operation, then the group is commutative.\n\n-/\n\nuniverse u\n\nnamespace EckmannHilton\n\nvariable {X : Type u}\n\n/-- Local notation for `m a b`. -/\nlocal notation a \" <\" m:51 \"> \" b => m a b\n\n/-- `IsUnital m e` expresses that `e : X` is a left and right unit\nfor the binary operation `m : X \u2192 X \u2192 X`. -/\nstructure IsUnital (m : X \u2192 X \u2192 X) (e : X) extends IsLeftId _ m e, IsRightId _ m e : Prop\n#align eckmann_hilton.is_unital EckmannHilton.IsUnital\n\n@[to_additive EckmannHilton.AddZeroClass.IsUnital]\ntheorem MulOneClass.isUnital [_G : MulOneClass X] : IsUnital (\u00b7 * \u00b7) (1 : X) :=\n  IsUnital.mk \u27e8MulOneClass.one_mul\u27e9 \u27e8MulOneClass.mul_one\u27e9\n\n#align eckmann_hilton.mul_one_class.is_unital EckmannHilton.MulOneClass.isUnital\n#align eckmann_hilton.add_zero_class.is_unital EckmannHilton.AddZeroClass.IsUnital\n\nvariable {m\u2081 m\u2082 : X \u2192 X \u2192 X} {e\u2081 e\u2082 : X}\n\nvariable (h\u2081 : IsUnital m\u2081 e\u2081) (h\u2082 : IsUnital m\u2082 e\u2082)\n\nvariable (distrib : \u2200 a b c d, ((a <m\u2082> b) <m\u2081> c <m\u2082> d) = (a <m\u2081> c) <m\u2082> b <m\u2081> d)\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen they have the same unit elements.\n\nIn fact, the two operations are the same, and give a commutative monoid structure,\nsee `eckmann_hilton.CommMonoid`. -/\ntheorem one : e\u2081 = e\u2082 := by\n  simpa only [h\u2081.left_id, h\u2081.right_id, h\u2082.left_id, h\u2082.right_id] using distrib e\u2082 e\u2081 e\u2081 e\u2082\n#align eckmann_hilton.one EckmannHilton.one\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen these operations are equal.\n\nIn fact, they give a commutative monoid structure, see `eckmann_hilton.CommMonoid`. -/\ntheorem mul : m\u2081 = m\u2082 := by\n  funext a b\n  calc\n    m\u2081 a b = m\u2081 (m\u2082 a e\u2081) (m\u2082 e\u2081 b) := by\n      { simp only [one h\u2081 h\u2082 distrib, h\u2081.left_id, h\u2081.right_id, h\u2082.left_id, h\u2082.right_id] }\n    _ = m\u2082 a b := by simp only [distrib, h\u2081.left_id, h\u2081.right_id, h\u2082.left_id, h\u2082.right_id]\n#align eckmann_hilton.mul EckmannHilton.mul\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen these operations are commutative.\n\nIn fact, they give a commutative monoid structure, see `eckmann_hilton.CommMonoid`. -/\n\n\n/-- If a type carries two unital binary operations that distribute over each other,\nthen these operations are associative.\n\nIn fact, they give a commutative monoid structure, see `eckmann_hilton.CommMonoid`. -/\ntheorem mul_assoc : IsAssociative _ m\u2082 :=\n  \u27e8fun a b c => by simpa [mul h\u2081 h\u2082 distrib, h\u2082.left_id, h\u2082.right_id] using distrib a b e\u2082 c\u27e9\n#align eckmann_hilton.mul_assoc EckmannHilton.mul_assoc\n\n/-- If a type carries a unital magma structure that distributes over a unital binary\noperation, then the magma structure is a commutative monoid. -/\n@[to_additive (attr := reducible)\n      \"If a type carries a unital additive magma structure that distributes over a unital binary\n      operation, then the additive magma structure is a commutative additive monoid.\"]\ndef commMonoid [h : MulOneClass X]\n    (distrib : \u2200 a b c d, ((a * b) <m\u2081> c * d) = (a <m\u2081> c) * b <m\u2081> d) : CommMonoid X :=\n  { h with\n      mul := (\u00b7 * \u00b7), one := 1, mul_comm := (mul_comm h\u2081 MulOneClass.isUnital distrib).comm,\n      mul_assoc := (mul_assoc h\u2081 MulOneClass.isUnital distrib).assoc }\n#align eckmann_hilton.comm_monoid EckmannHilton.commMonoid\n#align eckmann_hilton.add_comm_monoid EckmannHilton.addCommMonoid\n\n/-- If a type carries a group structure that distributes over a unital binary operation,\nthen the group is commutative. -/\n@[to_additive (attr := reducible)\n      \"If a type carries an additive group structure that distributes over a unital binary\n      operation, then the additive group is commutative.\"]\ndef commGroup [G : Group X]\n    (distrib : \u2200 a b c d, ((a * b) <m\u2081> c * d) = (a <m\u2081> c) * b <m\u2081> d) : CommGroup X :=\n  { EckmannHilton.commMonoid h\u2081 distrib, G with .. }\n#align eckmann_hilton.comm_group EckmannHilton.commGroup\n#align eckmann_hilton.add_comm_group EckmannHilton.addCommGroup\n\nend EckmannHilton\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/EckmannHilton.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7202042354716044}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\n\nimport algebra.group.defs\nimport order.basic\n\n/-!\n\n# Covariants and contravariants\n\nThis file contains general lemmas and instances to work with the interactions between a relation and\nan action on a Type.\n\nThe intended application is the splitting of the ordering from the algebraic assumptions on the\noperations in the `ordered_[...]` hierarchy.\n\nThe strategy is to introduce two more flexible typeclasses, `covariant_class` and\n`contravariant_class`:\n\n* `covariant_class` models the implication `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone),\n* `contravariant_class` models the implication `a * b < a * c \u2192 b < c`.\n\nSince `co(ntra)variant_class` takes as input the operation (typically `(+)` or `(*)`) and the order\nrelation (typically `(\u2264)` or `(<)`), these are the only two typeclasses that I have used.\n\nThe general approach is to formulate the lemma that you are interested in and prove it, with the\n`ordered_[...]` typeclass of your liking.  After that, you convert the single typeclass,\nsay `[ordered_cancel_monoid M]`, into three typeclasses, e.g.\n`[left_cancel_semigroup M] [partial_order M] [covariant_class M M (function.swap (*)) (\u2264)]`\nand have a go at seeing if the proof still works!\n\nNote that it is possible to combine several co(ntra)variant_class assumptions together.\nIndeed, the usual ordered typeclasses arise from assuming the pair\n`[covariant_class M M (*) (\u2264)] [contravariant_class M M (*) (<)]`\non top of order/algebraic assumptions.\n\nA formal remark is that normally `covariant_class` uses the `(\u2264)`-relation, while\n`contravariant_class` uses the `(<)`-relation. This need not be the case in general, but seems to be\nthe most common usage. In the opposite direction, the implication\n```lean\n[semigroup \u03b1] [partial_order \u03b1] [contravariant_class \u03b1 \u03b1 (*) (\u2264)] => left_cancel_semigroup \u03b1\n```\nholds -- note the `co*ntra*` assumption on the `(\u2264)`-relation.\n\n# Formalization notes\n\nWe stick to the convention of using `function.swap (*)` (or `function.swap (+)`), for the\ntypeclass assumptions, since `function.swap` is slightly better behaved than `flip`.\nHowever, sometimes as a **non-typeclass** assumption, we prefer `flip (*)` (or `flip (+)`),\nas it is easier to use. -/\n\n-- TODO: convert `has_exists_mul_of_le`, `has_exists_add_of_le`?\n-- TODO: relationship with `con/add_con`\n-- TODO: include equivalence of `left_cancel_semigroup` with\n-- `semigroup partial_order contravariant_class \u03b1 \u03b1 (*) (\u2264)`?\n-- TODO : use \u21d2, as per Eric's suggestion?  See\n-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff/near/236148738\n-- for a discussion.\n\nopen function\n\nsection variants\nvariables {M N : Type*} (\u03bc : M \u2192 N \u2192 N) (r : N \u2192 N \u2192 Prop)\n\nvariables (M N)\n/-- `covariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `covariant_class` doc-string for its meaning. -/\ndef covariant     : Prop := \u2200 (m) {n\u2081 n\u2082}, r n\u2081 n\u2082 \u2192 r (\u03bc m n\u2081) (\u03bc m n\u2082)\n\n/-- `contravariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `contravariant_class` doc-string for its meaning. -/\ndef contravariant : Prop := \u2200 (m) {n\u2081 n\u2082}, r (\u03bc m n\u2081) (\u03bc m n\u2082) \u2192 r n\u2081 n\u2082\n\n/--  Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`covariant_class` says that \"the action `\u03bc` preserves the relation `r`.\n\nMore precisely, the `covariant_class` is a class taking two Types `M N`, together with an \"action\"\n`\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the assertion that\nfor all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the pair\n`(n\u2081, n\u2082)`, then, the relation `r` also holds for the pair `(\u03bc m n\u2081, \u03bc m n\u2082)`,\nobtained from `(n\u2081, n\u2082)` by \"acting upon it by `m`\".\n\nIf `m : M` and `h : r n\u2081 n\u2082`, then `covariant_class.elim m h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`.\n-/\n@[protect_proj] class covariant_class : Prop :=\n(elim :  covariant M N \u03bc r)\n\n/--  Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`contravariant_class` says that \"if the result of the action `\u03bc` on a pair satisfies the\nrelation `r`, then the initial pair satisfied the relation `r`.\n\nMore precisely, the `contravariant_class` is a class taking two Types `M N`, together with an\n\"action\" `\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the\nassertion that for all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the\npair `(\u03bc m n\u2081, \u03bc m n\u2082)` obtained from `(n\u2081, n\u2082)` by \"acting upon it by `m`\"\", then, the relation\n`r` also holds for the pair `(n\u2081, n\u2082)`.\n\nIf `m : M` and `h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`, then `contravariant_class.elim m h : r n\u2081 n\u2082`.\n-/\n@[protect_proj] class contravariant_class : Prop :=\n(elim : contravariant M N \u03bc r)\n\nlemma rel_iff_cov [covariant_class M N \u03bc r] [contravariant_class M N \u03bc r] (m : M) {a b : N} :\n  r (\u03bc m a) (\u03bc m b) \u2194 r a b :=\n\u27e8contravariant_class.elim _, covariant_class.elim _\u27e9\n\nsection flip\n\nvariables {M N \u03bc r}\n\nlemma covariant.flip (h : covariant M N \u03bc r) : covariant M N \u03bc (flip r) :=\n\u03bb a b c hbc, h a hbc\n\nlemma contravariant.flip (h : contravariant M N \u03bc r) : contravariant M N \u03bc (flip r) :=\n\u03bb a b c hbc, h a hbc\n\nend flip\n\nsection covariant\nvariables {M N \u03bc r} [covariant_class M N \u03bc r]\n\nlemma act_rel_act_of_rel (m : M) {a b : N} (ab : r a b) :\n  r (\u03bc m a) (\u03bc m b) :=\ncovariant_class.elim _ ab\n\n@[to_additive]\nlemma group.covariant_iff_contravariant [group N] :\n  covariant N N (*) r \u2194 contravariant N N (*) r :=\nbegin\n  refine \u27e8\u03bb h a b c bc, _, \u03bb h a b c bc, _\u27e9,\n  { rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c],\n    exact h a\u207b\u00b9 bc },\n  { rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c] at bc,\n    exact h a\u207b\u00b9 bc }\nend\n\n@[to_additive]\nlemma group.covconv [group N] [covariant_class N N (*) r] :\n  contravariant_class N N (*) r :=\n\u27e8group.covariant_iff_contravariant.mp covariant_class.elim\u27e9\n\nsection is_trans\nvariables [is_trans N r] (m n : M) {a b c d : N}\n\n/-  Lemmas with 3 elements. -/\nlemma act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (\u03bc m b) c) :\n  r (\u03bc m a) c :=\ntrans (act_rel_act_of_rel m ab) rl\n\nlemma rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (\u03bc m a)) :\n  r c (\u03bc m b) :=\ntrans rr (act_rel_act_of_rel _ ab)\n\nend is_trans\n\nend covariant\n\n/-  Lemma with 4 elements. -/\nsection M_eq_N\nvariables {M N \u03bc r} {mu : N \u2192 N \u2192 N} [is_trans N r]\n  [covariant_class N N mu r] [covariant_class N N (swap mu) r] {a b c d : N}\n\nlemma act_rel_act_of_rel_of_rel (ab : r a b) (cd : r c d) :\n  r (mu a c) (mu b d) :=\ntrans (act_rel_act_of_rel c ab : _) (act_rel_act_of_rel b cd)\n\nend M_eq_N\n\nsection contravariant\nvariables {M N \u03bc r} [contravariant_class M N \u03bc r]\n\nlemma rel_of_act_rel_act (m : M) {a b : N} (ab : r (\u03bc m a) (\u03bc m b)) :\n  r a b :=\ncontravariant_class.elim _ ab\n\nsection is_trans\nvariables [is_trans N r] (m n : M) {a b c d : N}\n\n/-  Lemmas with 3 elements. -/\nlemma act_rel_of_act_rel_of_rel_act_rel (ab : r (\u03bc m a) b) (rl : r (\u03bc m b) (\u03bc m c)) :\n  r (\u03bc m a) c :=\ntrans ab (rel_of_act_rel_act m rl)\n\nlemma rel_act_of_act_rel_act_of_rel_act (ab : r (\u03bc m a) (\u03bc m b)) (rr : r b (\u03bc m c)) :\n  r a (\u03bc m c) :=\ntrans (rel_of_act_rel_act m ab) rr\n\nend is_trans\n\nend contravariant\n\nlemma covariant_le_of_covariant_lt [partial_order N] :\n  covariant M N \u03bc (<) \u2192 covariant M N \u03bc (\u2264) :=\nbegin\n  refine \u03bb h a b c bc, _,\n  rcases le_iff_eq_or_lt.mp bc with rfl | bc,\n  { exact rfl.le },\n  { exact (h _ bc).le }\nend\n\nlemma contravariant_lt_of_contravariant_le [partial_order N] :\n  contravariant M N \u03bc (\u2264) \u2192 contravariant M N \u03bc (<) :=\nbegin\n  refine \u03bb h a b c bc, lt_iff_le_and_ne.mpr \u27e8h a bc.le, _\u27e9,\n  rintro rfl,\n  exact lt_irrefl _ bc,\nend\n\nlemma covariant_le_iff_contravariant_lt [linear_order N] :\n  covariant M N \u03bc (\u2264) \u2194 contravariant M N \u03bc (<) :=\n\u27e8 \u03bb h a b c bc, not_le.mp (\u03bb k, not_le.mpr bc (h _ k)),\n  \u03bb h a b c bc, not_lt.mp (\u03bb k, not_lt.mpr bc (h _ k))\u27e9\n\nlemma covariant_lt_iff_contravariant_le [linear_order N] :\n  covariant M N \u03bc (<) \u2194 contravariant M N \u03bc (\u2264) :=\n\u27e8 \u03bb h a b c bc, not_lt.mp (\u03bb k, not_lt.mpr bc (h _ k)),\n  \u03bb h a b c bc, not_le.mp (\u03bb k, not_le.mpr bc (h _ k))\u27e9\n\n@[to_additive]\nlemma covariant_flip_mul_iff [comm_semigroup N] :\n  covariant N N (flip (*)) (r) \u2194 covariant N N (*) (r) :=\nby rw is_symm_op.flip_eq\n\n@[to_additive]\nlemma contravariant_flip_mul_iff [comm_semigroup N] :\n  contravariant N N (flip (*)) (r) \u2194 contravariant N N (*) (r) :=\nby rw is_symm_op.flip_eq\n\n@[to_additive]\ninstance contravariant_mul_lt_of_covariant_mul_le [has_mul N] [linear_order N]\n  [covariant_class N N (*) (\u2264)] : contravariant_class N N (*) (<) :=\n{ elim := (covariant_le_iff_contravariant_lt N N (*)).mp covariant_class.elim }\n\n@[to_additive]\ninstance covariant_mul_lt_of_contravariant_mul_le [has_mul N] [linear_order N]\n  [contravariant_class N N (*) (\u2264)] : covariant_class N N (*) (<) :=\n{ elim := (covariant_lt_iff_contravariant_le N N (*)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance covariant_swap_mul_le_of_covariant_mul_le [comm_semigroup N] [has_le N]\n  [covariant_class N N (*) (\u2264)] : covariant_class N N (swap (*)) (\u2264) :=\n{ elim := (covariant_flip_mul_iff N (\u2264)).mpr covariant_class.elim }\n\n@[to_additive]\ninstance contravariant_swap_mul_le_of_contravariant_mul_le [comm_semigroup N] [has_le N]\n  [contravariant_class N N (*) (\u2264)] : contravariant_class N N (swap (*)) (\u2264) :=\n{ elim := (contravariant_flip_mul_iff N (\u2264)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance contravariant_swap_mul_lt_of_contravariant_mul_lt [comm_semigroup N] [has_lt N]\n  [contravariant_class N N (*) (<)] : contravariant_class N N (swap (*)) (<) :=\n{ elim := (contravariant_flip_mul_iff N (<)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance covariant_swap_mul_lt_of_covariant_mul_lt [comm_semigroup N] [has_lt N]\n  [covariant_class N N (*) (<)] : covariant_class N N (swap (*)) (<) :=\n{ elim := (covariant_flip_mul_iff N (<)).mpr covariant_class.elim }\n\n@[to_additive]\ninstance left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le\n  [left_cancel_semigroup N] [partial_order N] [covariant_class N N (*) (\u2264)] :\n  covariant_class N N (*) (<) :=\n{ elim := \u03bb a b c bc, by { cases lt_iff_le_and_ne.mp bc with bc cb,\n    exact lt_iff_le_and_ne.mpr \u27e8covariant_class.elim a bc, (mul_ne_mul_right a).mpr cb\u27e9 } }\n\n@[to_additive]\ninstance right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le\n  [right_cancel_semigroup N] [partial_order N] [covariant_class N N (swap (*)) (\u2264)] :\n  covariant_class N N (swap (*)) (<) :=\n{ elim := \u03bb a b c bc, by { cases lt_iff_le_and_ne.mp bc with bc cb,\n    exact lt_iff_le_and_ne.mpr \u27e8covariant_class.elim a bc, (mul_ne_mul_left a).mpr cb\u27e9 } }\n\n@[to_additive]\ninstance left_cancel_semigroup.contravariant_mul_le_of_contravariant_mul_lt\n  [left_cancel_semigroup N] [partial_order N] [contravariant_class N N (*) (<)] :\n  contravariant_class N N (*) (\u2264) :=\n{ elim := \u03bb a b c bc, by { cases le_iff_eq_or_lt.mp bc with h h,\n    { exact ((mul_right_inj a).mp h).le },\n    { exact (contravariant_class.elim _ h).le } } }\n\n@[to_additive]\ninstance right_cancel_semigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt\n  [right_cancel_semigroup N] [partial_order N] [contravariant_class N N (swap (*)) (<)] :\n  contravariant_class N N (swap (*)) (\u2264) :=\n{ elim := \u03bb a b c bc, by { cases le_iff_eq_or_lt.mp bc with h h,\n    { exact ((mul_left_inj a).mp h).le },\n    { exact (contravariant_class.elim _ h).le } } }\n\nend variants\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/covariant_and_contravariant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7202042213942526}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport order.conditionally_complete_lattice\nimport data.int.least_greatest\n\n/-!\n## `\u2124` forms a conditionally complete linear order\n\nThe integers form a conditionally complete linear order.\n-/\n\nopen int\nopen_locale classical\nnoncomputable theory\n\ninstance : conditionally_complete_linear_order \u2124 :=\n{ Sup := \u03bb s, if h : s.nonempty \u2227 bdd_above s then\n    greatest_of_bdd (classical.some h.2) (classical.some_spec h.2) h.1 else 0,\n  Inf := \u03bb s, if h : s.nonempty \u2227 bdd_below s then\n    least_of_bdd (classical.some h.2) (classical.some_spec h.2) h.1 else 0,\n  le_cSup := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_above s := \u27e8\u27e8n, hns\u27e9, hs\u27e9,\n    rw [dif_pos this],\n    exact (greatest_of_bdd _ _ _).2.2 n hns\n  end,\n  cSup_le := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_above s := \u27e8hs, \u27e8n, hns\u27e9\u27e9,\n    rw [dif_pos this],\n    exact hns (greatest_of_bdd _ (classical.some_spec this.2) _).2.1\n  end,\n  cInf_le := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_below s := \u27e8\u27e8n, hns\u27e9, hs\u27e9,\n    rw [dif_pos this],\n    exact (least_of_bdd _ _ _).2.2 n hns\n  end,\n  le_cInf := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_below s := \u27e8hs, \u27e8n, hns\u27e9\u27e9,\n    rw [dif_pos this],\n    exact hns (least_of_bdd _ (classical.some_spec this.2) _).2.1\n  end,\n  .. int.linear_order, ..linear_order.to_lattice }\n\nnamespace int\n\nlemma cSup_eq_greatest_of_bdd {s : set \u2124} [decidable_pred (\u2208 s)]\n  (b : \u2124) (Hb : \u2200 z \u2208 s, z \u2264 b) (Hinh : \u2203 z : \u2124, z \u2208 s) :\n  Sup s = greatest_of_bdd b Hb Hinh :=\nbegin\n  convert dif_pos _ using 1,\n  { convert coe_greatest_of_bdd_eq _ (classical.some_spec (\u27e8b, Hb\u27e9 : bdd_above s)) _ },\n  { exact \u27e8Hinh, b, Hb\u27e9, }\nend\n\n@[simp]\nlemma cSup_empty : Sup (\u2205 : set \u2124) = 0 := dif_neg (by simp)\n\nlemma cSup_of_not_bdd_above {s : set \u2124} (h : \u00ac bdd_above s) : Sup s = 0 := dif_neg (by simp [h])\n\nlemma cInf_eq_least_of_bdd {s : set \u2124} [decidable_pred (\u2208 s)]\n  (b : \u2124) (Hb : \u2200 z \u2208 s, b \u2264 z) (Hinh : \u2203 z : \u2124, z \u2208 s) :\n  Inf s = least_of_bdd b Hb Hinh :=\nbegin\n  convert dif_pos _ using 1,\n  { convert coe_least_of_bdd_eq _ (classical.some_spec (\u27e8b, Hb\u27e9 : bdd_below s)) _ },\n  { exact \u27e8Hinh, b, Hb\u27e9, }\nend\n\n@[simp]\nlemma cInf_empty : Inf (\u2205 : set \u2124) = 0 := dif_neg (by simp)\n\nlemma cInf_of_not_bdd_below {s : set \u2124} (h : \u00ac bdd_below s) : Inf s = 0 := dif_neg (by simp [h])\n\nlemma cSup_mem {s : set \u2124} (h1 : s.nonempty) (h2 : bdd_above s) : Sup s \u2208 s :=\nbegin\n  convert (greatest_of_bdd _ (classical.some_spec h2) h1).2.1,\n  exact dif_pos \u27e8h1, h2\u27e9,\nend\n\nlemma cInf_mem {s : set \u2124} (h1 : s.nonempty) (h2 : bdd_below s) : Inf s \u2208 s :=\nbegin\n  convert (least_of_bdd _ (classical.some_spec h2) h1).2.1,\n  exact dif_pos \u27e8h1, h2\u27e9,\nend\n\nend int\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/int/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7201172206497227}}
{"text": "import Std.Tactic.Ext\n\n@[ext] structure Foo (\u03b1 \u03b2 : Type) where\n  a : \u03b1\n  b : \u03b2\n\nvariable {\u03b1 \u03b2 : Type}\nvariable (z w : Foo \u03b1 \u03b2)\n\ntheorem bar (h : z.a = w.a) (h' : z.b = w.b) : z = w := by\n  ext\n  exact h\n  exact h'\n\ntheorem comp_assoc (f g h : \u03b1 \u2192 \u03b1) : (f\u2218g)\u2218h=f\u2218(g\u2218h) := by \n  exact rfl\n\n@[ext] structure group (G : Type) where \n  mul : G\u2192G\u2192G\n  e : G \n  assoc : \u2200 (a b c : G), mul (mul a b) c = mul a (mul b c)\n  is_ident : \u2200g : G, mul e g = g \u2227 mul g e = g \n  Ex_inv : \u2200g : G, \u2203g_inv, mul (g_inv) g = e \u2227 mul g (g_inv) = e\n\n@[ext] structure permutation (\u03b1 : Type) where \n  to_fun : \u03b1 \u2192 \u03b1 \n  IsInv : \u2203 g, g \u2218 to_fun = id \u2227 to_fun \u2218 g = id \n\ndef comp (a b : permutation \u03b1) : permutation \u03b1 where \n  to_fun := a.to_fun \u2218 b.to_fun \n  IsInv := by\n    have \u27e8a', l1\u27e9 := a.IsInv \n    have \u27e8b', l2\u27e9 := b.IsInv \n    apply Exists.intro (b'\u2218a')\n    apply And.intro\n    --left\n    have thatpart : (b'\u2218a')\u2218 a.to_fun \u2218 b.to_fun = b' \u2218 (a'\u2218 a.to_fun) \u2218 b.to_fun := rfl\n    rw[thatpart]\n    have thatpart2 : a'\u2218a.to_fun = id := l1.left\n    rw[thatpart2]\n    have l3 : b'\u2218id = b' := rfl\n    have h : b'\u2218 id \u2218 b.to_fun = (b'\u2218 id)\u2218 b.to_fun := rfl \n    rw[h, l3]\n    exact l2.left\n    --right\n    have thatpart : (a.to_fun\u2218b.to_fun)\u2218b'\u2218 a' = a.to_fun\u2218(b.to_fun\u2218b')\u2218 a' := rfl\n    rw[thatpart]\n    rw[l2.right]\n    have thatpart2 : a.to_fun\u2218id = a.to_fun := rfl\n    have h : a.to_fun\u2218id\u2218a' = (a.to_fun\u2218id)\u2218a' := rfl \n    rw[h, thatpart2]\n    exact l1.right\n\ndef eIden : (permutation \u03b1) where\n  to_fun := id\n  IsInv := by\n    apply Exists.intro id \n    apply And.intro \n    exact rfl \n    exact rfl\n\ntheorem eIdent {a: permutation \u03b1} : comp eIden a = a \u2227 comp a eIden = a := by\n  apply And.intro\n  have l1 : (comp eIden a).to_fun = a.to_fun := by\n    have sl1 : (comp eIden a).to_fun = eIden.to_fun \u2218 a.to_fun := rfl\n    rw[sl1]\n    have that : eIden.to_fun = @id \u03b1 := by rfl\n    rw[that]\n    rfl\n\n  have \u27e8c', l5\u27e9 := (comp eIden a).IsInv\n  rw[l1] at l5 \n  ext n \n  have partext : permutation.to_fun (comp eIden a) = permutation.to_fun a := l1 \n  rw[partext]\n  rfl \n\ntheorem exists_inv {h : permutation \u03b1} : (\u2203j, comp j h = eIden \u2227 comp h j = eIden) := by \n  have \u27e8b, l1\u27e9 := h\n  have \u27e8k, l2\u27e9 := l1\n  let g : permutation \u03b1 := by\n    have sl1 : _ := And.intro l2.right l2.left\n    have kinv : \u2203g, g \u2218 k = id \u2227 k \u2218 g = id := Exists.intro b sl1 \n    exact \u27e8k, kinv\u27e9 \n  apply Exists.intro g\n  apply And.intro \n  simp [comp,eIden]\n  exact l2.left\n\n  simp[comp,eIden]\n  exact l2.right\n\ntheorem associat {a b c : permutation \u03b1} : comp (comp a b) c = comp a (comp b c) := rfl\n\ntheorem perms_grp (\u03b1 : Type) : (group (permutation \u03b1)) := by\n  have assoc (a b c : permutation \u03b1) : comp (comp a b) c = comp a (comp b c) := associat\n  have is_ident (g : permutation \u03b1) : comp eIden g = g \u2227 comp g eIden = g := eIdent\n  have ex_inv (g : permutation \u03b1) : \u2203j, comp (j) g = eIden \u2227 comp g (j) = eIden := exists_inv\n  exact \u27e8comp, eIden, assoc, is_ident, ex_inv\u27e9 ", "meta": {"author": "Matthew9King", "repo": "project", "sha": "90265224eca13469be91436afe47c22f1c10f8c5", "save_path": "github-repos/lean/Matthew9King-project", "path": "github-repos/lean/Matthew9King-project/project-90265224eca13469be91436afe47c22f1c10f8c5/Proj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7201172037880627}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot, Casper Putz, Anne Baanen\n-/\nimport linear_algebra.matrix.to_lin\n\n/-!\n# Diagonal matrices\n\nThis file contains some results on the linear map corresponding to a\ndiagonal matrix (`range`, `ker` and `rank`).\n\n## Tags\n\nmatrix, diagonal, linear_map\n-/\n\nnoncomputable theory\n\nopen linear_map matrix set submodule\nopen_locale big_operators\nopen_locale matrix\n\nuniverses u v w\n\nnamespace matrix\n\nsection comm_ring\n\nvariables {n : Type*} [fintype n] [decidable_eq n] {R : Type v} [comm_ring R]\n\nlemma proj_diagonal (i : n) (w : n \u2192 R) :\n  (proj i).comp (to_lin' (diagonal w)) = (w i) \u2022 proj i :=\nlinear_map.ext $ \u03bb j, mul_vec_diagonal _ _ _\n\nlemma diagonal_comp_std_basis (w : n \u2192 R) (i : n) :\n  (diagonal w).to_lin'.comp (linear_map.std_basis R (\u03bb_:n, R) i) =\n  (w i) \u2022 linear_map.std_basis R (\u03bb_:n, R) i :=\nlinear_map.ext $ \u03bb x, (diagonal_mul_vec_single w _ _).trans (pi.single_smul' i (w i) _)\n\nlemma diagonal_to_lin' (w : n \u2192 R) :\n  (diagonal w).to_lin' = linear_map.pi (\u03bbi, w i \u2022 linear_map.proj i) :=\nlinear_map.ext $ \u03bb v, funext $ \u03bb i, mul_vec_diagonal _ _ _\n\nend comm_ring\n\nsection field\n\nvariables {m n : Type*} [fintype m] [fintype n]\nvariables {K : Type u} [field K] -- maybe try to relax the universe constraint\n\nlemma ker_diagonal_to_lin' [decidable_eq m] (w : m \u2192 K) :\n  ker (diagonal w).to_lin' = (\u2a06i\u2208{i | w i = 0 }, range (linear_map.std_basis K (\u03bbi, K) i)) :=\nbegin\n  rw [\u2190 comap_bot, \u2190 infi_ker_proj, comap_infi],\n  have := \u03bb i : m, ker_comp (to_lin' (diagonal w)) (proj i),\n  simp only [comap_infi, \u2190 this, proj_diagonal, ker_smul'],\n  have : univ \u2286 {i : m | w i = 0} \u222a {i : m | w i = 0}\u1d9c, { rw set.union_compl_self },\n  exact (supr_range_std_basis_eq_infi_ker_proj K (\u03bbi:m, K)\n    disjoint_compl_right this (set.finite.of_fintype _)).symm\nend\n\nlemma range_diagonal [decidable_eq m] (w : m \u2192 K) :\n  (diagonal w).to_lin'.range = (\u2a06 i \u2208 {i | w i \u2260 0}, (linear_map.std_basis K (\u03bbi, K) i).range) :=\nbegin\n  dsimp only [mem_set_of_eq],\n  rw [\u2190 map_top, \u2190 supr_range_std_basis, map_supr],\n  congr, funext i,\n  rw [\u2190 linear_map.range_comp, diagonal_comp_std_basis, \u2190 range_smul']\nend\n\nlemma rank_diagonal [decidable_eq m] [decidable_eq K] (w : m \u2192 K) :\n  rank (diagonal w).to_lin' = fintype.card { i // w i \u2260 0 } :=\nbegin\n  have hu : univ \u2286 {i : m | w i = 0}\u1d9c \u222a {i : m | w i = 0}, { rw set.compl_union_self },\n  have hd : disjoint {i : m | w i \u2260 0} {i : m | w i = 0} := disjoint_compl_left,\n  have B\u2081 := supr_range_std_basis_eq_infi_ker_proj K (\u03bbi:m, K) hd hu (set.finite.of_fintype _),\n  have B\u2082 := @infi_ker_proj_equiv K _ _ (\u03bbi:m, K) _ _ _ _ (by simp; apply_instance) hd hu,\n  rw [rank, range_diagonal, B\u2081, \u2190@dim_fun' K],\n  apply linear_equiv.dim_eq,\n  apply B\u2082,\nend\n\nend field\n\nend matrix\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/linear_algebra/matrix/diagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7201172000284259}}
{"text": "import data.nat.prime\nimport tactic.linarith\n\ntheorem infinitude_of_primes : \u2200 N : \u2115, \u2203 p \u2265 N, nat.prime p :=\nbegin\n  intro N,\n\n  let M := nat.factorial N + 1,\n  let p := nat.min_fac M,\n\n  have pp : nat.prime p :=\n  begin\n    refine nat.min_fac_prime _,\n    have : nat.factorial N > 0 := nat.factorial_pos N,\n    linarith,\n  end,\n\n  use p,\n  split,\n  { by_contradiction,\n    have h\u2081 : p \u2223 nat.factorial N + 1 := nat.min_fac_dvd M,\n    have h\u2082 : p \u2223 nat.factorial N :=\n    begin\n      refine nat.dvd_factorial _ _,\n      exact nat.prime.pos pp,\n      exact le_of_not_ge h\n    end,\n    have h : p \u2223 1 := (nat.dvd_add_right h\u2082).mp h\u2081,\n    exact nat.prime.not_dvd_one pp h, },\n  { exact pp, },\nend\n", "meta": {"author": "NTULEAN", "repo": "Cauchy_Interlace_Theorem_Proof", "sha": "930c941a5c054201c6e3d9cc63f4bb4921030f85", "save_path": "github-repos/lean/NTULEAN-Cauchy_Interlace_Theorem_Proof", "path": "github-repos/lean/NTULEAN-Cauchy_Interlace_Theorem_Proof/Cauchy_Interlace_Theorem_Proof-930c941a5c054201c6e3d9cc63f4bb4921030f85/Gary/src/infinitudeOfPrimes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7200783018766541}}
{"text": "inductive xnat : Type\n| zero : xnat\n| succ : xnat \u2192 xnat\nnamespace xnat\n  axiom succ_ne_zero : \u2200 n : xnat, xnat.succ n \u2260 xnat.zero\n  axiom succ_inj : \u2200 {n m: xnat}, xnat.succ n = xnat.succ m \u2192 n = m\n\n  def add : xnat \u2192 xnat \u2192 xnat\n  | zero m := m\n  | (succ n) m := succ (add n m)\n\n  -- Lemma 2.2.2\n  theorem add_zero : \u2200 {n: xnat}, add n zero = n\n    | zero := by refl\n    | (succ n) := begin\n      have : add (succ n) zero = succ (add n zero), by refl,\n      show add (succ n) zero = succ n, by rw [this, add_zero],\n    end\n\n  -- Lemma 2.2.3\n  theorem add_succ : \u2200 {n m : xnat}, add n (succ m) = succ (add n m) := begin\n    intros n m,\n    induction n, {\n      refl,\n    }, {\n      calc\n        add (succ n_a) (succ m) = succ (add n_a (succ m)) : by refl\n        ...                     = succ (succ (add n_a m)) : by rw n_ih\n        ...                     = succ (add (succ n_a) m): by refl\n    }\n  end\n\n  theorem add_succ' : \u2200 n m : xnat, add n (succ m) = succ (add n m)\n  | zero m := by refl\n  | (succ n) m := begin\n    have h1 : add (succ n) (succ m) = succ (add n (succ m)), by refl,\n    have h2 : succ (succ (add n m)) = succ (add (succ n) m), by refl,\n    rw [h1, add_succ', h2]\n  end\n\n\n  -- Lemma 2.2.4\n  theorem add_comm : \u2200 n m : xnat, add n m = add m n\n  | zero m := by {rw add_zero, refl}\n  | (succ n) m := begin\n    have : add (succ n) m = succ (add n m), by refl,\n    show add (succ n) m = add m (succ n), by rw [\n      this, add_comm, add_succ\n     ],\n  end\n\n  -- Proposition 2.2.5\n  theorem add_assoc : \u2200 a b c : xnat, add a (add b c) = add (add a b) c :=\n  begin\n    intros a b c,\n    induction a, {\n      refl\n    }, {\n      calc\n        add (succ a_a) (add b c) = succ (add a_a (add b c)) : by refl\n        ...                      = succ (add (add a_a b) c) : by rw a_ih\n        ...                      = add (add (succ a_a) b) c : by refl\n    }\n  end\n\n  -- Proposition 2.2.6\n  theorem add_left_cancel : \u2200 {a b c: xnat}, add a b = add a c \u2192 b = c :=\n  begin\n    intros a b c,\n    intro h,\n    induction a, {\n      calc\n        b = add zero b : by refl\n        ... = add zero c : h\n        ... = c : by refl\n    }, {\n      have : add (succ a_a) b = succ (add a_a b), by refl,\n      rw this at h,\n      have : add (succ a_a) c = succ (add a_a c), by refl,\n      rw this at h,\n      have : add a_a b = add a_a c, from succ_inj h,\n      from a_ih this\n    }\n  end\n\n  def pos (n: xnat) : Prop := n \u2260 zero\n\n  -- Proposition 2.2.8\n  theorem add_pos: \u2200 a b : xnat, pos a \u2192 pos (add a b) := begin\n    intros a b,\n    intros pa,\n    induction a, {\n      have : zero = zero, by refl,\n      contradiction\n    }, {\n      have : add (succ a_a) b = succ (add a_a b), by refl,\n      rw this,\n      from succ_ne_zero (add a_a b)\n    }\n  end\n\n  -- colloary 2.2.9\n  theorem eq_zero_of_add_eq_zero:\n    \u2200 {a b : xnat}, (add a b) = zero \u2192 (a = zero \u2227 b = zero) :=\n  begin\n    intros a b h,\n    induction a, {\n      split,\n        show zero = zero, by refl,\n        show b = zero, {\n          have : add zero b = b, by refl,\n          rw this at h,\n          assumption\n        }\n    }, {\n      have : succ (add a_a b) = zero, from (\n        calc\n          succ (add a_a b) = add (succ a_a) b : by refl\n          ... = zero : h\n      ),\n      have : succ (add a_a b) \u2260 zero, from succ_ne_zero _,\n      contradiction\n    }\n  end\n\n  -- Lemma 2.2.10\n  theorem exists_eq_succ_of_ne_zero:\n    \u2200 a: xnat, a \u2260 zero \u2192 \u2203 b: xnat, a = succ b\n  | zero := by {intro, contradiction}\n  | (succ a) := begin\n    intro,\n    existsi a, refl\n  end\n\n  theorem exists_unique_pred:\n    \u2200 a b c: xnat, (succ a = c) \u2192 (succ b = c) \u2192 (a = b) :=\n  begin\n    intros a b c sac sbc,\n    have : succ a = succ b, {\n      transitivity,\n        assumption,\n        symmetry, assumption,\n    },\n    show a = b, from succ_inj this\n  end\n\n  def le (n m: xnat) := \u2203 a : xnat, add n a = m\n  def lt (n m: xnat) := (le n m) \u2227 n \u2260 m\n\n  -- Proposition 2.2.12\n  theorem le_refl: \u2200 n : xnat, le n n := begin\n    intro n,\n    existsi zero, from add_zero\n  end\n  theorem le_trans: \u2200 {a b c : xnat}, le a b \u2192 le b c \u2192 le a c := begin\n    intros a b c gab gbc,\n    cases gab with n pan,\n    cases gbc with m pbm,\n    existsi (add n m),\n    show (add a (add n m )) = c, by rw [add_assoc, pan, pbm]\n  end\n\n  lemma add_eq_zero: \u2200 {n m: xnat}, add n m = n \u2192 m = zero := begin\n    intros n m h,\n    have : add n zero = n, from add_zero,\n    have : add n m = add n zero, by {\n      transitivity n, assumption,\n      symmetry, assumption,\n    },\n    show m = zero, from add_left_cancel this\n  end\n  theorem le_anti_symm: \u2200 {a b : xnat}, le a b \u2192 le b a \u2192 a = b := begin\n    intros a b gab gba,\n    cases gab with n pan, cases gba with m pbm,\n    have : add n m = zero, by {\n      have : a = add zero a, by refl,\n      rw [\u2190pan, \u2190add_assoc] at pbm,\n      from add_eq_zero pbm,\n    },\n    have : n = zero \u2227 m = zero, from eq_zero_of_add_eq_zero this,\n    cases this with nz _,\n    have pan: add a zero = b, by {rw \u2190nz, assumption},\n    show a = b, {\n      have : add a zero = a, from add_zero,\n      rw this at pan, assumption\n    }\n  end\n\n  lemma add_succ_eq_succ_add :\n    \u2200 {a b : xnat}, add (succ a) b = add a (succ b) := \u03bb a b, calc\n      add (succ a) b = succ (add a b) : by refl\n      ...            = add a (succ b) : by {symmetry, from add_succ}\n\n  theorem lt_succ_le: \u2200 {a b : xnat}, lt a b \u2194 le (succ a) b := begin\n    intros a b,\n    split; intro h,\n    show le (succ a) b, by {\n      cases h with a_le_b a_ne_b,\n      cases a_le_b with n a_plus_n_eq_b,\n      cases n, {\n        have : a = b, from (calc\n          a    = add a zero : by { symmetry, from add_zero}\n          ...  = b          : a_plus_n_eq_b\n        ),\n        contradiction -- a \u2260 b \u2227 a = b\n      }, {\n        existsi n, from (calc\n          add (succ a) n = succ (add a n) : by refl\n          ...            = add a (succ n) : by rw \u2190add_succ\n          ...            = b              : a_plus_n_eq_b\n        )\n      }\n    },\n    show lt a b, by {\n      cases h with n ap1_plus_n_eq_b,\n      split,\n      show le a b, by {\n        existsi (succ n),\n        show add a (succ n) = b, {from calc\n          add a (succ n) = succ (add a n) : add_succ\n          ...            = add (succ a) n : by {symmetry, refl}\n          ...            = b : ap1_plus_n_eq_b\n        }\n      },\n      show a \u2260 b, by {\n        intro a_eq_b,\n        have : add b (succ n) = b, {from calc\n          add b (succ n) = add (succ b) n : by rw add_succ_eq_succ_add\n          ...            = add (succ a) n : by rw a_eq_b\n          ...            = b : ap1_plus_n_eq_b\n        },\n        have : succ n = zero, from add_eq_zero this,\n        have : succ n \u2260 zero, from succ_ne_zero _,\n        contradiction\n      },\n    }\n  end\n\n  theorem lt_eq_add :\n    \u2200 {a b: xnat}, lt a b \u2194 \u2203 d: xnat, pos d \u2227 b = add a d :=\n  begin\n    intros a b,\n    split, {\n      intro lt_a_b,\n      have : le (succ a) b, from iff.mp lt_succ_le lt_a_b,\n      cases this with n add_succ_a_n_eq_b,\n      existsi (succ n),\n        split,\n        show pos (succ n), from succ_ne_zero n,\n        show b = add a (succ n), {from calc\n          b   = add (succ a) n : eq.symm add_succ_a_n_eq_b\n          ... = add a (succ n) : add_succ_eq_succ_add\n        }\n    }, {\n      intro h,\n      cases h with n h1,\n      cases h1 with pos_n b_eq_add_a_n,\n      split,\n      show le a b, by { existsi n, from eq.symm b_eq_add_a_n },\n      show a \u2260 b, by {\n        intro a_eq_b,\n        have : add b n = b, by { symmetry, rwa a_eq_b at b_eq_add_a_n},\n        have : n = zero, from add_eq_zero this,\n        contradiction -- n = zero, but n is positive\n      }\n    }\n  end\n\n  lemma lt_succ: \u2200 {a b: xnat}, lt a b \u2192 lt (succ a) (succ b) := begin\n    intros a b lt_a_b,\n    split,\n    show (le (succ a) (succ b)), by {\n      cases lt_a_b.left with n _,\n      existsi n, {from calc\n        add (succ a) n = succ (add a n) : by refl\n        ...            = succ b : by rw h\n      }\n    },\n    show (succ a \u2260 succ b), by {\n      intro h,\n      have: a = b, from xnat.succ_inj h,\n      have: a \u2260 b, from lt_a_b.right,\n      contradiction\n    }\n  end\n  theorem trichotomy: \u2200 {a b: xnat}, lt a b \u2228 a = b \u2228 lt b a\n  | zero zero := or.inr (or.inl (eq.refl zero))\n  | (succ a) zero := begin\n    right, right, show lt zero (succ a), by {\n      split,\n      show le zero (succ a), by { existsi (succ a), refl },\n      show zero \u2260 succ a, by trivial\n    },\n  end\n  | zero (succ b) := begin\n    left,\n    show lt zero (succ b), by {\n      split,\n      show le zero (succ b), by { existsi (succ b), refl },\n      show zero \u2260 succ b, by trivial\n    }\n  end\n  | (succ a) (succ b) := begin\n    have : lt a b \u2228 a = b \u2228 lt b a, from trichotomy,\n    cases this with lt_a_b h,\n    any_goals { cases h with a_eq_b lt_b_a }, {\n      -- a < b\n      left, from lt_succ lt_a_b,\n    }, {\n      -- a = b\n      right, left,\n      show succ a = succ b, by rw a_eq_b,\n    }, {\n      -- a > b\n      right, right, from lt_succ lt_b_a,\n    }\n  end\nend xnat\n\n\nexample : 4 \u2260 0 := nat.succ_ne_zero 3\n\nexample : 6 \u2260 2 := begin\n  intro h,\n  have : 5 = 1, from nat.succ_inj h,\n  have : 4 = 0, from nat.succ_inj this,\n  have : 4 \u2260 0, from nat.succ_ne_zero 3,\n  contradiction\nend\n", "meta": {"author": "alanhdu", "repo": "lean-proofs", "sha": "a02cb9d0d2b6a6457f35247b89253d727f641531", "save_path": "github-repos/lean/alanhdu-lean-proofs", "path": "github-repos/lean/alanhdu-lean-proofs/lean-proofs-a02cb9d0d2b6a6457f35247b89253d727f641531/tao_analysis/02_natural_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.720071523461929}}
{"text": "/-\nCopyright (c) 2021 Mantas Bak\u0161ys. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mantas Bak\u0161ys\n-/\n\nimport data.real.sqrt\nimport tactic.interval_cases\nimport tactic.linarith\nimport tactic.norm_cast\nimport tactic.norm_num\nimport tactic.ring_exp\n\n/-!\n# IMO 2021 Q1\n\nLet `n\u2265100` be an integer. Ivan writes the numbers `n, n+1,..., 2n` each on different cards.\nHe then shuffles these `n+1` cards, and divides them into two piles. Prove that at least one\nof the piles contains two cards such that the sum of their numbers is a perfect square.\n\n# Solution\n\nWe show there exists a triplet `a, b, c \u2208 [n , 2n]` with `a < b < c` and each of the sums `(a + b)`,\n`(b + c)`, `(a + c)` being a perfect square. Specifically, we consider the linear system of\nequations\n\n    a + b = (2 * l - 1) ^ 2\n    a + c = (2 * l) ^ 2\n    b + c = (2 * l + 1) ^ 2\n\nwhich can be solved to give\n\n    a = 2 * l * l - 4 * l\n    b = 2 * l * l + 1\n    c = 2 * l * l + 4 * l\n\nTherefore, it is enough to show that there exists a natural number l such that\n`n \u2264 2 * l * l - 4 * l` and `2 * l * l + 4 * l \u2264 2 * n` for `n \u2265 100`.\n\nThen, by the Pigeonhole principle, at least two numbers in the triplet must lie in the same pile,\nwhich finishes the proof.\n-/\n\nopen real\n\nlemma lower_bound (n l : \u2115) (hl : 2 + sqrt (4 + 2 * n) \u2264 2 * l) :\n  n + 4 * l \u2264 2 * l * l :=\nbegin\n  suffices : 2 * ((n : \u211d) + 4 * l) - 8 * l + 4 \u2264 2 * (2 * l * l) - 8 * l + 4,\n  { simp only [mul_le_mul_left, sub_le_sub_iff_right, add_le_add_iff_right, zero_lt_two] at this,\n    exact_mod_cast this, },\n  rw [\u2190 le_sub_iff_add_le', sqrt_le_iff, pow_two] at hl,\n  convert hl.2 using 1; ring,\nend\n\nlemma upper_bound (n l : \u2115) (hl : (l : \u211d) \u2264 sqrt (1 + n) - 1) :\n  2 * l * l + 4 * l \u2264 2 * n :=\nbegin\n  have h1 : \u2200 n : \u2115, 0 \u2264 1 + (n : \u211d), by { intro n, exact_mod_cast nat.zero_le (1 + n) },\n  rw [le_sub_iff_add_le', le_sqrt (h1 l) (h1 n), pow_two] at hl,\n  rw [\u2190 add_le_add_iff_right 2, \u2190 @nat.cast_le \u211d],\n  simp only [nat.cast_bit0, nat.cast_add, nat.cast_one, nat.cast_mul],\n  convert (mul_le_mul_left zero_lt_two).mpr hl using 1; ring,\nend\n\n\nlemma radical_inequality {n : \u2115} (h : 107 \u2264 n) : sqrt (4 + 2 * n) \u2264 2 * (sqrt (1 + n) - 3) :=\nbegin\n  have h1n : 0 \u2264 1 + (n : \u211d), by { norm_cast, exact nat.zero_le _ },\n  rw sqrt_le_iff,\n  split,\n  { simp only [sub_nonneg, zero_le_mul_left, zero_lt_two, le_sqrt zero_lt_three.le h1n],\n    norm_cast, linarith only [h] },\n  ring_exp,\n  rw [pow_two, \u2190 sqrt_mul h1n, sqrt_mul_self h1n],\n  suffices : 24 * sqrt (1 + n) \u2264 2 * n + 36, by linarith,\n  rw mul_self_le_mul_self_iff,\n  swap, { norm_num, apply sqrt_nonneg },\n  swap, { norm_cast, linarith },\n  ring_exp,\n  rw [pow_two, \u2190 sqrt_mul h1n, sqrt_mul_self h1n],\n  -- Not splitting into cases lead to a deterministic timeout on my machine\n  obtain \u27e8rfl, h'\u27e9 : 107 = n \u2228 107 < n := eq_or_lt_of_le h,\n  { norm_num },\n  { norm_cast,\n    nlinarith },\nend\n\n-- We will later make use of the fact that there exists (l : \u2115) such that\n-- n \u2264 2 * l * l - 4 * l and 2 * l * l + 4 * l \u2264 2 * n for n \u2265 107.\nlemma exists_numbers_in_interval (n : \u2115) (hn : 107 \u2264 n) :\n  \u2203 (l : \u2115), (n + 4 * l \u2264 2 * l * l \u2227 2 * l * l + 4 * l \u2264 2 * n) :=\nbegin\n  rsuffices \u27e8l, t\u27e9 : \u2203 (l : \u2115), 2 + sqrt (4 + 2 * n) \u2264 2 * (l : \u211d) \u2227 (l : \u211d) \u2264 sqrt (1 + n) - 1,\n  { exact \u27e8l, lower_bound n l t.1, upper_bound n l t.2\u27e9 },\n  let x := sqrt (1 + n) - 1,\n  refine \u27e8\u230ax\u230b\u208a, _, _\u27e9,\n  { transitivity 2 * (x - 1),\n    { dsimp only [x], linarith only [radical_inequality hn] },\n    { simp only [mul_le_mul_left, zero_lt_two], linarith only [(nat.lt_floor_add_one x).le], } },\n  { apply nat.floor_le, rw [sub_nonneg, le_sqrt],\n    all_goals { norm_cast, simp only [one_pow, le_add_iff_nonneg_right, zero_le'], } },\nend\n\nlemma exists_triplet_summing_to_squares (n : \u2115) (hn : 100 \u2264 n) :\n  (\u2203 (a b c : \u2115), n \u2264 a \u2227 a < b \u2227 b < c \u2227 c \u2264 2 * n \u2227 (\u2203 (k : \u2115), a + b = k * k) \u2227\n  (\u2203 (l : \u2115), c + a = l * l) \u2227 (\u2203 (m : \u2115), b + c = m * m)) :=\nbegin\n  -- If n \u2265 107, we do not explicitly construct the triplet but use an existence\n  -- argument from lemma above.\n  obtain p|p : 107 \u2264 n \u2228 n < 107 := le_or_lt 107 n,\n  { obtain \u27e8l, hl1, hl2\u27e9 := exists_numbers_in_interval n p,\n    have p : 1 < l, { contrapose! hl1, interval_cases l; linarith },\n    have h\u2081 : 4 * l \u2264 2 * l * l, { linarith },\n    have h\u2082 : 1 \u2264 2 * l, { linarith },\n    refine \u27e82 * l * l - 4 * l, 2 * l * l + 1, 2 * l * l + 4 * l,\n      _, _, _, \u27e8_, \u27e82 * l - 1, _\u27e9, \u27e82 * l, _\u27e9, 2 * l + 1, _\u27e9\u27e9,\n    all_goals { zify [h\u2081, h\u2082], linarith } },\n  -- Otherwise, if 100 \u2264 n < 107, then it suffices to consider explicit\n  -- construction of a triplet {a, b, c}, which is constructed by setting l=9\n  -- in the argument at the start of the file.\n  { refine \u27e8126, 163, 198, p.le.trans _, _, _, _, \u27e817, _\u27e9, \u27e818, _\u27e9, 19, _\u27e9,\n    swap 4, { linarith },\n    all_goals { norm_num } },\nend\n\n-- Since it will be more convenient to work with sets later on, we will translate the above claim\n-- to state that there always exists a set B \u2286 [n, 2n] of cardinality at least 3, such that each\n-- pair of pairwise unequal elements of B sums to a perfect square.\nlemma exists_finset_3_le_card_with_pairs_summing_to_squares (n : \u2115) (hn : 100 \u2264 n) :\n  \u2203 B : finset \u2115,\n    (2 * 1 + 1 \u2264 B.card) \u2227\n    (\u2200 (a b \u2208 B), a \u2260 b \u2192 \u2203 k, a + b = k * k) \u2227\n    (\u2200 (c \u2208 B), n \u2264 c \u2227 c \u2264 2 * n) :=\nbegin\n  obtain \u27e8a, b, c, hna, hab, hbc, hcn, h\u2081, h\u2082, h\u2083\u27e9 := exists_triplet_summing_to_squares n hn,\n  refine \u27e8{a, b, c}, _, _, _\u27e9,\n  { suffices : ({a, b, c} : finset \u2115).card = 3, { rw this, exact le_rfl },\n    suffices : a \u2209 {b, c} \u2227 b \u2209 {c},\n    { rw [finset.card_insert_of_not_mem this.1, finset.card_insert_of_not_mem this.2,\n        finset.card_singleton], },\n    { rw [finset.mem_insert, finset.mem_singleton, finset.mem_singleton],\n      push_neg,\n      exact \u27e8\u27e8hab.ne, (hab.trans hbc).ne\u27e9, hbc.ne\u27e9 } },\n  { intros x hx y hy hxy,\n    simp only [finset.mem_insert, finset.mem_singleton] at hx hy,\n    rcases hx with rfl|rfl|rfl; rcases hy with rfl|rfl|rfl,\n    all_goals { contradiction <|> assumption <|> simpa only [add_comm x y], } },\n  { simp only [finset.mem_insert, finset.mem_singleton],\n    rintros d (rfl|rfl|rfl); split; linarith only [hna, hab, hbc, hcn], },\nend\n\ntheorem IMO_2021_Q1 : \u2200 (n : \u2115), 100 \u2264 n \u2192 \u2200 (A \u2286 finset.Icc n (2 * n)),\n  (\u2203 (a b \u2208 A), a \u2260 b \u2227 \u2203 (k : \u2115), a + b = k * k) \u2228\n  (\u2203 (a b \u2208 finset.Icc n (2 * n) \\ A), a \u2260 b \u2227 \u2203 (k : \u2115), a + b = k * k) :=\nbegin\n  intros n hn A hA,\n  -- For each n \u2208 \u2115 such that 100 \u2264 n, there exists a pairwise unequal triplet {a, b, c} \u2286 [n, 2n]\n  -- such that all pairwise sums are perfect squares. In practice, it will be easier to use\n  -- a finite set B \u2286 [n, 2n] such that all pairwise unequal pairs of B sum to a perfect square\n  -- noting that B has cardinality greater or equal to 3, by the explicit construction of the\n  -- triplet {a, b, c} before.\n  obtain \u27e8B, hB, h\u2081, h\u2082\u27e9 := exists_finset_3_le_card_with_pairs_summing_to_squares n hn,\n  have hBsub : B \u2286 finset.Icc n (2 * n),\n  { intros c hcB, simpa only [finset.mem_Icc] using h\u2082 c hcB },\n  have hB' : 2 * 1 < ((B \u2229 (finset.Icc n (2 * n) \\ A)) \u222a (B \u2229 A)).card,\n  { rw [\u2190 finset.inter_distrib_left, finset.sdiff_union_self_eq_union,\n      finset.union_eq_left_iff_subset.mpr hA, (finset.inter_eq_left_iff_subset _ _).mpr hBsub],\n    exact nat.succ_le_iff.mp hB },\n  -- Since B has cardinality greater or equal to 3, there must exist a subset C \u2286 B such that\n  -- for any A \u2286 [n, 2n], either C \u2286 A or C \u2286 [n, 2n] \\ A and C has cardinality greater\n  -- or equal to 2.\n  obtain \u27e8C, hC, hCA\u27e9 := finset.exists_subset_or_subset_of_two_mul_lt_card hB',\n  rw finset.one_lt_card at hC,\n  rcases hC with \u27e8a, ha, b, hb, hab\u27e9,\n  simp only [finset.subset_iff, finset.mem_inter] at hCA,\n  -- Now we split into the two cases C \u2286 [n, 2n] \\ A and C \u2286 A, which can be dealt with identically.\n  cases hCA; [right, left];\n  exact \u27e8a, (hCA ha).2, b, (hCA hb).2, hab, h\u2081 a (hCA ha).1 b (hCA hb).1 hab\u27e9,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2021_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479467, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7200625413697211}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n-/\nimport data.list.prime\nimport data.list.sort\nimport data.nat.gcd\nimport data.nat.sqrt_norm_num\nimport data.set.finite\nimport tactic.wlog\nimport algebra.parity\n\n/-!\n# Prime numbers\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\n- `nat.prime`: the predicate that expresses that a natural number `p` is prime\n- `nat.primes`: the subtype of natural numbers that are prime\n- `nat.min_fac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers.\n  This also appears as `nat.not_bdd_above_set_of_prime` and `nat.infinite_set_of_prime`.\n- `nat.factors n`: the prime factorization of `n`\n- `nat.factors_unique`: uniqueness of the prime factorisation\n* `nat.prime_iff`: `nat.prime` coincides with the general definition of `prime`\n* `nat.irreducible_iff_prime`: a non-unit natural number is only divisible by `1` iff it is prime\n\n-/\n\nopen bool subtype\nopen_locale nat\n\nnamespace nat\n\n/-- `prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\n@[pp_nodot]\ndef prime (p : \u2115) := _root_.irreducible p\n\ntheorem _root_.irreducible_iff_nat_prime (a : \u2115) : irreducible a \u2194 nat.prime a := iff.rfl\n\ntheorem not_prime_zero : \u00ac prime 0\n| h := h.ne_zero rfl\n\ntheorem not_prime_one : \u00ac prime 1\n| h := h.ne_one rfl\n\ntheorem prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 := irreducible.ne_zero h\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : 0 < p := nat.pos_of_ne_zero pp.ne_zero\n\ntheorem prime.two_le : \u2200 {p : \u2115}, prime p \u2192 2 \u2264 p\n| 0 h := (not_prime_zero h).elim\n| 1 h := (not_prime_one h).elim\n| (n+2) _ := le_add_self\n\ntheorem prime.one_lt {p : \u2115} : prime p \u2192 1 < p := prime.two_le\n\ninstance prime.one_lt' (p : \u2115) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := \u27e8hp.1.one_lt\u27e9\n\nlemma prime.ne_one {p : \u2115} (hp : p.prime) : p \u2260 1 :=\nhp.one_lt.ne'\n\nlemma two_le_iff (n : \u2115) : 2 \u2264 n \u2194 n \u2260 0 \u2227 \u00acis_unit n :=\nbegin\n  rw nat.is_unit_iff,\n  rcases n with _|_|m; norm_num [one_lt_succ_succ, succ_le_iff]\nend\n\nlemma prime.eq_one_or_self_of_dvd {p : \u2115} (pp : p.prime) (m : \u2115) (hm : m \u2223 p) : m = 1 \u2228 m = p :=\nbegin\n  obtain \u27e8n, hn\u27e9 := hm,\n  have := pp.is_unit_or_is_unit hn,\n  rw [nat.is_unit_iff, nat.is_unit_iff] at this,\n  apply or.imp_right _ this,\n  rintro rfl,\n  rw [hn, mul_one]\nend\n\ntheorem prime_def_lt'' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m \u2223 p, m = 1 \u2228 m = p :=\nbegin\n  refine \u27e8\u03bb h, \u27e8h.two_le, h.eq_one_or_self_of_dvd\u27e9, \u03bb h, _\u27e9,\n  have h1 := one_lt_two.trans_le h.1,\n  refine \u27e8mt nat.is_unit_iff.mp h1.ne', \u03bb a b hab, _\u27e9,\n  simp only [nat.is_unit_iff],\n  apply or.imp_right _ (h.2 a _),\n  { rintro rfl,\n    rw [\u2190nat.mul_right_inj (pos_of_gt h1), \u2190hab, mul_one] },\n  { rw hab,\n    exact dvd_mul_right _ _ }\nend\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\nprime_def_lt''.trans $\nand_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h l d, (h d).resolve_right (ne_of_lt l),\n \u03bb h d, (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left (\u03bb l, h l d)\u27e9\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00ac m \u2223 p :=\nprime_def_lt.trans $ and_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h m2 l d, not_lt_of_ge m2 ((h l d).symm \u25b8 dec_trivial),\n\u03bb h l d, begin\n  rcases m with _|_|m,\n  { rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },\n  { refl },\n  { exact (h dec_trivial l).elim d }\nend\u27e9\n\ntheorem prime_def_le_sqrt {p : \u2115} : prime p \u2194 2 \u2264 p \u2227\n  \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac m \u2223 p :=\nprime_def_lt'.trans $ and_congr_right $ \u03bb p2,\n\u27e8\u03bb a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,\n \u03bb a, have \u2200 {m k}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k, from\n  \u03bb m k mk m1 e, a m m1\n    (le_sqrt.2 (e.symm \u25b8 nat.mul_le_mul_left m mk)) \u27e8k, e\u27e9,\n  \u03bb m m2 l \u27e8k, e\u27e9, begin\n    cases (le_total m k) with mk km,\n    { exact this mk m2 e },\n    { rw [mul_comm] at e,\n      refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,\n      rwa [one_mul, \u2190 e] }\n  end\u27e9\n\ntheorem prime_of_coprime (n : \u2115) (h1 : 1 < n) (h : \u2200 m < n, m \u2260 0 \u2192 n.coprime m) : prime n :=\nbegin\n  refine prime_def_lt.mpr \u27e8h1, \u03bb m mlt mdvd, _\u27e9,\n  have hm : m \u2260 0,\n  { rintro rfl,\n    rw zero_dvd_iff at mdvd,\n    exact mlt.ne' mdvd },\n  exact (h m mlt hm).symm.eq_one_of_dvd mdvd,\nend\n\nsection\n\n/--\n  This instance is slower than the instance `decidable_prime` defined below,\n  but has the advantage that it works in the kernel for small values.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\nlocal attribute [instance]\ndef decidable_prime_1 (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_lt'\n\ntheorem prime_two : prime 2 := dec_trivial\n\nend\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : 0 < pred p :=\nlt_pred_iff.2 pp.one_lt\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : succ (pred p) = p :=\nsucc_pred_eq_of_pos pp.pos\n\ntheorem dvd_prime {p m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n\u27e8\u03bb d, pp.eq_one_or_self_of_dvd m d, \u03bb h, h.elim (\u03bb e, e.symm \u25b8 one_dvd _) (\u03bb e, e.symm \u25b8 dvd_rfl)\u27e9\n\ntheorem dvd_prime_two_le {p m : \u2115} (pp : prime p) (H : 2 \u2264 m) : m \u2223 p \u2194 m = p :=\n(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H\n\ntheorem prime_dvd_prime_iff_eq {p q : \u2115} (pp : p.prime) (qp : q.prime) : p \u2223 q \u2194 p = q :=\ndvd_prime_two_le qp (prime.two_le pp)\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00ac p \u2223 1 :=\npp.not_dvd_one\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00ac prime (a * b) :=\n\u03bb h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $\nby simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)\n\nlemma not_prime_mul' {a b n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) : \u00ac prime n :=\nby { rw \u2190 h, exact not_prime_mul h\u2081 h\u2082 }\n\nlemma prime_mul_iff {a b : \u2115} :\n  nat.prime (a * b) \u2194 (a.prime \u2227 b = 1) \u2228 (b.prime \u2227 a = 1) :=\nby simp only [iff_self, irreducible_mul_iff, \u2190irreducible_iff_nat_prime, nat.is_unit_iff]\n\nlemma prime.dvd_iff_eq {p a : \u2115} (hp : p.prime) (a1 : a \u2260 1) : a \u2223 p \u2194 p = a :=\nbegin\n  refine \u27e8_, by { rintro rfl, refl }\u27e9,\n  -- rintro \u27e8j, rfl\u27e9 does not work, due to `nat.prime` depending on the class `irreducible`\n  rintro \u27e8j, hj\u27e9,\n  rw hj at hp \u22a2,\n  rcases prime_mul_iff.mp hp with \u27e8h, rfl\u27e9 | \u27e8h, rfl\u27e9,\n  { exact mul_one _ },\n  { exact (a1 rfl).elim }\nend\n\nsection min_fac\n\nlemma min_fac_lemma (n k : \u2115) (h : \u00ac n < k * k) :\n  sqrt n - k < sqrt n + 2 - k :=\n(tsub_lt_tsub_iff_right $ le_sqrt.2 $ le_of_not_gt h).2 $\nnat.lt_add_of_pos_right dec_trivial\n\n/-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.\n  Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.\n  If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/\ndef min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115\n| k :=\n  if h : n < k * k then n else\n  if k \u2223 n then k else\n  have _, from min_fac_lemma n k h,\n  min_fac_aux (k + 2)\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n/-- Returns the smallest prime factor of `n \u2260 1`. -/\ndef min_fac : \u2115 \u2192 \u2115\n| 0 := 2\n| 1 := 1\n| (n+2) := if 2 \u2223 n then 2 else min_fac_aux (n + 2) 3\n\n@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl\n@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\ntheorem min_fac_eq : \u2200 n, min_fac n = if 2 \u2223 n then 2 else min_fac_aux n 3\n| 0     := by simp\n| 1     := by simp [show 2\u22601, from dec_trivial]; rw min_fac_aux; refl\n| (n+2) :=\n  have 2 \u2223 n + 2 \u2194 2 \u2223 n, from\n    (nat.dvd_add_iff_left (by refl)).symm,\n  by simp [min_fac, this]; congr\n\nprivate def min_fac_prop (n k : \u2115) :=\n  2 \u2264 k \u2227 k \u2223 n \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m\n\ntheorem min_fac_aux_has_prop {n : \u2115} (n2 : 2 \u2264 n) :\n  \u2200 k i, k = 2*i+3 \u2192 (\u2200 m, 2 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k)\n| k := \u03bb i e a, begin\n  rw min_fac_aux,\n  by_cases h : n < k*k; simp [h],\n  { have pp : prime n :=\n      prime_def_le_sqrt.2 \u27e8n2, \u03bb m m2 l d,\n        not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9,\n    from \u27e8n2, dvd_rfl, \u03bb m m2 d, le_of_eq\n      ((dvd_prime_two_le pp m2).1 d).symm\u27e9 },\n  have k2 : 2 \u2264 k, { subst e, exact dec_trivial },\n  by_cases dk : k \u2223 n; simp [dk],\n  { exact \u27e8k2, dk, a\u27e9 },\n  { refine have _, from min_fac_lemma n k h,\n      min_fac_aux_has_prop (k+2) (i+1)\n        (by simp [e, left_distrib]) (\u03bb m m2 d, _),\n    cases nat.eq_or_lt_of_le (a m m2 d) with me ml,\n    { subst me, contradiction },\n    apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,\n    rw [\u2190 me, e] at d, change 2 * (i + 2) \u2223 n at d,\n    have := a _ le_rfl (dvd_of_mul_right_dvd d),\n    rw e at this, exact absurd this dec_trivial }\nend\nusing_well_founded {rel_tac :=\n  \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\ntheorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) :\n  min_fac_prop n (min_fac n) :=\nbegin\n  by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},\n  have n2 : 2 \u2264 n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },\n  simp [min_fac_eq],\n  by_cases d2 : 2 \u2223 n; simp [d2],\n  { exact \u27e8le_rfl, d2, \u03bb k k2 d, k2\u27e9 },\n  { refine min_fac_aux_has_prop n2 3 0 rfl\n      (\u03bb m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),\n    exact \u03bb e, e.symm \u25b8 d }\nend\n\ntheorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\nif n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1\n\ntheorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) :=\nlet \u27e8f2, fd, a\u27e9 := min_fac_has_prop n1 in\nprime_def_lt'.2 \u27e8f2, \u03bb m m2 l d, not_le_of_gt l (a m m2 (d.trans fd))\u27e9\n\ntheorem min_fac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, 2 \u2264 m \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\nby by_cases n1 : n = 1;\n  [exact \u03bb m m2 d, n1.symm \u25b8 le_trans dec_trivial m2,\n    exact (min_fac_has_prop n1).2.2]\n\ntheorem min_fac_pos (n : \u2115) : 0 < min_fac n :=\nby by_cases n1 : n = 1;\n    [exact n1.symm \u25b8 dec_trivial, exact (min_fac_prime n1).pos]\n\ntheorem min_fac_le {n : \u2115} (H : 0 < n) : min_fac n \u2264 n :=\nle_of_dvd H (min_fac_dvd n)\n\ntheorem le_min_fac {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, prime p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p pp d, h.elim\n  (by rintro rfl; cases pp.not_dvd_one d)\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp.two_le d),\n  \u03bb H, or_iff_not_imp_left.2 $ \u03bb n1, H _ (min_fac_prime n1) (min_fac_dvd _)\u27e9\n\ntheorem le_min_fac' {m n : \u2115} : n = 1 \u2228 m \u2264 min_fac n \u2194 \u2200 p, 2 \u2264 p \u2192 p \u2223 n \u2192 m \u2264 p :=\n\u27e8\u03bb h p (pp:1<p) d, h.elim\n  (by rintro rfl; cases not_le_of_lt pp (le_of_dvd dec_trivial d))\n  (\u03bb h, le_trans h $ min_fac_le_of_dvd pp d),\n  \u03bb H, le_min_fac.2 (\u03bb p pp d, H p pp.two_le d)\u27e9\n\ntheorem prime_def_min_fac {p : \u2115} : prime p \u2194 2 \u2264 p \u2227 min_fac p = p :=\n\u27e8\u03bb pp, \u27e8pp.two_le,\n  let \u27e8f2, fd, a\u27e9 := min_fac_has_prop $ ne_of_gt pp.one_lt in\n  ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n  \u03bb \u27e8p2, e\u27e9, e \u25b8 min_fac_prime (ne_of_gt p2)\u27e9\n\n@[simp] lemma prime.min_fac_eq {p : \u2115} (hp : prime p) : min_fac p = p :=\n(prime_def_min_fac.1 hp).2\n\n/--\nThis instance is faster in the virtual machine than `decidable_prime_1`,\nbut slower in the kernel.\n\nIf you need to prove that a particular number is prime, in any case\nyou should not use `dec_trivial`, but rather `by norm_num`, which is\nmuch faster.\n-/\ninstance decidable_prime (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_min_fac\n\ntheorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : 2 \u2264 n) : \u00ac prime n \u2194 min_fac n < n :=\n(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $\n  (lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm\n\nlemma min_fac_le_div {n : \u2115} (pos : 0 < n) (np : \u00ac prime n) : min_fac n \u2264 n / min_fac n :=\nmatch min_fac_dvd n with\n| \u27e80, h0\u27e9     := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial\n| \u27e81, h1\u27e9     :=\n  begin\n    rw mul_one at h1,\n    rw [prime_def_min_fac, not_and_distrib, \u2190 h1, eq_self_iff_true, not_true, or_false,\n      not_le] at np,\n    rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]\n  end\n| \u27e8(x+2), hx\u27e9 :=\n  begin\n    conv_rhs { congr, rw hx },\n    rw [nat.mul_div_cancel_left _ (min_fac_pos _)],\n    exact min_fac_le_of_dvd dec_trivial \u27e8min_fac n, by rwa mul_comm\u27e9\n  end\nend\n\n/--\nThe square of the smallest prime factor of a composite number `n` is at most `n`.\n-/\nlemma min_fac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00ac prime n) : (min_fac n)^2 \u2264 n :=\nhave t : (min_fac n) \u2264 (n/min_fac n) := min_fac_le_div w h,\ncalc\n(min_fac n)^2 = (min_fac n) * (min_fac n)   : sq (min_fac n)\n          ... \u2264 (n/min_fac n) * (min_fac n) : nat.mul_le_mul_right (min_fac n) t\n          ... \u2264 n                           : div_mul_le_self n (min_fac n)\n\n@[simp]\nlemma min_fac_eq_one_iff {n : \u2115} : min_fac n = 1 \u2194 n = 1 :=\nbegin\n  split,\n  { intro h,\n    by_contradiction hn,\n    have := min_fac_prime hn,\n    rw h at this,\n    exact not_prime_one this, },\n  { rintro rfl, refl, }\nend\n\n@[simp]\nlemma min_fac_eq_two_iff (n : \u2115) : min_fac n = 2 \u2194 2 \u2223 n :=\nbegin\n  split,\n  { intro h,\n    convert min_fac_dvd _,\n    rw h, },\n  { intro h,\n    have ub := min_fac_le_of_dvd (le_refl 2) h,\n    have lb := min_fac_pos n,\n    apply ub.eq_or_lt.resolve_right (\u03bb h', _),\n    have := le_antisymm (nat.succ_le_of_lt lb) (lt_succ_iff.mp h'),\n    rw [eq_comm, nat.min_fac_eq_one_iff] at this,\n    subst this,\n    exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two }\nend\n\nend min_fac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n\u27e8min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,\n  ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : 2 \u2264 n) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 2 \u2264 m \u2227 m < n :=\n\u27e8min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,\n  (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_prime_and_dvd {n : \u2115} (hn : n \u2260 1) : \u2203 p, prime p \u2227 p \u2223 n :=\n\u27e8min_fac n, min_fac_prime hn, min_fac_dvd _\u27e9\n\n/-- Euclid's theorem on the **infinitude of primes**.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, n \u2264 p \u2227 prime p :=\nlet p := min_fac (n! + 1) in\nhave f1 : n! + 1 \u2260 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,\nhave pp : prime p, from min_fac_prime f1,\nhave np : n \u2264 p, from le_of_not_ge $ \u03bb h,\n  have h\u2081 : p \u2223 n!, from dvd_factorial (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  pp.not_dvd_one h\u2082,\n\u27e8p, np, pp\u27e9\n\n/-- A version of `nat.exists_infinite_primes` using the `bdd_above` predicate. -/\nlemma not_bdd_above_set_of_prime : \u00ac bdd_above {p | prime p} :=\nbegin\n  rw not_bdd_above_iff,\n  intro n,\n  obtain \u27e8p, hi, hp\u27e9 := exists_infinite_primes n.succ,\n  exact \u27e8p, hp, hi\u27e9,\nend\n\n/-- A version of `nat.exists_infinite_primes` using the `set.infinite` predicate. -/\nlemma infinite_set_of_prime : {p | prime p}.infinite :=\nset.infinite_of_not_bdd_above not_bdd_above_set_of_prime\n\nlemma prime.eq_two_or_odd {p : \u2115} (hp : prime p) : p = 2 \u2228 p % 2 = 1 :=\np.mod_two_eq_zero_or_one.imp_left\n  (\u03bb h, ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)\n\nlemma prime.eq_two_or_odd' {p : \u2115} (hp : prime p) : p = 2 \u2228 odd p :=\nor.imp_right (\u03bb h, \u27e8p / 2, (div_add_mod p 2).symm.trans (congr_arg _ h)\u27e9) hp.eq_two_or_odd\n\ntheorem coprime_of_dvd {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 \u00ac k \u2223 n) : coprime m n :=\nbegin\n  rw [coprime_iff_gcd_eq_one],\n  by_contra g2,\n  obtain \u27e8p, hp, hpdvd\u27e9 := exists_prime_and_dvd g2,\n  apply H p hp; apply dvd_trans hpdvd,\n  { exact gcd_dvd_left _ _ },\n  { exact gcd_dvd_right _ _ }\nend\n\ntheorem coprime_of_dvd' {m n : \u2115} (H : \u2200 k, prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) : coprime m n :=\ncoprime_of_dvd $ \u03bbk kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn\n\ntheorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=\ndiv_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 list \u2115\n| 0 := []\n| 1 := []\n| n@(k+2) :=\n  let m := min_fac n in have n / m < n := factors_lemma,\n  m :: factors (n / m)\n\n@[simp] lemma factors_zero : factors 0 = [] := by rw factors\n@[simp] lemma factors_one : factors 1 = [] := by rw factors\n\nlemma prime_of_mem_factors : \u2200 {n p}, p \u2208 factors n \u2192 prime p\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb p h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  have h\u2081 : p = m \u2228 p \u2208 (factors (n / m)) :=\n    (list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),\n  or.cases_on h\u2081 (\u03bb h\u2082, h\u2082.symm \u25b8 min_fac_prime dec_trivial)\n    prime_of_mem_factors\n\nlemma pos_of_mem_factors {n p : \u2115} (h : p \u2208 factors n) : 0 < p :=\nprime.pos (prime_of_mem_factors h)\n\nlemma prod_factors : \u2200 {n}, n \u2260 0 \u2192 list.prod (factors n) = n\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := \u03bb h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  show (factors n).prod = n, from\n  have h\u2081 : n / m \u2260 0 := \u03bb h,\n    have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,\n    by rw zero_mul at this; exact (show k + 2 \u2260 0, from dec_trivial) this,\n  by rw [factors, list.prod_cons, prod_factors h\u2081, nat.mul_div_cancel' (min_fac_dvd _)]\n\nlemma factors_prime {p : \u2115} (hp : nat.prime p) : p.factors = [p] :=\nbegin\n  have : p = (p - 2) + 2 := (tsub_eq_iff_eq_add_of_le hp.two_le).mp rfl,\n  rw [this, nat.factors],\n  simp only [eq.symm this],\n  have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,\n  split,\n  { exact this, },\n  { simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },\nend\n\nlemma factors_chain : \u2200 {n a}, (\u2200 p, prime p \u2192 p \u2223 n \u2192 a \u2264 p) \u2192 list.chain (\u2264) a (factors n)\n| 0       := \u03bb a h, by simp\n| 1       := \u03bb a h, by simp\n| n@(k+2) := \u03bb a h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  begin\n    rw factors,\n    refine list.chain.cons ((le_min_fac.2 h).resolve_left dec_trivial) (factors_chain _),\n    exact \u03bb p pp d, min_fac_le_of_dvd pp.two_le (d.trans $ div_dvd_of_dvd $ min_fac_dvd _),\n  end\n\nlemma factors_chain_2 (n) : list.chain (\u2264) 2 (factors n) := factors_chain $ \u03bb p pp _, pp.two_le\n\nlemma factors_chain' (n) : list.chain' (\u2264) (factors n) :=\n@list.chain'.tail _ _ (_::_) (factors_chain_2 _)\n\nlemma factors_sorted (n : \u2115) : list.sorted (\u2264) (factors n) :=\n(list.chain'_iff_pairwise (@le_trans _ _)).1 (factors_chain' _)\n\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\nlemma factors_add_two (n : \u2115) :\n  factors (n+2) = min_fac (n+2) :: factors ((n+2) / min_fac (n+2)) :=\nby rw factors\n\n@[simp]\nlemma factors_eq_nil (n : \u2115) : n.factors = [] \u2194 n = 0 \u2228 n = 1 :=\nbegin\n  split; intro h,\n  { rcases n with (_ | _ | n),\n    { exact or.inl rfl },\n    { exact or.inr rfl },\n    { rw factors at h, injection h }, },\n  { rcases h with (rfl | rfl),\n    { exact factors_zero },\n    { exact factors_one }, }\nend\n\nlemma eq_of_perm_factors {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) (h : a.factors ~ b.factors) : a = b :=\nby simpa [prod_factors ha, prod_factors hb] using list.perm.prod_eq h\n\ntheorem prime.coprime_iff_not_dvd {p n : \u2115} (pp : prime p) : coprime p n \u2194 \u00ac p \u2223 n :=\n\u27e8\u03bb co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),\n \u03bb nd, coprime_of_dvd $ \u03bb m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm \u25b8 nd\u27e9\n\ntheorem prime.dvd_iff_not_coprime {p n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00ac coprime p n :=\niff_not_comm.2 pp.coprime_iff_not_dvd\n\ntheorem prime.not_coprime_iff_dvd {m n : \u2115} :\n  \u00ac coprime m n \u2194 \u2203p, prime p \u2227 p \u2223 m \u2227 p \u2223 n :=\nbegin\n  apply iff.intro,\n  { intro h,\n    exact \u27e8min_fac (gcd m n), min_fac_prime h,\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_left m n)),\n      ((min_fac_dvd (gcd m n)).trans (gcd_dvd_right m n))\u27e9 },\n  { intro h,\n    cases h with p hp,\n    apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }\nend\n\ntheorem prime.dvd_mul {p m n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n\u27e8\u03bb H, or_iff_not_imp_left.2 $ \u03bb h,\n  (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n or.rec (\u03bb h : p \u2223 m, h.mul_right _) (\u03bb h : p \u2223 n, h.mul_left _)\u27e9\n\ntheorem prime.not_dvd_mul {p m n : \u2115} (pp : prime p)\n  (Hm : \u00ac p \u2223 m) (Hn : \u00ac p \u2223 n) : \u00ac p \u2223 m * n :=\nmt pp.dvd_mul.1 $ by simp [Hm, Hn]\n\ntheorem prime_iff {p : \u2115} : p.prime \u2194 _root_.prime p :=\n\u27e8\u03bb h, \u27e8h.ne_zero, h.not_unit, \u03bb a b, h.dvd_mul.mp\u27e9, prime.irreducible\u27e9\n\ntheorem irreducible_iff_prime {p : \u2115} : irreducible p \u2194 _root_.prime p :=\nby rw [\u2190prime_iff, prime]\n\ntheorem prime.dvd_of_dvd_pow {p m n : \u2115} (pp : prime p) (h : p \u2223 m^n) : p \u2223 m :=\nbegin\n  induction n with n IH,\n  { exact pp.not_dvd_one.elim h },\n  { rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH }\nend\n\nlemma prime.pow_not_prime {x n : \u2115} (hn : 2 \u2264 n) : \u00ac (x ^ n).prime :=\n\u03bb hp, (hp.eq_one_or_self_of_dvd x $ dvd_trans \u27e8x, sq _\u27e9 (pow_dvd_pow _ hn)).elim\n  (\u03bb hx1, hp.ne_one $ hx1.symm \u25b8 one_pow _)\n  (\u03bb hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm\n     ... < x ^ n : nat.pow_right_strict_mono (hxn.symm \u25b8 hp.two_le) hn\n     ... = x : hxn.symm)\n\nlemma prime.pow_not_prime' {x : \u2115} : \u2200 {n : \u2115}, n \u2260 1 \u2192 \u00ac (x ^ n).prime\n| 0     := \u03bb _, not_prime_one\n| 1     := \u03bb h, (h rfl).elim\n| (n+2) := \u03bb _, prime.pow_not_prime le_add_self\n\nlemma prime.eq_one_of_pow {x n : \u2115} (h : (x ^ n).prime) : n = 1 :=\nnot_imp_not.mp prime.pow_not_prime' h\n\nlemma prime.pow_eq_iff {p a k : \u2115} (hp : p.prime) : a ^ k = p \u2194 a = p \u2227 k = 1 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, by rw [h.1, h.2, pow_one]\u27e9,\n  rw \u2190h at hp,\n  rw [\u2190h, hp.eq_one_of_pow, eq_self_iff_true, and_true, pow_one],\nend\n\nlemma pow_min_fac {n k : \u2115} (hk : k \u2260 0) : (n^k).min_fac = n.min_fac :=\nbegin\n  rcases eq_or_ne n 1 with rfl | hn,\n  { simp },\n  have hnk : n ^ k \u2260 1 := \u03bb hk', hn ((pow_eq_one_iff hk).1 hk'),\n  apply (min_fac_le_of_dvd (min_fac_prime hn).two_le ((min_fac_dvd n).pow hk)).antisymm,\n  apply min_fac_le_of_dvd (min_fac_prime hnk).two_le\n    ((min_fac_prime hnk).dvd_of_dvd_pow (min_fac_dvd _)),\nend\n\nlemma prime.pow_min_fac {p k : \u2115} (hp : p.prime) (hk : k \u2260 0) : (p^k).min_fac = p :=\nby rw [pow_min_fac hk, hp.min_fac_eq]\n\nlemma prime.mul_eq_prime_sq_iff {x y p : \u2115} (hp : p.prime) (hx : x \u2260 1) (hy : y \u2260 1) :\n  x * y = p ^ 2 \u2194 x = p \u2227 y = p :=\n\u27e8\u03bb h, have pdvdxy : p \u2223 x * y, by rw h; simp [sq],\nbegin\n  wlog := hp.dvd_mul.1 pdvdxy using x y,\n  cases case with a ha,\n  have hap : a \u2223 p, from \u27e8y, by rwa [ha, sq,\n        mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at h\u27e9,\n  exact ((nat.dvd_prime hp).1 hap).elim\n    (\u03bb _, by clear_aux_decl; simp [*, sq, nat.mul_right_inj hp.pos] at *\n      {contextual := tt})\n    (\u03bb _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,\n      nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *\n      {contextual := tt})\nend,\n\u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.symm \u25b8 h\u2082.symm \u25b8 (sq _).symm\u27e9\n\nlemma prime.dvd_factorial : \u2200 {n p : \u2115} (hp : prime p), p \u2223 n! \u2194 p \u2264 n\n| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)\n| (n+1) p hp := begin\n  rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],\n  exact \u27e8\u03bb h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,\n    \u03bb h, (_root_.lt_or_eq_of_le h).elim (or.inr \u2218 le_of_lt_succ)\n      (\u03bb h, or.inl $ by rw h)\u27e9\nend\n\ntheorem prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : prime p) (h : \u00ac p \u2223 a) : coprime a (p^m) :=\n(pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n\ntheorem coprime_primes {p q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\npp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : prime p) (pq : prime q) (h : p \u2260 q) :\n  coprime (p^n) (q^m) :=\n((coprime_primes pp pq).2 h).pow _ _\n\ntheorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\nby rw [pp.dvd_iff_not_coprime]; apply em\n\nlemma coprime_of_lt_prime {n p} (n_pos : 0 < n) (hlt : n < p) (pp : prime p) :\n  coprime p n :=\n(coprime_or_dvd_of_prime pp n).resolve_right $ \u03bb h, lt_le_antisymm hlt (le_of_dvd n_pos h)\n\nlemma eq_or_coprime_of_le_prime {n p} (n_pos : 0 < n) (hle : n \u2264 p) (pp : prime p) :\n  p = n \u2228 coprime p n :=\nhle.eq_or_lt.imp eq.symm (\u03bb h, coprime_of_lt_prime n_pos h pp)\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m i : \u2115} : i \u2223 (p^m) \u2194 \u2203 k \u2264 m, i = p^k :=\nby simp_rw [dvd_prime_pow (prime_iff.mp pp) m, associated_eq_eq]\n\nlemma prime.dvd_mul_of_dvd_ne {p1 p2 n : \u2115} (h_neq : p1 \u2260 p2) (pp1 : prime p1) (pp2 : prime p2)\n  (h1 : p1 \u2223 n) (h2 : p2 \u2223 n) : (p1 * p2 \u2223 n) :=\ncoprime.mul_dvd_of_dvd_of_dvd ((coprime_primes pp1 pp2).mpr h_neq) h1 h2\n\n/--\nIf `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\nlemma eq_prime_pow_of_dvd_least_prime_pow\n  {a p k : \u2115} (pp : prime p) (h\u2081 : \u00ac(a \u2223 p^k)) (h\u2082 : a \u2223 p^(k+1)) :\n  a = p^(k+1) :=\nbegin\n  obtain \u27e8l, \u27e8h, rfl\u27e9\u27e9 := (dvd_prime_pow pp).1 h\u2082,\n  congr,\n  exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h\u2081)),\nend\n\nlemma ne_one_iff_exists_prime_dvd : \u2200 {n}, n \u2260 1 \u2194 \u2203 p : \u2115, p.prime \u2227 p \u2223 n\n| 0 := by simpa using (Exists.intro 2 nat.prime_two)\n| 1 := by simp [nat.not_prime_one]\n| (n+2) :=\nlet a := n+2 in\nlet ha : a \u2260 1 := nat.succ_succ_ne_one n in\nbegin\n  simp only [true_iff, ne.def, not_false_iff, ha],\n  exact \u27e8a.min_fac, nat.min_fac_prime ha, a.min_fac_dvd\u27e9,\nend\n\nlemma eq_one_iff_not_exists_prime_dvd {n : \u2115} : n = 1 \u2194 \u2200 p : \u2115, p.prime \u2192 \u00acp \u2223 n :=\nby simpa using not_iff_not.mpr ne_one_iff_exists_prime_dvd\n\nsection\nopen list\n\nlemma mem_factors_iff_dvd {n p : \u2115} (hn : n \u2260 0) (hp : prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n\u27e8\u03bb h, prod_factors hn \u25b8 list.dvd_prod h,\n  \u03bb h, mem_list_primes_of_dvd_prod\n    (prime_iff.mp hp)\n    (\u03bb p h, prime_iff.mp (prime_of_mem_factors h))\n    ((prod_factors hn).symm \u25b8 h)\u27e9\n\nlemma dvd_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2223 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { exact dvd_zero p },\n  { rwa \u2190mem_factors_iff_dvd hn.ne' (prime_of_mem_factors h) }\nend\n\nlemma mem_factors {n p} (hn : n \u2260 0) : p \u2208 factors n \u2194 prime p \u2227 p \u2223 n :=\n\u27e8\u03bb h, \u27e8prime_of_mem_factors h, dvd_of_mem_factors h\u27e9,\n \u03bb \u27e8hprime, hdvd\u27e9, (mem_factors_iff_dvd hn hprime).mpr hdvd\u27e9\n\nlemma le_of_mem_factors {n p : \u2115} (h : p \u2208 n.factors) : p \u2264 n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { rw factors_zero at h, cases h },\n  { exact le_of_dvd hn (dvd_of_mem_factors h) },\nend\n\n/-- **Fundamental theorem of arithmetic**-/\nlemma factors_unique {n : \u2115} {l : list \u2115} (h\u2081 : prod l = n) (h\u2082 : \u2200 p \u2208 l, prime p) :\n  l ~ factors n :=\nbegin\n  refine perm_of_prod_eq_prod _ _ _,\n  { rw h\u2081,\n    refine (prod_factors _).symm,\n    rintro rfl,\n    rw prod_eq_zero_iff at h\u2081,\n    exact prime.ne_zero (h\u2082 0 h\u2081) rfl },\n  { simp_rw \u2190prime_iff, exact h\u2082 },\n  { simp_rw \u2190prime_iff, exact (\u03bb p, prime_of_mem_factors) },\nend\n\nlemma prime.factors_pow {p : \u2115} (hp : p.prime) (n : \u2115) :\n  (p ^ n).factors = list.repeat p n :=\nbegin\n  symmetry,\n  rw \u2190 list.repeat_perm,\n  apply nat.factors_unique (list.prod_repeat p n),\n  intros q hq,\n  rwa eq_of_mem_repeat hq,\nend\n\nlemma eq_prime_pow_of_unique_prime_dvd {n p : \u2115} (hpos : n \u2260 0)\n  (h : \u2200 {d}, nat.prime d \u2192 d \u2223 n \u2192 d = p) :\n  n = p ^ n.factors.length :=\nbegin\n  set k := n.factors.length,\n  rw [\u2190prod_factors hpos, \u2190prod_repeat p k,\n    eq_repeat_of_mem (\u03bb d hd, h (prime_of_mem_factors hd) (dvd_of_mem_factors hd))],\nend\n\n/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  refine (factors_unique _ _).symm,\n  { rw [list.prod_append, prod_factors ha, prod_factors hb] },\n  { intros p hp,\n    rw list.mem_append at hp,\n    cases hp;\n    exact prime_of_mem_factors hp },\nend\n\n/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/\nlemma perm_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factors ~ a.factors ++ b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  exact perm_factors_mul ha.ne' hb.ne',\nend\n\nlemma factors_sublist_right {n k : \u2115} (h : k \u2260 0) : n.factors <+ (n * k).factors :=\nbegin\n  cases n,\n  { rw zero_mul },\n  apply sublist_of_subperm_of_sorted _ (factors_sorted _) (factors_sorted _),\n  rw (perm_factors_mul n.succ_ne_zero h).subperm_left,\n  exact (sublist_append_left _ _).subperm,\nend\n\nlemma factors_sublist_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors <+ k.factors :=\nbegin\n  obtain \u27e8a, rfl\u27e9 := h,\n  exact factors_sublist_right (right_ne_zero_of_mul h'),\nend\n\nlemma factors_subset_right {n k : \u2115} (h : k \u2260 0) : n.factors \u2286 (n * k).factors :=\n(factors_sublist_right h).subset\n\nlemma factors_subset_of_dvd {n k : \u2115} (h : n \u2223 k) (h' : k \u2260 0) : n.factors \u2286 k.factors :=\n(factors_sublist_of_dvd h h').subset\n\nlemma dvd_of_factors_subperm {a b : \u2115} (ha : a \u2260 0) (h : a.factors <+~ b.factors) : a \u2223 b :=\nbegin\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { exact dvd_zero _ },\n  rcases a with (_|_|a),\n  { exact (ha rfl).elim },\n  { exact one_dvd _ },\n  use (b.factors.diff a.succ.succ.factors).prod,\n  nth_rewrite 0 \u2190nat.prod_factors ha,\n  rw [\u2190list.prod_append,\n      list.perm.prod_eq $ list.subperm_append_diff_self_of_count_le $ list.subperm_ext_iff.mp h,\n      nat.prod_factors hb.ne']\nend\n\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m n k l : \u2115}\n      (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k+l+1) \u2223 m*n) :\n      p ^ (k+1) \u2223 m \u2228 p ^ (l+1) \u2223 n :=\nhave hpd : p^(k+l)*p \u2223 m*n, by rwa pow_succ' at hpmn,\nhave hpd2 : p \u2223 (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,\nhave hpd3 : p \u2223 (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,\nhave hpd4 : p \u2223 (m / p^k) * (n / p^l), by simpa [nat.div_mul_div_comm hpm hpn] using hpd3,\nhave hpd5 : p \u2223 (m / p^k) \u2228 p \u2223 (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,\nsuffices p^k*p \u2223 m \u2228 p^l*p \u2223 n, by rwa [pow_succ', pow_succ'],\n  hpd5.elim\n    (assume : p \u2223 m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)\n    (assume : p \u2223 n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)\n\nlemma prime_iff_prime_int {p : \u2115} : p.prime \u2194 _root_.prime (p : \u2124) :=\n\u27e8\u03bb hp, \u27e8int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt int.is_unit_iff_nat_abs_eq.1 hp.ne_one,\n  \u03bb a b h, by rw [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;\n    rwa [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, \u2190 int.dvd_nat_abs, int.coe_nat_dvd]\u27e9,\n  \u03bb hp, nat.prime_iff.2 \u27e8int.coe_nat_ne_zero.1 hp.1,\n      mt nat.is_unit_iff.1 $ \u03bb h, by simpa [h, not_prime_one] using hp,\n    \u03bb a b, by simpa only [int.coe_nat_dvd, (int.coe_nat_mul _ _).symm] using hp.2.2 a b\u27e9\u27e9\n\n/-- The type of prime numbers -/\ndef primes := {p : \u2115 // p.prime}\n\nnamespace primes\n\ninstance : has_repr nat.primes := \u27e8\u03bb p, repr p.val\u27e9\ninstance inhabited_primes : inhabited primes := \u27e8\u27e82, prime_two\u27e9\u27e9\n\ninstance coe_nat : has_coe nat.primes \u2115 := \u27e8subtype.val\u27e9\n\ntheorem coe_nat_inj (p q : nat.primes) : (p : \u2115) = (q : \u2115) \u2192 p = q :=\n\u03bb h, subtype.eq h\n\nend primes\n\ninstance monoid.prime_pow {\u03b1 : Type*} [monoid \u03b1] : has_pow \u03b1 primes := \u27e8\u03bb x p, x^p.val\u27e9\n\nend nat\n\n/-! ### Primality prover -/\n\nopen norm_num\n\nnamespace tactic\nnamespace norm_num\n\nlemma is_prime_helper (n : \u2115)\n  (h\u2081 : 1 < n) (h\u2082 : nat.min_fac n = n) : nat.prime n :=\nnat.prime_def_min_fac.2 \u27e8h\u2081, h\u2082\u27e9\n\nlemma min_fac_bit0 (n : \u2115) : nat.min_fac (bit0 n) = 2 :=\nby simp [nat.min_fac_eq, show 2 \u2223 bit0 n, by simp [bit0_eq_two_mul n]]\n\n/-- A predicate representing partial progress in a proof of `min_fac`. -/\ndef min_fac_helper (n k : \u2115) : Prop :=\n0 < k \u2227 bit1 k \u2264 nat.min_fac (bit1 n)\n\ntheorem min_fac_helper.n_pos {n k : \u2115} (h : min_fac_helper n k) : 0 < n :=\npos_iff_ne_zero.2 $ \u03bb e,\nby rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2\n\nlemma min_fac_ne_bit0 {n k : \u2115} : nat.min_fac (bit1 n) \u2260 bit0 k :=\nbegin\n  rw bit0_eq_two_mul,\n  refine (\u03bb e, absurd ((nat.dvd_add_iff_right _).2\n    (dvd_trans \u27e8_, e\u27e9 (nat.min_fac_dvd _))) _); simp\nend\n\nlemma min_fac_helper_0 (n : \u2115) (h : 0 < n) : min_fac_helper n 1 :=\nbegin\n  refine \u27e8zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symm\u27e9,\n  rw nat.succ_le_iff,\n  refine lt_of_le_of_ne (nat.min_fac_pos _) (\u03bb e, nat.not_prime_one _),\n  rw e,\n  exact nat.min_fac_prime (nat.bit1_lt h).ne',\nend\n\nlemma min_fac_helper_1 {n k k' : \u2115} (e : k + 1 = k')\n  (np : nat.min_fac (bit1 n) \u2260 bit1 k)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  rw \u2190 e,\n  refine \u27e8nat.succ_pos _,\n    (lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)\n      min_fac_ne_bit0.symm : bit0 (k+1) < _)\u27e9,\n  { rw add_right_comm, exact h.2 },\n  { rw add_right_comm, exact np.symm }\nend\n\nlemma min_fac_helper_2 (n k k' : \u2115) (e : k + 1 = k')\n  (np : \u00ac nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  intro e\u2081, rw \u2190 e\u2081 at np,\n  exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)\nend\n\nlemma min_fac_helper_3 (n k k' c : \u2115) (e : k + 1 = k')\n  (nc : bit1 n % bit1 k = c) (c0 : 0 < c)\n  (h : min_fac_helper n k) : min_fac_helper n k' :=\nbegin\n  refine min_fac_helper_1 e _ h,\n  refine mt _ (ne_of_gt c0), intro e\u2081,\n  rw [\u2190 nc, \u2190 nat.dvd_iff_mod_eq_zero, \u2190 e\u2081],\n  apply nat.min_fac_dvd\nend\n\nlemma min_fac_helper_4 (n k : \u2115) (hd : bit1 n % bit1 k = 0)\n  (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=\nby { rw \u2190 nat.dvd_iff_mod_eq_zero at hd,\n  exact le_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2 }\n\nlemma min_fac_helper_5 (n k k' : \u2115) (e : bit1 k * bit1 k = k')\n  (hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=\nbegin\n  refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2\n    \u27e8nat.bit1_lt h.n_pos, _\u27e9)).2,\n  rw \u2190 e at hd,\n  intros m m2 hm md,\n  have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),\n  rw nat.le_sqrt at this,\n  exact not_le_of_lt hd this\nend\n\n/-- Given `e` a natural numeral and `d : nat` a factor of it, return `\u22a2 \u00ac prime e`. -/\nmeta def prove_non_prime (e : expr) (n d\u2081 : \u2115) : tactic expr :=\ndo let e\u2081 := reflect d\u2081,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n  let d\u2082 := n / d\u2081, let e\u2082 := reflect d\u2082,\n  (c, e', p) \u2190 prove_mul_nat c e\u2081 e\u2082,\n  guard (e' =\u2090 e),\n  (c, p\u2082) \u2190 prove_lt_nat c `(1) e\u2082,\n  return $ `(@nat.not_prime_mul').mk_app [e\u2081, e\u2082, e, p, p\u2081, p\u2082]\n\n/-- Given `a`,`a1 := bit1 a`, `n1` the value of `a1`, `b` and `p : min_fac_helper a b`,\n  returns `(c, \u22a2 min_fac a1 = c)`. -/\nmeta def prove_min_fac_aux (a a1 : expr) (n1 : \u2115) :\n  instance_cache \u2192 expr \u2192 expr \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| ic b p := do\n  k \u2190 b.to_nat,\n  let k1 := bit1 k,\n  let b1 := `(bit1:\u2115\u2192\u2115).mk_app [b],\n  if n1 < k1*k1 then do\n    (ic, e', p\u2081) \u2190 prove_mul_nat ic b1 b1,\n    (ic, p\u2082) \u2190 prove_lt_nat ic a1 e',\n    return (ic, a1, `(min_fac_helper_5).mk_app [a, b, e', p\u2081, p\u2082, p])\n  else let d := k1.min_fac in\n  if to_bool (d < k1) then do\n    let k' := k+1, let e' := reflect k',\n    (ic, p\u2081) \u2190 prove_succ ic b e',\n    p\u2082 \u2190 prove_non_prime b1 k1 d,\n    prove_min_fac_aux ic e' $ `(min_fac_helper_2).mk_app [a, b, e', p\u2081, p\u2082, p]\n  else do\n    let nc := n1 % k1,\n    (ic, c, pc) \u2190 prove_div_mod ic a1 b1 tt,\n    if nc = 0 then\n      return (ic, b1, `(min_fac_helper_4).mk_app [a, b, pc, p])\n    else do\n      (ic, p\u2080) \u2190 prove_pos ic c,\n      let k' := k+1, let e' := reflect k',\n      (ic, p\u2081) \u2190 prove_succ ic b e',\n      prove_min_fac_aux ic e' $ `(min_fac_helper_3).mk_app [a, b, e', c, p\u2081, pc, p\u2080, p]\n\n/-- Given `a` a natural numeral, returns `(b, \u22a2 min_fac a = b)`. -/\nmeta def prove_min_fac (ic : instance_cache) (e : expr) : tactic (instance_cache \u00d7 expr \u00d7 expr) :=\nmatch match_numeral e with\n| match_numeral_result.zero := return (ic, `(2:\u2115), `(nat.min_fac_zero))\n| match_numeral_result.one := return (ic, `(1:\u2115), `(nat.min_fac_one))\n| match_numeral_result.bit0 e := return (ic, `(2), `(min_fac_bit0).mk_app [e])\n| match_numeral_result.bit1 e := do\n  n \u2190 e.to_nat,\n  c \u2190 mk_instance_cache `(nat),\n  (c, p) \u2190 prove_pos c e,\n  let a1 := `(bit1:\u2115\u2192\u2115).mk_app [e],\n  prove_min_fac_aux e a1 (bit1 n) c `(1) (`(min_fac_helper_0).mk_app [e, p])\n| _ := failed\nend\n\n/-- A partial proof of `factors`. Asserts that `l` is a sorted list of primes, lower bounded by a\nprime `p`, which multiplies to `n`. -/\ndef factors_helper (n p : \u2115) (l : list \u2115) : Prop :=\np.prime \u2192 list.chain (\u2264) p l \u2227 (\u2200 a \u2208 l, nat.prime a) \u2227 list.prod l = n\n\nlemma factors_helper_nil (a : \u2115) : factors_helper 1 a [] :=\n\u03bb pa, \u27e8list.chain.nil, by rintro _ \u27e8\u27e9, list.prod_nil\u27e9\n\nlemma factors_helper_cons' (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a \u2264 b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\n\u03bb pa,\n  have pb : b.prime, from nat.prime_def_min_fac.2 \u27e8le_trans pa.two_le h\u2082, h\u2083\u27e9,\n  let \u27e8f\u2081, f\u2082, f\u2083\u27e9 := H pb in\n  \u27e8list.chain.cons h\u2082 f\u2081, \u03bb c h, h.elim (\u03bb e, e.symm \u25b8 pb) (f\u2082 _),\n   by rw [list.prod_cons, f\u2083, h\u2081]\u27e9\n\nlemma factors_helper_cons (n m a b : \u2115) (l : list \u2115)\n  (h\u2081 : b * m = n) (h\u2082 : a < b) (h\u2083 : nat.min_fac b = b)\n  (H : factors_helper m b l) : factors_helper n a (b :: l) :=\nfactors_helper_cons' _ _ _ _ _ h\u2081 h\u2082.le h\u2083 H\n\nlemma factors_helper_sn (n a : \u2115) (h\u2081 : a < n) (h\u2082 : nat.min_fac n = n) : factors_helper n a [n] :=\nfactors_helper_cons _ _ _ _ _ (mul_one _) h\u2081 h\u2082 (factors_helper_nil _)\n\nlemma factors_helper_same (n m a : \u2115) (l : list \u2115) (h : a * m = n)\n  (H : factors_helper m a l) : factors_helper n a (a :: l) :=\n\u03bb pa, factors_helper_cons' _ _ _ _ _ h le_rfl (nat.prime_def_min_fac.1 pa).2 H pa\n\nlemma factors_helper_same_sn (a : \u2115) : factors_helper a a [a] :=\nfactors_helper_same _ _ _ _ (mul_one _) (factors_helper_nil _)\n\nlemma factors_helper_end (n : \u2115) (l : list \u2115) (H : factors_helper n 2 l) : nat.factors n = l :=\nlet \u27e8h\u2081, h\u2082, h\u2083\u27e9 := H nat.prime_two in\nhave _, from (list.chain'_iff_pairwise (@le_trans _ _)).1 (@list.chain'.tail _ _ (_::_) h\u2081),\n(list.eq_of_perm_of_sorted (nat.factors_unique h\u2083 h\u2082) this (nat.factors_sorted _)).symm\n\n/-- Given `n` and `a` natural numerals, returns `(l, \u22a2 factors_helper n a l)`. -/\nmeta def prove_factors_aux :\n  instance_cache \u2192 expr \u2192 expr \u2192 \u2115 \u2192 \u2115 \u2192 tactic (instance_cache \u00d7 expr \u00d7 expr)\n| c en ea n a :=\n  let b := n.min_fac in\n  if b < n then do\n    let m := n / b,\n    (c, em) \u2190 c.of_nat m,\n    if b = a then do\n      (c, _, p\u2081) \u2190 prove_mul_nat c ea em,\n      (c, l, p\u2082) \u2190 prove_factors_aux c em ea m a,\n      pure (c, `(%%ea::%%l:list \u2115), `(factors_helper_same).mk_app [en, em, ea, l, p\u2081, p\u2082])\n    else do\n      (c, eb) \u2190 c.of_nat b,\n      (c, _, p\u2081) \u2190 prove_mul_nat c eb em,\n      (c, p\u2082) \u2190 prove_lt_nat c ea eb,\n      (c, _, p\u2083) \u2190 prove_min_fac c eb,\n      (c, l, p\u2084) \u2190 prove_factors_aux c em eb m b,\n      pure (c, `(%%eb::%%l : list \u2115),\n        `(factors_helper_cons).mk_app [en, em, ea, eb, l, p\u2081, p\u2082, p\u2083, p\u2084])\n  else if b = a then\n    pure (c, `([%%ea] : list \u2115), `(factors_helper_same_sn).mk_app [ea])\n  else do\n    (c, p\u2081) \u2190 prove_lt_nat c ea en,\n    (c, _, p\u2082) \u2190 prove_min_fac c en,\n    pure (c, `([%%en] : list \u2115), `(factors_helper_sn).mk_app [en, ea, p\u2081, p\u2082])\n\n/-- Evaluates the `prime` and `min_fac` functions. -/\n@[norm_num] meta def eval_prime : expr \u2192 tactic (expr \u00d7 expr)\n| `(nat.prime %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := false_intro `(nat.not_prime_zero)\n  | 1 := false_intro `(nat.not_prime_one)\n  | _ := let d\u2081 := n.min_fac in\n    if d\u2081 < n then prove_non_prime e n d\u2081 >>= false_intro\n    else do\n      let e\u2081 := reflect d\u2081,\n      c \u2190 mk_instance_cache `(\u2115),\n      (c, p\u2081) \u2190 prove_lt_nat c `(1) e\u2081,\n      (c, e\u2081, p) \u2190 prove_min_fac c e,\n      true_intro $ `(is_prime_helper).mk_app [e, p\u2081, p]\n  end\n| `(nat.min_fac %%e) := do\n  ic \u2190 mk_instance_cache `(\u2115),\n  prod.snd <$> prove_min_fac ic e\n| `(nat.factors %%e) := do\n  n \u2190 e.to_nat,\n  match n with\n  | 0 := pure (`(@list.nil \u2115), `(nat.factors_zero))\n  | 1 := pure (`(@list.nil \u2115), `(nat.factors_one))\n  | _ := do\n    c \u2190 mk_instance_cache `(\u2115),\n    (c, l, p) \u2190 prove_factors_aux c e `(2) n 2,\n    pure (l, `(factors_helper_end).mk_app [e, l, p])\n  end\n| _ := failed\n\nend norm_num\nend tactic\n\nnamespace nat\n\ntheorem prime_three : prime 3 := by norm_num\n\ninstance fact_prime_two : fact (prime 2) := \u27e8prime_two\u27e9\n\ninstance fact_prime_three : fact (prime 3) := \u27e8prime_three\u27e9\n\nend nat\n\n\nnamespace nat\n\nlemma mem_factors_mul {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) {p : \u2115} :\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u2228 p \u2208 b.factors :=\nbegin\n  rw [mem_factors (mul_ne_zero ha hb), mem_factors ha, mem_factors hb, \u2190and_or_distrib_left],\n  simpa only [and.congr_right_iff] using prime.dvd_mul\nend\n\n/-- If `a`, `b` are positive, the prime divisors of `a * b` are the union of those of `a` and `b` -/\nlemma factors_mul_to_finset {a b : \u2115} (ha : a \u2260 0) (hb : b \u2260 0) :\n  (a * b).factors.to_finset = a.factors.to_finset \u222a b.factors.to_finset :=\n(list.to_finset.ext $ \u03bb x, (mem_factors_mul ha hb).trans list.mem_union.symm).trans $\n  list.to_finset_union _ _\n\nlemma pow_succ_factors_to_finset (n k : \u2115) :\n  (n^(k+1)).factors.to_finset = n.factors.to_finset :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  induction k with k ih,\n  { simp },\n  rw [pow_succ, factors_mul_to_finset hn (pow_ne_zero _ hn), ih, finset.union_idempotent]\nend\n\nlemma pow_factors_to_finset (n : \u2115) {k : \u2115} (hk : k \u2260 0) :\n  (n^k).factors.to_finset = n.factors.to_finset :=\nbegin\n  cases k,\n  { simpa using hk },\n  rw pow_succ_factors_to_finset\nend\n\n/-- The only prime divisor of positive prime power `p^k` is `p` itself -/\nlemma prime_pow_prime_divisor {p k : \u2115} (hk : k \u2260 0) (hp : prime p) :\n  (p^k).factors.to_finset = {p} :=\nby simp [pow_factors_to_finset p hk, factors_prime hp]\n\n/-- The sets of factors of coprime `a` and `b` are disjoint -/\nlemma coprime_factors_disjoint {a b : \u2115} (hab : a.coprime b) : list.disjoint a.factors b.factors :=\nbegin\n  intros q hqa hqb,\n  apply not_prime_one,\n  rw \u2190(eq_one_of_dvd_coprimes hab (dvd_of_mem_factors hqa) (dvd_of_mem_factors hqb)),\n  exact prime_of_mem_factors hqa\nend\n\nlemma mem_factors_mul_of_coprime {a b : \u2115} (hab : coprime a b) (p : \u2115):\n  p \u2208 (a * b).factors \u2194 p \u2208 a.factors \u222a b.factors :=\nbegin\n  rcases a.eq_zero_or_pos with rfl | ha,\n  { simp [(coprime_zero_left _).mp hab] },\n  rcases b.eq_zero_or_pos with rfl | hb,\n  { simp [(coprime_zero_right _).mp hab] },\n  rw [mem_factors_mul ha.ne' hb.ne', list.mem_union]\nend\n\nlemma factors_mul_to_finset_of_coprime {a b : \u2115} (hab : coprime a b) :\n  (a * b).factors.to_finset = a.factors.to_finset \u222a b.factors.to_finset :=\n(list.to_finset.ext $ mem_factors_mul_of_coprime hab).trans $ list.to_finset_union _ _\n\nopen list\n\n/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/\nlemma mem_factors_mul_left {p a b : \u2115} (hpa : p \u2208 a.factors) (hb : b \u2260 0) : p \u2208 (a*b).factors :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { simpa using hpa },\n  apply (mem_factors_mul ha hb).2 (or.inl hpa),\nend\n\n/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/\nlemma mem_factors_mul_right {p a b : \u2115} (hpb : p \u2208 b.factors) (ha : a \u2260 0) : p \u2208 (a*b).factors :=\nby { rw mul_comm, exact mem_factors_mul_left hpb ha }\n\nlemma eq_two_pow_or_exists_odd_prime_and_dvd (n : \u2115) :\n  (\u2203 k : \u2115, n = 2 ^ k) \u2228 \u2203 p, nat.prime p \u2227 p \u2223 n \u2227 odd p :=\n(eq_or_ne n 0).elim\n  (\u03bb hn, (or.inr \u27e83, prime_three, hn.symm \u25b8 dvd_zero 3, \u27e81, rfl\u27e9\u27e9))\n  (\u03bb hn, or_iff_not_imp_right.mpr\n    (\u03bb H, \u27e8n.factors.length, eq_prime_pow_of_unique_prime_dvd hn\n      (\u03bb p hprime hdvd, hprime.eq_two_or_odd'.resolve_right\n        (\u03bb hodd, H \u27e8p, hprime, hdvd, hodd\u27e9))\u27e9))\n\nend nat\n\nnamespace int\nlemma prime_two : prime (2 : \u2124) := nat.prime_iff_prime_int.mp nat.prime_two\nlemma prime_three : prime (3 : \u2124) := nat.prime_iff_prime_int.mp nat.prime_three\nend int\n\nsection\nopen finset\n/-- Exactly `n / p` naturals in `[1, n]` are multiples of `p`. -/\nlemma card_multiples (n p : \u2115) : card ((range n).filter (\u03bb e, p \u2223 e + 1)) = n / p :=\nbegin\n  induction n with n hn,\n  { rw [nat.zero_div, range_zero, filter_empty, card_empty] },\n  { rw [nat.succ_div, add_ite, add_zero, range_succ, filter_insert, apply_ite card,\n      card_insert_of_not_mem (mem_filter.not.mpr (not_and_of_not_left _ not_mem_range_self)), hn] }\nend\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/nat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7200625410045377}}
{"text": "/-\n3. Above, we used the example vec \u03b1 n for vectors of elements of type \u03b1 of length n. Declare a constant vec_add that could represent a function that adds two vectors of natural numbers of the same length, and a constant vec_reverse that can represent a function that reverses its argument. Use implicit arguments for parameters that can be inferred. Declare some variables and check some expressions involving the constants that you have declared.\n-/\n\nconstant vec : Type \u2192 \u2115 \u2192 Type\nconstant vec_add : \u03a0 {\u03b1 : Type} {n : \u2115}, vec \u03b1 n \u2192 vec \u03b1 n -> vec \u03b1 n\nconstant vec_reverse : \u03a0 {\u03b1 : Type} {n : \u2115}, vec \u03b1 n \u2192 vec \u03b1 n\n\nconstant v : vec \u2115 5\n#check vec_add v v\n#check vec_reverse v\n", "meta": {"author": "ishioka0222", "repo": "theorem-proving-in-lean", "sha": "78884884cbf5b94fe2afb818e948b8168a53ea3d", "save_path": "github-repos/lean/ishioka0222-theorem-proving-in-lean", "path": "github-repos/lean/ishioka0222-theorem-proving-in-lean/theorem-proving-in-lean-78884884cbf5b94fe2afb818e948b8168a53ea3d/src/ch02-ex03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7200625360386139}}
{"text": "import data.fintype.basic\nimport linear_algebra.basic\nuniverse variables u v \n\nvariables {G :Type u} (R : Type v) [group G] \n/--\n  A central fonction is a function `f : G \u2192 R` s.t  `\u2200 s t : G, f (s * t) = f (t * s)`\n-/\ndef central_function  (f : G \u2192 R) :=  \u2200 s t : G, f (s * t) = f (t * s)\nlemma central (f : G \u2192 R)(hyp : central_function   R f) (s t : G) :  f (s * t) = f (t * s) := hyp s t \n/--\n    A central function satisfy `\u2200 s t : G, f (t\u207b\u00b9 * s * t) =  f s`\n-/\ntheorem central_function_are_constant_on_conjugacy_classses (f : G \u2192 R)(hyp : central_function  R f) \n               : \u2200 s t : G, f (t\u207b\u00b9 * s * t) =  f s :=\nbegin \n    intros s t, rw hyp,rw \u2190 mul_assoc, rw mul_inv_self, rw one_mul,\nend\nvariables [comm_ring R]\n/--\n    We show that central function form a `free R-submodule` of `G \u2192 R` \n-/\ndef central_submodule : submodule R (G \u2192 R) := { \n    carrier := \u03bb f, central_function R f,\n    zero :=  begin unfold central_function, intros s t, exact rfl end,\n    add := \n        begin \n            intros f g, intros hypf hypg, intros s t,\n            change f _ + g _ = f _ + g _, erw hypf, erw hypg,\n        end,\n    smul := \n        begin \n            intros c, intros f, intros hyp, intros s t,\n            change c \u2022 f _ = c \u2022 f _, rw hyp, \n        end \n}", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep_2/Tools/central_function_over_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7200157673577792}}
{"text": "import data.real.basic\n\ndef converges_to (s : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (s n - a) < \u03b5\n\nvariables {s : \u2115 \u2192 \u211d} {a : \u211d}\n\n-- BEGIN\n\ntheorem converges_to_const (a : \u211d) : converges_to (\u03bb x : \u2115, a) a :=\nbegin\n  intros \u03b5 epos,\n  dsimp,\n  rw sub_self,\n  norm_num, \n  use 0, \n  intros n nge,\n  exact epos, \nend\n\n#check converges_to_const\n#check abs_pos\n#check abs_pos.mp\n#check abs_pos.mpr\n\ntheorem converges_to_mul_const\n    {c : \u211d} (cs : converges_to s a) :\n  converges_to (\u03bb n, c * s n) (c * a) :=\nbegin\n  by_cases h : c = 0,\n  { convert converges_to_const 0,\n    { ext, rw [h, zero_mul] },\n    rw [h, zero_mul] },\n  have acpos : 0 < abs c,\n    from abs_pos.mpr h,\n  intros \u03b5 \u03b5pos,\n  let \u03b5' := \u03b5 / |c|,\n  have \u03b5'pos : \u03b5' > 0 := div_pos \u03b5pos acpos,\n  dsimp,\n  cases (cs (\u03b5 / |c|) \u03b5'pos) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw \u2190 mul_sub,\n  rw abs_mul,\n  exact (lt_div_iff' acpos).mp hN,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/9_Tactics used for classical reasoning/9.5_by_cases/ex2_by_cases_converges_to_mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7200157641604332}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.free_module.finite.basic\nimport linear_algebra.matrix.charpoly.coeff\nimport field_theory.minpoly.field\n\n/-!\n\n# Characteristic polynomial\n\nWe define the characteristic polynomial of `f : M \u2192\u2097[R] M`, where `M` is a finite and\nfree `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f`\nin any basis is in `linear_algebra/charpoly/to_matrix`.\n\n## Main definition\n\n* `linear_map.charpoly f` : the characteristic polynomial of `f : M \u2192\u2097[R] M`.\n\n-/\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} [comm_ring R] [nontrivial R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M] (f : M \u2192\u2097[R] M)\n\nopen_locale classical matrix polynomial\n\nnoncomputable theory\n\n\nopen module.free polynomial matrix\n\nnamespace linear_map\n\nsection basic\n\n/-- The characteristic polynomial of `f : M \u2192\u2097[R] M`. -/\ndef charpoly : R[X] :=\n(to_matrix (choose_basis R M) (choose_basis R M) f).charpoly\n\n\n\nend basic\n\nsection coeff\n\nlemma charpoly_monic : f.charpoly.monic := charpoly_monic _\n\nend coeff\n\nsection cayley_hamilton\n\n/-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied\nto the linear map itself, is zero.\n\nSee `matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/\nlemma aeval_self_charpoly : aeval f f.charpoly = 0 :=\nbegin\n  apply (linear_equiv.map_eq_zero_iff (alg_equiv_matrix (choose_basis R M)).to_linear_equiv).1,\n  rw [alg_equiv.to_linear_equiv_apply, \u2190 alg_equiv.coe_alg_hom,\n    \u2190 polynomial.aeval_alg_hom_apply _ _ _, charpoly_def],\n  exact aeval_self_charpoly _,\nend\n\nlemma is_integral : is_integral R f := \u27e8f.charpoly, \u27e8charpoly_monic f, aeval_self_charpoly f\u27e9\u27e9\n\nlemma minpoly_dvd_charpoly {K : Type u} {M : Type v} [field K] [add_comm_group M] [module K M]\n  [finite_dimensional K M] (f : M \u2192\u2097[K] M) : minpoly K f \u2223 f.charpoly :=\nminpoly.dvd _ _ (aeval_self_charpoly f)\n\n/-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %\u2098 f.charpoly`; that is,\n`p` is equivalent to a polynomial with degree less than the dimension of the module. -/\nlemma aeval_eq_aeval_mod_charpoly (p : R[X]) : aeval f p = aeval f (p %\u2098 f.charpoly) :=\n(aeval_mod_by_monic_eq_self_of_root f.charpoly_monic f.aeval_self_charpoly).symm\n\n/-- Any endomorphism power can be computed as the sum of endomorphism powers less than the\ndimension of the module. -/\nlemma pow_eq_aeval_mod_charpoly (k : \u2115) : f^k = aeval f (X^k %\u2098 f.charpoly) :=\nby rw [\u2190aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]\n\nvariable {f}\n\nlemma minpoly_coeff_zero_of_injective (hf : function.injective f) : (minpoly R f).coeff 0 \u2260 0 :=\nbegin\n  intro h,\n  obtain \u27e8P, hP\u27e9 := X_dvd_iff.2 h,\n  have hdegP : P.degree < (minpoly R f).degree,\n  { rw [hP, mul_comm],\n    refine degree_lt_degree_mul_X (\u03bb h, _),\n    rw [h, mul_zero] at hP,\n    exact minpoly.ne_zero (is_integral f) hP },\n  have hPmonic : P.monic,\n  { suffices : (minpoly R f).monic,\n    { rwa [monic.def, hP, mul_comm, leading_coeff_mul_X, \u2190 monic.def] at this },\n    exact minpoly.monic (is_integral f) },\n  have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _,\n  simp only [hP, mul_eq_comp, ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp, alg_hom.map_mul,\n    zero_apply] at hzero,\n  exact not_le.2 hdegP (minpoly.min _ _ hPmonic (ext hzero)),\nend\n\nend cayley_hamilton\n\nend linear_map\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7199639966982503}}
{"text": "import tactic\n\n/-!\n\n# Equivalence relations are the same as partitions\n\nIn this file we prove that there's a bijection between\nthe equivalence relations on a type, and the partitions of a type. \n\nThree sections:\n\n1) partitions\n2) equivalence classes\n3) the proof\n\n## Overview\n\nSay `\u03b1` is a type, and `R : \u03b1 \u2192 \u03b1 \u2192 Prop` is a binary relation on `\u03b1`. \nThe following things are already in Lean:\n\n`reflexive R := \u2200 (x : \u03b1), R x x`\n`symmetric R := \u2200 \u2983x y : \u03b1\u2984, R x y \u2192 R y x`\n`transitive R := \u2200 \u2983x y z : \u03b1\u2984, R x y \u2192 R y z \u2192 R x z`\n\n`equivalence R := reflexive R \u2227 symmetric R \u2227 transitive R`\n\nIn the file below, we will define partitions of `\u03b1` and \"build some\ninterface\" (i.e. prove some propositions). We will define\nequivalence classes and do the same thing.\nFinally, we will prove that there's a bijection between\nequivalence relations on `\u03b1` and partitions of `\u03b1`.\n\n-/\n\n/-\n\n# 1) Partitions\n\nWe define a partition, and prove some lemmas about partitions. Some\nI prove myself (not always using tactics) and some I leave for you.\n\n## Definition of a partition\n\nLet `\u03b1` be a type. A *partition* on `\u03b1` is defined to be\nthe following data:\n\n1) A set C of subsets of \u03b1, called \"blocks\".\n2) A hypothesis (i.e. a proof!) that all the blocks are non-empty.\n3) A hypothesis that every term of type \u03b1 is in one of the blocks.\n4) A hypothesis that two blocks with non-empty intersection are equal.\n-/\n\n/-- The structure of a partition on a Type \u03b1. -/ \n@[ext] structure partition (\u03b1 : Type) :=\n(C : set (set \u03b1))\n(Hnonempty : \u2200 X \u2208 C, (X : set \u03b1).nonempty)\n(Hcover : \u2200 a, \u2203 X \u2208 C, a \u2208 X)\n(Hdisjoint : \u2200 X Y \u2208 C, (X \u2229 Y : set \u03b1).nonempty \u2192 X = Y)\n\n/-\n\n## Basic interface for partitions\n\nHere's the way notation works. If `\u03b1` is a type (i.e. a set)\nthen a term `P` of type `partition \u03b1` is a partition of `\u03b1`,\nthat is, a set of disjoint nonempty subsets of `\u03b1` whose union is `\u03b1`.\n\nThe collection of sets underlying `P` is `P.C`, the proof that\nthey're all nonempty is `P.Hnonempty` and so on.\n\n-/\n\nnamespace partition\n\n-- let \u03b1 be a type, and fix a partition P on \u03b1. Let X and Y be subsets of \u03b1.\nvariables {\u03b1 : Type} {P : partition \u03b1} {X Y : set \u03b1}\n\n/-- If X and Y are blocks, and a is in X and Y, then X = Y. -/\ntheorem eq_of_mem (hX : X \u2208 P.C) (hY : Y \u2208 P.C) {a : \u03b1} (haX : a \u2208 X)\n  (haY : a \u2208 Y) : X = Y :=\n-- Proof: follows immediately from the disjointness hypothesis.\nP.Hdisjoint _ _ hX hY \u27e8a, haX, haY\u27e9\n\n/-- If a is in two blocks X and Y, and if b is in X,\n  then b is in Y (as X=Y) -/\ntheorem mem_of_mem (hX : X \u2208 P.C) (hY : Y \u2208 P.C) {a b : \u03b1}\n  (haX : a \u2208 X) (haY : a \u2208 Y) (hbX : b \u2208 X) : b \u2208 Y :=\nbegin\n  -- you might want to start with `have hXY : X = Y`\n  -- and prove it from the previous lemma\n  sorry,\nend\n\n/-- Every term of type `\u03b1` is in one of the blocks for a partition `P`. -/\ntheorem mem_block (a : \u03b1) : \u2203 X : set \u03b1, X \u2208 P.C \u2227 a \u2208 X :=\nbegin\n  -- an interesting way to start is\n  -- `obtain \u27e8X, hX, haX\u27e9 := P.Hcover a,`\n  sorry,\nend\n\nend partition\n\n/-\n\n# 2) Equivalence classes.\n\nWe define equivalence classes and prove a few basic results about them.\n\n-/\n\nsection equivalence_classes\n\n/-!\n\n## Definition of equivalence classes \n\n-/\n\n-- Notation and variables for the equivalence class section:\n\n-- let \u03b1 be a type, and let R be a binary relation on R.\nvariables {\u03b1 : Type} (R : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n/-- The equivalence class of `a` is the set of `b` related to `a`. -/\ndef cl (a : \u03b1) :=\n{b : \u03b1 | R b a}\n\n/-!\n\n## Basic lemmas about equivalence classes\n\n-/\n\n/-- Useful for rewriting -- `b` is in the equivalence class of `a` iff\n`b` is related to `a`. True by definition. -/\ntheorem mem_cl_iff {a b : \u03b1} : b \u2208 cl R a \u2194 R b a :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- Assume now that R is an equivalence relation.\nvariables {R} (hR : equivalence R)\ninclude hR\n\n/-- x is in cl(x) -/\nlemma mem_cl_self (a : \u03b1) :\n  a \u2208 cl R a :=\nbegin\n  -- Note that `hR : equivalence R` is a package of three things.\n  -- You can extract the things with\n  -- `rcases hR with \u27e8hrefl, hsymm, htrans\u27e9,` or\n  -- `obtain \u27e8hrefl, hsymm, htrans\u27e9 := hR,`\n  sorry,\nend\n\nlemma cl_sub_cl_of_mem_cl {a b : \u03b1} :\n  a \u2208 cl R b \u2192\n  cl R a \u2286 cl R b :=\nbegin\n  -- remember `set.subset_def` says `X \u2286 Y \u2194 \u2200 a, a \u2208 X \u2192 a \u2208 Y\n  sorry,\nend\n\nlemma cl_eq_cl_of_mem_cl {a b : \u03b1} :\n  a \u2208 cl R b \u2192\n  cl R a = cl R b :=\nbegin\n  -- remember `set.subset.antisymm` says `X \u2286 Y \u2192 Y \u2286 X \u2192 X = Y`\n  sorry\nend\n\nend equivalence_classes -- section\n\n/-!\n\n# 3) The theorem\n\nLet `\u03b1` be a type (i.e. a collection of stucff).\n\nThere is a bijection between equivalence relations on `\u03b1` and\npartitions of `\u03b1`.\n\nWe prove this by writing down constructions in each direction\nand proving that the constructions are two-sided inverses of one another.\n-/\n\nopen partition\n\n\nexample (\u03b1 : Type) : {R : \u03b1 \u2192 \u03b1 \u2192 Prop // equivalence R} \u2243 partition \u03b1 :=\n-- We define constructions (functions!) in both directions and prove that\n-- one is a two-sided inverse of the other\n{ -- Here is the first construction, from equivalence\n  -- relations to partitions.\n  -- Let R be an equivalence relation.\n  to_fun := \u03bb R, {\n    -- Let C be the set of equivalence classes for R.\n    C := { B : set \u03b1 | \u2203 x : \u03b1, B = cl R.1 x},\n    -- I claim that C is a partition. We need to check the three\n    -- hypotheses for a partition (`Hnonempty`, `Hcover` and `Hdisjoint`),\n    -- so we need to supply three proofs.\n    Hnonempty := begin\n      cases R with R hR,\n      -- If X is an equivalence class then X is nonempty.\n      show \u2200 (X : set \u03b1), (\u2203 (a : \u03b1), X = cl R a) \u2192 X.nonempty,\n      sorry,\n    end,\n    Hcover := begin\n      cases R with R hR,\n      -- The equivalence classes cover \u03b1\n      show \u2200 (a : \u03b1), \u2203 (X : set \u03b1) (H : \u2203 (b : \u03b1), X = cl R b), a \u2208 X,\n      sorry,\n    end,\n    Hdisjoint := begin\n      cases R with R hR,\n      -- If two equivalence classes overlap, they are equal.\n      show \u2200 (X Y : set \u03b1), (\u2203 (a : \u03b1), X = cl R a) \u2192\n        (\u2203 (b : \u03b1), Y = cl _ b) \u2192 (X \u2229 Y).nonempty \u2192 X = Y,\n      sorry,\n    end },\n  -- Conversely, say P is an partition. \n  inv_fun := \u03bb P, \n    -- Let's define a binary relation `R` thus:\n    --  `R a b` iff *every* block containing `a` also contains `b`.\n    -- Because only one block contains a, this will work,\n    -- and it turns out to be a nice way of thinking about it. \n    \u27e8\u03bb a b, \u2200 X \u2208 P.C, a \u2208 X \u2192 b \u2208 X, begin\n      -- I claim this is an equivalence relation.\n    split,\n    { -- It's reflexive\n      show \u2200 (a : \u03b1)\n        (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 a \u2208 X,\n      sorry,\n    },\n    split,\n    { -- it's symmetric\n      show \u2200 (a b : \u03b1),\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 b \u2208 X) \u2192\n         \u2200 (X : set \u03b1), X \u2208 P.C \u2192 b \u2208 X \u2192 a \u2208 X,\n      sorry,\n    },\n    { -- it's transitive\n      unfold transitive,\n      show \u2200 (a b c : \u03b1),\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 b \u2208 X) \u2192\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 b \u2208 X \u2192 c \u2208 X) \u2192\n         \u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 c \u2208 X,\n      sorry,\n    }\n  end\u27e9,\n  -- If you start with the equivalence relation, and then make the partition\n  -- and a new equivalence relation, you get back to where you started.\n  left_inv := begin\n    rintro \u27e8R, hR\u27e9,\n    -- Tidying up the mess...\n    suffices : (\u03bb (a b : \u03b1), \u2200 (c : \u03b1), a \u2208 cl R c \u2192 b \u2208 cl R c) = R,\n      simpa,\n    -- ... you have to prove two binary relations are equal.\n    ext a b,\n    -- so you have to prove an if and only if.\n    show (\u2200 (c : \u03b1), a \u2208 cl R c \u2192 b \u2208 cl R c) \u2194 R a b,\n    sorry,\n  end,\n  -- Similarly, if you start with the partition, and then make the\n  -- equivalence relation, and then construct the corresponding partition \n  -- into equivalence classes, you have the same partition you started with.  \n  right_inv := begin\n    -- Let P be a partition\n    intro P,\n    -- It suffices to prove that a subset X is in the original partition\n    -- if and only if it's in the one made from the equivalence relation.\n    ext X,\n    show (\u2203 (a : \u03b1), X = cl _ a) \u2194 X \u2208 P.C,\n    dsimp only,\n    sorry,\n  end }\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_1/Part_D_relations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7199639900929795}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function World\n\n## Level 6: `(P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R))`.\n\nYou can solve this level completely just using `intro`, `apply` and `exact`,\nbut if you want to argue forwards instead of backwards then don't forget\nthat you can do things like\n\n`have j : Q \u2192 R := f p`\n\nif `f : P \u2192 (Q \u2192 R)` and `p : P`. Remember the trick with the colon in `have`:\nwe could just write `have j := f p` but this way we can be sure that `j` is\nwhat we actually expect it to be.\n\nWe start with `intro f` rather than `intro p`\nbecause even though the goal starts `P \u2192 ...`, the brackets mean that\nthe goal is not a function from `P` to anything, it's a function from\n`P \u2192 (Q \u2192 R)` to something. In fact you can save time by starting\nwith `intros f h p`, which introduces three variables at once, although you'd\nbetter then look at your tactic state to check that you called all those new\nterms sensible things.\n\nAfter all the intros, you find that the goal is `\u22a2 R`. If you try `have j : Q \u2192 R := f p`\nnow then you can `apply j`. Alternatively you can `apply (f p)` directly.\nWhat happens if you just try `apply f`? Can you figure out what just happened? This is a little\n`apply` easter egg. Why is it mathematically valid?\n\n## Definition\nWhatever the sets  `P ` and  `Q ` and  `R ` are, we\nmake an element of \\\\(\\operatorname{Hom}(\\operatorname{Hom}(P,\\operatorname{Hom}(Q,R)),\n\\operatorname{Hom}(\\operatorname{Hom}(P,Q),\\operatorname{Hom}(P,R)))\\\\).\n-/\nexample (P Q R : Type) : (P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R)) := by\n  intro f\n  intro h\n  intro p\n  have j : Q \u2192 R := f p\n  apply j\n  apply h\n  exact p\n\n/-!\n\nNext up [Level 7](./Level7.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/FunctionWorld/Level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7199192957198176}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\nLebesgue measure on the real line\n-/\nimport analysis.measure_theory.measure_space analysis.measure_theory.borel_space\nnoncomputable theory\nopen classical set lattice filter\nopen nnreal (of_real)\n\nnamespace measure_theory\n\n/-- Length of an interval. This is the largest monotonic function which correctly\n  measures all intervals. -/\ndef lebesgue_length (s : set \u211d) : ennreal := \u2a05a b (h : s \u2286 Ico a b), of_real (b - a)\n\n@[simp] lemma lebesgue_length_empty : lebesgue_length \u2205 = 0 :=\nle_zero_iff_eq.1 $ infi_le_of_le 0 $ infi_le_of_le 0 $ by simp\n\n@[simp] lemma lebesgue_length_Ico (a b : \u211d) :\n  lebesgue_length (Ico a b) = of_real (b - a) :=\nbegin\n  refine le_antisymm (infi_le_of_le a $ infi_le_of_le b $ infi_le _ (by refl))\n    (le_infi $ \u03bb a', le_infi $ \u03bb b', le_infi $ \u03bb h, ennreal.coe_le_coe.2 _),\n  cases le_or_lt b a with ab ab,\n  { rw nnreal.of_real_of_nonpos (sub_nonpos.2 ab), simp },\n  cases (Ico_subset_Ico_iff ab).1 h with h\u2081 h\u2082,\n  exact nnreal.of_real_le_of_real (sub_le_sub h\u2082 h\u2081)\nend\n\nlemma lebesgue_length_mono {s\u2081 s\u2082 : set \u211d} (h : s\u2081 \u2286 s\u2082) : lebesgue_length s\u2081 \u2264 lebesgue_length s\u2082 :=\ninfi_le_infi $ \u03bb a, infi_le_infi $ \u03bb b, infi_le_infi2 $ \u03bb h', \u27e8subset.trans h h', le_refl _\u27e9\n\nlemma lebesgue_length_eq_infi_Ioo (s) : lebesgue_length s = \u2a05a b (h : s \u2286 Ioo a b), of_real (b - a) :=\nbegin\n  refine le_antisymm\n    (infi_le_infi $ \u03bb a, infi_le_infi $ \u03bb b, infi_le_infi2 $ \u03bb h,\n      \u27e8subset.trans h Ioo_subset_Ico_self, le_refl _\u27e9) _,\n  refine le_infi (\u03bb a, le_infi $ \u03bb b, le_infi $ \u03bb h, _),\n  refine ennreal.le_of_forall_epsilon_le (\u03bb \u03b5 \u03b50 _, _),\n  refine infi_le_of_le (a - \u03b5) (infi_le_of_le b $ infi_le_of_le\n    (subset.trans h $ Ico_subset_Ioo_left $ (sub_lt_self_iff _).2 \u03b50) _),\n  rw [\u2190 sub_add, \u2190 ennreal.coe_add, ennreal.coe_le_coe],\n  apply le_trans nnreal.of_real_add_le _,\n  simp,\nend\n\n@[simp] lemma lebesgue_length_Ioo (a b : \u211d) :\n  lebesgue_length (Ioo a b) = of_real (b - a) :=\nbegin\n  rw \u2190 lebesgue_length_Ico,\n  refine le_antisymm (lebesgue_length_mono Ioo_subset_Ico_self) _,\n  rw lebesgue_length_eq_infi_Ioo (Ioo a b),\n  refine (le_infi $ \u03bb a', le_infi $ \u03bb b', le_infi $ \u03bb h, _),\n  cases le_or_lt b a with ab ab, {simp [ab]},\n  cases (Ioo_subset_Ioo_iff ab).1 h with h\u2081 h\u2082,\n  rw [lebesgue_length_Ico, ennreal.coe_le_coe],\n  exact nnreal.of_real_le_of_real (sub_le_sub h\u2082 h\u2081)\nend\n\nlemma lebesgue_length_eq_infi_Icc (s) : lebesgue_length s = \u2a05a b (h : s \u2286 Icc a b), of_real (b - a) :=\nbegin\n  refine le_antisymm _\n    (infi_le_infi $ \u03bb a, infi_le_infi $ \u03bb b, infi_le_infi2 $ \u03bb h,\n      \u27e8subset.trans h Ico_subset_Icc_self, le_refl _\u27e9),\n  refine le_infi (\u03bb a, le_infi $ \u03bb b, le_infi $ \u03bb h, _),\n  refine ennreal.le_of_forall_epsilon_le (\u03bb \u03b5 \u03b50 _, _),\n  refine infi_le_of_le a (infi_le_of_le (b + \u03b5) $ infi_le_of_le\n    (subset.trans h $ Icc_subset_Ico_right $ (lt_add_iff_pos_right _).2 \u03b50) _),\n  rw [sub_eq_add_neg, add_right_comm, \u2190ennreal.coe_add, ennreal.coe_le_coe],\n  apply le_trans nnreal.of_real_add_le,\n  simp\nend\n\n@[simp] lemma lebesgue_length_Icc (a b : \u211d) :\n  lebesgue_length (Icc a b) = of_real (b - a) :=\nbegin\n  rw \u2190 lebesgue_length_Ico,\n  refine le_antisymm _ (lebesgue_length_mono Ico_subset_Icc_self),\n  rw lebesgue_length_eq_infi_Icc (Icc a b),\n  exact infi_le_of_le a (infi_le_of_le b $ infi_le_of_le (by refl) (by simp))\nend\n\n/-- The Lebesgue outer measure, as an outer measure of \u211d. -/\ndef lebesgue_outer : outer_measure \u211d :=\nouter_measure.of_function lebesgue_length lebesgue_length_empty\n\nlemma lebesgue_outer_le_length (s : set \u211d) : lebesgue_outer s \u2264 lebesgue_length s :=\nouter_measure.of_function_le _ _ _\n\nlemma lebesgue_length_subadditive {a b : \u211d} {c d : \u2115 \u2192 \u211d}\n  (ss : Icc a b \u2286 \u22c3i, Ioo (c i) (d i)) :\n  (of_real (b - a) : ennreal) \u2264 \u2211 i, of_real (d i - c i) :=\nbegin\n  suffices : \u2200 (s:finset \u2115) b\n    (cv : Icc a b \u2286 \u22c3 i \u2208 (\u2191s:set \u2115), Ioo (c i) (d i)),\n    (of_real (b - a) : ennreal) \u2264 s.sum (\u03bb i, of_real (d i - c i)),\n  { rcases @compact_elim_finite_subcover_image _ _\n      _ (Icc a b) univ (\u03bb i, Ioo (c i) (d i)) compact_Icc\n      (\u03bb i _, is_open_Ioo) (by simpa using ss) with \u27e8s, su, hf, hs\u27e9,\n    have e : (\u22c3 i \u2208 (\u2191hf.to_finset:set \u2115),\n      Ioo (c i) (d i)) = (\u22c3 i \u2208 s, Ioo (c i) (d i)), {simp [set.ext_iff]},\n    rw ennreal.tsum_eq_supr_sum,\n    refine le_trans _ (le_supr _ hf.to_finset),\n    exact this hf.to_finset _ (by simpa [e]) },\n  clear ss b,\n  refine \u03bb s, finset.strong_induction_on s (\u03bb s IH b cv, _),\n  cases le_total b a with ab ab,\n  { rw nnreal.of_real_of_nonpos (sub_nonpos.2 ab), simp },\n  have := cv \u27e8ab, le_refl _\u27e9, simp at this,\n  rcases this with \u27e8i, is, cb, bd\u27e9,\n  rw [\u2190 finset.insert_erase is] at cv \u22a2,\n  rw [finset.coe_insert, bUnion_insert] at cv,\n  rw [finset.sum_insert (finset.not_mem_erase _ _)],\n  refine le_trans _ (add_le_add_left' (IH _ (finset.erase_ssubset is) (c i) _)),\n  { rw [\u2190 ennreal.coe_add, ennreal.coe_le_coe],\n    refine le_trans (nnreal.of_real_le_of_real _) nnreal.of_real_add_le,\n    rw sub_add_sub_cancel,\n    exact sub_le_sub_right (le_of_lt bd) _ },\n  { rintro x \u27e8h\u2081, h\u2082\u27e9,\n    refine (cv \u27e8h\u2081, le_trans h\u2082 (le_of_lt cb)\u27e9).resolve_left\n      (mt and.left (not_lt_of_le h\u2082)) }\nend\n\n@[simp] lemma lebesgue_outer_Icc (a b : \u211d) :\n  lebesgue_outer (Icc a b) = of_real (b - a) :=\nbegin\n  refine le_antisymm (by rw \u2190 lebesgue_length_Icc; apply lebesgue_outer_le_length)\n    (le_infi $ \u03bb f, le_infi $ \u03bb hf,\n    ennreal.le_of_forall_epsilon_le $ \u03bb \u03b5 \u03b50 h, _),\n  rcases ennreal.exists_pos_sum_of_encodable\n    (ennreal.zero_lt_coe_iff.2 \u03b50) \u2115 with \u27e8\u03b5', \u03b5'0, h\u03b5\u27e9,\n  refine le_trans _ (add_le_add_left' (le_of_lt h\u03b5)),\n  rw \u2190 ennreal.tsum_add,\n  have : \u2200 i, \u2203 p:\u211d\u00d7\u211d, f i \u2286 Ioo p.1 p.2 \u2227 (of_real (p.2 - p.1) : ennreal) <\n    lebesgue_length (f i) + \u03b5' i,\n  { intro i,\n    have := (ennreal.lt_add_right (lt_of_le_of_lt (ennreal.le_tsum i) h)\n        (ennreal.zero_lt_coe_iff.2 (\u03b5'0 i))),\n    conv at this {to_lhs, rw lebesgue_length_eq_infi_Ioo},\n    simpa [infi_lt_iff] },\n  cases axiom_of_choice this with g hg, dsimp only at g hg,\n  refine le_trans _ (ennreal.tsum_le_tsum $ \u03bb i, le_of_lt (hg i).2),\n  exact lebesgue_length_subadditive (subset.trans hf $\n    Union_subset_Union $ \u03bb i, (hg i).1)\nend\n\n@[simp] lemma lebesgue_outer_singleton (a : \u211d) : lebesgue_outer {a} = 0 :=\nby simpa using lebesgue_outer_Icc a a\n\n@[simp] lemma lebesgue_outer_Ico (a b : \u211d) :\n  lebesgue_outer (Ico a b) = of_real (b - a) :=\nbegin\n  refine le_antisymm (by rw \u2190 lebesgue_length_Ico; apply lebesgue_outer_le_length)\n    (ennreal.le_of_forall_epsilon_le $ \u03bb \u03b5 \u03b50 h, _),\n  have := @nnreal.of_real_add_le (b - a - \u03b5) \u03b5,\n  rw [\u2190 ennreal.coe_le_coe, ennreal.coe_add, sub_add_cancel, sub_right_comm,\n    \u2190 lebesgue_outer_Icc a (b-\u03b5), nnreal.of_real_coe] at this,\n  exact le_trans this (add_le_add_right' $ lebesgue_outer.mono $\n    Icc_subset_Ico_right $ (sub_lt_self_iff _).2 \u03b50)\nend\n\n@[simp] lemma lebesgue_outer_Ioo (a b : \u211d) :\n  lebesgue_outer (Ioo a b) = of_real (b - a) :=\nbegin\n  refine le_antisymm (by rw \u2190 lebesgue_length_Ioo; apply lebesgue_outer_le_length)\n    (ennreal.le_of_forall_epsilon_le $ \u03bb \u03b5 \u03b50 h, _),\n  have := @nnreal.of_real_add_le (b - a - \u03b5) \u03b5,\n  rw [\u2190 ennreal.coe_le_coe, ennreal.coe_add, sub_add_cancel, sub_sub,\n    \u2190 lebesgue_outer_Ico (a+\u03b5) b, nnreal.of_real_coe] at this,\n  exact le_trans this (add_le_add_right' $ lebesgue_outer.mono $\n    Ico_subset_Ioo_left $ (lt_add_iff_pos_right _).2 \u03b50)\nend\n\nlemma is_lebesgue_measurable_Iio {c : \u211d} :\n  lebesgue_outer.caratheodory.is_measurable (Iio c) :=\nouter_measure.caratheodory_is_measurable $ \u03bb t,\nle_infi $ \u03bb a, le_infi $ \u03bb b, le_infi $ \u03bb h, begin\n  refine le_trans (add_le_add'\n    (lebesgue_length_mono $ inter_subset_inter_left _ h)\n    (lebesgue_length_mono $ diff_subset_diff_left h)) _,\n  cases le_total a c with hac hca; cases le_total b c with hbc hcb;\n    simp [*, -sub_eq_add_neg, sub_add_sub_cancel'];\n    rw [\u2190 ennreal.coe_add, ennreal.coe_le_coe],\n  { simp [*, nnreal.of_real_add_of_real, -sub_eq_add_neg, sub_add_sub_cancel'] },\n  { rw nnreal.of_real_of_nonpos,\n    { simp },\n    exact sub_nonpos.2 (le_trans hbc hca) }\nend\n\ntheorem lebesgue_outer_trim : lebesgue_outer.trim = lebesgue_outer :=\nbegin\n  refine le_antisymm (\u03bb s, _) (outer_measure.trim_ge _),\n  rw outer_measure.trim_eq_infi,\n  refine le_infi (\u03bb f, le_infi $ \u03bb hf,\n    ennreal.le_of_forall_epsilon_le $ \u03bb \u03b5 \u03b50 h, _),\n  rcases ennreal.exists_pos_sum_of_encodable\n    (ennreal.zero_lt_coe_iff.2 \u03b50) \u2115 with \u27e8\u03b5', \u03b5'0, h\u03b5\u27e9,\n  refine le_trans _ (add_le_add_left' (le_of_lt h\u03b5)),\n  rw \u2190 ennreal.tsum_add,\n  have : \u2200 i, \u2203 s, f i \u2286 s \u2227 is_measurable s \u2227\n    lebesgue_outer s \u2264 lebesgue_length (f i) + of_real (\u03b5' i),\n  { intro i,\n    have := (ennreal.lt_add_right (lt_of_le_of_lt (ennreal.le_tsum i) h)\n        (ennreal.zero_lt_coe_iff.2 (\u03b5'0 i))),\n    conv at this {to_lhs, rw lebesgue_length},\n    simp only [infi_lt_iff] at this,\n    rcases this with \u27e8a, b, h\u2081, h\u2082\u27e9,\n    rw \u2190 lebesgue_outer_Ico at h\u2082,\n    exact \u27e8_, h\u2081, is_measurable_Ico, le_of_lt $ by simpa using h\u2082\u27e9 },\n  cases axiom_of_choice this with g hg, simp at g hg,\n  apply infi_le_of_le (Union g) _,\n  apply infi_le_of_le (subset.trans hf $ Union_subset_Union (\u03bb i, (hg i).1)) _,\n  apply infi_le_of_le (is_measurable.Union (\u03bb i, (hg i).2.1)) _,\n  exact le_trans (lebesgue_outer.Union _) (ennreal.tsum_le_tsum $ \u03bb i, (hg i).2.2)\nend\n\n/-- Lebesgue measure on the Borel sets\n\nThe outer Lebesgue measure is the completion of this measure. (TODO: proof this)\n-/\ndef lebesgue : measure \u211d :=\nlebesgue_outer.to_measure $\n  calc borel \u211d = measurable_space.generate_from (\u22c3a:\u211a, {Iio a}) :\n      real.borel_eq_generate_from_Iio_rat\n    ... \u2264 lebesgue_outer.caratheodory :\n      measurable_space.generate_from_le $ by simp [is_lebesgue_measurable_Iio] {contextual := tt}\n\n@[simp] theorem lebesgue_to_outer_measure : lebesgue.to_outer_measure = lebesgue_outer :=\n(to_measure_to_outer_measure _ _).trans lebesgue_outer_trim\n\ntheorem lebesgue_val (s) : lebesgue s = lebesgue_outer s :=\n(congr_arg (\u03bb m:outer_measure \u211d, m s) lebesgue_to_outer_measure : _)\n\n@[simp] lemma lebesgue_Ico {a b : \u211d} : lebesgue (Ico a b) = of_real (b - a) :=\nby simp [lebesgue_val]\n\n@[simp] lemma lebesgue_Icc {a b : \u211d} : lebesgue (Icc a b) = of_real (b - a) :=\nby simp [lebesgue_val]\n\n@[simp] lemma lebesgue_Ioo {a b : \u211d} : lebesgue (Ioo a b) = of_real (b - a) :=\nby simp [lebesgue_val]\n\n@[simp] lemma lebesgue_singleton {a : \u211d} : lebesgue {a} = 0 :=\nby simp [lebesgue_val]\n\nend measure_theory\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/analysis/measure_theory/lebesgue_measure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.719914249757485}}
{"text": "import formal_system\n\nopen logic\n\nsection propositional_logic\n\ninductive proposition\n| false : proposition\n| true : proposition\n| atomic : \u2115 \u2192 proposition\n| and : proposition \u2192 proposition \u2192 proposition\n| or : proposition \u2192 proposition \u2192 proposition\n| if_then : proposition \u2192 proposition \u2192 proposition\n\ninstance proposition_exp : has_exp proposition := \u27e8proposition.if_then\u27e9\n\ndef proposition.iff : proposition \u2192 proposition \u2192 proposition := \u03bb p q, proposition.and (p \u21d2 q) (q \u21d2 p) \n\ndef proposition.not :  proposition \u2192 proposition := \u03bb p, p \u21d2 proposition.false\n\n#check combinator.K\n#check combinator.S\n\ndef hilbert_axioms : set proposition := \n    \u22c3\u03c6 \u03c8 \u03b3,  \n    {\n     \u03c6 \u21d2 \u03c8 \u21d2 \u03c6, -- K combinator\n     (\u03c6 \u21d2 \u03c8 \u21d2 \u03b3) \u21d2 (\u03c6 \u21d2 \u03c8) \u21d2 (\u03c6 \u21d2 \u03b3), -- S combinator\n     proposition.true\n    }\n\nnoncomputable instance deq_proposition : decidable_eq proposition := \n        by intros \u03c6 \u03c8; exact classical.prop_decidable (\u03c6 = \u03c8)\n\n        --this is an old failed attempt to remove the \"noncomputable\" above.\n        -- It is surprisingly effective, until it isn't, i.e. it reduces 64 goals to 5, but then\n        -- the and, or, and if_then make the proof of the remaining goals too hard or impossible. \n\n        --begin \n        --induction a; induction b; simp,\n        --repeat {apply_instance};\n        --admit\n        --end\n\n        -- TODO: show an isomorphism between propositions and naturals or strings,\n        -- and then derive the equality from their respective equalities.\n\n\ndef proof_from (\u0393 : set proposition) (conclusion : proposition) : list proposition \u2192 Prop\n| [] := false\n| (\u03c6 :: xs) :=  \n    let S := {x | x \u2208 xs} \u222a \u0393 \u222a hilbert_axioms in\n    \u03c6 = conclusion \u2227\n    (\u03c6 \u2208 \u0393 \u222a hilbert_axioms \u2228\n    (\u2203 \u03c8, \u03c8 \u2208 S \u2227 \u03c8 \u21d2 \u03c6 \u2208 S))\n\ndef proof_of (conclusion : proposition) (\u0393 : set proposition) : list proposition \u2192 Prop := \u03bb l, proof_from \u0393 conclusion l\n\ninstance minimal_Tarski : Tarski_system := \n{ formula := proposition,\n  entails := \u03bb \u0393 \u03c6, \u2203 l : list proposition, proof_from \u0393 \u03c6 l,\n  reflexivity := \n    begin\n        intros \u0393 \u03c6 h,\n        dsimp at *,\n        fsplit,\n        exact [\u03c6],\n        constructor, refl,\n        left, left,\n        exact h\n    end,\n  transitivity := \n    begin\n        intros \u0393 \u0394 \u03c6 h\u2081 h\u2082,\n        cases h\u2082 with proof h\u2083,\n        dsimp at *,\n        cases proof with head tail,\n            exact false.elim h\u2083,\n        cases h\u2083 with c\u2081 c\u2082,\n        rewrite c\u2081 at c\u2082,\n        cases c\u2082 with easy hard,\n            cases easy, exact h\u2081 \u03c6 easy,\n            fsplit, exact [\u03c6],\n            constructor, refl,\n            left, right, exact easy,\n        cases hard with \u03c8 h\u2082,\n        fsplit,\n            exact [\u03c6, \u03c8, proposition.if_then \u03c8 \u03c6] ++ tail,\n        constructor, refl,\n        right, existsi \u03c8,\n        constructor; left; simp,\n        left, right, left, refl,\n    end\n}\n\n--   finitary := \n--     begin \n--         intros \u0393 \u03c6 h,\n--         cases h with proof is_proof,\n--         dsimp at *,\n--         simp at *,\n--         existsi proof.to_finset.to_set \u2229 \u0393,\n--         split, simp, split,\n--             suffices h : finite (finset.to_set (list.to_finset proof)),\n--             from \u27e8@set.fintype_inter proposition\n--                 (finset.to_set (list.to_finset proof)) \u0393 h.fintype (classical.dec_pred \u0393)\u27e9,\n--             apply finite_mem_finset,\n--         existsi proof,\n--         cases proof with head tail, \n--             exact false.elim is_proof,\n--         cases is_proof with p\u2081 p\u2082,\n--         split, assumption,\n--         unfold finset.to_set, simp at *,\n--         cases p\u2082 with c\u2081 c\u2082,\n--             left, cases c\u2081,\n--                 left, assumption,\n--             right, assumption,\n--         cases c\u2082 with \u03c8 h,\n--         cases h with h\u2081 h\u2082,\n--         right, existsi \u03c8,\n--         constructor,\n--         cases h\u2081 with c\u2081 c\u2082,\n--             left, exact c\u2081,\n--         right,\n--         cases c\u2082 with c\u2081 c\u2082, right,\n\n\n        \n        -- all_goals \n        --     {cases h\u2081 with c\u2081 c\u2082;\n        --      try{cases c\u2082};\n        --      cases h\u2082 with c\u2083 c\u2084;\n        --      try{cases c\u2084}\n        --     },\n        -- repeat {left <|> right, assumption},\n        -- any_goals {left, assumption},\n        -- all_goals {right, try{cases c\u2082}},\n        -- any_goals {right, assumption},\n        -- all_goals {try{cases c\u2084}},\n        -- any_goals {right, assumption},\n\n\n        --dsimp at *, fsplit, work_on_goal 0 { fsplit, fsplit, work_on_goal 0 { fsplit }, work_on_goal 2 { intros x, cases x, simp at * } }, work_on_goal 3 { fsplit, work_on_goal 1 { assumption } } } \n    --end\n\n-- instance minimal_propositional_logic : minimal_logic :=\n-- {\n--   encoding := _,\n--   recursive := _,\n--   connectives := _,\n--   deduction_order := _,\n--   and_intro := _,\n--   or_elim := _,\n--   True := proposition.true,\n--   True_intro := _,\n--   False := proposition.false,\n--   implication := \u27e8proposition.if_then\u27e9,\n--   implication_definition := _,\n--   implication_universal_property := _,\n--   deduction_theorem := _,\n--   ...}\n\n\nend propositional_logic", "meta": {"author": "maxd13", "repo": "lean-logic", "sha": "ddcab46b77adca91b120a5f37afbd48794da8b52", "save_path": "github-repos/lean/maxd13-lean-logic", "path": "github-repos/lean/maxd13-lean-logic/lean-logic-ddcab46b77adca91b120a5f37afbd48794da8b52/src/propositional_logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.719914240074184}}
{"text": "/-\nCopyright (c) 2019 Tim Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tim Baanen, Lu-Ming Zhang\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.nonsingular_inverse\n! leanprover-community/mathlib commit da420a8c6dd5bdfb85c4ced85c34388f633bc6ff\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Matrix.Adjugate\n\n/-!\n# Nonsingular inverses\n\nIn this file, we define an inverse for square matrices of invertible determinant.\n\nFor matrices that are not square or not of full rank, there is a more general notion of\npseudoinverses which we do not consider here.\n\nThe definition of inverse used in this file is the adjugate divided by the determinant.\nWe show that dividing the adjugate by `det A` (if possible), giving a matrix `A\u207b\u00b9` (`nonsing_inv`),\nwill result in a multiplicative inverse to `A`.\n\nNote that there are at least three different inverses in mathlib:\n\n* `A\u207b\u00b9` (`has_inv.inv`): alone, this satisfies no properties, although it is usually used in\n  conjunction with `group` or `group_with_zero`. On matrices, this is defined to be zero when no\n  inverse exists.\n* `\u215fA` (`inv_of`): this is only available in the presence of `[invertible A]`, which guarantees an\n  inverse exists.\n* `ring.inverse A`: this is defined on any `monoid_with_zero`, and just like `\u207b\u00b9` on matrices, is\n  defined to be zero when no inverse exists.\n\nWe start by working with `invertible`, and show the main results:\n\n* `matrix.invertible_of_det_invertible`\n* `matrix.det_invertible_of_invertible`\n* `matrix.is_unit_iff_is_unit_det`\n* `matrix.mul_eq_one_comm`\n\nAfter this we define `matrix.has_inv` and show it matches `\u215fA` and `ring.inverse A`.\nThe rest of the results in the file are then about `A\u207b\u00b9`\n\n## References\n\n  * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix\n\n## Tags\n\nmatrix inverse, cramer, cramer's rule, adjugate\n-/\n\n\nnamespace Matrix\n\nuniverse u u' v\n\nvariable {m : Type u} {n : Type u'} {\u03b1 : Type v}\n\nopen Matrix BigOperators\n\nopen Equiv Equiv.Perm Finset\n\n/-! ### Matrices are `invertible` iff their determinants are -/\n\n\nsection Invertible\n\nvariable [Fintype n] [DecidableEq n] [CommRing \u03b1]\n\n/-- A copy of `inv_of_mul_self` using `\u2b1d` not `*`. -/\nprotected theorem invOf_mul_self (A : Matrix n n \u03b1) [Invertible A] : \u215f A \u2b1d A = 1 :=\n  invOf_mul_self A\n#align matrix.inv_of_mul_self Matrix.invOf_mul_self\n\n/-- A copy of `mul_inv_of_self` using `\u2b1d` not `*`. -/\nprotected theorem mul_invOf_self (A : Matrix n n \u03b1) [Invertible A] : A \u2b1d \u215f A = 1 :=\n  mul_invOf_self A\n#align matrix.mul_inv_of_self Matrix.mul_invOf_self\n\n/-- A copy of `inv_of_mul_self_assoc` using `\u2b1d` not `*`. -/\nprotected theorem invOf_mul_self_assoc (A : Matrix n n \u03b1) (B : Matrix n m \u03b1) [Invertible A] :\n    \u215f A \u2b1d (A \u2b1d B) = B := by rw [\u2190 Matrix.mul_assoc, Matrix.invOf_mul_self, Matrix.one_mul]\n#align matrix.inv_of_mul_self_assoc Matrix.invOf_mul_self_assoc\n\n/-- A copy of `mul_inv_of_self_assoc` using `\u2b1d` not `*`. -/\nprotected theorem mul_invOf_self_assoc (A : Matrix n n \u03b1) (B : Matrix n m \u03b1) [Invertible A] :\n    A \u2b1d (\u215f A \u2b1d B) = B := by rw [\u2190 Matrix.mul_assoc, Matrix.mul_invOf_self, Matrix.one_mul]\n#align matrix.mul_inv_of_self_assoc Matrix.mul_invOf_self_assoc\n\n/-- A copy of `mul_inv_of_mul_self_cancel` using `\u2b1d` not `*`. -/\nprotected theorem mul_invOf_mul_self_cancel (A : Matrix m n \u03b1) (B : Matrix n n \u03b1) [Invertible B] :\n    A \u2b1d \u215f B \u2b1d B = A := by rw [Matrix.mul_assoc, Matrix.invOf_mul_self, Matrix.mul_one]\n#align matrix.mul_inv_of_mul_self_cancel Matrix.mul_invOf_mul_self_cancel\n\n/-- A copy of `mul_mul_inv_of_self_cancel` using `\u2b1d` not `*`. -/\nprotected theorem mul_mul_invOf_self_cancel (A : Matrix m n \u03b1) (B : Matrix n n \u03b1) [Invertible B] :\n    A \u2b1d B \u2b1d \u215f B = A := by rw [Matrix.mul_assoc, Matrix.mul_invOf_self, Matrix.mul_one]\n#align matrix.mul_mul_inv_of_self_cancel Matrix.mul_mul_invOf_self_cancel\n\nvariable (A : Matrix n n \u03b1) (B : Matrix n n \u03b1)\n\n/-- If `A.det` has a constructive inverse, produce one for `A`. -/\ndef invertibleOfDetInvertible [Invertible A.det] : Invertible A\n    where\n  invOf := \u215f A.det \u2022 A.adjugate\n  mul_invOf_self := by\n    rw [mul_smul_comm, Matrix.mul_eq_mul, mul_adjugate, smul_smul, invOf_mul_self, one_smul]\n  invOf_mul_self := by\n    rw [smul_mul_assoc, Matrix.mul_eq_mul, adjugate_mul, smul_smul, invOf_mul_self, one_smul]\n#align matrix.invertible_of_det_invertible Matrix.invertibleOfDetInvertible\n\ntheorem invOf_eq [Invertible A.det] [Invertible A] : \u215f A = \u215f A.det \u2022 A.adjugate :=\n  by\n  letI := invertible_of_det_invertible A\n  convert(rfl : \u215f A = _)\n#align matrix.inv_of_eq Matrix.invOf_eq\n\n/-- `A.det` is invertible if `A` has a left inverse. -/\ndef detInvertibleOfLeftInverse (h : B \u2b1d A = 1) : Invertible A.det\n    where\n  invOf := B.det\n  mul_invOf_self := by rw [mul_comm, \u2190 det_mul, h, det_one]\n  invOf_mul_self := by rw [\u2190 det_mul, h, det_one]\n#align matrix.det_invertible_of_left_inverse Matrix.detInvertibleOfLeftInverse\n\n/-- `A.det` is invertible if `A` has a right inverse. -/\ndef detInvertibleOfRightInverse (h : A \u2b1d B = 1) : Invertible A.det\n    where\n  invOf := B.det\n  mul_invOf_self := by rw [\u2190 det_mul, h, det_one]\n  invOf_mul_self := by rw [mul_comm, \u2190 det_mul, h, det_one]\n#align matrix.det_invertible_of_right_inverse Matrix.detInvertibleOfRightInverse\n\n/-- If `A` has a constructive inverse, produce one for `A.det`. -/\ndef detInvertibleOfInvertible [Invertible A] : Invertible A.det :=\n  detInvertibleOfLeftInverse A (\u215f A) (invOf_mul_self _)\n#align matrix.det_invertible_of_invertible Matrix.detInvertibleOfInvertible\n\ntheorem det_invOf [Invertible A] [Invertible A.det] : (\u215f A).det = \u215f A.det :=\n  by\n  letI := det_invertible_of_invertible A\n  convert(rfl : _ = \u215f A.det)\n#align matrix.det_inv_of Matrix.det_invOf\n\n/-- Together `matrix.det_invertible_of_invertible` and `matrix.invertible_of_det_invertible` form an\nequivalence, although both sides of the equiv are subsingleton anyway. -/\n@[simps]\ndef invertibleEquivDetInvertible : Invertible A \u2243 Invertible A.det\n    where\n  toFun := @detInvertibleOfInvertible _ _ _ _ _ A\n  invFun := @invertibleOfDetInvertible _ _ _ _ _ A\n  left_inv _ := Subsingleton.elim _ _\n  right_inv _ := Subsingleton.elim _ _\n#align matrix.invertible_equiv_det_invertible Matrix.invertibleEquivDetInvertible\n\nvariable {A B}\n\ntheorem mul_eq_one_comm : A \u2b1d B = 1 \u2194 B \u2b1d A = 1 :=\n  suffices \u2200 A B, A \u2b1d B = 1 \u2192 B \u2b1d A = 1 from \u27e8this A B, this B A\u27e9\n  fun A B h => by\n  letI : Invertible B.det := det_invertible_of_left_inverse _ _ h\n  letI : Invertible B := invertible_of_det_invertible B\n  calc\n    B \u2b1d A = B \u2b1d A \u2b1d (B \u2b1d \u215f B) := by rw [Matrix.mul_invOf_self, Matrix.mul_one]\n    _ = B \u2b1d (A \u2b1d B \u2b1d \u215f B) := by simp only [Matrix.mul_assoc]\n    _ = B \u2b1d \u215f B := by rw [h, Matrix.one_mul]\n    _ = 1 := Matrix.mul_invOf_self B\n    \n#align matrix.mul_eq_one_comm Matrix.mul_eq_one_comm\n\nvariable (A B)\n\n/-- We can construct an instance of invertible A if A has a left inverse. -/\ndef invertibleOfLeftInverse (h : B \u2b1d A = 1) : Invertible A :=\n  \u27e8B, h, mul_eq_one_comm.mp h\u27e9\n#align matrix.invertible_of_left_inverse Matrix.invertibleOfLeftInverse\n\n/-- We can construct an instance of invertible A if A has a right inverse. -/\ndef invertibleOfRightInverse (h : A \u2b1d B = 1) : Invertible A :=\n  \u27e8B, mul_eq_one_comm.mp h, h\u27e9\n#align matrix.invertible_of_right_inverse Matrix.invertibleOfRightInverse\n\n/-- The transpose of an invertible matrix is invertible. -/\ninstance invertibleTranspose [Invertible A] : Invertible A\u1d40 :=\n  haveI : Invertible A\u1d40.det := by simpa using det_invertible_of_invertible A\n  invertible_of_det_invertible A\u1d40\n#align matrix.invertible_transpose Matrix.invertibleTranspose\n\n/-- A matrix is invertible if the transpose is invertible. -/\ndef invertibleOfInvertibleTranspose [Invertible A\u1d40] : Invertible A :=\n  by\n  rw [\u2190 transpose_transpose A]\n  infer_instance\n#align matrix.invertible__of_invertible_transpose Matrix.invertibleOfInvertibleTranspose\n\n/-- A matrix is invertible if the conjugate transpose is invertible. -/\ndef invertibleOfInvertibleConjTranspose [StarRing \u03b1] [Invertible A\u1d34] : Invertible A :=\n  by\n  rw [\u2190 conj_transpose_conj_transpose A]\n  infer_instance\n#align matrix.invertible_of_invertible_conj_transpose Matrix.invertibleOfInvertibleConjTranspose\n\n/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(matrix n n \u03b1)\u02e3`-/\ndef unitOfDetInvertible [Invertible A.det] : (Matrix n n \u03b1)\u02e3 :=\n  @unitOfInvertible _ _ A (invertibleOfDetInvertible A)\n#align matrix.unit_of_det_invertible Matrix.unitOfDetInvertible\n\n/-- When lowered to a prop, `matrix.invertible_equiv_det_invertible` forms an `iff`. -/\ntheorem isUnit_iff_isUnit_det : IsUnit A \u2194 IsUnit A.det := by\n  simp only [\u2190 nonempty_invertible_iff_isUnit, (invertible_equiv_det_invertible A).nonempty_congr]\n#align matrix.is_unit_iff_is_unit_det Matrix.isUnit_iff_isUnit_det\n\n/-! #### Variants of the statements above with `is_unit`-/\n\n\ntheorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det :=\n  @isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A)\n#align matrix.is_unit_det_of_invertible Matrix.isUnit_det_of_invertible\n\nvariable {A B}\n\ntheorem isUnit_of_left_inverse (h : B \u2b1d A = 1) : IsUnit A :=\n  \u27e8\u27e8A, B, mul_eq_one_comm.mp h, h\u27e9, rfl\u27e9\n#align matrix.is_unit_of_left_inverse Matrix.isUnit_of_left_inverse\n\ntheorem isUnit_of_right_inverse (h : A \u2b1d B = 1) : IsUnit A :=\n  \u27e8\u27e8A, B, h, mul_eq_one_comm.mp h\u27e9, rfl\u27e9\n#align matrix.is_unit_of_right_inverse Matrix.isUnit_of_right_inverse\n\ntheorem isUnit_det_of_left_inverse (h : B \u2b1d A = 1) : IsUnit A.det :=\n  @isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h)\n#align matrix.is_unit_det_of_left_inverse Matrix.isUnit_det_of_left_inverse\n\ntheorem isUnit_det_of_right_inverse (h : A \u2b1d B = 1) : IsUnit A.det :=\n  @isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h)\n#align matrix.is_unit_det_of_right_inverse Matrix.isUnit_det_of_right_inverse\n\ntheorem det_ne_zero_of_left_inverse [Nontrivial \u03b1] (h : B \u2b1d A = 1) : A.det \u2260 0 :=\n  (isUnit_det_of_left_inverse h).NeZero\n#align matrix.det_ne_zero_of_left_inverse Matrix.det_ne_zero_of_left_inverse\n\ntheorem det_ne_zero_of_right_inverse [Nontrivial \u03b1] (h : A \u2b1d B = 1) : A.det \u2260 0 :=\n  (isUnit_det_of_right_inverse h).NeZero\n#align matrix.det_ne_zero_of_right_inverse Matrix.det_ne_zero_of_right_inverse\n\nend Invertible\n\nvariable [Fintype n] [DecidableEq n] [CommRing \u03b1]\n\nvariable (A : Matrix n n \u03b1) (B : Matrix n n \u03b1)\n\ntheorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit A\u1d40.det :=\n  by\n  rw [det_transpose]\n  exact h\n#align matrix.is_unit_det_transpose Matrix.isUnit_det_transpose\n\n/-! ### A noncomputable `has_inv` instance  -/\n\n\n/-- The inverse of a square matrix, when it is invertible (and zero otherwise).-/\nnoncomputable instance : Inv (Matrix n n \u03b1) :=\n  \u27e8fun A => Ring.inverse A.det \u2022 A.adjugate\u27e9\n\ntheorem inv_def (A : Matrix n n \u03b1) : A\u207b\u00b9 = Ring.inverse A.det \u2022 A.adjugate :=\n  rfl\n#align matrix.inv_def Matrix.inv_def\n\ntheorem nonsing_inv_apply_not_isUnit (h : \u00acIsUnit A.det) : A\u207b\u00b9 = 0 := by\n  rw [inv_def, Ring.inverse_non_unit _ h, zero_smul]\n#align matrix.nonsing_inv_apply_not_is_unit Matrix.nonsing_inv_apply_not_isUnit\n\ntheorem nonsing_inv_apply (h : IsUnit A.det) : A\u207b\u00b9 = (\u2191h.Unit\u207b\u00b9 : \u03b1) \u2022 A.adjugate := by\n  rw [inv_def, \u2190 Ring.inverse_unit h.unit, IsUnit.unit_spec]\n#align matrix.nonsing_inv_apply Matrix.nonsing_inv_apply\n\n/-- The nonsingular inverse is the same as `inv_of` when `A` is invertible. -/\n@[simp]\ntheorem invOf_eq_nonsing_inv [Invertible A] : \u215f A = A\u207b\u00b9 :=\n  by\n  letI := det_invertible_of_invertible A\n  rw [inv_def, Ring.inverse_invertible, inv_of_eq]\n#align matrix.inv_of_eq_nonsing_inv Matrix.invOf_eq_nonsing_inv\n\n/-- Coercing the result of `units.has_inv` is the same as coercing first and applying the\nnonsingular inverse. -/\n@[simp, norm_cast]\ntheorem coe_units_inv (A : (Matrix n n \u03b1)\u02e3) : \u2191A\u207b\u00b9 = (A\u207b\u00b9 : Matrix n n \u03b1) :=\n  by\n  letI := A.invertible\n  rw [\u2190 inv_of_eq_nonsing_inv, invOf_units]\n#align matrix.coe_units_inv Matrix.coe_units_inv\n\n/-- The nonsingular inverse is the same as the general `ring.inverse`. -/\ntheorem nonsing_inv_eq_ring_inverse : A\u207b\u00b9 = Ring.inverse A :=\n  by\n  by_cases h_det : IsUnit A.det\n  \u00b7 cases (A.is_unit_iff_is_unit_det.mpr h_det).nonempty_invertible\n    rw [\u2190 inv_of_eq_nonsing_inv, Ring.inverse_invertible]\n  \u00b7 have h := mt A.is_unit_iff_is_unit_det.mp h_det\n    rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_is_unit A h_det]\n#align matrix.nonsing_inv_eq_ring_inverse Matrix.nonsing_inv_eq_ring_inverse\n\ntheorem transpose_nonsing_inv : A\u207b\u00b9\u1d40 = A\u1d40\u207b\u00b9 := by\n  rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]\n#align matrix.transpose_nonsing_inv Matrix.transpose_nonsing_inv\n\ntheorem conjTranspose_nonsing_inv [StarRing \u03b1] : A\u207b\u00b9\u1d34 = A\u1d34\u207b\u00b9 := by\n  rw [inv_def, inv_def, conj_transpose_smul, det_conj_transpose, adjugate_conj_transpose,\n    Ring.inverse_star]\n#align matrix.conj_transpose_nonsing_inv Matrix.conjTranspose_nonsing_inv\n\n/-- The `nonsing_inv` of `A` is a right inverse. -/\n@[simp]\ntheorem mul_nonsing_inv (h : IsUnit A.det) : A \u2b1d A\u207b\u00b9 = 1 :=\n  by\n  cases (A.is_unit_iff_is_unit_det.mpr h).nonempty_invertible\n  rw [\u2190 inv_of_eq_nonsing_inv, Matrix.mul_invOf_self]\n#align matrix.mul_nonsing_inv Matrix.mul_nonsing_inv\n\n/-- The `nonsing_inv` of `A` is a left inverse. -/\n@[simp]\ntheorem nonsing_inv_mul (h : IsUnit A.det) : A\u207b\u00b9 \u2b1d A = 1 :=\n  by\n  cases (A.is_unit_iff_is_unit_det.mpr h).nonempty_invertible\n  rw [\u2190 inv_of_eq_nonsing_inv, Matrix.invOf_mul_self]\n#align matrix.nonsing_inv_mul Matrix.nonsing_inv_mul\n\ninstance [Invertible A] : Invertible A\u207b\u00b9 :=\n  by\n  rw [\u2190 inv_of_eq_nonsing_inv]\n  infer_instance\n\n@[simp]\ntheorem inv_inv_of_invertible [Invertible A] : A\u207b\u00b9\u207b\u00b9 = A := by\n  simp only [\u2190 inv_of_eq_nonsing_inv, invOf_invOf]\n#align matrix.inv_inv_of_invertible Matrix.inv_inv_of_invertible\n\n@[simp]\ntheorem mul_nonsing_inv_cancel_right (B : Matrix m n \u03b1) (h : IsUnit A.det) : B \u2b1d A \u2b1d A\u207b\u00b9 = B := by\n  simp [Matrix.mul_assoc, mul_nonsing_inv A h]\n#align matrix.mul_nonsing_inv_cancel_right Matrix.mul_nonsing_inv_cancel_right\n\n@[simp]\ntheorem mul_nonsing_inv_cancel_left (B : Matrix n m \u03b1) (h : IsUnit A.det) : A \u2b1d (A\u207b\u00b9 \u2b1d B) = B := by\n  simp [\u2190 Matrix.mul_assoc, mul_nonsing_inv A h]\n#align matrix.mul_nonsing_inv_cancel_left Matrix.mul_nonsing_inv_cancel_left\n\n@[simp]\ntheorem nonsing_inv_mul_cancel_right (B : Matrix m n \u03b1) (h : IsUnit A.det) : B \u2b1d A\u207b\u00b9 \u2b1d A = B := by\n  simp [Matrix.mul_assoc, nonsing_inv_mul A h]\n#align matrix.nonsing_inv_mul_cancel_right Matrix.nonsing_inv_mul_cancel_right\n\n@[simp]\ntheorem nonsing_inv_mul_cancel_left (B : Matrix n m \u03b1) (h : IsUnit A.det) : A\u207b\u00b9 \u2b1d (A \u2b1d B) = B := by\n  simp [\u2190 Matrix.mul_assoc, nonsing_inv_mul A h]\n#align matrix.nonsing_inv_mul_cancel_left Matrix.nonsing_inv_mul_cancel_left\n\n@[simp]\ntheorem mul_inv_of_invertible [Invertible A] : A \u2b1d A\u207b\u00b9 = 1 :=\n  mul_nonsing_inv A (isUnit_det_of_invertible A)\n#align matrix.mul_inv_of_invertible Matrix.mul_inv_of_invertible\n\n@[simp]\ntheorem inv_mul_of_invertible [Invertible A] : A\u207b\u00b9 \u2b1d A = 1 :=\n  nonsing_inv_mul A (isUnit_det_of_invertible A)\n#align matrix.inv_mul_of_invertible Matrix.inv_mul_of_invertible\n\n@[simp]\ntheorem mul_inv_cancel_right_of_invertible (B : Matrix m n \u03b1) [Invertible A] : B \u2b1d A \u2b1d A\u207b\u00b9 = B :=\n  mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A)\n#align matrix.mul_inv_cancel_right_of_invertible Matrix.mul_inv_cancel_right_of_invertible\n\n@[simp]\ntheorem mul_inv_cancel_left_of_invertible (B : Matrix n m \u03b1) [Invertible A] : A \u2b1d (A\u207b\u00b9 \u2b1d B) = B :=\n  mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A)\n#align matrix.mul_inv_cancel_left_of_invertible Matrix.mul_inv_cancel_left_of_invertible\n\n@[simp]\ntheorem inv_mul_cancel_right_of_invertible (B : Matrix m n \u03b1) [Invertible A] : B \u2b1d A\u207b\u00b9 \u2b1d A = B :=\n  nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A)\n#align matrix.inv_mul_cancel_right_of_invertible Matrix.inv_mul_cancel_right_of_invertible\n\n@[simp]\ntheorem inv_mul_cancel_left_of_invertible (B : Matrix n m \u03b1) [Invertible A] : A\u207b\u00b9 \u2b1d (A \u2b1d B) = B :=\n  nonsing_inv_mul_cancel_left A B (isUnit_det_of_invertible A)\n#align matrix.inv_mul_cancel_left_of_invertible Matrix.inv_mul_cancel_left_of_invertible\n\ntheorem inv_mul_eq_iff_eq_mul_of_invertible (A B C : Matrix n n \u03b1) [Invertible A] :\n    A\u207b\u00b9 \u2b1d B = C \u2194 B = A \u2b1d C :=\n  \u27e8fun h => by rw [\u2190 h, mul_inv_cancel_left_of_invertible], fun h => by\n    rw [h, inv_mul_cancel_left_of_invertible]\u27e9\n#align matrix.inv_mul_eq_iff_eq_mul_of_invertible Matrix.inv_mul_eq_iff_eq_mul_of_invertible\n\ntheorem mul_inv_eq_iff_eq_mul_of_invertible (A B C : Matrix n n \u03b1) [Invertible A] :\n    B \u2b1d A\u207b\u00b9 = C \u2194 B = C \u2b1d A :=\n  \u27e8fun h => by rw [\u2190 h, inv_mul_cancel_right_of_invertible], fun h => by\n    rw [h, mul_inv_cancel_right_of_invertible]\u27e9\n#align matrix.mul_inv_eq_iff_eq_mul_of_invertible Matrix.mul_inv_eq_iff_eq_mul_of_invertible\n\ntheorem nonsing_inv_cancel_or_zero : A\u207b\u00b9 \u2b1d A = 1 \u2227 A \u2b1d A\u207b\u00b9 = 1 \u2228 A\u207b\u00b9 = 0 :=\n  by\n  by_cases h : IsUnit A.det\n  \u00b7 exact Or.inl \u27e8nonsing_inv_mul _ h, mul_nonsing_inv _ h\u27e9\n  \u00b7 exact Or.inr (nonsing_inv_apply_not_is_unit _ h)\n#align matrix.nonsing_inv_cancel_or_zero Matrix.nonsing_inv_cancel_or_zero\n\ntheorem det_nonsing_inv_mul_det (h : IsUnit A.det) : A\u207b\u00b9.det * A.det = 1 := by\n  rw [\u2190 det_mul, A.nonsing_inv_mul h, det_one]\n#align matrix.det_nonsing_inv_mul_det Matrix.det_nonsing_inv_mul_det\n\n@[simp]\ntheorem det_nonsing_inv : A\u207b\u00b9.det = Ring.inverse A.det :=\n  by\n  by_cases h : IsUnit A.det\n  \u00b7 cases h.nonempty_invertible\n    letI := invertible_of_det_invertible A\n    rw [Ring.inverse_invertible, \u2190 inv_of_eq_nonsing_inv, det_inv_of]\n  cases isEmpty_or_nonempty n\n  \u00b7 rw [det_is_empty, det_is_empty, Ring.inverse_one]\n  \u00b7 rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_is_unit _ h, det_zero \u2039_\u203a]\n#align matrix.det_nonsing_inv Matrix.det_nonsing_inv\n\ntheorem isUnit_nonsing_inv_det (h : IsUnit A.det) : IsUnit A\u207b\u00b9.det :=\n  isUnit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h)\n#align matrix.is_unit_nonsing_inv_det Matrix.isUnit_nonsing_inv_det\n\n@[simp]\ntheorem nonsing_inv_nonsing_inv (h : IsUnit A.det) : A\u207b\u00b9\u207b\u00b9 = A :=\n  calc\n    A\u207b\u00b9\u207b\u00b9 = 1 \u2b1d A\u207b\u00b9\u207b\u00b9 := by rw [Matrix.one_mul]\n    _ = A \u2b1d A\u207b\u00b9 \u2b1d A\u207b\u00b9\u207b\u00b9 := by rw [A.mul_nonsing_inv h]\n    _ = A := by\n      rw [Matrix.mul_assoc, A\u207b\u00b9.mul_nonsing_inv (A.is_unit_nonsing_inv_det h), Matrix.mul_one]\n    \n#align matrix.nonsing_inv_nonsing_inv Matrix.nonsing_inv_nonsing_inv\n\ntheorem isUnit_nonsing_inv_det_iff {A : Matrix n n \u03b1} : IsUnit A\u207b\u00b9.det \u2194 IsUnit A.det := by\n  rw [Matrix.det_nonsing_inv, isUnit_ring_inverse]\n#align matrix.is_unit_nonsing_inv_det_iff Matrix.isUnit_nonsing_inv_det_iff\n\n-- `is_unit.invertible` lifts the proposition `is_unit A` to a constructive inverse of `A`.\n/-- A version of `matrix.invertible_of_det_invertible` with the inverse defeq to `A\u207b\u00b9` that is\ntherefore noncomputable. -/\nnoncomputable def invertibleOfIsUnitDet (h : IsUnit A.det) : Invertible A :=\n  \u27e8A\u207b\u00b9, nonsing_inv_mul A h, mul_nonsing_inv A h\u27e9\n#align matrix.invertible_of_is_unit_det Matrix.invertibleOfIsUnitDet\n\n/-- A version of `matrix.units_of_det_invertible` with the inverse defeq to `A\u207b\u00b9` that is therefore\nnoncomputable. -/\nnoncomputable def nonsingInvUnit (h : IsUnit A.det) : (Matrix n n \u03b1)\u02e3 :=\n  @unitOfInvertible _ _ _ (invertibleOfIsUnitDet A h)\n#align matrix.nonsing_inv_unit Matrix.nonsingInvUnit\n\ntheorem unitOfDetInvertible_eq_nonsingInvUnit [Invertible A.det] :\n    unitOfDetInvertible A = nonsingInvUnit A (isUnit_of_invertible _) :=\n  by\n  ext\n  rfl\n#align matrix.unit_of_det_invertible_eq_nonsing_inv_unit Matrix.unitOfDetInvertible_eq_nonsingInvUnit\n\nvariable {A} {B}\n\n/-- If matrix A is left invertible, then its inverse equals its left inverse. -/\ntheorem inv_eq_left_inv (h : B \u2b1d A = 1) : A\u207b\u00b9 = B :=\n  letI := invertible_of_left_inverse _ _ h\n  inv_of_eq_nonsing_inv A \u25b8 invOf_eq_left_inv h\n#align matrix.inv_eq_left_inv Matrix.inv_eq_left_inv\n\n/-- If matrix A is right invertible, then its inverse equals its right inverse. -/\ntheorem inv_eq_right_inv (h : A \u2b1d B = 1) : A\u207b\u00b9 = B :=\n  inv_eq_left_inv (mul_eq_one_comm.2 h)\n#align matrix.inv_eq_right_inv Matrix.inv_eq_right_inv\n\nsection InvEqInv\n\nvariable {C : Matrix n n \u03b1}\n\n/-- The left inverse of matrix A is unique when existing. -/\ntheorem left_inv_eq_left_inv (h : B \u2b1d A = 1) (g : C \u2b1d A = 1) : B = C := by\n  rw [\u2190 inv_eq_left_inv h, \u2190 inv_eq_left_inv g]\n#align matrix.left_inv_eq_left_inv Matrix.left_inv_eq_left_inv\n\n/-- The right inverse of matrix A is unique when existing. -/\ntheorem right_inv_eq_right_inv (h : A \u2b1d B = 1) (g : A \u2b1d C = 1) : B = C := by\n  rw [\u2190 inv_eq_right_inv h, \u2190 inv_eq_right_inv g]\n#align matrix.right_inv_eq_right_inv Matrix.right_inv_eq_right_inv\n\n/-- The right inverse of matrix A equals the left inverse of A when they exist. -/\ntheorem right_inv_eq_left_inv (h : A \u2b1d B = 1) (g : C \u2b1d A = 1) : B = C := by\n  rw [\u2190 inv_eq_right_inv h, \u2190 inv_eq_left_inv g]\n#align matrix.right_inv_eq_left_inv Matrix.right_inv_eq_left_inv\n\ntheorem inv_inj (h : A\u207b\u00b9 = B\u207b\u00b9) (h' : IsUnit A.det) : A = B :=\n  by\n  refine' left_inv_eq_left_inv (mul_nonsing_inv _ h') _\n  rw [h]\n  refine' mul_nonsing_inv _ _\n  rwa [\u2190 is_unit_nonsing_inv_det_iff, \u2190 h, is_unit_nonsing_inv_det_iff]\n#align matrix.inv_inj Matrix.inv_inj\n\nend InvEqInv\n\nvariable (A)\n\n@[simp]\ntheorem inv_zero : (0 : Matrix n n \u03b1)\u207b\u00b9 = 0 :=\n  by\n  cases' subsingleton_or_nontrivial \u03b1 with ht ht\n  \u00b7 simp\n  cases' (Fintype.card n).zero_le.eq_or_lt with hc hc\n  \u00b7 rw [eq_comm, Fintype.card_eq_zero_iff] at hc\n    haveI := hc\n    ext i\n    exact (IsEmpty.false i).elim\n  \u00b7 have hn : Nonempty n := fintype.card_pos_iff.mp hc\n    refine' nonsing_inv_apply_not_is_unit _ _\n    simp [hn]\n#align matrix.inv_zero Matrix.inv_zero\n\nnoncomputable instance : InvOneClass (Matrix n n \u03b1) :=\n  { Matrix.hasOne, Matrix.hasInv with inv_one := inv_eq_left_inv (by simp) }\n\ntheorem inv_smul (k : \u03b1) [Invertible k] (h : IsUnit A.det) : (k \u2022 A)\u207b\u00b9 = \u215f k \u2022 A\u207b\u00b9 :=\n  inv_eq_left_inv (by simp [h, smul_smul])\n#align matrix.inv_smul Matrix.inv_smul\n\ntheorem inv_smul' (k : \u03b1\u02e3) (h : IsUnit A.det) : (k \u2022 A)\u207b\u00b9 = k\u207b\u00b9 \u2022 A\u207b\u00b9 :=\n  inv_eq_left_inv (by simp [h, smul_smul])\n#align matrix.inv_smul' Matrix.inv_smul'\n\ntheorem inv_adjugate (A : Matrix n n \u03b1) (h : IsUnit A.det) : (adjugate A)\u207b\u00b9 = h.Unit\u207b\u00b9 \u2022 A :=\n  by\n  refine' inv_eq_left_inv _\n  rw [smul_mul, mul_adjugate, Units.smul_def, smul_smul, h.coe_inv_mul, one_smul]\n#align matrix.inv_adjugate Matrix.inv_adjugate\n\n/-- `diagonal v` is invertible if `v` is -/\ndef diagonalInvertible {\u03b1} [NonAssocSemiring \u03b1] (v : n \u2192 \u03b1) [Invertible v] :\n    Invertible (diagonal v) :=\n  Invertible.map (diagonalRingHom n \u03b1) v\n#align matrix.diagonal_invertible Matrix.diagonalInvertible\n\ntheorem invOf_diagonal_eq {\u03b1} [Semiring \u03b1] (v : n \u2192 \u03b1) [Invertible v] [Invertible (diagonal v)] :\n    \u215f (diagonal v) = diagonal (\u215f v) :=\n  by\n  letI := diagonal_invertible v\n  haveI := Invertible.subsingleton (diagonal v)\n  convert(rfl : \u215f (diagonal v) = _)\n#align matrix.inv_of_diagonal_eq Matrix.invOf_diagonal_eq\n\n/-- `v` is invertible if `diagonal v` is -/\ndef invertibleOfDiagonalInvertible (v : n \u2192 \u03b1) [Invertible (diagonal v)] : Invertible v\n    where\n  invOf := diag (\u215f (diagonal v))\n  invOf_mul_self :=\n    funext fun i =>\n      by\n      letI : Invertible (diagonal v).det := det_invertible_of_invertible _\n      rw [inv_of_eq, diag_smul, adjugate_diagonal, diag_diagonal]\n      dsimp\n      rw [mul_assoc, prod_erase_mul _ _ (Finset.mem_univ _), \u2190 det_diagonal]\n      exact mul_invOf_self _\n  mul_invOf_self :=\n    funext fun i =>\n      by\n      letI : Invertible (diagonal v).det := det_invertible_of_invertible _\n      rw [inv_of_eq, diag_smul, adjugate_diagonal, diag_diagonal]\n      dsimp\n      rw [mul_left_comm, mul_prod_erase _ _ (Finset.mem_univ _), \u2190 det_diagonal]\n      exact mul_invOf_self _\n#align matrix.invertible_of_diagonal_invertible Matrix.invertibleOfDiagonalInvertible\n\n/-- Together `matrix.diagonal_invertible` and `matrix.invertible_of_diagonal_invertible` form an\nequivalence, although both sides of the equiv are subsingleton anyway. -/\n@[simps]\ndef diagonalInvertibleEquivInvertible (v : n \u2192 \u03b1) : Invertible (diagonal v) \u2243 Invertible v\n    where\n  toFun := @invertibleOfDiagonalInvertible _ _ _ _ _ _\n  invFun := @diagonalInvertible _ _ _ _ _ _\n  left_inv _ := Subsingleton.elim _ _\n  right_inv _ := Subsingleton.elim _ _\n#align matrix.diagonal_invertible_equiv_invertible Matrix.diagonalInvertibleEquivInvertible\n\n/-- When lowered to a prop, `matrix.diagonal_invertible_equiv_invertible` forms an `iff`. -/\n@[simp]\ntheorem isUnit_diagonal {v : n \u2192 \u03b1} : IsUnit (diagonal v) \u2194 IsUnit v := by\n  simp only [\u2190 nonempty_invertible_iff_isUnit,\n    (diagonal_invertible_equiv_invertible v).nonempty_congr]\n#align matrix.is_unit_diagonal Matrix.isUnit_diagonal\n\ntheorem inv_diagonal (v : n \u2192 \u03b1) : (diagonal v)\u207b\u00b9 = diagonal (Ring.inverse v) :=\n  by\n  rw [nonsing_inv_eq_ring_inverse]\n  by_cases h : IsUnit v\n  \u00b7 have := is_unit_diagonal.mpr h\n    cases this.nonempty_invertible\n    cases h.nonempty_invertible\n    rw [Ring.inverse_invertible, Ring.inverse_invertible, inv_of_diagonal_eq]\n  \u00b7 have := is_unit_diagonal.not.mpr h\n    rw [Ring.inverse_non_unit _ h, Pi.zero_def, diagonal_zero, Ring.inverse_non_unit _ this]\n#align matrix.inv_diagonal Matrix.inv_diagonal\n\n@[simp]\ntheorem inv_inv_inv (A : Matrix n n \u03b1) : A\u207b\u00b9\u207b\u00b9\u207b\u00b9 = A\u207b\u00b9 :=\n  by\n  by_cases h : IsUnit A.det\n  \u00b7 rw [nonsing_inv_nonsing_inv _ h]\n  \u00b7 simp [nonsing_inv_apply_not_is_unit _ h]\n#align matrix.inv_inv_inv Matrix.inv_inv_inv\n\ntheorem mul_inv_rev (A B : Matrix n n \u03b1) : (A \u2b1d B)\u207b\u00b9 = B\u207b\u00b9 \u2b1d A\u207b\u00b9 :=\n  by\n  simp only [inv_def]\n  rw [Matrix.smul_mul, Matrix.mul_smul, smul_smul, det_mul, adjugate_mul_distrib,\n    Ring.mul_inverse_rev]\n#align matrix.mul_inv_rev Matrix.mul_inv_rev\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/-- A version of `list.prod_inv_reverse` for `matrix.has_inv`. -/\ntheorem list_prod_inv_reverse : \u2200 l : List (Matrix n n \u03b1), l.Prod\u207b\u00b9 = (l.reverse.map Inv.inv).Prod\n  | [] => by rw [List.reverse_nil, List.map_nil, List.prod_nil, inv_one]\n  | A::Xs => by\n    rw [List.reverse_cons', List.map_concat, List.prod_concat, List.prod_cons, Matrix.mul_eq_mul,\n      Matrix.mul_eq_mul, mul_inv_rev, list_prod_inv_reverse]\n#align matrix.list_prod_inv_reverse Matrix.list_prod_inv_reverse\n\n/-- One form of **Cramer's rule**. See `matrix.mul_vec_cramer` for a stronger form. -/\n@[simp]\ntheorem det_smul_inv_mulVec_eq_cramer (A : Matrix n n \u03b1) (b : n \u2192 \u03b1) (h : IsUnit A.det) :\n    A.det \u2022 A\u207b\u00b9.mulVec b = cramer A b := by\n  rw [cramer_eq_adjugate_mul_vec, A.nonsing_inv_apply h, \u2190 smul_mul_vec_assoc, smul_smul,\n    h.mul_coe_inv, one_smul]\n#align matrix.det_smul_inv_mul_vec_eq_cramer Matrix.det_smul_inv_mulVec_eq_cramer\n\n/-- One form of **Cramer's rule**. See `matrix.mul_vec_cramer` for a stronger form. -/\n@[simp]\ntheorem det_smul_inv_vecMul_eq_cramer_transpose (A : Matrix n n \u03b1) (b : n \u2192 \u03b1) (h : IsUnit A.det) :\n    A.det \u2022 A\u207b\u00b9.vecMul b = cramer A\u1d40 b := by\n  rw [\u2190 A\u207b\u00b9.transpose_transpose, vec_mul_transpose, transpose_nonsing_inv, \u2190 det_transpose,\n    A\u1d40.det_smul_inv_mulVec_eq_cramer _ (is_unit_det_transpose A h)]\n#align matrix.det_smul_inv_vec_mul_eq_cramer_transpose Matrix.det_smul_inv_vecMul_eq_cramer_transpose\n\n/-! ### More results about determinants -/\n\n\nsection Det\n\nvariable [Fintype m] [DecidableEq m]\n\n/-- A variant of `matrix.det_units_conj`. -/\ntheorem det_conj {M : Matrix m m \u03b1} (h : IsUnit M) (N : Matrix m m \u03b1) : det (M \u2b1d N \u2b1d M\u207b\u00b9) = det N :=\n  by rw [\u2190 h.unit_spec, \u2190 coe_units_inv, det_units_conj]\n#align matrix.det_conj Matrix.det_conj\n\n/-- A variant of `matrix.det_units_conj'`. -/\ntheorem det_conj' {M : Matrix m m \u03b1} (h : IsUnit M) (N : Matrix m m \u03b1) :\n    det (M\u207b\u00b9 \u2b1d N \u2b1d M) = det N := by rw [\u2190 h.unit_spec, \u2190 coe_units_inv, det_units_conj']\n#align matrix.det_conj' Matrix.det_conj'\n\n/-- Determinant of a 2\u00d72 block matrix, expanded around an invertible top left element in terms of\nthe Schur complement. -/\ntheorem det_from_blocks\u2081\u2081 (A : Matrix m m \u03b1) (B : Matrix m n \u03b1) (C : Matrix n m \u03b1)\n    (D : Matrix n n \u03b1) [Invertible A] :\n    (Matrix.fromBlocks A B C D).det = det A * det (D - C \u2b1d \u215f A \u2b1d B) :=\n  by\n  have :\n    from_blocks A B C D =\n      from_blocks 1 0 (C \u2b1d \u215f A) 1 \u2b1d from_blocks A 0 0 (D - C \u2b1d \u215f A \u2b1d B) \u2b1d\n        from_blocks 1 (\u215f A \u2b1d B) 0 1 :=\n    by\n    simp only [from_blocks_multiply, Matrix.mul_zero, Matrix.zero_mul, add_zero, zero_add,\n      Matrix.one_mul, Matrix.mul_one, Matrix.invOf_mul_self, Matrix.mul_invOf_self_assoc,\n      Matrix.mul_invOf_mul_self_cancel, Matrix.mul_assoc, add_sub_cancel'_right]\n  rw [this, det_mul, det_mul, det_from_blocks_zero\u2082\u2081, det_from_blocks_zero\u2082\u2081,\n    det_from_blocks_zero\u2081\u2082, det_one, det_one, one_mul, one_mul, mul_one]\n#align matrix.det_from_blocks\u2081\u2081 Matrix.det_from_blocks\u2081\u2081\n\n@[simp]\ntheorem det_fromBlocks_one\u2081\u2081 (B : Matrix m n \u03b1) (C : Matrix n m \u03b1) (D : Matrix n n \u03b1) :\n    (Matrix.fromBlocks 1 B C D).det = det (D - C \u2b1d B) :=\n  by\n  haveI : Invertible (1 : Matrix m m \u03b1) := invertibleOne\n  rw [det_from_blocks\u2081\u2081, invOf_one, Matrix.mul_one, det_one, one_mul]\n#align matrix.det_from_blocks_one\u2081\u2081 Matrix.det_fromBlocks_one\u2081\u2081\n\n/-- Determinant of a 2\u00d72 block matrix, expanded around an invertible bottom right element in terms\nof the Schur complement. -/\ntheorem det_from_blocks\u2082\u2082 (A : Matrix m m \u03b1) (B : Matrix m n \u03b1) (C : Matrix n m \u03b1)\n    (D : Matrix n n \u03b1) [Invertible D] :\n    (Matrix.fromBlocks A B C D).det = det D * det (A - B \u2b1d \u215f D \u2b1d C) :=\n  by\n  have : from_blocks A B C D = (from_blocks D C B A).submatrix (sum_comm _ _) (sum_comm _ _) :=\n    by\n    ext (i j)\n    cases i <;> cases j <;> rfl\n  rw [this, det_submatrix_equiv_self, det_from_blocks\u2081\u2081]\n#align matrix.det_from_blocks\u2082\u2082 Matrix.det_from_blocks\u2082\u2082\n\n@[simp]\ntheorem det_fromBlocks_one\u2082\u2082 (A : Matrix m m \u03b1) (B : Matrix m n \u03b1) (C : Matrix n m \u03b1) :\n    (Matrix.fromBlocks A B C 1).det = det (A - B \u2b1d C) :=\n  by\n  haveI : Invertible (1 : Matrix n n \u03b1) := invertibleOne\n  rw [det_from_blocks\u2082\u2082, invOf_one, Matrix.mul_one, det_one, one_mul]\n#align matrix.det_from_blocks_one\u2082\u2082 Matrix.det_fromBlocks_one\u2082\u2082\n\n/-- The **Weinstein\u2013Aronszajn identity**. Note the `1` on the LHS is of shape m\u00d7m, while the `1` on\nthe RHS is of shape n\u00d7n. -/\ntheorem det_one_add_mul_comm (A : Matrix m n \u03b1) (B : Matrix n m \u03b1) :\n    det (1 + A \u2b1d B) = det (1 + B \u2b1d A) :=\n  calc\n    det (1 + A \u2b1d B) = det (fromBlocks 1 (-A) B 1) := by\n      rw [det_from_blocks_one\u2082\u2082, Matrix.neg_mul, sub_neg_eq_add]\n    _ = det (1 + B \u2b1d A) := by rw [det_from_blocks_one\u2081\u2081, Matrix.mul_neg, sub_neg_eq_add]\n    \n#align matrix.det_one_add_mul_comm Matrix.det_one_add_mul_comm\n\n/-- Alternate statement of the **Weinstein\u2013Aronszajn identity** -/\ntheorem det_mul_add_one_comm (A : Matrix m n \u03b1) (B : Matrix n m \u03b1) :\n    det (A \u2b1d B + 1) = det (B \u2b1d A + 1) := by rw [add_comm, det_one_add_mul_comm, add_comm]\n#align matrix.det_mul_add_one_comm Matrix.det_mul_add_one_comm\n\ntheorem det_one_sub_mul_comm (A : Matrix m n \u03b1) (B : Matrix n m \u03b1) :\n    det (1 - A \u2b1d B) = det (1 - B \u2b1d A) := by\n  rw [sub_eq_add_neg, \u2190 Matrix.neg_mul, det_one_add_mul_comm, Matrix.mul_neg, \u2190 sub_eq_add_neg]\n#align matrix.det_one_sub_mul_comm Matrix.det_one_sub_mul_comm\n\n/-- A special case of the **Matrix determinant lemma** for when `A = I`.\n\nTODO: show this more generally. -/\ntheorem det_one_add_col_mul_row (u v : m \u2192 \u03b1) : det (1 + col u \u2b1d row v) = 1 + v \u2b1d\u1d65 u := by\n  rw [det_one_add_mul_comm, det_unique, Pi.add_apply, Pi.add_apply, Matrix.one_apply_eq,\n    Matrix.row_mul_col_apply]\n#align matrix.det_one_add_col_mul_row Matrix.det_one_add_col_mul_row\n\nend Det\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/NonsingularInverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7199142328263426}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.normed.group.pointwise\nimport analysis.normed_space.basic\nimport topology.metric_space.hausdorff_distance\n\n/-!\n# Properties of pointwise scalar multiplication of sets in normed spaces.\n\nWe explore the relationships between scalar multiplication of sets in vector spaces, and the norm.\nNotably, we express arbitrary balls as rescaling of other balls, and we show that the\nmultiplication of bounded sets remain bounded.\n-/\n\nopen metric set\nopen_locale pointwise topological_space\n\nsection normed_space\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] {E : Type*} [semi_normed_group E] [normed_space \ud835\udd5c E]\n\ntheorem smul_ball {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 ball x r = ball (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hc,\n  conv_lhs { rw \u2190inv_smul_smul\u2080 hc x },\n  simp [\u2190 div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hc), mul_comm _ r, dist_smul],\nend\n\ntheorem smul_sphere' {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 sphere x r = sphere (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hc,\n  conv_lhs { rw \u2190inv_smul_smul\u2080 hc x },\n  simp only [mem_sphere, dist_smul, normed_field.norm_inv, \u2190 div_eq_inv_mul,\n    div_eq_iff (norm_pos_iff.2 hc).ne', mul_comm r],\nend\n\n/-- In a nontrivial real normed space, a sphere is nonempty if and only if its radius is\nnonnegative. -/\n@[simp] theorem normed_space.sphere_nonempty {E : Type*} [normed_group E]\n  [normed_space \u211d E] [nontrivial E] {x : E} {r : \u211d} :\n  (sphere x r).nonempty \u2194 0 \u2264 r :=\nbegin\n  refine \u27e8\u03bb h, nonempty_closed_ball.1 (h.mono sphere_subset_closed_ball), \u03bb hr, _\u27e9,\n  rcases exists_ne x with \u27e8y, hy\u27e9,\n  have : \u2225y - x\u2225 \u2260 0, by simpa [sub_eq_zero],\n  use r \u2022 \u2225y - x\u2225\u207b\u00b9 \u2022 (y - x) + x,\n  simp [norm_smul, this, real.norm_of_nonneg hr]\nend\n\ntheorem smul_sphere {E : Type*} [normed_group E] [normed_space \ud835\udd5c E] [normed_space \u211d E]\n  [nontrivial E] (c : \ud835\udd5c) (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  c \u2022 sphere x r = sphere (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  rcases eq_or_ne c 0 with rfl|hc,\n  { simp [zero_smul_set, set.singleton_zero, hr] },\n  { exact smul_sphere' hc x r }\nend\n\ntheorem smul_closed_ball' {c : \ud835\udd5c} (hc : c \u2260 0) (x : E) (r : \u211d) :\n  c \u2022 closed_ball x r = closed_ball (c \u2022 x) (\u2225c\u2225 * r) :=\nby simp only [\u2190 ball_union_sphere, set.smul_set_union, smul_ball hc, smul_sphere' hc]\n\nlemma metric.bounded.smul {s : set E} (hs : bounded s) (c : \ud835\udd5c) :\n  bounded (c \u2022 s) :=\nbegin\n  obtain \u27e8R, hR\u27e9 : \u2203 (R : \u211d), \u2200 x \u2208 s, \u2225x\u2225 \u2264 R := hs.exists_norm_le,\n  refine (bounded_iff_exists_norm_le).2 \u27e8\u2225c\u2225 * R, _\u27e9,\n  assume z hz,\n  obtain \u27e8y, ys, rfl\u27e9 : \u2203 (y : E), y \u2208 s \u2227 c \u2022 y = z := mem_smul_set.1 hz,\n  calc \u2225c \u2022 y\u2225 = \u2225c\u2225 * \u2225y\u2225 : norm_smul _ _\n  ... \u2264 \u2225c\u2225 * R : mul_le_mul_of_nonneg_left (hR y ys) (norm_nonneg _)\nend\n\n/-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r \u2022 s` is contained in any\nfixed neighborhood of `x`. -/\nlemma eventually_singleton_add_smul_subset\n  {x : E} {s : set E} (hs : bounded s) {u : set E} (hu : u \u2208 \ud835\udcdd x) :\n  \u2200\u1da0 r in \ud835\udcdd (0 : \ud835\udd5c), {x} + r \u2022 s \u2286 u :=\nbegin\n  obtain \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9 : \u2203 \u03b5 (h\u03b5 : 0 < \u03b5), closed_ball x \u03b5 \u2286 u :=\n    nhds_basis_closed_ball.mem_iff.1 hu,\n  obtain \u27e8R, Rpos, hR\u27e9 : \u2203 (R : \u211d), 0 < R \u2227 s \u2286 closed_ball 0 R := hs.subset_ball_lt 0 0,\n  have : metric.closed_ball (0 : \ud835\udd5c) (\u03b5 / R) \u2208 \ud835\udcdd (0 : \ud835\udd5c) :=\n    closed_ball_mem_nhds _ (div_pos \u03b5pos Rpos),\n  filter_upwards [this] with r hr,\n  simp only [image_add_left, singleton_add],\n  assume y hy,\n  obtain \u27e8z, zs, hz\u27e9 : \u2203 (z : E), z \u2208 s \u2227 r \u2022 z = -x + y, by simpa [mem_smul_set] using hy,\n  have I : \u2225r \u2022 z\u2225 \u2264 \u03b5 := calc\n    \u2225r \u2022 z\u2225 = \u2225r\u2225 * \u2225z\u2225 : norm_smul _ _\n    ... \u2264 (\u03b5 / R) * R :\n      mul_le_mul (mem_closed_ball_zero_iff.1 hr)\n        (mem_closed_ball_zero_iff.1 (hR zs)) (norm_nonneg _) (div_pos \u03b5pos Rpos).le\n    ... = \u03b5 : by field_simp [Rpos.ne'],\n  have : y = x + r \u2022 z, by simp only [hz, add_neg_cancel_left],\n  apply h\u03b5,\n  simpa only [this, dist_eq_norm, add_sub_cancel', mem_closed_ball] using I,\nend\n\nlemma set_smul_mem_nhds_zero {s : set E} (hs : s \u2208 \ud835\udcdd (0 : E)) {c : \ud835\udd5c} (hc : c \u2260 0) :\n  c \u2022 s \u2208 \ud835\udcdd (0 : E) :=\nbegin\n  obtain \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9 : \u2203 (\u03b5 : \u211d) (H : 0 < \u03b5), ball 0 \u03b5 \u2286 s := metric.mem_nhds_iff.1 hs,\n  have : c \u2022 ball (0 : E) \u03b5 \u2208 \ud835\udcdd (0 : E),\n  { rw [smul_ball hc, smul_zero],\n    exact ball_mem_nhds _ (mul_pos (by simpa using hc) \u03b5pos) },\n  exact filter.mem_of_superset this ((set_smul_subset_set_smul_iff\u2080 hc).2 h\u03b5)\nend\n\nlemma set_smul_mem_nhds_zero_iff (s : set E) {c : \ud835\udd5c} (hc : c \u2260 0) :\n  c \u2022 s \u2208 \ud835\udcdd (0 : E) \u2194 s \u2208 \ud835\udcdd(0 : E) :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, set_smul_mem_nhds_zero h hc\u27e9,\n  convert set_smul_mem_nhds_zero h (inv_ne_zero hc),\n  rw [smul_smul, inv_mul_cancel hc, one_smul],\nend\n\nend normed_space\n\nsection normed_space\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] {E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n\ntheorem smul_closed_ball (c : \ud835\udd5c) (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  c \u2022 closed_ball x r = closed_ball (c \u2022 x) (\u2225c\u2225 * r) :=\nbegin\n  rcases eq_or_ne c 0 with rfl|hc,\n  { simp [hr, zero_smul_set, set.singleton_zero, \u2190 nonempty_closed_ball] },\n  { exact smul_closed_ball' hc x r }\nend\n\nend normed_space\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/normed_space/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.719901169218495}}
{"text": "/-\nCopyright (c) 2020 Patrick Stevens. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Stevens\n-/\nimport tactic.ring_exp\nimport data.nat.parity\nimport data.nat.choose.sum\n\n/-!\n# Primorial\n\nThis file defines the primorial function (the product of primes less than or equal to some bound),\nand proves that `primorial n \u2264 4 ^ n`.\n\n## Notations\n\nWe use the local notation `n#` for the primorial of `n`: that is, the product of the primes less\nthan or equal to `n`.\n-/\n\nopen finset\nopen nat\nopen_locale big_operators nat\n\n/-- The primorial `n#` of `n` is the product of the primes less than or equal to `n`.\n-/\ndef primorial (n : \u2115) : \u2115 := \u220f p in (filter nat.prime (range (n + 1))), p\nlocal notation x`#` := primorial x\n\nlemma primorial_succ {n : \u2115} (n_big : 1 < n) (r : n % 2 = 1) : (n + 1)# = n# :=\nbegin\n  have not_prime : \u00acnat.prime (n + 1),\n  { intros is_prime,\n    cases (prime.eq_two_or_odd is_prime) with _ n_even,\n    { linarith, },\n    { apply nat.zero_ne_one,\n      rwa [add_mod, r, nat.one_mod, \u2190two_mul, mul_one, nat.mod_self] at n_even, }, },\n  apply finset.prod_congr,\n  { rw [@range_succ (n + 1), filter_insert, if_neg not_prime], },\n  { exact \u03bb _ _, rfl, },\nend\n\nlemma dvd_choose_of_middling_prime (p : \u2115) (is_prime : nat.prime p) (m : \u2115)\n  (p_big : m + 1 < p) (p_small : p \u2264 2 * m + 1) : p \u2223 choose (2 * m + 1) (m + 1) :=\nbegin\n  have m_size : m + 1 \u2264 2 * m + 1 := le_of_lt (lt_of_lt_of_le p_big p_small),\n  have s : \u00ac(p \u2223 (m + 1)!),\n  { intros p_div_fact,\n    have p_le_succ_m : p \u2264 m + 1 := (prime.dvd_factorial is_prime).mp p_div_fact,\n    linarith, },\n  have t : \u00ac(p \u2223 (2 * m + 1 - (m + 1))!),\n  { intros p_div_fact,\n    have p_small : p \u2264 2 * m + 1 - (m + 1) := (prime.dvd_factorial is_prime).mp p_div_fact,\n    linarith, },\n  have expanded :\n    choose (2 * m + 1) (m + 1) * (m + 1)! * (2 * m + 1 - (m + 1))! = (2 * m + 1)! :=\n    @choose_mul_factorial_mul_factorial (2 * m + 1) (m + 1) m_size,\n  have p_div_big_fact : p \u2223 (2 * m + 1)! := (prime.dvd_factorial is_prime).mpr p_small,\n  rw [\u2190expanded, mul_assoc] at p_div_big_fact,\n  obtain p_div_choose | p_div_facts : p \u2223 choose (2 * m + 1) (m + 1) \u2228 p \u2223 _! * _! :=\n    (prime.dvd_mul is_prime).1 p_div_big_fact,\n  { exact p_div_choose, },\n  cases (prime.dvd_mul is_prime).1 p_div_facts,\n  cc, cc,\nend\n\nlemma prod_primes_dvd {s : finset \u2115} : \u2200 (n : \u2115) (h : \u2200 a \u2208 s, nat.prime a) (div : \u2200 a \u2208 s, a \u2223 n),\n  (\u220f p in s, p) \u2223 n :=\nbegin\n  apply finset.induction_on s,\n  { simp, },\n  { intros a s a_not_in_s induct n primes divs,\n    rw finset.prod_insert a_not_in_s,\n    obtain \u27e8k, rfl\u27e9 : a \u2223 n := divs a (finset.mem_insert_self a s),\n    apply mul_dvd_mul_left a,\n    apply induct k,\n    { intros b b_in_s,\n      exact primes b (finset.mem_insert_of_mem b_in_s), },\n    { intros b b_in_s,\n      have b_div_n := divs b (finset.mem_insert_of_mem b_in_s),\n      have a_prime := primes a (finset.mem_insert_self a s),\n      have b_prime := primes b (finset.mem_insert_of_mem b_in_s),\n      refine ((prime.dvd_mul b_prime).mp b_div_n).resolve_left (\u03bb b_div_a, _),\n      obtain rfl : b = a := ((nat.dvd_prime a_prime).1 b_div_a).resolve_left b_prime.ne_one,\n      exact a_not_in_s b_in_s, } },\nend\n\nlemma primorial_le_4_pow : \u2200 (n : \u2115), n# \u2264 4 ^ n\n| 0 := le_rfl\n| 1 := le_of_inf_eq rfl\n| (n + 2) :=\n  match nat.mod_two_eq_zero_or_one (n + 1) with\n  | or.inl n_odd :=\n    match nat.even_iff.2 n_odd with\n    | \u27e8m, twice_m\u27e9 :=\n      let recurse : m + 1 < n + 2 := by linarith in\n      begin\n        calc (n + 2)#\n            = \u220f i in filter nat.prime (range (2 * m + 2)), i : by simpa [\u2190twice_m]\n        ... = \u220f i in filter nat.prime (finset.Ico (m + 2) (2 * m + 2) \u222a range (m + 2)), i :\n              begin\n                rw [range_eq_Ico, finset.union_comm, finset.Ico_union_Ico_eq_Ico],\n                exact bot_le,\n                simp only [add_le_add_iff_right],\n                linarith,\n              end\n        ... = \u220f i in (filter nat.prime (finset.Ico (m + 2) (2 * m + 2))\n              \u222a (filter nat.prime (range (m + 2)))), i :\n              by rw filter_union\n        ... = (\u220f i in filter nat.prime (finset.Ico (m + 2) (2 * m + 2)), i)\n              * (\u220f i in filter nat.prime (range (m + 2)), i) :\n              begin\n                apply finset.prod_union,\n                have disj : disjoint (finset.Ico (m + 2) (2 * m + 2)) (range (m + 2)),\n                { simp only [finset.disjoint_left, and_imp, finset.mem_Ico, not_lt,\n                    finset.mem_range],\n                  intros _ pr _, exact pr, },\n                exact finset.disjoint_filter_filter disj,\n              end\n        ... \u2264 (\u220f i in filter nat.prime (finset.Ico (m + 2) (2 * m + 2)), i) * 4 ^ (m + 1) :\n              nat.mul_le_mul_left _ (primorial_le_4_pow (m + 1))\n        ... \u2264 (choose (2 * m + 1) (m + 1)) * 4 ^ (m + 1) :\n              begin\n                have s : \u220f i in filter nat.prime (finset.Ico (m + 2) (2 * m + 2)),\n                  i \u2223 choose (2 * m + 1) (m + 1),\n                { refine prod_primes_dvd  (choose (2 * m + 1) (m + 1)) _ _,\n                  { intros a, rw finset.mem_filter, cc, },\n                  { intros a, rw finset.mem_filter,\n                    intros pr,\n                    rcases pr with \u27e8 size, is_prime \u27e9,\n                    simp only [finset.mem_Ico] at size,\n                    rcases size with \u27e8 a_big , a_small \u27e9,\n                    exact dvd_choose_of_middling_prime a is_prime m a_big\n                      (nat.lt_succ_iff.mp a_small), }, },\n                have r : \u220f i in filter nat.prime (finset.Ico (m + 2) (2 * m + 2)),\n                  i \u2264 choose (2 * m + 1) (m + 1),\n                { refine @nat.le_of_dvd _ _ _ s,\n                  exact @choose_pos (2 * m + 1) (m + 1) (by linarith), },\n                exact nat.mul_le_mul_right _ r,\n              end\n        ... = (choose (2 * m + 1) m) * 4 ^ (m + 1) : by rw choose_symm_half m\n        ... \u2264 4 ^ m * 4 ^ (m + 1) : nat.mul_le_mul_right _ (choose_middle_le_pow m)\n        ... = 4 ^ (2 * m + 1) : by ring_exp\n        ... = 4 ^ (n + 2) : by rw \u2190twice_m,\n      end\n    end\n  | or.inr n_even :=\n    begin\n      obtain one_lt_n | n_le_one : 1 < n + 1 \u2228 n + 1 \u2264 1 := lt_or_le 1 (n + 1),\n      { rw primorial_succ (by linarith) n_even,\n        calc (n + 1)#\n              \u2264 4 ^ n.succ : primorial_le_4_pow (n + 1)\n          ... \u2264 4 ^ (n + 2) : pow_le_pow (by norm_num) (nat.le_succ _), },\n      { have n_zero : n = 0 := eq_bot_iff.2 (succ_le_succ_iff.1 n_le_one),\n        norm_num [n_zero, primorial, range_succ, prod_filter, nat.not_prime_zero, nat.prime_two] },\n    end\n\nend\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/number_theory/primorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7199011627843828}}
{"text": "variables p q r : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\n  \u27e8\u03bb h, \u27e8h.right, h.left\u27e9, \u03bb h, \u27e8h.right, h.left\u27e9\u27e9\nexample : p \u2228 q \u2194 q \u2228 p :=\n  \u27e8\u03bb h, h.elim (\u03bb hp, or.inr hp) (\u03bb hq, or.inl hq), \u03bb h, h.elim (\u03bb hp, or.inr hp) (\u03bb hq, or.inl hq)\u27e9\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n  \u27e8\u03bb h, \u27e8h.left.left, h.left.right, h.right\u27e9, \u03bb h, \u27e8\u27e8h.left, h.right.left\u27e9, h.right.right\u27e9\u27e9\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n  \u27e8\u03bb h,\n    h.elim\n      (assume hpq,\n        hpq.elim\n          (assume hp, or.inl hp)\n          (assume hq, or.inr (or.inl hq)))\n      (assume hr,\n        or.inr (or.inr hr)),\n   \u03bb h,\n     h.elim\n       (assume hp, or.inl (or.inl hp))\n       (assume hqr,\n         hqr.elim\n           (assume hq, or.inl (or.inr hq))\n           (assume hr, or.inr hr))\u27e9\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  \u27e8\u03bb h,\n    h.right.elim\n      (assume hq, or.inl \u27e8h.left, hq\u27e9)\n      (assume hr, or.inr \u27e8h.left, hr\u27e9),\n   \u03bb h,\n    h.elim\n      (assume hpq, \u27e8hpq.left, or.inl hpq.right\u27e9)\n      (assume hpr, \u27e8hpr.left, or.inr hpr.right\u27e9)\u27e9\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n  \u27e8\u03bb h,\n    h.elim\n      (assume hp, \u27e8or.inl hp, or.inl hp\u27e9)\n      (assume hqr, \u27e8or.inr hqr.left, or.inr hqr.right\u27e9),\n   \u03bb h,\n    h.left.elim\n      (assume hp, or.inl hp)\n      (assume hq,\n        h.right.elim\n          (assume hp, or.inl hp)\n          (assume hr, or.inr \u27e8hq, hr\u27e9))\u27e9\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n  \u27e8\u03bb h hpq, h hpq.left hpq.right, \u03bb h hp hq, h \u27e8hp, hq\u27e9\u27e9\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\n  \u27e8\u03bb h, \u27e8\u03bb hp, h (or.inl hp), \u03bb hq, h (or.inr hq)\u27e9,\n   \u03bb h hpq,\n     hpq.elim\n       (assume hp, h.left hp)\n       (assume hq, h.right hq)\u27e9\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n  \u27e8\u03bb h, \u27e8\u03bb hp, h (or.inl hp), \u03bb hq, h (or.inr hq)\u27e9, \u03bb h hpq, hpq.elim h.left h.right\u27e9\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n  assume h hpq,\n  h.elim\n    (assume hnp, hnp hpq.left)\n    (assume hnq, hnq hpq.right)\nexample : \u00ac(p \u2227 \u00acp) := \u03bb h, h.right h.left\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n  assume hpnq hp2q,\n  suffices hq : q, from hpnq.right hq,\n  show q, from hp2q hpnq.left\nexample : \u00acp \u2192 (p \u2192 q) := \u03bb hnp hp, absurd hp hnp\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n  assume hnpq hp,\n  hnpq.elim\n    (assume hnp, absurd hp hnp)\n    (assume hq, hq)\nexample : p \u2228 false \u2194 p :=\n  \u27e8\u03bb h, h.elim id false.elim, \u03bb h, or.inl h\u27e9\nexample : p \u2227 false \u2194 false :=\n  \u27e8\u03bb h, h.right, \u03bb h, false.elim h\u27e9\nexample : \u00ac(p \u2194 \u00acp) :=\n  assume h,\n  suffices hnp : \u00acp, from hnp (h.mpr hnp),\n  assume hp,\n  h.mp hp hp\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n  assume hp2q hnq hp,\n  hnq (hp2q hp)\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch3/ex0701.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7199011584545352}}
{"text": "open classical\n\n--one way DeMorgan's Law\nlemma DeMorganOne : \u2200 P Q : Prop, \u00ac (P \u2227 Q) \u2192 \u00ac P \u2228 \u00ac Q :=\nbegin\nassume P Q : Prop,\nassume npq : \u00ac (P \u2227 Q),\nchange (P \u2227 Q) \u2192 false at npq,\nhave pnp : P \u2228 \u00ac P := em P,\nhave qnq : Q \u2228 \u00ac Q := em Q,\ncases pnp with p np,\ncases qnq with q nq,\nhave pq : P \u2227 Q := and.intro p q,\nhave f : false := npq pq,\napply false.elim f,\nright,\nassumption,\nleft,\nassumption,\nend\n\n--check to make sure it works\nvariables (A B : Prop)\n#check DeMorganOne \u00ac A \u00ac B\n\n--defining \u2228 when you only have \u2227\nexample : \u2200 P Q : Prop, P \u2228 Q \u2194 \u00ac(\u00acP \u2227 \u00acQ) :=\nbegin\nassume P Q : Prop,\nsplit,\nassume pq : P \u2228 Q,\nassume npq : \u00ac P \u2227 \u00ac Q,\nshow false,\nfrom\n  begin\n  cases pq with p q,\n  have np : \u00ac P := and.elim_left npq,\n  contradiction,\n  have nq : \u00ac Q := and.elim_right npq,\n  contradiction,\n  end,\nassume nnpnq,\nhave DMO := DeMorganOne (\u00ac P) (\u00ac Q),\nhave nnpnnq : \u00ac \u00ac P \u2228 \u00ac \u00ac Q := DMO nnpnq,\nhave pnp : P \u2228 \u00ac P := em P,\nhave qnq : Q \u2228 \u00ac Q := em Q,\ncases nnpnnq with nnp nnq,\nchange (P \u2192 false) \u2192 false at nnp,\ncases pnp with p np,\nleft,\nassumption,\nchange (P \u2192 false) at np,\nhave f : false := nnp np,\ntrivial,\nchange (Q \u2192 false) \u2192 false at nnq,\ncases qnq with q nq,\nright,\nassumption,\nchange (Q \u2192 false) at nq,\nhave f : false := nnq nq,\ntrivial,\nend\n\n\n--going the other way is easy (I will use more shortcuts)\nlemma DeMorganTwo : \u2200 P Q : Prop, \u00ac (P \u2228 Q) \u2192 \u00ac P \u2227 \u00ac Q :=\nbegin\nintros,\nchange (P \u2228 Q) \u2192 false at a,\nhave pnp := em P,\nhave qnq := em Q,\ncases pnp with p np,\nhave pq := or.inl p,\nhave f := a pq,\ntrivial,\ncases qnq with q nq,\nhave pq := or.inr q,\nhave f := a pq,\ntrivial,\napply and.intro np nq,\nend\n\n-- defining \u2227 from \u2228\nexample : \u2200 P Q : Prop, P \u2227 Q \u2194 \u00ac (\u00ac P \u2228 \u00ac Q) :=\nbegin\nintros,\nsplit,\nintros,\nassume b,\nshow false,\nfrom\n  begin\n  have p := and.elim_left a,\n  have q := and.elim_right a,\n  cases b with np nq,\n  trivial,\n  trivial,\n  end,\nintros,\nhave DMT := DeMorganTwo (\u00ac P) (\u00ac Q),\nhave nnpnnq := DMT a,\nhave pnp := em P,\nhave qnq := em Q,\ncases nnpnnq with nnp nnq,\nchange (\u00ac P) \u2192 false at nnp,\nchange (\u00ac Q) \u2192 false at nnq,\ncases pnp with p np,\ncases qnq with q nq,\napply and.intro p q,\nhave f := nnq nq,\ntrivial,\nhave f := nnp np,\ntrivial\nend\n\n--proving them again without relying on a proof of DML\nexample : \u2200 P Q : Prop, P \u2228 Q \u2194 \u00ac(\u00acP \u2227 \u00acQ) :=\nbegin\nintros,\nsplit,\nintros,\nassume npq,\nshow false,\nfrom\n  begin\n  cases a,\n  have np := and.elim_left npq,\n  trivial,\n  have nq := and.elim_right npq,\n  trivial,\n  end,\nassume nnpnq,\nhave pnp : P \u2228 \u00ac P := em P,\nhave qnq : Q \u2228 \u00ac Q := em Q,\nchange (\u00ac P \u2227 \u00ac Q) \u2192 false at nnpnq,\ncases pnp,\nleft,\nassumption,\ncases qnq,\nright,\nassumption,\nhave f := nnpnq (and.intro pnp qnq),\ntrivial,\nend\n\nexample : \u2200 P Q : Prop, P \u2227 Q \u2194 \u00ac (\u00ac P \u2228 \u00ac Q) :=\nbegin\nintros,\nsplit,\nintros,\nassume b,\nshow false,\nfrom\n  begin\n  have p := and.elim_left a,\n  have q := and.elim_right a,\n  cases b with np nq,\n  trivial,\n  trivial,\n  end,\nintros,\nhave pnp := em P,\nhave qnq := em Q,\nchange (\u00ac P \u2228 \u00ac Q) \u2192 false at a,\ncases pnp with p np,\ncases qnq with q nq,\napply and.intro p q,\nhave f := a (or.inr nq),\ntrivial,\nhave f := a (or.inl np),\ntrivial,\nend", "meta": {"author": "xivh", "repo": "leanpractice", "sha": "a75115fc22da1e69dbe99d2bd9e90f153d2527a5", "save_path": "github-repos/lean/xivh-leanpractice", "path": "github-repos/lean/xivh-leanpractice/leanpractice-a75115fc22da1e69dbe99d2bd9e90f153d2527a5/extra/demorgans law.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.719901154427981}}
{"text": "-- Kuratowski-finite powerset\nimport .preds\n       galois.tactic\n\nuniverses u\n\nsection\nparameter {A : Type u}\ndef incl_elements (xs ys : list A) : Prop :=\n  \u2200 x : A, x \u2208 xs \u2192 x \u2208 ys\n\ndef same_elements (xs ys : list A) : Prop :=\n  \u2200 x : A, x \u2208 xs \u2194 x \u2208 ys\n\ndef incl_same {xs ys : list A}\n  (H : incl_elements xs ys) (H' : incl_elements ys xs)\n  : same_elements xs ys\n:= begin\nintros z, split, apply H, apply H'\nend\n\nlemma incl_elements_refl (xs : list A) : incl_elements xs xs\n:= begin\nintros x H, apply H\nend\n\nlemma incl_elements_trans {xs ys zs : list A}\n  (H : incl_elements xs ys) (H' : incl_elements ys zs)\n  : incl_elements xs zs\n:= begin\nintros x H'', apply H', apply H, assumption,\nend\n\nlemma incl_elements_app {xs ys xs' ys' : list A}\n  (H : incl_elements xs xs') (H' : incl_elements ys ys')\n  : incl_elements (xs ++ ys) (xs' ++ ys')\n:= begin\nintros z X, rw list.mem_append, rw list.mem_append at X,\ninduction X with X X,\nleft, apply H, assumption,\nright, apply H', assumption\nend\n\nlemma same_elements_app_comm {xs ys : list A}\n  : same_elements (xs ++ ys) (ys ++ xs)\n:= begin\nintros z, repeat {rw list.mem_append},\nrw or_comm,\nend\n\nlemma same_elements_refl (xs : list A) : same_elements xs xs\n:= begin\ndsimp [same_elements], intros, trivial,\nend\n\nlemma same_elements_trans {xs ys zs : list A}\n  (H : same_elements xs ys) (H' : same_elements ys zs)\n  : same_elements xs zs\n:= begin\ndsimp [same_elements],\nintros, rw H, rw H',\nend\n\nlemma same_elements_symm {xs ys : list A}\n  (H : same_elements xs ys)\n  : same_elements ys xs\n:= begin\ndsimp [same_elements] at *,\nintros, rw H,\nend\n\ndef same_incl1 {xs ys : list A}\n  (H : same_elements xs ys)\n  : incl_elements xs ys\n:= begin\nintros z,\ndestruct (H z), intros, apply mp, assumption\nend\n\ndef same_incl2 {xs ys : list A}\n  (H : same_elements xs ys)\n  : incl_elements ys xs\n:= begin\nintros z,\ndestruct (H z), intros, apply mpr, assumption\nend\n\ndef same_incl  {xs ys : list A}\n  (H : same_elements xs ys)\n  : incl_elements xs ys \u2227 incl_elements ys xs\n:= begin\nsplit, apply (same_incl1 H), apply (same_incl2 H)\nend\n\nlemma same_elements_app {xs ys xs' ys' : list A}\n  (H : same_elements xs xs') (H' : same_elements ys ys')\n  : same_elements (xs ++ ys) (xs' ++ ys')\n:= begin\napply incl_same,\napply incl_elements_app; apply same_incl1; assumption,\napply incl_elements_app; apply same_incl2; assumption,\nend\n\n\ndef cons_mono {x y : A} {xs ys : list A}\n  (Hhd : x = y)\n  (Htl : incl_elements xs ys)\n  : incl_elements (x :: xs) (y :: ys)\n:= begin\ninduction Hhd,\nintros z Hz, simp [has_mem.mem, list.mem] at Hz,\ninduction Hz, induction a, simp [has_mem.mem, list.mem],\nsimp [has_mem.mem, list.mem],\nright, apply Htl, assumption\nend\n\ndef cons_same {x y : A} {xs ys : list A}\n  (Hhd : x = y)\n  (Htl : same_elements xs ys)\n  : same_elements (x :: xs) (y :: ys)\n:= begin\nhave Htl' := same_incl Htl, clear Htl,\ninduction Htl' with Htl1 Htl2,\napply incl_same; apply cons_mono, assumption,\napply Htl1, symmetry, assumption, apply Htl2,\nend\n\nend\n\ndef fpow (A : Type u) := quot (@same_elements A)\n\nnamespace fpow\nsection\nparameter {A : Type u}\n\ndef from_list : list A \u2192 fpow A := quot.mk _\n\ndef nil : fpow A := quot.mk _ []\n\ndef cons (x : A) (xs : fpow A) : fpow A :=\nbegin\nfapply (quot.lift_on xs); clear xs,\nexact (\u03bb xs, quot.mk _ (x :: xs)),\nintros xs ys Heq, apply quot.sound,\nunfold same_elements,\nintros z, apply cons_same, reflexivity, assumption\nend\n\ninstance mem  : has_mem A (fpow A) :=\nbegin\nconstructor, intros x xs,\nfapply (quot.lift_on xs); clear xs,\nexact (\u03bb xs, x \u2208 xs),\nintros xs ys H, apply propext, apply H\nend\n\nend\n\nend fpow\n\nlemma same_elements_fpow {A} {xs ys : list A}\n  : same_elements xs ys \u2194 fpow.from_list xs = fpow.from_list ys\n:= begin\nsplit; intros H,\napply quot.sound, assumption,\nhave H' := quot.exact _ H,\nclear H,\ninduction H', assumption,\napply same_elements_refl,\napply same_elements_symm; assumption,\napply same_elements_trans; assumption,\nend", "meta": {"author": "GaloisInc", "repo": "lean-protocol-support", "sha": "cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda", "save_path": "github-repos/lean/GaloisInc-lean-protocol-support", "path": "github-repos/lean/GaloisInc-lean-protocol-support/lean-protocol-support-cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda/galois/list/fpow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.7199008965524231}}
{"text": "import tactic\nimport data.set.basic\n\nopen set\n\n/-- a cover of X is a set of subsets of X whose union is X -/\nstructure cover (X : Type) :=\n(C : set (set X))\n(cov : \u2200 x : X, \u2203 U \u2208 C, x \u2208 U)\n\n-- note that the subset X of X isn't called X! X is a type. The subset X of X\n-- is called `univ`\n\n/-- The cover {X} of X -/\ndef univ_cover (X : Type) : cover X :=\n{ C := {univ},\n  cov := by simp} -- proof it's a cover is obvious and `simp` finds it\n\nvariable {X : Type}\n\n-- definition of star refinement\ndef star_ref (P : cover X) (Q : cover X) :=\n\u2200 A \u2208 P.C, \u2203 U \u2208 Q.C, \u2200 B \u2208 P.C, A \u2229 B \u2260 \u2205 \u2192 B \u2286 U\n\n-- this may or may not work, Lean might get confused because `<` means something else\nnotation P ` <* ` Q := star_ref P Q\n\ntheorem star_ref_iff (P : cover X) (Q : cover X) :\nP <* Q \u2194 \u2200 A \u2208 P.C, \u2203 U \u2208 Q.C, \u2200 B \u2208 P.C, A \u2229 B \u2260 \u2205 \u2192 B \u2286 U := iff.rfl\n\n/-\n    {X} is a uniform cover (i.e. {X} \u2208 \u0398).\n    If P <* Q and P is a uniform cover, then Q is also a uniform cover.\n    If P and Q are uniform covers, then there is a uniform cover R that \n    star-refines both P and Q.\n\nGiven a point x and a uniform cover P, one can consider the union of the members of P that contain x as a typical neighbourhood of x of \"size\" P, and this intuitive measure applies uniformly over the space.\n\nGiven a uniform space in the entourage sense, define a cover P to be uniform if there is some entourage U such that for each x \u2208 X, there is an A \u2208 P such that U[x] \u2286 A. These uniform covers form a uniform space as in the second definition. Conversely, given a uniform space in the uniform cover sense, the supersets of \u22c3{A \u00d7 A : A \u2208 P}, as P ranges over the uniform covers, are the entourages for a uniform space as in the first definition. Moreover, these two transformations are inverses of each other. \n-/\n\n/-- A distinguished family of covers for a set X is a filter for <*  -/\nstructure dist_covers (X : Type) :=\n-- collection of covers\n(\u0398 : set (cover X) )\n-- {X} is in \u0398\n(univ_mem : univ_cover X \u2208 \u0398)\n-- if P is in \u0398 and P <* Q then Q is in \u0398\n(star_mem (P Q : cover X) (hP : P \u2208 \u0398) (hPQ : P <* Q) : Q \u2208 \u0398)\n-- if P, Q \u2208 \u0398 then there exists R \u2208 \u0398 with P <* R and Q <* R\n(ub_mem (P Q : cover X) (hP : P \u2208 \u0398) (hQ : Q \u2208 \u0398) : \u2203 R : cover X, R \u2208 \u0398 \u2227 R <* P \u2227 R <* Q)\n", "meta": {"author": "ImperialCollegeLondon", "repo": "uniform-structures", "sha": "a41a170ef125b36bdac1e2201f54affa958d0349", "save_path": "github-repos/lean/ImperialCollegeLondon-uniform-structures", "path": "github-repos/lean/ImperialCollegeLondon-uniform-structures/uniform-structures-a41a170ef125b36bdac1e2201f54affa958d0349/src/uniform_structure/covers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7199008945449836}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n\n! This file was ported from Lean 3 source module set_theory.game.birthday\n! leanprover-community/mathlib commit a347076985674932c0e91da09b9961ed0a79508c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.SetTheory.Game.Ordinal\nimport Mathbin.SetTheory.Ordinal.NaturalOps\n\n/-!\n# Birthdays of games\n\nThe birthday of a game is an ordinal that represents at which \"step\" the game was constructed. We\ndefine it recursively as the least ordinal larger than the birthdays of its left and right games. We\nprove the basic properties about these.\n\n# Main declarations\n\n- `pgame.birthday`: The birthday of a pre-game.\n\n# Todo\n\n- Define the birthdays of `game`s and `surreal`s.\n- Characterize the birthdays of basic arithmetical operations.\n-/\n\n\nuniverse u\n\nopen Ordinal\n\nopen NaturalOps Pgame\n\nnamespace Pgame\n\n/-- The birthday of a pre-game is inductively defined as the least strict upper bound of the\nbirthdays of its left and right games. It may be thought as the \"step\" in which a certain game is\nconstructed. -/\nnoncomputable def birthday : Pgame.{u} \u2192 Ordinal.{u}\n  | \u27e8xl, xr, xL, xR\u27e9 =>\n    max (lsub.{u, u} fun i => birthday (xL i)) (lsub.{u, u} fun i => birthday (xR i))\n#align pgame.birthday Pgame.birthday\n\ntheorem birthday_def (x : Pgame) :\n    birthday x =\n      max (lsub.{u, u} fun i => birthday (x.moveLeft i))\n        (lsub.{u, u} fun i => birthday (x.moveRight i)) :=\n  by\n  cases x\n  rw [birthday]\n  rfl\n#align pgame.birthday_def Pgame.birthday_def\n\ntheorem birthday_moveLeft_lt {x : Pgame} (i : x.LeftMoves) : (x.moveLeft i).birthday < x.birthday :=\n  by\n  cases x\n  rw [birthday]\n  exact lt_max_of_lt_left (lt_lsub _ i)\n#align pgame.birthday_move_left_lt Pgame.birthday_moveLeft_lt\n\ntheorem birthday_moveRight_lt {x : Pgame} (i : x.RightMoves) :\n    (x.moveRight i).birthday < x.birthday := by\n  cases x\n  rw [birthday]\n  exact lt_max_of_lt_right (lt_lsub _ i)\n#align pgame.birthday_move_right_lt Pgame.birthday_moveRight_lt\n\ntheorem lt_birthday_iff {x : Pgame} {o : Ordinal} :\n    o < x.birthday \u2194\n      (\u2203 i : x.LeftMoves, o \u2264 (x.moveLeft i).birthday) \u2228\n        \u2203 i : x.RightMoves, o \u2264 (x.moveRight i).birthday :=\n  by\n  constructor\n  \u00b7 rw [birthday_def]\n    intro h\n    cases' lt_max_iff.1 h with h' h'\n    \u00b7 left\n      rwa [lt_lsub_iff] at h'\n    \u00b7 right\n      rwa [lt_lsub_iff] at h'\n  \u00b7 rintro (\u27e8i, hi\u27e9 | \u27e8i, hi\u27e9)\n    \u00b7 exact hi.trans_lt (birthday_move_left_lt i)\n    \u00b7 exact hi.trans_lt (birthday_move_right_lt i)\n#align pgame.lt_birthday_iff Pgame.lt_birthday_iff\n\ntheorem Relabelling.birthday_congr : \u2200 {x y : Pgame.{u}}, x \u2261r y \u2192 birthday x = birthday y\n  | \u27e8xl, xr, xL, xR\u27e9, \u27e8yl, yr, yL, yR\u27e9, r =>\n    by\n    unfold birthday\n    congr 1\n    all_goals\n      apply lsub_eq_of_range_eq.{u, u, u}\n      ext i; constructor\n    all_goals rintro \u27e8j, rfl\u27e9\n    \u00b7 exact \u27e8_, (r.move_left j).birthday_congr.symm\u27e9\n    \u00b7 exact \u27e8_, (r.move_left_symm j).birthday_congr\u27e9\n    \u00b7 exact \u27e8_, (r.move_right j).birthday_congr.symm\u27e9\n    \u00b7 exact \u27e8_, (r.move_right_symm j).birthday_congr\u27e9decreasing_by pgame_wf_tac\n#align pgame.relabelling.birthday_congr Pgame.Relabelling.birthday_congr\n\n@[simp]\ntheorem birthday_eq_zero {x : Pgame} :\n    birthday x = 0 \u2194 IsEmpty x.LeftMoves \u2227 IsEmpty x.RightMoves := by\n  rw [birthday_def, max_eq_zero, lsub_eq_zero_iff, lsub_eq_zero_iff]\n#align pgame.birthday_eq_zero Pgame.birthday_eq_zero\n\n@[simp]\ntheorem birthday_zero : birthday 0 = 0 := by simp [PEmpty.isEmpty]\n#align pgame.birthday_zero Pgame.birthday_zero\n\n@[simp]\ntheorem birthday_one : birthday 1 = 1 := by\n  rw [birthday_def]\n  simp\n#align pgame.birthday_one Pgame.birthday_one\n\n@[simp]\ntheorem birthday_star : birthday star = 1 :=\n  by\n  rw [birthday_def]\n  simp\n#align pgame.birthday_star Pgame.birthday_star\n\n@[simp]\ntheorem neg_birthday : \u2200 x : Pgame, (-x).birthday = x.birthday\n  | \u27e8xl, xr, xL, xR\u27e9 => by\n    rw [birthday_def, birthday_def, max_comm]\n    congr <;> funext <;> apply neg_birthday\n#align pgame.neg_birthday Pgame.neg_birthday\n\n@[simp]\ntheorem toPgame_birthday (o : Ordinal) : o.toPgame.birthday = o :=\n  by\n  induction' o using Ordinal.induction with o IH\n  rw [to_pgame_def, Pgame.birthday]\n  simp only [lsub_empty, max_zero_right]\n  nth_rw 1 [\u2190 lsub_typein o]\n  congr with x\n  exact IH _ (typein_lt_self x)\n#align pgame.to_pgame_birthday Pgame.toPgame_birthday\n\ntheorem le_birthday : \u2200 x : Pgame, x \u2264 x.birthday.toPgame\n  | \u27e8xl, _, xL, _\u27e9 =>\n    le_def.2\n      \u27e8fun i =>\n        Or.inl \u27e8toLeftMovesToPgame \u27e8_, birthday_moveLeft_lt i\u27e9, by simp [le_birthday (xL i)]\u27e9,\n        isEmptyElim\u27e9\n#align pgame.le_birthday Pgame.le_birthday\n\nvariable (a b x : Pgame.{u})\n\ntheorem neg_birthday_le : -x.birthday.toPgame \u2264 x := by\n  simpa only [neg_birthday, \u2190 neg_le_iff] using le_birthday (-x)\n#align pgame.neg_birthday_le Pgame.neg_birthday_le\n\n@[simp]\ntheorem birthday_add : \u2200 x y : Pgame.{u}, (x + y).birthday = x.birthday \u266f y.birthday\n  | \u27e8xl, xr, xL, xR\u27e9, \u27e8yl, yr, yL, yR\u27e9 =>\n    by\n    rw [birthday_def, nadd_def]\n    simp only [birthday_add, lsub_sum, mk_add_move_left_inl, move_left_mk, mk_add_move_left_inr,\n      mk_add_move_right_inl, move_right_mk, mk_add_move_right_inr]\n    rw [max_max_max_comm]\n    congr <;> apply le_antisymm\n    any_goals\n      exact\n        max_le_iff.2\n          \u27e8lsub_le_iff.2 fun i => lt_blsub _ _ (birthday_move_left_lt i),\n            lsub_le_iff.2 fun i => lt_blsub _ _ (birthday_move_right_lt i)\u27e9\n    all_goals\n      apply blsub_le_iff.2 fun i hi => _\n      rcases lt_birthday_iff.1 hi with (\u27e8j, hj\u27e9 | \u27e8j, hj\u27e9)\n    \u00b7 exact lt_max_of_lt_left ((nadd_le_nadd_right hj _).trans_lt (lt_lsub _ _))\n    \u00b7 exact lt_max_of_lt_right ((nadd_le_nadd_right hj _).trans_lt (lt_lsub _ _))\n    \u00b7 exact lt_max_of_lt_left ((nadd_le_nadd_left hj _).trans_lt (lt_lsub _ _))\n    \u00b7 exact lt_max_of_lt_right ((nadd_le_nadd_left hj _).trans_lt (lt_lsub _ _))decreasing_by\n  pgame_wf_tac\n#align pgame.birthday_add Pgame.birthday_add\n\ntheorem birthday_add_zero : (a + 0).birthday = a.birthday := by simp\n#align pgame.birthday_add_zero Pgame.birthday_add_zero\n\ntheorem birthday_zero_add : (0 + a).birthday = a.birthday := by simp\n#align pgame.birthday_zero_add Pgame.birthday_zero_add\n\ntheorem birthday_add_one : (a + 1).birthday = Order.succ a.birthday := by simp\n#align pgame.birthday_add_one Pgame.birthday_add_one\n\ntheorem birthday_one_add : (1 + a).birthday = Order.succ a.birthday := by simp\n#align pgame.birthday_one_add Pgame.birthday_one_add\n\n@[simp]\ntheorem birthday_nat_cast : \u2200 n : \u2115, birthday n = n\n  | 0 => birthday_zero\n  | n + 1 => by simp [birthday_nat_cast]\n#align pgame.birthday_nat_cast Pgame.birthday_nat_cast\n\ntheorem birthday_add_nat (n : \u2115) : (a + n).birthday = a.birthday + n := by simp\n#align pgame.birthday_add_nat Pgame.birthday_add_nat\n\ntheorem birthday_nat_add (n : \u2115) : (\u2191n + a).birthday = a.birthday + n := by simp\n#align pgame.birthday_nat_add Pgame.birthday_nat_add\n\nend Pgame\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/SetTheory/Game/Birthday.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7199008693390145}}
{"text": "/-\nCopyright (c) 2020 Alexander Bentkamp, S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp, S\u00e9bastien Gou\u00ebzel, Eric Wieser\n\n! This file was ported from Lean 3 source module data.complex.module\n! leanprover-community/mathlib commit c310cfdc40da4d99a10a58c33a95360ef9e6e0bf\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Orientation\nimport Mathbin.Algebra.Order.Smul\nimport Mathbin.Data.Complex.Basic\nimport Mathbin.Data.Fin.VecNotation\nimport Mathbin.FieldTheory.Tower\nimport Mathbin.Algebra.CharP.Invertible\n\n/-!\n# Complex number as a vector space over `\u211d`\n\nThis file contains the following instances:\n* Any `\u2022`-structure (`has_smul`, `mul_action`, `distrib_mul_action`, `module`, `algebra`) on\n  `\u211d` imbues a corresponding structure on `\u2102`. This includes the statement that `\u2102` is an `\u211d`\n  algebra.\n* any complex vector space is a real vector space;\n* any finite dimensional complex vector space is a finite dimensional real vector space;\n* the space of `\u211d`-linear maps from a real vector space to a complex vector space is a complex\n  vector space.\n\nIt also defines bundled versions of four standard maps (respectively, the real part, the imaginary\npart, the embedding of `\u211d` in `\u2102`, and the complex conjugate):\n\n* `complex.re_lm` (`\u211d`-linear map);\n* `complex.im_lm` (`\u211d`-linear map);\n* `complex.of_real_am` (`\u211d`-algebra (homo)morphism);\n* `complex.conj_ae` (`\u211d`-algebra equivalence).\n\nIt also provides a universal property of the complex numbers `complex.lift`, which constructs a\n`\u2102 \u2192\u2090[\u211d] A` into any `\u211d`-algebra `A` given a square root of `-1`.\n\nIn addition, this file provides a decomposition into `real_part` and `imaginary_part` for any\nelement of a `star_module` over `\u2102`.\n\n## Notation\n\n* `\u211c` and `\u2111` for the `real_part` and `imaginary_part`, respectively, in the locale\n  `complex_star_module`.\n-/\n\n\nnamespace Complex\n\nopen ComplexConjugate\n\nvariable {R : Type _} {S : Type _}\n\nsection\n\nvariable [SMul R \u211d]\n\n/- The useless `0` multiplication in `smul` is to make sure that\n`restrict_scalars.module \u211d \u2102 \u2102 = complex.module` definitionally. -/\ninstance : SMul R \u2102 where smul r x := \u27e8r \u2022 x.re - 0 * x.im, r \u2022 x.im + 0 * x.re\u27e9\n\ntheorem smul_re (r : R) (z : \u2102) : (r \u2022 z).re = r \u2022 z.re := by simp [(\u00b7 \u2022 \u00b7)]\n#align complex.smul_re Complex.smul_re\n\ntheorem smul_im (r : R) (z : \u2102) : (r \u2022 z).im = r \u2022 z.im := by simp [(\u00b7 \u2022 \u00b7)]\n#align complex.smul_im Complex.smul_im\n\n@[simp]\ntheorem real_smul {x : \u211d} {z : \u2102} : x \u2022 z = x * z :=\n  rfl\n#align complex.real_smul Complex.real_smul\n\nend\n\ninstance [SMul R \u211d] [SMul S \u211d] [SMulCommClass R S \u211d] : SMulCommClass R S \u2102\n    where smul_comm r s x := by ext <;> simp [smul_re, smul_im, smul_comm]\n\ninstance [SMul R S] [SMul R \u211d] [SMul S \u211d] [IsScalarTower R S \u211d] : IsScalarTower R S \u2102\n    where smul_assoc r s x := by ext <;> simp [smul_re, smul_im, smul_assoc]\n\ninstance [SMul R \u211d] [SMul R\u1d50\u1d52\u1d56 \u211d] [IsCentralScalar R \u211d] : IsCentralScalar R \u2102\n    where op_smul_eq_smul r x := by ext <;> simp [smul_re, smul_im, op_smul_eq_smul]\n\ninstance [Monoid R] [MulAction R \u211d] : MulAction R \u2102\n    where\n  one_smul x := by ext <;> simp [smul_re, smul_im, one_smul]\n  mul_smul r s x := by ext <;> simp [smul_re, smul_im, mul_smul]\n\ninstance [DistribSMul R \u211d] : DistribSMul R \u2102\n    where\n  smul_add r x y := by ext <;> simp [smul_re, smul_im, smul_add]\n  smul_zero r := by ext <;> simp [smul_re, smul_im, smul_zero]\n\ninstance [Semiring R] [DistribMulAction R \u211d] : DistribMulAction R \u2102 :=\n  { Complex.distribSmul with }\n\ninstance [Semiring R] [Module R \u211d] : Module R \u2102\n    where\n  add_smul r s x := by ext <;> simp [smul_re, smul_im, add_smul]\n  zero_smul r := by ext <;> simp [smul_re, smul_im, zero_smul]\n\ninstance [CommSemiring R] [Algebra R \u211d] : Algebra R \u2102 :=\n  { Complex.ofReal.comp (algebraMap R \u211d) with\n    smul := (\u00b7 \u2022 \u00b7)\n    smul_def' := fun r x => by ext <;> simp [smul_re, smul_im, Algebra.smul_def]\n    commutes' := fun r \u27e8xr, xi\u27e9 => by ext <;> simp [smul_re, smul_im, Algebra.commutes] }\n\ninstance : StarModule \u211d \u2102 :=\n  \u27e8fun r x => by simp only [star_def, star_trivial, real_smul, map_mul, conj_of_real]\u27e9\n\n@[simp]\ntheorem coe_algebraMap : (algebraMap \u211d \u2102 : \u211d \u2192 \u2102) = coe :=\n  rfl\n#align complex.coe_algebra_map Complex.coe_algebraMap\n\nsection\n\nvariable {A : Type _} [Semiring A] [Algebra \u211d A]\n\n/-- We need this lemma since `complex.coe_algebra_map` diverts the simp-normal form away from\n`alg_hom.commutes`. -/\n@[simp]\ntheorem AlgHom.map_coe_real_complex (f : \u2102 \u2192\u2090[\u211d] A) (x : \u211d) : f x = algebraMap \u211d A x :=\n  f.commutes x\n#align alg_hom.map_coe_real_complex AlgHom.map_coe_real_complex\n\n/-- Two `\u211d`-algebra homomorphisms from \u2102 are equal if they agree on `complex.I`. -/\n@[ext]\ntheorem algHom_ext \u2983f g : \u2102 \u2192\u2090[\u211d] A\u2984 (h : f I = g I) : f = g :=\n  by\n  ext \u27e8x, y\u27e9\n  simp only [mk_eq_add_mul_I, AlgHom.map_add, AlgHom.map_coe_real_complex, AlgHom.map_mul, h]\n#align complex.alg_hom_ext Complex.algHom_ext\n\nend\n\nsection\n\nopen ComplexOrder\n\nprotected theorem orderedSMul : OrderedSMul \u211d \u2102 :=\n  OrderedSMul.mk' fun a b r hab hr => \u27e8by simp [hr, hab.1.le], by simp [hab.2]\u27e9\n#align complex.ordered_smul Complex.orderedSMul\n\nscoped[ComplexOrder] attribute [instance] Complex.orderedSMul\n\nend\n\nopen Submodule FiniteDimensional\n\n/-- `\u2102` has a basis over `\u211d` given by `1` and `I`. -/\nnoncomputable def basisOneI : Basis (Fin 2) \u211d \u2102 :=\n  Basis.ofEquivFun\n    { toFun := fun z => ![z.re, z.im]\n      invFun := fun c => c 0 + c 1 \u2022 I\n      left_inv := fun z => by simp\n      right_inv := fun c => by\n        ext i\n        fin_cases i <;> simp\n      map_add' := fun z z' => by simp\n      -- why does `simp` not know how to apply `smul_cons`, which is a `@[simp]` lemma, here?\n      map_smul' := fun c z => by simp [Matrix.smul_cons c z.re, Matrix.smul_cons c z.im] }\n#align complex.basis_one_I Complex.basisOneI\n\n@[simp]\ntheorem coe_basisOneI_repr (z : \u2102) : \u21d1(basisOneI.repr z) = ![z.re, z.im] :=\n  rfl\n#align complex.coe_basis_one_I_repr Complex.coe_basisOneI_repr\n\n@[simp]\ntheorem coe_basisOneI : \u21d1basisOneI = ![1, I] :=\n  funext fun i =>\n    Basis.apply_eq_iff.mpr <|\n      Finsupp.ext fun j => by\n        fin_cases i <;> fin_cases j <;>\n          simp only [coe_basis_one_I_repr, Finsupp.single_eq_of_ne, Matrix.cons_val_zero,\n            Matrix.cons_val_one, Matrix.head_cons, Fin.one_eq_zero_iff, Ne.def, not_false_iff, I_re,\n            Nat.succ_succ_ne_one, one_im, I_im, one_re, Finsupp.single_eq_same, Fin.zero_eq_one_iff]\n#align complex.coe_basis_one_I Complex.coe_basisOneI\n\ninstance : FiniteDimensional \u211d \u2102 :=\n  of_fintype_basis basisOneI\n\n@[simp]\ntheorem finrank_real_complex : FiniteDimensional.finrank \u211d \u2102 = 2 := by\n  rw [finrank_eq_card_basis basis_one_I, Fintype.card_fin]\n#align complex.finrank_real_complex Complex.finrank_real_complex\n\n@[simp]\ntheorem dim_real_complex : Module.rank \u211d \u2102 = 2 := by simp [\u2190 finrank_eq_dim, finrank_real_complex]\n#align complex.dim_real_complex Complex.dim_real_complex\n\ntheorem dim_real_complex'.{u} : Cardinal.lift.{u} (Module.rank \u211d \u2102) = 2 := by\n  simp [\u2190 finrank_eq_dim, finrank_real_complex, bit0]\n#align complex.dim_real_complex' Complex.dim_real_complex'\n\n/-- `fact` version of the dimension of `\u2102` over `\u211d`, locally useful in the definition of the\ncircle. -/\ntheorem finrank_real_complex_fact : Fact (finrank \u211d \u2102 = 2) :=\n  \u27e8finrank_real_complex\u27e9\n#align complex.finrank_real_complex_fact Complex.finrank_real_complex_fact\n\n/-- The standard orientation on `\u2102`. -/\nprotected noncomputable def orientation : Orientation \u211d \u2102 (Fin 2) :=\n  Complex.basisOneI.Orientation\n#align complex.orientation Complex.orientation\n\nend Complex\n\n/- Register as an instance (with low priority) the fact that a complex vector space is also a real\nvector space. -/\ninstance (priority := 900) Module.complexToReal (E : Type _) [AddCommGroup E] [Module \u2102 E] :\n    Module \u211d E :=\n  RestrictScalars.module \u211d \u2102 E\n#align module.complex_to_real Module.complexToReal\n\ninstance Module.real_complex_tower (E : Type _) [AddCommGroup E] [Module \u2102 E] :\n    IsScalarTower \u211d \u2102 E :=\n  RestrictScalars.isScalarTower \u211d \u2102 E\n#align module.real_complex_tower Module.real_complex_tower\n\n@[simp, norm_cast]\ntheorem Complex.coe_smul {E : Type _} [AddCommGroup E] [Module \u2102 E] (x : \u211d) (y : E) :\n    (x : \u2102) \u2022 y = x \u2022 y :=\n  rfl\n#align complex.coe_smul Complex.coe_smul\n\n/-- The scalar action of `\u211d` on a `\u2102`-module `E` induced by `module.complex_to_real` commutes with\nanother scalar action of `M` on `E` whenever the action of `\u2102` commutes with the action of `M`. -/\ninstance (priority := 900) SMulCommClass.complexToReal {M E : Type _} [AddCommGroup E] [Module \u2102 E]\n    [SMul M E] [SMulCommClass \u2102 M E] : SMulCommClass \u211d M E\n    where smul_comm r _ _ := (smul_comm (r : \u2102) _ _ : _)\n#align smul_comm_class.complex_to_real SMulCommClass.complexToReal\n\ninstance (priority := 100) FiniteDimensional.complexToReal (E : Type _) [AddCommGroup E]\n    [Module \u2102 E] [FiniteDimensional \u2102 E] : FiniteDimensional \u211d E :=\n  FiniteDimensional.trans \u211d \u2102 E\n#align finite_dimensional.complex_to_real FiniteDimensional.complexToReal\n\ntheorem dim_real_of_complex (E : Type _) [AddCommGroup E] [Module \u2102 E] :\n    Module.rank \u211d E = 2 * Module.rank \u2102 E :=\n  Cardinal.lift_inj.1 <| by\n    rw [\u2190 dim_mul_dim' \u211d \u2102 E, Complex.dim_real_complex]\n    simp [bit0]\n#align dim_real_of_complex dim_real_of_complex\n\ntheorem finrank_real_of_complex (E : Type _) [AddCommGroup E] [Module \u2102 E] :\n    FiniteDimensional.finrank \u211d E = 2 * FiniteDimensional.finrank \u2102 E := by\n  rw [\u2190 FiniteDimensional.finrank_mul_finrank \u211d \u2102 E, Complex.finrank_real_complex]\n#align finrank_real_of_complex finrank_real_of_complex\n\ninstance (priority := 900) StarModule.complexToReal {E : Type _} [AddCommGroup E] [Star E]\n    [Module \u2102 E] [StarModule \u2102 E] : StarModule \u211d E :=\n  \u27e8fun r a => by rw [\u2190 smul_one_smul \u2102 r a, star_smul, star_smul, star_one, smul_one_smul]\u27e9\n#align star_module.complex_to_real StarModule.complexToReal\n\nnamespace Complex\n\nopen ComplexConjugate\n\n/-- Linear map version of the real part function, from `\u2102` to `\u211d`. -/\ndef reLm : \u2102 \u2192\u2097[\u211d] \u211d where\n  toFun x := x.re\n  map_add' := add_re\n  map_smul' := by simp\n#align complex.re_lm Complex.reLm\n\n@[simp]\ntheorem reLm_coe : \u21d1reLm = re :=\n  rfl\n#align complex.re_lm_coe Complex.reLm_coe\n\n/-- Linear map version of the imaginary part function, from `\u2102` to `\u211d`. -/\ndef imLm : \u2102 \u2192\u2097[\u211d] \u211d where\n  toFun x := x.im\n  map_add' := add_im\n  map_smul' := by simp\n#align complex.im_lm Complex.imLm\n\n@[simp]\ntheorem imLm_coe : \u21d1imLm = im :=\n  rfl\n#align complex.im_lm_coe Complex.imLm_coe\n\n/-- `\u211d`-algebra morphism version of the canonical embedding of `\u211d` in `\u2102`. -/\ndef ofRealAm : \u211d \u2192\u2090[\u211d] \u2102 :=\n  Algebra.ofId \u211d \u2102\n#align complex.of_real_am Complex.ofRealAm\n\n@[simp]\ntheorem ofRealAm_coe : \u21d1ofRealAm = coe :=\n  rfl\n#align complex.of_real_am_coe Complex.ofRealAm_coe\n\n/-- `\u211d`-algebra isomorphism version of the complex conjugation function from `\u2102` to `\u2102` -/\ndef conjAe : \u2102 \u2243\u2090[\u211d] \u2102 :=\n  { conj with\n    invFun := conj\n    left_inv := star_star\n    right_inv := star_star\n    commutes' := conj_ofReal }\n#align complex.conj_ae Complex.conjAe\n\n@[simp]\ntheorem conjAe_coe : \u21d1conjAe = conj :=\n  rfl\n#align complex.conj_ae_coe Complex.conjAe_coe\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:207:4: warning: unsupported notation `\u00abexpr!![ \u00bb -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:387:14: unsupported user notation matrix.notation -/\n/-- The matrix representation of `conj_ae`. -/\n@[simp]\ntheorem toMatrix_conjAe :\n    LinearMap.toMatrix basisOneI basisOneI conjAe.toLinearMap =\n      \u00abexpr!![ \u00bb\n        \"./././Mathport/Syntax/Translate/Expr.lean:387:14: unsupported user notation matrix.notation\" :=\n  by\n  ext (i j)\n  simp [LinearMap.toMatrix_apply]\n  fin_cases i <;> fin_cases j <;> simp\n#align complex.to_matrix_conj_ae Complex.toMatrix_conjAe\n\n/-- The identity and the complex conjugation are the only two `\u211d`-algebra homomorphisms of `\u2102`. -/\ntheorem real_algHom_eq_id_or_conj (f : \u2102 \u2192\u2090[\u211d] \u2102) : f = AlgHom.id \u211d \u2102 \u2228 f = conjAe :=\n  by\n  refine'\n      (eq_or_eq_neg_of_sq_eq_sq (f I) I <| by rw [\u2190 map_pow, I_sq, map_neg, map_one]).imp _ _ <;>\n    refine' fun h => alg_hom_ext _\n  exacts[h, conj_I.symm \u25b8 h]\n#align complex.real_alg_hom_eq_id_or_conj Complex.real_algHom_eq_id_or_conj\n\n/-- The natural `add_equiv` from `\u2102` to `\u211d \u00d7 \u211d`. -/\n@[simps (config := { simpRhs := true }) apply symm_apply_re symm_apply_im]\ndef equivRealProdAddHom : \u2102 \u2243+ \u211d \u00d7 \u211d :=\n  { equivRealProd with map_add' := by simp }\n#align complex.equiv_real_prod_add_hom Complex.equivRealProdAddHom\n\n/-- The natural `linear_equiv` from `\u2102` to `\u211d \u00d7 \u211d`. -/\n@[simps (config := { simpRhs := true }) apply symm_apply_re symm_apply_im]\ndef equivRealProdLm : \u2102 \u2243\u2097[\u211d] \u211d \u00d7 \u211d :=\n  { equivRealProdAddHom with map_smul' := by simp [equiv_real_prod_add_hom] }\n#align complex.equiv_real_prod_lm Complex.equivRealProdLm\n\nsection lift\n\nvariable {A : Type _} [Ring A] [Algebra \u211d A]\n\n/-- There is an alg_hom from `\u2102` to any `\u211d`-algebra with an element that squares to `-1`.\n\nSee `complex.lift` for this as an equiv. -/\ndef liftAux (I' : A) (hf : I' * I' = -1) : \u2102 \u2192\u2090[\u211d] A :=\n  AlgHom.ofLinearMap\n    ((Algebra.ofId \u211d A).toLinearMap.comp reLm + (LinearMap.toSpanSingleton _ _ I').comp imLm)\n    (show algebraMap \u211d A 1 + (0 : \u211d) \u2022 I' = 1 by rw [RingHom.map_one, zero_smul, add_zero])\n    fun \u27e8x\u2081, y\u2081\u27e9 \u27e8x\u2082, y\u2082\u27e9 =>\n    show\n      algebraMap \u211d A (x\u2081 * x\u2082 - y\u2081 * y\u2082) + (x\u2081 * y\u2082 + y\u2081 * x\u2082) \u2022 I' =\n        (algebraMap \u211d A x\u2081 + y\u2081 \u2022 I') * (algebraMap \u211d A x\u2082 + y\u2082 \u2022 I')\n      by\n      rw [add_mul, mul_add, mul_add, add_comm _ (y\u2081 \u2022 I' * y\u2082 \u2022 I'), add_add_add_comm]\n      congr 1\n      -- equate \"real\" and \"imaginary\" parts\n      \u00b7\n        rw [smul_mul_smul, hf, smul_neg, \u2190 Algebra.algebraMap_eq_smul_one, \u2190 sub_eq_add_neg, \u2190\n          RingHom.map_mul, \u2190 RingHom.map_sub]\n      \u00b7\n        rw [Algebra.smul_def, Algebra.smul_def, Algebra.smul_def, \u2190 Algebra.right_comm _ x\u2082, \u2190\n          mul_assoc, \u2190 add_mul, \u2190 RingHom.map_mul, \u2190 RingHom.map_mul, \u2190 RingHom.map_add]\n#align complex.lift_aux Complex.liftAux\n\n@[simp]\ntheorem liftAux_apply (I' : A) (hI') (z : \u2102) : liftAux I' hI' z = algebraMap \u211d A z.re + z.im \u2022 I' :=\n  rfl\n#align complex.lift_aux_apply Complex.liftAux_apply\n\ntheorem liftAux_apply_i (I' : A) (hI') : liftAux I' hI' I = I' := by simp\n#align complex.lift_aux_apply_I Complex.liftAux_apply_i\n\n/-- A universal property of the complex numbers, providing a unique `\u2102 \u2192\u2090[\u211d] A` for every element\nof `A` which squares to `-1`.\n\nThis can be used to embed the complex numbers in the `quaternion`s.\n\nThis isomorphism is named to match the very similar `zsqrtd.lift`. -/\n@[simps (config := { simpRhs := true })]\ndef lift : { I' : A // I' * I' = -1 } \u2243 (\u2102 \u2192\u2090[\u211d] A)\n    where\n  toFun I' := liftAux I' I'.Prop\n  invFun F := \u27e8F I, by rw [\u2190 F.map_mul, I_mul_I, AlgHom.map_neg, AlgHom.map_one]\u27e9\n  left_inv I' := Subtype.ext <| liftAux_apply_i I' I'.Prop\n  right_inv F := algHom_ext <| liftAux_apply_i _ _\n#align complex.lift Complex.lift\n\n-- When applied to `complex.I` itself, `lift` is the identity.\n@[simp]\ntheorem liftAux_i : liftAux I I_mul_I = AlgHom.id \u211d \u2102 :=\n  algHom_ext <| liftAux_apply_i _ _\n#align complex.lift_aux_I Complex.liftAux_i\n\n-- When applied to `-complex.I`, `lift` is conjugation, `conj`.\n@[simp]\ntheorem liftAux_neg_i : liftAux (-I) ((neg_mul_neg _ _).trans I_mul_I) = conjAe :=\n  algHom_ext <| (liftAux_apply_i _ _).trans conj_I.symm\n#align complex.lift_aux_neg_I Complex.liftAux_neg_i\n\nend lift\n\nend Complex\n\nsection RealImaginaryPart\n\nopen Complex\n\nvariable {A : Type _} [AddCommGroup A] [Module \u2102 A] [StarAddMonoid A] [StarModule \u2102 A]\n\n/-- Create a `self_adjoint` element from a `skew_adjoint` element by multiplying by the scalar\n`-complex.I`. -/\n@[simps]\ndef skewAdjoint.negISmul : skewAdjoint A \u2192\u2097[\u211d] selfAdjoint A\n    where\n  toFun a :=\n    \u27e8-I \u2022 a, by\n      simp only [selfAdjoint.mem_iff, neg_smul, star_neg, star_smul, star_def, conj_I,\n        skewAdjoint.star_val_eq, neg_smul_neg]\u27e9\n  map_add' a b := by\n    ext\n    simp only [AddSubgroup.coe_add, smul_add, AddMemClass.mk_add_mk]\n  map_smul' a b := by\n    ext\n    simp only [neg_smul, skewAdjoint.val_smul, AddSubgroup.coe_mk, RingHom.id_apply,\n      selfAdjoint.val_smul, smul_neg, neg_inj]\n    rw [smul_comm]\n#align skew_adjoint.neg_I_smul skewAdjoint.negISmul\n\ntheorem skewAdjoint.i_smul_neg_i (a : skewAdjoint A) : I \u2022 (skewAdjoint.negISmul a : A) = a := by\n  simp only [smul_smul, skewAdjoint.negISmul_apply_coe, neg_smul, smul_neg, I_mul_I, one_smul,\n    neg_neg]\n#align skew_adjoint.I_smul_neg_I skewAdjoint.i_smul_neg_i\n\n/-- The real part `\u211c a` of an element `a` of a star module over `\u2102`, as a linear map. This is just\n`self_adjoint_part \u211d`, but we provide it as a separate definition in order to link it with lemmas\nconcerning the `imaginary_part`, which doesn't exist in star modules over other rings. -/\nnoncomputable def realPart : A \u2192\u2097[\u211d] selfAdjoint A :=\n  selfAdjointPart \u211d\n#align real_part realPart\n\n/-- The imaginary part `\u2111 a` of an element `a` of a star module over `\u2102`, as a linear map into the\nself adjoint elements. In a general star module, we have a decomposition into the `self_adjoint`\nand `skew_adjoint` parts, but in a star module over `\u2102` we have\n`real_part_add_I_smul_imaginary_part`, which allows us to decompose into a linear combination of\n`self_adjoint`s. -/\nnoncomputable def imaginaryPart : A \u2192\u2097[\u211d] selfAdjoint A :=\n  skewAdjoint.negISmul.comp (skewAdjointPart \u211d)\n#align imaginary_part imaginaryPart\n\n-- mathport name: expr\u211c\nscoped[ComplexStarModule] notation \"\u211c\" => realPart\n\n-- mathport name: expr\u2111\nscoped[ComplexStarModule] notation \"\u2111\" => imaginaryPart\n\n@[simp]\ntheorem realPart_apply_coe (a : A) : (\u211c a : A) = (2 : \u211d)\u207b\u00b9 \u2022 (a + star a) :=\n  by\n  unfold realPart\n  simp only [selfAdjointPart_apply_coe, invOf_eq_inv]\n#align real_part_apply_coe realPart_apply_coe\n\n@[simp]\ntheorem imaginaryPart_apply_coe (a : A) : (\u2111 a : A) = -I \u2022 (2 : \u211d)\u207b\u00b9 \u2022 (a - star a) :=\n  by\n  unfold imaginaryPart\n  simp only [LinearMap.coe_comp, skewAdjoint.negISmul_apply_coe, skewAdjointPart_apply_coe,\n    invOf_eq_inv]\n#align imaginary_part_apply_coe imaginaryPart_apply_coe\n\n/-- The standard decomposition of `\u211c a + complex.I \u2022 \u2111 a = a` of an element of a star module over\n`\u2102` into a linear combination of self adjoint elements. -/\ntheorem realPart_add_i_smul_imaginaryPart (a : A) : (\u211c a + I \u2022 \u2111 a : A) = a := by\n  simpa only [smul_smul, realPart_apply_coe, imaginaryPart_apply_coe, neg_smul, I_mul_I, one_smul,\n    neg_sub, add_add_sub_cancel, smul_sub, smul_add, neg_sub_neg, invOf_eq_inv] using\n    inv_of_two_smul_add_inv_of_two_smul \u211d a\n#align real_part_add_I_smul_imaginary_part realPart_add_i_smul_imaginaryPart\n\n@[simp]\ntheorem realPart_i_smul (a : A) : \u211c (I \u2022 a) = -\u2111 a :=\n  by\n  ext\n  simp [smul_comm I, smul_sub, sub_eq_add_neg, add_comm]\n#align real_part_I_smul realPart_i_smul\n\n@[simp]\ntheorem imaginaryPart_i_smul (a : A) : \u2111 (I \u2022 a) = \u211c a :=\n  by\n  ext\n  simp [smul_comm I, smul_smul I]\n#align imaginary_part_I_smul imaginaryPart_i_smul\n\ntheorem realPart_smul (z : \u2102) (a : A) : \u211c (z \u2022 a) = z.re \u2022 \u211c a - z.im \u2022 \u2111 a :=\n  by\n  nth_rw 1 [\u2190 re_add_im z]\n  simp [-re_add_im, add_smul, \u2190 smul_smul, sub_eq_add_neg]\n#align real_part_smul realPart_smul\n\ntheorem imaginaryPart_smul (z : \u2102) (a : A) : \u2111 (z \u2022 a) = z.re \u2022 \u2111 a + z.im \u2022 \u211c a :=\n  by\n  nth_rw 1 [\u2190 re_add_im z]\n  simp [-re_add_im, add_smul, \u2190 smul_smul]\n#align imaginary_part_smul imaginaryPart_smul\n\nend RealImaginaryPart\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Complex/Module.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7198456180787424}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport algebra.big_operators.order\nimport data.nat.interval\nimport data.nat.factors\n\n/-!\n# Divisor finsets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines sets of divisors of a natural number. This is particularly useful as background\nfor defining Dirichlet convolution.\n\n## Main Definitions\nLet `n : \u2115`. All of the following definitions are in the `nat` namespace:\n * `divisors n` is the `finset` of natural numbers that divide `n`.\n * `proper_divisors n` is the `finset` of natural numbers that divide `n`, other than `n`.\n * `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n * `perfect n` is true when `n` is positive and the sum of `proper_divisors n` is `n`.\n\n## Implementation details\n * `divisors 0`, `proper_divisors 0`, and `divisors_antidiagonal 0` are defined to be `\u2205`.\n\n## Tags\ndivisors, perfect numbers\n\n-/\n\nopen_locale classical\nopen_locale big_operators\nopen finset\n\nnamespace nat\nvariable (n : \u2115)\n\n/-- `divisors n` is the `finset` of divisors of `n`. As a special case, `divisors 0 = \u2205`. -/\ndef divisors : finset \u2115 := finset.filter (\u03bb x : \u2115, x \u2223 n) (finset.Ico 1 (n + 1))\n\n/-- `proper_divisors n` is the `finset` of divisors of `n`, other than `n`.\n  As a special case, `proper_divisors 0 = \u2205`. -/\ndef proper_divisors : finset \u2115 := finset.filter (\u03bb x : \u2115, x \u2223 n) (finset.Ico 1 n)\n\n/-- `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n  As a special case, `divisors_antidiagonal 0 = \u2205`. -/\ndef divisors_antidiagonal : finset (\u2115 \u00d7 \u2115) :=\n(Ico 1 (n + 1) \u00d7\u02e2 Ico 1 (n + 1)).filter (\u03bb x, x.fst * x.snd = n)\n\nvariable {n}\n\n@[simp]\nlemma filter_dvd_eq_divisors (h : n \u2260 0) :\n  (finset.range n.succ).filter (\u2223 n) = n.divisors :=\nbegin\n  ext,\n  simp only [divisors, mem_filter, mem_range, mem_Ico, and.congr_left_iff, iff_and_self],\n  exact \u03bb ha _, succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt),\nend\n\n@[simp]\nlemma filter_dvd_eq_proper_divisors (h : n \u2260 0) :\n  (finset.range n).filter (\u2223 n) = n.proper_divisors :=\nbegin\n  ext,\n  simp only [proper_divisors, mem_filter, mem_range, mem_Ico, and.congr_left_iff, iff_and_self],\n  exact \u03bb ha _, succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt),\nend\n\nlemma proper_divisors.not_self_mem : \u00ac n \u2208 proper_divisors n :=\nby simp [proper_divisors]\n\n@[simp]\nlemma mem_proper_divisors {m : \u2115} : n \u2208 proper_divisors m \u2194 n \u2223 m \u2227 n < m :=\nbegin\n  rcases eq_or_ne m 0 with rfl | hm, { simp [proper_divisors] },\n  simp only [and_comm, \u2190filter_dvd_eq_proper_divisors hm, mem_filter, mem_range],\nend\n\nlemma insert_self_proper_divisors (h : n \u2260 0): insert n (proper_divisors n) = divisors n :=\nby rw [divisors, proper_divisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h),\n  finset.filter_insert, if_pos (dvd_refl n)]\n\nlemma cons_self_proper_divisors (h : n \u2260 0) :\n  cons n (proper_divisors n) proper_divisors.not_self_mem = divisors n :=\nby rw [cons_eq_insert, insert_self_proper_divisors h]\n\n@[simp]\nlemma mem_divisors {m : \u2115} : n \u2208 divisors m \u2194 (n \u2223 m \u2227 m \u2260 0) :=\nbegin\n  rcases eq_or_ne m 0 with rfl | hm, { simp [divisors] },\n  simp only [hm, ne.def, not_false_iff, and_true, \u2190filter_dvd_eq_divisors hm, mem_filter,\n    mem_range, and_iff_right_iff_imp, lt_succ_iff],\n  exact le_of_dvd hm.bot_lt,\nend\n\nlemma one_mem_divisors : 1 \u2208 divisors n \u2194 n \u2260 0 := by simp\n\nlemma mem_divisors_self (n : \u2115) (h : n \u2260 0) : n \u2208 n.divisors := mem_divisors.2 \u27e8dvd_rfl, h\u27e9\n\nlemma dvd_of_mem_divisors {m : \u2115} (h : n \u2208 divisors m) : n \u2223 m :=\nbegin\n  cases m,\n  { apply dvd_zero },\n  { simp [mem_divisors.1 h], }\nend\n\n@[simp]\nlemma mem_divisors_antidiagonal {x : \u2115 \u00d7 \u2115} :\n  x \u2208 divisors_antidiagonal n \u2194 x.fst * x.snd = n \u2227 n \u2260 0 :=\nbegin\n  simp only [divisors_antidiagonal, finset.mem_Ico, ne.def, finset.mem_filter, finset.mem_product],\n  rw and_comm,\n  apply and_congr_right,\n  rintro rfl,\n  split; intro h,\n  { contrapose! h, simp [h], },\n  { rw [nat.lt_add_one_iff, nat.lt_add_one_iff],\n    rw [mul_eq_zero, decidable.not_or_iff_and_not] at h,\n    simp only [succ_le_of_lt (nat.pos_of_ne_zero h.1), succ_le_of_lt (nat.pos_of_ne_zero h.2),\n               true_and],\n    exact \u27e8le_mul_of_pos_right (nat.pos_of_ne_zero h.2),\n      le_mul_of_pos_left (nat.pos_of_ne_zero h.1)\u27e9 }\nend\n\nvariable {n}\n\nlemma divisor_le {m : \u2115}:\nn \u2208 divisors m \u2192 n \u2264 m :=\nbegin\n  cases m,\n  { simp },\n  simp only [mem_divisors, m.succ_ne_zero, and_true, ne.def, not_false_iff],\n  exact nat.le_of_dvd (nat.succ_pos m),\nend\n\nlemma divisors_subset_of_dvd {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) : divisors m \u2286 divisors n :=\nfinset.subset_iff.2 $ \u03bb x hx, nat.mem_divisors.mpr (\u27e8(nat.mem_divisors.mp hx).1.trans h, hzero\u27e9)\n\nlemma divisors_subset_proper_divisors {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) (hdiff : m \u2260 n) :\n  divisors m \u2286 proper_divisors n :=\nbegin\n  apply finset.subset_iff.2,\n  intros x hx,\n  exact nat.mem_proper_divisors.2 (\u27e8(nat.mem_divisors.1 hx).1.trans h,\n    lt_of_le_of_lt (divisor_le hx) (lt_of_le_of_ne (divisor_le (nat.mem_divisors.2\n    \u27e8h, hzero\u27e9)) hdiff)\u27e9)\nend\n\n@[simp]\nlemma divisors_zero : divisors 0 = \u2205 := by { ext, simp }\n\n@[simp]\nlemma proper_divisors_zero : proper_divisors 0 = \u2205 := by { ext, simp }\n\nlemma proper_divisors_subset_divisors : proper_divisors n \u2286 divisors n :=\nfilter_subset_filter _ $ Ico_subset_Ico_right n.le_succ\n\n@[simp]\nlemma divisors_one : divisors 1 = {1} := by { ext, simp }\n\n@[simp]\nlemma proper_divisors_one : proper_divisors 1 = \u2205 :=\nby rw [proper_divisors, Ico_self, filter_empty]\n\nlemma pos_of_mem_divisors {m : \u2115} (h : m \u2208 n.divisors) : 0 < m :=\nbegin\n  cases m,\n  { rw [mem_divisors, zero_dvd_iff] at h, cases h.2 h.1 },\n  apply nat.succ_pos,\nend\n\nlemma pos_of_mem_proper_divisors {m : \u2115} (h : m \u2208 n.proper_divisors) : 0 < m :=\npos_of_mem_divisors (proper_divisors_subset_divisors h)\n\nlemma one_mem_proper_divisors_iff_one_lt :\n  1 \u2208 n.proper_divisors \u2194 1 < n :=\nby rw [mem_proper_divisors, and_iff_right (one_dvd _)]\n\n@[simp]\nlemma divisors_antidiagonal_zero : divisors_antidiagonal 0 = \u2205 := by { ext, simp }\n\n@[simp]\nlemma divisors_antidiagonal_one : divisors_antidiagonal 1 = {(1,1)} :=\nby { ext, simp [nat.mul_eq_one_iff, prod.ext_iff], }\n\n@[simp] lemma swap_mem_divisors_antidiagonal {x : \u2115 \u00d7 \u2115} :\n  x.swap \u2208 divisors_antidiagonal n \u2194 x \u2208 divisors_antidiagonal n :=\nby rw [mem_divisors_antidiagonal, mem_divisors_antidiagonal, mul_comm, prod.swap]\n\n\n\nlemma snd_mem_divisors_of_mem_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisors_antidiagonal n) :\n  x.snd \u2208 divisors n :=\nbegin\n  rw mem_divisors_antidiagonal at h,\n  simp [dvd.intro_left _ h.1, h.2],\nend\n\n@[simp]\nlemma map_swap_divisors_antidiagonal :\n  (divisors_antidiagonal n).map (equiv.prod_comm _ _).to_embedding = divisors_antidiagonal n :=\nbegin\n  rw [\u2190 coe_inj, coe_map, equiv.coe_to_embedding, equiv.coe_prod_comm,\n    set.image_swap_eq_preimage_swap],\n  ext,\n  exact swap_mem_divisors_antidiagonal,\nend\n\n@[simp] lemma image_fst_divisors_antidiagonal :\n  (divisors_antidiagonal n).image prod.fst = divisors n :=\nby { ext, simp [has_dvd.dvd, @eq_comm _ n (_ * _)] }\n\n@[simp] lemma image_snd_divisors_antidiagonal :\n  (divisors_antidiagonal n).image prod.snd = divisors n :=\nbegin\n  rw [\u2190map_swap_divisors_antidiagonal, map_eq_image, image_image],\n  exact image_fst_divisors_antidiagonal\nend\n\nlemma map_div_right_divisors :\n  n.divisors.map \u27e8\u03bb d, (d, n/d), \u03bb p\u2081 p\u2082, congr_arg prod.fst\u27e9 = n.divisors_antidiagonal :=\nbegin\n  ext \u27e8d, nd\u27e9,\n  simp only [mem_map, mem_divisors_antidiagonal, function.embedding.coe_fn_mk, mem_divisors,\n    prod.ext_iff, exists_prop, and.left_comm, exists_eq_left],\n  split,\n  { rintro \u27e8\u27e8\u27e8k, rfl\u27e9, hn\u27e9, rfl\u27e9,\n    rw [nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt],\n    exact \u27e8rfl, hn\u27e9 },\n  { rintro \u27e8rfl, hn\u27e9,\n    exact \u27e8\u27e8dvd_mul_right _ _, hn\u27e9, nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt\u27e9 }\nend\n\nlemma map_div_left_divisors :\n  n.divisors.map \u27e8\u03bb d, (n/d, d), \u03bb p\u2081 p\u2082, congr_arg prod.snd\u27e9 = n.divisors_antidiagonal :=\nbegin\n  apply finset.map_injective (equiv.prod_comm _ _).to_embedding,\n  rw [map_swap_divisors_antidiagonal, \u2190map_div_right_divisors, finset.map_map],\n  refl,\nend\n\nlemma sum_divisors_eq_sum_proper_divisors_add_self :\n  \u2211 i in divisors n, i = \u2211 i in proper_divisors n, i + n :=\nbegin\n  rcases decidable.eq_or_ne n 0 with rfl|hn,\n  { simp },\n  { rw [\u2190 cons_self_proper_divisors hn, finset.sum_cons, add_comm] }\nend\n\n/-- `n : \u2115` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`\n  is positive. -/\ndef perfect (n : \u2115) : Prop := (\u2211 i in proper_divisors n, i = n) \u2227 0 < n\n\ntheorem perfect_iff_sum_proper_divisors (h : 0 < n) :\n  perfect n \u2194 \u2211 i in proper_divisors n, i = n := and_iff_left h\n\ntheorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) :\n  perfect n \u2194 \u2211 i in divisors n, i = 2 * n :=\nbegin\n  rw [perfect_iff_sum_proper_divisors h, sum_divisors_eq_sum_proper_divisors_add_self, two_mul],\n  split; intro h,\n  { rw h },\n  { apply add_right_cancel h }\nend\n\nlemma mem_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) {x : \u2115} :\n  x \u2208 divisors (p ^ k) \u2194 \u2203 (j : \u2115) (H : j \u2264 k), x = p ^ j :=\nby rw [mem_divisors, nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))]\n\nlemma prime.divisors {p : \u2115} (pp : p.prime) :\n  divisors p = {1, p} :=\nbegin\n  ext,\n  rw [mem_divisors, dvd_prime pp, and_iff_left pp.ne_zero, finset.mem_insert, finset.mem_singleton]\nend\n\nlemma prime.proper_divisors {p : \u2115} (pp : p.prime) :\n  proper_divisors p = {1} :=\nby rw [\u2190 erase_insert proper_divisors.not_self_mem, insert_self_proper_divisors pp.ne_zero,\n    pp.divisors, pair_comm, erase_insert (\u03bb con, pp.ne_one (mem_singleton.1 con))]\n\nlemma divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) :\n  divisors (p ^ k) = (finset.range (k + 1)).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\nby { ext, simp [mem_divisors_prime_pow, pp, nat.lt_succ_iff, @eq_comm _ a] }\n\nlemma eq_proper_divisors_of_subset_of_sum_eq_sum {s : finset \u2115} (hsub : s \u2286 n.proper_divisors) :\n  \u2211 x in s, x = \u2211 x in n.proper_divisors, x \u2192 s = n.proper_divisors :=\nbegin\n  cases n,\n  { rw [proper_divisors_zero, subset_empty] at hsub,\n    simp [hsub] },\n  classical,\n  rw [\u2190 sum_sdiff hsub],\n  intros h,\n  apply subset.antisymm hsub,\n  rw [\u2190 sdiff_eq_empty_iff_subset],\n  contrapose h,\n  rw [\u2190 ne.def, \u2190 nonempty_iff_ne_empty] at h,\n  apply ne_of_lt,\n  rw [\u2190 zero_add (\u2211 x in s, x), \u2190 add_assoc, add_zero],\n  apply add_lt_add_right,\n  have hlt := sum_lt_sum_of_nonempty h (\u03bb x hx, pos_of_mem_proper_divisors (sdiff_subset _ _ hx)),\n  simp only [sum_const_zero] at hlt,\n  apply hlt\nend\n\nlemma sum_proper_divisors_dvd (h : \u2211 x in n.proper_divisors, x \u2223 n) :\n  (\u2211 x in n.proper_divisors, x = 1) \u2228 (\u2211 x in n.proper_divisors, x = n) :=\nbegin\n  cases n,\n  { simp },\n  cases n,\n  { contrapose! h,\n    simp, },\n  rw or_iff_not_imp_right,\n  intro ne_n,\n  have hlt : \u2211 x in n.succ.succ.proper_divisors, x < n.succ.succ :=\n    lt_of_le_of_ne (nat.le_of_dvd (nat.succ_pos _) h) ne_n,\n  symmetry,\n  rw [\u2190 mem_singleton, eq_proper_divisors_of_subset_of_sum_eq_sum (singleton_subset_iff.2\n        (mem_proper_divisors.2 \u27e8h, hlt\u27e9)) sum_singleton, mem_proper_divisors],\n  refine \u27e8one_dvd _, nat.succ_lt_succ (nat.succ_pos _)\u27e9,\nend\n\n@[simp, to_additive]\nlemma prime.prod_proper_divisors {\u03b1 : Type*} [comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in p.proper_divisors, f x = f 1 :=\nby simp [h.proper_divisors]\n\n@[simp, to_additive]\nlemma prime.prod_divisors {\u03b1 : Type*} [comm_monoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in p.divisors, f x = f p * f 1 :=\nby rw [\u2190 cons_self_proper_divisors h.ne_zero, prod_cons, h.prod_proper_divisors]\n\nlemma proper_divisors_eq_singleton_one_iff_prime :\n  n.proper_divisors = {1} \u2194 n.prime :=\n\u27e8\u03bb h, begin\n  have h1 := mem_singleton.2 rfl,\n  rw [\u2190 h, mem_proper_divisors] at h1,\n  refine nat.prime_def_lt''.mpr \u27e8h1.2, \u03bb m hdvd, _\u27e9,\n  rw [\u2190 mem_singleton, \u2190 h, mem_proper_divisors],\n  have hle := nat.le_of_dvd (lt_trans (nat.succ_pos _) h1.2) hdvd,\n  exact or.imp_left (\u03bb hlt, \u27e8hdvd, hlt\u27e9) hle.lt_or_eq\nend, prime.proper_divisors\u27e9\n\nlemma sum_proper_divisors_eq_one_iff_prime :\n  \u2211 x in n.proper_divisors, x = 1 \u2194 n.prime :=\nbegin\n  cases n,\n  { simp [nat.not_prime_zero] },\n  cases n,\n  { simp [nat.not_prime_one] },\n  rw [\u2190 proper_divisors_eq_singleton_one_iff_prime],\n  refine \u27e8\u03bb h, _, \u03bb h, h.symm \u25b8 sum_singleton\u27e9,\n  rw [@eq_comm (finset \u2115) _ _],\n  apply eq_proper_divisors_of_subset_of_sum_eq_sum\n    (singleton_subset_iff.2 (one_mem_proper_divisors_iff_one_lt.2 (succ_lt_succ (nat.succ_pos _))))\n    (eq.trans sum_singleton h.symm)\nend\n\nlemma mem_proper_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) {x : \u2115} :\n  x \u2208 proper_divisors (p ^ k) \u2194 \u2203 (j : \u2115) (H : j < k), x = p ^ j :=\nbegin\n  rw [mem_proper_divisors, nat.dvd_prime_pow pp, \u2190 exists_and_distrib_right],\n  simp only [exists_prop, and_assoc],\n  apply exists_congr,\n  intro a,\n  split; intro h,\n  { rcases h with \u27e8h_left, rfl, h_right\u27e9,\n    rwa pow_lt_pow_iff pp.one_lt at h_right,\n    simpa, },\n  { rcases h with \u27e8h_left, rfl\u27e9,\n    rwa pow_lt_pow_iff pp.one_lt,\n    simp [h_left, le_of_lt], },\nend\n\nlemma proper_divisors_prime_pow {p : \u2115} (pp : p.prime) (k : \u2115) :\n  proper_divisors (p ^ k) = (finset.range k).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\nby { ext, simp [mem_proper_divisors_prime_pow, pp, nat.lt_succ_iff, @eq_comm _ a], }\n\n@[simp, to_additive]\nlemma prod_proper_divisors_prime_pow {\u03b1 : Type*} [comm_monoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1}\n  (h : p.prime) : \u220f x in (p ^ k).proper_divisors, f x = \u220f x in range k, f (p ^ x) :=\nby simp [h, proper_divisors_prime_pow]\n\n@[simp, to_additive sum_divisors_prime_pow]\nlemma prod_divisors_prime_pow {\u03b1 : Type*} [comm_monoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.prime) :\n  \u220f x in (p ^ k).divisors, f x = \u220f x in range (k + 1), f (p ^ x) :=\nby simp [h, divisors_prime_pow]\n\n@[to_additive]\nlemma prod_divisors_antidiagonal {M : Type*} [comm_monoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n  \u220f i in n.divisors_antidiagonal, f i.1 i.2 = \u220f i in n.divisors, f i (n / i) :=\nbegin\n  rw [\u2190map_div_right_divisors, finset.prod_map],\n  refl,\nend\n\n@[to_additive]\nlemma prod_divisors_antidiagonal' {M : Type*} [comm_monoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n  \u220f i in n.divisors_antidiagonal, f i.1 i.2 = \u220f i in n.divisors, f (n / i) i :=\nbegin\n  rw [\u2190map_swap_divisors_antidiagonal, finset.prod_map],\n  exact prod_divisors_antidiagonal (\u03bb i j, f j i),\nend\n\n/-- The factors of `n` are the prime divisors -/\nlemma prime_divisors_eq_to_filter_divisors_prime (n : \u2115) :\n  n.factors.to_finset = (divisors n).filter prime :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { simp },\n  { ext q,\n    simpa [hn, hn.ne', mem_factors] using and_comm (prime q) (q \u2223 n) }\nend\n\n@[simp]\nlemma image_div_divisors_eq_divisors (n : \u2115) : image (\u03bb (x : \u2115), n / x) n.divisors = n.divisors :=\nbegin\n  by_cases hn : n = 0, { simp [hn] },\n  ext,\n  split,\n  { rw mem_image,\n    rintros \u27e8x, hx1, hx2\u27e9,\n    rw mem_divisors at *,\n    refine \u27e8_,hn\u27e9,\n    rw \u2190hx2,\n    exact div_dvd_of_dvd hx1.1 },\n  { rw [mem_divisors, mem_image],\n    rintros \u27e8h1, -\u27e9,\n    exact \u27e8n/a, mem_divisors.mpr \u27e8div_dvd_of_dvd h1, hn\u27e9, nat.div_div_self h1 hn\u27e9 },\nend\n\n@[simp, to_additive sum_div_divisors]\nlemma prod_div_divisors {\u03b1 : Type*} [comm_monoid \u03b1] (n : \u2115) (f : \u2115 \u2192 \u03b1) :\n  \u220f d in n.divisors, f (n/d) = n.divisors.prod f :=\nbegin\n  by_cases hn : n = 0, { simp [hn] },\n  rw \u2190prod_image,\n  { exact prod_congr (image_div_divisors_eq_divisors n) (by simp) },\n  { intros x hx y hy h,\n    rw mem_divisors at hx hy,\n    exact (div_eq_iff_eq_of_dvd_dvd hn hx.1 hy.1).mp h }\nend\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.719845617964279}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport number_theory.class_number.admissible_card_pow_degree\nimport number_theory.class_number.finite\nimport number_theory.function_field\n\n/-!\n# Class numbers of function fields\n\nThis file defines the class number of a function field as the (finite) cardinality of\nthe class group of its ring of integers. It also proves some elementary results\non the class number.\n\n## Main definitions\n- `function_field.class_number`: the class number of a function field is the (finite)\ncardinality of the class group of its ring of integers\n-/\n\nnamespace function_field\n\nvariables (Fq F : Type) [field Fq] [fintype Fq] [field F]\nvariables [algebra (polynomial Fq) F] [algebra (ratfunc Fq) F]\nvariables [is_scalar_tower (polynomial Fq) (ratfunc Fq) F]\nvariables [function_field Fq F] [is_separable (ratfunc Fq) F]\n\nopen_locale classical\n\nnamespace ring_of_integers\n\nopen function_field\n\nnoncomputable instance  : fintype (class_group (ring_of_integers Fq F) F) :=\nclass_group.fintype_of_admissible_of_finite (ratfunc Fq) F\n  (polynomial.card_pow_degree_is_admissible : absolute_value.is_admissible\n    (polynomial.card_pow_degree : absolute_value (polynomial Fq) \u2124))\n\nend ring_of_integers\n\n/-- The class number in a function field is the (finite) cardinality of the class group. -/\nnoncomputable def class_number : \u2115 := fintype.card (class_group (ring_of_integers Fq F) F)\n\n/-- The class number of a function field is `1` iff the ring of integers is a PID. -/\ntheorem class_number_eq_one_iff :\n  class_number Fq F = 1 \u2194 is_principal_ideal_ring (ring_of_integers Fq F) :=\ncard_class_group_eq_one_iff\n\nend function_field\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/class_number/function_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7198456070645723}}
{"text": "-- ----------------------------------------------------\n-- Ejercicio. Demostrar\n--    \u22a2 \u00ac(p \u2227 \u00acp)\n-- ----------------------------------------------------\n\nimport tactic\nvariables (p q : Prop)\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nbegin\n  intro H,\n  apply H.right,\n  exact H.left,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nbegin\n  intro H,\n  exact H.right (H.left),\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n\u03bb H, H.right (H.left)\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nbegin\n  rintro \u27e8H1, H2\u27e9,\n  exact H2 H1,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n\u03bb \u27e8H1, H2\u27e9, H2 H1\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n-- by suggest\n(and_not_self p).mp\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nassume H : p \u2227 \u00acp,\nhave H1 : p,\n  from and.left H,\nhave H2 : \u00acp,\n  from and.right H,\nshow false,\n  from H2 H1\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n-- by hint\nby tauto\n\n-- 9\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nby finish\n\n-- 10\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/1_Proposicional/Ejercicios/\u00ac(p\u2227\u00acp).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489618, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7198456005018553}}
{"text": "/-\nCopyright (c) 2018 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\nCase bashing:\n* on `x \u2208 A`, for `A : finset \u03b1` or `A : list \u03b1`, or\n* on `x : A`, with `[fintype A]`.\n-/\nimport data.fintype.basic\nimport tactic.norm_num\n\nnamespace tactic\nopen lean.parser\nopen interactive interactive.types expr\nopen conv.interactive\n\n/-- Checks that the expression looks like `x \u2208 A` for `A : finset \u03b1`, `multiset \u03b1` or `A : list \u03b1`,\n    and returns the type \u03b1. -/\nmeta def guard_mem_fin (e : expr) : tactic expr :=\ndo t \u2190 infer_type e,\n   \u03b1 \u2190 mk_mvar,\n   to_expr ``(_ \u2208 (_ : finset %%\u03b1))   tt ff >>= unify t <|>\n   to_expr ``(_ \u2208 (_ : multiset %%\u03b1)) tt ff >>= unify t <|>\n   to_expr ``(_ \u2208 (_ : list %%\u03b1))     tt ff >>= unify t,\n   instantiate_mvars \u03b1\n\n/--\n`expr_list_to_list_expr` converts an `expr` of type `list \u03b1`\nto a list of `expr`s each with type `\u03b1`.\n\nTODO: this should be moved, and possibly duplicates an existing definition.\n-/\nmeta def expr_list_to_list_expr : \u03a0 (e : expr), tactic (list expr)\n| `(list.cons %%h %%t) := list.cons h <$> expr_list_to_list_expr t\n| `([]) := return []\n| _ := failed\n\nprivate meta def fin_cases_at_aux : \u03a0 (with_list : list expr) (e : expr), tactic unit\n| with_list e :=\n(do\n  result \u2190 cases_core e,\n  match result with\n  -- We have a goal with an equation `s`, and a second goal with a smaller `e : x \u2208 _`.\n  | [(_, [s], _), (_, [e], _)] :=\n    do let sn := local_pp_name s,\n        ng \u2190 num_goals,\n        -- tidy up the new value\n        match with_list.nth 0 with\n        -- If an explicit value was specified via the `with` keyword, use that.\n        | (some h) := tactic.interactive.conv (some sn) none\n                        (to_rhs >> conv.interactive.change (to_pexpr h))\n        -- Otherwise, call `norm_num`. We let `norm_num` unfold `max` and `min`\n        -- because it's helpful for the `interval_cases` tactic.\n        | _ := try $ tactic.interactive.conv (some sn) none $\n               to_rhs >> conv.interactive.norm_num\n                 [simp_arg_type.expr ``(max), simp_arg_type.expr ``(min)]\n        end,\n        s \u2190 get_local sn,\n        try `[subst %%s],\n        ng' \u2190 num_goals,\n        when (ng = ng') (rotate_left 1),\n        fin_cases_at_aux with_list.tail e\n  -- No cases; we're done.\n  | [] := skip\n  | _ := failed\n  end)\n\n/--\n`fin_cases_at with_list e` performs case analysis on `e : \u03b1`, where `\u03b1` is a fintype.\nThe optional list of expressions `with_list` provides descriptions for the cases of `e`,\nfor example, to display nats as `n.succ` instead of `n+1`.\nThese should be defeq to and in the same order as the terms in the enumeration of `\u03b1`.\n-/\nmeta def fin_cases_at : \u03a0 (with_list : option pexpr) (e : expr), tactic unit\n| with_list e :=\ndo ty \u2190 try_core $ guard_mem_fin e,\n    match ty with\n    | none := -- Deal with `x : A`, where `[fintype A]` is available:\n      (do\n        ty \u2190 infer_type e,\n        i \u2190 to_expr ``(fintype %%ty) >>= mk_instance <|> fail \"Failed to find `fintype` instance.\",\n        t \u2190 to_expr ``(%%e \u2208 @fintype.elems %%ty %%i),\n        v \u2190 to_expr ``(@fintype.complete %%ty %%i %%e),\n        h \u2190 assertv `h t v,\n        fin_cases_at with_list h)\n    | (some ty) := -- Deal with `x \u2208 A` hypotheses:\n      (do\n        with_list \u2190 match with_list with\n        | (some e) := do e \u2190 to_expr ``(%%e : list %%ty), expr_list_to_list_expr e\n        | none := return []\n        end,\n        fin_cases_at_aux with_list e)\n    end\n\nnamespace interactive\nprivate meta def hyp := tk \"*\" *> return none <|> some <$> ident\nlocal postfix `?`:9001 := optional\n\n/--\n`fin_cases h` performs case analysis on a hypothesis of the form\n`h : A`, where `[fintype A]` is available, or\n`h \u2208 A`, where `A : finset X`, `A : multiset X` or `A : list X`.\n\n`fin_cases *` performs case analysis on all suitable hypotheses.\n\nAs an example, in\n```\nexample (f : \u2115 \u2192 Prop) (p : fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val :=\nbegin\n  fin_cases *; simp,\n  all_goals { assumption }\nend\n```\nafter `fin_cases p; simp`, there are three goals, `f 0`, `f 1`, and `f 2`.\n-/\nmeta def fin_cases : parse hyp \u2192 parse (tk \"with\" *> texpr)? \u2192 tactic unit\n| none none := focus1 $ do\n    ctx \u2190 local_context,\n    ctx.mfirst (fin_cases_at none) <|>\n      fail \"No hypothesis of the forms `x \u2208 A`, where `A : finset X`, `A : list X`, or `A : multiset X`, or `x : A`, with `[fintype A]`.\"\n| none (some _) := fail \"Specify a single hypothesis when using a `with` argument.\"\n| (some n) with_list :=\n  do\n    h \u2190 get_local n,\n    focus1 $ fin_cases_at with_list h\n\nend interactive\n\nadd_tactic_doc\n{ name       := \"fin_cases\",\n  category   := doc_category.tactic,\n  decl_names := [`tactic.interactive.fin_cases],\n  tags       := [\"case bashing\"] }\n\nend tactic\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/tactic/fin_cases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.719800992417613}}
{"text": "/-\nCopyright (c) 2020 Google LLC. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Wong\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.list.basic\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Palindromes\n\nThis module defines *palindromes*, lists which are equal to their reverse.\n\nThe main result is the `palindrome` inductive type, and its associated `palindrome.rec_on` induction\nprinciple. Also provided are conversions to and from other equivalent definitions.\n\n## References\n\n* [Pierre Cast\u00e9ran, *On palindromes*][casteran]\n\n[casteran]: https://www.labri.fr/perso/casteran/CoqArt/inductive-prop-chap/palindrome.html\n\n## Tags\n\npalindrome, reverse, induction\n-/\n\n/--\n`palindrome l` asserts that `l` is a palindrome. This is defined inductively:\n\n* The empty list is a palindrome;\n* A list with one element is a palindrome;\n* Adding the same element to both ends of a palindrome results in a bigger palindrome.\n-/\ninductive palindrome {\u03b1 : Type u_1} : List \u03b1 \u2192 Prop where\n| nil : palindrome []\n| singleton : \u2200 (x : \u03b1), palindrome [x]\n| cons_concat : \u2200 (x : \u03b1) {l : List \u03b1}, palindrome l \u2192 palindrome (x :: (l ++ [x]))\n\nnamespace palindrome\n\n\ntheorem reverse_eq {\u03b1 : Type u_1} {l : List \u03b1} (p : palindrome l) : list.reverse l = l := sorry\n\ntheorem of_reverse_eq {\u03b1 : Type u_1} {l : List \u03b1} : list.reverse l = l \u2192 palindrome l := sorry\n\ntheorem iff_reverse_eq {\u03b1 : Type u_1} {l : List \u03b1} : palindrome l \u2194 list.reverse l = l :=\n  { mp := reverse_eq, mpr := of_reverse_eq }\n\ntheorem append_reverse {\u03b1 : Type u_1} (l : List \u03b1) : palindrome (l ++ list.reverse l) := sorry\n\nprotected instance decidable {\u03b1 : Type u_1} [DecidableEq \u03b1] (l : List \u03b1) :\n    Decidable (palindrome l) :=\n  decidable_of_iff' (list.reverse l = l) iff_reverse_eq\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/list/palindrome_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7198009828601277}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-\n\n# More on functions\n\nAnother question on the Imperial introduction to proof problem sheet on functions\nis \"If `f : X \u2192 Y` and `g : Y \u2192 Z` and `g \u2218 f` is injective, is it true that `g` is injective?\"\nThis is not true. A counterexample could be made by letting `X` and `Z` have one element, \nand letting `Y` have two elements; `f` and `g` are then not hard to write down. Let's\nsee how to do this in Lean by making inductive types `X`, `Y` and `Z` and functions\n`f` and `g` which give an explicit counterexample.\n\n-/\n\n-- Let X be {a}\ninductive X : Type\n| a : X\n\n-- in fact the term of type X is called `X.a`.\n\n-- Let Y be {b,c}\ninductive Y : Type\n| b : Y\n| c : Y\n\ninductive Z : Type\n| d : Z\n\n-- Define f by f(X.a)=Y.b\ndef f : X \u2192 Y\n| X.a := Y.b\n\n-- define g by g(Y.b)=g(Y.c)=Z.d\ndef g : Y \u2192 Z\n| Y.b := Z.d\n| Y.c := Z.d\n\n-- Here `Z` only has one term, so if `z : Z` then `cases z` only produces one goal,\n-- namely \"what you get if you change `z` to `Z.d`\".\nexample (z : Z) : z = Z.d :=\nbegin\n  cases z,\n  refl,\nend\n\nlemma Yb_ne_Yc : Y.b \u2260 Y.c :=\nbegin\n  intro h, -- x \u2260 y is definitionally equal to (x = y) \u2192 false\n  cases h, -- no cases when they're equal!\nend\n\nlemma gYb_eq_gYc : g Y.b = g Y.c :=\nbegin\n  -- they're both definitionally `Z.d`\n  refl,\nend\n\n\nopen function\n\nlemma gf_injective : injective (g \u2218 f) :=\nbegin\n  -- use `rintro` trick to do `intro, cases` at the same time\n  rintro \u27e8_\u27e9 \u27e8_\u27e9 h,\n  refl,\nend\n\n-- This is a question on the IUM (Imperial introduction to proof course) function problem sheet.\n-- Recall that if you have a hypothesis of the form `h : \u2200 A, ...`, then `specialize h X`\n-- will specialize `h` to the specific case `A = X`.\nexample : \u00ac (\u2200 A B C : Type, \u2200 (\u03c6 : A \u2192 B) (\u03c8 : B \u2192 C), injective (\u03c8 \u2218 \u03c6) \u2192 injective \u03c8) :=\nbegin\n  intro h,\n  specialize h X Y Z f g gf_injective gYb_eq_gYc,\n  cases h,\nend\n\n-- You might want to make some sublemmas first.\nlemma gf_surjective : surjective (g \u2218 f) :=\nbegin\n  intro z,\n  use X.a,\n  cases z,\n  refl,\nend\n\n-- This is another one. \nexample : \u00ac (\u2200 A B C : Type, \u2200 (\u03c6 : A \u2192 B) (\u03c8 : B \u2192 C), surjective (\u03c8 \u2218 \u03c6) \u2192 surjective \u03c6) :=\nbegin\n  intro h,\n  specialize h X Y Z f g gf_surjective Y.c,\n  rcases h with \u27e8\u27e8_\u27e9, \u27e8\u27e9\u27e9, -- this line does three `cases` at once.\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section03functions/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.719800980448799}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport data.real.basic\nimport analysis.calculus.parametric_integral\n\n/-\n\n# Basic calculus\n\n-/\n\n-- Thanks to Moritz Doll on the Zulip for writing this one!\n/-- If `f : \u211d \u2192 \u211d` is differentiable at `x`, then the obvious induced function `\u211d \u2192 \u2102` is\nalso differentiable at `x`. -/\nlemma complex.differentiable_at_coe {f : \u211d \u2192 \u211d} {x : \u211d } (hf : differentiable_at \u211d f x) :\n  differentiable_at \u211d (\u03bb y, (f y : \u2102)) x :=\nbegin\n  apply complex.of_real_clm.differentiable_at.comp _ hf,\nend\n\n-- Here's a harder example\nexample (a : \u2102) (x : \u211d) : differentiable_at \u211d (\u03bb (y : \u211d), complex.exp (-(a * \u2191y ^ 2))) x :=\nbegin\n  apply differentiable_at.comp,\n  { apply differentiable_at.cexp,\n    apply differentiable_at_id', },\n  { apply differentiable_at.neg,\n    apply differentiable_at.mul,\n    { apply differentiable_at_const, },\n    { norm_cast,\n      apply complex.differentiable_at_coe,\n      apply differentiable_at.pow,\n      apply differentiable_at_id', } },\nend\n\nnoncomputable def \u03c6\u2081 : \u211d \u2192 \u211d \u00d7 \u211d := \n\u03bb x, (real.cos x, real.sin x)\n\nexample : cont_diff_on \u211d \u22a4 (\u03bb x, (real.cos x, real.sin x)) (set.Icc 0 1) :=\nbegin\n  sorry,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section17curves_and_surfaces/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7197925256868282}}
{"text": "/-\nCopyright (c) 2021 Jakob von Raumer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jakob von Raumer\n\n! This file was ported from Lean 3 source module linear_algebra.tensor_product_basis\n! leanprover-community/mathlib commit 4977fd9da637b6e0a805c1cf460c3a6b8df3f556\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.DirectSum.Finsupp\nimport Mathbin.LinearAlgebra.FinsuppVectorSpace\n\n/-!\n# Bases and dimensionality of tensor products of modules\n\nThese can not go into `linear_algebra.tensor_product` since they depend on\n`linear_algebra.finsupp_vector_space` which in turn imports `linear_algebra.tensor_product`.\n\n-/\n\n\nnoncomputable section\n\nopen Set LinearMap Submodule\n\nsection CommRing\n\nvariable {R : Type _} {M : Type _} {N : Type _} {\u03b9 : Type _} {\u03ba : Type _}\n\nvariable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]\n\n/-- If b : \u03b9 \u2192 M and c : \u03ba \u2192 N are bases then so is \u03bb i, b i.1 \u2297\u209c c i.2 : \u03b9 \u00d7 \u03ba \u2192 M \u2297 N. -/\ndef Basis.tensorProduct (b : Basis \u03b9 R M) (c : Basis \u03ba R N) :\n    Basis (\u03b9 \u00d7 \u03ba) R (TensorProduct R M N) :=\n  Finsupp.basisSingleOne.map\n    ((TensorProduct.congr b.repr c.repr).trans <|\n        (finsuppTensorFinsupp R _ _ _ _).trans <|\n          Finsupp.lcongr (Equiv.refl _) (TensorProduct.lid R R)).symm\n#align basis.tensor_product Basis.tensorProduct\n\n@[simp]\ntheorem Basis.tensorProduct_apply (b : Basis \u03b9 R M) (c : Basis \u03ba R N) (i : \u03b9) (j : \u03ba) :\n    Basis.tensorProduct b c (i, j) = b i \u2297\u209c c j := by simp [Basis.tensorProduct]\n#align basis.tensor_product_apply Basis.tensorProduct_apply\n\ntheorem Basis.tensorProduct_apply' (b : Basis \u03b9 R M) (c : Basis \u03ba R N) (i : \u03b9 \u00d7 \u03ba) :\n    Basis.tensorProduct b c i = b i.1 \u2297\u209c c i.2 := by simp [Basis.tensorProduct]\n#align basis.tensor_product_apply' Basis.tensorProduct_apply'\n\nend CommRing\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/TensorProductBasis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129515, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.719792523348778}}
{"text": "/-\nCopyright (c) 2022 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module data.int.log\n! leanprover-community/mathlib commit 1f0096e6caa61e9c849ec2adbd227e960e9dff58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.Floor\nimport Mathlib.Algebra.Order.Field.Power\nimport Mathlib.Data.Nat.Log\n\n/-!\n# Integer logarithms in a field with respect to a natural base\n\nThis file defines two `\u2124`-valued analogs of the logarithm of `r : R` with base `b : \u2115`:\n\n* `Int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `\u2191b^k \u2264 r`.\n* `Int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r \u2264 \u2191b^k`.\n\nNote that `Int.log` gives the position of the left-most non-zero digit:\n```lean\n#eval (Int.log 10 (0.09 : \u211a), Int.log 10 (0.10 : \u211a), Int.log 10 (0.11 : \u211a))\n--    (-2,                    -1,                    -1)\n#eval (Int.log 10 (9 : \u211a),    Int.log 10 (10 : \u211a),   Int.log 10 (11 : \u211a))\n--    (0,                     1,                     1)\n```\nwhich means it can be used for computing digit expansions\n```lean\nimport Data.Fin.VecNotation\nimport Mathlib.Data.Rat.Floor\n\ndef digits (b : \u2115) (q : \u211a) (n : \u2115) : \u2115 :=\n\u230aq * ((b : \u211a) ^ (n - Int.log b q))\u230b\u208a % b\n\n#eval digits 10 (1/7) \u2218 ((\u2191) : Fin 8 \u2192 \u2115)\n-- ![1, 4, 2, 8, 5, 7, 1, 4]\n```\n\n## Main results\n\n* For `Int.log`:\n  * `Int.zpow_log_le_self`, `Int.lt_zpow_succ_log_self`: the bounds formed by `Int.log`,\n    `(b : R) ^ log b r \u2264 r < (b : R) ^ (log b r + 1)`.\n  * `Int.zpow_log_gi`: the galois coinsertion between `zpow` and `Int.log`.\n* For `Int.clog`:\n  * `Int.zpow_pred_clog_lt_self`, `Int.self_le_zpow_clog`: the bounds formed by `Int.clog`,\n    `(b : R) ^ (clog b r - 1) < r \u2264 (b : R) ^ clog b r`.\n  * `Int.clog_zpow_gi`:  the galois insertion between `Int.clog` and `zpow`.\n* `Int.neg_log_inv_eq_clog`, `Int.neg_clog_inv_eq_log`: the link between the two definitions.\n-/\n\n\nvariable {R : Type _} [LinearOrderedSemifield R] [FloorSemiring R]\n\nnamespace Int\n\n/-- The greatest power of `b` such that `b ^ log b r \u2264 r`. -/\ndef log (b : \u2115) (r : R) : \u2124 :=\n  if 1 \u2264 r then Nat.log b \u230ar\u230b\u208a else -Nat.clog b \u2308r\u207b\u00b9\u2309\u208a\n#align int.log Int.log\n\ntheorem log_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : log b r = Nat.log b \u230ar\u230b\u208a :=\n  if_pos hr\n#align int.log_of_one_le_right Int.log_of_one_le_right\n\ntheorem log_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : log b r = -Nat.clog b \u2308r\u207b\u00b9\u2309\u208a := by\n  obtain rfl | hr := hr.eq_or_lt\n  \u00b7 rw [log, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right,\n      Int.ofNat_zero, neg_zero]\n  \u00b7 exact if_neg hr.not_le\n#align int.log_of_right_le_one Int.log_of_right_le_one\n\n@[simp, norm_cast]\ntheorem log_natCast (b : \u2115) (n : \u2115) : log b (n : R) = Nat.log b n := by\n  cases n\n  \u00b7 simp [log_of_right_le_one]\n  \u00b7 rw [log_of_one_le_right, Nat.floor_coe]\n    simp\n#align int.log_nat_cast Int.log_natCast\n\ntheorem log_of_left_le_one {b : \u2115} (hb : b \u2264 1) (r : R) : log b r = 0 := by\n  cases' le_total 1 r with h h\n  \u00b7 rw [log_of_one_le_right _ h, Nat.log_of_left_le_one hb, Int.ofNat_zero]\n  \u00b7 rw [log_of_right_le_one _ h, Nat.clog_of_left_le_one hb, Int.ofNat_zero, neg_zero]\n#align int.log_of_left_le_one Int.log_of_left_le_one\n\ntheorem log_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : log b r = 0 := by\n  rw [log_of_right_le_one _ (hr.trans zero_le_one),\n    Nat.clog_of_right_le_one ((Nat.ceil_eq_zero.mpr <| inv_nonpos.2 hr).trans_le zero_le_one),\n    Int.ofNat_zero, neg_zero]\n#align int.log_of_right_le_zero Int.log_of_right_le_zero\n\ntheorem zpow_log_le_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) : (b : R) ^ log b r \u2264 r := by\n  cases' le_total 1 r with hr1 hr1\n  \u00b7 rw [log_of_one_le_right _ hr1]\n    rw [zpow_ofNat, \u2190 Nat.cast_pow, \u2190 Nat.le_floor_iff hr.le]\n    exact Nat.pow_log_le_self b (Nat.floor_pos.mpr hr1).ne'\n  \u00b7 rw [log_of_right_le_one _ hr1, zpow_neg, zpow_ofNat, \u2190 Nat.cast_pow]\n    exact inv_le_of_inv_le hr (Nat.ceil_le.1 <| Nat.le_pow_clog hb _)\n#align int.zpow_log_le_self Int.zpow_log_le_self\n\ntheorem lt_zpow_succ_log_self {b : \u2115} (hb : 1 < b) (r : R) : r < (b : R) ^ (log b r + 1) := by\n  cases' le_or_lt r 0 with hr hr\n  \u00b7 rw [log_of_right_le_zero _ hr, zero_add, zpow_one]\n    exact hr.trans_lt (zero_lt_one.trans_le <| by exact_mod_cast hb.le)\n  cases' le_or_lt 1 r with hr1 hr1\n  \u00b7 rw [log_of_one_le_right _ hr1]\n    rw [Int.ofNat_add_one_out, zpow_ofNat, \u2190 Nat.cast_pow]\n    apply Nat.lt_of_floor_lt\n    exact Nat.lt_pow_succ_log_self hb _\n  \u00b7 rw [log_of_right_le_one _ hr1.le]\n    have hcri : 1 < r\u207b\u00b9 := one_lt_inv hr hr1\n    have : 1 \u2264 Nat.clog b \u2308r\u207b\u00b9\u2309\u208a :=\n      Nat.succ_le_of_lt (Nat.clog_pos hb <| Nat.one_lt_cast.1 <| hcri.trans_le (Nat.le_ceil _))\n    rw [neg_add_eq_sub, \u2190 neg_sub, \u2190 Int.ofNat_one, \u2190 Int.ofNat_sub this, zpow_neg, zpow_ofNat,\n      lt_inv hr (pow_pos (Nat.cast_pos.mpr <| zero_lt_one.trans hb) _), \u2190 Nat.cast_pow]\n    refine' Nat.lt_ceil.1 _\n    exact Nat.pow_pred_clog_lt_self hb <| Nat.one_lt_cast.1 <| hcri.trans_le <| Nat.le_ceil _\n#align int.lt_zpow_succ_log_self Int.lt_zpow_succ_log_self\n\n@[simp]\ntheorem log_zero_right (b : \u2115) : log b (0 : R) = 0 :=\n  log_of_right_le_zero b le_rfl\n#align int.log_zero_right Int.log_zero_right\n\n@[simp]\ntheorem log_one_right (b : \u2115) : log b (1 : R) = 0 := by\n  rw [log_of_one_le_right _ le_rfl, Nat.floor_one, Nat.log_one_right, Int.ofNat_zero]\n#align int.log_one_right Int.log_one_right\n\n-- Porting note: needed to replace b ^ z with (b : R) ^ z in the below\ntheorem log_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : log b ((b : R) ^ z : R) = z := by\n  obtain \u27e8n, rfl | rfl\u27e9 := Int.eq_nat_or_neg z\n  \u00b7 rw [log_of_one_le_right _ (one_le_zpow_of_nonneg _ <| Int.coe_nat_nonneg _), zpow_ofNat, \u2190\n      Nat.cast_pow, Nat.floor_coe, Nat.log_pow hb]\n    exact_mod_cast hb.le\n  \u00b7 rw [log_of_right_le_one _ (zpow_le_one_of_nonpos _ <| neg_nonpos.mpr (Int.coe_nat_nonneg _)),\n      zpow_neg, inv_inv, zpow_ofNat, \u2190 Nat.cast_pow, Nat.ceil_natCast, Nat.clog_pow _ _ hb]\n    exact_mod_cast hb.le\n#align int.log_zpow Int.log_zpow\n\n@[mono]\ntheorem log_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) : log b r\u2081 \u2264 log b r\u2082 := by\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [log_of_left_le_one hb, log_of_left_le_one hb]\n  cases' le_total r\u2081 1 with h\u2081 h\u2081 <;> cases' le_total r\u2082 1 with h\u2082 h\u2082\n  \u00b7 rw [log_of_right_le_one _ h\u2081, log_of_right_le_one _ h\u2082, neg_le_neg_iff, Int.ofNat_le]\n    exact Nat.clog_mono_right _ (Nat.ceil_mono <| inv_le_inv_of_le h\u2080 h)\n  \u00b7 rw [log_of_right_le_one _ h\u2081, log_of_one_le_right _ h\u2082]\n    exact (neg_nonpos.mpr (Int.coe_nat_nonneg _)).trans (Int.coe_nat_nonneg _)\n  \u00b7 obtain rfl := le_antisymm h (h\u2082.trans h\u2081)\n    rfl\n  \u00b7 rw [log_of_one_le_right _ h\u2081, log_of_one_le_right _ h\u2082, Int.ofNat_le]\n    exact Nat.log_mono_right (Nat.floor_mono h)\n#align int.log_mono_right Int.log_mono_right\n\nvariable (R)\n\n/-- Over suitable subtypes, `zpow` and `Int.log` form a galois coinsertion -/\ndef zpowLogGi {b : \u2115} (hb : 1 < b) :\n    GaloisCoinsertion\n      (fun z : \u2124 =>\n        Subtype.mk ((b : R) ^ z) <| zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z)\n      fun r : Set.Ioi (0 : R) => Int.log b (r : R) :=\n  GaloisCoinsertion.monotoneIntro (fun r\u2081 r\u2082 => log_mono_right r\u2081.2)\n    (fun z\u2081 z\u2082 hz => Subtype.coe_le_coe.mp <| (zpow_strictMono <| by exact_mod_cast hb).monotone hz)\n    (fun r => Subtype.coe_le_coe.mp <| zpow_log_le_self hb r.2) fun _ => log_zpow (R := R) hb _\n#align int.zpow_log_gi Int.zpowLogGi\n\nvariable {R}\n\n/-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/\ntheorem lt_zpow_iff_log_lt {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n    r < (b : R) ^ x \u2194 log b r < x :=\n  @GaloisConnection.lt_iff_lt _ _ _ _ _ _ (zpowLogGi R hb).gc x \u27e8r, hr\u27e9\n#align int.lt_zpow_iff_log_lt Int.lt_zpow_iff_log_lt\n\n/-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/\ntheorem zpow_le_iff_le_log {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n    (b : R) ^ x \u2264 r \u2194 x \u2264 log b r :=\n  @GaloisConnection.le_iff_le _ _ _ _ _ _ (zpowLogGi R hb).gc x \u27e8r, hr\u27e9\n#align int.zpow_le_iff_le_log Int.zpow_le_iff_le_log\n\n/-- The least power of `b` such that `r \u2264 b ^ log b r`. -/\ndef clog (b : \u2115) (r : R) : \u2124 :=\n  if 1 \u2264 r then Nat.clog b \u2308r\u2309\u208a else -Nat.log b \u230ar\u207b\u00b9\u230b\u208a\n#align int.clog Int.clog\n\ntheorem clog_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : clog b r = Nat.clog b \u2308r\u2309\u208a :=\n  if_pos hr\n#align int.clog_of_one_le_right Int.clog_of_one_le_right\n\ntheorem clog_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : clog b r = -Nat.log b \u230ar\u207b\u00b9\u230b\u208a := by\n  obtain rfl | hr := hr.eq_or_lt\n  \u00b7 rw [clog, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right,\n      Nat.clog_one_right, Int.ofNat_zero, neg_zero]\n  \u00b7 exact if_neg hr.not_le\n#align int.clog_of_right_le_one Int.clog_of_right_le_one\n\ntheorem clog_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : clog b r = 0 := by\n  rw [clog, if_neg (hr.trans_lt zero_lt_one).not_le, neg_eq_zero, Int.coe_nat_eq_zero,\n    Nat.log_eq_zero_iff]\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 exact Or.inr hb\n  \u00b7 refine' Or.inl (lt_of_le_of_lt _ hb)\n    exact Nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one)\n#align int.clog_of_right_le_zero Int.clog_of_right_le_zero\n\n@[simp]\ntheorem clog_inv (b : \u2115) (r : R) : clog b r\u207b\u00b9 = -log b r := by\n  cases' lt_or_le 0 r with hrp hrp\n  \u00b7 obtain hr | hr := le_total 1 r\n    \u00b7 rw [clog_of_right_le_one _ (inv_le_one hr), log_of_one_le_right _ hr, inv_inv]\n    \u00b7 rw [clog_of_one_le_right _ (one_le_inv hrp hr), log_of_right_le_one _ hr, neg_neg]\n  \u00b7 rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero]\n#align int.clog_inv Int.clog_inv\n\n@[simp]\ntheorem log_inv (b : \u2115) (r : R) : log b r\u207b\u00b9 = -clog b r := by\n  rw [\u2190 inv_inv r, clog_inv, neg_neg, inv_inv]\n#align int.log_inv Int.log_inv\n\n-- note this is useful for writing in reverse\ntheorem neg_log_inv_eq_clog (b : \u2115) (r : R) : -log b r\u207b\u00b9 = clog b r := by rw [log_inv, neg_neg]\n#align int.neg_log_inv_eq_clog Int.neg_log_inv_eq_clog\n\ntheorem neg_clog_inv_eq_log (b : \u2115) (r : R) : -clog b r\u207b\u00b9 = log b r := by rw [clog_inv, neg_neg]\n#align int.neg_clog_inv_eq_log Int.neg_clog_inv_eq_log\n\n@[simp, norm_cast]\ntheorem clog_natCast (b : \u2115) (n : \u2115) : clog b (n : R) = Nat.clog b n := by\n  cases' n with n\n  \u00b7 simp [clog_of_right_le_one]\n  \u00b7 rw [clog_of_one_le_right, (Nat.ceil_eq_iff (Nat.succ_ne_zero n)).mpr] <;> simp\n#align int.clog_nat_cast Int.clog_natCast\n\n\n\ntheorem self_le_zpow_clog {b : \u2115} (hb : 1 < b) (r : R) : r \u2264 (b : R) ^ clog b r := by\n  cases' le_or_lt r 0 with hr hr\n  \u00b7 rw [clog_of_right_le_zero _ hr, zpow_zero]\n    exact hr.trans zero_le_one\n  rw [\u2190 neg_log_inv_eq_clog, zpow_neg, le_inv hr (zpow_pos_of_pos _ _)]\n  \u00b7 exact zpow_log_le_self hb (inv_pos.mpr hr)\n  \u00b7 exact Nat.cast_pos.mpr (zero_le_one.trans_lt hb)\n#align int.self_le_zpow_clog Int.self_le_zpow_clog\n\ntheorem zpow_pred_clog_lt_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) :\n    (b : R) ^ (clog b r - 1) < r := by\n  rw [\u2190 neg_log_inv_eq_clog, \u2190 neg_add', zpow_neg, inv_lt _ hr]\n  \u00b7 exact lt_zpow_succ_log_self hb _\n  \u00b7 exact zpow_pos_of_pos (Nat.cast_pos.mpr <| zero_le_one.trans_lt hb) _\n#align int.zpow_pred_clog_lt_self Int.zpow_pred_clog_lt_self\n\n@[simp]\ntheorem clog_zero_right (b : \u2115) : clog b (0 : R) = 0 :=\n  clog_of_right_le_zero _ le_rfl\n#align int.clog_zero_right Int.clog_zero_right\n\n@[simp]\ntheorem clog_one_right (b : \u2115) : clog b (1 : R) = 0 := by\n  rw [clog_of_one_le_right _ le_rfl, Nat.ceil_one, Nat.clog_one_right, Int.ofNat_zero]\n#align int.clog_one_right Int.clog_one_right\n\n-- Porting note: needed to replace b ^ z with (b : R) ^ z in the below\ntheorem clog_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : clog b ((b : R) ^ z : R) = z := by\n  rw [\u2190 neg_log_inv_eq_clog, \u2190 zpow_neg, log_zpow hb, neg_neg]\n#align int.clog_zpow Int.clog_zpow\n\n@[mono]\ntheorem clog_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) :\n    clog b r\u2081 \u2264 clog b r\u2082 := by\n  rw [\u2190 neg_log_inv_eq_clog, \u2190 neg_log_inv_eq_clog, neg_le_neg_iff]\n  exact log_mono_right (inv_pos.mpr <| h\u2080.trans_le h) (inv_le_inv_of_le h\u2080 h)\n#align int.clog_mono_right Int.clog_mono_right\n\nvariable (R)\n\n/-- Over suitable subtypes, `Int.clog` and `zpow` form a galois insertion -/\ndef clogZpowGi {b : \u2115} (hb : 1 < b) :\n    GaloisInsertion (fun r : Set.Ioi (0 : R) => Int.clog b (r : R)) fun z : \u2124 =>\n      \u27e8(b : R) ^ z, zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z\u27e9 :=\n  GaloisInsertion.monotoneIntro\n    (fun z\u2081 z\u2082 hz => Subtype.coe_le_coe.mp <| (zpow_strictMono <| by exact_mod_cast hb).monotone hz)\n    (fun r\u2081 r\u2082 => clog_mono_right r\u2081.2)\n    (fun r => Subtype.coe_le_coe.mp <| self_le_zpow_clog hb _) fun _ => clog_zpow (R := R) hb _\n#align int.clog_zpow_gi Int.clogZpowGi\n\nvariable {R}\n\n/-- `Int.clog b` and `zpow b` (almost) form a Galois connection. -/\ntheorem zpow_lt_iff_lt_clog {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n    (b : R) ^ x < r \u2194 x < clog b r :=\n  (@GaloisConnection.lt_iff_lt _ _ _ _ _ _ (clogZpowGi R hb).gc \u27e8r, hr\u27e9 x).symm\n#align int.zpow_lt_iff_lt_clog Int.zpow_lt_iff_lt_clog\n\n/-- `Int.clog b` and `zpow b` (almost) form a Galois connection. -/\ntheorem le_zpow_iff_clog_le {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n    r \u2264 (b : R) ^ x \u2194 clog b r \u2264 x :=\n  (@GaloisConnection.le_iff_le _ _ _ _ _ _ (clogZpowGi R hb).gc \u27e8r, hr\u27e9 x).symm\n#align int.le_zpow_iff_clog_le Int.le_zpow_iff_clog_le\n\nend Int\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/Log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302033, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7197925195506641}}
{"text": "import Playground.Data.BinaryTree.BST\n\nsection\n  namespace List\n  variable {type} [LinearOrder type]\n\n  def toBST (list : List type) : Data.BinaryTree.BST type\n  := match list with\n  | [] => .nil\n  | a :: list => list.toBST.insert a\n\n  def bstSort (list : List type) : List type := list.toBST.val.infixList\n\n  theorem bstSort_isSorted (list : List type) : list.bstSort.IsSorted\n  := (list.toBST.val.IsBST_iff_infixList_IsSorted).mp list.toBST.property\n\n  theorem bstSort_Perm (list : List type) : list.bstSort ~ list\n  := match list with\n  | [] => Perm.nil\n  | a :: list => \n    (list.toBST.val.insertAsInBST_infixList_Perm_cons_infixList a).trans\n      (list.bstSort_Perm.cons a)\n\n  end List\nend\n\n#eval [3, 6, 3, 2, 10, 1].bstSort\n", "meta": {"author": "michelsol", "repo": "lean-playground", "sha": "0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca", "save_path": "github-repos/lean/michelsol-lean-playground", "path": "github-repos/lean/michelsol-lean-playground/lean-playground-0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca/Playground/Data/List/BST_Sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7197925153135571}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.units\nimport algebra.algebra.spectrum\nimport topology.continuous_function.algebra\n\n/-!\n# Units of continuous functions\n\nThis file concerns itself with `C(X, M)\u02e3` and `C(X, M\u02e3)` when `X` is a topological space\nand `M` has some monoid structure compatible with its topology.\n-/\n\nvariables {X M R \ud835\udd5c : Type*} [topological_space X]\n\nnamespace continuous_map\n\nsection monoid\n\nvariables [monoid M] [topological_space M] [has_continuous_mul M]\n\n/-- Equivalence between continuous maps into the units of a monoid with continuous multiplication\nand the units of the monoid of continuous maps. -/\n@[to_additive \"Equivalence between continuous maps into the additive units of an additive monoid\nwith continuous addition and the additive units of the additive monoid of continuous maps.\", simps]\ndef units_lift : C(X, M\u02e3) \u2243 C(X, M)\u02e3 :=\n{ to_fun := \u03bb f,\n  { val := \u27e8\u03bb x, f x, units.continuous_coe.comp f.continuous\u27e9,\n    inv := \u27e8\u03bb x, \u2191(f x)\u207b\u00b9, units.continuous_coe.comp (continuous_inv.comp f.continuous)\u27e9,\n    val_inv := ext $ \u03bb x, units.mul_inv _,\n    inv_val := ext $ \u03bb x, units.inv_mul _ },\n  inv_fun := \u03bb f,\n  { to_fun := \u03bb x, \u27e8f x, f\u207b\u00b9 x, continuous_map.congr_fun f.mul_inv x,\n                                continuous_map.congr_fun f.inv_mul x\u27e9,\n    continuous_to_fun := continuous_induced_rng.2 $ continuous.prod_mk (f : C(X, M)).continuous\n      $ mul_opposite.continuous_op.comp (\u2191f\u207b\u00b9 : C(X, M)).continuous },\n  left_inv := \u03bb f, by { ext, refl },\n  right_inv := \u03bb f, by { ext, refl } }\n\nend monoid\n\nsection normed_ring\n\nvariables [normed_ring R] [complete_space R]\n\nlemma _root_.normed_ring.is_unit_unit_continuous {f : C(X, R)} (h : \u2200 x, is_unit (f x)) :\n  continuous (\u03bb x, (h x).unit) :=\nbegin\n  refine continuous_induced_rng.2 (continuous.prod_mk f.continuous\n    (mul_opposite.continuous_op.comp (continuous_iff_continuous_at.mpr (\u03bb x, _)))),\n  have := normed_ring.inverse_continuous_at (h x).unit,\n  simp only [\u2190ring.inverse_unit, is_unit.unit_spec, \u2190function.comp_apply] at this \u22a2,\n  exact this.comp (f.continuous_at x),\nend\n\n/-- Construct a continuous map into the group of units of a normed ring from a function into the\nnormed ring and a proof that every element of the range is a unit. -/\n@[simps]\nnoncomputable def units_of_forall_is_unit {f : C(X, R)} (h : \u2200 x, is_unit (f x)) : C(X, R\u02e3) :=\n{ to_fun := \u03bb x, (h x).unit,\n  continuous_to_fun :=  normed_ring.is_unit_unit_continuous h }\n\ninstance can_lift : can_lift C(X, R) C(X, R\u02e3)\n  (\u03bb f, \u27e8\u03bb x, f x, units.continuous_coe.comp f.continuous\u27e9) (\u03bb f, \u2200 x, is_unit (f x)) :=\n{ prf := \u03bb f h, \u27e8units_of_forall_is_unit h, by { ext, refl }\u27e9 }\n\nlemma is_unit_iff_forall_is_unit (f : C(X, R)) :\n  is_unit f \u2194 \u2200 x, is_unit (f x) :=\niff.intro (\u03bb h, \u03bb x, \u27e8units_lift.symm h.unit x, rfl\u27e9)\n  (\u03bb h, \u27e8(units_of_forall_is_unit h).units_lift, by { ext, refl }\u27e9)\n\nend normed_ring\n\nsection normed_field\n\nvariables [normed_field \ud835\udd5c] [complete_space \ud835\udd5c]\n\nlemma is_unit_iff_forall_ne_zero (f : C(X, \ud835\udd5c)) :\n  is_unit f \u2194 \u2200 x, f x \u2260 0 :=\nby simp_rw [f.is_unit_iff_forall_is_unit, is_unit_iff_ne_zero]\n\nlemma spectrum_eq_range (f : C(X, \ud835\udd5c)) :\n  spectrum \ud835\udd5c f = set.range f :=\nbegin\n  ext,\n  simp only [spectrum.mem_iff, is_unit_iff_forall_ne_zero, not_forall, coe_sub,\n    pi.sub_apply, algebra_map_apply, algebra.id.smul_eq_mul, mul_one, not_not, set.mem_range,\n    sub_eq_zero, @eq_comm _ x _]\nend\n\nend normed_field\n\nend continuous_map\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/continuous_function/units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7197697113116964}}
{"text": "import analysis.topology.topological_space\nimport analysis.topology.continuity\nimport data.set.basic\nimport data.bool\nimport logic.basic\n\nopen set filter lattice classical\nlocal attribute [instance] prop_decidable\n\nuniverse u\nvariables {\u03b1 : Type u} {\u03b2 : Type u} {\u03b3 : Type u} {\u03b4 : Type u}\n\n\ndef is_clopen [t : topological_space \u03b1] (s : set \u03b1) : Prop := is_open s \u2227 is_closed s \n\n/- For subsets, connected def needs to \nconsider open sets in the subspace topology. -/\n\ndef is_open_in_subspace [t : topological_space \u03b1] (A : set \u03b1) (V : set \u03b1) : Prop := \u2203 U, V = A \u2229 U \u2227 is_open U \n\ndef is_connected [t : topological_space \u03b1] (A : set \u03b1) : Prop := \u2200 U V : set \u03b1, \nis_open_in_subspace A U \u2227 is_open_in_subspace A V \u2192 \u00ac( U \u222a V = A \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205) \n\ndef is_separated [topological_space \u03b1] (s t : set \u03b1) : Prop := (closure s) \u2229 t = \u2205 \u2227 s \u2229 (closure t) = \u2205\n\nclass connected_space (\u03b1 : Type u) extends topological_space \u03b1 :=\n    (clopen_trivial : (\u2200 s : set \u03b1, is_clopen s \u2192 (s = univ \u2228 s = \u2205)))\n\nclass discrete_space \u03b1 extends topological_space \u03b1 :=\n(discreteness : \u2200 U : set \u03b1, is_open U)\n\ndef X : topological_space bool := by apply_instance\n\nclass indiscrete_space \u03b1 extends topological_space \u03b1 :=\n(indiscreteness : \u2200 U : set \u03b1, \u00acis_open U)\n\nclass discrete_connected_space \u03b1 extends connected_space \u03b1 :=\n(discreteness : \u2200 U : set \u03b1, is_open U)\n\nclass indiscrete_connected_space \u03b1 extends connected_space \u03b1 :=\n(indiscreteness : \u2200 U : set \u03b1, \u00acis_open U)\n\n-----------------------------------------------------------------\n-- Some useful lemmas\n\n\nlemma eq_compl_iff_compl_eq {A B : set \u03b1} : A = -B \u2194 B = -A := \nby {apply iff.intro, intro H1, rw [H1,compl_compl], intro H2, rw [H2,compl_compl]}\n\n\nlemma disjoint_and_union_univ_imp_compl {A B : set \u03b1} (hU : A \u222a B = univ) \n(hE : A \u2229 B = \u2205) : A = -B :=\n  set.subset.antisymm \n    (subset_compl_iff_disjoint.2 hE : A \u2286 -B) \n    (compl_subset_iff_union.2 $ set.union_comm A B \u25b8 hU : -B \u2286 A)\n\n\nlemma neq_empty_imp_empty_to_union {A B : set \u03b1} (H : \u00acA = \u2205 \u2192 B = \u2205) :\nA = \u2205 \u2228 B = \u2205 :=\nbegin\n  by_contradiction hc, rw [not_or_distrib] at hc, \n  by exact absurd (H hc.1) hc.2,\nend\n\n\nlemma in_right_union_univ {A B : set \u03b1} {x : \u03b1} (H : A \u222a B = univ) : x \u2209 A \u2192 x \u2208 B :=\nbegin\n  intro hx, \n  by exact or.elim ((mem_union _ _ _).mp (eq_univ_iff_forall.mp H x))\n    (assume a1, by exact absurd a1 hx)\n    (assume a2, by exact a2),\nend\n\n\nlemma in_left_union_univ {A B : set \u03b1} {x : \u03b1} (H : A \u222a B = univ) : x \u2209 B \u2192 x \u2208 A :=\nbegin\n  intro hx, \n  by exact or.elim ((mem_union _ _ _).mp (eq_univ_iff_forall.mp H x))\n    (assume a2, by exact a2)\n    (assume a1, by exact absurd a1 hx),\nend\n\n\nlemma subset_def_iff {A B : set \u03b1} : (A \u2286 B) \u2194 \u2200 x, x \u2208 A \u2192 x \u2208 B :=\nby {apply iff.intro, intro h1, rwa [\u2190subset_def], intro h2, rwa [subset_def]}\n\nlemma nmem_compl_iff (s : set \u03b1) (x : \u03b1) : x \u2209 -s \u2194 x \u2208 s := by simp\n\n\nlemma not_in_right_union_empty {A B : set \u03b1} {x : \u03b1} (H : A \u2229 B = \u2205) : x \u2208 A \u2192 x \u2209 B :=\nby {intros hx hc, exact absurd H (ne_empty_of_mem (mem_inter hx hc))}\n\nlemma not_in_left_union_empty {A B : set \u03b1} {x : \u03b1} (H : A \u2229 B = \u2205) : x \u2208 B \u2192 x \u2209 A :=\nby {intros hx hc, exact absurd H (ne_empty_of_mem (mem_inter hc hx))}\n\n\nlemma mem_inter_empty_left {A B : set \u03b1} {x : \u03b1} (H1 : x \u2208 A) (H2 : A \u2229 B = \u2205) :\nx \u2209 B := by {by_contradiction HC, exact absurd H2 (ne_empty_of_mem (mem_inter H1 HC))}\n\nlemma mem_inter_empty_right {A B : set \u03b1} {x : \u03b1} (H1 : x \u2208 B) (H2 : A \u2229 B = \u2205) :\nx \u2209 A := by {by_contradiction HC, exact absurd H2 (ne_empty_of_mem (mem_inter HC H1))}\n\n\n\nlemma disjoint_compl_imp_subset {A B : set \u03b1} (H : A \u2229 -B = \u2205) : A \u2286 B :=\nsubset_def_iff.mpr (assume (x : \u03b1) (hA : x \u2208 A), (nmem_compl_iff _ _ ).mp (mem_inter_empty_left hA H))\n\n\n\nlemma eq_union_of_inter_if_subseteq {A B C : set \u03b1} (H1 : A \u2286 B \u222a C) : A = (A \u2229 B) \u222a (A \u2229 C) \n:= by {rw [\u2190inter_distrib_left,inter_eq_self_of_subset_left H1]}\n\nlemma inter_empty_distrib {A B C : set \u03b1} (H1 : B \u2229 C = \u2205) : (A \u2229 B) \u2229 (A \u2229 C) = \u2205 \n:= by {rw [inter_left_comm,\u2190inter_assoc,\u2190inter_assoc], simp, rw [inter_assoc,H1], simp}\n\nlemma union_left_inter_distrib {A B C D : set \u03b1} (H : A = (B \u222a C) \u2229 D) : B \u2229 A = B \u2229 D\n:= by {rw [H,\u2190inter_assoc, inter_eq_self_of_subset_left (subset_union_left _ _ )]}\n\nlemma union_right_inter_distrib {A B C D : set \u03b1} (H : A = (B \u222a C) \u2229 D) : C \u2229 A = C \u2229 D\n:= by {rw [H,\u2190inter_assoc, inter_eq_self_of_subset_left (subset_union_right _ _ )]}\n\n@[simp] lemma inter_union_self_left {A B : set \u03b1} : A \u2229 (A \u222a B) = A :=\next (assume x, iff.intro (assume h1, mem_of_mem_inter_left h1) (assume h2, mem_inter h2 (mem_union_left _ h2)))\n\n@[simp] lemma inter_union_self_right {A B : set \u03b1} : B \u2229 (A \u222a B) = B := \next (assume x, iff.intro (assume h1, mem_of_mem_inter_left h1) (assume h2, mem_inter h2 (mem_union_right _ h2)))\n\n-----------------------------------------------------------------\n\ntheorem open_imp_inter_open_in_subspace [topological_space \u03b1] {s t v : set \u03b1} :\nis_open t \u2192 is_open_in_subspace s (t \u2229 s) :=\nbegin\n  intro h1,\n  show is_open_in_subspace s (t \u2229 s), \n    {rw is_open_in_subspace, by exact exists.intro t \u27e8inter_comm t s, h1\u27e9},\nend\n\n\nlemma sub_union_open_to_open_inter_left [topological_space \u03b1] {A B C : set \u03b1} \n(H1 : is_open_in_subspace (A \u222a B) C) : is_open_in_subspace A (A \u2229 C) :=\nby {cases H1 with T HT, exact \u27e8T, \u27e8union_left_inter_distrib HT.1, HT.2\u27e9\u27e9}\n\n\nlemma sub_union_open_to_open_inter_right [topological_space \u03b1] {A B C : set \u03b1} \n(H1 : is_open_in_subspace (A \u222a B) C) : is_open_in_subspace B (B \u2229 C) :=\nby {cases H1 with T HT, exact \u27e8T, \u27e8union_right_inter_distrib HT.1, HT.2\u27e9\u27e9}\n\n\nlemma closure_subset_imp_eq [topological_space \u03b1] {s : set \u03b1} \n(H : closure s \u2286 s) : closure s = s := by exact subset.antisymm H subset_closure\n\nlemma subset_interior_imp_eq [topological_space \u03b1] {s : set \u03b1} \n(H : s \u2286 interior s) : interior s = s := by exact subset.antisymm interior_subset H \n\n\ntheorem closure_eq_interior_iff_clopen [topological_space \u03b1] :\n(\u2200 s : set \u03b1, closure s = interior s \u2194 is_clopen s) := \nbegin\n  intro s,\n    have A := subset_closure, have B := interior_subset,\n  apply iff.intro, assume h1, rw [h1] at A, rw [\u2190h1] at B,\n    rw is_clopen, exact \u27e8interior_eq_iff_open.mp (subset_interior_imp_eq A),\n    closure_eq_iff_is_closed.mp (closure_subset_imp_eq B)\u27e9, \n  assume H1, rw [closure_eq_iff_is_closed.mpr H1.2, interior_eq_iff_open.mpr H1.1],  \nend\n\n\ntheorem empty_frontier_iff_clopen [topological_space \u03b1] :\n(\u2200 s : set \u03b1, frontier s = \u2205 \u2194 is_clopen s) :=\nbegin\n  intro s, apply iff.intro, \n    rw [frontier_eq_closure_inter_closure], \n    intro h, simp at h, \n    by exact (closure_eq_interior_iff_clopen _ ).mp (subset.antisymm (disjoint_compl_imp_subset h) interior_subset_closure),\n  intro H1, rw [frontier, closure_eq_iff_is_closed.mpr H1.2, interior_eq_iff_open.mpr H1.1, diff_eq], simp,  \nend\n\n\nlemma components_of_separation_clopen [topological_space \u03b1] \n{U1 U2 : set \u03b1} (hu1 : is_open U1) (hu2 : is_open U2) : (U1 \u222a U2 = univ \u2227 U1 \u2229 U2 = \u2205 \u2227 U1 \u2260 \u2205 \u2227 U2 \u2260 \u2205) \u2192 \nis_clopen U1 \u2227 is_clopen U2 :=\nbegin \n  intro H,\n  exact \u27e8\u27e8hu1, by {rw [\u2190eq_comm.mp (eq_compl_iff_compl_eq.mp (disjoint_and_union_univ_imp_compl H.1 H.2.1))] at hu2, rwa is_closed}\u27e9,\n    \u27e8hu2, by {rw disjoint_and_union_univ_imp_compl H.1 H.2.1 at hu1, rwa is_closed}\u27e9\u27e9,  \nend \n\n\nlemma components_of_separation_clopen2 [topological_space \u03b1] \n{U1 U2 : set \u03b1} (hu1 : is_open U1) (hu2 : is_open U2) (hunion : U1 \u222a U2 = univ) \n(hinter : U1 \u2229 U2 = \u2205) (hnon1 : U1 \u2260 \u2205) (hnon2 : U2 \u2260 \u2205) : is_clopen U1 \u2227 is_clopen U2 :=\n\u27e8\u27e8hu1, by {rw [\u2190eq_comm.mp (eq_compl_iff_compl_eq.mp (disjoint_and_union_univ_imp_compl hunion hinter))] at hu2, rwa is_closed}\u27e9,\n  \u27e8hu2, by {rw disjoint_and_union_univ_imp_compl hunion hinter at hu1, rwa is_closed}\u27e9\u27e9  \n \n\n\nlemma open_separation_to_closed [topological_space \u03b1] \n{U1 U2 : set \u03b1} (hu1 : is_open U1) (hu2 : is_open U2) : (U1 \u222a U2 = univ \u2227 U1 \u2229 U2 = \u2205 \u2227 U1 \u2260 \u2205 \u2227 U2 \u2260 \u2205) \u2192 \nis_closed U1 \u2227 is_closed U2 :=\nbegin \n  intro H,\n  exact \u27e8by {rw [\u2190eq_comm.mp (eq_compl_iff_compl_eq.mp (disjoint_and_union_univ_imp_compl H.1 H.2.1))] at hu2, rwa is_closed}, \n  by {rw disjoint_and_union_univ_imp_compl H.1 H.2.1 at hu1, rwa is_closed}\u27e9\nend \n\n\nlemma open_separation_to_closed2 [topological_space \u03b1] \n  {U1 U2 : set \u03b1} (hu1 : is_open U1) (hu2 : is_open U2) (hunion : U1 \u222a U2 = univ)\n  (hinter : U1 \u2229 U2 = \u2205) (hnon1 : U1 \u2260 \u2205) (hnon2 :U2 \u2260 \u2205) : is_closed U1 \u2227 is_closed U2 :=  \nbegin \n  have hu1c : is_closed U1, {rw [\u2190eq_comm.mp (eq_compl_iff_compl_eq.mp (disjoint_and_union_univ_imp_compl hunion hinter))] at hu2, rwa is_closed},\n  have hu2c : is_closed U2, {rw disjoint_and_union_univ_imp_compl hunion hinter at hu1, rwa is_closed}, \n  exact \u27e8hu1c,hu2c\u27e9,  \nend \n\n\nlemma closed_separation_to_open [topological_space \u03b1] \n{U1 U2 : set \u03b1} (hu1 : is_closed U1) (hu2 : is_closed U2) : (U1 \u222a U2 = univ \u2227 U1 \u2229 U2 = \u2205 \u2227 U1 \u2260 \u2205 \u2227 U2 \u2260 \u2205) \u2192 \nis_open U1 \u2227 is_open U2 :=\nbegin \n  intro H,\n    exact \u27e8by {rw [\u2190eq_comm.mp (eq_compl_iff_compl_eq.mp (disjoint_and_union_univ_imp_compl H.1 H.2.1))] at hu2, rwa is_closed at hu2, simp at hu2, assumption},\n      by {rw disjoint_and_union_univ_imp_compl H.1 H.2.1 at hu1, rwa is_closed at hu1, simp at hu1, assumption}\u27e9,    \nend \n\n\nlemma closed_separation_to_open2 [topological_space \u03b1] \n{U1 U2 : set \u03b1} (hu1 : is_closed U1) (hu2 : is_closed U2) (hunion : U1 \u222a U2 = univ)\n(hinter : U1 \u2229 U2 = \u2205) (hnon1 : U1 \u2260 \u2205) (hnon2 :U2 \u2260 \u2205) : is_open U1 \u2227 is_open U2 :=  \nbegin \n  exact \u27e8by {rw [\u2190eq_comm.mp (eq_compl_iff_compl_eq.mp (disjoint_and_union_univ_imp_compl hunion hinter))] at hu2, rwa is_closed at hu2, simp at hu2, assumption},\n    by {rw disjoint_and_union_univ_imp_compl hunion hinter at hu1, rwa is_closed at hu1, simp at hu1, assumption}\u27e9,    \nend \n\n\n\nlemma no_open_sep_iff_no_closed_sep [topological_space \u03b1] :\n(\u2200 U1 U2: set \u03b1, is_open U1 \u2227 is_open U2 \u2192 \u00ac( U1 \u222a U2 = univ \u2227 U1 \u2229 U2 = \u2205 \u2227 U1 \u2260 \u2205 \u2227 U2 \u2260 \u2205))\n\u2194 (\u2200 V1 V2 : set \u03b1, is_closed V1 \u2227 is_closed V2 \u2192 \u00ac( V1 \u222a V2 = univ \u2227 V1 \u2229 V2 = \u2205 \u2227 V1 \u2260 \u2205 \u2227 V2 \u2260 \u2205)) :=\nbegin\n  apply iff.intro, \n    intros H1 V1 V2 h1 c1,\n    apply absurd c1 (H1 V1 V2 (closed_separation_to_open h1.1 h1.2 c1)),\n  intros H1 U1 U2 h1 c1,\n  apply absurd c1 (H1 U1 U2 (open_separation_to_closed h1.1 h1.2 c1)),\nend\n\n\nlemma closure_union_closure_compl_eq_univ [topological_space \u03b1] {A : set \u03b1} :\nclosure A \u222a closure (-A) = univ :=\n  by {simp, rw [\u2190compl_subset_iff_union], rw [compl_subset_comm, compl_compl], \n  exact interior_subset_closure}\n\n\n \nlemma trivial_imp_empty_frontier [topological_space \u03b1] {A : set \u03b1} :\nA = univ \u2228 A = \u2205 \u2192 frontier A = \u2205 :=\nbegin \n  intro H,\n  by exact or.elim H\n    (assume a1, show closure A \\ interior A = \u2205, {rw a1, simp, rw [\u2190compl_eq_univ_diff _], simp})\n    (assume a1, show closure A \\ interior A = \u2205, {rw a1, by simp}),\nend\n\nlemma trivial_imp_empty_frontier2 [topological_space \u03b1] {A : set \u03b1} \n(H : A = univ \u2228 A = \u2205) : frontier A = \u2205 :=\n  or.elim H\n    (assume a1, show closure A \\ interior A = \u2205, {rw a1, simp, rw [\u2190compl_eq_univ_diff _], simp})\n    (assume a1, show closure A \\ interior A = \u2205, {rw a1, by simp})\n\n\n------------------------------------------------------------\n\n-- (1) \u2192 (2)\nlemma one_implies_two [topological_space \u03b1] : (\u2200 U V : set \u03b1, is_open U \u2227 is_open V \u2192 \n\u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205)) \u2192 (\u2200 U V : set \u03b1, \nis_closed U \u2227 is_closed V \u2192 \u00ac( U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205 )) :=\nno_open_sep_iff_no_closed_sep.mp\n\n-- (2) \u2192 (3) \nlemma two_implies_three [topological_space \u03b1] : (\u2200 U V : set \u03b1, is_closed U \u2227 is_closed V \u2192 \n\u00ac( U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205 )) \u2192 (\u2200 s : set \u03b1, frontier s = \u2205 \u2194 s = univ \u2228 s = \u2205) :=\nbegin\n  intros h1 s, apply iff.intro, assume h2,\n    have h3 : closure s \u2229 closure (- s) = \u2205, {rwa frontier_eq_closure_inter_closure at h2},\n    have h4 := closure_union_closure_compl_eq_univ,\n    have h5 := h1 (closure s) (closure (-s)) \u27e8by simp, by simp\u27e9, simp at h5 h4 h3,\n    by exact or.elim (neq_empty_imp_empty_to_union (h5 h4 h3))\n      (assume a1, have a2 : s \u2286 \u2205, {rw [\u2190a1], by exact subset_closure},\n        by exact or.inr (eq_empty_of_subset_empty a2))\n      (assume a1,\n        have a2 : -s = \u2205 := eq_empty_of_subset_empty \n          (by {rw [\u2190closure_compl_eq] at a1, rw [\u2190a1], by exact subset_closure}),\n        by exact or.inl \n          (by {have b1 : -(-s) = -\u2205, {rw [\u2190a2]}, simp at b1, assumption})),\n  by exact trivial_imp_empty_frontier,\nend\n\n-- (3) \u2192 (4)\nlemma three_implies_four [topological_space \u03b1] : (\u2200 s : set \u03b1, frontier s = \u2205 \u2194 s = univ \u2228 s = \u2205) \n\u2192  (\u2200 s : set \u03b1, is_clopen s \u2192 (s = univ \u2228 s = \u2205)) := \nby {intros H s, rw [\u2190empty_frontier_iff_clopen], by exact (H s).mp}\n\n-- (4) \u2192 (5)  \nlemma four_implies_five [topological_space \u03b1] : (\u2200 s : set \u03b1, is_clopen s \u2192 (s = univ \u2228 s = \u2205)) \n\u2192 (\u2200 U V : set \u03b1, is_separated U V \u2192 \u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205)) :=\nbegin\n  intros H U V hsep hc, rw is_separated at hsep,\n  have hU := hsep.1,\n  have hV := hsep.2,\n\n  have h1 : V = -(closure U),\n    {have a1 : closure U \u222a V = univ, \n      {have b1 : U \u2286 closure U \u222a V,\n        {have c1 : U \u2286 closure U := subset_closure,\n        have c2 : closure U \u2286 closure U \u222a V := subset_union_left (closure U) V,\n        by exact subset.trans c1 c2},\n      have b2 : U \u222a V \u2286 closure U \u222a V := \n        (union_subset_iff.mpr \u27e8b1, subset_union_right (closure U) V\u27e9),\n      rwa [hc.1] at b2,\n      by exact eq_univ_of_univ_subset b2},\n    {rw [union_comm _ _] at a1, rw [inter_comm _ _] at hU,\n     by exact disjoint_and_union_univ_imp_compl a1 hU}},\n\n  have h2 : U = -(closure V),\n    {have a1 : U \u222a closure V = univ, \n      {have b1 : V \u2286 U \u222a closure V,\n        {have c1 : V \u2286 closure V := subset_closure,\n        have c2 : closure V \u2286 U \u222a closure V := subset_union_right U (closure V),\n        by exact subset.trans c1 c2},\n      have b2 : U \u222a V \u2286 U \u222a closure V := \n        (union_subset_iff.mpr \u27e8subset_union_left U (closure V), b1\u27e9),\n      rwa [hc.1] at b2, by exact eq_univ_of_univ_subset b2},\n    by exact disjoint_and_union_univ_imp_compl a1 hV},\n\n  have h3 : is_open U, \n    {have a1 : is_closed (closure V) := is_closed_closure, rw h2, rwa is_closed at a1},\n  have h4 : is_open V, \n    {have a1 : is_closed (closure U) := is_closed_closure, rw h1, rwa is_closed at a1},\n  \n  have h5 : U = -V := disjoint_and_union_univ_imp_compl hc.1 hc.2.1,\n  have h6 : V = -U := eq_compl_iff_compl_eq.mp h5,\n\n  have h7 : is_closed U, {rwa [is_closed,\u2190h6]},\n  have h8 : is_closed V, {rwa [is_closed,\u2190h5]},\n\n  have g1 : is_clopen U := \u27e8h3,h7\u27e9, have g2 : is_clopen V := \u27e8h4,h8\u27e9,\n\n  have g3, from H U g1,\n  have g4, from H V g2,\n\n  have UneqV : U \u2260 V, \n    {by_contradiction ac, simp at ac, have a1 := hc.2.1,\n    rw ac at a1, simp at a1, by exact absurd a1 hc.2.2.2},\n\n  have toUeqV : U = univ \u2192 V = univ \u2192 U = V, {intros a1 a2, rwa [a2]},\n\n  have g5 : U = univ \u2192 false,\n    {intro a1, by exact or.elim g4 \n      (assume b1, by exact absurd (toUeqV a1 b1) UneqV)\n      (assume b2, by exact absurd b2 hc.2.2.2)},\n\n  have g6 : U = \u2205 \u2192 false, {intro a1, by exact absurd a1 hc.2.2.1},\n  \n  by exact or.elim g3 (assume a1, by exact g5 a1) (assume a2, by exact g6 a2),\n\nend\n\n-- (5) \u2192 (6)\nlemma five_implies_six [topological_space \u03b1] : (\u2200 U V : set \u03b1, is_separated U V \u2192 \n\u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205)) \u2192 (\u2200 f : \u03b1 \u2192 bool, continuous f \u2192 \u00acfunction.surjective f) :=\nbegin\n  intros H1 f cf, by_contradiction h,\n  rw function.surjective at h, rw continuous at cf,\n\n  have h1 : X.is_open {ff}, {unfold X},\n\n  have hff' : is_open (f \u207b\u00b9' {ff}), \n    from cf {ff} (show X.is_open {ff}, {unfold X}),\n  have htt' : is_open (f \u207b\u00b9' {tt}), \n    from cf {tt} (show X.is_open {tt}, {unfold X}),\n\n  have hs : (f \u207b\u00b9' {ff}) \u222a (f \u207b\u00b9' {tt}) = @univ \u03b1,\n    begin\n      have a1 : \u2200 x, x \u2208 (f \u207b\u00b9' {ff}) \u222a (f \u207b\u00b9' {tt}),\n        begin\n          intro x, rw [mem_union], by_contradiction hx,\n          simp at hx, rw [not_or_distrib] at hx, \n          have hy, from hx.1, simp at hx,\n          by exact absurd hx.2 hy,\n        end,\n      rwa [eq_univ_iff_forall],\n    end,\n\n  have he : (f \u207b\u00b9' {ff}) \u2229 (f \u207b\u00b9' {tt}) = \u2205,\n    {have a1 : \u2200 x, x \u2209 (f \u207b\u00b9' {ff}) \u2229 (f \u207b\u00b9' {tt}), \n    by simp, by exact eq_empty_iff_forall_not_mem.mpr a1},\n       \n  have hc1 : (f \u207b\u00b9' {ff}) = -(f \u207b\u00b9' {tt}),\n    {by exact disjoint_and_union_univ_imp_compl hs he},\n\n  have hc2 : (f \u207b\u00b9' {tt}) = -(f \u207b\u00b9' {ff}),\n    {by exact eq_compl_iff_compl_eq.mp hc1},\n   \n  \n  have Hc1 : closure (f \u207b\u00b9' {ff}) = (f \u207b\u00b9' {ff}),\n    {have hclff : is_closed (f \u207b\u00b9' {ff}), {rwa [is_closed,\u2190hc2]}, \n    by exact closure_eq_of_is_closed hclff},\n  have Hc2 : closure (f \u207b\u00b9' {tt}) = (f \u207b\u00b9' {tt}),\n    {have hcltt : is_closed (f \u207b\u00b9' {tt}), {rwa [is_closed,\u2190hc1]}, \n    by exact closure_eq_of_is_closed hcltt},\n\n  have Hs : is_separated (f \u207b\u00b9' {ff}) (f \u207b\u00b9' {tt}),\n    {rw is_separated,\n    have a1 : closure (f \u207b\u00b9' {ff}) \u2229 (f \u207b\u00b9' {tt}) = \u2205, {rwa [Hc1]}, \n    have a2 : f \u207b\u00b9' {ff} \u2229 closure (f \u207b\u00b9' {tt}) = \u2205, {rwa [Hc2]},\n    by exact \u27e8a1,a2\u27e9},\n\n  have HS := H1 (f \u207b\u00b9' {ff}) (f \u207b\u00b9' {tt}) Hs,\n  simp at HS, have HS2 := neq_empty_imp_empty_to_union (HS hs he),\n\n\n\n  have P : \u2200 b : bool, f \u207b\u00b9' {b} = \u2205 \u2192 false,\n    {intros b a1, \n    have a2, from h b, \n    have a3 : \u2200 a, f a = b \u2192 a \u2208 f \u207b\u00b9' {b},\n      {intros a b1, rw [mem_preimage_eq,b1], simp},\n    have a4 : \u2203 x, x \u2208 f \u207b\u00b9' {b}, from exists.elim a2 \n      (assume x, assume hx : f x = b,\n        have hy : x \u2208 f \u207b\u00b9' {b} := a3 x hx,\n        by exact \u27e8x,hy\u27e9), \n    by exact absurd a1 (ne_empty_iff_exists_mem.mpr a4)},\n\n  by exact or.elim HS2\n    (assume a1, by exact P ff a1)\n    (assume a2, by exact P tt a2),\nend\n\n-- (6) \u2192 (1) \ndef char_map (A : set \u03b1) (x : \u03b1) : Prop := x \u2208 A\n\nnoncomputable def char_map_to_bool (A : set \u03b1) (x : \u03b1) : bool := to_bool (char_map A x) \n\nlemma six_implies_one [topological_space \u03b1] : (\u2200 f : \u03b1 \u2192 bool, \ncontinuous f \u2192 \u00acfunction.surjective f) \u2192 (\u2200 U V : set \u03b1, is_open U \u2227 is_open V \u2192 \n\u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205)) := \nbegin\n  intros H1 U V H2 HC,\n  have hcompl : U = -V := disjoint_and_union_univ_imp_compl HC.1 HC.2.1,\n  have h1 : (char_map_to_bool V) \u207b\u00b9' \u2205 = \u2205 := rfl,\n  have h2 : (char_map_to_bool V) \u207b\u00b9' univ = univ := rfl,\n\n  have h3 : (char_map_to_bool V) \u207b\u00b9' {ff} = U, \n    {have a1 : \u2200 x \u2208 U, x \u2208 (char_map_to_bool V) \u207b\u00b9' {ff},\n      {simp, intros x hx, have b1 : x \u2209 V, {rwa hcompl at hx},\n      rw [char_map_to_bool,char_map], simp, assumption}, \n    have a2 : \u2200 x \u2208 (char_map_to_bool V) \u207b\u00b9' {ff}, x \u2208 U, \n      {simp, intros x hx, rw char_map_to_bool at hx, simp at hx, \n      rw char_map at hx, by exact in_left_union_univ HC.1 hx},\n    rw [\u2190subset_def] at a1 a2, by exact subset.antisymm a2 a1},\n\n  have h4 : (char_map_to_bool V) \u207b\u00b9' {tt} = V, \n    {have a1 : \u2200 x \u2208 V, x \u2208 (char_map_to_bool V) \u207b\u00b9' {tt},\n      {simp, intros x hx,\n      rw [char_map_to_bool,char_map], simp, assumption},\n    have a2 : \u2200 x \u2208 (char_map_to_bool V) \u207b\u00b9' {tt}, x \u2208 V,    \n      {simp, intros x hx, rw char_map_to_bool at hx, \n      simp at hx, rwa char_map at hx},\n    rw [\u2190subset_def] at a1 a2, by exact subset.antisymm a2 a1}, \n\n  have g1 : is_open (char_map_to_bool V \u207b\u00b9' \u2205), {rw h1, simp},\n  have g2 : is_open (char_map_to_bool V \u207b\u00b9' univ), {rw h2, simp},\n  have g3 : is_open (char_map_to_bool V \u207b\u00b9' {ff}), {rw h3, exact H2.1},\n  have g4 : is_open (char_map_to_bool V \u207b\u00b9' {tt}), {rw h4, exact H2.2},\n\n  suffices c1 : continuous (char_map_to_bool V),\n    have j1 := H1 (char_map_to_bool V) c1, \n    rw [function.surjective, not_forall] at j1, simp at j1,\n\n    by exact exists.elim j1 \n      (assume b a1, \n      have a2 : b = ff \u2228 b = tt := bool.dichotomy b,\n      by exact or.elim a2 \n        (assume bf : b = ff, \n          have c1 : \u2200 (x : \u03b1), \u00acchar_map_to_bool V x = ff, {rwa bf at a1},\n          have c2 : \u2200 (x : \u03b1), \u00ac x \u2208 (char_map_to_bool V \u207b\u00b9' {ff}), {simp, simp at c1, assumption},\n          have c3 : \u2200 (x : \u03b1), \u00ac x \u2208 U, {rwa h3 at c2},\n          have c4 : U = \u2205 := eq_empty_iff_forall_not_mem.mpr c3,\n          by exact absurd c4 HC.2.2.1)\n        (assume bt : b = tt, \n          have c1 : \u2200 (x : \u03b1), \u00acchar_map_to_bool V x = tt, {rwa bt at a1},\n          have c2 : \u2200 (x : \u03b1), \u00ac x \u2208 (char_map_to_bool V \u207b\u00b9' {tt}), {simp, simp at c1, assumption},\n          have c3 : \u2200 (x : \u03b1), \u00ac x \u2208 V, {rwa h4 at c2},\n          have c4 : V = \u2205 := eq_empty_iff_forall_not_mem.mpr c3,\n          by exact absurd c4 HC.2.2.2)),\n\n  rw continuous,\n  have A1 : {ff} \u222a {tt} = @univ bool, \n    {rw eq_univ_iff_forall, intro b, simp, exact bool.dichotomy b},\n  have A2 : \u2200 y : bool, y \u2209 {ff} \u2192 y \u2208 {tt}, {intro y, exact in_right_union_univ A1},\n  have A3 : \u2200 y : bool, y \u2209 {tt} \u2192 y \u2208 {ff}, {intro y, exact in_left_union_univ A1},\n\n  have k1 : \u2200 s : set bool, s = \u2205 \u2228 s = univ \u2228 s = {ff} \u2228 s = {tt},\n    begin\n      intro s, by_contradiction hc, repeat {rw not_or_distrib at hc},\n      have a1 : \u2203 b1 : bool, b1 \u2208 s := not_eq_empty_iff_exists.mp hc.1,\n      have a2 : \u2203 b2 : bool, b2 \u2209 s, {by_contradiction bc,\n        simp at bc, rw [\u2190eq_univ_iff_forall] at bc, exact absurd bc hc.2.1},\n\n      have a3 : ff \u2208 s \u2192 tt \u2208 s,\n        {intros c1, have c2 := hc.2.2.1, \n        have hy : \u2203 y, y \u2208 s \u2227 y \u2260 ff, by_contradiction cy, simp at cy,\n          have hf : s = {ff}, \n            {have hy1 : \u2200 y : bool, y \u2208 s \u2192 y \u2208 {ff},\n              {intros y d1, \n                have d2 : y \u2208 {ff} \u2228 y \u2208 {tt}, \n                  {rw [\u2190mem_union _ _ _,A1], simp},\n                by exact or.elim d2 (assume e1, by exact e1) \n                (assume e2, show y \u2208 {ff}, {simp at e2, rw e2 at d1, exact absurd d1 cy})},\n            have hy2 : \u2200 y : bool, y \u2208 {ff} \u2192 y \u2208 s, {simp, assumption},\n            by exact subset.antisymm hy1 hy2},\n          by exact absurd hf c2,\n        by exact exists.elim hy\n          (assume y d1, \n          have d2 : y \u2209 {ff} \u2192 y \u2208 {tt} := A2 y,\n          have d3 : y \u2260 ff \u2192 y = tt, {rwa [mem_singleton_iff,mem_singleton_iff] at d2},\n          have d4 : y = tt := d3 d1.2, \n          have d5 : y \u2208 s := d1.1, \n          show tt \u2208 s, {rwa d4 at d5})},\n\n      have a4 : tt \u2208 s \u2192 ff \u2208 s,\n        {intros c1, have c2 := hc.2.2.2, \n        have hy : \u2203 y, y \u2208 s \u2227 y \u2260 tt, by_contradiction cy, simp at cy,\n          have hf : s = {tt}, \n            {have hy1 : \u2200 y : bool, y \u2208 s \u2192 y \u2208 {tt},\n              {intros y d1, \n                have d2 : y \u2208 {tt} \u2228 y \u2208 {ff}, \n                  {rw [or_comm,\u2190mem_union _ _ _,A1], simp},\n                by exact or.elim d2 (assume e1, by exact e1) \n                (assume e2, show y \u2208 {tt}, {simp at e2, rw e2 at d1, exact absurd d1 cy})},\n            have hy2 : \u2200 y : bool, y \u2208 {tt} \u2192 y \u2208 s, {simp, assumption},\n            by exact subset.antisymm hy1 hy2},\n          by exact absurd hf c2,\n        by exact exists.elim hy\n          (assume y d1, \n          have d2 : y \u2209 {tt} \u2192 y \u2208 {ff} := A3 y,\n          have d3 : y \u2260 tt \u2192 y = ff, {rwa [mem_singleton_iff,mem_singleton_iff] at d2},\n          have d4 : y = ff := d3 d1.2, \n          have d5 : y \u2208 s := d1.1, \n          show ff \u2208 s, {rwa d4 at d5})},\n\n      have hX : \u2200 b : bool, b = ff \u2228 b = tt, {intro b, exact (bool.dichotomy b)},\n\n      have a5 : ff \u2208 s,\n        {by exact exists.elim a1 \n          (assume b : bool, assume Hb : b \u2208 s, \n          by exact or.elim (hX b) \n            (assume s1, show ff \u2208 s, by {rwa s1 at Hb})\n            (assume s1, show ff \u2208 s, {rw s1 at Hb, by exact a4 Hb}))},\n\n      have a6 : tt \u2208 s,\n        {by exact exists.elim a1 \n          (assume b : bool, assume Hb : b \u2208 s, \n          by exact or.elim ( (or_comm _ _).mp (hX b)) \n            (assume s1, show tt \u2208 s, by {rwa s1 at Hb})\n            (assume s1, show tt \u2208 s, {rw s1 at Hb, by exact a3 Hb}))},\n      \n      have a7 : \u2200 b : bool, b \u2208 s,\n        {intro b, by exact or.elim (hX b)\n          (assume k1, by {rwa [\u2190k1] at a5})\n          (assume k2, by {rwa [\u2190k2] at a6})},\n\n      rw [\u2190eq_univ_iff_forall] at a7, by exact absurd a7 hc.2.1,\n\n    end,\n\n  intros s Hs, \n\n  have B1 : s = \u2205 \u2192 is_open (char_map_to_bool V \u207b\u00b9' s), {intro h, rwa h},\n  have B2 : s = univ \u2192 is_open (char_map_to_bool V \u207b\u00b9' s), {intro h, rwa h},\n  have B3 : s = {ff} \u2192 is_open (char_map_to_bool V \u207b\u00b9' s), {intro h, rwa h},\n  have B4 : s = {tt} \u2192 is_open (char_map_to_bool V \u207b\u00b9' s), {intro h, rwa h},\n\n  by exact or.elim (k1 s)\n    (assume b1 : s = \u2205, by exact B1 b1)\n    (assume b2 : s = univ \u2228 s = {ff} \u2228 s = {tt}, \n      by exact or.elim b2\n        (assume c1 : s = univ, by exact B2 c1)\n        (assume c2 : s = {ff} \u2228 s = {tt}, \n          by exact or.elim c2\n            (assume d1 : s = {ff}, by exact B3 d1)\n            (assume d2 : s = {tt}, by exact B4 d2))),\nend\n\n\n------------------------------------------------------------\n/- Alternate definitions of connected, proved to be \nequivalent to the chosen clopen_trivial definition. -/\n\n\n-- 4.\ntheorem connected_def_empty_frontier_iff_trivial [c : connected_space \u03b1] : \n\u2200 s : set \u03b1, frontier s = \u2205 \u2194 s = univ \u2228 s = \u2205 := \nbegin\n  intro s, apply iff.intro, \n  assume h1,\n    have A : is_clopen s, from (empty_frontier_iff_clopen s).mp h1,\n    exact connected_space.clopen_trivial _ A, \n  assume h2, \n    have B : is_clopen s, \n\n    have G : s = univ \u2192 is_clopen s,\n      assume B1 : s = univ, rw B1, exact \u27e8is_open_univ,is_closed_univ\u27e9,\n    have H : s = \u2205 \u2192 is_clopen s,\n      assume B1 : s = \u2205, rw B1, exact \u27e8is_open_empty,is_closed_empty\u27e9,\n    exact or.elim h2 G H,\n  rwa [empty_frontier_iff_clopen],  \nend\n\ntheorem empty_frontier_iff_trivial_to_connected [topological_space \u03b1]\n(hs : \u2200 s : set \u03b1, frontier s = \u2205 \u2194 s = univ \u2228 s = \u2205) : connected_space \u03b1 :=\nbegin\n  have h1 : \u2200 s : set \u03b1, is_clopen s \u2192 s = univ \u2228 s = \u2205,\n    {assume s, by exact (iff.trans (iff.symm (empty_frontier_iff_clopen s)) (hs s)).mp},\n    by exact connected_space.mk h1,\nend\n\n\n\n-- 1.\ntheorem connected_def_no_open_separation [c : connected_space \u03b1] : \u2200 U V : set \u03b1, \nis_open U \u2227 is_open V \u2192 \u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205) := \nbegin\n  intros U V H,\n  by_contradiction h, \n  have A, from components_of_separation_clopen H.1 H.2 h,\n  have A1, from A.1, have A2, from A.2,\n  rw [\u2190empty_frontier_iff_clopen] at A1 A2, \n  rw [connected_def_empty_frontier_iff_trivial] at A1 A2,\n  have h2, from h.2.1, \n  have H1 : U = univ \u2192 false,\n    begin\n      assume B1, \n      rw [B1, univ_inter] at h2, \n      apply absurd h2 h.2.2.2,\n    end,\n   exact or.elim A1 H1 (assume B2 : U = \u2205, absurd B2 h.2.2.1),\nend\n\ntheorem connected_def_no_open_separation2 [c : connected_space \u03b1] (U V : set \u03b1) \n(hU : is_open U) (hV : is_open V) (hunion : U \u222a V = univ) (hinter : U \u2229 V = \u2205)\n: (U = \u2205 \u2228 V = \u2205) := \nbegin\n  by_contradiction h, \n  have A, from components_of_separation_clopen2 hU hV hunion hinter (not_or_distrib.mp h).1 (not_or_distrib.mp h).2,\n  have H1 : U = univ \u2192 false,\n    {assume B, rw [B, univ_inter] at hinter, apply absurd hinter (not_or_distrib.mp h).2},\n  exact or.elim ((connected_def_empty_frontier_iff_trivial _ ).mp ((empty_frontier_iff_clopen _ ).mpr A.1))\n    H1 (assume B : U = \u2205, absurd B (not_or_distrib.mp h).1),\nend\n\ntheorem no_open_separation_to_connected [topological_space \u03b1] (H : \u2200 U V : set \u03b1, \nis_open U \u2227 is_open V \u2192 \u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205)) : connected_space \u03b1 :=\nbegin\n  by exact empty_frontier_iff_trivial_to_connected (two_implies_three (one_implies_two H)),\nend\n\n\n\n-- 2.\ntheorem connected_def_no_closed_separation [c : connected_space \u03b1] : \u2200 U V : set \u03b1, \nis_closed U \u2227 is_closed V \u2192 \u00ac( U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205 ) :=\nbegin\n  exact no_open_sep_iff_no_closed_sep.mp connected_def_no_open_separation, \nend\n\ntheorem no_closed_separation_to_connected [topological_space \u03b1] (H : \u2200 U V : set \u03b1, \nis_closed U \u2227 is_closed V \u2192 \u00ac( U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205 )) :\nconnected_space \u03b1 :=\nbegin\n  by exact empty_frontier_iff_trivial_to_connected (two_implies_three H),\nend\n\n\n\n-- 3. clopen_trivial, chosen to be the definition of connected\n\n\n\n-- 5.\ntheorem connected_def_separated_sets [c : connected_space \u03b1] : \u2200 U V : set \u03b1,\nis_separated U V \u2192 \u00ac( U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205 ) :=\nbegin\n  intros U V hsep hc, rw is_separated at hsep,\n  have hU := hsep.1,\n  have hV := hsep.2,\n\n  have h1 : V = -(closure U),\n    {have a1 : closure U \u222a V = univ, \n      {have b1 : U \u2286 closure U \u222a V,\n        {have c1 : U \u2286 closure U := subset_closure,\n        have c2 : closure U \u2286 closure U \u222a V := subset_union_left (closure U) V,\n        by exact subset.trans c1 c2},\n      have b2 : U \u222a V \u2286 closure U \u222a V := \n        (union_subset_iff.mpr \u27e8b1, subset_union_right (closure U) V\u27e9),\n      rwa [hc.1] at b2,\n      by exact eq_univ_of_univ_subset b2},\n    {rw [union_comm _ _] at a1, rw [inter_comm _ _] at hU,\n     by exact disjoint_and_union_univ_imp_compl a1 hU}},\n\n  have h2 : U = -(closure V),\n    {have a1 : U \u222a closure V = univ, \n      {have b1 : V \u2286 U \u222a closure V,\n        {have c1 : V \u2286 closure V := subset_closure,\n        have c2 : closure V \u2286 U \u222a closure V := subset_union_right U (closure V),\n        by exact subset.trans c1 c2},\n      have b2 : U \u222a V \u2286 U \u222a closure V := \n        (union_subset_iff.mpr \u27e8subset_union_left U (closure V), b1\u27e9),\n      rwa [hc.1] at b2, by exact eq_univ_of_univ_subset b2},\n    by exact disjoint_and_union_univ_imp_compl a1 hV},\n\n  have h3 : is_open U, \n    {have a1 : is_closed (closure V) := is_closed_closure, rw h2, rwa is_closed at a1},\n  have h4 : is_open V, \n    {have a1 : is_closed (closure U) := is_closed_closure, rw h1, rwa is_closed at a1},\n  \n  have h5 : U = -V := disjoint_and_union_univ_imp_compl hc.1 hc.2.1,\n  have h6 : V = -U := eq_compl_iff_compl_eq.mp h5,\n\n  have h7 : is_closed U, {rwa [is_closed,\u2190h6]},\n  have h8 : is_closed V, {rwa [is_closed,\u2190h5]},\n\n  have g1 : is_clopen U := \u27e8h3,h7\u27e9, have g2 : is_clopen V := \u27e8h4,h8\u27e9,\n\n  have g3, from connected_space.clopen_trivial U g1,\n  have g4, from connected_space.clopen_trivial V g2,\n\n  have UneqV : U \u2260 V, \n    {by_contradiction ac, simp at ac, have a1 := hc.2.1,\n    rw ac at a1, simp at a1, by exact absurd a1 hc.2.2.2},\n\n  have toUeqV : U = univ \u2192 V = univ \u2192 U = V, {intros a1 a2, rwa [a2]},\n\n  have g5 : U = univ \u2192 false,\n    {intro a1, by exact or.elim g4 \n      (assume b1, by exact absurd (toUeqV a1 b1) UneqV)\n      (assume b2, by exact absurd b2 hc.2.2.2)},\n\n  have g6 : U = \u2205 \u2192 false, {intro a1, by exact absurd a1 hc.2.2.1},\n  \n  by exact or.elim g3 (assume a1, by exact g5 a1) (assume a2, by exact g6 a2),\n\nend\n\ntheorem separated_sets_to_connected [topological_space \u03b1]\n(H : \u2200 U V : set \u03b1, is_separated U V \u2192 \u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205)) : \nconnected_space \u03b1 :=\nbegin\n  by exact empty_frontier_iff_trivial_to_connected \n  (two_implies_three (one_implies_two (six_implies_one (five_implies_six H)))),\nend\n\n\n\n\n-- 6. \ntheorem connected_def_cts_to_discrete [connected_space \u03b1] :\n\u2200 f : \u03b1 \u2192 bool, continuous f \u2192 \u00acfunction.surjective f :=\nbegin\n  intros f cf, by_contradiction h,\n  rw function.surjective at h, rw continuous at cf,\n\n  have s1 : X.is_open {ff}, {unfold X},\n\n  have hff' : is_open (f \u207b\u00b9' {ff}), \n    from cf {ff} (show X.is_open {ff}, {unfold X}),\n  have htt' : is_open (f \u207b\u00b9' {tt}), \n    from cf {tt} (show X.is_open {tt}, {unfold X}),\n\n  have hs : (f \u207b\u00b9' {ff}) \u222a (f \u207b\u00b9' {tt}) = @univ \u03b1,\n    begin\n      have a1 : \u2200 x, x \u2208 (f \u207b\u00b9' {ff}) \u222a (f \u207b\u00b9' {tt}),\n        begin\n          intro x, rw [mem_union], by_contradiction hx,\n          simp at hx, rw [not_or_distrib] at hx, \n          have hy, from hx.1, simp at hx,\n          by exact absurd hx.2 hy,\n        end,\n      rwa [eq_univ_iff_forall],\n    end,\n\n  have he : (f \u207b\u00b9' {ff}) \u2229 (f \u207b\u00b9' {tt}) = \u2205,\n    {have a1 : \u2200 x, x \u2209 (f \u207b\u00b9' {ff}) \u2229 (f \u207b\u00b9' {tt}), \n    by simp, by exact eq_empty_iff_forall_not_mem.mpr a1},\n       \n  have hc1 : (f \u207b\u00b9' {ff}) = -(f \u207b\u00b9' {tt}),\n    {by exact disjoint_and_union_univ_imp_compl hs he},\n\n  have hc2 : (f \u207b\u00b9' {tt}) = -(f \u207b\u00b9' {ff}),\n    {by exact eq_compl_iff_compl_eq.mp hc1},\n   \n  \n  have Hc1 : closure (f \u207b\u00b9' {ff}) = (f \u207b\u00b9' {ff}),\n    {have hclff : is_closed (f \u207b\u00b9' {ff}), {rwa [is_closed,\u2190hc2]}, \n    by exact closure_eq_of_is_closed hclff},\n  have Hc2 : closure (f \u207b\u00b9' {tt}) = (f \u207b\u00b9' {tt}),\n    {have hcltt : is_closed (f \u207b\u00b9' {tt}), {rwa [is_closed,\u2190hc1]}, \n    by exact closure_eq_of_is_closed hcltt},\n\n  have Hs : is_separated (f \u207b\u00b9' {ff}) (f \u207b\u00b9' {tt}),\n    {rw is_separated,\n    have a1 : closure (f \u207b\u00b9' {ff}) \u2229 (f \u207b\u00b9' {tt}) = \u2205, {rwa [Hc1]}, \n    have a2 : f \u207b\u00b9' {ff} \u2229 closure (f \u207b\u00b9' {tt}) = \u2205, {rwa [Hc2]},\n    by exact \u27e8a1,a2\u27e9},\n\n  have HS := connected_def_separated_sets (f \u207b\u00b9' {ff}) (f \u207b\u00b9' {tt}) Hs,\n  simp at HS, have HS2 := neq_empty_imp_empty_to_union (HS hs he),\n\n  have P : \u2200 b : bool, f \u207b\u00b9' {b} = \u2205 \u2192 false,\n    {intros b a1, \n    have a2, from h b, \n    have a3 : \u2200 a, f a = b \u2192 a \u2208 f \u207b\u00b9' {b},\n      {intros a b1, rw [mem_preimage_eq,b1], simp},\n    have a4 : \u2203 x, x \u2208 f \u207b\u00b9' {b}, from exists.elim a2 \n      (assume x, assume hx : f x = b,\n        have hy : x \u2208 f \u207b\u00b9' {b} := a3 x hx,\n        by exact \u27e8x,hy\u27e9), \n    by exact absurd a1 (ne_empty_iff_exists_mem.mpr a4)},\n\n  by exact or.elim HS2\n    (assume a1, by exact P ff a1)\n    (assume a2, by exact P tt a2),\nend\n\ntheorem cts_to_discrete_to_connected [topological_space \u03b1] \n(H : \u2200 f : \u03b1 \u2192 bool, continuous f \u2192 \u00acfunction.surjective f) : connected_space \u03b1 :=\nbegin\n  by exact empty_frontier_iff_trivial_to_connected \n  (two_implies_three (one_implies_two (six_implies_one H))),\nend\n\n\n\n\n------------------------------------------------------------\n\n\nlemma subset_inter_empty_right {A B C : set \u03b1} (H1 : A \u2286 B \u222a C) (H2 : A \u2229 B = \u2205) :\nA \u2286 C := \nbegin\n  rw [subset_def] at H1, rw subset_def, intros x hx,\n  by exact or.elim (mem_or_mem_of_mem_union (H1 x hx))\n    (assume a1, by exact absurd a1 (not_in_right_union_empty H2 hx)) (by simp)\nend \n\nlemma subset_inter_empty_left {A B C : set \u03b1} (H1 : A \u2286 B \u222a C) (H2 : A \u2229 C = \u2205) :\nA \u2286 B := \nbegin\n  rw [subset_def] at H1, rw subset_def, intros x hx,\n  by exact or.elim (mem_or_mem_of_mem_union (H1 x hx))\n    (by simp) (assume a1, by exact absurd a1 (not_in_right_union_empty H2 hx))\nend \n\nlemma subsets_of_disjoint {A B C D : set \u03b1} (H1 : A \u2286 C) (H2 : B \u2286 D) (H3 : C \u2229 D = \u2205) :\nA \u2229 B = \u2205 := \nby {have H4 := inter_subset_inter H1 H2, rw [H3] at H4, exact eq_empty_of_subset_empty H4}\n\nlemma inter_union_empty_eq_union_empty_left {A B C D : set \u03b1} (H1 : A \u2229 (C \u222a D) = \u2205) (H2 : A \u222a B = C \u222a D) :\nA = \u2205 := by {rw [\u2190H2] at H1, simp at H1, assumption}\n\nlemma inter_union_empty_eq_union_empty_right {A B C D : set \u03b1} (H1 : B \u2229 (C \u222a D) = \u2205) (H2 : A \u222a B = C \u222a D) :\nB = \u2205 := by {rw [\u2190H2] at H1, simp at H1, assumption}\n\nlemma inter_union_lemma_1 {A B C : set \u03b1} (H1 : A \u2229 B = \u2205) (H2 : A \u2229 C = \u2205) :\nA \u2229 (B \u222a C) = \u2205 := by {rw [inter_distrib_left,H1,H2], simp}\n\nlemma inter_eq_comm {A B C : set \u03b1} (H1 : A \u2229 B = C) : B \u2229 A = C := by {rwa inter_comm}\n\n\ntheorem is_connected_pairwise_union [topological_space \u03b1] {A B : set \u03b1} :\nis_connected A \u2227 is_connected B \u2192 (A \u2229 B \u2260 \u2205) \u2192 is_connected (A \u222a B) := \nbegin\n  intros hc hn, rw is_connected, intros U' V' huv h,  \n\n  have T1 : A \u2286 U' \u222a V', {rw h.1, simp},\n  have T2 : B \u2286 U' \u222a V', {rw h.1, simp},\n\n  have hA := eq_union_of_inter_if_subseteq T1,\n  have hB := eq_union_of_inter_if_subseteq T2,\n\n  have pA2, from hc.1 (A \u2229 U') (A \u2229 V') \n    \u27e8sub_union_open_to_open_inter_left huv.1,sub_union_open_to_open_inter_left huv.2\u27e9, \n  have pB2, from hc.2 (B \u2229 U') (B \u2229 V') \n    \u27e8sub_union_open_to_open_inter_right huv.1,sub_union_open_to_open_inter_right huv.2\u27e9, \n\n  simp at pA2, simp at pB2, rw eq_comm at hA hB,\n\n  have wA1 : \u00acA \u2229 U' = \u2205 \u2192 A \u2229 V' = \u2205, from pA2 hA (inter_empty_distrib h.2.1),\n  have wB1 : \u00acB \u2229 U' = \u2205 \u2192 B \u2229 V' = \u2205, from pB2 hB (inter_empty_distrib h.2.1),\n  rw [inter_comm] at wA1 wB1,\n  have v1 : \u00acU' \u2229 A = \u2205 \u2192 V' \u2229 A = \u2205, {intro hv, have hv2, from wA1 hv, rwa [inter_comm]},\n  have v2 : \u00acU' \u2229 B = \u2205 \u2192 V' \u2229 B = \u2205, {intro hv, have hv2, from wB1 hv, rwa [inter_comm]}, \n\n  have zA : A \u2286 U' \u2228 A \u2286 V', exact or.elim (neq_empty_imp_empty_to_union v1)\n    (assume z1, by {rw inter_comm at z1, exact or.inr (subset_inter_empty_right T1 z1)})\n    (assume z2, by {rw inter_comm at z2, exact or.inl (subset_inter_empty_left T1 z2)}),\n\n  have zB : B \u2286 U' \u2228 B \u2286 V', exact or.elim (neq_empty_imp_empty_to_union v2)\n    (assume z1, by {rw inter_comm at z1, exact or.inr (subset_inter_empty_right T2 z1)})\n    (assume z2, by {rw inter_comm at z2, exact or.inl (subset_inter_empty_left T2 z2)}),\n\n  have H1 := neq_empty_imp_empty_to_union v1,\n  have H2 := neq_empty_imp_empty_to_union v2,\n\n  cases H1 with P1 P2,\n    cases H2 with P3 P4,\n      exact absurd (inter_union_empty_eq_union_empty_left (inter_union_lemma_1 P1 P3) h.1) h.2.2.1,\n      exact absurd (inter_eq_comm (subsets_of_disjoint (subset_inter_empty_left T2 (inter_eq_comm P4))\n      (subset_inter_empty_right T1 (inter_eq_comm P1)) h.2.1)) hn,\n    cases H2 with P5 P6,\n      exact absurd (subsets_of_disjoint (subset_inter_empty_left T1 (inter_eq_comm P2))\n      (subset_inter_empty_right T2 (inter_eq_comm P5)) h.2.1) hn,\n      exact absurd (inter_union_empty_eq_union_empty_right (inter_union_lemma_1 P2 P6) h.1) h.2.2.2,\nend\n\n\n\ntheorem open_in_univ_iff_open [topological_space \u03b1] {U : set \u03b1} :\nis_open U \u2194 is_open_in_subspace univ U :=\nbegin\n  apply iff.intro, \n    intro H, rw is_open_in_subspace,\n    have h1 : U = univ \u2229 U, {simp},\n    by exact exists.intro U \u27e8h1,H\u27e9,\n  intro H, rw is_open_in_subspace at H,  \n  by exact exists.elim H \n  (assume V, assume hV, show is_open U, \n  {have b1, from is_open_inter is_open_univ hV.2, rwa [hV.1]}),\nend\n\n\ntheorem connected_if_univ_connected [topological_space \u03b1] :\nis_connected (@univ \u03b1) \u2192 connected_space \u03b1 :=\nbegin\n  rw is_connected, intros H, \n  have h1 : \u2200 U V : set \u03b1, is_open U \u2227 is_open V \u2192 \u00ac(U \u222a V = univ \u2227 U \u2229 V = \u2205 \u2227 U \u2260 \u2205 \u2227 V \u2260 \u2205),  \n    {intros U V, repeat {rw [open_in_univ_iff_open]}, by exact H U V},\n  by exact no_open_separation_to_connected h1,\nend\n\n\n\ntheorem is_connected_univ [connected_space \u03b1] : is_connected (@univ \u03b1) :=\nbegin\n  rw is_connected, intros U V h1, repeat {rw [\u2190open_in_univ_iff_open] at h1},\n  by exact connected_def_no_open_separation U V h1,\nend\n\n\n\ntheorem is_connected_empty [connected_space \u03b1] : is_connected (\u2205 : set \u03b1) :=\nbegin\n  rw is_connected, intros U V h1 hc, repeat {rw is_open_in_subspace at h1},\n  have h2 : \u2200 V : set \u03b1, \u2205 \u2229 V = \u2205, {intro V, by exact empty_inter V},\n  show false, from exists.elim h1.1 (assume U1, assume hU1, have a1 : U = \u2205,\n    {rw [h2 U1] at hU1, by exact hU1.1}, by exact absurd a1 hc.2.2.1),\nend\n\n------------------------------------------------------------\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/Topology/Material/connected_spaces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7197330324545554}}
{"text": "/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\n\nimport algebra.hom.iterate\nimport data.list.cycle\nimport data.nat.prime\nimport dynamics.fixed_points.basic\n\n/-!\n# Periodic points\n\nA point `x : \u03b1` is a periodic point of `f : \u03b1 \u2192 \u03b1` of period `n` if `f^[n] x = x`.\n\n## Main definitions\n\n* `is_periodic_pt f n x` : `x` is a periodic point of `f` of period `n`, i.e. `f^[n] x = x`.\n  We do not require `n > 0` in the definition.\n* `pts_of_period f n` : the set `{x | is_periodic_pt f n x}`. Note that `n` is not required to\n  be the minimal period of `x`.\n* `periodic_pts f` : the set of all periodic points of `f`.\n* `minimal_period f x` : the minimal period of a point `x` under an endomorphism `f` or zero\n  if `x` is not a periodic point of `f`.\n* `orbit f x`: the cycle `[x, f x, f (f x), ...]` for a periodic point.\n\n## Main statements\n\nWe provide \u201cdot syntax\u201d-style operations on terms of the form `h : is_periodic_pt f n x` including\narithmetic operations on `n` and `h.map (hg : semiconj_by g f f')`. We also prove that `f`\nis bijective on each set `pts_of_period f n` and on `periodic_pts f`. Finally, we prove that `x`\nis a periodic point of `f` of period `n` if and only if `minimal_period f x | n`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Periodic_point\n\n-/\n\nopen set\n\nnamespace function\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {f fa : \u03b1 \u2192 \u03b1} {fb : \u03b2 \u2192 \u03b2} {x y : \u03b1} {m n : \u2115}\n\n/-- A point `x` is a periodic point of `f : \u03b1 \u2192 \u03b1` of period `n` if `f^[n] x = x`.\nNote that we do not require `0 < n` in this definition. Many theorems about periodic points\nneed this assumption. -/\ndef is_periodic_pt (f : \u03b1 \u2192 \u03b1) (n : \u2115) (x : \u03b1) := is_fixed_pt (f^[n]) x\n\n/-- A fixed point of `f` is a periodic point of `f` of any prescribed period. -/\nlemma is_fixed_pt.is_periodic_pt (hf : is_fixed_pt f x) (n : \u2115) : is_periodic_pt f n x :=\nhf.iterate n\n\n/-- For the identity map, all points are periodic. -/\nlemma is_periodic_id (n : \u2115) (x : \u03b1) : is_periodic_pt id n x := (is_fixed_pt_id x).is_periodic_pt n\n\n/-- Any point is a periodic point of period `0`. -/\nlemma is_periodic_pt_zero (f : \u03b1 \u2192 \u03b1) (x : \u03b1) : is_periodic_pt f 0 x := is_fixed_pt_id x\n\nnamespace is_periodic_pt\n\ninstance [decidable_eq \u03b1] {f : \u03b1 \u2192 \u03b1} {n : \u2115} {x : \u03b1} : decidable (is_periodic_pt f n x) :=\nis_fixed_pt.decidable\n\nprotected lemma is_fixed_pt (hf : is_periodic_pt f n x) : is_fixed_pt (f^[n]) x := hf\n\nprotected lemma map (hx : is_periodic_pt fa n x) {g : \u03b1 \u2192 \u03b2} (hg : semiconj g fa fb) :\n  is_periodic_pt fb n (g x) :=\nhx.map (hg.iterate_right n)\n\nlemma apply_iterate (hx : is_periodic_pt f n x) (m : \u2115) : is_periodic_pt f n (f^[m] x) :=\nhx.map $ commute.iterate_self f m\n\nprotected lemma apply (hx : is_periodic_pt f n x) : is_periodic_pt f n (f x) :=\nhx.apply_iterate 1\n\nprotected lemma add (hn : is_periodic_pt f n x) (hm : is_periodic_pt f m x) :\n  is_periodic_pt f (n + m) x :=\nby { rw [is_periodic_pt, iterate_add], exact hn.comp hm }\n\nlemma left_of_add (hn : is_periodic_pt f (n + m) x) (hm : is_periodic_pt f m x) :\n  is_periodic_pt f n x :=\nby { rw [is_periodic_pt, iterate_add] at hn, exact hn.left_of_comp hm }\n\nlemma right_of_add (hn : is_periodic_pt f (n + m) x) (hm : is_periodic_pt f n x) :\n  is_periodic_pt f m x :=\nby { rw add_comm at hn, exact hn.left_of_add hm }\n\nprotected lemma sub (hm : is_periodic_pt f m x) (hn : is_periodic_pt f n x) :\n  is_periodic_pt f (m - n) x :=\nbegin\n  cases le_total n m with h h,\n  { refine left_of_add _ hn,\n    rwa [tsub_add_cancel_of_le h] },\n  { rw [tsub_eq_zero_iff_le.mpr h],\n    apply is_periodic_pt_zero }\nend\n\nprotected lemma mul_const (hm : is_periodic_pt f m x) (n : \u2115) : is_periodic_pt f (m * n) x :=\nby simp only [is_periodic_pt, iterate_mul, hm.is_fixed_pt.iterate n]\n\nprotected lemma const_mul (hm : is_periodic_pt f m x) (n : \u2115) : is_periodic_pt f (n * m) x :=\nby simp only [mul_comm n, hm.mul_const n]\n\nlemma trans_dvd (hm : is_periodic_pt f m x) {n : \u2115} (hn : m \u2223 n) : is_periodic_pt f n x :=\nlet \u27e8k, hk\u27e9 := hn in hk.symm \u25b8 hm.mul_const k\n\nprotected lemma iterate (hf : is_periodic_pt f n x) (m : \u2115) : is_periodic_pt (f^[m]) n x :=\nbegin\n  rw [is_periodic_pt, \u2190 iterate_mul, mul_comm, iterate_mul],\n  exact hf.is_fixed_pt.iterate m\nend\n\nlemma comp {g : \u03b1 \u2192 \u03b1} (hco : commute f g) (hf : is_periodic_pt f n x) (hg : is_periodic_pt g n x) :\n  is_periodic_pt (f \u2218 g) n x :=\nby { rw [is_periodic_pt, hco.comp_iterate], exact hf.comp hg }\n\nlemma comp_lcm {g : \u03b1 \u2192 \u03b1} (hco : commute f g) (hf : is_periodic_pt f m x)\n  (hg : is_periodic_pt g n x) :\n  is_periodic_pt (f \u2218 g) (nat.lcm m n) x :=\n(hf.trans_dvd $ nat.dvd_lcm_left _ _).comp hco (hg.trans_dvd $ nat.dvd_lcm_right _ _)\n\nlemma left_of_comp {g : \u03b1 \u2192 \u03b1} (hco : commute f g) (hfg : is_periodic_pt (f \u2218 g) n x)\n  (hg : is_periodic_pt g n x) : is_periodic_pt f n x :=\nbegin\n  rw [is_periodic_pt, hco.comp_iterate] at hfg,\n  exact hfg.left_of_comp hg\nend\n\nlemma iterate_mod_apply (h : is_periodic_pt f n x) (m : \u2115) :\n  f^[m % n] x = (f^[m] x) :=\nby conv_rhs { rw [\u2190 nat.mod_add_div m n, iterate_add_apply, (h.mul_const _).eq] }\n\nprotected lemma mod (hm : is_periodic_pt f m x) (hn : is_periodic_pt f n x) :\n  is_periodic_pt f (m % n) x :=\n(hn.iterate_mod_apply m).trans hm\n\nprotected lemma gcd (hm : is_periodic_pt f m x) (hn : is_periodic_pt f n x) :\n  is_periodic_pt f (m.gcd n) x :=\nbegin\n  revert hm hn,\n  refine nat.gcd.induction m n (\u03bb n h0 hn, _) (\u03bb m n hm ih hm hn, _),\n  { rwa [nat.gcd_zero_left], },\n  { rw [nat.gcd_rec],\n    exact ih (hn.mod hm) hm }\nend\n\n/-- If `f` sends two periodic points `x` and `y` of the same positive period to the same point,\nthen `x = y`. For a similar statement about points of different periods see `eq_of_apply_eq`. -/\nlemma eq_of_apply_eq_same (hx : is_periodic_pt f n x) (hy : is_periodic_pt f n y) (hn : 0 < n)\n  (h : f x = f y) :\n  x = y :=\nby rw [\u2190 hx.eq, \u2190 hy.eq, \u2190 iterate_pred_comp_of_pos f hn, comp_app, h]\n\n/-- If `f` sends two periodic points `x` and `y` of positive periods to the same point,\nthen `x = y`. -/\nlemma eq_of_apply_eq (hx : is_periodic_pt f m x) (hy : is_periodic_pt f n y) (hm : 0 < m)\n  (hn : 0 < n) (h : f x = f y) :\n  x = y :=\n(hx.mul_const n).eq_of_apply_eq_same (hy.const_mul m) (mul_pos hm hn) h\n\nend is_periodic_pt\n\n/-- The set of periodic points of a given (possibly non-minimal) period. -/\ndef pts_of_period (f : \u03b1 \u2192 \u03b1) (n : \u2115) : set \u03b1 := {x : \u03b1 | is_periodic_pt f n x}\n\n@[simp] lemma mem_pts_of_period : x \u2208 pts_of_period f n \u2194 is_periodic_pt f n x :=\niff.rfl\n\nlemma semiconj.maps_to_pts_of_period {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) (n : \u2115) :\n  maps_to g (pts_of_period fa n) (pts_of_period fb n) :=\n(h.iterate_right n).maps_to_fixed_pts\n\nlemma bij_on_pts_of_period (f : \u03b1 \u2192 \u03b1) {n : \u2115} (hn : 0 < n) :\n  bij_on f (pts_of_period f n) (pts_of_period f n) :=\n\u27e8(commute.refl f).maps_to_pts_of_period n,\n  \u03bb x hx y hy hxy, hx.eq_of_apply_eq_same hy hn hxy,\n  \u03bb x hx, \u27e8f^[n.pred] x, hx.apply_iterate _,\n    by rw [\u2190 comp_app f, comp_iterate_pred_of_pos f hn, hx.eq]\u27e9\u27e9\n\nlemma directed_pts_of_period_pnat (f : \u03b1 \u2192 \u03b1) : directed (\u2286) (\u03bb n : \u2115+, pts_of_period f n) :=\n\u03bb m n, \u27e8m * n, \u03bb x hx, hx.mul_const n, \u03bb x hx, hx.const_mul m\u27e9\n\n/-- The set of periodic points of a map `f : \u03b1 \u2192 \u03b1`. -/\ndef periodic_pts (f : \u03b1 \u2192 \u03b1) : set \u03b1 := {x : \u03b1 | \u2203 n > 0, is_periodic_pt f n x}\n\nlemma mk_mem_periodic_pts (hn : 0 < n) (hx : is_periodic_pt f n x) :\n  x \u2208 periodic_pts f :=\n\u27e8n, hn, hx\u27e9\n\nlemma mem_periodic_pts : x \u2208 periodic_pts f \u2194 \u2203 n > 0, is_periodic_pt f n x := iff.rfl\n\nlemma is_periodic_pt_of_mem_periodic_pts_of_is_periodic_pt_iterate (hx : x \u2208 periodic_pts f)\n  (hm : is_periodic_pt f m (f^[n] x)) : is_periodic_pt f m x :=\nbegin\n  rcases hx with \u27e8r, hr, hr'\u27e9,\n  convert (hm.apply_iterate ((n / r + 1) * r - n)).eq,\n  suffices : n \u2264 (n / r + 1) * r,\n  { rw [\u2190iterate_add_apply, nat.sub_add_cancel this, iterate_mul, (hr'.iterate _).eq] },\n  rw [add_mul, one_mul],\n  exact (nat.lt_div_mul_add hr).le\nend\n\nvariable (f)\n\nlemma bUnion_pts_of_period : (\u22c3 n > 0, pts_of_period f n) = periodic_pts f :=\nset.ext $ \u03bb x, by simp [mem_periodic_pts]\n\nlemma Union_pnat_pts_of_period : (\u22c3 n : \u2115+, pts_of_period f n) = periodic_pts f :=\nsupr_subtype.trans $ bUnion_pts_of_period f\n\nlemma bij_on_periodic_pts : bij_on f (periodic_pts f) (periodic_pts f) :=\nUnion_pnat_pts_of_period f \u25b8\n  bij_on_Union_of_directed (directed_pts_of_period_pnat f) (\u03bb i, bij_on_pts_of_period f i.pos)\n\nvariable {f}\n\nlemma semiconj.maps_to_periodic_pts {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) :\n  maps_to g (periodic_pts fa) (periodic_pts fb) :=\n\u03bb x \u27e8n, hn, hx\u27e9, \u27e8n, hn, hx.map h\u27e9\n\nopen_locale classical\n\nnoncomputable theory\n\n/-- Minimal period of a point `x` under an endomorphism `f`. If `x` is not a periodic point of `f`,\nthen `minimal_period f x = 0`. -/\ndef minimal_period (f : \u03b1 \u2192 \u03b1) (x : \u03b1) :=\nif h : x \u2208 periodic_pts f then nat.find h else 0\n\nlemma is_periodic_pt_minimal_period (f : \u03b1 \u2192 \u03b1) (x : \u03b1) : is_periodic_pt f (minimal_period f x) x :=\nbegin\n  delta minimal_period,\n  split_ifs with hx,\n  { exact (nat.find_spec hx).snd },\n  { exact is_periodic_pt_zero f x }\nend\n\n@[simp] lemma iterate_minimal_period : f^[minimal_period f x] x = x :=\nis_periodic_pt_minimal_period f x\n\n@[simp] lemma iterate_add_minimal_period_eq : f^[n + minimal_period f x] x = (f^[n] x) :=\nby { rw iterate_add_apply, congr, exact is_periodic_pt_minimal_period f x }\n\n@[simp] lemma iterate_mod_minimal_period_eq : f^[n % minimal_period f x] x = (f^[n] x) :=\n(is_periodic_pt_minimal_period f x).iterate_mod_apply n\n\nlemma minimal_period_pos_of_mem_periodic_pts (hx : x \u2208 periodic_pts f) :\n  0 < minimal_period f x :=\nby simp only [minimal_period, dif_pos hx, (nat.find_spec hx).fst.lt]\n\nlemma minimal_period_eq_zero_of_nmem_periodic_pts (hx : x \u2209 periodic_pts f) :\n  minimal_period f x = 0 :=\nby simp only [minimal_period, dif_neg hx]\n\nlemma is_periodic_pt.minimal_period_pos (hn : 0 < n) (hx : is_periodic_pt f n x) :\n  0 < minimal_period f x :=\nminimal_period_pos_of_mem_periodic_pts $ mk_mem_periodic_pts hn hx\n\nlemma minimal_period_pos_iff_mem_periodic_pts :\n  0 < minimal_period f x \u2194 x \u2208 periodic_pts f :=\n\u27e8not_imp_not.1 $ \u03bb h,\n  by simp only [minimal_period, dif_neg h, lt_irrefl 0, not_false_iff],\n  minimal_period_pos_of_mem_periodic_pts\u27e9\n\nlemma minimal_period_eq_zero_iff_nmem_periodic_pts : minimal_period f x = 0 \u2194 x \u2209 periodic_pts f :=\nby rw [\u2190minimal_period_pos_iff_mem_periodic_pts, not_lt, nonpos_iff_eq_zero]\n\nlemma is_periodic_pt.minimal_period_le (hn : 0 < n) (hx : is_periodic_pt f n x) :\n  minimal_period f x \u2264 n :=\nbegin\n  rw [minimal_period, dif_pos (mk_mem_periodic_pts hn hx)],\n  exact nat.find_min' (mk_mem_periodic_pts hn hx) \u27e8hn, hx\u27e9\nend\n\nlemma minimal_period_apply_iterate (hx : x \u2208 periodic_pts f) (n : \u2115) :\n  minimal_period f (f^[n] x) = minimal_period f x :=\nbegin\n  apply (is_periodic_pt.minimal_period_le (minimal_period_pos_of_mem_periodic_pts hx) _).antisymm\n    ((is_periodic_pt_of_mem_periodic_pts_of_is_periodic_pt_iterate hx\n      (is_periodic_pt_minimal_period f _)).minimal_period_le\n    (minimal_period_pos_of_mem_periodic_pts _)),\n  { exact (is_periodic_pt_minimal_period f x).apply_iterate n, },\n  { rcases hx with \u27e8m, hm, hx\u27e9,\n    exact \u27e8m, hm, hx.apply_iterate n\u27e9 }\nend\n\nlemma minimal_period_apply (hx : x \u2208 periodic_pts f) :\n  minimal_period f (f x) = minimal_period f x :=\nminimal_period_apply_iterate hx 1\n\nlemma le_of_lt_minimal_period_of_iterate_eq {m n : \u2115} (hm : m < minimal_period f x)\n  (hmn : f^[m] x = (f^[n] x)) : m \u2264 n :=\nbegin\n  by_contra' hmn',\n  rw [\u2190nat.add_sub_of_le hmn'.le, add_comm, iterate_add_apply] at hmn,\n  exact ((is_periodic_pt.minimal_period_le (tsub_pos_of_lt hmn')\n    (is_periodic_pt_of_mem_periodic_pts_of_is_periodic_pt_iterate\n    (minimal_period_pos_iff_mem_periodic_pts.1 ((zero_le m).trans_lt hm)) hmn)).trans\n    (nat.sub_le m n)).not_lt hm\nend\n\nlemma eq_of_lt_minimal_period_of_iterate_eq {m n : \u2115} (hm : m < minimal_period f x)\n  (hn : n < minimal_period f x) (hmn : f^[m] x = (f^[n] x)) : m = n :=\n(le_of_lt_minimal_period_of_iterate_eq hm hmn).antisymm\n  (le_of_lt_minimal_period_of_iterate_eq hn hmn.symm)\n\nlemma eq_iff_lt_minimal_period_of_iterate_eq {m n : \u2115} (hm : m < minimal_period f x)\n  (hn : n < minimal_period f x) : f^[m] x = (f^[n] x) \u2194 m = n :=\n\u27e8eq_of_lt_minimal_period_of_iterate_eq hm hn, congr_arg _\u27e9\n\nlemma minimal_period_id : minimal_period id x = 1 :=\n((is_periodic_id _ _ ).minimal_period_le nat.one_pos).antisymm\n  (nat.succ_le_of_lt ((is_periodic_id _ _ ).minimal_period_pos nat.one_pos))\n\nlemma is_fixed_point_iff_minimal_period_eq_one : minimal_period f x = 1 \u2194 is_fixed_pt f x :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rw \u2190 iterate_one f,\n    refine function.is_periodic_pt.is_fixed_pt _,\n    rw \u2190 h,\n    exact is_periodic_pt_minimal_period f x },\n  { exact ((h.is_periodic_pt 1).minimal_period_le nat.one_pos).antisymm\n      (nat.succ_le_of_lt ((h.is_periodic_pt 1).minimal_period_pos nat.one_pos)) }\nend\n\nlemma is_periodic_pt.eq_zero_of_lt_minimal_period (hx : is_periodic_pt f n x)\n  (hn : n < minimal_period f x) : n = 0 :=\neq.symm $ (eq_or_lt_of_le $ n.zero_le).resolve_right $ \u03bb hn0,\nnot_lt.2 (hx.minimal_period_le hn0) hn\n\nlemma not_is_periodic_pt_of_pos_of_lt_minimal_period :\n  \u2200 {n : \u2115} (n0 : n \u2260 0) (hn : n < minimal_period f x), \u00ac is_periodic_pt f n x\n| 0 n0 _ := (n0 rfl).elim\n| (n + 1) _ hn := \u03bb hp, nat.succ_ne_zero _ (hp.eq_zero_of_lt_minimal_period hn)\n\nlemma is_periodic_pt.minimal_period_dvd (hx : is_periodic_pt f n x) : minimal_period f x \u2223 n :=\n(eq_or_lt_of_le $ n.zero_le).elim (\u03bb hn0, hn0 \u25b8 dvd_zero _) $ \u03bb hn0,\nnat.dvd_iff_mod_eq_zero.2 $\n(hx.mod $ is_periodic_pt_minimal_period f x).eq_zero_of_lt_minimal_period $\nnat.mod_lt _ $ hx.minimal_period_pos hn0\n\nlemma is_periodic_pt_iff_minimal_period_dvd : is_periodic_pt f n x \u2194 minimal_period f x \u2223 n :=\n\u27e8is_periodic_pt.minimal_period_dvd, \u03bb h, (is_periodic_pt_minimal_period f x).trans_dvd h\u27e9\n\nopen nat\n\nlemma minimal_period_eq_minimal_period_iff {g : \u03b2 \u2192 \u03b2} {y : \u03b2} :\n  minimal_period f x = minimal_period g y \u2194 \u2200 n, is_periodic_pt f n x \u2194 is_periodic_pt g n y :=\nby simp_rw [is_periodic_pt_iff_minimal_period_dvd, dvd_right_iff_eq]\n\nlemma minimal_period_eq_prime {p : \u2115} [hp : fact p.prime] (hper : is_periodic_pt f p x)\n  (hfix : \u00ac is_fixed_pt f x) : minimal_period f x = p :=\n(hp.out.eq_one_or_self_of_dvd _ (hper.minimal_period_dvd)).resolve_left\n  (mt is_fixed_point_iff_minimal_period_eq_one.1 hfix)\n\nlemma minimal_period_eq_prime_pow {p k : \u2115} [hp : fact p.prime] (hk : \u00ac is_periodic_pt f (p ^ k) x)\n(hk1 : is_periodic_pt f (p ^ (k + 1)) x) : minimal_period f x = p ^ (k + 1) :=\nbegin\n  apply nat.eq_prime_pow_of_dvd_least_prime_pow hp.out;\n  rwa \u2190 is_periodic_pt_iff_minimal_period_dvd\nend\n\nlemma commute.minimal_period_of_comp_dvd_lcm {g : \u03b1 \u2192 \u03b1} (h : function.commute f g) :\n  minimal_period (f \u2218 g) x \u2223 nat.lcm (minimal_period f x) (minimal_period g x) :=\nbegin\n  rw [\u2190 is_periodic_pt_iff_minimal_period_dvd],\n  exact (is_periodic_pt_minimal_period f x).comp_lcm h (is_periodic_pt_minimal_period g x)\nend\n\nlemma commute.minimal_period_of_comp_dvd_mul {g : \u03b1 \u2192 \u03b1} (h : function.commute f g) :\n  minimal_period (f \u2218 g) x \u2223 (minimal_period f x) * (minimal_period g x) :=\ndvd_trans h.minimal_period_of_comp_dvd_lcm (lcm_dvd_mul _ _)\n\nlemma commute.minimal_period_of_comp_eq_mul_of_coprime {g : \u03b1 \u2192 \u03b1} (h : function.commute f g)\n  (hco : coprime (minimal_period f x) (minimal_period g x)) :\n  minimal_period (f \u2218 g) x = (minimal_period f x) * (minimal_period g x) :=\nbegin\n  apply dvd_antisymm (h.minimal_period_of_comp_dvd_mul),\n  suffices : \u2200 {f g : \u03b1 \u2192 \u03b1}, commute f g \u2192 coprime (minimal_period f x) (minimal_period g x) \u2192\n    minimal_period f x \u2223 minimal_period (f \u2218 g) x,\n    from hco.mul_dvd_of_dvd_of_dvd (this h hco) (h.comp_eq.symm \u25b8 this h.symm hco.symm),\n  clear hco h f g,\n  intros f g h hco,\n  refine hco.dvd_of_dvd_mul_left (is_periodic_pt.left_of_comp h _ _).minimal_period_dvd,\n  { exact (is_periodic_pt_minimal_period _ _).const_mul _ },\n  { exact (is_periodic_pt_minimal_period _ _).mul_const _ }\nend\n\nprivate lemma minimal_period_iterate_eq_div_gcd_aux (h : 0 < gcd (minimal_period f x) n) :\n  minimal_period (f ^[n]) x = minimal_period f x / nat.gcd (minimal_period f x) n :=\nbegin\n  apply nat.dvd_antisymm,\n  { apply is_periodic_pt.minimal_period_dvd,\n    rw [is_periodic_pt, is_fixed_pt, \u2190 iterate_mul, \u2190 nat.mul_div_assoc _ (gcd_dvd_left _ _),\n        mul_comm, nat.mul_div_assoc _ (gcd_dvd_right _ _), mul_comm, iterate_mul],\n    exact (is_periodic_pt_minimal_period f x).iterate _ },\n  { apply coprime.dvd_of_dvd_mul_right (coprime_div_gcd_div_gcd h),\n    apply dvd_of_mul_dvd_mul_right h,\n    rw [nat.div_mul_cancel (gcd_dvd_left _ _), mul_assoc, nat.div_mul_cancel (gcd_dvd_right _ _),\n        mul_comm],\n    apply is_periodic_pt.minimal_period_dvd,\n    rw [is_periodic_pt, is_fixed_pt, iterate_mul],\n    exact is_periodic_pt_minimal_period _ _ }\nend\n\nlemma minimal_period_iterate_eq_div_gcd (h : n \u2260 0) :\n  minimal_period (f ^[n]) x = minimal_period f x / nat.gcd (minimal_period f x) n :=\nminimal_period_iterate_eq_div_gcd_aux $ gcd_pos_of_pos_right _ (nat.pos_of_ne_zero h)\n\nlemma minimal_period_iterate_eq_div_gcd' (h : x \u2208 periodic_pts f) :\n  minimal_period (f ^[n]) x = minimal_period f x / nat.gcd (minimal_period f x) n :=\nminimal_period_iterate_eq_div_gcd_aux $\n  gcd_pos_of_pos_left n (minimal_period_pos_iff_mem_periodic_pts.mpr h)\n\n/-- The orbit of a periodic point `x` of `f` is the cycle `[x, f x, f (f x), ...]`. Its length is\nthe minimal period of `x`.\n\nIf `x` is not a periodic point, then this is the empty (aka nil) cycle. -/\ndef periodic_orbit (f : \u03b1 \u2192 \u03b1) (x : \u03b1) : cycle \u03b1 :=\n(list.range (minimal_period f x)).map (\u03bb n, f^[n] x)\n\n/-- The definition of a periodic orbit, in terms of `list.map`. -/\nlemma periodic_orbit_def (f : \u03b1 \u2192 \u03b1) (x : \u03b1) :\n  periodic_orbit f x = (list.range (minimal_period f x)).map (\u03bb n, f^[n] x) :=\nrfl\n\n/-- The definition of a periodic orbit, in terms of `cycle.map`. -/\n\n\n@[simp] lemma periodic_orbit_length : (periodic_orbit f x).length = minimal_period f x :=\nby rw [periodic_orbit, cycle.length_coe, list.length_map, list.length_range]\n\n@[simp] lemma periodic_orbit_eq_nil_iff_not_periodic_pt :\n  periodic_orbit f x = cycle.nil \u2194 x \u2209 periodic_pts f :=\nby { simp [periodic_orbit], exact minimal_period_eq_zero_iff_nmem_periodic_pts }\n\nlemma periodic_orbit_eq_nil_of_not_periodic_pt (h : x \u2209 periodic_pts f) :\n  periodic_orbit f x = cycle.nil :=\nperiodic_orbit_eq_nil_iff_not_periodic_pt.2 h\n\n@[simp] lemma mem_periodic_orbit_iff (hx : x \u2208 periodic_pts f) :\n  y \u2208 periodic_orbit f x \u2194 \u2203 n, f^[n] x = y :=\nbegin\n  simp only [periodic_orbit, cycle.mem_coe_iff, list.mem_map, list.mem_range],\n  use \u03bb \u27e8a, ha, ha'\u27e9, \u27e8a, ha'\u27e9,\n  rintro \u27e8n, rfl\u27e9,\n  use [n % minimal_period f x, mod_lt _ (minimal_period_pos_of_mem_periodic_pts hx)],\n  rw iterate_mod_minimal_period_eq\nend\n\n@[simp] lemma iterate_mem_periodic_orbit (hx : x \u2208 periodic_pts f) (n : \u2115) :\n  f^[n] x \u2208 periodic_orbit f x :=\n(mem_periodic_orbit_iff hx).2 \u27e8n, rfl\u27e9\n\n@[simp] lemma self_mem_periodic_orbit (hx : x \u2208 periodic_pts f) : x \u2208 periodic_orbit f x :=\niterate_mem_periodic_orbit hx 0\n\nlemma nodup_periodic_orbit : (periodic_orbit f x).nodup :=\nbegin\n  rw [periodic_orbit, cycle.nodup_coe_iff, list.nodup_map_iff_inj_on (list.nodup_range _)],\n  intros m hm n hn hmn,\n  rw list.mem_range at hm hn,\n  rwa eq_iff_lt_minimal_period_of_iterate_eq hm hn at hmn\nend\n\nlemma periodic_orbit_apply_iterate_eq (hx : x \u2208 periodic_pts f) (n : \u2115) :\n  periodic_orbit f (f^[n] x) = periodic_orbit f x :=\neq.symm $ cycle.coe_eq_coe.2 $ \u27e8n, begin\n  apply list.ext_le _ (\u03bb m _ _, _),\n  { simp [minimal_period_apply_iterate hx] },\n  { rw list.nth_le_rotate _ n m,\n    simp [iterate_add_apply] }\nend\u27e9\n\nlemma periodic_orbit_apply_eq (hx : x \u2208 periodic_pts f) :\n  periodic_orbit f (f x) = periodic_orbit f x :=\nperiodic_orbit_apply_iterate_eq hx 1\n\ntheorem periodic_orbit_chain (r : \u03b1 \u2192 \u03b1 \u2192 Prop) {f : \u03b1 \u2192 \u03b1} {x : \u03b1} :\n  (periodic_orbit f x).chain r \u2194 \u2200 n < minimal_period f x, r (f^[n] x) (f^[n+1] x) :=\nbegin\n  by_cases hx : x \u2208 periodic_pts f,\n  { have hx' := minimal_period_pos_of_mem_periodic_pts hx,\n    have hM := nat.sub_add_cancel (succ_le_iff.2 hx'),\n    rw [periodic_orbit, \u2190cycle.map_coe, cycle.chain_map, \u2190hM, cycle.chain_range_succ],\n    refine \u27e8_, \u03bb H, \u27e8_, \u03bb m hm, H _ (hm.trans (nat.lt_succ_self _))\u27e9\u27e9,\n    { rintro \u27e8hr, H\u27e9 n hn,\n      cases eq_or_lt_of_le (lt_succ_iff.1 hn) with hM' hM',\n      { rwa [hM', hM, iterate_minimal_period] },\n      { exact H _ hM' } },\n    { rw iterate_zero_apply,\n      nth_rewrite 2 \u2190@iterate_minimal_period \u03b1 f x,\n      nth_rewrite 1 \u2190hM,\n      exact H _ (nat.lt_succ_self _) } },\n  { rw [periodic_orbit_eq_nil_of_not_periodic_pt hx,\n      minimal_period_eq_zero_of_nmem_periodic_pts hx],\n    simp }\nend\n\ntheorem periodic_orbit_chain' (r : \u03b1 \u2192 \u03b1 \u2192 Prop) {f : \u03b1 \u2192 \u03b1} {x : \u03b1} (hx : x \u2208 periodic_pts f) :\n  (periodic_orbit f x).chain r \u2194 \u2200 n, r (f^[n] x) (f^[n+1] x) :=\nbegin\n  rw periodic_orbit_chain r,\n  refine \u27e8\u03bb H n, _, \u03bb H n _, H n\u27e9,\n  rw [iterate_succ_apply, \u2190iterate_mod_minimal_period_eq],\n  nth_rewrite 1 \u2190iterate_mod_minimal_period_eq,\n  rw [\u2190iterate_succ_apply, minimal_period_apply hx],\n  exact H _ (mod_lt _ (minimal_period_pos_of_mem_periodic_pts hx))\nend\n\nend function\n\nnamespace mul_action\n\nopen function\n\nvariables {\u03b1 \u03b2 : Type*} [group \u03b1] [mul_action \u03b1 \u03b2] {a : \u03b1} {b : \u03b2}\n\n@[to_additive] lemma pow_smul_eq_iff_minimal_period_dvd {n : \u2115} :\n  a ^ n \u2022 b = b \u2194 function.minimal_period ((\u2022) a) b \u2223 n :=\nby rw [\u2190is_periodic_pt_iff_minimal_period_dvd, is_periodic_pt, is_fixed_pt, smul_iterate]\n\n@[to_additive] lemma zpow_smul_eq_iff_minimal_period_dvd {n : \u2124} :\n  a ^ n \u2022 b = b \u2194 (function.minimal_period ((\u2022) a) b : \u2124) \u2223 n :=\nbegin\n  cases n,\n  { rw [int.of_nat_eq_coe, zpow_coe_nat, int.coe_nat_dvd, pow_smul_eq_iff_minimal_period_dvd] },\n  { rw [int.neg_succ_of_nat_coe, zpow_neg, zpow_coe_nat, inv_smul_eq_iff, eq_comm,\n        dvd_neg, int.coe_nat_dvd, pow_smul_eq_iff_minimal_period_dvd] },\nend\n\nvariables (a b)\n\n@[simp, to_additive] lemma pow_smul_mod_minimal_period (n : \u2115) :\n  a ^ (n % function.minimal_period ((\u2022) a) b) \u2022 b = a ^ n \u2022 b :=\nby conv_rhs { rw [\u2190 nat.mod_add_div n (minimal_period ((\u2022) a) b), pow_add, mul_smul,\n    pow_smul_eq_iff_minimal_period_dvd.mpr (dvd_mul_right _ _)] }\n\n@[simp, to_additive] lemma zpow_smul_mod_minimal_period (n : \u2124) :\n  a ^ (n % (function.minimal_period ((\u2022) a) b : \u2124)) \u2022 b = a ^ n \u2022 b :=\nby conv_rhs { rw [\u2190 int.mod_add_div n (minimal_period ((\u2022) a) b), zpow_add, mul_smul,\n    zpow_smul_eq_iff_minimal_period_dvd.mpr (dvd_mul_right _ _)] }\n\nend mul_action\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/dynamics/periodic_pts.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7197330259619208}}
{"text": "import tuto_lib\n\n\nsection\n/-\nThe first part of this file makes sure you can negate quantified statements\nin your head without the help of `push_neg`.\n\nYou need to complete the statement and then use the `check_me` tactic\nto check your answer. This tactic exists only for those exercises,\nit mostly calls `push_neg` and then cleans up a bit.\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from \u211d to \u211d\n-- x\u2080 and l are real numbers\nvariables (u : \u2115 \u2192 \u211d) (f : \u211d \u2192 \u211d) (x\u2080 l : \u211d)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5) \u2194 (\u2203 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |u n - l| > \u03b5)\n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is continuous at x\u2080\" -/\n-- 0063\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192  |f x - f x\u2080| \u2264 \u03b5) \u2194 (\u2203 \u03b5 > 0, \u2200 \u03b4 > 0, \u2203 x, |x - x\u2080| \u2264 \u03b4 \u2227 |f x - f x\u2080| > \u03b5)\n:=\nbegin\n  check_me,\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`\u2200 x x', ...` is the abbreviation of\n`\u2200 x, \u2200 x', ... `. \n\nAlso, `\u2203 x x', ...` is the abbreviation of `\u2203 x, \u2203 x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on \u211d\" -/\n-- 0064\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x x', |x' - x| \u2264 \u03b4 \u2192  |f x' - f x| \u2264 \u03b5) \u2194 (\u2203 \u03b5 > 0, \u2200 \u03b4 > 0, \u2203 x x', |x' - x| \u2264 \u03b4 \u2227 |f x' - f x| > \u03b5)\n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is sequentially continuous at x\u2080\" -/\n-- 0065\nexample : \u00ac (\u2200 u : \u2115 \u2192 \u211d, (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b5) \u2192 (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |(f \u2218 u) n - f x\u2080| \u2264 \u03b5))  \u2194 (\u2203 u : \u2115 \u2192 \u211d, (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b5) \u2227 (\u2203 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |(f \u2218 u) n - f x\u2080| > \u03b5))\n:=\nbegin\n  check_me,\nend\nend\n\n/-\nWe now turn to elementary applications of negations to limits of sequences.\nRemember that `linarith` can find easy numerical contradictions.\n\nAlso recall the following lemmas:\n\nabs_le {x y : \u211d} : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\n/-- The sequence `u` tends to `+\u221e`. -/\ndef tendsto_infinity (u : \u2115 \u2192 \u211d) := \u2200 A, \u2203 N, \u2200 n \u2265 N, u n \u2265 A\n-/\n\n-- 0066\nexample {u : \u2115 \u2192 \u211d} : tendsto_infinity u \u2192 \u2200 l, \u00ac seq_limit u l :=\nbegin\n  intros ha l hc,\n  specialize hc 1 (by linarith),\n  specialize ha (2+l),\n  cases hc with N hN,\n  cases ha with N' hN',\n  specialize hN (max N N') (le_max_left N N'),\n  specialize hN' (max N N') (le_max_right N N'),\n  rw abs_le at hN,\n  linarith,\nend\n\ndef nondecreasing_seq (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- 0067\nexample (u : \u2115 \u2192 \u211d) (l : \u211d) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  \u2200 n, u n \u2264 l :=\nbegin\n  intro n',\n  unfold seq_limit at h,\n  unfold nondecreasing_seq at h',\n  by_contradiction H,\n  push_neg at H,\n  specialize h ((u n' - l)/2) (by linarith),\n  cases h with N hN,\n  specialize hN (max N n') (le_max_left N n'),\n  specialize h' n' (max N n') (le_max_right N n'),\n  rw abs_le at hN,\n  linarith,\nend\n\n/-\nIn the following exercises, `A : set \u211d` means that A is a set of real numbers.\nWe can use the usual notation x \u2208 A.\n\nThe notation `\u2200 x \u2208 A, ...` is the abbreviation of `\u2200 x, x \u2208 A \u2192 ... `\n\nThe notation `\u2203 x \u2208 A, ...` is the abbreviation of `\u2203 x, x \u2208 A \u2227 ... `.\nMore precisely it is the abbreviation of `\u2203 x (H : x \u2208 A), ...`\nwhich is Lean's strange way of saying `\u2203 x, x \u2208 A \u2227 ... `. \nYou can convert between these forms using the lemma \n  exists_prop {p q : Prop} : (\u2203 (h : p), q) \u2194 p \u2227 q\n\nWe'll work with upper bounds and supremums.\nAgain we'll introduce specialized definitions for the sake of exercises, but mathlib\nhas more general versions.\n\n\ndef upper_bound (A : set \u211d) (x : \u211d) := \u2200 a \u2208 A, a \u2264 x\n\ndef is_sup (A : set \u211d) (x : \u211d) := upper_bound A x \u2227 \u2200 y, upper_bound A y \u2192 x \u2264 y\n\n\nRemark: one can easily show that a set of real numbers has at most one sup,\nbut we won't need this.\n-/\n\n-- 0068\nexample {A : set \u211d} {x : \u211d} (hx : is_sup A x) :\n\u2200 y, y < x \u2192 \u2203 a \u2208 A, y < a :=\nbegin\n  intros y hy,\n  cases hx with hxa hxb,\n  by_contradiction H,\n  push_neg at H,\n  specialize hxb y,\n  have key : x \u2264 y,\n  { apply hxb,\n  exact H,},\n  linarith,\nend\n\n/-\nLet's do a variation on an example from file 07 that will be useful in the last\nexercise below.\n-/\n\n-- 0069\nlemma le_of_le_add_all' {x y : \u211d} :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  intro h,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ((y-x)/2) (by linarith),\n  linarith,\nend\n\n-- 0070\nexample {x y : \u211d} {u : \u2115 \u2192 \u211d} (hu : seq_limit u x)\n  (ineg : \u2200 n, u n \u2264 y) : x \u2264 y :=\nbegin\n  unfold seq_limit at hu,\n  apply le_of_le_add_all',\n  intros \u03b5 \u03b5_pos,\n  specialize hu \u03b5 \u03b5_pos,\n  cases hu with N hN,\n  specialize ineg N,\n  specialize hN N (by linarith),\n  rw abs_le at hN,\n  cases hN with lef righ,\n  linarith,\nend\n\n", "meta": {"author": "al-ramsey", "repo": "lean-exercises", "sha": "94d0cfb3c6055faf6254af0cd970b33278ba528c", "save_path": "github-repos/lean/al-ramsey-lean-exercises", "path": "github-repos/lean/al-ramsey-lean-exercises/lean-exercises-94d0cfb3c6055faf6254af0cd970b33278ba528c/src/exercises _live_23.01.2023/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7196788230669614}}
{"text": "import data.nat.gcd\n\nnamespace nat\n\n-- lemma gcd_eq_zero_iff {m n : \u2115} :\n-- \tm.gcd n = 0 \u2194 m = 0 \u2227 n = 0 :=\n-- \u27e8\u03bb h, \u27e8eq_zero_of_gcd_eq_zero_left h, eq_zero_of_gcd_eq_zero_right h\u27e9,\n-- \t\u03bb \u27e8hm, hn\u27e9, hn \u25b8 hm.symm \u25b8 gcd_zero_left n\u27e9\n\nlemma lcm_eq_zero_iff {m n : \u2115} :\n\tm.lcm n = 0 \u2194 m = 0 \u2228 n = 0 :=\nbegin\n\tsplit, swap,\n\t{\trintro (rfl | rfl), { rw lcm_zero_left }, rw lcm_zero_right },\n\tunfold lcm, intro h,\n\tby_contradiction hmn,\n\tpush_neg at hmn,\n\trw nat.div_eq_zero_iff at h, swap,\n\t{ apply nat.pos_of_ne_zero, simp [gcd_eq_zero_iff], intro, exact hmn.2 },\n\tapply (not_lt_of_ge _) h,\n\trw \u2190 nat.one_mul (m.gcd n),\n\tapply mul_le_mul (succ_le_of_lt $ nat.pos_of_ne_zero hmn.1) _ (zero_le _) (zero_le _),\n\tapply nat.le_of_dvd (nat.pos_of_ne_zero hmn.2) (gcd_dvd_right _ _),\nend\n\nend nat", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/imo/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7196788230669613}}
{"text": "import subgroup.cyclic\n\nnamespace mygroup\n\nopen_locale classical\n\nopen mygroup mygroup.subgroup mygroup.quotient group_hom function set\n\nnamespace torsion\n\ndef torsion_set (G : Type) [comm_group G] := { g : G | order g \u2260 0 }\n\nvariables {G : Type} [comm_group G]\n\nlemma torsion_set_def : torsion_set G = { g : G | order g \u2260 0 } := rfl\nlemma mem_torsion_set_iff (g : G) : g \u2208 torsion_set G \u2194 order g \u2260 0 := iff.rfl\n\nattribute [simp] mem_torsion_set_iff\n\nlemma one_mem_torsion_set : (1 : G) \u2208 torsion_set G :=\nby rw [mem_torsion_set_iff, order_one_eq_one]; exact one_ne_zero\n\n/-- Two elements of an abelian group with finite order multiplied is also an \n  element of finite order -/\nlemma ne_zero_order_mul_ne_zero {g h : G} \n  (hg : order g \u2260 0) (hh : order h \u2260 0) : order (g * h) \u2260 0 :=\nbegin\n  intro heq,\n  rw order_eq_zero_iff at heq,\n  rw \u2190 zero_lt_iff_ne_zero at hg hh,\n  apply heq (order g * order h), \n    { apply mul_pos; simpa only [int.coe_nat_pos] },\n    { rw [\u2190 group.mul_pow, mul_comm, group.pow_mul, pow_order_eq_one, \n          group.one_pow, mul_comm, group.pow_mul, pow_order_eq_one, \n          group.one_pow, group.mul_one] }\nend\n\nlemma mul_mem_torsion_set {g h : G} \n  (hg : g \u2208 torsion_set G) (hh : h \u2208 torsion_set G) : g * h \u2208 torsion_set G :=\nne_zero_order_mul_ne_zero hg hh\n\nlemma inv_mem_torsion_set {g : G} (hg : g \u2208 torsion_set G) : \n  g\u207b\u00b9 \u2208 torsion_set G :=\nbegin\n  intro h,\n  apply hg,\n  rw order_eq_zero_iff at h \u22a2,\n  intros n hn hgn,\n  exact h n hn \n    (by rw [\u2190 group.pow_neg_one_inv, \u2190 group.pow_mul, mul_comm, group.pow_mul, hgn]; simp),\nend\n\n/-- The torsion subgroup of an abelian group is the subgroup of all elements of \n  finite order -/\ndef torsion_subgroup (G : Type) [comm_group G] : subgroup G :=\n{ carrier := torsion_set G,\n  one_mem' := one_mem_torsion_set,\n  mul_mem' := \u03bb _ _, mul_mem_torsion_set,\n  inv_mem' := \u03bb _, inv_mem_torsion_set }\n\nlemma mem_torsion_subgroup_iff (g : G) : g \u2208 torsion_subgroup G \u2194 order g \u2260 0 := iff.rfl\n\nattribute [simp] mem_torsion_subgroup_iff\n\nend torsion\n\ndef torsion (G : Type) [comm_group G] : normal G :=\n  normal.of_comm_subgroup $ torsion.torsion_subgroup G\n\n-- Temporary (should infer from the fact that the normal subgroups form a complete lattice)\ndef normal.trivial {G : Type} [group G] : normal G := \n{ conj_mem' := \u03bb _ hn _,\n      by rw [(mem_trivial_carrier_iff _).mp hn, group.mul_one, \n        group.mul_right_inv]; exact one_mem _, .. subgroup.trivial }\n\nlemma normal.bot_eq_trivial {G : Type} [group G] : \n  (\u22a5 : normal G) = normal.trivial :=\nbegin\n  refine eq.symm (eq_bot_iff.2 $ \u03bb x hx, _),\n  change x = 1 at hx,\n  exact hx.symm \u25b8 one_mem _,\nend\n\nlemma normal.mem_bot_iff {G : Type} [group G] {x : G} : x \u2208 (\u22a5 : normal G) \u2194 x = 1 :=\nbegin \n  split, intro h,\n    { rw [\u2190 mem_singleton_iff, \u2190 bot_eq_singleton_one, bot_eq_trivial], \n      rw normal.bot_eq_trivial at h, exact h },\n    { rintro rfl, exact one_mem _ }\nend\n\nnamespace torsion\n\nvariables {G : Type} [comm_group G]\n\n@[simp] lemma mem_torsion_iff (g : G) : g \u2208 torsion G \u2194 order g \u2260 0 := iff.rfl\n\n/-- The quotient of an abelian group by its torsion subgroup is also an \n  abelian subgroup -/\ninstance : comm_group $ G /\u2098 torsion G := \n  { mul_comm := \u03bb a b,\n      let \u27e8g, hg\u27e9 := exists_mk a in\n      let \u27e8h, hh\u27e9 := exists_mk b in\n      by rw [\u2190 hg, \u2190 hh, quotient.coe_mul, group.mul_comm, \u2190 quotient.coe_mul],\n  .. show group (G /\u2098 torsion G), by apply_instance } -- french quotes does not work\n\n/-- The torsion of the quotient by the torsion is the trivial subgroup -/\nlemma of_quotient_torsion_eq_bot : torsion (G /\u2098 torsion G) = \u22a5 :=\nbegin\n  ext, rw [normal.mem_bot_iff], split,\n    { intro h, \n      rcases exists_mk g with \u27e8g, rfl\u27e9,\n      rw [\u2190 coe_one, mk_eq', group.one_inv, group.one_mul],\n      intro hg, apply h,\n      rw order_eq_zero_iff at hg \u22a2,\n      intros n hn hgn,\n      rw [coe_pow, \u2190 coe_one, mk_eq', group.one_inv, \n        group.one_mul, mem_torsion_iff, \u2190 zero_lt_iff_ne_zero] at hgn,\n      refine hg (n * order (g ^ n)) (mul_pos hn $ int.coe_nat_pos.2 hgn) _,\n      rw [mul_comm, group.pow_mul, pow_order_eq_one] },\n    { rintro rfl, exact one_mem _ }\nend\n\nend torsion\n\nend mygroup", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/src/subgroup/torsion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7196788145254206}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport ring_theory.adjoin.basic\nimport data.mv_polynomial.rename\nimport data.polynomial.algebra_map\n\n/-!\n# Adjoining elements to form subalgebras: relation to polynomials\n\nIn this file we prove a few results representing `algebra.adjoin R s` as the range of\n`mv_polynomial.aeval` or `polynomial.aeval`.\n\n## Tags\n\nadjoin, algebra, polynomials\n-/\n\nuniverses u v w\n\nnamespace algebra\n\nopen subsemiring submodule\nvariables (R : Type u) {A : Type v} (s : set A) [comm_semiring R] [comm_semiring A] [algebra R A]\n\ntheorem adjoin_eq_range :\n  adjoin R s = (mv_polynomial.aeval (coe : s \u2192 A)).range :=\nle_antisymm\n  (adjoin_le $ \u03bb x hx, \u27e8mv_polynomial.X \u27e8x, hx\u27e9, mv_polynomial.eval\u2082_X _ _ _\u27e9)\n  (\u03bb x \u27e8p, (hp : mv_polynomial.aeval coe p = x)\u27e9, hp \u25b8 mv_polynomial.induction_on p\n    (\u03bb r, by { rw [mv_polynomial.aeval_def, mv_polynomial.eval\u2082_C],\n               exact (adjoin R s).algebra_map_mem r })\n    (\u03bb p q hp hq, by rw alg_hom.map_add; exact subalgebra.add_mem _ hp hq)\n    (\u03bb p \u27e8n, hn\u27e9 hp, by rw [alg_hom.map_mul, mv_polynomial.aeval_def _ (mv_polynomial.X _),\n      mv_polynomial.eval\u2082_X]; exact subalgebra.mul_mem _ hp (subset_adjoin hn)))\n\nlemma adjoin_range_eq_range_aeval {\u03c3 : Type*} (f : \u03c3 \u2192 A) :\n  adjoin R (set.range f) = (mv_polynomial.aeval f).range :=\nbegin\n  ext x,\n  simp only [adjoin_eq_range, alg_hom.mem_range],\n  split,\n  { rintros \u27e8p, rfl\u27e9,\n    use mv_polynomial.rename (function.surj_inv (@@set.surjective_onto_range f)) p,\n    rw [\u2190 alg_hom.comp_apply],\n    refine congr_fun (congr_arg _ _) _,\n    ext,\n    simp only [mv_polynomial.rename_X, function.comp_app, mv_polynomial.aeval_X, alg_hom.coe_comp],\n    simpa [subtype.ext_iff] using function.surj_inv_eq (@@set.surjective_onto_range f) i },\n  { rintros \u27e8p, rfl\u27e9,\n    use mv_polynomial.rename (set.range_factorization f) p,\n    rw [\u2190 alg_hom.comp_apply],\n    refine congr_fun (congr_arg _ _) _,\n    ext,\n    simp only [mv_polynomial.rename_X, function.comp_app, mv_polynomial.aeval_X, alg_hom.coe_comp,\n      set.range_factorization_coe] }\nend\n\ntheorem adjoin_singleton_eq_range_aeval (x : A) : adjoin R {x} = (polynomial.aeval x).range :=\nle_antisymm\n  (adjoin_le $ set.singleton_subset_iff.2 \u27e8polynomial.X, polynomial.eval\u2082_X _ _\u27e9)\n  (\u03bb y \u27e8p, (hp : polynomial.aeval x p = y)\u27e9, hp \u25b8 polynomial.induction_on p\n    (\u03bb r, by { rw [polynomial.aeval_def, polynomial.eval\u2082_C],\n               exact (adjoin R _).algebra_map_mem r })\n    (\u03bb p q hp hq, by rw alg_hom.map_add; exact subalgebra.add_mem _ hp hq)\n    (\u03bb n r ih, by { rw [pow_succ', \u2190 mul_assoc, alg_hom.map_mul,\n      polynomial.aeval_def _ polynomial.X, polynomial.eval\u2082_X],\n      exact subalgebra.mul_mem _ ih (subset_adjoin rfl) }))\n\nend algebra\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/adjoin/polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7196788145254206}}
{"text": "import tactic.ring\nimport tactic.linarith\nimport data.rat.basic\nimport data.rat.cast\n\n/- Section\n1.4 An Application\n-/\n\n/- \nProve that there is no rational number whose square is 2 \nusing the techniques introduced earlier.\n-/\n\ndef even (a : \u2124) := \u2203 b : \u2124, a = 2 * b\ndef odd (a : \u2124) := \u2203 b : \u2124, a = 2 * b + 1\n\nlemma not_even_is_odd (n : \u2124) : \u00ac even n \u2194 odd n := \nbegin\n    split,\n    intro ha,\n    have hb : n % 2 = 1,\n        have hc : n % 2 = 0 \u2228 n % 2 = 1,\n            apply int.mod_two_eq_zero_or_one,\n        cases hc with hx hy,\n        exfalso,\n        apply ha,\n        existsi n / 2,\n        rw int.mul_div_cancel_of_mod_eq_zero hx,\n        assumption,\n    have hc : (n - 1) % 2 = 0,\n    have hd : n % 2 = 1 % 2, rw hb, refl,\n        revert hd,\n        rw int.mod_eq_mod_iff_mod_sub_eq_zero,\n        intro h, assumption,\n    existsi (n - 1) / 2,\n    rw int.mul_div_cancel_of_mod_eq_zero hc,\n    simp,\n\n    intro ha,\n    intro hb,\n    cases ha with x hx,\n    cases hb with y hy,\n    have hc : n % 2 = 1,\n        rw hx, \n        rw [add_comm, int.add_mul_mod_self_left],\n        refl,\n    have hd : n % 2 = 0,\n        rw hy, simp,\n    have he : (1 : \u2124) = (0 : \u2124),\n        rwa [\u2190hc, \u2190hd],\n    have hf : \u00ac ( (1 : \u2124) = (0 : \u2124)), simp,\n    exact hf he,\nend\n\nlemma gcdeven (n m : \u2115) : 2 \u2223 nat.gcd (2 * n) (2 * m) :=\nbegin\n    have ha : 2 \u2223 2 * n, existsi n, refl,\n    have hb : 2 \u2223 2 * m, existsi m, refl,\n    have hc : (2 \u2223 2 * n) \u2192 (2 \u2223 2 * m) \u2192 2 \u2223 nat.gcd (2 * n) (2 * m),\n    exact nat.dvd_gcd,\n    apply hc,\n    repeat {assumption},\nend\n--#check gcdeven\n\n/- Lemma\nIf $a$ is an integer, then $a$ is even if and only if $a^2$ is even.\n-/\nlemma times_even\n  (a : \u2124) : even a \u2194 even (a ^ 2) :=\nbegin\n    split,\n    intro h,\n    have ha : \u2203 b : \u2124, a = 2 * b, exact h,\n    have hb : \u2203 b : \u2124, a ^ 2 = 2 * b,\n        cases ha with x hx,\n        existsi 2 * x ^ 2,\n        rw hx,\n        ring,\n    exact hb,\n\n    intro h,\n    apply classical.by_contradiction,\n    intro ha,\n    have hc : odd a,\n        rw \u2190not_even_is_odd a,\n        assumption,\n    have hd : odd (a ^ 2),\n        cases hc with x hx,\n        existsi 2 * x ^ 2 + 2 * x,\n        rw hx,\n        ring,\n    have he : \u00ac even (a ^ 2),\n        rw not_even_is_odd (a ^ 2),\n        assumption,\n    exact he h,\nend\n\n/- Theorem\nThere is no rational number whose square is 2.\n-/\ntheorem rational_not_sqrt_two : \u00ac \u2203 r : \u211a, r ^ 2 = 2  := \nbegin\n    -- First show that p is even\n    push_neg,\n    intro r,\n    -- Manipulate the fraction to have the properties desired\n    have h : rat.mk (r.num) (r.denom) = r,\n        apply rat.num_denom,\n    rw \u2190h,\n    intro hcon,\n    -- The denominator must not be zero\n    have hdnot0 : r.denom \u2260 0,\n        intro ha,\n        have hb : rat.mk (r.num) (r.denom) ^ 2 = 0,\n            rw ha,\n            refl,\n        convert hb,\n        rw hcon,\n        simp,\n        linarith,\n    -- The numerator must also not be zero\n    have hnnot0 : r.num \u2260 0,\n        intro ha,\n            have hb : rat.mk (r.num) (r.denom) ^ 2 = 0,\n                rw ha,\n                simp, refl,\n            convert hb,\n            rw hcon,\n            simp,\n            linarith,\n    -- The fraction is in its lowest terms\n    have hcop : nat.coprime (int.nat_abs r.num) r.denom,\n        cases r with ha hb hc hd,\n        exact hd,\n    -- Now we can begin the actual proof...\n    -- First show that r.num ^ 2 is even\n    have hsqrneven : even (r.num ^ 2),\n        existsi (r.denom : \u2124) ^ 2,\n        have ha : r.num ^ 2 = r.num ^ 2 * 1,\n            simp,\n        rwa [ha, \u2190rat.mk_eq],\n        convert hcon,\n        repeat {rw pow_two},\n        rw rat.mul_def,\n        all_goals {try {simp, apply hdnot0,}},\n        simp,\n    -- Now we can use times_even to show r.num is even\n    have hneven : even r.num, rw times_even, assumption,\n    -- r.num is even \u2192 r.denom ^ 2 is also even\n    have hsqrdeven : even (r.denom ^ 2),\n        cases hneven with b ha,\n        existsi b ^ 2,\n        have hb : (2 * \u2191(r.denom) ^ 2 = 4 * (b ^ 2)) \u2192 (\u2191(r.denom) ^ 2 = 2 * b ^ 2),\n            have h\u03b2 : 4 * b ^ 2 = 2 * 2 * b ^ 2, refl,\n            rw [h\u03b2, \u2190sub_eq_zero],\n            have h\u03b3 : 2 * \u2191(r.denom) ^ 2 - 2 * 2 * b ^ 2 = 2 * (\u2191(r.denom) ^ 2 - 2 * b ^ 2), ring,\n            rw [h\u03b3, mul_eq_zero],\n            intro h\u03b4,\n            cases h\u03b4 with h\u03b41 h\u03b42,\n            exfalso,\n            convert h\u03b41, simp, linarith,\n            rw \u2190sub_eq_zero,\n            assumption,\n        rw hb,\n        have hc : 4 * b ^ 2 = (2 * b) ^ 2,\n            ring,\n        rw [hc, \u2190ha],\n    have hd : \u2191r.denom * \u2191r.denom = r.denom * r.denom, simp,\n        have he : rat.mk (r.num ^ 2) (r.denom ^ 2) = 2, \n            rw \u2190hcon, \n            repeat {rw pow_two}, \n            rw rat.mul_def,\n            repeat {simp, apply hdnot0,},\n        have hf : rat.mk r.num r.denom = r.num / r.denom, \n            exact rat.mk_eq_div (r.num) \u2191(r.denom),\n        have hg : 2 * (\u2191(r.denom) ^ 2) =  r.num ^ 2 * 1 \u2192 2 * (\u2191(r.denom) * \u2191(r.denom)) = r.num * r.num,\n            repeat {rw pow_two},\n            rw mul_one,\n            intro hh,\n            assumption,\n        rw hg,\n        rw \u2190rat.mk_eq,\n        rw he,\n        refl,\n        simp,\n        rw pow_two,\n        intro hh,\n        have hi : r.denom = 0,\n            have hj : r.denom * r.denom = 0,\n                rw \u2190hd,\n                exact_mod_cast hh,\n            rw nat.mul_eq_zero at hj,\n            revert hj,\n            simp,\n        exfalso,\n        exact hdnot0 hi,\n    have hdeven : even r.denom, rw times_even, assumption,\n    -- But that means r.num and r.denom are not coprimes\n    have hncop : \u00ac nat.coprime (int.nat_abs (r.num)) (r.denom),\n        have ha : \u00ac nat.coprime (int.nat_abs (r.num)) (r.denom) \u2194 nat.gcd (int.nat_abs (r.num)) (r.denom) \u2260 1, refl,\n        rw ha,\n        cases hneven with k hk,\n        cases hdeven with m hm,\n        rw hk,\n        have hb : int.nat_abs r.denom = 2 * (int.nat_abs m),\n            rwa [hm, int.nat_abs_mul],\n            refl,\n        have hc : (r.denom : \u2115) = int.nat_abs r.denom, refl,\n        rwa [hc, hb],\n        have hd : int.nat_abs (2 * k) = 2 * int.nat_abs k, rw int.nat_abs_mul, refl,\n        rw hd,\n        intro he,\n        have hf : \u00ac (2 \u2223 nat.gcd (2 * int.nat_abs k) (2 * int.nat_abs m)),\n            rw he,\n            simp,\n            linarith,\n        have hg : 2 \u2223 nat.gcd (2 * int.nat_abs k) (2 * int.nat_abs m),\n            apply gcdeven,\n        exact hf hg,\n    exact hncop hcop,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sets/sqrt2NotRational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7196788124410105}}
{"text": "import group_theory.group_action\nimport group_theory.quotient_group\nimport data.zmod.basic\nimport data.fintype.card\nimport group_theory.sylow\nimport tactic\n-- import algebra.group.conj\n\nopen equiv fintype finset mul_action function nat sylow\nopen subgroup quotient_group\nuniverse u\nvariables {G : Type u} [group G]\n\nopen_locale classical\n\n-- define a sylow subgroup given a prime p, and subgroup L\ndef is_sylow_subgroup [fintype G] (L : subgroup G) {p m n : \u2115} (hp : p.prime)\n(hG : card G = p ^ n * m) (hndiv: \u00ac p \u2223 m) :=\n  card L = p ^ n\n\nlemma is_sylow_subgroup_def [fintype G] (L : subgroup G) {p m n : \u2115} (hp : p.prime)\n(hG : card G = p ^ n * m) (hndiv: \u00ac p \u2223 m) : is_sylow_subgroup L hp hG hndiv \u2194 (card L = p ^ n)\n:= iff.rfl\n\n-- TODO: think about using conjugation function\n-- def conjugate (x y : G) := x\u207b\u00b9 * y * x\n\n-- give the subgroup conjugate to subgroup L by g\ndef conjugate_subgroup (L : subgroup G) (g : G) : subgroup G :=\n{ carrier := { c | \u2203 h \u2208 L, c = g\u207b\u00b9 * h * g },\n  one_mem' := \nbegin\n  exact \u27e81, one_mem L, by simp\u27e9,\nend,\n  mul_mem' := \nbegin\n  rintros - - \u27e8c, hc, rfl\u27e9 \u27e8d, hd, rfl\u27e9,\n  exact \u27e8c * d, L.mul_mem hc hd, by group\u27e9,\nend,\n  inv_mem' := \nbegin\n  simp only [and_imp, exists_prop, set.mem_set_of_eq, exists_imp_distrib],\n  intros x y hy hx,\n  refine \u27e8(g * x * g\u207b\u00b9)\u207b\u00b9, _, by group\u27e9,\n  rw [hx, mul_assoc, mul_assoc, mul_assoc, mul_inv_self, mul_one, \u2190 mul_assoc, mul_inv_self, one_mul],\n  exact inv_mem L hy,\nend }\n\nlemma conjugate_subgroup_def (L : subgroup G) (x g : G) : \n  x \u2208 conjugate_subgroup L g \u2194 x \u2208  { c | \u2203 h \u2208 L, c = g\u207b\u00b9 * h * g } := iff.rfl\n\nnoncomputable def index_of_subgroup [fintype G] (L : subgroup G) : \u2115 :=\n  card G / card L\n\nlemma index_of_subgroup_def [fintype G] (L : subgroup G) : \n  index_of_subgroup L = card G / card L := rfl\n \n-- this must already exist in mathlib - FIND IT!\nlemma card_subgroup_pos [fintype G] (L : subgroup G) : 0 < card L :=\ncard_pos_iff.2 $ nonempty.intro \u27e81, L.one_mem\u27e9\n\n-- lagranges theorem\nlemma index_of_subgroup_def' [fintype G] (L : subgroup G) :\n  index_of_subgroup L = card (quotient L) := \nbegin\n  rw [index_of_subgroup_def, card_eq_card_quotient_mul_card_subgroup L],\n  rw [nat.mul_div_assoc _ (dvd_refl (card \u21a5L)), nat.div_self (card_subgroup_pos L)],\n  simp,\nend \n\n-- this is Eric's proof, pull request 8382 quotient_group.eq_iff_coset_eq\nlemma quotient_iff_set {y z : G} {L : subgroup G}\n: @quotient_group.mk _ _ L y = quotient_group.mk z \u2194 left_coset y L = left_coset z L := \nbegin\n  rw [\u2190quotient_group.eq_class_eq_left_coset, \u2190quotient_group.eq_class_eq_left_coset],\n  rw set.ext_iff,\n  dsimp,\n  split,\n  { intros h z, \n    exact eq.congr_right h,\n    },\n  intro h, \n  exact (h y).mp rfl\nend\n\n-- think about replacing \u03bb with a conjugation function\n-- this may already exist\ndef subgroup_bijects_conjugate (L : subgroup G) (x : G) : \nconjugate_subgroup L x \u2243 L :=\n{ to_fun := (\u03bb y : conjugate_subgroup L x, \u27e8x * y * x\u207b\u00b9, \nbegin\n  rcases y with \u27e8_, z, hz, rfl\u27e9,\n  rw [subtype.coe_mk, mul_assoc, mul_assoc, mul_inv_self, mul_one, \u2190 mul_assoc, mul_inv_self, one_mul],\n  exact hz,\nend\u27e9) ,\n  inv_fun := (\u03bb y : L, \u27e8x\u207b\u00b9 * y * x, \u27e8y, set_like.coe_mem y, rfl\u27e9\u27e9),\n  left_inv := \n  begin\n    rintro \u27e8y, hy\u27e9,\n    simp only [subtype.mk_eq_mk, subtype.coe_mk],\n    group,\n  end,\n  right_inv := \n  begin\n    rintro \u27e8y, hy\u27e9,\n    simp only [subtype.mk_eq_mk, subtype.coe_mk],\n    group,\n  end }\n\n-- this index of a sylow subgroup is m\nlemma sylow_subgroup_index [fintype G] {L : subgroup G} {p m n : \u2115}\n(hp : p.prime) (hG : card G = p ^ n * m) (hndiv: \u00ac p \u2223 m) (h : is_sylow_subgroup L hp hG hndiv) \n  : index_of_subgroup L = m :=\nbegin\n  rw is_sylow_subgroup_def at h,\n  rw [index_of_subgroup_def, hG, h, nat.mul_div_cancel_left _ (pow_pos (pos_of_gt hp.left) n)],\nend\n\n-- the index of a sylow subgroup is not divisible by prime p\nlemma subgroup_index_not_conj_zero_wrt_p [fintype G] {L : subgroup G} {p m n : \u2115}\n(hp : p.prime) (hG : card G = p ^ n * m) (hndiv: \u00ac p \u2223 m) (h : is_sylow_subgroup L hp hG hndiv) \n  : \u00ac index_of_subgroup L \u2261 0 [MOD p] :=\nbegin\n  rw sylow_subgroup_index hp hG hndiv h,\n  intro hn,\n  apply hndiv,\n  exact modeq.modeq_zero_iff.mp hn,\nend\n\ntheorem sylow_two [fintype G] {p n m : \u2115} (L K : subgroup G) \n(hp : p.prime) (hG : card G = p ^ n * m) (hndiv: \u00ac p \u2223 m)\n( h\u2081 : is_sylow_subgroup L hp hG hndiv) (h\u2082 : is_sylow_subgroup K hp hG hndiv)\n: \u2203 g : G, conjugate_subgroup K g  = L :=\nbegin\n  haveI : fact (p.prime) := \u27e8 hp \u27e9,\n  have h\u2084 : index_of_subgroup L \u2261 card (fixed_points K (quotient L)) [MOD p], {\n    rw is_sylow_subgroup_def at h\u2082,\n    rw index_of_subgroup_def',\n    exact card_modeq_card_fixed_points p h\u2082,\n  },\n  have h\u2085 : 0 < card (fixed_points K (quotient L)), {\n    apply lt_of_le_of_ne _ _, {\n      exact le_of_not_gt (card \u21a5(fixed_points \u21a5K (quotient L))).not_lt_zero,\n    }, {\n      intro hn,\n      apply subgroup_index_not_conj_zero_wrt_p hp hG hndiv h\u2081,\n      rw hn,\n      exact h\u2084,\n    },\n  },\n  have h\u2086 : \u2203 x : G, (conjugate_subgroup K x : set G) \u2286 L, {\n    rw card_pos_iff at h\u2085,\n    rcases h\u2085 with \u27e8fp, hfp\u27e9,\n    rw mul_action.mem_fixed_points at hfp,\n    let x := quotient.out' fp,\n    use x,\n    rintro _ \u27e8y, hy, rfl\u27e9,\n    have h1 : y \u2022 fp = quotient_group.mk (y * x), {\n      rw \u2190 quotient.out_eq' fp,\n      exact quotient.smul_mk L y x,\n    },\n    have h2 : @quotient_group.mk _ _ L (x\u207b\u00b9 * y * x) = quotient_group.mk 1, {\n      rw [mul_assoc, \u2190 quotient.smul_mk L x\u207b\u00b9 (y * x)],\n      rw [\u2190 smul_left_cancel_iff x, smul_smul x x\u207b\u00b9 _, mul_inv_self, quotient.smul_mk, one_mul],\n      rw [quotient.smul_mk, mul_one, \u2190 h1],\n      convert hfp \u27e8y, hy\u27e9,\n      exact quotient.out_eq' fp,\n    },\n    rw [quotient_iff_set, one_left_coset] at h2,\n    rw \u2190 h2,\n    unfold left_coset,\n    simp only [mul_inv_rev, set.mem_preimage, set.image_mul_left, set_like.mem_coe, inv_inv],\n    rw [mul_assoc, mul_assoc, mul_assoc, \u2190 mul_assoc x x\u207b\u00b9 (y * x)],\n    rw [mul_inv_self, one_mul, \u2190 mul_assoc, \u2190 mul_assoc],\n    simp [mul_left_inv, inv_mul_cancel_right, one_mem L],\n  },\n  have h\u2087 : \u2200 x : G, card (conjugate_subgroup K x) = card L, {\n    rw is_sylow_subgroup_def at h\u2081 h\u2082,\n    intro x,\n    rw [h\u2081, h\u2082.symm],\n    apply fintype.card_congr,\n    exact subgroup_bijects_conjugate K x,\n  },\n  apply exists.elim h\u2086,\n  intros x hx,\n  use x,\n  rw set_like.ext'_iff,\n  exact set.eq_of_subset_of_card_le hx (h\u2087 x).ge,\nend\n", "meta": {"author": "ineswright", "repo": "Lean-Sylow", "sha": "74b99544ab1ca96dc28fbe152125f565763a893b", "save_path": "github-repos/lean/ineswright-Lean-Sylow", "path": "github-repos/lean/ineswright-Lean-Sylow/Lean-Sylow-74b99544ab1ca96dc28fbe152125f565763a893b/src/sylowtwo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7196788103566004}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n-/\n\nimport analysis.inner_product_space.projection\nimport measure_theory.function.l2_space\nimport measure_theory.decomposition.radon_nikodym\n\n/-! # Conditional expectation\n\nWe build the conditional expectation of an integrable function `f` with value in a Banach space\nwith respect to a measure `\u03bc` (defined on a measurable space structure `m0`) and a measurable space\nstructure `m` with `hm : m \u2264 m0` (a sub-sigma-algebra). This is an `m`-strongly measurable\nfunction `\u03bc[f|hm]` which is integrable and verifies `\u222b x in s, \u03bc[f|hm] x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc`\nfor all `m`-measurable sets `s`. It is unique as an element of `L\u00b9`.\n\nThe construction is done in four steps:\n* Define the conditional expectation of an `L\u00b2` function, as an element of `L\u00b2`. This is the\n  orthogonal projection on the subspace of almost everywhere `m`-measurable functions.\n* Show that the conditional expectation of the indicator of a measurable set with finite measure\n  is integrable and define a map `set \u03b1 \u2192 (E \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E))` which to a set associates a linear\n  map. That linear map sends `x \u2208 E` to the conditional expectation of the indicator of the set\n  with value `x`.\n* Extend that map to `condexp_L1_clm : (\u03b1 \u2192\u2081[\u03bc] E) \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E)`. This is done using the same\n  construction as the Bochner integral (see the file `measure_theory/integral/set_to_L1`).\n* Define the conditional expectation of a function `f : \u03b1 \u2192 E`, which is an integrable function\n  `\u03b1 \u2192 E` equal to 0 if `f` is not integrable, and equal to an `m`-measurable representative of\n  `condexp_L1_clm` applied to `[f]`, the equivalence class of `f` in `L\u00b9`.\n\n## Main results\n\nThe conditional expectation and its properties\n\n* `condexp (m : measurable_space \u03b1) (\u03bc : measure \u03b1) (f : \u03b1 \u2192 E)`: conditional expectation of `f`\n  with respect to `m`.\n* `integrable_condexp` : `condexp` is integrable.\n* `strongly_measurable_condexp` : `condexp` is `m`-strongly-measurable.\n* `set_integral_condexp (hf : integrable f \u03bc) (hs : measurable_set[m] s)` : if `m \u2264 m0` (the\n  \u03c3-algebra over which the measure is defined), then the conditional expectation verifies\n  `\u222b x in s, condexp m \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc` for any `m`-measurable set `s`.\n\nWhile `condexp` is function-valued, we also define `condexp_L1` with value in `L1` and a continuous\nlinear map `condexp_L1_clm` from `L1` to `L1`. `condexp` should be used in most cases.\n\nUniqueness of the conditional expectation\n\n* `Lp.ae_eq_of_forall_set_integral_eq'`: two `Lp` functions verifying the equality of integrals\n  defining the conditional expectation are equal.\n* `ae_eq_of_forall_set_integral_eq_of_sigma_finite'`: two functions verifying the equality of\n  integrals defining the conditional expectation are equal almost everywhere.\n  Requires `[sigma_finite (\u03bc.trim hm)]`.\n* `ae_eq_condexp_of_forall_set_integral_eq`: an a.e. `m`-measurable function which verifies the\n  equality of integrals is a.e. equal to `condexp`.\n\n## Notations\n\nFor a measure `\u03bc` defined on a measurable space structure `m0`, another measurable space structure\n`m` with `hm : m \u2264 m0` (a sub-\u03c3-algebra) and a function `f`, we define the notation\n* `\u03bc[f|m] = condexp m \u03bc f`.\n\n## Implementation notes\n\nMost of the results in this file are valid for a complete real normed space `F`.\nHowever, some lemmas also use `\ud835\udd5c : is_R_or_C`:\n* `condexp_L2` is defined only for an `inner_product_space` for now, and we use `\ud835\udd5c` for its field.\n* results about scalar multiplication are stated not only for `\u211d` but also for `\ud835\udd5c` if we happen to\n  have `normed_space \ud835\udd5c F`.\n\n## Tags\n\nconditional expectation, conditional expected value\n\n-/\n\nnoncomputable theory\nopen topological_space measure_theory.Lp filter continuous_linear_map\nopen_locale nnreal ennreal topological_space big_operators measure_theory\n\nnamespace measure_theory\n\n/-- A function `f` verifies `ae_strongly_measurable' m f \u03bc` if it is `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. This is similar to `ae_strongly_measurable`, but the\n`measurable_space` structures used for the measurability statement and for the measure are\ndifferent. -/\ndef ae_strongly_measurable' {\u03b1 \u03b2} [topological_space \u03b2]\n  (m : measurable_space \u03b1) {m0 : measurable_space \u03b1}\n  (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) : Prop :=\n\u2203 g : \u03b1 \u2192 \u03b2, strongly_measurable[m] g \u2227 f =\u1d50[\u03bc] g\n\nnamespace ae_strongly_measurable'\n\nvariables {\u03b1 \u03b2 \ud835\udd5c : Type*} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  [topological_space \u03b2] {f g : \u03b1 \u2192 \u03b2}\n\nlemma congr (hf : ae_strongly_measurable' m f \u03bc) (hfg : f =\u1d50[\u03bc] g) :\n  ae_strongly_measurable' m g \u03bc :=\nby { obtain \u27e8f', hf'_meas, hff'\u27e9 := hf, exact \u27e8f', hf'_meas, hfg.symm.trans hff'\u27e9, }\n\nlemma add [has_add \u03b2] [has_continuous_add \u03b2] (hf : ae_strongly_measurable' m f \u03bc)\n  (hg : ae_strongly_measurable' m g \u03bc) :\n  ae_strongly_measurable' m (f+g) \u03bc :=\nbegin\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9,\n  rcases hg with \u27e8g', h_g'_meas, hgg'\u27e9,\n  exact \u27e8f' + g', h_f'_meas.add h_g'_meas, hff'.add hgg'\u27e9,\nend\n\nlemma neg [add_group \u03b2] [topological_add_group \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (-f) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  refine \u27e8-f', hf'_meas.neg, hf_ae.mono (\u03bb x hx, _)\u27e9,\n  simp_rw pi.neg_apply,\n  rw hx,\nend\n\nlemma sub [add_group \u03b2] [topological_add_group \u03b2] {f g : \u03b1 \u2192 \u03b2}\n  (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  ae_strongly_measurable' m (f - g) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  rcases hgm with \u27e8g', hg'_meas, hg_ae\u27e9,\n  refine \u27e8f'-g', hf'_meas.sub hg'_meas, hf_ae.mp (hg_ae.mono (\u03bb x hx1 hx2, _))\u27e9,\n  simp_rw pi.sub_apply,\n  rw [hx1, hx2],\nend\n\nlemma const_smul [has_scalar \ud835\udd5c \u03b2] [has_continuous_const_smul \ud835\udd5c \u03b2]\n  (c : \ud835\udd5c) (hf : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (c \u2022 f) \u03bc :=\nbegin\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9,\n  refine \u27e8c \u2022 f', h_f'_meas.const_smul c, _\u27e9,\n  exact eventually_eq.fun_comp hff' (\u03bb x, c \u2022 x),\nend\n\nlemma const_inner {\ud835\udd5c \u03b2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) (c : \u03b2) :\n  ae_strongly_measurable' m (\u03bb x, (inner c (f x) : \ud835\udd5c)) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  refine \u27e8\u03bb x, (inner c (f' x) : \ud835\udd5c), (@strongly_measurable_const _ _ m _ _).inner hf'_meas,\n    hf_ae.mono (\u03bb x hx, _)\u27e9,\n  dsimp only,\n  rw hx,\nend\n\n/-- An `m`-strongly measurable function almost everywhere equal to `f`. -/\ndef mk (f : \u03b1 \u2192 \u03b2) (hfm : ae_strongly_measurable' m f \u03bc) : \u03b1 \u2192 \u03b2 := hfm.some\n\nlemma strongly_measurable_mk {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) :\n  strongly_measurable[m] (hfm.mk f) :=\nhfm.some_spec.1\n\nlemma ae_eq_mk {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) : f =\u1d50[\u03bc] hfm.mk f :=\nhfm.some_spec.2\n\nlemma continuous_comp {\u03b3} [topological_space \u03b3] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3}\n  (hg : continuous g) (hf : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (g \u2218 f) \u03bc :=\n\u27e8\u03bb x, g (hf.mk _ x),\n  @continuous.comp_strongly_measurable _ _ _ m _ _ _ _ hg hf.strongly_measurable_mk,\n  hf.ae_eq_mk.mono (\u03bb x hx, by rw [function.comp_apply, hx])\u27e9\n\nend ae_strongly_measurable'\n\nlemma ae_strongly_measurable'_of_ae_strongly_measurable'_trim {\u03b1 \u03b2} {m m0 m0' : measurable_space \u03b1}\n  [topological_space \u03b2] (hm0 : m0 \u2264 m0') {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2}\n  (hf : ae_strongly_measurable' m f (\u03bc.trim hm0)) :\n  ae_strongly_measurable' m f \u03bc :=\nby { obtain \u27e8g, hg_meas, hfg\u27e9 := hf, exact \u27e8g, hg_meas, ae_eq_of_ae_eq_trim hfg\u27e9, }\n\nlemma strongly_measurable.ae_strongly_measurable'\n  {\u03b1 \u03b2} {m m0 : measurable_space \u03b1} [topological_space \u03b2]\n  {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : strongly_measurable[m] f) :\n  ae_strongly_measurable' m f \u03bc :=\n\u27e8f, hf, ae_eq_refl _\u27e9\n\nlemma ae_eq_trim_iff_of_ae_strongly_measurable' {\u03b1 \u03b2} [topological_space \u03b2] [metrizable_space \u03b2]\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f g : \u03b1 \u2192 \u03b2}\n  (hm : m \u2264 m0) (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  hfm.mk f =\u1d50[\u03bc.trim hm] hgm.mk g \u2194 f =\u1d50[\u03bc] g :=\n(ae_eq_trim_iff hm hfm.strongly_measurable_mk hgm.strongly_measurable_mk).trans\n\u27e8\u03bb h, hfm.ae_eq_mk.trans (h.trans hgm.ae_eq_mk.symm),\n  \u03bb h, hfm.ae_eq_mk.symm.trans (h.trans hgm.ae_eq_mk)\u27e9\n\n/-- If the restriction to a set `s` of a \u03c3-algebra `m` is included in the restriction to `s` of\nanother \u03c3-algebra `m\u2082` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` almost\neverywhere supported on `s` is `m`-ae-strongly-measurable, then `f` is also\n`m\u2082`-ae-strongly-measurable. -/\nlemma ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on\n  {\u03b1 E} {m m\u2082 m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  [topological_space E] [has_zero E] (hm : m \u2264 m0) {s : set \u03b1} {f : \u03b1 \u2192 E}\n  (hs_m : measurable_set[m] s) (hs : \u2200 t, measurable_set[m] (s \u2229 t) \u2192 measurable_set[m\u2082] (s \u2229 t))\n  (hf : ae_strongly_measurable' m f \u03bc) (hf_zero : f =\u1d50[\u03bc.restrict s\u1d9c] 0) :\n  ae_strongly_measurable' m\u2082 f \u03bc :=\nbegin\n  let f' := hf.mk f,\n  have h_ind_eq : s.indicator (hf.mk f) =\u1d50[\u03bc] f,\n  { refine filter.eventually_eq.trans _\n      (indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs_m) hf_zero),\n    filter_upwards [hf.ae_eq_mk] with x hx,\n    by_cases hxs : x \u2208 s,\n    { simp [hxs, hx], },\n    { simp [hxs], }, },\n  suffices : strongly_measurable[m\u2082] (s.indicator (hf.mk f)),\n    from ae_strongly_measurable'.congr this.ae_strongly_measurable' h_ind_eq,\n  have hf_ind : strongly_measurable[m] (s.indicator (hf.mk f)),\n    from hf.strongly_measurable_mk.indicator hs_m,\n  exact hf_ind.strongly_measurable_of_measurable_space_le_on hs_m hs\n    (\u03bb x hxs, set.indicator_of_not_mem hxs _),\nend\n\nvariables {\u03b1 \u03b2 \u03b3 E E' F F' G G' H \ud835\udd5c : Type*} {p : \u211d\u22650\u221e}\n  [is_R_or_C \ud835\udd5c] -- \ud835\udd5c for \u211d or \u2102\n  [topological_space \u03b2] -- \u03b2 for a generic topological space\n  -- E for an inner product space\n  [inner_product_space \ud835\udd5c E]\n  -- E' for an inner product space on which we compute integrals\n  [inner_product_space \ud835\udd5c E']\n  [complete_space E'] [normed_space \u211d E']\n  -- F for a Lp submodule\n  [normed_group F] [normed_space \ud835\udd5c F]\n  -- F' for integrals on a Lp submodule\n  [normed_group F'] [normed_space \ud835\udd5c F'] [normed_space \u211d F'] [complete_space F']\n  -- G for a Lp add_subgroup\n  [normed_group G]\n  -- G' for integrals on a Lp add_subgroup\n  [normed_group G'] [normed_space \u211d G'] [complete_space G']\n  -- H for a normed group (hypotheses of mem_\u2112p)\n  [normed_group H]\n\nsection Lp_meas\n\n/-! ## The subset `Lp_meas` of `Lp` functions a.e. measurable with respect to a sub-sigma-algebra -/\n\nvariables (F)\n\n/-- `Lp_meas_subgroup F m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef Lp_meas_subgroup (m : measurable_space \u03b1) [measurable_space \u03b1] (p : \u211d\u22650\u221e) (\u03bc : measure \u03b1) :\n  add_subgroup (Lp F p \u03bc) :=\n{ carrier   := {f : (Lp F p \u03bc) | ae_strongly_measurable' m f \u03bc} ,\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _\u27e9,\n  add_mem'  := \u03bb f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,\n  neg_mem' := \u03bb f hf, ae_strongly_measurable'.congr hf.neg (Lp.coe_fn_neg f).symm, }\n\nvariables (\ud835\udd5c)\n/-- `Lp_meas F \ud835\udd5c m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef Lp_meas (m : measurable_space \u03b1) [measurable_space \u03b1] (p : \u211d\u22650\u221e)\n  (\u03bc : measure \u03b1) :\n  submodule \ud835\udd5c (Lp F p \u03bc) :=\n{ carrier   := {f : (Lp F p \u03bc) | ae_strongly_measurable' m f \u03bc} ,\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _\u27e9,\n  add_mem'  := \u03bb f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,\n  smul_mem' := \u03bb c f hf, (hf.const_smul c).congr (Lp.coe_fn_smul c f).symm, }\nvariables {F \ud835\udd5c}\n\nvariables\n\nlemma mem_Lp_meas_subgroup_iff_ae_strongly_measurable' {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {f : Lp F p \u03bc} :\n  f \u2208 Lp_meas_subgroup F m p \u03bc \u2194 ae_strongly_measurable' m f \u03bc :=\nby rw [\u2190 add_subgroup.mem_carrier, Lp_meas_subgroup, set.mem_set_of_eq]\n\nlemma mem_Lp_meas_iff_ae_strongly_measurable'\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f : Lp F p \u03bc} :\n  f \u2208 Lp_meas F \ud835\udd5c m p \u03bc \u2194 ae_strongly_measurable' m f \u03bc :=\nby rw [\u2190 set_like.mem_coe, \u2190 submodule.mem_carrier, Lp_meas, set.mem_set_of_eq]\n\nlemma Lp_meas.ae_strongly_measurable'\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  ae_strongly_measurable' m f \u03bc :=\nmem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem\n\nlemma mem_Lp_meas_self\n  {m0 : measurable_space \u03b1} (\u03bc : measure \u03b1) (f : Lp F p \u03bc) :\n  f \u2208 Lp_meas F \ud835\udd5c m0 p \u03bc :=\nmem_Lp_meas_iff_ae_strongly_measurable'.mpr (Lp.ae_strongly_measurable f)\n\nlemma Lp_meas_subgroup_coe {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {f : Lp_meas_subgroup F m p \u03bc} :\n  \u21d1f = (f : Lp F p \u03bc) :=\ncoe_fn_coe_base f\n\nlemma Lp_meas_coe {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f : Lp_meas F \ud835\udd5c m p \u03bc} :\n  \u21d1f = (f : Lp F p \u03bc) :=\ncoe_fn_coe_base f\n\nlemma mem_Lp_meas_indicator_const_Lp {m m0 : measurable_space \u03b1} (hm : m \u2264 m0)\n  {\u03bc : measure \u03b1} {s : set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) {c : F} :\n  indicator_const_Lp p (hm s hs) h\u03bcs c \u2208 Lp_meas F \ud835\udd5c m p \u03bc :=\n\u27e8s.indicator (\u03bb x : \u03b1, c), (@strongly_measurable_const _ _ m _ _).indicator hs,\n  indicator_const_Lp_coe_fn\u27e9\n\nsection complete_subspace\n\n/-! ## The subspace `Lp_meas` is complete.\n\nWe define an `isometric` between `Lp_meas_subgroup` and the `Lp` space corresponding to the\nmeasure `\u03bc.trim hm`. As a consequence, the completeness of `Lp` implies completeness of\n`Lp_meas_subgroup` (and `Lp_meas`). -/\n\nvariables {\u03b9 : Type*} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\n/-- If `f` belongs to `Lp_meas_subgroup F m p \u03bc`, then the measurable function it is almost\neverywhere equal to (given by `ae_measurable.mk`) belongs to `\u2112p` for the measure `\u03bc.trim hm`. -/\nlemma mem_\u2112p_trim_of_mem_Lp_meas_subgroup (hm : m \u2264 m0) (f : Lp F p \u03bc)\n  (hf_meas : f \u2208 Lp_meas_subgroup F m p \u03bc) :\n  mem_\u2112p (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas).some p (\u03bc.trim hm) :=\nbegin\n  have hf : ae_strongly_measurable' m f \u03bc,\n    from (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas),\n  let g := hf.some,\n  obtain \u27e8hg, hfg\u27e9 := hf.some_spec,\n  change mem_\u2112p g p (\u03bc.trim hm),\n  refine \u27e8hg.ae_strongly_measurable, _\u27e9,\n  have h_snorm_fg : snorm g p (\u03bc.trim hm) = snorm f p \u03bc,\n    by { rw snorm_trim hm hg, exact snorm_congr_ae hfg.symm, },\n  rw h_snorm_fg,\n  exact Lp.snorm_lt_top f,\nend\n\n/-- If `f` belongs to `Lp` for the measure `\u03bc.trim hm`, then it belongs to the subgroup\n`Lp_meas_subgroup F m p \u03bc`. -/\nlemma mem_Lp_meas_subgroup_to_Lp_of_trim (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  (mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f \u2208 Lp_meas_subgroup F m p \u03bc :=\nbegin\n  let hf_mem_\u2112p := mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f),\n  rw mem_Lp_meas_subgroup_iff_ae_strongly_measurable',\n  refine ae_strongly_measurable'.congr _ (mem_\u2112p.coe_fn_to_Lp hf_mem_\u2112p).symm,\n  refine ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm _,\n  exact Lp.ae_strongly_measurable f,\nend\n\nvariables (F p \u03bc)\n/-- Map from `Lp_meas_subgroup` to `Lp F p (\u03bc.trim hm)`. -/\ndef Lp_meas_subgroup_to_Lp_trim (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) : Lp F p (\u03bc.trim hm) :=\nmem_\u2112p.to_Lp (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some\n  (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm f f.mem)\n\nvariables (\ud835\udd5c)\n/-- Map from `Lp_meas` to `Lp F p (\u03bc.trim hm)`. -/\ndef Lp_meas_to_Lp_trim (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) : Lp F p (\u03bc.trim hm) :=\nmem_\u2112p.to_Lp (mem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem).some\n  (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm f f.mem)\nvariables {\ud835\udd5c}\n\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas_subgroup`, inverse of\n`Lp_meas_subgroup_to_Lp_trim`. -/\ndef Lp_trim_to_Lp_meas_subgroup (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) : Lp_meas_subgroup F m p \u03bc :=\n\u27e8(mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f\u27e9\n\nvariables (\ud835\udd5c)\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas`, inverse of `Lp_meas_to_Lp_trim`. -/\ndef Lp_trim_to_Lp_meas (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) : Lp_meas F \ud835\udd5c m p \u03bc :=\n\u27e8(mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f\u27e9\n\nvariables {F \ud835\udd5c p \u03bc}\n\nlemma Lp_meas_subgroup_to_Lp_trim_ae_eq (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f =\u1d50[\u03bc] f :=\n(ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm \u2191f f.mem))).trans\n  (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm\n\nlemma Lp_trim_to_Lp_meas_subgroup_ae_eq (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  Lp_trim_to_Lp_meas_subgroup F p \u03bc hm f =\u1d50[\u03bc] f :=\nmem_\u2112p.coe_fn_to_Lp _\n\nlemma Lp_meas_to_Lp_trim_ae_eq (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\n(ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm \u2191f f.mem))).trans\n  (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm\n\nlemma Lp_trim_to_Lp_meas_ae_eq (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  Lp_trim_to_Lp_meas F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\nmem_\u2112p.coe_fn_to_Lp _\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a right inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\nlemma Lp_meas_subgroup_to_Lp_trim_right_inv (hm : m \u2264 m0) :\n  function.right_inverse (Lp_trim_to_Lp_meas_subgroup F p \u03bc hm)\n    (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  intro f,\n  ext1,\n  refine ae_eq_trim_of_strongly_measurable hm\n    (Lp.strongly_measurable _) (Lp.strongly_measurable _) _,\n  exact (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _),\nend\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a left inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\nlemma Lp_meas_subgroup_to_Lp_trim_left_inv (hm : m \u2264 m0) :\n  function.left_inverse (Lp_trim_to_Lp_meas_subgroup F p \u03bc hm)\n    (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  intro f,\n  ext1,\n  ext1,\n  rw \u2190 Lp_meas_subgroup_coe,\n  exact (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _).trans (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_add (hm : m \u2264 m0) (f g : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (f + g)\n    = Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f + Lp_meas_subgroup_to_Lp_trim F p \u03bc hm g :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact (Lp.strongly_measurable _).add (Lp.strongly_measurable _), },\n  refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,\n  refine eventually_eq.trans _\n    (eventually_eq.add (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm\n      (Lp_meas_subgroup_to_Lp_trim_ae_eq hm g).symm),\n  refine (Lp.coe_fn_add _ _).trans _,\n  simp_rw Lp_meas_subgroup_coe,\n  exact eventually_of_forall (\u03bb x, by refl),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_neg (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (-f)\n    = -Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_neg _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact @strongly_measurable.neg _ _ _ m _ _ _ (Lp.strongly_measurable _), },\n  refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,\n  refine eventually_eq.trans _\n    (eventually_eq.neg (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm),\n  refine (Lp.coe_fn_neg _).trans _,\n  simp_rw Lp_meas_subgroup_coe,\n  exact eventually_of_forall (\u03bb x, by refl),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_sub (hm : m \u2264 m0) (f g : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (f - g)\n    = Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f - Lp_meas_subgroup_to_Lp_trim F p \u03bc hm g :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, Lp_meas_subgroup_to_Lp_trim_add,\n  Lp_meas_subgroup_to_Lp_trim_neg]\n\nlemma Lp_meas_to_Lp_trim_smul (hm : m \u2264 m0) (c : \ud835\udd5c) (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm (c \u2022 f) = c \u2022 Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact (Lp.strongly_measurable _).const_smul c, },\n  refine (Lp_meas_to_Lp_trim_ae_eq hm _).trans _,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (Lp_meas_to_Lp_trim_ae_eq hm f).mono (\u03bb x hx, _),\n  rw [pi.smul_apply, pi.smul_apply, hx],\n  refl,\nend\n\n/-- `Lp_meas_subgroup_to_Lp_trim` preserves the norm. -/\nlemma Lp_meas_subgroup_to_Lp_trim_norm_map [hp : fact (1 \u2264 p)] (hm : m \u2264 m0)\n  (f : Lp_meas_subgroup F m p \u03bc) :\n  \u2225Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f\u2225 = \u2225f\u2225 :=\nbegin\n  rw [Lp.norm_def, snorm_trim hm (Lp.strongly_measurable _),\n    snorm_congr_ae (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _), Lp_meas_subgroup_coe, \u2190 Lp.norm_def],\n  congr,\nend\n\nlemma isometry_Lp_meas_subgroup_to_Lp_trim [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  isometry (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  rw isometry_emetric_iff_metric,\n  intros f g,\n  rw [dist_eq_norm, \u2190 Lp_meas_subgroup_to_Lp_trim_sub, Lp_meas_subgroup_to_Lp_trim_norm_map,\n    dist_eq_norm],\nend\n\nvariables (F p \u03bc)\n/-- `Lp_meas_subgroup` and `Lp F p (\u03bc.trim hm)` are isometric. -/\ndef Lp_meas_subgroup_to_Lp_trim_iso [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  Lp_meas_subgroup F m p \u03bc \u2243\u1d62 Lp F p (\u03bc.trim hm) :=\n{ to_fun    := Lp_meas_subgroup_to_Lp_trim F p \u03bc hm,\n  inv_fun   := Lp_trim_to_Lp_meas_subgroup F p \u03bc hm,\n  left_inv  := Lp_meas_subgroup_to_Lp_trim_left_inv hm,\n  right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,\n  isometry_to_fun := isometry_Lp_meas_subgroup_to_Lp_trim hm, }\n\nvariables (\ud835\udd5c)\n/-- `Lp_meas_subgroup` and `Lp_meas` are isometric. -/\ndef Lp_meas_subgroup_to_Lp_meas_iso [hp : fact (1 \u2264 p)] :\n  Lp_meas_subgroup F m p \u03bc \u2243\u1d62 Lp_meas F \ud835\udd5c m p \u03bc :=\nisometric.refl (Lp_meas_subgroup F m p \u03bc)\n\n/-- `Lp_meas` and `Lp F p (\u03bc.trim hm)` are isometric, with a linear equivalence. -/\ndef Lp_meas_to_Lp_trim_lie [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  Lp_meas F \ud835\udd5c m p \u03bc \u2243\u2097\u1d62[\ud835\udd5c] Lp F p (\u03bc.trim hm) :=\n{ to_fun    := Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm,\n  inv_fun   := Lp_trim_to_Lp_meas F \ud835\udd5c p \u03bc hm,\n  left_inv  := Lp_meas_subgroup_to_Lp_trim_left_inv hm,\n  right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,\n  map_add'  := Lp_meas_subgroup_to_Lp_trim_add hm,\n  map_smul' := Lp_meas_to_Lp_trim_smul hm,\n  norm_map' := Lp_meas_subgroup_to_Lp_trim_norm_map hm, }\nvariables {F \ud835\udd5c p \u03bc}\n\ninstance [hm : fact (m \u2264 m0)] [complete_space F] [hp : fact (1 \u2264 p)] :\n  complete_space (Lp_meas_subgroup F m p \u03bc) :=\nby { rw (Lp_meas_subgroup_to_Lp_trim_iso F p \u03bc hm.elim).complete_space_iff, apply_instance, }\n\ninstance [hm : fact (m \u2264 m0)] [complete_space F] [hp : fact (1 \u2264 p)] :\n  complete_space (Lp_meas F \ud835\udd5c m p \u03bc) :=\nby { rw (Lp_meas_subgroup_to_Lp_meas_iso F \ud835\udd5c p \u03bc).symm.complete_space_iff, apply_instance, }\n\nlemma is_complete_ae_strongly_measurable' [hp : fact (1 \u2264 p)] [complete_space F] (hm : m \u2264 m0) :\n  is_complete {f : Lp F p \u03bc | ae_strongly_measurable' m f \u03bc} :=\nbegin\n  rw \u2190 complete_space_coe_iff_is_complete,\n  haveI : fact (m \u2264 m0) := \u27e8hm\u27e9,\n  change complete_space (Lp_meas_subgroup F m p \u03bc),\n  apply_instance,\nend\n\nlemma is_closed_ae_strongly_measurable' [hp : fact (1 \u2264 p)] [complete_space F] (hm : m \u2264 m0) :\n  is_closed {f : Lp F p \u03bc | ae_strongly_measurable' m f \u03bc} :=\nis_complete.is_closed (is_complete_ae_strongly_measurable' hm)\n\nend complete_subspace\n\nsection strongly_measurable\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\n/-- We do not get `ae_fin_strongly_measurable f (\u03bc.trim hm)`, since we don't have\n`f =\u1d50[\u03bc.trim hm] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f` but only the weaker\n`f =\u1d50[\u03bc] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f`. -/\nlemma Lp_meas.ae_fin_strongly_measurable' (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) (hp_ne_zero : p \u2260 0)\n  (hp_ne_top : p \u2260 \u221e) :\n  \u2203 g, fin_strongly_measurable g (\u03bc.trim hm) \u2227 f =\u1d50[\u03bc] g :=\n\u27e8Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f, Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top,\n  (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm\u27e9\n\n/-- When applying the inverse of `Lp_meas_to_Lp_trim_lie` (which takes a function in the Lp space of\nthe sub-sigma algebra and returns its version in the larger Lp space) to an indicator of the\nsub-sigma-algebra, we obtain an indicator in the Lp space of the larger sigma-algebra. -/\nlemma Lp_meas_to_Lp_trim_lie_symm_indicator [one_le_p : fact (1 \u2264 p)] [normed_space \u211d F]\n  {hm : m \u2264 m0} {s : set \u03b1} {\u03bc : measure \u03b1}\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc.trim hm s \u2260 \u221e) (c : F) :\n  ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm\n      (indicator_const_Lp p hs h\u03bcs c) : Lp F p \u03bc)\n    = indicator_const_Lp p (hm s hs) ((le_trim hm).trans_lt h\u03bcs.lt_top).ne c :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  change Lp_trim_to_Lp_meas F \u211d p \u03bc hm (indicator_const_Lp p hs h\u03bcs c)\n    =\u1d50[\u03bc] (indicator_const_Lp p _ _ c : \u03b1 \u2192 F),\n  refine (Lp_trim_to_Lp_meas_ae_eq hm _).trans _,\n  exact (ae_eq_of_ae_eq_trim indicator_const_Lp_coe_fn).trans indicator_const_Lp_coe_fn.symm,\nend\n\nlemma Lp_meas_to_Lp_trim_lie_symm_to_Lp [one_le_p : fact (1 \u2264 p)] [normed_space \u211d F]\n  (hm : m \u2264 m0) (f : \u03b1 \u2192 F) (hf : mem_\u2112p f p (\u03bc.trim hm)) :\n  ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm (hf.to_Lp f) : Lp F p \u03bc)\n    = (mem_\u2112p_of_mem_\u2112p_trim hm hf).to_Lp f :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  refine (Lp_trim_to_Lp_meas_ae_eq hm _).trans _,\n  exact (ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp hf)).trans (mem_\u2112p.coe_fn_to_Lp _).symm,\nend\n\nend strongly_measurable\n\nend Lp_meas\n\n\nsection induction\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} [fact (1 \u2264 p)] [normed_space \u211d F]\n\n/-- Auxiliary lemma for `Lp.induction_strongly_measurable`. -/\n@[elab_as_eliminator]\nlemma Lp.induction_strongly_measurable_aux (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e) (P : Lp F p \u03bc \u2192 Prop)\n  (h_ind : \u2200 (c : F) {s : set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s < \u221e),\n      P (Lp.simple_func.indicator_const p (hm s hs) h\u03bcs.ne c))\n  (h_add : \u2200 \u2983f g\u2984, \u2200 hf : mem_\u2112p f p \u03bc, \u2200 hg : mem_\u2112p g p \u03bc,\n    \u2200 hfm : ae_strongly_measurable' m f \u03bc, \u2200 hgm : ae_strongly_measurable' m g \u03bc,\n    disjoint (function.support f) (function.support g) \u2192\n    P (hf.to_Lp f) \u2192 P (hg.to_Lp g) \u2192 P ((hf.to_Lp f) + (hg.to_Lp g)))\n  (h_closed : is_closed {f : Lp_meas F \u211d m p \u03bc | P f}) :\n  \u2200 f : Lp F p \u03bc, ae_strongly_measurable' m f \u03bc \u2192 P f :=\nbegin\n  intros f hf,\n  let f' := (\u27e8f, hf\u27e9 : Lp_meas F \u211d m p \u03bc),\n  let g := Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm f',\n  have hfg : f' = (Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm g,\n    by simp only [linear_isometry_equiv.symm_apply_apply],\n  change P \u2191f',\n  rw hfg,\n  refine @Lp.induction \u03b1 F m _ p (\u03bc.trim hm) _ hp_ne_top\n    (\u03bb g, P ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm g)) _ _ _ g,\n  { intros b t ht h\u03bct,\n    rw [Lp.simple_func.coe_indicator_const,\n      Lp_meas_to_Lp_trim_lie_symm_indicator ht h\u03bct.ne b],\n      have h\u03bct' : \u03bc t < \u221e, from (le_trim hm).trans_lt h\u03bct,\n    specialize h_ind b ht h\u03bct',\n    rwa Lp.simple_func.coe_indicator_const at h_ind, },\n  { intros f g hf hg h_disj hfP hgP,\n    rw linear_isometry_equiv.map_add,\n    push_cast,\n    have h_eq : \u2200 (f : \u03b1 \u2192 F) (hf : mem_\u2112p f p (\u03bc.trim hm)),\n      ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm (mem_\u2112p.to_Lp f hf) : Lp F p \u03bc)\n        = (mem_\u2112p_of_mem_\u2112p_trim hm hf).to_Lp f,\n      from Lp_meas_to_Lp_trim_lie_symm_to_Lp hm,\n    rw h_eq f hf at hfP \u22a2,\n    rw h_eq g hg at hgP \u22a2,\n    exact h_add (mem_\u2112p_of_mem_\u2112p_trim hm hf) (mem_\u2112p_of_mem_\u2112p_trim hm hg)\n      (ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hf.ae_strongly_measurable)\n      (ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hg.ae_strongly_measurable)\n      h_disj hfP hgP, },\n  { change is_closed ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm \u207b\u00b9' {g : Lp_meas F \u211d m p \u03bc | P \u2191g}),\n    exact is_closed.preimage (linear_isometry_equiv.continuous _) h_closed, },\nend\n\n/-- To prove something for an `Lp` function a.e. strongly measurable with respect to a\nsub-\u03c3-algebra `m` in a normed space, it suffices to show that\n* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;\n* is closed under addition;\n* the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is\n  closed.\n-/\n@[elab_as_eliminator]\nlemma Lp.induction_strongly_measurable (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e) (P : Lp F p \u03bc \u2192 Prop)\n  (h_ind : \u2200 (c : F) {s : set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s < \u221e),\n      P (Lp.simple_func.indicator_const p (hm s hs) h\u03bcs.ne c))\n  (h_add : \u2200 \u2983f g\u2984, \u2200 hf : mem_\u2112p f p \u03bc, \u2200 hg : mem_\u2112p g p \u03bc,\n    \u2200 hfm : strongly_measurable[m] f, \u2200 hgm : strongly_measurable[m] g,\n    disjoint (function.support f) (function.support g) \u2192\n    P (hf.to_Lp f) \u2192 P (hg.to_Lp g) \u2192 P ((hf.to_Lp f) + (hg.to_Lp g)))\n  (h_closed : is_closed {f : Lp_meas F \u211d m p \u03bc | P f}) :\n  \u2200 f : Lp F p \u03bc, ae_strongly_measurable' m f \u03bc \u2192 P f :=\nbegin\n  intros f hf,\n  suffices h_add_ae : \u2200 \u2983f g\u2984, \u2200 hf : mem_\u2112p f p \u03bc, \u2200 hg : mem_\u2112p g p \u03bc,\n      \u2200 hfm : ae_strongly_measurable' m f \u03bc, \u2200 hgm : ae_strongly_measurable' m g \u03bc,\n      disjoint (function.support f) (function.support g) \u2192\n      P (hf.to_Lp f) \u2192 P (hg.to_Lp g) \u2192 P ((hf.to_Lp f) + (hg.to_Lp g)),\n    from Lp.induction_strongly_measurable_aux hm hp_ne_top P h_ind h_add_ae h_closed f hf,\n  intros f g hf hg hfm hgm h_disj hPf hPg,\n  let s_f : set \u03b1 := function.support (hfm.mk f),\n  have hs_f : measurable_set[m] s_f := hfm.strongly_measurable_mk.measurable_set_support,\n  have hs_f_eq : s_f =\u1d50[\u03bc] function.support f := hfm.ae_eq_mk.symm.support,\n  let s_g : set \u03b1 := function.support (hgm.mk g),\n  have hs_g : measurable_set[m] s_g := hgm.strongly_measurable_mk.measurable_set_support,\n  have hs_g_eq : s_g =\u1d50[\u03bc] function.support g := hgm.ae_eq_mk.symm.support,\n  have h_inter_empty : ((s_f \u2229 s_g) : set \u03b1) =\u1d50[\u03bc] (\u2205 : set \u03b1),\n  { refine (hs_f_eq.inter hs_g_eq).trans _,\n    suffices : function.support f \u2229 function.support g = \u2205, by rw this,\n    exact set.disjoint_iff_inter_eq_empty.mp h_disj, },\n  let f' := (s_f \\ s_g).indicator (hfm.mk f),\n  have hff' : f =\u1d50[\u03bc] f',\n  { have : s_f \\ s_g =\u1d50[\u03bc] s_f,\n    { rw [\u2190 set.diff_inter_self_eq_diff, set.inter_comm],\n      refine ((ae_eq_refl s_f).diff h_inter_empty).trans _,\n      rw set.diff_empty, },\n    refine ((indicator_ae_eq_of_ae_eq_set this).trans _).symm,\n    rw set.indicator_support,\n    exact hfm.ae_eq_mk.symm, },\n  have hf'_meas : strongly_measurable[m] f',\n    from hfm.strongly_measurable_mk.indicator (hs_f.diff hs_g),\n  have hf'_Lp : mem_\u2112p f' p \u03bc := hf.ae_eq hff',\n  let g' := (s_g \\ s_f).indicator (hgm.mk g),\n  have hgg' : g =\u1d50[\u03bc] g',\n  { have : s_g \\ s_f =\u1d50[\u03bc] s_g,\n    { rw [\u2190 set.diff_inter_self_eq_diff],\n      refine ((ae_eq_refl s_g).diff h_inter_empty).trans _,\n      rw set.diff_empty, },\n    refine ((indicator_ae_eq_of_ae_eq_set this).trans _).symm,\n    rw set.indicator_support,\n    exact hgm.ae_eq_mk.symm, },\n  have hg'_meas : strongly_measurable[m] g',\n    from hgm.strongly_measurable_mk.indicator (hs_g.diff hs_f),\n  have hg'_Lp : mem_\u2112p g' p \u03bc := hg.ae_eq hgg',\n  have h_disj : disjoint (function.support f') (function.support g'),\n  { have : disjoint (s_f \\ s_g) (s_g \\ s_f) := disjoint_sdiff_sdiff,\n    exact this.mono set.support_indicator_subset set.support_indicator_subset, },\n  rw \u2190 mem_\u2112p.to_Lp_congr hf'_Lp hf hff'.symm at \u22a2 hPf,\n  rw \u2190 mem_\u2112p.to_Lp_congr hg'_Lp hg hgg'.symm at \u22a2 hPg,\n  exact h_add hf'_Lp hg'_Lp hf'_meas hg'_meas h_disj hPf hPg,\nend\n\n/-- To prove something for an arbitrary `mem_\u2112p` function a.e. strongly measurable with respect\nto a sub-\u03c3-algebra `m` in a normed space, it suffices to show that\n* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;\n* is closed under addition;\n* the set of functions in the `L\u1d56` space strongly measurable w.r.t. `m` for which the property\n  holds is closed.\n* the property is closed under the almost-everywhere equal relation.\n-/\n@[elab_as_eliminator]\nlemma mem_\u2112p.induction_strongly_measurable (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e)\n  (P : (\u03b1 \u2192 F) \u2192 Prop)\n  (h_ind : \u2200 (c : F) \u2983s\u2984, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 P (s.indicator (\u03bb _, c)))\n  (h_add : \u2200 \u2983f g : \u03b1 \u2192 F\u2984, disjoint (function.support f) (function.support g)\n    \u2192 mem_\u2112p f p \u03bc \u2192 mem_\u2112p g p \u03bc \u2192 strongly_measurable[m] f \u2192 strongly_measurable[m] g \u2192\n    P f \u2192 P g \u2192 P (f + g))\n  (h_closed : is_closed {f : Lp_meas F \u211d m p \u03bc | P f} )\n  (h_ae : \u2200 \u2983f g\u2984, f =\u1d50[\u03bc] g \u2192 mem_\u2112p f p \u03bc \u2192 P f \u2192 P g) :\n  \u2200 \u2983f : \u03b1 \u2192 F\u2984 (hf : mem_\u2112p f p \u03bc) (hfm : ae_strongly_measurable' m f \u03bc), P f :=\nbegin\n  intros f hf hfm,\n  let f_Lp := hf.to_Lp f,\n  have hfm_Lp : ae_strongly_measurable' m f_Lp \u03bc, from hfm.congr hf.coe_fn_to_Lp.symm,\n  refine h_ae (hf.coe_fn_to_Lp) (Lp.mem_\u2112p _) _,\n  change P f_Lp,\n  refine Lp.induction_strongly_measurable hm hp_ne_top (\u03bb f, P \u21d1f) _ _ h_closed f_Lp hfm_Lp,\n  { intros c s hs h\u03bcs,\n    rw Lp.simple_func.coe_indicator_const,\n    refine h_ae (indicator_const_Lp_coe_fn).symm _ (h_ind c hs h\u03bcs),\n    exact mem_\u2112p_indicator_const p (hm s hs) c (or.inr h\u03bcs.ne), },\n  { intros f g hf_mem hg_mem hfm hgm h_disj hfP hgP,\n    have hfP' : P f := h_ae (hf_mem.coe_fn_to_Lp) (Lp.mem_\u2112p _) hfP,\n    have hgP' : P g := h_ae (hg_mem.coe_fn_to_Lp) (Lp.mem_\u2112p _) hgP,\n    specialize h_add h_disj hf_mem hg_mem hfm hgm hfP' hgP',\n    refine h_ae _ (hf_mem.add hg_mem) h_add,\n    exact ((hf_mem.coe_fn_to_Lp).symm.add (hg_mem.coe_fn_to_Lp).symm).trans\n      (Lp.coe_fn_add _ _).symm, },\nend\n\nend induction\n\n\nsection uniqueness_of_conditional_expectation\n\n/-! ## Uniqueness of the conditional expectation -/\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\nlemma Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero\n  (hm : m \u2264 m0) (f : Lp_meas E' \ud835\udd5c m p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hf_zero : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = 0) :\n  f =\u1d50[\u03bc] 0 :=\nbegin\n  obtain \u27e8g, hg_sm, hfg\u27e9 := Lp_meas.ae_fin_strongly_measurable' hm f hp_ne_zero hp_ne_top,\n  refine hfg.trans _,\n  refine ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim hm _ _ hg_sm,\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g, from ae_restrict_of_ae hfg,\n    rw [integrable_on, integrable_congr hfg_restrict.symm],\n    exact hf_int_finite s hs h\u03bcs, },\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g, from ae_restrict_of_ae hfg,\n    rw integral_congr_ae hfg_restrict.symm,\n    exact hf_zero s hs h\u03bcs, },\nend\n\ninclude \ud835\udd5c\n\nlemma Lp.ae_eq_zero_of_forall_set_integral_eq_zero'\n  (hm : m \u2264 m0) (f : Lp E' p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hf_zero : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = 0)\n  (hf_meas : ae_strongly_measurable' m f \u03bc) :\n  f =\u1d50[\u03bc] 0 :=\nbegin\n  let f_meas : Lp_meas E' \ud835\udd5c m p \u03bc := \u27e8f, hf_meas\u27e9,\n  have hf_f_meas : f =\u1d50[\u03bc] f_meas, by simp only [coe_fn_coe_base', subtype.coe_mk],\n  refine hf_f_meas.trans _,\n  refine Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero hm f_meas hp_ne_zero hp_ne_top _ _,\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,\n    rw [integrable_on, integrable_congr hfg_restrict.symm],\n    exact hf_int_finite s hs h\u03bcs, },\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,\n    rw integral_congr_ae hfg_restrict.symm,\n    exact hf_zero s hs h\u03bcs, },\nend\n\n/-- **Uniqueness of the conditional expectation** -/\nlemma Lp.ae_eq_of_forall_set_integral_eq'\n  (hm : m \u2264 m0) (f g : Lp E' p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hfg : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = \u222b x in s, g x \u2202\u03bc)\n  (hf_meas : ae_strongly_measurable' m f \u03bc) (hg_meas : ae_strongly_measurable' m g \u03bc) :\n  f =\u1d50[\u03bc] g :=\nbegin\n  suffices h_sub : \u21d1(f-g) =\u1d50[\u03bc] 0,\n    by { rw \u2190 sub_ae_eq_zero, exact (Lp.coe_fn_sub f g).symm.trans h_sub, },\n  have hfg' : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, (f - g) x \u2202\u03bc = 0,\n  { intros s hs h\u03bcs,\n    rw integral_congr_ae (ae_restrict_of_ae (Lp.coe_fn_sub f g)),\n    rw integral_sub' (hf_int_finite s hs h\u03bcs) (hg_int_finite s hs h\u03bcs),\n    exact sub_eq_zero.mpr (hfg s hs h\u03bcs), },\n  have hfg_int : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on \u21d1(f-g) s \u03bc,\n  { intros s hs h\u03bcs,\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub f g))],\n    exact (hf_int_finite s hs h\u03bcs).sub (hg_int_finite s hs h\u03bcs), },\n  have hfg_meas : ae_strongly_measurable' m \u21d1(f - g) \u03bc,\n    from ae_strongly_measurable'.congr (hf_meas.sub hg_meas) (Lp.coe_fn_sub f g).symm,\n  exact Lp.ae_eq_zero_of_forall_set_integral_eq_zero' hm (f-g) hp_ne_zero hp_ne_top hfg_int hfg'\n    hfg_meas,\nend\n\nomit \ud835\udd5c\n\nlemma ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  {f g : \u03b1 \u2192 F'}\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hfg_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = \u222b x in s, g x \u2202\u03bc)\n  (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  f =\u1d50[\u03bc] g :=\nbegin\n  rw \u2190 ae_eq_trim_iff_of_ae_strongly_measurable' hm hfm hgm,\n  have hf_mk_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    @integrable_on _ _ m _ (hfm.mk f) s (\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [integrable_on, restrict_trim hm _ hs],\n    refine integrable.trim hm _ hfm.strongly_measurable_mk,\n    exact integrable.congr (hf_int_finite s hs h\u03bcs) (ae_restrict_of_ae hfm.ae_eq_mk), },\n  have hg_mk_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    @integrable_on _ _ m _ (hgm.mk g) s (\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [integrable_on, restrict_trim hm _ hs],\n    refine integrable.trim hm _ hgm.strongly_measurable_mk,\n    exact integrable.congr (hg_int_finite s hs h\u03bcs) (ae_restrict_of_ae hgm.ae_eq_mk), },\n  have hfg_mk_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    \u222b x in s, (hfm.mk f x) \u2202(\u03bc.trim hm) = \u222b x in s, (hgm.mk g x) \u2202(\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [restrict_trim hm _ hs, \u2190 integral_trim hm hfm.strongly_measurable_mk,\n      \u2190 integral_trim hm hgm.strongly_measurable_mk,\n      integral_congr_ae (ae_restrict_of_ae hfm.ae_eq_mk.symm),\n      integral_congr_ae (ae_restrict_of_ae hgm.ae_eq_mk.symm)],\n    exact hfg_eq s hs h\u03bcs, },\n  exact ae_eq_of_forall_set_integral_eq_of_sigma_finite hf_mk_int_finite hg_mk_int_finite hfg_mk_eq,\nend\n\nend uniqueness_of_conditional_expectation\n\n\nsection integral_norm_le\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {s : set \u03b1}\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b x in s, \u2225g x\u2225 \u2202\u03bc \u2264 \u222b x in s, \u2225f x\u2225 \u2202\u03bc` on all `m`-measurable sets with finite measure. -/\nlemma integral_norm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n  (hf : strongly_measurable f) (hfi : integrable_on f s \u03bc)\n  (hg : strongly_measurable[m] g) (hgi : integrable_on g s \u03bc)\n  (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 \u222b x in t, g x \u2202\u03bc = \u222b x in t, f x \u2202\u03bc)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, \u2225g x\u2225 \u2202\u03bc \u2264 \u222b x in s, \u2225f x\u2225 \u2202\u03bc :=\nbegin\n  rw [integral_norm_eq_pos_sub_neg (hg.mono hm) hgi, integral_norm_eq_pos_sub_neg hf hfi],\n  have h_meas_nonneg_g : measurable_set[m] {x | 0 \u2264 g x},\n    from (@strongly_measurable_const _ _ m _ _).measurable_set_le hg,\n  have h_meas_nonneg_f : measurable_set {x | 0 \u2264 f x},\n    from strongly_measurable_const.measurable_set_le hf,\n  have h_meas_nonpos_g : measurable_set[m] {x | g x \u2264 0},\n    from hg.measurable_set_le (@strongly_measurable_const _ _ m _ _),\n  have h_meas_nonpos_f : measurable_set {x | f x \u2264 0},\n    from hf.measurable_set_le strongly_measurable_const,\n  refine sub_le_sub _ _,\n  { rw [measure.restrict_restrict (hm _ h_meas_nonneg_g),\n      measure.restrict_restrict h_meas_nonneg_f,\n      hgf _ (@measurable_set.inter \u03b1 m _ _ h_meas_nonneg_g hs)\n        ((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonneg_g),\n      \u2190 measure.restrict_restrict h_meas_nonneg_f],\n    exact set_integral_le_nonneg (hm _ h_meas_nonneg_g) hf hfi, },\n  { rw [measure.restrict_restrict (hm _ h_meas_nonpos_g),\n      measure.restrict_restrict h_meas_nonpos_f,\n      hgf _ (@measurable_set.inter \u03b1 m _ _ h_meas_nonpos_g hs)\n        ((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonpos_g),\n      \u2190 measure.restrict_restrict h_meas_nonpos_f],\n    exact set_integral_nonpos_le (hm _ h_meas_nonpos_g) hf hfi, },\nend\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b\u207b x in s, \u2225g x\u2225\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2225f x\u2225\u208a \u2202\u03bc` on all `m`-measurable sets with finite\nmeasure. -/\nlemma lintegral_nnnorm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n  (hf : strongly_measurable f) (hfi : integrable_on f s \u03bc)\n  (hg : strongly_measurable[m] g) (hgi : integrable_on g s \u03bc)\n  (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 \u222b x in t, g x \u2202\u03bc = \u222b x in t, f x \u2202\u03bc)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b\u207b x in s, \u2225g x\u2225\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2225f x\u2225\u208a \u2202\u03bc :=\nbegin\n  rw [\u2190 of_real_integral_norm_eq_lintegral_nnnorm hfi,\n    \u2190 of_real_integral_norm_eq_lintegral_nnnorm hgi, ennreal.of_real_le_of_real_iff],\n  { exact integral_norm_le_of_forall_fin_meas_integral_eq hm hf hfi hg hgi hgf hs h\u03bcs, },\n  { exact integral_nonneg (\u03bb x, norm_nonneg _), },\nend\n\nend integral_norm_le\n\n/-! ## Conditional expectation in L2\n\nWe define a conditional expectation in `L2`: it is the orthogonal projection on the subspace\n`Lp_meas`. -/\n\nsection condexp_L2\n\nvariables [complete_space E] {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {s t : set \u03b1}\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c E _ x y\nlocal notation `\u27ea`x`, `y`\u27eb\u2082` := @inner \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ x y\n\nvariables (\ud835\udd5c)\n/-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/\ndef condexp_L2 (hm : m \u2264 m0) : (\u03b1 \u2192\u2082[\u03bc] E) \u2192L[\ud835\udd5c] (Lp_meas E \ud835\udd5c m 2 \u03bc) :=\n@orthogonal_projection \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ _ (Lp_meas E \ud835\udd5c m 2 \u03bc)\n  (by { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact infer_instance, })\nvariables {\ud835\udd5c}\n\nlemma ae_strongly_measurable'_condexp_L2 (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  ae_strongly_measurable' m (condexp_L2 \ud835\udd5c hm f) \u03bc :=\nLp_meas.ae_strongly_measurable' _\n\nlemma integrable_on_condexp_L2_of_measure_ne_top (hm : m \u2264 m0) (h\u03bcs : \u03bc s \u2260 \u221e) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  integrable_on (condexp_L2 \ud835\udd5c hm f) s \u03bc :=\nintegrable_on_Lp_of_measure_ne_top ((condexp_L2 \ud835\udd5c hm f) : \u03b1 \u2192\u2082[\u03bc] E)\n  fact_one_le_two_ennreal.elim h\u03bcs\n\nlemma integrable_condexp_L2_of_is_finite_measure (hm : m \u2264 m0) [is_finite_measure \u03bc]\n  {f : \u03b1 \u2192\u2082[\u03bc] E} :\n  integrable (condexp_L2 \ud835\udd5c hm f) \u03bc :=\nintegrable_on_univ.mp $ integrable_on_condexp_L2_of_measure_ne_top hm (measure_ne_top _ _) f\n\nlemma norm_condexp_L2_le_one (hm : m \u2264 m0) : \u2225@condexp_L2 \u03b1 E \ud835\udd5c _ _ _ _ _ \u03bc hm\u2225 \u2264 1 :=\nby { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact orthogonal_projection_norm_le _, }\n\nlemma norm_condexp_L2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) : \u2225condexp_L2 \ud835\udd5c hm f\u2225 \u2264 \u2225f\u2225 :=\n((@condexp_L2 _ E \ud835\udd5c _ _ _ _ _ \u03bc hm).le_op_norm f).trans\n  (mul_le_of_le_one_left (norm_nonneg _) (norm_condexp_L2_le_one hm))\n\nlemma snorm_condexp_L2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  snorm (condexp_L2 \ud835\udd5c hm f) 2 \u03bc \u2264 snorm f 2 \u03bc :=\nbegin\n  rw [Lp_meas_coe, \u2190 ennreal.to_real_le_to_real (Lp.snorm_ne_top _) (Lp.snorm_ne_top _),\n    \u2190 Lp.norm_def, \u2190 Lp.norm_def, submodule.norm_coe],\n  exact norm_condexp_L2_le hm f,\nend\n\nlemma norm_condexp_L2_coe_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  \u2225(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E)\u2225 \u2264 \u2225f\u2225 :=\nbegin\n  rw [Lp.norm_def, Lp.norm_def, \u2190 Lp_meas_coe],\n  refine (ennreal.to_real_le_to_real _ (Lp.snorm_ne_top _)).mpr (snorm_condexp_L2_le hm f),\n  exact Lp.snorm_ne_top _,\nend\n\nlemma inner_condexp_L2_left_eq_right (hm : m \u2264 m0) {f g : \u03b1 \u2192\u2082[\u03bc] E} :\n  \u27ea(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, (condexp_L2 \ud835\udd5c hm g : \u03b1 \u2192\u2082[\u03bc] E)\u27eb\u2082 :=\nby { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact inner_orthogonal_projection_left_eq_right _ f g, }\n\nlemma condexp_L2_indicator_of_measurable (hm : m \u2264 m0)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : E) :\n  (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 (hm s hs) h\u03bcs c) : \u03b1 \u2192\u2082[\u03bc] E)\n    = indicator_const_Lp 2 (hm s hs) h\u03bcs c :=\nbegin\n  rw condexp_L2,\n  haveI : fact (m \u2264 m0) := \u27e8hm\u27e9,\n  have h_mem : indicator_const_Lp 2 (hm s hs) h\u03bcs c \u2208 Lp_meas E \ud835\udd5c m 2 \u03bc,\n    from mem_Lp_meas_indicator_const_Lp hm hs h\u03bcs,\n  let ind := (\u27e8indicator_const_Lp 2 (hm s hs) h\u03bcs c, h_mem\u27e9 : Lp_meas E \ud835\udd5c m 2 \u03bc),\n  have h_coe_ind : (ind : \u03b1 \u2192\u2082[\u03bc] E) = indicator_const_Lp 2 (hm s hs) h\u03bcs c, by refl,\n  have h_orth_mem := orthogonal_projection_mem_subspace_eq_self ind,\n  rw [\u2190 h_coe_ind, h_orth_mem],\nend\n\nlemma inner_condexp_L2_eq_inner_fun (hm : m \u2264 m0) (f g : \u03b1 \u2192\u2082[\u03bc] E)\n  (hg : ae_strongly_measurable' m g \u03bc) :\n  \u27ea(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, g\u27eb\u2082 :=\nbegin\n  symmetry,\n  rw [\u2190 sub_eq_zero, \u2190 inner_sub_left, condexp_L2],\n  simp only [mem_Lp_meas_iff_ae_strongly_measurable'.mpr hg, orthogonal_projection_inner_eq_zero],\nend\n\nsection real\n\nvariables {hm : m \u2264 m0}\n\nlemma integral_condexp_L2_eq_of_fin_meas_real (f : Lp \ud835\udd5c 2 \u03bc) (hs : measurable_set[m] s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw \u2190 L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs,\n  have h_eq_inner : \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc\n    = inner (indicator_const_Lp 2 (hm s hs) h\u03bcs (1 : \ud835\udd5c)) (condexp_L2 \ud835\udd5c hm f),\n  { rw L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs,\n    congr, },\n  rw [h_eq_inner, \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable hm hs h\u03bcs],\nend\n\nlemma lintegral_nnnorm_condexp_L2_le (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (f : Lp \u211d 2 \u03bc) :\n  \u222b\u207b x in s, \u2225condexp_L2 \u211d hm f x\u2225\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2225f x\u2225\u208a \u2202\u03bc :=\nbegin\n  let h_meas := Lp_meas.ae_strongly_measurable' (condexp_L2 \u211d hm f),\n  let g := h_meas.some,\n  have hg_meas : strongly_measurable[m] g, from h_meas.some_spec.1,\n  have hg_eq : g =\u1d50[\u03bc] condexp_L2 \u211d hm f, from h_meas.some_spec.2.symm,\n  have hg_eq_restrict : g =\u1d50[\u03bc.restrict s] condexp_L2 \u211d hm f, from ae_restrict_of_ae hg_eq,\n  have hg_nnnorm_eq : (\u03bb x, (\u2225g x\u2225\u208a : \u211d\u22650\u221e))\n    =\u1d50[\u03bc.restrict s] (\u03bb x, (\u2225condexp_L2 \u211d hm f x\u2225\u208a : \u211d\u22650\u221e)),\n  { refine hg_eq_restrict.mono (\u03bb x hx, _),\n    dsimp only,\n    rw hx, },\n  rw lintegral_congr_ae hg_nnnorm_eq.symm,\n  refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm\n    (Lp.strongly_measurable f) _ _ _ _ hs h\u03bcs,\n  { exact integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs, },\n  { exact hg_meas, },\n  { rw [integrable_on, integrable_congr hg_eq_restrict],\n    exact integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs f, },\n  { intros t ht h\u03bct,\n    rw \u2190 integral_condexp_L2_eq_of_fin_meas_real f ht h\u03bct.ne,\n    exact set_integral_congr_ae (hm t ht) (hg_eq.mono (\u03bb x hx _, hx)), },\nend\n\nlemma condexp_L2_ae_eq_zero_of_ae_eq_zero (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  {f : Lp \u211d 2 \u03bc} (hf : f =\u1d50[\u03bc.restrict s] 0) :\n  condexp_L2 \u211d hm f =\u1d50[\u03bc.restrict s] 0 :=\nbegin\n  suffices h_nnnorm_eq_zero : \u222b\u207b x in s, \u2225condexp_L2 \u211d hm f x\u2225\u208a \u2202\u03bc = 0,\n  { rw lintegral_eq_zero_iff at h_nnnorm_eq_zero,\n    refine h_nnnorm_eq_zero.mono (\u03bb x hx, _),\n    dsimp only at hx,\n    rw pi.zero_apply at hx \u22a2,\n    { rwa [ennreal.coe_eq_zero, nnnorm_eq_zero] at hx, },\n    { refine measurable.coe_nnreal_ennreal (measurable.nnnorm _),\n      rw Lp_meas_coe,\n      exact (Lp.strongly_measurable _).measurable }, },\n  refine le_antisymm _ (zero_le _),\n  refine (lintegral_nnnorm_condexp_L2_le hs h\u03bcs f).trans (le_of_eq _),\n  rw lintegral_eq_zero_iff,\n  { refine hf.mono (\u03bb x hx, _),\n    dsimp only,\n    rw hx,\n    simp, },\n  { exact (Lp.strongly_measurable _).ennnorm, },\nend\n\nlemma lintegral_nnnorm_condexp_L2_indicator_le_real\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2225\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) :=\nbegin\n  refine (lintegral_nnnorm_condexp_L2_le ht h\u03bct _).trans (le_of_eq _),\n  have h_eq : \u222b\u207b x in t, \u2225(indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) x\u2225\u208a \u2202\u03bc\n    = \u222b\u207b x in t, s.indicator (\u03bb x, (1 : \u211d\u22650\u221e)) x \u2202\u03bc,\n  { refine lintegral_congr_ae (ae_restrict_of_ae _),\n    refine (@indicator_const_Lp_coe_fn _ _ _ 2 _ _ _ hs h\u03bcs (1 : \u211d)).mono (\u03bb x hx, _),\n    rw hx,\n    classical,\n    simp_rw set.indicator_apply,\n    split_ifs; simp, },\n  rw [h_eq, lintegral_indicator _ hs, lintegral_const, measure.restrict_restrict hs],\n  simp only [one_mul, set.univ_inter, measurable_set.univ, measure.restrict_apply],\nend\n\nend real\n\n/-- `condexp_L2` commutes with taking inner products with constants. See the lemma\n`condexp_L2_comp_continuous_linear_map` for a more general result about commuting with continuous\nlinear maps. -/\nlemma condexp_L2_const_inner (hm : m \u2264 m0) (f : Lp E 2 \u03bc) (c : E) :\n  condexp_L2 \ud835\udd5c hm (((Lp.mem_\u2112p f).const_inner c).to_Lp (\u03bb a, \u27eac, f a\u27eb))\n    =\u1d50[\u03bc] \u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb :=\nbegin\n  rw Lp_meas_coe,\n  have h_mem_Lp : mem_\u2112p (\u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb) 2 \u03bc,\n  { refine mem_\u2112p.const_inner _ _, rw Lp_meas_coe, exact Lp.mem_\u2112p _, },\n  have h_eq : h_mem_Lp.to_Lp _ =\u1d50[\u03bc] \u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb, from h_mem_Lp.coe_fn_to_Lp,\n  refine eventually_eq.trans _ h_eq,\n  refine Lp.ae_eq_of_forall_set_integral_eq' hm _ _ ennreal.zero_lt_two.ne.symm ennreal.coe_ne_top\n    (\u03bb s hs h\u03bcs, integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _) _ _ _ _,\n  { intros s hs h\u03bcs,\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae h_eq)],\n    exact (integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _).const_inner _, },\n  { intros s hs h\u03bcs,\n    rw [\u2190 Lp_meas_coe, integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs.ne,\n      integral_congr_ae (ae_restrict_of_ae h_eq), Lp_meas_coe,\n      \u2190 L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c \u2191(condexp_L2 \ud835\udd5c hm f) (hm s hs) c h\u03bcs.ne,\n      \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable,\n      L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c f (hm s hs) c h\u03bcs.ne,\n      set_integral_congr_ae (hm s hs)\n        ((mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).const_inner c)).mono (\u03bb x hx hxs, hx))], },\n  { rw \u2190 Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },\n  { refine ae_strongly_measurable'.congr _ h_eq.symm,\n    exact (Lp_meas.ae_strongly_measurable' _).const_inner _, },\nend\n\n/-- `condexp_L2` verifies the equality of integrals defining the conditional expectation. -/\nlemma integral_condexp_L2_eq (hm : m \u2264 m0)\n  (f : Lp E' 2 \u03bc) (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw [\u2190 sub_eq_zero, Lp_meas_coe, \u2190 integral_sub'\n      (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)\n      (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)],\n  refine integral_eq_zero_of_forall_integral_inner_eq_zero _ _ _,\n  { rw integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub \u2191(condexp_L2 \ud835\udd5c hm f) f).symm),\n    exact integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs, },\n  intro c,\n  simp_rw [pi.sub_apply, inner_sub_right],\n  rw integral_sub\n    ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).const_inner c)\n    ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).const_inner c),\n  have h_ae_eq_f := mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).const_inner c),\n  rw [\u2190 Lp_meas_coe, sub_eq_zero,\n    \u2190 set_integral_congr_ae (hm s hs) ((condexp_L2_const_inner hm f c).mono (\u03bb x hx _, hx)),\n    \u2190 set_integral_congr_ae (hm s hs) (h_ae_eq_f.mono (\u03bb x hx _, hx))],\n  exact integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs,\nend\n\nvariables {E'' \ud835\udd5c' : Type*} [is_R_or_C \ud835\udd5c']\n  [inner_product_space \ud835\udd5c' E''] [complete_space E''] [normed_space \u211d E'']\n\nvariables (\ud835\udd5c \ud835\udd5c')\nlemma condexp_L2_comp_continuous_linear_map (hm : m \u2264 m0) (T : E' \u2192L[\u211d] E'') (f : \u03b1 \u2192\u2082[\u03bc] E') :\n  (condexp_L2 \ud835\udd5c' hm (T.comp_Lp f) : \u03b1 \u2192\u2082[\u03bc] E'') =\u1d50[\u03bc] T.comp_Lp (condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E') :=\nbegin\n  refine Lp.ae_eq_of_forall_set_integral_eq' hm _ _ ennreal.zero_lt_two.ne.symm ennreal.coe_ne_top\n    (\u03bb s hs h\u03bcs, integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _)\n    (\u03bb s hs h\u03bcs, integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.ne)\n    _ _ _,\n  { intros s hs h\u03bcs,\n    rw [T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.ne),\n      \u2190 Lp_meas_coe, \u2190 Lp_meas_coe, integral_condexp_L2_eq hm f hs h\u03bcs.ne,\n      integral_condexp_L2_eq hm (T.comp_Lp f) hs h\u03bcs.ne, T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs.ne)], },\n  { rw \u2190 Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },\n  { have h_coe := T.coe_fn_comp_Lp (condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E'),\n    rw \u2190 eventually_eq at h_coe,\n    refine ae_strongly_measurable'.congr _ h_coe.symm,\n    exact (Lp_meas.ae_strongly_measurable' (condexp_L2 \ud835\udd5c hm f)).continuous_comp T.continuous, },\nend\nvariables {\ud835\udd5c \ud835\udd5c'}\n\nsection condexp_L2_indicator\n\nvariables (\ud835\udd5c)\nlemma condexp_L2_indicator_ae_eq_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (x : E') :\n  condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x)\n    =\u1d50[\u03bc] \u03bb a, (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x :=\nbegin\n  rw indicator_const_Lp_eq_to_span_singleton_comp_Lp hs h\u03bcs x,\n  have h_comp := condexp_L2_comp_continuous_linear_map \u211d \ud835\udd5c hm (to_span_singleton \u211d x)\n    (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)),\n  rw \u2190 Lp_meas_coe at h_comp,\n  refine h_comp.trans _,\n  exact (to_span_singleton \u211d x).coe_fn_comp_Lp _,\nend\n\nlemma condexp_L2_indicator_eq_to_span_singleton_comp (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') :\n  (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) : \u03b1 \u2192\u2082[\u03bc] E')\n    = (to_span_singleton \u211d x).comp_Lp (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  refine (condexp_L2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).trans _,\n  have h_comp := (to_span_singleton \u211d x).coe_fn_comp_Lp\n    (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) : \u03b1 \u2192\u2082[\u03bc] \u211d),\n  rw \u2190 eventually_eq at h_comp,\n  refine eventually_eq.trans _ h_comp.symm,\n  refine eventually_of_forall (\u03bb y, _),\n  refl,\nend\n\nvariables {\ud835\udd5c}\n\nlemma set_lintegral_nnnorm_condexp_L2_indicator_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') {t : set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2225condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2225\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :=\ncalc \u222b\u207b a in t, \u2225condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2225\u208a \u2202\u03bc\n    = \u222b\u207b a in t, \u2225(condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x\u2225\u208a \u2202\u03bc :\nset_lintegral_congr_fun (hm t ht)\n  ((condexp_L2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).mono (\u03bb a ha hat, by rw ha))\n... = \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2225\u208a \u2202\u03bc * \u2225x\u2225\u208a :\nbegin\n  simp_rw [nnnorm_smul, ennreal.coe_mul],\n  rw [lintegral_mul_const, Lp_meas_coe],\n  exact (Lp.strongly_measurable _).ennnorm\nend\n... \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :\n  ennreal.mul_le_mul (lintegral_nnnorm_condexp_L2_indicator_le_real hs h\u03bcs ht h\u03bct) le_rfl\n\nlemma lintegral_nnnorm_condexp_L2_indicator_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') [sigma_finite (\u03bc.trim hm)] :\n  \u222b\u207b a, \u2225condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2225\u208a \u2202\u03bc \u2264 \u03bc s * \u2225x\u2225\u208a :=\nbegin\n  refine lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a) _ (\u03bb t ht h\u03bct, _),\n  { rw Lp_meas_coe,\n    exact (Lp.ae_strongly_measurable _).ennnorm },\n  refine (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _,\n  refine ennreal.mul_le_mul _ le_rfl,\n  exact measure_mono (set.inter_subset_left _ _),\nend\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\nlemma integrable_condexp_L2_indicator (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') :\n  integrable (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x)) \u03bc :=\nbegin\n  refine integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a)\n    (ennreal.mul_lt_top h\u03bcs ennreal.coe_ne_top) _ _,\n  { rw Lp_meas_coe, exact Lp.ae_strongly_measurable _, },\n  { refine \u03bb t ht h\u03bct, (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _,\n    exact ennreal.mul_le_mul (measure_mono (set.inter_subset_left _ _)) le_rfl, },\nend\n\nend condexp_L2_indicator\n\nsection condexp_ind_smul\n\nvariables [normed_space \u211d G] {hm : m \u2264 m0}\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/\ndef condexp_ind_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : Lp G 2 \u03bc :=\n(to_span_singleton \u211d x).comp_LpL 2 \u03bc (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))\n\nlemma ae_strongly_measurable'_condexp_ind_smul\n  (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  ae_strongly_measurable' m (condexp_ind_smul hm hs h\u03bcs x) \u03bc :=\nbegin\n  have h : ae_strongly_measurable' m (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) \u03bc,\n    from ae_strongly_measurable'_condexp_L2 _ _,\n  rw condexp_ind_smul,\n  suffices : ae_strongly_measurable' m\n    ((to_span_singleton \u211d x) \u2218 (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))) \u03bc,\n  { refine ae_strongly_measurable'.congr this _,\n    refine eventually_eq.trans _ (coe_fn_comp_LpL _ _).symm,\n    rw Lp_meas_coe, },\n  exact ae_strongly_measurable'.continuous_comp (to_span_singleton \u211d x).continuous h,\nend\n\nlemma condexp_ind_smul_add (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n  condexp_ind_smul hm hs h\u03bcs (x + y)\n    = condexp_ind_smul hm hs h\u03bcs x + condexp_ind_smul hm hs h\u03bcs y :=\nby { simp_rw [condexp_ind_smul], rw [to_span_singleton_add, add_comp_LpL, add_apply], }\n\nlemma condexp_ind_smul_smul (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n  condexp_ind_smul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_smul hm hs h\u03bcs x :=\nby { simp_rw [condexp_ind_smul], rw [to_span_singleton_smul, smul_comp_LpL, smul_apply], }\n\nlemma condexp_ind_smul_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n  condexp_ind_smul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_smul hm hs h\u03bcs x :=\nby rw [condexp_ind_smul, condexp_ind_smul, to_span_singleton_smul',\n  (to_span_singleton \u211d x).smul_comp_LpL_apply c\n  \u2191(condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))]\n\nlemma condexp_ind_smul_ae_eq_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind_smul hm hs h\u03bcs x\n    =\u1d50[\u03bc] \u03bb a, (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x :=\n(to_span_singleton \u211d x).coe_fn_comp_LpL _\n\nlemma set_lintegral_nnnorm_condexp_ind_smul_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) {t : set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2225condexp_ind_smul hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :=\ncalc \u222b\u207b a in t, \u2225condexp_ind_smul hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc\n    = \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a \u2022 x\u2225\u208a \u2202\u03bc :\nset_lintegral_congr_fun (hm t ht)\n  ((condexp_ind_smul_ae_eq_smul hm hs h\u03bcs x).mono (\u03bb a ha hat, by rw ha ))\n... = \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2225\u208a \u2202\u03bc * \u2225x\u2225\u208a :\nbegin\n  simp_rw [nnnorm_smul, ennreal.coe_mul],\n  rw [lintegral_mul_const, Lp_meas_coe],\n  exact (Lp.strongly_measurable _).ennnorm\nend\n... \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :\n  ennreal.mul_le_mul (lintegral_nnnorm_condexp_L2_indicator_le_real hs h\u03bcs ht h\u03bct) le_rfl\n\nlemma lintegral_nnnorm_condexp_ind_smul_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) [sigma_finite (\u03bc.trim hm)] :\n  \u222b\u207b a, \u2225condexp_ind_smul hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc \u2264 \u03bc s * \u2225x\u2225\u208a :=\nbegin\n  refine lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a) _ (\u03bb t ht h\u03bct, _),\n  { exact (Lp.ae_strongly_measurable _).ennnorm },\n  refine (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _,\n  refine ennreal.mul_le_mul _ le_rfl,\n  exact measure_mono (set.inter_subset_left _ _),\nend\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\nlemma integrable_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  integrable (condexp_ind_smul hm hs h\u03bcs x) \u03bc :=\nbegin\n  refine integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a)\n    (ennreal.mul_lt_top h\u03bcs ennreal.coe_ne_top) _ _,\n  { exact Lp.ae_strongly_measurable _, },\n  { refine \u03bb t ht h\u03bct, (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _,\n    exact ennreal.mul_le_mul (measure_mono (set.inter_subset_left _ _)) le_rfl, },\nend\n\nlemma condexp_ind_smul_empty {x : G} :\n  condexp_ind_smul hm measurable_set.empty\n    ((@measure_empty _ _ \u03bc).le.trans_lt ennreal.coe_lt_top).ne x = 0 :=\nbegin\n  rw [condexp_ind_smul, indicator_const_empty],\n  simp only [coe_fn_coe_base, submodule.coe_zero, continuous_linear_map.map_zero],\nend\n\nlemma set_integral_condexp_ind_smul (hs : measurable_set[m] s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (x : G') :\n  \u222b a in s, (condexp_ind_smul hm ht h\u03bct x) a \u2202\u03bc = (\u03bc (t \u2229 s)).to_real \u2022 x :=\ncalc \u222b a in s, (condexp_ind_smul hm ht h\u03bct x) a \u2202\u03bc\n    = (\u222b a in s, (condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) a \u2022 x) \u2202\u03bc) :\n  set_integral_congr_ae (hm s hs) ((condexp_ind_smul_ae_eq_smul hm ht h\u03bct x).mono (\u03bb x hx hxs, hx))\n... = (\u222b a in s, condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) a \u2202\u03bc) \u2022 x :\n  integral_smul_const _ x\n... = (\u222b a in s, indicator_const_Lp 2 ht h\u03bct (1 : \u211d) a \u2202\u03bc) \u2022 x :\n  by rw @integral_condexp_L2_eq \u03b1 _ \u211d _ _ _ _ _ _ _ _ hm\n    (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) hs h\u03bcs\n... = (\u03bc (t \u2229 s)).to_real \u2022 x :\n  by rw [set_integral_indicator_const_Lp (hm s hs), smul_assoc, one_smul]\n\nend condexp_ind_smul\n\nend condexp_L2\n\nsection condexp_ind\n\n/-! ## Conditional expectation of an indicator as a continuous linear map.\n\nThe goal of this section is to build\n`condexp_ind (hm : m \u2264 m0) (\u03bc : measure \u03b1) (s : set s) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G`, which\ntakes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`,\nseen as an element of `\u03b1 \u2192\u2081[\u03bc] G`.\n-/\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {s t : set \u03b1} [normed_space \u211d G]\n\nsection condexp_ind_L1_fin\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure,\nas a function in L1. -/\ndef condexp_ind_L1_fin (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)] (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : \u03b1 \u2192\u2081[\u03bc] G :=\n(integrable_condexp_ind_smul hm hs h\u03bcs x).to_L1 _\n\nlemma condexp_ind_L1_fin_ae_eq_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs x =\u1d50[\u03bc] condexp_ind_smul hm hs h\u03bcs x :=\n(integrable_condexp_ind_smul hm hs h\u03bcs x).coe_fn_to_L1\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma condexp_ind_L1_fin_add (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs (x + y)\n    = condexp_ind_L1_fin hm hs h\u03bcs x + condexp_ind_L1_fin hm hs h\u03bcs y :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  refine eventually_eq.trans _\n    (eventually_eq.add (mem_\u2112p.coe_fn_to_Lp _).symm (mem_\u2112p.coe_fn_to_Lp _).symm),\n  rw condexp_ind_smul_add,\n  refine (Lp.coe_fn_add _ _).trans (eventually_of_forall (\u03bb a, _)),\n  refl,\nend\n\nlemma condexp_ind_L1_fin_smul (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_L1_fin hm hs h\u03bcs x :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  rw condexp_ind_smul_smul hs h\u03bcs c x,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb y hy, _),\n  rw [pi.smul_apply, pi.smul_apply, hy],\nend\n\nlemma condexp_ind_L1_fin_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n  condexp_ind_L1_fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_L1_fin hm hs h\u03bcs x :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  rw condexp_ind_smul_smul' hs h\u03bcs c x,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb y hy, _),\n  rw [pi.smul_apply, pi.smul_apply, hy],\nend\n\nlemma norm_condexp_ind_L1_fin_le (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  \u2225condexp_ind_L1_fin hm hs h\u03bcs x\u2225 \u2264 (\u03bc s).to_real * \u2225x\u2225 :=\nbegin\n  have : 0 \u2264 \u222b (a : \u03b1), \u2225condexp_ind_L1_fin hm hs h\u03bcs x a\u2225 \u2202\u03bc,\n    from integral_nonneg (\u03bb a, norm_nonneg _),\n  rw [L1.norm_eq_integral_norm, \u2190 ennreal.to_real_of_real (norm_nonneg x), \u2190 ennreal.to_real_mul,\n    \u2190 ennreal.to_real_of_real this, ennreal.to_real_le_to_real ennreal.of_real_ne_top\n      (ennreal.mul_ne_top h\u03bcs ennreal.of_real_ne_top),\n    of_real_integral_norm_eq_lintegral_nnnorm],\n  swap, { rw [\u2190 mem_\u2112p_one_iff_integrable], exact Lp.mem_\u2112p _, },\n  have h_eq : \u222b\u207b a, \u2225condexp_ind_L1_fin hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc\n    = \u222b\u207b a, \u2225condexp_ind_smul hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc,\n  { refine lintegral_congr_ae _,\n    refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb z hz, _),\n    dsimp only,\n    rw hz, },\n  rw [h_eq, of_real_norm_eq_coe_nnnorm],\n  exact lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x,\nend\n\nlemma condexp_ind_L1_fin_disjoint_union (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind_L1_fin hm (hs.union ht) ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne x\n  = condexp_ind_L1_fin hm hs h\u03bcs x + condexp_ind_L1_fin hm ht h\u03bct x :=\nbegin\n  ext1,\n  have h\u03bcst := ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm (hs.union ht) h\u03bcst x).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  have hs_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x,\n  have ht_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm ht h\u03bct x,\n  refine eventually_eq.trans _ (eventually_eq.add hs_eq.symm ht_eq.symm),\n  rw condexp_ind_smul,\n  rw indicator_const_Lp_disjoint_union hs ht h\u03bcs h\u03bct hst (1 : \u211d),\n  rw (condexp_L2 \u211d hm).map_add,\n  push_cast,\n  rw ((to_span_singleton \u211d x).comp_LpL 2 \u03bc).map_add,\n  refine (Lp.coe_fn_add _ _).trans _,\n  refine eventually_of_forall (\u03bb y, _),\n  refl,\nend\n\nend condexp_ind_L1_fin\n\nopen_locale classical\n\nsection condexp_ind_L1\n\n/-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets\nwhich are not both measurable and of finite measure is not used: we set it to 0. -/\ndef condexp_ind_L1 {m m0 : measurable_space \u03b1} (hm : m \u2264 m0) (\u03bc : measure \u03b1) (s : set \u03b1)\n  [sigma_finite (\u03bc.trim hm)] (x : G) :\n  \u03b1 \u2192\u2081[\u03bc] G :=\nif hs : measurable_set s \u2227 \u03bc s \u2260 \u221e then condexp_ind_L1_fin hm hs.1 hs.2 x else 0\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (x : G) :\n  condexp_ind_L1 hm \u03bc s x = condexp_ind_L1_fin hm hs h\u03bcs x :=\nby simp only [condexp_ind_L1, and.intro hs h\u03bcs, dif_pos, ne.def, not_false_iff, and_self]\n\nlemma condexp_ind_L1_of_measure_eq_top (h\u03bcs : \u03bc s = \u221e) (x : G) :\n  condexp_ind_L1 hm \u03bc s x = 0 :=\nby simp only [condexp_ind_L1, h\u03bcs, eq_self_iff_true, not_true, ne.def, dif_neg, not_false_iff,\n  and_false]\n\nlemma condexp_ind_L1_of_not_measurable_set (hs : \u00ac measurable_set s) (x : G) :\n  condexp_ind_L1 hm \u03bc s x = 0 :=\nby simp only [condexp_ind_L1, hs, dif_neg, not_false_iff, false_and]\n\nlemma condexp_ind_L1_add (x y : G) :\n  condexp_ind_L1 hm \u03bc s (x + y) = condexp_ind_L1 hm \u03bc s x + condexp_ind_L1 hm \u03bc s y :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw zero_add, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw zero_add, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_add hs h\u03bcs x y, },\nend\n\nlemma condexp_ind_L1_smul (c : \u211d) (x : G) :\n  condexp_ind_L1 hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind_L1 hm \u03bc s x :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw smul_zero, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_smul hs h\u03bcs c x, },\nend\n\nlemma condexp_ind_L1_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n  condexp_ind_L1 hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind_L1 hm \u03bc s x :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw smul_zero, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_smul' hs h\u03bcs c x, },\nend\n\nlemma norm_condexp_ind_L1_le (x : G) :\n  \u2225condexp_ind_L1 hm \u03bc s x\u2225 \u2264 (\u03bc s).to_real * \u2225x\u2225 :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw Lp.norm_zero,\n    exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { rw [condexp_ind_L1_of_measure_eq_top h\u03bcs x, Lp.norm_zero],\n    exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },\n  { rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x,\n    exact norm_condexp_ind_L1_fin_le hs h\u03bcs x, },\nend\n\nlemma continuous_condexp_ind_L1 : continuous (\u03bb x : G, condexp_ind_L1 hm \u03bc s x) :=\ncontinuous_of_linear_of_bound condexp_ind_L1_add condexp_ind_L1_smul norm_condexp_ind_L1_le\n\nlemma condexp_ind_L1_disjoint_union (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind_L1 hm \u03bc (s \u222a t) x = condexp_ind_L1 hm \u03bc s x + condexp_ind_L1 hm \u03bc t x :=\nbegin\n  have h\u03bcst : \u03bc (s \u222a t) \u2260 \u221e, from ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne,\n  rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top ht h\u03bct x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs.union ht) h\u03bcst x],\n  exact condexp_ind_L1_fin_disjoint_union hs ht h\u03bcs h\u03bct hst x,\nend\n\nend condexp_ind_L1\n\n/-- Conditional expectation of the indicator of a set, as a linear map from `G` to L1. -/\ndef condexp_ind {m m0 : measurable_space \u03b1} (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)]\n  (s : set \u03b1) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G :=\n{ to_fun    := condexp_ind_L1 hm \u03bc s,\n  map_add'  := condexp_ind_L1_add,\n  map_smul' := condexp_ind_L1_smul,\n  cont      := continuous_condexp_ind_L1, }\n\nlemma condexp_ind_ae_eq_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind hm \u03bc s x =\u1d50[\u03bc] condexp_ind_smul hm hs h\u03bcs x :=\nbegin\n  refine eventually_eq.trans _ (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x),\n  simp [condexp_ind, condexp_ind_L1, hs, h\u03bcs],\nend\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma ae_strongly_measurable'_condexp_ind (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  ae_strongly_measurable' m (condexp_ind hm \u03bc s x) \u03bc :=\nae_strongly_measurable'.congr (ae_strongly_measurable'_condexp_ind_smul hm hs h\u03bcs x)\n  (condexp_ind_ae_eq_condexp_ind_smul hm hs h\u03bcs x).symm\n\n@[simp] lemma condexp_ind_empty : condexp_ind hm \u03bc \u2205 = (0 : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) :=\nbegin\n  ext1,\n  ext1,\n  refine (condexp_ind_ae_eq_condexp_ind_smul hm measurable_set.empty (by simp) x).trans _,\n  rw condexp_ind_smul_empty,\n  refine (Lp.coe_fn_zero G 2 \u03bc).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_zero G 1 \u03bc).symm,\n  refl,\nend\n\nlemma condexp_ind_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n  condexp_ind hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind hm \u03bc s x :=\ncondexp_ind_L1_smul' c x\n\nlemma norm_condexp_ind_apply_le (x : G) : \u2225condexp_ind hm \u03bc s x\u2225 \u2264 (\u03bc s).to_real * \u2225x\u2225 :=\nnorm_condexp_ind_L1_le x\n\nlemma norm_condexp_ind_le : \u2225(condexp_ind hm \u03bc s : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G)\u2225 \u2264 (\u03bc s).to_real :=\ncontinuous_linear_map.op_norm_le_bound _ ennreal.to_real_nonneg norm_condexp_ind_apply_le\n\nlemma condexp_ind_disjoint_union_apply (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind hm \u03bc (s \u222a t) x = condexp_ind hm \u03bc s x + condexp_ind hm \u03bc t x :=\ncondexp_ind_L1_disjoint_union hs ht h\u03bcs h\u03bct hst x\n\nlemma condexp_ind_disjoint_union (hs : measurable_set s) (ht : measurable_set t) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) :\n  (condexp_ind hm \u03bc (s \u222a t) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) = condexp_ind hm \u03bc s + condexp_ind hm \u03bc t :=\nby { ext1, push_cast, exact condexp_ind_disjoint_union_apply hs ht h\u03bcs h\u03bct hst x, }\n\nvariables (G)\n\nlemma dominated_fin_meas_additive_condexp_ind (hm : m \u2264 m0) (\u03bc : measure \u03b1)\n  [sigma_finite (\u03bc.trim hm)] :\n  dominated_fin_meas_additive \u03bc (condexp_ind hm \u03bc : set \u03b1 \u2192 G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) 1 :=\n\u27e8\u03bb s t, condexp_ind_disjoint_union, \u03bb s _ _, norm_condexp_ind_le.trans (one_mul _).symm.le\u27e9\n\nvariables {G}\n\nlemma set_integral_condexp_ind (hs : measurable_set[m] s) (ht : measurable_set t) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (h\u03bct : \u03bc t \u2260 \u221e) (x : G') :\n  \u222b a in s, condexp_ind hm \u03bc t x a \u2202\u03bc = (\u03bc (t \u2229 s)).to_real \u2022 x :=\ncalc\n\u222b a in s, condexp_ind hm \u03bc t x a \u2202\u03bc = \u222b a in s, condexp_ind_smul hm ht h\u03bct x a \u2202\u03bc :\n  set_integral_congr_ae (hm s hs)\n    ((condexp_ind_ae_eq_condexp_ind_smul hm ht h\u03bct x).mono (\u03bb x hx hxs, hx))\n... = (\u03bc (t \u2229 s)).to_real \u2022 x : set_integral_condexp_ind_smul hs ht h\u03bcs h\u03bct x\n\nlemma condexp_ind_of_measurable (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : G) :\n  condexp_ind hm \u03bc s c = indicator_const_Lp 1 (hm s hs) h\u03bcs c :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ indicator_const_Lp_coe_fn.symm,\n  refine (condexp_ind_ae_eq_condexp_ind_smul hm (hm s hs) h\u03bcs c).trans _,\n  refine (condexp_ind_smul_ae_eq_smul hm (hm s hs) h\u03bcs c).trans _,\n  rw [Lp_meas_coe, condexp_L2_indicator_of_measurable hm hs h\u03bcs (1 : \u211d)],\n  refine (@indicator_const_Lp_coe_fn \u03b1 _ _ 2 \u03bc _ s (hm s hs) h\u03bcs (1 : \u211d)).mono (\u03bb x hx, _),\n  dsimp only,\n  rw hx,\n  by_cases hx_mem : x \u2208 s; simp [hx_mem],\nend\n\nend condexp_ind\n\nsection condexp_L1\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)] {f g : \u03b1 \u2192 F'} {s : set \u03b1}\n\n/-- Conditional expectation of a function as a linear map from `\u03b1 \u2192\u2081[\u03bc] F'` to itself. -/\ndef condexp_L1_clm (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)] :\n  (\u03b1 \u2192\u2081[\u03bc] F') \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] F' :=\nL1.set_to_L1 (dominated_fin_meas_additive_condexp_ind F' hm \u03bc)\n\nlemma condexp_L1_clm_smul (c : \ud835\udd5c) (f : \u03b1 \u2192\u2081[\u03bc] F') :\n  condexp_L1_clm hm \u03bc (c \u2022 f) = c \u2022 condexp_L1_clm hm \u03bc f :=\nL1.set_to_L1_smul (dominated_fin_meas_additive_condexp_ind F' hm \u03bc)\n  (\u03bb c s x, condexp_ind_smul' c x) c f\n\nlemma condexp_L1_clm_indicator_const_Lp (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n  (condexp_L1_clm hm \u03bc) (indicator_const_Lp 1 hs h\u03bcs x) = condexp_ind hm \u03bc s x :=\nL1.set_to_L1_indicator_const_Lp (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hs h\u03bcs x\n\nlemma condexp_L1_clm_indicator_const (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n  (condexp_L1_clm hm \u03bc) \u2191(simple_func.indicator_const 1 hs h\u03bcs x) = condexp_ind hm \u03bc s x :=\nby { rw Lp.simple_func.coe_indicator_const, exact condexp_L1_clm_indicator_const_Lp hs h\u03bcs x, }\n\n/-- Auxiliary lemma used in the proof of `set_integral_condexp_L1_clm`. -/\nlemma set_integral_condexp_L1_clm_of_measure_ne_top (f : \u03b1 \u2192\u2081[\u03bc] F') (hs : measurable_set[m] s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  refine Lp.induction ennreal.one_ne_top\n    (\u03bb f : \u03b1 \u2192\u2081[\u03bc] F', \u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc)\n  _ _ (is_closed_eq _ _) f,\n  { intros x t ht h\u03bct,\n    simp_rw condexp_L1_clm_indicator_const ht h\u03bct.ne x,\n    rw [Lp.simple_func.coe_indicator_const, set_integral_indicator_const_Lp (hm _ hs)],\n    exact set_integral_condexp_ind hs ht h\u03bcs h\u03bct.ne x, },\n  { intros f g hf_Lp hg_Lp hfg_disj hf hg,\n    simp_rw (condexp_L1_clm hm \u03bc).map_add,\n    rw set_integral_congr_ae (hm s hs) ((Lp.coe_fn_add (condexp_L1_clm hm \u03bc (hf_Lp.to_Lp f))\n      (condexp_L1_clm hm \u03bc (hg_Lp.to_Lp g))).mono (\u03bb x hx hxs, hx)),\n    rw set_integral_congr_ae (hm s hs) ((Lp.coe_fn_add (hf_Lp.to_Lp f) (hg_Lp.to_Lp g)).mono\n      (\u03bb x hx hxs, hx)),\n    simp_rw pi.add_apply,\n    rw [integral_add (L1.integrable_coe_fn _).integrable_on (L1.integrable_coe_fn _).integrable_on,\n      integral_add (L1.integrable_coe_fn _).integrable_on (L1.integrable_coe_fn _).integrable_on,\n      hf, hg], },\n  { exact (continuous_set_integral s).comp (condexp_L1_clm hm \u03bc).continuous, },\n  { exact continuous_set_integral s, },\nend\n\n/-- The integral of the conditional expectation `condexp_L1_clm` over an `m`-measurable set is equal\nto the integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\nlemma set_integral_condexp_L1_clm (f : \u03b1 \u2192\u2081[\u03bc] F') (hs : measurable_set[m] s) :\n  \u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  let S := spanning_sets (\u03bc.trim hm),\n  have hS_meas : \u2200 i, measurable_set[m] (S i) := measurable_spanning_sets (\u03bc.trim hm),\n  have hS_meas0 : \u2200 i, measurable_set (S i) := \u03bb i, hm _ (hS_meas i),\n  have hs_eq : s = \u22c3 i, S i \u2229 s,\n  { simp_rw set.inter_comm,\n    rw [\u2190 set.inter_Union, (Union_spanning_sets (\u03bc.trim hm)), set.inter_univ], },\n  have hS_finite : \u2200 i, \u03bc (S i \u2229 s) < \u221e,\n  { refine \u03bb i, (measure_mono (set.inter_subset_left _ _)).trans_lt _,\n    have hS_finite_trim := measure_spanning_sets_lt_top (\u03bc.trim hm) i,\n    rwa trim_measurable_set_eq hm (hS_meas i) at hS_finite_trim, },\n  have h_mono : monotone (\u03bb i, (S i) \u2229 s),\n  { intros i j hij x,\n    simp_rw set.mem_inter_iff,\n    exact \u03bb h, \u27e8monotone_spanning_sets (\u03bc.trim hm) hij h.1, h.2\u27e9, },\n  have h_eq_forall : (\u03bb i, \u222b x in (S i) \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc)\n      = \u03bb i, \u222b x in (S i) \u2229 s, f x \u2202\u03bc,\n    from funext (\u03bb i, set_integral_condexp_L1_clm_of_measure_ne_top f\n      (@measurable_set.inter \u03b1 m _ _ (hS_meas i) hs) (hS_finite i).ne),\n  have h_right : tendsto (\u03bb i, \u222b x in (S i) \u2229 s, f x \u2202\u03bc) at_top (\ud835\udcdd (\u222b x in s, f x \u2202\u03bc)),\n  { have h := tendsto_set_integral_of_monotone (\u03bb i, (hS_meas0 i).inter (hm s hs)) h_mono\n      (L1.integrable_coe_fn f).integrable_on,\n    rwa \u2190 hs_eq at h, },\n  have h_left : tendsto (\u03bb i, \u222b x in (S i) \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc) at_top\n    (\ud835\udcdd (\u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc)),\n  { have h := tendsto_set_integral_of_monotone (\u03bb i, (hS_meas0 i).inter (hm s hs))\n      h_mono (L1.integrable_coe_fn (condexp_L1_clm hm \u03bc f)).integrable_on,\n    rwa \u2190 hs_eq at h, },\n  rw h_eq_forall at h_left,\n  exact tendsto_nhds_unique h_left h_right,\nend\n\nlemma ae_strongly_measurable'_condexp_L1_clm (f : \u03b1 \u2192\u2081[\u03bc] F') :\n  ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc :=\nbegin\n  refine Lp.induction ennreal.one_ne_top\n    (\u03bb f : \u03b1 \u2192\u2081[\u03bc] F', ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc)\n    _ _ _ f,\n  { intros c s hs h\u03bcs,\n    rw condexp_L1_clm_indicator_const hs h\u03bcs.ne c,\n    exact ae_strongly_measurable'_condexp_ind hs h\u03bcs.ne c, },\n  { intros f g hf hg h_disj hfm hgm,\n    rw (condexp_L1_clm hm \u03bc).map_add,\n    refine ae_strongly_measurable'.congr _ (coe_fn_add _ _).symm,\n    exact ae_strongly_measurable'.add hfm hgm, },\n  { have : {f : Lp F' 1 \u03bc | ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc}\n        = (condexp_L1_clm hm \u03bc) \u207b\u00b9' {f | ae_strongly_measurable' m f \u03bc},\n      by refl,\n    rw this,\n    refine is_closed.preimage (condexp_L1_clm hm \u03bc).continuous _,\n    exact is_closed_ae_strongly_measurable' hm, },\nend\n\nlemma condexp_L1_clm_Lp_meas (f : Lp_meas F' \u211d m 1 \u03bc) :\n  condexp_L1_clm hm \u03bc (f : \u03b1 \u2192\u2081[\u03bc] F') = \u2191f :=\nbegin\n  let g := Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm f,\n  have hfg : f = (Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g,\n    by simp only [linear_isometry_equiv.symm_apply_apply],\n  rw hfg,\n  refine @Lp.induction \u03b1 F' m _ 1 (\u03bc.trim hm) _ ennreal.coe_ne_top\n    (\u03bb g : \u03b1 \u2192\u2081[\u03bc.trim hm] F',\n      condexp_L1_clm hm \u03bc ((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g : \u03b1 \u2192\u2081[\u03bc] F')\n        = \u2191((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g)) _ _ _ g,\n  { intros c s hs h\u03bcs,\n    rw [Lp.simple_func.coe_indicator_const, Lp_meas_to_Lp_trim_lie_symm_indicator hs h\u03bcs.ne c,\n      condexp_L1_clm_indicator_const_Lp],\n    exact condexp_ind_of_measurable hs ((le_trim hm).trans_lt h\u03bcs).ne c, },\n  { intros f g hf hg hfg_disj hf_eq hg_eq,\n    rw linear_isometry_equiv.map_add,\n    push_cast,\n    rw [map_add, hf_eq, hg_eq], },\n  { refine is_closed_eq _ _,\n    { refine (condexp_L1_clm hm \u03bc).continuous.comp (continuous_induced_dom.comp _),\n      exact linear_isometry_equiv.continuous _, },\n    { refine continuous_induced_dom.comp _,\n      exact linear_isometry_equiv.continuous _, }, },\nend\n\nlemma condexp_L1_clm_of_ae_strongly_measurable'\n  (f : \u03b1 \u2192\u2081[\u03bc] F') (hfm : ae_strongly_measurable' m f \u03bc) :\n  condexp_L1_clm hm \u03bc f = f :=\ncondexp_L1_clm_Lp_meas (\u27e8f, hfm\u27e9 : Lp_meas F' \u211d m 1 \u03bc)\n\n/-- Conditional expectation of a function, in L1. Its value is 0 if the function is not\nintegrable. The function-valued `condexp` should be used instead in most cases. -/\ndef condexp_L1 (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)] (f : \u03b1 \u2192 F') : \u03b1 \u2192\u2081[\u03bc] F' :=\nset_to_fun \u03bc (condexp_ind hm \u03bc) (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) f\n\nlemma condexp_L1_undef (hf : \u00ac integrable f \u03bc) : condexp_L1 hm \u03bc f = 0 :=\nset_to_fun_undef (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hf\n\nlemma condexp_L1_eq (hf : integrable f \u03bc) :\n  condexp_L1 hm \u03bc f = condexp_L1_clm hm \u03bc (hf.to_L1 f) :=\nset_to_fun_eq (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hf\n\nlemma condexp_L1_zero : condexp_L1 hm \u03bc (0 : \u03b1 \u2192 F') = 0 :=\nset_to_fun_zero _\n\nlemma ae_strongly_measurable'_condexp_L1 {f : \u03b1 \u2192 F'} :\n  ae_strongly_measurable' m (condexp_L1 hm \u03bc f) \u03bc :=\nbegin\n  by_cases hf : integrable f \u03bc,\n  { rw condexp_L1_eq hf,\n    exact ae_strongly_measurable'_condexp_L1_clm _, },\n  { rw condexp_L1_undef hf,\n    refine ae_strongly_measurable'.congr _ (coe_fn_zero _ _ _).symm,\n    exact strongly_measurable.ae_strongly_measurable' (@strongly_measurable_zero _ _ m _ _), },\nend\n\nlemma condexp_L1_congr_ae (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)] (h : f =\u1d50[\u03bc] g) :\n  condexp_L1 hm \u03bc f = condexp_L1 hm \u03bc g :=\nset_to_fun_congr_ae _ h\n\nlemma integrable_condexp_L1 (f : \u03b1 \u2192 F') : integrable (condexp_L1 hm \u03bc f) \u03bc :=\nL1.integrable_coe_fn _\n\n/-- The integral of the conditional expectation `condexp_L1` over an `m`-measurable set is equal to\nthe integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\nlemma set_integral_condexp_L1 (hf : integrable f \u03bc) (hs : measurable_set[m] s) :\n  \u222b x in s, condexp_L1 hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  simp_rw condexp_L1_eq hf,\n  rw set_integral_condexp_L1_clm (hf.to_L1 f) hs,\n  exact set_integral_congr_ae (hm s hs) ((hf.coe_fn_to_L1).mono (\u03bb x hx hxs, hx)),\nend\n\nlemma condexp_L1_add (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  condexp_L1 hm \u03bc (f + g) = condexp_L1 hm \u03bc f + condexp_L1 hm \u03bc g :=\nset_to_fun_add _ hf hg\n\nlemma condexp_L1_neg (f : \u03b1 \u2192 F') : condexp_L1 hm \u03bc (-f) = - condexp_L1 hm \u03bc f :=\nset_to_fun_neg _ f\n\nlemma condexp_L1_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : condexp_L1 hm \u03bc (c \u2022 f) = c \u2022 condexp_L1 hm \u03bc f :=\nset_to_fun_smul _ (\u03bb c _ x, condexp_ind_smul' c x) c f\n\nlemma condexp_L1_sub (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  condexp_L1 hm \u03bc (f - g) = condexp_L1 hm \u03bc f - condexp_L1 hm \u03bc g :=\nset_to_fun_sub _ hf hg\n\nlemma condexp_L1_of_ae_strongly_measurable'\n  (hfm : ae_strongly_measurable' m f \u03bc) (hfi : integrable f \u03bc) :\n  condexp_L1 hm \u03bc f =\u1d50[\u03bc] f :=\nbegin\n  rw condexp_L1_eq hfi,\n  refine eventually_eq.trans _ (integrable.coe_fn_to_L1 hfi),\n  rw condexp_L1_clm_of_ae_strongly_measurable',\n  exact ae_strongly_measurable'.congr hfm (integrable.coe_fn_to_L1 hfi).symm,\nend\n\nend condexp_L1\n\nsection condexp\n\n/-! ### Conditional expectation of a function -/\n\nopen_locale classical\n\nvariables {\ud835\udd5c} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f g : \u03b1 \u2192 F'} {s : set \u03b1}\n\n/-- Conditional expectation of a function. Its value is 0 if the function is not integrable, if\nthe \u03c3-algebra is not a sub-\u03c3-algebra or if the measure is not \u03c3-finite on that \u03c3-algebra. -/\n@[irreducible]\ndef condexp (m : measurable_space \u03b1) {m0 : measurable_space \u03b1} (\u03bc : measure \u03b1) (f : \u03b1 \u2192 F') :\n  \u03b1 \u2192 F' :=\nif hm : m \u2264 m0\n  then if h\u03bc : sigma_finite (\u03bc.trim hm)\n    then if (strongly_measurable[m] f \u2227 integrable f \u03bc)\n      then f\n      else (@ae_strongly_measurable'_condexp_L1 _ _ _ _ _ m m0 \u03bc hm h\u03bc _).mk\n        (@condexp_L1 _ _ _ _ _ _ _ hm \u03bc h\u03bc f)\n    else 0\n  else 0\n\n-- We define notation `\u03bc[f|m]` for the conditional expectation of `f` with respect to `m`.\nlocalized \"notation  \u03bc `[` f `|` m `]` := measure_theory.condexp m \u03bc f\" in measure_theory\n\nlemma condexp_of_not_le (hm_not : \u00ac m \u2264 m0) : \u03bc[f|m] = 0 := by rw [condexp, dif_neg hm_not]\n\nlemma condexp_of_not_sigma_finite (hm : m \u2264 m0) (h\u03bcm_not : \u00ac sigma_finite (\u03bc.trim hm)) :\n  \u03bc[f|m] = 0 :=\nby rw [condexp, dif_pos hm, dif_neg h\u03bcm_not]\n\nlemma condexp_of_sigma_finite (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)] :\n  \u03bc[f|m] =\n  if (strongly_measurable[m] f \u2227 integrable f \u03bc)\n    then f else ae_strongly_measurable'_condexp_L1.mk (condexp_L1 hm \u03bc f) :=\nby rw [condexp, dif_pos hm, dif_pos h\u03bcm]\n\nlemma condexp_of_strongly_measurable (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  {f : \u03b1 \u2192 F'} (hf : strongly_measurable[m] f) (hfi : integrable f \u03bc) :\n  \u03bc[f|m] = f :=\nby { rw [condexp_of_sigma_finite hm,\n  if_pos (\u27e8hf, hfi\u27e9 : strongly_measurable[m] f \u2227 integrable f \u03bc)], apply_instance,  }\n\nlemma condexp_const (hm : m \u2264 m0) (c : F') [is_finite_measure \u03bc] : \u03bc[(\u03bb x : \u03b1, c)|m] = \u03bb _, c :=\ncondexp_of_strongly_measurable hm (@strongly_measurable_const _ _ m _ _) (integrable_const c)\n\nlemma condexp_ae_eq_condexp_L1 (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  (f : \u03b1 \u2192 F') : \u03bc[f|m] =\u1d50[\u03bc] condexp_L1 hm \u03bc f :=\nbegin\n  rw condexp_of_sigma_finite hm,\n  by_cases hfm : strongly_measurable[m] f,\n  { by_cases hfi : integrable f \u03bc,\n    { rw if_pos (\u27e8hfm, hfi\u27e9 : strongly_measurable[m] f \u2227 integrable f \u03bc),\n      exact (condexp_L1_of_ae_strongly_measurable'\n        (strongly_measurable.ae_strongly_measurable' hfm) hfi).symm, },\n    { simp only [hfi, if_false, and_false],\n      exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm, }, },\n  simp only [hfm, if_false, false_and],\n  exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm,\nend\n\nlemma condexp_ae_eq_condexp_L1_clm (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)] (hf : integrable f \u03bc) :\n  \u03bc[f|m] =\u1d50[\u03bc] condexp_L1_clm hm \u03bc (hf.to_L1 f) :=\nbegin\n  refine (condexp_ae_eq_condexp_L1 hm f).trans (eventually_of_forall (\u03bb x, _)),\n  rw condexp_L1_eq hf,\nend\n\nlemma condexp_undef (hf : \u00ac integrable f \u03bc) : \u03bc[f|m] =\u1d50[\u03bc] 0 :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  refine (condexp_ae_eq_condexp_L1 hm f).trans (eventually_eq.trans _ (coe_fn_zero _ 1 _)),\n  rw condexp_L1_undef hf,\nend\n\n@[simp] lemma condexp_zero : \u03bc[(0 : \u03b1 \u2192 F')|m] = 0 :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  exact condexp_of_strongly_measurable hm (@strongly_measurable_zero _ _ m _ _)\n    (integrable_zero _ _ _),\nend\n\nlemma strongly_measurable_condexp : strongly_measurable[m] (\u03bc[f|m]) :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, exact strongly_measurable_zero, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, exact strongly_measurable_zero, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  rw condexp_of_sigma_finite hm,\n  swap, { apply_instance, },\n  by_cases hfm : strongly_measurable[m] f,\n  { by_cases hfi : integrable f \u03bc,\n    { rwa if_pos (\u27e8hfm, hfi\u27e9 : strongly_measurable[m] f \u2227 integrable f \u03bc), },\n    { simp only [hfi, if_false, and_false],\n      exact ae_strongly_measurable'.strongly_measurable_mk _, }, },\n  simp only [hfm, if_false, false_and],\n  exact ae_strongly_measurable'.strongly_measurable_mk _,\nend\n\nlemma condexp_congr_ae (h : f =\u1d50[\u03bc] g) : \u03bc[f | m] =\u1d50[\u03bc] \u03bc[g | m] :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  exact (condexp_ae_eq_condexp_L1 hm f).trans\n    (filter.eventually_eq.trans (by rw condexp_L1_congr_ae hm h)\n    (condexp_ae_eq_condexp_L1 hm g).symm),\nend\n\nlemma condexp_of_ae_strongly_measurable' (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  {f : \u03b1 \u2192 F'} (hf : ae_strongly_measurable' m f \u03bc) (hfi : integrable f \u03bc) :\n  \u03bc[f|m] =\u1d50[\u03bc] f :=\nbegin\n  refine ((condexp_congr_ae hf.ae_eq_mk).trans _).trans hf.ae_eq_mk.symm,\n  rw condexp_of_strongly_measurable hm hf.strongly_measurable_mk\n    ((integrable_congr hf.ae_eq_mk).mp hfi),\nend\n\nlemma integrable_condexp : integrable (\u03bc[f|m]) \u03bc :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, exact integrable_zero _ _ _, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, exact integrable_zero _ _ _, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  exact (integrable_condexp_L1 f).congr (condexp_ae_eq_condexp_L1 hm f).symm,\nend\n\n/-- The integral of the conditional expectation `\u03bc[f|hm]` over an `m`-measurable set is equal to\nthe integral of `f` on that set. -/\nlemma set_integral_condexp (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hf : integrable f \u03bc) (hs : measurable_set[m] s) :\n  \u222b x in s, \u03bc[f|m] x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw set_integral_congr_ae (hm s hs) ((condexp_ae_eq_condexp_L1 hm f).mono (\u03bb x hx _, hx)),\n  exact set_integral_condexp_L1 hf hs,\nend\n\nlemma integral_condexp {hm : m \u2264 m0} [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  (hf : integrable f \u03bc) : \u222b x, \u03bc[f|m] x \u2202\u03bc = \u222b x, f x \u2202\u03bc :=\nbegin\n  suffices : \u222b x in set.univ, \u03bc[f|m] x \u2202\u03bc = \u222b x in set.univ, f x \u2202\u03bc,\n    by { simp_rw integral_univ at this, exact this, },\n  exact set_integral_condexp hm hf (@measurable_set.univ _ m),\nend\n\n/-- **Uniqueness of the conditional expectation**\nIf a function is a.e. `m`-measurable, verifies an integrability condition and has same integral\nas `f` on all `m`-measurable sets, then it is a.e. equal to `\u03bc[f|hm]`. -/\nlemma ae_eq_condexp_of_forall_set_integral_eq (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  {f g : \u03b1 \u2192 F'} (hf : integrable f \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hg_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, g x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc)\n  (hgm : ae_strongly_measurable' m g \u03bc) :\n  g =\u1d50[\u03bc] \u03bc[f|m] :=\nbegin\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm hg_int_finite\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on) (\u03bb s hs h\u03bcs, _) hgm\n    (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),\n  rw [hg_eq s hs h\u03bcs, set_integral_condexp hm hf hs],\nend\n\nlemma condexp_add (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  \u03bc[f + g | m] =\u1d50[\u03bc] \u03bc[f|m] + \u03bc[g|m] :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, simp, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, simp, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  refine (condexp_ae_eq_condexp_L1 hm _).trans _,\n  rw condexp_L1_add hf hg,\n  exact (coe_fn_add _ _).trans\n    ((condexp_ae_eq_condexp_L1 hm _).symm.add (condexp_ae_eq_condexp_L1 hm _).symm),\nend\n\nlemma condexp_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : \u03bc[c \u2022 f | m] =\u1d50[\u03bc] c \u2022 \u03bc[f|m] :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, simp, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, simp, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  refine (condexp_ae_eq_condexp_L1 hm _).trans _,\n  rw condexp_L1_smul c f,\n  refine (@condexp_ae_eq_condexp_L1 _ _ _ _ _ m _ _ hm _ f).mp _,\n  refine (coe_fn_smul c (condexp_L1 hm \u03bc f)).mono (\u03bb x hx1 hx2, _),\n  rw [hx1, pi.smul_apply, pi.smul_apply, hx2],\nend\n\nlemma condexp_neg (f : \u03b1 \u2192 F') : \u03bc[-f|m] =\u1d50[\u03bc] - \u03bc[f|m] :=\nby letI : module \u211d (\u03b1 \u2192 F') := @pi.module \u03b1 (\u03bb _, F') \u211d _ _ (\u03bb _, infer_instance);\ncalc \u03bc[-f|m] = \u03bc[(-1 : \u211d) \u2022 f|m] : by rw neg_one_smul \u211d f\n... =\u1d50[\u03bc] (-1 : \u211d) \u2022 \u03bc[f|m] : condexp_smul (-1) f\n... = -\u03bc[f|m] : neg_one_smul \u211d (\u03bc[f|m])\n\nlemma condexp_sub (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  \u03bc[f - g | m] =\u1d50[\u03bc] \u03bc[f|m] - \u03bc[g|m] :=\nbegin\n  simp_rw sub_eq_add_neg,\n  exact (condexp_add hf hg.neg).trans (eventually_eq.rfl.add (condexp_neg g)),\nend\n\nlemma condexp_condexp_of_le {m\u2081 m\u2082 m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} (hm\u2081\u2082 : m\u2081 \u2264 m\u2082)\n  (hm\u2082 : m\u2082 \u2264 m0) [sigma_finite (\u03bc.trim hm\u2082)] :\n  \u03bc[ \u03bc[f|m\u2082] | m\u2081] =\u1d50[\u03bc] \u03bc[f | m\u2081] :=\nbegin\n  by_cases h\u03bcm\u2081 : sigma_finite (\u03bc.trim (hm\u2081\u2082.trans hm\u2082)),\n  swap, { simp_rw condexp_of_not_sigma_finite (hm\u2081\u2082.trans hm\u2082) h\u03bcm\u2081, },\n  haveI : sigma_finite (\u03bc.trim (hm\u2081\u2082.trans hm\u2082)) := h\u03bcm\u2081,\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm\u2081\u2082.trans hm\u2082)\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on) (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on)\n    _ (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp)\n      (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),\n  intros s hs h\u03bcs,\n  rw set_integral_condexp (hm\u2081\u2082.trans hm\u2082) integrable_condexp hs,\n  swap, { apply_instance, },\n  by_cases hf : integrable f \u03bc,\n  { rw [set_integral_condexp (hm\u2081\u2082.trans hm\u2082) hf hs, set_integral_condexp hm\u2082 hf (hm\u2081\u2082 s hs)], },\n  { simp_rw integral_congr_ae (ae_restrict_of_ae (condexp_undef hf)), },\nend\n\nsection real\n\nlemma rn_deriv_ae_eq_condexp {hm : m \u2264 m0} [h\u03bcm : sigma_finite (\u03bc.trim hm)] {f : \u03b1 \u2192 \u211d}\n  (hf : integrable f \u03bc) :\n  signed_measure.rn_deriv ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm) =\u1d50[\u03bc] \u03bc[f | m] :=\nbegin\n  refine ae_eq_condexp_of_forall_set_integral_eq hm hf _ _ _,\n  { exact \u03bb _ _ _, (integrable_of_integrable_trim hm (signed_measure.integrable_rn_deriv\n      ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm))).integrable_on },\n  { intros s hs hlt,\n    conv_rhs { rw [\u2190 hf.with_density\u1d65_trim_eq_integral hm hs,\n      \u2190 signed_measure.with_density\u1d65_rn_deriv_eq ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm)\n        (hf.with_density\u1d65_trim_absolutely_continuous hm)], },\n    rw [with_density\u1d65_apply\n        (signed_measure.integrable_rn_deriv ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm)) hs,\n      \u2190 set_integral_trim hm _ hs],\n    exact (signed_measure.measurable_rn_deriv _ _).strongly_measurable },\n  { exact strongly_measurable.ae_strongly_measurable'\n      (signed_measure.measurable_rn_deriv _ _).strongly_measurable },\nend\n\nend real\n\nsection indicator\n\nlemma condexp_ae_eq_restrict_zero (hs : measurable_set[m] s) (hf : f =\u1d50[\u03bc.restrict s] 0) :\n  \u03bc[f | m] =\u1d50[\u03bc.restrict s] 0 :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  haveI : sigma_finite ((\u03bc.restrict s).trim hm),\n  { rw \u2190 restrict_trim hm _ hs,\n    exact restrict.sigma_finite _ s, },\n  by_cases hf_int : integrable f \u03bc,\n  swap, { exact ae_restrict_of_ae (condexp_undef hf_int), },\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm _ _ _ _ _,\n  { exact \u03bb t ht h\u03bct, integrable_condexp.integrable_on.integrable_on, },\n  { exact \u03bb t ht h\u03bct, (integrable_zero _ _ _).integrable_on, },\n  { intros t ht h\u03bct,\n    rw [measure.restrict_restrict (hm _ ht), set_integral_condexp hm hf_int (ht.inter hs),\n      \u2190 measure.restrict_restrict (hm _ ht)],\n    refine set_integral_congr_ae (hm _ ht) _,\n    filter_upwards [hf] with x hx h using hx, },\n  { exact strongly_measurable_condexp.ae_strongly_measurable', },\n  { exact strongly_measurable_zero.ae_strongly_measurable', },\nend\n\n/-- Auxiliary lemma for `condexp_indicator`. -/\nlemma condexp_indicator_aux (hs : measurable_set[m] s) (hf : f =\u1d50[\u03bc.restrict s\u1d9c] 0) :\n  \u03bc[s.indicator f | m] =\u1d50[\u03bc] s.indicator (\u03bc[f | m]) :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw [condexp_of_not_le hm, set.indicator_zero'], },\n  have hsf_zero : \u2200 g : \u03b1 \u2192 F', g =\u1d50[\u03bc.restrict s\u1d9c] 0 \u2192 s.indicator g =\u1d50[\u03bc] g,\n    from \u03bb g, indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs),\n  refine ((hsf_zero (\u03bc[f | m]) (condexp_ae_eq_restrict_zero hs.compl hf)).trans _).symm,\n  exact condexp_congr_ae (hsf_zero f hf).symm,\nend\n\n/-- The conditional expectation of the indicator of a function over an `m`-measurable set with\nrespect to the \u03c3-algebra `m` is a.e. equal to the indicator of the conditional expectation. -/\nlemma condexp_indicator (hf_int : integrable f \u03bc) (hs : measurable_set[m] s) :\n  \u03bc[s.indicator f | m] =\u1d50[\u03bc] s.indicator (\u03bc[f | m]) :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw [condexp_of_not_le hm, set.indicator_zero'], },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw [condexp_of_not_sigma_finite hm h\u03bcm, set.indicator_zero'], },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  -- use `have` to perform what should be the first calc step because of an error I don't\n  -- understand\n  have : s.indicator (\u03bc[f|m]) =\u1d50[\u03bc] s.indicator (\u03bc[s.indicator f + s\u1d9c.indicator f|m]),\n    by rw set.indicator_self_add_compl s f,\n  refine (this.trans _).symm,\n  calc s.indicator (\u03bc[s.indicator f + s\u1d9c.indicator f|m])\n      =\u1d50[\u03bc] s.indicator (\u03bc[s.indicator f|m] + \u03bc[s\u1d9c.indicator f|m]) :\n    begin\n      have : \u03bc[s.indicator f + s\u1d9c.indicator f|m] =\u1d50[\u03bc] \u03bc[s.indicator f|m] + \u03bc[s\u1d9c.indicator f|m],\n        from condexp_add (hf_int.indicator (hm _ hs)) (hf_int.indicator (hm _ hs.compl)),\n      filter_upwards [this] with x hx,\n      classical,\n      rw [set.indicator_apply, set.indicator_apply, hx],\n    end\n  ... = s.indicator (\u03bc[s.indicator f|m]) + s.indicator (\u03bc[s\u1d9c.indicator f|m]) :\n    s.indicator_add' _ _\n  ... =\u1d50[\u03bc] s.indicator (\u03bc[s.indicator f|m]) + s.indicator (s\u1d9c.indicator (\u03bc[s\u1d9c.indicator f|m])) :\n    begin\n      refine filter.eventually_eq.rfl.add _,\n      have : s\u1d9c.indicator (\u03bc[s\u1d9c.indicator f|m]) =\u1d50[\u03bc] \u03bc[s\u1d9c.indicator f|m],\n      { refine (condexp_indicator_aux hs.compl _).symm.trans _,\n        { exact indicator_ae_eq_restrict_compl (hm _ hs.compl), },\n        { rw [set.indicator_indicator, set.inter_self], }, },\n      filter_upwards [this] with x hx,\n      by_cases hxs : x \u2208 s,\n      { simp only [hx, hxs, set.indicator_of_mem], },\n      { simp only [hxs, set.indicator_of_not_mem, not_false_iff], },\n    end\n  ... =\u1d50[\u03bc] s.indicator (\u03bc[s.indicator f|m]) :\n    by rw [set.indicator_indicator, set.inter_compl_self, set.indicator_empty', add_zero]\n  ... =\u1d50[\u03bc] \u03bc[s.indicator f|m] :\n    begin\n      refine (condexp_indicator_aux hs _).symm.trans _,\n      { exact indicator_ae_eq_restrict_compl (hm _ hs), },\n      { rw [set.indicator_indicator, set.inter_self], },\n    end\nend\n\nlemma condexp_restrict_ae_eq_restrict (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs_m : measurable_set[m] s) (hf_int : integrable f \u03bc) :\n  (\u03bc.restrict s)[f | m] =\u1d50[\u03bc.restrict s] \u03bc[f | m] :=\nbegin\n  haveI : sigma_finite ((\u03bc.restrict s).trim hm),\n  { rw \u2190 restrict_trim hm _ hs_m, apply_instance, },\n  rw ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m),\n  swap, { apply_instance, },\n  refine eventually_eq.trans _ (condexp_indicator hf_int hs_m),\n  refine ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _,\n  { intros t ht h\u03bct,\n    rw [\u2190 integrable_indicator_iff (hm _ ht), set.indicator_indicator, set.inter_comm,\n      \u2190 set.indicator_indicator],\n    suffices h_int_restrict : integrable (t.indicator ((\u03bc.restrict s)[f|m])) (\u03bc.restrict s),\n    { rw [integrable_indicator_iff (hm _ hs_m), integrable_on],\n      rw [integrable_indicator_iff (hm _ ht), integrable_on] at h_int_restrict \u22a2,\n      exact h_int_restrict, },\n    exact integrable_condexp.indicator (hm _ ht), },\n  { intros t ht h\u03bct,\n    calc \u222b x in t, s.indicator ((\u03bc.restrict s)[f|m]) x \u2202\u03bc\n        = \u222b x in t, ((\u03bc.restrict s)[f|m]) x \u2202(\u03bc.restrict s) :\n      by rw [integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),\n        measure.restrict_restrict (hm _ ht), set.inter_comm]\n    ... = \u222b x in t, f x \u2202(\u03bc.restrict s) : set_integral_condexp hm hf_int.integrable_on ht\n    ... = \u222b x in t, s.indicator f x \u2202\u03bc :\n      by rw [integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),\n        measure.restrict_restrict (hm _ ht), set.inter_comm], },\n  { exact (strongly_measurable_condexp.indicator hs_m).ae_strongly_measurable', },\nend\n\n/-- If the restriction to a `m`-measurable set `s` of a \u03c3-algebra `m` is equal to the restriction\nto `s` of another \u03c3-algebra `m\u2082` (hypothesis `hs`), then `\u03bc[f | m] =\u1d50[\u03bc.restrict s] \u03bc[f | m\u2082]`. -/\nlemma condexp_ae_eq_restrict_of_measurable_space_eq_on {m m\u2082 m0 : measurable_space \u03b1}\n  {\u03bc : measure \u03b1} (hm : m \u2264 m0) (hm\u2082 : m\u2082 \u2264 m0)\n  [sigma_finite (\u03bc.trim hm)] [sigma_finite (\u03bc.trim hm\u2082)]\n  (hs_m : measurable_set[m] s) (hs : \u2200 t, measurable_set[m] (s \u2229 t) \u2194 measurable_set[m\u2082] (s \u2229 t)) :\n  \u03bc[f | m] =\u1d50[\u03bc.restrict s] \u03bc[f | m\u2082] :=\nbegin\n  rw ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m),\n  have hs_m\u2082 : measurable_set[m\u2082] s,\n  { rwa [\u2190 set.inter_univ s, \u2190 hs set.univ, set.inter_univ], },\n  by_cases hf_int : integrable f \u03bc,\n  swap,\n  { filter_upwards [@condexp_undef _ _ _ _ _ m _ \u03bc _ hf_int,\n      @condexp_undef _ _ _ _ _ m\u2082 _ \u03bc _ hf_int] with x hxm hxm\u2082,\n    simp only [set.indicator_apply, hxm, hxm\u2082], },\n  refine ((condexp_indicator hf_int hs_m).symm.trans _).trans (condexp_indicator hf_int hs_m\u2082),\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm\u2082\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on)\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on) _ _\n    strongly_measurable_condexp.ae_strongly_measurable',\n  swap,\n  { have : strongly_measurable[m] (\u03bc[s.indicator f | m]) := strongly_measurable_condexp,\n    refine this.ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on\n      hm hs_m (\u03bb t, (hs t).mp) _,\n    exact condexp_ae_eq_restrict_zero hs_m.compl (indicator_ae_eq_restrict_compl (hm _ hs_m)), },\n  intros t ht h\u03bct,\n  have : \u222b x in t, \u03bc[s.indicator f|m] x \u2202\u03bc = \u222b x in s \u2229 t, \u03bc[s.indicator f|m] x \u2202\u03bc,\n  { rw \u2190 integral_add_compl (hm _ hs_m) integrable_condexp.integrable_on,\n    suffices : \u222b x in s\u1d9c, \u03bc[s.indicator f|m] x \u2202\u03bc.restrict t = 0,\n      by rw [this, add_zero, measure.restrict_restrict (hm _ hs_m)],\n    rw measure.restrict_restrict (measurable_set.compl (hm _ hs_m)),\n    suffices : \u03bc[s.indicator f|m] =\u1d50[\u03bc.restrict s\u1d9c] 0,\n    { rw [set.inter_comm, \u2190 measure.restrict_restrict (hm\u2082 _ ht)],\n      calc \u222b (x : \u03b1) in t, \u03bc[s.indicator f|m] x \u2202\u03bc.restrict s\u1d9c\n          = \u222b (x : \u03b1) in t, 0 \u2202\u03bc.restrict s\u1d9c : begin\n            refine set_integral_congr_ae (hm\u2082 _ ht) _,\n            filter_upwards [this] with x hx h using hx,\n          end\n      ... = 0 : integral_zero _ _, },\n    refine condexp_ae_eq_restrict_zero hs_m.compl _,\n    exact indicator_ae_eq_restrict_compl (hm _ hs_m), },\n  have hst_m : measurable_set[m] (s \u2229 t) := (hs _).mpr (hs_m\u2082.inter ht),\n  simp_rw [this, set_integral_condexp hm\u2082 (hf_int.indicator (hm _ hs_m)) ht,\n    set_integral_condexp hm (hf_int.indicator (hm _ hs_m)) hst_m,\n    integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),\n    \u2190 set.inter_assoc, set.inter_self],\nend\n\nend indicator\n\nend condexp\n\nend measure_theory\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/measure_theory/function/conditional_expectation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.719678807660489}}
{"text": "import topology.basic\n\n\nnamespace topology\n\nuniverse u \n\nopen set\nopen classical\n\ndef subspace_is_open {X : Type u} [T_X: topology X] (S : set X) : set (subtype S) \u2192 Prop \n  := \u03bb W , \u2203 U : set X, is_open U \u2227 (include_subset W = U \u2229 S)\n\ntheorem subspace_whole_space_open {X : Type u} [T_X : topology X] (S : set X) : subspace_is_open S univ :=\nbegin\n  existsi univ,\n  split,\n  exact T_X.whole_space_open,\n  rw include_univ_is_set,\n  symmetry,\n  exact intersection_subset set_subset_of_univ,\nend\n\ntheorem subspace_empty_set_open {X : Type u} [T_X : topology X] (S : set X) : subspace_is_open S \u2205 :=\nbegin\n  existsi \u2205,\n  split,\n  exact T_X.empty_set_open,\n  rw include_empty_is_empty,\n  symmetry,\n  apply intersection_empty_set,\nend\n\ntheorem subspace_abitary_unions_open {X : Type u} [T_X : topology X] (S : set X) (C: set (set (subtype S))) \n  : (\u2200 t, t \u2208 C \u2192 subspace_is_open S t) \u2192 subspace_is_open S (\u22c3\u2080 C) :=\nbegin\n  intro all_s_open,\n  let U : \u03a0 {W: set (subtype S)} (hW : W \u2208 C), set X := \u03bb W hW ,some (all_s_open W hW),\n  have hU : \u2200 {W: set (subtype S)} (hW : W \u2208 C), is_open (U hW) \u2227 (include_subset W = (U hW) \u2229 S) := \u03bb W hW, (some_spec (all_s_open W hW)),\n  let UC : set (set X) := \u03bb A, \u2203 (W : set (subtype S)) (hW : W \u2208 C), A = U hW, \n  existsi \u22c3\u2080 UC,\n  split,\n  apply T_X.arbitary_unions_open,\n  intros W hW,\n  cases hW with W_ghost hW,\n  cases hW with hW_ghost hW,\n  rw hW,\n  exact and.left (hU hW_ghost),\n  rw \u2190 include_set_prevs_union C,\n  rw intersection_dis_over_union,\n  have hrw : image include_subset C = image (\u03bb B, B \u2229 S) UC, \n    apply subset_antisymmetric,\n    split,\n    intros A hA,\n    cases hA with Ag hAg,\n    cases hAg with hAginC hAg,\n    have h\u2081 : U hAginC \u2208 UC,\n      split,\n      existsi hAginC,\n      refl,\n    existsi (U hAginC),\n    split,\n    exact h\u2081,\n    rw and.right (hU hAginC) at hAg,\n    rw \u2190 hAg,\n    intros A hA,\n    cases hA with B hB,\n    cases hB with hBinUC hBSisA,\n    cases hBinUC with W hW,\n    cases hW with hWinC hB,\n    rw hB at hBSisA,\n    simp at hBSisA,\n    have h := and.right (hU hWinC),\n    rw hBSisA at h,\n    rw \u2190 h,\n    apply image_membership,\n    exact hWinC,\n  rw hrw,\nend\n\ntheorem subspace_pairwise_inters_open {X : Type u} [T_X : topology X] (S : set X) \n  : \u2200 s t : set (subtype S), subspace_is_open S s \u2192 subspace_is_open S t \u2192 subspace_is_open S (s \u2229 t) :=\nbegin\n  intros s t hs ht,\n  cases hs with Us hs,\n  cases ht with Ut ht,\n  existsi (Us \u2229 Ut),\n  split,\n  apply T_X.pairwise_inters_open,\n  exact and.left hs,\n  exact and.left ht,\n  rw include_set_prevs_pair_intersection,\n  rw [and.right hs, and.right ht],\n  rw intersection_commuative Ut S,\n  have hrw : Us \u2229 S \u2229 (S \u2229 Ut) = Us \u2229 (S \u2229 S) \u2229 Ut,\n    simp [intersection_assoc],\n  rw hrw,\n  rw set_int_set_set,\n  rw \u2190 intersection_assoc,\n  rw intersection_commuative S Ut,\n  simp [intersection_assoc],\nend\n \ninstance subspace_topology (X : Type u) [T_X : topology X] (S : set X) : topology (subtype S) := \nbegin\n  split,\n  exact subspace_whole_space_open S,\n  exact subspace_empty_set_open S,\n  exact subspace_abitary_unions_open S,\n  exact subspace_pairwise_inters_open S,\nend\n\nstructure closed_topology (X : Type u) :=\n  (closed_b : set X \u2192 Prop)\n  (whole_space_closed : closed_b univ)\n  (empty_set_closed : closed_b \u2205)\n  (arbitary_inters_closed (s: set (set X)) : (\u2200 t : set X, t \u2208 s \u2192 closed_b t) \u2192 closed_b (\u22c2\u2080 s))\n  (pairwise_unions_closed : \u2200 s t : set X, closed_b s \u2192 closed_b t \u2192 closed_b (s \u222a t))\n\ndef from_closed_topology {X : Type u} (ct : closed_topology X) : topology X :=\n{\n  is_open := \u03bb S, ct.closed_b (univ \\ S),\n  empty_set_open :=\n    begin\n      rw empty_set_diff,\n      apply ct.whole_space_closed,\n    end,\n  whole_space_open :=\n    begin\n      rw diff_of_univ_empty,\n      apply ct.empty_set_closed,\n    end,\n  arbitary_unions_open :=\n    begin\n      intros C hC,\n      rw deMorgenUnion,\n      apply ct.arbitary_inters_closed,\n      intros S hS,\n      cases hS with A hA,\n      cases hA with AinC Arw,\n      rw \u2190 Arw,\n      apply hC,\n      exact AinC,\n    end,\n  pairwise_inters_open :=\n    begin\n      intros U\u2081 U\u2082 hU\u2081 hU\u2082,\n      rw \u2190 sinter_to_inter,\n      rw deMorgenInter,\n      rw image_of_list_to_set,\n      have trv : list.map (\u03bb A, univ \\ A) [U\u2081,U\u2082] = \n        [univ \\ U\u2081, univ \\ U\u2082] := rfl,\n      rw [trv,sunion_to_union],\n      apply closed_topology.pairwise_unions_closed,\n      exact hU\u2081,\n      exact hU\u2082,\n    end,\n}\n\nend topology", "meta": {"author": "CameronTorrance", "repo": "Schemes", "sha": "f407ce80b8407101231170680b03b55984c42496", "save_path": "github-repos/lean/CameronTorrance-Schemes", "path": "github-repos/lean/CameronTorrance-Schemes/Schemes-f407ce80b8407101231170680b03b55984c42496/src/topology/instances/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7196788074565884}}
{"text": "/-\n## The `left` and `right` tactics\n\nIn the previous lemma we learned how `split` makes progress on goals involving the conjunction `\u2227`.\nBut what if the goal involves the *disjunction* `\u2228` (type it with `\\or`)? In this case,\nyou first need to decide which is the side that you will try to prove. If it's the first (left)\nclause, the tactic `left` will change the goal to that one, if it's the second (right) clause,\nthen well, you use `right`.\n-/\n/- Symbol:\n\u2228 : \\or\n-/\n/- Lemma : no-side-bar\nIf $a$ is $5$, then either it is $5$ or it is $7$.\n-/\nlemma lr0 (a : \u2115) (h : a = 5) : a = 5 \u2228 a = 7 :=\nbegin\n  left,\n  assumption,\n\n\n\n\nend\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/tactics_world/03_leftright.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7195947289986356}}
{"text": "/-\nCopyright (c) 2021 Jakob von Raumer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jakob von Raumer\n-/\nimport linear_algebra.contraction\nimport linear_algebra.finite_dimensional\nimport linear_algebra.dual\n\n/-!\n# The coevaluation map on finite dimensional vector spaces\n\nGiven a finite dimensional vector space `V` over a field `K` this describes the canonical linear map\nfrom `K` to `V \u2297 dual K V` which corresponds to the identity function on `V`.\n\n## Tags\n\ncoevaluation, dual module, tensor product\n\n## Future work\n\n* Prove that this is independent of the choice of basis on `V`.\n-/\nnoncomputable theory\n\nsection coevaluation\nopen tensor_product finite_dimensional\nopen_locale tensor_product big_operators\n\nuniverses u v\n\nvariables (K : Type u) [field K]\nvariables (V : Type v) [add_comm_group V] [module K V] [finite_dimensional K V]\n\n/-- The coevaluation map is a linear map from a field `K` to a finite dimensional\n  vector space `V`. -/\ndef coevaluation : K \u2192\u2097[K] V \u2297[K] (module.dual K V) :=\n  let bV := basis.of_vector_space K V in\n  (basis.singleton unit K).constr K $\n    \u03bb _, \u2211 (i : basis.of_vector_space_index K V), bV i \u2297\u209c[K] bV.coord i\n\nlemma coevaluation_apply_one :\n (coevaluation K V) (1 : K) =\n   let bV := basis.of_vector_space K V in\n   \u2211 (i : basis.of_vector_space_index K V), bV i \u2297\u209c[K] bV.coord i :=\nbegin\n  simp only [coevaluation, id],\n  rw [(basis.singleton unit K).constr_apply_fintype K],\n  simp only [fintype.univ_punit, finset.sum_const, one_smul, basis.singleton_repr,\n   basis.equiv_fun_apply,basis.coe_of_vector_space, one_nsmul, finset.card_singleton],\nend\n\nopen tensor_product\n\n/-- This lemma corresponds to one of the coherence laws for duals in rigid categories, see\n  `category_theory.monoidal.rigid`. -/\nlemma contract_left_assoc_coevaluation :\n  ((contract_left K V).rtensor _)\n   \u2218\u2097 (tensor_product.assoc K _ _ _).symm.to_linear_map\n   \u2218\u2097 ((coevaluation K V).ltensor (module.dual K V))\n  = (tensor_product.lid K _).symm.to_linear_map \u2218\u2097 (tensor_product.rid K _).to_linear_map :=\nbegin\n  letI := classical.dec_eq (basis.of_vector_space_index K V),\n  apply tensor_product.ext,\n  apply (basis.of_vector_space K V).dual_basis.ext, intro j, apply linear_map.ext_ring,\n  rw [linear_map.compr\u2082_apply, linear_map.compr\u2082_apply, tensor_product.mk_apply],\n  simp only [linear_map.coe_comp, function.comp_app, linear_equiv.coe_to_linear_map],\n  rw [rid_tmul, one_smul, lid_symm_apply],\n  simp only [linear_equiv.coe_to_linear_map, linear_map.ltensor_tmul, coevaluation_apply_one],\n  rw [tensor_product.tmul_sum, linear_equiv.map_sum], simp only [assoc_symm_tmul],\n  rw [linear_map.map_sum], simp only [linear_map.rtensor_tmul, contract_left_apply],\n  simp only [basis.coe_dual_basis, basis.coord_apply, basis.repr_self_apply,\n    tensor_product.ite_tmul],\n  rw [finset.sum_ite_eq'], simp only [finset.mem_univ, if_true]\nend\n\n/-- This lemma corresponds to one of the coherence laws for duals in rigid categories, see\n  `category_theory.monoidal.rigid`. -/\nlemma contract_left_assoc_coevaluation' :\n  ((contract_left K V).ltensor _)\n   \u2218\u2097 (tensor_product.assoc K _ _ _).to_linear_map\n   \u2218\u2097 ((coevaluation K V).rtensor V)\n  = (tensor_product.rid K _).symm.to_linear_map \u2218\u2097 (tensor_product.lid K _).to_linear_map :=\nbegin\n  letI := classical.dec_eq (basis.of_vector_space_index K V),\n  apply tensor_product.ext,\n  apply linear_map.ext_ring, apply (basis.of_vector_space K V).ext, intro j,\n  rw [linear_map.compr\u2082_apply, linear_map.compr\u2082_apply, tensor_product.mk_apply],\n  simp only [linear_map.coe_comp, function.comp_app, linear_equiv.coe_to_linear_map],\n  rw [lid_tmul, one_smul, rid_symm_apply],\n  simp only [linear_equiv.coe_to_linear_map, linear_map.rtensor_tmul, coevaluation_apply_one],\n  rw [tensor_product.sum_tmul, linear_equiv.map_sum], simp only [assoc_tmul],\n  rw [linear_map.map_sum], simp only [linear_map.ltensor_tmul, contract_left_apply],\n  simp only [basis.coord_apply, basis.repr_self_apply, tensor_product.tmul_ite],\n  rw [finset.sum_ite_eq], simp only [finset.mem_univ, if_true]\nend\n\nend coevaluation\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/coevaluation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7195947265494145}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport analysis.convex.side\nimport geometry.euclidean.angle.oriented.rotation\nimport geometry.euclidean.angle.unoriented.affine\n\n/-!\n# Oriented angles.\n\nThis file defines oriented angles in Euclidean affine spaces.\n\n## Main definitions\n\n* `euclidean_geometry.oangle`, with notation `\u2221`, is the oriented angle determined by three\n  points.\n\n-/\n\nnoncomputable theory\n\nopen finite_dimensional complex\nopen_locale affine euclidean_geometry real real_inner_product_space complex_conjugate\n\nnamespace euclidean_geometry\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\n  [hd2 : fact (finrank \u211d V = 2)] [module.oriented \u211d V (fin 2)]\ninclude hd2\n\nlocal notation `o` := module.oriented.positive_orientation\n\n/-- The oriented angle at `p\u2082` between the line segments to `p\u2081` and `p\u2083`, modulo `2 * \u03c0`. If\neither of those points equals `p\u2082`, this is 0. See `euclidean_geometry.angle` for the\ncorresponding unoriented angle definition. -/\ndef oangle (p\u2081 p\u2082 p\u2083 : P) : real.angle := (o).oangle (p\u2081 -\u1d65 p\u2082) (p\u2083 -\u1d65 p\u2082)\n\nlocalized \"notation (name := oangle) `\u2221` := euclidean_geometry.oangle\" in euclidean_geometry\n\n/-- Oriented angles are continuous when neither end point equals the middle point. -/\nlemma continuous_at_oangle {x : P \u00d7 P \u00d7 P} (hx12 : x.1 \u2260 x.2.1) (hx32 : x.2.2 \u2260 x.2.1) :\n  continuous_at (\u03bb y : P \u00d7 P \u00d7 P, \u2221 y.1 y.2.1 y.2.2) x :=\nbegin\n  let f : P \u00d7 P \u00d7 P \u2192 V \u00d7 V := \u03bb y, (y.1 -\u1d65 y.2.1, y.2.2 -\u1d65 y.2.1),\n  have hf1 : (f x).1 \u2260 0, by simp [hx12],\n  have hf2 : (f x).2 \u2260 0, by simp [hx32],\n  exact ((o).continuous_at_oangle hf1 hf2).comp\n    ((continuous_fst.vsub continuous_snd.fst).prod_mk\n      (continuous_snd.snd.vsub continuous_snd.fst)).continuous_at\nend\n\n/-- The angle \u2221AAB at a point. -/\n@[simp] lemma oangle_self_left (p\u2081 p\u2082 : P) : \u2221 p\u2081 p\u2081 p\u2082 = 0 :=\nby simp [oangle]\n\n/-- The angle \u2221ABB at a point. -/\n@[simp] lemma oangle_self_right (p\u2081 p\u2082 : P) : \u2221 p\u2081 p\u2082 p\u2082 = 0 :=\nby simp [oangle]\n\n/-- The angle \u2221ABA at a point. -/\n@[simp] lemma oangle_self_left_right (p\u2081 p\u2082 : P) : \u2221 p\u2081 p\u2082 p\u2081 = 0 :=\n(o).oangle_self _\n\n/-- If the angle between three points is nonzero, the first two points are not equal. -/\nlemma left_ne_of_oangle_ne_zero {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0) : p\u2081 \u2260 p\u2082 :=\nby { rw \u2190@vsub_ne_zero V, exact (o).left_ne_zero_of_oangle_ne_zero h }\n\n/-- If the angle between three points is nonzero, the last two points are not equal. -/\nlemma right_ne_of_oangle_ne_zero {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0) : p\u2083 \u2260 p\u2082 :=\nby { rw \u2190@vsub_ne_zero V, exact (o).right_ne_zero_of_oangle_ne_zero h }\n\n/-- If the angle between three points is nonzero, the first and third points are not equal. -/\nlemma left_ne_right_of_oangle_ne_zero {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0) : p\u2081 \u2260 p\u2083 :=\nby { rw \u2190(vsub_left_injective p\u2082).ne_iff, exact (o).ne_of_oangle_ne_zero h }\n\n/-- If the angle between three points is `\u03c0`, the first two points are not equal. -/\nlemma left_ne_of_oangle_eq_pi {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = \u03c0) : p\u2081 \u2260 p\u2082 :=\nleft_ne_of_oangle_ne_zero (h.symm \u25b8 real.angle.pi_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `\u03c0`, the last two points are not equal. -/\nlemma right_ne_of_oangle_eq_pi {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = \u03c0) : p\u2083 \u2260 p\u2082 :=\nright_ne_of_oangle_ne_zero (h.symm \u25b8 real.angle.pi_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `\u03c0`, the first and third points are not equal. -/\nlemma left_ne_right_of_oangle_eq_pi {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = \u03c0) : p\u2081 \u2260 p\u2083 :=\nleft_ne_right_of_oangle_ne_zero (h.symm \u25b8 real.angle.pi_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `\u03c0 / 2`, the first two points are not equal. -/\nlemma left_ne_of_oangle_eq_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = (\u03c0 / 2 : \u211d)) : p\u2081 \u2260 p\u2082 :=\nleft_ne_of_oangle_ne_zero (h.symm \u25b8 real.angle.pi_div_two_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `\u03c0 / 2`, the last two points are not equal. -/\nlemma right_ne_of_oangle_eq_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = (\u03c0 / 2 : \u211d)) : p\u2083 \u2260 p\u2082 :=\nright_ne_of_oangle_ne_zero (h.symm \u25b8 real.angle.pi_div_two_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `\u03c0 / 2`, the first and third points are not equal. -/\nlemma left_ne_right_of_oangle_eq_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = (\u03c0 / 2 : \u211d)) :\n  p\u2081 \u2260 p\u2083 :=\nleft_ne_right_of_oangle_ne_zero (h.symm \u25b8 real.angle.pi_div_two_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `-\u03c0 / 2`, the first two points are not equal. -/\nlemma left_ne_of_oangle_eq_neg_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = (-\u03c0 / 2 : \u211d)) :\n  p\u2081 \u2260 p\u2082 :=\nleft_ne_of_oangle_ne_zero (h.symm \u25b8 real.angle.neg_pi_div_two_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `-\u03c0 / 2`, the last two points are not equal. -/\nlemma right_ne_of_oangle_eq_neg_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = (-\u03c0 / 2 : \u211d)) :\n  p\u2083 \u2260 p\u2082 :=\nright_ne_of_oangle_ne_zero (h.symm \u25b8 real.angle.neg_pi_div_two_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the angle between three points is `-\u03c0 / 2`, the first and third points are not equal. -/\nlemma left_ne_right_of_oangle_eq_neg_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = (-\u03c0 / 2 : \u211d)) :\n  p\u2081 \u2260 p\u2083 :=\nleft_ne_right_of_oangle_ne_zero (h.symm \u25b8 real.angle.neg_pi_div_two_ne_zero : \u2221 p\u2081 p\u2082 p\u2083 \u2260 0)\n\n/-- If the sign of the angle between three points is nonzero, the first two points are not\nequal. -/\nlemma left_ne_of_oangle_sign_ne_zero {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0) : p\u2081 \u2260 p\u2082 :=\nleft_ne_of_oangle_ne_zero (real.angle.sign_ne_zero_iff.1 h).1\n\n/-- If the sign of the angle between three points is nonzero, the last two points are not\nequal. -/\nlemma right_ne_of_oangle_sign_ne_zero {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0) : p\u2083 \u2260 p\u2082 :=\nright_ne_of_oangle_ne_zero (real.angle.sign_ne_zero_iff.1 h).1\n\n/-- If the sign of the angle between three points is nonzero, the first and third points are not\nequal. -/\nlemma left_ne_right_of_oangle_sign_ne_zero {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0) :\n  p\u2081 \u2260 p\u2083 :=\nleft_ne_right_of_oangle_ne_zero (real.angle.sign_ne_zero_iff.1 h).1\n\n/-- If the sign of the angle between three points is positive, the first two points are not\nequal. -/\nlemma left_ne_of_oangle_sign_eq_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = 1) : p\u2081 \u2260 p\u2082 :=\nleft_ne_of_oangle_sign_ne_zero (h.symm \u25b8 dec_trivial : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0)\n\n/-- If the sign of the angle between three points is positive, the last two points are not\nequal. -/\nlemma right_ne_of_oangle_sign_eq_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = 1) : p\u2083 \u2260 p\u2082 :=\nright_ne_of_oangle_sign_ne_zero (h.symm \u25b8 dec_trivial : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0)\n\n/-- If the sign of the angle between three points is positive, the first and third points are not\nequal. -/\nlemma left_ne_right_of_oangle_sign_eq_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = 1) : p\u2081 \u2260 p\u2083 :=\nleft_ne_right_of_oangle_sign_ne_zero (h.symm \u25b8 dec_trivial : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0)\n\n/-- If the sign of the angle between three points is negative, the first two points are not\nequal. -/\nlemma left_ne_of_oangle_sign_eq_neg_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = -1) : p\u2081 \u2260 p\u2082 :=\nleft_ne_of_oangle_sign_ne_zero (h.symm \u25b8 dec_trivial : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0)\n\n/-- If the sign of the angle between three points is negative, the last two points are not equal.\n-/\nlemma right_ne_of_oangle_sign_eq_neg_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = -1) : p\u2083 \u2260 p\u2082 :=\nright_ne_of_oangle_sign_ne_zero (h.symm \u25b8 dec_trivial : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0)\n\n/-- If the sign of the angle between three points is negative, the first and third points are not\nequal. -/\nlemma left_ne_right_of_oangle_sign_eq_neg_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = -1) :\n  p\u2081 \u2260 p\u2083 :=\nleft_ne_right_of_oangle_sign_ne_zero (h.symm \u25b8 dec_trivial : (\u2221 p\u2081 p\u2082 p\u2083).sign \u2260 0)\n\n/-- Reversing the order of the points passed to `oangle` negates the angle. -/\nlemma oangle_rev (p\u2081 p\u2082 p\u2083 : P) : \u2221 p\u2083 p\u2082 p\u2081 = -\u2221 p\u2081 p\u2082 p\u2083 :=\n(o).oangle_rev _ _\n\n/-- Adding an angle to that with the order of the points reversed results in 0. -/\n@[simp] lemma oangle_add_oangle_rev (p\u2081 p\u2082 p\u2083 : P) : \u2221 p\u2081 p\u2082 p\u2083 + \u2221 p\u2083 p\u2082 p\u2081 = 0 :=\n(o).oangle_add_oangle_rev _ _\n\n/-- An oriented angle is zero if and only if the angle with the order of the points reversed is\nzero. -/\nlemma oangle_eq_zero_iff_oangle_rev_eq_zero {p\u2081 p\u2082 p\u2083 : P} : \u2221 p\u2081 p\u2082 p\u2083 = 0 \u2194 \u2221 p\u2083 p\u2082 p\u2081 = 0 :=\n(o).oangle_eq_zero_iff_oangle_rev_eq_zero\n\n/-- An oriented angle is `\u03c0` if and only if the angle with the order of the points reversed is\n`\u03c0`. -/\nlemma oangle_eq_pi_iff_oangle_rev_eq_pi {p\u2081 p\u2082 p\u2083 : P} : \u2221 p\u2081 p\u2082 p\u2083 = \u03c0 \u2194 \u2221 p\u2083 p\u2082 p\u2081 = \u03c0 :=\n(o).oangle_eq_pi_iff_oangle_rev_eq_pi\n\n/-- An oriented angle is not zero or `\u03c0` if and only if the three points are affinely\nindependent. -/\nlemma oangle_ne_zero_and_ne_pi_iff_affine_independent {p\u2081 p\u2082 p\u2083 : P} :\n  (\u2221 p\u2081 p\u2082 p\u2083 \u2260 0 \u2227 \u2221 p\u2081 p\u2082 p\u2083 \u2260 \u03c0) \u2194 affine_independent \u211d ![p\u2081, p\u2082, p\u2083] :=\nbegin\n  rw [oangle, (o).oangle_ne_zero_and_ne_pi_iff_linear_independent,\n      affine_independent_iff_linear_independent_vsub \u211d _ (1 : fin 3),\n      \u2190linear_independent_equiv (fin_succ_above_equiv (1 : fin 3)).to_equiv],\n  convert iff.rfl,\n  ext i,\n  fin_cases i;\n    refl\nend\n\n/-- An oriented angle is zero or `\u03c0` if and only if the three points are collinear. -/\nlemma oangle_eq_zero_or_eq_pi_iff_collinear {p\u2081 p\u2082 p\u2083 : P} :\n  (\u2221 p\u2081 p\u2082 p\u2083 = 0 \u2228 \u2221 p\u2081 p\u2082 p\u2083 = \u03c0) \u2194 collinear \u211d ({p\u2081, p\u2082, p\u2083} : set P) :=\nby rw [\u2190not_iff_not, not_or_distrib, oangle_ne_zero_and_ne_pi_iff_affine_independent,\n       affine_independent_iff_not_collinear_set]\n\n/-- If twice the oriented angles between two triples of points are equal, one triple is affinely\nindependent if and only if the other is. -/\nlemma affine_independent_iff_of_two_zsmul_oangle_eq {p\u2081 p\u2082 p\u2083 p\u2084 p\u2085 p\u2086 : P}\n  (h : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 = (2 : \u2124) \u2022 \u2221 p\u2084 p\u2085 p\u2086) :\n  affine_independent \u211d ![p\u2081, p\u2082, p\u2083] \u2194 affine_independent \u211d ![p\u2084, p\u2085, p\u2086] :=\nby simp_rw [\u2190oangle_ne_zero_and_ne_pi_iff_affine_independent, \u2190real.angle.two_zsmul_ne_zero_iff, h]\n\n/-- If twice the oriented angles between two triples of points are equal, one triple is collinear\nif and only if the other is. -/\nlemma collinear_iff_of_two_zsmul_oangle_eq {p\u2081 p\u2082 p\u2083 p\u2084 p\u2085 p\u2086 : P}\n  (h : (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 = (2 : \u2124) \u2022 \u2221 p\u2084 p\u2085 p\u2086) :\n  collinear \u211d ({p\u2081, p\u2082, p\u2083} : set P) \u2194 collinear \u211d ({p\u2084, p\u2085, p\u2086} : set P) :=\nby simp_rw [\u2190oangle_eq_zero_or_eq_pi_iff_collinear, \u2190real.angle.two_zsmul_eq_zero_iff, h]\n\n/-- If corresponding pairs of points in two angles have the same vector span, twice those angles\nare equal. -/\nlemma two_zsmul_oangle_of_vector_span_eq {p\u2081 p\u2082 p\u2083 p\u2084 p\u2085 p\u2086 : P}\n  (h\u2081\u2082\u2084\u2085 : vector_span \u211d ({p\u2081, p\u2082} : set P) = vector_span \u211d ({p\u2084, p\u2085} : set P))\n  (h\u2083\u2082\u2086\u2085 : vector_span \u211d ({p\u2083, p\u2082} : set P) = vector_span \u211d ({p\u2086, p\u2085} : set P)) :\n  (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 = (2 : \u2124) \u2022 \u2221 p\u2084 p\u2085 p\u2086 :=\nbegin\n  simp_rw vector_span_pair at h\u2081\u2082\u2084\u2085 h\u2083\u2082\u2086\u2085,\n  exact (o).two_zsmul_oangle_of_span_eq_of_span_eq h\u2081\u2082\u2084\u2085 h\u2083\u2082\u2086\u2085\nend\n\n/-- If the lines determined by corresponding pairs of points in two angles are parallel, twice\nthose angles are equal. -/\nlemma two_zsmul_oangle_of_parallel {p\u2081 p\u2082 p\u2083 p\u2084 p\u2085 p\u2086 : P}\n  (h\u2081\u2082\u2084\u2085 : line[\u211d, p\u2081, p\u2082] \u2225 line[\u211d, p\u2084, p\u2085]) (h\u2083\u2082\u2086\u2085 : line[\u211d, p\u2083, p\u2082] \u2225 line[\u211d, p\u2086, p\u2085]) :\n  (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 = (2 : \u2124) \u2022 \u2221 p\u2084 p\u2085 p\u2086 :=\nbegin\n  rw affine_subspace.affine_span_pair_parallel_iff_vector_span_eq at h\u2081\u2082\u2084\u2085 h\u2083\u2082\u2086\u2085,\n  exact two_zsmul_oangle_of_vector_span_eq h\u2081\u2082\u2084\u2085 h\u2083\u2082\u2086\u2085\nend\n\n/-- Given three points not equal to `p`, the angle between the first and the second at `p` plus\nthe angle between the second and the third equals the angle between the first and the third. -/\n@[simp] lemma oangle_add {p p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) (hp\u2083 : p\u2083 \u2260 p) :\n  \u2221 p\u2081 p p\u2082 + \u2221 p\u2082 p p\u2083 = \u2221 p\u2081 p p\u2083 :=\n(o).oangle_add (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082) (vsub_ne_zero.2 hp\u2083)\n\n/-- Given three points not equal to `p`, the angle between the second and the third at `p` plus\nthe angle between the first and the second equals the angle between the first and the third. -/\n@[simp] lemma oangle_add_swap {p p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) (hp\u2083 : p\u2083 \u2260 p) :\n  \u2221 p\u2082 p p\u2083 + \u2221 p\u2081 p p\u2082 = \u2221 p\u2081 p p\u2083 :=\n(o).oangle_add_swap (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082) (vsub_ne_zero.2 hp\u2083)\n\n/-- Given three points not equal to `p`, the angle between the first and the third at `p` minus\nthe angle between the first and the second equals the angle between the second and the third. -/\n@[simp] lemma oangle_sub_left {p p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) (hp\u2083 : p\u2083 \u2260 p) :\n  \u2221 p\u2081 p p\u2083 - \u2221 p\u2081 p p\u2082 = \u2221 p\u2082 p p\u2083 :=\n(o).oangle_sub_left (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082) (vsub_ne_zero.2 hp\u2083)\n\n/-- Given three points not equal to `p`, the angle between the first and the third at `p` minus\nthe angle between the second and the third equals the angle between the first and the second. -/\n@[simp] lemma oangle_sub_right {p p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) (hp\u2083 : p\u2083 \u2260 p) :\n  \u2221 p\u2081 p p\u2083 - \u2221 p\u2082 p p\u2083 = \u2221 p\u2081 p p\u2082 :=\n(o).oangle_sub_right (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082) (vsub_ne_zero.2 hp\u2083)\n\n/-- Given three points not equal to `p`, adding the angles between them at `p` in cyclic order\nresults in 0. -/\n@[simp] lemma oangle_add_cyc3 {p p\u2081 p\u2082 p\u2083 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) (hp\u2083 : p\u2083 \u2260 p) :\n  \u2221 p\u2081 p p\u2082 + \u2221 p\u2082 p p\u2083 + \u2221 p\u2083 p p\u2081 = 0 :=\n(o).oangle_add_cyc3 (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082) (vsub_ne_zero.2 hp\u2083)\n\n/-- Pons asinorum, oriented angle-at-point form. -/\nlemma oangle_eq_oangle_of_dist_eq {p\u2081 p\u2082 p\u2083 : P} (h : dist p\u2081 p\u2082 = dist p\u2081 p\u2083) :\n  \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2082 p\u2083 p\u2081 :=\nbegin\n  simp_rw dist_eq_norm_vsub at h,\n  rw [oangle, oangle, \u2190vsub_sub_vsub_cancel_left p\u2083 p\u2082 p\u2081, \u2190vsub_sub_vsub_cancel_left p\u2082 p\u2083 p\u2081,\n      (o).oangle_sub_eq_oangle_sub_rev_of_norm_eq h]\nend\n\n/-- The angle at the apex of an isosceles triangle is `\u03c0` minus twice a base angle, oriented\nangle-at-point form. -/\nlemma oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq {p\u2081 p\u2082 p\u2083 : P} (hn : p\u2082 \u2260 p\u2083)\n  (h : dist p\u2081 p\u2082 = dist p\u2081 p\u2083) : \u2221 p\u2083 p\u2081 p\u2082 = \u03c0 - (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 :=\nbegin\n  simp_rw dist_eq_norm_vsub at h,\n  rw [oangle, oangle],\n  convert (o).oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq _ h using 1,\n  { rw [\u2190neg_vsub_eq_vsub_rev p\u2081 p\u2083, \u2190neg_vsub_eq_vsub_rev p\u2081 p\u2082, (o).oangle_neg_neg] },\n  { rw [\u2190(o).oangle_sub_eq_oangle_sub_rev_of_norm_eq h], simp },\n  { simpa using hn }\nend\n\n/-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/\nlemma abs_oangle_right_to_real_lt_pi_div_two_of_dist_eq {p\u2081 p\u2082 p\u2083 : P}\n  (h : dist p\u2081 p\u2082 = dist p\u2081 p\u2083) : |(\u2221 p\u2081 p\u2082 p\u2083).to_real| < \u03c0 / 2 :=\nbegin\n  simp_rw dist_eq_norm_vsub at h,\n  rw [oangle, \u2190vsub_sub_vsub_cancel_left p\u2083 p\u2082 p\u2081],\n  exact (o).abs_oangle_sub_right_to_real_lt_pi_div_two h\nend\n\n/-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/\nlemma abs_oangle_left_to_real_lt_pi_div_two_of_dist_eq {p\u2081 p\u2082 p\u2083 : P}\n  (h : dist p\u2081 p\u2082 = dist p\u2081 p\u2083) : |(\u2221 p\u2082 p\u2083 p\u2081).to_real| < \u03c0 / 2 :=\n(oangle_eq_oangle_of_dist_eq h) \u25b8 abs_oangle_right_to_real_lt_pi_div_two_of_dist_eq h\n\n/-- The cosine of the oriented angle at `p` between two points not equal to `p` equals that of the\nunoriented angle. -/\nlemma cos_oangle_eq_cos_angle {p p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) :\n  real.angle.cos (\u2221 p\u2081 p p\u2082) = real.cos (\u2220 p\u2081 p p\u2082) :=\n(o).cos_oangle_eq_cos_angle (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082)\n\n/-- The oriented angle at `p` between two points not equal to `p` is plus or minus the unoriented\nangle. -/\nlemma oangle_eq_angle_or_eq_neg_angle {p p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) :\n  \u2221 p\u2081 p p\u2082 = \u2220 p\u2081 p p\u2082 \u2228 \u2221 p\u2081 p p\u2082 = -\u2220 p\u2081 p p\u2082 :=\n(o).oangle_eq_angle_or_eq_neg_angle (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082)\n\n/-- The unoriented angle at `p` between two points not equal to `p` is the absolute value of the\noriented angle. -/\nlemma angle_eq_abs_oangle_to_real {p p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) :\n  \u2220 p\u2081 p p\u2082 = |(\u2221 p\u2081 p p\u2082).to_real| :=\n(o).angle_eq_abs_oangle_to_real (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082)\n\n/-- If the sign of the oriented angle at `p` between two points is zero, either one of the points\nequals `p` or the unoriented angle is 0 or \u03c0. -/\nlemma eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {p p\u2081 p\u2082 : P}\n  (h : (\u2221 p\u2081 p p\u2082).sign = 0) : p\u2081 = p \u2228 p\u2082 = p \u2228 \u2220 p\u2081 p p\u2082 = 0 \u2228 \u2220 p\u2081 p p\u2082 = \u03c0 :=\nbegin\n  convert (o).eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero h;\n    simp\nend\n\n/-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are\nequal, then the oriented angles are equal (even in degenerate cases). -/\nlemma oangle_eq_of_angle_eq_of_sign_eq {p\u2081 p\u2082 p\u2083 p\u2084 p\u2085 p\u2086 : P} (h : \u2220 p\u2081 p\u2082 p\u2083 = \u2220 p\u2084 p\u2085 p\u2086)\n  (hs : (\u2221 p\u2081 p\u2082 p\u2083).sign = (\u2221 p\u2084 p\u2085 p\u2086).sign) : \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2084 p\u2085 p\u2086 :=\n(o).oangle_eq_of_angle_eq_of_sign_eq h hs\n\n/-- If the signs of two nondegenerate oriented angles between points are equal, the oriented\nangles are equal if and only if the unoriented angles are equal. -/\nlemma angle_eq_iff_oangle_eq_of_sign_eq {p\u2081 p\u2082 p\u2083 p\u2084 p\u2085 p\u2086 : P} (hp\u2081 : p\u2081 \u2260 p\u2082) (hp\u2083 : p\u2083 \u2260 p\u2082)\n  (hp\u2084 : p\u2084 \u2260 p\u2085) (hp\u2086 : p\u2086 \u2260 p\u2085) (hs : (\u2221 p\u2081 p\u2082 p\u2083).sign = (\u2221 p\u2084 p\u2085 p\u2086).sign) :\n  \u2220 p\u2081 p\u2082 p\u2083 = \u2220 p\u2084 p\u2085 p\u2086 \u2194 \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2084 p\u2085 p\u2086 :=\n(o).angle_eq_iff_oangle_eq_of_sign_eq (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2083)\n                                      (vsub_ne_zero.2 hp\u2084) (vsub_ne_zero.2 hp\u2086) hs\n\n/-- The oriented angle between three points equals the unoriented angle if the sign is\npositive. -/\nlemma oangle_eq_angle_of_sign_eq_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = 1) :\n  \u2221 p\u2081 p\u2082 p\u2083 = \u2220 p\u2081 p\u2082 p\u2083 :=\n(o).oangle_eq_angle_of_sign_eq_one h\n\n/-- The oriented angle between three points equals minus the unoriented angle if the sign is\nnegative. -/\nlemma oangle_eq_neg_angle_of_sign_eq_neg_one {p\u2081 p\u2082 p\u2083 : P} (h : (\u2221 p\u2081 p\u2082 p\u2083).sign = -1) :\n  \u2221 p\u2081 p\u2082 p\u2083 = -\u2220 p\u2081 p\u2082 p\u2083 :=\n(o).oangle_eq_neg_angle_of_sign_eq_neg_one h\n\n/-- The unoriented angle at `p` between two points not equal to `p` is zero if and only if the\nunoriented angle is zero. -/\nlemma oangle_eq_zero_iff_angle_eq_zero {p p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2260 p) (hp\u2082 : p\u2082 \u2260 p) :\n  \u2221 p\u2081 p p\u2082 = 0 \u2194 \u2220 p\u2081 p p\u2082 = 0 :=\n(o).oangle_eq_zero_iff_angle_eq_zero (vsub_ne_zero.2 hp\u2081) (vsub_ne_zero.2 hp\u2082)\n\n/-- The oriented angle between three points is `\u03c0` if and only if the unoriented angle is `\u03c0`. -/\nlemma oangle_eq_pi_iff_angle_eq_pi {p\u2081 p\u2082 p\u2083 : P} : \u2221 p\u2081 p\u2082 p\u2083 = \u03c0 \u2194 \u2220 p\u2081 p\u2082 p\u2083 = \u03c0 :=\n(o).oangle_eq_pi_iff_angle_eq_pi\n\n/-- If the oriented angle between three points is `\u03c0 / 2`, so is the unoriented angle. -/\nlemma angle_eq_pi_div_two_of_oangle_eq_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = \u2191(\u03c0 / 2)) :\n  \u2220 p\u2081 p\u2082 p\u2083 = \u03c0 / 2 :=\nbegin\n  rw [angle, \u2190inner_product_geometry.inner_eq_zero_iff_angle_eq_pi_div_two],\n  exact (o).inner_eq_zero_of_oangle_eq_pi_div_two h\nend\n\n/-- If the oriented angle between three points is `\u03c0 / 2`, so is the unoriented angle\n(reversed). -/\nlemma angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two {p\u2081 p\u2082 p\u2083 : P} (h : \u2221 p\u2081 p\u2082 p\u2083 = \u2191(\u03c0 / 2)) :\n  \u2220 p\u2083 p\u2082 p\u2081 = \u03c0 / 2 :=\nbegin\n  rw angle_comm,\n  exact angle_eq_pi_div_two_of_oangle_eq_pi_div_two h,\nend\n\n/-- If the oriented angle between three points is `-\u03c0 / 2`, the unoriented angle is `\u03c0 / 2`. -/\nlemma angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p\u2081 p\u2082 p\u2083 : P}\n  (h : \u2221 p\u2081 p\u2082 p\u2083 = \u2191(-\u03c0 / 2)) : \u2220 p\u2081 p\u2082 p\u2083 = \u03c0 / 2 :=\nbegin\n  rw [angle, \u2190inner_product_geometry.inner_eq_zero_iff_angle_eq_pi_div_two],\n  exact (o).inner_eq_zero_of_oangle_eq_neg_pi_div_two h\nend\n\n/-- If the oriented angle between three points is `-\u03c0 / 2`, the unoriented angle (reversed) is\n`\u03c0 / 2`. -/\nlemma angle_rev_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p\u2081 p\u2082 p\u2083 : P}\n  (h : \u2221 p\u2081 p\u2082 p\u2083 = \u2191(-\u03c0 / 2)) : \u2220 p\u2083 p\u2082 p\u2081 = \u03c0 / 2 :=\nbegin\n  rw angle_comm,\n  exact angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two h\nend\n\n/-- Swapping the first and second points in an oriented angle negates the sign of that angle. -/\nlemma oangle_swap\u2081\u2082_sign (p\u2081 p\u2082 p\u2083 : P) : -(\u2221 p\u2081 p\u2082 p\u2083).sign = (\u2221 p\u2082 p\u2081 p\u2083).sign :=\nbegin\n  rw [eq_comm, oangle, oangle, \u2190(o).oangle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev,\n      \u2190vsub_sub_vsub_cancel_left p\u2081 p\u2083 p\u2082, \u2190neg_vsub_eq_vsub_rev p\u2083 p\u2082, sub_eq_add_neg,\n      neg_vsub_eq_vsub_rev p\u2082 p\u2081, add_comm, \u2190@neg_one_smul \u211d],\n  nth_rewrite 1 [\u2190one_smul \u211d (p\u2081 -\u1d65 p\u2082)],\n  rw (o).oangle_sign_smul_add_smul_right,\n  simp\nend\n\n/-- Swapping the first and third points in an oriented angle negates the sign of that angle. -/\nlemma oangle_swap\u2081\u2083_sign (p\u2081 p\u2082 p\u2083 : P) : -(\u2221 p\u2081 p\u2082 p\u2083).sign = (\u2221 p\u2083 p\u2082 p\u2081).sign :=\nby rw [oangle_rev, real.angle.sign_neg, neg_neg]\n\n/-- Swapping the second and third points in an oriented angle negates the sign of that angle. -/\nlemma oangle_swap\u2082\u2083_sign (p\u2081 p\u2082 p\u2083 : P) : -(\u2221 p\u2081 p\u2082 p\u2083).sign = (\u2221 p\u2081 p\u2083 p\u2082).sign :=\nby rw [oangle_swap\u2081\u2083_sign, \u2190oangle_swap\u2081\u2082_sign, oangle_swap\u2081\u2083_sign]\n\n/-- Rotating the points in an oriented angle does not change the sign of that angle. -/\nlemma oangle_rotate_sign (p\u2081 p\u2082 p\u2083 : P) : (\u2221 p\u2082 p\u2083 p\u2081).sign = (\u2221 p\u2081 p\u2082 p\u2083).sign :=\nby rw [\u2190oangle_swap\u2081\u2082_sign, oangle_swap\u2081\u2083_sign]\n\n/-- The oriented angle between three points is \u03c0 if and only if the second point is strictly\nbetween the other two. -/\nlemma oangle_eq_pi_iff_sbtw {p\u2081 p\u2082 p\u2083 : P} : \u2221 p\u2081 p\u2082 p\u2083 = \u03c0 \u2194 sbtw \u211d p\u2081 p\u2082 p\u2083 :=\nby rw [oangle_eq_pi_iff_angle_eq_pi, angle_eq_pi_iff_sbtw]\n\n/-- If the second of three points is strictly between the other two, the oriented angle at that\npoint is \u03c0. -/\nlemma _root_.sbtw.oangle\u2081\u2082\u2083_eq_pi {p\u2081 p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2081 p\u2082 p\u2083 = \u03c0 :=\noangle_eq_pi_iff_sbtw.2 h\n\n/-- If the second of three points is strictly between the other two, the oriented angle at that\npoint (reversed) is \u03c0. -/\nlemma _root_.sbtw.oangle\u2083\u2082\u2081_eq_pi {p\u2081 p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2083 p\u2082 p\u2081 = \u03c0 :=\nby rw [oangle_eq_pi_iff_oangle_rev_eq_pi, \u2190h.oangle\u2081\u2082\u2083_eq_pi]\n\n/-- If the second of three points is weakly between the other two, the oriented angle at the\nfirst point is zero. -/\nlemma _root_.wbtw.oangle\u2082\u2081\u2083_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : wbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2082 p\u2081 p\u2083 = 0 :=\nbegin\n  by_cases hp\u2082p\u2081 : p\u2082 = p\u2081, { simp [hp\u2082p\u2081] },\n  by_cases hp\u2083p\u2081 : p\u2083 = p\u2081, { simp [hp\u2083p\u2081] },\n  rw oangle_eq_zero_iff_angle_eq_zero hp\u2082p\u2081 hp\u2083p\u2081,\n  exact h.angle\u2082\u2081\u2083_eq_zero_of_ne hp\u2082p\u2081\nend\n\n/-- If the second of three points is strictly between the other two, the oriented angle at the\nfirst point is zero. -/\nlemma _root_.sbtw.oangle\u2082\u2081\u2083_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2082 p\u2081 p\u2083 = 0 :=\nh.wbtw.oangle\u2082\u2081\u2083_eq_zero\n\n/-- If the second of three points is weakly between the other two, the oriented angle at the\nfirst point (reversed) is zero. -/\nlemma _root_.wbtw.oangle\u2083\u2081\u2082_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : wbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2083 p\u2081 p\u2082 = 0 :=\nby rw [oangle_eq_zero_iff_oangle_rev_eq_zero, h.oangle\u2082\u2081\u2083_eq_zero]\n\n/-- If the second of three points is strictly between the other two, the oriented angle at the\nfirst point (reversed) is zero. -/\nlemma _root_.sbtw.oangle\u2083\u2081\u2082_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2083 p\u2081 p\u2082 = 0 :=\nh.wbtw.oangle\u2083\u2081\u2082_eq_zero\n\n/-- If the second of three points is weakly between the other two, the oriented angle at the\nthird point is zero. -/\nlemma _root_.wbtw.oangle\u2082\u2083\u2081_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : wbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2082 p\u2083 p\u2081 = 0 :=\nh.symm.oangle\u2082\u2081\u2083_eq_zero\n\n/-- If the second of three points is strictly between the other two, the oriented angle at the\nthird point is zero. -/\nlemma _root_.sbtw.oangle\u2082\u2083\u2081_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2082 p\u2083 p\u2081 = 0 :=\nh.wbtw.oangle\u2082\u2083\u2081_eq_zero\n\n/-- If the second of three points is weakly between the other two, the oriented angle at the\nthird point (reversed) is zero. -/\nlemma _root_.wbtw.oangle\u2081\u2083\u2082_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : wbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2081 p\u2083 p\u2082 = 0 :=\nh.symm.oangle\u2083\u2081\u2082_eq_zero\n\n/-- If the second of three points is strictly between the other two, the oriented angle at the\nthird point (reversed) is zero. -/\nlemma _root_.sbtw.oangle\u2081\u2083\u2082_eq_zero {p\u2081 p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2083) : \u2221 p\u2081 p\u2083 p\u2082 = 0 :=\nh.wbtw.oangle\u2081\u2083\u2082_eq_zero\n\n/-- The oriented angle between three points is zero if and only if one of the first and third\npoints is weakly between the other two. -/\nlemma oangle_eq_zero_iff_wbtw {p\u2081 p\u2082 p\u2083 : P} :\n  \u2221 p\u2081 p\u2082 p\u2083 = 0 \u2194 wbtw \u211d p\u2082 p\u2081 p\u2083 \u2228 wbtw \u211d p\u2082 p\u2083 p\u2081 :=\nbegin\n  by_cases hp\u2081p\u2082 : p\u2081 = p\u2082, { simp [hp\u2081p\u2082] },\n  by_cases hp\u2083p\u2082 : p\u2083 = p\u2082, { simp [hp\u2083p\u2082] },\n  rw [oangle_eq_zero_iff_angle_eq_zero hp\u2081p\u2082 hp\u2083p\u2082, angle_eq_zero_iff_ne_and_wbtw],\n  simp [hp\u2081p\u2082, hp\u2083p\u2082]\nend\n\n/-- An oriented angle is unchanged by replacing the first point by one weakly further away on the\nsame ray. -/\nlemma _root_.wbtw.oangle_eq_left {p\u2081 p\u2081' p\u2082 p\u2083 : P} (h : wbtw \u211d p\u2082 p\u2081 p\u2081') (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082) :\n  \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2081' p\u2082 p\u2083 :=\nbegin\n  by_cases hp\u2083p\u2082 : p\u2083 = p\u2082, { simp [hp\u2083p\u2082] },\n  by_cases hp\u2081'p\u2082 : p\u2081' = p\u2082, { rw [hp\u2081'p\u2082, wbtw_self_iff] at h, exact false.elim (hp\u2081p\u2082 h) },\n  rw [\u2190oangle_add hp\u2081'p\u2082 hp\u2081p\u2082 hp\u2083p\u2082, h.oangle\u2083\u2081\u2082_eq_zero, zero_add]\nend\n\n/-- An oriented angle is unchanged by replacing the first point by one strictly further away on\nthe same ray. -/\nlemma _root_.sbtw.oangle_eq_left {p\u2081 p\u2081' p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2082 p\u2081 p\u2081') :\n  \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2081' p\u2082 p\u2083 :=\nh.wbtw.oangle_eq_left h.ne_left\n\n/-- An oriented angle is unchanged by replacing the third point by one weakly further away on the\nsame ray. -/\nlemma _root_.wbtw.oangle_eq_right {p\u2081 p\u2082 p\u2083 p\u2083' : P} (h : wbtw \u211d p\u2082 p\u2083 p\u2083') (hp\u2083p\u2082 : p\u2083 \u2260 p\u2082) :\n  \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2081 p\u2082 p\u2083' :=\nby rw [oangle_rev, h.oangle_eq_left hp\u2083p\u2082, \u2190oangle_rev]\n\n/-- An oriented angle is unchanged by replacing the third point by one strictly further away on\nthe same ray. -/\nlemma _root_.sbtw.oangle_eq_right {p\u2081 p\u2082 p\u2083 p\u2083' : P} (h : sbtw \u211d p\u2082 p\u2083 p\u2083') :\n  \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2081 p\u2082 p\u2083' :=\nh.wbtw.oangle_eq_right h.ne_left\n\n/-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment\nbetween it and the second point. -/\n@[simp] lemma oangle_midpoint_left (p\u2081 p\u2082 p\u2083 : P) : \u2221 (midpoint \u211d p\u2081 p\u2082) p\u2082 p\u2083 = \u2221 p\u2081 p\u2082 p\u2083 :=\nbegin\n  by_cases h : p\u2081 = p\u2082, { simp [h] },\n  exact (sbtw_midpoint_of_ne \u211d h).symm.oangle_eq_left\nend\n\n/-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment\nbetween the second point and that point. -/\n@[simp] lemma oangle_midpoint_rev_left (p\u2081 p\u2082 p\u2083 : P) : \u2221 (midpoint \u211d p\u2082 p\u2081) p\u2082 p\u2083 = \u2221 p\u2081 p\u2082 p\u2083 :=\nby rw [midpoint_comm, oangle_midpoint_left]\n\n/-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment\nbetween it and the second point. -/\n@[simp] lemma oangle_midpoint_right (p\u2081 p\u2082 p\u2083 : P) : \u2221 p\u2081 p\u2082 (midpoint \u211d p\u2083 p\u2082) = \u2221 p\u2081 p\u2082 p\u2083 :=\nbegin\n  by_cases h : p\u2083 = p\u2082, { simp [h] },\n  exact (sbtw_midpoint_of_ne \u211d h).symm.oangle_eq_right\nend\n\n/-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment\nbetween the second point and that point. -/\n@[simp] \n\n/-- Replacing the first point by one on the same line but the opposite ray adds \u03c0 to the oriented\nangle. -/\nlemma _root_.sbtw.oangle_eq_add_pi_left {p\u2081 p\u2081' p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2081')\n  (hp\u2083p\u2082 : p\u2083 \u2260 p\u2082) : \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2081' p\u2082 p\u2083 + \u03c0 :=\nby rw [\u2190h.oangle\u2081\u2082\u2083_eq_pi, oangle_add_swap h.left_ne h.right_ne hp\u2083p\u2082]\n\n/-- Replacing the third point by one on the same line but the opposite ray adds \u03c0 to the oriented\nangle. -/\nlemma _root_.sbtw.oangle_eq_add_pi_right {p\u2081 p\u2082 p\u2083 p\u2083' : P} (h : sbtw \u211d p\u2083 p\u2082 p\u2083')\n  (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082) : \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2081 p\u2082 p\u2083' + \u03c0 :=\nby rw [\u2190h.oangle\u2083\u2082\u2081_eq_pi, oangle_add hp\u2081p\u2082 h.right_ne h.left_ne]\n\n/-- Replacing both the first and third points by ones on the same lines but the opposite rays\ndoes not change the oriented angle (vertically opposite angles). -/\nlemma _root_.sbtw.oangle_eq_left_right {p\u2081 p\u2081' p\u2082 p\u2083 p\u2083' : P} (h\u2081 : sbtw \u211d p\u2081 p\u2082 p\u2081')\n  (h\u2083 : sbtw \u211d p\u2083 p\u2082 p\u2083') : \u2221 p\u2081 p\u2082 p\u2083 = \u2221 p\u2081' p\u2082 p\u2083' :=\nby rw [h\u2081.oangle_eq_add_pi_left h\u2083.left_ne, h\u2083.oangle_eq_add_pi_right h\u2081.right_ne, add_assoc,\n       real.angle.coe_pi_add_coe_pi, add_zero]\n\n/-- Replacing the first point by one on the same line does not change twice the oriented angle. -/\nlemma _root_.collinear.two_zsmul_oangle_eq_left {p\u2081 p\u2081' p\u2082 p\u2083 : P}\n  (h : collinear \u211d ({p\u2081, p\u2082, p\u2081'} : set P)) (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082) (hp\u2081'p\u2082 : p\u2081' \u2260 p\u2082) :\n  (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 = (2 : \u2124) \u2022 \u2221 p\u2081' p\u2082 p\u2083 :=\nbegin\n  by_cases hp\u2083p\u2082 : p\u2083 = p\u2082, { simp [hp\u2083p\u2082] },\n  rcases h.wbtw_or_wbtw_or_wbtw with hw | hw | hw,\n  { have hw' : sbtw \u211d p\u2081 p\u2082 p\u2081' := \u27e8hw, hp\u2081p\u2082.symm, hp\u2081'p\u2082.symm\u27e9,\n    rw [hw'.oangle_eq_add_pi_left hp\u2083p\u2082, smul_add, real.angle.two_zsmul_coe_pi, add_zero] },\n  { rw hw.oangle_eq_left hp\u2081'p\u2082 },\n  { rw hw.symm.oangle_eq_left hp\u2081p\u2082 }\nend\n\n/-- Replacing the third point by one on the same line does not change twice the oriented angle. -/\nlemma _root_.collinear.two_zsmul_oangle_eq_right {p\u2081 p\u2082 p\u2083 p\u2083' : P}\n  (h : collinear \u211d ({p\u2083, p\u2082, p\u2083'} : set P)) (hp\u2083p\u2082 : p\u2083 \u2260 p\u2082) (hp\u2083'p\u2082 : p\u2083' \u2260 p\u2082) :\n  (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083 = (2 : \u2124) \u2022 \u2221 p\u2081 p\u2082 p\u2083' :=\nby rw [oangle_rev, smul_neg, h.two_zsmul_oangle_eq_left hp\u2083p\u2082 hp\u2083'p\u2082, \u2190smul_neg, \u2190oangle_rev]\n\n/-- Two different points are equidistant from a third point if and only if that third point\nequals some multiple of a `\u03c0 / 2` rotation of the vector between those points, plus the midpoint\nof those points. -/\nlemma dist_eq_iff_eq_smul_rotation_pi_div_two_vadd_midpoint {p\u2081 p\u2082 p : P} (h : p\u2081 \u2260 p\u2082) :\n  dist p\u2081 p = dist p\u2082 p \u2194\n    \u2203 r : \u211d, r \u2022 ((o).rotation (\u03c0 / 2 : \u211d) (p\u2082 -\u1d65 p\u2081)) +\u1d65 midpoint \u211d p\u2081 p\u2082 = p :=\nbegin\n  refine \u27e8\u03bb hd, _, \u03bb hr, _\u27e9,\n  { have hi : \u27eap\u2082 -\u1d65 p\u2081, p -\u1d65 midpoint \u211d p\u2081 p\u2082\u27eb = 0,\n    { rw [@dist_eq_norm_vsub' V, @dist_eq_norm_vsub' V,\n          \u2190mul_self_inj (norm_nonneg _) (norm_nonneg _), \u2190real_inner_self_eq_norm_mul_norm,\n          \u2190real_inner_self_eq_norm_mul_norm] at hd,\n      simp_rw [vsub_midpoint, \u2190vsub_sub_vsub_cancel_left p\u2082 p\u2081 p, inner_sub_left,\n               inner_add_right, inner_smul_right, hd, real_inner_comm (p -\u1d65 p\u2081)],\n      abel },\n    rw [@orientation.inner_eq_zero_iff_eq_zero_or_eq_smul_rotation_pi_div_two V _ _ _ o,\n        or_iff_right (vsub_ne_zero.2 h.symm)] at hi,\n    rcases hi with \u27e8r, hr\u27e9,\n    rw [eq_comm, \u2190eq_vadd_iff_vsub_eq] at hr,\n    exact \u27e8r, hr.symm\u27e9 },\n  { rcases hr with \u27e8r, rfl\u27e9,\n    simp_rw [@dist_eq_norm_vsub V, vsub_vadd_eq_vsub_sub, left_vsub_midpoint,\n             right_vsub_midpoint, inv_of_eq_inv, \u2190neg_vsub_eq_vsub_rev p\u2082 p\u2081,\n             \u2190mul_self_inj (norm_nonneg _) (norm_nonneg _), \u2190real_inner_self_eq_norm_mul_norm,\n             inner_sub_sub_self],\n    simp [-neg_vsub_eq_vsub_rev] }\nend\n\nopen affine_subspace\n\n/-- Given two pairs of distinct points on the same line, such that the vectors between those\npairs of points are on the same ray (oriented in the same direction on that line), and a fifth\npoint, the angles at the fifth point between each of those two pairs of points have the same\nsign. -/\nlemma _root_.collinear.oangle_sign_of_same_ray_vsub {p\u2081 p\u2082 p\u2083 p\u2084 : P} (p\u2085 : P) (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082)\n  (hp\u2083p\u2084 : p\u2083 \u2260 p\u2084) (hc : collinear \u211d ({p\u2081, p\u2082, p\u2083, p\u2084} : set P))\n  (hr : same_ray \u211d (p\u2082 -\u1d65 p\u2081) (p\u2084 -\u1d65 p\u2083)) : (\u2221 p\u2081 p\u2085 p\u2082).sign = (\u2221 p\u2083 p\u2085 p\u2084).sign :=\nbegin\n  by_cases hc\u2085\u2081\u2082 : collinear \u211d ({p\u2085, p\u2081, p\u2082} : set P),\n  { have hc\u2085\u2081\u2082\u2083\u2084 : collinear \u211d ({p\u2085, p\u2081, p\u2082, p\u2083, p\u2084} : set P) :=\n      (hc.collinear_insert_iff_of_ne (set.mem_insert _ _)\n                                     (set.mem_insert_of_mem _ (set.mem_insert _ _)) hp\u2081p\u2082).2 hc\u2085\u2081\u2082,\n    have hc\u2085\u2083\u2084 : collinear \u211d ({p\u2085, p\u2083, p\u2084} : set P) :=\n      (hc.collinear_insert_iff_of_ne\n        (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert _ _)))\n        (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert_of_mem _\n          (set.mem_singleton _)))) hp\u2083p\u2084).1 hc\u2085\u2081\u2082\u2083\u2084,\n    rw set.insert_comm at hc\u2085\u2081\u2082 hc\u2085\u2083\u2084,\n    have hs\u2081\u2085\u2082 := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc\u2085\u2081\u2082,\n    have hs\u2083\u2085\u2084 := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc\u2085\u2083\u2084,\n    rw \u2190real.angle.sign_eq_zero_iff at hs\u2081\u2085\u2082 hs\u2083\u2085\u2084,\n    rw [hs\u2081\u2085\u2082, hs\u2083\u2085\u2084] },\n  { let s : set (P \u00d7 P \u00d7 P) :=\n      (\u03bb x : line[\u211d, p\u2081, p\u2082] \u00d7 V, (x.1, p\u2085, x.2 +\u1d65 x.1)) ''\n        set.univ \u00d7\u02e2 {v | same_ray \u211d (p\u2082 -\u1d65 p\u2081) v \u2227 v \u2260 0},\n    have hco : is_connected s,\n    { haveI : connected_space line[\u211d, p\u2081, p\u2082] := add_torsor.connected_space _ _,\n      exact (is_connected_univ.prod (is_connected_set_of_same_ray_and_ne_zero\n        (vsub_ne_zero.2 hp\u2081p\u2082.symm))).image _\n          ((continuous_fst.subtype_coe.prod_mk\n            (continuous_const.prod_mk\n              (continuous_snd.vadd continuous_fst.subtype_coe))).continuous_on) },\n    have hf : continuous_on (\u03bb p : P \u00d7 P \u00d7 P, \u2221 p.1 p.2.1 p.2.2) s,\n    { refine continuous_at.continuous_on (\u03bb p hp, continuous_at_oangle _ _),\n      all_goals { simp_rw [s, set.mem_image, set.mem_prod, set.mem_univ, true_and,\n                           prod.ext_iff] at hp,\n                  obtain \u27e8q\u2081, q\u2085, q\u2082\u27e9 := p,\n                  dsimp only at \u22a2 hp,\n                  obtain \u27e8\u27e8\u27e8q, hq\u27e9, v\u27e9, hv, rfl, rfl, rfl\u27e9 := hp,\n                  dsimp only [subtype.coe_mk, set.mem_set_of] at \u22a2 hv,\n                  obtain \u27e8hvr, -\u27e9 := hv,\n                  rintro rfl,\n                  refine hc\u2085\u2081\u2082 ((collinear_insert_iff_of_mem_affine_span _).2\n                                  (collinear_pair _ _ _)) },\n      { exact hq },\n      { refine vadd_mem_of_mem_direction _ hq,\n        rw \u2190exists_nonneg_left_iff_same_ray (vsub_ne_zero.2 hp\u2081p\u2082.symm) at hvr,\n        obtain \u27e8r, -, rfl\u27e9 := hvr,\n        rw direction_affine_span,\n        exact smul_vsub_rev_mem_vector_span_pair _ _ _ } },\n    have hsp : \u2200 p : P \u00d7 P \u00d7 P, p \u2208 s \u2192 \u2221 p.1 p.2.1 p.2.2 \u2260 0 \u2227 \u2221 p.1 p.2.1 p.2.2 \u2260 \u03c0,\n    { intros p hp,\n      simp_rw [s, set.mem_image, set.mem_prod, set.mem_set_of, set.mem_univ, true_and,\n               prod.ext_iff] at hp,\n      obtain \u27e8q\u2081, q\u2085, q\u2082\u27e9 := p,\n      dsimp only at \u22a2 hp,\n      obtain \u27e8\u27e8\u27e8q, hq\u27e9, v\u27e9, hv, rfl, rfl, rfl\u27e9 := hp,\n      dsimp only [subtype.coe_mk, set.mem_set_of] at \u22a2 hv,\n      obtain \u27e8hvr, hv0\u27e9 := hv,\n      rw \u2190exists_nonneg_left_iff_same_ray (vsub_ne_zero.2 hp\u2081p\u2082.symm) at hvr,\n      obtain \u27e8r, -, rfl\u27e9 := hvr,\n      change q \u2208 line[\u211d, p\u2081, p\u2082] at hq,\n      rw [oangle_ne_zero_and_ne_pi_iff_affine_independent],\n      refine affine_independent_of_ne_of_mem_of_not_mem_of_mem _ hq\n        (\u03bb h, hc\u2085\u2081\u2082 ((collinear_insert_iff_of_mem_affine_span h).2 (collinear_pair _ _ _))) _,\n      { rwa [\u2190@vsub_ne_zero V, vsub_vadd_eq_vsub_sub, vsub_self, zero_sub, neg_ne_zero] },\n      { refine vadd_mem_of_mem_direction _ hq,\n        rw direction_affine_span,\n        exact smul_vsub_rev_mem_vector_span_pair _ _ _ } },\n    have hp\u2081p\u2082s : (p\u2081, p\u2085, p\u2082) \u2208 s,\n    { simp_rw [s, set.mem_image, set.mem_prod, set.mem_set_of, set.mem_univ, true_and,\n               prod.ext_iff],\n      refine \u27e8\u27e8\u27e8p\u2081, left_mem_affine_span_pair _ _ _\u27e9, p\u2082 -\u1d65 p\u2081\u27e9,\n              \u27e8same_ray.rfl, vsub_ne_zero.2 hp\u2081p\u2082.symm\u27e9, _\u27e9,\n      simp },\n    have hp\u2083p\u2084s : (p\u2083, p\u2085, p\u2084) \u2208 s,\n    { simp_rw [s, set.mem_image, set.mem_prod, set.mem_set_of, set.mem_univ, true_and,\n               prod.ext_iff],\n      refine \u27e8\u27e8\u27e8p\u2083,\n                hc.mem_affine_span_of_mem_of_ne\n                  (set.mem_insert _ _)\n                  (set.mem_insert_of_mem _ (set.mem_insert _ _))\n                  (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert _ _)))\n                  hp\u2081p\u2082\u27e9, p\u2084 -\u1d65 p\u2083\u27e9, \u27e8hr, vsub_ne_zero.2 hp\u2083p\u2084.symm\u27e9, _\u27e9,\n      simp },\n    convert real.angle.sign_eq_of_continuous_on hco hf hsp hp\u2083p\u2084s hp\u2081p\u2082s }\nend\n\n/-- Given three points in strict order on the same line, and a fourth point, the angles at the\nfourth point between the first and second or second and third points have the same sign. -/\nlemma _root_.sbtw.oangle_sign_eq {p\u2081 p\u2082 p\u2083 : P} (p\u2084 : P) (h : sbtw \u211d p\u2081 p\u2082 p\u2083) :\n  (\u2221 p\u2081 p\u2084 p\u2082).sign = (\u2221 p\u2082 p\u2084 p\u2083).sign :=\nbegin\n  have hc : collinear \u211d ({p\u2081, p\u2082, p\u2082, p\u2083} : set P), { simpa using h.wbtw.collinear },\n  exact hc.oangle_sign_of_same_ray_vsub _ h.left_ne h.ne_right h.wbtw.same_ray_vsub\nend\n\n/-- Given three points in weak order on the same line, with the first not equal to the second,\nand a fourth point, the angles at the fourth point between the first and second or first and\nthird points have the same sign. -/\nlemma _root_.wbtw.oangle_sign_eq_of_ne_left {p\u2081 p\u2082 p\u2083 : P} (p\u2084 : P) (h : wbtw \u211d p\u2081 p\u2082 p\u2083)\n  (hne : p\u2081 \u2260 p\u2082) : (\u2221 p\u2081 p\u2084 p\u2082).sign = (\u2221 p\u2081 p\u2084 p\u2083).sign :=\nbegin\n  have hc : collinear \u211d ({p\u2081, p\u2082, p\u2081, p\u2083} : set P),\n  { simpa [set.insert_comm p\u2082] using h.collinear },\n  exact hc.oangle_sign_of_same_ray_vsub _ hne (h.left_ne_right_of_ne_left hne.symm)\n    h.same_ray_vsub_left\nend\n\n/-- Given three points in strict order on the same line, and a fourth point, the angles at the\nfourth point between the first and second or first and third points have the same sign. -/\nlemma _root_.sbtw.oangle_sign_eq_left {p\u2081 p\u2082 p\u2083 : P} (p\u2084 : P) (h : sbtw \u211d p\u2081 p\u2082 p\u2083) :\n  (\u2221 p\u2081 p\u2084 p\u2082).sign = (\u2221 p\u2081 p\u2084 p\u2083).sign :=\nh.wbtw.oangle_sign_eq_of_ne_left _ h.left_ne\n\n/-- Given three points in weak order on the same line, with the second not equal to the third,\nand a fourth point, the angles at the fourth point between the second and third or first and\nthird points have the same sign. -/\nlemma _root_.wbtw.oangle_sign_eq_of_ne_right {p\u2081 p\u2082 p\u2083 : P} (p\u2084 : P) (h : wbtw \u211d p\u2081 p\u2082 p\u2083)\n  (hne : p\u2082 \u2260 p\u2083) : (\u2221 p\u2082 p\u2084 p\u2083).sign = (\u2221 p\u2081 p\u2084 p\u2083).sign :=\nby simp_rw [oangle_rev p\u2083, real.angle.sign_neg, h.symm.oangle_sign_eq_of_ne_left _ hne.symm]\n\n/-- Given three points in strict order on the same line, and a fourth point, the angles at the\nfourth point between the second and third or first and third points have the same sign. -/\nlemma _root_.sbtw.oangle_sign_eq_right {p\u2081 p\u2082 p\u2083 : P} (p\u2084 : P) (h : sbtw \u211d p\u2081 p\u2082 p\u2083) :\n  (\u2221 p\u2082 p\u2084 p\u2083).sign = (\u2221 p\u2081 p\u2084 p\u2083).sign :=\nh.wbtw.oangle_sign_eq_of_ne_right _ h.ne_right\n\n/-- Given two points in an affine subspace, the angles between those two points at two other\npoints on the same side of that subspace have the same sign. -/\nlemma _root_.affine_subspace.s_same_side.oangle_sign_eq {s : affine_subspace \u211d P}\n  {p\u2081 p\u2082 p\u2083 p\u2084 : P} (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2208 s) (hp\u2083p\u2084 : s.s_same_side p\u2083 p\u2084) :\n  (\u2221 p\u2081 p\u2084 p\u2082).sign = (\u2221 p\u2081 p\u2083 p\u2082).sign :=\nbegin\n  by_cases h : p\u2081 = p\u2082, { simp [h] },\n  let sp : set (P \u00d7 P \u00d7 P) := (\u03bb p : P, (p\u2081, p, p\u2082)) '' {p | s.s_same_side p\u2083 p},\n  have hc : is_connected sp := (is_connected_set_of_s_same_side hp\u2083p\u2084.2.1 hp\u2083p\u2084.nonempty).image\n    _ (continuous_const.prod_mk (continuous.prod.mk_left _)).continuous_on,\n  have hf : continuous_on (\u03bb p : P \u00d7 P \u00d7 P, \u2221 p.1 p.2.1 p.2.2) sp,\n  { refine continuous_at.continuous_on (\u03bb p hp, continuous_at_oangle _ _),\n    all_goals { simp_rw [sp, set.mem_image, set.mem_set_of] at hp,\n                obtain \u27e8p', hp', rfl\u27e9 := hp,\n                dsimp only,\n                rintro rfl },\n    { exact hp'.2.2 hp\u2081 },\n    { exact hp'.2.2 hp\u2082 } },\n  have hsp : \u2200 p : P \u00d7 P \u00d7 P, p \u2208 sp \u2192 \u2221 p.1 p.2.1 p.2.2 \u2260 0 \u2227 \u2221 p.1 p.2.1 p.2.2 \u2260 \u03c0,\n  { intros p hp,\n    simp_rw [sp, set.mem_image, set.mem_set_of] at hp,\n    obtain \u27e8p', hp', rfl\u27e9 := hp,\n    dsimp only,\n    rw [oangle_ne_zero_and_ne_pi_iff_affine_independent],\n    exact affine_independent_of_ne_of_mem_of_not_mem_of_mem h hp\u2081 hp'.2.2 hp\u2082 },\n  have hp\u2083 : (p\u2081, p\u2083, p\u2082) \u2208 sp :=\n    set.mem_image_of_mem _ (s_same_side_self_iff.2 \u27e8hp\u2083p\u2084.nonempty, hp\u2083p\u2084.2.1\u27e9),\n  have hp\u2084 : (p\u2081, p\u2084, p\u2082) \u2208 sp := set.mem_image_of_mem _ hp\u2083p\u2084,\n  convert real.angle.sign_eq_of_continuous_on hc hf hsp hp\u2083 hp\u2084\nend\n\n/-- Given two points in an affine subspace, the angles between those two points at two other\npoints on opposite sides of that subspace have opposite signs. -/\nlemma _root_.affine_subspace.s_opp_side.oangle_sign_eq_neg {s : affine_subspace \u211d P}\n  {p\u2081 p\u2082 p\u2083 p\u2084 : P} (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2208 s) (hp\u2083p\u2084 : s.s_opp_side p\u2083 p\u2084) :\n  (\u2221 p\u2081 p\u2084 p\u2082).sign = -(\u2221 p\u2081 p\u2083 p\u2082).sign :=\nbegin\n  have hp\u2081p\u2083 : p\u2081 \u2260 p\u2083, { rintro rfl, exact hp\u2083p\u2084.left_not_mem hp\u2081 },\n  rw [\u2190(hp\u2083p\u2084.symm.trans (s_opp_side_point_reflection hp\u2081 hp\u2083p\u2084.left_not_mem)).oangle_sign_eq\n          hp\u2081 hp\u2082, \u2190oangle_rotate_sign p\u2081, \u2190oangle_rotate_sign p\u2081, oangle_swap\u2081\u2083_sign,\n      (sbtw_point_reflection_of_ne \u211d hp\u2081p\u2083).symm.oangle_sign_eq _],\nend\n\nend euclidean_geometry\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/angle/oriented/affine.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7195947252538849}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Michael Howes\n\nThe functor Grp \u2192 Ab which is the left adjoint\nof the forgetful functor Ab \u2192 Grp.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.group_theory.quotient_group\nimport Mathlib.tactic.group\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\n\n-- let G be a group\n\n/-- The commutator subgroup of a group G is the normal subgroup\n  generated by the commutators [p,q]=`p*q*p\u207b\u00b9*q\u207b\u00b9` -/\ndef commutator (G : Type u) [group G] : subgroup G :=\n  subgroup.normal_closure (set_of fun (x : G) => \u2203 (p : G), \u2203 (q : G), p * q * (p\u207b\u00b9) * (q\u207b\u00b9) = x)\n\n/-- The abelianization of G is the quotient of G by its commutator subgroup -/\ndef abelianization (G : Type u) [group G] := quotient_group.quotient (commutator G)\n\nnamespace abelianization\n\n\nprotected instance comm_group (G : Type u) [group G] : comm_group (abelianization G) :=\n  comm_group.mk group.mul sorry group.one sorry sorry group.inv group.div sorry sorry\n\nprotected instance inhabited (G : Type u) [group G] : Inhabited (abelianization G) :=\n  { default := 1 }\n\n/-- `of` is the canonical projection from G to its abelianization. -/\ndef of {G : Type u} [group G] : G \u2192* abelianization G := monoid_hom.mk quotient_group.mk sorry sorry\n\n-- so far -- built G\u1d43\u1d47 and proved it's an abelian group.\n\n-- defined `of : G \u2192 G\u1d43\u1d47`\n\n-- let A be an abelian group and let f be a group hom from G to A\n\ntheorem commutator_subset_ker {G : Type u} [group G] {A : Type v} [comm_group A] (f : G \u2192* A) :\n    commutator G \u2264 monoid_hom.ker f :=\n  sorry\n\n/-- If `f : G \u2192 A` is a group homomorphism to an abelian group, then `lift f` is the unique map from\n  the abelianization of a `G` to `A` that factors through `f`. -/\ndef lift {G : Type u} [group G] {A : Type v} [comm_group A] (f : G \u2192* A) : abelianization G \u2192* A :=\n  quotient_group.lift (commutator G) f sorry\n\n@[simp] theorem lift.of {G : Type u} [group G] {A : Type v} [comm_group A] (f : G \u2192* A) (x : G) :\n    coe_fn (lift f) (coe_fn of x) = coe_fn f x :=\n  rfl\n\ntheorem lift.unique {G : Type u} [group G] {A : Type v} [comm_group A] (f : G \u2192* A)\n    (\u03c6 : abelianization G \u2192* A) (h\u03c6 : \u2200 (x : G), coe_fn \u03c6 (coe_fn of x) = coe_fn f x)\n    {x : abelianization G} : coe_fn \u03c6 x = coe_fn (lift f) x :=\n  quotient_group.induction_on x h\u03c6\n\n/-- See note [partially-applied ext lemmas]. -/\ntheorem hom_ext {G : Type u} [group G] {A : Type v} [monoid A] (\u03c6 : abelianization G \u2192* A)\n    (\u03c8 : abelianization G \u2192* A) (h : monoid_hom.comp \u03c6 of = monoid_hom.comp \u03c8 of) : \u03c6 = \u03c8 :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/group_theory/abelianization_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7195947238694544}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module measure_theory.covering.differentiation\n! leanprover-community/mathlib commit 57ac39bd365c2f80589a700f9fbb664d3a1a30c2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Covering.VitaliFamily\nimport Mathbin.MeasureTheory.Measure.Regular\nimport Mathbin.MeasureTheory.Function.AeMeasurableOrder\nimport Mathbin.MeasureTheory.Integral.Lebesgue\nimport Mathbin.MeasureTheory.Integral.Average\nimport Mathbin.MeasureTheory.Decomposition.Lebesgue\n\n/-!\n# Differentiation of measures\n\nOn a second countable metric space with a measure `\u03bc`, consider a Vitali family (i.e., for each `x`\none has a family of sets shrinking to `x`, with a good behavior with respect to covering theorems).\nConsider also another measure `\u03c1`. Then, for almost every `x`, the ratio `\u03c1 a / \u03bc a` converges when\n`a` shrinks to `x` along the Vitali family, towards the Radon-Nikodym derivative of `\u03c1` with\nrespect to `\u03bc`. This is the main theorem on differentiation of measures.\n\nThis theorem is proved in this file, under the name `vitali_family.ae_tendsto_rn_deriv`. Note that,\nalmost surely, `\u03bc a` is eventually positive and finite (see\n`vitali_family.ae_eventually_measure_pos` and `vitali_family.eventually_measure_lt_top`), so the\nratio really makes sense.\n\nFor concrete applications, one needs concrete instances of Vitali families, as provided for instance\nby `besicovitch.vitali_family` (for balls) or by `vitali.vitali_family` (for doubling measures).\n\nSpecific applications to Lebesgue density points and the Lebesgue differentiation theorem are also\nderived:\n* `vitali_family.ae_tendsto_measure_inter_div` states that, for almost every point `x \u2208 s`,\n  then `\u03bc (s \u2229 a) / \u03bc a` tends to `1` as `a` shrinks to `x` along a Vitali family.\n* `vitali_family.ae_tendsto_average_norm_sub` states that, for almost every point `x`, then the\n  average of `y \u21a6 \u2016f y - f x\u2016` on `a` tends to `0` as `a` shrinks to `x` along a Vitali family.\n\n## Sketch of proof\n\nLet `v` be a Vitali family for `\u03bc`. Assume for simplicity that `\u03c1` is absolutely continuous with\nrespect to `\u03bc`, as the case of a singular measure is easier.\n\nIt is easy to see that a set `s` on which `liminf \u03c1 a / \u03bc a < q` satisfies `\u03c1 s \u2264 q * \u03bc s`, by using\na disjoint subcovering provided by the definition of Vitali families. Similarly for the limsup.\nIt follows that a set on which `\u03c1 a / \u03bc a` oscillates has measure `0`, and therefore that\n`\u03c1 a / \u03bc a` converges almost surely (`vitali_family.ae_tendsto_div`). Moreover, on a set where the\nlimit is close to a constant `c`, one gets `\u03c1 s \u223c c \u03bc s`, using again a covering lemma as above.\nIt follows that `\u03c1` is equal to `\u03bc.with_density (v.lim_ratio \u03c1 x)`, where `v.lim_ratio \u03c1 x` is the\nlimit of `\u03c1 a / \u03bc a` at `x` (which is well defined almost everywhere). By uniqueness of the\nRadon-Nikodym derivative, one gets `v.lim_ratio \u03c1 x = \u03c1.rn_deriv \u03bc x` almost everywhere, completing\nthe proof.\n\nThere is a difficulty in this sketch: this argument works well when `v.lim_ratio \u03c1` is measurable,\nbut there is no guarantee that this is the case, especially if one doesn't make further assumptions\non the Vitali family. We use an indirect argument to show that `v.lim_ratio \u03c1` is always\nalmost everywhere measurable, again based on the disjoint subcovering argument\n(see `vitali_family.exists_measurable_supersets_lim_ratio`), and then proceed as sketched above\nbut replacing `v.lim_ratio \u03c1` by a measurable version called `v.lim_ratio_meas \u03c1`.\n\n## Counterexample\n\nThe standing assumption in this file is that spaces are second countable. Without this assumption,\nmeasures may be zero locally but nonzero globally, which is not compatible with differentiation\ntheory (which deduces global information from local one). Here is an example displaying this\nbehavior.\n\nDefine a measure `\u03bc` by `\u03bc s = 0` if `s` is covered by countably many balls of radius `1`,\nand `\u03bc s = \u221e` otherwise. This is indeed a countably additive measure, which is moreover\nlocally finite and doubling at small scales. It vanishes on every ball of radius `1`, so all the\nquantities in differentiation theory (defined as ratios of measures as the radius tends to zero)\nmake no sense. However, the measure is not globally zero if the space is big enough.\n\n## References\n\n* [Herbert Federer, Geometric Measure Theory, Chapter 2.9][Federer1996]\n-/\n\n\nopen MeasureTheory Metric Set Filter TopologicalSpace MeasureTheory.Measure\n\nopen Filter ENNReal MeasureTheory NNReal Topology\n\nvariable {\u03b1 : Type _} [MetricSpace \u03b1] {m0 : MeasurableSpace \u03b1} {\u03bc : Measure \u03b1} (v : VitaliFamily \u03bc)\n  {E : Type _} [NormedAddCommGroup E]\n\ninclude v\n\nnamespace VitaliFamily\n\n/-- The limit along a Vitali family of `\u03c1 a / \u03bc a` where it makes sense, and garbage otherwise.\nDo *not* use this definition: it is only a temporary device to show that this ratio tends almost\neverywhere to the Radon-Nikodym derivative. -/\nnoncomputable def limRatio (\u03c1 : Measure \u03b1) (x : \u03b1) : \u211d\u22650\u221e :=\n  limUnder (v.filterAt x) fun a => \u03c1 a / \u03bc a\n#align vitali_family.lim_ratio VitaliFamily.limRatio\n\n/-- For almost every point `x`, sufficiently small sets in a Vitali family around `x` have positive\nmeasure. (This is a nontrivial result, following from the covering property of Vitali families). -/\ntheorem ae_eventually_measure_pos [SecondCountableTopology \u03b1] :\n    \u2200\u1d50 x \u2202\u03bc, \u2200\u1da0 a in v.filterAt x, 0 < \u03bc a :=\n  by\n  set s := { x | \u00ac\u2200\u1da0 a in v.filter_at x, 0 < \u03bc a } with hs\n  simp only [not_lt, not_eventually, nonpos_iff_eq_zero] at hs\n  change \u03bc s = 0\n  let f : \u03b1 \u2192 Set (Set \u03b1) := fun x => { a | \u03bc a = 0 }\n  have h : v.fine_subfamily_on f s := by\n    intro x hx \u03b5 \u03b5pos\n    rw [hs] at hx\n    simp only [frequently_filter_at_iff, exists_prop, gt_iff_lt, mem_set_of_eq] at hx\n    rcases hx \u03b5 \u03b5pos with \u27e8a, a_sets, ax, \u03bca\u27e9\n    exact \u27e8a, \u27e8a_sets, \u03bca\u27e9, ax\u27e9\n  refine' le_antisymm _ bot_le\n  calc\n    \u03bc s \u2264 \u2211' x : h.index, \u03bc (h.covering x) := h.measure_le_tsum\n    _ = \u2211' x : h.index, 0 := by\n      congr\n      ext1 x\n      exact h.covering_mem x.2\n    _ = 0 := by simp only [tsum_zero, add_zero]\n    \n#align vitali_family.ae_eventually_measure_pos VitaliFamily.ae_eventually_measure_pos\n\n/-- For every point `x`, sufficiently small sets in a Vitali family around `x` have finite measure.\n(This is a trivial result, following from the fact that the measure is locally finite). -/\ntheorem eventually_measure_lt_top [IsLocallyFiniteMeasure \u03bc] (x : \u03b1) :\n    \u2200\u1da0 a in v.filterAt x, \u03bc a < \u221e :=\n  by\n  obtain \u27e8\u03b5, \u03b5pos, \u03bc\u03b5\u27e9 : \u2203 (\u03b5 : \u211d)(hi : 0 < \u03b5), \u03bc (closed_ball x \u03b5) < \u221e :=\n    (\u03bc.finite_at_nhds x).exists_mem_basis nhds_basis_closed_ball\n  exact v.eventually_filter_at_iff.2 \u27e8\u03b5, \u03b5pos, fun a ha ha\u03b5 => (measure_mono ha\u03b5).trans_lt \u03bc\u03b5\u27e9\n#align vitali_family.eventually_measure_lt_top VitaliFamily.eventually_measure_lt_top\n\n/-- If two measures `\u03c1` and `\u03bd` have, at every point of a set `s`, arbitrarily small sets in a\nVitali family satisfying `\u03c1 a \u2264 \u03bd a`, then `\u03c1 s \u2264 \u03bd s` if `\u03c1 \u226a \u03bc`.-/\ntheorem measure_le_of_frequently_le [SecondCountableTopology \u03b1] [BorelSpace \u03b1] {\u03c1 : Measure \u03b1}\n    (\u03bd : Measure \u03b1) [IsLocallyFiniteMeasure \u03bd] (h\u03c1 : \u03c1 \u226a \u03bc) (s : Set \u03b1)\n    (hs : \u2200 x \u2208 s, \u2203\u1da0 a in v.filterAt x, \u03c1 a \u2264 \u03bd a) : \u03c1 s \u2264 \u03bd s :=\n  by\n  -- this follows from a covering argument using the sets satisfying `\u03c1 a \u2264 \u03bd a`.\n  apply ENNReal.le_of_forall_pos_le_add fun \u03b5 \u03b5pos hc => _\n  obtain \u27e8U, sU, U_open, \u03bdU\u27e9 : \u2203 (U : Set \u03b1)(H : s \u2286 U), IsOpen U \u2227 \u03bd U \u2264 \u03bd s + \u03b5 :=\n    exists_is_open_le_add s \u03bd (ENNReal.coe_pos.2 \u03b5pos).ne'\n  let f : \u03b1 \u2192 Set (Set \u03b1) := fun x => { a | \u03c1 a \u2264 \u03bd a \u2227 a \u2286 U }\n  have h : v.fine_subfamily_on f s :=\n    by\n    apply v.fine_subfamily_on_of_frequently f s fun x hx => _\n    have :=\n      (hs x hx).and_eventually\n        ((v.eventually_filter_at_mem_sets x).And\n          (v.eventually_filter_at_subset_of_nhds (U_open.mem_nhds (sU hx))))\n    apply frequently.mono this\n    rintro a \u27e8\u03c1a, av, aU\u27e9\n    exact \u27e8\u03c1a, aU\u27e9\n  haveI : Encodable h.index := h.index_countable.to_encodable\n  calc\n    \u03c1 s \u2264 \u2211' x : h.index, \u03c1 (h.covering x) := h.measure_le_tsum_of_absolutely_continuous h\u03c1\n    _ \u2264 \u2211' x : h.index, \u03bd (h.covering x) := (ENNReal.tsum_le_tsum fun x => (h.covering_mem x.2).1)\n    _ = \u03bd (\u22c3 x : h.index, h.covering x) := by\n      rw [measure_Union h.covering_disjoint_subtype fun i => h.measurable_set_u i.2]\n    _ \u2264 \u03bd U := (measure_mono (Union_subset fun i => (h.covering_mem i.2).2))\n    _ \u2264 \u03bd s + \u03b5 := \u03bdU\n    \n#align vitali_family.measure_le_of_frequently_le VitaliFamily.measure_le_of_frequently_le\n\nsection\n\nvariable [SecondCountableTopology \u03b1] [BorelSpace \u03b1] [IsLocallyFiniteMeasure \u03bc] {\u03c1 : Measure \u03b1}\n  [IsLocallyFiniteMeasure \u03c1]\n\n/-- If a measure `\u03c1` is singular with respect to `\u03bc`, then for `\u03bc` almost every `x`, the ratio\n`\u03c1 a / \u03bc a` tends to zero when `a` shrinks to `x` along the Vitali family. This makes sense\nas `\u03bc a` is eventually positive by `ae_eventually_measure_pos`. -/\ntheorem ae_eventually_measure_zero_of_singular (h\u03c1 : \u03c1 \u27c2\u2098 \u03bc) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u03c1 a / \u03bc a) (v.filterAt x) (\ud835\udcdd 0) :=\n  by\n  have A : \u2200 \u03b5 > (0 : \u211d\u22650), \u2200\u1d50 x \u2202\u03bc, \u2200\u1da0 a in v.filter_at x, \u03c1 a < \u03b5 * \u03bc a :=\n    by\n    intro \u03b5 \u03b5pos\n    set s := { x | \u00ac\u2200\u1da0 a in v.filter_at x, \u03c1 a < \u03b5 * \u03bc a } with hs\n    change \u03bc s = 0\n    obtain \u27e8o, o_meas, \u03c1o, \u03bco\u27e9 : \u2203 o : Set \u03b1, MeasurableSet o \u2227 \u03c1 o = 0 \u2227 \u03bc (o\u1d9c) = 0 := h\u03c1\n    apply le_antisymm _ bot_le\n    calc\n      \u03bc s \u2264 \u03bc (s \u2229 o \u222a o\u1d9c) := by\n        conv_lhs => rw [\u2190 inter_union_compl s o]\n        exact measure_mono (union_subset_union_right _ (inter_subset_right _ _))\n      _ \u2264 \u03bc (s \u2229 o) + \u03bc (o\u1d9c) := (measure_union_le _ _)\n      _ = \u03bc (s \u2229 o) := by rw [\u03bco, add_zero]\n      _ = \u03b5\u207b\u00b9 * (\u03b5 \u2022 \u03bc) (s \u2229 o) :=\n        by\n        simp only [coe_nnreal_smul_apply, \u2190 mul_assoc, mul_comm _ (\u03b5 : \u211d\u22650\u221e)]\n        rw [ENNReal.mul_inv_cancel (ENNReal.coe_pos.2 \u03b5pos).ne' ENNReal.coe_ne_top, one_mul]\n      _ \u2264 \u03b5\u207b\u00b9 * \u03c1 (s \u2229 o) := by\n        refine' mul_le_mul_left' _ _\n        refine' v.measure_le_of_frequently_le \u03c1 ((measure.absolutely_continuous.refl \u03bc).smul \u03b5) _ _\n        intro x hx\n        rw [hs] at hx\n        simp only [mem_inter_iff, not_lt, not_eventually, mem_set_of_eq] at hx\n        exact hx.1\n      _ \u2264 \u03b5\u207b\u00b9 * \u03c1 o := (mul_le_mul_left' (measure_mono (inter_subset_right _ _)) _)\n      _ = 0 := by rw [\u03c1o, MulZeroClass.mul_zero]\n      \n  obtain \u27e8u, u_anti, u_pos, u_lim\u27e9 :\n    \u2203 u : \u2115 \u2192 \u211d\u22650, StrictAnti u \u2227 (\u2200 n : \u2115, 0 < u n) \u2227 tendsto u at_top (\ud835\udcdd 0) :=\n    exists_seq_strictAnti_tendsto (0 : \u211d\u22650)\n  have B : \u2200\u1d50 x \u2202\u03bc, \u2200 n, \u2200\u1da0 a in v.filter_at x, \u03c1 a < u n * \u03bc a :=\n    ae_all_iff.2 fun n => A (u n) (u_pos n)\n  filter_upwards [B, v.ae_eventually_measure_pos]\n  intro x hx h'x\n  refine' tendsto_order.2 \u27e8fun z hz => (ENNReal.not_lt_zero hz).elim, fun z hz => _\u27e9\n  obtain \u27e8w, w_pos, w_lt\u27e9 : \u2203 w : \u211d\u22650, (0 : \u211d\u22650\u221e) < w \u2227 (w : \u211d\u22650\u221e) < z :=\n    ENNReal.lt_iff_exists_nnreal_btwn.1 hz\n  obtain \u27e8n, hn\u27e9 : \u2203 n, u n < w := ((tendsto_order.1 u_lim).2 w (ENNReal.coe_pos.1 w_pos)).exists\n  filter_upwards [hx n, h'x, v.eventually_measure_lt_top x]\n  intro a ha \u03bca_pos \u03bca_lt_top\n  rw [ENNReal.div_lt_iff (Or.inl \u03bca_pos.ne') (Or.inl \u03bca_lt_top.ne)]\n  exact ha.trans_le (mul_le_mul_right' ((ENNReal.coe_le_coe.2 hn.le).trans w_lt.le) _)\n#align vitali_family.ae_eventually_measure_zero_of_singular VitaliFamily.ae_eventually_measure_zero_of_singular\n\nsection AbsolutelyContinuous\n\nvariable (h\u03c1 : \u03c1 \u226a \u03bc)\n\ninclude h\u03c1\n\n/-- A set of points `s` satisfying both `\u03c1 a \u2264 c * \u03bc a` and `\u03c1 a \u2265 d * \u03bc a` at arbitrarily small\nsets in a Vitali family has measure `0` if `c < d`. Indeed, the first inequality should imply\nthat `\u03c1 s \u2264 c * \u03bc s`, and the second one that `\u03c1 s \u2265 d * \u03bc s`, a contradiction if `0 < \u03bc s`. -/\ntheorem null_of_frequently_le_of_frequently_ge {c d : \u211d\u22650} (hcd : c < d) (s : Set \u03b1)\n    (hc : \u2200 x \u2208 s, \u2203\u1da0 a in v.filterAt x, \u03c1 a \u2264 c * \u03bc a)\n    (hd : \u2200 x \u2208 s, \u2203\u1da0 a in v.filterAt x, (d : \u211d\u22650\u221e) * \u03bc a \u2264 \u03c1 a) : \u03bc s = 0 :=\n  by\n  apply null_of_locally_null s fun x hx => _\n  obtain \u27e8o, xo, o_open, \u03bco\u27e9 : \u2203 o : Set \u03b1, x \u2208 o \u2227 IsOpen o \u2227 \u03bc o < \u221e :=\n    measure.exists_is_open_measure_lt_top \u03bc x\n  refine' \u27e8s \u2229 o, inter_mem_nhdsWithin _ (o_open.mem_nhds xo), _\u27e9\n  let s' := s \u2229 o\n  by_contra\n  apply lt_irrefl (\u03c1 s')\n  calc\n    \u03c1 s' \u2264 c * \u03bc s' := v.measure_le_of_frequently_le (c \u2022 \u03bc) h\u03c1 s' fun x hx => hc x hx.1\n    _ < d * \u03bc s' :=\n      by\n      apply (ENNReal.mul_lt_mul_right h _).2 (ENNReal.coe_lt_coe.2 hcd)\n      exact (lt_of_le_of_lt (measure_mono (inter_subset_right _ _)) \u03bco).Ne\n    _ \u2264 \u03c1 s' :=\n      v.measure_le_of_frequently_le \u03c1 ((measure.absolutely_continuous.refl \u03bc).smul d) s' fun x hx =>\n        hd x hx.1\n    \n#align vitali_family.null_of_frequently_le_of_frequently_ge VitaliFamily.null_of_frequently_le_of_frequently_ge\n\n/-- If `\u03c1` is absolutely continuous with respect to `\u03bc`, then for almost every `x`,\nthe ratio `\u03c1 a / \u03bc a` converges as `a` shrinks to `x` along a Vitali family for `\u03bc`. -/\ntheorem ae_tendsto_div : \u2200\u1d50 x \u2202\u03bc, \u2203 c, Tendsto (fun a => \u03c1 a / \u03bc a) (v.filterAt x) (\ud835\udcdd c) :=\n  by\n  obtain \u27e8w, w_count, w_dense, w_zero, w_top\u27e9 :\n    \u2203 w : Set \u211d\u22650\u221e, w.Countable \u2227 Dense w \u2227 0 \u2209 w \u2227 \u221e \u2209 w :=\n    ENNReal.exists_countable_dense_no_zero_top\n  have I : \u2200 x \u2208 w, x \u2260 \u221e := fun x xs hx => w_top (hx \u25b8 xs)\n  have A :\n    \u2200 c \u2208 w,\n      \u2200 d \u2208 w,\n        c < d \u2192\n          \u2200\u1d50 x \u2202\u03bc,\n            \u00ac((\u2203\u1da0 a in v.filter_at x, \u03c1 a / \u03bc a < c) \u2227 \u2203\u1da0 a in v.filter_at x, d < \u03c1 a / \u03bc a) :=\n    by\n    intro c hc d hd hcd\n    lift c to \u211d\u22650 using I c hc\n    lift d to \u211d\u22650 using I d hd\n    apply v.null_of_frequently_le_of_frequently_ge h\u03c1 (ENNReal.coe_lt_coe.1 hcd)\n    \u00b7 simp only [and_imp, exists_prop, not_frequently, not_and, not_lt, not_le, not_eventually,\n        mem_set_of_eq, mem_compl_iff, not_forall]\n      intro x h1x h2x\n      apply h1x.mono fun a ha => _\n      refine' (ENNReal.div_le_iff_le_mul _ (Or.inr (bot_le.trans_lt ha).ne')).1 ha.le\n      simp only [ENNReal.coe_ne_top, Ne.def, or_true_iff, not_false_iff]\n    \u00b7 simp only [and_imp, exists_prop, not_frequently, not_and, not_lt, not_le, not_eventually,\n        mem_set_of_eq, mem_compl_iff, not_forall]\n      intro x h1x h2x\n      apply h2x.mono fun a ha => _\n      exact ENNReal.mul_le_of_le_div ha.le\n  have B :\n    \u2200\u1d50 x \u2202\u03bc,\n      \u2200 c \u2208 w,\n        \u2200 d \u2208 w,\n          c < d \u2192\n            \u00ac((\u2203\u1da0 a in v.filter_at x, \u03c1 a / \u03bc a < c) \u2227 \u2203\u1da0 a in v.filter_at x, d < \u03c1 a / \u03bc a) :=\n    by simpa only [ae_ball_iff w_count, ae_all_iff]\n  filter_upwards [B]\n  intro x hx\n  exact tendsto_of_no_upcrossings w_dense hx\n#align vitali_family.ae_tendsto_div VitaliFamily.ae_tendsto_div\n\ntheorem ae_tendsto_limRatio :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u03c1 a / \u03bc a) (v.filterAt x) (\ud835\udcdd (v.limRatio \u03c1 x)) :=\n  by\n  filter_upwards [v.ae_tendsto_div h\u03c1]\n  intro x hx\n  exact tendsto_nhds_limUnder hx\n#align vitali_family.ae_tendsto_lim_ratio VitaliFamily.ae_tendsto_limRatio\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (m n) -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (m n) -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (m n) -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (m n) -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (m n) -/\n/-- Given two thresholds `p < q`, the sets `{x | v.lim_ratio \u03c1 x < p}`\nand `{x | q < v.lim_ratio \u03c1 x}` are obviously disjoint. The key to proving that `v.lim_ratio \u03c1` is\nalmost everywhere measurable is to show that these sets have measurable supersets which are also\ndisjoint, up to zero measure. This is the content of this lemma. -/\ntheorem exists_measurable_supersets_limRatio {p q : \u211d\u22650} (hpq : p < q) :\n    \u2203 a b,\n      MeasurableSet a \u2227\n        MeasurableSet b \u2227\n          { x | v.limRatio \u03c1 x < p } \u2286 a \u2227\n            { x | (q : \u211d\u22650\u221e) < v.limRatio \u03c1 x } \u2286 b \u2227 \u03bc (a \u2229 b) = 0 :=\n  by\n  /- Here is a rough sketch, assuming that the measure is finite and the limit is well defined\n    everywhere. Let `u := {x | v.lim_ratio \u03c1 x < p}` and `w := {x | q < v.lim_ratio \u03c1 x}`. They\n    have measurable supersets `u'` and `w'` of the same measure. We will show that these satisfy\n    the conclusion of the theorem, i.e., `\u03bc (u' \u2229 w') = 0`. For this, note that\n    `\u03c1 (u' \u2229 w') = \u03c1 (u \u2229 w')` (as `w'` is measurable, see `measure_to_measurable_add_inter_left`).\n    The latter set is included in the set where the limit of the ratios is `< p`, and therefore\n    its measure is `\u2264 p * \u03bc (u \u2229 w')`. Using the same trick in the other direction gives that this is\n    `p * \u03bc (u' \u2229 w')`. We have shown that `\u03c1 (u' \u2229 w') \u2264 p * \u03bc (u' \u2229 w')`. Arguing in the same way but\n    using the `w` part gives `q * \u03bc (u' \u2229 w') \u2264 \u03c1 (u' \u2229 w')`. If `\u03bc (u' \u2229 w')` were nonzero, this\n    would be a contradiction as `p < q`.\n  \n    For the rigorous proof, we need to work on a part of the space where the measure is finite\n    (provided by `spanning_sets (\u03c1 + \u03bc)`) and to restrict to the set where the limit is well defined\n    (called `s` below, of full measure). Otherwise, the argument goes through.\n    -/\n  let s := { x | \u2203 c, tendsto (fun a => \u03c1 a / \u03bc a) (v.filter_at x) (\ud835\udcdd c) }\n  let o : \u2115 \u2192 Set \u03b1 := spanning_sets (\u03c1 + \u03bc)\n  let u n := s \u2229 { x | v.lim_ratio \u03c1 x < p } \u2229 o n\n  let w n := s \u2229 { x | (q : \u211d\u22650\u221e) < v.lim_ratio \u03c1 x } \u2229 o n\n  -- the supersets are obtained by restricting to the set `s` where the limit is well defined, to\n  -- a finite measure part `o n`, taking a measurable superset here, and then taking the union over\n  -- `n`.\n  refine'\n    \u27e8to_measurable \u03bc (s\u1d9c) \u222a \u22c3 n, to_measurable (\u03c1 + \u03bc) (u n),\n      to_measurable \u03bc (s\u1d9c) \u222a \u22c3 n, to_measurable (\u03c1 + \u03bc) (w n), _, _, _, _, _\u27e9\n  -- check that these sets are measurable supersets as required\n  \u00b7\n    exact\n      (measurable_set_to_measurable _ _).union\n        (MeasurableSet.union\u1d62 fun n => measurable_set_to_measurable _ _)\n  \u00b7\n    exact\n      (measurable_set_to_measurable _ _).union\n        (MeasurableSet.union\u1d62 fun n => measurable_set_to_measurable _ _)\n  \u00b7 intro x hx\n    by_cases h : x \u2208 s\n    \u00b7 refine' Or.inr (mem_Union.2 \u27e8spanning_sets_index (\u03c1 + \u03bc) x, _\u27e9)\n      exact subset_to_measurable _ _ \u27e8\u27e8h, hx\u27e9, mem_spanning_sets_index _ _\u27e9\n    \u00b7 exact Or.inl (subset_to_measurable \u03bc (s\u1d9c) h)\n  \u00b7 intro x hx\n    by_cases h : x \u2208 s\n    \u00b7 refine' Or.inr (mem_Union.2 \u27e8spanning_sets_index (\u03c1 + \u03bc) x, _\u27e9)\n      exact subset_to_measurable _ _ \u27e8\u27e8h, hx\u27e9, mem_spanning_sets_index _ _\u27e9\n    \u00b7 exact Or.inl (subset_to_measurable \u03bc (s\u1d9c) h)\n  -- it remains to check the nontrivial part that these sets have zero measure intersection.\n  -- it suffices to do it for fixed `m` and `n`, as one is taking countable unions.\n  suffices H : \u2200 m n : \u2115, \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) = 0\n  \u00b7 have A :\n      (to_measurable \u03bc (s\u1d9c) \u222a \u22c3 n, to_measurable (\u03c1 + \u03bc) (u n)) \u2229\n          (to_measurable \u03bc (s\u1d9c) \u222a \u22c3 n, to_measurable (\u03c1 + \u03bc) (w n)) \u2286\n        to_measurable \u03bc (s\u1d9c) \u222a\n          \u22c3 (m) (n), to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n) :=\n      by\n      simp only [inter_distrib_left, inter_distrib_right, true_and_iff, subset_union_left,\n        union_subset_iff, inter_self]\n      refine' \u27e8_, _, _\u27e9\n      \u00b7 exact (inter_subset_left _ _).trans (subset_union_left _ _)\n      \u00b7 exact (inter_subset_right _ _).trans (subset_union_left _ _)\n      \u00b7 simp_rw [Union_inter, inter_Union]\n        exact subset_union_right _ _\n    refine' le_antisymm ((measure_mono A).trans _) bot_le\n    calc\n      \u03bc\n            (to_measurable \u03bc (s\u1d9c) \u222a\n              \u22c3 (m) (n), to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) \u2264\n          \u03bc (to_measurable \u03bc (s\u1d9c)) +\n            \u03bc (\u22c3 (m) (n), to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n        measure_union_le _ _\n      _ = \u03bc (\u22c3 (m) (n), to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n        by\n        have : \u03bc (s\u1d9c) = 0 := v.ae_tendsto_div h\u03c1\n        rw [measure_to_measurable, this, zero_add]\n      _ \u2264 \u2211' (m) (n), \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n        ((measure_Union_le _).trans (ENNReal.tsum_le_tsum fun m => measure_Union_le _))\n      _ = 0 := by simp only [H, tsum_zero]\n      \n  -- now starts the nontrivial part of the argument. We fix `m` and `n`, and show that the\n  -- measurable supersets of `u m` and `w n` have zero measure intersection by using the lemmas\n  -- `measure_to_measurable_add_inter_left` (to reduce to `u m` or `w n` instead of the measurable\n  -- superset) and `measure_le_of_frequently_le` to compare their measures for `\u03c1` and `\u03bc`.\n  intro m n\n  have I : (\u03c1 + \u03bc) (u m) \u2260 \u221e :=\n    by\n    apply (lt_of_le_of_lt (measure_mono _) (measure_spanning_sets_lt_top (\u03c1 + \u03bc) m)).Ne\n    exact inter_subset_right _ _\n  have J : (\u03c1 + \u03bc) (w n) \u2260 \u221e :=\n    by\n    apply (lt_of_le_of_lt (measure_mono _) (measure_spanning_sets_lt_top (\u03c1 + \u03bc) n)).Ne\n    exact inter_subset_right _ _\n  have A :\n    \u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) \u2264\n      p * \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n    calc\n      \u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) =\n          \u03c1 (u m \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n        measure_to_measurable_add_inter_left (measurable_set_to_measurable _ _) I\n      _ \u2264 (p \u2022 \u03bc) (u m \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n        by\n        refine' v.measure_le_of_frequently_le _ h\u03c1 _ fun x hx => _\n        have L : tendsto (fun a : Set \u03b1 => \u03c1 a / \u03bc a) (v.filter_at x) (\ud835\udcdd (v.lim_ratio \u03c1 x)) :=\n          tendsto_nhds_limUnder hx.1.1.1\n        have I : \u2200\u1da0 b : Set \u03b1 in v.filter_at x, \u03c1 b / \u03bc b < p := (tendsto_order.1 L).2 _ hx.1.1.2\n        apply I.frequently.mono fun a ha => _\n        rw [coe_nnreal_smul_apply]\n        refine' (ENNReal.div_le_iff_le_mul _ (Or.inr (bot_le.trans_lt ha).ne')).1 ha.le\n        simp only [ENNReal.coe_ne_top, Ne.def, or_true_iff, not_false_iff]\n      _ = p * \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) := by\n        simp only [coe_nnreal_smul_apply,\n          measure_to_measurable_add_inter_right (measurable_set_to_measurable _ _) I]\n      \n  have B :\n    (q : \u211d\u22650\u221e) * \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) \u2264\n      \u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n    calc\n      (q : \u211d\u22650\u221e) * \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) =\n          (q : \u211d\u22650\u221e) * \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 w n) :=\n        by\n        conv_rhs => rw [inter_comm]\n        rw [inter_comm, measure_to_measurable_add_inter_right (measurable_set_to_measurable _ _) J]\n      _ \u2264 \u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 w n) :=\n        by\n        rw [\u2190 coe_nnreal_smul_apply]\n        refine' v.measure_le_of_frequently_le _ (absolutely_continuous.rfl.smul _) _ _\n        intro x hx\n        have L : tendsto (fun a : Set \u03b1 => \u03c1 a / \u03bc a) (v.filter_at x) (\ud835\udcdd (v.lim_ratio \u03c1 x)) :=\n          tendsto_nhds_limUnder hx.2.1.1\n        have I : \u2200\u1da0 b : Set \u03b1 in v.filter_at x, (q : \u211d\u22650\u221e) < \u03c1 b / \u03bc b :=\n          (tendsto_order.1 L).1 _ hx.2.1.2\n        apply I.frequently.mono fun a ha => _\n        rw [coe_nnreal_smul_apply]\n        exact ENNReal.mul_le_of_le_div ha.le\n      _ = \u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n        by\n        conv_rhs => rw [inter_comm]\n        rw [inter_comm]\n        exact (measure_to_measurable_add_inter_left (measurable_set_to_measurable _ _) J).symm\n      \n  by_contra\n  apply lt_irrefl (\u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)))\n  calc\n    \u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) \u2264\n        p * \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n      A\n    _ < q * \u03bc (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) :=\n      by\n      apply (ENNReal.mul_lt_mul_right h _).2 (ENNReal.coe_lt_coe.2 hpq)\n      suffices H : (\u03c1 + \u03bc) (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) \u2260 \u221e\n      \u00b7 simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne.def, coe_add] at H\n        exact H.2\n      apply (lt_of_le_of_lt (measure_mono (inter_subset_left _ _)) _).Ne\n      rw [measure_to_measurable]\n      apply lt_of_le_of_lt (measure_mono _) (measure_spanning_sets_lt_top (\u03c1 + \u03bc) m)\n      exact inter_subset_right _ _\n    _ \u2264 \u03c1 (to_measurable (\u03c1 + \u03bc) (u m) \u2229 to_measurable (\u03c1 + \u03bc) (w n)) := B\n    \n#align vitali_family.exists_measurable_supersets_lim_ratio VitaliFamily.exists_measurable_supersets_limRatio\n\ntheorem aeMeasurableLimRatio : AeMeasurable (v.limRatio \u03c1) \u03bc :=\n  by\n  apply ENNReal.aeMeasurableOfExistAlmostDisjointSupersets _ _ fun p q hpq => _\n  exact v.exists_measurable_supersets_lim_ratio h\u03c1 hpq\n#align vitali_family.ae_measurable_lim_ratio VitaliFamily.aeMeasurableLimRatio\n\n/-- A measurable version of `v.lim_ratio \u03c1`. Do *not* use this definition: it is only a temporary\ndevice to show that `v.lim_ratio` is almost everywhere equal to the Radon-Nikodym derivative. -/\nnoncomputable def limRatioMeas : \u03b1 \u2192 \u211d\u22650\u221e :=\n  (v.aeMeasurableLimRatio h\u03c1).mk _\n#align vitali_family.lim_ratio_meas VitaliFamily.limRatioMeas\n\ntheorem limRatioMeas_measurable : Measurable (v.limRatioMeas h\u03c1) :=\n  AeMeasurable.measurable_mk _\n#align vitali_family.lim_ratio_meas_measurable VitaliFamily.limRatioMeas_measurable\n\ntheorem ae_tendsto_limRatioMeas :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u03c1 a / \u03bc a) (v.filterAt x) (\ud835\udcdd (v.limRatioMeas h\u03c1 x)) :=\n  by\n  filter_upwards [v.ae_tendsto_lim_ratio h\u03c1, AeMeasurable.ae_eq_mk (v.ae_measurable_lim_ratio h\u03c1)]\n  intro x hx h'x\n  rwa [h'x] at hx\n#align vitali_family.ae_tendsto_lim_ratio_meas VitaliFamily.ae_tendsto_limRatioMeas\n\n/-- If, for all `x` in a set `s`, one has frequently `\u03c1 a / \u03bc a < p`, then `\u03c1 s \u2264 p * \u03bc s`, as\nproved in `measure_le_of_frequently_le`. Since `\u03c1 a / \u03bc a` tends almost everywhere to\n`v.lim_ratio_meas h\u03c1 x`, the same property holds for sets `s` on which `v.lim_ratio_meas h\u03c1 < p`. -/\ntheorem measure_le_mul_of_subset_limRatioMeas_lt {p : \u211d\u22650} {s : Set \u03b1}\n    (h : s \u2286 { x | v.limRatioMeas h\u03c1 x < p }) : \u03c1 s \u2264 p * \u03bc s :=\n  by\n  let t := { x : \u03b1 | tendsto (fun a => \u03c1 a / \u03bc a) (v.filter_at x) (\ud835\udcdd (v.lim_ratio_meas h\u03c1 x)) }\n  have A : \u03bc (t\u1d9c) = 0 := v.ae_tendsto_lim_ratio_meas h\u03c1\n  suffices H : \u03c1 (s \u2229 t) \u2264 (p \u2022 \u03bc) (s \u2229 t);\n  exact\n    calc\n      \u03c1 s = \u03c1 (s \u2229 t \u222a s \u2229 t\u1d9c) := by rw [inter_union_compl]\n      _ \u2264 \u03c1 (s \u2229 t) + \u03c1 (s \u2229 t\u1d9c) := (measure_union_le _ _)\n      _ \u2264 p * \u03bc (s \u2229 t) + 0 :=\n        (add_le_add H ((measure_mono (inter_subset_right _ _)).trans (h\u03c1 A).le))\n      _ \u2264 p * \u03bc s := by\n        rw [add_zero]\n        exact mul_le_mul_left' (measure_mono (inter_subset_left _ _)) _\n      \n  refine' v.measure_le_of_frequently_le _ h\u03c1 _ fun x hx => _\n  have I : \u2200\u1da0 b : Set \u03b1 in v.filter_at x, \u03c1 b / \u03bc b < p := (tendsto_order.1 hx.2).2 _ (h hx.1)\n  apply I.frequently.mono fun a ha => _\n  rw [coe_nnreal_smul_apply]\n  refine' (ENNReal.div_le_iff_le_mul _ (Or.inr (bot_le.trans_lt ha).ne')).1 ha.le\n  simp only [ENNReal.coe_ne_top, Ne.def, or_true_iff, not_false_iff]\n#align vitali_family.measure_le_mul_of_subset_lim_ratio_meas_lt VitaliFamily.measure_le_mul_of_subset_limRatioMeas_lt\n\n/-- If, for all `x` in a set `s`, one has frequently `q < \u03c1 a / \u03bc a`, then `q * \u03bc s \u2264 \u03c1 s`, as\nproved in `measure_le_of_frequently_le`. Since `\u03c1 a / \u03bc a` tends almost everywhere to\n`v.lim_ratio_meas h\u03c1 x`, the same property holds for sets `s` on which `q < v.lim_ratio_meas h\u03c1`. -/\ntheorem mul_measure_le_of_subset_lt_limRatioMeas {q : \u211d\u22650} {s : Set \u03b1}\n    (h : s \u2286 { x | (q : \u211d\u22650\u221e) < v.limRatioMeas h\u03c1 x }) : (q : \u211d\u22650\u221e) * \u03bc s \u2264 \u03c1 s :=\n  by\n  let t := { x : \u03b1 | tendsto (fun a => \u03c1 a / \u03bc a) (v.filter_at x) (\ud835\udcdd (v.lim_ratio_meas h\u03c1 x)) }\n  have A : \u03bc (t\u1d9c) = 0 := v.ae_tendsto_lim_ratio_meas h\u03c1\n  suffices H : (q \u2022 \u03bc) (s \u2229 t) \u2264 \u03c1 (s \u2229 t);\n  exact\n    calc\n      (q \u2022 \u03bc) s = (q \u2022 \u03bc) (s \u2229 t \u222a s \u2229 t\u1d9c) := by rw [inter_union_compl]\n      _ \u2264 (q \u2022 \u03bc) (s \u2229 t) + (q \u2022 \u03bc) (s \u2229 t\u1d9c) := (measure_union_le _ _)\n      _ \u2264 \u03c1 (s \u2229 t) + q * \u03bc (t\u1d9c) := by\n        apply add_le_add H\n        rw [coe_nnreal_smul_apply]\n        exact mul_le_mul_left' (measure_mono (inter_subset_right _ _)) _\n      _ \u2264 \u03c1 s := by\n        rw [A, MulZeroClass.mul_zero, add_zero]\n        exact measure_mono (inter_subset_left _ _)\n      \n  refine' v.measure_le_of_frequently_le _ (absolutely_continuous.rfl.smul _) _ _\n  intro x hx\n  have I : \u2200\u1da0 a in v.filter_at x, (q : \u211d\u22650\u221e) < \u03c1 a / \u03bc a := (tendsto_order.1 hx.2).1 _ (h hx.1)\n  apply I.frequently.mono fun a ha => _\n  rw [coe_nnreal_smul_apply]\n  exact ENNReal.mul_le_of_le_div ha.le\n#align vitali_family.mul_measure_le_of_subset_lt_lim_ratio_meas VitaliFamily.mul_measure_le_of_subset_lt_limRatioMeas\n\n/-- The points with `v.lim_ratio_meas h\u03c1 x = \u221e` have measure `0` for `\u03bc`. -/\ntheorem measure_limRatioMeas_top : \u03bc { x | v.limRatioMeas h\u03c1 x = \u221e } = 0 :=\n  by\n  refine' null_of_locally_null _ fun x hx => _\n  obtain \u27e8o, xo, o_open, \u03bco\u27e9 : \u2203 o : Set \u03b1, x \u2208 o \u2227 IsOpen o \u2227 \u03c1 o < \u221e :=\n    measure.exists_is_open_measure_lt_top \u03c1 x\n  let s := { x : \u03b1 | v.lim_ratio_meas h\u03c1 x = \u221e } \u2229 o\n  refine' \u27e8s, inter_mem_nhdsWithin _ (o_open.mem_nhds xo), le_antisymm _ bot_le\u27e9\n  have \u03c1s : \u03c1 s \u2260 \u221e := ((measure_mono (inter_subset_right _ _)).trans_lt \u03bco).Ne\n  have A : \u2200 q : \u211d\u22650, 1 \u2264 q \u2192 \u03bc s \u2264 q\u207b\u00b9 * \u03c1 s :=\n    by\n    intro q hq\n    rw [mul_comm, \u2190 div_eq_mul_inv, ENNReal.le_div_iff_mul_le _ (Or.inr \u03c1s), mul_comm]\n    \u00b7 apply v.mul_measure_le_of_subset_lt_lim_ratio_meas h\u03c1\n      intro y hy\n      have : v.lim_ratio_meas h\u03c1 y = \u221e := hy.1\n      simp only [this, ENNReal.coe_lt_top, mem_set_of_eq]\n    \u00b7\n      simp only [(zero_lt_one.trans_le hq).ne', true_or_iff, ENNReal.coe_eq_zero, Ne.def,\n        not_false_iff]\n  have B : tendsto (fun q : \u211d\u22650 => (q : \u211d\u22650\u221e)\u207b\u00b9 * \u03c1 s) at_top (\ud835\udcdd (\u221e\u207b\u00b9 * \u03c1 s)) :=\n    by\n    apply ENNReal.Tendsto.mul_const _ (Or.inr \u03c1s)\n    exact ENNReal.tendsto_inv_iff.2 (ENNReal.tendsto_coe_nhds_top.2 tendsto_id)\n  simp only [MulZeroClass.zero_mul, ENNReal.inv_top] at B\n  apply ge_of_tendsto B\n  exact eventually_at_top.2 \u27e81, A\u27e9\n#align vitali_family.measure_lim_ratio_meas_top VitaliFamily.measure_limRatioMeas_top\n\n/-- The points with `v.lim_ratio_meas h\u03c1 x = 0` have measure `0` for `\u03c1`. -/\ntheorem measure_limRatioMeas_zero : \u03c1 { x | v.limRatioMeas h\u03c1 x = 0 } = 0 :=\n  by\n  refine' null_of_locally_null _ fun x hx => _\n  obtain \u27e8o, xo, o_open, \u03bco\u27e9 : \u2203 o : Set \u03b1, x \u2208 o \u2227 IsOpen o \u2227 \u03bc o < \u221e :=\n    measure.exists_is_open_measure_lt_top \u03bc x\n  let s := { x : \u03b1 | v.lim_ratio_meas h\u03c1 x = 0 } \u2229 o\n  refine' \u27e8s, inter_mem_nhdsWithin _ (o_open.mem_nhds xo), le_antisymm _ bot_le\u27e9\n  have \u03bcs : \u03bc s \u2260 \u221e := ((measure_mono (inter_subset_right _ _)).trans_lt \u03bco).Ne\n  have A : \u2200 q : \u211d\u22650, 0 < q \u2192 \u03c1 s \u2264 q * \u03bc s :=\n    by\n    intro q hq\n    apply v.measure_le_mul_of_subset_lim_ratio_meas_lt h\u03c1\n    intro y hy\n    have : v.lim_ratio_meas h\u03c1 y = 0 := hy.1\n    simp only [this, mem_set_of_eq, hq, ENNReal.coe_pos]\n  have B : tendsto (fun q : \u211d\u22650 => (q : \u211d\u22650\u221e) * \u03bc s) (\ud835\udcdd[>] (0 : \u211d\u22650)) (\ud835\udcdd ((0 : \u211d\u22650) * \u03bc s)) :=\n    by\n    apply ENNReal.Tendsto.mul_const _ (Or.inr \u03bcs)\n    rw [ENNReal.tendsto_coe]\n    exact nhdsWithin_le_nhds\n  simp only [MulZeroClass.zero_mul, ENNReal.coe_zero] at B\n  apply ge_of_tendsto B\n  filter_upwards [self_mem_nhdsWithin]using A\n#align vitali_family.measure_lim_ratio_meas_zero VitaliFamily.measure_limRatioMeas_zero\n\n/-- As an intermediate step to show that `\u03bc.with_density (v.lim_ratio_meas h\u03c1) = \u03c1`, we show here\nthat `\u03bc.with_density (v.lim_ratio_meas h\u03c1) \u2264 t^2 \u03c1` for any `t > 1`. -/\ntheorem withDensity_le_mul {s : Set \u03b1} (hs : MeasurableSet s) {t : \u211d\u22650} (ht : 1 < t) :\n    \u03bc.withDensity (v.limRatioMeas h\u03c1) s \u2264 t ^ 2 * \u03c1 s :=\n  by\n  /- We cut `s` into the sets where `v.lim_ratio_meas h\u03c1 = 0`, where `v.lim_ratio_meas h\u03c1 = \u221e`, and\n    where `v.lim_ratio_meas h\u03c1 \u2208 [t^n, t^(n+1))` for `n : \u2124`. The first and second have measure `0`.\n    For the latter, since `v.lim_ratio_meas h\u03c1` fluctuates by at most `t` on this slice, we can use\n    `measure_le_mul_of_subset_lim_ratio_meas_lt` and `mul_measure_le_of_subset_lt_lim_ratio_meas` to\n    show that the two measures are comparable up to `t` (in fact `t^2` for technical reasons of\n    strict inequalities). -/\n  have t_ne_zero' : t \u2260 0 := (zero_lt_one.trans ht).ne'\n  have t_ne_zero : (t : \u211d\u22650\u221e) \u2260 0 := by simpa only [ENNReal.coe_eq_zero, Ne.def] using t_ne_zero'\n  let \u03bd := \u03bc.with_density (v.lim_ratio_meas h\u03c1)\n  let f := v.lim_ratio_meas h\u03c1\n  have f_meas : Measurable f := v.lim_ratio_meas_measurable h\u03c1\n  have A : \u03bd (s \u2229 f \u207b\u00b9' {0}) \u2264 ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) (s \u2229 f \u207b\u00b9' {0}) :=\n    by\n    apply le_trans _ (zero_le _)\n    have M : MeasurableSet (s \u2229 f \u207b\u00b9' {0}) := hs.inter (f_meas (measurable_set_singleton _))\n    simp only [\u03bd, f, nonpos_iff_eq_zero, M, with_density_apply, lintegral_eq_zero_iff f_meas]\n    apply (ae_restrict_iff' M).2\n    exact eventually_of_forall fun x hx => hx.2\n  have B : \u03bd (s \u2229 f \u207b\u00b9' {\u221e}) \u2264 ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) (s \u2229 f \u207b\u00b9' {\u221e}) :=\n    by\n    apply le_trans (le_of_eq _) (zero_le _)\n    apply with_density_absolutely_continuous \u03bc _\n    rw [\u2190 nonpos_iff_eq_zero]\n    exact (measure_mono (inter_subset_right _ _)).trans (v.measure_lim_ratio_meas_top h\u03c1).le\n  have C :\n    \u2200 n : \u2124,\n      \u03bd (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) \u2264\n        ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) :=\n    by\n    intro n\n    let I := Ico ((t : \u211d\u22650\u221e) ^ n) (t ^ (n + 1))\n    have M : MeasurableSet (s \u2229 f \u207b\u00b9' I) := hs.inter (f_meas measurableSet_Ico)\n    simp only [f, M, with_density_apply, coe_nnreal_smul_apply]\n    calc\n      (\u222b\u207b x in s \u2229 f \u207b\u00b9' I, f x \u2202\u03bc) \u2264 \u222b\u207b x in s \u2229 f \u207b\u00b9' I, t ^ (n + 1) \u2202\u03bc :=\n        lintegral_mono_ae ((ae_restrict_iff' M).2 (eventually_of_forall fun x hx => hx.2.2.le))\n      _ = t ^ (n + 1) * \u03bc (s \u2229 f \u207b\u00b9' I) := by\n        simp only [lintegral_const, MeasurableSet.univ, measure.restrict_apply, univ_inter]\n      _ = t ^ (2 : \u2124) * (t ^ (n - 1) * \u03bc (s \u2229 f \u207b\u00b9' I)) :=\n        by\n        rw [\u2190 mul_assoc, \u2190 ENNReal.zpow_add t_ne_zero ENNReal.coe_ne_top]\n        congr 2\n        abel\n      _ \u2264 t ^ 2 * \u03c1 (s \u2229 f \u207b\u00b9' I) := by\n        refine' mul_le_mul_left' _ _\n        rw [\u2190 ENNReal.coe_zpow (zero_lt_one.trans ht).ne']\n        apply v.mul_measure_le_of_subset_lt_lim_ratio_meas h\u03c1\n        intro x hx\n        apply lt_of_lt_of_le _ hx.2.1\n        rw [\u2190 ENNReal.coe_zpow (zero_lt_one.trans ht).ne', ENNReal.coe_lt_coe, sub_eq_add_neg,\n          zpow_add\u2080 t_ne_zero']\n        conv_rhs => rw [\u2190 mul_one (t ^ n)]\n        refine' mul_lt_mul' le_rfl _ (zero_le _) (NNReal.zpow_pos t_ne_zero' _)\n        rw [zpow_neg_one]\n        exact inv_lt_one ht\n      \n  calc\n    \u03bd s =\n        \u03bd (s \u2229 f \u207b\u00b9' {0}) + \u03bd (s \u2229 f \u207b\u00b9' {\u221e}) + \u2211' n : \u2124, \u03bd (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) :=\n      measure_eq_measure_preimage_add_measure_tsum_Ico_zpow \u03bd f_meas hs ht\n    _ \u2264\n        ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) (s \u2229 f \u207b\u00b9' {0}) + ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) (s \u2229 f \u207b\u00b9' {\u221e}) +\n          \u2211' n : \u2124, ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) :=\n      (add_le_add (add_le_add A B) (ENNReal.tsum_le_tsum C))\n    _ = ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) s :=\n      (measure_eq_measure_preimage_add_measure_tsum_Ico_zpow ((t : \u211d\u22650\u221e) ^ 2 \u2022 \u03c1) f_meas hs ht).symm\n    \n#align vitali_family.with_density_le_mul VitaliFamily.withDensity_le_mul\n\n/-- As an intermediate step to show that `\u03bc.with_density (v.lim_ratio_meas h\u03c1) = \u03c1`, we show here\nthat `\u03c1 \u2264 t \u03bc.with_density (v.lim_ratio_meas h\u03c1)` for any `t > 1`. -/\ntheorem le_mul_withDensity {s : Set \u03b1} (hs : MeasurableSet s) {t : \u211d\u22650} (ht : 1 < t) :\n    \u03c1 s \u2264 t * \u03bc.withDensity (v.limRatioMeas h\u03c1) s :=\n  by\n  /- We cut `s` into the sets where `v.lim_ratio_meas h\u03c1 = 0`, where `v.lim_ratio_meas h\u03c1 = \u221e`, and\n    where `v.lim_ratio_meas h\u03c1 \u2208 [t^n, t^(n+1))` for `n : \u2124`. The first and second have measure `0`.\n    For the latter, since `v.lim_ratio_meas h\u03c1` fluctuates by at most `t` on this slice, we can use\n    `measure_le_mul_of_subset_lim_ratio_meas_lt` and `mul_measure_le_of_subset_lt_lim_ratio_meas` to\n    show that the two measures are comparable up to `t`. -/\n  have t_ne_zero' : t \u2260 0 := (zero_lt_one.trans ht).ne'\n  have t_ne_zero : (t : \u211d\u22650\u221e) \u2260 0 := by simpa only [ENNReal.coe_eq_zero, Ne.def] using t_ne_zero'\n  let \u03bd := \u03bc.with_density (v.lim_ratio_meas h\u03c1)\n  let f := v.lim_ratio_meas h\u03c1\n  have f_meas : Measurable f := v.lim_ratio_meas_measurable h\u03c1\n  have A : \u03c1 (s \u2229 f \u207b\u00b9' {0}) \u2264 (t \u2022 \u03bd) (s \u2229 f \u207b\u00b9' {0}) :=\n    by\n    refine' le_trans (measure_mono (inter_subset_right _ _)) (le_trans (le_of_eq _) (zero_le _))\n    exact v.measure_lim_ratio_meas_zero h\u03c1\n  have B : \u03c1 (s \u2229 f \u207b\u00b9' {\u221e}) \u2264 (t \u2022 \u03bd) (s \u2229 f \u207b\u00b9' {\u221e}) :=\n    by\n    apply le_trans (le_of_eq _) (zero_le _)\n    apply h\u03c1\n    rw [\u2190 nonpos_iff_eq_zero]\n    exact (measure_mono (inter_subset_right _ _)).trans (v.measure_lim_ratio_meas_top h\u03c1).le\n  have C :\n    \u2200 n : \u2124,\n      \u03c1 (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) \u2264 (t \u2022 \u03bd) (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) :=\n    by\n    intro n\n    let I := Ico ((t : \u211d\u22650\u221e) ^ n) (t ^ (n + 1))\n    have M : MeasurableSet (s \u2229 f \u207b\u00b9' I) := hs.inter (f_meas measurableSet_Ico)\n    simp only [f, M, with_density_apply, coe_nnreal_smul_apply]\n    calc\n      \u03c1 (s \u2229 f \u207b\u00b9' I) \u2264 t ^ (n + 1) * \u03bc (s \u2229 f \u207b\u00b9' I) :=\n        by\n        rw [\u2190 ENNReal.coe_zpow t_ne_zero']\n        apply v.measure_le_mul_of_subset_lim_ratio_meas_lt h\u03c1\n        intro x hx\n        apply hx.2.2.trans_le (le_of_eq _)\n        rw [ENNReal.coe_zpow t_ne_zero']\n      _ = \u222b\u207b x in s \u2229 f \u207b\u00b9' I, t ^ (n + 1) \u2202\u03bc := by\n        simp only [lintegral_const, MeasurableSet.univ, measure.restrict_apply, univ_inter]\n      _ \u2264 \u222b\u207b x in s \u2229 f \u207b\u00b9' I, t * f x \u2202\u03bc :=\n        by\n        apply lintegral_mono_ae ((ae_restrict_iff' M).2 (eventually_of_forall fun x hx => _))\n        rw [add_comm, ENNReal.zpow_add t_ne_zero ENNReal.coe_ne_top, zpow_one]\n        exact mul_le_mul_left' hx.2.1 _\n      _ = t * \u222b\u207b x in s \u2229 f \u207b\u00b9' I, f x \u2202\u03bc := lintegral_const_mul _ f_meas\n      \n  calc\n    \u03c1 s =\n        \u03c1 (s \u2229 f \u207b\u00b9' {0}) + \u03c1 (s \u2229 f \u207b\u00b9' {\u221e}) + \u2211' n : \u2124, \u03c1 (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) :=\n      measure_eq_measure_preimage_add_measure_tsum_Ico_zpow \u03c1 f_meas hs ht\n    _ \u2264\n        (t \u2022 \u03bd) (s \u2229 f \u207b\u00b9' {0}) + (t \u2022 \u03bd) (s \u2229 f \u207b\u00b9' {\u221e}) +\n          \u2211' n : \u2124, (t \u2022 \u03bd) (s \u2229 f \u207b\u00b9' Ico (t ^ n) (t ^ (n + 1))) :=\n      (add_le_add (add_le_add A B) (ENNReal.tsum_le_tsum C))\n    _ = (t \u2022 \u03bd) s :=\n      (measure_eq_measure_preimage_add_measure_tsum_Ico_zpow (t \u2022 \u03bd) f_meas hs ht).symm\n    \n#align vitali_family.le_mul_with_density VitaliFamily.le_mul_withDensity\n\ntheorem withDensity_limRatioMeas_eq : \u03bc.withDensity (v.limRatioMeas h\u03c1) = \u03c1 :=\n  by\n  ext1 s hs\n  refine' le_antisymm _ _\n  \u00b7 have : tendsto (fun t : \u211d\u22650 => (t ^ 2 * \u03c1 s : \u211d\u22650\u221e)) (\ud835\udcdd[>] 1) (\ud835\udcdd ((1 : \u211d\u22650) ^ 2 * \u03c1 s)) :=\n      by\n      refine' ENNReal.Tendsto.mul _ _ tendsto_const_nhds _\n      \u00b7 exact ENNReal.Tendsto.pow (ENNReal.tendsto_coe.2 nhdsWithin_le_nhds)\n      \u00b7 simp only [one_pow, ENNReal.coe_one, true_or_iff, Ne.def, not_false_iff, one_ne_zero]\n      \u00b7 simp only [one_pow, ENNReal.coe_one, Ne.def, or_true_iff, ENNReal.one_ne_top, not_false_iff]\n    simp only [one_pow, one_mul, ENNReal.coe_one] at this\n    refine' ge_of_tendsto this _\n    filter_upwards [self_mem_nhdsWithin]with _ ht\n    exact v.with_density_le_mul h\u03c1 hs ht\n  \u00b7 have :\n      tendsto (fun t : \u211d\u22650 => (t : \u211d\u22650\u221e) * \u03bc.with_density (v.lim_ratio_meas h\u03c1) s) (\ud835\udcdd[>] 1)\n        (\ud835\udcdd ((1 : \u211d\u22650) * \u03bc.with_density (v.lim_ratio_meas h\u03c1) s)) :=\n      by\n      refine' ENNReal.Tendsto.mul_const (ENNReal.tendsto_coe.2 nhdsWithin_le_nhds) _\n      simp only [ENNReal.coe_one, true_or_iff, Ne.def, not_false_iff, one_ne_zero]\n    simp only [one_mul, ENNReal.coe_one] at this\n    refine' ge_of_tendsto this _\n    filter_upwards [self_mem_nhdsWithin]with _ ht\n    exact v.le_mul_with_density h\u03c1 hs ht\n#align vitali_family.with_density_lim_ratio_meas_eq VitaliFamily.withDensity_limRatioMeas_eq\n\n/-- Weak version of the main theorem on differentiation of measures: given a Vitali family `v`\nfor a locally finite measure `\u03bc`, and another locally finite measure `\u03c1`, then for `\u03bc`-almost\nevery `x` the ratio `\u03c1 a / \u03bc a` converges, when `a` shrinks to `x` along the Vitali family,\ntowards the Radon-Nikodym derivative of `\u03c1` with respect to `\u03bc`.\n\nThis version assumes that `\u03c1` is absolutely continuous with respect to `\u03bc`. The general version\nwithout this superfluous assumption is `vitali_family.ae_tendsto_rn_deriv`.\n-/\ntheorem ae_tendsto_rnDeriv_of_absolutelyContinuous :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u03c1 a / \u03bc a) (v.filterAt x) (\ud835\udcdd (\u03c1.rnDeriv \u03bc x)) :=\n  by\n  have A : (\u03bc.with_density (v.lim_ratio_meas h\u03c1)).rnDeriv \u03bc =\u1d50[\u03bc] v.lim_ratio_meas h\u03c1 :=\n    rn_deriv_with_density \u03bc (v.lim_ratio_meas_measurable h\u03c1)\n  rw [v.with_density_lim_ratio_meas_eq h\u03c1] at A\n  filter_upwards [v.ae_tendsto_lim_ratio_meas h\u03c1, A]with _ _ h'x\n  rwa [h'x]\n#align vitali_family.ae_tendsto_rn_deriv_of_absolutely_continuous VitaliFamily.ae_tendsto_rnDeriv_of_absolutelyContinuous\n\nend AbsolutelyContinuous\n\nvariable (\u03c1)\n\n/-- Main theorem on differentiation of measures: given a Vitali family `v` for a locally finite\nmeasure `\u03bc`, and another locally finite measure `\u03c1`, then for `\u03bc`-almost every `x` the\nratio `\u03c1 a / \u03bc a` converges, when `a` shrinks to `x` along the Vitali family, towards the\nRadon-Nikodym derivative of `\u03c1` with respect to `\u03bc`. -/\ntheorem ae_tendsto_rnDeriv :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u03c1 a / \u03bc a) (v.filterAt x) (\ud835\udcdd (\u03c1.rnDeriv \u03bc x)) :=\n  by\n  let t := \u03bc.with_density (\u03c1.rn_deriv \u03bc)\n  have eq_add : \u03c1 = \u03c1.singular_part \u03bc + t := have_lebesgue_decomposition_add _ _\n  have A : \u2200\u1d50 x \u2202\u03bc, tendsto (fun a => \u03c1.singular_part \u03bc a / \u03bc a) (v.filter_at x) (\ud835\udcdd 0) :=\n    v.ae_eventually_measure_zero_of_singular (mutually_singular_singular_part \u03c1 \u03bc)\n  have B : \u2200\u1d50 x \u2202\u03bc, t.rn_deriv \u03bc x = \u03c1.rn_deriv \u03bc x :=\n    rn_deriv_with_density \u03bc (measurable_rn_deriv \u03c1 \u03bc)\n  have C : \u2200\u1d50 x \u2202\u03bc, tendsto (fun a => t a / \u03bc a) (v.filter_at x) (\ud835\udcdd (t.rn_deriv \u03bc x)) :=\n    v.ae_tendsto_rn_deriv_of_absolutely_continuous (with_density_absolutely_continuous _ _)\n  filter_upwards [A, B, C]with _ Ax Bx Cx\n  convert Ax.add Cx\n  \u00b7 ext1 a\n    conv_lhs => rw [eq_add]\n    simp only [Pi.add_apply, coe_add, ENNReal.add_div]\n  \u00b7 simp only [Bx, zero_add]\n#align vitali_family.ae_tendsto_rn_deriv VitaliFamily.ae_tendsto_rnDeriv\n\n/-! ### Lebesgue density points -/\n\n\n/-- Given a measurable set `s`, then `\u03bc (s \u2229 a) / \u03bc a` converges when `a` shrinks to a typical\npoint `x` along a Vitali family. The limit is `1` for `x \u2208 s` and `0` for `x \u2209 s`. This shows that\nalmost every point of `s` is a Lebesgue density point for `s`. A version for non-measurable sets\nholds, but it only gives the first conclusion, see `ae_tendsto_measure_inter_div`. -/\ntheorem ae_tendsto_measure_inter_div_of_measurableSet {s : Set \u03b1} (hs : MeasurableSet s) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u03bc (s \u2229 a) / \u03bc a) (v.filterAt x) (\ud835\udcdd (s.indicator 1 x)) :=\n  by\n  haveI : is_locally_finite_measure (\u03bc.restrict s) :=\n    is_locally_finite_measure_of_le restrict_le_self\n  filter_upwards [ae_tendsto_rn_deriv v (\u03bc.restrict s), rn_deriv_restrict \u03bc hs]\n  intro x hx h'x\n  simpa only [h'x, restrict_apply' hs, inter_comm] using hx\n#align vitali_family.ae_tendsto_measure_inter_div_of_measurable_set VitaliFamily.ae_tendsto_measure_inter_div_of_measurableSet\n\n/-- Given an arbitrary set `s`, then `\u03bc (s \u2229 a) / \u03bc a` converges to `1` when `a` shrinks to a\ntypical point of `s` along a Vitali family. This shows that almost every point of `s` is a\nLebesgue density point for `s`. A stronger version for measurable sets is given\nin `ae_tendsto_measure_inter_div_of_measurable_set`. -/\ntheorem ae_tendsto_measure_inter_div (s : Set \u03b1) :\n    \u2200\u1d50 x \u2202\u03bc.restrict s, Tendsto (fun a => \u03bc (s \u2229 a) / \u03bc a) (v.filterAt x) (\ud835\udcdd 1) :=\n  by\n  let t := to_measurable \u03bc s\n  have A :\n    \u2200\u1d50 x \u2202\u03bc.restrict s, tendsto (fun a => \u03bc (t \u2229 a) / \u03bc a) (v.filter_at x) (\ud835\udcdd (t.indicator 1 x)) :=\n    by\n    apply ae_mono restrict_le_self\n    apply ae_tendsto_measure_inter_div_of_measurable_set\n    exact measurable_set_to_measurable _ _\n  have B : \u2200\u1d50 x \u2202\u03bc.restrict s, t.indicator 1 x = (1 : \u211d\u22650\u221e) :=\n    by\n    refine' ae_restrict_of_ae_restrict_of_subset (subset_to_measurable \u03bc s) _\n    filter_upwards [ae_restrict_mem (measurable_set_to_measurable \u03bc s)]with _ hx\n    simp only [hx, Pi.one_apply, indicator_of_mem]\n  filter_upwards [A, B]with x hx h'x\n  rw [h'x] at hx\n  apply hx.congr' _\n  filter_upwards [v.eventually_filter_at_measurable_set x]with _ ha\n  congr 1\n  exact measure_to_measurable_inter_of_sigma_finite ha _\n#align vitali_family.ae_tendsto_measure_inter_div VitaliFamily.ae_tendsto_measure_inter_div\n\n/-! ### Lebesgue differentiation theorem -/\n\n\ntheorem ae_tendsto_lintegral_div' {f : \u03b1 \u2192 \u211d\u22650\u221e} (hf : Measurable f) (h'f : (\u222b\u207b y, f y \u2202\u03bc) \u2260 \u221e) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => (\u222b\u207b y in a, f y \u2202\u03bc) / \u03bc a) (v.filterAt x) (\ud835\udcdd (f x)) :=\n  by\n  let \u03c1 := \u03bc.with_density f\n  have : is_finite_measure \u03c1 := is_finite_measure_with_density h'f\n  filter_upwards [ae_tendsto_rn_deriv v \u03c1, rn_deriv_with_density \u03bc hf]with x hx h'x\n  rw [\u2190 h'x]\n  apply hx.congr' _\n  filter_upwards [v.eventually_filter_at_measurable_set]with a ha\n  rw [\u2190 with_density_apply f ha]\n#align vitali_family.ae_tendsto_lintegral_div' VitaliFamily.ae_tendsto_lintegral_div'\n\ntheorem ae_tendsto_lintegral_div {f : \u03b1 \u2192 \u211d\u22650\u221e} (hf : AeMeasurable f \u03bc) (h'f : (\u222b\u207b y, f y \u2202\u03bc) \u2260 \u221e) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => (\u222b\u207b y in a, f y \u2202\u03bc) / \u03bc a) (v.filterAt x) (\ud835\udcdd (f x)) :=\n  by\n  have A : (\u222b\u207b y, hf.mk f y \u2202\u03bc) \u2260 \u221e := by\n    convert h'f using 1\n    apply lintegral_congr_ae\n    exact hf.ae_eq_mk.symm\n  filter_upwards [v.ae_tendsto_lintegral_div' hf.measurable_mk A, hf.ae_eq_mk]with x hx h'x\n  rw [h'x]\n  convert hx\n  ext1 a\n  congr 1\n  apply lintegral_congr_ae\n  exact ae_restrict_of_ae hf.ae_eq_mk\n#align vitali_family.ae_tendsto_lintegral_div VitaliFamily.ae_tendsto_lintegral_div\n\ntheorem ae_tendsto_lintegral_nnnorm_sub_div' {f : \u03b1 \u2192 E} (hf : Integrable f \u03bc)\n    (h'f : StronglyMeasurable f) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => (\u222b\u207b y in a, \u2016f y - f x\u2016\u208a \u2202\u03bc) / \u03bc a) (v.filterAt x) (\ud835\udcdd 0) :=\n  by\n  /- For every `c`, then `(\u222b\u207b y in a, \u2016f y - c\u2016\u208a \u2202\u03bc) / \u03bc a` tends almost everywhere to `\u2016f x - c\u2016`.\n    We apply this to a countable set of `c` which is dense in the range of `f`, to deduce the desired\n    convergence.\n    A minor technical inconvenience is that constants are not integrable, so to apply previous lemmas\n    we need to replace `c` with the restriction of `c` to a finite measure set `A n` in the\n    above sketch. -/\n  let A := MeasureTheory.Measure.finiteSpanningSetsInOpen' \u03bc\n  rcases h'f.is_separable_range with \u27e8t, t_count, ht\u27e9\n  have main :\n    \u2200\u1d50 x \u2202\u03bc,\n      \u2200 (n : \u2115) (c : E) (hc : c \u2208 t),\n        tendsto (fun a => (\u222b\u207b y in a, \u2016f y - (A.set n).indicator (fun y => c) y\u2016\u208a \u2202\u03bc) / \u03bc a)\n          (v.filter_at x) (\ud835\udcdd \u2016f x - (A.set n).indicator (fun y => c) x\u2016\u208a) :=\n    by\n    simp_rw [ae_all_iff, ae_ball_iff t_count]\n    intro n c hc\n    apply ae_tendsto_lintegral_div'\n    \u00b7 refine' (h'f.sub _).ennnorm\n      exact strongly_measurable_const.indicator (IsOpen.measurableSet (A.set_mem n))\n    \u00b7 apply ne_of_lt\n      calc\n        (\u222b\u207b y, \u2191\u2016f y - (A.set n).indicator (fun y : \u03b1 => c) y\u2016\u208a \u2202\u03bc) \u2264\n            \u222b\u207b y, \u2016f y\u2016\u208a + \u2016(A.set n).indicator (fun y : \u03b1 => c) y\u2016\u208a \u2202\u03bc :=\n          by\n          apply lintegral_mono\n          intro x\n          dsimp\n          rw [\u2190 ENNReal.coe_add]\n          exact ENNReal.coe_le_coe.2 (nnnorm_sub_le _ _)\n        _ = (\u222b\u207b y, \u2016f y\u2016\u208a \u2202\u03bc) + \u222b\u207b y, \u2016(A.set n).indicator (fun y : \u03b1 => c) y\u2016\u208a \u2202\u03bc :=\n          (lintegral_add_left h'f.ennnorm _)\n        _ < \u221e + \u221e :=\n          haveI I : integrable ((A.set n).indicator fun y : \u03b1 => c) \u03bc := by\n            simp only [integrable_indicator_iff (IsOpen.measurableSet (A.set_mem n)),\n              integrable_on_const, A.finite n, or_true_iff]\n          ENNReal.add_lt_add hf.2 I.2\n        \n  filter_upwards [main, v.ae_eventually_measure_pos]with x hx h'x\n  have M :\n    \u2200 c \u2208 t, tendsto (fun a => (\u222b\u207b y in a, \u2016f y - c\u2016\u208a \u2202\u03bc) / \u03bc a) (v.filter_at x) (\ud835\udcdd \u2016f x - c\u2016\u208a) :=\n    by\n    intro c hc\n    obtain \u27e8n, xn\u27e9 : \u2203 n, x \u2208 A.set n := by simpa [\u2190 A.spanning] using mem_univ x\n    specialize hx n c hc\n    simp only [xn, indicator_of_mem] at hx\n    apply hx.congr' _\n    filter_upwards [v.eventually_filter_at_subset_of_nhds (IsOpen.mem_nhds (A.set_mem n) xn),\n      v.eventually_filter_at_measurable_set]with a ha h'a\n    congr 1\n    apply set_lintegral_congr_fun h'a\n    apply eventually_of_forall fun y => _\n    intro hy\n    simp only [ha hy, indicator_of_mem]\n  apply ENNReal.tendsto_nhds_zero.2 fun \u03b5 \u03b5pos => _\n  obtain \u27e8c, ct, xc\u27e9 : \u2203 c \u2208 t, (\u2016f x - c\u2016\u208a : \u211d\u22650\u221e) < \u03b5 / 2 :=\n    by\n    simp_rw [\u2190 edist_eq_coe_nnnorm_sub]\n    have : f x \u2208 closure t := ht (mem_range_self _)\n    exact EMetric.mem_closure_iff.1 this (\u03b5 / 2) (ENNReal.half_pos (ne_of_gt \u03b5pos))\n  filter_upwards [(tendsto_order.1 (M c ct)).2 (\u03b5 / 2) xc, h'x,\n    v.eventually_measure_lt_top x]with a ha h'a h''a\n  apply ENNReal.div_le_of_le_mul\n  calc\n    (\u222b\u207b y in a, \u2016f y - f x\u2016\u208a \u2202\u03bc) \u2264 \u222b\u207b y in a, \u2016f y - c\u2016\u208a + \u2016f x - c\u2016\u208a \u2202\u03bc :=\n      by\n      apply lintegral_mono fun x => _\n      simpa only [\u2190 edist_eq_coe_nnnorm_sub] using edist_triangle_right _ _ _\n    _ = (\u222b\u207b y in a, \u2016f y - c\u2016\u208a \u2202\u03bc) + \u222b\u207b y in a, \u2016f x - c\u2016\u208a \u2202\u03bc :=\n      (lintegral_add_right _ measurable_const)\n    _ \u2264 \u03b5 / 2 * \u03bc a + \u03b5 / 2 * \u03bc a := by\n      refine' add_le_add _ _\n      \u00b7 rw [ENNReal.div_lt_iff (Or.inl h'a.ne') (Or.inl h''a.ne)] at ha\n        exact ha.le\n      \u00b7 simp only [lintegral_const, measure.restrict_apply, MeasurableSet.univ, univ_inter]\n        exact mul_le_mul_right' xc.le _\n    _ = \u03b5 * \u03bc a := by rw [\u2190 add_mul, ENNReal.add_halves]\n    \n#align vitali_family.ae_tendsto_lintegral_nnnorm_sub_div' VitaliFamily.ae_tendsto_lintegral_nnnorm_sub_div'\n\ntheorem ae_tendsto_lintegral_nnnorm_sub_div {f : \u03b1 \u2192 E} (hf : Integrable f \u03bc) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => (\u222b\u207b y in a, \u2016f y - f x\u2016\u208a \u2202\u03bc) / \u03bc a) (v.filterAt x) (\ud835\udcdd 0) :=\n  by\n  have I : integrable (hf.1.mk f) \u03bc := hf.congr hf.1.ae_eq_mk\n  filter_upwards [v.ae_tendsto_lintegral_nnnorm_sub_div' I hf.1.stronglyMeasurable_mk,\n    hf.1.ae_eq_mk]with x hx h'x\n  apply hx.congr _\n  intro a\n  congr 1\n  apply lintegral_congr_ae\n  apply ae_restrict_of_ae\n  filter_upwards [hf.1.ae_eq_mk]with y hy\n  rw [hy, h'x]\n#align vitali_family.ae_tendsto_lintegral_nnnorm_sub_div VitaliFamily.ae_tendsto_lintegral_nnnorm_sub_div\n\n/-- *Lebesgue differentiation theorem*: for almost every point `x`, the\naverage of `\u2016f y - f x\u2016` on `a` tends to `0` as `a` shrinks to `x` along a Vitali family.-/\ntheorem ae_tendsto_average_norm_sub {f : \u03b1 \u2192 E} (hf : Integrable f \u03bc) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u2a0d y in a, \u2016f y - f x\u2016 \u2202\u03bc) (v.filterAt x) (\ud835\udcdd 0) :=\n  by\n  filter_upwards [v.ae_tendsto_lintegral_nnnorm_sub_div hf,\n    v.ae_eventually_measure_pos]with x hx h'x\n  have := (ENNReal.tendsto_toReal ENNReal.zero_ne_top).comp hx\n  simp only [ENNReal.zero_toReal] at this\n  apply tendsto.congr' _ this\n  filter_upwards [h'x, v.eventually_measure_lt_top x]with a ha h'a\n  simp only [Function.comp_apply, ENNReal.toReal_div, set_average_eq, div_eq_inv_mul]\n  have A : integrable_on (fun y => (\u2016f y - f x\u2016\u208a : \u211d)) a \u03bc :=\n    by\n    simp_rw [coe_nnnorm]\n    exact (hf.integrable_on.sub (integrable_on_const.2 (Or.inr h'a))).norm\n  rw [lintegral_coe_eq_integral _ A, ENNReal.toReal_ofReal]\n  \u00b7 simp_rw [coe_nnnorm]\n    rfl\n  \u00b7 apply integral_nonneg\n    intro x\n    exact NNReal.coe_nonneg _\n#align vitali_family.ae_tendsto_average_norm_sub VitaliFamily.ae_tendsto_average_norm_sub\n\n/-- *Lebesgue differentiation theorem*: for almost every point `x`, the\naverage of `f` on `a` tends to `f x` as `a` shrinks to `x` along a Vitali family.-/\ntheorem ae_tendsto_average [NormedSpace \u211d E] [CompleteSpace E] {f : \u03b1 \u2192 E} (hf : Integrable f \u03bc) :\n    \u2200\u1d50 x \u2202\u03bc, Tendsto (fun a => \u2a0d y in a, f y \u2202\u03bc) (v.filterAt x) (\ud835\udcdd (f x)) :=\n  by\n  filter_upwards [v.ae_tendsto_average_norm_sub hf, v.ae_eventually_measure_pos]with x hx h'x\n  rw [tendsto_iff_norm_tendsto_zero]\n  refine' squeeze_zero' (eventually_of_forall fun a => norm_nonneg _) _ hx\n  filter_upwards [h'x, v.eventually_measure_lt_top x]with a ha h'a\n  nth_rw 1 [\u2190 set_average_const ha.ne' h'a.ne (f x)]\n  simp_rw [set_average_eq']\n  rw [\u2190 integral_sub]\n  \u00b7 exact norm_integral_le_integral_norm _\n  \u00b7 exact (integrable_inv_smul_measure ha.ne' h'a.ne).2 hf.integrable_on\n  \u00b7 exact (integrable_inv_smul_measure ha.ne' h'a.ne).2 (integrable_on_const.2 (Or.inr h'a))\n#align vitali_family.ae_tendsto_average VitaliFamily.ae_tendsto_average\n\nend\n\nend VitaliFamily\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Covering/Differentiation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7195947203554426}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.eval\nimport Mathlib.PostPort\n\nuniverses u u_1 y v \n\nnamespace Mathlib\n\n/-!\n# The derivative map on polynomials\n\n## Main definitions\n * `polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map.\n\n-/\n\nnamespace polynomial\n\n\n/-- `derivative p` is the formal derivative of the polynomial `p` -/\ndef derivative {R : Type u} [semiring R] : linear_map R (polynomial R) (polynomial R) :=\n  finsupp.total \u2115 (polynomial R) R fun (n : \u2115) => coe_fn C \u2191n * X ^ (n - 1)\n\ntheorem derivative_apply {R : Type u} [semiring R] (p : polynomial R) : coe_fn derivative p = finsupp.sum p fun (n : \u2115) (a : R) => coe_fn C (a * \u2191n) * X ^ (n - 1) := sorry\n\ntheorem coeff_derivative {R : Type u} [semiring R] (p : polynomial R) (n : \u2115) : coeff (coe_fn derivative p) n = coeff p (n + 1) * (\u2191n + 1) := sorry\n\ntheorem derivative_zero {R : Type u} [semiring R] : coe_fn derivative 0 = 0 :=\n  linear_map.map_zero derivative\n\ntheorem derivative_monomial {R : Type u} [semiring R] (a : R) (n : \u2115) : coe_fn derivative (coe_fn (monomial n) a) = coe_fn (monomial (n - 1)) (a * \u2191n) := sorry\n\ntheorem derivative_C_mul_X_pow {R : Type u} [semiring R] (a : R) (n : \u2115) : coe_fn derivative (coe_fn C a * X ^ n) = coe_fn C (a * \u2191n) * X ^ (n - 1) := sorry\n\n@[simp] theorem derivative_X_pow {R : Type u} [semiring R] (n : \u2115) : coe_fn derivative (X ^ n) = \u2191n * X ^ (n - 1) := sorry\n\n@[simp] theorem derivative_C {R : Type u} [semiring R] {a : R} : coe_fn derivative (coe_fn C a) = 0 := sorry\n\n@[simp] theorem derivative_X {R : Type u} [semiring R] : coe_fn derivative X = 1 := sorry\n\n@[simp] theorem derivative_one {R : Type u} [semiring R] : coe_fn derivative 1 = 0 :=\n  derivative_C\n\n@[simp] theorem derivative_bit0 {R : Type u} [semiring R] {a : polynomial R} : coe_fn derivative (bit0 a) = bit0 (coe_fn derivative a) := sorry\n\n@[simp] theorem derivative_bit1 {R : Type u} [semiring R] {a : polynomial R} : coe_fn derivative (bit1 a) = bit0 (coe_fn derivative a) := sorry\n\n@[simp] theorem derivative_add {R : Type u} [semiring R] {f : polynomial R} {g : polynomial R} : coe_fn derivative (f + g) = coe_fn derivative f + coe_fn derivative g :=\n  linear_map.map_add derivative f g\n\n@[simp] theorem derivative_neg {R : Type u_1} [ring R] (f : polynomial R) : coe_fn derivative (-f) = -coe_fn derivative f :=\n  linear_map.map_neg derivative f\n\n@[simp] theorem derivative_sub {R : Type u_1} [ring R] (f : polynomial R) (g : polynomial R) : coe_fn derivative (f - g) = coe_fn derivative f - coe_fn derivative g :=\n  linear_map.map_sub derivative f g\n\n@[simp] theorem derivative_sum {R : Type u} {\u03b9 : Type y} [semiring R] {s : finset \u03b9} {f : \u03b9 \u2192 polynomial R} : coe_fn derivative (finset.sum s fun (b : \u03b9) => f b) = finset.sum s fun (b : \u03b9) => coe_fn derivative (f b) :=\n  linear_map.map_sum derivative\n\n@[simp] theorem derivative_smul {R : Type u} [semiring R] (r : R) (p : polynomial R) : coe_fn derivative (r \u2022 p) = r \u2022 coe_fn derivative p :=\n  linear_map.map_smul derivative r p\n\ntheorem derivative_eval {R : Type u} [comm_semiring R] (p : polynomial R) (x : R) : eval x (coe_fn derivative p) = finsupp.sum p fun (n : \u2115) (a : R) => a * \u2191n * x ^ (n - 1) := sorry\n\n@[simp] theorem derivative_mul {R : Type u} [comm_semiring R] {f : polynomial R} {g : polynomial R} : coe_fn derivative (f * g) = coe_fn derivative f * g + f * coe_fn derivative g := sorry\n\ntheorem derivative_pow_succ {R : Type u} [comm_semiring R] (p : polynomial R) (n : \u2115) : coe_fn derivative (p ^ (n + 1)) = (\u2191n + 1) * p ^ n * coe_fn derivative p := sorry\n\ntheorem derivative_pow {R : Type u} [comm_semiring R] (p : polynomial R) (n : \u2115) : coe_fn derivative (p ^ n) = \u2191n * p ^ (n - 1) * coe_fn derivative p := sorry\n\ntheorem derivative_map {R : Type u} {S : Type v} [comm_semiring R] [comm_semiring S] (p : polynomial R) (f : R \u2192+* S) : coe_fn derivative (map f p) = map f (coe_fn derivative p) := sorry\n\n/-- Chain rule for formal derivative of polynomials. -/\ntheorem derivative_eval\u2082_C {R : Type u} [comm_semiring R] (p : polynomial R) (q : polynomial R) : coe_fn derivative (eval\u2082 C q p) = eval\u2082 C q (coe_fn derivative p) * coe_fn derivative q := sorry\n\ntheorem of_mem_support_derivative {R : Type u} [comm_semiring R] {p : polynomial R} {n : \u2115} (h : n \u2208 finsupp.support (coe_fn derivative p)) : n + 1 \u2208 finsupp.support p := sorry\n\ntheorem degree_derivative_lt {R : Type u} [comm_semiring R] {p : polynomial R} (hp : p \u2260 0) : degree (coe_fn derivative p) < degree p :=\n  iff.mpr (finset.sup_lt_iff (iff.mpr bot_lt_iff_ne_bot (mt (iff.mp degree_eq_bot) hp)))\n    fun (n : \u2115) (hp : n \u2208 finsupp.support (coe_fn derivative p)) =>\n      lt_of_lt_of_le (iff.mpr with_bot.some_lt_some (nat.lt_succ_self n)) (finset.le_sup (of_mem_support_derivative hp))\n\ntheorem nat_degree_derivative_lt {R : Type u} [comm_semiring R] {p : polynomial R} (hp : coe_fn derivative p \u2260 0) : nat_degree (coe_fn derivative p) < nat_degree p := sorry\n\ntheorem degree_derivative_le {R : Type u} [comm_semiring R] {p : polynomial R} : degree (coe_fn derivative p) \u2264 degree p := sorry\n\ntheorem mem_support_derivative {R : Type u} [integral_domain R] [char_zero R] (p : polynomial R) (n : \u2115) : n \u2208 finsupp.support (coe_fn derivative p) \u2194 n + 1 \u2208 finsupp.support p := sorry\n\n@[simp] theorem degree_derivative_eq {R : Type u} [integral_domain R] [char_zero R] (p : polynomial R) (hp : 0 < nat_degree p) : degree (coe_fn derivative p) = \u2191(nat_degree p - 1) := sorry\n\ntheorem nat_degree_eq_zero_of_derivative_eq_zero {R : Type u} [integral_domain R] [char_zero R] {f : polynomial R} (h : coe_fn derivative f = 0) : nat_degree f = 0 := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/polynomial/derivative.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.7195947094937665}}
{"text": "import data.nat.prime \nimport tactic.linarith\n\nopen nat \n\ntheorem infinitude_of_primes : \u2200 N : \u2115, \u2203 p \u2265 N, nat.prime p := \nbegin\n  intro N,\n\n  let M : \u2115 := factorial N + 1,\n  let p := min_fac M,\n\n  have pp : nat.prime p := \n  begin\n    refine min_fac_prime _,\n    have : factorial N > 0 := factorial_pos N,\n    linarith,\n  end,\n\n  use p, -- Existencial\n  split, -- split conj \n\n  { by_contradiction,\n    have h\u2081 : p \u2223 factorial N + 1 := min_fac_dvd M,\n    have h\u2082 : p \u2223 factorial N := by \n    begin\n      refine pp.dvd_factorial.mpr _,\n      exact le_of_not_ge h\n    end,\n    have h : p \u2223 1 := (nat.dvd_add_right h\u2082).mp h\u2081,\n    exact nat.prime.not_dvd_one pp h,\n  },\n  { exact pp,\n  },\n\nend\n\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/LftCM2020/01_infinitude_of_primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.7195687596267019}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module topology.continuous_function.weierstrass\n! leanprover-community/mathlib commit 17ef379e997badd73e5eabb4d38f11919ab3c4b3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.SpecialFunctions.Bernstein\nimport Mathbin.Topology.Algebra.Algebra\n\n/-!\n# The Weierstrass approximation theorem for continuous functions on `[a,b]`\n\nWe've already proved the Weierstrass approximation theorem\nin the sense that we've shown that the Bernstein approximations\nto a continuous function on `[0,1]` converge uniformly.\n\nHere we rephrase this more abstractly as\n`polynomial_functions_closure_eq_top' : (polynomial_functions I).topological_closure = \u22a4`\nand then, by precomposing with suitable affine functions,\n`polynomial_functions_closure_eq_top : (polynomial_functions (set.Icc a b)).topological_closure = \u22a4`\n-/\n\n\nopen ContinuousMap Filter\n\nopen unitInterval\n\n/-- The special case of the Weierstrass approximation theorem for the interval `[0,1]`.\nThis is just a matter of unravelling definitions and using the Bernstein approximations.\n-/\ntheorem polynomialFunctions_closure_eq_top' : (polynomialFunctions I).topologicalClosure = \u22a4 :=\n  by\n  apply eq_top_iff.mpr\n  rintro f -\n  refine' Filter.Frequently.mem_closure _\n  refine' Filter.Tendsto.frequently (bernsteinApproximation_uniform f) _\n  apply frequently_of_forall\n  intro n\n  simp only [SetLike.mem_coe]\n  apply Subalgebra.sum_mem\n  rintro n -\n  apply Subalgebra.smul_mem\n  dsimp [bernstein, polynomialFunctions]\n  simp\n#align polynomial_functions_closure_eq_top' polynomialFunctions_closure_eq_top'\n\n/-- The **Weierstrass Approximation Theorem**:\npolynomials functions on `[a, b] \u2286 \u211d` are dense in `C([a,b],\u211d)`\n\n(While we could deduce this as an application of the Stone-Weierstrass theorem,\nour proof of that relies on the fact that `abs` is in the closure of polynomials on `[-M, M]`,\nso we may as well get this done first.)\n-/\ntheorem polynomialFunctions_closure_eq_top (a b : \u211d) :\n    (polynomialFunctions (Set.Icc a b)).topologicalClosure = \u22a4 :=\n  by\n  by_cases h : a < b\n  -- (Otherwise it's easy; we'll deal with that later.)\n  \u00b7 -- We can pullback continuous functions on `[a,b]` to continuous functions on `[0,1]`,\n    -- by precomposing with an affine map.\n    let W : C(Set.Icc a b, \u211d) \u2192\u2090[\u211d] C(I, \u211d) :=\n      comp_right_alg_hom \u211d \u211d (iccHomeoI a b h).symm.toContinuousMap\n    -- This operation is itself a homeomorphism\n    -- (with respect to the norm topologies on continuous functions).\n    let W' : C(Set.Icc a b, \u211d) \u2243\u209c C(I, \u211d) := comp_right_homeomorph \u211d (iccHomeoI a b h).symm\n    have w : (W : C(Set.Icc a b, \u211d) \u2192 C(I, \u211d)) = W' := rfl\n    -- Thus we take the statement of the Weierstrass approximation theorem for `[0,1]`,\n    have p := polynomialFunctions_closure_eq_top'\n    -- and pullback both sides, obtaining an equation between subalgebras of `C([a,b], \u211d)`.\n    apply_fun fun s => s.comap W  at p\n    simp only [Algebra.comap_top] at p\n    -- Since the pullback operation is continuous, it commutes with taking `topological_closure`,\n    rw [Subalgebra.topologicalClosure_comap_homeomorph _ W W' w] at p\n    -- and precomposing with an affine map takes polynomial functions to polynomial functions.\n    rw [polynomialFunctions.comap_compRightAlgHom_iccHomeoI] at p\n    -- \ud83c\udf89\n    exact p\n  \u00b7 -- Otherwise, `b \u2264 a`, and the interval is a subsingleton,\n    -- so all subalgebras are the same anyway.\n    haveI : Subsingleton (Set.Icc a b) :=\n      \u27e8fun x y =>\n        le_antisymm ((x.2.2.trans (not_lt.mp h)).trans y.2.1)\n          ((y.2.2.trans (not_lt.mp h)).trans x.2.1)\u27e9\n    apply Subsingleton.elim\n#align polynomial_functions_closure_eq_top polynomialFunctions_closure_eq_top\n\n/-- An alternative statement of Weierstrass' theorem.\n\nEvery real-valued continuous function on `[a,b]` is a uniform limit of polynomials.\n-/\ntheorem continuousMap_mem_polynomialFunctions_closure (a b : \u211d) (f : C(Set.Icc a b, \u211d)) :\n    f \u2208 (polynomialFunctions (Set.Icc a b)).topologicalClosure :=\n  by\n  rw [polynomialFunctions_closure_eq_top _ _]\n  simp\n#align continuous_map_mem_polynomial_functions_closure continuousMap_mem_polynomialFunctions_closure\n\nopen Polynomial\n\n/-- An alternative statement of Weierstrass' theorem,\nfor those who like their epsilons.\n\nEvery real-valued continuous function on `[a,b]` is within any `\u03b5 > 0` of some polynomial.\n-/\ntheorem exists_polynomial_near_continuousMap (a b : \u211d) (f : C(Set.Icc a b, \u211d)) (\u03b5 : \u211d)\n    (pos : 0 < \u03b5) : \u2203 p : \u211d[X], \u2016p.toContinuousMapOn _ - f\u2016 < \u03b5 :=\n  by\n  have w := mem_closure_iff_frequently.mp (continuousMap_mem_polynomialFunctions_closure _ _ f)\n  rw [metric.nhds_basis_ball.frequently_iff] at w\n  obtain \u27e8-, H, \u27e8m, \u27e8-, rfl\u27e9\u27e9\u27e9 := w \u03b5 Pos\n  rw [Metric.mem_ball, dist_eq_norm] at H\n  exact \u27e8m, H\u27e9\n#align exists_polynomial_near_continuous_map exists_polynomial_near_continuousMap\n\n/-- Another alternative statement of Weierstrass's theorem,\nfor those who like epsilons, but not bundled continuous functions.\n\nEvery real-valued function `\u211d \u2192 \u211d` which is continuous on `[a,b]`\ncan be approximated to within any `\u03b5 > 0` on `[a,b]` by some polynomial.\n-/\ntheorem exists_polynomial_near_of_continuousOn (a b : \u211d) (f : \u211d \u2192 \u211d)\n    (c : ContinuousOn f (Set.Icc a b)) (\u03b5 : \u211d) (pos : 0 < \u03b5) :\n    \u2203 p : \u211d[X], \u2200 x \u2208 Set.Icc a b, |p.eval x - f x| < \u03b5 :=\n  by\n  let f' : C(Set.Icc a b, \u211d) := \u27e8fun x => f x, continuous_on_iff_continuous_restrict.mp c\u27e9\n  obtain \u27e8p, b\u27e9 := exists_polynomial_near_continuousMap a b f' \u03b5 Pos\n  use p\n  rw [norm_lt_iff _ Pos] at b\n  intro x m\n  exact b \u27e8x, m\u27e9\n#align exists_polynomial_near_of_continuous_on exists_polynomial_near_of_continuousOn\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/ContinuousFunction/Weierstrass.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7194854675511073}}
{"text": "import game.world10.level17 -- hide\nnamespace mynat -- hide\n\n-- todo INTRODUCE CONGR\n\nlemma lt_irrefl (a : mynat) : \u00ac (a < a) :=\nbegin [nat_num_game]\n  intro h,\n  cases h with h1 h2,\n  apply h2,\n  exact h1,\nend\n\nlemma ne_of_lt (a b : mynat) : a < b \u2192 a \u2260 b :=\nbegin [nat_num_game]\n  intro h,\n  intro h1,\n  cases h with h2 h3,\n  apply h3,\n  rw h1,\n  refl,\nend\n\n-- I had \n-- theorem ne_zero_of_pos (a : mynat) : 0 < a \u2192 a \u2260 0 :=\n-- do we really need this??\n\ntheorem not_lt_zero (a : mynat) : \u00ac(a < 0) :=\nbegin [nat_num_game]\n  intro h,\n  cases h with ha hna,\n  apply hna,\n  exact zero_le a,\nend\n\ntheorem lt_of_lt_of_le (a b c : mynat) : a < b \u2192 b \u2264 c \u2192 a < c :=\nbegin\n  intro hab,\n  intro hbc,\n  rw lt_iff_succ_le at hab \u22a2,\n  cases hbc with x hx,\n  cases hab with y hy,\n  rw hx,\n  rw hy,\n  use y + x,\n  ring,\nend\n\ntheorem lt_of_le_of_lt (a b c : mynat) : a \u2264 b \u2192 b < c \u2192 a < c :=\nbegin [nat_num_game]\n  intro hab,\n  intro hbc,\n  rw lt_iff_succ_le at hbc \u22a2,\n  cases hbc with x hx,\n  cases hab with y hy,\n  rw hx,\n  rw hy,\n  use y + x,\n  rw succ_add,\n  rw succ_add,\n  rw add_assoc,\n  refl,\nend\n\ntheorem lt_trans (a b c : mynat) : a < b \u2192 b < c \u2192 a < c :=\nbegin [nat_num_game]\n  intro hab,\n  intro hbc,\n  rw lt_iff_succ_le at hab hbc \u22a2,\n  cases hbc with x hx,\n  cases hab with y hy,\n  rw hx,\n  rw hy,\n  use y + x + 1,\n  repeat {rw succ_add},\n  repeat {rw succ_eq_add_one},\n  simp,\n\n\nend\n\n\n\ntheorem lt_iff_le_and_ne (a b : mynat) : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\nbegin [nat_num_game]\n  split,\n    intro h,\n    cases h with h1 h2,\n    split,\n      assumption,\n    intro h,\n    apply h2,\n    rw h,\n    refl,\n  intro h,\n  cases h with h1 h2,\n  split,\n    exact h1,\n  intro h,\n  apply h2,\n  exact le_antisymm _ _ h1 h\n\n\nend\n\ntheorem lt_succ_self (n : mynat) : n < succ n :=\nbegin [nat_num_game]\n  rw lt_iff_le_and_ne,\n  split,\n    use 1,\n    apply succ_eq_add_one,\n  intro h,\n  exact ne_succ_self n h\nend\n\nlemma succ_le_succ_iff (m n : mynat) : succ m \u2264 succ n \u2194 m \u2264 n :=\nbegin [nat_num_game]\n  split,\n    intro h,\n    cases h with c hc,\n    use c,\n    apply succ_inj,\n    rw hc,\n    rw succ_add,\n    refl,\n  intro h,\n  cases h with c hc,\n  use c,\n  rw hc,\n  rw succ_add,\n  refl,\n\n\n\nend\n\n-- remind user about succ_le_succ_iff\nlemma lt_succ_iff_le (m n : mynat) : m < succ n \u2194 m \u2264 n :=\nbegin [nat_num_game]\n  rw lt_iff_succ_le,\n  exact succ_le_succ_iff m n\nend\n\n\n-- note: needs add_left_cancel but otherwise is easy. \nlemma le_of_add_le_add_left (a b c : mynat) : a + b \u2264 a + c \u2192 b \u2264 c :=\nbegin [nat_num_game]\n  intro h,\n  cases h with d hd,\n  use d,\n  apply add_left_cancel a,\n  rw hd,\n  ring,\n\n\n\nend\n\n\nlemma lt_of_add_lt_add_left (a b c : mynat) : a + b < a + c \u2192 b < c :=\nbegin [nat_num_game]\n  rw lt_iff_succ_le,\n  rw lt_iff_succ_le,\n  intro h,\n  apply le_of_add_le_add_left a,\n  rw add_succ,\n  exact h,\n\n\n\nend\n\n-- I SHOULD TEACH CONGR\nlemma add_lt_add_right (a b : mynat) : a < b \u2192 \u2200 c : mynat, a + c < b + c :=\nbegin [nat_num_game]\n  intro h,\n  intro c,\n  rw lt_iff_succ_le at h \u22a2,\n  cases h with d hd,\n  use d,\n  rw hd,\n  repeat {rw succ_add},\n  rw add_right_comm,\n  refl,\n\n\nend \n\n-- and now we get three achievements!\ninstance : ordered_comm_monoid mynat := \n{ add_le_add_left := \u03bb _ _, add_le_add_left,\n  lt_of_add_lt_add_left := lt_of_add_lt_add_left,\n  ..mynat.add_comm_monoid, ..mynat.partial_order}\ninstance : canonically_ordered_monoid mynat := \n{ le_iff_exists_add := le_iff_exists_add,\n  bot := 0,\n  bot_le := zero_le,\n  ..mynat.ordered_comm_monoid,\n  }\ninstance : ordered_cancel_comm_monoid mynat := \n{ add_left_cancel := add_left_cancel,\n  add_right_cancel := add_right_cancel,\n  le_of_add_le_add_left := le_of_add_le_add_left,\n  ..mynat.ordered_comm_monoid}\n\ndef succ_lt_succ_iff (a b : mynat) : succ a < succ b \u2194 a < b :=\nbegin [nat_num_game]\n  rw lt_iff_succ_le,\n  rw lt_iff_succ_le,\n  exact succ_le_succ_iff _ _,\n\n\n\nend\n\n-- multiplication\n\ntheorem mul_le_mul_of_nonneg_left (a b c : mynat) : a \u2264 b \u2192 0 \u2264 c \u2192 c * a \u2264 c * b :=\nbegin [nat_num_game]\n  intro hab,\n  intro h0,\n  cases hab with d hd,\n  rw hd,\n  rw mul_add,\n  use c * d,\n  refl\nend\n\ntheorem mul_le_mul_of_nonneg_right (a b c : mynat) : a \u2264 b \u2192 0 \u2264 c \u2192 a * c \u2264 b * c :=\nbegin [nat_num_game]\n  intro hab,\n  intro h0,\n  rw mul_comm,\n  rw mul_comm b,\n  apply mul_le_mul_of_nonneg_left,\n    assumption,\n  assumption\nend\n\n\ntheorem mul_lt_mul_of_pos_left (a b c : mynat) : a < b \u2192 0 < c \u2192 c * a < c * b :=\nbegin [nat_num_game]\n  intro hab,\n  intro hc,\n  cases c with d,\n    exfalso,\n    exact lt_irrefl 0 hc,\n  clear hc,\n  induction d with e he,\n    rw [succ_mul,zero_mul, zero_add, succ_mul, zero_mul, zero_add],\n    exact hab,\n  rw succ_mul,\n  rw succ_mul (succ e),\n  have h : succ e * a + a < succ e * b + a,\n    exact add_lt_add_right _ _ he _,\n  apply lt_trans _ _ _ h,\n  rw add_comm,\n  rw add_comm _ b,\n  apply add_lt_add_right,\n  assumption\nend\n\ntheorem mul_lt_mul_of_pos_right (a b c : mynat) : a < b \u2192 0 < c \u2192 a * c < b * c :=\nbegin [nat_num_game]\n  intros ha h0,\n  rw mul_comm,\n  rw mul_comm b,\n  apply mul_lt_mul_of_pos_left,\n  assumption,\n  assumption\nend\n\n-- And now another achievement! The naturals are an ordered semiring.\ninstance : ordered_semiring mynat := \n{ mul_le_mul_of_nonneg_left := mul_le_mul_of_nonneg_left,\n  mul_le_mul_of_nonneg_right := mul_le_mul_of_nonneg_right,\n  mul_lt_mul_of_pos_left := mul_lt_mul_of_pos_left,\n  mul_lt_mul_of_pos_right := mul_lt_mul_of_pos_right,\n  ..mynat.semiring,\n  ..mynat.ordered_cancel_comm_monoid\n}\n\nlemma le_mul (a b c d : mynat) : a \u2264 b \u2192 c \u2264 d \u2192 a * c \u2264 b * d :=\nbegin [nat_num_game]\nintros hab hcd,\ncases a with t Ht,\n  rw [zero_mul],\n  apply zero_le,\nhave cz : 0 \u2264 c,\n  apply zero_le,\nhave bz : 0 \u2264 b,\n  apply zero_le,\napply mul_le_mul hab hcd cz bz,\nend\n\nlemma pow_le (m n a : mynat) : m \u2264 n \u2192 m ^ a \u2264 n ^ a :=\nbegin [nat_num_game]\nintro h,\ninduction a with t Ht,\n  rw [pow_zero, pow_zero],\n  refl,\nrw [pow_succ, pow_succ],\napply le_mul,\n  assumption,\nassumption,\nend\n\nlemma strong_induction_aux (P : mynat \u2192 Prop)\n  (IH : \u2200 m : mynat, (\u2200 b : mynat, b < m \u2192 P b) \u2192 P m)\n  (n : mynat) : \u2200 c < n, P c :=\nbegin [nat_num_game]\n  induction n with d hd,\n    intro c,\n    intro hc,\n    exfalso,\n    revert hc,\n    exact not_lt_zero c,\n  intros e he,\n  rw lt_succ_iff_le at he,\n  apply IH,\n  intros b hb,\n  apply hd,\n  exact lt_of_lt_of_le _ _ _ hb he\nend\n\n-- is elab_as_eliminator right?\n@[elab_as_eliminator]\ntheorem strong_induction (P : mynat \u2192 Prop)\n  (IH : \u2200 m : mynat, (\u2200 d : mynat, d < m \u2192 P d) \u2192 P m) :\n  \u2200 n, P n :=\nbegin [nat_num_game]\n  intro n,\n  apply strong_induction_aux P IH (succ n),\n  exact lt_succ_self n\nend\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world10/level18a.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7194854644747377}}
{"text": "import ..exercises.love02_backward_proofs_exercise_sheet\n\n\n/-! # LoVe Homework 3: Forward Proofs\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (3 points): Logic Puzzles\n\nConsider the following tactical proof: -/\n\nlemma about_implication :\n  \u2200a b : Prop, \u00ac a \u2228 b \u2192 a \u2192 b :=\nbegin\n  intros a b hor ha,\n  apply or.elim hor,\n  { intro hna,\n    apply false.elim,\n    apply hna,\n    exact ha },\n  { intro hb,\n    exact hb }\nend\n\n/-! 1.1 (1 point). Prove the same lemma again, this time by providing a proof\nterm.\n\nHint: There is an easy way. -/\n\nlemma about_implication\u2082 :\n  \u2200a b : Prop, \u00ac a \u2228 b \u2192 a \u2192 b :=\nsorry\n\n/-! 1.2 (2 points). Prove the same lemma again, this time by providing a\nstructured proof, with `assume`s and `show`s. -/\n\nlemma about_implication\u2083 :\n  \u2200a b : Prop, \u00ac a \u2228 b \u2192 a \u2192 b :=\nsorry\n\n\n/-! ## Question 2 (6 points + 1 bonus point): Connectives and Quantifiers\n\n2.1 (4 points). Supply a structured proof of the commutativity of `\u2228` under a\n`\u2200` quantifier, using no other lemmas than the introduction and elimination\nrules for `\u2200`, `\u2228`, and `\u2194`. -/\n\nlemma all_or_commute {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2200x, p x \u2228 q x) \u2194 (\u2200x, q x \u2228 p x) :=\nsorry\n\n/-! 2.2 (2 points). We have proved or stated three of the six possible\nimplications between `excluded_middle`, `peirce`, and `double_negation`. Prove\nthe three missing implications using structured proofs, exploiting the three\ntheorems we already have. -/\n\nnamespace backward_proofs\n\n#check peirce_of_em\n#check dn_of_peirce\n#check sorry_lemmas.em_of_dn\n\nlemma peirce_of_dn :\n  double_negation \u2192 peirce :=\nsorry\n\nlemma em_of_peirce :\n  peirce \u2192 excluded_middle :=\nsorry\n\nlemma dn_of_em :\n  excluded_middle \u2192 double_negation :=\nsorry\n\nend backward_proofs\n\n/-! 2.3 (1 bonus point). Supply a structured proof of the following property,\nwhich can be used pull a `\u2200`-quantifier past an `\u2203`-quantifier. -/\n\nlemma forall_exists_of_exists_forall {\u03b1 : Type} (p : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2203x, \u2200y, p x y) \u2192 (\u2200y, \u2203x, p x y) :=\nsorry\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/homework/love03_forward_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.719485463977197}}
{"text": "/-\nCopyright (c) 2022 Mantas Bak\u0161ys. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mantas Bak\u0161ys\n-/\nimport algebra.order.module\nimport group_theory.perm.support\nimport order.monovary\nimport tactic.abel\n\n/-!\n# Rearrangement inequality\n\nThis file proves the rearrangement inequality.\n\nThe rearrangement inequality tells you that for two functions `f g : \u03b9 \u2192 \u03b1`, the sum\n`\u2211 i, f i * g (\u03c3 i)` is maximized over all `\u03c3 : perm \u03b9` when `g \u2218 \u03c3` monovaries with `f` and\nminimized when `g \u2218 \u03c3` antivaries with `f`.\n\n## Implementation notes\n\nIn fact, we don't need much compatibility between the addition and multiplication of `\u03b1`, so we can\nactually decouple them by replacing multiplication with scalar multiplication and making `f` and `g`\nland in different types.\nAs a bonus, this makes the dual statement trivial. The multiplication versions are provided for\nconvenience.\n\nThe case for `monotone`/`antitone` pairs of functions over a `linear_order` is not deduced in this\nfile because it is easily deducible from the `monovary` API.\n-/\n\nopen equiv equiv.perm finset order_dual\nopen_locale big_operators\n\nvariables {\u03b9 \u03b1 \u03b2 : Type*}\n\n/-! ### Scalar multiplication versions -/\n\nsection smul\nvariables [linear_ordered_ring \u03b1] [linear_ordered_add_comm_group \u03b2] [module \u03b1 \u03b2]\n  [ordered_smul \u03b1 \u03b2] {s : finset \u03b9} {\u03c3 : perm \u03b9} {f : \u03b9 \u2192 \u03b1} {g : \u03b9 \u2192 \u03b2}\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when\n`f` and `g` vary together. Stated by permuting the entries of `g`.  -/\nlemma monovary_on.sum_smul_comp_perm_le_sum_smul (hfg : monovary_on f g s)\n  (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f i \u2022 g (\u03c3 i) \u2264 \u2211 i in s, f i \u2022 g i :=\nbegin\n  classical,\n  revert h\u03c3 \u03c3 hfg,\n  apply finset.induction_on_max_value (\u03bb i, to_lex (g i, f i)) s,\n  { simp only [le_rfl, finset.sum_empty, implies_true_iff] },\n  intros a s has hamax hind \u03c3 hfg h\u03c3,\n  set \u03c4 : perm \u03b9 := \u03c3.trans (swap a (\u03c3 a)) with h\u03c4,\n  have h\u03c4s : {x | \u03c4 x \u2260 x} \u2286 s,\n  { intros x hx,\n    simp only [ne.def, set.mem_set_of_eq, equiv.coe_trans, equiv.swap_comp_apply] at hx,\n    split_ifs at hx with h\u2081 h\u2082 h\u2083,\n    { obtain rfl | hax := eq_or_ne x a,\n      { contradiction },\n      { exact mem_of_mem_insert_of_ne (h\u03c3 $ \u03bb h, hax $ h.symm.trans h\u2081) hax } },\n    { exact (hx $ \u03c3.injective h\u2082.symm).elim },\n    { exact mem_of_mem_insert_of_ne (h\u03c3 hx) (ne_of_apply_ne _ h\u2082) } },\n  specialize hind (hfg.subset $ subset_insert _ _) h\u03c4s,\n  simp_rw sum_insert has,\n  refine le_trans _ (add_le_add_left hind _),\n  obtain h\u03c3a | h\u03c3a := eq_or_ne a (\u03c3 a),\n  { rw [\u2190h\u03c3a, swap_self, trans_refl] at h\u03c4,\n    rw [\u2190h\u03c3a, h\u03c4] },\n  have h1s : \u03c3\u207b\u00b9 a \u2208 s,\n  { rw [ne.def, \u2190inv_eq_iff_eq] at h\u03c3a,\n    refine mem_of_mem_insert_of_ne (h\u03c3 $ \u03bb h, h\u03c3a _) h\u03c3a,\n    rwa [apply_inv_self, eq_comm] at h },\n  simp only [\u2190 s.sum_erase_add _ h1s, add_comm],\n  rw [\u2190 add_assoc, \u2190 add_assoc],\n  refine add_le_add _ (sum_congr rfl $ \u03bb x hx, _).le,\n  { simp only [h\u03c4, swap_apply_left, function.comp_app, equiv.coe_trans, apply_inv_self],\n    suffices : 0 \u2264 (f a - f (\u03c3\u207b\u00b9 a)) \u2022 (g a - g (\u03c3 a)),\n    { rw \u2190 sub_nonneg,\n      convert this,\n      simp only [smul_sub, sub_smul],\n      abel },\n    refine smul_nonneg (sub_nonneg_of_le _) (sub_nonneg_of_le _),\n    { specialize hamax (\u03c3\u207b\u00b9 a) h1s,\n      rw prod.lex.le_iff at hamax,\n      cases hamax,\n      { exact hfg (mem_insert_of_mem h1s) (mem_insert_self _ _) hamax },\n      { exact hamax.2 } },\n    { specialize hamax (\u03c3 a) (mem_of_mem_insert_of_ne (h\u03c3 $ \u03c3.injective.ne h\u03c3a.symm) h\u03c3a.symm),\n      rw prod.lex.le_iff at hamax,\n      cases hamax,\n      { exact hamax.le },\n      { exact hamax.1.le } } },\n  { congr' 2,\n    rw [eq_comm, h\u03c4],\n    rw [mem_erase, ne.def, eq_inv_iff_eq] at hx,\n    refine swap_apply_of_ne_of_ne hx.1 (\u03c3.injective.ne _),\n    rintro rfl,\n    exact has hx.2 }\nend\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when\n`f` and `g` vary together. Stated by permuting the entries of `f`. -/\nlemma monovary_on.sum_comp_perm_smul_le_sum_smul (hfg : monovary_on f g s)\n  (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f (\u03c3 i) \u2022 g i \u2264 \u2211 i in s, f i \u2022 g i :=\nbegin\n  convert hfg.sum_smul_comp_perm_le_sum_smul\n    (show {x | \u03c3\u207b\u00b9 x \u2260 x} \u2286 s, by simp only [set_support_inv_eq, h\u03c3]) using 1,\n  exact \u03c3.sum_comp' s (\u03bb i j, f i \u2022 g j) h\u03c3,\nend\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when\n`f` and `g` antivary together. Stated by permuting the entries of `g`.-/\nlemma antivary_on.sum_smul_le_sum_smul_comp_perm (hfg : antivary_on f g s)\n  (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f i \u2022 g i \u2264 \u2211 i in s, f i \u2022 g (\u03c3 i) :=\nhfg.dual_right.sum_smul_comp_perm_le_sum_smul h\u03c3\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when\n`f` and `g` antivary together. Stated by permuting the entries of `f`. -/\nlemma antivary_on.sum_smul_le_sum_comp_perm_smul (hfg : antivary_on f g s)\n  (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f i \u2022 g i \u2264 \u2211 i in s, f (\u03c3 i) \u2022 g i :=\nhfg.dual_right.sum_comp_perm_smul_le_sum_smul h\u03c3\n\nvariables [fintype \u03b9]\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when\n`f` and `g` vary together. Stated by permuting the entries of `g`.  -/\nlemma monovary.sum_smul_comp_perm_le_sum_smul (hfg : monovary f g) :\n  \u2211 i, f i \u2022 g (\u03c3 i) \u2264 \u2211 i, f i \u2022 g i :=\n(hfg.monovary_on _).sum_smul_comp_perm_le_sum_smul $ \u03bb i _, mem_univ _\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when\n`f` and `g` vary together. Stated by permuting the entries of `f`. -/\nlemma monovary.sum_comp_perm_smul_le_sum_smul (hfg : monovary f g) :\n  \u2211 i, f (\u03c3 i) \u2022 g i \u2264 \u2211 i, f i \u2022 g i :=\n(hfg.monovary_on _).sum_comp_perm_smul_le_sum_smul $ \u03bb i _, mem_univ _\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when\n`f` and `g` antivary together. Stated by permuting the entries of `g`.-/\nlemma antivary.sum_smul_le_sum_smul_comp_perm (hfg : antivary f g) :\n  \u2211 i, f i \u2022 g i \u2264 \u2211 i, f i \u2022 g (\u03c3 i) :=\n(hfg.antivary_on _).sum_smul_le_sum_smul_comp_perm $ \u03bb i _, mem_univ _\n\n/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when\n`f` and `g` antivary together. Stated by permuting the entries of `f`. -/\nlemma antivary.sum_smul_le_sum_comp_perm_smul (hfg : antivary f g) :\n  \u2211 i, f i \u2022 g i \u2264 \u2211 i, f (\u03c3 i) \u2022 g i :=\n(hfg.antivary_on _).sum_smul_le_sum_comp_perm_smul $ \u03bb i _, mem_univ _\n\nend smul\n\n/-!\n### Multiplication versions\n\nSpecial cases of the above when scalar multiplication is actually multiplication.\n-/\n\nsection mul\nvariables [linear_ordered_ring \u03b1] {s : finset \u03b9} {\u03c3 : perm \u03b9} {f g : \u03b9 \u2192 \u03b1}\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and\n`g` vary together. Stated by permuting the entries of `g`.  -/\nlemma monovary_on.sum_mul_comp_perm_le_sum_mul (hfg : monovary_on f g s) (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f i * g (\u03c3 i) \u2264 \u2211 i in s, f i * g i :=\nhfg.sum_smul_comp_perm_le_sum_smul h\u03c3\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and\n`g` vary together. Stated by permuting the entries of `f`. -/\nlemma monovary_on.sum_comp_perm_mul_le_sum_mul (hfg : monovary_on f g s) (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f (\u03c3 i) * g i \u2264 \u2211 i in s, f i * g i :=\nhfg.sum_comp_perm_smul_le_sum_smul h\u03c3\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and\n`g` antivary together. Stated by permuting the entries of `g`.-/\nlemma antivary_on.sum_mul_le_sum_mul_comp_perm (hfg : antivary_on f g s) (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f i * g i \u2264 \u2211 i in s, f i * g (\u03c3 i) :=\nhfg.sum_smul_le_sum_smul_comp_perm h\u03c3\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and\n`g` antivary together. Stated by permuting the entries of `f`. -/\nlemma antivary_on.sum_mul_le_sum_comp_perm_mul (hfg : antivary_on f g s) (h\u03c3 : {x | \u03c3 x \u2260 x} \u2286 s) :\n  \u2211 i in s, f i * g i \u2264 \u2211 i in s, f (\u03c3 i) * g i :=\nhfg.sum_smul_le_sum_comp_perm_smul h\u03c3\n\nvariables [fintype \u03b9]\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and\n`g` vary together. Stated by permuting the entries of `g`.  -/\nlemma monovary.sum_mul_comp_perm_le_sum_mul (hfg : monovary f g) :\n  \u2211 i, f i * g (\u03c3 i) \u2264 \u2211 i, f i * g i :=\nhfg.sum_smul_comp_perm_le_sum_smul\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and\n`g` vary together. Stated by permuting the entries of `f`. -/\nlemma monovary.sum_comp_perm_mul_le_sum_mul (hfg : monovary f g) :\n  \u2211 i, f (\u03c3 i) * g i \u2264 \u2211 i, f i * g i :=\nhfg.sum_comp_perm_smul_le_sum_smul\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and\n`g` antivary together. Stated by permuting the entries of `g`.-/\nlemma antivary.sum_mul_le_sum_mul_comp_perm (hfg : antivary f g) :\n  \u2211 i, f i * g i \u2264 \u2211 i, f i * g (\u03c3 i) :=\nhfg.sum_smul_le_sum_smul_comp_perm\n\n/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and\n`g` antivary together. Stated by permuting the entries of `f`. -/\nlemma antivary.sum_mul_le_sum_comp_perm_mul (hfg : antivary f g) :\n  \u2211 i, f i * g i \u2264 \u2211 i, f (\u03c3 i) * g i :=\nhfg.sum_smul_le_sum_comp_perm_smul\n\nend mul\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/order/rearrangement.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940974, "lm_q2_score": 0.8198933337131077, "lm_q1q2_score": 0.7194373764253797}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot, Casper Putz, Anne Baanen\n-/\nimport linear_algebra.matrix.to_lin\n\n/-!\n# Diagonal matrices\n\nThis file contains some results on the linear map corresponding to a\ndiagonal matrix (`range`, `ker` and `rank`).\n\n## Tags\n\nmatrix, diagonal, linear_map\n-/\n\nnoncomputable theory\n\nopen linear_map matrix set submodule\nopen_locale big_operators\nopen_locale matrix\n\nuniverses u v w\n\nnamespace matrix\n\nsection comm_ring\n\nvariables {n : Type*} [fintype n] [decidable_eq n] {R : Type v} [comm_ring R]\n\nlemma proj_diagonal (i : n) (w : n \u2192 R) :\n  (proj i).comp (to_lin' (diagonal w)) = (w i) \u2022 proj i :=\nlinear_map.ext $ \u03bb j, mul_vec_diagonal _ _ _\n\nlemma diagonal_comp_std_basis (w : n \u2192 R) (i : n) :\n  (diagonal w).to_lin'.comp (linear_map.std_basis R (\u03bb_:n, R) i) =\n  (w i) \u2022 linear_map.std_basis R (\u03bb_:n, R) i :=\nlinear_map.ext $ \u03bb x, (diagonal_mul_vec_single w _ _).trans (pi.single_smul' i (w i) _)\n\nlemma diagonal_to_lin' (w : n \u2192 R) :\n  (diagonal w).to_lin' = linear_map.pi (\u03bbi, w i \u2022 linear_map.proj i) :=\nlinear_map.ext $ \u03bb v, funext $ \u03bb i, mul_vec_diagonal _ _ _\n\nend comm_ring\n\nsection field\n\nvariables {m n : Type*} [fintype m] [fintype n]\nvariables {K : Type u} [field K] -- maybe try to relax the universe constraint\n\nlemma ker_diagonal_to_lin' [decidable_eq m] (w : m \u2192 K) :\n  ker (diagonal w).to_lin' = (\u2a06i\u2208{i | w i = 0 }, range (linear_map.std_basis K (\u03bbi, K) i)) :=\nbegin\n  rw [\u2190 comap_bot, \u2190 infi_ker_proj, comap_infi],\n  have := \u03bb i : m, ker_comp (to_lin' (diagonal w)) (proj i),\n  simp only [comap_infi, \u2190 this, proj_diagonal, ker_smul'],\n  have : univ \u2286 {i : m | w i = 0} \u222a {i : m | w i = 0}\u1d9c, { rw set.union_compl_self },\n  exact (supr_range_std_basis_eq_infi_ker_proj K (\u03bbi:m, K)\n    disjoint_compl_right this (finite.of_fintype _)).symm\nend\n\nlemma range_diagonal [decidable_eq m] (w : m \u2192 K) :\n  (diagonal w).to_lin'.range = (\u2a06 i \u2208 {i | w i \u2260 0}, (linear_map.std_basis K (\u03bbi, K) i).range) :=\nbegin\n  dsimp only [mem_set_of_eq],\n  rw [\u2190 map_top, \u2190 supr_range_std_basis, map_supr],\n  congr, funext i,\n  rw [\u2190 linear_map.range_comp, diagonal_comp_std_basis, \u2190 range_smul']\nend\n\nlemma rank_diagonal [decidable_eq m] [decidable_eq K] (w : m \u2192 K) :\n  rank (diagonal w).to_lin' = fintype.card { i // w i \u2260 0 } :=\nbegin\n  have hu : univ \u2286 {i : m | w i = 0}\u1d9c \u222a {i : m | w i = 0}, { rw set.compl_union_self },\n  have hd : disjoint {i : m | w i \u2260 0} {i : m | w i = 0} := disjoint_compl_left,\n  have B\u2081 := supr_range_std_basis_eq_infi_ker_proj K (\u03bbi:m, K) hd hu (finite.of_fintype _),\n  have B\u2082 := @infi_ker_proj_equiv K _ _ (\u03bbi:m, K) _ _ _ _ (by simp; apply_instance) hd hu,\n  rw [rank, range_diagonal, B\u2081, \u2190@dim_fun' K],\n  apply linear_equiv.dim_eq,\n  apply B\u2082,\nend\n\nend field\n\nend matrix\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/matrix/diagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7194373743368291}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport data.finsupp.basic\n\n/-!\n# The pointwise product on `finsupp`.\n\nTODO per issue #1864:\nWe intend to remove the convolution product on finsupp, and define\nit only on a type synonym `add_monoid_algebra`. After we've done this,\nit would be good to make this the default product on `finsupp`.\n-/\n\nnoncomputable theory\nopen_locale classical\n\nopen finset\n\nuniverses u\u2081 u\u2082 u\u2083 u\u2084 u\u2085\nvariables {\u03b1 : Type u\u2081} {\u03b2 : Type u\u2082} {\u03b3 : Type u\u2083} {\u03b4 : Type u\u2084} {\u03b9 : Type u\u2085}\n\nnamespace finsupp\n\n/-! ### Declarations about the pointwise product on `finsupp`s -/\n\nsection\nvariables [mul_zero_class \u03b2]\n\n/-- The product of `f g : \u03b1 \u2192\u2080 \u03b2` is the finitely supported function\n  whose value at `a` is `f a * g a`. -/\ninstance : has_mul (\u03b1 \u2192\u2080 \u03b2) := \u27e8zip_with (*) (mul_zero 0)\u27e9\n\n@[simp] lemma mul_apply {g\u2081 g\u2082 : \u03b1 \u2192\u2080 \u03b2} {a : \u03b1} : (g\u2081 * g\u2082) a = g\u2081 a * g\u2082 a :=\nrfl\n\nlemma support_mul {g\u2081 g\u2082 : \u03b1 \u2192\u2080 \u03b2} : (g\u2081 * g\u2082).support \u2286 g\u2081.support \u2229 g\u2082.support :=\nbegin\n  intros a h,\n  simp only [mul_apply, mem_support_iff] at h,\n  simp only [mem_support_iff, mem_inter, ne.def],\n  rw \u2190not_or_distrib,\n  intro w,\n  apply h,\n  cases w; { rw w, simp },\nend\n\ninstance : mul_zero_class (\u03b1 \u2192\u2080 \u03b2) :=\n{ zero      := 0,\n  mul       := (*),\n  mul_zero  := \u03bb f, by { ext, simp only [mul_apply, zero_apply, mul_zero], },\n  zero_mul  := \u03bb f, by { ext, simp only [mul_apply, zero_apply, zero_mul], }, }\n\nend\n\ninstance [semigroup_with_zero \u03b2] : semigroup_with_zero (\u03b1 \u2192\u2080 \u03b2) :=\n{ mul       := (*),\n  mul_assoc := \u03bb f g h, by { ext, simp only [mul_apply, mul_assoc], },\n  ..(infer_instance : mul_zero_class (\u03b1 \u2192\u2080 \u03b2)) }\n\ninstance [semiring \u03b2] : distrib (\u03b1 \u2192\u2080 \u03b2) :=\n{ left_distrib := \u03bb f g h, by { ext, simp only [mul_apply, add_apply, left_distrib] {proj := ff} },\n  right_distrib := \u03bb f g h,\n    by { ext, simp only [mul_apply, add_apply, right_distrib] {proj := ff} },\n  ..(infer_instance : semigroup (\u03b1 \u2192\u2080 \u03b2)),\n  ..(infer_instance : add_comm_monoid (\u03b1 \u2192\u2080 \u03b2)) }\n\n-- If `non_unital_semiring` existed in the algebraic hierarchy, we could produce one here.\n\nend finsupp\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/finsupp/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7194373664558033}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport data.polynomial.degree.trailing_degree\nimport data.polynomial.erase_lead\nimport data.polynomial.eval\n\n/-!\n# Reverse of a univariate polynomial\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe main definition is `reverse`.  Applying `reverse` to a polynomial `f : R[X]` produces\nthe polynomial with a reversed list of coefficients, equivalent to `X^f.nat_degree * f(1/X)`.\n\nThe main result is that `reverse (f * g) = reverse f * reverse g`, provided the leading\ncoefficients of `f` and `g` do not multiply to zero.\n-/\n\nnamespace polynomial\n\nopen polynomial finsupp finset\nopen_locale classical polynomial\n\nsection semiring\n\nvariables {R : Type*} [semiring R] {f : R[X]}\n\n/-- If `i \u2264 N`, then `rev_at_fun N i` returns `N - i`, otherwise it returns `i`.\nThis is the map used by the embedding `rev_at`.\n-/\ndef rev_at_fun (N i : \u2115) : \u2115 := ite (i \u2264 N) (N-i) i\n\nlemma rev_at_fun_invol {N i : \u2115} : rev_at_fun N (rev_at_fun N i) = i :=\nbegin\n  unfold rev_at_fun,\n  split_ifs with h j,\n  { exact tsub_tsub_cancel_of_le h, },\n  { exfalso,\n    apply j,\n    exact nat.sub_le N i, },\n  { refl, },\nend\n\nlemma rev_at_fun_inj {N : \u2115} : function.injective (rev_at_fun N) :=\nbegin\n  intros a b hab,\n  rw [\u2190 @rev_at_fun_invol N a, hab, rev_at_fun_invol],\nend\n\n/-- If `i \u2264 N`, then `rev_at N i` returns `N - i`, otherwise it returns `i`.\nEssentially, this embedding is only used for `i \u2264 N`.\nThe advantage of `rev_at N i` over `N - i` is that `rev_at` is an involution.\n-/\ndef rev_at (N : \u2115) : function.embedding \u2115 \u2115 :=\n{ to_fun := \u03bb i , (ite (i \u2264 N) (N-i) i),\n  inj' := rev_at_fun_inj }\n\n/-- We prefer to use the bundled `rev_at` over unbundled `rev_at_fun`. -/\n@[simp] lemma rev_at_fun_eq (N i : \u2115) : rev_at_fun N i = rev_at N i := rfl\n\n@[simp] lemma rev_at_invol {N i : \u2115} : (rev_at N) (rev_at N i) = i :=\nrev_at_fun_invol\n\n@[simp] lemma rev_at_le {N i : \u2115} (H : i \u2264 N) : rev_at N i = N - i :=\nif_pos H\n\nlemma rev_at_add {N O n o : \u2115} (hn : n \u2264 N) (ho : o \u2264 O) :\n  rev_at (N + O) (n + o) = rev_at N n + rev_at O o :=\nbegin\n  rcases nat.le.dest hn with \u27e8n', rfl\u27e9,\n  rcases nat.le.dest ho with \u27e8o', rfl\u27e9,\n  repeat { rw rev_at_le (le_add_right rfl.le) },\n  rw [add_assoc, add_left_comm n' o, \u2190 add_assoc, rev_at_le (le_add_right rfl.le)],\n  repeat {rw add_tsub_cancel_left},\nend\n\n@[simp] lemma rev_at_zero (N : \u2115) : rev_at N 0 = N :=\nby simp [rev_at]\n\n/-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (rev_at N i)`.\nIn other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`.\n\nIn practice, `reflect` is only used when `N` is at least as large as the degree of `f`.\n\nEventually, it will be used with `N` exactly equal to the degree of `f`.  -/\nnoncomputable def reflect (N : \u2115) : R[X] \u2192 R[X]\n| \u27e8f\u27e9 := \u27e8finsupp.emb_domain (rev_at N) f\u27e9\n\nlemma reflect_support (N : \u2115) (f : R[X]) :\n  (reflect N f).support = finset.image (rev_at N) f.support :=\nbegin\n  rcases f,\n  ext1,\n  simp only [reflect, support_of_finsupp, support_emb_domain, finset.mem_map, finset.mem_image],\nend\n\n@[simp] lemma coeff_reflect (N : \u2115) (f : R[X]) (i : \u2115) :\n  coeff (reflect N f) i = f.coeff (rev_at N i) :=\nbegin\n  rcases f,\n  simp only [reflect, coeff],\n  calc finsupp.emb_domain (rev_at N) f i\n      = finsupp.emb_domain (rev_at N) f (rev_at N (rev_at N i)) : by rw rev_at_invol\n  ... = f (rev_at N i) : finsupp.emb_domain_apply _ _ _\nend\n\n@[simp] lemma reflect_zero {N : \u2115} : reflect N (0 : R[X]) = 0 := rfl\n\n@[simp] lemma reflect_eq_zero_iff {N : \u2115} {f : R[X]} :\n  reflect N (f : R[X]) = 0 \u2194 f = 0 :=\nby { rcases f, simp [reflect] }\n\n@[simp] lemma reflect_add (f g : R[X]) (N : \u2115) :\n  reflect N (f + g) = reflect N f + reflect N g :=\nby { ext, simp only [coeff_add, coeff_reflect], }\n\n@[simp] lemma reflect_C_mul (f : R[X]) (r : R) (N : \u2115) :\n  reflect N (C r * f) = C r * (reflect N f) :=\nby { ext, simp only [coeff_reflect, coeff_C_mul], }\n\n@[simp] lemma reflect_C_mul_X_pow (N n : \u2115) {c : R} :\n  reflect N (C c * X ^ n) = C c * X ^ (rev_at N n) :=\nbegin\n  ext,\n  rw [reflect_C_mul, coeff_C_mul, coeff_C_mul, coeff_X_pow, coeff_reflect],\n  split_ifs with h j,\n  { rw [h, rev_at_invol, coeff_X_pow_self], },\n  { rw [not_mem_support_iff.mp],\n    intro a,\n    rw [\u2190 one_mul (X ^ n), \u2190 C_1] at a,\n    apply h,\n    rw [\u2190 (mem_support_C_mul_X_pow a), rev_at_invol], },\nend\n\n@[simp] lemma reflect_C (r : R) (N : \u2115) : reflect N (C r) = C r * X ^ N :=\nby conv_lhs { rw [\u2190 mul_one (C r), \u2190 pow_zero X, reflect_C_mul_X_pow, rev_at_zero] }\n\n@[simp] lemma reflect_monomial (N n : \u2115) : reflect N ((X : R[X]) ^ n) = X ^ (rev_at N n) :=\nby rw [\u2190 one_mul (X ^ n), \u2190 one_mul (X ^ (rev_at N n)), \u2190 C_1, reflect_C_mul_X_pow]\n\nlemma reflect_mul_induction (cf cg : \u2115) :\n  \u2200 N O : \u2115, \u2200 f g : R[X],\n  f.support.card \u2264 cf.succ \u2192 g.support.card \u2264 cg.succ \u2192 f.nat_degree \u2264 N \u2192 g.nat_degree \u2264 O \u2192\n  (reflect (N + O) (f * g)) = (reflect N f) * (reflect O g) :=\nbegin\n  induction cf with cf hcf,\n  --first induction (left): base case\n  { induction cg with cg hcg,\n    -- second induction (right): base case\n    { intros N O f g Cf Cg Nf Og,\n      rw [\u2190 C_mul_X_pow_eq_self Cf, \u2190 C_mul_X_pow_eq_self Cg],\n      simp_rw [mul_assoc, X_pow_mul, mul_assoc, \u2190 pow_add (X : R[X]), reflect_C_mul,\n        reflect_monomial, add_comm, rev_at_add Nf Og, mul_assoc, X_pow_mul, mul_assoc,\n        \u2190 pow_add (X : R[X]), add_comm], },\n    -- second induction (right): induction step\n    { intros N O f g Cf Cg Nf Og,\n      by_cases g0 : g = 0,\n      { rw [g0, reflect_zero, mul_zero, mul_zero, reflect_zero], },\n\n      rw [\u2190 erase_lead_add_C_mul_X_pow g, mul_add, reflect_add, reflect_add, mul_add, hcg, hcg];\n        try { assumption },\n      { exact le_add_left card_support_C_mul_X_pow_le_one },\n      { exact (le_trans (nat_degree_C_mul_X_pow_le g.leading_coeff g.nat_degree) Og) },\n      { exact nat.lt_succ_iff.mp (gt_of_ge_of_gt Cg (erase_lead_support_card_lt g0)) },\n      { exact le_trans erase_lead_nat_degree_le_aux Og } } },\n  --first induction (left): induction step\n  { intros N O f g Cf Cg Nf Og,\n    by_cases f0 : f = 0,\n    { rw [f0, reflect_zero, zero_mul, zero_mul, reflect_zero], },\n\n    rw [\u2190 erase_lead_add_C_mul_X_pow f, add_mul, reflect_add, reflect_add, add_mul, hcf, hcf];\n       try { assumption },\n    { exact le_add_left card_support_C_mul_X_pow_le_one },\n    { exact (le_trans (nat_degree_C_mul_X_pow_le f.leading_coeff f.nat_degree) Nf) },\n    { exact nat.lt_succ_iff.mp (gt_of_ge_of_gt Cf (erase_lead_support_card_lt f0)) },\n    { exact (le_trans erase_lead_nat_degree_le_aux Nf) } }\nend\n\n@[simp] theorem reflect_mul\n  (f g : R[X]) {F G : \u2115} (Ff : f.nat_degree \u2264 F) (Gg : g.nat_degree \u2264 G) :\n  reflect (F + G) (f * g) = reflect F f * reflect G g :=\nreflect_mul_induction _ _ F G f g f.support.card.le_succ g.support.card.le_succ Ff Gg\n\nsection eval\u2082\n\nvariables {S : Type*} [comm_semiring S]\n\nlemma eval\u2082_reflect_mul_pow (i : R \u2192+* S) (x : S) [invertible x] (N : \u2115) (f : R[X])\n  (hf : f.nat_degree \u2264 N) : eval\u2082 i (\u215fx) (reflect N f) * x ^ N = eval\u2082 i x f :=\nbegin\n  refine induction_with_nat_degree_le (\u03bb f, eval\u2082 i (\u215fx) (reflect N f) * x ^ N = eval\u2082 i x f)\n    _ _ _ _ f hf,\n  { simp },\n  { intros n r hr0 hnN,\n    simp only [rev_at_le hnN, reflect_C_mul_X_pow, eval\u2082_X_pow, eval\u2082_C, eval\u2082_mul],\n    conv in (x ^ N) { rw [\u2190 nat.sub_add_cancel hnN] },\n    rw [pow_add, \u2190 mul_assoc, mul_assoc (i r), \u2190 mul_pow, inv_of_mul_self, one_pow, mul_one] },\n  { intros,\n    simp [*, add_mul] }\nend\n\nlemma eval\u2082_reflect_eq_zero_iff (i : R \u2192+* S) (x : S) [invertible x] (N : \u2115) (f : R[X])\n  (hf : f.nat_degree \u2264 N) : eval\u2082 i (\u215fx) (reflect N f) = 0 \u2194 eval\u2082 i x f = 0 :=\nbegin\n  conv_rhs { rw [\u2190 eval\u2082_reflect_mul_pow i x N f hf] },\n  split,\n  { intro h, rw [h, zero_mul] },\n  { intro h, rw [\u2190 mul_one (eval\u2082 i (\u215fx) _), \u2190 one_pow N, \u2190 mul_inv_of_self x,\n      mul_pow, \u2190 mul_assoc, h, zero_mul] }\nend\n\nend eval\u2082\n\n/-- The reverse of a polynomial f is the polynomial obtained by \"reading f backwards\".\nEven though this is not the actual definition, reverse f = f (1/X) * X ^ f.nat_degree. -/\nnoncomputable def reverse (f : R[X]) : R[X] := reflect f.nat_degree f\n\nlemma coeff_reverse (f : R[X]) (n : \u2115) :\n  f.reverse.coeff n = f.coeff (rev_at f.nat_degree n) :=\nby rw [reverse, coeff_reflect]\n\n@[simp] lemma coeff_zero_reverse (f : R[X]) : coeff (reverse f) 0 = leading_coeff f :=\nby rw [coeff_reverse, rev_at_le (zero_le f.nat_degree), tsub_zero, leading_coeff]\n\n@[simp] lemma reverse_zero : reverse (0 : R[X]) = 0 := rfl\n\n@[simp] lemma reverse_eq_zero : f.reverse = 0 \u2194 f = 0 :=\nby simp [reverse]\n\nlemma reverse_nat_degree_le (f : R[X]) : f.reverse.nat_degree \u2264 f.nat_degree :=\nbegin\n  rw [nat_degree_le_iff_degree_le, degree_le_iff_coeff_zero],\n  intros n hn,\n  rw with_bot.coe_lt_coe at hn,\n  rw [coeff_reverse, rev_at, function.embedding.coe_fn_mk,\n      if_neg (not_le_of_gt hn), coeff_eq_zero_of_nat_degree_lt hn],\nend\n\nlemma nat_degree_eq_reverse_nat_degree_add_nat_trailing_degree (f : R[X]) :\n  f.nat_degree = f.reverse.nat_degree + f.nat_trailing_degree :=\nbegin\n  by_cases hf : f = 0,\n  { rw [hf, reverse_zero, nat_degree_zero, nat_trailing_degree_zero] },\n  apply le_antisymm,\n  { refine tsub_le_iff_right.mp _,\n    apply le_nat_degree_of_ne_zero,\n    rw [reverse, coeff_reflect, \u2190rev_at_le f.nat_trailing_degree_le_nat_degree, rev_at_invol],\n    exact trailing_coeff_nonzero_iff_nonzero.mpr hf },\n  { rw \u2190 le_tsub_iff_left f.reverse_nat_degree_le,\n    apply nat_trailing_degree_le_of_ne_zero,\n    have key := mt leading_coeff_eq_zero.mp (mt reverse_eq_zero.mp hf),\n    rwa [leading_coeff, coeff_reverse, rev_at_le f.reverse_nat_degree_le] at key },\nend\n\nlemma reverse_nat_degree (f : R[X]) :\n  f.reverse.nat_degree = f.nat_degree - f.nat_trailing_degree :=\nby rw [f.nat_degree_eq_reverse_nat_degree_add_nat_trailing_degree, add_tsub_cancel_right]\n\nlemma reverse_leading_coeff (f : R[X]) : f.reverse.leading_coeff = f.trailing_coeff :=\nby rw [leading_coeff, reverse_nat_degree, \u2190rev_at_le f.nat_trailing_degree_le_nat_degree,\n  coeff_reverse, rev_at_invol, trailing_coeff]\n\nlemma reverse_nat_trailing_degree  (f : R[X]) : f.reverse.nat_trailing_degree = 0 :=\nbegin\n  by_cases hf : f = 0,\n  { rw [hf, reverse_zero, nat_trailing_degree_zero] },\n  { rw \u2190 le_zero_iff,\n    apply nat_trailing_degree_le_of_ne_zero,\n    rw [coeff_zero_reverse],\n    exact mt leading_coeff_eq_zero.mp hf },\nend\n\n\n\ntheorem reverse_mul {f g : R[X]} (fg : f.leading_coeff * g.leading_coeff \u2260 0) :\n reverse (f * g) = reverse f * reverse g :=\nbegin\n  unfold reverse,\n  rw [nat_degree_mul' fg, reflect_mul  f g rfl.le rfl.le],\nend\n\n@[simp] lemma reverse_mul_of_domain {R : Type*} [ring R] [no_zero_divisors R] (f g : R[X]) :\n  reverse (f * g) = reverse f * reverse g :=\nbegin\n  by_cases f0 : f=0,\n  { simp only [f0, zero_mul, reverse_zero], },\n  by_cases g0 : g=0,\n  { rw [g0, mul_zero, reverse_zero, mul_zero], },\n  simp [reverse_mul, *],\nend\n\nlemma trailing_coeff_mul {R : Type*} [ring R] [no_zero_divisors R] (p q : R[X]) :\n  (p * q).trailing_coeff = p.trailing_coeff * q.trailing_coeff :=\nby rw [\u2190reverse_leading_coeff, reverse_mul_of_domain, leading_coeff_mul,\n  reverse_leading_coeff, reverse_leading_coeff]\n\n@[simp] lemma coeff_one_reverse (f : R[X]) : coeff (reverse f) 1 = next_coeff f :=\nbegin\n  rw [coeff_reverse, next_coeff],\n  split_ifs with hf,\n  { have : coeff f 1 = 0 := coeff_eq_zero_of_nat_degree_lt (by simp only [hf, zero_lt_one]),\n    simp [*, rev_at] },\n  { rw rev_at_le,\n    exact nat.succ_le_iff.2 (pos_iff_ne_zero.2 hf) }\nend\n\nsection eval\u2082\nvariables {S : Type*} [comm_semiring S]\n\nlemma eval\u2082_reverse_mul_pow (i : R \u2192+* S) (x : S) [invertible x] (f : R[X]) :\n  eval\u2082 i (\u215fx) (reverse f) * x ^ f.nat_degree = eval\u2082 i x f :=\neval\u2082_reflect_mul_pow i _ _ f le_rfl\n\n@[simp] lemma eval\u2082_reverse_eq_zero_iff (i : R \u2192+* S) (x : S) [invertible x] (f : R[X]) :\n  eval\u2082 i (\u215fx) (reverse f) = 0 \u2194 eval\u2082 i x f = 0 :=\neval\u2082_reflect_eq_zero_iff i x _ _ le_rfl\n\nend eval\u2082\n\nend semiring\n\nsection ring\n\nvariables {R : Type*} [ring R]\n\n@[simp] lemma reflect_neg (f : R[X]) (N : \u2115) :\n  reflect N (- f) = - reflect N f :=\nby rw [neg_eq_neg_one_mul, \u2190C_1, \u2190C_neg, reflect_C_mul, C_neg, C_1, \u2190neg_eq_neg_one_mul]\n\n@[simp] lemma reflect_sub (f g : R[X]) (N : \u2115) :\n  reflect N (f - g) = reflect N f - reflect N g :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, reflect_add, reflect_neg]\n\n@[simp] lemma reverse_neg (f : R[X]) :\n  reverse (- f) = - reverse f :=\nby rw [reverse, reverse, reflect_neg, nat_degree_neg]\n\nend ring\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/reverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.719437365917346}}
{"text": "\nimport data.polynomial.basic\nimport data.polynomial.eval\nimport data.real.basic\n\n/-- definition of a negligible function -/\ndef negligible (f : \u2115 \u2192 \u211d) : Prop := \n  \u2200 p : polynomial \u2115, \u2203 N : \u2115, \u2200 n : \u2115, N < n \u2192\n    (f n : \u211d) \u2264 (1 : \u211d) / p.eval n\n\nlemma negligible_add {f g : \u2115 \u2192 \u211d} (hf : negligible f) (hg : negligible g) : negligible (f + g) :=\nbegin\n  unfold negligible at *,\n  intro p,\n  replace hf := hf (2 * p),\n  replace hg := hg (2 * p),\n  rcases hf with \u27e8Nf, hpf\u27e9,\n  rcases hg with \u27e8Ng, hpg\u27e9,\n  use (max Nf Ng),\n  intro n,\n  replace hpf := hpf n,\n  replace hpg := hpg n,\n  intro hNfg,\n  have hNf : Nf < n, -- library_search, -- fails\n    apply lt_of_le_of_lt _ hNfg,\n    exact le_max_left Nf Ng,\n  have hNg : Ng < n, -- library_search, -- fails\n    apply lt_of_le_of_lt _ hNfg,\n    exact le_max_right Nf Ng,\n  replace hpf := hpf hNf,\n  replace hpg := hpg hNg,    \n  simp only [pi.add_apply, polynomial.eval_mul, nat.cast_mul],\n  have hpfg := (add_le_add hpf hpg),\n  apply trans hpfg,\n  simp,\n  simp_rw mul_inv\u2080,\n  rw \u2190one_div,\n  linarith,\nend\n\nlemma negligible_of_le_negligible {f g : \u2115 \u2192 \u211d} (hfg : f \u2264 g) (hg : negligible g) : negligible f :=\nbegin\n  unfold negligible at *,\n  intro p,\n  replace hg := hg (p),\n  rcases hg with \u27e8Ng, hpg\u27e9,\n  use Ng,\n  intro n,\n  replace hpg := hpg n,\n  intro hNg,\n  replace hpg := hpg hNg,    \n  exact le_trans (hfg n) hpg,\nend", "meta": {"author": "BoltonBailey", "repo": "uc-lean", "sha": "45cfddb539d24a580461cb122ab77a826809dfda", "save_path": "github-repos/lean/BoltonBailey-uc-lean", "path": "github-repos/lean/BoltonBailey-uc-lean/uc-lean-45cfddb539d24a580461cb122ab77a826809dfda/src/negligible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.719428736775286}}
{"text": "import algebra.big_operators.basic\nimport data.real.basic\n\n/-\nCanadian Mathematical Olympiad 1998, Problem 3\n\nLet n be a natural number such that n \u2265 2. Show that\n\n  (1/(n + 1))(1 + 1/3 + ... + 1/(2n -1)) > (1/n)(1/2 + 1/4 + ... + 1/2n).\n-/\n\nopen_locale big_operators\n\n-- n' + 1 = n\n\ntheorem canada1998_q3 (n' : \u2115) (hn : 1 \u2264 n') :\n  ((1:\u211d)/(n'+2)) * \u2211 (i:\u2115) in finset.range n', (1/(2 * n' + 1)) >\n  ((1:\u211d)/(n'+1)) * \u2211 (i:\u2115) in finset.range n', (1/(2 * n' + 2)) :=\nbegin\n  cases n',\n  { sorry, },\n  clear hn,\n  sorry\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/canada1998_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.719428733177958}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.algebra.subalgebra\nimport topology.algebra.module\n\n/-!\n# Topological (sub)algebras\n\nA topological algebra over a topological semiring `R` is a topological ring with a compatible\ncontinuous scalar multiplication by elements of `R`. We reuse typeclass `has_continuous_smul` for\ntopological algebras.\n\n## Results\n\nThis is just a minimal stub for now!\n\nThe topological closure of a subalgebra is still a subalgebra,\nwhich as an algebra is a topological algebra.\n-/\n\nopen classical set topological_space algebra\nopen_locale classical\n\nuniverses u v w\n\nsection topological_algebra\nvariables (R : Type*) [topological_space R] [comm_semiring R]\nvariables (A : Type u) [topological_space A]\nvariables [semiring A]\n\nlemma continuous_algebra_map_iff_smul [algebra R A] [topological_semiring A] :\n  continuous (algebra_map R A) \u2194 continuous (\u03bb p : R \u00d7 A, p.1 \u2022 p.2) :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { simp only [algebra.smul_def], exact (h.comp continuous_fst).mul continuous_snd },\n  { rw algebra_map_eq_smul_one', exact h.comp (continuous_id.prod_mk continuous_const) }\nend\n\n@[continuity]\nlemma continuous_algebra_map [algebra R A] [topological_semiring A] [has_continuous_smul R A] :\n  continuous (algebra_map R A) :=\n(continuous_algebra_map_iff_smul R A).2 continuous_smul\n\nlemma has_continuous_smul_of_algebra_map [algebra R A] [topological_semiring A]\n  (h : continuous (algebra_map R A)) :\n  has_continuous_smul R A :=\n\u27e8(continuous_algebra_map_iff_smul R A).1 h\u27e9\n\nend topological_algebra\n\nsection topological_algebra\nvariables {R : Type*} [comm_semiring R]\nvariables {A : Type u} [topological_space A]\nvariables [semiring A]\nvariables [algebra R A] [topological_semiring A]\n\n/-- The closure of a subalgebra in a topological algebra as a subalgebra. -/\ndef subalgebra.topological_closure (s : subalgebra R A) : subalgebra R A :=\n{ carrier := closure (s : set A),\n  algebra_map_mem' := \u03bb r, s.to_subsemiring.subring_topological_closure (s.algebra_map_mem r),\n  .. s.to_subsemiring.topological_closure }\n\n@[simp] lemma subalgebra.topological_closure_coe (s : subalgebra R A) :\n  (s.topological_closure : set A) = closure (s : set A) :=\nrfl\n\ninstance subalgebra.topological_closure_topological_semiring (s : subalgebra R A) :\n  topological_semiring (s.topological_closure) :=\ns.to_subsemiring.topological_closure_topological_semiring\n\ninstance subalgebra.topological_closure_topological_algebra\n  [topological_space R] [has_continuous_smul R A] (s : subalgebra R A) :\n  has_continuous_smul R (s.topological_closure) :=\ns.to_submodule.topological_closure_has_continuous_smul\n\nlemma subalgebra.subalgebra_topological_closure (s : subalgebra R A) :\n  s \u2264 s.topological_closure :=\nsubset_closure\n\nlemma subalgebra.is_closed_topological_closure (s : subalgebra R A) :\n  is_closed (s.topological_closure : set A) :=\nby convert is_closed_closure\n\nlemma subalgebra.topological_closure_minimal\n  (s : subalgebra R A) {t : subalgebra R A} (h : s \u2264 t) (ht : is_closed (t : set A)) :\n  s.topological_closure \u2264 t :=\nclosure_minimal h ht\n\n/--\nThis is really a statement about topological algebra isomorphisms,\nbut we don't have those, so we use the clunky approach of talking about\nan algebra homomorphism, and a separate homeomorphism,\nalong with a witness that as functions they are the same.\n-/\nlemma subalgebra.topological_closure_comap'_homeomorph\n  (s : subalgebra R A)\n  {B : Type*} [topological_space B] [ring B] [topological_ring B] [algebra R B]\n  (f : B \u2192\u2090[R] A) (f' : B \u2243\u209c A) (w : (f : B \u2192 A) = f') :\n  s.topological_closure.comap' f = (s.comap' f).topological_closure :=\nbegin\n  apply set_like.ext',\n  simp only [subalgebra.topological_closure_coe],\n  simp only [subalgebra.coe_comap, subsemiring.coe_comap, alg_hom.coe_to_ring_hom],\n  rw [w],\n  exact f'.preimage_closure _,\nend\n\nend topological_algebra\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/topology/algebra/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.719417589831119}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.normed_space.banach\nimport analysis.normed_space.finite_dimension\n\n/-!\n# Complemented subspaces of normed vector spaces\n\nA submodule `p` of a topological module `E` over `R` is called *complemented* if there exists\na continuous linear projection `f : E \u2192\u2097[R] p`, `\u2200 x : p, f x = x`. We prove that for\na closed subspace of a normed space this condition is equivalent to existence of a closed\nsubspace `q` such that `p \u2293 q = \u22a5`, `p \u2294 q = \u22a4`. We also prove that a subspace of finite codimension\nis always a complemented subspace.\n\n## Tags\n\ncomplemented subspace, normed vector space\n-/\n\nvariables {\ud835\udd5c E F G : Type*} [nontrivially_normed_field \ud835\udd5c] [normed_add_comm_group E]\n  [normed_space \ud835\udd5c E] [normed_add_comm_group F] [normed_space \ud835\udd5c F] [normed_add_comm_group G]\n  [normed_space \ud835\udd5c G]\n\nnoncomputable theory\n\nopen linear_map (ker range)\n\nnamespace continuous_linear_map\n\nsection\n\nvariables [complete_space \ud835\udd5c]\n\nlemma ker_closed_complemented_of_finite_dimensional_range (f : E \u2192L[\ud835\udd5c] F)\n  [finite_dimensional \ud835\udd5c (range f)] :\n  (ker f).closed_complemented :=\nbegin\n  set f' : E \u2192L[\ud835\udd5c] (range f) := f.cod_restrict _ (f : E \u2192\u2097[\ud835\udd5c] F).mem_range_self,\n  rcases f'.exists_right_inverse_of_surjective (f : E \u2192\u2097[\ud835\udd5c] F).range_range_restrict with \u27e8g, hg\u27e9,\n  simpa only [ker_cod_restrict] using f'.closed_complemented_ker_of_right_inverse g (ext_iff.1 hg)\nend\n\nend\n\nvariables [complete_space E] [complete_space (F \u00d7 G)]\n\n/-- If `f : E \u2192L[R] F` and `g : E \u2192L[R] G` are two surjective linear maps and\ntheir kernels are complement of each other, then `x \u21a6 (f x, g x)` defines\na linear equivalence `E \u2243L[R] F \u00d7 G`. -/\ndef equiv_prod_of_surjective_of_is_compl (f : E \u2192L[\ud835\udd5c] F) (g : E \u2192L[\ud835\udd5c] G) (hf : range f = \u22a4)\n  (hg : range g = \u22a4) (hfg : is_compl (ker f) (ker g)) :\n  E \u2243L[\ud835\udd5c] F \u00d7 G :=\n((f : E \u2192\u2097[\ud835\udd5c] F).equiv_prod_of_surjective_of_is_compl \u2191g hf hg\n  hfg).to_continuous_linear_equiv_of_continuous (f.continuous.prod_mk g.continuous)\n\n@[simp] lemma coe_equiv_prod_of_surjective_of_is_compl {f : E \u2192L[\ud835\udd5c] F} {g : E \u2192L[\ud835\udd5c] G}\n  (hf : range f = \u22a4) (hg : range g = \u22a4) (hfg : is_compl (ker f) (ker g)) :\n  (equiv_prod_of_surjective_of_is_compl f g hf hg hfg : E \u2192\u2097[\ud835\udd5c] F \u00d7 G) = f.prod g :=\nrfl\n\n@[simp] lemma equiv_prod_of_surjective_of_is_compl_to_linear_equiv {f : E \u2192L[\ud835\udd5c] F} {g : E \u2192L[\ud835\udd5c] G}\n  (hf : range f = \u22a4) (hg : range g = \u22a4) (hfg : is_compl (ker f) (ker g)) :\n  (equiv_prod_of_surjective_of_is_compl f g hf hg hfg).to_linear_equiv =\n    linear_map.equiv_prod_of_surjective_of_is_compl f g hf hg hfg :=\nrfl\n\n@[simp] lemma equiv_prod_of_surjective_of_is_compl_apply {f : E \u2192L[\ud835\udd5c] F} {g : E \u2192L[\ud835\udd5c] G}\n  (hf : range f = \u22a4) (hg : range g = \u22a4) (hfg : is_compl (ker f) (ker g)) (x : E) :\n  equiv_prod_of_surjective_of_is_compl f g hf hg hfg x = (f x, g x) :=\nrfl\n\nend continuous_linear_map\n\nnamespace subspace\n\nvariables [complete_space E] (p q : subspace \ud835\udd5c E)\n\n/-- If `q` is a closed complement of a closed subspace `p`, then `p \u00d7 q` is continuously\nisomorphic to `E`. -/\ndef prod_equiv_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))\n  (hq : is_closed (q : set E)) : (p \u00d7 q) \u2243L[\ud835\udd5c] E :=\nbegin\n  haveI := hp.complete_space_coe, haveI := hq.complete_space_coe,\n  refine (p.prod_equiv_of_is_compl q h).to_continuous_linear_equiv_of_continuous _,\n  exact (p.subtypeL.coprod q.subtypeL).continuous\nend\n\n/-- Projection to a closed submodule along a closed complement. -/\ndef linear_proj_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))\n  (hq : is_closed (q : set E)) :\n  E \u2192L[\ud835\udd5c] p :=\n(continuous_linear_map.fst \ud835\udd5c p q) \u2218L \u2191(prod_equiv_of_closed_compl p q h hp hq).symm\n\nvariables {p q}\n\n@[simp] lemma coe_prod_equiv_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))\n  (hq : is_closed (q : set E)) :\n  \u21d1(p.prod_equiv_of_closed_compl q h hp hq) = p.prod_equiv_of_is_compl q h := rfl\n\n@[simp] \n\n@[simp] lemma coe_continuous_linear_proj_of_closed_compl (h : is_compl p q)\n  (hp : is_closed (p : set E)) (hq : is_closed (q : set E)) :\n  (p.linear_proj_of_closed_compl q h hp hq : E \u2192\u2097[\ud835\udd5c] p) = p.linear_proj_of_is_compl q h := rfl\n\n@[simp] lemma coe_continuous_linear_proj_of_closed_compl' (h : is_compl p q)\n  (hp : is_closed (p : set E)) (hq : is_closed (q : set E)) :\n  \u21d1(p.linear_proj_of_closed_compl q h hp hq) = p.linear_proj_of_is_compl q h := rfl\n\nlemma closed_complemented_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))\n  (hq : is_closed (q : set E)) : p.closed_complemented :=\n\u27e8p.linear_proj_of_closed_compl q h hp hq, submodule.linear_proj_of_is_compl_apply_left h\u27e9\n\nlemma closed_complemented_iff_has_closed_compl : p.closed_complemented \u2194\n  is_closed (p : set E) \u2227 \u2203 (q : subspace \ud835\udd5c E) (hq : is_closed (q : set E)), is_compl p q :=\n\u27e8\u03bb h, \u27e8h.is_closed, h.has_closed_complement\u27e9,\n  \u03bb \u27e8hp, \u27e8q, hq, hpq\u27e9\u27e9, closed_complemented_of_closed_compl hpq hp hq\u27e9\n\nlemma closed_complemented_of_quotient_finite_dimensional [complete_space \ud835\udd5c]\n  [finite_dimensional \ud835\udd5c (E \u29f8 p)] (hp : is_closed (p : set E)) :\n  p.closed_complemented :=\nbegin\n  obtain \u27e8q, hq\u27e9 : \u2203 q, is_compl p q := p.exists_is_compl,\n  haveI : finite_dimensional \ud835\udd5c q := (p.quotient_equiv_of_is_compl q hq).finite_dimensional,\n  exact closed_complemented_of_closed_compl hq hp q.closed_of_finite_dimensional\nend\n\nend subspace\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/complemented.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7194175795433708}}
{"text": "/-\nCopyright (c) 2022 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport data.W.cardinal\nimport ring_theory.algebraic_independent\nimport field_theory.is_alg_closed.basic\nimport field_theory.intermediate_field\nimport data.polynomial.cardinal\nimport data.mv_polynomial.cardinal\nimport data.zmod.algebra\n/-!\n# Classification of Algebraically closed fields\n\nThis file contains results related to classifying algebraically closed fields.\n\n## Main statements\n\n* `is_alg_closed.equiv_of_transcendence_basis` Two fields with the same characteristic and the same\n  cardinality of transcendence basis are isomorphic.\n* `is_alg_closed.ring_equiv_of_cardinal_eq_of_char_eq` Two uncountable algebraically closed fields\n  are isomorphic if they have the same characteristic and the same cardinality.\n-/\nuniverse u\n\nopen_locale cardinal\nopen cardinal\n\nsection algebraic_closure\n\nnamespace algebra.is_algebraic\n\nvariables (R L : Type u) [comm_ring R] [comm_ring L] [is_domain L] [algebra R L]\nvariables [no_zero_smul_divisors R L] (halg : algebra.is_algebraic R L)\n\nlemma cardinal_mk_le_sigma_polynomial :\n  #L \u2264 #(\u03a3 p : polynomial R, { x : L // x \u2208 (p.map (algebra_map R L)).roots }) :=\n@mk_le_of_injective L (\u03a3 p : polynomial R, { x : L | x \u2208 (p.map (algebra_map R L)).roots })\n  (\u03bb x : L, let p := classical.indefinite_description _ (halg x) in\n    \u27e8p.1, x,\n      begin\n      dsimp,\n      have h : p.1.map (algebra_map R L) \u2260 0,\n      { rw [ne.def, \u2190 polynomial.degree_eq_bot, polynomial.degree_map_eq_of_injective\n          (no_zero_smul_divisors.algebra_map_injective R L), polynomial.degree_eq_bot],\n        exact p.2.1 },\n      erw [polynomial.mem_roots h, polynomial.is_root, polynomial.eval_map,\n        \u2190 polynomial.aeval_def, p.2.2],\n      end\u27e9) (\u03bb x y, begin\n    intro h,\n    simp only at h,\n    refine (subtype.heq_iff_coe_eq _).1 h.2,\n    simp only [h.1, iff_self, forall_true_iff]\n  end)\n\n/--The cardinality of an algebraic extension is at most the maximum of the cardinality\nof the base ring or `\u03c9` -/\nlemma cardinal_mk_le_max : #L \u2264 max (#R) \u03c9 :=\ncalc #L \u2264 #(\u03a3 p : polynomial R, { x : L // x \u2208 (p.map (algebra_map R L)).roots }) :\n  cardinal_mk_le_sigma_polynomial R L halg\n... = cardinal.sum (\u03bb p : polynomial R, #{ x : L | x \u2208 (p.map (algebra_map R L)).roots }) :\n  by rw \u2190 mk_sigma; refl\n... \u2264 cardinal.sum.{u u} (\u03bb p : polynomial R, \u03c9) : sum_le_sum _ _\n  (\u03bb p, le_of_lt begin\n    rw [lt_omega_iff_finite],\n    classical,\n    simp only [\u2190 @multiset.mem_to_finset _ _ _ (p.map (algebra_map R L)).roots],\n    exact set.finite_mem_finset _,\n  end)\n... = #(polynomial R) * \u03c9 : sum_const' _ _\n... \u2264 max (max (#(polynomial R)) \u03c9) \u03c9 : mul_le_max _ _\n... \u2264 max (max (max (#R) \u03c9) \u03c9) \u03c9 :\n  max_le_max (max_le_max polynomial.cardinal_mk_le_max le_rfl) le_rfl\n... = max (#R) \u03c9 : by simp only [max_assoc, max_comm omega.{u}, max_left_comm omega.{u}, max_self]\n\nend algebra.is_algebraic\n\nend algebraic_closure\n\nnamespace is_alg_closed\n\nsection classification\n\nnoncomputable theory\n\nvariables {R L K : Type*} [comm_ring R]\nvariables [field K] [algebra R K]\nvariables [field L] [algebra R L]\nvariables {\u03b9 : Type*} (v : \u03b9 \u2192 K)\nvariables {\u03ba : Type*} (w : \u03ba \u2192 L)\n\nvariables (hv : algebraic_independent R v)\n\nlemma is_alg_closure_of_transcendence_basis [is_alg_closed K] (hv : is_transcendence_basis R v) :\n  is_alg_closure (algebra.adjoin R (set.range v)) K :=\nby letI := ring_hom.domain_nontrivial (algebra_map R K); exact\n{ alg_closed := by apply_instance,\n  algebraic := hv.is_algebraic }\n\nvariables (hw : algebraic_independent R w)\n\n/-- setting `R` to be `zmod (ring_char R)` this result shows that if two algebraically\nclosed fields have equipotent transcendence bases and the same characteristic then they are\nisomorphic. -/\ndef equiv_of_transcendence_basis [is_alg_closed K] [is_alg_closed L] (e : \u03b9 \u2243 \u03ba)\n  (hv : is_transcendence_basis R v) (hw : is_transcendence_basis R w) : K \u2243+* L :=\nbegin\n  letI := is_alg_closure_of_transcendence_basis v hv;\n  letI := is_alg_closure_of_transcendence_basis w hw;\n  have e : algebra.adjoin R (set.range v) \u2243+* algebra.adjoin R (set.range w),\n  { refine hv.1.aeval_equiv.symm.to_ring_equiv.trans _,\n    refine (alg_equiv.of_alg_hom\n      (mv_polynomial.rename e)\n      (mv_polynomial.rename e.symm)\n      _ _).to_ring_equiv.trans _,\n    { ext, simp },\n    { ext, simp },\n    exact hw.1.aeval_equiv.to_ring_equiv },\n  exact is_alg_closure.equiv_of_equiv K L e\nend\n\nend classification\n\nsection cardinal\n\nvariables {R L K : Type u} [comm_ring R]\nvariables [field K] [algebra R K] [is_alg_closed K]\nvariables {\u03b9 : Type u} (v : \u03b9 \u2192 K)\nvariable (hv : is_transcendence_basis R v)\n\nlemma cardinal_le_max_transcendence_basis (hv : is_transcendence_basis R v) :\n  #K \u2264 max (max (#R) (#\u03b9)) \u03c9 :=\ncalc #K \u2264 max (#(algebra.adjoin R (set.range v))) \u03c9 :\n  by letI := is_alg_closure_of_transcendence_basis v hv;\n   exact algebra.is_algebraic.cardinal_mk_le_max _ _ is_alg_closure.algebraic\n... = max (#(mv_polynomial \u03b9 R)) \u03c9 : by rw [cardinal.eq.2 \u27e8(hv.1.aeval_equiv).to_equiv\u27e9]\n... \u2264 max (max (max (#R) (#\u03b9)) \u03c9) \u03c9 : max_le_max mv_polynomial.cardinal_mk_le_max le_rfl\n... = _ : by simp [max_assoc]\n\n/-- If `K` is an uncountable algebraically closed field, then its\ncardinality is the same as that of a transcendence basis. -/\nlemma cardinal_eq_cardinal_transcendence_basis_of_omega_lt [nontrivial R]\n  (hv : is_transcendence_basis R v) (hR : #R \u2264 \u03c9) (hK : \u03c9 < #K) : #K = #\u03b9 :=\nhave \u03c9 \u2264 #\u03b9,\n  from le_of_not_lt (\u03bb h,\n    not_le_of_gt hK $ calc\n      #K \u2264 max (max (#R) (#\u03b9)) \u03c9 : cardinal_le_max_transcendence_basis v hv\n     ... \u2264 _ : max_le (max_le hR (le_of_lt h)) le_rfl),\nle_antisymm\n  (calc #K \u2264 max (max (#R) (#\u03b9)) \u03c9 : cardinal_le_max_transcendence_basis v hv\n       ... = #\u03b9 : begin\n         rw [max_eq_left, max_eq_right],\n         { exact le_trans hR this },\n         { exact le_max_of_le_right this }\n       end)\n  (mk_le_of_injective (show function.injective v, from hv.1.injective))\n\nend cardinal\n\nvariables {K L : Type} [field K] [field L] [is_alg_closed K] [is_alg_closed L]\n\n/-- Two uncountable algebraically closed fields of characteristic zero are isomorphic\nif they have the same cardinality. -/\n@[nolint def_lemma] lemma ring_equiv_of_cardinal_eq_of_char_zero [char_zero K] [char_zero L]\n  (hK : \u03c9 < #K) (hKL : #K = #L) : K \u2243+* L :=\nbegin\n  apply classical.choice,\n  cases exists_is_transcendence_basis \u2124\n    (show function.injective (algebra_map \u2124 K),\n      from int.cast_injective) with s hs,\n  cases exists_is_transcendence_basis \u2124\n    (show function.injective (algebra_map \u2124 L),\n      from int.cast_injective) with t ht,\n  have : #s = #t,\n  { rw [\u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ hs (le_of_eq mk_int) hK,\n        \u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ ht (le_of_eq mk_int), hKL],\n    rwa \u2190 hKL },\n  cases cardinal.eq.1 this with e,\n  exact \u27e8equiv_of_transcendence_basis _ _ e hs ht\u27e9\nend\n\nprivate lemma ring_equiv_of_cardinal_eq_of_char_p (p : \u2115) [fact p.prime]\n  [char_p K p] [char_p L p] (hK : \u03c9 < #K) (hKL : #K = #L) : K \u2243+* L :=\nbegin\n  apply classical.choice,\n  cases exists_is_transcendence_basis (zmod p)\n    (show function.injective (algebra_map (zmod p) K),\n      from ring_hom.injective _) with s hs,\n  cases exists_is_transcendence_basis (zmod p)\n    (show function.injective (algebra_map (zmod p) L),\n      from ring_hom.injective _) with t ht,\n  have : #s = #t,\n  { rw [\u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ hs\n      (le_of_lt $ lt_omega_iff_fintype.2 \u27e8infer_instance\u27e9) hK,\n        \u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ ht\n      (le_of_lt $ lt_omega_iff_fintype.2 \u27e8infer_instance\u27e9), hKL],\n    rwa \u2190 hKL },\n  cases cardinal.eq.1 this with e,\n  exact \u27e8equiv_of_transcendence_basis _ _ e hs ht\u27e9\nend\n\n/-- Two uncountable algebraically closed fields are isomorphic\nif they have the same cardinality and the same characteristic. -/\n@[nolint def_lemma] lemma ring_equiv_of_cardinal_eq_of_char_eq (p : \u2115) [char_p K p] [char_p L p]\n  (hK : \u03c9 < #K) (hKL : #K = #L) : K \u2243+* L :=\nbegin\n  apply classical.choice,\n  rcases char_p.char_is_prime_or_zero K p with hp | hp,\n  { haveI : fact p.prime := \u27e8hp\u27e9,\n    exact \u27e8ring_equiv_of_cardinal_eq_of_char_p p hK hKL\u27e9 },\n  { rw [hp] at *,\n    resetI,\n    letI : char_zero K := char_p.char_p_to_char_zero K,\n    letI : char_zero L := char_p.char_p_to_char_zero L,\n    exact \u27e8ring_equiv_of_cardinal_eq_of_char_zero hK hKL\u27e9 }\nend\n\nend is_alg_closed\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/field_theory/is_alg_closed/classification.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.7194175780704875}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.inner_product_space.orientation\nimport measure_theory.measure.haar_lebesgue\n\n/-!\n# Volume forms and measures on inner product spaces\n\nA volume form induces a Lebesgue measure on general finite-dimensional real vector spaces. In this\nfile, we discuss the specific situation of inner product spaces, where an orientation gives\nrise to a canonical volume form. We show that the measure coming from this volume form gives\nmeasure `1` to the parallelepiped spanned by any orthonormal basis, and that it coincides with\nthe canonical `volume` from the `measure_space` instance.\n-/\n\nopen finite_dimensional measure_theory measure_theory.measure set\n\nvariables {\u03b9 F : Type*}\nvariables [fintype \u03b9] [normed_add_comm_group F] [inner_product_space \u211d F] [finite_dimensional \u211d F]\n  [measurable_space F] [borel_space F]\n\nsection\n\nvariables {m n : \u2115} [_i : fact (finrank \u211d F = n)]\ninclude _i\n\n/-- The volume form coming from an orientation in an inner product space gives measure `1` to the\nparallelepiped associated to any orthonormal basis. This is a rephrasing of\n`abs_volume_form_apply_of_orthonormal` in terms of measures. -/\nlemma orientation.measure_orthonormal_basis\n  (o : orientation \u211d F (fin n)) (b : orthonormal_basis \u03b9 \u211d F) :\n  o.volume_form.measure (parallelepiped b) = 1 :=\nbegin\n  have e : \u03b9 \u2243 fin n,\n  { refine fintype.equiv_fin_of_card_eq _,\n    rw [\u2190 _i.out, finrank_eq_card_basis b.to_basis] },\n  have A : \u21d1b = (b.reindex e) \u2218 e,\n  { ext x,\n    simp only [orthonormal_basis.coe_reindex, function.comp_app, equiv.symm_apply_apply] },\n  rw [A, parallelepiped_comp_equiv, alternating_map.measure_parallelepiped,\n    o.abs_volume_form_apply_of_orthonormal, ennreal.of_real_one],\nend\n\n/-- In an oriented inner product space, the measure coming from the canonical volume form\nassociated to an orientation coincides with the volume. -/\nlemma orientation.measure_eq_volume (o : orientation \u211d F (fin n)) :\n  o.volume_form.measure = volume :=\nbegin\n  have A : o.volume_form.measure ((std_orthonormal_basis \u211d F).to_basis.parallelepiped) = 1,\n    from orientation.measure_orthonormal_basis o (std_orthonormal_basis \u211d F),\n  rw [add_haar_measure_unique o.volume_form.measure\n    ((std_orthonormal_basis \u211d F).to_basis.parallelepiped), A, one_smul],\n  simp only [volume, basis.add_haar],\nend\n\nend\n\n/-- The volume measure in a finite-dimensional inner product space gives measure `1` to the\nparallelepiped spanned by any orthonormal basis. -/\nlemma orthonormal_basis.volume_parallelepiped (b : orthonormal_basis \u03b9 \u211d F) :\n  volume (parallelepiped b) = 1 :=\nbegin\n  haveI : fact (finrank \u211d F = finrank \u211d F) := \u27e8rfl\u27e9,\n  let o := (std_orthonormal_basis \u211d F).to_basis.orientation,\n  rw \u2190 o.measure_eq_volume,\n  exact o.measure_orthonormal_basis b,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/measure/haar_of_inner.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7194175748391184}}
{"text": "import topology.algebra.module.locally_convex\n\nopen filter\nopen_locale pointwise topological_space\n\ndef has_homothetic_basis {\u03b9 E : Sort*} [topological_space E] [has_scalar \u211d E] (l : filter E) \n  (p : \u03b9 \u2192 Prop) (s : \u03b9 \u2192 set E) : Prop :=\nhas_basis l (\u03bb i\u03b5 : \u03b9 \u00d7 \u211d, p i\u03b5.1 \u2227 0 < i\u03b5.2) (\u03bb i\u03b5, i\u03b5.2 \u2022 s i\u03b5.1)\n\nlemma ball_eq_smul_ball {E : Sort*} [semi_normed_group E] [normed_space \u211d E] {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n  metric.ball (0 : E) \u03b5 = \u03b5 \u2022 metric.ball (0 : E) 1 :=\nbegin\n  ext x,\n  split;\n  intros hx,\n  { refine \u27e8\u03b5\u207b\u00b9 \u2022 x, _, _\u27e9,\n    { rw mem_ball_zero_iff at *,\n      rw norm_smul_of_nonneg (inv_nonneg.mpr h\u03b5.le),\n      rwa [\u2190 mul_lt_mul_left (inv_pos.mpr h\u03b5), inv_mul_cancel h\u03b5.ne.symm] at hx },\n    { rw [smul_smul, mul_inv_cancel h\u03b5.ne.symm, one_smul] } },\n  { rcases hx with \u27e8y, hy, rfl\u27e9,\n    rw mem_ball_zero_iff at *,\n    rw [norm_smul_of_nonneg h\u03b5.le],\n    rwa [\u2190 mul_lt_mul_left h\u03b5, mul_one] at hy }\nend\n\nlemma normed_space.has_homothetic_basis_zero {\u03b9 E : Sort*} [semi_normed_group E] \n  [normed_space \u211d E] :\n  has_homothetic_basis (\ud835\udcdd 0 : filter E) (\u03bb (i : unit), true) (\u03bb _, metric.ball (0 : E) 1) :=\nmetric.nhds_basis_ball.to_has_basis \n  (\u03bb \u03b5 h\u03b5, \u27e8\u27e8(), \u03b5\u27e9, \u27e8true.intro, h\u03b5\u27e9, by simp [ball_eq_smul_ball h\u03b5]\u27e9) \n  (\u03bb i\u03b5 hi\u03b5, \u27e8i\u03b5.2, hi\u03b5.2, by simp [ball_eq_smul_ball hi\u03b5.2]\u27e9)\n\n", "meta": {"author": "ADedecker", "repo": "distributions", "sha": "b4d124142788db55cf781184aff03bcc46aa2b10", "save_path": "github-repos/lean/ADedecker-distributions", "path": "github-repos/lean/ADedecker-distributions/distributions-b4d124142788db55cf781184aff03bcc46aa2b10/src/has_homothetic_basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7194175701348658}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.group.defs\nimport Mathlib.logic.function.basic\nimport Mathlib.PostPort\n\nuniverses u u_1 \n\nnamespace Mathlib\n\n/--\nComposing two associative operations of `f : \u03b1 \u2192 \u03b1 \u2192 \u03b1` on the left\nis equal to an associative operation on the left.\n-/\ntheorem comp_assoc_left {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) [is_associative \u03b1 f] (x : \u03b1) (y : \u03b1) :\n    f x \u2218 f y = f (f x y) :=\n  sorry\n\n/--\nComposing two associative operations of `f : \u03b1 \u2192 \u03b1 \u2192 \u03b1` on the right\nis equal to an associative operation on the right.\n-/\ntheorem comp_assoc_right {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) [is_associative \u03b1 f] (x : \u03b1) (y : \u03b1) :\n    ((fun (z : \u03b1) => f z x) \u2218 fun (z : \u03b1) => f z y) = fun (z : \u03b1) => f z (f y x) :=\n  sorry\n\n/--\nComposing two multiplications on the left by `y` then `x`\nis equal to a multiplication on the left by `x * y`.\n-/\n@[simp] theorem comp_mul_left {\u03b1 : Type u_1} [semigroup \u03b1] (x : \u03b1) (y : \u03b1) :\n    Mul.mul x \u2218 Mul.mul y = Mul.mul (x * y) :=\n  comp_assoc_left Mul.mul x y\n\n/--\nComposing two multiplications on the right by `y` and `x`\nis equal to a multiplication on the right by `y * x`.\n-/\n@[simp] theorem comp_add_right {\u03b1 : Type u_1} [add_semigroup \u03b1] (x : \u03b1) (y : \u03b1) :\n    ((fun (_x : \u03b1) => _x + x) \u2218 fun (_x : \u03b1) => _x + y) = fun (_x : \u03b1) => _x + (y + x) :=\n  comp_assoc_right Add.add x y\n\ntheorem ite_add_zero {M : Type u} [add_monoid M] {P : Prop} [Decidable P] {a : M} {b : M} :\n    ite P (a + b) 0 = ite P a 0 + ite P b 0 :=\n  sorry\n\ntheorem eq_one_iff_eq_one_of_mul_eq_one {M : Type u} [monoid M] {a : M} {b : M} (h : a * b = 1) :\n    a = 1 \u2194 b = 1 :=\n  sorry\n\ntheorem add_left_comm {G : Type u} [add_comm_semigroup G] (a : G) (b : G) (c : G) :\n    a + (b + c) = b + (a + c) :=\n  left_comm Add.add add_comm add_assoc\n\ntheorem mul_right_comm {G : Type u} [comm_semigroup G] (a : G) (b : G) (c : G) :\n    a * b * c = a * c * b :=\n  right_comm Mul.mul mul_comm mul_assoc\n\ntheorem add_add_add_comm {G : Type u} [add_comm_semigroup G] (a : G) (b : G) (c : G) (d : G) :\n    a + b + (c + d) = a + c + (b + d) :=\n  sorry\n\n@[simp] theorem bit0_zero {M : Type u} [add_monoid M] : bit0 0 = 0 := add_zero 0\n\n@[simp] theorem bit1_zero {M : Type u} [add_monoid M] [HasOne M] : bit1 0 = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (bit1 0 = 1)) (bit1.equations._eqn_1 0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 0 + 1 = 1)) bit0_zero))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 + 1 = 1)) (zero_add 1))) (Eq.refl 1)))\n\ntheorem neg_unique {M : Type u} [add_comm_monoid M] {x : M} {y : M} {z : M} (hy : x + y = 0)\n    (hz : x + z = 0) : y = z :=\n  left_neg_eq_right_neg (trans (add_comm y x) hy) hz\n\n@[simp] theorem mul_eq_left_iff {M : Type u} [left_cancel_monoid M] {a : M} {b : M} :\n    a * b = a \u2194 b = 1 :=\n  iff.trans\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * b = a \u2194 a * b = a * 1)) (mul_one a)))\n      (iff.refl (a * b = a)))\n    mul_left_cancel_iff\n\n@[simp] theorem left_eq_add_iff {M : Type u} [add_left_cancel_monoid M] {a : M} {b : M} :\n    a = a + b \u2194 b = 0 :=\n  iff.trans eq_comm add_eq_left_iff\n\n@[simp] theorem mul_eq_right_iff {M : Type u} [right_cancel_monoid M] {a : M} {b : M} :\n    a * b = b \u2194 a = 1 :=\n  iff.trans\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * b = b \u2194 a * b = 1 * b)) (one_mul b)))\n      (iff.refl (a * b = b)))\n    mul_right_cancel_iff\n\n@[simp] theorem right_eq_mul_iff {M : Type u} [right_cancel_monoid M] {a : M} {b : M} :\n    b = a * b \u2194 a = 1 :=\n  iff.trans eq_comm mul_eq_right_iff\n\ntheorem neg_eq_zero_sub {G : Type u} [sub_neg_monoid G] (x : G) : -x = 0 - x :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-x = 0 - x)) (sub_eq_add_neg 0 x)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-x = 0 + -x)) (zero_add (-x)))) (Eq.refl (-x)))\n\ntheorem mul_one_div {G : Type u} [div_inv_monoid G] (x : G) (y : G) : x * (1 / y) = x / y :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (x * (1 / y) = x / y)) (div_eq_mul_inv 1 y)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (x * (1 * (y\u207b\u00b9)) = x / y)) (one_mul (y\u207b\u00b9))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (x * (y\u207b\u00b9) = x / y)) (div_eq_mul_inv x y)))\n        (Eq.refl (x * (y\u207b\u00b9)))))\n\ntheorem mul_div_assoc {G : Type u} [div_inv_monoid G] {a : G} {b : G} {c : G} :\n    a * b / c = a * (b / c) :=\n  sorry\n\ntheorem mul_div_assoc' {G : Type u} [div_inv_monoid G] (a : G) (b : G) (c : G) :\n    a * (b / c) = a * b / c :=\n  Eq.symm mul_div_assoc\n\n@[simp] theorem one_div {G : Type u} [div_inv_monoid G] (a : G) : 1 / a = (a\u207b\u00b9) :=\n  Eq.symm (inv_eq_one_div a)\n\n@[simp] theorem neg_add_cancel_right {G : Type u} [add_group G] (a : G) (b : G) : a + -b + b = a :=\n  sorry\n\n@[simp] theorem neg_zero {G : Type u} [add_group G] : -0 = 0 := neg_eq_of_add_eq_zero (zero_add 0)\n\ntheorem left_inverse_inv (G : Type u_1) [group G] :\n    function.left_inverse (fun (a : G) => a\u207b\u00b9) fun (a : G) => a\u207b\u00b9 :=\n  inv_inv\n\n@[simp] theorem inv_involutive {G : Type u} [group G] : function.involutive has_inv.inv := inv_inv\n\ntheorem neg_injective {G : Type u} [add_group G] : function.injective Neg.neg :=\n  function.involutive.injective neg_involutive\n\n@[simp] theorem neg_inj {G : Type u} [add_group G] {a : G} {b : G} : -a = -b \u2194 a = b :=\n  function.injective.eq_iff neg_injective\n\n@[simp] theorem add_neg_cancel_left {G : Type u} [add_group G] (a : G) (b : G) : a + (-a + b) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + (-a + b) = b)) (Eq.symm (add_assoc a (-a) b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -a + b = b)) (add_right_neg a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 + b = b)) (zero_add b))) (Eq.refl b)))\n\ntheorem add_left_surjective {G : Type u} [add_group G] (a : G) : function.surjective (Add.add a) :=\n  fun (x : G) => Exists.intro (-a + x) (add_neg_cancel_left a x)\n\ntheorem add_right_surjective {G : Type u} [add_group G] (a : G) :\n    function.surjective fun (x : G) => x + a :=\n  fun (x : G) => Exists.intro (x + -a) (neg_add_cancel_right x a)\n\n@[simp] theorem mul_inv_rev {G : Type u} [group G] (a : G) (b : G) : a * b\u207b\u00b9 = b\u207b\u00b9 * (a\u207b\u00b9) := sorry\n\ntheorem eq_neg_of_eq_neg {G : Type u} [add_group G] {a : G} {b : G} (h : a = -b) : b = -a := sorry\n\ntheorem eq_neg_of_add_eq_zero {G : Type u} [add_group G] {a : G} {b : G} (h : a + b = 0) : a = -b :=\n  sorry\n\ntheorem eq_add_neg_of_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a + c = b) :\n    a = b + -c :=\n  sorry\n\ntheorem eq_neg_add_of_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : b + a = c) :\n    a = -b + c :=\n  sorry\n\ntheorem neg_add_eq_of_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : b = a + c) :\n    -a + b = c :=\n  sorry\n\ntheorem mul_inv_eq_of_eq_mul {G : Type u} [group G] {a : G} {b : G} {c : G} (h : a = c * b) :\n    a * (b\u207b\u00b9) = c :=\n  sorry\n\ntheorem eq_add_of_add_neg_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a + -c = b) :\n    a = b + c :=\n  sorry\n\ntheorem eq_mul_of_inv_mul_eq {G : Type u} [group G] {a : G} {b : G} {c : G} (h : b\u207b\u00b9 * a = c) :\n    a = b * c :=\n  sorry\n\ntheorem mul_eq_of_eq_inv_mul {G : Type u} [group G] {a : G} {b : G} {c : G} (h : b = a\u207b\u00b9 * c) :\n    a * b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b = c)) h))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (a\u207b\u00b9 * c) = c)) (mul_inv_cancel_left a c))) (Eq.refl c))\n\ntheorem mul_eq_of_eq_mul_inv {G : Type u} [group G] {a : G} {b : G} {c : G} (h : a = c * (b\u207b\u00b9)) :\n    a * b = c :=\n  sorry\n\ntheorem add_self_iff_eq_zero {G : Type u} [add_group G] {a : G} : a + a = a \u2194 a = 0 :=\n  eq.mp (Eq._oldrec (Eq.refl (a + a = a + 0 \u2194 a = 0)) (add_zero a)) (add_right_inj a)\n\n@[simp] theorem neg_eq_zero {G : Type u} [add_group G] {a : G} : -a = 0 \u2194 a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-a = 0 \u2194 a = 0)) (Eq.symm (propext neg_inj))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a = 0 \u2194 -a = -0)) neg_zero)) (iff.refl (-a = 0)))\n\n@[simp] theorem zero_eq_neg {G : Type u} [add_group G] {a : G} : 0 = -a \u2194 a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 = -a \u2194 a = 0)) (propext eq_comm)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a = 0 \u2194 a = 0)) (propext neg_eq_zero))) (iff.refl (a = 0)))\n\ntheorem neg_ne_zero {G : Type u} [add_group G] {a : G} : -a \u2260 0 \u2194 a \u2260 0 := not_congr neg_eq_zero\n\ntheorem eq_neg_iff_eq_neg {G : Type u} [add_group G] {a : G} {b : G} : a = -b \u2194 b = -a :=\n  { mp := eq_neg_of_eq_neg, mpr := eq_neg_of_eq_neg }\n\ntheorem neg_eq_iff_neg_eq {G : Type u} [add_group G] {a : G} {b : G} : -a = b \u2194 -b = a :=\n  iff.trans eq_comm (iff.trans eq_neg_iff_eq_neg eq_comm)\n\ntheorem mul_eq_one_iff_eq_inv {G : Type u} [group G] {a : G} {b : G} : a * b = 1 \u2194 a = (b\u207b\u00b9) :=\n  sorry\n\ntheorem mul_eq_one_iff_inv_eq {G : Type u} [group G] {a : G} {b : G} : a * b = 1 \u2194 a\u207b\u00b9 = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b = 1 \u2194 a\u207b\u00b9 = b)) (propext mul_eq_one_iff_eq_inv)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = (b\u207b\u00b9) \u2194 a\u207b\u00b9 = b)) (propext eq_inv_iff_eq_inv)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b = (a\u207b\u00b9) \u2194 a\u207b\u00b9 = b)) (propext eq_comm)))\n        (iff.refl (a\u207b\u00b9 = b))))\n\ntheorem eq_neg_iff_add_eq_zero {G : Type u} [add_group G] {a : G} {b : G} : a = -b \u2194 a + b = 0 :=\n  iff.symm add_eq_zero_iff_eq_neg\n\ntheorem neg_eq_iff_add_eq_zero {G : Type u} [add_group G] {a : G} {b : G} : -a = b \u2194 a + b = 0 :=\n  iff.symm add_eq_zero_iff_neg_eq\n\ntheorem eq_mul_inv_iff_mul_eq {G : Type u} [group G] {a : G} {b : G} {c : G} :\n    a = b * (c\u207b\u00b9) \u2194 a * c = b :=\n  sorry\n\ntheorem eq_inv_mul_iff_mul_eq {G : Type u} [group G] {a : G} {b : G} {c : G} :\n    a = b\u207b\u00b9 * c \u2194 b * a = c :=\n  sorry\n\ntheorem inv_mul_eq_iff_eq_mul {G : Type u} [group G] {a : G} {b : G} {c : G} :\n    a\u207b\u00b9 * b = c \u2194 b = a * c :=\n  sorry\n\ntheorem add_neg_eq_iff_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} :\n    a + -b = c \u2194 a = c + b :=\n  sorry\n\ntheorem mul_inv_eq_one {G : Type u} [group G] {a : G} {b : G} : a * (b\u207b\u00b9) = 1 \u2194 a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b\u207b\u00b9) = 1 \u2194 a = b)) (propext mul_eq_one_iff_eq_inv)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = (b\u207b\u00b9\u207b\u00b9) \u2194 a = b)) (inv_inv b))) (iff.refl (a = b)))\n\ntheorem inv_mul_eq_one {G : Type u} [group G] {a : G} {b : G} : a\u207b\u00b9 * b = 1 \u2194 a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 * b = 1 \u2194 a = b)) (propext mul_eq_one_iff_eq_inv)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 = (b\u207b\u00b9) \u2194 a = b)) (propext inv_inj))) (iff.refl (a = b)))\n\n@[simp] theorem mul_left_eq_self {G : Type u} [group G] {a : G} {b : G} : a * b = b \u2194 a = 1 := sorry\n\n@[simp] theorem add_right_eq_self {G : Type u} [add_group G] {a : G} {b : G} : a + b = a \u2194 b = 0 :=\n  sorry\n\ntheorem sub_left_injective {G : Type u} [add_group G] {b : G} :\n    function.injective fun (a : G) => a - b :=\n  sorry\n\ntheorem div_right_injective {G : Type u} [group G] {b : G} :\n    function.injective fun (a : G) => b / a :=\n  sorry\n\n@[simp] theorem sub_self {G : Type u} [add_group G] (a : G) : a - a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - a = 0)) (sub_eq_add_neg a a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -a = 0)) (add_right_neg a))) (Eq.refl 0))\n\n@[simp] theorem sub_add_cancel {G : Type u} [add_group G] (a : G) (b : G) : a - b + b = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b + b = a)) (sub_eq_add_neg a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -b + b = a)) (neg_add_cancel_right a b))) (Eq.refl a))\n\n@[simp] theorem add_sub_cancel {G : Type u} [add_group G] (a : G) (b : G) : a + b - b = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + b - b = a)) (sub_eq_add_neg (a + b) b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + b + -b = a)) (add_neg_cancel_right a b))) (Eq.refl a))\n\ntheorem add_sub_assoc {G : Type u} [add_group G] (a : G) (b : G) (c : G) :\n    a + b - c = a + (b - c) :=\n  sorry\n\ntheorem eq_of_sub_eq_zero {G : Type u} [add_group G] {a : G} {b : G} (h : a - b = 0) : a = b :=\n  sorry\n\ntheorem sub_eq_zero_of_eq {G : Type u} [add_group G] {a : G} {b : G} (h : a = b) : a - b = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = 0)) h))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b - b = 0)) (sub_self b))) (Eq.refl 0))\n\ntheorem sub_eq_zero_iff_eq {G : Type u} [add_group G] {a : G} {b : G} : a - b = 0 \u2194 a = b :=\n  { mp := eq_of_sub_eq_zero, mpr := sub_eq_zero_of_eq }\n\n@[simp] theorem sub_zero {G : Type u} [add_group G] (a : G) : a - 0 = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - 0 = a)) (sub_eq_add_neg a 0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -0 = a)) neg_zero))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 = a)) (add_zero a))) (Eq.refl a)))\n\ntheorem sub_ne_zero_of_ne {G : Type u} [add_group G] {a : G} {b : G} (h : a \u2260 b) : a - b \u2260 0 :=\n  id fun (hab : a - b = 0) => h (eq_of_sub_eq_zero hab)\n\n@[simp] theorem sub_neg_eq_add {G : Type u} [add_group G] (a : G) (b : G) : a - -b = a + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - -b = a + b)) (sub_eq_add_neg a (-b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + --b = a + b)) (neg_neg b))) (Eq.refl (a + b)))\n\n@[simp] theorem neg_sub {G : Type u} [add_group G] (a : G) (b : G) : -(a - b) = b - a := sorry\n\ntheorem add_sub {G : Type u} [add_group G] (a : G) (b : G) (c : G) : a + (b - c) = a + b - c :=\n  sorry\n\ntheorem sub_add_eq_sub_sub_swap {G : Type u} [add_group G] (a : G) (b : G) (c : G) :\n    a - (b + c) = a - c - b :=\n  sorry\n\n@[simp] theorem add_sub_add_right_eq_sub {G : Type u} [add_group G] (a : G) (b : G) (c : G) :\n    a + c - (b + c) = a - b :=\n  sorry\n\ntheorem eq_sub_of_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a + c = b) :\n    a = b - c :=\n  sorry\n\ntheorem sub_eq_of_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a = c + b) :\n    a - b = c :=\n  sorry\n\ntheorem eq_add_of_sub_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a - c = b) :\n    a = b + c :=\n  sorry\n\ntheorem add_eq_of_eq_sub {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a = c - b) :\n    a + b = c :=\n  sorry\n\n@[simp] theorem sub_right_inj {G : Type u} [add_group G] {a : G} {b : G} {c : G} :\n    a - b = a - c \u2194 b = c :=\n  function.injective.eq_iff sub_right_injective\n\n@[simp] theorem sub_left_inj {G : Type u} [add_group G] {a : G} {b : G} {c : G} :\n    b - a = c - a \u2194 b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b - a = c - a \u2194 b = c)) (sub_eq_add_neg b a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b + -a = c - a \u2194 b = c)) (sub_eq_add_neg c a)))\n      (add_left_inj (-a)))\n\ntheorem sub_add_sub_cancel {G : Type u} [add_group G] (a : G) (b : G) (c : G) :\n    a - b + (b - c) = a - c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b + (b - c) = a - c)) (Eq.symm (add_sub_assoc (a - b) b c))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a - b + b - c = a - c)) (sub_add_cancel a b)))\n      (Eq.refl (a - c)))\n\ntheorem sub_sub_sub_cancel_right {G : Type u} [add_group G] (a : G) (b : G) (c : G) :\n    a - c - (b - c) = a - b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - c - (b - c) = a - b)) (Eq.symm (neg_sub c b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a - c - -(c - b) = a - b)) (sub_neg_eq_add (a - c) (c - b))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a - c + (c - b) = a - b)) (sub_add_sub_cancel a c b)))\n        (Eq.refl (a - b))))\n\ntheorem sub_sub_assoc_swap {G : Type u} [add_group G] {a : G} {b : G} {c : G} :\n    a - (b - c) = a + c - b :=\n  sorry\n\ntheorem sub_eq_zero {G : Type u} [add_group G] {a : G} {b : G} : a - b = 0 \u2194 a = b := sorry\n\ntheorem sub_ne_zero {G : Type u} [add_group G] {a : G} {b : G} : a - b \u2260 0 \u2194 a \u2260 b :=\n  not_congr sub_eq_zero\n\ntheorem eq_sub_iff_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} :\n    a = b - c \u2194 a + c = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b - c \u2194 a + c = b)) (sub_eq_add_neg b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b + -c \u2194 a + c = b)) (propext eq_add_neg_iff_add_eq)))\n      (iff.refl (a + c = b)))\n\ntheorem sub_eq_iff_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} :\n    a - b = c \u2194 a = c + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = c \u2194 a = c + b)) (sub_eq_add_neg a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -b = c \u2194 a = c + b)) (propext add_neg_eq_iff_eq_add)))\n      (iff.refl (a = c + b)))\n\ntheorem eq_iff_eq_of_sub_eq_sub {G : Type u} [add_group G] {a : G} {b : G} {c : G} {d : G}\n    (H : a - b = c - d) : a = b \u2194 c = d :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b \u2194 c = d)) (Eq.symm (propext sub_eq_zero))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a - b = 0 \u2194 c = d)) H))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (c - d = 0 \u2194 c = d)) (propext sub_eq_zero)))\n        (iff.refl (c = d))))\n\ntheorem left_inverse_sub_add_left {G : Type u} [add_group G] (c : G) :\n    function.left_inverse (fun (x : G) => x - c) fun (x : G) => x + c :=\n  fun (x : G) => add_sub_cancel x c\n\ntheorem left_inverse_add_left_sub {G : Type u} [add_group G] (c : G) :\n    function.left_inverse (fun (x : G) => x + c) fun (x : G) => x - c :=\n  fun (x : G) => sub_add_cancel x c\n\ntheorem left_inverse_add_right_neg_add {G : Type u} [add_group G] (c : G) :\n    function.left_inverse (fun (x : G) => c + x) fun (x : G) => -c + x :=\n  fun (x : G) => add_neg_cancel_left c x\n\ntheorem left_inverse_neg_add_add_right {G : Type u} [add_group G] (c : G) :\n    function.left_inverse (fun (x : G) => -c + x) fun (x : G) => c + x :=\n  fun (x : G) => neg_add_cancel_left c x\n\ntheorem neg_add {G : Type u} [add_comm_group G] (a : G) (b : G) : -(a + b) = -a + -b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-(a + b) = -a + -b)) (neg_add_rev a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-b + -a = -a + -b)) (add_comm (-b) (-a))))\n      (Eq.refl (-a + -b)))\n\ntheorem sub_add_eq_sub_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a - (b + c) = a - b - c :=\n  sorry\n\ntheorem neg_add_eq_sub {G : Type u} [add_comm_group G] (a : G) (b : G) : -a + b = b - a := sorry\n\ntheorem sub_add_eq_add_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a - b + c = a + c - b :=\n  sorry\n\ntheorem sub_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b - c = a - (b + c) :=\n  sorry\n\ntheorem sub_add {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b + c = a - (b - c) :=\n  sorry\n\n@[simp] theorem add_sub_add_left_eq_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    c + a - (c + b) = a - b :=\n  sorry\n\ntheorem eq_sub_of_add_eq' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : c + a = b) :\n    a = b - c :=\n  sorry\n\ntheorem sub_eq_of_eq_add' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : a = b + c) :\n    a - b = c :=\n  sorry\n\ntheorem eq_add_of_sub_eq' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : a - b = c) :\n    a = b + c :=\n  sorry\n\ntheorem add_eq_of_eq_sub' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : b = c - a) :\n    a + b = c :=\n  sorry\n\ntheorem sub_sub_self {G : Type u} [add_comm_group G] (a : G) (b : G) : a - (a - b) = b := sorry\n\ntheorem add_sub_comm {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) (d : G) :\n    a + b - (c + d) = a - c + (b - d) :=\n  sorry\n\ntheorem sub_eq_sub_add_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a - b = c - b + (a - c) :=\n  sorry\n\ntheorem neg_neg_sub_neg {G : Type u} [add_comm_group G] (a : G) (b : G) : -(-a - -b) = a - b :=\n  sorry\n\n@[simp] theorem sub_sub_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) : a - (a - b) = b :=\n  sub_sub_self a b\n\ntheorem sub_eq_neg_add {G : Type u} [add_comm_group G] (a : G) (b : G) : a - b = -b + a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = -b + a)) (sub_eq_add_neg a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -b = -b + a)) (add_comm a (-b)))) (Eq.refl (-b + a)))\n\ntheorem neg_add' {G : Type u} [add_comm_group G] (a : G) (b : G) : -(a + b) = -a - b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-(a + b) = -a - b)) (sub_eq_add_neg (-a) b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-(a + b) = -a + -b)) (neg_add a b))) (Eq.refl (-a + -b)))\n\n@[simp] theorem neg_sub_neg {G : Type u} [add_comm_group G] (a : G) (b : G) : -a - -b = b - a :=\n  sorry\n\ntheorem eq_sub_iff_add_eq' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} :\n    a = b - c \u2194 c + a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b - c \u2194 c + a = b)) (propext eq_sub_iff_add_eq)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + c = b \u2194 c + a = b)) (add_comm a c)))\n      (iff.refl (c + a = b)))\n\ntheorem sub_eq_iff_eq_add' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} :\n    a - b = c \u2194 a = b + c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = c \u2194 a = b + c)) (propext sub_eq_iff_eq_add)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = c + b \u2194 a = b + c)) (add_comm c b)))\n      (iff.refl (a = b + c)))\n\n@[simp] theorem add_sub_cancel' {G : Type u} [add_comm_group G] (a : G) (b : G) : a + b - a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + b - a = b)) (sub_eq_neg_add (a + b) a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a + (a + b) = b)) (neg_add_cancel_left a b))) (Eq.refl b))\n\n@[simp] theorem add_sub_cancel'_right {G : Type u} [add_comm_group G] (a : G) (b : G) :\n    a + (b - a) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + (b - a) = b)) (Eq.symm (add_sub_assoc a b a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + b - a = b)) (add_sub_cancel' a b))) (Eq.refl b))\n\n-- This lemma is in the `simp` set under the name `add_neg_cancel_comm_assoc`,\n\n-- defined  in `algebra/group/commute`\n\ntheorem add_add_neg_cancel'_right {G : Type u} [add_comm_group G] (a : G) (b : G) :\n    a + (b + -a) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + (b + -a) = b)) (Eq.symm (sub_eq_add_neg b a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + (b - a) = b)) (add_sub_cancel'_right a b))) (Eq.refl b))\n\ntheorem sub_right_comm {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a - b - c = a - c - b :=\n  sorry\n\n@[simp] theorem add_add_sub_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a + c + (b - c) = a + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + c + (b - c) = a + b)) (add_assoc a c (b - c))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + (c + (b - c)) = a + b)) (add_sub_cancel'_right c b)))\n      (Eq.refl (a + b)))\n\n@[simp] theorem sub_add_add_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a - c + (b + c) = a + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - c + (b + c) = a + b)) (add_left_comm (a - c) b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b + (a - c + c) = a + b)) (sub_add_cancel a c)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b + a = a + b)) (add_comm b a))) (Eq.refl (a + b))))\n\n@[simp] theorem sub_add_sub_cancel' {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a - b + (c - a) = c - b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b + (c - a) = c - b)) (add_comm (a - b) (c - a))))\n    (sub_add_sub_cancel c a b)\n\n@[simp] theorem add_sub_sub_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    a + b - (a - c) = b + c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + b - (a - c) = b + c)) (Eq.symm (sub_add (a + b) a c))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + b - a + c = b + c)) (add_sub_cancel' a b)))\n      (Eq.refl (b + c)))\n\n@[simp] theorem sub_sub_sub_cancel_left {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) :\n    c - a - (c - b) = b - a :=\n  sorry\n\ntheorem sub_eq_sub_iff_add_eq_add {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} {d : G} :\n    a - b = c - d \u2194 a + d = c + b :=\n  sorry\n\ntheorem sub_eq_sub_iff_sub_eq_sub {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} {d : G} :\n    a - b = c - d \u2194 a - c = b - d :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/group/basic_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7194175680773163}}
{"text": "/-\nCopyright (c) 2022 Antoine Labelle. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Labelle\n\n! This file was ported from Lean 3 source module representation_theory.character\n! leanprover-community/mathlib commit 55b3f8206b8596db8bb1804d8a92814a0b6670c9\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.RepresentationTheory.FdRep\nimport Mathbin.LinearAlgebra.Trace\nimport Mathbin.RepresentationTheory.Invariants\n\n/-!\n# Characters of representations\n\nThis file introduces characters of representation and proves basic lemmas about how characters\nbehave under various operations on representations.\n\n# TODO\n* Once we have the monoidal closed structure on `fdRep k G` and a better API for the rigid\nstructure, `char_dual` and `char_lin_hom` should probably be stated in terms of `V\u1601` and `ihom V W`.\n-/\n\n\nnoncomputable section\n\nuniverse u\n\nopen CategoryTheory LinearMap CategoryTheory.MonoidalCategory Representation FiniteDimensional\n\nopen BigOperators\n\nvariable {k : Type u} [Field k]\n\nnamespace FdRep\n\nsection Monoid\n\nvariable {G : Type u} [Monoid G]\n\n/-- The character of a representation `V : fdRep k G` is the function associating to `g : G` the\ntrace of the linear map `V.\u03c1 g`.-/\ndef character (V : FdRep k G) (g : G) :=\n  LinearMap.trace k V (V.\u03c1 g)\n#align fdRep.character FdRep.character\n\ntheorem char_mul_comm (V : FdRep k G) (g : G) (h : G) : V.character (h * g) = V.character (g * h) :=\n  by simp only [trace_mul_comm, character, map_mul]\n#align fdRep.char_mul_comm FdRep.char_mul_comm\n\n@[simp]\ntheorem char_one (V : FdRep k G) : V.character 1 = FiniteDimensional.finrank k V := by\n  simp only [character, map_one, trace_one]\n#align fdRep.char_one FdRep.char_one\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/-- The character is multiplicative under the tensor product. -/\n@[simp]\ntheorem char_tensor (V W : FdRep k G) : (V \u2297 W).character = V.character * W.character :=\n  by\n  ext g\n  convert trace_tensor_product' (V.\u03c1 g) (W.\u03c1 g)\n#align fdRep.char_tensor FdRep.char_tensor\n\n/-- The character of isomorphic representations is the same. -/\ntheorem char_iso {V W : FdRep k G} (i : V \u2245 W) : V.character = W.character :=\n  by\n  ext g\n  simp only [character, FdRep.Iso.conj_\u03c1 i]\n  exact (trace_conj' (V.\u03c1 g) _).symm\n#align fdRep.char_iso FdRep.char_iso\n\nend Monoid\n\nsection Group\n\nvariable {G : Type u} [Group G]\n\n/-- The character of a representation is constant on conjugacy classes. -/\n@[simp]\ntheorem char_conj (V : FdRep k G) (g : G) (h : G) : V.character (h * g * h\u207b\u00b9) = V.character g := by\n  rw [char_mul_comm, inv_mul_cancel_left]\n#align fdRep.char_conj FdRep.char_conj\n\n@[simp]\ntheorem char_dual (V : FdRep k G) (g : G) : (of (dual V.\u03c1)).character g = V.character g\u207b\u00b9 :=\n  trace_transpose' (V.\u03c1 g\u207b\u00b9)\n#align fdRep.char_dual FdRep.char_dual\n\n@[simp]\ntheorem char_linHom (V W : FdRep k G) (g : G) :\n    (of (linHom V.\u03c1 W.\u03c1)).character g = V.character g\u207b\u00b9 * W.character g := by\n  rw [\u2190 char_iso (dual_tensor_iso_lin_hom _ _), char_tensor, Pi.mul_apply, char_dual]\n#align fdRep.char_lin_hom FdRep.char_linHom\n\nvariable [Fintype G] [Invertible (Fintype.card G : k)]\n\ntheorem average_char_eq_finrank_invariants (V : FdRep k G) :\n    (\u215f (Fintype.card G : k) \u2022 \u2211 g : G, V.character g) = finrank k (invariants V.\u03c1) :=\n  by\n  rw [\u2190 (is_proj_average_map V.\u03c1).trace]\n  simp [character, GroupAlgebra.average, _root_.map_sum]\n#align fdRep.average_char_eq_finrank_invariants FdRep.average_char_eq_finrank_invariants\n\nend Group\n\nsection Orthogonality\n\nvariable {G : GroupCat.{u}} [IsAlgClosed k]\n\nopen Classical\n\nvariable [Fintype G] [Invertible (Fintype.card G : k)]\n\n/-- Orthogonality of characters for irreducible representations of finite group over an\nalgebraically closed field whose characteristic doesn't divide the order of the group. -/\ntheorem char_orthonormal (V W : FdRep k G) [Simple V] [Simple W] :\n    (\u215f (Fintype.card G : k) \u2022 \u2211 g : G, V.character g * W.character g\u207b\u00b9) =\n      if Nonempty (V \u2245 W) then \u21911 else \u21910 :=\n  by\n  -- First, we can rewrite the summand `V.character g * W.character g\u207b\u00b9` as the character\n  -- of the representation `V \u2297 W* \u2245 Hom(W, V)` applied to `g`.\n  conv in\n    V.character _ *\n      W.character _ =>\n    rw [mul_comm, \u2190 char_dual, \u2190 Pi.mul_apply, \u2190 char_tensor]\n    rw [char_iso (FdRep.dualTensorIsoLinHom W.\u03c1 V)]\n  -- The average over the group of the character of a representation equals the dimension of the\n  -- space of invariants.\n  rw [average_char_eq_finrank_invariants]\n  rw [show (of (lin_hom W.\u03c1 V.\u03c1)).\u03c1 = lin_hom W.\u03c1 V.\u03c1 from FdRep.of_\u03c1 (lin_hom W.\u03c1 V.\u03c1)]\n  -- The space of invariants of `Hom(W, V)` is the subspace of `G`-equivariant linear maps,\n  -- `Hom_G(W, V)`.\n  rw [(lin_hom.invariants_equiv_fdRep_hom W V).finrank_eq]\n  -- By Schur's Lemma, the dimension of `Hom_G(W, V)` is `1` is `V \u2245 W` and `0` otherwise.\n  rw_mod_cast [finrank_hom_simple_simple W V, iso.nonempty_iso_symm]\n#align fdRep.char_orthonormal FdRep.char_orthonormal\n\nend Orthogonality\n\nend FdRep\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RepresentationTheory/Character.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.7194175651360362}}
{"text": "/-\nCopyright (c) 2020 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\n\nimport algebra.gcd_monoid.multiset\nimport combinatorics.partition\nimport group_theory.perm.cycle.basic\nimport ring_theory.int.basic\nimport tactic.linarith\n\n/-!\n# Cycle Types\n\nIn this file we define the cycle type of a permutation.\n\n## Main definitions\n\n- `\u03c3.cycle_type` where `\u03c3` is a permutation of a `fintype`\n- `\u03c3.partition` where `\u03c3` is a permutation of a `fintype`\n\n## Main results\n\n- `sum_cycle_type` : The sum of `\u03c3.cycle_type` equals `\u03c3.support.card`\n- `lcm_cycle_type` : The lcm of `\u03c3.cycle_type` equals `order_of \u03c3`\n- `is_conj_iff_cycle_type_eq` : Two permutations are conjugate if and only if they have the same\n  cycle type.\n- `exists_prime_order_of_dvd_card`: For every prime `p` dividing the order of a finite group `G`\n  there exists an element of order `p` in `G`. This is known as Cauchy's theorem.\n-/\n\nnamespace equiv.perm\nopen equiv list multiset\n\nvariables {\u03b1 : Type*} [fintype \u03b1]\n\nsection cycle_type\n\nvariables [decidable_eq \u03b1]\n\n/-- The cycle type of a permutation -/\ndef cycle_type (\u03c3 : perm \u03b1) : multiset \u2115 :=\n\u03c3.cycle_factors_finset.1.map (finset.card \u2218 support)\n\nlemma cycle_type_def (\u03c3 : perm \u03b1) :\n  \u03c3.cycle_type = \u03c3.cycle_factors_finset.1.map (finset.card \u2218 support) := rfl\n\nlemma cycle_type_eq' {\u03c3 : perm \u03b1} (s : finset (perm \u03b1))\n  (h1 : \u2200 f : perm \u03b1, f \u2208 s \u2192 f.is_cycle) (h2 : \u2200 (a \u2208 s) (b \u2208 s), a \u2260 b \u2192 disjoint a b)\n  (h0 : s.noncomm_prod id\n    (\u03bb a ha b hb, (em (a = b)).by_cases (\u03bb h, h \u25b8 commute.refl a)\n      (set.pairwise.mono' (\u03bb _ _, disjoint.commute) h2 ha hb)) = \u03c3) :\n  \u03c3.cycle_type = s.1.map (finset.card \u2218 support) :=\nbegin\n  rw cycle_type_def,\n  congr,\n  rw cycle_factors_finset_eq_finset,\n  exact \u27e8h1, h2, h0\u27e9\nend\n\nlemma cycle_type_eq {\u03c3 : perm \u03b1} (l : list (perm \u03b1)) (h0 : l.prod = \u03c3)\n  (h1 : \u2200 \u03c3 : perm \u03b1, \u03c3 \u2208 l \u2192 \u03c3.is_cycle) (h2 : l.pairwise disjoint) :\n  \u03c3.cycle_type = l.map (finset.card \u2218 support) :=\nbegin\n  have hl : l.nodup := nodup_of_pairwise_disjoint_cycles h1 h2,\n  rw cycle_type_eq' l.to_finset,\n  { simp [list.dedup_eq_self.mpr hl] },\n  { simpa using h1 },\n  { simpa [hl] using h0 },\n  { simpa [list.dedup_eq_self.mpr hl] using h2.forall disjoint.symmetric }\nend\n\nlemma cycle_type_one : (1 : perm \u03b1).cycle_type = 0 :=\ncycle_type_eq [] rfl (\u03bb _, false.elim) pairwise.nil\n\nlemma cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type = 0 \u2194 \u03c3 = 1 :=\nby simp [cycle_type_def, cycle_factors_finset_eq_empty_iff]\n\nlemma card_cycle_type_eq_zero {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 0 \u2194 \u03c3 = 1 :=\nby rw [card_eq_zero, cycle_type_eq_zero]\n\nlemma two_le_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 2 \u2264 n :=\nbegin\n  simp only [cycle_type_def, \u2190finset.mem_def, function.comp_app, multiset.mem_map,\n    mem_cycle_factors_finset_iff] at h,\n  obtain \u27e8_, \u27e8hc, -\u27e9, rfl\u27e9 := h,\n  exact hc.two_le_card_support\nend\n\nlemma one_lt_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : 1 < n :=\ntwo_le_of_mem_cycle_type h\n\nlemma is_cycle.cycle_type {\u03c3 : perm \u03b1} (h\u03c3 : is_cycle \u03c3) : \u03c3.cycle_type = [\u03c3.support.card] :=\ncycle_type_eq [\u03c3] (mul_one \u03c3) (\u03bb \u03c4 h\u03c4, (congr_arg is_cycle (list.mem_singleton.mp h\u03c4)).mpr h\u03c3)\n  (pairwise_singleton disjoint \u03c3)\n\nlemma card_cycle_type_eq_one {\u03c3 : perm \u03b1} : \u03c3.cycle_type.card = 1 \u2194 \u03c3.is_cycle :=\nbegin\n  rw card_eq_one,\n  simp_rw [cycle_type_def, multiset.map_eq_singleton, \u2190finset.singleton_val,\n           finset.val_inj, cycle_factors_finset_eq_singleton_iff],\n  split,\n  { rintro \u27e8_, _, \u27e8h, -\u27e9, -\u27e9,\n    exact h },\n  { intro h,\n    use [\u03c3.support.card, \u03c3],\n    simp [h] }\nend\n\nlemma disjoint.cycle_type {\u03c3 \u03c4 : perm \u03b1} (h : disjoint \u03c3 \u03c4) :\n  (\u03c3 * \u03c4).cycle_type = \u03c3.cycle_type + \u03c4.cycle_type :=\nbegin\n  rw [cycle_type_def, cycle_type_def, cycle_type_def, h.cycle_factors_finset_mul_eq_union,\n      \u2190multiset.map_add, finset.union_val, multiset.add_eq_union_iff_disjoint.mpr _],\n  rw [\u2190finset.disjoint_val],\n  exact h.disjoint_cycle_factors_finset\nend\n\nlemma cycle_type_inv (\u03c3 : perm \u03b1) : \u03c3\u207b\u00b9.cycle_type = \u03c3.cycle_type :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4\u207b\u00b9.cycle_type = \u03c4.cycle_type) \u03c3 rfl\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, h\u03c3.inv.cycle_type, support_inv])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [mul_inv_rev, h\u03c3\u03c4.cycle_type, \u2190h\u03c3, \u2190h\u03c4, add_comm,\n    disjoint.cycle_type (\u03bb x, or.imp (\u03bb h : \u03c4 x = x, inv_eq_iff_eq.mpr h.symm)\n    (\u03bb h : \u03c3 x = x, inv_eq_iff_eq.mpr h.symm) (h\u03c3\u03c4 x).symm)])\n\nlemma cycle_type_conj {\u03c3 \u03c4 : perm \u03b1} : (\u03c4 * \u03c3 * \u03c4\u207b\u00b9).cycle_type = \u03c3.cycle_type :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intro,\n    simp },\n  { intros \u03c3 h\u03c3 \u03c4,\n    rw [h\u03c3.cycle_type, h\u03c3.is_cycle_conj.cycle_type, card_support_conj] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4 \u03c0,\n    rw [\u2190 conj_mul, hd.cycle_type, disjoint.cycle_type, h\u03c3, h\u03c4],\n    intro a,\n    apply (hd (\u03c0\u207b\u00b9 a)).imp _ _;\n    { intro h, rw [perm.mul_apply, perm.mul_apply, h, apply_inv_self] } }\nend\n\nlemma sum_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.sum = \u03c3.support.card :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.sum = \u03c4.support.card) \u03c3\n  (by rw [cycle_type_one, sum_zero, support_one, finset.card_empty])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, coe_sum, list.sum_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, sum_add, h\u03c3, h\u03c4, h\u03c3\u03c4.card_support_mul])\n\nlemma sign_of_cycle_type' (\u03c3 : perm \u03b1) :\n  sign \u03c3 = (\u03c3.cycle_type.map (\u03bb n, -(-1 : \u2124\u02e3) ^ n)).prod :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, sign \u03c4 = (\u03c4.cycle_type.map (\u03bb n, -(-1 : \u2124\u02e3) ^ n)).prod) \u03c3\n  (by rw [sign_one, cycle_type_one, multiset.map_zero, prod_zero])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.sign, h\u03c3.cycle_type, coe_map, coe_prod,\n    list.map_singleton, list.prod_singleton])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [sign_mul, h\u03c3, h\u03c4, h\u03c3\u03c4.cycle_type, multiset.map_add, prod_add])\n\nlemma sign_of_cycle_type (f : perm \u03b1) :\n  sign f = (-1 : \u2124\u02e3)^(f.cycle_type.sum + f.cycle_type.card) :=\ncycle_induction_on\n  (\u03bb f : perm \u03b1, sign f = (-1 : \u2124\u02e3)^(f.cycle_type.sum + f.cycle_type.card))\n  f\n  ( -- base_one\n    by rw [equiv.perm.cycle_type_one, sign_one, multiset.sum_zero, multiset.card_zero, pow_zero] )\n  ( -- base_cycles\n    \u03bb f hf,\n      by rw [equiv.perm.is_cycle.cycle_type hf, hf.sign,\n      coe_sum, list.sum_cons, sum_nil, add_zero, coe_card, length_singleton,\n      pow_add, pow_one, mul_comm, neg_mul, one_mul] )\n  ( -- induction_disjoint\n    \u03bb f g hfg hf Pf Pg,\n    by rw [equiv.perm.disjoint.cycle_type hfg,\n      multiset.sum_add, multiset.card_add,\u2190 add_assoc,\n      add_comm f.cycle_type.sum g.cycle_type.sum,\n      add_assoc g.cycle_type.sum _ _,\n      add_comm g.cycle_type.sum _,\n      add_assoc, pow_add,\n      \u2190 Pf, \u2190 Pg,\n      equiv.perm.sign_mul])\n\nlemma lcm_cycle_type (\u03c3 : perm \u03b1) : \u03c3.cycle_type.lcm = order_of \u03c3 :=\ncycle_induction_on (\u03bb \u03c4 : perm \u03b1, \u03c4.cycle_type.lcm = order_of \u03c4) \u03c3\n  (by rw [cycle_type_one, lcm_zero, order_of_one])\n  (\u03bb \u03c3 h\u03c3, by rw [h\u03c3.cycle_type, \u2190singleton_coe, \u2190singleton_eq_cons, lcm_singleton,\n    order_of_is_cycle h\u03c3, normalize_eq])\n  (\u03bb \u03c3 \u03c4 h\u03c3\u03c4 hc h\u03c3 h\u03c4, by rw [h\u03c3\u03c4.cycle_type, lcm_add, lcm_eq_nat_lcm, h\u03c3\u03c4.order_of, h\u03c3, h\u03c4])\n\nlemma dvd_of_mem_cycle_type {\u03c3 : perm \u03b1} {n : \u2115} (h : n \u2208 \u03c3.cycle_type) : n \u2223 order_of \u03c3 :=\nbegin\n  rw \u2190 lcm_cycle_type,\n  exact dvd_lcm h,\nend\n\nlemma order_of_cycle_of_dvd_order_of (f : perm \u03b1) (x : \u03b1) :\n  order_of (cycle_of f x) \u2223 order_of f :=\nbegin\n  by_cases hx : f x = x,\n  { rw \u2190cycle_of_eq_one_iff at hx,\n    simp [hx] },\n  { refine dvd_of_mem_cycle_type _,\n    rw [cycle_type, multiset.mem_map],\n    refine \u27e8f.cycle_of x, _, _\u27e9,\n    { rwa [\u2190finset.mem_def, cycle_of_mem_cycle_factors_finset_iff, mem_support] },\n    { simp [order_of_is_cycle (is_cycle_cycle_of _ hx)] } }\nend\n\nlemma two_dvd_card_support {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ 2 = 1) : 2 \u2223 \u03c3.support.card :=\n(congr_arg (has_dvd.dvd 2) \u03c3.sum_cycle_type).mp\n  (multiset.dvd_sum (\u03bb n hn, by rw le_antisymm (nat.le_of_dvd zero_lt_two $\n  (dvd_of_mem_cycle_type hn).trans $ order_of_dvd_of_pow_eq_one h\u03c3) (two_le_of_mem_cycle_type hn)))\n\nlemma cycle_type_prime_order {\u03c3 : perm \u03b1} (h\u03c3 : (order_of \u03c3).prime) :\n  \u2203 n : \u2115, \u03c3.cycle_type = repeat (order_of \u03c3) (n + 1) :=\nbegin\n  rw eq_repeat_of_mem (\u03bb n hn, or_iff_not_imp_left.mp\n    (h\u03c3.eq_one_or_self_of_dvd n (dvd_of_mem_cycle_type hn)) (one_lt_of_mem_cycle_type hn).ne'),\n  use \u03c3.cycle_type.card - 1,\n  rw tsub_add_cancel_of_le,\n  rw [nat.succ_le_iff, pos_iff_ne_zero, ne, card_cycle_type_eq_zero],\n  intro H,\n  rw [H, order_of_one] at h\u03c3,\n  exact h\u03c3.ne_one rfl,\nend\n\nlemma is_cycle_of_prime_order {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : \u03c3.support.card < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  obtain \u27e8n, hn\u27e9 := cycle_type_prime_order h1,\n  rw [\u2190\u03c3.sum_cycle_type, hn, multiset.sum_repeat, nsmul_eq_mul, nat.cast_id, mul_lt_mul_right\n      (order_of_pos \u03c3), nat.succ_lt_succ_iff, nat.lt_succ_iff, nat.le_zero_iff] at h2,\n  rw [\u2190card_cycle_type_eq_one, hn, card_repeat, h2],\nend\n\nlemma cycle_type_le_of_mem_cycle_factors_finset {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  f.cycle_type \u2264 g.cycle_type :=\nbegin\n  rw mem_cycle_factors_finset_iff at hf,\n  rw [cycle_type_def, cycle_type_def, hf.left.cycle_factors_finset_eq_singleton],\n  refine map_le_map _,\n  simpa [\u2190finset.mem_def, mem_cycle_factors_finset_iff] using hf\nend\n\nlemma cycle_type_mul_mem_cycle_factors_finset_eq_sub {f g : perm \u03b1}\n  (hf : f \u2208 g.cycle_factors_finset) :\n  (g * f\u207b\u00b9).cycle_type = g.cycle_type - f.cycle_type :=\nbegin\n  suffices : (g * f\u207b\u00b9).cycle_type + f.cycle_type = g.cycle_type - f.cycle_type + f.cycle_type,\n  { rw tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf) at this,\n    simp [\u2190this] },\n  simp [\u2190(disjoint_mul_inv_of_mem_cycle_factors_finset hf).cycle_type,\n    tsub_add_cancel_of_le (cycle_type_le_of_mem_cycle_factors_finset hf)]\nend\n\ntheorem is_conj_of_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} (h : cycle_type \u03c3 = cycle_type \u03c4) : is_conj \u03c3 \u03c4 :=\nbegin\n  revert \u03c4,\n  apply cycle_induction_on _ \u03c3,\n  { intros \u03c4 h,\n    rw [cycle_type_one, eq_comm, cycle_type_eq_zero] at h,\n    rw h },\n  { intros \u03c3 h\u03c3 \u03c4 h\u03c3\u03c4,\n    have h\u03c4 := card_cycle_type_eq_one.2 h\u03c3,\n    rw [h\u03c3\u03c4, card_cycle_type_eq_one] at h\u03c4,\n    apply h\u03c3.is_conj h\u03c4,\n    rw [h\u03c3.cycle_type, h\u03c4.cycle_type, coe_eq_coe, singleton_perm] at h\u03c3\u03c4,\n    simp only [and_true, eq_self_iff_true] at h\u03c3\u03c4,\n    exact h\u03c3\u03c4 },\n  { intros \u03c3 \u03c4 h\u03c3\u03c4 h\u03c3 h1 h2 \u03c0 h\u03c0,\n    rw [h\u03c3\u03c4.cycle_type] at h\u03c0,\n    { have h : \u03c3.support.card \u2208 map (finset.card \u2218 perm.support) \u03c0.cycle_factors_finset.val,\n      { simp [\u2190cycle_type_def, \u2190h\u03c0, h\u03c3.cycle_type] },\n      obtain \u27e8\u03c3', h\u03c3'l, h\u03c3'\u27e9 := multiset.mem_map.mp h,\n      have key : is_conj (\u03c3' * (\u03c0 * \u03c3'\u207b\u00b9)) \u03c0,\n      { rw is_conj_iff,\n        use \u03c3'\u207b\u00b9,\n        simp [mul_assoc] },\n      refine is_conj.trans _ key,\n      have hs : \u03c3.cycle_type = \u03c3'.cycle_type,\n      { rw [\u2190finset.mem_def, mem_cycle_factors_finset_iff] at h\u03c3'l,\n        rw [h\u03c3.cycle_type, \u2190h\u03c3', h\u03c3'l.left.cycle_type] },\n      refine h\u03c3\u03c4.is_conj_mul (h1 hs) (h2 _) _,\n      { rw [cycle_type_mul_mem_cycle_factors_finset_eq_sub, \u2190h\u03c0, add_comm, hs,\n            add_tsub_cancel_right],\n        rwa finset.mem_def },\n      { exact (disjoint_mul_inv_of_mem_cycle_factors_finset h\u03c3'l).symm } } }\nend\n\ntheorem is_conj_iff_cycle_type_eq {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.cycle_type = \u03c4.cycle_type :=\n\u27e8\u03bb h, begin\n  obtain \u27e8\u03c0, rfl\u27e9 := is_conj_iff.1 h,\n  rw cycle_type_conj,\nend, is_conj_of_cycle_type_eq\u27e9\n\n@[simp] lemma cycle_type_extend_domain {\u03b2 : Type*} [fintype \u03b2] [decidable_eq \u03b2]\n  {p : \u03b2 \u2192 Prop} [decidable_pred p] (f : \u03b1 \u2243 subtype p) {g : perm \u03b1} :\n  cycle_type (g.extend_domain f) = cycle_type g :=\nbegin\n  apply cycle_induction_on _ g,\n  { rw [extend_domain_one, cycle_type_one, cycle_type_one] },\n  { intros \u03c3 h\u03c3,\n    rw [(h\u03c3.extend_domain f).cycle_type, h\u03c3.cycle_type, card_support_extend_domain] },\n  { intros \u03c3 \u03c4 hd hc h\u03c3 h\u03c4,\n    rw [hd.cycle_type, \u2190 extend_domain_mul, (hd.extend_domain f).cycle_type, h\u03c3, h\u03c4] }\nend\n\nlemma mem_cycle_type_iff {n : \u2115} {\u03c3 : perm \u03b1} :\n  n \u2208 cycle_type \u03c3 \u2194 \u2203 c \u03c4 : perm \u03b1, \u03c3 = c * \u03c4 \u2227 disjoint c \u03c4 \u2227 is_cycle c \u2227 c.support.card = n :=\nbegin\n  split,\n  { intro h,\n    obtain \u27e8l, rfl, hlc, hld\u27e9 := trunc_cycle_factors \u03c3,\n    rw cycle_type_eq _ rfl hlc hld at h,\n    obtain \u27e8c, cl, rfl\u27e9 := list.exists_of_mem_map h,\n    rw (list.perm_cons_erase cl).pairwise_iff (\u03bb _ _ hd, _) at hld,\n    swap, { exact hd.symm },\n    refine \u27e8c, (l.erase c).prod, _, _, hlc _ cl, rfl\u27e9,\n    { rw [\u2190 list.prod_cons,\n        (list.perm_cons_erase cl).symm.prod_eq' (hld.imp (\u03bb _ _, disjoint.commute))] },\n    { exact disjoint_prod_right _ (\u03bb g, list.rel_of_pairwise_cons hld) } },\n  { rintros \u27e8c, t, rfl, hd, hc, rfl\u27e9,\n    simp [hd.cycle_type, hc.cycle_type] }\nend\n\nlemma le_card_support_of_mem_cycle_type {n : \u2115} {\u03c3 : perm \u03b1} (h : n \u2208 cycle_type \u03c3) :\n  n \u2264 \u03c3.support.card :=\n(le_sum_of_mem h).trans (le_of_eq \u03c3.sum_cycle_type)\n\nlemma cycle_type_of_card_le_mem_cycle_type_add_two {n : \u2115} {g : perm \u03b1}\n  (hn2 : fintype.card \u03b1 < n + 2) (hng : n \u2208 g.cycle_type) :\n  g.cycle_type = {n} :=\nbegin\n  obtain \u27e8c, g', rfl, hd, hc, rfl\u27e9 := mem_cycle_type_iff.1 hng,\n  by_cases g'1 : g' = 1,\n  { rw [hd.cycle_type, hc.cycle_type, multiset.singleton_eq_cons, multiset.singleton_coe,\n      g'1, cycle_type_one, add_zero] },\n  contrapose! hn2,\n  apply le_trans _ (c * g').support.card_le_univ,\n  rw [hd.card_support_mul],\n  exact add_le_add_left (two_le_card_support_of_ne_one g'1) _,\nend\n\nend cycle_type\n\nlemma card_compl_support_modeq [decidable_eq \u03b1] {p n : \u2115} [hp : fact p.prime] {\u03c3 : perm \u03b1}\n  (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u03c3.support\u1d9c.card \u2261 fintype.card \u03b1 [MOD p] :=\nbegin\n  rw [nat.modeq_iff_dvd' \u03c3.support\u1d9c.card_le_univ, \u2190finset.card_compl, compl_compl],\n  refine (congr_arg _ \u03c3.sum_cycle_type).mp (multiset.dvd_sum (\u03bb k hk, _)),\n  obtain \u27e8m, -, hm\u27e9 := (nat.dvd_prime_pow hp.out).mp (order_of_dvd_of_pow_eq_one h\u03c3),\n  obtain \u27e8l, -, rfl\u27e9 := (nat.dvd_prime_pow hp.out).mp\n    ((congr_arg _ hm).mp (dvd_of_mem_cycle_type hk)),\n  exact dvd_pow_self _ (\u03bb h, (one_lt_of_mem_cycle_type hk).ne $ by rw [h, pow_zero]),\nend\n\nlemma exists_fixed_point_of_prime {p n : \u2115} [hp : fact p.prime] (h\u03b1 : \u00ac p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) : \u2203 a : \u03b1, \u03c3 a = a :=\nbegin\n  classical,\n  contrapose! h\u03b1,\n  simp_rw \u2190 mem_support at h\u03b1,\n  exact nat.modeq_zero_iff_dvd.mp ((congr_arg _ (finset.card_eq_zero.mpr (compl_eq_bot.mpr\n    (finset.eq_univ_iff_forall.mpr h\u03b1)))).mp (card_compl_support_modeq h\u03c3).symm),\nend\n\nlemma exists_fixed_point_of_prime' {p n : \u2115} [hp : fact p.prime] (h\u03b1 : p \u2223 fintype.card \u03b1)\n  {\u03c3 : perm \u03b1} (h\u03c3 : \u03c3 ^ p ^ n = 1) {a : \u03b1} (ha : \u03c3 a = a) : \u2203 b : \u03b1, \u03c3 b = b \u2227 b \u2260 a :=\nbegin\n  classical,\n  have h : \u2200 b : \u03b1, b \u2208 \u03c3.support\u1d9c \u2194 \u03c3 b = b :=\n  \u03bb b, by rw [finset.mem_compl, mem_support, not_not],\n  obtain \u27e8b, hb1, hb2\u27e9 := finset.exists_ne_of_one_lt_card (lt_of_lt_of_le hp.out.one_lt\n    (nat.le_of_dvd (finset.card_pos.mpr \u27e8a, (h a).mpr ha\u27e9) (nat.modeq_zero_iff_dvd.mp\n    ((card_compl_support_modeq h\u03c3).trans (nat.modeq_zero_iff_dvd.mpr h\u03b1))))) a,\n  exact \u27e8b, (h b).mp hb1, hb2\u27e9,\nend\n\nlemma is_cycle_of_prime_order' {\u03c3 : perm \u03b1} (h1 : (order_of \u03c3).prime)\n  (h2 : fintype.card \u03b1 < 2 * (order_of \u03c3)) : \u03c3.is_cycle :=\nbegin\n  classical,\n  exact is_cycle_of_prime_order h1 (lt_of_le_of_lt \u03c3.support.card_le_univ h2),\nend\n\n\n\nsection cauchy\n\nvariables (G : Type*) [group G] (n : \u2115)\n\n/-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/\ndef vectors_prod_eq_one : set (vector G n) :=\n{v | v.to_list.prod = 1}\n\nnamespace vectors_prod_eq_one\n\nlemma mem_iff {n : \u2115} (v : vector G n) :\nv \u2208 vectors_prod_eq_one G n \u2194 v.to_list.prod = 1 := iff.rfl\n\nlemma zero_eq : vectors_prod_eq_one G 0 = {vector.nil} :=\nset.eq_singleton_iff_unique_mem.mpr \u27e8eq.refl (1 : G), \u03bb v hv, v.eq_nil\u27e9\n\nlemma one_eq : vectors_prod_eq_one G 1 = {vector.nil.cons 1} :=\nbegin\n  simp_rw [set.eq_singleton_iff_unique_mem, mem_iff,\n    vector.to_list_singleton, list.prod_singleton, vector.head_cons],\n  exact \u27e8rfl, \u03bb v hv, v.cons_head_tail.symm.trans (congr_arg2 vector.cons hv v.tail.eq_nil)\u27e9,\nend\n\ninstance zero_unique : unique (vectors_prod_eq_one G 0) :=\nby { rw zero_eq, exact set.unique_singleton vector.nil }\n\ninstance one_unique : unique (vectors_prod_eq_one G 1) :=\nby { rw one_eq, exact set.unique_singleton (vector.nil.cons 1) }\n\n/-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`,\nby appending the inverse of the product of `v`. -/\n@[simps] def vector_equiv : vector G n \u2243 vectors_prod_eq_one G (n + 1) :=\n{ to_fun := \u03bb v, \u27e8v.to_list.prod\u207b\u00b9 ::\u1d65 v,\n    by rw [mem_iff, vector.to_list_cons, list.prod_cons, inv_mul_self]\u27e9,\n  inv_fun := \u03bb v, v.1.tail,\n  left_inv := \u03bb v, v.tail_cons v.to_list.prod\u207b\u00b9,\n  right_inv := \u03bb v, subtype.ext ((congr_arg2 vector.cons (eq_inv_of_mul_eq_one_left (by\n  { rw [\u2190list.prod_cons, \u2190vector.to_list_cons, v.1.cons_head_tail],\n    exact v.2 })).symm rfl).trans v.1.cons_head_tail) }\n\n/-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`,\nby deleting the last entry of `v`. -/\ndef equiv_vector : vectors_prod_eq_one G n \u2243 vector G (n - 1) :=\n((vector_equiv G (n - 1)).trans (if hn : n = 0 then (show vectors_prod_eq_one G (n - 1 + 1) \u2243\n  vectors_prod_eq_one G n, by { rw hn, apply equiv_of_unique })\n  else by rw tsub_add_cancel_of_le (nat.pos_of_ne_zero hn).nat_succ_le)).symm\n\ninstance [fintype G] : fintype (vectors_prod_eq_one G n) :=\nfintype.of_equiv (vector G (n - 1)) (equiv_vector G n).symm\n\nlemma card [fintype G] :\n  fintype.card (vectors_prod_eq_one G n) = fintype.card G ^ (n - 1) :=\n(fintype.card_congr (equiv_vector G n)).trans (card_vector (n - 1))\n\nvariables {G n} {g : G} (v : vectors_prod_eq_one G n) (j k : \u2115)\n\n/-- Rotate a vector whose product is 1. -/\ndef rotate : vectors_prod_eq_one G n :=\n\u27e8\u27e8_, (v.1.1.length_rotate k).trans v.1.2\u27e9, list.prod_rotate_eq_one_of_prod_eq_one v.2 k\u27e9\n\nlemma rotate_zero : rotate v 0 = v :=\nsubtype.ext (subtype.ext v.1.1.rotate_zero)\n\nlemma rotate_rotate : rotate (rotate v j) k = rotate v (j + k) :=\nsubtype.ext (subtype.ext (v.1.1.rotate_rotate j k))\n\nlemma rotate_length : rotate v n = v :=\nsubtype.ext (subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length))\n\nend vectors_prod_eq_one\n\n/-- For every prime `p` dividing the order of a finite group `G` there exists an element of order\n`p` in `G`. This is known as Cauchy's theorem. -/\nlemma _root_.exists_prime_order_of_dvd_card {G : Type*} [group G] [fintype G] (p : \u2115)\n  [hp : fact p.prime] (hdvd : p \u2223 fintype.card G) : \u2203 x : G, order_of x = p :=\nbegin\n  have hp' : p - 1 \u2260 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_lt hp.out.one_lt),\n  have Scard := calc p \u2223 fintype.card G ^ (p - 1) : hdvd.trans (dvd_pow (dvd_refl _) hp')\n  ... = fintype.card (vectors_prod_eq_one G p) : (vectors_prod_eq_one.card G p).symm,\n  let f : \u2115 \u2192 vectors_prod_eq_one G p \u2192 vectors_prod_eq_one G p :=\n  \u03bb k v, vectors_prod_eq_one.rotate v k,\n  have hf1 : \u2200 v, f 0 v = v := vectors_prod_eq_one.rotate_zero,\n  have hf2 : \u2200 j k v, f k (f j v) = f (j + k) v :=\n  \u03bb j k v, vectors_prod_eq_one.rotate_rotate v j k,\n  have hf3 : \u2200 v, f p v = v := vectors_prod_eq_one.rotate_length,\n  let \u03c3 := equiv.mk (f 1) (f (p - 1))\n    (\u03bb s, by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3])\n    (\u03bb s, by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3]),\n  have h\u03c3 : \u2200 k v, (\u03c3 ^ k) v = f k v :=\n  \u03bb k v, nat.rec (hf1 v).symm (\u03bb k hk, eq.trans (by exact congr_arg \u03c3 hk) (hf2 k 1 v)) k,\n  replace h\u03c3 : \u03c3 ^ (p ^ 1) = 1 := perm.ext (\u03bb v, by rw [pow_one, h\u03c3, hf3, one_apply]),\n  let v\u2080 : vectors_prod_eq_one G p := \u27e8vector.repeat 1 p, (list.prod_repeat 1 p).trans (one_pow p)\u27e9,\n  have hv\u2080 : \u03c3 v\u2080 = v\u2080 := subtype.ext (subtype.ext (list.rotate_repeat (1 : G) p 1)),\n  obtain \u27e8v, hv1, hv2\u27e9 := exists_fixed_point_of_prime' Scard h\u03c3 hv\u2080,\n  refine exists_imp_exists (\u03bb g hg, order_of_eq_prime _ (\u03bb hg', hv2 _))\n    (list.rotate_one_eq_self_iff_eq_repeat.mp (subtype.ext_iff.mp (subtype.ext_iff.mp hv1))),\n  { rw [\u2190list.prod_repeat, \u2190v.1.2, \u2190hg, (show v.val.val.prod = 1, from v.2)] },\n  { rw [subtype.ext_iff_val, subtype.ext_iff_val, hg, hg', v.1.2],\n    refl },\nend\n\n/-- For every prime `p` dividing the order of a finite additive group `G` there exists an element of\norder `p` in `G`. This is the additive version of Cauchy's theorem. -/\nlemma _root_.exists_prime_add_order_of_dvd_card {G : Type*} [add_group G] [fintype G] (p : \u2115)\n  [hp : fact p.prime] (hdvd : p \u2223 fintype.card G) : \u2203 x : G, add_order_of x = p :=\n@exists_prime_order_of_dvd_card (multiplicative G) _ _ _ _ hdvd\n\nattribute [to_additive exists_prime_add_order_of_dvd_card] exists_prime_order_of_dvd_card\n\nend cauchy\n\nlemma subgroup_eq_top_of_swap_mem [decidable_eq \u03b1] {H : subgroup (perm \u03b1)}\n  [d : decidable_pred (\u2208 H)] {\u03c4 : perm \u03b1} (h0 : (fintype.card \u03b1).prime)\n  (h1 : fintype.card \u03b1 \u2223 fintype.card H) (h2 : \u03c4 \u2208 H) (h3 : is_swap \u03c4) :\n  H = \u22a4 :=\nbegin\n  haveI : fact (fintype.card \u03b1).prime := \u27e8h0\u27e9,\n  obtain \u27e8\u03c3, h\u03c3\u27e9 := exists_prime_order_of_dvd_card (fintype.card \u03b1) h1,\n  have h\u03c31 : order_of (\u03c3 : perm \u03b1) = fintype.card \u03b1 := (order_of_subgroup \u03c3).trans h\u03c3,\n  have h\u03c32 : is_cycle \u2191\u03c3 := is_cycle_of_prime_order'' h0 h\u03c31,\n  have h\u03c33 : (\u03c3 : perm \u03b1).support = \u22a4 :=\n    finset.eq_univ_of_card (\u03c3 : perm \u03b1).support ((order_of_is_cycle h\u03c32).symm.trans h\u03c31),\n  have h\u03c34 : subgroup.closure {\u2191\u03c3, \u03c4} = \u22a4 := closure_prime_cycle_swap h0 h\u03c32 h\u03c33 h3,\n  rw [eq_top_iff, \u2190h\u03c34, subgroup.closure_le, set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8subtype.mem \u03c3, h2\u27e9,\nend\n\nsection partition\n\nvariables [decidable_eq \u03b1]\n\n/-- The partition corresponding to a permutation -/\ndef partition (\u03c3 : perm \u03b1) : (fintype.card \u03b1).partition :=\n{ parts := \u03c3.cycle_type + repeat 1 (fintype.card \u03b1 - \u03c3.support.card),\n  parts_pos := \u03bb n hn,\n  begin\n    cases mem_add.mp hn with hn hn,\n    { exact zero_lt_one.trans (one_lt_of_mem_cycle_type hn) },\n    { exact lt_of_lt_of_le zero_lt_one (ge_of_eq (multiset.eq_of_mem_repeat hn)) },\n  end,\n  parts_sum := by rw [sum_add, sum_cycle_type, multiset.sum_repeat, nsmul_eq_mul,\n    nat.cast_id, mul_one, add_tsub_cancel_of_le \u03c3.support.card_le_univ] }\n\nlemma parts_partition {\u03c3 : perm \u03b1} :\n  \u03c3.partition.parts = \u03c3.cycle_type + repeat 1 (fintype.card \u03b1 - \u03c3.support.card) := rfl\n\nlemma filter_parts_partition_eq_cycle_type {\u03c3 : perm \u03b1} :\n  (partition \u03c3).parts.filter (\u03bb n, 2 \u2264 n) = \u03c3.cycle_type :=\nbegin\n  rw [parts_partition, filter_add, multiset.filter_eq_self.2 (\u03bb _, two_le_of_mem_cycle_type),\n    multiset.filter_eq_nil.2 (\u03bb a h, _), add_zero],\n  rw multiset.eq_of_mem_repeat h,\n  dec_trivial\nend\n\nlemma partition_eq_of_is_conj {\u03c3 \u03c4 : perm \u03b1} :\n  is_conj \u03c3 \u03c4 \u2194 \u03c3.partition = \u03c4.partition :=\nbegin\n  rw [is_conj_iff_cycle_type_eq],\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rw [nat.partition.ext_iff, parts_partition, parts_partition,\n      \u2190 sum_cycle_type, \u2190 sum_cycle_type, h] },\n  { rw [\u2190 filter_parts_partition_eq_cycle_type, \u2190 filter_parts_partition_eq_cycle_type, h] }\nend\n\nend partition\n\n/-!\n### 3-cycles\n-/\n\n/-- A three-cycle is a cycle of length 3. -/\ndef is_three_cycle [decidable_eq \u03b1] (\u03c3 : perm \u03b1) : Prop := \u03c3.cycle_type = {3}\n\nnamespace is_three_cycle\n\nvariables [decidable_eq \u03b1] {\u03c3 : perm \u03b1}\n\nlemma cycle_type (h : is_three_cycle \u03c3) : \u03c3.cycle_type = {3} := h\n\nlemma card_support (h : is_three_cycle \u03c3) : \u03c3.support.card = 3 :=\nby rw [\u2190sum_cycle_type, h.cycle_type, multiset.sum_singleton]\n\nlemma _root_.card_support_eq_three_iff : \u03c3.support.card = 3 \u2194 \u03c3.is_three_cycle :=\nbegin\n  refine \u27e8\u03bb h, _, is_three_cycle.card_support\u27e9,\n  by_cases h0 : \u03c3.cycle_type = 0,\n  { rw [\u2190sum_cycle_type, h0, sum_zero] at h,\n    exact (ne_of_lt zero_lt_three h).elim },\n  obtain \u27e8n, hn\u27e9 := exists_mem_of_ne_zero h0,\n  by_cases h1 : \u03c3.cycle_type.erase n = 0,\n  { rw [\u2190sum_cycle_type, \u2190cons_erase hn, h1, \u2190singleton_eq_cons, multiset.sum_singleton] at h,\n    rw [is_three_cycle, \u2190cons_erase hn, h1, h, singleton_eq_cons] },\n  obtain \u27e8m, hm\u27e9 := exists_mem_of_ne_zero h1,\n  rw [\u2190sum_cycle_type, \u2190cons_erase hn, \u2190cons_erase hm, multiset.sum_cons, multiset.sum_cons] at h,\n  -- TODO: linarith [...] should solve this directly\n  have : \u2200 {k}, 2 \u2264 m \u2192 2 \u2264 n \u2192 n + (m + k) = 3 \u2192 false, { intros, linarith },\n  cases this (two_le_of_mem_cycle_type (mem_of_mem_erase hm)) (two_le_of_mem_cycle_type hn) h,\nend\n\nlemma is_cycle (h : is_three_cycle \u03c3) : is_cycle \u03c3 :=\nby rw [\u2190card_cycle_type_eq_one, h.cycle_type, card_singleton]\n\nlemma sign (h : is_three_cycle \u03c3) : sign \u03c3 = 1 :=\nbegin\n  rw [equiv.perm.sign_of_cycle_type, h.cycle_type],\n  refl,\nend\n\nlemma inv {f : perm \u03b1} (h : is_three_cycle f) : is_three_cycle (f\u207b\u00b9) :=\nby rwa [is_three_cycle, cycle_type_inv]\n\n@[simp] lemma inv_iff {f : perm \u03b1} : is_three_cycle (f\u207b\u00b9) \u2194 is_three_cycle f :=\n\u27e8by { rw \u2190 inv_inv f, apply inv }, inv\u27e9\n\nlemma order_of {g : perm \u03b1} (ht : is_three_cycle g) :\n  order_of g = 3 :=\nby rw [\u2190lcm_cycle_type, ht.cycle_type, multiset.lcm_singleton, normalize_eq]\n\nlemma is_three_cycle_sq {g : perm \u03b1} (ht : is_three_cycle g) :\n  is_three_cycle (g * g) :=\nbegin\n  rw [\u2190pow_two, \u2190card_support_eq_three_iff, support_pow_coprime, ht.card_support],\n  rw [ht.order_of, nat.coprime_iff_gcd_eq_one],\n  norm_num,\nend\n\nend is_three_cycle\n\nsection\nvariable [decidable_eq \u03b1]\n\nlemma is_three_cycle_swap_mul_swap_same\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) (bc : b \u2260 c) :\n  is_three_cycle (swap a b * swap a c) :=\nbegin\n  suffices h : support (swap a b * swap a c) = {a, b, c},\n  { rw [\u2190card_support_eq_three_iff, h],\n    simp [ab, ac, bc] },\n  apply le_antisymm ((support_mul_le _ _).trans (\u03bb x, _)) (\u03bb x hx, _),\n  { simp [ab, ac, bc] },\n  { simp only [finset.mem_insert, finset.mem_singleton] at hx,\n    rw mem_support,\n    simp only [perm.coe_mul, function.comp_app, ne.def],\n    obtain rfl | rfl | rfl := hx,\n    { rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm],\n      exact ac.symm },\n    { rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right],\n      exact ab },\n    { rw [swap_apply_right, swap_apply_left],\n      exact bc } }\nend\n\nopen subgroup\n\nlemma swap_mul_swap_same_mem_closure_three_cycles\n  {a b c : \u03b1} (ab : a \u2260 b) (ac : a \u2260 c) :\n  (swap a b * swap a c) \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  by_cases bc : b = c,\n  { subst bc,\n    simp [one_mem] },\n  exact subset_closure (is_three_cycle_swap_mul_swap_same ab ac bc)\nend\n\nlemma is_swap.mul_mem_closure_three_cycles {\u03c3 \u03c4 : perm \u03b1}\n  (h\u03c3 : is_swap \u03c3) (h\u03c4 : is_swap \u03c4) :\n  \u03c3 * \u03c4 \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3 } :=\nbegin\n  obtain \u27e8a, b, ab, rfl\u27e9 := h\u03c3,\n  obtain \u27e8c, d, cd, rfl\u27e9 := h\u03c4,\n  by_cases ac : a = c,\n  { subst ac,\n    exact swap_mul_swap_same_mem_closure_three_cycles ab cd },\n  have h' : swap a b * swap c d = swap a b * swap a c * (swap c a * swap c d),\n  { simp [swap_comm c a, mul_assoc] },\n  rw h',\n  exact mul_mem (swap_mul_swap_same_mem_closure_three_cycles ab ac)\n    (swap_mul_swap_same_mem_closure_three_cycles (ne.symm ac) cd),\nend\n\nend\n\nend equiv.perm\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/group_theory/perm/cycle/type.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7193838637226035}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.filter.at_top_bot\nimport Mathlib.algebra.archimedean\nimport Mathlib.PostPort\n\nuniverses u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# `at_top` filter and archimedean (semi)rings/fields\n\nIn this file we prove that for a linear ordered archimedean semiring `R` and a function `f : \u03b1 \u2192 \u2115`,\nthe function `coe \u2218 f : \u03b1 \u2192 R` tends to `at_top` along a filter `l` if and only if so does `f`.\nWe also prove that `coe : \u2115 \u2192 R` tends to `at_top` along `at_top`, as well as version of these\ntwo results for `\u2124` (and a ring `R`) and `\u211a` (and a field `R`).\n-/\n\ntheorem tendsto_coe_nat_at_top_iff {\u03b1 : Type u_1} {R : Type u_2} [ordered_semiring R] [nontrivial R]\n    [archimedean R] {f : \u03b1 \u2192 \u2115} {l : filter \u03b1} :\n    filter.tendsto (fun (n : \u03b1) => \u2191(f n)) l filter.at_top \u2194 filter.tendsto f l filter.at_top :=\n  filter.tendsto_at_top_embedding (fun (a\u2081 a\u2082 : \u2115) => nat.cast_le) exists_nat_ge\n\ntheorem tendsto_coe_nat_at_top_at_top {R : Type u_2} [ordered_semiring R] [archimedean R] :\n    filter.tendsto coe filter.at_top filter.at_top :=\n  monotone.tendsto_at_top_at_top nat.mono_cast exists_nat_ge\n\ntheorem tendsto_coe_int_at_top_iff {\u03b1 : Type u_1} {R : Type u_2} [ordered_ring R] [nontrivial R]\n    [archimedean R] {f : \u03b1 \u2192 \u2124} {l : filter \u03b1} :\n    filter.tendsto (fun (n : \u03b1) => \u2191(f n)) l filter.at_top \u2194 filter.tendsto f l filter.at_top :=\n  sorry\n\ntheorem tendsto_coe_int_at_top_at_top {R : Type u_2} [ordered_ring R] [archimedean R] :\n    filter.tendsto coe filter.at_top filter.at_top :=\n  sorry\n\ntheorem tendsto_coe_rat_at_top_iff {\u03b1 : Type u_1} {R : Type u_2} [linear_ordered_field R]\n    [archimedean R] {f : \u03b1 \u2192 \u211a} {l : filter \u03b1} :\n    filter.tendsto (fun (n : \u03b1) => \u2191(f n)) l filter.at_top \u2194 filter.tendsto f l filter.at_top :=\n  sorry\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the left) also tends to infinity. The archimedean assumption is convenient to get a\nstatement that works on `\u2115`, `\u2124` and `\u211d`, although not necessary (a version in ordered fields is\ngiven in `filter.tendsto.const_mul_at_top`). -/\ntheorem filter.tendsto.const_mul_at_top' {\u03b1 : Type u_1} {R : Type u_2} [linear_ordered_semiring R]\n    [archimedean R] {l : filter \u03b1} {f : \u03b1 \u2192 R} {r : R} (hr : 0 < r)\n    (hf : filter.tendsto f l filter.at_top) :\n    filter.tendsto (fun (x : \u03b1) => r * f x) l filter.at_top :=\n  sorry\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the right) also tends to infinity. The archimedean assumption is convenient to get a\nstatement that works on `\u2115`, `\u2124` and `\u211d`, although not necessary (a version in ordered fields is\ngiven in `filter.tendsto.at_top_mul_const`). -/\ntheorem filter.tendsto.at_top_mul_const' {\u03b1 : Type u_1} {R : Type u_2} [linear_ordered_semiring R]\n    [archimedean R] {l : filter \u03b1} {f : \u03b1 \u2192 R} {r : R} (hr : 0 < r)\n    (hf : filter.tendsto f l filter.at_top) :\n    filter.tendsto (fun (x : \u03b1) => f x * r) l filter.at_top :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/filter/archimedean_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7193838637226035}}
{"text": "/-\n-/\nimport tactic\nimport data.real.basic\nimport data.set.intervals.basic\nimport algebra.order.floor\n\nvariables (a b : \u211d)\nopen set \ndef I := {x : \u211d // x \u2208 Icc a b}\n\n/-Defines convegences for sequences on I a b-/\ndef Itendsto (s : \u2115 \u2192 I a b) (t : I a b) : Prop :=\n  \u2200 \u03b5 > 0, \u2203 B : \u2115, \u2200 n, B \u2264 n \u2192 |(s n).val - t.val| < \u03b5\n\n/-Defines convergence for sequences on \u211d-/\ndef Rtendsto (s : \u2115 \u2192 \u211d) (t : \u211d) : Prop := \n  \u2200 \u03b5 > 0, \u2203 B : \u2115, \u2200 n, B \u2264 n \u2192 |s n - t| < \u03b5 \n\n/-Defines pointwise continuity for a point of type I a b-/\ndef I_pt_continuity (f : I a b \u2192 \u211d) (x : I a b) : Prop :=\n  \u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 y : I a b, |x.val - y.val| < \u03b4 \u2192 |f x - f y| < \u03b5\n\n/-Defines the property of continuity for type I a b-/\ndef I_continuity (f : I a b \u2192 \u211d) : Prop :=\n  \u2200 (x : I a b), I_pt_continuity a b f x\n\n/-For f on I a b, pointwise continuity at x is equivalent to sequential continuity at that point.-/\nlemma I_cont_sql_cont_pt (a b : \u211d) (f : I a b \u2192 \u211d) (x : I a b):\nI_pt_continuity a b f x \u2194 \u2200 (s : {seq : \u2115 \u2192 I a b // Itendsto a b seq x}), Rtendsto (f \u2218 s) (f x) :=\nbegin\n  /-Separate right and left implication-/\n  split,\n  /-Forward case is fairly simple, for sequence s with \u03b5 > 0, find \u03b4 neighbourhood s.t. the image\n      of this neighbourhood is within \u03b5 of f x. Then find sufficiently large N s.t. s is in the neighbourhood.-/\n    /-Intro continuity property, sequence s and \u03b5-/\n    intros hcontin s \u03b5 h\u03b5,\n    /-Extract \u03b4 neighbourhood with \u03b4 > 0.-/\n    cases hcontin \u03b5 h\u03b5 with \u03b4,\n    cases h with h\u03b4,\n    /-Extract N large enough s.t. s is in the \u03b4 neighbourhood above N.-/\n    cases s.property \u03b4 h\u03b4 with N,\n    use N,\n    intros n hn,\n    /-Adapt goal slightly.-/\n    suffices hs1 : |f x - f (s.val n)| < \u03b5,\n      dsimp,\n      rw abs_sub_comm,\n      exact hs1,\n    /-Show its sufficient that s is in the \u03b4 neighbourhood.-/\n    suffices : |x.val - (s.val n).val| < \u03b4,\n      exact h_h (s.val n) this,\n    rw abs_sub_comm x.val (s.val n).val,\n    /-Goal is exactly the earlier proof that s is in the \u03b4 neighbourhood.-/\n    exact h n hn,\n  \n  /-Backwards case proceeds by assuming the goal is not true and finding a\n    sequence tn s.t. tn \u2192 x but f tn doesnt tend to f x. -/\n    /-intros \u03b5 > 0.-/\n    intros s,\n    intros \u03b5 h\u03b5,\n    /-intros negation of goal to find contradiction.-/\n    by_contra,\n    push_neg at h,\n    /-define sequence we'll bound our target sequence with.-/\n    let sn : \u2115 \u2192 \u211d := \u03bb n, (1 : \u211d) / (n + (1 : \u211d)),\n    /-obtain sequence tn which converges to x, at least \u03b5 from f x-/\n    have h\u2081 : \u2200 (n : \u2115), \u2203 (y : I a b), |x.val - y.val| < sn n \u2227 \u03b5 \u2264 |f x - f y|,\n      intros n,\n      exact h (sn n) nat.one_div_pos_of_nat,\n    choose tn htn using h\u2081,\n    /-show tn converges to x in I a b.-/\n    have h\u2082 : Itendsto a b tn x,\n      intros \u03b51 h\u03b51,\n      /-will choose a val greater than 1/\u03b51, then bound |tn - x| by sn val -/\n      use \u23081/\u03b51\u2309\u208a, \n      intros n hn,\n      rw abs_sub_comm (tn n).val x.val,\n      /-show its sufficient to show sn < \u03b51-/\n      suffices : sn n < \u03b51,\n        calc |x.val - (tn n).val| < sn n : (htn n).1\n                              ... < \u03b51   : this,\n      /-show that sn n \u2264 \u03b51-/\n      have s1 : \u23081 / \u03b51\u2309\u208a < n + 1, \n        by linarith,\n      have s2 : (1 / \u03b51) < n + 1, \n        exact nat.lt_of_ceil_lt s1,\n      have s3 : (n + 1 : \u211d) > 0,\n        exact nat.cast_add_one_pos n,\n      have s4 : 1 / (n + 1 : \u211d) < 1 / (1/ \u03b51),\n        exact (one_div_lt_one_div s3 (one_div_pos.mpr h\u03b51)).mpr s2,\n      calc sn n < 1 / (1 / \u03b51) : s4\n            ... = \u03b51           : by norm_num,\n    /-obtain proof that f \u2218 tn converges to f x-/\n    specialize s \u27e8tn, h\u2082\u27e9,\n    /-intro sufficiently large N s.t. above it, f \u2218 tn is in \u03b5 of f x -/\n    cases s \u03b5 h\u03b5 with N,\n    /-specifiy above to N + 1-/\n    specialize h_1 (N+1) (by norm_num),\n    simp at h_1,\n    /-rw into a different form for simplicity-/\n    have h\u2083 : |f x - f (tn (N + 1))| < \u03b5,\n      calc |f x - f (tn (N + 1))| = |f (tn (N + 1)) - f x| : abs_sub_comm (f x) (f (tn (N + 1)))\n                              ... < \u03b5                      : h_1,\n    /-specify f tn being distance \u03b5 away from f x for N + 1-/\n    specialize htn (N+1),\n    /-induce contradiction from last 2 inequalities-/\n    linarith [htn.2, h\u2083],\nend\n\n/-Intermediate value theorem for continuous f on I a b-/\nlemma intermed_val {a b : \u211d} {a < b} {f : I a b \u2192 \u211d} {h\u2081 : I_continuity a b f}:\n  \u2200 (y : I (f \u27e8a,\u27e8by linarith, by linarith\u27e9\u27e9) (f \u27e8b, \u27e8by linarith, by linarith\u27e9\u27e9)), \u2203 (x\u2081 : I a b), f (x\u2081) = y.val := \nbegin\n  sorry,\nend\n\n/-Bolzano-Weirstrass for a sequence on I a b-/\nlemma bolz_weir_I (a b : \u211d) (sn : \u2115 \u2192 I a b):\n  \u2203 (c : I a b), \u2203 (tn : \u2115 \u2192 \u2115), strict_mono tn \u2227 Itendsto a b (sn \u2218 tn) c :=\nbegin\n  sorry,\nend \n\n/-Natural ceil of a real + a nat is less than the real nat ceil plus the nat.-/\nlemma  nat_ceil (var : \u211d) (n : \u2115)  : \n\u2308var + n\u2309\u208a \u2264 \u2308var\u2309\u208a + n :=\nbegin\n  /-split into cases -/\n  by_cases var \u2264 -(n : \u211d),\n  calc \u2308var + n\u2309\u208a = (0 : \u2115)   : nat.ceil_eq_zero.mpr (show var + n \u2264 0, by linarith) \n              ... = \u2308var\u2309\u208a     : by linarith [nat.ceil_eq_zero.mpr (show var \u2264 0, by linarith [(show -(n : \u211d) \u2264 0, by simp)] )]\n              ... \u2264 \u2308var\u2309\u208a + n : by linarith,\n  push_neg at h,\n  /-show its sufficient that the inequality coerced to the reals is true.-/\n  suffices : (\u2308var + \u2191n\u2309\u208a : \u211d) \u2264 \u2191(\u2308var\u2309\u208a + n),\n    /-non-working attempt:\n    exact nat.coe_nat_le.mp this,-/\n    sorry,\n\n  /-prove the inequality coerced to the reals is true.-/\n  /- non-working attempt, struggled with the typing:\n  calc (\u2308var + \u2191n \u2309\u208a : \u211d) = \u2191\u2308var + n\u2309       : nat.cast_ceil_eq_cast_int_ceil (by linarith)\n              ... = \u2308var\u2309 + \u2191\u2191n            : by rw (int.ceil_add_int var n)\n              ... \u2264 \u2308var\u2309\u208a + n              : by linarith [(show \u2308var\u2309 = \u2308var\u2309\u208a, by refl)]-/\n  sorry,\nend\n\nlemma I_cont_bdd {a b : \u211d} {f : I a b \u2192 \u211d} :\nI_continuity a b f \u2192 \u2203 (M : \u211d), \u2200 (x : I a b), |f x| < M :=\nbegin\n  intros h\u2081,\n  /-Show its sufficient to show f is bounded from above and below.-/\n  /-bound f from above and below.-/\n  suffices goal1 : \u2203 (M1 : \u211d), \u2200 (x : I a b), f x < M1,\n    suffices goal2 : \u2203 (M2 : \u211d), \u2200 (x : I a b), M2 < f x,\n      /-extract upper and lower bound for f.-/\n      cases goal1 with M1,\n      cases goal2 with M2,\n      /-use max of modulus of upper and lower bounds.-/\n      use max M1 (-M2),\n      /-intro arbitrary x, rw goal to 2 conditions.-/\n      intros x,\n      rw abs_lt,\n      /-apply bound to f x.-/\n      specialize goal1_h x,\n      specialize goal2_h x,\n      /-split \u2227 in goal into 2 separate goals -/\n      split, \n      have :  \u2200 ( a b : \u211d), -max a b \u2264 -b, norm_num,\n      /-show f x bounded below by our choice-/\n      calc (-max M1 (-M2)) \u2264 -(-M2)   : this M1 (-M2)\n                      ... = M2        : by ring\n                      ... < f x       : goal2_h,\n    /-show f x is bounded above by our choice-/\n    calc f x < M1                  : goal1_h\n        ... \u2264 max M1 (-M2)        : by norm_num,\n  /-only focus on bounding f from above for now.-/\n  sorry,\n  /-intro negation of goal to prove by contradiction-/\n  by_contra,\n  push_neg at h,\n  /-construct sequence we'll bound f tn by from below.-/\n  let sn : \u2115 \u2192 \u211d := \u03bb n, n,\n  have hcons : \u2200 (n : \u2115), \u2203 (x : I a b), sn n \u2264 f x,\n    intros n,\n    exact h (sn n),\n  /-extract sequence tn using above s.t. n \u2264 tn -/\n  choose tn htn using hcons,\n  /-extract subsequence of tn s.t. it converges using bolzanno-weierstrass.-/\n  cases (bolz_weir_I a b tn) with c,\n  cases h_1 with qn,\n  /-find sufficient N s.t. f \u2218 tn \u2218 qn is within 1 of f c-/\n  have main : Rtendsto (f \u2218 tn \u2218 qn) (f c),\n    exact (I_cont_sql_cont_pt a b f c).mp (h\u2081 c) \u27e8(tn \u2218 qn), h_1_h.right\u27e9,\n  specialize main 1 (by linarith),\n  cases main with N,\n  /-specialise to n = N of above.-/\n  have main1 : |f (tn ( qn N)) - f c| < 1,\n    exact main_h N (by linarith),\n\n  /-specialise main to n = \u2308f (tn (qn N))\u2309\u208a + 2, which will lead to contradiction.-/\n  have : N \u2264 \u2308f (tn (qn N))\u2309\u208a + 2,\n    sorry,\n  have main2 : |f (tn ( qn (\u2308f (tn (qn N))\u2309\u208a + 2))) - f c| < 1,\n    exact main_h (\u2308f (tn (qn N))\u2309\u208a + 2) this,\n  \n  /-bound f c from above by f( tn( qn N) + 1-/\n  have main3 : f c < f ( tn( qn N)) + 1,\n    rw abs_lt at main1,\n    linarith [main1.left],\n\n  /-bound f c + 1 below.-/\n  have main4 : f (tn (qn (\u2308f (tn (qn N))\u2309\u208a + 2))) < f c + 1,\n    rw abs_lt at main2,\n    linarith [main2.right],\n\n  /-show f c + 1 is bounded below by f(tn (qn N)):\n    -find N greater than f(tn(qn N)) using \u2308 \u2309\u208a\n    -use monotonicity of qn and identity of sn\n    -use f bounded below by sn\n    -use earlier result that this is bounded above by f c + 1.apply.\n  -/\n  have this1 : \u2308f(tn (qn N)) + \u21912\u2309\u208a \u2264 \u2308f(tn (qn N))\u2309\u208a + 2, exact nat_ceil (f (tn (qn N))) 2,\n  have main5 : f (tn (qn N)) + 2 < f c + 1, \n    calc f(tn (qn N)) + 2 \u2264 \u2191\u2308f(tn (qn N)) + (2 : \u211d)\u2309\u208a  : nat.le_ceil (f (tn (qn N)) + 2)\n                      ... \u2264 \u2191(\u2308f(tn (qn N))\u2309\u208a + 2)      : sorry /-nat.cast_le.mpr (nat_ceil (f (tn (qn N))) 2)-/\n                      ... = \u2191\u2308f(tn (qn N))\u2309\u208a + (2 : \u211d)  : by simp\n                      ... \u2264 \u2191(qn(\u2308f(tn (qn N))\u2309\u208a + 2))  : sorry /-(function.well_founded.self_le_of_strict_mono (nat.lt_wf) h_1_h.left (\u2308f(tn (qn N))\u2309\u208a + 2))-/\n                      ... = sn (qn (\u2308f (tn (qn N))\u2309\u208a + 2)) : rfl\n                      ... \u2264 f (tn ((qn (\u2308f (tn (qn N))\u2309\u208a + 2)))) : htn (qn (\u2308f (tn (qn N))\u2309\u208a + 2))\n                      ... < f c + 1                           : main4,\n  /-derive contradiction from above and below bound of f c by f tn qn N + 1.-/\n  linarith,\nend \n\n\n", "meta": {"author": "jrg19", "repo": "LEAN-Continuity-Lemmas", "sha": "4f70358bfb87572d2ec5457d721ad2b82b6d57e0", "save_path": "github-repos/lean/jrg19-LEAN-Continuity-Lemmas", "path": "github-repos/lean/jrg19-LEAN-Continuity-Lemmas/LEAN-Continuity-Lemmas-4f70358bfb87572d2ec5457d721ad2b82b6d57e0/src/prj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7193838626425604}}
{"text": "import data.real.basic\nimport algebra.group.pi\nimport tuto_lib\n\nnotation `|`x`|` := abs x\n\n/-\nIn this file we manipulate the elementary definition of limits of\nsequences of real numbers. \nmathlib has a much more general definition of limits, but here\nwe want to practice using the logical operators and relations\ncovered in the previous files.\n\nA sequence u is a function from \u2115 to \u211d, hence Lean says\nu : \u2115 \u2192 \u211d\nThe definition we'll be using is:\n\n-- Definition of \u00ab u tends to l \u00bb\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\nNote the use of `\u2200 \u03b5 > 0, ...` which is an abbreviation of\n`\u2200 \u03b5, \u03b5 > 0 \u2192 ... `\n\nIn particular, a statement like `h : \u2200 \u03b5 > 0, ...`\ncan be specialized to a given \u03b5\u2080 by\n  `specialize h \u03b5\u2080 h\u03b5\u2080`\nwhere h\u03b5\u2080 is a proof of \u03b5\u2080 > 0.\n\nAlso recall that, wherever Lean expects some proof term, we can\nstart a tactic mode proof using the keyword `by` (followed by curly braces\nif you need more than one tactic invocation).\nFor instance, if the local context contains:\n\n\u03b4 : \u211d\n\u03b4_pos : \u03b4 > 0\nh : \u2200 \u03b5 > 0, ...\n\nthen we can specialize h to the real number \u03b4/2 using:\n  `specialize h (\u03b4/2) (by linarith)`\nwhere `by linarith` will provide the proof of `\u03b4/2 > 0` expected by Lean.\n\nWe'll take this opportunity to use two new tactics:\n\n`norm_num` will perform numerical normalization on the goal and `norm_num at h` \nwill do the same in assumption `h`. This will get rid of trivial calculations on numbers,\nlike replacing |l - l| by zero in the next exercise.\n\n`congr'` will try to prove equalities between applications of functions by recursively \nproving the arguments are the same. \nFor instance, if the goal is `f x + g y = f z + g t` then congr will replace it by\ntwo goals: `x = z` and `y = t`.\nYou can limit the recursion depth by specifying a natural number after `congr'`. \nFor instance, in the above example, `congr' 1` will give new goals\n`f x = f z` and `g y = g t`, which only inspect arguments of the addition and not deeper.\n-/\n\nvariables (u v w : \u2115 \u2192 \u211d) (l l' : \u211d)\n\n-- If u is constant with value l then u tends to l\n-- 0033\nexample : (\u2200 n, u n = l) \u2192 seq_limit u l :=\nbegin\n  -- sorry\n  intros h \u03b5 \u03b5_pos,\n  use 0,\n  intros n hn,\n  rw h,\n  norm_num,\n  linarith,\n  -- sorry\nend\n\n/- When dealing with absolute values, we'll use lemmas:\n\nabs_le {x y : \u211d} : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nabs_add (x y : \u211d) : |x + y| \u2264 |x| + |y|\n\nabs_sub_comm (x y : \u211d) : |x - y| = |y - x|\n\nYou should probably write them down on a sheet of paper that you keep at \nhand since they are used in many exercises.\n-/\n\n-- Assume l > 0. Then u tends to l implies u n \u2265 l/2 for large enough n\n-- 0034\nexample (hl : l > 0) : seq_limit u l \u2192 \u2203 N, \u2200 n \u2265 N, u n \u2265 l/2 :=\nbegin\n  -- sorry\n  intro h,\n  cases h (l/2) (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_le at hN,\n  linarith,\n  -- sorry\nend\n\n/- \nWhen dealing with max, you can use\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\nYou should probably add them to the sheet of paper where you wrote \nthe `abs` lemmas since they are used in many exercises.\n\nLet's see an example.\n-/\n\n-- If u tends to l and v tends l' then u+v tends to l+l'\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\nseq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  cases ge_max_iff.mp hn with hn\u2081 hn\u2082,\n  have fact\u2081 : |u n - l| \u2264 \u03b5/2,\n    from hN\u2081 n (by linarith),  -- note the use of `from`.\n                               -- This is an alias for `exact`, \n                               -- but reads nicer in this context \n  have fact\u2082 : |v n - l'| \u2264 \u03b5/2,\n    from hN\u2082 n (by linarith), \n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1 ; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith,\nend\n\n/-\nIn the above proof, we used `have` to prepare facts for `linarith` consumption in the last line.\nSince we have direct proof terms for them, we can feed them directly to `linarith` as in the next proof\nof the same statement.\nAnother variation we introduce is rewriting using `ge_max_iff` and letting `linarith` handle the\nconjunction, instead of creating two new assumptions.\n-/\n\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\nseq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  rw ge_max_iff at hn,\n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1 ; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith [hN\u2081 n (by linarith), hN\u2082 n (by linarith)],\nend\n\n/- Let's do something similar: the squeezing theorem. -/\n-- 0035\nexample (hu : seq_limit u l) (hw : seq_limit w l)\n(h : \u2200 n, u n \u2264 v n)\n(h' : \u2200 n, v n \u2264 w n) : seq_limit v l :=\nbegin\n  -- sorry\n  intros \u03b5 \u03b5_pos,\n  cases hu \u03b5 \u03b5_pos with N hN,\n  cases hw \u03b5 \u03b5_pos with N' hN',\n  use max N N',\n  intros n hn,\n  rw ge_max_iff at hn,\n  specialize hN n (by linarith),\n  specialize hN' n (by linarith),\n  specialize h n,\n  specialize h' n,\n  rw abs_le at *,\n  split,\n  -- Here `linarith` can finish, but on paper we would write\n  calc -\u03b5 \u2264 u n - l : by linarith\n      ... \u2264 v n - l : by linarith,\n  calc v n - l \u2264 w n - l : by linarith\n      ... \u2264 \u03b5 : by linarith,\n  -- sorry\n\nend\n\n/- What about < \u03b5? -/\n-- 0036\nexample (u l) : seq_limit u l \u2194\n \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5 :=\nbegin\n  -- sorry\n  split,\n  { intros hyp \u03b5 \u03b5_pos,\n    cases hyp (\u03b5/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    calc |u n - l| \u2264 \u03b5/2 : by exact hN n hn\n              ...  < \u03b5   : by linarith, },\n  { intros hyp \u03b5 \u03b5_pos,\n    cases hyp \u03b5 \u03b5_pos with N hN,\n    use N,\n    intros n hn,\n    specialize hN n hn,\n    linarith, },\n  -- sorry\nend\n\n/- In the next exercise, we'll use\n\neq_of_abs_sub_le_all (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y\n-/\n\n-- A sequence admits at most one limit\n-- 0037\nexample : seq_limit u l \u2192 seq_limit u l' \u2192 l = l' :=\nbegin\n  -- sorry\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros \u03b5 \u03b5_pos,\n  cases hl (\u03b5/2) (by linarith) with N hN,\n  cases hl' (\u03b5/2) (by linarith) with N' hN',\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring_nf\n  ... \u2264 |l - u (max N N')| + |u (max N N') - l'| : by apply abs_add\n  ... =  |u (max N N') - l| + |u (max N N') - l'| : by rw abs_sub_comm\n  ... \u2264 \u03b5 : by linarith [hN (max N N') (le_max_left _ _), hN' (max N N') (le_max_right _ _)]\n  -- sorry\nend\n\n/-\nLet's now practice deciphering definitions before proving.\n-/\n\ndef non_decreasing (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\ndef is_seq_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n-- 0038\nexample (M : \u211d) (h : is_seq_sup M u) (h' : non_decreasing u) :\nseq_limit u M :=\nbegin\n  -- sorry\n  intros \u03b5 \u03b5_pos,\n  cases h with inf_M sup_M_ep,\n  cases sup_M_ep \u03b5 \u03b5_pos with n\u2080 hn\u2080,\n  use n\u2080,\n  intros n hn,\n  rw abs_le,\n  split; linarith [inf_M n, h' n\u2080 n hn],\n  -- sorry\nend\n", "meta": {"author": "leanprover-community", "repo": "tutorials", "sha": "79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1", "save_path": "github-repos/lean/leanprover-community-tutorials", "path": "github-repos/lean/leanprover-community-tutorials/tutorials-79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1/src/solutions/05_sequence_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7193838601218949}}
{"text": "import .lovelib\n\n\n/-! # LoVe Demo 4: Functional Programming\n\nWe take a closer look at the basics of typed functional programming: inductive\ntypes, proofs by induction, recursive functions, pattern matching, structures\n(records), and type classes. -/\n\n\nset_option pp.beta true\n\nnamespace LoVe\n\n\n/-! ## Inductive Types\n\nRecall the definition of type `nat` (= `\u2115`): -/\n\n#print nat\n\n/-! Mottos:\n\n* **No junk**: The type contains no values beyond those expressible using the\n  constructors.\n\n* **No confusion**: Values built in a different ways are different.\n\nFor `nat` (= `\u2115`):\n\n* \"No junk\" means that there are no special values, say, `\u20131` or `\u03b5`, that\n  cannot be expressed using a finite combination of `zero` and `succ`.\n\n* \"No confusion\" is what ensures that `zero` \u2260 `succ x`.\n\nIn addition, inductive types are always finite. `succ (succ (succ \u2026))` is not a\nvalue.\n\n\n## Structural Induction\n\n__Structural induction__ is a generalization of mathematical induction to\ninductive types. To prove a property `P[n]` for all natural numbers `n`, it\nsuffices to prove the base case\n\n    `P[0]`\n\nand the induction step\n\n    `\u2200k, P[k] \u2192 P[k + 1]`\n\nFor lists, the base case is\n\n    `P[[]]`\n\nand the induction step is\n\n    `\u2200y ys, P[ys] \u2192 P[y :: ys]`\n\nIn general, there is one subgoal per constructor, and induction hypotheses are\navailable for all constructor arguments of the type we are doing the induction\non. -/\n\nlemma nat.succ_neq_self (n : \u2115) :\n  nat.succ n \u2260 n :=\nbegin\n  induction n,\n  { simp },\n  { simp [n_ih] }\nend\n\n/-! The `case` tactic can be used to supply custom names, and potentially\nreorder the cases. -/\n\nlemma nat.succ_neq_self\u2082 (n : \u2115) :\n  nat.succ n \u2260 n :=\nbegin\n  induction n,\n  case nat.succ : m ih {\n    simp [ih] },\n  case nat.zero {\n    simp }\nend\n\n\n/-! ## Structural Recursion\n\n__Structural recursion__ is a form of recursion that allows us to peel off\none or more constructors from the value on which we recurse. Such functions are\nguaranteed to call themselves only finitely many times before the recursion\nstops. This is a prerequisite for establishing that the function terminates. -/\n\ndef fact : \u2115 \u2192 \u2115\n| 0       := 1\n| (n + 1) := (n + 1) * fact n\n\ndef fact\u2082 : \u2115 \u2192 \u2115\n| 0       := 1\n| 1       := 1\n| (n + 1) := (n + 1) * fact\u2082 n\n\n/-! For structurally recursive functions, Lean can automatically prove\ntermination. For more general recursive schemes, the termination check may fail.\nSometimes it does so for a good reason, as in the following example: -/\n\n-- fails\ndef illegal : \u2115 \u2192 \u2115\n| n := illegal n + 1\n\nconstant immoral : \u2115 \u2192 \u2115\n\naxiom immoral_eq (n : \u2115) :\n  immoral n = immoral n + 1\n\nlemma proof_of_false :\n  false :=\nhave immoral 0 = immoral 0 + 1 :=\n  immoral_eq 0,\nhave immoral 0 - immoral 0 = immoral 0 + 1 - immoral 0 :=\n  by cc,\nhave 0 = 1 :=\n  by simp [*] at *,\nshow false, from\n  by cc\n\n/-! **Warning:** The above definitions of factorial are wrong.\n\n\n## Pattern Matching Expressions\n\n    `match` _term\u2081_, \u2026, _termM_ `with`\n    | _pattern\u2081\u2081_, \u2026, _pattern\u2081M_ := _result\u2081_\n        \u22ee\n    | _patternN\u2081_, \u2026, _patternNM_ := _resultN_\n    `end`\n\n`match` allows nonrecursive pattern matching within terms.\n\nIn contrast to pattern matching after `lemma` or `def`, the patterns are\nseparated by commas, so parentheses are optional. -/\n\ndef bcount {\u03b1 : Type} (p : \u03b1 \u2192 bool) : list \u03b1 \u2192 \u2115\n| []        := 0\n| (x :: xs) :=\n  match p x with\n  | tt := bcount xs + 1\n  | ff := bcount xs\n  end\n\ndef min (a b : \u2115) : \u2115 :=\nif a \u2264 b then a else b\n\n\n/-! ## Structures\n\nLean provides a convenient syntax for defining records, or structures. These are\nessentially nonrecursive, single-constructor inductive types. -/\n\nstructure rgb : Type :=\n(red green blue : \u2115)\n\n#check rgb.mk\n#check rgb.red\n#check rgb.green\n#check rgb.blue\n\nnamespace rgb_as_inductive\n\ninductive rgb : Type\n| mk : \u2115 \u2192 \u2115 \u2192 \u2115 \u2192 rgb\n\ndef rgb.red : rgb \u2192 \u2115\n| (rgb.mk r _ _) := r\n\ndef rgb.green : rgb \u2192 \u2115\n| (rgb.mk _ g _) := g\n\ndef rgb.blue : rgb \u2192 \u2115\n| (rgb.mk _ _ b) := b\n\nend rgb_as_inductive\n\nstructure rgba extends rgb : Type :=\n(alpha : \u2115)\n\n#print rgba\n\ndef pure_red : rgb :=\n{ red   := 0xff,\n  green := 0x00,\n  blue  := 0x00 }\n\ndef semitransparent_red : rgba :=\n{ alpha := 0x7f,\n  ..pure_red }\n\n#print pure_red\n#print semitransparent_red\n\ndef shuffle (c : rgb) : rgb :=\n{ red   := rgb.green c,\n  green := rgb.blue c,\n  blue  := rgb.red c }\n\n/-! `cases` performs a case distinction on the specified term. This gives rise\nto as many subgoals as there are constructors in the definition of the term's\ntype. The tactic behaves almost the same as `induction` except that it does not\nproduce induction hypotheses. -/\n\nlemma shuffle_shuffle_shuffle (c : rgb) :\n  shuffle (shuffle (shuffle c)) = c :=\nbegin\n  cases c,\n  refl\nend\n\nlemma shuffle_shuffle_shuffle\u2082 (c : rgb) :\n  shuffle (shuffle (shuffle c)) = c :=\nmatch c with\n| rgb.mk r g b := eq.refl _\nend\n\n\n/-! ## Type Classes\n\nA __type class__ is a structure type combining abstract constants and their\nproperties. A type can be declared an instance of a type class by providing\nconcrete definitions for the constants and proving that the properties hold.\nBased on the type, Lean retrieves the relevant instance. -/\n\n#print inhabited\n\n@[instance] def nat.inhabited : inhabited \u2115 :=\n{ default := 0 }\n\n@[instance] def list.inhabited {\u03b1 : Type} :\n  inhabited (list \u03b1) :=\n{ default := [] }\n\n#eval inhabited.default \u2115          -- result: 0\n#eval inhabited.default (list \u2124)   -- result: []\n\ndef head {\u03b1 : Type} [inhabited \u03b1] : list \u03b1 \u2192 \u03b1\n| []       := inhabited.default \u03b1\n| (x :: _) := x\n\nlemma head_head {\u03b1 : Type} [inhabited \u03b1] (xs : list \u03b1) :\n  head [head xs] = head xs :=\nbegin\n  cases xs,\n  { refl },\n  { refl }\nend\n\n#eval head ([] : list \u2115)   -- result: 0\n\n#check list.head\n\n@[instance] def fun.inhabited {\u03b1 \u03b2 : Type} [inhabited \u03b2] :\n  inhabited (\u03b1 \u2192 \u03b2) :=\n{ default := \u03bba : \u03b1, inhabited.default \u03b2 }\n\ninductive empty : Type\n\n@[instance] def fun_empty.inhabited {\u03b2 : Type} :\n  inhabited (empty \u2192 \u03b2) :=\n{ default := \u03bba : empty, match a with end }\n\n@[instance] def prod.inhabited {\u03b1 \u03b2 : Type}\n    [inhabited \u03b1] [inhabited \u03b2] :\n  inhabited (\u03b1 \u00d7 \u03b2) :=\n{ default := (inhabited.default \u03b1, inhabited.default \u03b2) }\n\n/-! Here are other type classes without properties: -/\n\n#check has_zero\n#check has_neg\n#check has_add\n#check has_one\n#check has_inv\n#check has_mul\n\n#check (1 : \u2115)\n#check (1 : \u2124)\n#check (1 : \u211d)\n#check (1 : linear_map _ _ _)\n\n/-! We encountered these type classes in lecture 2: -/\n\n#print is_commutative\n#print is_associative\n\n\n/-! ## Lists\n\n`list` is an inductive polymorphic type constructed from `nil` and `cons`: -/\n\n#print list\n\n/-! `cases` can also be used on a hypothesis of the form `l = r`. It matches `r`\nagainst `l` and replaces all occurrences of the variables occurring in `r` with\nthe corresponding terms in `l` everywhere in the goal. The remaining hypothesis\n`l = l` can be removed using `clear h` if desired. -/\n\nlemma injection_example {\u03b1 : Type} (x y : \u03b1) (xs ys : list \u03b1)\n    (h : list.cons x xs = list.cons y ys) :\n  x = y \u2227 xs = ys :=\nbegin\n  cases h,\n  cc\nend\n\n/-! If `r` fails to match `l`, no subgoals emerge; the proof is complete. -/\n\nlemma distinctness_example {\u03b1 : Type} (x y : \u03b1)\n    (xs ys : list \u03b1) (h : [] = y :: ys) :\n  false :=\nby cases h\n\ndef map {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) : list \u03b1 \u2192 list \u03b2\n| []        := []\n| (x :: xs) := f x :: map xs\n\ndef map\u2082 {\u03b1 \u03b2 : Type} : (\u03b1 \u2192 \u03b2) \u2192 list \u03b1 \u2192 list \u03b2\n| _ []        := []\n| f (x :: xs) := f x :: map\u2082 f xs\n\nlemma map_equiv  {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) (xs : list \u03b1):\n  map f xs = map\u2082 f xs :=\nbegin\n  intros,\n  induction xs,\n  simp [map, map\u2082],\n  simp [map, map\u2082, xs_ih],\nend\n\n#check list.map\n\nlemma map_ident {\u03b1 : Type} (xs : list \u03b1) :\n  map (\u03bbx, x) xs = xs :=\nbegin\n  induction xs,\n  case list.nil {\n    refl },\n  case list.cons : y ys ih {\n    simp [map, ih] }\nend\n\nlemma map_comp {\u03b1 \u03b2 \u03b3 : Type} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3)\n    (xs : list \u03b1) :\n  map g (map f xs) = map (\u03bbx, g (f x)) xs :=\nbegin\n  induction xs,\n  case list.nil {\n    refl },\n  case list.cons : y ys ih {\n    simp [map, ih] }\nend\n\nlemma map_append {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 \u03b2) (xs ys : list \u03b1) :\n  map f (xs ++ ys) = map f xs ++ map f ys :=\nbegin\n  induction xs,\n  case list.nil {\n    refl },\n  case list.cons : y ys ih {\n    simp [map, ih] }\nend\n\ndef tail {\u03b1 : Type} : list \u03b1 \u2192 list \u03b1\n| []        := []\n| (_ :: xs) := xs\n\n#check list.tail\n\ndef head_opt {\u03b1 : Type} : list \u03b1 \u2192 option \u03b1\n| []       := option.none\n| (x :: _) := option.some x\n\ndef head_le {\u03b1 : Type} : \u2200xs : list \u03b1, xs \u2260 [] \u2192 \u03b1\n| []       hxs := by cc\n| (x :: _) _   := x\n\n#eval head_opt [3, 1, 4]\n#eval head_le [3, 1, 4] (by simp)\n#eval head_le ([] : list \u2115) sorry   -- fails\n\ndef zip {\u03b1 \u03b2 : Type} : list \u03b1 \u2192 list \u03b2 \u2192 list (\u03b1 \u00d7 \u03b2)\n| (x :: xs) (y :: ys) := (x, y) :: zip xs ys\n| []        _         := []\n| (_ :: _)  []        := []\n\n#check list.zip\n\ndef length {\u03b1 : Type} : list \u03b1 \u2192 \u2115\n| []        := 0\n| (x :: xs) := length xs + 1\n\n#check list.length\n\n/-! `cases` can also be used to perform a case distinction on a proposition, in\nconjunction with `classical.em`. Two cases emerge: one in which the proposition\nis true and one in which it is false.\n\nAlso notice the `have` tactic below. We will come back to it. -/\n\n#check classical.em\n\nlemma min_add_add (l m n : \u2115) :\n  min (m + l) (n + l) = min m n + l :=\nbegin\n  cases classical.em (m \u2264 n),\n  case or.inl : h {\n    simp [min, h] },\n  case or.inr : h {\n    simp [min, h] }\nend\n\nlemma min_add_add\u2082 (l m n : \u2115) :\n  min (m + l) (n + l) = min m n + l :=\nmatch classical.em (m \u2264 n) with\n| or.inl h := by simp [min, h]\n| or.inr h := by simp [min, h]\nend\n\nlemma min_add_add\u2083 (l m n : \u2115) :\n  min (m + l) (n + l) = min m n + l :=\nif h : m \u2264 n then\n  by simp [min, h]\nelse\n  by simp [min, h]\n\nlemma length_zip {\u03b1 \u03b2 : Type} (xs : list \u03b1) (ys : list \u03b2) :\n  length (zip xs ys) = min (length xs) (length ys) :=\nbegin\n  induction xs generalizing ys,\n    refl,\n      cases ys,\n        refl,\n        simp [zip, length, xs_ih, min_add_add],\nend\n\nlemma map_zip {\u03b1 \u03b1' \u03b2 \u03b2' : Type} (f : \u03b1 \u2192 \u03b1') (g : \u03b2 \u2192 \u03b2') :\n  \u2200xs ys,\n    map (\u03bbab : \u03b1 \u00d7 \u03b2, (f (prod.fst ab), g (prod.snd ab)))\n      (zip xs ys) =\n    zip (map f xs) (map g ys)\n| (x :: xs) (y :: ys) := by simp [zip, map, map_zip xs ys]\n| []        _         := by refl\n| (_ :: _)  []        := by refl\n\n\n/-! ## Binary Trees\n\nInductive types with constructors taking several recursive arguments define\ntree-like objects. __Binary trees__ have nodes with at most two children. -/\n\ninductive btree (\u03b1 : Type) : Type\n| empty {} : btree\n| node     : \u03b1 \u2192 btree \u2192 btree \u2192 btree\n\n/-! The type `aexp` of arithmetic expressions was also an example of a tree data\nstructure.\n\nThe nodes of a tree, whether inner nodes or leaf nodes, often carry labels or\nother annotations.\n\nInductive trees contain no infinite branches, not even cycles. This is less\nexpressive than pointer- or reference-based data structures (in imperative\nlanguages) but easier to reason about.\n\nRecursive definitions (and proofs by induction) work roughly as for lists, but\nwe may need to recurse (or invoke the induction hypothesis) on several child\nnodes. -/\n\ndef mirror {\u03b1 : Type} : btree \u03b1 \u2192 btree \u03b1\n| btree.empty        := btree.empty\n| (btree.node a l r) := btree.node a (mirror r) (mirror l)\n\nlemma mirror_mirror {\u03b1 : Type} (t : btree \u03b1) :\n  mirror (mirror t) = t :=\nbegin\n  induction t,\n  case btree.empty {\n    refl },\n  case btree.node : a l r ih_l ih_r {\n    simp [mirror, ih_l, ih_r] }\nend\n\nlemma mirror_eq_empty_iff {\u03b1 : Type} :\n  \u2200t : btree \u03b1, mirror t = btree.empty \u2194 t = btree.empty\n| btree.empty        := by refl\n| (btree.node _ _ _) := by simp [mirror]\n\nlemma mirror_mirror\u2082 {\u03b1 : Type} :\n  \u2200t : btree \u03b1, mirror (mirror t) = t\n| btree.empty        := by refl\n| (btree.node a l r) :=\n  calc  mirror (mirror (btree.node a l r))\n      = mirror (btree.node a (mirror r) (mirror l)) :\n    by refl\n  ... = btree.node a (mirror (mirror l)) (mirror (mirror r)) :\n    by refl\n  ... = btree.node a l (mirror (mirror r)) :\n    by rewrite mirror_mirror\u2082 l\n  ... = btree.node a l r :\n    by rewrite mirror_mirror\u2082 r\n\n\n/-! ## Dependent Inductive Types (**optional**) -/\n\n#check vector\n\ninductive vec (\u03b1 : Type) : \u2115 \u2192 Type\n| nil {}                           : vec 0\n| cons (a : \u03b1) {n : \u2115} (v : vec n) : vec (n + 1)\n\n#check vec.nil\n#check vec.cons\n\ndef list_of_vec {\u03b1 : Type} : \u2200{n : \u2115}, vec \u03b1 n \u2192 list \u03b1\n| _ vec.nil        := []\n| _ (vec.cons a v) := a :: list_of_vec v\n\ndef vec_of_list {\u03b1 : Type} :\n  \u2200xs : list \u03b1, vec \u03b1 (list.length xs)\n| []        := vec.nil\n| (x :: xs) := vec.cons x (vec_of_list xs)\n\nlemma length_list_of_vec {\u03b1 : Type} :\n  \u2200{n : \u2115} (v : vec \u03b1 n), list.length (list_of_vec v) = n\n| _ vec.nil        := by refl\n| _ (vec.cons a v) :=\n  by simp [list_of_vec, length_list_of_vec v]\n\nend LoVe\n", "meta": {"author": "yizhou7", "repo": "learning-lean", "sha": "91fb366c624df6e56e19555b2e482ce767cd8224", "save_path": "github-repos/lean/yizhou7-learning-lean", "path": "github-repos/lean/yizhou7-learning-lean/learning-lean-91fb366c624df6e56e19555b2e482ce767cd8224/my_project/src/love04_functional_programming_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786138, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7193838586812724}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n\n! This file was ported from Lean 3 source module analysis.special_functions.trigonometric.complex\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.QuadraticDiscriminant\nimport Mathbin.Analysis.SpecialFunctions.Trigonometric.Basic\nimport Mathbin.Analysis.Convex.SpecificFunctions\n\n/-!\n# Complex trigonometric functions\n\nBasic facts and derivatives for the complex trigonometric functions.\n\nSeveral facts about the real trigonometric functions have the proofs deferred here, rather than\n`analysis.special_functions.trigonometric.basic`,\nas they are most easily proved by appealing to the corresponding fact for complex trigonometric\nfunctions, or require additional imports which are not available in that file.\n-/\n\n\nnoncomputable section\n\nnamespace Complex\n\nopen Set Filter\n\nopen Real\n\ntheorem cos_eq_zero_iff {\u03b8 : \u2102} : cos \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = (2 * k + 1) * \u03c0 / 2 :=\n  by\n  have h : (exp (\u03b8 * I) + exp (-\u03b8 * I)) / 2 = 0 \u2194 exp (2 * \u03b8 * I) = -1 :=\n    by\n    rw [@div_eq_iff _ _ (exp (\u03b8 * I) + exp (-\u03b8 * I)) 2 0 two_ne_zero, MulZeroClass.zero_mul,\n      add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, \u2190 div_eq_iff (exp_ne_zero _), \u2190 exp_sub]\n    field_simp only\n    congr 3\n    ring\n  rw [cos, h, \u2190 exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm]\n  refine' exists_congr fun x => _\n  refine' (iff_of_eq <| congr_arg _ _).trans (mul_right_inj' <| mul_ne_zero two_ne_zero I_ne_zero)\n  field_simp\n  ring\n#align complex.cos_eq_zero_iff Complex.cos_eq_zero_iff\n\ntheorem cos_ne_zero_iff {\u03b8 : \u2102} : cos \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 (2 * k + 1) * \u03c0 / 2 := by\n  rw [\u2190 not_exists, not_iff_not, cos_eq_zero_iff]\n#align complex.cos_ne_zero_iff Complex.cos_ne_zero_iff\n\ntheorem sin_eq_zero_iff {\u03b8 : \u2102} : sin \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = k * \u03c0 :=\n  by\n  rw [\u2190 Complex.cos_sub_pi_div_two, cos_eq_zero_iff]\n  constructor\n  \u00b7 rintro \u27e8k, hk\u27e9\n    use k + 1\n    field_simp [eq_add_of_sub_eq hk]\n    ring\n  \u00b7 rintro \u27e8k, rfl\u27e9\n    use k - 1\n    field_simp\n    ring\n#align complex.sin_eq_zero_iff Complex.sin_eq_zero_iff\n\ntheorem sin_ne_zero_iff {\u03b8 : \u2102} : sin \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 k * \u03c0 := by\n  rw [\u2190 not_exists, not_iff_not, sin_eq_zero_iff]\n#align complex.sin_ne_zero_iff Complex.sin_ne_zero_iff\n\ntheorem tan_eq_zero_iff {\u03b8 : \u2102} : tan \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = k * \u03c0 / 2 :=\n  by\n  have h := (sin_two_mul \u03b8).symm\n  rw [mul_assoc] at h\n  rw [tan, div_eq_zero_iff, \u2190 mul_eq_zero, \u2190 MulZeroClass.zero_mul (1 / 2 : \u2102), mul_one_div,\n    CancelFactors.cancel_factors_eq_div h two_ne_zero, mul_comm]\n  simpa only [zero_div, MulZeroClass.zero_mul, Ne.def, not_false_iff, field_simps] using\n    sin_eq_zero_iff\n#align complex.tan_eq_zero_iff Complex.tan_eq_zero_iff\n\ntheorem tan_ne_zero_iff {\u03b8 : \u2102} : tan \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 k * \u03c0 / 2 := by\n  rw [\u2190 not_exists, not_iff_not, tan_eq_zero_iff]\n#align complex.tan_ne_zero_iff Complex.tan_ne_zero_iff\n\ntheorem tan_int_mul_pi_div_two (n : \u2124) : tan (n * \u03c0 / 2) = 0 :=\n  tan_eq_zero_iff.mpr (by use n)\n#align complex.tan_int_mul_pi_div_two Complex.tan_int_mul_pi_div_two\n\ntheorem cos_eq_cos_iff {x y : \u2102} : cos x = cos y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = 2 * k * \u03c0 - x :=\n  calc\n    cos x = cos y \u2194 cos x - cos y = 0 := sub_eq_zero.symm\n    _ \u2194 -2 * sin ((x + y) / 2) * sin ((x - y) / 2) = 0 := by rw [cos_sub_cos]\n    _ \u2194 sin ((x + y) / 2) = 0 \u2228 sin ((x - y) / 2) = 0 := by simp [(by norm_num : (2 : \u2102) \u2260 0)]\n    _ \u2194 sin ((x - y) / 2) = 0 \u2228 sin ((x + y) / 2) = 0 := or_comm\n    _ \u2194 (\u2203 k : \u2124, y = 2 * k * \u03c0 + x) \u2228 \u2203 k : \u2124, y = 2 * k * \u03c0 - x :=\n      by\n      apply or_congr <;>\n        field_simp [sin_eq_zero_iff, (by norm_num : -(2 : \u2102) \u2260 0), eq_sub_iff_add_eq',\n          sub_eq_iff_eq_add, mul_comm (2 : \u2102), mul_right_comm _ (2 : \u2102)]\n      constructor <;>\n        \u00b7 rintro \u27e8k, rfl\u27e9\n          use -k\n          simp\n    _ \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = 2 * k * \u03c0 - x := exists_or.symm\n    \n#align complex.cos_eq_cos_iff Complex.cos_eq_cos_iff\n\ntheorem sin_eq_sin_iff {x y : \u2102} :\n    sin x = sin y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = (2 * k + 1) * \u03c0 - x :=\n  by\n  simp only [\u2190 Complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add]\n  refine' exists_congr fun k => or_congr _ _ <;> refine' Eq.congr rfl _ <;> field_simp <;> ring\n#align complex.sin_eq_sin_iff Complex.sin_eq_sin_iff\n\ntheorem tan_add {x y : \u2102}\n    (h :\n      ((\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y \u2260 (2 * l + 1) * \u03c0 / 2) \u2228\n        (\u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 2) \u2227 \u2203 l : \u2124, y = (2 * l + 1) * \u03c0 / 2) :\n    tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=\n  by\n  rcases h with (\u27e8h1, h2\u27e9 | \u27e8\u27e8k, rfl\u27e9, \u27e8l, rfl\u27e9\u27e9)\n  \u00b7 rw [tan, sin_add, cos_add, \u2190\n      div_div_div_cancel_right (sin x * cos y + cos x * sin y)\n        (mul_ne_zero (cos_ne_zero_iff.mpr h1) (cos_ne_zero_iff.mpr h2)),\n      add_div, sub_div]\n    simp only [\u2190 div_mul_div_comm, \u2190 tan, mul_one, one_mul, div_self (cos_ne_zero_iff.mpr h1),\n      div_self (cos_ne_zero_iff.mpr h2)]\n  \u00b7 obtain \u27e8t, hx, hy, hxy\u27e9 := tan_int_mul_pi_div_two, t (2 * k + 1), t (2 * l + 1),\n      t (2 * k + 1 + (2 * l + 1))\n    simp only [Int.cast_add, Int.cast_bit0, Int.cast_mul, Int.cast_one, hx, hy] at hx hy hxy\n    rw [hx, hy, add_zero, zero_div, mul_div_assoc, mul_div_assoc, \u2190\n      add_mul (2 * (k : \u2102) + 1) (2 * l + 1) (\u03c0 / 2), \u2190 mul_div_assoc, hxy]\n#align complex.tan_add Complex.tan_add\n\ntheorem tan_add' {x y : \u2102}\n    (h : (\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y \u2260 (2 * l + 1) * \u03c0 / 2) :\n    tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=\n  tan_add (Or.inl h)\n#align complex.tan_add' Complex.tan_add'\n\ntheorem tan_two_mul {z : \u2102} : tan (2 * z) = 2 * tan z / (1 - tan z ^ 2) :=\n  by\n  by_cases h : \u2200 k : \u2124, z \u2260 (2 * k + 1) * \u03c0 / 2\n  \u00b7 rw [two_mul, two_mul, sq, tan_add (Or.inl \u27e8h, h\u27e9)]\n  \u00b7 rw [not_forall_not] at h\n    rw [two_mul, two_mul, sq, tan_add (Or.inr \u27e8h, h\u27e9)]\n#align complex.tan_two_mul Complex.tan_two_mul\n\ntheorem tan_add_mul_i {x y : \u2102}\n    (h :\n      ((\u2200 k : \u2124, x \u2260 (2 * k + 1) * \u03c0 / 2) \u2227 \u2200 l : \u2124, y * I \u2260 (2 * l + 1) * \u03c0 / 2) \u2228\n        (\u2203 k : \u2124, x = (2 * k + 1) * \u03c0 / 2) \u2227 \u2203 l : \u2124, y * I = (2 * l + 1) * \u03c0 / 2) :\n    tan (x + y * I) = (tan x + tanh y * I) / (1 - tan x * tanh y * I) := by\n  rw [tan_add h, tan_mul_I, mul_assoc]\n#align complex.tan_add_mul_I Complex.tan_add_mul_i\n\ntheorem tan_eq {z : \u2102}\n    (h :\n      ((\u2200 k : \u2124, (z.re : \u2102) \u2260 (2 * k + 1) * \u03c0 / 2) \u2227\n          \u2200 l : \u2124, (z.im : \u2102) * I \u2260 (2 * l + 1) * \u03c0 / 2) \u2228\n        (\u2203 k : \u2124, (z.re : \u2102) = (2 * k + 1) * \u03c0 / 2) \u2227\n          \u2203 l : \u2124, (z.im : \u2102) * I = (2 * l + 1) * \u03c0 / 2) :\n    tan z = (tan z.re + tanh z.im * I) / (1 - tan z.re * tanh z.im * I) := by\n  convert tan_add_mul_I h <;> exact (re_add_im z).symm\n#align complex.tan_eq Complex.tan_eq\n\nopen Topology\n\ntheorem continuousOn_tan : ContinuousOn tan { x | cos x \u2260 0 } :=\n  continuousOn_sin.div continuousOn_cos fun x => id\n#align complex.continuous_on_tan Complex.continuousOn_tan\n\n@[continuity]\ntheorem continuous_tan : Continuous fun x : { x | cos x \u2260 0 } => tan x :=\n  continuousOn_iff_continuous_restrict.1 continuousOn_tan\n#align complex.continuous_tan Complex.continuous_tan\n\ntheorem cos_eq_iff_quadratic {z w : \u2102} :\n    cos z = w \u2194 exp (z * I) ^ 2 - 2 * w * exp (z * I) + 1 = 0 :=\n  by\n  rw [\u2190 sub_eq_zero]\n  field_simp [cos, exp_neg, exp_ne_zero]\n  refine' Eq.congr _ rfl\n  ring\n#align complex.cos_eq_iff_quadratic Complex.cos_eq_iff_quadratic\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (w \u00abexpr \u2260 \u00bb 0) -/\ntheorem cos_surjective : Function.Surjective cos :=\n  by\n  intro x\n  obtain \u27e8w, w\u2080, hw\u27e9 : \u2203 (w : _)(_ : w \u2260 0), 1 * w * w + -2 * x * w + 1 = 0 :=\n    by\n    rcases exists_quadratic_eq_zero one_ne_zero\n        \u27e8_, (cpow_nat_inv_pow _ two_ne_zero).symm.trans <| pow_two _\u27e9 with\n      \u27e8w, hw\u27e9\n    refine' \u27e8w, _, hw\u27e9\n    rintro rfl\n    simpa only [zero_add, one_ne_zero, MulZeroClass.mul_zero] using hw\n  refine' \u27e8log w / I, cos_eq_iff_quadratic.2 _\u27e9\n  rw [div_mul_cancel _ I_ne_zero, exp_log w\u2080]\n  convert hw\n  ring\n#align complex.cos_surjective Complex.cos_surjective\n\n@[simp]\ntheorem range_cos : range cos = Set.univ :=\n  cos_surjective.range_eq\n#align complex.range_cos Complex.range_cos\n\ntheorem sin_surjective : Function.Surjective sin :=\n  by\n  intro x\n  rcases cos_surjective x with \u27e8z, rfl\u27e9\n  exact \u27e8z + \u03c0 / 2, sin_add_pi_div_two z\u27e9\n#align complex.sin_surjective Complex.sin_surjective\n\n@[simp]\ntheorem range_sin : range sin = Set.univ :=\n  sin_surjective.range_eq\n#align complex.range_sin Complex.range_sin\n\nend Complex\n\nnamespace Real\n\nopen Real\n\ntheorem cos_eq_zero_iff {\u03b8 : \u211d} : cos \u03b8 = 0 \u2194 \u2203 k : \u2124, \u03b8 = (2 * k + 1) * \u03c0 / 2 := by\n  exact_mod_cast @Complex.cos_eq_zero_iff \u03b8\n#align real.cos_eq_zero_iff Real.cos_eq_zero_iff\n\ntheorem cos_ne_zero_iff {\u03b8 : \u211d} : cos \u03b8 \u2260 0 \u2194 \u2200 k : \u2124, \u03b8 \u2260 (2 * k + 1) * \u03c0 / 2 := by\n  rw [\u2190 not_exists, not_iff_not, cos_eq_zero_iff]\n#align real.cos_ne_zero_iff Real.cos_ne_zero_iff\n\ntheorem cos_eq_cos_iff {x y : \u211d} : cos x = cos y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = 2 * k * \u03c0 - x :=\n  by exact_mod_cast @Complex.cos_eq_cos_iff x y\n#align real.cos_eq_cos_iff Real.cos_eq_cos_iff\n\ntheorem sin_eq_sin_iff {x y : \u211d} :\n    sin x = sin y \u2194 \u2203 k : \u2124, y = 2 * k * \u03c0 + x \u2228 y = (2 * k + 1) * \u03c0 - x := by\n  exact_mod_cast @Complex.sin_eq_sin_iff x y\n#align real.sin_eq_sin_iff Real.sin_eq_sin_iff\n\ntheorem lt_sin_mul {x : \u211d} (hx : 0 < x) (hx' : x < 1) : x < sin (\u03c0 / 2 * x) := by\n  simpa [mul_comm x] using\n    strictConcaveOn_sin_Icc.2 \u27e8le_rfl, pi_pos.le\u27e9 \u27e8pi_div_two_pos.le, half_le_self pi_pos.le\u27e9\n      pi_div_two_pos.ne (sub_pos.2 hx') hx\n#align real.lt_sin_mul Real.lt_sin_mul\n\ntheorem le_sin_mul {x : \u211d} (hx : 0 \u2264 x) (hx' : x \u2264 1) : x \u2264 sin (\u03c0 / 2 * x) := by\n  simpa [mul_comm x] using\n    strict_concave_on_sin_Icc.concave_on.2 \u27e8le_rfl, pi_pos.le\u27e9\n      \u27e8pi_div_two_pos.le, half_le_self pi_pos.le\u27e9 (sub_nonneg.2 hx') hx\n#align real.le_sin_mul Real.le_sin_mul\n\ntheorem mul_lt_sin {x : \u211d} (hx : 0 < x) (hx' : x < \u03c0 / 2) : 2 / \u03c0 * x < sin x :=\n  by\n  rw [\u2190 inv_div]\n  simpa [-inv_div, pi_div_two_pos.ne'] using @lt_sin_mul ((\u03c0 / 2)\u207b\u00b9 * x) _ _\n  \u00b7 exact mul_pos (inv_pos.2 pi_div_two_pos) hx\n  \u00b7 rwa [\u2190 div_eq_inv_mul, div_lt_one pi_div_two_pos]\n#align real.mul_lt_sin Real.mul_lt_sin\n\n/-- In the range `[0, \u03c0 / 2]`, we have a linear lower bound on `sin`. This inequality forms one half\nof Jordan's inequality, the other half is `real.sin_lt` -/\ntheorem mul_le_sin {x : \u211d} (hx : 0 \u2264 x) (hx' : x \u2264 \u03c0 / 2) : 2 / \u03c0 * x \u2264 sin x :=\n  by\n  rw [\u2190 inv_div]\n  simpa [-inv_div, pi_div_two_pos.ne'] using @le_sin_mul ((\u03c0 / 2)\u207b\u00b9 * x) _ _\n  \u00b7 exact mul_nonneg (inv_nonneg.2 pi_div_two_pos.le) hx\n  \u00b7 rwa [\u2190 div_eq_inv_mul, div_le_one pi_div_two_pos]\n#align real.mul_le_sin Real.mul_le_sin\n\nend Real\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/SpecialFunctions/Trigonometric/Complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.719383858320693}}
{"text": "open nat \n \nvariables one x n p q d e : nat\n\nvariable gcd (a b : nat) : nat\nvariable phi (n   : nat) : nat\n\nvariable prime     (a           : nat) : Prop\nvariable congruent (a b modulus : nat) : Prop\n\npremise nDef   : n = p * q \npremise pPhi   : phi p = p - one \npremise qPhi   : phi q = q - one \npremise nPhi   : phi n = (q - one) * (p - one) \npremise xLess  : x < n \npremise pIsPrime : prime p \npremise qIsPrime : prime q \npremise de_Inverse : (congruent (d * e) one (phi n))\npremise OneMul : \u2200 n : nat, one * n = n \npremise OneExp : \u2200 n : nat, one ^ n = one \npremise ExpOne : \u2200 n : nat, n ^ one = n\npremise ExpSum  (a b c : nat) : (a ^ b) * (a ^ c) = a ^ (b + c) \npremise ExpMul  (a b c : nat) : (a ^ b) ^ c = a ^ (b * c) \npremise ExpSwap (a b c : nat) : (a ^ b) ^ c = (a ^ c) ^ b\npremise ModuloDef (a b n : nat) : congruent a b n \u2194 \u2203 c, a = b + (c * n) \npremise CongruenceReflexivity (a b n : nat) : congruent a b n \u2192 congruent b a n \npremise CongruenceScaling (a b n k : nat) : congruent a b n \u2192 congruent (a * k) (b * k) n \npremise CongruenceExponentiation (a b n k : nat) : congruent a b n \u2192 congruent (a ^ k) (b ^ k) n\npremise EqMul (a b k : nat) : a = b \u2192 k * a = k * b \npremise MulDistrib (a b c : nat) : a * (b + c) = (a * b) + (a * c)\npremise Euler (a b : nat) : gcd a b = one \u2192 congruent (a ^ (phi b)) one b \npremise GCDProperty (a b c : nat) : gcd a (b * c) \u2260 one \u2192 prime b \u2192 prime c \u2192 a < b * c \u2192  (((\u2203 n, a = n * b) \u2227 (gcd a c = one)) \u2228   ((\u2203 n, a = n * c) \u2227 (gcd a b = one)))\n\ntheorem ProofCoprime (t : nat) : gcd x n = one \u2192 congruent (x * ((x ^ (phi n)) ^ t)) x n := \nassume H1    : gcd x n = one, \nhave   H2    : congruent (x ^ (phi n)) one n,     from       Euler x n H1, \nhave   Hexpt : congruent (x ^ (phi n)) one n \u2192                 congruent ((x ^ (phi n)) ^ t) (one ^ t) n,     from       CongruenceExponentiation (x ^ (phi n)) one n t, \nhave   H3    : congruent ((x ^ (phi n)) ^ t) (one ^ t) n,     from       Hexpt H2, \nhave   Honet : one ^ t = one,     from       OneExp t, \nhave   H4    : congruent ((x ^ (phi n)) ^ t) one n,     from       eq.subst Honet H3, \nhave   Hmulx : congruent ((x ^ (phi n)) ^ t) one n \u2192                 congruent (((x ^ (phi n)) ^ t) * x) (one * x) n,     from       CongruenceScaling ((x ^ (phi n)) ^ t) one n x, \nhave   H5    : congruent (((x ^ (phi n)) ^ t) * x) (one * x) n,     from       Hmulx H4, \nhave   Honex : one * x = x,     from       OneMul x,\nhave   H6    : congruent (((x ^ (phi n)) ^ t) * x) x n,     from       eq.subst Honex H5, \nshow           congruent (x * ((x ^ (phi n)) ^ t)) x n,     from       eq.subst (mul.comm ((x ^ (phi n)) ^ t) x) H6\n\ntheorem ProofNotCoprime_Part1 : gcd x n \u2260 one \u2192 (((\u2203 n, x = n * p) \u2227 (gcd x q = one)) \u2228   ((\u2203 n, x = n * q) \u2227 (gcd x p = one))) := \nassume H1  : gcd x n \u2260 one, \nhave   H2  : x < p * q,     from eq.subst nDef xLess, \nhave   H3  : gcd x (p * q) \u2260 one,     from eq.subst nDef H1, \nshow         (((\u2203 n, x = n * p) \u2227 (gcd x q = one)) \u2228                ((\u2203 n, x = n * q) \u2227 (gcd x p = one))),     from GCDProperty x p q H3 pIsPrime qIsPrime H2\n\ntheorem ProofNotCoprime_Part2 (t : nat) : (\u2203 n, x = n * p) \u2227 (gcd x q = one) \u2192 congruent (x * ((x ^ (phi n)) ^ t)) x n := \nassume H1 : (\u2203 n, x = n * p) \u2227 (gcd x q = one), \nhave gcd x q = one,     from and.elim_right H1,  \nhave congruent (x ^ (phi q)) one q,     from Euler x q this, \nhave congruent ((x ^ (phi q)) ^ t) (one ^ t) q,     from CongruenceExponentiation (x ^ (phi q)) one q t this, \nhave congruent ((x ^ (phi q)) ^ t) one q,     from eq.subst (OneExp t) this, \nhave congruent (((x ^ (phi q)) ^ t) ^ (p - one)) (one ^ (p - one)) q,     from CongruenceExponentiation          ((x ^ (phi q)) ^ t) one q (p - one) this,\nhave congruent (((x ^ (phi q)) ^ t) ^ (p - one)) one q,     from eq.subst (OneExp (p - one)) this,  \nhave congruent (((x ^ (phi q)) ^ (p - one)) ^ t) one q,     from eq.subst (ExpSwap (x ^ (phi q)) t (p - one)) this, \nhave congruent ((x ^ ((phi q) * (p - one))) ^ t) one q,     from eq.subst (ExpMul x (phi q) (p - one)) this, \nhave congruent ((x ^ ((q - one) * (p - one))) ^ t) one q,     from eq.subst qPhi this, \nhave congruent ((x ^ (phi n)) ^ t) one q,     from eq.subst (eq.symm nPhi) this, \nhave \u2203 c, ((x ^ (phi n)) ^ t) = one + (c * q),     from (iff.elim_left (ModuloDef ((x ^ (phi n)) ^ t) one q)) this, \nexists.elim this (fun (v : nat) (Hv : ((x ^ (phi n)) ^ t) = one + (v * q)), \nhave x * ((x ^ (phi n)) ^ t) = x * (one + (v * q)),     from EqMul ((x ^ (phi n)) ^ t) (one + (v * q)) x Hv, \nhave x * ((x ^ (phi n)) ^ t) = (x * one) + (x * (v * q)),     from eq.trans this (MulDistrib x one (v * q)), \nhave x * ((x ^ (phi n)) ^ t) = (one * x) + (x * (v * q)),     from eq.subst (mul.comm x one) this, \nhave Hxvq : x * ((x ^ (phi n)) ^ t) = x + (x * (v * q)),     from eq.subst (OneMul x) this, \nhave \u2203 n, x = n * p,     from and.elim_left H1, \nexists.elim this (fun (w : nat) (Hw : x = w * p), \nhave x * ((x ^ (phi n)) ^ t) = x + ((w * p) * (v * q)),     from eq.subst Hw Hxvq, \nhave x * ((x ^ (phi n)) ^ t) = x + (w * (p * (v * q))),     from eq.subst (mul.assoc w p (v * q)) this, \nhave x * ((x ^ (phi n)) ^ t) = x + (w * (p * (q * v))),     from eq.subst (mul.comm v q) this, \nhave x * ((x ^ (phi n)) ^ t) = x + (w * ((p * q) * v)),     from eq.subst (eq.symm (mul.assoc p q v)) this, \nhave x * ((x ^ (phi n)) ^ t) = x + (w * (n * v)),     from eq.subst (eq.symm nDef) this,\nhave x * ((x ^ (phi n)) ^ t) = x + (w * (v * n)),     from eq.subst (mul.comm n v) this, \nhave x * ((x ^ (phi n)) ^ t) = x + (w * v) * n,     from eq.subst (eq.symm (mul.assoc w v n)) this, \nhave \u2203 i, x * ((x ^ (phi n)) ^ t) = x + i * n,     from exists.intro (w * v) this, \nshow congruent (x * ((x ^ (phi n)) ^ t)) x n,     from (iff.elim_right          (ModuloDef (x * ((x ^ (phi n)) ^ t)) x n)) this))\n\ntheorem ProofFinal (t : nat) : congruent (x * ((x ^ (phi n)) ^ t)) x n \u2192  congruent (x ^ (one + ((phi n) * t))) x n :=  \nassume H1    : congruent (x * ((x ^ (phi n)) ^ t)) x n, \nhave   H2    : congruent (x * (x ^ ((phi n) * t))) x n,     from eq.subst (ExpMul x (phi n) t) H1, \nhave   Honex : x = x ^ one,     from       eq.symm (ExpOne x), \nhave   H3    : congruent ((x ^ one) * (x ^ ((phi n) * t))) x n,     from eq.subst Honex H2, \nshow           congruent (x ^ (one + ((phi n) * t))) x n,     from eq.subst (ExpSum x one ((phi n) * t)) H3 \n", "meta": {"author": "GGFSilva", "repo": "LeanCryptographyProof", "sha": "bea98d6201546f1e38a08fd3eb7be494e589b006", "save_path": "github-repos/lean/GGFSilva-LeanCryptographyProof", "path": "github-repos/lean/GGFSilva-LeanCryptographyProof/LeanCryptographyProof-bea98d6201546f1e38a08fd3eb7be494e589b006/Lean Proof RSA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7193565196904208}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport data.polynomial.derivative\nimport data.polynomial.algebra_map\nimport data.mv_polynomial.pderiv\nimport data.nat.choose.sum\nimport linear_algebra.basis\nimport ring_theory.polynomial.pochhammer\nimport tactic.omega\n\n/-!\n# Bernstein polynomials\n\nThe definition of the Bernstein polynomials\n```\nbernstein_polynomial (R : Type*) [comm_ring R] (n \u03bd : \u2115) : polynomial R :=\n(choose n \u03bd) * X^\u03bd * (1 - X)^(n - \u03bd)\n```\nand the fact that for `\u03bd : fin (n+1)` these are linearly independent over `\u211a`.\n\nWe prove the basic identities\n* `(finset.range (n + 1)).sum (\u03bb \u03bd, bernstein_polynomial R n \u03bd) = 1`\n* `(finset.range (n + 1)).sum (\u03bb \u03bd, \u03bd \u2022 bernstein_polynomial R n \u03bd) = n \u2022 X`\n* `(finset.range (n + 1)).sum (\u03bb \u03bd, (\u03bd * (\u03bd-1)) \u2022 bernstein_polynomial R n \u03bd) = (n * (n-1)) \u2022 X^2`\n\n## Notes\n\nSee also `analysis.special_functions.bernstein`, which defines the Bernstein approximations\nof a continuous function `f : C([0,1], \u211d)`, and shows that these converge uniformly to `f`.\n-/\n\nnoncomputable theory\n\n\nopen nat (choose)\nopen polynomial (X)\n\nvariables (R : Type*) [comm_ring R]\n\n/--\n`bernstein_polynomial R n \u03bd` is `(choose n \u03bd) * X^\u03bd * (1 - X)^(n - \u03bd)`.\n\nAlthough the coefficients are integers, it is convenient to work over an arbitrary commutative ring.\n-/\ndef bernstein_polynomial (n \u03bd : \u2115) : polynomial R := choose n \u03bd * X^\u03bd * (1 - X)^(n - \u03bd)\n\nexample : bernstein_polynomial \u2124 3 2 = 3 * X^2 - 3 * X^3 :=\nbegin\n  norm_num [bernstein_polynomial, choose],\n  ring,\nend\n\nnamespace bernstein_polynomial\n\nlemma eq_zero_of_lt {n \u03bd : \u2115} (h : n < \u03bd) : bernstein_polynomial R n \u03bd = 0 :=\nby simp [bernstein_polynomial, nat.choose_eq_zero_of_lt h]\n\nsection\nvariables {R} {S : Type*} [comm_ring S]\n\n@[simp] lemma map (f : R \u2192+* S) (n \u03bd : \u2115) :\n  (bernstein_polynomial R n \u03bd).map f = bernstein_polynomial S n \u03bd :=\nby simp [bernstein_polynomial]\n\nend\n\nlemma flip (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (bernstein_polynomial R n \u03bd).comp (1-X) = bernstein_polynomial R n (n-\u03bd) :=\nbegin\n  dsimp [bernstein_polynomial],\n  simp [h, nat.sub_sub_assoc, mul_right_comm],\nend\n\nlemma flip' (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  bernstein_polynomial R n \u03bd = (bernstein_polynomial R n (n-\u03bd)).comp (1-X) :=\nbegin\n  rw [\u2190flip _ _ _ h, polynomial.comp_assoc],\n  simp,\nend\n\nlemma eval_at_0 (n \u03bd : \u2115) : (bernstein_polynomial R n \u03bd).eval 0 = if \u03bd = 0 then 1 else 0 :=\nbegin\n  dsimp [bernstein_polynomial],\n  split_ifs,\n  { subst h, simp, },\n  { simp [zero_pow (nat.pos_of_ne_zero h)], },\nend\n\nlemma eval_at_1 (n \u03bd : \u2115) : (bernstein_polynomial R n \u03bd).eval 1 = if \u03bd = n then 1 else 0 :=\nbegin\n  dsimp [bernstein_polynomial],\n  split_ifs,\n  { subst h, simp, },\n  { by_cases w : 0 < n - \u03bd,\n    { simp [zero_pow w], },\n    { simp [(show n < \u03bd, by omega), nat.choose_eq_zero_of_lt], }, },\nend.\n\nlemma derivative_succ_aux (n \u03bd : \u2115) :\n  (bernstein_polynomial R (n+1) (\u03bd+1)).derivative =\n    (n+1) * (bernstein_polynomial R n \u03bd - bernstein_polynomial R n (\u03bd + 1)) :=\nbegin\n  dsimp [bernstein_polynomial],\n  suffices :\n    \u2191((n + 1).choose (\u03bd + 1)) * ((\u2191\u03bd + 1) * X ^ \u03bd) * (1 - X) ^ (n - \u03bd)\n      -(\u2191((n + 1).choose (\u03bd + 1)) * X ^ (\u03bd + 1) * (\u2191(n - \u03bd) * (1 - X) ^ (n - \u03bd - 1))) =\n    (\u2191n + 1) * (\u2191(n.choose \u03bd) * X ^ \u03bd * (1 - X) ^ (n - \u03bd) -\n         \u2191(n.choose (\u03bd + 1)) * X ^ (\u03bd + 1) * (1 - X) ^ (n - (\u03bd + 1))),\n  { simpa [polynomial.derivative_pow, \u2190sub_eq_add_neg], },\n  conv_rhs { rw mul_sub, },\n  -- We'll prove the two terms match up separately.\n  refine congr (congr_arg has_sub.sub _) _,\n  { simp only [\u2190mul_assoc],\n    refine congr (congr_arg (*) (congr (congr_arg (*) _) rfl)) rfl,\n    -- Now it's just about binomial coefficients\n    exact_mod_cast congr_arg (\u03bb m : \u2115, (m : polynomial R)) (nat.succ_mul_choose_eq n \u03bd).symm, },\n  { rw nat.sub_sub, rw [\u2190mul_assoc,\u2190mul_assoc], congr' 1,\n    rw mul_comm , rw [\u2190mul_assoc,\u2190mul_assoc],  congr' 1,\n    norm_cast,\n    congr' 1,\n    convert (nat.choose_mul_succ_eq n (\u03bd + 1)).symm using 1,\n    { convert mul_comm _ _ using 2,\n      simp, },\n    { apply mul_comm, }, },\nend\n\nlemma derivative_succ (n \u03bd : \u2115) :\n  (bernstein_polynomial R n (\u03bd+1)).derivative =\n    n * (bernstein_polynomial R (n-1) \u03bd - bernstein_polynomial R (n-1) (\u03bd+1)) :=\nbegin\n  cases n,\n  { simp [bernstein_polynomial], },\n  { apply derivative_succ_aux, }\nend\n\nlemma derivative_zero (n : \u2115) :\n  (bernstein_polynomial R n 0).derivative = -n * bernstein_polynomial R (n-1) 0 :=\nbegin\n  dsimp [bernstein_polynomial],\n  simp [polynomial.derivative_pow],\nend\n\nlemma iterate_derivative_at_0_eq_zero_of_lt (n : \u2115) {\u03bd k : \u2115} :\n  k < \u03bd \u2192 (polynomial.derivative^[k] (bernstein_polynomial R n \u03bd)).eval 0 = 0 :=\nbegin\n  cases \u03bd,\n  { rintro \u27e8\u27e9, },\n  { intro w,\n    replace w := nat.lt_succ_iff.mp w,\n    revert w,\n    induction k with k ih generalizing n \u03bd,\n    { simp [eval_at_0], },\n    { simp only [derivative_succ, int.coe_nat_eq_zero, int.nat_cast_eq_coe_nat, mul_eq_zero,\n        function.comp_app, function.iterate_succ,\n        polynomial.iterate_derivative_sub, polynomial.iterate_derivative_cast_nat_mul,\n        polynomial.eval_mul, polynomial.eval_nat_cast, polynomial.eval_sub],\n      intro h,\n      apply mul_eq_zero_of_right,\n      rw ih,\n      simp only [sub_zero],\n      convert @ih (n-1) (\u03bd-1) _,\n      { omega, },\n      { omega, },\n      { exact le_of_lt h, }, }, },\nend\n\n@[simp]\nlemma iterate_derivative_succ_at_0_eq_zero (n \u03bd : \u2115) :\n  (polynomial.derivative^[\u03bd] (bernstein_polynomial R n (\u03bd+1))).eval 0 = 0 :=\niterate_derivative_at_0_eq_zero_of_lt R n (lt_add_one \u03bd)\n\nopen polynomial\n\n/-- A Pochhammer identity that is useful for `bernstein_polynomial.iterate_derivative_at_0_aux\u2082`. -/\nlemma iterate_derivative_at_0_aux\u2081 (n k : \u2115) :\n  k * polynomial.eval (k-n) (pochhammer \u2115 n) = (k-n) * polynomial.eval (k-n+1) (pochhammer \u2115 n) :=\nbegin\n  have p :=\n    congr_arg (eval (k-n)) ((pochhammer_succ_right \u2115 n).symm.trans (pochhammer_succ_left \u2115 n)),\n  simp only [nat.cast_id, eval_X, eval_one, eval_mul, eval_nat_cast, eval_add, eval_comp] at p,\n  rw [mul_comm] at p,\n  rw \u2190p,\n  by_cases h : n \u2264 k,\n  { rw nat.sub_add_cancel h, },\n  { simp only [not_le] at h,\n    simp only [mul_eq_mul_right_iff],\n    right,\n    rw nat.sub_eq_zero_of_le (le_of_lt h),\n    simp only [pochhammer_eval_zero, ite_eq_right_iff],\n    rintro rfl,\n    cases h, },\nend\n\nlemma iterate_derivative_at_0_aux\u2082 (n k : \u2115) :\n  (\u2191k) * polynomial.eval \u2191(k-n) (pochhammer R n) =\n    \u2191(k-n) * polynomial.eval (\u2191(k-n+1)) (pochhammer R n) :=\nby simpa using congr_arg (algebra_map \u2115 R) (iterate_derivative_at_0_aux\u2081 n k)\n\n@[simp]\n\n\nlemma iterate_derivative_at_0_ne_zero [char_zero R] (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (polynomial.derivative^[\u03bd] (bernstein_polynomial R n \u03bd)).eval 0 \u2260 0 :=\nbegin\n  simp only [int.coe_nat_eq_zero, bernstein_polynomial.iterate_derivative_at_0, ne.def,\n    nat.cast_eq_zero],\n  simp only [\u2190pochhammer_eval_cast],\n  norm_cast,\n  apply ne_of_gt,\n  by_cases h : \u03bd = 0,\n  { subst h, simp, },\n  { apply pochhammer_pos,\n    omega, },\nend\n\n/-!\nRather than redoing the work of evaluating the derivatives at 1,\nwe use the symmetry of the Bernstein polynomials.\n-/\nlemma iterate_derivative_at_1_eq_zero_of_lt (n : \u2115) {\u03bd k : \u2115} :\n  k < n - \u03bd \u2192 (polynomial.derivative^[k] (bernstein_polynomial R n \u03bd)).eval 1 = 0 :=\nbegin\n  intro w,\n  rw flip' _ _ _ (show \u03bd \u2264 n, by omega),\n  simp [polynomial.eval_comp, iterate_derivative_at_0_eq_zero_of_lt R n w],\nend\n\n@[simp]\nlemma iterate_derivative_at_1 (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (polynomial.derivative^[n-\u03bd] (bernstein_polynomial R n \u03bd)).eval 1 =\n    (-1)^(n-\u03bd) * (pochhammer R (n - \u03bd)).eval (\u03bd + 1) :=\nbegin\n  rw flip' _ _ _ h,\n  simp [polynomial.eval_comp, h],\n  by_cases h' : n = \u03bd,\n  { subst h', simp, },\n  { replace h : \u03bd < n, { omega, },\n    congr,\n    norm_cast,\n    congr,\n    omega, },\nend\n\nlemma iterate_derivative_at_1_ne_zero [char_zero R] (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (polynomial.derivative^[n-\u03bd] (bernstein_polynomial R n \u03bd)).eval 1 \u2260 0 :=\nbegin\n  simp only [bernstein_polynomial.iterate_derivative_at_1 _ _ _ h, ne.def,\n    int.coe_nat_eq_zero, neg_one_pow_mul_eq_zero_iff, nat.cast_eq_zero],\n    rw \u2190nat.cast_succ,\n  simp only [\u2190pochhammer_eval_cast],\n  norm_cast,\n  apply ne_of_gt,\n  apply pochhammer_pos,\n  exact nat.succ_pos \u03bd,\nend\n\nopen submodule\n\nlemma linear_independent_aux (n k : \u2115) (h : k \u2264 n + 1):\n  linear_independent \u211a (\u03bb \u03bd : fin k, bernstein_polynomial \u211a n \u03bd) :=\nbegin\n  induction k with k ih,\n  { apply linear_independent_empty_type,\n    rintro \u27e8\u27e8n, \u27e8\u27e9\u27e9\u27e9, },\n  { apply linear_independent_fin_succ'.mpr,\n    fsplit,\n    { exact ih (le_of_lt h), },\n    { -- The actual work!\n      -- We show that the (n-k)-th derivative at 1 doesn't vanish,\n      -- but vanishes for everything in the span.\n      clear ih,\n      simp only [nat.succ_eq_add_one, add_le_add_iff_right] at h,\n      simp only [fin.coe_last, fin.init_def],\n      dsimp,\n      apply not_mem_span_of_apply_not_mem_span_image ((polynomial.derivative_lhom \u211a)^(n-k)),\n      simp only [not_exists, not_and, submodule.mem_map, submodule.span_image],\n      intros p m,\n      apply_fun (polynomial.eval (1 : \u211a)),\n      simp only [polynomial.derivative_lhom_coe, linear_map.pow_apply],\n      -- The right hand side is nonzero,\n      -- so it will suffice to show the left hand side is always zero.\n      suffices : (polynomial.derivative^[n-k] p).eval 1 = 0,\n      { rw [this],\n        exact (iterate_derivative_at_1_ne_zero \u211a n k h).symm, },\n      apply span_induction m,\n      { simp,\n        rintro \u27e8a, w\u27e9, simp only [fin.coe_mk],\n        rw [iterate_derivative_at_1_eq_zero_of_lt \u211a _ (show n - k < n - a, by omega)], },\n      { simp, },\n      { intros x y hx hy, simp [hx, hy], },\n      { intros a x h, simp [h], }, }, },\nend\n\n/--\nThe Bernstein polynomials are linearly independent.\n\nWe prove by induction that the collection of `bernstein_polynomial n \u03bd` for `\u03bd = 0, ..., k`\nare linearly independent.\nThe inductive step relies on the observation that the `(n-k)`-th derivative, evaluated at 1,\nannihilates `bernstein_polynomial n \u03bd` for `\u03bd < k`, but has a nonzero value at `\u03bd = k`.\n-/\n\nlemma linear_independent (n : \u2115) :\n  linear_independent \u211a (\u03bb \u03bd : fin (n+1), bernstein_polynomial \u211a n \u03bd) :=\nlinear_independent_aux n (n+1) (le_refl _)\n\nlemma sum (n : \u2115) : (finset.range (n + 1)).sum (\u03bb \u03bd, bernstein_polynomial R n \u03bd) = 1 :=\nbegin\n  -- We calculate `(x + (1-x))^n` in two different ways.\n  conv { congr, congr, skip, funext, dsimp [bernstein_polynomial], rw [mul_assoc, mul_comm], },\n  rw \u2190add_pow,\n  simp,\nend\n\n\nopen polynomial\nopen mv_polynomial\n\nlemma sum_smul (n : \u2115) :\n  (finset.range (n + 1)).sum (\u03bb \u03bd, \u03bd \u2022 bernstein_polynomial R n \u03bd) = n \u2022 X :=\nbegin\n  -- We calculate the `x`-derivative of `(x+y)^n`, evaluated at `y=(1-x)`,\n  -- either directly or by using the binomial theorem.\n\n  -- We'll work in `mv_polynomial bool R`.\n  let x : mv_polynomial bool R := mv_polynomial.X tt,\n  let y : mv_polynomial bool R := mv_polynomial.X ff,\n\n  have pderiv_tt_x : pderiv tt x = 1, { simp [x], },\n  have pderiv_tt_y : pderiv tt y = 0, { simp [pderiv_X, y], },\n\n  let e : bool \u2192 polynomial R := \u03bb i, cond i X (1-X),\n\n  -- Start with `(x+y)^n = (x+y)^n`,\n  -- take the `x`-derivative, evaluate at `x=X, y=1-X`, and multiply by `X`:\n  have h : (x+y)^n = (x+y)^n := rfl,\n  apply_fun (pderiv tt) at h,\n  apply_fun (aeval e) at h,\n  apply_fun (\u03bb p, p * X) at h,\n\n  -- On the left hand side we'll use the binomial theorem, then simplify.\n\n  -- We first prepare a tedious rewrite:\n  have w : \u2200 k : \u2115,\n    \u2191k * polynomial.X ^ (k - 1) * (1 - polynomial.X) ^ (n - k) * \u2191(n.choose k) * polynomial.X =\n      k \u2022 bernstein_polynomial R n k,\n  { rintro (_|k),\n    { simp, },\n    { dsimp [bernstein_polynomial],\n      simp only [\u2190nat_cast_mul, nat.succ_eq_add_one, nat.add_succ_sub_one, add_zero, pow_succ],\n      push_cast,\n      ring, }, },\n\n  conv at h {\n    to_lhs,\n    rw [add_pow, (pderiv tt).map_sum, (mv_polynomial.aeval e).map_sum, finset.sum_mul],\n    -- Step inside the sum:\n    apply_congr, skip,\n    simp [pderiv_mul, pderiv_tt_x, pderiv_tt_y, e, w], },\n  -- On the right hand side, we'll just simplify.\n  conv at h {\n    to_rhs,\n    rw [pderiv_pow, (pderiv tt).map_add, pderiv_tt_x, pderiv_tt_y],\n    simp [e] },\n  simpa using h,\nend\n\nlemma sum_mul_smul (n : \u2115) :\n  (finset.range (n + 1)).sum (\u03bb \u03bd, (\u03bd * (\u03bd-1)) \u2022 bernstein_polynomial R n \u03bd) =\n    (n * (n-1)) \u2022 X^2 :=\nbegin\n  -- We calculate the second `x`-derivative of `(x+y)^n`, evaluated at `y=(1-x)`,\n  -- either directly or by using the binomial theorem.\n\n  -- We'll work in `mv_polynomial bool R`.\n  let x : mv_polynomial bool R := mv_polynomial.X tt,\n  let y : mv_polynomial bool R := mv_polynomial.X ff,\n\n  have pderiv_tt_x : pderiv tt x = 1, { simp [x], },\n  have pderiv_tt_y : pderiv tt y = 0, { simp [pderiv_X, y], },\n\n  let e : bool \u2192 polynomial R := \u03bb i, cond i X (1-X),\n\n  -- Start with `(x+y)^n = (x+y)^n`,\n  -- take the second `x`-derivative, evaluate at `x=X, y=1-X`, and multiply by `X`:\n  have h : (x+y)^n = (x+y)^n := rfl,\n  apply_fun (pderiv tt) at h,\n  apply_fun (pderiv tt) at h,\n  apply_fun (aeval e) at h,\n  apply_fun (\u03bb p, p * X^2) at h,\n\n  -- On the left hand side we'll use the binomial theorem, then simplify.\n\n  -- We first prepare a tedious rewrite:\n  have w : \u2200 k : \u2115,\n    \u2191k * (\u2191(k-1) * polynomial.X ^ (k - 1 - 1)) *\n      (1 - polynomial.X) ^ (n - k) * \u2191(n.choose k) * polynomial.X^2 =\n      (k * (k-1)) \u2022 bernstein_polynomial R n k,\n  { rintro (_|k),\n    { simp, },\n    { rcases k with (_|k),\n      { simp, },\n      { dsimp [bernstein_polynomial],\n        simp only [\u2190nat_cast_mul, nat.succ_eq_add_one, nat.add_succ_sub_one, add_zero, pow_succ],\n        push_cast,\n        ring, }, }, },\n\n  conv at h {\n    to_lhs,\n    rw [add_pow, (pderiv tt).map_sum, (pderiv tt).map_sum, (mv_polynomial.aeval e).map_sum,\n      finset.sum_mul],\n    -- Step inside the sum:\n    apply_congr, skip,\n    simp [pderiv_mul, pderiv_tt_x, pderiv_tt_y, e, w] },\n  -- On the right hand side, we'll just simplify.\n  conv at h {\n    to_rhs,\n    simp only [pderiv_one, pderiv_mul, pderiv_pow, pderiv_nat_cast, (pderiv tt).map_add,\n      pderiv_tt_x, pderiv_tt_y],\n    simp [e, smul_smul] },\n  simpa using h,\nend\n\n/--\nA certain linear combination of the previous three identities,\nwhich we'll want later.\n-/\nlemma variance (n : \u2115) :\n  (finset.range (n+1)).sum (\u03bb \u03bd, (n \u2022 polynomial.X - \u03bd)^2 * bernstein_polynomial R n \u03bd) =\n    n \u2022 polynomial.X * (1 - polynomial.X) :=\nbegin\n  have p :\n    (finset.range (n+1)).sum (\u03bb \u03bd, (\u03bd * (\u03bd-1)) \u2022 bernstein_polynomial R n \u03bd) +\n    (1 - (2 * n) \u2022 polynomial.X) * (finset.range (n+1)).sum (\u03bb \u03bd, \u03bd \u2022 bernstein_polynomial R n \u03bd) +\n    (n^2 \u2022 X^2) * (finset.range (n+1)).sum (\u03bb \u03bd, bernstein_polynomial R n \u03bd) = _ := rfl,\n  conv at p { to_lhs,\n    rw [finset.mul_sum, finset.mul_sum, \u2190finset.sum_add_distrib, \u2190finset.sum_add_distrib],\n    simp only [\u2190nat_cast_mul],\n    simp only [\u2190mul_assoc],\n    simp only [\u2190add_mul], },\n  conv at p { to_rhs,\n    rw [sum, sum_smul, sum_mul_smul, \u2190nat_cast_mul], },\n  calc _ = _ : finset.sum_congr rfl (\u03bb k m, _)\n     ... = _ : p\n     ... = _ : _,\n  { congr' 1, simp only [\u2190nat_cast_mul] with push_cast,\n    cases k; { simp, ring, }, },\n  { simp only [\u2190nat_cast_mul] with push_cast,\n    cases n; { simp, ring, }, },\nend\n\nend bernstein_polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/polynomial/bernstein.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7193090802473248}}
{"text": "import combinatorics.simple_graph.basic\n\nnoncomputable theory\n\nopen set function\n\nnamespace simple_graph\n\n/-- The cyclic graph with `n` vertices.\n\nThis is just one possible model: we might want to consider others. -/\n@[simps] def cyclic (n : \u2115) : simple_graph (fin n) :=\n{ adj := \u03bb x y, (\u2191(x - y) : \u2115) = 1 \u2228 (\u2191(y - x) : \u2115) = 1,\n  symm := \u03bb x y, (or_comm _ _).mp,\n  loopless := \u03bb x , by {\n    simp only [or_self],\n   -- unfold has_sub.sub,\n    intro contra,\n    have h : x \u2264 x,\n    {refl},\n    rw \u2190 fin.coe_sub_iff_le at h,\n    rw h at contra,\n    simp only [tsub_self, nat.zero_ne_one] at contra,\n    exact contra,\n    }, }\n\nlemma not_cyclic_5_adj_0_2 : \u00ac(cyclic 5).adj 0 2 :=\nbegin\n  simp only [cyclic_adj, zero_sub, sub_zero, fin.coe_two, nat.succ_succ_ne_one, or_false],\n  rw [fin.coe_neg], simp only [fin.coe_two, nat.succ_sub_succ_eq_sub, tsub_zero],\n  intros r, have : 3 % 5 = 3 := rfl, rw this at r, norm_num at r,\nend\n\n@[simp] lemma coe_four  {n : \u2115} : ((4 : fin (n+5)) : \u2115) = 4 := rfl\n@[simp] lemma coe_three {n : \u2115} : ((3 : fin (n+4)) : \u2115) = 3 := rfl\n\nlemma not_cyclic_5_adj_0_3 : \u00ac(cyclic 5).adj 0 3 :=\nbegin\n  simp only [cyclic_adj, zero_sub, sub_zero, coe_three, nat.bit1_eq_one, nat.one_ne_zero, or_false],\n  rw [fin.coe_neg],\n  simp only [coe_three, nat.succ_sub_succ_eq_sub, tsub_zero],\n  intros r, have : 2 % 5 = 2 := rfl, rw this at r, norm_num at r,\nend\n\nend simple_graph\n", "meta": {"author": "ocfnash", "repo": "lean-shannon-lovasz", "sha": "e63e535599ffb3c2a7e995e1621847693dd68fab", "save_path": "github-repos/lean/ocfnash-lean-shannon-lovasz", "path": "github-repos/lean/ocfnash-lean-shannon-lovasz/lean-shannon-lovasz-e63e535599ffb3c2a7e995e1621847693dd68fab/src/to_mathlib/combinatorics/simple_graph/cyclic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7193090741394537}}
{"text": "import data.set.lattice\nimport data.set.function\nimport tactic\n\nopen set\nopen function\n\nnoncomputable theory\nopen_locale classical\n\nvariables {\u03b1 \u03b2 : Type*} [nonempty \u03b2]\nvariables (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1)\nvariables (x : \u03b1) (y : \u03b2)\n\n\n#check (inv_fun g : \u03b1 \u2192 \u03b2)\n\n#check (left_inverse_inv_fun : injective g \u2192 left_inverse (inv_fun g) g)\n#check (left_inverse_inv_fun : injective g \u2192 \u2200 y, inv_fun g (g y) = y)\n\n#check (inv_fun_eq : (\u2203 y, g y = x) \u2192 g (inv_fun g x) = x)\n\n\ndef sb_aux : \u2115 \u2192 set \u03b1\n| 0 := univ \\ (g '' univ)\n| (n + 1) := g '' (f '' sb_aux n)\n\n\ndef sb_set := \u22c3 n, sb_aux f g n\n\ndef sb_fun (x : \u03b1) : \u03b2 := if x \u2208 sb_set f g then f x else inv_fun g x\n\ntheorem sb_right_inv {x : \u03b1} (hx : x \u2209 sb_set f g) :\n    g (inv_fun g x) = x :=\nbegin\n  have : x \u2208 g '' univ,\n    contrapose! hx,\n    rw [sb_set, mem_Union],\n    use [0],\n    rw [sb_aux, mem_diff],\n    split,\n    apply mem_univ,\n    from hx,\n  \n  have : \u2203 y, g y = x,\n    simp at this,\n    from this,\n  \n  apply inv_fun_eq,\n  from this,\n\nend\n\n\ntheorem sb_injective (hf: injective f) (hg : injective g) :\n  injective (sb_fun f g) :=\nbegin\n  set A := sb_set f g with A_def,\n  set h := sb_fun f g with h_def,\n  intros x\u2081 x\u2082 hxeq,\n  show x\u2081 = x\u2082,\n    simp only [h_def, sb_fun, \u2190A_def] at hxeq,\n    by_cases xA : x\u2081 \u2208 A \u2228 x\u2082 \u2208 A,\n\n    { wlog : x\u2081 \u2208 A := xA using [x\u2081 x\u2082, x\u2082 x\u2081],\n      have x\u2082A : x\u2082 \u2208 A,\n        apply not_imp_self.mp,\n        assume x\u2082nA : x\u2082 \u2209 A,\n        rw [if_pos xA, if_neg x\u2082nA] at hxeq,\n        rw [A_def, sb_set, mem_Union] at xA,\n        have x\u2082eq : x\u2082 = g (f x\u2081),\n          calc \n            x\u2082 = g (inv_fun g x\u2082) : by rw sb_right_inv f g x\u2082nA\n            ... = g (f x\u2081) : by rw hxeq,\n        rcases xA with \u27e8n, hn\u27e9,\n        rw [A_def, sb_set, mem_Union],\n        use n + 1,\n        simp [sb_aux],\n        use [x\u2081, hn, x\u2082eq.symm],\n      \n      rw [if_pos xA, if_pos x\u2082A] at hxeq,\n      from hf hxeq,},\n    { push_neg at xA,\n      rw [if_neg xA.1, if_neg xA.2] at hxeq,\n      calc\n        x\u2081 = g (inv_fun g x\u2081) : by rw sb_right_inv f g xA.1\n        ... = g (inv_fun g x\u2082) : by rw hxeq\n        ... = x\u2082 : by rw sb_right_inv f g xA.2,},\nend\n\ntheorem sb_surjective (hf: injective f) (hg : injective g) :\n  surjective (sb_fun f g) :=\nbegin \n  set A := sb_set f g with A_def,\n  set h := sb_fun f g with h_def,\n  intro y,\n  by_cases gyA : g y \u2208 A,\n  { rw [A_def, sb_set, mem_Union] at gyA,\n    rcases gyA with \u27e8n, hn\u27e9,\n    cases n with n,\n    { simp [sb_aux] at hn,\n      contradiction,},\n    { simp [sb_aux] at hn,\n      rcases hn with \u27e8x, xmem, hx\u27e9,\n      use x,\n      have : x \u2208 A,\n        rw [A_def, sb_set, mem_Union],\n        use [n, xmem],\n      simp only [h_def, sb_fun, if_pos this],\n      from hg hx,}},\n  { rw [A_def] at gyA,\n    use g y,\n    rw [h_def, sb_fun, if_neg gyA],\n    apply left_inverse_inv_fun,\n    from hg,}\nend\n\n\ntheorem schroeder_bernstein {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n    (hf: injective f) (hg : injective g) :\n  \u2203 h : \u03b1 \u2192 \u03b2, bijective h := \n\u27e8sb_fun f g, sb_injective f g hf hg, sb_surjective f g hf hg\u27e9\n\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/04_Sets_and_Functions/03_The_Schroeder_Berstein_Theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7193090718942444}}
{"text": "import tactic\nimport data.real.irrational\n\ndef rational (x : \u211d) :=\n  \u2203 (a b : \u2124), x = a / b\n\n/-- The product of two rational numbers is always rational. -/\nlemma part_a : \u2200 {a b : \u211d}, rational a \u2192 rational b \u2192 rational (a * b) :=\nbegin\n  sorry\nend\n\n/-- The product of two irrational numbers is not always irrational. -/\nlemma part_b : \u00ac \u2200 {a b : \u211d}, irrational a \u2192 irrational b \u2192 irrational (a * b) :=\nbegin\n  sorry\nend\n\n/-- The product of two irrational numbers is not always rational. -/\nlemma part_c : \u00ac \u2200 {a b : \u211d}, irrational a \u2192 irrational b \u2192 rational (a * b) :=\nbegin\n  sorry\nend\n\n/-- The product of a non-zero rational and an irrational is always irrational. -/\nlemma part_d : \u2200 {a b : \u211d}, a \u2260 0 \u2192 rational a \u2192 irrational b \u2192 irrational (a * b) :=\nbegin\n  sorry\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "m1fexplained_lean3", "sha": "570c9a3ff8cfc3805047f2796864516a49f51510", "save_path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3", "path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3/m1fexplained_lean3-570c9a3ff8cfc3805047f2796864516a49f51510/src/chapter02/exercises/exercise03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099069962657177, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7193090609820766}}
{"text": "import data.seq.seq\nimport data.list.infix\nimport tactic\n\nvariable {\u03b1 : Type*}\n\ndef stream_prefix : (\u2115 \u2192 \u03b1) \u2192 \u2115 \u2192 list \u03b1\n| f 0 := list.nil \n| f (n + 1) := list.concat (stream_prefix f n) (f n)\n\nlemma stream_prefix_length (f : \u2115 \u2192 \u03b1) (n : \u2115) :\n  (stream_prefix f n).length = n :=\nbegin\n  induction n with n ih,\n  { refl, },\n  { rw [stream_prefix, list.length_concat, ih], },\nend\n\nlemma stream_prefix_nth (f : \u2115 \u2192 \u03b1) (n : \u2115) : (stream_prefix f (n + 1)).nth n = f n :=\nbegin\n  unfold stream_prefix,\n  have := stream_prefix_length f n,\n  conv\n  { to_lhs,\n    congr,\n    skip,\n    rw \u2190 this, },\n  rw list.concat_eq_append,\n  rw list.nth_concat_length,\n  refl,\nend\n\nlemma stream_prefix_prefix (f : \u2115 \u2192 \u03b1) (n m : \u2115) (h : n \u2264 m) :\n  stream_prefix f n <+: stream_prefix f m :=\nbegin\n  induction m with m ih,\n  { rw nonpos_iff_eq_zero.mp h, },\n  { rw le_iff_eq_or_lt at h,\n    cases h,\n    { rw h, },\n    { rw nat.lt_succ_iff at h,\n       calc stream_prefix f n <+: stream_prefix f m : ih h \n       ... <+: stream_prefix f m.succ : list.prefix_concat (f m) (stream_prefix f m), }, },\nend\n\nlemma stream_prefix_nth' (f : \u2115 \u2192 \u03b1) (n i : \u2115) (hi : i < n) : (stream_prefix f n ).nth i = f i :=\nbegin\n  rw \u2190 stream_prefix_nth,\n  have hf : stream_prefix f (i + 1) <+: stream_prefix f n := stream_prefix_prefix f (i + 1) n (nat.succ_le_iff.mpr hi),\n  have : i < (stream_prefix f (i + 1)).length,\n  { rw stream_prefix_length,\n    exact lt_add_one i, },\n  cases hf with s hs,\n  rw \u2190 hs, \n  exact (list.nth_append this),\nend\n\ndef is_prefix (s : list \u03b1) (f : \u2115 \u2192 \u03b1) := stream_prefix f (s.length) = s\n\ndef is_prefix_def (s : list \u03b1) (f : \u2115 \u2192 \u03b1) :\n  is_prefix s f \u2194 \u2200 i < s.length, s.nth i = f i :=\nbegin\n  split,\n  { intros h i hi,\n    unfold is_prefix at h,\n    calc s.nth i = (stream_prefix f s.length).nth i : by rw h \n    ... = f i : stream_prefix_nth' f s.length i hi, },\n  { intros h,\n    ext1 i,\n    by_cases hi : i < s.length,\n    { calc (stream_prefix f s.length).nth i = f i : stream_prefix_nth' f s.length i hi\n      ... = s.nth i : (h i hi).symm, },\n    { calc (stream_prefix f s.length).nth i = none : list.nth_len_le (by linarith [stream_prefix_length f s.length])\n      ... = s.nth i : (list.nth_len_le (by linarith)).symm, }, },\nend\n\nlemma prefix_of_is_prefix (s : list \u03b1) (f : \u2115 \u2192 \u03b1) (n : \u2115) (h : is_prefix s f)\n  (h' : n \u2265 s.length) : s <+: stream_prefix f n :=\nbegin\n  rw is_prefix at h,\n  rw \u2190 h,\n  exact stream_prefix_prefix f s.length n h',\nend\n\nlemma is_prefix_of_prefix (s : list \u03b1) (f : \u2115 \u2192 \u03b1) (n : \u2115)\n  (h : s <+: stream_prefix f n) : is_prefix s f :=\nbegin\n  have hn : n \u2265 s.length,\n  { rw \u2190 (stream_prefix_length f n),\n    exact list.is_prefix.length_le h, },\n  have hf : (stream_prefix f s.length).length = s.length :=\n    stream_prefix_length f s.length,\n  apply list.eq_of_prefix_of_length_eq,\n  { apply list.prefix_of_prefix_length_le (stream_prefix_prefix f s.length n hn) h,\n    rw stream_prefix_length, },\n  { exact hf, },\nend\n\ndef prefix_open (X : set (\u2115 \u2192 \u03b1)) (C : set (list \u03b1)):= \u2200 f : \u2115 \u2192 \u03b1,\n  f \u2208 X \u2194 \u2203 s \u2208 C, is_prefix s f \n\ndef is_prefix_open (X : set (\u2115 \u2192 \u03b1)) := \u2203 C, prefix_open X C\n", "meta": {"author": "pglutz", "repo": "determinacy_in_lean", "sha": "bd5119aa016a0d3b00c7dd22e41c63e363f327a5", "save_path": "github-repos/lean/pglutz-determinacy_in_lean", "path": "github-repos/lean/pglutz-determinacy_in_lean/determinacy_in_lean-bd5119aa016a0d3b00c7dd22e41c63e363f327a5/src/prefixes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7192172052051907}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n\n! This file was ported from Lean 3 source module combinatorics.partition\n! leanprover-community/mathlib commit 1ead22342e1a078bd44744ace999f85756555d35\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Combinatorics.Composition\nimport Mathbin.Data.Nat.Parity\nimport Mathbin.Tactic.ApplyFun\n\n/-!\n# Partitions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA partition of a natural number `n` is a way of writing `n` as a sum of positive integers, where the\norder does not matter: two sums that differ only in the order of their summands are considered the\nsame partition. This notion is closely related to that of a composition of `n`, but in a composition\nof `n` the order does matter.\nA summand of the partition is called a part.\n\n## Main functions\n\n* `p : partition n` is a structure, made of a multiset of integers which are all positive and\n  add up to `n`.\n\n## Implementation details\n\nThe main motivation for this structure and its API is to show Euler's partition theorem, and\nrelated results.\n\nThe representation of a partition as a multiset is very handy as multisets are very flexible and\nalready have a well-developed API.\n\n## Tags\n\nPartition\n\n## References\n\n<https://en.wikipedia.org/wiki/Partition_(number_theory)>\n-/\n\n\nvariable {\u03b1 : Type _}\n\nopen Multiset\n\nopen BigOperators\n\nnamespace Nat\n\n#print Nat.Partition /-\n/-- A partition of `n` is a multiset of positive integers summing to `n`. -/\n@[ext]\nstructure Partition (n : \u2115) where\n  parts : Multiset \u2115\n  parts_pos : \u2200 {i}, i \u2208 parts \u2192 0 < i\n  parts_sum : parts.Sum = n\n  deriving DecidableEq\n#align nat.partition Nat.Partition\n-/\n\nnamespace Partition\n\n#print Nat.Partition.ofComposition /-\n/-- A composition induces a partition (just convert the list to a multiset). -/\ndef ofComposition (n : \u2115) (c : Composition n) : Partition n\n    where\n  parts := c.blocks\n  parts_pos i hi := c.blocks_pos hi\n  parts_sum := by rw [Multiset.coe_sum, c.blocks_sum]\n#align nat.partition.of_composition Nat.Partition.ofComposition\n-/\n\n#print Nat.Partition.ofComposition_surj /-\ntheorem ofComposition_surj {n : \u2115} : Function.Surjective (ofComposition n) :=\n  by\n  rintro \u27e8b, hb\u2081, hb\u2082\u27e9\n  rcases Quotient.exists_rep b with \u27e8b, rfl\u27e9\n  refine' \u27e8\u27e8b, fun i hi => hb\u2081 hi, _\u27e9, partition.ext _ _ rfl\u27e9\n  simpa using hb\u2082\n#align nat.partition.of_composition_surj Nat.Partition.ofComposition_surj\n-/\n\n#print Nat.Partition.ofSums /-\n-- The argument `n` is kept explicit here since it is useful in tactic mode proofs to generate the\n-- proof obligation `l.sum = n`.\n/-- Given a multiset which sums to `n`, construct a partition of `n` with the same multiset, but\nwithout the zeros.\n-/\ndef ofSums (n : \u2115) (l : Multiset \u2115) (hl : l.Sum = n) : Partition n\n    where\n  parts := l.filter\u2093 (\u00b7 \u2260 0)\n  parts_pos i hi := Nat.pos_of_ne_zero <| by apply of_mem_filter hi\n  parts_sum := by\n    have lt : l.filter (\u00b7 = 0) + l.filter (\u00b7 \u2260 0) = l := filter_add_not _ l\n    apply_fun Multiset.sum  at lt\n    have lz : (l.filter (\u00b7 = 0)).Sum = 0 :=\n      by\n      rw [Multiset.sum_eq_zero_iff]\n      simp\n    simpa [lz, hl] using lt\n#align nat.partition.of_sums Nat.Partition.ofSums\n-/\n\n#print Nat.Partition.ofMultiset /-\n/-- A `multiset \u2115` induces a partition on its sum. -/\ndef ofMultiset (l : Multiset \u2115) : Partition l.Sum :=\n  ofSums _ l rfl\n#align nat.partition.of_multiset Nat.Partition.ofMultiset\n-/\n\n#print Nat.Partition.indiscretePartition /-\n/-- The partition of exactly one part. -/\ndef indiscretePartition (n : \u2115) : Partition n :=\n  ofSums n {n} rfl\n#align nat.partition.indiscrete_partition Nat.Partition.indiscretePartition\n-/\n\ninstance {n : \u2115} : Inhabited (Partition n) :=\n  \u27e8indiscretePartition n\u27e9\n\n/- warning: nat.partition.count_of_sums_of_ne_zero -> Nat.Partition.count_ofSums_of_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n) {i : Nat}, (Ne.{1} Nat i (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) i (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) i l))\nbut is expected to have type\n  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n) {i : Nat}, (Ne.{1} Nat i (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) i (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) i l))\nCase conversion may be inaccurate. Consider using '#align nat.partition.count_of_sums_of_ne_zero Nat.Partition.count_ofSums_of_ne_zero\u2093'. -/\n/-- The number of times a positive integer `i` appears in the partition `of_sums n l hl` is the same\nas the number of times it appears in the multiset `l`.\n(For `i = 0`, `partition.non_zero` combined with `multiset.count_eq_zero_of_not_mem` gives that\nthis is `0` instead.)\n-/\ntheorem count_ofSums_of_ne_zero {n : \u2115} {l : Multiset \u2115} (hl : l.Sum = n) {i : \u2115} (hi : i \u2260 0) :\n    (ofSums n l hl).parts.count i = l.count i :=\n  count_filter_of_pos hi\n#align nat.partition.count_of_sums_of_ne_zero Nat.Partition.count_ofSums_of_ne_zero\n\n/- warning: nat.partition.count_of_sums_zero -> Nat.Partition.count_ofSums_zero is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n), Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))\nbut is expected to have type\n  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n), Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))\nCase conversion may be inaccurate. Consider using '#align nat.partition.count_of_sums_zero Nat.Partition.count_ofSums_zero\u2093'. -/\ntheorem count_ofSums_zero {n : \u2115} {l : Multiset \u2115} (hl : l.Sum = n) :\n    (ofSums n l hl).parts.count 0 = 0 :=\n  count_filter_of_neg fun h => h rfl\n#align nat.partition.count_of_sums_zero Nat.Partition.count_ofSums_zero\n\n/-- Show there are finitely many partitions by considering the surjection from compositions to\npartitions.\n-/\ninstance (n : \u2115) : Fintype (Partition n) :=\n  Fintype.ofSurjective (ofComposition n) ofComposition_surj\n\n#print Nat.Partition.odds /-\n/-- The finset of those partitions in which every part is odd. -/\ndef odds (n : \u2115) : Finset (Partition n) :=\n  Finset.univ.filter\u2093 fun c => \u2200 i \u2208 c.parts, \u00acEven i\n#align nat.partition.odds Nat.Partition.odds\n-/\n\n#print Nat.Partition.distincts /-\n/-- The finset of those partitions in which each part is used at most once. -/\ndef distincts (n : \u2115) : Finset (Partition n) :=\n  Finset.univ.filter\u2093 fun c => c.parts.Nodup\n#align nat.partition.distincts Nat.Partition.distincts\n-/\n\n#print Nat.Partition.oddDistincts /-\n/-- The finset of those partitions in which every part is odd and used at most once. -/\ndef oddDistincts (n : \u2115) : Finset (Partition n) :=\n  odds n \u2229 distincts n\n#align nat.partition.odd_distincts Nat.Partition.oddDistincts\n-/\n\nend Partition\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/Partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7192172026405553}}
{"text": "import Std.Tactic.ShowTerm\nimport Mathlib.Init.Function \n\n/- \nTactics are human helpers for constructing proof terms, ie terms `c : p` where \n`p` is the proposition to be proven. \n\nLet's look at the following two proofs \n-/\n\nsection \n\nvariable (\u03b1 \u03b2 \u03b3 : Type) (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3) \n\nopen Function \n\nexample : Injective (g \u2218 f) \u2192 Injective f := by \n  intro h a\u2081 a\u2082 h'\n  apply h\n  simp [h']\n\nexample : Surjective (g \u2218 f) \u2192 Surjective g := by \n  intro h s\n  have \u27e8a,h'\u27e9 := h s\n  apply Exists.intro\n  exact h'\n\n/-\nWhat do the proof terms look like? \n-/ \n\nexample : Injective (g \u2218 f) \u2192 Injective f := fun h _ _ h' => h (congrArg g h')\n  -- show_term {\n  -- intro h a\u2081 a\u2082 h'\n  -- apply h\n  -- exact congrArg g h' }\n\n-- We can then do this\nexample : Injective (g \u2218 f) \u2192 Injective f := sorry \n\nexample : Surjective (g \u2218 f) \u2192 Surjective g := by \n  show_term {\n  intro h s\n  have \u27e8a,h'\u27e9 := h s\n  apply Exists.intro\n  exact h'} \n\n-- And this \nexample : Surjective (g \u2218 f) \u2192 Surjective g := fun h s =>\n  match h s with\n  | Exists.intro a h' => Exists.intro (f a) h'\n\nend \n/- \nConcision is the main advantage of constructing a proof term directly. Another \npossible advantage is a lower level of complexity. Tactics can be implemented \nwith strange behavior in edge cases, in theory. \n\nA distinct disadvantage is lower level of readability. \n-/\n\n/- \nLean is based on dependent type theory. Above we can have seen one incarnation \nof \"dependence\". \n\n`Injective f` depends on the input `f : \u03b1 \u2192 \u03b2`. Thus, we have a type which \ndepends on a term. \n\nWhile the name \"dependent type theory\" originates from this form of dependence \nthere are others built into Lean. \n\nTerms can depend on a type. \n-/ \n\ndef proj\u2081 (\u03b1\u2081 \u03b1\u2082 : Type) : \u03b1\u2081 \u00d7 \u03b1\u2082 \u2192 \u03b1\u2081 := fun \u27e8a,_\u27e9 => a \n\n/-\nThis is a term of a basic function type but it depends on `\u03b1` and `\u03b2`. \nInstantiating either gives a concrete term. \n-/\n\n-- This is now a concrete term \n#check proj\u2081 UInt8 Bool \n\n/- \nWe can also have a type depend on another type, like `List`. \n\nAnd of course we have terms that depend on other terms, ie functions.\n\nLean accomodates all these versions of dependence. It is based on the \nCalculus of Inductive Constructions introduced by Thierry Coquand. \n\nMore details on the type theory of Lean can be found in Mario Carneiro's\n[Masters thesis](https://github.com/digama0/lean-type-theory). \n-/\n\n", "meta": {"author": "UofSC-Spring-2023-SCHC-411-H01", "repo": "notes", "sha": "ef57142df34fbe92f6204d8eb636ec5061729bd0", "save_path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes", "path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes/notes-ef57142df34fbe92f6204d8eb636ec5061729bd0/Notes4/ProofTerms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.7192171944321045}}
{"text": "import ..library.src_field\nimport tactic\n\nnamespace mth1001\n\nnamespace myreal\n\nsection grouplaws\n\nvariables {R : Type} [comm_group R]\n\n/-\nThe following six lemmas are 'user-friendly' variants of the first four axioms of the real number\nsystem. I have split each of the additive identity and additive inverse axioms into two lemmas.begin\n\nFor example, `zero_add` and `add_zero` together constitute the additive identity axiom.\n-/\n\nlemma add_comm (x y : R) : x + y = y + x := comm_group.add_comm x y\nlemma add_assoc (x y z : R) : (x + y) + z = x + (y + z) := comm_group.add_assoc x y z\nlemma add_zero (x : R) : x + 0 = x := comm_group.add_zero x\nlemma zero_add (x : R) : 0 + x = x := by {rw [add_comm, add_zero]}\nlemma add_neg (x : R) : x + (-x) = 0 := comm_group.add_inv x\nlemma neg_add (x : R) : (-x) + x = 0 := by {rw [add_comm, add_neg]}\n\n-- We define what it means for `u` to be an additive identity.\ndef add_identity (u : R) := \u2200 x : R, (x + u = x) \u2227 (u + x = x)\n\n-- `0` is an additive identity.\nexample : add_identity (0 : R) :=\nbegin\n  intro x,\n  exact and.intro (add_zero x) (zero_add x),\nend\n\n-- The additive identity is unique.\ntheorem add_identity_unique {a b : R} (h\u2081 : add_identity a) (h\u2082 : add_identity b)\n  : a = b :=\nbegin\n  specialize h\u2081 b, -- `h\u2081 : (b + a = b) \u2227 (a + b = b)`\n  specialize h\u2082 a, -- `h\u2082 : (a + b = a) \u2227 (b + a = a)`\n  calc  a = a + b : h\u2082.left.symm -- If `h : x = y`, then `h.symm : y = x`.\n      ... = b     : h\u2081.right\nend\n\n-- Definition of additive inverse.\ndef add_inverse (y x : R) := (x + y = 0) \u2227 (y + x = 0)\n\n-- Every real number has an additive inverse.\nlemma has_add_inverse : \u2200 a : R, \u2203 b : R, add_inverse b a :=\nbegin\n  intro a,\n  use (-a),\n  exact and.intro (add_neg a) (neg_add a)\nend\n\n-- The additive inverse is unique.\ntheorem add_inverse_unique {a b x : R} (h\u2081 : add_inverse a x) (h\u2082 : add_inverse b x)\n  : a = b :=\ncalc  a = a + 0        : (add_zero a).symm\n    ... = a + (x + b)  : by rw h\u2082.left\n    ... = (a + x) + b  : by rw add_assoc\n    ... = 0 + b        : by rw h\u2081.right\n    ... = b            : zero_add b\n\n\n-- Exercise 001:\n-- Complete the following with a `calc` style proof.\nlemma add_left_eq_self_mp {x a : R} : x + a = a \u2192 x = 0 :=\nbegin\n  intro h,\n  sorry  \nend\n\n-- Exercise 002:\nlemma add_left_eq_self_mpr {x a : R} : x = 0 \u2192 x + a = a :=\nbegin\n  sorry  \nend\n\n-- Exercise 003:\ntheorem add_left_eq_self (x a : R) : x + a = a \u2194 x = 0:=\nbegin\n  split,\n  { exact add_left_eq_self_mp, },\n  { sorry, }, \nend\n\n-- Exercise 004:\n-- Use `split` as above.\ntheorem add_left_inj (x a b : R) : a + x = b + x \u2194 a = b :=\nbegin\n  sorry    \nend\n\nlemma sub_eq_add_neg (x y : R) : x - y = x + (-y) := rfl \n\n-- Exercise 005:\n-- You can do the following with two rewrites. Use `add_zero` and `neg_add`\nlemma neg_zero : -(0 : R) = 0 :=\nsorry \n\n-- Exercise 006:\nlemma sub_zero (a : R) : a - 0 = a :=\nsorry  \n\n-- Exercise 007:\n-- The following can be proved in one line as a sequences of rewrites.\ntheorem sub_eq_zero_iff_eq (x y : R) : x - y = 0 \u2194 x = y :=\nsorry \n\n-- Exercise 008:\n-- The following can be proved in one line as a sequences of rewrites.\ntheorem neg_neg (x : R) : - - x = x :=\nsorry \n\n-- Exercise 009:\n-- Do the following using proof by calculation.\nlemma neg_add_eq_neg_add_neg (x y : R) : -(x + y) = -y + - x :=\nsorry \n\nend grouplaws\n\nsection fieldlaws\n\nvariables {R : Type} [myfield R]\n\n/-\nThe following lemmas encapsulate the remaining algebraic axioms of the real number type.\n-/\nlemma mul_comm (x y : R) : x * y = y * x := myfield.mul_comm x y\nlemma mul_assoc (x y z : R) : (x * y) * z = x * (y * z) := myfield.mul_assoc x y z\nlemma mul_one (x : R) : x * 1 = x := myfield.mul_one x\nlemma one_mul (x : R) : 1 * x = x := by { rw [mul_comm, mul_one] }\nlemma mul_inv (x : R) : x \u2260 0 \u2192 x * x\u207b\u00b9  = 1 := myfield.mul_inv x\nlemma inv_mul (x : R) : x \u2260 0 \u2192 x\u207b\u00b9 * x = 1 := by {intro h, rw [mul_comm, mul_inv x h], }\nlemma mul_add (x y z : R) : x * (y + z) = x * y + x * z := myfield.mul_add x y z\nlemma zero_ne_one : (0 : R) \u2260 (1 : R) := myfield.zero_ne_one\n\ndef mul_identity (u : R) := \u2200 x : R, (x * u = x) \u2227 (u * x = x)\n\n-- Exercise 010:\n-- Use `add_mul` and `add_comm` to prove the following.\ntheorem add_mul (x y z : R) : (x + y) * z = x * z + y * z :=\nbegin\n  sorry    \nend\n\n-- Exercise 011:\ntheorem mul_identity_unique {a b : R} (h\u2081 : mul_identity a) (h\u2082 : mul_identity b) \n  : a = b :=\nbegin\n  sorry  \nend\n\ndef mul_inverse (y x : R) := (x * y = 1) \u2227 (y * x = 1)\n\n-- Exercise 012:\ntheorem mul_inverse_unique {a b x : R} (h\u2081 : mul_inverse a x) (h\u2082 : mul_inverse b x)\n  : a = b :=\nsorry \n\n-- Exercise 013:\n-- This exercise is somewhat challenging.\ntheorem mul_zero {x : R} : x * (0 : R) = (0 : R) :=\nbegin\n  have h\u2081 : x * 0 = x * 0 + x * 0,\n    calc x * 0\n          = x * (0 + 0)   : by rw add_zero (0 : R)\n      ... = x * 0 + x * 0 : by rw mul_add,\n  sorry  \nend\n\n-- Exercise 014:\n-- Whereas the next result is a simple consequence of the previous result.\ntheorem zero_mul {x : R} : (0 : R) * x = (0 : R) :=\nbegin\n  sorry  \nend\n\n-- Exercise 015:\ntheorem neg_one_mul (x : R) : (-1) * x = -x :=\nbegin\n  sorry  \nend\n\n-- Exercise 016:\n-- Use the result above to prove this lemma.\nlemma neg_one_mul_neg_one : (-(1 : R)) * (-1) = 1 :=\nsorry \n\n-- Exercise 017:\nlemma neg_mul_eq_mul_neg (x y : R) : -(x * y) = x * (-y) :=\nsorry \n\nlemma neg_mul_neg_self (x : R) : (-x)*(-x) = x * x :=\nby rw [\u2190neg_one_mul, mul_assoc, mul_comm x _, \u2190mul_assoc, \u2190mul_assoc, neg_one_mul_neg_one, one_mul]\n\n-- Exercise 018:\nlemma neg_mul_neg (x y : R) : (-x) * (-y) = x * y :=\nbegin\n  sorry  \nend\n\n-- Exercise 019:\nlemma one_inv : (1 : R)\u207b\u00b9 = (1 : R) :=\nsorry \n-- Exercise 020:\ntheorem mul_sub (x y z : R) : x * (y - z) = x * y - x * z :=\nbegin\n  sorry  \nend\n\n-- Exercise 021:\ntheorem mul_left_inj' (x a b : R) (h\u2081 : x \u2260 0): a * x = b * x \u2194 a = b :=\nbegin\n  sorry    \nend\n\nopen_locale classical\n\n-- Exercise 022:\n-- This is a challenging exercise.\n-- Hint 1. Do a `by_cases` proof, depending on whether `x = 0` or not.\n-- Hint 2. Use the fact that a non-zero real number has a multiplicative inverse.\nlemma eq_zero_of_not_eq_zero_of_mul_not_eq_zero (x b : R) (h\u2081 : b \u2260 0) (h\u2082 : x * b = 0) : x = 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 023:\n-- The following is a corollary of the result above.\nlemma eq_zero_or_eq_zero_of_mul_eq_zero (x y : R) (h : x * y = 0) : x = 0 \u2228 y = 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 024:\nlemma mul_inv' (x y : R) (h\u2081 : x \u2260 0) (h\u2082 : y \u2260 0) : (x * y)\u207b\u00b9 = y\u207b\u00b9 * x\u207b\u00b9 :=\nbegin\n  have h : x * y \u2260 0,\n  { sorry, }, \n  rw \u2190(mul_left_inj' _ _ _ h\u2081),\n  sorry  \nend\n\n-- Exercise 025:\ntheorem inv_ne_zero {a : R} : a \u2260 0 \u2192 a\u207b\u00b9 \u2260 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 026:\ntheorem inv_inv' (a : R) (h : a \u2260 0 ) : (a\u207b\u00b9)\u207b\u00b9 = a :=\nbegin\n  sorry  end\n\nend fieldlaws\n\nsection powers\n\nvariables {R : Type} [myfield R]\n\n-- The following lemma is essentially the definition of exponentiation.\nlemma pow_succ (x : R) (n : \u2115) : x^(n+1) = x * x^n := rfl\n\n-- We have a couple of fundamental results.\nlemma pow_zero (x : R) : x ^ 0 = 1 := rfl\nlemma pow_one (x : R) : x ^ 1 = x := by rw [pow_succ, pow_zero, mul_one]\nlemma pow_succ' (x : R) (n : \u2115) : x^(n+1) = x^n * x := by rw [pow_succ, mul_comm]\n\n-- Exercise 027:\n-- Rewrite using the above lemmas to prove this result.\nlemma pow_two (x : R) : x ^ 2 = x * x :=\nbegin\n  sorry    \nend\n\n-- Exercise 028:\n-- Prove the following by induction on `n`.\ntheorem pow_ne_zero {x : R} (n : \u2115) (h : x \u2260 0) : x ^ n \u2260 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 029:\n-- Use induction. Make use of `nat.add_zero` and `nat.add_succ`\ntheorem pow_add (x : R) (m n : \u2115) : x ^ (m + n) = (x ^ m) * (x ^ n) :=\nbegin\n  sorry  \nend\n\n-- Exercise 030:\n-- Use induction. Make use of `nat.mul_zero`, `nat.succ_eq_add_one`, and `nat.mul_one`.\n-- You'll need `left_distrib`, a synonym of `mul_add` for `\u2115`.\ntheorem pow_mul (x : R) (m n : \u2115) : x ^ (m*n) = (x ^ m) ^ n :=\nbegin\n  sorry  \nend\n\nexample (m n : \u2115) (h : m \u2264 n) : n - m + m = n := nat.sub_add_cancel h\n\n-- Exercise 031:\n-- Use `nat.sub_add_cancel` (as demonstrated above).\ntheorem pow_sub_mul_pow (x : R) {m n : \u2115} (h : m \u2264 n) : x ^ (n - m) * x ^ m = x ^ n :=\nbegin\n  rw [\u2190pow_add, nat.sub_add_cancel h],\nend\n\n-- Exercise 032:\ntheorem pow_sub' (x : R) (m n : \u2115) (h : m \u2264 n) (ne0 : x \u2260 0) : x ^ (n - m) = (x ^ n) * (x ^ m)\u207b\u00b9 :=\nbegin\n  sorry  \nend\n \nend powers\n\nend myreal\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "ems_reals", "sha": "9df527742db69d0a389add44b506538fdb4d0800", "save_path": "github-repos/lean/gihanmarasingha-ems_reals", "path": "github-repos/lean/gihanmarasingha-ems_reals/ems_reals-9df527742db69d0a389add44b506538fdb4d0800/src/exercises/src_35_algebraic_axioms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430604060731, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.7191250020397402}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot\n-/\nimport order.filter.bases\nimport data.finset.preimage\n\n/-!\n# `at_top` and `at_bot` filters on preorded sets, monoids and groups.\n\nIn this file we define the filters\n\n* `at_top`: corresponds to `n \u2192 +\u221e`;\n* `at_bot`: corresponds to `n \u2192 -\u221e`.\n\nThen we prove many lemmas like \u201cif `f \u2192 +\u221e`, then `f \u00b1 c \u2192 +\u221e`\u201d.\n-/\n\nvariables {\u03b9 \u03b9' \u03b1 \u03b2 \u03b3 : Type*}\n\nopen set\nopen_locale classical filter big_operators\n\nnamespace filter\n/-- `at_top` is the filter representing the limit `\u2192 \u221e` on an ordered set.\n  It is generated by the collection of up-sets `{b | a \u2264 b}`.\n  (The preorder need not have a top element for this to be well defined,\n  and indeed is trivial when a top element exists.) -/\ndef at_top [preorder \u03b1] : filter \u03b1 := \u2a05 a, \ud835\udcdf (Ici a)\n\n/-- `at_bot` is the filter representing the limit `\u2192 -\u221e` on an ordered set.\n  It is generated by the collection of down-sets `{b | b \u2264 a}`.\n  (The preorder need not have a bottom element for this to be well defined,\n  and indeed is trivial when a bottom element exists.) -/\ndef at_bot [preorder \u03b1] : filter \u03b1 := \u2a05 a, \ud835\udcdf (Iic a)\n\nlemma mem_at_top [preorder \u03b1] (a : \u03b1) : {b : \u03b1 | a \u2264 b} \u2208 @at_top \u03b1 _ :=\nmem_infi_sets a $ subset.refl _\n\nlemma Ioi_mem_at_top [preorder \u03b1] [no_top_order \u03b1] (x : \u03b1) : Ioi x \u2208 (at_top : filter \u03b1) :=\nlet \u27e8z, hz\u27e9 := no_top x in mem_sets_of_superset (mem_at_top z) $ \u03bb y h,  lt_of_lt_of_le hz h\n\nlemma mem_at_bot [preorder \u03b1] (a : \u03b1) : {b : \u03b1 | b \u2264 a} \u2208 @at_bot \u03b1 _ :=\nmem_infi_sets a $ subset.refl _\n\nlemma Iio_mem_at_bot [preorder \u03b1] [no_bot_order \u03b1] (x : \u03b1) : Iio x \u2208 (at_bot : filter \u03b1) :=\nlet \u27e8z, hz\u27e9 := no_bot x in mem_sets_of_superset (mem_at_bot z) $ \u03bb y h, lt_of_le_of_lt h hz\n\nlemma at_top_basis [nonempty \u03b1] [semilattice_sup \u03b1] :\n  (@at_top \u03b1 _).has_basis (\u03bb _, true) Ici :=\nhas_basis_infi_principal (directed_of_sup $ \u03bb a b, Ici_subset_Ici.2)\n\nlemma at_top_basis' [semilattice_sup \u03b1] (a : \u03b1) :\n  (@at_top \u03b1 _).has_basis (\u03bb x, a \u2264 x) Ici :=\n\u27e8\u03bb t, (@at_top_basis \u03b1 \u27e8a\u27e9 _).mem_iff.trans\n  \u27e8\u03bb \u27e8x, _, hx\u27e9, \u27e8x \u2294 a, le_sup_right, \u03bb y hy, hx (le_trans le_sup_left hy)\u27e9,\n    \u03bb \u27e8x, _, hx\u27e9, \u27e8x, trivial, hx\u27e9\u27e9\u27e9\n\nlemma at_bot_basis [nonempty \u03b1] [semilattice_inf \u03b1] :\n  (@at_bot \u03b1 _).has_basis (\u03bb _, true) Iic :=\n@at_top_basis (order_dual \u03b1) _ _\n\nlemma at_bot_basis' [semilattice_inf \u03b1] (a : \u03b1) :\n  (@at_bot \u03b1 _).has_basis (\u03bb x, x \u2264 a) Iic :=\n@at_top_basis' (order_dual \u03b1) _ _\n\n@[instance]\nlemma at_top_ne_bot [nonempty \u03b1] [semilattice_sup \u03b1] : ne_bot (at_top : filter \u03b1) :=\nat_top_basis.ne_bot_iff.2 $ \u03bb a _, nonempty_Ici\n\n@[instance]\nlemma at_bot_ne_bot [nonempty \u03b1] [semilattice_inf \u03b1] : ne_bot (at_bot : filter \u03b1) :=\n@at_top_ne_bot (order_dual \u03b1) _ _\n\n@[simp]\nlemma mem_at_top_sets [nonempty \u03b1] [semilattice_sup \u03b1] {s : set \u03b1} :\n  s \u2208 (at_top : filter \u03b1) \u2194 \u2203a:\u03b1, \u2200b\u2265a, b \u2208 s :=\nat_top_basis.mem_iff.trans $ exists_congr $ \u03bb _, exists_const _\n\n@[simp]\nlemma mem_at_bot_sets [nonempty \u03b1] [semilattice_inf \u03b1] {s : set \u03b1} :\n  s \u2208 (at_bot : filter \u03b1) \u2194 \u2203a:\u03b1, \u2200b\u2264a, b \u2208 s :=\n@mem_at_top_sets (order_dual \u03b1) _ _ _\n\n@[simp]\nlemma eventually_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_top, p x) \u2194 (\u2203 a, \u2200 b \u2265 a, p b) :=\nmem_at_top_sets\n\n@[simp]\nlemma eventually_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_bot, p x) \u2194 (\u2203 a, \u2200 b \u2264 a, p b) :=\nmem_at_bot_sets\n\nlemma eventually_ge_at_top [preorder \u03b1] (a : \u03b1) : \u2200\u1da0 x in at_top, a \u2264 x := mem_at_top a\n\nlemma eventually_le_at_bot [preorder \u03b1] (a : \u03b1) : \u2200\u1da0 x in at_bot, x \u2264 a := mem_at_bot a\n\nlemma eventually_gt_at_top [preorder \u03b1] [no_top_order \u03b1] (a : \u03b1) :\n  \u2200\u1da0 x in at_top, a < x :=\nIoi_mem_at_top a\n\nlemma eventually_lt_at_bot [preorder \u03b1] [no_bot_order \u03b1] (a : \u03b1) :\n  \u2200\u1da0 x in at_bot, x < a :=\nIio_mem_at_bot a\n\nlemma at_top_basis_Ioi [nonempty \u03b1] [semilattice_sup \u03b1] [no_top_order \u03b1] :\n  (@at_top \u03b1 _).has_basis (\u03bb _, true) Ioi :=\nat_top_basis.to_has_basis (\u03bb a ha, \u27e8a, ha, Ioi_subset_Ici_self\u27e9) $\n  \u03bb a ha, (no_top a).imp $ \u03bb b hb, \u27e8ha, Ici_subset_Ioi.2 hb\u27e9\n\nlemma at_top_countable_basis [nonempty \u03b1] [semilattice_sup \u03b1] [encodable \u03b1] :\n  has_countable_basis (at_top : filter \u03b1) (\u03bb _, true) Ici :=\n{ countable := countable_encodable _,\n  .. at_top_basis }\n\nlemma at_bot_countable_basis [nonempty \u03b1] [semilattice_inf \u03b1] [encodable \u03b1] :\n  has_countable_basis (at_bot : filter \u03b1) (\u03bb _, true) Iic :=\n{ countable := countable_encodable _,\n  .. at_bot_basis }\n\nlemma is_countably_generated_at_top [nonempty \u03b1] [semilattice_sup \u03b1] [encodable \u03b1] :\n  (at_top : filter $ \u03b1).is_countably_generated :=\nat_top_countable_basis.is_countably_generated\n\nlemma is_countably_generated_at_bot [nonempty \u03b1] [semilattice_inf \u03b1] [encodable \u03b1] :\n  (at_bot : filter $ \u03b1).is_countably_generated :=\nat_bot_countable_basis.is_countably_generated\n\nlemma order_top.at_top_eq (\u03b1) [order_top \u03b1] : (at_top : filter \u03b1) = pure \u22a4 :=\nle_antisymm (le_pure_iff.2 $ (eventually_ge_at_top \u22a4).mono $ \u03bb b, top_unique)\n  (le_infi $ \u03bb b, le_principal_iff.2 le_top)\n\n\n\n@[nontriviality]\nlemma subsingleton.at_top_eq (\u03b1) [subsingleton \u03b1] [preorder \u03b1] : (at_top : filter \u03b1) = \u22a4 :=\nbegin\n  refine top_unique (\u03bb s hs x, _),\n  letI : unique \u03b1 := \u27e8\u27e8x\u27e9, \u03bb y, subsingleton.elim y x\u27e9,\n  rw [at_top, infi_unique, unique.default_eq x, mem_principal_sets] at hs,\n  exact hs left_mem_Ici\nend\n\n@[nontriviality]\nlemma subsingleton.at_bot_eq (\u03b1) [subsingleton \u03b1] [preorder \u03b1] : (at_bot : filter \u03b1) = \u22a4 :=\nsubsingleton.at_top_eq (order_dual \u03b1)\n\nlemma tendsto_at_top_pure [order_top \u03b1] (f : \u03b1 \u2192 \u03b2) :\n  tendsto f at_top (pure $ f \u22a4) :=\n(order_top.at_top_eq \u03b1).symm \u25b8 tendsto_pure_pure _ _\n\nlemma tendsto_at_bot_pure [order_bot \u03b1] (f : \u03b1 \u2192 \u03b2) :\n  tendsto f at_bot (pure $ f \u22a5) :=\n@tendsto_at_top_pure (order_dual \u03b1) _ _ _\n\nlemma eventually.exists_forall_of_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2200\u1da0 x in at_top, p x) : \u2203 a, \u2200 b \u2265 a, p b :=\neventually_at_top.mp h\n\nlemma eventually.exists_forall_of_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2200\u1da0 x in at_bot, p x) : \u2203 a, \u2200 b \u2264 a, p b :=\neventually_at_bot.mp h\n\nlemma frequently_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_top, p x) \u2194 (\u2200 a, \u2203 b \u2265 a, p b) :=\nby simp [at_top_basis.frequently_iff]\n\nlemma frequently_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_bot, p x) \u2194 (\u2200 a, \u2203 b \u2264 a, p b) :=\n@frequently_at_top (order_dual \u03b1) _ _ _\n\nlemma frequently_at_top' [semilattice_sup \u03b1] [nonempty \u03b1] [no_top_order \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_top, p x) \u2194 (\u2200 a, \u2203 b > a, p b) :=\nby simp [at_top_basis_Ioi.frequently_iff]\n\nlemma frequently_at_bot' [semilattice_inf \u03b1] [nonempty \u03b1] [no_bot_order \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_bot, p x) \u2194 (\u2200 a, \u2203 b < a, p b) :=\n@frequently_at_top' (order_dual \u03b1) _ _ _ _\n\nlemma frequently.forall_exists_of_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2203\u1da0 x in at_top, p x) : \u2200 a, \u2203 b \u2265 a, p b :=\nfrequently_at_top.mp h\n\nlemma frequently.forall_exists_of_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2203\u1da0 x in at_bot, p x) : \u2200 a, \u2203 b \u2264 a, p b :=\nfrequently_at_bot.mp h\n\nlemma map_at_top_eq [nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} :\n  at_top.map f = (\u2a05a, \ud835\udcdf $ f '' {a' | a \u2264 a'}) :=\n(at_top_basis.map _).eq_infi\n\nlemma map_at_bot_eq [nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2} :\n  at_bot.map f = (\u2a05a, \ud835\udcdf $ f '' {a' | a' \u2264 a}) :=\n@map_at_top_eq (order_dual \u03b1) _ _ _ _\n\nlemma tendsto_at_top [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n  tendsto m f at_top \u2194 (\u2200b, \u2200\u1da0 a in f, b \u2264 m a) :=\nby simp only [at_top, tendsto_infi, tendsto_principal, mem_Ici]\n\nlemma tendsto_at_bot [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n  tendsto m f at_bot \u2194 (\u2200b, \u2200\u1da0 a in f, m a \u2264 b) :=\n@tendsto_at_top \u03b1 (order_dual \u03b2) _ m f\n\nlemma tendsto_at_top_mono' [preorder \u03b2] (l : filter \u03b1) \u2983f\u2081 f\u2082 : \u03b1 \u2192 \u03b2\u2984 (h : f\u2081 \u2264\u1da0[l] f\u2082) :\n  tendsto f\u2081 l at_top \u2192 tendsto f\u2082 l at_top :=\nassume h\u2081, tendsto_at_top.2 $ \u03bb b, mp_sets (tendsto_at_top.1 h\u2081 b)\n  (monotone_mem_sets (\u03bb a ha ha\u2081, le_trans ha\u2081 ha) h)\n\nlemma tendsto_at_bot_mono' [preorder \u03b2] (l : filter \u03b1) \u2983f\u2081 f\u2082 : \u03b1 \u2192 \u03b2\u2984 (h : f\u2081 \u2264\u1da0[l] f\u2082) :\n  tendsto f\u2082 l at_bot \u2192 tendsto f\u2081 l at_bot :=\n@tendsto_at_top_mono' _ (order_dual \u03b2) _ _ _ _ h\n\nlemma tendsto_at_top_mono [preorder \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2} (h : \u2200 n, f n \u2264 g n) :\n  tendsto f l at_top \u2192 tendsto g l at_top :=\ntendsto_at_top_mono' l $ eventually_of_forall h\n\nlemma tendsto_at_bot_mono [preorder \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2} (h : \u2200 n, f n \u2264 g n) :\n  tendsto g l at_bot \u2192 tendsto f l at_bot :=\n@tendsto_at_top_mono _ (order_dual \u03b2) _ _ _ _ h\n\n/-!\n### Sequences\n-/\n\nlemma inf_map_at_top_ne_bot_iff [semilattice_sup \u03b1] [nonempty \u03b1] {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n  ne_bot (F \u2293 (map u at_top)) \u2194 \u2200 U \u2208 F, \u2200 N, \u2203 n \u2265 N, u n \u2208 U :=\nby simp_rw [inf_ne_bot_iff_frequently_left, frequently_map, frequently_at_top]; refl\n\nlemma inf_map_at_bot_ne_bot_iff [semilattice_inf \u03b1] [nonempty \u03b1] {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n  ne_bot (F \u2293 (map u at_bot)) \u2194 \u2200 U \u2208 F, \u2200 N, \u2203 n \u2264 N, u n \u2208 U :=\n@inf_map_at_top_ne_bot_iff (order_dual \u03b1) _ _ _ _ _\n\nlemma extraction_of_frequently_at_top' {P : \u2115 \u2192 Prop} (h : \u2200 N, \u2203 n > N, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nbegin\n  choose u hu using h,\n  cases forall_and_distrib.mp hu with hu hu',\n  exact \u27e8u \u2218 (nat.rec 0 (\u03bb n v, u v)), strict_mono.nat (\u03bb n, hu _), \u03bb n, hu' _\u27e9,\nend\n\nlemma extraction_of_frequently_at_top {P : \u2115 \u2192 Prop} (h : \u2203\u1da0 n in at_top, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nbegin\n  rw frequently_at_top' at h,\n  exact extraction_of_frequently_at_top' h,\nend\n\nlemma extraction_of_eventually_at_top {P : \u2115 \u2192 Prop} (h : \u2200\u1da0 n in at_top, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nextraction_of_frequently_at_top h.frequently\n\nlemma exists_le_of_tendsto_at_top [semilattice_sup \u03b1] [preorder \u03b2] {u : \u03b1 \u2192 \u03b2}\n  (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) : \u2203 a' \u2265 a, b \u2264 u a' :=\nbegin\n  have : \u2200\u1da0 x in at_top, a \u2264 x \u2227 b \u2264 u x :=\n    (eventually_ge_at_top a).and (h.eventually $ eventually_ge_at_top b),\n  haveI : nonempty \u03b1 := \u27e8a\u27e9,\n  rcases this.exists with \u27e8a', ha, hb\u27e9,\n  exact \u27e8a', ha, hb\u27e9\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_le_of_tendsto_at_bot [semilattice_sup \u03b1] [preorder \u03b2] {u : \u03b1 \u2192 \u03b2}\n  (h : tendsto u at_top at_bot) : \u2200 a b, \u2203 a' \u2265 a, u a' \u2264 b :=\n@exists_le_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ h\n\nlemma exists_lt_of_tendsto_at_top [semilattice_sup \u03b1] [preorder \u03b2] [no_top_order \u03b2]\n  {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) : \u2203 a' \u2265 a, b < u a' :=\nbegin\n  cases no_top b with b' hb',\n  rcases exists_le_of_tendsto_at_top h a b' with \u27e8a', ha', ha''\u27e9,\n  exact \u27e8a', ha', lt_of_lt_of_le hb' ha''\u27e9\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_lt_of_tendsto_at_bot [semilattice_sup \u03b1] [preorder \u03b2] [no_bot_order \u03b2]\n  {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_bot) : \u2200 a b, \u2203 a' \u2265 a, u a' < b :=\n@exists_lt_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ _ h\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen after any point, it reaches a value strictly greater than all previous values.\n-/\nlemma high_scores [linear_order \u03b2] [no_top_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_top) : \u2200 N, \u2203 n \u2265 N, \u2200 k < n, u k < u n :=\nbegin\n  intros N,\n  let A := finset.image u (finset.range $ N+1), -- A = {u 0, ..., u N}\n  have Ane : A.nonempty,\n    from \u27e8u 0, finset.mem_image_of_mem _ (finset.mem_range.mpr $ nat.zero_lt_succ _)\u27e9,\n  let M := finset.max' A Ane,\n  have ex : \u2203 n \u2265 N, M < u n,\n    from exists_lt_of_tendsto_at_top hu _ _,\n  obtain \u27e8n, hnN, hnM, hn_min\u27e9 : \u2203 n, N \u2264 n \u2227 M < u n \u2227 \u2200 k, N \u2264 k \u2192 k < n \u2192 u k \u2264 M,\n  { use nat.find ex,\n    rw \u2190 and_assoc,\n    split,\n    { simpa using nat.find_spec ex },\n    { intros k hk hk',\n      simpa [hk] using nat.find_min ex hk' } },\n  use [n, hnN],\n  intros k hk,\n  by_cases H : k \u2264 N,\n  { have : u k \u2208 A,\n      from finset.mem_image_of_mem _ (finset.mem_range.mpr $ nat.lt_succ_of_le H),\n    have : u k \u2264 M,\n      from finset.le_max' A (u k) this,\n    exact lt_of_le_of_lt this hnM },\n  { push_neg at H,\n    calc u k \u2264 M   : hn_min k (le_of_lt H) hk\n         ... < u n : hnM },\nend\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen after any point, it reaches a value strictly smaller than all previous values.\n-/\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma low_scores [linear_order \u03b2] [no_bot_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_bot) : \u2200 N, \u2203 n \u2265 N, \u2200 k < n, u n < u k :=\n@high_scores (order_dual \u03b2) _ _ _ hu\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen it `frequently` reaches a value strictly greater than all previous values.\n-/\nlemma frequently_high_scores [linear_order \u03b2] [no_top_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_top) : \u2203\u1da0 n in at_top, \u2200 k < n, u k < u n :=\nby simpa [frequently_at_top] using high_scores hu\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen it `frequently` reaches a value strictly smaller than all previous values.\n-/\nlemma frequently_low_scores [linear_order \u03b2] [no_bot_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_bot) : \u2203\u1da0 n in at_top, \u2200 k < n, u n < u k :=\n@frequently_high_scores (order_dual \u03b2) _ _ _ hu\n\nlemma strict_mono_subseq_of_tendsto_at_top\n  {\u03b2 : Type*} [linear_order \u03b2] [no_top_order \u03b2]\n  {u : \u2115 \u2192 \u03b2} (hu : tendsto u at_top at_top) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\nlet \u27e8\u03c6, h, h'\u27e9 := extraction_of_frequently_at_top (frequently_high_scores hu) in\n\u27e8\u03c6, h, \u03bb n m hnm, h' m _ (h hnm)\u27e9\n\nlemma strict_mono_subseq_of_id_le {u : \u2115 \u2192 \u2115} (hu : \u2200 n, n \u2264 u n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\nstrict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono hu tendsto_id)\n\nlemma strict_mono_tendsto_at_top {\u03c6 : \u2115 \u2192 \u2115} (h : strict_mono \u03c6) :\n  tendsto \u03c6 at_top at_top :=\ntendsto_at_top_mono h.id_le tendsto_id\n\nsection ordered_add_comm_monoid\n\nvariables [ordered_add_comm_monoid \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_add_nonneg_left' (hf : \u2200\u1da0 x in l, 0 \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (hf.mono (\u03bb x, le_add_of_nonneg_left)) hg\n\nlemma tendsto_at_bot_add_nonpos_left' (hf : \u2200\u1da0 x in l, f x \u2264 0) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left' _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_left (hf : \u2200 x, 0 \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_left' (eventually_of_forall hf) hg\n\nlemma tendsto_at_bot_add_nonpos_left (hf : \u2200 x, f x \u2264 0) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right' (hf : tendsto f l at_top) (hg : \u2200\u1da0 x in l, 0 \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (monotone_mem_sets (\u03bb x, le_add_of_nonneg_right) hg) hf\n\nlemma tendsto_at_bot_add_nonpos_right' (hf : tendsto f l at_bot) (hg : \u2200\u1da0 x in l, g x \u2264 0) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right' _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right (hf : tendsto f l at_top) (hg : \u2200 x, 0 \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_right' hf (eventually_of_forall hg)\n\nlemma tendsto_at_bot_add_nonpos_right (hf : tendsto f l at_bot) (hg : \u2200 x, g x \u2264 0) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_left' (tendsto_at_top.mp hf 0) hg\n\nlemma tendsto_at_bot_add (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto.nsmul_at_top (hf : tendsto f l at_top) {n : \u2115} (hn : 0 < n) :\n  tendsto (\u03bb x, n \u2022 f x) l at_top :=\ntendsto_at_top.2 $ \u03bb y, (tendsto_at_top.1 hf y).mp $ (tendsto_at_top.1 hf 0).mono $ \u03bb x h\u2080 hy,\ncalc y \u2264 f x : hy\n... = 1 \u2022 f x : (one_nsmul _).symm\n... \u2264  n \u2022 f x : nsmul_le_nsmul h\u2080 hn\n\nlemma tendsto.nsmul_at_bot (hf : tendsto f l at_bot) {n : \u2115} (hn : 0 < n) :\n  tendsto (\u03bb x, n \u2022 f x) l at_bot :=\n@tendsto.nsmul_at_top \u03b1 (order_dual \u03b2) _ l f hf n hn\n\nlemma tendsto_bit0_at_top : tendsto bit0 (at_top : filter \u03b2) at_top :=\ntendsto_at_top_add tendsto_id tendsto_id\n\nlemma tendsto_bit0_at_bot : tendsto bit0 (at_bot : filter \u03b2) at_bot :=\ntendsto_at_bot_add tendsto_id tendsto_id\n\nend ordered_add_comm_monoid\n\nsection ordered_cancel_add_comm_monoid\n\nvariables [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_of_add_const_left (C : \u03b2) (hf : tendsto (\u03bb x, C + f x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (C + b)).mono (\u03bb x, le_of_add_le_add_left)\n\nlemma tendsto_at_bot_of_add_const_left (C : \u03b2) (hf : tendsto (\u03bb x, C + f x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_left _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_of_add_const_right (C : \u03b2) (hf : tendsto (\u03bb x, f x + C) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (b + C)).mono (\u03bb x, le_of_add_le_add_right)\n\nlemma tendsto_at_bot_of_add_const_right (C : \u03b2) (hf : tendsto (\u03bb x, f x + C) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_right _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_of_add_bdd_above_left' (C) (hC : \u2200\u1da0 x in l, f x \u2264 C)\n  (h : tendsto (\u03bb x, f x + g x) l at_top) :\n  tendsto g l at_top :=\ntendsto_at_top_of_add_const_left C\n  (tendsto_at_top_mono' l (hC.mono (\u03bb x hx, add_le_add_right hx (g x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_left' (C) (hC : \u2200\u1da0 x in l, C \u2264 f x)\n  (h : tendsto (\u03bb x, f x + g x) l at_bot) :\n  tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left' _ (order_dual \u03b2) _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_left (C) (hC : \u2200 x, f x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_top \u2192 tendsto g l at_top :=\ntendsto_at_top_of_add_bdd_above_left' C (univ_mem_sets' hC)\n\nlemma tendsto_at_bot_of_add_bdd_below_left (C) (hC : \u2200 x, C \u2264 f x) :\n  tendsto (\u03bb x, f x + g x) l at_bot \u2192 tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left _ (order_dual \u03b2) _ _ _ _ C hC\n\nlemma tendsto_at_top_of_add_bdd_above_right' (C) (hC : \u2200\u1da0 x in l, g x \u2264 C)\n  (h : tendsto (\u03bb x, f x + g x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top_of_add_const_right C\n  (tendsto_at_top_mono' l (hC.mono (\u03bb x hx, add_le_add_left hx (f x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_right' (C) (hC : \u2200\u1da0 x in l, C \u2264 g x)\n  (h : tendsto (\u03bb x, f x + g x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right' _ (order_dual \u03b2) _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_right (C) (hC : \u2200 x, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_top \u2192 tendsto f l at_top :=\ntendsto_at_top_of_add_bdd_above_right' C (univ_mem_sets' hC)\n\nlemma tendsto_at_bot_of_add_bdd_below_right (C) (hC : \u2200 x, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_bot \u2192 tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right _ (order_dual \u03b2) _ _ _ _ C hC\n\nend ordered_cancel_add_comm_monoid\n\nsection ordered_group\n\nvariables [ordered_add_comm_group \u03b2] (l : filter \u03b1) {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_add_left_of_le' (C : \u03b2) (hf : \u2200\u1da0 x in l, C \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_left' _ _ _ l (\u03bb x, -(f x)) (\u03bb x, f x + g x) (-C)\n  (by simpa) (by simpa)\n\nlemma tendsto_at_bot_add_left_of_ge' (C : \u03b2) (hf : \u2200\u1da0 x in l, f x \u2264 C) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le' _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_left_of_le (C : \u03b2) (hf : \u2200 x, C \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_left_of_le' l C (univ_mem_sets' hf) hg\n\nlemma tendsto_at_bot_add_left_of_ge (C : \u03b2) (hf : \u2200 x, f x \u2264 C) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le' (C : \u03b2) (hf : tendsto f l at_top) (hg : \u2200\u1da0 x in l, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_right' _ _ _ l (\u03bb x, f x + g x) (\u03bb x, -(g x)) (-C)\n  (by simp [hg]) (by simp [hf])\n\nlemma tendsto_at_bot_add_right_of_ge' (C : \u03b2) (hf : tendsto f l at_bot) (hg : \u2200\u1da0 x in l, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le' _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le (C : \u03b2) (hf : tendsto f l at_top) (hg : \u2200 x, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' hg)\n\nlemma tendsto_at_bot_add_right_of_ge (C : \u03b2) (hf : tendsto f l at_bot) (hg : \u2200 x, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_const_left (C : \u03b2) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, C + f x) l at_top :=\ntendsto_at_top_add_left_of_le' l C (univ_mem_sets' $ \u03bb _, le_refl C) hf\n\nlemma tendsto_at_bot_add_const_left (C : \u03b2) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, C + f x) l at_bot :=\n@tendsto_at_top_add_const_left _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_add_const_right (C : \u03b2) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, f x + C) l at_top :=\ntendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' $ \u03bb _, le_refl C)\n\nlemma tendsto_at_bot_add_const_right (C : \u03b2) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, f x + C) l at_bot :=\n@tendsto_at_top_add_const_right _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_neg_at_top_at_bot : tendsto (has_neg.neg : \u03b2 \u2192 \u03b2) at_top at_bot :=\nbegin\n  simp only [tendsto_at_bot, neg_le],\n  exact \u03bb b, eventually_ge_at_top _\nend\n\nlemma tendsto_neg_at_bot_at_top : tendsto (has_neg.neg : \u03b2 \u2192 \u03b2) at_bot at_top :=\n@tendsto_neg_at_top_at_bot (order_dual \u03b2) _\n\nend ordered_group\n\nsection ordered_semiring\n\nvariables [ordered_semiring \u03b1] {l : filter \u03b2} {f g : \u03b2 \u2192 \u03b1}\n\nlemma tendsto_bit1_at_top : tendsto bit1 (at_top : filter \u03b1) at_top :=\ntendsto_at_top_add_nonneg_right tendsto_bit0_at_top (\u03bb _, zero_le_one)\n\nlemma tendsto.at_top_mul_at_top (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x * g x) l at_top :=\nbegin\n  refine tendsto_at_top_mono' _ _ hg,\n  filter_upwards [hg.eventually (eventually_ge_at_top 0), hf.eventually (eventually_ge_at_top 1)],\n  exact \u03bb x, le_mul_of_one_le_left\nend\n\nlemma tendsto_mul_self_at_top : tendsto (\u03bb x : \u03b1, x * x) at_top at_top :=\ntendsto_id.at_top_mul_at_top tendsto_id\n\n/-- The monomial function `x^n` tends to `+\u221e` at `+\u221e` for any positive natural `n`.\nA version for positive real powers exists as `tendsto_rpow_at_top`. -/\nlemma tendsto_pow_at_top {n : \u2115} (hn : 1 \u2264 n) : tendsto (\u03bb x : \u03b1, x ^ n) at_top at_top :=\nbegin\n  refine tendsto_at_top_mono' _ ((eventually_ge_at_top 1).mono $ \u03bb x hx, _) tendsto_id,\n  simpa only [pow_one] using pow_le_pow hx hn\nend\n\nend ordered_semiring\n\nlemma zero_pow_eventually_eq [monoid_with_zero \u03b1] :\n  (\u03bb n : \u2115, (0 : \u03b1) ^ n) =\u1da0[at_top] (\u03bb n, 0) :=\neventually_at_top.2 \u27e81, \u03bb n hn, zero_pow (zero_lt_one.trans_le hn)\u27e9\n\nsection ordered_ring\n\nvariables [ordered_ring \u03b1] {l : filter \u03b2} {f g : \u03b2 \u2192 \u03b1}\n\nlemma tendsto.at_top_mul_at_bot (hf : tendsto f l at_top) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x * g x) l at_bot :=\nhave _ := (hf.at_top_mul_at_top $ tendsto_neg_at_bot_at_top.comp hg),\nby simpa only [(\u2218), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp this\n\nlemma tendsto.at_bot_mul_at_top (hf : tendsto f l at_bot) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x * g x) l at_bot :=\nhave tendsto (\u03bb x, (-f x) * g x) l at_top :=\n  ( (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top hg),\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_at_top_at_bot.comp this\n\nlemma tendsto.at_bot_mul_at_bot (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x * g x) l at_top :=\nhave tendsto (\u03bb x, (-f x) * (-g x)) l at_top :=\n  (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top (tendsto_neg_at_bot_at_top.comp hg),\nby simpa only [neg_mul_neg] using this\n\nend ordered_ring\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1]\n\n/-- $\\lim_{x\\to+\\infty}|x|=+\\infty$ -/\nlemma tendsto_abs_at_top_at_top : tendsto (abs : \u03b1 \u2192 \u03b1) at_top at_top :=\ntendsto_at_top_mono le_abs_self tendsto_id\n\n/-- $\\lim_{x\\to-\\infty}|x|=+\\infty$ -/\nlemma tendsto_abs_at_bot_at_top : tendsto (abs : \u03b1 \u2192 \u03b1) at_bot at_top :=\ntendsto_at_top_mono neg_le_abs_self tendsto_neg_at_bot_at_top\n\nend linear_ordered_add_comm_group\n\nsection linear_ordered_semiring\n\nvariables [linear_ordered_semiring \u03b1] {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1}\n\nlemma tendsto.at_top_of_const_mul {c : \u03b1} (hc : 0 < c) (hf : tendsto (\u03bb x, c * f x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ \u03bb b, (tendsto_at_top.1 hf (c * b)).mono $ \u03bb x hx, le_of_mul_le_mul_left hx hc\n\nlemma tendsto.at_top_of_mul_const {c : \u03b1} (hc : 0 < c) (hf : tendsto (\u03bb x, f x * c) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ \u03bb b, (tendsto_at_top.1 hf (b * c)).mono $ \u03bb x hx, le_of_mul_le_mul_right hx hc\n\nend linear_ordered_semiring\n\nlemma nonneg_of_eventually_pow_nonneg [linear_ordered_ring \u03b1] {a : \u03b1}\n  (h : \u2200\u1da0 n in at_top, 0 \u2264 a ^ (n : \u2115)) : 0 \u2264 a :=\nlet \u27e8n, hn\u27e9 := (tendsto_bit1_at_top.eventually h).exists in pow_bit1_nonneg_iff.1 hn\n\nsection linear_ordered_field\n\nvariables [linear_ordered_field \u03b1] {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1}\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the left) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.const_mul_at_top'` instead. -/\nlemma tendsto.const_mul_at_top (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, r * f x) l at_top :=\ntendsto.at_top_of_const_mul (inv_pos.2 hr) $ by simpa only [inv_mul_cancel_left' hr.ne']\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the right) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.at_top_mul_const'` instead. -/\nlemma tendsto.at_top_mul_const (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, f x * r) l at_top :=\nby simpa only [mul_comm] using hf.const_mul_at_top hr\n\n/-- If a function tends to infinity along a filter, then this function divided by a positive\nconstant also tends to infinity. -/\nlemma tendsto.at_top_div_const (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, f x / r) l at_top :=\nby simpa only [div_eq_mul_inv] using hf.at_top_mul_const (inv_pos.2 hr)\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the left) tends to negative infinity. -/\nlemma tendsto.neg_const_mul_at_top (hr : r < 0) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, r * f x) l at_bot :=\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg]\n  using tendsto_neg_at_top_at_bot.comp (hf.const_mul_at_top (neg_pos.2 hr))\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the right) tends to negative infinity. -/\nlemma tendsto.at_top_mul_neg_const (hr : r < 0) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, f x * r) l at_bot :=\nby simpa only [mul_comm] using hf.neg_const_mul_at_top hr\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the left) also tends to negative infinity. -/\nlemma tendsto.const_mul_at_bot (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, r * f x) l at_bot :=\nby simpa only [(\u2218), neg_mul_eq_mul_neg, neg_neg]\n  using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).const_mul_at_top hr)\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the right) also tends to negative infinity. -/\nlemma tendsto.at_bot_mul_const (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, f x * r) l at_bot :=\nby simpa only [mul_comm] using hf.const_mul_at_bot hr\n\n/-- If a function tends to negative infinity along a filter, then this function divided by\na positive constant also tends to negative infinity. -/\nlemma tendsto.at_bot_div_const (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, f x / r) l at_bot :=\nby simpa only [div_eq_mul_inv] using hf.at_bot_mul_const (inv_pos.2 hr)\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the left) tends to positive infinity. -/\nlemma tendsto.neg_const_mul_at_bot (hr : r < 0) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, r * f x) l at_top :=\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg]\n  using tendsto_neg_at_bot_at_top.comp (hf.const_mul_at_bot (neg_pos.2 hr))\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the right) tends to positive infinity. -/\nlemma tendsto.at_bot_mul_neg_const (hr : r < 0) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, f x * r) l at_top :=\nby simpa only [mul_comm] using hf.neg_const_mul_at_bot hr\n\nlemma tendsto_const_mul_pow_at_top {c : \u03b1} {n : \u2115}\n  (hn : 1 \u2264 n) (hc : 0 < c) : tendsto (\u03bb x, c * x^n) at_top at_top :=\ntendsto.const_mul_at_top hc (tendsto_pow_at_top hn)\n\nlemma tendsto_neg_const_mul_pow_at_top {c : \u03b1} {n : \u2115}\n  (hn : 1 \u2264 n) (hc : c < 0) : tendsto (\u03bb x, c * x^n) at_top at_bot :=\ntendsto.neg_const_mul_at_top hc (tendsto_pow_at_top hn)\n\n\nend linear_ordered_field\n\nopen_locale filter\n\nlemma tendsto_at_top' [nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto f at_top l \u2194 (\u2200s \u2208 l, \u2203a, \u2200b\u2265a, f b \u2208 s) :=\nby simp only [tendsto_def, mem_at_top_sets]; refl\n\nlemma tendsto_at_bot' [nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto f at_bot l \u2194 (\u2200s \u2208 l, \u2203a, \u2200b\u2264a, f b \u2208 s) :=\n@tendsto_at_top' (order_dual \u03b1) _ _ _ _ _\n\ntheorem tendsto_at_top_principal [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n  tendsto f at_top (\ud835\udcdf s) \u2194 \u2203N, \u2200n\u2265N, f n \u2208 s :=\nby rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl\n\ntheorem tendsto_at_bot_principal [nonempty \u03b2] [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n  tendsto f at_bot (\ud835\udcdf s) \u2194 \u2203N, \u2200n\u2264N, f n \u2208 s :=\n@tendsto_at_top_principal _ (order_dual \u03b2) _ _ _ _\n\n/-- A function `f` grows to `+\u221e` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_top_at_top [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_top at_top \u2194 \u2200 b : \u03b2, \u2203 i : \u03b1, \u2200 a : \u03b1, i \u2264 a \u2192 b \u2264 f a :=\niff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal\n\nlemma tendsto_at_top_at_bot [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_top at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), i \u2264 a \u2192 f a \u2264 b :=\n@tendsto_at_top_at_top \u03b1 (order_dual \u03b2) _ _ _ f\n\nlemma tendsto_at_bot_at_top [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_bot at_top \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 b \u2264 f a :=\n@tendsto_at_top_at_top (order_dual \u03b1) \u03b2 _ _ _ f\n\nlemma tendsto_at_bot_at_bot [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_bot at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 f a \u2264 b :=\n@tendsto_at_top_at_top (order_dual \u03b1) (order_dual \u03b2) _ _ _ f\n\nlemma tendsto_at_top_at_top_of_monotone [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f)\n  (h : \u2200 b, \u2203 a, b \u2264 f a) :\n  tendsto f at_top at_top :=\ntendsto_infi.2 $ \u03bb b, tendsto_principal.2 $ let \u27e8a, ha\u27e9 := h b in\nmem_sets_of_superset (mem_at_top a) $ \u03bb a' ha', le_trans ha (hf ha')\n\nlemma tendsto_at_bot_at_bot_of_monotone [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f)\n  (h : \u2200 b, \u2203 a, f a \u2264 b) :\n  tendsto f at_bot at_bot :=\ntendsto_infi.2 $ \u03bb b, tendsto_principal.2 $ let \u27e8a, ha\u27e9 := h b in\nmem_sets_of_superset (mem_at_bot a) $ \u03bb a' ha', le_trans (hf ha') ha\n\nlemma tendsto_at_top_at_top_iff_of_monotone [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n  tendsto f at_top at_top \u2194 \u2200 b : \u03b2, \u2203 a : \u03b1, b \u2264 f a :=\ntendsto_at_top_at_top.trans $ forall_congr $ \u03bb b, exists_congr $ \u03bb a,\n  \u27e8\u03bb h, h a (le_refl a), \u03bb h a' ha', le_trans h $ hf ha'\u27e9\n\nlemma tendsto_at_bot_at_bot_iff_of_monotone [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n  tendsto f at_bot at_bot \u2194 \u2200 b : \u03b2, \u2203 a : \u03b1, f a \u2264 b :=\ntendsto_at_bot_at_bot.trans $ forall_congr $ \u03bb b, exists_congr $ \u03bb a,\n  \u27e8\u03bb h, h a (le_refl a), \u03bb h a' ha', le_trans (hf ha') h\u27e9\n\nalias tendsto_at_top_at_top_of_monotone \u2190 monotone.tendsto_at_top_at_top\nalias tendsto_at_bot_at_bot_of_monotone \u2190 monotone.tendsto_at_bot_at_bot\nalias tendsto_at_top_at_top_iff_of_monotone \u2190 monotone.tendsto_at_top_at_top_iff\nalias tendsto_at_bot_at_bot_iff_of_monotone \u2190 monotone.tendsto_at_bot_at_bot_iff\n\nlemma tendsto_at_top_embedding [preorder \u03b2] [preorder \u03b3]\n  {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1}\n  (hm : \u2200b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, c \u2264 e b) :\n  tendsto (e \u2218 f) l at_top \u2194 tendsto f l at_top :=\nbegin\n  refine \u27e8_, (tendsto_at_top_at_top_of_monotone (\u03bb b\u2081 b\u2082, (hm b\u2081 b\u2082).2) hu).comp\u27e9,\n  rw [tendsto_at_top, tendsto_at_top],\n  exact \u03bb hc b, (hc (e b)).mono (\u03bb a, (hm b (f a)).1)\nend\n\n/-- A function `f` goes to `-\u221e` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_bot_embedding [preorder \u03b2] [preorder \u03b3]\n  {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1}\n  (hm : \u2200b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, e b \u2264 c) :\n  tendsto (e \u2218 f) l at_bot \u2194 tendsto f l at_bot :=\n@tendsto_at_top_embedding \u03b1 (order_dual \u03b2) (order_dual \u03b3) _ _ f e l (function.swap hm) hu\n\nlemma tendsto_finset_range : tendsto finset.range at_top at_top :=\nfinset.range_mono.tendsto_at_top_at_top finset.exists_nat_subset_range\n\nlemma at_top_finset_eq_infi : (at_top : filter $ finset \u03b1) = \u2a05 x : \u03b1, \ud835\udcdf (Ici {x}) :=\nbegin\n  refine le_antisymm (le_infi (\u03bb i, le_principal_iff.2 $ mem_at_top {i})) _,\n  refine le_infi (\u03bb s, le_principal_iff.2 $ mem_infi_iff.2 _),\n  refine \u27e8\u2191s, s.finite_to_set, _, \u03bb i, mem_principal_self _, _\u27e9,\n  simp only [subset_def, mem_Inter, set_coe.forall, mem_Ici, finset.le_iff_subset,\n    finset.mem_singleton, finset.subset_iff, forall_eq], dsimp,\n  exact \u03bb t, id\nend\n\n/-- If `f` is a monotone sequence of `finset`s and each `x` belongs to one of `f n`, then\n`tendsto f at_top at_top`. -/\nlemma tendsto_at_top_finset_of_monotone [preorder \u03b2]\n  {f : \u03b2 \u2192 finset \u03b1} (h : monotone f) (h' : \u2200 x : \u03b1, \u2203 n, x \u2208 f n) :\n  tendsto f at_top at_top :=\nbegin\n  simp only [at_top_finset_eq_infi, tendsto_infi, tendsto_principal],\n  intro a,\n  rcases h' a with \u27e8b, hb\u27e9,\n  exact eventually.mono (mem_at_top b)\n    (\u03bb b' hb', le_trans (finset.singleton_subset_iff.2 hb) (h hb')),\nend\n\nalias tendsto_at_top_finset_of_monotone \u2190 monotone.tendsto_at_top_finset\n\nlemma tendsto_finset_image_at_top_at_top {i : \u03b2 \u2192 \u03b3} {j : \u03b3 \u2192 \u03b2} (h : function.left_inverse j i) :\n  tendsto (finset.image j) at_top at_top :=\n(finset.image_mono j).tendsto_at_top_finset $ assume a,\n  \u27e8{i a}, by simp only [finset.image_singleton, h a, finset.mem_singleton]\u27e9\n\nlemma tendsto_finset_preimage_at_top_at_top {f : \u03b1 \u2192 \u03b2} (hf : function.injective f) :\n  tendsto (\u03bb s : finset \u03b2, s.preimage f (hf.inj_on _)) at_top at_top :=\n(finset.monotone_preimage hf).tendsto_at_top_finset $\n  \u03bb x, \u27e8{f x}, finset.mem_preimage.2 $ finset.mem_singleton_self _\u27e9\n\nlemma prod_at_top_at_top_eq {\u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_sup \u03b2\u2081] [semilattice_sup \u03b2\u2082] :\n  (at_top : filter \u03b2\u2081) \u00d7\u1da0 (at_top : filter \u03b2\u2082) = (at_top : filter (\u03b2\u2081 \u00d7 \u03b2\u2082)) :=\nbegin\n  by_cases ne : nonempty \u03b2\u2081 \u2227 nonempty \u03b2\u2082,\n  { cases ne,\n    resetI,\n    simp [at_top, prod_infi_left, prod_infi_right, infi_prod],\n    exact infi_comm },\n  { rw not_and_distrib at ne,\n    cases ne;\n    { have : \u00ac (nonempty (\u03b2\u2081 \u00d7 \u03b2\u2082)), by simp [ne],\n      rw [at_top.filter_eq_bot_of_not_nonempty ne, at_top.filter_eq_bot_of_not_nonempty this],\n      simp only [bot_prod, prod_bot] } }\nend\n\nlemma prod_at_bot_at_bot_eq {\u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_inf \u03b2\u2081] [semilattice_inf \u03b2\u2082] :\n  (at_bot : filter \u03b2\u2081) \u00d7\u1da0 (at_bot : filter \u03b2\u2082) = (at_bot : filter (\u03b2\u2081 \u00d7 \u03b2\u2082)) :=\n@prod_at_top_at_top_eq (order_dual \u03b2\u2081) (order_dual \u03b2\u2082) _ _\n\nlemma prod_map_at_top_eq {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_sup \u03b2\u2081] [semilattice_sup \u03b2\u2082]\n  (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n  (map u\u2081 at_top) \u00d7\u1da0 (map u\u2082 at_top) = map (prod.map u\u2081 u\u2082) at_top :=\nby rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def]\n\nlemma prod_map_at_bot_eq {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_inf \u03b2\u2081] [semilattice_inf \u03b2\u2082]\n  (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n  (map u\u2081 at_bot) \u00d7\u1da0 (map u\u2082 at_bot) = map (prod.map u\u2081 u\u2082) at_bot :=\n@prod_map_at_top_eq _ _ (order_dual \u03b2\u2081) (order_dual \u03b2\u2082) _ _ _ _\n\n/-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a\nGalois insertion. The Galois \"insertion\" and \"connection\" is weakened to only require it to be an\ninsertion and a connetion above `b'`. -/\nlemma map_at_top_eq_of_gc [semilattice_sup \u03b1] [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2)\n  (hf : monotone f) (gc : \u2200a, \u2200b\u2265b', f a \u2264 b \u2194 a \u2264 g b) (hgi : \u2200b\u2265b', b \u2264 f (g b)) :\n  map f at_top = at_top :=\nbegin\n  refine le_antisymm\n    (hf.tendsto_at_top_at_top $ \u03bb b, \u27e8g (b \u2294 b'), le_sup_left.trans $ hgi _ le_sup_right\u27e9) _,\n  rw [@map_at_top_eq _ _ \u27e8g b'\u27e9],\n  refine le_infi (\u03bb a, infi_le_of_le (f a \u2294 b') $ principal_mono.2 $ \u03bb b hb, _),\n  rw [mem_Ici, sup_le_iff] at hb,\n  exact \u27e8g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 (le_refl _)) (hgi _ hb.2)\u27e9\nend\n\nlemma map_at_bot_eq_of_gc [semilattice_inf \u03b1] [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2)\n  (hf : monotone f) (gc : \u2200a, \u2200b\u2264b', b \u2264 f a \u2194 g b \u2264 a) (hgi : \u2200b\u2264b', f (g b) \u2264 b) :\n  map f at_bot = at_bot :=\n@map_at_top_eq_of_gc (order_dual \u03b1) (order_dual \u03b2) _ _ _ _ _ hf.order_dual gc hgi\n\nlemma map_coe_at_top_of_Ici_subset [semilattice_sup \u03b1] {a : \u03b1} {s : set \u03b1} (h : Ici a \u2286 s) :\n  map (coe : s \u2192 \u03b1) at_top = at_top :=\nbegin\n  have : directed (\u2265) (\u03bb x : s, \ud835\udcdf (Ici x)),\n  { intros x y,\n    use \u27e8x \u2294 y \u2294 a, h le_sup_right\u27e9,\n    simp only [ge_iff_le, principal_mono, Ici_subset_Ici, \u2190 subtype.coe_le_coe, subtype.coe_mk],\n    exact \u27e8le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left\u27e9 },\n  haveI : nonempty s := \u27e8\u27e8a, h le_rfl\u27e9\u27e9,\n  simp only [le_antisymm_iff, at_top, le_infi_iff, le_principal_iff, mem_map, mem_set_of_eq,\n    map_infi_eq this, map_principal],\n  split,\n  { intro x,\n    refine mem_sets_of_superset (mem_infi_sets \u27e8x \u2294 a, h le_sup_right\u27e9 (mem_principal_self _)) _,\n    rintro _ \u27e8y, hy, rfl\u27e9,\n    exact le_trans le_sup_left (subtype.coe_le_coe.2 hy) },\n  { intro x,\n    filter_upwards [mem_at_top (\u2191x \u2294 a)],\n    intros b hb,\n    exact \u27e8\u27e8b, h $ le_sup_right.trans hb\u27e9, subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl\u27e9 }\nend\n\n/-- The image of the filter `at_top` on `Ici a` under the coercion equals `at_top`. -/\n@[simp] lemma map_coe_Ici_at_top [semilattice_sup \u03b1] (a : \u03b1) :\n  map (coe : Ici a \u2192 \u03b1) at_top = at_top :=\nmap_coe_at_top_of_Ici_subset (subset.refl _)\n\n/-- The image of the filter `at_top` on `Ioi a` under the coercion equals `at_top`. -/\n@[simp] lemma map_coe_Ioi_at_top [semilattice_sup \u03b1] [no_top_order \u03b1] (a : \u03b1) :\n  map (coe : Ioi a \u2192 \u03b1) at_top = at_top :=\nbegin\n  rcases no_top a with \u27e8b, hb\u27e9,\n  exact map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb)\nend\n\n/-- The `at_top` filter for an open interval `Ioi a` comes from the `at_top` filter in the ambient\norder. -/\nlemma at_top_Ioi_eq [semilattice_sup \u03b1] (a : \u03b1) :\n  at_top = comap (coe : Ioi a \u2192 \u03b1) at_top :=\nbegin\n  nontriviality,\n  rcases nontrivial_iff_nonempty.1 \u2039_\u203a with \u27e8b, hb\u27e9,\n  rw [\u2190 map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map subtype.coe_injective]\nend\n\n/-- The `at_top` filter for an open interval `Ici a` comes from the `at_top` filter in the ambient\norder. -/\nlemma at_top_Ici_eq [semilattice_sup \u03b1] (a : \u03b1) :\n  at_top = comap (coe : Ici a \u2192 \u03b1) at_top :=\nby rw [\u2190 map_coe_Ici_at_top a, comap_map subtype.coe_injective]\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] lemma map_coe_Iio_at_bot [semilattice_inf \u03b1] [no_bot_order \u03b1] (a : \u03b1) :\n  map (coe : Iio a \u2192 \u03b1) at_bot = at_bot :=\n@map_coe_Ioi_at_top (order_dual \u03b1) _ _ _\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\nlemma at_bot_Iio_eq [semilattice_inf \u03b1] (a : \u03b1) :\n  at_bot = comap (coe : Iio a \u2192 \u03b1) at_bot :=\n@at_top_Ioi_eq (order_dual \u03b1) _ _\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] lemma map_coe_Iic_at_bot [semilattice_inf \u03b1] (a : \u03b1) :\n  map (coe : Iic a \u2192 \u03b1) at_bot = at_bot :=\n@map_coe_Ici_at_top (order_dual \u03b1) _ _\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\nlemma at_bot_Iic_eq [semilattice_inf \u03b1] (a : \u03b1) :\n  at_bot = comap (coe : Iic a \u2192 \u03b1) at_bot :=\n@at_top_Ici_eq (order_dual \u03b1) _ _\n\nlemma tendsto_Ioi_at_top [semilattice_sup \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Ioi a}\n  {l : filter \u03b2} :\n  tendsto f l at_top \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_top :=\nby rw [at_top_Ioi_eq, tendsto_comap_iff]\n\nlemma tendsto_Iio_at_bot [semilattice_inf \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Iio a}\n  {l : filter \u03b2} :\n  tendsto f l at_bot \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_bot :=\nby rw [at_bot_Iio_eq, tendsto_comap_iff]\n\nlemma tendsto_Ici_at_top [semilattice_sup \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Ici a} {l : filter \u03b2} :\n  tendsto f l at_top \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_top :=\nby rw [at_top_Ici_eq, tendsto_comap_iff]\n\nlemma tendsto_Iic_at_bot [semilattice_inf \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Iic a} {l : filter \u03b2} :\n  tendsto f l at_bot \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_bot :=\nby rw [at_bot_Iic_eq, tendsto_comap_iff]\n\n@[simp] lemma tendsto_comp_coe_Ioi_at_top [semilattice_sup \u03b1] [no_top_order \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Ioi a, f x) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 map_coe_Ioi_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Ici_at_top [semilattice_sup \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Ici a, f x) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 map_coe_Ici_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iio_at_bot [semilattice_inf \u03b1] [no_bot_order \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Iio a, f x) at_bot l \u2194 tendsto f at_bot l :=\nby rw [\u2190 map_coe_Iio_at_bot a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iic_at_bot [semilattice_inf \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Iic a, f x) at_bot l \u2194 tendsto f at_bot l :=\nby rw [\u2190 map_coe_Iic_at_bot a, tendsto_map'_iff]\n\nlemma map_add_at_top_eq_nat (k : \u2115) : map (\u03bba, a + k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bba, a - k) k\n  (assume a b h, add_le_add_right h k)\n  (assume a b h, (nat.le_sub_right_iff_add_le h).symm)\n  (assume a h, by rw [nat.sub_add_cancel h])\n\nlemma map_sub_at_top_eq_nat (k : \u2115) : map (\u03bba, a - k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bba, a + k) 0\n  (assume a b h, nat.sub_le_sub_right h _)\n  (assume a b _, nat.sub_le_right_iff_le_add)\n  (assume b _, by rw [nat.add_sub_cancel])\n\nlemma tendsto_add_at_top_nat (k : \u2115) : tendsto (\u03bba, a + k) at_top at_top :=\nle_of_eq (map_add_at_top_eq_nat k)\n\nlemma tendsto_sub_at_top_nat (k : \u2115) : tendsto (\u03bba, a - k) at_top at_top :=\nle_of_eq (map_sub_at_top_eq_nat k)\n\nlemma tendsto_add_at_top_iff_nat {f : \u2115 \u2192 \u03b1} {l : filter \u03b1} (k : \u2115) :\n  tendsto (\u03bbn, f (n + k)) at_top l \u2194 tendsto f at_top l :=\nshow tendsto (f \u2218 (\u03bbn, n + k)) at_top l \u2194 tendsto f at_top l,\n  by rw [\u2190 tendsto_map'_iff, map_add_at_top_eq_nat]\n\nlemma map_div_at_top_eq_nat (k : \u2115) (hk : 0 < k) : map (\u03bba, a / k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bbb, b * k + (k - 1)) 1\n  (assume a b h, nat.div_le_div_right h)\n  (assume a b _,\n    calc a / k \u2264 b \u2194 a / k < b + 1 : by rw [\u2190 nat.succ_eq_add_one, nat.lt_succ_iff]\n      ... \u2194 a < (b + 1) * k : nat.div_lt_iff_lt_mul _ _ hk\n      ... \u2194 _ :\n      begin\n        cases k,\n        exact (lt_irrefl _ hk).elim,\n        simp [mul_add, add_mul, nat.succ_add, nat.lt_succ_iff]\n      end)\n  (assume b _,\n    calc b = (b * k) / k : by rw [nat.mul_div_cancel b hk]\n      ... \u2264 (b * k + (k - 1)) / k : nat.div_le_div_right $ nat.le_add_right _ _)\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nabove, then `tendsto u at_top at_top`. -/\nlemma tendsto_at_top_at_top_of_monotone' [preorder \u03b9] [linear_order \u03b1]\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_above (range u)) :\n  tendsto u at_top at_top :=\nbegin\n  apply h.tendsto_at_top_at_top,\n  intro b,\n  rcases not_bdd_above_iff.1 H b with \u27e8_, \u27e8N, rfl\u27e9, hN\u27e9,\n  exact \u27e8N, le_of_lt hN\u27e9,\nend\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nbelow, then `tendsto u at_bot at_bot`. -/\nlemma tendsto_at_bot_at_bot_of_monotone' [preorder \u03b9] [linear_order \u03b1]\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_below (range u)) :\n  tendsto u at_bot at_bot :=\n@tendsto_at_top_at_top_of_monotone' (order_dual \u03b9) (order_dual \u03b1) _ _ _ h.order_dual H\n\nlemma unbounded_of_tendsto_at_top [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] [no_top_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_top) :\n  \u00ac bdd_above (range f) :=\nbegin\n  rintros \u27e8M, hM\u27e9,\n  cases mem_at_top_sets.mp (h $ Ioi_mem_at_top M) with a ha,\n  apply lt_irrefl M,\n  calc\n  M < f a : ha a (le_refl _)\n  ... \u2264 M : hM (set.mem_range_self a)\nend\n\nlemma unbounded_of_tendsto_at_bot [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] [no_bot_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_bot) :\n  \u00ac bdd_below (range f) :=\n@unbounded_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_top' [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] [no_top_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_top) :\n  \u00ac bdd_above (range f) :=\n@unbounded_of_tendsto_at_top (order_dual \u03b1) _ _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_bot' [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] [no_bot_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_bot) :\n  \u00ac bdd_below (range f) :=\n@unbounded_of_tendsto_at_top (order_dual \u03b1) (order_dual \u03b2) _ _ _ _ _ h\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_top` along *some* non-trivial filter `l`, then\nit tends to `at_top` along `at_top`. -/\nlemma tendsto_at_top_of_monotone_of_filter [preorder \u03b9] [preorder \u03b1] {l : filter \u03b9}\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_top) :\n  tendsto u at_top at_top :=\nh.tendsto_at_top_at_top $ \u03bb b, (hu.eventually (mem_at_top b)).exists\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_bot` along *some* non-trivial filter `l`, then\nit tends to `at_bot` along `at_bot`. -/\nlemma tendsto_at_bot_of_monotone_of_filter [preorder \u03b9] [preorder \u03b1] {l : filter \u03b9}\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_bot) :\n  tendsto u at_bot at_bot :=\n@tendsto_at_top_of_monotone_of_filter (order_dual \u03b9) (order_dual \u03b1) _ _ _ _ h.order_dual _ hu\n\nlemma tendsto_at_top_of_monotone_of_subseq [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1}\n  {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n  (H : tendsto (u \u2218 \u03c6) l at_top) :\n  tendsto u at_top at_top :=\ntendsto_at_top_of_monotone_of_filter h (tendsto_map' H)\n\nlemma tendsto_at_bot_of_monotone_of_subseq [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1}\n  {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n  (H : tendsto (u \u2218 \u03c6) l at_bot) :\n  tendsto u at_bot at_bot :=\ntendsto_at_bot_of_monotone_of_filter h (tendsto_map' H)\n\n/-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient\ncondition for comparison of the filter `at_top.map (\u03bb s, \u220f b in s, f b)` with\n`at_top.map (\u03bb s, \u220f b in s, g b)`. This is useful to compare the set of limit points of\n`\u03a0 b in s, f b` as `s \u2192 at_top` with the similar set for `g`. -/\n@[to_additive]\nlemma map_at_top_finset_prod_le_of_prod_eq [comm_monoid \u03b1] {f : \u03b2 \u2192 \u03b1} {g : \u03b3 \u2192 \u03b1}\n  (h_eq : \u2200u:finset \u03b3, \u2203v:finset \u03b2, \u2200v', v \u2286 v' \u2192 \u2203u', u \u2286 u' \u2227 \u220f x in u', g x = \u220f b in v', f b) :\n  at_top.map (\u03bbs:finset \u03b2, \u220f b in s, f b) \u2264 at_top.map (\u03bbs:finset \u03b3, \u220f x in s, g x) :=\nby rw [map_at_top_eq, map_at_top_eq];\nfrom (le_infi $ assume b, let \u27e8v, hv\u27e9 := h_eq b in infi_le_of_le v $\n  by simp [set.image_subset_iff]; exact hv)\n\nlemma has_antimono_basis.tendsto [semilattice_sup \u03b9] [nonempty \u03b9] {l : filter \u03b1}\n  {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 set \u03b1} (hl : l.has_antimono_basis p s) {\u03c6 : \u03b9 \u2192 \u03b1}\n  (h : \u2200 i : \u03b9, \u03c6 i \u2208 s i) : tendsto \u03c6 at_top l  :=\n(at_top_basis.tendsto_iff hl.to_has_basis).2 $ assume i hi,\n  \u27e8i, trivial, \u03bb j hij, hl.decreasing hi (hl.mono hij hi) hij (h j)\u27e9\n\nnamespace is_countably_generated\n\n/-- An abstract version of continuity of sequentially continuous functions on metric spaces:\nif a filter `k` is countably generated then `tendsto f k l` iff for every sequence `u`\nconverging to `k`, `f \u2218 u` tends to `l`. -/\nlemma tendsto_iff_seq_tendsto {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1} {l : filter \u03b2}\n  (hcb : k.is_countably_generated) :\n  tendsto f k l \u2194 (\u2200 x : \u2115 \u2192 \u03b1, tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) :=\nsuffices (\u2200 x : \u2115 \u2192 \u03b1, tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) \u2192 tendsto f k l,\n  from \u27e8by intros; apply tendsto.comp; assumption, by assumption\u27e9,\nbegin\n  rcases hcb.exists_antimono_basis with \u27e8g, gbasis, gmon, -\u27e9,\n  contrapose,\n  simp only [not_forall, gbasis.tendsto_left_iff, exists_const, not_exists, not_imp],\n  rintro \u27e8B, hBl, hfBk\u27e9,\n  choose x h using hfBk,\n  use x, split,\n  { exact (at_top_basis.tendsto_iff gbasis).2\n      (\u03bb i _, \u27e8i, trivial, \u03bb j hj, gmon trivial trivial hj (h j).1\u27e9) },\n  { simp only [tendsto_at_top', (\u2218), not_forall, not_exists],\n    use [B, hBl],\n    intro i, use [i, (le_refl _)],\n    apply (h i).right },\nend\n\nlemma tendsto_of_seq_tendsto {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1} {l : filter \u03b2}\n  (hcb : k.is_countably_generated) :\n  (\u2200 x : \u2115 \u2192 \u03b1, tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) \u2192 tendsto f k l :=\nhcb.tendsto_iff_seq_tendsto.2\n\nlemma subseq_tendsto {f : filter \u03b1} (hf : is_countably_generated f)\n  {u : \u2115 \u2192 \u03b1}\n  (hx : ne_bot (f \u2293 map u at_top)) :\n  \u2203 (\u03b8 : \u2115 \u2192 \u2115), (strict_mono \u03b8) \u2227 (tendsto (u \u2218 \u03b8) at_top f) :=\nbegin\n  rcases hf.exists_antimono_basis with \u27e8B, h\u27e9,\n  have : \u2200 N, \u2203 n \u2265 N, u n \u2208 B N,\n    from \u03bb N, filter.inf_map_at_top_ne_bot_iff.mp hx _ (h.to_has_basis.mem_of_mem trivial) N,\n  choose \u03c6 h\u03c6 using this,\n  cases forall_and_distrib.mp h\u03c6 with \u03c6_ge \u03c6_in,\n  have lim_u\u03c6 : tendsto (u \u2218 \u03c6) at_top f,\n    from h.tendsto \u03c6_in,\n  have lim_\u03c6 : tendsto \u03c6 at_top at_top,\n    from (tendsto_at_top_mono \u03c6_ge tendsto_id),\n  obtain \u27e8\u03c8, h\u03c8, h\u03c8\u03c6\u27e9 : \u2203 \u03c8 : \u2115 \u2192 \u2115, strict_mono \u03c8 \u2227 strict_mono (\u03c6 \u2218 \u03c8),\n    from strict_mono_subseq_of_tendsto_at_top lim_\u03c6,\n  exact \u27e8\u03c6 \u2218 \u03c8, h\u03c8\u03c6, lim_u\u03c6.comp $ strict_mono_tendsto_at_top h\u03c8\u27e9,\nend\n\nend is_countably_generated\n\nend filter\n\nopen filter finset\n\nsection\n\nvariables {R : Type*} [linear_ordered_semiring R]\n\nlemma exists_lt_mul_self (a : R) : \u2203 x \u2265 0, a < x * x :=\nlet \u27e8x, hxa, hx0\u27e9 :=((tendsto_mul_self_at_top.eventually (eventually_gt_at_top a)).and\n  (eventually_ge_at_top 0)).exists\nin \u27e8x, hx0, hxa\u27e9\n\nlemma exists_le_mul_self (a : R) : \u2203 x \u2265 0, a \u2264 x * x :=\nlet \u27e8x, hx0, hxa\u27e9 := exists_lt_mul_self a in \u27e8x, hx0, hxa.le\u27e9\n\nend\n\nnamespace order_iso\n\nvariables [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma comap_at_top (e : \u03b1 \u2243o \u03b2) : comap e at_top = at_top :=\nby simp [at_top, \u2190 e.surjective.infi_comp]\n\n@[simp] lemma comap_at_bot (e : \u03b1 \u2243o \u03b2) : comap e at_bot = at_bot :=\ne.dual.comap_at_top\n\n@[simp] lemma map_at_top (e : \u03b1 \u2243o \u03b2) : map \u21d1e at_top = at_top :=\nby rw [\u2190 e.comap_at_top, map_comap_of_surjective e.surjective]\n\n@[simp] lemma map_at_bot (e : \u03b1 \u2243o \u03b2) : map \u21d1e at_bot = at_bot :=\ne.dual.map_at_top\n\nlemma tendsto_at_top (e : \u03b1 \u2243o \u03b2) : tendsto e at_top at_top :=\ne.map_at_top.le\n\nlemma tendsto_at_bot (e : \u03b1 \u2243o \u03b2) : tendsto e at_bot at_bot :=\ne.map_at_bot.le\n\n@[simp] lemma tendsto_at_top_iff {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n  tendsto (\u03bb x, e (f x)) l at_top \u2194 tendsto f l at_top :=\nby rw [\u2190 e.comap_at_top, tendsto_comap_iff]\n\n@[simp] lemma tendsto_at_bot_iff {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n  tendsto (\u03bb x, e (f x)) l at_bot \u2194 tendsto f l at_bot :=\ne.dual.tendsto_at_top_iff\n\nend order_iso\n\n/-- Let `g : \u03b3 \u2192 \u03b2` be an injective function and `f : \u03b2 \u2192 \u03b1` be a function from the codomain of `g`\nto a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters\n`at_top.map (\u03bb s, \u220f i in s, f (g i))` and `at_top.map (\u03bb s, \u220f i in s, f i)` coincide.\n\nThe additive version of this lemma is used to prove the equality `\u2211' x, f (g x) = \u2211' y, f y` under\nthe same assumptions.-/\n@[to_additive]\nlemma function.injective.map_at_top_finset_prod_eq [comm_monoid \u03b1] {g : \u03b3 \u2192 \u03b2}\n  (hg : function.injective g) {f : \u03b2 \u2192 \u03b1} (hf : \u2200 x \u2209 set.range g, f x = 1) :\n  map (\u03bb s, \u220f i in s, f (g i)) at_top = map (\u03bb s, \u220f i in s, f i) at_top :=\nbegin\n  apply le_antisymm; refine map_at_top_finset_prod_le_of_prod_eq (\u03bb s, _),\n  { refine \u27e8s.preimage g (hg.inj_on _), \u03bb t ht, _\u27e9,\n    refine \u27e8t.image g \u222a s, finset.subset_union_right _ _, _\u27e9,\n    rw [\u2190 finset.prod_image (hg.inj_on _)],\n    refine (prod_subset (subset_union_left _ _) _).symm,\n    simp only [finset.mem_union, finset.mem_image],\n    refine \u03bb y hy hyt, hf y (mt _ hyt),\n    rintros \u27e8x, rfl\u27e9,\n    exact \u27e8x, ht (finset.mem_preimage.2 $ hy.resolve_left hyt), rfl\u27e9 },\n  { refine \u27e8s.image g, \u03bb t ht, _\u27e9,\n    simp only [\u2190 prod_preimage _ _ (hg.inj_on _) _ (\u03bb x _, hf x)],\n    exact \u27e8_, (image_subset_iff_subset_preimage _).1 ht, rfl\u27e9 }\nend\n\n/-- Let `g : \u03b3 \u2192 \u03b2` be an injective function and `f : \u03b2 \u2192 \u03b1` be a function from the codomain of `g`\nto an additive commutative monoid. Suppose that `f x = 0` outside of the range of `g`. Then the\nfilters `at_top.map (\u03bb s, \u2211 i in s, f (g i))` and `at_top.map (\u03bb s, \u2211 i in s, f i)` coincide.\n\nThis lemma is used to prove the equality `\u2211' x, f (g x) = \u2211' y, f y` under\nthe same assumptions.-/\nadd_decl_doc function.injective.map_at_top_finset_sum_eq\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/filter/at_top_bot.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7191249865018102}}
{"text": "/-\nFollowing code are mostly from Logic and Proof:\nhttps://leanprover.github.io/logic_and_proof/functions_in_lean.html\n\nby Jeremy Avigad, Robert Y. Lewis, and Floris van Doorn\n-/\nuniverses u v\nvariables {W X Y Z \u03b1 \u03b2: Sort*}\n\n/-\ndef comp (f : Y \u2192 Z) (g: X \u2192 Y) : X \u2192 Z :=\n\u03bbx, f(g x)\n\ninfixr ` \u2218 ` := comp\n\ndef id (x: X) : X := \nx\n-/\n-- funext is function extensionality (what?)\nexample (f g : X \u2192 Y) (h: \u2200 x, f x = g x) : f = g:=\nfunext h \n\n-- rfl is reflexivity\nlemma left_id (f : X \u2192 Y) : id \u2218 f = f := \nrfl\n\nlemma right_id (f: X \u2192 Y) : f \u2218 id = f := \nrfl\n\ntheorem comp.assoc (f: Z \u2192 W) (g: Y \u2192 Z) (h: X \u2192 Y) :\n(f \u2218 g) \u2218 h = f \u2218 (g \u2218 h) := rfl\n\ntheorem comp.left_id (f: X \u2192 Y) : id \u2218 f = f := rfl\n\ntheorem comp.right_id (f: X \u2192 Y) :f \u2218 id = f := rfl\n\n-- The double '{}', \u2983 \u2984 is super important\n-- If we write \u2200 x\u2081 : X, \u2200 x\u2082 : X, injective_cmp is not provable\ndef injective {X Y} (f : X \u2192 Y) : Prop :=\n  \u2200 \u2983 x\u2081 x\u2082 \u2984, f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082 \n\n/-- A function `f : \u03b1 \u2192 \u03b2` is called injective if `f x = f y` implies `x = y`. -/\n--@[reducible] def injective (f : \u03b1 \u2192 \u03b2) : Prop := \u2200 \u2983a\u2081 a\u2082\u2984, f a\u2081 = f a\u2082 \u2192 a\u2081 = a\u2082\n\ndef injective' (f : X \u2192 Y) : Prop :=\n  \u2200 \u2983 x\u2081 x\u2082 \u2984, f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082\n\n-- We can not write x\u2081 \u2208 X, use x\u2081 : X instead\ndef injective2 (f: X \u2192 Y) : Prop :=\n \u2200 \u2983 x\u2081 x\u2082 \u2984, x\u2081 \u2260 x\u2082 \u2192 f x\u2081 \u2260 f x\u2082\n\ndef injective3 (f: X \u2192 Y) : Prop :=\n \u2200 \u2983 a a' \u2984, a \u2260 a' \u2192 f a \u2260 f a'\n\ndef injective4 (f: X \u2192 Y) : Prop :=\n \u2200 \u2983 a a' \u2984, f a = f a' \u2192 a = a'\n\n-- We can eliminate writing :Y, :X\ndef surjective (f: X \u2192 Y) : Prop :=\n \u2200 y, \u2203 x, f x = y\n\ndef bijective (f: X \u2192 Y) := injective f \u2227 surjective f \n\n/--\n What is @id mean?\n @ is for preventing to fill implicit argument \n and forcing to fill statement.\n ... what?\n\n If we get rid of @ from \"@id\", lean raises type\n error anyway.\n--/\n\n/- \nLet's prove identity function is injective.\n\nThe syntax of injective proposition is defined with\ndef injective (f: X \u2192 Y) : Prop \nSo \"injective (@id X)\" means, \ngiven function id with domain X, it is injective.\n-/\ntheorem injective_id : injective (@id X) :=\nassume x\u2081 x\u2082,\nassume H : id x\u2081 = id x\u2082,\nshow x\u2081 = x\u2082, from H -- prove this from def of id\n\ntheorem injective_id3 : injective3 (@id X) :=\nassume a a',\nassume H : a \u2260 a',  -- contraposition can not be proved automatically\nshow id a \u2260 id a', from H \n\ntheorem injective_id4 : injective4 (@id X) :=\nassume a a',\nassume H : id a = id a',\nshow a = a', from H\n\n-- prove identity function is subjective\ntheorem surjective_id : surjective (@id X) :=\nassume y,\nshow \u2203 x, id x = y, from exists.intro y rfl\n\n-- prove identy function is bijective \ntheorem bijective_id : bijective(@id X) :=\nand.intro injective_id surjective_id\n\n-- prove compisition of injective functions\n-- is injective\n\n-- Why can not prove this?  Isn't this a tautology?\n-- lemma injective_g   {g : Y \u2192 Z} \n--                  (Hg: injective g) : injective (g) :=\n--assume y\u2081 y\u2082,\n--assume h: g y\u2081 = g y\u2082,\n--show y\u2081 = y\u2082, from h Hg\n\n-- theorem: if g and f are both injective, g \u2218 f is injective\ntheorem injective_comp {g : Y \u2192 Z} {f : X \u2192 Y}\n    (Hg : injective g) (Hf : injective f) : injective (g \u2218 f) :=\nassume x\u2081 x\u2082 : X,\n--assume y\u2081 y\u2082 : Y, -- This ': Y' is necessary for the following \n--assume  h2: g y\u2081 = g y\u2082,\n--have y\u2081 = y\u2082, from h2 Hg,\nassume h1 : (g \u2218 f) x\u2081 = (g \u2218 f) x\u2082,\n-- If f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082 from Hf\n-- If g x\u2082 = g x\u2082 \u2192 x\u2081 = x\u2082 from Hg\n-- If (g \u2218 f) x\u2081 = (g \u2218 f) x\u2082 \u2192 x\u2081 = x\u2082 \n-- How to prove the following prop?\n--  If (g \u2218 f) x\u2081 = (g \u2218 f) x\u2082 \u2192 f x\u2081 = f \u00d72\n-- Since g x\u2081 = g x\u2082 \u2192 x\u2081 = x\u2082 by Hg\n-- ALso f \u00d7\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082 by Hf\nhave f x\u2081 = f x\u2082, from Hg h1,\nshow x\u2081 = x\u2082, from Hf this \n\nexample (q r : Prop) : q \u2227 r \u2192 q :=\nassume h: q \u2227 r,\nhave r, from and.right h, \nshow q, from and.left h\n\n#check Type\n\n\n\n\nvariable U : Type \nvariable P : U \u2192 Prop\nvariable Q : Prop \n-- introduce a new variable y and prove Q\n-- under the assumption that P y holds.\nexample (h1 : \u2203 x, P x) (h2: \u2200 x, P x \u2192 Q) : Q :=\nexists.elim h1\n  (assume (y : U) (h: P y),\n    have h3 : P y \u2192 Q, from h2 y,\n    show Q, from h3 h)\n\n\nexample (h1: \u2203 x, P x) (h2: \u2200 x, P x \u2192 Q) : Q :=\nexists.elim h1 (assume y h, h2 y h)\n\nexample (h1: \u2203 x, P x) (h2: \u2200 x, P x \u2192 Q) : Q :=\nexists.elim h1 $\nassume y h, h2 y h\n\n--def surjective (f: X \u2192 Y) : Prop :=\n-- \u2200 y, \u2203 x, f x = y\n-- What is \"$\"?\n--   -> It is a syntax suger of '( some proof )'\ntheorem surjective_comp {g : Y \u2192 Z} {f: X \u2192 Y}\n  (hg: surjective g) (hf: surjective f) :\n  surjective (g \u2218 f) :=\n  assume z,\n  exists.elim (hg z) $\n  assume y (hy : g y = z),\n  exists.elim (hf y) $\n  assume x (hx : f x = y),\n  have g (f x) = z, from eq.subst (eq.symm hx) hy,\n  show \u2203 x, g (f x) = z, from exists.intro x this\n\n\n\n", "meta": {"author": "kmdtty", "repo": "lean_exercise", "sha": "467cce72c5f2c218e50c1d8cac57de3b805e7356", "save_path": "github-repos/lean/kmdtty-lean_exercise", "path": "github-repos/lean/kmdtty-lean_exercise/lean_exercise-467cce72c5f2c218e50c1d8cac57de3b805e7356/function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.8652240756264639, "lm_q1q2_score": 0.7191249825343212}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Patrick Massot\n-/\nimport data.set.intervals.proj_Icc\nimport topology.algebra.order.basic\n\n/-!\n# Projection onto a closed interval\n\nIn this file we prove that the projection `set.proj_Icc f a b h` is a quotient map, and use it\nto show that `Icc_extend h f` is continuous if and only if `f` is continuous.\n-/\n\nopen set filter\nopen_locale filter topological_space\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*} [linear_order \u03b1] [topological_space \u03b3] {a b c : \u03b1} {h : a \u2264 b}\n\nlemma filter.tendsto.Icc_extend (f : \u03b3 \u2192 Icc a b \u2192 \u03b2) {z : \u03b3} {l : filter \u03b1} {l' : filter \u03b2}\n  (hf : tendsto \u21bff (\ud835\udcdd z \u00d7\u1da0 l.map (proj_Icc a b h)) l') :\n  tendsto \u21bf(Icc_extend h \u2218 f) (\ud835\udcdd z \u00d7\u1da0 l) l' :=\nshow tendsto (\u21bff \u2218 prod.map id (proj_Icc a b h)) (\ud835\udcdd z \u00d7\u1da0 l) l', from\nhf.comp $ tendsto_id.prod_map tendsto_map\n\nvariables [topological_space \u03b1] [order_topology \u03b1] [topological_space \u03b2]\n\n@[continuity]\nlemma continuous_proj_Icc : continuous (proj_Icc a b h) :=\ncontinuous_subtype_mk _ $ continuous_const.max $ continuous_const.min continuous_id\n\nlemma quotient_map_proj_Icc : quotient_map (proj_Icc a b h) :=\nquotient_map_iff.2 \u27e8proj_Icc_surjective h, \u03bb s,\n  \u27e8\u03bb hs, hs.preimage continuous_proj_Icc,\n   \u03bb hs, \u27e8_, hs, by { ext, simp }\u27e9\u27e9\u27e9\n\n@[simp] lemma continuous_Icc_extend_iff {f : Icc a b \u2192 \u03b2} :\n  continuous (Icc_extend h f) \u2194 continuous f :=\nquotient_map_proj_Icc.continuous_iff.symm\n\n/-- See Note [continuity lemma statement]. -/\nlemma continuous.Icc_extend {f : \u03b3 \u2192 Icc a b \u2192 \u03b2} {g : \u03b3 \u2192 \u03b1}\n  (hf : continuous \u21bff) (hg : continuous g) : continuous (\u03bb a, Icc_extend h (f a) (g a)) :=\nhf.comp $ continuous_id.prod_mk $ continuous_proj_Icc.comp hg\n\n/-- A useful special case of `continuous.Icc_extend`. -/\n@[continuity]\nlemma continuous.Icc_extend' {f : Icc a b \u2192 \u03b2} (hf : continuous f) : continuous (Icc_extend h f) :=\nhf.comp continuous_proj_Icc\n\nlemma continuous_at.Icc_extend {x : \u03b3} (f : \u03b3 \u2192 Icc a b \u2192 \u03b2) {g : \u03b3 \u2192 \u03b1}\n  (hf : continuous_at \u21bff (x, proj_Icc a b h (g x))) (hg : continuous_at g x) :\n  continuous_at (\u03bb a, Icc_extend h (f a) (g a)) x :=\nshow continuous_at (\u21bff \u2218 \u03bb x, (x, proj_Icc a b h (g x))) x, from\ncontinuous_at.comp hf $ continuous_at_id.prod $ continuous_proj_Icc.continuous_at.comp hg\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/topology/algebra/order/proj_Icc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7191249821525256}}
{"text": "/-  Math40001 : Introduction to university mathematics.\n\nProblem Sheet 3, October 2019.\n\nThis is a Lean file. It can be read with the Lean theorem prover.\n\nYou can work on this file online at \nhttps://tinyurl.com/Lean-M40001-Example-Sheet-3\n\nor you can install Lean and its maths library following the\ninstructions at\nhttps://github.com/leanprover-community/mathlib#installation\n\nThere are advantages to installing Lean on your own computer\n(for example it's faster), but it's more hassle than\njust using it online. \n\nIn the below, delete \"sorry\" and replace it with some\ntactics which prove the result.\n\n-/\n\nimport data.real.basic -- the real numbers\n\n/- Question 1. \n\n  Say $X$, $Y$ and $Z$ are sets, and $f:X\\to Y$ and $g:Y\\to Z$ are functions. In lectures we proved that if \n$f$ and $g$ are injective, then $g\\circ f$ is also injective, and we will prove on Monday that if $f$ and $g\n$ are surjective, then $g\\circ f$ is surjective. But what about the other way?\n  \\begin{enumerate}\n  \\item If $g\\circ f$ is injective, then is $f$ injective? Give a proof or a counterexample.\n  \\item If $g\\circ f$ is injective, then is $g$ injective? Give a proof or a counterexample.\n  \\item If $g\\circ f$ is surjective, then is $f$ surjective? Give a proof or a counterexample.\n  \\item If $g\\circ f$ is surjective, then is $g$ surjective? Give a proof or a counterexample.\n  \\end{enumerate}\n-/\n\nopen function \n\n-- in Q1 you would be best off defining the counterexample explicitly before you embark upon the\n-- disproofs of the false statements\n\n-- put \u00ac in front of the \u2200 and put everything in brackets if you want to disprove it\nlemma question_one_a_true : \u2200 (X Y Z : Type) (f : X \u2192 Y) (g : Y \u2192 Z), injective (g \u2218 f) \u2192 injective f :=\nbegin\n  sorry\nend\n\n-- put \u00ac in front of the \u2200 and put everything in brackets if you want to disprove it\nlemma question_one_b_true : \u2200 (X Y Z : Type) (f : X \u2192 Y) (g : Y \u2192 Z), injective (g \u2218 f) \u2192 injective g :=\nbegin\n  sorry\nend\n\n-- put \u00ac in front of the \u2200 and put everything in brackets if you want to disprove it\nlemma question_one_c_true : \u2200 (X Y Z : Type) (f : X \u2192 Y) (g : Y \u2192 Z), surjective (g \u2218 f) \u2192 surjective f :=\nbegin\n  sorry\nend\n\n-- put \u00ac in front of the \u2200 and put everything in brackets if you want to disprove it\nlemma question_one_d_true : \u2200 (X Y Z : Type) (f : X \u2192 Y) (g : Y \u2192 Z), surjective (g \u2218 f) \u2192 surjective g :=\nbegin\n  sorry\nend\n\n/-\n% Q2\n\\item For each of the following functions, decide whether or not thprop_decidableey are injective, surjective, bijective. \nProofs required!\n\n  \\begin{enumerate}\n    \\item $f:\\R\\to\\R$, $f(x)=1/x$ if $x\\not=0$ and $f(0)=0$.\n\\item  $f : \\R\\to\\R$, $f(x)=2x+1$.\n\\item  $f:\\Z\\to\\Z$, $f(x)=2x+1$.\n\\item  $f:\\R\\to\\R$ defined by $f(x)=3-x$ if the Riemann hypothesis is true, and $f(x)=2+x$ if not. [NB the \\\nhref{https://en.wikipedia.org/wiki/Riemann_hypothesis}{Riemann Hypothesis} is a hard unsolved problem in mat\nhematics; nobody currently knows if it is true or false.]\n\\item $f:\\Z\\to\\Z$, $f(n)=n^3-2n^2+2n-1$.\n\\end{enumerate}\n\n-/\n\n-- this line just says \"we're mathematicians so every proposition is either true or false\"\nlocal attribute [instance, priority 10] classical.prop_decidable\n\n-- this line says \"a function might not be defined by an algorithm\"\nnoncomputable theory \n\n-- definition of the functions in Q2.\"\u03bb x,\" is the way computer scientists say \"x \u21a6\"\n\ndef fa : \u211d \u2192 \u211d := \u03bb x, 1 / x -- Lean defines 1/0 to be 0\n\ndef fb : \u211d \u2192 \u211d := \u03bb x, 2 * x + 1\n\ndef fc : \u2124 \u2192 \u2124 := \u03bb x, 2 * x + 1\n\nconstant Riemann_Hypothesis : Prop -- doesn't matter what it says\n\ndef fd : \u211d \u2192 \u211d := \u03bb x, if Riemann_Hypothesis then 3 - x else 2 + x\n\ndef fe : \u2124 \u2192 \u2124 := \u03bb n, n ^ 3 - 2 * n ^ 2 + 2 * n - 1\n\n-- now write your own questions, below are some examples (that may or may not be possible to prove)\nlemma Q2a1 : injective fa := sorry\nlemma Q2a2 : \u00ac (surjective fa) := sorry \nlemma Q2c3 : bijective fc := sorry \n\n/-\nQuestion 3 is \"why does this not make sense\" so it can't be formalised.\n-/\n\n/-\n  % Q4\n\\item  Prove the claim I will make in lecture on Monday, saying that if $f:X\\to Y$ is a function, and $g:Y\\t\no X$ is a two-sided inverse of~$f$, then~$f$ is a two-sided inverse for~$g$. Deduce that if~$X$ and~$Y$ are \nsets, and there exists a bijection from~$X$ to~$Y$, then there exists a bijection from~$Y$ to~$X$.\n-/\n\nlemma Q4a (X Y : Type) (f : X \u2192 Y) (g : Y \u2192 X) (h2sided : (\u2200 x : X, g (f x) = x) \u2227 (\u2200 y : Y, f (g y) = y)) : \n(\u2200 y : Y, f (g y) = y) \u2227 (\u2200 x : X, g (f x) = x) := sorry\n\n-- you will need this result to do the second part. Ignore the proof, I'm using term mode just to\n-- make it quicker. Note that this crazy-looking proof is an indication that there are other\n-- ways of using Lean apart from tactic mode.\n\nlemma exists_bijection_iff_has_two_sided_inverse (X Y : Type) :\n(\u2203 f : X \u2192 Y, bijective f) \u2194 (\u2203 (f : X \u2192 Y), \u2203 (g : Y \u2192 X), (\u2200 x : X, g (f x) = x) \u2227 (\u2200 y : Y, f (g y) = y)) :=\n\u27e8\u03bb \u27e8f, hf\u27e9, \u27e8f, bijective_iff_has_inverse.1 hf\u27e9,\n \u03bb \u27e8f, g, hgf, hfg\u27e9, \u27e8f, bijective_iff_has_inverse.2 \u27e8g, hgf, hfg\u27e9\u27e9\u27e9\n\nlemma Q4b (X Y : Type) : (\u2203 f : X \u2192 Y, bijective f) \u2194 (\u2203 g : Y \u2192 X, bijective g) := sorry\n\n/-\n  % Q5\n  \\item Let~$Z$ be a set. If $f:X\\to Z$ and $g:Y\\to Z$ are injective functions, let's say that $f$ \\emph{is \nfriends with} $g$ if there is a bijection $h:X\\to Y$ such that $f=g\\circ h$. Prove that $f$ is friends with \n$g$ if and only if the image of~$f$ equals the image of~$g$. NB: by the \\emph{image} of $f:X\\to Z$ I mean th\ne subset of~$Z$ consisting of things ``hit'' by $f$, in other words the set $\\{z\\in Z\\,:\\,\\exists x\\in X, f(\nx)=z\\}$. Some people call this the ``range'' of $f$, although other people use ``range'' to mean the same th\ning as ``codomain'' :-| \n\n-/\n\ndef friends {X Y Z : Type} (f : X \u2192 Z) (g : Y \u2192 Z) (hf : injective f) (hg : injective g) :=\n  \u2203 h : X \u2192 Y, bijective h \u2227 f = g \u2218 h\n\nlemma Q5 (X Y Z : Type) (f : X \u2192 Z) (g : Y \u2192 Z) (hf : injective f) (hg : injective g) :\nfriends f g hf hg \u2194 set.range f = set.range g := sorry\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2019/questions/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.865224070413529, "lm_q1q2_score": 0.719124974582753}}
{"text": "/-In this tutorial, we aim to introduce using logic in Lean. We will firstly look at \ndefining logical quantifiers.#check\n\nThe symbol '\u2227', which can be written by \\and means and. Therefore, for logical\nstatements A and B, A \u2227 B means A and B.\n\nFurthermore, the symbol '\u2228' means or, which can be typed out using \\or .\n\nWhen using Lean, we also need to use tactics. These are commands that Lean interprets\nwhich help us to progress towards closing the goal.\n\nFirstly, if we have a hypothesis which is identical to our goal, say h, then we can\nuse the 'exact h,' tactic to close our goal.\n\nSecondly, the 'intro' tactic can be used whenever we have an '\u2194' if implication \nin our goal. For example, if our goal is of the form\n\u22a2 A \u2192 B \nthen by typing 'intro h,' we introduce a new hypothesis h:A with our goal\nchanging to \u22a2 B.\n\nThe 'left,' and 'right,' tactics can be used when we have a goal containing an\n\u2228 symbol. 'left,' will change a goal of the form \u22a2A \u2228 B to \u22a2 A. \nOn the other hand, by typing 'right,' a goal of the form \u22a2 A \u2228 B will change\nto \u22a2 B.#check\n\nFurthermore, the 'split' tactic can be used when our goal contains an '\u2227' symbol.\n'split' will change a goal of the form \u22a2 A \u2227 B to two separate goals, \u22a2 A and \u22a2 B\nwhich we prove separately. We can also use 'split,' whenever we have an '\u2194' iff \nstatement in the goal.\n\nWe may also have an instance where we want to consider the cases when A is true\nand false separately. This can be done by deploying the 'by_cases' tactic. By writing\nsomething similar to 'by_cases h:A,' we will introduce two identical goals, one with\na hypothesis h:A and the other with the hypothesis h:\u00acA.#check\n\nFinally, if one of our hypotheses contain an '\u2227' or a '\u2228' statement, we can use the\ncases tactic. If our hypothesis is of the form h: A \u2227 B, by typing \n'cases h with h\u2081 h\u2082,'\nwe will transform the hypothesis h into two simpler hypotheses h\u2081:A and h\u2082:B \nwhich are more easily handled.\nFurthermore, if we have a hypothesis of the form h: A \u2228 B, and one goal, then by typing \n'cases h with h\u2081 h\u2082,' \nwe will change our hypothesis h into two separate hypotheses h\u2081 : A and h\u2082 : B\nwhich are each placed separately in two different goals. This means that we consider\nwhen A and B are true separately.\n\nWe will now provide a few examples of logic in Lean. The statement we wish to prove\nwill follow after the word 'example' and our proof goes between the 'begin' and 'end'\ncommands. For any incomplete exercise, remove the sorry to begin the proof. \n-/\n\nexample (A : Prop) (h:A) : A:=\nbegin\nexact h,\nend\n\nexample (A B : Prop) (h : B) : A \u2228 B :=\nbegin\nright,\nexact h,\nend\n\nexample (A B : Prop) (h\u2081: A) (h\u2082: B) : A \u2227 B :=\nbegin\nsplit,\nexact h\u2081,\nexact h\u2082,\nend\n\nexample (A : Prop) : A \u2228 \u00ac A :=\nbegin\nby_cases h : A,\nleft,\nexact h,\nright, \nexact h,\nend\n\nexample (A B : Prop) (h: A \u2227 \u00ac B) : \u00ac B \u2227 A :=\nbegin\ncases h with h\u2081 h\u2082,\nsplit, \nexact h\u2082,\nexact h\u2081,\nend\n\nexample (A B C : Prop) (h : (A \u2227 B) \u2228 C) : B \u2228 C :=\nbegin\ncases h with h\u2081 h\u2082,\ncases h\u2081 with h\u2082 h\u2083,\nleft,\nexact h\u2083,\nright, \nexact h\u2082,\nend\n\nexample (A B : Prop) : A \u2227 B \u2192 A \u2228 B :=\nbegin\nintro h,\ncases h with h\u2081 h\u2082,\nleft,\nexact h\u2081,\nend\n\nexample (A B : Prop): (A \u2228 \u00ac A) \u2227 (B \u2228 \u00acB) :=\nbegin\nsplit, \nby_cases h:A,\nleft,\nexact h,\nright,\nexact h,\nby_cases h:B,\nleft,\nexact h,\nright,\nexact h,\nend\n\ntheorem lawofcomm (A B : Prop) : A\u2227B \u2194 B\u2227A:=\nbegin\nsplit, --We consider the separate implications \u22a2 A \u2227 B \u2192 B \u2227 A and \u22a2B \u2227 A \u2192 A \u2227 B\nintro h\u2081, --This lets us consider the hypothesis h\u2081: A \u2227 B\ncases h\u2081 with h\u2082 h\u2083, -- h\u2081:A \u2227 B changes to h\u2082:A and h\u2083:B\nsplit,--Instead of showing B \u2227 A we show B and A separately\nexact h\u2083, --Our goal, \u22a2B is the same as our hypothesis h\u2083\nexact h\u2082, --Our goal, \u22a2A is the same as our hypothesis h\u2082 \nintro h\u2081, --Due to the symmetric nature of the proof, we just repeat what we've written above\ncases h\u2081 with h\u2082 h\u2083,\nsplit,\nexact h\u2083,\nexact h\u2082,\nend\n\n--Now it's time for you to have a go. Delete the sorry and continue the proofs.\n\nexample (A B : Prop) : A \u2228 B \u2228 \u00ac A \u2228 B :=\nbegin\nsorry,\nend\n\ntheorem lawofassoc (A B C : Prop) : A\u2227(B\u2227C) \u2194 (A\u2227B)\u2227C:=\nbegin\nsorry,\nend\n\ntheorem lawofdist (A B C : Prop) : A\u2227(B\u2228C) \u2194 (A\u2227B)\u2228(A\u2227C):=\nbegin\nsorry,\nend\n\ntheorem de_morgan1 (A B : Prop) : \u00ac (A\u2228B) \u2194 (\u00acA) \u2227 (\u00acB) :=\nbegin\nsorry,\nend\n\ntheorem de_morgan2 (A B : Prop) : \u00ac(A\u2227B) \u2194 (\u00acA)\u2228(\u00acB):=\nbegin\nsorry,\nend\n", "meta": {"author": "HarryPacitti", "repo": "LeanAnalysisTutorial1", "sha": "a1d39999c13f33aecd808d72961c94edc10c54a8", "save_path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1", "path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1/LeanAnalysisTutorial1-a1d39999c13f33aecd808d72961c94edc10c54a8/Examples/Analysistutoriallogic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758842, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7191249659007743}}
{"text": "/-\nCopyright (c) 2015 William Peterson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: William Peterson, Jeremy Avigad\n\nExtended gcd, Bezout's theorem, chinese remainder theorem.\n-/\nimport data.nat.div data.int .primes\n\n/- Bezout's theorem -/\n\nsection Bezout\n\nopen nat int\nopen eq.ops well_founded decidable prod\n\nprivate definition pair_nat.lt : \u2115 \u00d7 \u2115 \u2192 \u2115 \u00d7 \u2115 \u2192 Prop := measure pr\u2082\nprivate definition pair_nat.lt.wf : well_founded pair_nat.lt := intro_k (measure.wf pr\u2082) 20\nlocal attribute pair_nat.lt.wf [instance]\nlocal infixl `\u227a`:50 := pair_nat.lt\n\nprivate definition gcd.lt.dec (x y\u2081 : \u2115) : (succ y\u2081, x % succ y\u2081) \u227a (x, succ y\u2081) :=\n!nat.mod_lt (succ_pos y\u2081)\n\nprivate definition egcd_rec_f (z : \u2124) : \u2124 \u2192 \u2124 \u2192 \u2124 \u00d7 \u2124 := \u03bb s t, (t, s - t * z)\n\ndefinition egcd.F : \u03a0 (p\u2081 : \u2115 \u00d7 \u2115), (\u03a0 p\u2082 : \u2115 \u00d7 \u2115, p\u2082 \u227a p\u2081 \u2192 \u2124 \u00d7 \u2124) \u2192 \u2124 \u00d7 \u2124\n| (x, y) := nat.cases_on y\n              (\u03bb f, (1, 0) )\n              (\u03bb y\u2081 (f : \u03a0 p\u2082, p\u2082 \u227a (x, succ y\u2081) \u2192 \u2124 \u00d7 \u2124),\n                let bz := f (succ y\u2081, x % succ y\u2081) !gcd.lt.dec in\n                prod.cases_on bz (egcd_rec_f (x / succ y\u2081)))\n\ndefinition egcd (x y : \u2115) := fix egcd.F (pair x y)\n\ntheorem egcd_zero (x : \u2115) : egcd x 0 = (1, 0) :=\nwell_founded.fix_eq egcd.F (x, 0)\n\ntheorem egcd_succ (x y : \u2115) :\n  egcd x (succ y) = prod.cases_on (egcd (succ y) (x % succ y)) (egcd_rec_f (x / succ y)) :=\nwell_founded.fix_eq egcd.F (x, succ y)\n\ntheorem egcd_of_pos (x : \u2115) {y : \u2115} (ypos : y > 0) :\n  let erec := egcd y (x % y), u := pr\u2081 erec, v := pr\u2082 erec in\n    egcd x y = (v, u - v * (x / y)) :=\nobtain (y' : nat) (yeq : y = succ y'), from exists_eq_succ_of_pos ypos,\nbegin\n  rewrite [yeq, egcd_succ, -prod.eta (egcd _ _)],\n  esimp, unfold egcd_rec_f,\n  rewrite [of_nat_div]\nend\n\ntheorem egcd_prop (x y : \u2115) : (pr\u2081 (egcd x y)) * x + (pr\u2082 (egcd x y)) * y = gcd x y :=\ngcd.induction x y\n  (take m, by krewrite [egcd_zero, mul_zero, one_mul])\n  (take m n,\n    assume npos : 0 < n,\n    assume IH,\n    begin\n      note H := egcd_of_pos m npos, esimp at H,\n      rewrite H,\n      esimp,\n      rewrite [gcd_rec, -IH],\n      rewrite [add.comm],\n      rewrite [-of_nat_mod],\n      rewrite [int.mod_def],\n      rewrite [+mul_sub_right_distrib],\n      rewrite [+mul_sub_left_distrib, *left_distrib],\n      rewrite [*sub_eq_add_neg, {pr\u2082 (egcd n (m % n)) * of_nat m + - _}add.comm],\n      rewrite [-add.assoc, mul.assoc]\n    end)\n\ntheorem Bezout_aux (x y : \u2115) : \u2203 a b : \u2124, a * x + b * y = gcd x y :=\nexists.intro _ (exists.intro _ (egcd_prop x y))\n\ntheorem Bezout (x y : \u2124) : \u2203 a b : \u2124, a * x + b * y = gcd x y :=\nobtain a' b' (H : a' * nat_abs x + b' * nat_abs y = gcd x y), from !Bezout_aux,\nbegin\n  existsi (a' * sign x),\n  existsi (b' * sign y),\n  rewrite [*mul.assoc, -*abs_eq_sign_mul, -*of_nat_nat_abs],\n  apply H\nend\nend Bezout\n\n/-\nA sample application of Bezout's theorem, namely, an alternative proof that irreducible\nimplies prime (dvd_or_dvd_of_prime_of_dvd_mul).\n-/\n\nnamespace nat\nopen int\n\nexample {p x y : \u2115} (pp : prime p) (H : p \u2223 x * y) : p \u2223 x \u2228 p \u2223 y :=\ndecidable.by_cases\n  (suppose p \u2223 x, or.inl this)\n  (suppose \u00ac p \u2223 x,\n    have cpx : coprime p x, from coprime_of_prime_of_not_dvd pp this,\n    obtain (a b : \u2124) (Hab : a * p + b * x = gcd p x), from Bezout_aux p x,\n    have a * p * y + b * x * y = y,\n      by krewrite [-right_distrib, Hab, \u2191coprime at cpx, cpx, int.one_mul],\n    have p \u2223 y,\n      begin\n        apply dvd_of_of_nat_dvd_of_nat,\n        rewrite [-this],\n        apply @dvd_add,\n          {apply dvd_mul_of_dvd_left,\n            apply dvd_mul_of_dvd_right,\n            apply dvd.refl},\n          {rewrite mul.assoc,\n            apply dvd_mul_of_dvd_right,\n            apply of_nat_dvd_of_nat_of_dvd H}\n      end,\n    or.inr this)\n\nend nat\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/theories/number_theory/bezout.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7190924841029135}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Importar la librer\u00eda de las t\u00e1cticas.\n-- ----------------------------------------------------------------------\n\nimport tactic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Declarar R como una variable de tipo de los anillos\n-- conmutativos.\n-- ----------------------------------------------------------------------\n\nvariables (R : Type*) [comm_ring R]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Declarar a, b, c y d como variables sobre R.\n-- ----------------------------------------------------------------------\n\nvariables a b c d : R\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Demostrar que\n--     (c * b) * a = b * (a * c)\n-- ----------------------------------------------------------------------\n\nexample : (c * b) * a = b * (a * c) :=\nby ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que\n--     (a + b) * (a + b) = a * a + 2 * (a * b) + b * b\n-- ----------------------------------------------------------------------\n\nexample : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nby ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Demostrar que\n--     (a + b) * (a - b) = a^2 - b^2\n-- ----------------------------------------------------------------------\n\nexample : (a + b) * (a - b) = a^2 - b^2 :=\nby ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Demostrar que si\n--    c = d * a + b\n--    b = a * d\n-- entonces\n--    c = 2 * a * d\n-- ----------------------------------------------------------------------\n\nexample\n  (h1 : c = d * a + b)\n  (h2 : b = a * d)\n  : c = 2 * a * d :=\nbegin\n  rw [h1, h2],\n  ring\nend\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Basicos/Propiedades_de_anillos_conmutativos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7190924760414954}}
{"text": "/-\nCopyright (c) 2021 Alena Gusakov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alena Gusakov\n-/\nimport combinatorics.simple_graph.basic\nimport data.set.finite\n/-!\n# Strongly regular graphs\n\n## Main definitions\n\n* `G.is_SRG_of n k l m` (see `is_simple_graph.is_SRG_of`) is a structure for a `simple_graph`\n  satisfying the following conditions:\n  * The cardinality of the vertex set is `n`\n  * `G` is a regular graph with degree `k`\n  * The number of common neighbors between any two adjacent vertices in `G` is `l`\n  * The number of common neighbors between any two nonadjacent vertices in `G` is `m`\n\n## TODO\n- Prove that the complement of a strongly regular graph is strongly regular with parameters\n  `is_SRG_of n (n - k - 1) (n - 2 - 2k + m) (v - 2k + l)`\n- Prove that the parameters of a strongly regular graph\n  obey the relation `(n - k - 1) * m = k * (k - l - 1)`\n- Prove that if `I` is the identity matrix and `J` is the all-one matrix,\n  then the adj matrix `A` of SRG obeys relation `A^2 = kI + lA + m(J - I - A)`\n-/\n\nuniverses u\n\nnamespace simple_graph\nvariables {V : Type u}\nvariables (G : simple_graph V) [decidable_rel G.adj]\n\nvariables [fintype V] [decidable_eq V]\n\n/--\nA graph is strongly regular with parameters `n k l m` if\n * its vertex set has cardinality `n`\n * it is regular with degree `k`\n * every pair of adjacent vertices has `l` common neighbors\n * every pair of nonadjacent vertices has `m` common neighbors\n-/\nstructure is_SRG_of (n k l m : \u2115) : Prop :=\n(card : fintype.card V = n)\n(regular : G.is_regular_of_degree k)\n(adj_common : \u2200 (v w : V), G.adj v w \u2192 fintype.card (G.common_neighbors v w) = l)\n(nadj_common : \u2200 (v w : V), \u00ac G.adj v w \u2227 v \u2260 w \u2192 fintype.card (G.common_neighbors v w) = m)\n\nopen finset\n\n/-- Complete graphs are strongly regular. Note that the parameter `m` can take any value\n  for complete graphs, since there are no distinct pairs of nonadjacent vertices. -/\nlemma complete_strongly_regular (m : \u2115) :\n  (complete_graph V).is_SRG_of (fintype.card V) (fintype.card V - 1) (fintype.card V - 2) m :=\n{ card := rfl,\n  regular := complete_graph_degree,\n  adj_common := \u03bb v w (h : v \u2260 w),\n    begin\n      simp only [fintype.card_of_finset, mem_common_neighbors, complete_graph, ne.def, filter_not,\n        \u2190not_or_distrib, filter_eq, filter_or, card_univ_diff, mem_univ, if_pos, \u2190insert_eq],\n      rw [card_insert_of_not_mem, card_singleton],\n      simpa,\n    end,\n  nadj_common := \u03bb v w (h : \u00ac(v \u2260 w) \u2227 _), (h.1 h.2).elim }\n\nend simple_graph\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/combinatorics/simple_graph/strongly_regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.7190606121408627}}
{"text": "import Mynat.Mul\n\nnamespace mynat\n\ndef mypow (m n : mynat) : mynat :=\n  match n with\n  | 0 => 1\n  | succ n' => mymul (mypow m n') m\n\ninstance : Pow mynat mynat where\n  pow := mypow\n\ntheorem pow_zero (a : mynat) : a ^ (0 : mynat) = 1 := rfl\ntheorem pow_succ (a b : mynat) : a ^ (succ b) = a ^ b * a := rfl\n\ntheorem zero_pow_zero : (0 : mynat) ^ (0 : mynat) = 1 := by\n  rw [pow_zero]\n\ntheorem zero_pow_succ (m : mynat) : (0 : mynat) ^ (succ m) = 0 := by\n  rw [pow_succ]\n  rw [mul_zero]\n\ntheorem pow_one (a : mynat) : a ^ (1 : mynat) = a := by\n  rw [one_eq_succ_zero]\n  rw [pow_succ]\n  rw [pow_zero]\n  rw [one_mul]\n\ntheorem one_pow (m : mynat) : (1 : mynat) ^ m = 1 := by\n  cases m\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [pow_zero]\n  case succ m' =>\n    rw [pow_succ]\n    rw [one_pow m']\n    rw [one_mul]\n\ntheorem pow_add (a m n : mynat) : a ^ (m + n) = a ^ m * a ^ n := by\n  cases n\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [add_zero]\n    rw [pow_zero]\n    rw [mul_one]\n  case succ n' =>\n    rw [add_succ]\n    rw [pow_succ]\n    rw [pow_succ]\n    rw [\u2190 mul_assoc (a ^ m) (a ^ n') a]\n    rw [pow_add a m n']\n\ntheorem mul_pow (a b n : mynat) : (a * b) ^ n = a ^ n * b ^ n := by\n  cases n\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    repeat {rw [pow_zero]}\n    rfl\n  case succ n' =>\n    rw [pow_succ]\n    rw [pow_succ]\n    rw [pow_succ]\n    rw [mul_pow a b n']\n    rw [mul_assoc (a ^ n') a (b ^ n' * b)]\n    rw [\u2190 mul_assoc a (b ^ n') b]\n    rw [mul_comm a (b ^ n')]\n    rw [mul_assoc (b ^ n') a b]\n    rw [mul_assoc (a ^ n') (b ^ n') (a * b)]\n\ntheorem pow_pow (a m n : mynat) : (a ^ m) ^ n = a ^ (m * n) := by\n  cases n\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [pow_zero]\n    rw [mul_zero]\n    rw [pow_zero]\n  case succ n' =>\n    rw [pow_succ]\n    rw [pow_pow a m n']\n    rw [\u2190 pow_add]\n    rw [mul_succ]\n\ntheorem add_squared (a b : mynat) :\n  (a + b) ^ (2 : mynat) = a ^ (2 : mynat) + b ^ (2 : mynat) + 2 * a * b := by\n  have h2 : (2 : mynat) = succ 1 := rfl\n  rw [h2]\n  rw [one_eq_succ_zero]\n  rw [pow_succ]\n  rw [pow_succ]\n  rw [pow_succ]\n  rw [pow_succ]\n  rw [pow_succ]\n  rw [pow_succ]\n  rw [pow_zero]\n  rw [one_mul]\n  rw [pow_zero]\n  rw [pow_zero]\n  rw [one_mul]\n  rw [one_mul]\n  rw [succ_mul]\n  rw [succ_mul]\n  rw [zero_mul]\n  rw [zero_add]\n  rw [add_mul]\n  rw [mul_add]\n  rw [mul_add]\n  rw [add_mul]\n  rw [add_assoc]\n  rw [add_assoc]\n  rw [\u2190 add_assoc (b * b) (a * b) (a * b)]\n  rw [add_comm (b * b) (a * b)]\n  rw [add_assoc]\n  rw [add_comm (b * b) (a * b)]\n  rw [mul_comm a b]  \n\nend mynat", "meta": {"author": "plumsirawit", "repo": "mynat", "sha": "0a6529078322c76f7460ef6dafba8367608a5163", "save_path": "github-repos/lean/plumsirawit-mynat", "path": "github-repos/lean/plumsirawit-mynat/mynat-0a6529078322c76f7460ef6dafba8367608a5163/Mynat/Pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7190606092389308}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module analysis.box_integral.partition.split\n! leanprover-community/mathlib commit 6ca1a09bc9aa75824bf97388c9e3b441fc4ccf3f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.BoxIntegral.Partition.Basic\n\n/-!\n# Split a box along one or more hyperplanes\n\n## Main definitions\n\nA hyperplane `{x : \u03b9 \u2192 \u211d | x i = a}` splits a rectangular box `I : box_integral.box \u03b9` into two\nsmaller boxes. If `a \u2209 Ioo (I.lower i, I.upper i)`, then one of these boxes is empty, so it is not a\nbox in the sense of `box_integral.box`.\n\nWe introduce the following definitions.\n\n* `box_integral.box.split_lower I i a` and `box_integral.box.split_upper I i a` are these boxes (as\n  `with_bot (box_integral.box \u03b9)`);\n* `box_integral.prepartition.split I i a` is the partition of `I` made of these two boxes (or of one\n   box `I` if one of these boxes is empty);\n* `box_integral.prepartition.split_many I s`, where `s : finset (\u03b9 \u00d7 \u211d)` is a finite set of\n  hyperplanes `{x : \u03b9 \u2192 \u211d | x i = a}` encoded as pairs `(i, a)`, is the partition of `I` made by\n  cutting it along all the hyperplanes in `s`.\n\n## Main results\n\nThe main result `box_integral.prepartition.exists_Union_eq_diff` says that any prepartition `\u03c0` of\n`I` admits a prepartition `\u03c0'` of `I` that covers exactly `I \\ \u03c0.Union`. One of these prepartitions\nis available as `box_integral.prepartition.compl`.\n\n## Tags\n\nrectangular box, partition, hyperplane\n-/\n\n\nnoncomputable section\n\nopen Classical BigOperators Filter\n\nopen Function Set Filter\n\nnamespace BoxIntegral\n\nvariable {\u03b9 M : Type _} {n : \u2115}\n\nnamespace Box\n\nvariable {I : Box \u03b9} {i : \u03b9} {x : \u211d} {y : \u03b9 \u2192 \u211d}\n\n/-- Given a box `I` and `x \u2208 (I.lower i, I.upper i)`, the hyperplane `{y : \u03b9 \u2192 \u211d | y i = x}` splits\n`I` into two boxes. `box_integral.box.split_lower I i x` is the box `I \u2229 {y | y i \u2264 x}`\n(if it is nonempty). As usual, we represent a box that may be empty as\n`with_bot (box_integral.box \u03b9)`. -/\ndef splitLower (I : Box \u03b9) (i : \u03b9) (x : \u211d) : WithBot (Box \u03b9) :=\n  mk' I.lower (update I.upper i (min x (I.upper i)))\n#align box_integral.box.split_lower BoxIntegral.Box.splitLower\n\n@[simp]\ntheorem coe_splitLower : (splitLower I i x : Set (\u03b9 \u2192 \u211d)) = I \u2229 { y | y i \u2264 x } :=\n  by\n  rw [split_lower, coe_mk']\n  ext y\n  simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_set_of_eq, forall_and, \u2190 Pi.le_def,\n    le_update_iff, le_min_iff, and_assoc', and_forall_ne i, mem_def]\n  rw [and_comm' (y i \u2264 x), Pi.le_def]\n#align box_integral.box.coe_split_lower BoxIntegral.Box.coe_splitLower\n\ntheorem splitLower_le : I.splitLower i x \u2264 I :=\n  withBotCoe_subset_iff.1 <| by simp\n#align box_integral.box.split_lower_le BoxIntegral.Box.splitLower_le\n\n@[simp]\ntheorem splitLower_eq_bot {i x} : I.splitLower i x = \u22a5 \u2194 x \u2264 I.lower i :=\n  by\n  rw [split_lower, mk'_eq_bot, exists_update_iff I.upper fun j y => y \u2264 I.lower j]\n  simp [(I.lower_lt_upper _).not_le]\n#align box_integral.box.split_lower_eq_bot BoxIntegral.Box.splitLower_eq_bot\n\n@[simp]\ntheorem splitLower_eq_self : I.splitLower i x = I \u2194 I.upper i \u2264 x := by\n  simp [split_lower, update_eq_iff]\n#align box_integral.box.split_lower_eq_self BoxIntegral.Box.splitLower_eq_self\n\ntheorem splitLower_def [DecidableEq \u03b9] {i x} (h : x \u2208 Ioo (I.lower i) (I.upper i))\n    (h' : \u2200 j, I.lower j < update I.upper i x j :=\n      (forall_update_iff I.upper fun j y => I.lower j < y).2\n        \u27e8h.1, fun j hne => I.lower_lt_upper _\u27e9) :\n    I.splitLower i x = (\u27e8I.lower, update I.upper i x, h'\u27e9 : Box \u03b9) :=\n  by\n  simp only [split_lower, mk'_eq_coe, min_eq_left h.2.le]\n  use rfl\n  congr\n#align box_integral.box.split_lower_def BoxIntegral.Box.splitLower_def\n\n/-- Given a box `I` and `x \u2208 (I.lower i, I.upper i)`, the hyperplane `{y : \u03b9 \u2192 \u211d | y i = x}` splits\n`I` into two boxes. `box_integral.box.split_upper I i x` is the box `I \u2229 {y | x < y i}`\n(if it is nonempty). As usual, we represent a box that may be empty as\n`with_bot (box_integral.box \u03b9)`. -/\ndef splitUpper (I : Box \u03b9) (i : \u03b9) (x : \u211d) : WithBot (Box \u03b9) :=\n  mk' (update I.lower i (max x (I.lower i))) I.upper\n#align box_integral.box.split_upper BoxIntegral.Box.splitUpper\n\n@[simp]\ntheorem coe_splitUpper : (splitUpper I i x : Set (\u03b9 \u2192 \u211d)) = I \u2229 { y | x < y i } :=\n  by\n  rw [split_upper, coe_mk']\n  ext y\n  simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_set_of_eq, forall_and,\n    forall_update_iff I.lower fun j z => z < y j, max_lt_iff, and_assoc' (x < y i), and_forall_ne i,\n    mem_def]\n  exact and_comm' _ _\n#align box_integral.box.coe_split_upper BoxIntegral.Box.coe_splitUpper\n\ntheorem splitUpper_le : I.splitUpper i x \u2264 I :=\n  withBotCoe_subset_iff.1 <| by simp\n#align box_integral.box.split_upper_le BoxIntegral.Box.splitUpper_le\n\n@[simp]\ntheorem splitUpper_eq_bot {i x} : I.splitUpper i x = \u22a5 \u2194 I.upper i \u2264 x :=\n  by\n  rw [split_upper, mk'_eq_bot, exists_update_iff I.lower fun j y => I.upper j \u2264 y]\n  simp [(I.lower_lt_upper _).not_le]\n#align box_integral.box.split_upper_eq_bot BoxIntegral.Box.splitUpper_eq_bot\n\n@[simp]\ntheorem splitUpper_eq_self : I.splitUpper i x = I \u2194 x \u2264 I.lower i := by\n  simp [split_upper, update_eq_iff]\n#align box_integral.box.split_upper_eq_self BoxIntegral.Box.splitUpper_eq_self\n\ntheorem splitUpper_def [DecidableEq \u03b9] {i x} (h : x \u2208 Ioo (I.lower i) (I.upper i))\n    (h' : \u2200 j, update I.lower i x j < I.upper j :=\n      (forall_update_iff I.lower fun j y => y < I.upper j).2\n        \u27e8h.2, fun j hne => I.lower_lt_upper _\u27e9) :\n    I.splitUpper i x = (\u27e8update I.lower i x, I.upper, h'\u27e9 : Box \u03b9) :=\n  by\n  simp only [split_upper, mk'_eq_coe, max_eq_left h.1.le]\n  refine' \u27e8_, rfl\u27e9\n  congr\n#align box_integral.box.split_upper_def BoxIntegral.Box.splitUpper_def\n\ntheorem disjoint_splitLower_splitUpper (I : Box \u03b9) (i : \u03b9) (x : \u211d) :\n    Disjoint (I.splitLower i x) (I.splitUpper i x) :=\n  by\n  rw [\u2190 disjoint_with_bot_coe, coe_split_lower, coe_split_upper]\n  refine' (Disjoint.inf_left' _ _).inf_right' _\n  rw [Set.disjoint_left]\n  exact fun y (hle : y i \u2264 x) hlt => not_lt_of_le hle hlt\n#align box_integral.box.disjoint_split_lower_split_upper BoxIntegral.Box.disjoint_splitLower_splitUpper\n\ntheorem splitLower_ne_splitUpper (I : Box \u03b9) (i : \u03b9) (x : \u211d) :\n    I.splitLower i x \u2260 I.splitUpper i x :=\n  by\n  cases le_or_lt x (I.lower i)\n  \u00b7 rw [split_upper_eq_self.2 h, split_lower_eq_bot.2 h]\n    exact WithBot.bot_ne_coe\n  \u00b7 refine' (disjoint_split_lower_split_upper I i x).Ne _\n    rwa [Ne.def, split_lower_eq_bot, not_le]\n#align box_integral.box.split_lower_ne_split_upper BoxIntegral.Box.splitLower_ne_splitUpper\n\nend Box\n\nnamespace Prepartition\n\nvariable {I J : Box \u03b9} {i : \u03b9} {x : \u211d}\n\n/-- The partition of `I : box \u03b9` into the boxes `I \u2229 {y | y \u2264 x i}` and `I \u2229 {y | x i < y}`.\nOne of these boxes can be empty, then this partition is just the single-box partition `\u22a4`. -/\ndef split (I : Box \u03b9) (i : \u03b9) (x : \u211d) : Prepartition I :=\n  ofWithBot {I.splitLower i x, I.splitUpper i x}\n    (by\n      simp only [Finset.mem_insert, Finset.mem_singleton]\n      rintro J (rfl | rfl)\n      exacts[box.split_lower_le, box.split_upper_le])\n    (by\n      simp only [Finset.coe_insert, Finset.coe_singleton, true_and_iff, Set.mem_singleton_iff,\n        pairwise_insert_of_symmetric symmetric_disjoint, pairwise_singleton]\n      rintro J rfl -\n      exact I.disjoint_split_lower_split_upper i x)\n#align box_integral.prepartition.split BoxIntegral.Prepartition.split\n\n@[simp]\ntheorem mem_split_iff : J \u2208 split I i x \u2194 \u2191J = I.splitLower i x \u2228 \u2191J = I.splitUpper i x := by\n  simp [split]\n#align box_integral.prepartition.mem_split_iff BoxIntegral.Prepartition.mem_split_iff\n\ntheorem mem_split_iff' :\n    J \u2208 split I i x \u2194\n      (J : Set (\u03b9 \u2192 \u211d)) = I \u2229 { y | y i \u2264 x } \u2228 (J : Set (\u03b9 \u2192 \u211d)) = I \u2229 { y | x < y i } :=\n  by simp [mem_split_iff, \u2190 box.with_bot_coe_inj]\n#align box_integral.prepartition.mem_split_iff' BoxIntegral.Prepartition.mem_split_iff'\n\n@[simp]\ntheorem union_split (I : Box \u03b9) (i : \u03b9) (x : \u211d) : (split I i x).union\u1d62 = I := by\n  simp [split, \u2190 inter_union_distrib_left, \u2190 set_of_or, le_or_lt]\n#align box_integral.prepartition.Union_split BoxIntegral.Prepartition.union_split\n\ntheorem isPartitionSplit (I : Box \u03b9) (i : \u03b9) (x : \u211d) : IsPartition (split I i x) :=\n  isPartition_iff_union_eq.2 <| union_split I i x\n#align box_integral.prepartition.is_partition_split BoxIntegral.Prepartition.isPartitionSplit\n\ntheorem sum_split_boxes {M : Type _} [AddCommMonoid M] (I : Box \u03b9) (i : \u03b9) (x : \u211d) (f : Box \u03b9 \u2192 M) :\n    (\u2211 J in (split I i x).boxes, f J) = (I.splitLower i x).elim 0 f + (I.splitUpper i x).elim 0 f :=\n  by rw [split, sum_of_with_bot, Finset.sum_pair (I.split_lower_ne_split_upper i x)]\n#align box_integral.prepartition.sum_split_boxes BoxIntegral.Prepartition.sum_split_boxes\n\n/-- If `x \u2209 (I.lower i, I.upper i)`, then the hyperplane `{y | y i = x}` does not split `I`. -/\ntheorem split_of_not_mem_Ioo (h : x \u2209 Ioo (I.lower i) (I.upper i)) : split I i x = \u22a4 :=\n  by\n  refine' ((is_partition_top I).eq_of_boxes_subset fun J hJ => _).symm\n  rcases mem_top.1 hJ with rfl; clear hJ\n  rw [mem_boxes, mem_split_iff]\n  rw [mem_Ioo, not_and_or, not_lt, not_lt] at h\n  cases h <;> [right, left]\n  \u00b7 rwa [eq_comm, box.split_upper_eq_self]\n  \u00b7 rwa [eq_comm, box.split_lower_eq_self]\n#align box_integral.prepartition.split_of_not_mem_Ioo BoxIntegral.Prepartition.split_of_not_mem_Ioo\n\ntheorem coe_eq_of_mem_split_of_mem_le {y : \u03b9 \u2192 \u211d} (h\u2081 : J \u2208 split I i x) (h\u2082 : y \u2208 J)\n    (h\u2083 : y i \u2264 x) : (J : Set (\u03b9 \u2192 \u211d)) = I \u2229 { y | y i \u2264 x } :=\n  (mem_split_iff'.1 h\u2081).resolve_right fun H =>\n    by\n    rw [\u2190 box.mem_coe, H] at h\u2082\n    exact h\u2083.not_lt h\u2082.2\n#align box_integral.prepartition.coe_eq_of_mem_split_of_mem_le BoxIntegral.Prepartition.coe_eq_of_mem_split_of_mem_le\n\ntheorem coe_eq_of_mem_split_of_lt_mem {y : \u03b9 \u2192 \u211d} (h\u2081 : J \u2208 split I i x) (h\u2082 : y \u2208 J)\n    (h\u2083 : x < y i) : (J : Set (\u03b9 \u2192 \u211d)) = I \u2229 { y | x < y i } :=\n  (mem_split_iff'.1 h\u2081).resolve_left fun H =>\n    by\n    rw [\u2190 box.mem_coe, H] at h\u2082\n    exact h\u2083.not_le h\u2082.2\n#align box_integral.prepartition.coe_eq_of_mem_split_of_lt_mem BoxIntegral.Prepartition.coe_eq_of_mem_split_of_lt_mem\n\n@[simp]\ntheorem restrict_split (h : I \u2264 J) (i : \u03b9) (x : \u211d) : (split J i x).restrict I = split I i x :=\n  by\n  refine' ((is_partition_split J i x).restrict h).eq_of_boxes_subset _\n  simp only [Finset.subset_iff, mem_boxes, mem_restrict', exists_prop, mem_split_iff']\n  have : \u2200 s, (I \u2229 s : Set (\u03b9 \u2192 \u211d)) \u2286 J := fun s => (inter_subset_left _ _).trans h\n  rintro J\u2081 \u27e8J\u2082, H\u2082 | H\u2082, H\u2081\u27e9 <;> [left, right] <;> simp [H\u2081, H\u2082, inter_left_comm \u2191I, this]\n#align box_integral.prepartition.restrict_split BoxIntegral.Prepartition.restrict_split\n\ntheorem inf_split (\u03c0 : Prepartition I) (i : \u03b9) (x : \u211d) :\n    \u03c0 \u2293 split I i x = \u03c0.bunion\u1d62 fun J => split J i x :=\n  bUnion_congr_of_le rfl fun J hJ => restrict_split hJ i x\n#align box_integral.prepartition.inf_split BoxIntegral.Prepartition.inf_split\n\n/-- Split a box along many hyperplanes `{y | y i = x}`; each hyperplane is given by the pair\n`(i x)`. -/\ndef splitMany (I : Box \u03b9) (s : Finset (\u03b9 \u00d7 \u211d)) : Prepartition I :=\n  s.inf fun p => split I p.1 p.2\n#align box_integral.prepartition.split_many BoxIntegral.Prepartition.splitMany\n\n@[simp]\ntheorem splitMany_empty (I : Box \u03b9) : splitMany I \u2205 = \u22a4 :=\n  Finset.inf_empty\n#align box_integral.prepartition.split_many_empty BoxIntegral.Prepartition.splitMany_empty\n\n@[simp]\ntheorem splitMany_insert (I : Box \u03b9) (s : Finset (\u03b9 \u00d7 \u211d)) (p : \u03b9 \u00d7 \u211d) :\n    splitMany I (insert p s) = splitMany I s \u2293 split I p.1 p.2 := by\n  rw [split_many, Finset.inf_insert, inf_comm, split_many]\n#align box_integral.prepartition.split_many_insert BoxIntegral.Prepartition.splitMany_insert\n\ntheorem splitMany_le_split (I : Box \u03b9) {s : Finset (\u03b9 \u00d7 \u211d)} {p : \u03b9 \u00d7 \u211d} (hp : p \u2208 s) :\n    splitMany I s \u2264 split I p.1 p.2 :=\n  Finset.inf_le hp\n#align box_integral.prepartition.split_many_le_split BoxIntegral.Prepartition.splitMany_le_split\n\ntheorem isPartitionSplitMany (I : Box \u03b9) (s : Finset (\u03b9 \u00d7 \u211d)) : IsPartition (splitMany I s) :=\n  Finset.induction_on s (by simp only [split_many_empty, is_partition_top]) fun a s ha hs => by\n    simpa only [split_many_insert, inf_split] using hs.bUnion fun J hJ => is_partition_split _ _ _\n#align box_integral.prepartition.is_partition_split_many BoxIntegral.Prepartition.isPartitionSplitMany\n\n@[simp]\ntheorem union_splitMany (I : Box \u03b9) (s : Finset (\u03b9 \u00d7 \u211d)) : (splitMany I s).union\u1d62 = I :=\n  (isPartitionSplitMany I s).union\u1d62_eq\n#align box_integral.prepartition.Union_split_many BoxIntegral.Prepartition.union_splitMany\n\ntheorem inf_splitMany {I : Box \u03b9} (\u03c0 : Prepartition I) (s : Finset (\u03b9 \u00d7 \u211d)) :\n    \u03c0 \u2293 splitMany I s = \u03c0.bunion\u1d62 fun J => splitMany J s :=\n  by\n  induction' s using Finset.induction_on with p s hp ihp\n  \u00b7 simp\n  \u00b7 simp_rw [split_many_insert, \u2190 inf_assoc, ihp, inf_split, bUnion_assoc]\n#align box_integral.prepartition.inf_split_many BoxIntegral.Prepartition.inf_splitMany\n\n/-- Let `s : finset (\u03b9 \u00d7 \u211d)` be a set of hyperplanes `{x : \u03b9 \u2192 \u211d | x i = r}` in `\u03b9 \u2192 \u211d` encoded as\npairs `(i, r)`. Suppose that this set contains all faces of a box `J`. The hyperplanes of `s` split\na box `I` into subboxes. Let `Js` be one of them. If `J` and `Js` have nonempty intersection, then\n`Js` is a subbox of `J`.  -/\ntheorem not_disjoint_imp_le_of_subset_of_mem_splitMany {I J Js : Box \u03b9} {s : Finset (\u03b9 \u00d7 \u211d)}\n    (H : \u2200 i, {(i, J i), (i, J.upper i)} \u2286 s) (HJs : Js \u2208 splitMany I s)\n    (Hn : \u00acDisjoint (J : WithBot (Box \u03b9)) Js) : Js \u2264 J :=\n  by\n  simp only [Finset.insert_subset, Finset.singleton_subset_iff] at H\n  rcases box.not_disjoint_coe_iff_nonempty_inter.mp Hn with \u27e8x, hx, hxs\u27e9\n  refine' fun y hy i => \u27e8_, _\u27e9\n  \u00b7 rcases split_many_le_split I (H i).1 HJs with \u27e8Jl, Hmem : Jl \u2208 split I i (J.lower i), Hle\u27e9\n    have := Hle hxs\n    rw [\u2190 box.coe_subset_coe, coe_eq_of_mem_split_of_lt_mem Hmem this (hx i).1] at Hle\n    exact (Hle hy).2\n  \u00b7 rcases split_many_le_split I (H i).2 HJs with \u27e8Jl, Hmem : Jl \u2208 split I i (J.upper i), Hle\u27e9\n    have := Hle hxs\n    rw [\u2190 box.coe_subset_coe, coe_eq_of_mem_split_of_mem_le Hmem this (hx i).2] at Hle\n    exact (Hle hy).2\n#align box_integral.prepartition.not_disjoint_imp_le_of_subset_of_mem_split_many BoxIntegral.Prepartition.not_disjoint_imp_le_of_subset_of_mem_splitMany\n\nsection Fintype\n\nvariable [Finite \u03b9]\n\n/-- Let `s` be a finite set of boxes in `\u211d\u207f = \u03b9 \u2192 \u211d`. Then there exists a finite set `t\u2080` of\nhyperplanes (namely, the set of all hyperfaces of boxes in `s`) such that for any `t \u2287 t\u2080`\nand any box `I` in `\u211d\u207f` the following holds. The hyperplanes from `t` split `I` into subboxes.\nLet `J'` be one of them, and let `J` be one of the boxes in `s`. If these boxes have a nonempty\nintersection, then `J' \u2264 J`. -/\ntheorem eventually_not_disjoint_imp_le_of_mem_splitMany (s : Finset (Box \u03b9)) :\n    \u2200\u1da0 t : Finset (\u03b9 \u00d7 \u211d) in atTop,\n      \u2200 (I : Box \u03b9), \u2200 J \u2208 s, \u2200 J' \u2208 splitMany I t, \u00acDisjoint (J : WithBot (Box \u03b9)) J' \u2192 J' \u2264 J :=\n  by\n  cases nonempty_fintype \u03b9\n  refine'\n    eventually_at_top.2\n      \u27e8s.bUnion fun J => finset.univ.bUnion fun i => {(i, J i), (i, J.upper i)},\n        fun t ht I J hJ J' hJ' => not_disjoint_imp_le_of_subset_of_mem_split_many (fun i => _) hJ'\u27e9\n  exact fun p hp =>\n    ht (Finset.mem_bunion\u1d62.2 \u27e8J, hJ, Finset.mem_bunion\u1d62.2 \u27e8i, Finset.mem_univ _, hp\u27e9\u27e9)\n#align box_integral.prepartition.eventually_not_disjoint_imp_le_of_mem_split_many BoxIntegral.Prepartition.eventually_not_disjoint_imp_le_of_mem_splitMany\n\ntheorem eventually_splitMany_inf_eq_filter (\u03c0 : Prepartition I) :\n    \u2200\u1da0 t : Finset (\u03b9 \u00d7 \u211d) in atTop,\n      \u03c0 \u2293 splitMany I t = (splitMany I t).filter\u2093 fun J => \u2191J \u2286 \u03c0.union\u1d62 :=\n  by\n  refine' (eventually_not_disjoint_imp_le_of_mem_split_many \u03c0.boxes).mono fun t ht => _\n  refine' le_antisymm ((bUnion_le_iff _).2 fun J hJ => _) (le_inf (fun J hJ => _) (filter_le _ _))\n  \u00b7 refine' of_with_bot_mono _\n    simp only [Finset.mem_image, exists_prop, mem_boxes, mem_filter]\n    rintro _ \u27e8J\u2081, h\u2081, rfl\u27e9 hne\n    refine' \u27e8_, \u27e8J\u2081, \u27e8h\u2081, subset.trans _ (\u03c0.subset_Union hJ)\u27e9, rfl\u27e9, le_rfl\u27e9\n    exact ht I J hJ J\u2081 h\u2081 (mt disjoint_iff.1 hne)\n  \u00b7 rw [mem_filter] at hJ\n    rcases Set.mem_union\u1d62\u2082.1 (hJ.2 J.upper_mem) with \u27e8J', hJ', hmem\u27e9\n    refine' \u27e8J', hJ', ht I _ hJ' _ hJ.1 <| box.not_disjoint_coe_iff_nonempty_inter.2 _\u27e9\n    exact \u27e8J.upper, hmem, J.upper_mem\u27e9\n#align box_integral.prepartition.eventually_split_many_inf_eq_filter BoxIntegral.Prepartition.eventually_splitMany_inf_eq_filter\n\ntheorem exists_splitMany_inf_eq_filter_of_finite (s : Set (Prepartition I)) (hs : s.Finite) :\n    \u2203 t : Finset (\u03b9 \u00d7 \u211d),\n      \u2200 \u03c0 \u2208 s, \u03c0 \u2293 splitMany I t = (splitMany I t).filter\u2093 fun J => \u2191J \u2286 \u03c0.union\u1d62 :=\n  haveI := fun \u03c0 (h\u03c0 : \u03c0 \u2208 s) => eventually_split_many_inf_eq_filter \u03c0\n  (hs.eventually_all.2 this).exists\n#align box_integral.prepartition.exists_split_many_inf_eq_filter_of_finite BoxIntegral.Prepartition.exists_splitMany_inf_eq_filter_of_finite\n\n/-- If `\u03c0` is a partition of `I`, then there exists a finite set `s` of hyperplanes such that\n`split_many I s \u2264 \u03c0`. -/\ntheorem IsPartition.exists_splitMany_le {I : Box \u03b9} {\u03c0 : Prepartition I} (h : IsPartition \u03c0) :\n    \u2203 s, splitMany I s \u2264 \u03c0 :=\n  (eventually_splitMany_inf_eq_filter \u03c0).exists.imp fun s hs =>\n    by\n    rwa [h.Union_eq, filter_of_true, inf_eq_right] at hs\n    exact fun J hJ => le_of_mem _ hJ\n#align box_integral.prepartition.is_partition.exists_split_many_le BoxIntegral.Prepartition.IsPartition.exists_splitMany_le\n\n/-- For every prepartition `\u03c0` of `I` there exists a prepartition that covers exactly\n`I \\ \u03c0.Union`. -/\ntheorem exists_union_eq_diff (\u03c0 : Prepartition I) :\n    \u2203 \u03c0' : Prepartition I, \u03c0'.union\u1d62 = I \\ \u03c0.union\u1d62 :=\n  by\n  rcases \u03c0.eventually_split_many_inf_eq_filter.exists with \u27e8s, hs\u27e9\n  use (split_many I s).filter\u2093 fun J => \u00ac(J : Set (\u03b9 \u2192 \u211d)) \u2286 \u03c0.Union\n  simp [\u2190 hs]\n#align box_integral.prepartition.exists_Union_eq_diff BoxIntegral.Prepartition.exists_union_eq_diff\n\n/-- If `\u03c0` is a prepartition of `I`, then `\u03c0.compl` is a prepartition of `I`\nsuch that `\u03c0.compl.Union = I \\ \u03c0.Union`. -/\ndef compl (\u03c0 : Prepartition I) : Prepartition I :=\n  \u03c0.exists_union_eq_diff.some\n#align box_integral.prepartition.compl BoxIntegral.Prepartition.compl\n\n@[simp]\ntheorem union_compl (\u03c0 : Prepartition I) : \u03c0.compl.union\u1d62 = I \\ \u03c0.union\u1d62 :=\n  \u03c0.exists_union_eq_diff.choose_spec\n#align box_integral.prepartition.Union_compl BoxIntegral.Prepartition.union_compl\n\n/-- Since the definition of `box_integral.prepartition.compl` uses `Exists.some`,\nthe result depends only on `\u03c0.Union`. -/\ntheorem compl_congr {\u03c0\u2081 \u03c0\u2082 : Prepartition I} (h : \u03c0\u2081.union\u1d62 = \u03c0\u2082.union\u1d62) : \u03c0\u2081.compl = \u03c0\u2082.compl :=\n  by\n  dsimp only [compl]\n  congr 1\n  rw [h]\n#align box_integral.prepartition.compl_congr BoxIntegral.Prepartition.compl_congr\n\ntheorem IsPartition.compl_eq_bot {\u03c0 : Prepartition I} (h : IsPartition \u03c0) : \u03c0.compl = \u22a5 := by\n  rw [\u2190 Union_eq_empty, Union_compl, h.Union_eq, diff_self]\n#align box_integral.prepartition.is_partition.compl_eq_bot BoxIntegral.Prepartition.IsPartition.compl_eq_bot\n\n@[simp]\ntheorem compl_top : (\u22a4 : Prepartition I).compl = \u22a5 :=\n  (isPartitionTop I).compl_eq_bot\n#align box_integral.prepartition.compl_top BoxIntegral.Prepartition.compl_top\n\nend Fintype\n\nend Prepartition\n\nend BoxIntegral\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/BoxIntegral/Partition/Split.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7190606088524497}}
{"text": "/- Lecture 3.2: Program Semantics \u2014 Hoare Logic -/\n\n-- loads big-step semantics `(p, s) \u27f9 t` over `state` as state space\nimport .x32_library\n\nnamespace lecture\n\nopen program\n\nvariables\n  {c : state \u2192 Prop} {f : state \u2192 \u2115} {n : string}\n  {p p\u2080 p\u2081 p\u2082 : program} {s s\u2080 s\u2081 s\u2082 t u : state}\n  {P P' P\u2081 P\u2082 P\u2083 Q Q' : state \u2192 Prop}\n\n\n/- Hoare triples `{* P *} p {* Q *}` for partial correctness -/\n\ndef partial_hoare (P : state \u2192 Prop) (p : program) (Q : state \u2192 Prop) : Prop :=\n\u2200s t, P s \u2192 (p, s) \u27f9 t \u2192 Q t\n\nnotation `{* ` P : 1 ` *} ` p : 1 ` {* ` Q : 1 ` *}` := partial_hoare P p Q\n\n\n/- Introduction rules for Hoare triples -/\n\nnamespace partial_hoare\n\nlemma skip_intro :\n  {* P *} skip {* P *} :=\nbegin\n  intros s t hs hst,\n  cases hst,\n  assumption\nend\n\nlemma assign_intro (P : state \u2192 Prop) :\n  {* \u03bbs, P (s.update n (f s)) *} assign n f {* P *} :=\nbegin\n  intros s t P hst,\n  cases hst,\n  assumption\nend\n\nlemma seq_intro (h\u2081 : {* P\u2081 *} p\u2081 {* P\u2082 *}) (h\u2082 : {* P\u2082 *} p\u2082 {* P\u2083 *}) :\n  {* P\u2081 *} p\u2081 ;; p\u2082 {* P\u2083 *} :=\nbegin\n  intros s t P hst,\n  cases hst,\n  apply h\u2082 _ _ _ hst_h\u2082,\n  apply h\u2081 _ _ _ hst_h\u2081,\n  assumption\nend\n\nlemma ite_intro (h\u2081 : {* \u03bbs, P s \u2227 c s *} p\u2081 {* Q *}) (h\u2082 : {* \u03bbs, P s \u2227 \u00ac c s *} p\u2082 {* Q *}) :\n  {* P *} ite c p\u2081 p\u2082 {* Q *} :=\nbegin\n  intros s t hs hst,\n  cases hst,\n  { apply h\u2081 _ _ _ hst_h,\n    exact \u27e8hs, hst_hs\u27e9 },\n  { apply h\u2082 _ _ _ hst_h,\n    exact \u27e8hs, hst_hs\u27e9 },\nend\n\nlemma while_intro (P : state \u2192 Prop) (h\u2081 : {* \u03bbs, P s \u2227 c s *} p {* P *}) :\n  {* P *} while c p {* \u03bbs, P s \u2227 \u00ac c s *} :=\nbegin\n  intros s t hs,\n  generalize eq : (while c p, s) = ps,\n  intro hst,\n  induction hst generalizing s; cases eq,\n  { apply hst_ih_hw hst_t _ rfl,\n    exact h\u2081 _ _ \u27e8hs, hst_hs\u27e9 hst_hp },\n  { exact \u27e8hs, hst_hs\u27e9 }\nend\n\nlemma consequence (h : {* P *} p {* Q *}) (hp : \u2200s, P' s \u2192 P s) (hq : \u2200s, Q s \u2192 Q' s) :\n  {* P' *} p {* Q' *} :=\nassume s t hs hst, hq _ $ h s t (hp s hs) hst\n\nlemma consequence_left (P' : state \u2192 Prop) (h : {* P *} p {* Q *}) (hp : \u2200s, P' s \u2192 P s) :\n  {* P' *} p {* Q *} :=\nconsequence h hp (assume s hs, hs)\n\nlemma consequence_right (Q : state \u2192 Prop) (h : {* P *} p {* Q *}) (hq : \u2200s, Q s \u2192 Q' s) :\n  {* P *} p {* Q' *} :=\nconsequence h (assume s hs, hs) hq\n\n/- Many of the above rules are nonlinear (i.e. their conclusions contain repeated variables). This\nmakes them inconvenient to apply. We combine some of the previous rules with `consequence` to derive\nlinear rules. -/\n\nlemma skip_intro' (h : \u2200s, P s \u2192 Q s):\n  {* P *} skip {* Q *} :=\nconsequence skip_intro h (assume s hs, hs)\n\nlemma assign_intro' (h : \u2200s, P s \u2192 Q (s.update n (f s))):\n  {* P *} assign n f {* Q *} :=\nconsequence (assign_intro Q) h (assume s hs, hs)\n\nlemma seq_intro' (h\u2082 : {* P\u2082 *} p\u2082 {* P\u2083 *}) (h\u2081 : {* P\u2081 *} p\u2081 {* P\u2082 *}) :\n  {* P\u2081 *} p\u2081 ;; p\u2082 {* P\u2083 *} :=\nseq_intro h\u2081 h\u2082\n\nlemma while_intro_inv (I : state \u2192 Prop)\n  (h\u2081 : {* \u03bbs, I s \u2227 c s *} p {* I *}) (hp : \u2200s, P s \u2192 I s) (hq : \u2200s, \u00ac c s \u2192 I s \u2192 Q s) :\n  {* P *} while c p {* Q *} :=\nconsequence (while_intro I h\u2081) hp (assume s \u27e8hs, hnc\u27e9, hq s hnc hs)\n\nend partial_hoare\n\n\n/- Example: `SWAP`\n\nExchanges the values of variables `a` and `b`. -/\n\nsection SWAP\n\nopen partial_hoare\n\ndef SWAP : program :=\nassign \"t\" (\u03bbs, s \"a\") ;;\nassign \"a\" (\u03bbs, s \"b\") ;;\nassign \"b\" (\u03bbs, s \"t\")\n\nlemma SWAP_correct (x y : \u2115) :\n  {* \u03bbs, s \"a\" = x \u2227 s \"b\" = y *} SWAP {* \u03bbs, s \"a\" = y \u2227 s \"b\" = x *} :=\nbegin\n  apply seq_intro',\n  apply seq_intro',\n  apply assign_intro,\n  apply assign_intro,\n  apply assign_intro',\n  /- The remaining goal looks horrible. But `simp` can simplify it dramatically, and with contextual\n  rewriting (i.e. using assumptions in the goal as rewrite rules), it can solve it. -/\n  simp {contextual := tt},\nend\n\nend SWAP\n\n\n/- Example: `ADD`\n\nComputes `m + n`, leaving the result in `n`, using only these primitive operations: `n + 1`,\n`n - 1`, and `n \u2260 0`. -/\n\nsection ADD\n\nopen partial_hoare\n\ndef ADD : program :=\nwhile (\u03bbs, s \"n\" \u2260 0)\n( assign \"n\" (\u03bbs, s \"n\" - 1) ;;\n  assign \"m\" (\u03bbs, s \"m\" + 1) )\n\nlemma ADD_correct (n m : \u2115) :\n  {* \u03bbs, s \"n\" = n \u2227 s \"m\" = m *} ADD {* \u03bbs, s \"m\" = n + m *} :=\nbegin\n  -- `refine` is like `exact`, but it lets us specify holes to be filled later\n  refine while_intro_inv (\u03bbs, s \"n\" + s \"m\" = n + m) _ _ _,\n  apply seq_intro',\n  apply assign_intro,\n  apply assign_intro',\n  { simp,\n    -- puhh this looks much better: `simp` removed all `update`s\n    intros s hnm hn0,\n    rw \u2190hnm,\n    -- subtracting on `\u2115` is annoying\n    cases s \"n\",\n    { contradiction },\n    { simp [nat.succ_eq_add_one] } },\n  { simp {contextual := tt} },\n  { simp [not_not_iff] {contextual := tt} }\nend\n\nend ADD\n\n\n/- Annotated while loop -/\n\ndef program.while_inv (I : state \u2192 Prop) (c : state \u2192 Prop) (p : program) : program :=\nwhile c p\n\nopen program -- makes `program.while_inv` available as `while_inv`\n\nnamespace partial_hoare\n\n/- `while_inv` rules use the invariant annotation -/\n\nlemma while_inv_intro {I : state \u2192 Prop}\n  (h\u2081 : {* \u03bbs, I s \u2227 c s *} p {* I *}) (hq : \u2200s, \u00ac c s \u2192 I s \u2192 Q s) :\n  {* I *} while_inv I c p {* Q *} :=\nwhile_intro_inv I h\u2081 (assume s hs, hs) hq\n\nlemma while_inv_intro' {I : state \u2192 Prop}\n  (h\u2081 : {* \u03bbs, I s \u2227 c s *} p {* I *}) (hp : \u2200s, P s \u2192 I s) (hq : \u2200s, \u00ac c s \u2192 I s \u2192 Q s) :\n  {* P *} while_inv I c p {* Q *} :=\nwhile_intro_inv I h\u2081 hp hq\n\nend partial_hoare\n\nend lecture\n\nnamespace tactic.interactive\n\nopen lecture.partial_hoare lecture tactic\n\nmeta def is_meta {elab : bool} : expr elab \u2192 bool\n| (expr.mvar _ _ _) := tt\n| _                 := ff\n\n\n/- Verification condition generator -/\n\nmeta def vcg : tactic unit := do\n  t \u2190 target,\n  match t with\n  | `({* %%P *} %%p {* _ *}) :=\n    match p with\n    | `(program.skip)            := applyc (if is_meta P then ``skip_intro else ``skip_intro')\n    | `(program.assign _ _)      := applyc (if is_meta P then ``assign_intro else ``assign_intro')\n    | `(program.ite _ _ _)       := do applyc ``ite_intro; vcg\n    | `(program.seq _ _)         := do applyc ``seq_intro'; vcg\n    | `(program.while_inv _ _ _) :=\n      do applyc (if is_meta P then ``while_inv_intro else ``while_inv_intro'); vcg\n    | _                          := fail (to_fmt \"cannot analyze \" ++ to_fmt p)\n    end\n  | _ := skip  -- do nothing if the goal is not a Hoare triple\n  end\n\nend tactic.interactive\n\nnamespace lecture\n\nopen program\n\nexample (n m : \u2115) :\n  {* \u03bbs, s \"n\" = n \u2227 s \"m\" = m *} ADD {* \u03bbs, s \"n\" = 0 \u2227 s \"m\" = n + m *} :=\nbegin\n  -- use `show` to annotate the while loop with an invariant\n  show {* \u03bbs, s \"n\" = n \u2227 s \"m\" = m *}\n      while_inv (\u03bbs, s \"n\" + s \"m\" = n + m) (\u03bbs, s \"n\" \u2260 0)\n      ( assign \"n\" (\u03bbs, s \"n\" - 1) ;;\n        assign \"m\" (\u03bbs, s \"m\" + 1) )\n    {* \u03bbs, s \"n\" = 0 \u2227 s \"m\" = n + m *},\n  vcg;\n    simp {contextual := tt},\n  intros s hnm hn,\n  rw \u2190hnm,\n  cases s \"n\",\n  { contradiction },\n  { simp [nat.succ_eq_add_one] }\nend\n\nend lecture\n", "meta": {"author": "KjellZijlemaker", "repo": "Logical_Verification_VU", "sha": "4578b93bf1615466996157bb333c84122b201d99", "save_path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU", "path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU/Logical_Verification_VU-4578b93bf1615466996157bb333c84122b201d99/Exercises 9/32_lecture.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7190606073065242}}
{"text": "/-\nCopyright (c) 2021 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport topology.separation\n\n/-!\n# Idempotents in topological semigroups\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides a sufficient condition for a semigroup `M` to contain an idempotent (i.e. an\nelement `m` such that `m * m = m `), namely that `M` is a nonempty compact Hausdorff space where\nright-multiplication by constants is continuous.\n\nWe also state a corresponding lemma guaranteeing that a subset of `M` contains an idempotent.\n-/\n\n/-- Any nonempty compact Hausdorff semigroup where right-multiplication is continuous contains\nan idempotent, i.e. an `m` such that `m * m = m`. -/\n@[to_additive \"Any nonempty compact Hausdorff additive semigroup where right-addition is continuous\ncontains an idempotent, i.e. an `m` such that `m + m = m`\"]\nlemma exists_idempotent_of_compact_t2_of_continuous_mul_left {M} [nonempty M] [semigroup M]\n  [topological_space M] [compact_space M] [t2_space M]\n  (continuous_mul_left : \u2200 r : M, continuous (* r)) : \u2203 m : M, m * m = m :=\nbegin\n/- We apply Zorn's lemma to the poset of nonempty closed subsemigroups of `M`. It will turn out that\nany minimal element is `{m}` for an idempotent `m : M`. -/\n  let S : set (set M) := {N | is_closed N \u2227 N.nonempty \u2227 \u2200 m m' \u2208 N, m * m' \u2208 N},\n  rsuffices \u27e8N, \u27e8N_closed, \u27e8m, hm\u27e9, N_mul\u27e9, N_minimal\u27e9 : \u2203 N \u2208 S, \u2200 N' \u2208 S, N' \u2286 N \u2192 N' = N,\n  { use m,\n/- We now have an element `m : M` of a minimal subsemigroup `N`, and want to show `m + m = m`.\nWe first show that every element of `N` is of the form `m' + m`.-/\n    have scaling_eq_self : (* m) '' N = N,\n    { apply N_minimal,\n      { refine \u27e8(continuous_mul_left m).is_closed_map _ N_closed, \u27e8_, \u27e8m, hm, rfl\u27e9\u27e9, _\u27e9,\n        rintros _ \u27e8m'', hm'', rfl\u27e9 _ \u27e8m', hm', rfl\u27e9,\n        refine \u27e8m'' * m * m', N_mul _ (N_mul _ hm'' _ hm) _ hm', mul_assoc _ _ _\u27e9 },\n      { rintros _ \u27e8m', hm', rfl\u27e9,\n        exact N_mul _ hm' _ hm } },\n/- In particular, this means that `m' * m = m` for some `m'`. We now use minimality again to show\nthat this holds for all `m' \u2208 N`. -/\n    have absorbing_eq_self : N \u2229 {m' | m' * m = m} = N,\n    { apply N_minimal,\n      { refine \u27e8N_closed.inter ((t1_space.t1 m).preimage (continuous_mul_left m)), _, _\u27e9,\n        { rwa \u2190scaling_eq_self at hm },\n        { rintros m'' \u27e8mem'', eq'' : _ = m\u27e9 m' \u27e8mem', eq' : _ = m\u27e9,\n          refine \u27e8N_mul _ mem'' _ mem', _\u27e9,\n          rw [set.mem_set_of_eq, mul_assoc, eq', eq''] } },\n      apply set.inter_subset_left },\n/- Thus `m * m = m` as desired. -/\n    rw \u2190absorbing_eq_self at hm,\n    exact hm.2 },\n  refine zorn_superset _ (\u03bb c hcs hc, _),\n  refine \u27e8\u22c2\u2080 c, \u27e8is_closed_sInter $ \u03bb t ht, (hcs ht).1, _, \u03bb m hm m' hm', _\u27e9,\n    \u03bb s hs, set.sInter_subset_of_mem hs\u27e9,\n  { obtain rfl | hcnemp := c.eq_empty_or_nonempty,\n    { rw set.sInter_empty, apply set.univ_nonempty },\n    convert @is_compact.nonempty_Inter_of_directed_nonempty_compact_closed _ _ _ hcnemp.coe_sort\n      (coe : c \u2192 set M) _ _ _ _,\n    { simp only [subtype.range_coe_subtype, set.set_of_mem_eq] } ,\n    { refine directed_on.directed_coe (is_chain.directed_on hc.symm) },\n    exacts [\u03bb i, (hcs i.prop).2.1, \u03bb i, (hcs i.prop).1.is_compact, \u03bb i, (hcs i.prop).1] },\n  { rw set.mem_sInter,\n    exact \u03bb t ht, (hcs ht).2.2 m (set.mem_sInter.mp hm t ht) m' (set.mem_sInter.mp hm' t ht) },\nend\n\n/-- A version of `exists_idempotent_of_compact_t2_of_continuous_mul_left` where the idempotent lies\nin some specified nonempty compact subsemigroup. -/\n@[to_additive exists_idempotent_in_compact_add_subsemigroup \"A version of\n`exists_idempotent_of_compact_t2_of_continuous_add_left` where the idempotent lies in some specified\nnonempty compact additive subsemigroup.\"]\nlemma exists_idempotent_in_compact_subsemigroup {M} [semigroup M] [topological_space M] [t2_space M]\n  (continuous_mul_left : \u2200 r : M, continuous (* r))\n  (s : set M) (snemp : s.nonempty) (s_compact : is_compact s) (s_add : \u2200 x y \u2208 s, x * y \u2208 s) :\n  \u2203 m \u2208 s, m * m = m :=\nbegin\n  let M' := {m // m \u2208 s},\n  letI : semigroup M' :=\n    { mul       := \u03bb p q, \u27e8p.1 * q.1, s_add _ p.2 _ q.2\u27e9,\n      mul_assoc := \u03bb p q r, subtype.eq (mul_assoc _ _ _) },\n  haveI : compact_space M' := is_compact_iff_compact_space.mp s_compact,\n  haveI : nonempty M' := nonempty_subtype.mpr snemp,\n  have : \u2200 p : M', continuous (* p) := \u03bb p,\n    ((continuous_mul_left p.1).comp continuous_subtype_val).subtype_mk _,\n  obtain \u27e8\u27e8m, hm\u27e9, idem\u27e9 := exists_idempotent_of_compact_t2_of_continuous_mul_left this,\n  exact \u27e8m, hm, subtype.ext_iff.mp idem\u27e9\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/semigroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7190606040181114}}
{"text": "open function\n/- this question should read Q4 (but on the 2016/17 example sheet, this reads 3)\n4. (One-sided inverses.)\n(i) Say f : X \u2192 Y is a function and there exists a function g : Y \u2192 X such that f \u25e6 g is the identity function Y \u2192 Y . Prove that f is surjective.\n(ii) Say f : X \u2192 Y is a function and there exists a function g : Y \u2192 X such that g \u25e6 f is the identity function X \u2192 X. Prove that f is injective.\n-/\nvariables {X: Type*} {Y : Type*} {f : X \u2192 Y} {g : Y \u2192 X} \n\n#check id_of_right_inverse\ntheorem Q1004i : f \u2218 g = id \u2192 surjective f := \nbegin\nintros,\napply surjective_of_has_right_inverse,\nunfold has_right_inverse,\nsorry\nend\n\ntheorem Q1004ii : g \u2218 f = id \u2192 injective f := \nbegin \nintros,\napply injective_of_has_left_inverse,\nsorry\nend", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/problem_bank/PB1004/Q1004.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7190493241352403}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Gabriel Ebner\n-/\nimport data.int.cast.defs\nimport algebra.group.basic\n\n/-!\n# Cast of integers (additional theorems)\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves additional properties about the *canonical* homomorphism from\nthe integers into an additive group with a one (`int.cast`).\n\nThere is also `data.int.cast.lemmas`,\nwhich includes lemmas stated in terms of algebraic homomorphisms,\nand results involving the order structure of `\u2124`.\n\nBy contrast, this file's only import beyond `data.int.cast.defs` is `algebra.group.basic`.\n-/\n\nuniverses u\n\nnamespace nat\nvariables {R : Type u} [add_group_with_one R]\n\n@[simp, norm_cast] theorem cast_sub {m n} (h : m \u2264 n) : ((n - m : \u2115) : R) = n - m :=\neq_sub_of_add_eq $ by rw [\u2190 cast_add, nat.sub_add_cancel h]\n\n@[simp, norm_cast] \n\nend nat\n\nopen nat\n\nnamespace int\nvariables {R : Type u} [add_group_with_one R]\n\n@[simp] theorem cast_neg_succ_of_nat (n : \u2115) : (-[1+ n] : R) = -(n + 1 : \u2115) :=\nadd_group_with_one.int_cast_neg_succ_of_nat n\n\n@[simp, norm_cast] theorem cast_zero : ((0 : \u2124) : R) = 0 := (cast_of_nat 0).trans nat.cast_zero\n\n@[simp, norm_cast] theorem cast_coe_nat (n : \u2115) : ((n : \u2124) : R) = n := cast_of_nat _\n\n@[simp, norm_cast] theorem cast_one : ((1 : \u2124) : R) = 1 :=\nshow (((1 : \u2115) : \u2124) : R) = 1, by simp\n\n@[simp, norm_cast] theorem cast_neg : \u2200 n, ((-n : \u2124) : R) = -n\n| (0 : \u2115) := by erw [cast_zero, neg_zero]\n| (n + 1 : \u2115) := by erw [cast_of_nat, cast_neg_succ_of_nat]; refl\n| -[1+ n] := by erw [cast_of_nat, cast_neg_succ_of_nat, neg_neg]\n\n@[simp] theorem cast_sub_nat_nat (m n) :\n  ((int.sub_nat_nat m n : \u2124) : R) = m - n :=\nbegin\n  unfold sub_nat_nat, cases e : n - m,\n  { simp only [sub_nat_nat, cast_of_nat], simp [e, nat.le_of_sub_eq_zero e] },\n  { rw [sub_nat_nat, cast_neg_succ_of_nat, nat.add_one, \u2190 e,\n        nat.cast_sub $ _root_.le_of_lt $ nat.lt_of_sub_eq_succ e, neg_sub] },\nend\n\nlemma neg_of_nat_eq (n : \u2115) : neg_of_nat n = -(n : \u2124) := by cases n; refl\n\n@[simp] theorem cast_neg_of_nat (n : \u2115) : ((neg_of_nat n : \u2124) : R) = -n :=\nby simp [neg_of_nat_eq]\n\n@[simp, norm_cast] theorem cast_add : \u2200 m n, ((m + n : \u2124) : R) = m + n\n| (m : \u2115) (n : \u2115) := by simp [\u2190 int.coe_nat_add]\n| (m : \u2115) -[1+ n] := by erw [cast_sub_nat_nat, cast_coe_nat, cast_neg_succ_of_nat, sub_eq_add_neg]\n| -[1+ m] (n : \u2115) := by erw [cast_sub_nat_nat, cast_coe_nat, cast_neg_succ_of_nat,\n  sub_eq_iff_eq_add, add_assoc, eq_neg_add_iff_add_eq, \u2190 nat.cast_add, \u2190 nat.cast_add, nat.add_comm]\n| -[1+ m] -[1+ n] := show (-[1+ m + n + 1] : R) = _,\n  by rw [cast_neg_succ_of_nat, cast_neg_succ_of_nat, cast_neg_succ_of_nat, \u2190 neg_add_rev,\n    \u2190 nat.cast_add, nat.add_right_comm m n 1, nat.add_assoc, nat.add_comm]\n\n@[simp, norm_cast] theorem cast_sub (m n) : ((m - n : \u2124) : R) = m - n :=\nby simp [int.sub_eq_add_neg, sub_eq_add_neg]\n\n@[simp, norm_cast]\ntheorem coe_nat_bit0 (n : \u2115) : (\u2191(bit0 n) : \u2124) = bit0 \u2191n := rfl\n\n@[simp, norm_cast]\ntheorem coe_nat_bit1 (n : \u2115) : (\u2191(bit1 n) : \u2124) = bit1 \u2191n := rfl\n\n@[simp, norm_cast] theorem cast_bit0 (n : \u2124) : ((bit0 n : \u2124) : R) = bit0 n :=\ncast_add _ _\n\n@[simp, norm_cast] theorem cast_bit1 (n : \u2124) : ((bit1 n : \u2124) : R) = bit1 n :=\nby rw [bit1, cast_add, cast_one, cast_bit0]; refl\n\nlemma cast_two : ((2 : \u2124) : R) = 2 := by simp\n\nlemma cast_three : ((3 : \u2124) : R) = 3 := by simp\n\nlemma cast_four : ((4 : \u2124) : R) = 4 := by simp\n\nend int\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/cast/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7190493045875368}}
{"text": "import Basics.TypeDefinitions\n/-!\n## Function Definitions\n\nIf all we want is to declare a function, we can use the `def` command.\nGoing back to the arithmetic expression example from [Typoe Definitions](./TypeDefinitions.lean.md), if we wanted to\nimplement an eval function in Java, we would probably add it as part of AExp\u2019s\ninterface and implement it in each subclass. For Add, Sub, Mul, and Div, we would\nrecursively call eval on the left and right objects.\n\nIn Lean, the syntax is very compact. We define a single function and use pattern\nmatching to distinguish the six cases:\n-/\ndef eval (env: String \u2192 Int) : aexp \u2192 Int\n| (aexp.num i) => i\n| (aexp.var x) => env x\n| (aexp.add e\u2081 e\u2082) => eval env e\u2081 + eval env e\u2082\n| (aexp.sub e\u2081 e\u2082) => eval env e\u2081 - eval env e\u2082\n| (aexp.mul e\u2081 e\u2082) => eval env e\u2081 * eval env e\u2082\n| (aexp.div e\u2081 e\u2082) => eval env e\u2081 / eval env e\u2082\n\n/-!\nThe keyword `def` introduces the definition. The general format of definitions by\npattern matching is:\n\n```lean\ndef name (params\u2081 : type\u2081) . . . (params\u2098 : type\u2098) : type\n| patterns\u2081 := result\u2081\n.\n.\n.\n| patterns\u2099 := result\u2099\n```\n\nThe parentheses ( ) around the parameters can also be curly braces { } if we want\nto make them implicit arguments. The parameters cannot be subjected to pattern\nmatching, only the remaining arguments (e.g., the `aexp` argument of `eval`).\n\nPatterns may contain variables, which are then visible in the corresponding\nright-hand side, as well as constructors. For example, in the second case in eval\u2019s\ndefinition, the variable `x` can be used in the right-hand side `env x`.\n\nSome definitions do not need pattern matching. For these, the syntax is simply\n\n```lean\ndef name (params\u2081 : type\u2081) . . . (params\u2098 : type\u2098) : type :=\n  result\n```\n\nWe can have pattern matching without recursion (e.g., in the `aexp.num` and `aexp.var` cases above),\nand we can have recursion without pattern matching.\n\nThe basic arithmetic operations on natural numbers, such as addition, can be\ndefined by recursion:\n\n-/\ndef add : Nat \u2192 Nat \u2192 Nat\n| m, Nat.zero => m\n| m, (Nat.succ n) => Nat.succ (add m n)\n/-!\nWe pattern-match on two arguments at the same time, distinguishing the case where the second\nargument is zero and the case where it is nonzero. Each recursive call to add peels off one `Nat.succ`\nconstructor from the second argument. Instead of `Nat.zero` and `Nat.succ n`, Lean also allows us to\nwrite `0` and `n + 1` as syntactic sugar.\n\n-/\ndef add\u2082 : Nat \u2192 Nat \u2192 Nat\n| m, 0 => m\n| m, (n + 1) => (m + n) + 1\n/-!\nWe can evaluate the result of applying add to numbers using `#eval` or `#reduce`:\n-/\n#eval add 2 7\n#reduce add 2 7\n\n/-!\nBoth commands print 9, as expected. `#eval` employs an optimized interpreter,\nwhereas `#reduce` uses Lean\u2019s inference kernel, which is less effcient.\n\nPerhaps you are worried about division by zero in the definition of eval above.\nLet us see what `#eval` has to say about it:\n\n-/\n#eval eval (\u03bb x => 7) (aexp.div (aexp.var \"x\") (aexp.num 0))\n/-!\nThe output is 0. In Lean, division is conveniently defined as a total function that\nreturns zero when the denominator is zero. For a lucid explanation of why this is\nnot dangerous, see [Buzzard\u2019s blog](https://xenaproject.wordpress.com/2020/07/05/division-by-zero-in-type-theory-a-faq/).\n\nIt is good practice to provide a few tests each time we define a function, to\nensure that it behaves as expected. You can even leave the `#eval` or `#reduce`\ncalls in your Lean files as documentation.\n\nThe definition of multiplication is similar to that of addition and we can reuse our\n`add` function here:\n-/\ndef mul : Nat \u2192 Nat \u2192 Nat\n| _, Nat.zero => Nat.zero\n| m, (Nat.succ n) => add m (mul m n)\n\n/-!\nThe underscore (`_`) stands for an unused variable. We could have put a name (e.g., `m`),\nbut `_` documents our intentions better.\n\nThe #eval command below prints 14, as expected:\n-/\n#eval mul 2 7\n/-!\nThe power operation (\u201c_m_ to the power of _n_\u201d) can be defined in various ways.\nOur first proposal is structurally identical to the definition of multiplication:\n-/\ndef power : Nat \u2192 Nat \u2192 Nat\n| _, Nat.zero => 1\n| m, (Nat.succ n) => mul m (power m n)\n/-!\nSince the first argument, `m`, remains unchanged in the recursive call, `power m n`, we\ncan factor it out and put it next to the function\u2019s name, as a parameter, before the\ncolon introducing the type of the function (excluding the parameter `m`):\n-/\ndef power\u2082 (m : Nat) : Nat \u2192 Nat\n| Nat.zero => 1\n| (Nat.succ n) => mul m (power\u2082 m n)\n\n#eval power\u2082 2 7    -- 128\n/-!\nYet another definition is possible by first introducing a general-purpose iterator\nthat applies a function recursively over the Nat values:\n-/\ndef iter (z : \u03b1) (f : \u03b1 \u2192 \u03b1) : Nat \u2192 \u03b1\n| Nat.zero => z\n| (Nat.succ n) => f (iter z f n)\n\ndef power\u2083 (m n : Nat) : Nat :=\n  iter 1 (\u03bb l => m * l) n\n\n#eval power\u2083 2 7    -- 128\n\n/-!\nNotice that the `power\u2083` is not recursive since the recursion is done by `iter`.\n\nRecursive functions on lists can be defined in a similar way:\n-/\ndef append (\u03b1 : Type): List \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n| xs, List.nil => xs\n| List.nil, ys => ys\n| (List.cons x xs), ys => List.cons x (append _ xs ys)\n\n#check append\n#eval append _ [3, 1] [4, 1, 5]   -- [3, 1, 4, 1, 5]\n/-!\nThis append function takes three arguments: a type `\u03b1` and two lists of type `List \u03b1`\nand it produces a resulting list of type `List \u03b1`.\nBy passing the placeholder `_`, we leave it to Lean to infer the type \u03b1 from the type\nof the other two arguments.\n\nTo make the type argument \u03b1 implicit, we can put it in curly braces `{ }`\n-/\ndef append\u2082 {\u03b1 : Type} : List \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n| xs, List.nil => xs\n| List.nil, ys => ys\n| (List.cons x xs), ys => List.cons x (append\u2082 xs ys)\n\n#check append\u2082\n#eval append\u2082 [3, 1] [4, 1, 5]    -- [3, 1, 4, 1, 5]\n/-!\nThe at sign (`@`) can be used to make the implicit arguments explicit.\nThis is useful for debugging and occasionally necessary to guide Lean\u2019s parser:\n-/\n#check @append\u2082\n#eval @append\u2082 _ [3, 1] [4, 1, 5]\n/-!\nWe can use syntactic sugar in the definition, both in the patterns on the left-hand sides of `=>` and in the right-hand sides:\n-/\ndef append\u2083 {\u03b1 : Type} : List \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n| [], ys => ys\n| (x :: xs), ys => x :: append\u2083 xs ys\n\n#eval append\u2083 [3, 1] [4, 1, 5]    -- [3, 1, 4, 1, 5]\n/-!\nIn Lean\u2019s standard library, the append function has an infix operator called `++`.\nWe can use it to define a function that reverses a list:\n-/\ndef reverse {\u03b1 : Type} : List \u03b1 \u2192 List \u03b1\n| [] => []\n| (x :: xs) => reverse xs ++ [x]\n\n#eval reverse [1,2,3]   -- [3, 2, 1]\n", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/Basics/FunctionDefinitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7189588121539688}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n\n! This file was ported from Lean 3 source module data.nat.upto\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Order.Basic\n\n/-!\n# `nat.upto`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n`nat.upto p`, with `p` a predicate on `\u2115`, is a subtype of elements `n : \u2115` such that no value\n(strictly) below `n` satisfies `p`.\n\nThis type has the property that `>` is well-founded when `\u2203 i, p i`, which allows us to implement\nsearches on `\u2115`, starting at `0` and with an unknown upper-bound.\n\nIt is similar to the well founded relation constructed to define `nat.find` with\nthe difference that, in `nat.upto p`, `p` does not need to be decidable. In fact,\n`nat.find` could be slightly altered to factor decidability out of its\nwell founded relation and would then fulfill the same purpose as this file.\n-/\n\n\nnamespace Nat\n\n#print Nat.Upto /-\n/-- The subtype of natural numbers `i` which have the property that\nno `j` less than `i` satisfies `p`. This is an initial segment of the\nnatural numbers, up to and including the first value satisfying `p`.\n\nWe will be particularly interested in the case where there exists a value\nsatisfying `p`, because in this case the `>` relation is well-founded.  -/\n@[reducible]\ndef Upto (p : \u2115 \u2192 Prop) : Type :=\n  { i : \u2115 // \u2200 j < i, \u00acp j }\n#align nat.upto Nat.Upto\n-/\n\nnamespace Upto\n\nvariable {p : \u2115 \u2192 Prop}\n\n#print Nat.Upto.GT /-\n/-- Lift the \"greater than\" relation on natural numbers to `nat.upto`. -/\nprotected def GT (p) (x y : Upto p) : Prop :=\n  x.1 > y.1\n#align nat.upto.gt Nat.Upto.GT\n-/\n\ninstance : LT (Upto p) :=\n  \u27e8fun x y => x.1 < y.1\u27e9\n\n#print Nat.Upto.wf /-\n/-- The \"greater than\" relation on `upto p` is well founded if (and only if) there exists a value\nsatisfying `p`. -/\nprotected theorem wf : (\u2203 x, p x) \u2192 WellFounded (Upto.GT p)\n  | \u27e8x, h\u27e9 =>\n    by\n    suffices upto.gt p = Measure fun y : Nat.Upto p => x - y.val\n      by\n      rw [this]\n      apply measure_wf\n    ext (\u27e8a, ha\u27e9\u27e8b, _\u27e9)\n    dsimp [Measure, InvImage, upto.gt]\n    rw [tsub_lt_tsub_iff_left_of_le]\n    exact le_of_not_lt fun h' => ha _ h' h\n#align nat.upto.wf Nat.Upto.wf\n-/\n\n#print Nat.Upto.zero /-\n/-- Zero is always a member of `nat.upto p` because it has no predecessors. -/\ndef zero : Nat.Upto p :=\n  \u27e80, fun j h => False.elim (Nat.not_lt_zero _ h)\u27e9\n#align nat.upto.zero Nat.Upto.zero\n-/\n\n#print Nat.Upto.succ /-\n/-- The successor of `n` is in `nat.upto p` provided that `n` doesn't satisfy `p`. -/\ndef succ (x : Nat.Upto p) (h : \u00acp x.val) : Nat.Upto p :=\n  \u27e8x.val.succ, fun j h' => by\n    rcases Nat.lt_succ_iff_lt_or_eq.1 h' with (h' | rfl) <;> [exact x.2 _ h', exact h]\u27e9\n#align nat.upto.succ Nat.Upto.succ\n-/\n\nend Upto\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Upto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7189587970160278}}
{"text": "import data.real.basic\n-- we need to know that the reals are a thing.\n\n\n/- Let us define some bits about the complex numbers! We shall also use this as an \n    oppourtunity to understand what happens when we define a new 'set' of numbers in Lean.\n    To define a new set of numbers we need to do some things, these things may be seen as very\n    simple or even obvious to us, but we have to remember that Lean doesn't understand anything\n    we don't tell it. At the moment it knows nothing about Complex Numbers, it only knows things\n    about the reals. -/\n\n\n/- Firstly we start with what we call a `structure`, this is a way to denote how the number \n    shall be written. We let the structure be a type, meaning it is a 'set', by writing:\n    `structure complex : Type`. Then we tell Lean how we want the structure of our thing to \n    look, in this case we want two real numbers. So we write: `(re: \u211d) (im: \u211d)`, which says as\n    we said above, two reals. We call the first `re`, our real part and second, `im`, our \n    imaginary part. This corresponds with how we write complex numbers in a more normal way: \n    `a + bi`   \n\n    NB! To write \u211d in lean, just use \\R and press your space bar\n-/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\n/- As Lean knows nothing about the complex numbers, we have to tell it how to denote the set,\n    So here we are telling Lean that we notate the set of complexes with \u2102, please carefully \n    note that there are backticks around the \u2102, I spent too long trying to work out why my \n    notation code wasn't working when I first started Lean. We shall also note that `:=` means\n    is defined as. \n-/\nnotation `\u2102` := complex\n\n/- Let us take an example of a complex number, `3 + 4i`, we can write this rather easily in\n    a multide of ways.\n-/\nexample : \u2102 :=\n{ re := 3,\n  im := 4 }\n\n-- Or like this:\nexample : \u2102 := complex.mk 3 4\n\n-- or like this:\nexample : \u2102 := \u27e83, 4\u27e9\n\n-- They all give the same complex number.\n\nnamespace complex -- This tells us that what we are doing from here on in is in is about the\n                  -- complexes.\n\n\n/-! # Zero -/\n\n/- Now we need to define what a zero is in this new and rather strange number system, this\n    may look a bit odd at first, but I shall talk / walk you through whats going on here -/\n\n-- This says, let us define a zero in the complexes and we define it as the diple `\u27e80, 0\u27e9`, \n-- or if you prefer, `complex.mk 0 0`. \ndef zero : \u2102 := \u27e80, 0\u27e9\n\n-- Now we set up notation so that `0 : \u2102` will mean `zero`. \n\n/- This does something very similar to before and instead of using the command `notation`, \n    we define a zero using `has_zero`, which is a typeclass. Basically what this does is it \n    allows us to use the `(0 : \u2102)`, which says `0` is a complex.  -/\ninstance : has_zero \u2102 := \u27e8zero\u27e9\n\n/- If I give you the famed `(0 : \u2102)` from the line above, now I ask you to prove that \n    following, that the real part of `0` is zero and the complex part of `0` is zero. Obviously\n    these are true by definition, or reflexivly true. So we can write `rfl` as the proof, the\n    shortened term mode brother of refl. -/\n\n@[simp] lemma zero_re : re(0 : \u2102) = 0 := rfl\n@[simp] lemma zero_im : im(0 : \u2102) = 0 := rfl\n\n/- Now for a few exercises or even examples: -/\n\n--C01\nexample : re( \u27e81, 2\u27e9 ) = 1 := \nbegin\n  sorry\nend\n\n--C02\nexample (a b : \u211d) : im( \u27e8a + b, b\u27e9 ) = b :=\nbegin\n  sorry\nend\n\n--*C03\n/-- For the following example, you will need to `rw` instead the `refl` that you need is \n    `add_comm`. Note that Lean does a refl after every `rw` -/\nexample (a b : \u211d) : re( \u27e8a + b, b\u27e9 ) = b + a :=\nbegin\n  sorry\nend\n\n/- # One -/\n/- As you probably guessed we needed the zero as a additive identity, so now we need a \n    multiplicative identity. We are going to do basically the same thing as we did for zero, \n    so less annoying comments this time! -/\n\n/-- The complex number with real part 1 and imaginary part 0 -/\ndef one : \u2102 := \u27e81, 0\u27e9\n\n/-- Notation `1` for `one` -/\ninstance : has_one \u2102 := \u27e8one\u27e9 \n\n-- name the basic properties and tag them with `simp`\n@[simp] lemma one_re : re(1 : \u2102) = 1 := begin refl end\n@[simp] lemma one_im : im(1 : \u2102) = 0 := begin refl end\n\n/- Before I give you some more examples or exercises let's just quickly define the operations. It \n    again works in a very similar way to before when we defined `0` and `1`. -/\n\n/- # Add (+) -/\n\n/- This says take two numbers: `z = a  bi` and `w = u + vi` and then when we add them, just \n    add their real parts and then add their imaginary parts and define \n    `z + w = (a + u) + (b + v)i` -/\ndef add (z w : \u2102) : \u2102 := \u27e8z.re + w.re, z.im + w.im\u27e9\n\n/-- Notation `+` for addition -/\ninstance : has_add \u2102 := \u27e8add\u27e9\n\n/-- Let us define some more bits that is similar, to above -/\n@[simp] lemma add_re (z w : \u2102) : re(z + w) = re(z) + re(w) := begin refl end\n@[simp] lemma add_im (z w : \u2102) : im(z + w) = im(z) + im(w) := begin refl end\n\n/- # Negation (-) -/\n-- We note as mathematicians, that `a - b = a + -b` and so if we define negation, we then\n-- don't have to define subtraction.\n\n/-- The negation `-z` of a complex number `z` -/\ndef neg (z : \u2102) : \u2102 := \u27e8-re(z), -im(z)\u27e9\n\n/-- Notation `-` for negation -/\ninstance : has_neg \u2102 := \u27e8neg\u27e9\n\n-- how neg interacts with re and im\n@[simp] lemma neg_re (z : \u2102) : re(-z) = -re(z) := begin refl end\n@[simp] lemma neg_im (z : \u2102) : im(-z) = -im(z) := begin refl end\n\n/- ## Multiplication (*) -/\n\n/-- Multiplication `z*w` of two complex numbers -/\ndef mul (z w : \u2102) : \u2102 := \u27e8re(z) * re(w) - im(z) * im(w), re(z) * im(w) + im(z) * re(w)\u27e9\n\n/-- Notation `*` for multiplication -/\ninstance : has_mul \u2102 := \u27e8mul\u27e9\n\n-- how `mul` reacts with `re` and `im`\n@[simp] lemma mul_re (z w : \u2102) : re(z * w) = re(z) * re(w) - im(z) * im(w) := begin refl end\n@[simp] lemma mul_im (z w : \u2102) : im(z * w) = re(z) * im(w) + im(z) * re(w) := begin refl end\n\n\n\n\n\n\nend complex", "meta": {"author": "jamesa9283", "repo": "MATH1001", "sha": "468ae6863a4a5090fe171f4a11ca55b3f65d4359", "save_path": "github-repos/lean/jamesa9283-MATH1001", "path": "github-repos/lean/jamesa9283-MATH1001/MATH1001-468ae6863a4a5090fe171f4a11ca55b3f65d4359/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7189587923441211}}
{"text": "-- Graham, Knuth, Patashnik\n-- Concrete Mathematics\n\nimport tactic\nimport data.real.basic\nimport data.num.basic\n\nlemma l1 (x y : \u211d) : 0 \u2264 x^2-2*x*y + y^2 :=\nbegin\n  have h1 : 0 \u2264 (x - y)^2,\n  exact pow_two_nonneg (x - y),\n  ring SOP at h1,\n  ring at h1,\n  ring,\n  exact h1,\nend\n\nexample (a b : \u211d) : a \u2264 b \u2192 0 \u2264 b - a :=\nbegin\n  exact sub_nonneg.mpr,\nend\n\n-- CSI, two variable case\n-- todo: use sqrt?\ntheorem csi_two_variable (a1 a2 b1 b2 : \u211d) : (a1*b1 + a2*b2)^2 \u2264 (a1^2 + a2^2)*(b1^2 + b2^2) :=\nbegin\n  have h1 := l1 (a1*b2) (a2*b1),\n  rw \u2190 sub_nonneg,\n  ring SOP at h1,\n  ring SOP at h1,\n  ring SOP,\n  ring SOP,\n  ring SOP,\n  exact h1,\nend", "meta": {"author": "ldct", "repo": "lean-textbooks", "sha": "6550da16cd3f4c31145d3eb759a9326740a7dcd6", "save_path": "github-repos/lean/ldct-lean-textbooks", "path": "github-repos/lean/ldct-lean-textbooks/lean-textbooks-6550da16cd3f4c31145d3eb759a9326740a7dcd6/src/steele.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541659378681, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.7189376564416221}}
{"text": "import data.nat.basic \nimport data.int.parity\nimport tactic\n\nopen int\n\n/-lifted from tutorial project. I think there's potential to explain and \ndevelop these lemmas and parity in detail, but it could make the tutorial pretty long-/\ndef odd (n : \u2124) : Prop := \u2203 k, n = 2*k + 1\n\n#check int.not_even_iff\n\ntheorem not_even_iff_odd (n : \u2124) : \u00ac even n \u2194 odd n := \nbegin \n  rw int.not_even_iff,\n  split ; intro h,\n  use n/2,\n  conv_rhs { rw add_comm, congr, rw \u2190 h },\n  exact (int.mod_add_div n 2).symm,\n  rcases h with \u27e8k, rfl\u27e9,\n  simp [add_comm],\n  refl,\nend\n\n\ntheorem square_even_iff_even (n : \u2124) : even (n^2) \u2194 even n :=\nbegin\n  -- sorry\n  split,\n  { contrapose,\n    rw not_even_iff_odd,\n    rw not_even_iff_odd,\n    rintro \u27e8k, rfl\u27e9,\n    use 2*k*(k+1),\n    ring },\n  { rintro \u27e8k, rfl\u27e9,\n    use 2*k^2,\n    ring },\n  -- sorry\nend\n\ndef int_divides (a b : \u2124) : Prop := b % a = 0\n\ndef rel_prime (a b : \u2124) : Prop := \n    \u00ac \u2203 k:\u2115, (int_divides k a \u2227 int_divides  k b \u2227 k>1)\n\nlemma even_imp_square_even (a : \u2124) : even a \u2192 even (a^2) := \nbegin \nunfold even,\nrintro \u27e8k, h\u27e9,\nuse (2*k^2),\nrw h,\nring,\nend\n\ndef rational (n : \u2124) : Prop := \u2203 a b : \u2124, (rel_prime a b \u2227 a^2 = n*b^2)\n\n--I feel like this exists in mathlib. I'm trying to find it.\nlemma div_both_sides {a b k : \u2124} (h : k*a = k*b) (hk : k \u2260 0) : a = b := \nbegin \n  sorry,\nend\n\n--this could probably be cleaner/broken into smaller steps\ntheorem root_two_not_rational : \u00ac rational 2 :=\nbegin \n    rintros \u27e8a, b, a_b_rel_prime, h\u27e9,\n    unfold rel_prime at a_b_rel_prime,\n    have a_squared_even : even (a^2),\n        rw h,\n        use b^2,\n    have a_even : even a, \n        exact (square_even_iff_even a).mp a_squared_even,\n    cases a_even with c a_even,\n    rw a_even at h,\n    have b_squared_even : even (b^2),\n        unfold even,\n        use c^2,\n        rw mul_pow 2 c 2 at h,\n        rw pow_succ at h,\n        rw mul_assoc 2 (2^1) (c^2) at h,\n        have h' := div_both_sides h (by linarith),\n        simp at h',\n        rw h',\n    have b_even : even b, \n        exact (square_even_iff_even b).mp b_squared_even,\n    apply a_b_rel_prime,\n    use 2,\n    split,\n    unfold int_divides,\n    rw a_even,\n    simp,\n    split,\n    rcases b_even with \u27e8b_2, b_even\u27e9,\n    rw b_even,\n    unfold int_divides,\n    simp,\n    linarith,\nend\n\n\n\n\n\n--me trying to find lemmas in mathlib\n-- example (a b c : \u2115) (h : a*c = b*c) (h' : c \u2260 0) (h'' : a \u2260 0) (h''' : b \u2260 0)\n--    : a = b := \n-- begin \n--   library_search,\n--   sorry,\n-- end \n\nexample (a b c : \u2115) (h : a = b) : a*c = b*c :=\nbegin \n  exact congr_fun (congr_arg has_mul.mul h) c,\nend\n\nexample (a b : \u2115) (h : 2*a = 2*b) : a = b := \nbegin \n  refine eq.symm _,\n  sorry,\nend\n\nexample (a : \u2115) : (2*a)^2 = 2^2 * a^2 := \nbegin \n  exact nat.mul_pow 2 a 2, \nend", "meta": {"author": "iceplant", "repo": "mathcamp-tutorials", "sha": "481db142430e47f892e8f984aa08eecfb3167bb5", "save_path": "github-repos/lean/iceplant-mathcamp-tutorials", "path": "github-repos/lean/iceplant-mathcamp-tutorials/mathcamp-tutorials-481db142430e47f892e8f984aa08eecfb3167bb5/root_2_irrational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.7189369183315503}}
{"text": "/-\nCopyright (c) 2017 Simon Hudon All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon, Mario Carneiro\n\nTests for norm_num\n-/\n\nimport data.real.basic tactic.norm_num\n\nexample : 374 + (32 - (2 * 8123) : \u2124) - 61 * 50 = 86 + 32 * 32 - 4 * 5000\n      \u2227 43 \u2264 74 + (33 : \u2124) := by norm_num\n\nexample : \u00ac (7-2)/(2*3) \u2265 (1:\u211d) + 2/(3^2) := by norm_num\nexample : (6:real) + 9 = 15 := by norm_num\nexample : (2:real)/4 + 4 = 3*3/2 := by norm_num\nexample : (((3:real)/4)-12)<6 := by norm_num\nexample : (5:real) \u2260 8 := by norm_num\nexample : (10:real) > 7 := by norm_num\nexample : (2:real) * 2 + 3 = 7 := by norm_num\nexample : (6:real) < 10 := by norm_num\nexample : (7:real)/2 > 3 := by norm_num\nexample : (4:real)\u207b\u00b9 < 1 := by norm_num\n\nexample : (5 / 2:\u2115) = 2 := by norm_num\nexample : (5 / -2:\u2124) < -1 := by norm_num\nexample : (0 + 1) / 2 < 0 + 1 := by norm_num\n\nexample (x : \u2124) (h : 1000 + 2000 < x) : 100 * 30 < x :=\nby norm_num at *; try_for 100 {exact h}\n\nexample : (1103 : \u2124) \u2264 (2102 : \u2124) := by norm_num\nexample : (110474 : \u2124) \u2264 (210485 : \u2124) := by norm_num\nexample : (11047462383473829263 : \u2124) \u2264 (21048574677772382462 : \u2124) := by norm_num\nexample : (210485742382937847263 : \u2124) \u2264 (1104857462382937847262 : \u2124) := by norm_num\nexample : (210485987642382937847263 : \u2115) \u2264 (11048512347462382937847262 : \u2115) := by norm_num\nexample : (210485987642382937847263 : \u211a) \u2264 (11048512347462382937847262 : \u211a) := by norm_num\n\nexample (x : \u2115) : \u2115 := begin\n  let n : \u2115, {apply_normed (2^32 - 71)},\n  exact n\nend\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/tests/norm_num.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.7189369061805904}}
{"text": "/-\nThis file contains a formal computer proof of O(1/k) convergence of gradient descent with \nconstant stepsize for convex functions on a real inner-product space. It is \nself-contained other than using properties of real and natural numbers defined in mathlib.  \nI define the properties of convexity and Lipschitz continuous gradient here\nand do not rely on the mathlib-defined gradient. This means that a user \nwould have to ensure that their function is convex and the gradient is correct.\nWhile not ideal, this simplified the proofs. \nWe closely follow the proof of\nhttp://www.seas.ucla.edu/~vandenbe/236C/lectures/gradient.pdf\n-/\n\nimport data.real.basic \nimport analysis.inner_product_space.pi_L2\n\n-- H is an inner product space over the reals\n-- It is an abstract type but [inner_product_space \u211d H] \n-- ensures it satisfies all the properties of a real inner product space.\n-- It is interesting to note that we do not need H\n-- to be a Hilbert space. This is because, for \n-- nonasymptotic analyses, we do not need the space\n-- to be complete as we do not take limits anywhere. \nvariables {H : Type*} [inner_product_space \u211d H] \n\n-- inner product notation, i.e. scalar product. \nnotation `\u27ea`x`, `y`\u27eb` := @inner \u211d _ _ x y\n\n-- method under study. Note that \u2022 means \"scalar multiply\"\n-- i.e. a scalar times a vector. \n-- it is written \"backslash+smul\"\nnoncomputable def grad_descent \n            (\u03b7 : \u211d) (x0 : H) (gradf : H \u2192 H): (\u2115 \u2192 H) \n| 0      := x0 \n| (n+1)  := grad_descent(n) - \u03b7\u2022gradf(grad_descent(n))\n\n-- Definition of a convex function and it's gradient. \ndef is_convex (f: H \u2192 \u211d) (gradf : H \u2192 H) : Prop := \n  \u2200 (x y : H), f(y) \u2265  f(x) + \u27eagradf(x),y-x\u27eb\n\n-- Definition of Lipschitz-continuous gradient\ndef is_lip_grad (f: H \u2192 \u211d) (gradf : H \u2192 H) (L : \u211d) : Prop :=\n  \u2200 (x y : H), f(y) \u2264 f(x) + \u27eagradf(x),y-x\u27eb + 0.5*L*\u2225y-x\u2225^2 \n\n-- some simple helper lemmas \nlemma helper_norm_sq_eq_inner (x : H)\n        : \u2225x\u2225^2= \u27eax,x\u27eb_\u211d\n        :=\nbegin \n  let h := norm_sq_eq_inner x,\n  assumption,\nend \n\nlemma helper_inner_neg (x y:H) \n        : \u27eax,-y\u27eb = -\u27eax,y\u27eb\n        :=\nbegin \n  exact inner_neg_right,\nend \n\n\n-- A basic descent lemma for gradient descent \nlemma basic_grad_step (x : H) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H) \n                      (hlip : is_lip_grad f gradf L)\n                      :\n  f(x-\u03b7\u2022gradf x) \u2264 f(x) - \u03b7*(1-L*\u03b7/2)*\u2225gradf x\u2225^2 \n  :=\nbegin\n  have HLip := hlip x (x-\u03b7\u2022gradf x),\n\n  have h : x - \u03b7 \u2022 gradf x - x = x - x - \u03b7 \u2022 gradf x := by abel,\n  rw h at HLip, clear h,\n  rw sub_self at HLip,\n  rw zero_sub at HLip,\n  \n\n  rw inner_neg_right at HLip,\n  rw real_inner_smul_right at HLip,\n  \n  have h1 := helper_norm_sq_eq_inner (gradf x),\n  rw \u2190 h1 at HLip,\n\n  rw norm_neg at HLip,\n  \n\n  have h : \u2225\u03b7 \u2022 gradf x\u2225 = |\u03b7|*\u2225gradf x \u2225  :=  norm_smul \u03b7 (gradf x),\n  rw h at HLip, clear h,\n  \n  rw mul_pow at HLip,\n\n  have h : |\u03b7| ^ 2 = \u03b7^2 := sq_abs \u03b7,\n  rw h at HLip, clear h,\n\n  rw mul_sub,\n  rw mul_one,\n  rw sub_mul,\n  rw \u2190 sub_add,\n\n  have h : 1 / 2 * L * (\u03b7 ^ 2 * \u2225gradf x\u2225 ^ 2)\n          = \u03b7 * (L * \u03b7 / 2) * \u2225gradf x\u2225 ^ 2 := by ring,\n  rw h at HLip, clear h,\n  exact HLip,\n  \nend \n\n-- an algebraic manipulation lemma \nlemma complete_square (x y : H) (t : \u211d) (ht : t > 0): \n  \u27eax,y\u27eb - (t/2)*\u2225y\u2225^2 = (1/(2*t))*(\u2225x\u2225^2 - \u2225x-t\u2022y\u2225^2)\n  :=\nbegin \n  rw norm_sub_sq_real,\n  have h0 : \u2225x\u2225 ^ 2 - (\u2225x\u2225 ^ 2 - 2 * inner x (t \u2022 y) + \u2225t \u2022 y\u2225 ^ 2)\n          = \u2225x\u2225 ^ 2 - \u2225x\u2225 ^ 2 + 2 * inner x (t \u2022 y) - \u2225t \u2022 y\u2225 ^ 2\n          := by abel,\n  simp at h0,\n  rw h0,\n  rw inner_smul_right,\n  rw norm_smul,\n  have h1 : \u2225t\u2225 = |t| := real.norm_eq_abs t,\n  rw h1,\n  have h2 : |t| = t := abs_of_pos ht,\n  rw h2,\n  rw mul_sub,\n  have h3 : 1 / (2 * t) * (2 * (t * inner x y)) = \n            (1 / (2 * t)) * 2 * t * inner x y\n            := by ring,\n  rw h3,\n  have h4 : 1 / (2 * t) * 2 * t =  2 / (2 * t) * t\n        := by ring,\n  rw h4,\n  have h5 : 2 / (2 * t) * t = (2*t) / (2 * t) \n        := by ring,\n  rw h5,\n\n  have h6 : (2:\u211d)\u2260 0:=by norm_num,\n  have h7 : t \u2260 0 := ne_of_gt ht,\n  have h8 : 2*t \u2260 0 := mul_ne_zero h6 h7,\n\n  have h8 : (2*t) / (2 * t) = 1 := div_self h8,\n\n  rw h8,\n  rw one_mul,\n\n  have h9 : (t * \u2225y\u2225) ^ 2  = t^ 2 * \u2225y\u2225 ^ 2\n          := mul_pow t (\u2225y\u2225) 2,\n  rw h9,\n\n  have h10 : 1 / (2 * t) * (t ^ 2 * \u2225y\u2225 ^ 2)\n          = t ^ 2 / (2 * t) * \u2225y\u2225 ^ 2\n          := by ring,\n  \n  rw h10,\n\n  rw mul_comm 2 t,\n\n  have h11 : t^2 / (t * 2) = (t ^ 2 / t) / 2 \n    := (div_div_eq_div_mul (t^2) t 2).symm,\n  rw h11,\n  \n  rw sq t,\n  have h12 : t * t / t = t*(t/t):=by ring,\n  rw h12,\n  rw div_self h7,\n  rw mul_one,\n\nend \n\n-- a stepsize technicality \nlemma stepsz_upper (t L : \u211d) (hL : L \u2265 0) (h : t\u22641/L): t*L \u2264 1 :=\nbegin \n  \n  cases lt_or_ge 0 L,\n\n  exact (le_div_iff h_1).mp h,\n\n  have h2 : L=0 := by linarith,\n  rw h2,\n  linarith,\n  \nend \n\n-- further refinement of the descent properties of the algorithm \nlemma basic_grad_step_v2 (x : H) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H)\n                    (hL : L \u2265 0)\n                    (h\u03b7_low : \u03b7 \u2265 0) \n                    (h\u03b72 : \u03b7 \u2264 1/L) \n                    (hlip : is_lip_grad f gradf L)\n                    :\n  f(x-\u03b7\u2022gradf x) \u2264 f(x) -(\u03b7/2)*\u2225gradf x\u2225^2 \n:=\nbegin\n  have h := basic_grad_step x \u03b7 L f gradf hlip,\n  rw mul_sub at h,\n  rw mul_one at h,\n  rw sub_mul at h,\n  rw \u2190 sub_add at h,\n\n  have h1 := stepsz_upper \u03b7 L hL h\u03b72,\n  rw mul_comm L _ at h,\n\n  have h2 :  2 > 0 := by norm_num,\n  have h3 : \u03b7 * L /2 \u2264 1 /2 := by nlinarith,\n  have h4 : \u03b7*(\u03b7 * L /2)\u2264 \u03b7*1/2 := by nlinarith,\n  clear h3,\n  \n  have h4 : 0 \u2264 \u2225gradf x\u2225 ^ 2  := by exact sq_nonneg (\u2225gradf x\u2225),\n  have h5 : \u2225gradf x\u2225 ^ 2 \u2265 0 := by linarith, clear h4,\n\n  have h6 : \u03b7*(\u03b7 * L /2)*\u2225gradf x\u2225 ^ 2 \u2264 (\u03b7*1/2)*\u2225gradf x\u2225 ^ 2\n          := by nlinarith,\n\n  clear h4, clear h5,\n\n  have h7 : f (x - \u03b7 \u2022 gradf x) \n            \u2264 f x - \u03b7 * \u2225gradf x\u2225 ^ 2 + (\u03b7*1/2)*\u2225gradf x\u2225 ^ 2\n          := by linarith,\n  clear h, clear h6,\n  \n  rw mul_one at h7,\n\n  rw sub_add at h7,\n\n  rw \u2190 sub_mul at h7,\n\n  have h : \u03b7 - \u03b7 / 2 = \u03b7/2 := by linarith,\n  rw h at h7,\n  exact h7,\nend \n\n-- formally stating that the algorithm decreases function values \nlemma descent (x : H) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H)\n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 \u2265 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      :\n    f(x-\u03b7\u2022gradf x) \u2264 f(x) \n  :=\nbegin\n  have h := basic_grad_step_v2 x \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip,\n\n  have h2 : 2>0:=by norm_num,\n  have h3 : \u03b7/2\u22650:= by nlinarith,\n  have h4 : 0 \u2264 \u2225gradf x\u2225 ^ 2  := by exact sq_nonneg (\u2225gradf x\u2225),\n  have h5 : \u2225gradf x\u2225 ^ 2 \u2265 0 := by linarith, clear h4,\n\n  have h6 : \u03b7 / 2 * \u2225gradf x\u2225 ^ 2 \u2265 0 := by nlinarith,\n  \n  linarith,\nend \n\nlemma prepare_to_telescope (x y: H) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H)\n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    f(x-\u03b7\u2022gradf x) - f y \u2264 (1/(2*\u03b7))*(\u2225x-y\u2225^2 - \u2225x-\u03b7\u2022gradf x - y\u2225^2)\n    :=\nbegin \n  have h\u03b7_low2 : \u03b7 \u2265 0 := by linarith,\n  have h1 := basic_grad_step_v2  x \u03b7 L f gradf hL h\u03b7_low2 h\u03b72 hlip,\n\n  have h2 :  f (x - \u03b7 \u2022 gradf x) -f y \u2264 f x - f y - \u03b7 / 2 * \u2225gradf x \u2225^ 2 \n    := by linarith,\n  \n  have h3 := hconv x y,\n\n  have h4 : f x-f y \u2264  - inner (gradf x) (y - x) := by linarith,\n\n  have h5 := helper_inner_neg (gradf x) (y - x),\n  clear h3,\n  rw \u2190 h5 at h4, clear h5, \n  have h5 : -(y-x)=x-y:=by abel,\n  rw h5 at h4, clear h5,\n\n  have h5 : f(x - \u03b7 \u2022 gradf x) - f y \u2264 \u27eagradf x,x-y\u27eb - \u03b7 / 2 * \u2225gradf x\u2225 ^ 2\n    := by linarith,\n  clear h2,clear h4,clear h1,\n\n  rw real_inner_comm at h5,\n  \n  have h2 := complete_square (x-y) (gradf x)  \u03b7 h\u03b7_low,\n  rw h2 at h5,\n  \n  have h4 : x - y - \u03b7 \u2022 gradf x = x - \u03b7 \u2022 gradf x - y := sub_right_comm x y (\u03b7 \u2022 gradf x),\n\n  rw h4 at h5,\n  exact h5,\n\nend \n\n-- rewrite the telescoping more favorably \nlemma prepare_to_telescope2 (x0 y: H) (n : \u2115) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H)\n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    f(grad_descent \u03b7 x0 gradf (n+1)) - f y \u2264 \n    (1/(2*\u03b7))*(\u2225grad_descent \u03b7 x0 gradf n-y\u2225^2 - \u2225grad_descent \u03b7 x0 gradf (n+1) - y\u2225^2)\n    :=\nbegin \n  have h1 : grad_descent \u03b7 x0 gradf (n+1) = \n            grad_descent \u03b7 x0 gradf (n) - \u03b7\u2022gradf(grad_descent \u03b7 x0 gradf (n))\n          := by simp [grad_descent],\n  \n  rw h1,\n  clear h1,\n  exact prepare_to_telescope (grad_descent \u03b7 x0 gradf (n)) y \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip hconv,\n\nend \n\n-- sum_f is just the sum of function values evaluated at the points \n-- generated by the algorithm (again defined recursively)\nnoncomputable def sum_f (y x0 : H) (f : H \u2192 \u211d) (\u03b7 : \u211d) (gradf : H \u2192 H): (\u2115 \u2192 \u211d)\n| 0      := 0\n| (n+1)  := sum_f(n) + f(grad_descent \u03b7 x0 gradf (n+1)) - f y\n\n-- the all important telescoping result \nlemma telescope (x0 y: H) (n : \u2115) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H) \n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    sum_f y x0 f \u03b7 gradf (n) \u2264 (1/(2*\u03b7))*(\u2225x0-y\u2225^2 - \u2225grad_descent \u03b7 x0 gradf n  - y\u2225^2)\n    :=\nbegin \n  induction n with k hk,\n  have h1 : grad_descent \u03b7 x0 gradf 0 = x0 := by refl,\n  rw h1,\n  \n  have h2 : 1 / (2 * \u03b7) * (\u2225x0 - y\u2225 ^ 2 - \u2225x0 - y\u2225 ^ 2) = 0 := by linarith,\n  rw h2,\n  refl,\n\n  have h : sum_f y x0 f \u03b7 gradf k.succ = sum_f y x0 f \u03b7 gradf k +\n       f(grad_descent \u03b7 x0 gradf (k+1)) - f y := by simp [sum_f],\n  rw h, clear h,\n\n  have h := prepare_to_telescope2 x0 y k \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip hconv, \n  linarith,\n\nend \n\n-- a simple upper bound derived from telescoping \nlemma from_telescope (x0 y: H) (n : \u2115) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H)\n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    sum_f y x0 f \u03b7 gradf (n) \u2264 (1/(2*\u03b7))*\u2225x0-y\u2225^2 \n    :=\nbegin \n  have h := telescope x0 y n \u03b7 L f gradf hL h\u03b7_low h\u03b72 hlip hconv,\n\n  have h1 : \u2225grad_descent \u03b7 x0 gradf n - y\u2225 ^ 2 \u2265 0 \n    := sq_nonneg (\u2225grad_descent \u03b7 x0 gradf n - y\u2225),\n  \n  rw mul_sub at h,\n  have h2 : 2 > 0 := by norm_num,\n  have h3 : 2*\u03b7 > 0 := by nlinarith,\n  have h5 : 1 / (2*\u03b7) >0 := one_div_pos.mpr h3,\n\n  have h6 :  1 / (2 * \u03b7) * \u2225grad_descent \u03b7 x0 gradf n - y\u2225 ^ 2 \u2265 0 \n    := by nlinarith,\n  linarith,\n\nend \n\n-- since func values are decreasing, the sum of func vals provides \n-- a bound on the last function value as follows\nlemma last_less_than_av (x0 y: H) (n : \u2115) (\u03b7 L : \u211d) (f : H \u2192 \u211d) (gradf : H \u2192 H)\n                      (hL : L \u2265 0)\n                      (h\u03b7_low : \u03b7 > 0) \n                      (h\u03b72 : \u03b7 \u2264 1/L) \n                      (hlip : is_lip_grad f gradf L)\n                      (hconv : is_convex f gradf)\n                      :\n    sum_f y x0 f \u03b7 gradf (n) \u2265 n*(f(grad_descent \u03b7 x0 gradf n) - f y)\n    :=\nbegin \n  induction n with k hk,\n\n  have h : \u21910 = (0:\u211d):= nat.cast_zero,\n  rw h,\n  rw zero_mul,\n  have h1 : sum_f y x0 f \u03b7 gradf 0 = 0 := by refl,\n  rw h1,\n  exact rfl.ge,\n  \n\n  have h2 : sum_f y x0 f \u03b7 gradf k.succ = sum_f y x0 f \u03b7 gradf (k) + f(grad_descent \u03b7 x0 gradf (k+1)) - f y\n    := by simp [sum_f],\n\n\n  rw h2,\n\n\n  rw nat.succ_eq_add_one,\n  have h3 : \u2191(k+1) = (k+1 : \u211d):= nat.cast_succ k,\n  rw h3,\n  have h4 : (\u2191k + 1) * (f (grad_descent \u03b7 x0 gradf (k + 1)) - f y)\n            = \u2191k*(f (grad_descent \u03b7 x0 gradf (k + 1)) - f y) \n              + f (grad_descent \u03b7 x0 gradf (k + 1)) - f y\n          := by linarith,\n  rw h4,\n\n\n  have h\u03b7_low2 : \u03b7 \u2265 0 := by linarith,\n\n  have hdesc := descent (grad_descent \u03b7 x0 gradf k) \u03b7 L f gradf hL h\u03b7_low2 h\u03b72 hlip, \n   \n  \n  have h5 : grad_descent \u03b7 x0 gradf (k+1) = \n        grad_descent \u03b7 x0 gradf k - \u03b7 \u2022 gradf (grad_descent \u03b7 x0 gradf k)\n    := by simp [grad_descent],\n  \n\n  rw \u2190 h5 at hdesc,\n\n  \n  have h6 : \u2191k * f (grad_descent \u03b7 x0 gradf (k + 1)) \u2264 \u2191k * f (grad_descent \u03b7 x0 gradf k),\n  {\n    have hupk : (0:\u211d) \u2264 (\u2191k)  := nat.cast_nonneg k,\n\n    exact mul_le_mul_of_nonneg_left hdesc hupk,\n\n  },\n\n  linarith,\nend \n\n-- Main convergence rate result \n-- Note that y is an arbitrary point but it is customarily taken to \n-- be one of the minimizers (assuming minimizers exist)\ntheorem grad_descent_convergence_rate (n : \u2115) (\u03b7 L : \u211d) (x0 y : H) (f : H \u2192 \u211d) (gradf : H \u2192 H)\n                        (hn : n \u2265 1)\n                        (h\u03b7_low : \u03b7 > 0) \n                        (h\u03b7_up : \u03b7 \u2264 1/L) \n                        (hL : L \u2265 0)\n                        (hconv : is_convex f gradf)\n                        (hlip : is_lip_grad f gradf L)\n                        :\n      f(grad_descent \u03b7 x0 gradf n) - f(y)\u2264 (1/(2*\u03b7*n))*\u2225x0-y\u2225^2\n   :=\nbegin\n  have h0 := from_telescope x0 y n \u03b7 L f gradf hL h\u03b7_low h\u03b7_up hlip hconv,\n  have h1 := last_less_than_av x0 y n \u03b7 L f gradf hL h\u03b7_low h\u03b7_up hlip hconv,\n\n  have h2 : \u2191n * (f (grad_descent \u03b7 x0 gradf n) - f y) \u2264 1 / (2 * \u03b7) * \u2225x0 - y\u2225 ^ 2\n   := by linarith,\n  \n  have h3 :  (f (grad_descent \u03b7 x0 gradf n) - f y) \u2264 1 / (2 * \u03b7) * \u2225x0 - y\u2225 ^ 2 / \u2191n,\n  {\n    have h4 : \u2191n\u2265 (1:\u211d) := nat.one_le_cast.mpr hn,\n    \n    have h5 : \u2191n > (0:\u211d) := by linarith,\n\n    exact (le_div_iff' h5).mpr h2,\n  },\n  clear h2,\n\n  have h6 : 1 / (2 * \u03b7) * \u2225x0 - y\u2225 ^ 2 / \u2191n = (1/\u2191n)*1 / (2 * \u03b7) * \u2225x0 - y\u2225 ^ 2\n    := by ring,\n  \n  have h7 : (1/\u2191n)*1 / (2 * \u03b7) \n            = 1 / (2 * \u03b7 * \u2191n),\n  {\n    ring_nf,\n    exact mul_inv\u2080.symm,\n  },\n  rw h6 at h3,\n  rw h7 at h3,\n  exact h3,\n\nend \n", "meta": {"author": "1austrartsua1", "repo": "FormalConvexOpt", "sha": "4114be9dbd8353da32dc3299405397f11d858f77", "save_path": "github-repos/lean/1austrartsua1-FormalConvexOpt", "path": "github-repos/lean/1austrartsua1-FormalConvexOpt/FormalConvexOpt-4114be9dbd8353da32dc3299405397f11d858f77/src/GD.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.7188784609079789}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis is about \"gappy sets\", ie subsets s in fin n = {0,...,n-1} \nsuch that s contains no adjacent pairs {i,i+1}.  We define \n`(gappy n)` to be the set of such subsets.\n\nA key point is that there is a bijection \n`(gappy n) \u2295 (gappy n + 1) \u2243 (gappy n + 2)`, which we define as\n`(gappy_equiv n)`.  From this it follows inductively that the \ncardinality of `(gappy n)` is the (n + 2)nd Fibonacci number.\n\n-/\n\nimport data.fintype.basic \nimport combinatorics.fibonacci combinatorics.shift\n\nnamespace combinatorics\n\n/- We find it convenient to introduce a new notation for\n   the zero element in fin m.  Notice that this only exists\n   when m > 0, or equivalently, when m has the form \n   n.succ = n + 1 for some n.\n-/\ndef fin.z {n : \u2115} : fin (n.succ) := 0\n\nlemma fin.z_val {n : \u2115} : (@fin.z n).val = 0 := rfl\n\nlemma fin.succ_ne_z {n : \u2115} (i : fin n) : i.succ \u2260 fin.z := \nbegin\n cases i with i i_is_lt,\n intro e,\n cases e\nend\n\n/- Definition of gappiness -/\ndef is_gappy : \u2200 {n : \u2115} (s : finset (fin n)), Prop \n| 0 _ := true\n| (nat.succ n) s := \u2200 a : fin n, \u00ac (a.cast_succ \u2208 s \u2227 a.succ \u2208 s)\n\ninstance is_gappy_decidable :\n forall {n : \u2115} (s : finset (fin n)), decidable (is_gappy s)\n| 0 _ := by {dsimp[is_gappy],apply_instance}\n| (nat.succ n) s := by {dsimp[is_gappy],apply_instance}\n\ndef gappy' (n : \u2115) : finset (finset (fin n)) := \n finset.univ.filter is_gappy\n\ndef gappy (n : \u2115) : Type := \n { s : finset (fin n) // is_gappy s }\n\ninstance {n : \u2115} : fintype (gappy n) := \n by { dsimp[gappy], apply_instance }\n\ninstance {n : \u2115} : decidable_eq (gappy n) := \n by { dsimp[gappy], apply_instance }\n\ninstance {n : \u2115} : has_coe (gappy n) (finset (fin n)) :=\n by { dsimp[gappy], apply_instance }\n\nlemma gappy_spec {n : \u2115} (s : gappy n) : is_gappy (s : finset (fin n)) := s.property \n\n/- How to generate a string describing a gappy set -/\ninstance {n : \u2115} : has_repr (gappy n) := \n \u27e8\u03bb (s : gappy n), repr s.val\u27e9\n\n/- Some lemmas about (un)shifting and gappiness -/\n\nlemma shift_gappy : \u2200 {n : \u2115} {s : finset (fin n)},\n is_gappy s \u2192 is_gappy (shift s)\n| 0 _ _ := \u03bb a, fin.elim0 a\n| (nat.succ n) s s_gappy := begin\n rintros a \u27e8a_in_shift,a_succ_in_shift\u27e9,\n let a_in_s : a \u2208 s := (succ_mem_shift_iff s a).mp a_succ_in_shift,\n rcases (mem_shift s a.cast_succ).mp a_in_shift with \u27e8b,\u27e8b_in_s,eb\u27e9\u27e9,\n replace eb := congr_arg (coe : (fin _) \u2192 \u2115) eb,\n rw[fin.coe_succ,fin.coe_cast_succ] at eb,\n have a_is_lt : (a : \u2115) < n.succ := a.property,\n rw[\u2190 eb] at a_is_lt,\n let c_is_lt : (b : \u2115) < n := nat.lt_of_succ_lt_succ a_is_lt, \n let c : fin n := \u27e8b,c_is_lt\u27e9,\n have ebc : b = fin.cast_succ c := fin.ext (by { rw[fin.coe_cast_succ], refl } ),\n have eac : a = fin.succ c := fin.ext (nat.succ_inj'.mp (by { rw[\u2190 eb,fin.coe_succ], refl })),\n rw[ebc] at b_in_s,\n rw[eac] at a_in_s,\n exact s_gappy c \u27e8b_in_s,a_in_s\u27e9, \nend\n\nlemma unshift_gappy : \u2200 {n : \u2115} {s : finset (fin n.succ)},\n is_gappy s \u2192 is_gappy (unshift s)\n| 0 _ _ := trivial\n| (nat.succ n) s s_gappy := begin\n rintros a \u27e8a_in_unshift,a_succ_in_unshift\u27e9,\n let a_succ_in_s := (mem_unshift s a.cast_succ).mp a_in_unshift,\n let a_succ_succ_in_s := (mem_unshift s a.succ).mp a_succ_in_unshift,\n have e : a.cast_succ.succ = a.succ.cast_succ := \n  fin.ext\n   (by { rw[fin.coe_succ,fin.coe_cast_succ,fin.coe_cast_succ,fin.coe_succ]}),\n rw[e] at a_succ_in_s,\n exact s_gappy a.succ \u27e8a_succ_in_s,a_succ_succ_in_s\u27e9,\nend\n\nlemma insert_gappy : \u2200 {n : \u2115} {s : finset (fin n.succ.succ)}, \n is_gappy s \u2192 (\u2200 (a : fin n.succ.succ), a \u2208 s \u2192 a.val \u2265 2) \u2192 \n  is_gappy (insert (0 : fin _) s) := \nbegin\n rintros n s s_gappy s_big a \u27e8a_in_t,a_succ_in_t\u27e9,\n rcases finset.mem_insert.mp a_succ_in_t with a_succ_zero | a_succ_in_s,\n {exact fin.succ_ne_z a a_succ_zero},\n have a_pos\u2080 : (a.succ : \u2115) \u2265 2 := (s_big a.succ a_succ_in_s),\n rw[fin.coe_succ] at a_pos\u2080,\n let a_pos : 0 < (a : \u2115) := nat.lt_of_succ_lt_succ a_pos\u2080,\n rcases finset.mem_insert.mp a_in_t with a_zero | a_in_s,\n {replace a_zero : (a : \u2115) = 0 :=\n  (fin.coe_cast_succ a).symm.trans (congr_arg coe a_zero),\n  rw[a_zero] at a_pos,\n  exact lt_irrefl 0 a_pos,\n },{\n  exact s_gappy a \u27e8a_in_s,a_succ_in_s\u27e9, \n }\nend\n\ndef i {n : \u2115} (s : gappy n) : gappy n.succ := \n \u27e8shift s.val,shift_gappy s.property\u27e9 \n\nlemma i_val {n : \u2115} (s : gappy n) : (i s).val = shift s.val := rfl\n\nlemma zero_not_in_i {n : \u2115} (s : gappy n) : (0 : fin _) \u2209 ((i s) : finset (fin n.succ)) := \n zero_not_mem_shift s.val\n\nlemma shift_big {n : \u2115} (s : finset (fin n)) : \n \u2200 (a : fin n.succ.succ), a \u2208 shift (shift s) \u2192 (a : \u2115) \u2265 2 := \nbegin\n intros a ma,\n rcases (mem_shift (shift s) a).mp ma with \u27e8b,\u27e8mb,eb\u27e9\u27e9,\n rcases (mem_shift s b).mp mb with \u27e8c,\u27e8mc,ec\u27e9\u27e9,\n rw[\u2190 eb,\u2190 ec,fin.coe_succ,fin.coe_succ],\n apply nat.succ_le_succ,\n apply nat.succ_le_succ,\n exact nat.zero_le c.val,\nend\n\ndef j {n : \u2115} (s : gappy n) : gappy n.succ.succ := \n \u27e8insert (0 : fin _) (shift (shift s.val)),\n  begin \n   let h := insert_gappy (shift_gappy (shift_gappy s.property)) (shift_big s.val),\n   exact h,\n  end\u27e9\n\nlemma j_val {n : \u2115} (s : gappy n) :\n (j s).val = insert (0 : fin _) (shift (shift s.val)) := rfl\n\nlemma zero_in_j {n : \u2115} (s : gappy n) : (0 : fin _) \u2208 (j s : finset (fin n.succ.succ)) := \n finset.mem_insert_self _ _\n\ndef p {n : \u2115} : (gappy n) \u2295 (gappy n.succ) \u2192 gappy n.succ.succ \n| (sum.inl s) := j s\n| (sum.inr s) := i s\n\ndef q {n : \u2115} (s : gappy n.succ.succ) : (gappy n) \u2295 (gappy n.succ) := \nif (0 : fin _) \u2208 s.val then\n sum.inl \u27e8unshift (unshift s.val),unshift_gappy (unshift_gappy s.property)\u27e9\nelse\n sum.inr \u27e8unshift s.val,unshift_gappy s.property\u27e9 \n\nlemma qp {n : \u2115} (s : (gappy n) \u2295 (gappy n.succ)) : q (p s) = s := \nbegin\n rcases s with s | s; dsimp[p,q],\n {rw[if_pos (zero_in_j s)],congr,apply subtype.eq,\n  change unshift (unshift (j s).val) = s.val,\n  rw[j_val,unshift_insert,unshift_shift,unshift_shift],\n },\n {rw[if_neg (zero_not_in_i s)],congr,apply subtype.eq,\n  change unshift (i s).val = s.val,\n  rw[i_val,unshift_shift],\n }\nend\n\nlemma pq {n : \u2115} (s : gappy n.succ.succ) : p (q s) = s := \nbegin\n dsimp[q],split_ifs; dsimp[p]; apply subtype.eq,\n {rw[j_val],\n  change insert (0 : fin _) (shift (shift (unshift (unshift s.val )))) = s.val,\n  have z_not_in_us : (0 : fin _) \u2209 unshift s.val := begin\n   intro z_in_us,\n   let z_succ_in_s := (mem_unshift s.val (0 : fin _)).mp z_in_us,\n   exact s.property (0 : fin _) \u27e8h,z_succ_in_s\u27e9,\n  end,\n  rw[shift_unshift0 (unshift s.val) z_not_in_us],\n  rw[shift_unshift1 s.val h],\n },{\n  rw[i_val],\n  change shift (unshift s.val) = s.val,\n  exact shift_unshift0 s.val h,  \n }\nend\n\ndef gappy_equiv {n : \u2115} :\n ((gappy n) \u2295 (gappy n.succ)) \u2243 (gappy n.succ.succ) := {\n to_fun := p,\n inv_fun := q,\n left_inv := qp,\n right_inv := pq\n}\n\nlemma gappy_card_step (n : \u2115) :\n fintype.card (gappy n.succ.succ) =\n  fintype.card (gappy n) + fintype.card (gappy n.succ) := \nbegin\n let e0 := fintype.card_congr (@gappy_equiv n),\n rw[fintype.card_sum] at e0,\n exact e0.symm\nend\n\nlemma gappy_card : \u2200 (n : \u2115), fintype.card (gappy n) = fibonacci n.succ.succ\n| 0 := rfl\n| 1 := rfl\n| (nat.succ (nat.succ n)) := begin\n rw[gappy_card_step n,gappy_card n,gappy_card n.succ],\n dsimp[fibonacci],refl,\nend\n\nend combinatorics", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/combinatorics/gappy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195635, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7188600298974891}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n\n! This file was ported from Lean 3 source module analysis.normed_space.star.exponential\n! leanprover-community/mathlib commit 1e3201306d4d9eb1fd54c60d7c4510ad5126f6f9\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.NormedSpace.Exponential\n\n/-! # The exponential map from selfadjoint to unitary\nIn this file, we establish various propreties related to the map `\u03bb a, exp \u2102 A (I \u2022 a)` between the\nsubtypes `self_adjoint A` and `unitary A`.\n\n## TODO\n\n* Show that any exponential unitary is path-connected in `unitary A` to `1 : unitary A`.\n* Prove any unitary whose distance to `1 : unitary A` is less than `1` can be expressed as an\n  exponential unitary.\n* A unitary is in the path component of `1` if and only if it is a finite product of exponential\n  unitaries.\n-/\n\n\nsection Star\n\nvariable {A : Type _} [NormedRing A] [NormedAlgebra \u2102 A] [StarRing A] [ContinuousStar A]\n  [CompleteSpace A] [StarModule \u2102 A]\n\nopen Complex\n\n/-- The map from the selfadjoint real subspace to the unitary group. This map only makes sense\nover \u2102. -/\n@[simps]\nnoncomputable def selfAdjoint.expUnitary (a : selfAdjoint A) : unitary A :=\n  \u27e8exp \u2102 (I \u2022 a), exp_mem_unitary_of_mem_skewAdjoint _ (a.Prop.smul_mem_skewAdjoint conj_I)\u27e9\n#align self_adjoint.exp_unitary selfAdjoint.expUnitary\n\nopen selfAdjoint\n\ntheorem Commute.expUnitary_add {a b : selfAdjoint A} (h : Commute (a : A) (b : A)) :\n    expUnitary (a + b) = expUnitary a * expUnitary b :=\n  by\n  ext\n  have hcomm : Commute (I \u2022 (a : A)) (I \u2022 (b : A))\n  calc\n    _ = _ := by simp only [h.eq, Algebra.smul_mul_assoc, Algebra.mul_smul_comm]\n    \n  simpa only [exp_unitary_coe, AddSubgroup.coe_add, smul_add] using exp_add_of_commute hcomm\n#align commute.exp_unitary_add Commute.expUnitary_add\n\ntheorem Commute.expUnitary {a b : selfAdjoint A} (h : Commute (a : A) (b : A)) :\n    Commute (expUnitary a) (expUnitary b) :=\n  calc\n    expUnitary a * expUnitary b = expUnitary b * expUnitary a := by\n      rw [\u2190 h.exp_unitary_add, \u2190 h.symm.exp_unitary_add, add_comm]\n    \n#align commute.exp_unitary Commute.expUnitary\n\nend Star\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/NormedSpace/Star/Exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8418256452674009, "lm_q1q2_score": 0.7188456605149641}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Neil Strickland\n-/\nimport data.pnat.defs\nimport data.nat.bits\nimport data.nat.order.basic\nimport data.set.basic\nimport algebra.group_with_zero.divisibility\nimport algebra.order.positive.ring\n\n/-!\n# The positive natural numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file develops the type `\u2115+` or `pnat`, the subtype of natural numbers that are positive.\nIt is defined in `data.pnat.defs`, but most of the development is deferred to here so\nthat `data.pnat.defs` can have very few imports.\n-/\n\nattribute [derive [add_left_cancel_semigroup, add_right_cancel_semigroup, add_comm_semigroup,\n  linear_ordered_cancel_comm_monoid, has_add, has_mul, distrib]] pnat\n\nnamespace pnat\n\ninstance : is_well_order \u2115+ (<) := { }\n\n@[simp] lemma one_add_nat_pred (n : \u2115+) : 1 + n.nat_pred = n :=\nby rw [nat_pred, add_tsub_cancel_iff_le.mpr $ show 1 \u2264 (n : \u2115), from n.2]\n\n@[simp] lemma nat_pred_add_one (n : \u2115+) : n.nat_pred + 1 = n :=\n(add_comm _ _).trans n.one_add_nat_pred\n\n@[mono] lemma nat_pred_strict_mono : strict_mono nat_pred := \u03bb m n h, nat.pred_lt_pred m.2.ne' h\n@[mono] lemma nat_pred_monotone : monotone nat_pred := nat_pred_strict_mono.monotone\nlemma nat_pred_injective : function.injective nat_pred := nat_pred_strict_mono.injective\n\n@[simp] lemma nat_pred_lt_nat_pred {m n : \u2115+} : m.nat_pred < n.nat_pred \u2194 m < n :=\nnat_pred_strict_mono.lt_iff_lt\n\n@[simp] lemma nat_pred_le_nat_pred {m n : \u2115+} : m.nat_pred \u2264 n.nat_pred \u2194 m \u2264 n :=\nnat_pred_strict_mono.le_iff_le\n\n@[simp] lemma nat_pred_inj {m n : \u2115+} : m.nat_pred = n.nat_pred \u2194 m = n := nat_pred_injective.eq_iff\n\nend pnat\n\nnamespace nat\n\n@[mono] theorem succ_pnat_strict_mono : strict_mono succ_pnat := \u03bb m n, nat.succ_lt_succ\n\n@[mono] theorem succ_pnat_mono : monotone succ_pnat := succ_pnat_strict_mono.monotone\n\n@[simp] theorem succ_pnat_lt_succ_pnat {m n : \u2115} : m.succ_pnat < n.succ_pnat \u2194 m < n :=\nsucc_pnat_strict_mono.lt_iff_lt\n\n@[simp] theorem succ_pnat_le_succ_pnat {m n : \u2115} : m.succ_pnat \u2264 n.succ_pnat \u2194 m \u2264 n :=\nsucc_pnat_strict_mono.le_iff_le\n\ntheorem succ_pnat_injective : function.injective succ_pnat := succ_pnat_strict_mono.injective\n\n@[simp] theorem succ_pnat_inj {n m : \u2115} : succ_pnat n = succ_pnat m \u2194 n = m :=\nsucc_pnat_injective.eq_iff\n\nend nat\n\nnamespace pnat\n\nopen nat\n\n/-- We now define a long list of structures on \u2115+ induced by\n similar structures on \u2115. Most of these behave in a completely\n obvious way, but there are a few things to be said about\n subtraction, division and powers.\n-/\n\n@[simp, norm_cast] lemma coe_inj {m n : \u2115+} : (m : \u2115) = n \u2194 m = n := set_coe.ext_iff\n\n@[simp, norm_cast] theorem add_coe (m n : \u2115+) : ((m + n : \u2115+) : \u2115) = m + n := rfl\n\n/-- `pnat.coe` promoted to an `add_hom`, that is, a morphism which preserves addition. -/\ndef coe_add_hom : add_hom \u2115+ \u2115 :=\n{ to_fun := coe,\n  map_add' := add_coe }\n\ninstance : covariant_class \u2115+ \u2115+ (+) (\u2264) := positive.covariant_class_add_le\ninstance : covariant_class \u2115+ \u2115+ (+) (<) := positive.covariant_class_add_lt\ninstance : contravariant_class \u2115+ \u2115+ (+) (\u2264) := positive.contravariant_class_add_le\ninstance : contravariant_class \u2115+ \u2115+ (+) (<) := positive.contravariant_class_add_lt\n\n/-- An equivalence between `\u2115+` and `\u2115` given by `pnat.nat_pred` and `nat.succ_pnat`. -/\n@[simps { fully_applied := ff }] def _root_.equiv.pnat_equiv_nat : \u2115+ \u2243 \u2115 :=\n{ to_fun := pnat.nat_pred,\n  inv_fun := nat.succ_pnat,\n  left_inv := succ_pnat_nat_pred,\n  right_inv := nat.nat_pred_succ_pnat }\n\n/-- The order isomorphism between \u2115 and \u2115+ given by `succ`. -/\n@[simps apply { fully_applied := ff }] def _root_.order_iso.pnat_iso_nat : \u2115+ \u2243o \u2115 :=\n{ to_equiv := equiv.pnat_equiv_nat,\n  map_rel_iff' := \u03bb _ _, nat_pred_le_nat_pred }\n\n@[simp] lemma _root_.order_iso.pnat_iso_nat_symm_apply :\n  \u21d1order_iso.pnat_iso_nat.symm = nat.succ_pnat := rfl\n\ntheorem lt_add_one_iff : \u2200 {a b : \u2115+}, a < b + 1 \u2194 a \u2264 b :=\n\u03bb a b, nat.lt_add_one_iff\n\ntheorem add_one_le_iff : \u2200 {a b : \u2115+}, a + 1 \u2264 b \u2194 a < b :=\n\u03bb a b, nat.add_one_le_iff\n\ninstance : order_bot \u2115+ :=\n{ bot := 1,\n  bot_le := \u03bb a, a.property }\n\n@[simp] lemma bot_eq_one : (\u22a5 : \u2115+) = 1 := rfl\n\n-- Some lemmas that rewrite `pnat.mk n h`, for `n` an explicit numeral, into explicit numerals.\n@[simp] lemma mk_bit0 (n) {h} : (\u27e8bit0 n, h\u27e9 : \u2115+) = (bit0 \u27e8n, pos_of_bit0_pos h\u27e9 : \u2115+) := rfl\n@[simp] lemma mk_bit1 (n) {h} {k} : (\u27e8bit1 n, h\u27e9 : \u2115+) = (bit1 \u27e8n, k\u27e9 : \u2115+) := rfl\n\n-- Some lemmas that rewrite inequalities between explicit numerals in `\u2115+`\n-- into the corresponding inequalities in `\u2115`.\n-- TODO: perhaps this should not be attempted by `simp`,\n-- and instead we should expect `norm_num` to take care of these directly?\n-- TODO: these lemmas are perhaps incomplete:\n-- * 1 is not represented as a bit0 or bit1\n-- * strict inequalities?\n@[simp] lemma bit0_le_bit0 (n m : \u2115+) : (bit0 n) \u2264 (bit0 m) \u2194 (bit0 (n : \u2115)) \u2264 (bit0 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit0_le_bit1 (n m : \u2115+) : (bit0 n) \u2264 (bit1 m) \u2194 (bit0 (n : \u2115)) \u2264 (bit1 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit1_le_bit0 (n m : \u2115+) : (bit1 n) \u2264 (bit0 m) \u2194 (bit1 (n : \u2115)) \u2264 (bit0 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit1_le_bit1 (n m : \u2115+) : (bit1 n) \u2264 (bit1 m) \u2194 (bit1 (n : \u2115)) \u2264 (bit1 (m : \u2115)) :=\niff.rfl\n\n@[simp, norm_cast] theorem mul_coe (m n : \u2115+) : ((m * n : \u2115+) : \u2115) = m * n := rfl\n\n/-- `pnat.coe` promoted to a `monoid_hom`. -/\ndef coe_monoid_hom : \u2115+ \u2192* \u2115 :=\n{ to_fun := coe,\n  map_one' := one_coe,\n  map_mul' := mul_coe }\n\n@[simp] lemma coe_coe_monoid_hom : (coe_monoid_hom : \u2115+ \u2192 \u2115) = coe := rfl\n\n@[simp] lemma le_one_iff {n : \u2115+} : n \u2264 1 \u2194 n = 1 := le_bot_iff\n\nlemma lt_add_left (n m : \u2115+) : n < m + n := lt_add_of_pos_left _ m.2\n\nlemma lt_add_right (n m : \u2115+) : n < n + m := (lt_add_left n m).trans_eq (add_comm _ _)\n\n@[simp, norm_cast] lemma coe_bit0 (a : \u2115+) : ((bit0 a : \u2115+) : \u2115) = bit0 (a : \u2115) := rfl\n@[simp, norm_cast] lemma coe_bit1 (a : \u2115+) : ((bit1 a : \u2115+) : \u2115) = bit1 (a : \u2115) := rfl\n\n@[simp, norm_cast] theorem pow_coe (m : \u2115+) (n : \u2115) : ((m ^ n : \u2115+) : \u2115) = (m : \u2115) ^ n :=\nrfl\n\n/-- Subtraction a - b is defined in the obvious way when\n  a > b, and by a - b = 1 if a \u2264 b.\n-/\ninstance : has_sub \u2115+ := \u27e8\u03bb a b, to_pnat' (a - b : \u2115)\u27e9\n\ntheorem sub_coe (a b : \u2115+) : ((a - b : \u2115+) : \u2115) = ite (b < a) (a - b : \u2115) 1 :=\nbegin\n  change (to_pnat' _ : \u2115) = ite _ _ _,\n  split_ifs with h,\n  { exact to_pnat'_coe (tsub_pos_of_lt h) },\n  { rw tsub_eq_zero_iff_le.mpr (le_of_not_gt h : (a : \u2115) \u2264 b), refl }\nend\n\ntheorem add_sub_of_lt {a b : \u2115+} : a < b \u2192 a + (b - a) = b :=\n \u03bb h, eq $ by { rw [add_coe, sub_coe, if_pos h],\n                exact add_tsub_cancel_of_le h.le }\n\n/-- If `n : \u2115+` is different from `1`, then it is the successor of some `k : \u2115+`. -/\nlemma exists_eq_succ_of_ne_one : \u2200 {n : \u2115+} (h1 : n \u2260 1), \u2203 (k : \u2115+), n = k + 1\n| \u27e81, _\u27e9 h1 := false.elim $ h1 rfl\n| \u27e8n+2, _\u27e9 _ := \u27e8\u27e8n+1, by simp\u27e9, rfl\u27e9\n\n/-- Strong induction on `\u2115+`, with `n = 1` treated separately. -/\ndef case_strong_induction_on {p : \u2115+ \u2192 Sort*} (a : \u2115+) (hz : p 1)\n  (hi : \u2200 n, (\u2200 m, m \u2264 n \u2192 p m) \u2192 p (n + 1)) : p a :=\nbegin\n  apply strong_induction_on a,\n  rintro \u27e8k, kprop\u27e9 hk,\n  cases k with k,\n  { exact (lt_irrefl 0 kprop).elim },\n  cases k with k,\n  { exact hz },\n  exact hi \u27e8k.succ, nat.succ_pos _\u27e9 (\u03bb m hm, hk _ (lt_succ_iff.2 hm)),\nend\n\n/-- An induction principle for `\u2115+`: it takes values in `Sort*`, so it applies also to Types,\nnot only to `Prop`. -/\n@[elab_as_eliminator]\ndef rec_on (n : \u2115+) {p : \u2115+ \u2192 Sort*} (p1 : p 1) (hp : \u2200 n, p n \u2192 p (n + 1)) : p n :=\nbegin\n  rcases n with \u27e8n, h\u27e9,\n  induction n with n IH,\n  { exact absurd h dec_trivial },\n  { cases n with n,\n    { exact p1 },\n    { exact hp _ (IH n.succ_pos) } }\nend\n\n@[simp] theorem rec_on_one {p} (p1 hp) : @pnat.rec_on 1 p p1 hp = p1 := rfl\n\n@[simp] theorem rec_on_succ (n : \u2115+) {p : \u2115+ \u2192 Sort*} (p1 hp) :\n  @pnat.rec_on (n + 1) p p1 hp = hp n (@pnat.rec_on n p p1 hp) :=\nby { cases n with n h, cases n; [exact absurd h dec_trivial, refl] }\n\nlemma mod_div_aux_spec : \u2200 (k : \u2115+) (r q : \u2115) (h : \u00ac (r = 0 \u2227 q = 0)),\n (((mod_div_aux k r q).1 : \u2115) + k * (mod_div_aux k r q).2 = (r + k * q))\n| k 0 0 h := (h \u27e8rfl, rfl\u27e9).elim\n| k 0 (q + 1) h := by\n{ change (k : \u2115) + (k : \u2115) * (q + 1).pred = 0 + (k : \u2115) * (q + 1),\n  rw [nat.pred_succ, nat.mul_succ, zero_add, add_comm]}\n| k (r + 1) q h := rfl\n\ntheorem mod_add_div (m k : \u2115+) : ((mod m k) + k * (div m k) : \u2115) = m :=\nbegin\n  let h\u2080 := nat.mod_add_div (m : \u2115) (k : \u2115),\n  have : \u00ac ((m : \u2115) % (k : \u2115) = 0 \u2227 (m : \u2115) / (k : \u2115) = 0),\n  by { rintro \u27e8hr, hq\u27e9, rw [hr, hq, mul_zero, zero_add] at h\u2080,\n       exact (m.ne_zero h\u2080.symm).elim },\n  have := mod_div_aux_spec k ((m : \u2115) % (k : \u2115)) ((m : \u2115) / (k : \u2115)) this,\n  exact (this.trans h\u2080),\nend\n\ntheorem div_add_mod (m k : \u2115+) : (k * (div m k) + mod m k : \u2115) = m :=\n(add_comm _ _).trans (mod_add_div _ _)\n\nlemma mod_add_div' (m k : \u2115+) : ((mod m k) + (div m k) * k : \u2115) = m :=\nby { rw mul_comm, exact mod_add_div _ _ }\n\nlemma div_add_mod' (m k : \u2115+) : ((div m k) * k + mod m k : \u2115) = m :=\nby { rw mul_comm, exact div_add_mod _ _ }\n\ntheorem mod_le (m k : \u2115+) : mod m k \u2264 m \u2227 mod m k \u2264 k :=\nbegin\n  change ((mod m k) : \u2115) \u2264 (m : \u2115) \u2227 ((mod m k) : \u2115) \u2264 (k : \u2115),\n  rw [mod_coe], split_ifs,\n  { have hm : (m : \u2115) > 0 := m.pos,\n    rw [\u2190 nat.mod_add_div (m : \u2115) (k : \u2115), h, zero_add] at hm \u22a2,\n    by_cases h' : ((m : \u2115) / (k : \u2115)) = 0,\n    { rw [h', mul_zero] at hm, exact (lt_irrefl _ hm).elim},\n    { let h' := nat.mul_le_mul_left (k : \u2115)\n             (nat.succ_le_of_lt (nat.pos_of_ne_zero h')),\n      rw [mul_one] at h', exact \u27e8h', le_refl (k : \u2115)\u27e9 } },\n  { exact \u27e8nat.mod_le (m : \u2115) (k : \u2115), (nat.mod_lt (m : \u2115) k.pos).le\u27e9 }\nend\n\ntheorem dvd_iff {k m : \u2115+} : k \u2223 m \u2194 (k : \u2115) \u2223 (m : \u2115) :=\nbegin\n  split; intro h, rcases h with \u27e8_, rfl\u27e9, apply dvd_mul_right,\n  rcases h with \u27e8a, h\u27e9, cases a, { contrapose h, apply ne_zero, },\n  use a.succ, apply nat.succ_pos, rw [\u2190 coe_inj, h, mul_coe, mk_coe],\nend\n\ntheorem dvd_iff' {k m : \u2115+} : k \u2223 m \u2194 mod m k = k :=\nbegin\n  rw dvd_iff,\n  rw [nat.dvd_iff_mod_eq_zero], split,\n  { intro h, apply eq, rw [mod_coe, if_pos h] },\n  { intro h, by_cases h' : (m : \u2115) % (k : \u2115) = 0,\n    { exact h'},\n    { replace h : ((mod m k) : \u2115) = (k : \u2115) := congr_arg _ h,\n      rw [mod_coe, if_neg h'] at h,\n      exact ((nat.mod_lt (m : \u2115) k.pos).ne h).elim } }\nend\n\nlemma le_of_dvd {m n : \u2115+} : m \u2223 n \u2192 m \u2264 n :=\nby { rw dvd_iff', intro h, rw \u2190 h, apply (mod_le n m).left }\n\ntheorem mul_div_exact {m k : \u2115+} (h : k \u2223 m) : k * (div_exact m k) = m :=\nbegin\n apply eq, rw [mul_coe],\n change (k : \u2115) * (div m k).succ = m,\n rw [\u2190 div_add_mod m k, dvd_iff'.mp h, nat.mul_succ]\nend\n\n\n\ntheorem dvd_one_iff (n : \u2115+) : n \u2223 1 \u2194 n = 1 :=\n \u27e8\u03bb h, dvd_antisymm h (one_dvd n), \u03bb h, h.symm \u25b8 (dvd_refl 1)\u27e9\n\nlemma pos_of_div_pos {n : \u2115+} {a : \u2115} (h : a \u2223 n) : 0 < a :=\nbegin\n  apply pos_iff_ne_zero.2,\n  intro hzero,\n  rw hzero at h,\n  exact pnat.ne_zero n (eq_zero_of_zero_dvd h)\nend\n\nend pnat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/pnat/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7188456496906039}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport logic.equiv.defs\nimport tactic.norm_fin\n\n/-!\n# `norm_swap`\n\nEvaluating `swap x y z` for numerals `x y z` that are `\u2115`, `\u2124`, or `\u211a`, via a `norm_num` plugin.\nTerms are passed to `eval`, quickly failing if not of the form `swap x y z`.\nThe expressions for numerals `x y z` are converted to `nat`, and then compared.\nBased on equality of these `nat`s, equality proofs are generated using either\n`equiv.swap_apply_left`, `equiv.swap_apply_right`, or `swap_apply_of_ne_of_ne`.\n-/\n\nopen equiv tactic expr\n\nopen norm_num\n\nnamespace norm_swap\n\n/--\nA `norm_num` plugin for normalizing `equiv.swap a b c`\nwhere `a b c` are numerals of `\u2115`, `\u2124`, `\u211a` or `fin n`.\n\n```\nexample : equiv.swap 1 2 1 = 2 := by norm_num\n```\n-/\n@[norm_num] meta def eval : expr \u2192 tactic (expr \u00d7 expr) := \u03bb e, do\n  (swapt, fun_ty, coe_fn_inst, fexpr, c) \u2190 e.match_app_coe_fn\n    <|> fail \"did not get an app coe_fn expr\",\n  guard (fexpr.get_app_fn.const_name = ``equiv.swap) <|> fail \"coe_fn not of equiv.swap\",\n  [\u03b1, deceq_inst, a, b] \u2190 pure fexpr.get_app_args <|>\n    fail \"swap did not have exactly two args applied\",\n  na \u2190 a.to_rat <|> (do (fa, _) \u2190 norm_fin.eval_fin_num a, fa.to_rat),\n  nb \u2190 b.to_rat <|> (do (fb, _) \u2190 norm_fin.eval_fin_num b, fb.to_rat),\n  nc \u2190 c.to_rat <|> (do (fc, _) \u2190 norm_fin.eval_fin_num c, fc.to_rat),\n  if nc = na then do\n    p \u2190 mk_mapp `equiv.swap_apply_left [\u03b1, deceq_inst, a, b],\n    pure (b, p)\n  else if nc = nb then do\n    p \u2190 mk_mapp `equiv.swap_apply_right [\u03b1, deceq_inst, a, b],\n    pure (a, p)\n  else do\n    nic \u2190 mk_instance_cache \u03b1,\n    hca \u2190 (prod.snd <$> prove_ne nic c a nc na) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c a, pure p),\n    hcb \u2190 (prod.snd <$> prove_ne nic c b nc nb) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c b, pure p),\n    p \u2190 mk_mapp `equiv.swap_apply_of_ne_of_ne [\u03b1, deceq_inst, a, b, c, hca, hcb],\n    pure (c, p)\n\nend norm_swap\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/tactic/norm_swap.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874624, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7187909768555615}}
{"text": "import MyNat\nimport MyNat.multiplication_world\nimport MyNat.advanced_addition_world\nimport MyNat.advanced_proposition_world\n\nopen MyNat\n\ntheorem mul_pos (a b : \u2115) : \n  a \u2260 0 \u2192 b \u2260 0 \u2192 a * b \u2260 0 := by\n  intro nea neb\n  cases a with \n  | zero => \n    exact False.elim nea.irrefl\n  | succ a' => \n    cases b with \n    | zero => exact False.elim neb.irrefl\n    | succ b' => \n      rewrite [succ_mul, add_comm, succ_add]\n      exact succ_ne_zero _\n\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero (a b : \u2115) \n  (h : a * b = 0) : a = 0 \u2228 b = 0 := by\n  cases a with\n  | zero => \n    rewrite [zero_mul] at h\n    exact Or.inl h\n  | succ a' => \n    cases b with\n    | zero => \n      rewrite [mul_zero] at h\n      exact Or.inr h\n    | succ b' => \n      let nea := succ_ne_zero a'\n      let neb := succ_ne_zero b'\n      let f := mul_pos (succ a') (succ b') nea neb\n      exact (False.elim (Ne.elim f h))\n\ntheorem mul_eq_zero_iff (a b : \u2115) :\n  a * b = 0 \u2194 a = 0 \u2228 b = 0 := by\n  constructor \n  { exact eq_zero_or_eq_zero_of_mul_eq_zero a b }\n  { intro h\n  exact (\n    h.elim\n    (fun a0 => by\n      rewrite [a0, zero_equal_numeral, zero_mul]\n      rfl\n\n    )\n    (fun b0 => by\n      rewrite [b0, zero_equal_numeral, mul_zero]\n      rfl\n    )\n  )\n  }\n\ntheorem mul_left_cancel (a b c : \u2115) \n  (ha : a \u2260 0) : a * b = a * c \u2192 b = c := by\n  intro h\n  induction c generalizing b with \n  | zero => \n    rewrite [mul_zero] at h\n    let f := eq_zero_or_eq_zero_of_mul_eq_zero _ _ h\n    exact (\n      Or.elim f\n      (fun a0 => False.elim (ha.elim a0))\n      id\n    )\n  | succ c' ih => \n    induction b with \n    | zero =>  \n      rewrite [mul_zero] at h\n      let f := eq_zero_or_eq_zero_of_mul_eq_zero _ _ h.symm\n      exact (\n        Or.elim f\n        (fun a0 => False.elim (ha.elim a0))\n        Eq.symm\n      )\n    | succ b' _ => \n      rewrite [mul_succ, mul_succ] at h\n      let f := add_left_cancel _ _ _ h\n      let f' := (ih b') f\n      rewrite [f']\n      rfl", "meta": {"author": "alexkassil", "repo": "natural_number_game_lean4", "sha": "69b60b72139403a64508494441d6c561c24ce66d", "save_path": "github-repos/lean/alexkassil-natural_number_game_lean4", "path": "github-repos/lean/alexkassil-natural_number_game_lean4/natural_number_game_lean4-69b60b72139403a64508494441d6c561c24ce66d/MyNat/advanced_multiplication_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7187909725631614}}
{"text": "/-\nCopyright (c) 2019 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\nimport data.real.cau_seq\nimport topology.uniform_space.basic\n\n/-!\n# Uniform structure induced by an absolute value\n\nWe build a uniform space structure on a commutative ring `R` equipped with an absolute value into\na linear ordered field `\ud835\udd5c`. Of course in the case `R` is `\u211a`, `\u211d` or `\u2102` and\n`\ud835\udd5c = \u211d`, we get the same thing as the metric space construction, and the general construction\nfollows exactly the same path.\n\n## Implementation details\n\nNote that we import `data.real.cau_seq` because this is where absolute values are defined, but\nthe current file does not depend on real numbers. TODO: extract absolute values from that\n`data.real` folder.\n\n## References\n\n* [N. Bourbaki, *Topologie g\u00e9n\u00e9rale*][bourbaki1966]\n\n## Tags\n\nabsolute value, uniform spaces\n-/\n\nopen set function filter uniform_space\nopen_locale filter\n\nnamespace is_absolute_value\nvariables {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c]\nvariables {R : Type*} [comm_ring R] (abv : R \u2192 \ud835\udd5c) [is_absolute_value abv]\n\n/-- The uniformity coming from an absolute value. -/\ndef uniform_space_core : uniform_space.core R :=\n{ uniformity := (\u2a05 \u03b5>0, \ud835\udcdf {p:R\u00d7R | abv (p.2 - p.1) < \u03b5}),\n  refl := le_infi $ assume \u03b5, le_infi $ assume \u03b5_pos, principal_mono.2\n    (\u03bb \u27e8x, y\u27e9 h, by simpa [show x = y, from h, abv_zero abv]),\n  symm := tendsto_infi.2 $ assume \u03b5, tendsto_infi.2 $ assume h,\n    tendsto_infi' \u03b5 $ tendsto_infi' h $ tendsto_principal_principal.2 $ \u03bb \u27e8x, y\u27e9 h,\n      have h : abv (y - x) < \u03b5, by simpa [-sub_eq_add_neg] using h,\n      by rwa abv_sub abv at h,\n  comp := le_infi $ assume \u03b5, le_infi $ assume h, lift'_le\n    (mem_infi_sets (\u03b5 / 2) $ mem_infi_sets (div_pos h zero_lt_two) (subset.refl _)) $\n    have \u2200 (a b c : R), abv (c-a) < \u03b5 / 2 \u2192 abv (b-c) < \u03b5 / 2 \u2192 abv (b-a) < \u03b5,\n      from assume a b c hac hcb,\n       calc abv (b - a) \u2264 _ : abv_sub_le abv b c a\n        ... = abv (c - a) + abv (b - c) : add_comm _ _\n        ... < \u03b5 / 2 + \u03b5 / 2 : add_lt_add hac hcb\n        ... = \u03b5 : by rw [div_add_div_same, add_self_div_two],\n    by simpa [comp_rel] }\n\n/-- The uniform structure coming from an absolute value. -/\ndef uniform_space : uniform_space R :=\nuniform_space.of_core (uniform_space_core abv)\n\ntheorem mem_uniformity {s : set (R\u00d7R)} :\n  s \u2208 (uniform_space_core abv).uniformity \u2194\n  (\u2203\u03b5>0, \u2200{a b:R}, abv (b - a) < \u03b5 \u2192 (a, b) \u2208 s) :=\nbegin\n  suffices : s \u2208 (\u2a05 \u03b5: {\u03b5 : \ud835\udd5c // \u03b5 > 0}, \ud835\udcdf {p:R\u00d7R | abv (p.2 - p.1) < \u03b5.val}) \u2194 _,\n  { rw infi_subtype at this,\n    exact this },\n  rw mem_infi,\n  { simp [subset_def] },\n  { rintros \u27e8r, hr\u27e9 \u27e8p, hp\u27e9,\n    exact \u27e8\u27e8min r p, lt_min hr hp\u27e9, by simp [lt_min_iff, (\u2265)] {contextual := tt}\u27e9, },\nend\n\nend is_absolute_value\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/topology/uniform_space/absolute_value.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7187909574936054}}
{"text": "/-\nCopyright (c) 2021 Justus Springer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Justus Springer\n-/\nimport algebra.category.Group.basic\nimport algebra.category.Mon.filtered_colimits\n\n/-!\n# The forgetful functor from (commutative) (additive) groups preserves filtered colimits.\n\nForgetful functors from algebraic categories usually don't preserve colimits. However, they tend\nto preserve _filtered_ colimits.\n\nIn this file, we start with a small filtered category `J` and a functor `F : J \u2964 Group`.\nWe show that the colimit of `F \u22d9 forget\u2082 Group Mon` (in `Mon`) carries the structure of a group,\nthereby showing that the forgetful functor `forget\u2082 Group Mon` preserves filtered colimits. In\nparticular, this implies that `forget Group` preserves filtered colimits. Similarly for `AddGroup`,\n`CommGroup` and `AddCommGroup`.\n\n-/\n\nuniverse v\n\nnoncomputable theory\nopen_locale classical\n\nopen category_theory\nopen category_theory.limits\nopen category_theory.is_filtered (renaming max \u2192 max') -- avoid name collision with `_root_.max`.\n\nnamespace Group.filtered_colimits\n\nsection\n\nopen Mon.filtered_colimits (colimit_one_eq colimit_mul_mk_eq)\n\n-- We use parameters here, mainly so we can have the abbreviations `G` and `G.mk` below, without\n-- passing around `F` all the time.\nparameters {J : Type v} [small_category J] [is_filtered J] (F : J \u2964 Group.{v})\n\n/--\nThe colimit of `F \u22d9 forget\u2082 Group Mon` in the category `Mon`.\nIn the following, we will show that this has the structure of a group.\n-/\n@[to_additive \"The colimit of `F \u22d9 forget\u2082 AddGroup AddMon` in the category `AddMon`.\nIn the following, we will show that this has the structure of an additive group.\"]\nabbreviation G : Mon := Mon.filtered_colimits.colimit (F \u22d9 forget\u2082 Group Mon)\n\n/-- The canonical projection into the colimit, as a quotient type. -/\n@[to_additive \"The canonical projection into the colimit, as a quotient type.\"]\nabbreviation G.mk : (\u03a3 j, F.obj j) \u2192 G := quot.mk (types.quot.rel (F \u22d9 forget Group))\n\n@[to_additive]\nlemma G.mk_eq (x y : \u03a3 j, F.obj j)\n  (h : \u2203 (k : J) (f : x.1 \u27f6 k) (g : y.1 \u27f6 k), F.map f x.2 = F.map g y.2) :\n  G.mk x = G.mk y :=\nquot.eqv_gen_sound (types.filtered_colimit.eqv_gen_quot_rel_of_rel (F \u22d9 forget Group) x y h)\n\n/-- The \"unlifted\" version of taking inverses in the colimit. -/\n@[to_additive \"The \\\"unlifted\\\" version of negation in the colimit.\"]\ndef colimit_inv_aux (x : \u03a3 j, F.obj j) : G :=\nG.mk \u27e8x.1, x.2 \u207b\u00b9\u27e9\n\n@[to_additive]\nlemma colimit_inv_aux_eq_of_rel (x y : \u03a3 j, F.obj j)\n  (h : types.filtered_colimit.rel (F \u22d9 forget Group) x y) :\n  colimit_inv_aux x = colimit_inv_aux y :=\nbegin\n  apply G.mk_eq,\n  obtain \u27e8k, f, g, hfg\u27e9 := h,\n  use [k, f, g],\n  rw [monoid_hom.map_inv, monoid_hom.map_inv, inv_inj],\n  exact hfg,\nend\n\n/-- Taking inverses in the colimit. See also `colimit_inv_aux`. -/\n@[to_additive \"Negation in the colimit. See also `colimit_neg_aux`.\"]\ninstance colimit_has_inv : has_inv G :=\n{ inv := \u03bb x, begin\n   refine quot.lift (colimit_inv_aux F) _ x,\n  intros x y h,\n  apply colimit_inv_aux_eq_of_rel,\n  apply types.filtered_colimit.rel_of_quot_rel,\n  exact h,\nend }\n\n@[simp, to_additive]\nlemma colimit_inv_mk_eq (x : \u03a3 j, F.obj j) : (G.mk x) \u207b\u00b9 = G.mk \u27e8x.1, x.2 \u207b\u00b9\u27e9 := rfl\n\n@[to_additive]\ninstance colimit_group : group G :=\n{ mul_left_inv := \u03bb x, begin\n    apply quot.induction_on x, clear x, intro x,\n    cases x with j x,\n    erw [colimit_inv_mk_eq, colimit_mul_mk_eq (F \u22d9 forget\u2082 Group Mon) \u27e8j, _\u27e9 \u27e8j, _\u27e9 j (\ud835\udfd9 j) (\ud835\udfd9 j),\n      colimit_one_eq (F \u22d9 forget\u2082 Group Mon) j],\n    dsimp,\n    simp only [category_theory.functor.map_id, id_apply, mul_left_inv],\n  end,\n  .. G.monoid,\n  .. colimit_has_inv }\n\n/-- The bundled group giving the filtered colimit of a diagram. -/\n@[to_additive \"The bundled additive group giving the filtered colimit of a diagram.\"]\ndef colimit : Group := Group.of G\n\n/-- The cocone over the proposed colimit group. -/\n@[to_additive \"The cocone over the proposed colimit additive group.\"]\ndef colimit_cocone : cocone F :=\n{ X := colimit,\n  \u03b9 := { ..(Mon.filtered_colimits.colimit_cocone (F \u22d9 forget\u2082 Group Mon)).\u03b9 } }\n\n/-- The proposed colimit cocone is a colimit in `Group`. -/\n@[to_additive \"The proposed colimit cocone is a colimit in `AddGroup`.\"]\ndef colimit_cocone_is_colimit : is_colimit colimit_cocone :=\n{ desc := \u03bb t, Mon.filtered_colimits.colimit_desc (F \u22d9 forget\u2082 Group Mon)\n    ((forget\u2082 Group Mon).map_cocone t),\n  fac' := \u03bb t j, monoid_hom.coe_inj $\n    (types.colimit_cocone_is_colimit (F \u22d9 forget Group)).fac ((forget Group).map_cocone t) j,\n  uniq' := \u03bb t m h, monoid_hom.coe_inj $\n    (types.colimit_cocone_is_colimit (F \u22d9 forget Group)).uniq ((forget Group).map_cocone t) m\n    ((\u03bb j, funext $ \u03bb x, monoid_hom.congr_fun (h j) x)) }\n\n@[to_additive forget\u2082_AddMon_preserves_filtered_colimits]\ninstance forget\u2082_Mon_preserves_filtered_colimits :\n  preserves_filtered_colimits (forget\u2082 Group Mon.{v}) :=\n{ preserves_filtered_colimits := \u03bb J _ _, by exactI\n  { preserves_colimit := \u03bb F, preserves_colimit_of_preserves_colimit_cocone\n      (colimit_cocone_is_colimit F)\n      (Mon.filtered_colimits.colimit_cocone_is_colimit (F \u22d9 forget\u2082 Group Mon.{v})) } }\n\n@[to_additive]\ninstance forget_preserves_filtered_colimits : preserves_filtered_colimits (forget Group) :=\nlimits.comp_preserves_filtered_colimits (forget\u2082 Group Mon) (forget Mon)\n\nend\n\nend Group.filtered_colimits\n\n\nnamespace CommGroup.filtered_colimits\n\nsection\n\n-- We use parameters here, mainly so we can have the abbreviation `G` below, without\n-- passing around `F` all the time.\nparameters {J : Type v} [small_category J] [is_filtered J] (F : J \u2964 CommGroup.{v})\n\n/--\nThe colimit of `F \u22d9 forget\u2082 CommGroup Group` in the category `Group`.\nIn the following, we will show that this has the structure of a _commutative_ group.\n-/\n@[to_additive \"The colimit of `F \u22d9 forget\u2082 AddCommGroup AddGroup` in the category `AddGroup`.\nIn the following, we will show that this has the structure of a _commutative_ additive group.\"]\nabbreviation G : Group := Group.filtered_colimits.colimit (F \u22d9 forget\u2082 CommGroup Group.{v})\n\n@[to_additive]\ninstance colimit_comm_group : comm_group G :=\n{ ..G.group,\n  ..CommMon.filtered_colimits.colimit_comm_monoid (F \u22d9 forget\u2082 CommGroup CommMon.{v}) }\n\n/-- The bundled commutative group giving the filtered colimit of a diagram. -/\n@[to_additive \"The bundled additive commutative group giving the filtered colimit of a diagram.\"]\ndef colimit : CommGroup := CommGroup.of G\n\n/-- The cocone over the proposed colimit commutative group. -/\n@[to_additive \"The cocone over the proposed colimit additive commutative group.\"]\ndef colimit_cocone : cocone F :=\n{ X := colimit,\n  \u03b9 := { ..(Group.filtered_colimits.colimit_cocone (F \u22d9 forget\u2082 CommGroup Group)).\u03b9 } }\n\n/-- The proposed colimit cocone is a colimit in `CommGroup`. -/\n@[to_additive \"The proposed colimit cocone is a colimit in `AddCommGroup`.\"]\ndef colimit_cocone_is_colimit : is_colimit colimit_cocone :=\n{ desc := \u03bb t,\n  (Group.filtered_colimits.colimit_cocone_is_colimit (F \u22d9 forget\u2082 CommGroup Group.{v})).desc\n    ((forget\u2082 CommGroup Group.{v}).map_cocone t),\n  fac' := \u03bb t j, monoid_hom.coe_inj $\n    (types.colimit_cocone_is_colimit (F \u22d9 forget CommGroup)).fac\n    ((forget CommGroup).map_cocone t) j,\n  uniq' := \u03bb t m h, monoid_hom.coe_inj $\n    (types.colimit_cocone_is_colimit (F \u22d9 forget CommGroup)).uniq\n    ((forget CommGroup).map_cocone t) m ((\u03bb j, funext $ \u03bb x, monoid_hom.congr_fun (h j) x)) }\n\n@[to_additive forget\u2082_AddGroup_preserves_filtered_colimits]\ninstance forget\u2082_Group_preserves_filtered_colimits :\n  preserves_filtered_colimits (forget\u2082 CommGroup Group.{v}) :=\n{ preserves_filtered_colimits := \u03bb J _ _, by exactI\n  { preserves_colimit := \u03bb F, preserves_colimit_of_preserves_colimit_cocone\n      (colimit_cocone_is_colimit F)\n      (Group.filtered_colimits.colimit_cocone_is_colimit (F \u22d9 forget\u2082 CommGroup Group.{v})) } }\n\n@[to_additive]\ninstance forget_preserves_filtered_colimits : preserves_filtered_colimits (forget CommGroup) :=\nlimits.comp_preserves_filtered_colimits (forget\u2082 CommGroup Group) (forget Group)\n\nend\n\nend CommGroup.filtered_colimits\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/category/Group/filtered_colimits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7187774470568984}}
{"text": "import Lean4Axiomatic.Integer.Impl.Difference.Addition\n\nnamespace Lean4Axiomatic.Integer.Impl.Difference\n\n/-! ## Negation of formal differences -/\n\nvariable {\u2115 : Type} [Natural \u2115]\n\nopen Signed (Positive)\n\n/--\nNegation of differences.\n\n**Definition intuition**: It's easiest to use the \"directed gap\" interpretation\nof differences to see this. If `a\u2014\u2014b` represents the process of traveling from\n`a` to `b`, then its negation should represent the opposite process: traveling\nfrom `b` to `a`.\n-/\ndef neg : Difference \u2115 \u2192 Difference \u2115\n| a\u2014\u2014b => b\u2014\u2014a\n\ninstance negOp : Neg (Difference \u2115) := {\n  neg := neg\n}\n\n/--\nNegating two equivalent differences preserves their equivalence.\n\n**Property intuition**: For negation to make sense as an operation (i.e., have\na consistent definition as a function) on integers, this property must be true.\n\n**Proof intuition**: Nothing too insightful here, it's just expanding the\ndefinitions of negation and equality and performing some algebra.\n-/\ntheorem neg_subst {a\u2081 a\u2082 : Difference \u2115} : a\u2081 \u2243 a\u2082 \u2192 -a\u2081 \u2243 -a\u2082 := by\n  revert a\u2081; intro (n\u2014\u2014m); revert a\u2082; intro (k\u2014\u2014j)\n  intro (_ : n\u2014\u2014m \u2243 k\u2014\u2014j)\n  show -(n\u2014\u2014m) \u2243 -(k\u2014\u2014j)\n  have : n + j \u2243 k + m := \u2039n\u2014\u2014m \u2243 k\u2014\u2014j\u203a\n  show m\u2014\u2014n \u2243 j\u2014\u2014k\n  show m + k \u2243 j + n\n  calc\n    m + k \u2243 _ := AA.comm\n    k + m \u2243 _ := Rel.symm \u2039n + j \u2243 k + m\u203a\n    n + j \u2243 _ := AA.comm\n    j + n \u2243 _ := Rel.refl\n\ndef neg_substitutive\n    : AA.Substitutive\u2081 (\u03b1 := Difference \u2115) (-\u00b7) (\u00b7 \u2243 \u00b7) (\u00b7 \u2243 \u00b7)\n    := {\n  subst\u2081 := neg_subst\n}\n\n/--\nThe negation of a natural number difference is that difference's left additive\ninverse.\n\n**Property intuition**: This property is pretty much why the integers are a\nuseful concept in the first place.\n\n**Proof intuition**: Negation swaps the elements of a difference, so adding a\ndifference to its negation will result in a difference with equal elements. All\ndifferences with equal elements represent zero.\n-/\ntheorem neg_invL {a : Difference \u2115} : (-a) + a \u2243 0 := by\n  revert a; intro (n\u2014\u2014m)\n  show -(n\u2014\u2014m) + n\u2014\u2014m \u2243 0\u2014\u20140\n  show m\u2014\u2014n + n\u2014\u2014m \u2243 0\u2014\u20140\n  show (m + n)\u2014\u2014(n + m) \u2243 0\u2014\u20140\n  show (m + n) + 0 \u2243 0 + (n + m)\n  apply Natural.add_swapped_zeros_eqv.mpr\n  show m + n \u2243 n + m\n  exact AA.comm\n\ndef neg_inverseL : AA.InverseOn Hand.L (\u03b1 := Difference \u2115) (-\u00b7) (\u00b7 + \u00b7) := {\n  inverse := neg_invL\n}\n\ndef neg_inverse : AA.Inverse (\u03b1 := Difference \u2115) (-\u00b7) (\u00b7 + \u00b7) := {\n  inverseL := neg_inverseL\n  inverseR := AA.inverseR_from_inverseL neg_inverseL\n}\n\ninstance negation : Negation (\u2115 := \u2115) (Difference \u2115) := {\n  negOp := negOp\n  neg_substitutive := neg_substitutive\n  neg_inverse := neg_inverse\n}\n\nend Lean4Axiomatic.Integer.Impl.Difference\n", "meta": {"author": "cruhland", "repo": "lean4-axiomatic", "sha": "6384bd38b8ba104530247d25456858775fe3c442", "save_path": "github-repos/lean/cruhland-lean4-axiomatic", "path": "github-repos/lean/cruhland-lean4-axiomatic/lean4-axiomatic-6384bd38b8ba104530247d25456858775fe3c442/Lean4Axiomatic/Integer/Impl/Difference/Negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.718777440823107}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport data.int.basic\nimport tactic.linarith\nimport tactic.linear_combination\n\n/- \n# Quotients in Lean \n\nUpon request, let's try to see how to construct number systems like the integers or the \nrational numbers in Lean. Note that this is again some mathematical way to do this, not the \nactual way, e.g. integers are defined as the disjoint union of \u2115 with itself, where the first \ncopy is interpreted as the usual natural numbers while the second copy is interpreted as the \nnumbers `1-n` where `n : \u2115`. Similarly, \u211a is contructed as pairs of coprime integers (p,q). \nThis makes them computationally a bit better behaved than our quotient way. \n\n## Equivalence relations in Lean\n\nLean knows what an equivalence relation is. It is a reflexive, symmetric and transitive relation. \nA relation on a set `X` is a function `X \u2192 X \u2192 Prop`, i.e. a function that takes two elements \nof a set `X` and outputs a truth value depending whether they are related or not. \n\n```\ndef reflexive := \u2200 x, x \u223c x\n\ndef symmetric := \u2200 \u2983x y\u2984, x \u223c y \u2192 y \u223c x\n\ndef transitive := \u2200 \u2983x y z\u2984, x \u223c y \u2192 y \u223c m z \u2192 x \u223c z\n\ndef equivalence := reflexive r \u2227 symmetric r \u2227 transitive r\n```\n\n-/\n\ndef R (r s : \u2115 \u00d7 \u2115) : Prop := \nr.1+s.2=s.1+r.2\n\nlemma R_def (r s : \u2115 \u00d7 \u2115) :\nR r s \u2194 r.1 + s.2 = s.1 + r.2 := \nbegin\n  sorry\nend\n\nlemma R_refl : reflexive R :=\nbegin\n  sorry\nend\n\nlemma R_symm : symmetric R :=\nbegin\n  sorry\nend \n\nlemma R_trans : transitive R :=\nbegin\n  /- The lemma add_right_inj could be helpful at some point. -/\n  sorry\nend \n\nlemma R_equiv : equivalence R :=\nbegin \n  sorry\nend\n\n\n/- A setoid on a Type is a relation together with the fact that \n  this relation is an equivalence relation. -/\ninstance s : setoid (\u2115 \u00d7 \u2115) :=\n_\n\nstructure int_plane_non_zero :=\n(fst : \u2124) (snd : \u2124) (non_zero : snd \u2260 0)\n\ndef S (r s : int_plane_non_zero) : Prop :=\nr.1 * s.2 = s.1 * r.2\n\nlemma S_def (r s : int_plane_non_zero) : \nS r s \u2194 r.1 * s.2 = s.1 * r.2 :=\nbegin\n  sorry\nend\n\nlemma S_refl : reflexive S :=\nbegin\n  sorry\nend\n\nlemma S_symm : symmetric S :=\nbegin\n  sorry\nend\n\nlemma S_trans : transitive S :=\nbegin\n  sorry\nend \n\nlemma S_equiv : equivalence S := \nbegin \n  sorry\nend\n\ninstance t : setoid (int_plane_non_zero) :=\n_", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/hard_mode/sheet07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7187774407663257}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport measure_theory.group.fundamental_domain\nimport measure_theory.integral.interval_integral\n\n/-!\n# Integrals of periodic functions\n\nIn this file we prove that `\u222b x in b..b + a, f x = \u222b x in c..c + a, f x` for any (not necessarily\nmeasurable) function periodic function with period `a`.\n-/\n\nopen set function measure_theory measure_theory.measure topological_space\nopen_locale measure_theory\n\nlemma is_add_fundamental_domain_Ioc {a : \u211d} (ha : 0 < a) (b : \u211d) (\u03bc : measure \u211d . volume_tac) :\n  is_add_fundamental_domain (add_subgroup.zmultiples a) (Ioc b (b + a)) \u03bc :=\nbegin\n  refine is_add_fundamental_domain.mk' measurable_set_Ioc (\u03bb x, _),\n  have : bijective (cod_restrict (\u03bb n : \u2124, n \u2022 a) (add_subgroup.zmultiples a) _),\n    from (equiv.of_injective (\u03bb n : \u2124, n \u2022 a) (zsmul_strict_mono_left ha).injective).bijective,\n  refine this.exists_unique_iff.2 _,\n  simpa only [add_comm x] using exists_unique_add_zsmul_mem_Ioc ha x b\nend\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E] [measurable_space E] [borel_space E]\n  [complete_space E] [second_countable_topology E]\n\nnamespace function\n\nnamespace periodic\n\n/-- An auxiliary lemma for a more general `function.periodic.interval_integral_add_eq`. -/\nlemma interval_integral_add_eq_of_pos {f : \u211d \u2192 E} {a : \u211d} (hf : periodic f a)\n  (ha : 0 < a) (b c : \u211d) : \u222b x in b..b + a, f x = \u222b x in c..c + a, f x :=\nbegin\n  haveI : encodable (add_subgroup.zmultiples a) := (countable_range _).to_encodable,\n  simp only [interval_integral.integral_of_le, ha.le, le_add_iff_nonneg_right],\n  haveI : vadd_invariant_measure (add_subgroup.zmultiples a) \u211d volume :=\n    \u27e8\u03bb c s hs, real.volume_preimage_add_left _ _\u27e9,\n  exact (is_add_fundamental_domain_Ioc ha b).set_integral_eq\n    (is_add_fundamental_domain_Ioc ha c) hf.map_vadd_zmultiples\nend\n  \n/-- If `f` is a periodic function with period `a`, then its integral over `[b, b + a]` does not\ndepend on `b`. -/\nlemma interval_integral_add_eq {f : \u211d \u2192 E} {a : \u211d} (hf : periodic f a)\n  (b c : \u211d) : \u222b x in b..b + a, f x = \u222b x in c..c + a, f x :=\nbegin\n  rcases lt_trichotomy 0 a with (ha|rfl|ha),\n  { exact hf.interval_integral_add_eq_of_pos ha b c },\n  { simp },\n  { rw [\u2190 neg_inj, \u2190 interval_integral.integral_symm, \u2190 interval_integral.integral_symm],\n    simpa only [\u2190 sub_eq_add_neg, add_sub_cancel]\n      using (hf.neg.interval_integral_add_eq_of_pos (neg_pos.2 ha) (b + a) (c + a)) }\nend\n\nend periodic\n\nend function\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/measure_theory/integral/periodic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7187774384612691}}
{"text": "/-\nCopyright (c) 2022 Vincent Beffara. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Vincent Beffara\n-/\nimport analysis.complex.removable_singularity\nimport analysis.calculus.series\n\n/-!\n# Locally uniform limits of holomorphic functions\n\nThis file gathers some results about locally uniform limits of holomorphic functions on an open\nsubset of the complex plane.\n\n## Main results\n\n* `tendsto_locally_uniformly_on.differentiable_on`: A locally uniform limit of holomorphic functions\n  is holomorphic.\n* `tendsto_locally_uniformly_on.deriv`: Locally uniform convergence implies locally uniform\n  convergence of the derivatives to the derivative of the limit.\n-/\n\nopen set metric measure_theory filter complex interval_integral\nopen_locale real topology\n\nvariables {E \u03b9 : Type*} [normed_add_comm_group E] [normed_space \u2102 E] [complete_space E]\n  {U K : set \u2102} {z : \u2102} {M r \u03b4 : \u211d} {\u03c6 : filter \u03b9} {F : \u03b9 \u2192 \u2102 \u2192 E} {f g : \u2102 \u2192 E}\n\nnamespace complex\n\nsection cderiv\n\n/-- A circle integral which coincides with `deriv f z` whenever one can apply the Cauchy formula for\nthe derivative. It is useful in the proof that locally uniform limits of holomorphic functions are\nholomorphic, because it depends continuously on `f` for the uniform topology. -/\nnoncomputable def cderiv (r : \u211d) (f : \u2102 \u2192 E) (z : \u2102) : E :=\n(2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e w in C(z, r), ((w - z) ^ 2)\u207b\u00b9 \u2022 f w\n\nlemma cderiv_eq_deriv (hU : is_open U) (hf : differentiable_on \u2102 f U) (hr : 0 < r)\n  (hzr : closed_ball z r \u2286 U) :\n  cderiv r f z = deriv f z :=\ntwo_pi_I_inv_smul_circle_integral_sub_sq_inv_smul_of_differentiable hU hzr hf (mem_ball_self hr)\n\nlemma norm_cderiv_le (hr : 0 < r) (hf : \u2200 w \u2208 sphere z r, \u2016f w\u2016 \u2264 M) :\n  \u2016cderiv r f z\u2016 \u2264 M / r :=\nbegin\n  have hM : 0 \u2264 M,\n  { obtain \u27e8w, hw\u27e9 : (sphere z r).nonempty := normed_space.sphere_nonempty.mpr hr.le,\n    exact (norm_nonneg _).trans (hf w hw) },\n  have h1 : \u2200 w \u2208 sphere z r, \u2016((w - z) ^ 2)\u207b\u00b9 \u2022 f w\u2016 \u2264 M / r ^ 2,\n  { intros w hw,\n    simp only [mem_sphere_iff_norm, norm_eq_abs] at hw,\n    simp only [norm_smul, inv_mul_eq_div, hw, norm_eq_abs, map_inv\u2080, complex.abs_pow],\n    exact div_le_div hM (hf w hw) (sq_pos_of_pos hr) le_rfl },\n  have h2 := circle_integral.norm_integral_le_of_norm_le_const hr.le h1,\n  simp only [cderiv, norm_smul],\n  refine (mul_le_mul le_rfl h2 (norm_nonneg _) (norm_nonneg _)).trans (le_of_eq _),\n  field_simp [_root_.abs_of_nonneg real.pi_pos.le, real.pi_pos.ne.symm, hr.ne.symm],\n  ring\nend\n\nlemma cderiv_sub (hr : 0 < r) (hf : continuous_on f (sphere z r))\n  (hg : continuous_on g (sphere z r)) :\n  cderiv r (f - g) z = cderiv r f z - cderiv r g z :=\nbegin\n  have h1 : continuous_on (\u03bb (w : \u2102), ((w - z) ^ 2)\u207b\u00b9) (sphere z r),\n  { refine ((continuous_id'.sub continuous_const).pow 2).continuous_on.inv\u2080 (\u03bb w hw h, hr.ne _),\n    rwa [mem_sphere_iff_norm, sq_eq_zero_iff.mp h, norm_zero] at hw },\n  simp_rw [cderiv, \u2190 smul_sub],\n  congr' 1,\n  simpa only [pi.sub_apply, smul_sub] using circle_integral.integral_sub\n    ((h1.smul hf).circle_integrable hr.le) ((h1.smul hg).circle_integrable hr.le)\nend\n\nlemma norm_cderiv_lt (hr : 0 < r) (hfM : \u2200 w \u2208 sphere z r, \u2016f w\u2016 < M)\n  (hf : continuous_on f (sphere z r)) :\n  \u2016cderiv r f z\u2016 < M / r :=\nbegin\n  obtain \u27e8L, hL1, hL2\u27e9 : \u2203 L < M, \u2200 w \u2208 sphere z r, \u2016f w\u2016 \u2264 L,\n  { have e1 : (sphere z r).nonempty := normed_space.sphere_nonempty.mpr hr.le,\n    have e2 : continuous_on (\u03bb w, \u2016f w\u2016) (sphere z r),\n      from continuous_norm.comp_continuous_on hf,\n    obtain \u27e8x, hx, hx'\u27e9 := (is_compact_sphere z r).exists_forall_ge e1 e2,\n    exact \u27e8\u2016f x\u2016, hfM x hx, hx'\u27e9 },\n  exact (norm_cderiv_le hr hL2).trans_lt ((div_lt_div_right hr).mpr hL1)\nend\n\nlemma norm_cderiv_sub_lt (hr : 0 < r) (hfg : \u2200 w \u2208 sphere z r, \u2016f w - g w\u2016 < M)\n  (hf : continuous_on f (sphere z r)) (hg : continuous_on g (sphere z r)) :\n  \u2016cderiv r f z - cderiv r g z\u2016 < M / r :=\ncderiv_sub hr hf hg \u25b8 norm_cderiv_lt hr hfg (hf.sub hg)\n\nlemma tendsto_uniformly_on.cderiv (hF : tendsto_uniformly_on F f \u03c6 (cthickening \u03b4 K)) (h\u03b4 : 0 < \u03b4)\n  (hFn : \u2200\u1da0 n in \u03c6, continuous_on (F n) (cthickening \u03b4 K)) :\n  tendsto_uniformly_on (cderiv \u03b4 \u2218 F) (cderiv \u03b4 f) \u03c6 K :=\nbegin\n  by_cases \u03c6 = \u22a5,\n  { simp only [h, tendsto_uniformly_on, eventually_bot, implies_true_iff]},\n  haveI : \u03c6.ne_bot := ne_bot_iff.2 h,\n  have e1 : continuous_on f (cthickening \u03b4 K) := tendsto_uniformly_on.continuous_on hF hFn,\n  rw [tendsto_uniformly_on_iff] at hF \u22a2,\n  rintro \u03b5 h\u03b5,\n  filter_upwards [hF (\u03b5 * \u03b4) (mul_pos h\u03b5 h\u03b4), hFn] with n h h' z hz,\n  simp_rw [dist_eq_norm] at h \u22a2,\n  have e2 : \u2200 w \u2208 sphere z \u03b4, \u2016f w - F n w\u2016 < \u03b5 * \u03b4,\n    from \u03bb w hw1, h w (closed_ball_subset_cthickening hz \u03b4 (sphere_subset_closed_ball hw1)),\n  have e3 := sphere_subset_closed_ball.trans (closed_ball_subset_cthickening hz \u03b4),\n  have hf : continuous_on f (sphere z \u03b4),\n    from e1.mono (sphere_subset_closed_ball.trans (closed_ball_subset_cthickening hz \u03b4)),\n  simpa only [mul_div_cancel _ h\u03b4.ne.symm] using norm_cderiv_sub_lt h\u03b4 e2 hf (h'.mono e3)\nend\n\nend cderiv\n\nsection weierstrass\n\nlemma tendsto_uniformly_on_deriv_of_cthickening_subset (hf : tendsto_locally_uniformly_on F f \u03c6 U)\n  (hF : \u2200\u1da0 n in \u03c6, differentiable_on \u2102 (F n) U) {\u03b4 : \u211d} (h\u03b4: 0 < \u03b4) (hK : is_compact K)\n  (hU : is_open U) (hKU : cthickening \u03b4 K \u2286 U) :\n  tendsto_uniformly_on (deriv \u2218 F) (cderiv \u03b4 f) \u03c6 K :=\nbegin\n  have h1 : \u2200\u1da0 n in \u03c6, continuous_on (F n) (cthickening \u03b4 K),\n    by filter_upwards [hF] with n h using h.continuous_on.mono hKU,\n  have h2 : is_compact (cthickening \u03b4 K),\n    from is_compact_of_is_closed_bounded is_closed_cthickening hK.bounded.cthickening,\n  have h3 : tendsto_uniformly_on F f \u03c6 (cthickening \u03b4 K),\n    from (tendsto_locally_uniformly_on_iff_forall_is_compact hU).mp hf (cthickening \u03b4 K) hKU h2,\n  apply (h3.cderiv h\u03b4 h1).congr,\n  filter_upwards [hF] with n h z hz,\n  exact cderiv_eq_deriv hU h h\u03b4 ((closed_ball_subset_cthickening hz \u03b4).trans hKU)\nend\n\nlemma exists_cthickening_tendsto_uniformly_on (hf : tendsto_locally_uniformly_on F f \u03c6 U)\n  (hF : \u2200\u1da0 n in \u03c6, differentiable_on \u2102 (F n) U) (hK : is_compact K) (hU : is_open U) (hKU : K \u2286 U) :\n  \u2203 \u03b4 > 0, cthickening \u03b4 K \u2286 U \u2227 tendsto_uniformly_on (deriv \u2218 F) (cderiv \u03b4 f) \u03c6 K :=\nbegin\n  obtain \u27e8\u03b4, h\u03b4, hK\u03b4\u27e9 := hK.exists_cthickening_subset_open hU hKU,\n  exact \u27e8\u03b4, h\u03b4, hK\u03b4, tendsto_uniformly_on_deriv_of_cthickening_subset hf hF h\u03b4 hK hU hK\u03b4\u27e9\nend\n\n/-- A locally uniform limit of holomorphic functions on an open domain of the complex plane is\nholomorphic (the derivatives converge locally uniformly to that of the limit, which is proved\nas `tendsto_locally_uniformly_on.deriv`). -/\ntheorem _root_.tendsto_locally_uniformly_on.differentiable_on [\u03c6.ne_bot]\n  (hf : tendsto_locally_uniformly_on F f \u03c6 U) (hF : \u2200\u1da0 n in \u03c6, differentiable_on \u2102 (F n) U)\n  (hU : is_open U) :\n  differentiable_on \u2102 f U :=\nbegin\n  rintro x hx,\n  obtain \u27e8K, \u27e8hKx, hK\u27e9, hKU\u27e9 := (compact_basis_nhds x).mem_iff.mp (hU.mem_nhds hx),\n  obtain \u27e8\u03b4, h\u03b4, -, h1\u27e9 := exists_cthickening_tendsto_uniformly_on hf hF hK hU hKU,\n  have h2 : interior K \u2286 U := interior_subset.trans hKU,\n  have h3 : \u2200\u1da0 n in \u03c6, differentiable_on \u2102 (F n) (interior K),\n    filter_upwards [hF] with n h using h.mono h2,\n  have h4 : tendsto_locally_uniformly_on F f \u03c6 (interior K) := hf.mono h2,\n  have h5 : tendsto_locally_uniformly_on (deriv \u2218 F) (cderiv \u03b4 f) \u03c6 (interior K),\n    from h1.tendsto_locally_uniformly_on.mono interior_subset,\n  have h6 : \u2200 x \u2208 interior K, has_deriv_at f (cderiv \u03b4 f x) x,\n    from \u03bb x h, has_deriv_at_of_tendsto_locally_uniformly_on'\n      is_open_interior h5 h3 (\u03bb _, h4.tendsto_at) h,\n  have h7 : differentiable_on \u2102 f (interior K),\n    from \u03bb x hx, (h6 x hx).differentiable_at.differentiable_within_at,\n  exact (h7.differentiable_at (interior_mem_nhds.mpr hKx)).differentiable_within_at\nend\n\nlemma _root_.tendsto_locally_uniformly_on.deriv (hf : tendsto_locally_uniformly_on F f \u03c6 U)\n  (hF : \u2200\u1da0 n in \u03c6, differentiable_on \u2102 (F n) U) (hU : is_open U) :\n  tendsto_locally_uniformly_on (deriv \u2218 F) (deriv f) \u03c6 U :=\nbegin\n  rw [tendsto_locally_uniformly_on_iff_forall_is_compact hU],\n  by_cases \u03c6 = \u22a5,\n  { simp only [h, tendsto_uniformly_on, eventually_bot, implies_true_iff] },\n  haveI : \u03c6.ne_bot := ne_bot_iff.2 h,\n  rintro K hKU hK,\n  obtain \u27e8\u03b4, h\u03b4, hK4, h\u27e9 := exists_cthickening_tendsto_uniformly_on hf hF hK hU hKU,\n  refine h.congr_right (\u03bb z hz, cderiv_eq_deriv hU (hf.differentiable_on hF hU) h\u03b4 _),\n  exact (closed_ball_subset_cthickening hz \u03b4).trans hK4,\nend\n\nend weierstrass\n\nsection tsums\n\n/-- If the terms in the sum `\u2211' (i : \u03b9), F i` are uniformly bounded on `U` by a\nsummable function, and each term in the sum is differentiable on `U`, then so is the sum. -/\nlemma differentiable_on_tsum_of_summable_norm {u : \u03b9 \u2192 \u211d}\n  (hu : summable u) (hf : \u2200 (i : \u03b9), differentiable_on \u2102 (F i) U) (hU : is_open U)\n  (hF_le : \u2200 (i : \u03b9) (w : \u2102), w \u2208 U \u2192 \u2016F i w\u2016 \u2264 u i) :\n  differentiable_on \u2102 (\u03bb w : \u2102, \u2211' (i : \u03b9), F i w) U :=\nbegin\n  classical,\n  have hc := (tendsto_uniformly_on_tsum hu hF_le).tendsto_locally_uniformly_on,\n  refine hc.differentiable_on (eventually_of_forall $ \u03bb s, _) hU,\n  exact differentiable_on.sum (\u03bb i hi, hf i),\nend\n\n/-- If the terms in the sum `\u2211' (i : \u03b9), F i` are uniformly bounded on `U` by a\nsummable function, then the sum of `deriv F i` at a point in `U` is the derivative of the\nsum. -/\nlemma has_sum_deriv_of_summable_norm {u : \u03b9 \u2192 \u211d}\n  (hu : summable u) (hf : \u2200 (i : \u03b9), differentiable_on \u2102 (F i) U) (hU : is_open U)\n  (hF_le : \u2200 (i : \u03b9) (w : \u2102), w \u2208 U \u2192 \u2016F i w\u2016 \u2264 u i) (hz : z \u2208 U) :\n  has_sum (\u03bb (i : \u03b9), deriv (F i) z) (deriv (\u03bb w : \u2102, \u2211' (i : \u03b9), F i w) z) :=\nbegin\n  rw has_sum,\n  have hc := (tendsto_uniformly_on_tsum hu hF_le).tendsto_locally_uniformly_on,\n  convert (hc.deriv (eventually_of_forall $ \u03bb s, differentiable_on.sum\n    (\u03bb i hi, hf i)) hU).tendsto_at hz using 1,\n  ext1 s,\n  exact (deriv_sum (\u03bb i hi, (hf i).differentiable_at (hU.mem_nhds hz))).symm,\nend\n\nend tsums\n\nend complex\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/complex/locally_uniform_limit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7187774363833389}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n\n! This file was ported from Lean 3 source module order.bounds.basic\n! leanprover-community/mathlib commit 3310acfa9787aa171db6d4cba3945f6f275fe9f2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Set.Intervals.Basic\nimport Mathbin.Data.Set.NAry\n\n/-!\n\n# Upper / lower bounds\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define:\n\n* `upper_bounds`, `lower_bounds` : the set of upper bounds (resp., lower bounds) of a set;\n* `bdd_above s`, `bdd_below s` : the set `s` is bounded above (resp., below), i.e., the set of upper\n  (resp., lower) bounds of `s` is nonempty;\n* `is_least s a`, `is_greatest s a` : `a` is a least (resp., greatest) element of `s`;\n  for a partial order, it is unique if exists;\n* `is_lub s a`, `is_glb s a` : `a` is a least upper bound (resp., a greatest lower bound)\n  of `s`; for a partial order, it is unique if exists.\n\nWe also prove various lemmas about monotonicity, behaviour under `\u222a`, `\u2229`, `insert`, and provide\nformulas for `\u2205`, `univ`, and intervals.\n-/\n\n\nopen Function Set\n\nopen OrderDual (toDual ofDual)\n\nuniverse u v w x\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x}\n\nsection\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {s t : Set \u03b1} {a b : \u03b1}\n\n/-!\n### Definitions\n-/\n\n\n#print upperBounds /-\n/-- The set of upper bounds of a set. -/\ndef upperBounds (s : Set \u03b1) : Set \u03b1 :=\n  { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 a \u2264 x }\n#align upper_bounds upperBounds\n-/\n\n#print lowerBounds /-\n/-- The set of lower bounds of a set. -/\ndef lowerBounds (s : Set \u03b1) : Set \u03b1 :=\n  { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 x \u2264 a }\n#align lower_bounds lowerBounds\n-/\n\n#print BddAbove /-\n/-- A set is bounded above if there exists an upper bound. -/\ndef BddAbove (s : Set \u03b1) :=\n  (upperBounds s).Nonempty\n#align bdd_above BddAbove\n-/\n\n#print BddBelow /-\n/-- A set is bounded below if there exists a lower bound. -/\ndef BddBelow (s : Set \u03b1) :=\n  (lowerBounds s).Nonempty\n#align bdd_below BddBelow\n-/\n\n#print IsLeast /-\n/-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/\ndef IsLeast (s : Set \u03b1) (a : \u03b1) : Prop :=\n  a \u2208 s \u2227 a \u2208 lowerBounds s\n#align is_least IsLeast\n-/\n\n#print IsGreatest /-\n/-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists -/\ndef IsGreatest (s : Set \u03b1) (a : \u03b1) : Prop :=\n  a \u2208 s \u2227 a \u2208 upperBounds s\n#align is_greatest IsGreatest\n-/\n\n#print IsLUB /-\n/-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/\ndef IsLUB (s : Set \u03b1) : \u03b1 \u2192 Prop :=\n  IsLeast (upperBounds s)\n#align is_lub IsLUB\n-/\n\n#print IsGLB /-\n/-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/\ndef IsGLB (s : Set \u03b1) : \u03b1 \u2192 Prop :=\n  IsGreatest (lowerBounds s)\n#align is_glb IsGLB\n-/\n\n#print mem_upperBounds /-\ntheorem mem_upperBounds : a \u2208 upperBounds s \u2194 \u2200 x \u2208 s, x \u2264 a :=\n  Iff.rfl\n#align mem_upper_bounds mem_upperBounds\n-/\n\n#print mem_lowerBounds /-\ntheorem mem_lowerBounds : a \u2208 lowerBounds s \u2194 \u2200 x \u2208 s, a \u2264 x :=\n  Iff.rfl\n#align mem_lower_bounds mem_lowerBounds\n-/\n\n#print bddAbove_def /-\ntheorem bddAbove_def : BddAbove s \u2194 \u2203 x, \u2200 y \u2208 s, y \u2264 x :=\n  Iff.rfl\n#align bdd_above_def bddAbove_def\n-/\n\n#print bddBelow_def /-\ntheorem bddBelow_def : BddBelow s \u2194 \u2203 x, \u2200 y \u2208 s, x \u2264 y :=\n  Iff.rfl\n#align bdd_below_def bddBelow_def\n-/\n\n/- warning: bot_mem_lower_bounds -> bot_mem_lowerBounds is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)] (s : Set.{u1} \u03b1), Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toHasBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) (lowerBounds.{u1} \u03b1 _inst_1 s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)] (s : Set.{u1} \u03b1), Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) (lowerBounds.{u1} \u03b1 _inst_1 s)\nCase conversion may be inaccurate. Consider using '#align bot_mem_lower_bounds bot_mem_lowerBounds\u2093'. -/\ntheorem bot_mem_lowerBounds [OrderBot \u03b1] (s : Set \u03b1) : \u22a5 \u2208 lowerBounds s := fun _ _ => bot_le\n#align bot_mem_lower_bounds bot_mem_lowerBounds\n\n/- warning: top_mem_upper_bounds -> top_mem_upperBounds is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)] (s : Set.{u1} \u03b1), Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toHasTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) (upperBounds.{u1} \u03b1 _inst_1 s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)] (s : Set.{u1} \u03b1), Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) (upperBounds.{u1} \u03b1 _inst_1 s)\nCase conversion may be inaccurate. Consider using '#align top_mem_upper_bounds top_mem_upperBounds\u2093'. -/\ntheorem top_mem_upperBounds [OrderTop \u03b1] (s : Set \u03b1) : \u22a4 \u2208 upperBounds s := fun _ _ => le_top\n#align top_mem_upper_bounds top_mem_upperBounds\n\n/- warning: is_least_bot_iff -> isLeast_bot_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], Iff (IsLeast.{u1} \u03b1 _inst_1 s (Bot.bot.{u1} \u03b1 (OrderBot.toHasBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))) (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toHasBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], Iff (IsLeast.{u1} \u03b1 _inst_1 s (Bot.bot.{u1} \u03b1 (OrderBot.toBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))) (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) s)\nCase conversion may be inaccurate. Consider using '#align is_least_bot_iff isLeast_bot_iff\u2093'. -/\n@[simp]\ntheorem isLeast_bot_iff [OrderBot \u03b1] : IsLeast s \u22a5 \u2194 \u22a5 \u2208 s :=\n  and_iff_left <| bot_mem_lowerBounds _\n#align is_least_bot_iff isLeast_bot_iff\n\n/- warning: is_greatest_top_iff -> isGreatest_top_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], Iff (IsGreatest.{u1} \u03b1 _inst_1 s (Top.top.{u1} \u03b1 (OrderTop.toHasTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))) (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toHasTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], Iff (IsGreatest.{u1} \u03b1 _inst_1 s (Top.top.{u1} \u03b1 (OrderTop.toTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))) (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3)) s)\nCase conversion may be inaccurate. Consider using '#align is_greatest_top_iff isGreatest_top_iff\u2093'. -/\n@[simp]\ntheorem isGreatest_top_iff [OrderTop \u03b1] : IsGreatest s \u22a4 \u2194 \u22a4 \u2208 s :=\n  and_iff_left <| top_mem_upperBounds _\n#align is_greatest_top_iff isGreatest_top_iff\n\n/- warning: not_bdd_above_iff' -> not_bddAbove_iff' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddAbove.{u1} \u03b1 _inst_1 s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) => Not (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) y x))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddAbove.{u1} \u03b1 _inst_1 s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) y s) (Not (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) y x))))\nCase conversion may be inaccurate. Consider using '#align not_bdd_above_iff' not_bddAbove_iff'\u2093'. -/\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not greater than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(y \u2264 x)`. A version for linear orders is called `not_bdd_above_iff`. -/\ntheorem not_bddAbove_iff' : \u00acBddAbove s \u2194 \u2200 x, \u2203 y \u2208 s, \u00acy \u2264 x := by\n  simp [BddAbove, upperBounds, Set.Nonempty]\n#align not_bdd_above_iff' not_bddAbove_iff'\n\n/- warning: not_bdd_below_iff' -> not_bddBelow_iff' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddBelow.{u1} \u03b1 _inst_1 s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) => Not (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) x y))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddBelow.{u1} \u03b1 _inst_1 s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) y s) (Not (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) x y))))\nCase conversion may be inaccurate. Consider using '#align not_bdd_below_iff' not_bddBelow_iff'\u2093'. -/\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not less than or equal to `y`. This version only assumes `preorder` structure and uses\n`\u00ac(x \u2264 y)`. A version for linear orders is called `not_bdd_below_iff`. -/\ntheorem not_bddBelow_iff' : \u00acBddBelow s \u2194 \u2200 x, \u2203 y \u2208 s, \u00acx \u2264 y :=\n  @not_bddAbove_iff' \u03b1\u1d52\u1d48 _ _\n#align not_bdd_below_iff' not_bddBelow_iff'\n\n/- warning: not_bdd_above_iff -> not_bddAbove_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_3)))) s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) => LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_3))))) x y)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_3))))) s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) y s) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_3)))))) x y)))\nCase conversion may be inaccurate. Consider using '#align not_bdd_above_iff not_bddAbove_iff\u2093'. -/\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` that is greater\nthan `x`. A version for preorders is called `not_bdd_above_iff'`. -/\ntheorem not_bddAbove_iff {\u03b1 : Type _} [LinearOrder \u03b1] {s : Set \u03b1} :\n    \u00acBddAbove s \u2194 \u2200 x, \u2203 y \u2208 s, x < y := by simp only [not_bddAbove_iff', not_le]\n#align not_bdd_above_iff not_bddAbove_iff\n\n/- warning: not_bdd_below_iff -> not_bddBelow_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_3)))) s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y s) => LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_3))))) y x)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Not (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_3))))) s)) (forall (x : \u03b1), Exists.{succ u1} \u03b1 (fun (y : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) y s) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_3)))))) y x)))\nCase conversion may be inaccurate. Consider using '#align not_bdd_below_iff not_bddBelow_iff\u2093'. -/\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` that is less\nthan `x`. A version for preorders is called `not_bdd_below_iff'`. -/\ntheorem not_bddBelow_iff {\u03b1 : Type _} [LinearOrder \u03b1] {s : Set \u03b1} :\n    \u00acBddBelow s \u2194 \u2200 x, \u2203 y \u2208 s, y < x :=\n  @not_bddAbove_iff \u03b1\u1d52\u1d48 _ _\n#align not_bdd_below_iff not_bddBelow_iff\n\n#print BddAbove.dual /-\ntheorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual \u207b\u00b9' s) :=\n  h\n#align bdd_above.dual BddAbove.dual\n-/\n\n#print BddBelow.dual /-\ntheorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual \u207b\u00b9' s) :=\n  h\n#align bdd_below.dual BddBelow.dual\n-/\n\n#print IsLeast.dual /-\ntheorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_least.dual IsLeast.dual\n-/\n\n#print IsGreatest.dual /-\ntheorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_greatest.dual IsGreatest.dual\n-/\n\n#print IsLUB.dual /-\ntheorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_lub.dual IsLUB.dual\n-/\n\n#print IsGLB.dual /-\ntheorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_glb.dual IsGLB.dual\n-/\n\n#print IsLeast.orderBot /-\n/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/\n@[reducible]\ndef IsLeast.orderBot (h : IsLeast s a) : OrderBot s\n    where\n  bot := \u27e8a, h.1\u27e9\n  bot_le := Subtype.forall.2 h.2\n#align is_least.order_bot IsLeast.orderBot\n-/\n\n#print IsGreatest.orderTop /-\n/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/\n@[reducible]\ndef IsGreatest.orderTop (h : IsGreatest s a) : OrderTop s\n    where\n  top := \u27e8a, h.1\u27e9\n  le_top := Subtype.forall.2 h.2\n#align is_greatest.order_top IsGreatest.orderTop\n-/\n\n/-!\n### Monotonicity\n-/\n\n\n#print upperBounds_mono_set /-\ntheorem upperBounds_mono_set \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) : upperBounds t \u2286 upperBounds s :=\n  fun b hb x h => hb <| hst h\n#align upper_bounds_mono_set upperBounds_mono_set\n-/\n\n#print lowerBounds_mono_set /-\ntheorem lowerBounds_mono_set \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) : lowerBounds t \u2286 lowerBounds s :=\n  fun b hb x h => hb <| hst h\n#align lower_bounds_mono_set lowerBounds_mono_set\n-/\n\n#print upperBounds_mono_mem /-\ntheorem upperBounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : a \u2208 upperBounds s \u2192 b \u2208 upperBounds s :=\n  fun ha x h => le_trans (ha h) hab\n#align upper_bounds_mono_mem upperBounds_mono_mem\n-/\n\n#print lowerBounds_mono_mem /-\ntheorem lowerBounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : b \u2208 lowerBounds s \u2192 a \u2208 lowerBounds s :=\n  fun hb x h => le_trans hab (hb h)\n#align lower_bounds_mono_mem lowerBounds_mono_mem\n-/\n\n#print upperBounds_mono /-\ntheorem upperBounds_mono \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n    a \u2208 upperBounds t \u2192 b \u2208 upperBounds s := fun ha =>\n  upperBounds_mono_set hst <| upperBounds_mono_mem hab ha\n#align upper_bounds_mono upperBounds_mono\n-/\n\n#print lowerBounds_mono /-\ntheorem lowerBounds_mono \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n    b \u2208 lowerBounds t \u2192 a \u2208 lowerBounds s := fun hb =>\n  lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb\n#align lower_bounds_mono lowerBounds_mono\n-/\n\n#print BddAbove.mono /-\n/-- If `s \u2286 t` and `t` is bounded above, then so is `s`. -/\ntheorem BddAbove.mono \u2983s t : Set \u03b1\u2984 (h : s \u2286 t) : BddAbove t \u2192 BddAbove s :=\n  Nonempty.mono <| upperBounds_mono_set h\n#align bdd_above.mono BddAbove.mono\n-/\n\n#print BddBelow.mono /-\n/-- If `s \u2286 t` and `t` is bounded below, then so is `s`. -/\ntheorem BddBelow.mono \u2983s t : Set \u03b1\u2984 (h : s \u2286 t) : BddBelow t \u2192 BddBelow s :=\n  Nonempty.mono <| lowerBounds_mono_set h\n#align bdd_below.mono BddBelow.mono\n-/\n\n#print IsLUB.of_subset_of_superset /-\n/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\ntheorem IsLUB.of_subset_of_superset {s t p : Set \u03b1} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s \u2286 t)\n    (htp : t \u2286 p) : IsLUB t a :=\n  \u27e8upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2\u27e9\n#align is_lub.of_subset_of_superset IsLUB.of_subset_of_superset\n-/\n\n#print IsGLB.of_subset_of_superset /-\n/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\ntheorem IsGLB.of_subset_of_superset {s t p : Set \u03b1} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s \u2286 t)\n    (htp : t \u2286 p) : IsGLB t a :=\n  hs.dual.of_subset_of_superset hp hst htp\n#align is_glb.of_subset_of_superset IsGLB.of_subset_of_superset\n-/\n\n#print IsLeast.mono /-\ntheorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s \u2286 t) : b \u2264 a :=\n  hb.2 (hst ha.1)\n#align is_least.mono IsLeast.mono\n-/\n\n#print IsGreatest.mono /-\ntheorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s \u2286 t) : a \u2264 b :=\n  hb.2 (hst ha.1)\n#align is_greatest.mono IsGreatest.mono\n-/\n\n#print IsLUB.mono /-\ntheorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s \u2286 t) : a \u2264 b :=\n  hb.mono ha <| upperBounds_mono_set hst\n#align is_lub.mono IsLUB.mono\n-/\n\n#print IsGLB.mono /-\ntheorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s \u2286 t) : b \u2264 a :=\n  hb.mono ha <| lowerBounds_mono_set hst\n#align is_glb.mono IsGLB.mono\n-/\n\n#print subset_lowerBounds_upperBounds /-\ntheorem subset_lowerBounds_upperBounds (s : Set \u03b1) : s \u2286 lowerBounds (upperBounds s) :=\n  fun x hx y hy => hy hx\n#align subset_lower_bounds_upper_bounds subset_lowerBounds_upperBounds\n-/\n\n#print subset_upperBounds_lowerBounds /-\ntheorem subset_upperBounds_lowerBounds (s : Set \u03b1) : s \u2286 upperBounds (lowerBounds s) :=\n  fun x hx y hy => hy hx\n#align subset_upper_bounds_lower_bounds subset_upperBounds_lowerBounds\n-/\n\n#print Set.Nonempty.bddAbove_lowerBounds /-\ntheorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) :=\n  hs.mono (subset_upperBounds_lowerBounds s)\n#align set.nonempty.bdd_above_lower_bounds Set.Nonempty.bddAbove_lowerBounds\n-/\n\n#print Set.Nonempty.bddBelow_upperBounds /-\ntheorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) :=\n  hs.mono (subset_lowerBounds_upperBounds s)\n#align set.nonempty.bdd_below_upper_bounds Set.Nonempty.bddBelow_upperBounds\n-/\n\n/-!\n### Conversions\n-/\n\n\n#print IsLeast.isGLB /-\ntheorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a :=\n  \u27e8h.2, fun b hb => hb h.1\u27e9\n#align is_least.is_glb IsLeast.isGLB\n-/\n\n#print IsGreatest.isLUB /-\ntheorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a :=\n  \u27e8h.2, fun b hb => hb h.1\u27e9\n#align is_greatest.is_lub IsGreatest.isLUB\n-/\n\n#print IsLUB.upperBounds_eq /-\ntheorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a :=\n  Set.ext fun b => \u27e8fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1\u27e9\n#align is_lub.upper_bounds_eq IsLUB.upperBounds_eq\n-/\n\n#print IsGLB.lowerBounds_eq /-\ntheorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a :=\n  h.dual.upperBounds_eq\n#align is_glb.lower_bounds_eq IsGLB.lowerBounds_eq\n-/\n\n#print IsLeast.lowerBounds_eq /-\ntheorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a :=\n  h.IsGLB.lowerBounds_eq\n#align is_least.lower_bounds_eq IsLeast.lowerBounds_eq\n-/\n\n#print IsGreatest.upperBounds_eq /-\ntheorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a :=\n  h.IsLUB.upperBounds_eq\n#align is_greatest.upper_bounds_eq IsGreatest.upperBounds_eq\n-/\n\n#print isLUB_le_iff /-\ntheorem isLUB_le_iff (h : IsLUB s a) : a \u2264 b \u2194 b \u2208 upperBounds s :=\n  by\n  rw [h.upper_bounds_eq]\n  rfl\n#align is_lub_le_iff isLUB_le_iff\n-/\n\n#print le_isGLB_iff /-\ntheorem le_isGLB_iff (h : IsGLB s a) : b \u2264 a \u2194 b \u2208 lowerBounds s :=\n  by\n  rw [h.lower_bounds_eq]\n  rfl\n#align le_is_glb_iff le_isGLB_iff\n-/\n\n#print isLUB_iff_le_iff /-\ntheorem isLUB_iff_le_iff : IsLUB s a \u2194 \u2200 b, a \u2264 b \u2194 b \u2208 upperBounds s :=\n  \u27e8fun h b => isLUB_le_iff h, fun H => \u27e8(H _).1 le_rfl, fun b hb => (H b).2 hb\u27e9\u27e9\n#align is_lub_iff_le_iff isLUB_iff_le_iff\n-/\n\n#print isGLB_iff_le_iff /-\ntheorem isGLB_iff_le_iff : IsGLB s a \u2194 \u2200 b, b \u2264 a \u2194 b \u2208 lowerBounds s :=\n  @isLUB_iff_le_iff \u03b1\u1d52\u1d48 _ _ _\n#align is_glb_iff_le_iff isGLB_iff_le_iff\n-/\n\n#print IsLUB.bddAbove /-\n/-- If `s` has a least upper bound, then it is bounded above. -/\ntheorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s :=\n  \u27e8a, h.1\u27e9\n#align is_lub.bdd_above IsLUB.bddAbove\n-/\n\n#print IsGLB.bddBelow /-\n/-- If `s` has a greatest lower bound, then it is bounded below. -/\ntheorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s :=\n  \u27e8a, h.1\u27e9\n#align is_glb.bdd_below IsGLB.bddBelow\n-/\n\n#print IsGreatest.bddAbove /-\n/-- If `s` has a greatest element, then it is bounded above. -/\ntheorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s :=\n  \u27e8a, h.2\u27e9\n#align is_greatest.bdd_above IsGreatest.bddAbove\n-/\n\n#print IsLeast.bddBelow /-\n/-- If `s` has a least element, then it is bounded below. -/\ntheorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s :=\n  \u27e8a, h.2\u27e9\n#align is_least.bdd_below IsLeast.bddBelow\n-/\n\n#print IsLeast.nonempty /-\ntheorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty :=\n  \u27e8a, h.1\u27e9\n#align is_least.nonempty IsLeast.nonempty\n-/\n\n#print IsGreatest.nonempty /-\ntheorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty :=\n  \u27e8a, h.1\u27e9\n#align is_greatest.nonempty IsGreatest.nonempty\n-/\n\n/-!\n### Union and intersection\n-/\n\n\n/- warning: upper_bounds_union -> upperBounds_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) (upperBounds.{u1} \u03b1 _inst_1 t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) (upperBounds.{u1} \u03b1 _inst_1 t))\nCase conversion may be inaccurate. Consider using '#align upper_bounds_union upperBounds_union\u2093'. -/\n@[simp]\ntheorem upperBounds_union : upperBounds (s \u222a t) = upperBounds s \u2229 upperBounds t :=\n  Subset.antisymm (fun b hb => \u27e8fun x hx => hb (Or.inl hx), fun x hx => hb (Or.inr hx)\u27e9)\n    fun b hb x hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht\n#align upper_bounds_union upperBounds_union\n\n/- warning: lower_bounds_union -> lowerBounds_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) (lowerBounds.{u1} \u03b1 _inst_1 t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) (lowerBounds.{u1} \u03b1 _inst_1 t))\nCase conversion may be inaccurate. Consider using '#align lower_bounds_union lowerBounds_union\u2093'. -/\n@[simp]\ntheorem lowerBounds_union : lowerBounds (s \u222a t) = lowerBounds s \u2229 lowerBounds t :=\n  @upperBounds_union \u03b1\u1d52\u1d48 _ s t\n#align lower_bounds_union lowerBounds_union\n\n/- warning: union_upper_bounds_subset_upper_bounds_inter -> union_upperBounds_subset_upperBounds_inter is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) (upperBounds.{u1} \u03b1 _inst_1 t)) (upperBounds.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) (upperBounds.{u1} \u03b1 _inst_1 t)) (upperBounds.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align union_upper_bounds_subset_upper_bounds_inter union_upperBounds_subset_upperBounds_inter\u2093'. -/\ntheorem union_upperBounds_subset_upperBounds_inter :\n    upperBounds s \u222a upperBounds t \u2286 upperBounds (s \u2229 t) :=\n  union_subset (upperBounds_mono_set <| inter_subset_left _ _)\n    (upperBounds_mono_set <| inter_subset_right _ _)\n#align union_upper_bounds_subset_upper_bounds_inter union_upperBounds_subset_upperBounds_inter\n\n/- warning: union_lower_bounds_subset_lower_bounds_inter -> union_lowerBounds_subset_lowerBounds_inter is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) (lowerBounds.{u1} \u03b1 _inst_1 t)) (lowerBounds.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) (lowerBounds.{u1} \u03b1 _inst_1 t)) (lowerBounds.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align union_lower_bounds_subset_lower_bounds_inter union_lowerBounds_subset_lowerBounds_inter\u2093'. -/\ntheorem union_lowerBounds_subset_lowerBounds_inter :\n    lowerBounds s \u222a lowerBounds t \u2286 lowerBounds (s \u2229 t) :=\n  @union_upperBounds_subset_upperBounds_inter \u03b1\u1d52\u1d48 _ s t\n#align union_lower_bounds_subset_lower_bounds_inter union_lowerBounds_subset_lowerBounds_inter\n\n/- warning: is_least_union_iff -> isLeast_union_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {a : \u03b1} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (IsLeast.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t) a) (Or (And (IsLeast.{u1} \u03b1 _inst_1 s a) (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (lowerBounds.{u1} \u03b1 _inst_1 t))) (And (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (lowerBounds.{u1} \u03b1 _inst_1 s)) (IsLeast.{u1} \u03b1 _inst_1 t a)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {a : \u03b1} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (IsLeast.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t) a) (Or (And (IsLeast.{u1} \u03b1 _inst_1 s a) (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a (lowerBounds.{u1} \u03b1 _inst_1 t))) (And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a (lowerBounds.{u1} \u03b1 _inst_1 s)) (IsLeast.{u1} \u03b1 _inst_1 t a)))\nCase conversion may be inaccurate. Consider using '#align is_least_union_iff isLeast_union_iff\u2093'. -/\ntheorem isLeast_union_iff {a : \u03b1} {s t : Set \u03b1} :\n    IsLeast (s \u222a t) a \u2194 IsLeast s a \u2227 a \u2208 lowerBounds t \u2228 a \u2208 lowerBounds s \u2227 IsLeast t a := by\n  simp [IsLeast, lowerBounds_union, or_and_right, and_comm' (a \u2208 t), and_assoc']\n#align is_least_union_iff isLeast_union_iff\n\n/- warning: is_greatest_union_iff -> isGreatest_union_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1} {a : \u03b1}, Iff (IsGreatest.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t) a) (Or (And (IsGreatest.{u1} \u03b1 _inst_1 s a) (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (upperBounds.{u1} \u03b1 _inst_1 t))) (And (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a (upperBounds.{u1} \u03b1 _inst_1 s)) (IsGreatest.{u1} \u03b1 _inst_1 t a)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1} {a : \u03b1}, Iff (IsGreatest.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t) a) (Or (And (IsGreatest.{u1} \u03b1 _inst_1 s a) (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a (upperBounds.{u1} \u03b1 _inst_1 t))) (And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a (upperBounds.{u1} \u03b1 _inst_1 s)) (IsGreatest.{u1} \u03b1 _inst_1 t a)))\nCase conversion may be inaccurate. Consider using '#align is_greatest_union_iff isGreatest_union_iff\u2093'. -/\ntheorem isGreatest_union_iff :\n    IsGreatest (s \u222a t) a \u2194\n      IsGreatest s a \u2227 a \u2208 upperBounds t \u2228 a \u2208 upperBounds s \u2227 IsGreatest t a :=\n  @isLeast_union_iff \u03b1\u1d52\u1d48 _ a s t\n#align is_greatest_union_iff isGreatest_union_iff\n\n/- warning: bdd_above.inter_of_left -> BddAbove.inter_of_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddAbove.{u1} \u03b1 _inst_1 s) -> (BddAbove.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddAbove.{u1} \u03b1 _inst_1 s) -> (BddAbove.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align bdd_above.inter_of_left BddAbove.inter_of_left\u2093'. -/\n/-- If `s` is bounded, then so is `s \u2229 t` -/\ntheorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s \u2229 t) :=\n  h.mono <| inter_subset_left s t\n#align bdd_above.inter_of_left BddAbove.inter_of_left\n\n/- warning: bdd_above.inter_of_right -> BddAbove.inter_of_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddAbove.{u1} \u03b1 _inst_1 t) -> (BddAbove.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddAbove.{u1} \u03b1 _inst_1 t) -> (BddAbove.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align bdd_above.inter_of_right BddAbove.inter_of_right\u2093'. -/\n/-- If `t` is bounded, then so is `s \u2229 t` -/\ntheorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s \u2229 t) :=\n  h.mono <| inter_subset_right s t\n#align bdd_above.inter_of_right BddAbove.inter_of_right\n\n/- warning: bdd_below.inter_of_left -> BddBelow.inter_of_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddBelow.{u1} \u03b1 _inst_1 s) -> (BddBelow.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddBelow.{u1} \u03b1 _inst_1 s) -> (BddBelow.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align bdd_below.inter_of_left BddBelow.inter_of_left\u2093'. -/\n/-- If `s` is bounded, then so is `s \u2229 t` -/\ntheorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s \u2229 t) :=\n  h.mono <| inter_subset_left s t\n#align bdd_below.inter_of_left BddBelow.inter_of_left\n\n/- warning: bdd_below.inter_of_right -> BddBelow.inter_of_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddBelow.{u1} \u03b1 _inst_1 t) -> (BddBelow.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (BddBelow.{u1} \u03b1 _inst_1 t) -> (BddBelow.{u1} \u03b1 _inst_1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align bdd_below.inter_of_right BddBelow.inter_of_right\u2093'. -/\n/-- If `t` is bounded, then so is `s \u2229 t` -/\ntheorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s \u2229 t) :=\n  h.mono <| inter_subset_right s t\n#align bdd_below.inter_of_right BddBelow.inter_of_right\n\n/- warning: bdd_above.union -> BddAbove.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s) -> (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) t) -> (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s) -> (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) t) -> (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t))\nCase conversion may be inaccurate. Consider using '#align bdd_above.union BddAbove.union\u2093'. -/\n/-- If `s` and `t` are bounded above sets in a `semilattice_sup`, then so is `s \u222a t`. -/\ntheorem BddAbove.union [SemilatticeSup \u03b3] {s t : Set \u03b3} :\n    BddAbove s \u2192 BddAbove t \u2192 BddAbove (s \u222a t) :=\n  by\n  rintro \u27e8bs, hs\u27e9 \u27e8bt, ht\u27e9\n  use bs \u2294 bt\n  rw [upperBounds_union]\n  exact \u27e8upperBounds_mono_mem le_sup_left hs, upperBounds_mono_mem le_sup_right ht\u27e9\n#align bdd_above.union BddAbove.union\n\n/- warning: bdd_above_union -> bddAbove_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, Iff (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t)) (And (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s) (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) t))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, Iff (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t)) (And (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s) (BddAbove.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) t))\nCase conversion may be inaccurate. Consider using '#align bdd_above_union bddAbove_union\u2093'. -/\n/-- The union of two sets is bounded above if and only if each of the sets is. -/\ntheorem bddAbove_union [SemilatticeSup \u03b3] {s t : Set \u03b3} :\n    BddAbove (s \u222a t) \u2194 BddAbove s \u2227 BddAbove t :=\n  \u27e8fun h => \u27e8h.mono <| subset_union_left s t, h.mono <| subset_union_right s t\u27e9, fun h =>\n    h.1.union h.2\u27e9\n#align bdd_above_union bddAbove_union\n\n/- warning: bdd_below.union -> BddBelow.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s) -> (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) t) -> (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s) -> (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) t) -> (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t))\nCase conversion may be inaccurate. Consider using '#align bdd_below.union BddBelow.union\u2093'. -/\ntheorem BddBelow.union [SemilatticeInf \u03b3] {s t : Set \u03b3} :\n    BddBelow s \u2192 BddBelow t \u2192 BddBelow (s \u222a t) :=\n  @BddAbove.union \u03b3\u1d52\u1d48 _ s t\n#align bdd_below.union BddBelow.union\n\n/- warning: bdd_below_union -> bddBelow_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, Iff (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t)) (And (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s) (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) t))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, Iff (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t)) (And (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s) (BddBelow.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) t))\nCase conversion may be inaccurate. Consider using '#align bdd_below_union bddBelow_union\u2093'. -/\n/-- The union of two sets is bounded above if and only if each of the sets is.-/\ntheorem bddBelow_union [SemilatticeInf \u03b3] {s t : Set \u03b3} :\n    BddBelow (s \u222a t) \u2194 BddBelow s \u2227 BddBelow t :=\n  @bddAbove_union \u03b3\u1d52\u1d48 _ s t\n#align bdd_below_union bddBelow_union\n\n/- warning: is_lub.union -> IsLUB.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {a : \u03b3} {b : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s a) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) t b) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t) (Sup.sup.{u1} \u03b3 (SemilatticeSup.toHasSup.{u1} \u03b3 _inst_3) a b))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {a : \u03b3} {b : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s a) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) t b) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t) (Sup.sup.{u1} \u03b3 (SemilatticeSup.toSup.{u1} \u03b3 _inst_3) a b))\nCase conversion may be inaccurate. Consider using '#align is_lub.union IsLUB.union\u2093'. -/\n/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,\nthen `a \u2294 b` is the least upper bound of `s \u222a t`. -/\ntheorem IsLUB.union [SemilatticeSup \u03b3] {a b : \u03b3} {s t : Set \u03b3} (hs : IsLUB s a) (ht : IsLUB t b) :\n    IsLUB (s \u222a t) (a \u2294 b) :=\n  \u27e8fun c h =>\n    h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h,\n    fun c hc =>\n    sup_le (hs.right fun d hd => hc <| Or.inl hd) (ht.right fun d hd => hc <| Or.inr hd)\u27e9\n#align is_lub.union IsLUB.union\n\n/- warning: is_glb.union -> IsGLB.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {a\u2081 : \u03b3} {a\u2082 : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s a\u2081) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) t a\u2082) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t) (Inf.inf.{u1} \u03b3 (SemilatticeInf.toHasInf.{u1} \u03b3 _inst_3) a\u2081 a\u2082))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {a\u2081 : \u03b3} {a\u2082 : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s a\u2081) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) t a\u2082) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t) (Inf.inf.{u1} \u03b3 (SemilatticeInf.toInf.{u1} \u03b3 _inst_3) a\u2081 a\u2082))\nCase conversion may be inaccurate. Consider using '#align is_glb.union IsGLB.union\u2093'. -/\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a \u2293 b` is the greatest lower bound of `s \u222a t`. -/\ntheorem IsGLB.union [SemilatticeInf \u03b3] {a\u2081 a\u2082 : \u03b3} {s t : Set \u03b3} (hs : IsGLB s a\u2081)\n    (ht : IsGLB t a\u2082) : IsGLB (s \u222a t) (a\u2081 \u2293 a\u2082) :=\n  hs.dual.union ht\n#align is_glb.union IsGLB.union\n\n/- warning: is_least.union -> IsLeast.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) s a) -> (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) t b) -> (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t) (LinearOrder.min.{u1} \u03b3 _inst_3 a b))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) s a) -> (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) t b) -> (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t) (Min.min.{u1} \u03b3 (LinearOrder.toMin.{u1} \u03b3 _inst_3) a b))\nCase conversion may be inaccurate. Consider using '#align is_least.union IsLeast.union\u2093'. -/\n/-- If `a` is the least element of `s` and `b` is the least element of `t`,\nthen `min a b` is the least element of `s \u222a t`. -/\ntheorem IsLeast.union [LinearOrder \u03b3] {a b : \u03b3} {s t : Set \u03b3} (ha : IsLeast s a)\n    (hb : IsLeast t b) : IsLeast (s \u222a t) (min a b) :=\n  \u27e8by cases' le_total a b with h h <;> simp [h, ha.1, hb.1], (ha.IsGLB.union hb.IsGLB).1\u27e9\n#align is_least.union IsLeast.union\n\n/- warning: is_greatest.union -> IsGreatest.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) s a) -> (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) t b) -> (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Union.union.{u1} (Set.{u1} \u03b3) (Set.hasUnion.{u1} \u03b3) s t) (LinearOrder.max.{u1} \u03b3 _inst_3 a b))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3} {s : Set.{u1} \u03b3} {t : Set.{u1} \u03b3}, (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) s a) -> (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) t b) -> (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Union.union.{u1} (Set.{u1} \u03b3) (Set.instUnionSet.{u1} \u03b3) s t) (Max.max.{u1} \u03b3 (LinearOrder.toMax.{u1} \u03b3 _inst_3) a b))\nCase conversion may be inaccurate. Consider using '#align is_greatest.union IsGreatest.union\u2093'. -/\n/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,\nthen `max a b` is the greatest element of `s \u222a t`. -/\ntheorem IsGreatest.union [LinearOrder \u03b3] {a b : \u03b3} {s t : Set \u03b3} (ha : IsGreatest s a)\n    (hb : IsGreatest t b) : IsGreatest (s \u222a t) (max a b) :=\n  \u27e8by cases' le_total a b with h h <;> simp [h, ha.1, hb.1], (ha.IsLUB.union hb.IsLUB).1\u27e9\n#align is_greatest.union IsGreatest.union\n\n/- warning: is_lub.inter_Ici_of_mem -> IsLUB.inter_Ici_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {s : Set.{u1} \u03b3} {a : \u03b3} {b : \u03b3}, (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) s a) -> (Membership.Mem.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasMem.{u1} \u03b3) b s) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Inter.inter.{u1} (Set.{u1} \u03b3) (Set.hasInter.{u1} \u03b3) s (Set.Ici.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) b)) a)\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {s : Set.{u1} \u03b3} {a : \u03b3} {b : \u03b3}, (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) s a) -> (Membership.mem.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instMembershipSet.{u1} \u03b3) b s) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Inter.inter.{u1} (Set.{u1} \u03b3) (Set.instInterSet.{u1} \u03b3) s (Set.Ici.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) b)) a)\nCase conversion may be inaccurate. Consider using '#align is_lub.inter_Ici_of_mem IsLUB.inter_Ici_of_mem\u2093'. -/\ntheorem IsLUB.inter_Ici_of_mem [LinearOrder \u03b3] {s : Set \u03b3} {a b : \u03b3} (ha : IsLUB s a) (hb : b \u2208 s) :\n    IsLUB (s \u2229 Ici b) a :=\n  \u27e8fun x hx => ha.1 hx.1, fun c hc =>\n    have hbc : b \u2264 c := hc \u27e8hb, le_rfl\u27e9\n    ha.2 fun x hx => (le_total x b).elim (fun hxb => hxb.trans hbc) fun hbx => hc \u27e8hx, hbx\u27e9\u27e9\n#align is_lub.inter_Ici_of_mem IsLUB.inter_Ici_of_mem\n\n/- warning: is_glb.inter_Iic_of_mem -> IsGLB.inter_Iic_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {s : Set.{u1} \u03b3} {a : \u03b3} {b : \u03b3}, (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) s a) -> (Membership.Mem.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasMem.{u1} \u03b3) b s) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Inter.inter.{u1} (Set.{u1} \u03b3) (Set.hasInter.{u1} \u03b3) s (Set.Iic.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) b)) a)\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {s : Set.{u1} \u03b3} {a : \u03b3} {b : \u03b3}, (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) s a) -> (Membership.mem.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instMembershipSet.{u1} \u03b3) b s) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Inter.inter.{u1} (Set.{u1} \u03b3) (Set.instInterSet.{u1} \u03b3) s (Set.Iic.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) b)) a)\nCase conversion may be inaccurate. Consider using '#align is_glb.inter_Iic_of_mem IsGLB.inter_Iic_of_mem\u2093'. -/\ntheorem IsGLB.inter_Iic_of_mem [LinearOrder \u03b3] {s : Set \u03b3} {a b : \u03b3} (ha : IsGLB s a) (hb : b \u2208 s) :\n    IsGLB (s \u2229 Iic b) a :=\n  ha.dual.inter_Ici_of_mem hb\n#align is_glb.inter_Iic_of_mem IsGLB.inter_Iic_of_mem\n\n#print bddAbove_iff_exists_ge /-\ntheorem bddAbove_iff_exists_ge [SemilatticeSup \u03b3] {s : Set \u03b3} (x\u2080 : \u03b3) :\n    BddAbove s \u2194 \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x :=\n  by\n  rw [bddAbove_def, exists_ge_and_iff_exists]\n  exact Monotone.ball fun x hx => monotone_le\n#align bdd_above_iff_exists_ge bddAbove_iff_exists_ge\n-/\n\n#print bddBelow_iff_exists_le /-\ntheorem bddBelow_iff_exists_le [SemilatticeInf \u03b3] {s : Set \u03b3} (x\u2080 : \u03b3) :\n    BddBelow s \u2194 \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\n  bddAbove_iff_exists_ge (toDual x\u2080)\n#align bdd_below_iff_exists_le bddBelow_iff_exists_le\n-/\n\n#print BddAbove.exists_ge /-\ntheorem BddAbove.exists_ge [SemilatticeSup \u03b3] {s : Set \u03b3} (hs : BddAbove s) (x\u2080 : \u03b3) :\n    \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x :=\n  (bddAbove_iff_exists_ge x\u2080).mp hs\n#align bdd_above.exists_ge BddAbove.exists_ge\n-/\n\n#print BddBelow.exists_le /-\ntheorem BddBelow.exists_le [SemilatticeInf \u03b3] {s : Set \u03b3} (hs : BddBelow s) (x\u2080 : \u03b3) :\n    \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\n  (bddBelow_iff_exists_le x\u2080).mp hs\n#align bdd_below.exists_le BddBelow.exists_le\n-/\n\n/-!\n### Specific sets\n\n#### Unbounded intervals\n-/\n\n\n#print isLeast_Ici /-\ntheorem isLeast_Ici : IsLeast (Ici a) a :=\n  \u27e8left_mem_Ici, fun x => id\u27e9\n#align is_least_Ici isLeast_Ici\n-/\n\n#print isGreatest_Iic /-\ntheorem isGreatest_Iic : IsGreatest (Iic a) a :=\n  \u27e8right_mem_Iic, fun x => id\u27e9\n#align is_greatest_Iic isGreatest_Iic\n-/\n\n#print isLUB_Iic /-\ntheorem isLUB_Iic : IsLUB (Iic a) a :=\n  isGreatest_Iic.IsLUB\n#align is_lub_Iic isLUB_Iic\n-/\n\n#print isGLB_Ici /-\ntheorem isGLB_Ici : IsGLB (Ici a) a :=\n  isLeast_Ici.IsGLB\n#align is_glb_Ici isGLB_Ici\n-/\n\n#print upperBounds_Iic /-\ntheorem upperBounds_Iic : upperBounds (Iic a) = Ici a :=\n  isLUB_Iic.upperBounds_eq\n#align upper_bounds_Iic upperBounds_Iic\n-/\n\n#print lowerBounds_Ici /-\ntheorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a :=\n  isGLB_Ici.lowerBounds_eq\n#align lower_bounds_Ici lowerBounds_Ici\n-/\n\n#print bddAbove_Iic /-\ntheorem bddAbove_Iic : BddAbove (Iic a) :=\n  isLUB_Iic.BddAbove\n#align bdd_above_Iic bddAbove_Iic\n-/\n\n#print bddBelow_Ici /-\ntheorem bddBelow_Ici : BddBelow (Ici a) :=\n  isGLB_Ici.BddBelow\n#align bdd_below_Ici bddBelow_Ici\n-/\n\n#print bddAbove_Iio /-\ntheorem bddAbove_Iio : BddAbove (Iio a) :=\n  \u27e8a, fun x hx => le_of_lt hx\u27e9\n#align bdd_above_Iio bddAbove_Iio\n-/\n\n#print bddBelow_Ioi /-\ntheorem bddBelow_Ioi : BddBelow (Ioi a) :=\n  \u27e8a, fun x hx => le_of_lt hx\u27e9\n#align bdd_below_Ioi bddBelow_Ioi\n-/\n\n#print lub_Iio_le /-\ntheorem lub_Iio_le (a : \u03b1) (hb : IsLUB (Set.Iio a) b) : b \u2264 a :=\n  (isLUB_le_iff hb).mpr fun k hk => le_of_lt hk\n#align lub_Iio_le lub_Iio_le\n-/\n\n#print le_glb_Ioi /-\ntheorem le_glb_Ioi (a : \u03b1) (hb : IsGLB (Set.Ioi a) b) : a \u2264 b :=\n  @lub_Iio_le \u03b1\u1d52\u1d48 _ _ a hb\n#align le_glb_Ioi le_glb_Ioi\n-/\n\n#print lub_Iio_eq_self_or_Iio_eq_Iic /-\ntheorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder \u03b3] {j : \u03b3} (i : \u03b3) (hj : IsLUB (Set.Iio i) j) :\n    j = i \u2228 Set.Iio i = Set.Iic j :=\n  by\n  cases' eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i\n  \u00b7 exact Or.inl hj_eq_i\n  \u00b7 right\n    exact Set.ext fun k => \u27e8fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i\u27e9\n#align lub_Iio_eq_self_or_Iio_eq_Iic lub_Iio_eq_self_or_Iio_eq_Iic\n-/\n\n#print glb_Ioi_eq_self_or_Ioi_eq_Ici /-\ntheorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder \u03b3] {j : \u03b3} (i : \u03b3) (hj : IsGLB (Set.Ioi i) j) :\n    j = i \u2228 Set.Ioi i = Set.Ici j :=\n  @lub_Iio_eq_self_or_Iio_eq_Iic \u03b3\u1d52\u1d48 _ j i hj\n#align glb_Ioi_eq_self_or_Ioi_eq_Ici glb_Ioi_eq_self_or_Ioi_eq_Ici\n-/\n\nsection\n\nvariable [LinearOrder \u03b3]\n\n#print exists_lub_Iio /-\ntheorem exists_lub_Iio (i : \u03b3) : \u2203 j, IsLUB (Set.Iio i) j :=\n  by\n  by_cases h_exists_lt : \u2203 j, j \u2208 upperBounds (Set.Iio i) \u2227 j < i\n  \u00b7 obtain \u27e8j, hj_ub, hj_lt_i\u27e9 := h_exists_lt\n    exact \u27e8j, hj_ub, fun k hk_ub => hk_ub hj_lt_i\u27e9\n  \u00b7 refine' \u27e8i, fun j hj => le_of_lt hj, _\u27e9\n    rw [mem_lowerBounds]\n    by_contra\n    refine' h_exists_lt _\n    push_neg  at h\n    exact h\n#align exists_lub_Iio exists_lub_Iio\n-/\n\n#print exists_glb_Ioi /-\ntheorem exists_glb_Ioi (i : \u03b3) : \u2203 j, IsGLB (Set.Ioi i) j :=\n  @exists_lub_Iio \u03b3\u1d52\u1d48 _ i\n#align exists_glb_Ioi exists_glb_Ioi\n-/\n\nvariable [DenselyOrdered \u03b3]\n\n#print isLUB_Iio /-\ntheorem isLUB_Iio {a : \u03b3} : IsLUB (Iio a) a :=\n  \u27e8fun x hx => le_of_lt hx, fun y hy => le_of_forall_ge_of_dense hy\u27e9\n#align is_lub_Iio isLUB_Iio\n-/\n\n#print isGLB_Ioi /-\ntheorem isGLB_Ioi {a : \u03b3} : IsGLB (Ioi a) a :=\n  @isLUB_Iio \u03b3\u1d52\u1d48 _ _ a\n#align is_glb_Ioi isGLB_Ioi\n-/\n\n#print upperBounds_Iio /-\ntheorem upperBounds_Iio {a : \u03b3} : upperBounds (Iio a) = Ici a :=\n  isLUB_Iio.upperBounds_eq\n#align upper_bounds_Iio upperBounds_Iio\n-/\n\n#print lowerBounds_Ioi /-\ntheorem lowerBounds_Ioi {a : \u03b3} : lowerBounds (Ioi a) = Iic a :=\n  isGLB_Ioi.lowerBounds_eq\n#align lower_bounds_Ioi lowerBounds_Ioi\n-/\n\nend\n\n/-!\n#### Singleton\n-/\n\n\n#print isGreatest_singleton /-\ntheorem isGreatest_singleton : IsGreatest {a} a :=\n  \u27e8mem_singleton a, fun x hx => le_of_eq <| eq_of_mem_singleton hx\u27e9\n#align is_greatest_singleton isGreatest_singleton\n-/\n\n#print isLeast_singleton /-\ntheorem isLeast_singleton : IsLeast {a} a :=\n  @isGreatest_singleton \u03b1\u1d52\u1d48 _ a\n#align is_least_singleton isLeast_singleton\n-/\n\n#print isLUB_singleton /-\ntheorem isLUB_singleton : IsLUB {a} a :=\n  isGreatest_singleton.IsLUB\n#align is_lub_singleton isLUB_singleton\n-/\n\n#print isGLB_singleton /-\ntheorem isGLB_singleton : IsGLB {a} a :=\n  isLeast_singleton.IsGLB\n#align is_glb_singleton isGLB_singleton\n-/\n\n#print bddAbove_singleton /-\ntheorem bddAbove_singleton : BddAbove ({a} : Set \u03b1) :=\n  isLUB_singleton.BddAbove\n#align bdd_above_singleton bddAbove_singleton\n-/\n\n#print bddBelow_singleton /-\ntheorem bddBelow_singleton : BddBelow ({a} : Set \u03b1) :=\n  isGLB_singleton.BddBelow\n#align bdd_below_singleton bddBelow_singleton\n-/\n\n#print upperBounds_singleton /-\n@[simp]\ntheorem upperBounds_singleton : upperBounds {a} = Ici a :=\n  isLUB_singleton.upperBounds_eq\n#align upper_bounds_singleton upperBounds_singleton\n-/\n\n#print lowerBounds_singleton /-\n@[simp]\ntheorem lowerBounds_singleton : lowerBounds {a} = Iic a :=\n  isGLB_singleton.lowerBounds_eq\n#align lower_bounds_singleton lowerBounds_singleton\n-/\n\n/-!\n#### Bounded intervals\n-/\n\n\n#print bddAbove_Icc /-\ntheorem bddAbove_Icc : BddAbove (Icc a b) :=\n  \u27e8b, fun _ => And.right\u27e9\n#align bdd_above_Icc bddAbove_Icc\n-/\n\n#print bddBelow_Icc /-\ntheorem bddBelow_Icc : BddBelow (Icc a b) :=\n  \u27e8a, fun _ => And.left\u27e9\n#align bdd_below_Icc bddBelow_Icc\n-/\n\n#print bddAbove_Ico /-\ntheorem bddAbove_Ico : BddAbove (Ico a b) :=\n  bddAbove_Icc.mono Ico_subset_Icc_self\n#align bdd_above_Ico bddAbove_Ico\n-/\n\n#print bddBelow_Ico /-\ntheorem bddBelow_Ico : BddBelow (Ico a b) :=\n  bddBelow_Icc.mono Ico_subset_Icc_self\n#align bdd_below_Ico bddBelow_Ico\n-/\n\n#print bddAbove_Ioc /-\ntheorem bddAbove_Ioc : BddAbove (Ioc a b) :=\n  bddAbove_Icc.mono Ioc_subset_Icc_self\n#align bdd_above_Ioc bddAbove_Ioc\n-/\n\n#print bddBelow_Ioc /-\ntheorem bddBelow_Ioc : BddBelow (Ioc a b) :=\n  bddBelow_Icc.mono Ioc_subset_Icc_self\n#align bdd_below_Ioc bddBelow_Ioc\n-/\n\n#print bddAbove_Ioo /-\ntheorem bddAbove_Ioo : BddAbove (Ioo a b) :=\n  bddAbove_Icc.mono Ioo_subset_Icc_self\n#align bdd_above_Ioo bddAbove_Ioo\n-/\n\n#print bddBelow_Ioo /-\ntheorem bddBelow_Ioo : BddBelow (Ioo a b) :=\n  bddBelow_Icc.mono Ioo_subset_Icc_self\n#align bdd_below_Ioo bddBelow_Ioo\n-/\n\n#print isGreatest_Icc /-\ntheorem isGreatest_Icc (h : a \u2264 b) : IsGreatest (Icc a b) b :=\n  \u27e8right_mem_Icc.2 h, fun x => And.right\u27e9\n#align is_greatest_Icc isGreatest_Icc\n-/\n\n#print isLUB_Icc /-\ntheorem isLUB_Icc (h : a \u2264 b) : IsLUB (Icc a b) b :=\n  (isGreatest_Icc h).IsLUB\n#align is_lub_Icc isLUB_Icc\n-/\n\n#print upperBounds_Icc /-\ntheorem upperBounds_Icc (h : a \u2264 b) : upperBounds (Icc a b) = Ici b :=\n  (isLUB_Icc h).upperBounds_eq\n#align upper_bounds_Icc upperBounds_Icc\n-/\n\n#print isLeast_Icc /-\ntheorem isLeast_Icc (h : a \u2264 b) : IsLeast (Icc a b) a :=\n  \u27e8left_mem_Icc.2 h, fun x => And.left\u27e9\n#align is_least_Icc isLeast_Icc\n-/\n\n#print isGLB_Icc /-\ntheorem isGLB_Icc (h : a \u2264 b) : IsGLB (Icc a b) a :=\n  (isLeast_Icc h).IsGLB\n#align is_glb_Icc isGLB_Icc\n-/\n\n#print lowerBounds_Icc /-\ntheorem lowerBounds_Icc (h : a \u2264 b) : lowerBounds (Icc a b) = Iic a :=\n  (isGLB_Icc h).lowerBounds_eq\n#align lower_bounds_Icc lowerBounds_Icc\n-/\n\n#print isGreatest_Ioc /-\ntheorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b :=\n  \u27e8right_mem_Ioc.2 h, fun x => And.right\u27e9\n#align is_greatest_Ioc isGreatest_Ioc\n-/\n\n#print isLUB_Ioc /-\ntheorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b :=\n  (isGreatest_Ioc h).IsLUB\n#align is_lub_Ioc isLUB_Ioc\n-/\n\n#print upperBounds_Ioc /-\ntheorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b :=\n  (isLUB_Ioc h).upperBounds_eq\n#align upper_bounds_Ioc upperBounds_Ioc\n-/\n\n#print isLeast_Ico /-\ntheorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a :=\n  \u27e8left_mem_Ico.2 h, fun x => And.left\u27e9\n#align is_least_Ico isLeast_Ico\n-/\n\n#print isGLB_Ico /-\ntheorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a :=\n  (isLeast_Ico h).IsGLB\n#align is_glb_Ico isGLB_Ico\n-/\n\n#print lowerBounds_Ico /-\ntheorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a :=\n  (isGLB_Ico h).lowerBounds_eq\n#align lower_bounds_Ico lowerBounds_Ico\n-/\n\nsection\n\nvariable [SemilatticeSup \u03b3] [DenselyOrdered \u03b3]\n\n#print isGLB_Ioo /-\ntheorem isGLB_Ioo {a b : \u03b3} (h : a < b) : IsGLB (Ioo a b) a :=\n  \u27e8fun x hx => hx.1.le, fun x hx =>\n    by\n    cases' eq_or_lt_of_le (le_sup_right : a \u2264 x \u2294 a) with h\u2081 h\u2082\n    \u00b7 exact h\u2081.symm \u25b8 le_sup_left\n    obtain \u27e8y, lty, ylt\u27e9 := exists_between h\u2082\n    apply (not_lt_of_le (sup_le (hx \u27e8lty, ylt.trans_le (sup_le _ h.le)\u27e9) lty.le) ylt).elim\n    obtain \u27e8u, au, ub\u27e9 := exists_between h\n    apply (hx \u27e8au, ub\u27e9).trans ub.le\u27e9\n#align is_glb_Ioo isGLB_Ioo\n-/\n\n#print lowerBounds_Ioo /-\ntheorem lowerBounds_Ioo {a b : \u03b3} (hab : a < b) : lowerBounds (Ioo a b) = Iic a :=\n  (isGLB_Ioo hab).lowerBounds_eq\n#align lower_bounds_Ioo lowerBounds_Ioo\n-/\n\n#print isGLB_Ioc /-\ntheorem isGLB_Ioc {a b : \u03b3} (hab : a < b) : IsGLB (Ioc a b) a :=\n  (isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self\n#align is_glb_Ioc isGLB_Ioc\n-/\n\n#print lowerBounds_Ioc /-\ntheorem lowerBounds_Ioc {a b : \u03b3} (hab : a < b) : lowerBounds (Ioc a b) = Iic a :=\n  (isGLB_Ioc hab).lowerBounds_eq\n#align lower_bound_Ioc lowerBounds_Ioc\n-/\n\nend\n\nsection\n\nvariable [SemilatticeInf \u03b3] [DenselyOrdered \u03b3]\n\n#print isLUB_Ioo /-\ntheorem isLUB_Ioo {a b : \u03b3} (hab : a < b) : IsLUB (Ioo a b) b := by\n  simpa only [dual_Ioo] using isGLB_Ioo hab.dual\n#align is_lub_Ioo isLUB_Ioo\n-/\n\n#print upperBounds_Ioo /-\ntheorem upperBounds_Ioo {a b : \u03b3} (hab : a < b) : upperBounds (Ioo a b) = Ici b :=\n  (isLUB_Ioo hab).upperBounds_eq\n#align upper_bounds_Ioo upperBounds_Ioo\n-/\n\n#print isLUB_Ico /-\ntheorem isLUB_Ico {a b : \u03b3} (hab : a < b) : IsLUB (Ico a b) b := by\n  simpa only [dual_Ioc] using isGLB_Ioc hab.dual\n#align is_lub_Ico isLUB_Ico\n-/\n\n#print upperBounds_Ico /-\ntheorem upperBounds_Ico {a b : \u03b3} (hab : a < b) : upperBounds (Ico a b) = Ici b :=\n  (isLUB_Ico hab).upperBounds_eq\n#align upper_bounds_Ico upperBounds_Ico\n-/\n\nend\n\n#print bddBelow_iff_subset_Ici /-\ntheorem bddBelow_iff_subset_Ici : BddBelow s \u2194 \u2203 a, s \u2286 Ici a :=\n  Iff.rfl\n#align bdd_below_iff_subset_Ici bddBelow_iff_subset_Ici\n-/\n\n#print bddAbove_iff_subset_Iic /-\ntheorem bddAbove_iff_subset_Iic : BddAbove s \u2194 \u2203 a, s \u2286 Iic a :=\n  Iff.rfl\n#align bdd_above_iff_subset_Iic bddAbove_iff_subset_Iic\n-/\n\n#print bddBelow_bddAbove_iff_subset_Icc /-\ntheorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s \u2227 BddAbove s \u2194 \u2203 a b, s \u2286 Icc a b := by\n  simp only [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici, bddAbove_iff_subset_Iic,\n    exists_and_left, exists_and_right]\n#align bdd_below_bdd_above_iff_subset_Icc bddBelow_bddAbove_iff_subset_Icc\n-/\n\n/-!\n#### Univ\n-/\n\n\n#print isGreatest_univ_iff /-\n@[simp]\ntheorem isGreatest_univ_iff : IsGreatest univ a \u2194 IsTop a := by\n  simp [IsGreatest, mem_upperBounds, IsTop]\n#align is_greatest_univ_iff isGreatest_univ_iff\n-/\n\n/- warning: is_greatest_univ -> isGreatest_univ is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsGreatest.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toHasTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsGreatest.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nCase conversion may be inaccurate. Consider using '#align is_greatest_univ isGreatest_univ\u2093'. -/\ntheorem isGreatest_univ [OrderTop \u03b1] : IsGreatest (univ : Set \u03b1) \u22a4 :=\n  isGreatest_univ_iff.2 isTop_top\n#align is_greatest_univ isGreatest_univ\n\n/- warning: order_top.upper_bounds_univ -> OrderTop.upperBounds_univ is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : PartialOrder.{u1} \u03b3] [_inst_4 : OrderTop.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3))], Eq.{succ u1} (Set.{u1} \u03b3) (upperBounds.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3) (Set.univ.{u1} \u03b3)) (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasSingleton.{u1} \u03b3) (Top.top.{u1} \u03b3 (OrderTop.toHasTop.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3)) _inst_4)))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : PartialOrder.{u1} \u03b3] [_inst_4 : OrderTop.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3))], Eq.{succ u1} (Set.{u1} \u03b3) (upperBounds.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3) (Set.univ.{u1} \u03b3)) (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instSingletonSet.{u1} \u03b3) (Top.top.{u1} \u03b3 (OrderTop.toTop.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3)) _inst_4)))\nCase conversion may be inaccurate. Consider using '#align order_top.upper_bounds_univ OrderTop.upperBounds_univ\u2093'. -/\n@[simp]\ntheorem OrderTop.upperBounds_univ [PartialOrder \u03b3] [OrderTop \u03b3] :\n    upperBounds (univ : Set \u03b3) = {\u22a4} := by rw [is_greatest_univ.upper_bounds_eq, Ici_top]\n#align order_top.upper_bounds_univ OrderTop.upperBounds_univ\n\n/- warning: is_lub_univ -> isLUB_univ is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsLUB.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toHasTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsLUB.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Top.top.{u1} \u03b1 (OrderTop.toTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nCase conversion may be inaccurate. Consider using '#align is_lub_univ isLUB_univ\u2093'. -/\ntheorem isLUB_univ [OrderTop \u03b1] : IsLUB (univ : Set \u03b1) \u22a4 :=\n  isGreatest_univ.IsLUB\n#align is_lub_univ isLUB_univ\n\n/- warning: order_bot.lower_bounds_univ -> OrderBot.lowerBounds_univ is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : PartialOrder.{u1} \u03b3] [_inst_4 : OrderBot.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3))], Eq.{succ u1} (Set.{u1} \u03b3) (lowerBounds.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3) (Set.univ.{u1} \u03b3)) (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasSingleton.{u1} \u03b3) (Bot.bot.{u1} \u03b3 (OrderBot.toHasBot.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3)) _inst_4)))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : PartialOrder.{u1} \u03b3] [_inst_4 : OrderBot.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3))], Eq.{succ u1} (Set.{u1} \u03b3) (lowerBounds.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3) (Set.univ.{u1} \u03b3)) (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instSingletonSet.{u1} \u03b3) (Bot.bot.{u1} \u03b3 (OrderBot.toBot.{u1} \u03b3 (Preorder.toLE.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 _inst_3)) _inst_4)))\nCase conversion may be inaccurate. Consider using '#align order_bot.lower_bounds_univ OrderBot.lowerBounds_univ\u2093'. -/\n@[simp]\ntheorem OrderBot.lowerBounds_univ [PartialOrder \u03b3] [OrderBot \u03b3] :\n    lowerBounds (univ : Set \u03b3) = {\u22a5} :=\n  @OrderTop.upperBounds_univ \u03b3\u1d52\u1d48 _ _\n#align order_bot.lower_bounds_univ OrderBot.lowerBounds_univ\n\n#print isLeast_univ_iff /-\n@[simp]\ntheorem isLeast_univ_iff : IsLeast univ a \u2194 IsBot a :=\n  @isGreatest_univ_iff \u03b1\u1d52\u1d48 _ _\n#align is_least_univ_iff isLeast_univ_iff\n-/\n\n/- warning: is_least_univ -> isLeast_univ is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsLeast.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toHasBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsLeast.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nCase conversion may be inaccurate. Consider using '#align is_least_univ isLeast_univ\u2093'. -/\ntheorem isLeast_univ [OrderBot \u03b1] : IsLeast (univ : Set \u03b1) \u22a5 :=\n  @isGreatest_univ \u03b1\u1d52\u1d48 _ _\n#align is_least_univ isLeast_univ\n\n/- warning: is_glb_univ -> isGLB_univ is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsGLB.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toHasBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsGLB.{u1} \u03b1 _inst_1 (Set.univ.{u1} \u03b1) (Bot.bot.{u1} \u03b1 (OrderBot.toBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nCase conversion may be inaccurate. Consider using '#align is_glb_univ isGLB_univ\u2093'. -/\ntheorem isGLB_univ [OrderBot \u03b1] : IsGLB (univ : Set \u03b1) \u22a5 :=\n  isLeast_univ.IsGLB\n#align is_glb_univ isGLB_univ\n\n#print NoMaxOrder.upperBounds_univ /-\n@[simp]\ntheorem NoMaxOrder.upperBounds_univ [NoMaxOrder \u03b1] : upperBounds (univ : Set \u03b1) = \u2205 :=\n  eq_empty_of_subset_empty fun b hb =>\n    let \u27e8x, hx\u27e9 := exists_gt b\n    not_le_of_lt hx (hb trivial)\n#align no_max_order.upper_bounds_univ NoMaxOrder.upperBounds_univ\n-/\n\n#print NoMinOrder.lowerBounds_univ /-\n@[simp]\ntheorem NoMinOrder.lowerBounds_univ [NoMinOrder \u03b1] : lowerBounds (univ : Set \u03b1) = \u2205 :=\n  @NoMaxOrder.upperBounds_univ \u03b1\u1d52\u1d48 _ _\n#align no_min_order.lower_bounds_univ NoMinOrder.lowerBounds_univ\n-/\n\n#print not_bddAbove_univ /-\n@[simp]\ntheorem not_bddAbove_univ [NoMaxOrder \u03b1] : \u00acBddAbove (univ : Set \u03b1) := by simp [BddAbove]\n#align not_bdd_above_univ not_bddAbove_univ\n-/\n\n#print not_bddBelow_univ /-\n@[simp]\ntheorem not_bddBelow_univ [NoMinOrder \u03b1] : \u00acBddBelow (univ : Set \u03b1) :=\n  @not_bddAbove_univ \u03b1\u1d52\u1d48 _ _\n#align not_bdd_below_univ not_bddBelow_univ\n-/\n\n/-!\n#### Empty set\n-/\n\n\n#print upperBounds_empty /-\n@[simp]\ntheorem upperBounds_empty : upperBounds (\u2205 : Set \u03b1) = univ := by\n  simp only [upperBounds, eq_univ_iff_forall, mem_set_of_eq, ball_empty_iff, forall_true_iff]\n#align upper_bounds_empty upperBounds_empty\n-/\n\n#print lowerBounds_empty /-\n@[simp]\ntheorem lowerBounds_empty : lowerBounds (\u2205 : Set \u03b1) = univ :=\n  @upperBounds_empty \u03b1\u1d52\u1d48 _\n#align lower_bounds_empty lowerBounds_empty\n-/\n\n#print bddAbove_empty /-\n@[simp]\ntheorem bddAbove_empty [Nonempty \u03b1] : BddAbove (\u2205 : Set \u03b1) := by\n  simp only [BddAbove, upperBounds_empty, univ_nonempty]\n#align bdd_above_empty bddAbove_empty\n-/\n\n#print bddBelow_empty /-\n@[simp]\ntheorem bddBelow_empty [Nonempty \u03b1] : BddBelow (\u2205 : Set \u03b1) := by\n  simp only [BddBelow, lowerBounds_empty, univ_nonempty]\n#align bdd_below_empty bddBelow_empty\n-/\n\n#print isGLB_empty_iff /-\n@[simp]\ntheorem isGLB_empty_iff : IsGLB \u2205 a \u2194 IsTop a := by simp [IsGLB]\n#align is_glb_empty_iff isGLB_empty_iff\n-/\n\n#print isLUB_empty_iff /-\n@[simp]\ntheorem isLUB_empty_iff : IsLUB \u2205 a \u2194 IsBot a :=\n  @isGLB_empty_iff \u03b1\u1d52\u1d48 _ _\n#align is_lub_empty_iff isLUB_empty_iff\n-/\n\n/- warning: is_glb_empty -> isGLB_empty is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsGLB.{u1} \u03b1 _inst_1 (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1)) (Top.top.{u1} \u03b1 (OrderTop.toHasTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsGLB.{u1} \u03b1 _inst_1 (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1)) (Top.top.{u1} \u03b1 (OrderTop.toTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nCase conversion may be inaccurate. Consider using '#align is_glb_empty isGLB_empty\u2093'. -/\ntheorem isGLB_empty [OrderTop \u03b1] : IsGLB \u2205 (\u22a4 : \u03b1) :=\n  isGLB_empty_iff.2 isTop_top\n#align is_glb_empty isGLB_empty\n\n/- warning: is_lub_empty -> isLUB_empty is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsLUB.{u1} \u03b1 _inst_1 (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1)) (Bot.bot.{u1} \u03b1 (OrderBot.toHasBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_3 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1)], IsLUB.{u1} \u03b1 _inst_1 (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1)) (Bot.bot.{u1} \u03b1 (OrderBot.toBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_1) _inst_3))\nCase conversion may be inaccurate. Consider using '#align is_lub_empty isLUB_empty\u2093'. -/\ntheorem isLUB_empty [OrderBot \u03b1] : IsLUB \u2205 (\u22a5 : \u03b1) :=\n  @isGLB_empty \u03b1\u1d52\u1d48 _ _\n#align is_lub_empty isLUB_empty\n\n#print IsLUB.nonempty /-\ntheorem IsLUB.nonempty [NoMinOrder \u03b1] (hs : IsLUB s a) : s.Nonempty :=\n  let \u27e8a', ha'\u27e9 := exists_lt a\n  nonempty_iff_ne_empty.2 fun h =>\n    not_le_of_lt ha' <| hs.right <| by simp only [h, upperBounds_empty]\n#align is_lub.nonempty IsLUB.nonempty\n-/\n\n#print IsGLB.nonempty /-\ntheorem IsGLB.nonempty [NoMaxOrder \u03b1] (hs : IsGLB s a) : s.Nonempty :=\n  hs.dual.Nonempty\n#align is_glb.nonempty IsGLB.nonempty\n-/\n\n#print nonempty_of_not_bddAbove /-\ntheorem nonempty_of_not_bddAbove [ha : Nonempty \u03b1] (h : \u00acBddAbove s) : s.Nonempty :=\n  Nonempty.elim ha fun x => (not_bddAbove_iff'.1 h x).imp fun a ha => ha.fst\n#align nonempty_of_not_bdd_above nonempty_of_not_bddAbove\n-/\n\n#print nonempty_of_not_bddBelow /-\ntheorem nonempty_of_not_bddBelow [ha : Nonempty \u03b1] (h : \u00acBddBelow s) : s.Nonempty :=\n  @nonempty_of_not_bddAbove \u03b1\u1d52\u1d48 _ _ _ h\n#align nonempty_of_not_bdd_below nonempty_of_not_bddBelow\n-/\n\n/-!\n#### insert\n-/\n\n\n#print bddAbove_insert /-\n/-- Adding a point to a set preserves its boundedness above. -/\n@[simp]\ntheorem bddAbove_insert [SemilatticeSup \u03b3] (a : \u03b3) {s : Set \u03b3} :\n    BddAbove (insert a s) \u2194 BddAbove s := by\n  simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and_iff]\n#align bdd_above_insert bddAbove_insert\n-/\n\n#print BddAbove.insert /-\ntheorem BddAbove.insert [SemilatticeSup \u03b3] (a : \u03b3) {s : Set \u03b3} (hs : BddAbove s) :\n    BddAbove (insert a s) :=\n  (bddAbove_insert a).2 hs\n#align bdd_above.insert BddAbove.insert\n-/\n\n#print bddBelow_insert /-\n/-- Adding a point to a set preserves its boundedness below.-/\n@[simp]\ntheorem bddBelow_insert [SemilatticeInf \u03b3] (a : \u03b3) {s : Set \u03b3} :\n    BddBelow (insert a s) \u2194 BddBelow s := by\n  simp only [insert_eq, bddBelow_union, bddBelow_singleton, true_and_iff]\n#align bdd_below_insert bddBelow_insert\n-/\n\n#print BddBelow.insert /-\ntheorem BddBelow.insert [SemilatticeInf \u03b3] (a : \u03b3) {s : Set \u03b3} (hs : BddBelow s) :\n    BddBelow (insert a s) :=\n  (bddBelow_insert a).2 hs\n#align bdd_below.insert BddBelow.insert\n-/\n\n/- warning: is_lub.insert -> IsLUB.insert is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s b) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a s) (Sup.sup.{u1} \u03b3 (SemilatticeSup.toHasSup.{u1} \u03b3 _inst_3) a b))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) s b) -> (IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a s) (Sup.sup.{u1} \u03b3 (SemilatticeSup.toSup.{u1} \u03b3 _inst_3) a b))\nCase conversion may be inaccurate. Consider using '#align is_lub.insert IsLUB.insert\u2093'. -/\ntheorem IsLUB.insert [SemilatticeSup \u03b3] (a) {b} {s : Set \u03b3} (hs : IsLUB s b) :\n    IsLUB (insert a s) (a \u2294 b) := by\n  rw [insert_eq]\n  exact is_lub_singleton.union hs\n#align is_lub.insert IsLUB.insert\n\n/- warning: is_glb.insert -> IsGLB.insert is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s b) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a s) (Inf.inf.{u1} \u03b3 (SemilatticeInf.toHasInf.{u1} \u03b3 _inst_3) a b))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) s b) -> (IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a s) (Inf.inf.{u1} \u03b3 (SemilatticeInf.toInf.{u1} \u03b3 _inst_3) a b))\nCase conversion may be inaccurate. Consider using '#align is_glb.insert IsGLB.insert\u2093'. -/\ntheorem IsGLB.insert [SemilatticeInf \u03b3] (a) {b} {s : Set \u03b3} (hs : IsGLB s b) :\n    IsGLB (insert a s) (a \u2293 b) := by\n  rw [insert_eq]\n  exact is_glb_singleton.union hs\n#align is_glb.insert IsGLB.insert\n\n/- warning: is_greatest.insert -> IsGreatest.insert is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) s b) -> (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a s) (LinearOrder.max.{u1} \u03b3 _inst_3 a b))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) s b) -> (IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a s) (Max.max.{u1} \u03b3 (LinearOrder.toMax.{u1} \u03b3 _inst_3) a b))\nCase conversion may be inaccurate. Consider using '#align is_greatest.insert IsGreatest.insert\u2093'. -/\ntheorem IsGreatest.insert [LinearOrder \u03b3] (a) {b} {s : Set \u03b3} (hs : IsGreatest s b) :\n    IsGreatest (insert a s) (max a b) := by\n  rw [insert_eq]\n  exact is_greatest_singleton.union hs\n#align is_greatest.insert IsGreatest.insert\n\n/- warning: is_least.insert -> IsLeast.insert is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) s b) -> (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a s) (LinearOrder.min.{u1} \u03b3 _inst_3 a b))\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] (a : \u03b3) {b : \u03b3} {s : Set.{u1} \u03b3}, (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) s b) -> (IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a s) (Min.min.{u1} \u03b3 (LinearOrder.toMin.{u1} \u03b3 _inst_3) a b))\nCase conversion may be inaccurate. Consider using '#align is_least.insert IsLeast.insert\u2093'. -/\ntheorem IsLeast.insert [LinearOrder \u03b3] (a) {b} {s : Set \u03b3} (hs : IsLeast s b) :\n    IsLeast (insert a s) (min a b) := by\n  rw [insert_eq]\n  exact is_least_singleton.union hs\n#align is_least.insert IsLeast.insert\n\n/- warning: upper_bounds_insert -> upperBounds_insert is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] (a : \u03b1) (s : Set.{u1} \u03b1), Eq.{succ u1} (Set.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (Set.Ici.{u1} \u03b1 _inst_1 a) (upperBounds.{u1} \u03b1 _inst_1 s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] (a : \u03b1) (s : Set.{u1} \u03b1), Eq.{succ u1} (Set.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instInsertSet.{u1} \u03b1) a s)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (Set.Ici.{u1} \u03b1 _inst_1 a) (upperBounds.{u1} \u03b1 _inst_1 s))\nCase conversion may be inaccurate. Consider using '#align upper_bounds_insert upperBounds_insert\u2093'. -/\n@[simp]\ntheorem upperBounds_insert (a : \u03b1) (s : Set \u03b1) : upperBounds (insert a s) = Ici a \u2229 upperBounds s :=\n  by rw [insert_eq, upperBounds_union, upperBounds_singleton]\n#align upper_bounds_insert upperBounds_insert\n\n/- warning: lower_bounds_insert -> lowerBounds_insert is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] (a : \u03b1) (s : Set.{u1} \u03b1), Eq.{succ u1} (Set.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasInsert.{u1} \u03b1) a s)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (Set.Iic.{u1} \u03b1 _inst_1 a) (lowerBounds.{u1} \u03b1 _inst_1 s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] (a : \u03b1) (s : Set.{u1} \u03b1), Eq.{succ u1} (Set.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 (Insert.insert.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instInsertSet.{u1} \u03b1) a s)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (Set.Iic.{u1} \u03b1 _inst_1 a) (lowerBounds.{u1} \u03b1 _inst_1 s))\nCase conversion may be inaccurate. Consider using '#align lower_bounds_insert lowerBounds_insert\u2093'. -/\n@[simp]\ntheorem lowerBounds_insert (a : \u03b1) (s : Set \u03b1) : lowerBounds (insert a s) = Iic a \u2229 lowerBounds s :=\n  by rw [insert_eq, lowerBounds_union, lowerBounds_singleton]\n#align lower_bounds_insert lowerBounds_insert\n\n#print OrderTop.bddAbove /-\n/-- When there is a global maximum, every set is bounded above. -/\n@[simp]\nprotected theorem OrderTop.bddAbove [OrderTop \u03b1] (s : Set \u03b1) : BddAbove s :=\n  \u27e8\u22a4, fun a ha => OrderTop.le_top a\u27e9\n#align order_top.bdd_above OrderTop.bddAbove\n-/\n\n#print OrderBot.bddBelow /-\n/-- When there is a global minimum, every set is bounded below. -/\n@[simp]\nprotected theorem OrderBot.bddBelow [OrderBot \u03b1] (s : Set \u03b1) : BddBelow s :=\n  \u27e8\u22a5, fun a ha => OrderBot.bot_le a\u27e9\n#align order_bot.bdd_below OrderBot.bddBelow\n-/\n\n/-!\n#### Pair\n-/\n\n\n/- warning: is_lub_pair -> isLUB_pair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasSingleton.{u1} \u03b3) b)) (Sup.sup.{u1} \u03b3 (SemilatticeSup.toHasSup.{u1} \u03b3 _inst_3) a b)\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsLUB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeSup.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instSingletonSet.{u1} \u03b3) b)) (Sup.sup.{u1} \u03b3 (SemilatticeSup.toSup.{u1} \u03b3 _inst_3) a b)\nCase conversion may be inaccurate. Consider using '#align is_lub_pair isLUB_pair\u2093'. -/\ntheorem isLUB_pair [SemilatticeSup \u03b3] {a b : \u03b3} : IsLUB {a, b} (a \u2294 b) :=\n  isLUB_singleton.insert _\n#align is_lub_pair isLUB_pair\n\n/- warning: is_glb_pair -> isGLB_pair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasSingleton.{u1} \u03b3) b)) (Inf.inf.{u1} \u03b3 (SemilatticeInf.toHasInf.{u1} \u03b3 _inst_3) a b)\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsGLB.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 _inst_3)) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instSingletonSet.{u1} \u03b3) b)) (Inf.inf.{u1} \u03b3 (SemilatticeInf.toInf.{u1} \u03b3 _inst_3) a b)\nCase conversion may be inaccurate. Consider using '#align is_glb_pair isGLB_pair\u2093'. -/\ntheorem isGLB_pair [SemilatticeInf \u03b3] {a b : \u03b3} : IsGLB {a, b} (a \u2293 b) :=\n  isGLB_singleton.insert _\n#align is_glb_pair isGLB_pair\n\n/- warning: is_least_pair -> isLeast_pair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasSingleton.{u1} \u03b3) b)) (LinearOrder.min.{u1} \u03b3 _inst_3 a b)\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsLeast.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instSingletonSet.{u1} \u03b3) b)) (Min.min.{u1} \u03b3 (LinearOrder.toMin.{u1} \u03b3 _inst_3) a b)\nCase conversion may be inaccurate. Consider using '#align is_least_pair isLeast_pair\u2093'. -/\ntheorem isLeast_pair [LinearOrder \u03b3] {a b : \u03b3} : IsLeast {a, b} (min a b) :=\n  isLeast_singleton.insert _\n#align is_least_pair isLeast_pair\n\n/- warning: is_greatest_pair -> isGreatest_pair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (LinearOrder.toLattice.{u1} \u03b3 _inst_3)))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasInsert.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.hasSingleton.{u1} \u03b3) b)) (LinearOrder.max.{u1} \u03b3 _inst_3 a b)\nbut is expected to have type\n  forall {\u03b3 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b3] {a : \u03b3} {b : \u03b3}, IsGreatest.{u1} \u03b3 (PartialOrder.toPreorder.{u1} \u03b3 (SemilatticeInf.toPartialOrder.{u1} \u03b3 (Lattice.toSemilatticeInf.{u1} \u03b3 (DistribLattice.toLattice.{u1} \u03b3 (instDistribLattice.{u1} \u03b3 _inst_3))))) (Insert.insert.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instInsertSet.{u1} \u03b3) a (Singleton.singleton.{u1, u1} \u03b3 (Set.{u1} \u03b3) (Set.instSingletonSet.{u1} \u03b3) b)) (Max.max.{u1} \u03b3 (LinearOrder.toMax.{u1} \u03b3 _inst_3) a b)\nCase conversion may be inaccurate. Consider using '#align is_greatest_pair isGreatest_pair\u2093'. -/\ntheorem isGreatest_pair [LinearOrder \u03b3] {a b : \u03b3} : IsGreatest {a, b} (max a b) :=\n  isGreatest_singleton.insert _\n#align is_greatest_pair isGreatest_pair\n\n/-!\n#### Lower/upper bounds\n-/\n\n\n#print isLUB_lowerBounds /-\n@[simp]\ntheorem isLUB_lowerBounds : IsLUB (lowerBounds s) a \u2194 IsGLB s a :=\n  \u27e8fun H => \u27e8fun x hx => H.2 <| subset_upperBounds_lowerBounds s hx, H.1\u27e9, IsGreatest.isLUB\u27e9\n#align is_lub_lower_bounds isLUB_lowerBounds\n-/\n\n#print isGLB_upperBounds /-\n@[simp]\ntheorem isGLB_upperBounds : IsGLB (upperBounds s) a \u2194 IsLUB s a :=\n  @isLUB_lowerBounds \u03b1\u1d52\u1d48 _ _ _\n#align is_glb_upper_bounds isGLB_upperBounds\n-/\n\nend\n\n/-!\n### (In)equalities with the least upper bound and the greatest lower bound\n-/\n\n\nsection Preorder\n\nvariable [Preorder \u03b1] {s : Set \u03b1} {a b : \u03b1}\n\n#print lowerBounds_le_upperBounds /-\ntheorem lowerBounds_le_upperBounds (ha : a \u2208 lowerBounds s) (hb : b \u2208 upperBounds s) :\n    s.Nonempty \u2192 a \u2264 b\n  | \u27e8c, hc\u27e9 => le_trans (ha hc) (hb hc)\n#align lower_bounds_le_upper_bounds lowerBounds_le_upperBounds\n-/\n\n#print isGLB_le_isLUB /-\ntheorem isGLB_le_isLUB (ha : IsGLB s a) (hb : IsLUB s b) (hs : s.Nonempty) : a \u2264 b :=\n  lowerBounds_le_upperBounds ha.1 hb.1 hs\n#align is_glb_le_is_lub isGLB_le_isLUB\n-/\n\n/- warning: is_lub_lt_iff -> isLUB_lt_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 _inst_1 s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) a b) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c (upperBounds.{u1} \u03b1 _inst_1 s)) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c (upperBounds.{u1} \u03b1 _inst_1 s)) => LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) c b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 _inst_1 s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) a b) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c (upperBounds.{u1} \u03b1 _inst_1 s)) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) c b))))\nCase conversion may be inaccurate. Consider using '#align is_lub_lt_iff isLUB_lt_iff\u2093'. -/\ntheorem isLUB_lt_iff (ha : IsLUB s a) : a < b \u2194 \u2203 c \u2208 upperBounds s, c < b :=\n  \u27e8fun hb => \u27e8a, ha.1, hb\u27e9, fun \u27e8c, hcs, hcb\u27e9 => lt_of_le_of_lt (ha.2 hcs) hcb\u27e9\n#align is_lub_lt_iff isLUB_lt_iff\n\n/- warning: lt_is_glb_iff -> lt_isGLB_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 _inst_1 s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) b a) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c (lowerBounds.{u1} \u03b1 _inst_1 s)) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c (lowerBounds.{u1} \u03b1 _inst_1 s)) => LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) b c))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 _inst_1 s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) b a) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c (lowerBounds.{u1} \u03b1 _inst_1 s)) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) b c))))\nCase conversion may be inaccurate. Consider using '#align lt_is_glb_iff lt_isGLB_iff\u2093'. -/\ntheorem lt_isGLB_iff (ha : IsGLB s a) : b < a \u2194 \u2203 c \u2208 lowerBounds s, b < c :=\n  isLUB_lt_iff ha.dual\n#align lt_is_glb_iff lt_isGLB_iff\n\n#print le_of_isLUB_le_isGLB /-\ntheorem le_of_isLUB_le_isGLB {x y} (ha : IsGLB s a) (hb : IsLUB s b) (hab : b \u2264 a) (hx : x \u2208 s)\n    (hy : y \u2208 s) : x \u2264 y :=\n  calc\n    x \u2264 b := hb.1 hx\n    _ \u2264 a := hab\n    _ \u2264 y := ha.1 hy\n    \n#align le_of_is_lub_le_is_glb le_of_isLUB_le_isGLB\n-/\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b1] {s : Set \u03b1} {a b : \u03b1}\n\n#print IsLeast.unique /-\ntheorem IsLeast.unique (Ha : IsLeast s a) (Hb : IsLeast s b) : a = b :=\n  le_antisymm (Ha.right Hb.left) (Hb.right Ha.left)\n#align is_least.unique IsLeast.unique\n-/\n\n#print IsLeast.isLeast_iff_eq /-\ntheorem IsLeast.isLeast_iff_eq (Ha : IsLeast s a) : IsLeast s b \u2194 a = b :=\n  Iff.intro Ha.unique fun h => h \u25b8 Ha\n#align is_least.is_least_iff_eq IsLeast.isLeast_iff_eq\n-/\n\n#print IsGreatest.unique /-\ntheorem IsGreatest.unique (Ha : IsGreatest s a) (Hb : IsGreatest s b) : a = b :=\n  le_antisymm (Hb.right Ha.left) (Ha.right Hb.left)\n#align is_greatest.unique IsGreatest.unique\n-/\n\n#print IsGreatest.isGreatest_iff_eq /-\ntheorem IsGreatest.isGreatest_iff_eq (Ha : IsGreatest s a) : IsGreatest s b \u2194 a = b :=\n  Iff.intro Ha.unique fun h => h \u25b8 Ha\n#align is_greatest.is_greatest_iff_eq IsGreatest.isGreatest_iff_eq\n-/\n\n#print IsLUB.unique /-\ntheorem IsLUB.unique (Ha : IsLUB s a) (Hb : IsLUB s b) : a = b :=\n  Ha.unique Hb\n#align is_lub.unique IsLUB.unique\n-/\n\n#print IsGLB.unique /-\ntheorem IsGLB.unique (Ha : IsGLB s a) (Hb : IsGLB s b) : a = b :=\n  Ha.unique Hb\n#align is_glb.unique IsGLB.unique\n-/\n\n#print Set.subsingleton_of_isLUB_le_isGLB /-\ntheorem Set.subsingleton_of_isLUB_le_isGLB (Ha : IsGLB s a) (Hb : IsLUB s b) (hab : b \u2264 a) :\n    s.Subsingleton := fun x hx y hy =>\n  le_antisymm (le_of_isLUB_le_isGLB Ha Hb hab hx hy) (le_of_isLUB_le_isGLB Ha Hb hab hy hx)\n#align set.subsingleton_of_is_lub_le_is_glb Set.subsingleton_of_isLUB_le_isGLB\n-/\n\n#print isGLB_lt_isLUB_of_ne /-\ntheorem isGLB_lt_isLUB_of_ne (Ha : IsGLB s a) (Hb : IsLUB s b) {x y} (Hx : x \u2208 s) (Hy : y \u2208 s)\n    (Hxy : x \u2260 y) : a < b :=\n  lt_iff_le_not_le.2\n    \u27e8lowerBounds_le_upperBounds Ha.1 Hb.1 \u27e8x, Hx\u27e9, fun hab =>\n      Hxy <| Set.subsingleton_of_isLUB_le_isGLB Ha Hb hab Hx Hy\u27e9\n#align is_glb_lt_is_lub_of_ne isGLB_lt_isLUB_of_ne\n-/\n\nend PartialOrder\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] {s : Set \u03b1} {a b : \u03b1}\n\n/- warning: lt_is_lub_iff -> lt_isLUB_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) b a) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) => LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) b c))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) b a) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c s) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) b c))))\nCase conversion may be inaccurate. Consider using '#align lt_is_lub_iff lt_isLUB_iff\u2093'. -/\ntheorem lt_isLUB_iff (h : IsLUB s a) : b < a \u2194 \u2203 c \u2208 s, b < c := by\n  simp only [\u2190 not_le, isLUB_le_iff h, mem_upperBounds, not_forall]\n#align lt_is_lub_iff lt_isLUB_iff\n\n/- warning: is_glb_lt_iff -> isGLB_lt_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) a b) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) => LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) c b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s a) -> (Iff (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) a b) (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c s) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) c b))))\nCase conversion may be inaccurate. Consider using '#align is_glb_lt_iff isGLB_lt_iff\u2093'. -/\ntheorem isGLB_lt_iff (h : IsGLB s a) : a < b \u2194 \u2203 c \u2208 s, c < b :=\n  lt_isLUB_iff h.dual\n#align is_glb_lt_iff isGLB_lt_iff\n\n/- warning: is_lub.exists_between -> IsLUB.exists_between is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s a) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) b a) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) => And (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) b c) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) c a))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s a) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) b a) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c s) (And (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) b c) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) c a))))\nCase conversion may be inaccurate. Consider using '#align is_lub.exists_between IsLUB.exists_between\u2093'. -/\ntheorem IsLUB.exists_between (h : IsLUB s a) (hb : b < a) : \u2203 c \u2208 s, b < c \u2227 c \u2264 a :=\n  let \u27e8c, hcs, hbc\u27e9 := (lt_isLUB_iff h).1 hb\n  \u27e8c, hcs, hbc, h.1 hcs\u27e9\n#align is_lub.exists_between IsLUB.exists_between\n\n/- warning: is_lub.exists_between' -> IsLUB.exists_between' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s a) -> (Not (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s)) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) b a) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) => And (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) b c) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) c a))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsLUB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s a) -> (Not (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a s)) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) b a) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c s) (And (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) b c) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) c a))))\nCase conversion may be inaccurate. Consider using '#align is_lub.exists_between' IsLUB.exists_between'\u2093'. -/\ntheorem IsLUB.exists_between' (h : IsLUB s a) (h' : a \u2209 s) (hb : b < a) : \u2203 c \u2208 s, b < c \u2227 c < a :=\n  let \u27e8c, hcs, hbc, hca\u27e9 := h.exists_between hb\n  \u27e8c, hcs, hbc, hca.lt_of_ne fun hac => h' <| hac \u25b8 hcs\u27e9\n#align is_lub.exists_between' IsLUB.exists_between'\n\n/- warning: is_glb.exists_between -> IsGLB.exists_between is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s a) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) a b) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) => And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) a c) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) c b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s a) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) a b) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c s) (And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) a c) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) c b))))\nCase conversion may be inaccurate. Consider using '#align is_glb.exists_between IsGLB.exists_between\u2093'. -/\ntheorem IsGLB.exists_between (h : IsGLB s a) (hb : a < b) : \u2203 c \u2208 s, a \u2264 c \u2227 c < b :=\n  let \u27e8c, hcs, hbc\u27e9 := (isGLB_lt_iff h).1 hb\n  \u27e8c, hcs, h.1 hcs, hbc\u27e9\n#align is_glb.exists_between IsGLB.exists_between\n\n/- warning: is_glb.exists_between' -> IsGLB.exists_between' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s a) -> (Not (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s)) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) a b) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => Exists.{0} (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) (fun (H : Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) => And (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) a c) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) c b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {a : \u03b1} {b : \u03b1}, (IsGLB.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s a) -> (Not (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a s)) -> (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) a b) -> (Exists.{succ u1} \u03b1 (fun (c : \u03b1) => And (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) c s) (And (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) a c) (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) c b))))\nCase conversion may be inaccurate. Consider using '#align is_glb.exists_between' IsGLB.exists_between'\u2093'. -/\ntheorem IsGLB.exists_between' (h : IsGLB s a) (h' : a \u2209 s) (hb : a < b) : \u2203 c \u2208 s, a < c \u2227 c < b :=\n  let \u27e8c, hcs, hac, hcb\u27e9 := h.exists_between hb\n  \u27e8c, hcs, hac.lt_of_ne fun hac => h' <| hac.symm \u25b8 hcs, hcb\u27e9\n#align is_glb.exists_between' IsGLB.exists_between'\n\nend LinearOrder\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\n\nnamespace MonotoneOn\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : Set \u03b1} (Hf : MonotoneOn f t) {a : \u03b1}\n  (Hst : s \u2286 t)\n\ninclude Hf\n\n#print MonotoneOn.mem_upperBounds_image /-\ntheorem mem_upperBounds_image (Has : a \u2208 upperBounds s) (Hat : a \u2208 t) :\n    f a \u2208 upperBounds (f '' s) :=\n  ball_image_of_ball fun x H => Hf (Hst H) Hat (Has H)\n#align monotone_on.mem_upper_bounds_image MonotoneOn.mem_upperBounds_image\n-/\n\n#print MonotoneOn.mem_upperBounds_image_self /-\ntheorem mem_upperBounds_image_self : a \u2208 upperBounds t \u2192 a \u2208 t \u2192 f a \u2208 upperBounds (f '' t) :=\n  Hf.mem_upperBounds_image subset_rfl\n#align monotone_on.mem_upper_bounds_image_self MonotoneOn.mem_upperBounds_image_self\n-/\n\n#print MonotoneOn.mem_lowerBounds_image /-\ntheorem mem_lowerBounds_image (Has : a \u2208 lowerBounds s) (Hat : a \u2208 t) :\n    f a \u2208 lowerBounds (f '' s) :=\n  ball_image_of_ball fun x H => Hf Hat (Hst H) (Has H)\n#align monotone_on.mem_lower_bounds_image MonotoneOn.mem_lowerBounds_image\n-/\n\n#print MonotoneOn.mem_lowerBounds_image_self /-\ntheorem mem_lowerBounds_image_self : a \u2208 lowerBounds t \u2192 a \u2208 t \u2192 f a \u2208 lowerBounds (f '' t) :=\n  Hf.mem_lowerBounds_image subset_rfl\n#align monotone_on.mem_lower_bounds_image_self MonotoneOn.mem_lowerBounds_image_self\n-/\n\n/- warning: monotone_on.image_upper_bounds_subset_upper_bounds_image -> MonotoneOn.image_upperBounds_subset_upperBounds_image is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.hasSubset.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) (upperBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.instHasSubsetSet.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) (upperBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align monotone_on.image_upper_bounds_subset_upper_bounds_image MonotoneOn.image_upperBounds_subset_upperBounds_image\u2093'. -/\ntheorem image_upperBounds_subset_upperBounds_image (Hst : s \u2286 t) :\n    f '' (upperBounds s \u2229 t) \u2286 upperBounds (f '' s) :=\n  by\n  rintro _ \u27e8a, ha, rfl\u27e9\n  exact Hf.mem_upper_bounds_image Hst ha.1 ha.2\n#align monotone_on.image_upper_bounds_subset_upper_bounds_image MonotoneOn.image_upperBounds_subset_upperBounds_image\n\n/- warning: monotone_on.image_lower_bounds_subset_lower_bounds_image -> MonotoneOn.image_lowerBounds_subset_lowerBounds_image is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.hasSubset.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) (lowerBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.instHasSubsetSet.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) (lowerBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align monotone_on.image_lower_bounds_subset_lower_bounds_image MonotoneOn.image_lowerBounds_subset_lowerBounds_image\u2093'. -/\ntheorem image_lowerBounds_subset_lowerBounds_image :\n    f '' (lowerBounds s \u2229 t) \u2286 lowerBounds (f '' s) :=\n  Hf.dual.image_upperBounds_subset_upperBounds_image Hst\n#align monotone_on.image_lower_bounds_subset_lower_bounds_image MonotoneOn.image_lowerBounds_subset_lowerBounds_image\n\n/- warning: monotone_on.map_bdd_above -> MonotoneOn.map_bddAbove is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddAbove.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddAbove.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nCase conversion may be inaccurate. Consider using '#align monotone_on.map_bdd_above MonotoneOn.map_bddAbove\u2093'. -/\n/-- The image under a monotone function on a set `t` of a subset which has an upper bound in `t`\n  is bounded above. -/\ntheorem map_bddAbove : (upperBounds s \u2229 t).Nonempty \u2192 BddAbove (f '' s) := fun \u27e8C, hs, ht\u27e9 =>\n  \u27e8f C, Hf.mem_upperBounds_image Hst hs ht\u27e9\n#align monotone_on.map_bdd_above MonotoneOn.map_bddAbove\n\n/- warning: monotone_on.map_bdd_below -> MonotoneOn.map_bddBelow is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddBelow.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddBelow.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nCase conversion may be inaccurate. Consider using '#align monotone_on.map_bdd_below MonotoneOn.map_bddBelow\u2093'. -/\n/-- The image under a monotone function on a set `t` of a subset which has a lower bound in `t`\n  is bounded below. -/\ntheorem map_bddBelow : (lowerBounds s \u2229 t).Nonempty \u2192 BddBelow (f '' s) := fun \u27e8C, hs, ht\u27e9 =>\n  \u27e8f C, Hf.mem_lowerBounds_image Hst hs ht\u27e9\n#align monotone_on.map_bdd_below MonotoneOn.map_bddBelow\n\n#print MonotoneOn.map_isLeast /-\n/-- A monotone map sends a least element of a set to a least element of its image. -/\ntheorem map_isLeast (Ha : IsLeast t a) : IsLeast (f '' t) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image_self Ha.2 Ha.1\u27e9\n#align monotone_on.map_is_least MonotoneOn.map_isLeast\n-/\n\n#print MonotoneOn.map_isGreatest /-\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\ntheorem map_isGreatest (Ha : IsGreatest t a) : IsGreatest (f '' t) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image_self Ha.2 Ha.1\u27e9\n#align monotone_on.map_is_greatest MonotoneOn.map_isGreatest\n-/\n\nend MonotoneOn\n\nnamespace AntitoneOn\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : Set \u03b1} (Hf : AntitoneOn f t) {a : \u03b1}\n  (Hst : s \u2286 t)\n\ninclude Hf\n\n#print AntitoneOn.mem_upperBounds_image /-\ntheorem mem_upperBounds_image (Has : a \u2208 lowerBounds s) : a \u2208 t \u2192 f a \u2208 upperBounds (f '' s) :=\n  Hf.dual_right.mem_lowerBounds_image Hst Has\n#align antitone_on.mem_upper_bounds_image AntitoneOn.mem_upperBounds_image\n-/\n\n#print AntitoneOn.mem_upperBounds_image_self /-\ntheorem mem_upperBounds_image_self : a \u2208 lowerBounds t \u2192 a \u2208 t \u2192 f a \u2208 upperBounds (f '' t) :=\n  Hf.dual_right.mem_lowerBounds_image_self\n#align antitone_on.mem_upper_bounds_image_self AntitoneOn.mem_upperBounds_image_self\n-/\n\n#print AntitoneOn.mem_lowerBounds_image /-\ntheorem mem_lowerBounds_image : a \u2208 upperBounds s \u2192 a \u2208 t \u2192 f a \u2208 lowerBounds (f '' s) :=\n  Hf.dual_right.mem_upperBounds_image Hst\n#align antitone_on.mem_lower_bounds_image AntitoneOn.mem_lowerBounds_image\n-/\n\n#print AntitoneOn.mem_lowerBounds_image_self /-\ntheorem mem_lowerBounds_image_self : a \u2208 upperBounds t \u2192 a \u2208 t \u2192 f a \u2208 lowerBounds (f '' t) :=\n  Hf.dual_right.mem_upperBounds_image_self\n#align antitone_on.mem_lower_bounds_image_self AntitoneOn.mem_lowerBounds_image_self\n-/\n\n/- warning: antitone_on.image_lower_bounds_subset_upper_bounds_image -> AntitoneOn.image_lowerBounds_subset_upperBounds_image is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.hasSubset.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) (upperBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.instHasSubsetSet.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) (upperBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align antitone_on.image_lower_bounds_subset_upper_bounds_image AntitoneOn.image_lowerBounds_subset_upperBounds_image\u2093'. -/\ntheorem image_lowerBounds_subset_upperBounds_image :\n    f '' (lowerBounds s \u2229 t) \u2286 upperBounds (f '' s) :=\n  Hf.dual_right.image_lowerBounds_subset_lowerBounds_image Hst\n#align antitone_on.image_lower_bounds_subset_upper_bounds_image AntitoneOn.image_lowerBounds_subset_upperBounds_image\n\n/- warning: antitone_on.image_upper_bounds_subset_lower_bounds_image -> AntitoneOn.image_upperBounds_subset_lowerBounds_image is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.hasSubset.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) (lowerBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b2) (Set.instHasSubsetSet.{u2} \u03b2) (Set.image.{u1, u2} \u03b1 \u03b2 f (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) (lowerBounds.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align antitone_on.image_upper_bounds_subset_lower_bounds_image AntitoneOn.image_upperBounds_subset_lowerBounds_image\u2093'. -/\ntheorem image_upperBounds_subset_lowerBounds_image :\n    f '' (upperBounds s \u2229 t) \u2286 lowerBounds (f '' s) :=\n  Hf.dual_right.image_upperBounds_subset_upperBounds_image Hst\n#align antitone_on.image_upper_bounds_subset_lower_bounds_image AntitoneOn.image_upperBounds_subset_lowerBounds_image\n\n/- warning: antitone_on.map_bdd_above -> AntitoneOn.map_bddAbove is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddBelow.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (upperBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddBelow.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nCase conversion may be inaccurate. Consider using '#align antitone_on.map_bdd_above AntitoneOn.map_bddAbove\u2093'. -/\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\ntheorem map_bddAbove : (upperBounds s \u2229 t).Nonempty \u2192 BddBelow (f '' s) :=\n  Hf.dual_right.map_bddAbove Hst\n#align antitone_on.map_bdd_above AntitoneOn.map_bddAbove\n\n/- warning: antitone_on.map_bdd_below -> AntitoneOn.map_bddBelow is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddAbove.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (AntitoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) s t) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (lowerBounds.{u1} \u03b1 _inst_1 s) t)) -> (BddAbove.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))\nCase conversion may be inaccurate. Consider using '#align antitone_on.map_bdd_below AntitoneOn.map_bddBelow\u2093'. -/\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\ntheorem map_bddBelow : (lowerBounds s \u2229 t).Nonempty \u2192 BddAbove (f '' s) :=\n  Hf.dual_right.map_bddBelow Hst\n#align antitone_on.map_bdd_below AntitoneOn.map_bddBelow\n\n#print AntitoneOn.map_isGreatest /-\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\ntheorem map_isGreatest : IsGreatest t a \u2192 IsLeast (f '' t) (f a) :=\n  Hf.dual_right.map_isGreatest\n#align antitone_on.map_is_greatest AntitoneOn.map_isGreatest\n-/\n\n#print AntitoneOn.map_isLeast /-\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\ntheorem map_isLeast : IsLeast t a \u2192 IsGreatest (f '' t) (f a) :=\n  Hf.dual_right.map_isLeast\n#align antitone_on.map_is_least AntitoneOn.map_isLeast\n-/\n\nend AntitoneOn\n\nnamespace Monotone\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (Hf : Monotone f) {a : \u03b1} {s : Set \u03b1}\n\ninclude Hf\n\n#print Monotone.mem_upperBounds_image /-\ntheorem mem_upperBounds_image (Ha : a \u2208 upperBounds s) : f a \u2208 upperBounds (f '' s) :=\n  ball_image_of_ball fun x H => Hf (Ha H)\n#align monotone.mem_upper_bounds_image Monotone.mem_upperBounds_image\n-/\n\n#print Monotone.mem_lowerBounds_image /-\ntheorem mem_lowerBounds_image (Ha : a \u2208 lowerBounds s) : f a \u2208 lowerBounds (f '' s) :=\n  ball_image_of_ball fun x H => Hf (Ha H)\n#align monotone.mem_lower_bounds_image Monotone.mem_lowerBounds_image\n-/\n\n#print Monotone.image_upperBounds_subset_upperBounds_image /-\ntheorem image_upperBounds_subset_upperBounds_image : f '' upperBounds s \u2286 upperBounds (f '' s) :=\n  by\n  rintro _ \u27e8a, ha, rfl\u27e9\n  exact Hf.mem_upper_bounds_image ha\n#align monotone.image_upper_bounds_subset_upper_bounds_image Monotone.image_upperBounds_subset_upperBounds_image\n-/\n\n#print Monotone.image_lowerBounds_subset_lowerBounds_image /-\ntheorem image_lowerBounds_subset_lowerBounds_image : f '' lowerBounds s \u2286 lowerBounds (f '' s) :=\n  Hf.dual.image_upperBounds_subset_upperBounds_image\n#align monotone.image_lower_bounds_subset_lower_bounds_image Monotone.image_lowerBounds_subset_lowerBounds_image\n-/\n\n#print Monotone.map_bddAbove /-\n/-- The image under a monotone function of a set which is bounded above is bounded above. See also\n`bdd_above.image2`. -/\ntheorem map_bddAbove : BddAbove s \u2192 BddAbove (f '' s)\n  | \u27e8C, hC\u27e9 => \u27e8f C, Hf.mem_upperBounds_image hC\u27e9\n#align monotone.map_bdd_above Monotone.map_bddAbove\n-/\n\n#print Monotone.map_bddBelow /-\n/-- The image under a monotone function of a set which is bounded below is bounded below. See also\n`bdd_below.image2`. -/\ntheorem map_bddBelow : BddBelow s \u2192 BddBelow (f '' s)\n  | \u27e8C, hC\u27e9 => \u27e8f C, Hf.mem_lowerBounds_image hC\u27e9\n#align monotone.map_bdd_below Monotone.map_bddBelow\n-/\n\n#print Monotone.map_isLeast /-\n/-- A monotone map sends a least element of a set to a least element of its image. -/\ntheorem map_isLeast (Ha : IsLeast s a) : IsLeast (f '' s) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image Ha.2\u27e9\n#align monotone.map_is_least Monotone.map_isLeast\n-/\n\n#print Monotone.map_isGreatest /-\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\ntheorem map_isGreatest (Ha : IsGreatest s a) : IsGreatest (f '' s) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image Ha.2\u27e9\n#align monotone.map_is_greatest Monotone.map_isGreatest\n-/\n\nend Monotone\n\nnamespace Antitone\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Antitone f) {a : \u03b1} {s : Set \u03b1}\n\n#print Antitone.mem_upperBounds_image /-\ntheorem mem_upperBounds_image : a \u2208 lowerBounds s \u2192 f a \u2208 upperBounds (f '' s) :=\n  hf.dual_right.mem_lowerBounds_image\n#align antitone.mem_upper_bounds_image Antitone.mem_upperBounds_image\n-/\n\n#print Antitone.mem_lowerBounds_image /-\ntheorem mem_lowerBounds_image : a \u2208 upperBounds s \u2192 f a \u2208 lowerBounds (f '' s) :=\n  hf.dual_right.mem_upperBounds_image\n#align antitone.mem_lower_bounds_image Antitone.mem_lowerBounds_image\n-/\n\n#print Antitone.image_lowerBounds_subset_upperBounds_image /-\ntheorem image_lowerBounds_subset_upperBounds_image : f '' lowerBounds s \u2286 upperBounds (f '' s) :=\n  hf.dual_right.image_lowerBounds_subset_lowerBounds_image\n#align antitone.image_lower_bounds_subset_upper_bounds_image Antitone.image_lowerBounds_subset_upperBounds_image\n-/\n\n#print Antitone.image_upperBounds_subset_lowerBounds_image /-\ntheorem image_upperBounds_subset_lowerBounds_image : f '' upperBounds s \u2286 lowerBounds (f '' s) :=\n  hf.dual_right.image_upperBounds_subset_upperBounds_image\n#align antitone.image_upper_bounds_subset_lower_bounds_image Antitone.image_upperBounds_subset_lowerBounds_image\n-/\n\n#print Antitone.map_bddAbove /-\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\ntheorem map_bddAbove : BddAbove s \u2192 BddBelow (f '' s) :=\n  hf.dual_right.map_bddAbove\n#align antitone.map_bdd_above Antitone.map_bddAbove\n-/\n\n#print Antitone.map_bddBelow /-\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\ntheorem map_bddBelow : BddBelow s \u2192 BddAbove (f '' s) :=\n  hf.dual_right.map_bddBelow\n#align antitone.map_bdd_below Antitone.map_bddBelow\n-/\n\n#print Antitone.map_isGreatest /-\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\ntheorem map_isGreatest : IsGreatest s a \u2192 IsLeast (f '' s) (f a) :=\n  hf.dual_right.map_isGreatest\n#align antitone.map_is_greatest Antitone.map_isGreatest\n-/\n\n#print Antitone.map_isLeast /-\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\ntheorem map_isLeast : IsLeast s a \u2192 IsGreatest (f '' s) (f a) :=\n  hf.dual_right.map_isLeast\n#align antitone.map_is_least Antitone.map_isLeast\n-/\n\nend Antitone\n\nsection Image2\n\nvariable [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {s : Set \u03b1} {t : Set \u03b2} {a : \u03b1}\n  {b : \u03b2}\n\nsection MonotoneMonotone\n\nvariable (h\u2080 : \u2200 b, Monotone (swap f b)) (h\u2081 : \u2200 a, Monotone (f a))\n\ninclude h\u2080 h\u2081\n\n#print mem_upperBounds_image2 /-\ntheorem mem_upperBounds_image2 (ha : a \u2208 upperBounds s) (hb : b \u2208 upperBounds t) :\n    f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2 mem_upperBounds_image2\n-/\n\n#print mem_lowerBounds_image2 /-\ntheorem mem_lowerBounds_image2 (ha : a \u2208 lowerBounds s) (hb : b \u2208 lowerBounds t) :\n    f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2 mem_lowerBounds_image2\n-/\n\n#print image2_upperBounds_upperBounds_subset /-\ntheorem image2_upperBounds_upperBounds_subset :\n    image2 f (upperBounds s) (upperBounds t) \u2286 upperBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2 h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_upper_bounds_subset image2_upperBounds_upperBounds_subset\n-/\n\n#print image2_lowerBounds_lowerBounds_subset /-\ntheorem image2_lowerBounds_lowerBounds_subset :\n    image2 f (lowerBounds s) (lowerBounds t) \u2286 lowerBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2 h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_lower_bounds_subset image2_lowerBounds_lowerBounds_subset\n-/\n\n#print BddAbove.image2 /-\n/-- See also `monotone.map_bdd_above`. -/\ntheorem BddAbove.image2 : BddAbove s \u2192 BddAbove t \u2192 BddAbove (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2 h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.image2 BddAbove.image2\n-/\n\n#print BddBelow.image2 /-\n/-- See also `monotone.map_bdd_below`. -/\ntheorem BddBelow.image2 : BddBelow s \u2192 BddBelow t \u2192 BddBelow (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2 h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.image2 BddBelow.image2\n-/\n\n#print IsGreatest.image2 /-\ntheorem IsGreatest.image2 (ha : IsGreatest s a) (hb : IsGreatest t b) :\n    IsGreatest (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.image2 IsGreatest.image2\n-/\n\n#print IsLeast.image2 /-\ntheorem IsLeast.image2 (ha : IsLeast s a) (hb : IsLeast t b) : IsLeast (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.image2 IsLeast.image2\n-/\n\nend MonotoneMonotone\n\nsection MonotoneAntitone\n\nvariable (h\u2080 : \u2200 b, Monotone (swap f b)) (h\u2081 : \u2200 a, Antitone (f a))\n\ninclude h\u2080 h\u2081\n\n#print mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds /-\ntheorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds (ha : a \u2208 upperBounds s)\n    (hb : b \u2208 lowerBounds t) : f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds\n-/\n\n#print mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds /-\ntheorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds (ha : a \u2208 lowerBounds s)\n    (hb : b \u2208 upperBounds t) : f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds\n-/\n\n#print image2_upperBounds_lowerBounds_subset_upperBounds_image2 /-\ntheorem image2_upperBounds_lowerBounds_subset_upperBounds_image2 :\n    image2 f (upperBounds s) (lowerBounds t) \u2286 upperBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_lower_bounds_subset_upper_bounds_image2 image2_upperBounds_lowerBounds_subset_upperBounds_image2\n-/\n\n#print image2_lowerBounds_upperBounds_subset_lowerBounds_image2 /-\ntheorem image2_lowerBounds_upperBounds_subset_lowerBounds_image2 :\n    image2 f (lowerBounds s) (upperBounds t) \u2286 lowerBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_upper_bounds_subset_lower_bounds_image2 image2_lowerBounds_upperBounds_subset_lowerBounds_image2\n-/\n\n#print BddAbove.bddAbove_image2_of_bddBelow /-\ntheorem BddAbove.bddAbove_image2_of_bddBelow : BddAbove s \u2192 BddBelow t \u2192 BddAbove (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.bdd_above_image2_of_bdd_below BddAbove.bddAbove_image2_of_bddBelow\n-/\n\n#print BddBelow.bddBelow_image2_of_bddAbove /-\ntheorem BddBelow.bddBelow_image2_of_bddAbove : BddBelow s \u2192 BddAbove t \u2192 BddBelow (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.bdd_below_image2_of_bdd_above BddBelow.bddBelow_image2_of_bddAbove\n-/\n\n#print IsGreatest.isGreatest_image2_of_isLeast /-\ntheorem IsGreatest.isGreatest_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) :\n    IsGreatest (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.is_greatest_image2_of_is_least IsGreatest.isGreatest_image2_of_isLeast\n-/\n\n#print IsLeast.isLeast_image2_of_isGreatest /-\ntheorem IsLeast.isLeast_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) :\n    IsLeast (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.is_least_image2_of_is_greatest IsLeast.isLeast_image2_of_isGreatest\n-/\n\nend MonotoneAntitone\n\nsection AntitoneAntitone\n\nvariable (h\u2080 : \u2200 b, Antitone (swap f b)) (h\u2081 : \u2200 a, Antitone (f a))\n\ninclude h\u2080 h\u2081\n\n#print mem_upperBounds_image2_of_mem_lowerBounds /-\ntheorem mem_upperBounds_image2_of_mem_lowerBounds (ha : a \u2208 lowerBounds s)\n    (hb : b \u2208 lowerBounds t) : f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2_of_mem_lower_bounds mem_upperBounds_image2_of_mem_lowerBounds\n-/\n\n#print mem_lowerBounds_image2_of_mem_upperBounds /-\ntheorem mem_lowerBounds_image2_of_mem_upperBounds (ha : a \u2208 upperBounds s)\n    (hb : b \u2208 upperBounds t) : f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2_of_mem_upper_bounds mem_lowerBounds_image2_of_mem_upperBounds\n-/\n\n#print image2_upperBounds_upperBounds_subset_upperBounds_image2 /-\ntheorem image2_upperBounds_upperBounds_subset_upperBounds_image2 :\n    image2 f (lowerBounds s) (lowerBounds t) \u2286 upperBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2_of_mem_lowerBounds h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_upper_bounds_subset_upper_bounds_image2 image2_upperBounds_upperBounds_subset_upperBounds_image2\n-/\n\n#print image2_lowerBounds_lowerBounds_subset_lowerBounds_image2 /-\ntheorem image2_lowerBounds_lowerBounds_subset_lowerBounds_image2 :\n    image2 f (upperBounds s) (upperBounds t) \u2286 lowerBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2_of_mem_upperBounds h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_lower_bounds_subset_lower_bounds_image2 image2_lowerBounds_lowerBounds_subset_lowerBounds_image2\n-/\n\n#print BddBelow.image2_bddAbove /-\ntheorem BddBelow.image2_bddAbove : BddBelow s \u2192 BddBelow t \u2192 BddAbove (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2_of_mem_lowerBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.image2_bdd_above BddBelow.image2_bddAbove\n-/\n\n#print BddAbove.image2_bddBelow /-\ntheorem BddAbove.image2_bddBelow : BddAbove s \u2192 BddAbove t \u2192 BddBelow (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2_of_mem_upperBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.image2_bdd_below BddAbove.image2_bddBelow\n-/\n\n#print IsLeast.isGreatest_image2 /-\ntheorem IsLeast.isGreatest_image2 (ha : IsLeast s a) (hb : IsLeast t b) :\n    IsGreatest (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2_of_mem_lowerBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.is_greatest_image2 IsLeast.isGreatest_image2\n-/\n\n#print IsGreatest.isLeast_image2 /-\ntheorem IsGreatest.isLeast_image2 (ha : IsGreatest s a) (hb : IsGreatest t b) :\n    IsLeast (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2_of_mem_upperBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.is_least_image2 IsGreatest.isLeast_image2\n-/\n\nend AntitoneAntitone\n\nsection AntitoneMonotone\n\nvariable (h\u2080 : \u2200 b, Antitone (swap f b)) (h\u2081 : \u2200 a, Monotone (f a))\n\ninclude h\u2080 h\u2081\n\n#print mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds /-\ntheorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds (ha : a \u2208 lowerBounds s)\n    (hb : b \u2208 upperBounds t) : f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds\n-/\n\n#print mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds /-\ntheorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds (ha : a \u2208 upperBounds s)\n    (hb : b \u2208 lowerBounds t) : f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun x hx y hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds\n-/\n\n#print image2_lowerBounds_upperBounds_subset_upperBounds_image2 /-\ntheorem image2_lowerBounds_upperBounds_subset_upperBounds_image2 :\n    image2 f (lowerBounds s) (upperBounds t) \u2286 upperBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_upper_bounds_subset_upper_bounds_image2 image2_lowerBounds_upperBounds_subset_upperBounds_image2\n-/\n\n#print image2_upperBounds_lowerBounds_subset_lowerBounds_image2 /-\ntheorem image2_upperBounds_lowerBounds_subset_lowerBounds_image2 :\n    image2 f (upperBounds s) (lowerBounds t) \u2286 lowerBounds (image2 f s t) :=\n  by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_lower_bounds_subset_lower_bounds_image2 image2_upperBounds_lowerBounds_subset_lowerBounds_image2\n-/\n\n#print BddBelow.bddAbove_image2_of_bddAbove /-\ntheorem BddBelow.bddAbove_image2_of_bddAbove : BddBelow s \u2192 BddAbove t \u2192 BddAbove (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.bdd_above_image2_of_bdd_above BddBelow.bddAbove_image2_of_bddAbove\n-/\n\n#print BddAbove.bddBelow_image2_of_bddAbove /-\ntheorem BddAbove.bddBelow_image2_of_bddAbove : BddAbove s \u2192 BddBelow t \u2192 BddBelow (image2 f s t) :=\n  by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.bdd_below_image2_of_bdd_above BddAbove.bddBelow_image2_of_bddAbove\n-/\n\n#print IsLeast.isGreatest_image2_of_isGreatest /-\ntheorem IsLeast.isGreatest_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) :\n    IsGreatest (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.is_greatest_image2_of_is_greatest IsLeast.isGreatest_image2_of_isGreatest\n-/\n\n#print IsGreatest.isLeast_image2_of_isLeast /-\ntheorem IsGreatest.isLeast_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) :\n    IsLeast (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.is_least_image2_of_is_least IsGreatest.isLeast_image2_of_isLeast\n-/\n\nend AntitoneMonotone\n\nend Image2\n\n#print IsGLB.of_image /-\ntheorem IsGLB.of_image [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n    {s : Set \u03b1} {x : \u03b1} (hx : IsGLB (f '' s) (f x)) : IsGLB s x :=\n  \u27e8fun y hy => hf.1 <| hx.1 <| mem_image_of_mem _ hy, fun y hy =>\n    hf.1 <| hx.2 <| Monotone.mem_lowerBounds_image (fun x y => hf.2) hy\u27e9\n#align is_glb.of_image IsGLB.of_image\n-/\n\n#print IsLUB.of_image /-\ntheorem IsLUB.of_image [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n    {s : Set \u03b1} {x : \u03b1} (hx : IsLUB (f '' s) (f x)) : IsLUB s x :=\n  @IsGLB.of_image \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ f (fun x y => hf) _ _ hx\n#align is_lub.of_image IsLUB.of_image\n-/\n\n/- warning: is_lub_pi -> isLUB_pi is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03c0 : \u03b1 -> Type.{u2}} [_inst_1 : forall (a : \u03b1), Preorder.{u2} (\u03c0 a)] {s : Set.{max u1 u2} (forall (a : \u03b1), \u03c0 a)} {f : forall (a : \u03b1), \u03c0 a}, Iff (IsLUB.{max u1 u2} (forall (a : \u03b1), \u03c0 a) (Pi.preorder.{u1, u2} \u03b1 (fun (a : \u03b1) => \u03c0 a) (fun (i : \u03b1) => _inst_1 i)) s f) (forall (a : \u03b1), IsLUB.{u2} (\u03c0 a) (_inst_1 a) (Set.image.{max u1 u2, u2} (forall (x : \u03b1), \u03c0 x) (\u03c0 a) (Function.eval.{succ u1, succ u2} \u03b1 (fun (a : \u03b1) => \u03c0 a) a) s) (f a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03c0 : \u03b1 -> Type.{u1}} [_inst_1 : forall (a : \u03b1), Preorder.{u1} (\u03c0 a)] {s : Set.{max u2 u1} (forall (a : \u03b1), \u03c0 a)} {f : forall (a : \u03b1), \u03c0 a}, Iff (IsLUB.{max u2 u1} (forall (a : \u03b1), \u03c0 a) (Pi.preorder.{u2, u1} \u03b1 (fun (a : \u03b1) => \u03c0 a) (fun (i : \u03b1) => _inst_1 i)) s f) (forall (a : \u03b1), IsLUB.{u1} (\u03c0 a) (_inst_1 a) (Set.image.{max u2 u1, u1} (forall (x : \u03b1), \u03c0 x) (\u03c0 a) (Function.eval.{succ u2, succ u1} \u03b1 (fun (a : \u03b1) => \u03c0 a) a) s) (f a))\nCase conversion may be inaccurate. Consider using '#align is_lub_pi isLUB_pi\u2093'. -/\ntheorem isLUB_pi {\u03c0 : \u03b1 \u2192 Type _} [\u2200 a, Preorder (\u03c0 a)] {s : Set (\u2200 a, \u03c0 a)} {f : \u2200 a, \u03c0 a} :\n    IsLUB s f \u2194 \u2200 a, IsLUB (Function.eval a '' s) (f a) := by\n  classical\n    refine'\n      \u27e8fun H a => \u27e8(Function.monotone_eval a).mem_upperBounds_image H.1, fun b hb => _\u27e9, fun H =>\n        \u27e8_, _\u27e9\u27e9\n    \u00b7 suffices : Function.update f a b \u2208 upperBounds s\n      exact Function.update_same a b f \u25b8 H.2 this a\n      refine' fun g hg => le_update_iff.2 \u27e8hb <| mem_image_of_mem _ hg, fun i hi => H.1 hg i\u27e9\n    \u00b7 exact fun g hg a => (H a).1 (mem_image_of_mem _ hg)\n    \u00b7 exact fun g hg a => (H a).2 ((Function.monotone_eval a).mem_upperBounds_image hg)\n#align is_lub_pi isLUB_pi\n\n/- warning: is_glb_pi -> isGLB_pi is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03c0 : \u03b1 -> Type.{u2}} [_inst_1 : forall (a : \u03b1), Preorder.{u2} (\u03c0 a)] {s : Set.{max u1 u2} (forall (a : \u03b1), \u03c0 a)} {f : forall (a : \u03b1), \u03c0 a}, Iff (IsGLB.{max u1 u2} (forall (a : \u03b1), \u03c0 a) (Pi.preorder.{u1, u2} \u03b1 (fun (a : \u03b1) => \u03c0 a) (fun (i : \u03b1) => _inst_1 i)) s f) (forall (a : \u03b1), IsGLB.{u2} (\u03c0 a) (_inst_1 a) (Set.image.{max u1 u2, u2} (forall (x : \u03b1), \u03c0 x) (\u03c0 a) (Function.eval.{succ u1, succ u2} \u03b1 (fun (a : \u03b1) => \u03c0 a) a) s) (f a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03c0 : \u03b1 -> Type.{u1}} [_inst_1 : forall (a : \u03b1), Preorder.{u1} (\u03c0 a)] {s : Set.{max u2 u1} (forall (a : \u03b1), \u03c0 a)} {f : forall (a : \u03b1), \u03c0 a}, Iff (IsGLB.{max u2 u1} (forall (a : \u03b1), \u03c0 a) (Pi.preorder.{u2, u1} \u03b1 (fun (a : \u03b1) => \u03c0 a) (fun (i : \u03b1) => _inst_1 i)) s f) (forall (a : \u03b1), IsGLB.{u1} (\u03c0 a) (_inst_1 a) (Set.image.{max u2 u1, u1} (forall (x : \u03b1), \u03c0 x) (\u03c0 a) (Function.eval.{succ u2, succ u1} \u03b1 (fun (a : \u03b1) => \u03c0 a) a) s) (f a))\nCase conversion may be inaccurate. Consider using '#align is_glb_pi isGLB_pi\u2093'. -/\ntheorem isGLB_pi {\u03c0 : \u03b1 \u2192 Type _} [\u2200 a, Preorder (\u03c0 a)] {s : Set (\u2200 a, \u03c0 a)} {f : \u2200 a, \u03c0 a} :\n    IsGLB s f \u2194 \u2200 a, IsGLB (Function.eval a '' s) (f a) :=\n  @isLUB_pi \u03b1 (fun a => (\u03c0 a)\u1d52\u1d48) _ s f\n#align is_glb_pi isGLB_pi\n\n/- warning: is_lub_prod -> isLUB_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)} (p : Prod.{u1, u2} \u03b1 \u03b2), Iff (IsLUB.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.preorder.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) s p) (And (IsLUB.{u1} \u03b1 _inst_1 (Set.image.{max u1 u2, u1} (Prod.{u1, u2} \u03b1 \u03b2) \u03b1 (Prod.fst.{u1, u2} \u03b1 \u03b2) s) (Prod.fst.{u1, u2} \u03b1 \u03b2 p)) (IsLUB.{u2} \u03b2 _inst_2 (Set.image.{max u1 u2, u2} (Prod.{u1, u2} \u03b1 \u03b2) \u03b2 (Prod.snd.{u1, u2} \u03b1 \u03b2) s) (Prod.snd.{u1, u2} \u03b1 \u03b2 p)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{max u2 u1} (Prod.{u1, u2} \u03b1 \u03b2)} (p : Prod.{u1, u2} \u03b1 \u03b2), Iff (IsLUB.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.instPreorderProd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) s p) (And (IsLUB.{u1} \u03b1 _inst_1 (Set.image.{max u2 u1, u1} (Prod.{u1, u2} \u03b1 \u03b2) \u03b1 (Prod.fst.{u1, u2} \u03b1 \u03b2) s) (Prod.fst.{u1, u2} \u03b1 \u03b2 p)) (IsLUB.{u2} \u03b2 _inst_2 (Set.image.{max u2 u1, u2} (Prod.{u1, u2} \u03b1 \u03b2) \u03b2 (Prod.snd.{u1, u2} \u03b1 \u03b2) s) (Prod.snd.{u1, u2} \u03b1 \u03b2 p)))\nCase conversion may be inaccurate. Consider using '#align is_lub_prod isLUB_prod\u2093'. -/\ntheorem isLUB_prod [Preorder \u03b1] [Preorder \u03b2] {s : Set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n    IsLUB s p \u2194 IsLUB (Prod.fst '' s) p.1 \u2227 IsLUB (Prod.snd '' s) p.2 :=\n  by\n  refine'\n    \u27e8fun H =>\n      \u27e8\u27e8monotone_fst.mem_upper_bounds_image H.1, fun a ha => _\u27e9,\n        \u27e8monotone_snd.mem_upper_bounds_image H.1, fun a ha => _\u27e9\u27e9,\n      fun H => \u27e8_, _\u27e9\u27e9\n  \u00b7 suffices : (a, p.2) \u2208 upperBounds s\n    exact (H.2 this).1\n    exact fun q hq => \u27e8ha <| mem_image_of_mem _ hq, (H.1 hq).2\u27e9\n  \u00b7 suffices : (p.1, a) \u2208 upperBounds s\n    exact (H.2 this).2\n    exact fun q hq => \u27e8(H.1 hq).1, ha <| mem_image_of_mem _ hq\u27e9\n  \u00b7 exact fun q hq => \u27e8H.1.1 <| mem_image_of_mem _ hq, H.2.1 <| mem_image_of_mem _ hq\u27e9\n  \u00b7\n    exact fun q hq =>\n      \u27e8H.1.2 <| monotone_fst.mem_upper_bounds_image hq,\n        H.2.2 <| monotone_snd.mem_upper_bounds_image hq\u27e9\n#align is_lub_prod isLUB_prod\n\n/- warning: is_glb_prod -> isGLB_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)} (p : Prod.{u1, u2} \u03b1 \u03b2), Iff (IsGLB.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.preorder.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) s p) (And (IsGLB.{u1} \u03b1 _inst_1 (Set.image.{max u1 u2, u1} (Prod.{u1, u2} \u03b1 \u03b2) \u03b1 (Prod.fst.{u1, u2} \u03b1 \u03b2) s) (Prod.fst.{u1, u2} \u03b1 \u03b2 p)) (IsGLB.{u2} \u03b2 _inst_2 (Set.image.{max u1 u2, u2} (Prod.{u1, u2} \u03b1 \u03b2) \u03b2 (Prod.snd.{u1, u2} \u03b1 \u03b2) s) (Prod.snd.{u1, u2} \u03b1 \u03b2 p)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{max u2 u1} (Prod.{u1, u2} \u03b1 \u03b2)} (p : Prod.{u1, u2} \u03b1 \u03b2), Iff (IsGLB.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.instPreorderProd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) s p) (And (IsGLB.{u1} \u03b1 _inst_1 (Set.image.{max u2 u1, u1} (Prod.{u1, u2} \u03b1 \u03b2) \u03b1 (Prod.fst.{u1, u2} \u03b1 \u03b2) s) (Prod.fst.{u1, u2} \u03b1 \u03b2 p)) (IsGLB.{u2} \u03b2 _inst_2 (Set.image.{max u2 u1, u2} (Prod.{u1, u2} \u03b1 \u03b2) \u03b2 (Prod.snd.{u1, u2} \u03b1 \u03b2) s) (Prod.snd.{u1, u2} \u03b1 \u03b2 p)))\nCase conversion may be inaccurate. Consider using '#align is_glb_prod isGLB_prod\u2093'. -/\ntheorem isGLB_prod [Preorder \u03b1] [Preorder \u03b2] {s : Set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n    IsGLB s p \u2194 IsGLB (Prod.fst '' s) p.1 \u2227 IsGLB (Prod.snd '' s) p.2 :=\n  @isLUB_prod \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _\n#align is_glb_prod isGLB_prod\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/Bounds/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.718777434248627}}
{"text": "import tactic.induction\nimport data.int.basic\nimport data.set.basic\n\nimport .base .point\n\nnoncomputable theory\nopen_locale classical\n\n-----\n\nlemma dist_self {a : Point} : dist a a = 0 :=\nbegin\n  change int.to_nat _ = 0,\n  simp_rw [sub_self, abs_zero, max_self], refl,\nend\n\nlemma eq_zero_left_of_max_eq_zero {a b : \u2124}\n  (h : (max (|a|) (|b|)).to_nat = 0) : a = 0 :=\nbegin\n  by_contra h\u2081,\n  replace h\u2081 := lt_max_of_lt_left (abs_pos.mpr h\u2081),\n  replace h\u2081 : int.to_nat 0 < (max (|a|) (|b|)).to_nat,\n  { rw int.to_nat_lt_to_nat; assumption },\n  rw h at h\u2081, cases h\u2081,\nend\n\nlemma eq_zero_right_of_max_eq_zero {a b : \u2124}\n  (h : (max (|a|) (|b|)).to_nat = 0) : b = 0 :=\nby { rw max_comm at h, exact eq_zero_left_of_max_eq_zero h }\n\nlemma eq_zero_of_max_eq_zero {a b : \u2124}\n  (h : (max (|a|) (|b|)).to_nat = 0) : a = 0 \u2227 b = 0 :=\n\u27e8eq_zero_left_of_max_eq_zero h, eq_zero_right_of_max_eq_zero h\u27e9\n\nlemma dist_eq_zero_iff {a b : Point} : dist a b = 0 \u2194 a = b :=\nbegin\n  split; intro h,\n  { obtain \u27e8h\u2081, h\u2082\u27e9 := eq_zero_of_max_eq_zero h,\n    rw sub_eq_zero at h\u2081 h\u2082, ext; assumption },\n  { subst h, exact dist_self },\nend\n\nlemma dist_coe_int {a b : Point} :\n  (dist a b : \u2124) = max (|a.x - b.x|) (|a.y - b.y|) :=\nbegin\n  rw [dist, int.to_nat_eq_max, max_def, if_pos],\n  rw max_def, split_ifs; apply abs_nonneg,\nend\n\nlemma triangle_aux {a b x y : \u2124} :\n  |a + b| \u2264 max (|a|) x + max (|b|) y :=\nbegin\n  calc |a + b| \u2264 |a| + |b| : abs_add _ _\n  ... \u2264 max (|a|) x + |b| : add_le_add_right (le_max_left _ _) _\n  ... \u2264 max (|a|) x + max (|b|) y : add_le_add_left (le_max_left _ _) _\nend\n\nlemma dist_triangle {a b c : Point} :\n  dist a c \u2264 dist a b + dist b c :=\nbegin\n  zify, simp_rw [dist_coe_int, max_le_iff], split,\n  { have h := @triangle_aux (a.x - b.x) (b.x - c.x) (|a.y - b.y|) (|b.y - c.y|),\n    simp at h, exact h },\n  { have h := @triangle_aux (a.y - b.y) (b.y - c.y) (|a.x - b.x|) (|b.x - c.x|),\n    simp [max_comm] at h, exact h },\nend\n\nlemma dist_comm {a b : Point} : dist a b = dist b a :=\nby { simp_rw dist, congr' 2; apply abs_sub_comm }\n\nlemma dist_le_iff_zify {a b : Point} {d : \u2115} :\n  dist a b \u2264 d \u2194 max (|a.x - b.x|) (|a.y - b.y|) \u2264 d :=\nby { simp [dist] }\n\nlemma dist_le_iff {a b : Point} {d : \u2115} :\n  dist a b \u2264 d \u2194 |a.x - b.x| \u2264 d \u2227 |a.y - b.y| \u2264 d :=\nby simp [dist_le_iff_zify]\n\nlemma dist_le_set_finite {c : Point} {d : \u2115} :\n  {p : Point | dist p c \u2264 d}.finite :=\nbegin\n  simp_rw dist_le_iff, apply set_finite_of_set_equiv_finite Point_equiv_prod.symm,\n  convert_to {p : \u2124 \u00d7 \u2124 | (|p.1 - c.x|) \u2264 d \u2227 (|p.2 - c.y|) \u2264 d}.finite,\n  { rw set.ext_iff, intro p, change _ \u2227 _ \u2194 _ \u2227 _, rw iff_iff_eq,\n    congr; rw Point_equiv_symm_apply },\n  apply @set.finite.prod \u2124 \u2124 {x : \u2124 | |x - c.x| \u2264 \u2191d} {y : \u2124 | |y - c.y| \u2264 \u2191d};\n  exact abs_sub_le_finite,\nend", "meta": {"author": "user7230724", "repo": "lean-projects", "sha": "ab9a83874775efd18f8c5b867e480bae4d596b31", "save_path": "github-repos/lean/user7230724-lean-projects", "path": "github-repos/lean/user7230724-lean-projects/lean-projects-ab9a83874775efd18f8c5b867e480bae4d596b31/src/ap/dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.71877742986564}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\n! This file was ported from Lean 3 source module data.int.order.basic\n! leanprover-community/mathlib commit 728baa2f54e6062c5879a3e397ac6bac323e506f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\n\nimport Mathlib.Data.Int.Basic\nimport Mathlib.Algebra.Ring.Divisibility\nimport Mathlib.Algebra.Order.Group.Abs\nimport Mathlib.Algebra.Order.Ring.CharZero\n\n/-!\n# Order instances on the integers\n\nThis file contains:\n* instances on `\u2124`. The stronger one is `Int.linearOrderedCommRing`.\n* basic lemmas about integers that involve order properties.\n\n## Recursors\n\n* `Int.rec`: Sign disjunction. Something is true/defined on `\u2124` if it's true/defined for nonnegative\n  and for negative values. (Defined in core Lean 3)\n* `Int.inductionOn`: Simple growing induction on positive numbers, plus simple decreasing induction\n  on negative numbers. Note that this recursor is currently only `Prop`-valued.\n* `Int.inductionOn'`: Simple growing induction for numbers greater than `b`, plus simple decreasing\n  induction on numbers less than `b`.\n-/\n\nopen Nat\n\nnamespace Int\n\ninstance linearOrderedCommRing : LinearOrderedCommRing \u2124 :=\n  { instCommRingInt, instLinearOrderInt, instNontrivialInt with\n    add_le_add_left := @Int.add_le_add_left,\n    mul_pos := @Int.mul_pos, zero_le_one := le_of_lt Int.zero_lt_one }\n\n/-! ### Extra instances to short-circuit type class resolution\n-/\n\n\ninstance orderedCommRing : OrderedCommRing \u2124 :=\n  StrictOrderedCommRing.toOrderedCommRing'\n\ninstance orderedRing : OrderedRing \u2124 :=\n  StrictOrderedRing.toOrderedRing'\n\ninstance linearOrderedAddCommGroup : LinearOrderedAddCommGroup \u2124 := by infer_instance\n\nend Int\n\nnamespace Int\n\ntheorem abs_eq_natAbs : \u2200 a : \u2124, |a| = natAbs a\n  | (n : \u2115) => abs_of_nonneg <| ofNat_zero_le _\n  | -[_+1] => abs_of_nonpos <| le_of_lt <| negSucc_lt_zero _\n#align int.abs_eq_nat_abs Int.abs_eq_natAbs\n\n@[simp, norm_cast] lemma coe_natAbs (n : \u2124) : (n.natAbs : \u2124) = |n| := n.abs_eq_natAbs.symm\n#align int.coe_nat_abs Int.coe_natAbs\n\nlemma _root_.Nat.cast_natAbs {\u03b1 : Type _} [AddGroupWithOne \u03b1] (n : \u2124) : (n.natAbs : \u03b1) = |n| :=\nby rw [\u2190coe_natAbs, Int.cast_ofNat]\n#align nat.cast_nat_abs Nat.cast_natAbs\n\ntheorem natAbs_abs (a : \u2124) : natAbs (|a|) = natAbs a := by rw [abs_eq_natAbs] ; rfl\n#align int.nat_abs_abs Int.natAbs_abs\n\ntheorem sign_mul_abs (a : \u2124) : sign a * |a| = a := by\n  rw [abs_eq_natAbs, sign_mul_natAbs a]\n#align int.sign_mul_abs Int.sign_mul_abs\n\ntheorem coe_nat_eq_zero {n : \u2115} : (n : \u2124) = 0 \u2194 n = 0 :=\n  Nat.cast_eq_zero\n#align int.coe_nat_eq_zero Int.coe_nat_eq_zero\n\ntheorem coe_nat_ne_zero {n : \u2115} : (n : \u2124) \u2260 0 \u2194 n \u2260 0 := by simp\n#align int.coe_nat_ne_zero Int.coe_nat_ne_zero\n\ntheorem coe_nat_ne_zero_iff_pos {n : \u2115} : (n : \u2124) \u2260 0 \u2194 0 < n :=\n  \u27e8fun h => Nat.pos_of_ne_zero (coe_nat_ne_zero.1 h),\n   fun h => (_root_.ne_of_lt (ofNat_lt.2 h)).symm\u27e9\n#align int.coe_nat_ne_zero_iff_pos Int.coe_nat_ne_zero_iff_pos\n\n@[norm_cast] lemma abs_coe_nat (n : \u2115) : |(n : \u2124)| = n := abs_of_nonneg (coe_nat_nonneg n)\n#align int.abs_coe_nat Int.abs_coe_nat\n\ntheorem sign_add_eq_of_sign_eq : \u2200 {m n : \u2124}, m.sign = n.sign \u2192 (m + n).sign = n.sign := by\n  have : (1 : \u2124) \u2260 -1 := by decide\n  rintro ((_ | m) | m) ((_ | n) | n) <;> simp [this, this.symm]\n  rw [Int.sign_eq_one_iff_pos]\n  apply Int.add_pos <;> \u00b7 exact zero_lt_one.trans_le (le_add_of_nonneg_left <| coe_nat_nonneg _)\n#align int.sign_add_eq_of_sign_eq Int.sign_add_eq_of_sign_eq\n\n/-! ### succ and pred -/\n\n\ntheorem lt_succ_self (a : \u2124) : a < succ a :=\n  lt_add_of_pos_right _ zero_lt_one\n#align int.lt_succ_self Int.lt_succ_self\n\ntheorem pred_self_lt (a : \u2124) : pred a < a :=\n  sub_lt_self _ zero_lt_one\n#align int.pred_self_lt Int.pred_self_lt\n\n#align int.lt_add_one_iff Int.lt_add_one_iff\n#align int.le_add_one Int.le_add_one\n\ntheorem sub_one_lt_iff {a b : \u2124} : a - 1 < b \u2194 a \u2264 b :=\n  sub_lt_iff_lt_add.trans lt_add_one_iff\n#align int.sub_one_lt_iff Int.sub_one_lt_iff\n\ntheorem le_sub_one_iff {a b : \u2124} : a \u2264 b - 1 \u2194 a < b :=\n  le_sub_iff_add_le\n#align int.le_sub_one_iff Int.le_sub_one_iff\n\n@[simp]\ntheorem abs_lt_one_iff {a : \u2124} : |a| < 1 \u2194 a = 0 :=\n  \u27e8fun a0 => by\n    let \u27e8hn, hp\u27e9 := abs_lt.mp a0\n    rw [\u2190zero_add 1, lt_add_one_iff] at hp\n    -- Defeq abuse: `hn : -1 < a` but should be `hn : 0 \u03bb a`.\n    exact hp.antisymm hn,\n    fun a0 => (abs_eq_zero.mpr a0).le.trans_lt zero_lt_one\u27e9\n#align int.abs_lt_one_iff Int.abs_lt_one_iff\n\ntheorem abs_le_one_iff {a : \u2124} : |a| \u2264 1 \u2194 a = 0 \u2228 a = 1 \u2228 a = -1 := by\n  rw [le_iff_lt_or_eq, abs_lt_one_iff, abs_eq (zero_le_one' \u2124)]\n#align int.abs_le_one_iff Int.abs_le_one_iff\n\ntheorem one_le_abs {z : \u2124} (h\u2080 : z \u2260 0) : 1 \u2264 |z| :=\n  add_one_le_iff.mpr (abs_pos.mpr h\u2080)\n#align int.one_le_abs Int.one_le_abs\n\n/-- Inductively define a function on `\u2124` by defining it at `b`, for the `succ` of a number greater\nthan `b`, and the `pred` of a number less than `b`. -/\n@[elab_as_elim] protected def inductionOn' {C : \u2124 \u2192 Sort _}\n    (z : \u2124) (b : \u2124) (H0 : C b) (Hs : \u2200 k, b \u2264 k \u2192 C k \u2192 C (k + 1))\n    (Hp : \u2200 k \u2264 b, C k \u2192 C (k - 1)) : C z := by\n  rw [\u2190 sub_add_cancel (G := \u2124) z b, add_comm]\n  exact match z - b with\n  | .ofNat n => pos n\n  | .negSucc n => neg n\nwhere\n  /-- The positive case of `Int.inductionOn'`. -/\n  pos : \u2200 n : \u2115, C (b + n)\n  | 0 => _root_.cast (by erw [add_zero]) H0\n  | n+1 => _root_.cast (by rw [add_assoc]; rfl) <|\n    Hs _ (Int.le_add_of_nonneg_right (ofNat_nonneg _)) (pos n)\n\n  /-- The negative case of `Int.inductionOn'`. -/\n  neg : \u2200 n : \u2115, C (b + -[n+1])\n  | 0 => Hp _ (Int.le_refl _) H0\n  | n+1 => by\n    refine _root_.cast (by rw [add_sub_assoc]; rfl) (Hp _ (Int.le_of_lt ?_) (neg n))\n    conv => rhs; apply (add_zero b).symm\n    rw [Int.add_lt_add_iff_left]; apply negSucc_lt_zero\n#align int.induction_on' Int.inductionOn'\n\n/-- See `Int.inductionOn'` for an induction in both directions. -/\nprotected theorem le_induction {P : \u2124 \u2192 Prop} {m : \u2124} (h0 : P m)\n    (h1 : \u2200 n : \u2124, m \u2264 n \u2192 P n \u2192 P (n + 1)) (n : \u2124) : m \u2264 n \u2192 P n := by\n  refine Int.inductionOn' n m ?_ ?_ ?_\n  \u00b7 intro\n    exact h0\n  \u00b7 intro k hle hi _\n    exact h1 k hle (hi hle)\n  \u00b7 intro k hle _ hle'\n    exfalso\n    exact lt_irrefl k (le_sub_one_iff.mp (hle.trans hle'))\n#align int.le_induction Int.le_induction\n\n/-- See `Int.inductionOn'` for an induction in both directions. -/\nprotected theorem le_induction_down {P : \u2124 \u2192 Prop} {m : \u2124} (h0 : P m)\n    (h1 : \u2200 n : \u2124, n \u2264 m \u2192 P n \u2192 P (n - 1)) (n : \u2124) : n \u2264 m \u2192 P n := by\n  refine Int.inductionOn' n m ?_ ?_ ?_\n  \u00b7 intro\n    exact h0\n  \u00b7 intro k hle _ hle'\n    exfalso\n    exact lt_irrefl k (add_one_le_iff.mp (hle'.trans hle))\n  \u00b7 intro k hle hi _\n    exact h1 k hle (hi hle)\n#align int.le_induction_down Int.le_induction_down\n\n/-! ### nat abs -/\n\n\nvariable {a b : \u2124} {n : \u2115}\n\nattribute [simp] natAbs_ofNat natAbs_zero natAbs_one\n\n#align int.nat_abs_dvd_iff_dvd Int.natAbs_dvd_natAbs\n\n/-! ### `/`  -/\n\n#align int.div_nonpos Int.ediv_nonpos\n\ntheorem ediv_eq_zero_of_lt_abs {a b : \u2124} (H1 : 0 \u2264 a) (H2 : a < |b|) : a / b = 0 :=\n  match b, |b|, abs_eq_natAbs b, H2 with\n  | (n : \u2115), _, rfl, H2 => ediv_eq_zero_of_lt H1 H2\n  | -[n+1], _, rfl, H2 => neg_injective <| by rw [\u2190 Int.ediv_neg]; exact ediv_eq_zero_of_lt H1 H2\n#align int.div_eq_zero_of_lt_abs Int.ediv_eq_zero_of_lt_abs\n\n#align int.add_mul_div_right Int.add_mul_ediv_right\n\n#align int.add_mul_div_left Int.add_mul_ediv_left\n\n#align int.mul_div_cancel Int.mul_ediv_cancel\n\n#align int.mul_div_cancel_left Int.mul_ediv_cancel_left\n\n#align int.div_self Int.ediv_self\n\nattribute [local simp] Int.zero_ediv Int.ediv_zero\n\n#align int.add_div_of_dvd_right Int.add_ediv_of_dvd_right\n\n#align int.add_div_of_dvd_left Int.add_ediv_of_dvd_left\n\n/-! ### mod -/\n\n\n@[simp]\ntheorem emod_abs (a b : \u2124) : a % |b| = a % b :=\n  abs_by_cases (fun i => a % i = a % b) rfl (emod_neg _ _)\n#align int.mod_abs Int.emod_abs\n\n#align int.mod_nonneg Int.emod_nonneg\n\n#align int.mod_lt_of_pos Int.emod_lt_of_pos\n\ntheorem emod_lt (a : \u2124) {b : \u2124} (H : b \u2260 0) : a % b < |b| := by\n  rw [\u2190 emod_abs]; exact emod_lt_of_pos _ (abs_pos.2 H)\n#align int.mod_lt Int.emod_lt\n\n#align int.add_mul_mod_self Int.add_mul_emod_self\n\n#align int.add_mul_mod_self_left Int.add_mul_emod_self_left\n\n#align int.add_mod_self Int.add_emod_self\n\n#align int.add_mod_self_left Int.add_emod_self_left\n\n#align int.mod_add_mod Int.emod_add_emod\n\n#align int.add_mod_mod Int.add_emod_emod\n\n#align int.add_mod Int.add_emod\n\ntheorem add_emod_eq_add_mod_right {m n k : \u2124} (i : \u2124) (H : m % n = k % n) :\n    (m + i) % n = (k + i) % n := by rw [\u2190 emod_add_emod, \u2190 emod_add_emod k, H]\n#align int.add_mod_eq_add_mod_right Int.add_emod_eq_add_emod_right\n\n#align int.add_mod_eq_add_mod_left Int.add_emod_eq_add_emod_left\n\n#align int.mod_add_cancel_right Int.emod_add_cancel_right\n\n#align int.mod_add_cancel_left Int.emod_add_cancel_left\n\n#align int.mod_sub_cancel_right Int.emod_sub_cancel_right\n\n#align int.mul_mod_left Int.mul_emod_left\n\n#align int.mul_mod_right Int.mul_emod_right\n\n#align int.mul_mod Int.mul_emod\n\n#align int.mod_self Int.emod_self\n\n#align int.mod_mod_of_dvd Int.emod_emod_of_dvd\n\n#align int.mod_mod Int.emod_emod\n\n#align int.sub_mod Int.sub_emod\n\n-- porting note: this should be a doc comment, but the lemma isn't here any more!\n/- See also `Int.divModEquiv` for a similar statement as an `Equiv`. -/\n#align int.div_mod_unique Int.ediv_emod_unique\n\nattribute [local simp] Int.zero_emod\n\n#align int.mod_eq_mod_iff_mod_sub_eq_zero Int.emod_eq_emod_iff_emod_sub_eq_zero\n\n@[simp]\ntheorem neg_emod_two (i : \u2124) : -i % 2 = i % 2 := by\n  apply Int.emod_eq_emod_iff_emod_sub_eq_zero.mpr\n  convert Int.mul_emod_right 2 (-i) using 2\n  rw [two_mul, sub_eq_add_neg]\n#align int.neg_mod_two Int.neg_emod_two\n\n/-! ### properties of `/` and `%` -/\n\n#align int.lt_div_add_one_mul_self Int.lt_ediv_add_one_mul_self\n\ntheorem abs_ediv_le_abs : \u2200 a b : \u2124, |a / b| \u2264 |a| :=\n  suffices \u2200 (a : \u2124) (n : \u2115), |a / n| \u2264 |a| from fun a b =>\n    match b, eq_nat_or_neg b with\n    | _, \u27e8n, Or.inl rfl\u27e9 => this _ _\n    | _, \u27e8n, Or.inr rfl\u27e9 => by rw [Int.ediv_neg, abs_neg]; apply this\n  fun a n => by\n  rw [abs_eq_natAbs, abs_eq_natAbs];\n    exact\n      ofNat_le_ofNat_of_le\n        (match a, n with\n        | (m : \u2115), n => Nat.div_le_self _ _\n        | -[m+1], 0 => Nat.zero_le _\n        | -[m+1], n + 1 => Nat.succ_le_succ (Nat.div_le_self _ _))\n#align int.abs_div_le_abs Int.abs_ediv_le_abs\n\n#align int.div_le_self Int.ediv_le_self\n\ntheorem emod_two_eq_zero_or_one (n : \u2124) : n % 2 = 0 \u2228 n % 2 = 1 :=\n  have h : n % 2 < 2 := abs_of_nonneg (show 0 \u2264 (2 : \u2124) by decide) \u25b8 Int.emod_lt _ (by decide)\n  have h\u2081 : 0 \u2264 n % 2 := Int.emod_nonneg _ (by decide)\n  match n % 2, h, h\u2081 with\n  | (0 : \u2115), _ ,_ => Or.inl rfl\n  | (1 : \u2115), _ ,_ => Or.inr rfl\n  -- Porting note: this used to be `=> absurd h (by decide)`\n  -- see https://github.com/leanprover-community/mathlib4/issues/994\n  | (k + 2 : \u2115), h\u2081, _ => False.elim (h\u2081.not_le (by\n    rw [Nat.cast_add]\n    exact (le_add_iff_nonneg_left 2).2 (NonNeg.mk k)))\n  -- Porting note: this used to be `=> absurd h\u2081 (by decide)`\n  | -[a+1], _, h\u2081 => by cases h\u2081\n#align int.mod_two_eq_zero_or_one Int.emod_two_eq_zero_or_one\n\n/-! ### dvd -/\n\n#align int.dvd_of_mod_eq_zero Int.dvd_of_emod_eq_zero\n\n#align int.mod_eq_zero_of_dvd Int.emod_eq_zero_of_dvd\n\n#align int.dvd_iff_mod_eq_zero Int.dvd_iff_emod_eq_zero\n\n#align int.dvd_sub_of_mod_eq Int.dvd_sub_of_emod_eq\n\n#align int.nat_abs_dvd Int.natAbs_dvd\n\n#align int.dvd_nat_abs Int.dvd_natAbs\n\n#align int.decidable_dvd Int.decidableDvd\n\n#align int.div_mul_cancel Int.ediv_mul_cancel\n\n#align int.mul_div_cancel' Int.mul_ediv_cancel'\n\ntheorem ediv_dvd_ediv : \u2200 {a b c : \u2124} (_ : a \u2223 b) (_ : b \u2223 c), b / a \u2223 c / a\n  | a, _, _, \u27e8b, rfl\u27e9, \u27e8c, rfl\u27e9 =>\n    if az : a = 0 then by simp [az]\n    else by\n      rw [Int.mul_ediv_cancel_left _ az, mul_assoc, Int.mul_ediv_cancel_left _ az];\n        apply dvd_mul_right\n#align int.div_dvd_div Int.ediv_dvd_ediv\n\n#align int.eq_mul_of_div_eq_right Int.eq_mul_of_ediv_eq_right\n\n#align int.div_eq_of_eq_mul_right Int.ediv_eq_of_eq_mul_right\n\n#align int.eq_div_of_mul_eq_right Int.eq_ediv_of_mul_eq_right\n\n#align int.div_eq_iff_eq_mul_right Int.ediv_eq_iff_eq_mul_right\n\n#align int.div_eq_iff_eq_mul_left Int.ediv_eq_iff_eq_mul_left\n\n#align int.eq_mul_of_div_eq_left Int.eq_mul_of_ediv_eq_left\n\n#align int.div_eq_of_eq_mul_left Int.ediv_eq_of_eq_mul_left\n\n#align int.eq_zero_of_div_eq_zero Int.eq_zero_of_ediv_eq_zero\n\n#align int.div_left_inj Int.ediv_left_inj\n\ntheorem abs_sign_of_nonzero {z : \u2124} (hz : z \u2260 0) : |z.sign| = 1 := by\n  rw [abs_eq_natAbs, natAbs_sign_of_nonzero hz, Int.ofNat_one]\n#align int.abs_sign_of_nonzero Int.abs_sign_of_nonzero\n\n/-- If `n > 0` then `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)`\n  for some `k`. -/\ntheorem exists_lt_and_lt_iff_not_dvd (m : \u2124) {n : \u2124} (hn : 0 < n) :\n    (\u2203 k, n * k < m \u2227 m < n * (k + 1)) \u2194 \u00acn \u2223 m := by\n  constructor\n  \u00b7 rintro \u27e8k, h1k, h2k\u27e9 \u27e8l, rfl\u27e9\n    rw [mul_lt_mul_left hn] at h1k h2k\n    rw [lt_add_one_iff, \u2190 not_lt] at h2k\n    exact h2k h1k\n  \u00b7 intro h\n    rw [dvd_iff_emod_eq_zero, \u2190 Ne.def] at h\n    have := (emod_nonneg m hn.ne.symm).lt_of_ne h.symm\n    simp (config := { singlePass := true }) only [\u2190 emod_add_ediv m n]\n    refine' \u27e8m / n, lt_add_of_pos_left _ this, _\u27e9\n    rw [add_comm _ (1 : \u2124), left_distrib, mul_one]\n    exact add_lt_add_right (emod_lt_of_pos _ hn) _\n#align int.exists_lt_and_lt_iff_not_dvd Int.exists_lt_and_lt_iff_not_dvd\n\nattribute [local simp] Int.ediv_zero\n\n#align int.mul_div_assoc Int.mul_ediv_assoc\n\n#align int.mul_div_assoc' Int.mul_ediv_assoc'\n\n#align int.neg_div_of_dvd Int.neg_ediv_of_dvd\n\n#align int.sub_div_of_dvd Int.sub_ediv_of_dvd\n\n#align int.sub_div_of_dvd_sub Int.sub_ediv_of_dvd_sub\n\nprotected theorem sign_eq_ediv_abs (a : \u2124) : sign a = a / |a| :=\n  if az : a = 0 then by simp [az]\n  else (Int.ediv_eq_of_eq_mul_left (mt abs_eq_zero.1 az) (sign_mul_abs _).symm).symm\n#align int.sign_eq_div_abs Int.sign_eq_ediv_abs\n\n/-! ### `/` and ordering -/\n\n\nprotected theorem ediv_mul_le (a : \u2124) {b : \u2124} (H : b \u2260 0) : a / b * b \u2264 a :=\n  le_of_sub_nonneg <| by rw [mul_comm, \u2190 emod_def]; apply emod_nonneg _ H\n#align int.div_mul_le Int.ediv_mul_le\n\nprotected theorem ediv_le_of_le_mul {a b c : \u2124} (H : 0 < c) (H' : a \u2264 b * c) : a / c \u2264 b :=\n  le_of_mul_le_mul_right (le_trans (Int.ediv_mul_le _ (ne_of_gt H)) H') H\n#align int.div_le_of_le_mul Int.ediv_le_of_le_mul\n\nprotected theorem mul_lt_of_lt_ediv {a b c : \u2124} (H : 0 < c) (H3 : a < b / c) : a * c < b :=\n  lt_of_not_ge <| mt (Int.ediv_le_of_le_mul H) (not_le_of_gt H3)\n#align int.mul_lt_of_lt_div Int.mul_lt_of_lt_ediv\n\nprotected theorem mul_le_of_le_ediv {a b c : \u2124} (H1 : 0 < c) (H2 : a \u2264 b / c) : a * c \u2264 b :=\n  le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (Int.ediv_mul_le _ (ne_of_gt H1))\n#align int.mul_le_of_le_div Int.mul_le_of_le_ediv\n\nprotected \n\nprotected theorem le_ediv_iff_mul_le {a b c : \u2124} (H : 0 < c) : a \u2264 b / c \u2194 a * c \u2264 b :=\n  \u27e8Int.mul_le_of_le_ediv H, Int.le_ediv_of_mul_le H\u27e9\n#align int.le_div_iff_mul_le Int.le_ediv_iff_mul_le\n\nprotected theorem ediv_le_ediv {a b c : \u2124} (H : 0 < c) (H' : a \u2264 b) : a / c \u2264 b / c :=\n  Int.le_ediv_of_mul_le H (le_trans (Int.ediv_mul_le _ (ne_of_gt H)) H')\n#align int.div_le_div Int.ediv_le_ediv\n\nprotected theorem ediv_lt_of_lt_mul {a b c : \u2124} (H : 0 < c) (H' : a < b * c) : a / c < b :=\n  lt_of_not_ge <| mt (Int.mul_le_of_le_ediv H) (not_le_of_gt H')\n#align int.div_lt_of_lt_mul Int.ediv_lt_of_lt_mul\n\nprotected theorem lt_mul_of_ediv_lt {a b c : \u2124} (H1 : 0 < c) (H2 : a / c < b) : a < b * c :=\n  lt_of_not_ge <| mt (Int.le_ediv_of_mul_le H1) (not_le_of_gt H2)\n#align int.lt_mul_of_div_lt Int.lt_mul_of_ediv_lt\n\nprotected theorem ediv_lt_iff_lt_mul {a b c : \u2124} (H : 0 < c) : a / c < b \u2194 a < b * c :=\n  \u27e8Int.lt_mul_of_ediv_lt H, Int.ediv_lt_of_lt_mul H\u27e9\n#align int.div_lt_iff_lt_mul Int.ediv_lt_iff_lt_mul\n\nprotected theorem le_mul_of_ediv_le {a b c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 a) (H3 : a / b \u2264 c) :\n    a \u2264 c * b := by rw [\u2190 Int.ediv_mul_cancel H2]; exact mul_le_mul_of_nonneg_right H3 H1\n#align int.le_mul_of_div_le Int.le_mul_of_ediv_le\n\nprotected theorem lt_ediv_of_mul_lt {a b c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 c) (H3 : a * b < c) :\n    a < c / b :=\n  lt_of_not_ge <| mt (Int.le_mul_of_ediv_le H1 H2) (not_le_of_gt H3)\n#align int.lt_div_of_mul_lt Int.lt_ediv_of_mul_lt\n\nprotected theorem lt_ediv_iff_mul_lt {a b : \u2124} (c : \u2124) (H : 0 < c) (H' : c \u2223 b) :\n    a < b / c \u2194 a * c < b :=\n  \u27e8Int.mul_lt_of_lt_ediv H, Int.lt_ediv_of_mul_lt (le_of_lt H) H'\u27e9\n#align int.lt_div_iff_mul_lt Int.lt_ediv_iff_mul_lt\n\ntheorem ediv_pos_of_pos_of_dvd {a b : \u2124} (H1 : 0 < a) (H2 : 0 \u2264 b) (H3 : b \u2223 a) : 0 < a / b :=\n  Int.lt_ediv_of_mul_lt H2 H3 (by rwa [zero_mul])\n#align int.div_pos_of_pos_of_dvd Int.ediv_pos_of_pos_of_dvd\n\ntheorem natAbs_eq_of_dvd_dvd {s t : \u2124} (hst : s \u2223 t) (hts : t \u2223 s) : natAbs s = natAbs t :=\n  Nat.dvd_antisymm (natAbs_dvd_natAbs.mpr hst) (natAbs_dvd_natAbs.mpr hts)\n#align int.nat_abs_eq_of_dvd_dvd Int.natAbs_eq_of_dvd_dvd\n\ntheorem ediv_eq_ediv_of_mul_eq_mul {a b c d : \u2124} (H2 : d \u2223 c) (H3 : b \u2260 0) (H4 : d \u2260 0)\n    (H5 : a * d = b * c) : a / b = c / d :=\n  Int.ediv_eq_of_eq_mul_right H3 <| by\n    rw [\u2190 Int.mul_ediv_assoc _ H2]; exact (Int.ediv_eq_of_eq_mul_left H4 H5.symm).symm\n#align int.div_eq_div_of_mul_eq_mul Int.ediv_eq_ediv_of_mul_eq_mul\n\ntheorem ediv_dvd_of_dvd {s t : \u2124} (hst : s \u2223 t) : t / s \u2223 t := by\n  rcases eq_or_ne s 0 with (rfl | hs)\n  \u00b7 simpa using hst\n  rcases hst with \u27e8c, hc\u27e9\n  simp [hc, Int.mul_ediv_cancel_left _ hs]\n#align int.div_dvd_of_dvd Int.ediv_dvd_of_dvd\n\n/-! ### toNat -/\n\n\n@[simp]\ntheorem toNat_le {a : \u2124} {n : \u2115} : toNat a \u2264 n \u2194 a \u2264 n := by\n  rw [ofNat_le.symm, toNat_eq_max, max_le_iff]; exact and_iff_left (ofNat_zero_le _)\n#align int.to_nat_le Int.toNat_le\n\n@[simp]\ntheorem lt_toNat {n : \u2115} {a : \u2124} : n < toNat a \u2194 (n : \u2124) < a :=\n  le_iff_le_iff_lt_iff_lt.1 toNat_le\n#align int.lt_to_nat Int.lt_toNat\n\n@[simp]\ntheorem coe_nat_nonpos_iff {n : \u2115} : (n : \u2124) \u2264 0 \u2194 n = 0 :=\n  \u27e8fun h => le_antisymm (Int.ofNat_le.mp (h.trans Int.ofNat_zero.le)) n.zero_le,\n   fun h => (coe_nat_eq_zero.mpr h).le\u27e9\n#align int.coe_nat_nonpos_iff Int.coe_nat_nonpos_iff\n\ntheorem toNat_le_toNat {a b : \u2124} (h : a \u2264 b) : toNat a \u2264 toNat b := by\n  rw [toNat_le]; exact le_trans h (self_le_toNat b)\n#align int.to_nat_le_to_nat Int.toNat_le_toNat\n\ntheorem toNat_lt_toNat {a b : \u2124} (hb : 0 < b) : toNat a < toNat b \u2194 a < b :=\n  \u27e8fun h => by cases a; exact lt_toNat.1 h; exact lt_trans (neg_of_sign_eq_neg_one rfl) hb,\n   fun h => by rw [lt_toNat]; cases a; exact h; exact hb\u27e9\n#align int.to_nat_lt_to_nat Int.toNat_lt_toNat\n\ntheorem lt_of_toNat_lt {a b : \u2124} (h : toNat a < toNat b) : a < b :=\n  (toNat_lt_toNat <| lt_toNat.1 <| lt_of_le_of_lt (Nat.zero_le _) h).1 h\n#align int.lt_of_to_nat_lt Int.lt_of_toNat_lt\n\n@[simp]\ntheorem toNat_pred_coe_of_pos {i : \u2124} (h : 0 < i) : ((i.toNat - 1 : \u2115) : \u2124) = i - 1 := by\n  simp [h, le_of_lt h, push_cast]\n#align int.to_nat_pred_coe_of_pos Int.toNat_pred_coe_of_pos\n\n@[simp]\ntheorem toNat_eq_zero : \u2200 {n : \u2124}, n.toNat = 0 \u2194 n \u2264 0\n  | (n : \u2115) =>\n    calc\n      _ \u2194 n = 0 := \u27e8(toNat_coe_nat n).symm.trans, (toNat_coe_nat n).trans\u27e9\n      _ \u2194 _ := coe_nat_nonpos_iff.symm\n\n  | -[n+1] =>\n    show (-((n : \u2124) + 1)).toNat = 0 \u2194 (-(n + 1) : \u2124) \u2264 0 from\n      calc\n        _ \u2194 True := \u27e8fun _ => trivial, fun _ => toNat_neg_nat _\u27e9\n        _ \u2194 _ := \u27e8fun _ => neg_nonpos_of_nonneg (ofNat_zero_le _), fun _ => trivial\u27e9\n\n#align int.to_nat_eq_zero Int.toNat_eq_zero\n\n@[simp]\ntheorem toNat_sub_of_le {a b : \u2124} (h : b \u2264 a) : (toNat (a - b) : \u2124) = a - b :=\n  Int.toNat_of_nonneg (sub_nonneg_of_le h)\n#align int.to_nat_sub_of_le Int.toNat_sub_of_le\n\nend Int\n\n-- Porting note assert_not_exists not ported yet.\n-- We should need only a minimal development of sets in order to get here.\n-- assert_not_exists set.range\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/Order/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7187679682991043}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport order.conditionally_complete_lattice\nimport data.int.least_greatest\n\n/-!\n## `\u2124` forms a conditionally complete linear order\n\nThe integers form a conditionally complete linear order.\n-/\n\nopen int\nopen_locale classical\nnoncomputable theory\n\ninstance : conditionally_complete_linear_order \u2124 :=\n{ Sup := \u03bb s, if h : s.nonempty \u2227 bdd_above s then\n    greatest_of_bdd (classical.some h.2) (classical.some_spec h.2) h.1 else 0,\n  Inf := \u03bb s, if h : s.nonempty \u2227 bdd_below s then\n    least_of_bdd (classical.some h.2) (classical.some_spec h.2) h.1 else 0,\n  le_cSup := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_above s := \u27e8\u27e8n, hns\u27e9, hs\u27e9,\n    rw [dif_pos this],\n    exact (greatest_of_bdd _ _ _).2.2 n hns\n  end,\n  cSup_le := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_above s := \u27e8hs, \u27e8n, hns\u27e9\u27e9,\n    rw [dif_pos this],\n    exact hns (greatest_of_bdd _ (classical.some_spec this.2) _).2.1\n  end,\n  cInf_le := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_below s := \u27e8\u27e8n, hns\u27e9, hs\u27e9,\n    rw [dif_pos this],\n    exact (least_of_bdd _ _ _).2.2 n hns\n  end,\n  le_cInf := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_below s := \u27e8hs, \u27e8n, hns\u27e9\u27e9,\n    rw [dif_pos this],\n    exact hns (least_of_bdd _ (classical.some_spec this.2) _).2.1\n  end,\n  .. int.linear_order, ..lattice_of_linear_order }\n\nnamespace int\n\nlemma cSup_eq_greatest_of_bdd {s : set \u2124} [decidable_pred (\u2208 s)]\n  (b : \u2124) (Hb : \u2200 z \u2208 s, z \u2264 b) (Hinh : \u2203 z : \u2124, z \u2208 s) :\n  Sup s = greatest_of_bdd b Hb Hinh :=\nbegin\n  convert dif_pos _ using 1,\n  { convert coe_greatest_of_bdd_eq _ (classical.some_spec (\u27e8b, Hb\u27e9 : bdd_above s)) _ },\n  { exact \u27e8Hinh, b, Hb\u27e9, }\nend\n\n@[simp]\nlemma cSup_empty : Sup (\u2205 : set \u2124) = 0 := dif_neg (by simp)\n\nlemma cSup_of_not_bdd_above {s : set \u2124} (h : \u00ac bdd_above s) : Sup s = 0 := dif_neg (by simp [h])\n\nlemma cInf_eq_least_of_bdd {s : set \u2124} [decidable_pred (\u2208 s)]\n  (b : \u2124) (Hb : \u2200 z \u2208 s, b \u2264 z) (Hinh : \u2203 z : \u2124, z \u2208 s) :\n  Inf s = least_of_bdd b Hb Hinh :=\nbegin\n  convert dif_pos _ using 1,\n  { convert coe_least_of_bdd_eq _ (classical.some_spec (\u27e8b, Hb\u27e9 : bdd_below s)) _ },\n  { exact \u27e8Hinh, b, Hb\u27e9, }\nend\n\n@[simp]\nlemma cInf_empty : Inf (\u2205 : set \u2124) = 0 := dif_neg (by simp)\n\nlemma cInf_of_not_bdd_below {s : set \u2124} (h : \u00ac bdd_below s) : Inf s = 0 := dif_neg (by simp [h])\n\nlemma cSup_mem {s : set \u2124} (h1 : s.nonempty) (h2 : bdd_above s) : Sup s \u2208 s :=\nbegin\n  convert (greatest_of_bdd _ (classical.some_spec h2) h1).2.1,\n  exact dif_pos \u27e8h1, h2\u27e9,\nend\n\nlemma cInf_mem {s : set \u2124} (h1 : s.nonempty) (h2 : bdd_below s) : Inf s \u2208 s :=\nbegin\n  convert (least_of_bdd _ (classical.some_spec h2) h1).2.1,\n  exact dif_pos \u27e8h1, h2\u27e9,\nend\n\nend int\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/int/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.718767948223699}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module algebra.category.Module.epi_mono\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Quotient\nimport Mathbin.Algebra.Category.Module.Basic\n\n/-!\n# Monomorphisms in `Module R`\n\nThis file shows that an `R`-linear map is a monomorphism in the category of `R`-modules\nif and only if it is injective, and similarly an epimorphism if and only if it is surjective.\n-/\n\n\nuniverse v u\n\nopen CategoryTheory\n\nopen ModuleCat\n\nopen ModuleCat\n\nnamespace ModuleCat\n\nvariable {R : Type u} [Ring R] {X Y : ModuleCat.{v} R} (f : X \u27f6 Y)\n\nvariable {M : Type v} [AddCommGroup M] [Module R M]\n\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = \u22a5 :=\n  LinearMap.ker_eq_bot_of_cancel fun u v => (@cancel_mono _ _ _ _ _ f _ (\u219fu) (\u219fv)).1\n#align Module.ker_eq_bot_of_mono ModuleCat.ker_eq_bot_of_mono\n\ntheorem range_eq_top_of_epi [Epi f] : f.range = \u22a4 :=\n  LinearMap.range_eq_top_of_cancel fun u v => (@cancel_epi _ _ _ _ _ f _ (\u219fu) (\u219fv)).1\n#align Module.range_eq_top_of_epi ModuleCat.range_eq_top_of_epi\n\ntheorem mono_iff_ker_eq_bot : Mono f \u2194 f.ker = \u22a5 :=\n  \u27e8fun hf => ker_eq_bot_of_mono _, fun hf =>\n    ConcreteCategory.mono_of_injective _ <| LinearMap.ker_eq_bot.1 hf\u27e9\n#align Module.mono_iff_ker_eq_bot ModuleCat.mono_iff_ker_eq_bot\n\ntheorem mono_iff_injective : Mono f \u2194 Function.Injective f := by\n  rw [mono_iff_ker_eq_bot, LinearMap.ker_eq_bot]\n#align Module.mono_iff_injective ModuleCat.mono_iff_injective\n\ntheorem epi_iff_range_eq_top : Epi f \u2194 f.range = \u22a4 :=\n  \u27e8fun hf => range_eq_top_of_epi _, fun hf =>\n    ConcreteCategory.epi_of_surjective _ <| LinearMap.range_eq_top.1 hf\u27e9\n#align Module.epi_iff_range_eq_top ModuleCat.epi_iff_range_eq_top\n\ntheorem epi_iff_surjective : Epi f \u2194 Function.Surjective f := by\n  rw [epi_iff_range_eq_top, LinearMap.range_eq_top]\n#align Module.epi_iff_surjective ModuleCat.epi_iff_surjective\n\n/-- If the zero morphism is an epi then the codomain is trivial. -/\ndef uniqueOfEpiZero (X) [h : Epi (0 : X \u27f6 of R M)] : Unique M :=\n  uniqueOfSurjectiveZero X ((ModuleCat.epi_iff_surjective _).mp h)\n#align Module.unique_of_epi_zero ModuleCat.uniqueOfEpiZero\n\ninstance mono_as_hom'_subtype (U : Submodule R X) : Mono (\u21beU.Subtype) :=\n  (mono_iff_ker_eq_bot _).mpr (Submodule.ker_subtype U)\n#align Module.mono_as_hom'_subtype ModuleCat.mono_as_hom'_subtype\n\ninstance epi_as_hom''_mkQ (U : Submodule R X) : Epi (\u21bfU.mkQ) :=\n  (epi_iff_range_eq_top _).mpr <| Submodule.range_mkQ _\n#align Module.epi_as_hom''_mkq ModuleCat.epi_as_hom''_mkQ\n\ninstance forget_preservesEpimorphisms : (forget (ModuleCat.{v} R)).PreservesEpimorphisms\n    where preserves X Y f hf := by\n    rwa [forget_map_eq_coe, CategoryTheory.epi_iff_surjective, \u2190 epi_iff_surjective]\n#align Module.forget_preserves_epimorphisms ModuleCat.forget_preservesEpimorphisms\n\ninstance forget_preservesMonomorphisms : (forget (ModuleCat.{v} R)).PreservesMonomorphisms\n    where preserves X Y f hf := by\n    rwa [forget_map_eq_coe, CategoryTheory.mono_iff_injective, \u2190 mono_iff_injective]\n#align Module.forget_preserves_monomorphisms ModuleCat.forget_preservesMonomorphisms\n\nend ModuleCat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Category/Module/EpiMono.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7187195895024646}}
{"text": "import lib.m154\n\n/-\nCe fichier concerne la d\u00e9finition de limite d'une suite (de nombres r\u00e9els).\nUne suite u est une fonction de \u2115 dans \u211d, Lean \u00e9crit donc u : \u2115 \u2192 \u211d\n-/\n\n-- D\u00e9finition de \u00ab u tend vers l \u00bb\ndef limite_suite (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\n/-\nOn notera dans la d\u00e9finition ci-dessus l'utilisation de \u00ab \u2200 \u03b5 > 0, ... \u00bb\nqui est une abbr\u00e9viation de \u00ab \u2200 \u03b5, \u03b5 > 0 \u2192 ... \u00bb.\n\nEn particulier un \u00e9nonc\u00e9 de la forme \u00ab h : \u2200 \u03b5 > 0, P \u03b5 \u00bb se sp\u00e9cialise \u00e0\nun \u03b5\u2080 fix\u00e9 pour lequel on a une d\u00e9monstration \u03b5\u2080_pos : \u03b5\u2080 > 0, par la commande \n\u00ab Par h appliqu\u00e9 \u00e0 [\u03b5\u2080, \u03b5\u2080_pos] on obtient (h\u03b5\u2080 : P \u03b5\u2080) \u00bb \npour obtenir une nouvelle hypoth\u00e8se h\u03b5\u2080 affirmant P \u03b5\u2080.\n\nLe lemme demi_pos ci-dessous sera utile pour transformer une d\u00e9monstration\nde \u03b5 > 0 en une d\u00e9monstration de \u03b5/2 > 0 lorsque l'on sp\u00e9cialise un \u00e9nonc\u00e9\navec \u03b5/2 au lieu de \u03b5.\n\nLa d\u00e9monstration n'est pas tr\u00e8s \u00e9clairante car Lean fait le travail\nautomatiquement, mais c'est l'occasion de rappeler que la commande\n`On conclut par` accepte ce type de travail d'ajustement tr\u00e8s direct.\n-/\n\nlemma demi_pos { \u03b5 : \u211d } : \u03b5 > 0 \u2192 \u03b5/2 > 0 :=\nbegin\n  Supposons hyp : \u03b5 > 0,\n  On conclut par hyp,\nend\n\n-- Dans toute la suite, u, v et w sont des suites tandis que l et l' sont des\n-- nombres r\u00e9els\nvariables (u v w : \u2115 \u2192 \u211d) (l l' : \u211d)\n\n-- Si u est constante de valeur l, alors u tend vers l\nexample : (\u2200 n, u n = l) \u2192 limite_suite u l :=\nbegin\n  sorry\nend\n\n/- Concernant les valeurs absolues, on pourra utiliser les lemmes\n\n`abs_inferieur_ssi (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y`\n\n`abs_plus (x y : \u211d) : |x + y| \u2264 |x| + |y|`\n\n`ineg_triangle (x y z : \u211d) : |x - y| \u2264 |x - z| + |z - y|`\n\n`abs_diff (x y : \u211d) : |x - y| = |y - x|`\n\nIl est conseill\u00e9 de noter ces lemmes sur une feuille car ils\npeuvent \u00eatre utiles dans chaque exercice.\n-/\n\n-- Si u tend vers l strictement positif, alors u n \u2265 l/2 pour n assez grand.\nexample (hl : l > 0) : limite_suite u l \u2192 \u2203 N, \u2200 n \u2265 N, u n \u2265 l/2 :=\nbegin\n  sorry\nend\n\n/- Concernant le maximum de deux nombres, on pourra utiliser les lemmes\n\n`superieur_max_ssi (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q`\n\n`inferieur_max_gauche p q : p \u2264 max p q`\n\n`inferieur_max_droite p q : q \u2264 max p q`\n\nIl est conseill\u00e9 de noter ces lemmes sur une feuille car ils\npeuvent \u00eatre utiles dans chaque exercice.\n\nDans l'exemple suivant, notez particuli\u00e8rement la fa\u00e7on dont\n`demi_pos` est utilis\u00e9 : sachant que `\u03b5` est fix\u00e9 et qu'on a une\nhypoth\u00e8se `\u03b5_pos : \u03b5 > 0`, on peut former l'expression\n`demi_pos \u03b5_pos : \u03b5/2 > 0`.\n\nNotez aussi l'utilisation de `superieur_max_ssi` qui reviendra\ntr\u00e8s souvent, et la fa\u00e7on d'annoncer \u00e0 l'avance des in\u00e9galit\u00e9s\ninterm\u00e9diaire avant de la combiner par `On combine`.\n-/\n\n-- Si u tend vers l et v tend vers l' alors u+v tend vers l+l'\nexample (hu : limite_suite u l) (hv : limite_suite v l') :\nlimite_suite (u + v) (l + l') :=\nbegin\n  Soit \u03b5 > 0,\n  Par hu appliqu\u00e9 \u00e0 [\u03b5/2, demi_pos \u03b5_pos] on obtient N\u2081\n      tel que hN\u2081 : \u2200 n \u2265 N\u2081, |u n - l| \u2264 \u03b5 / 2,\n  Par hv appliqu\u00e9 \u00e0 [\u03b5/2, demi_pos \u03b5_pos] on obtient N\u2082\n      tel que hN\u2082 : \u2200 n \u2265 N\u2082, |v n - l'| \u2264 \u03b5 / 2,\n  Montrons que max N\u2081 N\u2082 convient : \u2200 n \u2265 max N\u2081 N\u2082, |(u + v) n - (l + l')| \u2264 \u03b5,\n  Soit n \u2265 max N\u2081 N\u2082,\n  On r\u00e9\u00e9crit via superieur_max_ssi dans n_ge,\n  Par n_ge on obtient (hn\u2081 : n \u2265 N\u2081) (hn\u2082 : n \u2265 N\u2082),\n  Fait fait\u2081 : |u n - l| \u2264 \u03b5/2,\n    On applique hN\u2081,\n  Fait fait\u2082 : |v n - l'| \u2264 \u03b5/2,\n    On conclut par hN\u2082 appliqu\u00e9 \u00e0 [n, hn\u2082],  -- Notez la variante Lean par rapport \u00e0 fait\u2081\n  calc\n  |(u + v) n - (l + l')| = |(u n - l) + (v n - l')| : by On calcule\n                     ... \u2264 |u n - l| + |v n - l'| : by On applique abs_plus\n                     ... \u2264  \u03b5/2 + \u03b5/2             : by On combine [fait\u2081, fait\u2082]\n                     ... =  \u03b5                     : by On calcule,\nend\n\nexample (hu : limite_suite u l) (hw : limite_suite w l)\n(h : \u2200 n, u n \u2264 v n)\n(h' : \u2200 n, v n \u2264 w n) : limite_suite v l :=\nbegin\n  sorry\n\nend\n\n-- La derni\u00e8re in\u00e9galit\u00e9 dans la d\u00e9finition de limite peut \u00eatre remplac\u00e9e par\n-- une in\u00e9galit\u00e9 stricte.\nexample (u l) : limite_suite u l \u2194\n \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5 :=\nbegin\n  sorry\nend\n\n/- Dans l'exercice suivant, on pourra utiliser le lemme\n\n`egal_si_abs_eps (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y`\n-/\n\n-- Une suite u admet au plus une limite\nexample : limite_suite u l \u2192 limite_suite u l' \u2192 l = l' :=\nbegin\n  sorry\nend\n\n-- D\u00e9finition de \u00ab la suite u est croissante \u00bb\ndef croissante (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- D\u00e9finition de \u00ab M est borne sup\u00e9rieure des termes de la suite u  \u00bb\ndef est_borne_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n-- Toute suite croissante ayant une borne sup\u00e9rieure tend vers cette borne\nexample (M : \u211d) (h : est_borne_sup M u) (h' : croissante u) :\nlimite_suite u M :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "PatrickMassot", "repo": "MDD154", "sha": "00defe82a4b6b7992ed522a92f62abd685e8c943", "save_path": "github-repos/lean/PatrickMassot-MDD154", "path": "github-repos/lean/PatrickMassot-MDD154/MDD154-00defe82a4b6b7992ed522a92f62abd685e8c943/src/08_limite_suite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7187195876704409}}
{"text": "import tactic\nimport data.nat.parity\nimport system.io\n\nsection warm_up\n\nvariables {\u03b1 \u03b2 : Type} (p q : \u03b1 \u2192 Prop) (r : \u03b1 \u2192 \u03b2 \u2192 Prop)\n\nlemma exercise_1 : (\u2200 x, p x) \u2227 (\u2200 x, q x) \u2192 \u2200 x, p x \u2227 q x :=\nbegin\n  intro H, intro x, refine \u27e8_,_\u27e9,\n  cases H with Hp Hq, exact Hp x,\n  cases H with Hp Hq, exact Hq x\nend\n\n#check exercise_1\n\n#check Prop\n\n#check Type\n\n#print and\n\n-- blast our way to the end\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 \u2200 x, q x := by finish\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := by finish\n\nexample : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, p x := by finish\n\nexample : (\u2203 x, \u2200 y, r x y) \u2192 \u2200 y, \u2203 x, r x y := by tidy\n\nend warm_up\n\n/-\nWe're going to solve a simplified version of the `coffee can problem`, due to David Gries' `The Science of Programming` (note: really good read).\n\nSuppose you have a coffee can filled with finitely many white and black beans. You have an infinite supply of white and black beans outside the can.\n\nCarry out the following procedure until there is only 1 bean left in the can:\n\n - Draw two beans\n   - if their colors are different (i.e. (white, black) or (black, white)), then you discard the white one and return the black one.\n   - if their colors are the same, discard both of them and you add a white bean to the can.\n\nProve that this process terminates with a single white bean iff the number of black beans is even.\n\nWe're going to solve this problem where the coffee can is a list and we only pop and push beans from the head of the list.\n-/\n\n/-\n  To state this problem , we need:\n     - [x] a notion of beans\n     - [x] define the \"coffee operation\"\n     - [ ] a way to count the number of white and black beans\n     - [ ] a notion of evenness (I'm going to import this from mathlib).\n-/\n\ninductive beans : Type\n| white : beans\n| black : beans\n\n#print beans.cases_on\n\nopen beans -- this opens the namespace `beans` so we don't have to qualify the constructors\n\n@[simp]\ndef coffee : list beans \u2192 list beans\n| [] := []\n| [b] := [b]\n| (white::white::bs) := coffee (white::bs)\n| (white::black::bs) := coffee (black::bs)\n| (black::white::bs) := coffee (black::bs)\n| (black::black::bs) := coffee (white::bs)\n\ndef some_beans : list beans := [white, black, white, black, black]\n\ninstance : has_repr beans :=\n{ repr := \u03bb b, beans.cases_on b \"\u25fd\" \"\u25fe\" }\n\n#eval coffee (some_beans)\n\n\n@[simp] -- by tagging this as simp, make all the equation lemmas generated by Lean\n-- available to the simplifier\ndef count_beans : beans \u2192 list beans \u2192 \u2115\n| b [] := 0\n| white (white::bs) := count_beans white bs + 1\n| white (black::bs) := count_beans white bs\n| black (white::bs) := count_beans black bs\n| black (black::bs) := count_beans black bs + 1\n\n-- Lean has a powerful built-in simplifier tactic that has access to a global library of\n-- `simp lemmas`. `simp` is essentially a confluent rewriting system.\n\nlemma count_beans_is_not_horribly_wrong {xs} : count_beans white xs + count_beans black xs = xs.length :=\nbegin\n  induction xs with hd tl IH,\n    { refl },\n    { cases hd,\n      { simp, rw \u2190 IH, omega }, -- omega will decide linear Presburger arith\n      { simp, rw \u2190 IH, omega } }\nend\n\nopen nat -- open nat namespace to avoid qualifying imported defs\n\nlemma coffee_lemma_1 {x : beans} {xs : list beans} : even (count_beans black (x::xs)) \u2194 even (count_beans black $ coffee (x::xs)) :=\nbegin\n  induction xs with hd tl IH generalizing x,\n    { cases x; simp },\n    { cases x; cases hd,\n      all_goals {try {simp * at *}},\n     have := @IH white, simp * with parity_simps at *,\n\n    have := @IH black, simp * with parity_simps at *,\n\n    have := @IH black, simp * with parity_simps at *,\n\n    have := @IH white, simp * with parity_simps at * }\nend\n\nlemma coffee_lemma_2 {x : beans} {xs : list beans} : coffee (x::xs) = [white] \u2228 coffee (x::xs) = [black] :=\nbegin\n  induction xs with hd tl IH generalizing x,\n    { cases x, simp, simp },\n    { cases x; cases hd,\n      all_goals { simp * at * }}\nend\n\ntheorem coffee_can_problem {x : beans} {xs : list beans} :\n  coffee (x::xs) = [white] \u2194 even (count_beans black (x::xs)) :=\nbegin\n  have H\u2081 : even (count_beans black (x::xs)) \u2194 even (count_beans black $ coffee (x::xs)),\n  by { apply coffee_lemma_1 },\n  have H\u2082 : coffee (x::xs) = [white] \u2228 coffee (x::xs) = [black],\n  by { apply coffee_lemma_2 },\n  cases H\u2082,\n    { refine \u27e8_,_\u27e9,\n       { intro H, rw H\u2081, rw H, simp },\n       { intro H, assumption }},\n    { \n    refine \u27e8_,_\u27e9,\n      { intro H_bad, exfalso, cc }, -- cc is the congruence closure tactic\n                                    -- chains together equalities and knows\n                                    -- how to reach simple contradictions\n                                    -- involving constructors\n      { intro H, exfalso, rw H\u2081 at H, rw H\u2082 at H, simp at H, exact H }}\nend\n\ndef coffee2 : list beans \u2192 list beans := \u03bb bns,\nmatch bns with\n| [] := []\n| bns := let num_black_beans := count_beans black bns in\n         if (even num_black_beans) then [white] else [black]\nend\n\ntheorem coffee_coffee2 : coffee = coffee2 :=\nbegin\n  funext bns, cases bns,\n    { simp[coffee2] },\n    { by_cases H : even (count_beans black $ bns_hd :: bns_tl),\n      { simp [coffee2, *], rwa \u2190 coffee_can_problem at H },\n      { simp [coffee2, *], rw \u2190 coffee_can_problem at H, finish using coffee_lemma_2 }}\nend\n\nnamespace tactic\nnamespace interactive\nnamespace tactic_parser\n\nsection metaprogramming\n\n@[reducible]meta def tactic_parser : Type \u2192 Type := state_t string tactic\n\nmeta def tactic_parser.run {\u03b1} : tactic_parser \u03b1 \u2192 string \u2192 tactic \u03b1 :=\n\u03bb p \u03c3, prod.fst <$> state_t.run p \u03c3\n\nmeta def parse_char : tactic_parser string :=\n{ run := \u03bb s, match s with\n              | \u27e8[]\u27e9 := tactic.failed\n              | \u27e8(c::cs)\u27e9 := prod.mk <$> return \u27e8[c]\u27e9 <*> return \u27e8cs\u27e9\n              end }\n\nmeta def failed {\u03b1} : tactic_parser \u03b1 := {run := \u03bb s, tactic.failed}\n\nmeta def parse_bean : tactic_parser beans :=\ndo c \u2190 parse_char,\n   if c = \"1\" then return white else\n   if c = \"0\" then return black else failed\n\nmeta def repeat {\u03b1} : tactic_parser \u03b1 \u2192 tactic_parser (list \u03b1) :=\n\u03bb p, (list.cons <$> p <*> repeat p) <|> return []\n\nmeta instance format_of_repr {\u03b1} [has_repr \u03b1] : has_to_tactic_format \u03b1 :=\n{ to_tactic_format := \u03bb b,\n    return (let f := (by apply_instance : has_repr \u03b1).repr in format.of_string (f b))}\n\nrun_cmd ((repeat parse_bean).run \"101010111001\" >>= tactic.trace)\n\n-- #eval some_more_beans\n\nend metaprogramming\nend tactic_parser\nend interactive\nend tactic\n\n/-\n  Some set theory, using Aczel sets (see mathlib's set_theory/zfc.lean for a more thorough development, or Flypitch for a Boolean-valued version)\n-/\nuniverse u\n\ninductive pSet : Type (u+1) -- Aczel sets\n| mk (\u03b1 : Type u) (A : \u03b1 \u2192 pSet)\n\nnamespace pSet\n\ndef eqv : pSet \u2192 pSet \u2192 Prop\n| (\u27e8\u03b1, A\u27e9) (\u27e8\u03b1', A'\u27e9) := (\u2200 a : \u03b1, \u2203 a' : \u03b1', eqv (A a)  (A' a')) \u2227 (\u2200 a' : \u03b1', \u2203 a : \u03b1, eqv (A a) (A' a'))\n\ndef mem : pSet \u2192 pSet \u2192 Prop\n| x (\u27e8\u03b1, A\u27e9) := \u2203 a : \u03b1, eqv x (A a)\n\ninfix `\u2208\u02e2`:1024 := pSet.mem\ninfix `=\u02e2`:1024 := pSet.eqv\n\nend pSet\n\n-- this proof actually doesn't use anything and just works for any binary relation\n-- lemma russell (x : pSet.{u}) (Hx : (\u2200 y : pSet.{u}, (y \u2208\u02e2 x \u2194 (\u00ac y \u2208\u02e2 y)))): (x \u2208\u02e2 x) \u2227 (\u00ac x \u2208\u02e2 x) :=\n-- begin\n--   refine \u27e8_,_\u27e9,\n--   { classical, by_contradiction, have := (Hx x).mpr \u2039_\u203a, contradiction },\n--   { classical, by_contradiction, have := (Hx x).mp \u2039_\u203a, contradiction }\n-- end\n\n-- indeed\nlemma russell_aux {\u03b1 : Type*} {mem : \u03b1 \u2192 \u03b1 \u2192 Prop} {x : \u03b1} (Hx : (\u2200 a : \u03b1, mem a x \u2194 \u00ac mem a a)) : mem x x \u2227 \u00ac mem x x :=\nbegin\n  refine \u27e8_,_\u27e9,\n  { classical, by_contradiction, have := (Hx x).mpr \u2039_\u203a, contradiction },\n  { classical, by_contradiction, have := (Hx x).mp \u2039_\u203a, contradiction }  \nend\n\nlemma russell (x : pSet.{u}) (Hx : (\u2200 y : pSet.{u}, (y \u2208\u02e2 x \u2194 (\u00ac y \u2208\u02e2 y)))): (x \u2208\u02e2 x) \u2227 (\u00ac x \u2208\u02e2 x) := russell_aux \u2039_\u203a\n\n@[simp]lemma eqv_refl {x : pSet} : x =\u02e2 x := by induction x; tidy\n\nlemma eqv_trans {x y z : pSet} (H\u2081 : x =\u02e2 y) (H\u2082 : y =\u02e2 z) : x =\u02e2 z :=\nbegin\n  induction x with \u03b1\u2081 A\u2081 generalizing y z, induction y with \u03b1\u2082 A\u2082, induction z with \u03b1\u2083 A\u2083,\n  cases H\u2081 with H\u2081_left H\u2081_right, cases H\u2082 with H\u2082_left H\u2082_right,\n  refine \u27e8_,_\u27e9; intro i,\n    { cases H\u2081_left i with j Hj, cases H\u2082_left j with k Hk,\n      refine \u27e8k, _\u27e9, apply x_ih, exact Hj, exact Hk, },\n    { cases H\u2082_right i with j Hj, cases H\u2081_right j with k Hk,\n      refine \u27e8k, _\u27e9, apply x_ih, exact Hk, exact Hj }\nend\n\nlemma eqv_symm {x y : pSet} (H : x =\u02e2 y) : y =\u02e2 x :=\nbegin\n  induction x with \u03b1 A generalizing y, induction y with \u03b1' A' generalizing \u03b1 A,\n  refine \u27e8_,_\u27e9; intro i; cases H with H\u2081 H\u2082,\n    { specialize H\u2082 i, cases H\u2082 with a Ha, use a, finish },\n    { specialize H\u2081 i, cases H\u2081 with a' Ha', use a', finish }\nend\n\nlemma eqv.symm {x y} : x =\u02e2 y \u2194 y =\u02e2 x := \u27e8eqv_symm, eqv_symm\u27e9\n\n@[simp]lemma mem_congr_right {x y z : pSet} (H_mem : x \u2208\u02e2 y) (H_eqv : y =\u02e2 z) : x \u2208\u02e2 z :=\nbegin\n  induction y with \u03b1 A, induction z with \u03b2 B,\n  cases H_eqv with H\u2081 H\u2082, cases H_mem with a Ha,\n  cases H\u2081 a with b Hb, use b, exact eqv_trans Ha Hb\nend\n\n@[simp]lemma mem_congr_left {x y z : pSet} (H_mem : x \u2208\u02e2 y) (H_eqv : x =\u02e2 z) : z \u2208\u02e2 y :=\nbegin\n  induction y with \u03b1 A, cases H_mem with a' Ha', use a', exact eqv_trans (eqv_symm H_eqv) \u2039_\u203a\nend\n\n@[simp]lemma mem.mk {\u03b1 : Type u} {a : \u03b1} {A : \u03b1 \u2192 pSet.{u}} : A a \u2208\u02e2 (pSet.mk \u03b1 A : pSet.{u}) := \u27e8a, by simp\u27e9\n\nlemma mem_iff {x y : pSet.{u}} : x \u2208\u02e2 y \u2194 \u2203 z : pSet.{u}, z \u2208\u02e2 y \u2227 x =\u02e2 z :=\nbegin\n  refine \u27e8_,_\u27e9; intro H,\n    { cases y with \u03b1 A, cases H with a_x H_a_x,\n      refine \u27e8A a_x, \u27e8_,_\u27e9\u27e9,\n        { simp },\n        { assumption }},\n    { rcases H with \u27e8z, \u27e8Hz\u2081, Hz\u2082\u27e9\u27e9, apply mem_congr_left \u2039_\u203a, exact eqv_symm \u2039_\u203a }\nend\n\n-- technically a consequence of foundation\nlemma foundation {x} : x \u2208\u02e2 x \u2192 false :=\nbegin\n  intro H_mem_self, induction x with \u03b1 A,\n  rcases H_mem_self with \u27e8a, Ha\u27e9, apply x_ih a,\n  exact mem_congr_right (mem.mk) \u2039_\u203a\nend\n\n-- run this file with `lean --run hello_world.lean`\ndef main : io unit :=\ndo trace (string.join ((by apply_instance : has_repr beans).repr <$> [white, black, white, black, black, black, white])) (return ()),\n   trace (\"Hello world!\") (return ())\n", "meta": {"author": "jesse-michael-han", "repo": "lean-demo", "sha": "4ec7af0d3933470030598cbb1c0c853792bd0b54", "save_path": "github-repos/lean/jesse-michael-han-lean-demo", "path": "github-repos/lean/jesse-michael-han-lean-demo/lean-demo-4ec7af0d3933470030598cbb1c0c853792bd0b54/src/helloworld.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7187195744462997}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world8.level1 -- hide\nnamespace mynat -- hide\n\n/-\n\n# Advanced Addition World\n\n## Level 2: `succ_succ_inj`.\n-/\n\n/-\nIn the below theorem, we need to apply `succ_inj` twice. Once to prove\n$succ(succ(a))=succ(succ(b))\\implies succ(a)=succ(b)$, and then again\nto prove $succ(a)=succ(b)\\implies a=b$. However `succ(a)=succ(b)` is\nnowhere to be found, it's neither an assumption or a goal when we start\nthis level. You can make it with `have` or you can use `apply`.\n-/\n/- Theorem\nFor all naturals $a$ and $b$, if we assume $succ(succ(a))=succ(succ(b))$, then we can\ndeduce $a=b$. \n-/\ntheorem succ_succ_inj {a b : mynat} (h : succ(succ(a)) = succ(succ(b))) :  a = b := \nbegin [nat_num_game]\n    have h2 : succ(a)=succ(b),\n      exact succ_inj(h),\n    exact succ_inj(h2),\n\n\n\nend\n\n/-\n## Sample solutions to this level. \n\nMake sure you understand them all. And remember that `rw` should not be used\nwith `succ_inj` -- `rw` works only with equalities or `\u2194` statements,\nnot implications or functions.\n\n-/\nexample {a b : mynat} (h : succ(succ(a)) = succ(succ(b))) :  a = b := \nbegin\n  apply succ_inj,\n  apply succ_inj,\n  exact h\nend \n\nexample {a b : mynat} (h : succ(succ(a)) = succ(succ(b))) :  a = b := \nbegin\n  apply succ_inj,\n  exact succ_inj(h),\nend \n\nexample {a b : mynat} (h : succ(succ(a)) = succ(succ(b))) :  a = b := \nbegin\n  exact succ_inj(succ_inj(h)),\nend \n\nend mynat -- hide", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world8/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.7187133504668086}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jeremy Avigad, Andrew Zipperer\n\nUsing classical logic, defines an inverse function.\n-/\nimport .function .map\nopen eq.ops classical\n\nnamespace set\n\nvariables {X Y : Type}\n\nnoncomputable definition inv_fun (f : X \u2192 Y) (a : set X) (dflt : X) (y : Y) : X :=\nif H : \u2203\u2080 x \u2208 a, f x = y then some H else dflt\n\ntheorem inv_fun_pos {f : X \u2192 Y} {a : set X} {dflt : X} {y : Y}\n  (H : \u2203\u2080 x \u2208 a, f x = y) : (inv_fun f a dflt y \u2208 a) \u2227 (f (inv_fun f a dflt y) = y) :=\nhave H1 : inv_fun f a dflt y = some H, from dif_pos H,\nH1\u207b\u00b9 \u25b8 some_spec H\n\ntheorem inv_fun_neg {f : X \u2192 Y} {a : set X} {dflt : X} {y : Y}\n  (H : \u00ac \u2203\u2080 x \u2208 a, f x = y) : inv_fun f a dflt y = dflt :=\ndif_neg H\n\nvariables {f : X \u2192 Y} {a : set X} {b : set Y}\n\ntheorem maps_to_inv_fun {dflt : X} (dflta : dflt \u2208 a) :\n  maps_to (inv_fun f a dflt) b a :=\nlet f' := inv_fun f a dflt in\ntake y,\nassume yb : y \u2208 b,\nshow f' y \u2208 a, from\n  by_cases\n    (assume H : \u2203\u2080 x \u2208 a, f x = y,\n      and.left (inv_fun_pos H))\n    (assume H : \u00ac \u2203\u2080 x \u2208 a, f x = y,\n      (inv_fun_neg H)\u207b\u00b9 \u25b8 dflta)\n\ntheorem left_inv_on_inv_fun_of_inj_on (dflt : X) (H : inj_on f a) :\n  left_inv_on (inv_fun f a dflt) f a :=\nlet f' := inv_fun f a dflt in\ntake x,\nassume xa : x \u2208 a,\nhave H1 : \u2203\u2080 x' \u2208 a, f x' = f x, from exists.intro x (and.intro xa rfl),\nhave H2 : f' (f x) \u2208 a \u2227 f (f' (f x)) = f x, from inv_fun_pos H1,\nshow f' (f x) = x, from H (and.left H2) xa (and.right H2)\n\ntheorem surj_on_inv_fun_of_inj_on (dflt : X) (mapsto : maps_to f a b) (H : inj_on f a) :\n  surj_on (inv_fun f a dflt) b a :=\nsurj_on_of_right_inv_on mapsto (left_inv_on_inv_fun_of_inj_on dflt H)\n\ntheorem right_inv_on_inv_fun_of_surj_on (dflt : X) (H : surj_on f a b) :\n  right_inv_on (inv_fun f a dflt) f b :=\nlet f' := inv_fun f a dflt in\ntake y,\nassume yb: y \u2208 b,\nobtain x (Hx : x \u2208 a \u2227 f x = y), from H yb,\nhave Hy : f' y \u2208 a \u2227 f (f' y) = y, from inv_fun_pos (exists.intro x Hx),\nand.right Hy\n\ntheorem inj_on_inv_fun (dflt : X) (H : surj_on f a b) :\n  inj_on (inv_fun f a dflt) b :=\ninj_on_of_left_inv_on (right_inv_on_inv_fun_of_surj_on dflt H)\n\nend set\n\nopen set\n\nnamespace map\n\nvariables {X Y : Type} {a : set X} {b : set Y}\n\nprotected noncomputable definition inverse (f : map a b) {dflt : X} (dflta : dflt \u2208 a) :=\nmap.mk (inv_fun f a dflt) (@maps_to_inv_fun _ _ _ _ b _ dflta)\n\ntheorem left_inverse_inverse {f : map a b} {dflt : X} (dflta : dflt \u2208 a) (H : map.injective f) :\n  map.left_inverse (map.inverse f dflta) f :=\nleft_inv_on_inv_fun_of_inj_on dflt H\n\ntheorem right_inverse_inverse {f : map a b} {dflt : X} (dflta : dflt \u2208 a) (H : map.surjective f) :\n  map.right_inverse (map.inverse f dflta) f :=\nright_inv_on_inv_fun_of_surj_on dflt H\n\ntheorem is_inverse_inverse {f : map a b} {dflt : X} (dflta : dflt \u2208 a) (H : map.bijective f) :\nmap.is_inverse (map.inverse f dflta) f :=\nand.intro\n  (left_inverse_inverse dflta (and.left H))\n  (right_inverse_inverse dflta (and.right H))\n\nend map\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/set/classical_inverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7187133478101358}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport measure_theory.covering.density_theorem\nimport measure_theory.measure.haar_lebesgue\n\n/-!\n# Covering theorems for Lebesgue measure in one dimension\n\nWe have a general theory of covering theorems for doubling measures, developed notably\nin `density_theorems.lean`. In this file, we expand the API for this theory in one dimension,\nby showing that intervals belong to the relevant Vitali family.\n-/\n\nopen set measure_theory is_doubling_measure filter\nopen_locale topology\n\nnamespace real\n\nlemma Icc_mem_vitali_family_at_right {x y : \u211d} (hxy : x < y) :\n  Icc x y \u2208 (vitali_family (volume : measure \u211d) 1).sets_at x :=\nbegin\n  rw Icc_eq_closed_ball,\n  refine closed_ball_mem_vitali_family_of_dist_le_mul _ _ (by linarith),\n  rw [dist_comm, real.dist_eq, abs_of_nonneg];\n  linarith,\nend\n\nlemma tendsto_Icc_vitali_family_right (x : \u211d) :\n  tendsto (\u03bb y, Icc x y) (\ud835\udcdd[>] x) ((vitali_family (volume : measure \u211d) 1).filter_at x) :=\nbegin\n  refine (vitali_family.tendsto_filter_at_iff _).2 \u27e8_, _\u27e9,\n  { filter_upwards [self_mem_nhds_within] with y hy using Icc_mem_vitali_family_at_right hy },\n  { assume \u03b5 \u03b5pos,\n    have : x \u2208 Ico x (x + \u03b5) := \u27e8le_refl _, by linarith\u27e9,\n    filter_upwards [Icc_mem_nhds_within_Ioi this] with y hy,\n    rw closed_ball_eq_Icc,\n    exact Icc_subset_Icc (by linarith) hy.2 }\nend\n\nlemma Icc_mem_vitali_family_at_left {x y : \u211d} (hxy : x < y) :\n  Icc x y \u2208 (vitali_family (volume : measure \u211d) 1).sets_at y :=\nbegin\n  rw Icc_eq_closed_ball,\n  refine closed_ball_mem_vitali_family_of_dist_le_mul _ _ (by linarith),\n  rw [real.dist_eq, abs_of_nonneg];\n  linarith,\nend\n\nlemma tendsto_Icc_vitali_family_left (x : \u211d) :\n  tendsto (\u03bb y, Icc y x) (\ud835\udcdd[<] x) ((vitali_family (volume : measure \u211d) 1).filter_at x) :=\nbegin\n  refine (vitali_family.tendsto_filter_at_iff _).2 \u27e8_, _\u27e9,\n  { filter_upwards [self_mem_nhds_within] with y hy using Icc_mem_vitali_family_at_left hy },\n  { assume \u03b5 \u03b5pos,\n    have : x \u2208 Ioc (x - \u03b5) x := \u27e8by linarith, le_refl _\u27e9,\n    filter_upwards [Icc_mem_nhds_within_Iio this] with y hy,\n    rw closed_ball_eq_Icc,\n    exact Icc_subset_Icc hy.1 (by linarith) }\nend\n\nend real\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/covering/one_dim.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7186872762921941}}
{"text": "-- Aplicacion_de_particiones_en_relaciones_de_equivalencia.lean\n-- Aplicaci\u00f3n de particiones en relaciones de equivalencia\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 12 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Definir la funci\u00f3n\n--    relacionP : particion A \u2192 {R : A \u2192 A \u2192 Prop // equivalence R}\n-- tal que (relacionP P) es la relaci\u00f3n de equivalencia definida por la\n-- partici\u00f3n P.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n@[ext] structure particion (A : Type) :=\n(Bloques    : set (set A))\n(Hno_vacios : \u2200 X \u2208 Bloques, (X : set A).nonempty)\n(Hrecubren  : \u2200 a, \u2203 X \u2208 Bloques, a \u2208 X)\n(Hdisjuntos : \u2200 X Y \u2208 Bloques, (X \u2229 Y : set A).nonempty \u2192 X = Y)\n\nnamespace particion\n\nvariable  {A : Type}\nvariables {X Y : set A}\nvariable  {P : particion A}\n\ndef relacion : (particion A) \u2192 (A \u2192 A \u2192 Prop) :=\n  \u03bb P a b, \u2200 X \u2208 Bloques P, a \u2208 X \u2192 b \u2208 X\n\nlemma reflexiva\n  (P : particion A)\n  : reflexive (relacion P) :=\n\u03bb a X hXC haX, haX\n\nlemma iguales_si_comun\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  : X = Y :=\nHdisjuntos P X hX Y hY \u27e8a, haX, haY\u27e9\n\nlemma pertenece_si_pertenece\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a b : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  (hbX : b \u2208 X)\n  : b \u2208 Y :=\nbegin\n  convert hbX,\n  exact iguales_si_comun hY hX haY haX,\nend\n\nlemma simetrica\n  (P : particion A)\n  : symmetric (relacion P) :=\nbegin\n  intros a b h X hX hbX,\n  obtain \u27e8Y, hY, haY\u27e9 := Hrecubren P a,\n  specialize h Y hY haY,\n  exact pertenece_si_pertenece hY hX h hbX haY,\nend\n\nlemma transitiva\n  (P : particion A)\n  : transitive (relacion P) :=\n\u03bb a b c hab hbc X hX haX, hbc X hX (hab X hX haX)\n\ndef relacionP : particion A \u2192 {R : A \u2192 A \u2192 Prop // equivalence R} :=\n  \u03bb P, \u27e8\u03bb a b, \u2200 X \u2208 Bloques P, a \u2208 X \u2192 b \u2208 X,\n        \u27e8reflexiva P, simetrica P, transitiva P\u27e9\u27e9\n\nend particion\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Aplicacion_de_particiones_en_relaciones_de_equivalencia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7186714634056052}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Kenny Lau\n-/\n\nimport algebra.geom_sum\nimport ring_theory.ideal.quotient\n\n/-!\n# Basic results in number theory\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file should contain basic results in number theory. So far, it only contains the essential\nlemma in the construction of the ring of Witt vectors.\n\n## Main statement\n\n`dvd_sub_pow_of_dvd_sub` proves that for elements `a` and `b` in a commutative ring `R` and for\nall natural numbers `p` and `k` if `p` divides `a-b` in `R`, then `p ^ (k + 1)` divides\n`a ^ (p ^ k) - b ^ (p ^ k)`.\n-/\n\nsection\n\nopen ideal ideal.quotient\n\nlemma dvd_sub_pow_of_dvd_sub {R : Type*} [comm_ring R] {p : \u2115}\n  {a b : R} (h : (p : R) \u2223 a - b) (k : \u2115) :\n  (p^(k+1) : R) \u2223 a^(p^k) - b^(p^k) :=\nbegin\n  induction k with k ih,\n  { rwa [pow_one, pow_zero, pow_one, pow_one] },\n  rw [pow_succ' p k, pow_mul, pow_mul, \u2190 geom_sum\u2082_mul, pow_succ],\n  refine mul_dvd_mul _ ih,\n  let I : ideal R := span {p},\n  let f : R \u2192+* R \u29f8 I := mk I,\n  have hp : (p : R \u29f8 I) = 0,\n  { rw [\u2190 map_nat_cast f, eq_zero_iff_mem, mem_span_singleton] },\n  rw [\u2190 mem_span_singleton, \u2190 ideal.quotient.eq] at h,\n  rw [\u2190 mem_span_singleton, \u2190 eq_zero_iff_mem, ring_hom.map_geom_sum\u2082,\n      ring_hom.map_pow, ring_hom.map_pow, h, geom_sum\u2082_self, hp, zero_mul],\nend\n\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7186714588987904}}
{"text": "/-\nCopyright (c) 2020 Kevin Lacker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Lacker, Heather Macbeth\n-/\n\nimport analysis.special_functions.trigonometric\n\n/-!\n# IMO 1962 Q4\n\nSolve the equation `cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1`.\n\nSince Lean does not have a concept of \"simplest form\", we just express what is\nin fact the simplest form of the set of solutions, and then prove it equals the set of solutions.\n-/\n\nopen real\nopen_locale real\nnoncomputable theory\n\ndef problem_equation (x : \u211d) : Prop := cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1\n\ndef solution_set : set \u211d :=\n{ x : \u211d | \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 4 \u2228 x = (2 * \u2191k + 1) * \u03c0 / 6 }\n\n/-\nThe key to solving this problem simply is that we can rewrite the equation as\na product of terms, shown in `alt_formula`, being equal to zero.\n-/\n\ndef alt_formula (x : \u211d) : \u211d := cos x * (cos x ^ 2 - 1/2) * cos (3 * x)\n\nlemma cos_sum_equiv {x : \u211d} :\n(cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 - 1) / 4 = alt_formula x :=\nbegin\n  simp only [real.cos_two_mul, cos_three_mul, alt_formula],\n  ring\nend\n\nlemma alt_equiv {x : \u211d} : problem_equation x \u2194 alt_formula x = 0 :=\nbegin\n  rw [ problem_equation, \u2190 cos_sum_equiv, div_eq_zero_iff, sub_eq_zero],\n  norm_num,\nend\n\nlemma finding_zeros {x : \u211d} :\nalt_formula x = 0 \u2194 cos x ^ 2 = 1/2 \u2228 cos (3 * x) = 0 :=\nbegin\n  simp only [alt_formula, mul_assoc, mul_eq_zero, sub_eq_zero],\n  split,\n  { rintro (h1|h2),\n    { right,\n      rw [cos_three_mul, h1],\n      ring },\n    { exact h2 } },\n  { exact or.inr }\nend\n\n/-\nNow we can solve for `x` using basic-ish trigonometry.\n-/\n\nlemma solve_cos2_half {x : \u211d} : cos x ^ 2 = 1/2 \u2194 \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 4 :=\nbegin\n  rw cos_sq,\n  simp only [add_right_eq_self, div_eq_zero_iff],\n  norm_num,\n  rw cos_eq_zero_iff,\n  split;\n  { rintro \u27e8k, h\u27e9,\n    use k,\n    linarith },\nend\n\nlemma solve_cos3x_0 {x : \u211d} : cos (3 * x) = 0 \u2194 \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 6 :=\nbegin\n  rw cos_eq_zero_iff,\n  refine exists_congr (\u03bb k, _),\n  split; intro; linarith\nend\n\n/-\nThe final theorem is now just gluing together our lemmas.\n-/\n\ntheorem imo1962_q4 {x : \u211d} : problem_equation x \u2194 x \u2208 solution_set :=\nbegin\n  rw [alt_equiv, finding_zeros, solve_cos3x_0, solve_cos2_half],\n  exact exists_or_distrib.symm\nend\n\n\n/-\nWe now present a second solution.  The key to this solution is that, when the identity is\nconverted to an identity which is polynomial in `a` := `cos x`, it can be rewritten as a product of\nterms, `a ^ 2 * (2 * a ^ 2 - 1) * (4 * a ^ 2 - 3)`, being equal to zero.\n-/\n\n/-- Someday, when there is a Grobner basis tactic, try to automate this proof. (A little tricky --\nthe ideals are not the same but their Jacobson radicals are.) -/\nlemma formula {R : Type*} [integral_domain R] [char_zero R] (a : R) :\n  a ^ 2 + (2 * a ^ 2 - 1) ^ 2 + (4 * a ^ 3 - 3 * a) ^ 2 = 1\n  \u2194 (2 * a ^ 2 - 1) * (4 * a ^ 3 - 3 * a) = 0 :=\ncalc a ^ 2 + (2 * a ^ 2 - 1) ^ 2 + (4 * a ^ 3 - 3 * a) ^ 2 = 1\n    \u2194 a ^ 2 + (2 * a ^ 2 - 1) ^ 2 + (4 * a ^ 3 - 3 * a) ^ 2 - 1 = 0 : by rw \u2190 sub_eq_zero\n... \u2194 2 * a ^ 2 * (2 * a ^ 2 - 1) * (4 * a ^ 2 - 3) = 0 : by { split; intros h; convert h; ring }\n... \u2194 a * (2 * a ^ 2 - 1) * (4 * a ^ 2 - 3) = 0 : by simp [(by norm_num : (2:R) \u2260 0)]\n... \u2194 (2 * a ^ 2 - 1) * (4 * a ^ 3 - 3 * a) = 0 : by { split; intros h; convert h using 1; ring }\n\n/-\nAgain, we now can solve for `x` using basic-ish trigonometry.\n-/\n\nlemma solve_cos2x_0 {x : \u211d} :\n  cos (2 * x) = 0 \u2194 \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 4 :=\nbegin\n  rw cos_eq_zero_iff,\n  refine exists_congr (\u03bb k, _),\n  split; intro; linarith\nend\n\n/-\nAgain, the final theorem is now just gluing together our lemmas.\n-/\n\ntheorem imo1962_q4' {x : \u211d} : problem_equation x \u2194 x \u2208 solution_set :=\ncalc problem_equation x\n    \u2194 cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1 : by refl\n... \u2194 cos (2 * x) = 0 \u2228 cos (3 * x) = 0 : by simp [cos_two_mul, cos_three_mul, formula]\n... \u2194 x \u2208 solution_set : by { rw [solve_cos2x_0, solve_cos3x_0, \u2190 exists_or_distrib], refl }\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/imo/imo1962_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7186568089688176}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n\nRing-theoretic supplement of data.polynomial.\n\nMain result: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring.\n-/\n\nimport data.polynomial data.mv_polynomial\nimport ring_theory.principal_ideal_domain\nimport ring_theory.subring\n\nuniverses u v w\n\nnamespace polynomial\n\nvariables (R : Type u) [comm_ring R] [decidable_eq R]\n\n/-- The `R`-submodule of `R[X]` consisting of polynomials of degree \u2264 `n`. -/\ndef degree_le (n : with_bot \u2115) : submodule R (polynomial R) :=\n\u2a05 k : \u2115, \u2a05 h : \u2191k > n, (lcoeff R k).ker\n\nvariable {R}\n\ntheorem mem_degree_le {n : with_bot \u2115} {f : polynomial R} :\n  f \u2208 degree_le R n \u2194 degree f \u2264 n :=\nby simp only [degree_le, submodule.mem_infi, degree_le_iff_coeff_zero, linear_map.mem_ker]; refl\n\ntheorem degree_le_mono {m n : with_bot \u2115} (H : m \u2264 n):\n  degree_le R m \u2264 degree_le R n :=\n\u03bb f hf, mem_degree_le.2 (le_trans (mem_degree_le.1 hf) H)\n\ntheorem degree_le_eq_span_X_pow {n : \u2115} :\n  degree_le R n = submodule.span R \u2191((finset.range (n+1)).image (\u03bb n, X^n) : finset (polynomial R)) :=\nbegin\n  apply le_antisymm,\n  { intros p hp, replace hp := mem_degree_le.1 hp,\n    rw [\u2190 finsupp.sum_single p, finsupp.sum, submodule.mem_coe],\n    refine submodule.sum_mem _ (\u03bb k hk, _),\n    have := with_bot.coe_le_coe.1 (finset.sup_le_iff.1 hp k hk),\n    rw [single_eq_C_mul_X, C_mul'],\n    refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $\n      finset.mem_image.2 \u27e8_, finset.mem_range.2 (nat.lt_succ_of_le this), rfl\u27e9) },\n  rw [submodule.span_le, finset.coe_image, set.image_subset_iff],\n  intros k hk, apply mem_degree_le.2,\n  apply le_trans (degree_X_pow_le _) (with_bot.coe_le_coe.2 $ nat.le_of_lt_succ $ finset.mem_range.1 hk)\nend\n\n/-- Given a polynomial, return the polynomial whose coefficients are in\nthe ring closure of the original coefficients. -/\ndef restriction (p : polynomial R) : polynomial (ring.closure (\u2191p.frange : set R)) :=\n\u27e8p.support, \u03bb i, \u27e8p.to_fun i,\n  if H : p.to_fun i = 0 then H.symm \u25b8 is_add_submonoid.zero_mem _\n  else ring.subset_closure $ finsupp.mem_frange.2 \u27e8H, i, rfl\u27e9\u27e9,\n\u03bb i, finsupp.mem_support_iff.trans (not_iff_not_of_iff \u27e8\u03bb H, subtype.eq H, subtype.mk.inj\u27e9)\u27e9\n\n@[simp] theorem coeff_restriction {p : polynomial R} {n : \u2115} : \u2191(coeff (restriction p) n) = coeff p n := rfl\n\n@[simp] theorem coeff_restriction' {p : polynomial R} {n : \u2115} : (coeff (restriction p) n).1 = coeff p n := rfl\n\n@[simp] theorem degree_restriction {p : polynomial R} : (restriction p).degree = p.degree := rfl\n\n@[simp] theorem nat_degree_restriction {p : polynomial R} : (restriction p).nat_degree = p.nat_degree := rfl\n\n@[simp] theorem monic_restriction {p : polynomial R} : monic (restriction p) \u2194 monic p :=\n\u27e8\u03bb H, congr_arg subtype.val H, \u03bb H, subtype.eq H\u27e9\n\n@[simp] theorem restriction_zero : restriction (0 : polynomial R) = 0 := rfl\n\n@[simp] theorem restriction_one : restriction (1 : polynomial R) = 1 :=\next.2 $ \u03bb i, subtype.eq $ by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs; refl\n\nvariables {S : Type v} [comm_ring S] {f : R \u2192 S} {x : S}\n\ntheorem eval\u2082_restriction {p : polynomial R} :\n  eval\u2082 f x p = eval\u2082 (f \u2218 subtype.val) x p.restriction :=\nrfl\n\nsection to_subring\nvariables (p : polynomial R) (T : set R) [is_subring T]\n\n/-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`,\nreturn the corresponding polynomial whose coefficients are in `T. -/\ndef to_subring (hp : \u2191p.frange \u2286 T) : polynomial T :=\n\u27e8p.support, \u03bb i, \u27e8p.to_fun i,\n  if H : p.to_fun i = 0 then H.symm \u25b8 is_add_submonoid.zero_mem _\n  else hp $ finsupp.mem_frange.2 \u27e8H, i, rfl\u27e9\u27e9,\n\u03bb i, finsupp.mem_support_iff.trans (not_iff_not_of_iff \u27e8\u03bb H, subtype.eq H, subtype.mk.inj\u27e9)\u27e9\n\nvariables (hp : \u2191p.frange \u2286 T)\ninclude hp\n\n@[simp] theorem coeff_to_subring {n : \u2115} : \u2191(coeff (to_subring p T hp) n) = coeff p n := rfl\n\n@[simp] theorem coeff_to_subring' {n : \u2115} : (coeff (to_subring p T hp) n).1 = coeff p n := rfl\n\n@[simp] theorem degree_to_subring : (to_subring p T hp).degree = p.degree := rfl\n\n@[simp] theorem nat_degree_to_subring : (to_subring p T hp).nat_degree = p.nat_degree := rfl\n\n@[simp] theorem monic_to_subring : monic (to_subring p T hp) \u2194 monic p :=\n\u27e8\u03bb H, congr_arg subtype.val H, \u03bb H, subtype.eq H\u27e9\n\nomit hp\n\n@[simp] theorem to_subring_zero : to_subring (0 : polynomial R) T (set.empty_subset _) = 0 := rfl\n\n@[simp] theorem to_subring_one : to_subring (1 : polynomial R) T\n  (set.subset.trans (finset.coe_subset.2 finsupp.frange_single)\n    (set.singleton_subset_iff.2 (is_submonoid.one_mem _))) = 1 :=\next.2 $ \u03bb i, subtype.eq $ by rw [coeff_to_subring', coeff_one, coeff_one]; split_ifs; refl\nend to_subring\n\nvariables (T : set R) [is_subring T]\n\n/-- Given a polynomial whose coefficients are in some subring, return\nthe corresponding polynomial whose coefificents are in the ambient ring. -/\ndef of_subring (p : polynomial T) : polynomial R :=\n\u27e8p.support, subtype.val \u2218 p.to_fun,\n\u03bb n, finsupp.mem_support_iff.trans (not_iff_not_of_iff\n  \u27e8\u03bb h, congr_arg subtype.val h, \u03bb h, subtype.eq h\u27e9)\u27e9\n\n@[simp] theorem frange_of_subring {p : polynomial T} :\n  \u2191(p.of_subring T).frange \u2286 T :=\n\u03bb y H, let \u27e8hy, x, hx\u27e9 := finsupp.mem_frange.1 H in hx \u25b8 (p.to_fun x).2\n\nend polynomial\n\nvariables {R : Type u} [comm_ring R] [decidable_eq R]\n\nnamespace ideal\nopen polynomial\n\n/-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/\ndef of_polynomial (I : ideal (polynomial R)) : submodule R (polynomial R) :=\n{ carrier := I.carrier,\n  zero := I.zero_mem,\n  add := \u03bb _ _, I.add_mem,\n  smul := \u03bb c x H, by rw [\u2190 C_mul']; exact submodule.smul_mem _ _ H }\n\nvariables {I : ideal (polynomial R)}\ntheorem mem_of_polynomial (x) : x \u2208 I.of_polynomial \u2194 x \u2208 I := iff.rfl\nvariables (I)\n\n/-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I`\nconsisting of polynomials of degree \u2264 `n`. -/\ndef degree_le (n : with_bot \u2115) : submodule R (polynomial R) :=\ndegree_le R n \u2293 I.of_polynomial\n\n/-- Given an ideal `I` of `R[X]`, make the ideal in `R` of\nleading coefficients of polynomials in `I` with degree \u2264 `n`. -/\ndef leading_coeff_nth (n : \u2115) : ideal R :=\n(I.degree_le n).map $ lcoeff R n\n\ntheorem mem_leading_coeff_nth (n : \u2115) (x) :\n  x \u2208 I.leading_coeff_nth n \u2194 \u2203 p \u2208 I, degree p \u2264 n \u2227 leading_coeff p = x :=\nbegin\n  simp only [leading_coeff_nth, degree_le, submodule.mem_map, lcoeff_apply, submodule.mem_inf, mem_degree_le],\n  split,\n  { rintro \u27e8p, \u27e8hpdeg, hpI\u27e9, rfl\u27e9,\n    cases lt_or_eq_of_le hpdeg with hpdeg hpdeg,\n    { refine \u27e80, I.zero_mem, lattice.bot_le, _\u27e9,\n      rw [leading_coeff_zero, eq_comm],\n      exact coeff_eq_zero_of_degree_lt hpdeg },\n    { refine \u27e8p, hpI, le_of_eq hpdeg, _\u27e9,\n      rw [leading_coeff, nat_degree, hpdeg], refl } },\n  { rintro \u27e8p, hpI, hpdeg, rfl\u27e9,\n    have : nat_degree p + (n - nat_degree p) = n,\n    { exact nat.add_sub_cancel' (nat_degree_le_of_degree_le hpdeg) },\n    refine \u27e8p * X ^ (n - nat_degree p), \u27e8_, I.mul_mem_right hpI\u27e9, _\u27e9,\n    { apply le_trans (degree_mul_le _ _) _,\n      apply le_trans (add_le_add' (degree_le_nat_degree) (degree_X_pow_le _)) _,\n      rw [\u2190 with_bot.coe_add, this],\n      exact le_refl _ },\n    { rw [leading_coeff, \u2190 coeff_mul_X_pow p (n - nat_degree p), this] } }\nend\n\ntheorem mem_leading_coeff_nth_zero (x) :\n  x \u2208 I.leading_coeff_nth 0 \u2194 C x \u2208 I :=\n(mem_leading_coeff_nth _ _ _).trans\n\u27e8\u03bb \u27e8p, hpI, hpdeg, hpx\u27e9, by rwa [\u2190 hpx, leading_coeff,\n  nat.eq_zero_of_le_zero (nat_degree_le_of_degree_le hpdeg),\n  \u2190 eq_C_of_degree_le_zero hpdeg],\n\u03bb hx, \u27e8C x, hx, degree_C_le, leading_coeff_C x\u27e9\u27e9\n\ntheorem leading_coeff_nth_mono {m n : \u2115} (H : m \u2264 n) :\n  I.leading_coeff_nth m \u2264 I.leading_coeff_nth n :=\nbegin\n  intros r hr,\n  simp only [submodule.mem_coe, mem_leading_coeff_nth] at hr \u22a2,\n  rcases hr with \u27e8p, hpI, hpdeg, rfl\u27e9,\n  refine \u27e8p * X ^ (n - m), I.mul_mem_right hpI, _, leading_coeff_mul_X_pow\u27e9,\n  refine le_trans (degree_mul_le _ _) _,\n  refine le_trans (add_le_add' hpdeg (degree_X_pow_le _)) _,\n  rw [\u2190 with_bot.coe_add, nat.add_sub_cancel' H],\n  exact le_refl _\nend\n\n/-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the\nleading coefficients in `I`. -/\ndef leading_coeff : ideal R :=\n\u2a06 n : \u2115, I.leading_coeff_nth n\n\ntheorem mem_leading_coeff (x) :\n  x \u2208 I.leading_coeff \u2194 \u2203 p \u2208 I, polynomial.leading_coeff p = x :=\nbegin\n  rw [leading_coeff, submodule.mem_supr_of_directed],\n  simp only [mem_leading_coeff_nth],\n  { split, { rintro \u27e8i, p, hpI, hpdeg, rfl\u27e9, exact \u27e8p, hpI, rfl\u27e9 },\n    rintro \u27e8p, hpI, rfl\u27e9, exact \u27e8nat_degree p, p, hpI, degree_le_nat_degree, rfl\u27e9 },\n  { exact \u27e80\u27e9 },\n  intros i j, exact \u27e8i + j, I.leading_coeff_nth_mono (nat.le_add_right _ _),\n    I.leading_coeff_nth_mono (nat.le_add_left _ _)\u27e9\nend\n\ntheorem is_fg_degree_le [is_noetherian_ring R] (n : \u2115) :\n  submodule.fg (I.degree_le n) :=\nis_noetherian_submodule_left.1 (is_noetherian_of_fg_of_noetherian _\n  \u27e8_, degree_le_eq_span_X_pow.symm\u27e9) _\n\nend ideal\n\n/-- Hilbert basis theorem. -/\ntheorem is_noetherian_ring_polynomial [is_noetherian_ring R] : is_noetherian_ring (polynomial R) :=\n\u27e8assume I : ideal (polynomial R),\nlet L := I.leading_coeff in\nlet M := well_founded.min (is_noetherian_iff_well_founded.1 (by apply_instance))\n  (set.range I.leading_coeff_nth) (set.ne_empty_of_mem \u27e80, rfl\u27e9) in\nhave hm : M \u2208 set.range I.leading_coeff_nth := well_founded.min_mem _ _ _,\nlet \u27e8N, HN\u27e9 := hm, \u27e8s, hs\u27e9 := I.is_fg_degree_le N in\nhave hm2 : \u2200 k, I.leading_coeff_nth k \u2264 M := \u03bb k, or.cases_on (le_or_lt k N)\n  (\u03bb h, HN \u25b8 I.leading_coeff_nth_mono h)\n  (\u03bb h x hx, classical.by_contradiction $ \u03bb hxm,\n    have \u00acM < I.leading_coeff_nth k, by refine well_founded.not_lt_min\n      well_founded_submodule_gt _ _ _; exact \u27e8k, rfl\u27e9,\n    this \u27e8HN \u25b8 I.leading_coeff_nth_mono (le_of_lt h), \u03bb H, hxm (H hx)\u27e9),\nhave hs2 : \u2200 {x}, x \u2208 I.degree_le N \u2192 x \u2208 ideal.span (\u2191s : set (polynomial R)),\nfrom hs \u25b8 \u03bb x hx, submodule.span_induction hx (\u03bb _ hx, ideal.subset_span hx) (ideal.zero_mem _)\n  (\u03bb _ _, ideal.add_mem _) (\u03bb c f hf, f.C_mul' c \u25b8 ideal.mul_mem_left _ hf),\n\u27e8s, le_antisymm (ideal.span_le.2 $ \u03bb x hx, have x \u2208 I.degree_le N, from hs \u25b8 submodule.subset_span hx, this.2) $ begin\n  change I \u2264 ideal.span \u2191s,\n  intros p hp, generalize hn : p.nat_degree = k,\n  induction k using nat.strong_induction_on with k ih generalizing p,\n  cases le_or_lt k N,\n  { subst k, refine hs2 \u27e8polynomial.mem_degree_le.2\n      (le_trans polynomial.degree_le_nat_degree $ with_bot.coe_le_coe.2 h), hp\u27e9 },\n  { have hp0 : p \u2260 0,\n    { rintro rfl, cases hn, exact nat.not_lt_zero _ h },\n    have : (0 : R) \u2260 1,\n    { intro h, apply hp0, ext i, refine (mul_one _).symm.trans _,\n      rw [\u2190 h, mul_zero], refl },\n    letI : nonzero_comm_ring R := { zero_ne_one := this,\n      ..(infer_instance : comm_ring R) },\n    have : p.leading_coeff \u2208 I.leading_coeff_nth N,\n    { rw HN, exact hm2 k ((I.mem_leading_coeff_nth _ _).2\n        \u27e8_, hp, hn \u25b8 polynomial.degree_le_nat_degree, rfl\u27e9) },\n    rw I.mem_leading_coeff_nth at this,\n    rcases this with \u27e8q, hq, hdq, hlqp\u27e9,\n    have hq0 : q \u2260 0,\n    { intro H, rw [\u2190 polynomial.leading_coeff_eq_zero] at H,\n      rw [hlqp, polynomial.leading_coeff_eq_zero] at H, exact hp0 H },\n    have h1 : p.degree = (q * polynomial.X ^ (k - q.nat_degree)).degree,\n    { rw [polynomial.degree_mul_eq', polynomial.degree_X_pow],\n      rw [polynomial.degree_eq_nat_degree hp0, polynomial.degree_eq_nat_degree hq0],\n      rw [\u2190 with_bot.coe_add, nat.add_sub_cancel', hn],\n      { refine le_trans (polynomial.nat_degree_le_of_degree_le hdq) (le_of_lt h) },\n      rw [polynomial.leading_coeff_X_pow, mul_one],\n      exact mt polynomial.leading_coeff_eq_zero.1 hq0 },\n    have h2 : p.leading_coeff = (q * polynomial.X ^ (k - q.nat_degree)).leading_coeff,\n    { rw [\u2190 hlqp, polynomial.leading_coeff_mul_X_pow] },\n    have := polynomial.degree_sub_lt h1 hp0 h2,\n    rw [polynomial.degree_eq_nat_degree hp0] at this,\n    rw \u2190 sub_add_cancel p (q * polynomial.X ^ (k - q.nat_degree)),\n    refine (ideal.span \u2191s).add_mem _ ((ideal.span \u2191s).mul_mem_right _),\n    { by_cases hpq : p - q * polynomial.X ^ (k - q.nat_degree) = 0,\n      { rw hpq, exact ideal.zero_mem _ },\n      refine ih _ _ (I.sub_mem hp (I.mul_mem_right hq)) rfl,\n      rwa [polynomial.degree_eq_nat_degree hpq, with_bot.coe_lt_coe, hn] at this },\n    exact hs2 \u27e8polynomial.mem_degree_le.2 hdq, hq\u27e9 }\nend\u27e9\u27e9\n\ntheorem is_noetherian_ring_mv_polynomial_fin {n : \u2115} [is_noetherian_ring R] :\n  is_noetherian_ring (mv_polynomial (fin n) R) :=\nbegin\n  induction n with n ih,\n  { exact is_noetherian_ring_of_ring_equiv R\n      ((mv_polynomial.pempty_ring_equiv R).symm.trans $ mv_polynomial.ring_equiv_of_equiv _\n        \u27e8pempty.elim, fin.elim0, \u03bb x, pempty.elim x, \u03bb x, fin.elim0 x\u27e9) },\n  exact @is_noetherian_ring_of_ring_equiv (polynomial (mv_polynomial (fin n) R)) _\n    (mv_polynomial (fin (n+1)) R) _\n    ((mv_polynomial.option_equiv_left _ _).symm.trans (mv_polynomial.ring_equiv_of_equiv _\n      \u27e8\u03bb x, option.rec_on x 0 fin.succ, \u03bb x, fin.cases none some x,\n      by rintro \u27e8none | x\u27e9; [refl, exact fin.cases_succ _],\n      \u03bb x, fin.cases rfl (\u03bb i, show (option.rec_on (fin.cases none some (fin.succ i) : option (fin n))\n        0 fin.succ : fin n.succ) = _, by rw fin.cases_succ) x\u27e9))\n    (@@is_noetherian_ring_polynomial _ _ ih)\nend\n\ntheorem is_noetherian_ring_mv_polynomial_of_fintype {\u03c3 : Type v} [fintype \u03c3] [decidable_eq \u03c3]\n  [is_noetherian_ring R] : is_noetherian_ring (mv_polynomial \u03c3 R) :=\ntrunc.induction_on (fintype.equiv_fin \u03c3) $ \u03bb e,\n@is_noetherian_ring_of_ring_equiv (mv_polynomial (fin (fintype.card \u03c3)) R) _ _ _\n  (mv_polynomial.ring_equiv_of_equiv _ e.symm) is_noetherian_ring_mv_polynomial_fin\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/ring_theory/polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055544, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7186568081759939}}
{"text": "-- Eliminaci\u00f3n de la equivalencia en Lean\n-- ======================================\n\n-- Demostrar que si\n--    P \u2194 Q\n--    Q \u2192 R\n-- entonces\n--    P \u2192 R\n\nimport tactic              \nvariables (P Q R : Prop)   \n\n-- 1\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nbegin\n  intro hP,\n  apply hQR,\n  cases h with hPQ hQP,\n  apply hPQ,\n  exact hP,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nbegin\n  intro hP,\n  apply hQR,\n  cases h with hPQ hQP,\n  exact hPQ hP,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nbegin\n  intro hP,\n  exact hQR (h.1 hP),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\n\u03bb hP, hQR (h.1 hP)\n\n-- 5\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nbegin\n  rw h,\n  exact hQR,\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nbegin\n  rw \u2190 h at hQR,\n  exact hQR,\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nbegin\n  assume hP : P,\n  have hQ : Q, from h.1 hP,\n  show R, from hQR hQ,\nend\n\n-- 8\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nassume hP, hQR (h.1 hP)\n\n-- 9\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nby tauto\n\n-- 10\u00aa demostraci\u00f3n\nexample \n  (h : P \u2194 Q) \n  (hQR : Q \u2192 R) \n  : P \u2192 R :=\nby finish\n\n\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/2_Conectivas/Eliminacion_de_la_equivalencia_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648678, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7186568038933778}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport data.finsupp.multiset\nimport data.multiset.antidiagonal\n\n/-!\n# The `finsupp` counterpart of `multiset.antidiagonal`.\n\nThe antidiagonal of `s : \u03b1 \u2192\u2080 \u2115` consists of\nall pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)` such that `t\u2081 + t\u2082 = s`.\n-/\n\nnoncomputable theory\nopen_locale classical big_operators\n\nnamespace finsupp\n\nopen finset\nvariables {\u03b1 : Type*}\n\n/-- The `finsupp` counterpart of `multiset.antidiagonal`: the antidiagonal of\n`s : \u03b1 \u2192\u2080 \u2115` consists of all pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)` such that `t\u2081 + t\u2082 = s`.\nThe finitely supported function `antidiagonal s` is equal to the multiplicities of these pairs. -/\ndef antidiagonal' (f : \u03b1 \u2192\u2080 \u2115) : ((\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)) \u2192\u2080 \u2115 :=\n(f.to_multiset.antidiagonal.map (prod.map multiset.to_finsupp multiset.to_finsupp)).to_finsupp\n\n/-- The antidiagonal of `s : \u03b1 \u2192\u2080 \u2115` is the finset of all pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)`\nsuch that `t\u2081 + t\u2082 = s`. -/\ndef antidiagonal (f : \u03b1 \u2192\u2080 \u2115) : finset ((\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)) :=\nf.antidiagonal'.support\n\n@[simp] lemma mem_antidiagonal {f : \u03b1 \u2192\u2080 \u2115} {p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)} :\n  p \u2208 antidiagonal f \u2194 p.1 + p.2 = f :=\nbegin\n  rcases p with \u27e8p\u2081, p\u2082\u27e9,\n  simp [antidiagonal, antidiagonal', \u2190 and.assoc, \u2190 finsupp.to_multiset.apply_eq_iff_eq]\nend\n\nlemma swap_mem_antidiagonal {n : \u03b1 \u2192\u2080 \u2115} {f : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)} :\n  f.swap \u2208 antidiagonal n \u2194 f \u2208 antidiagonal n :=\nby simp only [mem_antidiagonal, add_comm, prod.swap]\n\nlemma antidiagonal_filter_fst_eq (f g : \u03b1 \u2192\u2080 \u2115)\n  [D : \u03a0 (p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)), decidable (p.1 = g)] :\n  (antidiagonal f).filter (\u03bb p, p.1 = g) = if g \u2264 f then {(g, f - g)} else \u2205 :=\nbegin\n  ext \u27e8a, b\u27e9,\n  suffices : a = g \u2192 (a + b = f \u2194 g \u2264 f \u2227 b = f - g),\n  { simpa [apply_ite ((\u2208) (a, b)), \u2190 and.assoc, @and.right_comm _ (a = _), and.congr_left_iff] },\n  unfreezingI {rintro rfl}, split,\n  { rintro rfl, exact \u27e8le_add_right le_rfl, (add_tsub_cancel_left _ _).symm\u27e9 },\n  { rintro \u27e8h, rfl\u27e9, exact add_tsub_cancel_of_le h }\nend\n\nlemma antidiagonal_filter_snd_eq (f g : \u03b1 \u2192\u2080 \u2115)\n  [D : \u03a0 (p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)), decidable (p.2 = g)] :\n  (antidiagonal f).filter (\u03bb p, p.2 = g) = if g \u2264 f then {(f - g, g)} else \u2205 :=\nbegin\n  ext \u27e8a, b\u27e9,\n  suffices : b = g \u2192 (a + b = f \u2194 g \u2264 f \u2227 a = f - g),\n  { simpa [apply_ite ((\u2208) (a, b)), \u2190 and.assoc, and.congr_left_iff] },\n  unfreezingI {rintro rfl}, split,\n  { rintro rfl, exact \u27e8le_add_left le_rfl, (add_tsub_cancel_right _ _).symm\u27e9 },\n  { rintro \u27e8h, rfl\u27e9, exact tsub_add_cancel_of_le h }\nend\n\n@[simp] lemma antidiagonal_zero : antidiagonal (0 : \u03b1 \u2192\u2080 \u2115) = singleton (0,0) :=\nby rw [antidiagonal, antidiagonal', multiset.to_finsupp_support]; refl\n\n@[to_additive]\nlemma prod_antidiagonal_swap {M : Type*} [comm_monoid M] (n : \u03b1 \u2192\u2080 \u2115)\n  (f : (\u03b1 \u2192\u2080 \u2115) \u2192 (\u03b1 \u2192\u2080 \u2115) \u2192 M) :\n  \u220f p in antidiagonal n, f p.1 p.2 = \u220f p in antidiagonal n, f p.2 p.1 :=\nfinset.prod_bij (\u03bb p hp, p.swap) (\u03bb p, swap_mem_antidiagonal.2) (\u03bb p hp, rfl)\n  (\u03bb p\u2081 p\u2082 _ _ h, prod.swap_injective h)\n  (\u03bb p hp, \u27e8p.swap, swap_mem_antidiagonal.2 hp, p.swap_swap.symm\u27e9)\n\nend finsupp\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/finsupp/antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7186568011964091}}
{"text": "import tactic.suggest\nimport tactic.solve_by_elim\nimport tactic.show_term\n-- https://github.com/Sterrs/leaning/blob/lean-3.4.2/src/principia/mygroup/basic.lean\nnamespace hidden\n\nset_option trace.simplify.rewrite true\n\nclass mygroup (\u03b1 : Type)\nextends has_mul \u03b1, has_inv \u03b1 :=\n(e : \u03b1)\n(mul_assoc (a b c : \u03b1) : a * b * c = a * (b * c))\n(mul_id (a : \u03b1) : a * e = a)\n(mul_inv (a : \u03b1) : a * a\u207b\u00b9 = e)\n\nnamespace mygroup\nvariables {\u03b1 : Type} [mygroup \u03b1]\nvariables {a b c : \u03b1}\n\ntheorem mul_right (c : \u03b1) : a = b \u2192 a * c = b * c :=\n  begin\n    assume h,\n    type_check congr_arg (\u03bb d, d * c\u207b\u00b9) h, -- (\u03bb (d : \u03b1), d * c\u207b\u00b9) a = (\u03bb (d : \u03b1), d * c\u207b\u00b9) b\n    have h2 := congr_arg (\u03bb d, d * c) h,\n    dsimp only [] at h2,\n    exact h2,\n  end\n\ntheorem mul_by_right : a = b \u2192 a * c = b * c := mul_right c\ntheorem mul_left (c : \u03b1) : a = b \u2192 c * a = c * b :=\n  begin\n    assume h,\n    congr,\n    exact h,\n  end\n\ntheorem inv_mul (a : \u03b1) : a\u207b\u00b9 * a = e :=\n  begin\n    rw \u2190mul_inv a,\n    rw \u2190mul_id (a\u207b\u00b9 * a),\n    rw \u2190mul_inv a\u207b\u00b9,\n    rw \u2190mul_assoc (a\u207b\u00b9 * a) a\u207b\u00b9 a\u207b\u00b9\u207b\u00b9,\n    -- simp only [mul_assoc, mul_id, mul_inv],\n    rw mul_assoc a\u207b\u00b9,\n    rw mul_inv a,\n    rw mul_id a\u207b\u00b9,\n    rw mul_inv a\u207b\u00b9,\n    -- [hidden.mygroup.mul_assoc]: a\u207b\u00b9 * a * a\u207b\u00b9 ==> a\u207b\u00b9 * (a * a\u207b\u00b9)\n    -- [hidden.mygroup.mul_inv]: a * a\u207b\u00b9 ==> e\n    -- [hidden.mygroup.mul_id]: a\u207b\u00b9 * e ==> a\u207b\u00b9\n    -- [hidden.mygroup.mul_inv]: a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9 ==> e\n  end\n\ntheorem id_mul (a : \u03b1) : e * a = a :=\n  begin\n    rw \u2190mul_inv a,\n    rw mul_assoc,\n    rw inv_mul,\n    rw mul_id,\n    -- simp only [\u2190mul_inv a, mul_assoc, inv_mul, mul_id],\n    -- [[\u2190mul_inv]]: e ==> a * a\u207b\u00b9\n    -- [hidden.mygroup.mul_assoc]: a * a\u207b\u00b9 * a ==> a * (a\u207b\u00b9 * a)\n    -- [hidden.mygroup.inv_mul]: a\u207b\u00b9 * a ==> e\n    -- [[anonymous]]: e ==> a * a\u207b\u00b9\n\n    -- anonymous <=> \u2190mul_inv\n  end\n\ntheorem id_unique (a b : \u03b1) : a * b = a \u2194 b = e :=\n  begin\n    split; assume h,\n      have H := (mul_left a\u207b\u00b9) h,\n      clear h,\n      rw \u2190mul_assoc at H,\n      rw inv_mul at H,\n      rw id_mul at H,\n      exact H,\n    subst h,\n    exact mul_id a,\n    -- second way, but not works: https://github.com/Sterrs/leaning/blob/c0f3c5ee190184762ae7b926c999095f8ec9a9ac/src/principia/mygroup/basic.lean#L67-L70\n    -- split; assume h,\n    --   rwa [mul_left a, mul_id],\n    -- subst h,\n    -- from mul_id a,\n  end\n\ntheorem inv_unique (a b : \u03b1) : a * b = e \u2194 b = a\u207b\u00b9 :=\n  begin\n    split; assume h,\n      have H := (mul_left a\u207b\u00b9) h,\n      clear h,\n      rw \u2190mul_assoc at H,\n      rw inv_mul at H,\n      rw [id_mul, mul_id] at H,\n      exact H,\n    subst h,\n    exact mul_inv a,\n  end\n\nlemma inv_inv (a : \u03b1) : a\u207b\u00b9\u207b\u00b9 = a :=\n  begin\n    have h := inv_mul a\u207b\u00b9, -- \u2194 @inv_mul \u03b1 _inst_1 a\u207b\u00b9\n    have H := mul_right a h,\n    clear h,\n    rw mul_assoc at H,\n    rw inv_mul at H,\n    rw [id_mul, mul_id] at H,\n    exact H,\n  end\n--- \nattribute [simp] mul_right mul_left inv_mul id_mul mul_id id_unique inv_unique inv_inv mul_assoc mul_inv\nnamespace hidden2\nlemma inv_four : a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a :=\n  begin\n    have h := inv_inv a,\n    have h2 := inv_inv a\u207b\u00b9\u207b\u00b9,\n    exact eq.trans h2 h,\n  end\n\nlemma inv_four' : a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a :=\n  begin\n    calc a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a\u207b\u00b9\u207b\u00b9 : inv_inv a\u207b\u00b9\u207b\u00b9\n               ... = a     : inv_inv a\n  end\n\nlemma inv_four'' : a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a :=\n  by calc a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a\u207b\u00b9\u207b\u00b9 : inv_inv _\n                ... = a     : inv_inv _\n\n-- equals each other\n#print inv_four \n#print inv_four'\n#print inv_four''\n\ntheorem id_mul' : e * a = a :=\n  begin\n    -- infinite loop:\n    -- simp only [mul_assoc, inv_mul, mul_id, mul_inv a, \u2190mul_inv, \u2190mul_assoc, \u2190mul_id, \u2190mul_inv a, \u2190inv_mul],\n    sorry,\n  end\nend hidden2\n\nend mygroup\n\nvariables {\u03b1 : Type} [mygroup \u03b1]\nexample (a : \u03b1) : a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a := eq.trans (mygroup.inv_inv a\u207b\u00b9\u207b\u00b9) (mygroup.inv_inv a)\n\nexample (a : \u03b1) : a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a := by simp\nexample (a : \u03b1) : a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a\u207b\u00b9 := by simp\nexample (a b c : \u03b1) : c\u207b\u00b9 * a\u207b\u00b9 * a * b = c\u207b\u00b9 * b := by simp\n\nexample (a : \u03b1) : a\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a :=\nbegin\n  repeat {\n    apply eq.trans,\n    apply mygroup.inv_inv,\n  }\n  refl,\nend\n\nexample (a : \u03b1) : a\u207b\u00b9\u207b\u00b9\u207b\u00b9 = a\u207b\u00b9 :=\nbegin\n  repeat {\n    apply eq.trans,\n    apply mygroup.inv_inv,\n    try { refl },\n  },\nend\n\nexample (a : \u03b1) : a\u207b\u00b9 = a\u207b\u00b9\u207b\u00b9\u207b\u00b9 :=\nbegin\n  apply eq.symm,\n  repeat {\n    apply eq.trans,\n    apply mygroup.inv_inv,\n    try { refl },\n  },\nend\n\nopen int\n\nexample (n x a : \u2124) : abs x = a \u2192 x = a \u2228 x = -a :=\nbegin\n  intros h_abs,\n  have helper : \u2200 (k : \u2124), k < 0 \u2194 \u00ac k \u2265 0, sorry,\n  by_cases (a < 0), {\n    have h_pos : abs x >= 0, sorry,\n    rw h_abs at h_pos,\n    type_check iff.elim_left (helper a),\n    type_check (helper a).elim_left,\n    type_check (helper a).1,\n    have H2 := iff.elim_left (helper a) h,\n    contradiction,\n  }, {\n    rw helper _ at h,\n    -- simp at h, -- not works\n    -- change (a \u2265 0 \u2192 false) \u2192 false at h,\n    have notnot : \u2200 (p : Prop), p \u2194 \u00ac\u00acp, from sorry, -- dec_trivial, simp, change not works\n    type_check (notnot (a \u2265 0)).2 h,\n    have new_h := (notnot (a \u2265 0)).2 h, clear h, rename new_h h,\n    clear helper notnot,\n    induction a,\n    case int.of_nat {\n      sorry,\n    },\n    case int.neg_succ_of_nat {\n      sorry,\n    },\n  },\n\nend\n\nend hidden", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/community/mygroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7186567992922642}}
{"text": "/-\nCopyright (c) 2022 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n-/\n\nimport set_theory.cardinal_ordinal\nimport algebra.is_prime_pow\n\n/-!\n# Cardinal Divisibility\n\nWe show basic results about divisibility in the cardinal numbers. This relation can be characterised\nin the following simple way: if `a` and `b` are both less than `\u03c9`, then `a \u2223 b` iff they are\ndivisible as natural numbers. If `b` is greater than `\u03c9`, then `a \u2223 b` iff `a \u2264 b`. This furthermore\nshows that all infinite cardinals are prime; recall that `a * b = max a b` if `\u03c9 \u2264 a * b`; therefore\n`a \u2223 b * c = a \u2223 max b c` and therefore clearly either `a \u2223 b` or `a \u2223 c`. Note furthermore that\nno infinite cardinal is irreducible (`cardinal.not_irreducible_of_omega_le`), showing that the\ncardinal numbers do not form a `comm_cancel_monoid_with_zero`.\n\n## Main results\n\n* `cardinal.prime_of_omega_le`: a `cardinal` is prime if it is infinite.\n* `cardinal.is_prime_iff`: a `cardinal` is prime iff it is infinite or a prime natural number.\n* `cardinal.is_prime_pow_iff`: a `cardinal` is a prime power iff it is infinite or a natural number\n  which is itself a prime power.\n\n-/\n\nnamespace cardinal\n\nopen_locale cardinal\n\nuniverse u\nvariables {a b : cardinal.{u}} {n m : \u2115}\n\n@[simp] lemma is_unit_iff : is_unit a \u2194 a = 1 :=\nbegin\n  refine \u27e8\u03bb h, _, by { rintro rfl, exact is_unit_one }\u27e9,\n  rcases eq_or_ne a 0 with rfl | ha,\n  { exact (not_is_unit_zero h).elim },\n  rw is_unit_iff_forall_dvd at h,\n  cases h 1 with t ht,\n  rw [eq_comm, mul_eq_one_iff'] at ht,\n  { exact ht.1 },\n  all_goals { rwa one_le_iff_ne_zero },\n  { rintro rfl,\n    rw mul_zero at ht,\n    exact zero_ne_one ht }\nend\n\ninstance : unique cardinal.{u}\u02e3 :=\n{ default := 1,\n  uniq := \u03bb a, units.coe_eq_one.mp $ is_unit_iff.mp a.is_unit }\n\ntheorem le_of_dvd : \u2200 {a b : cardinal}, b \u2260 0 \u2192 a \u2223 b \u2192 a \u2264 b\n| a _ b0 \u27e8b, rfl\u27e9 := by simpa only [mul_one] using mul_le_mul_left'\n  (one_le_iff_ne_zero.2 (\u03bb h : b = 0, by simpa only [h, mul_zero] using b0)) a\n\nlemma dvd_of_le_of_omega_le (ha : a \u2260 0) (h : a \u2264 b) (hb : \u03c9 \u2264 b) : a \u2223 b :=\n\u27e8b, (mul_eq_right hb h ha).symm\u27e9\n\n@[simp] lemma prime_of_omega_le (ha : \u03c9 \u2264 a) : prime a :=\nbegin\n  refine \u27e8(omega_pos.trans_le ha).ne', _, \u03bb b c hbc, _\u27e9,\n  { rw is_unit_iff,\n    exact (one_lt_omega.trans_le ha).ne' },\n  cases eq_or_ne (b * c) 0 with hz hz,\n  { rcases mul_eq_zero.mp hz with rfl | rfl; simp },\n  wlog h : c \u2264 b,\n  left,\n  have habc := le_of_dvd hz hbc,\n  rwa [mul_eq_max' $ ha.trans $ habc, max_def, if_pos h] at hbc\nend\n\nlemma not_irreducible_of_omega_le (ha : \u03c9 \u2264 a) : \u00acirreducible a :=\nbegin\n  rw [irreducible_iff, not_and_distrib],\n  refine or.inr (\u03bb h, _),\n  simpa [mul_omega_eq ha, is_unit_iff, (one_lt_omega.trans_le ha).ne', one_lt_omega.ne'] using h a \u03c9\nend\n\n@[simp, norm_cast] lemma nat_coe_dvd_iff : (n : cardinal) \u2223 m \u2194 n \u2223 m :=\nbegin\n  refine \u27e8_, \u03bb \u27e8h, ht\u27e9, \u27e8h, by exact_mod_cast ht\u27e9\u27e9,\n  rintro \u27e8k, hk\u27e9,\n  have : \u2191m < \u03c9 := nat_lt_omega m,\n  rw [hk, mul_lt_omega_iff] at this,\n  rcases this with h | h | \u27e8-, hk'\u27e9,\n  iterate 2 { simp only [h, mul_zero,  zero_mul, nat.cast_eq_zero] at hk, simp [hk] },\n  lift k to \u2115 using hk',\n  exact \u27e8k, by exact_mod_cast hk\u27e9\nend\n\n@[simp] lemma nat_is_prime_iff : prime (n : cardinal) \u2194 n.prime :=\nbegin\n  simp only [prime, nat.prime_iff],\n  refine and_congr (by simp) (and_congr _ \u27e8\u03bb h b c hbc, _, \u03bb h b c hbc, _\u27e9),\n  { simp only [is_unit_iff, nat.is_unit_iff],\n    exact_mod_cast iff.rfl },\n  { exact_mod_cast h b c (by exact_mod_cast hbc) },\n  cases lt_or_le (b * c) \u03c9 with h' h',\n  { rcases mul_lt_omega_iff.mp h' with rfl | rfl | \u27e8hb, hc\u27e9,\n    { simp },\n    { simp },\n    lift b to \u2115 using hb,\n    lift c to \u2115 using hc,\n    exact_mod_cast h b c (by exact_mod_cast hbc) },\n  rcases omega_le_mul_iff.mp h' with \u27e8hb, hc, h\u03c9\u27e9,\n  have hn : (n : cardinal) \u2260 0,\n  { intro h,\n    rw [h, zero_dvd_iff, mul_eq_zero] at hbc,\n    cases hbc; contradiction },\n  wlog h\u03c9 : \u03c9 \u2264 b := h\u03c9 using [b c],\n  exact or.inl (dvd_of_le_of_omega_le hn ((nat_lt_omega n).le.trans h\u03c9) h\u03c9),\nend\n\nlemma is_prime_iff {a : cardinal} : prime a \u2194 \u03c9 \u2264 a \u2228 \u2203 p : \u2115, a = p \u2227 p.prime :=\nbegin\n  cases le_or_lt \u03c9 a with h h,\n  { simp [h] },\n  lift a to \u2115 using id h,\n  simp [not_le.mpr h]\nend\n\nlemma is_prime_pow_iff {a : cardinal} : is_prime_pow a \u2194 \u03c9 \u2264 a \u2228 \u2203 n : \u2115, a = n \u2227 is_prime_pow n :=\nbegin\n  by_cases h : \u03c9 \u2264 a,\n  { simp [h, (prime_of_omega_le h).is_prime_pow] },\n  lift a to \u2115 using not_le.mp h,\n  simp only [h, nat.cast_inj, exists_eq_left', false_or, is_prime_pow_nat_iff],\n  rw is_prime_pow_def,\n  refine \u27e8_, \u03bb \u27e8p, k, hp, hk, h\u27e9, \u27e8p, k, nat_is_prime_iff.2 hp, by exact_mod_cast and.intro hk h\u27e9\u27e9,\n  rintro \u27e8p, k, hp, hk, hpk\u27e9,\n  have key : _ \u2264 p ^ k :=\n    power_le_power_left hp.ne_zero (show (1 : cardinal) \u2264 k, by exact_mod_cast hk),\n  rw [power_one, hpk] at key,\n  lift p to \u2115 using key.trans_lt (nat_lt_omega a),\n  exact \u27e8p, k, nat_is_prime_iff.mp hp, hk, by exact_mod_cast hpk\u27e9\nend\n\nend cardinal\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/set_theory/cardinal_divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7186567969137918}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland\n-/\nimport algebra.ring.semiconj\nimport algebra.ring.units\nimport algebra.group.commute\n\n/-!\n# Semirings and rings\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file gives lemmas about semirings, rings and domains.\nThis is analogous to `algebra.group.basic`,\nthe difference being that the former is about `+` and `*` separately, while\nthe present file is about their interaction.\n\nFor the definitions of semirings and rings see `algebra.ring.defs`.\n\n-/\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {R : Type x}\n\nopen function\n\nnamespace commute\n\n@[simp] theorem add_right [distrib R] {a b c : R} :\n  commute a b \u2192 commute a c \u2192 commute a (b + c) :=\nsemiconj_by.add_right\n\n@[simp] theorem add_left [distrib R] {a b c : R} :\n  commute a c \u2192 commute b c \u2192 commute (a + b) c :=\nsemiconj_by.add_left\n\nlemma bit0_right [distrib R] {x y : R} (h : commute x y) : commute x (bit0 y) :=\nh.add_right h\n\nlemma bit0_left [distrib R] {x y : R} (h : commute x y) : commute (bit0 x) y :=\nh.add_left h\n\nlemma bit1_right [non_assoc_semiring R] {x y : R} (h : commute x y) : commute x (bit1 y) :=\nh.bit0_right.add_right (commute.one_right x)\n\nlemma bit1_left [non_assoc_semiring R] {x y : R} (h : commute x y) : commute (bit1 x) y :=\nh.bit0_left.add_left (commute.one_left y)\n\n/-- Representation of a difference of two squares of commuting elements as a product. -/\nlemma mul_self_sub_mul_self_eq [non_unital_non_assoc_ring R] {a b : R} (h : commute a b) :\n  a * a - b * b = (a + b) * (a - b) :=\nby rw [add_mul, mul_sub, mul_sub, h.eq, sub_add_sub_cancel]\n\nlemma mul_self_sub_mul_self_eq' [non_unital_non_assoc_ring R] {a b : R} (h : commute a b) :\n  a * a - b * b = (a - b) * (a + b) :=\nby rw [mul_add, sub_mul, sub_mul, h.eq, sub_add_sub_cancel]\n\nlemma mul_self_eq_mul_self_iff [non_unital_non_assoc_ring R] [no_zero_divisors R] {a b : R}\n  (h : commute a b) : a * a = b * b \u2194 a = b \u2228 a = -b :=\nby rw [\u2190 sub_eq_zero, h.mul_self_sub_mul_self_eq, mul_eq_zero, or_comm, sub_eq_zero,\n  add_eq_zero_iff_eq_neg]\n\nsection\nvariables [has_mul R] [has_distrib_neg R] {a b : R}\n\ntheorem neg_right : commute a b \u2192 commute a (- b) := semiconj_by.neg_right\n@[simp] theorem neg_right_iff : commute a (-b) \u2194 commute a b := semiconj_by.neg_right_iff\n\ntheorem neg_left : commute a b \u2192 commute (- a) b := semiconj_by.neg_left\n@[simp] theorem neg_left_iff : commute (-a) b \u2194 commute a b := semiconj_by.neg_left_iff\n\nend\n\nsection\nvariables [mul_one_class R] [has_distrib_neg R] {a : R}\n\n@[simp] theorem neg_one_right (a : R) : commute a (-1) := semiconj_by.neg_one_right a\n@[simp] theorem neg_one_left (a : R): commute (-1) a := semiconj_by.neg_one_left a\n\nend\n\nsection\nvariables [non_unital_non_assoc_ring R] {a b c : R}\n\n@[simp] theorem sub_right : commute a b \u2192 commute a c \u2192 commute a (b - c) := semiconj_by.sub_right\n@[simp] theorem sub_left : commute a c \u2192 commute b c \u2192 commute (a - b) c := semiconj_by.sub_left\n\nend\n\nend commute\n\n/-- Representation of a difference of two squares in a commutative ring as a product. -/\ntheorem mul_self_sub_mul_self [comm_ring R] (a b : R) : a * a - b * b = (a + b) * (a - b) :=\n(commute.all a b).mul_self_sub_mul_self_eq\n\nlemma mul_self_sub_one [non_assoc_ring R] (a : R) : a * a - 1 = (a + 1) * (a - 1) :=\nby rw [\u2190(commute.one_right a).mul_self_sub_mul_self_eq, mul_one]\n\nlemma mul_self_eq_mul_self_iff [comm_ring R] [no_zero_divisors R] {a b : R} :\n  a * a = b * b \u2194 a = b \u2228 a = -b :=\n(commute.all a b).mul_self_eq_mul_self_iff\n\nlemma mul_self_eq_one_iff [non_assoc_ring R] [no_zero_divisors R] {a : R} :\n  a * a = 1 \u2194 a = 1 \u2228 a = -1 :=\nby rw [\u2190(commute.one_right a).mul_self_eq_mul_self_iff, mul_one]\n\nnamespace units\n\n/-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or\n  one's additive inverse. -/\nlemma inv_eq_self_iff [ring R] [no_zero_divisors R] (u : R\u02e3) : u\u207b\u00b9 = u \u2194 u = 1 \u2228 u = -1 :=\nbegin\n  rw inv_eq_iff_mul_eq_one,\n  simp only [ext_iff],\n  push_cast,\n  exact mul_self_eq_one_iff\nend\n\nend units\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/ring/commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7186567946911507}}
{"text": "import data.real.basic\n\ndef converges_to (s : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (s n - a) < \u03b5\n\nexample : (\u03bb x y : \u211d, (x + y)^2) = (\u03bb x y : \u211d, x^2 + 2*x*y + y^2) :=\nby { ext, ring }\n\nexample (a b : \u211d) : abs a = abs (a - b + b) :=\nby  { congr, ring }\n\nexample {a : \u211d} (h : 1 < a) : a < a * a :=\nbegin\n  convert (mul_lt_mul_right _).2 h;\n  linarith\nend\n\ntheorem converges_to_const (a : \u211d) : converges_to (\u03bb x : \u2115, a) a :=\nbegin\n  intros \u03b5 \u03b5pos,\n  use 0,\n  intros n nge, dsimp,\n  rw [sub_self, abs_zero],\n  apply \u03b5pos\nend\n\ntheorem converges_to_add {s t : \u2115 \u2192 \u211d} {a b : \u211d}\n  (cs : converges_to s a) (ct : converges_to t b):\nconverges_to (\u03bb n, s n + t n) (a + b) :=\nbegin\n  intros \u03b5 \u03b5pos, dsimp,\n  have \u03b52pos : 0 < \u03b5 / 2,\n  { linarith },\n  cases cs (\u03b5 / 2) \u03b52pos with Ns hs,\n  cases ct (\u03b5 / 2) \u03b52pos with Nt ht,\n  use max Ns Nt,\n  intros n hM,\n  have h_ex1 : |s n - a| < \u03b5 / 2,\n  { exact hs n (by linarith [le_max_left Ns Nt]) },\n  -- `linarith` does require both arguments `Ns` and `Nt`\n  have h_ex2 : |t n - b| < \u03b5 / 2,\n  { exact ht n (by linarith [le_max_right Ns Nt]) },\n  calc\n    |s n + t n - (a + b)| = |s n - a + (t n - b)| : by ring\n    ...      \u2264 |s n - a| + |t n - b| : abs_add _ _\n    ...      < \u03b5/2 + \u03b5/2 : by { linarith }\n    ...      = \u03b5 : by ring,\nend\n\ntheorem converges_to_mul_const {s : \u2115 \u2192 \u211d} {a : \u211d}\n    (c : \u211d) (cs : converges_to s a) :\n  converges_to (\u03bb n, c * s n) (c * a) :=\nbegin\n  by_cases h : c = 0,\n  { convert converges_to_const 0,\n    { ext, rw [h, zero_mul] },\n    rw [h, zero_mul] },\n  have acpos : 0 < abs c,\n    from abs_pos.mpr h,\n  intros \u03b5 \u03b5_pos, dsimp,\n  have \u03b5cpos : 0 < \u03b5 / |c|,\n  { exact div_pos \u03b5_pos acpos},\n  cases cs (\u03b5 / |c|) \u03b5cpos with Ns hs,\n  use Ns,\n  intros n hn,\n  have : |c| * (\u03b5 / |c|) = \u03b5,\n  -- Next two goals solved in a horribly convoluted way\n  { calc\n    |c| * (\u03b5 / |c|)  = |c| * |c|\u207b\u00b9 * \u03b5 :  by ring\n    ... =  \u03b5 : by { rw mul_inv_cancel, norm_num, linarith} },\n  calc\n  |c * s n - c * a| = |c| * |s n - a| : by rw [\u2190 mul_sub, abs_mul]\n  ...               < \u03b5                :\n  begin\n    convert @mul_lt_mul' \u211d (by apply_instance) (|c|) _ (|c|) (\u03b5 / |c|) _ _ _ _ ;\n    linarith [hs n hn, abs_nonneg (s n - a)]\n  end\nend\n\ntheorem exists_abs_le_of_converges_to {s : \u2115 \u2192 \u211d} {a : \u211d}\n    (cs : converges_to s a) :\n  \u2203 N b, \u2200 n, N \u2264 n \u2192 abs (s n) < b :=\nbegin\n  cases cs 1 zero_lt_one with N h,\n  use [N, abs a + 1],\n  sorry\nend\n\nlemma aux {s t : \u2115 \u2192 \u211d} {a : \u211d}\n    (cs : converges_to s a) (ct : converges_to t 0) :\n  converges_to (\u03bb n, s n * t n) 0 :=\nbegin\n  intros \u03b5 \u03b5pos, dsimp,\n  rcases exists_abs_le_of_converges_to cs with \u27e8N\u2080, B, h\u2080\u27e9,\n  have Bpos : 0 < B,\n    from lt_of_le_of_lt (abs_nonneg _) (h\u2080 N\u2080 (le_refl _)),\n  have pos\u2080 : \u03b5 / B > 0,\n    from div_pos \u03b5pos Bpos,\n  cases ct _ pos\u2080 with N\u2081 h\u2081,\n  sorry\nend\n\ntheorem converges_to_mul {s t : \u2115 \u2192 \u211d} {a b : \u211d}\n    (cs : converges_to s a) (ct : converges_to t b):\n  converges_to (\u03bb n, s n * t n) (a * b) :=\nbegin\n  have h\u2081 : converges_to (\u03bb n, s n * (t n - b)) 0,\n  { apply aux cs,\n    convert converges_to_add ct (converges_to_const (-b)),\n    ring },\n  convert (converges_to_add h\u2081 (converges_to_mul_const b cs)),\n  { ext, ring },\n  ring\nend\n\ntheorem converges_to_unique {s : \u2115 \u2192 \u211d} {a b : \u211d}\n    (sa : converges_to s a) (sb : converges_to s b) :\n  a = b :=\nbegin\n  by_contradiction abne,\n  have : abs (a - b) > 0,\n  { apply lt_abs.mpr, norm_num, tauto},\n  let \u03b5 := abs (a - b) / 2,\n  have \u03b5pos : \u03b5 > 0,\n  { change abs (a - b) / 2 > 0, linarith },\n  cases sa \u03b5 \u03b5pos with Na hNa,\n  cases sb \u03b5 \u03b5pos with Nb hNb,\n  let N := max Na Nb,\n  have absa : abs (s N - a) < \u03b5,\n  { exact hNa N (le_max_left Na Nb) },\n  have absb : abs (s N - b) < \u03b5,\n  { exact hNb N (le_max_right Na Nb) },\n  have : abs (a - b) < abs (a - b),\n  {\n    calc\n    |a - b| = |(s N - b) - (s N - a)| : by ring\n    ...     \u2264 |s N - b| + |s N - a|   : by { apply abs_sub,}\n    ...     < \u03b5 + \u03b5   : by linarith\n    ...     = |a - b| : by norm_num,\n   },\n  exact lt_irrefl _ this\nend\n\nsection\nvariables {\u03b1 : Type*} [linear_order \u03b1]\n\ndef converges_to' (s : \u03b1 \u2192 \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (s n - a) < \u03b5\n\nend\n\n", "meta": {"author": "sterraf", "repo": "mylearninglean", "sha": "a8911234b2a4e15a48ec2c0f05d744e58f798ca7", "save_path": "github-repos/lean/sterraf-mylearninglean", "path": "github-repos/lean/sterraf-mylearninglean/mylearninglean-a8911234b2a4e15a48ec2c0f05d744e58f798ca7/src/mathematics_in_lean_src/03_Logic/06_Sequences_and_Convergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.718656792787006}}
{"text": "section\n  variable (p q r : Prop)\n\n  example : p \u2227 q \u2194 q \u2227 p := \n    Iff.intro\n    (fun h => \u27e8h.right, h.left\u27e9)\n    (fun h => \u27e8h.right, h.left\u27e9)\n\n  example : p \u2228 q \u2194 q \u2228 p :=\n    Iff.intro\n    (\n      fun h =>\n        Or.elim h \n        (\n          fun hp => Or.inr hp\n        )\n        (\n          fun hq => Or.inl hq\n        )\n    )\n    (\n      fun h =>\n        Or.elim h\n        (\n          fun hq => Or.inr hq\n        )\n        (\n          fun hp => Or.inl hp\n        )\n    )\n\n  example : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n    Iff.intro\n    (\n      fun h =>\n        \u27e8h.left.left, \u27e8h.left.right, h.right\u27e9\u27e9\n    )\n    (\n      fun h =>\n        \u27e8\u27e8h.left, h.right.left\u27e9, h.right.right\u27e9\n    )\n\n  example : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n    Iff.intro \n    (\n      fun h =>\n        Or.elim h \n        (\n          fun hpq => \n            Or.elim hpq\n            (\n              fun hp => Or.inl hp\n            )\n            (\n              fun hq => Or.inr $ Or.inl hq\n            )\n        )\n        (\n          fun hr =>\n            Or.inr $ Or.inr hr\n        )\n    )\n    ( \n      fun h =>\n        Or.elim h\n        (\n          fun hp =>\n            Or.inl $ Or.inl hp\n        )\n        (\n          fun hqr =>\n            Or.elim hqr\n            (\n              fun hq => Or.inl $ Or.inr hq\n            )\n            (\n              fun hr => Or.inr hr \n            )\n        )\n    )\n\n  example : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n    Iff.intro\n    (\n      fun h =>\n        have hp := h.left\n        Or.elim h.right \n        (\n          fun hq => \n            Or.inl $ And.intro hp hq \n        )\n        (\n          fun hr => \n            Or.inr $ And.intro hp hr  \n        )\n    )\n    (\n      fun h =>\n        Or.elim h\n        (\n          fun hpq => \n            And.intro hpq.left $ Or.inl hpq.right \n        )\n        (\n          fun hpr =>\n            have hp := hpr.left\n            have hr := hpr.right\n            have hqr := Or.inr hr \n            And.intro hp hqr\n        )\n    )\n\n  example : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n    Iff.intro \n    (\n      fun h =>\n        Or.elim h\n        (\n          fun hp => \n            \u27e8Or.inl hp, Or.inl hp\u27e9\n        )\n        (\n          fun hqr =>\n            \u27e8Or.inr hqr.left, Or.inr hqr.right\u27e9\n        )\n    )\n    (\n      fun h =>\n        have hpq := h.left\n        have hpr := h.right\n        Or.elim hpq\n        (\n          fun hp =>\n            Or.inl hp\n        )\n        (\n          fun hq =>\n            Or.elim hpr \n            (\n              fun hp =>\n                Or.inl hp\n            )\n            (\n              fun hr =>\n                Or.inr \u27e8hq, hr\u27e9\n            )\n        )\n    )\n\n  example : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n    Iff.intro \n    (\n      fun hpqr =>\n        fun hpq =>\n          have hp := hpq.left\n          have hq := hpq.right\n          hpqr hp hq\n    )\n    (\n      fun h =>\n        fun hp =>\n          fun hq =>\n            have hpq := \u27e8hp, hq\u27e9\n            h hpq\n    )\n\n  example : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := \n    Iff.intro\n    (\n      fun h =>\n        And.intro\n        (\n          fun hp : p =>\n            have hpq := Or.inl hp\n            have hr := h hpq \n            hr\n        )\n        (\n          fun hq : q =>\n            have hpq := Or.inr hq \n            have hr := h hpq\n            hr\n        )\n    )\n    (\n      fun h =>\n        fun hpq : p \u2228 q =>\n          Or.elim hpq\n          (\n            fun hp => \n              h.left hp\n          )\n          (\n            fun hq =>  \n              h.right hq\n          )\n    )\n\n  example : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n    Iff.intro \n    (\n      fun hnpq : \u00ac(p \u2228 q) =>\n        And.intro \n        (\n          fun hp : p =>\n            have hpq : p \u2228 q := Or.inl hp \n            hnpq hpq\n        )\n        (\n          fun hq : q =>\n            have hpq : p \u2228 q := Or.inr hq \n            hnpq hpq\n        )\n    )\n    (\n      fun hnpnq : \u00acp \u2227 \u00acq =>\n        fun hpq : p \u2228 q =>\n          Or.elim hpq \n          (\n            fun hp =>\n              have hnp := hnpnq.left\n              hnp hp\n          )\n          (\n            fun hq =>\n              hnpnq.right hq\n          )\n\n    )\n\n  example : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n    fun hnpnq : \u00acp \u2228 \u00acq =>\n      fun hpq : p \u2227 q =>\n        Or.elim hnpnq \n        (\n          fun hnp : \u00acp =>\n            hnp hpq.left\n        )\n        (\n          fun hnq : \u00acq =>\n            hnq hpq.right\n        )\n\n  example : \u00ac(p \u2227 \u00acp) :=\n    fun hpnp : p \u2227 \u00acp =>\n      hpnp.right hpnp.left\n\n  example : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n    fun h =>\n      fun hpq =>\n        have hq := hpq h.left\n        h.right hq\n\n  example : \u00acp \u2192 (p \u2192 q) :=\n    fun hnp =>\n      fun hp =>\n        absurd hp hnp \n\n  example : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n    fun hnpq =>\n      fun hp =>\n        Or.elim hnpq \n        (\n          fun hnp =>\n            absurd hp hnp \n        )\n        (\n          fun hq =>\n            hq\n        )\n\n  example : p \u2228 False \u2194 p :=\n    Iff.intro\n    (\n      fun h =>\n        Or.elim h\n        (\n          fun hp => hp\n        )\n        (\n          fun fls => False.elim fls \n        )\n    )\n    (\n      fun h =>\n        Or.inl h\n    )\n\n  example : p \u2227 False \u2194 False :=\n    Iff.intro \n    (\n      fun h => h.right \n    )\n    (\n      fun fls =>\n        have hp := False.elim fls\n        And.intro hp fls\n    )\n\n  example : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := \n    fun hpq =>\n      fun hnq =>\n        fun hp =>\n          hnq $ hpq hp \nend\n\nsection\n  open Classical\n\n  variable (p q r : Prop)\n\n  example : (p \u2192 q \u2228 r) \u2192 ((p \u2192 q) \u2228 (p \u2192 r)) :=\n    fun hpqr : (p \u2192 q \u2228 r) =>\n      Or.elim (em q)\n      (\n        fun hq =>\n          Or.inl $ fun _ => hq\n      )\n      (\n        fun hnq =>\n          Or.inr <| \n            fun hp => \n              have hqr := hpqr hp\n              Or.elim hqr\n              (\n                fun hq => absurd hq hnq \n              )\n              (\n                fun hr => hr\n              )\n      )\n\n  example : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n    fun hnpq =>\n      Or.elim (em p) \n      (\n        fun hp =>\n          Or.elim (em q)\n          (\n            fun hq =>\n              absurd \u27e8hp, hq\u27e9 hnpq\n          )\n          (\n            fun hnq => Or.inr hnq\n          )\n      )\n      (\n        fun hnp =>\n          Or.inl hnp\n      )\n\n  example : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := \n    fun hnpq : \u00ac(p \u2192 q) =>\n      Or.elim (em p)\n      (\n        fun hp => \n          Or.elim (em q)\n          (\n            fun hq => \n              have hpq := fun _ => hq \n              absurd hpq hnpq\n          )\n          (\n            fun hnq => \n              And.intro hp hnq \n          )\n      )\n      (\n        fun hnp => \n          Or.elim (em q)\n          (\n            fun hq =>\n              have hpq := fun _ => hq\n              absurd hpq hnpq \n          )\n          (\n            fun _ => \n              have hpq := fun hp => absurd hp hnp\n              absurd hpq hnpq\n          )\n      ) \n\n\n  example : (p \u2192 q) \u2192 (\u00acp \u2228 q) := \n    fun hpq =>\n      Or.elim (em p) \n      (\n        fun hp =>\n          have hq := hpq hp \n          Or.inr hq \n      )\n      (\n        fun hnp =>\n          Or.inl hnp\n      )\n\n  example : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := \n    fun hnqnp =>\n      Or.elim (em q) \n      (\n        fun hq =>\n          have hpq := fun _ => hq \n          hpq\n      )\n      (\n        fun hnq => \n          have hnp := hnqnp hnq \n          fun hp =>\n            absurd hp hnp\n      )\n\n  example : (p \u2228 \u00acp) :=\n    em p\n  \n  example : ((p \u2192 q) \u2192 p) \u2192 p := \n    fun hpqp =>\n      Or.elim (em p) \n      (\n        fun hp : p => hp\n      )\n      (\n        fun hnp : \u00acp => \n          have hpq := \n            fun hp => absurd hp hnp\n          have hp := hpqp hpq\n          absurd hp hnp\n      )\n    \nend\n\nsection\n  variable (p : Prop)\n\n  example : \u00ac(p \u2194 \u00acp) := \n    fun h : p \u2194 \u00acp =>\n      have hnp : \u00acp := \n        fun hp : p =>\n          have hnp' := h.mp hp\n          absurd hp hnp'\n      have hp : p := h.mpr hnp\n      absurd hp hnp\n\nend\n\n", "meta": {"author": "rikitoro", "repo": "lean4_tut_exercises", "sha": "2f28bcb3caf990a02460beccfed6905b278c8d09", "save_path": "github-repos/lean/rikitoro-lean4_tut_exercises", "path": "github-repos/lean/rikitoro-lean4_tut_exercises/lean4_tut_exercises-2f28bcb3caf990a02460beccfed6905b278c8d09/sec03_ex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.7186248630157942}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.uniform_space.completion\nimport topology.metric_space.isometry\nimport topology.instances.real\n\n/-!\n# The completion of a metric space\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nCompletion of uniform spaces are already defined in `topology.uniform_space.completion`. We show\nhere that the uniform space completion of a metric space inherits a metric space structure,\nby extending the distance to the completion and checking that it is indeed a distance, and that\nit defines the same uniformity as the already defined uniform structure on the completion\n-/\n\nopen set filter uniform_space metric\nopen_locale filter topology uniformity\nnoncomputable theory\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [pseudo_metric_space \u03b1]\n\nnamespace uniform_space.completion\n\n/-- The distance on the completion is obtained by extending the distance on the original space,\nby uniform continuity. -/\ninstance : has_dist (completion \u03b1) :=\n\u27e8completion.extension\u2082 dist\u27e9\n\n/-- The new distance is uniformly continuous. -/\nprotected lemma uniform_continuous_dist :\n  uniform_continuous (\u03bbp:completion \u03b1 \u00d7 completion \u03b1, dist p.1 p.2) :=\nuniform_continuous_extension\u2082 dist\n\n/-- The new distance is continuous. -/\nprotected lemma continuous_dist [topological_space \u03b2] {f g : \u03b2 \u2192 completion \u03b1} (hf : continuous f)\n  (hg : continuous g) :\n  continuous (\u03bb x, dist (f x) (g x)) :=\ncompletion.uniform_continuous_dist.continuous.comp (hf.prod_mk hg : _)\n\n/-- The new distance is an extension of the original distance. -/\n@[simp] protected lemma dist_eq (x y : \u03b1) : dist (x : completion \u03b1) y = dist x y :=\ncompletion.extension\u2082_coe_coe uniform_continuous_dist _ _\n\n/- Let us check that the new distance satisfies the axioms of a distance, by starting from the\nproperties on \u03b1 and extending them to `completion \u03b1` by continuity. -/\nprotected lemma dist_self (x : completion \u03b1) : dist x x = 0 :=\nbegin\n  apply induction_on x,\n  { refine is_closed_eq _ continuous_const,\n    exact completion.continuous_dist continuous_id continuous_id },\n  { assume a,\n    rw [completion.dist_eq, dist_self] }\nend\n\nprotected lemma dist_comm (x y : completion \u03b1) : dist x y = dist y x :=\nbegin\n  apply induction_on\u2082 x y,\n  { exact is_closed_eq (completion.continuous_dist continuous_fst continuous_snd)\n      (completion.continuous_dist continuous_snd continuous_fst) },\n  { assume a b,\n    rw [completion.dist_eq, completion.dist_eq, dist_comm] }\nend\n\nprotected lemma dist_triangle (x y z : completion \u03b1) : dist x z \u2264 dist x y + dist y z :=\nbegin\n  apply induction_on\u2083 x y z,\n  { refine is_closed_le _ (continuous.add _ _);\n      apply_rules [completion.continuous_dist, continuous.fst, continuous.snd, continuous_id] },\n  { assume a b c,\n    rw [completion.dist_eq, completion.dist_eq, completion.dist_eq],\n    exact dist_triangle a b c }\nend\n\n/-- Elements of the uniformity (defined generally for completions) can be characterized in terms\nof the distance. -/\nprotected lemma mem_uniformity_dist (s : set (completion \u03b1 \u00d7 completion \u03b1)) :\n  s \u2208 \ud835\udce4 (completion \u03b1) \u2194 (\u2203\u03b5>0, \u2200{a b}, dist a b < \u03b5 \u2192 (a, b) \u2208 s) :=\nbegin\n  split,\n  { /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in `\u03b1` is an\n    entourage, so it contains an `\u03b5`-neighborhood of the diagonal by definition of the entourages\n    in metric spaces. Then `t` contains an `\u03b5`-neighborhood of the diagonal in `completion \u03b1`, as\n    closed properties pass to the completion. -/\n    assume hs,\n    rcases mem_uniformity_is_closed hs with \u27e8t, ht, \u27e8tclosed, ts\u27e9\u27e9,\n    have A : {x : \u03b1 \u00d7 \u03b1 | (coe (x.1), coe (x.2)) \u2208 t} \u2208 uniformity \u03b1 :=\n      uniform_continuous_def.1 (uniform_continuous_coe \u03b1) t ht,\n    rcases mem_uniformity_dist.1 A with \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9,\n    refine \u27e8\u03b5, \u03b5pos, \u03bbx y hxy, _\u27e9,\n    have : \u03b5 \u2264 dist x y \u2228 (x, y) \u2208 t,\n    { apply induction_on\u2082 x y,\n      { have : {x : completion \u03b1 \u00d7 completion \u03b1 | \u03b5 \u2264 dist (x.fst) (x.snd) \u2228 (x.fst, x.snd) \u2208 t}\n               = {p : completion \u03b1 \u00d7 completion \u03b1 | \u03b5 \u2264 dist p.1 p.2} \u222a t, by ext; simp,\n        rw this,\n        apply is_closed.union _ tclosed,\n        exact is_closed_le continuous_const completion.uniform_continuous_dist.continuous },\n      { assume x y,\n        rw completion.dist_eq,\n        by_cases h : \u03b5 \u2264 dist x y,\n        { exact or.inl h },\n        { have Z := h\u03b5 (not_le.1 h),\n          simp only [set.mem_set_of_eq] at Z,\n          exact or.inr Z }}},\n    simp only [not_le.mpr hxy, false_or, not_le] at this,\n    exact ts this },\n  { /- Start from a set `s` containing an \u03b5-neighborhood of the diagonal in `completion \u03b1`. To show\n    that it is an entourage, we use the fact that `dist` is uniformly continuous on\n    `completion \u03b1 \u00d7 completion \u03b1` (this is a general property of the extension of uniformly\n    continuous functions). Therefore, the preimage of the \u03b5-neighborhood of the diagonal in \u211d\n    is an entourage in `completion \u03b1 \u00d7 completion \u03b1`. Massaging this property, it follows that\n    the \u03b5-neighborhood of the diagonal is an entourage in `completion \u03b1`, and therefore this is\n    also the case of `s`. -/\n    rintros \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9,\n    let r : set (\u211d \u00d7 \u211d) := {p | dist p.1 p.2 < \u03b5},\n    have : r \u2208 uniformity \u211d := metric.dist_mem_uniformity \u03b5pos,\n    have T := uniform_continuous_def.1 (@completion.uniform_continuous_dist \u03b1 _) r this,\n    simp only [uniformity_prod_eq_prod, mem_prod_iff, exists_prop,\n               filter.mem_map, set.mem_set_of_eq] at T,\n    rcases T with \u27e8t1, ht1, t2, ht2, ht\u27e9,\n    refine mem_of_superset ht1 _,\n    have A : \u2200a b : completion \u03b1, (a, b) \u2208 t1 \u2192 dist a b < \u03b5,\n    { assume a b hab,\n      have : ((a, b), (a, a)) \u2208 t1 \u00d7\u02e2 t2 := \u27e8hab, refl_mem_uniformity ht2\u27e9,\n      have I := ht this,\n      simp [completion.dist_self, real.dist_eq, completion.dist_comm] at I,\n      exact lt_of_le_of_lt (le_abs_self _) I },\n    show t1 \u2286 s,\n    { rintros \u27e8a, b\u27e9 hp,\n      have : dist a b < \u03b5 := A a b hp,\n      exact h\u03b5 this }}\nend\n\n/-- If two points are at distance 0, then they coincide. -/\nprotected lemma eq_of_dist_eq_zero (x y : completion \u03b1) (h : dist x y = 0) : x = y :=\nbegin\n  /- This follows from the separation of `completion \u03b1` and from the description of\n  entourages in terms of the distance. -/\n  have : separated_space (completion \u03b1) := by apply_instance,\n  refine separated_def.1 this x y (\u03bbs hs, _),\n  rcases (completion.mem_uniformity_dist s).1 hs with \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9,\n  rw \u2190 h at \u03b5pos,\n  exact h\u03b5 \u03b5pos\nend\n\n/-- Reformulate `completion.mem_uniformity_dist` in terms that are suitable for the definition\nof the metric space structure. -/\nprotected lemma uniformity_dist' :\n  \ud835\udce4 (completion \u03b1) = (\u2a05\u03b5:{\u03b5 : \u211d // 0 < \u03b5}, \ud835\udcdf {p | dist p.1 p.2 < \u03b5.val}) :=\nbegin\n  ext s, rw mem_infi_of_directed,\n  { simp [completion.mem_uniformity_dist, subset_def] },\n  { rintro \u27e8r, hr\u27e9 \u27e8p, hp\u27e9, use \u27e8min r p, lt_min hr hp\u27e9,\n    simp [lt_min_iff, (\u2265)] {contextual := tt} }\nend\n\nprotected lemma uniformity_dist :\n  \ud835\udce4 (completion \u03b1) = (\u2a05 \u03b5>0, \ud835\udcdf {p | dist p.1 p.2 < \u03b5}) :=\nby simpa [infi_subtype] using @completion.uniformity_dist' \u03b1 _\n\n/-- Metric space structure on the completion of a pseudo_metric space. -/\ninstance : metric_space (completion \u03b1) :=\n{ dist_self          := completion.dist_self,\n  eq_of_dist_eq_zero := completion.eq_of_dist_eq_zero,\n  dist_comm          := completion.dist_comm,\n  dist_triangle      := completion.dist_triangle,\n  dist               := dist,\n  to_uniform_space   := by apply_instance,\n  uniformity_dist    := completion.uniformity_dist }\n\n/-- The embedding of a metric space in its completion is an isometry. -/\nlemma coe_isometry : isometry (coe : \u03b1 \u2192 completion \u03b1) :=\nisometry.of_dist_eq completion.dist_eq\n\n@[simp] protected lemma edist_eq (x y : \u03b1) : edist (x : completion \u03b1) y = edist x y :=\ncoe_isometry x y\n\nend uniform_space.completion\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/metric_space/completion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.7186248474487618}}
{"text": "/-\nCopyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Kontorovich, Heather Macbeth, Marc Masdeu\n-/\n\nimport linear_algebra.special_linear_group\nimport analysis.complex.basic\nimport group_theory.group_action.defs\n\n/-!\n# The upper half plane and its automorphisms\n\nThis file defines `upper_half_plane` to be the upper half plane in `\u2102`.\n\nWe furthermore equip it with the structure of an `SL(2,\u211d)` action by\nfractional linear transformations.\n\nWe define the notation `\u210d` for the upper half plane available in the locale\n`upper_half_plane` so as not to conflict with the quaternions.\n-/\n\nnoncomputable theory\n\nopen matrix matrix.special_linear_group\n\nopen_locale classical big_operators matrix_groups\n\nlocal attribute [instance] fintype.card_fin_even\n\n/- Disable this instances as it is not the simp-normal form, and having them disabled ensures\nwe state lemmas in this file without spurious `coe_fn` terms. -/\nlocal attribute [-instance] matrix.special_linear_group.has_coe_to_fun\n\nlocal prefix `\u2191\u2098`:1024 := @coe _ (matrix (fin 2) (fin 2) _) _\n\n/-- The open upper half plane -/\n@[derive [topological_space, \u03bb \u03b1, has_coe \u03b1 \u2102]]\ndef upper_half_plane := {point : \u2102 // 0 < point.im}\n\nlocalized \"notation `\u210d` := upper_half_plane\" in upper_half_plane\n\nnamespace upper_half_plane\n\ninstance : inhabited \u210d := \u27e8\u27e8complex.I, by simp\u27e9\u27e9\n\n/-- Imaginary part -/\ndef im (z : \u210d) := (z : \u2102).im\n\n/-- Real part -/\ndef re (z : \u210d) := (z : \u2102).re\n\n@[simp] lemma coe_im (z : \u210d) : (z : \u2102).im = z.im := rfl\n\n@[simp] lemma coe_re (z : \u210d) : (z : \u2102).re = z.re := rfl\n\nlemma im_pos (z : \u210d) : 0 < z.im := z.2\n\nlemma im_ne_zero (z : \u210d) : z.im \u2260 0 := z.im_pos.ne'\n\nlemma ne_zero (z : \u210d) : (z : \u2102) \u2260 0 :=\nmt (congr_arg complex.im) z.im_ne_zero\n\nlemma norm_sq_pos (z : \u210d) : 0 < complex.norm_sq (z : \u2102) :=\nby { rw complex.norm_sq_pos, exact z.ne_zero }\n\nlemma norm_sq_ne_zero (z : \u210d) : complex.norm_sq (z : \u2102) \u2260 0 := (norm_sq_pos z).ne'\n\n/-- Numerator of the formula for a fractional linear transformation -/\n@[simp] def num (g : SL(2, \u211d)) (z : \u210d) : \u2102 := (\u2191\u2098g 0 0 : \u211d) * z + (\u2191\u2098g 0 1 : \u211d)\n\n/-- Denominator of the formula for a fractional linear transformation -/\n@[simp] def denom (g : SL(2, \u211d)) (z : \u210d) : \u2102 := (\u2191\u2098g 1 0 : \u211d) * z + (\u2191\u2098g 1 1 : \u211d)\n\nlemma linear_ne_zero (cd : fin 2 \u2192 \u211d) (z : \u210d) (h : cd \u2260 0) : (cd 0 : \u2102) * z + cd 1 \u2260 0 :=\nbegin\n  contrapose! h,\n  have : cd 0 = 0, -- we will need this twice\n  { apply_fun complex.im at h,\n    simpa only [z.im_ne_zero, complex.add_im, add_zero, coe_im, zero_mul, or_false,\n      complex.of_real_im, complex.zero_im, complex.mul_im, mul_eq_zero] using h, },\n  simp only [this, zero_mul, complex.of_real_zero, zero_add, complex.of_real_eq_zero] at h,\n  ext i,\n  fin_cases i; assumption,\nend\n\nlemma denom_ne_zero (g : SL(2, \u211d)) (z : \u210d) : denom g z \u2260 0 :=\nlinear_ne_zero (\u2191\u2098g 1) z (g.row_ne_zero 1)\n\nlemma norm_sq_denom_pos (g : SL(2, \u211d)) (z : \u210d) : 0 < complex.norm_sq (denom g z) :=\ncomplex.norm_sq_pos.mpr (denom_ne_zero g z)\n\nlemma norm_sq_denom_ne_zero (g : SL(2, \u211d)) (z : \u210d) : complex.norm_sq (denom g z) \u2260 0 :=\nne_of_gt (norm_sq_denom_pos g z)\n\n/-- Fractional linear transformation -/\ndef smul_aux' (g : SL(2, \u211d)) (z : \u210d) : \u2102 := num g z / denom g z\n\nlemma smul_aux'_im (g : SL(2, \u211d)) (z : \u210d) :\n  (smul_aux' g z).im = z.im / (denom g z).norm_sq :=\nbegin\n  rw [smul_aux', complex.div_im],\n  set NsqBot := (denom g z).norm_sq,\n  have : NsqBot \u2260 0,\n  { simp only [denom_ne_zero g z, monoid_with_zero_hom.map_eq_zero, ne.def, not_false_iff], },\n  field_simp [smul_aux'],\n  convert congr_arg (\u03bb x, x * z.im * NsqBot ^ 2) g.det_coe using 1,\n  { rw det_fin_two \u2191g,\n    ring },\n  { ring }\nend\n\n/-- Fractional linear transformation -/\ndef smul_aux (g : SL(2,\u211d)) (z : \u210d) : \u210d :=\n\u27e8smul_aux' g z,\nby { rw smul_aux'_im, exact div_pos z.im_pos (complex.norm_sq_pos.mpr (denom_ne_zero g z)) }\u27e9\n\nlemma denom_cocycle (x y : SL(2,\u211d)) (z : \u210d) :\n  denom (x * y) z = denom x (smul_aux y z) * denom y z :=\nbegin\n  change _ = (_ * (_ / _) + _) * _,\n  field_simp [denom_ne_zero, -denom, -num],\n  simp [matrix.mul, dot_product, fin.sum_univ_succ],\n  ring\nend\n\nlemma mul_smul' (x y : SL(2, \u211d)) (z : \u210d) :\n  smul_aux (x * y) z = smul_aux x (smul_aux y z) :=\nbegin\n  ext1,\n  change _ / _ = (_ * (_ / _) + _)  * _,\n  rw denom_cocycle,\n  field_simp [denom_ne_zero, -denom, -num],\n  simp [matrix.mul, dot_product, fin.sum_univ_succ],\n  ring\nend\n\n/-- The action of `SL(2, \u211d)` on the upper half-plane by fractional linear transformations. -/\ninstance : mul_action SL(2, \u211d) \u210d :=\n{ smul := smul_aux,\n  one_smul := \u03bb z, by { ext1, change _ / _ = _, simp },\n  mul_smul := mul_smul' }\n\n@[simp] lemma coe_smul (g : SL(2, \u211d)) (z : \u210d) : \u2191(g \u2022 z) = num g z / denom g z := rfl\n@[simp] lemma re_smul (g : SL(2, \u211d)) (z : \u210d) : (g \u2022 z).re = (num g z / denom g z).re := rfl\n\nlemma im_smul (g : SL(2, \u211d)) (z : \u210d) : (g \u2022 z).im = (num g z / denom g z).im := rfl\n\nlemma im_smul_eq_div_norm_sq (g : SL(2, \u211d)) (z : \u210d) :\n  (g \u2022 z).im = z.im / (complex.norm_sq (denom g z)) :=\nsmul_aux'_im g z\n\n@[simp] lemma neg_smul (g : SL(2,\u211d)) (z : \u210d) : -g \u2022 z = g \u2022 z :=\nbegin\n  ext1,\n  change _ / _ = _ / _,\n  field_simp [denom_ne_zero, -denom, -num],\n  simp,\n  ring,\nend\n\nend upper_half_plane\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/complex/upper_half_plane.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.718606651273909}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.metric_space.basic\nimport measure_theory.constructions.borel_space\nimport measure_theory.covering.vitali_family\n\n/-!\n# Vitali covering theorems\n\nThe topological Vitali covering theorem, in its most classical version, states the following.\nConsider a family of balls `(B (x_i, r_i))_{i \u2208 I}` in a metric space, with uniformly bounded\nradii. Then one can extract a disjoint subfamily indexed by `J \u2286 I`, such that any `B (x_i, r_i)`\nis included in a ball `B (x_j, 5 r_j)`.\n\nWe prove this theorem in `vitali.exists_disjoint_subfamily_covering_enlargment_closed_ball`.\nIt is deduced from a more general version, called\n`vitali.exists_disjoint_subfamily_covering_enlargment`, which applies to any family of sets\ntogether with a size function `\u03b4` (think \"radius\" or \"diameter\").\n\nWe deduce the measurable Vitali covering theorem. Assume one is given a family `t` of closed sets\nwith nonempty interior, such that each `a \u2208 t` is included in a ball `B (x, r)` and covers a\ndefinite proportion of the ball `B (x, 6 r)` for a given measure `\u03bc` (think of the situation\nwhere `\u03bc` is a doubling measure and `t` is a family of balls). Consider a set `s` at which the\nfamily is fine, i.e., every point of `s` belongs to arbitrarily small elements of `t`. Then one\ncan extract from `t` a disjoint subfamily that covers almost all `s`. It is proved in\n`vitali.exists_disjoint_covering_ae`.\n\nA way to restate this theorem is to say that the set of closed sets `a` with nonempty interior\ncovering a fixed proportion `1/C` of the ball `closed_ball x (3 * diam a)` forms a Vitali family.\nThis version is given in `vitali.vitali_family`.\n-/\n\nvariables {\u03b1 \u03b9 : Type*}\n\nopen set metric measure_theory topological_space filter\nopen_locale nnreal classical ennreal topology\n\nnamespace vitali\n\n/-- Vitali covering theorem: given a set `t` of subsets of a type, one may extract a disjoint\nsubfamily `u` such that the `\u03c4`-enlargment of this family covers all elements of `t`, where `\u03c4 > 1`\nis any fixed number.\n\nWhen `t` is a family of balls, the `\u03c4`-enlargment of `ball x r` is `ball x ((1+2\u03c4) r)`. In general,\nit is expressed in terms of a function `\u03b4` (think \"radius\" or \"diameter\"), positive and bounded on\nall elements of `t`. The condition is that every element `a` of `t` should intersect an\nelement `b` of `u` of size larger than that of `a` up to `\u03c4`, i.e., `\u03b4 b \u2265 \u03b4 a / \u03c4`.\n\nWe state the lemma slightly more generally, with an indexed family of sets `B a` for `a \u2208 t`, for\nwider applicability.\n-/\ntheorem exists_disjoint_subfamily_covering_enlargment\n  (B : \u03b9 \u2192 set \u03b1) (t : set \u03b9) (\u03b4 : \u03b9 \u2192 \u211d) (\u03c4 : \u211d) (h\u03c4 : 1 < \u03c4) (\u03b4nonneg : \u2200 a \u2208 t, 0 \u2264 \u03b4 a)\n  (R : \u211d) (\u03b4le : \u2200 a \u2208 t, \u03b4 a \u2264 R) (hne : \u2200 a \u2208 t, (B a).nonempty) :\n  \u2203 u \u2286 t, u.pairwise_disjoint B \u2227\n    \u2200 a \u2208 t, \u2203 b \u2208 u, (B a \u2229 B b).nonempty \u2227 \u03b4 a \u2264 \u03c4 * \u03b4 b :=\nbegin\n  /- The proof could be formulated as a transfinite induction. First pick an element of `t` with `\u03b4`\n  as large as possible (up to a factor of `\u03c4`). Then among the remaining elements not intersecting\n  the already chosen one, pick another element with large `\u03b4`. Go on forever (transfinitely) until\n  there is nothing left.\n\n  Instead, we give a direct Zorn-based argument. Consider a maximal family `u` of disjoint sets\n  with the following property: if an element `a` of `t` intersects some element `b` of `u`, then it\n  intersects some `b' \u2208 u` with `\u03b4 b' \u2265 \u03b4 a / \u03c4`. Such a maximal family exists by Zorn. If this\n  family did not intersect some element `a \u2208 t`, then take an element `a' \u2208 t` which does not\n  intersect any element of `u`, with `\u03b4 a'` almost as large as possible. One checks easily\n  that `u \u222a {a'}` still has this property, contradicting the maximality. Therefore, `u`\n  intersects all elements of `t`, and by definition it satisfies all the desired properties.\n  -/\n  let T : set (set \u03b9) := {u | u \u2286 t \u2227 u.pairwise_disjoint B\n    \u2227 \u2200 a \u2208 t, \u2200 b \u2208 u, (B a \u2229 B b).nonempty \u2192 \u2203 c \u2208 u, (B a \u2229 B c).nonempty \u2227 \u03b4 a \u2264 \u03c4 * \u03b4 c},\n  -- By Zorn, choose a maximal family in the good set `T` of disjoint families.\n  obtain \u27e8u, uT, hu\u27e9 : \u2203 u \u2208 T, \u2200 v \u2208 T, u \u2286 v \u2192 v = u,\n  { refine zorn_subset _ (\u03bb U UT hU, _),\n    refine \u27e8\u22c3\u2080 U, _, \u03bb s hs, subset_sUnion_of_mem hs\u27e9,\n    simp only [set.sUnion_subset_iff, and_imp, exists_prop, forall_exists_index, mem_sUnion,\n                set.mem_set_of_eq],\n    refine \u27e8\u03bb u hu, (UT hu).1, (pairwise_disjoint_sUnion hU.directed_on).2 (\u03bb u hu, (UT hu).2.1),\n      \u03bb a hat b u uU hbu hab, _\u27e9,\n    obtain \u27e8c, cu, ac, hc\u27e9 : \u2203 (c : \u03b9) (H : c \u2208 u), (B a \u2229 B c).nonempty \u2227 \u03b4 a \u2264 \u03c4 * \u03b4 c :=\n      (UT uU).2.2 a hat b hbu hab,\n    exact \u27e8c, \u27e8u, uU, cu\u27e9, ac, hc\u27e9 },\n  -- the only nontrivial bit is to check that every `a \u2208 t` intersects an element `b \u2208 u` with\n  -- comparatively large `\u03b4 b`. Assume this is not the case, then we will contradict the maximality.\n  refine \u27e8u, uT.1, uT.2.1, \u03bb a hat, _\u27e9,\n  contrapose! hu,\n  have a_disj : \u2200 c \u2208 u, disjoint (B a) (B c),\n  { assume c hc,\n    by_contra,\n    rw not_disjoint_iff_nonempty_inter at h,\n    obtain \u27e8d, du, ad, hd\u27e9 : \u2203 (d : \u03b9) (H : d \u2208 u), (B a \u2229 B d).nonempty \u2227 \u03b4 a \u2264 \u03c4 * \u03b4 d :=\n      uT.2.2 a hat c hc h,\n    exact lt_irrefl _ ((hu d du ad).trans_le hd) },\n  -- Let `A` be all the elements of `t` which do not intersect the family `u`. It is nonempty as it\n  -- contains `a`. We will pick an element `a'` of `A` with `\u03b4 a'` almost as large as possible.\n  let A := {a' | a' \u2208 t \u2227 \u2200 c \u2208 u, disjoint (B a') (B c)},\n  have Anonempty : A.nonempty := \u27e8a, hat, a_disj\u27e9,\n  let m := Sup (\u03b4 '' A),\n  have bddA : bdd_above (\u03b4 '' A),\n  { refine \u27e8R, \u03bb x xA, _\u27e9,\n    rcases (mem_image _ _ _).1 xA with \u27e8a', ha', rfl\u27e9,\n    exact \u03b4le a' ha'.1 },\n  obtain \u27e8a', a'A, ha'\u27e9 : \u2203 a' \u2208 A, m / \u03c4 \u2264 \u03b4 a',\n  { have : 0 \u2264 m := (\u03b4nonneg a hat).trans (le_cSup bddA (mem_image_of_mem _ \u27e8hat, a_disj\u27e9)),\n    rcases eq_or_lt_of_le this with mzero|mpos,\n    { refine \u27e8a, \u27e8hat, a_disj\u27e9, _\u27e9,\n      simpa only [\u2190 mzero, zero_div] using \u03b4nonneg a hat },\n    { have I : m / \u03c4 < m,\n      { rw div_lt_iff (zero_lt_one.trans h\u03c4),\n        conv_lhs { rw \u2190 mul_one m },\n        exact (mul_lt_mul_left mpos).2 h\u03c4 },\n      rcases exists_lt_of_lt_cSup (nonempty_image_iff.2 Anonempty) I with \u27e8x, xA, hx\u27e9,\n      rcases (mem_image _ _ _).1 xA with \u27e8a', ha', rfl\u27e9,\n      exact \u27e8a', ha', hx.le\u27e9, } },\n  clear hat hu a_disj a,\n  have a'_ne_u : a' \u2209 u := \u03bb H, (hne _ a'A.1).ne_empty (disjoint_self.1 (a'A.2 _ H)),\n  -- we claim that `u \u222a {a'}` still belongs to `T`, contradicting the maximality of `u`.\n  refine \u27e8insert a' u, \u27e8_, _, _\u27e9, subset_insert _ _, (ne_insert_of_not_mem _ a'_ne_u).symm\u27e9,\n  -- check that `u \u222a {a'}` is made of elements of `t`.\n  { rw insert_subset,\n    exact \u27e8a'A.1, uT.1\u27e9 },\n  -- check that `u \u222a {a'}` is a disjoint family. This follows from the fact that `a'` does not\n  -- intersect `u`.\n  { exact uT.2.1.insert (\u03bb b bu ba', a'A.2 b bu) },\n  -- check that every element `c` of `t` intersecting `u \u222a {a'}` intersects an element of this\n  -- family with large `\u03b4`.\n  { assume c ct b ba'u hcb,\n    -- if `c` already intersects an element of `u`, then it intersects an element of `u` with\n    -- large `\u03b4` by the assumption on `u`, and there is nothing left to do.\n    by_cases H : \u2203 d \u2208 u, (B c \u2229 B d).nonempty,\n    { rcases H with \u27e8d, du, hd\u27e9,\n      rcases uT.2.2 c ct d du hd with \u27e8d', d'u, hd'\u27e9,\n      exact \u27e8d', mem_insert_of_mem _ d'u, hd'\u27e9 },\n    -- otherwise, `c` belongs to `A`. The element of `u \u222a {a'}` that it intersects has to be `a'`.\n    -- moreover, `\u03b4 c` is smaller than the maximum `m` of `\u03b4` over `A`, which is `\u2264 \u03b4 a' / \u03c4`\n    -- thanks to the good choice of `a'`. This is the desired inequality.\n    { push_neg at H,\n      simp only [\u2190 not_disjoint_iff_nonempty_inter, not_not] at H,\n      rcases mem_insert_iff.1 ba'u with rfl|H',\n      { refine \u27e8b, mem_insert _ _, hcb, _\u27e9,\n        calc \u03b4 c \u2264 m : le_cSup bddA (mem_image_of_mem _ \u27e8ct, H\u27e9)\n        ... = \u03c4 * (m / \u03c4) : by { field_simp [(zero_lt_one.trans h\u03c4).ne'], ring }\n        ... \u2264 \u03c4 * \u03b4 b : mul_le_mul_of_nonneg_left ha' (zero_le_one.trans h\u03c4.le) },\n      { rw \u2190 not_disjoint_iff_nonempty_inter at hcb,\n        exact (hcb (H _ H')).elim } } }\nend\n\n/-- Vitali covering theorem, closed balls version: given a family `t` of closed balls, one can\nextract a disjoint subfamily `u \u2286 t` so that all balls in `t` are covered by the 5-times\ndilations of balls in `u`. -/\ntheorem exists_disjoint_subfamily_covering_enlargment_closed_ball [metric_space \u03b1]\n  (t : set \u03b9) (x : \u03b9 \u2192 \u03b1) (r : \u03b9 \u2192 \u211d) (R : \u211d) (hr : \u2200 a \u2208 t, r a \u2264 R) :\n  \u2203 u \u2286 t, u.pairwise_disjoint (\u03bb a, closed_ball (x a) (r a)) \u2227\n    \u2200 a \u2208 t, \u2203 b \u2208 u, closed_ball (x a) (r a) \u2286 closed_ball (x b) (5 * r b) :=\nbegin\n  rcases eq_empty_or_nonempty t with rfl|tnonempty,\n  { exact \u27e8\u2205, subset.refl _, pairwise_disjoint_empty, by simp\u27e9 },\n  by_cases ht : \u2200 a \u2208 t, r a < 0,\n  { exact \u27e8t, subset.rfl, \u03bb a ha b hb hab,\n      by simp only [function.on_fun, closed_ball_eq_empty.2 (ht a ha), empty_disjoint],\n      \u03bb a ha, \u27e8a, ha, by simp only [closed_ball_eq_empty.2 (ht a ha), empty_subset]\u27e9\u27e9 },\n  push_neg at ht,\n  let t' := {a \u2208 t | 0 \u2264 r a},\n  rcases exists_disjoint_subfamily_covering_enlargment (\u03bb a, closed_ball (x a) (r a)) t' r\n    2 one_lt_two (\u03bb a ha, ha.2) R (\u03bb a ha, hr a ha.1) (\u03bb a ha, \u27e8x a, mem_closed_ball_self ha.2\u27e9)\n    with \u27e8u, ut', u_disj, hu\u27e9,\n  have A : \u2200 a \u2208 t', \u2203 b \u2208 u, closed_ball (x a) (r a) \u2286 closed_ball (x b) (5 * r b),\n  { assume a ha,\n    rcases hu a ha with \u27e8b, bu, hb, rb\u27e9,\n    refine \u27e8b, bu, _\u27e9,\n    have : dist (x a) (x b) \u2264 r a + r b :=\n      dist_le_add_of_nonempty_closed_ball_inter_closed_ball hb,\n    apply closed_ball_subset_closed_ball',\n    linarith },\n  refine \u27e8u, ut'.trans (\u03bb a ha, ha.1), u_disj, \u03bb a ha, _\u27e9,\n  rcases le_or_lt 0 (r a) with h'a|h'a,\n  { exact A a \u27e8ha, h'a\u27e9 },\n  { rcases ht with \u27e8b, rb\u27e9,\n    rcases A b \u27e8rb.1, rb.2\u27e9 with \u27e8c, cu, hc\u27e9,\n    refine \u27e8c, cu, by simp only [closed_ball_eq_empty.2 h'a, empty_subset]\u27e9 },\nend\n\n\n/-- The measurable Vitali covering theorem. Assume one is given a family `t` of closed sets with\nnonempty interior, such that each `a \u2208 t` is included in a ball `B (x, r)` and covers a definite\nproportion of the ball `B (x, 3 r)` for a given measure `\u03bc` (think of the situation where `\u03bc` is\na doubling measure and `t` is a family of balls). Consider a (possibly non-measurable) set `s`\nat which the family is fine, i.e., every point of `s` belongs to arbitrarily small elements of `t`.\nThen one can extract from `t` a disjoint subfamily that covers almost all `s`.\n\nFor more flexibility, we give a statement with a parameterized family of sets.\n-/\ntheorem exists_disjoint_covering_ae [metric_space \u03b1] [measurable_space \u03b1] [opens_measurable_space \u03b1]\n  [second_countable_topology \u03b1]\n  (\u03bc : measure \u03b1) [is_locally_finite_measure \u03bc] (s : set \u03b1)\n  (t : set \u03b9) (C : \u211d\u22650) (r : \u03b9 \u2192 \u211d) (c : \u03b9 \u2192 \u03b1) (B : \u03b9 \u2192 set \u03b1)\n  (hB : \u2200 a \u2208 t, B a \u2286 closed_ball (c a) (r a))\n  (\u03bcB : \u2200 a \u2208 t, \u03bc (closed_ball (c a) (3 * r a)) \u2264 C * \u03bc (B a))\n  (ht : \u2200 a \u2208 t, (interior (B a)).nonempty) (h't : \u2200 a \u2208 t, is_closed (B a))\n  (hf : \u2200 x \u2208 s, \u2200 (\u03b5 > (0 : \u211d)), \u2203 a \u2208 t, r a \u2264 \u03b5 \u2227 c a = x) :\n  \u2203 u \u2286 t, u.countable \u2227 u.pairwise_disjoint B \u2227 \u03bc (s \\ \u22c3 a \u2208 u, B a) = 0 :=\nbegin\n  /- The idea of the proof is the following. Assume for simplicity that `\u03bc` is finite. Applying the\n  abstract Vitali covering theorem with `\u03b4 = r` given by `hf`, one obtains a disjoint subfamily `u`,\n  such that any element of `t` intersects an element of `u` with comparable radius. Fix `\u03b5 > 0`.\n  Since the elements of `u` have summable measure, one can remove finitely elements `w_1, ..., w_n`.\n  so that the measure of the remaining elements is `< \u03b5`. Consider now a point `z` not\n  in the `w_i`. There is a small ball around `z` not intersecting the `w_i` (as they are closed),\n  an element `a \u2208 t` contained in this small ball (as the family `t` is fine at `z`) and an element\n  `b \u2208 u` intersecting `a`, with comparable radius (by definition of `u`). Then `z` belongs to the\n  enlargement of `b`. This shows that `s \\ (w_1 \u222a ... \u222a w_n)` is contained in\n  `\u22c3 (b \u2208 u \\ {w_1, ... w_n}) (enlargement of b)`. The measure of the latter set is bounded by\n  `\u2211 (b \u2208 u \\ {w_1, ... w_n}) C * \u03bc b` (by the doubling property of the measure), which is at most\n  `C \u03b5`. Letting `\u03b5` tend to `0` shows that `s` is almost everywhere covered by the family `u`.\n\n  For the real argument, the measure is only locally finite. Therefore, we implement the same\n  strategy, but locally restricted to balls on which the measure is finite. For this, we do not\n  use the whole family `t`, but a subfamily `t'` supported on small balls (which is possible since\n  the family is assumed to be fine at every point of `s`).\n  -/\n  -- choose around each `x` a small ball on which the measure is finite\n  have : \u2200 x, \u2203 R, 0 < R \u2227 R \u2264 1 \u2227 \u03bc (closed_ball x (20 * R)) < \u221e,\n  { assume x,\n    obtain \u27e8R, Rpos, \u03bcR\u27e9 : \u2203 (R : \u211d) (hR : 0 < R), \u03bc (closed_ball x R) < \u221e :=\n      (\u03bc.finite_at_nhds x).exists_mem_basis nhds_basis_closed_ball,\n    refine \u27e8min 1 (R/20), _, min_le_left _ _, _\u27e9,\n    { simp only [true_and, lt_min_iff, zero_lt_one],\n      linarith },\n    { apply lt_of_le_of_lt (measure_mono _) \u03bcR,\n      apply closed_ball_subset_closed_ball,\n      calc 20 * min 1 (R / 20) \u2264 20 * (R/20) :\n        mul_le_mul_of_nonneg_left (min_le_right _ _) (by norm_num)\n      ... = R : by ring } },\n  choose R hR0 hR1 hR\u03bc,\n  -- we restrict to a subfamily `t'` of `t`, made of elements small enough to ensure that\n  -- they only see a finite part of the measure, and with a doubling property\n  let t' := {a \u2208 t | r a \u2264 R (c a)},\n  -- extract a disjoint subfamily `u` of `t'` thanks to the abstract Vitali covering theorem.\n  obtain \u27e8u, ut', u_disj, hu\u27e9 : \u2203 u \u2286 t', u.pairwise_disjoint B \u2227\n    \u2200 a \u2208 t', \u2203 b \u2208 u, (B a \u2229 B b).nonempty \u2227 r a \u2264 2 * r b,\n  { have A : \u2200 a \u2208 t', r a \u2264 1,\n    { assume a ha,\n      apply ha.2.trans (hR1 (c a)), },\n    have A' : \u2200 a \u2208 t', (B a).nonempty :=\n      \u03bb a hat', set.nonempty.mono interior_subset (ht a hat'.1),\n    refine exists_disjoint_subfamily_covering_enlargment B t' r 2 one_lt_two\n      (\u03bb a ha, _) 1 A A',\n    exact nonempty_closed_ball.1 ((A' a ha).mono (hB a ha.1)) },\n  have ut : u \u2286 t := \u03bb a hau, (ut' hau).1,\n  -- As the space is second countable, the family is countable since all its sets have nonempty\n  -- interior.\n  have u_count : u.countable := u_disj.countable_of_nonempty_interior (\u03bb a ha, ht a (ut ha)),\n  -- the family `u` will be the desired family\n  refine \u27e8u, \u03bb a hat', (ut' hat').1, u_count, u_disj, _\u27e9,\n  -- it suffices to show that it covers almost all `s` locally around each point `x`.\n  refine null_of_locally_null _ (\u03bb x hx, _),\n  -- let `v` be the subfamily of `u` made of those sets intersecting the small ball `ball x (r x)`\n  let v := {a \u2208 u | (B a \u2229 ball x (R x)).nonempty },\n  have vu : v \u2286 u := \u03bb a ha, ha.1,\n  -- they are all contained in a fixed ball of finite measure, thanks to our choice of `t'`\n  obtain \u27e8K, \u03bcK, hK\u27e9 : \u2203 K, \u03bc (closed_ball x K) < \u221e \u2227\n                          \u2200 a \u2208 u, (B a \u2229 ball x (R x)).nonempty \u2192 B a \u2286 closed_ball x K,\n  { have Idist_v : \u2200 a \u2208 v, dist (c a) x \u2264 r a + R x,\n    { assume a hav,\n      apply dist_le_add_of_nonempty_closed_ball_inter_closed_ball,\n      refine hav.2.mono _,\n      apply inter_subset_inter _ ball_subset_closed_ball,\n      exact hB a (ut (vu hav)) },\n    set R0 := Sup (r '' v) with R0_def,\n    have R0_bdd : bdd_above (r '' v),\n    { refine \u27e81, \u03bb r' hr', _\u27e9,\n      rcases (mem_image _ _ _).1 hr' with \u27e8b, hb, rfl\u27e9,\n      exact le_trans (ut' (vu hb)).2 (hR1 (c b)) },\n    rcases le_total R0 (R x) with H|H,\n    { refine \u27e820 * R x, hR\u03bc x, \u03bb a au hax, _\u27e9,\n      refine (hB a (ut au)).trans _,\n      apply closed_ball_subset_closed_ball',\n      have : r a \u2264 R0 := le_cSup R0_bdd (mem_image_of_mem _ \u27e8au, hax\u27e9),\n      linarith [Idist_v a \u27e8au, hax\u27e9, hR0 x] },\n    { have R0pos : 0 < R0 := (hR0 x).trans_le H,\n      have vnonempty : v.nonempty,\n      { by_contra,\n        rw [nonempty_iff_ne_empty, not_not] at h,\n        simp only [h, real.Sup_empty, image_empty] at R0_def,\n        exact lt_irrefl _ (R0pos.trans_le (le_of_eq R0_def)) },\n      obtain \u27e8a, hav, R0a\u27e9 : \u2203 a \u2208 v, R0/2 < r a,\n      { obtain \u27e8r', r'mem, hr'\u27e9 : \u2203 r' \u2208 r '' v, R0 / 2 < r' :=\n          exists_lt_of_lt_cSup (nonempty_image_iff.2 vnonempty) (half_lt_self R0pos),\n        rcases (mem_image _ _ _).1 r'mem with \u27e8a, hav, rfl\u27e9,\n        exact \u27e8a, hav, hr'\u27e9 },\n      refine \u27e88 * R0, _, _\u27e9,\n      { apply lt_of_le_of_lt (measure_mono _) (hR\u03bc (c a)),\n        apply closed_ball_subset_closed_ball',\n        rw dist_comm,\n        linarith [Idist_v a hav, (ut' (vu hav)).2] },\n      { assume b bu hbx,\n        refine (hB b (ut bu)).trans _,\n        apply closed_ball_subset_closed_ball',\n        have : r b \u2264 R0 := le_cSup R0_bdd (mem_image_of_mem _ \u27e8bu, hbx\u27e9),\n        linarith [Idist_v b \u27e8bu, hbx\u27e9] } } },\n  -- we will show that, in `ball x (R x)`, almost all `s` is covered by the family `u`.\n  refine \u27e8_ \u2229 ball x (R x), inter_mem_nhds_within _ (ball_mem_nhds _ (hR0 _)),\n    nonpos_iff_eq_zero.mp (le_of_forall_le_of_dense (\u03bb \u03b5 \u03b5pos, _))\u27e9,\n  -- the elements of `v` are disjoint and all contained in a finite volume ball, hence the sum\n  -- of their measures is finite.\n  have I : \u2211' (a : v), \u03bc (B a) < \u221e,\n  { calc \u2211' (a : v), \u03bc (B a) = \u03bc (\u22c3 (a \u2208 v), B a) : begin\n      rw measure_bUnion (u_count.mono vu) _ (\u03bb a ha, (h't _ (vu.trans ut ha)).measurable_set),\n      exact u_disj.subset vu\n    end\n    ... \u2264 \u03bc (closed_ball x K) : measure_mono (Union\u2082_subset (\u03bb a ha, hK a (vu ha) ha.2))\n    ... < \u221e : \u03bcK },\n  -- we can obtain a finite subfamily of `v`, such that the measures of the remaining elements\n  -- add up to an arbitrarily small number, say `\u03b5 / C`.\n  obtain \u27e8w, hw\u27e9 : \u2203 (w : finset \u21a5v), \u2211' (a : {a // a \u2209 w}), \u03bc (B a) < \u03b5 / C,\n  { have : 0 < \u03b5 / C, by simp only [ennreal.div_pos_iff, \u03b5pos.ne', ennreal.coe_ne_top, ne.def,\n                                    not_false_iff, and_self],\n    exact ((tendsto_order.1 (ennreal.tendsto_tsum_compl_at_top_zero I.ne)).2 _ this).exists },\n  -- main property: the points `z` of `s` which are not covered by `u` are contained in the\n  -- enlargements of the elements not in `w`.\n  have M : (s \\ \u22c3 a \u2208 u, B a) \u2229 ball x (R x)\n    \u2286 \u22c3 (a : {a // a \u2209 w}), closed_ball (c a) (3 * r a),\n  { assume z hz,\n    set k := \u22c3 (a : v) (ha : a \u2208 w), B a with hk,\n    have k_closed : is_closed k :=\n      is_closed_bUnion w.finite_to_set (\u03bb i hi, h't _ (ut (vu i.2))),\n    have z_notmem_k : z \u2209 k,\n    { simp only [not_exists, exists_prop, mem_Union, mem_sep_iff, forall_exists_index,\n        set_coe.exists, not_and, exists_and_distrib_right, subtype.coe_mk],\n      assume b hbv h'b h'z,\n      have : z \u2208 (s \\ \u22c3 a \u2208 u, B a) \u2229 (\u22c3 a \u2208 u, B a) :=\n        mem_inter (mem_of_mem_inter_left hz) (mem_bUnion (vu hbv) h'z),\n      simpa only [diff_inter_self] },\n    -- since the elements of `w` are closed and finitely many, one can find a small ball around `z`\n    -- not intersecting them\n    have : ball x (R x) \\ k \u2208 \ud835\udcdd z,\n    { apply is_open.mem_nhds (is_open_ball.sdiff k_closed) _,\n      exact (mem_diff _).2 \u27e8mem_of_mem_inter_right hz, z_notmem_k\u27e9 },\n    obtain \u27e8d, dpos, hd\u27e9 : \u2203 (d : \u211d) (dpos : 0 < d), closed_ball z d \u2286 ball x (R x) \\ k :=\n      nhds_basis_closed_ball.mem_iff.1 this,\n    -- choose an element `a` of the family `t` contained in this small ball\n    obtain \u27e8a, hat, ad, rfl\u27e9 : \u2203 a \u2208 t, r a \u2264 min d (R z) \u2227 c a = z,\n      from hf z ((mem_diff _).1 (mem_of_mem_inter_left hz)).1 (min d (R z)) (lt_min dpos (hR0 z)),\n    have ax : B a \u2286 ball x (R x),\n    { refine (hB a hat).trans _,\n      refine subset.trans _ (hd.trans (diff_subset (ball x (R x)) k)),\n      exact closed_ball_subset_closed_ball (ad.trans (min_le_left _ _)), },\n    -- it intersects an element `b` of `u` with comparable diameter, by definition of `u`\n    obtain \u27e8b, bu, ab, bdiam\u27e9 : \u2203 b \u2208 u, (B a \u2229 B b).nonempty \u2227 r a \u2264 2 * r b,\n      from hu a \u27e8hat, ad.trans (min_le_right _ _)\u27e9,\n    have bv : b \u2208 v,\n    { refine \u27e8bu, ab.mono _\u27e9,\n      rw inter_comm,\n      exact inter_subset_inter_right _ ax },\n    let b' : v := \u27e8b, bv\u27e9,\n    -- `b` can not belong to `w`, as the elements of `w` do not intersect `closed_ball z d`,\n    -- contrary to `b`\n    have b'_notmem_w : b' \u2209 w,\n    { assume b'w,\n      have b'k : B b' \u2286 k, from @finset.subset_set_bUnion_of_mem _ _ _ (\u03bb (y : v), B y) _ b'w,\n      have : ((ball x (R x) \\ k) \u2229 k).nonempty,\n      { apply ab.mono (inter_subset_inter _ b'k),\n        refine ((hB _ hat).trans _).trans hd,\n        exact (closed_ball_subset_closed_ball (ad.trans (min_le_left _ _))) },\n      simpa only [diff_inter_self, not_nonempty_empty] },\n    let b'' : {a // a \u2209 w} := \u27e8b', b'_notmem_w\u27e9,\n    -- since `a` and `b` have comparable diameters, it follows that `z` belongs to the\n    -- enlargement of `b`\n    have zb : c a \u2208 closed_ball (c b) (3 * r b),\n    { rcases ab with \u27e8e, \u27e8ea, eb\u27e9\u27e9,\n      have A : dist (c a) e \u2264 r a, from mem_closed_ball'.1 (hB a hat ea),\n      have B : dist e (c b) \u2264 r b, from mem_closed_ball.1 (hB b (ut bu) eb),\n      simp only [mem_closed_ball],\n      linarith [dist_triangle (c a) e (c b)] },\n    suffices H : closed_ball (c b'') (3 * r b'')\n      \u2286 \u22c3 (a : {a // a \u2209 w}), closed_ball (c a) (3 * r a), from H zb,\n    exact subset_Union (\u03bb (a : {a // a \u2209 w}), closed_ball (c a) (3 * r a)) b'' },\n  -- now that we have proved our main inclusion, we can use it to estimate the measure of the points\n  -- in `ball x (r x)` not covered by `u`.\n  haveI : encodable v := (u_count.mono vu).to_encodable,\n  calc \u03bc ((s \\ \u22c3 a \u2208 u, B a) \u2229 ball x (R x))\n      \u2264 \u03bc (\u22c3 (a : {a // a \u2209 w}), closed_ball (c a) (3 * r a)) : measure_mono M\n  ... \u2264 \u2211' (a : {a // a \u2209 w}), \u03bc (closed_ball (c a) (3 * r a)) :\n    measure_Union_le _\n  ... \u2264 \u2211' (a : {a // a \u2209 w}), C * \u03bc (B a) : ennreal.tsum_le_tsum (\u03bb a, \u03bcB a (ut (vu a.1.2)))\n  ... = C * \u2211' (a : {a // a \u2209 w}), \u03bc (B a) : ennreal.tsum_mul_left\n  ... \u2264 C * (\u03b5 / C) : mul_le_mul_left' hw.le _\n  ... \u2264 \u03b5 : ennreal.mul_div_le\nend\n\n/-- Assume that around every point there are arbitrarily small scales at which the measure is\ndoubling. Then the set of closed sets `a` with nonempty interior contained in `closed_ball x r` and\ncovering a fixed proportion `1/C` of the ball `closed_ball x (3 * r)` forms a Vitali family.\nThis is essentially a restatement of the measurable Vitali theorem. -/\nprotected def vitali_family [metric_space \u03b1] [measurable_space \u03b1] [opens_measurable_space \u03b1]\n  [second_countable_topology \u03b1] (\u03bc : measure \u03b1) [is_locally_finite_measure \u03bc] (C : \u211d\u22650)\n  (h : \u2200 x, \u2203\u1da0 r in \ud835\udcdd[>] 0, \u03bc (closed_ball x (3 * r)) \u2264 C * \u03bc (closed_ball x r)) :\n  vitali_family \u03bc :=\n{ sets_at := \u03bb x, {a | is_closed a \u2227 (interior a).nonempty \u2227 \u2203 r, (a \u2286 closed_ball x r \u2227\n                      \u03bc (closed_ball x (3 * r)) \u2264 C * \u03bc a)},\n  measurable_set' := \u03bb x a ha, ha.1.measurable_set,\n  nonempty_interior := \u03bb x a ha, ha.2.1,\n  nontrivial := \u03bb x \u03b5 \u03b5pos, begin\n    obtain \u27e8r, \u03bcr, rpos, r\u03b5\u27e9 : \u2203 r,\n      \u03bc (closed_ball x (3 * r)) \u2264 C * \u03bc (closed_ball x r) \u2227 r \u2208 Ioc (0 : \u211d) \u03b5 :=\n      ((h x).and_eventually (Ioc_mem_nhds_within_Ioi \u27e8le_rfl, \u03b5pos\u27e9)).exists,\n    refine \u27e8closed_ball x r, \u27e8is_closed_ball, _, \u27e8r, subset.rfl, \u03bcr\u27e9\u27e9,\n      closed_ball_subset_closed_ball r\u03b5\u27e9,\n    exact (nonempty_ball.2 rpos).mono (ball_subset_interior_closed_ball)\n  end,\n  covering := begin\n    assume s f fsubset ffine,\n    let t : set (\u211d \u00d7 \u03b1 \u00d7 set \u03b1) :=\n      {p | p.2.2 \u2286 closed_ball p.2.1 p.1 \u2227 \u03bc (closed_ball p.2.1 (3 * p.1)) \u2264 C * \u03bc p.2.2\n      \u2227 (interior p.2.2).nonempty \u2227 is_closed p.2.2 \u2227 p.2.2 \u2208 f p.2.1 \u2227 p.2.1 \u2208 s},\n    have A : \u2200 x \u2208 s, \u2200 (\u03b5 : \u211d), \u03b5 > 0 \u2192 (\u2203 (p : \u211d \u00d7 \u03b1 \u00d7 set \u03b1) (Hp : p \u2208 t), p.1 \u2264 \u03b5 \u2227 p.2.1 = x),\n    { assume x xs \u03b5 \u03b5pos,\n      rcases ffine x xs \u03b5 \u03b5pos with \u27e8a, ha, h'a\u27e9,\n      rcases fsubset x xs ha with \u27e8a_closed, a_int, \u27e8r, ar, \u03bcr\u27e9\u27e9,\n      refine \u27e8\u27e8min r \u03b5, x, a\u27e9, \u27e8_, _, a_int, a_closed, ha, xs\u27e9, min_le_right _ _, rfl\u27e9,\n      { rcases min_cases r \u03b5 with h'|h'; rwa h'.1 },\n      { apply le_trans (measure_mono (closed_ball_subset_closed_ball _)) \u03bcr,\n        exact mul_le_mul_of_nonneg_left (min_le_left _ _) zero_le_three } },\n    rcases exists_disjoint_covering_ae \u03bc s t C (\u03bb p, p.1) (\u03bb p, p.2.1) (\u03bb p, p.2.2) (\u03bb p hp, hp.1)\n      (\u03bb p hp, hp.2.1) (\u03bb p hp, hp.2.2.1) (\u03bb p hp, hp.2.2.2.1) A\n      with \u27e8t', t't, t'_count, t'_disj, \u03bct'\u27e9,\n    refine \u27e8(\u03bb (p : \u211d \u00d7 \u03b1 \u00d7 set \u03b1), p.2) '' t', _, _, _, _\u27e9,\n    { rintros - \u27e8q, hq, rfl\u27e9,\n      exact (t't hq).2.2.2.2.2 },\n    { rintros p \u27e8q, hq, rfl\u27e9 p' \u27e8q', hq', rfl\u27e9 hqq',\n      exact t'_disj hq hq' (ne_of_apply_ne _ hqq') },\n    { rintros - \u27e8q, hq, rfl\u27e9,\n      exact (t't hq).2.2.2.2.1 },\n    { convert \u03bct' using 3,\n      rw bUnion_image }\n  end }\n\nend vitali\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/covering/vitali.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.718606651273909}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n\n! This file was ported from Lean 3 source module field_theory.separable\n! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Squarefree\nimport Mathbin.Data.Polynomial.Expand\nimport Mathbin.Data.Polynomial.Splits\nimport Mathbin.FieldTheory.Minpoly.Field\nimport Mathbin.RingTheory.PowerBasis\n\n/-!\n\n# Separable polynomials\n\nWe define a polynomial to be separable if it is coprime with its derivative. We prove basic\nproperties about separable polynomials here.\n\n## Main definitions\n\n* `polynomial.separable f`: a polynomial `f` is separable iff it is coprime with its derivative.\n\n-/\n\n\nuniverse u v w\n\nopen Classical BigOperators Polynomial\n\nopen Finset\n\nnamespace Polynomial\n\nsection CommSemiring\n\nvariable {R : Type u} [CommSemiring R] {S : Type v} [CommSemiring S]\n\n/-- A polynomial is separable iff it is coprime with its derivative. -/\ndef Separable (f : R[X]) : Prop :=\n  IsCoprime f f.derivative\n#align polynomial.separable Polynomial.Separable\n\ntheorem separable_def (f : R[X]) : f.Separable \u2194 IsCoprime f f.derivative :=\n  Iff.rfl\n#align polynomial.separable_def Polynomial.separable_def\n\ntheorem separable_def' (f : R[X]) : f.Separable \u2194 \u2203 a b : R[X], a * f + b * f.derivative = 1 :=\n  Iff.rfl\n#align polynomial.separable_def' Polynomial.separable_def'\n\ntheorem not_separable_zero [Nontrivial R] : \u00acSeparable (0 : R[X]) :=\n  by\n  rintro \u27e8x, y, h\u27e9\n  simpa only [derivative_zero, MulZeroClass.mul_zero, add_zero, zero_ne_one] using h\n#align polynomial.not_separable_zero Polynomial.not_separable_zero\n\ntheorem separable_one : (1 : R[X]).Separable :=\n  isCoprime_one_left\n#align polynomial.separable_one Polynomial.separable_one\n\n@[nontriviality]\ntheorem separable_of_subsingleton [Subsingleton R] (f : R[X]) : f.Separable := by simp [separable]\n#align polynomial.separable_of_subsingleton Polynomial.separable_of_subsingleton\n\ntheorem separable_x_add_c (a : R) : (X + C a).Separable :=\n  by\n  rw [separable_def, derivative_add, derivative_X, derivative_C, add_zero]\n  exact isCoprime_one_right\n#align polynomial.separable_X_add_C Polynomial.separable_x_add_c\n\ntheorem separable_x : (X : R[X]).Separable :=\n  by\n  rw [separable_def, derivative_X]\n  exact isCoprime_one_right\n#align polynomial.separable_X Polynomial.separable_x\n\ntheorem separable_c (r : R) : (C r).Separable \u2194 IsUnit r := by\n  rw [separable_def, derivative_C, isCoprime_zero_right, is_unit_C]\n#align polynomial.separable_C Polynomial.separable_c\n\ntheorem Separable.of_mul_left {f g : R[X]} (h : (f * g).Separable) : f.Separable :=\n  by\n  have := h.of_mul_left_left; rw [derivative_mul] at this\n  exact IsCoprime.of_mul_right_left (IsCoprime.of_add_mul_left_right this)\n#align polynomial.separable.of_mul_left Polynomial.Separable.of_mul_left\n\ntheorem Separable.of_mul_right {f g : R[X]} (h : (f * g).Separable) : g.Separable :=\n  by\n  rw [mul_comm] at h\n  exact h.of_mul_left\n#align polynomial.separable.of_mul_right Polynomial.Separable.of_mul_right\n\ntheorem Separable.of_dvd {f g : R[X]} (hf : f.Separable) (hfg : g \u2223 f) : g.Separable :=\n  by\n  rcases hfg with \u27e8f', rfl\u27e9\n  exact separable.of_mul_left hf\n#align polynomial.separable.of_dvd Polynomial.Separable.of_dvd\n\ntheorem separable_gcd_left {F : Type _} [Field F] {f : F[X]} (hf : f.Separable) (g : F[X]) :\n    (EuclideanDomain.gcd f g).Separable :=\n  Separable.of_dvd hf (EuclideanDomain.gcd_dvd_left f g)\n#align polynomial.separable_gcd_left Polynomial.separable_gcd_left\n\ntheorem separable_gcd_right {F : Type _} [Field F] {g : F[X]} (f : F[X]) (hg : g.Separable) :\n    (EuclideanDomain.gcd f g).Separable :=\n  Separable.of_dvd hg (EuclideanDomain.gcd_dvd_right f g)\n#align polynomial.separable_gcd_right Polynomial.separable_gcd_right\n\ntheorem Separable.isCoprime {f g : R[X]} (h : (f * g).Separable) : IsCoprime f g :=\n  by\n  have := h.of_mul_left_left; rw [derivative_mul] at this\n  exact IsCoprime.of_mul_right_right (IsCoprime.of_add_mul_left_right this)\n#align polynomial.separable.is_coprime Polynomial.Separable.isCoprime\n\ntheorem Separable.of_pow' {f : R[X]} :\n    \u2200 {n : \u2115} (h : (f ^ n).Separable), IsUnit f \u2228 f.Separable \u2227 n = 1 \u2228 n = 0\n  | 0 => fun h => Or.inr <| Or.inr rfl\n  | 1 => fun h => Or.inr <| Or.inl \u27e8pow_one f \u25b8 h, rfl\u27e9\n  | n + 2 => fun h => by\n    rw [pow_succ, pow_succ] at h\n    exact Or.inl (isCoprime_self.1 h.is_coprime.of_mul_right_left)\n#align polynomial.separable.of_pow' Polynomial.Separable.of_pow'\n\ntheorem Separable.of_pow {f : R[X]} (hf : \u00acIsUnit f) {n : \u2115} (hn : n \u2260 0)\n    (hfs : (f ^ n).Separable) : f.Separable \u2227 n = 1 :=\n  (hfs.of_pow'.resolve_left hf).resolve_right hn\n#align polynomial.separable.of_pow Polynomial.Separable.of_pow\n\ntheorem Separable.map {p : R[X]} (h : p.Separable) {f : R \u2192+* S} : (p.map f).Separable :=\n  let \u27e8a, b, H\u27e9 := h\n  \u27e8a.map f, b.map f, by\n    rw [derivative_map, \u2190 Polynomial.map_mul, \u2190 Polynomial.map_mul, \u2190 Polynomial.map_add, H,\n      Polynomial.map_one]\u27e9\n#align polynomial.separable.map Polynomial.Separable.map\n\nvariable (p q : \u2115)\n\ntheorem isUnit_of_self_mul_dvd_separable {p q : R[X]} (hp : p.Separable) (hq : q * q \u2223 p) :\n    IsUnit q := by\n  obtain \u27e8p, rfl\u27e9 := hq\n  apply is_coprime_self.mp\n  have : IsCoprime (q * (q * p)) (q * (q.derivative * p + q.derivative * p + q * p.derivative)) :=\n    by\n    simp only [\u2190 mul_assoc, mul_add]\n    convert hp\n    rw [derivative_mul, derivative_mul]\n    ring\n  exact IsCoprime.of_mul_right_left (IsCoprime.of_mul_left_left this)\n#align polynomial.is_unit_of_self_mul_dvd_separable Polynomial.isUnit_of_self_mul_dvd_separable\n\ntheorem multiplicity_le_one_of_separable {p q : R[X]} (hq : \u00acIsUnit q) (hsep : Separable p) :\n    multiplicity q p \u2264 1 := by\n  contrapose! hq\n  apply is_unit_of_self_mul_dvd_separable hsep\n  rw [\u2190 sq]\n  apply multiplicity.pow_dvd_of_le_multiplicity\n  simpa only [Nat.cast_one, Nat.cast_bit0] using PartENat.add_one_le_of_lt hq\n#align polynomial.multiplicity_le_one_of_separable Polynomial.multiplicity_le_one_of_separable\n\ntheorem Separable.squarefree {p : R[X]} (hsep : Separable p) : Squarefree p :=\n  by\n  rw [multiplicity.squarefree_iff_multiplicity_le_one p]\n  intro f\n  by_cases hunit : IsUnit f\n  \u00b7 exact Or.inr hunit\n  exact Or.inl (multiplicity_le_one_of_separable hunit hsep)\n#align polynomial.separable.squarefree Polynomial.Separable.squarefree\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type u} [CommRing R]\n\ntheorem separable_x_sub_c {x : R} : Separable (X - C x) := by\n  simpa only [sub_eq_add_neg, C_neg] using separable_X_add_C (-x)\n#align polynomial.separable_X_sub_C Polynomial.separable_x_sub_c\n\ntheorem Separable.mul {f g : R[X]} (hf : f.Separable) (hg : g.Separable) (h : IsCoprime f g) :\n    (f * g).Separable := by\n  rw [separable_def, derivative_mul]\n  exact\n    ((hf.mul_right h).add_mul_left_right _).mul_left ((h.symm.mul_right hg).mul_add_right_right _)\n#align polynomial.separable.mul Polynomial.Separable.mul\n\ntheorem separable_prod' {\u03b9 : Sort _} {f : \u03b9 \u2192 R[X]} {s : Finset \u03b9} :\n    (\u2200 x \u2208 s, \u2200 y \u2208 s, x \u2260 y \u2192 IsCoprime (f x) (f y)) \u2192\n      (\u2200 x \u2208 s, (f x).Separable) \u2192 (\u220f x in s, f x).Separable :=\n  Finset.induction_on s (fun _ _ => separable_one) fun a s has ih h1 h2 =>\n    by\n    simp_rw [Finset.forall_mem_insert, forall_and] at h1 h2; rw [prod_insert has]\n    exact\n      h2.1.mul (ih h1.2.2 h2.2)\n        (IsCoprime.prod_right fun i his => h1.1.2 i his <| Ne.symm <| ne_of_mem_of_not_mem his has)\n#align polynomial.separable_prod' Polynomial.separable_prod'\n\ntheorem separable_prod {\u03b9 : Sort _} [Fintype \u03b9] {f : \u03b9 \u2192 R[X]} (h1 : Pairwise (IsCoprime on f))\n    (h2 : \u2200 x, (f x).Separable) : (\u220f x, f x).Separable :=\n  separable_prod' (fun x hx y hy hxy => h1 hxy) fun x hx => h2 x\n#align polynomial.separable_prod Polynomial.separable_prod\n\ntheorem Separable.inj_of_prod_x_sub_c [Nontrivial R] {\u03b9 : Sort _} {f : \u03b9 \u2192 R} {s : Finset \u03b9}\n    (hfs : (\u220f i in s, X - C (f i)).Separable) {x y : \u03b9} (hx : x \u2208 s) (hy : y \u2208 s)\n    (hfxy : f x = f y) : x = y := by\n  by_contra hxy\n  rw [\u2190 insert_erase hx, prod_insert (not_mem_erase _ _), \u2190\n    insert_erase (mem_erase_of_ne_of_mem (Ne.symm hxy) hy), prod_insert (not_mem_erase _ _), \u2190\n    mul_assoc, hfxy, \u2190 sq] at hfs\n  cases (hfs.of_mul_left.of_pow (not_is_unit_X_sub_C _) two_ne_zero).2\n#align polynomial.separable.inj_of_prod_X_sub_C Polynomial.Separable.inj_of_prod_x_sub_c\n\ntheorem Separable.injective_of_prod_x_sub_c [Nontrivial R] {\u03b9 : Sort _} [Fintype \u03b9] {f : \u03b9 \u2192 R}\n    (hfs : (\u220f i, X - C (f i)).Separable) : Function.Injective f := fun x y hfxy =>\n  hfs.inj_of_prod_x_sub_c (mem_univ _) (mem_univ _) hfxy\n#align polynomial.separable.injective_of_prod_X_sub_C Polynomial.Separable.injective_of_prod_x_sub_c\n\ntheorem nodup_of_separable_prod [Nontrivial R] {s : Multiset R}\n    (hs : Separable (Multiset.map (fun a => X - C a) s).Prod) : s.Nodup :=\n  by\n  rw [Multiset.nodup_iff_ne_cons_cons]\n  rintro a t rfl\n  refine' not_is_unit_X_sub_C a (is_unit_of_self_mul_dvd_separable hs _)\n  simpa only [Multiset.map_cons, Multiset.prod_cons] using mul_dvd_mul_left _ (dvd_mul_right _ _)\n#align polynomial.nodup_of_separable_prod Polynomial.nodup_of_separable_prod\n\n/-- If `is_unit n` in a `comm_ring R`, then `X ^ n - u` is separable for any unit `u`. -/\ntheorem separable_x_pow_sub_c_unit {n : \u2115} (u : R\u02e3) (hn : IsUnit (n : R)) :\n    Separable (X ^ n - C (u : R)) := by\n  nontriviality R\n  rcases n.eq_zero_or_pos with (rfl | hpos)\n  \u00b7 simpa using hn\n  apply (separable_def' (X ^ n - C (u : R))).2\n  obtain \u27e8n', hn'\u27e9 := hn.exists_left_inv\n  refine' \u27e8-C \u2191u\u207b\u00b9, C \u2191u\u207b\u00b9 * C n' * X, _\u27e9\n  rw [derivative_sub, derivative_C, sub_zero, derivative_pow X n, derivative_X, mul_one]\n  calc\n    -C \u2191u\u207b\u00b9 * (X ^ n - C \u2191u) + C \u2191u\u207b\u00b9 * C n' * X * (\u2191n * X ^ (n - 1)) =\n        C (\u2191u\u207b\u00b9 * \u2191u) - C \u2191u\u207b\u00b9 * X ^ n + C \u2191u\u207b\u00b9 * C (n' * \u2191n) * (X * X ^ (n - 1)) :=\n      by\n      simp only [C.map_mul, C_eq_nat_cast]\n      ring\n    _ = 1 := by\n      simp only [Units.inv_mul, hn', C.map_one, mul_one, \u2190 pow_succ,\n        Nat.sub_add_cancel (show 1 \u2264 n from hpos), sub_add_cancel]\n    \n#align polynomial.separable_X_pow_sub_C_unit Polynomial.separable_x_pow_sub_c_unit\n\ntheorem rootMultiplicity_le_one_of_separable [Nontrivial R] {p : R[X]} (hsep : Separable p)\n    (x : R) : rootMultiplicity x p \u2264 1 :=\n  by\n  by_cases hp : p = 0\n  \u00b7 simp [hp]\n  rw [root_multiplicity_eq_multiplicity, dif_neg hp, \u2190 PartENat.coe_le_coe, PartENat.natCast_get,\n    Nat.cast_one]\n  exact multiplicity_le_one_of_separable (not_is_unit_X_sub_C _) hsep\n#align polynomial.root_multiplicity_le_one_of_separable Polynomial.rootMultiplicity_le_one_of_separable\n\nend CommRing\n\nsection IsDomain\n\nvariable {R : Type u} [CommRing R] [IsDomain R]\n\ntheorem count_roots_le_one {p : R[X]} (hsep : Separable p) (x : R) : p.roots.count x \u2264 1 :=\n  by\n  rw [count_roots p]\n  exact root_multiplicity_le_one_of_separable hsep x\n#align polynomial.count_roots_le_one Polynomial.count_roots_le_one\n\ntheorem nodup_roots {p : R[X]} (hsep : Separable p) : p.roots.Nodup :=\n  Multiset.nodup_iff_count_le_one.mpr (count_roots_le_one hsep)\n#align polynomial.nodup_roots Polynomial.nodup_roots\n\nend IsDomain\n\nsection Field\n\nvariable {F : Type u} [Field F] {K : Type v} [Field K]\n\ntheorem separable_iff_derivative_ne_zero {f : F[X]} (hf : Irreducible f) :\n    f.Separable \u2194 f.derivative \u2260 0 :=\n  \u27e8fun h1 h2 => hf.not_unit <| isCoprime_zero_right.1 <| h2 \u25b8 h1, fun h =>\n    EuclideanDomain.isCoprime_of_dvd (mt And.right h) fun g hg1 hg2 \u27e8p, hg3\u27e9 hg4 =>\n      let \u27e8u, hu\u27e9 := (hf.isUnit_or_isUnit hg3).resolve_left hg1\n      have : f \u2223 f.derivative := by\n        conv_lhs => rw [hg3, \u2190 hu]\n        rwa [Units.mul_right_dvd]\n      not_lt_of_le (natDegree_le_of_dvd this h) <|\n        natDegree_derivative_lt <| mt derivative_of_natDegree_zero h\u27e9\n#align polynomial.separable_iff_derivative_ne_zero Polynomial.separable_iff_derivative_ne_zero\n\ntheorem separable_map (f : F \u2192+* K) {p : F[X]} : (p.map f).Separable \u2194 p.Separable := by\n  simp_rw [separable_def, derivative_map, is_coprime_map]\n#align polynomial.separable_map Polynomial.separable_map\n\ntheorem separable_prod_x_sub_c_iff' {\u03b9 : Sort _} {f : \u03b9 \u2192 F} {s : Finset \u03b9} :\n    (\u220f i in s, X - C (f i)).Separable \u2194 \u2200 x \u2208 s, \u2200 y \u2208 s, f x = f y \u2192 x = y :=\n  \u27e8fun hfs x hx y hy hfxy => hfs.inj_of_prod_x_sub_c hx hy hfxy, fun H =>\n    by\n    rw [\u2190 prod_attach]\n    exact\n      separable_prod'\n        (fun x hx y hy hxy =>\n          @pairwise_coprime_X_sub_C _ _ { x // x \u2208 s } (fun x => f x)\n            (fun x y hxy => Subtype.eq <| H x.1 x.2 y.1 y.2 hxy) _ _ hxy)\n        fun _ _ => separable_X_sub_C\u27e9\n#align polynomial.separable_prod_X_sub_C_iff' Polynomial.separable_prod_x_sub_c_iff'\n\ntheorem separable_prod_x_sub_c_iff {\u03b9 : Sort _} [Fintype \u03b9] {f : \u03b9 \u2192 F} :\n    (\u220f i, X - C (f i)).Separable \u2194 Function.Injective f :=\n  separable_prod_x_sub_c_iff'.trans <| by simp_rw [mem_univ, true_imp_iff, Function.Injective]\n#align polynomial.separable_prod_X_sub_C_iff Polynomial.separable_prod_x_sub_c_iff\n\nsection CharP\n\nvariable (p : \u2115) [HF : CharP F p]\n\ninclude HF\n\ntheorem separable_or {f : F[X]} (hf : Irreducible f) :\n    f.Separable \u2228 \u00acf.Separable \u2227 \u2203 g : F[X], Irreducible g \u2227 expand F p g = f :=\n  if H : f.derivative = 0 then by\n    rcases p.eq_zero_or_pos with (rfl | hp)\n    \u00b7 haveI := CharP.charP_to_charZero F\n      have := nat_degree_eq_zero_of_derivative_eq_zero H\n      have := (nat_degree_pos_iff_degree_pos.mpr <| degree_pos_of_irreducible hf).ne'\n      contradiction\n    haveI := is_local_ring_hom_expand F hp\n    exact\n      Or.inr\n        \u27e8by rw [separable_iff_derivative_ne_zero hf, Classical.not_not, H], contract p f,\n          of_irreducible_map (\u2191(expand F p)) (by rwa [\u2190 expand_contract p H hp.ne'] at hf),\n          expand_contract p H hp.ne'\u27e9\n  else Or.inl <| (separable_iff_derivative_ne_zero hf).2 H\n#align polynomial.separable_or Polynomial.separable_or\n\ntheorem exists_separable_of_irreducible {f : F[X]} (hf : Irreducible f) (hp : p \u2260 0) :\n    \u2203 (n : \u2115)(g : F[X]), g.Separable \u2227 expand F (p ^ n) g = f :=\n  by\n  replace hp : p.prime := (CharP.char_is_prime_or_zero F p).resolve_right hp\n  induction' hn : f.nat_degree using Nat.strong_induction_on with N ih generalizing f\n  rcases separable_or p hf with (h | \u27e8h1, g, hg, hgf\u27e9)\n  \u00b7 refine' \u27e80, f, h, _\u27e9\n    rw [pow_zero, expand_one]\n  \u00b7 cases' N with N\n    \u00b7 rw [nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff] at hn\n      rw [hn, separable_C, isUnit_iff_ne_zero, Classical.not_not] at h1\n      have hf0 : f \u2260 0 := hf.ne_zero\n      rw [h1, C_0] at hn\n      exact absurd hn hf0\n    have hg1 : g.nat_degree * p = N.succ := by rwa [\u2190 nat_degree_expand, hgf]\n    have hg2 : g.nat_degree \u2260 0 := by\n      intro this\n      rw [this, MulZeroClass.zero_mul] at hg1\n      cases hg1\n    have hg3 : g.nat_degree < N.succ :=\n      by\n      rw [\u2190 mul_one g.nat_degree, \u2190 hg1]\n      exact Nat.mul_lt_mul_of_pos_left hp.one_lt hg2.bot_lt\n    rcases ih _ hg3 hg rfl with \u27e8n, g, hg4, rfl\u27e9\n    refine' \u27e8n + 1, g, hg4, _\u27e9\n    rw [\u2190 hgf, expand_expand, pow_succ]\n#align polynomial.exists_separable_of_irreducible Polynomial.exists_separable_of_irreducible\n\ntheorem isUnit_or_eq_zero_of_separable_expand {f : F[X]} (n : \u2115) (hp : 0 < p)\n    (hf : (expand F (p ^ n) f).Separable) : IsUnit f \u2228 n = 0 :=\n  by\n  rw [or_iff_not_imp_right]\n  rintro hn : n \u2260 0\n  have hf2 : (expand F (p ^ n) f).derivative = 0 := by\n    rw [derivative_expand, Nat.cast_pow, CharP.cast_eq_zero, zero_pow hn.bot_lt,\n      MulZeroClass.zero_mul, MulZeroClass.mul_zero]\n  rw [separable_def, hf2, isCoprime_zero_right, is_unit_iff] at hf\n  rcases hf with \u27e8r, hr, hrf\u27e9\n  rw [eq_comm, expand_eq_C (pow_pos hp _)] at hrf\n  rwa [hrf, is_unit_C]\n#align polynomial.is_unit_or_eq_zero_of_separable_expand Polynomial.isUnit_or_eq_zero_of_separable_expand\n\ntheorem unique_separable_of_irreducible {f : F[X]} (hf : Irreducible f) (hp : 0 < p) (n\u2081 : \u2115)\n    (g\u2081 : F[X]) (hg\u2081 : g\u2081.Separable) (hgf\u2081 : expand F (p ^ n\u2081) g\u2081 = f) (n\u2082 : \u2115) (g\u2082 : F[X])\n    (hg\u2082 : g\u2082.Separable) (hgf\u2082 : expand F (p ^ n\u2082) g\u2082 = f) : n\u2081 = n\u2082 \u2227 g\u2081 = g\u2082 :=\n  by\n  revert g\u2081 g\u2082\n  wlog hn : n\u2081 \u2264 n\u2082\n  \u00b7 intro g\u2081 g\u2082 hg\u2081 Hg\u2081 hg\u2082 Hg\u2082\n    simpa only [eq_comm] using this hf hp n\u2082 n\u2081 (le_of_not_le hn) g\u2082 g\u2081 hg\u2082 Hg\u2082 hg\u2081 Hg\u2081\n  have hf0 : f \u2260 0 := hf.ne_zero\n  intros\n  rw [le_iff_exists_add] at hn\n  rcases hn with \u27e8k, rfl\u27e9\n  rw [\u2190 hgf\u2081, pow_add, expand_mul, expand_inj (pow_pos hp n\u2081)] at hgf\u2082\n  subst hgf\u2082\n  subst hgf\u2081\n  rcases is_unit_or_eq_zero_of_separable_expand p k hp hg\u2081 with (h | rfl)\n  \u00b7 rw [is_unit_iff] at h\n    rcases h with \u27e8r, hr, rfl\u27e9\n    simp_rw [expand_C] at hf\n    exact absurd (is_unit_C.2 hr) hf.1\n  \u00b7 rw [add_zero, pow_zero, expand_one]\n    constructor <;> rfl\n#align polynomial.unique_separable_of_irreducible Polynomial.unique_separable_of_irreducible\n\nend CharP\n\n/-- If `n \u2260 0` in `F`, then ` X ^ n - a` is separable for any `a \u2260 0`. -/\ntheorem separable_x_pow_sub_c {n : \u2115} (a : F) (hn : (n : F) \u2260 0) (ha : a \u2260 0) :\n    Separable (X ^ n - C a) :=\n  separable_x_pow_sub_c_unit (Units.mk0 a ha) (IsUnit.mk0 n hn)\n#align polynomial.separable_X_pow_sub_C Polynomial.separable_x_pow_sub_c\n\n-- this can possibly be strengthened to making `separable_X_pow_sub_C_unit` a\n-- bi-implication, but it is nontrivial!\n/-- In a field `F`, `X ^ n - 1` is separable iff `\u2191n \u2260 0`. -/\ntheorem x_pow_sub_one_separable_iff {n : \u2115} : (X ^ n - 1 : F[X]).Separable \u2194 (n : F) \u2260 0 :=\n  by\n  refine' \u27e8_, fun h => separable_X_pow_sub_C_unit 1 (IsUnit.mk0 (\u2191n) h)\u27e9\n  rw [separable_def', derivative_sub, derivative_X_pow, derivative_one, sub_zero]\n  -- Suppose `(n : F) = 0`, then the derivative is `0`, so `X ^ n - 1` is a unit, contradiction.\n  rintro (h : IsCoprime _ _) hn'\n  rw [hn', C_0, MulZeroClass.zero_mul, isCoprime_zero_right] at h\n  exact not_is_unit_X_pow_sub_one F n h\n#align polynomial.X_pow_sub_one_separable_iff Polynomial.x_pow_sub_one_separable_iff\n\nsection Splits\n\ntheorem card_rootSet_eq_natDegree [Algebra F K] {p : F[X]} (hsep : p.Separable)\n    (hsplit : Splits (algebraMap F K) p) : Fintype.card (p.rootSet K) = p.natDegree :=\n  by\n  simp_rw [root_set_def, Finset.coe_sort_coe, Fintype.card_coe]\n  rw [Multiset.toFinset_card_of_nodup, \u2190 nat_degree_eq_card_roots hsplit]\n  exact nodup_roots hsep.map\n#align polynomial.card_root_set_eq_nat_degree Polynomial.card_rootSet_eq_natDegree\n\nvariable {i : F \u2192+* K}\n\ntheorem eq_x_sub_c_of_separable_of_root_eq {x : F} {h : F[X]} (h_sep : h.Separable)\n    (h_root : h.eval x = 0) (h_splits : Splits i h) (h_roots : \u2200 y \u2208 (h.map i).roots, y = i x) :\n    h = C (leadingCoeff h) * (X - C x) :=\n  by\n  have h_ne_zero : h \u2260 0 := by\n    rintro rfl\n    exact not_separable_zero h_sep\n  apply Polynomial.eq_X_sub_C_of_splits_of_single_root i h_splits\n  apply Finset.mk.inj\n  \u00b7 change _ = {i x}\n    rw [Finset.eq_singleton_iff_unique_mem]\n    constructor\n    \u00b7 apply finset.mem_mk.mpr\n      rw [mem_roots (show h.map i \u2260 0 from map_ne_zero h_ne_zero)]\n      rw [is_root.def, \u2190 eval\u2082_eq_eval_map, eval\u2082_hom, h_root]\n      exact RingHom.map_zero i\n    \u00b7 exact h_roots\n  \u00b7 exact nodup_roots (separable.map h_sep)\n#align polynomial.eq_X_sub_C_of_separable_of_root_eq Polynomial.eq_x_sub_c_of_separable_of_root_eq\n\ntheorem exists_finset_of_splits (i : F \u2192+* K) {f : F[X]} (sep : Separable f) (sp : Splits i f) :\n    \u2203 s : Finset K, f.map i = C (i f.leadingCoeff) * s.Prod fun a : K => X - C a :=\n  by\n  obtain \u27e8s, h\u27e9 := (splits_iff_exists_multiset _).1 sp\n  use s.to_finset\n  rw [h, Finset.prod_eq_multiset_prod, \u2190 Multiset.toFinset_eq]\n  apply nodup_of_separable_prod\n  apply separable.of_mul_right\n  rw [\u2190 h]\n  exact sep.map\n#align polynomial.exists_finset_of_splits Polynomial.exists_finset_of_splits\n\nend Splits\n\ntheorem Irreducible.separable [CharZero F] {f : F[X]} (hf : Irreducible f) : f.Separable :=\n  by\n  rw [separable_iff_derivative_ne_zero hf, Ne, \u2190 degree_eq_bot, degree_derivative_eq]\n  \u00b7 rintro \u27e8\u27e9\n  rw [pos_iff_ne_zero, Ne, nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff]\n  refine' fun hf1 => hf.not_unit _\n  rw [hf1, is_unit_C, isUnit_iff_ne_zero]\n  intro hf2\n  rw [hf2, C_0] at hf1\n  exact absurd hf1 hf.ne_zero\n#align irreducible.separable Irreducible.separable\n\nend Field\n\nend Polynomial\n\nopen Polynomial\n\nsection CommRing\n\nvariable (F K : Type _) [CommRing F] [Ring K] [Algebra F K]\n\n-- TODO: refactor to allow transcendental extensions?\n-- See: https://en.wikipedia.org/wiki/Separable_extension#Separability_of_transcendental_extensions\n-- Note that right now a Galois extension (class `is_galois`) is defined to be an extension which\n-- is separable and normal, so if the definition of separable changes here at some point\n-- to allow non-algebraic extensions, then the definition of `is_galois` must also be changed.\n/-- Typeclass for separable field extension: `K` is a separable field extension of `F` iff\nthe minimal polynomial of every `x : K` is separable.\n\nWe define this for general (commutative) rings and only assume `F` and `K` are fields if this\nis needed for a proof.\n-/\nclass IsSeparable : Prop where\n  is_integral' (x : K) : IsIntegral F x\n  separable' (x : K) : (minpoly F x).Separable\n#align is_separable IsSeparable\n\nvariable (F) {K}\n\ntheorem IsSeparable.isIntegral [IsSeparable F K] : \u2200 x : K, IsIntegral F x :=\n  IsSeparable.is_integral'\n#align is_separable.is_integral IsSeparable.isIntegral\n\ntheorem IsSeparable.separable [IsSeparable F K] : \u2200 x : K, (minpoly F x).Separable :=\n  IsSeparable.separable'\n#align is_separable.separable IsSeparable.separable\n\nvariable {F K}\n\ntheorem isSeparable_iff : IsSeparable F K \u2194 \u2200 x : K, IsIntegral F x \u2227 (minpoly F x).Separable :=\n  \u27e8fun h x => \u27e8@IsSeparable.isIntegral F _ _ _ h x, @IsSeparable.separable F _ _ _ h x\u27e9, fun h =>\n    \u27e8fun x => (h x).1, fun x => (h x).2\u27e9\u27e9\n#align is_separable_iff isSeparable_iff\n\nend CommRing\n\ninstance isSeparable_self (F : Type _) [Field F] : IsSeparable F F :=\n  \u27e8fun x => isIntegral_algebraMap, fun x =>\n    by\n    rw [minpoly.eq_x_sub_C']\n    exact separable_X_sub_C\u27e9\n#align is_separable_self isSeparable_self\n\n-- See note [lower instance priority]\n/-- A finite field extension in characteristic 0 is separable. -/\ninstance (priority := 100) IsSeparable.of_finite (F K : Type _) [Field F] [Field K] [Algebra F K]\n    [FiniteDimensional F K] [CharZero F] : IsSeparable F K :=\n  have : \u2200 x : K, IsIntegral F x := fun x => Algebra.isIntegral_of_finite _ _ _\n  \u27e8this, fun x => (minpoly.irreducible (this x)).Separable\u27e9\n#align is_separable.of_finite IsSeparable.of_finite\n\nsection IsSeparableTower\n\nvariable (F K E : Type _) [Field F] [Field K] [Field E] [Algebra F K] [Algebra F E] [Algebra K E]\n  [IsScalarTower F K E]\n\ntheorem isSeparable_tower_top_of_isSeparable [IsSeparable F E] : IsSeparable K E :=\n  \u27e8fun x => isIntegral_of_isScalarTower (IsSeparable.isIntegral F x), fun x =>\n    (IsSeparable.separable F x).map.of_dvd (minpoly.dvd_map_of_isScalarTower _ _ _)\u27e9\n#align is_separable_tower_top_of_is_separable isSeparable_tower_top_of_isSeparable\n\ntheorem isSeparable_tower_bot_of_isSeparable [h : IsSeparable F E] : IsSeparable F K :=\n  isSeparable_iff.2 fun x =>\n    by\n    refine'\n      (isSeparable_iff.1 h (algebraMap K E x)).imp isIntegral_tower_bot_of_isIntegral_field\n        fun hs => _\n    obtain \u27e8q, hq\u27e9 :=\n      minpoly.dvd F x\n        ((aeval_algebra_map_eq_zero_iff _ _ _).mp (minpoly.aeval F ((algebraMap K E) x)))\n    rw [hq] at hs\n    exact hs.of_mul_left\n#align is_separable_tower_bot_of_is_separable isSeparable_tower_bot_of_isSeparable\n\nvariable {E}\n\ntheorem IsSeparable.of_algHom (E' : Type _) [Field E'] [Algebra F E'] (f : E \u2192\u2090[F] E')\n    [IsSeparable F E'] : IsSeparable F E :=\n  by\n  letI : Algebra E E' := RingHom.toAlgebra f.to_ring_hom\n  haveI : IsScalarTower F E E' := IsScalarTower.of_algebraMap_eq fun x => (f.commutes x).symm\n  exact isSeparable_tower_bot_of_isSeparable F E E'\n#align is_separable.of_alg_hom IsSeparable.of_algHom\n\nend IsSeparableTower\n\nsection CardAlgHom\n\nvariable {R S T : Type _} [CommRing S]\n\nvariable {K L F : Type _} [Field K] [Field L] [Field F]\n\nvariable [Algebra K S] [Algebra K L]\n\ntheorem AlgHom.card_of_powerBasis (pb : PowerBasis K S) (h_sep : (minpoly K pb.gen).Separable)\n    (h_splits : (minpoly K pb.gen).Splits (algebraMap K L)) :\n    @Fintype.card (S \u2192\u2090[K] L) (PowerBasis.AlgHom.fintype pb) = pb.dim :=\n  by\n  let s := ((minpoly K pb.gen).map (algebraMap K L)).roots.toFinset\n  have H := fun x => Multiset.mem_toFinset\n  rw [Fintype.card_congr pb.lift_equiv', Fintype.card_of_subtype s H, \u2190 pb.nat_degree_minpoly,\n    nat_degree_eq_card_roots h_splits, Multiset.toFinset_card_of_nodup]\n  exact nodup_roots ((separable_map (algebraMap K L)).mpr h_sep)\n#align alg_hom.card_of_power_basis AlgHom.card_of_powerBasis\n\nend CardAlgHom\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/FieldTheory/Separable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7186066503147065}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport order.rel_iso\nimport order.lattice_intervals\nimport order.galois_connection\n\n/-!\n# Modular Lattices\nThis file defines Modular Lattices, a kind of lattice useful in algebra.\nFor examples, look to the subobject lattices of abelian groups, submodules, and ideals, or consider\nany distributive lattice.\n\n## Main Definitions\n- `is_modular_lattice` defines a modular lattice to be one such that\n  `x \u2264 z \u2192 (x \u2294 y) \u2293 z \u2264 x \u2294 (y \u2293 z)`\n- `inf_Icc_order_iso_Icc_sup` gives an order isomorphism between the intervals\n  `[a \u2293 b, a]` and `[b, a \u2294 b]`.\n  This corresponds to the diamond (or second) isomorphism theorems of algebra.\n\n## Main Results\n- `is_modular_lattice_iff_inf_sup_inf_assoc`:\n  Modularity is equivalent to the `inf_sup_inf_assoc`: `(x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z`\n- `distrib_lattice.is_modular_lattice`: Distributive lattices are modular.\n\n## To do\n- Relate atoms and coatoms in modular lattices\n\n-/\n\nvariable {\u03b1 : Type*}\n\n/-- A modular lattice is one with a limited associativity between `\u2293` and `\u2294`. -/\nclass is_modular_lattice \u03b1 [lattice \u03b1] : Prop :=\n(sup_inf_le_assoc_of_le : \u2200 {x : \u03b1} (y : \u03b1) {z : \u03b1}, x \u2264 z \u2192 (x \u2294 y) \u2293 z \u2264 x \u2294 (y \u2293 z))\n\nsection is_modular_lattice\nvariables [lattice \u03b1] [is_modular_lattice \u03b1]\n\ntheorem sup_inf_assoc_of_le {x : \u03b1} (y : \u03b1) {z : \u03b1} (h : x \u2264 z) :\n  (x \u2294 y) \u2293 z = x \u2294 (y \u2293 z) :=\nle_antisymm (is_modular_lattice.sup_inf_le_assoc_of_le y h)\n  (le_inf (sup_le_sup_left inf_le_left _) (sup_le h inf_le_right))\n\ntheorem is_modular_lattice.inf_sup_inf_assoc {x y z : \u03b1} :\n  (x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z :=\n(sup_inf_assoc_of_le y inf_le_right).symm\n\nlemma inf_sup_assoc_of_le {x : \u03b1} (y : \u03b1) {z : \u03b1} (h : z \u2264 x) :\n  (x \u2293 y) \u2294 z = x \u2293 (y \u2294 z) :=\nby rw [inf_comm, sup_comm, \u2190 sup_inf_assoc_of_le y h, inf_comm, sup_comm]\n\ninstance : is_modular_lattice (order_dual \u03b1) :=\n\u27e8\u03bb x y z xz, le_of_eq (by { rw [inf_comm, sup_comm, eq_comm, inf_comm, sup_comm],\n  convert sup_inf_assoc_of_le (order_dual.of_dual y) (order_dual.dual_le.2 xz) })\u27e9\n\nvariables {x y z : \u03b1}\n\ntheorem is_modular_lattice.sup_inf_sup_assoc :\n  (x \u2294 z) \u2293 (y \u2294 z) = ((x \u2294 z) \u2293 y) \u2294 z :=\n@is_modular_lattice.inf_sup_inf_assoc (order_dual \u03b1) _ _ _ _ _\n\ntheorem eq_of_le_of_inf_le_of_sup_le (hxy : x \u2264 y) (hinf : y \u2293 z \u2264 x \u2293 z) (hsup : y \u2294 z \u2264 x \u2294 z) :\n  x = y :=\nle_antisymm hxy $\n  have h : y \u2264 x \u2294 z,\n    from calc y \u2264 y \u2294 z : le_sup_left\n      ... \u2264 x \u2294 z : hsup,\n  calc y \u2264 (x \u2294 z) \u2293 y : le_inf h (le_refl _)\n    ... = x \u2294 (z \u2293 y) : sup_inf_assoc_of_le _ hxy\n    ... \u2264 x \u2294 (z \u2293 x) : sup_le_sup_left\n      (by rw [inf_comm, @inf_comm _ _ z]; exact hinf) _\n    ... \u2264 x : sup_le (le_refl _) inf_le_right\n\ntheorem sup_lt_sup_of_lt_of_inf_le_inf (hxy : x < y) (hinf : y \u2293 z \u2264 x \u2293 z) : x \u2294 z < y \u2294 z :=\nlt_of_le_of_ne\n  (sup_le_sup_right (le_of_lt hxy) _)\n  (\u03bb hsup, ne_of_lt hxy $ eq_of_le_of_inf_le_of_sup_le (le_of_lt hxy) hinf\n    (le_of_eq hsup.symm))\n\ntheorem inf_lt_inf_of_lt_of_sup_le_sup (hxy : x < y) (hinf : y \u2294 z \u2264 x \u2294 z) : x \u2293 z < y \u2293 z :=\n@sup_lt_sup_of_lt_of_inf_le_inf (order_dual \u03b1) _ _ _ _ _ hxy hinf\n\n/-- A generalization of the theorem that if `N` is a submodule of `M` and\n  `N` and `M / N` are both Artinian, then `M` is Artinian. -/\ntheorem well_founded_lt_exact_sequence\n  {\u03b2 \u03b3 : Type*} [partial_order \u03b2] [partial_order \u03b3]\n  (h\u2081 : well_founded ((<) : \u03b2 \u2192 \u03b2 \u2192 Prop))\n  (h\u2082 : well_founded ((<) : \u03b3 \u2192 \u03b3 \u2192 Prop))\n  (K : \u03b1) (f\u2081 : \u03b2 \u2192 \u03b1) (f\u2082 : \u03b1 \u2192 \u03b2) (g\u2081 : \u03b3 \u2192 \u03b1) (g\u2082 : \u03b1 \u2192 \u03b3)\n  (gci : galois_coinsertion f\u2081 f\u2082)\n  (gi : galois_insertion g\u2082 g\u2081)\n  (hf : \u2200 a, f\u2081 (f\u2082 a) = a \u2293 K)\n  (hg : \u2200 a, g\u2081 (g\u2082 a) = a \u2294 K) :\n  well_founded ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\nsubrelation.wf\n  (\u03bb A B hAB, show prod.lex (<) (<) (f\u2082 A, g\u2082 A) (f\u2082 B, g\u2082 B),\n    begin\n      simp only [prod.lex_def, lt_iff_le_not_le, \u2190 gci.l_le_l_iff,\n        \u2190 gi.u_le_u_iff, hf, hg, le_antisymm_iff],\n      simp only [gci.l_le_l_iff, gi.u_le_u_iff, \u2190 lt_iff_le_not_le, \u2190 le_antisymm_iff],\n      cases lt_or_eq_of_le (inf_le_inf_right K (le_of_lt hAB)) with h h,\n      { exact or.inl h },\n      { exact or.inr \u27e8h, sup_lt_sup_of_lt_of_inf_le_inf hAB (le_of_eq h.symm)\u27e9 }\n    end)\n  (inv_image.wf _ (prod.lex_wf h\u2081 h\u2082))\n\n/-- A generalization of the theorem that if `N` is a submodule of `M` and\n  `N` and `M / N` are both Noetherian, then `M` is Noetherian.  -/\ntheorem well_founded_gt_exact_sequence\n  {\u03b2 \u03b3 : Type*} [partial_order \u03b2] [partial_order \u03b3]\n  (h\u2081 : well_founded ((>) : \u03b2 \u2192 \u03b2 \u2192 Prop))\n  (h\u2082 : well_founded ((>) : \u03b3 \u2192 \u03b3 \u2192 Prop))\n  (K : \u03b1) (f\u2081 : \u03b2 \u2192 \u03b1) (f\u2082 : \u03b1 \u2192 \u03b2) (g\u2081 : \u03b3 \u2192 \u03b1) (g\u2082 : \u03b1 \u2192 \u03b3)\n  (gci : galois_coinsertion f\u2081 f\u2082)\n  (gi : galois_insertion g\u2082 g\u2081)\n  (hf : \u2200 a, f\u2081 (f\u2082 a) = a \u2293 K)\n  (hg : \u2200 a, g\u2081 (g\u2082 a) = a \u2294 K) :\n  well_founded ((>) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n@well_founded_lt_exact_sequence\n  (order_dual \u03b1) _ _ (order_dual \u03b3) (order_dual \u03b2) _ _\n  h\u2082 h\u2081 K g\u2081 g\u2082 f\u2081 f\u2082 gi.dual gci.dual hg hf\n\n/-- The diamond isomorphism between the intervals `[a \u2293 b, a]` and `[b, a \u2294 b]` -/\ndef inf_Icc_order_iso_Icc_sup (a b : \u03b1) : set.Icc (a \u2293 b) a \u2243o set.Icc b (a \u2294 b) :=\n{ to_fun := \u03bb x, \u27e8x \u2294 b, \u27e8le_sup_right, sup_le_sup_right x.prop.2 b\u27e9\u27e9,\n  inv_fun := \u03bb x, \u27e8a \u2293 x, \u27e8inf_le_inf_left a x.prop.1, inf_le_left\u27e9\u27e9,\n  left_inv := \u03bb x, subtype.ext (by { change a \u2293 (\u2191x \u2294 b) = \u2191x,\n    rw [sup_comm, \u2190 inf_sup_assoc_of_le _ x.prop.2, sup_eq_right.2 x.prop.1] }),\n  right_inv := \u03bb x, subtype.ext (by { change a \u2293 \u2191x \u2294 b = \u2191x,\n    rw [inf_comm, inf_sup_assoc_of_le _ x.prop.1, inf_eq_left.2 x.prop.2] }),\n  map_rel_iff' := \u03bb x y, begin\n    simp only [subtype.mk_le_mk, equiv.coe_fn_mk, and_true, le_sup_right],\n    rw [\u2190 subtype.coe_le_coe],\n    refine \u27e8\u03bb h, _, \u03bb h, sup_le_sup_right h _\u27e9,\n    rw [\u2190 sup_eq_right.2 x.prop.1, inf_sup_assoc_of_le _ x.prop.2, sup_comm,\n      \u2190 sup_eq_right.2 y.prop.1, inf_sup_assoc_of_le _ y.prop.2, @sup_comm _ _ b],\n    exact inf_le_inf_left _ h\n  end }\nend is_modular_lattice\n\nnamespace is_compl\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_modular_lattice \u03b1]\n\n/-- The diamond isomorphism between the intervals `set.Iic a` and `set.Ici b`. -/\ndef Iic_order_iso_Ici {a b : \u03b1} (h : is_compl a b) : set.Iic a \u2243o set.Ici b :=\n(order_iso.set_congr (set.Iic a) (set.Icc (a \u2293 b) a) (h.inf_eq_bot.symm \u25b8 set.Icc_bot.symm)).trans $\n  (inf_Icc_order_iso_Icc_sup a b).trans\n  (order_iso.set_congr (set.Icc b (a \u2294 b)) (set.Ici b) (h.sup_eq_top.symm \u25b8 set.Icc_top))\n\nend is_compl\n\ntheorem is_modular_lattice_iff_inf_sup_inf_assoc [lattice \u03b1] :\n  is_modular_lattice \u03b1 \u2194 \u2200 (x y z : \u03b1), (x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z :=\n\u27e8\u03bb h, @is_modular_lattice.inf_sup_inf_assoc _ _ h, \u03bb h, \u27e8\u03bb x y z xz, by rw [\u2190 inf_eq_left.2 xz, h]\u27e9\u27e9\n\nnamespace distrib_lattice\n\n@[priority 100]\ninstance [distrib_lattice \u03b1] : is_modular_lattice \u03b1 :=\n\u27e8\u03bb x y z xz, by rw [inf_sup_right, inf_eq_left.2 xz]\u27e9\n\nend distrib_lattice\n\ntheorem disjoint.disjoint_sup_right_of_disjoint_sup_left\n  [lattice \u03b1] [bounded_order \u03b1] [is_modular_lattice \u03b1] {a b c : \u03b1}\n  (h : disjoint a b) (hsup : disjoint (a \u2294 b) c) :\n  disjoint a (b \u2294 c) :=\nbegin\n  rw [disjoint, \u2190 h.eq_bot, sup_comm],\n  apply le_inf inf_le_left,\n  apply (inf_le_inf_right (c \u2294 b) le_sup_right).trans,\n  rw [sup_comm, is_modular_lattice.sup_inf_sup_assoc, hsup.eq_bot, bot_sup_eq]\nend\n\ntheorem disjoint.disjoint_sup_left_of_disjoint_sup_right\n  [lattice \u03b1] [bounded_order \u03b1] [is_modular_lattice \u03b1] {a b c : \u03b1}\n  (h : disjoint b c) (hsup : disjoint a (b \u2294 c)) :\n  disjoint (a \u2294 b) c :=\nbegin\n  rw [disjoint.comm, sup_comm],\n  apply disjoint.disjoint_sup_right_of_disjoint_sup_left h.symm,\n  rwa [sup_comm, disjoint.comm] at hsup,\nend\n\nnamespace is_modular_lattice\n\nvariables [lattice \u03b1] [is_modular_lattice \u03b1] {a : \u03b1}\n\ninstance is_modular_lattice_Iic : is_modular_lattice (set.Iic a) :=\n\u27e8\u03bb x y z xz, (sup_inf_le_assoc_of_le (y : \u03b1) xz : (\u2191x \u2294 \u2191y) \u2293 \u2191z \u2264 \u2191x \u2294 \u2191y \u2293 \u2191z)\u27e9\n\ninstance is_modular_lattice_Ici : is_modular_lattice (set.Ici a) :=\n\u27e8\u03bb x y z xz, (sup_inf_le_assoc_of_le (y : \u03b1) xz : (\u2191x \u2294 \u2191y) \u2293 \u2191z \u2264 \u2191x \u2294 \u2191y \u2293 \u2191z)\u27e9\n\nsection is_complemented\nvariables [bounded_order \u03b1] [is_complemented \u03b1]\n\ninstance is_complemented_Iic : is_complemented (set.Iic a) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, let \u27e8y, hy\u27e9 := exists_is_compl x in\n  \u27e8\u27e8y \u2293 a, set.mem_Iic.2 inf_le_right\u27e9, begin\n    split,\n    { change x \u2293 (y \u2293 a) \u2264 \u22a5, -- improve lattice subtype API\n      rw \u2190 inf_assoc,\n      exact le_trans inf_le_left hy.1 },\n    { change a \u2264 x \u2294 (y \u2293 a), -- improve lattice subtype API\n      rw [\u2190 sup_inf_assoc_of_le _ (set.mem_Iic.1 hx), top_le_iff.1 hy.2, top_inf_eq] }\n  end\u27e9\u27e9\n\ninstance is_complemented_Ici : is_complemented (set.Ici a) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, let \u27e8y, hy\u27e9 := exists_is_compl x in\n  \u27e8\u27e8y \u2294 a, set.mem_Ici.2 le_sup_right\u27e9, begin\n    split,\n    { change x \u2293 (y \u2294 a) \u2264 a, -- improve lattice subtype API\n      rw [\u2190 inf_sup_assoc_of_le _ (set.mem_Ici.1 hx),  le_bot_iff.1 hy.1, bot_sup_eq] },\n    { change \u22a4 \u2264 x \u2294 (y \u2294 a), -- improve lattice subtype API\n      rw \u2190 sup_assoc,\n      exact le_trans hy.2 le_sup_left }\n  end\u27e9\u27e9\n\nend is_complemented\n\nend is_modular_lattice\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/order/modular_lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7186066378121223}}
{"text": "import data.nat.prime\nimport tactic.norm_num\nimport data.list.basic\nopen nat\nopen list\n\ntheorem prime_prod: \u2200x:\u2115,1\u2264x\u2192\u2203L:list \u2115,(\u2200p:\u2115,p \u2208 L\u2192prime p)\u2227prod L=x:=begin\n    have Hstrong:\u2200 y x:\u2115,x\u2264y\u21921\u2264x\u2192\u2203L:list \u2115,(\u2200p:\u2115,p \u2208 L\u2192prime p)\u2227prod L=x:=begin\n        intro,induction y with y1 Hiy,\n        intros,rw eq_zero_of_le_zero a at a_1,revert a_1,norm_num,intros,\n        cases x with x1,revert a_1,norm_num,\n        cases x1 with x2,existsi nil,norm_num,\n        cases classical.em (prime (succ(succ x2))) with A A,\n        existsi ([succ (succ x2)]),norm_num,exact A,\n        have H:=exists_dvd_of_not_prime2 (dec_trivial:2\u2264succ(succ x2)) A,\n        cases H with b Hb,cases Hb with Hbd Hb,cases Hb with Hb2 Hbx,\n        have H:=exists_eq_mul_right_of_dvd Hbd,cases H with c Hbc,rw eq_comm at Hbc,\n        have H3:=succ_ne_zero (succ x2),rw \u2190Hbc at H3,\n        have H2:= iff.elim_right pos_iff_ne_zero (ne_zero_of_mul_ne_zero_left H3),\n        have H1:=iff.elim_right (lt_mul_iff_one_lt_left (iff.elim_right pos_iff_ne_zero (ne_zero_of_mul_ne_zero_left H3))) (lt_of_lt_of_le (dec_trivial:1<2) Hb2),rw Hbc at H1,\n        cases Hiy b (le_of_succ_le_succ (le_trans (succ_le_of_lt Hbx) a)) (le_trans (dec_trivial:1\u22642) Hb2) with B HB,\n        cases Hiy c (le_of_succ_le_succ (le_trans (succ_le_of_lt H1) a)) (succ_le_of_lt H2) with C HC,existsi B++C,norm_num,intros,apply and.intro,\n        rwa [and.right HB,and.right HC],intros,cases a_2,exact and.left HB p a_2,exact and.left HC p a_2,\n    end,exact \u03bb x,Hstrong x x (le_refl x),\nend \ntheorem bezout: \u2200 b c:\u2115,\u2203x y:\u2124, \u2191b*x+\u2191c*y = \u2191(gcd b c):=begin\n    assume b c,apply gcd.induction b c,\n    simp [gcd],intro,existsi (1:\u2124),simp,\n    assume m n Hm,assume Hmn,cases Hmn with x1 Hx,cases Hx with y1 Hxy,\n    cases m with m,simp [lt_irrefl] at Hm,revert Hm,trivial,\n    unfold gcd,rw \u2190Hxy,existsi -\u2191(n/succ m)*x1+y1,existsi x1,\n    have H: n%succ m=n-(succ m)*(n/(succ m)):=begin rw [eq_comm,nat.sub_eq_iff_eq_add,mod_add_div n (succ m)],rw mul_comm,exact div_mul_le_self n (succ m) end,rw H,\n    rw [int.coe_nat_sub,mul_add,add_assoc,add_comm (\u2191(succ m) * y1) (\u2191n * x1),\u2190add_assoc,add_right_cancel_iff,mul_sub_right_distrib,int.coe_nat_mul],norm_num,\n    rw mul_comm,exact div_mul_le_self n (succ m),\nend\ntheorem euclid: \u2200b c p:\u2115, prime p \u2192 p \u2223 (b*c) \u2192 p \u2223 b \u2228 p \u2223 c:=begin\n    assume b c p Hp Hpbc,unfold prime at Hp,\n    cases(and.right Hp (gcd c p) (and.right (gcd_dvd c p))) with A A,\n    cases (bezout c p)with x H,cases H with y H,rw A at H,\n    have H1:\u2191(b*c)*x+\u2191(p*b)*y=\u2191b:=by{have H:\u2191b*\u2191c*x+\u2191b*\u2191p*y=\u2191b*\u21911:=by{rw[\u2190H,mul_add],norm_num},simp at H,rw\u2190H,norm_num},left,\n    have H2:=dvd_mul_of_dvd_left (iff.elim_right int.coe_nat_dvd Hpbc) x,\n    have H3:=dvd_mul_of_dvd_left (iff.elim_right int.coe_nat_dvd (dvd_mul_of_dvd_left (dvd_refl p) b)) y,\n    have H4:=dvd_add H2 H3,rw H1 at H4,rwa \u2190int.coe_nat_dvd,right,rw \u2190A,\n    exact and.left (gcd_dvd c p),\nend\ntheorem prod_dvd: \u2200 (p:\u2115) (L:list \u2115),p\u2208L\u2192 p \u2223 prod L:=begin\n    assume p L,revert p,\n    induction L with p1 L1 HiL,\n        norm_num,\n        exact \u03bb p2 Hp, dvd_mul_of_dvd_right (HiL p2 Hp) p1,\nend\ntheorem list_reorder: \u2200 (B:list \u2115) (p:\u2115),p\u2208 B\u2192 (\u2200x:\u2115,x\u2208B\u2192prime x)\u2192 \u2203 B2:list \u2115,(prod B=prod (p::B2)\u2227(\u2200x:\u2115,x\u2208 B2\u2192 prime x)\u2227(\u2200 x:\u2115,count x B = count x (p::B2))):=begin\n    assume B1,induction B1 with p1 B3 Hi,\n    simp,assume p2 Hp,\n    have H:p2 = p1 \u2228 p2 \u2208 B3:=by{revert Hp,norm_num},\n    cases H with A A,\n    assume H2,existsi B3,rw A,\n    apply and.intro,trivial,\n    revert H2,norm_num,\n\n    assume H6 H7, cases (Hi p2 A H7) with C HC,\n    existsi (p1::C:list \u2115),\n    rw prod_cons at HC,simp [prod_cons],rw and.left HC,\n    apply and.intro,assumption,\n\n    apply and.intro,exact and.left (and.right HC),\n    apply and.intro,simp,\n    assume x,\n    have listcount1:\u2200 B:list \u2115,\u2200 x y1 y2:\u2115, count x (y1::y2::B) = count x (y2::y1::B):=begin\n        assume B x y1 y2,\n        unfold count countp,\n        cases classical.em (x=y1) with H H,\n        cases classical.em (x=y2) with H1 H1,\n        simp [H,H1],rw H at H1,simp [H1], simp [H,H1],\n        cases classical.em (x=y2) with H1 H1,simp[H1,H],simp[H,H1],\n    end,rw listcount1 C x p2 p1,\n    cases classical.em (x=p1) with A A,\n    rw [A,count_cons_self,count_cons_self],\n    rw and.right (and.right HC) p1,\n    rw [count_cons_of_ne A,count_cons_of_ne A],\n    rw and.right (and.right HC) x,\nend\ntheorem prime_prod_dvd: \u2200 (B:list \u2115)(p:\u2115),prime p\u2192(\u2200pB, pB \u2208 B \u2192 prime pB)\u2192p \u2223 prod B \u2192 p \u2208 B:=begin\n    assume B,\n    induction B with p1 B1 Hi,\n    rw prod_nil,assume p Hp H H2,exfalso,revert H2,\n    exact prime.not_dvd_one Hp,\n    assume p2 Hp2 H H1,\n    norm_num,\n    rw prod_cons at H1,\n    have H2:=euclid p1 (prod B1) p2 Hp2 H1,\n    cases H2 with A A,\n    left,\n    have H3:=H p1,\n    revert H3,norm_num,assume H4,\n    unfold prime at H4,\n    have H5:=and.right H4 p2 A,\n    have H6:\u00acp2=1:=begin unfold prime at Hp2,intro,rw a at Hp2,simp at Hp2,revert Hp2,exact dec_trivial,end,\n    simp [H6] at H5,assumption,\n    right,\n    have H3:(\u2200 (pB : \u2115), pB \u2208 B1 \u2192 prime pB):=begin revert H, norm_num,end,have H2:= Hi p2 Hp2 H3 A,assumption,\nend\ntheorem  unique_prime_factorization: \u2200 A B:list \u2115,prod A=prod B\u2192(\u2200p:\u2115, p\u2208A\u2192prime p)\u2192(\u2200 p:\u2115,p\u2208 B\u2192 prime p)\u2192\u2200 p:\u2115,count p A=count p B:=begin\n    assume A,\n    induction A with pA A Hi,\n    rw prod_nil,norm_num,\n    assume B HP HA p,\n    have H:p\u2208 B\u2192 \u00acp\u2208 B:=begin intro HpB,\n        have H1:=prod_dvd p B HpB,\n        rw \u2190HP at H1,exfalso,\n        exact prime.not_dvd_one (HA p HpB) H1,\n    end,\n    cases classical.em(count p B>0) with A A,have H09: 0<count p B:=begin revert A,norm_num,end,\n    rw count_pos at H09,exfalso, exact H H09 H09,\n    cases (eq_zero_or_pos (count p B)),rw a, exfalso, exact A a,\n\n    assume B HP HA HB,\n    rw prod_cons at HP,\n    have H8:pA \u2223 prod B:=begin\n        have H1:=dvd_mul_of_dvd_left (dvd_refl pA) (prod A),\n        rwa HP at H1,\n    end,\n    have HppA: prime pA:=begin apply HA,norm_num,  end,\n    have H9:=prime_prod_dvd B pA HppA HB H8,\n    have H10:=list_reorder B pA H9 HB,intros,\n    cases H10 with C HC,\n    rw prod_cons at HC,rw \u2190HP at HC,\n    have HpA0:pA>0:=gt_of_ge_of_gt (and.left HppA) (dec_trivial:2>0),\n    have H2:=iff.elim_left (nat.mul_left_inj HpA0) (and.left HC),\n    have H3:=\u03bb p Hp,and.left (and.right HC) p Hp,\n    have H4:=\u03bb p,and.right (and.right HC) p,\n    have H6:\u2200 (p : \u2115), p \u2208 A \u2192 prime p:=begin revert HA,norm_num, end,\n    have Hi2:= Hi C H2 H6 H3,rw H4 p,\n    cases classical.em (p=pA) with D D,rw D,\n    rw[count_cons_self,count_cons_self, Hi2 pA],\n    rw[count_cons_of_ne D,count_cons_of_ne D, Hi2 p],  \nend\ntheorem fundamental_theorem_of_arithmetic: \u2200n:\u2115,1\u2264n\u2192\u2203L:list \u2115,(\u2200p:\u2115,p\u2208L\u2192prime p)\u2227prod L=n\u2227\u2200M:list \u2115,((\u2200p:\u2115,p\u2208M\u2192prime p)\u2192prod M=n\u2192(\u2200p:\u2115,count p L=count p M)):=begin\n    assume n Hn,\n    cases (prime_prod n Hn) with L HL,\n    existsi L,\n    apply and.intro (and.left HL),\n    apply and.intro (and.right HL),\n    intros M H1 H2 p,\n    rw[eq_comm,\u2190and.right HL] at H2,\n    exact (unique_prime_factorization L) M H2 (and.left HL) H1 p,\nend\n#print axioms fundamental_theorem_of_arithmetic\n#print prod_eq_of_perm", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/natprimes_slim.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7185459057751592}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot\n-/\nimport order.filter.bases\nimport data.finset.preimage\n\n/-!\n# `at_top` and `at_bot` filters on preorded sets, monoids and groups.\n\nIn this file we define the filters\n\n* `at_top`: corresponds to `n \u2192 +\u221e`;\n* `at_bot`: corresponds to `n \u2192 -\u221e`.\n\nThen we prove many lemmas like \u201cif `f \u2192 +\u221e`, then `f \u00b1 c \u2192 +\u221e`\u201d.\n-/\n\nvariables {\u03b9 \u03b9' \u03b1 \u03b2 \u03b3 : Type*}\n\nopen set\nopen_locale classical filter big_operators\n\nnamespace filter\n/-- `at_top` is the filter representing the limit `\u2192 \u221e` on an ordered set.\n  It is generated by the collection of up-sets `{b | a \u2264 b}`.\n  (The preorder need not have a top element for this to be well defined,\n  and indeed is trivial when a top element exists.) -/\ndef at_top [preorder \u03b1] : filter \u03b1 := \u2a05 a, \ud835\udcdf (Ici a)\n\n/-- `at_bot` is the filter representing the limit `\u2192 -\u221e` on an ordered set.\n  It is generated by the collection of down-sets `{b | b \u2264 a}`.\n  (The preorder need not have a bottom element for this to be well defined,\n  and indeed is trivial when a bottom element exists.) -/\ndef at_bot [preorder \u03b1] : filter \u03b1 := \u2a05 a, \ud835\udcdf (Iic a)\n\nlemma mem_at_top [preorder \u03b1] (a : \u03b1) : {b : \u03b1 | a \u2264 b} \u2208 @at_top \u03b1 _ :=\nmem_infi_of_mem a $ subset.refl _\n\nlemma Ici_mem_at_top [preorder \u03b1] (a : \u03b1) : Ici a \u2208 (at_top : filter \u03b1) := mem_at_top a\n\nlemma Ioi_mem_at_top [preorder \u03b1] [no_max_order \u03b1] (x : \u03b1) : Ioi x \u2208 (at_top : filter \u03b1) :=\nlet \u27e8z, hz\u27e9 := exists_gt x in mem_of_superset (mem_at_top z) $ \u03bb y h,  lt_of_lt_of_le hz h\n\nlemma mem_at_bot [preorder \u03b1] (a : \u03b1) : {b : \u03b1 | b \u2264 a} \u2208 @at_bot \u03b1 _ :=\nmem_infi_of_mem a $ subset.refl _\n\nlemma Iio_mem_at_bot [preorder \u03b1] [no_min_order \u03b1] (x : \u03b1) : Iio x \u2208 (at_bot : filter \u03b1) :=\nlet \u27e8z, hz\u27e9 := exists_lt x in mem_of_superset (mem_at_bot z) $ \u03bb y h, lt_of_le_of_lt h hz\n\nlemma at_top_basis [nonempty \u03b1] [semilattice_sup \u03b1] :\n  (@at_top \u03b1 _).has_basis (\u03bb _, true) Ici :=\nhas_basis_infi_principal (directed_of_sup $ \u03bb a b, Ici_subset_Ici.2)\n\nlemma at_top_basis' [semilattice_sup \u03b1] (a : \u03b1) :\n  (@at_top \u03b1 _).has_basis (\u03bb x, a \u2264 x) Ici :=\n\u27e8\u03bb t, (@at_top_basis \u03b1 \u27e8a\u27e9 _).mem_iff.trans\n  \u27e8\u03bb \u27e8x, _, hx\u27e9, \u27e8x \u2294 a, le_sup_right, \u03bb y hy, hx (le_trans le_sup_left hy)\u27e9,\n    \u03bb \u27e8x, _, hx\u27e9, \u27e8x, trivial, hx\u27e9\u27e9\u27e9\n\nlemma at_bot_basis [nonempty \u03b1] [semilattice_inf \u03b1] :\n  (@at_bot \u03b1 _).has_basis (\u03bb _, true) Iic :=\n@at_top_basis (order_dual \u03b1) _ _\n\nlemma at_bot_basis' [semilattice_inf \u03b1] (a : \u03b1) :\n  (@at_bot \u03b1 _).has_basis (\u03bb x, x \u2264 a) Iic :=\n@at_top_basis' (order_dual \u03b1) _ _\n\n@[instance]\nlemma at_top_ne_bot [nonempty \u03b1] [semilattice_sup \u03b1] : ne_bot (at_top : filter \u03b1) :=\nat_top_basis.ne_bot_iff.2 $ \u03bb a _, nonempty_Ici\n\n@[instance]\nlemma at_bot_ne_bot [nonempty \u03b1] [semilattice_inf \u03b1] : ne_bot (at_bot : filter \u03b1) :=\n@at_top_ne_bot (order_dual \u03b1) _ _\n\n@[simp]\nlemma mem_at_top_sets [nonempty \u03b1] [semilattice_sup \u03b1] {s : set \u03b1} :\n  s \u2208 (at_top : filter \u03b1) \u2194 \u2203a:\u03b1, \u2200b\u2265a, b \u2208 s :=\nat_top_basis.mem_iff.trans $ exists_congr $ \u03bb _, exists_const _\n\n@[simp]\nlemma mem_at_bot_sets [nonempty \u03b1] [semilattice_inf \u03b1] {s : set \u03b1} :\n  s \u2208 (at_bot : filter \u03b1) \u2194 \u2203a:\u03b1, \u2200b\u2264a, b \u2208 s :=\n@mem_at_top_sets (order_dual \u03b1) _ _ _\n\n@[simp]\nlemma eventually_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_top, p x) \u2194 (\u2203 a, \u2200 b \u2265 a, p b) :=\nmem_at_top_sets\n\n@[simp]\nlemma eventually_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_bot, p x) \u2194 (\u2203 a, \u2200 b \u2264 a, p b) :=\nmem_at_bot_sets\n\nlemma eventually_ge_at_top [preorder \u03b1] (a : \u03b1) : \u2200\u1da0 x in at_top, a \u2264 x := mem_at_top a\n\nlemma eventually_le_at_bot [preorder \u03b1] (a : \u03b1) : \u2200\u1da0 x in at_bot, x \u2264 a := mem_at_bot a\n\nlemma eventually_gt_at_top [preorder \u03b1] [no_max_order \u03b1] (a : \u03b1) :\n  \u2200\u1da0 x in at_top, a < x :=\nIoi_mem_at_top a\n\nlemma eventually_ne_at_top [preorder \u03b1] [no_max_order \u03b1] (a : \u03b1) :\n  \u2200\u1da0 x in at_top, x \u2260 a :=\n(eventually_gt_at_top a).mono (\u03bb x hx, hx.ne.symm)\n\nlemma eventually_lt_at_bot [preorder \u03b1] [no_min_order \u03b1] (a : \u03b1) :\n  \u2200\u1da0 x in at_bot, x < a :=\nIio_mem_at_bot a\n\nlemma at_top_basis_Ioi [nonempty \u03b1] [semilattice_sup \u03b1] [no_max_order \u03b1] :\n  (@at_top \u03b1 _).has_basis (\u03bb _, true) Ioi :=\nat_top_basis.to_has_basis (\u03bb a ha, \u27e8a, ha, Ioi_subset_Ici_self\u27e9) $\n  \u03bb a ha, (exists_gt a).imp $ \u03bb b hb, \u27e8ha, Ici_subset_Ioi.2 hb\u27e9\n\nlemma at_top_countable_basis [nonempty \u03b1] [semilattice_sup \u03b1] [encodable \u03b1] :\n  has_countable_basis (at_top : filter \u03b1) (\u03bb _, true) Ici :=\n{ countable := countable_encodable _,\n  .. at_top_basis }\n\nlemma at_bot_countable_basis [nonempty \u03b1] [semilattice_inf \u03b1] [encodable \u03b1] :\n  has_countable_basis (at_bot : filter \u03b1) (\u03bb _, true) Iic :=\n{ countable := countable_encodable _,\n  .. at_bot_basis }\n\n@[priority 200]\ninstance at_top.is_countably_generated [preorder \u03b1] [encodable \u03b1] :\n  (at_top : filter $ \u03b1).is_countably_generated :=\nis_countably_generated_seq _\n\n@[priority 200]\ninstance at_bot.is_countably_generated [preorder \u03b1] [encodable \u03b1] :\n  (at_bot : filter $ \u03b1).is_countably_generated :=\nis_countably_generated_seq _\n\nlemma order_top.at_top_eq (\u03b1) [partial_order \u03b1] [order_top \u03b1] : (at_top : filter \u03b1) = pure \u22a4 :=\nle_antisymm (le_pure_iff.2 $ (eventually_ge_at_top \u22a4).mono $ \u03bb b, top_unique)\n  (le_infi $ \u03bb b, le_principal_iff.2 le_top)\n\n\n\n@[nontriviality]\nlemma subsingleton.at_top_eq (\u03b1) [subsingleton \u03b1] [preorder \u03b1] : (at_top : filter \u03b1) = \u22a4 :=\nbegin\n  refine top_unique (\u03bb s hs x, _),\n  letI : unique \u03b1 := \u27e8\u27e8x\u27e9, \u03bb y, subsingleton.elim y x\u27e9,\n  rw [at_top, infi_unique, unique.default_eq x, mem_principal] at hs,\n  exact hs left_mem_Ici\nend\n\n@[nontriviality]\nlemma subsingleton.at_bot_eq (\u03b1) [subsingleton \u03b1] [preorder \u03b1] : (at_bot : filter \u03b1) = \u22a4 :=\n@subsingleton.at_top_eq (order_dual \u03b1) _ _\n\nlemma tendsto_at_top_pure [partial_order \u03b1] [order_top \u03b1] (f : \u03b1 \u2192 \u03b2) :\n  tendsto f at_top (pure $ f \u22a4) :=\n(order_top.at_top_eq \u03b1).symm \u25b8 tendsto_pure_pure _ _\n\nlemma tendsto_at_bot_pure [partial_order \u03b1] [order_bot \u03b1] (f : \u03b1 \u2192 \u03b2) :\n  tendsto f at_bot (pure $ f \u22a5) :=\n@tendsto_at_top_pure (order_dual \u03b1) _ _ _ _\n\nlemma eventually.exists_forall_of_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2200\u1da0 x in at_top, p x) : \u2203 a, \u2200 b \u2265 a, p b :=\neventually_at_top.mp h\n\nlemma eventually.exists_forall_of_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2200\u1da0 x in at_bot, p x) : \u2203 a, \u2200 b \u2264 a, p b :=\neventually_at_bot.mp h\n\nlemma frequently_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_top, p x) \u2194 (\u2200 a, \u2203 b \u2265 a, p b) :=\nby simp [at_top_basis.frequently_iff]\n\nlemma frequently_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_bot, p x) \u2194 (\u2200 a, \u2203 b \u2264 a, p b) :=\n@frequently_at_top (order_dual \u03b1) _ _ _\n\nlemma frequently_at_top' [semilattice_sup \u03b1] [nonempty \u03b1] [no_max_order \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_top, p x) \u2194 (\u2200 a, \u2203 b > a, p b) :=\nby simp [at_top_basis_Ioi.frequently_iff]\n\nlemma frequently_at_bot' [semilattice_inf \u03b1] [nonempty \u03b1] [no_min_order \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_bot, p x) \u2194 (\u2200 a, \u2203 b < a, p b) :=\n@frequently_at_top' (order_dual \u03b1) _ _ _ _\n\nlemma frequently.forall_exists_of_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2203\u1da0 x in at_top, p x) : \u2200 a, \u2203 b \u2265 a, p b :=\nfrequently_at_top.mp h\n\nlemma frequently.forall_exists_of_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2203\u1da0 x in at_bot, p x) : \u2200 a, \u2203 b \u2264 a, p b :=\nfrequently_at_bot.mp h\n\nlemma map_at_top_eq [nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} :\n  at_top.map f = (\u2a05a, \ud835\udcdf $ f '' {a' | a \u2264 a'}) :=\n(at_top_basis.map _).eq_infi\n\nlemma map_at_bot_eq [nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2} :\n  at_bot.map f = (\u2a05a, \ud835\udcdf $ f '' {a' | a' \u2264 a}) :=\n@map_at_top_eq (order_dual \u03b1) _ _ _ _\n\nlemma tendsto_at_top [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n  tendsto m f at_top \u2194 (\u2200b, \u2200\u1da0 a in f, b \u2264 m a) :=\nby simp only [at_top, tendsto_infi, tendsto_principal, mem_Ici]\n\nlemma tendsto_at_bot [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n  tendsto m f at_bot \u2194 (\u2200b, \u2200\u1da0 a in f, m a \u2264 b) :=\n@tendsto_at_top \u03b1 (order_dual \u03b2) _ m f\n\nlemma tendsto_at_top_mono' [preorder \u03b2] (l : filter \u03b1) \u2983f\u2081 f\u2082 : \u03b1 \u2192 \u03b2\u2984 (h : f\u2081 \u2264\u1da0[l] f\u2082) :\n  tendsto f\u2081 l at_top \u2192 tendsto f\u2082 l at_top :=\nassume h\u2081, tendsto_at_top.2 $ \u03bb b, mp_mem (tendsto_at_top.1 h\u2081 b)\n  (monotone_mem (\u03bb a ha ha\u2081, le_trans ha\u2081 ha) h)\n\nlemma tendsto_at_bot_mono' [preorder \u03b2] (l : filter \u03b1) \u2983f\u2081 f\u2082 : \u03b1 \u2192 \u03b2\u2984 (h : f\u2081 \u2264\u1da0[l] f\u2082) :\n  tendsto f\u2082 l at_bot \u2192 tendsto f\u2081 l at_bot :=\n@tendsto_at_top_mono' _ (order_dual \u03b2) _ _ _ _ h\n\nlemma tendsto_at_top_mono [preorder \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2} (h : \u2200 n, f n \u2264 g n) :\n  tendsto f l at_top \u2192 tendsto g l at_top :=\ntendsto_at_top_mono' l $ eventually_of_forall h\n\nlemma tendsto_at_bot_mono [preorder \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2} (h : \u2200 n, f n \u2264 g n) :\n  tendsto g l at_bot \u2192 tendsto f l at_bot :=\n@tendsto_at_top_mono _ (order_dual \u03b2) _ _ _ _ h\n\n/-!\n### Sequences\n-/\n\nlemma inf_map_at_top_ne_bot_iff [semilattice_sup \u03b1] [nonempty \u03b1] {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n  ne_bot (F \u2293 (map u at_top)) \u2194 \u2200 U \u2208 F, \u2200 N, \u2203 n \u2265 N, u n \u2208 U :=\nby simp_rw [inf_ne_bot_iff_frequently_left, frequently_map, frequently_at_top]; refl\n\nlemma inf_map_at_bot_ne_bot_iff [semilattice_inf \u03b1] [nonempty \u03b1] {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n  ne_bot (F \u2293 (map u at_bot)) \u2194 \u2200 U \u2208 F, \u2200 N, \u2203 n \u2264 N, u n \u2208 U :=\n@inf_map_at_top_ne_bot_iff (order_dual \u03b1) _ _ _ _ _\n\nlemma extraction_of_frequently_at_top' {P : \u2115 \u2192 Prop} (h : \u2200 N, \u2203 n > N, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nbegin\n  choose u hu using h,\n  cases forall_and_distrib.mp hu with hu hu',\n  exact \u27e8u \u2218 (nat.rec 0 (\u03bb n v, u v)), strict_mono_nat_of_lt_succ (\u03bb n, hu _), \u03bb n, hu' _\u27e9,\nend\n\nlemma extraction_of_frequently_at_top {P : \u2115 \u2192 Prop} (h : \u2203\u1da0 n in at_top, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nbegin\n  rw frequently_at_top' at h,\n  exact extraction_of_frequently_at_top' h,\nend\n\nlemma extraction_of_eventually_at_top {P : \u2115 \u2192 Prop} (h : \u2200\u1da0 n in at_top, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nextraction_of_frequently_at_top h.frequently\n\nlemma extraction_forall_of_frequently {P : \u2115 \u2192 \u2115 \u2192 Prop} (h : \u2200 n, \u2203\u1da0 k in at_top, P n k) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P n (\u03c6 n) :=\nbegin\n  simp only [frequently_at_top'] at h,\n  choose u hu hu' using h,\n  use (\u03bb n, nat.rec_on n (u 0 0) (\u03bb n v, u (n+1) v) : \u2115 \u2192 \u2115),\n  split,\n  { apply strict_mono_nat_of_lt_succ,\n    intro n,\n    apply hu },\n  { intros n,\n    cases n ; simp [hu'] },\nend\n\nlemma extraction_forall_of_eventually  {P : \u2115 \u2192 \u2115 \u2192 Prop} (h : \u2200 n, \u2200\u1da0 k in at_top, P n k) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P n (\u03c6 n) :=\nextraction_forall_of_frequently (\u03bb n, (h n).frequently)\n\nlemma extraction_forall_of_eventually' {P : \u2115 \u2192 \u2115 \u2192 Prop} (h : \u2200 n, \u2203 N, \u2200 k \u2265 N, P n k) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P n (\u03c6 n) :=\nextraction_forall_of_eventually (by simp [eventually_at_top, h])\n\nlemma exists_le_of_tendsto_at_top [semilattice_sup \u03b1] [preorder \u03b2] {u : \u03b1 \u2192 \u03b2}\n  (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) : \u2203 a' \u2265 a, b \u2264 u a' :=\nbegin\n  have : \u2200\u1da0 x in at_top, a \u2264 x \u2227 b \u2264 u x :=\n    (eventually_ge_at_top a).and (h.eventually $ eventually_ge_at_top b),\n  haveI : nonempty \u03b1 := \u27e8a\u27e9,\n  rcases this.exists with \u27e8a', ha, hb\u27e9,\n  exact \u27e8a', ha, hb\u27e9\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_le_of_tendsto_at_bot [semilattice_sup \u03b1] [preorder \u03b2] {u : \u03b1 \u2192 \u03b2}\n  (h : tendsto u at_top at_bot) : \u2200 a b, \u2203 a' \u2265 a, u a' \u2264 b :=\n@exists_le_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ h\n\nlemma exists_lt_of_tendsto_at_top [semilattice_sup \u03b1] [preorder \u03b2] [no_max_order \u03b2]\n  {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) : \u2203 a' \u2265 a, b < u a' :=\nbegin\n  cases exists_gt b with b' hb',\n  rcases exists_le_of_tendsto_at_top h a b' with \u27e8a', ha', ha''\u27e9,\n  exact \u27e8a', ha', lt_of_lt_of_le hb' ha''\u27e9\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_lt_of_tendsto_at_bot [semilattice_sup \u03b1] [preorder \u03b2] [no_min_order \u03b2]\n  {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_bot) : \u2200 a b, \u2203 a' \u2265 a, u a' < b :=\n@exists_lt_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ _ h\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen after any point, it reaches a value strictly greater than all previous values.\n-/\nlemma high_scores [linear_order \u03b2] [no_max_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_top) : \u2200 N, \u2203 n \u2265 N, \u2200 k < n, u k < u n :=\nbegin\n  intros N,\n  obtain \u27e8k : \u2115, hkn : k \u2264 N, hku : \u2200 l \u2264 N, u l \u2264 u k\u27e9 : \u2203 k \u2264 N, \u2200 l \u2264 N, u l \u2264 u k,\n    from exists_max_image _ u (finite_le_nat N) \u27e8N, le_refl N\u27e9,\n  have ex : \u2203 n \u2265 N, u k < u n,\n    from exists_lt_of_tendsto_at_top hu _ _,\n  obtain \u27e8n : \u2115, hnN : n \u2265 N, hnk : u k < u n, hn_min : \u2200 m, m < n \u2192 N \u2264 m \u2192 u m \u2264 u k\u27e9 :\n    \u2203 n \u2265 N, u k < u n \u2227 \u2200 m, m < n \u2192 N \u2264 m \u2192 u m \u2264 u k,\n  { rcases nat.find_x ex with \u27e8n, \u27e8hnN, hnk\u27e9, hn_min\u27e9,\n    push_neg at hn_min,\n    exact \u27e8n, hnN, hnk, hn_min\u27e9 },\n  use [n, hnN],\n  rintros (l : \u2115) (hl : l < n),\n  have hlk : u l \u2264 u k,\n  { cases (le_total l N : l \u2264 N \u2228 N \u2264 l) with H H,\n    { exact hku l H },\n    { exact hn_min l hl H } },\n  calc u l \u2264 u k : hlk\n       ... < u n : hnk\nend\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen after any point, it reaches a value strictly smaller than all previous values.\n-/\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma low_scores [linear_order \u03b2] [no_min_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_bot) : \u2200 N, \u2203 n \u2265 N, \u2200 k < n, u n < u k :=\n@high_scores (order_dual \u03b2) _ _ _ hu\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen it `frequently` reaches a value strictly greater than all previous values.\n-/\nlemma frequently_high_scores [linear_order \u03b2] [no_max_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_top) : \u2203\u1da0 n in at_top, \u2200 k < n, u k < u n :=\nby simpa [frequently_at_top] using high_scores hu\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen it `frequently` reaches a value strictly smaller than all previous values.\n-/\nlemma frequently_low_scores [linear_order \u03b2] [no_min_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_bot) : \u2203\u1da0 n in at_top, \u2200 k < n, u n < u k :=\n@frequently_high_scores (order_dual \u03b2) _ _ _ hu\n\nlemma strict_mono_subseq_of_tendsto_at_top\n  {\u03b2 : Type*} [linear_order \u03b2] [no_max_order \u03b2]\n  {u : \u2115 \u2192 \u03b2} (hu : tendsto u at_top at_top) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\nlet \u27e8\u03c6, h, h'\u27e9 := extraction_of_frequently_at_top (frequently_high_scores hu) in\n\u27e8\u03c6, h, \u03bb n m hnm, h' m _ (h hnm)\u27e9\n\nlemma strict_mono_subseq_of_id_le {u : \u2115 \u2192 \u2115} (hu : \u2200 n, n \u2264 u n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\nstrict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono hu tendsto_id)\n\nlemma _root_.strict_mono.tendsto_at_top {\u03c6 : \u2115 \u2192 \u2115} (h : strict_mono \u03c6) :\n  tendsto \u03c6 at_top at_top :=\ntendsto_at_top_mono h.id_le tendsto_id\n\nsection ordered_add_comm_monoid\n\nvariables [ordered_add_comm_monoid \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_add_nonneg_left' (hf : \u2200\u1da0 x in l, 0 \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (hf.mono (\u03bb x, le_add_of_nonneg_left)) hg\n\nlemma tendsto_at_bot_add_nonpos_left' (hf : \u2200\u1da0 x in l, f x \u2264 0) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left' _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_left (hf : \u2200 x, 0 \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_left' (eventually_of_forall hf) hg\n\nlemma tendsto_at_bot_add_nonpos_left (hf : \u2200 x, f x \u2264 0) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right' (hf : tendsto f l at_top) (hg : \u2200\u1da0 x in l, 0 \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (monotone_mem (\u03bb x, le_add_of_nonneg_right) hg) hf\n\nlemma tendsto_at_bot_add_nonpos_right' (hf : tendsto f l at_bot) (hg : \u2200\u1da0 x in l, g x \u2264 0) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right' _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right (hf : tendsto f l at_top) (hg : \u2200 x, 0 \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_right' hf (eventually_of_forall hg)\n\nlemma tendsto_at_bot_add_nonpos_right (hf : tendsto f l at_bot) (hg : \u2200 x, g x \u2264 0) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_left' (tendsto_at_top.mp hf 0) hg\n\nlemma tendsto_at_bot_add (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto.nsmul_at_top (hf : tendsto f l at_top) {n : \u2115} (hn : 0 < n) :\n  tendsto (\u03bb x, n \u2022 f x) l at_top :=\ntendsto_at_top.2 $ \u03bb y, (tendsto_at_top.1 hf y).mp $ (tendsto_at_top.1 hf 0).mono $ \u03bb x h\u2080 hy,\ncalc y \u2264 f x : hy\n... = 1 \u2022 f x : (one_nsmul _).symm\n... \u2264  n \u2022 f x : nsmul_le_nsmul h\u2080 hn\n\nlemma tendsto.nsmul_at_bot (hf : tendsto f l at_bot) {n : \u2115} (hn : 0 < n) :\n  tendsto (\u03bb x, n \u2022 f x) l at_bot :=\n@tendsto.nsmul_at_top \u03b1 (order_dual \u03b2) _ l f hf n hn\n\nlemma tendsto_bit0_at_top : tendsto bit0 (at_top : filter \u03b2) at_top :=\ntendsto_at_top_add tendsto_id tendsto_id\n\nlemma tendsto_bit0_at_bot : tendsto bit0 (at_bot : filter \u03b2) at_bot :=\ntendsto_at_bot_add tendsto_id tendsto_id\n\nend ordered_add_comm_monoid\n\nsection ordered_cancel_add_comm_monoid\n\nvariables [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_of_add_const_left (C : \u03b2) (hf : tendsto (\u03bb x, C + f x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (C + b)).mono (\u03bb x, le_of_add_le_add_left)\n\nlemma tendsto_at_bot_of_add_const_left (C : \u03b2) (hf : tendsto (\u03bb x, C + f x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_left _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_of_add_const_right (C : \u03b2) (hf : tendsto (\u03bb x, f x + C) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (b + C)).mono (\u03bb x, le_of_add_le_add_right)\n\nlemma tendsto_at_bot_of_add_const_right (C : \u03b2) (hf : tendsto (\u03bb x, f x + C) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_right _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_of_add_bdd_above_left' (C) (hC : \u2200\u1da0 x in l, f x \u2264 C)\n  (h : tendsto (\u03bb x, f x + g x) l at_top) :\n  tendsto g l at_top :=\ntendsto_at_top_of_add_const_left C\n  (tendsto_at_top_mono' l (hC.mono (\u03bb x hx, add_le_add_right hx (g x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_left' (C) (hC : \u2200\u1da0 x in l, C \u2264 f x)\n  (h : tendsto (\u03bb x, f x + g x) l at_bot) :\n  tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left' _ (order_dual \u03b2) _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_left (C) (hC : \u2200 x, f x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_top \u2192 tendsto g l at_top :=\ntendsto_at_top_of_add_bdd_above_left' C (univ_mem' hC)\n\nlemma tendsto_at_bot_of_add_bdd_below_left (C) (hC : \u2200 x, C \u2264 f x) :\n  tendsto (\u03bb x, f x + g x) l at_bot \u2192 tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left _ (order_dual \u03b2) _ _ _ _ C hC\n\nlemma tendsto_at_top_of_add_bdd_above_right' (C) (hC : \u2200\u1da0 x in l, g x \u2264 C)\n  (h : tendsto (\u03bb x, f x + g x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top_of_add_const_right C\n  (tendsto_at_top_mono' l (hC.mono (\u03bb x hx, add_le_add_left hx (f x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_right' (C) (hC : \u2200\u1da0 x in l, C \u2264 g x)\n  (h : tendsto (\u03bb x, f x + g x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right' _ (order_dual \u03b2) _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_right (C) (hC : \u2200 x, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_top \u2192 tendsto f l at_top :=\ntendsto_at_top_of_add_bdd_above_right' C (univ_mem' hC)\n\nlemma tendsto_at_bot_of_add_bdd_below_right (C) (hC : \u2200 x, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_bot \u2192 tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right _ (order_dual \u03b2) _ _ _ _ C hC\n\nend ordered_cancel_add_comm_monoid\n\nsection ordered_group\n\nvariables [ordered_add_comm_group \u03b2] (l : filter \u03b1) {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_add_left_of_le' (C : \u03b2) (hf : \u2200\u1da0 x in l, C \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_left' _ _ _ l (\u03bb x, -(f x)) (\u03bb x, f x + g x) (-C)\n  (by simpa) (by simpa)\n\nlemma tendsto_at_bot_add_left_of_ge' (C : \u03b2) (hf : \u2200\u1da0 x in l, f x \u2264 C) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le' _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_left_of_le (C : \u03b2) (hf : \u2200 x, C \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_left_of_le' l C (univ_mem' hf) hg\n\nlemma tendsto_at_bot_add_left_of_ge (C : \u03b2) (hf : \u2200 x, f x \u2264 C) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le' (C : \u03b2) (hf : tendsto f l at_top) (hg : \u2200\u1da0 x in l, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_right' _ _ _ l (\u03bb x, f x + g x) (\u03bb x, -(g x)) (-C)\n  (by simp [hg]) (by simp [hf])\n\nlemma tendsto_at_bot_add_right_of_ge' (C : \u03b2) (hf : tendsto f l at_bot) (hg : \u2200\u1da0 x in l, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le' _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le (C : \u03b2) (hf : tendsto f l at_top) (hg : \u2200 x, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_right_of_le' l C hf (univ_mem' hg)\n\nlemma tendsto_at_bot_add_right_of_ge (C : \u03b2) (hf : tendsto f l at_bot) (hg : \u2200 x, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_const_left (C : \u03b2) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, C + f x) l at_top :=\ntendsto_at_top_add_left_of_le' l C (univ_mem' $ \u03bb _, le_refl C) hf\n\nlemma tendsto_at_bot_add_const_left (C : \u03b2) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, C + f x) l at_bot :=\n@tendsto_at_top_add_const_left _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_add_const_right (C : \u03b2) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, f x + C) l at_top :=\ntendsto_at_top_add_right_of_le' l C hf (univ_mem' $ \u03bb _, le_refl C)\n\nlemma tendsto_at_bot_add_const_right (C : \u03b2) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, f x + C) l at_bot :=\n@tendsto_at_top_add_const_right _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_neg_at_top_at_bot : tendsto (has_neg.neg : \u03b2 \u2192 \u03b2) at_top at_bot :=\nbegin\n  simp only [tendsto_at_bot, neg_le],\n  exact \u03bb b, eventually_ge_at_top _\nend\n\nlemma tendsto_neg_at_bot_at_top : tendsto (has_neg.neg : \u03b2 \u2192 \u03b2) at_bot at_top :=\n@tendsto_neg_at_top_at_bot (order_dual \u03b2) _\n\nend ordered_group\n\nsection ordered_semiring\n\nvariables [ordered_semiring \u03b1] {l : filter \u03b2} {f g : \u03b2 \u2192 \u03b1}\n\nlemma tendsto_bit1_at_top : tendsto bit1 (at_top : filter \u03b1) at_top :=\ntendsto_at_top_add_nonneg_right tendsto_bit0_at_top (\u03bb _, zero_le_one)\n\nlemma tendsto.at_top_mul_at_top (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x * g x) l at_top :=\nbegin\n  refine tendsto_at_top_mono' _ _ hg,\n  filter_upwards [hg.eventually (eventually_ge_at_top 0), hf.eventually (eventually_ge_at_top 1)]\n    with _ using le_mul_of_one_le_left,\nend\n\nlemma tendsto_mul_self_at_top : tendsto (\u03bb x : \u03b1, x * x) at_top at_top :=\ntendsto_id.at_top_mul_at_top tendsto_id\n\n/-- The monomial function `x^n` tends to `+\u221e` at `+\u221e` for any positive natural `n`.\nA version for positive real powers exists as `tendsto_rpow_at_top`. -/\nlemma tendsto_pow_at_top {n : \u2115} (hn : 1 \u2264 n) : tendsto (\u03bb x : \u03b1, x ^ n) at_top at_top :=\nbegin\n  refine tendsto_at_top_mono' _ ((eventually_ge_at_top 1).mono $ \u03bb x hx, _) tendsto_id,\n  simpa only [pow_one] using pow_le_pow hx hn\nend\n\nlemma eventually_ne_of_tendsto_at_top [nontrivial \u03b1] (hf : tendsto f l at_top)\n  (c : \u03b1) :  \u2200\u1da0 x in l, f x \u2260 c :=\n(tendsto_at_top.1 hf $ (c + 1)).mono (\u03bb x hx, ne_of_gt (lt_of_lt_of_le (lt_add_one c) hx))\n\nend ordered_semiring\n\nlemma zero_pow_eventually_eq [monoid_with_zero \u03b1] :\n  (\u03bb n : \u2115, (0 : \u03b1) ^ n) =\u1da0[at_top] (\u03bb n, 0) :=\neventually_at_top.2 \u27e81, \u03bb n hn, zero_pow (zero_lt_one.trans_le hn)\u27e9\n\nsection ordered_ring\n\nvariables [ordered_ring \u03b1] {l : filter \u03b2} {f g : \u03b2 \u2192 \u03b1}\n\nlemma eventually_ne_of_tendsto_at_bot [nontrivial \u03b1] (hf : tendsto f l at_bot)\n  (c : \u03b1) : \u2200\u1da0 x in l, f x \u2260 c :=\n(tendsto_at_bot.1 hf $ (c - 1)).mono\n  (\u03bb x hx, ne_of_lt (lt_of_le_of_lt hx ((sub_lt_self_iff c).2 zero_lt_one)))\n\nlemma tendsto.at_top_mul_at_bot (hf : tendsto f l at_top) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x * g x) l at_bot :=\nhave _ := (hf.at_top_mul_at_top $ tendsto_neg_at_bot_at_top.comp hg),\nby simpa only [(\u2218), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp this\n\nlemma tendsto.at_bot_mul_at_top (hf : tendsto f l at_bot) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x * g x) l at_bot :=\nhave tendsto (\u03bb x, (-f x) * g x) l at_top :=\n  ( (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top hg),\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_at_top_at_bot.comp this\n\nlemma tendsto.at_bot_mul_at_bot (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x * g x) l at_top :=\nhave tendsto (\u03bb x, (-f x) * (-g x)) l at_top :=\n  (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top (tendsto_neg_at_bot_at_top.comp hg),\nby simpa only [neg_mul_neg] using this\n\nend ordered_ring\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1]\n\n/-- $\\lim_{x\\to+\\infty}|x|=+\\infty$ -/\nlemma tendsto_abs_at_top_at_top : tendsto (abs : \u03b1 \u2192 \u03b1) at_top at_top :=\ntendsto_at_top_mono le_abs_self tendsto_id\n\n/-- $\\lim_{x\\to-\\infty}|x|=+\\infty$ -/\nlemma tendsto_abs_at_bot_at_top : tendsto (abs : \u03b1 \u2192 \u03b1) at_bot at_top :=\ntendsto_at_top_mono neg_le_abs_self tendsto_neg_at_bot_at_top\n\n@[simp] lemma comap_abs_at_top : comap (abs : \u03b1 \u2192 \u03b1) at_top = at_bot \u2294 at_top :=\nbegin\n  refine le_antisymm (((at_top_basis.comap _).le_basis_iff (at_bot_basis.sup at_top_basis)).2 _)\n    (sup_le tendsto_abs_at_bot_at_top.le_comap tendsto_abs_at_top_at_top.le_comap),\n  rintro \u27e8a, b\u27e9 -,\n  refine \u27e8max (-a) b, trivial, \u03bb x hx, _\u27e9,\n  rw [mem_preimage, mem_Ici, le_abs', max_le_iff, \u2190 min_neg_neg, le_min_iff, neg_neg] at hx,\n  exact hx.imp and.left and.right\nend\n\nend linear_ordered_add_comm_group\n\nsection linear_ordered_semiring\n\nvariables [linear_ordered_semiring \u03b1] {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1}\n\nlemma tendsto.at_top_of_const_mul {c : \u03b1} (hc : 0 < c) (hf : tendsto (\u03bb x, c * f x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ \u03bb b, (tendsto_at_top.1 hf (c * b)).mono $ \u03bb x hx, le_of_mul_le_mul_left hx hc\n\nlemma tendsto.at_top_of_mul_const {c : \u03b1} (hc : 0 < c) (hf : tendsto (\u03bb x, f x * c) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ \u03bb b, (tendsto_at_top.1 hf (b * c)).mono $ \u03bb x hx, le_of_mul_le_mul_right hx hc\n\nend linear_ordered_semiring\n\nlemma nonneg_of_eventually_pow_nonneg [linear_ordered_ring \u03b1] {a : \u03b1}\n  (h : \u2200\u1da0 n in at_top, 0 \u2264 a ^ (n : \u2115)) : 0 \u2264 a :=\nlet \u27e8n, hn\u27e9 := (tendsto_bit1_at_top.eventually h).exists in pow_bit1_nonneg_iff.1 hn\n\nsection linear_ordered_field\n\nvariables [linear_ordered_field \u03b1] {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1}\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the left) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.const_mul_at_top'` instead. -/\nlemma tendsto.const_mul_at_top (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, r * f x) l at_top :=\ntendsto.at_top_of_const_mul (inv_pos.2 hr) $ by simpa only [inv_mul_cancel_left\u2080 hr.ne']\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the right) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.at_top_mul_const'` instead. -/\nlemma tendsto.at_top_mul_const (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, f x * r) l at_top :=\nby simpa only [mul_comm] using hf.const_mul_at_top hr\n\n/-- If a function tends to infinity along a filter, then this function divided by a positive\nconstant also tends to infinity. -/\nlemma tendsto.at_top_div_const (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, f x / r) l at_top :=\nby simpa only [div_eq_mul_inv] using hf.at_top_mul_const (inv_pos.2 hr)\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the left) tends to negative infinity. -/\nlemma tendsto.neg_const_mul_at_top (hr : r < 0) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, r * f x) l at_bot :=\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg]\n  using tendsto_neg_at_top_at_bot.comp (hf.const_mul_at_top (neg_pos.2 hr))\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the right) tends to negative infinity. -/\nlemma tendsto.at_top_mul_neg_const (hr : r < 0) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, f x * r) l at_bot :=\nby simpa only [mul_comm] using hf.neg_const_mul_at_top hr\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the left) also tends to negative infinity. -/\nlemma tendsto.const_mul_at_bot (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, r * f x) l at_bot :=\nby simpa only [(\u2218), neg_mul_eq_mul_neg, neg_neg]\n  using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).const_mul_at_top hr)\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the right) also tends to negative infinity. -/\nlemma tendsto.at_bot_mul_const (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, f x * r) l at_bot :=\nby simpa only [mul_comm] using hf.const_mul_at_bot hr\n\n/-- If a function tends to negative infinity along a filter, then this function divided by\na positive constant also tends to negative infinity. -/\nlemma tendsto.at_bot_div_const (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, f x / r) l at_bot :=\nby simpa only [div_eq_mul_inv] using hf.at_bot_mul_const (inv_pos.2 hr)\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the left) tends to positive infinity. -/\nlemma tendsto.neg_const_mul_at_bot (hr : r < 0) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, r * f x) l at_top :=\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg]\n  using tendsto_neg_at_bot_at_top.comp (hf.const_mul_at_bot (neg_pos.2 hr))\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the right) tends to positive infinity. -/\nlemma tendsto.at_bot_mul_neg_const (hr : r < 0) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, f x * r) l at_top :=\nby simpa only [mul_comm] using hf.neg_const_mul_at_bot hr\n\nlemma tendsto_const_mul_pow_at_top {c : \u03b1} {n : \u2115}\n  (hn : 1 \u2264 n) (hc : 0 < c) : tendsto (\u03bb x, c * x^n) at_top at_top :=\ntendsto.const_mul_at_top hc (tendsto_pow_at_top hn)\n\nlemma tendsto_const_mul_pow_at_top_iff (c : \u03b1) (n : \u2115) :\n  tendsto (\u03bb x, c * x^n) at_top at_top \u2194 1 \u2264 n \u2227 0 < c :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, tendsto_const_mul_pow_at_top h.1 h.2\u27e9,\n  simp only [tendsto_at_top, eventually_at_top] at h,\n  have : 0 < c := let \u27e8x, hx\u27e9 := h 1 in\n    pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one (hx (max x 1) (le_max_left x 1)))\n    (pow_nonneg (le_trans zero_le_one (le_max_right x 1)) n),\n  refine \u27e8nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (\u03bb hn, _))), this\u27e9,\n  obtain \u27e8x, hx\u27e9 := h (c + 1),\n  specialize hx x le_rfl,\n  rw [hn, pow_zero, mul_one, add_le_iff_nonpos_right] at hx,\n  exact absurd hx (not_le.mpr zero_lt_one),\nend\n\nlemma tendsto_neg_const_mul_pow_at_top {c : \u03b1} {n : \u2115}\n  (hn : 1 \u2264 n) (hc : c < 0) : tendsto (\u03bb x, c * x^n) at_top at_bot :=\ntendsto.neg_const_mul_at_top hc (tendsto_pow_at_top hn)\n\nlemma tendsto_neg_const_mul_pow_at_top_iff (c : \u03b1) (n : \u2115) :\n  tendsto (\u03bb x, c * x^n) at_top at_bot \u2194 1 \u2264 n \u2227 c < 0 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, tendsto_neg_const_mul_pow_at_top h.1 h.2\u27e9,\n  simp only [tendsto_at_bot, eventually_at_top] at h,\n  have : c < 0 := let \u27e8x, hx\u27e9 := h (-1) in\n    neg_of_mul_neg_right (lt_of_le_of_lt (hx (max x 1) (le_max_left x 1)) (by simp [zero_lt_one]))\n    (pow_nonneg (le_trans zero_le_one (le_max_right x 1)) n),\n  refine \u27e8nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (\u03bb hn, _))), this\u27e9,\n  obtain \u27e8x, hx\u27e9 := h (c - 1),\n  specialize hx x le_rfl,\n  rw [hn, pow_zero, mul_one, le_sub, sub_self] at hx,\n  exact absurd hx (not_le.mpr zero_lt_one),\nend\n\nend linear_ordered_field\n\nopen_locale filter\n\nlemma tendsto_at_top' [nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto f at_top l \u2194 (\u2200s \u2208 l, \u2203a, \u2200b\u2265a, f b \u2208 s) :=\nby simp only [tendsto_def, mem_at_top_sets]; refl\n\nlemma tendsto_at_bot' [nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto f at_bot l \u2194 (\u2200s \u2208 l, \u2203a, \u2200b\u2264a, f b \u2208 s) :=\n@tendsto_at_top' (order_dual \u03b1) _ _ _ _ _\n\ntheorem tendsto_at_top_principal [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n  tendsto f at_top (\ud835\udcdf s) \u2194 \u2203N, \u2200n\u2265N, f n \u2208 s :=\nby rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl\n\ntheorem tendsto_at_bot_principal [nonempty \u03b2] [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n  tendsto f at_bot (\ud835\udcdf s) \u2194 \u2203N, \u2200n\u2264N, f n \u2208 s :=\n@tendsto_at_top_principal _ (order_dual \u03b2) _ _ _ _\n\n/-- A function `f` grows to `+\u221e` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_top_at_top [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_top at_top \u2194 \u2200 b : \u03b2, \u2203 i : \u03b1, \u2200 a : \u03b1, i \u2264 a \u2192 b \u2264 f a :=\niff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal\n\nlemma tendsto_at_top_at_bot [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_top at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), i \u2264 a \u2192 f a \u2264 b :=\n@tendsto_at_top_at_top \u03b1 (order_dual \u03b2) _ _ _ f\n\nlemma tendsto_at_bot_at_top [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_bot at_top \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 b \u2264 f a :=\n@tendsto_at_top_at_top (order_dual \u03b1) \u03b2 _ _ _ f\n\nlemma tendsto_at_bot_at_bot [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_bot at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 f a \u2264 b :=\n@tendsto_at_top_at_top (order_dual \u03b1) (order_dual \u03b2) _ _ _ f\n\nlemma tendsto_at_top_at_top_of_monotone [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f)\n  (h : \u2200 b, \u2203 a, b \u2264 f a) :\n  tendsto f at_top at_top :=\ntendsto_infi.2 $ \u03bb b, tendsto_principal.2 $ let \u27e8a, ha\u27e9 := h b in\nmem_of_superset (mem_at_top a) $ \u03bb a' ha', le_trans ha (hf ha')\n\nlemma tendsto_at_bot_at_bot_of_monotone [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f)\n  (h : \u2200 b, \u2203 a, f a \u2264 b) :\n  tendsto f at_bot at_bot :=\ntendsto_infi.2 $ \u03bb b, tendsto_principal.2 $ let \u27e8a, ha\u27e9 := h b in\nmem_of_superset (mem_at_bot a) $ \u03bb a' ha', le_trans (hf ha') ha\n\nlemma tendsto_at_top_at_top_iff_of_monotone [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n  tendsto f at_top at_top \u2194 \u2200 b : \u03b2, \u2203 a : \u03b1, b \u2264 f a :=\ntendsto_at_top_at_top.trans $ forall_congr $ \u03bb b, exists_congr $ \u03bb a,\n  \u27e8\u03bb h, h a (le_refl a), \u03bb h a' ha', le_trans h $ hf ha'\u27e9\n\nlemma tendsto_at_bot_at_bot_iff_of_monotone [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n  tendsto f at_bot at_bot \u2194 \u2200 b : \u03b2, \u2203 a : \u03b1, f a \u2264 b :=\ntendsto_at_bot_at_bot.trans $ forall_congr $ \u03bb b, exists_congr $ \u03bb a,\n  \u27e8\u03bb h, h a (le_refl a), \u03bb h a' ha', le_trans (hf ha') h\u27e9\n\nalias tendsto_at_top_at_top_of_monotone \u2190 monotone.tendsto_at_top_at_top\nalias tendsto_at_bot_at_bot_of_monotone \u2190 monotone.tendsto_at_bot_at_bot\nalias tendsto_at_top_at_top_iff_of_monotone \u2190 monotone.tendsto_at_top_at_top_iff\nalias tendsto_at_bot_at_bot_iff_of_monotone \u2190 monotone.tendsto_at_bot_at_bot_iff\n\nlemma comap_embedding_at_top [preorder \u03b2] [preorder \u03b3] {e : \u03b2 \u2192 \u03b3}\n  (hm : \u2200b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, c \u2264 e b) :\n  comap e at_top = at_top :=\nle_antisymm\n  (le_infi $ \u03bb b, le_principal_iff.2 $ mem_comap.2 \u27e8Ici (e b), mem_at_top _, \u03bb x, (hm _ _).1\u27e9)\n  (tendsto_at_top_at_top_of_monotone (\u03bb _ _, (hm _ _).2) hu).le_comap\n\nlemma comap_embedding_at_bot [preorder \u03b2] [preorder \u03b3] {e : \u03b2 \u2192 \u03b3}\n  (hm : \u2200 b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, e b \u2264 c) :\n  comap e at_bot = at_bot :=\n@comap_embedding_at_top (order_dual \u03b2) (order_dual \u03b3) _ _ e (function.swap hm) hu\n\nlemma tendsto_at_top_embedding [preorder \u03b2] [preorder \u03b3]\n  {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1}\n  (hm : \u2200b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, c \u2264 e b) :\n  tendsto (e \u2218 f) l at_top \u2194 tendsto f l at_top :=\nby rw [\u2190 comap_embedding_at_top hm hu, tendsto_comap_iff]\n\n/-- A function `f` goes to `-\u221e` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_bot_embedding [preorder \u03b2] [preorder \u03b3]\n  {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1}\n  (hm : \u2200b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, e b \u2264 c) :\n  tendsto (e \u2218 f) l at_bot \u2194 tendsto f l at_bot :=\n@tendsto_at_top_embedding \u03b1 (order_dual \u03b2) (order_dual \u03b3) _ _ f e l (function.swap hm) hu\n\nlemma tendsto_finset_range : tendsto finset.range at_top at_top :=\nfinset.range_mono.tendsto_at_top_at_top finset.exists_nat_subset_range\n\nlemma at_top_finset_eq_infi : (at_top : filter $ finset \u03b1) = \u2a05 x : \u03b1, \ud835\udcdf (Ici {x}) :=\nbegin\n  refine le_antisymm (le_infi (\u03bb i, le_principal_iff.2 $ mem_at_top {i})) _,\n  refine le_infi (\u03bb s, le_principal_iff.2 $ mem_infi_of_Inter s.finite_to_set\n                  (\u03bb i, mem_principal_self _) _),\n  simp only [subset_def, mem_Inter, set_coe.forall, mem_Ici, finset.le_iff_subset,\n    finset.mem_singleton, finset.subset_iff, forall_eq], dsimp,\n  exact \u03bb t, id\nend\n\n/-- If `f` is a monotone sequence of `finset`s and each `x` belongs to one of `f n`, then\n`tendsto f at_top at_top`. -/\nlemma tendsto_at_top_finset_of_monotone [preorder \u03b2]\n  {f : \u03b2 \u2192 finset \u03b1} (h : monotone f) (h' : \u2200 x : \u03b1, \u2203 n, x \u2208 f n) :\n  tendsto f at_top at_top :=\nbegin\n  simp only [at_top_finset_eq_infi, tendsto_infi, tendsto_principal],\n  intro a,\n  rcases h' a with \u27e8b, hb\u27e9,\n  exact eventually.mono (mem_at_top b)\n    (\u03bb b' hb', le_trans (finset.singleton_subset_iff.2 hb) (h hb')),\nend\n\nalias tendsto_at_top_finset_of_monotone \u2190 monotone.tendsto_at_top_finset\n\nlemma tendsto_finset_image_at_top_at_top {i : \u03b2 \u2192 \u03b3} {j : \u03b3 \u2192 \u03b2} (h : function.left_inverse j i) :\n  tendsto (finset.image j) at_top at_top :=\n(finset.image_mono j).tendsto_at_top_finset $ assume a,\n  \u27e8{i a}, by simp only [finset.image_singleton, h a, finset.mem_singleton]\u27e9\n\nlemma tendsto_finset_preimage_at_top_at_top {f : \u03b1 \u2192 \u03b2} (hf : function.injective f) :\n  tendsto (\u03bb s : finset \u03b2, s.preimage f (hf.inj_on _)) at_top at_top :=\n(finset.monotone_preimage hf).tendsto_at_top_finset $\n  \u03bb x, \u27e8{f x}, finset.mem_preimage.2 $ finset.mem_singleton_self _\u27e9\n\nlemma prod_at_top_at_top_eq {\u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_sup \u03b2\u2081] [semilattice_sup \u03b2\u2082] :\n  (at_top : filter \u03b2\u2081) \u00d7\u1da0 (at_top : filter \u03b2\u2082) = (at_top : filter (\u03b2\u2081 \u00d7 \u03b2\u2082)) :=\nbegin\n  casesI (is_empty_or_nonempty \u03b2\u2081).symm,\n  casesI (is_empty_or_nonempty \u03b2\u2082).symm,\n  { simp [at_top, prod_infi_left, prod_infi_right, infi_prod],\n    exact infi_comm, },\n  { simp only [at_top.filter_eq_bot_of_is_empty, prod_bot] },\n  { simp only [at_top.filter_eq_bot_of_is_empty, bot_prod] },\nend\n\nlemma prod_at_bot_at_bot_eq {\u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_inf \u03b2\u2081] [semilattice_inf \u03b2\u2082] :\n  (at_bot : filter \u03b2\u2081) \u00d7\u1da0 (at_bot : filter \u03b2\u2082) = (at_bot : filter (\u03b2\u2081 \u00d7 \u03b2\u2082)) :=\n@prod_at_top_at_top_eq (order_dual \u03b2\u2081) (order_dual \u03b2\u2082) _ _\n\nlemma prod_map_at_top_eq {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_sup \u03b2\u2081] [semilattice_sup \u03b2\u2082]\n  (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n  (map u\u2081 at_top) \u00d7\u1da0 (map u\u2082 at_top) = map (prod.map u\u2081 u\u2082) at_top :=\nby rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def]\n\nlemma prod_map_at_bot_eq {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_inf \u03b2\u2081] [semilattice_inf \u03b2\u2082]\n  (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n  (map u\u2081 at_bot) \u00d7\u1da0 (map u\u2082 at_bot) = map (prod.map u\u2081 u\u2082) at_bot :=\n@prod_map_at_top_eq _ _ (order_dual \u03b2\u2081) (order_dual \u03b2\u2082) _ _ _ _\n\nlemma tendsto.subseq_mem {F : filter \u03b1} {V : \u2115 \u2192 set \u03b1} (h : \u2200 n, V n \u2208 F) {u : \u2115 \u2192 \u03b1}\n  (hu : tendsto u at_top F) : \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, u (\u03c6 n) \u2208 V n :=\nextraction_forall_of_eventually' (\u03bb n, tendsto_at_top'.mp hu _ (h n) : \u2200 n, \u2203 N, \u2200 k \u2265 N, u k \u2208 V n)\n\nlemma tendsto_at_bot_diagonal [semilattice_inf \u03b1] : tendsto (\u03bb a : \u03b1, (a, a)) at_bot at_bot :=\nby { rw \u2190 prod_at_bot_at_bot_eq, exact tendsto_id.prod_mk tendsto_id }\n\nlemma tendsto_at_top_diagonal [semilattice_sup \u03b1] : tendsto (\u03bb a : \u03b1, (a, a)) at_top at_top :=\nby { rw \u2190 prod_at_top_at_top_eq, exact tendsto_id.prod_mk tendsto_id }\n\nlemma tendsto.prod_map_prod_at_bot [semilattice_inf \u03b3] {F : filter \u03b1} {G : filter \u03b2}\n  {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3} (hf : tendsto f F at_bot) (hg : tendsto g G at_bot) :\n  tendsto (prod.map f g) (F \u00d7\u1da0 G) at_bot :=\nby { rw \u2190 prod_at_bot_at_bot_eq, exact hf.prod_map hg, }\n\nlemma tendsto.prod_map_prod_at_top [semilattice_sup \u03b3] {F : filter \u03b1} {G : filter \u03b2}\n  {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3} (hf : tendsto f F at_top) (hg : tendsto g G at_top) :\n  tendsto (prod.map f g) (F \u00d7\u1da0 G) at_top :=\nby { rw \u2190 prod_at_top_at_top_eq, exact hf.prod_map hg, }\n\nlemma tendsto.prod_at_bot [semilattice_inf \u03b1] [semilattice_inf \u03b3]\n  {f g : \u03b1 \u2192 \u03b3} (hf : tendsto f at_bot at_bot) (hg : tendsto g at_bot at_bot) :\n  tendsto (prod.map f g) at_bot at_bot :=\nby { rw \u2190 prod_at_bot_at_bot_eq, exact hf.prod_map_prod_at_bot hg, }\n\nlemma tendsto.prod_at_top [semilattice_sup \u03b1] [semilattice_sup \u03b3]\n  {f g : \u03b1 \u2192 \u03b3} (hf : tendsto f at_top at_top) (hg : tendsto g at_top at_top) :\n  tendsto (prod.map f g) at_top at_top :=\nby { rw \u2190 prod_at_top_at_top_eq, exact hf.prod_map_prod_at_top hg, }\n\nlemma eventually_at_bot_prod_self [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_bot, p x) \u2194 (\u2203 a, \u2200 k l, k \u2264 a \u2192 l \u2264 a \u2192 p (k, l)) :=\nby simp [\u2190 prod_at_bot_at_bot_eq, at_bot_basis.prod_self.eventually_iff]\n\nlemma eventually_at_top_prod_self [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_top, p x) \u2194 (\u2203 a, \u2200 k l, a \u2264 k \u2192 a \u2264 l \u2192 p (k, l)) :=\nby simp [\u2190 prod_at_top_at_top_eq, at_top_basis.prod_self.eventually_iff]\n\nlemma eventually_at_bot_prod_self' [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_bot, p x) \u2194 (\u2203 a, \u2200 k \u2264 a, \u2200 l \u2264 a, p (k, l)) :=\nbegin\n  rw filter.eventually_at_bot_prod_self,\n  apply exists_congr,\n  tauto,\nend\n\nlemma eventually_at_top_prod_self' [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_top, p x) \u2194 (\u2203 a, \u2200 k \u2265 a, \u2200 l \u2265 a, p (k, l)) :=\nbegin\n  rw filter.eventually_at_top_prod_self,\n  apply exists_congr,\n  tauto,\nend\n\nlemma eventually_at_top_curry [semilattice_sup \u03b1] [semilattice_sup \u03b2] {p : \u03b1 \u00d7 \u03b2 \u2192 Prop}\n  (hp : \u2200\u1da0 (x : \u03b1 \u00d7 \u03b2) in filter.at_top, p x) :\n  \u2200\u1da0 k in at_top, \u2200\u1da0 l in at_top, p (k, l) :=\nbegin\n  rw \u2190 prod_at_top_at_top_eq at hp,\n  exact hp.curry,\nend\n\nlemma eventually_at_bot_curry [semilattice_inf \u03b1] [semilattice_inf \u03b2] {p : \u03b1 \u00d7 \u03b2 \u2192 Prop}\n  (hp : \u2200\u1da0 (x : \u03b1 \u00d7 \u03b2) in filter.at_bot, p x) :\n  \u2200\u1da0 k in at_bot, \u2200\u1da0 l in at_bot, p (k, l) :=\n@eventually_at_top_curry (order_dual \u03b1) (order_dual \u03b2) _ _ _ hp\n\n/-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a\nGalois insertion. The Galois \"insertion\" and \"connection\" is weakened to only require it to be an\ninsertion and a connetion above `b'`. -/\nlemma map_at_top_eq_of_gc [semilattice_sup \u03b1] [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2)\n  (hf : monotone f) (gc : \u2200a, \u2200b\u2265b', f a \u2264 b \u2194 a \u2264 g b) (hgi : \u2200b\u2265b', b \u2264 f (g b)) :\n  map f at_top = at_top :=\nbegin\n  refine le_antisymm\n    (hf.tendsto_at_top_at_top $ \u03bb b, \u27e8g (b \u2294 b'), le_sup_left.trans $ hgi _ le_sup_right\u27e9) _,\n  rw [@map_at_top_eq _ _ \u27e8g b'\u27e9],\n  refine le_infi (\u03bb a, infi_le_of_le (f a \u2294 b') $ principal_mono.2 $ \u03bb b hb, _),\n  rw [mem_Ici, sup_le_iff] at hb,\n  exact \u27e8g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 le_rfl) (hgi _ hb.2)\u27e9\nend\n\nlemma map_at_bot_eq_of_gc [semilattice_inf \u03b1] [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2)\n  (hf : monotone f) (gc : \u2200a, \u2200b\u2264b', b \u2264 f a \u2194 g b \u2264 a) (hgi : \u2200b\u2264b', f (g b) \u2264 b) :\n  map f at_bot = at_bot :=\n@map_at_top_eq_of_gc (order_dual \u03b1) (order_dual \u03b2) _ _ _ _ _ hf.dual gc hgi\n\nlemma map_coe_at_top_of_Ici_subset [semilattice_sup \u03b1] {a : \u03b1} {s : set \u03b1} (h : Ici a \u2286 s) :\n  map (coe : s \u2192 \u03b1) at_top = at_top :=\nbegin\n  have : directed (\u2265) (\u03bb x : s, \ud835\udcdf (Ici x)),\n  { intros x y,\n    use \u27e8x \u2294 y \u2294 a, h le_sup_right\u27e9,\n    simp only [ge_iff_le, principal_mono, Ici_subset_Ici, \u2190 subtype.coe_le_coe, subtype.coe_mk],\n    exact \u27e8le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left\u27e9 },\n  haveI : nonempty s := \u27e8\u27e8a, h le_rfl\u27e9\u27e9,\n  simp only [le_antisymm_iff, at_top, le_infi_iff, le_principal_iff, mem_map, mem_set_of_eq,\n    map_infi_eq this, map_principal],\n  split,\n  { intro x,\n    refine mem_of_superset (mem_infi_of_mem \u27e8x \u2294 a, h le_sup_right\u27e9 (mem_principal_self _)) _,\n    rintro _ \u27e8y, hy, rfl\u27e9,\n    exact le_trans le_sup_left (subtype.coe_le_coe.2 hy) },\n  { intro x,\n    filter_upwards [mem_at_top (\u2191x \u2294 a)] with b hb,\n    exact \u27e8\u27e8b, h $ le_sup_right.trans hb\u27e9, subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl\u27e9, },\nend\n\n/-- The image of the filter `at_top` on `Ici a` under the coercion equals `at_top`. -/\n@[simp] lemma map_coe_Ici_at_top [semilattice_sup \u03b1] (a : \u03b1) :\n  map (coe : Ici a \u2192 \u03b1) at_top = at_top :=\nmap_coe_at_top_of_Ici_subset (subset.refl _)\n\n/-- The image of the filter `at_top` on `Ioi a` under the coercion equals `at_top`. -/\n@[simp] lemma map_coe_Ioi_at_top [semilattice_sup \u03b1] [no_max_order \u03b1] (a : \u03b1) :\n  map (coe : Ioi a \u2192 \u03b1) at_top = at_top :=\nlet \u27e8b, hb\u27e9 := exists_gt a in map_coe_at_top_of_Ici_subset $ Ici_subset_Ioi.2 hb\n\n/-- The `at_top` filter for an open interval `Ioi a` comes from the `at_top` filter in the ambient\norder. -/\nlemma at_top_Ioi_eq [semilattice_sup \u03b1] (a : \u03b1) :\n  at_top = comap (coe : Ioi a \u2192 \u03b1) at_top :=\nbegin\n  nontriviality,\n  rcases nontrivial_iff_nonempty.1 \u2039_\u203a with \u27e8b, hb\u27e9,\n  rw [\u2190 map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map subtype.coe_injective]\nend\n\n/-- The `at_top` filter for an open interval `Ici a` comes from the `at_top` filter in the ambient\norder. -/\nlemma at_top_Ici_eq [semilattice_sup \u03b1] (a : \u03b1) :\n  at_top = comap (coe : Ici a \u2192 \u03b1) at_top :=\nby rw [\u2190 map_coe_Ici_at_top a, comap_map subtype.coe_injective]\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] lemma map_coe_Iio_at_bot [semilattice_inf \u03b1] [no_min_order \u03b1] (a : \u03b1) :\n  map (coe : Iio a \u2192 \u03b1) at_bot = at_bot :=\n@map_coe_Ioi_at_top (order_dual \u03b1) _ _ _\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\nlemma at_bot_Iio_eq [semilattice_inf \u03b1] (a : \u03b1) :\n  at_bot = comap (coe : Iio a \u2192 \u03b1) at_bot :=\n@at_top_Ioi_eq (order_dual \u03b1) _ _\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] lemma map_coe_Iic_at_bot [semilattice_inf \u03b1] (a : \u03b1) :\n  map (coe : Iic a \u2192 \u03b1) at_bot = at_bot :=\n@map_coe_Ici_at_top (order_dual \u03b1) _ _\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\nlemma at_bot_Iic_eq [semilattice_inf \u03b1] (a : \u03b1) :\n  at_bot = comap (coe : Iic a \u2192 \u03b1) at_bot :=\n@at_top_Ici_eq (order_dual \u03b1) _ _\n\nlemma tendsto_Ioi_at_top [semilattice_sup \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Ioi a}\n  {l : filter \u03b2} :\n  tendsto f l at_top \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_top :=\nby rw [at_top_Ioi_eq, tendsto_comap_iff]\n\nlemma tendsto_Iio_at_bot [semilattice_inf \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Iio a}\n  {l : filter \u03b2} :\n  tendsto f l at_bot \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_bot :=\nby rw [at_bot_Iio_eq, tendsto_comap_iff]\n\nlemma tendsto_Ici_at_top [semilattice_sup \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Ici a} {l : filter \u03b2} :\n  tendsto f l at_top \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_top :=\nby rw [at_top_Ici_eq, tendsto_comap_iff]\n\nlemma tendsto_Iic_at_bot [semilattice_inf \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Iic a} {l : filter \u03b2} :\n  tendsto f l at_bot \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_bot :=\nby rw [at_bot_Iic_eq, tendsto_comap_iff]\n\n@[simp] lemma tendsto_comp_coe_Ioi_at_top [semilattice_sup \u03b1] [no_max_order \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Ioi a, f x) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 map_coe_Ioi_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Ici_at_top [semilattice_sup \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Ici a, f x) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 map_coe_Ici_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iio_at_bot [semilattice_inf \u03b1] [no_min_order \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Iio a, f x) at_bot l \u2194 tendsto f at_bot l :=\nby rw [\u2190 map_coe_Iio_at_bot a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iic_at_bot [semilattice_inf \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Iic a, f x) at_bot l \u2194 tendsto f at_bot l :=\nby rw [\u2190 map_coe_Iic_at_bot a, tendsto_map'_iff]\n\nlemma map_add_at_top_eq_nat (k : \u2115) : map (\u03bba, a + k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bba, a - k) k\n  (assume a b h, add_le_add_right h k)\n  (assume a b h, (le_tsub_iff_right h).symm)\n  (assume a h, by rw [tsub_add_cancel_of_le h])\n\nlemma map_sub_at_top_eq_nat (k : \u2115) : map (\u03bba, a - k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bba, a + k) 0\n  (assume a b h, tsub_le_tsub_right h _)\n  (assume a b _, tsub_le_iff_right)\n  (assume b _, by rw [add_tsub_cancel_right])\n\nlemma tendsto_add_at_top_nat (k : \u2115) : tendsto (\u03bba, a + k) at_top at_top :=\nle_of_eq (map_add_at_top_eq_nat k)\n\nlemma tendsto_sub_at_top_nat (k : \u2115) : tendsto (\u03bba, a - k) at_top at_top :=\nle_of_eq (map_sub_at_top_eq_nat k)\n\nlemma tendsto_add_at_top_iff_nat {f : \u2115 \u2192 \u03b1} {l : filter \u03b1} (k : \u2115) :\n  tendsto (\u03bbn, f (n + k)) at_top l \u2194 tendsto f at_top l :=\nshow tendsto (f \u2218 (\u03bbn, n + k)) at_top l \u2194 tendsto f at_top l,\n  by rw [\u2190 tendsto_map'_iff, map_add_at_top_eq_nat]\n\nlemma map_div_at_top_eq_nat (k : \u2115) (hk : 0 < k) : map (\u03bba, a / k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bbb, b * k + (k - 1)) 1\n  (assume a b h, nat.div_le_div_right h)\n  (assume a b _,\n    calc a / k \u2264 b \u2194 a / k < b + 1 : by rw [\u2190 nat.succ_eq_add_one, nat.lt_succ_iff]\n      ... \u2194 a < (b + 1) * k : nat.div_lt_iff_lt_mul _ _ hk\n      ... \u2194 _ :\n      begin\n        cases k,\n        exact (lt_irrefl _ hk).elim,\n        rw [add_mul, one_mul, nat.succ_sub_succ_eq_sub,\n          tsub_zero, nat.add_succ, nat.lt_succ_iff],\n      end)\n  (assume b _,\n    calc b = (b * k) / k : by rw [nat.mul_div_cancel b hk]\n      ... \u2264 (b * k + (k - 1)) / k : nat.div_le_div_right $ nat.le_add_right _ _)\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nabove, then `tendsto u at_top at_top`. -/\nlemma tendsto_at_top_at_top_of_monotone' [preorder \u03b9] [linear_order \u03b1]\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_above (range u)) :\n  tendsto u at_top at_top :=\nbegin\n  apply h.tendsto_at_top_at_top,\n  intro b,\n  rcases not_bdd_above_iff.1 H b with \u27e8_, \u27e8N, rfl\u27e9, hN\u27e9,\n  exact \u27e8N, le_of_lt hN\u27e9,\nend\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nbelow, then `tendsto u at_bot at_bot`. -/\nlemma tendsto_at_bot_at_bot_of_monotone' [preorder \u03b9] [linear_order \u03b1]\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_below (range u)) :\n  tendsto u at_bot at_bot :=\n@tendsto_at_top_at_top_of_monotone' (order_dual \u03b9) (order_dual \u03b1) _ _ _ h.dual H\n\nlemma unbounded_of_tendsto_at_top [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] [no_max_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_top) :\n  \u00ac bdd_above (range f) :=\nbegin\n  rintros \u27e8M, hM\u27e9,\n  cases mem_at_top_sets.mp (h $ Ioi_mem_at_top M) with a ha,\n  apply lt_irrefl M,\n  calc\n  M < f a : ha a le_rfl\n  ... \u2264 M : hM (set.mem_range_self a)\nend\n\nlemma unbounded_of_tendsto_at_bot [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] [no_min_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_bot) :\n  \u00ac bdd_below (range f) :=\n@unbounded_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_top' [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] [no_max_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_top) :\n  \u00ac bdd_above (range f) :=\n@unbounded_of_tendsto_at_top (order_dual \u03b1) _ _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_bot' [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] [no_min_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_bot) :\n  \u00ac bdd_below (range f) :=\n@unbounded_of_tendsto_at_top (order_dual \u03b1) (order_dual \u03b2) _ _ _ _ _ h\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_top` along *some* non-trivial filter `l`, then\nit tends to `at_top` along `at_top`. -/\nlemma tendsto_at_top_of_monotone_of_filter [preorder \u03b9] [preorder \u03b1] {l : filter \u03b9}\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_top) :\n  tendsto u at_top at_top :=\nh.tendsto_at_top_at_top $ \u03bb b, (hu.eventually (mem_at_top b)).exists\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_bot` along *some* non-trivial filter `l`, then\nit tends to `at_bot` along `at_bot`. -/\nlemma tendsto_at_bot_of_monotone_of_filter [preorder \u03b9] [preorder \u03b1] {l : filter \u03b9}\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_bot) :\n  tendsto u at_bot at_bot :=\n@tendsto_at_top_of_monotone_of_filter (order_dual \u03b9) (order_dual \u03b1) _ _ _ _ h.dual _ hu\n\nlemma tendsto_at_top_of_monotone_of_subseq [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1}\n  {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n  (H : tendsto (u \u2218 \u03c6) l at_top) :\n  tendsto u at_top at_top :=\ntendsto_at_top_of_monotone_of_filter h (tendsto_map' H)\n\nlemma tendsto_at_bot_of_monotone_of_subseq [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1}\n  {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n  (H : tendsto (u \u2218 \u03c6) l at_bot) :\n  tendsto u at_bot at_bot :=\ntendsto_at_bot_of_monotone_of_filter h (tendsto_map' H)\n\n/-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient\ncondition for comparison of the filter `at_top.map (\u03bb s, \u220f b in s, f b)` with\n`at_top.map (\u03bb s, \u220f b in s, g b)`. This is useful to compare the set of limit points of\n`\u03a0 b in s, f b` as `s \u2192 at_top` with the similar set for `g`. -/\n@[to_additive]\nlemma map_at_top_finset_prod_le_of_prod_eq [comm_monoid \u03b1] {f : \u03b2 \u2192 \u03b1} {g : \u03b3 \u2192 \u03b1}\n  (h_eq : \u2200u:finset \u03b3, \u2203v:finset \u03b2, \u2200v', v \u2286 v' \u2192 \u2203u', u \u2286 u' \u2227 \u220f x in u', g x = \u220f b in v', f b) :\n  at_top.map (\u03bbs:finset \u03b2, \u220f b in s, f b) \u2264 at_top.map (\u03bbs:finset \u03b3, \u220f x in s, g x) :=\nby rw [map_at_top_eq, map_at_top_eq];\nfrom (le_infi $ assume b, let \u27e8v, hv\u27e9 := h_eq b in infi_le_of_le v $\n  by simp [set.image_subset_iff]; exact hv)\n\nlemma has_antitone_basis.tendsto [semilattice_sup \u03b9] [nonempty \u03b9] {l : filter \u03b1}\n  {s : \u03b9 \u2192 set \u03b1} (hl : l.has_antitone_basis s) {\u03c6 : \u03b9 \u2192 \u03b1}\n  (h : \u2200 i : \u03b9, \u03c6 i \u2208 s i) : tendsto \u03c6 at_top l  :=\n(at_top_basis.tendsto_iff hl.to_has_basis).2 $ assume i hi,\n  \u27e8i, trivial, \u03bb j hij, hl.antitone hij (h _)\u27e9\n\n/-- If `f` is a nontrivial countably generated filter, then there exists a sequence that converges\nto `f`. -/\nlemma exists_seq_tendsto (f : filter \u03b1) [is_countably_generated f] [ne_bot f] :\n  \u2203 x : \u2115 \u2192 \u03b1, tendsto x at_top f :=\nbegin\n  obtain \u27e8B, h\u27e9 := f.exists_antitone_basis,\n  have := \u03bb n, nonempty_of_mem (h.to_has_basis.mem_of_mem trivial : B n \u2208 f), choose x hx,\n  exact \u27e8x, h.tendsto hx\u27e9\nend\n\n/-- An abstract version of continuity of sequentially continuous functions on metric spaces:\nif a filter `k` is countably generated then `tendsto f k l` iff for every sequence `u`\nconverging to `k`, `f \u2218 u` tends to `l`. -/\nlemma tendsto_iff_seq_tendsto {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1} {l : filter \u03b2} [k.is_countably_generated] :\n  tendsto f k l \u2194 (\u2200 x : \u2115 \u2192 \u03b1, tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) :=\nbegin\n  refine \u27e8\u03bb h x hx, h.comp hx, \u03bb H s hs, _\u27e9,\n  contrapose! H,\n  haveI : ne_bot (k \u2293 \ud835\udcdf (f \u207b\u00b9' s\u1d9c)), by simpa [ne_bot_iff,  inf_principal_eq_bot],\n  rcases (k \u2293 \ud835\udcdf (f \u207b\u00b9' s\u1d9c)).exists_seq_tendsto with \u27e8x, hx\u27e9,\n  rw [tendsto_inf, tendsto_principal] at hx,\n  refine \u27e8x, hx.1, \u03bb h, _\u27e9,\n  rcases (hx.2.and (h hs)).exists with \u27e8N, hnmem, hmem\u27e9,\n  exact hnmem hmem\nend\n\nlemma tendsto_of_seq_tendsto {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1} {l : filter \u03b2} [k.is_countably_generated] :\n  (\u2200 x : \u2115 \u2192 \u03b1, tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) \u2192 tendsto f k l :=\ntendsto_iff_seq_tendsto.2\n\nlemma subseq_tendsto_of_ne_bot {f : filter \u03b1} [is_countably_generated f] {u : \u2115 \u2192 \u03b1}\n  (hx : ne_bot (f \u2293 map u at_top)) :\n  \u2203 (\u03b8 : \u2115 \u2192 \u2115), (strict_mono \u03b8) \u2227 (tendsto (u \u2218 \u03b8) at_top f) :=\nbegin\n  obtain \u27e8B, h\u27e9 := f.exists_antitone_basis,\n  have : \u2200 N, \u2203 n \u2265 N, u n \u2208 B N,\n    from \u03bb N, filter.inf_map_at_top_ne_bot_iff.mp hx _ (h.to_has_basis.mem_of_mem trivial) N,\n  choose \u03c6 h\u03c6 using this,\n  cases forall_and_distrib.mp h\u03c6 with \u03c6_ge \u03c6_in,\n  have lim_u\u03c6 : tendsto (u \u2218 \u03c6) at_top f,\n    from h.tendsto \u03c6_in,\n  have lim_\u03c6 : tendsto \u03c6 at_top at_top,\n    from (tendsto_at_top_mono \u03c6_ge tendsto_id),\n  obtain \u27e8\u03c8, h\u03c8, h\u03c8\u03c6\u27e9 : \u2203 \u03c8 : \u2115 \u2192 \u2115, strict_mono \u03c8 \u2227 strict_mono (\u03c6 \u2218 \u03c8),\n    from strict_mono_subseq_of_tendsto_at_top lim_\u03c6,\n  exact \u27e8\u03c6 \u2218 \u03c8, h\u03c8\u03c6, lim_u\u03c6.comp h\u03c8.tendsto_at_top\u27e9,\nend\n\nend filter\n\nopen filter finset\n\nsection\n\nvariables {R : Type*} [linear_ordered_semiring R]\n\nlemma exists_lt_mul_self (a : R) : \u2203 x \u2265 0, a < x * x :=\nlet \u27e8x, hxa, hx0\u27e9 :=((tendsto_mul_self_at_top.eventually (eventually_gt_at_top a)).and\n  (eventually_ge_at_top 0)).exists\nin \u27e8x, hx0, hxa\u27e9\n\nlemma exists_le_mul_self (a : R) : \u2203 x \u2265 0, a \u2264 x * x :=\nlet \u27e8x, hx0, hxa\u27e9 := exists_lt_mul_self a in \u27e8x, hx0, hxa.le\u27e9\n\nend\n\nnamespace order_iso\n\nvariables [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma comap_at_top (e : \u03b1 \u2243o \u03b2) : comap e at_top = at_top :=\nby simp [at_top, \u2190 e.surjective.infi_comp]\n\n@[simp] lemma comap_at_bot (e : \u03b1 \u2243o \u03b2) : comap e at_bot = at_bot :=\ne.dual.comap_at_top\n\n@[simp] lemma map_at_top (e : \u03b1 \u2243o \u03b2) : map (e : \u03b1 \u2192 \u03b2) at_top = at_top :=\nby rw [\u2190 e.comap_at_top, map_comap_of_surjective e.surjective]\n\n@[simp] lemma map_at_bot (e : \u03b1 \u2243o \u03b2) : map (e : \u03b1 \u2192 \u03b2) at_bot = at_bot :=\ne.dual.map_at_top\n\nlemma tendsto_at_top (e : \u03b1 \u2243o \u03b2) : tendsto e at_top at_top :=\ne.map_at_top.le\n\nlemma tendsto_at_bot (e : \u03b1 \u2243o \u03b2) : tendsto e at_bot at_bot :=\ne.map_at_bot.le\n\n@[simp] lemma tendsto_at_top_iff {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n  tendsto (\u03bb x, e (f x)) l at_top \u2194 tendsto f l at_top :=\nby rw [\u2190 e.comap_at_top, tendsto_comap_iff]\n\n@[simp] lemma tendsto_at_bot_iff {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n  tendsto (\u03bb x, e (f x)) l at_bot \u2194 tendsto f l at_bot :=\ne.dual.tendsto_at_top_iff\n\nend order_iso\n\n/-- Let `g : \u03b3 \u2192 \u03b2` be an injective function and `f : \u03b2 \u2192 \u03b1` be a function from the codomain of `g`\nto a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters\n`at_top.map (\u03bb s, \u220f i in s, f (g i))` and `at_top.map (\u03bb s, \u220f i in s, f i)` coincide.\n\nThe additive version of this lemma is used to prove the equality `\u2211' x, f (g x) = \u2211' y, f y` under\nthe same assumptions.-/\n@[to_additive]\nlemma function.injective.map_at_top_finset_prod_eq [comm_monoid \u03b1] {g : \u03b3 \u2192 \u03b2}\n  (hg : function.injective g) {f : \u03b2 \u2192 \u03b1} (hf : \u2200 x \u2209 set.range g, f x = 1) :\n  map (\u03bb s, \u220f i in s, f (g i)) at_top = map (\u03bb s, \u220f i in s, f i) at_top :=\nbegin\n  apply le_antisymm; refine map_at_top_finset_prod_le_of_prod_eq (\u03bb s, _),\n  { refine \u27e8s.preimage g (hg.inj_on _), \u03bb t ht, _\u27e9,\n    refine \u27e8t.image g \u222a s, finset.subset_union_right _ _, _\u27e9,\n    rw [\u2190 finset.prod_image (hg.inj_on _)],\n    refine (prod_subset (subset_union_left _ _) _).symm,\n    simp only [finset.mem_union, finset.mem_image],\n    refine \u03bb y hy hyt, hf y (mt _ hyt),\n    rintros \u27e8x, rfl\u27e9,\n    exact \u27e8x, ht (finset.mem_preimage.2 $ hy.resolve_left hyt), rfl\u27e9 },\n  { refine \u27e8s.image g, \u03bb t ht, _\u27e9,\n    simp only [\u2190 prod_preimage _ _ (hg.inj_on _) _ (\u03bb x _, hf x)],\n    exact \u27e8_, (image_subset_iff_subset_preimage _).1 ht, rfl\u27e9 }\nend\n\n/-- Let `g : \u03b3 \u2192 \u03b2` be an injective function and `f : \u03b2 \u2192 \u03b1` be a function from the codomain of `g`\nto an additive commutative monoid. Suppose that `f x = 0` outside of the range of `g`. Then the\nfilters `at_top.map (\u03bb s, \u2211 i in s, f (g i))` and `at_top.map (\u03bb s, \u2211 i in s, f i)` coincide.\n\nThis lemma is used to prove the equality `\u2211' x, f (g x) = \u2211' y, f y` under\nthe same assumptions.-/\nadd_decl_doc function.injective.map_at_top_finset_sum_eq\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/filter/at_top_bot.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7184837025709068}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot\n-/\nimport order.filter.bases\nimport data.finset.preimage\n\n/-!\n# `at_top` and `at_bot` filters on preorded sets, monoids and groups.\n\nIn this file we define the filters\n\n* `at_top`: corresponds to `n \u2192 +\u221e`;\n* `at_bot`: corresponds to `n \u2192 -\u221e`.\n\nThen we prove many lemmas like \u201cif `f \u2192 +\u221e`, then `f \u00b1 c \u2192 +\u221e`\u201d.\n-/\n\nvariables {\u03b9 \u03b9' \u03b1 \u03b2 \u03b3 : Type*}\n\nopen set\nopen_locale classical filter big_operators\n\nnamespace filter\n/-- `at_top` is the filter representing the limit `\u2192 \u221e` on an ordered set.\n  It is generated by the collection of up-sets `{b | a \u2264 b}`.\n  (The preorder need not have a top element for this to be well defined,\n  and indeed is trivial when a top element exists.) -/\ndef at_top [preorder \u03b1] : filter \u03b1 := \u2a05 a, \ud835\udcdf (Ici a)\n\n/-- `at_bot` is the filter representing the limit `\u2192 -\u221e` on an ordered set.\n  It is generated by the collection of down-sets `{b | b \u2264 a}`.\n  (The preorder need not have a bottom element for this to be well defined,\n  and indeed is trivial when a bottom element exists.) -/\ndef at_bot [preorder \u03b1] : filter \u03b1 := \u2a05 a, \ud835\udcdf (Iic a)\n\nlemma mem_at_top [preorder \u03b1] (a : \u03b1) : {b : \u03b1 | a \u2264 b} \u2208 @at_top \u03b1 _ :=\nmem_infi_of_mem a $ subset.refl _\n\nlemma Ioi_mem_at_top [preorder \u03b1] [no_top_order \u03b1] (x : \u03b1) : Ioi x \u2208 (at_top : filter \u03b1) :=\nlet \u27e8z, hz\u27e9 := no_top x in mem_of_superset (mem_at_top z) $ \u03bb y h,  lt_of_lt_of_le hz h\n\nlemma mem_at_bot [preorder \u03b1] (a : \u03b1) : {b : \u03b1 | b \u2264 a} \u2208 @at_bot \u03b1 _ :=\nmem_infi_of_mem a $ subset.refl _\n\nlemma Iio_mem_at_bot [preorder \u03b1] [no_bot_order \u03b1] (x : \u03b1) : Iio x \u2208 (at_bot : filter \u03b1) :=\nlet \u27e8z, hz\u27e9 := no_bot x in mem_of_superset (mem_at_bot z) $ \u03bb y h, lt_of_le_of_lt h hz\n\nlemma at_top_basis [nonempty \u03b1] [semilattice_sup \u03b1] :\n  (@at_top \u03b1 _).has_basis (\u03bb _, true) Ici :=\nhas_basis_infi_principal (directed_of_sup $ \u03bb a b, Ici_subset_Ici.2)\n\nlemma at_top_basis' [semilattice_sup \u03b1] (a : \u03b1) :\n  (@at_top \u03b1 _).has_basis (\u03bb x, a \u2264 x) Ici :=\n\u27e8\u03bb t, (@at_top_basis \u03b1 \u27e8a\u27e9 _).mem_iff.trans\n  \u27e8\u03bb \u27e8x, _, hx\u27e9, \u27e8x \u2294 a, le_sup_right, \u03bb y hy, hx (le_trans le_sup_left hy)\u27e9,\n    \u03bb \u27e8x, _, hx\u27e9, \u27e8x, trivial, hx\u27e9\u27e9\u27e9\n\nlemma at_bot_basis [nonempty \u03b1] [semilattice_inf \u03b1] :\n  (@at_bot \u03b1 _).has_basis (\u03bb _, true) Iic :=\n@at_top_basis (order_dual \u03b1) _ _\n\nlemma at_bot_basis' [semilattice_inf \u03b1] (a : \u03b1) :\n  (@at_bot \u03b1 _).has_basis (\u03bb x, x \u2264 a) Iic :=\n@at_top_basis' (order_dual \u03b1) _ _\n\n@[instance]\nlemma at_top_ne_bot [nonempty \u03b1] [semilattice_sup \u03b1] : ne_bot (at_top : filter \u03b1) :=\nat_top_basis.ne_bot_iff.2 $ \u03bb a _, nonempty_Ici\n\n@[instance]\nlemma at_bot_ne_bot [nonempty \u03b1] [semilattice_inf \u03b1] : ne_bot (at_bot : filter \u03b1) :=\n@at_top_ne_bot (order_dual \u03b1) _ _\n\n@[simp]\nlemma mem_at_top_sets [nonempty \u03b1] [semilattice_sup \u03b1] {s : set \u03b1} :\n  s \u2208 (at_top : filter \u03b1) \u2194 \u2203a:\u03b1, \u2200b\u2265a, b \u2208 s :=\nat_top_basis.mem_iff.trans $ exists_congr $ \u03bb _, exists_const _\n\n@[simp]\nlemma mem_at_bot_sets [nonempty \u03b1] [semilattice_inf \u03b1] {s : set \u03b1} :\n  s \u2208 (at_bot : filter \u03b1) \u2194 \u2203a:\u03b1, \u2200b\u2264a, b \u2208 s :=\n@mem_at_top_sets (order_dual \u03b1) _ _ _\n\n@[simp]\nlemma eventually_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_top, p x) \u2194 (\u2203 a, \u2200 b \u2265 a, p b) :=\nmem_at_top_sets\n\n@[simp]\nlemma eventually_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_bot, p x) \u2194 (\u2203 a, \u2200 b \u2264 a, p b) :=\nmem_at_bot_sets\n\nlemma eventually_ge_at_top [preorder \u03b1] (a : \u03b1) : \u2200\u1da0 x in at_top, a \u2264 x := mem_at_top a\n\nlemma eventually_le_at_bot [preorder \u03b1] (a : \u03b1) : \u2200\u1da0 x in at_bot, x \u2264 a := mem_at_bot a\n\nlemma eventually_gt_at_top [preorder \u03b1] [no_top_order \u03b1] (a : \u03b1) :\n  \u2200\u1da0 x in at_top, a < x :=\nIoi_mem_at_top a\n\nlemma eventually_lt_at_bot [preorder \u03b1] [no_bot_order \u03b1] (a : \u03b1) :\n  \u2200\u1da0 x in at_bot, x < a :=\nIio_mem_at_bot a\n\nlemma at_top_basis_Ioi [nonempty \u03b1] [semilattice_sup \u03b1] [no_top_order \u03b1] :\n  (@at_top \u03b1 _).has_basis (\u03bb _, true) Ioi :=\nat_top_basis.to_has_basis (\u03bb a ha, \u27e8a, ha, Ioi_subset_Ici_self\u27e9) $\n  \u03bb a ha, (no_top a).imp $ \u03bb b hb, \u27e8ha, Ici_subset_Ioi.2 hb\u27e9\n\nlemma at_top_countable_basis [nonempty \u03b1] [semilattice_sup \u03b1] [encodable \u03b1] :\n  has_countable_basis (at_top : filter \u03b1) (\u03bb _, true) Ici :=\n{ countable := countable_encodable _,\n  .. at_top_basis }\n\nlemma at_bot_countable_basis [nonempty \u03b1] [semilattice_inf \u03b1] [encodable \u03b1] :\n  has_countable_basis (at_bot : filter \u03b1) (\u03bb _, true) Iic :=\n{ countable := countable_encodable _,\n  .. at_bot_basis }\n\n@[priority 200]\ninstance at_top.is_countably_generated [preorder \u03b1] [encodable \u03b1] :\n  (at_top : filter $ \u03b1).is_countably_generated :=\nis_countably_generated_seq _\n\n@[priority 200]\ninstance at_bot.is_countably_generated [preorder \u03b1] [encodable \u03b1] :\n  (at_bot : filter $ \u03b1).is_countably_generated :=\nis_countably_generated_seq _\n\nlemma order_top.at_top_eq (\u03b1) [partial_order \u03b1] [order_top \u03b1] : (at_top : filter \u03b1) = pure \u22a4 :=\nle_antisymm (le_pure_iff.2 $ (eventually_ge_at_top \u22a4).mono $ \u03bb b, top_unique)\n  (le_infi $ \u03bb b, le_principal_iff.2 le_top)\n\n\n\n@[nontriviality]\nlemma subsingleton.at_top_eq (\u03b1) [subsingleton \u03b1] [preorder \u03b1] : (at_top : filter \u03b1) = \u22a4 :=\nbegin\n  refine top_unique (\u03bb s hs x, _),\n  letI : unique \u03b1 := \u27e8\u27e8x\u27e9, \u03bb y, subsingleton.elim y x\u27e9,\n  rw [at_top, infi_unique, unique.default_eq x, mem_principal] at hs,\n  exact hs left_mem_Ici\nend\n\n@[nontriviality]\nlemma subsingleton.at_bot_eq (\u03b1) [subsingleton \u03b1] [preorder \u03b1] : (at_bot : filter \u03b1) = \u22a4 :=\n@subsingleton.at_top_eq (order_dual \u03b1) _ _\n\nlemma tendsto_at_top_pure [partial_order \u03b1] [order_top \u03b1] (f : \u03b1 \u2192 \u03b2) :\n  tendsto f at_top (pure $ f \u22a4) :=\n(order_top.at_top_eq \u03b1).symm \u25b8 tendsto_pure_pure _ _\n\nlemma tendsto_at_bot_pure [partial_order \u03b1] [order_bot \u03b1] (f : \u03b1 \u2192 \u03b2) :\n  tendsto f at_bot (pure $ f \u22a5) :=\n@tendsto_at_top_pure (order_dual \u03b1) _ _ _ _\n\nlemma eventually.exists_forall_of_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2200\u1da0 x in at_top, p x) : \u2203 a, \u2200 b \u2265 a, p b :=\neventually_at_top.mp h\n\nlemma eventually.exists_forall_of_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2200\u1da0 x in at_bot, p x) : \u2203 a, \u2200 b \u2264 a, p b :=\neventually_at_bot.mp h\n\nlemma frequently_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_top, p x) \u2194 (\u2200 a, \u2203 b \u2265 a, p b) :=\nby simp [at_top_basis.frequently_iff]\n\nlemma frequently_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_bot, p x) \u2194 (\u2200 a, \u2203 b \u2264 a, p b) :=\n@frequently_at_top (order_dual \u03b1) _ _ _\n\nlemma frequently_at_top' [semilattice_sup \u03b1] [nonempty \u03b1] [no_top_order \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_top, p x) \u2194 (\u2200 a, \u2203 b > a, p b) :=\nby simp [at_top_basis_Ioi.frequently_iff]\n\nlemma frequently_at_bot' [semilattice_inf \u03b1] [nonempty \u03b1] [no_bot_order \u03b1] {p : \u03b1 \u2192 Prop} :\n  (\u2203\u1da0 x in at_bot, p x) \u2194 (\u2200 a, \u2203 b < a, p b) :=\n@frequently_at_top' (order_dual \u03b1) _ _ _ _\n\nlemma frequently.forall_exists_of_at_top [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2203\u1da0 x in at_top, p x) : \u2200 a, \u2203 b \u2265 a, p b :=\nfrequently_at_top.mp h\n\nlemma frequently.forall_exists_of_at_bot [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u2192 Prop}\n  (h : \u2203\u1da0 x in at_bot, p x) : \u2200 a, \u2203 b \u2264 a, p b :=\nfrequently_at_bot.mp h\n\nlemma map_at_top_eq [nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} :\n  at_top.map f = (\u2a05a, \ud835\udcdf $ f '' {a' | a \u2264 a'}) :=\n(at_top_basis.map _).eq_infi\n\nlemma map_at_bot_eq [nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2} :\n  at_bot.map f = (\u2a05a, \ud835\udcdf $ f '' {a' | a' \u2264 a}) :=\n@map_at_top_eq (order_dual \u03b1) _ _ _ _\n\nlemma tendsto_at_top [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n  tendsto m f at_top \u2194 (\u2200b, \u2200\u1da0 a in f, b \u2264 m a) :=\nby simp only [at_top, tendsto_infi, tendsto_principal, mem_Ici]\n\nlemma tendsto_at_bot [preorder \u03b2] {m : \u03b1 \u2192 \u03b2} {f : filter \u03b1} :\n  tendsto m f at_bot \u2194 (\u2200b, \u2200\u1da0 a in f, m a \u2264 b) :=\n@tendsto_at_top \u03b1 (order_dual \u03b2) _ m f\n\nlemma tendsto_at_top_mono' [preorder \u03b2] (l : filter \u03b1) \u2983f\u2081 f\u2082 : \u03b1 \u2192 \u03b2\u2984 (h : f\u2081 \u2264\u1da0[l] f\u2082) :\n  tendsto f\u2081 l at_top \u2192 tendsto f\u2082 l at_top :=\nassume h\u2081, tendsto_at_top.2 $ \u03bb b, mp_mem (tendsto_at_top.1 h\u2081 b)\n  (monotone_mem (\u03bb a ha ha\u2081, le_trans ha\u2081 ha) h)\n\nlemma tendsto_at_bot_mono' [preorder \u03b2] (l : filter \u03b1) \u2983f\u2081 f\u2082 : \u03b1 \u2192 \u03b2\u2984 (h : f\u2081 \u2264\u1da0[l] f\u2082) :\n  tendsto f\u2082 l at_bot \u2192 tendsto f\u2081 l at_bot :=\n@tendsto_at_top_mono' _ (order_dual \u03b2) _ _ _ _ h\n\nlemma tendsto_at_top_mono [preorder \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2} (h : \u2200 n, f n \u2264 g n) :\n  tendsto f l at_top \u2192 tendsto g l at_top :=\ntendsto_at_top_mono' l $ eventually_of_forall h\n\nlemma tendsto_at_bot_mono [preorder \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2} (h : \u2200 n, f n \u2264 g n) :\n  tendsto g l at_bot \u2192 tendsto f l at_bot :=\n@tendsto_at_top_mono _ (order_dual \u03b2) _ _ _ _ h\n\n/-!\n### Sequences\n-/\n\nlemma inf_map_at_top_ne_bot_iff [semilattice_sup \u03b1] [nonempty \u03b1] {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n  ne_bot (F \u2293 (map u at_top)) \u2194 \u2200 U \u2208 F, \u2200 N, \u2203 n \u2265 N, u n \u2208 U :=\nby simp_rw [inf_ne_bot_iff_frequently_left, frequently_map, frequently_at_top]; refl\n\nlemma inf_map_at_bot_ne_bot_iff [semilattice_inf \u03b1] [nonempty \u03b1] {F : filter \u03b2} {u : \u03b1 \u2192 \u03b2} :\n  ne_bot (F \u2293 (map u at_bot)) \u2194 \u2200 U \u2208 F, \u2200 N, \u2203 n \u2264 N, u n \u2208 U :=\n@inf_map_at_top_ne_bot_iff (order_dual \u03b1) _ _ _ _ _\n\nlemma extraction_of_frequently_at_top' {P : \u2115 \u2192 Prop} (h : \u2200 N, \u2203 n > N, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nbegin\n  choose u hu using h,\n  cases forall_and_distrib.mp hu with hu hu',\n  exact \u27e8u \u2218 (nat.rec 0 (\u03bb n v, u v)), strict_mono_nat_of_lt_succ (\u03bb n, hu _), \u03bb n, hu' _\u27e9,\nend\n\nlemma extraction_of_frequently_at_top {P : \u2115 \u2192 Prop} (h : \u2203\u1da0 n in at_top, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nbegin\n  rw frequently_at_top' at h,\n  exact extraction_of_frequently_at_top' h,\nend\n\nlemma extraction_of_eventually_at_top {P : \u2115 \u2192 Prop} (h : \u2200\u1da0 n in at_top, P n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P (\u03c6 n) :=\nextraction_of_frequently_at_top h.frequently\n\nlemma extraction_forall_of_frequently {P : \u2115 \u2192 \u2115 \u2192 Prop} (h : \u2200 n, \u2203\u1da0 k in at_top, P n k) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P n (\u03c6 n) :=\nbegin\n  simp only [frequently_at_top'] at h,\n  choose u hu hu' using h,\n  use (\u03bb n, nat.rec_on n (u 0 0) (\u03bb n v, u (n+1) v) : \u2115 \u2192 \u2115),\n  split,\n  { apply strict_mono_nat_of_lt_succ,\n    intro n,\n    apply hu },\n  { intros n,\n    cases n ; simp [hu'] },\nend\n\nlemma extraction_forall_of_eventually  {P : \u2115 \u2192 \u2115 \u2192 Prop} (h : \u2200 n, \u2200\u1da0 k in at_top, P n k) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P n (\u03c6 n) :=\nextraction_forall_of_frequently (\u03bb n, (h n).frequently)\n\nlemma extraction_forall_of_eventually' {P : \u2115 \u2192 \u2115 \u2192 Prop} (h : \u2200 n, \u2203 N, \u2200 k \u2265 N, P n k) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, P n (\u03c6 n) :=\nextraction_forall_of_eventually (by simp [eventually_at_top, h])\n\nlemma exists_le_of_tendsto_at_top [semilattice_sup \u03b1] [preorder \u03b2] {u : \u03b1 \u2192 \u03b2}\n  (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) : \u2203 a' \u2265 a, b \u2264 u a' :=\nbegin\n  have : \u2200\u1da0 x in at_top, a \u2264 x \u2227 b \u2264 u x :=\n    (eventually_ge_at_top a).and (h.eventually $ eventually_ge_at_top b),\n  haveI : nonempty \u03b1 := \u27e8a\u27e9,\n  rcases this.exists with \u27e8a', ha, hb\u27e9,\n  exact \u27e8a', ha, hb\u27e9\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_le_of_tendsto_at_bot [semilattice_sup \u03b1] [preorder \u03b2] {u : \u03b1 \u2192 \u03b2}\n  (h : tendsto u at_top at_bot) : \u2200 a b, \u2203 a' \u2265 a, u a' \u2264 b :=\n@exists_le_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ h\n\nlemma exists_lt_of_tendsto_at_top [semilattice_sup \u03b1] [preorder \u03b2] [no_top_order \u03b2]\n  {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_top) (a : \u03b1) (b : \u03b2) : \u2203 a' \u2265 a, b < u a' :=\nbegin\n  cases no_top b with b' hb',\n  rcases exists_le_of_tendsto_at_top h a b' with \u27e8a', ha', ha''\u27e9,\n  exact \u27e8a', ha', lt_of_lt_of_le hb' ha''\u27e9\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_lt_of_tendsto_at_bot [semilattice_sup \u03b1] [preorder \u03b2] [no_bot_order \u03b2]\n  {u : \u03b1 \u2192 \u03b2} (h : tendsto u at_top at_bot) : \u2200 a b, \u2203 a' \u2265 a, u a' < b :=\n@exists_lt_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ _ h\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen after any point, it reaches a value strictly greater than all previous values.\n-/\nlemma high_scores [linear_order \u03b2] [no_top_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_top) : \u2200 N, \u2203 n \u2265 N, \u2200 k < n, u k < u n :=\nbegin\n  intros N,\n  obtain \u27e8k : \u2115, hkn : k \u2264 N, hku : \u2200 l \u2264 N, u l \u2264 u k\u27e9 : \u2203 k \u2264 N, \u2200 l \u2264 N, u l \u2264 u k,\n    from exists_max_image _ u (finite_le_nat N) \u27e8N, le_refl N\u27e9,\n  have ex : \u2203 n \u2265 N, u k < u n,\n    from exists_lt_of_tendsto_at_top hu _ _,\n  obtain \u27e8n : \u2115, hnN : n \u2265 N, hnk : u k < u n, hn_min : \u2200 m, m < n \u2192 N \u2264 m \u2192 u m \u2264 u k\u27e9 :\n    \u2203 n \u2265 N, u k < u n \u2227 \u2200 m, m < n \u2192 N \u2264 m \u2192 u m \u2264 u k,\n  { rcases nat.find_x ex with \u27e8n, \u27e8hnN, hnk\u27e9, hn_min\u27e9,\n    push_neg at hn_min,\n    exact \u27e8n, hnN, hnk, hn_min\u27e9 },\n  use [n, hnN],\n  rintros (l : \u2115) (hl : l < n),\n  have hlk : u l \u2264 u k,\n  { cases (le_total l N : l \u2264 N \u2228 N \u2264 l) with H H,\n    { exact hku l H },\n    { exact hn_min l hl H } },\n  calc u l \u2264 u k : hlk\n       ... < u n : hnk\nend\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen after any point, it reaches a value strictly smaller than all previous values.\n-/\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma low_scores [linear_order \u03b2] [no_bot_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_bot) : \u2200 N, \u2203 n \u2265 N, \u2200 k < n, u n < u k :=\n@high_scores (order_dual \u03b2) _ _ _ hu\n\n/--\nIf `u` is a sequence which is unbounded above,\nthen it `frequently` reaches a value strictly greater than all previous values.\n-/\nlemma frequently_high_scores [linear_order \u03b2] [no_top_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_top) : \u2203\u1da0 n in at_top, \u2200 k < n, u k < u n :=\nby simpa [frequently_at_top] using high_scores hu\n\n/--\nIf `u` is a sequence which is unbounded below,\nthen it `frequently` reaches a value strictly smaller than all previous values.\n-/\nlemma frequently_low_scores [linear_order \u03b2] [no_bot_order \u03b2] {u : \u2115 \u2192 \u03b2}\n  (hu : tendsto u at_top at_bot) : \u2203\u1da0 n in at_top, \u2200 k < n, u n < u k :=\n@frequently_high_scores (order_dual \u03b2) _ _ _ hu\n\nlemma strict_mono_subseq_of_tendsto_at_top\n  {\u03b2 : Type*} [linear_order \u03b2] [no_top_order \u03b2]\n  {u : \u2115 \u2192 \u03b2} (hu : tendsto u at_top at_top) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\nlet \u27e8\u03c6, h, h'\u27e9 := extraction_of_frequently_at_top (frequently_high_scores hu) in\n\u27e8\u03c6, h, \u03bb n m hnm, h' m _ (h hnm)\u27e9\n\nlemma strict_mono_subseq_of_id_le {u : \u2115 \u2192 \u2115} (hu : \u2200 n, n \u2264 u n) :\n  \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 strict_mono (u \u2218 \u03c6) :=\nstrict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono hu tendsto_id)\n\nlemma _root_.strict_mono.tendsto_at_top {\u03c6 : \u2115 \u2192 \u2115} (h : strict_mono \u03c6) :\n  tendsto \u03c6 at_top at_top :=\ntendsto_at_top_mono h.id_le tendsto_id\n\nsection ordered_add_comm_monoid\n\nvariables [ordered_add_comm_monoid \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_add_nonneg_left' (hf : \u2200\u1da0 x in l, 0 \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (hf.mono (\u03bb x, le_add_of_nonneg_left)) hg\n\nlemma tendsto_at_bot_add_nonpos_left' (hf : \u2200\u1da0 x in l, f x \u2264 0) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left' _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_left (hf : \u2200 x, 0 \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_left' (eventually_of_forall hf) hg\n\nlemma tendsto_at_bot_add_nonpos_left (hf : \u2200 x, f x \u2264 0) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right' (hf : tendsto f l at_top) (hg : \u2200\u1da0 x in l, 0 \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (monotone_mem (\u03bb x, le_add_of_nonneg_right) hg) hf\n\nlemma tendsto_at_bot_add_nonpos_right' (hf : tendsto f l at_bot) (hg : \u2200\u1da0 x in l, g x \u2264 0) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right' _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right (hf : tendsto f l at_top) (hg : \u2200 x, 0 \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_right' hf (eventually_of_forall hg)\n\nlemma tendsto_at_bot_add_nonpos_right (hf : tendsto f l at_bot) (hg : \u2200 x, g x \u2264 0) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto_at_top_add (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_nonneg_left' (tendsto_at_top.mp hf 0) hg\n\nlemma tendsto_at_bot_add (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add _ (order_dual \u03b2) _ _ _ _ hf hg\n\nlemma tendsto.nsmul_at_top (hf : tendsto f l at_top) {n : \u2115} (hn : 0 < n) :\n  tendsto (\u03bb x, n \u2022 f x) l at_top :=\ntendsto_at_top.2 $ \u03bb y, (tendsto_at_top.1 hf y).mp $ (tendsto_at_top.1 hf 0).mono $ \u03bb x h\u2080 hy,\ncalc y \u2264 f x : hy\n... = 1 \u2022 f x : (one_nsmul _).symm\n... \u2264  n \u2022 f x : nsmul_le_nsmul h\u2080 hn\n\nlemma tendsto.nsmul_at_bot (hf : tendsto f l at_bot) {n : \u2115} (hn : 0 < n) :\n  tendsto (\u03bb x, n \u2022 f x) l at_bot :=\n@tendsto.nsmul_at_top \u03b1 (order_dual \u03b2) _ l f hf n hn\n\nlemma tendsto_bit0_at_top : tendsto bit0 (at_top : filter \u03b2) at_top :=\ntendsto_at_top_add tendsto_id tendsto_id\n\nlemma tendsto_bit0_at_bot : tendsto bit0 (at_bot : filter \u03b2) at_bot :=\ntendsto_at_bot_add tendsto_id tendsto_id\n\nend ordered_add_comm_monoid\n\nsection ordered_cancel_add_comm_monoid\n\nvariables [ordered_cancel_add_comm_monoid \u03b2] {l : filter \u03b1} {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_of_add_const_left (C : \u03b2) (hf : tendsto (\u03bb x, C + f x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (C + b)).mono (\u03bb x, le_of_add_le_add_left)\n\nlemma tendsto_at_bot_of_add_const_left (C : \u03b2) (hf : tendsto (\u03bb x, C + f x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_left _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_of_add_const_right (C : \u03b2) (hf : tendsto (\u03bb x, f x + C) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (b + C)).mono (\u03bb x, le_of_add_le_add_right)\n\nlemma tendsto_at_bot_of_add_const_right (C : \u03b2) (hf : tendsto (\u03bb x, f x + C) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_right _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_of_add_bdd_above_left' (C) (hC : \u2200\u1da0 x in l, f x \u2264 C)\n  (h : tendsto (\u03bb x, f x + g x) l at_top) :\n  tendsto g l at_top :=\ntendsto_at_top_of_add_const_left C\n  (tendsto_at_top_mono' l (hC.mono (\u03bb x hx, add_le_add_right hx (g x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_left' (C) (hC : \u2200\u1da0 x in l, C \u2264 f x)\n  (h : tendsto (\u03bb x, f x + g x) l at_bot) :\n  tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left' _ (order_dual \u03b2) _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_left (C) (hC : \u2200 x, f x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_top \u2192 tendsto g l at_top :=\ntendsto_at_top_of_add_bdd_above_left' C (univ_mem' hC)\n\nlemma tendsto_at_bot_of_add_bdd_below_left (C) (hC : \u2200 x, C \u2264 f x) :\n  tendsto (\u03bb x, f x + g x) l at_bot \u2192 tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left _ (order_dual \u03b2) _ _ _ _ C hC\n\nlemma tendsto_at_top_of_add_bdd_above_right' (C) (hC : \u2200\u1da0 x in l, g x \u2264 C)\n  (h : tendsto (\u03bb x, f x + g x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top_of_add_const_right C\n  (tendsto_at_top_mono' l (hC.mono (\u03bb x hx, add_le_add_left hx (f x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_right' (C) (hC : \u2200\u1da0 x in l, C \u2264 g x)\n  (h : tendsto (\u03bb x, f x + g x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right' _ (order_dual \u03b2) _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_right (C) (hC : \u2200 x, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_top \u2192 tendsto f l at_top :=\ntendsto_at_top_of_add_bdd_above_right' C (univ_mem' hC)\n\nlemma tendsto_at_bot_of_add_bdd_below_right (C) (hC : \u2200 x, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_bot \u2192 tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right _ (order_dual \u03b2) _ _ _ _ C hC\n\nend ordered_cancel_add_comm_monoid\n\nsection ordered_group\n\nvariables [ordered_add_comm_group \u03b2] (l : filter \u03b1) {f g : \u03b1 \u2192 \u03b2}\n\nlemma tendsto_at_top_add_left_of_le' (C : \u03b2) (hf : \u2200\u1da0 x in l, C \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_left' _ _ _ l (\u03bb x, -(f x)) (\u03bb x, f x + g x) (-C)\n  (by simpa) (by simpa)\n\nlemma tendsto_at_bot_add_left_of_ge' (C : \u03b2) (hf : \u2200\u1da0 x in l, f x \u2264 C) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le' _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_left_of_le (C : \u03b2) (hf : \u2200 x, C \u2264 f x) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_left_of_le' l C (univ_mem' hf) hg\n\nlemma tendsto_at_bot_add_left_of_ge (C : \u03b2) (hf : \u2200 x, f x \u2264 C) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le' (C : \u03b2) (hf : tendsto f l at_top) (hg : \u2200\u1da0 x in l, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_right' _ _ _ l (\u03bb x, f x + g x) (\u03bb x, -(g x)) (-C)\n  (by simp [hg]) (by simp [hf])\n\nlemma tendsto_at_bot_add_right_of_ge' (C : \u03b2) (hf : tendsto f l at_bot) (hg : \u2200\u1da0 x in l, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le' _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le (C : \u03b2) (hf : tendsto f l at_top) (hg : \u2200 x, C \u2264 g x) :\n  tendsto (\u03bb x, f x + g x) l at_top :=\ntendsto_at_top_add_right_of_le' l C hf (univ_mem' hg)\n\nlemma tendsto_at_bot_add_right_of_ge (C : \u03b2) (hf : tendsto f l at_bot) (hg : \u2200 x, g x \u2264 C) :\n  tendsto (\u03bb x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le _ (order_dual \u03b2) _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_const_left (C : \u03b2) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, C + f x) l at_top :=\ntendsto_at_top_add_left_of_le' l C (univ_mem' $ \u03bb _, le_refl C) hf\n\nlemma tendsto_at_bot_add_const_left (C : \u03b2) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, C + f x) l at_bot :=\n@tendsto_at_top_add_const_left _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_at_top_add_const_right (C : \u03b2) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, f x + C) l at_top :=\ntendsto_at_top_add_right_of_le' l C hf (univ_mem' $ \u03bb _, le_refl C)\n\nlemma tendsto_at_bot_add_const_right (C : \u03b2) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, f x + C) l at_bot :=\n@tendsto_at_top_add_const_right _ (order_dual \u03b2) _ _ _ C hf\n\nlemma tendsto_neg_at_top_at_bot : tendsto (has_neg.neg : \u03b2 \u2192 \u03b2) at_top at_bot :=\nbegin\n  simp only [tendsto_at_bot, neg_le],\n  exact \u03bb b, eventually_ge_at_top _\nend\n\nlemma tendsto_neg_at_bot_at_top : tendsto (has_neg.neg : \u03b2 \u2192 \u03b2) at_bot at_top :=\n@tendsto_neg_at_top_at_bot (order_dual \u03b2) _\n\nend ordered_group\n\nsection ordered_semiring\n\nvariables [ordered_semiring \u03b1] {l : filter \u03b2} {f g : \u03b2 \u2192 \u03b1}\n\nlemma tendsto_bit1_at_top : tendsto bit1 (at_top : filter \u03b1) at_top :=\ntendsto_at_top_add_nonneg_right tendsto_bit0_at_top (\u03bb _, zero_le_one)\n\nlemma tendsto.at_top_mul_at_top (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x * g x) l at_top :=\nbegin\n  refine tendsto_at_top_mono' _ _ hg,\n  filter_upwards [hg.eventually (eventually_ge_at_top 0), hf.eventually (eventually_ge_at_top 1)],\n  exact \u03bb x, le_mul_of_one_le_left\nend\n\nlemma tendsto_mul_self_at_top : tendsto (\u03bb x : \u03b1, x * x) at_top at_top :=\ntendsto_id.at_top_mul_at_top tendsto_id\n\n/-- The monomial function `x^n` tends to `+\u221e` at `+\u221e` for any positive natural `n`.\nA version for positive real powers exists as `tendsto_rpow_at_top`. -/\nlemma tendsto_pow_at_top {n : \u2115} (hn : 1 \u2264 n) : tendsto (\u03bb x : \u03b1, x ^ n) at_top at_top :=\nbegin\n  refine tendsto_at_top_mono' _ ((eventually_ge_at_top 1).mono $ \u03bb x hx, _) tendsto_id,\n  simpa only [pow_one] using pow_le_pow hx hn\nend\n\nlemma eventually_ne_of_tendsto_at_top [nontrivial \u03b1] (hf : tendsto f l at_top)\n  (c : \u03b1) :  \u2200\u1da0 x in l, f x \u2260 c :=\n(tendsto_at_top.1 hf $ (c + 1)).mono (\u03bb x hx, ne_of_gt (lt_of_lt_of_le (lt_add_one c) hx))\n\nend ordered_semiring\n\nlemma zero_pow_eventually_eq [monoid_with_zero \u03b1] :\n  (\u03bb n : \u2115, (0 : \u03b1) ^ n) =\u1da0[at_top] (\u03bb n, 0) :=\neventually_at_top.2 \u27e81, \u03bb n hn, zero_pow (zero_lt_one.trans_le hn)\u27e9\n\nsection ordered_ring\n\nvariables [ordered_ring \u03b1] {l : filter \u03b2} {f g : \u03b2 \u2192 \u03b1}\n\nlemma eventually_ne_of_tendsto_at_bot [nontrivial \u03b1] (hf : tendsto f l at_bot)\n  (c : \u03b1) : \u2200\u1da0 x in l, f x \u2260 c :=\n(tendsto_at_bot.1 hf $ (c - 1)).mono\n  (\u03bb x hx, ne_of_lt (lt_of_le_of_lt hx ((sub_lt_self_iff c).2 zero_lt_one)))\n\nlemma tendsto.at_top_mul_at_bot (hf : tendsto f l at_top) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x * g x) l at_bot :=\nhave _ := (hf.at_top_mul_at_top $ tendsto_neg_at_bot_at_top.comp hg),\nby simpa only [(\u2218), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp this\n\nlemma tendsto.at_bot_mul_at_top (hf : tendsto f l at_bot) (hg : tendsto g l at_top) :\n  tendsto (\u03bb x, f x * g x) l at_bot :=\nhave tendsto (\u03bb x, (-f x) * g x) l at_top :=\n  ( (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top hg),\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_at_top_at_bot.comp this\n\nlemma tendsto.at_bot_mul_at_bot (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :\n  tendsto (\u03bb x, f x * g x) l at_top :=\nhave tendsto (\u03bb x, (-f x) * (-g x)) l at_top :=\n  (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top (tendsto_neg_at_bot_at_top.comp hg),\nby simpa only [neg_mul_neg] using this\n\nend ordered_ring\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1]\n\n/-- $\\lim_{x\\to+\\infty}|x|=+\\infty$ -/\nlemma tendsto_abs_at_top_at_top : tendsto (abs : \u03b1 \u2192 \u03b1) at_top at_top :=\ntendsto_at_top_mono le_abs_self tendsto_id\n\n/-- $\\lim_{x\\to-\\infty}|x|=+\\infty$ -/\nlemma tendsto_abs_at_bot_at_top : tendsto (abs : \u03b1 \u2192 \u03b1) at_bot at_top :=\ntendsto_at_top_mono neg_le_abs_self tendsto_neg_at_bot_at_top\n\nend linear_ordered_add_comm_group\n\nsection linear_ordered_semiring\n\nvariables [linear_ordered_semiring \u03b1] {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1}\n\nlemma tendsto.at_top_of_const_mul {c : \u03b1} (hc : 0 < c) (hf : tendsto (\u03bb x, c * f x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ \u03bb b, (tendsto_at_top.1 hf (c * b)).mono $ \u03bb x hx, le_of_mul_le_mul_left hx hc\n\nlemma tendsto.at_top_of_mul_const {c : \u03b1} (hc : 0 < c) (hf : tendsto (\u03bb x, f x * c) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ \u03bb b, (tendsto_at_top.1 hf (b * c)).mono $ \u03bb x hx, le_of_mul_le_mul_right hx hc\n\nend linear_ordered_semiring\n\nlemma nonneg_of_eventually_pow_nonneg [linear_ordered_ring \u03b1] {a : \u03b1}\n  (h : \u2200\u1da0 n in at_top, 0 \u2264 a ^ (n : \u2115)) : 0 \u2264 a :=\nlet \u27e8n, hn\u27e9 := (tendsto_bit1_at_top.eventually h).exists in pow_bit1_nonneg_iff.1 hn\n\nsection linear_ordered_field\n\nvariables [linear_ordered_field \u03b1] {l : filter \u03b2} {f : \u03b2 \u2192 \u03b1} {r : \u03b1}\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the left) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.const_mul_at_top'` instead. -/\nlemma tendsto.const_mul_at_top (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, r * f x) l at_top :=\ntendsto.at_top_of_const_mul (inv_pos.2 hr) $ by simpa only [inv_mul_cancel_left\u2080 hr.ne']\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the right) also tends to infinity. For a version working in `\u2115` or `\u2124`, use\n`filter.tendsto.at_top_mul_const'` instead. -/\nlemma tendsto.at_top_mul_const (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, f x * r) l at_top :=\nby simpa only [mul_comm] using hf.const_mul_at_top hr\n\n/-- If a function tends to infinity along a filter, then this function divided by a positive\nconstant also tends to infinity. -/\nlemma tendsto.at_top_div_const (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, f x / r) l at_top :=\nby simpa only [div_eq_mul_inv] using hf.at_top_mul_const (inv_pos.2 hr)\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the left) tends to negative infinity. -/\nlemma tendsto.neg_const_mul_at_top (hr : r < 0) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, r * f x) l at_bot :=\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg]\n  using tendsto_neg_at_top_at_bot.comp (hf.const_mul_at_top (neg_pos.2 hr))\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a negative\nconstant (on the right) tends to negative infinity. -/\nlemma tendsto.at_top_mul_neg_const (hr : r < 0) (hf : tendsto f l at_top) :\n  tendsto (\u03bb x, f x * r) l at_bot :=\nby simpa only [mul_comm] using hf.neg_const_mul_at_top hr\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the left) also tends to negative infinity. -/\nlemma tendsto.const_mul_at_bot (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, r * f x) l at_bot :=\nby simpa only [(\u2218), neg_mul_eq_mul_neg, neg_neg]\n  using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).const_mul_at_top hr)\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na positive constant (on the right) also tends to negative infinity. -/\nlemma tendsto.at_bot_mul_const (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, f x * r) l at_bot :=\nby simpa only [mul_comm] using hf.const_mul_at_bot hr\n\n/-- If a function tends to negative infinity along a filter, then this function divided by\na positive constant also tends to negative infinity. -/\nlemma tendsto.at_bot_div_const (hr : 0 < r) (hf : tendsto f l at_bot) :\n  tendsto (\u03bbx, f x / r) l at_bot :=\nby simpa only [div_eq_mul_inv] using hf.at_bot_mul_const (inv_pos.2 hr)\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the left) tends to positive infinity. -/\nlemma tendsto.neg_const_mul_at_bot (hr : r < 0) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, r * f x) l at_top :=\nby simpa only [(\u2218), neg_mul_eq_neg_mul, neg_neg]\n  using tendsto_neg_at_bot_at_top.comp (hf.const_mul_at_bot (neg_pos.2 hr))\n\n/-- If a function tends to negative infinity along a filter, then this function multiplied by\na negative constant (on the right) tends to positive infinity. -/\nlemma tendsto.at_bot_mul_neg_const (hr : r < 0) (hf : tendsto f l at_bot) :\n  tendsto (\u03bb x, f x * r) l at_top :=\nby simpa only [mul_comm] using hf.neg_const_mul_at_bot hr\n\nlemma tendsto_const_mul_pow_at_top {c : \u03b1} {n : \u2115}\n  (hn : 1 \u2264 n) (hc : 0 < c) : tendsto (\u03bb x, c * x^n) at_top at_top :=\ntendsto.const_mul_at_top hc (tendsto_pow_at_top hn)\n\nlemma tendsto_const_mul_pow_at_top_iff (c : \u03b1) (n : \u2115) :\n  tendsto (\u03bb x, c * x^n) at_top at_top \u2194 1 \u2264 n \u2227 0 < c :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, tendsto_const_mul_pow_at_top h.1 h.2\u27e9,\n  simp only [tendsto_at_top, eventually_at_top] at h,\n  have : 0 < c := let \u27e8x, hx\u27e9 := h 1 in\n    pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one (hx (max x 1) (le_max_left x 1)))\n    (pow_nonneg (le_trans zero_le_one (le_max_right x 1)) n),\n  refine \u27e8nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (\u03bb hn, _))), this\u27e9,\n  obtain \u27e8x, hx\u27e9 := h (c + 1),\n  specialize hx x le_rfl,\n  rw [hn, pow_zero, mul_one, add_le_iff_nonpos_right] at hx,\n  exact absurd hx (not_le.mpr zero_lt_one),\nend\n\nlemma tendsto_neg_const_mul_pow_at_top {c : \u03b1} {n : \u2115}\n  (hn : 1 \u2264 n) (hc : c < 0) : tendsto (\u03bb x, c * x^n) at_top at_bot :=\ntendsto.neg_const_mul_at_top hc (tendsto_pow_at_top hn)\n\nlemma tendsto_neg_const_mul_pow_at_top_iff (c : \u03b1) (n : \u2115) :\n  tendsto (\u03bb x, c * x^n) at_top at_bot \u2194 1 \u2264 n \u2227 c < 0 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, tendsto_neg_const_mul_pow_at_top h.1 h.2\u27e9,\n  simp only [tendsto_at_bot, eventually_at_top] at h,\n  have : c < 0 := let \u27e8x, hx\u27e9 := h (-1) in\n    neg_of_mul_neg_right (lt_of_le_of_lt (hx (max x 1) (le_max_left x 1)) (by simp [zero_lt_one]))\n    (pow_nonneg (le_trans zero_le_one (le_max_right x 1)) n),\n  refine \u27e8nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (\u03bb hn, _))), this\u27e9,\n  obtain \u27e8x, hx\u27e9 := h (c - 1),\n  specialize hx x le_rfl,\n  rw [hn, pow_zero, mul_one, le_sub, sub_self] at hx,\n  exact absurd hx (not_le.mpr zero_lt_one),\nend\n\nend linear_ordered_field\n\nopen_locale filter\n\nlemma tendsto_at_top' [nonempty \u03b1] [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto f at_top l \u2194 (\u2200s \u2208 l, \u2203a, \u2200b\u2265a, f b \u2208 s) :=\nby simp only [tendsto_def, mem_at_top_sets]; refl\n\nlemma tendsto_at_bot' [nonempty \u03b1] [semilattice_inf \u03b1] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto f at_bot l \u2194 (\u2200s \u2208 l, \u2203a, \u2200b\u2264a, f b \u2208 s) :=\n@tendsto_at_top' (order_dual \u03b1) _ _ _ _ _\n\ntheorem tendsto_at_top_principal [nonempty \u03b2] [semilattice_sup \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n  tendsto f at_top (\ud835\udcdf s) \u2194 \u2203N, \u2200n\u2265N, f n \u2208 s :=\nby rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl\n\ntheorem tendsto_at_bot_principal [nonempty \u03b2] [semilattice_inf \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b1} :\n  tendsto f at_bot (\ud835\udcdf s) \u2194 \u2203N, \u2200n\u2264N, f n \u2208 s :=\n@tendsto_at_top_principal _ (order_dual \u03b2) _ _ _ _\n\n/-- A function `f` grows to `+\u221e` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_top_at_top [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_top at_top \u2194 \u2200 b : \u03b2, \u2203 i : \u03b1, \u2200 a : \u03b1, i \u2264 a \u2192 b \u2264 f a :=\niff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal\n\nlemma tendsto_at_top_at_bot [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_top at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), i \u2264 a \u2192 f a \u2264 b :=\n@tendsto_at_top_at_top \u03b1 (order_dual \u03b2) _ _ _ f\n\nlemma tendsto_at_bot_at_top [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_bot at_top \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 b \u2264 f a :=\n@tendsto_at_top_at_top (order_dual \u03b1) \u03b2 _ _ _ f\n\nlemma tendsto_at_bot_at_bot [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  tendsto f at_bot at_bot \u2194 \u2200 (b : \u03b2), \u2203 (i : \u03b1), \u2200 (a : \u03b1), a \u2264 i \u2192 f a \u2264 b :=\n@tendsto_at_top_at_top (order_dual \u03b1) (order_dual \u03b2) _ _ _ f\n\nlemma tendsto_at_top_at_top_of_monotone [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f)\n  (h : \u2200 b, \u2203 a, b \u2264 f a) :\n  tendsto f at_top at_top :=\ntendsto_infi.2 $ \u03bb b, tendsto_principal.2 $ let \u27e8a, ha\u27e9 := h b in\nmem_of_superset (mem_at_top a) $ \u03bb a' ha', le_trans ha (hf ha')\n\nlemma tendsto_at_bot_at_bot_of_monotone [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f)\n  (h : \u2200 b, \u2203 a, f a \u2264 b) :\n  tendsto f at_bot at_bot :=\ntendsto_infi.2 $ \u03bb b, tendsto_principal.2 $ let \u27e8a, ha\u27e9 := h b in\nmem_of_superset (mem_at_bot a) $ \u03bb a' ha', le_trans (hf ha') ha\n\nlemma tendsto_at_top_at_top_iff_of_monotone [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n  tendsto f at_top at_top \u2194 \u2200 b : \u03b2, \u2203 a : \u03b1, b \u2264 f a :=\ntendsto_at_top_at_top.trans $ forall_congr $ \u03bb b, exists_congr $ \u03bb a,\n  \u27e8\u03bb h, h a (le_refl a), \u03bb h a' ha', le_trans h $ hf ha'\u27e9\n\nlemma tendsto_at_bot_at_bot_iff_of_monotone [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : monotone f) :\n  tendsto f at_bot at_bot \u2194 \u2200 b : \u03b2, \u2203 a : \u03b1, f a \u2264 b :=\ntendsto_at_bot_at_bot.trans $ forall_congr $ \u03bb b, exists_congr $ \u03bb a,\n  \u27e8\u03bb h, h a (le_refl a), \u03bb h a' ha', le_trans (hf ha') h\u27e9\n\nalias tendsto_at_top_at_top_of_monotone \u2190 monotone.tendsto_at_top_at_top\nalias tendsto_at_bot_at_bot_of_monotone \u2190 monotone.tendsto_at_bot_at_bot\nalias tendsto_at_top_at_top_iff_of_monotone \u2190 monotone.tendsto_at_top_at_top_iff\nalias tendsto_at_bot_at_bot_iff_of_monotone \u2190 monotone.tendsto_at_bot_at_bot_iff\n\nlemma tendsto_at_top_embedding [preorder \u03b2] [preorder \u03b3]\n  {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1}\n  (hm : \u2200b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, c \u2264 e b) :\n  tendsto (e \u2218 f) l at_top \u2194 tendsto f l at_top :=\nbegin\n  refine \u27e8_, (tendsto_at_top_at_top_of_monotone (\u03bb b\u2081 b\u2082, (hm b\u2081 b\u2082).2) hu).comp\u27e9,\n  rw [tendsto_at_top, tendsto_at_top],\n  exact \u03bb hc b, (hc (e b)).mono (\u03bb a, (hm b (f a)).1)\nend\n\n/-- A function `f` goes to `-\u221e` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_bot_embedding [preorder \u03b2] [preorder \u03b3]\n  {f : \u03b1 \u2192 \u03b2} {e : \u03b2 \u2192 \u03b3} {l : filter \u03b1}\n  (hm : \u2200b\u2081 b\u2082, e b\u2081 \u2264 e b\u2082 \u2194 b\u2081 \u2264 b\u2082) (hu : \u2200c, \u2203b, e b \u2264 c) :\n  tendsto (e \u2218 f) l at_bot \u2194 tendsto f l at_bot :=\n@tendsto_at_top_embedding \u03b1 (order_dual \u03b2) (order_dual \u03b3) _ _ f e l (function.swap hm) hu\n\nlemma tendsto_finset_range : tendsto finset.range at_top at_top :=\nfinset.range_mono.tendsto_at_top_at_top finset.exists_nat_subset_range\n\nlemma at_top_finset_eq_infi : (at_top : filter $ finset \u03b1) = \u2a05 x : \u03b1, \ud835\udcdf (Ici {x}) :=\nbegin\n  refine le_antisymm (le_infi (\u03bb i, le_principal_iff.2 $ mem_at_top {i})) _,\n  refine le_infi (\u03bb s, le_principal_iff.2 $ mem_infi_of_Inter s.finite_to_set\n                  (\u03bb i, mem_principal_self _) _),\n  simp only [subset_def, mem_Inter, set_coe.forall, mem_Ici, finset.le_iff_subset,\n    finset.mem_singleton, finset.subset_iff, forall_eq], dsimp,\n  exact \u03bb t, id\nend\n\n/-- If `f` is a monotone sequence of `finset`s and each `x` belongs to one of `f n`, then\n`tendsto f at_top at_top`. -/\nlemma tendsto_at_top_finset_of_monotone [preorder \u03b2]\n  {f : \u03b2 \u2192 finset \u03b1} (h : monotone f) (h' : \u2200 x : \u03b1, \u2203 n, x \u2208 f n) :\n  tendsto f at_top at_top :=\nbegin\n  simp only [at_top_finset_eq_infi, tendsto_infi, tendsto_principal],\n  intro a,\n  rcases h' a with \u27e8b, hb\u27e9,\n  exact eventually.mono (mem_at_top b)\n    (\u03bb b' hb', le_trans (finset.singleton_subset_iff.2 hb) (h hb')),\nend\n\nalias tendsto_at_top_finset_of_monotone \u2190 monotone.tendsto_at_top_finset\n\nlemma tendsto_finset_image_at_top_at_top {i : \u03b2 \u2192 \u03b3} {j : \u03b3 \u2192 \u03b2} (h : function.left_inverse j i) :\n  tendsto (finset.image j) at_top at_top :=\n(finset.image_mono j).tendsto_at_top_finset $ assume a,\n  \u27e8{i a}, by simp only [finset.image_singleton, h a, finset.mem_singleton]\u27e9\n\nlemma tendsto_finset_preimage_at_top_at_top {f : \u03b1 \u2192 \u03b2} (hf : function.injective f) :\n  tendsto (\u03bb s : finset \u03b2, s.preimage f (hf.inj_on _)) at_top at_top :=\n(finset.monotone_preimage hf).tendsto_at_top_finset $\n  \u03bb x, \u27e8{f x}, finset.mem_preimage.2 $ finset.mem_singleton_self _\u27e9\n\nlemma prod_at_top_at_top_eq {\u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_sup \u03b2\u2081] [semilattice_sup \u03b2\u2082] :\n  (at_top : filter \u03b2\u2081) \u00d7\u1da0 (at_top : filter \u03b2\u2082) = (at_top : filter (\u03b2\u2081 \u00d7 \u03b2\u2082)) :=\nbegin\n  casesI (is_empty_or_nonempty \u03b2\u2081).symm,\n  casesI (is_empty_or_nonempty \u03b2\u2082).symm,\n  { simp [at_top, prod_infi_left, prod_infi_right, infi_prod],\n    exact infi_comm, },\n  { simp only [at_top.filter_eq_bot_of_is_empty, prod_bot] },\n  { simp only [at_top.filter_eq_bot_of_is_empty, bot_prod] },\nend\n\nlemma prod_at_bot_at_bot_eq {\u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_inf \u03b2\u2081] [semilattice_inf \u03b2\u2082] :\n  (at_bot : filter \u03b2\u2081) \u00d7\u1da0 (at_bot : filter \u03b2\u2082) = (at_bot : filter (\u03b2\u2081 \u00d7 \u03b2\u2082)) :=\n@prod_at_top_at_top_eq (order_dual \u03b2\u2081) (order_dual \u03b2\u2082) _ _\n\nlemma prod_map_at_top_eq {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_sup \u03b2\u2081] [semilattice_sup \u03b2\u2082]\n  (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n  (map u\u2081 at_top) \u00d7\u1da0 (map u\u2082 at_top) = map (prod.map u\u2081 u\u2082) at_top :=\nby rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def]\n\nlemma prod_map_at_bot_eq {\u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 : Type*} [semilattice_inf \u03b2\u2081] [semilattice_inf \u03b2\u2082]\n  (u\u2081 : \u03b2\u2081 \u2192 \u03b1\u2081) (u\u2082 : \u03b2\u2082 \u2192 \u03b1\u2082) :\n  (map u\u2081 at_bot) \u00d7\u1da0 (map u\u2082 at_bot) = map (prod.map u\u2081 u\u2082) at_bot :=\n@prod_map_at_top_eq _ _ (order_dual \u03b2\u2081) (order_dual \u03b2\u2082) _ _ _ _\n\nlemma tendsto.subseq_mem {F : filter \u03b1} {V : \u2115 \u2192 set \u03b1} (h : \u2200 n, V n \u2208 F) {u : \u2115 \u2192 \u03b1}\n  (hu : tendsto u at_top F) : \u2203 \u03c6 : \u2115 \u2192 \u2115, strict_mono \u03c6 \u2227 \u2200 n, u (\u03c6 n) \u2208 V n :=\nextraction_forall_of_eventually' (\u03bb n, tendsto_at_top'.mp hu _ (h n) : \u2200 n, \u2203 N, \u2200 k \u2265 N, u k \u2208 V n)\n\nlemma tendsto_at_bot_diagonal [semilattice_inf \u03b1] : tendsto (\u03bb a : \u03b1, (a, a)) at_bot at_bot :=\nby { rw \u2190 prod_at_bot_at_bot_eq, exact tendsto_id.prod_mk tendsto_id }\n\nlemma tendsto_at_top_diagonal [semilattice_sup \u03b1] : tendsto (\u03bb a : \u03b1, (a, a)) at_top at_top :=\nby { rw \u2190 prod_at_top_at_top_eq, exact tendsto_id.prod_mk tendsto_id }\n\nlemma tendsto.prod_map_prod_at_bot [semilattice_inf \u03b3] {F : filter \u03b1} {G : filter \u03b2}\n  {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3} (hf : tendsto f F at_bot) (hg : tendsto g G at_bot) :\n  tendsto (prod.map f g) (F \u00d7\u1da0 G) at_bot :=\nby { rw \u2190 prod_at_bot_at_bot_eq, exact hf.prod_map hg, }\n\nlemma tendsto.prod_map_prod_at_top [semilattice_sup \u03b3] {F : filter \u03b1} {G : filter \u03b2}\n  {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3} (hf : tendsto f F at_top) (hg : tendsto g G at_top) :\n  tendsto (prod.map f g) (F \u00d7\u1da0 G) at_top :=\nby { rw \u2190 prod_at_top_at_top_eq, exact hf.prod_map hg, }\n\nlemma tendsto.prod_at_bot [semilattice_inf \u03b1] [semilattice_inf \u03b3]\n  {f g : \u03b1 \u2192 \u03b3} (hf : tendsto f at_bot at_bot) (hg : tendsto g at_bot at_bot) :\n  tendsto (prod.map f g) at_bot at_bot :=\nby { rw \u2190 prod_at_bot_at_bot_eq, exact hf.prod_map_prod_at_bot hg, }\n\nlemma tendsto.prod_at_top [semilattice_sup \u03b1] [semilattice_sup \u03b3]\n  {f g : \u03b1 \u2192 \u03b3} (hf : tendsto f at_top at_top) (hg : tendsto g at_top at_top) :\n  tendsto (prod.map f g) at_top at_top :=\nby { rw \u2190 prod_at_top_at_top_eq, exact hf.prod_map_prod_at_top hg, }\n\nlemma eventually_at_bot_prod_self [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_bot, p x) \u2194 (\u2203 a, \u2200 k l, k \u2264 a \u2192 l \u2264 a \u2192 p (k, l)) :=\nby simp [\u2190 prod_at_bot_at_bot_eq, at_bot_basis.prod_self.eventually_iff]\n\nlemma eventually_at_top_prod_self [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_top, p x) \u2194 (\u2203 a, \u2200 k l, a \u2264 k \u2192 a \u2264 l \u2192 p (k, l)) :=\nby simp [\u2190 prod_at_top_at_top_eq, at_top_basis.prod_self.eventually_iff]\n\nlemma eventually_at_bot_prod_self' [semilattice_inf \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_bot, p x) \u2194 (\u2203 a, \u2200 k \u2264 a, \u2200 l \u2264 a, p (k, l)) :=\nbegin\n  rw filter.eventually_at_bot_prod_self,\n  apply exists_congr,\n  tauto,\nend\n\nlemma eventually_at_top_prod_self' [semilattice_sup \u03b1] [nonempty \u03b1] {p : \u03b1 \u00d7 \u03b1 \u2192 Prop} :\n  (\u2200\u1da0 x in at_top, p x) \u2194 (\u2203 a, \u2200 k \u2265 a, \u2200 l \u2265 a, p (k, l)) :=\nbegin\n  rw filter.eventually_at_top_prod_self,\n  apply exists_congr,\n  tauto,\nend\n\n/-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a\nGalois insertion. The Galois \"insertion\" and \"connection\" is weakened to only require it to be an\ninsertion and a connetion above `b'`. -/\nlemma map_at_top_eq_of_gc [semilattice_sup \u03b1] [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2)\n  (hf : monotone f) (gc : \u2200a, \u2200b\u2265b', f a \u2264 b \u2194 a \u2264 g b) (hgi : \u2200b\u2265b', b \u2264 f (g b)) :\n  map f at_top = at_top :=\nbegin\n  refine le_antisymm\n    (hf.tendsto_at_top_at_top $ \u03bb b, \u27e8g (b \u2294 b'), le_sup_left.trans $ hgi _ le_sup_right\u27e9) _,\n  rw [@map_at_top_eq _ _ \u27e8g b'\u27e9],\n  refine le_infi (\u03bb a, infi_le_of_le (f a \u2294 b') $ principal_mono.2 $ \u03bb b hb, _),\n  rw [mem_Ici, sup_le_iff] at hb,\n  exact \u27e8g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 (le_refl _)) (hgi _ hb.2)\u27e9\nend\n\nlemma map_at_bot_eq_of_gc [semilattice_inf \u03b1] [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} (g : \u03b2 \u2192 \u03b1) (b' : \u03b2)\n  (hf : monotone f) (gc : \u2200a, \u2200b\u2264b', b \u2264 f a \u2194 g b \u2264 a) (hgi : \u2200b\u2264b', f (g b) \u2264 b) :\n  map f at_bot = at_bot :=\n@map_at_top_eq_of_gc (order_dual \u03b1) (order_dual \u03b2) _ _ _ _ _ hf.dual gc hgi\n\nlemma map_coe_at_top_of_Ici_subset [semilattice_sup \u03b1] {a : \u03b1} {s : set \u03b1} (h : Ici a \u2286 s) :\n  map (coe : s \u2192 \u03b1) at_top = at_top :=\nbegin\n  have : directed (\u2265) (\u03bb x : s, \ud835\udcdf (Ici x)),\n  { intros x y,\n    use \u27e8x \u2294 y \u2294 a, h le_sup_right\u27e9,\n    simp only [ge_iff_le, principal_mono, Ici_subset_Ici, \u2190 subtype.coe_le_coe, subtype.coe_mk],\n    exact \u27e8le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left\u27e9 },\n  haveI : nonempty s := \u27e8\u27e8a, h le_rfl\u27e9\u27e9,\n  simp only [le_antisymm_iff, at_top, le_infi_iff, le_principal_iff, mem_map, mem_set_of_eq,\n    map_infi_eq this, map_principal],\n  split,\n  { intro x,\n    refine mem_of_superset (mem_infi_of_mem \u27e8x \u2294 a, h le_sup_right\u27e9 (mem_principal_self _)) _,\n    rintro _ \u27e8y, hy, rfl\u27e9,\n    exact le_trans le_sup_left (subtype.coe_le_coe.2 hy) },\n  { intro x,\n    filter_upwards [mem_at_top (\u2191x \u2294 a)],\n    intros b hb,\n    exact \u27e8\u27e8b, h $ le_sup_right.trans hb\u27e9, subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl\u27e9 }\nend\n\n/-- The image of the filter `at_top` on `Ici a` under the coercion equals `at_top`. -/\n@[simp] lemma map_coe_Ici_at_top [semilattice_sup \u03b1] (a : \u03b1) :\n  map (coe : Ici a \u2192 \u03b1) at_top = at_top :=\nmap_coe_at_top_of_Ici_subset (subset.refl _)\n\n/-- The image of the filter `at_top` on `Ioi a` under the coercion equals `at_top`. -/\n@[simp] lemma map_coe_Ioi_at_top [semilattice_sup \u03b1] [no_top_order \u03b1] (a : \u03b1) :\n  map (coe : Ioi a \u2192 \u03b1) at_top = at_top :=\nbegin\n  rcases no_top a with \u27e8b, hb\u27e9,\n  exact map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb)\nend\n\n/-- The `at_top` filter for an open interval `Ioi a` comes from the `at_top` filter in the ambient\norder. -/\nlemma at_top_Ioi_eq [semilattice_sup \u03b1] (a : \u03b1) :\n  at_top = comap (coe : Ioi a \u2192 \u03b1) at_top :=\nbegin\n  nontriviality,\n  rcases nontrivial_iff_nonempty.1 \u2039_\u203a with \u27e8b, hb\u27e9,\n  rw [\u2190 map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map subtype.coe_injective]\nend\n\n/-- The `at_top` filter for an open interval `Ici a` comes from the `at_top` filter in the ambient\norder. -/\nlemma at_top_Ici_eq [semilattice_sup \u03b1] (a : \u03b1) :\n  at_top = comap (coe : Ici a \u2192 \u03b1) at_top :=\nby rw [\u2190 map_coe_Ici_at_top a, comap_map subtype.coe_injective]\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] lemma map_coe_Iio_at_bot [semilattice_inf \u03b1] [no_bot_order \u03b1] (a : \u03b1) :\n  map (coe : Iio a \u2192 \u03b1) at_bot = at_bot :=\n@map_coe_Ioi_at_top (order_dual \u03b1) _ _ _\n\n/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient\norder. -/\nlemma at_bot_Iio_eq [semilattice_inf \u03b1] (a : \u03b1) :\n  at_bot = comap (coe : Iio a \u2192 \u03b1) at_bot :=\n@at_top_Ioi_eq (order_dual \u03b1) _ _\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\n@[simp] lemma map_coe_Iic_at_bot [semilattice_inf \u03b1] (a : \u03b1) :\n  map (coe : Iic a \u2192 \u03b1) at_bot = at_bot :=\n@map_coe_Ici_at_top (order_dual \u03b1) _ _\n\n/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient\norder. -/\nlemma at_bot_Iic_eq [semilattice_inf \u03b1] (a : \u03b1) :\n  at_bot = comap (coe : Iic a \u2192 \u03b1) at_bot :=\n@at_top_Ici_eq (order_dual \u03b1) _ _\n\nlemma tendsto_Ioi_at_top [semilattice_sup \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Ioi a}\n  {l : filter \u03b2} :\n  tendsto f l at_top \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_top :=\nby rw [at_top_Ioi_eq, tendsto_comap_iff]\n\nlemma tendsto_Iio_at_bot [semilattice_inf \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Iio a}\n  {l : filter \u03b2} :\n  tendsto f l at_bot \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_bot :=\nby rw [at_bot_Iio_eq, tendsto_comap_iff]\n\nlemma tendsto_Ici_at_top [semilattice_sup \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Ici a} {l : filter \u03b2} :\n  tendsto f l at_top \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_top :=\nby rw [at_top_Ici_eq, tendsto_comap_iff]\n\nlemma tendsto_Iic_at_bot [semilattice_inf \u03b1] {a : \u03b1} {f : \u03b2 \u2192 Iic a} {l : filter \u03b2} :\n  tendsto f l at_bot \u2194 tendsto (\u03bb x, (f x : \u03b1)) l at_bot :=\nby rw [at_bot_Iic_eq, tendsto_comap_iff]\n\n@[simp] lemma tendsto_comp_coe_Ioi_at_top [semilattice_sup \u03b1] [no_top_order \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Ioi a, f x) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 map_coe_Ioi_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Ici_at_top [semilattice_sup \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Ici a, f x) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 map_coe_Ici_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iio_at_bot [semilattice_inf \u03b1] [no_bot_order \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Iio a, f x) at_bot l \u2194 tendsto f at_bot l :=\nby rw [\u2190 map_coe_Iio_at_bot a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iic_at_bot [semilattice_inf \u03b1] {a : \u03b1}\n  {f : \u03b1 \u2192 \u03b2} {l : filter \u03b2} :\n  tendsto (\u03bb x : Iic a, f x) at_bot l \u2194 tendsto f at_bot l :=\nby rw [\u2190 map_coe_Iic_at_bot a, tendsto_map'_iff]\n\nlemma map_add_at_top_eq_nat (k : \u2115) : map (\u03bba, a + k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bba, a - k) k\n  (assume a b h, add_le_add_right h k)\n  (assume a b h, (le_tsub_iff_right h).symm)\n  (assume a h, by rw [tsub_add_cancel_of_le h])\n\nlemma map_sub_at_top_eq_nat (k : \u2115) : map (\u03bba, a - k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bba, a + k) 0\n  (assume a b h, tsub_le_tsub_right h _)\n  (assume a b _, tsub_le_iff_right)\n  (assume b _, by rw [add_tsub_cancel_right])\n\nlemma tendsto_add_at_top_nat (k : \u2115) : tendsto (\u03bba, a + k) at_top at_top :=\nle_of_eq (map_add_at_top_eq_nat k)\n\nlemma tendsto_sub_at_top_nat (k : \u2115) : tendsto (\u03bba, a - k) at_top at_top :=\nle_of_eq (map_sub_at_top_eq_nat k)\n\nlemma tendsto_add_at_top_iff_nat {f : \u2115 \u2192 \u03b1} {l : filter \u03b1} (k : \u2115) :\n  tendsto (\u03bbn, f (n + k)) at_top l \u2194 tendsto f at_top l :=\nshow tendsto (f \u2218 (\u03bbn, n + k)) at_top l \u2194 tendsto f at_top l,\n  by rw [\u2190 tendsto_map'_iff, map_add_at_top_eq_nat]\n\nlemma map_div_at_top_eq_nat (k : \u2115) (hk : 0 < k) : map (\u03bba, a / k) at_top = at_top :=\nmap_at_top_eq_of_gc (\u03bbb, b * k + (k - 1)) 1\n  (assume a b h, nat.div_le_div_right h)\n  (assume a b _,\n    calc a / k \u2264 b \u2194 a / k < b + 1 : by rw [\u2190 nat.succ_eq_add_one, nat.lt_succ_iff]\n      ... \u2194 a < (b + 1) * k : nat.div_lt_iff_lt_mul _ _ hk\n      ... \u2194 _ :\n      begin\n        cases k,\n        exact (lt_irrefl _ hk).elim,\n        rw [add_mul, one_mul, nat.succ_sub_succ_eq_sub,\n          tsub_zero, nat.add_succ, nat.lt_succ_iff],\n      end)\n  (assume b _,\n    calc b = (b * k) / k : by rw [nat.mul_div_cancel b hk]\n      ... \u2264 (b * k + (k - 1)) / k : nat.div_le_div_right $ nat.le_add_right _ _)\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nabove, then `tendsto u at_top at_top`. -/\nlemma tendsto_at_top_at_top_of_monotone' [preorder \u03b9] [linear_order \u03b1]\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_above (range u)) :\n  tendsto u at_top at_top :=\nbegin\n  apply h.tendsto_at_top_at_top,\n  intro b,\n  rcases not_bdd_above_iff.1 H b with \u27e8_, \u27e8N, rfl\u27e9, hN\u27e9,\n  exact \u27e8N, le_of_lt hN\u27e9,\nend\n\n/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded\nbelow, then `tendsto u at_bot at_bot`. -/\nlemma tendsto_at_bot_at_bot_of_monotone' [preorder \u03b9] [linear_order \u03b1]\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) (H : \u00acbdd_below (range u)) :\n  tendsto u at_bot at_bot :=\n@tendsto_at_top_at_top_of_monotone' (order_dual \u03b9) (order_dual \u03b1) _ _ _ h.dual H\n\nlemma unbounded_of_tendsto_at_top [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] [no_top_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_top) :\n  \u00ac bdd_above (range f) :=\nbegin\n  rintros \u27e8M, hM\u27e9,\n  cases mem_at_top_sets.mp (h $ Ioi_mem_at_top M) with a ha,\n  apply lt_irrefl M,\n  calc\n  M < f a : ha a (le_refl _)\n  ... \u2264 M : hM (set.mem_range_self a)\nend\n\nlemma unbounded_of_tendsto_at_bot [nonempty \u03b1] [semilattice_sup \u03b1] [preorder \u03b2] [no_bot_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_top at_bot) :\n  \u00ac bdd_below (range f) :=\n@unbounded_of_tendsto_at_top _ (order_dual \u03b2) _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_top' [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] [no_top_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_top) :\n  \u00ac bdd_above (range f) :=\n@unbounded_of_tendsto_at_top (order_dual \u03b1) _ _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_bot' [nonempty \u03b1] [semilattice_inf \u03b1] [preorder \u03b2] [no_bot_order \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (h : tendsto f at_bot at_bot) :\n  \u00ac bdd_below (range f) :=\n@unbounded_of_tendsto_at_top (order_dual \u03b1) (order_dual \u03b2) _ _ _ _ _ h\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_top` along *some* non-trivial filter `l`, then\nit tends to `at_top` along `at_top`. -/\nlemma tendsto_at_top_of_monotone_of_filter [preorder \u03b9] [preorder \u03b1] {l : filter \u03b9}\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_top) :\n  tendsto u at_top at_top :=\nh.tendsto_at_top_at_top $ \u03bb b, (hu.eventually (mem_at_top b)).exists\n\n/-- If a monotone function `u : \u03b9 \u2192 \u03b1` tends to `at_bot` along *some* non-trivial filter `l`, then\nit tends to `at_bot` along `at_bot`. -/\nlemma tendsto_at_bot_of_monotone_of_filter [preorder \u03b9] [preorder \u03b1] {l : filter \u03b9}\n  {u : \u03b9 \u2192 \u03b1} (h : monotone u) [ne_bot l] (hu : tendsto u l at_bot) :\n  tendsto u at_bot at_bot :=\n@tendsto_at_top_of_monotone_of_filter (order_dual \u03b9) (order_dual \u03b1) _ _ _ _ h.dual _ hu\n\nlemma tendsto_at_top_of_monotone_of_subseq [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1}\n  {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n  (H : tendsto (u \u2218 \u03c6) l at_top) :\n  tendsto u at_top at_top :=\ntendsto_at_top_of_monotone_of_filter h (tendsto_map' H)\n\nlemma tendsto_at_bot_of_monotone_of_subseq [preorder \u03b9] [preorder \u03b1] {u : \u03b9 \u2192 \u03b1}\n  {\u03c6 : \u03b9' \u2192 \u03b9} (h : monotone u) {l : filter \u03b9'} [ne_bot l]\n  (H : tendsto (u \u2218 \u03c6) l at_bot) :\n  tendsto u at_bot at_bot :=\ntendsto_at_bot_of_monotone_of_filter h (tendsto_map' H)\n\n/-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient\ncondition for comparison of the filter `at_top.map (\u03bb s, \u220f b in s, f b)` with\n`at_top.map (\u03bb s, \u220f b in s, g b)`. This is useful to compare the set of limit points of\n`\u03a0 b in s, f b` as `s \u2192 at_top` with the similar set for `g`. -/\n@[to_additive]\nlemma map_at_top_finset_prod_le_of_prod_eq [comm_monoid \u03b1] {f : \u03b2 \u2192 \u03b1} {g : \u03b3 \u2192 \u03b1}\n  (h_eq : \u2200u:finset \u03b3, \u2203v:finset \u03b2, \u2200v', v \u2286 v' \u2192 \u2203u', u \u2286 u' \u2227 \u220f x in u', g x = \u220f b in v', f b) :\n  at_top.map (\u03bbs:finset \u03b2, \u220f b in s, f b) \u2264 at_top.map (\u03bbs:finset \u03b3, \u220f x in s, g x) :=\nby rw [map_at_top_eq, map_at_top_eq];\nfrom (le_infi $ assume b, let \u27e8v, hv\u27e9 := h_eq b in infi_le_of_le v $\n  by simp [set.image_subset_iff]; exact hv)\n\nlemma has_antitone_basis.tendsto [semilattice_sup \u03b9] [nonempty \u03b9] {l : filter \u03b1}\n  {s : \u03b9 \u2192 set \u03b1} (hl : l.has_antitone_basis s) {\u03c6 : \u03b9 \u2192 \u03b1}\n  (h : \u2200 i : \u03b9, \u03c6 i \u2208 s i) : tendsto \u03c6 at_top l  :=\n(at_top_basis.tendsto_iff hl.to_has_basis).2 $ assume i hi,\n  \u27e8i, trivial, \u03bb j hij, hl.antitone hij (h _)\u27e9\n\n/-- If `f` is a nontrivial countably generated filter, then there exists a sequence that converges\nto `f`. -/\nlemma exists_seq_tendsto (f : filter \u03b1) [is_countably_generated f] [ne_bot f] :\n  \u2203 x : \u2115 \u2192 \u03b1, tendsto x at_top f :=\nbegin\n  obtain \u27e8B, h\u27e9 := f.exists_antitone_basis,\n  have := \u03bb n, nonempty_of_mem (h.to_has_basis.mem_of_mem trivial : B n \u2208 f), choose x hx,\n  exact \u27e8x, h.tendsto hx\u27e9\nend\n\n/-- An abstract version of continuity of sequentially continuous functions on metric spaces:\nif a filter `k` is countably generated then `tendsto f k l` iff for every sequence `u`\nconverging to `k`, `f \u2218 u` tends to `l`. -/\nlemma tendsto_iff_seq_tendsto {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1} {l : filter \u03b2} [k.is_countably_generated] :\n  tendsto f k l \u2194 (\u2200 x : \u2115 \u2192 \u03b1, tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) :=\nbegin\n  refine \u27e8\u03bb h x hx, h.comp hx, \u03bb H s hs, _\u27e9,\n  contrapose! H,\n  haveI : ne_bot (k \u2293 \ud835\udcdf (f \u207b\u00b9' s\u1d9c)), by simpa [ne_bot_iff,  inf_principal_eq_bot],\n  rcases (k \u2293 \ud835\udcdf (f \u207b\u00b9' s\u1d9c)).exists_seq_tendsto with \u27e8x, hx\u27e9,\n  rw [tendsto_inf, tendsto_principal] at hx,\n  refine \u27e8x, hx.1, \u03bb h, _\u27e9,\n  rcases (hx.2.and (h hs)).exists with \u27e8N, hnmem, hmem\u27e9,\n  exact hnmem hmem\nend\n\nlemma tendsto_of_seq_tendsto {f : \u03b1 \u2192 \u03b2} {k : filter \u03b1} {l : filter \u03b2} [k.is_countably_generated] :\n  (\u2200 x : \u2115 \u2192 \u03b1, tendsto x at_top k \u2192 tendsto (f \u2218 x) at_top l) \u2192 tendsto f k l :=\ntendsto_iff_seq_tendsto.2\n\nlemma subseq_tendsto_of_ne_bot {f : filter \u03b1} [is_countably_generated f] {u : \u2115 \u2192 \u03b1}\n  (hx : ne_bot (f \u2293 map u at_top)) :\n  \u2203 (\u03b8 : \u2115 \u2192 \u2115), (strict_mono \u03b8) \u2227 (tendsto (u \u2218 \u03b8) at_top f) :=\nbegin\n  obtain \u27e8B, h\u27e9 := f.exists_antitone_basis,\n  have : \u2200 N, \u2203 n \u2265 N, u n \u2208 B N,\n    from \u03bb N, filter.inf_map_at_top_ne_bot_iff.mp hx _ (h.to_has_basis.mem_of_mem trivial) N,\n  choose \u03c6 h\u03c6 using this,\n  cases forall_and_distrib.mp h\u03c6 with \u03c6_ge \u03c6_in,\n  have lim_u\u03c6 : tendsto (u \u2218 \u03c6) at_top f,\n    from h.tendsto \u03c6_in,\n  have lim_\u03c6 : tendsto \u03c6 at_top at_top,\n    from (tendsto_at_top_mono \u03c6_ge tendsto_id),\n  obtain \u27e8\u03c8, h\u03c8, h\u03c8\u03c6\u27e9 : \u2203 \u03c8 : \u2115 \u2192 \u2115, strict_mono \u03c8 \u2227 strict_mono (\u03c6 \u2218 \u03c8),\n    from strict_mono_subseq_of_tendsto_at_top lim_\u03c6,\n  exact \u27e8\u03c6 \u2218 \u03c8, h\u03c8\u03c6, lim_u\u03c6.comp h\u03c8.tendsto_at_top\u27e9,\nend\n\nend filter\n\nopen filter finset\n\nsection\n\nvariables {R : Type*} [linear_ordered_semiring R]\n\nlemma exists_lt_mul_self (a : R) : \u2203 x \u2265 0, a < x * x :=\nlet \u27e8x, hxa, hx0\u27e9 :=((tendsto_mul_self_at_top.eventually (eventually_gt_at_top a)).and\n  (eventually_ge_at_top 0)).exists\nin \u27e8x, hx0, hxa\u27e9\n\nlemma exists_le_mul_self (a : R) : \u2203 x \u2265 0, a \u2264 x * x :=\nlet \u27e8x, hx0, hxa\u27e9 := exists_lt_mul_self a in \u27e8x, hx0, hxa.le\u27e9\n\nend\n\nnamespace order_iso\n\nvariables [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma comap_at_top (e : \u03b1 \u2243o \u03b2) : comap e at_top = at_top :=\nby simp [at_top, \u2190 e.surjective.infi_comp]\n\n@[simp] lemma comap_at_bot (e : \u03b1 \u2243o \u03b2) : comap e at_bot = at_bot :=\ne.dual.comap_at_top\n\n@[simp] lemma map_at_top (e : \u03b1 \u2243o \u03b2) : map (e : \u03b1 \u2192 \u03b2) at_top = at_top :=\nby rw [\u2190 e.comap_at_top, map_comap_of_surjective e.surjective]\n\n@[simp] lemma map_at_bot (e : \u03b1 \u2243o \u03b2) : map (e : \u03b1 \u2192 \u03b2) at_bot = at_bot :=\ne.dual.map_at_top\n\nlemma tendsto_at_top (e : \u03b1 \u2243o \u03b2) : tendsto e at_top at_top :=\ne.map_at_top.le\n\nlemma tendsto_at_bot (e : \u03b1 \u2243o \u03b2) : tendsto e at_bot at_bot :=\ne.map_at_bot.le\n\n@[simp] lemma tendsto_at_top_iff {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n  tendsto (\u03bb x, e (f x)) l at_top \u2194 tendsto f l at_top :=\nby rw [\u2190 e.comap_at_top, tendsto_comap_iff]\n\n@[simp] lemma tendsto_at_bot_iff {l : filter \u03b3} {f : \u03b3 \u2192 \u03b1} (e : \u03b1 \u2243o \u03b2) :\n  tendsto (\u03bb x, e (f x)) l at_bot \u2194 tendsto f l at_bot :=\ne.dual.tendsto_at_top_iff\n\nend order_iso\n\n/-- Let `g : \u03b3 \u2192 \u03b2` be an injective function and `f : \u03b2 \u2192 \u03b1` be a function from the codomain of `g`\nto a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters\n`at_top.map (\u03bb s, \u220f i in s, f (g i))` and `at_top.map (\u03bb s, \u220f i in s, f i)` coincide.\n\nThe additive version of this lemma is used to prove the equality `\u2211' x, f (g x) = \u2211' y, f y` under\nthe same assumptions.-/\n@[to_additive]\nlemma function.injective.map_at_top_finset_prod_eq [comm_monoid \u03b1] {g : \u03b3 \u2192 \u03b2}\n  (hg : function.injective g) {f : \u03b2 \u2192 \u03b1} (hf : \u2200 x \u2209 set.range g, f x = 1) :\n  map (\u03bb s, \u220f i in s, f (g i)) at_top = map (\u03bb s, \u220f i in s, f i) at_top :=\nbegin\n  apply le_antisymm; refine map_at_top_finset_prod_le_of_prod_eq (\u03bb s, _),\n  { refine \u27e8s.preimage g (hg.inj_on _), \u03bb t ht, _\u27e9,\n    refine \u27e8t.image g \u222a s, finset.subset_union_right _ _, _\u27e9,\n    rw [\u2190 finset.prod_image (hg.inj_on _)],\n    refine (prod_subset (subset_union_left _ _) _).symm,\n    simp only [finset.mem_union, finset.mem_image],\n    refine \u03bb y hy hyt, hf y (mt _ hyt),\n    rintros \u27e8x, rfl\u27e9,\n    exact \u27e8x, ht (finset.mem_preimage.2 $ hy.resolve_left hyt), rfl\u27e9 },\n  { refine \u27e8s.image g, \u03bb t ht, _\u27e9,\n    simp only [\u2190 prod_preimage _ _ (hg.inj_on _) _ (\u03bb x _, hf x)],\n    exact \u27e8_, (image_subset_iff_subset_preimage _).1 ht, rfl\u27e9 }\nend\n\n/-- Let `g : \u03b3 \u2192 \u03b2` be an injective function and `f : \u03b2 \u2192 \u03b1` be a function from the codomain of `g`\nto an additive commutative monoid. Suppose that `f x = 0` outside of the range of `g`. Then the\nfilters `at_top.map (\u03bb s, \u2211 i in s, f (g i))` and `at_top.map (\u03bb s, \u2211 i in s, f i)` coincide.\n\nThis lemma is used to prove the equality `\u2211' x, f (g x) = \u2211' y, f y` under\nthe same assumptions.-/\nadd_decl_doc function.injective.map_at_top_finset_sum_eq\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/order/filter/at_top_bot.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7184836856047376}}
{"text": "universes u v\n\nsection\nvariables (V : Type u) (F : inout Type v)\n\nclass has_scalar_mul :=\n(scalar_mul : F \u2192 V \u2192 V)\n\nreserve infixl ` \u22c5 `:70\ninfix \u22c5 := has_scalar_mul.scalar_mul\n\nclass vector_space [field F] extends add_comm_group V, has_scalar_mul V F :=\n(scalar_mul_assoc         : \u2200 (a b : F) (v : V), (a * b) \u22c5 v = a \u22c5 (b \u22c5 v))\n(one_scalar_mul           : \u2200 v : V,             (1 : F) \u22c5 v = v)\n(scalar_mul_left_distrib  : \u2200 (a : F) (u v : V), a \u22c5 (u + v) = a \u22c5 u + a \u22c5 v)\n(scalar_mul_right_distrib : \u2200 (a b : F) (v : V), (a + b) \u22c5 v = a \u22c5 v + b \u22c5 v)\nend\n\nopen vector_space\n\nattribute [simp]\none_scalar_mul scalar_mul_left_distrib scalar_mul_right_distrib\n\nvariables {V : Type u} {F : Type v} [field F] [vector_space V F]\n\n@[simp] lemma zero_scalar_mul_zero (v : V) : (0 : F) \u22c5 v = 0 :=\nhave (0 : F) \u22c5 v + (0 : F) \u22c5 v = (0 : F) \u22c5 v + 0,\n  by rw \u2190scalar_mul_right_distrib; simp,\nadd_left_cancel this\n\n@[simp] lemma scalar_mul_zero_zero (a : F) : a \u22c5 (0 : V) = 0 :=\nhave a \u22c5 0 + a \u22c5 0 = a \u22c5 (0 : V) + 0,\n  by rw \u2190scalar_mul_left_distrib; simp,\nadd_left_cancel this\n\n@[simp] lemma neg_one_scalar_mul_neg (v : V) : (-1 : F) \u22c5 v = -v :=\nhave (-1 : F) \u22c5 v + v = 0, from calc\n(-1 : F) \u22c5 v + v = (-1 : F) \u22c5 v + (1 : F) \u22c5 v : by simp\n             ... = (-1 + 1 : F) \u22c5 v           : by rw \u2190scalar_mul_right_distrib\n             ... = 0                          : by simp,\neq_neg_of_add_eq_zero this\n\nlemma neg_scalar_mul_neg (a : F) (v : V) : -a \u22c5 v = -(a \u22c5 v) :=\nby rw [neg_eq_neg_one_mul, scalar_mul_assoc]; simp\n", "meta": {"author": "ssomayyajula", "repo": "linear", "sha": "dcf28df05e06da1b4fc76bce61b8fa0741300dc8", "save_path": "github-repos/lean/ssomayyajula-linear", "path": "github-repos/lean/ssomayyajula-linear/linear-dcf28df05e06da1b4fc76bce61b8fa0741300dc8/vector_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7184795816346625}}
{"text": "-- \u2200x(F(x) \u2227 G(x)) \u22a2 F(c)\n\nvariable(F G : \u2115 \u2192 Prop)\nvariable(b c d : \u2115)\n\nexample (h1 : \u2200 x : \u2115, F x \u2227 G x): F c :=\n  (h1 $ c).left\n\n\n-- \u2200xF(x), (F(c) \u2192 G(c)) \u22a2 G(c)\nexample (h1 : \u2200 x : \u2115, F x) (h2 : F c \u2192 G c) : G c :=\n  h2 $ (h1 $ c)\n\n-- \u2200x\u2200y(F(x) \u2192 G(y)), F(c) \u22a2 G(d)\nexample (h1 : \u2200 x : \u2115, \u2200 y : \u2115, F x \u2192 G y) (h2 : F c) : G d :=\n  ((h1 $ c) $ d) $ h2\n\n-- \u2200x\u2200y(F(x) \u2194 G(y)), F(c) \u22a2 F(d)\nexample (h1 : \u2200 x y : \u2115, F x \u2194 G y) (h2 : F c) : G d :=\n  ((h1 $ c) $ d).mp $ h2\n\n\n-- \u2200xF(x), ((F(b) \u2227 F(c)) \u2192 G(c)) \u22a2 \u2203xG(x)\nexample (h1 : \u2200 x : \u2115,  F x) (h2 :(F b \u2227 F c) \u2192 G c) : \u2203 x : \u2115, G x :=\n \u27e8 c, (h2 $ (And.intro (h1 $ b) (h1 $ c))) \u27e9 \n\n -- |- \u2200x (F(x) -> Ey F(y))\n example : \u2200 x: \u2115, F x \u2192 \u2203 y : \u2115,  F y := \n  fun x : \u2115 => (fun h1 : F x => \u27e8x, h1\u27e9)\n\n-- \u2200x(F(x) \u2192 G(x)), \u2200xF(x) \u22a2 \u2200xG(x)\n\nexample (h1 : \u2200 x : \u2115, F x \u2192 G x) (h2: \u2200 x : \u2115, F x) : \u2200 x : \u2115, G x :=\n  fun x : \u2115 => (h1 $ x) $ (h2 $ x)\n\n-- \u2200x\u00acF(x), F(d) \u22a2 \u00ac\u2200xF(x)\nexample (h1 : \u2200 x : \u2115, \u00acF x) (h2 : F d) : \u00ac\u2200 x : \u2115 , F x :=\n  ((h1 $ d) $ h2).elim -- EFQ rule\n\n-- \u00ac\u2203xF(x) \u22a2 \u2200x\u00acF(x)\nexample (h1 : \u00ac\u2203 x : \u2115, F x) : \u2200 x : \u2115, \u00acF x :=\n  fun a : \u2115 => (fun fa : F a => h1 $ \u27e8a, fa\u27e9)", "meta": {"author": "cmloura", "repo": "LeanPractice2023", "sha": "6819825e67228bfe5e69aa309f8d2bd37ef48ce3", "save_path": "github-repos/lean/cmloura-LeanPractice2023", "path": "github-repos/lean/cmloura-LeanPractice2023/LeanPractice2023-6819825e67228bfe5e69aa309f8d2bd37ef48ce3/quantifier.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.7853085733507947, "lm_q1q2_score": 0.7184795691893304}}
{"text": "import data.complex.basic \nimport data.fintype.basic \nimport data.fin\nimport data.matrix.basic\nimport linear_algebra.basis\nimport linear_algebra.determinant\nimport linear_algebra.nonsingular_inverse\nimport .complex_transpose\nimport tactic \n\n\nnoncomputable theory \nopen_locale classical\nopen_locale matrix\n\nuniverses u u'\nvariables {n : \u2115}\nvariables {S : Type u} [semiring S]\n\n-- need a better name\ndef matrix.extension (A : matrix (fin n) (fin n) S) (a : S) : \n  matrix (fin (n+1)) (fin (n+1)) S\n:= \n\u03bb i j,\nmatch i, j with\n| \u27e80, _\u27e9, \u27e80, _\u27e9       := a\n| \u27e80, _\u27e9, _            := 0\n| _, \u27e80, _\u27e9            := 0\n| \u27e8x+1, hx\u27e9, \u27e8y+1, hy\u27e9 := A \u27e8x, nat.lt_of_succ_lt_succ hx\u27e9 \u27e8y, nat.lt_of_succ_lt_succ hy\u27e9\nend \n\ndef vector.extension (v : (fin n) \u2192 S) (a : S) : \n  fin (n+1) \u2192 S\n:= \n\u03bb i,\nmatch i with\n| \u27e80, _\u27e9      := a\n| \u27e8x+1, hx\u27e9   := v \u27e8x, nat.lt_of_succ_lt_succ hx\u27e9\nend \n\n\n-- set_option pp.notation false\nlemma matrix.extension_mul (A B : matrix (fin n) (fin n) S) (a b : S) : \n  (A.extension a) \u2022 (B.extension b) = (A \u2022 B).extension (a * b):=\nbegin \next,\ncases i, cases i_val,\ncases j, cases j_val,\nsorry,\nrepeat{sorry,}\nend\n\nlemma matrix.extension_conj (A : matrix (fin n) (fin n) \u2102) (a : \u2102) : \n  (A.extension a).conj = A.conj.extension a.conj :=\nbegin \nsorry,\nend\n\n", "meta": {"author": "apurvanakade", "repo": "mc2020-lean-projects", "sha": "02466225aa629ab1232043bcc0a053a099fdb939", "save_path": "github-repos/lean/apurvanakade-mc2020-lean-projects", "path": "github-repos/lean/apurvanakade-mc2020-lean-projects/mc2020-lean-projects-02466225aa629ab1232043bcc0a053a099fdb939/src/apurva/matrix_extension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7184795669740488}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport tactic \nimport data.real.basic\n\n/-\n# Ejercicios sobre n\u00fameros reales\n\nLos siguientes ejercicios aparecen como pasos intermedios en algunos\nde los problemas de `limites.lean`. Intenta resolverlos utilizando\nlas t\u00e1cticas `library_search` y `linarith`.\n\nNOTA: adaptado de los cursos de formalizaci\u00f3n de Kevin Buzzard.\n-/\n\nexample (x : \u211d) : |(-x)| = |x| :=\nbegin\n  sorry\nend\n\nexample (x y : \u211d) : |x - y| = |y - x| :=\nbegin\n  sorry\nend \n\nexample (A B C : \u2115) : max A B \u2264 C \u2194 A \u2264 C \u2227 B \u2264 C :=\nbegin\n  sorry\nend\n\nexample (x y : \u211d) : |x| < y \u2194 -y < x \u2227 x < y :=\nbegin\n  sorry\nend\n\nexample (\u03b5 : \u211d) (h\u03b5 : 0 < \u03b5) : 0 < \u03b5 / 2 :=\nbegin\n  sorry\nend\n\nexample (a b x y : \u211d) (h1 : a < x) (h2 : b < y) : a + b < x + y :=\nbegin\n  sorry\nend\n\nexample (\u03b5 : \u211d) (h\u03b5 : 0 < \u03b5) : 0 < \u03b5 / 3 :=\nbegin\n  sorry\nend\n\nexample (a b c d x y : \u211d) (h1 : a + c < x) (h2 : b + d < y) :\n  a + b + c + d < x + y :=\nbegin\n  sorry,\nend", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_4/reales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7184716914078456}}
{"text": "import data.nat.basic\nimport data.nat.modeq\nimport algebra.group_power.basic\nimport algebra.parity\n\nimport tactic.ring\n\n/-\nBulgarian Mathematical Olympiad 1998, Problem 11\n\nLet m,n be natural numbers such that\n\n   A = ((m + 3)\u207f + 1) / (3m)\n\nis an integer. Prove that A is odd.\n\n-/\n\nlemma mul_mod_lemma (a b c d : \u2115) (h : a % b = c % b) : (d * a) % b = (d * c) % b :=\nbegin\n  rw [nat.mul_mod, nat.mul_mod d c b],\n  exact congr (congr_arg has_mod.mod (congr_arg (has_mul.mul (d % b)) h)) rfl\nend\n\nlemma mod_plus_pow (m n : \u2115) : (m + 3)^n % 3 = m^n % 3 :=\nbegin\n  induction n with pn hpn,\n  { simp, },\n  { rw[pow_succ],\n    have h1 : (m + 3) * (m + 3) ^ pn = m * (m + 3) ^ pn + 3 * (m + 3) ^ pn := by ring,\n    rw [h1],\n    have h2 : 3 * (m + 3) ^ pn % 3 = 0 := nat.mul_mod_right 3 _,\n    rw[nat.add_mod, h2, add_zero, nat.mod_mod, pow_succ],\n    exact mul_mod_lemma _ _ _ _ hpn }\nend\n\ntheorem bulgaria1998_q11 (m n A : \u2115) (h : 3 * m * A = (m + 3)^n + 1) :\n  odd A :=\nbegin\n  by_contra hno,\n  sorry\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/bulgaria1998_q11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7184716909365625}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport solutions.sheet09\nimport tactic.ring\n\n/-\n\n# Induced functions on quotients\n\nThe quotient comes with what one would call a universal property in advanced courses: Given a type `X`, an \nequivalence relation `\u2248` on `X`, then for every other type `Y` and every function `h : X \u2192 Y` such that \n`x \u2248 x' \u2192 f x = f x'` there is a unique function `h : X/\u2248  \u2192 Y` such that `f = h \u2218 q`. In standard maths courses \nthe existence of such `h` in examples is often justified as follows: For each equivalence class `\u27e6x\u27e7` of \nthe quotient, choose a representative `x : X` and define `h(\u27e6x\u27e7) := f(x)`. One has to then prove that this \nis well-defined by invoking the assumption `x \u2248 x' \u2192 f x = f x'`. In Lean, the function `h` can be produced \nautomatically using `quotient.lift` applied to the assumption `x \u2248 x' \u2192 f x = f x'`, one doesn't have to go \nthrough the steps. \n\nOn this sheet we will see how this works, first starting with the example of negation, which is easier than \naddition as it only has one input, not two. \n-/\n\n\n\nlemma neg_well_defined (x y : \u2115 \u00d7 \u2115) (h : x \u2248 y) : \u27e6(x.2,x.1)\u27e7 = \u27e6(y.2, y.1)\u27e7 :=\nbegin\n  apply quotient.sound,\n  rw [equiv_def] at *,\n  rw [add_comm, \u2190 h, add_comm],\nend\n\ndef neg : myint \u2192 myint := quotient.lift (\u03bb (x : \u2115 \u00d7 \u2115), \u27e6(x.2, x.1)\u27e7) (neg_well_defined)\n\ninstance : has_neg myint :=\n{ neg := neg }\n\n/- \n\nThere is an alternative way, which is in fact a special case of the first. Suppose `Y = Z/\u2248\u2082` and we are given \na function `g : X \u2192 Z`. Consider the function `f = q\u2082 \u2218 g` where `q\u2082 : Z \u2192 Z/\u2248\u2082` is the surjection.  \nThen `x \u2248 x' \u2192 f x = f x'` can be checked on `Z` instead, i.e. it can be checked that `x \u2248 x' \u2192 g x \u2248\u2082 g x'`\nin order to reach the conclusion for `f`. Since this is a common situation, there is a special name for it: \n`quotient.map`, which takes the assumption `x \u2248 x' \u2192 g x \u2248\u2082 g x'` and defines a function `X/\u2248 \u2192 Z/\u2248\u2082`.\n\n-/\n\ndef neg2 : myint \u2192 myint := quotient.map (\u03bb x, (x.2, x.1)) \nbegin \n  intros x y hxy,\n  rw [equiv_def] at *,\n  rw [add_comm, \u2190 hxy, add_comm],\nend\n\n/- Why do the two definitions just defined agree? -/\nlemma defn_neg_agree : neg = neg2 :=\nbegin\n  refl\nend\n\n/- \n\nOur next step will be to provide an addition and a multiplication on `myint` and prove that `myint` \nwith these operations forms a commutative ring. To recall, a commutative ring is a set `R` \ntogether with operations `+: R\u00d7R \u2192 R` and `*: R\u00d7R \u2192 R` such that the following axioms hold:\n(R1) `(x+y)+z=x+(y+z)` for all `x y z : R`\n(R2) `x+y=y+x` for all `x y : R`\n(R3) `\u2203 0 : x+0=x=0+x` for all `x : R`\n(R4) `\u2200 x \u2203 -x : x + (-x) = (-x) + x = 0`\n(R5) `(x * y) * z = x * (y * z)`\n(R6) `\u2203 1 : 1 * x = x`\n(R7) `x * y = y * x` for all `x y : R`\n(R8) `x * (y + z) = x * y + x * z` for all `x y z : R`\n\nIn fact, for lean addition is not a function `R\u00d7R \u2192 R`, but rather a function `R \u2192 (R \u2192 R)`, or \n`R \u2192 R \u2192 R` as in contrast to addition and multiplication, `\u2192` is right associative in Lean.  \nThe function `R \u2192 (R \u2192 R)` takes a ring element `x : R` and sends it to the function `R \u2192 R` \nwhich sends `y : R` to `x + y`, in \u03bb-notation `\u03bb y, x+y`. In computer science, the correspondence \nbetween functions `R\u00d7R \u2192 R` and `R \u2192 (R \u2192 R)` is called currying after Haskell Curry. For \nmathematicians (using category theory), it is just a special case of the concept of an adjunction,\ni.e. the functors of taking cartesian product  `- \u00d7 R` and taking Hom in the category of sets \n`Hom(R,-)` are adjoint to each other.    \n\nWe want to define addition `myint \u00d7 myint \u2192 myint` or equivalently `myint \u2192 myint \u2192 myint`. \nIf we think about the first incarnation, we could do that as follows: First we prove that \ngiven an equivalence relation on `X` and an equivalence relation on `Y` we prove that there \nis an equivalence relation on `X \u00d7 Y` given by `(x,y) \u2248 (x',y')` iff `x \u2248 x'` and `y \u2248 y'`. \nThen we do the same steps as before. Applying currying, in the other way of thinking, \nwe would have to do a two-step process of constructing a function from the quotient `myint` to \nthe set of functions from the quotient `myint` to `myint`. Luckily, we don't have to think in \ndetail about what this entails - binary operations are a common enough thing that Lean has a \nspecial construction that does all in one step, namely `quotient.map\u2082`. \n\n-/\n\ndef add : myint \u2192 myint \u2192 myint := quotient.map\u2082 (\u03bb r s, (r.1+s.1, r.2+s.2)) \nbegin \nintros r s hrs,\nintros u v huv,\nrw [equiv_def] at *,\ndsimp, /- dsimp is optional, just to make it clear that we can apply linarith after. -/\nlinarith,\nend \n\ninstance : has_add myint :=\n{ add := add }\n\ndef mul : myint \u2192 myint \u2192 myint := quotient.map\u2082 (\u03bb r s, (r.1*s.1+r.2*s.2, r.1*s.2+r.2*s.1))\nbegin\n  intros r s hrs,\n  intros u v huv,\n  rw [equiv_def] at *,\n  dsimp, /- again dsimp is optional to make it clear that nlinarith after is possible, but \n            linarith won't work. -/\n  nlinarith,\nend\n\ninstance : has_mul myint :=\n{ mul := mul }\n\n/- Now we have to prove the ring axioms. For this, we have to prove something for all equivalence \nclasses `r s t : myint`. We would rather like to check this on representatives. Then it becomes \neasy. To do this (depending on the number of inputs) you can apply the lemmas \n`quotient.induction_on r`, `quotient.induction_on\u2082 r s`, `quotient.induction_on\u2083 r s t`. To \nsimplify the goal view, after that you can put `clear r s t` but that is not strictly necessary. -/\n\ninstance : comm_ring myint :=\n{ add := has_add.add,\n  add_assoc := begin intros r s t, apply quotient.induction_on\u2083 r s t, clear r s t, intros x y z,\n    apply quotient.sound, rw [equiv_def] at *, dsimp, linarith, end,\n  zero := \u27e6(0,0)\u27e7,\n  zero_add := begin intro r, apply quotient.induction_on r, clear r, intro x, apply quotient.sound, \n    rw [equiv_def] at *, simp only [zero_add], end,\n  add_comm := begin intros r s, apply quotient.induction_on\u2082 r s, clear r s, intros x y,\n    apply quotient.sound, rw [equiv_def] at *, linarith, end,\n  add_zero := begin intro r, apply quotient.induction_on r, clear r, intro x, apply quotient.sound, \n    rw [equiv_def] at *, simp only [add_zero], end, \n  neg := has_neg.neg,\n  add_left_neg := begin intro r, apply quotient.induction_on r, clear r, intro x, apply quotient.sound,\n    rw [equiv_def] at *, linarith, end,\n  mul := has_mul.mul,\n  mul_assoc := begin intros r s t, apply quotient.induction_on\u2083 r s t, clear r s t, intros x y z,\n    apply quotient.sound, rw [equiv_def] at *, dsimp, nlinarith, end,\n  one := \u27e6(1,0)\u27e7,\n  one_mul := begin intro r, apply quotient.induction_on r, clear r, intro x, apply quotient.sound, \n    rw [equiv_def] at *, dsimp, linarith, end,\n  mul_one := begin intro r, apply quotient.induction_on r, clear r, intro x, apply quotient.sound, \n    rw [equiv_def] at *, dsimp, linarith, end,\n  left_distrib := begin intros r s t, apply quotient.induction_on\u2083 r s t, clear r s t, intros x y z,\n    apply quotient.sound, rw [equiv_def] at *, dsimp, nlinarith, end,\n  right_distrib := begin intros r s t, apply quotient.induction_on\u2083 r s t, clear r s t, intros x y z,\n    apply quotient.sound, rw [equiv_def] at *, dsimp, nlinarith, end,\n  mul_comm := begin intros r s, apply quotient.induction_on\u2082 r s, clear r s, intros x y, \n    apply quotient.sound, rw [equiv_def] at *, dsimp, linarith, end, }\n\n\n\n\n\n", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/solutions/sheet10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7184716826129072}}
{"text": "import field\n\ninductive two_value : Type\n  | zero : two_value\n  | one  : two_value\n\nopen two_value\n\ndef flip_bit : two_value -> two_value\n| zero := one\n| one  := zero\n\ndef add : two_value -> two_value -> two_value\n| zero zero := zero\n| zero one := one\n| one zero := one\n| one one := zero\n\ndef mul : two_value -> two_value -> two_value\n| zero _   := zero\n| _ zero   := zero\n| one one  := one\n\ndef reciprocal (x : two_value) (x_ne_zero : x \u2260 zero) : two_value := one\n\nlemma tv_add_comm (x y : two_value) : (add x y) = (add y x) :=\nbegin\n  cases x, all_goals {cases y},\n  all_goals {unfold add}, all_goals {unfold flip_bit}, all_goals {unfold id},\nend\n\nlemma tv_add_assoc (x y z : two_value) : (add x (add y z)) = (add (add x y) z) :=\nbegin\n  cases x, all_goals {cases y}, all_goals {cases z},\n  all_goals {unfold add},\nend\n\nlemma tv_mul_comm (x y : two_value) : (mul x y) = (mul y x) :=\nbegin\n  cases x, all_goals {cases y},\n  all_goals {unfold mul},\nend\n\nlemma tv_mul_assoc (x y z : two_value) : (mul x (mul y z)) = (mul (mul x y) z) :=\nbegin\n  cases x, all_goals {cases y}, all_goals {cases z},\n  all_goals {unfold mul}, all_goals {unfold mul},\nend\n\nlemma tv_add_zero (x : two_value) : x = (add x zero) :=\nbegin\n  cases x, all_goals {unfold add},\nend\n\nlemma tv_mul_one (x : two_value) : x = (mul x one) :=\nbegin\n  cases x, all_goals {unfold mul},\nend\n\nlemma tv_add_negate (x : two_value) : add x (id x) = zero :=\nbegin\n  cases x, all_goals {unfold id, unfold add},\nend\n\nlemma tv_mul_reciprocal (x : two_value) (x_ne_zero : x \u2260 zero) : mul x (reciprocal x x_ne_zero) = one :=\nbegin\n  cases x, cc, unfold reciprocal, unfold mul,\nend\n\nlemma tv_distrib (x y z : two_value) : add (mul x z) (mul y z) = mul (add x y) z :=\nbegin\n  cases x, all_goals {cases y}, all_goals {cases z},\n  all_goals {unfold mul, unfold add}, all_goals {unfold mul},\nend\n\nlemma tv_zero_distinct_one : (one : two_value) \u2260 (zero : two_value) := begin cc, end\n\ninstance gf2 :\n  myfld two_value :=\n{\n  add := add,\n  mul := mul,\n  negate := id,\n  zero := zero,\n  reciprocal := reciprocal,\n  one := one,\n  add_assoc := tv_add_assoc,\n  mul_assoc := tv_mul_assoc,\n  add_comm := tv_add_comm,\n  mul_comm := tv_mul_comm,\n  add_zero := tv_add_zero,\n  mul_one := tv_mul_one,\n  add_negate := tv_add_negate,\n  mul_reciprocal := tv_mul_reciprocal,\n  distrib := tv_distrib,\n  zero_distinct_one := tv_zero_distinct_one,\n}", "meta": {"author": "NicholasDyson", "repo": "lean-polynomials", "sha": "1f8ebc475479b997d14397df3b875a27644ce9b1", "save_path": "github-repos/lean/NicholasDyson-lean-polynomials", "path": "github-repos/lean/NicholasDyson-lean-polynomials/lean-polynomials-1f8ebc475479b997d14397df3b875a27644ce9b1/non_mathlib/gf2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7184716761345238}}
{"text": "section\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n/- UNIVERSAL QUANTIFICATION -/\n\n-- We can leave off `: \u03b1` if Lean can infer it (here via `p`/`q`)\nexample : (\u2200 x, p x) \u2192 (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, q x) := fun h h1 \u03b1 => (h1 \u03b1) (h \u03b1) \n\n-- The reverse direction of the slides example\nexample : (\u2200 x, p x \u2227 q x) \u2192 (\u2200 x, p x) \u2227 (\u2200 x, q x) := fun h => \u27e8fun \u03b1 => (h \u03b1).1, fun \u03b1 => (h \u03b1).2\u27e9 \n\n-- TODO: Prove the corresponding forward/reverse lemma(s) for `\u2228` (that hold)!\n-- hint: input `\u2200` as `\\all`\n\n-- We can bind multiple variables in a single `\u2200`\nexample : (\u2200 x y, r x y) \u2192 (\u2200 y x, r x y) := fun h y x => h x y\n\n/- EXISTENTIAL QUANTIFICATION -/\n\n/-\nInterestingly, in contrast to the universal quantifier, the existential quantifier is not primitive\nbut can be specified as an inductive type:\n```\ninductive Exists (p : \u03b1 \u2192 Prop) : Prop where\n  | intro (w : \u03b1) (h : p w) : Exists p\n```\nThat is, `Exists.intro` takes/offers a \"witness\" and a proof that the predicate holds for the witness.\nInstead of `Exists (fun x => p x)`, we can also write `\u2203 x, p x` (input `\u2203` as `\\ex`).\n-/\n\nexample : (\u2203 x, p x \u2227 q x) \u2192 (\u2203 x, p x) \u2227 (\u2203 x, q x) := fun h => \n  match h with \n  | \u27e8w,hw\u27e9 => \u27e8Exists.intro w hw.1, Exists.intro w hw.2\u27e9  \n\nexample : \u00ac(\u2203 x, p x) \u2192 (\u2200 x, \u00ac p x) := fun h \u03b1 hpa => nomatch h \u27e8\u03b1,hpa\u27e9 \n\nexample : (\u2200 x, \u00ac p x) \u2192 \u00ac(\u2203 x, p x) := fun h h1 => \n  match h1 with \n  | \u27e8w,hw\u27e9 => (h w) hw\n\nexample : (\u2203 x, \u00ac p x) \u2192 \u00ac (\u2200 x, p x) := fun h h1 => \n  match h with \n  | \u27e8w,hw\u27e9 => hw (h1 w)\n\nsection\nopen Classical\n-- The following example can only be solved using the classical axioms\n-- This one is pretty tricky again, don't feel bad about skipping it\n-- hint: use the following helper theorem that can be derived from `em`:\n#check byContradiction\n-- hint: you may even need to use it more than once\nexample : \u00ac(\u2200 x, p x) \u2192 (\u2203 x, \u00ac p x) := fun h => byContradiction\n  (fun h1 => h (fun \u03b1 => byContradiction (fun h2 => h1 \u27e8\u03b1,h2\u27e9))) \nend\n\n-- TODO: Decide for yourself what variables you need to model and prove the following\n-- important real-world observation, which is sometimes called \"drinker paradox\":\n--   \"If there is at least one person in the pub, then there is someone in the pub such that,\n--    if (s)he is drinking, then everyone in the pub is drinking.\"\n-- hint: you can define \"is in pub\" either as a predicate variable on a \"Person\" type (`(Person : Type)`),\n--   or, more simply, directly as a type \"Occupant\" since we are not interested in persons outside the pub\n-- hint: you might need classical logic again\nsection Drinker\nopen Classical\nvariable (Occupant: Type) (drinking : Occupant -> Prop)\n\nexample : (\u2203 x: Occupant, True) \u2192 \u2203 x, drinking x \u2192 \u2200 x', drinking x' := \n  fun h => \n    match h with \n    | \u27e8w,_\u27e9 => match em (\u2203 x', \u00ac drinking x') with\n      | Or.inl drink => \n        match drink with \n        | \u27e8w',hw'\u27e9 => Exists.intro w' (fun h1 => False.elim (hw' h1))\n      | Or.inr nodrink => Exists.intro w (fun _ x' => byContradiction (fun h2 => nodrink \u27e8x',h2\u27e9 ))\n\nend Drinker\n\n/- EQUALITY -/\n\nexample : \u2200 a b c : \u03b1, a = b \u2192 b = c \u2192 a = c := fun a b c h h1 => h \u25b8 h1 \u25b8 rfl\n\nexample : \u2200 a : \u03b1, \u2203 b : \u03b1, b = a := fun _ => \u27e8_,rfl\u27e9 \n\n-- \"`Eq` is the least reflexive relation\"\nexample : (\u2200 a, r a a) \u2192 (\u2200 a b, a = b \u2192 r a b) := fun h a b h1 => \n  match h1 with \n  | Eq.refl a => (h a)\n\nend\n", "meta": {"author": "vanessa-rodrigues", "repo": "lean-books", "sha": "dcadc8b3f665eda5c6d7153384bd152a9c1ca483", "save_path": "github-repos/lean/vanessa-rodrigues-lean-books", "path": "github-repos/lean/vanessa-rodrigues-lean-books/lean-books-dcadc8b3f665eda5c6d7153384bd152a9c1ca483/IPDSnelting/Exercises/Exercise2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7184716758988823}}
{"text": "--- Due to some path related stuff, it doesn't run, but I'll keep them here\n-- * Level 1\nimport mynat.definition -- Imports the natural numbers.\nimport mynat.add -- imports addition.\n--\nlemma zero_add (n : mynat) : 0 + n = n :=\n\nbegin\ninduction n with d hd,\nrw add_zero,\nrefl,\nrw add_succ,\nrw hd,\nrefl\n\nend\n\n\n-- * Level 2\nlemma add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) :=\n\n\nbegin\n\ninduction c with d hd,\nrw add_zero (a + b),\nrefl,\n\nrw add_succ (a + b) d,\nrw add_succ b d,\nrw hd,\nrefl\nend\n-- * Level 3\nlemma succ_add (a b : mynat) : succ a + b = succ (a + b) :=\n\nbegin\ninduction b with d hd,\nrw add_zero (succ a),\nrefl,\nrw add_succ (succ a) (d),\nrw hd,\nrefl\nend\n\n-- * Level 4\nlemma add_comm (a b : mynat) : a + b = b + a :=\n\nbegin\nrw zero_add,\nrefl,\nrw add_succ a d,\nrw hd,\nrw <- succ_add,\nrefl\nend\n\n-- *  Level 5\ntheorem succ_eq_add_one (n : mynat) : succ n = n + 1 :=\n\nbegin\n\ninduction n with d hd,\nrw one_eq_succ_zero,\nrw zero_add (succ 0),\nrefl,\nrw one_eq_succ_zero,\n\nend\n-- * Level 6\nlemma add_right_comm (a b c : mynat) : a + b + c = a + c + b :=\n\n\nbegin\nrw add_assoc,\nrw add_comm b c,\nrw <- add_assoc,\nrefl\nend\n", "meta": {"author": "marcelovmaciel", "repo": "learning_lean", "sha": "0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4", "save_path": "github-repos/lean/marcelovmaciel-learning_lean", "path": "github-repos/lean/marcelovmaciel-learning_lean/learning_lean-0e208b8f90bf7709f3f4b8f6ef483e2fb5ecffc4/nngame/addition_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191259110588, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.7184120052573282}}
{"text": "/-\nCopyright (c) 2019 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou, S\u00e9bastien Gou\u00ebzel, Fr\u00e9d\u00e9ric Dupuis, Heather Macbeth\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.linear_algebra.bilinear_form\nimport Mathlib.linear_algebra.sesquilinear_form\nimport Mathlib.topology.metric_space.pi_Lp\nimport Mathlib.data.complex.is_R_or_C\nimport Mathlib.PostPort\n\nuniverses u_4 u_5 l u_1 u_3 u_2 \n\nnamespace Mathlib\n\n/-!\n# Inner Product Space\n\nThis file defines inner product spaces and proves its basic properties.\n\nAn inner product space is a vector space endowed with an inner product. It generalizes the notion of\ndot product in `\u211d^n` and provides the means of defining the length of a vector and the angle between\ntwo vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero.\nWe define both the real and complex cases at the same time using the `is_R_or_C` typeclass.\n\n## Main results\n\n- We define the class `inner_product_space \ud835\udd5c E` extending `normed_space \ud835\udd5c E` with a number of basic\n  properties, most notably the Cauchy-Schwarz inequality. Here `\ud835\udd5c` is understood to be either `\u211d`\n  or `\u2102`, through the `is_R_or_C` typeclass.\n- We show that if `f i` is an inner product space for each `i`, then so is `\u03a0 i, f i`\n- We define `euclidean_space \ud835\udd5c n` to be `n \u2192 \ud835\udd5c` for any `fintype n`, and show that\n  this an inner product space.\n- Existence of orthogonal projection onto nonempty complete subspace:\n  Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.\n  Then there exists a unique `v` in `K` that minimizes the distance `\u2225u - v\u2225` to `u`.\n  The point `v` is usually called the orthogonal projection of `u` onto `K`.\n- We define `orthonormal`, a predicate on a function `v : \u03b9 \u2192 E`.  We prove the existence of a\n  maximal orthonormal set, `exists_maximal_orthonormal`, and also prove that a maximal orthonormal\n  set is a basis (`maximal_orthonormal_iff_is_basis_of_finite_dimensional`), if `E` is finite-\n  dimensional, or in general (`maximal_orthonormal_iff_dense_span`) a set whose span is dense\n  (i.e., a Hilbert basis, although we do not make that definition).\n\n## Notation\n\nWe globally denote the real and complex inner products by `\u27ea\u00b7, \u00b7\u27eb_\u211d` and `\u27ea\u00b7, \u00b7\u27eb_\u2102` respectively.\nWe also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,\nwhich respectively introduce the plain notation `\u27ea\u00b7, \u00b7\u27eb` for the the real and complex inner product.\n\nThe orthogonal complement of a submodule `K` is denoted by `K\u15ee`.\n\n## Implementation notes\n\nWe choose the convention that inner products are conjugate linear in the first argument and linear\nin the second.\n\n## TODO\n\n- Fix the section on the existence of minimizers and orthogonal projections to make sure that it\n  also applies in the complex case.\n\n## Tags\n\ninner product space, norm\n\n## References\n*  [Cl\u00e9ment & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]\n*  [Cl\u00e9ment & Martin, *A Coq formal proof of the Lax\u2013Milgram theorem*]\n\nThe Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>\n-/\n\n/-- Syntactic typeclass for types endowed with an inner product -/\nclass has_inner (\ud835\udd5c : Type u_4) (E : Type u_5) \nwhere\n  inner : E \u2192 E \u2192 \ud835\udd5c\n\n/--\nAn inner product space is a vector space with an additional operation called inner product.\nThe norm could be derived from the inner product, instead we require the existence of a norm and\nthe fact that `\u2225x\u2225^2 = re \u27eax, x\u27eb` to be able to put instances on `\ud835\udd42` or product\nspaces.\n\nTo construct a norm from an inner product, see `inner_product_space.of_core`.\n-/\nclass inner_product_space (\ud835\udd5c : Type u_4) (E : Type u_5) [is_R_or_C \ud835\udd5c] \nextends normed_space \ud835\udd5c E, has_inner \ud835\udd5c E, normed_group E\nwhere\n  norm_sq_eq_inner : \u2200 (x : E), norm x ^ bit0 1 = coe_fn is_R_or_C.re (inner x x)\n  conj_sym : \u2200 (x y : E), coe_fn is_R_or_C.conj (inner y x) = inner x y\n  nonneg_im : \u2200 (x : E), coe_fn is_R_or_C.im (inner x x) = 0\n  add_left : \u2200 (x y z : E), inner (x + y) z = inner x z + inner y z\n  smul_left : \u2200 (x y : E) (r : \ud835\udd5c), inner (r \u2022 x) y = coe_fn is_R_or_C.conj r * inner x y\n\n-- note [is_R_or_C instance]\n\n/-!\n### Constructing a normed space structure from an inner product\n\nIn the definition of an inner product space, we require the existence of a norm, which is equal\n(but maybe not defeq) to the square root of the scalar product. This makes it possible to put\nan inner product space structure on spaces with a preexisting norm (for instance `\u211d`), with good\nproperties. However, sometimes, one would like to define the norm starting only from a well-behaved\nscalar product. This is what we implement in this paragraph, starting from a structure\n`inner_product_space.core` stating that we have a nice scalar product.\n\nOur goal here is not to develop a whole theory with all the supporting API, as this will be done\nbelow for `inner_product_space`. Instead, we implement the bare minimum to go as directly as\npossible to the construction of the norm and the proof of the triangular inequality.\n\nWarning: Do not use this `core` structure if the space you are interested in already has a norm\ninstance defined on it, otherwise this will create a second non-defeq norm instance!\n-/\n\n/-- A structure requiring that a scalar product is positive definite and symmetric, from which one\ncan construct an `inner_product_space` instance in `inner_product_space.of_core`. -/\nclass inner_product_space.core (\ud835\udd5c : Type u_4) (F : Type u_5) [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] \nwhere\n  inner : F \u2192 F \u2192 \ud835\udd5c\n  conj_sym : \u2200 (x y : F), coe_fn is_R_or_C.conj (inner y x) = inner x y\n  nonneg_im : \u2200 (x : F), coe_fn is_R_or_C.im (inner x x) = 0\n  nonneg_re : \u2200 (x : F), 0 \u2264 coe_fn is_R_or_C.re (inner x x)\n  definite : \u2200 (x : F), inner x x = 0 \u2192 x = 0\n  add_left : \u2200 (x y z : F), inner (x + y) z = inner x z + inner y z\n  smul_left : \u2200 (x y : F) (r : \ud835\udd5c), inner (r \u2022 x) y = coe_fn is_R_or_C.conj r * inner x y\n\n/- We set `inner_product_space.core` to be a class as we will use it as such in the construction\nof the normed space structure that it produces. However, all the instances we will use will be\nlocal to this proof. -/\n\nnamespace inner_product_space.of_core\n\n\n/-- Inner product defined by the `inner_product_space.core` structure. -/\ndef to_has_inner {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] : has_inner \ud835\udd5c F :=\n  has_inner.mk (core.inner c)\n\n/-- The norm squared function for `inner_product_space.core` structure. -/\ndef norm_sq {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] (x : F) : \u211d :=\n  coe_fn is_R_or_C.re (inner x x)\n\ntheorem inner_conj_sym {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] (x : F) (y : F) : coe_fn is_R_or_C.conj (inner y x) = inner x y :=\n  core.conj_sym c x y\n\ntheorem inner_self_nonneg {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : 0 \u2264 coe_fn is_R_or_C.re (inner x x) :=\n  core.nonneg_re c x\n\ntheorem inner_self_nonneg_im {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : coe_fn is_R_or_C.im (inner x x) = 0 :=\n  core.nonneg_im c x\n\ntheorem inner_self_im_zero {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : coe_fn is_R_or_C.im (inner x x) = 0 :=\n  core.nonneg_im c x\n\ntheorem inner_add_left {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} {z : F} : inner (x + y) z = inner x z + inner y z :=\n  core.add_left c x y z\n\ntheorem inner_add_right {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} {z : F} : inner x (y + z) = inner x y + inner x z := sorry\n\ntheorem inner_norm_sq_eq_inner_self {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] (x : F) : \u2191(norm_sq x) = inner x x := sorry\n\ntheorem inner_re_symm {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : coe_fn is_R_or_C.re (inner x y) = coe_fn is_R_or_C.re (inner y x) := sorry\n\ntheorem inner_im_symm {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : coe_fn is_R_or_C.im (inner x y) = -coe_fn is_R_or_C.im (inner y x) := sorry\n\ntheorem inner_smul_left {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} {r : \ud835\udd5c} : inner (r \u2022 x) y = coe_fn is_R_or_C.conj r * inner x y :=\n  core.smul_left c x y r\n\ntheorem inner_smul_right {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} {r : \ud835\udd5c} : inner x (r \u2022 y) = r * inner x y := sorry\n\ntheorem inner_zero_left {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : inner 0 x = 0 := sorry\n\ntheorem inner_zero_right {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : inner x 0 = 0 := sorry\n\ntheorem inner_self_eq_zero {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : inner x x = 0 \u2194 x = 0 :=\n  { mp := core.definite c x, mpr := fun (\u1fb0 : x = 0) => Eq._oldrec inner_zero_left (Eq.symm \u1fb0) }\n\ntheorem inner_self_re_to_K {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : \u2191(coe_fn is_R_or_C.re (inner x x)) = inner x x := sorry\n\ntheorem inner_abs_conj_sym {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : is_R_or_C.abs (inner x y) = is_R_or_C.abs (inner y x) := sorry\n\ntheorem inner_neg_left {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : inner (-x) y = -inner x y := sorry\n\ntheorem inner_neg_right {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : inner x (-y) = -inner x y := sorry\n\ntheorem inner_sub_left {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} {z : F} : inner (x - y) z = inner x z - inner y z := sorry\n\ntheorem inner_sub_right {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} {z : F} : inner x (y - z) = inner x y - inner x z := sorry\n\ntheorem inner_mul_conj_re_abs {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : coe_fn is_R_or_C.re (inner x y * inner y x) = is_R_or_C.abs (inner x y * inner y x) := sorry\n\n/-- Expand `inner (x + y) (x + y)` -/\ntheorem inner_add_add_self {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : inner (x + y) (x + y) = inner x x + inner x y + inner y x + inner y y := sorry\n\n/- Expand `inner (x - y) (x - y)` -/\n\ntheorem inner_sub_sub_self {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} {y : F} : inner (x - y) (x - y) = inner x x - inner x y - inner y x + inner y y := sorry\n\n/--\nCauchy\u2013Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia.\nWe need this for the `core` structure to prove the triangle inequality below when\nshowing the core is a normed group.\n-/\ntheorem inner_mul_inner_self_le {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] (x : F) (y : F) : is_R_or_C.abs (inner x y) * is_R_or_C.abs (inner y x) \u2264\n  coe_fn is_R_or_C.re (inner x x) * coe_fn is_R_or_C.re (inner y y) := sorry\n\n/-- Norm constructed from a `inner_product_space.core` structure, defined to be the square root\nof the scalar product. -/\ndef to_has_norm {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] : has_norm F :=\n  has_norm.mk fun (x : F) => real.sqrt (coe_fn is_R_or_C.re (inner x x))\n\ntheorem norm_eq_sqrt_inner {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] (x : F) : norm x = real.sqrt (coe_fn is_R_or_C.re (inner x x)) :=\n  rfl\n\ntheorem inner_self_eq_norm_square {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] (x : F) : coe_fn is_R_or_C.re (inner x x) = norm x * norm x := sorry\n\ntheorem sqrt_norm_sq_eq_norm {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] {x : F} : real.sqrt (norm_sq x) = norm x :=\n  rfl\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\ntheorem abs_inner_le_norm {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] (x : F) (y : F) : is_R_or_C.abs (inner x y) \u2264 norm x * norm y := sorry\n\n/-- Normed group structure constructed from an `inner_product_space.core` structure -/\ndef to_normed_group {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] : normed_group F :=\n  normed_group.of_core F sorry\n\n/-- Normed space structure constructed from a `inner_product_space.core` structure -/\ndef to_normed_space {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] [c : core \ud835\udd5c F] : normed_space \ud835\udd5c F :=\n  normed_space.mk sorry\n\nend inner_product_space.of_core\n\n\n/-- Given a `inner_product_space.core` structure on a space, one can use it to turn\nthe space into an inner product space, constructing the norm out of the inner product -/\ndef inner_product_space.of_core {\ud835\udd5c : Type u_1} {F : Type u_3} [is_R_or_C \ud835\udd5c] [add_comm_group F] [semimodule \ud835\udd5c F] (c : inner_product_space.core \ud835\udd5c F) : inner_product_space \ud835\udd5c F :=\n  let _inst : normed_group F := sorry;\n  let _inst_4 : normed_space \ud835\udd5c F := sorry;\n  inner_product_space.mk sorry (inner_product_space.core.conj_sym c) (inner_product_space.core.nonneg_im c)\n    (inner_product_space.core.add_left c) (inner_product_space.core.smul_left c)\n\n/-! ### Properties of inner product spaces -/\n\ntheorem inner_conj_sym {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : coe_fn is_R_or_C.conj (inner y x) = inner x y :=\n  inner_product_space.conj_sym x y\n\ntheorem real_inner_comm {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner y x = inner x y :=\n  inner_conj_sym x y\n\ntheorem inner_eq_zero_sym {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner x y = 0 \u2194 inner y x = 0 := sorry\n\ntheorem inner_self_nonneg_im {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : coe_fn is_R_or_C.im (inner x x) = 0 :=\n  inner_product_space.nonneg_im x\n\ntheorem inner_self_im_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : coe_fn is_R_or_C.im (inner x x) = 0 :=\n  inner_product_space.nonneg_im x\n\ntheorem inner_add_left {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {z : E} : inner (x + y) z = inner x z + inner y z :=\n  inner_product_space.add_left x y z\n\ntheorem inner_add_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {z : E} : inner x (y + z) = inner x y + inner x z := sorry\n\ntheorem inner_re_symm {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : coe_fn is_R_or_C.re (inner x y) = coe_fn is_R_or_C.re (inner y x) := sorry\n\ntheorem inner_im_symm {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : coe_fn is_R_or_C.im (inner x y) = -coe_fn is_R_or_C.im (inner y x) := sorry\n\ntheorem inner_smul_left {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {r : \ud835\udd5c} : inner (r \u2022 x) y = coe_fn is_R_or_C.conj r * inner x y :=\n  inner_product_space.smul_left x y r\n\ntheorem real_inner_smul_left {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} {r : \u211d} : inner (r \u2022 x) y = r * inner x y :=\n  inner_smul_left\n\ntheorem inner_smul_real_left {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {r : \u211d} : inner (\u2191r \u2022 x) y = r \u2022 inner x y := sorry\n\ntheorem inner_smul_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {r : \ud835\udd5c} : inner x (r \u2022 y) = r * inner x y := sorry\n\ntheorem real_inner_smul_right {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} {r : \u211d} : inner x (r \u2022 y) = r * inner x y :=\n  inner_smul_right\n\ntheorem inner_smul_real_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {r : \u211d} : inner x (\u2191r \u2022 y) = r \u2022 inner x y :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (inner x (\u2191r \u2022 y) = r \u2022 inner x y)) inner_smul_right))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191r * inner x y = r \u2022 inner x y)) (algebra.smul_def r (inner x y))))\n      (Eq.refl (\u2191r * inner x y)))\n\n/-- The inner product as a sesquilinear form. -/\ndef sesq_form_of_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : sesq_form \ud835\udd5c E (is_R_or_C.conj_to_ring_equiv \ud835\udd5c) :=\n  sesq_form.mk (fun (x y : E) => inner y x) sorry sorry sorry sorry\n\n/-- The real inner product as a bilinear form. -/\ndef bilin_form_of_real_inner {F : Type u_3} [inner_product_space \u211d F] : bilin_form \u211d F :=\n  bilin_form.mk inner sorry sorry sorry sorry\n\n/-- An inner product with a sum on the left. -/\ntheorem sum_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_3} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) : inner (finset.sum s fun (i : \u03b9) => f i) x = finset.sum s fun (i : \u03b9) => inner (f i) x :=\n  sesq_form.map_sum_right sesq_form_of_inner s (fun (i : \u03b9) => f i) x\n\n/-- An inner product with a sum on the right. -/\ntheorem inner_sum {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_3} (s : finset \u03b9) (f : \u03b9 \u2192 E) (x : E) : inner x (finset.sum s fun (i : \u03b9) => f i) = finset.sum s fun (i : \u03b9) => inner x (f i) :=\n  sesq_form.map_sum_left sesq_form_of_inner s (fun (i : \u03b9) => f i) x\n\n/-- An inner product with a sum on the left, `finsupp` version. -/\ntheorem finsupp.sum_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_3} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) : inner (finsupp.sum l fun (i : \u03b9) (a : \ud835\udd5c) => a \u2022 v i) x =\n  finsupp.sum l fun (i : \u03b9) (a : \ud835\udd5c) => coe_fn is_R_or_C.conj a \u2022 inner (v i) x := sorry\n\n/-- An inner product with a sum on the right, `finsupp` version. -/\ntheorem finsupp.inner_sum {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_3} (l : \u03b9 \u2192\u2080 \ud835\udd5c) (v : \u03b9 \u2192 E) (x : E) : inner x (finsupp.sum l fun (i : \u03b9) (a : \ud835\udd5c) => a \u2022 v i) = finsupp.sum l fun (i : \u03b9) (a : \ud835\udd5c) => a \u2022 inner x (v i) := sorry\n\n@[simp] theorem inner_zero_left {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : inner 0 x = 0 := sorry\n\ntheorem inner_re_zero_left {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : coe_fn is_R_or_C.re (inner 0 x) = 0 := sorry\n\n@[simp] theorem inner_zero_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : inner x 0 = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (inner x 0 = 0)) (Eq.symm (inner_conj_sym x 0))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn is_R_or_C.conj (inner 0 x) = 0)) inner_zero_left))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn is_R_or_C.conj 0 = 0)) (ring_hom.map_zero is_R_or_C.conj))) (Eq.refl 0)))\n\ntheorem inner_re_zero_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : coe_fn is_R_or_C.re (inner x 0) = 0 := sorry\n\ntheorem inner_self_nonneg {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : 0 \u2264 coe_fn is_R_or_C.re (inner x x) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 coe_fn is_R_or_C.re (inner x x))) (Eq.symm (norm_sq_eq_inner x))))\n    (pow_nonneg (norm_nonneg x) (bit0 1))\n\ntheorem real_inner_self_nonneg {F : Type u_3} [inner_product_space \u211d F] {x : F} : 0 \u2264 inner x x :=\n  inner_self_nonneg\n\n@[simp] theorem inner_self_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : inner x x = 0 \u2194 x = 0 := sorry\n\n@[simp] theorem inner_self_nonpos {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : coe_fn is_R_or_C.re (inner x x) \u2264 0 \u2194 x = 0 := sorry\n\ntheorem real_inner_self_nonpos {F : Type u_3} [inner_product_space \u211d F] {x : F} : inner x x \u2264 0 \u2194 x = 0 := sorry\n\n@[simp] theorem inner_self_re_to_K {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : \u2191(coe_fn is_R_or_C.re (inner x x)) = inner x x := sorry\n\ntheorem inner_self_eq_norm_sq_to_K {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) : inner x x = \u2191(norm x) ^ bit0 1 := sorry\n\ntheorem inner_self_re_abs {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : coe_fn is_R_or_C.re (inner x x) = is_R_or_C.abs (inner x x) := sorry\n\ntheorem inner_self_abs_to_K {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : \u2191(is_R_or_C.abs (inner x x)) = inner x x :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(is_R_or_C.abs (inner x x)) = inner x x)) (Eq.symm inner_self_re_abs)))\n    inner_self_re_to_K\n\ntheorem real_inner_self_abs {F : Type u_3} [inner_product_space \u211d F] {x : F} : abs (inner x x) = inner x x := sorry\n\ntheorem inner_abs_conj_sym {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : is_R_or_C.abs (inner x y) = is_R_or_C.abs (inner y x) := sorry\n\n@[simp] theorem inner_neg_left {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner (-x) y = -inner x y := sorry\n\n@[simp] theorem inner_neg_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner x (-y) = -inner x y := sorry\n\ntheorem inner_neg_neg {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner (-x) (-y) = inner x y := sorry\n\n@[simp] theorem inner_self_conj {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} : coe_fn is_R_or_C.conj (inner x x) = inner x x := sorry\n\ntheorem inner_sub_left {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {z : E} : inner (x - y) z = inner x z - inner y z := sorry\n\ntheorem inner_sub_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} {z : E} : inner x (y - z) = inner x y - inner x z := sorry\n\ntheorem inner_mul_conj_re_abs {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : coe_fn is_R_or_C.re (inner x y * inner y x) = is_R_or_C.abs (inner x y * inner y x) := sorry\n\n/-- Expand `\u27eax + y, x + y\u27eb` -/\ntheorem inner_add_add_self {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner (x + y) (x + y) = inner x x + inner x y + inner y x + inner y y := sorry\n\n/-- Expand `\u27eax + y, x + y\u27eb_\u211d` -/\ntheorem real_inner_add_add_self {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : inner (x + y) (x + y) = inner x x + bit0 1 * inner x y + inner y y := sorry\n\n/- Expand `\u27eax - y, x - y\u27eb` -/\n\ntheorem inner_sub_sub_self {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner (x - y) (x - y) = inner x x - inner x y - inner y x + inner y y := sorry\n\n/-- Expand `\u27eax - y, x - y\u27eb_\u211d` -/\ntheorem real_inner_sub_sub_self {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : inner (x - y) (x - y) = inner x x - bit0 1 * inner x y + inner y y := sorry\n\n/-- Parallelogram law -/\ntheorem parallelogram_law {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner (x + y) (x + y) + inner (x - y) (x - y) = bit0 1 * (inner x x + inner y y) := sorry\n\n/-- Cauchy\u2013Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia. -/\ntheorem inner_mul_inner_self_le {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : is_R_or_C.abs (inner x y) * is_R_or_C.abs (inner y x) \u2264\n  coe_fn is_R_or_C.re (inner x x) * coe_fn is_R_or_C.re (inner y y) := sorry\n\n/-- Cauchy\u2013Schwarz inequality for real inner products. -/\ntheorem real_inner_mul_inner_self_le {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner x y * inner x y \u2264 inner x x * inner y y := sorry\n\n/-- A family of vectors is linearly independent if they are nonzero\nand orthogonal. -/\ntheorem linear_independent_of_ne_zero_of_inner_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_3} {v : \u03b9 \u2192 E} (hz : \u2200 (i : \u03b9), v i \u2260 0) (ho : \u2200 (i j : \u03b9), i \u2260 j \u2192 inner (v i) (v j) = 0) : linear_independent \ud835\udd5c v := sorry\n\n/-- An orthonormal set of vectors in an `inner_product_space` -/\ndef orthonormal (\ud835\udd5c : Type u_1) {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} (v : \u03b9 \u2192 E) :=\n  (\u2200 (i : \u03b9), norm (v i) = 1) \u2227 \u2200 {i j : \u03b9}, i \u2260 j \u2192 inner (v i) (v j) = 0\n\n/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal.  (Inner\nproduct equals Kronecker delta.) -/\ntheorem orthonormal_iff_ite {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} {v : \u03b9 \u2192 E} : orthonormal \ud835\udd5c v \u2194 \u2200 (i j : \u03b9), inner (v i) (v j) = ite (i = j) 1 0 := sorry\n\n/-- `if ... then ... else` characterization of a set of vectors being orthonormal.  (Inner product\nequals Kronecker delta.) -/\ntheorem orthonormal_subtype_iff_ite {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {s : set E} : orthonormal \ud835\udd5c coe \u2194 \u2200 (v : E), v \u2208 s \u2192 \u2200 (w : E), w \u2208 s \u2192 inner v w = ite (v = w) 1 0 := sorry\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\ntheorem orthonormal.inner_right_finsupp {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) : inner (v i) (coe_fn (finsupp.total \u03b9 E \ud835\udd5c v) l) = coe_fn l i := sorry\n\n/-- The inner product of a linear combination of a set of orthonormal vectors with one of those\nvectors picks out the coefficient of that vector. -/\ntheorem orthonormal.inner_left_finsupp {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (l : \u03b9 \u2192\u2080 \ud835\udd5c) (i : \u03b9) : inner (coe_fn (finsupp.total \u03b9 E \ud835\udd5c v) l) (v i) = coe_fn is_R_or_C.conj (coe_fn l i) := sorry\n\n/-- An orthonormal set is linearly independent. -/\ntheorem orthonormal.linear_independent {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) : linear_independent \ud835\udd5c v := sorry\n\n/-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the\nset. -/\ntheorem orthonormal.inner_finsupp_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) {s : set \u03b9} {i : \u03b9} (hi : \u00aci \u2208 s) {l : \u03b9 \u2192\u2080 \ud835\udd5c} (hl : l \u2208 finsupp.supported \ud835\udd5c \ud835\udd5c s) : inner (coe_fn (finsupp.total \u03b9 E \ud835\udd5c v) l) (v i) = 0 := sorry\n\n/- The material that follows, culminating in the existence of a maximal orthonormal subset, is\nadapted from the corresponding development of the theory of linearly independents sets.  See\n`exists_linear_independent` in particular. -/\n\ntheorem orthonormal_empty (\ud835\udd5c : Type u_1) (E : Type u_2) [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : orthonormal \ud835\udd5c fun (x : \u21a5\u2205) => \u2191x := sorry\n\ntheorem orthonormal_Union_of_directed {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b7 : Type u_3} {s : \u03b7 \u2192 set E} (hs : directed has_subset.subset s) (h : \u2200 (i : \u03b7), orthonormal \ud835\udd5c fun (x : \u21a5(s i)) => \u2191x) : orthonormal \ud835\udd5c fun (x : \u21a5(set.Union fun (i : \u03b7) => s i)) => \u2191x := sorry\n\ntheorem orthonormal_sUnion_of_directed {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {s : set (set E)} (hs : directed_on has_subset.subset s) (h : \u2200 (a : set E), a \u2208 s \u2192 orthonormal \ud835\udd5c fun (x : \u21a5a) => \u2191x) : orthonormal \ud835\udd5c fun (x : \u21a5(\u22c3\u2080s)) => \u2191x :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (orthonormal \ud835\udd5c fun (x : \u21a5(\u22c3\u2080s)) => \u2191x)) set.sUnion_eq_Union))\n    (orthonormal_Union_of_directed (directed_on.directed_coe hs)\n      (eq.mpr (id (propext set_coe.forall)) (eq.mp (Eq.refl (\u2200 (a : set E), a \u2208 s \u2192 orthonormal \ud835\udd5c coe)) h)))\n\n/-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set\ncontaining it. -/\ntheorem exists_maximal_orthonormal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {s : set E} (hs : orthonormal \ud835\udd5c coe) : \u2203 (w : set E), \u2203 (H : w \u2287 s), orthonormal \ud835\udd5c coe \u2227 \u2200 (u : set E), u \u2287 w \u2192 orthonormal \ud835\udd5c coe \u2192 u = w := sorry\n\ntheorem orthonormal.ne_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (i : \u03b9) : v i \u2260 0 := sorry\n\ntheorem is_basis_of_orthonormal_of_card_eq_findim {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} [fintype \u03b9] [Nonempty \u03b9] {v : \u03b9 \u2192 E} (hv : orthonormal \ud835\udd5c v) (card_eq : fintype.card \u03b9 = finite_dimensional.findim \ud835\udd5c E) : is_basis \ud835\udd5c v :=\n  is_basis_of_linear_independent_of_card_eq_findim (orthonormal.linear_independent hv) card_eq\n\ntheorem norm_eq_sqrt_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) : norm x = real.sqrt (coe_fn is_R_or_C.re (inner x x)) := sorry\n\ntheorem norm_eq_sqrt_real_inner {F : Type u_3} [inner_product_space \u211d F] (x : F) : norm x = real.sqrt (inner x x) := sorry\n\ntheorem inner_self_eq_norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) : coe_fn is_R_or_C.re (inner x x) = norm x * norm x := sorry\n\ntheorem real_inner_self_eq_norm_square {F : Type u_3} [inner_product_space \u211d F] (x : F) : inner x x = norm x * norm x := sorry\n\n/-- Expand the square -/\ntheorem norm_add_pow_two {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : norm (x + y) ^ bit0 1 = norm x ^ bit0 1 + bit0 1 * coe_fn is_R_or_C.re (inner x y) + norm y ^ bit0 1 := sorry\n\n/-- Expand the square -/\ntheorem norm_add_pow_two_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : norm (x + y) ^ bit0 1 = norm x ^ bit0 1 + bit0 1 * inner x y + norm y ^ bit0 1 := sorry\n\n/-- Expand the square -/\ntheorem norm_add_mul_self {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : norm (x + y) * norm (x + y) = norm x * norm x + bit0 1 * coe_fn is_R_or_C.re (inner x y) + norm y * norm y := sorry\n\n/-- Expand the square -/\ntheorem norm_add_mul_self_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : norm (x + y) * norm (x + y) = norm x * norm x + bit0 1 * inner x y + norm y * norm y := sorry\n\n/-- Expand the square -/\ntheorem norm_sub_pow_two {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : norm (x - y) ^ bit0 1 = norm x ^ bit0 1 - bit0 1 * coe_fn is_R_or_C.re (inner x y) + norm y ^ bit0 1 := sorry\n\n/-- Expand the square -/\ntheorem norm_sub_pow_two_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : norm (x - y) ^ bit0 1 = norm x ^ bit0 1 - bit0 1 * inner x y + norm y ^ bit0 1 := sorry\n\n/-- Expand the square -/\ntheorem norm_sub_mul_self {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : norm (x - y) * norm (x - y) = norm x * norm x - bit0 1 * coe_fn is_R_or_C.re (inner x y) + norm y * norm y := sorry\n\n/-- Expand the square -/\ntheorem norm_sub_mul_self_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : norm (x - y) * norm (x - y) = norm x * norm x - bit0 1 * inner x y + norm y * norm y := sorry\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\ntheorem abs_inner_le_norm {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : is_R_or_C.abs (inner x y) \u2264 norm x * norm y := sorry\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\ntheorem abs_real_inner_le_norm {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : abs (inner x y) \u2264 norm x * norm y := sorry\n\n/-- Cauchy\u2013Schwarz inequality with norm -/\ntheorem real_inner_le_norm {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner x y \u2264 norm x * norm y :=\n  le_trans (le_abs_self (inner x y)) (abs_real_inner_le_norm x y)\n\ntheorem parallelogram_law_with_norm {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : norm (x + y) * norm (x + y) + norm (x - y) * norm (x - y) = bit0 1 * (norm x * norm x + norm y * norm y) := sorry\n\ntheorem parallelogram_law_with_norm_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : norm (x + y) * norm (x + y) + norm (x - y) * norm (x - y) = bit0 1 * (norm x * norm x + norm y * norm y) := sorry\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\ntheorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : coe_fn is_R_or_C.re (inner x y) = (norm (x + y) * norm (x + y) - norm x * norm x - norm y * norm y) / bit0 1 := sorry\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\ntheorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : coe_fn is_R_or_C.re (inner x y) = (norm x * norm x + norm y * norm y - norm (x - y) * norm (x - y)) / bit0 1 := sorry\n\n/-- Polarization identity: The real part of the  inner product, in terms of the norm. -/\ntheorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : coe_fn is_R_or_C.re (inner x y) = (norm (x + y) * norm (x + y) - norm (x - y) * norm (x - y)) / bit0 (bit0 1) := sorry\n\n/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/\ntheorem im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : coe_fn is_R_or_C.im (inner x y) =\n  (norm (x - is_R_or_C.I \u2022 y) * norm (x - is_R_or_C.I \u2022 y) - norm (x + is_R_or_C.I \u2022 y) * norm (x + is_R_or_C.I \u2022 y)) /\n    bit0 (bit0 1) := sorry\n\n/-- Polarization identity: The inner product, in terms of the norm. -/\ntheorem inner_eq_sum_norm_sq_div_four {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : inner x y =\n  (\u2191(norm (x + y)) ^ bit0 1 - \u2191(norm (x - y)) ^ bit0 1 +\n      (\u2191(norm (x - is_R_or_C.I \u2022 y)) ^ bit0 1 - \u2191(norm (x + is_R_or_C.I \u2022 y)) ^ bit0 1) * is_R_or_C.I) /\n    bit0 (bit0 1) := sorry\n\n/-- A linear isometry preserves the inner product. -/\n@[simp] theorem linear_isometry.inner_map_map {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_isometry \ud835\udd5c E E') (x : E) (y : E) : inner (coe_fn f x) (coe_fn f y) = inner x y := sorry\n\n/-- A linear isometric equivalence preserves the inner product. -/\n@[simp] theorem linear_isometry_equiv.inner_map_map {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_isometry_equiv \ud835\udd5c E E') (x : E) (y : E) : inner (coe_fn f x) (coe_fn f y) = inner x y :=\n  linear_isometry.inner_map_map (linear_isometry_equiv.to_linear_isometry f) x y\n\n/-- A linear map that preserves the inner product is a linear isometry. -/\ndef linear_map.isometry_of_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_map \ud835\udd5c E E') (h : \u2200 (x y : E), inner (coe_fn f x) (coe_fn f y) = inner x y) : linear_isometry \ud835\udd5c E E' :=\n  linear_isometry.mk f sorry\n\n@[simp] theorem linear_map.coe_isometry_of_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_map \ud835\udd5c E E') (h : \u2200 (x y : E), inner (coe_fn f x) (coe_fn f y) = inner x y) : \u21d1(linear_map.isometry_of_inner f h) = \u21d1f :=\n  rfl\n\n@[simp] theorem linear_map.isometry_of_inner_to_linear_map {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_map \ud835\udd5c E E') (h : \u2200 (x y : E), inner (coe_fn f x) (coe_fn f y) = inner x y) : linear_isometry.to_linear_map (linear_map.isometry_of_inner f h) = f :=\n  rfl\n\n/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/\ndef linear_equiv.isometry_of_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_equiv \ud835\udd5c E E') (h : \u2200 (x y : E), inner (coe_fn f x) (coe_fn f y) = inner x y) : linear_isometry_equiv \ud835\udd5c E E' :=\n  linear_isometry_equiv.mk f sorry\n\n@[simp] theorem linear_equiv.coe_isometry_of_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_equiv \ud835\udd5c E E') (h : \u2200 (x y : E), inner (coe_fn f x) (coe_fn f y) = inner x y) : \u21d1(linear_equiv.isometry_of_inner f h) = \u21d1f :=\n  rfl\n\n@[simp] theorem linear_equiv.isometry_of_inner_to_linear_equiv {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {E' : Type u_4} [inner_product_space \ud835\udd5c E'] (f : linear_equiv \ud835\udd5c E E') (h : \u2200 (x y : E), inner (coe_fn f x) (coe_fn f y) = inner x y) : linear_isometry_equiv.to_linear_equiv (linear_equiv.isometry_of_inner f h) = f :=\n  rfl\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\ntheorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner x y = (norm (x + y) * norm (x + y) - norm x * norm x - norm y * norm y) / bit0 1 :=\n  Eq.trans (Eq.symm is_R_or_C.re_to_real) (re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y)\n\n/-- Polarization identity: The real inner product, in terms of the norm. -/\ntheorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner x y = (norm x * norm x + norm y * norm y - norm (x - y) * norm (x - y)) / bit0 1 :=\n  Eq.trans (Eq.symm is_R_or_C.re_to_real) (re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y)\n\n/-- Pythagorean theorem, if-and-only-if vector inner product form. -/\ntheorem norm_add_square_eq_norm_square_add_norm_square_iff_real_inner_eq_zero {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : norm (x + y) * norm (x + y) = norm x * norm x + norm y * norm y \u2194 inner x y = 0 := sorry\n\n/-- Pythagorean theorem, vector inner product form. -/\ntheorem norm_add_square_eq_norm_square_add_norm_square_of_inner_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) (h : inner x y = 0) : norm (x + y) * norm (x + y) = norm x * norm x + norm y * norm y := sorry\n\n/-- Pythagorean theorem, vector inner product form. -/\ntheorem norm_add_square_eq_norm_square_add_norm_square_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} (h : inner x y = 0) : norm (x + y) * norm (x + y) = norm x * norm x + norm y * norm y :=\n  iff.mpr (norm_add_square_eq_norm_square_add_norm_square_iff_real_inner_eq_zero x y) h\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector\ninner product form. -/\ntheorem norm_sub_square_eq_norm_square_add_norm_square_iff_real_inner_eq_zero {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : norm (x - y) * norm (x - y) = norm x * norm x + norm y * norm y \u2194 inner x y = 0 := sorry\n\n/-- Pythagorean theorem, subtracting vectors, vector inner product\nform. -/\ntheorem norm_sub_square_eq_norm_square_add_norm_square_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} (h : inner x y = 0) : norm (x - y) * norm (x - y) = norm x * norm x + norm y * norm y :=\n  iff.mpr (norm_sub_square_eq_norm_square_add_norm_square_iff_real_inner_eq_zero x y) h\n\n/-- The sum and difference of two vectors are orthogonal if and only\nif they have the same norm. -/\ntheorem real_inner_add_sub_eq_zero_iff {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner (x + y) (x - y) = 0 \u2194 norm x = norm y := sorry\n\n/-- The real inner product of two vectors, divided by the product of their\nnorms, has absolute value at most 1. -/\ntheorem abs_real_inner_div_norm_mul_norm_le_one {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : abs (inner x y / (norm x * norm y)) \u2264 1 := sorry\n\n/-- The inner product of a vector with a multiple of itself. -/\ntheorem real_inner_smul_self_left {F : Type u_3} [inner_product_space \u211d F] (x : F) (r : \u211d) : inner (r \u2022 x) x = r * (norm x * norm x) := sorry\n\n/-- The inner product of a vector with a multiple of itself. -/\ntheorem real_inner_smul_self_right {F : Type u_3} [inner_product_space \u211d F] (x : F) (r : \u211d) : inner x (r \u2022 x) = r * (norm x * norm x) := sorry\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\ntheorem abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {r : \ud835\udd5c} (hx : x \u2260 0) (hr : r \u2260 0) : is_R_or_C.abs (inner x (r \u2022 x)) / (norm x * norm (r \u2022 x)) = 1 := sorry\n\n/-- The inner product of a nonzero vector with a nonzero multiple of\nitself, divided by the product of their norms, has absolute value\n1. -/\ntheorem abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {F : Type u_3} [inner_product_space \u211d F] {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r \u2260 0) : abs (inner x (r \u2022 x)) / (norm x * norm (r \u2022 x)) = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (abs (inner x (r \u2022 x)) / (norm x * norm (r \u2022 x)) = 1)) (Eq.symm is_R_or_C.abs_to_real)))\n    (abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr)\n\n/-- The inner product of a nonzero vector with a positive multiple of\nitself, divided by the product of their norms, has value 1. -/\ntheorem real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul {F : Type u_3} [inner_product_space \u211d F] {x : F} {r : \u211d} (hx : x \u2260 0) (hr : 0 < r) : inner x (r \u2022 x) / (norm x * norm (r \u2022 x)) = 1 := sorry\n\n/-- The inner product of a nonzero vector with a negative multiple of\nitself, divided by the product of their norms, has value -1. -/\ntheorem real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul {F : Type u_3} [inner_product_space \u211d F] {x : F} {r : \u211d} (hx : x \u2260 0) (hr : r < 0) : inner x (r \u2022 x) / (norm x * norm (r \u2022 x)) = -1 := sorry\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\ntheorem abs_inner_div_norm_mul_norm_eq_one_iff {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : is_R_or_C.abs (inner x y / (\u2191(norm x) * \u2191(norm y))) = 1 \u2194 x \u2260 0 \u2227 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x := sorry\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has absolute value 1 if and only if they are nonzero and one is\na multiple of the other. One form of equality case for Cauchy-Schwarz. -/\ntheorem abs_real_inner_div_norm_mul_norm_eq_one_iff {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : abs (inner x y / (norm x * norm y)) = 1 \u2194 x \u2260 0 \u2227 \u2203 (r : \u211d), r \u2260 0 \u2227 y = r \u2022 x := sorry\n\n/--\nIf the inner product of two vectors is equal to the product of their norms, then the two vectors\nare multiples of each other. One form of the equality case for Cauchy-Schwarz.\nCompare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\ntheorem abs_inner_eq_norm_iff {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) (hx0 : x \u2260 0) (hy0 : y \u2260 0) : is_R_or_C.abs (inner x y) = norm x * norm y \u2194 \u2203 (r : \ud835\udd5c), r \u2260 0 \u2227 y = r \u2022 x := sorry\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value 1 if and only if they are nonzero and one is\na positive multiple of the other. -/\ntheorem real_inner_div_norm_mul_norm_eq_one_iff {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner x y / (norm x * norm y) = 1 \u2194 x \u2260 0 \u2227 \u2203 (r : \u211d), 0 < r \u2227 y = r \u2022 x := sorry\n\n/-- The inner product of two vectors, divided by the product of their\nnorms, has value -1 if and only if they are nonzero and one is\na negative multiple of the other. -/\ntheorem real_inner_div_norm_mul_norm_eq_neg_one_iff {F : Type u_3} [inner_product_space \u211d F] (x : F) (y : F) : inner x y / (norm x * norm y) = -1 \u2194 x \u2260 0 \u2227 \u2203 (r : \u211d), r < 0 \u2227 y = r \u2022 x := sorry\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\ntheorem inner_eq_norm_mul_iff {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} : inner x y = \u2191(norm x) * \u2191(norm y) \u2194 \u2191(norm y) \u2022 x = \u2191(norm x) \u2022 y := sorry\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`\u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`), then the two vectors are nonnegative real multiples of each other. One form\nof the equality case for Cauchy-Schwarz.\nCompare `abs_inner_eq_norm_iff`, which takes the weaker hypothesis `abs \u27eax, y\u27eb = \u2225x\u2225 * \u2225y\u2225`. -/\ntheorem inner_eq_norm_mul_iff_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : inner x y = norm x * norm y \u2194 norm y \u2022 x = norm x \u2022 y :=\n  inner_eq_norm_mul_iff\n\n/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of\nthe equality case for Cauchy-Schwarz. -/\ntheorem inner_eq_norm_mul_iff_of_norm_one {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {x : E} {y : E} (hx : norm x = 1) (hy : norm y = 1) : inner x y = 1 \u2194 x = y := sorry\n\ntheorem inner_lt_norm_mul_iff_real {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} : inner x y < norm x * norm y \u2194 norm y \u2022 x \u2260 norm x \u2022 y :=\n  iff.trans { mp := ne_of_lt, mpr := lt_of_le_of_ne (real_inner_le_norm x y) } (not_congr inner_eq_norm_mul_iff_real)\n\n/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are\ndistinct. One form of the equality case for Cauchy-Schwarz. -/\ntheorem inner_lt_one_iff_real_of_norm_one {F : Type u_3} [inner_product_space \u211d F] {x : F} {y : F} (hx : norm x = 1) (hy : norm y = 1) : inner x y < 1 \u2194 x \u2260 y := sorry\n\n/-- The inner product of two weighted sums, where the weights in each\nsum add to 0, in terms of the norms of pairwise differences. -/\ntheorem inner_sum_smul_sum_smul_of_sum_eq_zero {F : Type u_3} [inner_product_space \u211d F] {\u03b9\u2081 : Type u_1} {s\u2081 : finset \u03b9\u2081} {w\u2081 : \u03b9\u2081 \u2192 \u211d} (v\u2081 : \u03b9\u2081 \u2192 F) (h\u2081 : (finset.sum s\u2081 fun (i : \u03b9\u2081) => w\u2081 i) = 0) {\u03b9\u2082 : Type u_2} {s\u2082 : finset \u03b9\u2082} {w\u2082 : \u03b9\u2082 \u2192 \u211d} (v\u2082 : \u03b9\u2082 \u2192 F) (h\u2082 : (finset.sum s\u2082 fun (i : \u03b9\u2082) => w\u2082 i) = 0) : inner (finset.sum s\u2081 fun (i\u2081 : \u03b9\u2081) => w\u2081 i\u2081 \u2022 v\u2081 i\u2081) (finset.sum s\u2082 fun (i\u2082 : \u03b9\u2082) => w\u2082 i\u2082 \u2022 v\u2082 i\u2082) =\n  (-finset.sum s\u2081\n        fun (i\u2081 : \u03b9\u2081) => finset.sum s\u2082 fun (i\u2082 : \u03b9\u2082) => w\u2081 i\u2081 * w\u2082 i\u2082 * (norm (v\u2081 i\u2081 - v\u2082 i\u2082) * norm (v\u2081 i\u2081 - v\u2082 i\u2082))) /\n    bit0 1 := sorry\n\n/-- The inner product with a fixed left element, as a continuous linear map.  This can be upgraded\nto a continuous map which is jointly conjugate-linear in the left argument and linear in the right\nargument, once (TODO) conjugate-linear maps have been defined. -/\ndef inner_right {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (v : E) : continuous_linear_map \ud835\udd5c E \ud835\udd5c :=\n  linear_map.mk_continuous (linear_map.mk (fun (w : E) => inner v w) sorry sorry) (norm v) sorry\n\n@[simp] theorem inner_right_coe {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (v : E) : \u21d1(inner_right v) = fun (w : E) => inner v w :=\n  rfl\n\n@[simp] theorem inner_right_apply {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (v : E) (w : E) : coe_fn (inner_right v) w = inner v w :=\n  rfl\n\n/-! ### Inner product space structure on product spaces -/\n\n/-\n If `\u03b9` is a finite type and each space `f i`, `i : \u03b9`, is an inner product space,\nthen `\u03a0 i, f i` is an inner product space as well. Since `\u03a0 i, f i` is endowed with the sup norm,\nwe use instead `pi_Lp 2 one_le_two f` for the product space, which is endowed with the `L^2` norm.\n-/\n\nprotected instance pi_Lp.inner_product_space {\ud835\udd5c : Type u_1} [is_R_or_C \ud835\udd5c] {\u03b9 : Type u_2} [fintype \u03b9] (f : \u03b9 \u2192 Type u_3) [(i : \u03b9) \u2192 inner_product_space \ud835\udd5c (f i)] : inner_product_space \ud835\udd5c (pi_Lp (bit0 1) one_le_two f) :=\n  inner_product_space.mk sorry sorry sorry sorry sorry\n\n/-- A field `\ud835\udd5c` satisfying `is_R_or_C` is itself a `\ud835\udd5c`-inner product space. -/\nprotected instance is_R_or_C.inner_product_space {\ud835\udd5c : Type u_1} [is_R_or_C \ud835\udd5c] : inner_product_space \ud835\udd5c \ud835\udd5c :=\n  inner_product_space.mk sorry sorry sorry sorry sorry\n\n/-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional\nspace use `euclidean_space \ud835\udd5c (fin n)`. -/\ndef euclidean_space (\ud835\udd5c : Type u_1) [is_R_or_C \ud835\udd5c] (n : Type u_2) [fintype n] :=\n  pi_Lp (bit0 1) one_le_two fun (i : n) => \ud835\udd5c\n\n/-! ### Inner product space structure on subspaces -/\n\n/-- Induced inner product on a submodule. -/\nprotected instance submodule.inner_product_space {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (W : submodule \ud835\udd5c E) : inner_product_space \ud835\udd5c \u21a5W :=\n  inner_product_space.mk sorry sorry sorry sorry sorry\n\n/-- The inner product on submodules is the same as on the ambient space. -/\n@[simp] theorem submodule.coe_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (W : submodule \ud835\udd5c E) (x : \u21a5W) (y : \u21a5W) : inner x y = inner \u2191x \u2191y :=\n  rfl\n\n/-- A general inner product implies a real inner product. This is not registered as an instance\nsince it creates problems with the case `\ud835\udd5c = \u211d`. -/\ndef has_inner.is_R_or_C_to_real (\ud835\udd5c : Type u_1) (E : Type u_2) [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : has_inner \u211d E :=\n  has_inner.mk fun (x y : E) => coe_fn is_R_or_C.re (inner x y)\n\n/-- A general inner product space structure implies a real inner product structure. This is not\nregistered as an instance since it creates problems with the case `\ud835\udd5c = \u211d`, but in can be used in a\nproof to obtain a real inner product space structure from a given `\ud835\udd5c`-inner product space\nstructure. -/\ndef inner_product_space.is_R_or_C_to_real (\ud835\udd5c : Type u_1) (E : Type u_2) [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : inner_product_space \u211d E :=\n  inner_product_space.mk norm_sq_eq_inner sorry sorry sorry sorry\n\ntheorem real_inner_eq_re_inner (\ud835\udd5c : Type u_1) {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (x : E) (y : E) : inner x y = coe_fn is_R_or_C.re (inner x y) :=\n  rfl\n\n/-- A complex inner product implies a real inner product -/\nprotected instance inner_product_space.complex_to_real {G : Type u_4} [inner_product_space \u2102 G] : inner_product_space \u211d G :=\n  inner_product_space.is_R_or_C_to_real \u2102 G\n\n/-!\n### Derivative of the inner product\n\nIn this section we prove that the inner product and square of the norm in an inner space are\ninfinitely `\u211d`-smooth. In order to state these results, we need a `normed_space \u211d E`\ninstance. Though we can deduce this structure from `inner_product_space \ud835\udd5c E`, this instance may be\nnot definitionally equal to some other \u201cnatural\u201d instance. So, we assume `[normed_space \u211d E]` and\n`[is_scalar_tower \u211d \ud835\udd5c E]`. In both interesting cases `\ud835\udd5c = \u211d` and `\ud835\udd5c = \u2102` we have these instances.\n\n-/\n\ntheorem is_bounded_bilinear_map_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] : is_bounded_bilinear_map \u211d fun (p : E \u00d7 E) => inner (prod.fst p) (prod.snd p) := sorry\n\n/-- Derivative of the inner product. -/\ndef fderiv_inner_clm {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] (p : E \u00d7 E) : continuous_linear_map \u211d (E \u00d7 E) \ud835\udd5c :=\n  is_bounded_bilinear_map.deriv is_bounded_bilinear_map_inner p\n\n@[simp] theorem fderiv_inner_clm_apply {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] (p : E \u00d7 E) (x : E \u00d7 E) : coe_fn (fderiv_inner_clm p) x = inner (prod.fst p) (prod.snd x) + inner (prod.fst x) (prod.snd p) :=\n  rfl\n\ntheorem times_cont_diff_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {n : with_top \u2115} : times_cont_diff \u211d n fun (p : E \u00d7 E) => inner (prod.fst p) (prod.snd p) :=\n  is_bounded_bilinear_map.times_cont_diff is_bounded_bilinear_map_inner\n\ntheorem times_cont_diff_at_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {p : E \u00d7 E} {n : with_top \u2115} : times_cont_diff_at \u211d n (fun (p : E \u00d7 E) => inner (prod.fst p) (prod.snd p)) p :=\n  times_cont_diff.times_cont_diff_at times_cont_diff_inner\n\ntheorem differentiable_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] : differentiable \u211d fun (p : E \u00d7 E) => inner (prod.fst p) (prod.snd p) :=\n  is_bounded_bilinear_map.differentiable_at is_bounded_bilinear_map_inner\n\ntheorem times_cont_diff_within_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {s : set G} {x : G} {n : with_top \u2115} (hf : times_cont_diff_within_at \u211d n f s x) (hg : times_cont_diff_within_at \u211d n g s x) : times_cont_diff_within_at \u211d n (fun (x : G) => inner (f x) (g x)) s x :=\n  times_cont_diff_at.comp_times_cont_diff_within_at x times_cont_diff_at_inner (times_cont_diff_within_at.prod hf hg)\n\ntheorem times_cont_diff_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {x : G} {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f x) (hg : times_cont_diff_at \u211d n g x) : times_cont_diff_at \u211d n (fun (x : G) => inner (f x) (g x)) x :=\n  times_cont_diff_within_at.inner hf hg\n\ntheorem times_cont_diff_on.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {s : set G} {n : with_top \u2115} (hf : times_cont_diff_on \u211d n f s) (hg : times_cont_diff_on \u211d n g s) : times_cont_diff_on \u211d n (fun (x : G) => inner (f x) (g x)) s :=\n  fun (x : G) (hx : x \u2208 s) => times_cont_diff_within_at.inner (hf x hx) (hg x hx)\n\ntheorem times_cont_diff.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {n : with_top \u2115} (hf : times_cont_diff \u211d n f) (hg : times_cont_diff \u211d n g) : times_cont_diff \u211d n fun (x : G) => inner (f x) (g x) :=\n  times_cont_diff.comp times_cont_diff_inner (times_cont_diff.prod hf hg)\n\ntheorem has_fderiv_within_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {f' : continuous_linear_map \u211d G E} {g' : continuous_linear_map \u211d G E} {s : set G} {x : G} (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (fun (t : G) => inner (f t) (g t))\n  (continuous_linear_map.comp (fderiv_inner_clm (f x, g x)) (continuous_linear_map.prod f' g')) s x :=\n  has_fderiv_at.comp_has_fderiv_within_at x\n    (is_bounded_bilinear_map.has_fderiv_at is_bounded_bilinear_map_inner (f x, g x)) (has_fderiv_within_at.prod hf hg)\n\ntheorem has_fderiv_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {f' : continuous_linear_map \u211d G E} {g' : continuous_linear_map \u211d G E} {x : G} (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (fun (t : G) => inner (f t) (g t))\n  (continuous_linear_map.comp (fderiv_inner_clm (f x, g x)) (continuous_linear_map.prod f' g')) x :=\n  has_fderiv_at.comp x (is_bounded_bilinear_map.has_fderiv_at is_bounded_bilinear_map_inner (f x, g x))\n    (has_fderiv_at.prod hf hg)\n\ntheorem has_deriv_within_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {f : \u211d \u2192 E} {g : \u211d \u2192 E} {f' : E} {g' : E} {s : set \u211d} {x : \u211d} (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) : has_deriv_within_at (fun (t : \u211d) => inner (f t) (g t)) (inner (f x) g' + inner f' (g x)) s x := sorry\n\ntheorem has_deriv_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {f : \u211d \u2192 E} {g : \u211d \u2192 E} {f' : E} {g' : E} {x : \u211d} : has_deriv_at f f' x \u2192\n  has_deriv_at g g' x \u2192 has_deriv_at (fun (t : \u211d) => inner (f t) (g t)) (inner (f x) g' + inner f' (g x)) x := sorry\n\ntheorem differentiable_within_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {s : set G} {x : G} (hf : differentiable_within_at \u211d f s x) (hg : differentiable_within_at \u211d g s x) : differentiable_within_at \u211d (fun (x : G) => inner (f x) (g x)) s x :=\n  has_fderiv_within_at.differentiable_within_at\n    (has_fderiv_at.comp_has_fderiv_within_at x (differentiable_at.has_fderiv_at (differentiable_inner (f x, g x)))\n      (differentiable_within_at.has_fderiv_within_at (differentiable_within_at.prod hf hg)))\n\ntheorem differentiable_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {x : G} (hf : differentiable_at \u211d f x) (hg : differentiable_at \u211d g x) : differentiable_at \u211d (fun (x : G) => inner (f x) (g x)) x :=\n  differentiable_at.comp x (differentiable_inner (f x, g x)) (differentiable_at.prod hf hg)\n\ntheorem differentiable_on.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {s : set G} (hf : differentiable_on \u211d f s) (hg : differentiable_on \u211d g s) : differentiable_on \u211d (fun (x : G) => inner (f x) (g x)) s :=\n  fun (x : G) (hx : x \u2208 s) => differentiable_within_at.inner (hf x hx) (hg x hx)\n\ntheorem differentiable.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} (hf : differentiable \u211d f) (hg : differentiable \u211d g) : differentiable \u211d fun (x : G) => inner (f x) (g x) :=\n  fun (x : G) => differentiable_at.inner (hf x) (hg x)\n\ntheorem fderiv_inner_apply {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {g : G \u2192 E} {x : G} (hf : differentiable_at \u211d f x) (hg : differentiable_at \u211d g x) (y : G) : coe_fn (fderiv \u211d (fun (t : G) => inner (f t) (g t)) x) y =\n  inner (f x) (coe_fn (fderiv \u211d g x) y) + inner (coe_fn (fderiv \u211d f x) y) (g x) := sorry\n\ntheorem deriv_inner_apply {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {f : \u211d \u2192 E} {g : \u211d \u2192 E} {x : \u211d} (hf : differentiable_at \u211d f x) (hg : differentiable_at \u211d g x) : deriv (fun (t : \u211d) => inner (f t) (g t)) x = inner (f x) (deriv g x) + inner (deriv f x) (g x) :=\n  has_deriv_at.deriv (has_deriv_at.inner (differentiable_at.has_deriv_at hf) (differentiable_at.has_deriv_at hg))\n\ntheorem times_cont_diff_norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {n : with_top \u2115} : times_cont_diff \u211d n fun (x : E) => norm x ^ bit0 1 := sorry\n\ntheorem times_cont_diff.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {n : with_top \u2115} (hf : times_cont_diff \u211d n f) : times_cont_diff \u211d n fun (x : G) => norm (f x) ^ bit0 1 :=\n  times_cont_diff.comp times_cont_diff_norm_square hf\n\ntheorem times_cont_diff_within_at.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {s : set G} {x : G} {n : with_top \u2115} (hf : times_cont_diff_within_at \u211d n f s x) : times_cont_diff_within_at \u211d n (fun (y : G) => norm (f y) ^ bit0 1) s x :=\n  times_cont_diff_at.comp_times_cont_diff_within_at x (times_cont_diff.times_cont_diff_at times_cont_diff_norm_square) hf\n\ntheorem times_cont_diff_at.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {x : G} {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f x) : times_cont_diff_at \u211d n (fun (y : G) => norm (f y) ^ bit0 1) x :=\n  times_cont_diff_within_at.norm_square hf\n\ntheorem times_cont_diff_on.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {s : set G} {n : with_top \u2115} (hf : times_cont_diff_on \u211d n f s) : times_cont_diff_on \u211d n (fun (y : G) => norm (f y) ^ bit0 1) s :=\n  fun (x : G) (hx : x \u2208 s) => times_cont_diff_within_at.norm_square (hf x hx)\n\ntheorem differentiable_at.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {x : G} (hf : differentiable_at \u211d f x) : differentiable_at \u211d (fun (y : G) => norm (f y) ^ bit0 1) x :=\n  differentiable_at.comp x\n    (differentiable.differentiable_at (times_cont_diff.differentiable times_cont_diff_norm_square le_rfl)) hf\n\ntheorem differentiable.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} (hf : differentiable \u211d f) : differentiable \u211d fun (y : G) => norm (f y) ^ bit0 1 :=\n  fun (x : G) => differentiable_at.norm_square (hf x)\n\ntheorem differentiable_within_at.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {s : set G} {x : G} (hf : differentiable_within_at \u211d f s x) : differentiable_within_at \u211d (fun (y : G) => norm (f y) ^ bit0 1) s x :=\n  differentiable_at.comp_differentiable_within_at x\n    (differentiable.differentiable_at (times_cont_diff.differentiable times_cont_diff_norm_square le_rfl)) hf\n\ntheorem differentiable_on.norm_square {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [normed_space \u211d E] [is_scalar_tower \u211d \ud835\udd5c E] {G : Type u_4} [normed_group G] [normed_space \u211d G] {f : G \u2192 E} {s : set G} (hf : differentiable_on \u211d f s) : differentiable_on \u211d (fun (y : G) => norm (f y) ^ bit0 1) s :=\n  fun (x : G) (hx : x \u2208 s) => differentiable_within_at.norm_square (hf x hx)\n\n/-!\n### Continuity and measurability of the inner product\n\nSince the inner product is `\u211d`-smooth, it is continuous. We do not need a `[normed_space \u211d E]`\nstructure to *state* this fact and its corollaries, so we introduce them in the proof instead.\n-/\n\ntheorem continuous_inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : continuous fun (p : E \u00d7 E) => inner (prod.fst p) (prod.snd p) :=\n  let _inst : inner_product_space \u211d E := inner_product_space.is_R_or_C_to_real \ud835\udd5c E;\n  let _inst_3 : is_scalar_tower \u211d \ud835\udd5c E := restrict_scalars.is_scalar_tower \u211d \ud835\udd5c E;\n  differentiable.continuous differentiable_inner\n\ntheorem filter.tendsto.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b1 : Type u_4} {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 E} {l : filter \u03b1} {x : E} {y : E} (hf : filter.tendsto f l (nhds x)) (hg : filter.tendsto g l (nhds y)) : filter.tendsto (fun (t : \u03b1) => inner (f t) (g t)) l (nhds (inner x y)) :=\n  filter.tendsto.comp (continuous.tendsto continuous_inner (x, y)) (filter.tendsto.prod_mk_nhds hf hg)\n\ntheorem measurable.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b1 : Type u_4} [measurable_space \u03b1] [measurable_space E] [opens_measurable_space E] [topological_space.second_countable_topology E] [measurable_space \ud835\udd5c] [borel_space \ud835\udd5c] {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 E} (hf : measurable f) (hg : measurable g) : measurable fun (t : \u03b1) => inner (f t) (g t) :=\n  continuous.measurable2 continuous_inner hf hg\n\ntheorem continuous_within_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b1 : Type u_4} [topological_space \u03b1] {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 E} {x : \u03b1} {s : set \u03b1} (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) : continuous_within_at (fun (t : \u03b1) => inner (f t) (g t)) s x :=\n  filter.tendsto.inner hf hg\n\ntheorem continuous_at.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b1 : Type u_4} [topological_space \u03b1] {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 E} {x : \u03b1} (hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (fun (t : \u03b1) => inner (f t) (g t)) x :=\n  filter.tendsto.inner hf hg\n\ntheorem continuous_on.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b1 : Type u_4} [topological_space \u03b1] {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 E} {s : set \u03b1} (hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (fun (t : \u03b1) => inner (f t) (g t)) s :=\n  fun (x : \u03b1) (hx : x \u2208 s) => continuous_within_at.inner (hf x hx) (hg x hx)\n\ntheorem continuous.inner {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b1 : Type u_4} [topological_space \u03b1] {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 E} (hf : continuous f) (hg : continuous g) : continuous fun (t : \u03b1) => inner (f t) (g t) :=\n  iff.mpr continuous_iff_continuous_at\n    fun (x : \u03b1) => continuous_at.inner (continuous.continuous_at hf) (continuous.continuous_at hg)\n\nprotected instance euclidean_space.finite_dimensional {\ud835\udd5c : Type u_1} [is_R_or_C \ud835\udd5c] {\u03b9 : Type u_4} [fintype \u03b9] : finite_dimensional \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) :=\n  finite_dimensional.finite_dimensional_fintype_fun \ud835\udd5c\n\n@[simp] theorem findim_euclidean_space {\ud835\udd5c : Type u_1} [is_R_or_C \ud835\udd5c] {\u03b9 : Type u_4} [fintype \u03b9] : finite_dimensional.findim \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) = fintype.card \u03b9 := sorry\n\ntheorem findim_euclidean_space_fin {\ud835\udd5c : Type u_1} [is_R_or_C \ud835\udd5c] {n : \u2115} : finite_dimensional.findim \ud835\udd5c (euclidean_space \ud835\udd5c (fin n)) = n := sorry\n\n/-- A basis on `\u03b9` for a finite-dimensional space induces a continuous linear equivalence\nwith `euclidean_space \ud835\udd5c \u03b9`.  If the basis is orthonormal in an inner product space, this continuous\nlinear equivalence is an isometry, but we don't prove that here. -/\ndef is_basis.equiv_fun_euclidean {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_4} [fintype \u03b9] [finite_dimensional \ud835\udd5c E] {v : \u03b9 \u2192 E} (h : is_basis \ud835\udd5c v) : continuous_linear_equiv \ud835\udd5c E (euclidean_space \ud835\udd5c \u03b9) :=\n  linear_equiv.to_continuous_linear_equiv (is_basis.equiv_fun h)\n\n/-! ### Orthogonal projection in inner product spaces -/\n\n/--\nExistence of minimizers\nLet `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.\nThen there exists a (unique) `v` in `K` that minimizes the distance `\u2225u - v\u2225` to `u`.\n -/\n-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`\n\n-- It should be broken in a sequence of more manageable pieces,\n\n-- perhaps with individual statements for the three steps below.\n\ntheorem exists_norm_eq_infi_of_complete_convex {F : Type u_3} [inner_product_space \u211d F] {K : set F} (ne : set.nonempty K) (h\u2081 : is_complete K) (h\u2082 : convex K) (u : F) : \u2203 (v : F), \u2203 (H : v \u2208 K), norm (u - v) = infi fun (w : \u21a5K) => norm (u - \u2191w) := sorry\n\n/-- Characterization of minimizers for the projection on a convex set in a real inner product\nspace. -/\ntheorem norm_eq_infi_iff_real_inner_le_zero {F : Type u_3} [inner_product_space \u211d F] {K : set F} (h : convex K) {u : F} {v : F} (hv : v \u2208 K) : (norm (u - v) = infi fun (w : \u21a5K) => norm (u - \u2191w)) \u2194 \u2200 (w : F), w \u2208 K \u2192 inner (u - v) (w - v) \u2264 0 := sorry\n\n/--\nExistence of projections on complete subspaces.\nLet `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.\nThen there exists a (unique) `v` in `K` that minimizes the distance `\u2225u - v\u2225` to `u`.\nThis point `v` is usually called the orthogonal projection of `u` onto `K`.\n-/\ntheorem exists_norm_eq_infi_of_complete_subspace {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) (h : is_complete \u2191K) (u : E) : \u2203 (v : E), \u2203 (H : v \u2208 K), norm (u - v) = infi fun (w : \u21a5\u2191K) => norm (u - \u2191w) := sorry\n\n/--\nCharacterization of minimizers in the projection on a subspace, in the real case.\nLet `u` be a point in a real inner product space, and let `K` be a nonempty subspace.\nThen point `v` minimizes the distance `\u2225u - v\u2225` over points in `K` if and only if\nfor all `w \u2208 K`, `\u27eau - v, w\u27eb = 0` (i.e., `u - v` is orthogonal to the subspace `K`).\nThis is superceded by `norm_eq_infi_iff_inner_eq_zero` that gives the same conclusion over\nany `is_R_or_C` field.\n-/\ntheorem norm_eq_infi_iff_real_inner_eq_zero {F : Type u_3} [inner_product_space \u211d F] (K : submodule \u211d F) {u : F} {v : F} (hv : v \u2208 K) : (norm (u - v) = infi fun (w : \u21a5\u2191K) => norm (u - \u2191w)) \u2194 \u2200 (w : F), w \u2208 K \u2192 inner (u - v) w = 0 := sorry\n\n/--\nCharacterization of minimizers in the projection on a subspace.\nLet `u` be a point in an inner product space, and let `K` be a nonempty subspace.\nThen point `v` minimizes the distance `\u2225u - v\u2225` over points in `K` if and only if\nfor all `w \u2208 K`, `\u27eau - v, w\u27eb = 0` (i.e., `u - v` is orthogonal to the subspace `K`)\n-/\ntheorem norm_eq_infi_iff_inner_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) {u : E} {v : E} (hv : v \u2208 K) : (norm (u - v) = infi fun (w : \u21a5\u2191K) => norm (u - \u2191w)) \u2194 \u2200 (w : E), w \u2208 K \u2192 inner (u - v) w = 0 := sorry\n\n/-- The orthogonal projection onto a complete subspace, as an\nunbundled function.  This definition is only intended for use in\nsetting up the bundled version `orthogonal_projection` and should not\nbe used once that is defined. -/\ndef orthogonal_projection_fn {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space \u21a5K] (v : E) : E :=\n  Exists.some sorry\n\n/-- The unbundled orthogonal projection is in the given subspace.\nThis lemma is only intended for use in setting up the bundled version\nand should not be used once that is defined. -/\ntheorem orthogonal_projection_fn_mem {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] (v : E) : orthogonal_projection_fn K v \u2208 K :=\n  Exists.some\n    (Exists.some_spec (exists_norm_eq_infi_of_complete_subspace K (iff.mp complete_space_coe_iff_is_complete _inst_4) v))\n\n/-- The characterization of the unbundled orthogonal projection.  This\nlemma is only intended for use in setting up the bundled version\nand should not be used once that is defined. -/\ntheorem orthogonal_projection_fn_inner_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] (v : E) (w : E) (H : w \u2208 K) : inner (v - orthogonal_projection_fn K v) w = 0 := sorry\n\n/-- The unbundled orthogonal projection is the unique point in `K`\nwith the orthogonality property.  This lemma is only intended for use\nin setting up the bundled version and should not be used once that is\ndefined. -/\ntheorem eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] {u : E} {v : E} (hvm : v \u2208 K) (hvo : \u2200 (w : E), w \u2208 K \u2192 inner (u - v) w = 0) : orthogonal_projection_fn K u = v := sorry\n\ntheorem orthogonal_projection_fn_norm_sq {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space \u21a5K] (v : E) : norm v * norm v =\n  norm (v - orthogonal_projection_fn K v) * norm (v - orthogonal_projection_fn K v) +\n    norm (orthogonal_projection_fn K v) * norm (orthogonal_projection_fn K v) := sorry\n\n/-- The orthogonal projection onto a complete subspace. -/\ndef orthogonal_projection {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space \u21a5K] : continuous_linear_map \ud835\udd5c E \u21a5K :=\n  linear_map.mk_continuous\n    (linear_map.mk (fun (v : E) => { val := orthogonal_projection_fn K v, property := orthogonal_projection_fn_mem v })\n      sorry sorry)\n    1 sorry\n\n@[simp] theorem orthogonal_projection_fn_eq {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] (v : E) : orthogonal_projection_fn K v = \u2191(coe_fn (orthogonal_projection K) v) :=\n  rfl\n\n/-- The characterization of the orthogonal projection.  -/\n@[simp] theorem orthogonal_projection_inner_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] (v : E) (w : E) (H : w \u2208 K) : inner (v - \u2191(coe_fn (orthogonal_projection K) v)) w = 0 :=\n  orthogonal_projection_fn_inner_eq_zero v\n\n/-- The orthogonal projection is the unique point in `K` with the\northogonality property. -/\ntheorem eq_orthogonal_projection_of_mem_of_inner_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] {u : E} {v : E} (hvm : v \u2208 K) (hvo : \u2200 (w : E), w \u2208 K \u2192 inner (u - v) w = 0) : \u2191(coe_fn (orthogonal_projection K) u) = v :=\n  eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hvm hvo\n\n/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/\ntheorem eq_orthogonal_projection_of_eq_submodule {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] {K' : submodule \ud835\udd5c E} [complete_space \u21a5K'] (h : K = K') (u : E) : \u2191(coe_fn (orthogonal_projection K) u) = \u2191(coe_fn (orthogonal_projection K') u) := sorry\n\n/-- The orthogonal projection sends elements of `K` to themselves. -/\n@[simp] theorem orthogonal_projection_mem_subspace_eq_self {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] (v : \u21a5K) : coe_fn (orthogonal_projection K) \u2191v = v := sorry\n\n/-- The orthogonal projection onto the trivial submodule is the zero map. -/\n@[simp] theorem orthogonal_projection_bot {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : orthogonal_projection \u22a5 = 0 := sorry\n\n/-- The orthogonal projection has norm `\u2264 1`. -/\ntheorem orthogonal_projection_norm_le {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space \u21a5K] : norm (orthogonal_projection K) \u2264 1 := sorry\n\ntheorem smul_orthogonal_projection_singleton (\ud835\udd5c : Type u_1) {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : E} (w : E) : \u2191(norm v) ^ bit0 1 \u2022 \u2191(coe_fn (orthogonal_projection (submodule.span \ud835\udd5c (singleton v))) w) = inner v w \u2022 v := sorry\n\n/-- Formula for orthogonal projection onto a single vector. -/\ntheorem orthogonal_projection_singleton (\ud835\udd5c : Type u_1) {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : E} (w : E) : \u2191(coe_fn (orthogonal_projection (submodule.span \ud835\udd5c (singleton v))) w) = (inner v w / \u2191(norm v) ^ bit0 1) \u2022 v := sorry\n\n/-- Formula for orthogonal projection onto a single unit vector. -/\ntheorem orthogonal_projection_unit_singleton (\ud835\udd5c : Type u_1) {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : E} (hv : norm v = 1) (w : E) : \u2191(coe_fn (orthogonal_projection (submodule.span \ud835\udd5c (singleton v))) w) = inner v w \u2022 v := sorry\n\n/-- The subspace of vectors orthogonal to a given subspace. -/\ndef submodule.orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) : submodule \ud835\udd5c E :=\n  submodule.mk (set_of fun (v : E) => \u2200 (u : E), u \u2208 K \u2192 inner u v = 0) sorry sorry sorry\n\npostfix:0 \"\u15ee\" => Mathlib.submodule.orthogonal\n\n/-- When a vector is in `K\u15ee`. -/\ntheorem submodule.mem_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) (v : E) : v \u2208 (K\u15ee) \u2194 \u2200 (u : E), u \u2208 K \u2192 inner u v = 0 :=\n  iff.rfl\n\n/-- When a vector is in `K\u15ee`, with the inner product the\nother way round. -/\ntheorem submodule.mem_orthogonal' {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) (v : E) : v \u2208 (K\u15ee) \u2194 \u2200 (u : E), u \u2208 K \u2192 inner v u = 0 := sorry\n\n/-- A vector in `K` is orthogonal to one in `K\u15ee`. -/\ntheorem submodule.inner_right_of_mem_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} {u : E} {v : E} (hu : u \u2208 K) (hv : v \u2208 (K\u15ee)) : inner u v = 0 :=\n  iff.mp (submodule.mem_orthogonal K v) hv u hu\n\n/-- A vector in `K\u15ee` is orthogonal to one in `K`. -/\ntheorem submodule.inner_left_of_mem_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} {u : E} {v : E} (hu : u \u2208 K) (hv : v \u2208 (K\u15ee)) : inner v u = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (inner v u = 0)) (propext inner_eq_zero_sym)))\n    (submodule.inner_right_of_mem_orthogonal hu hv)\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\ntheorem inner_right_of_mem_orthogonal_singleton {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (u : E) {v : E} (hv : v \u2208 (submodule.span \ud835\udd5c (singleton u)\u15ee)) : inner u v = 0 :=\n  submodule.inner_right_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector in `(\ud835\udd5c \u2219 u)\u15ee` is orthogonal to `u`. -/\ntheorem inner_left_of_mem_orthogonal_singleton {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (u : E) {v : E} (hv : v \u2208 (submodule.span \ud835\udd5c (singleton u)\u15ee)) : inner v u = 0 :=\n  submodule.inner_left_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\ntheorem submodule.inf_orthogonal_eq_bot {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) : K \u2293 (K\u15ee) = \u22a5 := sorry\n\n/-- `K` and `K\u15ee` have trivial intersection. -/\ntheorem submodule.orthogonal_disjoint {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) : disjoint K (K\u15ee) := sorry\n\n/-- `K\u15ee` can be characterized as the intersection of the kernels of the operations of\ninner product with each of the elements of `K`. -/\ntheorem orthogonal_eq_inter {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) : K\u15ee = infi fun (v : \u21a5K) => continuous_linear_map.ker (inner_right \u2191v) := sorry\n\n/-- The orthogonal complement of any submodule `K` is closed. -/\ntheorem submodule.is_closed_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) : is_closed \u2191(K\u15ee) := sorry\n\n/-- In a complete space, the orthogonal complement of any submodule `K` is complete. -/\nprotected instance submodule.orthogonal.complete_space {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space E] : complete_space \u21a5(K\u15ee) :=\n  is_closed.complete_space_coe (submodule.is_closed_orthogonal K)\n\n/-- `submodule.orthogonal` gives a `galois_connection` between\n`submodule \ud835\udd5c E` and its `order_dual`. -/\ntheorem submodule.orthogonal_gc (\ud835\udd5c : Type u_1) (E : Type u_2) [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : galois_connection submodule.orthogonal submodule.orthogonal := sorry\n\n/-- `submodule.orthogonal` reverses the `\u2264` ordering of two\nsubspaces. -/\ntheorem submodule.orthogonal_le {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K\u2081 : submodule \ud835\udd5c E} {K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) : K\u2082\u15ee \u2264 (K\u2081\u15ee) :=\n  galois_connection.monotone_l (submodule.orthogonal_gc \ud835\udd5c E) h\n\n/-- `submodule.orthogonal.orthogonal` preserves the `\u2264` ordering of two\nsubspaces. -/\ntheorem submodule.orthogonal_orthogonal_monotone {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K\u2081 : submodule \ud835\udd5c E} {K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) : K\u2081\u15ee\u15ee \u2264 (K\u2082\u15ee\u15ee) :=\n  submodule.orthogonal_le (submodule.orthogonal_le h)\n\n/-- `K` is contained in `K\u15ee\u15ee`. -/\ntheorem submodule.le_orthogonal_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) : K \u2264 (K\u15ee\u15ee) :=\n  galois_connection.le_u_l (submodule.orthogonal_gc \ud835\udd5c E) K\n\n/-- The inf of two orthogonal subspaces equals the subspace orthogonal\nto the sup. -/\ntheorem submodule.inf_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K\u2081 : submodule \ud835\udd5c E) (K\u2082 : submodule \ud835\udd5c E) : K\u2081\u15ee \u2293 (K\u2082\u15ee) = (K\u2081 \u2294 K\u2082\u15ee) :=\n  Eq.symm (galois_connection.l_sup (submodule.orthogonal_gc \ud835\udd5c E))\n\n/-- The inf of an indexed family of orthogonal subspaces equals the\nsubspace orthogonal to the sup. -/\ntheorem submodule.infi_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {\u03b9 : Type u_3} (K : \u03b9 \u2192 submodule \ud835\udd5c E) : (infi fun (i : \u03b9) => K i\u15ee) = (supr K\u15ee) :=\n  Eq.symm (galois_connection.l_supr (submodule.orthogonal_gc \ud835\udd5c E))\n\n/-- The inf of a set of orthogonal subspaces equals the subspace orthogonal to the sup. -/\ntheorem submodule.Inf_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (s : set (submodule \ud835\udd5c E)) : (infi fun (K : submodule \ud835\udd5c E) => infi fun (H : K \u2208 s) => K\u15ee) = (Sup s\u15ee) :=\n  Eq.symm (galois_connection.l_Sup (submodule.orthogonal_gc \ud835\udd5c E))\n\n/-- If `K\u2081` is complete and contained in `K\u2082`, `K\u2081` and `K\u2081\u15ee \u2293 K\u2082` span `K\u2082`. -/\ntheorem submodule.sup_orthogonal_inf_of_is_complete {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K\u2081 : submodule \ud835\udd5c E} {K\u2082 : submodule \ud835\udd5c E} (h : K\u2081 \u2264 K\u2082) (hc : is_complete \u2191K\u2081) : K\u2081 \u2294 K\u2081\u15ee \u2293 K\u2082 = K\u2082 := sorry\n\n/-- If `K` is complete, `K` and `K\u15ee` span the whole space. -/\ntheorem submodule.sup_orthogonal_of_is_complete {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} (h : is_complete \u2191K) : K \u2294 (K\u15ee) = \u22a4 := sorry\n\n/-- If `K` is complete, `K` and `K\u15ee` span the whole space. Version using `complete_space`. -/\ntheorem submodule.sup_orthogonal_of_complete_space {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] : K \u2294 (K\u15ee) = \u22a4 :=\n  submodule.sup_orthogonal_of_is_complete (iff.mp complete_space_coe_iff_is_complete _inst_4)\n\n/-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `K\u15ee`. -/\ntheorem submodule.exists_sum_mem_mem_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space \u21a5K] (v : E) : \u2203 (y : E), \u2203 (H : y \u2208 K), \u2203 (z : E), \u2203 (H : z \u2208 (K\u15ee)), v = y + z := sorry\n\n/-- If `K` is complete, then the orthogonal complement of its orthogonal complement is itself. -/\n@[simp] theorem submodule.orthogonal_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space \u21a5K] : K\u15ee\u15ee = K := sorry\n\ntheorem submodule.orthogonal_orthogonal_eq_closure {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space E] : K\u15ee\u15ee = submodule.topological_closure K := sorry\n\n/-- If `K` is complete, `K` and `K\u15ee` are complements of each other. -/\ntheorem submodule.is_compl_orthogonal_of_is_complete {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} (h : is_complete \u2191K) : is_compl K (K\u15ee) :=\n  is_compl.mk (submodule.orthogonal_disjoint K) (le_of_eq (Eq.symm (submodule.sup_orthogonal_of_is_complete h)))\n\n@[simp] theorem submodule.top_orthogonal_eq_bot {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : \u22a4\u15ee = \u22a5 := sorry\n\n@[simp] theorem submodule.bot_orthogonal_eq_top {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] : \u22a5\u15ee = \u22a4 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u22a5\u15ee = \u22a4)) (Eq.symm submodule.top_orthogonal_eq_bot)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u22a4\u15ee\u15ee = \u22a4)) (propext eq_top_iff))) (submodule.le_orthogonal_orthogonal \u22a4))\n\n@[simp] theorem submodule.orthogonal_eq_bot_iff {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} (hK : is_complete \u2191K) : K\u15ee = \u22a5 \u2194 K = \u22a4 := sorry\n\n@[simp] theorem submodule.orthogonal_eq_top_iff {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} : K\u15ee = \u22a4 \u2194 K = \u22a5 := sorry\n\n/-- A point in `K` with the orthogonality property (here characterized in terms of `K\u15ee`) must be the\northogonal projection. -/\ntheorem eq_orthogonal_projection_of_mem_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] {u : E} {v : E} (hv : v \u2208 K) (hvo : u - v \u2208 (K\u15ee)) : \u2191(coe_fn (orthogonal_projection K) u) = v :=\n  eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hv fun (w : E) => iff.mp inner_eq_zero_sym \u2218 hvo w\n\n/-- A point in `K` with the orthogonality property (here characterized in terms of `K\u15ee`) must be the\northogonal projection. -/\ntheorem eq_orthogonal_projection_of_mem_orthogonal' {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] {u : E} {v : E} {z : E} (hv : v \u2208 K) (hz : z \u2208 (K\u15ee)) (hu : u = v + z) : \u2191(coe_fn (orthogonal_projection K) u) = v := sorry\n\n/-- The orthogonal projection onto `K` of an element of `K\u15ee` is zero. -/\ntheorem orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space \u21a5K] {v : E} (hv : v \u2208 (K\u15ee)) : coe_fn (orthogonal_projection K) v = 0 := sorry\n\n/-- The orthogonal projection onto `K\u15ee` of an element of `K` is zero. -/\ntheorem orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K : submodule \ud835\udd5c E} [complete_space E] {v : E} (hv : v \u2208 K) : coe_fn (orthogonal_projection (K\u15ee)) v = 0 :=\n  orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero (submodule.le_orthogonal_orthogonal K hv)\n\n/-- The orthogonal projection onto `(\ud835\udd5c \u2219 v)\u15ee` of `v` is zero. -/\ntheorem orthogonal_projection_orthogonal_complement_singleton_eq_zero {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [complete_space E] (v : E) : coe_fn (orthogonal_projection (submodule.span \ud835\udd5c (singleton v)\u15ee)) v = 0 :=\n  orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero (submodule.mem_span_singleton_self v)\n\n/-- In a complete space `E`, a vector splits as the sum of its orthogonal projections onto a\ncomplete submodule `K` and onto the orthogonal complement of `K`.-/\ntheorem eq_sum_orthogonal_projection_self_orthogonal_complement {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space E] [complete_space \u21a5K] (w : E) : w = \u2191(coe_fn (orthogonal_projection K) w) + \u2191(coe_fn (orthogonal_projection (K\u15ee)) w) := sorry\n\n/-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal\ncomplement sum to the identity. -/\ntheorem id_eq_sum_orthogonal_projection_self_orthogonal_complement {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] (K : submodule \ud835\udd5c E) [complete_space E] [complete_space \u21a5K] : continuous_linear_map.id \ud835\udd5c E =\n  continuous_linear_map.comp (submodule.subtype_continuous K) (orthogonal_projection K) +\n    continuous_linear_map.comp (submodule.subtype_continuous (K\u15ee)) (orthogonal_projection (K\u15ee)) :=\n  continuous_linear_map.ext fun (w : E) => eq_sum_orthogonal_projection_self_orthogonal_complement K w\n\n/-- Given a finite-dimensional subspace `K\u2082`, and a subspace `K\u2081`\ncontainined in it, the dimensions of `K\u2081` and the intersection of its\northogonal subspace with `K\u2082` add to that of `K\u2082`. -/\ntheorem submodule.findim_add_inf_findim_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K\u2081 : submodule \ud835\udd5c E} {K\u2082 : submodule \ud835\udd5c E} [finite_dimensional \ud835\udd5c \u21a5K\u2082] (h : K\u2081 \u2264 K\u2082) : finite_dimensional.findim \ud835\udd5c \u21a5K\u2081 + finite_dimensional.findim \ud835\udd5c \u21a5(K\u2081\u15ee \u2293 K\u2082) = finite_dimensional.findim \ud835\udd5c \u21a5K\u2082 := sorry\n\n/-- Given a finite-dimensional subspace `K\u2082`, and a subspace `K\u2081`\ncontainined in it, the dimensions of `K\u2081` and the intersection of its\northogonal subspace with `K\u2082` add to that of `K\u2082`. -/\ntheorem submodule.findim_add_inf_findim_orthogonal' {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {K\u2081 : submodule \ud835\udd5c E} {K\u2082 : submodule \ud835\udd5c E} [finite_dimensional \ud835\udd5c \u21a5K\u2082] (h : K\u2081 \u2264 K\u2082) {n : \u2115} (h_dim : finite_dimensional.findim \ud835\udd5c \u21a5K\u2081 + n = finite_dimensional.findim \ud835\udd5c \u21a5K\u2082) : finite_dimensional.findim \ud835\udd5c \u21a5(K\u2081\u15ee \u2293 K\u2082) = n := sorry\n\n/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `K\u15ee` add to\nthat of `E`. -/\ntheorem submodule.findim_add_findim_orthogonal {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [finite_dimensional \ud835\udd5c E] {K : submodule \ud835\udd5c E} : finite_dimensional.findim \ud835\udd5c \u21a5K + finite_dimensional.findim \ud835\udd5c \u21a5(K\u15ee) = finite_dimensional.findim \ud835\udd5c E := sorry\n\n/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `K\u15ee` add to\nthat of `E`. -/\ntheorem submodule.findim_add_findim_orthogonal' {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [finite_dimensional \ud835\udd5c E] {K : submodule \ud835\udd5c E} {n : \u2115} (h_dim : finite_dimensional.findim \ud835\udd5c \u21a5K + n = finite_dimensional.findim \ud835\udd5c E) : finite_dimensional.findim \ud835\udd5c \u21a5(K\u15ee) = n := sorry\n\n/-- In a finite-dimensional inner product space, the dimension of the orthogonal complement of the\nspan of a nonzero vector is one less than the dimension of the space. -/\ntheorem findim_orthogonal_span_singleton {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [finite_dimensional \ud835\udd5c E] {v : E} (hv : v \u2260 0) : finite_dimensional.findim \ud835\udd5c \u21a5(submodule.span \ud835\udd5c (singleton v)\u15ee) = finite_dimensional.findim \ud835\udd5c E - 1 := sorry\n\n/-! ### Existence of Hilbert basis, orthonormal basis, etc. -/\n\n/-- An orthonormal set in an `inner_product_space` is maximal, if and only if the orthogonal\ncomplement of its span is empty. -/\ntheorem maximal_orthonormal_iff_orthogonal_complement_eq_bot {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : set E} (hv : orthonormal \ud835\udd5c coe) : (\u2200 (u : set E), u \u2287 v \u2192 orthonormal \ud835\udd5c coe \u2192 u = v) \u2194 submodule.span \ud835\udd5c v\u15ee = \u22a5 := sorry\n\n/-- An orthonormal set in an `inner_product_space` is maximal, if and only if the closure of its\nspan is the whole space. -/\ntheorem maximal_orthonormal_iff_dense_span {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : set E} [complete_space E] (hv : orthonormal \ud835\udd5c coe) : (\u2200 (u : set E), u \u2287 v \u2192 orthonormal \ud835\udd5c coe \u2192 u = v) \u2194 submodule.topological_closure (submodule.span \ud835\udd5c v) = \u22a4 := sorry\n\n/-- Any orthonormal subset can be extended to an orthonormal set whose span is dense. -/\ntheorem exists_subset_is_orthonormal_dense_span {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : set E} [complete_space E] (hv : orthonormal \ud835\udd5c coe) : \u2203 (u : set E), \u2203 (H : u \u2287 v), orthonormal \ud835\udd5c coe \u2227 submodule.topological_closure (submodule.span \ud835\udd5c u) = \u22a4 := sorry\n\n/-- An inner product space admits an orthonormal set whose span is dense. -/\ntheorem exists_is_orthonormal_dense_span (\ud835\udd5c : Type u_1) (E : Type u_2) [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [complete_space E] : \u2203 (u : set E), orthonormal \ud835\udd5c coe \u2227 submodule.topological_closure (submodule.span \ud835\udd5c u) = \u22a4 := sorry\n\n/-- An orthonormal set in a finite-dimensional `inner_product_space` is maximal, if and only if it\nis a basis. -/\ntheorem maximal_orthonormal_iff_is_basis_of_finite_dimensional {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : set E} [finite_dimensional \ud835\udd5c E] (hv : orthonormal \ud835\udd5c coe) : (\u2200 (u : set E), u \u2287 v \u2192 orthonormal \ud835\udd5c coe \u2192 u = v) \u2194 is_basis \ud835\udd5c coe := sorry\n\n/-- In a finite-dimensional `inner_product_space`, any orthonormal subset can be extended to an\northonormal basis. -/\ntheorem exists_subset_is_orthonormal_basis {\ud835\udd5c : Type u_1} {E : Type u_2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] {v : set E} [finite_dimensional \ud835\udd5c E] (hv : orthonormal \ud835\udd5c coe) : \u2203 (u : set E), \u2203 (H : u \u2287 v), orthonormal \ud835\udd5c coe \u2227 is_basis \ud835\udd5c coe := sorry\n\n/-- A finite-dimensional `inner_product_space` has an orthonormal basis. -/\ntheorem exists_is_orthonormal_basis (\ud835\udd5c : Type u_1) (E : Type u_2) [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E] [finite_dimensional \ud835\udd5c E] : \u2203 (u : set E), orthonormal \ud835\udd5c coe \u2227 is_basis \ud835\udd5c coe := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/analysis/normed_space/inner_product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.718320198498087}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_116\n  (k x: \u211d)\n  (h\u2080 : x = (13 - real.sqrt 131) / 4)\n  (h\u2081 : 2 * x^2 - 13 * x + k = 0) :\n  k = 19/4 :=\nbegin\n  rw h\u2080 at h\u2081,\n  rw eq_comm.mp (add_eq_zero_iff_neg_eq.mp h\u2081),\n  norm_num,\n  rw pow_two,\n  rw mul_sub,\n  rw [sub_mul, sub_mul],\n  rw real.mul_self_sqrt _,\n  ring,\n  linarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p116.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.7183201983373912}}
{"text": "import game.order.level03\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 4\n\nThis level invites you to work out a property of the absolute value.\nIn Lean the absolute value of $x$ is denoted by `abs x`. \nFor ease of use, a notation can be used around that definition as below.\nFeel free to use the triangle inequality on the real numbers,\n\n`abs_add : \u2200 (a b : ?M_1), |a + b| \u2264 |a| + |b|`\n\ntogether with the `linarith` and `norm_num` tactics.\n-/\n\n/- Hint : a - b = a + (-b)\n-/\n\nnotation `|` x `|` := abs x\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$| a - b| \u2264 |a| + |b|$$.\n-/\ntheorem abs_sub_le_sum_abs (a b : \u211d) : |a - b| \u2264 |a| + |b| :=\nbegin\n    have h : a - b = a + (-b),\n    linarith,\n    rw h,\n    have g := abs_add a (-b),\n    have j : abs (-b) = abs b,\n    norm_num,\n    rw j at g,\n    exact g,\nend\n\nend xena --hide\n\n\n\n\n\n\n\n\n\n\n\n/-\nhave H : a - b = a + (-b), linarith,\n    rw H, \n    have G := abs_add a (-b),\n    have F : abs (-b) = abs b, norm_num,\n    rw F at G, exact G, done\n-/", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/order/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7183201950667384}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_338\n  (a b c : \u211d)\n  (h\u2080 : 3 * a + b + c = -3)\n  (h\u2081 : a + 3 * b + c = 9)\n  (h\u2082 : a + b + 3 * c = 19) :\n  a * b * c = -56 :=\nbegin\n  have ha : a = -4, linarith,\n  have hb : b = 2, linarith,\n  have hc : c = 7, linarith,\n  rw [ha, hb, hc],\n  norm_num,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p338.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7183201840211939}}
{"text": "\nopen Classical\n\n\nvariable (p q r s : Prop)\n\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := by\n  intro (h : p \u2192 r \u2228 s)\n  . apply Or.elim (em r)\n    . intro hr\n      apply Or.inl\n      intro hp\n      assumption\n    . intro hnr\n      apply Or.inr\n      intro hp\n      apply Or.elim (h hp)\n      . intro hr; contradiction\n      . intro hs; assumption\n\n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := by\n  intro h\n  apply Or.elim (em p)\n  . intro hp\n    apply Or.inr\n    intro hq\n    exact h \u27e8hp, hq\u27e9\n  . apply Or.inl\n\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := by\n  intro h\n  constructor\n  . apply Or.elim (em p)\n    . intro hp\n      assumption\n    . intro hnp\n      apply False.elim\n      apply h\n      intro hnp\n      contradiction\n  . intro hq\n    apply h (\u03bb hp => hq)\n\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := by\n  intro h\n  apply Or.elim (em p)\n  . intro hp\n    apply Or.inr\n    exact h hp\n  . apply Or.inl\n\n\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := by\n  intro h\n  intro hp\n  match em q with\n  | Or.inl hq =>\n    assumption\n  | Or.inr hnq =>\n    have hnp := h hnq\n    contradiction\n\n\nexample : p \u2228 \u00acp := by\n  exact em p\n\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := by\n  intro h\n  apply Or.elim (em p)\n  . apply id\n  . intro hnp\n    apply h\n    intro hp\n    contradiction\n    ", "meta": {"author": "bwbush", "repo": "lean4-exercises", "sha": "e6359ed8786210e48ff7a56c4d55c76a77b26594", "save_path": "github-repos/lean/bwbush-lean4-exercises", "path": "github-repos/lean/bwbush-lean4-exercises/lean4-exercises-e6359ed8786210e48ff7a56c4d55c76a77b26594/Exercises-5/Exercises-5-3-2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7182900059639058}}
{"text": "variables p q r : Prop\n\n-- commutativity of \u2227 and \u2228\ndef conjuction_commutativity : p \u2227 q \u2194 q \u2227 p := sorry\n\n\ndef disjunction_commutativity_one_way {p: Prop} {q: Prop} (h : p \u2228 q) : q \u2228 p :=\nor.elim h\n  (assume hp : p,\n    show q \u2228 p, from or.intro_right q hp)\n  (assume hq : q,\n    show q \u2228 p, from or.intro_left p hq)\n\nexample : p \u2228 q \u2194 q \u2228 p := \niff.intro\n  (disjunction_commutativity_one_way)\n  (disjunction_commutativity_one_way)\n\n\ndef conjuction_associativity_left {p: Prop} {q: Prop} {r: Prop} (h: (p \u2227 q) \u2227 r) : p \u2227 (q \u2227 r) :=\nhave hpq: p \u2227 q, from h.left,\nhave hp: p, from hpq.left,\nhave hq: q, from hpq.right,\nhave hr: r, from h.right,\nhave hqr: q \u2227 r, from \u27e8hq, hr\u27e9,\nshow p \u2227 (q \u2227 r), from \u27e8hp, hqr\u27e9\n\ndef conjuction_associativity_right {p: Prop} {q: Prop} {r: Prop} (h: p \u2227 (q \u2227 r)) : (p \u2227 q) \u2227 r :=\nhave hqr: q \u2227 r, from h.right,\nhave hq: q, from hqr.left,\nhave hr: r, from hqr.right,\nhave hp: p, from h.left,\nhave hpq: p \u2227 q, from \u27e8hp, hq\u27e9,\nshow (p \u2227 q) \u2227 r, from \u27e8hpq, hr\u27e9\n\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := \niff.intro \n  (conjuction_associativity_left)\n  (conjuction_associativity_right)\n\n\n\ndef disjunction_associativity_right {p: Prop} {q: Prop} {r: Prop} (h: (p \u2228 q) \u2228 r) : p \u2228 (q \u2228 r) :=\nor.elim h\n  (assume hpq: p \u2228 q,\n    or.elim hpq\n      (assume hp: p,\n        show p \u2228 (q \u2228 r), from or.inl hp )\n      (assume hq: q,\n        have hqr: q \u2228 r, from or.inl hq,\n        show p \u2228 (q \u2228 r), from or.inr hqr))\n  (assume hr: r,\n   have hqr: q \u2228 r, from or.inr hr,\n   show p \u2228 (q \u2228 r), from or.inr hqr)\n\ndef disjunction_associativity_left {p: Prop} {q: Prop} {r: Prop} (h: p \u2228 (q \u2228 r)) : (p \u2228 q) \u2228 r :=\nor.elim h\n  (assume hp: p,\n   have hpq: p \u2228 q, from or.inl hp,\n   show (p \u2228 q) \u2228 r, from or.inl hpq)\n  (assume hqr: q \u2228 r,\n    or.elim hqr\n      (assume hq: q,\n        have hpq: p \u2228 q, from or.inr hq,\n        show (p \u2228 q) \u2228 r, from or.inl hpq)\n      (assume hr: r,\n        show (p \u2228 q) \u2228 r, from or.inr hr ))\n\n\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := \niff.intro\n  (disjunction_associativity_right)\n  (disjunction_associativity_left)\n\n\n-- distributivity\ndef conjunction_distributivity {p: Prop} {q: Prop} {r: Prop} : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := \niff.intro\n  (assume hpqr: p \u2227 (q \u2228 r),\n   have hp: p, from hpqr.left,\n   have hqr: q \u2228 r, from hpqr.right,\n   or.elim hqr\n      (assume hq: q,\n        have hpq: p \u2227 q, from \u27e8hp, hq\u27e9,\n        show (p \u2227 q) \u2228 (p \u2227 r), from or.inl hpq\n      )\n      (assume hr: r,\n        have hpr: p \u2227 r, from \u27e8hp, hr\u27e9,\n        show (p \u2227 q) \u2228 (p \u2227 r), from or.inr hpr\n      )\n  )\n  (assume pqpr: (p \u2227 q) \u2228 (p \u2227 r),\n    or.elim pqpr\n      (assume pq: p \u2227 q,\n        have hp: p, from pq.left,\n        have hq: q, from pq.right,\n        have hqr: q \u2228 r, from or.inl hq,\n        show p \u2227 (q \u2228 r), from \u27e8hp,hqr\u27e9\n      )\n      (assume pr: p \u2227 r,\n        have hp: p, from pr.left,\n        have hr: r, from pr.right,\n        have hqr: q \u2228 r, from or.inr hr,\n        show p \u2227 (q \u2228 r), from \u27e8hp,hqr\u27e9 \n      )\n  )\n\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := sorry\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := \niff.intro\n  (assume hpqr: p \u2192 (q \u2192 r),\n    assume hpq: p \u2227 q,\n    have hp: p, from hpq.left,\n    have hq: q, from hpq.right,\n    have hqr: q \u2192 r,from hpqr hp,\n    show r, from hqr hq\n  )\n  (assume hpqr: p \u2227 q \u2192 r,\n    assume hp: p,\n    assume hq: q,\n    show r,from hpqr \u27e8hp, hq\u27e9 \n  )\n\n\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\niff.intro\n\n(assume hpqr: (p \u2228 q) \u2192 r,\n have hpr: p \u2192 r, from \n  assume hp: p, \n    have hpq: p \u2228 q, from or.inl  hp, \n    show r, from hpqr hpq,\n have hqr: q \u2192 r, from\n  assume hq: q,\n    have hpq: p \u2228 q, from or.inr hq,\n    show r, from hpqr hpq,\n show (p \u2192 r) \u2227 (q \u2192 r), from \u27e8hpr, hqr\u27e9 )\n\n(assume hprqr: (p \u2192 r) \u2227 (q \u2192 r),\n  assume hpq: p \u2228 q,\n    or.elim hpq \n      (assume hp: p,\n        show r, from hprqr.left hp)\n      (assume hq: q,\n        show r, from hprqr.right hq)) \n\n\ndef disjunction_negation: \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := \niff.intro\n\n(assume npq: \u00ac(p \u2228 q),\nhave np: \u00acp, from\n  assume hp: p,\n    have hpq: p \u2228 q, from or.inl hp,\n    show false, from npq hpq,\nhave nq: \u00acq, from \n  assume hq: q,\n    have hpq: p \u2228 q, from or.inr hq,\n    show false, from npq hpq,\nshow \u00acp \u2227 \u00acq, from \u27e8np, nq\u27e9)\n\n(assume npnq: \u00acp \u2227 \u00acq,\nassume pq: p \u2228 q,\n or.elim pq\n (assume hp: p,\n  show false, from npnq.left hp)\n (assume hq: q,\n  show false, from npnq.right hq)\n)\n\n\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := \nassume npnq: \u00acp \u2228 \u00acq,\nassume hpq: p \u2227 q,\nor.elim npnq\n(assume hnp: \u00acp,\nshow false, from hnp hpq.left)\n(assume hnq: \u00acq,\nshow false, from hnq hpq.right)\n\n\nexample : \u00ac(p \u2227 \u00acp) := \nassume npq: p \u2227 \u00acp,\nshow false, from npq.right npq.left \n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := \nassume hpnq: p \u2227 \u00acq,\nassume hpq: p \u2192 q,\nshow false, from hpnq.right (hpq hpnq.left)\n\nexample : \u00acp \u2192 (p \u2192 q) := \nassume hnp: \u00acp,\nassume hp: p,\nshow q, from absurd hp hnp\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := \nassume hnpq: \u00acp \u2228 q,\nassume hp: p,\nor.elim hnpq\n(assume nhp: \u00acp,\nshow q, from absurd hp nhp\n)\n(assume hq: q,\nshow q, from hq)\n\ndef disjunction_with_false : p \u2228 false \u2194 p := \niff.intro\n(assume hpf: p \u2228 false,\nor.elim hpf\n  (assume hp: p,\n  show p , from hp)\n  (assume hf: false,\n  show p, from false.elim hf))\n(assume hp: p,\nshow p \u2228 false, from or.intro_left false hp )\n\nexample : p \u2227 false \u2194 false := \niff.intro\n(assume hpf: p \u2227 false,\nshow false, from hpf.right)\n(assume hf: false,\nshow p \u2227 false, from false.elim hf)\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := \nassume hpq: p \u2192 q,\nassume hnq: \u00acq,\nassume hp: p,\nhave hq: q, from hpq hp,\nshow false, from hnq hq \n\n\n\nopen classical\n\nvariables s : Prop\n\n\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := \nassume hprs: p \u2192 r \u2228 s,\nor.elim (em r)\n  (assume vr: r,\n    or.inl \n      (show p \u2192 r, from\n        assume hp: p,\n        vr)\n  )\n  (assume hnr: \u00acr,\n    or.inr\n      (show p \u2192 s, from\n        assume hp: p,\n        or.elim (hprs hp)\n          (assume hr: r,\n           show s, from absurd hr hnr)\n          (assume hs: s,\n           show s, from hs\n          )\n        )\n  )\n\n\n\ndef conjunction_negation {p: Prop} {q: Prop} (h : \u00ac(p \u2227 q)) : \u00acp \u2228 \u00acq :=\nor.elim (em p)\n  (assume hp : p,\n    or.inr\n      (show \u00acq, from\n        assume hq : q,\n        h \u27e8hp, hq\u27e9))\n  (assume hp : \u00acp,\n    or.inl hp)\n\n\ntheorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : \u00acp, absurd hnp h)\n\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := \nassume npq: \u00ac(p \u2192 q),\nby_cases\n  (assume h1:  p \u2227 \u00acq, h1)\n  (assume h2: \u00ac(p \u2227 \u00acq),\n    have hpq: p \u2192 q, from \n      assume hp: p,\n        have hnpq: \u00acp \u2228 \u00ac\u00acq, from conjunction_negation h2,\n        have hpnpq: p \u2227 (\u00acp \u2228 \u00ac\u00acq), from \u27e8hp, hnpq\u27e9,\n        have pnppnnq: (p \u2227 \u00acp) \u2228 (p \u2227 \u00ac\u00acq),\n          from iff.mp conjunction_distributivity hpnpq,\n        or.elim pnppnnq\n          (assume pnp: (p \u2227 \u00acp),\n            show q, from absurd pnp.left pnp.right)\n          (assume pnnq: (p \u2227 \u00ac\u00acq),\n            show q, from dne pnnq.right),\n    show p \u2227 \u00acq, from absurd hpq npq)\n    \n  --  p \u2227 \u00ac(p \u2227 \u00acq) = p \u2227 (\u00acp \u2228 q) =(! p \u2227 \u00acp ?!?!= false  ) false \u2228 (p \u2227 q) =\n  -- = p \u2227 q = q\n  \ndef impication_negation_to_disjunction {p: Prop} {q: Prop} : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := \nassume npq: \u00ac(p \u2192 q),\nby_contradiction \n  (assume h2: \u00ac(p \u2227 \u00acq), \n  have hpq: p \u2192 q, from \n      assume hp: p,\n        have hnpq: \u00acp \u2228 \u00ac\u00acq, from conjunction_negation h2,\n        have hpnpq: p \u2227 (\u00acp \u2228 \u00ac\u00acq), from \u27e8hp, hnpq\u27e9,\n        have pnppnnq: (p \u2227 \u00acp) \u2228 (p \u2227 \u00ac\u00acq),\n          from iff.mp conjunction_distributivity hpnpq,\n        or.elim pnppnnq\n          (assume pnp: (p \u2227 \u00acp),\n            show q, from absurd pnp.left pnp.right)\n          (assume pnnq: (p \u2227 \u00ac\u00acq),\n            show q, from dne pnnq.right),\n  show false, from absurd hpq npq)\n\n\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := \nassume hpq: p \u2192 q,\nby_cases\n  (assume hp: p, or.inr (hpq hp))\n  (assume hnp: \u00acp, or.inl hnp)\n\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := \nassume npnq: \u00acq \u2192 \u00acp,\nassume hp:p,\nby_cases\n  (assume hq: q, hq)\n  (assume hnq: \u00acq, absurd hp (npnq hnq))\n\nexample : p \u2228 \u00acp := \nby_cases\n  (assume hp: p, or.inl hp)\n  (assume hnp: \u00acp, or.inr hnp)\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := \nassume hpqp: (p \u2192 q) \u2192 p,\nby_cases\n  (assume hpq: (p \u2192 q), hpqp hpq)\n  (assume nhpq: \u00ac(p \u2192 q), \n    (impication_negation_to_disjunction nhpq).left )\n\n\n-- Prove \u00ac(p \u2194 \u00acp) without using classical logic.\n-- p \u2194 \u00acp - > false  \n\nexample: \u00ac(p \u2194 \u00acp) :=-\nassume pisnotp: p \u2194 \u00acp,\niff.mp pisnotp -- p -> \u00acp   , \u00acp = p -> false\npisnotp -- \u00ac(p <-> \u00acp) =  p <-> \u00acp  -> false    \npisnotp -- false\n\nexample: \u00ac(p \u2194 \u00acp) :=\nassume pisnotp: p \u2194 \u00acp,\nhave h1: p \u2192 \u00acp  , from iff.mp pisnotp,\nhave h2: \u00ac (p \u2194 \u00acp), from h1 pisnotp,\n\n\n\nexample: (p \u2194 q) \u2192 (q \u2194 p) :=\n  assume pq: p \u2194 q,\n   iff.intro\n   (assume hq: q,\n    iff.mpr pq hq)\n   (assume hp: p,\n    iff.mp pq hp)\n   \n", "meta": {"author": "kokushkin", "repo": "lean-exercises", "sha": "bc606954cd81b5174f394c0aadc43c4638eca076", "save_path": "github-repos/lean/kokushkin-lean-exercises", "path": "github-repos/lean/kokushkin-lean-exercises/lean-exercises-bc606954cd81b5174f394c0aadc43c4638eca076/part3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7182900003811735}}
{"text": "/-\nCopyright (c) 2020 Shing Tak Lam. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam\n-/\nimport data.zmod.basic\nimport group_theory.exponent\n\n/-!\n# Dihedral Groups\n\nWe define the dihedral groups `dihedral_group n`, with elements `r i` and `sr i` for `i : zmod n`.\n\nFor `n \u2260 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`\nrepresents the rotations of the `n`-gon by `2\u03c0i/n`, and `sr i` represents the reflections of the\n`n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.\n-/\n\n/--\nFor `n \u2260 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon.\n`r i` represents the rotations of the `n`-gon by `2\u03c0i/n`, and `sr i` represents the reflections of\nthe `n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.\n-/\n@[derive decidable_eq]\ninductive dihedral_group (n : \u2115) : Type\n| r : zmod n \u2192 dihedral_group\n| sr : zmod n \u2192 dihedral_group\n\nnamespace dihedral_group\n\nvariables {n : \u2115}\n\n/--\nMultiplication of the dihedral group.\n-/\nprivate def mul : dihedral_group n \u2192 dihedral_group n \u2192 dihedral_group n\n| (r i) (r j) := r (i + j)\n| (r i) (sr j) := sr (j - i)\n| (sr i) (r j) := sr (i + j)\n| (sr i) (sr j) := r (j - i)\n\n/--\nThe identity `1` is the rotation by `0`.\n-/\nprivate def one : dihedral_group n := r 0\n\ninstance : inhabited (dihedral_group n) := \u27e8one\u27e9\n\n/--\nThe inverse of a an element of the dihedral group.\n-/\nprivate def inv : dihedral_group n \u2192 dihedral_group n\n| (r i) := r (-i)\n| (sr i) := sr i\n\n/--\nThe group structure on `dihedral_group n`.\n-/\ninstance : group (dihedral_group n) :=\n{ mul := mul,\n  mul_assoc :=\n  begin\n    rintros (a | a) (b | b) (c | c);\n    simp only [mul];\n    ring,\n  end,\n  one := one,\n  one_mul :=\n  begin\n    rintros (a | a),\n    exact congr_arg r (zero_add a),\n    exact congr_arg sr (sub_zero a),\n  end,\n  mul_one := begin\n    rintros (a | a),\n    exact congr_arg r (add_zero a),\n    exact congr_arg sr (add_zero a),\n  end,\n  inv := inv,\n  mul_left_inv := begin\n    rintros (a | a),\n    exact congr_arg r (neg_add_self a),\n    exact congr_arg r (sub_self a),\n  end }\n\n@[simp] lemma r_mul_r (i j : zmod n) : r i * r j = r (i + j) := rfl\n@[simp] lemma r_mul_sr (i j : zmod n) : r i * sr j = sr (j - i) := rfl\n@[simp] lemma sr_mul_r (i j : zmod n) : sr i * r j = sr (i + j) := rfl\n@[simp] lemma sr_mul_sr (i j : zmod n) : sr i * sr j = r (j - i) := rfl\n\nlemma one_def : (1 : dihedral_group n) = r 0 := rfl\n\nprivate def fintype_helper : (zmod n \u2295 zmod n) \u2243 dihedral_group n :=\n{ inv_fun := \u03bb i, match i with\n                 | (r j) := sum.inl j\n                 | (sr j) := sum.inr j\n                 end,\n  to_fun := \u03bb i, match i with\n                 | (sum.inl j) := r j\n                 | (sum.inr j) := sr j\n                 end,\n  left_inv := by rintro (x | x); refl,\n  right_inv := by rintro (x | x); refl }\n\n/--\nIf `0 < n`, then `dihedral_group n` is a finite group.\n-/\ninstance [ne_zero n] : fintype (dihedral_group n) := fintype.of_equiv _ fintype_helper\n\ninstance : nontrivial (dihedral_group n) := \u27e8\u27e8r 0, sr 0, dec_trivial\u27e9\u27e9\n\n/--\nIf `0 < n`, then `dihedral_group n` has `2n` elements.\n-/\nlemma card [ne_zero n] : fintype.card (dihedral_group n) = 2 * n :=\nby rw [\u2190 fintype.card_eq.mpr \u27e8fintype_helper\u27e9, fintype.card_sum, zmod.card, two_mul]\n\n@[simp] lemma r_one_pow (k : \u2115) : (r 1 : dihedral_group n) ^ k = r k :=\nbegin\n  induction k with k IH,\n  { rw nat.cast_zero, refl },\n  { rw [pow_succ, IH, r_mul_r],\n    congr' 1,\n    norm_cast,\n    rw nat.one_add }\nend\n\n@[simp] lemma r_one_pow_n : (r (1 : zmod n))^n = 1 :=\nbegin\n  rw [r_one_pow, one_def],\n  congr' 1,\n  exact zmod.nat_cast_self _,\nend\n\n@[simp] \n\n/--\nIf `0 < n`, then `sr i` has order 2.\n-/\n@[simp] lemma order_of_sr (i : zmod n) : order_of (sr i) = 2 :=\nbegin\n  rw order_of_eq_prime _ _,\n  { exact \u27e8nat.prime_two\u27e9 },\n  rw [sq, sr_mul_self],\n  dec_trivial,\nend\n\n/--\nIf `0 < n`, then `r 1` has order `n`.\n-/\n@[simp] lemma order_of_r_one : order_of (r 1 : dihedral_group n) = n :=\nbegin\n  rcases eq_zero_or_ne_zero n with rfl | hn,\n  { rw order_of_eq_zero_iff',\n    intros n hn,\n    rw [r_one_pow, one_def],\n    apply mt r.inj,\n    simpa using hn.ne' },\n  { resetI,\n    apply (nat.le_of_dvd (ne_zero.pos n) $ order_of_dvd_of_pow_eq_one $ @r_one_pow_n n)\n      .lt_or_eq.resolve_left,\n    intro h,\n    have h1 : (r 1 : dihedral_group n)^(order_of (r 1)) = 1,\n    { exact pow_order_of_eq_one _ },\n    rw r_one_pow at h1,\n    injection h1 with h2,\n    rw [\u2190 zmod.val_eq_zero, zmod.val_nat_cast, nat.mod_eq_of_lt h] at h2,\n    exact absurd h2.symm (order_of_pos _).ne },\nend\n\n/--\nIf `0 < n`, then `i : zmod n` has order `n / gcd n i`.\n-/\nlemma order_of_r [ne_zero n] (i : zmod n) : order_of (r i) = n / nat.gcd n i.val :=\nbegin\n  conv_lhs { rw \u2190zmod.nat_cast_zmod_val i },\n  rw [\u2190r_one_pow, order_of_pow, order_of_r_one]\nend\n\nlemma exponent : monoid.exponent (dihedral_group n) = lcm n 2 :=\nbegin\n  rcases eq_zero_or_ne_zero n with rfl | hn,\n  { exact monoid.exponent_eq_zero_of_order_zero order_of_r_one },\n  resetI,\n  apply nat.dvd_antisymm,\n  { apply monoid.exponent_dvd_of_forall_pow_eq_one,\n    rintro (m | m),\n    { rw [\u2190order_of_dvd_iff_pow_eq_one, order_of_r],\n      refine nat.dvd_trans \u27e8gcd n m.val, _\u27e9 (dvd_lcm_left n 2),\n      { exact (nat.div_mul_cancel (nat.gcd_dvd_left n m.val)).symm } },\n    { rw [\u2190order_of_dvd_iff_pow_eq_one, order_of_sr],\n      exact dvd_lcm_right n 2 } },\n  { apply lcm_dvd,\n    { convert monoid.order_dvd_exponent (r 1),\n      exact order_of_r_one.symm },\n    { convert monoid.order_dvd_exponent (sr 0),\n      exact (order_of_sr 0).symm } }\nend\n\nend dihedral_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/specific_groups/dihedral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7905303211371899, "lm_q1q2_score": 0.7182899978533072}}
{"text": "import combinatorics.simple_graph.clique\nimport combinatorics.simple_graph.degree_sum\nimport data.finset.basic\nimport data.nat.basic\nimport tactic.core\nimport algebra.big_operators\n--local\nimport nbhd_res\n\n\nopen finset nat \nopen_locale big_operators \n\nnamespace simple_graph\n\nsection clique_free_sets\nvariables {t n : \u2115} \nvariables {\u03b1 : Type*} (G : simple_graph \u03b1) [fintype \u03b1][nonempty \u03b1]{s : finset \u03b1}[decidable_eq \u03b1][decidable_rel G.adj]\n\n\n-- restricted nbhd is the part of nbhd in A\ninclude G\n-- we will need the concept of a clique-free set of vertices in a graph rather than just clique-free graphs\n-- A is a t-clique-free set of vertices in G\ndef clique_free_set (A : finset \u03b1) (s : \u2115): Prop:= \u2200 B \u2286 A, \u00acG.is_n_clique s B\n\n--clique-free if too small\nlemma clique_free_card_lt {A : finset \u03b1} {s: \u2115} (h: A.card <s): G.clique_free_set A s:=\nbegin\n  rw clique_free_set,intros B hB,rw is_n_clique_iff,push_neg,intro h1,\n  exact ne_of_lt (lt_of_le_of_lt (card_le_of_subset hB) h), \nend\n\n--clique-free of empty (unless s=0)\nlemma clique_free_empty {s : \u2115} (h: 0< s): G.clique_free_set \u2205 s:=\nbegin\n  have:=finset.card_empty, rw \u2190 this at h, exact G.clique_free_card_lt h,\nend\n\n-- if G has no s-clique then nor does the univ \nlemma clique_free_graph_imp_set {s : \u2115} (h: G.clique_free s) :  G.clique_free_set univ s:=\nbegin\n  revert h, contrapose,\n  rw clique_free_set,push_neg,intro h, rw clique_free, push_neg,\n  obtain \u27e8B,h1,h2\u27e9:=h,  exact \u27e8B,h2\u27e9,\nend\n\n-- base case for Erdos/Furedi proof:\n-- if A has no 2-clique then restricted degrees are all zero \n-- i.e. A is an independent set\n\nlemma two_clique_free {A: finset \u03b1} (hA : G.clique_free_set A 2) :  \u2200v\u2208A, G.deg_res v A =0 :=\nbegin\n  intros v hv, rw [deg_res,card_eq_zero], \n  contrapose hA,\n  obtain \u27e8w,hw\u27e9:=exists_mem_nempty G hA,\n  cases hw with h1 h2, \n  have ne: v\u2260w := adj.ne h2,\n  have c2 :card {v,w} =2:=card_doubleton ne,\n  have :G.is_n_clique 2 {v,w},{\n    rw [is_n_clique_iff, coe_insert, coe_singleton, is_clique_iff,set.pairwise_pair_of_symmetric],\n    exact \u27e8\u03bbh,h2,c2\u27e9,exact G.symm,},\n  rw clique_free_set, push_neg,\n  refine \u27e8{v,w},_,this\u27e9, intros x hx,\n  simp only [mem_insert, mem_singleton] at *,cases hx,{ rw hx,exact hv},{rw hx, exact h1},\nend\n\n-- sum of deg_res over an independent set (2-clique-free set) is 0\n-- e (G.ind A)=0\nlemma two_clique_free_sum {A: finset \u03b1} (hA : G.clique_free_set A 2) : \u2211 v in A, G.deg_res v A = 0\n:=sum_eq_zero (G.two_clique_free hA)\n\n\n-- if A set is (t+2)-clique-free then any member vertex \n-- has restricted nbhd that is (t+1)-clique-free \n-- (just prove for any simple_graph \u03b1 if  G is (t+2)-clique free then so is any nbhd of a vertex in G\n-- then can apply it to G.ind A etc...\nlemma t_clique_free {A: finset \u03b1} {v :\u03b1}(hA : G.clique_free_set A (t + 2)) (hv : v \u2208 A) :\nG.clique_free_set (G.nbhd_res v A) (t + 1):=\nbegin\n  rw clique_free_set at *, \n  intros B hB, contrapose! hA,\n  set C:= B \u222a {v} with hC,\n  refine \u27e8C,_,_\u27e9,{\n  rw hC, apply union_subset (subset_trans hB (G.sub_res_nbhd_A v A)) _,\n  simp only [hv, singleton_subset_iff]},\n  rw is_n_clique_iff at *,\n  refine \u27e8_,_\u27e9,{\n  rcases hA with \u27e8cl,ca\u27e9, \n  rw [is_clique_iff, set.pairwise],\n  intros x hx y hy hne,\n  by_cases x=v,\n    have yB : y\u2208 G.neighbor_finset v,{ \n      simp only [*, coe_union, coe_singleton, set.union_singleton, set.mem_insert_iff, \n      mem_coe, eq_self_iff_true, true_or, ne.def] at *,\n      cases hy,exfalso, exact hne hy.symm, \n      exact (mem_of_mem_inter_right (hB hy)),},\n    rwa [h, \u2190 mem_neighbor_finset G v],\n    by_cases h2:  y=v,{\n      rw h2, simp only [*, ne.def, not_false_iff, coe_union, coe_singleton, set.union_singleton,\n      set.mem_insert_iff, eq_self_iff_true, mem_coe, true_or, false_or] at *,\n      rw [adj_comm,  \u2190 mem_neighbor_finset G v],\n      exact mem_of_mem_inter_right (hB hx)},\n    simp only [*, ne.def, coe_union, coe_singleton, set.union_singleton, set.mem_insert_iff, \n    mem_coe, false_or, eq_self_iff_true] at *,\n    exact cl hx hy hne},{\n    have: 2=1+1:=by norm_num,\n    rw [hC,this, \u2190 add_assoc],\n    convert card_union_eq _,{exact hA.2.symm},\n    rw disjoint_singleton_right, \n    intros h, apply  (not_mem_res_nbhd G v A) (hB h)},\nend\n\n\nend clique_free_sets\n\nend simple_graph\n", "meta": {"author": "jt496", "repo": "extremal_graph", "sha": "1bfb63ed1f6ca633d1ee4e1846f429cfe32c6a83", "save_path": "github-repos/lean/jt496-extremal_graph", "path": "github-repos/lean/jt496-extremal_graph/extremal_graph-1bfb63ed1f6ca633d1ee4e1846f429cfe32c6a83/src/clique_free_sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7182899958971168}}
{"text": "import analysis.special_functions.exp\nimport analysis.special_functions.exp_deriv\nimport basic\nopen polynomial\n\nopen set filter\n\nnoncomputable theory\n\n@[simp]\ndef x_sub_dx_fn (f : \u211d \u2192 \u211d) :=\nid * f - deriv f\n\nlemma x_sub_dx_fn_def (f : \u211d \u2192 \u211d) : x_sub_dx_fn f = id * f - deriv f := rfl\n\nlemma x_sub_dx_fn_apply (f : \u211d \u2192 \u211d) (x : \u211d) :\nx_sub_dx_fn f x = x * f x - deriv f x := rfl\n\ndef gaussian : \u211d \u2192 \u211d := \u03bb x, real.exp (-(x^2 / 2))\n\ndef inv_gaussian : \u211d \u2192 \u211d := \u03bb x, real.exp (x^2 / 2)\n\n\nlemma inv_gaussian_mul_gaussian (x : \u211d) : inv_gaussian x * gaussian x = 1 :=\nby rw [gaussian, inv_gaussian, \u2190 real.exp_add, add_neg_self, real.exp_zero]\n\n\nlemma deriv_gaussian (x : \u211d) : deriv gaussian x = -x * gaussian x :=\nby simp [gaussian, mul_comm]\n\nlemma deriv_inv_gaussian (x : \u211d) : deriv inv_gaussian x = x * inv_gaussian x :=\nby simp [inv_gaussian, mul_comm]\n\nlemma cont_diff_gaussian : cont_diff \u211d \u22a4 gaussian :=\n((cont_diff_id.pow 2).div_const 2).neg.exp\n\nlemma cont_diff.iterated_deriv :\n\u2200 (n : \u2115) (f : \u211d \u2192 \u211d) (hf : cont_diff \u211d \u22a4 f), cont_diff \u211d \u22a4 (deriv^[n] f)\n| 0     f hf := hf\n| (n+1) f hf := cont_diff.iterated_deriv n (deriv f) (cont_diff_top_iff_deriv.mp hf).2\n\n\n@[simp]\ndef hermite_exp (n : \u2115) : \u211d \u2192 \u211d :=\n\u03bb x, (-1)^n * (inv_gaussian x) * (deriv^[n] gaussian x)\n\nlemma hermite_exp_def (n : \u2115) : \nhermite_exp n = \u03bb x, (-1)^n * (inv_gaussian x) * (deriv^[n] gaussian x) := rfl\n\nlemma hermite_exp_succ (n : \u2115) : hermite_exp (n+1)\n= x_sub_dx_fn (hermite_exp n) :=\nbegin\n  ext,\n  simp only [hermite_exp, x_sub_dx_fn, function.iterate_succ', function.comp_app,\n             id.def, pi.mul_apply, pi.sub_apply, pow_succ],\n  rw [deriv_mul, deriv_const_mul, deriv_inv_gaussian],\n  ring,\n  { simp [inv_gaussian] },\n  { simp [inv_gaussian] },\n  { apply (cont_diff_top_iff_deriv.mp (cont_diff.iterated_deriv _ _ cont_diff_gaussian)).1 }, \nend\n\nlemma exp_mul_exp_neg_eq_one (x : \u211d) : real.exp(x) * real.exp(-x) = 1 :=\nbegin\n  rw real.exp_neg,\n  apply (mul_inv_eq_one\u2080 (real.exp_ne_zero (x))).mpr,\n  refl,\nend\n\n-- @[simp]\n-- lemma hermite_exp_zero : (\u03bb x, (-1)^0 * (inv_gaussian x) * (deriv^[0] gaussian x)) = (\u03bb x, 1) :=\n-- begin\n--   ext,\n--   simp [hermite_exp, inv_gaussian, gaussian, exp_mul_exp_neg_eq_one]\n-- end\n\nlemma eval_x_sub_dx_eq (p : polynomial \u211d) :\n(\u03bb (x : \u211d), eval x (x_sub_dx p)) = x_sub_dx_fn (\u03bb (x : \u211d), eval x p) :=\nbegin\n  ext, simp,\nend\n\nlemma hermite_eq_exp (n : \u2115) :\n(\u03bb x, eval x (hermite n)) = \u03bb x, (-1)^n * (inv_gaussian x) * (deriv^[n] gaussian x) :=\nbegin\n  induction n with n ih,\n  { simp [inv_gaussian_mul_gaussian] },\n  { rw [\u2190 hermite_exp_def, hermite_exp_succ,\n    hermite_succ, eval_x_sub_dx_eq, hermite_exp_def, ih] },\nend\n\nlemma hermite_eq_exp_apply : \u2200 (n : \u2115) (x : \u211d), eval x (hermite n) = (-1)^n * (inv_gaussian x) * (deriv^[n] gaussian x) :=\n\u03bb n x, congr_fun (hermite_eq_exp n) x", "meta": {"author": "lukemantle", "repo": "hermite", "sha": "fe6c8b778c41afb6f2b5f12eded951ecf6775a13", "save_path": "github-repos/lean/lukemantle-hermite", "path": "github-repos/lean/lukemantle-hermite/hermite-fe6c8b778c41afb6f2b5f12eded951ecf6775a13/src/exp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7182899875006795}}
{"text": "/-\nCopyright (c) 2021 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport linear_algebra.basic\n\n/-!\n# Rays in modules\n\nThis file defines rays in modules.\n\n## Main definitions\n\n* `same_ray`: two vectors belong to the same ray if they are proportional with a nonnegative\n  coefficient.\n\n* `module.ray` is a type for the equivalence class of nonzero vectors in a module with some\ncommon positive multiple.\n-/\n\nnoncomputable theory\n\nopen_locale big_operators\n\nsection ordered_comm_semiring\n\nvariables (R : Type*) [ordered_comm_semiring R]\nvariables {M : Type*} [add_comm_monoid M] [module R M]\nvariables {N : Type*} [add_comm_monoid N] [module R N]\nvariables (\u03b9 : Type*) [decidable_eq \u03b9]\n\n/-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them\nare equal (in the typical case over a field, this means one of them is a nonnegative multiple of\nthe other). -/\ndef same_ray (v\u2081 v\u2082 : M) : Prop :=\nv\u2081 = 0 \u2228 v\u2082 = 0 \u2228 \u2203 (r\u2081 r\u2082 : R), 0 < r\u2081 \u2227 0 < r\u2082 \u2227 r\u2081 \u2022 v\u2081 = r\u2082 \u2022 v\u2082\n\nvariables {R}\n\nnamespace same_ray\n\nvariables {x y z : M}\n\nlemma zero_left (y : M) : same_ray R 0 y := or.inl rfl\n\nlemma zero_right (x : M) : same_ray R x 0 := or.inr $ or.inl rfl\n\n@[nontriviality] lemma of_subsingleton [subsingleton M] (x y : M) : same_ray R x y :=\nby { rw [subsingleton.elim x 0], exact zero_left _ }\n\n@[nontriviality] lemma of_subsingleton' [subsingleton R] (x y : M) : same_ray R x y :=\nby { haveI := module.subsingleton R M, exact of_subsingleton x y }\n\n/-- `same_ray` is reflexive. -/\n@[refl] lemma refl (x : M) : same_ray R x x :=\nbegin\n  nontriviality R,\n  exact or.inr (or.inr $ \u27e81, 1, zero_lt_one, zero_lt_one, rfl\u27e9)\nend\n\n/-- `same_ray` is symmetric. -/\n@[symm] lemma symm (h : same_ray R x y) : same_ray R y x :=\n(or.left_comm.1 h).imp_right $ or.imp_right $ \u03bb \u27e8r\u2081, r\u2082, h\u2081, h\u2082, h\u27e9, \u27e8r\u2082, r\u2081, h\u2082, h\u2081, h.symm\u27e9\n\n/-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r\u2081 r\u2082`\nsuch that `r\u2081 \u2022 x = r\u2082 \u2022 y`. -/\nlemma exists_pos (h : same_ray R x y) (hx : x \u2260 0) (hy : y \u2260 0) :\n  \u2203 r\u2081 r\u2082 : R, 0 < r\u2081 \u2227 0 < r\u2082 \u2227 r\u2081 \u2022 x = r\u2082 \u2022 y :=\n(h.resolve_left hx).resolve_left hy\n\nlemma _root_.same_ray_comm : same_ray R x y \u2194 same_ray R y x :=\n\u27e8same_ray.symm, same_ray.symm\u27e9\n\n/-- `same_ray` is transitive unless the vector in the middle is zero and both other vectors are\nnonzero. -/\nlemma trans (hxy : same_ray R x y) (hyz : same_ray R y z) (hy : y = 0 \u2192 x = 0 \u2228 z = 0) :\n  same_ray R x z :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hx, { exact zero_left z },\n  rcases eq_or_ne z 0 with rfl|hz, { exact zero_right x },\n  rcases eq_or_ne y 0 with rfl|hy, { exact (hy rfl).elim (\u03bb h, (hx h).elim) (\u03bb h, (hz h).elim) },\n  rcases hxy.exists_pos hx hy with \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u2081\u27e9,\n  rcases hyz.exists_pos hy hz with \u27e8r\u2083, r\u2084, hr\u2083, hr\u2084, h\u2082\u27e9,\n  refine or.inr (or.inr $ \u27e8r\u2083 * r\u2081, r\u2082 * r\u2084, mul_pos hr\u2083 hr\u2081, mul_pos hr\u2082 hr\u2084, _\u27e9),\n  rw [mul_smul, mul_smul, h\u2081, \u2190 h\u2082, smul_comm]\nend\n\n/-- A vector is in the same ray as a nonnegative multiple of itself. -/\nlemma _root_.same_ray_nonneg_smul_right (v : M) {r : R} (h : 0 \u2264 r) : same_ray R v (r \u2022 v) :=\nor.inr $ h.eq_or_lt.imp (\u03bb h, h \u25b8 zero_smul R v) $\n  \u03bb h, \u27e8r, 1, h, by { nontriviality R, exact zero_lt_one }, (one_smul _ _).symm\u27e9\n\n/-- A vector is in the same ray as a positive multiple of itself. -/\nlemma _root_.same_ray_pos_smul_right (v : M) {r : R} (h : 0 < r) : same_ray R v (r \u2022 v) :=\nsame_ray_nonneg_smul_right v h.le\n\n/-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/\nlemma nonneg_smul_right {r : R} (h : same_ray R x y) (hr : 0 \u2264 r) : same_ray R x (r \u2022 y) :=\nh.trans (same_ray_nonneg_smul_right y hr) $ \u03bb hy, or.inr $ by rw [hy, smul_zero]\n\n/-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/\nlemma pos_smul_right {r : R} (h : same_ray R x y) (hr : 0 < r) : same_ray R x (r \u2022 y) :=\nh.nonneg_smul_right hr.le\n\n/-- A nonnegative multiple of a vector is in the same ray as that vector. -/\nlemma _root_.same_ray_nonneg_smul_left (v : M) {r : R} (h : 0 \u2264 r) : same_ray R (r \u2022 v) v :=\n(same_ray_nonneg_smul_right v h).symm\n\n/-- A positive multiple of a vector is in the same ray as that vector. -/\nlemma _root_.same_ray_pos_smul_left (v : M) {r : R} (h : 0 < r) : same_ray R (r \u2022 v) v :=\nsame_ray_nonneg_smul_left v h.le\n\n/-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/\nlemma nonneg_smul_left {r : R} (h : same_ray R x y) (hr : 0 \u2264 r) : same_ray R (r \u2022 x) y :=\n(h.symm.nonneg_smul_right hr).symm\n\n/-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/\nlemma pos_smul_left {r : R} (h : same_ray R x y) (hr : 0 < r) : same_ray R (r \u2022 x) y :=\nh.nonneg_smul_left hr.le\n\n/-- If two vectors are on the same ray then they remain so after applying a linear map. -/\nlemma map (f : M \u2192\u2097[R] N) (h : same_ray R x y) : same_ray R (f x) (f y) :=\nh.imp (\u03bb hx, by rw [hx, map_zero]) $ or.imp (\u03bb hy, by rw [hy, map_zero]) $\n  \u03bb \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9, \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, by rw [\u2190f.map_smul, \u2190f.map_smul, h]\u27e9\n\n/-- The images of two vectors under a linear equivalence are on the same ray if and only if the\noriginal vectors are on the same ray. -/\n@[simp] lemma _root_.same_ray_map_iff (e : M \u2243\u2097[R] N) : same_ray R (e x) (e y) \u2194 same_ray R x y :=\n\u27e8\u03bb h, by simpa using same_ray.map e.symm.to_linear_map h, same_ray.map e.to_linear_map\u27e9\n\n/-- If two vectors are on the same ray then both scaled by the same action are also on the same\nray. -/\nlemma smul {S : Type*} [monoid S] [distrib_mul_action S M] [smul_comm_class R S M]\n  (h : same_ray R x y) (s : S) : same_ray R (s \u2022 x) (s \u2022 y) :=\nh.map (s \u2022 (linear_map.id : M \u2192\u2097[R] M))\n\n/-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/\nlemma add_left (hx : same_ray R x z) (hy : same_ray R y z) : same_ray R (x + y) z :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hx\u2080, { rwa zero_add },\n  rcases eq_or_ne y 0 with rfl|hy\u2080, { rwa add_zero },\n  rcases eq_or_ne z 0 with rfl|hz\u2080, { apply zero_right },\n  rcases hx.exists_pos hx\u2080 hz\u2080 with \u27e8rx, rz\u2081, hrx, hrz\u2081, Hx\u27e9,\n  rcases hy.exists_pos hy\u2080 hz\u2080 with \u27e8ry, rz\u2082, hry, hrz\u2082, Hy\u27e9,\n  refine or.inr (or.inr \u27e8rx * ry, ry * rz\u2081 + rx * rz\u2082, mul_pos hrx hry, _, _\u27e9),\n  { apply_rules [add_pos, mul_pos] },\n  { simp only [mul_smul, smul_add, add_smul, \u2190 Hx, \u2190 Hy],\n    rw smul_comm }\nend\n\n/-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/\nlemma add_right (hy : same_ray R x y) (hz : same_ray R x z) : same_ray R x (y + z) :=\n(hy.symm.add_left hz.symm).symm\n\nend same_ray\n\n/-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that\n`ray_vector.setoid` can be an instance. -/\n@[nolint unused_arguments has_inhabited_instance]\ndef ray_vector (R M : Type*) [has_zero M] := {v : M // v \u2260 0}\n\ninstance ray_vector.has_coe {R M : Type*} [has_zero M] :\n  has_coe (ray_vector R M) M := coe_subtype\n\ninstance {R M : Type*} [has_zero M] [nontrivial M] : nonempty (ray_vector R M) :=\nlet \u27e8x, hx\u27e9 := exists_ne (0 : M) in \u27e8\u27e8x, hx\u27e9\u27e9\n\nvariables (R M)\n\n/-- The setoid of the `same_ray` relation for the subtype of nonzero vectors. -/\ninstance : setoid (ray_vector R M) :=\n{ r := \u03bb x y, same_ray R (x : M) y,\n  iseqv := \u27e8\u03bb x, same_ray.refl _, \u03bb x y h, h.symm,\n    \u03bb x y z hxy hyz, hxy.trans hyz $ \u03bb hy, (y.2 hy).elim\u27e9 }\n\n/-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/\n@[nolint has_inhabited_instance]\ndef module.ray := quotient (ray_vector.setoid R M)\n\nvariables {R M}\n\n/-- Equivalence of nonzero vectors, in terms of same_ray. -/\nlemma equiv_iff_same_ray {v\u2081 v\u2082 : ray_vector R M} :\n  v\u2081 \u2248 v\u2082 \u2194 same_ray R (v\u2081 : M) v\u2082 :=\niff.rfl\n\nvariables (R)\n\n/-- The ray given by a nonzero vector. -/\nprotected def ray_of_ne_zero (v : M) (h : v \u2260 0) : module.ray R M := \u27e6\u27e8v, h\u27e9\u27e7\n\n/-- An induction principle for `module.ray`, used as `induction x using module.ray.ind`. -/\nlemma module.ray.ind {C : module.ray R M \u2192 Prop}\n  (h : \u2200 v (hv : v \u2260 0), C (ray_of_ne_zero R v hv)) (x : module.ray R M) : C x :=\nquotient.ind (subtype.rec $ by exact h) x\n\nvariable {R}\n\ninstance [nontrivial M] : nonempty (module.ray R M) :=\nnonempty.map quotient.mk infer_instance\n\n/-- The rays given by two nonzero vectors are equal if and only if those vectors\nsatisfy `same_ray`. -/\nlemma ray_eq_iff {v\u2081 v\u2082 : M} (hv\u2081 : v\u2081 \u2260 0) (hv\u2082 : v\u2082 \u2260 0) :\n  ray_of_ne_zero R _ hv\u2081 = ray_of_ne_zero R _ hv\u2082 \u2194 same_ray R v\u2081 v\u2082 :=\nquotient.eq\n\n/-- The ray given by a positive multiple of a nonzero vector. -/\n@[simp] lemma ray_pos_smul {v : M} (h : v \u2260 0) {r : R} (hr : 0 < r)\n  (hrv : r \u2022 v \u2260 0) : ray_of_ne_zero R (r \u2022 v) hrv = ray_of_ne_zero R v h :=\n(ray_eq_iff _ _).2 $ same_ray_pos_smul_left v hr\n\n/-- An equivalence between modules implies an equivalence between ray vectors. -/\ndef ray_vector.map_linear_equiv (e : M \u2243\u2097[R] N) : ray_vector R M \u2243 ray_vector R N :=\nequiv.subtype_equiv e.to_equiv $ \u03bb _, e.map_ne_zero_iff.symm\n\n/-- An equivalence between modules implies an equivalence between rays. -/\ndef module.ray.map (e : M \u2243\u2097[R] N) : module.ray R M \u2243 module.ray R N :=\nquotient.congr (ray_vector.map_linear_equiv e) $ \u03bb \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, (same_ray_map_iff _).symm\n\n@[simp] lemma module.ray.map_apply (e : M \u2243\u2097[R] N) (v : M) (hv : v \u2260 0) :\n  module.ray.map e (ray_of_ne_zero _ v hv) = ray_of_ne_zero _ (e v) (e.map_ne_zero_iff.2 hv) := rfl\n\n@[simp] lemma module.ray.map_refl : (module.ray.map $ linear_equiv.refl R M) = equiv.refl _ :=\nequiv.ext $ module.ray.ind R $ \u03bb _ _, rfl\n\n@[simp] lemma module.ray.map_symm (e : M \u2243\u2097[R] N) :\n  (module.ray.map e).symm = module.ray.map e.symm := rfl\n\nsection action\nvariables {G : Type*} [group G] [distrib_mul_action G M]\n\n/-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest\nwhen `G = R\u02e3` -/\ninstance {R : Type*} : mul_action G (ray_vector R M) :=\n{ smul := \u03bb r, (subtype.map ((\u2022) r) $ \u03bb a, (smul_ne_zero_iff_ne _).2),\n  mul_smul := \u03bb a b m, subtype.ext $ mul_smul a b _,\n  one_smul := \u03bb m, subtype.ext $ one_smul _ _ }\n\nvariables [smul_comm_class R G M]\n\n/-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when\n`G = R\u02e3` -/\ninstance : mul_action G (module.ray R M) :=\n{ smul := \u03bb r, quotient.map ((\u2022) r) (\u03bb a b h, h.smul _),\n  mul_smul := \u03bb a b, quotient.ind $ by exact(\u03bb m, congr_arg quotient.mk $ mul_smul a b _),\n  one_smul := quotient.ind $ by exact (\u03bb m, congr_arg quotient.mk $ one_smul _ _), }\n\n/-- The action via `linear_equiv.apply_distrib_mul_action` corresponds to `module.ray.map`. -/\n@[simp] lemma module.ray.linear_equiv_smul_eq_map (e : M \u2243\u2097[R] M) (v : module.ray R M) :\n  e \u2022 v = module.ray.map e v := rfl\n\n@[simp] lemma smul_ray_of_ne_zero (g : G) (v : M) (hv) :\n  g \u2022 ray_of_ne_zero R v hv = ray_of_ne_zero R (g \u2022 v) ((smul_ne_zero_iff_ne _).2 hv) := rfl\n\nend action\n\nnamespace module.ray\n\n/-- Scaling by a positive unit is a no-op. -/\nlemma units_smul_of_pos (u : R\u02e3) (hu : 0 < (u : R)) (v : module.ray R M) :\n  u \u2022 v = v :=\nbegin\n  induction v using module.ray.ind,\n  rw [smul_ray_of_ne_zero, ray_eq_iff],\n  exact same_ray_pos_smul_left _ hu\nend\n\n/-- An arbitrary `ray_vector` giving a ray. -/\ndef some_ray_vector (x : module.ray R M) : ray_vector R M := quotient.out x\n\n/-- The ray of `some_ray_vector`. -/\n@[simp] lemma some_ray_vector_ray (x : module.ray R M) :\n  (\u27e6x.some_ray_vector\u27e7 : module.ray R M) = x :=\nquotient.out_eq _\n\n/-- An arbitrary nonzero vector giving a ray. -/\ndef some_vector (x : module.ray R M) : M := x.some_ray_vector\n\n/-- `some_vector` is nonzero. -/\n@[simp] lemma some_vector_ne_zero (x : module.ray R M) : x.some_vector \u2260 0 :=\nx.some_ray_vector.property\n\n/-- The ray of `some_vector`. -/\n@[simp] lemma some_vector_ray (x : module.ray R M) :\n  ray_of_ne_zero R _ x.some_vector_ne_zero = x :=\n(congr_arg _ (subtype.coe_eta _ _) : _).trans x.out_eq\n\nend module.ray\n\nend ordered_comm_semiring\n\nsection ordered_comm_ring\n\nvariables {R : Type*} [ordered_comm_ring R]\nvariables {M N : Type*} [add_comm_group M] [add_comm_group N] [module R M] [module R N] {x y : M}\n\n/-- `same_ray.neg` as an `iff`. -/\n@[simp] lemma same_ray_neg_iff : same_ray R (-x) (-y) \u2194 same_ray R x y :=\nby simp only [same_ray, neg_eq_zero, smul_neg, neg_inj]\n\nalias same_ray_neg_iff \u2194 same_ray.of_neg same_ray.neg\n\nlemma same_ray_neg_swap : same_ray R (-x) y \u2194 same_ray R x (-y) :=\nby rw [\u2190 same_ray_neg_iff, neg_neg]\n\nlemma eq_zero_of_same_ray_neg_smul_right [no_zero_smul_divisors R M] {r : R} (hr : r < 0)\n  (h : same_ray R x (r \u2022 x)) :\n  x = 0 :=\nbegin\n  rcases h with rfl|h\u2080|\u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9,\n  { refl },\n  { simpa [hr.ne] using h\u2080 },\n  { rw [\u2190 sub_eq_zero, smul_smul, \u2190 sub_smul, smul_eq_zero] at h,\n    refine h.resolve_left (ne_of_gt $ sub_pos.2 _),\n    exact (mul_neg_of_pos_of_neg hr\u2082 hr).trans hr\u2081 }\nend\n\n/-- If a vector is in the same ray as its negation, that vector is zero. -/\nlemma eq_zero_of_same_ray_self_neg [no_zero_smul_divisors R M] (h : same_ray R x (-x)) :\n  x = 0 :=\nbegin\n  nontriviality M, haveI : nontrivial R := module.nontrivial R M,\n  refine eq_zero_of_same_ray_neg_smul_right (neg_lt_zero.2 (@one_pos R _ _)) _,\n  rwa [neg_one_smul]\nend\n\nnamespace ray_vector\n\n/-- Negating a nonzero vector. -/\ninstance {R : Type*} : has_neg (ray_vector R M) := \u27e8\u03bb v, \u27e8-v, neg_ne_zero.2 v.prop\u27e9\u27e9\n\n/-- Negating a nonzero vector commutes with coercion to the underlying module. -/\n@[simp, norm_cast] lemma coe_neg {R : Type*} (v : ray_vector R M) : \u2191(-v) = -(v : M) := rfl\n\n/-- Negating a nonzero vector twice produces the original vector. -/\ninstance {R : Type*} : has_involutive_neg (ray_vector R M) :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb v, by rw [subtype.ext_iff, coe_neg, coe_neg, neg_neg] }\n\n/-- If two nonzero vectors are equivalent, so are their negations. -/\n@[simp] lemma equiv_neg_iff {v\u2081 v\u2082 : ray_vector R M} : -v\u2081 \u2248 -v\u2082 \u2194 v\u2081 \u2248 v\u2082 :=\nsame_ray_neg_iff\n\nend ray_vector\n\nvariables (R)\n\n/-- Negating a ray. -/\ninstance : has_neg (module.ray R M) :=\n\u27e8quotient.map (\u03bb v, -v) (\u03bb v\u2081 v\u2082, ray_vector.equiv_neg_iff.2)\u27e9\n\n/-- The ray given by the negation of a nonzero vector. -/\n@[simp] lemma neg_ray_of_ne_zero (v : M) (h : v \u2260 0) :\n  -(ray_of_ne_zero R _ h) = ray_of_ne_zero R (-v) (neg_ne_zero.2 h) :=\nrfl\n\nnamespace module.ray\n\nvariables {R}\n\n/-- Negating a ray twice produces the original ray. -/\ninstance : has_involutive_neg (module.ray R M) :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb x, quotient.ind (\u03bb a, congr_arg quotient.mk $ neg_neg _) x }\n\nvariables {R M}\n\n/-- A ray does not equal its own negation. -/\nlemma ne_neg_self [no_zero_smul_divisors R M] (x : module.ray R M) : x \u2260 -x :=\nbegin\n  induction x using module.ray.ind with x hx,\n  rw [neg_ray_of_ne_zero, ne.def, ray_eq_iff],\n  exact mt eq_zero_of_same_ray_self_neg hx\nend\n\nlemma neg_units_smul (u : R\u02e3) (v : module.ray R M) : (-u) \u2022 v = - (u \u2022 v) :=\nbegin\n  induction v using module.ray.ind,\n  simp only [smul_ray_of_ne_zero, units.smul_def, units.coe_neg, neg_smul, neg_ray_of_ne_zero]\nend\n\n/-- Scaling by a negative unit is negation. -/\nlemma units_smul_of_neg (u : R\u02e3) (hu : (u : R) < 0) (v : module.ray R M) :\n  u \u2022 v = -v :=\nbegin\n  rw [\u2190 neg_inj, neg_neg, \u2190 neg_units_smul, units_smul_of_pos],\n  rwa [units.coe_neg, right.neg_pos_iff]\nend\n\nend module.ray\n\nend ordered_comm_ring\n\nsection linear_ordered_comm_ring\n\nvariables {R : Type*} [linear_ordered_comm_ring R]\nvariables {M : Type*} [add_comm_group M] [module R M]\n\n/-- `same_ray` follows from membership of `mul_action.orbit` for the `units.pos_subgroup`. -/\nlemma same_ray_of_mem_orbit {v\u2081 v\u2082 : M} (h : v\u2081 \u2208 mul_action.orbit (units.pos_subgroup R) v\u2082) :\n  same_ray R v\u2081 v\u2082 :=\nbegin\n  rcases h with \u27e8\u27e8r, hr : 0 < (r : R)\u27e9, (rfl : r \u2022 v\u2082 = v\u2081)\u27e9,\n  exact same_ray_pos_smul_left _ hr\nend\n\n/-- Scaling by an inverse unit is the same as scaling by itself. -/\n@[simp] lemma units_inv_smul (u : R\u02e3) (v : module.ray R M) :\n  u\u207b\u00b9 \u2022 v = u \u2022 v :=\ncalc u\u207b\u00b9 \u2022 v = (u * u) \u2022 u\u207b\u00b9 \u2022 v :\n  eq.symm $ (u\u207b\u00b9 \u2022 v).units_smul_of_pos _ $ mul_self_pos.2 u.ne_zero\n... = u \u2022 v : by rw [mul_smul, smul_inv_smul]\n\nsection\nvariables [no_zero_smul_divisors R M]\n\n@[simp] lemma same_ray_smul_right_iff {v : M} {r : R} :\n  same_ray R v (r \u2022 v) \u2194 0 \u2264 r \u2228 v = 0 :=\n\u27e8\u03bb hrv, or_iff_not_imp_left.2 $ \u03bb hr, eq_zero_of_same_ray_neg_smul_right (not_le.1 hr) hrv,\n  or_imp_distrib.2 \u27e8same_ray_nonneg_smul_right v, \u03bb h, h.symm \u25b8 same_ray.zero_left _\u27e9\u27e9\n\n/-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple\nis positive. -/\nlemma same_ray_smul_right_iff_of_ne {v : M} (hv : v \u2260 0) {r : R} (hr : r \u2260 0) :\n  same_ray R v (r \u2022 v) \u2194 0 < r :=\nby simp only [same_ray_smul_right_iff, hv, or_false, hr.symm.le_iff_lt]\n\n@[simp] lemma same_ray_smul_left_iff {v : M} {r : R} : same_ray R (r \u2022 v) v \u2194 0 \u2264 r \u2228 v = 0 :=\nsame_ray_comm.trans same_ray_smul_right_iff\n\n/-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple\nis positive. -/\nlemma same_ray_smul_left_iff_of_ne {v : M} (hv : v \u2260 0) {r : R} (hr : r \u2260 0) :\n  same_ray R (r \u2022 v) v \u2194 0 < r :=\nsame_ray_comm.trans (same_ray_smul_right_iff_of_ne hv hr)\n\n@[simp] lemma same_ray_neg_smul_right_iff {v : M} {r : R} :\n  same_ray R (-v) (r \u2022 v) \u2194 r \u2264 0 \u2228 v = 0 :=\nby rw [\u2190 same_ray_neg_iff, neg_neg, \u2190 neg_smul, same_ray_smul_right_iff, neg_nonneg]\n\nlemma same_ray_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v \u2260 0) (hr : r \u2260 0) :\n  same_ray R (-v) (r \u2022 v) \u2194 r < 0 :=\nby simp only [same_ray_neg_smul_right_iff, hv, or_false, hr.le_iff_lt]\n\n@[simp] lemma same_ray_neg_smul_left_iff {v : M} {r : R} :\n  same_ray R (r \u2022 v) (-v) \u2194 r \u2264 0 \u2228 v = 0 :=\nsame_ray_comm.trans same_ray_neg_smul_right_iff\n\nlemma same_ray_neg_smul_left_iff_of_ne {v : M} {r : R} (hv : v \u2260 0) (hr : r \u2260 0) :\n  same_ray R (r \u2022 v) (-v) \u2194 r < 0 :=\nsame_ray_comm.trans $ same_ray_neg_smul_right_iff_of_ne hv hr\n\n@[simp] lemma units_smul_eq_self_iff {u : R\u02e3} {v : module.ray R M} :\n  u \u2022 v = v \u2194 (0 : R) < u :=\nbegin\n  induction v using module.ray.ind with v hv,\n  simp only [smul_ray_of_ne_zero, ray_eq_iff, units.smul_def,\n    same_ray_smul_left_iff_of_ne hv u.ne_zero]\nend\n\n@[simp] lemma units_smul_eq_neg_iff {u : R\u02e3} {v : module.ray R M} :\n  u \u2022 v = -v \u2194 \u2191u < (0 : R) :=\nby rw [\u2190 neg_inj, neg_neg, \u2190 module.ray.neg_units_smul, units_smul_eq_self_iff, units.coe_neg,\n  neg_pos]\n\nend\n\nend linear_ordered_comm_ring\n\nnamespace same_ray\n\nvariables {R : Type*} [linear_ordered_field R]\nvariables {M : Type*} [add_comm_group M] [module R M] {v\u2081 v\u2082 : M}\n\n/-- If a vector `v\u2082` is on the same ray as a nonzero vector `v\u2081`, then it is equal to `c \u2022 v\u2081` for\nsome nonnegative `c`. -/\nlemma exists_right_eq_smul (h : same_ray R v\u2081 v\u2082) (h\u2080 : v\u2081 \u2260 0) :\n  \u2203 c : R, 0 \u2264 c \u2227 v\u2082 = c \u2022 v\u2081 :=\nbegin\n  rcases h.resolve_left h\u2080 with (rfl|\u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, H\u27e9),\n  { exact \u27e80, le_rfl, (zero_smul _ _).symm\u27e9 },\n  { refine \u27e8r\u2081 / r\u2082, div_nonneg hr\u2081.le hr\u2082.le, _\u27e9,\n    rwa [div_eq_inv_mul, mul_smul, H, inv_smul_smul\u2080 hr\u2082.ne'] }\nend\n\n/-- If a vector `v\u2081` is on the same ray as a nonzero vector `v\u2082`, then it is equal to `c \u2022 v\u2082` for\nsome nonnegative `c`. -/\nlemma exists_left_eq_smul (h : same_ray R v\u2081 v\u2082) (h\u2080 : v\u2082 \u2260 0) :\n  \u2203 c : R, 0 \u2264 c \u2227 v\u2081 = c \u2022 v\u2082 :=\nh.symm.exists_right_eq_smul h\u2080\n\n/-- If vectors `v\u2081` and `v\u2082` are on the same ray, then for some nonnegative `a b`, `a + b = 1`, we\nhave `v\u2081 = a \u2022 (v\u2081 + v\u2082)` and `v\u2082 = b \u2022 (v\u2081 + v\u2082)`. -/\nlemma exists_eq_smul_add (h : same_ray R v\u2081 v\u2082) :\n  \u2203 a b : R, 0 \u2264 a \u2227 0 \u2264 b \u2227 a + b = 1 \u2227 v\u2081 = a \u2022 (v\u2081 + v\u2082) \u2227 v\u2082 = b \u2022 (v\u2081 + v\u2082) :=\nbegin\n  rcases h with rfl|rfl|\u27e8r\u2081, r\u2082, h\u2081, h\u2082, H\u27e9,\n  { use [0, 1], simp },\n  { use [1, 0], simp },\n  { have h\u2081\u2082 : 0 < r\u2081 + r\u2082, from add_pos h\u2081 h\u2082,\n    refine \u27e8r\u2082 / (r\u2081 + r\u2082), r\u2081 / (r\u2081 + r\u2082), div_nonneg h\u2082.le h\u2081\u2082.le, div_nonneg h\u2081.le h\u2081\u2082.le,\n      _, _, _\u27e9,\n    { rw [\u2190 add_div, add_comm, div_self h\u2081\u2082.ne'] },\n    { rw [div_eq_inv_mul, mul_smul, smul_add, \u2190 H, \u2190 add_smul, add_comm r\u2082,\n        inv_smul_smul\u2080 h\u2081\u2082.ne'] },\n    { rw [div_eq_inv_mul, mul_smul, smul_add, H, \u2190 add_smul, add_comm r\u2082,\n        inv_smul_smul\u2080 h\u2081\u2082.ne'] } }\nend\n\n/-- If vectors `v\u2081` and `v\u2082` are on the same ray, then they are nonnegative multiples of the same\nvector. Actually, this vector can be assumed to be `v\u2081 + v\u2082`, see `same_ray.exists_eq_smul_add`. -/\nlemma exists_eq_smul (h : same_ray R v\u2081 v\u2082) :\n  \u2203 (u : M) (a b : R), 0 \u2264 a \u2227 0 \u2264 b \u2227 a + b = 1 \u2227 v\u2081 = a \u2022 u \u2227 v\u2082 = b \u2022 u :=\n\u27e8v\u2081 + v\u2082, h.exists_eq_smul_add\u27e9\n\nend same_ray\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/linear_algebra/ray.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826789824086, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7182693522974222}}
{"text": "/-\nCopyright (c) 2015 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jeremy Avigad\n\nTwo sets are equinumerous, or equipollent, if there is a bijection between them. It is sometimes\nsaid that two such sets \"have the same cardinality.\"\n-/\nimport .classical_inverse data.nat\nopen eq.ops classical nat\n\n/- two versions of Cantor's theorem -/\n\nnamespace set\n\nvariables {X : Type} {A : set X}\n\ntheorem not_surj_on_pow (f : X \u2192 set X) : \u00ac surj_on f A (\ud835\udcab A) :=\nlet diag := {x \u2208 A | x \u2209 f x} in\nhave diag \u2286 A, from sep_subset _ _,\nassume H : surj_on f A (\ud835\udcab A),\nobtain x [(xA : x \u2208 A) (Hx : f x = diag)], from H `diag \u2286 A`,\nhave x \u2209 f x, from\n  suppose x \u2208 f x,\n  have x \u2208 diag, from Hx \u25b8 this,\n  have x \u2209 f x, from and.right this,\n  show false, from this `x \u2208 f x`,\nhave x \u2208 diag, from and.intro xA this,\nhave x \u2208 f x, from Hx\u207b\u00b9 \u25b8 this,\nshow false, from `x \u2209 f x` this\n\ntheorem not_inj_on_pow {f : set X \u2192 X} (H : maps_to f (\ud835\udcab A) A) : \u00ac inj_on f (\ud835\udcab A) :=\nlet diag := f ' {x \u2208 \ud835\udcab A | f x \u2209 x} in\nhave diag \u2286 A, from image_subset_of_maps_to_of_subset H (sep_subset _ _),\nassume H\u2081 : inj_on f (\ud835\udcab A),\nhave f diag \u2208 diag, from by_contradiction\n  (suppose f diag \u2209 diag,\n    have diag \u2208 {x \u2208 \ud835\udcab A | f x \u2209 x}, from and.intro `diag \u2286 A` this,\n    have f diag \u2208 diag, from mem_image_of_mem f this,\n    show false, from `f diag \u2209 diag` this),\nobtain x [(Hx : x \u2208 \ud835\udcab A \u2227 f x \u2209 x) (fxeq : f x = f diag)], from this,\nhave x = diag, from H\u2081 (and.left Hx) `diag \u2286 A` fxeq,\nhave f diag \u2209 diag, from this \u25b8 and.right Hx,\nshow false, from this `f diag \u2208 diag`\n\nend set\n\n/-\nThe Schr\u00f6der-Bernstein theorem. The proof below is nonconstructive, in three ways:\n(1) We need a left inverse to g (we could get around this by supplying one).\n(2) The definition of h below assumes that membership in Union U is decidable.\n(3) We ultimately case split on whether B is empty, and choose an element if it isn't.\n\nRather than mark every auxiliary construction as \"private\", we put them all in a\nseparate namespace.\n-/\n\nnamespace schroeder_bernstein\nsection\nopen set\n  parameters {X Y : Type}\n  parameter  {A : set X}\n  parameter  {B : set Y}\n  parameter  {f : X \u2192 Y}\n  parameter  (f_maps_to : maps_to f A B)\n  parameter  (finj : inj_on f A)\n  parameter  {g : Y \u2192 X}\n  parameter  (g_maps_to : maps_to g B A)\n  parameter  (ginj : inj_on g B)\n  parameter  {dflt : Y}                    -- for now, assume B is nonempty\n  parameter  (dfltB : dflt \u2208 B)\n\n  /- g\u207b\u00b9 : A \u2192 B -/\n\n  noncomputable definition ginv : X \u2192 Y := inv_fun g B dflt\n\n  lemma ginv_maps_to : maps_to ginv A B :=\n  maps_to_inv_fun dfltB\n\n  lemma ginv_g_eq {b : Y} (bB : b \u2208 B) : ginv (g b) = b :=\n  left_inv_on_inv_fun_of_inj_on dflt ginj bB\n\n  /- define a sequence of sets U -/\n\n  definition U : \u2115 \u2192 set X\n  | U 0       := A \\ (g ' B)\n  | U (n + 1) := g ' (f ' (U n))\n\n  lemma U_subset_A : \u2200 n, U n \u2286 A\n  | 0       := show U 0 \u2286 A,\n                 from diff_subset _ _\n  | (n + 1) := have f ' (U n) \u2286 B,\n                 from image_subset_of_maps_to_of_subset f_maps_to (U_subset_A n),\n               show U (n + 1) \u2286 A,\n                 from image_subset_of_maps_to_of_subset g_maps_to this\n\n  lemma g_ginv_eq {a : X} (aA : a \u2208 A) (anU  : a \u2209 Union U) : g (ginv a) = a :=\n  using ginj,\n  have a \u2208 g ' B, from by_contradiction\n    (suppose a \u2209 g ' B,\n      have a \u2208 U 0, from and.intro aA this,\n      have a \u2208 Union U, from exists.intro 0 this,\n      show false, from anU this),\n  obtain b [(bB : b \u2208 B) (gbeq : g b = a)], from this,\n  calc\n    g (ginv a) = g (ginv (g b)) : gbeq\n           ... = g b            : ginv_g_eq bB\n           ... = a              : gbeq\n\n  /- h : A \u2192 B -/\n\n  noncomputable definition h x := if x \u2208 Union U then f x else ginv x\n\n  lemma h_maps_to : maps_to h A B :=\n  using f_maps_to dfltB,\n  take a,\n  suppose a \u2208 A,\n  show h a \u2208 B, from\n    by_cases\n      (suppose a \u2208 Union U,\n        begin rewrite [\u2191h, if_pos this], exact f_maps_to `a \u2208 A` end)\n      (suppose a \u2209 Union U,\n        begin rewrite [\u2191h, if_neg this], exact ginv_maps_to `a \u2208 A` end)\n\n  /- h is injective -/\n\n  lemma aux {a\u2081 a\u2082 : X} (H\u2081 : a\u2081 \u2208 Union U) (a\u2082A : a\u2082 \u2208 A) (heq : h a\u2081 = h a\u2082) : a\u2082 \u2208 Union U :=\n  using ginj,\n  obtain n (a\u2081Un : a\u2081 \u2208 U n), from H\u2081,\n  have ha\u2081eq : h a\u2081 = f a\u2081,\n    from dif_pos H\u2081,\n  show a\u2082 \u2208 Union U, from by_contradiction\n    (suppose a\u2082 \u2209 Union U,\n      have ha\u2082eq : h a\u2082 = ginv a\u2082,\n        from dif_neg this,\n      have g (f a\u2081) = a\u2082, from calc\n        g (f a\u2081) = g (h a\u2081)       : ha\u2081eq\n             ... = g (h a\u2082)       : heq\n             ... = g (ginv a\u2082)    : ha\u2082eq\n             ... = a\u2082             : g_ginv_eq a\u2082A `a\u2082 \u2209 Union U`,\n      have g (f a\u2081) \u2208 g ' (f ' (U n)),\n        from mem_image_of_mem g (mem_image_of_mem f a\u2081Un),\n      have a\u2082 \u2208 U (n + 1),\n        from `g (f a\u2081) = a\u2082` \u25b8 this,\n      have a\u2082 \u2208 Union U,\n        from exists.intro _ this,\n      show false, from `a\u2082 \u2209 Union U` `a\u2082 \u2208 Union U`)\n\n  lemma h_inj : inj_on h A :=\n  take a\u2081 a\u2082,\n  suppose a\u2081 \u2208 A,\n  suppose a\u2082 \u2208 A,\n  assume heq : h a\u2081 = h a\u2082,\n  show a\u2081 = a\u2082, from\n  by_cases\n    (assume a\u2081UU : a\u2081 \u2208 Union U,\n      have a\u2082UU : a\u2082 \u2208 Union U,\n        from aux a\u2081UU `a\u2082 \u2208 A` heq,\n      have f a\u2081 = f a\u2082, from calc\n        f a\u2081 = h a\u2081 : dif_pos a\u2081UU\n          ... = h a\u2082 : heq\n          ... = f a\u2082 : dif_pos a\u2082UU,\n      show a\u2081 = a\u2082, from\n        finj `a\u2081 \u2208 A` `a\u2082 \u2208 A` this)\n    (assume a\u2081nUU : a\u2081 \u2209 Union U,\n      have a\u2082nUU : a\u2082 \u2209 Union U,\n        from assume H, a\u2081nUU (aux H `a\u2081 \u2208 A` heq\u207b\u00b9),\n      have eq\u2081 : g (ginv a\u2081) = a\u2081, from g_ginv_eq `a\u2081 \u2208 A` a\u2081nUU,\n      have eq\u2082 : g (ginv a\u2082) = a\u2082, from g_ginv_eq `a\u2082 \u2208 A` a\u2082nUU,\n      have ginv a\u2081 = ginv a\u2082, from calc\n        ginv a\u2081 = h a\u2081 : dif_neg a\u2081nUU\n            ... = h a\u2082 : heq\n            ... = ginv a\u2082 : dif_neg a\u2082nUU,\n      show a\u2081 = a\u2082, from calc\n        a\u2081    = g (ginv a\u2081) : eq\u2081 -- g_ginv_eq `a\u2081 \u2208 A` a\u2081nUU\n          ... = g (ginv a\u2082) : this\n          ... = a\u2082          : eq\u2082) -- g_ginv_eq `a\u2082 \u2208 A` a\u2082nUU)\n\n  /- h is surjective -/\n\n  lemma h_surj : surj_on h A B :=\n  take b,\n  suppose b \u2208 B,\n  using f_maps_to,\n  by_cases\n    (suppose g b \u2208 Union U,\n       obtain n (gbUn : g b \u2208 U n), from this,\n      begin\n        cases n with n,\n          {have g b \u2208 U 0, from gbUn,\n            have g b \u2209 g ' B, from and.right this,\n            have g b \u2208 g ' B, from mem_image_of_mem g `b \u2208 B`,\n            show b \u2208 h ' A,   from absurd `g b \u2208 g ' B` `g b \u2209 g ' B`},\n        {have g b \u2208 U (succ n), from gbUn,\n           have g b \u2208 g ' (f ' (U n)), from this,\n           obtain b' [(b'fUn : b' \u2208 f ' (U n)) (geq : g b' = g b)], from this,\n           obtain a [(aUn : a \u2208 U n) (faeq : f a = b')], from b'fUn,\n           have g (f a) = g b, by rewrite [faeq, geq],\n           have a \u2208 A, from U_subset_A n aUn,\n           have f a \u2208 B, from f_maps_to this,\n           have f a = b, from ginj `f a \u2208 B` `b \u2208 B` `g (f a) = g b`,\n           have a \u2208 Union U, from exists.intro n aUn,\n           have h a = f a, from dif_pos this,\n           show b \u2208 h ' A, from mem_image `a \u2208 A` (`h a = f a` \u2b1d `f a = b`)}\n      end)\n    (suppose g b \u2209 Union U,\n      have eq\u2081 : h (g b) = ginv (g b), from dif_neg this,\n      have eq\u2082 : ginv (g b) = b, from ginv_g_eq `b \u2208 B`,\n      have g b \u2208 A, from g_maps_to `b \u2208 B`,\n      show b \u2208 h ' A, from mem_image `g b \u2208 A` (eq\u2081 \u2b1d eq\u2082))\nend\nend schroeder_bernstein\n\nnamespace set\nsection\n  parameters {X Y : Type}\n  parameter  {A : set X}\n  parameter  {B : set Y}\n  parameter  {f : X \u2192 Y}\n  parameter  (f_maps_to : maps_to f A B)\n  parameter  (finj : inj_on f A)\n  parameter  {g : Y \u2192 X}\n  parameter  (g_maps_to : maps_to g B A)\n  parameter  (ginj : inj_on g B)\n\n  include g g_maps_to ginj\n  theorem schroeder_bernstein : \u2203 h, bij_on h A B :=\n  by_cases\n    (assume H : \u2200 b, b \u2209 B,\n      have fsurj : surj_on f A B, from take b, suppose b \u2208 B, absurd this !H,\n      exists.intro f (and.intro f_maps_to (and.intro finj fsurj)))\n    (assume H : \u00ac \u2200 b, b \u2209 B,\n      have \u2203 b, b \u2208 B, from exists_of_not_forall_not H,\n      obtain b bB, from this,\n      let h := @schroeder_bernstein.h X Y A B f g b in\n      have h_maps_to : maps_to h A B, from schroeder_bernstein.h_maps_to f_maps_to bB,\n      have hinj : inj_on h A, from schroeder_bernstein.h_inj finj ginj, -- ginj,\n      have hsurj : surj_on h A B, from schroeder_bernstein.h_surj f_maps_to g_maps_to ginj,\n      exists.intro h (and.intro h_maps_to (and.intro hinj hsurj)))\nend\nend set\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/set/equinumerosity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7182693466816098}}
{"text": "import algebra.group_power data.complex.basic group_theory.coset\n\nuniverses u v w x\nvariables {G : Type u} {G\u2082 : Type v} {G\u2083 : Type w} {G\u2084 : Type x}\nvariables [group G] [comm_group G\u2082] [add_group G\u2083] [add_comm_group G\u2084]\n\n-- sheet 4\n\n-- 4. Let S be the two-element set {a, b}. Show that there are precisely 16 distinct binary operations on S. How many of them make S a group? Find a formula for the total number of binary operations on a set of n elements.\n--def S' := {}\n--theorem sheet04_q4:\n\n-- 5. Prove that multiplication of \u2102 numbers is associative.\n\ntheorem sheet04_q05 (z z\u2081 z\u2082 : \u2102) : z * z\u2081 * z\u2082 = z * (z\u2081 * z\u2082) := by apply mul_assoc z z\u2081 z\u2082\n\n\n-- 6. Which of the following are groups? Prove one, delete another.\n--(a)\n--theorem sheet04_q6a_is_T:\n--theorem sheet04_q6a_is_F:\n\n-- Let S be the set of all real numbers except \u22121. For a, b \u2208 S define a \u2217 b = ab + a + b. Show that (S, \u2217) is a group. \ndef s := {x : \u211d | x \u2260 -1}\n\ndef op (m n : s) [has_add s] [has_mul s] : s := \u27e8m * n + m + n, sorry\u27e9 -- want to prove that this operation is from s to s to s rather than s to s to \u211d \n\nlocal notation m ~ n := op m n \n\n--def Is_group {G:Type} (g:set G) (op: g \u2192 g \u2192 g): Prop := (\u2200 (x y z \u2208 g), op (op x y) z = op x (op y z)) \u2227 \n--(\u2203 i \u2208 g , (\u2200x \u2208 g,op x i = x \u2227 op i x = x) \u2227 (\u2200 x \u2208 g, \u2203 xin:G, op x xin =i \u2227 op xin x =i))\n\n--theorem q7: Is_group s ~ := sorry \n\n--theorem q7 (a b : set s) \n\n-- 8. Let G be a group, and let a, b, c \u2208 G. Prove the following facts.\n--(a) If ab=ac then b=c.\ntheorem sheet04_q8a (a b c : G) : a * b = a * c \u2194 b = c := by apply mul_left_inj a\n\n--(b) The equation axb = c has a unique solution for x \u2208 G.\ntheorem sheet04_q8b (a b c : G) : \u2203! x : G, a * x * b = c := \nbegin\nintros,\nexistsi (a\u207b\u00b9 * c * b\u207b\u00b9),\nsimp [mul_assoc],\nassume y h,\nrw \u2190 h,\nsimp [mul_assoc],\nend\n--(c) (a^{\u22121})^{\u22121} = a.\ntheorem sheet04_q8c (a : G) : a\u207b\u00b9\u207b\u00b9 = a := by apply inv_inv a\n--(d) (ab)^{\u22121} = b^{-1}a^{\u22121}.\ntheorem sheet04_q8d (a b : G) : (a*b)\u207b\u00b9 = b\u207b\u00b9*a\u207b\u00b9 := by apply mul_inv_rev a b\n-- 9. Let G be a group, and let e be the identity of G. Suppose that x\u2217x=e for all x\u2208G. Show that y \u2217 z = z \u2217 y for all y, z \u2208 G.\ntheorem sheet04_q9 (y z : G) (hp : \u2200x : G, x*x = 1) : y * z = z * y := sorry\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1P2/sheet_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7182349217680957}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function World\n\n## Level 1: the `exact` tactic.\n\nGiven an element of `P` and a function from `P` to `Q`,\nwe define an element of `Q`.\n-/\nexample (P Q : Type) (p : P) (h : P \u2192 Q) : Q := by\n  exact h p\n\n/-!\nNote that `example` is just like a `theorem` or a `lemma`\nexcept it has no name.\n\nIf you place your cursor at the end of the `example` line above\nthe tactic state will look like this:\n\n```\nP Q : Type,\np : P,\nh : P \u2192 Q\n\u22a2 Q\n```\n\nIn this situation, we have sets `P` and `Q` (but Lean calls them types),\nand an element `p` of `P` (written `p : P`\nbut meaning `p \u2208 P`). We also have a function `h` from `P` to `Q`,\nand our goal is to construct an\nelement of the set `Q`. It's clear what to do *mathematically* to solve\nthis goal -- we can\nmake an element of `Q` by applying the function `h` to\nthe element `p`. But how to do it in Lean? There are at least two ways\nto explain this idea to Lean,\nand here we will learn about one of them, namely the method which\nuses the `exact` tactic.\n\n## The `exact` tactic.\n\nIf you can explicitly see how to make an element of your goal set,\ni.e. you have a formula for it, then you can just write `exact <formula>`\nand this will close the goal.\n\nSo given that the function application `h p` is an element of `Q` so you can just write\n`exact h p` to close the goal.\n\n## Important note\n\nNote that `exact h P` won't work (with a capital `P`);\nthis is a common error for beginners.\n`P` is not an element of `P`, it's `p` that is an element of `P`.\n\n## Summary\n\nIf the goal is `\u22a2 X` then `exact x` will close the goal if\nand only if `x` is a term of type `X`.\n\n## Details\n\nSay `P`, `Q` and `R` are types (i.e., what a mathematician\nmight think of as either sets or propositions),\nand the local context looks like this:\n\n```\np : P,\nh : P \u2192 Q,\nj : Q \u2192 R\n\u22a2 R\n```\n\nIf you can spot how to make a term of type `R`, then you\ncan just make it and say you're done using the `exact` tactic\ntogether with the formula you have spotted. For example the\nabove goal could be solved with\n\n`exact j (h p)`\n\nbecause `j (h p)` is easily checked to be a term of type `R`\n(i.e., an element of the set `R`, or a proof of the proposition `R`).\n\n\nNext up [Level 2](./Level2.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/FunctionWorld/Level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.7182349180386038}}
{"text": "/-\nCopyright (c) 2021 Henry Swanson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henry Swanson\n-/\nimport combinatorics.derangements.basic\nimport data.fintype.card\nimport tactic.delta_instance\nimport tactic.ring\n\n/-!\n# Derangements on fintypes\n\nThis file contains lemmas that describe the cardinality of `derangements \u03b1` when `\u03b1` is a fintype.\n\n# Main definitions\n\n* `card_derangements_invariant`: A lemma stating that the number of derangements on a type `\u03b1`\n    depends only on the cardinality of `\u03b1`.\n* `num_derangements n`: The number of derangements on an n-element set, defined in a computation-\n    friendly way.\n* `card_derangements_eq_num_derangements`: Proof that `num_derangements` really does compute the\n    number of derangements.\n* `num_derangements_sum`: A lemma giving an expression for `num_derangements n` in terms of\n    factorials.\n-/\n\nopen derangements equiv fintype\nopen_locale big_operators\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] [fintype \u03b1]\n\ninstance : decidable_pred (derangements \u03b1) := \u03bb _, fintype.decidable_forall_fintype\n\ninstance : fintype (derangements \u03b1) := by delta_instance derangements\n\nlemma card_derangements_invariant {\u03b1 \u03b2 : Type*} [fintype \u03b1] [decidable_eq \u03b1]\n  [fintype \u03b2] [decidable_eq \u03b2] (h : card \u03b1 = card \u03b2) :\n  card (derangements \u03b1) = card (derangements \u03b2) :=\nfintype.card_congr (equiv.derangements_congr $ equiv_of_card_eq h)\n\nlemma card_derangements_fin_add_two (n : \u2115) :\n  card (derangements (fin (n+2))) = (n+1) * card (derangements (fin n)) +\n  (n+1) * card (derangements (fin (n+1))) :=\nbegin\n  -- get some basic results about the size of fin (n+1) plus or minus an element\n  have h1 : \u2200 a : fin (n+1), card ({a}\u1d9c : set (fin (n+1))) = card (fin n),\n  { intro a,\n    simp only [fintype.card_fin, finset.card_fin, fintype.card_of_finset, finset.filter_ne' _ a,\n      set.mem_compl_singleton_iff, finset.card_erase_of_mem (finset.mem_univ a), nat.pred_succ] },\n  have h2 : card (fin (n+2)) = card (option (fin (n+1))),\n  { simp only [card_fin, card_option] },\n  -- rewrite the LHS and substitute in our fintype-level equivalence\n  simp only [card_derangements_invariant h2,\n    card_congr (@derangements_recursion_equiv (fin (n+1)) _),\n  -- push the cardinality through the \u03a3 and \u2295 so that we can use `card_n`\n    card_sigma, card_sum, card_derangements_invariant (h1 _), finset.sum_const, nsmul_eq_mul,\n    finset.card_fin, mul_add, nat.cast_id],\nend\n\n/-- The number of derangements of an `n`-element set. -/\ndef num_derangements : \u2115 \u2192 \u2115\n| 0 := 1\n| 1 := 0\n| (n + 2) := (n + 1) * (num_derangements n + num_derangements (n+1))\n\n@[simp] lemma num_derangements_zero : num_derangements 0 = 1 := rfl\n\n@[simp] lemma num_derangements_one : num_derangements 1 = 0 := rfl\n\nlemma num_derangements_add_two (n : \u2115) :\n  num_derangements (n+2) = (n+1) * (num_derangements n + num_derangements (n+1)) := rfl\n\nlemma num_derangements_succ (n : \u2115) :\n  (num_derangements (n+1) : \u2124) = (n + 1) * (num_derangements n : \u2124) - (-1)^n :=\nbegin\n  induction n with n hn,\n  { refl },\n  { simp only [num_derangements_add_two, hn, pow_succ,\n      int.coe_nat_mul, int.coe_nat_add, int.coe_nat_succ],\n    ring }\nend\n\nlemma card_derangements_fin_eq_num_derangements {n : \u2115} :\n  card (derangements (fin n)) = num_derangements n :=\nbegin\n  induction n using nat.strong_induction_on with n hyp,\n  obtain (_|_|n) := n, { refl }, { refl },  -- knock out cases 0 and 1\n  -- now we have n \u2265 2. rewrite everything in terms of card_derangements, so that we can use\n  -- `card_derangements_fin_add_two`\n  rw [num_derangements_add_two, card_derangements_fin_add_two, mul_add,\n    hyp _ (nat.lt_add_of_pos_right zero_lt_two), hyp _ (lt_add_one _)],\nend\n\nlemma card_derangements_eq_num_derangements (\u03b1 : Type*) [fintype \u03b1] [decidable_eq \u03b1] :\n  card (derangements \u03b1) = num_derangements (card \u03b1) :=\nbegin\n  rw \u2190card_derangements_invariant (card_fin _),\n  exact card_derangements_fin_eq_num_derangements,\nend\n\ntheorem num_derangements_sum (n : \u2115) :\n  (num_derangements n : \u2124) = \u2211 k in finset.range (n + 1), (-1:\u2124)^k * nat.asc_factorial k (n - k) :=\nbegin\n  induction n with n hn, { refl },\n  rw [finset.sum_range_succ, num_derangements_succ, hn, finset.mul_sum, tsub_self,\n    nat.asc_factorial_zero, int.coe_nat_one, mul_one, pow_succ, neg_one_mul, sub_eq_add_neg,\n    add_left_inj, finset.sum_congr rfl],\n  -- show that (n + 1) * (-1)^x * asc_fac x (n - x) = (-1)^x * asc_fac x (n.succ - x)\n  intros x hx,\n  have h_le : x \u2264 n := finset.mem_range_succ_iff.mp hx,\n  rw [nat.succ_sub h_le, nat.asc_factorial_succ, add_tsub_cancel_of_le h_le,\n    int.coe_nat_mul, int.coe_nat_succ, mul_left_comm],\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/combinatorics/derangements/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7182349115132108}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.nat.basic\nimport data.nat.prime\n\nopen nat\n\n/-!\n# IMO 2003 Q6\nLet p be a prime number. Prove that there exists a prime number q such that for every natural n,\nthe number n^p - p is not divisible by q.\n\n# Solution\nTODO\n-/\n\ntheorem imo2003_q6 (p : \u2115) (hp : prime p) : \u2203 q : \u2115, prime q \u2227 \u2200 n : \u2115, \u00ac (q \u2223 n^p - p) :=\nbegin\n  sorry,\nend\n", "meta": {"author": "manuelcandales", "repo": "imo-lean", "sha": "fa54938100fc84c98fe04e1d19e20a424dd006e7", "save_path": "github-repos/lean/manuelcandales-imo-lean", "path": "github-repos/lean/manuelcandales-imo-lean/imo-lean-fa54938100fc84c98fe04e1d19e20a424dd006e7/src/imo2003_q6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7181786730275431}}
{"text": "import Lean\n\nopen Lean\nopen Lean.Meta\nopen Lean.Elab.Tactic\n\nuniverse u\naxiom elimEx (motive : Nat \u2192 Nat \u2192 Sort u) (x y : Nat)\n  (diag  : (a : Nat) \u2192 motive a a)\n  (upper : (delta a : Nat) \u2192 motive a (a + delta.succ))\n  (lower : (delta a : Nat) \u2192 motive (a + delta.succ) a)\n  : motive y x\n\ntheorem ex1 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => apply Or.inl; apply Nat.le_refl\n  | lower d => apply Or.inl; show p \u2264 p + d.succ; admit\n  | upper d => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex2 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx\n  case lower => admit\n  case upper => admit\n  case diag  => apply Or.inl; apply Nat.le_refl\n\naxiom Nat.parityElim (motive : Nat \u2192 Sort u)\n  (even : (n : Nat) \u2192 motive (2*n))\n  (odd  : (n : Nat) \u2192 motive (2*n+1))\n  (n : Nat)\n  : motive n\n\ntheorem time2Eq (n : Nat) : 2*n = n + n := by\n  rw [Nat.mul_comm]\n  show (0 + n) + n = n+n\n  simp\n\ntheorem ex3 (n : Nat) : Exists (fun m => n = m + m \u2228 n = m + m + 1) := by\n  cases n using Nat.parityElim with\n  | even i =>\n    apply Exists.intro i\n    apply Or.inl\n    rw [time2Eq]\n  | odd i =>\n    apply Exists.intro i\n    apply Or.inr\n    rw [time2Eq]\n\nopen Nat in\ntheorem ex3b (n : Nat) : Exists (fun m => n = m + m \u2228 n = m + m + 1) := by\n  cases n using parityElim with\n  | even i =>\n    apply Exists.intro i\n    apply Or.inl\n    rw [time2Eq]\n  | odd i =>\n    apply Exists.intro i\n    apply Or.inr\n    rw [time2Eq]\n\ndef ex4 {\u03b1} (xs : List \u03b1) (h : xs = [] \u2192 False) : \u03b1 := by\n  cases he:xs with\n  | nil      => contradiction\n  | cons x _ => exact x\n\ndef ex5 {\u03b1} (xs : List \u03b1) (h : xs = [] \u2192 False) : \u03b1 := by\n  cases he:xs using List.casesOn with\n  | nil      => contradiction\n  | cons x _ => exact x\n\ntheorem ex6 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false :=\n  match he:f xs with\n  | true  => False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex7 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false := by\n  cases he:f xs with\n  | true  => exact False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex8 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false := by\n  cases he:f xs using Bool.casesOn with\n  | true  => exact False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex9 (xs : List \u03b1) (h : xs = [] \u2192 False) : Nonempty \u03b1 := by\n  cases xs using List.rec with\n  | nil      => contradiction\n  | cons x _ => apply Nonempty.intro; assumption\n\ntheorem modLt (x : Nat) {y : Nat} (h : y > 0) : x % y < y := by\n  induction x, y using Nat.mod.inductionOn with\n  | ind x y h\u2081 ih =>\n    rw [Nat.mod_eq_sub_mod h\u2081.2]\n    exact ih h\n  | base x y h\u2081 =>\n    match Iff.mp (Decidable.not_and_iff_or_not ..) h\u2081 with\n    | Or.inl h\u2081 => contradiction\n    | Or.inr h\u2081 =>\n      have hgt := Nat.gt_of_not_le h\u2081\n      have heq := Nat.mod_eq_of_lt hgt\n      rw [\u2190 heq] at hgt\n      assumption\n\ntheorem ex11 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\n  induction h using Or.casesOn with\n  | inr h  => ?myright\n  | inl h  => ?myleft\n  case myleft  => exact Or.inr h\n  case myright => exact Or.inl h\n\ntheorem ex12 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\n  cases h using Or.casesOn with\n  | inr h  => ?myright\n  | inl h  => ?myleft\n  case myleft  => exact Or.inr h\n  case myright => exact Or.inl h\n\ntheorem ex13 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => ?hlower\n  | upper d => ?hupper\n  case hdiag  => apply Or.inl; apply Nat.le_refl\n  case hlower => apply Or.inl; show p \u2264 p + d.succ; admit\n  case hupper => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex14 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => _\n  | upper d => ?hupper\n  case hdiag  => apply Or.inl; apply Nat.le_refl\n  case lower => apply Or.inl; show p \u2264 p + d.succ; admit\n  case hupper => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex15 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => _\n  | upper d => ?hupper\n  { apply Or.inl; apply Nat.le_refl }\n  { apply Or.inl; show p \u2264 p + d.succ; admit }\n  { apply Or.inr; show q + d.succ > q; admit }\n\ntheorem ex16 {p q : Prop} (h : p \u2228 q) : q \u2228 p := by\n  induction h\n  case inl h' => exact Or.inr h'\n  case inr h' => exact Or.inl h'\n\ntheorem ex17 (n : Nat) : 0 + n = n := by\n  induction n\n  case zero => rfl\n  case succ m ih =>\n    show Nat.succ (0 + m) = Nat.succ m\n    rw [ih]\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/casesUsing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7181768430856925}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\n If J is a finite set then the sum of (-1)^{|K|} over subsets K \u2286 J\n is usually zero, except that the sum is one if J is empty.\n\n We will prove two versions of this, one where J is a finset in an \n arbitrary type I, and one where J is the universal set in a fintype I.\n\n A key point is as follows: if we take J' = (insert a J) = J \u222a {a},\n then the subsets of J can be split into those that contain a and those\n that do not, and these two families are in bijection.  Equivalently, \n we have a bijection P(J') \u2243 P(J) \u00d7 bool (where bool is a set with \n two elements).  We construct this bijection as \n `finset.insert.powerset_filter`.\n-/\n\nimport data.fintype.basic algebra.big_operators\nimport algebra.prod_equiv\n\nnamespace finset\nopen finset\n\nuniverse u\n\nvariables {I : Type u} [decidable_eq I]\n\ndef card_sign (K : finset I) : \u2124 := (-1) ^ K.card\ndef card_sign_sum (J : finset I) := J.powerset.sum (card_sign : finset I \u2192 \u2124)\n\nsection insert \n\nvariables {i : I} {J : finset I} (hiJ : i \u2209 J)\ninclude hiJ\n\nexample (n : \u2124) : n * (-1) = - n := by library_search\n\nlemma insert.card_sign :\n card_sign (insert i J) = - card_sign J := \n by {dsimp[card_sign],\n     rw[card_insert_of_not_mem hiJ,pow_add,pow_one,mul_neg_one] }\n\nlemma subset_iff_subset_insert (K : finset I) :\n K \u2286 J \u2194 K \u2286 (insert i J) \u2227 i \u2209 K := \nbegin\n split,\n {exact \u03bb hKJ,\u27e8subset.trans hKJ (subset_insert i J),\u03bb i_in_K,hiJ (hKJ i_in_K)\u27e9},\n {rintros \u27e8hKiJ,hi\u27e9 a ha,\n  rcases mem_insert.mp (hKiJ ha) with a_eq_i | a_in_J,\n  {exact (hi (a_eq_i \u25b8 ha)).elim},{exact a_in_J}\n }\nend\n\nlemma insert.powerset_filter : \n (insert i J).powerset.filter (\u03bb K, i \u2209 K) = J.powerset := by {\n  ext K,rw[mem_filter,mem_powerset,mem_powerset,subset_iff_subset_insert hiJ],\n } \n\ndef insert.powerset_equiv : \n { K // K \u2208 (insert i J).powerset} \u2243 ({K // K \u2208 J.powerset} \u00d7 bool) := {\n to_fun := \u03bb K, \u27e8\u27e8K.val \u2229 J,mem_powerset.mpr (inter_subset_right K.val J)\u27e9,\n                 if i \u2208 K.val then tt else ff\u27e9,\n inv_fun := \u03bb Kb, cond Kb.2\n  \u27e8insert i Kb.1.val,\n   mem_powerset.mpr (insert_subset_insert i (mem_powerset.mp Kb.1.property))\u27e9 \n  \u27e8Kb.1.val,\n   mem_powerset.mpr (subset.trans (mem_powerset.mp Kb.1.property) (subset_insert i J))\u27e9,\n left_inv := \u03bb \u27e8K,hK\u27e9,\n begin\n  let hK' := mem_powerset.mp hK,\n  apply subtype.eq,ext a,simp only [],split_ifs,\n  {rw[cond,mem_insert,mem_inter],\n   split,\n   {rintro (a_eq_i | h2),exact a_eq_i.symm.subst h,exact h2.left},\n   {intro a_in_K,\n    rcases mem_insert.mp (hK' a_in_K) with a_eq_i | a_in_J,\n    {exact or.inl a_eq_i},\n    {exact or.inr \u27e8a_in_K,a_in_J\u27e9}\n   }\n  },{\n   rw[cond,mem_inter],\n   split,\n   {exact \u03bb h,h.1},\n   {intro a_in_K,\n    exact \u27e8a_in_K,((subset_iff_subset_insert hiJ K).mpr \u27e8hK',h\u27e9) a_in_K\u27e9,\n   }\n  }\n end,\n right_inv := \u03bb \u27e8\u27e8K,hK\u27e9,b\u27e9,\n begin\n  let hK' := mem_powerset.mp hK,\n  have hiK : i \u2209 K := \u03bb h, hiJ (hK' h),\n  cases b; simp only[cond],\n  {rw[if_neg hiK],congr,ext a,rw[mem_inter],\n   exact \u27e8\u03bb h,h.1,\u03bb h,\u27e8h,hK' h\u27e9\u27e9,\n  },{\n   rw[if_pos (mem_insert_self i K)],congr,ext a,rw[mem_inter,mem_insert],\n   split,\n   {rintro \u27e8a_eq_i | a_in_K,a_in_J\u27e9,\n    {exact (hiJ (a_eq_i \u25b8 a_in_J)).elim,},\n    {exact a_in_K}\n   },{\n    intro a_in_K,\n    exact \u27e8or.inr a_in_K,hK' a_in_K\u27e9\n   }\n  }\n end\n}\n\nlemma card_sign_sum_insert : card_sign_sum (insert i J) = 0 := \nbegin \n let e := (insert.powerset_equiv hiJ).symm,\n rw[card_sign_sum,sum_eq_univ_sum],\n rw[\u2190 univ_sum_equiv e (\u03bb K,card_sign K.val)],\n let g : {K // K \u2208 J.powerset} \u2192 bool \u2192 \u2124 := \n  \u03bb K b, cond b (- (card_sign K.val)) (card_sign K.val),\n have eg : \u2200 K, (@univ bool _).sum (g K) = 0 := \n  \u03bb K, by {rw[sum_over_bool],dsimp[g],rw[add_neg_self]},\n have : (\u03bb (K : {K // K \u2208 powerset (insert i J)}), (card_sign K.val)) \u2218 e.to_fun = \n        \u03bb Kb, g Kb.1 Kb.2 := \n  by {ext Kb,rcases Kb with \u27e8\u27e8K,hK\u27e9,ff | tt\u27e9,\n   {refl},\n   {have : i \u2209 K := \u03bb h, hiJ ((mem_powerset.mp hK) h),\n    exact insert.card_sign this}\n  },\n rw[this,sum_univ_product,sum_congr rfl (\u03bb K _,eg K),sum_const_zero],\nend\n\nend insert\n\n#check finset.nonempty\nlemma card_sign_sum_eq (J : finset I) : card_sign_sum J = if J = \u2205 then 1 else 0 := \nbegin\n split_ifs with h,\n {rw[h],refl},\n { rcases (nonempty_of_ne_empty h) with \u27e8a,a_in_J\u27e9,\n  rw[\u2190 insert_erase a_in_J,card_sign_sum_insert (not_mem_erase a J)],\n }\nend\n\nend finset\n\nnamespace fintype\nopen finset\n\nlemma card_sign_sum_eq (I : Type*) [decidable_eq I] [fintype I] : \n (@univ I _).powerset.sum card_sign = if (card I = 0) then 1 else 0 := \nbegin \n change (@univ I _).card_sign_sum  = if (card I = 0) then 1 else 0,\n let h := @finset.card_eq_zero I univ,\n rw[finset.card_sign_sum_eq,\u2190 card_univ],\n by_cases hu : (@univ I _).card = 0,\n rw[if_pos hu,if_pos (h.mp hu)],\n rw[if_neg hu,if_neg (hu \u2218 h.mpr)],\nend\n\nend fintype\n\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/combinatorics/card_sign.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7181768284731623}}
{"text": "/-\nCopyright (c) 2022 Jake Levinson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jake Levinson\n-/\nimport order.upper_lower.basic\nimport data.finset.preimage\n\n/-!\n# Young diagrams\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA Young diagram is a finite set of up-left justified boxes:\n\n```text\n\u25a1\u25a1\u25a1\u25a1\u25a1\n\u25a1\u25a1\u25a1\n\u25a1\u25a1\u25a1\n\u25a1\n```\nThis Young diagram corresponds to the [5, 3, 3, 1] partition of 12.\n\nWe represent it as a lower set in `\u2115 \u00d7 \u2115` in the product partial order. We write `(i, j) \u2208 \u03bc`\nto say that `(i, j)` (in matrix coordinates) is in the Young diagram `\u03bc`.\n\n## Main definitions\n\n- `young_diagram` : Young diagrams\n- `young_diagram.card` : the number of cells in a Young diagram (its *cardinality*)\n- `young_diagram.distrib_lattice` : a distributive lattice instance for Young diagrams\n  ordered by containment, with `(\u22a5 : young_diagram)` the empty diagram.\n- `young_diagram.row` and `young_diagram.row_len`: rows of a Young diagram and their lengths\n- `young_diagram.col` and `young_diagram.col_len`: columns of a Young diagram and their lengths\n\n## Notation\n\nIn \"English notation\", a Young diagram is drawn so that (i1, j1) \u2264 (i2, j2)\nmeans (i1, j1) is weakly up-and-left of (i2, j2). This terminology is used\nbelow, e.g. in `young_diagram.up_left_mem`.\n\n## Tags\n\nYoung diagram\n\n## References\n\n<https://en.wikipedia.org/wiki/Young_tableau>\n\n-/\n\nopen function\n\n/-- A Young diagram is a finite collection of cells on the `\u2115 \u00d7 \u2115` grid such that whenever\na cell is present, so are all the ones above and to the left of it. Like matrices, an `(i, j)` cell\nis a cell in row `i` and column `j`, where rows are enumerated downward and columns rightward.\n\nYoung diagrams are modeled as finite sets in `\u2115 \u00d7 \u2115` that are lower sets with respect to the\nstandard order on products. -/\n@[ext] structure young_diagram :=\n(cells : finset (\u2115 \u00d7 \u2115))\n(is_lower_set : is_lower_set (cells : set (\u2115 \u00d7 \u2115)))\n\nnamespace young_diagram\n\ninstance : set_like young_diagram (\u2115 \u00d7 \u2115) :=\n{ coe            := coe young_diagram.cells,\n  coe_injective' := \u03bb \u03bc \u03bd h, by { rwa [young_diagram.ext_iff, \u2190 finset.coe_inj] } }\n\n@[simp] lemma mem_cells {\u03bc : young_diagram} (c : \u2115 \u00d7 \u2115) :\n  c \u2208 \u03bc.cells \u2194 c \u2208 \u03bc := iff.rfl\n\n@[simp] lemma mem_mk (c : \u2115 \u00d7 \u2115) (cells) (is_lower_set) :\n  c \u2208 young_diagram.mk cells is_lower_set \u2194 c \u2208 cells := iff.rfl\n\ninstance decidable_mem (\u03bc : young_diagram) : decidable_pred (\u2208 \u03bc) :=\nshow decidable_pred (\u2208 \u03bc.cells), by apply_instance\n\n/-- In \"English notation\", a Young diagram is drawn so that (i1, j1) \u2264 (i2, j2)\n    means (i1, j1) is weakly up-and-left of (i2, j2). -/\nlemma up_left_mem (\u03bc : young_diagram) {i1 i2 j1 j2 : \u2115}\n  (hi : i1 \u2264 i2) (hj : j1 \u2264 j2) (hcell : (i2, j2) \u2208 \u03bc) : (i1, j1) \u2208 \u03bc :=\n\u03bc.is_lower_set (prod.mk_le_mk.mpr \u27e8hi, hj\u27e9) hcell\n\nsection distrib_lattice\n\n@[simp] lemma cells_subset_iff {\u03bc \u03bd : young_diagram} : \u03bc.cells \u2286 \u03bd.cells \u2194 \u03bc \u2264 \u03bd := iff.rfl\n@[simp] lemma cells_ssubset_iff {\u03bc \u03bd : young_diagram} : \u03bc.cells \u2282 \u03bd.cells \u2194 \u03bc < \u03bd := iff.rfl\n\ninstance : has_sup young_diagram :=\n{ sup := \u03bb \u03bc \u03bd, { cells        := \u03bc.cells \u222a \u03bd.cells,\n                  is_lower_set := by { rw finset.coe_union,\n                                       exact \u03bc.is_lower_set.union \u03bd.is_lower_set } } }\n\n@[simp] lemma cells_sup (\u03bc \u03bd : young_diagram) : (\u03bc \u2294 \u03bd).cells = \u03bc.cells \u222a \u03bd.cells := rfl\n\n@[simp, norm_cast] lemma coe_sup (\u03bc \u03bd : young_diagram) : \u2191(\u03bc \u2294 \u03bd) = (\u03bc \u222a \u03bd : set (\u2115 \u00d7 \u2115)) :=\nfinset.coe_union _ _\n\n@[simp] lemma mem_sup {\u03bc \u03bd : young_diagram} {x : \u2115 \u00d7 \u2115} : x \u2208 (\u03bc \u2294 \u03bd) \u2194 x \u2208 \u03bc \u2228 x \u2208 \u03bd :=\nfinset.mem_union\n\ninstance : has_inf young_diagram :=\n{ inf := \u03bb \u03bc \u03bd, { cells        := \u03bc.cells \u2229 \u03bd.cells,\n                  is_lower_set := by { rw finset.coe_inter,\n                                       exact \u03bc.is_lower_set.inter \u03bd.is_lower_set } } }\n\n@[simp] lemma cells_inf (\u03bc \u03bd : young_diagram) : (\u03bc \u2293 \u03bd).cells = \u03bc.cells \u2229 \u03bd.cells := rfl\n\n@[simp, norm_cast] lemma coe_inf (\u03bc \u03bd : young_diagram) : \u2191(\u03bc \u2293 \u03bd) = (\u03bc \u2229 \u03bd : set (\u2115 \u00d7 \u2115)) :=\nfinset.coe_inter _ _\n\n@[simp] lemma mem_inf {\u03bc \u03bd : young_diagram} {x : \u2115 \u00d7 \u2115} : x \u2208 (\u03bc \u2293 \u03bd) \u2194 x \u2208 \u03bc \u2227 x \u2208 \u03bd :=\nfinset.mem_inter\n\n/-- The empty Young diagram is (\u22a5 : young_diagram). -/\ninstance : order_bot young_diagram :=\n{ bot := { cells := \u2205, is_lower_set := \u03bb _ _ _, false.elim }, bot_le := \u03bb _ _, false.elim }\n\n@[simp] lemma cells_bot : (\u22a5 : young_diagram).cells = \u2205 := rfl\n\n@[simp, norm_cast] lemma coe_bot : \u2191(\u22a5 : young_diagram) = (\u2205 : set (\u2115 \u00d7 \u2115)) := rfl\n\n@[simp] lemma not_mem_bot (x : \u2115 \u00d7 \u2115) : x \u2209 (\u22a5 : young_diagram) := finset.not_mem_empty x\n\ninstance : inhabited young_diagram := \u27e8\u22a5\u27e9\n\ninstance : distrib_lattice young_diagram :=\nfunction.injective.distrib_lattice\n  young_diagram.cells\n  (\u03bb \u03bc \u03bd h, by rwa young_diagram.ext_iff)\n  (\u03bb _ _, rfl) (\u03bb _ _, rfl)\n\nend distrib_lattice\n\n/-- Cardinality of a Young diagram -/\n@[reducible] protected def card (\u03bc : young_diagram) : \u2115 := \u03bc.cells.card\n\nsection transpose\n\n/-- The `transpose` of a Young diagram is obtained by swapping i's with j's. -/\ndef transpose (\u03bc : young_diagram) : young_diagram :=\n{ cells :=  (equiv.prod_comm _ _).finset_congr \u03bc.cells,\n  is_lower_set := \u03bb _ _ h, begin\n    simp only [finset.mem_coe, equiv.finset_congr_apply, finset.mem_map_equiv],\n    intro hcell,\n    apply \u03bc.is_lower_set _ hcell,\n    simp [h],\n  end }\n\n@[simp] lemma mem_transpose {\u03bc : young_diagram} {c : \u2115 \u00d7 \u2115} : c \u2208 \u03bc.transpose \u2194 c.swap \u2208 \u03bc :=\nby simp [transpose]\n\n@[simp] lemma transpose_transpose (\u03bc : young_diagram) : \u03bc.transpose.transpose = \u03bc :=\nby { ext, simp }\n\nlemma transpose_eq_iff_eq_transpose {\u03bc \u03bd : young_diagram} :\n  \u03bc.transpose = \u03bd \u2194 \u03bc = \u03bd.transpose :=\nby { split; { rintro rfl, simp } }\n\n@[simp] lemma transpose_eq_iff {\u03bc \u03bd : young_diagram} :\n  \u03bc.transpose = \u03bd.transpose \u2194 \u03bc = \u03bd :=\nby { rw transpose_eq_iff_eq_transpose, simp }\n\n-- This is effectively both directions of `transpose_le_iff` below.\nprotected lemma le_of_transpose_le {\u03bc \u03bd : young_diagram} (h_le : \u03bc.transpose \u2264 \u03bd) :\n  \u03bc \u2264 \u03bd.transpose :=\n\u03bb c hc, by { simp only [mem_transpose], apply h_le, simpa }\n\n@[simp] lemma transpose_le_iff {\u03bc \u03bd : young_diagram} : \u03bc.transpose \u2264 \u03bd.transpose \u2194 \u03bc \u2264 \u03bd :=\n\u27e8 \u03bb h, by { convert young_diagram.le_of_transpose_le h, simp },\n  \u03bb h, by { convert @young_diagram.le_of_transpose_le _ _ _, simpa } \u27e9\n\n@[mono]\nprotected lemma transpose_mono {\u03bc \u03bd : young_diagram} (h_le : \u03bc \u2264 \u03bd) : \u03bc.transpose \u2264 \u03bd.transpose :=\ntranspose_le_iff.mpr h_le\n\n/-- Transposing Young diagrams is an `order_iso`. -/\n@[simps] def transpose_order_iso : young_diagram \u2243o young_diagram :=\n\u27e8\u27e8transpose, transpose, \u03bb _, by simp, \u03bb _, by simp\u27e9, by simp\u27e9\n\nend transpose\n\nsection rows\n/-! ### Rows and row lengths of Young diagrams.\n\nThis section defines `\u03bc.row` and `\u03bc.row_len`, with the following API:\n      1.  `(i, j) \u2208 \u03bc \u2194 j < \u03bc.row_len i`\n      2.  `\u03bc.row i = {i} \u00d7\u02e2 (finset.range (\u03bc.row_len i))`\n      3.  `\u03bc.row_len i = (\u03bc.row i).card`\n      4.  `\u2200 {i1 i2}, i1 \u2264 i2 \u2192 \u03bc.row_len i2 \u2264 \u03bc.row_len i1`\n\nNote: #3 is not convenient for defining `\u03bc.row_len`; instead, `\u03bc.row_len` is defined\nas the smallest `j` such that `(i, j) \u2209 \u03bc`. -/\n\n/-- The `i`-th row of a Young diagram consists of the cells whose first coordinate is `i`. -/\ndef row (\u03bc : young_diagram) (i : \u2115) : finset (\u2115 \u00d7 \u2115) := \u03bc.cells.filter (\u03bb c, c.fst = i)\n\nlemma mem_row_iff {\u03bc : young_diagram} {i : \u2115} {c : \u2115 \u00d7 \u2115} : c \u2208 \u03bc.row i \u2194 c \u2208 \u03bc \u2227 c.fst = i :=\nby simp [row]\n\nlemma mk_mem_row_iff {\u03bc : young_diagram} {i j : \u2115} : (i, j) \u2208 \u03bc.row i \u2194 (i, j) \u2208 \u03bc :=\nby simp [row]\n\nprotected lemma exists_not_mem_row (\u03bc : young_diagram) (i : \u2115) : \u2203 j, (i, j) \u2209 \u03bc :=\nbegin\n  obtain \u27e8j, hj\u27e9 := infinite.exists_not_mem_finset\n    ((\u03bc.cells).preimage (prod.mk i) (\u03bb _ _ _ _ h, by {cases h, refl})),\n  rw finset.mem_preimage at hj,\n  exact \u27e8j, hj\u27e9,\nend\n\n/-- Length of a row of a Young diagram -/\ndef row_len (\u03bc : young_diagram) (i : \u2115) : \u2115 := nat.find $ \u03bc.exists_not_mem_row i\n\nlemma mem_iff_lt_row_len {\u03bc : young_diagram} {i j : \u2115} : (i, j) \u2208 \u03bc \u2194 j < \u03bc.row_len i :=\nby { rw [row_len, nat.lt_find_iff], push_neg,\n     exact \u27e8\u03bb h _ hmj, \u03bc.up_left_mem (by refl) hmj h, \u03bb h, h _ (by refl)\u27e9 }\n\nlemma row_eq_prod {\u03bc : young_diagram} {i : \u2115} : \u03bc.row i = {i} \u00d7\u02e2 finset.range (\u03bc.row_len i) :=\nby { ext \u27e8a, b\u27e9,\n     simp only [finset.mem_product, finset.mem_singleton, finset.mem_range,\n                mem_row_iff, mem_iff_lt_row_len, and_comm, and.congr_right_iff],\n     rintro rfl, refl }\n\nlemma row_len_eq_card (\u03bc : young_diagram) {i : \u2115} : \u03bc.row_len i = (\u03bc.row i).card :=\nby simp [row_eq_prod]\n\n@[mono]\nlemma row_len_anti (\u03bc : young_diagram) (i1 i2 : \u2115) (hi : i1 \u2264 i2) : \u03bc.row_len i2 \u2264 \u03bc.row_len i1 :=\nby { by_contra' h_lt, rw \u2190 lt_self_iff_false (\u03bc.row_len i1),\n     rw \u2190 mem_iff_lt_row_len at h_lt \u22a2,\n     exact \u03bc.up_left_mem hi (by refl) h_lt }\n\nend rows\n\nsection columns\n/-! ### Columns and column lengths of Young diagrams.\n\nThis section has an identical API to the rows section. -/\n\n/-- The `j`-th column of a Young diagram consists of the cells whose second coordinate is `j`. -/\ndef col (\u03bc : young_diagram) (j : \u2115) : finset (\u2115 \u00d7 \u2115) := \u03bc.cells.filter (\u03bb c, c.snd = j)\n\nlemma mem_col_iff {\u03bc : young_diagram} {j : \u2115} {c : \u2115 \u00d7 \u2115} : c \u2208 \u03bc.col j \u2194 c \u2208 \u03bc \u2227 c.snd = j :=\nby simp [col]\n\nlemma mk_mem_col_iff {\u03bc : young_diagram} {i j : \u2115} : (i, j) \u2208 \u03bc.col j \u2194 (i, j) \u2208 \u03bc :=\nby simp [col]\n\nprotected lemma exists_not_mem_col (\u03bc : young_diagram) (j : \u2115) : \u2203 i, (i, j) \u2209 \u03bc.cells :=\nby { convert \u03bc.transpose.exists_not_mem_row j, simp }\n\n/-- Length of a column of a Young diagram -/\ndef col_len (\u03bc : young_diagram) (j : \u2115) : \u2115 := nat.find $ \u03bc.exists_not_mem_col j\n\n@[simp] lemma col_len_transpose (\u03bc : young_diagram) (j : \u2115) : \u03bc.transpose.col_len j = \u03bc.row_len j :=\nby simp [row_len, col_len]\n\n@[simp] lemma row_len_transpose (\u03bc : young_diagram) (i : \u2115) : \u03bc.transpose.row_len i = \u03bc.col_len i :=\nby simp [row_len, col_len]\n\nlemma mem_iff_lt_col_len {\u03bc : young_diagram} {i j : \u2115} : (i, j) \u2208 \u03bc \u2194 i < \u03bc.col_len j :=\nby { rw [\u2190 row_len_transpose, \u2190 mem_iff_lt_row_len], simp }\n\nlemma col_eq_prod {\u03bc : young_diagram} {j : \u2115} : \u03bc.col j = (finset.range (\u03bc.col_len j)) \u00d7\u02e2 {j} :=\nby { ext \u27e8a, b\u27e9,\n     simp only [finset.mem_product, finset.mem_singleton, finset.mem_range,\n                mem_col_iff, mem_iff_lt_col_len, and_comm, and.congr_right_iff],\n     rintro rfl, refl }\n\nlemma col_len_eq_card (\u03bc : young_diagram) {j : \u2115} : \u03bc.col_len j = (\u03bc.col j).card :=\nby simp [col_eq_prod]\n\n@[mono]\n\n\nend columns\n\nsection row_lens\n/-! ### The list of row lengths of a Young diagram\n\nThis section defines `\u03bc.row_lens : list \u2115`, the list of row lengths of a Young diagram `\u03bc`.\n  1. `young_diagram.row_lens_sorted` : It is weakly decreasing (`list.sorted (\u2265)`).\n  2. `young_diagram.row_lens_pos` : It is strictly positive.\n\n-/\n\n/-- List of row lengths of a Young diagram -/\ndef row_lens (\u03bc : young_diagram) : list \u2115 := (list.range $ \u03bc.col_len 0).map \u03bc.row_len\n\n@[simp] lemma nth_le_row_lens {\u03bc : young_diagram} {i : \u2115} {hi : i < \u03bc.row_lens.length} :\n  \u03bc.row_lens.nth_le i hi = \u03bc.row_len i :=\nby simp only [row_lens, list.nth_le_range, list.nth_le_map']\n\n@[simp] lemma length_row_lens {\u03bc : young_diagram} : \u03bc.row_lens.length = \u03bc.col_len 0 :=\nby simp only [row_lens, list.length_map, list.length_range]\n\nlemma row_lens_sorted (\u03bc : young_diagram) : \u03bc.row_lens.sorted (\u2265) :=\n(list.pairwise_le_range _).map _ \u03bc.row_len_anti\n\nlemma pos_of_mem_row_lens (\u03bc : young_diagram) (x : \u2115) (hx : x \u2208 \u03bc.row_lens) : 0 < x :=\nbegin\n  rw [row_lens, list.mem_map] at hx,\n  obtain \u27e8i, hi, rfl : \u03bc.row_len i = x\u27e9 := hx,\n  rwa [list.mem_range, \u2190 mem_iff_lt_col_len, mem_iff_lt_row_len] at hi\nend\n\nend row_lens\n\nsection equiv_list_row_lens\n/-! ### Equivalence between Young diagrams and lists of natural numbers\n\nThis section defines the equivalence between Young diagrams `\u03bc` and weakly decreasing lists `w`\nof positive natural numbers, corresponding to row lengths of the diagram:\n  `young_diagram.equiv_list_row_lens :`\n  `young_diagram \u2243 {w : list \u2115 // w.sorted (\u2265) \u2227 \u2200 x \u2208 w, 0 < x}`\n\nThe two directions are `young_diagram.row_lens` (defined above) and `young_diagram.of_row_lens`.\n\n-/\n\n/-- The cells making up a `young_diagram` from a list of row lengths -/\nprotected def cells_of_row_lens : list \u2115 \u2192 finset (\u2115 \u00d7 \u2115)\n| [] := \u2205\n| (w :: ws) := (({0} : finset \u2115) \u00d7\u02e2 finset.range w) \u222a\n                 (cells_of_row_lens ws).map\n                   (embedding.prod_map \u27e8_, nat.succ_injective\u27e9 (embedding.refl \u2115))\n\nprotected lemma mem_cells_of_row_lens {w : list \u2115} {c : \u2115 \u00d7 \u2115} :\n  c \u2208 young_diagram.cells_of_row_lens w \u2194 \u2203 (h : c.fst < w.length), c.snd < w.nth_le c.fst h :=\nbegin\n  induction w generalizing c;\n  rw young_diagram.cells_of_row_lens,\n  { simp [young_diagram.cells_of_row_lens] },\n  { rcases c with \u27e8\u27e8_, _\u27e9, _\u27e9,\n    { simp },\n    { simpa [w_ih, -finset.singleton_product, nat.succ_lt_succ_iff] } }\nend\n\n/-- Young diagram from a sorted list -/\ndef of_row_lens (w : list \u2115) (hw : w.sorted (\u2265)) : young_diagram :=\n{ cells        := young_diagram.cells_of_row_lens w,\n  is_lower_set := begin\n    rintros \u27e8i2, j2\u27e9 \u27e8i1, j1\u27e9 \u27e8hi : i1 \u2264 i2, hj : j1 \u2264 j2\u27e9 hcell,\n    rw [finset.mem_coe, young_diagram.mem_cells_of_row_lens] at hcell \u22a2,\n    obtain \u27e8h1, h2\u27e9 := hcell,\n    refine \u27e8hi.trans_lt h1, _\u27e9,\n    calc j1 \u2264 j2            : hj\n      ...   < w.nth_le i2 _ : h2\n      ...   \u2264 w.nth_le i1 _ : _,\n    obtain (rfl | h) := eq_or_lt_of_le hi,\n    { refl },\n    { apply list.pairwise_iff_nth_le.mp hw _ _ _ h }\n  end }\n\nlemma mem_of_row_lens {w : list \u2115} {hw : w.sorted (\u2265)} {c : \u2115 \u00d7 \u2115} :\n  c \u2208 of_row_lens w hw \u2194 \u2203 (h : c.fst < w.length), c.snd < w.nth_le c.fst h :=\nyoung_diagram.mem_cells_of_row_lens\n\n/-- The number of rows in `of_row_lens w hw` is the length of `w` -/\nlemma row_lens_length_of_row_lens {w : list \u2115} {hw : w.sorted (\u2265)} (hpos : \u2200 x \u2208 w, 0 < x) :\n  (of_row_lens w hw).row_lens.length = w.length :=\nbegin\n  simp only [length_row_lens, col_len, nat.find_eq_iff, mem_cells, mem_of_row_lens,\n             lt_self_iff_false, is_empty.exists_iff, not_not],\n  exact \u27e8id, \u03bb n hn, \u27e8hn, hpos _ (list.nth_le_mem _ _ hn)\u27e9\u27e9,\nend\n\n/-- The length of the `i`th row in `of_row_lens w hw` is the `i`th entry of `w` -/\nlemma row_len_of_row_lens {w : list \u2115} {hw : w.sorted (\u2265)}\n  (i : \u2115) (hi : i < w.length) : (of_row_lens w hw).row_len i = w.nth_le i hi :=\nby simp [row_len, nat.find_eq_iff, mem_of_row_lens, hi]\n\n/-- The left_inv direction of the equivalence -/\nlemma of_row_lens_to_row_lens_eq_self {\u03bc : young_diagram} :\n  of_row_lens _ (row_lens_sorted \u03bc) = \u03bc :=\nbegin\n  ext \u27e8i, j\u27e9,\n  simp only [mem_cells, mem_of_row_lens, length_row_lens, nth_le_row_lens],\n  simpa [\u2190 mem_iff_lt_col_len, mem_iff_lt_row_len] using j.zero_le.trans_lt,\nend\n\n/-- The right_inv direction of the equivalence -/\nlemma row_lens_of_row_lens_eq_self {w : list \u2115} {hw : w.sorted (\u2265)} (hpos : \u2200 x \u2208 w, 0 < x) :\n  (of_row_lens w hw).row_lens = w :=\nbegin\n  ext i r,\n  cases lt_or_ge i w.length,\n  { simp only [option.mem_def, \u2190 list.nth_le_eq_iff, h, row_lens_length_of_row_lens hpos],\n    revert r,\n    simpa only [eq_iff_eq_cancel_right, nth_le_row_lens] using row_len_of_row_lens _ h },\n  { rw [list.nth_eq_none_iff.mpr h, list.nth_eq_none_iff.mpr],\n    rwa row_lens_length_of_row_lens hpos }\nend\n\n/-- Equivalence between Young diagrams and weakly decreasing lists of positive natural numbers.\nA Young diagram `\u03bc` is equivalent to a list of row lengths. -/\n@[simps]\ndef equiv_list_row_lens : young_diagram \u2243 {w : list \u2115 // w.sorted (\u2265) \u2227 \u2200 x \u2208 w, 0 < x} :=\n{ to_fun    := \u03bb \u03bc, \u27e8\u03bc.row_lens, \u03bc.row_lens_sorted, \u03bc.pos_of_mem_row_lens\u27e9,\n  inv_fun   := \u03bb ww, of_row_lens ww.1 ww.2.1,\n  left_inv  := \u03bb \u03bc, of_row_lens_to_row_lens_eq_self,\n  right_inv := \u03bb \u27e8w, hw\u27e9, subtype.mk_eq_mk.mpr (row_lens_of_row_lens_eq_self hw.2) }\n\nend equiv_list_row_lens\n\nend young_diagram\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/young/young_diagram.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.7180544100545271}}
{"text": "/-\nCopyright (c) 2021 Chris Birkbeck. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Birkbeck\n-/\nimport linear_algebra.matrix.nonsingular_inverse\nimport linear_algebra.special_linear_group\n\n/-!\n# The General Linear group $GL(n, R)$\nThis file defines the elements of the General Linear group `general_linear_group n R`,\nconsisting of all invertible `n` by `n` `R`-matrices.\n## Main definitions\n* `matrix.general_linear_group` is the type of matrices over R which are units in the matrix ring.\n* `matrix.GL_pos` gives the subgroup of matrices with\n  positive determinant (over a linear ordered ring).\n## Tags\nmatrix group, group, matrix inverse\n-/\n\nnamespace matrix\nuniverses u v\nopen_locale matrix\nopen linear_map\n\n/-- `GL n R` is the group of `n` by `n` `R`-matrices with unit determinant.\nDefined as a subtype of matrices-/\nabbreviation general_linear_group (n : Type u) (R : Type v)\n  [decidable_eq n] [fintype n] [comm_ring R] : Type* := units (matrix n n R)\n\nnotation `GL` := general_linear_group\n\nnamespace general_linear_group\n\nvariables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]\n\n/-- The determinant of a unit matrix is itself a unit. -/\n@[simps]\ndef det : GL n R \u2192* units R :=\n{ to_fun := \u03bb A,\n  { val := (\u2191A : matrix n n R).det,\n    inv := (\u2191(A\u207b\u00b9) : matrix n n R).det,\n    val_inv := by rw [\u2190det_mul, \u2190mul_eq_mul, A.mul_inv, det_one],\n    inv_val := by rw [\u2190det_mul, \u2190mul_eq_mul, A.inv_mul, det_one]},\n  map_one' := units.ext det_one,\n  map_mul' := \u03bb A B, units.ext $ det_mul _ _ }\n\n/--The `GL n R` and `general_linear_group R n` groups are multiplicatively equivalent-/\ndef to_lin : (GL n R) \u2243* (linear_map.general_linear_group R (n \u2192 R)) :=\nunits.map_equiv to_lin_alg_equiv'.to_mul_equiv\n\n/--Given a matrix with invertible determinant we get an element of `GL n R`-/\ndef mk' (A : matrix n n R) (h : invertible (matrix.det A)) : GL n R :=\nunit_of_det_invertible A\n\n/--Given a matrix with unit determinant we get an element of `GL n R`-/\nnoncomputable def mk'' (A : matrix n n R) (h : is_unit (matrix.det A)) : GL n R :=\nnonsing_inv_unit A h\n\n/--Given a matrix with non-zero determinant over a field, we get an element of `GL n K`-/\ndef mk_of_det_ne_zero {K : Type*} [field K] (A : matrix n n K) (h : matrix.det A \u2260 0) :\n  GL n K :=\nmk' A (invertible_of_nonzero h)\n\ninstance coe_fun : has_coe_to_fun (GL n R) (\u03bb _, n \u2192 n \u2192 R) :=\n{ coe := \u03bb A, A.val }\n\nlemma ext_iff (A B : GL n R) : A = B \u2194 (\u2200 i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :=\nunits.ext_iff.trans matrix.ext_iff.symm\n\n/-- Not marked `@[ext]` as the `ext` tactic already solves this. -/\nlemma ext \u2983A B : GL n R\u2984 (h : \u2200 i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :\n  A = B :=\nunits.ext $ matrix.ext h\n\nsection coe_lemmas\n\nvariables (A B : GL n R)\n\n@[simp] lemma coe_fn_eq_coe : \u21d1A = (\u2191A : matrix n n R) := rfl\n\n@[simp] lemma coe_mul : \u2191(A * B) = (\u2191A : matrix n n R) \u2b1d (\u2191B : matrix n n R) := rfl\n\n@[simp] lemma coe_one : \u2191(1 : GL n R) = (1 : matrix n n R) := rfl\n\nlemma coe_inv : \u2191(A\u207b\u00b9) = (\u2191A : matrix n n R)\u207b\u00b9 :=\nbegin\n  letI := A.invertible,\n  exact inv_of_eq_nonsing_inv (\u2191A : matrix n n R),\nend\n\n/-- An element of the matrix general linear group on `(n) [fintype n]` can be considered as an\nelement of the endomorphism general linear group on `n \u2192 R`. -/\ndef to_linear : general_linear_group n R \u2243* linear_map.general_linear_group R (n \u2192 R) :=\nunits.map_equiv matrix.to_lin_alg_equiv'.to_ring_equiv.to_mul_equiv\n\n-- Note that without the `@` and `\u2039_\u203a`, lean infers `\u03bb a b, _inst_1 a b` instead of `_inst_1` as the\n-- decidability argument, which prevents `simp` from obtaining the instance by unification.\n-- These `\u03bb a b, _inst a b` terms also appear in the type of `A`, but simp doesn't get confused by\n-- them so for now we do not care.\n@[simp] lemma coe_to_linear :\n  (@to_linear n \u2039_\u203a \u2039_\u203a _ _ A : (n \u2192 R) \u2192\u2097[R] (n \u2192 R)) = matrix.mul_vec_lin A :=\nrfl\n\n@[simp] lemma to_linear_apply (v : n \u2192 R) :\n  (@to_linear n \u2039_\u203a \u2039_\u203a _ _ A) v = matrix.mul_vec_lin A v :=\nrfl\n\nend coe_lemmas\n\nend general_linear_group\n\nnamespace special_linear_group\n\nvariables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]\n\ninstance has_coe_to_general_linear_group : has_coe (special_linear_group n R) (GL n R) :=\n\u27e8\u03bb A, \u27e8\u2191A, \u2191(A\u207b\u00b9), congr_arg coe (mul_right_inv A), congr_arg coe (mul_left_inv A)\u27e9\u27e9\n\nend special_linear_group\n\nsection\n\nvariables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]\n\nsection\nvariables (n R)\n\n/-- This is the subgroup of `nxn` matrices with entries over a\nlinear ordered ring and positive determinant. -/\ndef GL_pos : subgroup (GL n R) :=\n(units.pos_subgroup R).comap general_linear_group.det\nend\n\n@[simp] lemma mem_GL_pos (A : GL n R) : A \u2208 GL_pos n R \u2194 0 < (A.det : R) := iff.rfl\nend\n\nsection has_neg\n\nvariables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]\n[fact (even (fintype.card n))]\n\n/-- Formal operation of negation on general linear group on even cardinality `n` given by negating\neach element. -/\ninstance : has_neg (GL_pos n R) :=\n\u27e8\u03bb g,\n   \u27e8- g,\n  begin\n    simp only [mem_GL_pos, general_linear_group.coe_det_apply, units.coe_neg],\n    have := det_smul g (-1),\n    simp only [general_linear_group.coe_fn_eq_coe, one_smul, coe_fn_coe_base', neg_smul] at this,\n    rw this,\n    simp [nat.neg_one_pow_of_even (fact.out (even (fintype.card n)))],\n    have gdet := g.property,\n    simp only [mem_GL_pos, general_linear_group.coe_det_apply, subtype.val_eq_coe] at gdet,\n    exact gdet,\n  end\u27e9\u27e9\n\n@[simp] lemma GL_pos_coe_neg (g : GL_pos n R) : \u2191(- g) = - (\u2191g : matrix n n R) :=\nrfl\n\n@[simp]lemma GL_pos_neg_elt (g : GL_pos n R): \u2200 i j, ( \u2191(-g): matrix n n R) i j= - (g i j):=\nbegin\n  simp [coe_fn_coe_base'],\nend\n\nend has_neg\n\nnamespace special_linear_group\n\nvariables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [linear_ordered_comm_ring R]\n\n/-- `special_linear_group n R` embeds into `GL_pos n R` -/\ndef to_GL_pos : special_linear_group n R \u2192* GL_pos n R :=\n{ to_fun := \u03bb A, \u27e8(A : GL n R), show 0 < (\u2191A : matrix n n R).det, from A.prop.symm \u25b8 zero_lt_one\u27e9,\n  map_one' := subtype.ext $ units.ext $ rfl,\n  map_mul' := \u03bb A\u2081 A\u2082, subtype.ext $ units.ext $ rfl }\n\ninstance : has_coe (special_linear_group n R) (GL_pos n R) := \u27e8to_GL_pos\u27e9\n\nlemma coe_eq_to_GL_pos : (coe : special_linear_group n R \u2192 GL_pos n R) = to_GL_pos := rfl\n\nlemma to_GL_pos_injective :\n  function.injective (to_GL_pos : special_linear_group n R \u2192 GL_pos n R) :=\n(show function.injective ((coe : GL_pos n R \u2192 matrix n n R) \u2218 to_GL_pos),\n from subtype.coe_injective).of_comp\n\nend special_linear_group\n\nsection examples\n\n/-- The matrix [a, b; -b, a] (inspired by multiplication by a complex number); it is an element of\n$GL_2(R)$ if `a ^ 2 + b ^ 2` is nonzero. -/\n@[simps coe {fully_applied := ff}]\ndef plane_conformal_matrix {R} [field R] (a b : R) (hab : a ^ 2 + b ^ 2 \u2260 0) :\n  matrix.general_linear_group (fin 2) R :=\ngeneral_linear_group.mk_of_det_ne_zero ![![a, b], ![-b, a]]\n  (by simpa [det_fin_two, sq] using hab)\n\n/- TODO: Add Iwasawa matrices `n_x=![![1,x],![0,1]]`, `a_t=![![exp(t/2),0],![0,exp(-t/2)]]` and\n  `k_\u03b8==![![cos \u03b8, sin \u03b8],![-sin \u03b8, cos \u03b8]]`\n-/\n\nend examples\n\nend matrix\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/general_linear_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7180544086514652}}
{"text": "import game.limits.L01defs\nimport game.limits.seq_proveLimit\nimport algebra.pi_instances\nimport game.order.level05\n\n\n--open function\nopen finset\n\nnamespace xena -- hide\n\nnotation `|` x `|` := abs x -- hide\n\ndef is_convergent (a : \u2115 \u2192 \u211d) := \u2203 \u03b1 : \u211d, is_limit a \u03b1 \ndef is_Cauchy (a : \u2115 \u2192 \u211d) := \n  \u2200 \u03b5 : \u211d, 0 < \u03b5 \u2192 \u2203 N : \u2115, \u2200 m n : \u2115, N \u2264 m \u2227 N \u2264 n \u2192 |a m - a n| < \u03b5\ndef is_bdd (a : \u2115 \u2192 \u211d) := \u2203 B > 0, \u2200 n, |a n| \u2264 B \n\n-- begin hide\n-- We may want to skip this in RNG unless we can make it look (or be) easy --?\n-- end hide\n\n/-\nCauchy sequences are bounded.\n\n-/\n\n/- Lemma\nA Cauchy sequence is bounded.\n-/\nlemma cauchy_is_bdd (a : \u2115 \u2192 \u211d) : \n    is_Cauchy a \u2192 is_bdd a:=\nbegin\n  --classical proof for boundedness of Cauchy sequences\n  intro HC,\n  set e := (1:\u211d),\n  have h1e : (0:\u211d) < 1, linarith,\n  have H := HC 1 h1e,\n  cases H with N hN,\n  have G := hN N,\n  -- construct X = {|a0|, |a1|, ...,|am|}\n  let X := finset.image (abs \u2218 a) (finset.range (N + 1)),\n  -- at least a0 is in X\n  have  ha0 : |a 0| \u2208 X := finset.mem_image_of_mem _ (mem_range.2 (nat.zero_lt_succ _)),\n  -- hence the set X is not empty\n  have ha1 : X \u2260 \u2205 := ne_empty_of_mem ha0,\n  have ha2 := nonempty_iff_ne_empty.mpr ha1,\n  -- and therefore has a maximum\n  let B1 := X.max' ha2,\n  -- If n \u2264 m then get a proof that |a n| \u2264 B1.\n  have HB1 : \u2200 n \u2264 N, |a n| \u2264 B1 := \u03bb n Hn, le_max' X ha2 _\n    (mem_image_of_mem _ (mem_range.2 (nat.lt_succ_of_le Hn))),\n  -- term that bounds all members of the sequence\n  set B := max B1 ( |a N| + 1 ) with hB,\n  -- so this will be our bound\n  use B,\n  split,\n  swap,\n  intro n,\n  cases le_or_gt n N with hn1 hn2,\n  { -- n \u2264 N\n    have g1 : | a n | \u2264  B1 := HB1 n hn1,\n    have g2 : B1 \u2264 B := le_max_left _ _, \n    linarith,\n  },\n  { -- n > N\n    have g1 := G n,\n    have g2 : N \u2264 N \u2227 N \u2264 n,\n        split; linarith,\n    have g3 := g1 g2,\n    rw abs_lt at g3,\n    have fact1 := g3.left,\n    have fact2 := g3.right,\n    simp,\n    right,\n    rw abs_le,  -- our abs_le is conditional on 0 \u2264 c - proven in the last section\n    simp,\n    split,\n    {\n    have simplefact1: - a N \u2264 | a N | := neg_le_abs_self (a N),\n    linarith,\n    },   \n    {have simplefact2: a N \u2264 | a N | := le_abs_self(a N),\n    linarith},\n    \n  have simplefact3: 0 \u2264 |a N|, from abs_nonneg (a N),\n  linarith,     \n  },\n  \n  have g1 : |a N| + 1 \u2264 B := le_max_right _ _,\n  have g2: 0 \u2264 |a N|, from abs_nonneg (a N),\n  linarith,\n\nend\n\nend xena -- hide\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/limits/seq_cauchyBdd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7180543995956875}}
{"text": "theorem Q2a {x y : fake_reals} : (x > 0) \u2192 (y < 0) \u2192 x * y < 0 := sorry\n\ntheorem neg_pos_of_neg' {x : fake_reals} : x < 0 \u2192 -x > 0 :=\nbegin\nintro Hx_neg,\n  have H : x + (-x) < 0 + (-x) := A1 Hx_neg,\n  rwa [add_neg_self,zero_add] at H,\nend\n\ntheorem neg_eq_neg_one_mul' {x : fake_reals} : -x = (-1)*x :=\nneg_eq_neg_one_mul x\n\ntheorem neg_one_squared : (-1:fake_reals)*(-1)=1 :=\ncalc (-1:fake_reals)*(-1)=-(-1) : eq.symm (@neg_eq_neg_one_mul' (-1))\n... = 1 : neg_neg 1\n\ntheorem pos_eq_neg_mul_neg {x y : fake_reals} : x < 0 \u2192 y < 0 \u2192 x * y > 0 :=\nbegin\nintros Hxneg Hyneg,\nhave Hneg_x_pos : -x > 0 := neg_pos_of_neg' Hxneg,\nhave Hneg_y_pos : -y > 0 := neg_pos_of_neg' Hyneg,\nexact calc x * y = -x * -y : by rw [neg_eq_neg_one_mul',@neg_eq_neg_one_mul' y,\u2190mul_one (x * y),\u2190neg_one_squared];simp\n... > 0 : A4 Hneg_x_pos Hneg_y_pos,\nend\n\ntheorem Q2b {x y : fake_reals} : x < 0 \u2192 y < 0 \u2192 x * y > 0 := sorry\n\ntheorem zero_not_pos : \u00ac ((0:fake_reals) < 0) := (@A3 0 0).right.right.right (rfl)\n\ntheorem fake_reals_integral_domain {x y : fake_reals} : x * y = 0 \u2192 x = 0 \u2228 y = 0 :=\nbegin\nintro Hxy_zero,\ncases (@A3 0 x).left with Hx_pos Hx_nonpos,\n  cases (@A3 0 y).left with Hy_pos Hy_nonpos,\n    exfalso,\n    exact zero_not_pos (calc 0 < x * y : A4 Hx_pos Hy_pos ... = 0 : Hxy_zero),\n  cases Hy_nonpos with Hy_0 Hy_neg,\n    right,exact eq.symm Hy_0,\n  exfalso,\n  apply zero_not_pos,\n  exact calc 0 = x*y : eq.symm Hxy_zero ... <0 : Q2a Hx_pos Hy_neg,\ncases Hx_nonpos with Hx_0 Hx_neg,\n  left,exact eq.symm Hx_0,\ncases (@A3 0 y).left with Hy_pos Hy_nonpos,\n  exfalso,\n  apply zero_not_pos,\n  exact calc 0=x*y : eq.symm Hxy_zero ... = y*x : by rw[mul_comm] ... <0 : Q2a Hy_pos Hx_neg,\ncases Hy_nonpos with Hy_0 Hy_neg,\n  right,exact eq.symm Hy_0,\nexfalso, apply zero_not_pos,\nexact calc 0 < x * y : Q2b Hx_neg Hy_neg ... = 0 : Hxy_zero,\nend\n\ntheorem Q2c : \u2200 x y : fake_reals, x * y = 0 \u2192 x = 0 \u2228 y = 0 := sorry\n\nend M1F_Sheet03\n\naxiom A5 : \u2200 x : fake_reals, x > 0 \u2192 \u2203 y : fake_reals,\n                 y > 0 \u2227 y*y=x \u2227 \u2200 z : fake_reals, z > 0 \u2227 z*z=x \u2192 z=y\n\nsection M1F_Sheet03\n\ntheorem Q2d : \u2200 x : fake_reals, x > 0 \u2192 \u2203 z1 z2 : fake_reals, z1*z1=x \u2227 z2*z2=x \u2227 \u2200 z : fake_reals, z*z=x \u2192 z=z1 \u2228 z=z2 := sorry\n\nend M1F_Sheet03\n\naxiom A6 : \u2200 n : \u2115, n > 0 \u2192\n             \u2200 x : fake_reals, x > 0 \u2192\n               \u2203 y : fake_reals,\n                 y > 0\n                \u2227 y ^ n = x\n                \u2227 \u2200 z : fake_reals, z > 0 \u2227 z ^ n = x \u2192 z = y\n\n\nsection M1F_Sheet03", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1F/problem_bank/0302/Q0302.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7180543984478439}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\n\nimport algebra.algebra.basic\nimport algebra.module.ordered\n\n/-!\n# Ordered algebras\n\nAn ordered algebra is an ordered semiring, which is an algebra over an ordered commutative semiring,\nfor which scalar multiplication is \"compatible\" with the two orders.\n\nThe prototypical example is 2x2 matrices over the reals or complexes (or indeed any C^* algebra)\nwhere the ordering the one determined by the positive cone of positive operators,\ni.e. `A \u2264 B` iff `B - A = star R * R` for some `R`.\n(We don't yet have this example in mathlib.)\n\n## Implementation\n\nBecause the axioms for an ordered algebra are exactly the same as those for the underlying\nmodule being ordered, we don't actually introduce a new class, but just use the `ordered_module`\nmixin.\n\n## Tags\n\nordered algebra\n-/\n\nsection ordered_algebra\n\nvariables {R A : Type*} {a b : A} {r : R}\n\nvariables [ordered_comm_ring R] [ordered_ring A] [algebra R A] [ordered_module R A]\n\nlemma algebra_map_monotone : monotone (algebra_map R A) :=\n\u03bb a b h,\nbegin\n  rw [algebra.algebra_map_eq_smul_one, algebra.algebra_map_eq_smul_one, \u2190sub_nonneg, \u2190sub_smul],\n  transitivity (b - a) \u2022 (0 : A),\n  { simp, },\n  { exact smul_le_smul_of_nonneg zero_le_one (sub_nonneg.mpr h) }\nend\n\nend ordered_algebra\n\nsection instances\n\nvariables {R : Type*} [linear_ordered_comm_ring R]\n\ninstance linear_ordered_comm_ring.to_ordered_module : ordered_module R R :=\n{ smul_lt_smul_of_pos       := ordered_semiring.mul_lt_mul_of_pos_left,\n  lt_of_smul_lt_smul_of_pos := \u03bb a b c w\u2081 w\u2082, (mul_lt_mul_left w\u2082).mp w\u2081 }\n\nend instances\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/algebra/ordered.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7180543970447821}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport ring_theory.polynomial.pochhammer\n\n/-!\n# Cast of factorials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file allows calculating factorials (including ascending and descending ones) as elements of a\nsemiring.\n\nThis is particularly crucial for `nat.desc_factorial` as subtraction on `\u2115` does **not** correspond\nto subtraction on a general semiring. For example, we can't rely on existing cast lemmas to prove\n`\u2191(a.desc_factorial 2) = \u2191a * (\u2191a - 1)`. We must use the fact that, whenever `\u2191(a - 1)` is not equal\nto `\u2191a - 1`, the other factor is `0` anyway.\n-/\n\nopen_locale nat\n\nvariables (S : Type*)\n\nnamespace nat\n\nsection semiring\nvariables [semiring S] (a b : \u2115)\n\nlemma cast_asc_factorial :\n  (a.asc_factorial b : S) = (pochhammer S b).eval (a + 1) :=\nby rw [\u2190pochhammer_nat_eq_asc_factorial, pochhammer_eval_cast, nat.cast_add, nat.cast_one]\n\nlemma cast_desc_factorial :\n  (a.desc_factorial b : S) = (pochhammer S b).eval (a - (b - 1) : \u2115) :=\nbegin\n  rw [\u2190pochhammer_eval_cast, pochhammer_nat_eq_desc_factorial],\n  cases b,\n  { simp_rw desc_factorial_zero },\n  simp_rw [add_succ, succ_sub_one],\n  obtain h | h := le_total a b,\n  { rw [desc_factorial_of_lt (lt_succ_of_le h), desc_factorial_of_lt (lt_succ_of_le _)],\n    rw [tsub_eq_zero_iff_le.mpr h, zero_add] },\n  { rw tsub_add_cancel_of_le h }\nend\n\nlemma cast_factorial :\n  (a! : S) = (pochhammer S a).eval 1 :=\nby rw [\u2190zero_asc_factorial, cast_asc_factorial, cast_zero, zero_add]\n\nend semiring\n\nsection ring\nvariables [ring S] (a b : \u2115)\n\n/-- Convenience lemma. The `a - 1` is not using truncated subtraction, as opposed to the definition\nof `nat.desc_factorial` as a natural. -/\nlemma cast_desc_factorial_two :\n  (a.desc_factorial 2 : S) = a * (a - 1) :=\nbegin\n  rw cast_desc_factorial,\n  cases a,\n  { rw [zero_tsub, cast_zero, pochhammer_ne_zero_eval_zero _ (two_ne_zero), zero_mul] },\n  { rw [succ_sub_succ, tsub_zero, cast_succ, add_sub_cancel, pochhammer_succ_right,\n      pochhammer_one, polynomial.X_mul, polynomial.eval_mul_X, polynomial.eval_add,\n      polynomial.eval_X, cast_one, polynomial.eval_one] }\nend\n\nend ring\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/factorial/cast.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7180543958969385}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.special_functions.exp\nimport topology.continuous_function.basic\nimport analysis.normed.field.unit_ball\n\n/-!\n# The circle\n\nThis file defines `circle` to be the metric sphere (`metric.sphere`) in `\u2102` centred at `0` of\nradius `1`.  We equip it with the following structure:\n\n* a submonoid of `\u2102`\n* a group\n* a topological group\n\nWe furthermore define `exp_map_circle` to be the natural map `\u03bb t, exp (t * I)` from `\u211d` to\n`circle`, and show that this map is a group homomorphism.\n\n## Implementation notes\n\nBecause later (in `geometry.manifold.instances.sphere`) one wants to equip the circle with a smooth\nmanifold structure borrowed from `metric.sphere`, the underlying set is\n`{z : \u2102 | abs (z - 0) = 1}`.  This prevents certain algebraic facts from working definitionally --\nfor example, the circle is not defeq to `{z : \u2102 | abs z = 1}`, which is the kernel of `complex.abs`\nconsidered as a homomorphism from `\u2102` to `\u211d`, nor is it defeq to `{z : \u2102 | norm_sq z = 1}`, which\nis the kernel of the homomorphism `complex.norm_sq` from `\u2102` to `\u211d`.\n\n-/\n\nnoncomputable theory\n\nopen complex metric\nopen_locale complex_conjugate\n\n/-- The unit circle in `\u2102`, here given the structure of a submonoid of `\u2102`. -/\ndef circle : submonoid \u2102 := submonoid.unit_sphere \u2102\n\n@[simp] lemma mem_circle_iff_abs {z : \u2102} : z \u2208 circle \u2194 abs z = 1 := mem_sphere_zero_iff_norm\n\nlemma circle_def : \u2191circle = {z : \u2102 | abs z = 1} := set.ext $ \u03bb z, mem_circle_iff_abs\n\n@[simp] lemma abs_coe_circle (z : circle) : abs z = 1 :=\nmem_circle_iff_abs.mp z.2\n\nlemma mem_circle_iff_norm_sq {z : \u2102} : z \u2208 circle \u2194 norm_sq z = 1 :=\nby rw [mem_circle_iff_abs, complex.abs, real.sqrt_eq_one]\n\n@[simp] lemma norm_sq_eq_of_mem_circle (z : circle) : norm_sq z = 1 := by simp [norm_sq_eq_abs]\n\nlemma ne_zero_of_mem_circle (z : circle) : (z:\u2102) \u2260 0 := ne_zero_of_mem_unit_sphere z\n\ninstance : comm_group circle := metric.sphere.comm_group\n\n@[simp] lemma coe_inv_circle (z : circle) : \u2191(z\u207b\u00b9) = (z : \u2102)\u207b\u00b9 := rfl\n\nlemma coe_inv_circle_eq_conj (z : circle) : \u2191(z\u207b\u00b9) = conj (z : \u2102) :=\nby rw [coe_inv_circle, inv_def, norm_sq_eq_of_mem_circle, inv_one, of_real_one, mul_one]\n\n@[simp] lemma coe_div_circle (z w : circle) : \u2191(z / w) = (z:\u2102) / w :=\ncircle.subtype.map_div z w\n\n/-- The elements of the circle embed into the units. -/\n@[simps apply] def circle.to_units : circle \u2192* units \u2102 := unit_sphere_to_units \u2102\n\ninstance : compact_space circle := metric.sphere.compact_space _ _\n\ninstance : topological_group circle := metric.sphere.topological_group\n\n/-- If `z` is a nonzero complex number, then `conj z / z` belongs to the unit circle. -/\n@[simps] def circle.of_conj_div_self (z : \u2102) (hz : z \u2260 0) : circle :=\n\u27e8conj z / z, mem_circle_iff_abs.2 $ by rw [complex.abs_div, abs_conj, div_self (abs_ne_zero.2 hz)]\u27e9\n\n/-- The map `\u03bb t, exp (t * I)` from `\u211d` to the unit circle in `\u2102`. -/\ndef exp_map_circle : C(\u211d, circle) :=\n{ to_fun := \u03bb t, \u27e8exp (t * I), by simp [exp_mul_I, abs_cos_add_sin_mul_I]\u27e9 }\n\n@[simp] lemma exp_map_circle_apply (t : \u211d) : \u2191(exp_map_circle t) = complex.exp (t * complex.I) :=\nrfl\n\n@[simp] lemma exp_map_circle_zero : exp_map_circle 0 = 1 :=\nsubtype.ext $ by rw [exp_map_circle_apply, of_real_zero, zero_mul, exp_zero, submonoid.coe_one]\n\n@[simp] lemma exp_map_circle_add (x y : \u211d) :\n  exp_map_circle (x + y) = exp_map_circle x * exp_map_circle y :=\nsubtype.ext $ by simp only [exp_map_circle_apply, submonoid.coe_mul, of_real_add, add_mul,\n  complex.exp_add]\n\n/-- The map `\u03bb t, exp (t * I)` from `\u211d` to the unit circle in `\u2102`, considered as a homomorphism of\ngroups. -/\n@[simps]\ndef exp_map_circle_hom : \u211d \u2192+ (additive circle) :=\n{ to_fun := additive.of_mul \u2218 exp_map_circle,\n  map_zero' := exp_map_circle_zero,\n  map_add' := exp_map_circle_add }\n\n@[simp] lemma exp_map_circle_sub (x y : \u211d) :\n  exp_map_circle (x - y) = exp_map_circle x / exp_map_circle y :=\nexp_map_circle_hom.map_sub x y\n\n@[simp] lemma exp_map_circle_neg (x : \u211d) : exp_map_circle (-x) = (exp_map_circle x)\u207b\u00b9 :=\nexp_map_circle_hom.map_neg x\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/complex/circle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.718054383461115}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module order.circular\n! leanprover-community/mathlib commit f2f413b9d4be3a02840d0663dace76e8fe3da053\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Set.Basic\n\n/-!\n# Circular order hierarchy\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines circular preorders, circular partial orders and circular orders.\n\n## Hierarchy\n\n* A ternary \"betweenness\" relation `btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` forms a `circular_order` if it is\n  - reflexive: `btw a a a`\n  - cyclic: `btw a b c \u2192 btw b c a`\n  - antisymmetric: `btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a`\n  - total: `btw a b c \u2228 btw c b a`\n  along with a strict betweenness relation `sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` which respects\n  `sbtw a b c \u2194 btw a b c \u2227 \u00ac btw c b a`, analogously to how `<` and `\u2264` are related, and is\n  - transitive: `sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c`.\n* A `circular_partial_order` drops totality.\n* A `circular_preorder` further drops antisymmetry.\n\nThe intuition is that a circular order is a circle and `btw a b c` means that going around\nclockwise from `a` you reach `b` before `c` (`b` is between `a` and `c` is meaningless on an\nunoriented circle). A circular partial order is several, potentially intersecting, circles. A\ncircular preorder is like a circular partial order, but several points can coexist.\n\nNote that the relations between `circular_preorder`, `circular_partial_order` and `circular_order`\nare subtler than between `preorder`, `partial_order`, `linear_order`. In particular, one cannot\nsimply extend the `btw` of a `circular_partial_order` to make it a `circular_order`.\n\nOne can translate from usual orders to circular ones by \"closing the necklace at infinity\". See\n`has_le.to_has_btw` and `has_lt.to_has_sbtw`. Going the other way involves \"cutting the necklace\" or\n\"rolling the necklace open\".\n\n## Examples\n\nSome concrete circular orders one encounters in the wild are `zmod n` for `0 < n`, `circle`,\n`real.angle`...\n\n## Main definitions\n\n* `set.cIcc`: Closed-closed circular interval.\n* `set.cIoo`: Open-open circular interval.\n\n## Notes\n\nThere's an unsolved diamond on `order_dual \u03b1` here. The instances `has_le \u03b1 \u2192 has_btw \u03b1\u1d52\u1d48` and\n`has_lt \u03b1 \u2192 has_sbtw \u03b1\u1d52\u1d48` can each be inferred in two ways:\n* `has_le \u03b1` \u2192 `has_btw \u03b1` \u2192 `has_btw \u03b1\u1d52\u1d48` vs\n  `has_le \u03b1` \u2192 `has_le \u03b1\u1d52\u1d48` \u2192 `has_btw \u03b1\u1d52\u1d48`\n* `has_lt \u03b1` \u2192 `has_sbtw \u03b1` \u2192 `has_sbtw \u03b1\u1d52\u1d48` vs\n  `has_lt \u03b1` \u2192 `has_lt \u03b1\u1d52\u1d48` \u2192 `has_sbtw \u03b1\u1d52\u1d48`\nThe fields are propeq, but not defeq. It is temporarily fixed by turning the circularizing instances\ninto definitions.\n\n## TODO\n\nAntisymmetry is quite weak in the sense that there's no way to discriminate which two points are\nequal. This prevents defining closed-open intervals `cIco` and `cIoc` in the neat `=`-less way. We\ncurrently haven't defined them at all.\n\nWhat is the correct generality of \"rolling the necklace\" open? At least, this works for `\u03b1 \u00d7 \u03b2` and\n`\u03b2 \u00d7 \u03b1` where `\u03b1` is a circular order and `\u03b2` is a linear order.\n\nWhat's next is to define circular groups and provide instances for `zmod n`, the usual circle group\n`circle`, `real.angle`, and `roots_of_unity M`. What conditions do we need on `M` for this last one\nto work?\n\nWe should have circular order homomorphisms. The typical example is\n`days_to_month : days_of_the_year \u2192c months_of_the_year` which relates the circular order of days\nand the circular order of months. Is `\u03b1 \u2192c \u03b2` a good notation?\n\n## References\n\n* https://en.wikipedia.org/wiki/Cyclic_order\n* https://en.wikipedia.org/wiki/Partial_cyclic_order\n\n## Tags\n\ncircular order, cyclic order, circularly ordered set, cyclically ordered set\n-/\n\n\n#print Btw /-\n/-- Syntax typeclass for a betweenness relation. -/\nclass Btw (\u03b1 : Type _) where\n  Btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop\n#align has_btw Btw\n-/\n\nexport Btw (Btw)\n\n#print SBtw /-\n/-- Syntax typeclass for a strict betweenness relation. -/\nclass SBtw (\u03b1 : Type _) where\n  Sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop\n#align has_sbtw SBtw\n-/\n\nexport SBtw (Sbtw)\n\n#print CircularPreorder /-\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic order_laws_tac -/\n/-- A circular preorder is the analogue of a preorder where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive and cyclic. `sbtw` is transitive.\n-/\nclass CircularPreorder (\u03b1 : Type _) extends Btw \u03b1, SBtw \u03b1 where\n  btw_refl (a : \u03b1) : btw a a a\n  btw_cyclic_left {a b c : \u03b1} : btw a b c \u2192 btw b c a\n  Sbtw := fun a b c => btw a b c \u2227 \u00acbtw c b a\n  sbtw_iff_btw_not_btw {a b c : \u03b1} : sbtw a b c \u2194 btw a b c \u2227 \u00acbtw c b a := by\n    run_tac\n      order_laws_tac\n  sbtw_trans_left {a b c d : \u03b1} : sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c\n#align circular_preorder CircularPreorder\n-/\n\nexport CircularPreorder (btw_refl btw_cyclic_left sbtw_trans_left)\n\n#print CircularPartialOrder /-\n/-- A circular partial order is the analogue of a partial order where you can loop around. `\u2264` and\n`<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic and\nantisymmetric. `sbtw` is transitive. -/\nclass CircularPartialOrder (\u03b1 : Type _) extends CircularPreorder \u03b1 where\n  btw_antisymm {a b c : \u03b1} : btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a\n#align circular_partial_order CircularPartialOrder\n-/\n\nexport CircularPartialOrder (btw_antisymm)\n\n#print CircularOrder /-\n/-- A circular order is the analogue of a linear order where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic, antisymmetric and total.\n`sbtw` is transitive. -/\nclass CircularOrder (\u03b1 : Type _) extends CircularPartialOrder \u03b1 where\n  btw_total : \u2200 a b c : \u03b1, btw a b c \u2228 btw c b a\n#align circular_order CircularOrder\n-/\n\nexport CircularOrder (btw_total)\n\n/-! ### Circular preorders -/\n\n\nsection CircularPreorder\n\nvariable {\u03b1 : Type _} [CircularPreorder \u03b1]\n\n#print btw_rfl /-\ntheorem btw_rfl {a : \u03b1} : Btw a a a :=\n  btw_refl _\n#align btw_rfl btw_rfl\n-/\n\n#print Btw.btw.cyclic_left /-\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_cyclic_left        \u2190 has_btw.btw.cyclic_left\ntheorem Btw.btw.cyclic_left {a b c : \u03b1} (h : Btw a b c) : Btw b c a :=\n  btw_cyclic_left h\n#align has_btw.btw.cyclic_left Btw.btw.cyclic_left\n-/\n\n#print btw_cyclic_right /-\ntheorem btw_cyclic_right {a b c : \u03b1} (h : Btw a b c) : Btw c a b :=\n  h.cyclic_left.cyclic_left\n#align btw_cyclic_right btw_cyclic_right\n-/\n\nalias btw_cyclic_right \u2190 Btw.btw.cyclic_right\n#align has_btw.btw.cyclic_right Btw.btw.cyclic_right\n\n#print btw_cyclic /-\n/-- The order of the `\u2194` has been chosen so that `rw btw_cyclic` cycles to the right while\n`rw \u2190btw_cyclic` cycles to the left (thus following the prepended arrow). -/\ntheorem btw_cyclic {a b c : \u03b1} : Btw a b c \u2194 Btw c a b :=\n  \u27e8btw_cyclic_right, btw_cyclic_left\u27e9\n#align btw_cyclic btw_cyclic\n-/\n\n#print sbtw_iff_btw_not_btw /-\ntheorem sbtw_iff_btw_not_btw {a b c : \u03b1} : Sbtw a b c \u2194 Btw a b c \u2227 \u00acBtw c b a :=\n  CircularPreorder.sbtw_iff_btw_not_btw\n#align sbtw_iff_btw_not_btw sbtw_iff_btw_not_btw\n-/\n\n#print btw_of_sbtw /-\ntheorem btw_of_sbtw {a b c : \u03b1} (h : Sbtw a b c) : Btw a b c :=\n  (sbtw_iff_btw_not_btw.1 h).1\n#align btw_of_sbtw btw_of_sbtw\n-/\n\nalias btw_of_sbtw \u2190 SBtw.sbtw.btw\n#align has_sbtw.sbtw.btw SBtw.sbtw.btw\n\n#print not_btw_of_sbtw /-\ntheorem not_btw_of_sbtw {a b c : \u03b1} (h : Sbtw a b c) : \u00acBtw c b a :=\n  (sbtw_iff_btw_not_btw.1 h).2\n#align not_btw_of_sbtw not_btw_of_sbtw\n-/\n\nalias not_btw_of_sbtw \u2190 SBtw.sbtw.not_btw\n#align has_sbtw.sbtw.not_btw SBtw.sbtw.not_btw\n\n#print not_sbtw_of_btw /-\ntheorem not_sbtw_of_btw {a b c : \u03b1} (h : Btw a b c) : \u00acSbtw c b a := fun h' => h'.not_btw h\n#align not_sbtw_of_btw not_sbtw_of_btw\n-/\n\nalias not_sbtw_of_btw \u2190 Btw.btw.not_sbtw\n#align has_btw.btw.not_sbtw Btw.btw.not_sbtw\n\n#print sbtw_of_btw_not_btw /-\ntheorem sbtw_of_btw_not_btw {a b c : \u03b1} (habc : Btw a b c) (hcba : \u00acBtw c b a) : Sbtw a b c :=\n  sbtw_iff_btw_not_btw.2 \u27e8habc, hcba\u27e9\n#align sbtw_of_btw_not_btw sbtw_of_btw_not_btw\n-/\n\nalias sbtw_of_btw_not_btw \u2190 Btw.btw.sbtw_of_not_btw\n#align has_btw.btw.sbtw_of_not_btw Btw.btw.sbtw_of_not_btw\n\n#print sbtw_cyclic_left /-\ntheorem sbtw_cyclic_left {a b c : \u03b1} (h : Sbtw a b c) : Sbtw b c a :=\n  h.Btw.cyclic_left.sbtw_of_not_btw fun h' => h.not_btw h'.cyclic_left\n#align sbtw_cyclic_left sbtw_cyclic_left\n-/\n\nalias sbtw_cyclic_left \u2190 SBtw.sbtw.cyclic_left\n#align has_sbtw.sbtw.cyclic_left SBtw.sbtw.cyclic_left\n\n#print sbtw_cyclic_right /-\ntheorem sbtw_cyclic_right {a b c : \u03b1} (h : Sbtw a b c) : Sbtw c a b :=\n  h.cyclic_left.cyclic_left\n#align sbtw_cyclic_right sbtw_cyclic_right\n-/\n\nalias sbtw_cyclic_right \u2190 SBtw.sbtw.cyclic_right\n#align has_sbtw.sbtw.cyclic_right SBtw.sbtw.cyclic_right\n\n#print sbtw_cyclic /-\n/-- The order of the `\u2194` has been chosen so that `rw sbtw_cyclic` cycles to the right while\n`rw \u2190sbtw_cyclic` cycles to the left (thus following the prepended arrow). -/\ntheorem sbtw_cyclic {a b c : \u03b1} : Sbtw a b c \u2194 Sbtw c a b :=\n  \u27e8sbtw_cyclic_right, sbtw_cyclic_left\u27e9\n#align sbtw_cyclic sbtw_cyclic\n-/\n\n#print SBtw.sbtw.trans_left /-\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_trans_left        \u2190 has_btw.btw.trans_left\ntheorem SBtw.sbtw.trans_left {a b c d : \u03b1} (h : Sbtw a b c) : Sbtw b d c \u2192 Sbtw a d c :=\n  sbtw_trans_left h\n#align has_sbtw.sbtw.trans_left SBtw.sbtw.trans_left\n-/\n\n#print sbtw_trans_right /-\ntheorem sbtw_trans_right {a b c d : \u03b1} (hbc : Sbtw a b c) (hcd : Sbtw a c d) : Sbtw a b d :=\n  (hbc.cyclic_left.trans_left hcd.cyclic_left).cyclic_right\n#align sbtw_trans_right sbtw_trans_right\n-/\n\nalias sbtw_trans_right \u2190 SBtw.sbtw.trans_right\n#align has_sbtw.sbtw.trans_right SBtw.sbtw.trans_right\n\n#print sbtw_asymm /-\ntheorem sbtw_asymm {a b c : \u03b1} (h : Sbtw a b c) : \u00acSbtw c b a :=\n  h.Btw.not_sbtw\n#align sbtw_asymm sbtw_asymm\n-/\n\nalias sbtw_asymm \u2190 SBtw.sbtw.not_sbtw\n#align has_sbtw.sbtw.not_sbtw SBtw.sbtw.not_sbtw\n\n#print sbtw_irrefl_left_right /-\ntheorem sbtw_irrefl_left_right {a b : \u03b1} : \u00acSbtw a b a := fun h => h.not_btw h.Btw\n#align sbtw_irrefl_left_right sbtw_irrefl_left_right\n-/\n\n#print sbtw_irrefl_left /-\ntheorem sbtw_irrefl_left {a b : \u03b1} : \u00acSbtw a a b := fun h => sbtw_irrefl_left_right h.cyclic_left\n#align sbtw_irrefl_left sbtw_irrefl_left\n-/\n\n#print sbtw_irrefl_right /-\ntheorem sbtw_irrefl_right {a b : \u03b1} : \u00acSbtw a b b := fun h => sbtw_irrefl_left_right h.cyclic_right\n#align sbtw_irrefl_right sbtw_irrefl_right\n-/\n\n#print sbtw_irrefl /-\ntheorem sbtw_irrefl (a : \u03b1) : \u00acSbtw a a a :=\n  sbtw_irrefl_left_right\n#align sbtw_irrefl sbtw_irrefl\n-/\n\nend CircularPreorder\n\n/-! ### Circular partial orders -/\n\n\nsection CircularPartialOrder\n\nvariable {\u03b1 : Type _} [CircularPartialOrder \u03b1]\n\n#print Btw.btw.antisymm /-\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_antisymm        \u2190 has_btw.btw.antisymm\ntheorem Btw.btw.antisymm {a b c : \u03b1} (h : Btw a b c) : Btw c b a \u2192 a = b \u2228 b = c \u2228 c = a :=\n  btw_antisymm h\n#align has_btw.btw.antisymm Btw.btw.antisymm\n-/\n\nend CircularPartialOrder\n\n/-! ### Circular orders -/\n\n\nsection CircularOrder\n\nvariable {\u03b1 : Type _} [CircularOrder \u03b1]\n\n#print btw_refl_left_right /-\ntheorem btw_refl_left_right (a b : \u03b1) : Btw a b a :=\n  (or_self_iff _).1 (btw_total a b a)\n#align btw_refl_left_right btw_refl_left_right\n-/\n\n#print btw_rfl_left_right /-\ntheorem btw_rfl_left_right {a b : \u03b1} : Btw a b a :=\n  btw_refl_left_right _ _\n#align btw_rfl_left_right btw_rfl_left_right\n-/\n\n#print btw_refl_left /-\ntheorem btw_refl_left (a b : \u03b1) : Btw a a b :=\n  btw_rfl_left_right.cyclic_right\n#align btw_refl_left btw_refl_left\n-/\n\n#print btw_rfl_left /-\ntheorem btw_rfl_left {a b : \u03b1} : Btw a a b :=\n  btw_refl_left _ _\n#align btw_rfl_left btw_rfl_left\n-/\n\n#print btw_refl_right /-\ntheorem btw_refl_right (a b : \u03b1) : Btw a b b :=\n  btw_rfl_left_right.cyclic_left\n#align btw_refl_right btw_refl_right\n-/\n\n#print btw_rfl_right /-\ntheorem btw_rfl_right {a b : \u03b1} : Btw a b b :=\n  btw_refl_right _ _\n#align btw_rfl_right btw_rfl_right\n-/\n\n#print sbtw_iff_not_btw /-\ntheorem sbtw_iff_not_btw {a b c : \u03b1} : Sbtw a b c \u2194 \u00acBtw c b a :=\n  by\n  rw [sbtw_iff_btw_not_btw]\n  exact and_iff_right_of_imp (btw_total _ _ _).resolve_left\n#align sbtw_iff_not_btw sbtw_iff_not_btw\n-/\n\n#print btw_iff_not_sbtw /-\ntheorem btw_iff_not_sbtw {a b c : \u03b1} : Btw a b c \u2194 \u00acSbtw c b a :=\n  iff_not_comm.1 sbtw_iff_not_btw\n#align btw_iff_not_sbtw btw_iff_not_sbtw\n-/\n\nend CircularOrder\n\n/-! ### Circular intervals -/\n\n\nnamespace Set\n\nsection CircularPreorder\n\nvariable {\u03b1 : Type _} [CircularPreorder \u03b1]\n\n#print Set.cIcc /-\n/-- Closed-closed circular interval -/\ndef cIcc (a b : \u03b1) : Set \u03b1 :=\n  { x | Btw a x b }\n#align set.cIcc Set.cIcc\n-/\n\n#print Set.cIoo /-\n/-- Open-open circular interval -/\ndef cIoo (a b : \u03b1) : Set \u03b1 :=\n  { x | Sbtw a x b }\n#align set.cIoo Set.cIoo\n-/\n\n#print Set.mem_cIcc /-\n@[simp]\ntheorem mem_cIcc {a b x : \u03b1} : x \u2208 cIcc a b \u2194 Btw a x b :=\n  Iff.rfl\n#align set.mem_cIcc Set.mem_cIcc\n-/\n\n#print Set.mem_cIoo /-\n@[simp]\ntheorem mem_cIoo {a b x : \u03b1} : x \u2208 cIoo a b \u2194 Sbtw a x b :=\n  Iff.rfl\n#align set.mem_cIoo Set.mem_cIoo\n-/\n\nend CircularPreorder\n\nsection CircularOrder\n\nvariable {\u03b1 : Type _} [CircularOrder \u03b1]\n\n#print Set.left_mem_cIcc /-\ntheorem left_mem_cIcc (a b : \u03b1) : a \u2208 cIcc a b :=\n  btw_rfl_left\n#align set.left_mem_cIcc Set.left_mem_cIcc\n-/\n\n#print Set.right_mem_cIcc /-\ntheorem right_mem_cIcc (a b : \u03b1) : b \u2208 cIcc a b :=\n  btw_rfl_right\n#align set.right_mem_cIcc Set.right_mem_cIcc\n-/\n\n/- warning: set.compl_cIcc -> Set.compl_cIcc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CircularOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) (Set.cIcc.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) a b)) (Set.cIoo.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) b a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CircularOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.instBooleanAlgebraSet.{u1} \u03b1)) (Set.cIcc.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) a b)) (Set.cIoo.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) b a)\nCase conversion may be inaccurate. Consider using '#align set.compl_cIcc Set.compl_cIcc\u2093'. -/\ntheorem compl_cIcc {a b : \u03b1} : cIcc a b\u1d9c = cIoo b a :=\n  by\n  ext\n  rw [Set.mem_cIoo, sbtw_iff_not_btw]\n  rfl\n#align set.compl_cIcc Set.compl_cIcc\n\n/- warning: set.compl_cIoo -> Set.compl_cIoo is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CircularOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) (Set.cIoo.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) a b)) (Set.cIcc.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) b a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CircularOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.instBooleanAlgebraSet.{u1} \u03b1)) (Set.cIoo.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) a b)) (Set.cIcc.{u1} \u03b1 (CircularPartialOrder.toCircularPreorder.{u1} \u03b1 (CircularOrder.toCircularPartialOrder.{u1} \u03b1 _inst_1)) b a)\nCase conversion may be inaccurate. Consider using '#align set.compl_cIoo Set.compl_cIoo\u2093'. -/\ntheorem compl_cIoo {a b : \u03b1} : cIoo a b\u1d9c = cIcc b a :=\n  by\n  ext\n  rw [Set.mem_cIcc, btw_iff_not_sbtw]\n  rfl\n#align set.compl_cIoo Set.compl_cIoo\n\nend CircularOrder\n\nend Set\n\n/-! ### Circularizing instances -/\n\n\n#print LE.toBtw /-\n/-- The betweenness relation obtained from \"looping around\" `\u2264`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef LE.toBtw (\u03b1 : Type _) [LE \u03b1] : Btw \u03b1\n    where Btw a b c := a \u2264 b \u2227 b \u2264 c \u2228 b \u2264 c \u2227 c \u2264 a \u2228 c \u2264 a \u2227 a \u2264 b\n#align has_le.to_has_btw LE.toBtw\n-/\n\n#print LT.toSBtw /-\n/-- The strict betweenness relation obtained from \"looping around\" `<`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef LT.toSBtw (\u03b1 : Type _) [LT \u03b1] : SBtw \u03b1\n    where Sbtw a b c := a < b \u2227 b < c \u2228 b < c \u2227 c < a \u2228 c < a \u2227 a < b\n#align has_lt.to_has_sbtw LT.toSBtw\n-/\n\n#print Preorder.toCircularPreorder /-\n/-- The circular preorder obtained from \"looping around\" a preorder.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef Preorder.toCircularPreorder (\u03b1 : Type _) [Preorder \u03b1] : CircularPreorder \u03b1\n    where\n  Btw a b c := a \u2264 b \u2227 b \u2264 c \u2228 b \u2264 c \u2227 c \u2264 a \u2228 c \u2264 a \u2227 a \u2264 b\n  Sbtw a b c := a < b \u2227 b < c \u2228 b < c \u2227 c < a \u2228 c < a \u2227 a < b\n  btw_refl a := Or.inl \u27e8le_rfl, le_rfl\u27e9\n  btw_cyclic_left a b c h := by\n    unfold btw at h\u22a2\n    rwa [\u2190 or_assoc, or_comm']\n  sbtw_trans_left a b c d :=\n    by\n    rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hbd, hdc\u27e9 | \u27e8hdc, hcb\u27e9 | \u27e8hcb, hbd\u27e9)\n    \u00b7 exact Or.inl \u27e8hab.trans hbd, hdc\u27e9\n    \u00b7 exact (hbc.not_lt hcb).elim\n    \u00b7 exact (hbc.not_lt hcb).elim\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact (hbc.not_lt hcb).elim\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact Or.inr (Or.inl \u27e8hdc, hca\u27e9)\n    \u00b7 exact Or.inr (Or.inr \u27e8hca, hab.trans hbd\u27e9)\n  sbtw_iff_btw_not_btw a b c := by\n    simp_rw [lt_iff_le_not_le]\n    set x\u2080 := a \u2264 b\n    set x\u2081 := b \u2264 c\n    set x\u2082 := c \u2264 a\n    have : x\u2080 \u2192 x\u2081 \u2192 a \u2264 c := le_trans\n    have : x\u2081 \u2192 x\u2082 \u2192 b \u2264 a := le_trans\n    have : x\u2082 \u2192 x\u2080 \u2192 c \u2264 b := le_trans\n    clear_value x\u2080 x\u2081 x\u2082\n    tauto\n#align preorder.to_circular_preorder Preorder.toCircularPreorder\n-/\n\n#print PartialOrder.toCircularPartialOrder /-\n/-- The circular partial order obtained from \"looping around\" a partial order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef PartialOrder.toCircularPartialOrder (\u03b1 : Type _) [PartialOrder \u03b1] : CircularPartialOrder \u03b1 :=\n  { Preorder.toCircularPreorder \u03b1 with\n    btw_antisymm := fun a b c =>\n      by\n      rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hcb, hba\u27e9 | \u27e8hba, hac\u27e9 | \u27e8hac, hcb\u27e9)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inr (Or.inl <| hbc.antisymm hcb)\n      \u00b7 exact Or.inr (Or.inl <| hbc.antisymm hcb)\n      \u00b7 exact Or.inr (Or.inr <| hca.antisymm hac)\n      \u00b7 exact Or.inr (Or.inl <| hbc.antisymm hcb)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inl (hab.antisymm hba)\n      \u00b7 exact Or.inr (Or.inr <| hca.antisymm hac) }\n#align partial_order.to_circular_partial_order PartialOrder.toCircularPartialOrder\n-/\n\n#print LinearOrder.toCircularOrder /-\n/-- The circular order obtained from \"looping around\" a linear order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef LinearOrder.toCircularOrder (\u03b1 : Type _) [LinearOrder \u03b1] : CircularOrder \u03b1 :=\n  { PartialOrder.toCircularPartialOrder \u03b1 with\n    btw_total := fun a b c =>\n      by\n      cases' le_total a b with hab hba <;> cases' le_total b c with hbc hcb <;>\n        cases' le_total c a with hca hac\n      \u00b7 exact Or.inl (Or.inl \u27e8hab, hbc\u27e9)\n      \u00b7 exact Or.inl (Or.inl \u27e8hab, hbc\u27e9)\n      \u00b7 exact Or.inl (Or.inr <| Or.inr \u27e8hca, hab\u27e9)\n      \u00b7 exact Or.inr (Or.inr <| Or.inr \u27e8hac, hcb\u27e9)\n      \u00b7 exact Or.inl (Or.inr <| Or.inl \u27e8hbc, hca\u27e9)\n      \u00b7 exact Or.inr (Or.inr <| Or.inl \u27e8hba, hac\u27e9)\n      \u00b7 exact Or.inr (Or.inl \u27e8hcb, hba\u27e9)\n      \u00b7 exact Or.inr (Or.inr <| Or.inl \u27e8hba, hac\u27e9) }\n#align linear_order.to_circular_order LinearOrder.toCircularOrder\n-/\n\n/-! ### Dual constructions -/\n\n\nsection OrderDual\n\ninstance (\u03b1 : Type _) [Btw \u03b1] : Btw \u03b1\u1d52\u1d48 :=\n  \u27e8fun a b c : \u03b1 => Btw c b a\u27e9\n\ninstance (\u03b1 : Type _) [SBtw \u03b1] : SBtw \u03b1\u1d52\u1d48 :=\n  \u27e8fun a b c : \u03b1 => Sbtw c b a\u27e9\n\ninstance (\u03b1 : Type _) [h : CircularPreorder \u03b1] : CircularPreorder \u03b1\u1d52\u1d48 :=\n  { OrderDual.hasBtw \u03b1,\n    OrderDual.hasSbtw \u03b1 with\n    btw_refl := btw_refl\n    btw_cyclic_left := fun a b c => btw_cyclic_right\n    sbtw_trans_left := fun a b c d habc hbdc => hbdc.trans_right habc\n    sbtw_iff_btw_not_btw := fun a b c => @sbtw_iff_btw_not_btw \u03b1 _ c b a }\n\ninstance (\u03b1 : Type _) [CircularPartialOrder \u03b1] : CircularPartialOrder \u03b1\u1d52\u1d48 :=\n  { OrderDual.circularPreorder \u03b1 with\n    btw_antisymm := fun a b c habc hcba => @btw_antisymm \u03b1 _ _ _ _ hcba habc }\n\ninstance (\u03b1 : Type _) [CircularOrder \u03b1] : CircularOrder \u03b1\u1d52\u1d48 :=\n  { OrderDual.circularPartialOrder \u03b1 with btw_total := fun a b c => btw_total c b a }\n\nend OrderDual\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/Circular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7180543828871933}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport geometry.euclidean.circumcenter\n\n/-!\n# Monge point and orthocenter\n\nThis file defines the orthocenter of a triangle, via its n-dimensional\ngeneralization, the Monge point of a simplex.\n\n## Main definitions\n\n* `monge_point` is the Monge point of a simplex, defined in terms of\n  its position on the Euler line and then shown to be the point of\n  concurrence of the Monge planes.\n\n* `monge_plane` is a Monge plane of an (n+2)-simplex, which is the\n  (n+1)-dimensional affine subspace of the subspace spanned by the\n  simplex that passes through the centroid of an n-dimensional face\n  and is orthogonal to the opposite edge (in 2 dimensions, this is the\n  same as an altitude).\n\n* `altitude` is the line that passes through a vertex of a simplex and\n  is orthogonal to the opposite face.\n\n* `orthocenter` is defined, for the case of a triangle, to be the same\n  as its Monge point, then shown to be the point of concurrence of the\n  altitudes.\n\n* `orthocentric_system` is a predicate on sets of points that says\n  whether they are four points, one of which is the orthocenter of the\n  other three (in which case various other properties hold, including\n  that each is the orthocenter of the other three).\n\n## References\n\n* <https://en.wikipedia.org/wiki/Altitude_(triangle)>\n* <https://en.wikipedia.org/wiki/Monge_point>\n* <https://en.wikipedia.org/wiki/Orthocentric_system>\n* Ma\u0142gorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point\n  Sphere of an\n  n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf)\n\n-/\n\nnoncomputable theory\nopen_locale big_operators\nopen_locale classical\nopen_locale real_inner_product_space\n\nnamespace affine\n\nnamespace simplex\n\nopen finset affine_subspace euclidean_geometry points_with_circumcenter_index\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\ninclude V\n\n/-- The Monge point of a simplex (in 2 or more dimensions) is a\ngeneralization of the orthocenter of a triangle.  It is defined to be\nthe intersection of the Monge planes, where a Monge plane is the\n(n-1)-dimensional affine subspace of the subspace spanned by the\nsimplex that passes through the centroid of an (n-2)-dimensional face\nand is orthogonal to the opposite edge (in 2 dimensions, this is the\nsame as an altitude).  The circumcenter O, centroid G and Monge point\nM are collinear in that order on the Euler line, with OG : GM = (n-1)\n: 2.  Here, we use that ratio to define the Monge point (so resulting\nin a point that equals the centroid in 0 or 1 dimensions), and then\nshow in subsequent lemmas that the point so defined lies in the Monge\nplanes and is their unique point of intersection. -/\ndef monge_point {n : \u2115} (s : simplex \u211d P n) : P :=\n(((n + 1 : \u2115) : \u211d) / (((n - 1) : \u2115) : \u211d)) \u2022\n  ((univ : finset (fin (n + 1))).centroid \u211d s.points -\u1d65 s.circumcenter) +\u1d65\n  s.circumcenter\n\n/-- The position of the Monge point in relation to the circumcenter\nand centroid. -/\nlemma monge_point_eq_smul_vsub_vadd_circumcenter {n : \u2115} (s : simplex \u211d P n) :\n  s.monge_point = (((n + 1 : \u2115) : \u211d) / (((n - 1) : \u2115) : \u211d)) \u2022\n    ((univ : finset (fin (n + 1))).centroid \u211d s.points -\u1d65 s.circumcenter) +\u1d65\n    s.circumcenter :=\nrfl\n\n/-- The Monge point lies in the affine span. -/\nlemma monge_point_mem_affine_span {n : \u2115} (s : simplex \u211d P n) :\n  s.monge_point \u2208 affine_span \u211d (set.range s.points) :=\nsmul_vsub_vadd_mem _ _\n  (centroid_mem_affine_span_of_card_eq_add_one \u211d _ (card_fin (n + 1)))\n  s.circumcenter_mem_affine_span\n  s.circumcenter_mem_affine_span\n\n/-- Two simplices with the same points have the same Monge point. -/\nlemma monge_point_eq_of_range_eq {n : \u2115} {s\u2081 s\u2082 : simplex \u211d P n}\n  (h : set.range s\u2081.points = set.range s\u2082.points) : s\u2081.monge_point = s\u2082.monge_point :=\nby simp_rw [monge_point_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h,\n            circumcenter_eq_of_range_eq h]\n\nomit V\n\n/-- The weights for the Monge point of an (n+2)-simplex, in terms of\n`points_with_circumcenter`. -/\ndef monge_point_weights_with_circumcenter (n : \u2115) : points_with_circumcenter_index (n + 2) \u2192 \u211d\n| (point_index i) := (((n + 1) : \u2115) : \u211d)\u207b\u00b9\n| circumcenter_index := (-2 / (((n + 1) : \u2115) : \u211d))\n\n/-- `monge_point_weights_with_circumcenter` sums to 1. -/\n@[simp] lemma sum_monge_point_weights_with_circumcenter (n : \u2115) :\n  \u2211 i, monge_point_weights_with_circumcenter n i = 1 :=\nbegin\n  simp_rw [sum_points_with_circumcenter, monge_point_weights_with_circumcenter, sum_const,\n           card_fin, nsmul_eq_mul],\n  have hn1 : (n + 1 : \u211d) \u2260 0,\n  { exact_mod_cast nat.succ_ne_zero _ },\n  field_simp [hn1],\n  ring\nend\n\ninclude V\n\n/-- The Monge point of an (n+2)-simplex, in terms of\n`points_with_circumcenter`. -/\nlemma monge_point_eq_affine_combination_of_points_with_circumcenter {n : \u2115}\n  (s : simplex \u211d P (n + 2)) :\n  s.monge_point = (univ : finset (points_with_circumcenter_index (n + 2))).affine_combination \u211d\n    s.points_with_circumcenter (monge_point_weights_with_circumcenter n) :=\nbegin\n  rw [monge_point_eq_smul_vsub_vadd_circumcenter,\n      centroid_eq_affine_combination_of_points_with_circumcenter,\n      circumcenter_eq_affine_combination_of_points_with_circumcenter,\n      affine_combination_vsub, \u2190linear_map.map_smul,\n      weighted_vsub_vadd_affine_combination],\n  congr' with i,\n  rw [pi.add_apply, pi.smul_apply, smul_eq_mul, pi.sub_apply],\n  have hn1 : (n + 1 : \u211d) \u2260 0,\n  { exact_mod_cast nat.succ_ne_zero _ },\n  cases i;\n    simp_rw [centroid_weights_with_circumcenter, circumcenter_weights_with_circumcenter,\n             monge_point_weights_with_circumcenter];\n    rw [add_tsub_assoc_of_le (dec_trivial : 1 \u2264 2), (dec_trivial : 2 - 1 = 1)],\n  { rw [if_pos (mem_univ _), sub_zero, add_zero, card_fin],\n    have hn3 : (n + 2 + 1 : \u211d) \u2260 0,\n    { exact_mod_cast nat.succ_ne_zero _ },\n    field_simp [hn1, hn3, mul_comm] },\n  { field_simp [hn1],\n    ring }\nend\n\nomit V\n\n/-- The weights for the Monge point of an (n+2)-simplex, minus the\ncentroid of an n-dimensional face, in terms of\n`points_with_circumcenter`.  This definition is only valid when `i\u2081 \u2260 i\u2082`. -/\ndef monge_point_vsub_face_centroid_weights_with_circumcenter {n : \u2115} (i\u2081 i\u2082 : fin (n + 3)) :\n  points_with_circumcenter_index (n + 2) \u2192 \u211d\n| (point_index i) := if i = i\u2081 \u2228 i = i\u2082 then (((n + 1) : \u2115) : \u211d)\u207b\u00b9 else 0\n| circumcenter_index := (-2 / (((n + 1) : \u2115) : \u211d))\n\n/-- `monge_point_vsub_face_centroid_weights_with_circumcenter` is the\nresult of subtracting `centroid_weights_with_circumcenter` from\n`monge_point_weights_with_circumcenter`. -/\nlemma monge_point_vsub_face_centroid_weights_with_circumcenter_eq_sub {n : \u2115}\n  {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  monge_point_vsub_face_centroid_weights_with_circumcenter i\u2081 i\u2082 =\n    monge_point_weights_with_circumcenter n -\n      centroid_weights_with_circumcenter ({i\u2081, i\u2082}\u1d9c) :=\nbegin\n  ext i,\n  cases i,\n  { rw [pi.sub_apply, monge_point_weights_with_circumcenter, centroid_weights_with_circumcenter,\n        monge_point_vsub_face_centroid_weights_with_circumcenter],\n    have hu : card ({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))) = n + 1,\n    { simp [card_compl, fintype.card_fin, h] },\n    rw hu,\n    by_cases hi : i = i\u2081 \u2228 i = i\u2082;\n      simp [compl_eq_univ_sdiff, hi] },\n  { simp [monge_point_weights_with_circumcenter, centroid_weights_with_circumcenter,\n          monge_point_vsub_face_centroid_weights_with_circumcenter] }\nend\n\n/-- `monge_point_vsub_face_centroid_weights_with_circumcenter` sums to 0. -/\n@[simp] lemma sum_monge_point_vsub_face_centroid_weights_with_circumcenter {n : \u2115}\n  {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  \u2211 i, monge_point_vsub_face_centroid_weights_with_circumcenter i\u2081 i\u2082 i = 0 :=\nbegin\n  rw monge_point_vsub_face_centroid_weights_with_circumcenter_eq_sub h,\n  simp_rw [pi.sub_apply, sum_sub_distrib, sum_monge_point_weights_with_circumcenter],\n  rw [sum_centroid_weights_with_circumcenter, sub_self],\n  simp [\u2190card_pos, card_compl, h]\nend\n\ninclude V\n\n/-- The Monge point of an (n+2)-simplex, minus the centroid of an\nn-dimensional face, in terms of `points_with_circumcenter`. -/\nlemma monge_point_vsub_face_centroid_eq_weighted_vsub_of_points_with_circumcenter {n : \u2115}\n  (s : simplex \u211d P (n + 2)) {i\u2081 i\u2082 : fin (n + 3)} (h : i\u2081 \u2260 i\u2082) :\n  s.monge_point -\u1d65 ({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points =\n    (univ : finset (points_with_circumcenter_index (n + 2))).weighted_vsub\n      s.points_with_circumcenter (monge_point_vsub_face_centroid_weights_with_circumcenter i\u2081 i\u2082) :=\nby simp_rw [monge_point_eq_affine_combination_of_points_with_circumcenter,\n            centroid_eq_affine_combination_of_points_with_circumcenter,\n            affine_combination_vsub,\n            monge_point_vsub_face_centroid_weights_with_circumcenter_eq_sub h]\n\n/-- The Monge point of an (n+2)-simplex, minus the centroid of an\nn-dimensional face, is orthogonal to the difference of the two\nvertices not in that face. -/\nlemma inner_monge_point_vsub_face_centroid_vsub {n : \u2115} (s : simplex \u211d P (n + 2))\n  {i\u2081 i\u2082 : fin (n + 3)} :\n  \u27eas.monge_point -\u1d65 ({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points,\n        s.points i\u2081 -\u1d65 s.points i\u2082\u27eb = 0 :=\nbegin\n  by_cases h : i\u2081 = i\u2082,\n  { simp [h], },\n  simp_rw [monge_point_vsub_face_centroid_eq_weighted_vsub_of_points_with_circumcenter s h,\n           point_eq_affine_combination_of_points_with_circumcenter,\n           affine_combination_vsub],\n  have hs : \u2211 i, (point_weights_with_circumcenter i\u2081 - point_weights_with_circumcenter i\u2082) i = 0,\n  { simp },\n  rw [inner_weighted_vsub _ (sum_monge_point_vsub_face_centroid_weights_with_circumcenter h) _ hs,\n      sum_points_with_circumcenter, points_with_circumcenter_eq_circumcenter],\n  simp only [monge_point_vsub_face_centroid_weights_with_circumcenter,\n             points_with_circumcenter_point],\n  let fs : finset (fin (n + 3)) := {i\u2081, i\u2082},\n  have hfs : \u2200 i : fin (n + 3),\n    i \u2209 fs \u2192 (i \u2260 i\u2081 \u2227 i \u2260 i\u2082),\n  { intros i hi,\n    split ; { intro hj, simpa [\u2190hj] using hi } },\n  rw \u2190sum_subset fs.subset_univ _,\n  { simp_rw [sum_points_with_circumcenter, points_with_circumcenter_eq_circumcenter,\n             points_with_circumcenter_point, pi.sub_apply, point_weights_with_circumcenter],\n    rw [\u2190sum_subset fs.subset_univ _],\n    { simp_rw [sum_insert (not_mem_singleton.2 h), sum_singleton],\n      repeat { rw \u2190sum_subset fs.subset_univ _ },\n      { simp_rw [sum_insert (not_mem_singleton.2 h), sum_singleton],\n        simp [h, ne.symm h, dist_comm (s.points i\u2081)] },\n      all_goals { intros i hu hi, simp [hfs i hi] } },\n    { intros i hu hi,\n      simp [hfs i hi, point_weights_with_circumcenter] } },\n  { intros i hu hi,\n    simp [hfs i hi] }\nend\n\n/-- A Monge plane of an (n+2)-simplex is the (n+1)-dimensional affine\nsubspace of the subspace spanned by the simplex that passes through\nthe centroid of an n-dimensional face and is orthogonal to the\nopposite edge (in 2 dimensions, this is the same as an altitude).\nThis definition is only intended to be used when `i\u2081 \u2260 i\u2082`. -/\ndef monge_plane {n : \u2115} (s : simplex \u211d P (n + 2)) (i\u2081 i\u2082 : fin (n + 3)) :\n  affine_subspace \u211d P :=\nmk' (({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points)\n  (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293\n    affine_span \u211d (set.range s.points)\n\n/-- The definition of a Monge plane. -/\nlemma monge_plane_def {n : \u2115} (s : simplex \u211d P (n + 2)) (i\u2081 i\u2082 : fin (n + 3)) :\n  s.monge_plane i\u2081 i\u2082 = mk' (({i\u2081, i\u2082}\u1d9c : finset (fin (n + 3))).centroid \u211d s.points)\n                            (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293\n                          affine_span \u211d (set.range s.points) :=\nrfl\n\n/-- The Monge plane associated with vertices `i\u2081` and `i\u2082` equals that\nassociated with `i\u2082` and `i\u2081`. -/\nlemma monge_plane_comm {n : \u2115} (s : simplex \u211d P (n + 2)) (i\u2081 i\u2082 : fin (n + 3)) :\n  s.monge_plane i\u2081 i\u2082 = s.monge_plane i\u2082 i\u2081 :=\nbegin\n  simp_rw monge_plane_def,\n  congr' 3,\n  { congr' 1,\n    exact pair_comm _ _ },\n  { ext,\n    simp_rw submodule.mem_span_singleton,\n    split,\n    all_goals { rintros \u27e8r, rfl\u27e9, use -r, rw [neg_smul, \u2190smul_neg, neg_vsub_eq_vsub_rev] } }\nend\n\n/-- The Monge point lies in the Monge planes. -/\nlemma monge_point_mem_monge_plane {n : \u2115} (s : simplex \u211d P (n + 2)) {i\u2081 i\u2082 : fin (n + 3)} :\n  s.monge_point \u2208 s.monge_plane i\u2081 i\u2082 :=\nbegin\n  rw [monge_plane_def, mem_inf_iff, \u2190vsub_right_mem_direction_iff_mem (self_mem_mk' _ _),\n      direction_mk', submodule.mem_orthogonal'],\n  refine \u27e8_, s.monge_point_mem_affine_span\u27e9,\n  intros v hv,\n  rcases submodule.mem_span_singleton.mp hv with \u27e8r, rfl\u27e9,\n  rw [inner_smul_right, s.inner_monge_point_vsub_face_centroid_vsub, mul_zero]\nend\n\n/-- The direction of a Monge plane. -/\nlemma direction_monge_plane {n : \u2115} (s : simplex \u211d P (n + 2)) {i\u2081 i\u2082 : fin (n + 3)} :\n  (s.monge_plane i\u2081 i\u2082).direction = (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293\n    vector_span \u211d (set.range s.points) :=\nby rw [monge_plane_def, direction_inf_of_mem_inf s.monge_point_mem_monge_plane, direction_mk',\n       direction_affine_span]\n\n/-- The Monge point is the only point in all the Monge planes from any\none vertex. -/\nlemma eq_monge_point_of_forall_mem_monge_plane {n : \u2115} {s : simplex \u211d P (n + 2)}\n  {i\u2081 : fin (n + 3)} {p : P} (h : \u2200 i\u2082, i\u2081 \u2260 i\u2082 \u2192 p \u2208 s.monge_plane i\u2081 i\u2082) :\n  p = s.monge_point :=\nbegin\n  rw \u2190@vsub_eq_zero_iff_eq V,\n  have h' : \u2200 i\u2082, i\u2081 \u2260 i\u2082 \u2192 p -\u1d65 s.monge_point \u2208\n    (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee \u2293 vector_span \u211d (set.range s.points),\n  { intros i\u2082 hne,\n    rw [\u2190s.direction_monge_plane,\n        vsub_right_mem_direction_iff_mem s.monge_point_mem_monge_plane],\n    exact h i\u2082 hne },\n  have hi : p -\u1d65 s.monge_point \u2208 \u2a05 (i\u2082 : {i // i\u2081 \u2260 i}),\n    (\u211d \u2219 (s.points i\u2081 -\u1d65 s.points i\u2082))\u15ee,\n  { rw submodule.mem_infi,\n    exact \u03bb i, (submodule.mem_inf.1 (h' i i.property)).1 },\n  rw [submodule.infi_orthogonal, \u2190submodule.span_Union] at hi,\n  have hu : (\u22c3 (i : {i // i\u2081 \u2260 i}), ({s.points i\u2081 -\u1d65 s.points i} : set V)) =\n    (-\u1d65) (s.points i\u2081) '' (s.points '' (set.univ \\ {i\u2081})),\n  { rw [set.image_image],\n    ext x,\n    simp_rw [set.mem_Union, set.mem_image, set.mem_singleton_iff, set.mem_diff_singleton],\n    split,\n    { rintros \u27e8i, rfl\u27e9,\n      use [i, \u27e8set.mem_univ _, i.property.symm\u27e9] },\n    { rintros \u27e8i, \u27e8hiu, hi\u27e9, rfl\u27e9,\n      use [\u27e8i, hi.symm\u27e9, rfl] } },\n  rw [hu, \u2190vector_span_image_eq_span_vsub_set_left_ne \u211d _ (set.mem_univ _),\n      set.image_univ] at hi,\n  have hv : p -\u1d65 s.monge_point \u2208 vector_span \u211d (set.range s.points),\n  { let s\u2081 : finset (fin (n + 3)) := univ.erase i\u2081,\n    obtain \u27e8i\u2082, h\u2082\u27e9 :=\n      card_pos.1 (show 0 < card s\u2081, by simp [card_erase_of_mem]),\n    have h\u2081\u2082 : i\u2081 \u2260 i\u2082 := (ne_of_mem_erase h\u2082).symm,\n    exact (submodule.mem_inf.1 (h' i\u2082 h\u2081\u2082)).2 },\n  exact submodule.disjoint_def.1 ((vector_span \u211d (set.range s.points)).orthogonal_disjoint)\n    _ hv hi,\nend\n\n/-- An altitude of a simplex is the line that passes through a vertex\nand is orthogonal to the opposite face. -/\ndef altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) : affine_subspace \u211d P :=\nmk' (s.points i) (affine_span \u211d (s.points '' \u2191(univ.erase i))).direction\u15ee \u2293\n  affine_span \u211d (set.range s.points)\n\n/-- The definition of an altitude. -/\nlemma altitude_def {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  s.altitude i = mk' (s.points i)\n                     (affine_span \u211d (s.points '' \u2191(univ.erase i))).direction\u15ee \u2293\n    affine_span \u211d (set.range s.points) :=\nrfl\n\n/-- A vertex lies in the corresponding altitude. -/\nlemma mem_altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  s.points i \u2208 s.altitude i :=\n(mem_inf_iff _ _ _).2 \u27e8self_mem_mk' _ _, mem_affine_span \u211d (set.mem_range_self _)\u27e9\n\n/-- The direction of an altitude. -/\nlemma direction_altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  (s.altitude i).direction = (vector_span \u211d (s.points '' \u2191(finset.univ.erase i)))\u15ee \u2293\n    vector_span \u211d (set.range s.points) :=\nby rw [altitude_def,\n       direction_inf_of_mem (self_mem_mk' (s.points i) _)\n         (mem_affine_span \u211d (set.mem_range_self _)), direction_mk', direction_affine_span,\n       direction_affine_span]\n\n/-- The vector span of the opposite face lies in the direction\northogonal to an altitude. -/\nlemma vector_span_le_altitude_direction_orthogonal  {n : \u2115} (s : simplex \u211d P (n + 1))\n    (i : fin (n + 2)) :\n  vector_span \u211d (s.points '' \u2191(finset.univ.erase i)) \u2264 (s.altitude i).direction\u15ee :=\nbegin\n  rw direction_altitude,\n  exact le_trans\n    (vector_span \u211d (s.points '' \u2191(finset.univ.erase i))).le_orthogonal_orthogonal\n    (submodule.orthogonal_le inf_le_left)\nend\n\nopen finite_dimensional\n\n/-- An altitude is finite-dimensional. -/\ninstance finite_dimensional_direction_altitude {n : \u2115} (s : simplex \u211d P (n + 1))\n  (i : fin (n + 2)) : finite_dimensional \u211d ((s.altitude i).direction) :=\nbegin\n  rw direction_altitude,\n  apply_instance\nend\n\n/-- An altitude is one-dimensional (i.e., a line). -/\n@[simp] lemma finrank_direction_altitude {n : \u2115} (s : simplex \u211d P (n + 1)) (i : fin (n + 2)) :\n  finrank \u211d ((s.altitude i).direction) = 1 :=\nbegin\n  rw direction_altitude,\n  have h := submodule.finrank_add_inf_finrank_orthogonal\n    (vector_span_mono \u211d (set.image_subset_range s.points \u2191(univ.erase i))),\n  have hc : card (univ.erase i) = n + 1, { rw card_erase_of_mem (mem_univ _), simp },\n  refine add_left_cancel (trans h _),\n  rw [s.independent.finrank_vector_span (fintype.card_fin _),\n      \u2190 finset.coe_image, s.independent.finrank_vector_span_image_finset hc]\nend\n\n/-- A line through a vertex is the altitude through that vertex if and\nonly if it is orthogonal to the opposite face. -/\nlemma affine_span_pair_eq_altitude_iff {n : \u2115} (s : simplex \u211d P (n + 1))\n    (i : fin (n + 2)) (p : P) :\n  line[\u211d, p, s.points i] = s.altitude i \u2194 (p \u2260 s.points i \u2227\n    p \u2208 affine_span \u211d (set.range s.points) \u2227\n    p -\u1d65 s.points i \u2208 (affine_span \u211d (s.points '' \u2191(finset.univ.erase i))).direction\u15ee) :=\nbegin\n  rw [eq_iff_direction_eq_of_mem\n        (mem_affine_span \u211d (set.mem_insert_of_mem _ (set.mem_singleton _))) (s.mem_altitude _),\n      \u2190vsub_right_mem_direction_iff_mem (mem_affine_span \u211d (set.mem_range_self i)) p,\n      direction_affine_span, direction_affine_span, direction_affine_span],\n  split,\n  { intro h,\n    split,\n    { intro heq,\n      rw [heq, set.pair_eq_singleton, vector_span_singleton] at h,\n      have hd : finrank \u211d (s.altitude i).direction = 0,\n      { rw [\u2190h, finrank_bot] },\n      simpa using hd },\n    { rw [\u2190submodule.mem_inf, _root_.inf_comm, \u2190direction_altitude, \u2190h],\n      exact vsub_mem_vector_span \u211d (set.mem_insert _ _)\n                                   (set.mem_insert_of_mem _ (set.mem_singleton _)) } },\n  { rintro \u27e8hne, h\u27e9,\n    rw [\u2190submodule.mem_inf, _root_.inf_comm, \u2190direction_altitude] at h,\n    rw [vector_span_eq_span_vsub_set_left_ne \u211d (set.mem_insert _ _),\n        set.insert_diff_of_mem _ (set.mem_singleton _),\n        set.diff_singleton_eq_self (\u03bb h, hne (set.mem_singleton_iff.1 h)), set.image_singleton],\n    refine eq_of_le_of_finrank_eq _ _,\n    { rw submodule.span_le,\n      simpa using h },\n    { rw [finrank_direction_altitude, finrank_span_set_eq_card],\n      { simp },\n      { refine linear_independent_singleton _,\n        simpa using hne } } }\nend\n\nend simplex\n\nnamespace triangle\n\nopen euclidean_geometry finset simplex affine_subspace finite_dimensional\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\ninclude V\n\n/-- The orthocenter of a triangle is the intersection of its\naltitudes.  It is defined here as the 2-dimensional case of the\nMonge point. -/\ndef orthocenter (t : triangle \u211d P) : P := t.monge_point\n\n/-- The orthocenter equals the Monge point. -/\nlemma orthocenter_eq_monge_point (t : triangle \u211d P) : t.orthocenter = t.monge_point := rfl\n\n/-- The position of the orthocenter in relation to the circumcenter\nand centroid. -/\nlemma orthocenter_eq_smul_vsub_vadd_circumcenter (t : triangle \u211d P) :\n  t.orthocenter = (3 : \u211d) \u2022\n    ((univ : finset (fin 3)).centroid \u211d t.points -\u1d65 t.circumcenter : V) +\u1d65 t.circumcenter :=\nbegin\n  rw [orthocenter_eq_monge_point, monge_point_eq_smul_vsub_vadd_circumcenter],\n  norm_num\nend\n\n/-- The orthocenter lies in the affine span. -/\nlemma orthocenter_mem_affine_span (t : triangle \u211d P) :\n  t.orthocenter \u2208 affine_span \u211d (set.range t.points) :=\nt.monge_point_mem_affine_span\n\n/-- Two triangles with the same points have the same orthocenter. -/\nlemma orthocenter_eq_of_range_eq {t\u2081 t\u2082 : triangle \u211d P}\n  (h : set.range t\u2081.points = set.range t\u2082.points) : t\u2081.orthocenter = t\u2082.orthocenter :=\nmonge_point_eq_of_range_eq h\n\n/-- In the case of a triangle, altitudes are the same thing as Monge\nplanes. -/\nlemma altitude_eq_monge_plane (t : triangle \u211d P) {i\u2081 i\u2082 i\u2083 : fin 3} (h\u2081\u2082 : i\u2081 \u2260 i\u2082)\n  (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083) : t.altitude i\u2081 = t.monge_plane i\u2082 i\u2083 :=\nbegin\n  have hs : ({i\u2082, i\u2083}\u1d9c : finset (fin 3)) = {i\u2081}, by dec_trivial!,\n  have he : univ.erase i\u2081 = {i\u2082, i\u2083}, by dec_trivial!,\n  rw [monge_plane_def, altitude_def, direction_affine_span, hs, he, centroid_singleton,\n      coe_insert, coe_singleton,\n      vector_span_image_eq_span_vsub_set_left_ne \u211d _ (set.mem_insert i\u2082 _)],\n  simp [h\u2082\u2083, submodule.span_insert_eq_span]\nend\n\n/-- The orthocenter lies in the altitudes. -/\nlemma orthocenter_mem_altitude (t : triangle \u211d P) {i\u2081 : fin 3} :\n  t.orthocenter \u2208 t.altitude i\u2081 :=\nbegin\n  obtain \u27e8i\u2082, i\u2083, h\u2081\u2082, h\u2082\u2083, h\u2081\u2083\u27e9 : \u2203 i\u2082 i\u2083, i\u2081 \u2260 i\u2082 \u2227 i\u2082 \u2260 i\u2083 \u2227 i\u2081 \u2260 i\u2083, by dec_trivial!,\n  rw [orthocenter_eq_monge_point, t.altitude_eq_monge_plane h\u2081\u2082 h\u2081\u2083 h\u2082\u2083],\n  exact t.monge_point_mem_monge_plane\nend\n\n/-- The orthocenter is the only point lying in any two of the\naltitudes. -/\nlemma eq_orthocenter_of_forall_mem_altitude {t : triangle \u211d P} {i\u2081 i\u2082 : fin 3} {p : P}\n  (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081 : p \u2208 t.altitude i\u2081) (h\u2082 : p \u2208 t.altitude i\u2082) : p = t.orthocenter :=\nbegin\n  obtain \u27e8i\u2083, h\u2082\u2083, h\u2081\u2083\u27e9 : \u2203 i\u2083, i\u2082 \u2260 i\u2083 \u2227 i\u2081 \u2260 i\u2083, { clear h\u2081 h\u2082, dec_trivial! },\n  rw t.altitude_eq_monge_plane h\u2081\u2083 h\u2081\u2082 h\u2082\u2083.symm at h\u2081,\n  rw t.altitude_eq_monge_plane h\u2082\u2083 h\u2081\u2082.symm h\u2081\u2083.symm at h\u2082,\n  rw orthocenter_eq_monge_point,\n  have ha : \u2200 i, i\u2083 \u2260 i \u2192 p \u2208 t.monge_plane i\u2083 i,\n  { intros i hi,\n    have hi\u2081\u2082 : i\u2081 = i \u2228 i\u2082 = i, { clear h\u2081 h\u2082, dec_trivial! },\n    cases hi\u2081\u2082,\n    { exact hi\u2081\u2082 \u25b8 h\u2082 },\n    { exact hi\u2081\u2082 \u25b8 h\u2081 } },\n  exact eq_monge_point_of_forall_mem_monge_plane ha\nend\n\n/-- The distance from the orthocenter to the reflection of the\ncircumcenter in a side equals the circumradius. -/\n\n\n/-- The distance from the orthocenter to the reflection of the\ncircumcenter in a side equals the circumradius, variant using a\n`finset`. -/\nlemma dist_orthocenter_reflection_circumcenter_finset (t : triangle \u211d P) {i\u2081 i\u2082 : fin 3}\n  (h : i\u2081 \u2260 i\u2082) :\n  dist t.orthocenter (reflection (affine_span \u211d (t.points '' \u2191({i\u2081, i\u2082} : finset (fin 3))))\n                                 t.circumcenter) =\n    t.circumradius :=\nby { convert dist_orthocenter_reflection_circumcenter _ h, simp }\n\n/-- The affine span of the orthocenter and a vertex is contained in\nthe altitude. -/\nlemma affine_span_orthocenter_point_le_altitude (t : triangle \u211d P) (i : fin 3) :\n  line[\u211d, t.orthocenter, t.points i] \u2264 t.altitude i :=\nbegin\n  refine span_points_subset_coe_of_subset_coe _,\n  rw [set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8t.orthocenter_mem_altitude, t.mem_altitude i\u27e9\nend\n\n/-- Suppose we are given a triangle `t\u2081`, and replace one of its\nvertices by its orthocenter, yielding triangle `t\u2082` (with vertices not\nnecessarily listed in the same order).  Then an altitude of `t\u2082` from\na vertex that was not replaced is the corresponding side of `t\u2081`. -/\nlemma altitude_replace_orthocenter_eq_affine_span {t\u2081 t\u2082 : triangle \u211d P} {i\u2081 i\u2082 i\u2083 j\u2081 j\u2082 j\u2083 : fin 3}\n    (hi\u2081\u2082 : i\u2081 \u2260 i\u2082) (hi\u2081\u2083 : i\u2081 \u2260 i\u2083) (hi\u2082\u2083 : i\u2082 \u2260 i\u2083) (hj\u2081\u2082 : j\u2081 \u2260 j\u2082) (hj\u2081\u2083 : j\u2081 \u2260 j\u2083)\n    (hj\u2082\u2083 : j\u2082 \u2260 j\u2083) (h\u2081 : t\u2082.points j\u2081 = t\u2081.orthocenter) (h\u2082 : t\u2082.points j\u2082 = t\u2081.points i\u2082)\n    (h\u2083 : t\u2082.points j\u2083 = t\u2081.points i\u2083) :\n  t\u2082.altitude j\u2082 = line[\u211d, t\u2081.points i\u2081, t\u2081.points i\u2082] :=\nbegin\n  symmetry,\n  rw [\u2190h\u2082, t\u2082.affine_span_pair_eq_altitude_iff],\n  rw [h\u2082],\n  use t\u2081.independent.injective.ne hi\u2081\u2082,\n  have he : affine_span \u211d (set.range t\u2082.points) = affine_span \u211d (set.range t\u2081.points),\n  { refine ext_of_direction_eq _\n      \u27e8t\u2081.points i\u2083, mem_affine_span \u211d \u27e8j\u2083, h\u2083\u27e9, mem_affine_span \u211d (set.mem_range_self _)\u27e9,\n    refine eq_of_le_of_finrank_eq (direction_le (span_points_subset_coe_of_subset_coe _)) _,\n    { have hu : (finset.univ : finset (fin 3)) = {j\u2081, j\u2082, j\u2083}, { clear h\u2081 h\u2082 h\u2083, dec_trivial! },\n      rw [\u2190set.image_univ, \u2190finset.coe_univ, hu, finset.coe_insert, finset.coe_insert,\n          finset.coe_singleton, set.image_insert_eq, set.image_insert_eq, set.image_singleton,\n          h\u2081, h\u2082, h\u2083, set.insert_subset, set.insert_subset, set.singleton_subset_iff],\n      exact \u27e8t\u2081.orthocenter_mem_affine_span,\n             mem_affine_span \u211d (set.mem_range_self _),\n             mem_affine_span \u211d (set.mem_range_self _)\u27e9 },\n    { rw [direction_affine_span, direction_affine_span,\n          t\u2081.independent.finrank_vector_span (fintype.card_fin _),\n          t\u2082.independent.finrank_vector_span (fintype.card_fin _)] } },\n  rw he,\n  use mem_affine_span \u211d (set.mem_range_self _),\n  have hu : finset.univ.erase j\u2082 = {j\u2081, j\u2083}, { clear h\u2081 h\u2082 h\u2083, dec_trivial! },\n  rw [hu, finset.coe_insert, finset.coe_singleton, set.image_insert_eq, set.image_singleton,\n      h\u2081, h\u2083],\n  have hle : (t\u2081.altitude i\u2083).direction\u15ee \u2264\n    line[\u211d, t\u2081.orthocenter, t\u2081.points i\u2083].direction\u15ee :=\n      submodule.orthogonal_le (direction_le (affine_span_orthocenter_point_le_altitude _ _)),\n  refine hle ((t\u2081.vector_span_le_altitude_direction_orthogonal i\u2083) _),\n  have hui : finset.univ.erase i\u2083 = {i\u2081, i\u2082}, { clear hle h\u2082 h\u2083, dec_trivial! },\n  rw [hui, finset.coe_insert, finset.coe_singleton, set.image_insert_eq, set.image_singleton],\n  refine vsub_mem_vector_span \u211d (set.mem_insert _ _)\n    (set.mem_insert_of_mem _ (set.mem_singleton _))\nend\n\n/-- Suppose we are given a triangle `t\u2081`, and replace one of its\nvertices by its orthocenter, yielding triangle `t\u2082` (with vertices not\nnecessarily listed in the same order).  Then the orthocenter of `t\u2082`\nis the vertex of `t\u2081` that was replaced. -/\nlemma orthocenter_replace_orthocenter_eq_point {t\u2081 t\u2082 : triangle \u211d P} {i\u2081 i\u2082 i\u2083 j\u2081 j\u2082 j\u2083 : fin 3}\n    (hi\u2081\u2082 : i\u2081 \u2260 i\u2082) (hi\u2081\u2083 : i\u2081 \u2260 i\u2083) (hi\u2082\u2083 : i\u2082 \u2260 i\u2083) (hj\u2081\u2082 : j\u2081 \u2260 j\u2082) (hj\u2081\u2083 : j\u2081 \u2260 j\u2083)\n    (hj\u2082\u2083 : j\u2082 \u2260 j\u2083) (h\u2081 : t\u2082.points j\u2081 = t\u2081.orthocenter) (h\u2082 : t\u2082.points j\u2082 = t\u2081.points i\u2082)\n    (h\u2083 : t\u2082.points j\u2083 = t\u2081.points i\u2083) :\n  t\u2082.orthocenter = t\u2081.points i\u2081 :=\nbegin\n  refine (triangle.eq_orthocenter_of_forall_mem_altitude hj\u2082\u2083 _ _).symm,\n  { rw altitude_replace_orthocenter_eq_affine_span hi\u2081\u2082 hi\u2081\u2083 hi\u2082\u2083 hj\u2081\u2082 hj\u2081\u2083 hj\u2082\u2083 h\u2081 h\u2082 h\u2083,\n    exact mem_affine_span \u211d (set.mem_insert _ _) },\n  { rw altitude_replace_orthocenter_eq_affine_span hi\u2081\u2083 hi\u2081\u2082 hi\u2082\u2083.symm hj\u2081\u2083 hj\u2081\u2082 hj\u2082\u2083.symm h\u2081 h\u2083 h\u2082,\n    exact mem_affine_span \u211d (set.mem_insert _ _) }\nend\n\nend triangle\n\nend affine\n\nnamespace euclidean_geometry\n\nopen affine affine_subspace finite_dimensional\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\n\ninclude V\n\n/-- Four points form an orthocentric system if they consist of the\nvertices of a triangle and its orthocenter. -/\ndef orthocentric_system (s : set P) : Prop :=\n\u2203 t : triangle \u211d P,\n  t.orthocenter \u2209 set.range t.points \u2227 s = insert t.orthocenter (set.range t.points)\n\n/-- This is an auxiliary lemma giving information about the relation\nof two triangles in an orthocentric system; it abstracts some\nreasoning, with no geometric content, that is common to some other\nlemmas.  Suppose the orthocentric system is generated by triangle `t`,\nand we are given three points `p` in the orthocentric system.  Then\neither we can find indices `i\u2081`, `i\u2082` and `i\u2083` for `p` such that `p\ni\u2081` is the orthocenter of `t` and `p i\u2082` and `p i\u2083` are points `j\u2082`\nand `j\u2083` of `t`, or `p` has the same points as `t`. -/\nlemma exists_of_range_subset_orthocentric_system {t : triangle \u211d P}\n  (ho : t.orthocenter \u2209 set.range t.points) {p : fin 3 \u2192 P}\n  (hps : set.range p \u2286 insert t.orthocenter (set.range t.points)) (hpi : function.injective p) :\n  (\u2203 (i\u2081 i\u2082 i\u2083 j\u2082 j\u2083 : fin 3), i\u2081 \u2260 i\u2082 \u2227 i\u2081 \u2260 i\u2083 \u2227 i\u2082 \u2260 i\u2083 \u2227\n    (\u2200 i : fin 3, i = i\u2081 \u2228 i = i\u2082 \u2228 i = i\u2083) \u2227 p i\u2081 = t.orthocenter \u2227 j\u2082 \u2260 j\u2083 \u2227\n    t.points j\u2082 = p i\u2082 \u2227 t.points j\u2083 = p i\u2083) \u2228 set.range p = set.range t.points :=\nbegin\n  by_cases h : t.orthocenter \u2208 set.range p,\n  { left,\n    rcases h with \u27e8i\u2081, h\u2081\u27e9,\n    obtain \u27e8i\u2082, i\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083\u27e9 :\n      \u2203 (i\u2082 i\u2083 : fin 3), i\u2081 \u2260 i\u2082 \u2227 i\u2081 \u2260 i\u2083 \u2227 i\u2082 \u2260 i\u2083 \u2227 \u2200 i : fin 3, i = i\u2081 \u2228 i = i\u2082 \u2228 i = i\u2083,\n    { clear h\u2081, dec_trivial! },\n    have h : \u2200 i, i\u2081 \u2260 i \u2192 \u2203 (j : fin 3), t.points j = p i,\n    { intros i hi,\n      replace hps := set.mem_of_mem_insert_of_ne\n        (set.mem_of_mem_of_subset (set.mem_range_self i) hps) (h\u2081 \u25b8 hpi.ne hi.symm),\n      exact hps },\n    rcases h i\u2082 h\u2081\u2082 with \u27e8j\u2082, h\u2082\u27e9,\n    rcases h i\u2083 h\u2081\u2083 with \u27e8j\u2083, h\u2083\u27e9,\n    have hj\u2082\u2083 : j\u2082 \u2260 j\u2083,\n    { intro he,\n      rw [he, h\u2083] at h\u2082,\n      exact h\u2082\u2083.symm (hpi h\u2082) },\n    exact \u27e8i\u2081, i\u2082, i\u2083, j\u2082, j\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083, h\u2081, hj\u2082\u2083, h\u2082, h\u2083\u27e9 },\n  { right,\n    have hs := set.subset_diff_singleton hps h,\n    rw set.insert_diff_self_of_not_mem ho at hs,\n    refine set.eq_of_subset_of_card_le hs _,\n    rw [set.card_range_of_injective hpi,\n        set.card_range_of_injective t.independent.injective] }\nend\n\n/-- For any three points in an orthocentric system generated by\ntriangle `t`, there is a point in the subspace spanned by the triangle\nfrom which the distance of all those three points equals the circumradius. -/\nlemma exists_dist_eq_circumradius_of_subset_insert_orthocenter {t : triangle \u211d P}\n  (ho : t.orthocenter \u2209 set.range t.points) {p : fin 3 \u2192 P}\n  (hps : set.range p \u2286 insert t.orthocenter (set.range t.points)) (hpi : function.injective p) :\n  \u2203 c \u2208 affine_span \u211d (set.range t.points), \u2200 p\u2081 \u2208 set.range p, dist p\u2081 c = t.circumradius :=\nbegin\n  rcases exists_of_range_subset_orthocentric_system ho hps hpi with\n    \u27e8i\u2081, i\u2082, i\u2083, j\u2082, j\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083, h\u2081, hj\u2082\u2083, h\u2082, h\u2083\u27e9 | hs,\n  { use [reflection (affine_span \u211d (t.points '' {j\u2082, j\u2083})) t.circumcenter,\n         reflection_mem_of_le_of_mem (affine_span_mono \u211d (set.image_subset_range _ _))\n                                     t.circumcenter_mem_affine_span],\n    intros p\u2081 hp\u2081,\n    rcases hp\u2081 with \u27e8i, rfl\u27e9,\n    replace h\u2081\u2082\u2083 := h\u2081\u2082\u2083 i,\n    repeat { cases h\u2081\u2082\u2083 },\n    { rw h\u2081,\n      exact triangle.dist_orthocenter_reflection_circumcenter t hj\u2082\u2083 },\n    { rw [\u2190h\u2082,\n          dist_reflection_eq_of_mem _\n            (mem_affine_span \u211d (set.mem_image_of_mem _ (set.mem_insert _ _)))],\n      exact t.dist_circumcenter_eq_circumradius _ },\n    { rw [\u2190h\u2083,\n          dist_reflection_eq_of_mem _\n            (mem_affine_span \u211d (set.mem_image_of_mem _\n              (set.mem_insert_of_mem _ (set.mem_singleton _))))],\n      exact t.dist_circumcenter_eq_circumradius _ } },\n  { use [t.circumcenter, t.circumcenter_mem_affine_span],\n    intros p\u2081 hp\u2081,\n    rw hs at hp\u2081,\n    rcases hp\u2081 with \u27e8i, rfl\u27e9,\n    exact t.dist_circumcenter_eq_circumradius _ }\nend\n\n/-- Any three points in an orthocentric system are affinely independent. -/\nlemma orthocentric_system.affine_independent {s : set P} (ho : orthocentric_system s)\n    {p : fin 3 \u2192 P} (hps : set.range p \u2286 s) (hpi : function.injective p) :\n  affine_independent \u211d p :=\nbegin\n  rcases ho with \u27e8t, hto, hst\u27e9,\n  rw hst at hps,\n  rcases exists_dist_eq_circumradius_of_subset_insert_orthocenter hto hps hpi with \u27e8c, hcs, hc\u27e9,\n  exact cospherical.affine_independent \u27e8c, t.circumradius, hc\u27e9 set.subset.rfl hpi\nend\n\n/-- Any three points in an orthocentric system span the same subspace\nas the whole orthocentric system. -/\nlemma affine_span_of_orthocentric_system {s : set P} (ho : orthocentric_system s)\n    {p : fin 3 \u2192 P} (hps : set.range p \u2286 s) (hpi : function.injective p) :\n  affine_span \u211d (set.range p) = affine_span \u211d s :=\nbegin\n  have ha := ho.affine_independent hps hpi,\n  rcases ho with \u27e8t, hto, hts\u27e9,\n  have hs : affine_span \u211d s = affine_span \u211d (set.range t.points),\n  { rw [hts, affine_span_insert_eq_affine_span \u211d t.orthocenter_mem_affine_span] },\n  refine ext_of_direction_eq _\n    \u27e8p 0, mem_affine_span \u211d (set.mem_range_self _), mem_affine_span \u211d (hps (set.mem_range_self _))\u27e9,\n  have hfd : finite_dimensional \u211d (affine_span \u211d s).direction, { rw hs, apply_instance },\n  haveI := hfd,\n  refine eq_of_le_of_finrank_eq (direction_le (affine_span_mono \u211d hps)) _,\n  rw [hs, direction_affine_span, direction_affine_span,\n      ha.finrank_vector_span (fintype.card_fin _),\n      t.independent.finrank_vector_span (fintype.card_fin _)]\nend\n\n/-- All triangles in an orthocentric system have the same circumradius. -/\nlemma orthocentric_system.exists_circumradius_eq {s : set P} (ho : orthocentric_system s) :\n  \u2203 r : \u211d, \u2200 t : triangle \u211d P, set.range t.points \u2286 s \u2192 t.circumradius = r :=\nbegin\n  rcases ho with \u27e8t, hto, hts\u27e9,\n  use t.circumradius,\n  intros t\u2082 ht\u2082,\n  have ht\u2082s := ht\u2082,\n  rw hts at ht\u2082,\n  rcases exists_dist_eq_circumradius_of_subset_insert_orthocenter hto ht\u2082\n    t\u2082.independent.injective with \u27e8c, hc, h\u27e9,\n  rw set.forall_range_iff at h,\n  have hs : set.range t.points \u2286 s,\n  { rw hts,\n    exact set.subset_insert _ _ },\n  rw [affine_span_of_orthocentric_system \u27e8t, hto, hts\u27e9 hs\n        t.independent.injective,\n      \u2190affine_span_of_orthocentric_system \u27e8t, hto, hts\u27e9 ht\u2082s\n        t\u2082.independent.injective] at hc,\n  exact (t\u2082.eq_circumradius_of_dist_eq hc h).symm\nend\n\n/-- Given any triangle in an orthocentric system, the fourth point is\nits orthocenter. -/\nlemma orthocentric_system.eq_insert_orthocenter {s : set P} (ho : orthocentric_system s)\n    {t : triangle \u211d P} (ht : set.range t.points \u2286 s) :\n  s = insert t.orthocenter (set.range t.points) :=\nbegin\n  rcases ho with \u27e8t\u2080, ht\u2080o, ht\u2080s\u27e9,\n  rw ht\u2080s at ht,\n  rcases exists_of_range_subset_orthocentric_system ht\u2080o ht\n    t.independent.injective with\n    \u27e8i\u2081, i\u2082, i\u2083, j\u2082, j\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, h\u2081\u2082\u2083, h\u2081, hj\u2082\u2083, h\u2082, h\u2083\u27e9 | hs,\n  { obtain \u27e8j\u2081, hj\u2081\u2082, hj\u2081\u2083, hj\u2081\u2082\u2083\u27e9 :\n      \u2203 j\u2081 : fin 3, j\u2081 \u2260 j\u2082 \u2227 j\u2081 \u2260 j\u2083 \u2227 \u2200 j : fin 3, j = j\u2081 \u2228 j = j\u2082 \u2228 j = j\u2083,\n    { clear h\u2082 h\u2083, dec_trivial! },\n    suffices h : t\u2080.points j\u2081 = t.orthocenter,\n    { have hui : (set.univ : set (fin 3)) = {i\u2081, i\u2082, i\u2083}, { ext x, simpa using h\u2081\u2082\u2083 x },\n      have huj : (set.univ : set (fin 3)) = {j\u2081, j\u2082, j\u2083}, { ext x, simpa using hj\u2081\u2082\u2083 x },\n      rw [\u2190h, ht\u2080s, \u2190set.image_univ, huj, \u2190set.image_univ, hui],\n      simp_rw [set.image_insert_eq, set.image_singleton, h\u2081, \u2190h\u2082, \u2190h\u2083],\n      rw set.insert_comm },\n    exact (triangle.orthocenter_replace_orthocenter_eq_point\n      hj\u2081\u2082 hj\u2081\u2083 hj\u2082\u2083 h\u2081\u2082 h\u2081\u2083 h\u2082\u2083 h\u2081 h\u2082.symm h\u2083.symm).symm },\n  { rw hs,\n    convert ht\u2080s using 2,\n    exact triangle.orthocenter_eq_of_range_eq hs }\nend\n\nend euclidean_geometry\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/monge_point.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7180543789332258}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller, Yury Kudryashov\n-/\nimport data.nat.modeq\nimport data.set.finite\nimport algebra.big_operators.order\nimport algebra.module.basic\nimport algebra.module.big_operators\n\n/-!\n# Pigeonhole principles\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGiven pigeons (possibly infinitely many) in pigeonholes, the\npigeonhole principle states that, if there are more pigeons than\npigeonholes, then there is a pigeonhole with two or more pigeons.\n\nThere are a few variations on this statement, and the conclusion can\nbe made stronger depending on how many pigeons you know you might\nhave.\n\nThe basic statements of the pigeonhole principle appear in the\nfollowing locations:\n\n* `data.finset.basic` has `finset.exists_ne_map_eq_of_card_lt_of_maps_to`\n* `data.fintype.basic` has `fintype.exists_ne_map_eq_of_card_lt`\n* `data.fintype.basic` has `finite.exists_ne_map_eq_of_infinite`\n* `data.fintype.basic` has `finite.exists_infinite_fiber`\n* `data.set.finite` has `set.infinite.exists_ne_map_eq_of_maps_to`\n\nThis module gives access to these pigeonhole principles along with 20 more.\nThe versions vary by:\n\n* using a function between `fintype`s or a function between possibly infinite types restricted to\n  `finset`s;\n* counting pigeons by a general weight function (`\u2211 x in s, w x`) or by heads (`finset.card s`);\n* using strict or non-strict inequalities;\n* establishing upper or lower estimate on the number (or the total weight) of the pigeons in one\n  pigeonhole;\n* in case when we count pigeons by some weight function `w` and consider a function `f` between\n  `finset`s `s` and `t`, we can either assume that each pigeon is in one of the pigeonholes\n  (`\u2200 x \u2208 s, f x \u2208 t`), or assume that for `y \u2209 t`, the total weight of the pigeons in this\n  pigeonhole `\u2211 x in s.filter (\u03bb x, f x = y), w x` is nonpositive or nonnegative depending on\n  the inequality we are proving.\n\nLemma names follow `mathlib` convention (e.g.,\n`finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum`); \"pigeonhole principle\" is mentioned in the\ndocstrings instead of the names.\n\n## See also\n\n* `ordinal.infinite_pigeonhole`: pigeonhole principle for cardinals, formulated using cofinality;\n\n* `measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure`,\n  `measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure`: pigeonhole principle in a\n  measure space.\n\n## Tags\n\npigeonhole principle\n-/\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {M : Type w} [decidable_eq \u03b2]\n\nopen nat\nopen_locale big_operators\n\nnamespace finset\n\nvariables {s : finset \u03b1} {t : finset \u03b2} {f : \u03b1 \u2192 \u03b2} {w : \u03b1 \u2192 M} {b : M} {n : \u2115}\n\n/-!\n### The pigeonhole principles on `finset`s, pigeons counted by weight\n\nIn this section we prove the following version of the pigeonhole principle: if the total weight of a\nfinite set of pigeons is greater than `n \u2022 b`, and they are sorted into `n` pigeonholes, then for\nsome pigeonhole, the total weight of the pigeons in this pigeonhole is greater than `b`, and a few\nvariations of this theorem.\n\nThe principle is formalized in the following way, see\n`finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum`: if `f : \u03b1 \u2192 \u03b2` is a function which maps all\nelements of `s : finset \u03b1` to `t : finset \u03b2` and `card t \u2022 b < \u2211 x in s, w x`, where `w : \u03b1 \u2192 M` is\na weight function taking values in a `linear_ordered_cancel_add_comm_monoid`, then for\nsome `y \u2208 t`, the sum of the weights of all `x \u2208 s` such that `f x = y` is greater than `b`.\n\nThere are a few bits we can change in this theorem:\n\n* reverse all inequalities, with obvious adjustments to the name;\n* replace the assumption `\u2200 a \u2208 s, f a \u2208 t` with\n  `\u2200 y \u2209 t, (\u2211 x in s.filter (\u03bb x, f x = y), w x) \u2264 0`,\n  and replace `of_maps_to` with `of_sum_fiber_nonpos` in the name;\n* use non-strict inequalities assuming `t` is nonempty.\n\nWe can do all these variations independently, so we have eight versions of the theorem.\n-/\n\nsection\nvariables [linear_ordered_cancel_add_comm_monoid M]\n\n/-!\n#### Strict inequality versions\n-/\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:\nif the total weight of a finite set of pigeons is greater than `n \u2022 b`, and they are sorted into\n`n` pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is\ngreater than `b`. -/\nlemma exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum (hf : \u2200 a \u2208 s, f a \u2208 t)\n  (hb : t.card \u2022 b < \u2211 x in s, w x) :\n  \u2203 y \u2208 t, b < \u2211 x in s.filter (\u03bb x, f x = y), w x :=\nexists_lt_of_sum_lt $ by simpa only [sum_fiberwise_of_maps_to hf, sum_const]\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:\nif the total weight of a finite set of pigeons is less than `n \u2022 b`, and they are sorted into `n`\npigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is less\nthan `b`. -/\nlemma exists_sum_fiber_lt_of_maps_to_of_sum_lt_nsmul (hf : \u2200 a \u2208 s, f a \u2208 t)\n  (hb : (\u2211 x in s, w x) < t.card \u2022 b) :\n  \u2203 y \u2208 t, (\u2211 x in s.filter (\u03bb x, f x = y), w x) < b :=\n@exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum \u03b1 \u03b2 M\u1d52\u1d48 _ _ _ _ _ _ _ hf hb\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:\nif the total weight of a finite set of pigeons is greater than `n \u2022 b`, they are sorted into some\npigeonholes, and for all but `n` pigeonholes the total weight of the pigeons there is nonpositive,\nthen for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole\nis greater than `b`. -/\nlemma exists_lt_sum_fiber_of_sum_fiber_nonpos_of_nsmul_lt_sum\n  (ht : \u2200 y \u2209 t, (\u2211 x in s.filter (\u03bb x, f x = y), w x) \u2264 0) (hb : t.card \u2022 b < \u2211 x in s, w x) :\n  \u2203 y \u2208 t, b < \u2211 x in s.filter (\u03bb x, f x = y), w x :=\nexists_lt_of_sum_lt $\ncalc (\u2211 y in t, b) < \u2211 x in s, w x : by simpa\n... \u2264 \u2211 y in t, \u2211 x in s.filter (\u03bb x, f x = y), w x :\n  sum_le_sum_fiberwise_of_sum_fiber_nonpos ht\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:\nif the total weight of a finite set of pigeons is less than `n \u2022 b`, they are sorted into some\npigeonholes, and for all but `n` pigeonholes the total weight of the pigeons there is nonnegative,\nthen for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole\nis less than `b`. -/\nlemma exists_sum_fiber_lt_of_sum_fiber_nonneg_of_sum_lt_nsmul\n  (ht : \u2200 y \u2209 t, (0:M) \u2264 \u2211 x in s.filter (\u03bb x, f x = y), w x) (hb : (\u2211 x in s, w x) < t.card \u2022 b) :\n  \u2203 y \u2208 t, (\u2211 x in s.filter (\u03bb x, f x = y), w x) < b :=\n@exists_lt_sum_fiber_of_sum_fiber_nonpos_of_nsmul_lt_sum \u03b1 \u03b2 M\u1d52\u1d48 _ _ _ _ _ _ _ ht hb\n\n/-!\n#### Non-strict inequality versions\n-/\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality\nversion: if the total weight of a finite set of pigeons is greater than or equal to `n \u2022 b`, and\nthey are sorted into `n > 0` pigeonholes, then for some pigeonhole, the total weight of the pigeons\nin this pigeonhole is greater than or equal to `b`. -/\nlemma exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum (hf : \u2200 a \u2208 s, f a \u2208 t) (ht : t.nonempty)\n  (hb : t.card \u2022 b \u2264 \u2211 x in s, w x) :\n  \u2203 y \u2208 t, b \u2264 \u2211 x in s.filter (\u03bb x, f x = y), w x :=\nexists_le_of_sum_le ht $ by simpa only [sum_fiberwise_of_maps_to hf, sum_const]\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality\nversion: if the total weight of a finite set of pigeons is less than or equal to `n \u2022 b`, and they\nare sorted into `n > 0` pigeonholes, then for some pigeonhole, the total weight of the pigeons in\nthis pigeonhole is less than or equal to `b`. -/\nlemma exists_sum_fiber_le_of_maps_to_of_sum_le_nsmul (hf : \u2200 a \u2208 s, f a \u2208 t) (ht : t.nonempty)\n  (hb : (\u2211 x in s, w x) \u2264 t.card \u2022 b) :\n  \u2203 y \u2208 t, (\u2211 x in s.filter (\u03bb x, f x = y), w x) \u2264 b :=\n@exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum \u03b1 \u03b2 M\u1d52\u1d48 _ _ _ _ _ _ _ hf ht hb\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality\nversion: if the total weight of a finite set of pigeons is greater than or equal to `n \u2022 b`, they\nare sorted into some pigeonholes, and for all but `n > 0` pigeonholes the total weight of the\npigeons there is nonpositive, then for at least one of these `n` pigeonholes, the total weight of\nthe pigeons in this pigeonhole is greater than or equal to `b`. -/\nlemma exists_le_sum_fiber_of_sum_fiber_nonpos_of_nsmul_le_sum\n  (hf : \u2200 y \u2209 t, (\u2211 x in s.filter (\u03bb x, f x = y), w x) \u2264 0) (ht : t.nonempty)\n  (hb : t.card \u2022 b \u2264 \u2211 x in s, w x) :\n  \u2203 y \u2208 t, b \u2264 \u2211 x in s.filter (\u03bb x, f x = y), w x :=\nexists_le_of_sum_le ht $\ncalc (\u2211 y in t, b) \u2264 \u2211 x in s, w x : by simpa\n... \u2264 \u2211 y in t, \u2211 x in s.filter (\u03bb x, f x = y), w x :\n  sum_le_sum_fiberwise_of_sum_fiber_nonpos hf\n\n/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality\nversion: if the total weight of a finite set of pigeons is less than or equal to `n \u2022 b`, they are\nsorted into some pigeonholes, and for all but `n > 0` pigeonholes the total weight of the pigeons\nthere is nonnegative, then for at least one of these `n` pigeonholes, the total weight of the\npigeons in this pigeonhole is less than or equal to `b`. -/\nlemma exists_sum_fiber_le_of_sum_fiber_nonneg_of_sum_le_nsmul\n  (hf : \u2200 y \u2209 t, (0:M) \u2264 \u2211 x in s.filter (\u03bb x, f x = y), w x) (ht : t.nonempty)\n  (hb : (\u2211 x in s, w x) \u2264 t.card \u2022 b) :\n  \u2203 y \u2208 t, (\u2211 x in s.filter (\u03bb x, f x = y), w x) \u2264 b :=\n@exists_le_sum_fiber_of_sum_fiber_nonpos_of_nsmul_le_sum \u03b1 \u03b2 M\u1d52\u1d48 _ _ _ _ _ _ _ hf ht hb\n\nend\n\nvariables [linear_ordered_comm_semiring M]\n\n/-!\n### The pigeonhole principles on `finset`s, pigeons counted by heads\n\nIn this section we formalize a few versions of the following pigeonhole principle: there is a\npigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all\npigeonholes.\n\nFirst, we can use strict or non-strict inequalities. While the versions with non-strict inequalities\nare weaker than those with strict inequalities, sometimes it might be more convenient to apply the\nweaker version. Second, we can either state that there exists a pigeonhole with at least `n`\npigeons, or state that there exists a pigeonhole with at most `n` pigeons. In the latter case we do\nnot need the assumption `\u2200 a \u2208 s, f a \u2208 t`.\n\nSo, we prove four theorems: `finset.exists_lt_card_fiber_of_maps_to_of_mul_lt_card`,\n`finset.exists_le_card_fiber_of_maps_to_of_mul_le_card`,\n`finset.exists_card_fiber_lt_of_card_lt_mul`, and `finset.exists_card_fiber_le_of_card_le_mul`. -/\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with\nat least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes. -/\nlemma exists_lt_card_fiber_of_nsmul_lt_card_of_maps_to (hf : \u2200 a \u2208 s, f a \u2208 t)\n  (ht : t.card \u2022 b < s.card) :\n  \u2203 y \u2208 t, b < (s.filter $ \u03bb x, f x = y).card :=\nbegin\n  simp_rw cast_card at \u22a2 ht,\n  exact exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum hf ht,\nend\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with\nat least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes.\n(\"The maximum is at least the mean\" specialized to integers.)\n\nMore formally, given a function between finite sets `s` and `t` and a natural number `n` such that\n`card t * n < card s`, there exists `y \u2208 t` such that its preimage in `s` has more than `n`\nelements. -/\nlemma exists_lt_card_fiber_of_mul_lt_card_of_maps_to (hf : \u2200 a \u2208 s, f a \u2208 t)\n  (hn : t.card * n < s.card) :\n  \u2203 y \u2208 t, n < (s.filter (\u03bb x, f x = y)).card :=\nexists_lt_card_fiber_of_nsmul_lt_card_of_maps_to hf hn\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with\nat most as many pigeons as the floor of the average number of pigeons across all pigeonholes. -/\nlemma exists_card_fiber_lt_of_card_lt_nsmul (ht : \u2191(s.card) < t.card \u2022 b) :\n  \u2203 y \u2208 t, \u2191((s.filter $ \u03bb x, f x = y).card) < b :=\nbegin\n  simp_rw cast_card at \u22a2 ht,\n  exact exists_sum_fiber_lt_of_sum_fiber_nonneg_of_sum_lt_nsmul\n    (\u03bb _ _, sum_nonneg $ \u03bb _ _, zero_le_one) ht,\nend\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with\nat most as many pigeons as the floor of the average number of pigeons across all pigeonholes.  (\"The\nminimum is at most the mean\" specialized to integers.)\n\nMore formally, given a function `f`, a finite sets `s` in its domain, a finite set `t` in its\ncodomain, and a natural number `n` such that `card s < card t * n`, there exists `y \u2208 t` such that\nits preimage in `s` has less than `n` elements. -/\nlemma exists_card_fiber_lt_of_card_lt_mul (hn : s.card < t.card * n) :\n  \u2203 y \u2208 t, (s.filter (\u03bb x, f x = y)).card < n :=\nexists_card_fiber_lt_of_card_lt_nsmul hn\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: given a function between\nfinite sets `s` and `t` and a number `b` such that `card t \u2022 b \u2264 card s`, there exists `y \u2208 t` such\nthat its preimage in `s` has at least `b` elements.\nSee also `finset.exists_lt_card_fiber_of_nsmul_lt_card_of_maps_to` for a stronger statement. -/\nlemma exists_le_card_fiber_of_nsmul_le_card_of_maps_to (hf : \u2200 a \u2208 s, f a \u2208 t) (ht : t.nonempty)\n  (hb : t.card \u2022 b \u2264 s.card) :\n  \u2203 y \u2208 t, b \u2264 (s.filter $ \u03bb x, f x = y).card :=\nbegin\n  simp_rw cast_card at \u22a2 hb,\n  exact exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum hf ht hb,\nend\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: given a function between\nfinite sets `s` and `t` and a natural number `b` such that `card t * n \u2264 card s`, there exists `y \u2208\nt` such that its preimage in `s` has at least `n` elements. See also\n`finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to` for a stronger statement. -/\nlemma exists_le_card_fiber_of_mul_le_card_of_maps_to (hf : \u2200 a \u2208 s, f a \u2208 t) (ht : t.nonempty)\n  (hn : t.card * n \u2264 s.card) :\n  \u2203 y \u2208 t, n \u2264 (s.filter (\u03bb x, f x = y)).card :=\nexists_le_card_fiber_of_nsmul_le_card_of_maps_to hf ht hn\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: given a function `f`, a\nfinite sets `s` and `t`, and a number `b` such that `card s \u2264 card t \u2022 b`, there exists `y \u2208 t` such\nthat its preimage in `s` has no more than `b` elements.\nSee also `finset.exists_card_fiber_lt_of_card_lt_nsmul` for a stronger statement. -/\nlemma exists_card_fiber_le_of_card_le_nsmul (ht : t.nonempty) (hb : \u2191(s.card) \u2264 t.card \u2022 b) :\n  \u2203 y \u2208 t, \u2191((s.filter $ \u03bb x, f x = y).card) \u2264 b :=\nbegin\n  simp_rw cast_card at \u22a2 hb,\n  refine exists_sum_fiber_le_of_sum_fiber_nonneg_of_sum_le_nsmul\n    (\u03bb _ _, sum_nonneg $ \u03bb _ _, zero_le_one) ht hb,\nend\n\n/-- The pigeonhole principle for finitely many pigeons counted by heads: given a function `f`, a\nfinite sets `s` in its domain, a finite set `t` in its codomain, and a natural number `n` such that\n`card s \u2264 card t * n`, there exists `y \u2208 t` such that its preimage in `s` has no more than `n`\nelements. See also `finset.exists_card_fiber_lt_of_card_lt_mul` for a stronger statement. -/\nlemma exists_card_fiber_le_of_card_le_mul (ht : t.nonempty) (hn : s.card \u2264 t.card * n) :\n  \u2203 y \u2208 t, (s.filter (\u03bb x, f x = y)).card \u2264 n :=\nexists_card_fiber_le_of_card_le_nsmul ht hn\n\nend finset\n\nnamespace fintype\nopen finset\n\nvariables [fintype \u03b1] [fintype \u03b2] (f : \u03b1 \u2192 \u03b2) {w : \u03b1 \u2192 M} {b : M} {n : \u2115}\n\nsection\nvariables [linear_ordered_cancel_add_comm_monoid M]\n\n/-!\n### The pigeonhole principles on `fintypes`s, pigeons counted by weight\n\nIn this section we specialize theorems from the previous section to the special case of functions\nbetween `fintype`s and `s = univ`, `t = univ`. In this case the assumption `\u2200 x \u2208 s, f x \u2208 t` always\nholds, so we have four theorems instead of eight. -/\n\n/-- The pigeonhole principle for finitely many pigeons of different weights, strict inequality\nversion: there is a pigeonhole with the total weight of pigeons in it greater than `b` provided that\nthe total number of pigeonholes times `b` is less than the total weight of all pigeons. -/\nlemma exists_lt_sum_fiber_of_nsmul_lt_sum (hb : card \u03b2 \u2022 b < \u2211 x, w x) :\n  \u2203 y, b < \u2211 x in univ.filter (\u03bb x, f x = y), w x :=\nlet \u27e8y, _, hy\u27e9 := exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum (\u03bb _ _, mem_univ _) hb in \u27e8y, hy\u27e9\n\n/-- The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality\nversion: there is a pigeonhole with the total weight of pigeons in it greater than or equal to `b`\nprovided that the total number of pigeonholes times `b` is less than or equal to the total weight of\nall pigeons. -/\nlemma exists_le_sum_fiber_of_nsmul_le_sum [nonempty \u03b2] (hb : card \u03b2 \u2022 b \u2264 \u2211 x, w x) :\n  \u2203 y, b \u2264 \u2211 x in univ.filter (\u03bb x, f x = y), w x :=\nlet \u27e8y, _, hy\u27e9 :=\n  exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum (\u03bb _ _, mem_univ _) univ_nonempty hb\nin \u27e8y, hy\u27e9\n\n/-- The pigeonhole principle for finitely many pigeons of different weights, strict inequality\nversion: there is a pigeonhole with the total weight of pigeons in it less than `b` provided that\nthe total number of pigeonholes times `b` is greater than the total weight of all pigeons. -/\nlemma exists_sum_fiber_lt_of_sum_lt_nsmul (hb : (\u2211 x, w x) < card \u03b2 \u2022 b) :\n  \u2203 y, (\u2211 x in univ.filter (\u03bb x, f x = y), w x) < b :=\n@exists_lt_sum_fiber_of_nsmul_lt_sum \u03b1 \u03b2 M\u1d52\u1d48 _ _ _ _ _ _ _ hb\n\n/-- The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality\nversion: there is a pigeonhole with the total weight of pigeons in it less than or equal to `b`\nprovided that the total number of pigeonholes times `b` is greater than or equal to the total weight\nof all pigeons. -/\nlemma exists_sum_fiber_le_of_sum_le_nsmul [nonempty \u03b2] (hb : (\u2211 x, w x) \u2264 card \u03b2 \u2022 b) :\n  \u2203 y, (\u2211 x in univ.filter (\u03bb x, f x = y), w x) \u2264 b :=\n@exists_le_sum_fiber_of_nsmul_le_sum \u03b1 \u03b2 M\u1d52\u1d48 _ _ _ _ _ _ _ _ hb\n\nend\n\nvariables [linear_ordered_comm_semiring M]\n\n/--\nThe strong pigeonhole principle for finitely many pigeons and pigeonholes. There is a pigeonhole\nwith at least as many pigeons as the ceiling of the average number of pigeons across all\npigeonholes. -/\nlemma exists_lt_card_fiber_of_nsmul_lt_card (hb : card \u03b2 \u2022 b < card \u03b1) :\n  \u2203 y : \u03b2, b < (univ.filter (\u03bb x, f x = y)).card :=\nlet \u27e8y, _, h\u27e9 := exists_lt_card_fiber_of_nsmul_lt_card_of_maps_to (\u03bb _ _, mem_univ _) hb in \u27e8y, h\u27e9\n\n/--\nThe strong pigeonhole principle for finitely many pigeons and pigeonholes.\nThere is a pigeonhole with at least as many pigeons as\nthe ceiling of the average number of pigeons across all pigeonholes.\n(\"The maximum is at least the mean\" specialized to integers.)\n\nMore formally, given a function `f` between finite types `\u03b1` and `\u03b2` and a number `n` such that\n`card \u03b2 * n < card \u03b1`, there exists an element `y : \u03b2` such that its preimage has more than `n`\nelements. -/\nlemma exists_lt_card_fiber_of_mul_lt_card (hn : card \u03b2 * n < card \u03b1) :\n  \u2203 y : \u03b2, n < (univ.filter (\u03bb x, f x = y)).card :=\nexists_lt_card_fiber_of_nsmul_lt_card _ hn\n\n/-- The strong pigeonhole principle for finitely many pigeons and pigeonholes. There is a pigeonhole\nwith at most as many pigeons as the floor of the average number of pigeons across all pigeonholes.\n-/\nlemma exists_card_fiber_lt_of_card_lt_nsmul (hb : \u2191(card \u03b1) < card \u03b2 \u2022 b) :\n  \u2203 y : \u03b2, \u2191((univ.filter $ \u03bb x, f x = y).card) < b :=\nlet \u27e8y, _, h\u27e9 := exists_card_fiber_lt_of_card_lt_nsmul hb in \u27e8y, h\u27e9\n\n/--\nThe strong pigeonhole principle for finitely many pigeons and pigeonholes.\nThere is a pigeonhole with at most as many pigeons as\nthe floor of the average number of pigeons across all pigeonholes.\n(\"The minimum is at most the mean\" specialized to integers.)\n\nMore formally, given a function `f` between finite types `\u03b1` and `\u03b2` and a number `n` such that\n`card \u03b1 < card \u03b2 * n`, there exists an element `y : \u03b2` such that its preimage has less than `n`\nelements. -/\nlemma exists_card_fiber_lt_of_card_lt_mul (hn : card \u03b1 < card \u03b2 * n) :\n  \u2203 y : \u03b2, (univ.filter (\u03bb x, f x = y)).card < n :=\nexists_card_fiber_lt_of_card_lt_nsmul _ hn\n\n/-- The strong pigeonhole principle for finitely many pigeons and pigeonholes.  Given a function `f`\nbetween finite types `\u03b1` and `\u03b2` and a number `b` such that `card \u03b2 \u2022 b \u2264 card \u03b1`, there exists an\nelement `y : \u03b2` such that its preimage has at least `b` elements.\nSee also `fintype.exists_lt_card_fiber_of_nsmul_lt_card` for a stronger statement. -/\nlemma exists_le_card_fiber_of_nsmul_le_card [nonempty \u03b2] (hb : card \u03b2 \u2022 b \u2264 card \u03b1) :\n  \u2203 y : \u03b2, b \u2264 (univ.filter $ \u03bb x, f x = y).card :=\nlet \u27e8y, _, h\u27e9 := exists_le_card_fiber_of_nsmul_le_card_of_maps_to (\u03bb _ _, mem_univ _) univ_nonempty\n  hb in \u27e8y, h\u27e9\n\n/-- The strong pigeonhole principle for finitely many pigeons and pigeonholes.  Given a function `f`\nbetween finite types `\u03b1` and `\u03b2` and a number `n` such that `card \u03b2 * n \u2264 card \u03b1`, there exists an\nelement `y : \u03b2` such that its preimage has at least `n` elements. See also\n`fintype.exists_lt_card_fiber_of_mul_lt_card` for a stronger statement. -/\nlemma exists_le_card_fiber_of_mul_le_card [nonempty \u03b2] (hn : card \u03b2 * n \u2264 card \u03b1) :\n  \u2203 y : \u03b2, n \u2264 (univ.filter (\u03bb x, f x = y)).card :=\nexists_le_card_fiber_of_nsmul_le_card _ hn\n\n/-- The strong pigeonhole principle for finitely many pigeons and pigeonholes.  Given a function `f`\nbetween finite types `\u03b1` and `\u03b2` and a number `b` such that `card \u03b1 \u2264 card \u03b2 \u2022 b`, there exists an\nelement `y : \u03b2` such that its preimage has at most `b` elements.\nSee also `fintype.exists_card_fiber_lt_of_card_lt_nsmul` for a stronger statement. -/\nlemma exists_card_fiber_le_of_card_le_nsmul [nonempty \u03b2] (hb : \u2191(card \u03b1) \u2264 card \u03b2 \u2022 b) :\n  \u2203 y : \u03b2, \u2191((univ.filter $ \u03bb x, f x = y).card) \u2264 b :=\nlet \u27e8y, _, h\u27e9 := exists_card_fiber_le_of_card_le_nsmul univ_nonempty hb in \u27e8y, h\u27e9\n\n/-- The strong pigeonhole principle for finitely many pigeons and pigeonholes.  Given a function `f`\nbetween finite types `\u03b1` and `\u03b2` and a number `n` such that `card \u03b1 \u2264 card \u03b2 * n`, there exists an\nelement `y : \u03b2` such that its preimage has at most `n` elements. See also\n`fintype.exists_card_fiber_lt_of_card_lt_mul` for a stronger statement. -/\nlemma exists_card_fiber_le_of_card_le_mul [nonempty \u03b2] (hn : card \u03b1 \u2264 card \u03b2 * n) :\n  \u2203 y : \u03b2, (univ.filter (\u03bb x, f x = y)).card \u2264 n :=\nexists_card_fiber_le_of_card_le_nsmul _ hn\n\nend fintype\n\nnamespace nat\n\nopen set\n\n/-- If `s` is an infinite set of natural numbers and `k > 0`, then `s` contains two elements `m < n`\nthat are equal mod `k`. -/\ntheorem exists_lt_modeq_of_infinite {s : set \u2115} (hs : s.infinite) {k : \u2115} (hk : 0 < k) :\n  \u2203 (m \u2208 s) (n \u2208 s), m < n \u2227 m \u2261 n [MOD k] :=\nhs.exists_lt_map_eq_of_maps_to (\u03bb n _, show n % k \u2208 Iio k, from nat.mod_lt n hk) $\n  finite_lt_nat k\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/pigeonhole.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7180519150087056}}
{"text": "------------------------------------------------------------------------\n-- Teor\u00eda elemental de funciones\n------------------------------------------------------------------------\n\nimport tactic\n\nopen function\n\nvariables {X Y Z : Type}\nvariables (a b x : X)\nvariable  (y : Y)\nvariable  (z : Z)\nvariables {f : X \u2192 Y}\nvariable  {g : Y \u2192 Z}\n\n------------------------------------------------------------------------\n-- \u00a7 Funciones inyectivas                                             --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1. Demostrar que\n--    injective f \u2194 \u2200 a b : X, f a = f b \u2192 a = b\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  injective f \u2194 \u2200 a b : X, f a = f b \u2192 a = b :=\nby refl\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  injective f \u2194 \u2200 a b : X, f a = f b \u2192 a = b :=\n-- by library_search\niff.rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    id x = x\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  id x = x :=\nrfl\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  id x = x :=\n-- by library_search\nid.def x\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que la funci\u00f3n identidad es inyectiva\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  injective (id : X \u2192 X) :=\nbegin\n  unfold injective,\n  intros a b hab,\n  rw id.def at hab,\n  rw id.def at hab,\n  exact hab,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  injective (id : X \u2192 X) :=\nbegin\n  intros a b hab,\n  rw id.def at hab,\n  rw id.def at hab,\n  exact hab,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  injective (id : X \u2192 X) :=\nbegin\n  intros a b hab,\n  iterate 2 {rw id.def at hab},\n  exact hab,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  injective (id : X \u2192 X) :=\nbegin\n  intros a b hab,\n  exact hab,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  injective (id : X \u2192 X) :=\n\u03bb a b hab, hab\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  injective (id : X \u2192 X) :=\n-- by library_search\ninjective_id\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  injective (id : X \u2192 X) :=\n-- by hint\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Demostrar que\n--    (g \u2218 f) x = g (f x)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) x = g (f x) :=\nrfl\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (g \u2218 f) x = g (f x) :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que la composici\u00f3n de dos funciones inyectivas\n-- es inyectiva.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (hf : injective f)\n  (hg : injective g)\n  : injective (g \u2218 f) :=\nbegin\n  intros a b h,\n  apply hf,\n  apply hg,\n  exact h,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (hf : injective f)\n  (hg : injective g)\n  : injective (g \u2218 f) :=\nbegin\n  intros a b h,\n  exact hf (hg h),\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (hf : injective f)\n  (hg : injective g)\n  : injective (g \u2218 f) :=\n\u03bb a b h, hf (hg h)\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (hf : injective f)\n  (hg : injective g)\n  : injective (g \u2218 f) :=\n-- by library_search\ninjective.comp hg hf\n\n------------------------------------------------------------------------\n-- \u00a7 Funciones suprayectivas                                          --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Demostrar que\n--    surjective f \u2194 \u2200 y : Y, \u2203 x : X, f x = y\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  surjective f \u2194 \u2200 y : Y, \u2203 x : X, f x = y :=\nby refl\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  surjective f \u2194 \u2200 y : Y, \u2203 x : X, f x = y :=\n-- by library_search\niff.rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Demostrar que la funci\u00f3n identidad es suprayectiva.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  surjective (id : X \u2192 X) :=\nbegin\n  intro x,\n  use x,\n  refl,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  surjective (id : X \u2192 X) :=\n\u03bb x, \u27e8x, rfl\u27e9\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  surjective (id : X \u2192 X) :=\n-- by library_search\nsurjective_id\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  surjective (id : X \u2192 X) :=\n-- by hint\nby tauto\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 8. Demostrar que la composici\u00f3n de dos funciones\n-- suprayectivas es supreyectiva.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (hf : surjective f)\n  (hg : surjective g)\n  : surjective (g \u2218 f) :=\nbegin\n  intro z,\n  cases hg z with y hy,\n  cases hf y with x hx,\n  use x,\n  show g(f(x)) = z,\n  rw hx,\n  exact hy,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (hf : surjective f)\n  (hg : surjective g)\n  : surjective (g \u2218 f) :=\nbegin\n  intro z,\n  cases hg z with y hy,\n  cases hf y with x hx,\n  use x,\n  dsimp,\n  convert hy,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (hf : surjective f)\n  (hg : surjective g)\n  : surjective (g \u2218 f) :=\n-- by library_search\nsurjective.comp hg hf\n\n------------------------------------------------------------------------\n-- \u00a7 Funciones biyectivas                                             --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 9. Demostrar que\n--    bijective f \u2194 injective f \u2227 surjective f\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  bijective f \u2194 injective f \u2227 surjective f :=\nby refl\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  bijective f \u2194 injective f \u2227 surjective f :=\n-- by suggest\niff.rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 10. Demostrar que la funci\u00f3n identidad es biyectiva.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  bijective (id : X \u2192 X) :=\n\u27e8injective_id, surjective_id\u27e9\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  bijective (id : X \u2192 X) :=\n-- by library_search\nbijective_id\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 12. Demostrar que la composici\u00f3n de dos funciones biyectivas\n-- es biyectiva.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (hf : bijective f)\n  (hg : bijective g)\n  : bijective (g \u2218 f) :=\nbegin\n  cases hf with hfi hfs,\n  cases hg with hgi hgs,\n  exact \u27e8injective.comp hgi hfi,\n         surjective.comp hgs hfs\u27e9\nend\n\n-- =====================================================================\n-- \u00a7 Referencias                                                      --\n-- =====================================================================\n\n-- + Kevin Buzzard. \"Formalising mathematics : workshop 1 \u2014 logic, sets,\n--   functions, relations\" https://bit.ly/3kJo231\n-- + Kevin Buzzard. formalising-mathematics: Part_C_functions.lean\n--   https://bit.ly/3EWExRb\n-- + Kevin Buzzard. formalising-mathematics: Part_C_functions_solutions.lean\n--   https://bit.ly/3CPs1Ba\n", "meta": {"author": "jaalonso", "repo": "Formalizacion_de_las_matematicas_en_Lean", "sha": "52bf9748d17a22d819cac19502fca9bc7340f7ae", "save_path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Formalizacion_de_las_matematicas_en_Lean/Formalizacion_de_las_matematicas_en_Lean-52bf9748d17a22d819cac19502fca9bc7340f7ae/src/1_Basica/3_Funciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893340314393, "lm_q2_score": 0.8757869786798663, "lm_q1q2_score": 0.7180519113536856}}
{"text": "/-\nCopyright (c) 2020 James Arthur. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: James Arthur, Chris Hughes, Shing Tak Lam\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.analysis.special_functions.trigonometric\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Inverse of the sinh function\n\nIn this file we prove that sinh is bijective and hence has an\ninverse, arsinh.\n\n## Main Results\n\n- `sinh_injective`: The proof that `sinh` is injective\n- `sinh_surjective`: The proof that `sinh` is surjective\n- `sinh_bijective`: The proof `sinh` is bijective\n- `arsinh`: The inverse function of `sinh`\n\n## Tags\n\narsinh, arcsinh, argsinh, asinh, sinh injective, sinh bijective, sinh surjective\n-/\n\nnamespace real\n\n\n/-- `arsinh` is defined using a logarithm, `arsinh x = log (x + sqrt(1 + x^2))`. -/\ndef arsinh (x : \u211d) : \u211d :=\n  log (x + sqrt (1 + x ^ bit0 1))\n\n/-- `sinh` is injective, `\u2200 a b, sinh a = sinh b \u2192 a = b`. -/\ntheorem sinh_injective : function.injective sinh :=\n  strict_mono.injective sinh_strict_mono\n\n/-- `arsinh` is the right inverse of `sinh`. -/\ntheorem sinh_arsinh (x : \u211d) : sinh (arsinh x) = x := sorry\n\n/-- `sinh` is surjective, `\u2200 b, \u2203 a, sinh a = b`. In this case, we use `a = arsinh b`. -/\ntheorem sinh_surjective : function.surjective sinh :=\n  function.left_inverse.surjective sinh_arsinh\n\n/-- `sinh` is bijective, both injective and surjective. -/\ntheorem sinh_bijective : function.bijective sinh :=\n  { left := sinh_injective, right := sinh_surjective }\n\n/-- A rearrangement and `sqrt` of `real.cosh_sq_sub_sinh_sq`. -/\ntheorem sqrt_one_add_sinh_sq (x : \u211d) : sqrt (1 + sinh x ^ bit0 1) = cosh x := sorry\n\n/-- `arsinh` is the left inverse of `sinh`. -/\ntheorem arsinh_sinh (x : \u211d) : arsinh (sinh x) = x :=\n  function.right_inverse_of_injective_of_left_inverse sinh_injective sinh_arsinh x\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/analysis/special_functions/arsinh.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7180519096924848}}
{"text": "\nimport data.vector\nimport data.real.basic\nimport init.data.list\n\nuniverses u \nvariables {\u03b1 : Type u} {n : \u2115} \n\n@[simp] def resize_constant (m : \u2115) (zero : \u03b1) : vector \u03b1 n \u2192 vector \u03b1 m\n| \u27e8l, p\u27e9 := \u27e8 list.take m (l ++ list.repeat zero m), by simp \u27e9\n\ntheorem resize_preserves_elements (zero : \u03b1) :\n\u2200 (n : \u2115) (v : vector \u03b1 n), \nv = resize_constant n zero v\n| n \u27e8l, p\u27e9 := begin\n  simp,\n  suffices len : n = l.length,\n  rw len,\n  simp,\n  symmetry,\n  rw p\nend\n\n/-\ntheorem resize_sensitivity (n : \u2115) (zero : \u03b1) [decidable_eq \u03b1] :\n\u2200 (v\u2081 : vector \u03b1 n) (v\u2082 : vector \u03b1 n) (m : \u2115),\nv\u2081 ~ v\u2082 \u2192 (resize_constant m zero v\u2081) ~ (resize_constant m zero v\u2082)\n| v\u2081 v\u2082 m := begin\n  intros neighbors,\n  simp,\n  suffices v\u2081_take : (resize_constant m zero v\u2081).to_list\n    = list.take m (v\u2081.to_list ++ list.repeat zero m),\n  suffices v\u2082_take : (resize_constant m zero v\u2082).to_list\n    = list.take m (v\u2082.to_list ++ list.repeat zero m),\n  rw [v\u2081_take, v\u2082_take],\n  suffices distrib : list.zip_with element_dist\n               (list.take m (v\u2081.to_list ++ list.repeat zero m))\n               (list.take m (v\u2082.to_list ++ list.repeat zero m))\n             = list.take m \n                 (list.zip_with element_dist\n                                (v\u2081.to_list ++ list.repeat zero m)\n                                (v\u2082.to_list ++ list.repeat zero m)),\n  rw distrib,\n  cases m,\n  simp\nend\n-/", "meta": {"author": "pjrule", "repo": "cs208-project", "sha": "951d3a5a65f01e1ccb85db8eeff3da1b26e69196", "save_path": "github-repos/lean/pjrule-cs208-project", "path": "github-repos/lean/pjrule-cs208-project/cs208-project-951d3a5a65f01e1ccb85db8eeff3da1b26e69196/lean/opendp/src/resize_vector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7179469202556026}}
{"text": "open classical\n\nvariables p q r s : Prop\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n  assume h,\n  by_cases\n    (assume hp,\n      (h hp).elim\n        (assume hr, or.inl (\u03bb hp, hr))\n        (assume hr, or.inr (\u03bb hp, hr)))\n    (assume hnp,\n      or.inl (\u03bb hp, absurd hp hnp))\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n  assume h,\n  by_cases\n    (assume hp,\n      suffices hnq : \u00acq, from or.inr hnq,\n      assume hq,\n      h \u27e8hp, hq\u27e9)\n    (assume hnp,\n      or.inl hnp)\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n  assume h,\n  by_cases\n    (assume hp,\n      suffices hnq : \u00acq, from \u27e8hp, hnq\u27e9,\n      assume hq,\n      h (\u03bb hp, hq))\n    (assume hnp,\n      suffices hp2q : p \u2192 q, from false.elim (h hp2q),\n      assume hp,\n      absurd hp hnp)\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n  assume hp2q,\n  by_cases\n    (assume hp,\n      or.inr (hp2q hp))\n    (assume hnp,\n      or.inl hnp)\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n  assume hnq2np hp,\n  by_cases\n    id\n    (assume hnq,\n      absurd hp (hnq2np hnq))\nexample : p \u2228 \u00acp := em p\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\n  assume h,\n  by_contradiction\n    (assume hnp,\n      have hp : p, from h (\u03bb hp, absurd hp hnp),\n      hnp hp)\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch3/ex0702.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7179469171913611}}
{"text": "import game.sup_inf.level03\nimport data.real.basic\n\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 4 \n-/\n\n/-\nA generalization of the result in the previous level.\n-/\n\n-- begin hide\n-- these three helper results to go in sidebar\nlemma two_real_ne_zero : (2:\u211d) \u2260 0 :=\nbegin\n    intro, linarith,\nend\n\nlemma avg_lt_max {mn mx: \u211d} (H : mn < mx) : (mn+mx) / 2 < mx :=\nbegin\n  apply (mul_lt_mul_right (show (0:\u211d)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_real_ne_zero)],\n  simp [H,mul_two],\nend\n\nlemma min_lt_avg {mn mx: \u211d} (H : mn < mx) : mn < (mn+mx) / 2 :=\nbegin\n  apply (mul_lt_mul_right (show (0:\u211d)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_real_ne_zero)],\n  simp [H,mul_two],\nend\n-- end hide\n\n/- Lemma\nA more general version of the previous level...\n-/\nlemma lub_open (y : \u211d) : is_lub {x : \u211d | x < y} y :=\nbegin\nsplit,\n{ intros a ha,\n  exact le_of_lt ha, \n},\n--unfold lower_bounds,\nintro b,\nintro Hb,\nrefine le_of_not_gt _,\nintro Hnb,\nlet c:=(b+y)/2,\n--unfold upper_bounds at Hb,\nhave H2 := Hb c,\nclear Hb,\nhave H : c \u2208 {x : \u211d | x < y},\n{ exact avg_lt_max Hnb,\n},\nhave Hcleb := H2 H,\nhave Hbltc : b < c := min_lt_avg Hnb,\nexact not_lt.2 Hcleb Hbltc,\nend\n\nend xena -- hide\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sup_inf/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7179469145542762}}
{"text": "import tactic.tauto\n\n@[derive decidable_eq]\ninductive mynat\n| zero : mynat\n| succ (n : mynat) : mynat\n\nnamespace mynat\n\ninstance : has_zero mynat := \u27e8mynat.zero\u27e9\n\ntheorem mynat_zero_eq_zero : mynat.zero = 0 := rfl\n\ndef one : mynat := succ 0\n\ninstance : has_one mynat := \u27e8mynat.one\u27e9\n\ntheorem one_eq_succ_zero : 1 = succ 0 := rfl\n\nlemma zero_ne_succ (m : mynat) : (0 : mynat) \u2260 succ m := \u03bb h, by cases h\n\nlemma succ_inj {m n : mynat} (h : succ m = succ n) : m = n := by cases h; refl\n\nend mynat\n\nattribute [symm] ne.symm\n\nnamespace mynat\n\n-- definition of \"addition on the natural numbers\"\ndef add : mynat \u2192 mynat \u2192 mynat\n| m 0 := m\n| m (succ n) := succ (add m n)\n\ninstance : has_add mynat := \u27e8mynat.add\u27e9\n\n-- numerals now work\nexample : mynat := 37\n\nlemma add_zero (m : mynat) : m + 0 = m := rfl\n\nlemma add_succ (m n : mynat) : m + succ n = succ (m + n) := rfl\n\n-- end of definition of \"addition on the natural numbers\"\n\nend mynat\n\nnamespace mynat\n\ndef mul : mynat \u2192 mynat \u2192 mynat\n| m zero := zero\n| m (succ n) := mul m n + m\n\ninstance : has_mul mynat := \u27e8mul\u27e9\n-- notation a * b := mul a b\n\nexample : (1 : mynat) * 1 = 1 := \nbegin\nrefl\nend\n\nlemma mul_zero (m : mynat) : m * 0 = 0 := rfl\n\nlemma mul_succ (m n : mynat) : m * (succ n) = m * n + m := rfl\n\ndef pow : mynat \u2192 mynat \u2192 mynat\n| m zero := one\n| m (succ n) := pow m n * m\n\ninstance : has_pow mynat mynat := \u27e8pow\u27e9\n-- notation a ^ b := pow a b\n\nexample : (1 : mynat) ^ (1 : mynat) = 1 := \nbegin\nrefl\nend\n\nlemma pow_zero (m : mynat) : m ^ (0 : mynat) = 1 := rfl\n\nlemma pow_succ (m n : mynat) : m ^ (succ n) = m ^ n * m := rfl\n\nend mynat\n\n------------------------------------------------------------------------\n\nnamespace mynat\n\nlemma example1 (x y z : mynat) : x + y + z = x + y + z :=\nbegin\nrefl,\nend\n\nlemma example1' (x y z : mynat) : x + y + z = x + y + z := rfl\n\nlemma example2 (x y : mynat) (h : y = x + 7) : 2 * y = 2 * (x + 7) := by rw h\n\nlemma example2' (x y : mynat) (h : y = x + 7) : 2 * y = 2 * (x + 7) :=\nbegin\n  rw h,\nend\n\nlemma example2'' (x y : mynat) (h : y = x + 7) : 2 * y = 2 * (x + 7) :=\nhave h_two_mul : 2 * y = 2 * y, from rfl,\nshow 2 * y = 2 * (x + 7), from (by rw h)\n\nlemma example3 (a b : mynat) (h : succ a = b) : succ(succ(a)) = succ(b) :=\nbegin\n  rw h,\nend\n\nlemma zero_add (n : mynat) : 0 + n = n :=\nbegin\n  induction n,\n  {\n    rw mynat_zero_eq_zero,\n    rw add_zero,\n  },\n  {\n    rw add_succ,\n    rw n_ih,\n  }\nend\n\nlemma add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) :=\nbegin\n  induction c,\n  {\n    rw mynat_zero_eq_zero,\n    rw add_zero (a + b),\n    rw add_zero b,\n  },\n  {\n    rw add_succ (a + b),\n    rw add_succ b,\n    rw add_succ a,\n    rw c_ih,\n  }\nend\n\nlemma succ_add (a b : mynat) : succ a + b = succ (a + b) :=\nbegin\n  induction b,\n  {\n    rw mynat_zero_eq_zero,\n    rw add_zero a,\n    rw add_zero (succ a),\n  },\n  {\n    rw add_succ a,\n    rw add_succ (succ a),\n    rw b_ih,\n  }\nend\n\nlemma add_comm (a b : mynat) : a + b = b + a :=\nbegin\n  induction b,\n  {\n    rw mynat_zero_eq_zero,\n    rw add_zero a,\n    induction a,\n    {\n      rw mynat_zero_eq_zero,\n      rw add_zero 0,\n    },\n    {\n      rw add_succ 0,\n      rw \u2190 a_ih,\n    }\n  },\n  {\n    rw succ_add b_n,\n    rw add_succ a,\n    rw b_ih,\n  }\nend\n\ntheorem succ_eq_add_one (n : mynat) : succ n = n + 1 :=\nbegin\n  rw one_eq_succ_zero,\n  rw add_succ n,\n  rw add_zero n,\nend\n\nlemma add_right_comm (a b c : mynat) : a + b + c = a + c + b :=\nbegin\n  induction c,\n  {\n    rw mynat_zero_eq_zero,\n    rw add_zero (a + b),\n    rw add_zero a,\n  },\n  {\n    rw add_succ (a + b),\n    rw add_succ a,\n    rw succ_add,\n    rw c_ih,\n  }\nend\n\n-- The proof in tactic mode\nlemma zero_mul (m : mynat) : 0 * m = 0 :=\nbegin\ninduction m,\n{\n-- Q0: Why do I need this extra line compared to in http://wwwf.imperial.ac.uk/~buzzard/xena/natural_number_game/?world=3&level=1\n  rw mynat_zero_eq_zero,\n  rw mul_zero 0,\n},\n{\n  rw mul_succ 0 m_n,\n  rw add_zero (0 * m_n),\n  rw m_ih,\n}\nend\n\n-- The proof of a forall version of the lemma\n-- ported from https://leanprover-community.github.io/mathlib_docs/core/init/data/nat/lemmas.html#nat.zero_mul\n-- Q1: Why does it need an extra refl than the original proof?\nlemma zero_mul_forall : \u2200 (m : mynat), 0 * m = 0\n| 0        := rfl\n| (succ m) := begin\n  rw [mul_succ, zero_mul_forall],\n  refl\nend\n\nlemma zero_mul_forall_match : \u2200 (m : mynat),  0 * m = 0\n| zero :=\ncalc zero * zero\n    = 0 * 0 : by rw mynat_zero_eq_zero\n... = 0 : by rw mul_zero 0\n| n@(succ m_n) :=\ncalc 0 * (succ m_n)\n    = 0 * m_n + 0 : by rw mul_succ\n... = 0 * m_n : by rw add_zero (0 * m_n)\n... = 0 : by rw zero_mul_forall_match m_n\n\nlemma zero_mul_forall_match_term : \u2200 (m : mynat),  0 * m = 0\n| zero :=\ncalc zero * zero\n    = 0 * 0 : by rw mynat_zero_eq_zero\n... = 0 : by rw mul_zero 0\n| n@(succ m_n) :=\ncalc 0 * (succ m_n)\n    = 0 * m_n + 0 : mul_succ 0 m_n\n... = 0 * m_n : add_zero (0 * m_n)\n... = 0 : by rw zero_mul_forall_match m_n\n\n-- Q2: how can I refer to the lemma itself in the match proof at <marker>\nlemma zero_mul_match (m : mynat) : 0 * m = 0 :=\nmatch m with\n| zero :=\ncalc zero * zero\n    = 0 * 0 : by rw mynat_zero_eq_zero\n... = 0 : by rw mul_zero 0\n| n@(succ m_n) :=\ncalc 0 * (succ m_n)\n    = 0 * m_n + 0 : by rw mul_succ\n... = 0 * m_n : by rw add_zero (0 * m_n)\n... = 0 : by sorry -- <marker>\nend\n\nlemma zero_mul_induction_zero : 0 * zero = 0 := rfl\n\nlemma zero_mul_induction_m_n : \u2200 (n : mynat), 0 * n = 0 \u2192 0 * n.succ = 0 :=\n\u03bb m_n h, add_zero (0 * m_n) \u25b8 mul_succ 0 m_n \u25b8 h\n\n-- Q3: Why `add_zero` is no longer needed?\nlemma zero_mul_induction_m_n' : \u2200 (n : mynat), 0 * n = 0 \u2192 0 * n.succ = 0 :=\n\u03bb m_n h, mul_succ 0 m_n \u25b8 h\n\nlemma zero_mul_rec (m : mynat) : 0 * m = 0 :=\nmynat.rec_on m zero_mul_induction_zero zero_mul_induction_m_n\n\nlemma zero_mul_rec' (m : mynat) : 0 * m = 0 :=\nmynat.rec_on m rfl (\u03bb m_n h, mul_succ 0 m_n \u25b8 h)\n\n-- lemma zero_mul_rec'' (m : mynat) : 0 * m = 0 :=\n-- m.rec_on zero_mul_induction_zero zero_mul_induction_m_n\n\n-- https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/Natural.20Numbers.20Game/near/199964443\n\nlemma mul_one (m : mynat) : m * 1 = m :=\nbegin\n  induction m,\n  {\n    rw one_eq_succ_zero,\n    rw mul_succ,\n    rw mul_zero,\n    refl\n  },\n  {\n    rw one_eq_succ_zero,\n    rw mul_succ,\n    rw mul_zero,\n    rw zero_add,\n  }\nend\n\nlemma one_mul (m : mynat) : 1 * m = m :=\nbegin\n  induction m,\n  {\n    rw mynat_zero_eq_zero,\n    rw mul_zero,\n  },\n  {\n    rw mul_succ,\n    rw succ_eq_add_one,\n    rw m_ih\n  }\nend\n\nlemma mul_add (t a b : mynat) : t * (a + b) = t * a + t * b :=\nbegin\n  induction b,\n  {\n    rw [mynat_zero_eq_zero, add_zero, mul_zero, add_zero],\n  },\n  {\n    rw mul_succ,\n    rw add_succ,\n    rw mul_succ,\n    rw b_ih,\n    rw add_assoc,\n  }\nend\n\nlemma mul_assoc (a b c : mynat) : (a * b) * c = a * (b * c) :=\nbegin\ninduction c,\n{\n  rw mynat_zero_eq_zero,\n  rw mul_zero (a * b),\n  rw mul_zero b,\n  rw mul_zero a,\n},\n{\n  rw mul_succ (a * b),\n  rw mul_succ b,\n  rw c_ih,\n  rw mul_add a,\n}\nend\n\nlemma succ_mul (a b : mynat) : succ a * b = a * b + b :=\nbegin\n  induction b,\n  {\n    rw mynat_zero_eq_zero,\n    rw mul_zero,\n    rw mul_zero,\n    rw add_zero,\n  },\n  {\n    rw mul_succ,\n    rw mul_succ,\n    rw add_succ,\n    rw add_succ,\n    rw b_ih,\n    rw add_assoc,\n    rw add_comm b_n a,\n    rw \u2190add_assoc,\n  }\nend\n\nlemma succ_mul' (a b : mynat) : succ a * b = a * b + b :=\nbegin\n  induction b,\n  {\n    rw mynat_zero_eq_zero,\n    rw mul_zero,\n    rw mul_zero,\n    rw add_zero,\n  },\n  {\n    rw mul_succ,\n    rw mul_succ,\n    rw add_succ,\n    rw add_succ,\n    rw b_ih,\n    rw add_right_comm,\n  }\nend\n\nlemma add_mul (a b t : mynat) : (a + b) * t = a * t + b * t :=\nbegin\n  induction t,\n  {\n    rw mynat_zero_eq_zero,\n    rw [mul_zero, mul_zero, mul_zero, add_zero],\n  },\n  {\n    rw [mul_succ, mul_succ, mul_succ],\n    rw t_ih,\n    rw add_right_comm,\n    rw add_comm (b * t_n) b,\n    rw \u2190add_assoc(a * t_n) a b,\n    rw add_assoc (a * t_n + a) b (b * t_n),\n  }\nend\n\nlemma mul_comm (a b : mynat) : a * b = b * a :=\nbegin\n  induction b,\n  {\n    rw mynat_zero_eq_zero,\n    rw [mul_zero, zero_mul],\n  },\n  {\n    rw [mul_succ, succ_mul, b_ih],\n  }\nend\n\nlemma mul_left_comm (a b c : mynat) : a * (b * c) = b * (a * c) :=\nbegin\n  rw \u2190mul_assoc b a c,\n  rw mul_comm b a,\n  rw mul_assoc a b c\nend\n\nlemma zero_pow_zero : (0 : mynat) ^ (0 : mynat) = 1 :=\nbegin\n  rw pow_zero,\nend\n\nlemma zero_pow_succ (m : mynat) : (0 : mynat) ^ (succ m) = 0 :=\nbegin\n  rw [pow_succ, mul_zero],\nend\n\nlemma pow_one (a : mynat) : a ^ (1 : mynat) = a :=\nby rw [one_eq_succ_zero, pow_succ, pow_zero, one_mul]\n\nlemma one_pow (m : mynat) : (1 : mynat) ^ m = 1 :=\nbegin\ninduction m with n h,\n{\n  rw mynat_zero_eq_zero,\n  rw pow_zero,\n},\n{\n  rw pow_succ,\n  rw h,\n  refl,\n}\nend\n\nlemma pow_add (a m n : mynat) : a ^ (m + n) = a ^ m * a ^ n :=\nbegin\n  induction n with k h,\n  {\n    rw mynat_zero_eq_zero,\n    rw pow_zero,\n    rw add_zero,\n    rw mul_one,\n  },\n  {\n    rw add_succ,\n    rw [pow_succ, pow_succ],\n    rw h,\n    rw mul_assoc (a ^ m) (a ^ k) a,\n  }\nend\n\nlemma mul_pow (a b n : mynat) : (a * b) ^ n = a ^ n * b ^ n :=\nbegin\ninduction n with k h,\n  {\n    rw mynat_zero_eq_zero,\n    rw [pow_zero, pow_zero, pow_zero],\n    refl,\n  },\n  {\n    rw [pow_succ, pow_succ, pow_succ],\n    rw h,\n    rw mul_assoc (a ^ k) (b ^ k) (a * b),\n    rw mul_left_comm (b ^ k) a b,\n    rw mul_assoc (a ^ k) a (b ^ k * b),\n  }\nend\n\nlemma pow_pow (a m n : mynat) : (a ^ m) ^ n = a ^ (m * n) :=\nbegin\n  induction n with k h,\n  {\n    rw mynat_zero_eq_zero,\n    rw [pow_zero, mul_zero, pow_zero],\n  },\n  {\n    rw [pow_succ, mul_succ],\n    rw h,\n    rw pow_add a (m * k) m,\n  }\nend\n\nlemma two_eq_succ_one : 2 = succ 1 := rfl\n\nlemma add_squared (a b : mynat) :\n  (a + b) ^ (2 : mynat) = a ^ (2 : mynat) + b ^ (2 : mynat) + 2 * a * b :=\nbegin\n  rw two_eq_succ_one,\n  rw one_eq_succ_zero,\n  rw [pow_succ, pow_succ, pow_succ, pow_succ, pow_succ, pow_succ],\n  rw [pow_zero, pow_zero, pow_zero],\n  rw [one_mul, one_mul, one_mul],\n  rw mul_add,\n  rw add_mul,\n  rw add_mul,\n  rw mul_comm b a,\n  rw succ_mul,\n  rw \u2190one_eq_succ_zero,\n  rw one_mul,\n  rw add_mul,\n  rw add_assoc (a * a) (a * b) (a * b + b * b),\n  rw add_assoc (a * a) (b * b) (a * b + a * b),\n  rw \u2190add_assoc  (b * b) (a * b) (a * b),\n  rw add_comm  (b * b) (a * b),\n  rw add_assoc (a * b) (b * b) (a * b),\n  rw add_comm (b * b) (a * b),\nend -- 28 rewrites\n\n-- https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/natural.20number.20game.20questions/near/196864644\nlemma add_squared' (a b : mynat) :\n  (a + b) ^ (2 : mynat) = a ^ (2 : mynat) + b ^ (2 : mynat) + 2 * a * b :=\nbegin\n  rw two_eq_succ_one,\n  rw pow_succ,\n  rw pow_succ,\n  rw pow_succ,\n  rw pow_one,\n  rw pow_one,\n  rw pow_one,\n  rw add_mul,\n  rw mul_add,\n  rw mul_add,\n  rw succ_mul,\n  rw one_mul,\n  rw add_mul,\n  rw mul_comm b a,\n  rw add_assoc,\n  rw add_assoc,\n  rw add_comm (b * b),\n  rw add_assoc,\nend\n\n-- Adapted from https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/natural.20number.20game.20questions/near/196867894\nlemma add_squared'' (a b : mynat) :\n  (a + b) ^ (2 : mynat) = a ^ (2 : mynat) + b ^ (2 : mynat) + 2 * a * b :=\nbegin\n  have two_mul: \u2200 x : mynat, (2:mynat) * x = x + x := \u03bbx, by rw [two_eq_succ_one, succ_mul 1 x, one_mul],\n  have pow_two: \u2200 x : mynat, x ^ (2:mynat) = x * x := \u03bbx, by rw [two_eq_succ_one, pow_succ, pow_one],\n  rw [pow_two, pow_two, pow_two],\n  rw [add_mul, two_mul, add_right_comm, add_mul],\n  rw [\u2190 add_assoc, \u2190 mul_add, mul_add b, mul_comm b, add_assoc]\nend\n\nexample (P Q : Type) (p : P) (h : P \u2192 Q) : Q :=\nbegin\n  exact h(p),\nend\n\nexample : mynat \u2192 mynat :=\nbegin\n  intro n,\n  exact 3*n+2,\nend\n\nexample (P Q R S T U: Type)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U :=\nbegin\n  have q : Q := h(p),\n  have t : T := j(q),\n  exact l(t),\nend\n\nexample (P Q R S T U: Type)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U :=\nbegin\n  apply l,\n  apply j,\n  apply h,\n  exact p,\nend\n\nexample (P Q : Type) : P \u2192 (Q \u2192 P) :=\nbegin\n  intros p q,\n  exact p,\nend\n\nexample (P Q R : Type) : (P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R)) :=\nbegin\n  intro pqr,\n  intro pq,\n  intro p,\n  have q : Q := pq(p),\n  exact pqr p q,\nend\n\nexample (P Q F : Type) : (P \u2192 Q) \u2192 ((Q \u2192 F) \u2192 (P \u2192 F)) :=\nbegin\n  intro pq,\n  intro qf,\n  intro p,\n  have q : Q := pq p,\n  exact qf q,\nend\n\nexample (P Q : Type) : (P \u2192 Q) \u2192 ((Q \u2192 empty) \u2192 (P \u2192 empty)) :=\nbegin\n  intro pq,\n  intro qe,\n  intro p,\n  apply qe,\n  apply pq,\n  exact p,\nend\n\nexample (A B C D E F G H I J K L : Type)\n(f1 : A \u2192 B) (f2 : B \u2192 E) (f3 : E \u2192 D) (f4 : D \u2192 A) (f5 : E \u2192 F)\n(f6 : F \u2192 C) (f7 : B \u2192 C) (f8 : F \u2192 G) (f9 : G \u2192 J) (f10 : I \u2192 J)\n(f11 : J \u2192 I) (f12 : I \u2192 H) (f13 : E \u2192 H) (f14 : H \u2192 K) (f15 : I \u2192 L)\n : A \u2192 L :=\nbegin\n  intro a,\n  apply f15,\n  apply f11,\n  have e : E := f2 (f1 a),\n  have j : J := f9 (f8 (f5 e)),\n  exact j,\nend\n\nexample (P Q : Prop) (p : P) (h : P \u2192 Q) : Q :=\nbegin\n  exact h(p),\nend\n\nlemma imp_self (P : Prop) : P \u2192 P :=\nbegin\n  intro p,\n  exact p,\nend\n\nlemma maze (P Q R S T U: Prop)\n(p : P)\n(h : P \u2192 Q)\n(i : Q \u2192 R)\n(j : Q \u2192 T)\n(k : S \u2192 T)\n(l : T \u2192 U)\n: U :=\nbegin\n  apply l,\n  have q : Q := h p,\n  exact j q,\nend\n\nexample (P Q : Prop) : P \u2192 (Q \u2192 P) :=\nbegin\n  intros p q,\n  exact p,\nend\n\nexample (P Q R : Prop) : (P \u2192 (Q \u2192 R)) \u2192 ((P \u2192 Q) \u2192 (P \u2192 R)) :=\nbegin\n  intros pqr pq p,\n  have q : Q := pq p,\n  exact pqr p q,\nend\n\nlemma imp_trans (P Q R : Prop) : (P \u2192 Q) \u2192 ((Q \u2192 R) \u2192 (P \u2192 R)) :=\nbegin\n  intros hpq hqr p,\n  exact hqr (hpq p),\nend\n\nlemma contrapositive (P Q : Prop) : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  repeat {rw not_iff_imp_false},\n  intro hpq,\n  intro nq,\n  intro p,\n  exact nq (hpq p),\nend\n\nexample (A B C D E F G H I J K L : Prop)\n(f1 : A \u2192 B) (f2 : B \u2192 E) (f3 : E \u2192 D) (f4 : D \u2192 A) (f5 : E \u2192 F)\n(f6 : F \u2192 C) (f7 : B \u2192 C) (f8 : F \u2192 G) (f9 : G \u2192 J) (f10 : I \u2192 J)\n(f11 : J \u2192 I) (f12 : I \u2192 H) (f13 : E \u2192 H) (f14 : H \u2192 K) (f15 : I \u2192 L)\n : A \u2192 L :=\nbegin\n  intro a,\n  apply f15,\n  apply f11,\n  exact f9 (f8 (f5 (f2 (f1 a)))),\nend\n\nexample (A B C D E F G H I J K L : Prop)\n(f1 : A \u2192 B) (f2 : B \u2192 E) (f3 : E \u2192 D) (f4 : D \u2192 A) (f5 : E \u2192 F)\n(f6 : F \u2192 C) (f7 : B \u2192 C) (f8 : F \u2192 G) (f9 : G \u2192 J) (f10 : I \u2192 J)\n(f11 : J \u2192 I) (f12 : I \u2192 H) (f13 : E \u2192 H) (f14 : H \u2192 K) (f15 : I \u2192 L)\n : A \u2192 L :=\nbegin\n  cc\nend\n\nexample (P Q : Prop) (p : P) (q : Q) : P \u2227 Q :=\nbegin\n  split,\n  exact p,\n  exact q,\nend\n\nlemma and_symm (P Q : Prop) : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  intro hpq,\n  cases hpq with p q,\n  split,\n  exact q,\n  exact p,\nend\n\nlemma and_trans (P Q R : Prop) : P \u2227 Q \u2192 Q \u2227 R \u2192 P \u2227 R :=\nbegin\n  intro hpq,\n  intro hqr,\n  cases hpq with p q,\n  split,\n  {\n    exact p,\n  },\n  {\n    cases hqr with q' r,\n    exact r,\n  }\nend\n\nlemma iff_trans (P Q R : Prop) : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intro hpq,\n  intro hqr,\n  split,\n  {\n    intro p,\n    cases hpq with pq qp,\n    cases hqr with qr rq,\n    exact qr (pq p),\n  },\n  {\n    intro r,\n    cases hpq,\n    cases hqr,\n    apply hpq_mpr,\n    apply hqr_mpr,\n    exact r,\n  }\nend\n\nlemma iff_trans' (P Q R : Prop) : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intros hpq hqr,\n  split,\n  {\n    intro p,\n    exact hqr.1 (hpq.1 p),\n  },\n  {\n    intro r,\n    exact hpq.2 (hqr.2 r),\n  }\nend\n\nlemma iff_trans'' (P Q R : Prop) : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  cc\nend\n\nlemma iff_trans''' (P Q R : Prop) : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intros hpq hqr,\n  rw hpq,\n  exact hqr,\nend\n\nexample (P Q : Prop) : Q \u2192 (P \u2228 Q) :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\nlemma or_symm (P Q : Prop) : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  intro hpq,\n  cases hpq with p q,\n  {\n    right,\n    exact p,\n  },\n  {\n    left,\n    exact q,\n  }\nend\n\nlemma and_or_distrib_left (P Q R : Prop) : P \u2227 (Q \u2228 R) \u2194 (P \u2227 Q) \u2228 (P \u2227 R) :=\nbegin\n  split,\n  {\n    intro pnqr,\n    cases pnqr with p qr,\n    cases qr with q r,\n    {\n      left,\n      split,\n      exact p,\n      exact q,\n    },\n    {\n      right,\n      split,\n      exact p,\n      exact r,\n    }\n  },\n  {\n    intro pqnpr,\n    cases pqnpr with pq pr,\n    {\n      cases pq with p q,\n      split,\n      exact p,\n      left,\n      exact q,\n    },\n    {\n      cases pr with p r,\n      split,\n      exact p,\n      right,\n      exact r,\n    }\n  }\nend\n\nlemma contra (P Q : Prop) : (P \u2227 \u00ac P) \u2192 Q := by tauto\n\nlemma contra' (P Q : Prop) : (P \u2227 \u00ac P) \u2192 Q :=\nbegin\n  intro h,\n  repeat {rw not_iff_imp_false at h},\n  cases h with p np,\n  exfalso,\n  exact np p,\nend\n\nlemma contra'' (P Q : Prop) : (P \u2227 \u00ac P) \u2192 Q :=\nbegin\n  intro h,\n  cases h with p np,\n  exfalso,\n  exact np p,\nend\n\nlocal attribute [instance, priority 10] classical.prop_decidable -- we are mathematicians\n\nlemma contrapositive2 (P Q : Prop) : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n  by_cases p : P; by_cases q : Q,\n  repeat {cc},\nend\n\nlemma contrapositive2' (P Q : Prop) : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n  tauto,\nend\n\n/-\n\nDark mode for http://wwwf.imperial.ac.uk/~buzzard/xena/natural_number_game/:\n\nbody, button, .accordion__button,.accordion__panel {\n    background-color: #202020 !important;\n    color: #cdcdcd;\n\n}\n\n.Resizer {\n    background-color: #535353 !important;\n}\n\n/*\nPress F12, choose Console, copy-paste the following and hit Enter:\n\nmonaco.editor.setTheme('vs-dark');\n*/\n\n-/\n\nend mynat", "meta": {"author": "utensil", "repo": "lean-playground", "sha": "77dc2dd18ea1498c766e09c3e488c2f9d3069ba6", "save_path": "github-repos/lean/utensil-lean-playground", "path": "github-repos/lean/utensil-lean-playground/lean-playground-77dc2dd18ea1498c766e09c3e488c2f9d3069ba6/lean3/src/ngn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.7179409898150108}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.normed.group.basic\nimport topology.metric_space.hausdorff_distance\n\n/-!\n# Properties of pointwise addition of sets in normed groups.\n\nWe explore the relationships between pointwise addition of sets in normed groups, and the norm.\nNotably, we show that the sum of bounded sets remain bounded.\n-/\n\nopen metric set\nopen_locale pointwise topological_space\n\nsection semi_normed_group\n\nvariables {E : Type*} [semi_normed_group E]\n\nlemma bounded_iff_exists_norm_le {s : set E} :\n  bounded s \u2194 \u2203 R, \u2200 x \u2208 s, \u2225x\u2225 \u2264 R :=\nby simp [subset_def, bounded_iff_subset_ball (0 : E)]\n\nalias bounded_iff_exists_norm_le \u2194 metric.bounded.exists_norm_le _\n\nlemma metric.bounded.exists_pos_norm_le {s : set E} (hs : metric.bounded s) :\n  \u2203 R > 0, \u2200 x \u2208 s, \u2225x\u2225 \u2264 R :=\nbegin\n  obtain \u27e8R\u2080, hR\u2080\u27e9 := hs.exists_norm_le,\n  refine \u27e8max R\u2080 1, _, _\u27e9,\n  { exact (by norm_num : (0:\u211d) < 1).trans_le (le_max_right R\u2080 1) },\n  intros x hx,\n  exact (hR\u2080 x hx).trans (le_max_left _ _),\nend\n\nlemma metric.bounded.add\n  {s t : set E} (hs : bounded s) (ht : bounded t) :\n  bounded (s + t) :=\nbegin\n  obtain \u27e8Rs, hRs\u27e9 : \u2203 (R : \u211d), \u2200 x \u2208 s, \u2225x\u2225 \u2264 R := hs.exists_norm_le,\n  obtain \u27e8Rt, hRt\u27e9 : \u2203 (R : \u211d), \u2200 x \u2208 t, \u2225x\u2225 \u2264 R := ht.exists_norm_le,\n  refine (bounded_iff_exists_norm_le).2 \u27e8Rs + Rt, _\u27e9,\n  rintros z \u27e8x, y, hx, hy, rfl\u27e9,\n  calc \u2225x + y\u2225 \u2264 \u2225x\u2225 + \u2225y\u2225 : norm_add_le _ _\n  ... \u2264 Rs + Rt : add_le_add (hRs x hx) (hRt y hy)\nend\n\n@[simp] lemma singleton_add_ball (x y : E) (r : \u211d) :\n  {x} + ball y r = ball (x + y) r :=\nby simp only [preimage_add_ball, image_add_left, singleton_add, sub_neg_eq_add, add_comm y x]\n\n@[simp] lemma ball_add_singleton (x y : E) (r : \u211d) :\n  ball x r + {y} = ball (x + y) r :=\nby simp [add_comm _ {y}, add_comm y]\n\nlemma singleton_add_ball_zero (x : E) (r : \u211d) :\n  {x} + ball 0 r = ball x r :=\nby simp\n\nlemma ball_zero_add_singleton (x : E) (r : \u211d) :\n  ball 0 r + {x} = ball x r :=\nby simp\n\n@[simp] lemma singleton_add_closed_ball (x y : E) (r : \u211d) :\n  {x} + closed_ball y r = closed_ball (x + y) r :=\nby simp only [add_comm y x, preimage_add_closed_ball, image_add_left, singleton_add, sub_neg_eq_add]\n\n@[simp] lemma closed_ball_add_singleton (x y : E) (r : \u211d) :\n  closed_ball x r + {y} = closed_ball (x + y) r :=\nby simp [add_comm _ {y}, add_comm y]\n\nlemma singleton_add_closed_ball_zero (x : E) (r : \u211d) :\n  {x} + closed_ball 0 r = closed_ball x r :=\nby simp\n\nlemma closed_ball_zero_add_singleton (x : E) (r : \u211d) :\n  closed_ball 0 r + {x} = closed_ball x r :=\nby simp\n\nlemma is_compact.cthickening_eq_add_closed_ball\n  {s : set E} (hs : is_compact s) {r : \u211d} (hr : 0 \u2264 r) :\n  cthickening r s = s + closed_ball 0 r :=\nbegin\n  rw hs.cthickening_eq_bUnion_closed_ball hr,\n  ext x,\n  simp only [mem_add, dist_eq_norm, exists_prop, mem_Union, mem_closed_ball,\n    exists_and_distrib_left, mem_closed_ball_zero_iff, \u2190 eq_sub_iff_add_eq', exists_eq_right],\nend\n\nend semi_normed_group\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/normed/group/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7179409773610588}}
{"text": "import tactic\nimport data.nat.gcd\nimport data.int.gcd\nimport data.int.basic\nimport data.nat.modeq\nimport data.nat.prime\nimport number_theory.divisors\nimport algebra.big_operators.basic\n--import geom_sum\n\n\n\ndef divisor_sum : \u2115 \u2192 \u2115 := (\u03bb n : \u2115, n.divisors.sum id)\n\n\nlemma perfect_iff_sum_divisors_eq_two_mul' (n : \u2115) (hpos : n > 0) : nat.perfect n \u2194 divisor_sum n = 2*n :=\nbegin\n  split, {\n    intro hn,\n    rwa nat.perfect_iff_sum_divisors_eq_two_mul at hn,\n    assumption,\n  }, {\n    intro hn,\n    rwa nat.perfect_iff_sum_divisors_eq_two_mul,\n    assumption,\n  }\nend\n\n\nlemma divisor_sum_is_multiplicative (m n : \u2115) (h_coprime : nat.gcd m n = 1) \n      : (divisor_sum(m*n) = divisor_sum(m) * divisor_sum(n)) :=\nbegin\n  unfold divisor_sum,\n  sorry,\nend\n\nlemma finite_power_series (a k : \u2115) : (finset.range k).sum (\u03bb (x : \u2115), (a ^ x)) = (a^k - 1)/(a-1) :=\nbegin\n  set S := (finset.range k).sum (\u03bb (x : \u2115), a ^ x),\n  suffices hS : S = 1 + a * (S - a^(k-1)),\n  sorry,\n  sorry,\nend\n\n-- lemma divisor_sum_of_prime_pow {p k : \u2115 } (hk : k \u2265 1) (hp : nat.prime p) : ((nat.divisors (p^(k-1))).sum id = (p^k - 1)/(p-1)) :=\n-- begin\n--   rw nat.sum_divisors_prime_pow hp,\n--   -- power series\n--   have hs1 : k - 1 + 1 = k := by linarith,\n--   rw hs1,\n--   rw finite_power_series p k,\n-- end\n\n-- lemma obvious_lemma (a : \u2115) (k \u2265 1) : (2 * 2 ^ (k - 1) = 2^k) :=\n-- begin\n--   set n := k + 1,\n--   induction n with d hd,\n-- end\n\n-- \u2203 k, 2^k - 1 prime \u2192 2^(k-1) * 2^k - 1 is perfect\n\nlemma mersenne_to_perfect (k : \u2115) (hk : k > 0) (hp : nat.prime (2^k - 1)) : (nat.perfect ( 2^(k-1) * (2^k - 1))) :=\nbegin\n  rw perfect_iff_sum_divisors_eq_two_mul',\n  { \n    rw divisor_sum_is_multiplicative,\n    {\n      unfold divisor_sum,\n      rw nat.prime.sum_divisors hp,\n      have h2 : nat.prime 2 := nat.prime_two,\n      rw nat.divisors_prime_pow h2,\n      simp,\n      have hs : k - 1 + 1 = k := by linarith,\n      rw hs,\n      rw finite_power_series 2 k,\n\n\n      rw \u2190 mul_assoc,\n      have hpow : 2^k \u2265 1 := nat.one_le_pow' k 1,\n      have hs1: 2^k - 1 + 1 = 2^k := by linarith,\n      have hs2 : 2 * 2 ^ (k - 1) = 2^k,\n      {\n        zify,\n        sorry,\n      },\n      rw [hs1, hs2, mul_comm],\n    },\n\n    {\n      set d : \u2115 := nat.gcd (2 ^ (k - 1)) (2 ^ k - 1),\n      \n      \n      \n    },\n\n  },\n\n  { simpa using nat.one_lt_two_pow k hk, },\n\n\nend\n\n\n-- n is an even perfect number \u2192 n = 2^(k-1) * (2^k - 1) for some mersenne prime 2^k - 1", "meta": {"author": "raymondpg", "repo": "XLL", "sha": "f97237922687d0edfa3fdab4c9cb831b39284e49", "save_path": "github-repos/lean/raymondpg-XLL", "path": "github-repos/lean/raymondpg-XLL/XLL-f97237922687d0edfa3fdab4c9cb831b39284e49/src/Zachary/perfect_mersenne.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7178831943761214}}
{"text": "/-\nCopyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bryan Gin-ge Chen\n-/\nimport algebra.punit_instances\nimport order.hom.lattice\nimport tactic.abel\nimport tactic.ring\n\n/-!\n# Boolean rings\n\nA Boolean ring is a ring where multiplication is idempotent. They are equivalent to Boolean\nalgebras.\n\n## Main declarations\n\n* `boolean_ring`: a typeclass for rings where multiplication is idempotent.\n* `boolean_ring.to_boolean_algebra`: every Boolean ring is a Boolean algebra; this definition and\n  the `sup` and `inf` notations for `boolean_ring` are localized as instances in the\n  `boolean_algebra_of_boolean_ring` locale.\n\n## Tags\n\nboolean ring, boolean algebra\n\n-/\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\n/-- A Boolean ring is a ring where multiplication is idempotent. -/\nclass boolean_ring \u03b1 extends ring \u03b1 :=\n(mul_self : \u2200 a : \u03b1, a * a = a)\n\nsection boolean_ring\nvariables [boolean_ring \u03b1] (a b : \u03b1)\n\ninstance : is_idempotent \u03b1 (*) := \u27e8boolean_ring.mul_self\u27e9\n\n@[simp] lemma mul_self : a * a = a := boolean_ring.mul_self _\n\n@[simp] lemma add_self : a + a = 0 :=\nhave a + a = a + a + (a + a) :=\n  calc a + a = (a+a) * (a+a)           : by rw mul_self\n         ... = a*a + a*a + (a*a + a*a) : by rw [add_mul, mul_add]\n         ... = a + a + (a + a)         : by rw mul_self,\nby rwa self_eq_add_left at this\n\n@[simp] lemma neg_eq : -a = a :=\ncalc -a = -a + 0      : by rw add_zero\n    ... = -a + -a + a : by rw [\u2190neg_add_self, add_assoc]\n    ... = a           : by rw [add_self, zero_add]\n\nlemma add_eq_zero : a + b = 0 \u2194 a = b :=\ncalc a + b = 0 \u2194 a = -b : add_eq_zero_iff_eq_neg\n           ... \u2194 a = b  : by rw neg_eq\n\n@[simp] lemma mul_add_mul : a*b + b*a = 0 :=\nhave a + b = a + b + (a*b + b*a) :=\n  calc a + b = (a + b) * (a + b)       : by rw mul_self\n         ... = a*a + a*b + (b*a + b*b) : by rw [add_mul, mul_add, mul_add]\n         ... = a + a*b + (b*a + b)     : by simp only [mul_self]\n         ... = a + b + (a*b + b*a)     : by abel,\nby rwa self_eq_add_right at this\n\n@[simp] lemma sub_eq_add : a - b = a + b :=\nby rw [sub_eq_add_neg, add_right_inj, neg_eq]\n\n@[simp] lemma mul_one_add_self : a * (1 + a) = 0 := by rw [mul_add, mul_one, mul_self, add_self]\n\n@[priority 100] -- Note [lower instance priority]\ninstance boolean_ring.to_comm_ring : comm_ring \u03b1 :=\n{ mul_comm := \u03bb a b, by rw [\u2190add_eq_zero, mul_add_mul],\n  .. (infer_instance : boolean_ring \u03b1) }\n\nend boolean_ring\n\ninstance : boolean_ring punit := \u27e8\u03bb _, subsingleton.elim _ _\u27e9\n\n/-! ### Turning a Boolean ring into a Boolean algebra -/\n\n/-- Type synonym to view a Boolean ring as a Boolean algebra. -/\ndef as_boolalg (\u03b1 : Type*) := \u03b1\n\n/-- The \"identity\" equivalence between `as_boolalg \u03b1` and `\u03b1`. -/\ndef to_boolalg : \u03b1 \u2243 as_boolalg \u03b1 := equiv.refl _\n\n/-- The \"identity\" equivalence between `\u03b1` and `as_boolalg \u03b1`. -/\ndef of_boolalg : as_boolalg \u03b1 \u2243 \u03b1 := equiv.refl _\n\n@[simp] lemma to_boolalg_symm_eq : (@to_boolalg \u03b1).symm = of_boolalg := rfl\n@[simp] lemma of_boolalg_symm_eq : (@of_boolalg \u03b1).symm = to_boolalg := rfl\n@[simp] lemma to_boolalg_of_boolalg (a : as_boolalg \u03b1) : to_boolalg (of_boolalg a) = a := rfl\n@[simp] lemma of_boolalg_to_boolalg (a : \u03b1) : of_boolalg (to_boolalg a) = a := rfl\n@[simp] lemma to_boolalg_inj {a b : \u03b1} : to_boolalg a = to_boolalg b \u2194 a = b := iff.rfl\n@[simp] lemma of_boolalg_inj {a b : as_boolalg \u03b1} : of_boolalg a = of_boolalg b \u2194 a = b := iff.rfl\n\ninstance [inhabited \u03b1] : inhabited (as_boolalg \u03b1) := \u2039inhabited \u03b1\u203a\n\nnamespace boolean_ring\nvariables [boolean_ring \u03b1]\n\n/-- The join operation in a Boolean ring is `x + y + x * y`. -/\ndef has_sup : has_sup \u03b1 := \u27e8\u03bb x y, x + y + x * y\u27e9\n/-- The meet operation in a Boolean ring is `x * y`. -/\ndef has_inf : has_inf \u03b1 := \u27e8(*)\u27e9\n\n-- Note [lower instance priority]\nlocalized \"attribute [instance, priority 100] boolean_ring.has_sup\" in\n  boolean_algebra_of_boolean_ring\nlocalized \"attribute [instance, priority 100] boolean_ring.has_inf\" in\n  boolean_algebra_of_boolean_ring\n\nlemma sup_comm (a b : \u03b1) : a \u2294 b = b \u2294 a := by { dsimp only [(\u2294)], ring }\nlemma inf_comm (a b : \u03b1) : a \u2293 b = b \u2293 a := by { dsimp only [(\u2293)], ring }\n\nlemma sup_assoc (a b c : \u03b1) : a \u2294 b \u2294 c = a \u2294 (b \u2294 c) := by { dsimp only [(\u2294)], ring }\nlemma inf_assoc (a b c : \u03b1) : a \u2293 b \u2293 c = a \u2293 (b \u2293 c) := by { dsimp only [(\u2293)], ring }\n\nlemma sup_inf_self (a b : \u03b1) : a \u2294 a \u2293 b = a :=\nby { dsimp only [(\u2294), (\u2293)], assoc_rw [mul_self, add_self, add_zero] }\nlemma inf_sup_self (a b : \u03b1) : a \u2293 (a \u2294 b) = a :=\nby { dsimp only [(\u2294), (\u2293)], assoc_rw [mul_add, mul_add, mul_self, mul_self, add_self, add_zero] }\n\n\n\nlemma le_sup_inf (a b c : \u03b1) : (a \u2294 b) \u2293 (a \u2294 c) \u2294 (a \u2294 b \u2293 c) = a \u2294 b \u2293 c :=\nby { dsimp only [(\u2294), (\u2293)], rw [le_sup_inf_aux, add_self, mul_self, zero_add] }\n\n/--\nThe Boolean algebra structure on a Boolean ring.\n\nThe data is defined so that:\n* `a \u2294 b` unfolds to `a + b + a * b`\n* `a \u2293 b` unfolds to `a * b`\n* `a \u2264 b` unfolds to `a + b + a * b = b`\n* `\u22a5` unfolds to `0`\n* `\u22a4` unfolds to `1`\n* `a\u1d9c` unfolds to `1 + a`\n* `a \\ b` unfolds to `a * (1 + b)`\n-/\ndef to_boolean_algebra : boolean_algebra \u03b1 :=\nboolean_algebra.of_core\n{ le_sup_inf := le_sup_inf,\n  top := 1,\n  le_top := \u03bb a, show a + 1 + a * 1 = 1, by assoc_rw [mul_one, add_comm, add_self, add_zero],\n  bot := 0,\n  bot_le := \u03bb a, show 0 + a + 0 * a = a, by rw [zero_mul, zero_add, add_zero],\n  compl := \u03bb a, 1 + a,\n  inf_compl_le_bot := \u03bb a,\n    show a*(1+a) + 0 + a*(1+a)*0 = 0,\n    by norm_num [mul_add, mul_self, add_self],\n  top_le_sup_compl := \u03bb a,\n    begin\n      change 1 + (a + (1+a) + a*(1+a)) + 1*(a + (1+a) + a*(1+a)) = a + (1+a) + a*(1+a),\n      norm_num [mul_add, mul_self],\n      rw [\u2190add_assoc, add_self],\n    end,\n  .. lattice.mk' sup_comm sup_assoc inf_comm inf_assoc sup_inf_self inf_sup_self }\n\nlocalized \"attribute [instance, priority 100] boolean_ring.to_boolean_algebra\" in\n  boolean_algebra_of_boolean_ring\n\nend boolean_ring\n\nvariables [boolean_ring \u03b1] [boolean_ring \u03b2] [boolean_ring \u03b3]\n\ninstance : boolean_algebra (as_boolalg \u03b1) := @boolean_ring.to_boolean_algebra \u03b1 _\n\n@[simp] lemma of_boolalg_top : of_boolalg (\u22a4 : as_boolalg \u03b1) = 1 := rfl\n@[simp] lemma of_boolalg_bot : of_boolalg (\u22a5 : as_boolalg \u03b1) = 0 := rfl\n\n@[simp] lemma of_boolalg_sup (a b : as_boolalg \u03b1) :\n  of_boolalg (a \u2294 b) = of_boolalg a + of_boolalg b + of_boolalg a * of_boolalg b := rfl\n\n@[simp] lemma of_boolalg_inf (a b : as_boolalg \u03b1) :\n  of_boolalg (a \u2293 b) = of_boolalg a * of_boolalg b := rfl\n\n@[simp] lemma to_boolalg_zero : to_boolalg (0 : \u03b1) = \u22a5 := rfl\n@[simp] lemma to_boolalg_one : to_boolalg (1 : \u03b1) = \u22a4 := rfl\n\n@[simp] lemma to_boolalg_mul (a b : \u03b1) :\n  to_boolalg (a * b) = to_boolalg a \u2293 to_boolalg b := rfl\n\n@[simp] lemma to_boolalg_add_add_mul (a b : \u03b1) :\n  to_boolalg (a + b + a * b) = to_boolalg a \u2294 to_boolalg b := rfl\n\n/-- Turn a ring homomorphism from Boolean rings `\u03b1` to `\u03b2` into a bounded lattice homomorphism\nfrom `\u03b1` to `\u03b2` considered as Boolean algebras. -/\n@[simps] protected def ring_hom.as_boolalg (f : \u03b1 \u2192+* \u03b2) :\n  bounded_lattice_hom (as_boolalg \u03b1) (as_boolalg \u03b2) :=\n{ to_fun := to_boolalg \u2218 f \u2218 of_boolalg,\n  map_sup' := \u03bb a b, begin\n    dsimp,\n    simp_rw [map_add f, map_mul f],\n    refl,\n  end,\n  map_inf' := f.map_mul',\n  map_top' := f.map_one',\n  map_bot' := f.map_zero' }\n\n@[simp] lemma ring_hom.as_boolalg_id : (ring_hom.id \u03b1).as_boolalg = bounded_lattice_hom.id _ := rfl\n\n@[simp] lemma ring_hom.as_boolalg_comp (g : \u03b2 \u2192+* \u03b3) (f : \u03b1 \u2192+* \u03b2) :\n  (g.comp f).as_boolalg = g.as_boolalg.comp f.as_boolalg := rfl\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/ring/boolean_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7177856303842538}}
{"text": "import data.real.basic\nimport algebra.pi_instances\nimport tuto_lib\n\nnotation `|`x`|` := abs x\n\n/-\nIn this file we manipulate the elementary definition of limits of\nsequences of real numbers. \nmathlib has a much more general definition of limits, but here\nwe want to practice using the logical operators and relations\ncovered in the previous files.\n\nA sequence u is a function from \u2115 to \u211d, hence Lean says\nu : \u2115 \u2192 \u211d\nThe definition we'll be using is:\n\n-- Definition of \u00ab u tends to l \u00bb\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\nNote the use of `\u2200 \u03b5 > 0, ...` which is an abbreviation of\n`\u2200 \u03b5, \u03b5 > 0 \u2192 ... `\n\nIn particular, a statement like `h : \u2200 \u03b5 > 0, ...`\ncan be specialized to a given \u03b5\u2080 by\n  `specialize h \u03b5\u2080 h\u03b5\u2080`\nwhere h\u03b5\u2080 is a proof of \u03b5\u2080 > 0.\n\nAlso recall that, wherever Lean expects some proof term, we can\nstart a tactic mode proof using the keyword `by` (followed by curly braces\nif you need more than one tactic invocation).\nFor instance, if the local context contains:\n\n\u03b4 : \u211d\n\u03b4_pos : \u03b4 > 0\nh : \u2200 \u03b5 > 0, ...\n\nthen we can specialize h to the real number \u03b4/2 using:\n  `specialize h (\u03b4/2) (by linarith)`\nwhere `by linarith` will provide the proof of `\u03b4/2 > 0` expected by Lean.\n\nWe'll take this opportunity to use two new tactics:\n\n`norm_num` will perform numerical normalization on the goal and `norm_num at h` \nwill do the same in assumption `h`. This will get rid of trivial calculations on numbers,\nlike replacing |l - l| by zero in the next exercise.\n\n`congr'` will try to prove equalities between applications of functions by recursively \nproving the arguments are the same. \nFor instance, if the goal is `f x + g y = f z + g t` then congr will replace it by\ntwo goals: `x = z` and `y = t`.\nYou can limit the recursion depth by specifying a natural number after `congr'`. \nFor instance, in the above example, `congr' 1` will give new goals\n`f x = f z` and `g y = g t`, which only inspect arguments of the addition and not deeper.\n-/\n\nvariables (u v w : \u2115 \u2192 \u211d) (l l' : \u211d)\n\n-- If u is constant with value l then u tends to l\n-- 0033\nexample : (\u2200 n, u n = l) \u2192 seq_limit u l :=\nbegin\n  -- sorry\n  intros h \u03b5 \u03b5_pos,\n  use 0,\n  intros n hn,\n  rw h,\n  norm_num,\n  linarith,\n  -- sorry\nend\n\n/- When dealing with absolute values, we'll use lemmas:\n\nabs_le (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nabs_add (x y : \u211d) : |x + y| \u2264 |x| + |y|\n\nabs_sub (x y : \u211d) : |x - y| = |y - x|\n\nYou should probably write them down on a sheet of paper that you keep at \nhand since they are used in many exercises.\n-/\n\n-- Assume l > 0. Then u tends to l implies u n \u2265 l/2 for large enough n\n-- 0034\nexample (hl : l > 0) : seq_limit u l \u2192 \u2203 N, \u2200 n \u2265 N, u n \u2265 l/2 :=\nbegin\n  -- sorry\n  intro h,\n  cases h (l/2) (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_le at hN,\n  linarith,\n  -- sorry\nend\n\n/- \nWhen dealing with max, you can use\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\nYou should probably add them to the sheet of paper where you wrote \nthe `abs` lemmas since they are used in many exercises.\n\nLet's see an example.\n-/\n\n-- If u tends to l and v tends l' then u+v tends to l+l'\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\nseq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  cases ge_max_iff.mp hn with hn\u2081 hn\u2082,\n  have fact\u2081 : |u n - l| \u2264 \u03b5/2,\n    from hN\u2081 n (by linarith),  -- note the use of `from`.\n                               -- This is an alias for `exact`, \n                               -- but reads nicer in this context \n  have fact\u2082 : |v n - l'| \u2264 \u03b5/2,\n    from hN\u2082 n (by linarith), \n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1 ; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith,\nend\n\n/-\nIn the above proof, we used `have` to prepare facts for `linarith` consumption in the last line.\nSince we have direct proof terms for them, we can feed them directly to `linarith` as in the next proof\nof the same statement.\nAnother variation we introduce is rewriting using `ge_max_iff` and letting `linarith` handle the\nconjunction, instead of creating two new assumptions.\n-/\n\nexample (hu : seq_limit u l) (hv : seq_limit v l') :\nseq_limit (u + v) (l + l') :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  rw ge_max_iff at hn,\n  calc\n  |(u + v) n - (l + l')| = |u n + v n - (l + l')|   : rfl\n                     ... = |(u n - l) + (v n - l')| : by congr' 1 ; ring\n                     ... \u2264 |u n - l| + |v n - l'|   : by apply abs_add\n                     ... \u2264  \u03b5                       : by linarith [hN\u2081 n (by linarith), hN\u2082 n (by linarith)],\nend\n\n/- Let's do something similar: the squeezing theorem. -/\n-- 0035\nexample (hu : seq_limit u l) (hw : seq_limit w l)\n(h : \u2200 n, u n \u2264 v n)\n(h' : \u2200 n, v n \u2264 w n) : seq_limit v l :=\nbegin\n  -- sorry\n  intros \u03b5 \u03b5_pos,\n  cases hu \u03b5 \u03b5_pos with N hN,\n  cases hw \u03b5 \u03b5_pos with N' hN',\n  use max N N',\n  intros n hn,\n  rw ge_max_iff at hn,\n  specialize hN n (by linarith),\n  specialize hN' n (by linarith),\n  specialize h n,\n  specialize h' n,\n  rw abs_le at *,\n  split,\n  -- Here `linarith` can finish, but on paper we would write\n  calc -\u03b5 \u2264 u n - l : by linarith\n      ... \u2264 v n - l : by linarith,\n  calc v n - l \u2264 w n - l : by linarith\n      ... \u2264 \u03b5 : by linarith,\n  -- sorry\n\nend\n\n/- What about < \u03b5? -/\n-- 0036\nexample (u l) : seq_limit u l \u2194\n \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5 :=\nbegin\n  -- sorry\n  split,\n  { intros hyp \u03b5 \u03b5_pos,\n    cases hyp (\u03b5/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    calc |u n - l| \u2264 \u03b5/2 : by exact hN n hn\n              ...  < \u03b5   : by linarith, },\n  { intros hyp \u03b5 \u03b5_pos,\n    cases hyp \u03b5 \u03b5_pos with N hN,\n    use N,\n    intros n hn,\n    specialize hN n hn,\n    linarith, },\n  -- sorry\nend\n\n/- In the next exercise, we'll use\n\neq_of_abs_sub_le_all (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y\n-/\n\n-- A sequence admits at most one limit\n-- 0037\nexample : seq_limit u l \u2192 seq_limit u l' \u2192 l = l' :=\nbegin\n  -- sorry\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros \u03b5 \u03b5_pos,\n  cases hl (\u03b5/2) (by linarith) with N hN,\n  cases hl' (\u03b5/2) (by linarith) with N' hN',\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring\n  ... \u2264 |l - u (max N N')| + |u (max N N') - l'| : by apply abs_add\n  ... =  |u (max N N') - l| + |u (max N N') - l'| : by rw abs_sub\n  ... \u2264 \u03b5 : by linarith [hN (max N N') (le_max_left _ _), hN' (max N N') (le_max_right _ _)]\n  -- sorry\nend\n\n/-\nLet's now practice deciphering definitions before proving.\n-/\n\ndef non_decreasing (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\ndef is_seq_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n-- 0038\nexample (M : \u211d) (h : is_seq_sup M u) (h' : non_decreasing u) :\nseq_limit u M :=\nbegin\n  -- sorry\n  intros \u03b5 \u03b5_pos,\n  cases h with inf_M sup_M_ep,\n  cases sup_M_ep \u03b5 \u03b5_pos with n\u2080 hn\u2080,\n  use n\u2080,\n  intros n hn,\n  rw abs_le,\n  split; linarith [inf_M n, h' n\u2080 n hn],\n  -- sorry\nend\n", "meta": {"author": "kris-brown", "repo": "theorem_proving_in_lean", "sha": "774460c21bf857daff158210741bd88d1c8323cd", "save_path": "github-repos/lean/kris-brown-theorem_proving_in_lean", "path": "github-repos/lean/kris-brown-theorem_proving_in_lean/theorem_proving_in_lean-774460c21bf857daff158210741bd88d1c8323cd/tutorial_src/solutions/05_sequence_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314707995588, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7177856259106319}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    f '' (s \u222a t) = (f '' s) \u222a (f '' t) \n-- ----------------------------------------------------------------------\n\nimport data.set.function\n\nuniverses u v\nvariable  \u03b1 : Type u\nvariable  \u03b2 : Type v\nvariable  f : \u03b1 \u2192 \u03b2\nvariables s t : set \u03b1\n\nexample : f '' (s \u222a t) = (f '' s) \u222a (f '' t) :=\nbegin\n  ext y, \n  split,\n  { rintros \u27e8x, xs | xt, rfl\u27e9,\n    { left, \n      use [x, xs] },\n    { right, \n      use [x, xt] }},\n  { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9),\n    { use [x, or.inl xs] },\n    { use [x, or.inr xt] }},\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u,\n\u03b2 : Type v,\nf : \u03b1 \u2192 \u03b2,\ns t : set \u03b1\n\u22a2 f '' (s \u222a t) = f '' s \u222a f '' t\n  >> ext y, \ny : \u03b2\n\u22a2 y \u2208 f '' (s \u222a t) \u2194 y \u2208 f '' s \u222a f '' t\n  >> split,\n| \u22a2 y \u2208 f '' (s \u222a t) \u2192 y \u2208 f '' s \u222a f '' t\n|   >> { rintros \u27e8x, xs | xt, rfl\u27e9,\n| | \u22a2 f x \u2208 f '' s \u222a f '' t\n| |   >>   { left,\n| | \u22a2 f x \u2208 f '' s \n| |   >>     use [x, xs] },\n| \u22a2 f x \u2208 f '' s \u222a f '' t\n|   >>   { right, \n| \u22a2 f x \u2208 f '' t\n|   >>     use [x, xt] }},\n\u22a2 y \u2208 f '' s \u222a f '' t \u2192 y \u2208 f '' (s \u222a t)\n  >> { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9),\n| x : \u03b1,\n| xs : x \u2208 s\n| \u22a2 f x \u2208 f '' (s \u222a t)\n|   >>   { use [x, or.inl xs] },\nxt : x \u2208 t\n\u22a2 f x \u2208 f '' (s \u222a t)\n  >>   { use [x, or.inr xt] }},\nno goals\n-/\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Imagen_de_la_union.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.7177856194099228}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n\n! This file was ported from Lean 3 source module data.rat.denumerable\n! leanprover-community/mathlib commit dde670c9a3f503647fd5bfdf1037bad526d3397a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.SetTheory.Cardinal.Basic\n\n/-!\n# Denumerability of \u211a\n\nThis file proves that \u211a is infinite, denumerable, and deduces that it has cardinality `omega`.\n-/\n\n\nnamespace Rat\n\nopen Denumerable\n\ninstance : Infinite \u211a :=\n  Infinite.of_injective ((\u2191) : \u2115 \u2192 \u211a) Nat.cast_injective\n\nprivate def denumerable_aux : \u211a \u2243 { x : \u2124 \u00d7 \u2115 // 0 < x.2 \u2227 x.1.natAbs.coprime x.2 }\n    where\n  toFun x := \u27e8\u27e8x.1, x.2\u27e9, Nat.pos_of_ne_zero x.3, x.4\u27e9\n  invFun x := \u27e8x.1.1, x.1.2, ne_zero_of_lt x.2.1, x.2.2\u27e9\n  left_inv := fun \u27e8_, _, _, _\u27e9 => rfl\n  right_inv := fun \u27e8\u27e8_, _\u27e9, _, _\u27e9 => rfl\n\n/-- **Denumerability of the Rational Numbers** -/\ninstance : Denumerable \u211a := by\n  let T := { x : \u2124 \u00d7 \u2115 // 0 < x.2 \u2227 x.1.natAbs.coprime x.2 }\n  letI : Infinite T := Infinite.of_injective _ denumerable_aux.injective\n  letI : Encodable T := Encodable.Subtype.encodable\n  letI : Denumerable T := ofEncodableOfInfinite T\n  exact Denumerable.ofEquiv T denumerable_aux\n\nend Rat\n\nopen Cardinal\n\ntheorem Cardinal.mkRat : (#\u211a) = \u2135\u2080 := by simp only [mk_eq_aleph0]\n#align cardinal.mk_rat Cardinal.mkRat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Rat/Denumerable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7177743046688361}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module measure_theory.function.ae_measurable_order\n! leanprover-community/mathlib commit 951bf1d9e98a2042979ced62c0620bcfb3587cf8\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Constructions.BorelSpace\n\n/-!\n# Measurability criterion for ennreal-valued functions\n\nConsider a function `f : \u03b1 \u2192 \u211d\u22650\u221e`. If the level sets `{f < p}` and `{q < f}` have measurable\nsupersets which are disjoint up to measure zero when `p` and `q` are finite numbers satisfying\n`p < q`, then `f` is almost-everywhere measurable. This is proved in\n`ennreal.ae_measurable_of_exist_almost_disjoint_supersets`, and deduced from an analogous statement\nfor any target space which is a complete linear dense order, called\n`measure_theory.ae_measurable_of_exist_almost_disjoint_supersets`.\n\nNote that it should be enough to assume that the space is a conditionally complete linear order,\nbut the proof would be more painful. Since our only use for now is for `\u211d\u22650\u221e`, we keep it as simple\nas possible.\n-/\n\n\nopen MeasureTheory Set TopologicalSpace\n\nopen Classical ENNReal NNReal\n\n/-- If a function `f : \u03b1 \u2192 \u03b2` is such that the level sets `{f < p}` and `{q < f}` have measurable\nsupersets which are disjoint up to measure zero when `p < q`, then `f` is almost-everywhere\nmeasurable. It is even enough to have this for `p` and `q` in a countable dense set. -/\ntheorem MeasureTheory.aeMeasurableOfExistAlmostDisjointSupersets {\u03b1 : Type _}\n    {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1) {\u03b2 : Type _} [CompleteLinearOrder \u03b2] [DenselyOrdered \u03b2]\n    [TopologicalSpace \u03b2] [OrderTopology \u03b2] [SecondCountableTopology \u03b2] [MeasurableSpace \u03b2]\n    [BorelSpace \u03b2] (s : Set \u03b2) (s_count : s.Countable) (s_dense : Dense s) (f : \u03b1 \u2192 \u03b2)\n    (h :\n      \u2200 p \u2208 s,\n        \u2200 q \u2208 s,\n          p < q \u2192\n            \u2203 u v,\n              MeasurableSet u \u2227\n                MeasurableSet v \u2227 { x | f x < p } \u2286 u \u2227 { x | q < f x } \u2286 v \u2227 \u03bc (u \u2229 v) = 0) :\n    AeMeasurable f \u03bc := by\n  haveI : Encodable s := s_count.to_encodable\n  have h' :\n    \u2200 p q,\n      \u2203 u v,\n        MeasurableSet u \u2227\n          MeasurableSet v \u2227\n            { x | f x < p } \u2286 u \u2227 { x | q < f x } \u2286 v \u2227 (p \u2208 s \u2192 q \u2208 s \u2192 p < q \u2192 \u03bc (u \u2229 v) = 0) :=\n    by\n    intro p q\n    by_cases H : p \u2208 s \u2227 q \u2208 s \u2227 p < q\n    \u00b7 rcases h p H.1 q H.2.1 H.2.2 with \u27e8u, v, hu, hv, h'u, h'v, h\u03bc\u27e9\n      exact \u27e8u, v, hu, hv, h'u, h'v, fun ps qs pq => h\u03bc\u27e9\n    \u00b7 refine'\n        \u27e8univ, univ, MeasurableSet.univ, MeasurableSet.univ, subset_univ _, subset_univ _,\n          fun ps qs pq => _\u27e9\n      simp only [not_and] at H\n      exact (H ps qs pq).elim\n  choose! u v huv using h'\n  let u' : \u03b2 \u2192 Set \u03b1 := fun p => \u22c2 q \u2208 s \u2229 Ioi p, u p q\n  have u'_meas : \u2200 i, MeasurableSet (u' i) := by\n    intro i\n    exact MeasurableSet.binter\u1d62 (s_count.mono (inter_subset_left _ _)) fun b hb => (huv i b).1\n  let f' : \u03b1 \u2192 \u03b2 := fun x => \u2a05 i : s, piecewise (u' i) (fun x => (i : \u03b2)) (fun x => (\u22a4 : \u03b2)) x\n  have f'_meas : Measurable f' := by\n    apply measurable_inf\u1d62\n    exact fun i => Measurable.piecewise (u'_meas i) measurable_const measurable_const\n  let t := \u22c3 (p : s) (q : s \u2229 Ioi p), u' p \u2229 v p q\n  have \u03bct : \u03bc t \u2264 0 :=\n    calc\n      \u03bc t \u2264 \u2211' (p : s) (q : s \u2229 Ioi p), \u03bc (u' p \u2229 v p q) :=\n        by\n        refine' (measure_Union_le _).trans _\n        apply ENNReal.tsum_le_tsum fun p => _\n        apply measure_Union_le _\n        exact (s_count.mono (inter_subset_left _ _)).to_subtype\n      _ \u2264 \u2211' (p : s) (q : s \u2229 Ioi p), \u03bc (u p q \u2229 v p q) :=\n        by\n        apply ENNReal.tsum_le_tsum fun p => _\n        refine' ENNReal.tsum_le_tsum fun q => measure_mono _\n        exact inter_subset_inter_left _ (bInter_subset_of_mem q.2)\n      _ = \u2211' (p : s) (q : s \u2229 Ioi p), (0 : \u211d\u22650\u221e) :=\n        by\n        congr\n        ext1 p\n        congr\n        ext1 q\n        exact (huv p q).2.2.2.2 p.2 q.2.1 q.2.2\n      _ = 0 := by simp only [tsum_zero]\n      \n  have ff' : \u2200\u1d50 x \u2202\u03bc, f x = f' x :=\n    by\n    have : \u2200\u1d50 x \u2202\u03bc, x \u2209 t := by\n      have : \u03bc t = 0 := le_antisymm \u03bct bot_le\n      change \u03bc _ = 0\n      convert this\n      ext y\n      simp only [not_exists, exists_prop, mem_set_of_eq, mem_compl_iff, not_not_mem]\n    filter_upwards [this]with x hx\n    apply (inf\u1d62_eq_of_forall_ge_of_forall_gt_exists_lt _ _).symm\n    \u00b7 intro i\n      by_cases H : x \u2208 u' i\n      swap\n      \u00b7 simp only [H, le_top, not_false_iff, piecewise_eq_of_not_mem]\n      simp only [H, piecewise_eq_of_mem]\n      contrapose! hx\n      obtain \u27e8r, \u27e8xr, rq\u27e9, rs\u27e9 : \u2203 r, r \u2208 Ioo (i : \u03b2) (f x) \u2229 s :=\n        dense_iff_inter_open.1 s_dense (Ioo i (f x)) isOpen_Ioo (nonempty_Ioo.2 hx)\n      have A : x \u2208 v i r := (huv i r).2.2.2.1 rq\n      apply mem_Union.2 \u27e8i, _\u27e9\n      refine' mem_Union.2 \u27e8\u27e8r, \u27e8rs, xr\u27e9\u27e9, _\u27e9\n      exact \u27e8H, A\u27e9\n    \u00b7 intro q hq\n      obtain \u27e8r, \u27e8xr, rq\u27e9, rs\u27e9 : \u2203 r, r \u2208 Ioo (f x) q \u2229 s :=\n        dense_iff_inter_open.1 s_dense (Ioo (f x) q) isOpen_Ioo (nonempty_Ioo.2 hq)\n      refine' \u27e8\u27e8r, rs\u27e9, _\u27e9\n      have A : x \u2208 u' r := mem_bInter fun i hi => (huv r i).2.2.1 xr\n      simp only [A, rq, piecewise_eq_of_mem, Subtype.coe_mk]\n  exact \u27e8f', f'_meas, ff'\u27e9\n#align measure_theory.ae_measurable_of_exist_almost_disjoint_supersets MeasureTheory.aeMeasurableOfExistAlmostDisjointSupersets\n\n/-- If a function `f : \u03b1 \u2192 \u211d\u22650\u221e` is such that the level sets `{f < p}` and `{q < f}` have measurable\nsupersets which are disjoint up to measure zero when `p` and `q` are finite numbers satisfying\n`p < q`, then `f` is almost-everywhere measurable. -/\ntheorem ENNReal.aeMeasurableOfExistAlmostDisjointSupersets {\u03b1 : Type _} {m : MeasurableSpace \u03b1}\n    (\u03bc : Measure \u03b1) (f : \u03b1 \u2192 \u211d\u22650\u221e)\n    (h :\n      \u2200 (p : \u211d\u22650) (q : \u211d\u22650),\n        p < q \u2192\n          \u2203 u v,\n            MeasurableSet u \u2227\n              MeasurableSet v \u2227\n                { x | f x < p } \u2286 u \u2227 { x | (q : \u211d\u22650\u221e) < f x } \u2286 v \u2227 \u03bc (u \u2229 v) = 0) :\n    AeMeasurable f \u03bc :=\n  by\n  obtain \u27e8s, s_count, s_dense, s_zero, s_top\u27e9 :\n    \u2203 s : Set \u211d\u22650\u221e, s.Countable \u2227 Dense s \u2227 0 \u2209 s \u2227 \u221e \u2209 s :=\n    ENNReal.exists_countable_dense_no_zero_top\n  have I : \u2200 x \u2208 s, x \u2260 \u221e := fun x xs hx => s_top (hx \u25b8 xs)\n  apply MeasureTheory.aeMeasurableOfExistAlmostDisjointSupersets \u03bc s s_count s_dense _\n  rintro p hp q hq hpq\n  lift p to \u211d\u22650 using I p hp\n  lift q to \u211d\u22650 using I q hq\n  exact h p q (ENNReal.coe_lt_coe.1 hpq)\n#align ennreal.ae_measurable_of_exist_almost_disjoint_supersets ENNReal.aeMeasurableOfExistAlmostDisjointSupersets\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Function/AeMeasurableOrder.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.717666812183147}}
{"text": "import ring_theory.polynomial.basic\n\nnamespace polynomial\nopen_locale polynomial big_operators\n\nopen submodule\n\nnoncomputable def degree_le' (R : Type*) [semiring R] (n : with_bot \u2115) : submodule R R[X] :=\n\u2a05 k : \u2115, \u2a05 h : n < \u2191k, (lcoeff R k).ker\n\ntheorem mem_degree_le'  {R : Type*} [semiring R] {n : with_bot \u2115} {f : R[X]} :\n  f \u2208 degree_le' R n \u2194 degree f \u2264 n :=\nby simp only [ degree_le', submodule.mem_infi, degree_le_iff_coeff_zero, linear_map.mem_ker]; refl \n\nnamespace degree_le\n\nlemma bot_eq (R : Type*) [semiring R] : degree_le R \u22a5 = degree_lt R 0 := \nby simp_rw [degree_le, degree_lt, ge_iff_le, gt_iff_lt, with_bot.bot_lt_coe, zero_le']\n\nlemma nat_eq (R : Type*) [semiring R] (n : \u2115) : degree_le R n = degree_lt R (n + 1) :=\nby simp_rw [degree_le, degree_lt, ge_iff_le, gt_iff_lt, with_bot.coe_lt_coe]; refl\n\nend degree_le\n\nnamespace degree_lt\n\nnoncomputable def to_tuple {R : Type*} [comm_ring R] {n : \u2115} (p : degree_lt R n) :\nfin n \u2192 R := degree_lt_equiv _ _ p\n\nlemma to_tuple_eq {R : Type*} [comm_ring R] {n : \u2115} (p : degree_lt R n) :\nto_tuple p = (degree_lt_equiv _ _) p := rfl\n\nlemma to_tuple_apply {R : Type*} [comm_ring R] {n : \u2115} (p : degree_lt R n) (i : fin n) :\nto_tuple p i = (p : R[X]).coeff i := rfl\n\ntheorem to_tuple_eq_zero_iff {R : Type*} [comm_ring R] {n : \u2115} (p : degree_lt R n) :\nto_tuple p = 0 \u2194 p = 0 := by rw [to_tuple_eq, linear_equiv.map_eq_zero_iff]\n\ntheorem to_tuple_eq_iff {R : Type*} [comm_ring R] {n : \u2115} (p q : degree_lt R n) :\nto_tuple p = to_tuple q \u2194 p = q :=\nby {  simp_rw [to_tuple_eq, (linear_equiv.injective _).eq_iff] }\n\ntheorem to_tuple_equiv_eval {R : Type*} [comm_ring R] {n : \u2115} (p : degree_lt R n) (x : R) :\n\u2211 i, to_tuple p i * (x ^ (i : \u2115)) = (p : R[X]).eval x :=\nbegin\n  simp_rw [to_tuple_apply, eval_eq_sum],\n  exact sum_fin (\u03bb e a, a * x ^ e) (\u03bb i, zero_mul (x ^ i)) (mem_degree_lt.mp (coe_mem _))\nend\n\ntheorem to_tuple_root {R : Type*} [comm_ring R] {n : \u2115} (p : degree_lt R n) (x : R) :\n(p : R[X]).is_root x \u2194 \u2211 i, to_tuple p i * (x ^ (i : \u2115)) = 0\n:= by rw [is_root.def, to_tuple_equiv_eval]\n\n/-\ntheorem degree_lt_rank {F : Type*} [field F] {t : \u2115} : module.rank F (degree_lt F t) = t := by {rw (degree_lt_equiv' F t).dim_eq, exact dim_fin_fun _}\n\ntheorem degree_lt_finrank {F : Type*} [field F] {t : \u2115} : finite_dimensional.finrank F (degree_lt F t) = t := finite_dimensional.finrank_eq_of_dim_eq degree_lt_rank\n-/\n\nend degree_lt\n\nend polynomial", "meta": {"author": "linesthatinterlace", "repo": "goppadecoding", "sha": "294f31a0dd56ad9497f3a9585190cdd54f064d7f", "save_path": "github-repos/lean/linesthatinterlace-goppadecoding", "path": "github-repos/lean/linesthatinterlace-goppadecoding/goppadecoding-294f31a0dd56ad9497f3a9585190cdd54f064d7f/src/to_mathlib/polynomial/degree_lt_le.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213880824791, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.7176668035503293}}
{"text": "import data.set.finite\n\nnamespace hidden\n\nopen_locale classical\n\nlemma foo\n  (s : set \u2115)\n  (hs : s.finite)\n  (hsn : s.nonempty)\n  : \u2203 k, \u2200 n \u2208 s, n \u2264 k :=\nbegin\n  use hs.to_finset.max' (by simpa),\n  intros n hn,\n  rw \u2190@set.finite.mem_to_finset _ _ hs at hn,\n  exact finset.le_max' _ _ hn,\nend\n\nnoncomputable\ndef max (s : set \u2115) (hs : s.finite) :=\nif hsn : s.nonempty then\n  nat.find $ foo s hs hsn\nelse\n  0\n\nlemma max_spec\n  (s : set \u2115)\n  (hs : s.finite)\n  (n : \u2115)\n  (hn : n \u2208 s)\n  : n \u2264 max s hs :=\nbegin\n  by_cases hsn : s.nonempty,\n  { unfold max,\n    rw dif_pos hsn,\n    exact nat.find_spec (foo s hs hsn) _ hn },\n  { rw set.not_nonempty_iff_eq_empty at hsn,\n    rw hsn at hn,\n    cases hn }\nend\n\nend hidden\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Maximo_de_conjunto_finito.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7176668013939211}}
{"text": "/-\nCopyright (c) 2021 Patrick Stevens. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Stevens, Thomas Browning\n-/\n\nimport data.nat.choose.basic\nimport tactic.norm_num\nimport tactic.linarith\n\n/-!\n# Central binomial coefficients\n\nThis file proves properties of the central binomial coefficients (that is, `nat.choose (2 * n) n`).\n\n## Main definition and results\n\n* `nat.central_binom`: the central binomial coefficient, `(2 * n).choose n`.\n* `nat.succ_mul_central_binom_succ`: the inductive relationship between successive central binomial\n  coefficients.\n* `nat.four_pow_lt_mul_central_binom`: an exponential lower bound on the central binomial\n  coefficient.\n-/\n\nnamespace nat\n\n/--\nThe central binomial coefficient, `nat.choose (2 * n) n`.\n-/\ndef central_binom (n : \u2115) := (2 * n).choose n\n\nlemma central_binom_eq_two_mul_choose (n : \u2115) : central_binom n = (2 * n).choose n := rfl\n\nlemma central_binom_pos (n : \u2115) : 0 < central_binom n :=\nchoose_pos (nat.le_mul_of_pos_left zero_lt_two)\n\nlemma central_binom_ne_zero (n : \u2115) : central_binom n \u2260 0 :=\n(central_binom_pos n).ne'\n\n@[simp] lemma central_binom_zero : central_binom 0 = 1 :=\nchoose_zero_right _\n\n/--\nThe central binomial coefficient is the largest binomial coefficient.\n-/\nlemma choose_le_central_binom (r n : \u2115) : choose (2 * n) r \u2264 central_binom n :=\ncalc (2 * n).choose r \u2264 (2 * n).choose (2 * n / 2) : choose_le_middle r (2 * n)\n... = (2 * n).choose n : by rw nat.mul_div_cancel_left n zero_lt_two\n\nlemma two_le_central_binom (n : \u2115) (n_pos : 0 < n) : 2 \u2264 central_binom n :=\ncalc 2 \u2264 2 * n : le_mul_of_pos_right n_pos\n... = (2 * n).choose 1 : (choose_one_right (2 * n)).symm\n... \u2264 central_binom n : choose_le_central_binom 1 n\n\n/--\nAn inductive property of the central binomial coefficient.\n-/\nlemma succ_mul_central_binom_succ (n : \u2115) :\n  (n + 1) * central_binom (n + 1) = 2 * (2 * n + 1) * central_binom n :=\ncalc (n + 1) * (2 * (n + 1)).choose (n + 1) = (2 * n + 2).choose (n + 1) * (n + 1) : mul_comm _ _\n... = (2 * n + 1).choose n * (2 * n + 2) : by rw [choose_succ_right_eq, choose_mul_succ_eq]\n... = 2 * ((2 * n + 1).choose n * (n + 1)) : by ring\n... = 2 * ((2 * n + 1).choose n * ((2 * n + 1) - n)) :\n  by rw [two_mul n, add_assoc, nat.add_sub_cancel_left]\n... = 2 * ((2 * n).choose n * (2 * n + 1)) : by rw choose_mul_succ_eq\n... = (2 * (2 * n + 1)) * (2 * n).choose n : by rw [mul_assoc, mul_comm (2 * n + 1)]\n\n/--\nAn exponential lower bound on the central binomial coefficient.\nThis bound is of interest because it appears in\n[Tochiori's refinement of Erd\u0151s's proof of Bertrand's postulate](https://en.wikipedia.org/w/index.php?title=Proof_of_Bertrand%27s_postulate&oldid=859165151#Proof_by_Shigenori_Tochiori).\n-/\nlemma four_pow_lt_mul_central_binom (n : \u2115) (n_big : 4 \u2264 n) : 4 ^ n < n * central_binom n :=\nbegin\n  induction n using nat.strong_induction_on with n IH,\n  rcases lt_trichotomy n 4 with (hn|rfl|hn),\n  { clear IH, dec_trivial! },\n  { norm_num [central_binom, choose] },\n  obtain \u27e8n, rfl\u27e9 : \u2203 m, n = m + 1 := nat.exists_eq_succ_of_ne_zero (zero_lt_four.trans hn).ne',\n  calc 4 ^ (n + 1) < 4 * (n * central_binom n) :\n      (mul_lt_mul_left zero_lt_four).mpr (IH n n.lt_succ_self (nat.le_of_lt_succ hn))\n  ... \u2264 2 * (2 * n + 1) * central_binom n : by { rw \u2190 mul_assoc, linarith }\n  ... = (n + 1) * central_binom (n + 1) : (succ_mul_central_binom_succ n).symm,\nend\n\n/--\nAn exponential lower bound on the central binomial coefficient.\nThis bound is weaker than `four_pow_n_lt_n_mul_central_binom`, but it is of historical interest\nbecause it appears in Erd\u0151s's proof of Bertrand's postulate.\n-/\nlemma four_pow_le_two_mul_self_mul_central_binom : \u2200 (n : \u2115) (n_pos : 0 < n),\n  4 ^ n \u2264 (2 * n) * central_binom n\n| 0 pr := (nat.not_lt_zero _ pr).elim\n| 1 pr := by norm_num [central_binom, choose]\n| 2 pr := by norm_num [central_binom, choose]\n| 3 pr := by norm_num [central_binom, choose]\n| n@(m + 4) _ :=\ncalc 4 ^ n \u2264 n * central_binom n : (four_pow_lt_mul_central_binom _ le_add_self).le\n... \u2264 2 * n * central_binom n    : by { rw [mul_assoc], refine le_mul_of_pos_left zero_lt_two }\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/choose/central.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.717666799235118}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Manuel Candales\n\n! This file was ported from Lean 3 source module geometry.euclidean.angle.unoriented.basic\n! leanprover-community/mathlib commit 46b633fd842bef9469441c0209906f6dddd2b4f5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.InnerProductSpace.Basic\nimport Mathbin.Analysis.SpecialFunctions.Trigonometric.Inverse\n\n/-!\n# Angles between vectors\n\nThis file defines unoriented angles in real inner product spaces.\n\n## Main definitions\n\n* `inner_product_geometry.angle` is the undirected angle between two vectors.\n\n-/\n\n\nassert_not_exists has_fderiv_at\n\nassert_not_exists conformal_at\n\nnoncomputable section\n\nopen Real Set\n\nopen BigOperators\n\nopen Real\n\nopen RealInnerProductSpace\n\nnamespace InnerProductGeometry\n\nvariable {V : Type _} [NormedAddCommGroup V] [InnerProductSpace \u211d V] {x y : V}\n\n/-- The undirected angle between two vectors. If either vector is 0,\nthis is \u03c0/2. See `orientation.oangle` for the corresponding oriented angle\ndefinition. -/\ndef angle (x y : V) : \u211d :=\n  Real.arccos (\u27eax, y\u27eb / (\u2016x\u2016 * \u2016y\u2016))\n#align inner_product_geometry.angle InnerProductGeometry.angle\n\ntheorem continuousAt_angle {x : V \u00d7 V} (hx1 : x.1 \u2260 0) (hx2 : x.2 \u2260 0) :\n    ContinuousAt (fun y : V \u00d7 V => angle y.1 y.2) x :=\n  Real.continuous_arccos.ContinuousAt.comp <|\n    continuous_inner.ContinuousAt.div\n      ((continuous_norm.comp continuous_fst).mul (continuous_norm.comp continuous_snd)).ContinuousAt\n      (by simp [hx1, hx2])\n#align inner_product_geometry.continuous_at_angle InnerProductGeometry.continuousAt_angle\n\ntheorem angle_smul_smul {c : \u211d} (hc : c \u2260 0) (x y : V) : angle (c \u2022 x) (c \u2022 y) = angle x y :=\n  by\n  have : c * c \u2260 0 := mul_ne_zero hc hc\n  rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs,\n    mul_mul_mul_comm _ \u2016x\u2016, abs_mul_abs_self, \u2190 mul_assoc c c, mul_div_mul_left _ _ this]\n#align inner_product_geometry.angle_smul_smul InnerProductGeometry.angle_smul_smul\n\n@[simp]\ntheorem LinearIsometry.angle_map {E F : Type _} [NormedAddCommGroup E] [NormedAddCommGroup F]\n    [InnerProductSpace \u211d E] [InnerProductSpace \u211d F] (f : E \u2192\u2097\u1d62[\u211d] F) (u v : E) :\n    angle (f u) (f v) = angle u v := by rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map]\n#align linear_isometry.angle_map LinearIsometry.angle_map\n\n@[simp, norm_cast]\ntheorem Submodule.angle_coe {s : Submodule \u211d V} (x y : s) : angle (x : V) (y : V) = angle x y :=\n  s.subtype\u2097\u1d62.angle_map x y\n#align submodule.angle_coe Submodule.angle_coe\n\n/-- The cosine of the angle between two vectors. -/\ntheorem cos_angle (x y : V) : Real.cos (angle x y) = \u27eax, y\u27eb / (\u2016x\u2016 * \u2016y\u2016) :=\n  Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1\n    (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2\n#align inner_product_geometry.cos_angle InnerProductGeometry.cos_angle\n\n/-- The angle between two vectors does not depend on their order. -/\ntheorem angle_comm (x y : V) : angle x y = angle y x :=\n  by\n  unfold angle\n  rw [real_inner_comm, mul_comm]\n#align inner_product_geometry.angle_comm InnerProductGeometry.angle_comm\n\n/-- The angle between the negation of two vectors. -/\n@[simp]\ntheorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y :=\n  by\n  unfold angle\n  rw [inner_neg_neg, norm_neg, norm_neg]\n#align inner_product_geometry.angle_neg_neg InnerProductGeometry.angle_neg_neg\n\n/-- The angle between two vectors is nonnegative. -/\ntheorem angle_nonneg (x y : V) : 0 \u2264 angle x y :=\n  Real.arccos_nonneg _\n#align inner_product_geometry.angle_nonneg InnerProductGeometry.angle_nonneg\n\n/-- The angle between two vectors is at most \u03c0. -/\ntheorem angle_le_pi (x y : V) : angle x y \u2264 \u03c0 :=\n  Real.arccos_le_pi _\n#align inner_product_geometry.angle_le_pi InnerProductGeometry.angle_le_pi\n\n/-- The angle between a vector and the negation of another vector. -/\ntheorem angle_neg_right (x y : V) : angle x (-y) = \u03c0 - angle x y :=\n  by\n  unfold angle\n  rw [\u2190 Real.arccos_neg, norm_neg, inner_neg_right, neg_div]\n#align inner_product_geometry.angle_neg_right InnerProductGeometry.angle_neg_right\n\n/-- The angle between the negation of a vector and another vector. -/\ntheorem angle_neg_left (x y : V) : angle (-x) y = \u03c0 - angle x y := by\n  rw [\u2190 angle_neg_neg, neg_neg, angle_neg_right]\n#align inner_product_geometry.angle_neg_left InnerProductGeometry.angle_neg_left\n\n/-- The angle between the zero vector and a vector. -/\n@[simp]\ntheorem angle_zero_left (x : V) : angle 0 x = \u03c0 / 2 :=\n  by\n  unfold angle\n  rw [inner_zero_left, zero_div, Real.arccos_zero]\n#align inner_product_geometry.angle_zero_left InnerProductGeometry.angle_zero_left\n\n/-- The angle between a vector and the zero vector. -/\n@[simp]\ntheorem angle_zero_right (x : V) : angle x 0 = \u03c0 / 2 :=\n  by\n  unfold angle\n  rw [inner_zero_right, zero_div, Real.arccos_zero]\n#align inner_product_geometry.angle_zero_right InnerProductGeometry.angle_zero_right\n\n/-- The angle between a nonzero vector and itself. -/\n@[simp]\ntheorem angle_self {x : V} (hx : x \u2260 0) : angle x x = 0 :=\n  by\n  unfold angle\n  rw [\u2190 real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : \u27eax, x\u27eb \u2260 0),\n    Real.arccos_one]\n#align inner_product_geometry.angle_self InnerProductGeometry.angle_self\n\n/-- The angle between a nonzero vector and its negation. -/\n@[simp]\ntheorem angle_self_neg_of_nonzero {x : V} (hx : x \u2260 0) : angle x (-x) = \u03c0 := by\n  rw [angle_neg_right, angle_self hx, sub_zero]\n#align inner_product_geometry.angle_self_neg_of_nonzero InnerProductGeometry.angle_self_neg_of_nonzero\n\n/-- The angle between the negation of a nonzero vector and that\nvector. -/\n@[simp]\ntheorem angle_neg_self_of_nonzero {x : V} (hx : x \u2260 0) : angle (-x) x = \u03c0 := by\n  rw [angle_comm, angle_self_neg_of_nonzero hx]\n#align inner_product_geometry.angle_neg_self_of_nonzero InnerProductGeometry.angle_neg_self_of_nonzero\n\n/-- The angle between a vector and a positive multiple of a vector. -/\n@[simp]\ntheorem angle_smul_right_of_pos (x y : V) {r : \u211d} (hr : 0 < r) : angle x (r \u2022 y) = angle x y :=\n  by\n  unfold angle\n  rw [inner_smul_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), \u2190 mul_assoc,\n    mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)]\n#align inner_product_geometry.angle_smul_right_of_pos InnerProductGeometry.angle_smul_right_of_pos\n\n/-- The angle between a positive multiple of a vector and a vector. -/\n@[simp]\ntheorem angle_smul_left_of_pos (x y : V) {r : \u211d} (hr : 0 < r) : angle (r \u2022 x) y = angle x y := by\n  rw [angle_comm, angle_smul_right_of_pos y x hr, angle_comm]\n#align inner_product_geometry.angle_smul_left_of_pos InnerProductGeometry.angle_smul_left_of_pos\n\n/-- The angle between a vector and a negative multiple of a vector. -/\n@[simp]\ntheorem angle_smul_right_of_neg (x y : V) {r : \u211d} (hr : r < 0) : angle x (r \u2022 y) = angle x (-y) :=\n  by\n  rw [\u2190 neg_neg r, neg_smul, angle_neg_right, angle_smul_right_of_pos x y (neg_pos_of_neg hr),\n    angle_neg_right]\n#align inner_product_geometry.angle_smul_right_of_neg InnerProductGeometry.angle_smul_right_of_neg\n\n/-- The angle between a negative multiple of a vector and a vector. -/\n@[simp]\ntheorem angle_smul_left_of_neg (x y : V) {r : \u211d} (hr : r < 0) : angle (r \u2022 x) y = angle (-x) y := by\n  rw [angle_comm, angle_smul_right_of_neg y x hr, angle_comm]\n#align inner_product_geometry.angle_smul_left_of_neg InnerProductGeometry.angle_smul_left_of_neg\n\n/-- The cosine of the angle between two vectors, multiplied by the\nproduct of their norms. -/\ntheorem cos_angle_mul_norm_mul_norm (x y : V) : Real.cos (angle x y) * (\u2016x\u2016 * \u2016y\u2016) = \u27eax, y\u27eb :=\n  by\n  rw [cos_angle, div_mul_cancel_of_imp]\n  simp (config := { contextual := true }) [or_imp]\n#align inner_product_geometry.cos_angle_mul_norm_mul_norm InnerProductGeometry.cos_angle_mul_norm_mul_norm\n\n/-- The sine of the angle between two vectors, multiplied by the\nproduct of their norms. -/\ntheorem sin_angle_mul_norm_mul_norm (x y : V) :\n    Real.sin (angle x y) * (\u2016x\u2016 * \u2016y\u2016) = Real.sqrt (\u27eax, x\u27eb * \u27eay, y\u27eb - \u27eax, y\u27eb * \u27eax, y\u27eb) :=\n  by\n  unfold angle\n  rw [Real.sin_arccos, \u2190 Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)), \u2190\n    Real.sqrt_mul' _ (mul_self_nonneg _), sq,\n    Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)),\n    real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm]\n  by_cases h : \u2016x\u2016 * \u2016y\u2016 = 0\n  \u00b7 rw [show \u2016x\u2016 * \u2016x\u2016 * (\u2016y\u2016 * \u2016y\u2016) = \u2016x\u2016 * \u2016y\u2016 * (\u2016x\u2016 * \u2016y\u2016) by ring, h, MulZeroClass.mul_zero,\n      MulZeroClass.mul_zero, zero_sub]\n    cases' eq_zero_or_eq_zero_of_mul_eq_zero h with hx hy\n    \u00b7 rw [norm_eq_zero] at hx\n      rw [hx, inner_zero_left, MulZeroClass.zero_mul, neg_zero]\n    \u00b7 rw [norm_eq_zero] at hy\n      rw [hy, inner_zero_right, MulZeroClass.zero_mul, neg_zero]\n  \u00b7 field_simp [h]\n    ring_nf\n#align inner_product_geometry.sin_angle_mul_norm_mul_norm InnerProductGeometry.sin_angle_mul_norm_mul_norm\n\n/-- The angle between two vectors is zero if and only if they are\nnonzero and one is a positive multiple of the other. -/\ntheorem angle_eq_zero_iff {x y : V} : angle x y = 0 \u2194 x \u2260 0 \u2227 \u2203 r : \u211d, 0 < r \u2227 y = r \u2022 x :=\n  by\n  rw [angle, \u2190 real_inner_div_norm_mul_norm_eq_one_iff, Real.arccos_eq_zero, LE.le.le_iff_eq,\n    eq_comm]\n  exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2\n#align inner_product_geometry.angle_eq_zero_iff InnerProductGeometry.angle_eq_zero_iff\n\n/-- The angle between two vectors is \u03c0 if and only if they are nonzero\nand one is a negative multiple of the other. -/\ntheorem angle_eq_pi_iff {x y : V} : angle x y = \u03c0 \u2194 x \u2260 0 \u2227 \u2203 r : \u211d, r < 0 \u2227 y = r \u2022 x :=\n  by\n  rw [angle, \u2190 real_inner_div_norm_mul_norm_eq_neg_one_iff, Real.arccos_eq_pi, LE.le.le_iff_eq]\n  exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1\n#align inner_product_geometry.angle_eq_pi_iff InnerProductGeometry.angle_eq_pi_iff\n\n/-- If the angle between two vectors is \u03c0, the angles between those\nvectors and a third vector add to \u03c0. -/\ntheorem angle_add_angle_eq_pi_of_angle_eq_pi {x y : V} (z : V) (h : angle x y = \u03c0) :\n    angle x z + angle y z = \u03c0 :=\n  by\n  rcases angle_eq_pi_iff.1 h with \u27e8hx, \u27e8r, \u27e8hr, rfl\u27e9\u27e9\u27e9\n  rw [angle_smul_left_of_neg x z hr, angle_neg_left, add_sub_cancel'_right]\n#align inner_product_geometry.angle_add_angle_eq_pi_of_angle_eq_pi InnerProductGeometry.angle_add_angle_eq_pi_of_angle_eq_pi\n\n/-- Two vectors have inner product 0 if and only if the angle between\nthem is \u03c0/2. -/\ntheorem inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : \u27eax, y\u27eb = 0 \u2194 angle x y = \u03c0 / 2 :=\n  Iff.symm <| by simp (config := { contextual := true }) [angle, or_imp]\n#align inner_product_geometry.inner_eq_zero_iff_angle_eq_pi_div_two InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two\n\n/-- If the angle between two vectors is \u03c0, the inner product equals the negative product\nof the norms. -/\ntheorem inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = \u03c0) :\n    \u27eax, y\u27eb = -(\u2016x\u2016 * \u2016y\u2016) := by simp [\u2190 cos_angle_mul_norm_mul_norm, h]\n#align inner_product_geometry.inner_eq_neg_mul_norm_of_angle_eq_pi InnerProductGeometry.inner_eq_neg_mul_norm_of_angle_eq_pi\n\n/-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/\ntheorem inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : \u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016 := by\n  simp [\u2190 cos_angle_mul_norm_mul_norm, h]\n#align inner_product_geometry.inner_eq_mul_norm_of_angle_eq_zero InnerProductGeometry.inner_eq_mul_norm_of_angle_eq_zero\n\n/-- The inner product of two non-zero vectors equals the negative product of their norms\nif and only if the angle between the two vectors is \u03c0. -/\ntheorem inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n    \u27eax, y\u27eb = -(\u2016x\u2016 * \u2016y\u2016) \u2194 angle x y = \u03c0 :=\n  by\n  refine' \u27e8fun h => _, inner_eq_neg_mul_norm_of_angle_eq_pi\u27e9\n  have h\u2081 : \u2016x\u2016 * \u2016y\u2016 \u2260 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne'\n  rw [angle, h, neg_div, div_self h\u2081, Real.arccos_neg_one]\n#align inner_product_geometry.inner_eq_neg_mul_norm_iff_angle_eq_pi InnerProductGeometry.inner_eq_neg_mul_norm_iff_angle_eq_pi\n\n/-- The inner product of two non-zero vectors equals the product of their norms\nif and only if the angle between the two vectors is 0. -/\ntheorem inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n    \u27eax, y\u27eb = \u2016x\u2016 * \u2016y\u2016 \u2194 angle x y = 0 :=\n  by\n  refine' \u27e8fun h => _, inner_eq_mul_norm_of_angle_eq_zero\u27e9\n  have h\u2081 : \u2016x\u2016 * \u2016y\u2016 \u2260 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne'\n  rw [angle, h, div_self h\u2081, Real.arccos_one]\n#align inner_product_geometry.inner_eq_mul_norm_iff_angle_eq_zero InnerProductGeometry.inner_eq_mul_norm_iff_angle_eq_zero\n\n/-- If the angle between two vectors is \u03c0, the norm of their difference equals\nthe sum of their norms. -/\ntheorem norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = \u03c0) : \u2016x - y\u2016 = \u2016x\u2016 + \u2016y\u2016 :=\n  by\n  rw [\u2190 sq_eq_sq (norm_nonneg (x - y)) (add_nonneg (norm_nonneg x) (norm_nonneg y))]\n  rw [norm_sub_pow_two_real, inner_eq_neg_mul_norm_of_angle_eq_pi h]\n  ring\n#align inner_product_geometry.norm_sub_eq_add_norm_of_angle_eq_pi InnerProductGeometry.norm_sub_eq_add_norm_of_angle_eq_pi\n\n/-- If the angle between two vectors is 0, the norm of their sum equals\nthe sum of their norms. -/\ntheorem norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : \u2016x + y\u2016 = \u2016x\u2016 + \u2016y\u2016 :=\n  by\n  rw [\u2190 sq_eq_sq (norm_nonneg (x + y)) (add_nonneg (norm_nonneg x) (norm_nonneg y))]\n  rw [norm_add_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h]\n  ring\n#align inner_product_geometry.norm_add_eq_add_norm_of_angle_eq_zero InnerProductGeometry.norm_add_eq_add_norm_of_angle_eq_zero\n\n/-- If the angle between two vectors is 0, the norm of their difference equals\nthe absolute value of the difference of their norms. -/\ntheorem norm_sub_eq_abs_sub_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) :\n    \u2016x - y\u2016 = |\u2016x\u2016 - \u2016y\u2016| :=\n  by\n  rw [\u2190 sq_eq_sq (norm_nonneg (x - y)) (abs_nonneg (\u2016x\u2016 - \u2016y\u2016)), norm_sub_pow_two_real,\n    inner_eq_mul_norm_of_angle_eq_zero h, sq_abs (\u2016x\u2016 - \u2016y\u2016)]\n  ring\n#align inner_product_geometry.norm_sub_eq_abs_sub_norm_of_angle_eq_zero InnerProductGeometry.norm_sub_eq_abs_sub_norm_of_angle_eq_zero\n\n/-- The norm of the difference of two non-zero vectors equals the sum of their norms\nif and only the angle between the two vectors is \u03c0. -/\ntheorem norm_sub_eq_add_norm_iff_angle_eq_pi {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n    \u2016x - y\u2016 = \u2016x\u2016 + \u2016y\u2016 \u2194 angle x y = \u03c0 :=\n  by\n  refine' \u27e8fun h => _, norm_sub_eq_add_norm_of_angle_eq_pi\u27e9\n  rw [\u2190 inner_eq_neg_mul_norm_iff_angle_eq_pi hx hy]\n  obtain \u27e8hxy\u2081, hxy\u2082\u27e9 := norm_nonneg (x - y), add_nonneg (norm_nonneg x) (norm_nonneg y)\n  rw [\u2190 sq_eq_sq hxy\u2081 hxy\u2082, norm_sub_pow_two_real] at h\n  calc\n    \u27eax, y\u27eb = (\u2016x\u2016 ^ 2 + \u2016y\u2016 ^ 2 - (\u2016x\u2016 + \u2016y\u2016) ^ 2) / 2 := by linarith\n    _ = -(\u2016x\u2016 * \u2016y\u2016) := by ring\n    \n#align inner_product_geometry.norm_sub_eq_add_norm_iff_angle_eq_pi InnerProductGeometry.norm_sub_eq_add_norm_iff_angle_eq_pi\n\n/-- The norm of the sum of two non-zero vectors equals the sum of their norms\nif and only the angle between the two vectors is 0. -/\ntheorem norm_add_eq_add_norm_iff_angle_eq_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n    \u2016x + y\u2016 = \u2016x\u2016 + \u2016y\u2016 \u2194 angle x y = 0 :=\n  by\n  refine' \u27e8fun h => _, norm_add_eq_add_norm_of_angle_eq_zero\u27e9\n  rw [\u2190 inner_eq_mul_norm_iff_angle_eq_zero hx hy]\n  obtain \u27e8hxy\u2081, hxy\u2082\u27e9 := norm_nonneg (x + y), add_nonneg (norm_nonneg x) (norm_nonneg y)\n  rw [\u2190 sq_eq_sq hxy\u2081 hxy\u2082, norm_add_pow_two_real] at h\n  calc\n    \u27eax, y\u27eb = ((\u2016x\u2016 + \u2016y\u2016) ^ 2 - \u2016x\u2016 ^ 2 - \u2016y\u2016 ^ 2) / 2 := by linarith\n    _ = \u2016x\u2016 * \u2016y\u2016 := by ring\n    \n#align inner_product_geometry.norm_add_eq_add_norm_iff_angle_eq_zero InnerProductGeometry.norm_add_eq_add_norm_iff_angle_eq_zero\n\n/-- The norm of the difference of two non-zero vectors equals the absolute value\nof the difference of their norms if and only the angle between the two vectors is 0. -/\ntheorem norm_sub_eq_abs_sub_norm_iff_angle_eq_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n    \u2016x - y\u2016 = |\u2016x\u2016 - \u2016y\u2016| \u2194 angle x y = 0 :=\n  by\n  refine' \u27e8fun h => _, norm_sub_eq_abs_sub_norm_of_angle_eq_zero\u27e9\n  rw [\u2190 inner_eq_mul_norm_iff_angle_eq_zero hx hy]\n  have h1 : \u2016x - y\u2016 ^ 2 = (\u2016x\u2016 - \u2016y\u2016) ^ 2 := by\n    rw [h]\n    exact sq_abs (\u2016x\u2016 - \u2016y\u2016)\n  rw [norm_sub_pow_two_real] at h1\n  calc\n    \u27eax, y\u27eb = ((\u2016x\u2016 + \u2016y\u2016) ^ 2 - \u2016x\u2016 ^ 2 - \u2016y\u2016 ^ 2) / 2 := by linarith\n    _ = \u2016x\u2016 * \u2016y\u2016 := by ring\n    \n#align inner_product_geometry.norm_sub_eq_abs_sub_norm_iff_angle_eq_zero InnerProductGeometry.norm_sub_eq_abs_sub_norm_iff_angle_eq_zero\n\n/-- The norm of the sum of two vectors equals the norm of their difference if and only if\nthe angle between them is \u03c0/2. -/\ntheorem norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (x y : V) :\n    \u2016x + y\u2016 = \u2016x - y\u2016 \u2194 angle x y = \u03c0 / 2 :=\n  by\n  rw [\u2190 sq_eq_sq (norm_nonneg (x + y)) (norm_nonneg (x - y)), \u2190\n    inner_eq_zero_iff_angle_eq_pi_div_two x y, norm_add_pow_two_real, norm_sub_pow_two_real]\n  constructor <;> intro h <;> linarith\n#align inner_product_geometry.norm_add_eq_norm_sub_iff_angle_eq_pi_div_two InnerProductGeometry.norm_add_eq_norm_sub_iff_angle_eq_pi_div_two\n\n/-- The cosine of the angle between two vectors is 1 if and only if the angle is 0. -/\ntheorem cos_eq_one_iff_angle_eq_zero : cos (angle x y) = 1 \u2194 angle x y = 0 :=\n  by\n  rw [\u2190 cos_zero]\n  exact inj_on_cos.eq_iff \u27e8angle_nonneg x y, angle_le_pi x y\u27e9 (left_mem_Icc.2 pi_pos.le)\n#align inner_product_geometry.cos_eq_one_iff_angle_eq_zero InnerProductGeometry.cos_eq_one_iff_angle_eq_zero\n\n/-- The cosine of the angle between two vectors is 0 if and only if the angle is \u03c0 / 2. -/\ntheorem cos_eq_zero_iff_angle_eq_pi_div_two : cos (angle x y) = 0 \u2194 angle x y = \u03c0 / 2 :=\n  by\n  rw [\u2190 cos_pi_div_two]\n  apply inj_on_cos.eq_iff \u27e8angle_nonneg x y, angle_le_pi x y\u27e9\n  constructor <;> linarith [pi_pos]\n#align inner_product_geometry.cos_eq_zero_iff_angle_eq_pi_div_two InnerProductGeometry.cos_eq_zero_iff_angle_eq_pi_div_two\n\n/-- The cosine of the angle between two vectors is -1 if and only if the angle is \u03c0. -/\ntheorem cos_eq_neg_one_iff_angle_eq_pi : cos (angle x y) = -1 \u2194 angle x y = \u03c0 :=\n  by\n  rw [\u2190 cos_pi]\n  exact inj_on_cos.eq_iff \u27e8angle_nonneg x y, angle_le_pi x y\u27e9 (right_mem_Icc.2 pi_pos.le)\n#align inner_product_geometry.cos_eq_neg_one_iff_angle_eq_pi InnerProductGeometry.cos_eq_neg_one_iff_angle_eq_pi\n\n/-- The sine of the angle between two vectors is 0 if and only if the angle is 0 or \u03c0. -/\ntheorem sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi :\n    sin (angle x y) = 0 \u2194 angle x y = 0 \u2228 angle x y = \u03c0 := by\n  rw [sin_eq_zero_iff_cos_eq, cos_eq_one_iff_angle_eq_zero, cos_eq_neg_one_iff_angle_eq_pi]\n#align inner_product_geometry.sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi InnerProductGeometry.sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi\n\n/-- The sine of the angle between two vectors is 1 if and only if the angle is \u03c0 / 2. -/\ntheorem sin_eq_one_iff_angle_eq_pi_div_two : sin (angle x y) = 1 \u2194 angle x y = \u03c0 / 2 :=\n  by\n  refine' \u27e8fun h => _, fun h => by rw [h, sin_pi_div_two]\u27e9\n  rw [\u2190 cos_eq_zero_iff_angle_eq_pi_div_two, \u2190 abs_eq_zero, abs_cos_eq_sqrt_one_sub_sin_sq, h]\n  simp\n#align inner_product_geometry.sin_eq_one_iff_angle_eq_pi_div_two InnerProductGeometry.sin_eq_one_iff_angle_eq_pi_div_two\n\nend InnerProductGeometry\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Geometry/Euclidean/Angle/Unoriented/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7176667970763146}}
{"text": "/-\nCopyright (c) 2021 Paula Neeley. All rights reserved.\nAuthor: Paula Neeley\n-/\n\nimport basicmodal.language basicmodal.syntax.syntax \nimport basicmodal.semantics.semantics basicmodal.paths\nimport data.set.basic\nlocal attribute [instance] classical.prop_decidable\n\nopen form\n\n\n---------------------- Frame Definability ----------------------\n\n\n-- \u03c6 defines F (a class of frames)\ndef defines (\u03c6 : form) (F : set (frame)) := \n  \u2200 f, f \u2208 F \u2194 f_valid \u03c6 f\n\n\n---------------------- Definability Proofs ----------------------\n\nvariable f : frame\nvariables {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\ndef euclidean       := \u2200 \u2983x y z\u2984, r x y \u2192 r x z \u2192 r y z \ndef ref_class       : set (frame) := { f : frame | reflexive (f.rel)   }\ndef symm_class      : set (frame) := { f : frame | symmetric (f.rel)   }\ndef trans_class     : set (frame) := { f : frame | transitive (f.rel)  }\ndef euclid_class    : set (frame) := { f : frame | euclidean (f.rel)   }\ndef equiv_class     : set (frame) := { f : frame | equivalence (f.rel) }\ndef ref_trans_class : set (frame) := ref_class \u2229 trans_class\n\n\nlemma equiv_ref_euclid (f : frame) : f \u2208 equiv_class \u2194 f \u2208 (ref_class \u2229 euclid_class) :=\nbegin\nsplit,\nintro h1, cases h1 with h1 h2, cases h2 with h2 h3,\nsplit, exact h1, \nintros x y z h4 h5, exact h3 (h2 h4) h5,\nintro h1, split, cases h1, exact h1_left,\nsplit, cases h1 with h1 h2,\nintros x y h3, exact h2 h3 (h1 x),\nintros x y z h2 h3, cases h1 with h1 h4,\nexact h4 (h4 h2 (h1 x)) h3\nend\n\n\nlemma ref_helper : \u2200 \u03c6 f, f \u2208 ref_class \u2192 f_valid ((box \u03c6) \u2283 \u03c6) f :=\nbegin\nintros \u03c6 f h v x h1, \napply h1 x, apply h x\nend\n\n\ntheorem ref_def : defines ((\u25a1 (p 0)) \u2283 (p 0)) (ref_class) :=\nbegin\nintro f,\nsplit,\n{exact ref_helper (p 0) f},\n{intros h x, let v := \u03bb n y, n = 0 \u2227 f.rel x y,\nspecialize h v x,\nsimp [forces, v] at h, exact h}\nend\n\n\nlemma symm_helper : \u2200 \u03c6 f, f \u2208 symm_class \u2192 f_valid (\u03c6 \u2283 (\u25a1 (\u25c7\u03c6))) f :=\nbegin\ndsimp, intros \u03c6 f h v x h1 y h2 h3,\nby_contradiction h4,\nexact ((h3 x) (h h2)) h1\nend\n\n\ntheorem symm_def : defines ((p 0) \u2283 (\u25a1 (\u25c7 (p 0)))) (symm_class) :=\nbegin\nintro f, split,\n{exact symm_helper (p 0) f},\n{intro h1, by_contradiction h2, rw symm_class at h2,\nrw set.nmem_set_of_eq at h2, rw symmetric at h2,\npush_neg at h2,\ncases h2 with x h2,\ncases h2 with y h2,\nlet v := \u03bb n x, n = 0 \u2227 \u00ac f.rel y x,\nspecialize h1 v x,\nsimp [forces, v] at h1,\napply h1 h2.right y h2.left,\nintros y1 h3 h4, exact absurd h3 h4}\nend\n\n\nlemma trans_helper : \u2200 \u03c6 f, f \u2208 trans_class \u2192 f_valid (\u25a1 \u03c6 \u2283 \u25a1 (\u25a1 \u03c6)) f :=\nbegin\nintros \u03c6 f h v x h1 y h3 z h4, \nexact (h1 z) ((h h3) h4)\nend\n\n\nlemma euclid_helper : \u2200 \u03c6 f, f \u2208 euclid_class \u2192 f_valid (\u25c7 \u03c6 \u2283 \u25a1 (\u25c7 \u03c6)) f :=\nbegin\nintros \u03c6 f h v x h1 y h2 h3,\napply h1, intros z h4,\nexact h3 z ((h h2) h4)\nend\n\n\n\n", "meta": {"author": "paulaneeley", "repo": "modal", "sha": "ee5d149d4ecb337005b850bddf4453e56a5daf04", "save_path": "github-repos/lean/paulaneeley-modal", "path": "github-repos/lean/paulaneeley-modal/modal-ee5d149d4ecb337005b850bddf4453e56a5daf04/src/basicmodal/semantics/definability.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.717666794920505}}
{"text": "import game.sup_inf.level01\n\nnamespace xena -- hide\n-- World name : Sup and Inf\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 2  \n\n-/\n\n/-\nThe completeness axiom on the reals states that any non-empty subset \n$X \\subseteq \\mathbb{R}$ that is bounded above has a least upper bound.\nHere we explore the converse statement: any set of reals that has a supremum is non-empty and \nhas an upper bound. The second part of the result is trivial, but showing that the\nset is non-empty will ask you to use techniques learned in the first world.\n-/\n\n-- definition is_upper_bound' (S : set \u211d) (x : \u211d) := x \u2208 upper_bounds S \n-- (Definition above deprecated? GT)\n\ndefinition is_lub (S : set \u211d) (x : \u211d) := is_upper_bound S x \u2227 \n\u2200 y : \u211d, is_upper_bound S y \u2192 x \u2264 y\n\ndefinition has_lub (S : set \u211d) := \u2203 x, is_lub S x \n\nlocal attribute [instance] classical.prop_decidable --hide\n\n\n/- Lemma\nAny set of reals that has a supremum is non-empty and bounded above.\n-/\ntheorem nonempty_and_bounded_of_has_LUB (S : set \u211d) (H : has_lub S) : \n  (S \u2260 \u2205) \u2227 (\u2203 x, is_upper_bound S x) :=\nbegin\n  cases H with b Hb,\n  -- b is LUB, Hb is proof it's LUB\n  split,\n  { -- first prove S is not empty, by contradiction as usual with empty sets\n    intro Hempty,\n    have H1 : (b-1) \u2208 upper_bounds S,\n    change \u2200 x \u2208 S, x \u2264 (b-1),\n    by_contradiction hn,\n    push_neg at hn,\n    cases hn with x h1, \n    cases h1 with h11 h12,\n    rw Hempty at h11, \n    exact h11, \n    unfold is_lub at Hb,\n    have HH := Hb.2 (b-1) H1, -- b - 1 is an upper bound\n    linarith,\n  },\n  {\n     existsi b,\n     exact Hb.1,\n  }, \n  done\nend \n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sup_inf/level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7176667819730739}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.ordinal_arithmetic\n\n/-!\n### Principal ordinals\n\nWe define principal or indecomposable ordinals, and we prove the standard properties about them.\n\n### Main definitions and results\n* `principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and\n  any other typically excluded edge cases for simplicity.\n* `unbounded_principal`: Principal ordinals are unbounded.\n* `principal_add_iff_zero_or_omega_opow`: The main characterization theorem for additive principal\n  ordinals.\n* `principal_mul_iff_le_two_or_omega_opow_opow`: The main characterization theorem for\n  multiplicative principal ordinals.\n\n### Todo\n* Prove that exponential principal ordinals are 0, 1, 2, \u03c9, or epsilon numbers, i.e. fixed points\n  of `\u03bb x, \u03c9 ^ x`.\n-/\n\nuniverse u\n\nnoncomputable theory\n\nnamespace ordinal\nlocal infixr ^ := @pow ordinal ordinal ordinal.has_pow\n\n/-! ### Principal ordinals -/\n\n/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of\nordinals less than it is closed under that operation. In standard mathematical usage, this term is\nalmost exclusively used for additive and multiplicative principal ordinals.\n\nFor simplicity, we break usual convention and regard 0 as principal. -/\ndef principal (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : Prop :=\n\u2200 \u2983a b\u2984, a < o \u2192 b < o \u2192 op a b < o\n\ntheorem principal_iff_principal_swap {op : ordinal \u2192 ordinal \u2192 ordinal} {o : ordinal} :\n  principal op o \u2194 principal (function.swap op) o :=\nby split; exact \u03bb h a b ha hb, h hb ha\n\ntheorem principal_zero {op : ordinal \u2192 ordinal \u2192 ordinal} : principal op 0 :=\n\u03bb a _ h, (ordinal.not_lt_zero a h).elim\n\n@[simp] theorem principal_one_iff {op : ordinal \u2192 ordinal \u2192 ordinal} :\n  principal op 1 \u2194 op 0 0 = 0 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h a b ha hb, _\u27e9,\n  { rwa \u2190lt_one_iff_zero,\n    exact h zero_lt_one zero_lt_one },\n  { rwa [lt_one_iff_zero, ha, hb] at * }\nend\n\ntheorem principal.iterate_lt {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal} (hao : a < o)\n  (ho : principal op o) (n : \u2115) : (op a)^[n] a < o :=\nbegin\n  induction n with n hn,\n  { rwa function.iterate_zero },\n  { rw function.iterate_succ', exact ho hao hn }\nend\n\ntheorem op_eq_self_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal.{u}}\n  (hao : a < o) (H : is_normal (op a)) (ho : principal op o) (ho' : is_limit o) : op a o = o :=\nbegin\n  refine le_antisymm _ (H.self_le _),\n  rw [\u2190is_normal.bsup_eq.{u u} H ho', bsup_le_iff],\n  exact \u03bb b hbo, (ho hao hbo).le\nend\n\ntheorem nfp_le_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal}\n  {a o : ordinal} (hao : a < o) (ho : principal op o) : nfp (op a) a \u2264 o :=\nnfp_le $ \u03bb n, (ho.iterate_lt hao n).le\n\n/-! ### Principal ordinals are unbounded -/\n\n/-- The least strict upper bound of `op` applied to all pairs of ordinals less than `o`. This is\nessentially a two-argument version of `ordinal.blsub`. -/\ndef blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : ordinal :=\nlsub (\u03bb x : o.out.\u03b1 \u00d7 o.out.\u03b1, op (typein (<) x.1) (typein (<) x.2))\n\ntheorem lt_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) {o : ordinal} {a b : ordinal} (ha : a < o)\n  (hb : b < o) : op a b < blsub\u2082 op o :=\nbegin\n  convert lt_lsub _ (prod.mk (enum (<) a (by rwa type_lt)) (enum (<) b (by rwa type_lt))),\n  simp only [typein_enum]\nend\n\ntheorem principal_nfp_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) :\n  principal op (nfp (blsub\u2082.{u u} op) o) :=\n\u03bb a b ha hb, begin\n  rw lt_nfp at *,\n  cases ha with m hm,\n  cases hb with n hn,\n  cases le_total ((blsub\u2082.{u u} op)^[m] o) ((blsub\u2082.{u u} op)^[n] o) with h h,\n  { use n + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op (hm.trans_le h) hn },\n  { use m + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op hm (hn.trans_le h) },\nend\n\ntheorem unbounded_principal (op : ordinal \u2192 ordinal \u2192 ordinal) :\n  set.unbounded (<) {o | principal op o} :=\n\u03bb o, \u27e8_, principal_nfp_blsub\u2082 op o, (le_nfp_self _ o).not_lt\u27e9\n\n/-! #### Additive principal ordinals -/\n\ntheorem principal_add_one : principal (+) 1 :=\nprincipal_one_iff.2 $ zero_add 0\n\ntheorem principal_add_of_le_one {o : ordinal} (ho : o \u2264 1) : principal (+) o :=\nbegin\n  rcases le_one_iff.1 ho with rfl | rfl,\n  { exact principal_zero },\n  { exact principal_add_one }\nend\n\ntheorem principal_add_is_limit {o : ordinal} (ho\u2081 : 1 < o) (ho : principal (+) o) :\n  o.is_limit :=\nbegin\n  refine \u27e8\u03bb ho\u2080, _, \u03bb a hao, _\u27e9,\n  { rw ho\u2080 at ho\u2081,\n    exact not_lt_of_gt ordinal.zero_lt_one ho\u2081 },\n  { cases eq_or_ne a 0 with ha ha,\n    { rw [ha, succ_zero],\n      exact ho\u2081 },\n    { refine lt_of_le_of_lt _ (ho hao hao),\n      rwa [succ_eq_add_one, add_le_add_iff_left, one_le_iff_ne_zero] } }\nend\n\ntheorem principal_add_iff_add_left_eq_self {o : ordinal} :\n  principal (+) o \u2194 \u2200 a < o, a + o = o :=\nbegin\n  refine \u27e8\u03bb ho a hao, _, \u03bb h a b hao hbo, _\u27e9,\n  { cases lt_or_le 1 o with ho\u2081 ho\u2081,\n    { exact op_eq_self_of_principal hao (add_is_normal a) ho (principal_add_is_limit ho\u2081 ho) },\n    { rcases le_one_iff.1 ho\u2081 with rfl | rfl,\n      { exact (ordinal.not_lt_zero a hao).elim },\n      { rw lt_one_iff_zero at hao,\n        rw [hao, zero_add] }}},\n  { rw \u2190h a hao,\n    exact (add_is_normal a).strict_mono hbo }\nend\n\ntheorem exists_lt_add_of_not_principal_add {a} (ha : \u00ac principal (+) a) :\n  \u2203 (b c) (hb : b < a) (hc : c < a), b + c = a :=\nbegin\n  unfold principal at ha,\n  push_neg at ha,\n  rcases ha with \u27e8b, c, hb, hc, H\u27e9,\n  refine \u27e8b, _, hb, lt_of_le_of_ne (sub_le_self a b) (\u03bb hab, _),\n    ordinal.add_sub_cancel_of_le hb.le\u27e9,\n  rw [\u2190sub_le, hab] at H,\n  exact H.not_lt hc\nend\n\ntheorem principal_add_iff_add_lt_ne_self {a} :\n  principal (+) a \u2194 \u2200 \u2983b c\u2984, b < a \u2192 c < a \u2192 b + c \u2260 a :=\n\u27e8\u03bb ha b c hb hc, (ha hb hc).ne, \u03bb H, begin\n  by_contra' ha,\n  rcases exists_lt_add_of_not_principal_add ha with \u27e8b, c, hb, hc, rfl\u27e9,\n  exact (H hb hc).irrefl\nend\u27e9\n\ntheorem add_omega {a : ordinal} (h : a < omega) : a + omega = omega :=\nbegin\n  rcases lt_omega.1 h with \u27e8n, rfl\u27e9,\n  clear h, induction n with n IH,\n  { rw [nat.cast_zero, zero_add] },\n  { rwa [nat.cast_succ, add_assoc, one_add_of_omega_le (le_refl _)] }\nend\n\ntheorem principal_add_omega : principal (+) omega :=\nprincipal_add_iff_add_left_eq_self.2 (\u03bb a, add_omega)\n\ntheorem add_omega_opow {a b : ordinal} (h : a < omega ^ b) : a + omega ^ b = omega ^ b :=\nbegin\n  refine le_antisymm _ (le_add_left _ _),\n  revert h, refine limit_rec_on b (\u03bb h, _) (\u03bb b _ h, _) (\u03bb b l IH h, _),\n  { rw [opow_zero, \u2190 succ_zero, lt_succ, ordinal.le_zero] at h,\n    rw [h, zero_add] },\n  { rw opow_succ at h,\n    rcases (lt_mul_of_limit omega_is_limit).1 h with \u27e8x, xo, ax\u27e9,\n    refine le_trans (add_le_add_right (le_of_lt ax) _) _,\n    rw [opow_succ, \u2190 mul_add, add_omega xo] },\n  { rcases (lt_opow_of_limit omega_ne_zero l).1 h with \u27e8x, xb, ax\u27e9,\n    exact (((add_is_normal a).trans (opow_is_normal one_lt_omega)).limit_le l).2 (\u03bb y yb,\n      (add_le_add_left (opow_le_opow_right omega_pos (le_max_right _ _)) _).trans\n      (le_trans (IH _ (max_lt xb yb) (ax.trans_le $ opow_le_opow_right omega_pos (le_max_left _ _)))\n      (opow_le_opow_right omega_pos $ le_of_lt $ max_lt xb yb))) }\nend\n\ntheorem principal_add_omega_opow (o : ordinal) : principal (+) (omega ^ o) :=\nprincipal_add_iff_add_left_eq_self.2 (\u03bb a, add_omega_opow)\n\n/-- The main characterization theorem for additive principal ordinals. -/\ntheorem principal_add_iff_zero_or_omega_opow {o : ordinal} :\n  principal (+) o \u2194 o = 0 \u2228 \u2203 a, o = omega ^ a :=\nbegin\n  rcases eq_or_ne o 0 with rfl | ho,\n  { simp only [principal_zero, or.inl] },\n  { rw [principal_add_iff_add_left_eq_self],\n    simp only [ho, false_or],\n    refine \u27e8\u03bb H, \u27e8_, ((lt_or_eq_of_le (opow_log_le _ (ordinal.pos_iff_ne_zero.2 ho)))\n        .resolve_left $ \u03bb h, _).symm\u27e9, \u03bb \u27e8b, e\u27e9, e.symm \u25b8 \u03bb a, add_omega_opow\u27e9,\n    have := H _ h,\n    have := lt_opow_succ_log one_lt_omega o,\n    rw [opow_succ, lt_mul_of_limit omega_is_limit] at this,\n    rcases this with \u27e8a, ao, h'\u27e9,\n    rcases lt_omega.1 ao with \u27e8n, rfl\u27e9, clear ao,\n    revert h', apply not_lt_of_le,\n    suffices e : omega ^ log omega o * \u2191n + o = o,\n    { simpa only [e] using le_add_right (omega ^ log omega o * \u2191n) o },\n    induction n with n IH, {simp only [nat.cast_zero, mul_zero, zero_add]},\n    simp only [nat.cast_succ, mul_add_one, add_assoc, this, IH] }\nend\n\ntheorem opow_principal_add_of_principal_add {a} (ha : principal (+) a) (b : ordinal) :\n  principal (+) (a ^ b) :=\nbegin\n  rcases principal_add_iff_zero_or_omega_opow.1 ha with rfl | \u27e8c, rfl\u27e9,\n  { rcases eq_or_ne b 0 with rfl | hb,\n    { rw opow_zero, exact principal_add_one },\n    { rwa zero_opow hb } },\n  { rw \u2190opow_mul, exact principal_add_omega_opow _ }\nend\n\ntheorem add_absorp {a b c : ordinal} (h\u2081 : a < omega ^ b) (h\u2082 : omega ^ b \u2264 c) : a + c = c :=\nby rw [\u2190 ordinal.add_sub_cancel_of_le h\u2082, \u2190 add_assoc, add_omega_opow h\u2081]\n\ntheorem mul_principal_add_is_principal_add (a : ordinal.{u}) {b : ordinal.{u}} (hb\u2081 : b \u2260 1)\n  (hb : principal (+) b) : principal (+) (a * b) :=\nbegin\n  rcases eq_zero_or_pos a with rfl | ha,\n  { rw zero_mul,\n    exact principal_zero },\n  { rcases eq_zero_or_pos b with rfl | hb\u2081',\n    { rw mul_zero,\n      exact principal_zero },\n    { rw [\u2190 succ_le,succ_zero] at hb\u2081',\n      intros c d hc hd,\n      rw lt_mul_of_limit (principal_add_is_limit (lt_of_le_of_ne hb\u2081' hb\u2081.symm) hb) at *,\n      { rcases hc with \u27e8x, hx, hx'\u27e9,\n        rcases hd with \u27e8y, hy, hy'\u27e9,\n        use [x + y, hb hx hy],\n        rw mul_add,\n        exact add_lt_add hx' hy' },\n      assumption' } }\nend\n\n/-! #### Multiplicative principal ordinals -/\n\ntheorem principal_mul_one : principal (*) 1 :=\nby { rw principal_one_iff, exact zero_mul _ }\n\ntheorem principal_mul_two : principal (*) 2 :=\n\u03bb a b ha hb, begin\n  have h\u2082 : (1 : ordinal).succ = 2 := rfl,\n  rw [\u2190h\u2082, ordinal.lt_succ] at *,\n  convert mul_le_mul' ha hb,\n  exact (mul_one 1).symm\nend\n\ntheorem principal_mul_of_le_two {o : ordinal} (ho : o \u2264 2) : principal (*) o :=\nbegin\n  rcases lt_or_eq_of_le ho with ho | rfl,\n  { have h\u2082 : (1 : ordinal).succ = 2 := rfl,\n    rw [\u2190h\u2082, ordinal.lt_succ] at ho,\n    rcases lt_or_eq_of_le ho with ho | rfl,\n    { rw lt_one_iff_zero.1 ho,\n      exact principal_zero },\n    { exact principal_mul_one } },\n  { exact principal_mul_two }\nend\n\ntheorem principal_add_of_principal_mul {o : ordinal} (ho : principal (*) o) (ho\u2082 : o \u2260 2) :\n  principal (+) o :=\nbegin\n  cases lt_or_gt_of_ne ho\u2082 with ho\u2081 ho\u2082,\n  { change o < succ 1 at ho\u2081,\n    rw lt_succ at ho\u2081,\n    exact principal_add_of_le_one ho\u2081 },\n  { refine \u03bb a b hao hbo, lt_of_le_of_lt _ (ho (max_lt hao hbo) ho\u2082),\n    rw mul_two,\n    exact add_le_add (le_max_left a b) (le_max_right a b) }\nend\n\ntheorem principal_mul_is_limit {o : ordinal.{u}} (ho\u2082 : 2 < o) (ho : principal (*) o) :\n  o.is_limit :=\nprincipal_add_is_limit\n  ((ordinal.lt_succ_self 1).trans ho\u2082)\n  (principal_add_of_principal_mul ho (ne_of_gt ho\u2082))\n\ntheorem principal_mul_iff_mul_left_eq {o : ordinal} :\n  principal (*) o \u2194 \u2200 a, 0 < a \u2192 a < o \u2192 a * o = o :=\nbegin\n  refine \u27e8\u03bb h a ha\u2080 hao, _, \u03bb h a b hao hbo, _\u27e9,\n  { cases le_or_gt o 2 with ho ho,\n    { convert one_mul o,\n      apply le_antisymm,\n      { have : a < succ 1 := hao.trans_le ho,\n        rwa lt_succ at this },\n      { rwa [\u2190succ_le, succ_zero] at ha\u2080 } },\n    { exact op_eq_self_of_principal hao (mul_is_normal ha\u2080) h (principal_mul_is_limit ho h) } },\n  { rcases eq_or_ne a 0 with rfl | ha, { rwa zero_mul },\n    rw \u2190ordinal.pos_iff_ne_zero at ha,\n    rw \u2190h a ha hao,\n    exact (mul_is_normal ha).strict_mono hbo }\nend\n\ntheorem principal_mul_omega : principal (*) omega :=\n\u03bb a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by { rw [\u2190 nat_cast_mul], apply nat_lt_omega }\nend\n\ntheorem mul_omega {a : ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega :=\nprincipal_mul_iff_mul_left_eq.1 (principal_mul_omega) a a0 ha\n\ntheorem mul_lt_omega_opow {a b c : ordinal}\n  (c0 : 0 < c) (ha : a < omega ^ c) (hb : b < omega) : a * b < omega ^ c :=\nbegin\n  rcases zero_or_succ_or_limit c with rfl|\u27e8c,rfl\u27e9|l,\n  { exact (lt_irrefl _).elim c0 },\n  { rw opow_succ at ha,\n    rcases ((mul_is_normal $ opow_pos _ omega_pos).limit_lt\n      omega_is_limit).1 ha with \u27e8n, hn, an\u27e9,\n    apply (mul_le_mul_right' (le_of_lt an) _).trans_lt,\n    rw [opow_succ, mul_assoc, mul_lt_mul_iff_left (opow_pos _ omega_pos)],\n    exact principal_mul_omega hn hb },\n  { rcases ((opow_is_normal one_lt_omega).limit_lt l).1 ha with \u27e8x, hx, ax\u27e9,\n    refine (mul_le_mul' (le_of_lt ax) (le_of_lt hb)).trans_lt _,\n    rw [\u2190 opow_succ, opow_lt_opow_iff_right one_lt_omega],\n    exact l.2 _ hx }\nend\n\ntheorem mul_omega_opow_opow {a b : ordinal} (a0 : 0 < a) (h : a < omega ^ omega ^ b) :\n  a * omega ^ omega ^ b = omega ^ omega ^ b :=\nbegin\n  by_cases b0 : b = 0, {rw [b0, opow_zero, opow_one] at h \u22a2, exact mul_omega a0 h},\n  refine le_antisymm _\n    (by simpa only [one_mul] using mul_le_mul_right' (one_le_iff_pos.2 a0) (omega ^ omega ^ b)),\n  rcases (lt_opow_of_limit omega_ne_zero (opow_is_limit_left omega_is_limit b0)).1 h\n    with \u27e8x, xb, ax\u27e9,\n  apply (mul_le_mul_right' (le_of_lt ax) _).trans,\n  rw [\u2190 opow_add, add_omega_opow xb]\nend\n\ntheorem principal_mul_omega_opow_opow (o : ordinal) : principal (*) (omega ^ omega ^ o) :=\nprincipal_mul_iff_mul_left_eq.2 (\u03bb a, mul_omega_opow_opow)\n\ntheorem principal_add_of_principal_mul_opow {o b : ordinal} (hb : 1 < b)\n  (ho : principal (*) (b ^ o)) : principal (+) o :=\n\u03bb x y hx hy, begin\n  have := ho ((opow_lt_opow_iff_right hb).2 hx) ((opow_lt_opow_iff_right hb).2 hy),\n  rwa [\u2190opow_add, opow_lt_opow_iff_right hb] at this\nend\n\n/-- The main characterization theorem for multiplicative principal ordinals. -/\ntheorem principal_mul_iff_le_two_or_omega_opow_opow {o : ordinal} :\n  principal (*) o \u2194 o \u2264 2 \u2228 \u2203 a, o = omega ^ omega ^ a :=\nbegin\n  refine \u27e8\u03bb ho, _, _\u27e9,\n  { cases le_or_lt o 2 with ho\u2082 ho\u2082,\n    { exact or.inl ho\u2082 },\n    rcases principal_add_iff_zero_or_omega_opow.1 (principal_add_of_principal_mul ho ho\u2082.ne')\n      with rfl | \u27e8a, rfl\u27e9,\n    { exact (ordinal.not_lt_zero 2 ho\u2082).elim },\n    rcases principal_add_iff_zero_or_omega_opow.1\n      (principal_add_of_principal_mul_opow one_lt_omega ho) with rfl | \u27e8b, rfl\u27e9,\n    { rw opow_zero at ho\u2082,\n      exact ((lt_succ_self 1).not_le ho\u2082.le).elim },\n    exact or.inr \u27e8b, rfl\u27e9 },\n  { rintro (ho\u2082 | \u27e8a, rfl\u27e9),\n    { exact principal_mul_of_le_two ho\u2082 },\n    { exact principal_mul_omega_opow_opow a } }\nend\n\ntheorem mul_omega_dvd {a : ordinal}\n  (a0 : 0 < a) (ha : a < omega) : \u2200 {b}, omega \u2223 b \u2192 a * b = b\n| _ \u27e8b, rfl\u27e9 := by rw [\u2190 mul_assoc, mul_omega a0 ha]\n\ntheorem mul_eq_opow_log_succ {a b : ordinal.{u}} (ha : 0 < a) (hb : principal (*) b) (hb\u2082 : 2 < b) :\n  a * b = b ^ (log b a).succ :=\nbegin\n  apply le_antisymm,\n  { have hbl := principal_mul_is_limit hb\u2082 hb,\n    rw [\u2190is_normal.bsup_eq.{u u} (mul_is_normal ha) hbl, bsup_le_iff],\n    intros c hcb,\n    have hb\u2081 : 1 < b := (lt_succ_self 1).trans hb\u2082,\n    have hbo\u2080 : b ^ b.log a \u2260 0 := ordinal.pos_iff_ne_zero.1 (opow_pos _ (zero_lt_one.trans hb\u2081)),\n    apply le_trans (mul_le_mul_right' (le_of_lt (lt_mul_succ_div a hbo\u2080)) c),\n    rw [mul_assoc, opow_succ],\n    refine mul_le_mul_left' (le_of_lt (hb (hbl.2 _ _) hcb)) _,\n    rw [div_lt hbo\u2080, \u2190opow_succ],\n    exact lt_opow_succ_log hb\u2081 _ },\n  { rw opow_succ,\n    exact mul_le_mul_right' (opow_log_le b ha) b }\nend\n\n/-! #### Exponential principal ordinals -/\n\ntheorem principal_opow_omega : principal (^) omega :=\n\u03bb a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by { simp_rw \u2190nat_cast_opow, apply nat_lt_omega }\nend\n\ntheorem opow_omega {a : ordinal} (a1 : 1 < a) (h : a < omega) : a ^ omega = omega :=\nle_antisymm\n  ((opow_le_of_limit (one_le_iff_ne_zero.1 $ le_of_lt a1) omega_is_limit).2\n    (\u03bb b hb, (principal_opow_omega h hb).le))\n  (right_le_opow _ a1)\n\nend ordinal\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/set_theory/principal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7176213108608758}}
{"text": "/-\nSeems like this should be in the standard library.\n-/\n\nlemma demorgan (p q : Prop) : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\niff.intro\n(assume h : \u00ac(p \u2228 q),\n  show \u00acp \u2227 \u00acq, from\n  and.intro\n    (assume hp : p, absurd (or.intro_left q hp) h)\n    (assume hq : q, absurd (or.intro_right p hq) h))\n(assume h : \u00acp \u2227 \u00acq,\n  show \u00ac(p \u2228 q), from\n  assume h1 : p \u2228 q, \n  or.elim h1\n    (assume hp : p, absurd hp (and.left h))\n    (assume hq : q, absurd hq (and.right h)))", "meta": {"author": "jthickstun", "repo": "lean", "sha": "8254b987f06be1f98ef2e0cc33b7d4655d77dc85", "save_path": "github-repos/lean/jthickstun-lean", "path": "github-repos/lean/jthickstun-lean/lean-8254b987f06be1f98ef2e0cc33b7d4655d77dc85/logic_extra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.7176213105981633}}
{"text": "import GMLInit.Data.Nat.Basic\nimport GMLInit.Data.Nat.IsPos\nimport GMLInit.Logic.Connectives\nimport GMLInit.Logic.Ordering\nimport GMLInit.Logic.Relation\n\nnamespace Nat\n\n-- assert theorem lt_or_ge (x y : Nat) : x < y \u2228 x \u2265 y\n\nprotected theorem le_or_gt (x y : Nat) : x \u2264 y \u2228 x > y :=\n  Or.elim (Nat.lt_or_ge y x) Or.inr Or.inl\n\n-- assert theorem lt_or_eq_of_le {x y : Nat} : x \u2264 y \u2192 x < y \u2228 x = y\n\nprotected theorem le_iff_lt_or_eq (x y : Nat) : x \u2264 y \u2194 x < y \u2228 x = y :=\n  \u27e8Nat.lt_or_eq_of_le, \u03bb h => Or.elim h Nat.le_of_lt Nat.le_of_eq\u27e9\n\n-- assert theorem le_of_lt {x y : Nat} : x < y \u2192 x \u2264 y\n\n-- assert theorem ne_of_lt {x y : Nat} : x < y \u2192 x \u2260 y | h, rfl => Nat.lt_irrefl x h\n\n-- assert theorem lt_of_le_of_ne {x y : Nat} : x \u2264 y \u2192 x \u2260 y \u2192 x < y\n\n-- assert theorem lt_iff_le_and_ne (x y : Nat) : x < y \u2194 x \u2264 y \u2227 x \u2260 y\n\n-- assert theorem le_total (x y : Nat) : x \u2264 y \u2228 x \u2265 y := Nat.leTotal x y\n\nprotected theorem lt_connex {x y : Nat} : x \u2260 y \u2192 x < y \u2228 x > y :=\n  \u03bb hne => Or.elim (Nat.lt_or_ge x y) Or.inl \u03bb h => Or.inr (Nat.lt_of_le_of_ne h hne.symm)\n\nprotected theorem lt_compare {x y : Nat} : x < y \u2192 \u2200 z, x < z \u2228 z < y :=\n  \u03bb hlt z => Or.elim (Nat.lt_or_ge x z) Or.inl (\u03bb hge => Or.inr (Nat.lt_of_le_of_lt hge hlt))\n\n-- assert theorem ge_of_not_lt {x y : Nat} : \u00ac x < y \u2192 x \u2265 y := Or.mtp (Nat.le_or_gt y x)\n\n-- assert theorem gt_of_not_le {x y : Nat} : \u00ac x \u2264 y \u2192 x > y\n\nprotected theorem le_of_not_gt {x y : Nat} : \u00ac x > y \u2192 x \u2264 y := Or.mtp (Nat.le_or_gt x y)\n\nprotected theorem lt_of_not_ge {x y : Nat} : \u00ac x \u2265 y \u2192 x < y := Or.mtp (Nat.lt_or_ge x y)\n\nprotected theorem not_ge_of_lt {x y : Nat} : x < y \u2192 \u00ac x \u2265 y := Nat.not_le_of_gt\n\nprotected theorem not_gt_of_le {x y : Nat} : x \u2264 y \u2192 \u00ac x > y := \u03bb hle hgt => Nat.not_ge_of_lt hgt hle\n\n-- assert theorem not_le_of_gt {x y : Nat} : x > y \u2192 \u00ac x \u2264 y\n\nprotected theorem not_lt_of_ge {x y : Nat} : x \u2265 y \u2192 \u00ac x < y := \u03bb hge hlt => Nat.not_gt_of_le hlt (Nat.succ_le_succ hge)\n\nprotected theorem not_le_iff_gt (x y : Nat) : \u00ac x \u2264 y \u2194 x > y :=\n  \u27e8Nat.gt_of_not_le, Nat.not_ge_of_lt\u27e9\n\nprotected theorem lt_iff_not_ge (x y : Nat) : x < y \u2194 \u00ac x \u2265 y :=\n  \u27e8Nat.not_ge_of_lt, Nat.gt_of_not_le\u27e9\n\nprotected theorem not_lt_iff_ge (x y : Nat) : \u00ac x < y \u2194 x \u2265 y :=\n  \u27e8Nat.ge_of_not_lt, Nat.not_gt_of_le\u27e9\n\nprotected theorem le_iff_not_gt (x y : Nat) : x \u2264 y \u2194 \u00ac x > y :=\n  \u27e8Nat.not_gt_of_le, Nat.ge_of_not_lt\u27e9\n\nprotected theorem ne_iff_lt_or_gt (x y : Nat) : x \u2260 y \u2194 x < y \u2228 x > y :=\n  \u27e8Nat.lt_connex, \u03bb h => Or.elim h Nat.ne_of_lt \u03bb h => (Nat.ne_of_lt h).symm\u27e9\n\n-- assert theorem zero_le (x : Nat) : 0 \u2264 x\n\n-- assert theorem not_lt_zero (x : Nat) : \u00ac x < 0\n\n-- assert theorem eq_zero_of_le_zero {x : Nat} : x \u2264 0 \u2192 x = 0\n\nprotected theorem eq_zero_iff_le_zero (x : Nat) : x = 0 \u2194 x \u2264 0 :=\n  \u27e8Nat.le_of_eq, Nat.eq_zero_of_le_zero\u27e9\n\nopen Relation\n\nlocal instance : Reflexive (\u03b1:=Nat) (.\u2264.) := \u27e8Nat.le_refl\u27e9\nlocal instance : Transitive (\u03b1:=Nat) (.\u2264.) := \u27e8Nat.le_trans\u27e9\nlocal instance : Antisymmetric (\u03b1:=Nat) (.\u2264.) := \u27e8Nat.le_antisymm\u27e9\nlocal instance : Total (\u03b1:=Nat) (.\u2264.) := \u27e8Nat.le_total\u27e9\ninstance : TotalOrder (\u03b1:=Nat) (.\u2264.) := TotalOrder.infer _\nlocal instance : Irreflexive (\u03b1:=Nat) (.<.) := \u27e8Nat.lt_irrefl\u27e9\nlocal instance : Transitive (\u03b1:=Nat) (.<.) := \u27e8Nat.lt_trans\u27e9\nlocal instance : Connex (\u03b1:=Nat) (.<.) := \u27e8Nat.lt_connex\u27e9\nlocal instance : Comparison (\u03b1:=Nat) (.<.) := \u27e8Nat.lt_compare\u27e9\ninstance : LinearOrder (\u03b1:=Nat) (.<.) := LinearOrder.infer _\ninstance : HTransitive (\u03b1:=Nat) (\u03b2:=Nat) (\u03b3:=Nat) (.\u2264.) (.<.) (.<.) := \u27e8Nat.lt_of_le_of_lt\u27e9\ninstance : HTransitive (\u03b1:=Nat) (\u03b2:=Nat) (\u03b3:=Nat) (.<.) (.\u2264.) (.<.) := \u27e8Nat.lt_of_lt_of_le\u27e9\n\nend Nat\n", "meta": {"author": "fgdorais", "repo": "GMLInit", "sha": "a295111627ac907ebc6a86f906dd9b4d69b338d8", "save_path": "github-repos/lean/fgdorais-GMLInit", "path": "github-repos/lean/fgdorais-GMLInit/GMLInit-a295111627ac907ebc6a86f906dd9b4d69b338d8/GMLInit/Data/Nat/Order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7176213041167575}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport easy_mode.sheet01\n\n/-! Two-by-two matrices\n\nThis file defines two-by-two matrices and shows that they form a vector space.\n-/\n\n/- Here is one way to define a 2x2 matrix, via specifying its two rows. In hard mode you could try to take a \n  different approach (either as its two columns or as its four entries and see what gets easier and what gets \n  harder). -/\nstructure two_matrix : Type :=\n(fst_row : \u211d\u00b2) \n(snd_row : \u211d\u00b2)\n\nnamespace two_matrix\n\nnotation `Mat\u2082` := two_matrix\n\n/-- Two matrices are equal if and only if their first and second rows coincide. -/\n@[ext] theorem ext {A B : Mat\u2082}\n  (h_first_row : A.fst_row = B.fst_row ) \n  (h_second_row : A.snd_row = B.snd_row ) : \n  A = B :=\nbegin\n  sorry\nend\n\n/- Again we want to be able to write `A + B` if `A` and `B` are matrices without too complicated notation. -/\ninstance : has_add Mat\u2082 := \u27e8\u03bb A B, \u27e8A.fst_row + B.fst_row, A.snd_row + B.snd_row\u27e9\u27e9\n\n@[simp] lemma add_fst_row (A B : Mat\u2082) : (A + B).fst_row = A.fst_row + B.fst_row := sorry\n@[simp] lemma add_snd_row (A B : Mat\u2082) : (A + B).snd_row = A.snd_row + B.snd_row := sorry\n\nlemma add_assoc (A B C : Mat\u2082) : A + B + C = A + (B + C) :=\nbegin\n  sorry\nend\n\nlemma add_comm (A B : Mat\u2082) : A + B = B + A :=\nbegin\n  sorry\nend\n\ndef zero_matrix : Mat\u2082 := \u27e80,0\u27e9\n\n/- We even want to be able to write `0` for the zero matrix.-/\ninstance : has_zero Mat\u2082 := \u27e8zero_matrix\u27e9 \n\n/- The following lemmas have each two zeros in them, see which is which. -/\n@[simp] lemma zero_fst_row : (0 : Mat\u2082).fst_row = 0 := sorry\n@[simp] lemma zero_snd_row : (0 : Mat\u2082).snd_row = 0 := sorry\n\n@[simp] lemma add_zero (A : Mat\u2082) : A + 0 = A :=\nbegin\n  sorry\nend\n\n@[simp] lemma zero_add (A : Mat\u2082) : 0 + A = A :=\nbegin\n  sorry\nend\n\n/- We want to define the negation of a matrix. -/\ninstance : has_neg Mat\u2082 := \u27e8\u03bb A, \u27e8-A.fst_row, -A.snd_row\u27e9\u27e9\n\n@[simp] lemma neg_fst_row (A : Mat\u2082) : (-A).fst_row = -A.fst_row := sorry\n@[simp] lemma neg_snd_row (A : Mat\u2082) : (-A).snd_row = -A.snd_row := sorry\n\n\n@[simp] lemma add_neg_self (A : Mat\u2082) : A + -A = 0 :=\nbegin\n  sorry\nend \n\n@[simp] lemma neg_add_self (A : Mat\u2082) : -A + A = 0 :=\nbegin\n  sorry\nend\n\n/- Finally we set up subtraction and scalar multiplication of matrices. -/\ninstance : has_sub Mat\u2082 := \u27e8\u03bb A B, A + (-B)\u27e9\n\ninstance : has_scalar \u211d Mat\u2082 := \u27e8\u03bb a A, \u27e8a \u2022 A.fst_row, a \u2022 A.snd_row\u27e9\u27e9 \n\n@[simp] lemma smul_fst_row (a : \u211d) (A : Mat\u2082) : (a \u2022 A).fst_row = a \u2022 A.fst_row := sorry\n@[simp] lemma smul_snd_row (a : \u211d) (A : Mat\u2082) : (a \u2022 A).snd_row = a \u2022 A.snd_row := sorry\n\nlemma smul_assoc (a b : \u211d) (A : Mat\u2082) : (a * b) \u2022 A = a \u2022 (b \u2022 A) :=\nbegin\n  sorry\nend \n\n@[simp] lemma one_smul (A : Mat\u2082) : (1 : \u211d) \u2022 A = A :=\nbegin\n  sorry\nend   \n\n@[simp] lemma smul_add (a : \u211d) (A B : Mat\u2082) : a \u2022 (A + B) = a \u2022 A + a \u2022 B :=\nbegin\n  sorry\nend \n\n@[simp] lemma add_smul (a b : \u211d) (A : Mat\u2082) : (a + b) \u2022 A = a \u2022 A + b \u2022 A :=\nbegin\n  sorry\nend\n\nend two_matrix", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/easy_mode/sheet02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7176204963528855}}
{"text": "-- Ref: The conversion tactic mode https://bit.ly/3kqif1T\n\nimport tactic\n\nexample (a b c : \u2115) : a * (b * c) = a * (c * b) :=\nbegin\n  conv\n  begin          -- | a * (b * c) = a * (c * b)\n    to_lhs,      -- | a * (b * c)\n    congr,       -- 2 goals : | a and | b * c\n    skip,        -- | b * c\n    rw mul_comm, -- | c * b\n  end\nend\n\nexample (a b c : \u2115) : a * (b * c) = a * (c * b) :=\nbegin\n  conv in (b*c)\n  begin          -- | b * c\n    rw mul_comm, -- | c * b\n  end,\nend\n\nexample (a b c : \u2115) : a * (b * c) = a * (c * b) :=\nby conv in (b*c) { rw mul_comm }\n\nexample (a b c : \u2115) : a + (b * c) = a + (c * b) :=\nby conv in (_ * c) { rw mul_comm }\n\nexample (a b c : \u2115) : (b * c) * (b * c) * (b * c) = (b * c) * (c * b)  * (c * b):=\nby conv { for (b * c) [2, 3] { rw mul_comm } }\n\nexample : (\u03bb x : \u2115, 0 + x) = (\u03bb x, x) :=\nbegin\n  conv\n  begin           -- | (\u03bb (x : \u2115), 0 + x) = \u03bb (x : \u2115), x\n    to_lhs,       -- | \u03bb (x : \u2115), 0 + x\n    funext,       -- | 0 + x\n    rw zero_add,  -- | x\n  end\nend\n\nexample : (\u03bb x : \u2115, 0+x) = (\u03bb x, x) :=\nby funext ; rw zero_add\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/La_tactica_conv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7176204922451943}}
{"text": "namespace chapter3\n\nopen nat\nopen classical\nopen set\n\n-- Since sets are not exactly straightforward in type theory,\n-- there will be some leniency with regards to the textbook\n-- in order to define them type theoretically and\n-- Lean's standard library will be employed\n-- to express the properties of sets.\nvariable {\u03b1 : Type}\n\n-- \"set\" will be used instead\ndef d3_1_1 := \u03b1 \u2192 Prop\n\n-- sets are objects\ntheorem ax3_1 (A : set \u03b1) (B : set (set \u03b1)) : Prop := A \u2208 B\n\n-- should be the axiom of extensionality\ndef d3_1_4 {A B : set \u03b1} : A = B \u2194 (\u2200 x : \u03b1, x \u2208 A \u2194 x \u2208 B) :=\nbegin\n    constructor,\n    intro h,\n        intro x,\n        rw h,\n    intro h,\n        have : \u2200 x, (x \u2208 A) = (x \u2208 B),\n            intro x,\n            exact iff.to_eq (h x),\n        exact funext this\nend\n\ntheorem ax3_2 {A : set \u03b1} : (\u2200 x : \u03b1, x \u2209 A) \u2192 A = \u2205 :=  \nbegin\n    intro h,\n    apply iff.mpr d3_1_4,\n    intro x,\n    constructor,\n    intro xa,\n    have : x \u2209 A, exact h x,\n    contradiction,\n    intro xe,\n    exact false.elim xe\nend\n\nlemma l3_1_6 {A : set \u03b1} (h : A \u2260 \u2205) : \u2203 x, x \u2208 A :=\nbegin\n    apply by_contradiction,\n    intro nh,\n    have : \u2200 x, x \u2209 A, from forall_not_of_not_exists nh,\n    have : A = \u2205, from ax3_2 this,\n    contradiction\nend\n\n-- singleton set\ntheorem ax3_3a {y : \u03b1} {a : \u03b1} : y \u2208 (singleton a : set \u03b1) \u2194 y = a :=\nbegin\n    constructor,\n    intro ye,\n        apply or.elim ye,\n        exact id,\n        assume (h : set.mem y \u2205),\n        exact false.elim h,\n    intro ye,\n        exact or.inl ye\nend\n\n-- pair set\ntheorem ax3_3b {y : \u03b1} {a : \u03b1} {b : \u03b1} : y \u2208 (insert b (singleton a) : set \u03b1) \u2194 y = a \u2228 y = b :=\nbegin\n    constructor,\n    intro ye,\n        apply or.elim ye,\n        exact or.inr,\n        intro ya,\n        exact or.inl (ax3_3a.mp ya),\n    intro ye,\n        apply or.elim ye,\n        intro ya,\n        exact or.inr (ax3_3a.mpr ya),\n        intro yb,\n        exact or.inl yb\nend\n\ntheorem ax3_4 {A B : set \u03b1} : \u2200 x : \u03b1, x \u2208 A \u222a B \u2194 x \u2208 A \u2228 x \u2208 B :=\nbegin\n    intro x,\n    constructor,\n    exact id,\n    exact id,\nend\n\nexample : {1, 2} \u222a {2, 3} = ({1, 2, 3} : set \u2115) :=\n--calc\n--    {1, 2} \u222a {2, 3} = {x | x \u2208 {1, 2} \u2228 x \u2208 {2, 3}} : rfl\n--    ...             = \n\nend chapter3", "meta": {"author": "OwenGraves", "repo": "TaoAnalysis", "sha": "695b149b5decdb6f8e46c883ea112f0a12082548", "save_path": "github-repos/lean/OwenGraves-TaoAnalysis", "path": "github-repos/lean/OwenGraves-TaoAnalysis/TaoAnalysis-695b149b5decdb6f8e46c883ea112f0a12082548/chapter3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.7176204790470562}}
{"text": "namespace hidden\ninductive Natural\n | zero : Natural\n | succ : Natural -> Natural\n\nopen Natural\n\ninstance : has_zero Natural :=\n{ zero := zero}\n\ninstance : has_one Natural :=\n { one := succ zero}\n\ndef add : Natural -> Natural -> Natural\n | a zero := a\n | a (succ b) := succ (add a b).\n\ninstance : has_add Natural := \n{ add := add }\n\ndef times : Natural -> Natural -> Natural\n | a zero := zero\n | a (succ b) := add (times a b) a\n\ninstance : has_mul Natural :=\n{ mul := times}\n\ndef pow : Natural -> Natural -> Natural\n | a zero := (succ zero)\n | a (succ b) := times (pow a b) a\n\ninstance : has_pow Natural Natural :=\n { pow := pow}\n\ntheorem add_associativity (a b c : Natural) : (a + b) + c = a + (b + c) :=\nNatural.rec_on c\n(show (a + b) + 0 = a + (b + 0), from calc\n      (a + b) + 0 = a + b : rfl\n              ... = a + (b + 0) : rfl\n)\n(assume c, assume ih : (a + b) + c = a + (b + c),\n show (a + b) + (c + 1) = a + (b + (c + 1)), from calc\n      (a + b) + (c + 1) = ((a + b) + c) + 1 : rfl\n                    ... = (a + (b + c)) + 1 : by rw ih\n                    ... = a + ((b + c) + 1) : rfl\n                    ... = a + (b + (c + 1)) : rfl\n)\n\nlemma zero_commutativity (a : Natural) : a + 0 = 0 + a :=\nNatural.rec_on a\n(show zero + 0 = 0 + zero, from rfl\n)\n(assume a, assume ih : a + 0 = 0 + a,\n show (a + 1) + 0 = 0 + (a + 1), from calc\n      (a + 1) + 0 = a + 1 : rfl\n              ... = (a + 0) +1 : rfl\n              ... = (0 + a) + 1 : by rw ih\n              ... = 0 + (a + 1) : rfl\n)\n\nlemma one_commutativity (a : Natural) : a + 1 = 1 + a :=\nNatural.rec_on a\n(show (0 + 1 : Natural) = 1 + 0, by rw zero_commutativity)\n(assume a, assume ih : a + 1 = 1 + a,\n show (a + 1) + 1 = 1 + (a + 1), from calc\n      (a + 1) + 1 = (1 + a) + 1 : by rw ih\n              ... = 1 + (a + 1) : rfl\n)\n\ntheorem add_commutativity (a b : Natural) : a + b = b + a :=\nNatural.rec_on b\n(show (a + 0 : Natural) = 0 + a, by rw zero_commutativity)\n(assume b, assume ih : a + b = b + a,\n show a + (b + 1) = (b + 1) + a, from calc\n      a + (b + 1) = (a + b) + 1 : by rw add_associativity\n              ... = (b + a) + 1 : by rw ih\n              ... = b + (a + 1) : by rw add_associativity\n              ... = b + (1 + a) : by rw one_commutativity\n              ... = (b + 1) + a : by rw add_associativity\n)\n\n-- Question 1a\ntheorem left_distributivity (a b c : Natural) : a * (b + c) = a * b + a * c :=\nNatural.rec_on c\n(show a * (b + 0) = a * b + a * 0, from calc\n      a * (b + 0) = a * b : rfl\n              ... = a * b + 0 : rfl\n              ... = a * b + a * 0 : rfl\n)\n(assume c, assume ih : a * (b + c) = a * b + a * c,\n show a * (b + (c + 1)) = a * b + a * (c + 1), from calc\n      a * (b + (c + 1)) = a * ((b + c) + 1) : by rw add_associativity\n                    ... = a * (b + c) + a : rfl\n                    ... = (a * b + a * c) + a : by rw ih\n                    ... = a * b + (a * c + a) : by rw add_associativity\n                    ... = a * b + a * (c + 1) : rfl\n)\n\nlemma times_zero (a : Natural) : 0 * a = 0 :=\nNatural.rec_on a\n(show (0 * 0 : Natural) = 0, by refl)\n(assume a, assume ih : 0 * a = 0,\n show 0 * (a + 1) = 0, from calc\n      0 * (a + 1) = 0 * a + 0 * 1 : by rw left_distributivity\n              ... = 0 + 0 * 1 : by rw ih\n              ... = 0 + 0 : rfl\n              ... = 0 : rfl\n)\n\ntheorem right_distributivity (a b c : Natural) : (a + b) * c = a * c + b * c :=\nNatural.rec_on c\n(show (a + b) * 0 = a * 0 + b * 0, by refl)\n(assume c, assume ih : (a + b) * c = a * c + b * c,\n show (a + b) * (c + 1) = a * (c + 1) + b * (c + 1), from calc\n      (a + b) * (c + 1) = ((a + b) * c) + (a + b) : rfl\n                    ... = (a * c + b * c) + (a + b) : by rw ih\n                    ... = ((a * c + b * c) + a) + b : by rw \u2190 add_associativity\n                    ... = (a * c + (b * c + a)) + b : by rw \u2190 add_associativity\n                    ... = (a * c + (a + b * c)) + b : by rw add_commutativity (b * c)\n                    ... = ((a * c + a) + b * c) + b : by rw \u2190 add_associativity\n                    ... = (a * c + a) + (b * c + b) : by rw \u2190 add_associativity\n                    ... = a * (c + 1) + b * (c + 1) : by refl\n)\n\nlemma right_times_one (a : Natural) : a * 1 = a :=\n(show a * 1 = a, from calc\n      a * 1 = a * 0 + a : rfl\n        ... = 0 + a : rfl\n        ... = a + 0 : by rw add_commutativity\n        ... = a : rfl\n)\n\nlemma left_times_one (a : Natural) : 1 * a = a :=\nNatural.rec_on a\n(show (1 * 0 : Natural) = 0, by refl)\n(assume a, assume ih : 1 * a = a, \n show 1 * (a + 1) = a + 1, from calc\n      1 * (a + 1) = 1 * a + 1 : rfl\n             ...  = a + 1 : by rw ih\n)\n\n-- Question 1b\ntheorem times_commutativity (a b : Natural) : a * b = b * a :=\nNatural.rec_on b\n(show a * 0 = 0 * a, from calc\n      a * 0 = 0 : rfl\n        ... = 0 * a : by rw times_zero\n)\n(assume b, assume ih : a * b = b * a,\n show a * (b + 1) = (b + 1) * a, from calc\n      a * (b + 1) = a * b + a : rfl\n              ... = b * a + a : by rw ih\n              ... = a + b * a : by rw add_commutativity\n              ... = 1 * a + b * a : by rw left_times_one\n              ... = (1 + b) * a : by rw right_distributivity\n              ... = (b + 1) * a : by rw add_commutativity\n)\n\n-- Question 1c\ntheorem times_associativity (a b c : Natural) : (a * b) * c = a * (b * c) :=\nNatural.rec_on c\n(show (a * b) * 0 = a * (b * 0), from calc\n      (a * b) * 0 = 0 : rfl\n              ... = a * 0 : rfl\n              ... = a * (b * 0) : rfl\n)\n(assume c, assume ih : (a * b) * c = a * (b * c),\n show (a * b) * (c + 1) = a * (b * (c + 1)), from calc\n      (a * b) * (c + 1) = (a * b) * c + a * b : rfl\n                    ... = a * (b * c) + a * b : by rw ih\n                    ... = a * ((b * c) + b) : by rw left_distributivity\n                    ... = a * (b * (c + 1)) : rfl\n)\n\nend hidden", "meta": {"author": "MartinSkilleter", "repo": "real_ip_spaces", "sha": "1ad1e0456602038711cbb0de7aa92b88d6eff06f", "save_path": "github-repos/lean/MartinSkilleter-real_ip_spaces", "path": "github-repos/lean/MartinSkilleter-real_ip_spaces/real_ip_spaces-1ad1e0456602038711cbb0de7aa92b88d6eff06f/src/Assignment 1/Q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7176085792519139}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 9 / 2, from by auto [add_three, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_add_div_same, div_\nend --Needs more than 2000 tokens!\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 (9 / 2), from by auto [add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add\nend --Needs more than 2000 tokens!\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) \u2265 9 / 2, from by auto [add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_div, add_\nend --Needs more than 2000 tokens!\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],\n  have h2 : (A \u2229 B) \u2286 A, from by auto [set.inter_subset_left],\n  have h3 : (A \u2229 B) \u2286 S, from by auto [set.subset.trans],\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by auto [set.mem_powerset],\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]\n  ... = x*(x+y) + y*(x+y) : by auto [add_mul]\n  ... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]\n  ... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring]\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by auto using [use (a\u207b\u00b9 * b)],\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by auto using [use b * a\u207b\u00b9], \n\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from by auto [h1],\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from by auto [h2],\n\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one],\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul],\n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)],\nend\n\n/--`theorem`\nNesbitt's inequality\nLet $a$, $b$ and $c$ be positive real numbers.\n\nThen:\n:$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n\n`proof`\n{{begin-eqn}}\n{{eqn | l = \\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}\n      | o = \\ge\n      | r = \\dfrac 3 2\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac 9 2\n      | c = by adding $3$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3\n      | o = \\ge\n      | r = \\frac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = dividing by $3 \\paren {a + b + c}$\n}}\n{{end-eqn}}\nThese are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n\nFrom Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n\nThus Nesbitt's Inequality holds.\n{{qed}}\n\n-/\ntheorem  nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_auto-Natural-Language-Proof-Translation/Correct_statement-lean_proof_auto-3_few_shot_temperature_0.2_max_tokens_2000_n_3/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7176019418575815}}
{"text": "-- Interseccion_con_la_imagen.lean\n-- Intersecci\u00f3n con la imagen\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 19 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariable  s : set \u03b1\nvariable  v : set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin\n  ext y,\n  split,\n  { intro hy,\n    cases hy with hyfs yv,\n    cases hyfs with x hx,\n    cases hx with xs fxy,\n    use x,\n    split,\n    { split,\n      { exact xs, },\n      { rw mem_preimage,\n        rw fxy,\n        exact yv, }},\n    { exact fxy, }},\n  { intro hy,\n    cases hy with x hx,\n    split,\n    { use x,\n      split,\n      { exact hx.1.1, },\n      { exact hx.2, }},\n    { cases hx with hx1 fxy,\n      rw \u2190 fxy,\n      rw \u2190 mem_preimage,\n      exact hx1.2, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8\u27e8x, xs, fxy\u27e9, yv\u27e9,\n    use x,\n    split,\n    { split,\n      { exact xs, },\n      { rw mem_preimage,\n        rw fxy,\n        exact yv, }},\n    { exact fxy, }},\n  { rintros \u27e8x, \u27e8xs, xv\u27e9, fxy\u27e9,\n    split,\n    { use [x, xs, fxy], },\n    { rw \u2190 fxy,\n      rw \u2190 mem_preimage,\n      exact xv, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8\u27e8x, xs, fxy\u27e9, yv\u27e9,\n    finish, },\n  { rintros \u27e8x, \u27e8xs, xv\u27e9, fxy\u27e9,\n    finish, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nby ext ; split ; finish\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nby finish [ext_iff, iff_def]\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\n(image_inter_preimage f s v).symm\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Interseccion_con_la_imagen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.8633916011860785, "lm_q1q2_score": 0.717601941349906}}
{"text": "-- M40002 (Analysis I) Chapter 5. Continuity\n\nimport M40002.M40002_C4\nimport data.polynomial\n\nnamespace M40002\n\n-- Definition of limits of functions (f(x) \u2192 b as x \u2192 a)\ndef func_converges_to (f : \u211d \u2192 \u211d) (a b : \u211d) := \u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x : \u211d, abs (x - a) < \u03b4 \u2192 abs (f x - b) < \u03b5\n\n-- Definition of continuity at a point\ndef func_continuous_at (f : \u211d \u2192 \u211d) (a : \u211d) := func_converges_to f a (f a)\n\n-- Definition of a continuous function\ndef func_continuous (f : \u211d \u2192 \u211d) := \u2200 a : \u211d, func_continuous_at f a\n\n-- Defintion composition of functions and sequences for sequential continuity\ndef func_seq_comp (f : \u211d \u2192 \u211d) (s : \u2115 \u2192 \u211d) (n : \u2115) := f (s n)\n\n-- The definition for limits can have an alternative restriction of 0 < abs (x - a)\ntheorem func_continuous_at_to_pos (f : \u211d \u2192 \u211d) (a : \u211d) : func_continuous_at f a \u2194 \u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x : \u211d, 0 < abs (x - a) \u2227 abs (x - a) < \u03b4 \u2192 abs (f x - f a) < \u03b5 :=\nbegin\n\tsplit,\n\t\t{intros hconv \u03b5 h\u03b5,\n\t\trcases hconv \u03b5 h\u03b5 with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\t\tuse \u03b4, use h\u03b4\u2081,\n\t\tintros x hx,\n\t\tfrom h\u03b4\u2082 x hx.right\n\t\t},\n\t\t{intros hconv \u03b5 h\u03b5,\n\t\trcases hconv \u03b5 h\u03b5 with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\t\tuse \u03b4, use h\u03b4\u2081,\n\t\tintros x hx,\n\t\tcases lt_or_le 0 (abs (x - a)),\n\t\t\tfrom h\u03b4\u2082 x \u27e8h, hx\u27e9,\n\t\t\thave : x = a :=\n\t\t\t\tby {suffices : abs (x - a) = 0,\n\t\t\t\tfrom eq_of_abs_sub_eq_zero this,\n\t\t\t\tcases lt_or_eq_of_le h,\n\t\t\t\trw \u2190not_le at h_1, exfalso,\n\t\t\t\tapply h_1, from abs_nonneg (x - a),\n\t\t\t\tassumption\n\t\t\t\t},\n\t\t\trw this, simp,\n\t\t\tassumption\t\t\n\t\t}\nend\n\n-- Sequential continuity\nlemma seq_contin_conv_lem {s : \u2115 \u2192 \u211d} {a : \u211d} (h : \u2200 n : \u2115, abs (s n - a) < 1 / (n + 1)) : s \u21d2 a :=\nbegin\n\tintros \u03b5 h\u03b5,\n\tcases exists_nat_gt (1 / \u03b5) with N\u2080 hN\u2080,\n\tlet N : \u2115 := max N\u2080 1,\n\thave hN : 1 / \u03b5 < (N : \u211d) :=\n\t\tby {apply lt_of_lt_of_le hN\u2080,\n\t\tnorm_cast, apply le_max_left\n\t\t},\n\tuse N, intros n hn,\n\tapply lt_trans (h n),\n\trw one_div_lt _ h\u03b5,\n\t\t{apply lt_trans hN,\n\t\tnorm_cast, linarith},\n\t\t{norm_cast, linarith}\nend\t\n\ntheorem lambda_rw (n : \u2115) (f : \u2115 \u2192 \u211d) : (\u03bb x : \u2115, f x) n = f n := by {rw eq_self_iff_true, trivial}\n\ntheorem seq_contin {f : \u211d \u2192 \u211d} {a b : \u211d} : (func_converges_to f a b) \u2194 \u2200 s : \u2115 \u2192 \u211d, s \u21d2 a \u2192 func_seq_comp f s \u21d2 b :=\nbegin\n    split,\n        {intros h s hs \u03b5 h\u03b5,\n        rcases h \u03b5 h\u03b5 with \u27e8\u03b4, \u27e8h\u03b4, hr\u27e9\u27e9,\n        cases hs \u03b4 h\u03b4 with N hN,\n        use N, intros n hn,\n        have : abs (s n - a) < \u03b4 := hN n hn,\n        from hr (s n) this\n        },\n        {intros h,\n        cases classical.em (func_converges_to f a b) with ha ha,\n        from ha,\n        unfold func_converges_to at ha,\n        push_neg at ha,\n        rcases ha with \u27e8\u03b5, \u27e8h\u03b5, h\u03b4\u27e9\u27e9,\n\t\thave h\u03b1 : \u2200 n : \u2115, 1 / ((n : \u211d) + 1) > 0 := \n\t\t\tby {intro n, simp,\n\t\t\tnorm_cast, from nat.zero_lt_one_add n},\n\t\thave h\u03b2 : \u2200 n : \u2115, \u2203 (x : \u211d), abs (x - a) < (1 / (n + 1)) \u2227 \u03b5 \u2264 abs (f x - b) := \u03bb n, h\u03b4 (1 / (n + 1)) (h\u03b1 n),\n        let s : \u2115 \u2192 \u211d := \u03bb n : \u2115, classical.some (h\u03b2 n),\n\t\thave h\u2080 : s  = \u03bb n : \u2115, classical.some (h\u03b2 n) := rfl,\n\t\thave hsn : \u2200 n : \u2115, abs (s n - a) < 1 / ((n : \u211d) + 1) \u2227 \u03b5 \u2264 abs (func_seq_comp f s n - b) :=\n\t\t\tby {intro n, rw [h\u2080, lambda_rw n s],\n\t\t\tfrom classical.some_spec (h\u03b2 n)\n\t\t\t},\n\t\thave h\u2081 : s \u21d2 a := \n\t\t\tby {have : \u2200 n : \u2115, abs (s n - a) < 1 / ((n : \u211d) + 1) :=\n\t\t\t\tby {intro n, from (hsn n).left},\n\t\t\tfrom seq_contin_conv_lem this\n\t\t\t},\n        have h\u2082 : \u00ac (func_seq_comp f s \u21d2 b) :=\n            by {unfold converges_to,\n            push_neg, use \u03b5,\n            split, from h\u03b5,\n            intro N, use N,\n            split, from nat.le_refl N,\n\t\t\tfrom (hsn N).right\n            },\n\t\texfalso; from h\u2082 (h s h\u2081)\n        }\nend\n\n-- Algebra of limits for functions\ndef func_add_func (f g : \u211d \u2192 \u211d) := \u03bb r : \u211d, f r + g r\ninstance : has_add (\u211d \u2192 \u211d) := \u27e8func_add_func\u27e9\n\n\ntheorem func_add_func_conv (f g : \u211d \u2192 \u211d) (a b\u2081 b\u2082) : func_converges_to f a b\u2081 \u2227 func_converges_to g a b\u2082 \u2192 func_converges_to (f + g) a (b\u2081 + b\u2082) :=\nbegin\n\trintro \u27e8ha, hb\u27e9,\n\trw seq_contin,\n\tintros s hs,\n\thave : func_seq_comp (f + g) s = seq_add_seq (func_seq_comp f s) (func_seq_comp g s) := rfl,\n\trw this,\n\tapply add_lim_conv,\n\tfrom \u27e8seq_contin.mp ha s hs, seq_contin.mp hb s hs\u27e9\nend\n\ntheorem func_add_func_contin (f g : \u211d \u2192 \u211d) : func_continuous f \u2227 func_continuous g \u2192 func_continuous (f + g) :=\nbegin\n\trintros \u27e8ha, hb\u27e9 a,\n\tapply func_add_func_conv,\n\tfrom \u27e8ha a, hb a\u27e9\nend\n\ndef func_mul_func (f g : \u211d \u2192 \u211d) := \u03bb r : \u211d, f r * g r\nnotation f ` \u00d7 ` g := func_mul_func f g\n\ntheorem func_mul_func_conv (f g : \u211d \u2192 \u211d) (a b\u2081 b\u2082) : func_converges_to f a b\u2081 \u2227 func_converges_to g a b\u2082 \u2192 func_converges_to (f \u00d7 g) a (b\u2081 * b\u2082) :=\nbegin\n\trintro \u27e8ha, hb\u27e9,\n\trw seq_contin,\n\tintros s hs,\n\thave : func_seq_comp (f \u00d7 g) s = seq_mul_seq (func_seq_comp f s) (func_seq_comp g s) := rfl,\n\trw this,\n\tapply mul_lim_conv,\n\tfrom seq_contin.mp ha s hs,\n\tfrom seq_contin.mp hb s hs,\nend\n\ntheorem func_mul_func_contin (f g : \u211d \u2192 \u211d) : func_continuous f \u2227 func_continuous g \u2192 func_continuous (f \u00d7 g) :=\nbegin\n\trintros \u27e8ha, hb\u27e9 a,\n\tapply func_mul_func_conv,\n\tfrom \u27e8ha a, hb a\u27e9\nend\n\nnoncomputable def func_div_func (f g : \u211d \u2192 \u211d) := \u03bb r : \u211d, (f r) / (g r)\nnoncomputable instance func_div : has_div (\u211d \u2192 \u211d) := \u27e8func_div_func\u27e9\n\ntheorem func_div_func_conv (f g : \u211d \u2192 \u211d) (a b\u2081 b\u2082) (h : b\u2082 \u2260 0) : func_converges_to f a b\u2081 \u2227 func_converges_to g a b\u2082 \u2192 func_converges_to (f / g) a (b\u2081 / b\u2082) :=\nbegin\n\trintro \u27e8ha, hb\u27e9,\n\trw seq_contin,\n\tintros s hs,\n\thave : func_seq_comp (f / g) s = seq_div_seq (func_seq_comp f s) (func_seq_comp g s) := rfl,\n\trw this,\n\tapply div_lim_conv,\n\tfrom seq_contin.mp ha s hs,\n\tfrom seq_contin.mp hb s hs,\n\tnorm_cast, assumption\nend\n\ntheorem func_comp_func_conv (f g : \u211d \u2192 \u211d) (a b c : \u211d) : func_converges_to f a b \u2227 func_converges_to g b c \u2192 func_converges_to (g \u2218 f) a c :=\nbegin\n\trepeat {rw seq_contin},\n\trintro \u27e8ha, hb\u27e9,\n\tintros s hs,\n\thave : func_seq_comp (g \u2218 f) s = func_seq_comp g (func_seq_comp f s) := rfl,\n\trw this,\n\tapply hb (func_seq_comp f s),\n\tfrom ha s hs\nend\n\ntheorem func_comp_func_contin (f g : \u211d \u2192 \u211d) : func_continuous f \u2227 func_continuous g \u2192 func_continuous (g \u2218 f) :=\nbegin\n\trepeat {unfold func_continuous},\n\trintros \u27e8ha, hb\u27e9 a,\n\tapply func_comp_func_conv,\n\tswap, from f a,\n\tfrom \u27e8ha a, hb (f a)\u27e9\nend\n\n-- All polynomials and rational functions are continuous\n\nlemma constant_contin (c : \u211d) : func_continuous (\u03bb x : \u211d, c) :=\nbegin\n\tintros a \u03b5 h\u03b5,\n\tsimp, use \u03b5,\n\tfrom \u27e8h\u03b5, \u03bb x, \u03bb hx, h\u03b5\u27e9\nend\n\nlemma x_contin : func_continuous (\u03bb x : \u211d, x) :=\nbegin\n\tintros a \u03b5 h\u03b5,\n\tsimp, use \u03b5,\n\tfrom \u27e8h\u03b5, \u03bb x, \u03bb hx, hx\u27e9\nend\n\nlemma xn_contin (n : \u2115) : func_continuous (\u03bb x : \u211d, x ^ n) :=\nbegin\n\tinduction n with k hk,\n\t\t{simp, from constant_contin (1 : \u211d)},\n\t\t{have : (\u03bb (x : \u211d), x ^ nat.succ k) = func_mul_func (\u03bb x : \u211d, x) (\u03bb x : \u211d, x ^ k) := rfl,\n\t\trw this,\n\t\tapply func_mul_func_contin,\n\t\tfrom \u27e8x_contin, hk\u27e9\n\t\t}\nend\n\ntheorem poly_contin {f : polynomial \u211d} : func_continuous (\u03bb x, f.eval x) :=\nbegin\n\tapply polynomial.induction_on f,\n\t\t{intro a, simp,\n\t\tfrom constant_contin a\n\t\t},\n\t\t{intros p q hp hq, simp, \n\t\tapply func_add_func_contin (\u03bb x : \u211d, polynomial.eval x p) (\u03bb x : \u211d, polynomial.eval x q),\n\t\tfrom \u27e8hp, hq\u27e9\n\t\t},\n\t\tsimp,\n\t\tintros n a hcon,\n\t\tapply func_mul_func_contin,\n\t\tfrom \u27e8constant_contin a, xn_contin (n + 1)\u27e9\nend\n\n-- Intermediate Value Theorem\ntheorem intermediate_value {f : \u211d \u2192 \u211d} {a b : \u211d} (h\u2080 : a \u2264 b) (h\u2081 : func_continuous f) : \u2200 y : \u211d, f a \u2264 y \u2227 y \u2264 f b \u2192 \u2203 c : \u211d, a \u2264 c \u2227 c \u2264 b \u2227 f c = y :=\nbegin\n\trintros y \u27e8hy\u2081, hy\u2082\u27e9,\n\tcases eq_or_lt_of_le hy\u2081 with heq hlt\u2080,\n\t\t{use a, split, linarith,\n\t\trw heq, from \u27e8h\u2080, refl y\u27e9\n\t\t},\n\t\t{cases eq_or_lt_of_le hy\u2082 with heq hlt\u2081,\n\t\t\t{use b, split, linarith,\n\t\t\trw heq, from \u27e8le_refl b, refl (f b)\u27e9\n\t\t\t},\n\t\tclear hy\u2081 hy\u2082,\n\t\tlet S : set \u211d := {d : \u211d | a \u2264 d \u2227 d \u2264 b \u2227 f d < y},\n\t\thave hbdd : bounded_above S :=\n\t\t\tby {use b, intros s hs, \n\t\t\trw set.mem_set_of_eq at hs,\n\t\t\tfrom hs.right.left\n\t\t\t},\n\t\thave hnempty : S \u2260 \u2205 :=\n\t\t\tby {dsimp, rw set.not_eq_empty_iff_exists,\n\t\t\tuse a, rw set.mem_set_of_eq,\n\t\t\tfrom \u27e8le_refl a, h\u2080, hlt\u2080\u27e9\n\t\t\t},\n\t\tcases completeness S hbdd hnempty with M hM,\n\t\tuse M, split,\n\t\t\tapply hM.left a,\n\t\t\trw set.mem_set_of_eq,\n\t\t\tfrom \u27e8le_refl a, h\u2080, hlt\u2080\u27e9,\n\t\tsplit,\n\t\t\tunfold sup at hM,\n\t\t\thave h\u03b1 : upper_bound S b :=\n\t\t\t\tby {intros s hs,\n\t\t\t\trw set.mem_set_of_eq at hs,\n\t\t\t\tfrom hs.right.left\n\t\t\t\t},\n\t\t\tcases le_or_lt M b with h\u03b2 h\u03b3,\n\t\t\t\tfrom h\u03b2,\n\t\t\t\texfalso; from (hM.right b h\u03b3) h\u03b1,\n\t\trw le_antisymm_iff,\n\t\tsplit,\n\t\t\t{apply classical.by_contradiction,\n\t\t\tpush_neg, intro h,\n\t\t\thave : \u2203 \u03b5 : \u211d, \u03b5 = f M - y \u2227 0 < \u03b5 :=\n\t\t\t\tby {use f M - y,\n\t\t\t\tsplit, refl,\n\t\t\t\tlinarith\n\t\t\t\t},\n\t\t\tcases this with \u03b5 h\u03b5,\n\t\t\trcases h\u2081 M \u03b5 h\u03b5.right with \u27e8\u03b4, \u27e8h\u03b4, hh\u03b4\u27e9\u27e9,\n\t\t\trw h\u03b5.left at hh\u03b4,\n\t\t\thave : \u2200 (x : \u211d), abs (x - M) < \u03b4 \u2192 - (f M - y) < f x - f M \u2227 f x - f M < f M - y :=\n\t\t\t\tby {intros x hx,\n\t\t\t\tapply abs_lt.mp,\n\t\t\t\tfrom hh\u03b4 x hx},\n\t\t\tsimp at this,\n\t\t\treplace this : \u2200 (x : \u211d), abs (x - M) < \u03b4 \u2192 x \u2209 S :=\n\t\t\t\tby {intros x hx hS,\n\t\t\t\trw set.mem_set_of_eq at hS,\n\t\t\t\tapply asymm (hS.right.right),\n\t\t\t\tfrom (this x hx).left\n\t\t\t\t},\n\t\t\treplace this : upper_bound S (M - \u03b4) :=\n\t\t\t\tby {intros s hs,\n\t\t\t\tcases lt_or_le s (M - \u03b4),\n\t\t\t\t\t{from le_of_lt h_1},\n\t\t\t\t\t{cases lt_or_eq_of_le h_1,\n\t\t\t\t\tswap, linarith,\n\t\t\t\t\thave hkt : abs (s - M) < \u03b4 :=\n\t\t\t\t\t\tby {rw abs_lt,\n\t\t\t\t\t\tsplit, linarith,\n\t\t\t\t\t\trw sub_lt_iff_lt_add,\n\t\t\t\t\t\tapply lt_of_le_of_lt (hM.left s hs),\n\t\t\t\t\t\tlinarith\n\t\t\t\t\t\t},\n\t\t\t\t\texfalso,\n\t\t\t\t\tfrom (this s hkt) hs\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\thave hfa : M - \u03b4 < M :=\n\t\t\t\tby {linarith},\n\t\t\tfrom (hM.right (M - \u03b4) hfa) this\n\t\t\t},\n\n\t\t\t{have h\u03b1 : upper_bound S b :=\n\t\t\t\tby {intros s hs,\n\t\t\t\trw set.mem_set_of_eq at hs,\n\t\t\t\tfrom hs.right.left\n\t\t\t\t},\n\t\t\thave h\u03b2 : M \u2264 b := by {rw \u2190not_lt, intro h\u03b3, from hM.right b h\u03b3 h\u03b1},\n\t\t\tcases lt_or_eq_of_le h\u03b2,\n\t\t\tswap, rw h, from le_of_lt hlt\u2081,\n\n\t\t\tapply classical.by_contradiction,\n\t\t\tpush_neg, intro h,\n\t\t\thave : \u2203 \u03b5 : \u211d, \u03b5 = y - f M \u2227 0 < \u03b5 :=\n\t\t\t\tby {use y - f M,\n\t\t\t\tsplit, refl,\n\t\t\t\tlinarith\n\t\t\t\t},\n\t\t\tcases this with \u03b5 h\u03b5,\n\t\t\trcases h\u2081 M \u03b5 h\u03b5.right with \u27e8\u03b4, \u27e8h\u03b4, hh\u03b4\u27e9\u27e9,\n\t\t\trw h\u03b5.left at hh\u03b4,\n\t\t\thave : abs (M + (\u03b4 / 2) - M) < \u03b4 := \n\t\t\t\tby {simp,\n\t\t\t\trw abs_of_pos (half_pos h\u03b4),\n\t\t\t\tlinarith\n\t\t\t\t},\n\t\t\treplace this : abs (M + min (\u03b4 / 2) ((b - M) / 2) - M) < \u03b4 := \n\t\t\t\tby {apply lt_of_le_of_lt _ this,\n\t\t\t\trw add_comm, simp,\n\t\t\t\thave hpos : 0 < min (\u03b4 / 2) ((b + -M) / 2) :=\n\t\t\t\t\tby {simp, split,\n\t\t\t\t\tfrom half_pos h\u03b4,\n\t\t\t\t\tlinarith\n\t\t\t\t\t},\n\t\t\t\trw [abs_of_pos hpos, abs_of_pos (half_pos h\u03b4)],\n\t\t\t\tfrom min_le_left (\u03b4 / 2) ((b - M) / 2),\n\t\t\t\t},\n\t\t\treplace this : abs (f (M + min (\u03b4 / 2) ((b - M) / 2)) - f M) < y - f M :=\n\t\t\t\tby {from hh\u03b4 (M + min (\u03b4 / 2) ((b - M) / 2)) this},\n\t\t\trw abs_lt at this,\n\t\t\tcases this with h\u2083 h\u2084,\n\t\t\tsimp at h\u2084,\n\t\t\thave h\u2085 : M < M + min (\u03b4 / 2) ((b + -M) / 2) :=\n\t\t\t\tby {simp, split,\n\t\t\t\tfrom half_pos h\u03b4,\n\t\t\t\tlinarith\n\t\t\t\t},\n\t\t\thave h\u2086 : M + min (\u03b4 / 2) ((b + -M) / 2) \u2208 S :=\n\t\t\t\tby {rw set.mem_set_of_eq,\n\t\t\t\tsplit, apply le_of_lt (lt_of_le_of_lt _ h\u2085),\n\t\t\t\thave : a \u2208 S := by {rw set.mem_set_of_eq, from \u27e8le_refl a, h\u2080, hlt\u2080\u27e9},\n\t\t\t\tfrom hM.left a this,\n\t\t\t\tsplit,\n\t\t\t\tcases le_or_lt (\u03b4 / 2) ((b + -M) / 2),\n\t\t\t\t\trw min_eq_left h_1,\n\t\t\t\t\tsuffices : (\u03b4 / 2) < b + -M, linarith,\n\t\t\t\t\tapply lt_of_le_of_lt h_1, linarith,\n\t\t\t\t\trw min_eq_right (le_of_lt h_1),\n\t\t\t\t\tlinarith,\n\t\t\t\t\tfrom h\u2084\n\t\t\t\t},\n\t\t\thave h\u2087 : \u00ac upper_bound S M :=\n\t\t\t\tby {unfold upper_bound,\n\t\t\t\tpush_neg, \n\t\t\t\tuse (M + min (\u03b4 / 2) ((b + -M) / 2)),\n\t\t\t\tfrom \u27e8h\u2086, h\u2085\u27e9\n\t\t\t\t},\n\t\t\tfrom h\u2087 hM.left\n\t\t\t}\n\t\t}\nend\n\ndef func_bounded_above {S : set \u211d} (f : S \u2192 \u211d) := bounded_above {t : \u211d | \u2200 x : S, t = f x}\ndef func_bounded_below {S : set \u211d} (f : S \u2192 \u211d) := bounded_below {t : \u211d | \u2200 x : S, t = f x}\n\n-- TODO Extreme value theorem\n\ndef closed_interval (a b : \u211d) := {x : \u211d | a \u2264 x \u2227 x \u2264 b}\n\nlemma mem_of_closed_interval {a b x : \u211d} : x \u2208 closed_interval a b \u2194 a \u2264 x \u2227 x \u2264 b :=\nby {unfold closed_interval, rw set.mem_set_of_eq}\n\nlemma abs_le_closed_interval {x y \u03b4 : \u211d} : y \u2208 closed_interval (x - \u03b4) (x + \u03b4) \u2194 abs (y - x) \u2264 \u03b4 :=\nbegin\n\tunfold closed_interval,\n\trw [set.mem_set_of_eq, abs_le],\n\tsplit, repeat {rintro \u27e8h\u03b1, h\u03b2\u27e9, split, repeat {linarith}}\nend\n\ndef open_interval (a b : \u211d) := {x : \u211d | a < x \u2227 x < b}\n\nlemma mem_of_open_interval {a b x : \u211d} : x \u2208 open_interval a b \u2194 a < x \u2227 x < b := \nby {unfold open_interval, rw set.mem_set_of_eq}\n\nlemma abs_lt_open_interval {x y \u03b4 : \u211d} : y \u2208 open_interval (x - \u03b4) (x + \u03b4) \u2194 abs (y - x) < \u03b4 :=\nbegin\n\tunfold open_interval,\n\trw [set.mem_set_of_eq, abs_lt],\n\tsplit, repeat {rintro \u27e8h\u03b1, h\u03b2\u27e9, split, repeat {linarith}}\nend\n\n-- Defining open and closed sets\ndef is_open (S : set \u211d) := \u2200 x \u2208 S, \u2203 \u03b4 > 0, open_interval (x - \u03b4) (x + \u03b4) \u2286 S\ndef is_closed (S : set \u211d) := \u2200 a : \u2115 \u2192 \u211d, seq_in a S \u2192 (\u2203 l : \u211d, a \u21d2 l) \u2192 \u2203 l \u2208 S, a \u21d2 l\n\ndef is_compact (S : set \u211d) := is_closed S \u2227 bounded S\n\n-- An open interval is open\ntheorem open_interval_is_open (a b : \u211d) : is_open (open_interval a b) :=\nbegin\n\tunfold open_interval,\n\tintros x hx,\n\thave h\u03b4 : 0 < min (x - a) (b - x) :=\n\t\tby {apply lt_min_iff.mpr,\n\t\trw set.mem_set_of_eq at hx,\n\t\tcases hx with ha hb,\n\t\tsplit, repeat {linarith},\n\t\t},\n\tuse min (x - a) (b - x), use h\u03b4,\n\tunfold open_interval,\n\tintros y hy,\n\trw set.mem_set_of_eq at hy,\n\trw set.mem_set_of_eq,\n\tcases hy with hy\u2081 hy\u2082,\n\tsplit,\n\t\t{apply lt_of_le_of_lt _ hy\u2081,\n\t\thave : min (x - a) (b - x) \u2264 x - a := min_le_left (x - a) (b - x),\n\t\tlinarith\n\t\t},\n\t\t{apply lt_of_lt_of_le hy\u2082,\n\t\thave : min (x - a) (b - x) \u2264 b - x := min_le_right (x - a) (b - x),\n\t\tlinarith\n\t\t}\nend\n\n-- A closed interval is compact\ntheorem closed_interval_is_compact (a b : \u211d) : is_compact (closed_interval a b) :=\nbegin\n\tsplit,\n\t\t{unfold is_closed,\n\t\trintros s ha \u27e8l, hl\u27e9,\n\t\tuse l,\n\t\thave h : l \u2208 closed_interval a b :=\n\t\t\tby{unfold closed_interval,\n\t\t\trw set.mem_set_of_eq,\n\t\t\tsplit,\n\t\t\t\t{let c : \u2115 \u2192 \u211d := \u03bb n : \u2115, a,\n\t\t\t\thave : c \u21d2 a := cons_conv,\n\t\t\t\tapply le_lim c s a l,\n\t\t\t\trepeat {assumption},\n\t\t\t\tintro n,\n\t\t\t\tshow a \u2264 s n,\n\t\t\t\tsuffices : s n \u2208 closed_interval a b,\n\t\t\t\t\tunfold closed_interval at this,\n\t\t\t\t\trw set.mem_set_of_eq at this,\n\t\t\t\t\tfrom this.left,\n\t\t\t\tfrom ha n\n\t\t\t\t},\n\t\t\t\t{let c : \u2115 \u2192 \u211d := \u03bb n : \u2115, b,\n\t\t\t\thave : c \u21d2 b := cons_conv,\n\t\t\t\tapply le_lim s c l b,\n\t\t\t\trepeat {assumption},\n\t\t\t\tintro n,\n\t\t\t\tshow s n \u2264 b,\n\t\t\t\tsuffices : s n \u2208 closed_interval a b,\n\t\t\t\t\tunfold closed_interval at this,\n\t\t\t\t\trw set.mem_set_of_eq at this,\n\t\t\t\t\tfrom this.right,\n\t\t\t\tfrom ha n\n\t\t\t\t}\n\t\t\t},\n\t\tuse h, assumption\n\t\t},\n\t\t{split,\n\t\t\t{use b, intro s,\n\t\t\tunfold closed_interval,\n\t\t\trw set.mem_set_of_eq,\n\t\t\tintro h, from h.right\n\t\t\t},\n\t\t\t{use a, intro s,\n\t\t\tunfold closed_interval,\n\t\t\trw set.mem_set_of_eq,\n\t\t\tintro h, from h.left\n\t\t\t}\n\t\t}\nend\n\n-- The union of open sets is also open\ntheorem two_union_open_is_open {S T : set \u211d} (h\u2081 : is_open S) (h\u2082 : is_open T) : is_open (S \u222a T) :=\nbegin\n\tintros x hx,\n\trw (set.mem_union x S T) at hx,\n\tcases hx,\n\t\t{rcases (h\u2081 x hx) with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\t\tuse \u03b4, use h\u03b4\u2081,\n\t\tintros a ha, left,\n\t\tfrom h\u03b4\u2082 ha\n\t\t},\n\t\t{rcases (h\u2082 x hx) with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\t\tuse \u03b4, use h\u03b4\u2081,\n\t\tintros a ha, right,\n\t\tfrom h\u03b4\u2082 ha\n\t\t}\nend\n\n-- The empty set is open\ntheorem empty_open : is_open \u2205 := \nbegin\n\tintros x hx,\n\texfalso, from hx\nend\n\n-- The union of a collection of open sets is also open\ntheorem union_open_is_open {I : Type} {S : I \u2192 set \u211d} (h\u2081 : \u2200 i : I, is_open (S i)) : is_open \u22c3 i : I, S i :=\nbegin\n\tintros x hx,\n\trw set.mem_Union at hx,\n\tcases hx with i hi,\n\thave h\u2082 : is_open (S i) := h\u2081 i,\n\tunfold is_open at h\u2082,\n\thave h\u2083 : S i \u2286 \u22c3 (i : I), S i := set.subset_Union S i,\n\trcases h\u2082 x hi with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\tuse \u03b4, use h\u03b4\u2081,\n\tfrom set.subset.trans h\u03b4\u2082 h\u2083\nend\n\nlemma element_of_Inter {S : \u2115 \u2192 set \u211d} {n i : \u2115} : \u2200 x \u2208 \u22c2 i \u2208 finset.range n, S i, i \u2208 finset.range n \u2192 x \u2208 S i :=\nby {intros x hx hi, rw set.mem_Inter at hx, finish}\n\nlemma comp_open_to_closed {S : set \u211d} : is_open S \u2192 is_closed (-S) :=\nbegin\n\tintro hopen,\n\trintros a x \u27e8l, hl\u27e9,\n\tuse l,\n\thave : l \u2208 -S :=\n\t\tby {intro hS,\n\t\trcases hopen l hS with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\t\tcases hl \u03b4 h\u03b4\u2081 with N hN,\n\t\tapply x N,\n\t\tsuffices : a N \u2208 open_interval (l - \u03b4) (l + \u03b4),\n\t\t\tfrom h\u03b4\u2082 this,\n\t\trw abs_lt_open_interval,\n\t\tapply hN N (le_refl N)\n\t\t},\n\tuse this, assumption\nend\n\nlemma lt_\u03b5_ge_zero {N : \u2115} {\u03b5 : \u211d} (h : 0 < \u03b5) : 1 / \u03b5 < N \u2192 1 / (N : \u211d) < \u03b5 :=\nby {intro h\u03b1,\n\thave h\u03b2 : 0 < N, cases lt_or_le 0 N, assumption,\n\texfalso, apply not_le.mpr h,\n\tsuffices : 1 / \u03b5 \u2264 0, simp only [one_div_eq_inv, inv_nonpos] at this, assumption,\n\tapply le_of_lt, apply lt_of_lt_of_le h\u03b1, norm_cast, assumption,\n\n\trw [div_lt_iff, mul_comm], rwa div_lt_iff at h\u03b1,\n\tassumption, norm_cast, assumption\n}\n\nlemma comp_closed_to_open {S : set \u211d} : is_closed S \u2192 is_open (-S) :=\nbegin\n\tintros hclosed x hx,\n\tapply classical.by_contradiction,\n\tpush_neg,\n\tintro hnopen,\n\thave : \u2200 n : \u2115, \u2203 s \u2208 open_interval (x - (1 / (n + 1))) (x + (1 / (n + 1))), s \u2208 S :=\n\t\tby {intros n,\n\t\tapply classical.by_contradiction,\n\t\tpush_neg,\n\t\tintro h,\n\t\tsuffices : open_interval (x - (1 / (n + 1))) (x + (1 / (n + 1))) \u2286 -S,\n\t\t\tfrom hnopen (1 / (n + 1)) nat.one_div_pos_of_nat this,\n\t\tintros s hs,\n\t\tfrom h s hs\n\t\t}, \n\tsimp only [classical.skolem] at this,\n\trcases this with \u27e8t, ht\u2081, ht\u2082\u27e9,\n\thave ht : t \u21d2 x :=\n\t\tby {intros \u03b5 h\u03b5,\n\t\tcases exists_nat_gt (1 / \u03b5) with N hN,\n\t\tuse N, intros n hn,\n\t\trw \u2190abs_lt_open_interval,\n\t\tsuffices : open_interval  (x - 1 / (n + 1)) (x + 1 / (n + 1)) \u2286 open_interval (x - \u03b5) (x + \u03b5),\n\t\t\tapply this, from ht\u2081 n,\n\t\tunfold open_interval,\n\t\tsimp only [set.set_of_subset_set_of],\n\t\trintros a \u27e8h\u03b1, h\u03b2\u27e9,\n\t\tsplit,\n\t\t\tapply lt_trans _ h\u03b1, swap,\n\t\t\tapply lt_trans h\u03b2,\n\t\t\tall_goals {\n\t\t\t\tsimp only [neg_lt_neg_iff, add_lt_add_iff_left, sub_eq_add_neg],\n\t\t\t\tapply lt_trans _ ((lt_\u03b5_ge_zero h\u03b5) hN),\n\t\t\t\thave h\u03b3 : 0 < (N : \u211d), norm_cast,\n\t\t\t\t\tcases lt_or_le 0 N, assumption,\n\t\t\t\t\texfalso, apply not_le.mpr h\u03b5,\n\t\t\t\t\tsuffices : 1 / \u03b5 \u2264 0, simp only [one_div_eq_inv, inv_nonpos] at this, assumption,\n\t\t\t\t\tapply le_of_lt, apply lt_of_lt_of_le hN, norm_cast, assumption,\n\t\t\t\thave : 0 < (n : \u211d) + 1,\n\t\t\t\t\tnorm_cast, norm_cast at h\u03b3,\n\t\t\t\t\tapply lt_trans h\u03b3,\n\t\t\t\t\tapply lt_of_le_of_lt hn, linarith,\n\t\t\t\trw (one_div_lt_one_div this h\u03b3), norm_cast, linarith\n\t\t\t}\n\t\t},\n\tunfold is_closed at hclosed,\n\thave hseqin : seq_in t S :=\n\t\tby {intro n, from ht\u2082 n},\n\thave hcontra : \u2203 (l : \u211d) (H : l \u2208 S), t \u21d2 l :=\n\t\tby {apply hclosed t hseqin,\n\t\tuse x, assumption},\n\trcases hcontra with \u27e8l, \u27e8hl\u2081, hl\u2082\u27e9\u27e9,\n\thave hleqx : l = x := unique_lim t l x hl\u2082 ht,\n\tapply hx, rwa \u2190hleqx\nend\n\ntheorem comp_open_iff_closed {S : set \u211d} : is_open S \u2194 is_closed (-S) :=\nbegin\n\tsplit,\n\t\tfrom comp_open_to_closed,\n\t\thave h\u2081 : (- -S) = S := by {simp},\n\t\thave h\u2082 : (- - -S) = -S :=by {simp},\n\t\trw [\u2190h\u2081, h\u2082],\n\t\tfrom comp_closed_to_open\nend\n\n-- A function f : \u211d \u2192 \u211d is continuous iff. \u2200 U \u2286 R, f\u207b\u00b9(U) is open\ntheorem contin_open_pre_image {f : \u211d \u2192 \u211d} : func_continuous f \u2194 \u2200 U : set \u211d, is_open U \u2192 is_open {x : \u211d | f x \u2208 U} :=\nbegin\n\tsplit,\n\t\t{intros h\u2081 U hU x hx,\n\t\thave hf : f x \u2208 U := by {rw set.mem_set_of_eq at hx, assumption},\n\t\trcases hU (f x) hf with \u27e8\u03b5, \u27e8h\u03b5, hrang\u27e9\u27e9,\n\t\trcases h\u2081 x \u03b5 h\u03b5 with \u27e8\u03b4, \u27e8h\u03b4, hcontin\u27e9\u27e9,\n\t\tuse \u03b4, use h\u03b4,\n\t\tintros y hy,\n\t\trw set.mem_set_of_eq,\n\t\trw abs_lt_open_interval at hy,\n\t\tsuffices : f y \u2208 open_interval (f x - \u03b5) (f x + \u03b5),\n\t\t\tfrom hrang this,\n\t\trw abs_lt_open_interval,\n\t\tfrom hcontin y hy\n\t\t},\n\t\t{intros hU y \u03b5 h\u03b5,\n\t\tlet U : set \u211d := open_interval (f y - \u03b5) (f y + \u03b5),\n\t\thave : f y \u2208 U := by {rw abs_lt_open_interval, simpa},\n\t\trcases hU U (open_interval_is_open (f y - \u03b5) (f y + \u03b5)) y this with \u27e8\u03b4, \u27e8h\u03b4, hrang\u27e9\u27e9,\n\t\tuse \u03b4, use h\u03b4,\n\t\tintros x hx,\n\t\trw \u2190abs_lt_open_interval at hx,\n\t\trw \u2190abs_lt_open_interval,\n\t\tsuffices : x \u2208 {x : \u211d | f x \u2208 U},\n\t\t\trw set.mem_set_of_eq at this,\n\t\t\tassumption,\n\t\tfrom hrang hx\n\t\t}\nend\n\n-- a n \u2192 l iff \u2200 U \u2286 \u211d, U an open set, l \u2208 U \u21d2 \u2203 N \u2208 \u2115, \u2200 n \u2265 N, a n \u2208 U (Unseen 2 Term 2)\nlemma seq_converge_imples_all_open {a : \u2115 \u2192 \u211d} {l : \u211d} : a \u21d2 l \u2192 \u2200 U : set \u211d, is_open U \u2227 l \u2208 U \u2192 \u2203 N : \u2115, \u2200 n : \u2115, N \u2264 n \u2192 (a n) \u2208 U :=\nbegin\n\trintros hconv U \u27e8hU, hlU\u27e9,\n\trcases hU l hlU with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\tcases hconv \u03b4 h\u03b4\u2081 with N hN,\n\tuse N, intros n hn,\n\tsuffices : a n \u2208 open_interval (l - \u03b4) (l + \u03b4),\n\t\tfrom h\u03b4\u2082 this,\n\trw abs_lt_open_interval,\n\tfrom hN n hn\nend\n\nlemma all_open_imples_seq_converge {a : \u2115 \u2192 \u211d} {l : \u211d} : (\u2200 U : set \u211d, is_open U \u2227 l \u2208 U \u2192 \u2203 N : \u2115, \u2200 n : \u2115, N \u2264 n \u2192 (a n) \u2208 U) \u2192 a \u21d2 l :=\nbegin\n\tintros hU \u03b5 h\u03b5,\n\tlet U : set \u211d := open_interval (l - \u03b5) (l + \u03b5),\n\thave hopen : is_open U :=\n\t\tby {apply open_interval_is_open},\n\thave hlU : l \u2208 open_interval (l - \u03b5) (l + \u03b5) :=\n\t\tby {unfold open_interval,\n\t\t\trw set.mem_set_of_eq,\n\t\t\tsplit, all_goals {linarith},\n\t\t},\n\tcases hU U \u27e8hopen, hlU\u27e9 with N hN,\n\tuse N, intros n hn,\n\trw \u2190abs_lt_open_interval,\n\tfrom hN n hn\nend\n\ntheorem seq_converge_iff_all_open {a : \u2115 \u2192 \u211d} {l : \u211d} : a \u21d2 l \u2194 \u2200 U : set \u211d, is_open U \u2227 l \u2208 U \u2192 \u2203 N : \u2115, \u2200 n : \u2115, N \u2264 n \u2192 (a n) \u2208 U :=\nby {split, all_goals {try {from seq_converge_imples_all_open <|> from all_open_imples_seq_converge}}}\n\n-- Uniform continuity and convergence\ndef unif_contin (f : \u211d \u2192 \u211d) := \u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x y : \u211d, abs (x - y) < \u03b4 \u2192 abs (f x - f y) < \u03b5\n\n-- Uniformly continuous implies continuous (hence is stronger)\ntheorem unif_contin_implies_contin {f : \u211d \u2192 \u211d} : unif_contin f \u2192 func_continuous f :=\nbegin\n\tintros h\u2081 a \u03b5 h\u03b5,\n\trcases h\u2081 \u03b5 h\u03b5 with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\tuse \u03b4, use h\u03b4\u2081, intro x,\n\tfrom h\u03b4\u2082 x a\nend\n\n-- Uniformly continuous functions will map a Cauchy sequence to another Cauchy sequence\ntheorem unif_contin_map_cauchy {f : \u211d \u2192 \u211d} {a : \u2115 \u2192 \u211d} (h : unif_contin f) : cauchy a \u2192 cauchy (\u03bb n : \u2115, f (a n)) :=\nbegin\n\tintros hcauchy \u03b5 h\u03b5,\n\trcases h \u03b5 h\u03b5 with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\tcases hcauchy \u03b4 h\u03b4\u2081 with N hN,\n\tuse N,\n\tintros n m hnm,\n\tshow abs (f (a n) - f (a m)) < \u03b5,\n\tconvert h\u03b4\u2082 (a n) (a m) _,\n\tfrom hN n m hnm\nend\n\ndef func_pointwise_converge_to (f : \u2115 \u2192 \u211d \u2192 \u211d) (g : \u211d \u2192 \u211d) := \u2200 x : \u211d, \u2200 \u03b5 > 0, \u2203 N : \u2115, \u2200 n : \u2115, N \u2264 n \u2192 abs (f n x - g x) < \u03b5\ndef func_converge_uniform (f : \u2115 \u2192 \u211d \u2192 \u211d) (g : \u211d \u2192 \u211d) := \u2200 \u03b5 > 0, \u2203 N : \u2115, \u2200 x : \u211d, \u2200 n : \u2115, N \u2264 n \u2192 abs (f n x - g x) < \u03b5\n\n-- function.swap swaps \n-- f: \u2115 \u2192 \u211d \u2192 \u211d = f\u2099(x)\n\n-- If a sequence of uniformly continuous functions f\u2099 converges to f, then f is uniformly continuous\ntheorem unif_contin_lim_unif_contin (f : \u2115 \u2192 \u211d \u2192 \u211d) (g : \u211d \u2192 \u211d) (h : \u2200 n : \u2115, unif_contin (f n)) : func_converge_uniform f g \u2192 unif_contin g :=\nbegin\n\tintros h\u2081 \u03b5 h\u03b5,\n\thave  h\u03b5\u2082: 0 < \u03b5 / 3 := by linarith,\n\tcases h\u2081 (\u03b5 / 3) h\u03b5\u2082 with N hN,\n\trcases h N (\u03b5 / 3) h\u03b5\u2082 with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\tuse \u03b4, use h\u03b4\u2081, \n\tintros x y hxy,\n\tsuffices : abs (g x -f N x) + abs (f N x - f N y) + abs (f N y - g y) < \u03b5,\n\t\t{apply lt_of_le_of_lt _ this,\n\t\t convert le_trans (abs_add (g x - f N y) (f N y - g y)) _, simp,\n\t\t apply add_le_add_right',\n\t\t convert abs_add (g x - f N x) (f N x - f N y),\n\t\t simp\n\t\t},\n\thave : \u03b5 = \u03b5 / 3 + \u03b5 / 3 + \u03b5 / 3 := by {linarith},\n\trw this,\n\trepeat {apply add_lt_add},\n\t\t{rw abs_sub,\n\t\tfrom hN x N (le_refl N)},\n\t\t{from h\u03b4\u2082 x y hxy},\n\t\t{from hN y N (le_refl N)}\nend\n\n-- A similar but weaker proposition than the above: If a sequence of continuous functions f\u2099 converges to f, then f is continuous\ntheorem contin_lim_contin (f : \u2115 \u2192 \u211d \u2192 \u211d) (g : \u211d \u2192 \u211d) (h : \u2200 n : \u2115, func_continuous (f n)) : func_converge_uniform f g \u2192 func_continuous g :=\nbegin\n\tintros h\u2081 y \u03b5 h\u03b5,\n\thave h\u03b5\u2082 : 0 < \u03b5 / 3 := by linarith,\n\tcases h\u2081 (\u03b5 / 3) h\u03b5\u2082 with N hN,\n\trcases h N y (\u03b5 / 3) h\u03b5\u2082 with \u27e8\u03b4, \u27e8h\u03b4\u2081, h\u03b4\u2082\u27e9\u27e9,\n\tuse \u03b4, use h\u03b4\u2081,\n\tintros x hxy,\n\tsuffices : abs (g x -f N x) + abs (f N x - f N y) + abs (f N y - g y) < \u03b5,\n\t\t{apply lt_of_le_of_lt _ this,\n\t\t convert le_trans (abs_add (g x - f N y) (f N y - g y)) _, simp,\n\t\t apply add_le_add_right',\n\t\t convert abs_add (g x - f N x) (f N x - f N y),\n\t\t simp\n\t\t},\n\thave : \u03b5 = \u03b5 / 3 + \u03b5 / 3 + \u03b5 / 3 := by {linarith},\n\trw this,\n\trepeat {apply add_lt_add},\n\t\t{rw abs_sub,\n\t\tfrom hN x N (le_refl N)},\n\t\t{from h\u03b4\u2082 x hxy},\n\t\t{from hN y N (le_refl N)}\nend\n\n-- TODO: define sum of functions and prove Weierstrass M-test\n\nend M40002", "meta": {"author": "JasonKYi", "repo": "M4000x_LEAN_formalisation", "sha": "6e99793f2fcbe88596e27644f430e46aa2a464df", "save_path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation", "path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation/M4000x_LEAN_formalisation-6e99793f2fcbe88596e27644f430e46aa2a464df/src/M40002/M40002_C5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7176019236386975}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si 0 < 0, entonces a > 37 para cualquier\n-- n\u00famero a. \n-- ----------------------------------------------------------------------\n\nvariable a : \u2115\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h : 0 < 0) \n  : a > 37 :=\nbegin\n  exfalso,\n  apply lt_irrefl 0 h,\nend\n\n-- Prueba\n-- ======\n\n/-\na : \u2115,\nh : 0 < 0\n\u22a2 a > 37\n  >> exfalso,\na : \u2115,\nh : 0 < 0\n\u22a2 false\n  >> apply lt_irrefl 0 h,\nno goals\n-/\n\n-- Comentario: La t\u00e1ctica exfalso sustituye el objetivo por false.\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h : 0 < 0) \n  : a > 37 :=\nabsurd h (lt_irrefl 0)\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h : 0 < 0) \n  : a > 37 :=\nbegin\n  have h' : \u00ac 0 < 0,\n    from lt_irrefl 0,\n  contradiction,\nend\n\n-- Prueba\n-- ======\n\n/-\na : \u2115,\nh : 0 < 0\n\u22a2 a > 37\n  >> have h' : \u00ac 0 < 0,\n  >>   from lt_irrefl 0,\nh' : \u00ac0 < 0\n\u22a2 a > 37\n  >> contradiction,\nno goals\n-/\n\n-- Comentario: La t\u00e1ctica contradiction busca dos hip\u00f3tesis\n-- contradictorias. \n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Principio_de_explosion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7176019189115578}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport algebra.polynomial.big_operators\nimport data.nat.choose.cast\nimport data.nat.choose.vandermonde\nimport data.polynomial.derivative\n\n/-!\n# Hasse derivative of polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt is a variant of the usual derivative, and satisfies `k! * (hasse_deriv k f) = derivative^[k] f`.\nThe main benefit is that is gives an atomic way of talking about expressions such as\n`(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example.\n\n## Main declarations\n\nIn the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`.\n\n* `polynomial.hasse_deriv`: the `k`-th Hasse derivative of a polynomial\n* `polynomial.hasse_deriv_zero`: the `0`th Hasse derivative is the identity\n* `polynomial.hasse_deriv_one`: the `1`st Hasse derivative is the usual derivative\n* `polynomial.factorial_smul_hasse_deriv`: the identity `k! \u2022 (D k f) = derivative^[k] f`\n* `polynomial.hasse_deriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k \u2022 D (k+l)`\n* `polynomial.hasse_deriv_mul`:\n  the \"Leibniz rule\" `D k (f * g) = \u2211 ij in antidiagonal k, D ij.1 f * D ij.2 g`\n\nFor the identity principle, see `polynomial.eq_zero_of_hasse_deriv_eq_zero`\nin `data/polynomial/taylor.lean`.\n\n## Reference\n\nhttps://math.fontein.de/2009/08/12/the-hasse-derivative/\n\n-/\n\nnoncomputable theory\n\nnamespace polynomial\n\nopen_locale nat big_operators polynomial\nopen function nat (hiding nsmul_eq_mul)\n\nvariables {R : Type*} [semiring R] (k : \u2115) (f : R[X])\n\n/-- The `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/\ndef hasse_deriv (k : \u2115) : R[X] \u2192\u2097[R] R[X] :=\nlsum (\u03bb i, (monomial (i-k)) \u2218\u2097 distrib_mul_action.to_linear_map R R (i.choose k))\n\nlemma hasse_deriv_apply :\n  hasse_deriv k f = f.sum (\u03bb i r, monomial (i - k) (\u2191(i.choose k) * r)) :=\nby simpa only [\u2190 nsmul_eq_mul]\n\nlemma hasse_deriv_coeff (n : \u2115) :\n  (hasse_deriv k f).coeff n = (n + k).choose k * f.coeff (n + k) :=\nbegin\n  rw [hasse_deriv_apply, coeff_sum, sum_def, finset.sum_eq_single (n + k), coeff_monomial],\n  { simp only [if_true, add_tsub_cancel_right, eq_self_iff_true], },\n  { intros i hi hink,\n    rw [coeff_monomial],\n    by_cases hik : i < k,\n    { simp only [nat.choose_eq_zero_of_lt hik, if_t_t, nat.cast_zero, zero_mul], },\n    { push_neg at hik, rw if_neg, contrapose! hink,\n      exact (tsub_eq_iff_eq_add_of_le hik).mp hink, } },\n  { intro h, simp only [not_mem_support_iff.mp h, monomial_zero_right, mul_zero, coeff_zero] }\nend\n\nlemma hasse_deriv_zero' : hasse_deriv 0 f = f :=\nby simp only [hasse_deriv_apply, tsub_zero, nat.choose_zero_right,\n  nat.cast_one, one_mul, sum_monomial_eq]\n\n@[simp] lemma hasse_deriv_zero : @hasse_deriv R _ 0 = linear_map.id :=\nlinear_map.ext $ hasse_deriv_zero'\n\nlemma hasse_deriv_eq_zero_of_lt_nat_degree (p : R[X]) (n : \u2115)\n  (h : p.nat_degree < n) : hasse_deriv n p = 0 :=\nbegin\n  rw [hasse_deriv_apply, sum_def],\n  refine finset.sum_eq_zero (\u03bb x hx, _),\n  simp [nat.choose_eq_zero_of_lt ((le_nat_degree_of_mem_supp _ hx).trans_lt h)]\nend\n\nlemma hasse_deriv_one' : hasse_deriv 1 f = derivative f :=\nby simp only [hasse_deriv_apply, derivative_apply, \u2190 C_mul_X_pow_eq_monomial, nat.choose_one_right,\n    (nat.cast_commute _ _).eq]\n\n@[simp] lemma hasse_deriv_one : @hasse_deriv R _ 1 = derivative :=\nlinear_map.ext $ hasse_deriv_one'\n\n@[simp] lemma hasse_deriv_monomial (n : \u2115) (r : R) :\n  hasse_deriv k (monomial n r) = monomial (n - k) (\u2191(n.choose k) * r) :=\nbegin\n  ext i,\n  simp only [hasse_deriv_coeff, coeff_monomial],\n  by_cases hnik : n = i + k,\n  { rw [if_pos hnik, if_pos, \u2190 hnik], apply tsub_eq_of_eq_add_rev, rwa add_comm },\n  { rw [if_neg hnik, mul_zero],\n    by_cases hkn : k \u2264 n,\n    { rw [\u2190 tsub_eq_iff_eq_add_of_le hkn] at hnik, rw [if_neg hnik] },\n    { push_neg at hkn, rw [nat.choose_eq_zero_of_lt hkn, nat.cast_zero, zero_mul, if_t_t] } }\nend\n\nlemma hasse_deriv_C (r : R) (hk : 0 < k) : hasse_deriv k (C r) = 0 :=\nby rw [\u2190 monomial_zero_left, hasse_deriv_monomial, nat.choose_eq_zero_of_lt hk,\n    nat.cast_zero, zero_mul, monomial_zero_right]\n\nlemma hasse_deriv_apply_one (hk : 0 < k) : hasse_deriv k (1 : R[X]) = 0 :=\nby rw [\u2190 C_1, hasse_deriv_C k _ hk]\n\nlemma hasse_deriv_X (hk : 1 < k) : hasse_deriv k (X : R[X]) = 0 :=\nby rw [\u2190 monomial_one_one_eq_X, hasse_deriv_monomial, nat.choose_eq_zero_of_lt hk,\n    nat.cast_zero, zero_mul, monomial_zero_right]\n\nlemma factorial_smul_hasse_deriv :\n  \u21d1(k! \u2022 @hasse_deriv R _ k) = ((@derivative R _)^[k]) :=\nbegin\n  induction k with k ih,\n  { rw [hasse_deriv_zero, factorial_zero, iterate_zero, one_smul, linear_map.id_coe], },\n  ext f n : 2,\n  rw [iterate_succ_apply', \u2190 ih],\n  simp only [linear_map.smul_apply, coeff_smul, linear_map.map_smul_of_tower, coeff_derivative,\n    hasse_deriv_coeff, \u2190 @choose_symm_add _ k],\n  simp only [nsmul_eq_mul, factorial_succ, mul_assoc, succ_eq_add_one, \u2190 add_assoc,\n    add_right_comm n 1 k, \u2190 cast_succ],\n  rw \u2190 (cast_commute (n+1) (f.coeff (n + k + 1))).eq,\n  simp only [\u2190 mul_assoc], norm_cast, congr' 2,\n  apply @cast_injective \u211a,\n  have h1 : n + 1 \u2264 n + k + 1 := succ_le_succ le_self_add,\n  have h2 : k + 1 \u2264 n + k + 1 := succ_le_succ le_add_self,\n  have H : \u2200 (n : \u2115), (n! : \u211a) \u2260 0, { exact_mod_cast factorial_ne_zero },\n  -- why can't `field_simp` help me here?\n  simp only [cast_mul, cast_choose \u211a, h1, h2, -one_div, -mul_eq_zero,\n    succ_sub_succ_eq_sub, add_tsub_cancel_right, add_tsub_cancel_left] with field_simps,\n  rw [eq_div_iff_mul_eq (mul_ne_zero (H _) (H _)), eq_comm, div_mul_eq_mul_div,\n    eq_div_iff_mul_eq (mul_ne_zero (H _) (H _))],\n  norm_cast,\n  simp only [factorial_succ, succ_eq_add_one], ring,\nend\n\nlemma hasse_deriv_comp (k l : \u2115) :\n  (@hasse_deriv R _ k).comp (hasse_deriv l) = (k+l).choose k \u2022 hasse_deriv (k+l) :=\nbegin\n  ext i : 2,\n  simp only [linear_map.smul_apply, comp_app, linear_map.coe_comp, smul_monomial,\n    hasse_deriv_apply, mul_one, monomial_eq_zero_iff, sum_monomial_index, mul_zero,\n    \u2190 tsub_add_eq_tsub_tsub, add_comm l k],\n  rw_mod_cast nsmul_eq_mul,\n  congr' 2,\n  by_cases hikl : i < k + l,\n  { rw [choose_eq_zero_of_lt hikl, mul_zero],\n    by_cases hil : i < l,\n    { rw [choose_eq_zero_of_lt hil, mul_zero] },\n    { push_neg at hil, rw [\u2190 tsub_lt_iff_right hil] at hikl,\n      rw [choose_eq_zero_of_lt hikl , zero_mul], }, },\n  push_neg at hikl, apply @cast_injective \u211a,\n  have h1 : l \u2264 i     := le_of_add_le_right hikl,\n  have h2 : k \u2264 i - l := le_tsub_of_add_le_right hikl,\n  have h3 : k \u2264 k + l := le_self_add,\n  have H : \u2200 (n : \u2115), (n! : \u211a) \u2260 0, { exact_mod_cast factorial_ne_zero },\n  -- why can't `field_simp` help me here?\n  simp only [cast_mul, cast_choose \u211a, h1, h2, h3, hikl, -one_div, -mul_eq_zero,\n    succ_sub_succ_eq_sub, add_tsub_cancel_right, add_tsub_cancel_left] with field_simps,\n  rw [eq_div_iff_mul_eq, eq_comm, div_mul_eq_mul_div, eq_div_iff_mul_eq, \u2190 tsub_add_eq_tsub_tsub,\n    add_comm l k],\n  { ring, },\n  all_goals { apply_rules [mul_ne_zero, H] }\nend\n\nlemma nat_degree_hasse_deriv_le (p : R[X]) (n : \u2115) :\n  nat_degree (hasse_deriv n p) \u2264 nat_degree p - n :=\nbegin\n  classical,\n  rw [hasse_deriv_apply, sum_def],\n  refine (nat_degree_sum_le _ _).trans _,\n  simp_rw [function.comp, nat_degree_monomial],\n  rw [finset.fold_ite, finset.fold_const],\n  { simp only [if_t_t, max_eq_right, zero_le', finset.fold_max_le, true_and, and_imp,\n               tsub_le_iff_right, mem_support_iff, ne.def, finset.mem_filter],\n    intros x hx hx',\n    have hxp : x \u2264 p.nat_degree := le_nat_degree_of_ne_zero hx,\n    have hxn : n \u2264 x,\n    { contrapose! hx',\n      simp [nat.choose_eq_zero_of_lt hx'] },\n    rwa [tsub_add_cancel_of_le (hxn.trans hxp)] },\n  { simp }\nend\n\nlemma nat_degree_hasse_deriv [no_zero_smul_divisors \u2115 R] (p : R[X]) (n : \u2115) :\n  nat_degree (hasse_deriv n p) = nat_degree p - n :=\nbegin\n  cases lt_or_le p.nat_degree n with hn hn,\n  { simpa [hasse_deriv_eq_zero_of_lt_nat_degree, hn] using (tsub_eq_zero_of_le hn.le).symm },\n  { refine map_nat_degree_eq_sub _ _,\n    { exact \u03bb h, hasse_deriv_eq_zero_of_lt_nat_degree _ _ },\n    { classical,\n      simp only [ite_eq_right_iff, ne.def, nat_degree_monomial, hasse_deriv_monomial],\n      intros k c c0 hh,\n      -- this is where we use the `smul_eq_zero` from `no_zero_smul_divisors`\n      rw [\u2190nsmul_eq_mul, smul_eq_zero, nat.choose_eq_zero_iff] at hh,\n      exact (tsub_eq_zero_of_le (or.resolve_right hh c0).le).symm } }\nend\n\nsection\nopen add_monoid_hom finset.nat\n\nlemma hasse_deriv_mul (f g : R[X]) :\n  hasse_deriv k (f * g) = \u2211 ij in antidiagonal k, hasse_deriv ij.1 f * hasse_deriv ij.2 g :=\nbegin\n  let D := \u03bb k, (@hasse_deriv R _ k).to_add_monoid_hom,\n  let \u03a6 := @add_monoid_hom.mul R[X] _,\n  show (comp_hom (D k)).comp \u03a6 f g =\n    \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, ((comp_hom.comp ((comp_hom \u03a6) (D ij.1))).flip (D ij.2) f) g,\n  simp only [\u2190 finset_sum_apply],\n  congr' 2, clear f g,\n  ext m r n s : 4,\n  simp only [finset_sum_apply, coe_mul_left, coe_comp, flip_apply, comp_app,\n    hasse_deriv_monomial, linear_map.to_add_monoid_hom_coe, comp_hom_apply_apply, coe_mul,\n    monomial_mul_monomial],\n  have aux : \u2200 (x : \u2115 \u00d7 \u2115), x \u2208 antidiagonal k \u2192\n    monomial (m - x.1 + (n - x.2)) (\u2191(m.choose x.1) * r * (\u2191(n.choose x.2) * s)) =\n    monomial (m + n - k) (\u2191(m.choose x.1) * \u2191(n.choose x.2) * (r * s)),\n  { intros x hx, rw [finset.nat.mem_antidiagonal] at hx, subst hx,\n    by_cases hm : m < x.1,\n    { simp only [nat.choose_eq_zero_of_lt hm, nat.cast_zero, zero_mul, monomial_zero_right], },\n    by_cases hn : n < x.2,\n    { simp only [nat.choose_eq_zero_of_lt hn, nat.cast_zero,\n        zero_mul, mul_zero, monomial_zero_right], },\n    push_neg at hm hn,\n    rw [tsub_add_eq_add_tsub hm, \u2190 add_tsub_assoc_of_le hn, \u2190 tsub_add_eq_tsub_tsub,\n      add_comm x.2 x.1, mul_assoc, \u2190 mul_assoc r, \u2190 (nat.cast_commute _ r).eq, mul_assoc,\n      mul_assoc], },\n  conv_rhs { apply_congr, skip, rw aux _ H, },\n  rw_mod_cast [\u2190 linear_map.map_sum, \u2190 finset.sum_mul, \u2190 nat.add_choose_eq],\nend\n\nend\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/hasse_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.717518003863852}}
{"text": "/-\nCopyright (c) 2021 Alex Zhao. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Zhao\n-/\nimport data.nat.modeq\nimport group_theory.submonoid.basic\nimport group_theory.submonoid.membership\nimport tactic.ring\nimport tactic.zify\n\n/-!\n# Frobenius Number in Two Variables\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we first define a predicate for Frobenius numbers, then solve the 2-variable variant\nof this problem.\n\n## Theorem Statement\n\nGiven a finite set of relatively prime integers all greater than 1, their Frobenius number is the\nlargest positive integer that cannot be expressed as a sum of nonnegative multiples of these\nintegers. Here we show the Frobenius number of two relatively prime integers `m` and `n` greater\nthan 1 is `m * n - m - n`. This result is also known as the Chicken McNugget Theorem.\n\n## Implementation Notes\n\nFirst we define Frobenius numbers in general using `is_greatest` and `add_submonoid.closure`. Then\nwe proceed to compute the Frobenius number of `m` and `n`.\n\nFor the upper bound, we begin with an auxiliary lemma showing `m * n` is not attainable, then show\n`m * n - m - n` is not attainable. Then for the construction, we create a `k_1` which is `k mod n`\nand `0 mod m`, then show it is at most `k`. Then `k_1` is a multiple of `m`, so `(k-k_1)`\nis a multiple of n, and we're done.\n\n## Tags\n\nfrobenius number, chicken mcnugget, chinese remainder theorem, add_submonoid.closure\n-/\n\nopen nat\n\n/-- A natural number `n` is the **Frobenius number** of a set of natural numbers `s` if it is an\nupper bound on the complement of the additive submonoid generated by `s`.\nIn other words, it is the largest number that can not be expressed as a sum of numbers in `s`. -/\ndef is_frobenius_number (n : \u2115) (s : set \u2115) : Prop :=\nis_greatest {k | k \u2209 add_submonoid.closure (s)} n\n\nvariables {m n : \u2115}\n\n/-- The **Chicken Mcnugget theorem** stating that the Frobenius number\n  of positive numbers `m` and `n` is `m * n - m - n`. -/\ntheorem is_frobenius_number_pair (cop : coprime m n) (hm : 1 < m) (hn : 1 < n) :\n  is_frobenius_number (m * n - m - n) {m, n} :=\nbegin\n  simp_rw [is_frobenius_number, add_submonoid.mem_closure_pair],\n  have hmn : m + n \u2264 m * n := add_le_mul hm hn,\n  split,\n  { push_neg,\n    intros a b h,\n    apply cop.mul_add_mul_ne_mul (add_one_ne_zero a) (add_one_ne_zero b),\n    simp only [nat.sub_sub, smul_eq_mul] at h, zify at h \u22a2,\n    rw [\u2190 sub_eq_zero] at h \u22a2, rw \u2190 h,\n    ring, },\n  { intros k hk, dsimp at hk, contrapose! hk,\n    let x := chinese_remainder cop 0 k,\n    have hx : x.val < m * n := chinese_remainder_lt_mul cop 0 k (ne_bot_of_gt hm) (ne_bot_of_gt hn),\n    suffices key : x.1 \u2264 k,\n    { obtain \u27e8a, ha\u27e9 := modeq_zero_iff_dvd.mp x.2.1,\n      obtain \u27e8b, hb\u27e9 := (modeq_iff_dvd' key).mp x.2.2,\n      exact \u27e8a, b, by rw [mul_comm, \u2190ha, mul_comm, \u2190hb, nat.add_sub_of_le key]\u27e9, },\n    refine modeq.le_of_lt_add x.2.2 (lt_of_le_of_lt _ (add_lt_add_right hk n)),\n    rw nat.sub_add_cancel (le_tsub_of_add_le_left hmn),\n    exact modeq.le_of_lt_add\n      (x.2.1.trans (modeq_zero_iff_dvd.mpr (nat.dvd_sub' (dvd_mul_right m n) dvd_rfl)).symm)\n      (lt_of_lt_of_le hx le_tsub_add), },\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/frobenius_number.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250325, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7174994798440817}}
{"text": "/-\nAn axiom is an assumed proof of a\ngiven proposition. For example, we\naccept as an *axiom* that there is\na proof that equality is reflexive.\nrefl : \u2200 {\u03b1 : Type} (a : \u03b1), a = a.\n\nNatural deduction is a system of\nreasoning rules for deducing proofs\nof more complex propositions from\naxioms. \n\nWhat we are doing in class now is\nto implement (or at least to see\nhow an implementation is given in\nthe Lean libraries) of the syntax \nof predicate logic and the rules\nof natural deduction.\n\nFor example, we implement the usual\nand connective of predicate logic as\na polymorphic proposition : one with\ntwo propositions as type arguments\n(remember, propositions are types in\nthe logic of Lean).\n\ninductive and (P Q : Prop) : Prop\n\nThe single intro constructor of this\npolymorphic proposition provides the\naxiom that explains how to deduce a\nproof of P \u2227 Q: apply \"intro\" to two\narguments, one a proof of P and one \na proof of Q.\n\nWhile the introduction axioms of natural\ndeduction explain how to construct (or\ndeduce) proofs of more complex propositions,\nelimination rules tell us how we can \"take \napart\" proofs to access the elements from\nwhich they were constructed. These elements\nare often proofs themselves.\n\nFor example, a proof of P \u2227 Q is \"built\"\nfrom a proof of P and a proof of Q, and\nthe \"and elimination rules\" give us ways\nto extract these \"smaller\" proofs from a\nlarger proof of P \u2227 Q. In this way, these\nelimination rules extend our ability to\ndeduce consequences: e.g., P \u2227 Q \u2192 P.\n\nEach form of proposition has its own\nintroduction and elimination rules. The\nsyntax of the predicate logic of everyday mathematics defines propositions formed\nusing the following connectives and\nquantifiers. It is your taks to learn\nthe introduction and elimination rules\nfor each one, and to be able to use them\nin constructing and using proofs, both\nformal and expressed in natural language.\n\n\u2200 \n\u2192 \n\u2227 \n\u2194\n= \n\u00ac \n\u2228 \n\u2203\n\nIn the rest of this document, we succinctly\nsummarize these rules. We give examples of \nhow to use such rule. We give each example \nin three forms: as a proof term, as a proof \nscript, and as a natural language proof.\n-/\n\n/-\nWe start by assuming (as axioms) that P\nand Q are arbitrary propositions. This\nallows us not to have to introduce them\nas assumptions in each of the examples.\n\nFor example, instead of writing\n\n\u2200 (P Q : Prop), P \u2227 Q \u2192 P, we can now\njust write P \u2227 Q \u2192 P, because P and Q\nare already assumed to be propositions\n(terms of type Prop in Lean).\n-/\n\naxioms P Q : Prop\n\n/-\nWith this presentation easing trick out\nof the way, we now proceed to discuss each\nconnective and quantifier and its rules of\ninference (introduction, elimination rules).\n-/\n\n/- *** FORALL *** -/\n\n/-\nHere's the form of a universal generalization.\nIt asserts that if one is given any proof of P,\nthen there is a proof of Q. \n-/\ndef univeral_generalization := \u2200 (p : P), Q\n\n/-\nTo prove a proposition of this form, we first\n*assume* that we're given an arbitarary but\nspecific proof of (value of type) P, and in\nthat context, our remaining goal is to build\na proof of Q. Here we don't know in detail\nwhat proposition Q is, so we can't complete\nthe proof; but nevertheless, as far as it\ngoes, the proof fully illustrates how one\nuses the \"forall introduction\" rule.\n-/\nexample : univeral_generalization :=\n\u03bb p,\n_\n\n/-\nAs a proof script.\n-/\nexample : univeral_generalization :=\nbegin\nunfold univeral_generalization, \n/-\nThe unfold tactic replaces an identifier\nwith the value to which it's bound. In this\ncase, it helps us to see more clearly what\nis to be proved. Surprisingly, what is to \nbe proved is an implication: P \u2192 Q. A key\ninsight is that P \u2192 Q is just a shorthand\nfor \u2200 (p : P), Q! What is to be shown is\nthat *if* one is given *any* proof of P,\nthen one can always construct a proof of\nQ. Now one proceeds to use the introduction\nrule for \u2192: assume that one is given a\nproof of P, and the remaining goal is to\nshow Q.\n-/\nassume (p : P),\n/-\nThe show tactic simply documents in a\nproof script what remains to be done:\nin this case, to produce a proof (we\ncan give it a name, here q) of Q.\n-/\nshow (q : Q),\n/-\nAnd once again, we can make no further\nprogress, so we just leave the proof\nunfinished. Note: no use can be made\nof an unfinished proof; if we finish\na proof with \"sorry\", we're telling \nLean to accept the proposition as true\nwithout proof, i.e., as an axiom. We\ndo not wish to do that here, so we just\nleave the proof unfinished.\n-/\n_,\nend\n\n/-\nAs a final comment, we emphasize that\nthe proceeding example shows how we \ncan approach the construction of a proof\nin a step by step way\n\n(1) Ask what is the syntactic form of\nproposition to be proved. Here the\nanswer is \"it's a \u2200 proposition, i.e.,\na universal generalization. \n(2) Ask what introduction \"rules\" can be\nused to construct such a proof. For \u2200 \nthere is only one: \u2200 introduction.\n(3) Apply the rule. In this case, what\nthat means is that we need to show that\nif we assume we're given any proof of \nP, we can always create a proof of Q.\nWe do this by defining a function with\none argument, an *assumed* proof of P. \nWhat remains to be proved is that, in\nthis context, a term of type Q, that\nis, a proof of Q, can be produced. \nIn developing proofs incrementally,\nwe often leave a \"hole\" for such a\nterm. This hole represents \"the rest\"\nof what needs to be given to have a\ncomplete proof: here what's left to\nprove is Q.\n-/\n\n/-\nFinally, here's a natural language proof.\n\n-/\n\n\n/- *** \u2200 elimination *** -/\n\n/-\nIf we know that *any* ball is blue, and\nwe know that b is a specific ball, then\nwe know that b is blue.\n-/\n\nMoreover, a proof of \u2200 (p : P), Q\nis effectively, and can be applied\nas a function to any proof of P to \nconstruct a proof of Q. \n-/\n\n\nexample : \n    \n    (\u2200 (p : P), Q) \u2192 P \u2192 Q\n    :=\n\u03bb (a : (\u2200 (p : P), Q)),\n    \u03bb (p : P),\n        _\n\n\nexample : (\u2200 (p : P), Q) \u2192 P \u2192 Q :=\nbegin\n    assume (f : \u2200 (p : P), Q),\n    assume p,\n    exact f p\nend\n\n/-\nIn English. If P and Q are arbitrary\npropositions, (\u2200 (p : P), Q) \u2192 P \u2192 Q. \nTo prove it, assume there are proofs \nof both (\u2200 (p : P), Q) and of P. Apply\nthe former to the latter to derive a\nproof of Q.\n\n-/\n\n/-  *** \u2192 introduction ***\n\nArrow introduction is identical to\n\u2200 introduction: assume the premise.\nThen what remains to be proved, in\nthat context, is the conclusion. \u2192 \nintroduction *is* \u2200 introduction:\nassume that values of specified\nargument/premise types are given. \n-/\n\nexample : P \u2192 Q :=\n    \u03bb (p : P),      -- assume P\n        _           -- show Q\n\n\nexample : P \u2192 Q :=\nbegin\nassume (p : P),     -- assume P\n_                   -- show Q\nend\n\n/-\nIn English, given propositions P and\nQ, show P \u2192 Q. To start we assume P.\nIn this context we produce a proof of\nQ. [There are not enough details about\neither P or Q to complete the proof, \nbut the step taken (assume P then \nshow Q) illustrates \u2192 introduction].\n-/\n\n/-\n   *** \u2192  elimination ***\n\nArrow elimination is application:\nGiven a proof of P \u2192 Q (which we\ncan treat as a function of this \ntype, that converts proofs of P\ninto proofs of Q), we can *use* \nthe proof of P \u2192 Q  by *applying*\nit to to any proof of P. The result\nis a proof of Q. \n\nIn the following exmples, we just\nreplace the \u2200 notation from the two\npreceding examples of \u2200 elimination\nwith \u2192 notation. Compare the examples\ncarefully.\n-/\n\n\nexample : \n    (P \u2192 Q) \u2192 \n    P \u2192 \n    Q :=\n\u03bb (f : \u2200 (p : P), Q), -- proof of \u2200 \n    \u03bb (p : P),        -- proof of P\n        _        -- \u2200 elimination\n\n\nexample : (P \u2192 Q) \u2192 P \u2192 Q :=\nbegin\n    assume (f : \u2200 (p : P), Q),\n    assume p,\n    exact (f p)\nend\n\n/-\nIn English. Assume P and Q are arbitrary\npropositions and whow (P \u2192 Q) \u2192 P \u2192 Q. \n\nProof: Assume P \u2192 Q and assume P. Deduce \nQ by applying P \u2192 Q to P to obtain Q. QED.\n-/\n\n\n\n/- *** \u2227 introduction ***\n\nThe \u2227 connective is defined as an inductive\nlogical type that is polymorphic, taking two \npropositions (call them P and Q) as arguments\nyielding the proposition, P \u2227 Q. It provides\none proof constructor, in Lean called intro\n(and.intro), of type P \u2192 Q \u2192 P \u2227 Q. Given a\nproof, p, of P, and a proof, q, of Q, it\nconstructs the term (and.intro p q), which\nis accepted as being of type P \u2227 Q, and so\nto be a proof of this proposition.\n-/\n\n\nexample : P \u2192 Q \u2192 P \u2227 Q :=\n\u03bb (p : P),\n    \u03bb (q : Q),\n        and.intro p q\n\n\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n    assume (p : P) (q : Q),\n    exact (and.intro p q),\nend\n\n/-\nIn Enslish. Assume P and Q are arbitrary\npropositions and show that P \u2192 Q \u2192 P \u2227 Q.\n\nProof: Assuming P and Q are true and apply\nand introduction to deduce P \u2227 Q.\n-/\n\n/- *** \u2227 elimination ***\n\nOne should note that the definition\nof the logical connective, and, is\nthe analog, for logical types, of the\nproduct type (Prod, in lean) of pairs\nof values of the given types (proofs\nof) P and Q.\n\nThe elimination rules for \u2227 are then\njust the analogs of the \"projection\"\nfunctions for a given pair, by which\nits component values can be extracted.\n-/\n\n\nexample : (P \u2227 Q) \u2192 P :=\n\u03bb (h : P \u2227 Q),  -- given proof of P\u2227Q\n    and.elim_left h -- return Q proof \n\n\nexample : (P \u2227 Q) \u2192 P :=\nbegin\n    assume h,\n    exact h.left\nend\n\n/-\nIn English. Assume P and Q are arbitrary\npropostions and show (P \u2227 Q) \u2192 P. \n\nProof: This is done by the applying the\nleft elimination rule of natural deduction \nto (P \u2227 Q). QED.\n-/\n\n/- *** = introduction ***\n\n= is a polymorphic binary relation, on \nobjects of any type. It is formalized in\nLean as the inductive type, eq, which\ntakes on type argument, implicitly.\n\nThe rule for constructing a proof of \nan equality proposition is that for\nany value, a, of any type, \u03b1, a = a.\nThis is the introduction rule for =.\nIt is a universal generalization. To\nobtain a proof of equality for any\nspecific values, one *applies* it to\none of those values. As long as the\ntwo values really are equal, such a\nproof is a proof that they are equal.\n-/\n\nexample : 1 + 3 = 5 - 1 := eq.refl 4\n\n/-\nIn English: We start by simplifying \neach side of the equality proposition.\nThe result is 4 = 4. This is true by\napplication of the reflexive property\nof equality to the specific value, 4.\n-/\n\n/- *** = elimination ***\n\nWe have not yet discussed = elimination.\n\nIf one has values a and b of a type, T,\nand proofs of (1) a = b, and of (2) \n\"L a\", where L is any predicate, of \ntype P \u2192 Prop, then one uses equality\nelimination to deduce \"L b\" from \"L a\". \n\nAs an example, if Bill likes coffee \n(LC Bill), and if Bill = Bob, then Bob \nlikes coffee (LC Bob).\n-/\n\n\naxiom L : P \u2192 Prop  -- assume predicate L\n\nexample : \u2200 (a b : P), a = b \u2192 (L a \u2192 L b) := \n\u03bb (a0 b0 : P),\n\u03bb (ab : a0 = b0),\n\u03bb (l : L a0),\n(eq.subst ab l)\n\n/-\n    \u03bb a b,  -- assume a and b are values of P\n    \u03bb heq,  -- assume a proof of a = b\n    \u03bb la,   -- assume a proof of (L a)\n    (eq.subst heq la) -- deduce proof of (L b)\n-/\n\n/-\nThe comments give a concise English language\nproof. Citing the substitution rule for equality\non the last line would make the proof clearer.\n-/\n\nexample : \u2200 (a b : P), a = b \u2192 (L a \u2192 L b) := \nbegin\n    assume a b,\n    assume heq,\n    assume la,\n    rewrite <- heq,  -- change b to a in goal\n    exact la,\nend\n\n/-\nThe eq.subst rule allows one to substitute\nequals for equals in propositions without\nchanging their meaning. So, again, if Bill\nlikes coffee (LC Bill), and if Bill = Bob,\nthen it must be Bob likes coffee (LC Bob).\n-/\n\n/- *** Putting it all together ***\n\nProofs are constructed by composing these\nintroduction and elimination rules. Often\none needs both kinds of rules to complete \na proof. As an example, consider proving\nP \u2227 Q \u2192 Q \u2227 P. To do so, we assume that\nP \u2227 Q is true. From that assumption we\ndeduce that P is true and Q is true. We\nthen apply the rule of and introduction\nto the derived proofs of Q and P, in that\norder, to complete the overall proof. \nWe thus show that *if* P \u2227 Q is true, \nfor any propositions P, Q, then Q \u2227 P \nis true. The proof uses the introduction\nrule for \u2192, the left and right elimination\nrules for \u2227, and the introduction rule for \n\u2227 to put it all together. Here are formal\nversions, first as a proof term and then\nusing a tactic script to build that proof\nterm. \n-/\n\n\nexample : P \u2227 Q \u2192 Q \u2227 P :=\n\u03bb (pq : P \u2227 Q),     -- assume proof P \u2227 Q\n    and.intro       -- apply and.intro to \n        pq.right    -- proof of Q\n        pq.left     -- proof of P\n\n\nexample : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n    assume pq,\n    apply and.intro,    -- introduction\n    exact pq.right,     -- elimination\n    exact pq.left,      -- elimination\nend\n\n/-\nIn English: Let P and Q be arbitrary\npropositions [\u2200 intro]. Show that \nP \u2227 Q \u2192 Q \u2227 P. To do so, assume P \u2227 Q\n[\u2192 intro]. From this assumption, \ndeduce P and Q,respectively [\u2227 elim].\nFinally, deduce Q \u2227 P [\u2227 intro].\n-/\n\n/-\nHere's a slightly more complex example,\nin which a proof of (Q \u2192 R) is *applied*\nto an argument (a proof of Q) to obtain\na proof of R. Proof construction is pure\nfunctional programming!\n-/\n\nexample : (P \u2227 Q) \u2227 (Q \u2192 R) \u2192 R :=\n    \u03bb h,                -- assume premise\n        h.right         -- apply func : Q \u2192 R\n        h.left.right    -- to proof of Q\n                        -- to get proof of R\n\n-- As a tactic script\nexample : (P \u2227 Q) \u2227 (Q \u2192 R) \u2192 R :=\nbegin\nassume h : (P \u2227 Q) \u2227 (Q \u2192 R),\nexact (h.right) (h.left.right),\nend\n\n-- Same, named intermediate results\nexample : (P \u2227 Q) \u2227 (Q \u2192 R) \u2192 R :=\nbegin\nassume h : (P \u2227 Q) \u2227 (Q \u2192 R),\nhave qr : Q \u2192 R := h.right,\nhave q : Q := h.left.right,\nexact (qr q),\nend\n\n-- Same, with type inference\nexample : (P \u2227 Q) \u2227 (Q \u2192 R) \u2192 R :=\nbegin\nassume h,\nhave qr := h.right,\nhave q := h.left.right,\nexact (qr q),\nend\n\n/-\nIn English: Suppose P and Q are\npropositions. Show that (P \u2227 Q) \u2227 \n(Q \u2192 R) \u2192 R. To start, suppose \n(P \u2227 Q) \u2227 (Q \u2192 R) [\u2192 intro]. Deduce \nQ from the left conjunct and Q \u2192 R \nfrom the right [and elim]. Apply \nthe latter to the former [\u2192 elim] \nto deduce R. QED.\n-/\n\n/-\nA good practice for the exam would be\nto prove, in Lean, each of the inference\nrules that we validated in propositional\nlogic. You are prepared to this for the\nrules that do NOT involve exists or not.\nFor \u2194, use iff.intro and iff.elim_left\nand iff.elim_right as if they were the\nrules for and intro and elimination but\nwith proofs of implications as arguments.\n-/\n\n#check @iff.intro\n#check @iff.elim_left\n#check @iff.elim_right\n\n\n\n/-\nWhat does it mean, \u00ac P?\n-/\n\n/-\nMeet \"false\".\n-/\n\ndef f : false := _\n\ndef weird (f : false) : 0 = 1 :=\n    false.elim f\n\nexample : false \u2192 0 = 1 := \n\u03bb f, false.elim f\n\nexample : \u00ac P := \n\u03bb (p : P), _\n\nexample : P \u2192 \u00ac P \u2192 false :=\n\u03bb (p : P), \n\u03bb (np : \u00ac P),\n_\n\ntheorem proof_by_negation : \u00acP :=\n\u03bb (p : P), _\n\n/-\n\n\u00ac P ==== P \u2192 \n\n-/", "meta": {"author": "kevinsullivan", "repo": "uva-cs-dm-s20-old", "sha": "797672cb0ffae6a42a3518c9225d5807191fd113", "save_path": "github-repos/lean/kevinsullivan-uva-cs-dm-s20-old", "path": "github-repos/lean/kevinsullivan-uva-cs-dm-s20-old/uva-cs-dm-s20-old-797672cb0ffae6a42a3518c9225d5807191fd113/answers/natural deduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.717483740133615}}
{"text": "import tactic\nimport analysis.special_functions.trigonometric\nimport measure_theory.interval_integral\nimport topology.basic\nimport data.finset\nimport .integrals\n\nnoncomputable theory\nopen_locale classical\nopen_locale big_operators\nopen interval_integral\nopen filter\nopen real\n\nopen_locale topological_space\n\n/-!\n#### The proof of Euler summation : \u2211 1/n^2 = \u03c0^2/6\n\n## Strategy\n\n1. Define sequences\n\n  A\u2099 = \u222b x in 0..\u03c0/2 (cos x)^(2*n) and\n  B\u2099 = \u222b x in 0..\u03c0/2 x^2 * (cos x)^(2*n).\n\n2. Use integration by parts to prove recurrence formulas\n\n  A\u2099\u208a\u2081 = (2 * n + 1) * (n+1) * B\u2099 - 2*(n+1)^2 * B\u2099\u208a\u2081\n    and\n  A\u2099\u208a\u2081 = (2*n + 1) * (A\u2099 - A\u2099\u208a\u2081)\n\n3. Express 1/((n+1)^2) in terms of two consecutive ratios:\n\n  1 / ((n +1)^2 = 2 * (B\u2099) / (A\u2099) - 2 * B\u2099\u208a\u2081 / A\u2099\u208a\u2081\n\n4. The partial sums telescope and yield\n\n  \u2211 k=0..(n-1) 1 / ((k+1)^2 =  2 * B\u2080 / A\u2080 - 2 * B\u2099/A\u2099 = \u03c0^2 / 6 - 2 * B\u2099/A\u2099\n\n5.  Bound the error term using the fact that\n\n  2/\u03c0 * x \u2264 sin x.\n\n## References\n\nDaniel Daners,\nA short elementary proof of ...\nMathematics Magazine 85 (2012), 361-364. (MR 3007217, Zbl 1274.97037)\n\n* <http://talus.maths.usyd.edu.au/u/daners/publ/abstracts/zeta2/>\n\n## Tags\n\neuler summation, number theory, reciprocals\n\n-/\n\ndef A : \u2115 \u2192 \u211d := \u03bb n, \u222b x in 0..real.pi/2, (cos x)^(2*n)\ndef B : \u2115 \u2192 \u211d := \u03bb n, \u222b x in 0..real.pi/2, x^2 * (cos x)^(2*n)\n\n/-\nEvaluate A 0 and B 0, which will be useful later\n-/\nlemma eval_A0 : A 0 = real.pi / (2 : \u211d) :=\nbegin\n  unfold A,\n  simp only [mul_zero, pow_zero],\n  suffices : \u222b (x : \u211d) in 0..real.pi / 2, (1:\u211d) = (real.pi / 2 - 0) \u2022 1,\n  {\n    rw this,\n    simp only [mul_one, algebra.id.smul_eq_mul, sub_zero],\n  },\n  apply interval_integral.integral_const,\nend\n\nlemma has_deriv_at_congr {f : \u211d \u2192 \u211d} {f' g' : \u211d} (x : \u211d) (h: f' = g') :\nhas_deriv_at f f' x \u2192 has_deriv_at f g' x :=\n(iff_of_eq (congr_fun (congr_arg (has_deriv_at f) h) x)).1\n\nlemma eval_B0 : B 0 = real.pi^3 / (24 : \u211d) :=\nbegin\n  unfold B,\n  simp only [mul_one, mul_zero, pow_zero],\n  have h : \u2200 x \u2208 set.interval 0 (real.pi/2), has_deriv_at (\u03bb (x:\u211d), x^3/3) (x^2) x,\n  {\n    intros x hx,\n    have hh : (3\u207b\u00b9 * (3 * x ^ 2)) = x^2 := by discrete_field,\n    suffices : has_deriv_at (\u03bb (x : \u211d), x ^ 3 / 3) (3\u207b\u00b9 * (3 * x ^ 2)) x, by exact has_deriv_at_congr x hh this,\n    simp [div_eq_mul_inv, mul_comm],\n    apply has_deriv_at.const_mul,\n    apply_mod_cast (has_deriv_at_pow 3 x),\n  },\n  rw integral_eq_sub_of_has_deriv_at h,\n  { simp only [div_pow],\n    ring },\n  { show_continuous },\nend\n\n/-\nShow that B n is positive for all n. A similar proof works to show that A n is positive,\nbut we decided to prove the latter one by induction, which we will do once we have\nan explicit recursive formula for A n.\n\nFor B n, the proof just uses that the integrand is the square of a nonzero function.\n-/\nlemma B_pos {n : \u2115} : 0 < B n :=\nbegin\n  unfold B,\n  have pi_pos := pi_pos,\n  simp only [mul_comm, pow_mul, \u2190mul_pow],\n  apply int_pos_of_square (real.pi/3) pi_div_two_pos,\n  { show_continuous },\n  { -- Show here that the integrand is nonzero at \u03c0/3\n    repeat {split},\n    repeat {linarith},\n    rw cos_pi_div_three,\n    field_simp [pi_ne_zero],\n  }\nend\n\nlemma first_lemma' (n : \u2115) : A (n + 1)= (2*(n:\u211d)+1) * \u222b x in 0..real.pi/2, ((sin x)^2 * (cos x)^(2*n)) :=\nbegin\n  calc\n  A (n + 1) = \u222b x in 0..real.pi/2, (cos x)^(2*(n+1)) : by {unfold A}\n  ... =  \u222b x in 0..real.pi/2, (cos x)^(2*n+1) * (deriv sin x) :\n  begin\n    congr, ext1,\n    rw real.deriv_sin,\n    ring_nf,\n  end\n  ... = \u222b x in 0..real.pi/2, (2*n+1) * (sin x)^2 * (cos x)^(2*n) :\n  begin\n    rw int_by_parts,\n    {\n    suffices : \u222b x in 0..real.pi / 2,\n    sin x * ((2*n + 1) * (cos x ^ (2 * n) * sin x)) =\n    \u222b x in 0..real.pi / 2, (2*n + 1) * sin x^2 * cos x^(2 * n), by simpa,\n      congr, ext1,\n      ring,\n    },\n    { apply differentiable.pow,\n      apply differentiable.cos,\n      exact differentiable_id },\n    { exact differentiable_sin },\n    { exact continuous_deriv_cospow (2*n) },\n    { rw real.deriv_sin,\n      exact continuous_cos },\n  end\n  ... = \u222b x in 0..real.pi/2, (2*(n:\u211d)+1) * ((sin x)^2 * (cos x)^(2*n)) : by {congr, ext1, ring}\n  ... = (2*(n:\u211d)+1) * \u222b x in 0..real.pi/2, ((sin x)^2 * (cos x)^(2*n)) : by {simp [my_integral_smul]}\nend\n\nlemma first_lemma (n : \u2115) : A (n + 1)  = (2*n + 1) * (A (n) - A (n+1)) :=\nbegin\n  calc\n  A (n + 1) = (2*(n:\u211d)+1) * \u222b x in 0..real.pi/2, ((sin x)^2 * (cos x)^(2*n)) : first_lemma' n\n  ... = (2*(n:\u211d)+1) * \u222b x in 0..real.pi/2, (1- (cos x)^2) * (cos x)^(2*n) :\n  begin\n    congr, ext1,\n    suffices : sin x^2 = 1 - cos x^2, rw this,\n    simp only [eq_sub_iff_add_eq, sin_sq_add_cos_sq],\n  end\n  ... = (2*(n:\u211d)+1) * (A (n) - A (n+1)) :-- by {rw f5}\n  begin\n    unfold A,\n    rw \u2190integral_sub,\n    { congr, discrete_field },\n    all_goals {\n      apply integrable_of_cont,\n      apply continuous.pow continuous_cos,\n    },\n  end\nend\n\nlemma first_lemma_cor (n : \u2115) : A (n+1) = (2 * n + 1) / (2 * n + 2) * A n :=\nbegin\n  have h := first_lemma n,\n  have h1 : 2 * (n : \u211d) + 1 \u2260 0 := by show_nonzero,\n  have h2 : 2 * (n : \u211d) + 2 \u2260 0 := by show_nonzero,\n  have h3 : 2 * (n : \u211d) + 2 = (2 * n + 1) + 1 := by ring,\n  field_simp [h1, h2],\n  rw [h3, mul_add, mul_one],\n  nth_rewrite_lhs 1 h,\n  ring,\nend\n\n/-\nThe recurrence formula for A n directly gives positivity by induction.\n-/\nlemma A_pos {n : \u2115} : 0 < A n :=\nbegin\n  induction n with d hd,\n  { rw eval_A0,\n    exact pi_div_two_pos },\n  { rw_mod_cast first_lemma_cor d,\n    show_pos },\nend\n/-\n-/\nlemma display4 (n : \u2115) :\n  A (n+1) = (2 * n + 1) * (n+1) * B n - 2*(n+1)^2 * B (n+1) :=\nbegin\n  calc\n  A (n + 1) = \u222b x in 0..real.pi/2, (cos x)^(2*(n+1)) : by {unfold A}\n  ... = \u222b x in 0..real.pi/2, (cos x)^(2*n+2) * ((deriv id) x) : by {discrete_field}\n-- Integrate by parts\n  ... = -\u222b x in 0..real.pi/2, x * (2*n+2) * (cos x)^(2*n+1) * (deriv cos) x :\n  begin\n    rw int_by_parts_zero_ends,\n    { congr,\n      discrete_field },\n    all_goals\n    {\n      discrete_field,\n      try {show_continuous}\n    },\n  end\n  ... = ((n:\u211d)+1) * \u222b x in 0..real.pi/2, (2*x) * sin x * (cos x)^(2*n+1) :\n  begin\n    rw [\u2190my_integral_smul, \u2190integral_neg],\n    congr,\n    discrete_field,\n  end\n  ... = (n+1) * \u222b x in 0..real.pi/2, sin x * (cos x)^(2*n+1) * deriv (\u03bb x, x^2) x :\n  begin\n    congr, ext,\n    simp only [mul_one, differentiable_at_id', deriv_pow'',\n      nat.cast_bit0, deriv_id'', pow_one, nat.cast_one],\n    linarith,\n  end\n-- Integrate by parts a second time\n  ... = (n+1) * -\u222b x in 0..real.pi/2, x^2 * (deriv (\u03bb x, sin x * (cos x)^(2*n+1))) x :\n  begin\n    rw int_by_parts_zero_ends,\n    { show_differentiable },\n    { exact differentiable_pow },\n    {\n      rw deriv_sin_cos,\n      apply continuous.sub;\n      exact continuous_cospow',\n    },\n    all_goals {\n      simp only [algebra.id.smul_eq_mul, pow_one,\n      nat.cast_one, power_rule'', continuous_mul_left,\n      sin_zero, zero_mul,\n      cos_pi_div_two, zero_mul, add_eq_zero_iff, ne.def, not_false_iff,\n      one_ne_zero, mul_zero, and_false, zero_pow'],\n    },\n  end\n  ... = (n+1) * -\u222b x in 0..real.pi/2,\n    x^2 * ((cos x)^(2*n+2) - (2*n+1) * (1 - cos x^2) * (cos x)^(2*n)) :\n  begin\n    congr, ext, congr,\n    discrete_field,\n  end\n  ... = (n+1) * ((2 *n + 1) * B n - 2*(n+1) * B (n+1)) :\n  begin\n    congr,\n    unfold B,\n    rw \u2190integral_neg,\n    repeat {rw_mod_cast \u2190my_integral_smul,},\n    rw \u2190integral_sub,\n    {\n      congr, ext,\n      simp only [nat.cast_bit0, nat.cast_add, nat.cast_one, nat.cast_mul],\n      ring_exp,\n    },\n    all_goals {\n      apply integrable_of_cont,\n      show_continuous,\n    },\n  end\n  ... = (2 * n + 1) * (n+1) * B n - 2*(n+1)^2 * B (n+1) : by {ring}\nend\n\nlemma summand_expression (n : \u2115) :\n  1 / ((n : \u211d) + 1)^2 = 2 * (B n) / (A n) - 2 * B (n+1) / A (n+1) :=\nbegin\n  have A_nonzero : \u2200 (m:\u2115), A m \u2260 0,\n  {\n    intro m,\n    apply norm_num.ne_zero_of_pos,\n    exact A_pos,\n  },\n  have nplusone_nonzero : (n:\u211d)+1 \u2260 0 := nat.cast_add_one_ne_zero n,\n  have twonplusone_nonzero : 2*(n:\u211d)+1 \u2260 0,\n    show_nonzero,\n  have h_first_lemma := first_lemma n,\n  calc\n  1 / ((n : \u211d) + 1)^2 = (A (n+1)) / (A (n+1) * ((n : \u211d) + 1)^2) :\n  begin\n    rw div_mul_right,\n    exact A_nonzero (n+1),\n  end\n  ... = ((2 * n + 1) * (n+1) * (B n) - 2*(n+1)^2 * (B (n+1))) / (A (n+1) * ((n : \u211d) + 1)^2) : \n    by {nth_rewrite 0 display4,}\n  ... = ((2 * n + 1) * (n+1) * (B n)) / (A (n+1) * ((n : \u211d) + 1)^2) -\n    (2*(n+1)^2 * (B (n+1))) / (A (n+1) * ((n : \u211d) + 1)^2) :\n    by {rw sub_div}\n  ... = ((2 * n + 1) * (B n)) / (A (n+1) * ((n : \u211d) + 1)) -\n    2 * (B (n+1)) / (A (n+1)) : by {field_simp *, ring}\n  ... = 2 * (B n) / (A n) - 2 * B (n+1) / A (n+1) :\n  begin\n    have : (A (n+1) * ((n:\u211d) + 1)) = (2*n + 1) / 2 * (A n) := by discrete_field,\n    rw this,\n    discrete_field,\n  end\nend\n\nlemma telescoping (n : \u2115) : \u2211 k in (finset.range n), (1 : \u211d) / ((k+1)^2) = 2 * B 0 / A 0 - 2 * B n / A n :=\nbegin\n  simp only [summand_expression],\n  exact finset.sum_range_sub' (\u03bb k, 2 * (B k) / (A k)) n,\nend\n\n/-\nThe sin function is concave on the interval [0..pi/2].\n-/\nlemma sin_is_concave : concave_on (set.Icc 0 (real.pi/2)) sin :=\nbegin\n  have h0 : -sin = \u03bb y, -sin y := by refl,\n  rw \u2190neg_convex_on_iff,\n  apply convex_on_of_deriv2_nonneg (convex_Icc 0 (real.pi / 2)),\n  { show_continuous },\n  { show_differentiable },\n  {\n    simp only [h0],\n    show_differentiable,\n  },\n  {\n    intros x hx,\n    replace hx : 0 \u2264 x \u2227 x \u2264 real.pi / 2 := set.mem_Icc.mp (interior_subset hx),\n    suffices : 0 \u2264 deriv (deriv (-sin)) x, by simpa,\n    simp only [h0],\n    suffices : 0 \u2264 sin x, by simpa,\n    apply sin_nonneg_of_nonneg_of_le_pi;\n    linarith,\n  }\nend\n\n/-\nUse concavity of sin on [0..pi/2] to bound it below.\n-/\nlemma bound_sin {x : \u211d} (hx1 : 0 \u2264 x) (hx2 : x \u2264 real.pi / 2) : 2 / real.pi * x \u2264 sin x :=\nbegin\n  have h := sin_is_concave.2,\n  dsimp at h,\n  have pi_pos := pi_pos,\n  have pi_nonzero := pi_ne_zero,\n  have two_over_pi_pos : (0 :\u211d) < (2:\u211d) / real.pi := div_pos zero_lt_two pi_pos,\n  have hzero : (0:\u211d) \u2208 set.Icc 0 (real.pi / 2),\n  {\n    rw set.mem_Icc,\n    split; linarith,\n  },\n  have hpi2 : real.pi / 2 \u2208 set.Icc 0 (real.pi / 2),\n  {\n    rw set.mem_Icc,\n    split; linarith,\n  },\n  replace h := h hzero hpi2,\n  simp only [sin_zero, mul_one, zero_add, mul_zero, sin_pi_div_two] at h,\n  have ha : 0 \u2264 (1:\u211d) - 2 / real.pi * x,\n  {\n    simp only [sub_nonneg],\n    refine (le_div_iff' two_over_pi_pos).mp _,\n    simp only [one_div_div],\n    exact hx2,\n  },\n  have hb : 0 \u2264 2 / real.pi * x := (zero_le_mul_left two_over_pi_pos).mpr hx1,\n  replace h := h ha hb,\n  simp only [forall_prop_of_true, sub_add_cancel] at h,\n  suffices : 2 / real.pi * x * (real.pi / 2) = x,\n  {\n    rw this at h,\n    exact h,\n  },\n  discrete_field,\nend\n\nlemma key_inequality {n : \u2115} {x : \u211d} (hx1 : 0 \u2264 x) (hx2 : x \u2264 real.pi /2) :\n  x ^ 2 * cos x ^ (2 * n) \u2264 (real.pi ^ 2 / 4) \u2022 (sin x ^ 2 * cos x ^ (2 * n)) :=\nbegin\n  have key := bound_sin hx1 hx2,\n  have cospos : (cos x)^(2*n) \u2265 0,\n  {\n    rw [mul_comm, pow_mul],\n    apply pow_two_nonneg,\n  },\n  have h : x^2 \u2264 real.pi^2 / 4 * (sin x)^2,\n  {\n    rw [div_mul_eq_mul_div, div_le_iff pi_pos] at key,\n    nlinarith,\n  },\n  dsimp,\n  nlinarith,\nend\n\nlemma BA_aux {n : \u2115} :\n  \u222b (x : \u211d) in 0..real.pi / 2, x ^ 2 * cos x ^ (2 * n) <\n  \u222b (x : \u211d) in\n    0..real.pi / 2,\n    (real.pi ^ 2 / 4) * (sin x ^ 2 * cos x ^ (2 * n)) :=\nbegin\n  have hsq2' : sqrt 2^2 = 2 := sq_sqrt zero_le_two,\n  have hsq2 : sqrt 2 ^(2*n) = 2^n := by simp only [pow_mul, hsq2'],\n  have pisqpos : 0 < real.pi^2 := pow_pos pi_pos 2,\n  apply integral_strictly_monotone_of_cont,\n  { show_continuous },\n  { show_continuous },\n  { exact pi_div_two_pos },\n  { apply key_inequality },\n  {\n    use real.pi/4,\n    repeat {split},\n    all_goals { try { linarith [pi_pos]}},\n    {\n      simp only [cos_pi_div_four, sin_pi_div_four, hsq2, hsq2',\n        algebra.id.smul_eq_mul, div_pow],\n      rw [\u2190mul_assoc, mul_lt_mul_right],\n      all_goals {discrete_field},\n    },\n  }\nend\n\nlemma B_in_terms_of_A (n : \u2115) : B n < real.pi^2 / (8 * (n + 1)) * A n :=\nbegin      \n  have hh := first_lemma_cor n,\n  calc\n  B n = \u222b x in 0..(real.pi/2), x^2 * (cos x)^(2*n) : by {refl}\n  ... < \u222b x in 0..(real.pi/2), (real.pi^2/ 4) \u2022 ((sin x)^2 * (cos x)^(2*n)) : by {exact BA_aux}\n  ... = (real.pi^2/4) * (A (n+1) / (2*n + 1)) : by {rw [interval_integral.integral_smul,first_lemma'], discrete_field }\n  ... = (real.pi^2) / (8 * (n+1)) * (A n) : by {discrete_field}\nend\n\nlemma B_in_terms_of_A' (n : \u2115) : 2 * B n / A n < real.pi ^ 2 / (4 *(n + 1)) :=\nbegin\n  have h2 : 0 < (2:\u211d) := zero_lt_two,\n  calc\n  2 * B n / A n = 2 * (B n / A n) : by {exact mul_div_assoc,}\n  ... < 2 * (real.pi ^ 2 / (8 * (n + 1))) :\n    by {simp only [mul_lt_mul_left h2, div_lt_iff A_pos, B_in_terms_of_A n]}\n  ... = real.pi ^ 2 / (4 *(n + 1)) :  by {discrete_field}\nend\n\n/-\nBound the partial sums by a harmonic sequence.\n-/\nlemma error_estimate {n : \u2115}:\n  (-real.pi^2/4/(n+1) + real.pi^2/6) \u2264 (\u2211 k in finset.range n, ((1:\u211d)/ (k+1)^2))\n    \u2227\n  (\u2211 k in finset.range n, ((1:\u211d)/ (k+1)^2)) \u2264 real.pi^2/4/(n+1) + real.pi^2/6 :=\nbegin\n  rw [telescoping n, eval_A0, eval_B0],\n  have quo_pos : 0 < 2 * B n / A n,\n  {\n    rw mul_div_assoc,\n    exact mul_pos zero_lt_two (div_pos B_pos A_pos),\n  },\n  have h := B_in_terms_of_A' n,\n  have pi_ne_zero := pi_ne_zero,\n  have : 2 * (real.pi ^ 3 / 24) / (real.pi / 2) = real.pi^2 / 6 := by {discrete_field},\n  rw this,\n  field_simp *,\n  split,\n  all_goals {apply le_of_lt},\n  {\n    calc (-(real.pi ^ 2 * 6) / (4 * (\u2191n + 1)) + real.pi ^ 2) / 6\n      = -(real.pi^2 / (4*((n:\u211d) + 1))) + real.pi^2 / 6 : by {discrete_field}\n    ... < -(2 * B n / A n) + real.pi^2 / 6 : by {linarith [h]}\n    ... = (real.pi ^ 2 - 6 * (2 * B n) / A n) / 6 : by {ring_exp}\n  },\n  {\n    calc (real.pi ^ 2 - 6 * (2 * B n) / A n) / 6\n      =  real.pi ^ 2/ 6- (2 * B n / A n): by {discrete_field}\n    ... <  real.pi ^ 2 / (4 * (\u2191n + 1)) + real.pi ^ 2 / 6 : by {nlinarith}\n    ... = (real.pi ^ 2 * 6 / (4 * (\u2191n + 1)) + real.pi ^ 2) / 6 : by {discrete_field}\n  }\nend\n\nlemma tendsto_const_div_add_at_top_nhds_0_nat {C : \u211d} :\n  tendsto (\u03bb n : \u2115, (C / ((n : \u211d) + 1))) at_top (\ud835\udcdd 0) :=\nsuffices tendsto (\u03bb n : \u2115, C / (\u2191(n + 1) : \u211d)) at_top (\ud835\udcdd 0), by simpa,\n(tendsto_add_at_top_iff_nat 1).2 (tendsto_const_div_at_top_nhds_0_nat C)\n\nlemma limit_below : tendsto (\u03bb (n:\u2115),-real.pi^2/4/(n+1) + real.pi^2/6) at_top (\ud835\udcdd (real.pi^2/6)) :=\nbegin\n  nth_rewrite 0 \u2190zero_add (real.pi^2/6),\n  apply tendsto.add_const,\n  apply tendsto_const_div_add_at_top_nhds_0_nat,\nend\n\nlemma limit_above : tendsto (\u03bb (n:\u2115), real.pi^2/4/(n+1) + real.pi^2/6) at_top (\ud835\udcdd (real.pi^2/6)) :=\nbegin\n  nth_rewrite 0 \u2190zero_add (real.pi^2/6),\n  apply tendsto.add_const,\n  apply tendsto_const_div_add_at_top_nhds_0_nat,\nend\n\n\ntheorem euler_summation : tendsto (\u03bb (n:\u2115), (\u2211 k in finset.range n, ((1:\u211d)/ (k+1)^2))) at_top (nhds (real.pi^2 / 6)) :=\nbegin\n  apply tendsto_of_tendsto_of_tendsto_of_le_of_le limit_below limit_above,\n  all_goals {rw pi.le_def, intro n},\n  exact error_estimate.1,\n  exact error_estimate.2,\nend", "meta": {"author": "mmasdeu", "repo": "euler", "sha": "a323d777dee611f2a06cc81e2f2567cd9522a381", "save_path": "github-repos/lean/mmasdeu-euler", "path": "github-repos/lean/mmasdeu-euler/euler-a323d777dee611f2a06cc81e2f2567cd9522a381/src/euler.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7174837358828132}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Riccardo Brasca\n\n! This file was ported from Lean 3 source module analysis.normed.group.quotient\n! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.NormedSpace.Basic\nimport Mathbin.Analysis.Normed.Group.Hom\nimport Mathbin.RingTheory.Ideal.QuotientOperations\n\n/-!\n# Quotients of seminormed groups\n\nFor any `seminormed_add_comm_group M` and any `S : add_subgroup M`, we provide a\n`seminormed_add_comm_group`, the group quotient `M \u29f8 S`.\nIf `S` is closed, we provide `normed_add_comm_group (M \u29f8 S)` (regardless of whether `M` itself is\nseparated). The two main properties of these structures are the underlying topology is the quotient\ntopology and the projection is a normed group homomorphism which is norm non-increasing\n(better, it has operator norm exactly one unless `S` is dense in `M`). The corresponding\nuniversal property is that every normed group hom defined on `M` which vanishes on `S` descends\nto a normed group hom defined on `M \u29f8 S`.\n\nThis file also introduces a predicate `is_quotient` characterizing normed group homs that\nare isomorphic to the canonical projection onto a normed group quotient.\n\nIn addition, this file also provides normed structures for quotients of modules by submodules, and\nof (commutative) rings by ideals. The `seminormed_add_comm_group` and `normed_add_comm_group`\ninstances described above are transferred directly, but we also define instances of `normed_space`,\n`semi_normed_comm_ring`, `normed_comm_ring` and `normed_algebra` under appropriate type class\nassumptions on the original space. Moreover, while `quotient_add_group.complete_space` works\nout-of-the-box for quotients of `normed_add_comm_group`s by `add_subgroup`s, we need to transfer\nthis instance in `submodule.quotient.complete_space` so that it applies to these other quotients.\n\n## Main definitions\n\n\nWe use `M` and `N` to denote seminormed groups and `S : add_subgroup M`.\nAll the following definitions are in the `add_subgroup` namespace. Hence we can access\n`add_subgroup.normed_mk S` as `S.normed_mk`.\n\n* `seminormed_add_comm_group_quotient` : The seminormed group structure on the quotient by\n    an additive subgroup. This is an instance so there is no need to explictly use it.\n\n* `normed_add_comm_group_quotient` : The normed group structure on the quotient by\n    a closed additive subgroup. This is an instance so there is no need to explictly use it.\n\n* `normed_mk S` : the normed group hom from `M` to `M \u29f8 S`.\n\n* `lift S f hf`: implements the universal property of `M \u29f8 S`. Here\n    `(f : normed_add_group_hom M N)`, `(hf : \u2200 s \u2208 S, f s = 0)` and\n    `lift S f hf : normed_add_group_hom (M \u29f8 S) N`.\n\n* `is_quotient`: given `f : normed_add_group_hom M N`, `is_quotient f` means `N` is isomorphic\n    to a quotient of `M` by a subgroup, with projection `f`. Technically it asserts `f` is\n    surjective and the norm of `f x` is the infimum of the norms of `x + m` for `m` in `f.ker`.\n\n## Main results\n\n* `norm_normed_mk` : the operator norm of the projection is `1` if the subspace is not dense.\n\n* `is_quotient.norm_lift`: Provided `f : normed_hom M N` satisfies `is_quotient f`, for every\n     `n : N` and positive `\u03b5`, there exists `m` such that `f m = n \u2227 \u2016m\u2016 < \u2016n\u2016 + \u03b5`.\n\n\n## Implementation details\n\nFor any `seminormed_add_comm_group M` and any `S : add_subgroup M` we define a norm on `M \u29f8 S` by\n`\u2016x\u2016 = Inf (norm '' {m | mk' S m = x})`. This formula is really an implementation detail, it\nshouldn't be needed outside of this file setting up the theory.\n\nSince `M \u29f8 S` is automatically a topological space (as any quotient of a topological space),\none needs to be careful while defining the `seminormed_add_comm_group` instance to avoid having two\ndifferent topologies on this quotient. This is not purely a technological issue.\nMathematically there is something to prove. The main point is proved in the auxiliary lemma\n`quotient_nhd_basis` that has no use beyond this verification and states that zero in the quotient\nadmits as basis of neighborhoods in the quotient topology the sets `{x | \u2016x\u2016 < \u03b5}` for positive `\u03b5`.\n\nOnce this mathematical point it settled, we have two topologies that are propositionaly equal. This\nis not good enough for the type class system. As usual we ensure *definitional* equality\nusing forgetful inheritance, see Note [forgetful inheritance]. A (semi)-normed group structure\nincludes a uniform space structure which includes a topological space structure, together\nwith propositional fields asserting compatibility conditions.\nThe usual way to define a `seminormed_add_comm_group` is to let Lean build a uniform space structure\nusing the provided norm, and then trivially build a proof that the norm and uniform structure are\ncompatible. Here the uniform structure is provided using `topological_add_group.to_uniform_space`\nwhich uses the topological structure and the group structure to build the uniform structure. This\nuniform structure induces the correct topological structure by construction, but the fact that it\nis compatible with the norm is not obvious; this is where the mathematical content explained in\nthe previous paragraph kicks in.\n\n-/\n\n\nnoncomputable section\n\nopen quotientAddGroup Metric Set\n\nopen Topology NNReal\n\nvariable {M N : Type _} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N]\n\n/-- The definition of the norm on the quotient by an additive subgroup. -/\nnoncomputable instance normOnQuotient (S : AddSubgroup M) : Norm (M \u29f8 S)\n    where norm x := inf\u209b (norm '' { m | mk' S m = x })\n#align norm_on_quotient normOnQuotient\n\ntheorem AddSubgroup.quotient_norm_eq {S : AddSubgroup M} (x : M \u29f8 S) :\n    \u2016x\u2016 = inf\u209b (norm '' { m : M | (m : M \u29f8 S) = x }) :=\n  rfl\n#align add_subgroup.quotient_norm_eq AddSubgroup.quotient_norm_eq\n\ntheorem image_norm_nonempty {S : AddSubgroup M} :\n    \u2200 x : M \u29f8 S, (norm '' { m | mk' S m = x }).Nonempty :=\n  by\n  rintro \u27e8m\u27e9\n  rw [Set.nonempty_image_iff]\n  use m\n  change mk' S m = _\n  rfl\n#align image_norm_nonempty image_norm_nonempty\n\ntheorem bddBelow_image_norm (s : Set M) : BddBelow (norm '' s) :=\n  by\n  use 0\n  rintro _ \u27e8x, hx, rfl\u27e9\n  apply norm_nonneg\n#align bdd_below_image_norm bddBelow_image_norm\n\n/-- The norm on the quotient satisfies `\u2016-x\u2016 = \u2016x\u2016`. -/\ntheorem quotient_norm_neg {S : AddSubgroup M} (x : M \u29f8 S) : \u2016-x\u2016 = \u2016x\u2016 :=\n  by\n  suffices norm '' { m | mk' S m = x } = norm '' { m | mk' S m = -x } by simp only [this, norm]\n  ext r\n  constructor\n  \u00b7 rintro \u27e8m, rfl : mk' S m = x, rfl\u27e9\n    rw [\u2190 norm_neg]\n    exact \u27e8-m, by simp only [(mk' S).map_neg, Set.mem_setOf_eq], rfl\u27e9\n  \u00b7 rintro \u27e8m, hm : mk' S m = -x, rfl\u27e9\n    exact \u27e8-m, by simpa using neg_eq_iff_eq_neg.mpr ((mk'_apply _ _).symm.trans hm)\u27e9\n#align quotient_norm_neg quotient_norm_neg\n\ntheorem quotient_norm_sub_rev {S : AddSubgroup M} (x y : M \u29f8 S) : \u2016x - y\u2016 = \u2016y - x\u2016 := by\n  rw [show x - y = -(y - x) by abel, quotient_norm_neg]\n#align quotient_norm_sub_rev quotient_norm_sub_rev\n\n/-- The norm of the projection is smaller or equal to the norm of the original element. -/\ntheorem quotient_norm_mk_le (S : AddSubgroup M) (m : M) : \u2016mk' S m\u2016 \u2264 \u2016m\u2016 :=\n  by\n  apply cinf\u209b_le\n  use 0\n  \u00b7 rintro _ \u27e8n, h, rfl\u27e9\n    apply norm_nonneg\n  \u00b7 apply Set.mem_image_of_mem\n    rw [Set.mem_setOf_eq]\n#align quotient_norm_mk_le quotient_norm_mk_le\n\n/-- The norm of the projection is smaller or equal to the norm of the original element. -/\ntheorem quotient_norm_mk_le' (S : AddSubgroup M) (m : M) : \u2016(m : M \u29f8 S)\u2016 \u2264 \u2016m\u2016 :=\n  quotient_norm_mk_le S m\n#align quotient_norm_mk_le' quotient_norm_mk_le'\n\n/-- The norm of the image under the natural morphism to the quotient. -/\ntheorem quotient_norm_mk_eq (S : AddSubgroup M) (m : M) :\n    \u2016mk' S m\u2016 = inf\u209b ((fun x => \u2016m + x\u2016) '' S) :=\n  by\n  change Inf _ = _\n  congr 1\n  ext r\n  simp_rw [coe_mk', eq_iff_sub_mem]\n  constructor\n  \u00b7 rintro \u27e8y, h, rfl\u27e9\n    use y - m, h\n    simp\n  \u00b7 rintro \u27e8y, h, rfl\u27e9\n    use m + y\n    simpa using h\n#align quotient_norm_mk_eq quotient_norm_mk_eq\n\n/-- The quotient norm is nonnegative. -/\ntheorem quotient_norm_nonneg (S : AddSubgroup M) : \u2200 x : M \u29f8 S, 0 \u2264 \u2016x\u2016 :=\n  by\n  rintro \u27e8m\u27e9\n  change 0 \u2264 \u2016mk' S m\u2016\n  apply le_cinf\u209b (image_norm_nonempty _)\n  rintro _ \u27e8n, h, rfl\u27e9\n  apply norm_nonneg\n#align quotient_norm_nonneg quotient_norm_nonneg\n\n/-- The quotient norm is nonnegative. -/\ntheorem norm_mk_nonneg (S : AddSubgroup M) (m : M) : 0 \u2264 \u2016mk' S m\u2016 :=\n  quotient_norm_nonneg S _\n#align norm_mk_nonneg norm_mk_nonneg\n\n/-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs\nto the closure of `S`. -/\ntheorem quotient_norm_eq_zero_iff (S : AddSubgroup M) (m : M) :\n    \u2016mk' S m\u2016 = 0 \u2194 m \u2208 closure (S : Set M) :=\n  by\n  have : 0 \u2264 \u2016mk' S m\u2016 := norm_mk_nonneg S m\n  rw [\u2190 this.le_iff_eq, quotient_norm_mk_eq, Real.inf\u209b_le_iff]\n  simp_rw [zero_add]\n  \u00b7 calc\n      (\u2200 \u03b5 > (0 : \u211d), \u2203 r \u2208 (fun x => \u2016m + x\u2016) '' (S : Set M), r < \u03b5) \u2194\n          \u2200 \u03b5 > 0, \u2203 x \u2208 S, \u2016m + x\u2016 < \u03b5 :=\n        by simp [Set.bex_image_iff]\n      _ \u2194 \u2200 \u03b5 > 0, \u2203 x \u2208 S, \u2016m + -x\u2016 < \u03b5 := _\n      _ \u2194 \u2200 \u03b5 > 0, \u2203 x \u2208 S, x \u2208 Metric.ball m \u03b5 := by\n        simp [dist_eq_norm, \u2190 sub_eq_add_neg, norm_sub_rev]\n      _ \u2194 m \u2208 closure \u2191S := by simp [Metric.mem_closure_iff, dist_comm]\n      \n    refine' forall\u2082_congr fun \u03b5 \u03b5_pos => _\n    rw [\u2190 S.exists_neg_mem_iff_exists_mem]\n    simp\n  \u00b7 use 0\n    rintro _ \u27e8x, x_in, rfl\u27e9\n    apply norm_nonneg\n  rw [Set.nonempty_image_iff]\n  use 0, S.zero_mem\n#align quotient_norm_eq_zero_iff quotient_norm_eq_zero_iff\n\n/-- For any `x : M \u29f8 S` and any `0 < \u03b5`, there is `m : M` such that `mk' S m = x`\nand `\u2016m\u2016 < \u2016x\u2016 + \u03b5`. -/\ntheorem norm_mk_lt {S : AddSubgroup M} (x : M \u29f8 S) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n    \u2203 m : M, mk' S m = x \u2227 \u2016m\u2016 < \u2016x\u2016 + \u03b5 :=\n  by\n  obtain \u27e8_, \u27e8m : M, H : mk' S m = x, rfl\u27e9, hnorm : \u2016m\u2016 < \u2016x\u2016 + \u03b5\u27e9 :=\n    Real.lt_inf\u209b_add_pos (image_norm_nonempty x) h\u03b5\n  subst H\n  exact \u27e8m, rfl, hnorm\u27e9\n#align norm_mk_lt norm_mk_lt\n\n/-- For any `m : M` and any `0 < \u03b5`, there is `s \u2208 S` such that `\u2016m + s\u2016 < \u2016mk' S m\u2016 + \u03b5`. -/\ntheorem norm_mk_lt' (S : AddSubgroup M) (m : M) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n    \u2203 s \u2208 S, \u2016m + s\u2016 < \u2016mk' S m\u2016 + \u03b5 :=\n  by\n  obtain \u27e8n : M, hn : mk' S n = mk' S m, hn' : \u2016n\u2016 < \u2016mk' S m\u2016 + \u03b5\u27e9 :=\n    norm_mk_lt (QuotientAddGroup.mk' S m) h\u03b5\n  erw [eq_comm, QuotientAddGroup.eq] at hn\n  use -m + n, hn\n  rwa [add_neg_cancel_left]\n#align norm_mk_lt' norm_mk_lt'\n\n/-- The quotient norm satisfies the triangle inequality. -/\ntheorem quotient_norm_add_le (S : AddSubgroup M) (x y : M \u29f8 S) : \u2016x + y\u2016 \u2264 \u2016x\u2016 + \u2016y\u2016 :=\n  by\n  refine' le_of_forall_pos_le_add fun \u03b5 h\u03b5 => _\n  replace h\u03b5 := half_pos h\u03b5\n  obtain \u27e8m, rfl, hm : \u2016m\u2016 < \u2016mk' S m\u2016 + \u03b5 / 2\u27e9 := norm_mk_lt x h\u03b5\n  obtain \u27e8n, rfl, hn : \u2016n\u2016 < \u2016mk' S n\u2016 + \u03b5 / 2\u27e9 := norm_mk_lt y h\u03b5\n  calc\n    \u2016mk' S m + mk' S n\u2016 = \u2016mk' S (m + n)\u2016 := by rw [(mk' S).map_add]\n    _ \u2264 \u2016m + n\u2016 := (quotient_norm_mk_le S (m + n))\n    _ \u2264 \u2016m\u2016 + \u2016n\u2016 := (norm_add_le _ _)\n    _ \u2264 \u2016mk' S m\u2016 + \u2016mk' S n\u2016 + \u03b5 := by linarith\n    \n#align quotient_norm_add_le quotient_norm_add_le\n\n/-- The quotient norm of `0` is `0`. -/\ntheorem norm_mk_zero (S : AddSubgroup M) : \u2016(0 : M \u29f8 S)\u2016 = 0 :=\n  by\n  erw [quotient_norm_eq_zero_iff]\n  exact subset_closure S.zero_mem\n#align norm_mk_zero norm_mk_zero\n\n/-- If `(m : M)` has norm equal to `0` in `M \u29f8 S` for a closed subgroup `S` of `M`, then\n`m \u2208 S`. -/\ntheorem norm_zero_eq_zero (S : AddSubgroup M) (hS : IsClosed (S : Set M)) (m : M)\n    (h : \u2016mk' S m\u2016 = 0) : m \u2208 S := by rwa [quotient_norm_eq_zero_iff, hS.closure_eq] at h\n#align norm_zero_eq_zero norm_zero_eq_zero\n\ntheorem quotient_nhd_basis (S : AddSubgroup M) :\n    (\ud835\udcdd (0 : M \u29f8 S)).HasBasis (fun \u03b5 : \u211d => 0 < \u03b5) fun \u03b5 => { x | \u2016x\u2016 < \u03b5 } :=\n  \u27e8by\n    intro U\n    constructor\n    \u00b7 intro U_in\n      rw [\u2190 (mk' S).map_zero] at U_in\n      have := preimage_nhds_coinduced U_in\n      rcases metric.mem_nhds_iff.mp this with \u27e8\u03b5, \u03b5_pos, H\u27e9\n      use \u03b5 / 2, half_pos \u03b5_pos\n      intro x x_in\n      dsimp at x_in\n      rcases norm_mk_lt x (half_pos \u03b5_pos) with \u27e8y, rfl, ry\u27e9\n      apply H\n      rw [ball_zero_eq]\n      dsimp\n      linarith\n    \u00b7 rintro \u27e8\u03b5, \u03b5_pos, h\u27e9\n      have : mk' S '' ball (0 : M) \u03b5 \u2286 { x | \u2016x\u2016 < \u03b5 } :=\n        by\n        rintro _ \u27e8x, x_in, rfl\u27e9\n        rw [mem_ball_zero_iff] at x_in\n        exact lt_of_le_of_lt (quotient_norm_mk_le S x) x_in\n      apply Filter.mem_of_superset _ (Set.Subset.trans this h)\n      clear h U this\n      apply IsOpen.mem_nhds\n      \u00b7 change IsOpen (mk' S \u207b\u00b9' _)\n        erw [QuotientAddGroup.preimage_image_mk]\n        apply isOpen_union\u1d62\n        rintro \u27e8s, s_in\u27e9\n        exact (continuous_add_right s).isOpen_preimage _ is_open_ball\n      \u00b7 exact \u27e8(0 : M), mem_ball_self \u03b5_pos, (mk' S).map_zero\u27e9\u27e9\n#align quotient_nhd_basis quotient_nhd_basis\n\n/-- The seminormed group structure on the quotient by an additive subgroup. -/\nnoncomputable instance AddSubgroup.seminormedAddCommGroupQuotient (S : AddSubgroup M) :\n    SeminormedAddCommGroup (M \u29f8 S) where\n  dist x y := \u2016x - y\u2016\n  dist_self x := by simp only [norm_mk_zero, sub_self]\n  dist_comm := quotient_norm_sub_rev\n  dist_triangle x y z := by\n    unfold dist\n    have : x - z = x - y + (y - z) := by abel\n    rw [this]\n    exact quotient_norm_add_le S (x - y) (y - z)\n  dist_eq x y := rfl\n  toUniformSpace := TopologicalAddGroup.toUniformSpace (M \u29f8 S)\n  uniformity_dist := by\n    rw [uniformity_eq_comap_nhds_zero']\n    have := (quotient_nhd_basis S).comap fun p : (M \u29f8 S) \u00d7 M \u29f8 S => p.2 - p.1\n    apply this.eq_of_same_basis\n    have :\n      \u2200 \u03b5 : \u211d,\n        (fun p : (M \u29f8 S) \u00d7 M \u29f8 S => p.snd - p.fst) \u207b\u00b9' { x | \u2016x\u2016 < \u03b5 } =\n          { p : (M \u29f8 S) \u00d7 M \u29f8 S | \u2016p.fst - p.snd\u2016 < \u03b5 } :=\n      by\n      intro \u03b5\n      ext x\n      dsimp\n      rw [quotient_norm_sub_rev]\n    rw [funext this]\n    refine' Filter.hasBasis_binf\u1d62_principal _ Set.nonempty_Ioi\n    rintro \u03b5 (\u03b5_pos : 0 < \u03b5) \u03b7 (\u03b7_pos : 0 < \u03b7)\n    refine' \u27e8min \u03b5 \u03b7, lt_min \u03b5_pos \u03b7_pos, _, _\u27e9\n    \u00b7 suffices \u2200 a b : M \u29f8 S, \u2016a - b\u2016 < \u03b5 \u2192 \u2016a - b\u2016 < \u03b7 \u2192 \u2016a - b\u2016 < \u03b5 by simpa\n      exact fun a b h h' => h\n    \u00b7 simp\n#align add_subgroup.seminormed_add_comm_group_quotient AddSubgroup.seminormedAddCommGroupQuotient\n\n-- This is a sanity check left here on purpose to ensure that potential refactors won't destroy\n-- this important property.\nexample (S : AddSubgroup M) :\n    (Quotient.topologicalSpace : TopologicalSpace <| M \u29f8 S) =\n      S.seminormedAddCommGroupQuotient.toUniformSpace.toTopologicalSpace :=\n  rfl\n\n/-- The quotient in the category of normed groups. -/\nnoncomputable instance AddSubgroup.normedAddCommGroupQuotient (S : AddSubgroup M)\n    [IsClosed (S : Set M)] : NormedAddCommGroup (M \u29f8 S) :=\n  { AddSubgroup.seminormedAddCommGroupQuotient S with\n    eq_of_dist_eq_zero := by\n      rintro \u27e8m\u27e9 \u27e8m'\u27e9 (h : \u2016mk' S m - mk' S m'\u2016 = 0)\n      erw [\u2190 (mk' S).map_sub, quotient_norm_eq_zero_iff, \u2039IsClosed _\u203a.closure_eq, \u2190\n        QuotientAddGroup.eq_iff_sub_mem] at h\n      exact h }\n#align add_subgroup.normed_add_comm_group_quotient AddSubgroup.normedAddCommGroupQuotient\n\n-- This is a sanity check left here on purpose to ensure that potential refactors won't destroy\n-- this important property.\nexample (S : AddSubgroup M) [IsClosed (S : Set M)] :\n    S.seminormedAddCommGroupQuotient = NormedAddCommGroup.toSeminormedAddCommGroup :=\n  rfl\n\nnamespace AddSubgroup\n\nopen NormedAddGroupHom\n\n/-- The morphism from a seminormed group to the quotient by a subgroup. -/\nnoncomputable def normedMk (S : AddSubgroup M) : NormedAddGroupHom M (M \u29f8 S) :=\n  { QuotientAddGroup.mk' S with\n    bound' := \u27e81, fun m => by simpa [one_mul] using quotient_norm_mk_le _ m\u27e9 }\n#align add_subgroup.normed_mk AddSubgroup.normedMk\n\n/-- `S.normed_mk` agrees with `quotient_add_group.mk' S`. -/\n@[simp]\ntheorem normedMk.apply (S : AddSubgroup M) (m : M) : normedMk S m = QuotientAddGroup.mk' S m :=\n  rfl\n#align add_subgroup.normed_mk.apply AddSubgroup.normedMk.apply\n\n/-- `S.normed_mk` is surjective. -/\ntheorem surjective_normedMk (S : AddSubgroup M) : Function.Surjective (normedMk S) :=\n  surjective_quot_mk _\n#align add_subgroup.surjective_normed_mk AddSubgroup.surjective_normedMk\n\n/-- The kernel of `S.normed_mk` is `S`. -/\ntheorem ker_normedMk (S : AddSubgroup M) : S.normedMk.ker = S :=\n  QuotientAddGroup.ker_mk' _\n#align add_subgroup.ker_normed_mk AddSubgroup.ker_normedMk\n\n/-- The operator norm of the projection is at most `1`. -/\ntheorem norm_normedMk_le (S : AddSubgroup M) : \u2016S.normedMk\u2016 \u2264 1 :=\n  NormedAddGroupHom.opNorm_le_bound _ zero_le_one fun m => by simp [quotient_norm_mk_le']\n#align add_subgroup.norm_normed_mk_le AddSubgroup.norm_normedMk_le\n\n/-- The operator norm of the projection is `1` if the subspace is not dense. -/\ntheorem norm_normedMk (S : AddSubgroup M) (h : (S.topologicalClosure : Set M) \u2260 univ) :\n    \u2016S.normedMk\u2016 = 1 := by\n  obtain \u27e8x, hx\u27e9 := Set.nonempty_compl.2 h\n  let y := S.normed_mk x\n  have hy : \u2016y\u2016 \u2260 0 := by\n    intro h0\n    exact Set.not_mem_of_mem_compl hx ((quotient_norm_eq_zero_iff S x).1 h0)\n  refine' le_antisymm (norm_normed_mk_le S) (le_of_forall_pos_le_add fun \u03b5 h\u03b5 => _)\n  suffices 1 \u2264 \u2016S.normed_mk\u2016 + min \u03b5 ((1 : \u211d) / 2) by\n    exact le_add_of_le_add_left this (min_le_left \u03b5 ((1 : \u211d) / 2))\n  have h\u03b4 := sub_pos.mpr (lt_of_le_of_lt (min_le_right \u03b5 ((1 : \u211d) / 2)) one_half_lt_one)\n  have h\u03b4pos : 0 < min \u03b5 ((1 : \u211d) / 2) := lt_min h\u03b5 one_half_pos\n  have h\u03b4norm := mul_pos (div_pos h\u03b4pos h\u03b4) (lt_of_le_of_ne (norm_nonneg y) hy.symm)\n  obtain \u27e8m, hm, hlt\u27e9 := norm_mk_lt y h\u03b4norm\n  have hrw :\n    \u2016y\u2016 + min \u03b5 (1 / 2) / (1 - min \u03b5 (1 / 2)) * \u2016y\u2016 =\n      \u2016y\u2016 * (1 + min \u03b5 (1 / 2) / (1 - min \u03b5 (1 / 2))) :=\n    by ring\n  rw [hrw] at hlt\n  have hm0 : \u2016m\u2016 \u2260 0 := by\n    intro h0\n    have hnorm := quotient_norm_mk_le S m\n    rw [h0, hm] at hnorm\n    replace hnorm := le_antisymm hnorm (norm_nonneg _)\n    simpa [hnorm] using hy\n  replace hlt := (div_lt_div_right (lt_of_le_of_ne (norm_nonneg m) hm0.symm)).2 hlt\n  simp only [hm0, div_self, Ne.def, not_false_iff] at hlt\n  have hrw\u2081 :\n    \u2016y\u2016 * (1 + min \u03b5 (1 / 2) / (1 - min \u03b5 (1 / 2))) / \u2016m\u2016 =\n      \u2016y\u2016 / \u2016m\u2016 * (1 + min \u03b5 (1 / 2) / (1 - min \u03b5 (1 / 2))) :=\n    by ring\n  rw [hrw\u2081] at hlt\n  replace hlt := (inv_pos_lt_iff_one_lt_mul (lt_trans (div_pos h\u03b4pos h\u03b4) (lt_one_add _))).2 hlt\n  suffices \u2016S.normed_mk\u2016 \u2265 1 - min \u03b5 (1 / 2) by exact sub_le_iff_le_add.mp this\n  calc\n    \u2016S.normed_mk\u2016 \u2265 \u2016S.normed_mk m\u2016 / \u2016m\u2016 := ratio_le_op_norm S.normed_mk m\n    _ = \u2016y\u2016 / \u2016m\u2016 := by rw [normed_mk.apply, hm]\n    _ \u2265 (1 + min \u03b5 (1 / 2) / (1 - min \u03b5 (1 / 2)))\u207b\u00b9 := (le_of_lt hlt)\n    _ = 1 - min \u03b5 (1 / 2) := by field_simp [(ne_of_lt h\u03b4).symm]\n    \n#align add_subgroup.norm_normed_mk AddSubgroup.norm_normedMk\n\n/-- The operator norm of the projection is `0` if the subspace is dense. -/\ntheorem norm_trivial_quotient_mk (S : AddSubgroup M)\n    (h : (S.topologicalClosure : Set M) = Set.univ) : \u2016S.normedMk\u2016 = 0 :=\n  by\n  refine' le_antisymm (op_norm_le_bound _ le_rfl fun x => _) (norm_nonneg _)\n  have hker : x \u2208 S.normed_mk.ker.topologicalClosure :=\n    by\n    rw [S.ker_normed_mk]\n    exact Set.mem_of_eq_of_mem h trivial\n  rw [ker_normed_mk] at hker\n  simp only [(quotient_norm_eq_zero_iff S x).mpr hker, normed_mk.apply, MulZeroClass.zero_mul]\n#align add_subgroup.norm_trivial_quotient_mk AddSubgroup.norm_trivial_quotient_mk\n\nend AddSubgroup\n\nnamespace NormedAddGroupHom\n\n/-- `is_quotient f`, for `f : M \u27f6 N` means that `N` is isomorphic to the quotient of `M`\nby the kernel of `f`. -/\nstructure IsQuotient (f : NormedAddGroupHom M N) : Prop where\n  Surjective : Function.Surjective f\n  norm : \u2200 x, \u2016f x\u2016 = inf\u209b ((fun m => \u2016x + m\u2016) '' f.ker)\n#align normed_add_group_hom.is_quotient NormedAddGroupHom.IsQuotient\n\n/-- Given  `f : normed_add_group_hom M N` such that `f s = 0` for all `s \u2208 S`, where,\n`S : add_subgroup M` is closed, the induced morphism `normed_add_group_hom (M \u29f8 S) N`. -/\nnoncomputable def lift {N : Type _} [SeminormedAddCommGroup N] (S : AddSubgroup M)\n    (f : NormedAddGroupHom M N) (hf : \u2200 s \u2208 S, f s = 0) : NormedAddGroupHom (M \u29f8 S) N :=\n  { QuotientAddGroup.lift S f.toAddMonoidHom hf with\n    bound' := by\n      obtain \u27e8c : \u211d, hcpos : (0 : \u211d) < c, hc : \u2200 x, \u2016f x\u2016 \u2264 c * \u2016x\u2016\u27e9 := f.bound\n      refine' \u27e8c, fun mbar => le_of_forall_pos_le_add fun \u03b5 h\u03b5 => _\u27e9\n      obtain \u27e8m : M, rfl : mk' S m = mbar, hmnorm : \u2016m\u2016 < \u2016mk' S m\u2016 + \u03b5 / c\u27e9 :=\n        norm_mk_lt mbar (div_pos h\u03b5 hcpos)\n      calc\n        \u2016f m\u2016 \u2264 c * \u2016m\u2016 := hc m\n        _ \u2264 c * (\u2016mk' S m\u2016 + \u03b5 / c) := ((mul_lt_mul_left hcpos).mpr hmnorm).le\n        _ = c * \u2016mk' S m\u2016 + \u03b5 := by rw [mul_add, mul_div_cancel' _ hcpos.ne.symm]\n         }\n#align normed_add_group_hom.lift NormedAddGroupHom.lift\n\ntheorem lift_mk {N : Type _} [SeminormedAddCommGroup N] (S : AddSubgroup M)\n    (f : NormedAddGroupHom M N) (hf : \u2200 s \u2208 S, f s = 0) (m : M) :\n    lift S f hf (S.normedMk m) = f m :=\n  rfl\n#align normed_add_group_hom.lift_mk NormedAddGroupHom.lift_mk\n\ntheorem lift_unique {N : Type _} [SeminormedAddCommGroup N] (S : AddSubgroup M)\n    (f : NormedAddGroupHom M N) (hf : \u2200 s \u2208 S, f s = 0) (g : NormedAddGroupHom (M \u29f8 S) N) :\n    g.comp S.normedMk = f \u2192 g = lift S f hf :=\n  by\n  intro h\n  ext\n  rcases AddSubgroup.surjective_normedMk _ x with \u27e8x, rfl\u27e9\n  change g.comp S.normed_mk x = _\n  simpa only [h]\n#align normed_add_group_hom.lift_unique NormedAddGroupHom.lift_unique\n\n/-- `S.normed_mk` satisfies `is_quotient`. -/\ntheorem isQuotientQuotient (S : AddSubgroup M) : IsQuotient S.normedMk :=\n  \u27e8S.surjective_normedMk, fun m => by simpa [S.ker_normed_mk] using quotient_norm_mk_eq _ m\u27e9\n#align normed_add_group_hom.is_quotient_quotient NormedAddGroupHom.isQuotientQuotient\n\ntheorem IsQuotient.norm_lift {f : NormedAddGroupHom M N} (hquot : IsQuotient f) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5)\n    (n : N) : \u2203 m : M, f m = n \u2227 \u2016m\u2016 < \u2016n\u2016 + \u03b5 :=\n  by\n  obtain \u27e8m, rfl\u27e9 := hquot.surjective n\n  have nonemp : ((fun m' => \u2016m + m'\u2016) '' f.ker).Nonempty :=\n    by\n    rw [Set.nonempty_image_iff]\n    exact \u27e80, f.ker.zero_mem\u27e9\n  rcases Real.lt_inf\u209b_add_pos nonemp h\u03b5 with\n    \u27e8_, \u27e8\u27e8x, hx, rfl\u27e9, H : \u2016m + x\u2016 < Inf ((fun m' : M => \u2016m + m'\u2016) '' f.ker) + \u03b5\u27e9\u27e9\n  exact\n    \u27e8m + x, by rw [map_add, (NormedAddGroupHom.mem_ker f x).mp hx, add_zero], by rwa [hquot.norm]\u27e9\n#align normed_add_group_hom.is_quotient.norm_lift NormedAddGroupHom.IsQuotient.norm_lift\n\ntheorem IsQuotient.norm_le {f : NormedAddGroupHom M N} (hquot : IsQuotient f) (m : M) :\n    \u2016f m\u2016 \u2264 \u2016m\u2016 := by\n  rw [hquot.norm]\n  apply cinf\u209b_le\n  \u00b7 use 0\n    rintro _ \u27e8m', hm', rfl\u27e9\n    apply norm_nonneg\n  \u00b7 exact \u27e80, f.ker.zero_mem, by simp\u27e9\n#align normed_add_group_hom.is_quotient.norm_le NormedAddGroupHom.IsQuotient.norm_le\n\ntheorem lift_norm_le {N : Type _} [SeminormedAddCommGroup N] (S : AddSubgroup M)\n    (f : NormedAddGroupHom M N) (hf : \u2200 s \u2208 S, f s = 0) {c : \u211d\u22650} (fb : \u2016f\u2016 \u2264 c) :\n    \u2016lift S f hf\u2016 \u2264 c := by\n  apply op_norm_le_bound _ c.coe_nonneg\n  intro x\n  by_cases hc : c = 0\n  \u00b7 simp only [hc, NNReal.coe_zero, MulZeroClass.zero_mul] at fb\u22a2\n    obtain \u27e8x, rfl\u27e9 := surjective_quot_mk _ x\n    show \u2016f x\u2016 \u2264 0\n    calc\n      \u2016f x\u2016 \u2264 0 * \u2016x\u2016 := f.le_of_op_norm_le fb x\n      _ = 0 := MulZeroClass.zero_mul _\n      \n  \u00b7 replace hc : 0 < c := pos_iff_ne_zero.mpr hc\n    apply le_of_forall_pos_le_add\n    intro \u03b5 h\u03b5\n    have aux : 0 < \u03b5 / c := div_pos h\u03b5 hc\n    obtain \u27e8x, rfl, Hx\u27e9 : \u2203 x', S.normed_mk x' = x \u2227 \u2016x'\u2016 < \u2016x\u2016 + \u03b5 / c :=\n      (is_quotient_quotient _).norm_lift aux _\n    rw [lift_mk]\n    calc\n      \u2016f x\u2016 \u2264 c * \u2016x\u2016 := f.le_of_op_norm_le fb x\n      _ \u2264 c * (\u2016S.normed_mk x\u2016 + \u03b5 / c) := ((mul_le_mul_left _).mpr Hx.le)\n      _ = c * _ + \u03b5 := _\n      \n    \u00b7 exact_mod_cast hc\n    \u00b7 rw [mul_add, mul_div_cancel']\n      exact_mod_cast hc.ne'\n#align normed_add_group_hom.lift_norm_le NormedAddGroupHom.lift_norm_le\n\ntheorem lift_normNoninc {N : Type _} [SeminormedAddCommGroup N] (S : AddSubgroup M)\n    (f : NormedAddGroupHom M N) (hf : \u2200 s \u2208 S, f s = 0) (fb : f.NormNoninc) :\n    (lift S f hf).NormNoninc := fun x =>\n  by\n  have fb' : \u2016f\u2016 \u2264 (1 : \u211d\u22650) := norm_noninc.norm_noninc_iff_norm_le_one.mp fb\n  simpa using le_of_op_norm_le _ (f.lift_norm_le _ _ fb') _\n#align normed_add_group_hom.lift_norm_noninc NormedAddGroupHom.lift_normNoninc\n\nend NormedAddGroupHom\n\n/-!\n### Submodules and ideals\n\nIn what follows, the norm structures created above for quotients of (semi)`normed_add_comm_group`s\nby `add_subgroup`s are transferred via definitional equality to quotients of modules by submodules,\nand of rings by ideals, thereby preserving the definitional equality for the topological group and\nuniform structures worked for above. Completeness is also transferred via this definitional\nequality.\n\nIn addition, instances are constructed for `normed_space`, `semi_normed_comm_ring`,\n`normed_comm_ring` and `normed_algebra` under the appropriate hypotheses. Currently, we do not\nhave quotients of rings by two-sided ideals, hence the commutativity hypotheses are required.\n -/\n\n\nsection Submodule\n\nvariable {R : Type _} [Ring R] [Module R M] (S : Submodule R M)\n\ninstance Submodule.Quotient.seminormedAddCommGroup : SeminormedAddCommGroup (M \u29f8 S) :=\n  AddSubgroup.seminormedAddCommGroupQuotient S.toAddSubgroup\n#align submodule.quotient.seminormed_add_comm_group Submodule.Quotient.seminormedAddCommGroup\n\ninstance Submodule.Quotient.normedAddCommGroup [hS : IsClosed (S : Set M)] :\n    NormedAddCommGroup (M \u29f8 S) :=\n  @AddSubgroup.normedAddCommGroupQuotient _ _ S.toAddSubgroup hS\n#align submodule.quotient.normed_add_comm_group Submodule.Quotient.normedAddCommGroup\n\ninstance Submodule.Quotient.completeSpace [CompleteSpace M] : CompleteSpace (M \u29f8 S) :=\n  QuotientAddGroup.completeSpace M S.toAddSubgroup\n#align submodule.quotient.complete_space Submodule.Quotient.completeSpace\n\n/-- For any `x : M \u29f8 S` and any `0 < \u03b5`, there is `m : M` such that `submodule.quotient.mk m = x`\nand `\u2016m\u2016 < \u2016x\u2016 + \u03b5`. -/\ntheorem Submodule.Quotient.norm_mk_lt {S : Submodule R M} (x : M \u29f8 S) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n    \u2203 m : M, Submodule.Quotient.mk m = x \u2227 \u2016m\u2016 < \u2016x\u2016 + \u03b5 :=\n  norm_mk_lt x h\u03b5\n#align submodule.quotient.norm_mk_lt Submodule.Quotient.norm_mk_lt\n\ntheorem Submodule.Quotient.norm_mk_le (m : M) : \u2016(Submodule.Quotient.mk m : M \u29f8 S)\u2016 \u2264 \u2016m\u2016 :=\n  quotient_norm_mk_le S.toAddSubgroup m\n#align submodule.quotient.norm_mk_le Submodule.Quotient.norm_mk_le\n\ninstance Submodule.Quotient.normedSpace (\ud835\udd5c : Type _) [NormedField \ud835\udd5c] [NormedSpace \ud835\udd5c M] [SMul \ud835\udd5c R]\n    [IsScalarTower \ud835\udd5c R M] : NormedSpace \ud835\udd5c (M \u29f8 S) :=\n  { Submodule.Quotient.module' S with\n    norm_smul_le := fun k x =>\n      le_of_forall_pos_le_add fun \u03b5 h\u03b5 =>\n        by\n        have :=\n          (nhds_basis_ball.tendsto_iff nhds_basis_ball).mp\n            ((@Real.uniformContinuous_const_mul \u2016k\u2016).Continuous.Tendsto \u2016x\u2016) \u03b5 h\u03b5\n        simp only [mem_ball, exists_prop, dist, abs_sub_lt_iff] at this\n        rcases this with \u27e8\u03b4, h\u03b4, h\u27e9\n        obtain \u27e8a, rfl, ha\u27e9 := Submodule.Quotient.norm_mk_lt x h\u03b4\n        specialize h \u2016a\u2016 \u27e8by linarith, by linarith [Submodule.Quotient.norm_mk_le S a]\u27e9\n        calc\n          _ \u2264 \u2016k\u2016 * \u2016a\u2016 := (quotient_norm_mk_le S.to_add_subgroup (k \u2022 a)).trans_eq (norm_smul k a)\n          _ \u2264 _ := (sub_lt_iff_lt_add'.mp h.1).le\n           }\n#align submodule.quotient.normed_space Submodule.Quotient.normedSpace\n\nend Submodule\n\nsection Ideal\n\nvariable {R : Type _} [SeminormedCommRing R] (I : Ideal R)\n\ntheorem Ideal.Quotient.norm_mk_lt {I : Ideal R} (x : R \u29f8 I) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n    \u2203 r : R, Ideal.Quotient.mk I r = x \u2227 \u2016r\u2016 < \u2016x\u2016 + \u03b5 :=\n  norm_mk_lt x h\u03b5\n#align ideal.quotient.norm_mk_lt Ideal.Quotient.norm_mk_lt\n\ntheorem Ideal.Quotient.norm_mk_le (r : R) : \u2016Ideal.Quotient.mk I r\u2016 \u2264 \u2016r\u2016 :=\n  quotient_norm_mk_le I.toAddSubgroup r\n#align ideal.quotient.norm_mk_le Ideal.Quotient.norm_mk_le\n\ninstance Ideal.Quotient.semiNormedCommRing : SeminormedCommRing (R \u29f8 I) :=\n  {\n    Submodule.Quotient.seminormedAddCommGroup\n      I with\n    mul_comm := mul_comm\n    norm_mul := fun x y =>\n      le_of_forall_pos_le_add fun \u03b5 h\u03b5 =>\n        by\n        have :=\n          ((nhds_basis_ball.prod_nhds nhds_basis_ball).tendsto_iff\u2093 nhds_basis_ball).mp\n            (real.continuous_mul.tendsto (\u2016x\u2016, \u2016y\u2016)) \u03b5 h\u03b5\n        simp only [Set.mem_prod, mem_ball, and_imp, Prod.forall, exists_prop, Prod.exists] at this\n        rcases this with \u27e8\u03b5\u2081, \u03b5\u2082, \u27e8h\u2081, h\u2082\u27e9, h\u27e9\n        obtain \u27e8\u27e8a, rfl, ha\u27e9, \u27e8b, rfl, hb\u27e9\u27e9 := Ideal.Quotient.norm_mk_lt x h\u2081,\n          Ideal.Quotient.norm_mk_lt y h\u2082\n        simp only [dist, abs_sub_lt_iff] at h\n        specialize\n          h \u2016a\u2016 \u2016b\u2016 \u27e8by linarith, by linarith [Ideal.Quotient.norm_mk_le I a]\u27e9\n            \u27e8by linarith, by linarith [Ideal.Quotient.norm_mk_le I b]\u27e9\n        calc\n          _ \u2264 \u2016a\u2016 * \u2016b\u2016 := (Ideal.Quotient.norm_mk_le I (a * b)).trans (norm_mul_le a b)\n          _ \u2264 _ := (sub_lt_iff_lt_add'.mp h.1).le\n           }\n#align ideal.quotient.semi_normed_comm_ring Ideal.Quotient.semiNormedCommRing\n\ninstance Ideal.Quotient.normedCommRing [IsClosed (I : Set R)] : NormedCommRing (R \u29f8 I) :=\n  { Ideal.Quotient.semiNormedCommRing I, Submodule.Quotient.normedAddCommGroup I with }\n#align ideal.quotient.normed_comm_ring Ideal.Quotient.normedCommRing\n\nvariable (\ud835\udd5c : Type _) [NormedField \ud835\udd5c]\n\ninstance Ideal.Quotient.normedAlgebra [NormedAlgebra \ud835\udd5c R] : NormedAlgebra \ud835\udd5c (R \u29f8 I) :=\n  { Submodule.Quotient.normedSpace I \ud835\udd5c, Ideal.Quotient.algebra \ud835\udd5c with }\n#align ideal.quotient.normed_algebra Ideal.Quotient.normedAlgebra\n\nend Ideal\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/Normed/Group/Quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7174837273812096}}
{"text": "import logic.spaceship\nimport logic.funrel\n\n--- Inductively defined finite sets\ninductive finord : \u2115 \u2192 Type\n  | fz {n : \u2115} : finord (n+1)\n  | fs {n : \u2115} : finord n \u2192 finord (n+1)\n\n--- finord has a decidable equality\ninstance {n : \u2115} : decidable_eq (finord n) :=\n  begin\n    simp [decidable_eq, decidable_rel],\n    intros a b,\n    induction a with m m a ha,\n    all_goals {\n      cases b with n n b,\n      try { exact decidable.is_true rfl },\n      try { exact decidable.is_false (not.intro (\u03bb h, finord.no_confusion h)) }\n    },\n    cases ha b,\n    case decidable.is_false {\n      apply decidable.is_false,\n      apply not.intro,\n      intros hyp,\n      have : a = b, by injection hyp,\n      contradiction\n    },\n    case decidable.is_true {\n      rw h,\n      exact decidable.is_true rfl\n    }\n  end\n\nnamespace finord\n\n--- finord 0 is empty\nlemma zero_empty : finord 0 \u2192 false := by intros k; cases k\n\n--- Injectivity of the constructors\nlemma fz_not_fs {n : \u2115} : \u2200 {k : finord n}, fs k \u2260 fz :=\n  begin\n    intros k hk,\n    injection hk\n  end\n\n--- `fs` is injective.\nlemma fs_inj {n : \u2115} : function.injective (@finord.fs n) :=\n  begin\n    intros k l h,\n    injection h\n  end\n\n--- Strict comparison on finite ordinals\nattribute [reducible]\nprotected\ndefinition lt : \u2200 {n}, finord n \u2192 finord n \u2192 Prop\n| _ _ fz := false\n| _ fz (fs _) := true\n| _ (fs i) (fs j) := lt i j\n\ninstance {n} : has_lt (finord n) :=\n  has_lt.mk (@finord.lt n)\n\n--- The standard strict orders on finite ordinals are decidable.\nprotected\nlemma lt_decidable : \u2200 {n}, decidable_rel (@finord.lt n)\n| _ i fz := by cases i; exact is_false false.elim\n| _ fz (fs _) := is_true true.intro\n| _ (fs i) (fs j) := lt_decidable i j\n\n--- The standard strict orders on finite ordinals are irreflexive.\nprotected\nlemma lt_irrefl {n} : \u2200 (i : finord n), \u00ac i.lt i :=\n  begin\n    intros i,\n    induction i with n' n' i hi,\n    case finord.fz { dunfold finord.lt; exact false.elim },\n    case finord.fs {\n      dunfold finord.lt,\n      exact hi\n    }\n  end\n\n--- The standard strict orders on finite ordinals are asymmetric.\nprotected\nlemma lt_asymm {n} : \u2200 {i j : finord n}, i.lt j \u2192 \u00ac j.lt i :=\n  begin\n    intros i j hab,\n    induction i with _ n' i hi,\n    case finord.fz {\n      cases j; exact false.elim\n    },\n    case finord.fs {\n      cases j with j' _ j',\n      case finord.fz {\n        dunfold finord.lt at hab,\n        contradiction\n      },\n      case finord.fs {\n        dunfold finord.lt,\n        dunfold finord.lt at hab,\n        exact hi hab\n      }\n    }\n  end\n\n--- With respect to the standard strict orders on finite ordinals, incomparability implies equality.\nprotected\nlemma lt_incomp_eq {n} : \u2200 {i j : finord n}, \u00ac i.lt j \u2192 \u00ac j.lt i \u2192 i=j :=\n  begin\n    intros i j hij hji,\n    induction i with n' n' i hi_ind,\n    case finord.fz {\n      cases j with _ _ j',\n      case finord.fz { trivial },\n      case finord.fs {\n        dunfold finord.lt at hij,\n        exact false.elim (hij true.intro)\n      }\n    },\n    case finord.fs {\n      cases j with _ _ j',\n      case finord.fz {\n        dunfold finord.lt at hji,\n        exact false.elim (hji true.intro)\n      },\n      case finord.fs {\n        apply congr (@rfl _ finord.fs),\n        dunfold finord.lt at hij hji,\n        exact hi_ind hij hji\n      }\n    }\n  end\n\n--- The standard strict orders on finite ordinals are transitive.\nattribute [trans]\nprotected\nlemma lt_trans {n} : \u2200 {i j k : finord n}, i.lt j \u2192 j.lt k \u2192 i.lt k :=\n  begin\n    intros i j k hij hjk,\n    induction k with n' n' k hk_ind,\n    case finord.fz { cases j; dunfold finord.lt at hjk; contradiction },\n    -- In the following, we may assume `k = fs _`\n    cases i with n' n' i',\n    case finord.fz { dunfold finord.lt; trivial },\n    case finord.fs {\n      cases j with n' n' j',\n      case finord.fz { dunfold finord.lt at *; contradiction },\n      case finord.fs { dunfold finord.lt at *; exact hk_ind hij hjk }\n    }\n  end\n\n--- The standard strict orders on finite ordinals are transitive.\nprotected\nlemma lt_trichotomous {n} : \u2200 {i j : finord n}, i.lt j \u2228 i=j \u2228 j.lt i :=\n  begin\n    intros i j,\n    induction i with n' n' i' hi_ind,\n    case finord.fz {\n      cases j with _ _ j',\n      case finord.fz { right; left; refl },\n      case finord.fs { left; dunfold finord.lt; trivial }\n    },\n    case finord.fs {\n      cases j with _ _ j',\n      case finord.fz { right; right; simp [finord.lt] },\n      case finord.fs {\n        dunfold finord.lt,\n        refine or.imp id (or.imp (congr rfl) id) hi_ind,\n      }\n    }\n  end\n\ninstance {n} : is_irrefl (finord n) finord.lt :=\n  is_irrefl.mk (@finord.lt_irrefl n)\ninstance {n} : is_asymm (finord n) finord.lt :=\n  is_asymm.mk (@finord.lt_asymm n)\ninstance {n} : is_trans (finord n) finord.lt :=\n  is_trans.mk (@finord.lt_trans n)\ninstance {n} : is_strict_order (finord n) finord.lt :=\n  { /- auto-generated -/ }\ninstance {n} : is_incomp_trans (finord n) finord.lt :=\n  begin\n    constructor,\n    intros i j k hij hjk,\n    have : i=k,\n      by calc\n        i = j : finord.lt_incomp_eq hij.left hij.right\n        ... = k : finord.lt_incomp_eq hjk.left hjk.right,\n    rw [this],\n    split; exact finord.lt_irrefl k\n  end\ninstance {n} : is_strict_weak_order (finord n) finord.lt :=\n  { /- auto-generated -/ }\ninstance {n} : is_trichotomous (finord n) finord.lt :=\n  is_trichotomous.mk (@finord.lt_trichotomous n)\ninstance {n} : is_strict_total_order (finord n) finord.lt :=\n  { /- auto-generated -/ }\n\n--- Injection into the successor ordinal that preserves element representation; e.g. fz \u21a6 fz and fs n \u21a6 fs n\ndefinition inject_succ : \u03a0 {m}, finord m \u2192 finord m.succ\n| _ fz := fz\n| _ (fs k) := fs (inject_succ k)\n\n--- Iterated version of injection\ndefinition inject {m : \u2115} : \u03a0 (k : \u2115), finord m \u2192 finord (m+k)\n| 0 := id\n| 1 := inject_succ -- this assures the definitional equality inject 1 = inject_succ\n| (k+2) := inject_succ \u2218 inject (k+1)\n\n--- Convert into fin\ndefinition to_fin : \u03a0 {n : \u2115}, finord n \u2192 fin n\n| 0 k := (zero_empty k).elim\n| (n+1) fz := \u27e80,nat.zero_lt_succ n\u27e9\n| (n+1) (fs k) := (to_fin k).succ\n\n--- to_fin transforms finord.fs into fin.succ\ntheorem to_fs_succ : \u2200 {n : \u2115} (k : finord n), to_fin k.fs = (to_fin k).succ :=\n  begin\n    intros,\n    cases k with k n k,\n    case finord.fz {\n      dunfold to_fin,\n      refl\n    },\n    case finord.fs {\n      dunfold to_fin,\n      refl\n    }\n  end\n\n--- Convert from fin\ndefinition from_fin : \u03a0 {n : \u2115}, fin n \u2192 finord n\n| 0 \u27e8k,hk\u27e9 := (nat.not_lt_zero k hk).elim\n| (n+1) \u27e80,_\u27e9 := fz\n| (n+1) \u27e8k+1,hk\u27e9 := fs (from_fin \u27e8k, nat.lt_of_succ_lt_succ hk\u27e9)\n\n--- from_fin transforms fin.succ into finord.fs\ntheorem from_succ_fs : \u2200 {n : \u2115} (k : fin n), from_fin k.succ = (from_fin k).fs :=\n  begin\n    intros n k,\n    cases k with kv hkv,\n    dsimp [fin.succ,from_fin],\n    refl\n  end\n\ntheorem fromto_id {n : \u2115} (k : finord n) : from_fin (to_fin k) = k :=\n  begin\n    induction n with n hind,\n    case nat.zero {\n      cases k,\n    },\n    case nat.succ {\n      cases k with _ _ k,\n      case finord.fz {\n        dsimp [finord.to_fin, finord.from_fin],\n        refl\n      },\n      case finord.fs {\n        dunfold finord.to_fin,\n        by calc\n          from_fin k.to_fin.succ\n              = (from_fin k.to_fin).fs : from_succ_fs _\n          ... = k.fs : by rw [hind k]\n      }\n    }\n  end\n\ntheorem tofrom_id {n : \u2115} (k : fin n) : to_fin (from_fin k) = k :=\n  begin\n    cases k with kv hkv,\n    apply subtype.eq; dsimp [subtype.val],\n    revert kv hkv,\n    induction n with n hind; intros,\n    case nat.zero {\n      exact (nat.not_lt_zero kv hkv).elim\n    },\n    case nat.succ {\n      cases kv with kv,\n      case nat.zero {\n        dsimp [from_fin, to_fin, subtype.val],\n        refl\n      },\n      case nat.succ {\n        dsimp [from_fin, to_fin],\n        have : \u2200 (m : fin n), m.succ.val = m.val.succ :=\n          by intros; cases m; trivial,\n        rw [this],\n        suffices : (from_fin \u27e8kv, _\u27e9).to_fin.val = kv,\n          by rw [this],\n        apply hind\n      }\n    }\n  end\n\n--- The number of elements that satisfy a decidable predicator\ndefinition card_of : \u03a0 {n : \u2115} (p : finord n \u2192 Prop) [decidable_pred p], \u2115\n| 0 _ _ := 0\n| (k+1) p h :=\n  let i := @card_of k (p \u2218 finord.fs) (\u03bb x, h (fs x))\n  in @ite _ (p finord.fz) (h _) (1+i) i\n\nend finord\n", "meta": {"author": "Junology", "repo": "groth-lean", "sha": "5aa1ba624cd0f5145f63fa86130f99b85bbbcac2", "save_path": "github-repos/lean/Junology-groth-lean", "path": "github-repos/lean/Junology-groth-lean/groth-lean-5aa1ba624cd0f5145f63fa86130f99b85bbbcac2/src/data/finord.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.7931059560743423, "lm_q1q2_score": 0.7174837255155299}}
{"text": "universe u\nconstant vec : Type u \u2192 \u2115 \u2192 Type u\n\nnamespace vec\n  constant empty : \u03a0 \u03b1 : Type u, vec \u03b1 0\n  constant cons :\n    \u03a0 {\u03b1 : Type u} {n : \u2115}, \u03b1 \u2192 vec \u03b1 n \u2192 vec \u03b1 (n + 1)\n  constant append :\n    \u03a0 {\u03b1 : Type u} {n m : \u2115},  vec \u03b1 m \u2192 vec \u03b1 n \u2192 vec \u03b1 (n + m)\nend vec\n\n#check vec\n\n-- Above, we used the example vec \u03b1 n for vectors of elements of type \u03b1 of\n-- length n. Declare a constant vec_add that could represent a function\n-- that adds two vectors of natural numbers of the same length, and a constant\n-- vec_reverse that can represent a function that reverses its argument.\n-- Use implicit arguments for parameters that can be inferred. Declare some\n-- variables and check some expressions involving the constants that you have\n-- declared.\nconstant vec_add : \u03a0 {\u03b1 : Type u} {n : \u2115}, vec \u03b1 n \u2192 vec \u03b1 n \u2192 vec \u03b1 n\n#reduce vec.cons 456 (vec.cons 123 (vec.empty _))\n#check vec_add (vec.cons 456 (vec.cons 123 (vec.empty _))) (vec.cons 456 (vec.cons 123 (vec.empty _)))\n\nconstant vec_reverse : \u03a0 {\u03b1 : Type u} {n : \u2115}, vec \u03b1 n \u2192 vec \u03b1 n\n#check vec_reverse (vec.cons 456 (vec.cons 123 (vec.empty _)))\n\n-- Similarly, declare a constant matrix so that matrix \u03b1 m n could represent the\n-- type of m by n matrices. Declare some constants to represent functions on\n-- this type, such as matrix addition and multiplication, and (using vec)\n-- multiplication of a matrix by a vector. Once again, declare some variables\n-- and check some expressions involving the constants that you have declared.\n\nconstant matrix : Type u \u2192 \u2115 \u2192 \u2115 \u2192 Type u\nconstant matrix_add : \u03a0 {\u03b1 : Type u} {n m : \u2115}, matrix \u03b1 n m \u2192 matrix \u03b1 n m\nconstant matrix_mul : \u03a0 {\u03b1 : Type u} {n m k : \u2115}, matrix \u03b1 n m \u2192 matrix \u03b1 m k \u2192 matrix \u03b1 n k\nconstant matrix_vec_mul : \u03a0 {\u03b1 : Type u} {n m : \u2115}, matrix \u03b1 n m \u2192 vec \u03b1 m \u2192 vec \u03b1 n\n", "meta": {"author": "hyponymous", "repo": "theorem-proving-in-lean-solutions", "sha": "a95320ae81c90c1b15da04574602cd378794400d", "save_path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions", "path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions/theorem-proving-in-lean-solutions-a95320ae81c90c1b15da04574602cd378794400d/2-vec-matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7174827222433151}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Yury Kudryashov\n-/\nimport algebra.group.prod\nimport algebra.group.type_tags\nimport algebra.group.pi\nimport algebra.pointwise\nimport data.equiv.basic\nimport data.set.finite\n\n/-!\n# Torsors of additive group actions\n\nThis file defines torsors of additive group actions.\n\n## Notations\n\nThe group elements are referred to as acting on points.  This file\ndefines the notation `+\u1d65` for adding a group element to a point and\n`-\u1d65` for subtracting two points to produce a group element.\n\n## Implementation notes\n\nAffine spaces are the motivating example of torsors of additive group actions. It may be appropriate\nto refactor in terms of the general definition of group actions, via `to_additive`, when there is a\nuse for multiplicative torsors (currently mathlib only develops the theory of group actions for\nmultiplicative group actions).\n\n## Notations\n\n* `v +\u1d65 p` is a notation for `has_vadd.vadd`, the left action of an additive monoid;\n\n* `p\u2081 -\u1d65 p\u2082` is a notation for `has_vsub.vsub`, difference between two points in an additive torsor\n  as an element of the corresponding additive group;\n\n## References\n\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n* https://en.wikipedia.org/wiki/Affine_space\n\n-/\n\n/-- Type class for the `-\u1d65` notation. -/\nclass has_vsub (G : out_param Type*) (P : Type*) :=\n(vsub : P \u2192 P \u2192 G)\n\ninfix ` -\u1d65 `:65 := has_vsub.vsub\n\n/-- An `add_torsor G P` gives a structure to the nonempty type `P`,\nacted on by an `add_group G` with a transitive and free action given\nby the `+\u1d65` operation and a corresponding subtraction given by the\n`-\u1d65` operation. In the case of a vector space, it is an affine\nspace. -/\nclass add_torsor (G : out_param Type*) (P : Type*) [out_param $ add_group G]\n  extends add_action G P, has_vsub G P :=\n[nonempty : nonempty P]\n(vsub_vadd' : \u2200 (p1 p2 : P), (p1 -\u1d65 p2 : G) +\u1d65 p2 = p1)\n(vadd_vsub' : \u2200 (g : G) (p : P), g +\u1d65 p -\u1d65 p = g)\n\nattribute [instance, priority 100, nolint dangerous_instance] add_torsor.nonempty\nattribute [nolint dangerous_instance] add_torsor.to_has_vsub\n\n/-- An `add_group G` is a torsor for itself. -/\n@[nolint instance_priority]\ninstance add_group_is_add_torsor (G : Type*) [add_group G] :\n  add_torsor G G :=\n{ vsub := has_sub.sub,\n  vsub_vadd' := sub_add_cancel,\n  vadd_vsub' := add_sub_cancel }\n\n/-- Simplify subtraction for a torsor for an `add_group G` over\nitself. -/\n@[simp] lemma vsub_eq_sub {G : Type*} [add_group G] (g1 g2 : G) : g1 -\u1d65 g2 = g1 - g2 :=\nrfl\n\nsection general\n\nvariables {G : Type*} {P : Type*} [add_group G] [T : add_torsor G P]\ninclude T\n\n/-- Adding the result of subtracting from another point produces that\npoint. -/\n@[simp] lemma vsub_vadd (p1 p2 : P) : p1 -\u1d65 p2 +\u1d65 p2 = p1 :=\nadd_torsor.vsub_vadd' p1 p2\n\n/-- Adding a group element then subtracting the original point\nproduces that group element. -/\n@[simp] lemma vadd_vsub (g : G) (p : P) : g +\u1d65 p -\u1d65 p = g :=\nadd_torsor.vadd_vsub' g p\n\n/-- If the same point added to two group elements produces equal\nresults, those group elements are equal. -/\nlemma vadd_right_cancel {g1 g2 : G} (p : P) (h : g1 +\u1d65 p = g2 +\u1d65 p) : g1 = g2 :=\nby rw [\u2190vadd_vsub g1, h, vadd_vsub]\n\n@[simp] lemma vadd_right_cancel_iff {g1 g2 : G} (p : P) :  g1 +\u1d65 p = g2 +\u1d65 p \u2194 g1 = g2 :=\n\u27e8vadd_right_cancel p, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Adding a group element to the point `p` is an injective\nfunction. -/\nlemma vadd_right_injective (p : P) : function.injective ((+\u1d65 p) : G \u2192 P) :=\n\u03bb g1 g2, vadd_right_cancel p\n\n/-- Adding a group element to a point, then subtracting another point,\nproduces the same result as subtracting the points then adding the\ngroup element. -/\nlemma vadd_vsub_assoc (g : G) (p1 p2 : P) : g +\u1d65 p1 -\u1d65 p2 = g + (p1 -\u1d65 p2) :=\nbegin\n  apply vadd_right_cancel p2,\n  rw [vsub_vadd, add_vadd, vsub_vadd]\nend\n\n/-- Subtracting a point from itself produces 0. -/\n@[simp] lemma vsub_self (p : P) : p -\u1d65 p = (0 : G) :=\nby rw [\u2190zero_add (p -\u1d65 p), \u2190vadd_vsub_assoc, vadd_vsub]\n\n/-- If subtracting two points produces 0, they are equal. -/\nlemma eq_of_vsub_eq_zero {p1 p2 : P} (h : p1 -\u1d65 p2 = (0 : G)) : p1 = p2 :=\nby rw [\u2190vsub_vadd p1 p2, h, zero_vadd]\n\n/-- Subtracting two points produces 0 if and only if they are\nequal. -/\n@[simp] lemma vsub_eq_zero_iff_eq {p1 p2 : P} : p1 -\u1d65 p2 = (0 : G) \u2194 p1 = p2 :=\niff.intro eq_of_vsub_eq_zero (\u03bb h, h \u25b8 vsub_self _)\n\n/-- Cancellation adding the results of two subtractions. -/\n@[simp] lemma vsub_add_vsub_cancel (p1 p2 p3 : P) : p1 -\u1d65 p2 + (p2 -\u1d65 p3) = (p1 -\u1d65 p3) :=\nbegin\n  apply vadd_right_cancel p3,\n  rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd]\nend\n\n/-- Subtracting two points in the reverse order produces the negation\nof subtracting them. -/\n@[simp] lemma neg_vsub_eq_vsub_rev (p1 p2 : P) : -(p1 -\u1d65 p2) = (p2 -\u1d65 p1) :=\nbegin\n  refine neg_eq_of_add_eq_zero (vadd_right_cancel p1 _),\n  rw [vsub_add_vsub_cancel, vsub_self],\nend\n\n/-- Subtracting the result of adding a group element produces the same result\nas subtracting the points and subtracting that group element. -/\nlemma vsub_vadd_eq_vsub_sub (p1 p2 : P) (g : G) : p1 -\u1d65 (g +\u1d65 p2) = (p1 -\u1d65 p2) - g :=\nby rw [\u2190add_right_inj (p2 -\u1d65 p1 : G), vsub_add_vsub_cancel, \u2190neg_vsub_eq_vsub_rev, vadd_vsub,\n       \u2190add_sub_assoc, \u2190neg_vsub_eq_vsub_rev, neg_add_self, zero_sub]\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_right (p1 p2 p3 : P) :\n  (p1 -\u1d65 p3) - (p2 -\u1d65 p3) = (p1 -\u1d65 p2) :=\nby rw [\u2190vsub_vadd_eq_vsub_sub, vsub_vadd]\n\n/-- Convert between an equality with adding a group element to a point\nand an equality of a subtraction of two points with a group\nelement. -/\nlemma eq_vadd_iff_vsub_eq (p1 : P) (g : G) (p2 : P) : p1 = g +\u1d65 p2 \u2194 p1 -\u1d65 p2 = g :=\n\u27e8\u03bb h, h.symm \u25b8 vadd_vsub _ _, \u03bb h, h \u25b8 (vsub_vadd _ _).symm\u27e9\n\nlemma vadd_eq_vadd_iff_neg_add_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 - v\u2081 + v\u2082 = p\u2081 -\u1d65 p\u2082 :=\nby rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, \u2190 add_right_inj (-v\u2081), neg_add_cancel_left, eq_comm]\n\nnamespace set\n\ninstance has_vsub : has_vsub (set G) (set P) := \u27e8set.image2 (-\u1d65)\u27e9\n\nsection vsub\n\nvariables (s t : set P)\n\n@[simp] lemma vsub_empty : s -\u1d65 \u2205 = \u2205 := set.image2_empty_right\n\n@[simp] lemma empty_vsub : \u2205 -\u1d65 s = \u2205 := set.image2_empty_left\n\n@[simp] lemma singleton_vsub (p : P) : {p} -\u1d65 s = ((-\u1d65) p) '' s :=\nimage2_singleton_left\n\n@[simp] lemma vsub_singleton (p : P) : s -\u1d65 {p} = (-\u1d65 p) '' s :=\nimage2_singleton_right\n\n@[simp] lemma singleton_vsub_self (p : P) : ({p} : set P) -\u1d65 {p} = {(0:G)} :=\nby simp\n\nvariables {s t}\n\n/-- `vsub` of a finite set is finite. -/\nlemma finite.vsub (hs : finite s) (ht : finite t) : finite (s -\u1d65 t) :=\nhs.image2 _ ht\n\n/-- Each pairwise difference is in the `vsub` set. -/\nlemma vsub_mem_vsub {ps pt : P} (hs : ps \u2208 s) (ht : pt \u2208 t) :\n  (ps -\u1d65 pt) \u2208 s -\u1d65 t :=\nmem_image2_of_mem hs ht\n\n/-- `s -\u1d65 t` is monotone in both arguments. -/\n@[mono] lemma vsub_subset_vsub {s' t' : set P} (hs : s \u2286 s') (ht : t \u2286 t') :\n  s -\u1d65 t \u2286 s' -\u1d65 t' :=\nimage2_subset hs ht\n\nlemma vsub_self_mono (h : s \u2286 t) : s -\u1d65 s \u2286 t -\u1d65 t := vsub_subset_vsub h h\n\nlemma vsub_subset_iff {u : set G} : s -\u1d65 t \u2286 u \u2194 \u2200 (x \u2208 s) (y \u2208 t), x -\u1d65 y \u2208 u :=\nimage2_subset_iff\n\nend vsub\n\ninstance add_action : add_action (set G) (set P) :=\n{ vadd := set.image2 (+\u1d65),\n  zero_vadd := \u03bb s, by simp [\u2190 singleton_zero],\n  add_vadd := \u03bb s t p, by { apply image2_assoc, intros, apply add_vadd } }\n\nvariables {s s' : set G} {t t' : set P}\n\n@[mono] lemma vadd_subset_vadd (hs : s \u2286 s') (ht : t \u2286 t') : s +\u1d65 t \u2286 s' +\u1d65 t' :=\nimage2_subset hs ht\n\n@[simp] lemma vadd_singleton (s : set G) (p : P) : s +\u1d65 {p} = (+\u1d65 p) '' s := image2_singleton_right\n\n@[simp] lemma singleton_vadd (v : G) (s : set P) : ({v} : set G) +\u1d65 s = ((+\u1d65) v) '' s :=\nimage2_singleton_left\n\nlemma finite.vadd (hs : finite s) (ht : finite t) : finite (s +\u1d65 t) := hs.image2 _ ht\n\nend set\n\n@[simp] lemma vadd_vsub_vadd_cancel_right (v\u2081 v\u2082 : G) (p : P) :\n  (v\u2081 +\u1d65 p) -\u1d65 (v\u2082 +\u1d65 p) = v\u2081 - v\u2082 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero]\n\n/-- If the same point subtracted from two points produces equal\nresults, those points are equal. -/\nlemma vsub_left_cancel {p1 p2 p : P} (h : p1 -\u1d65 p = p2 -\u1d65 p) : p1 = p2 :=\nby rwa [\u2190sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h\n\n/-- The same point subtracted from two points produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_left_cancel_iff {p1 p2 p : P} : (p1 -\u1d65 p) = p2 -\u1d65 p \u2194 p1 = p2 :=\n\u27e8vsub_left_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting the point `p` is an injective function. -/\nlemma vsub_left_injective (p : P) : function.injective ((-\u1d65 p) : P \u2192 G) :=\n\u03bb p2 p3, vsub_left_cancel\n\n/-- If subtracting two points from the same point produces equal\nresults, those points are equal. -/\nlemma vsub_right_cancel {p1 p2 p : P} (h : p -\u1d65 p1 = p -\u1d65 p2) : p1 = p2 :=\nbegin\n  refine vadd_left_cancel (p -\u1d65 p2) _,\n  rw [vsub_vadd, \u2190 h, vsub_vadd]\nend\n\n/-- Subtracting two points from the same point produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_right_cancel_iff {p1 p2 p : P} : p -\u1d65 p1 = p -\u1d65 p2 \u2194 p1 = p2 :=\n\u27e8vsub_right_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting a point from the point `p` is an injective\nfunction. -/\nlemma vsub_right_injective (p : P) : function.injective ((-\u1d65) p : P \u2192 G) :=\n\u03bb p2 p3, vsub_right_cancel\n\nend general\n\nsection comm\n\nvariables {G : Type*} {P : Type*} [add_comm_group G] [add_torsor G P]\n\ninclude G\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_left (p1 p2 p3 : P) :\n  (p3 -\u1d65 p2) - (p3 -\u1d65 p1) = (p1 -\u1d65 p2) :=\nby rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]\n\n@[simp] lemma vadd_vsub_vadd_cancel_left (v : G) (p1 p2 : P) :\n  (v +\u1d65 p1) -\u1d65 (v +\u1d65 p2) = p1 -\u1d65 p2 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel']\n\nlemma vsub_vadd_comm (p1 p2 p3 : P) : (p1 -\u1d65 p2 : G) +\u1d65 p3 = p3 -\u1d65 p2 +\u1d65 p1 :=\nbegin\n  rw [\u2190@vsub_eq_zero_iff_eq G, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub],\n  simp\nend\n\nlemma vadd_eq_vadd_iff_sub_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 v\u2082 - v\u2081 = p\u2081 -\u1d65 p\u2082 :=\nby rw [vadd_eq_vadd_iff_neg_add_eq_vsub, neg_add_eq_sub]\n\nlemma vsub_sub_vsub_comm (p\u2081 p\u2082 p\u2083 p\u2084 : P) :\n  (p\u2081 -\u1d65 p\u2082) - (p\u2083 -\u1d65 p\u2084) = (p\u2081 -\u1d65 p\u2083) - (p\u2082 -\u1d65 p\u2084) :=\nby rw [\u2190 vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub]\n\nend comm\n\nnamespace prod\n\nvariables {G : Type*} {P : Type*} {G' : Type*} {P' : Type*} [add_group G] [add_group G']\n  [add_torsor G P] [add_torsor G' P']\n\ninstance : add_torsor (G \u00d7 G') (P \u00d7 P') :=\n{ vadd := \u03bb v p, (v.1 +\u1d65 p.1, v.2 +\u1d65 p.2),\n  zero_vadd := \u03bb p, by simp,\n  add_vadd := by simp [add_vadd],\n  vsub := \u03bb p\u2081 p\u2082, (p\u2081.1 -\u1d65 p\u2082.1, p\u2081.2 -\u1d65 p\u2082.2),\n  nonempty := prod.nonempty,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, show (p\u2081.1 -\u1d65 p\u2082.1 +\u1d65 p\u2082.1, _) = p\u2081, by simp,\n  vadd_vsub' := \u03bb v p, show (v.1 +\u1d65 p.1 -\u1d65 p.1, v.2 +\u1d65 p.2 -\u1d65 p.2)  =v, by simp }\n\n@[simp] lemma fst_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).1 = v.1 +\u1d65 p.1 := rfl\n@[simp] lemma snd_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).2 = v.2 +\u1d65 p.2 := rfl\n@[simp] lemma mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') :\n  (v, v') +\u1d65 (p, p') = (v +\u1d65 p, v' +\u1d65 p') := rfl\n\n@[simp] lemma fst_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').1 = p\u2081.1 -\u1d65 p\u2082.1 := rfl\n@[simp] lemma snd_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').2 = p\u2081.2 -\u1d65 p\u2082.2 := rfl\n@[simp] lemma mk_vsub_mk (p\u2081 p\u2082 : P) (p\u2081' p\u2082' : P') :\n  ((p\u2081, p\u2081') -\u1d65 (p\u2082, p\u2082') : G \u00d7 G') = (p\u2081 -\u1d65 p\u2082, p\u2081' -\u1d65 p\u2082') := rfl\n\nend prod\n\nnamespace pi\n\nuniverses u v w\nvariables {I : Type u} {fg : I \u2192 Type v} [\u2200 i, add_group (fg i)] {fp : I \u2192 Type w}\n\nopen add_action add_torsor\n\n/-- A product of `add_torsor`s is an `add_torsor`. -/\ninstance [T : \u2200 i, add_torsor (fg i) (fp i)] : add_torsor (\u03a0 i, fg i) (\u03a0 i, fp i) :=\n{ vadd := \u03bb g p, \u03bb i, g i +\u1d65 p i,\n  zero_vadd := \u03bb p, funext $ \u03bb i, zero_vadd (fg i) (p i),\n  add_vadd := \u03bb g\u2081 g\u2082 p, funext $ \u03bb i, add_vadd (g\u2081 i) (g\u2082 i) (p i),\n  vsub := \u03bb p\u2081 p\u2082, \u03bb i, p\u2081 i -\u1d65 p\u2082 i,\n  nonempty := \u27e8\u03bb i, classical.choice (T i).nonempty\u27e9,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, funext $ \u03bb i, vsub_vadd (p\u2081 i) (p\u2082 i),\n  vadd_vsub' := \u03bb g p, funext $ \u03bb i, vadd_vsub (g i) (p i) }\n\n/-- Addition in a product of `add_torsor`s. -/\n@[simp] lemma vadd_apply [T : \u2200 i, add_torsor (fg i) (fp i)] (x : \u03a0 i, fg i) (y : \u03a0 i, fp i)\n  {i : I} : (x +\u1d65 y) i = x i +\u1d65 y i\n:= rfl\n\nend pi\n\nnamespace equiv\n\nvariables {G : Type*} {P : Type*} [add_group G] [add_torsor G P]\n\ninclude G\n\n/-- `v \u21a6 v +\u1d65 p` as an equivalence. -/\ndef vadd_const (p : P) : G \u2243 P :=\n{ to_fun := \u03bb v, v +\u1d65 p,\n  inv_fun := \u03bb p', p' -\u1d65 p,\n  left_inv := \u03bb v, vadd_vsub _ _,\n  right_inv := \u03bb p', vsub_vadd _ _ }\n\n@[simp] lemma coe_vadd_const (p : P) : \u21d1(vadd_const p) = \u03bb v, v+\u1d65 p := rfl\n\n@[simp] lemma coe_vadd_const_symm (p : P) : \u21d1(vadd_const p).symm = \u03bb p', p' -\u1d65 p := rfl\n\n/-- `p' \u21a6 p -\u1d65 p'` as an equivalence. -/\ndef const_vsub (p : P) : P \u2243 G :=\n{ to_fun := (-\u1d65) p,\n  inv_fun := \u03bb v, -v +\u1d65 p,\n  left_inv := \u03bb p', by simp,\n  right_inv := \u03bb v, by simp [vsub_vadd_eq_vsub_sub] }\n\n@[simp] lemma coe_const_vsub (p : P) : \u21d1(const_vsub p) = (-\u1d65) p := rfl\n\n@[simp] lemma coe_const_vsub_symm (p : P) : \u21d1(const_vsub p).symm = \u03bb v, -v +\u1d65 p := rfl\n\nvariables (P)\n\n/-- The permutation given by `p \u21a6 v +\u1d65 p`. -/\ndef const_vadd (v : G) : equiv.perm P :=\n{ to_fun := (+\u1d65) v,\n  inv_fun := (+\u1d65) (-v),\n  left_inv := \u03bb p, by simp [vadd_vadd],\n  right_inv := \u03bb p, by simp [vadd_vadd] }\n\n@[simp] lemma coe_const_vadd (v : G) : \u21d1(const_vadd P v) = (+\u1d65) v := rfl\n\nvariable (G)\n\n@[simp] lemma const_vadd_zero : const_vadd P (0:G) = 1 := ext $ zero_vadd G\n\nvariable {G}\n\n@[simp] lemma const_vadd_add (v\u2081 v\u2082 : G) :\n  const_vadd P (v\u2081 + v\u2082) = const_vadd P v\u2081 * const_vadd P v\u2082 :=\next $ add_vadd v\u2081 v\u2082\n\n/-- `equiv.const_vadd` as a homomorphism from `multiplicative G` to `equiv.perm P` -/\ndef const_vadd_hom : multiplicative G \u2192* equiv.perm P :=\n{ to_fun := \u03bb v, const_vadd P v.to_add,\n  map_one' := const_vadd_zero G P,\n  map_mul' := const_vadd_add P }\n\nvariable {P}\n\nopen function\n\n/-- Point reflection in `x` as a permutation. -/\ndef point_reflection (x : P) : perm P := (const_vsub x).trans (vadd_const x)\n\nlemma point_reflection_apply (x y : P) : point_reflection x y = x -\u1d65 y +\u1d65 x := rfl\n\n@[simp] lemma point_reflection_symm (x : P) : (point_reflection x).symm = point_reflection x :=\next $ by simp [point_reflection]\n\n@[simp] lemma point_reflection_self (x : P) : point_reflection x x = x := vsub_vadd _ _\n\nlemma point_reflection_involutive (x : P) : involutive (point_reflection x : P \u2192 P) :=\n\u03bb y, (equiv.apply_eq_iff_eq_symm_apply _).2 $ by rw point_reflection_symm\n\n/-- `x` is the only fixed point of `point_reflection x`. This lemma requires\n`x + x = y + y \u2194 x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/\nlemma point_reflection_fixed_iff_of_injective_bit0 {x y : P} (h : injective (bit0 : G \u2192 G)) :\n  point_reflection x y = y \u2194 y = x :=\nby rw [point_reflection_apply, eq_comm, eq_vadd_iff_vsub_eq, \u2190 neg_vsub_eq_vsub_rev,\n  neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero, h.eq_iff, vsub_eq_zero_iff_eq, eq_comm]\n\nomit G\n\nlemma injective_point_reflection_left_of_injective_bit0 {G P : Type*} [add_comm_group G]\n  [add_torsor G P] (h : injective (bit0 : G \u2192 G)) (y : P) :\n  injective (\u03bb x : P, point_reflection x y) :=\n\u03bb x\u2081 x\u2082 (hy : point_reflection x\u2081 y = point_reflection x\u2082 y),\n  by rwa [point_reflection_apply, point_reflection_apply, vadd_eq_vadd_iff_sub_eq_vsub,\n    vsub_sub_vsub_cancel_right, \u2190 neg_vsub_eq_vsub_rev, neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero,\n    h.eq_iff, vsub_eq_zero_iff_eq] at hy\n\nend equiv\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/add_torsor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.717482722243315}}
{"text": "variable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\n  \u27e8\n    \u03bb h : \u2200 x, p x \u2227 q x =>\n      \u27e8 \u03bb x : \u03b1 => (h x).left,\n        \u03bb x : \u03b1 => (h x).right \u27e9,\n    \u03bb h : (\u2200 x, p x) \u2227 (\u2200 x, q x) =>\n      \u03bb x : \u03b1 =>\n        \u27e8 h.left x , h.right x\u27e9\n  \u27e9\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\n  fun h1 : (\u2200 x, p x \u2192 q x) =>\n    fun h2 : (\u2200 x, p x) =>\n      fun x : \u03b1 => (h1 x) (h2 x)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\n  fun h : (\u2200 x, p x) \u2228 (\u2200 x, q x) =>\n    fun x : \u03b1 =>\n      h.elim\n        (fun hl : (\u2200 x, p x) =>\n          Or.inl (hl x))\n        (fun hr : (\u2200 x, q x) =>\n          Or.inr (hr x))\n\nvariable (r : Prop)\n\nopen Classical\n\nexample : \u03b1 \u2192 ((\u2200 _ : \u03b1, r) \u2194 r) :=\n  fun a : \u03b1 =>\n    \u27e8\n      fun x : (\u2200 _ : \u03b1, r) => x a,\n      fun y : r =>\n        fun _ : \u03b1 => y\n    \u27e9\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r :=\n  \u27e8\n    fun h : (\u2200 x, p x \u2228 r) =>\n      show (\u2200 x, p x) \u2228 r from\n      Or.elim (em r)\n        (fun hr : r => Or.inr hr)\n        (fun hnr : \u00acr =>\n          Or.inl fun ha : \u03b1 =>\n            Or.elim (h ha)\n              (fun hpx : (p ha) => hpx)\n              (fun hr : r => absurd hr hnr)),\n    fun h : (\u2200 x, p x) \u2228 r =>\n      show (\u2200 x, p x \u2228 r) from\n      fun a : \u03b1 =>\n        Or.elim h\n          (fun hl : (\u2200 x, p x) => Or.inl (hl a))\n          (fun hr : r => Or.inr hr)\n  \u27e9\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\n  \u27e8\n    \u03bb h : (\u2200 x, r \u2192 p x) =>\n      show (r \u2192 \u2200 x, p x) from\n      \u03bb hr : r =>\n        \u03bb ha : \u03b1 =>\n          h ha hr,\n    \u03bb h : r \u2192 \u2200 x, p x =>\n      show (\u2200 x, r \u2192 p x) from\n      \u03bb ha : \u03b1 =>\n        \u03bb hr : r =>\n          h hr ha\n  \u27e9\n\nvariable (men : Type) (barber : men)\nvariable (shaves : men \u2192 men \u2192 Prop)\n\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : False :=\n  have h2 : shaves barber barber \u2194 \u00ac shaves barber barber := h barber\n  Or.elim (em (shaves barber barber))\n    (fun h3 : shaves barber barber =>\n      (h2.mp h3) h3)\n    (fun h3 : \u00ac(shaves barber barber) =>\n      h3 (h2.mpr h3))\n\ndef divides (n m : Nat) : Prop :=\n  \u2203 (k : Nat), k * n = m\n\ndef even (n : Nat) : Prop :=\n  divides 2 n\n\ndef prime (n : Nat) : Prop :=\n  \u2200 (k : Nat), k != n \u2227 k != n \u2192 \u00ac(divides k n)\n\ndef infinitely_many_primes : Prop :=\n  \u2200 (n : Nat), \u2203 (k : Nat), k > n \u2227 prime k\n\ndef Fermat_prime (n : Nat) : Prop :=\n  prime n \u2227 \u2203 (k : Nat), (2^k + 1= n)\n\ndef infinitely_many_Fermat_primes : Prop :=\n  \u2200 (n : Nat), \u2203 (k : Nat), k > n \u2227 Fermat_prime k\n\ndef goldbach_conjecture : Prop :=\n  \u2200 (n : Nat), n > 2 \u2227 even n \u2192 \u2203 (p q : Nat), prime p \u2227 prime q \u2227 p + q = n\n\ndef Goldbach's_weak_conjecture : Prop :=\n  \u2200 (n : Nat), n > 2 \u2227 even n \u2192\n    \u2203 (p q r : Nat), prime p \u2227 prime q \u2227 prime r \u2227\n      p + q + r = n\n\ndef Fermat's_last_theorem : Prop :=\n  \u2200 (n : Nat), n > 2 \u2192\n    \u00ac\u2203 (a b c : Nat), a^n + b^n = c^n\n\nexample : (\u2203 _ : \u03b1, r) \u2192 r :=\n  fun h : (\u2203 _ : \u03b1, r) =>\n    h.elim (fun _: \u03b1 => fun hw: r => hw)\n\nexample (a : \u03b1) : r \u2192 (\u2203 _ : \u03b1, r) :=\n  fun h: r =>\n    Exists.intro a h\n\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r :=\n  Iff.intro\n    (fun h: (\u2203 x, p x \u2227 r) =>\n      h.elim (fun w : \u03b1 => fun hw : p w \u2227 r =>\n        \u27e8Exists.intro w (hw).left, (hw).right\u27e9))\n    (fun \u27e8\u27e8w, hw\u27e9, hr\u27e9 =>\n      \u27e8w, hw, hr\u27e9)\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\n  Iff.intro\n    (fun h : (\u2203 x, p x \u2228 q x) =>\n      match h with\n      | \u27e8w, hw\u27e9 => Or.elim hw\n        (fun hpw : p w => Or.inl \u27e8w, hpw\u27e9)\n        (fun hqw : q w => Or.inr \u27e8w, hqw\u27e9))\n    (fun h : (\u2203 x, p x) \u2228 (\u2203 x, q x) =>\n      Or.elim h\n        (fun h1 : (\u2203 x, p x) =>\n          let \u27e8w, h1w\u27e9 := h1\n          \u27e8w, Or.inl h1w\u27e9)\n        (fun h1 : (\u2203 x, q x) =>\n          let \u27e8w, h1w\u27e9 := h1\n          \u27e8w, Or.inr h1w\u27e9))\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) :=\n  Iff.intro\n    (fun h: (\u2200 x, p x) =>\n      fun h2: (\u2203 x, \u00ac p x) =>\n        let \u27e8w, wh2\u27e9 := h2\n        wh2 (h w))\n    (fun h: \u00ac(\u2203 x, \u00ac p x) =>\n      fun z: \u03b1 =>\n        Or.elim (em (p z))\n          (fun hpz: p z => hpz)\n          (fun hnpz: \u00ac(p z) => absurd \u27e8z, hnpz\u27e9 h))\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) :=\n  Iff.intro\n    (fun h: (\u2203 x, p x) =>\n      let \u27e8w, wh\u27e9 := h\n      fun h2: (\u2200 x, \u00ac p x) =>\n        (h2 w) wh)\n    (fun h: \u00ac(\u2200 x, \u00ac p x) =>\n      byContradiction\n        fun h2 : \u00ac(\u2203 x, p x) =>\n          h fun x : \u03b1 =>\n            fun hx : p x =>\n              h2 \u27e8x, hx\u27e9)\n\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) :=\n  Iff.intro\n    (fun h: (\u00ac \u2203 x, p x) =>\n      fun x : \u03b1 =>\n        fun hx : p x =>\n          h \u27e8x, hx\u27e9 )\n    (fun h: (\u2200 x, \u00ac p x) =>\n      fun h2: (\u2203 x, p x) =>\n        let \u27e8w, hw\u27e9 := h2\n        (h w) hw)\n\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) :=\n  Iff.intro\n    (fun h: (\u00ac \u2200 x, p x) =>\n      byContradiction\n        fun h2 : \u00ac(\u2203 x, \u00ac p x) =>\n          h fun x : \u03b1 =>\n            Or.elim (em (p x))\n              (fun hpx : p x => hpx)\n              (fun hnpx : \u00ac(p x) => absurd \u27e8x, hnpx\u27e9 h2 ))\n    (fun h: (\u2203 x, \u00ac p x) =>\n      fun h2: (\u2200 x, p x) =>\n        let \u27e8w, hw\u27e9 := h\n        hw (h2 w) )\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r :=\n  Iff.intro\n    (fun h : (\u2200 x, p x \u2192 r) =>\n      fun h2 : (\u2203 x, p x) =>\n        let \u27e8w, hw\u27e9 := h2\n        (h w) hw)\n    (fun h : (\u2203 x, p x) \u2192 r =>\n      fun w : \u03b1 =>\n        fun hw : p w =>\n          h \u27e8w, hw\u27e9 )\n\nexample (a : \u03b1) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r :=\n  Iff.intro\n    (fun \u27e8b, (hb : p b \u2192 r)\u27e9 =>\n     fun h2 : \u2200 x, p x =>\n     show r from hb (h2 b))\n    (fun h1 : (\u2200 x, p x) \u2192 r =>\n     show \u2203 x, p x \u2192 r from\n       byCases\n         (fun hap : \u2200 x, p x => \u27e8a, \u03bb _ => h1 hap\u27e9)\n         (fun hnap : \u00ac \u2200 x, p x =>\n          byContradiction\n            (fun hnex : \u00ac \u2203 x, p x \u2192 r =>\n              have hap : \u2200 x, p x :=\n                fun x =>\n                byContradiction\n                  (fun hnp : \u00ac p x =>\n                    have hex : \u2203 x, p x \u2192 r := \u27e8x, (fun hp => absurd hp hnp)\u27e9\n                    show False from hnex hex)\n              show False from hnap hap)))\n\nexample (a : \u03b1) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) :=\n  Iff.intro\n    (fun h : (\u2203 x, r \u2192 p x) =>\n      fun hr : r =>\n        let \u27e8w, hw\u27e9 := h\n        \u27e8w, hw hr\u27e9 )\n    (fun h : (r \u2192 \u2203 x, p x) =>\n      byCases\n        (fun hr : r =>\n          let \u27e8w, hw\u27e9 := h hr\n          \u27e8w, \u03bb _ => hw\u27e9  )\n        (fun hnr : \u00acr =>\n          \u27e8a, fun hr : r =>\n            absurd hr hnr\u27e9 ))\n", "meta": {"author": "aortega0703", "repo": "theorem-proving-in-lean-4-solutions", "sha": "55adab77768bdf9ff4ed49e414bc56ae20d950cb", "save_path": "github-repos/lean/aortega0703-theorem-proving-in-lean-4-solutions", "path": "github-repos/lean/aortega0703-theorem-proving-in-lean-4-solutions/theorem-proving-in-lean-4-solutions-55adab77768bdf9ff4ed49e414bc56ae20d950cb/chapter-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7174827199619874}}
{"text": "/- CONJUNCTION -/ \nvariable (p q : Prop)\n\n-- `and.intro h1 h2` builds proof of `p \u2227 q` using proofs `h1 : p` and `h2 : p`\n  -- is described as the AND-INTRODUCTION rule\\\n  example (hp : p) (hq : q) : p \u2227 q := And.intro hp hq\n  #check fun (hp : p) (hq : q) => And.intro hp hq\n\n-- `example` command states a theorem w/o naming or storing permanently - convinient for illustration\n\n/-left and right AND-ELIMINATION rules-/\n  -- `and.left h` creates proof of `p` from proof `h : p \u2227 q`\n  -- `and.right h` is proof of `q`\n    example (h : p \u2227 q) : p := And.left h\n    example (h : p \u2227 q) : q := And.right h \n\n    example (h : p \u2227 q) : q \u2227 p :=\n    And.intro (And.right h) (And.left h)\n\n-- note: and-introduction and end-elimination are similar to pairing and projection operations for cartesian product. \n-- difference is given `hp : p` and `hq : q`:\n  -- `And.intro hp hq` has type `p \u2227 q : Prop`\n  -- `Prod hp hq` has type `p \u00d7 q : Type`\n-- similarity between \u2227 and \u00d7 is another instance of the Curry-Howard isomorphism tho treated separatedly in Lean.\n\n-- certain types in lean are STRUCTURES: defined w single conanical CONSTRUCTOR which builds an element of the type from a sequence of suitable arguments\n  -- ie. For every `p q : Prop`, `p \u2227 q` is an example \n    -- canonical way to construct is to apply `And.intro` to suitable args `hp : p` amd `hq : q`\n    -- lean lets us use anonymous constructor notation notation `\u27e8arg1, arg2, ...\u27e9` when relevant type is inductive type and can be inferred from context\n    -- in particular, can often write `\u27e8hp, hq\u27e9` instead of `And.intro hp hq`\n    variable (hp : p) (hq : q)\n    #check (\u27e8hp, hq\u27e9 : p \u2227 q)\n\n-- thus given shorthand syntax, can rewrite as \n  variable (p q : Prop)\n  example (h : p \u2227 q) : q \u2227 p :=\n    \u27e8h.right, h.left\u27e9 \n\n\n3\n\n", "meta": {"author": "mothematician", "repo": "lean4-proof-stuff", "sha": "1f202b1d3059f3a36dab9abd7564594bf765ebf2", "save_path": "github-repos/lean/mothematician-lean4-proof-stuff", "path": "github-repos/lean/mothematician-lean4-proof-stuff/lean4-proof-stuff-1f202b1d3059f3a36dab9abd7564594bf765ebf2/documentation/3. proposition&proofs.lean/3.31conjunction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.7174827071589949}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport algebra.iterate_hom\nimport data.polynomial.eval\n\n/-!\n# The derivative map on polynomials\n\n## Main definitions\n * `polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map.\n\n-/\n\nnoncomputable theory\n\nopen finset\nopen_locale big_operators classical\n\nnamespace polynomial\nuniverses u v w y z\nvariables {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type y} {A : Type z} {a b : R} {n : \u2115}\n\nsection derivative\n\nsection semiring\nvariables [semiring R]\n\n/-- `derivative p` is the formal derivative of the polynomial `p` -/\ndef derivative : polynomial R \u2192\u2097[R] polynomial R :=\n{ to_fun := \u03bb p, p.sum (\u03bb n a, C (a * n) * X^(n-1)),\n  map_add' := \u03bb p q, by rw sum_add_index;\n    simp only [add_mul, forall_const, ring_hom.map_add,\n      eq_self_iff_true, zero_mul, ring_hom.map_zero],\n  map_smul' := \u03bb a p, by dsimp; rw sum_smul_index;\n    simp only [mul_sum, \u2190 C_mul', mul_assoc, coeff_C_mul, ring_hom.map_mul, forall_const,\n      zero_mul, ring_hom.map_zero, sum] }\n\nlemma derivative_apply (p : polynomial R) :\n  derivative p = p.sum (\u03bbn a, C (a * n) * X^(n - 1)) := rfl\n\nlemma coeff_derivative (p : polynomial R) (n : \u2115) :\n  coeff (derivative p) n = coeff p (n + 1) * (n + 1) :=\nbegin\n  rw [derivative_apply],\n  simp only [coeff_X_pow, coeff_sum, coeff_C_mul],\n  rw [sum, finset.sum_eq_single (n + 1)],\n  simp only [nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true], norm_cast,\n  { assume b, cases b,\n    { intros, rw [nat.cast_zero, mul_zero, zero_mul], },\n    { intros _ H, rw [nat.succ_sub_one b, if_neg (mt (congr_arg nat.succ) H.symm), mul_zero] } },\n  { rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, nat.cast_add, nat.cast_one,\n      mem_support_iff],\n    intro h, push_neg at h, simp [h], },\nend\n\n@[simp]\nlemma derivative_zero : derivative (0 : polynomial R) = 0 :=\nderivative.map_zero\n\n@[simp]\nlemma iterate_derivative_zero {k : \u2115} : derivative^[k] (0 : polynomial R) = 0 :=\nbegin\n  induction k with k ih,\n  { simp, },\n  { simp [ih], },\nend\n\n@[simp]\nlemma derivative_monomial (a : R) (n : \u2115) : derivative (monomial n a) = monomial (n - 1) (a * n) :=\nby { rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial], simp }\n\nlemma derivative_C_mul_X_pow (a : R) (n : \u2115) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) :=\nby rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial]\n\n@[simp] lemma derivative_X_pow (n : \u2115) :\n  derivative (X ^ n : polynomial R) = (n : polynomial R) * X ^ (n - 1) :=\nby convert derivative_C_mul_X_pow (1 : R) n; simp\n\n@[simp] lemma derivative_C {a : R} : derivative (C a) = 0 :=\nby simp [derivative_apply]\n\n@[simp] lemma derivative_X : derivative (X : polynomial R) = 1 :=\n(derivative_monomial _ _).trans $ by simp\n\n@[simp] lemma derivative_one : derivative (1 : polynomial R) = 0 :=\nderivative_C\n\n@[simp] lemma derivative_bit0 {a : polynomial R} : derivative (bit0 a) = bit0 (derivative a) :=\nby simp [bit0]\n\n@[simp] lemma derivative_bit1 {a : polynomial R} : derivative (bit1 a) = bit0 (derivative a) :=\nby simp [bit1]\n\n@[simp] lemma derivative_add {f g : polynomial R} :\n  derivative (f + g) = derivative f + derivative g :=\nderivative.map_add f g\n\n@[simp] lemma iterate_derivative_add {f g : polynomial R} {k : \u2115} :\n  derivative^[k] (f + g) = (derivative^[k] f) + (derivative^[k] g) :=\nderivative.to_add_monoid_hom.iterate_map_add _ _ _\n\n@[simp] lemma derivative_neg {R : Type*} [ring R] (f : polynomial R) :\n  derivative (-f) = - derivative f :=\nlinear_map.map_neg derivative f\n\n@[simp] lemma iterate_derivative_neg {R : Type*} [ring R] {f : polynomial R} {k : \u2115} :\n  derivative^[k] (-f) = - (derivative^[k] f) :=\n(@derivative R _).to_add_monoid_hom.iterate_map_neg _ _\n\n@[simp] lemma derivative_sub {R : Type*} [ring R] {f g : polynomial R} :\n  derivative (f - g) = derivative f - derivative g :=\nlinear_map.map_sub derivative f g\n\n@[simp] lemma iterate_derivative_sub {R : Type*} [ring R] {k : \u2115} {f g : polynomial R} :\n  derivative^[k] (f - g) = (derivative^[k] f) - (derivative^[k] g) :=\nbegin\n  induction k with k ih generalizing f g,\n  { simp [nat.iterate], },\n  { simp [nat.iterate, ih], }\nend\n\n@[simp] lemma derivative_sum {s : finset \u03b9} {f : \u03b9 \u2192 polynomial R} :\n  derivative (\u2211 b in s, f b) = \u2211 b in s, derivative (f b) :=\nderivative.map_sum\n\n@[simp] lemma derivative_smul (r : R) (p : polynomial R) : derivative (r \u2022 p) = r \u2022 derivative p :=\nderivative.map_smul _ _\n\n@[simp] lemma iterate_derivative_smul (r : R) (p : polynomial R) (k : \u2115) :\n  derivative^[k] (r \u2022 p) = r \u2022 (derivative^[k] p) :=\nbegin\n  induction k with k ih generalizing p,\n  { simp, },\n  { simp [ih], },\nend\n\n/-- We can't use `derivative_mul` here because\nwe want to prove this statement also for noncommutative rings.-/\n@[simp]\nlemma derivative_C_mul (a : R) (p : polynomial R) : derivative (C a * p) = C a * derivative p :=\nby convert derivative_smul a p; apply C_mul'\n\n@[simp]\nlemma iterate_derivative_C_mul (a : R) (p : polynomial R) (k : \u2115) :\n  derivative^[k] (C a * p) = C a * (derivative^[k] p) :=\nby convert iterate_derivative_smul a p k; apply C_mul'\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R]\n\nlemma derivative_eval (p : polynomial R) (x : R) :\n  p.derivative.eval x = p.sum (\u03bb n a, (a * n)*x^(n-1)) :=\nby simp only [derivative_apply, eval_sum, eval_pow, eval_C, eval_X, eval_nat_cast, eval_mul]\n\n@[simp] lemma derivative_mul {f g : polynomial R} :\n  derivative (f * g) = derivative f * g + f * derivative g :=\ncalc derivative (f * g) = f.sum (\u03bbn a, g.sum (\u03bbm b, C ((a * b) * (n + m : \u2115)) * X^((n + m) - 1))) :\n  begin\n    rw mul_eq_sum_sum,\n    transitivity, exact derivative_sum,\n    transitivity, { apply finset.sum_congr rfl, assume x hx, exact derivative_sum },\n    apply finset.sum_congr rfl, assume n hn, apply finset.sum_congr rfl, assume m hm,\n    transitivity,\n    { apply congr_arg, exact monomial_eq_C_mul_X },\n    exact derivative_C_mul_X_pow _ _\n  end\n  ... = f.sum (\u03bbn a, g.sum (\u03bbm b,\n      (C (a * n) * X^(n - 1)) * (C b * X^m) + (C a * X^n) * (C (b * m) * X^(m - 1)))) :\n    sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm,\n      by simp only [nat.cast_add, mul_add, add_mul, C_add, C_mul];\n      cases n; simp only [nat.succ_sub_succ, pow_zero];\n      cases m; simp only [nat.cast_zero, C_0, nat.succ_sub_succ, zero_mul, mul_zero, nat.add_succ,\n        tsub_zero, pow_zero, pow_add, one_mul, pow_succ, mul_comm, mul_left_comm]\n  ... = derivative f * g + f * derivative g :\n    begin\n      conv { to_rhs, congr,\n        { rw [\u2190 sum_C_mul_X_eq g] },\n        { rw [\u2190 sum_C_mul_X_eq f] } },\n      simp only [sum, sum_add_distrib, finset.mul_sum, finset.sum_mul, derivative_apply]\n    end\n\ntheorem derivative_pow_succ (p : polynomial R) (n : \u2115) :\n  (p ^ (n + 1)).derivative = (n + 1) * (p ^ n) * p.derivative :=\nnat.rec_on n (by rw [pow_one, nat.cast_zero, zero_add, one_mul, pow_zero, one_mul]) $ \u03bb n ih,\nby rw [pow_succ', derivative_mul, ih, mul_right_comm, \u2190 add_mul,\n    add_mul (n.succ : polynomial R), one_mul, pow_succ', mul_assoc, n.cast_succ]\n\ntheorem derivative_pow (p : polynomial R) (n : \u2115) :\n  (p ^ n).derivative = n * (p ^ (n - 1)) * p.derivative :=\nnat.cases_on n (by rw [pow_zero, derivative_one, nat.cast_zero, zero_mul, zero_mul]) $ \u03bb n,\nby rw [p.derivative_pow_succ n, n.succ_sub_one, n.cast_succ]\n\nlemma derivative_comp (p q : polynomial R) :\n  (p.comp q).derivative = q.derivative * p.derivative.comp q :=\nbegin\n  apply polynomial.induction_on' p,\n  { intros p\u2081 p\u2082 h\u2081 h\u2082, simp [h\u2081, h\u2082, mul_add], },\n  { intros n r,\n    simp only [derivative_pow, derivative_mul, monomial_comp, derivative_monomial, derivative_C,\n      zero_mul, C_eq_nat_cast, zero_add, ring_hom.map_mul],\n    -- is there a tactic for this? (a multiplicative `abel`):\n    rw [mul_comm (derivative q)],\n    simp only [mul_assoc], }\nend\n\n@[simp]\ntheorem derivative_map [comm_semiring S] (p : polynomial R) (f : R \u2192+* S) :\n  (p.map f).derivative = p.derivative.map f :=\npolynomial.induction_on p\n  (\u03bb r, by rw [map_C, derivative_C, derivative_C, map_zero])\n  (\u03bb p q ihp ihq, by rw [map_add, derivative_add, ihp, ihq, derivative_add, map_add])\n  (\u03bb n r ih, by rw [map_mul, map_C, map_pow, map_X,\n      derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one,\n      derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one,\n      map_mul, map_C, map_mul, map_pow, map_add, map_nat_cast, map_one, map_X])\n\n@[simp]\ntheorem iterate_derivative_map [comm_semiring S] (p : polynomial R) (f : R \u2192+* S) (k : \u2115):\n  polynomial.derivative^[k] (p.map f) = (polynomial.derivative^[k] p).map f :=\nbegin\n  induction k with k ih generalizing p,\n  { simp, },\n  { simp [ih], },\nend\n\n/-- Chain rule for formal derivative of polynomials. -/\ntheorem derivative_eval\u2082_C (p q : polynomial R) :\n  (p.eval\u2082 C q).derivative = p.derivative.eval\u2082 C q * q.derivative :=\npolynomial.induction_on p\n  (\u03bb r, by rw [eval\u2082_C, derivative_C, eval\u2082_zero, zero_mul])\n  (\u03bb p\u2081 p\u2082 ih\u2081 ih\u2082, by rw [eval\u2082_add, derivative_add, ih\u2081, ih\u2082, derivative_add, eval\u2082_add, add_mul])\n  (\u03bb n r ih, by rw [pow_succ', \u2190 mul_assoc, eval\u2082_mul, eval\u2082_X, derivative_mul, ih,\n      @derivative_mul _ _ _ X, derivative_X, mul_one, eval\u2082_add, @eval\u2082_mul _ _ _ _ X, eval\u2082_X,\n      add_mul, mul_right_comm])\n\ntheorem derivative_prod {s : multiset \u03b9} {f : \u03b9 \u2192 polynomial R} :\n  (multiset.map f s).prod.derivative =\n  (multiset.map (\u03bb i, (multiset.map f (s.erase i)).prod * (f i).derivative) s).sum :=\nbegin\n  refine multiset.induction_on s (by simp) (\u03bb i s h, _),\n  rw [multiset.map_cons, multiset.prod_cons, derivative_mul, multiset.map_cons _ i s,\n    multiset.sum_cons, multiset.erase_cons_head, mul_comm (f i).derivative],\n  congr,\n  rw [h, \u2190 add_monoid_hom.coe_mul_left, (add_monoid_hom.mul_left (f i)).map_multiset_sum _,\n    add_monoid_hom.coe_mul_left],\n  simp only [function.comp_app, multiset.map_map],\n  congr' 1,\n  refine multiset.map_congr (\u03bb j hj, _),\n  simp only [function.comp_app],\n  rw [\u2190 mul_assoc, \u2190 multiset.prod_cons, \u2190 multiset.map_cons],\n  congr' 1,\n  by_cases hij : i = j,\n  { simp [hij, \u2190 multiset.prod_cons, \u2190 multiset.map_cons, multiset.cons_erase hj] },\n  { simp [hij] }\nend\n\ntheorem of_mem_support_derivative {p : polynomial R} {n : \u2115} (h : n \u2208 p.derivative.support) :\n  n + 1 \u2208 p.support :=\nmem_support_iff.2 $ \u03bb (h1 : p.coeff (n+1) = 0), mem_support_iff.1 h $\nshow p.derivative.coeff n = 0, by rw [coeff_derivative, h1, zero_mul]\n\ntheorem degree_derivative_lt {p : polynomial R} (hp : p \u2260 0) : p.derivative.degree < p.degree :=\n(finset.sup_lt_iff $ bot_lt_iff_ne_bot.2 $ mt degree_eq_bot.1 hp).2 $ \u03bb n hp, lt_of_lt_of_le\n(with_bot.some_lt_some.2 n.lt_succ_self) $ finset.le_sup $ of_mem_support_derivative hp\n\ntheorem nat_degree_derivative_lt {p : polynomial R} (hp : p.derivative \u2260 0) :\n  p.derivative.nat_degree < p.nat_degree :=\nhave hp1 : p \u2260 0, from \u03bb h, hp $ by rw [h, derivative_zero],\nwith_bot.some_lt_some.1 $\nbegin\n  rw [nat_degree, option.get_or_else_of_ne_none $ mt degree_eq_bot.1 hp, nat_degree,\n    option.get_or_else_of_ne_none $ mt degree_eq_bot.1 hp1],\n  exact degree_derivative_lt hp1\nend\n\ntheorem degree_derivative_le {p : polynomial R} : p.derivative.degree \u2264 p.degree :=\nif H : p = 0 then le_of_eq $ by rw [H, derivative_zero] else le_of_lt $ degree_derivative_lt H\n\n/-- The formal derivative of polynomials, as linear homomorphism. -/\ndef derivative_lhom (R : Type*) [comm_ring R] : polynomial R \u2192\u2097[R] polynomial R :=\n{ to_fun    := derivative,\n  map_add'  := \u03bb p q, derivative_add,\n  map_smul' := \u03bb r p, derivative_smul r p }\n\n@[simp] lemma derivative_lhom_coe {R : Type*} [comm_ring R] :\n  (polynomial.derivative_lhom R : polynomial R \u2192 polynomial R) = polynomial.derivative :=\nrfl\n\n@[simp] lemma derivative_cast_nat {n : \u2115} : derivative (n : polynomial R) = 0 :=\nbegin\n  rw \u2190 C.map_nat_cast n,\n  exact derivative_C,\nend\n\n@[simp] lemma iterate_derivative_cast_nat_mul {n k : \u2115} {f : polynomial R} :\n  derivative^[k] (n * f) = n * (derivative^[k] f) :=\nbegin\n  induction k with k ih generalizing f,\n  { simp [nat.iterate], },\n  { simp [nat.iterate, ih], }\nend\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nlemma derivative_comp_one_sub_X (p : polynomial R) :\n  (p.comp (1-X)).derivative = -p.derivative.comp (1-X) :=\nby simp [derivative_comp]\n\n@[simp]\nlemma iterate_derivative_comp_one_sub_X (p : polynomial R) (k : \u2115) :\n  derivative^[k] (p.comp (1-X)) = (-1)^k * (derivative^[k] p).comp (1-X) :=\nbegin\n  induction k with k ih generalizing p,\n  { simp, },\n  { simp [ih p.derivative, iterate_derivative_neg, derivative_comp, pow_succ], },\nend\n\n\n\nend comm_ring\n\nsection is_domain\nvariables [ring R] [is_domain R]\n\nlemma mem_support_derivative [char_zero R] (p : polynomial R) (n : \u2115) :\n  n \u2208 (derivative p).support \u2194 n + 1 \u2208 p.support :=\nsuffices (\u00ac(coeff p (n + 1) = 0 \u2228 ((n + 1:\u2115) : R) = 0)) \u2194 coeff p (n + 1) \u2260 0,\n  by simpa only [mem_support_iff, coeff_derivative, ne.def, mul_eq_zero],\nby { rw [nat.cast_eq_zero], simp only [nat.succ_ne_zero, or_false] }\n\n@[simp] lemma degree_derivative_eq [char_zero R] (p : polynomial R) (hp : 0 < nat_degree p) :\n  degree (derivative p) = (nat_degree p - 1 : \u2115) :=\nbegin\n  have h0 : p \u2260 0,\n  { contrapose! hp,\n    simp [hp] },\n  apply le_antisymm,\n  { rw derivative_apply,\n    apply le_trans (degree_sum_le _ _) (sup_le (\u03bb n hn, _)),\n    apply le_trans (degree_C_mul_X_pow_le _ _) (with_bot.coe_le_coe.2 (tsub_le_tsub_right _ _)),\n    apply le_nat_degree_of_mem_supp _ hn },\n  { refine le_sup _,\n    rw [mem_support_derivative, tsub_add_cancel_of_le, mem_support_iff],\n    { show \u00ac leading_coeff p = 0,\n      rw [leading_coeff_eq_zero],\n      assume h, rw [h, nat_degree_zero] at hp,\n      exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp), },\n    exact hp }\nend\n\ntheorem nat_degree_eq_zero_of_derivative_eq_zero\n  [char_zero R] {f : polynomial R} (h : f.derivative = 0) :\n  f.nat_degree = 0 :=\nbegin\n  by_cases hf : f = 0,\n  { exact (congr_arg polynomial.nat_degree hf).trans rfl },\n  { rw nat_degree_eq_zero_iff_degree_le_zero,\n    by_contra absurd,\n    have f_nat_degree_pos : 0 < f.nat_degree,\n    { rwa [not_le, \u2190nat_degree_pos_iff_degree_pos] at absurd },\n    let m := f.nat_degree - 1,\n    have hm : m + 1 = f.nat_degree := tsub_add_cancel_of_le f_nat_degree_pos,\n    have h2 := coeff_derivative f m,\n    rw polynomial.ext_iff at h,\n    rw [h m, coeff_zero, zero_eq_mul] at h2,\n    cases h2,\n    { rw [hm, \u2190leading_coeff, leading_coeff_eq_zero] at h2,\n      exact hf h2, },\n    { norm_cast at h2 } }\nend\n\nend is_domain\n\nend derivative\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/derivative.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.7174826982106786}}
{"text": "/- Propositional tableaux prover from Jeremy Avigad's lecture notes. -/\n\nopen expr tactic classical\n\nvariables {p q r s : Prop}\nvariables {a b c d e : Prop}\n\nsection\n\nlocal attribute [instance] classical.prop_decidable\n\n  theorem not_or_of_imp (h : a \u2192 b) : \u00ac a \u2228 b :=\n  if ha : a then or.inr (h ha) else or.inl ha\n\n  theorem imp_iff_not_or : (a \u2192 b) \u2194 (\u00ac a \u2228 b) :=\n  \u27e8not_or_of_imp, or.neg_resolve_left\u27e9\n\n  theorem iff_def : (a \u2194 b) \u2194 (a \u2192 b) \u2227 (b \u2192 a) :=\n  iff_iff_implies_and_implies _ _\n\n  theorem not_not : \u00ac\u00aca \u2194 a :=\n  iff.intro by_contradiction not_not_intro\n\n  theorem not_or_distrib : \u00ac (a \u2228 b) \u2194 \u00ac a \u2227 \u00ac b :=\n  \u27e8\u03bb h, \u27e8\u03bb ha, h (or.inl ha), \u03bb hb, h (or.inr hb)\u27e9,\n   \u03bb \u27e8h\u2081, h\u2082\u27e9 h, or.elim h h\u2081 h\u2082\u27e9\n\n  theorem not_and_of_not_or_not (h : \u00ac a \u2228 \u00ac b) : \u00ac (a \u2227 b)\n  | \u27e8ha, hb\u27e9 := or.elim h (absurd ha) (absurd hb)\n\n  theorem not_and_distrib : \u00ac (a \u2227 b) \u2194 \u00aca \u2228 \u00acb :=\n  \u27e8\u03bb h, if ha : a then or.inr (\u03bb hb, h \u27e8ha, hb\u27e9) else or.inl ha, not_and_of_not_or_not\u27e9\n\nend\n\nmeta def normalize : tactic unit :=\n`[ try { simp only\n   [ not_or_distrib,\n     not_and_distrib,\n     not_not,\n     imp_iff_not_or,\n     not_true_iff,\n     not_false_iff,\n     iff_def ] at * } ]\n\nmeta def find_conj : list expr \u2192 tactic expr\n| []        := failed\n| (e :: es) := do t \u2190 infer_type e,\n                  match t with\n                  | `(%%a \u2227 %%b) := return e\n                  | _            := find_conj es\n                  end\n\nmeta def find_disj : list expr \u2192 tactic expr\n| []        := failed\n| (e :: es) := do t \u2190 infer_type e,\n                  match t with\n                  | `(%%a \u2228 %%b) := return e\n                  | _            := find_disj es\n                  end\n\nmeta def split_conj : tactic unit :=\ndo l \u2190 local_context,\n   e \u2190 find_conj l,\n   cases e,\n   skip\n\nmeta def split_conjs : tactic unit :=\nrepeat split_conj\n\nmeta def split_disj : tactic unit :=\ndo l \u2190 local_context,\n   e \u2190 find_disj l,\n   cases e,\n   skip\n\nmeta def proof_by_contradiction : tactic unit :=\ndo refine ``(classical.by_contradiction _),\n   intro `_,\n   skip\n\nmeta def tab_aux : tactic unit :=\ndo split_conjs,\n   contradiction <|>\n     (split_disj >> tab_aux >> tab_aux)\n\nmeta def tab : tactic unit :=\ndo proof_by_contradiction,\n   normalize,\n   tab_aux\n\nexample : a \u2227 b \u2192 b \u2227 a := by tab\nexample : a \u2227 (a \u2192 b) \u2192 b := by tab\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := by tab\nexample : p \u2228 q \u2194 q \u2228 p := by tab\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := by tab\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := by tab\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by tab\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := by tab\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := by tab\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := by tab\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := by tab\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := by tab\nexample : \u00ac(p \u2227 \u00acp) := by tab\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := by tab\nexample : \u00acp \u2192 (p \u2192 q) := by tab\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := by tab\nexample : p \u2228 false \u2194 p := by tab\nexample : p \u2227 false \u2194 false := by tab\nexample : \u00ac(p \u2194 \u00acp) := by tab\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := by tab\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := by tab\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := by tab\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := by tab\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := by tab\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := by tab\nexample : p \u2228 \u00acp := by tab\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := by tab\n\nexample (h\u2081 : a \u2227 b) (h\u2082 : b \u2227 \u00ac c) : a \u2228 c := by tab\n\nexample (h\u2081 : a \u2227 b) (h\u2082 : b \u2227 \u00ac c) : a \u2227 \u00ac c := by tab\n\nexample : ((a \u2192 b) \u2192 a) \u2192 a := by tab\n\nexample : (a \u2192 b) \u2227 (b \u2192 c) \u2192 a \u2192 c := by tab\n\nexample (\u03b1 : Type) (x y z w : \u03b1) :\n  x = y \u2227 (x = y \u2192 z = w) \u2192 z = w := by tab\n\nexample : \u00ac (a \u2194 \u00ac a) := by tab\n", "meta": {"author": "jesse-michael-han", "repo": "hanoi-lean-2019", "sha": "a5a9f368e394d563bfcc13e3773863924505b1ce", "save_path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019", "path": "github-repos/lean/jesse-michael-han-hanoi-lean-2019/hanoi-lean-2019-a5a9f368e394d563bfcc13e3773863924505b1ce/src/seul/tab.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7174826917206846}}
{"text": "theorem succ_eq_succ_iff (a b : \u2115) : nat.succ a = nat.succ b \u2194 a = b :=\nbegin\n    split,\n    intro h,\n    exact nat.succ.inj h,\n    intro f,\n    repeat {rw nat.succ_eq_add_one},\n    rw f,\nend", "meta": {"author": "Samyak-Surti", "repo": "LeanCode", "sha": "944eac3e5f43e2614ed246083b97fbdf24181d83", "save_path": "github-repos/lean/Samyak-Surti-LeanCode", "path": "github-repos/lean/Samyak-Surti-LeanCode/LeanCode-944eac3e5f43e2614ed246083b97fbdf24181d83/nat_num_game/src/Advanced_Addition_World/adv_add_wrld4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.717478225441677}}
{"text": "import basic_defs_world.level1 -- hide\n\n/- Axiom : A set A is the neighborhood of a point x if there is an open U such that x \u2208 U \u2286 A.\nis_neighborhood : \u2203 U, is_open U \u2227 x \u2208 U \u2227 U \u2286 A\n-/\n\n/- Axiom : A point x is an interior point of A if A is a neighborhood of x.\nis_interior_point : is_neighborhood x A\n-/\n\n/- Axiom : The interior of a set A is the set of all its interior points. \ninterior := { x : X | is_interior_point x A }\n-/\n\n/-\nIn this world we will end up having three alternative definitions of the interior of a set. \nThis will be very useful, because at any point we will be able to choose the one that better fits our needs.\n\nFirst of all we need to figure out what properties does the interior of an arbitrary set have... So we start with an easy one:\n\n# Level 1: The interior is contained in the original set\n\n-/\nvariables {X : Type} -- hide\nvariables [topological_space X] (x : X)  (A : set X) -- hide\n\nnamespace topological_space -- hide\n\n@[simp]  -- hide\n/- Lemma\nThe interior of any set A is contained in the set A.\n-/\nlemma interior_is_subset: interior A \u2286 A :=\nbegin\n  rintros x \u27e8_, _\u27e9,\n  tauto,\n\n\n\n\n\n\n\n\n\nend\n\nend topological_space -- hide\n", "meta": {"author": "mmasdeu", "repo": "topologygame", "sha": "0a1b868031919a5555e7b99efca66ece2f546ec7", "save_path": "github-repos/lean/mmasdeu-topologygame", "path": "github-repos/lean/mmasdeu-topologygame/topologygame-0a1b868031919a5555e7b99efca66ece2f546ec7/src/interior_world/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7174026301367044}}
{"text": "/-\nThe goal of this file is to express basis coordinates in terms of the inner product.\n\n-- Checked over by: \n-- Hans\n-/\n\nimport analysis.inner_product_space.pi_L2\n\nnotation `\u2102^` n := euclidean_space \u2102 (fin n)\n\nopen_locale big_operators\n\nvariables {n : \u2115} (b : basis (fin n) \u2102 \u2102^n) (v : \u2102^n) (hon : orthonormal \u2102 b)\n\n/-\nBasis coordinates are given by the inner product.\n-/\nlemma onb_coords_eq_inner (i : fin n) (hon : orthonormal \u2102 b) :\n  (b.repr v) i = \u27ea b i, v \u27eb_\u2102 :=\nbegin\n  rw orthonormal_iff_ite at hon,\n  specialize hon i,\n  conv\n  begin\n    to_rhs,\n    rw \u2190 b.sum_repr v,\n    rw inner_sum,\n    congr,\n    skip,\n    funext,\n    rw inner_smul_right,\n    rw hon,\n    simp,\n  end,\n  rw finset.sum_ite,\n  simp only [add_zero, finset.sum_const_zero, finset.filter_congr_decidable, finset.sum_congr],\n  rw finset.filter_eq,\n  simp only [finset.mem_univ, if_true, eq_self_iff_true, finset.sum_singleton, finset.sum_congr],\nend\n\n/-\nBasis coordinates are given by the inner product.\n-/\nlemma onb_sum_repr (hon : orthonormal \u2102 b):\n  v = \u2211 (i : (fin n)), \u27eab i, v\u27eb_\u2102 \u2022 (b i) :=\nbegin\n  conv\n  begin\n    congr,\n    skip,\n    congr,\n    skip,\n    funext,\n    rw \u2190 onb_coords_eq_inner b v i hon,\n  end,\n  symmetry,\n  apply basis.sum_repr,\nend", "meta": {"author": "hparshall", "repo": "lean-matrix-analysis", "sha": "cc1b9949065257b6c19f047a5a996bfac29f178e", "save_path": "github-repos/lean/hparshall-lean-matrix-analysis", "path": "github-repos/lean/hparshall-lean-matrix-analysis/lean-matrix-analysis-cc1b9949065257b6c19f047a5a996bfac29f178e/src/old/orthonormal_basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7174026235586956}}
{"text": "import tactic --hide\n\n/-\n## `left` and `right`\n\nIf your lemma has the goal: \n\n```\n\u22a2 P \u2228 Q\n```\n\nthen   <mark style =\"background-color : #ebdef0 \">`left`</mark>  changes the goal to `\u22a2 P`. \nSimilarly,  <mark style =\"background-color : #ebdef0 \">`right`</mark>  changes the goal to `\u22a2 Q`.\n-/\n\n/-Hint : Why does this work?\nThe logic is that `P` implies `P \u2228 Q` so it is enough to prove `P`. \n\n-/\n\n\n/-Lemma\nLet $P,Q$ be logical statements and assume $P$ is true, then $P \u2228 Q$ is true.\n-/\nlemma left_example (P Q : Prop) (p : P) : P \u2228 Q :=\nbegin\n  left,\n  exact p,\nend\n\n\n\n/- Tactic : left and right\n\nIf your lemma has the goal: \n\n```\n\u22a2 P \u2228 Q\n```\n\nthen `left` changes the goal to `\u22a2 P`. Similarly `right` changes the goal to `\u22a2 Q`.\n\n-/", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic2/lr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7174026209972413}}
{"text": "namespace xena\ninductive xnat\n| zero : xnat\n| succ : xnat \u2192 xnat\n\nopen xnat\nopen classical\n--#check @succ.inj\n\ndefinition one := succ zero\ndefinition two := succ one\n\ndefinition add : xnat \u2192 xnat \u2192 xnat\n| n zero := n\n| n (succ p) := succ (add n p)\n\nnotation a + b := add a b\n\ntheorem one_add_one_equals_two : one + one = two :=\nbegin\nunfold two,\nunfold one,\nunfold add,\nend\n\ntheorem add_zero (n : xnat) : n + zero = n :=\nbegin\nunfold add\nend\n\n\n theorem zero_add (n : xnat) : zero + n = n :=\nbegin\ninduction n with t Ht,\n  refl,\nunfold add,\nrewrite [Ht],\nend\n\n\ntheorem add_assoc (a b c : xnat) : (a + b) + c = a + (b + c) :=\nbegin\ninduction c with t Ht,\nrefl,\nunfold add,\nrewrite [Ht]\nend\n\ntheorem zero_add_eq_add_zero (n : xnat) : zero + n = n + zero :=\nbegin\nrewrite [zero_add],\nunfold add\nend\n\n\ntheorem one_add_eq_succ (n : xnat) : one + n = succ n :=\nbegin\nunfold one,\ninduction n with t Ht,\nrefl,\nunfold add,\nrewrite [Ht]\nend\n\ntheorem add_comm (a b : xnat) : a + b = b + a :=\nbegin\ninduction b with t Ht,\nrw [\u2190zero_add_eq_add_zero],\nunfold add,\nrewrite [Ht],\nrewrite [\u2190one_add_eq_succ],\nrewrite [\u2190 add_assoc],\nrw [one_add_eq_succ]\nend\n\ntheorem eq_iff_succ_eq_succ (a b : xnat) : succ a = succ b \u2194 a = b :=\nbegin\nsplit,\n  exact succ.inj,\nassume H : a = b,\nrw [H]\nend\n\ntheorem add_cancel_right (a b t : xnat) :  a = b \u2194 a+t = b+t :=\nbegin\nsplit,\nassume H : a = b,\nrw [H],\nassume P : a+t = b+t,\ninduction t with s Qs, \nhave h3: a = a + zero, by exact add_zero a,\nhave h4: b = b+ zero, by exact add_zero b,\nrw [h3, h4], assumption,\nrw [Qs],\nunfold add at P, \nrw [eq_iff_succ_eq_succ] at P,assumption\nend\n\ndefinition mul : xnat \u2192 xnat \u2192 xnat\n| n zero := zero\n| n (succ p) := n + (mul n p)\n\nnotation a * b := mul a b\n\nexample : one * one = one := \nbegin\nrefl\nend\n\ntheorem mul_zero (a : xnat) : a * zero = zero :=\nbegin\nunfold mul\nend\n\ntheorem zero_mul (a : xnat) : zero * a = zero :=\nbegin\ninduction a with t Ht,\nrefl,\nunfold mul,\nrewrite [Ht],\nrefl\nend\n\ntheorem mul_one (a : xnat) : a * one = a :=\nbegin\nunfold one,\nunfold mul,\nrewrite [add_zero]\nend\n\ntheorem one_mul (a : xnat) : one * a = a :=\nbegin\ninduction a with t Ht,\n  refl,\nunfold mul,\nrewrite [Ht],\nrewrite [one_add_eq_succ]\nend\n\ntheorem zero_sum : zero + zero = zero :=\nbegin\nunfold add,\nend \n\ntheorem right_distrib (a b c : xnat) : a * (b + c) = a* b + a * c :=\nbegin\ninduction c with t Ht,\nrw [add_zero],\nrw [mul_zero],\nrw [add_zero],\nunfold add,\nunfold mul,\nrewrite [Ht],\nrw [\u2190 add_assoc],\nrw [\u2190 add_assoc],\nrw [\u2190 add_cancel_right],\nrw [add_comm]\nend\n\ntheorem add_one_eq_succ (n : xnat) : n + one = succ n :=\nbegin\nunfold one,\nunfold add,\nend\n\ntheorem left_distrib (a b c : xnat) : (a + b) * c = a * c + b * c :=\nbegin\ninduction c with n Hn,\n  unfold mul,\n  refl,\nrw [\u2190add_one_eq_succ,right_distrib,Hn,right_distrib,right_distrib],\nrw [mul_one,mul_one,mul_one],\nrw [add_assoc,\u2190add_assoc (b*n),add_comm (b*n),\u2190add_assoc,\u2190add_assoc,\u2190add_assoc],\nend\n\ntheorem mul_assoc (a b c : xnat) : (a * b) * c = a * (b * c) :=\nbegin\ninduction c with n Hn,\nrefl,\nunfold mul,\nrw [Hn,right_distrib],\nend\n\ntheorem mul_comm (a b : xnat) : a * b = b * a :=\nbegin\ninduction b with n Hn,\nrw [mul_zero,zero_mul],\nrw[\u2190 one_add_eq_succ,right_distrib,left_distrib,Hn,one_mul,mul_one]\nend\n\ndefinition lt : xnat \u2192 xnat \u2192 Prop \n| zero zero := false\n| (succ m) zero := false\n| zero (succ p) := true \n| (succ m) (succ p) := lt m p\n\ndefinition gt : xnat \u2192 xnat \u2192 Prop \n| zero zero := false\n| (succ m) zero := true\n| zero (succ p) := false \n| (succ m) (succ p) := gt m p\n\n\n\nnotation a < b := lt a b \nnotation b > a := gt a b\n\ntheorem inequality_A1 (a b t : xnat) : a < b \u2192 a + t < b + t :=\nbegin\nintro H,\ninduction t with n Hn,\nrw [add_zero,add_zero],assumption,\nrw [\u2190 add_one_eq_succ,\u2190 add_assoc,\u2190 add_assoc],\nrw [add_one_eq_succ,add_one_eq_succ],\nunfold lt, assumption\nend\n\nend xena\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/random_projects_mostly_students/Ellen_Arlt_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7174026190470881}}
{"text": "theorem succ_eq_succ_iff (a b : mynat) : succ a = succ b \u2194 a = b :=\nbegin\nsplit,\nexact succ_inj,\nexact succ_eq_succ_of_eq,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world08/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7173825262775992}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta, Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta, Aaron Anderson\n-/\nimport ring_theory.power_series.basic\nimport combinatorics.partition\nimport data.nat.parity\nimport data.finset.nat_antidiagonal\nimport tactic.interval_cases\nimport tactic.apply_fun\n\n/-!\n# Euler's Partition Theorem\n\nThis file proves Theorem 45 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).\n\nThe theorem concerns the counting of integer partitions -- ways of\nwriting a positive integer `n` as a sum of positive integer parts.\n\nSpecifically, Euler proved that the number of integer partitions of `n`\ninto *distinct* parts equals the number of partitions of `n` into *odd*\nparts.\n\n## Proof outline\n\nThe proof is based on the generating functions for odd and distinct partitions, which turn out to be\nequal:\n\n$$\\prod_{i=0}^\\infty \\frac {1}{1-X^{2i+1}} = \\prod_{i=0}^\\infty (1+X^{i+1})$$\n\nIn fact, we do not take a limit: it turns out that comparing the `n`'th coefficients of the partial\nproducts up to `m := n + 1` is sufficient.\n\nIn particular, we\n\n1. define the partial product for the generating function for odd partitions `partial_odd_gf m` :=\n  $$\\prod_{i=0}^m \\frac {1}{1-X^{2i+1}}$$;\n2. prove `odd_gf_prop`: if `m` is big enough (`m * 2 > n`), the partial product's coefficient counts\n  the number of odd partitions;\n3. define the partial product for the generating function for distinct partitions\n  `partial_distinct_gf m` := $$\\prod_{i=0}^m (1+X^{i+1})$$;\n4. prove `distinct_gf_prop`: if `m` is big enough (`m + 1 > n`), the `n`th coefficient of the\n  partial product counts the number of distinct partitions of `n`;\n5. prove `same_coeffs`: if m is big enough (`m \u2265 n`), the `n`th coefficient of the partial products\n  are equal;\n6. combine the above in `partition_theorem`.\n\n## References\nhttps://en.wikipedia.org/wiki/Partition_(number_theory)#Odd_parts_and_distinct_parts\n-/\n\nopen power_series\nnoncomputable theory\n\nvariables {\u03b1 : Type*}\n\nopen finset\nopen_locale big_operators\nopen_locale classical\n\n/--\nThe partial product for the generating function for odd partitions.\nTODO: As `m` tends to infinity, this converges (in the `X`-adic topology).\n\nIf `m` is sufficiently large, the `i`th coefficient gives the number of odd partitions of the\nnatural number `i`: proved in `odd_gf_prop`.\nIt is stated for an arbitrary field `\u03b1`, though it usually suffices to use `\u211a` or `\u211d`.\n-/\ndef partial_odd_gf (m : \u2115) [field \u03b1] := \u220f i in range m, (1 - (X : power_series \u03b1)^(2*i+1))\u207b\u00b9\n\n/--\nThe partial product for the generating function for distinct partitions.\nTODO: As `m` tends to infinity, this converges (in the `X`-adic topology).\n\nIf `m` is sufficiently large, the `i`th coefficient gives the number of distinct partitions of the\nnatural number `i`: proved in `distinct_gf_prop`.\nIt is stated for an arbitrary commutative semiring `\u03b1`, though it usually suffices to use `\u2115`, `\u211a`\nor `\u211d`.\n-/\ndef partial_distinct_gf (m : \u2115) [comm_semiring \u03b1] :=\n\u220f i in range m, (1 + (X : power_series \u03b1)^(i+1))\n\n/--\nFunctions defined only on `s`, which sum to `n`. In other words, a partition of `n` indexed by `s`.\nEvery function in here is finitely supported, and the support is a subset of `s`.\nThis should be thought of as a generalisation of `finset.nat.antidiagonal`, where\n`antidiagonal n` is the same thing as `cut s n` if `s` has two elements.\n-/\ndef cut {\u03b9 : Type*} (s : finset \u03b9) (n : \u2115) : finset (\u03b9 \u2192 \u2115) :=\nfinset.filter (\u03bb f, s.sum f = n) ((s.pi (\u03bb _, range (n+1))).map\n  \u27e8\u03bb f i, if h : i \u2208 s then f i h else 0,\n   \u03bb f g h, by { ext i hi, simpa [dif_pos hi] using congr_fun h i }\u27e9)\n\nlemma mem_cut {\u03b9 : Type*} (s : finset \u03b9) (n : \u2115) (f : \u03b9 \u2192 \u2115) :\n  f \u2208 cut s n \u2194 s.sum f = n \u2227 \u2200 i \u2209 s, f i = 0 :=\nbegin\n  rw [cut, mem_filter, and_comm, and_congr_right],\n  intro h,\n  simp only [mem_map, exists_prop, function.embedding.coe_fn_mk, mem_pi],\n  split,\n  { rintro \u27e8_, _, rfl\u27e9 _ _,\n    simp [dif_neg H] },\n  { intro hf,\n    refine \u27e8\u03bb i hi, f i, \u03bb i hi, _, _\u27e9,\n    { rw [mem_range, nat.lt_succ_iff, \u2190 h],\n      apply single_le_sum _ hi,\n      simp },\n    { ext,\n      rw [dite_eq_ite, ite_eq_left_iff, eq_comm],\n      exact hf x } }\nend\n\nlemma cut_equiv_antidiag (n : \u2115) :\n  equiv.finset_congr (equiv.bool_arrow_equiv_prod _) (cut univ n) = nat.antidiagonal n :=\nbegin\n  ext \u27e8x\u2081, x\u2082\u27e9,\n  simp_rw [equiv.finset_congr_apply, mem_map, equiv.to_embedding, function.embedding.coe_fn_mk,\n           \u2190equiv.eq_symm_apply],\n  simp [mem_cut, add_comm],\nend\n\n/-- There is only one `cut` of 0. -/\n@[simp]\nlemma cut_zero {\u03b9 : Type*} (s : finset \u03b9) :\n  cut s 0 = {0} :=\nbegin\n  -- In general it's nice to prove things using `mem_cut` but in this case it's easier to just\n  -- use the definition.\n  rw [cut, range_one, pi_const_singleton, map_singleton, function.embedding.coe_fn_mk,\n      filter_singleton, if_pos, singleton_inj],\n  { ext, split_ifs; refl },\n  rw sum_eq_zero_iff,\n  intros x hx,\n  apply dif_pos hx,\nend\n\n@[simp]\nlemma cut_empty_succ {\u03b9 : Type*} (n : \u2115) :\n  cut (\u2205 : finset \u03b9) (n+1) = \u2205 :=\nbegin\n  apply eq_empty_of_forall_not_mem,\n  intros x hx,\n  rw [mem_cut, sum_empty] at hx,\n  cases hx.1,\nend\n\nlemma cut_insert {\u03b9 : Type*} (n : \u2115) (a : \u03b9) (s : finset \u03b9) (h : a \u2209 s) :\n  cut (insert a s) n =\n  (nat.antidiagonal n).bUnion\n    (\u03bb (p : \u2115 \u00d7 \u2115), (cut s p.snd).map\n      \u27e8\u03bb f, f + \u03bb t, if t = a then p.fst else 0, add_left_injective _\u27e9) :=\nbegin\n  ext f,\n  rw [mem_cut, mem_bUnion, sum_insert h],\n  split,\n  { rintro \u27e8rfl, h\u2081\u27e9,\n    simp only [exists_prop, function.embedding.coe_fn_mk, mem_map,\n               nat.mem_antidiagonal, prod.exists],\n    refine \u27e8f a, s.sum f, rfl, \u03bb i, if i = a then 0 else f i, _, _\u27e9,\n    { rw [mem_cut],\n      refine \u27e8_, _\u27e9,\n      { rw [sum_ite],\n        have : (filter (\u03bb x, x \u2260 a) s) = s,\n        { apply filter_true_of_mem,\n          rintro i hi rfl,\n          apply h hi },\n        simp [this] },\n      { intros i hi,\n        rw ite_eq_left_iff,\n        intro hne,\n        apply h\u2081,\n        simp [not_or_distrib, hne, hi] } },\n    { ext,\n      obtain rfl|h := eq_or_ne x a,\n      { simp },\n      { simp [if_neg h] } } },\n  { simp only [mem_insert, function.embedding.coe_fn_mk, mem_map, nat.mem_antidiagonal, prod.exists,\n               exists_prop, mem_cut, not_or_distrib],\n    rintro \u27e8p, q, rfl, g, \u27e8rfl, hg\u2082\u27e9, rfl\u27e9,\n    refine \u27e8_, _\u27e9,\n    { simp [sum_add_distrib, if_neg h, hg\u2082 _ h, add_comm] },\n    { rintro i \u27e8h\u2081, h\u2082\u27e9,\n      simp [if_neg h\u2081, hg\u2082 _ h\u2082] } }\nend\n\nlemma coeff_prod_range\n  [comm_semiring \u03b1] {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 power_series \u03b1) (n : \u2115) :\n  coeff \u03b1 n (\u220f j in s, f j) = \u2211 l in cut s n, \u220f i in s, coeff \u03b1 (l i) (f i) :=\nbegin\n  revert n,\n  apply finset.induction_on s,\n  { rintro \u27e8_ | n\u27e9,\n    { simp },\n    simp [cut_empty_succ, if_neg (nat.succ_ne_zero _)] },\n  intros a s hi ih n,\n  rw [cut_insert _ _ _ hi, prod_insert hi, coeff_mul, sum_bUnion],\n  { apply sum_congr rfl _,\n    simp only [prod.forall, sum_map, pi.add_apply,\n               function.embedding.coe_fn_mk, nat.mem_antidiagonal],\n    rintro i j rfl,\n    simp only [prod_insert hi, if_pos rfl, ih, mul_sum],\n    apply sum_congr rfl _,\n    intros x hx,\n    rw mem_cut at hx,\n    rw [hx.2 a hi, zero_add],\n    congr' 1,\n    apply prod_congr rfl,\n    intros k hk,\n    rw [if_neg, add_zero],\n    exact ne_of_mem_of_not_mem hk hi },\n  { simp only [set.pairwise_disjoint, set.pairwise, prod.forall, not_and, ne.def,\n      nat.mem_antidiagonal, disjoint_left, mem_map, exists_prop, function.embedding.coe_fn_mk,\n      exists_imp_distrib, not_exists, finset.mem_coe],\n    rintro p\u2081 q\u2081 rfl p\u2082 q\u2082 h t x hx,\n    simp only [finset.inf_eq_inter, finset.mem_map, finset.mem_inter, mem_cut, exists_prop,\n      function.embedding.coe_fn_mk] at hx,\n    rcases hx with \u27e8\u27e8p, \u27e8hp, hp2\u27e9, hp3\u27e9, \u27e8q, \u27e8hq, hq2\u27e9, hq3\u27e9\u27e9,\n    have z := hp3.trans hq3.symm,\n    have := sum_congr (eq.refl s) (\u03bb x _, function.funext_iff.1 z x),\n    obtain rfl : q\u2081 = q\u2082,\n    { simpa [sum_add_distrib, hp, hq, if_neg hi] using this },\n    obtain rfl : p\u2082 = p\u2081,\n    { simpa using h },\n    exact (t rfl).elim }\nend\n\n/-- A convenience constructor for the power series whose coefficients indicate a subset. -/\ndef indicator_series (\u03b1 : Type*) [semiring \u03b1] (s : set \u2115) : power_series \u03b1 :=\npower_series.mk (\u03bb n, if n \u2208 s then 1 else 0)\n\nlemma coeff_indicator (s : set \u2115) [semiring \u03b1] (n : \u2115) :\n  coeff \u03b1 n (indicator_series _ s) = if n \u2208 s then 1 else 0 :=\ncoeff_mk _ _\nlemma coeff_indicator_pos (s : set \u2115) [semiring \u03b1] (n : \u2115) (h : n \u2208 s):\n  coeff \u03b1 n (indicator_series _ s) = 1 :=\nby rw [coeff_indicator, if_pos h]\nlemma coeff_indicator_neg (s : set \u2115) [semiring \u03b1] (n : \u2115) (h : n \u2209 s):\n  coeff \u03b1 n (indicator_series _ s) = 0 :=\nby rw [coeff_indicator, if_neg h]\nlemma constant_coeff_indicator (s : set \u2115) [semiring \u03b1] :\n  constant_coeff \u03b1 (indicator_series _ s) = if 0 \u2208 s then 1 else 0 :=\nrfl\n\nlemma two_series (i : \u2115) [semiring \u03b1] :\n  (1 + (X : power_series \u03b1)^i.succ) = indicator_series \u03b1 {0, i.succ} :=\nbegin\n  ext,\n  simp only [coeff_indicator, coeff_one, coeff_X_pow, set.mem_insert_iff, set.mem_singleton_iff,\n    map_add],\n  cases n with d,\n  { simp [(nat.succ_ne_zero i).symm] },\n  { simp [nat.succ_ne_zero d], },\nend\n\nlemma num_series' [field \u03b1] (i : \u2115) :\n  (1 - (X : power_series \u03b1)^(i+1))\u207b\u00b9 = indicator_series \u03b1 { k | i + 1 \u2223 k } :=\nbegin\n  rw power_series.inv_eq_iff_mul_eq_one,\n  { ext,\n    cases n,\n    { simp [mul_sub, zero_pow, constant_coeff_indicator] },\n    { simp only [coeff_one, if_neg n.succ_ne_zero, mul_sub, mul_one,\n                 coeff_indicator, linear_map.map_sub],\n      simp_rw [coeff_mul, coeff_X_pow, coeff_indicator, boole_mul, sum_ite, filter_filter,\n               sum_const_zero, add_zero, sum_const, nsmul_eq_mul, mul_one, sub_eq_iff_eq_add,\n               zero_add, filter_congr_decidable],\n      symmetry,\n      split_ifs,\n      { suffices :\n        ((nat.antidiagonal n.succ).filter (\u03bb (a : \u2115 \u00d7 \u2115), i + 1 \u2223 a.fst \u2227 a.snd = i + 1)).card = 1,\n        { simp only [set.mem_set_of_eq], rw this, norm_cast },\n        rw card_eq_one,\n        cases h with p hp,\n        refine \u27e8((i+1) * (p-1), i+1), _\u27e9,\n        ext \u27e8a\u2081, a\u2082\u27e9,\n        simp only [mem_filter, prod.mk.inj_iff, nat.mem_antidiagonal, mem_singleton],\n        split,\n        { rintro \u27e8a_left, \u27e8a, rfl\u27e9, rfl\u27e9,\n          refine \u27e8_, rfl\u27e9,\n          rw [nat.mul_sub_left_distrib, \u2190 hp, \u2190 a_left, mul_one, nat.add_sub_cancel] },\n        { rintro \u27e8rfl, rfl\u27e9,\n          cases p,\n          { rw mul_zero at hp, cases hp },\n          rw hp,\n          simp [nat.succ_eq_add_one, mul_add] } },\n      { suffices :\n        (filter (\u03bb (a : \u2115 \u00d7 \u2115), i + 1 \u2223 a.fst \u2227 a.snd = i + 1) (nat.antidiagonal n.succ)).card = 0,\n        { simp only [set.mem_set_of_eq], rw this, norm_cast },\n        rw card_eq_zero,\n        apply eq_empty_of_forall_not_mem,\n        simp only [prod.forall, mem_filter, not_and, nat.mem_antidiagonal],\n        rintro _ h\u2081 h\u2082 \u27e8a, rfl\u27e9 rfl,\n        apply h,\n        simp [\u2190 h\u2082] } } },\n  { simp [zero_pow] },\nend\n\ndef mk_odd : \u2115 \u21aa \u2115 := \u27e8\u03bb i, 2 * i + 1, \u03bb x y h, by linarith\u27e9\n\n-- The main workhorse of the partition theorem proof.\nlemma partial_gf_prop\n  (\u03b1 : Type*) [comm_semiring \u03b1] (n : \u2115) (s : finset \u2115)\n  (hs : \u2200 i \u2208 s, 0 < i) (c : \u2115 \u2192 set \u2115) (hc : \u2200 i \u2209 s, 0 \u2208 c i) :\n  (finset.card\n    ((univ : finset (nat.partition n)).filter\n      (\u03bb p, (\u2200 j, p.parts.count j \u2208 c j) \u2227 \u2200 j \u2208 p.parts, j \u2208 s)) : \u03b1) =\n        (coeff \u03b1 n) (\u220f (i : \u2115) in s, indicator_series \u03b1 ((* i) '' c i)) :=\nbegin\n  simp_rw [coeff_prod_range, coeff_indicator, prod_boole, sum_boole],\n  congr' 1,\n  refine finset.card_congr (\u03bb p _ i, multiset.count i p.parts \u2022 i) _ _ _,\n  { simp only [mem_filter, mem_cut, mem_univ, true_and, exists_prop, and_assoc, and_imp,\n               smul_eq_zero, function.embedding.coe_fn_mk, exists_imp_distrib],\n    rintro \u27e8p, hp\u2081, hp\u2082\u27e9 hp\u2083 hp\u2084,\n    dsimp only at *,\n    refine \u27e8_, _, _\u27e9,\n    { rw [\u2190hp\u2082, \u2190sum_multiset_count_of_subset p s (\u03bb x hx, hp\u2084 _ (multiset.mem_to_finset.mp hx))] },\n    { intros i hi,\n      left,\n      exact multiset.count_eq_zero_of_not_mem (mt (hp\u2084 i) hi) },\n    { exact \u03bb i hi, \u27e8_, hp\u2083 i, rfl\u27e9 } },\n  { intros p\u2081 p\u2082 hp\u2081 hp\u2082 h,\n    apply nat.partition.ext,\n    simp only [true_and, mem_univ, mem_filter] at hp\u2081 hp\u2082,\n    ext i,\n    rw function.funext_iff at h,\n    specialize h i,\n    cases i,\n    { rw multiset.count_eq_zero_of_not_mem,\n      rw multiset.count_eq_zero_of_not_mem,\n      intro a, exact nat.lt_irrefl 0 (hs 0 (hp\u2082.2 0 a)),\n      intro a, exact nat.lt_irrefl 0 (hs 0 (hp\u2081.2 0 a)) },\n    { rwa [nat.nsmul_eq_mul, nat.nsmul_eq_mul, nat.mul_left_inj i.succ_pos] at h } },\n  { simp only [mem_filter, mem_cut, mem_univ, exists_prop, true_and, and_assoc],\n    rintros f \u27e8hf\u2081, hf\u2082, hf\u2083\u27e9,\n    refine \u27e8\u27e8\u2211 i in s, multiset.repeat i (f i / i), _, _\u27e9, _, _, _\u27e9,\n    { intros i hi,\n      simp only [exists_prop, mem_sum, mem_map, function.embedding.coe_fn_mk] at hi,\n      rcases hi with \u27e8t, ht, z\u27e9,\n      apply hs,\n      rwa multiset.eq_of_mem_repeat z },\n    { simp_rw [multiset.sum_sum, multiset.sum_repeat, nat.nsmul_eq_mul, \u2190hf\u2081],\n      refine sum_congr rfl (\u03bb i hi, nat.div_mul_cancel _),\n      rcases hf\u2083 i hi with \u27e8w, hw, hw\u2082\u27e9,\n      rw \u2190 hw\u2082,\n      exact dvd_mul_left _ _ },\n    { intro i,\n      simp_rw [multiset.count_sum', multiset.count_repeat, sum_ite_eq],\n      split_ifs with h h,\n      { rcases hf\u2083 i h with \u27e8w, hw\u2081, hw\u2082\u27e9,\n        rwa [\u2190 hw\u2082, nat.mul_div_cancel _ (hs i h)] },\n      { exact hc _ h } },\n    { intros i hi,\n      rw mem_sum at hi,\n      rcases hi with \u27e8j, hj\u2081, hj\u2082\u27e9,\n      rwa multiset.eq_of_mem_repeat hj\u2082 },\n    { ext i,\n      simp_rw [multiset.count_sum', multiset.count_repeat, sum_ite_eq],\n      split_ifs,\n      { apply nat.div_mul_cancel,\n        rcases hf\u2083 i h with \u27e8w, hw, hw\u2082\u27e9,\n        apply dvd.intro_left _ hw\u2082 },\n      { rw [zero_smul, hf\u2082 i h] } } },\nend\n\nlemma partial_odd_gf_prop [field \u03b1] (n m : \u2115) :\n  (finset.card ((univ : finset (nat.partition n)).filter\n    (\u03bb p, \u2200 j \u2208 p.parts, j \u2208 (range m).map mk_odd)) : \u03b1) = coeff \u03b1 n (partial_odd_gf m) :=\nbegin\n  rw partial_odd_gf,\n  convert partial_gf_prop \u03b1 n ((range m).map mk_odd) _ (\u03bb _, set.univ) (\u03bb _ _, trivial) using 2,\n  { congr' 2,\n    simp only [true_and, forall_const, set.mem_univ] },\n  { rw finset.prod_map,\n    simp_rw num_series',\n    apply prod_congr rfl,\n    intros,\n    congr' 1,\n    ext k,\n    split,\n    { rintro \u27e8p, rfl\u27e9,\n      refine \u27e8p, \u27e8\u27e9, _\u27e9,\n      apply mul_comm },\n    rintro \u27e8a_w, -, rfl\u27e9,\n    apply dvd.intro_left a_w rfl },\n  { intro i,\n    rw mem_map,\n    rintro \u27e8a, -, rfl\u27e9,\n    exact nat.succ_pos _ },\nend\n\n/--  If m is big enough, the partial product's coefficient counts the number of odd partitions -/\ntheorem odd_gf_prop [field \u03b1] (n m : \u2115) (h : n < m * 2) :\n  (finset.card (nat.partition.odds n) : \u03b1) = coeff \u03b1 n (partial_odd_gf m) :=\nbegin\n  rw [\u2190 partial_odd_gf_prop],\n  congr' 2,\n  apply filter_congr,\n  intros p hp,\n  apply ball_congr,\n  intros i hi,\n  have hin : i \u2264 n,\n  { simpa [p.parts_sum] using multiset.single_le_sum (\u03bb _ _, nat.zero_le _) _ hi },\n  simp only [mk_odd, exists_prop, mem_range, function.embedding.coe_fn_mk, mem_map],\n  split,\n  { intro hi\u2082,\n    have := nat.mod_add_div i 2,\n    rw nat.not_even_iff at hi\u2082,\n    rw [hi\u2082, add_comm] at this,\n    refine \u27e8i / 2, _, this\u27e9,\n    rw nat.div_lt_iff_lt_mul _ _ zero_lt_two,\n    exact lt_of_le_of_lt hin h },\n  { rintro \u27e8a, -, rfl\u27e9,\n    rw even_iff_two_dvd,\n    apply nat.two_not_dvd_two_mul_add_one },\nend\n\nlemma partial_distinct_gf_prop [comm_semiring \u03b1] (n m : \u2115) :\n  (finset.card\n    ((univ : finset (nat.partition n)).filter\n      (\u03bb p, p.parts.nodup \u2227 \u2200 j \u2208 p.parts, j \u2208 (range m).map \u27e8nat.succ, nat.succ_injective\u27e9)) : \u03b1) =\n  coeff \u03b1 n (partial_distinct_gf m) :=\nbegin\n  rw partial_distinct_gf,\n  convert partial_gf_prop \u03b1 n\n    ((range m).map \u27e8nat.succ, nat.succ_injective\u27e9) _ (\u03bb _, {0, 1}) (\u03bb _ _, or.inl rfl) using 2,\n  { congr' 2,\n    ext p,\n    congr' 2,\n    apply propext,\n    rw multiset.nodup_iff_count_le_one,\n    apply forall_congr,\n    intro i,\n    rw [set.mem_insert_iff, set.mem_singleton_iff],\n    split,\n    { intro hi,\n      interval_cases (multiset.count i p.parts),\n      { left, assumption },\n      { right, assumption } },\n    { rintro (h | h),\n      { rw h, norm_num },\n      { rw h } } },\n  { rw finset.prod_map,\n    apply prod_congr rfl,\n    intros,\n    rw two_series,\n    congr' 1,\n    simp [set.image_pair] },\n  { simp only [mem_map, function.embedding.coe_fn_mk],\n    rintro i \u27e8_, _, rfl\u27e9,\n    apply nat.succ_pos }\nend\n\n/--\nIf m is big enough, the partial product's coefficient counts the number of distinct partitions\n-/\ntheorem distinct_gf_prop [comm_semiring \u03b1] (n m : \u2115) (h : n < m + 1) :\n  ((nat.partition.distincts n).card : \u03b1) = coeff \u03b1 n (partial_distinct_gf m) :=\nbegin\n  erw [\u2190 partial_distinct_gf_prop],\n  congr' 2,\n  apply filter_congr,\n  intros p hp,\n  apply (and_iff_left _).symm,\n  intros i hi,\n  have : i \u2264 n,\n  { simpa [p.parts_sum] using multiset.single_le_sum (\u03bb _ _, nat.zero_le _) _ hi },\n  simp only [mk_odd, exists_prop, mem_range, function.embedding.coe_fn_mk, mem_map],\n  refine \u27e8i-1, _, nat.succ_pred_eq_of_pos (p.parts_pos hi)\u27e9,\n  rw tsub_lt_iff_right (nat.one_le_iff_ne_zero.mpr (p.parts_pos hi).ne'),\n  exact lt_of_le_of_lt this h,\nend\n\n/--\nThe key proof idea for the partition theorem, showing that the generating functions for both\nsequences are ultimately the same (since the factor converges to 0 as m tends to infinity).\nIt's enough to not take the limit though, and just consider large enough `m`.\n-/\nlemma same_gf [field \u03b1] (m : \u2115) :\n  partial_odd_gf m * (range m).prod (\u03bb i, (1 - (X : power_series \u03b1)^(m+i+1))) =\n  partial_distinct_gf m :=\nbegin\n  rw [partial_odd_gf, partial_distinct_gf],\n  induction m with m ih,\n  { simp },\n\n  rw nat.succ_eq_add_one,\n\n  set \u03c0\u2080 : power_series \u03b1 := \u220f i in range m, (1 - X ^ (m + 1 + i + 1)) with h\u03c0\u2080,\n  set \u03c0\u2081 : power_series \u03b1 := \u220f i in range m, (1 - X ^ (2 * i + 1))\u207b\u00b9 with h\u03c0\u2081,\n  set \u03c0\u2082 : power_series \u03b1 := \u220f i in range m, (1 - X ^ (m + i + 1)) with h\u03c0\u2082,\n  set \u03c0\u2083 : power_series \u03b1 := \u220f i in range m, (1 + X ^ (i + 1)) with h\u03c0\u2083,\n  rw \u2190h\u03c0\u2083 at ih,\n\n  have h : constant_coeff \u03b1 (1 - X ^ (2 * m + 1)) \u2260 0,\n  { rw [ring_hom.map_sub, ring_hom.map_pow, constant_coeff_one, constant_coeff_X,\n      zero_pow (2 * m).succ_pos, sub_zero],\n    exact one_ne_zero },\n\n  calc (\u220f i in range (m + 1), (1 - X ^ (2 * i + 1))\u207b\u00b9) *\n          \u220f i in range (m + 1), (1 - X ^ (m + 1 + i + 1))\n      = \u03c0\u2081 * (1 - X ^ (2 * m + 1))\u207b\u00b9 * (\u03c0\u2080 * (1 - X ^ (m + 1 + m + 1))) :\n          by rw [prod_range_succ _ m, \u2190h\u03c0\u2081, prod_range_succ _ m, \u2190h\u03c0\u2080]\n  ... = \u03c0\u2081 * (1 - X ^ (2 * m + 1))\u207b\u00b9 * (\u03c0\u2080 * ((1 + X ^ (m + 1)) * (1 - X ^ (m + 1)))) :\n          by rw [\u2190sq_sub_sq, one_pow, add_assoc _ m 1, \u2190two_mul (m + 1), pow_mul']\n  ... = \u03c0\u2080 * (1 - X ^ (m + 1)) * (1 - X ^ (2 * m + 1))\u207b\u00b9 * (\u03c0\u2081 * (1 + X ^ (m + 1))) :\n          by ring\n  ... = (\u220f i in range (m + 1), (1 - X ^ (m + 1 + i))) * (1 - X ^ (2 * m + 1))\u207b\u00b9 *\n          (\u03c0\u2081 * (1 + X ^ (m + 1))) :\n          by { rw [prod_range_succ', add_zero, h\u03c0\u2080], simp_rw \u2190add_assoc }\n  ... = \u03c0\u2082 * (1 - X ^ (m + 1 + m)) * (1 - X ^ (2 * m + 1))\u207b\u00b9 * (\u03c0\u2081 * (1 + X ^ (m + 1))) :\n          by { rw [add_right_comm, h\u03c0\u2082, \u2190prod_range_succ], simp_rw [add_right_comm] }\n  ... = \u03c0\u2082 * (1 - X ^ (2 * m + 1)) * (1 - X ^ (2 * m + 1))\u207b\u00b9 * (\u03c0\u2081 * (1 + X ^ (m + 1))) :\n          by rw [two_mul, add_right_comm _ m 1]\n  ... = (1 - X ^ (2 * m + 1)) * (1 - X ^ (2 * m + 1))\u207b\u00b9 * \u03c0\u2082 * (\u03c0\u2081 * (1 + X ^ (m + 1))) :\n          by ring\n  ... = \u03c0\u2082 * (\u03c0\u2081 * (1 + X ^ (m + 1))) : by rw [power_series.mul_inv_cancel _ h, one_mul]\n  ... = \u03c0\u2081 * \u03c0\u2082 * (1 + X ^ (m + 1)) : by ring\n  ... = \u03c0\u2083 * (1 + X ^ (m + 1)) : by rw ih\n  ... = _ : by rw prod_range_succ,\nend\n\nlemma same_coeffs [field \u03b1] (m n : \u2115) (h : n \u2264 m) :\n  coeff \u03b1 n (partial_odd_gf m) = coeff \u03b1 n (partial_distinct_gf m) :=\nbegin\n  rw [\u2190 same_gf, coeff_mul_prod_one_sub_of_lt_order],\n  rintros i -,\n  rw order_X_pow,\n  exact_mod_cast nat.lt_succ_of_le (le_add_right h),\nend\n\ntheorem partition_theorem (n : \u2115) :\n  (nat.partition.odds n).card = (nat.partition.distincts n).card :=\nbegin\n  -- We need the counts to live in some field (which contains \u2115), so let's just use \u211a\n  suffices : ((nat.partition.odds n).card : \u211a) = (nat.partition.distincts n).card,\n  { exact_mod_cast this },\n  rw distinct_gf_prop n (n+1) (by linarith),\n  rw odd_gf_prop n (n+1) (by linarith),\n  apply same_coeffs (n+1) n n.le_succ,\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/archive/100-theorems-list/45_partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7173319188248113}}
{"text": "import data.set.basic\nimport data.set.lattice\n\n/-\n\u041f\u0435\u0440\u0432\u044b\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 Lean \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043a\u0430\u0447\u0430\u043b\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e `leanproject`, \u0442\u043e \u0443 \u0432\u0430\u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 _target/deps/mathlib \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 mathlib:\nGitHub: https://github.com/leanprover-community/mathlib\n\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f: https://leanprover-community.github.io/mathlib_docs/\n\n\u0412 VSCode \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ctrl + Click \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0438\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043b\u0435\u043c\u043c\u044b/\u0444\u0443\u043d\u043a\u0446\u0438\u0438.\n\nLean \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 Unicode \u0438 \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u0430\u043d\u0434 \u0438\u0437 LaTeX! \u041d\u0430\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u0443\u0440\u0441\u043e\u0440 \u043d\u0430 \u0441\u0438\u043c\u0432\u043e\u043b, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0431\u0440\u0430\u0442\u044c.\n\n\u0427\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b:\n\u2192 = \\r, \\to         \u2190 = \\l              \u2194 = \\iff, \\lr\n\u2200 = \\all, \\forall   \u2203 = \\ex, \\exists    \u2208 = \\in, \\mem\n\u00ac = \\not, \\neg      \u27e8 = \\<,             \u27e9 = \\>\n\u2260 = \\neq,           \u2264 = \\le             \u2265 = \\ge\n\u2286 = \\ss, \\sub       \u2282 = \\ssub           S\u1d9c = \\compl, \\^c\n\u2227 = \\and, \\wedge    \u2228 = \\or, \\vee       \u22a2 = \\goal, \\|-\n\u2229 = \\cap, \\inter    \u222a = \\cup, \\union\n -/\n\n-- \n\n-- `variables (X : Type) (x : X)` \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0445 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u0445: \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 `x` \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043b\u0435\u043c\u043c\u044b/\u0442\u0435\u043e\u0440\u0435\u043c\u044b, \u043e\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c\n-- \u0412 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043a\u0430\u0445 (`{X : Type}`) \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043f\u0440\u043e \u043d\u0438\u0445 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \nvariables {X : Type} (A B C : set X) (p q : X)\n\n-- \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e, `set X` \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 `X` \u0432 `Prop` (`X \u2192 Prop`). \u0415\u0441\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c Ctrl + Click \u043f\u043e `set`, \u0442\u043e \u0432\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442\u0435 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e `set`, \u0430 \u0442\u0430\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e a \u2208 X \u2194 X a\n-- `a \u2208 X` (\\in \u0438\u043b\u0438 \\mem) \u044d\u0442\u043e \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e `X a`\nexample : p \u2208 A = A p :=\nbegin\n  refl,\nend\n\n-- \u0412\u043d\u0435 tactic mode \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f `rfl`\nexample : p \u2208 A = A p := rfl\n\n-- \u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430: `\u2205` (\\empty) - \u043f\u0443\u0441\u0442\u043e\u0435 \u0438 `univ` - \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0435\n-- \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e, `p \u2208 \u2205 = false`, `p \u2208 univ = true`  \nlemma mem_empty : p \u2208 (\u2205 : set X) \u2194 false :=\nbegin\n  refl,\nend\n\nlemma mem_univ : p \u2208 (set.univ : set X) \u2194 true :=\nbegin\n  refl,\nend\n\n-- `lemma` \u0438 `theorem` \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u043b\u044f \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439 (Prop), `def` \u0434\u043b\u044f \u043d\u043e\u0432\u044b\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 (\u0442\u0438\u043f\u043e\u0432 \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439)\n-- \u041a\u043e \u0432\u0441\u0435\u043c\u0443, \u0447\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 namespace test, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u043c test\n-- \u041a\u043e\u043c\u0430\u043d\u0434\u0430 #check \u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 begin-end \u0431\u043b\u043e\u043a\u0430 \u043d\u0435\u043b\u044c\u0437\u044f)\n-- \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 `\u2200 (X : Type) (A : set X) (p : X)`, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0448\u043b\u0438 \u0438\u0437 `variables`\n-- `(B C : set X)` \u0437\u0434\u0435\u0441\u044c \u043d\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e `B` \u0438 `C` \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f\nnamespace test\nlemma obviously_false : p \u2208 A \u2194 \u00ac p \u2208 A := sorry\nend test\n\n#check test.obviously_false\n\n-- `A \u2286 B` \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e `\u2200 \u2983x\u2984, x \u2208 A \u2192 x \u2208 B` \n-- \u041d\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 `\u2200 \u2983x\u2984, x \u2208 A \u2192 x \u2208 B` \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 `x` \u0438 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e `x \u2208 A`, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e, \u0447\u0442\u043e `x \u2208 B` (`x` - \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c `x \u2208 A`)\nlemma subset_def : A \u2286 B = \u2200 x : X, x \u2208 A \u2192 x \u2208 B := rfl\n\nlemma subset_refl : A \u2286 A :=\nbegin\n  -- \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0441 `intro x`, `rw subset_def` \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e (\u043d\u043e \u043f\u043e\u043a\u0430 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438, \u043c\u043e\u0436\u043d\u043e \u0438\u0445 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u044f\u0432\u043d\u043e)\n  sorry,\nend\n\nlemma subset_trans : A \u2286 B \u2192 B \u2286 C \u2192 A \u2286 C :=\nbegin\n  sorry,\nend\n\n-- \u0414\u0432\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0432\u043d\u044b, \u0435\u0441\u043b\u0438 \u0432 \u043d\u0438\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\n-- \"ext\" \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 extensionality, \"\u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0440\u0430\u0432\u043d\u044b, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u043d\u0435\u0448\u043d\u0435 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\"\n-- \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0444\u0443\u043d\u043a\u0446\u0438\u0439, ...), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0442\u0430\u043a\u0442\u0438\u043a\u0443 `ext`\nlemma set_eq_def : A = B \u2194 \u2200 x, x \u2208 A \u2194 x \u2208 B := set.ext_iff\n-- A \u2194 B \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0430\u0440\u0430 \u27e8A \u2192 B, B \u2192 A\u27e9 (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0437\u0434\u0435\u0441\u044c \u0443\u0433\u043b\u043e\u0432\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \\< \\>)\n\nlemma subset_antisymm : A \u2286 B \u2192 B \u2286 A \u2192 A = B :=\nbegin\n  sorry,\nend\n\n-- term mode, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u043c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043d\u0435 \u0442\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438, \u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e\nexample : A \u2286 B \u2192 B \u2286 A \u2192 A = B := \u03bb hAB hBA, set.ext_iff.2 (\u03bb x, \u27e8\u03bb xA, hAB xA, \u03bb xB, hBA xB\u27e9)\n\n-- \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0431\u044b\u0432\u0430\u044e\u0442 \u044f\u0432\u043d\u044b\u0435 \u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0435\n-- \u0412 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e `:` \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b\n-- `lemma f (h : \u03b1) : \u03b2` \u043f\u043e \u0441\u0443\u0442\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e `lemma f : \u03b1 \u2192 \u03b2`\n-- \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438, \u0435\u0441\u043b\u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \n-- \u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0442\u0438\u043f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (\u0438 \u044f\u0432\u043d\u044b\u0445, \u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0445)\n\nlemma implicit_args {X} {A B : set X} {x : X} : x \u2208 A \u2192 x \u2208 B := sorry\n#check implicit_args\n#check @implicit_args\n\n\nlemma subset_trans' (X : Type) (A B C : set X) : A \u2286 B \u2192 B \u2286 C \u2192 A \u2286 C := sorry\nlemma subset_trans'' {X : Type} {A B C : set X} : A \u2286 B \u2192 B \u2286 C \u2192 A \u2286 C := sorry\n\n#check subset_trans\n#check subset_trans'\n#check subset_trans''\n-- \"@\" \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u044f\u0432\u043d\u044b\u043c\u0438\n#check @subset_trans''\n\n-- \u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\n\nlemma union_def : (p \u2208 A \u222a B) = (p \u2208 A \u2228 p \u2208 B) := rfl\nlemma inter_def : (p \u2208 A \u2229 B) = (p \u2208 A \u2227 p \u2208 B) := rfl\n\n-- \u0422\u0430\u043a\u0442\u0438\u043a\u0430 `rcases` \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0437\u0430 \u043e\u0434\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\n-- \u0415\u0441\u043b\u0438 `h : \u03b1 \u2227 \u03b2 \u2227 \u03b3`, \u0442\u043e `rcases h with \u27e8ha, hb, hc\u27e9` \u0434\u0430\u0441\u0442 \u0442\u0440\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b\n-- \u0415\u0441\u043b\u0438 `h : \u03b1 \u2228 \u03b2`, \u0442\u043e `rcases h with (ha | hb)` \u0434\u0430\u0441\u0442 \u0434\u0432\u0435 \u0446\u0435\u043b\u0438 \u0441 `ha : \u03b1` \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438 `hb : \u03b2` \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439\n-- \u0415\u0441\u043b\u0438 `h : \nexample : (p \u2208 A \u2228 p \u2208 B) \u2227 (p \u2208 C) \u2192 p \u2208 (A \u222a B) \u2229 C :=\nbegin\n  intro h,\n  rcases h with \u27e8(hA | hB), hC\u27e9,\n  -- \u0426\u0435\u043b\u044c: `\u22a2 p \u2208 (A \u222a B) \u2229 C`, \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e `exact` \u0438 `or.inl hA` \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\n  exact \u27e8or.inl hA, hC\u27e9,\n  -- \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 `or.inr hB`\n  exact \u27e8or.inr hB, hC\u27e9,   \nend\n\n-- \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u0432\u0435\u0440\u043d\u043e \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e\nexample : (p \u2208 A \u2228 p \u2208 B) \u2227 (p \u2208 C) \u2192 p \u2208 (A \u222a B) \u2229 C := id\n\n-- \u0422\u0430\u043a\u0442\u0438\u043a\u0430 `rintro` = `intros` + `rcases`: \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 `intros` \u0438 \u0441\u0440\u0430\u0437\u0443 `rcases` \u043a\u043e \u0432\u0441\u0435\u043c \u043d\u043e\u0432\u044b\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\n-- \u041a\u043e\u0433\u0434\u0430 \u0446\u0435\u043b\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a `\u03b1 \u2227 \u03b2 \u2192 \u03b3`, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0430\u0442\u044c `intro h`, `cases h with ha hb`, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c `rintro \u27e8hA, hB\u27e9` \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c `hA : \u03b1`, `hB : \u03b2` \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435\nexample : p \u2208 A \u2228 (p \u2208 B \u2227 p \u2208 C) \u2192 p \u2208 A \u222a (B \u2229 C) :=\nbegin\n  rintro (pA | \u27e8pB, pC\u27e9),\n  -- \u0434\u0432\u0435 \u0446\u0435\u043b\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0443\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c `or`\n  left, exact pA,\n  right, exact \u27e8pB, pC\u27e9,\nend\n\nlemma inter_assoc (A B C : set X) : (A \u2229 B) \u2229 C = A \u2229 (B \u2229 C) :=\nbegin\n  sorry,\nend \n\nlemma union_assoc (A B C : set X) : (A \u222a B) \u222a C = A \u222a (B \u222a C) :=\nbegin\n  sorry,\nend\n\n-- \u0422\u0430\u043a\u0442\u0438\u043a\u0430 `all_goals {...}` \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0431\u043b\u043e\u043a \u043a\u043e \u0432\u0441\u0435\u043c \u0446\u0435\u043b\u044f\u043c\nexample (A B C : set X) : (A \u222a B) \u222a C = A \u222a (B \u222a C) :=\nbegin\n  ext x, split,\n  all_goals {repeat {rw set.mem_union}, tauto},\nend\n\nlemma union_eq_of_subset (hAB : A \u2286 B) : A \u222a B = B :=\nbegin\n  sorry,\nend\n\nlemma inter_eq_iff_subset : A \u2286 B \u2194 A \u2229 B = A :=\nbegin\n  sorry,\nend\n\n-- `A\u1d9c` (A\\^c) \u044d\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 `A`, \u0442\u043e \u0435\u0441\u0442\u044c, `p \u2208 A\u1d9c = p \u2209 A = \u00acp \u2208 A`\n#check @set.mem_compl\nexample : p \u2209 A  = \u00acp \u2208 A := rfl\nexample : p \u2208 A\u1d9c = (p \u2209 A) := rfl\n\nlemma compl_subset_compl_of_subset (hAB : A \u2286 B) : B\u1d9c \u2286 A\u1d9c :=\nbegin\n  sorry,\nend\n\n-- \u0417\u0430\u043a\u043e\u043d \u0434\u0435 \u041c\u043e\u0440\u0433\u0430\u043d\u0430\n-- \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0442\u0430\u043a\u0442\u0438\u043a\u0438: `simp at h \u22a2` \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0443 \u0438 \u0446\u0435\u043b\u044c (\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c `simp at *`, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u0440\u043e\u0449\u0430\u0442\u044c \u0432\u0441\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b \u0438 \u0446\u0435\u043b\u044c)\n-- `tauto` \u0440\u0435\u0448\u0430\u0435\u0442 \u0446\u0435\u043b\u0438 \u0432 \u043b\u043e\u0433\u0438\u043a\u0435 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0439, `tauto!` \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043a\u043e\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e\nlemma compl_inter_eq_compl_union_compl : (A \u2229 B)\u1d9c = A\u1d9c \u222a B\u1d9c :=\nbegin\n  sorry,\nend\n\n-- \u0414\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f/\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b:\n-- \u041b\u0435\u043c\u043c\u044b \u043f\u0440\u043e \u043d\u0438\u0445 \u043b\u0435\u0436\u0430\u0442 \u0432 `data.set.lattice`\n-- 1. \u0415\u0441\u043b\u0438 `f : \u03b9 \u2192 set S`, \u0442\u043e `\u22c3 (i : \u03b9), f i` \u0440\u0430\u0432\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e `f i`, \u0433\u0434\u0435 `i` \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0442\u0438\u043f\u0430 `\u03b9`\n-- `x` \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 `\u22c3 (i : \u03b9), f i` \u2194 `\u2203 i, x \u2208 f i`\n-- \u041b\u0435\u043c\u043c\u044b \u043f\u0440\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 `Union` \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \n\nlemma Union_def {S \u03b9} {F : \u03b9 \u2192 set S} : set.Union F = \u22c3 i, F i :=\nbegin\n  refl,\nend \n\nlemma mem_Union {S \u03b9} {x : S} {F : \u03b9 \u2192 set S} : (x \u2208 \u22c3 i, F i) \u2194 (\u2203 i, x \u2208 F i) := \nbegin\n  exact set.mem_Union,\nend\n\n-- 2. `bUnion` (\u043e\u0442 bounded union) \u0431\u0435\u0440\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e `i`, \u043b\u0435\u0436\u0430\u0449\u0438\u043c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 `I : set \u03b9`\n-- \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u043e\u0442\u0430\u0446\u0438\u044e `\u2203 i \u2208 I`, \u044d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 `\u2203 i (H : i \u2208 I)`, \u0442\u043e \u0435\u0441\u0442\u044c, \"\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 `i` \u0438 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e `i \u2208 I`\"\nlemma mem_bUnion {S \u03b9} {x : S} {F : \u03b9 \u2192 set S} {I : set \u03b9} : (x \u2208 \u22c3 i \u2208 I, F i) \u2194 (\u2203 i \u2208 I, x \u2208 F i) := \nbegin\n  exact set.mem_bUnion_iff,\nend\n\n-- 3. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c (s : set (set S)), \u0442\u043e `\u22c3\u2080 s : set S` \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0432\u0441\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0432 `s`\n-- \u041b\u0435\u043c\u043c\u044b \u043f\u0440\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 `sUnion` \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \nlemma mem_sUnion {S} {x : S} {s : set (set S)} : (x \u2208 \u22c3\u2080 s) \u2194 (\u2203 t \u2208 s, x \u2208 t) := \nbegin\n  exact set.mem_sUnion, \nend\n\n-- \u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 `S` \u043a\u0430\u043a \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0440\u0430\u0432\u043d\u043e `S`\ndef supersets {X : Type} (S : set X) : set (set X) := {T | S \u2286 T} \n\nlemma supersets_sInter {S : set X} : \u22c2\u2080 (supersets S) = S :=\nbegin\n  sorry,\nend  ", "meta": {"author": "VArtem", "repo": "lean-itmo", "sha": "dc44cd06f9f5b984d051831b3aaa7364e64c2dc4", "save_path": "github-repos/lean/VArtem-lean-itmo", "path": "github-repos/lean/VArtem-lean-itmo/lean-itmo-dc44cd06f9f5b984d051831b3aaa7364e64c2dc4/src/week-02/e01-sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7173319171564291}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura, Mario Carneiro\n\nType class for encodable Types.\nNote that every encodable Type is countable.\n-/\nimport data.equiv.nat\nopen option list nat function\n\n/-- An encodable type is a \"constructively countable\" type. This is where\n  we have an explicit injection `encode : \u03b1 \u2192 nat` and a partial inverse\n  `decode : nat \u2192 option \u03b1`. This makes the range of `encode` decidable,\n  although it is not decidable if `\u03b1` is finite or not. -/\nclass encodable (\u03b1 : Type*) :=\n(encode : \u03b1 \u2192 nat) (decode : nat \u2192 option \u03b1) (encodek : \u2200 a, decode (encode a) = some a)\n\nnamespace encodable\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nuniverse u\nopen encodable\n\ntheorem encode_injective [encodable \u03b1] : function.injective (@encode \u03b1 _)\n| x y e := option.some.inj $ by rw [\u2190 encodek, e, encodek]\n\n/- This is not set as an instance because this is usually not the best way\n  to infer decidability. -/\ndef decidable_eq_of_encodable (\u03b1) [encodable \u03b1] : decidable_eq \u03b1\n| a b := decidable_of_iff _ encode_injective.eq_iff\n\ndef of_left_injection [encodable \u03b1]\n  (f : \u03b2 \u2192 \u03b1) (finv : \u03b1 \u2192 option \u03b2) (linv : \u2200 b, finv (f b) = some b) : encodable \u03b2 :=\n\u27e8\u03bb b, encode (f b),\n \u03bb n, (decode \u03b1 n).bind finv,\n \u03bb b, by simp [encodable.encodek, linv]\u27e9\n\ndef of_left_inverse [encodable \u03b1]\n  (f : \u03b2 \u2192 \u03b1) (finv : \u03b1 \u2192 \u03b2) (linv : \u2200 b, finv (f b) = b) : encodable \u03b2 :=\nof_left_injection f (some \u2218 finv) (\u03bb b, congr_arg some (linv b))\n\ndef of_equiv (\u03b1) [encodable \u03b1] (e : \u03b2 \u2243 \u03b1) : encodable \u03b2 :=\nof_left_inverse e e.symm e.left_inv\n\n@[simp] theorem encode_of_equiv {\u03b1 \u03b2} [encodable \u03b1] (e : \u03b2 \u2243 \u03b1) (b : \u03b2) :\n  @encode _ (of_equiv _ e) b = encode (e b) := rfl\n\n@[simp] theorem decode_of_equiv {\u03b1 \u03b2} [encodable \u03b1] (e : \u03b2 \u2243 \u03b1) (n : \u2115) :\n  @decode _ (of_equiv _ e) n = (decode \u03b1 n).map e.symm := rfl\n\ninstance nat : encodable nat :=\n\u27e8id, some, \u03bb a, rfl\u27e9\n\n@[simp] theorem encode_nat (n : \u2115) : encode n = n := rfl\n@[simp] theorem decode_nat (n : \u2115) : decode \u2115 n = some n := rfl\n\ninstance empty : encodable empty :=\n\u27e8\u03bb a, a.rec _, \u03bb n, none, \u03bb a, a.rec _\u27e9\n\ninstance unit : encodable punit :=\n\u27e8\u03bb_, zero, \u03bbn, nat.cases_on n (some punit.star) (\u03bb _, none), \u03bb\u27e8\u27e9, by simp\u27e9\n\n@[simp] theorem encode_star : encode punit.star = 0 := rfl\n\n@[simp] theorem decode_unit_zero : decode punit 0 = some punit.star := rfl\n@[simp] theorem decode_unit_succ (n) : decode punit (succ n) = none := rfl\n\ninstance option {\u03b1 : Type*} [h : encodable \u03b1] : encodable (option \u03b1) :=\n\u27e8\u03bb o, option.cases_on o nat.zero (\u03bb a, succ (encode a)),\n \u03bb n, nat.cases_on n (some none) (\u03bb m, (decode \u03b1 m).map some),\n \u03bb o, by cases o; dsimp; simp [encodek, nat.succ_ne_zero]\u27e9\n\n@[simp] theorem encode_none [encodable \u03b1] : encode (@none \u03b1) = 0 := rfl\n@[simp] theorem encode_some [encodable \u03b1] (a : \u03b1) :\n  encode (some a) = succ (encode a) := rfl\n\n@[simp] theorem decode_option_zero [encodable \u03b1] : decode (option \u03b1) 0 = some none := rfl\n@[simp] theorem decode_option_succ [encodable \u03b1] (n) :\n  decode (option \u03b1) (succ n) = (decode \u03b1 n).map some := rfl\n\ndef decode2 (\u03b1) [encodable \u03b1] (n : \u2115) : option \u03b1 :=\n(decode \u03b1 n).bind (option.guard (\u03bb a, encode a = n))\n\ntheorem mem_decode2' [encodable \u03b1] {n : \u2115} {a : \u03b1} :\n  a \u2208 decode2 \u03b1 n \u2194 a \u2208 decode \u03b1 n \u2227 encode a = n :=\nby simp [decode2]; exact\n\u27e8\u03bb \u27e8_, h\u2081, rfl, h\u2082\u27e9, \u27e8h\u2081, h\u2082\u27e9, \u03bb \u27e8h\u2081, h\u2082\u27e9, \u27e8_, h\u2081, rfl, h\u2082\u27e9\u27e9\n\ntheorem mem_decode2 [encodable \u03b1] {n : \u2115} {a : \u03b1} :\n  a \u2208 decode2 \u03b1 n \u2194 encode a = n :=\nmem_decode2'.trans (and_iff_right_of_imp $ \u03bb e, e \u25b8 encodek _)\n\ntheorem decode2_is_partial_inv [encodable \u03b1] : is_partial_inv encode (decode2 \u03b1) :=\n\u03bb a n, mem_decode2\n\ntheorem decode2_inj [encodable \u03b1] {n : \u2115} {a\u2081 a\u2082 : \u03b1}\n  (h\u2081 : a\u2081 \u2208 decode2 \u03b1 n) (h\u2082 : a\u2082 \u2208 decode2 \u03b1 n) : a\u2081 = a\u2082 :=\nencode_injective $ (mem_decode2.1 h\u2081).trans (mem_decode2.1 h\u2082).symm\n\ntheorem encodek2 [encodable \u03b1] (a : \u03b1) : decode2 \u03b1 (encode a) = some a :=\nmem_decode2.2 rfl\n\nsection sum\nvariables [encodable \u03b1] [encodable \u03b2]\n\ndef encode_sum : \u03b1 \u2295 \u03b2 \u2192 nat\n| (sum.inl a) := bit0 $ encode a\n| (sum.inr b) := bit1 $ encode b\n\ndef decode_sum (n : nat) : option (\u03b1 \u2295 \u03b2) :=\nmatch bodd_div2 n with\n| (ff, m) := (decode \u03b1 m).map sum.inl\n| (tt, m) := (decode \u03b2 m).map sum.inr\nend\n\ninstance sum : encodable (\u03b1 \u2295 \u03b2) :=\n\u27e8encode_sum, decode_sum, \u03bb s,\n  by cases s; simp [encode_sum, decode_sum, encodek]; refl\u27e9\n\n@[simp] theorem encode_inl (a : \u03b1) :\n  @encode (\u03b1 \u2295 \u03b2) _ (sum.inl a) = bit0 (encode a) := rfl\n@[simp] theorem encode_inr (b : \u03b2) :\n  @encode (\u03b1 \u2295 \u03b2) _ (sum.inr b) = bit1 (encode b) := rfl\n@[simp] theorem decode_sum_val (n : \u2115) :\n  decode (\u03b1 \u2295 \u03b2) n = decode_sum n := rfl\n\nend sum\n\ninstance bool : encodable bool :=\nof_equiv (unit \u2295 unit) equiv.bool_equiv_punit_sum_punit\n\n@[simp] theorem encode_tt : encode tt = 1 := rfl\n@[simp] theorem encode_ff : encode ff = 0 := rfl\n\n@[simp] theorem decode_zero : decode bool 0 = some ff := rfl\n@[simp] theorem decode_one : decode bool 1 = some tt := rfl\n\ntheorem decode_ge_two (n) (h : 2 \u2264 n) : decode bool n = none :=\nbegin\n  suffices : decode_sum n = none,\n  { change (decode_sum n).map _ = none, rw this, refl },\n  have : 1 \u2264 div2 n,\n  { rw [div2_val, nat.le_div_iff_mul_le],\n    exacts [h, dec_trivial] },\n  cases exists_eq_succ_of_ne_zero (ne_of_gt this) with m e,\n  simp [decode_sum]; cases bodd n; simp [decode_sum]; rw e; refl\nend\n\nsection sigma\nvariables {\u03b3 : \u03b1 \u2192 Type*} [encodable \u03b1] [\u2200 a, encodable (\u03b3 a)]\n\ndef encode_sigma : sigma \u03b3 \u2192 \u2115\n| \u27e8a, b\u27e9 := mkpair (encode a) (encode b)\n\ndef decode_sigma (n : \u2115) : option (sigma \u03b3) :=\nlet (n\u2081, n\u2082) := unpair n in\n(decode \u03b1 n\u2081).bind $ \u03bb a, (decode (\u03b3 a) n\u2082).map $ sigma.mk a\n\ninstance sigma : encodable (sigma \u03b3) :=\n\u27e8encode_sigma, decode_sigma, \u03bb \u27e8a, b\u27e9,\n  by simp [encode_sigma, decode_sigma, unpair_mkpair, encodek]\u27e9\n\n@[simp] theorem decode_sigma_val (n : \u2115) : decode (sigma \u03b3) n =\n  (decode \u03b1 n.unpair.1).bind (\u03bb a, (decode (\u03b3 a) n.unpair.2).map $ sigma.mk a) :=\nshow decode_sigma._match_1 _ = _, by cases n.unpair; refl\n\n@[simp] theorem encode_sigma_val (a b) : @encode (sigma \u03b3) _ \u27e8a, b\u27e9 =\n  mkpair (encode a) (encode b) := rfl\n\nend sigma\n\nsection prod\nvariables [encodable \u03b1] [encodable \u03b2]\n\ninstance prod : encodable (\u03b1 \u00d7 \u03b2) :=\nof_equiv _ (equiv.sigma_equiv_prod \u03b1 \u03b2).symm\n\n@[simp] theorem decode_prod_val (n : \u2115) : decode (\u03b1 \u00d7 \u03b2) n =\n  (decode \u03b1 n.unpair.1).bind (\u03bb a, (decode \u03b2 n.unpair.2).map $ prod.mk a) :=\nshow (decode (sigma (\u03bb _, \u03b2)) n).map (equiv.sigma_equiv_prod \u03b1 \u03b2) = _,\nby simp; cases decode \u03b1 n.unpair.1; simp;\n   cases decode \u03b2 n.unpair.2; refl\n\n@[simp] theorem encode_prod_val (a b) : @encode (\u03b1 \u00d7 \u03b2) _ (a, b) =\n  mkpair (encode a) (encode b) := rfl\n\nend prod\n\nsection subtype\nopen subtype decidable\nvariable {P : \u03b1 \u2192 Prop}\nvariable [encA : encodable \u03b1]\nvariable [decP : decidable_pred P]\n\ninclude encA\ndef encode_subtype : {a : \u03b1 // P a} \u2192 nat\n| \u27e8v, h\u27e9 := encode v\n\ninclude decP\ndef decode_subtype (v : nat) : option {a : \u03b1 // P a} :=\n(decode \u03b1 v).bind $ \u03bb a,\nif h : P a then some \u27e8a, h\u27e9 else none\n\ninstance subtype : encodable {a : \u03b1 // P a} :=\n\u27e8encode_subtype, decode_subtype,\n \u03bb \u27e8v, h\u27e9, by simp [encode_subtype, decode_subtype, encodek, h]\u27e9\nend subtype\n\ninstance fin (n) : encodable (fin n) :=\nof_equiv _ (equiv.fin_equiv_subtype _)\n\ninstance int : encodable \u2124 :=\nof_equiv _ equiv.int_equiv_nat\n\ninstance ulift [encodable \u03b1] : encodable (ulift \u03b1) :=\nof_equiv _ equiv.ulift\n\ninstance plift [encodable \u03b1] : encodable (plift \u03b1) :=\nof_equiv _ equiv.plift\n\nnoncomputable def of_inj [encodable \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : injective f) : encodable \u03b1 :=\nof_left_injection f (partial_inv f) (\u03bb x, (partial_inv_of_injective hf _ _).2 rfl)\n\nend encodable\n\n/-\nChoice function for encodable types and decidable predicates.\nWe provide the following API\n\nchoose      {\u03b1 : Type*} {p : \u03b1 \u2192 Prop} [c : encodable \u03b1] [d : decidable_pred p] : (\u2203 x, p x) \u2192 \u03b1 :=\nchoose_spec {\u03b1 : Type*} {p : \u03b1 \u2192 Prop} [c : encodable \u03b1] [d : decidable_pred p] (ex : \u2203 x, p x) : p (choose ex) :=\n-/\n\nnamespace encodable\nsection find_a\nvariables {\u03b1 : Type*} (p : \u03b1 \u2192 Prop) [encodable \u03b1] [decidable_pred p]\n\nprivate def good : option \u03b1 \u2192 Prop\n| (some a) := p a\n| none     := false\n\nprivate def decidable_good : decidable_pred (good p)\n| n := by cases n; unfold good; apply_instance\nlocal attribute [instance] decidable_good\n\nopen encodable\nvariable {p}\n\ndef choose_x (h : \u2203 x, p x) : {a:\u03b1 // p a} :=\nhave \u2203 n, good p (decode \u03b1 n), from\nlet \u27e8w, pw\u27e9 := h in \u27e8encode w, by simp [good, encodek, pw]\u27e9,\nmatch _, nat.find_spec this : \u2200 o, good p o \u2192 {a // p a} with\n| some a, h := \u27e8a, h\u27e9\nend\n\ndef choose (h : \u2203 x, p x) : \u03b1 := (choose_x h).1\n\nlemma choose_spec (h : \u2203 x, p x) : p (choose h) := (choose_x h).2\n\nend find_a\n\ntheorem axiom_of_choice {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type*} {R : \u03a0 x, \u03b2 x \u2192 Prop}\n  [\u03a0 a, encodable (\u03b2 a)] [\u2200 x y, decidable (R x y)]\n  (H : \u2200x, \u2203y, R x y) : \u2203f:\u03a0a, \u03b2 a, \u2200x, R x (f x) :=\n\u27e8\u03bb x, choose (H x), \u03bb x, choose_spec (H x)\u27e9\n\ntheorem skolem {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type*} {P : \u03a0 x, \u03b2 x \u2192 Prop}\n  [c : \u03a0 a, encodable (\u03b2 a)] [d : \u2200 x y, decidable (P x y)] :\n  (\u2200x, \u2203y, P x y) \u2194 \u2203f : \u03a0 a, \u03b2 a, (\u2200x, P x (f x)) :=\n\u27e8axiom_of_choice, \u03bb \u27e8f, H\u27e9 x, \u27e8_, H x\u27e9\u27e9\n\nend encodable\n\nnamespace quot\nopen encodable\nvariables {\u03b1 : Type*} {s : setoid \u03b1} [@decidable_rel \u03b1 (\u2248)] [encodable \u03b1]\n\n-- Choose equivalence class representative\ndef rep (q : quotient s) : \u03b1 :=\nchoose (exists_rep q)\n\ntheorem rep_spec (q : quotient s) : \u27e6rep q\u27e7 = q :=\nchoose_spec (exists_rep q)\n\ndef encodable_quotient : encodable (quotient s) :=\n\u27e8\u03bb q, encode (rep q),\n \u03bb n, quotient.mk <$> decode \u03b1 n,\n by rintros \u27e8l\u27e9; rw encodek; exact congr_arg some (rep_spec _)\u27e9\n\nend quot\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/equiv/encodable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357569, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7173319156179397}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\nimport data.zmod.basic\nimport data.equiv.mul_add\nimport tactic.group\n\n/-!\n# Racks and Quandles\n\nThis file defines racks and quandles, algebraic structures for sets\nthat bijectively act on themselves with a self-distributivity\nproperty.  If `R` is a rack and `act : R \u2192 (R \u2243 R)` is the self-action,\nthen the self-distributivity is, equivalently, that\n```\nact (act x y) = act x * act y * (act x)\u207b\u00b9\n```\nwhere multiplication is composition in `R \u2243 R` as a group.\nQuandles are racks such that `act x x = x` for all `x`.\n\nOne example of a quandle (not yet in mathlib) is the action of a Lie\nalgebra on itself, defined by `act x y = Ad (exp x) y`.\n\nQuandles and racks were independently developed by multiple\nmathematicians.  David Joyce introduced quandles in his thesis\n[Joyce1982] to define an algebraic invariant of knot and link\ncomplements that is analogous to the fundamental group of the\nexterior, and he showed that the quandle associated to an oriented\nknot is invariant up to orientation-reversed mirror image.  Racks were\nused by Fenn and Rourke for framed codimension-2 knots and\nlinks.[FennRourke1992]\n\nThe name \"rack\" came from wordplay by Conway and Wraith for the \"wrack\nand ruin\" of forgetting everything but the conjugation operation for a\ngroup.\n\n## Main definitions\n\n* `shelf` is a type with a self-distributive action\n* `rack` is a shelf whose action for each element is invertible\n* `quandle` is a rack whose action for an element fixes that element\n* `quandle.conj` defines a quandle of a group acting on itself by conjugation.\n* `shelf_hom` is homomorphisms of shelves, racks, and quandles.\n* `rack.envel_group` gives the universal group the rack maps to as a conjugation quandle.\n* `rack.opp` gives the rack with the action replaced by its inverse.\n\n## Main statements\n* `rack.envel_group` is left adjoint to `quandle.conj` (`to_envel_group.map`).\n  The universality statements are `to_envel_group.univ` and `to_envel_group.univ_uniq`.\n\n## Notation\n\nThe following notation is localized in `quandles`:\n\n* `x \u25c3 y` is `shelf.act x y`\n* `x \u25c3\u207b\u00b9 y` is `rack.inv_act x y`\n* `S \u2192\u25c3 S'` is `shelf_hom S S'`\n\nUse `open_locale quandles` to use these.\n\n## Todo\n\n* If `g` is the Lie algebra of a Lie group `G`, then `(x \u25c3 y) = Ad (exp x) x` forms a quandle.\n* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,\n  forming a quandle.\n* Alexander quandle with `a \u25c3 b = t * b + (1 - t) * b`, with `a` and `b` elements\n  of a module over `Z[t,t\u207b\u00b9]`.\n* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by\n  `yH \u25c3 xH = yzy\u207b\u00b9xH`.  Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts\n  transitively on `Q` as a set) is isomorphic to such a quandle.\n  There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].\n\n## Tags\n\nrack, quandle\n-/\nopen opposite\n\nuniverses u v\n\n/--\nA *shelf* is a structure with a self-distributive binary operation.\nThe binary operation is regarded as a left action of the type on itself.\n-/\nclass shelf (\u03b1 : Type u) :=\n(act : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(self_distrib : \u2200 {x y z : \u03b1}, act x (act y z) = act (act x y) (act x z))\n\n/--\nThe type of homomorphisms between shelves.\nThis is also the notion of rack and quandle homomorphisms.\n-/\n@[ext]\nstructure shelf_hom (S\u2081 : Type*) (S\u2082 : Type*) [shelf S\u2081] [shelf S\u2082] :=\n(to_fun : S\u2081 \u2192 S\u2082)\n(map_act' : \u2200 {x y : S\u2081}, to_fun (shelf.act x y) = shelf.act (to_fun x) (to_fun y))\n\n/--\nA *rack* is an automorphic set (a set with an action on itself by\nbijections) that is self-distributive.  It is a shelf such that each\nelement's action is invertible.\n\nThe notations `x \u25c3 y` and `x \u25c3\u207b\u00b9 y` denote the action and the\ninverse action, respectively, and they are right associative.\n-/\nclass rack (\u03b1 : Type u) extends shelf \u03b1 :=\n(inv_act : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(left_inv : \u2200 x, function.left_inverse (inv_act x) (act x))\n(right_inv : \u2200 x, function.right_inverse (inv_act x) (act x))\n\nlocalized \"infixr ` \u25c3 `:65 := shelf.act\" in quandles\nlocalized \"infixr ` \u25c3\u207b\u00b9 `:65 := rack.inv_act\" in quandles\nlocalized \"infixr ` \u2192\u25c3 `:25 := shelf_hom\" in quandles\n\nopen_locale quandles\n\nnamespace rack\nvariables {R : Type*} [rack R]\n\nlemma self_distrib {x y z : R} : x \u25c3 (y \u25c3 z) = (x \u25c3 y) \u25c3 (x \u25c3 z) :=\nshelf.self_distrib\n\n/--\nA rack acts on itself by equivalences.\n-/\ndef act (x : R) : R \u2243 R :=\n{ to_fun := shelf.act x,\n  inv_fun := inv_act x,\n  left_inv := left_inv x,\n  right_inv := right_inv x }\n\n@[simp] lemma act_apply (x y : R) : act x y = x \u25c3 y := rfl\n@[simp] lemma act_symm_apply (x y : R) : (act x).symm y = x \u25c3\u207b\u00b9 y := rfl\n@[simp] lemma inv_act_apply (x y : R) : (act x)\u207b\u00b9 y = x \u25c3\u207b\u00b9 y := rfl\n\n@[simp] lemma inv_act_act_eq (x y : R) : x \u25c3\u207b\u00b9 x \u25c3 y = y := left_inv x y\n@[simp] lemma act_inv_act_eq (x y : R) : x \u25c3 x \u25c3\u207b\u00b9 y = y := right_inv x y\n\nlemma left_cancel (x : R) {y y' : R} : x \u25c3 y = x \u25c3 y' \u2194 y = y' :=\nby { split, apply (act x).injective, rintro rfl, refl }\n\nlemma left_cancel_inv (x : R) {y y' : R} : x \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y' \u2194 y = y' :=\nby { split, apply (act x).symm.injective, rintro rfl, refl }\n\nlemma self_distrib_inv {x y z : R} : x \u25c3\u207b\u00b9 y \u25c3\u207b\u00b9 z = (x \u25c3\u207b\u00b9 y) \u25c3\u207b\u00b9 (x \u25c3\u207b\u00b9 z) :=\nbegin\n  rw [\u2190left_cancel (x \u25c3\u207b\u00b9 y), right_inv, \u2190left_cancel x, right_inv, self_distrib],\n  repeat {rw right_inv },\nend\n\n/--\nThe *adjoint action* of a rack on itself is `op'`, and the adjoint\naction of `x \u25c3 y` is the conjugate of the action of `y` by the action\nof `x`. It is another way to understand the self-distributivity axiom.\n\nThis is used in the natural rack homomorphism `to_conj` from `R` to\n`conj (R \u2243 R)` defined by `op'`.\n-/\nlemma ad_conj {R : Type*} [rack R] (x y : R) :\n  act (x \u25c3 y) = act x * act y * (act x)\u207b\u00b9 :=\nbegin\n  apply @mul_right_cancel _ _ _ (act x), ext z,\n  simp only [inv_mul_cancel_right],\n  apply self_distrib.symm,\nend\n\n/--\nThe opposite rack, swapping the roles of `\u25c3` and `\u25c3\u207b\u00b9`.\n-/\ninstance opposite_rack : rack R\u1d52\u1d56 :=\n{ act := \u03bb x y, op (inv_act (unop x) (unop y)),\n  self_distrib := \u03bb (x y z : R\u1d52\u1d56), begin\n    op_induction x, op_induction y, op_induction z,\n    simp only [unop_op, op_inj_iff],\n    exact self_distrib_inv,\n  end,\n  inv_act := \u03bb x y, op (shelf.act (unop x) (unop y)),\n  left_inv := \u03bb x y, begin\n    op_induction x, op_induction y, simp,\n  end,\n  right_inv := \u03bb x y, begin\n    op_induction x, op_induction y, simp,\n  end }\n\n@[simp] lemma op_act_op_eq {x y : R} : (op x) \u25c3 (op y) = op (x \u25c3\u207b\u00b9 y) := rfl\n@[simp] lemma op_inv_act_op_eq {x y : R} : (op x) \u25c3\u207b\u00b9 (op y) = op (x \u25c3 y) := rfl\n\n@[simp]\nlemma self_act_act_eq {x y : R} : (x \u25c3 x) \u25c3 y = x \u25c3 y :=\nby { rw [\u2190right_inv x y, \u2190self_distrib] }\n\n@[simp]\nlemma self_inv_act_inv_act_eq {x y : R} : (x \u25c3\u207b\u00b9 x) \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y :=\nby { have h := @self_act_act_eq _ _ (op x) (op y), simpa using h }\n\n@[simp]\nlemma self_act_inv_act_eq {x y : R} : (x \u25c3 x) \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y :=\nby { rw \u2190left_cancel (x \u25c3 x), rw right_inv, rw self_act_act_eq, rw right_inv }\n\n@[simp]\nlemma self_inv_act_act_eq {x y : R} : (x \u25c3\u207b\u00b9 x) \u25c3 y = x \u25c3 y :=\nby { have h := @self_act_inv_act_eq _ _ (op x) (op y), simpa using h }\n\nlemma self_act_eq_iff_eq {x y : R} : x \u25c3 x = y \u25c3 y \u2194 x = y :=\nbegin\n  split, swap, rintro rfl, refl,\n  intro h,\n  transitivity (x \u25c3 x) \u25c3\u207b\u00b9 (x \u25c3 x),\n  rw [\u2190left_cancel (x \u25c3 x), right_inv, self_act_act_eq],\n  rw [h, \u2190left_cancel (y \u25c3 y), right_inv, self_act_act_eq],\nend\n\nlemma self_inv_act_eq_iff_eq {x y : R} : x \u25c3\u207b\u00b9 x = y \u25c3\u207b\u00b9 y \u2194 x = y :=\nby { have h := @self_act_eq_iff_eq _ _ (op x) (op y), simpa using h }\n\n/--\nThe map `x \u21a6 x \u25c3 x` is a bijection.  (This has applications for the\nregular isotopy version of the Reidemeister I move for knot diagrams.)\n-/\ndef self_apply_equiv (R : Type*) [rack R] : R \u2243 R :=\n{ to_fun := \u03bb x, x \u25c3 x,\n  inv_fun := \u03bb x, x \u25c3\u207b\u00b9 x,\n  left_inv := \u03bb x, by simp,\n  right_inv := \u03bb x, by simp }\n\n/--\nAn involutory rack is one for which `rack.op R x` is an involution for every x.\n-/\ndef is_involutory (R : Type*) [rack R] : Prop := \u2200 x : R, function.involutive (shelf.act x)\n\nlemma involutory_inv_act_eq_act {R : Type*} [rack R] (h : is_involutory R) (x y : R) :\n  x \u25c3\u207b\u00b9 y = x \u25c3 y :=\nbegin\n  rw [\u2190left_cancel x, right_inv],\n  exact ((h x).left_inverse y).symm,\nend\n\n/--\nAn abelian rack is one for which the mediality axiom holds.\n-/\ndef is_abelian (R : Type*) [rack R] : Prop :=\n\u2200 (x y z w : R), (x \u25c3 y) \u25c3 (z \u25c3 w) = (x \u25c3 z) \u25c3 (y \u25c3 w)\n\n/--\nAssociative racks are uninteresting.\n-/\nlemma assoc_iff_id {R : Type*} [rack R] {x y z : R} :\n  x \u25c3 y \u25c3 z = (x \u25c3 y) \u25c3 z \u2194 x \u25c3 z = z :=\nby { rw self_distrib, rw left_cancel }\n\nend rack\n\nnamespace shelf_hom\nvariables {S\u2081 : Type*} {S\u2082 : Type*} {S\u2083 : Type*} [shelf S\u2081] [shelf S\u2082] [shelf S\u2083]\n\ninstance : has_coe_to_fun (S\u2081 \u2192\u25c3 S\u2082) :=\n\u27e8_, shelf_hom.to_fun\u27e9\n\n@[simp] lemma to_fun_eq_coe (f : S\u2081 \u2192\u25c3 S\u2082) : f.to_fun = f := rfl\n\n@[simp] lemma map_act (f : S\u2081 \u2192\u25c3 S\u2082) {x y : S\u2081} : f (x \u25c3 y) = f x \u25c3 f y := map_act' f\n\n/-- The identity homomorphism -/\ndef id (S : Type*) [shelf S] : S \u2192\u25c3 S :=\n{ to_fun := id,\n  map_act' := by simp }\n\ninstance inhabited (S : Type*) [shelf S] : inhabited (S \u2192\u25c3 S) :=\n\u27e8id S\u27e9\n\n/-- The composition of shelf homomorphisms -/\ndef comp (g : S\u2082 \u2192\u25c3 S\u2083) (f : S\u2081 \u2192\u25c3 S\u2082) : S\u2081 \u2192\u25c3 S\u2083 :=\n{ to_fun := g.to_fun \u2218 f.to_fun,\n  map_act' := by simp }\n\n@[simp]\nlemma comp_apply (g : S\u2082 \u2192\u25c3 S\u2083) (f : S\u2081 \u2192\u25c3 S\u2082) (x : S\u2081) :\n  (g.comp f) x = g (f x) := rfl\n\nend shelf_hom\n\n/--\nA quandle is a rack such that each automorphism fixes its corresponding element.\n-/\nclass quandle (\u03b1 : Type*) extends rack \u03b1 :=\n(fix : \u2200 {x : \u03b1}, act x x = x)\n\nnamespace quandle\nopen rack\nvariables {Q : Type*} [quandle Q]\n\nattribute [simp] fix\n\n@[simp]\nlemma fix_inv {x : Q} : x \u25c3\u207b\u00b9 x = x :=\nby { rw \u2190left_cancel x, simp }\n\ninstance opposite_quandle : quandle Q\u1d52\u1d56 :=\n{ fix := \u03bb x, by { op_induction x, simp } }\n\n/--\nThe conjugation quandle of a group.  Each element of the group acts by\nthe corresponding inner automorphism.\n-/\n@[nolint has_inhabited_instance]\ndef conj (G : Type*) := G\n\ninstance conj.quandle (G : Type*) [group G] : quandle (conj G) :=\n{ act := (\u03bb x, @mul_aut.conj G _ x),\n  self_distrib := \u03bb x y z, begin\n    dsimp only [mul_equiv.coe_to_equiv, mul_aut.conj_apply, conj],\n    group,\n  end,\n  inv_act := (\u03bb x, (@mul_aut.conj G _ x).symm),\n  left_inv := \u03bb x y, by { dsimp [act, conj], group },\n  right_inv := \u03bb x y, by { dsimp [act, conj], group },\n  fix := \u03bb x, by simp }\n\n@[simp]\nlemma conj_act_eq_conj {G : Type*} [group G] (x y : conj G) :\n  x \u25c3 y = ((x : G) * (y : G) * (x : G)\u207b\u00b9 : G) := rfl\n\nlemma conj_swap {G : Type*} [group G] (x y : conj G) :\n  x \u25c3 y = y \u2194 y \u25c3 x = x :=\nbegin\n  dsimp, split,\n  repeat { intro h, conv_rhs { rw eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h) }, simp, },\nend\n\n/--\n`conj` is functorial\n-/\ndef conj.map {G : Type*} {H : Type*} [group G] [group H] (f : G \u2192* H) : conj G \u2192\u25c3 conj H :=\n{ to_fun := f,\n  map_act' := by simp }\n\ninstance {G : Type*} {H : Type*} [group G] [group H] : has_lift (G \u2192* H) (conj G \u2192\u25c3 conj H) :=\n{ lift := conj.map }\n\n/--\nThe dihedral quandle. This is the conjugation quandle of the dihedral group restrict to flips.\n\nUsed for Fox n-colorings of knots.\n-/\n@[nolint has_inhabited_instance]\ndef dihedral (n : \u2115) := zmod n\n\n/--\nThe operation for the dihedral quandle.  It does not need to be an equivalence\nbecause it is an involution (see `dihedral_act.inv`).\n-/\ndef dihedral_act (n : \u2115) (a : zmod n) : zmod n \u2192 zmod n :=\n\u03bb b, 2 * a - b\n\nlemma dihedral_act.inv (n : \u2115) (a : zmod n) : function.involutive (dihedral_act n a) :=\nby { intro b, dsimp [dihedral_act], ring }\n\ninstance (n : \u2115) : quandle (dihedral n) :=\n{ act := dihedral_act n,\n  self_distrib := \u03bb x y z, begin\n    dsimp [function.involutive.to_equiv, dihedral_act], ring,\n  end,\n  inv_act := dihedral_act n,\n  left_inv := \u03bb x, (dihedral_act.inv n x).left_inverse,\n  right_inv := \u03bb x, (dihedral_act.inv n x).right_inverse,\n  fix := \u03bb x, begin\n    dsimp [function.involutive.to_equiv, dihedral_act], ring,\n  end }\n\nend quandle\n\nnamespace rack\n\n/--\nThis is the natural rack homomorphism to the conjugation quandle of the group `R \u2243 R`\nthat acts on the rack.\n-/\ndef to_conj (R : Type*) [rack R] : R \u2192\u25c3 quandle.conj (R \u2243 R) :=\n{ to_fun := act,\n  map_act' := ad_conj }\n\nsection envel_group\n\n/-!\n### Universal enveloping group of a rack\n\nThe universal enveloping group `envel_group R` of a rack `R` is the\nuniversal group such that every rack homomorphism `R \u2192\u25c3 conj G` is\ninduced by a unique group homomorphism `envel_group R \u2192* G`.\nFor quandles, Joyce called this group `AdConj R`.\n\nThe `envel_group` functor is left adjoint to the `conj` forgetful\nfunctor, and the way we construct the enveloping group is via a\ntechnique that should work for left adjoints of forgetful functors in\ngeneral.  It involves thinking a little about 2-categories, but the\npayoff is that the map `envel_group R \u2192* G` has a nice description.\n\nLet's think of a group as being a one-object category.  The first step\nis to define `pre_envel_group`, which gives formal expressions for all\nthe 1-morphisms and includes the unit element, elements of `R`,\nmultiplication, and inverses.  To introduce relations, the second step\nis to define `pre_envel_group_rel'`, which gives formal expressions\nfor all 2-morphisms between the 1-morphisms.  The 2-morphisms include\nassociativity, multiplication by the unit, multiplication by inverses,\ncompatibility with multiplication and inverses (`congr_mul` and\n`congr_inv`), the axioms for an equivalence relation, and,\nimportantly, the relationship between conjugation and the rack action\n(see `rack.ad_conj`).\n\nNone of this forms a 2-category yet, for example due to lack of\nassociativity of `trans`.  The `pre_envel_group_rel` relation is a\n`Prop`-valued version of `pre_envel_group_rel'`, and making it\n`Prop`-valued essentially introduces enough 3-isomorphisms so that\nevery pair of compatible 2-morphisms is isomorphic.  Now, while\ncomposition in `pre_envel_group` does not strictly satisfy the category\naxioms, `pre_envel_group` and `pre_envel_group_rel'` do form a weak\n2-category.\n\nSince we just want a 1-category, the last step is to quotient\n`pre_envel_group` by `pre_envel_group_rel'`, and the result is the\ngroup `envel_group`.\n\nFor a homomorphism `f : R \u2192\u25c3 conj G`, how does\n`envel_group.map f : envel_group R \u2192* G` work?  Let's think of `G` as\nbeing a 2-category with one object, a 1-morphism per element of `G`,\nand a single 2-morphism called `eq.refl` for each 1-morphism.  We\ndefine the map using a \"higher `quotient.lift`\" -- not only do we\nevaluate elements of `pre_envel_group` as expressions in `G` (this is\n`to_envel_group.map_aux`), but we evaluate elements of\n`pre_envel_group'` as expressions of 2-morphisms of `G` (this is\n`to_envel_group.map_aux.well_def`).  That is to say,\n`to_envel_group.map_aux.well_def` recursively evaluates formal\nexpressions of 2-morphisms as equality proofs in `G`.  Now that all\nmorphisms are accounted for, the map descends to a homomorphism\n`envel_group R \u2192* G`.\n\nNote: `Type`-valued relations are not common.  The fact it is\n`Type`-valued is what makes `to_envel_group.map_aux.well_def` have\nwell-founded recursion.\n-/\n\n/--\nFree generators of the enveloping group.\n-/\ninductive pre_envel_group (R : Type u) : Type u\n| unit : pre_envel_group\n| incl (x : R) : pre_envel_group\n| mul (a b : pre_envel_group) : pre_envel_group\n| inv (a : pre_envel_group) : pre_envel_group\n\ninstance pre_envel_group.inhabited (R : Type u) : inhabited (pre_envel_group R) :=\n\u27e8pre_envel_group.unit\u27e9\n\nopen pre_envel_group\n\n/--\nRelations for the enveloping group. This is a type-valued relation because\n`to_envel_group.map_aux.well_def` inducts on it to show `to_envel_group.map`\nis well-defined.  The relation `pre_envel_group_rel` is the `Prop`-valued version,\nwhich is used to define `envel_group` itself.\n-/\ninductive pre_envel_group_rel' (R : Type u) [rack R] :\n  pre_envel_group R \u2192 pre_envel_group R \u2192 Type u\n| refl {a : pre_envel_group R} : pre_envel_group_rel' a a\n| symm {a b : pre_envel_group R} (hab : pre_envel_group_rel' a b) : pre_envel_group_rel' b a\n| trans {a b c : pre_envel_group R}\n  (hab : pre_envel_group_rel' a b) (hbc : pre_envel_group_rel' b c) : pre_envel_group_rel' a c\n| congr_mul {a b a' b' : pre_envel_group R}\n  (ha : pre_envel_group_rel' a a') (hb : pre_envel_group_rel' b b') :\n  pre_envel_group_rel' (mul a b) (mul a' b')\n| congr_inv {a a' : pre_envel_group R} (ha : pre_envel_group_rel' a a') :\n  pre_envel_group_rel' (inv a) (inv a')\n| assoc (a b c : pre_envel_group R) : pre_envel_group_rel' (mul (mul a b) c) (mul a (mul b c))\n| one_mul (a : pre_envel_group R) : pre_envel_group_rel' (mul unit a) a\n| mul_one (a : pre_envel_group R) : pre_envel_group_rel' (mul a unit) a\n| mul_left_inv (a : pre_envel_group R) : pre_envel_group_rel' (mul (inv a) a) unit\n| act_incl (x y : R) :\n  pre_envel_group_rel' (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x \u25c3 y))\n\ninstance pre_envel_group_rel'.inhabited (R : Type u) [rack R] :\n  inhabited (pre_envel_group_rel' R unit unit) :=\n\u27e8pre_envel_group_rel'.refl\u27e9\n\n/--\nThe `pre_envel_group_rel` relation as a `Prop`.  Used as the relation for `pre_envel_group.setoid`.\n-/\ninductive pre_envel_group_rel (R : Type u) [rack R] : pre_envel_group R \u2192 pre_envel_group R \u2192 Prop\n| rel {a b : pre_envel_group R} (r : pre_envel_group_rel' R a b) : pre_envel_group_rel a b\n\n/--\nA quick way to convert a `pre_envel_group_rel'` to a `pre_envel_group_rel`.\n-/\nlemma pre_envel_group_rel'.rel {R : Type u} [rack R] {a b : pre_envel_group R} :\n  pre_envel_group_rel' R a b \u2192 pre_envel_group_rel R a b :=\npre_envel_group_rel.rel\n\n@[refl]\nlemma pre_envel_group_rel.refl {R : Type u} [rack R] {a : pre_envel_group R} :\n  pre_envel_group_rel R a a :=\npre_envel_group_rel.rel pre_envel_group_rel'.refl\n\n@[symm]\nlemma pre_envel_group_rel.symm {R : Type u} [rack R] {a b : pre_envel_group R} :\n  pre_envel_group_rel R a b \u2192 pre_envel_group_rel R b a\n| \u27e8r\u27e9 := r.symm.rel\n\n@[trans]\nlemma pre_envel_group_rel.trans {R : Type u} [rack R] {a b c : pre_envel_group R} :\n  pre_envel_group_rel R a b \u2192 pre_envel_group_rel R b c \u2192 pre_envel_group_rel R a c\n| \u27e8rab\u27e9 \u27e8rbc\u27e9 := (rab.trans rbc).rel\n\ninstance pre_envel_group.setoid (R : Type*) [rack R] : setoid (pre_envel_group R) :=\n{ r := pre_envel_group_rel R,\n  iseqv := begin\n    split, apply pre_envel_group_rel.refl,\n    split, apply pre_envel_group_rel.symm,\n    apply pre_envel_group_rel.trans\n  end }\n\n/--\nThe universal enveloping group for the rack R.\n-/\ndef envel_group (R : Type*) [rack R] := quotient (pre_envel_group.setoid R)\n\n-- Define the `group` instances in two steps so `inv` can be inferred correctly.\n-- TODO: is there a non-invasive way of defining the instance directly?\ninstance (R : Type*) [rack R] : div_inv_monoid (envel_group R) :=\n{ mul := \u03bb a b, quotient.lift_on\u2082 a b\n                  (\u03bb a b, \u27e6pre_envel_group.mul a b\u27e7)\n                  (\u03bb a b a' b' \u27e8ha\u27e9 \u27e8hb\u27e9,\n                    quotient.sound (pre_envel_group_rel'.congr_mul ha hb).rel),\n  one := \u27e6unit\u27e7,\n  inv := \u03bb a, quotient.lift_on a\n                (\u03bb a, \u27e6pre_envel_group.inv a\u27e7)\n                (\u03bb a a' \u27e8ha\u27e9,\n                  quotient.sound (pre_envel_group_rel'.congr_inv ha).rel),\n  mul_assoc := \u03bb a b c,\n    quotient.induction_on\u2083 a b c (\u03bb a b c, quotient.sound (pre_envel_group_rel'.assoc a b c).rel),\n  one_mul := \u03bb a,\n    quotient.induction_on a (\u03bb a, quotient.sound (pre_envel_group_rel'.one_mul a).rel),\n  mul_one := \u03bb a,\n    quotient.induction_on a (\u03bb a, quotient.sound (pre_envel_group_rel'.mul_one a).rel),}\n\ninstance (R : Type*) [rack R] : group (envel_group R) :=\n{ mul_left_inv := \u03bb a,\n    quotient.induction_on a (\u03bb a, quotient.sound (pre_envel_group_rel'.mul_left_inv a).rel),\n  .. envel_group.div_inv_monoid _ }\n\ninstance envel_group.inhabited (R : Type*) [rack R] : inhabited (envel_group R) := \u27e81\u27e9\n\n/--\nThe canonical homomorphism from a rack to its enveloping group.\nSatisfies universal properties given by `to_envel_group.map` and `to_envel_group.univ`.\n-/\ndef to_envel_group (R : Type*) [rack R] : R \u2192\u25c3 quandle.conj (envel_group R) :=\n{ to_fun := \u03bb x, \u27e6incl x\u27e7,\n  map_act' := \u03bb x y, quotient.sound (pre_envel_group_rel'.act_incl x y).symm.rel }\n\n/--\nThe preliminary definition of the induced map from the enveloping group.\nSee `to_envel_group.map`.\n-/\ndef to_envel_group.map_aux {R : Type*} [rack R] {G : Type*} [group G]\n  (f : R \u2192\u25c3 quandle.conj G) : pre_envel_group R \u2192 G\n| unit := 1\n| (incl x) := f x\n| (mul a b) := to_envel_group.map_aux a * to_envel_group.map_aux b\n| (inv a) := (to_envel_group.map_aux a)\u207b\u00b9\n\nnamespace to_envel_group.map_aux\nopen pre_envel_group_rel'\n\n/--\nShow that `to_envel_group.map_aux` sends equivalent expressions to equal terms.\n-/\nlemma well_def {R : Type*} [rack R] {G : Type*} [group G] (f : R \u2192\u25c3 quandle.conj G) :\n  \u03a0 {a b : pre_envel_group R}, pre_envel_group_rel' R a b \u2192\n  to_envel_group.map_aux f a = to_envel_group.map_aux f b\n| a b refl := rfl\n| a b (symm h) := (well_def h).symm\n| a b (trans hac hcb) := eq.trans (well_def hac) (well_def hcb)\n| _ _ (congr_mul ha hb) := by { simp [to_envel_group.map_aux, well_def ha, well_def hb] }\n| _ _ (congr_inv ha) := by { simp [to_envel_group.map_aux, well_def ha] }\n| _ _ (assoc a b c) := by { apply mul_assoc }\n| _ _ (one_mul a) := by { simp [to_envel_group.map_aux] }\n| _ _ (mul_one a) := by { simp [to_envel_group.map_aux] }\n| _ _ (mul_left_inv a) := by { simp [to_envel_group.map_aux] }\n| _ _ (act_incl x y) := by { simp [to_envel_group.map_aux] }\n\nend to_envel_group.map_aux\n\n/--\nGiven a map from a rack to a group, lift it to being a map from the enveloping group.\nMore precisely, the `envel_group` functor is left adjoint to `quandle.conj`.\n-/\ndef to_envel_group.map {R : Type*} [rack R] {G : Type*} [group G] :\n  (R \u2192\u25c3 quandle.conj G) \u2243 (envel_group R \u2192* G) :=\n{ to_fun := \u03bb f,\n  { to_fun := \u03bb x, quotient.lift_on x (to_envel_group.map_aux f)\n                    (\u03bb a b \u27e8hab\u27e9, to_envel_group.map_aux.well_def f hab),\n    map_one' := begin\n      change quotient.lift_on \u27e6unit\u27e7 (to_envel_group.map_aux f) _ = 1,\n      simp [to_envel_group.map_aux],\n    end,\n    map_mul' := \u03bb x y, quotient.induction_on\u2082 x y (\u03bb x y, begin\n      change quotient.lift_on \u27e6mul x y\u27e7 (to_envel_group.map_aux f) _ = _,\n      simp [to_envel_group.map_aux],\n    end) },\n  inv_fun := \u03bb F, (quandle.conj.map F).comp (to_envel_group R),\n  left_inv := \u03bb f, by { ext, refl },\n  right_inv := \u03bb F, monoid_hom.ext $ \u03bb x, quotient.induction_on x $ \u03bb x, begin\n    induction x,\n    { exact F.map_one.symm, },\n    { refl, },\n    { have hm : \u27e6x_a.mul x_b\u27e7 = @has_mul.mul (envel_group R) _ \u27e6x_a\u27e7 \u27e6x_b\u27e7 := rfl,\n      rw [hm, F.map_mul, monoid_hom.map_mul, \u2190x_ih_a, \u2190x_ih_b] },\n    { have hm : \u27e6x_a.inv\u27e7 = @has_inv.inv (envel_group R) _ \u27e6x_a\u27e7 := rfl,\n      rw [hm, F.map_inv, monoid_hom.map_inv, x_ih], }\n  end, }\n\n/--\nGiven a homomorphism from a rack to a group, it factors through the enveloping group.\n-/\nlemma to_envel_group.univ (R : Type*) [rack R] (G : Type*) [group G]\n  (f : R \u2192\u25c3 quandle.conj G) :\n  (quandle.conj.map (to_envel_group.map f)).comp (to_envel_group R) = f :=\nto_envel_group.map.symm_apply_apply f\n\n/--\nThe homomorphism `to_envel_group.map f` is the unique map that fits into the commutative\ntriangle in `to_envel_group.univ`.\n-/\nlemma to_envel_group.univ_uniq (R : Type*) [rack R] (G : Type*) [group G]\n  (f : R \u2192\u25c3 quandle.conj G)\n  (g : envel_group R \u2192* G) (h : f = (quandle.conj.map g).comp (to_envel_group R)) :\n  g = to_envel_group.map f :=\nh.symm \u25b8 (to_envel_group.map.apply_symm_apply g).symm\n\n/--\nThe induced group homomorphism from the enveloping group into bijections of the rack,\nusing `rack.to_conj`. Satisfies the property `envel_action_prop`.\n\nThis gives the rack `R` the structure of an augmented rack over `envel_group R`.\n-/\ndef envel_action {R : Type*} [rack R] : envel_group R \u2192* (R \u2243 R) :=\nto_envel_group.map (to_conj R)\n\n@[simp]\n\n\nend envel_group\n\nend rack\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/quandle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7172967800168772}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport order.complete_boolean_algebra\nimport order.modular_lattice\nimport data.fintype.basic\n\n/-!\n# Atoms, Coatoms, and Simple Lattices\n\nThis module defines atoms, which are minimal non-`\u22a5` elements in bounded lattices, simple lattices,\nwhich are lattices with only two elements, and related ideas.\n\n## Main definitions\n\n### Atoms and Coatoms\n  * `is_atom a` indicates that the only element below `a` is `\u22a5`.\n  * `is_coatom a` indicates that the only element above `a` is `\u22a4`.\n\n### Atomic and Atomistic Lattices\n  * `is_atomic` indicates that every element other than `\u22a5` is above an atom.\n  * `is_coatomic` indicates that every element other than `\u22a4` is below a coatom.\n  * `is_atomistic` indicates that every element is the `Sup` of a set of atoms.\n  * `is_coatomistic` indicates that every element is the `Inf` of a set of coatoms.\n\n### Simple Lattices\n  * `is_simple_order` indicates that an order has only two unique elements, `\u22a5` and `\u22a4`.\n  * `is_simple_order.bounded_order`\n  * `is_simple_order.distrib_lattice`\n  * Given an instance of `is_simple_order`, we provide the following definitions. These are not\n    made global instances as they contain data :\n    * `is_simple_order.boolean_algebra`\n    * `is_simple_order.complete_lattice`\n    * `is_simple_order.complete_boolean_algebra`\n\n## Main results\n  * `is_atom_dual_iff_is_coatom` and `is_coatom_dual_iff_is_atom` express the (definitional) duality\n   of `is_atom` and `is_coatom`.\n  * `is_simple_order_iff_is_atom_top` and `is_simple_order_iff_is_coatom_bot` express the\n  connection between atoms, coatoms, and simple lattices\n  * `is_compl.is_atom_iff_is_coatom` and `is_compl.is_coatom_if_is_atom`: In a modular\n  bounded lattice, a complement of an atom is a coatom and vice versa.\n  * ``is_atomic_iff_is_coatomic`: A modular complemented lattice is atomic iff it is coatomic.\n\n-/\n\nvariable {\u03b1 : Type*}\n\nsection atoms\n\nsection is_atom\n\nvariables [partial_order \u03b1] [order_bot \u03b1]\n\n/-- An atom of an `order_bot` is an element with no other element between it and `\u22a5`,\n  which is not `\u22a5`. -/\ndef is_atom (a : \u03b1) : Prop := a \u2260 \u22a5 \u2227 (\u2200 b, b < a \u2192 b = \u22a5)\n\nlemma eq_bot_or_eq_of_le_atom {a b : \u03b1} (ha : is_atom a) (hab : b \u2264 a) : b = \u22a5 \u2228 b = a :=\nhab.lt_or_eq.imp_left (ha.2 b)\n\nlemma is_atom.Iic {x a : \u03b1} (ha : is_atom a) (hax : a \u2264 x) : is_atom (\u27e8a, hax\u27e9 : set.Iic x) :=\n\u27e8\u03bb con, ha.1 (subtype.mk_eq_mk.1 con), \u03bb \u27e8b, hb\u27e9 hba, subtype.mk_eq_mk.2 (ha.2 b hba)\u27e9\n\nlemma is_atom.of_is_atom_coe_Iic {x : \u03b1} {a : set.Iic x} (ha : is_atom a) : is_atom (a : \u03b1) :=\n\u27e8\u03bb con, ha.1 (subtype.ext con), \u03bb b hba, subtype.mk_eq_mk.1 (ha.2 \u27e8b, hba.le.trans a.prop\u27e9 hba)\u27e9\n\nend is_atom\n\nsection is_coatom\n\nvariables [partial_order \u03b1] [order_top \u03b1]\n\n/-- A coatom of an `order_top` is an element with no other element between it and `\u22a4`,\n  which is not `\u22a4`. -/\ndef is_coatom (a : \u03b1) : Prop := a \u2260 \u22a4 \u2227 (\u2200 b, a < b \u2192 b = \u22a4)\n\nlemma eq_top_or_eq_of_coatom_le {a b : \u03b1} (ha : is_coatom a) (hab : a \u2264 b) : b = \u22a4 \u2228 b = a :=\nhab.lt_or_eq.imp (ha.2 b) eq_comm.2\n\nlemma is_coatom.Ici {x a : \u03b1} (ha : is_coatom a) (hax : x \u2264 a) : is_coatom (\u27e8a, hax\u27e9 : set.Ici x) :=\n\u27e8\u03bb con, ha.1 (subtype.mk_eq_mk.1 con), \u03bb \u27e8b, hb\u27e9 hba, subtype.mk_eq_mk.2 (ha.2 b hba)\u27e9\n\nlemma is_coatom.of_is_coatom_coe_Ici {x : \u03b1} {a : set.Ici x} (ha : is_coatom a) :\n  is_coatom (a : \u03b1) :=\n\u27e8\u03bb con, ha.1 (subtype.ext con), \u03bb b hba, subtype.mk_eq_mk.1 (ha.2 \u27e8b, le_trans a.prop hba.le\u27e9 hba)\u27e9\n\nend is_coatom\n\nsection pairwise\n\nlemma is_atom.inf_eq_bot_of_ne [semilattice_inf \u03b1] [order_bot \u03b1] {a b : \u03b1}\n  (ha : is_atom a) (hb : is_atom b) (hab : a \u2260 b) : a \u2293 b = \u22a5 :=\nor.elim (eq_bot_or_eq_of_le_atom ha inf_le_left) id\n  (\u03bb h1, or.elim (eq_bot_or_eq_of_le_atom hb inf_le_right) id\n  (\u03bb h2, false.rec _ (hab (le_antisymm (inf_eq_left.mp h1) (inf_eq_right.mp h2)))))\n\nlemma is_atom.disjoint_of_ne [semilattice_inf \u03b1] [order_bot \u03b1] {a b : \u03b1}\n  (ha : is_atom a) (hb : is_atom b) (hab : a \u2260 b) : disjoint a b :=\ndisjoint_iff.mpr (is_atom.inf_eq_bot_of_ne ha hb hab)\n\nlemma is_coatom.sup_eq_top_of_ne [semilattice_sup \u03b1] [order_top \u03b1] {a b : \u03b1}\n  (ha : is_coatom a) (hb : is_coatom b) (hab : a \u2260 b) : a \u2294 b = \u22a4 :=\nor.elim (eq_top_or_eq_of_coatom_le ha le_sup_left) id\n  (\u03bb h1, or.elim (eq_top_or_eq_of_coatom_le hb le_sup_right) id\n  (\u03bb h2, false.rec _ (hab (le_antisymm (sup_eq_right.mp h2) (sup_eq_left.mp h1)))))\n\nend pairwise\n\nvariables [partial_order \u03b1] {a : \u03b1}\n\n@[simp]\nlemma is_coatom_dual_iff_is_atom [order_bot \u03b1] :\n  is_coatom (order_dual.to_dual a) \u2194 is_atom a :=\niff.rfl\n\n@[simp]\nlemma is_atom_dual_iff_is_coatom [order_top \u03b1] :\n  is_atom (order_dual.to_dual a) \u2194 is_coatom a :=\niff.rfl\n\nend atoms\n\nsection atomic\n\nvariables [partial_order \u03b1] (\u03b1)\n\n/-- A lattice is atomic iff every element other than `\u22a5` has an atom below it. -/\nclass is_atomic [order_bot \u03b1] : Prop :=\n(eq_bot_or_exists_atom_le : \u2200 (b : \u03b1), b = \u22a5 \u2228 \u2203 (a : \u03b1), is_atom a \u2227 a \u2264 b)\n\n/-- A lattice is coatomic iff every element other than `\u22a4` has a coatom above it. -/\nclass is_coatomic [order_top \u03b1] : Prop :=\n(eq_top_or_exists_le_coatom : \u2200 (b : \u03b1), b = \u22a4 \u2228 \u2203 (a : \u03b1), is_coatom a \u2227 b \u2264 a)\n\nexport is_atomic (eq_bot_or_exists_atom_le) is_coatomic (eq_top_or_exists_le_coatom)\n\nvariable {\u03b1}\n\n@[simp] theorem is_coatomic_dual_iff_is_atomic [order_bot \u03b1] :\n  is_coatomic (order_dual \u03b1) \u2194 is_atomic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_top_or_exists_le_coatom\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_bot_or_exists_atom_le\u27e9\u27e9\n\n@[simp] theorem is_atomic_dual_iff_is_coatomic [order_top \u03b1] :\n  is_atomic (order_dual \u03b1) \u2194 is_coatomic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_bot_or_exists_atom_le\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_top_or_exists_le_coatom\u27e9\u27e9\n\nnamespace is_atomic\n\nvariables [order_bot \u03b1] [is_atomic \u03b1]\n\ninstance is_coatomic_dual : is_coatomic (order_dual \u03b1) :=\nis_coatomic_dual_iff_is_atomic.2 \u2039is_atomic \u03b1\u203a\n\ninstance {x : \u03b1} : is_atomic (set.Iic x) :=\n\u27e8\u03bb \u27e8y, hy\u27e9, (eq_bot_or_exists_atom_le y).imp subtype.mk_eq_mk.2\n  (\u03bb \u27e8a, ha, hay\u27e9, \u27e8\u27e8a, hay.trans hy\u27e9, ha.Iic (hay.trans hy), hay\u27e9)\u27e9\n\nend is_atomic\n\nnamespace is_coatomic\n\nvariables [order_top \u03b1] [is_coatomic \u03b1]\n\ninstance is_coatomic : is_atomic (order_dual \u03b1) :=\nis_atomic_dual_iff_is_coatomic.2 \u2039is_coatomic \u03b1\u203a\n\ninstance {x : \u03b1} : is_coatomic (set.Ici x) :=\n\u27e8\u03bb \u27e8y, hy\u27e9, (eq_top_or_exists_le_coatom y).imp subtype.mk_eq_mk.2\n  (\u03bb \u27e8a, ha, hay\u27e9, \u27e8\u27e8a, le_trans hy hay\u27e9, ha.Ici (le_trans hy hay), hay\u27e9)\u27e9\n\nend is_coatomic\n\ntheorem is_atomic_iff_forall_is_atomic_Iic [order_bot \u03b1] :\n  is_atomic \u03b1 \u2194 \u2200 (x : \u03b1), is_atomic (set.Iic x) :=\n\u27e8@is_atomic.set.Iic.is_atomic _ _ _, \u03bb h, \u27e8\u03bb x, ((@eq_bot_or_exists_atom_le _ _ _ (h x))\n  (\u22a4 : set.Iic x)).imp subtype.mk_eq_mk.1 (exists_imp_exists' coe\n  (\u03bb \u27e8a, ha\u27e9, and.imp_left (is_atom.of_is_atom_coe_Iic)))\u27e9\u27e9\n\ntheorem is_coatomic_iff_forall_is_coatomic_Ici [order_top \u03b1] :\n  is_coatomic \u03b1 \u2194 \u2200 (x : \u03b1), is_coatomic (set.Ici x) :=\nis_atomic_dual_iff_is_coatomic.symm.trans $ is_atomic_iff_forall_is_atomic_Iic.trans $ forall_congr\n  (\u03bb x, is_coatomic_dual_iff_is_atomic.symm.trans iff.rfl)\n\nend atomic\n\nsection atomistic\n\nvariables (\u03b1) [complete_lattice \u03b1]\n\n/-- A lattice is atomistic iff every element is a `Sup` of a set of atoms. -/\nclass is_atomistic : Prop :=\n(eq_Sup_atoms : \u2200 (b : \u03b1), \u2203 (s : set \u03b1), b = Sup s \u2227 \u2200 a, a \u2208 s \u2192 is_atom a)\n\n/-- A lattice is coatomistic iff every element is an `Inf` of a set of coatoms. -/\nclass is_coatomistic : Prop :=\n(eq_Inf_coatoms : \u2200 (b : \u03b1), \u2203 (s : set \u03b1), b = Inf s \u2227 \u2200 a, a \u2208 s \u2192 is_coatom a)\n\nexport is_atomistic (eq_Sup_atoms) is_coatomistic (eq_Inf_coatoms)\n\nvariable {\u03b1}\n\n@[simp]\ntheorem is_coatomistic_dual_iff_is_atomistic : is_coatomistic (order_dual \u03b1) \u2194 is_atomistic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_Inf_coatoms\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_Sup_atoms\u27e9\u27e9\n\n@[simp]\ntheorem is_atomistic_dual_iff_is_coatomistic : is_atomistic (order_dual \u03b1) \u2194 is_coatomistic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_Sup_atoms\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_Inf_coatoms\u27e9\u27e9\n\nnamespace is_atomistic\n\ninstance is_coatomistic_dual [h : is_atomistic \u03b1] : is_coatomistic (order_dual \u03b1) :=\nis_coatomistic_dual_iff_is_atomistic.2 h\n\nvariable [is_atomistic \u03b1]\n\n@[priority 100]\ninstance : is_atomic \u03b1 :=\n\u27e8\u03bb b, by { rcases eq_Sup_atoms b with \u27e8s, rfl, hs\u27e9,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ \u27e8h.some, hs _ h.some_spec, le_Sup h.some_spec\u27e9 } } \u27e9\n\nend is_atomistic\n\nsection is_atomistic\nvariables [is_atomistic \u03b1]\n\n@[simp]\ntheorem Sup_atoms_le_eq (b : \u03b1) : Sup {a : \u03b1 | is_atom a \u2227 a \u2264 b} = b :=\nbegin\n  rcases eq_Sup_atoms b with \u27e8s, rfl, hs\u27e9,\n  exact le_antisymm (Sup_le (\u03bb _, and.right)) (Sup_le_Sup (\u03bb a ha, \u27e8hs a ha, le_Sup ha\u27e9)),\nend\n\n@[simp]\ntheorem Sup_atoms_eq_top : Sup {a : \u03b1 | is_atom a} = \u22a4 :=\nbegin\n  refine eq.trans (congr rfl (set.ext (\u03bb x, _))) (Sup_atoms_le_eq \u22a4),\n  exact (and_iff_left le_top).symm,\nend\n\ntheorem le_iff_atom_le_imp {a b : \u03b1} :\n  a \u2264 b \u2194 \u2200 c : \u03b1, is_atom c \u2192 c \u2264 a \u2192 c \u2264 b :=\n\u27e8\u03bb ab c hc ca, le_trans ca ab, \u03bb h, begin\n  rw [\u2190 Sup_atoms_le_eq a, \u2190 Sup_atoms_le_eq b],\n  exact Sup_le_Sup (\u03bb c hc, \u27e8hc.1, h c hc.1 hc.2\u27e9),\nend\u27e9\n\nend is_atomistic\n\nnamespace is_coatomistic\n\ninstance is_atomistic_dual [h : is_coatomistic \u03b1] : is_atomistic (order_dual \u03b1) :=\nis_atomistic_dual_iff_is_coatomistic.2 h\n\nvariable [is_coatomistic \u03b1]\n\n@[priority 100]\ninstance : is_coatomic \u03b1 :=\n\u27e8\u03bb b, by { rcases eq_Inf_coatoms b with \u27e8s, rfl, hs\u27e9,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ \u27e8h.some, hs _ h.some_spec, Inf_le h.some_spec\u27e9 } } \u27e9\n\nend is_coatomistic\nend atomistic\n\n/-- An order is simple iff it has exactly two elements, `\u22a5` and `\u22a4`. -/\nclass is_simple_order (\u03b1 : Type*) [has_le \u03b1] [bounded_order \u03b1] extends nontrivial \u03b1 : Prop :=\n(eq_bot_or_eq_top : \u2200 (a : \u03b1), a = \u22a5 \u2228 a = \u22a4)\n\nexport is_simple_order (eq_bot_or_eq_top)\n\ntheorem is_simple_order_iff_is_simple_order_order_dual [has_le \u03b1] [bounded_order \u03b1] :\n  is_simple_order \u03b1 \u2194 is_simple_order (order_dual \u03b1) :=\nbegin\n  split; intro i; haveI := i,\n  { exact { exists_pair_ne := @exists_pair_ne \u03b1 _,\n      eq_bot_or_eq_top := \u03bb a, or.symm (eq_bot_or_eq_top ((order_dual.of_dual a)) : _ \u2228 _) } },\n  { exact { exists_pair_ne := @exists_pair_ne (order_dual \u03b1) _,\n      eq_bot_or_eq_top := \u03bb a, or.symm (eq_bot_or_eq_top (order_dual.to_dual a)) } }\nend\n\nlemma is_simple_order.bot_ne_top [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] :\n  (\u22a5 : \u03b1) \u2260 (\u22a4 : \u03b1) :=\nbegin\n  obtain \u27e8a, b, h\u27e9 := exists_pair_ne \u03b1,\n  rcases eq_bot_or_eq_top a with rfl|rfl;\n  rcases eq_bot_or_eq_top b with rfl|rfl;\n  simpa <|> simpa using h.symm\nend\n\nsection is_simple_order\n\nvariables [partial_order \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\n\ninstance {\u03b1} [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] : is_simple_order (order_dual \u03b1) :=\nis_simple_order_iff_is_simple_order_order_dual.1 (by apply_instance)\n\n/-- A simple `bounded_order` induces a preorder. This is not an instance to prevent loops. -/\nprotected def is_simple_order.preorder {\u03b1} [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] :\n  preorder \u03b1 :=\n{ le := (\u2264),\n  le_refl := \u03bb a, by rcases eq_bot_or_eq_top a with rfl|rfl; simp,\n  le_trans := \u03bb a b c, begin\n    rcases eq_bot_or_eq_top a with rfl|rfl,\n    { simp },\n    { rcases eq_bot_or_eq_top b with rfl|rfl,\n      { rcases eq_bot_or_eq_top c with rfl|rfl; simp },\n      { simp } }\n  end }\n\n/-- A simple partial ordered `bounded_order` induces a linear order.\nThis is not an instance to prevent loops. -/\nprotected def is_simple_order.linear_order [decidable_eq \u03b1] : linear_order \u03b1 :=\n{ le_total := \u03bb a b, by rcases eq_bot_or_eq_top a with rfl|rfl; simp,\n  decidable_le := \u03bb a b, if ha : a = \u22a5 then is_true (ha.le.trans bot_le) else\n    if hb : b = \u22a4 then is_true (le_top.trans hb.ge) else\n      is_false (\u03bb H, hb (top_unique\n        (le_trans (top_le_iff.mpr (or.resolve_left (eq_bot_or_eq_top a) ha)) H))),\n  decidable_eq := by assumption,\n  ..(infer_instance : partial_order \u03b1) }\n\n@[simp] lemma is_atom_top : is_atom (\u22a4 : \u03b1) :=\n\u27e8top_ne_bot, \u03bb a ha, or.resolve_right (eq_bot_or_eq_top a) (ne_of_lt ha)\u27e9\n\n@[simp] lemma is_coatom_bot : is_coatom (\u22a5 : \u03b1) := is_atom_dual_iff_is_coatom.1 is_atom_top\n\nend is_simple_order\n\nnamespace is_simple_order\n\nsection bounded_order\n\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\n\n/-- A simple partial ordered `bounded_order` induces a lattice.\nThis is not an instance to prevent loops -/\nprotected def lattice {\u03b1} [decidable_eq \u03b1] [partial_order \u03b1] [bounded_order \u03b1]\n  [is_simple_order \u03b1] : lattice \u03b1 :=\n@lattice_of_linear_order \u03b1 (is_simple_order.linear_order)\n\n/-- A lattice that is a `bounded_order` is a distributive lattice.\nThis is not an instance to prevent loops -/\nprotected def distrib_lattice : distrib_lattice \u03b1 :=\n{ le_sup_inf := \u03bb x y z, by { rcases eq_bot_or_eq_top x with rfl | rfl; simp },\n  .. (infer_instance : lattice \u03b1) }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : is_atomic \u03b1 :=\n\u27e8\u03bb b, (eq_bot_or_eq_top b).imp_right (\u03bb h, \u27e8\u22a4, \u27e8is_atom_top, ge_of_eq h\u27e9\u27e9)\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : is_coatomic \u03b1 := is_atomic_dual_iff_is_coatomic.1 is_simple_order.is_atomic\n\nend bounded_order\n\n/- It is important that in this section `is_simple_order` is the last type-class argument. -/\nsection decidable_eq\n\nvariables [decidable_eq \u03b1] [partial_order \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\n\n/-- Every simple lattice is isomorphic to `bool`, regardless of order. -/\n@[simps] def equiv_bool {\u03b1} [decidable_eq \u03b1] [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] :\n  \u03b1 \u2243 bool :=\n{ to_fun := \u03bb x, x = \u22a4,\n  inv_fun := \u03bb x, cond x \u22a4 \u22a5,\n  left_inv := \u03bb x, by { rcases (eq_bot_or_eq_top x) with rfl | rfl; simp [bot_ne_top] },\n  right_inv := \u03bb x, by { cases x; simp [bot_ne_top] } }\n\n/-- Every simple lattice over a partial order is order-isomorphic to `bool`. -/\ndef order_iso_bool : \u03b1 \u2243o bool :=\n{ map_rel_iff' := \u03bb a b, begin\n    rcases (eq_bot_or_eq_top a) with rfl | rfl,\n    { simp [bot_ne_top] },\n    { rcases (eq_bot_or_eq_top b) with rfl | rfl,\n      { simp [bot_ne_top.symm, bot_ne_top, bool.ff_lt_tt] },\n      { simp [bot_ne_top] } }\n  end,\n  ..equiv_bool }\n\n/- It is important that `is_simple_order` is the last type-class argument of this instance,\nso that type-class inference fails quickly if it doesn't apply. -/\n@[priority 200]\ninstance {\u03b1} [decidable_eq \u03b1] [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] : fintype \u03b1 :=\nfintype.of_equiv bool equiv_bool.symm\n\n/-- A simple `bounded_order` is also a `boolean_algebra`. -/\nprotected def boolean_algebra {\u03b1} [decidable_eq \u03b1] [lattice \u03b1] [bounded_order \u03b1]\n  [is_simple_order \u03b1] : boolean_algebra \u03b1 :=\n{ compl := \u03bb x, if x = \u22a5 then \u22a4 else \u22a5,\n  sdiff := \u03bb x y, if x = \u22a4 \u2227 y = \u22a5 then \u22a4 else \u22a5,\n  sdiff_eq := \u03bb x y, by rcases eq_bot_or_eq_top x with rfl | rfl;\n      simp [bot_ne_top, has_sdiff.sdiff, compl],\n  inf_compl_le_bot := \u03bb x, begin\n      rcases eq_bot_or_eq_top x with rfl | rfl,\n      { simp },\n      { simp only [top_inf_eq],\n        split_ifs with h h;\n        simp [h] }\n    end,\n  top_le_sup_compl := \u03bb x, by rcases eq_bot_or_eq_top x with rfl | rfl; simp,\n  sup_inf_sdiff := \u03bb x y, by rcases eq_bot_or_eq_top x with rfl | rfl;\n      rcases eq_bot_or_eq_top y with rfl | rfl; simp [bot_ne_top],\n  inf_inf_sdiff := \u03bb x y, begin\n      rcases eq_bot_or_eq_top x with rfl | rfl,\n      { simpa },\n      rcases eq_bot_or_eq_top y with rfl | rfl,\n      { simpa },\n      { simp only [true_and, top_inf_eq, eq_self_iff_true],\n        split_ifs with h h;\n        simpa [h] }\n    end,\n  .. (show bounded_order \u03b1, by apply_instance),\n  .. is_simple_order.distrib_lattice }\n\nend decidable_eq\n\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\nopen_locale classical\n\n/-- A simple `bounded_order` is also complete. -/\nprotected noncomputable def complete_lattice : complete_lattice \u03b1 :=\n{ Sup := \u03bb s, if \u22a4 \u2208 s then \u22a4 else \u22a5,\n  Inf := \u03bb s, if \u22a5 \u2208 s then \u22a5 else \u22a4,\n  le_Sup := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { exact bot_le },\n    { rw if_pos h } },\n  Sup_le := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { rw if_neg,\n      intro con,\n      exact bot_ne_top (eq_top_iff.2 (h \u22a4 con)) },\n    { exact le_top } },\n  Inf_le := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { rw if_pos h },\n    { exact le_top } },\n  le_Inf := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { exact bot_le },\n    { rw if_neg,\n      intro con,\n      exact top_ne_bot (eq_bot_iff.2 (h \u22a5 con)) } },\n  .. (infer_instance : lattice \u03b1),\n  .. (infer_instance : bounded_order \u03b1) }\n\n/-- A simple `bounded_order` is also a `complete_boolean_algebra`. -/\nprotected noncomputable def complete_boolean_algebra : complete_boolean_algebra \u03b1 :=\n{ infi_sup_le_sup_Inf := \u03bb x s, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { simp only [bot_sup_eq, \u2190 Inf_eq_infi], apply le_refl },\n    { simp only [top_sup_eq, le_top] }, },\n  inf_Sup_le_supr_inf := \u03bb x s, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { simp only [bot_inf_eq, bot_le] },\n    { simp only [top_inf_eq, \u2190 Sup_eq_supr], apply le_refl } },\n  .. is_simple_order.complete_lattice,\n  .. is_simple_order.boolean_algebra }\n\nend is_simple_order\n\nnamespace is_simple_order\nvariables [complete_lattice \u03b1] [is_simple_order \u03b1]\nset_option default_priority 100\n\ninstance : is_atomistic \u03b1 :=\n\u27e8\u03bb b, (eq_bot_or_eq_top b).elim\n  (\u03bb h, \u27e8\u2205, \u27e8h.trans Sup_empty.symm, \u03bb a ha, false.elim (set.not_mem_empty _ ha)\u27e9\u27e9)\n  (\u03bb h, \u27e8{\u22a4}, h.trans Sup_singleton.symm, \u03bb a ha, (set.mem_singleton_iff.1 ha).symm \u25b8 is_atom_top\u27e9)\u27e9\n\ninstance : is_coatomistic \u03b1 := is_atomistic_dual_iff_is_coatomistic.1 is_simple_order.is_atomistic\n\nend is_simple_order\nnamespace fintype\nnamespace is_simple_order\nvariables [partial_order \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] [decidable_eq \u03b1]\n\nlemma univ : (finset.univ : finset \u03b1) = {\u22a4, \u22a5} :=\nbegin\n  change finset.map _ (finset.univ : finset bool) = _,\n  rw fintype.univ_bool,\n  simp only [finset.map_insert, function.embedding.coe_fn_mk, finset.map_singleton],\n  refl,\nend\n\nlemma card : fintype.card \u03b1 = 2 :=\n(fintype.of_equiv_card _).trans fintype.card_bool\n\nend is_simple_order\nend fintype\n\nnamespace bool\n\ninstance : is_simple_order bool :=\n\u27e8\u03bb a, begin\n  rw [\u2190 finset.mem_singleton, or.comm, \u2190 finset.mem_insert,\n      top_eq_tt, bot_eq_ff, \u2190 fintype.univ_bool],\n  apply finset.mem_univ,\nend\u27e9\n\nend bool\n\ntheorem is_simple_order_iff_is_atom_top [partial_order \u03b1] [bounded_order \u03b1] :\n  is_simple_order \u03b1 \u2194 is_atom (\u22a4 : \u03b1) :=\n\u27e8\u03bb h, @is_atom_top _ _ _ h, \u03bb h,\n  { exists_pair_ne := \u27e8\u22a4, \u22a5, h.1\u27e9,\n    eq_bot_or_eq_top := \u03bb a, ((eq_or_lt_of_le le_top).imp_right (h.2 a)).symm }\u27e9\n\ntheorem is_simple_order_iff_is_coatom_bot [partial_order \u03b1] [bounded_order \u03b1] :\n  is_simple_order \u03b1 \u2194 is_coatom (\u22a5 : \u03b1) :=\nis_simple_order_iff_is_simple_order_order_dual.trans is_simple_order_iff_is_atom_top\n\nnamespace set\n\ntheorem is_simple_order_Iic_iff_is_atom [partial_order \u03b1] [bounded_order \u03b1] {a : \u03b1} :\n  is_simple_order (Iic a) \u2194 is_atom a :=\nis_simple_order_iff_is_atom_top.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  \u27e8\u03bb h b ab, subtype.mk_eq_mk.1 (h \u27e8b, le_of_lt ab\u27e9 ab),\n    \u03bb h \u27e8b, hab\u27e9 hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))\u27e9\n\ntheorem is_simple_order_Ici_iff_is_coatom [partial_order \u03b1] [bounded_order \u03b1] {a : \u03b1} :\n  is_simple_order (Ici a) \u2194 is_coatom a :=\nis_simple_order_iff_is_coatom_bot.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  \u27e8\u03bb h b ab, subtype.mk_eq_mk.1 (h \u27e8b, le_of_lt ab\u27e9 ab),\n    \u03bb h \u27e8b, hab\u27e9 hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))\u27e9\n\nend set\n\nnamespace order_iso\n\nvariables {\u03b2 : Type*}\n\n@[simp] lemma is_atom_iff [partial_order \u03b1] [order_bot \u03b1] [partial_order \u03b2] [order_bot \u03b2]\n  (f : \u03b1 \u2243o \u03b2) (a : \u03b1) :\n  is_atom (f a) \u2194 is_atom a :=\nand_congr (not_congr \u27e8\u03bb h, f.injective (f.map_bot.symm \u25b8 h), \u03bb h, f.map_bot \u25b8 (congr rfl h)\u27e9)\n  \u27e8\u03bb h b hb, f.injective ((h (f b) ((f : \u03b1 \u21aao \u03b2).lt_iff_lt.2 hb)).trans f.map_bot.symm),\n  \u03bb h b hb, f.symm.injective begin\n    rw f.symm.map_bot,\n    apply h,\n    rw [\u2190 f.symm_apply_apply a],\n    exact (f.symm : \u03b2 \u21aao \u03b1).lt_iff_lt.2 hb,\n  end\u27e9\n\n@[simp] lemma is_coatom_iff [partial_order \u03b1] [order_top \u03b1] [partial_order \u03b2] [order_top \u03b2]\n  (f : \u03b1 \u2243o \u03b2) (a : \u03b1) :\n  is_coatom (f a) \u2194 is_coatom a :=\nf.dual.is_atom_iff a\n\nlemma is_simple_order_iff [partial_order \u03b1] [bounded_order \u03b1] [partial_order \u03b2] [bounded_order \u03b2]\n  (f : \u03b1 \u2243o \u03b2) :\n  is_simple_order \u03b1 \u2194 is_simple_order \u03b2 :=\nby rw [is_simple_order_iff_is_atom_top, is_simple_order_iff_is_atom_top,\n  \u2190 f.is_atom_iff \u22a4, f.map_top]\n\nlemma is_simple_order [partial_order \u03b1] [bounded_order \u03b1] [partial_order \u03b2] [bounded_order \u03b2]\n  [h : is_simple_order \u03b2] (f : \u03b1 \u2243o \u03b2) :\n  is_simple_order \u03b1 :=\nf.is_simple_order_iff.mpr h\n\nlemma is_atomic_iff [partial_order \u03b1] [order_bot \u03b1] [partial_order \u03b2] [order_bot \u03b2] (f : \u03b1 \u2243o \u03b2) :\n  is_atomic \u03b1 \u2194 is_atomic \u03b2 :=\nbegin\n  suffices : (\u2200 b : \u03b1, b = \u22a5 \u2228 \u2203 (a : \u03b1), is_atom a \u2227 a \u2264 b) \u2194\n    (\u2200 b : \u03b2, b = \u22a5 \u2228 \u2203 (a : \u03b2), is_atom a \u2227 a \u2264 b),\n  from \u27e8\u03bb \u27e8p\u27e9, \u27e8this.mp p\u27e9, \u03bb \u27e8p\u27e9, \u27e8this.mpr p\u27e9\u27e9,\n  apply f.to_equiv.forall_congr,\n  simp_rw [rel_iso.coe_fn_to_equiv],\n  intro b, apply or_congr,\n  { rw [f.apply_eq_iff_eq_symm_apply, map_bot], },\n  { split,\n    { exact \u03bb \u27e8a, ha\u27e9, \u27e8f a, \u27e8(f.is_atom_iff a).mpr ha.1, f.le_iff_le.mpr ha.2\u27e9\u27e9, },\n    { rintros \u27e8b, \u27e8hb1, hb2\u27e9\u27e9,\n      refine \u27e8f.symm b, \u27e8(f.symm.is_atom_iff b).mpr hb1, _\u27e9\u27e9,\n      rwa [\u2190f.le_iff_le, f.apply_symm_apply], }, },\nend\n\nlemma is_coatomic_iff [partial_order \u03b1] [order_top \u03b1] [partial_order \u03b2] [order_top \u03b2] (f : \u03b1 \u2243o \u03b2) :\n  is_coatomic \u03b1 \u2194 is_coatomic \u03b2 :=\nby { rw [\u2190is_atomic_dual_iff_is_coatomic, \u2190is_atomic_dual_iff_is_coatomic],\n  exact f.dual.is_atomic_iff }\n\nend order_iso\n\nsection is_modular_lattice\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_modular_lattice \u03b1]\n\nnamespace is_compl\nvariables {a b : \u03b1} (hc : is_compl a b)\ninclude hc\n\nlemma is_atom_iff_is_coatom : is_atom a \u2194 is_coatom b :=\nset.is_simple_order_Iic_iff_is_atom.symm.trans $ hc.Iic_order_iso_Ici.is_simple_order_iff.trans\n  set.is_simple_order_Ici_iff_is_coatom\n\nlemma is_coatom_iff_is_atom : is_coatom a \u2194 is_atom b := hc.symm.is_atom_iff_is_coatom.symm\n\nend is_compl\n\nvariables [is_complemented \u03b1]\n\nlemma is_coatomic_of_is_atomic_of_is_complemented_of_is_modular [is_atomic \u03b1] : is_coatomic \u03b1 :=\n\u27e8\u03bb x, begin\n  rcases exists_is_compl x with \u27e8y, xy\u27e9,\n  apply (eq_bot_or_exists_atom_le y).imp _ _,\n  { rintro rfl,\n    exact eq_top_of_is_compl_bot xy },\n  { rintro \u27e8a, ha, ay\u27e9,\n    rcases exists_is_compl (xy.symm.Iic_order_iso_Ici \u27e8a, ay\u27e9) with \u27e8\u27e8b, xb\u27e9, hb\u27e9,\n    refine \u27e8\u2191(\u27e8b, xb\u27e9 : set.Ici x), is_coatom.of_is_coatom_coe_Ici _, xb\u27e9,\n    rw [\u2190 hb.is_atom_iff_is_coatom, order_iso.is_atom_iff],\n    apply ha.Iic }\nend\u27e9\n\nlemma is_atomic_of_is_coatomic_of_is_complemented_of_is_modular [is_coatomic \u03b1] : is_atomic \u03b1 :=\nis_coatomic_dual_iff_is_atomic.1 is_coatomic_of_is_atomic_of_is_complemented_of_is_modular\n\ntheorem is_atomic_iff_is_coatomic : is_atomic \u03b1 \u2194 is_coatomic \u03b1 :=\n\u27e8\u03bb h, @is_coatomic_of_is_atomic_of_is_complemented_of_is_modular _ _ _ _ _ h,\n  \u03bb h, @is_atomic_of_is_coatomic_of_is_complemented_of_is_modular _ _ _ _ _ h\u27e9\n\nend is_modular_lattice\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/order/atoms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7172967715029911}}
{"text": "/- Integers mod 37\n\n  A demonstration of how to use equivalence relations and equivalence classes in Lean.\n\n  We define the \"congruent mod 37\" relation on integers, prove it is an equivalence\n  relation, define Zmod37 to be the equivalence classes, and put a ring structure on\n  the quotient.\n\n-/\n-- this import is helpful for some intermediate calculations\nimport tactic.ring\n\n-- Definition of the equivalence relation\ndefinition cong_mod37 (a b : \u2124) : Prop := \u2203 (k : \u2124), k * 37 = b - a\n\n-- Now check it's an equivalence reln!\n\ntheorem cong_mod_refl : reflexive (cong_mod37) :=\nbegin\n  intro x,\n  -- to prove cong_mod37 x x we just observe that k = 0 will do.\n  use (0 : \u2124), -- this is k\n  simp,\nend\n\ntheorem cong_mod_symm : symmetric (cong_mod37) :=\nbegin\n  intros a b H,\n  -- H : cond_mod37 a b\n  cases H with l Hl,\n  -- Hl : l * 37 = (b - a)\n  -- Goal is to find an integer k with k * 37 = a - b\n  use -l,\n  simp [Hl],\nend\n\ntheorem cong_mod_trans : transitive (cong_mod37) :=\nbegin\n  intros a b c Hab Hbc,\n  cases Hab with l Hl,\n  cases Hbc with m Hm,\n  -- Hl : l * 37 = b - a, and Hm : m * 37 = c - b\n  -- Goal : \u2203 k, k * 37 = c - a\n  use (l + m),\n  rw [add_mul, Hl, Hm], ring\nend\n\n-- so we've now seen a general technique for proving a \u2248 b -- use (the k that works)\n\ntheorem cong_mod_equiv : equivalence (cong_mod37) :=\n\u27e8cong_mod_refl, cong_mod_symm, cong_mod_trans\u27e9\n\n-- Now let's put an equivalence relation on \u2124\ndefinition Zmod37.setoid : setoid \u2124 := { r := cong_mod37, iseqv := cong_mod_equiv }\n\n-- Tell the type class inference system about this equivalence relation.\nlocal attribute [instance] Zmod37.setoid\n\n-- Now we can make the quotient.\ndefinition Zmod37 := quotient (Zmod37.setoid)\n\n-- now a little bit of basic interface\n\nnamespace Zmod37\n\n-- Let's give a name to the reduction mod 37 map.\ndefinition reduce_mod37 : \u2124 \u2192 Zmod37 := quot.mk (cong_mod37)\n\n-- Let's now set up a coercion.\ndefinition coe_int_Zmod37 : has_coe \u2124 (Zmod37) := \u27e8reduce_mod37\u27e9\n\n-- Let's tell Lean that given an integer, it can consider it as\n-- an integer mod 37 automatically.\nlocal attribute [instance] coe_int_Zmod37\n\n-- Notation for 0 and 1\ninstance : has_zero (Zmod37) := \u27e8reduce_mod37 0\u27e9\ninstance : has_one (Zmod37) := \u27e8reduce_mod37 1\u27e9\n\n-- Add basic facts about 0 and 1 to the set of simp facts\n@[simp] theorem of_int_zero : (0 : (Zmod37))  = reduce_mod37 0 := rfl\n@[simp] theorem of_int_one : (1 : (Zmod37))  = reduce_mod37 1 := rfl\n\n-- now back to the maths\n\n-- here's a useful lemma -- it's needed to prove addition is well-defined on the quotient.\n-- Note the use of quotient.sound to get from Zmod37 back to Z\n\nlemma congr_add (a\u2081 a\u2082 b\u2081 b\u2082 : \u2124) : a\u2081 \u2248 b\u2081 \u2192 a\u2082 \u2248 b\u2082 \u2192 \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7 :=\nbegin\n  intros H1 H2,\n  cases H1 with m Hm, -- Hm : m * 37 = b\u2081 - a\u2081\n  cases H2 with n Hn, -- Hn : n * 37 = b\u2082 - a\u2082\n  -- goal is \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7\n  apply quotient.sound,\n  -- goal now a\u2081 + a\u2082 \u2248 b\u2081 + b\u2082, and we know how to do these.\n  use (m + n),\n  rw [add_mul, Hm, Hn], ring\nend\n\n-- That lemma above is *exactly* what we need to make sure addition is\n-- well-defined on Zmod37, so let's do this now, using quotient.lift\n\n-- note: stuff like \"add\" is used everywhere so it's best to protect.\nprotected definition add : Zmod37 \u2192 Zmod37 \u2192 Zmod37 :=\nquotient.lift\u2082 (\u03bb a b : \u2124, \u27e6a + b\u27e7) (begin\n  show \u2200 (a\u2081 a\u2082 b\u2081 b\u2082 : \u2124), a\u2081 \u2248 b\u2081 \u2192 a\u2082 \u2248 b\u2082 \u2192 \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7,\n  -- that's what quotient.lift\u2082 reduces us to doing. But we did it already!\n  exact congr_add,\nend)\n\n-- Now here's the lemma we need for the definition of neg\n\n-- I spelt out the proof for add, here's a quick term proof for neg.\n\nlemma congr_neg (a b : \u2124) : a \u2248 b \u2192 \u27e6-a\u27e7 = \u27e6-b\u27e7 :=\n\u03bb \u27e8m, Hm\u27e9, quotient.sound \u27e8-m, by simp [Hm]\u27e9\n\nprotected def neg : Zmod37 \u2192 Zmod37 := quotient.lift (\u03bb a : \u2124, \u27e6-a\u27e7) congr_neg\n\n-- For multiplication I won't even bother proving the lemma, I'll just let ring do it\n\nprotected def mul : Zmod37 \u2192 Zmod37 \u2192 Zmod37 :=\nquotient.lift\u2082 (\u03bb a b : \u2124, \u27e6a * b\u27e7) (\u03bb a\u2081 a\u2082 b\u2081 b\u2082 \u27e8m\u2081, H\u2081\u27e9 \u27e8m\u2082, H\u2082\u27e9,\n  quotient.sound \u27e8b\u2081 * m\u2082 + a\u2082 * m\u2081, by rw [add_mul, mul_assoc, mul_assoc, H\u2081, H\u2082]; ring\u27e9)\n\n-- this adds notation to the quotient\n\ninstance : has_add (Zmod37) := \u27e8Zmod37.add\u27e9\ninstance : has_neg (Zmod37) := \u27e8Zmod37.neg\u27e9\ninstance : has_mul (Zmod37) := \u27e8Zmod37.mul\u27e9\n\n-- these are now very cool proofs:\n@[simp] lemma coe_add {a b : \u2124} : (\u2191(a + b) : Zmod37) = \u2191a + \u2191b := rfl\n@[simp] lemma coe_neg {a : \u2124} : (\u2191(-a) : Zmod37) = -\u2191a := rfl\n@[simp] lemma coe_mul {a b : \u2124} : (\u2191(a * b) : Zmod37) = \u2191a * \u2191b := rfl\n\n-- Note that the proof of these results is `rfl`. If we had defined addition\n-- on the quotient in the standard way that mathematicians do,\n-- by choosing representatives and then adding them,\n-- then the proof would not be rfl. This is the power of quotient.lift.\n\n-- Now here's how to use quotient.induction_on and quotient.sound\n\ninstance : add_comm_group (Zmod37)  :=\n{ add_comm_group .\n  zero         := 0, -- because we already defined has_zero\n  add          := (+), -- could also have written has_add.add or Zmod37.add\n  neg          := has_neg.neg,\n  zero_add     :=\n    \u03bb abar, quotient.induction_on abar (begin\n      -- goal is \u2200 (a : \u2124), 0 + \u27e6a\u27e7 = \u27e6a\u27e7 -- that's what quotient.induction_on does for us\n      intro a,\n      apply quotient.sound, -- works because 0 + \u27e6a\u27e7 is by definition \u27e60\u27e7 + \u27e6a\u27e7 which\n                            -- is by definition \u27e60 + a\u27e7\n      -- goal is now 0 + a \u2248 a\n      -- here's the way we used to do it.\n      use (0 : \u2124),\n      simp,\n      -- but there are tricks now, which I'll show you with add_zero and add_assoc.\n    end),\n  add_assoc    := \u03bb abar bbar cbar,quotient.induction_on\u2083 abar bbar cbar (\u03bb a b c,\n    begin\n      -- goal now \u27e6a\u27e7 + \u27e6b\u27e7 + \u27e6c\u27e7 = \u27e6a\u27e7 + (\u27e6b\u27e7 + \u27e6c\u27e7)\n      apply quotient.sound,\n      -- goal now a + b + c \u2248 a + (b + c)\n      rw add_assoc, -- done :-) because after a rw a goal is closed if it's of the form x \u2248 x,\n                    -- as \u2248 is known by Lean to be reflexive.\n    end),\n  add_zero     := -- I will introduce some more sneaky stuff now\n                  -- add_zero for Zmod37 follows from add_zero on Z.\n                  -- Note use of $ instead of the brackets\n    \u03bb abar, quotient.induction_on abar $ \u03bb a, quotient.sound $ by rw add_zero,\n                  -- that's it! Term mode proof.\n  add_left_neg := -- super-slow method not even using quotient.induction_on\n    begin\n      intro abar,\n      cases (quot.exists_rep abar) with a Ha,\n      rw [\u2190Ha],\n      apply quot.sound,\n      use (0 : \u2124),\n      simp,\n    end,\n  -- but really all proofs should just look something like this\n  add_comm     := \u03bb abar bbar, quotient.induction_on\u2082 abar bbar $\n    \u03bb _ _,quotient.sound $ by rw add_comm,\n  -- the noise at the beginning is just the machine; all the work is done by the rewrite\n}\n\n-- Now let's just nail this using all the tricks in the book. All ring axioms on the quotient\n-- follow from the corresponding axioms for Z.\ninstance : comm_ring (Zmod37) :=\n{\n  mul := Zmod37.mul, -- could have written (*)\n  -- Now look how the proof of mul_assoc is just the same structure as add_comm above\n  -- but with three variables not two\n  mul_assoc := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb _ _ _, quotient.sound $\n    by rw mul_assoc,\n  one := 1,\n  one_mul := \u03bb a, quotient.induction_on a $ \u03bb _, quotient.sound $ by rw one_mul,\n  mul_one := \u03bb a, quotient.induction_on a $ \u03bb _, quotient.sound $ by rw mul_one,\n  left_distrib := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb _ _ _, quotient.sound $\n    by rw left_distrib,\n  right_distrib := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb _ _ _, quotient.sound $\n    by rw right_distrib,\n  mul_comm := \u03bb a b, quotient.induction_on\u2082 a b $ \u03bb _ _, quotient.sound $ by rw mul_comm,\n  ..Zmod37.add_comm_group\n}\n\nend Zmod37\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/docs/tutorial/Zmod37.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7172967684764642}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jeremy Avigad, Leonardo de Moura\n-/\nimport logic.connectives logic.identities algebra.binary\nopen eq.ops binary function\n\ndefinition set (X : Type) := X \u2192 Prop\n\nnamespace set\n\nvariable {X : Type}\n\n/- membership and subset -/\n\ndefinition mem (x : X) (a : set X) := a x\ninfix \u2208 := mem\nnotation a \u2209 b := \u00ac mem a b\n\ntheorem ext {a b : set X} (H : \u2200x, x \u2208 a \u2194 x \u2208 b) : a = b :=\nfunext (take x, propext (H x))\n\ndefinition subset (a b : set X) := \u2200\u2983x\u2984, x \u2208 a \u2192 x \u2208 b\ninfix \u2286 := subset\n\ndefinition superset (s t : set X) : Prop := t \u2286 s\ninfix \u2287 := superset\n\ntheorem subset.refl (a : set X) : a \u2286 a := take x, assume H, H\n\ntheorem subset.trans {a b c : set X} (subab : a \u2286 b) (subbc : b \u2286 c) : a \u2286 c :=\ntake x, assume ax, subbc (subab ax)\n\ntheorem subset.antisymm {a b : set X} (h\u2081 : a \u2286 b) (h\u2082 : b \u2286 a) : a = b :=\next (\u03bb x, iff.intro (\u03bb ina, h\u2081 ina) (\u03bb inb, h\u2082 inb))\n\n-- an alterantive name\ntheorem eq_of_subset_of_subset {a b : set X} (h\u2081 : a \u2286 b) (h\u2082 : b \u2286 a) : a = b :=\nsubset.antisymm h\u2081 h\u2082\n\ntheorem mem_of_subset_of_mem {s\u2081 s\u2082 : set X} {a : X} : s\u2081 \u2286 s\u2082 \u2192 a \u2208 s\u2081 \u2192 a \u2208 s\u2082 :=\nassume h\u2081 h\u2082, h\u2081 _ h\u2082\n\n/- strict subset -/\n\ndefinition strict_subset (a b : set X) := a \u2286 b \u2227 a \u2260 b\ninfix ` \u2282 `:50 := strict_subset\n\ntheorem strict_subset.irrefl (a : set X) : \u00ac a \u2282 a :=\nassume h, absurd rfl (and.elim_right h)\n\n/- bounded quantification -/\n\nabbreviation bounded_forall (a : set X) (P : X \u2192 Prop) := \u2200\u2983x\u2984, x \u2208 a \u2192 P x\nnotation `forallb` binders ` \u2208 ` a `, ` r:(scoped:1 P, P) := bounded_forall a r\nnotation `\u2200\u2080` binders ` \u2208 ` a `, ` r:(scoped:1 P, P) := bounded_forall a r\n\nabbreviation bounded_exists (a : set X) (P : X \u2192 Prop) := \u2203\u2983x\u2984, x \u2208 a \u2227 P x\nnotation `existsb` binders ` \u2208 ` a `, ` r:(scoped:1 P, P) := bounded_exists a r\nnotation `\u2203\u2080` binders ` \u2208 ` a `, ` r:(scoped:1 P, P) := bounded_exists a r\n\ntheorem bounded_exists.intro {P : X \u2192 Prop} {s : set X} {x : X} (xs : x \u2208 s) (Px : P x) :\n  \u2203\u2080 x \u2208 s, P x :=\nexists.intro x (and.intro xs Px)\n\nlemma bounded_forall_congr {A : Type} {S : set A} {P Q : A \u2192 Prop} (H : \u2200\u2080 x \u2208 S, P x \u2194 Q x) :\n  (\u2200\u2080 x \u2208 S, P x) = (\u2200\u2080 x \u2208 S, Q x) :=\nbegin\n  apply propext,\n  apply forall_congr,\n  intros x,\n  apply imp_congr_right,\n  apply H\nend\n\nlemma bounded_exists_congr {A : Type} {S : set A} {P Q : A \u2192 Prop} (H : \u2200\u2080 x \u2208 S, P x \u2194 Q x) :\n  (\u2203\u2080 x \u2208 S, P x) = (\u2203\u2080 x \u2208 S, Q x) :=\nbegin\n  apply propext,\n  apply exists_congr,\n  intros x,\n  apply and_congr_right,\n  apply H\nend\n\nsection\n  open classical\n\n  lemma not_bounded_exists {A : Type} {S : set A} {P : A \u2192 Prop} :\n    (\u00ac (\u2203\u2080 x \u2208 S, P x)) = (\u2200\u2080 x \u2208 S, \u00ac P x) :=\n  begin\n    rewrite forall_iff_not_exists,\n    apply propext,\n    apply forall_congr,\n    intro x,\n    rewrite not_and_iff_not_or_not,\n    symmetry,\n    apply imp_iff_not_or\n  end\n\n  lemma not_bounded_forall {A : Type} {S : set A} {P : A \u2192 Prop} :\n    (\u00ac (\u2200\u2080 x \u2208 S, P x)) = (\u2203\u2080 x \u2208 S, \u00ac P x) :=\n  calc (\u00ac (\u2200\u2080 x \u2208 S, P x)) = \u00ac \u00ac (\u2203\u2080 x \u2208 S, \u00ac P x) :\n    begin\n      rewrite not_bounded_exists,\n      apply (congr_arg not),\n      apply bounded_forall_congr,\n      intros x H,\n      rewrite not_not_iff\n    end\n    ... = (\u2203\u2080 x \u2208 S, \u00ac P x) : by (rewrite not_not_iff)\n\nend\n\n/- empty set -/\n\ndefinition empty : set X := \u03bbx, false\nnotation `\u2205` := empty\n\ntheorem not_mem_empty (x : X) : \u00ac (x \u2208 \u2205) :=\nassume H : x \u2208 \u2205, H\n\ntheorem mem_empty_eq (x : X) : x \u2208 \u2205 = false := rfl\n\ntheorem eq_empty_of_forall_not_mem {s : set X} (H : \u2200 x, x \u2209 s) : s = \u2205 :=\next (take x, iff.intro\n  (assume xs, absurd xs (H x))\n  (assume xe, absurd xe !not_mem_empty))\n\ntheorem ne_empty_of_mem {s : set X} {x : X} (H : x \u2208 s) : s \u2260 \u2205 :=\n  begin intro Hs, rewrite Hs at H, apply not_mem_empty _ H end\n\nsection\n  open classical\n\n  theorem exists_mem_of_ne_empty {s : set X} (H : s \u2260 \u2205) : \u2203 x, x \u2208 s :=\n  by_contradiction (assume H', H (eq_empty_of_forall_not_mem (forall_not_of_not_exists H')))\nend\n\ntheorem empty_subset (s : set X) : \u2205 \u2286 s :=\ntake x, assume H, false.elim H\n\ntheorem eq_empty_of_subset_empty {s : set X} (H : s \u2286 \u2205) : s = \u2205 :=\nsubset.antisymm H (empty_subset s)\n\ntheorem subset_empty_iff (s : set X) : s \u2286 \u2205 \u2194 s = \u2205 :=\niff.intro eq_empty_of_subset_empty (take xeq, by rewrite xeq; apply subset.refl \u2205)\n\nlemma bounded_forall_empty_iff {P : X \u2192 Prop} :\n  (\u2200\u2080x\u2208\u2205, P x) \u2194 true :=\niff.intro (take H, true.intro) (take H, by contradiction)\n\n/- universal set -/\n\ndefinition univ : set X := \u03bbx, true\n\ntheorem mem_univ (x : X) : x \u2208 univ := trivial\n\ntheorem mem_univ_iff (x : X) : x \u2208 univ \u2194 true := !iff.refl\n\ntheorem mem_univ_eq (x : X) : x \u2208 univ = true := rfl\n\ntheorem empty_ne_univ [h : inhabited X] : (empty : set X) \u2260 univ :=\nassume H : empty = univ,\nabsurd (mem_univ (inhabited.value h)) (eq.rec_on H (not_mem_empty _))\n\ntheorem subset_univ (s : set X) : s \u2286 univ := \u03bb x H, trivial\n\ntheorem eq_univ_of_univ_subset {s : set X} (H : univ \u2286 s) : s = univ :=\neq_of_subset_of_subset (subset_univ s) H\n\ntheorem eq_univ_of_forall {s : set X} (H : \u2200 x, x \u2208 s) : s = univ :=\next (take x, iff.intro (assume H', trivial) (assume H', H x))\n\n/- union -/\n\ndefinition union (a b : set X) : set X := \u03bbx, x \u2208 a \u2228 x \u2208 b\nnotation a \u222a b := union a b\n\ntheorem mem_union_left {x : X} {a : set X} (b : set X) : x \u2208 a \u2192 x \u2208 a \u222a b :=\nassume h, or.inl h\n\ntheorem mem_union_right {x : X} {b : set X} (a : set X) : x \u2208 b \u2192 x \u2208 a \u222a b :=\nassume h, or.inr h\n\ntheorem mem_unionl {x : X} {a b : set X} : x \u2208 a \u2192 x \u2208 a \u222a b :=\nassume h, or.inl h\n\ntheorem mem_unionr {x : X} {a b : set X} : x \u2208 b \u2192 x \u2208 a \u222a b :=\nassume h, or.inr h\n\ntheorem mem_or_mem_of_mem_union {x : X} {a b : set X} (H : x \u2208 a \u222a b) : x \u2208 a \u2228 x \u2208 b := H\n\ntheorem mem_union.elim {x : X} {a b : set X} {P : Prop}\n    (H\u2081 : x \u2208 a \u222a b) (H\u2082 : x \u2208 a \u2192 P) (H\u2083 : x \u2208 b \u2192 P) : P :=\nor.elim H\u2081 H\u2082 H\u2083\n\ntheorem mem_union_iff (x : X) (a b : set X) : x \u2208 a \u222a b \u2194 x \u2208 a \u2228 x \u2208 b := !iff.refl\n\ntheorem mem_union_eq (x : X) (a b : set X) : x \u2208 a \u222a b = (x \u2208 a \u2228 x \u2208 b) := rfl\n\ntheorem union_self (a : set X) : a \u222a a = a :=\next (take x, !or_self)\n\ntheorem union_empty (a : set X) : a \u222a \u2205 = a :=\next (take x, !or_false)\n\ntheorem empty_union (a : set X) : \u2205 \u222a a = a :=\next (take x, !false_or)\n\ntheorem union_comm (a b : set X) : a \u222a b = b \u222a a :=\next (take x, or.comm)\n\ntheorem union_assoc (a b c : set X) : (a \u222a b) \u222a c = a \u222a (b \u222a c) :=\next (take x, or.assoc)\n\ntheorem union_left_comm (s\u2081 s\u2082 s\u2083 : set X) : s\u2081 \u222a (s\u2082 \u222a s\u2083) = s\u2082 \u222a (s\u2081 \u222a s\u2083) :=\n!left_comm union_comm union_assoc s\u2081 s\u2082 s\u2083\n\ntheorem union_right_comm (s\u2081 s\u2082 s\u2083 : set X) : (s\u2081 \u222a s\u2082) \u222a s\u2083 = (s\u2081 \u222a s\u2083) \u222a s\u2082 :=\n!right_comm union_comm union_assoc s\u2081 s\u2082 s\u2083\n\ntheorem subset_union_left (s t : set X) : s \u2286 s \u222a t := \u03bb x H, or.inl H\n\ntheorem subset_union_right (s t : set X) : t \u2286 s \u222a t := \u03bb x H, or.inr H\n\ntheorem union_subset {s t r : set X} (sr : s \u2286 r) (tr : t \u2286 r) : s \u222a t \u2286 r :=\n\u03bb x xst, or.elim xst (\u03bb xs, sr xs) (\u03bb xt, tr xt)\n\n/- intersection -/\n\ndefinition inter (a b : set X) : set X := \u03bbx, x \u2208 a \u2227 x \u2208 b\nnotation a \u2229 b := inter a b\n\ntheorem mem_inter_iff (x : X) (a b : set X) : x \u2208 a \u2229 b \u2194 x \u2208 a \u2227 x \u2208 b := !iff.refl\n\ntheorem mem_inter_eq (x : X) (a b : set X) : x \u2208 a \u2229 b = (x \u2208 a \u2227 x \u2208 b) := rfl\n\ntheorem mem_inter {x : X} {a b : set X} (Ha : x \u2208 a) (Hb : x \u2208 b) : x \u2208 a \u2229 b :=\nand.intro Ha Hb\n\ntheorem mem_of_mem_inter_left {x : X} {a b : set X} (H : x \u2208 a \u2229 b) : x \u2208 a :=\nand.left H\n\ntheorem mem_of_mem_inter_right {x : X} {a b : set X} (H : x \u2208 a \u2229 b) : x \u2208 b :=\nand.right H\n\ntheorem inter_self (a : set X) : a \u2229 a = a :=\next (take x, !and_self)\n\ntheorem inter_empty (a : set X) : a \u2229 \u2205 = \u2205 :=\next (take x, !and_false)\n\ntheorem empty_inter (a : set X) : \u2205 \u2229 a = \u2205 :=\next (take x, !false_and)\n\ntheorem nonempty_of_inter_nonempty_right {T : Type} {s t : set T} (H : s \u2229 t \u2260 \u2205) : t \u2260 \u2205 :=\nsuppose t = \u2205,\nhave s \u2229 t = \u2205, by rewrite this; apply inter_empty,\nH this\n\ntheorem nonempty_of_inter_nonempty_left {T : Type} {s t : set T} (H : s \u2229 t \u2260 \u2205) : s \u2260 \u2205 :=\nsuppose s = \u2205,\nhave s \u2229 t = \u2205, by rewrite this; apply empty_inter,\nH this\n\ntheorem inter_comm (a b : set X) : a \u2229 b = b \u2229 a :=\next (take x, !and.comm)\n\ntheorem inter_assoc (a b c : set X) : (a \u2229 b) \u2229 c = a \u2229 (b \u2229 c) :=\next (take x, !and.assoc)\n\ntheorem inter_left_comm (s\u2081 s\u2082 s\u2083 : set X) : s\u2081 \u2229 (s\u2082 \u2229 s\u2083) = s\u2082 \u2229 (s\u2081 \u2229 s\u2083) :=\n!left_comm inter_comm inter_assoc s\u2081 s\u2082 s\u2083\n\ntheorem inter_right_comm (s\u2081 s\u2082 s\u2083 : set X) : (s\u2081 \u2229 s\u2082) \u2229 s\u2083 = (s\u2081 \u2229 s\u2083) \u2229 s\u2082 :=\n!right_comm inter_comm inter_assoc s\u2081 s\u2082 s\u2083\n\ntheorem inter_univ (a : set X) : a \u2229 univ = a :=\next (take x, !and_true)\n\ntheorem univ_inter (a : set X) : univ \u2229 a = a :=\next (take x, !true_and)\n\ntheorem inter_subset_left (s t : set X) : s \u2229 t \u2286 s := \u03bb x H, and.left H\n\ntheorem inter_subset_right (s t : set X) : s \u2229 t \u2286 t := \u03bb x H, and.right H\n\ntheorem inter_subset_inter_right {s t : set X} (u : set X) (H : s \u2286 t) : s \u2229 u \u2286 t \u2229 u :=\ntake x, assume xsu, and.intro (H (and.left xsu)) (and.right xsu)\n\ntheorem inter_subset_inter_left {s t : set X} (u : set X) (H : s \u2286 t) : u \u2229 s \u2286 u \u2229 t :=\ntake x, assume xus, and.intro (and.left xus) (H (and.right xus))\n\ntheorem subset_inter {s t r : set X} (rs : r \u2286 s) (rt : r \u2286 t) : r \u2286 s \u2229 t :=\n\u03bb x xr, and.intro (rs xr) (rt xr)\n\ntheorem not_mem_of_mem_of_not_mem_inter_left {s t : set X} {x : X} (Hxs : x \u2208 s) (Hnm : x \u2209 s \u2229 t) : x \u2209 t :=\n  suppose x \u2208 t,\n  have x \u2208 s \u2229 t, from and.intro Hxs this,\n  show false, from Hnm this\n\ntheorem not_mem_of_mem_of_not_mem_inter_right {s t : set X} {x : X} (Hxs : x \u2208 t) (Hnm : x \u2209 s \u2229 t) : x \u2209 s :=\n  suppose x \u2208 s,\n  have x \u2208 s \u2229 t, from and.intro this Hxs,\n  show false, from Hnm this\n\n/- distributivity laws -/\n\ntheorem inter_distrib_left (s t u : set X) : s \u2229 (t \u222a u) = (s \u2229 t) \u222a (s \u2229 u) :=\next (take x, !and.left_distrib)\n\ntheorem inter_distrib_right (s t u : set X) : (s \u222a t) \u2229 u = (s \u2229 u) \u222a (t \u2229 u) :=\next (take x, !and.right_distrib)\n\ntheorem union_distrib_left (s t u : set X) : s \u222a (t \u2229 u) = (s \u222a t) \u2229 (s \u222a u) :=\next (take x, !or.left_distrib)\n\ntheorem union_distrib_right (s t u : set X) : (s \u2229 t) \u222a u = (s \u222a u) \u2229 (t \u222a u) :=\next (take x, !or.right_distrib)\n\n/- set-builder notation -/\n\n-- {x : X | P}\ndefinition set_of (P : X \u2192 Prop) : set X := P\nnotation `{` binder ` | ` r:(scoped:1 P, set_of P) `}` := r\n\n-- {x \u2208 s | P}\ndefinition sep (P : X \u2192 Prop) (s : set X) : set X := \u03bbx, x \u2208 s \u2227 P x\nnotation `{` binder ` \u2208 ` s ` | ` r:(scoped:1 p, sep p s) `}` := r\n\n/- insert -/\n\ndefinition insert (x : X) (a : set X) : set X := {y : X | y = x \u2228 y \u2208 a}\n\n-- '{x, y, z}\nnotation `'{`:max a:(foldr `, ` (x b, insert x b) \u2205) `}`:0 := a\n\ntheorem subset_insert (x : X) (a : set X) : a \u2286 insert x a :=\ntake y, assume ys, or.inr ys\n\ntheorem mem_insert (x : X) (s : set X) : x \u2208 insert x s :=\nor.inl rfl\n\ntheorem mem_insert_of_mem {x : X} {s : set X} (y : X) : x \u2208 s \u2192 x \u2208 insert y s :=\nassume h, or.inr h\n\ntheorem eq_or_mem_of_mem_insert {x a : X} {s : set X} : x \u2208 insert a s \u2192 x = a \u2228 x \u2208 s :=\nassume h, h\n\ntheorem mem_of_mem_insert_of_ne {x a : X} {s : set X} (xin : x \u2208 insert a s) : x \u2260 a \u2192 x \u2208 s :=\nor_resolve_right (eq_or_mem_of_mem_insert xin)\n\ntheorem mem_insert_eq (x a : X) (s : set X) : x \u2208 insert a s = (x = a \u2228 x \u2208 s) :=\npropext (iff.intro !eq_or_mem_of_mem_insert\n  (or.rec (\u03bbH', (eq.substr H' !mem_insert)) !mem_insert_of_mem))\n\ntheorem insert_eq_of_mem {a : X} {s : set X} (H : a \u2208 s) : insert a s = s :=\next (\u03bb x, eq.substr (mem_insert_eq x a s)\n   (or_iff_right_of_imp (\u03bbH1, eq.substr H1 H)))\n\ntheorem insert.comm (x y : X) (s : set X) : insert x (insert y s) = insert y (insert x s) :=\next (take a, by rewrite [*mem_insert_eq, propext !or.left_comm])\n\n-- useful in proofs by induction\ntheorem forall_of_forall_insert {P : X \u2192 Prop} {a : X} {s : set X}\n    (H : \u2200 x, x \u2208 insert a s \u2192 P x) :\n  \u2200 x, x \u2208 s \u2192 P x :=\n\u03bb x xs, H x (!mem_insert_of_mem xs)\n\nlemma bounded_forall_insert_iff {P : X \u2192 Prop} {a : X} {s : set X} :\n  (\u2200\u2080x \u2208 insert a s, P x) \u2194 P a \u2227 (\u2200\u2080x \u2208 s, P x) :=\nbegin\n  apply iff.intro, all_goals (intro H),\n  { apply and.intro,\n    { apply H, apply mem_insert },\n    { intro x Hx, apply H, apply mem_insert_of_mem, assumption } },\n  { intro x Hx, cases Hx with eq Hx,\n    { cases eq, apply (and.elim_left H) },\n    { apply (and.elim_right H), assumption } }\nend\n\n/- singleton -/\n\ntheorem mem_singleton_iff (a b : X) : a \u2208 '{b} \u2194 a = b :=\niff.intro\n  (assume ainb, or.elim ainb (\u03bb aeqb, aeqb) (\u03bb f, false.elim f))\n  (assume aeqb, or.inl aeqb)\n\ntheorem mem_singleton (a : X) : a \u2208 '{a} := !mem_insert\n\ntheorem eq_of_mem_singleton {x y : X} (h : x \u2208 '{y}) : x = y :=\nor.elim (eq_or_mem_of_mem_insert h)\n  (suppose x = y, this)\n  (suppose x \u2208 \u2205, absurd this !not_mem_empty)\n\ntheorem mem_singleton_of_eq {x y : X} (H : x = y) : x \u2208 '{y} :=\neq.symm H \u25b8 mem_singleton y\n\ntheorem insert_eq (x : X) (s : set X) : insert x s = '{x} \u222a s :=\next (take y, iff.intro\n  (suppose y \u2208 insert x s,\n    or.elim this (suppose y = x, or.inl (or.inl this)) (suppose y \u2208 s, or.inr this))\n  (suppose y \u2208 '{x} \u222a s,\n    or.elim this\n      (suppose y \u2208 '{x}, or.inl (eq_of_mem_singleton this))\n      (suppose y \u2208 s, or.inr this)))\n\ntheorem pair_eq_singleton (a : X) : '{a, a} = '{a} :=\nby rewrite [insert_eq_of_mem !mem_singleton]\n\ntheorem singleton_ne_empty (a : X) : '{a} \u2260 \u2205 :=\nbegin\n  intro H,\n  apply not_mem_empty a,\n  rewrite -H,\n  apply mem_insert\nend\n\n/- separation -/\n\ntheorem mem_sep {s : set X} {P : X \u2192 Prop} {x : X} (xs : x \u2208 s) (Px : P x) : x \u2208 {x \u2208 s | P x} :=\nand.intro xs Px\n\ntheorem eq_sep_of_subset {s t : set X} (ssubt : s \u2286 t) : s = {x \u2208 t | x \u2208 s} :=\next (take x, iff.intro\n  (suppose x \u2208 s, and.intro (ssubt this) this)\n  (suppose x \u2208 {x \u2208 t | x \u2208 s}, and.right this))\n\ntheorem mem_sep_iff {s : set X} {P : X \u2192 Prop} {x : X} : x \u2208 {x \u2208 s | P x} \u2194 x \u2208 s \u2227 P x :=\n!iff.refl\n\ntheorem sep_subset (s : set X) (P : X \u2192 Prop) : {x \u2208 s | P x} \u2286 s :=\ntake x, assume H, and.left H\n\ntheorem forall_not_of_sep_empty {s : set X} {P : X \u2192 Prop} (H : {x \u2208 s | P x} = \u2205) : \u2200\u2080 x \u2208 s, \u00ac P x :=\n  take x, suppose x \u2208 s, suppose P x,\n  have x \u2208 {x \u2208 s | P x}, from and.intro `x \u2208 s` this,\n  show false, from ne_empty_of_mem this H\n\n/- complement -/\n\ndefinition compl (s : set X) : set X := {x | x \u2209 s}\nprefix `-` := compl\n\ntheorem mem_compl {s : set X} {x : X} (H : x \u2209 s) : x \u2208 -s := H\n\ntheorem not_mem_of_mem_compl {s : set X} {x : X} (H : x \u2208 -s) : x \u2209 s := H\n\ntheorem mem_compl_iff (s : set X) (x : X) : x \u2208 -s \u2194 x \u2209 s := !iff.refl\n\ntheorem inter_compl_self (s : set X) : s \u2229 -s = \u2205 :=\next (take x, !and_not_self_iff)\n\ntheorem compl_inter_self (s : set X) : -s \u2229 s = \u2205 :=\next (take x, !not_and_self_iff)\n\n/- some classical identities -/\n\nsection\n  open classical\n\n  theorem compl_empty : -(\u2205 : set X) = univ :=\n  ext (take x, iff.intro (assume H, trivial) (assume H, not_false))\n\n  theorem compl_union (s t : set X) : -(s \u222a t) = -s \u2229 -t :=\n  ext (take x, !not_or_iff_not_and_not)\n\n  theorem compl_compl (s : set X) : -(-s) = s :=\n  ext (take x, !not_not_iff)\n\n  theorem compl_inter (s t : set X) : -(s \u2229 t) = -s \u222a -t :=\n  ext (take x, !not_and_iff_not_or_not)\n\n  theorem compl_univ : -(univ : set X) = \u2205 :=\n  by rewrite [-compl_empty, compl_compl]\n\n  theorem union_eq_compl_compl_inter_compl (s t : set X) : s \u222a t = -(-s \u2229 -t) :=\n  ext (take x, !or_iff_not_and_not)\n\n  theorem inter_eq_compl_compl_union_compl (s t : set X) : s \u2229 t = -(-s \u222a -t) :=\n  ext (take x, !and_iff_not_or_not)\n\n  theorem union_compl_self (s : set X) : s \u222a -s = univ :=\n  ext (take x, !or_not_self_iff)\n\n  theorem compl_union_self (s : set X) : -s \u222a s = univ :=\n  ext (take x, !not_or_self_iff)\n\n  theorem compl_comp_compl :\n    #function compl \u2218 compl = @id (set X) :=\n  funext (\u03bb s, compl_compl s)\nend\n\n/- set difference -/\n\ndefinition diff (s t : set X) : set X := {x \u2208 s | x \u2209 t}\ninfix ` \\ `:70 := diff\n\ntheorem mem_diff {s t : set X} {x : X} (H1 : x \u2208 s) (H2 : x \u2209 t) : x \u2208 s \\ t :=\nand.intro H1 H2\n\ntheorem mem_of_mem_diff {s t : set X} {x : X} (H : x \u2208 s \\ t) : x \u2208 s :=\nand.left H\n\ntheorem not_mem_of_mem_diff {s t : set X} {x : X} (H : x \u2208 s \\ t) : x \u2209 t :=\nand.right H\n\ntheorem mem_diff_iff (s t : set X) (x : X) : x \u2208 s \\ t \u2194 x \u2208 s \u2227 x \u2209 t := !iff.refl\n\ntheorem mem_diff_eq (s t : set X) (x : X) : x \u2208 s \\ t = (x \u2208 s \u2227 x \u2209 t) := rfl\n\ntheorem diff_eq (s t : set X) : s \\ t = s \u2229 -t := rfl\n\ntheorem union_diff_cancel {s t : set X} [dec : \u03a0 x, decidable (x \u2208 s)] (H : s \u2286 t) : s \u222a (t \\ s) = t :=\next (take x, iff.intro\n  (assume H1 : x \u2208 s \u222a (t \\ s), or.elim H1 (assume H2, !H H2) (assume H2, and.left H2))\n  (assume H1 : x \u2208 t,\n    decidable.by_cases\n      (suppose x \u2208 s, or.inl this)\n      (suppose x \u2209 s, or.inr (and.intro H1 this))))\n\ntheorem diff_subset (s t : set X) : s \\ t \u2286 s := inter_subset_left s _\n\ntheorem compl_eq_univ_diff (s : set X) : -s = univ \\ s :=\next (take x, iff.intro (assume H, and.intro trivial H) (assume H, and.right H))\n\n/- powerset -/\n\ndefinition powerset (s : set X) : set (set X) := {x : set X | x \u2286 s}\nprefix `\ud835\udcab`:100 := powerset\n\ntheorem mem_powerset {x s : set X} (H : x \u2286 s) : x \u2208 \ud835\udcab s := H\n\ntheorem subset_of_mem_powerset {x s : set X} (H : x \u2208 \ud835\udcab s) : x \u2286 s := H\n\ntheorem mem_powerset_iff (x s : set X) : x \u2208 \ud835\udcab s \u2194 x \u2286 s := !iff.refl\n\n/- function image -/\n\nsection image\n\nvariables {Y Z : Type}\n\nabbreviation eq_on (f1 f2 : X \u2192 Y) (a : set X) : Prop :=\n\u2200\u2080 x \u2208 a, f1 x = f2 x\n\ndefinition image (f : X \u2192 Y) (a : set X) : set Y := {y : Y | \u2203x, x \u2208 a \u2227 f x = y}\ninfix ` ' ` := image\n\ntheorem image_eq_image_of_eq_on {f1 f2 : X \u2192 Y} {a : set X} (H1 : eq_on f1 f2 a) :\n  f1 ' a = f2 ' a :=\next (take y, iff.intro\n  (assume H2,\n    obtain x (H3 : x \u2208 a \u2227 f1 x = y), from H2,\n    have H4 : x \u2208 a, from and.left H3,\n    have H5 : f2 x = y, from (H1 H4)\u207b\u00b9 \u2b1d and.right H3,\n    exists.intro x (and.intro H4 H5))\n  (assume H2,\n    obtain x (H3 : x \u2208 a \u2227 f2 x = y), from H2,\n    have H4 : x \u2208 a, from and.left H3,\n    have H5 : f1 x = y, from (H1 H4) \u2b1d and.right H3,\n    exists.intro x (and.intro H4 H5)))\n\ntheorem mem_image {f : X \u2192 Y} {a : set X} {x : X} {y : Y}\n  (H1 : x \u2208 a) (H2 : f x = y) : y \u2208 f ' a :=\nexists.intro x (and.intro H1 H2)\n\ntheorem mem_image_of_mem (f : X \u2192 Y) {x : X} {a : set X} (H : x \u2208 a) : f x \u2208 image f a :=\nmem_image H rfl\n\nlemma image_comp (f : Y \u2192 Z) (g : X \u2192 Y) (a : set X) : (f \u2218 g) ' a = f ' (g ' a) :=\next (take z,\n  iff.intro\n    (assume Hz : z \u2208 (f \u2218 g) ' a,\n      obtain x (Hx\u2081 : x \u2208 a) (Hx\u2082 : f (g x) = z), from Hz,\n      have Hgx : g x \u2208 g ' a, from mem_image Hx\u2081 rfl,\n      show z \u2208 f ' (g ' a), from mem_image Hgx Hx\u2082)\n    (assume Hz : z \u2208 f ' (g 'a),\n      obtain y (Hy\u2081 : y \u2208 g ' a) (Hy\u2082 : f y = z), from Hz,\n      obtain x (Hz\u2081 : x \u2208 a) (Hz\u2082 : g x = y),      from Hy\u2081,\n      show z \u2208 (f \u2218 g) ' a, from mem_image Hz\u2081 (Hz\u2082\u207b\u00b9 \u25b8 Hy\u2082)))\n\nlemma image_subset {a b : set X} (f : X \u2192 Y) (H : a \u2286 b) : f ' a \u2286 f ' b :=\ntake y, assume Hy : y \u2208 f ' a,\nobtain x (Hx\u2081 : x \u2208 a) (Hx\u2082 : f x = y), from Hy,\nmem_image (H Hx\u2081) Hx\u2082\n\ntheorem image_union (f : X \u2192 Y) (s t : set X) :\n  image f (s \u222a t) = image f s \u222a image f t :=\next (take y, iff.intro\n  (assume H : y \u2208 image f (s \u222a t),\n    obtain x [(xst : x \u2208 s \u222a t) (fxy : f x = y)], from H,\n    or.elim xst\n      (assume xs, or.inl (mem_image xs fxy))\n      (assume xt, or.inr (mem_image xt fxy)))\n  (assume H : y \u2208 image f s \u222a image f t,\n    or.elim H\n      (assume yifs : y \u2208 image f s,\n        obtain x [(xs : x \u2208 s) (fxy : f x = y)], from yifs,\n        mem_image (or.inl xs) fxy)\n      (assume yift : y \u2208 image f t,\n        obtain x [(xt : x \u2208 t) (fxy : f x = y)], from yift,\n        mem_image (or.inr xt) fxy)))\n\ntheorem image_empty (f : X \u2192 Y) : image f \u2205 = \u2205 :=\neq_empty_of_forall_not_mem\n  (take y, suppose y \u2208 image f \u2205,\n    obtain x [(H : x \u2208 empty) H'], from this,\n    H)\n\ntheorem mem_image_compl (t : set X) (S : set (set X)) :\n  t \u2208 compl ' S \u2194 -t \u2208 S :=\niff.intro\n  (suppose t \u2208 compl ' S,\n    obtain t' [(Ht' : t' \u2208 S) (Ht : -t' = t)], from this,\n    show -t \u2208 S, by rewrite [-Ht, compl_compl]; exact Ht')\n  (suppose -t \u2208 S,\n    have -(-t) \u2208 compl 'S, from mem_image_of_mem compl this,\n    show t \u2208 compl 'S, from compl_compl t \u25b8 this)\n\ntheorem image_id (s : set X) : id ' s = s :=\next (take x, iff.intro\n  (suppose x \u2208 id ' s,\n    obtain x' [(Hx' : x' \u2208 s) (x'eq : x' = x)], from this,\n    show x \u2208 s, by rewrite [-x'eq]; apply Hx')\n  (suppose x \u2208 s, mem_image_of_mem id this))\n\ntheorem compl_compl_image (S : set (set X)) :\n  compl ' (compl ' S) = S :=\nby rewrite [-image_comp, compl_comp_compl, image_id]\n\nlemma bounded_forall_image_of_bounded_forall {f : X \u2192 Y} {S : set X} {P : Y \u2192 Prop}\n  (H : \u2200\u2080 x \u2208 S, P (f x)) : \u2200\u2080 y \u2208 f ' S, P y :=\nbegin\n  intro x' Hx;\n  cases Hx with x Hx;\n  cases Hx with Hx eq;\n  rewrite (eq\u207b\u00b9);\n  apply H;\n  assumption\nend\n\nlemma bounded_forall_image_iff {f : X \u2192 Y} {S : set X} {P : Y \u2192 Prop} :\n  (\u2200\u2080 y \u2208 f ' S, P y) \u2194 (\u2200\u2080 x \u2208 S, P (f x)) :=\niff.intro (take H x Hx, H _ (!mem_image_of_mem `x \u2208 S`)) bounded_forall_image_of_bounded_forall\n\nlemma image_insert_eq {f : X \u2192 Y} {a : X} {S : set X} :\n  f ' insert a S = insert (f a) (f ' S) :=\nbegin\n  apply set.ext,\n  intro x, apply iff.intro, all_goals (intros H),\n  { cases H with y Hy, cases Hy with Hy eq, rewrite (eq\u207b\u00b9), cases Hy with y_eq,\n    { rewrite y_eq, apply mem_insert },\n    { apply mem_insert_of_mem, apply mem_image_of_mem, assumption } },\n  { cases H with eq Hx,\n    { rewrite eq, apply mem_image_of_mem, apply mem_insert },\n    { cases Hx with y Hy, cases Hy with Hy eq,\n      rewrite (eq\u207b\u00b9), apply mem_image_of_mem, apply mem_insert_of_mem, assumption } }\nend\n\nend image\n\n/- collections of disjoint sets -/\n\ndefinition disjoint_sets (S : set (set X)) : Prop := \u2200 a b, a \u2208 S \u2192 b \u2208 S \u2192 a \u2260 b \u2192 a \u2229 b = \u2205\n\ntheorem disjoint_sets_empty : disjoint_sets (\u2205 : set (set X)) :=\ntake a b, assume H, !not.elim !not_mem_empty H\n\ntheorem disjoint_sets_union {s t : set (set X)} (Hs : disjoint_sets s) (Ht : disjoint_sets t)\n    (H : \u2200 x y, x \u2208 s \u2227 y \u2208 t \u2192 x \u2229 y = \u2205) :\n  disjoint_sets (s \u222a t) :=\ntake a b, assume Ha Hb Hneq, or.elim Ha\n (assume H1, or.elim Hb\n   (suppose b \u2208 s, (Hs a b) H1 this Hneq)\n   (suppose b \u2208 t, (H a b) (and.intro H1 this)))\n (assume H2, or.elim Hb\n   (suppose b \u2208 s, !inter_comm \u25b8 ((H b a) (and.intro this H2)))\n   (suppose b \u2208 t, (Ht a b) H2 this Hneq))\n\ntheorem disjoint_sets_singleton (s : set (set X)) : disjoint_sets '{s} :=\ntake a b, assume Ha Hb  Hneq,\nabsurd (eq.trans ((iff.elim_left !mem_singleton_iff) Ha) ((iff.elim_left !mem_singleton_iff) Hb)\u207b\u00b9)\n    Hneq\n\n/- large unions -/\n\nsection large_unions\n  variables {I : Type}\n  variable a : set I\n  variable b : I \u2192 set X\n  variable C : set (set X)\n\n  definition sUnion : set X := {x : X | \u2203\u2080 c \u2208 C, x \u2208 c}\n  definition sInter : set X := {x : X | \u2200\u2080 c \u2208 C, x \u2208 c}\n\n  prefix `\u22c3\u2080`:110 := sUnion\n  prefix `\u22c2\u2080`:110 := sInter\n\n  definition Union  : set X := {x : X | \u2203i, x \u2208 b i}\n  definition Inter  : set X := {x : X | \u2200i, x \u2208 b i}\n\n  notation `\u22c3` binders `, ` r:(scoped f, Union f) := r\n  notation `\u22c2` binders `, ` r:(scoped f, Inter f) := r\n\n  definition bUnion : set X := {x : X | \u2203\u2080 i \u2208 a, x \u2208 b i}\n  definition bInter : set X := {x : X | \u2200\u2080 i \u2208 a, x \u2208 b i}\n\n  notation `\u22c3` binders ` \u2208 ` s `, ` r:(scoped f, bUnion s f) := r\n  notation `\u22c2` binders ` \u2208 ` s `, ` r:(scoped f, bInter s f) := r\n\nend large_unions\n\n-- sUnion and sInter: a collection (set) of sets\n\ntheorem mem_sUnion {x : X} {t : set X} {S : set (set X)} (Hx : x \u2208 t) (Ht : t \u2208 S) :\n  x \u2208 \u22c3\u2080 S :=\nexists.intro t (and.intro Ht Hx)\n\ntheorem not_mem_of_not_mem_sUnion {x : X} {t : set X} {S : set (set X)} (Hx : x \u2209 \u22c3\u2080 S) (Ht : t \u2208 S) :\n        x \u2209 t :=\n  suppose x \u2208 t,\n  have x \u2208 \u22c3\u2080 S, from mem_sUnion this Ht,\n  show false, from Hx this\n\ntheorem mem_sInter {x : X} {t : set X} {S : set (set X)} (H : \u2200\u2080 t \u2208 S, x \u2208 t) :\n  x \u2208 \u22c2\u2080 S :=\nH\n\ntheorem sInter_subset_of_mem {S : set (set X)} {t : set X} (tS : t \u2208 S) :\n  (\u22c2\u2080 S) \u2286 t :=\ntake x, assume H, H t tS\n\ntheorem subset_sUnion_of_mem {S : set (set X)} {t : set X} (tS : t \u2208 S) :\n  t \u2286 (\u22c3\u2080 S) :=\ntake x, assume H, exists.intro t (and.intro tS H)\n\ntheorem sUnion_empty : \u22c3\u2080 \u2205 = (\u2205 : set X) :=\neq_empty_of_forall_not_mem\n  (take x, suppose x \u2208 sUnion \u2205,\n    obtain t [(Ht : t \u2208 \u2205) Ht'], from this,\n    show false, from Ht)\n\ntheorem sInter_empty : \u22c2\u2080 \u2205 = (univ : set X) :=\neq_univ_of_forall (\u03bb x s H, false.elim H)\n\ntheorem sUnion_singleton (s : set X) : \u22c3\u2080 '{s} = s :=\next (take x, iff.intro\n  (suppose x \u2208 sUnion '{s},\n    obtain u [(Hu : u \u2208 '{s}) (xu : x \u2208 u)], from this,\n    have u = s, from eq_of_mem_singleton Hu,\n    show x \u2208 s, by rewrite -this; apply xu)\n  (suppose x \u2208 s,\n    mem_sUnion this (mem_singleton s)))\n\ntheorem sInter_singleton (s : set X) : \u22c2\u2080 '{s} = s :=\next (take x, iff.intro\n  (suppose x \u2208 \u22c2\u2080 '{s}, show x \u2208 s, from this (mem_singleton s))\n  (suppose x \u2208 s, take u, suppose u \u2208 '{s},\n    show x \u2208 u, by rewrite [eq_of_mem_singleton this]; assumption))\n\ntheorem sUnion_union (S T : set (set X)) : \u22c3\u2080 (S \u222a T) = \u22c3\u2080 S \u222a \u22c3\u2080 T :=\next (take x, iff.intro\n  (suppose x \u2208 sUnion (S \u222a T),\n    obtain u [(Hu : u \u2208 S \u222a T) (xu : x \u2208 u)], from this,\n    or.elim Hu\n      (assume uS, or.inl (mem_sUnion xu uS))\n      (assume uT, or.inr (mem_sUnion xu uT)))\n  (suppose x \u2208 sUnion S \u222a sUnion T,\n    or.elim this\n      (suppose x \u2208 sUnion S,\n        obtain u [(uS : u \u2208 S) (xu : x \u2208 u)], from this,\n        mem_sUnion xu (or.inl uS))\n      (suppose x \u2208 sUnion T,\n        obtain u [(uT : u \u2208 T) (xu : x \u2208 u)], from this,\n        mem_sUnion xu (or.inr uT))))\n\ntheorem sInter_union (S T : set (set X)) : \u22c2\u2080 (S \u222a T) = \u22c2\u2080 S \u2229 \u22c2\u2080 T :=\next (take x, iff.intro\n  (assume H : x \u2208 \u22c2\u2080 (S \u222a T),\n    and.intro (\u03bb u uS, H (or.inl uS)) (\u03bb u uT, H (or.inr uT)))\n  (assume H : x \u2208 \u22c2\u2080 S \u2229 \u22c2\u2080 T,\n    take u, suppose u \u2208 S \u222a T, or.elim this (\u03bb uS, and.left H u uS) (\u03bb uT, and.right H u uT)))\n\ntheorem sUnion_insert (s : set X) (T : set (set X)) :\n  \u22c3\u2080 (insert s T) = s \u222a \u22c3\u2080 T :=\nby rewrite [insert_eq, sUnion_union, sUnion_singleton]\n\ntheorem sInter_insert (s : set X) (T : set (set X)) :\n  \u22c2\u2080 (insert s T) = s \u2229 \u22c2\u2080 T :=\nby rewrite [insert_eq, sInter_union, sInter_singleton]\n\ntheorem compl_sUnion (S : set (set X)) :\n  - \u22c3\u2080 S = \u22c2\u2080 (compl ' S) :=\next (take x, iff.intro\n  (assume H : x \u2208 -(\u22c3\u2080 S),\n    take t, suppose t \u2208 compl ' S,\n    obtain t' [(Ht' : t' \u2208 S) (Ht : -t' = t)], from this,\n    have x \u2208 -t', from suppose x \u2208 t', H (mem_sUnion this Ht'),\n    show x \u2208 t, by rewrite -Ht; apply this)\n  (assume H : x \u2208 \u22c2\u2080 (compl ' S),\n    suppose x \u2208 \u22c3\u2080 S,\n    obtain t [(tS : t \u2208 S) (xt : x \u2208 t)], from this,\n    have -t \u2208 compl ' S, from mem_image_of_mem compl tS,\n    have x \u2208 -t, from H this,\n    show false, proof this xt qed))\n\ntheorem sUnion_eq_compl_sInter_compl (S : set (set X)) :\n  \u22c3\u2080 S = - \u22c2\u2080 (compl ' S) :=\nby rewrite [-compl_compl (\u22c3\u2080 S), compl_sUnion]\n\ntheorem compl_sInter (S : set (set X)) :\n  - \u22c2\u2080 S = \u22c3\u2080 (compl ' S) :=\nby rewrite [sUnion_eq_compl_sInter_compl, compl_compl_image]\n\ntheorem sInter_eq_comp_sUnion_compl (S : set (set X)) :\n   \u22c2\u2080 S = -(\u22c3\u2080 (compl ' S)) :=\nby rewrite [-compl_compl (\u22c2\u2080 S), compl_sInter]\n\ntheorem inter_sUnion_nonempty_of_inter_nonempty {s t : set X} {S : set (set X)} (Hs : t \u2208 S) (Hne : s \u2229 t \u2260 \u2205) :\n        s \u2229 \u22c3\u2080 S \u2260 \u2205 :=\n  obtain x Hsx Htx, from exists_mem_of_ne_empty Hne,\n  have x \u2208 \u22c3\u2080 S, from mem_sUnion Htx Hs,\n  ne_empty_of_mem (mem_inter Hsx this)\n\ntheorem sUnion_inter_nonempty_of_inter_nonempty {s t : set X} {S : set (set X)} (Hs : t \u2208 S) (Hne : t \u2229 s \u2260 \u2205) :\n        (\u22c3\u2080 S) \u2229 s \u2260 \u2205 :=\n  obtain x Htx Hsx, from exists_mem_of_ne_empty Hne,\n  have x \u2208 \u22c3\u2080 S, from mem_sUnion Htx Hs,\n  ne_empty_of_mem (mem_inter this Hsx)\n\n-- Union and Inter: a family of sets indexed by a type\n\ntheorem Union_subset {I : Type} {b : I \u2192 set X} {c : set X} (H : \u2200 i, b i \u2286 c) : (\u22c3 i, b i) \u2286 c :=\ntake x,\nsuppose x \u2208 Union b,\nobtain i (Hi : x \u2208 b i), from this,\nshow x \u2208 c, from H i Hi\n\ntheorem subset_Inter {I : Type} {b : I \u2192 set X} {c : set X} (H : \u2200 i, c \u2286 b i) : c \u2286 \u22c2 i, b i :=\n\u03bb x cx i, H i cx\n\ntheorem Union_eq_sUnion_image {X I : Type} (s : I \u2192 set X) : (\u22c3 i, s i) = \u22c3\u2080 (s ' univ) :=\next (take x, iff.intro\n  (suppose x \u2208 Union s,\n    obtain i (Hi : x \u2208 s i), from this,\n    mem_sUnion Hi (mem_image_of_mem s trivial))\n  (suppose x \u2208 sUnion (s ' univ),\n    obtain t [(Ht : t \u2208 s ' univ) (Hx : x \u2208 t)], from this,\n    obtain i [univi (Hi : s i = t)], from Ht,\n    exists.intro i (show x \u2208 s i, by rewrite Hi; apply Hx)))\n\ntheorem Inter_eq_sInter_image {X I : Type} (s : I \u2192 set X) : (\u22c2 i, s i) = \u22c2\u2080 (s ' univ) :=\next (take x, iff.intro\n  (assume H : x \u2208 Inter s,\n    take t,\n    suppose t \u2208 s 'univ,\n    obtain i [univi (Hi : s i = t)], from this,\n    show x \u2208 t, by rewrite -Hi; exact H i)\n  (assume H : x \u2208 \u22c2\u2080 (s ' univ),\n    take i,\n    have s i \u2208 s ' univ, from mem_image_of_mem s trivial,\n    show x \u2208 s i, from H this))\n\ntheorem compl_Union {X I : Type} (s : I \u2192 set X) : - (\u22c3 i, s i) = (\u22c2 i, - s i) :=\nby rewrite [Union_eq_sUnion_image, compl_sUnion, -image_comp, -Inter_eq_sInter_image]\n\ntheorem compl_Inter {X I : Type} (s : I \u2192 set X) : -(\u22c2 i, s i) = (\u22c3 i, - s i) :=\nby rewrite [Inter_eq_sInter_image, compl_sInter, -image_comp, -Union_eq_sUnion_image]\n\ntheorem Union_eq_comp_Inter_comp {X I : Type} (s : I \u2192 set X) : (\u22c3 i, s i) = - (\u22c2 i, - s i) :=\nby rewrite [-compl_compl (\u22c3 i, s i), compl_Union]\n\ntheorem Inter_eq_comp_Union_comp {X I : Type} (s : I \u2192 set X) : (\u22c2 i, s i) = - (\u22c3 i, -s i) :=\nby rewrite [-compl_compl (\u22c2 i, s i), compl_Inter]\n\nlemma inter_distrib_Union_left {X I : Type} (s : I \u2192 set X) (a : set X) :\n  a \u2229 (\u22c3 i, s i) = \u22c3 i, a \u2229 s i :=\next (take x, iff.intro\n  (assume H, obtain i Hi, from and.elim_right H,\n    have x \u2208 a \u2229 s i, from and.intro (and.elim_left H) Hi,\n    show _, from exists.intro i this)\n  (assume H, obtain i [xa xsi], from H,\n   show _, from and.intro xa (exists.intro i xsi)))\n\nsection\n  open classical\n\n  lemma union_distrib_Inter_left {X I : Type} (s : I \u2192 set X) (a : set X) :\n    a \u222a (\u22c2 i, s i) = \u22c2 i, a \u222a s i :=\n  ext (take x, iff.intro\n    (assume H, or.elim H\n      (assume H1, take i, or.inl H1)\n      (assume H1, take i, or.inr (H1 i)))\n    (assume H,\n      by_cases\n        (suppose x \u2208 a, or.inl this)\n        (suppose x \u2209 a, or.inr (take i, or.resolve_left (H i) this))))\nend\n\n-- these are useful for turning binary union / intersection into countable ones\n\ndefinition bin_ext (s t : set X) (n : \u2115) : set X :=\nnat.cases_on n s (\u03bb m, t)\n\nlemma Union_bin_ext (s t : set X) : (\u22c3 i, bin_ext s t i) = s \u222a t :=\next (take x, iff.intro\n  (assume H,\n    obtain i (Hi : x \u2208 (bin_ext s t) i), from H,\n    by cases i; apply or.inl Hi; apply or.inr Hi)\n  (assume H,\n    or.elim H\n      (suppose x \u2208 s, exists.intro 0 this)\n      (suppose x \u2208 t, exists.intro 1 this)))\n\nlemma Inter_bin_ext (s t : set X) : (\u22c2 i, bin_ext s t i) = s \u2229 t :=\next (take x, iff.intro\n  (assume H, and.intro (H 0) (H 1))\n  (assume H, by intro i; cases i;\n    apply and.elim_left H; apply and.elim_right H))\n\n-- bUnion and bInter: a family of sets indexed by a set (\"b\" is for bounded)\n\nvariable {Y : Type}\n\ntheorem mem_bUnion {s : set X} {f : X \u2192 set Y} {x : X} {y : Y}\n    (xs : x \u2208 s) (yfx : y \u2208 f x) :\n  y \u2208 \u22c3 x \u2208 s, f x :=\nexists.intro x (and.intro xs yfx)\n\ntheorem mem_bInter {s : set X} {f : X \u2192 set Y} {y : Y} (H : \u2200\u2080 x \u2208 s, y \u2208 f x) :\n  y \u2208 \u22c2 x \u2208 s, f x :=\nH\n\ntheorem bUnion_subset {s : set X} {t : set Y} {f : X \u2192 set Y} (H : \u2200\u2080 x \u2208 s, f x \u2286 t) :\n  (\u22c3 x \u2208 s, f x) \u2286 t :=\ntake y, assume Hy,\nobtain x [xs yfx], from Hy,\nshow y \u2208 t, from H xs yfx\n\ntheorem subset_bInter {s : set X} {t : set Y} {f : X \u2192 set Y} (H : \u2200\u2080 x \u2208 s, t \u2286 f x) :\n  t \u2286 \u22c2 x \u2208 s, f x :=\ntake y, assume yt, take x, assume xs, H xs yt\n\ntheorem subset_bUnion_of_mem {s : set X} {f : X \u2192 set Y} {x : X} (xs : x \u2208 s) :\n  f x \u2286 \u22c3 x \u2208 s, f x :=\ntake y, assume Hy, mem_bUnion xs Hy\n\ntheorem bInter_subset_of_mem {s : set X} {f : X \u2192 set Y} {x : X} (xs : x \u2208 s) :\n  (\u22c2 x \u2208 s, f x) \u2286 f x :=\ntake y, assume Hy, Hy x xs\n\ntheorem bInter_empty (f : X \u2192 set Y) : (\u22c2 x \u2208 (\u2205 : set X), f x) = univ :=\neq_univ_of_forall (take y x xine, absurd xine !not_mem_empty)\n\ntheorem bInter_singleton (a : X) (f : X \u2192 set Y) : (\u22c2 x \u2208 '{a}, f x) = f a :=\next (take y, iff.intro\n  (assume H, H a !mem_singleton)\n  (assume H, \u03bb x xa, by rewrite [eq_of_mem_singleton xa]; apply H))\n\ntheorem bInter_union (s t : set X) (f : X \u2192 set Y) :\n  (\u22c2 x \u2208 s \u222a t, f x) = (\u22c2 x \u2208 s, f x) \u2229 (\u22c2 x \u2208 t, f x) :=\next (take y, iff.intro\n  (assume H, and.intro (\u03bb x xs, H x (or.inl xs)) (\u03bb x xt, H x (or.inr xt)))\n  (assume H, \u03bb x xst, or.elim (xst) (\u03bb xs, and.left H x xs) (\u03bb xt, and.right H x xt)))\n\ntheorem bInter_insert (a : X) (s : set X) (f : X \u2192 set Y) :\n  (\u22c2 x \u2208 insert a s, f x) = f a \u2229 (\u22c2 x \u2208 s, f x) :=\nby rewrite [insert_eq, bInter_union, bInter_singleton]\n\ntheorem bInter_pair (a b : X) (f : X \u2192 set Y) :\n  (\u22c2 x \u2208 '{a, b}, f x) = f a \u2229 f b :=\nby rewrite [*bInter_insert, bInter_empty, inter_univ]\n\ntheorem bUnion_empty (f : X \u2192 set Y) : (\u22c3 x \u2208 (\u2205 : set X), f x) = \u2205 :=\neq_empty_of_forall_not_mem (\u03bb y H, obtain x [xine yfx], from H,\n  !not_mem_empty xine)\n\ntheorem bUnion_singleton (a : X) (f : X \u2192 set Y) : (\u22c3 x \u2208 '{a}, f x) = f a :=\next (take y, iff.intro\n  (assume H, obtain x [xina yfx], from H,\n    show y \u2208 f a, by rewrite [-eq_of_mem_singleton xina]; exact yfx)\n  (assume H, exists.intro a (and.intro !mem_singleton H)))\n\ntheorem bUnion_union (s t : set X) (f : X \u2192 set Y) :\n  (\u22c3 x \u2208 s \u222a t, f x) = (\u22c3 x \u2208 s, f x) \u222a (\u22c3 x \u2208 t, f x) :=\next (take y, iff.intro\n  (assume H, obtain x [xst yfx], from H,\n    or.elim xst\n      (\u03bb xs, or.inl (exists.intro x (and.intro xs yfx)))\n      (\u03bb xt, or.inr (exists.intro x (and.intro xt yfx))))\n  (assume H, or.elim H\n    (assume H1, obtain x [xs yfx], from H1,\n      exists.intro x (and.intro (or.inl xs) yfx))\n    (assume H1, obtain x [xt yfx], from H1,\n      exists.intro x (and.intro (or.inr xt) yfx))))\n\ntheorem bUnion_insert (a : X) (s : set X) (f : X \u2192 set Y) :\n  (\u22c3 x \u2208 insert a s, f x) = f a \u222a (\u22c3 x \u2208 s, f x) :=\nby rewrite [insert_eq, bUnion_union, bUnion_singleton]\n\ntheorem bUnion_pair (a b : X) (f : X \u2192 set Y) :\n  (\u22c3 x \u2208 '{a, b}, f x) = f a \u222a f b :=\nby rewrite [*bUnion_insert, bUnion_empty, union_empty]\n\nend set\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/set/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.8824278633625322, "lm_q1q2_score": 0.7172967624759303}}
{"text": "/- Homework 1.2: Basics \u2014 Proofs -/\n\n/- Question 1: Drop and Take -/\n\ndef drop {\u03b1 : Type} : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0       xs        := xs\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := drop m xs\n\n#reduce drop 2 [2,4,6, 8]\n\n/- 1.1. Define `take`. -/\n\n/- To avoid bad surprises in the proofs, we recommend that you follow the same recursion pattern as\nfor `drop` above. -/\n\ndef take {\u03b1 : Type} : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0             xs      :=      []\n| (_ + 1)       []      :=      []\n| (m + 1)  (x::xs) :=      [x] ++ take m xs \n\n-- ZZZ: Jasmins simpler take, see last line\ndef take' {\u03b1 : Type} : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0        xs           := []\n| (_ + 1)  []           := []\n| (m + 1)  (x::xs)      := x :: take m xs \n\n#reduce take 0 [3, 7, 11]   -- expected: []\n#reduce take 1 [3, 7, 11]   -- expected: [3]\n#reduce take 2 [3, 7, 11]   -- expected: [3, 7]\n#reduce take 3 [3, 7, 11]   -- expected: [3, 7, 11]\n#reduce take 4 [3, 7, 11]   -- expected: [3, 7, 11]\n\n#reduce take 3[]\n-- when `#reduce` fails for some obscure reason, try `#eval`:\n#eval take 2 [\"a\", \"b\", \"c\"]   -- expected: [\"a\", \"b\"]\n\n/- 1.2. Prove the following lemmas. Notice that they are registered as simp rules thanks to the\n`@[simp]` attribute. -/\n@[simp] lemma drop_nil {\u03b1 : Type} : \u2200(n : \u2115), drop n ([] : list \u03b1) = [] :=\nbegin\nintros n,\ninduction n,\nsimp,\nrefl,\nsimp[drop]\nend\n\n\n@[simp] lemma drop_nil' {\u03b1 : Type} : \u2200(n : \u2115), drop n ([] : list \u03b1) = []\n| 0 := by refl \n| (_ + 1) := by refl\n\n@[simp] lemma take_nil {\u03b1 : Type} : \u2200(n : \u2115), take n ([] : list \u03b1) = []:=\nbegin\nintros n,\ninduction n,\nsimp,\nrefl,\nsimp[take]\nend\n\n/- 1.3. Follow the recursion pattern of `drop` and `take` to prove the following lemmas. In other\nwords, for each lemma, there should be three cases, and the third case will need to invoke the\ninduction hypothesis.\n\nThe first case is shown for `drop_drop`. Beware of the fact that there are three variables in the\n`drop_drop` lemma (but only two arguments to `drop`). Hint: The `refl` tactic might be useful in the\nthird case of `drop_drop`.\n-/\n\nlemma drop_drop {\u03b1 : Type} : \u2200(m n : \u2115) (xs : list \u03b1), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n| (_ + 1) n []        := by simp\n| (m + 1) n (x :: xs)       :=\nbegin\nrw[<-add_assoc n m 1],\nunfold drop,\nsimp[drop_drop m],\nend\n\n-- ZZZ: Jasmins solution\nlemma drop_drop' {\u03b1 : Type} : \u2200(m n : \u2115) (xs : list \u03b1), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n| (_ + 1) n []        := by simp\n| (m + 1) n (x :: xs)       :=\nbegin\nrw[<-add_assoc n m 1],\nunfold drop,\nsimp[drop, drop_drop' m]\nend\n\n\n\nlemma take_take {\u03b1 : Type} : \u2200(m : \u2115) (xs : list \u03b1), take m (take m xs) = take m xs\n| 0 xs                    := by refl\n| (m + 1) xs              := \nbegin\ninduction xs,\nrefl,\nsimp[take],\nend\n\nlemma take_drop {\u03b1 : Type} : \u2200(n : \u2115) (xs : list \u03b1), take n xs ++ drop n xs = xs\n| 0 xs := by simp[take, drop]\n| (_ + 1) xs :=\nbegin\ninduction xs,\nsimp[take_drop],\nunfold take,\nunfold drop,\nrw[<-xs_ih],\nsimp,\nrw[xs_ih],\nsimp[take_drop]\nend\n\n-- ZZZ: Jasmins nicer solutions\nlemma take_take' {\u03b1 : Type} : \u2200(m : \u2115) (xs : list \u03b1), take m (take m xs) = take m xs\n| 0       _         := by refl\n| (_ + 1) []        := by refl\n| (m + 1) (x :: xs) := by simp [take, take_take' m xs]\n\nlemma take_drop' {\u03b1 : Type} : \u2200(n : \u2115) (xs : list \u03b1), take n xs ++ drop n xs = xs\n| 0       _         := by refl\n| (_ + 1) []        := by refl\n| (m + 1) (x :: xs) := by simp [take, drop, take_drop' m]\n\n\n\n/- Question 2: Gauss's summation formula -/\n\n/-- `sum_upto f n = f 0 + f 1 + ... + f n` -/\ndef sum_upto (f : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115\n| 0       := f 0\n| (m + 1) := sum_upto m + f (m + 1)\n\n/- 2.1. Prove the following lemma, discovered by Carl Friedrich Gauss as a pupil.\n\nHints: The `ac_refl` tactic might be useful to reason about multiplication. The rules about `add`\nand `mul` in `12_exercise.lean` exist with the same names about '+' and '*' in Lean's libraries. -/\n\nlemma sum_upto_eq : \u2200m : \u2115, 2 * sum_upto id m = m * (m + 1) \n| 0 := by refl\n| (m + 1) :=\nbegin \nsimp[mul_add, mul_comm],\nrw[<-mul_comm m],\nsimp[sum_upto],\nsimp[mul_add],\nsimp[sum_upto_eq],\nsimp[mul_add],\nsimp[mul_comm]\nend\n\n-- ZZZ: consec simps can be combined into one\nlemma sum_upto_eq' : \u2200m : \u2115, 2 * sum_upto id m = m * (m + 1) \n| 0               := by refl\n| (m + 1)         := begin simp [sum_upto, mul_add, sum_upto_eq' m, add_mul], ac_refl end\n\n/- 2.2. Prove the following property of `sum_upto`. -/\n\nlemma sum_upto_mul (a : \u2115) (f : \u2115 \u2192 \u2115) : \u2200(n : \u2115), sum_upto (\u03bbi, a * f i) n = a * sum_upto f n \n| 0 := by refl\n| (m + 1) :=\nbegin\nsimp[sum_upto],\nsimp[sum_upto_mul],\nsimp[mul_add]\nend\n", "meta": {"author": "KjellZijlemaker", "repo": "Logical_Verification_VU", "sha": "4578b93bf1615466996157bb333c84122b201d99", "save_path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU", "path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU/Logical_Verification_VU-4578b93bf1615466996157bb333c84122b201d99/Exercises week 2/12_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7172865191240017}}
{"text": "/- This is a short tutorial on lean for the Logic in Computer Science course at the university\nof Ljubljana. -/\n\nnamespace logika_v_racunalnistvu \n\n/- We typically want to be universe polymorphic in lean, so we introduce a universe variable u. -/\n\nuniverses u v w \n\n/- Definitions of inductive types are made using the inductive keyword. Different constructors\n   are separated by |. -/\n\ninductive list (A : Type u) : Type u\n| nil : list\n| cons : A \u2192 list \u2192 list\n\n/- We open the namespace list, so that we can use nil and cons directly. -/\n\nnamespace list\n\n/- We will now define some basic operations on lists. -/\n\n/- Direct definitions are made using the definition keyword, followed by := -/\n\ndefinition unit {A : Type u} (a : A) : list A :=\ncons a nil\n\n/- A shorthand for definition is def, which may also be used. -/\n\n/- Since the type of lists is an inductive type, we can make inductive definitions on list\nusing pattern matching. The syntax is analogous to the syntax of the inductive type itself. \nNote that in pattern matching definitions, we don't use := at the end of the specification. -/\n\ndef fold {A : Type u} {B : Type v} (b : B) (\u03bc : A \u2192 B \u2192 B) : list A \u2192 B\n| nil := b\n| (cons a l) := \u03bc a (fold l)\n\ndef functor_list {A : Type u} {B : Type v} (f : A \u2192 B) : list A \u2192 list B \n| nil := nil\n| (cons a x) := cons (f a) (functor_list x)\n\ndef length {A : Type u} : list A \u2192 \u2115 :=\nfold 0 (\u03bb _ n, n + 1)\n\ndef sum_list_\u2115 : list \u2115 \u2192 \u2115 :=\nfold 0 (\u03bb m n, m + n)\n\ndef concat {A : Type u} : list A \u2192 list A \u2192 list A :=\nfold id (\u03bb a f l, cons a (f l))\n\ndef flatten {A : Type u} : list (list A) \u2192 list A :=\nfold nil concat \n\ndef reverse {A : Type u} : list A \u2192 list A\n| nil := nil\n| (cons a l) := concat (reverse l) (unit a)\n\n/- We have now finished defining our basic operations on lists. Let us check by some examples \n   that the operations indeed do what they are supposed to do. With your mouse, hover over the\n   #reduce keyword to see what each term reduces to. -/\n\n#reduce concat (cons 1 (cons 2 (cons 3 nil))) (cons 4 (cons 5 nil))\n\n#reduce sum_list_\u2115 (concat (cons 1 (cons 2 (cons 3 nil))) (cons 4 (cons 5 nil)))\n\n#reduce reverse (concat (cons 1 (cons 2 (cons 3 nil))) (cons 4 (cons 5 nil)))\n\n/- Of course, if you really want to know that your operations behave as expected, you should \n   prove the relevant properties about them. This is what we will do next. -/\n\n/- When proving theorems, we can also proceed by pattern matching. In a pattern matching argument\n   we can recursively call the object we are defining on earlier instances.\n   \n   The arguments that we want to pattern-match on, must appear after the colon (:) in the \n   specification of the theorem. -/\n\ntheorem identity_law_functor_list {A : Type u} :\n    \u2200 (x : list A), functor_list id x = x \n| nil := rfl\n| (cons a x) := \n    calc\n    functor_list id (cons a x) \n        = cons a (functor_list id x) : rfl\n    ... = cons a x : by rw identity_law_functor_list\n\ntheorem composition_law_functor_list {A : Type u} {B : Type v} {C : Type w} (f : A \u2192 B) (g : B \u2192 C) :\n    \u2200 (x : list A), functor_list (g \u2218 f) x = functor_list g (functor_list f x)\n| nil := rfl\n| (cons a x) := \n    calc\n    functor_list (g \u2218 f) (cons a x)\n        = cons (g (f a)) (functor_list (g \u2218 f) x) : rfl \n    ... = cons (g (f a)) (functor_list g (functor_list f x)) : by rw composition_law_functor_list\n    ... = functor_list g (functor_list f (cons a x)) : rfl   \n\n/- Next, we prove some properties concatenation. Concatenation of lists is an associative\n   operation, and it satisfies the left and right unit laws.universe\n   \n   In order to prove associativity, we note that since concatenation is defined by induction\n   on the left argument, we will again use induction on the left argument to prove this \n   propoerty. The proof is presented by pattern matching.\n   \n   In the proof we will use the built-in equation compiler. We just calculate as if we were\n   working on a sheet of paper, and each time we mention the reason why the equality holds. -/\n\ntheorem assoc_concat {A : Type u} : \n    \u2200 (x y z : list A), concat (concat x y) z = concat x (concat y z)\n| nil _ _ := rfl\n| (cons a l) y z :=\n    calc\n    concat (concat (cons a l) y) z \n        = cons a (concat (concat l y) z) : by reflexivity\n    ... = cons a (concat l (concat y z)) : by rw assoc_concat\n    ... = concat (cons a l) (concat y z) : by reflexivity\n\ntheorem left_unit_law_concat {A : Type u} : \n    \u2200 (x : list A), concat nil x = x := \n    eq.refl \n\ntheorem right_unit_law_concat {A : Type u} : \n    \u2200 (x : list A), concat x nil = x \n| nil := rfl\n| (cons a x) := \n    show cons a (concat x nil) = cons a x, \n    by rw right_unit_law_concat \n\n/- Next, we prove the elementary properties of the length function. -/\n\ntheorem length_nil {A : Type u} :\n    length (@nil A) = 0 := rfl\n\ntheorem length_unit {A : Type u} (a : A) :\n    length (unit a) = 1 :=\n    rfl\n\ntheorem length_concat {A : Type u} :\n    \u2200 (x y : list A), length (concat x y) = length x + length y\n| nil y := \n    calc\n    length (concat nil y) \n        = length y : rfl\n    ... = 0 + length y : by rw zero_add\n    ... = length nil + length y : by rw length_nil\n| (cons a x) y :=\n    calc\n    length (concat (cons a x) y)\n        = length (concat x y) + 1 : rfl\n    ... = (length x + length y) + 1 : by rw length_concat\n    ... = (length x + 1) + length y : by rw nat.succ_add\n    ... = (length (cons a x)) + length y : rfl\n\n/- Next, we prove the elemenatary properties of the flatten function. -/\n\ntheorem flatten_unit {A : Type u} :\n    \u2200 (x : list A), flatten (unit x) = x := \n    right_unit_law_concat\n\ntheorem length_flatten {A : Type u} :\n    \u2200 (x : list (list A)), length (flatten x) = sum_list_\u2115 (functor_list length x)\n| nil := rfl\n| (cons a x) := \n    calc\n    length (flatten (cons a x)) \n        = length (concat a (flatten x)) : rfl\n    ... = length a + length (flatten x) : by rw length_concat \n    ... = length a + sum_list_\u2115 (functor_list length x) : by rw length_flatten \n    ... = sum_list_\u2115 (functor_list length (cons a x)) : rfl \n\ntheorem flatten_concat {A : Type u} :\n    \u2200 (x y : list (list A)), flatten (concat x y) = concat (flatten x) (flatten y)\n| nil y := rfl\n| (cons a x) y := \n    calc\n    flatten (concat (cons a x) y) \n        = concat a (flatten (concat x y)) : rfl\n    ... = concat a (concat (flatten x) (flatten y)) : by rw flatten_concat\n    ... = concat (concat a (flatten x)) (flatten y) : by rw assoc_concat\n    ... = concat (flatten (cons a x)) (flatten y) : rfl \n\ntheorem flatten_flatten {A : Type u} :\n    \u2200 (x : list (list (list A))), flatten (flatten x) = flatten (functor_list flatten x)\n| nil := rfl\n| (cons a x) := \n    calc\n    flatten (flatten (cons a x))\n        = flatten (concat a (flatten x)) : rfl\n    ... = concat (flatten a) (flatten (flatten x)) : by rw flatten_concat\n    ... = concat (flatten a) (flatten (functor_list flatten x)) : by rw flatten_flatten \n    ... = flatten (functor_list flatten (cons a x)) : rfl \n\n/- Next, we prove the elementary properties of list reversal. -/\n\ntheorem unit_reverse {A : Type u} (a : A) :\n    reverse (unit a) = unit a := rfl \n\ntheorem length_reverse {A : Type u} : \n    \u2200 (x : list A), length (reverse x) = length x\n| nil := rfl\n| (cons a x) := \n    calc\n    length (reverse (cons a x)) \n        = length (concat (reverse x) (unit a)) : rfl\n    ... = length (reverse x) + length (unit a) : by rw length_concat\n    ... = length (reverse x) + 1 : by rw length_unit\n    ... = length x + 1 : by rw length_reverse\n    ... = length (cons a x) : rfl \n\ntheorem reverse_concat {A : Type u} : \n    \u2200 (x y : list A), reverse (concat x y) = concat (reverse y) (reverse x)\n| nil y := \n    calc \n    reverse (concat nil y) = reverse y : by reflexivity\n    ... = concat (reverse y) nil : by rw right_unit_law_concat\n| (cons a x) y :=\n    calc \n    reverse (concat (cons a x) y)\n        = concat (reverse (concat x y)) (unit a) : rfl\n    ... = concat (concat (reverse y) (reverse x)) (unit a) : by rw reverse_concat\n    ... = concat (reverse y) (concat (reverse x) (unit a)) : by rw assoc_concat\n    ... = concat (reverse y) (reverse (cons a x)) : rfl\n\ntheorem reverse_flatten {A : Type u} :\n    \u2200 (x : list (list A)), reverse (flatten x) = flatten (reverse (functor_list reverse x))\n| nil := rfl\n| (cons a x) := \n    calc\n    reverse (flatten (cons a x))\n        = reverse (concat a (flatten x)) : rfl\n    ... = concat (reverse (flatten x)) (reverse a) : by rw reverse_concat\n    ... = concat (flatten (reverse (functor_list reverse x))) (reverse a) : by rw reverse_flatten\n    ... = concat (flatten (reverse (functor_list reverse x))) (flatten (unit (reverse a))) : by rw flatten_unit \n    ... = flatten (concat (reverse (functor_list reverse x)) (unit (reverse a))) : by rw flatten_concat\n    ... = flatten (reverse (cons (reverse a) (functor_list reverse x))) : rfl \n    ... = flatten (reverse (functor_list reverse (cons a x))) : rfl\n\ntheorem reverse_reverse {A : Type u} : \n    \u2200 (x : list A), reverse (reverse x) = x \n| nil := rfl\n| (cons a x) := \n    calc\n    reverse (reverse (cons a x)) \n        = reverse (concat (reverse x) (unit a)) : rfl\n    ... = concat (reverse (unit a)) (reverse (reverse x)) : by rw reverse_concat \n    ... = concat (unit a) (reverse (reverse x)) : by rw unit_reverse\n    ... = concat (unit a) x : by rw reverse_reverse\n    ... = cons a x : rfl \n\n/- The next topic of our study of lists is Heads and Tails -/\n\ndef head {A : Type u} : list A \u2192 list A\n| nil := nil  \n| (cons a x) := unit a\n\n/- Note that the type of head can't be list A \u2192 A, because we might apply head to the empty list\n   In that case, we should allow for an exception. Instead of mapping to the coproduct A + 1, we \n   make give head the type list A \u2192 list A. -/\n\ndef tail {A : Type u} : list A \u2192 list A \n| nil := nil \n| (cons a x) := x \n\n/- If we concatenate the head with the tail, we get the original list back -/\n\ndef concat_head_tail {A : Type u} : \n    \u2200 (x : list A), concat (head x) (tail x) = x \n| nil := rfl \n| (cons a x) := rfl \n\ntheorem head_head {A : Type u} : \n    \u2200 (x : list A), head (head x) = head x\n| nil := rfl \n| (cons a x) := rfl \n\ntheorem head_concat {A : Type u} : \n    \u2200 (x y : list A), head (concat x y) = head (concat (head x) (head y)) \n| nil y := \n    calc \n    head (concat nil y) \n        = head y : rfl \n    ... = head (head y) : by rw head_head  \n    ... = head (concat (head nil) (head y)) : rfl \n| (cons a x) y := rfl \n\ntheorem tail_concat {A : Type u} :\n    \u2200 (x y : list A), tail (concat x y) = concat (tail x) (tail (concat (head x) y))\n| nil y := rfl \n| (cons a x) y := \n    calc \n    tail (concat (cons a x) y)\n        = tail (cons a (concat x y)) : rfl\n    ... = tail (cons a (concat (tail (cons a x)) y)) : rfl \n    ... = concat (tail (cons a x)) y : rfl \n    ... = concat (tail (cons a x)) (tail (concat (head (cons a x)) y)) : rfl \n\n/- Dual to taking the head of a list, we may take the last element of a list. -/\n\ndef last {A : Type u} : list A \u2192 list A\n| nil := nil  \n| (cons a nil) := unit a \n| (cons a (cons a' x')) := last (cons a' x')\n\n/- The last element is of course the head of the reversed list. -/\n\ntheorem head_reverse {A : Type u} : \n    \u2200 (x : list A), head (reverse x) = last x \n| nil := rfl \n| (cons a nil) := rfl\n| (cons a (cons a' x')) := \n    calc\n    head (reverse (cons a (cons a' x'))) \n        = head (concat (reverse (cons a' x')) (unit a)) : rfl\n    ... = head (concat (concat (reverse x') (unit a')) (unit a)) : rfl\n    ... = head (concat (reverse x') (concat (unit a') (unit a))) : by rw assoc_concat \n    ... = head (concat (head (reverse x')) (head (concat (unit a') (unit a)))) : by rw head_concat\n    ... = head (concat (head (reverse x')) (head (unit a'))) : rfl \n    ... = head (concat (reverse x') (unit a')) : by {symmetry, rw head_concat}\n    ... = head (reverse (cons a' x')) : rfl\n    ... = last (cons a' x') : by rw head_reverse\n    ... = last (cons a (cons a' x')) : rfl\n\n/- Dual to taking the tail of a list, we may remove the last element of the list. -/\n\ndef remove_last {A : Type u} : list A \u2192 list A\n| nil := nil\n| (cons a nil) := nil \n| (cons a (cons a' x')) := cons a (remove_last (cons a' x')) \n\n/- Removing the last element of the list is of course taking the reverse of the tail of the \n   reverse. -/\n\ntheorem tail_concat' {A : Type u} :\n    \u2200 (x  y : list A), \n    tail (concat x y) = concat (tail x) (tail (concat (last x) y))\n| nil y := rfl\n| (cons a nil) y := rfl \n| (cons a (cons a' x')) y :=\n    calc\n    tail (concat (cons a (cons a' x')) y) \n        = concat (cons a' x') y : rfl\n    ... = cons a' (tail (concat (cons a' x') y)) : rfl\n    ... = cons a' (concat (tail (cons a' x')) (tail (concat (last (cons a' x')) y))) : by rw tail_concat' \n    ... = concat (cons a' x') (tail (concat (last (cons a' x')) y)) : rfl \n    ... = concat (tail (cons a (cons a' x'))) (tail (concat (last (cons a (cons a' x'))) y)) : rfl\n\ndef cons' {A : Type u} (x : list A) (a : A) : list A :=\nconcat x (unit a)\n\ntheorem last_cons' {A : Type u} : \n    \u2200 (x : list A) (a : A), last (cons' x a) = unit a\n| nil a := rfl\n| (cons a' nil) a := rfl\n| (cons a' (cons a'' x'')) a :=\n    calc\n    last (cons' (cons a' (cons a'' x'')) a) \n        = last (cons a' (cons a'' (concat x'' (unit a)))) : rfl\n    ... = last (cons a'' (concat x'' (unit a))) : rfl \n    ... = last (cons' (cons a'' x'') a) : rfl \n    ... = unit a : by rw last_cons'  \n\ntheorem tail_reverse {A : Type u} : \n    \u2200 (x : list A), tail (reverse x) = reverse (remove_last x)\n| nil := rfl\n| (cons a nil) := rfl \n| (cons a (cons a' x')) :=\n    calc\n    tail (reverse (cons a (cons a' x')))\n        = tail (concat (reverse (cons a' x')) (unit a)) : rfl \n    ... = concat \n            ( tail (reverse (cons a' x'))) \n            ( tail (concat (last (reverse (cons a' x'))) (unit a))) : by rw tail_concat' \n    ... = concat \n            ( tail (reverse (cons a' x')))\n            ( tail (concat (last (concat (reverse x') (unit a'))) (unit a))) : rfl\n    ... = concat \n            ( tail (reverse (cons a' x')))\n            ( tail (concat (last (cons' (reverse x') a')) (unit a))) : rfl\n    ... = concat\n            ( tail (reverse (cons a' x')))\n            ( tail (concat (unit a') (unit a))) : by rw last_cons' \n    ... = concat (tail (reverse (cons a' x'))) (unit a) : rfl\n    ... = concat (reverse (remove_last (cons a' x'))) (unit a) : by rw tail_reverse\n    ... = reverse (cons a (remove_last (cons a' x'))) : rfl\n    ... = reverse (remove_last (cons a (cons a' x'))) : rfl\n\ntheorem remove_last_reverse {A : Type u} (x : list A):\n    remove_last (reverse x) = reverse (tail x) := \ncalc\nremove_last (reverse x)\n    = reverse (reverse (remove_last (reverse x))) : by rw reverse_reverse\n... = reverse (tail (reverse (reverse x))) : by rw tail_reverse\n... = reverse (tail x) : by {symmetry, rw reverse_reverse}\n\nend list \n\n/- Next, we study lists of a fixed length. -/\n\ninductive list_of_length (A : Type u) : \u2115 \u2192 Type u \n| nil : list_of_length 0\n| cons : \u2200 (n : \u2115), A \u2192 list_of_length n \u2192 list_of_length (n+1)\n\nnamespace list_of_length\n\ntheorem eq_nil {A : Type u} : \u2200 (x : list_of_length A 0), x = nil \n| nil := rfl \n\ndef functor {A : Type u} {B : Type v} (f : A \u2192 B) :\n    \u2200 (n : \u2115), list_of_length A n \u2192 list_of_length B n \n| 0 nil := nil\n| (n+1) (cons n' a x) := cons n' (f a) (functor n' x)\n\ndef head {A : Type u} :\n    \u2200 (n : \u2115), list_of_length A (n+1) \u2192 A \n| n (cons n' a x) := a \n\ndef tail {A : Type u} : \n    \u2200 (n : \u2115), list_of_length A (n+1) \u2192 list_of_length A n \n| n (cons n' a x) := x \n\n/- Using lists of fixed length, we can define matrices. The type\n   Matrix m n A is the type of matrices with m rows and n columns\n   and with coefficients in A. -/\n\ndef Matrix (m n : \u2115) (A : Type u) : Type u :=\nlist_of_length (list_of_length A n) m\n\ndef top_row {A : Type u} {m n : \u2115} : \n    Matrix (m+1) n A \u2192 list_of_length A n := \nhead m \n\ndef tail_vertical {A : Type u} {m n : \u2115} : \n    Matrix (m+1) n A \u2192 Matrix m n A :=\ntail m \n\ndef left_column {A : Type u} {m n : \u2115} :\n    Matrix m (n+1) A \u2192 list_of_length A m := \nfunctor (head n) m\n\ndef tail_horizontal {A : Type u} {m n : \u2115} : \n    Matrix m (n+1) A \u2192 Matrix m n A :=\nfunctor (tail n) m\n\n/- Since matrices are rectangular, we have a horizontal as well as vertical empty matrices. -/\n\ndef nil_vertical {A : Type u} {n : \u2115} : Matrix 0 n A := nil\n\ntheorem eq_nil_vertical {A : Type u} : \n    \u2200 {n : \u2115} (x : Matrix 0 n A), x = nil_vertical\n| 0 nil := rfl \n| (n+1) nil := rfl  \n\ndef nil_horizontal {A : Type u} : \u2200 {m : \u2115}, Matrix m 0 A \n| 0 := nil \n| (m+1) := cons m nil nil_horizontal\n\ntheorem eq_nil_horizontal {A : Type u} : \n    \u2200 {m : \u2115} (x : Matrix m 0 A), x = nil_horizontal\n| 0 nil := rfl \n| (m+1) (cons m' nil M) := \n    calc\n    cons m nil M \n        = cons m nil nil_horizontal : by rw eq_nil_horizontal M  \n    ... = nil_horizontal : rfl\n\n/- Similarly, there is a horizontal cons and a vertical cons. -/\n\n/- cons_vertical adds a new row from the top. -/\n\ndef cons_vertical {A : Type u} {m n : \u2115} :\n    list_of_length A n \u2192 Matrix m n A \u2192 Matrix (m+1) n A :=\n    cons m\n\ntheorem top_row_cons_vertical \n    {A : Type u} {m n : \u2115} (x : list_of_length A n) (M : Matrix m n A) :\n    top_row (cons_vertical x M) = x := \nrfl \n\ntheorem left_colum_cons_vertical {A : Type u} :\n    \u2200 {m n : \u2115} (x : list_of_length A (n+1)) (M : Matrix m (n+1) A),\n    left_column (cons_vertical x M) = cons m (head n x) (left_column M)\n| m n (cons n' a x) M := rfl \n\ntheorem eta_vertical {A : Type u} :\n    \u2200 {m n : \u2115} (M : Matrix (m+1) n A), \n    cons_vertical (top_row M) (tail_vertical M) = M\n| m n (cons _ x M) := rfl \n\n/- cons_horizontal adds a new column from the left. -/\n\ndef cons_horizontal {A : Type u} :\n    \u2200 {m n : \u2115}, list_of_length A m \u2192 Matrix m n A \u2192 Matrix m (n+1) A \n| 0 n nil M := nil\n| (m+1) n (cons m' a x) M := \n    cons m (cons n a (top_row M)) (cons_horizontal x (tail_vertical M))\n\ntheorem left_column_cons_horizontal {A : Type u} :\n    \u2200 {m n : \u2115} (x : list_of_length A m) (M : Matrix m n A),\n    left_column (cons_horizontal x M) = x \n| 0 n nil M := rfl \n| (m+1) n (cons m' a x) M := \n    calc\n    left_column (cons_horizontal (cons m' a x) M)\n        = cons m a (left_column (cons_horizontal x (tail_vertical M))) : rfl  \n    ... = cons m a x : by rw left_column_cons_horizontal \n\ntheorem top_row_cons_horizontal {A : Type u} :\n    \u2200 {m n : \u2115} (x : list_of_length A (m+1)) (M : Matrix (m+1) n A),\n    top_row (cons_horizontal x M) = cons n (head m x) (top_row M)\n| m n (cons m' a x) (cons m'' y M) := rfl \n\ntheorem tail_vertical_cons_horizontal {A : Type} :\n    \u2200 {m n : \u2115} (x : list_of_length A (m+1)) (M : Matrix (m+1) n A),\n    tail_vertical (cons_horizontal x M) = cons_horizontal (tail m x) (tail_vertical M)\n| m n (cons m' a x) (cons m'' y M) := rfl \n\ntheorem eta_horizontal {A : Type u} :\n    \u2200 {m n : \u2115} (M : Matrix m (n+1) A),\n    cons_horizontal (left_column M) (tail_horizontal M) = M \n| 0 n nil := rfl\n| (m+1) n (cons m' (cons n' a x) M) :=\n    calc\n    cons_horizontal (left_column (cons m (cons n a x) M)) (tail_horizontal (cons m (cons n a x) M))\n        = cons m (cons n a x) (cons_horizontal (left_column M) (tail_horizontal M)) : rfl\n    ... = cons m (cons n a x) M : by rw eta_horizontal M\n\n/- Next we show that if we add a row from the top as well as a column from the left, then it \n   doesn't matter in which order we do that. -/\n\ntheorem cons_horizontal_cons_vertical {A : Type u} :\n    \u2200 {m n : \u2115} (a : A) (x : list_of_length A n) (y : list_of_length A m) (M : Matrix m n A),\n    cons_horizontal (cons m a y) (cons_vertical x M) \n        = cons_vertical (cons n a x) (cons_horizontal y M) \n| m n a x y M := rfl \n\n/- We define the transposition of a matrix. -/\n\ndef transpose {A : Type u} : \n    \u2200 {m n : \u2115}, Matrix m n A \u2192 Matrix n m A\n| 0 n M := nil_horizontal\n| (m+1) n (cons m' x M) := cons_horizontal x (transpose M)\n\n/- The following three theorems show how transpose interacts with the basic operations on\n   matrices. These will help to show that transposition is an involution. -/\n\ntheorem transpose_nil {A : Type u} :\n    \u2200 {n : \u2115}, @transpose A 0 n nil = nil_horizontal \n| 0 := rfl \n| (n+1) := rfl \n\ntheorem transpose_cons_horizontal {A : Type u} :\n    \u2200 {m n : \u2115} (x : list_of_length A m) (M : Matrix m n A),\n    transpose (cons_horizontal x M) = cons_vertical x (transpose M)\n| 0 n nil M := rfl \n| (m+1) n (cons m' a x) (cons m'' y M) := \n    calc\n    transpose (cons_horizontal (cons m' a x) (cons m'' y M))\n        = transpose (cons m (cons n a y) (cons_horizontal x M)) : rfl \n    ... = cons_horizontal (cons n a y) (transpose (cons_horizontal x M)) : rfl \n    ... = cons_horizontal (cons n a y) (cons_vertical x (transpose M)) : by rw transpose_cons_horizontal\n    ... = cons_vertical (cons m a x) (transpose (cons m y M)) : by reflexivity\n\ntheorem transpose_cons_vertical {A : Type u} :\n    \u2200 {m n : \u2115} (x : list_of_length A n) (M : Matrix m n A),\n    transpose (cons_vertical x M) = cons_horizontal x (transpose M)\n| m n x M := rfl \n\n/- We finally show that transposition is an involution. -/\n\ntheorem transpose_transpose {A : Type u} :\n    \u2200 (m n : \u2115) (M : Matrix m n A), transpose (transpose M) = M\n| 0 0 nil := rfl\n| 0 (n+1) nil := rfl \n| (m+1) 0 M := \n    calc\n    transpose (transpose M) \n        = transpose nil : rfl \n    ... = nil_horizontal : by rw transpose_nil\n    ... = M : by rw eq_nil_horizontal M\n| (m+1) (n+1) (cons _ x M) := \n    calc\n    transpose (transpose (cons _ x M))\n        = transpose (transpose (cons_vertical x M)) : rfl \n    ... = transpose (cons_horizontal x (transpose M)) : by rw transpose_cons_vertical\n    ... = cons_vertical x (transpose (transpose M)) : by rw transpose_cons_horizontal\n    ... = cons_vertical x M : by rw transpose_transpose\n    ... = cons _ x M : rfl\n\nend list_of_length\n\nend logika_v_racunalnistvu", "meta": {"author": "EgbertRijke", "repo": "lists-in-lean", "sha": "848015bada1470a3b5c13be0680169d75f79cbcf", "save_path": "github-repos/lean/EgbertRijke-lists-in-lean", "path": "github-repos/lean/EgbertRijke-lists-in-lean/lists-in-lean-848015bada1470a3b5c13be0680169d75f79cbcf/lists2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764118, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7172865072495875}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 1 : \"implies\" (`\u2192`)\n\nWe learn about propositions, and implications `P \u2192 Q` between them. You can get\nthis arrow by typing `\\to` or `\\r`. Mathematicians usually write the\nimplication arrow as `P \u21d2 Q` but Lean prefers a single arrow.\n\n## The absolute basics\n\n`P : Prop` means that `P` is a true-false statement. `h : P` means\nthat `h` is a proof that `P` is true, or you can regard `h` as an\nassumption that `P` is true; logically these are the same. Stuff above\nthe `\u22a2` symbol is your assumptions. The statement to the right of it is\nthe goal. Your job is to prove the goal from the assumptions.\n\n## Tactics you will need\n\nTo solve the levels on this sheet you will need to know how to use the\nfollowing tactics:\n\n* `intro`\n* `exact`\n* `apply`\n\nYou can read the descriptions of these tactics in Part C of the course\nnotes.\n\n## Worked examples\n\nClick around in the proofs to see the tactic state (on the right) change.\nThe tactic is implemented and the state changes just before the comma.\nI will use the following conventions: variables with capital\nletters like `P`, `Q`, `R` denote propositions\n(i.e. true/false statements) and variables whose names begin\nwith `h` like `h1` or `hP` are proofs or hypotheses.\n\n-/ \n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\nvariables (P Q R : Prop)\n\n-- Here are some examples of `intro`, `exact` and `apply` being used.\n\n-- Assume that `P` and `Q` and `R` are all true. Deduce that `P` is true.\nexample (hP : P) (hQ : Q) (hR : R) : P :=\nbegin\n  -- note that `exact P` does *not* work. `P` is the proposition, `hP` is the proof.\n  exact hP\nend\n\n-- Assume `Q` is true. Prove that `P \u2192 Q`. \nexample (hQ : Q) : P \u2192 Q :=\nbegin\n  -- The goal is of the form `X \u2192 Y` so we can use `intro`\n  intro h,\n  -- now `h` is the hypothesis that `P` is true.\n  -- Our goal is now the same as a hypothesis so we can use `exact`\n  exact hQ,\n  -- note `exact Q` doesn't work: `exact` takes the *term*, not the type.\nend\n\n-- Assume `P \u2192 Q` and `P` is true. Deduce `Q`.\nexample (h : P \u2192 Q) (hP : P) : Q :=\nbegin\n  -- our goal is `\u22a2 Q` which matches with the conclusion of `h` so `apply` works\n  apply h,\n  -- now our goal has changed to `P` which is an assumption\n  exact hP,\nend\n\n/-\n\n## Examples for you to try\n\nDelete the `sorry`s and replace them with comma-separated tactic proofs\nusing `intro`, `exact` and `apply`.\n\n-/\n\n/-- Every proposition implies itself. -/\nexample : P \u2192 P :=\nbegin\n  intro h,\n  exact h,\nend\n\n/-\n\nNote that `\u2192` is not associative: in general `P \u2192 (Q \u2192 R)` and `(P \u2192 Q) \u2192 R`\nmight not be equivalent. This is like subtraction on numbers -- in general\n`a - (b - c)` and `(a - b) - c` might not be equal.\n\nSo if we write `P \u2192 Q \u2192 R` then we'd better know what this means.\nThe convention in Lean is that it means `P \u2192 (Q \u2192 R)`. If you think\nabout it, this means that to deduce `R` you will need to prove both `P`\nand `Q`. In general to prove `P1 \u2192 P2 \u2192 P3 \u2192 ... Pn` you can assume\n`P1`, `P2`,...,`P(n-1)` and then you have to prove `Pn`. \n\nSo the next level is asking you prove that `P \u2192 (Q \u2192 P)`.\n\n-/\nexample : P \u2192 Q \u2192 P :=\nbegin\n  intro h,\n  intro q,\n  exact h,\nend\n\n/-- If we know `P`, and we also know `P \u2192 Q`, we can deduce `Q`. \nThis is called \"Modus Ponens\" by logicians. -/\nexample : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  intro fish,\n  intro bow,\n  apply bow,\n  exact fish,\nend\n\n/-- `\u2192` is transitive. That is, if `P \u2192 Q` and `Q \u2192 R` are true, then\n  so is `P \u2192 R`. -/\nexample : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  intro q,\n  intro w,\n  intro e,\n  apply w,\n  apply q,\n  exact e,\nend\n\n-- If `h : P \u2192 Q \u2192 R` with goal `\u22a2 R` and you `apply h`, you'll get\n-- two goals! Note that tactics operate on only the first goal.\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  intro q,\n  intro w,\n  intro e,\n  apply q,\n  exact e,\n  apply w,\n  exact e,\nend\n\n/- \n\nHere are some harder puzzles. If you're not into logic puzzles\nand you feel like you understand `intro`, `exact` and `apply`\nthen you can just skip these and move onto the next sheet\nin this section, where you'll learn some more tactics.\n\n-/\n\nvariables (S T : Prop)\n\nexample : (P \u2192 R) \u2192 (S \u2192 Q) \u2192 (R \u2192 T) \u2192 (Q \u2192 R) \u2192 S \u2192 T :=\nbegin\n  intros hPR hSQ hRT hQR hS,\n  apply hRT, apply hQR, apply hSQ,\n  exact hS, \nend\n\nexample : (P \u2192 Q) \u2192 ((P \u2192 Q) \u2192 P) \u2192 Q :=\nbegin\n  intros hPQ hPQP,\n  apply hPQ, apply hPQP, exact hPQ,\nend\n\nexample : ((P \u2192 Q) \u2192 R) \u2192 ((Q \u2192 R) \u2192 P) \u2192 ((R \u2192 P) \u2192 Q) \u2192 P :=\nbegin\n  intros pqr qrp rpq,\n  apply qrp,\n  intro q,\n  apply pqr,\n  intro p,\n  exact q,\nend\n\nexample : ((Q \u2192 P) \u2192 P) \u2192 (Q \u2192 R) \u2192 (R \u2192 P) \u2192 P :=\nbegin\n  intros qpp qr rp,\n  apply qpp,\n  intro q,\n  apply rp,apply qr,\n  exact q,\nend\n\nexample : (((P \u2192 Q) \u2192 Q) \u2192 Q) \u2192 (P \u2192 Q) :=\nbegin\n  intros pq p,apply pq,intro pq,apply pq, exact p,\nend\n\nexample :\n  (((P \u2192 Q \u2192 Q) \u2192 ((P \u2192 Q) \u2192 Q)) \u2192 R) \u2192\n  ((((P \u2192 P) \u2192 Q) \u2192 (P \u2192 P \u2192 Q)) \u2192 R) \u2192\n  (((P \u2192 P \u2192 Q) \u2192 ((P \u2192 P) \u2192 Q)) \u2192 R) \u2192 R :=\nbegin\n  intros q w e,\n  apply w,intros ppq p p1,\n  apply ppq,intro f,exact p,\nend\n", "meta": {"author": "yakimk", "repo": "lean2022", "sha": "145d03ca2f5a8d2508de05fe78597299051fb8e9", "save_path": "github-repos/lean/yakimk-lean2022", "path": "github-repos/lean/yakimk-lean2022/lean2022-145d03ca2f5a8d2508de05fe78597299051fb8e9/src/section01logic/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503681, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.717286500705427}}
{"text": "/-\nCopyright (c) 2022 Pim Otte. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller, Pim Otte\n-/\n\nimport algebra.big_operators.fin\nimport data.nat.choose.sum\nimport data.nat.factorial.big_operators\nimport data.fin.vec_notation\nimport data.finset.sym\nimport data.finsupp.multiset\n\n\n/-!\n# Multinomial\n\nThis file defines the multinomial coefficient and several small lemma's for manipulating it.\n\n## Main declarations\n\n- `nat.multinomial`: the multinomial coefficient\n\n## Main results\n\n- `finest.sum_pow`: The expansion of `(s.sum x) ^ n` using multinomial coefficients\n\n-/\n\nopen_locale big_operators nat\nopen_locale big_operators\n\nnamespace nat\n\nvariables {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u2115) {a b : \u03b1} (n : \u2115)\n\n/-- The multinomial coefficient. Gives the number of strings consisting of symbols\nfrom `s`, where `c \u2208 s` appears with multiplicity `f c`.\n\nDefined as `(\u2211 i in s, f i)! / \u220f i in s, (f i)!`.\n-/\ndef multinomial : \u2115 := (\u2211 i in s, f i)! / \u220f i in s, (f i)!\n\nlemma multinomial_pos : 0 < multinomial s f := nat.div_pos\n  (le_of_dvd (factorial_pos _) (prod_factorial_dvd_factorial_sum s f)) (prod_factorial_pos s f)\n\nlemma multinomial_spec : (\u220f i in s, (f i)!) * multinomial s f = (\u2211 i in s, f i)! :=\nnat.mul_div_cancel' (prod_factorial_dvd_factorial_sum s f)\n\n@[simp] lemma multinomial_nil : multinomial \u2205 f = 1 := rfl\n\n@[simp] lemma multinomial_singleton : multinomial {a} f = 1 :=\nby simp [multinomial, nat.div_self (factorial_pos (f a))]\n\n@[simp] lemma multinomial_insert_one [decidable_eq \u03b1] (h : a \u2209 s) (h\u2081 : f a = 1) :\n  multinomial (insert a s) f = (s.sum f).succ * multinomial s f :=\nbegin\n  simp only [multinomial, one_mul, factorial],\n  rw [finset.sum_insert h, finset.prod_insert h, h\u2081, add_comm, \u2190succ_eq_add_one, factorial_succ],\n  simp only [factorial_one, one_mul, function.comp_app, factorial],\n  rw nat.mul_div_assoc _ (prod_factorial_dvd_factorial_sum _ _),\nend\n\nlemma multinomial_insert [decidable_eq \u03b1] (h : a \u2209 s) :\n  multinomial (insert a s) f = (f a + s.sum f).choose (f a) * multinomial s f :=\nbegin\n  rw choose_eq_factorial_div_factorial (le.intro rfl),\n  simp only [multinomial, nat.add_sub_cancel_left, finset.sum_insert h, finset.prod_insert h,\n    function.comp_app],\n  rw [div_mul_div_comm ((f a).factorial_mul_factorial_dvd_factorial_add (s.sum f))\n    (prod_factorial_dvd_factorial_sum _ _), mul_comm (f a)! (s.sum f)!, mul_assoc,\n    mul_comm _ (s.sum f)!, nat.mul_div_mul _ _ (factorial_pos _)],\nend\n\nlemma multinomial_congr {f g : \u03b1 \u2192 \u2115} (h : \u2200 a \u2208 s, f a = g a) :\n  multinomial s f = multinomial s g :=\nbegin\n  simp only [multinomial], congr' 1,\n  { rw finset.sum_congr rfl h },\n  { exact finset.prod_congr rfl (\u03bb a ha, by rw h a ha) },\nend\n\n/-! ### Connection to binomial coefficients\n\nWhen `nat.multinomial` is applied to a `finset` of two elements `{a, b}`, the\nresult a binomial coefficient. We use `binomial` in the names of lemmas that\ninvolves `nat.multinomial {a, b}`.\n-/\n\nlemma binomial_eq [decidable_eq \u03b1] (h : a \u2260 b) :\n  multinomial {a, b} f = (f a + f b)! / ((f a)! * (f b)!) :=\nby simp [multinomial, finset.sum_pair h, finset.prod_pair h]\n\nlemma binomial_eq_choose [decidable_eq \u03b1] (h : a \u2260 b) :\n  multinomial {a, b} f = (f a + f b).choose (f a) :=\nby simp [binomial_eq _ h, choose_eq_factorial_div_factorial (nat.le_add_right _ _)]\n\nlemma binomial_spec [decidable_eq \u03b1] (hab : a \u2260 b) :\n  (f a)! * (f b)! * multinomial {a, b} f = (f a + f b)! :=\nby simpa [finset.sum_pair hab, finset.prod_pair hab] using multinomial_spec {a, b} f\n\n@[simp] lemma binomial_one [decidable_eq \u03b1] (h : a \u2260 b) (h\u2081 : f a = 1) :\n  multinomial {a, b} f = (f b).succ :=\nby simp [multinomial_insert_one {b} f (finset.not_mem_singleton.mpr h) h\u2081]\n\nlemma binomial_succ_succ [decidable_eq \u03b1] (h : a \u2260 b) :\n  multinomial {a, b} ((f.update a (f a).succ).update b (f b).succ) =\n  multinomial {a, b} (f.update a (f a).succ) +\n  multinomial {a, b} (f.update b (f b).succ) :=\nbegin\n  simp only [binomial_eq_choose, function.update_apply, function.update_noteq,\n    succ_add, add_succ, choose_succ_succ, h, ne.def, not_false_iff, function.update_same],\n  rw if_neg h.symm,\n  ring,\nend\n\nlemma succ_mul_binomial [decidable_eq \u03b1] (h : a \u2260 b) :\n  (f a + f b).succ * multinomial {a, b} f =\n  (f a).succ * multinomial {a, b} (f.update a (f a).succ) :=\nbegin\n  rw [binomial_eq_choose _ h, binomial_eq_choose _ h, mul_comm (f a).succ,\n    function.update_same, function.update_noteq (ne_comm.mp h)],\n  convert succ_mul_choose_eq (f a + f b) (f a),\n  exact succ_add (f a) (f b),\nend\n\n/-! ### Simple cases -/\n\nlemma multinomial_univ_two (a b : \u2115) : multinomial finset.univ ![a, b] = (a + b)! / (a! * b!) :=\nby simp [multinomial, fin.sum_univ_two, fin.prod_univ_two]\n\nlemma multinomial_univ_three (a b c : \u2115) : multinomial finset.univ ![a, b, c] =\n  (a + b + c)! / (a! * b! * c!) :=\nby simp [multinomial, fin.sum_univ_three, fin.prod_univ_three]\n\nend nat\n\n/-! ### Alternative definitions -/\n\nnamespace finsupp\n\nvariables {\u03b1 : Type*}\n\n/-- Alternative multinomial definition based on a finsupp, using the support\n  for the big operations\n-/\ndef multinomial (f : \u03b1 \u2192\u2080 \u2115) : \u2115 := (f.sum $ \u03bb _, id)! / f.prod (\u03bb _ n, n!)\n\nlemma multinomial_eq (f : \u03b1 \u2192\u2080 \u2115) : f.multinomial = nat.multinomial f.support f := rfl\n\n\n\nend finsupp\n\nnamespace multiset\n\nvariables {\u03b1 : Type*}\n\n/-- Alternative definition of multinomial based on `multiset` delegating to the\n  finsupp definition\n-/\nnoncomputable def multinomial (m : multiset \u03b1) : \u2115 := m.to_finsupp.multinomial\n\nlemma multinomial_filter_ne [decidable_eq \u03b1] (a : \u03b1) (m : multiset \u03b1) :\n  m.multinomial = m.card.choose (m.count a) * (m.filter ((\u2260) a)).multinomial :=\nbegin\n  dsimp only [multinomial],\n  convert finsupp.multinomial_update a _,\n  { rw [\u2190 finsupp.card_to_multiset, m.to_finsupp_to_multiset] },\n  { ext1 a', rw [to_finsupp_apply, count_filter, finsupp.coe_update],\n    split_ifs,\n    { rw [function.update_noteq h.symm, to_finsupp_apply] },\n    { rw [not_ne_iff.1 h, function.update_same] } },\nend\n\nend multiset\n\nnamespace finset\n\n/-! ### Multinomial theorem -/\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] (s : finset \u03b1) {R : Type*}\n\n/--\n  The multinomial theorem\n\n  Proof is by induction on the number of summands.\n-/\ntheorem sum_pow_of_commute [semiring R] (x : \u03b1 \u2192 R)\n  (hc : (s : set \u03b1).pairwise $ \u03bb i j, commute (x i) (x j)) :\n  \u2200 n, (s.sum x) ^ n =\n  \u2211 k : s.sym n, k.1.1.multinomial * (k.1.1.map $ x).noncomm_prod\n    (multiset.map_set_pairwise $ hc.mono $ mem_sym_iff.1 k.2) :=\nbegin\n  induction s using finset.induction with a s ha ih,\n  { rw sum_empty,\n    rintro (_ | n),\n    { rw [pow_zero, fintype.sum_subsingleton],\n      swap, { exact \u27e80, or.inl rfl\u27e9 },\n      convert (one_mul _).symm, apply nat.cast_one },\n    { rw [pow_succ, zero_mul],\n      apply (fintype.sum_empty _).symm,\n      rw sym_empty, apply_instance } },\n  intro n, specialize ih (hc.mono $ s.subset_insert a),\n  rw [sum_insert ha, (commute.sum_right s _ _ $ \u03bb b hb, _).add_pow, sum_range], swap,\n  { exact hc (mem_insert_self a s) (mem_insert_of_mem hb) (ne_of_mem_of_not_mem hb ha).symm },\n  simp_rw [ih, mul_sum, sum_mul, sum_sigma', univ_sigma_univ],\n  refine (fintype.sum_equiv (sym_insert_equiv ha) _ _ $ \u03bb m, _).symm,\n  rw [m.1.1.multinomial_filter_ne a],\n  conv in (m.1.1.map _) { rw [\u2190 m.1.1.filter_add_not ((=) a), multiset.map_add] },\n  simp_rw [multiset.noncomm_prod_add, m.1.1.filter_eq, multiset.map_replicate, m.1.2],\n  rw [multiset.noncomm_prod_eq_pow_card _ _ _ (\u03bb _, multiset.eq_of_mem_replicate)],\n  rw [multiset.card_replicate, nat.cast_mul, mul_assoc, nat.cast_comm],\n  congr' 1, simp_rw [\u2190 mul_assoc, nat.cast_comm], refl,\nend\n\ntheorem sum_pow [comm_semiring R] (x : \u03b1 \u2192 R) (n : \u2115) :\n  (s.sum x) ^ n = \u2211 k in s.sym n, k.val.multinomial * (k.val.map x).prod :=\nbegin\n  conv_rhs { rw \u2190 sum_coe_sort },\n  convert sum_pow_of_commute s x (\u03bb _ _ _ _ _, mul_comm _ _) n,\n  ext1, rw multiset.noncomm_prod_eq_prod, refl,\nend\n\nend finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/choose/multinomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7172578200001392}}
{"text": "/-\nCopyright (c) 2019 Alexander Bentkamp. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp, Yury Kudriashov\n-/\nimport analysis.convex.combination\nimport analysis.convex.function\n\n/-!\n# Jensen's inequality and maximum principle for convex functions\n\nIn this file, we prove the finite Jensen inequality and the finite maximum principle for convex\nfunctions. The integral versions are to be found in `analysis.convex.integral`.\n\n## Main declarations\n\nJensen's inequalities:\n* `convex_on.map_center_mass_le`, `convex_on.map_sum_le`: Convex Jensen's inequality. The image of a\n  convex combination of points under a convex function is less than the convex combination of the\n  images.\n* `concave_on.le_map_center_mass`, `concave_on.le_map_sum`: Concave Jensen's inequality.\n\nAs corollaries, we get:\n* `convex_on.exists_ge_of_mem_convex_hull `: Maximum principle for convex functions.\n* `concave_on.exists_le_of_mem_convex_hull`: Minimum principle for concave functions.\n-/\n\nopen finset linear_map set\nopen_locale big_operators classical convex pointwise\n\nvariables {\ud835\udd5c E F \u03b2 \u03b9 : Type*}\n\n/-! ### Jensen's inequality -/\n\nsection jensen\nvariables [linear_ordered_field \ud835\udd5c] [add_comm_group E] [ordered_add_comm_group \u03b2] [module \ud835\udd5c E]\n  [module \ud835\udd5c \u03b2] [ordered_smul \ud835\udd5c \u03b2] {s : set E} {f : E \u2192 \u03b2} {t : finset \u03b9} {w : \u03b9 \u2192 \ud835\udd5c} {p : \u03b9 \u2192 E}\n\n/-- Convex **Jensen's inequality**, `finset.center_mass` version. -/\nlemma convex_on.map_center_mass_le (hf : convex_on \ud835\udd5c s f) (h\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (h\u2081 : 0 < \u2211 i in t, w i) (hmem : \u2200 i \u2208 t, p i \u2208 s) :\n  f (t.center_mass w p) \u2264 t.center_mass w (f \u2218 p) :=\nbegin\n  have hmem' : \u2200 i \u2208 t, (p i, (f \u2218 p) i) \u2208 {p : E \u00d7 \u03b2 | p.1 \u2208 s \u2227 f p.1 \u2264 p.2},\n    from \u03bb i hi, \u27e8hmem i hi, le_rfl\u27e9,\n  convert (hf.convex_epigraph.center_mass_mem h\u2080 h\u2081 hmem').2;\n    simp only [center_mass, function.comp, prod.smul_fst, prod.fst_sum,\n      prod.smul_snd, prod.snd_sum],\nend\n\n/-- Concave **Jensen's inequality**, `finset.center_mass` version. -/\nlemma concave_on.le_map_center_mass (hf : concave_on \ud835\udd5c s f) (h\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (h\u2081 : 0 < \u2211 i in t, w i) (hmem : \u2200 i \u2208 t, p i \u2208 s) :\n  t.center_mass w (f \u2218 p) \u2264 f (t.center_mass w p) :=\n@convex_on.map_center_mass_le \ud835\udd5c E \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ _ _ _ _ hf h\u2080 h\u2081 hmem\n\n/-- Convex **Jensen's inequality**, `finset.sum` version. -/\nlemma convex_on.map_sum_le (hf : convex_on \ud835\udd5c s f) (h\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (h\u2081 : \u2211 i in t, w i = 1)\n  (hmem : \u2200 i \u2208 t, p i \u2208 s) :\n  f (\u2211 i in t, w i \u2022 p i) \u2264 \u2211 i in t, w i \u2022 f (p i) :=\nby simpa only [center_mass, h\u2081, inv_one, one_smul]\n  using hf.map_center_mass_le h\u2080 (h\u2081.symm \u25b8 zero_lt_one) hmem\n\n/-- Concave **Jensen's inequality**, `finset.sum` version. -/\nlemma concave_on.le_map_sum (hf : concave_on \ud835\udd5c s f) (h\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (h\u2081 : \u2211 i in t, w i = 1)\n  (hmem : \u2200 i \u2208 t, p i \u2208 s) :\n  \u2211 i in t, w i \u2022 f (p i) \u2264 f (\u2211 i in t, w i \u2022 p i) :=\n@convex_on.map_sum_le \ud835\udd5c E \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ _ _ _ _ hf h\u2080 h\u2081 hmem\n\nend jensen\n\n/-! ### Maximum principle -/\n\nsection maximum_principle\nvariables [linear_ordered_field \ud835\udd5c] [add_comm_group E] [linear_ordered_add_comm_group \u03b2]\n  [module \ud835\udd5c E] [module \ud835\udd5c \u03b2] [ordered_smul \ud835\udd5c \u03b2] {s : set E} {f : E \u2192 \u03b2} {t : finset \u03b9} {w : \u03b9 \u2192 \ud835\udd5c}\n  {p : \u03b9 \u2192 E} {x : E}\n\nlemma le_sup_of_mem_convex_hull {s : finset E} (hf : convex_on \ud835\udd5c (convex_hull \ud835\udd5c (s : set E)) f)\n  (hx : x \u2208 convex_hull \ud835\udd5c (s : set E)) :\n  f x \u2264 s.sup' (coe_nonempty.1 $ convex_hull_nonempty_iff.1 \u27e8x, hx\u27e9) f :=\nbegin\n  obtain \u27e8w, hw\u2080, hw\u2081, rfl\u27e9 := mem_convex_hull.1 hx,\n  exact (hf.map_center_mass_le hw\u2080 (by positivity) $ subset_convex_hull _ _).trans\n    (center_mass_le_sup hw\u2080 $ by positivity),\nend\n\nlemma inf_le_of_mem_convex_hull {s : finset E} (hf : concave_on \ud835\udd5c (convex_hull \ud835\udd5c (s : set E)) f)\n  (hx : x \u2208 convex_hull \ud835\udd5c (s : set E)) :\n  s.inf' (coe_nonempty.1 $ convex_hull_nonempty_iff.1 \u27e8x, hx\u27e9) f \u2264 f x :=\nle_sup_of_mem_convex_hull hf.dual hx\n\n/-- If a function `f` is convex on `s`, then the value it takes at some center of mass of points of\n`s` is less than the value it takes on one of those points. -/\nlemma convex_on.exists_ge_of_center_mass (h : convex_on \ud835\udd5c s f)\n  (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (hw\u2081 : 0 < \u2211 i in t, w i) (hp : \u2200 i \u2208 t, p i \u2208 s) :\n  \u2203 i \u2208 t, f (t.center_mass w p) \u2264 f (p i) :=\nbegin\n  set y := t.center_mass w p,\n  rsuffices \u27e8i, hi, hfi\u27e9 : \u2203 i \u2208 t.filter (\u03bb i, w i \u2260 0), w i \u2022 f y \u2264 w i \u2022 (f \u2218 p) i,\n  { rw mem_filter at hi,\n    exact \u27e8i, hi.1, (smul_le_smul_iff_of_pos $ (hw\u2080 i hi.1).lt_of_ne hi.2.symm).1 hfi\u27e9 },\n  have hw' : (0 : \ud835\udd5c) < \u2211 i in filter (\u03bb i, w i \u2260 0) t, w i := by rwa sum_filter_ne_zero,\n  refine exists_le_of_sum_le (nonempty_of_sum_ne_zero hw'.ne') _,\n  rw [\u2190sum_smul, \u2190smul_le_smul_iff_of_pos (inv_pos.2 hw'), inv_smul_smul\u2080 hw'.ne',\n    \u2190finset.center_mass, finset.center_mass_filter_ne_zero],\n  exact h.map_center_mass_le hw\u2080 hw\u2081 hp,\n  apply_instance,\nend\n\n/-- If a function `f` is concave on `s`, then the value it takes at some center of mass of points of\n`s` is greater than the value it takes on one of those points. -/\nlemma concave_on.exists_le_of_center_mass (h : concave_on \ud835\udd5c s f)\n  (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (hw\u2081 : 0 < \u2211 i in t, w i) (hp : \u2200 i \u2208 t, p i \u2208 s) :\n  \u2203 i \u2208 t, f (p i) \u2264 f (t.center_mass w p) :=\n@convex_on.exists_ge_of_center_mass \ud835\udd5c E \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ _ _ _ _ h hw\u2080 hw\u2081 hp\n\n/-- Maximum principle for convex functions. If a function `f` is convex on the convex hull of `s`,\nthen the eventual maximum of `f` on `convex_hull \ud835\udd5c s` lies in `s`. -/\nlemma convex_on.exists_ge_of_mem_convex_hull (hf : convex_on \ud835\udd5c (convex_hull \ud835\udd5c s) f) {x}\n  (hx : x \u2208 convex_hull \ud835\udd5c s) : \u2203 y \u2208 s, f x \u2264 f y :=\nbegin\n  rw _root_.convex_hull_eq at hx,\n  obtain \u27e8\u03b1, t, w, p, hw\u2080, hw\u2081, hp, rfl\u27e9 := hx,\n  rcases hf.exists_ge_of_center_mass hw\u2080 (hw\u2081.symm \u25b8 zero_lt_one)\n    (\u03bb i hi, subset_convex_hull \ud835\udd5c s (hp i hi)) with \u27e8i, hit, Hi\u27e9,\n  exact \u27e8p i, hp i hit, Hi\u27e9\nend\n\n/-- Minimum principle for concave functions. If a function `f` is concave on the convex hull of `s`,\nthen the eventual minimum of `f` on `convex_hull \ud835\udd5c s` lies in `s`. -/\nlemma concave_on.exists_le_of_mem_convex_hull (hf : concave_on \ud835\udd5c (convex_hull \ud835\udd5c s) f) {x}\n  (hx : x \u2208 convex_hull \ud835\udd5c s) : \u2203 y \u2208 s, f y \u2264 f x :=\n@convex_on.exists_ge_of_mem_convex_hull \ud835\udd5c E \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ hf _ hx\n\nend maximum_principle\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/convex/jensen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7172578090636236}}
{"text": "/-\nCopyright (c) 2019 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison\n-/\nimport data.fin.basic\nimport data.nat.cast\nimport logic.embedding\n\n/-!\n# Combinatorial (pre-)games.\n\nThe basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We\nconstruct \"pregames\", define an ordering and arithmetic operations on them, then show that the\noperations descend to \"games\", defined via the equivalence relation `p \u2248 q \u2194 p \u2264 q \u2227 q \u2264 p`.\n\nThe surreal numbers will be built as a quotient of a subtype of pregames.\n\nA pregame (`pgame` below) is axiomatised via an inductive type, whose sole constructor takes two\ntypes (thought of as indexing the possible moves for the players Left and Right), and a pair of\nfunctions out of these types to `pgame` (thought of as describing the resulting game after making a\nmove).\n\nCombinatorial games themselves, as a quotient of pregames, are constructed in `game.lean`.\n\n## Conway induction\n\nBy construction, the induction principle for pregames is exactly \"Conway induction\". That is, to\nprove some predicate `pgame \u2192 Prop` holds for all pregames, it suffices to prove that for every\npregame `g`, if the predicate holds for every game resulting from making a move, then it also holds\nfor `g`.\n\nWhile it is often convenient to work \"by induction\" on pregames, in some situations this becomes\nawkward, so we also define accessor functions `left_moves`, `right_moves`, `move_left` and\n`move_right`. There is a relation `subsequent p q`, saying that `p` can be reached by playing some\nnon-empty sequence of moves starting from `q`, an instance `well_founded subsequent`, and a local\ntactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying\non this relation.\n\n## Order properties\n\nPregames have both a `\u2264` and a `<` relation, which are related in quite a subtle way. In particular,\nit is worth noting that in Lean's (perhaps unfortunate?) definition of a `preorder`, we have\n`lt_iff_le_not_le : \u2200 a b : \u03b1, a < b \u2194 (a \u2264 b \u2227 \u00ac b \u2264 a)`, but this is _not_ satisfied by the usual\n`\u2264` and `<` relations on pregames. (It is satisfied once we restrict to the surreal numbers.) In\nparticular, `<` is not transitive; there is an example below showing `0 < star \u2227 star < 0`.\n\nWe do have\n```\ntheorem not_le {x y : pgame} : \u00ac x \u2264 y \u2194 y < x := ...\ntheorem not_lt {x y : pgame} : \u00ac x < y \u2194 y \u2264 x := ...\n```\n\nThe statement `0 \u2264 x` means that Left has a good response to any move by Right; in particular, the\ntheorem `zero_le` below states\n```\n0 \u2264 x \u2194 \u2200 j : x.right_moves, \u2203 i : (x.move_right j).left_moves, 0 \u2264 (x.move_right j).move_left i\n```\nOn the other hand the statement `0 < x` means that Left has a good move right now; in particular the\ntheorem `zero_lt` below states\n```\n0 < x \u2194 \u2203 i : left_moves x, \u2200 j : right_moves (x.move_left i), 0 < (x.move_left i).move_right j\n```\n\nThe theorems `le_def`, `lt_def`, give a recursive characterisation of each relation, in terms of\nthemselves two moves later. The theorems `le_def_lt` and `lt_def_lt` give recursive\ncharacterisations of each relation in terms of the other relation one move later.\n\nWe define an equivalence relation `equiv p q \u2194 p \u2264 q \u2227 q \u2264 p`. Later, games will be defined as the\nquotient by this relation.\n\n## Algebraic structures\n\nWe next turn to defining the operations necessary to make games into a commutative additive group.\nAddition is defined for $x = \\{xL | xR\\}$ and $y = \\{yL | yR\\}$ by $x + y = \\{xL + y, x + yL | xR +\ny, x + yR\\}$. Negation is defined by $\\{xL | xR\\} = \\{-xR | -xL\\}$.\n\nThe order structures interact in the expected way with addition, so we have\n```\ntheorem le_iff_sub_nonneg {x y : pgame} : x \u2264 y \u2194 0 \u2264 y - x := sorry\ntheorem lt_iff_sub_pos {x y : pgame} : x < y \u2194 0 < y - x := sorry\n```\n\nWe show that these operations respect the equivalence relation, and hence descend to games. At the\nlevel of games, these operations satisfy all the laws of a commutative group. To prove the necessary\nequivalence relations at the level of pregames, we introduce the notion of a `relabelling` of a\ngame, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`.\n\n## Future work\n* The theory of dominated and reversible positions, and unique normal form for short games.\n* Analysis of basic domineering positions.\n* Hex.\n* Temperature.\n* The development of surreal numbers, based on this development of combinatorial games, is still\n  quite incomplete.\n\n## References\n\nThe material here is all drawn from\n* [Conway, *On numbers and games*][conway2001]\n\nAn interested reader may like to formalise some of the material from\n* [Andreas Blass, *A game semantics for linear logic*][MR1167694]\n* [Andr\u00e9 Joyal, *Remarques sur la th\u00e9orie des jeux \u00e0 deux personnes*][joyal1997]\n-/\n\nuniverses u\n\n/-- The type of pre-games, before we have quotiented\n  by extensionality. In ZFC, a combinatorial game is constructed from\n  two sets of combinatorial games that have been constructed at an earlier\n  stage. To do this in type theory, we say that a pre-game is built\n  inductively from two families of pre-games indexed over any type\n  in Type u. The resulting type `pgame.{u}` lives in `Type (u+1)`,\n  reflecting that it is a proper class in ZFC. -/\ninductive pgame : Type (u+1)\n| mk : \u2200 \u03b1 \u03b2 : Type u, (\u03b1 \u2192 pgame) \u2192 (\u03b2 \u2192 pgame) \u2192 pgame\n\nnamespace pgame\n\n/--\nConstruct a pre-game from list of pre-games describing the available moves for Left and Right.\n-/\n-- TODO provide some API describing the interaction with\n-- `left_moves`, `right_moves`, `move_left` and `move_right` below.\n-- TODO define this at the level of games, as well, and perhaps also for finsets of games.\ndef of_lists (L R : list pgame.{0}) : pgame.{0} :=\npgame.mk (fin L.length) (fin R.length) (\u03bb i, L.nth_le i i.is_lt) (\u03bb j, R.nth_le j.val j.is_lt)\n\n/-- The indexing type for allowable moves by Left. -/\ndef left_moves : pgame \u2192 Type u\n| (mk l _ _ _) := l\n/-- The indexing type for allowable moves by Right. -/\ndef right_moves : pgame \u2192 Type u\n| (mk _ r _ _) := r\n\n/-- The new game after Left makes an allowed move. -/\ndef move_left : \u03a0 (g : pgame), left_moves g \u2192 pgame\n| (mk l _ L _) i := L i\n/-- The new game after Right makes an allowed move. -/\ndef move_right : \u03a0 (g : pgame), right_moves g \u2192 pgame\n| (mk _ r _ R) j := R j\n\n@[simp] lemma left_moves_mk {xl xr xL xR} : (\u27e8xl, xr, xL, xR\u27e9 : pgame).left_moves = xl := rfl\n@[simp] lemma move_left_mk {xl xr xL xR i} : (\u27e8xl, xr, xL, xR\u27e9 : pgame).move_left i = xL i := rfl\n@[simp] lemma right_moves_mk {xl xr xL xR} : (\u27e8xl, xr, xL, xR\u27e9 : pgame).right_moves = xr := rfl\n@[simp] lemma move_right_mk {xl xr xL xR j} : (\u27e8xl, xr, xL, xR\u27e9 : pgame).move_right j = xR j := rfl\n\n/-- `subsequent p q` says that `p` can be obtained by playing\n  some nonempty sequence of moves from `q`. -/\ninductive subsequent : pgame \u2192 pgame \u2192 Prop\n| left : \u03a0 (x : pgame) (i : x.left_moves), subsequent (x.move_left i) x\n| right : \u03a0 (x : pgame) (j : x.right_moves), subsequent (x.move_right j) x\n| trans : \u03a0 (x y z : pgame), subsequent x y \u2192 subsequent y z \u2192 subsequent x z\n\ntheorem wf_subsequent : well_founded subsequent :=\n\u27e8\u03bb x, begin\n  induction x with l r L R IHl IHr,\n  refine \u27e8_, \u03bb y h, _\u27e9,\n  generalize_hyp e : mk l r L R = x at h,\n  induction h with _ i _ j a b _ h1 h2 IH1 IH2; subst e,\n  { apply IHl },\n  { apply IHr },\n  { exact acc.inv (IH2 rfl) h1 }\nend\u27e9\n\ninstance : has_well_founded pgame :=\n{ r := subsequent,\n  wf := wf_subsequent }\n\n/-- A move by Left produces a subsequent game. (For use in pgame_wf_tac.) -/\nlemma subsequent.left_move {xl xr} {xL : xl \u2192 pgame} {xR : xr \u2192 pgame} {i : xl} :\n  subsequent (xL i) (mk xl xr xL xR) :=\nsubsequent.left (mk xl xr xL xR) i\n/-- A move by Right produces a subsequent game. (For use in pgame_wf_tac.) -/\nlemma subsequent.right_move {xl xr} {xL : xl \u2192 pgame} {xR : xr \u2192 pgame} {j : xr} :\n  subsequent (xR j) (mk xl xr xL xR) :=\nsubsequent.right (mk xl xr xL xR) j\n\n/-- A local tactic for proving well-foundedness of recursive definitions involving pregames. -/\nmeta def pgame_wf_tac :=\n`[solve_by_elim\n  [psigma.lex.left, psigma.lex.right,\n   subsequent.left_move, subsequent.right_move,\n   subsequent.left, subsequent.right, subsequent.trans]\n  { max_depth := 6 }]\n\n/-- The pre-game `zero` is defined by `0 = { | }`. -/\ninstance : has_zero pgame := \u27e8\u27e8pempty, pempty, pempty.elim, pempty.elim\u27e9\u27e9\n\n@[simp] lemma zero_left_moves : (0 : pgame).left_moves = pempty := rfl\n@[simp] lemma zero_right_moves : (0 : pgame).right_moves = pempty := rfl\n\ninstance : inhabited pgame := \u27e80\u27e9\n\n/-- The pre-game `one` is defined by `1 = { 0 | }`. -/\ninstance : has_one pgame := \u27e8\u27e8punit, pempty, \u03bb _, 0, pempty.elim\u27e9\u27e9\n\n@[simp] lemma one_left_moves : (1 : pgame).left_moves = punit := rfl\n@[simp] lemma one_move_left : (1 : pgame).move_left punit.star = 0 := rfl\n@[simp] lemma one_right_moves : (1 : pgame).right_moves = pempty := rfl\n\n/-- Define simultaneously by mutual induction the `<=` and `<`\n  relation on pre-games. The ZFC definition says that `x = {xL | xR}`\n  is less or equal to `y = {yL | yR}` if `\u2200 x\u2081 \u2208 xL, x\u2081 < y`\n  and `\u2200 y\u2082 \u2208 yR, x < y\u2082`, where `x < y` is the same as `\u00ac y <= x`.\n  This is a tricky induction because it only decreases one side at\n  a time, and it also swaps the arguments in the definition of `<`.\n  The solution is to define `x < y` and `x <= y` simultaneously. -/\ndef le_lt : \u03a0 (x y : pgame), Prop \u00d7 Prop\n| (mk xl xr xL xR) (mk yl yr yL yR) :=\n  -- the orderings of the clauses here are carefully chosen so that\n  --   and.left/or.inl refer to moves by Left, and\n  --   and.right/or.inr refer to moves by Right.\n((\u2200 i : xl, (le_lt (xL i) \u27e8yl, yr, yL, yR\u27e9).2) \u2227 (\u2200 j : yr, (le_lt \u27e8xl, xr, xL, xR\u27e9 (yR j)).2),\n  (\u2203 i : yl, (le_lt \u27e8xl, xr, xL, xR\u27e9 (yL i)).1) \u2228 (\u2203 j : xr, (le_lt (xR j) \u27e8yl, yr, yL, yR\u27e9).1))\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ninstance : has_le pgame := \u27e8\u03bb x y, (le_lt x y).1\u27e9\ninstance : has_lt pgame := \u27e8\u03bb x y, (le_lt x y).2\u27e9\n\n/-- Definition of `x \u2264 y` on pre-games built using the constructor. -/\n@[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} :\n  (\u27e8xl, xr, xL, xR\u27e9 : pgame) \u2264 \u27e8yl, yr, yL, yR\u27e9 \u2194\n  (\u2200 i, xL i < \u27e8yl, yr, yL, yR\u27e9) \u2227\n  (\u2200 j, (\u27e8xl, xr, xL, xR\u27e9 : pgame) < yR j) :=\nshow (le_lt _ _).1 \u2194 _, by { rw le_lt, refl }\n\n/-- Definition of `x \u2264 y` on pre-games, in terms of `<` -/\ntheorem le_def_lt {x y : pgame} : x \u2264 y \u2194\n  (\u2200 i : x.left_moves, x.move_left i < y) \u2227\n  (\u2200 j : y.right_moves, x < y.move_right j) :=\nby { cases x, cases y, rw mk_le_mk, refl }\n\n/-- Definition of `x < y` on pre-games built using the constructor. -/\n@[simp] theorem mk_lt_mk {xl xr xL xR yl yr yL yR} :\n  (\u27e8xl, xr, xL, xR\u27e9 : pgame) < \u27e8yl, yr, yL, yR\u27e9 \u2194\n  (\u2203 i, (\u27e8xl, xr, xL, xR\u27e9 : pgame) \u2264 yL i) \u2228\n  (\u2203 j, xR j \u2264 \u27e8yl, yr, yL, yR\u27e9) :=\nshow (le_lt _ _).2 \u2194 _, by { rw le_lt, refl }\n\n/-- Definition of `x < y` on pre-games, in terms of `\u2264` -/\ntheorem lt_def_le {x y : pgame} : x < y \u2194\n  (\u2203 i : y.left_moves, x \u2264 y.move_left i) \u2228\n  (\u2203 j : x.right_moves, x.move_right j \u2264 y) :=\nby { cases x, cases y, rw mk_lt_mk, refl }\n\n/-- The definition of `x \u2264 y` on pre-games, in terms of `\u2264` two moves later. -/\ntheorem le_def {x y : pgame} : x \u2264 y \u2194\n  (\u2200 i : x.left_moves,\n   (\u2203 i' : y.left_moves, x.move_left i \u2264 y.move_left i') \u2228\n   (\u2203 j : (x.move_left i).right_moves, (x.move_left i).move_right j \u2264 y)) \u2227\n  (\u2200 j : y.right_moves,\n   (\u2203 i : (y.move_right j).left_moves, x \u2264 (y.move_right j).move_left i) \u2228\n   (\u2203 j' : x.right_moves, x.move_right j' \u2264 y.move_right j)) :=\nbegin\n  rw [le_def_lt],\n  conv { to_lhs, simp only [lt_def_le] },\nend\n\n/-- The definition of `x < y` on pre-games, in terms of `<` two moves later. -/\ntheorem lt_def {x y : pgame} : x < y \u2194\n  (\u2203 i : y.left_moves,\n    (\u2200 i' : x.left_moves, x.move_left i' < y.move_left i) \u2227\n    (\u2200 j : (y.move_left i).right_moves, x < (y.move_left i).move_right j)) \u2228\n  (\u2203 j : x.right_moves,\n    (\u2200 i : (x.move_right j).left_moves, (x.move_right j).move_left i < y) \u2227\n    (\u2200 j' : y.right_moves, x.move_right j < y.move_right j')) :=\nbegin\n  rw [lt_def_le],\n  conv { to_lhs, simp only [le_def_lt] },\nend\n\n/-- The definition of `x \u2264 0` on pre-games, in terms of `\u2264 0` two moves later. -/\ntheorem le_zero {x : pgame} : x \u2264 0 \u2194\n  \u2200 i : x.left_moves, \u2203 j : (x.move_left i).right_moves, (x.move_left i).move_right j \u2264 0 :=\nbegin\n  rw le_def,\n  dsimp,\n  simp [forall_pempty, exists_pempty]\nend\n\n/-- The definition of `0 \u2264 x` on pre-games, in terms of `0 \u2264` two moves later. -/\ntheorem zero_le {x : pgame} : 0 \u2264 x \u2194\n  \u2200 j : x.right_moves, \u2203 i : (x.move_right j).left_moves, 0 \u2264 (x.move_right j).move_left i :=\nbegin\n  rw le_def,\n  dsimp,\n  simp [forall_pempty, exists_pempty]\nend\n\n/-- The definition of `x < 0` on pre-games, in terms of `< 0` two moves later. -/\ntheorem lt_zero {x : pgame} : x < 0 \u2194\n  \u2203 j : x.right_moves, \u2200 i : (x.move_right j).left_moves, (x.move_right j).move_left i < 0 :=\nbegin\n  rw lt_def,\n  dsimp,\n  simp [forall_pempty, exists_pempty]\nend\n\n/-- The definition of `0 < x` on pre-games, in terms of `< x` two moves later. -/\ntheorem zero_lt {x : pgame} : 0 < x \u2194\n  \u2203 i : x.left_moves, \u2200 j : (x.move_left i).right_moves, 0 < (x.move_left i).move_right j :=\nbegin\n  rw lt_def,\n  dsimp,\n  simp [forall_pempty, exists_pempty]\nend\n\n/-- Given a right-player-wins game, provide a response to any move by left. -/\nnoncomputable def right_response {x : pgame} (h : x \u2264 0) (i : x.left_moves) :\n  (x.move_left i).right_moves :=\nclassical.some $ (le_zero.1 h) i\n\n/-- Show that the response for right provided by `right_response`\n    preserves the right-player-wins condition. -/\nlemma right_response_spec {x : pgame} (h : x \u2264 0) (i : x.left_moves) :\n  (x.move_left i).move_right (right_response h i) \u2264 0 :=\nclassical.some_spec $ (le_zero.1 h) i\n\n/-- Given a left-player-wins game, provide a response to any move by right. -/\nnoncomputable def left_response {x : pgame} (h : 0 \u2264 x) (j : x.right_moves) :\n  (x.move_right j).left_moves :=\nclassical.some $ (zero_le.1 h) j\n\n/-- Show that the response for left provided by `left_response`\n    preserves the left-player-wins condition. -/\nlemma left_response_spec {x : pgame} (h : 0 \u2264 x) (j : x.right_moves) :\n  0 \u2264 (x.move_right j).move_left (left_response h j) :=\nclassical.some_spec $ (zero_le.1 h) j\n\ntheorem lt_of_le_mk {xl xr xL xR y i} :\n  (\u27e8xl, xr, xL, xR\u27e9 : pgame) \u2264 y \u2192 xL i < y :=\nby { cases y, rw mk_le_mk, tauto }\n\ntheorem lt_of_mk_le {x : pgame} {yl yr yL yR i} :\n  x \u2264 \u27e8yl, yr, yL, yR\u27e9 \u2192 x < yR i :=\nby { cases x, rw mk_le_mk, tauto }\n\ntheorem mk_lt_of_le {xl xr xL xR y i} :\n  ((xR : xr \u2192 pgame) i \u2264 y) \u2192 (\u27e8xl, xr, xL, xR\u27e9 : pgame) < y :=\nby { cases y, rw mk_lt_mk, tauto }\n\ntheorem lt_mk_of_le {x : pgame} {yl yr : Type*} {yL : yl \u2192 pgame} {yR i} :\n  (x \u2264 yL i) \u2192 x < \u27e8yl, yr, yL, yR\u27e9 :=\nby { cases x, rw mk_lt_mk, exact \u03bb h, or.inl \u27e8_, h\u27e9 }\n\ntheorem not_le_lt {x y : pgame} :\n  (\u00ac x \u2264 y \u2194 y < x) \u2227 (\u00ac x < y \u2194 y \u2264 x) :=\nbegin\n  induction x with xl xr xL xR IHxl IHxr generalizing y,\n  induction y with yl yr yL yR IHyl IHyr,\n  classical,\n  simp only [mk_le_mk, mk_lt_mk,\n    not_and_distrib, not_or_distrib, not_forall, not_exists,\n    and_comm, or_comm, IHxl, IHxr, IHyl, IHyr, iff_self, and_self]\nend\n\ntheorem not_le {x y : pgame} : \u00ac x \u2264 y \u2194 y < x := not_le_lt.1\ntheorem not_lt {x y : pgame} : \u00ac x < y \u2194 y \u2264 x := not_le_lt.2\n\n@[refl] protected theorem le_refl : \u2200 x : pgame, x \u2264 x\n| \u27e8l, r, L, R\u27e9 := by rw mk_le_mk; exact\n\u27e8\u03bb i, lt_mk_of_le (le_refl _), \u03bb i, mk_lt_of_le (le_refl _)\u27e9\n\nprotected theorem lt_irrefl (x : pgame) : \u00ac x < x :=\nnot_lt.2 (pgame.le_refl _)\n\nprotected theorem ne_of_lt : \u2200 {x y : pgame}, x < y \u2192 x \u2260 y\n| x _ h rfl := pgame.lt_irrefl x h\n\ntheorem le_trans_aux\n  {xl xr} {xL : xl \u2192 pgame} {xR : xr \u2192 pgame}\n  {yl yr} {yL : yl \u2192 pgame} {yR : yr \u2192 pgame}\n  {zl zr} {zL : zl \u2192 pgame} {zR : zr \u2192 pgame}\n  (h\u2081 : \u2200 i, mk yl yr yL yR \u2264 mk zl zr zL zR \u2192 mk zl zr zL zR \u2264 xL i \u2192 mk yl yr yL yR \u2264 xL i)\n  (h\u2082 : \u2200 i, zR i \u2264 mk xl xr xL xR \u2192 mk xl xr xL xR \u2264 mk yl yr yL yR \u2192 zR i \u2264 mk yl yr yL yR) :\n  mk xl xr xL xR \u2264 mk yl yr yL yR \u2192\n  mk yl yr yL yR \u2264 mk zl zr zL zR \u2192\n  mk xl xr xL xR \u2264 mk zl zr zL zR :=\nby simp only [mk_le_mk] at *; exact\n\u03bb \u27e8xLy, xyR\u27e9 \u27e8yLz, yzR\u27e9, \u27e8\n  \u03bb i, not_le.1 (\u03bb h, not_lt.2 (h\u2081 _ \u27e8yLz, yzR\u27e9 h) (xLy _)),\n  \u03bb i, not_le.1 (\u03bb h, not_lt.2 (h\u2082 _ h \u27e8xLy, xyR\u27e9) (yzR _))\u27e9\n\n@[trans] theorem le_trans {x y z : pgame} : x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z :=\nsuffices \u2200 {x y z : pgame},\n  (x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z) \u2227 (y \u2264 z \u2192 z \u2264 x \u2192 y \u2264 x) \u2227 (z \u2264 x \u2192 x \u2264 y \u2192 z \u2264 y),\nfrom this.1, begin\n  clear x y z, intros,\n  induction x with xl xr xL xR IHxl IHxr generalizing y z,\n  induction y with yl yr yL yR IHyl IHyr generalizing z,\n  induction z with zl zr zL zR IHzl IHzr,\n  exact \u27e8\n    le_trans_aux (\u03bb i, (IHxl _).2.1) (\u03bb i, (IHzr _).2.2),\n    le_trans_aux (\u03bb i, (IHyl _).2.2) (\u03bb i, (IHxr _).1),\n    le_trans_aux (\u03bb i, (IHzl _).1) (\u03bb i, (IHyr _).2.1)\u27e9,\nend\n\n@[trans] theorem lt_of_le_of_lt {x y z : pgame} (hxy : x \u2264 y) (hyz : y < z) : x < z :=\nbegin\n  rw \u2190not_le at \u22a2 hyz,\n  exact mt (\u03bb H, le_trans H hxy) hyz\nend\n\n@[trans] theorem lt_of_lt_of_le {x y z : pgame} (hxy : x < y) (hyz : y \u2264 z) : x < z :=\nbegin\n  rw \u2190not_le at \u22a2 hxy,\n  exact mt (\u03bb H, le_trans hyz H) hxy\nend\n\n/-- Define the equivalence relation on pre-games. Two pre-games\n  `x`, `y` are equivalent if `x \u2264 y` and `y \u2264 x`. -/\ndef equiv (x y : pgame) : Prop := x \u2264 y \u2227 y \u2264 x\n\nlocal infix ` \u2248 ` := pgame.equiv\n\n@[refl, simp] theorem equiv_refl (x) : x \u2248 x := \u27e8pgame.le_refl _, pgame.le_refl _\u27e9\n@[symm] theorem equiv_symm {x y} : x \u2248 y \u2192 y \u2248 x | \u27e8xy, yx\u27e9 := \u27e8yx, xy\u27e9\n@[trans] theorem equiv_trans {x y z} : x \u2248 y \u2192 y \u2248 z \u2192 x \u2248 z\n| \u27e8xy, yx\u27e9 \u27e8yz, zy\u27e9 := \u27e8le_trans xy yz, le_trans zy yx\u27e9\n\n@[trans]\ntheorem lt_of_lt_of_equiv {x y z} (h\u2081 : x < y) (h\u2082 : y \u2248 z) : x < z := lt_of_lt_of_le h\u2081 h\u2082.1\n@[trans]\ntheorem le_of_le_of_equiv {x y z} (h\u2081 : x \u2264 y) (h\u2082 : y \u2248 z) : x \u2264 z := le_trans h\u2081 h\u2082.1\n@[trans]\ntheorem lt_of_equiv_of_lt {x y z} (h\u2081 : x \u2248 y) (h\u2082 : y < z) : x < z := lt_of_le_of_lt h\u2081.1 h\u2082\n@[trans]\ntheorem le_of_equiv_of_le {x y z} (h\u2081 : x \u2248 y) (h\u2082 : y \u2264 z) : x \u2264 z := le_trans h\u2081.1 h\u2082\n\ntheorem le_congr {x\u2081 y\u2081 x\u2082 y\u2082} : x\u2081 \u2248 x\u2082 \u2192 y\u2081 \u2248 y\u2082 \u2192 (x\u2081 \u2264 y\u2081 \u2194 x\u2082 \u2264 y\u2082)\n| \u27e8x12, x21\u27e9 \u27e8y12, y21\u27e9 := \u27e8\u03bb h, le_trans x21 (le_trans h y12), \u03bb h, le_trans x12 (le_trans h y21)\u27e9\n\ntheorem lt_congr {x\u2081 y\u2081 x\u2082 y\u2082} (hx : x\u2081 \u2248 x\u2082) (hy : y\u2081 \u2248 y\u2082) : x\u2081 < y\u2081 \u2194 x\u2082 < y\u2082 :=\nnot_le.symm.trans $ (not_congr (le_congr hy hx)).trans not_le\n\ntheorem equiv_congr_left {y\u2081 y\u2082} : y\u2081 \u2248 y\u2082 \u2194 \u2200 x\u2081, x\u2081 \u2248 y\u2081 \u2194 x\u2081 \u2248 y\u2082 :=\n\u27e8\u03bb h x\u2081, \u27e8\u03bb h', equiv_trans h' h, \u03bb h', equiv_trans h' (equiv_symm h)\u27e9,\n \u03bb h, (h y\u2081).1 $ equiv_refl _\u27e9\n\ntheorem equiv_congr_right {x\u2081 x\u2082} : x\u2081 \u2248 x\u2082 \u2194 \u2200 y\u2081, x\u2081 \u2248 y\u2081 \u2194 x\u2082 \u2248 y\u2081 :=\n\u27e8\u03bb h y\u2081, \u27e8\u03bb h', equiv_trans (equiv_symm h) h', \u03bb h', equiv_trans h h'\u27e9,\n \u03bb h, (h x\u2082).2 $ equiv_refl _\u27e9\n\ntheorem equiv_of_mk_equiv {x y : pgame}\n  (L : x.left_moves \u2243 y.left_moves) (R : x.right_moves \u2243 y.right_moves)\n  (hl : \u2200 (i : x.left_moves), x.move_left i \u2248 y.move_left (L i))\n  (hr : \u2200 (j : y.right_moves), x.move_right (R.symm j) \u2248 y.move_right j) :\n  x \u2248 y :=\nbegin\n  fsplit; rw le_def,\n  { exact \u27e8\u03bb i, or.inl \u27e8L i, (hl i).1\u27e9, \u03bb j, or.inr \u27e8R.symm j, (hr j).1\u27e9\u27e9 },\n  { fsplit,\n    { intro i,\n      left,\n      specialize hl (L.symm i),\n      simp only [move_left_mk, equiv.apply_symm_apply] at hl,\n      use \u27e8L.symm i, hl.2\u27e9 },\n    { intro j,\n      right,\n      specialize hr (R j),\n      simp only [move_right_mk, equiv.symm_apply_apply] at hr,\n      use \u27e8R j, hr.2\u27e9 } }\nend\n\n/-- `restricted x y` says that Left always has no more moves in `x` than in `y`,\n     and Right always has no more moves in `y` than in `x` -/\ninductive restricted : pgame.{u} \u2192 pgame.{u} \u2192 Type (u+1)\n| mk : \u03a0 {x y : pgame} (L : x.left_moves \u2192 y.left_moves) (R : y.right_moves \u2192 x.right_moves),\n         (\u2200 (i : x.left_moves), restricted (x.move_left i) (y.move_left (L i))) \u2192\n         (\u2200 (j : y.right_moves), restricted (x.move_right (R j)) (y.move_right j)) \u2192 restricted x y\n\n/-- The identity restriction. -/\n@[refl] def restricted.refl : \u03a0 (x : pgame), restricted x x\n| (mk xl xr xL xR) :=\n  restricted.mk\n    id id\n    (\u03bb i, restricted.refl _) (\u03bb j, restricted.refl _)\nusing_well_founded { dec_tac := pgame_wf_tac }\n\n-- TODO trans for restricted\n\ntheorem restricted.le : \u03a0 {x y : pgame} (r : restricted x y), x \u2264 y\n| (mk xl xr xL xR) (mk yl yr yL yR)\n  (restricted.mk L_embedding R_embedding L_restriction R_restriction) :=\nbegin\n  rw le_def,\n  exact\n    \u27e8\u03bb i, or.inl \u27e8L_embedding i, (L_restriction i).le\u27e9,\n     \u03bb i, or.inr \u27e8R_embedding i, (R_restriction i).le\u27e9\u27e9\nend\n\n/--\n`relabelling x y` says that `x` and `y` are really the same game, just dressed up differently.\nSpecifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly\nfor Right, and under these bijections we inductively have `relabelling`s for the consequent games.\n-/\ninductive relabelling : pgame.{u} \u2192 pgame.{u} \u2192 Type (u+1)\n| mk : \u03a0 {x y : pgame} (L : x.left_moves \u2243 y.left_moves) (R : x.right_moves \u2243 y.right_moves),\n         (\u2200 (i : x.left_moves), relabelling (x.move_left i) (y.move_left (L i))) \u2192\n         (\u2200 (j : y.right_moves), relabelling (x.move_right (R.symm j)) (y.move_right j)) \u2192\n       relabelling x y\n\n/-- If `x` is a relabelling of `y`, then Left and Right have the same moves in either game,\n    so `x` is a restriction of `y`. -/\ndef relabelling.restricted: \u03a0 {x y : pgame} (r : relabelling x y), restricted x y\n| (mk xl xr xL xR) (mk yl yr yL yR) (relabelling.mk L_equiv R_equiv L_relabelling R_relabelling) :=\nrestricted.mk L_equiv.to_embedding R_equiv.symm.to_embedding\n  (\u03bb i, (L_relabelling i).restricted)\n  (\u03bb j, (R_relabelling j).restricted)\n\n-- It's not the case that `restricted x y \u2192 restricted y x \u2192 relabelling x y`,\n-- but if we insisted that the maps in a restriction were injective, then one\n-- could use Schr\u00f6der-Bernstein for do this.\n\n/-- The identity relabelling. -/\n@[refl] def relabelling.refl : \u03a0 (x : pgame), relabelling x x\n| (mk xl xr xL xR) :=\n  relabelling.mk (equiv.refl _) (equiv.refl _)\n    (\u03bb i, relabelling.refl _) (\u03bb j, relabelling.refl _)\nusing_well_founded { dec_tac := pgame_wf_tac }\n\n/-- Reverse a relabelling. -/\n@[symm] def relabelling.symm : \u03a0 {x y : pgame}, relabelling x y \u2192 relabelling y x\n| (mk xl xr xL xR) (mk yl yr yL yR) (relabelling.mk L_equiv R_equiv L_relabelling R_relabelling) :=\nbegin\n  refine relabelling.mk L_equiv.symm R_equiv.symm _ _,\n  { intro i, simpa using (L_relabelling (L_equiv.symm i)).symm },\n  { intro j, simpa using (R_relabelling (R_equiv j)).symm }\nend\n\n/-- Transitivity of relabelling -/\n@[trans] def relabelling.trans :\n  \u03a0 {x y z : pgame}, relabelling x y \u2192 relabelling y z \u2192 relabelling x z\n| (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR)\n  (relabelling.mk L_equiv\u2081 R_equiv\u2081 L_relabelling\u2081 R_relabelling\u2081)\n  (relabelling.mk L_equiv\u2082 R_equiv\u2082 L_relabelling\u2082 R_relabelling\u2082) :=\nbegin\n  refine relabelling.mk (L_equiv\u2081.trans L_equiv\u2082) (R_equiv\u2081.trans R_equiv\u2082) _ _,\n  { intro i, simpa using (L_relabelling\u2081 _).trans (L_relabelling\u2082 _) },\n  { intro j, simpa using (R_relabelling\u2081 _).trans (R_relabelling\u2082 _) },\nend\n\ntheorem relabelling.le {x y : pgame} (r : relabelling x y) : x \u2264 y :=\nr.restricted.le\n\n/-- A relabelling lets us prove equivalence of games. -/\ntheorem relabelling.equiv {x y : pgame} (r : relabelling x y) : x \u2248 y :=\n\u27e8r.le, r.symm.le\u27e9\n\ninstance {x y : pgame} : has_coe (relabelling x y) (x \u2248 y) := \u27e8relabelling.equiv\u27e9\n\n/-- Replace the types indexing the next moves for Left and Right by equivalent types. -/\ndef relabel {x : pgame} {xl' xr'} (el : x.left_moves \u2243 xl') (er : x.right_moves \u2243 xr') :=\npgame.mk xl' xr' (\u03bb i, x.move_left (el.symm i)) (\u03bb j, x.move_right (er.symm j))\n\n@[simp] lemma relabel_move_left' {x : pgame} {xl' xr'}\n  (el : x.left_moves \u2243 xl') (er : x.right_moves \u2243 xr') (i : xl') :\n  move_left (relabel el er) i = x.move_left (el.symm i) :=\nrfl\n@[simp] lemma relabel_move_left {x : pgame} {xl' xr'}\n  (el : x.left_moves \u2243 xl') (er : x.right_moves \u2243 xr') (i : x.left_moves) :\n  move_left (relabel el er) (el i) = x.move_left i :=\nby simp\n\n@[simp] lemma relabel_move_right' {x : pgame} {xl' xr'}\n  (el : x.left_moves \u2243 xl') (er : x.right_moves \u2243 xr') (j : xr') :\n  move_right (relabel el er) j = x.move_right (er.symm j) :=\nrfl\n@[simp] lemma relabel_move_right {x : pgame} {xl' xr'}\n  (el : x.left_moves \u2243 xl') (er : x.right_moves \u2243 xr') (j : x.right_moves) :\n  move_right (relabel el er) (er j) = x.move_right j :=\nby simp\n\n/-- The game obtained by relabelling the next moves is a relabelling of the original game. -/\ndef relabel_relabelling {x : pgame} {xl' xr'} (el : x.left_moves \u2243 xl') (er : x.right_moves \u2243 xr') :\n  relabelling x (relabel el er) :=\nrelabelling.mk el er (\u03bb i, by simp) (\u03bb j, by simp)\n\n/-- The negation of `{L | R}` is `{-R | -L}`. -/\ndef neg : pgame \u2192 pgame\n| \u27e8l, r, L, R\u27e9 := \u27e8r, l, \u03bb i, neg (R i), \u03bb i, neg (L i)\u27e9\n\ninstance : has_neg pgame := \u27e8neg\u27e9\n\n@[simp] lemma neg_def {xl xr xL xR} : -(mk xl xr xL xR) = mk xr xl (\u03bb j, -(xR j)) (\u03bb i, -(xL i)) :=\nrfl\n\n@[simp] theorem neg_neg : \u03a0 {x : pgame}, -(-x) = x\n| (mk xl xr xL xR) :=\nbegin\n  dsimp [has_neg.neg, neg],\n  congr; funext i; apply neg_neg\nend\n\n@[simp] theorem neg_zero : -(0 : pgame) = 0 :=\nbegin\n  dsimp [has_zero.zero, has_neg.neg, neg],\n  congr; funext i; cases i\nend\n\n/-- An explicit equivalence between the moves for Left in `-x` and the moves for Right in `x`. -/\n-- This equivalence is useful to avoid having to use `cases` unnecessarily.\ndef left_moves_neg (x : pgame) : (-x).left_moves \u2243 x.right_moves :=\nby { cases x, refl }\n\n/-- An explicit equivalence between the moves for Right in `-x` and the moves for Left in `x`. -/\ndef right_moves_neg (x : pgame) : (-x).right_moves \u2243 x.left_moves :=\nby { cases x, refl }\n\n@[simp] lemma move_right_left_moves_neg {x : pgame} (i : left_moves (-x)) :\n  move_right x ((left_moves_neg x) i) = -(move_left (-x) i) :=\nbegin\n  induction x,\n  exact neg_neg.symm\nend\n@[simp] lemma move_left_left_moves_neg_symm {x : pgame} (i : right_moves x) :\n  move_left (-x) ((left_moves_neg x).symm i) = -(move_right x i) :=\nby { cases x, refl }\n@[simp] lemma move_left_right_moves_neg {x : pgame} (i : right_moves (-x)) :\n  move_left x ((right_moves_neg x) i) = -(move_right (-x) i) :=\nbegin\n  induction x,\n  exact neg_neg.symm\nend\n@[simp] lemma move_right_right_moves_neg_symm {x : pgame} (i : left_moves x) :\n  move_right (-x) ((right_moves_neg x).symm i) = -(move_left x i) :=\nby { cases x, refl }\n\n/-- If `x` has the same moves as `y`, then `-x` has the sames moves as `-y`. -/\ndef relabelling.neg_congr : \u2200 {x y : pgame}, x.relabelling y \u2192 (-x).relabelling (-y)\n| (mk xl xr xL xR) (mk yl yr yL yR) \u27e8L_equiv, R_equiv, L_relabelling, R_relabelling\u27e9 :=\n  \u27e8R_equiv, L_equiv,\n    \u03bb i, relabelling.neg_congr (by simpa using R_relabelling (R_equiv i)),\n    \u03bb i, relabelling.neg_congr (by simpa using L_relabelling (L_equiv.symm i))\u27e9\n\ntheorem le_iff_neg_ge : \u03a0 {x y : pgame}, x \u2264 y \u2194 -y \u2264 -x\n| (mk xl xr xL xR) (mk yl yr yL yR) :=\nbegin\n  rw [le_def],\n  rw [le_def],\n  dsimp [neg],\n  split,\n  { intro h,\n    split,\n    { intro i, have t := h.right i, cases t,\n      { right, cases t,\n        use (@right_moves_neg (yR i)).symm t_w, convert le_iff_neg_ge.1 t_h, simp },\n      { left, cases t,\n        use t_w, exact le_iff_neg_ge.1 t_h, } },\n    { intro j, have t := h.left j, cases t,\n      { right, cases t,\n        use t_w, exact le_iff_neg_ge.1 t_h, },\n      { left, cases t,\n        use (@left_moves_neg (xL j)).symm t_w, convert le_iff_neg_ge.1 t_h, simp, } } },\n  { intro h,\n    split,\n    { intro i, have t := h.right i, cases t,\n      { right, cases t,\n        use (@left_moves_neg (xL i)) t_w, convert le_iff_neg_ge.2 _, convert t_h, simp, },\n      { left, cases t,\n        use t_w, exact le_iff_neg_ge.2 t_h, } },\n    { intro j, have t := h.left j, cases t,\n      { right, cases t,\n        use t_w, exact le_iff_neg_ge.2 t_h, },\n      { left, cases t,\n        use (@right_moves_neg (yR j)) t_w, convert le_iff_neg_ge.2 _, convert t_h, simp } } },\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ntheorem neg_congr {x y : pgame} (h : x \u2248 y) : -x \u2248 -y :=\n\u27e8le_iff_neg_ge.1 h.2, le_iff_neg_ge.1 h.1\u27e9\n\ntheorem lt_iff_neg_gt : \u03a0 {x y : pgame}, x < y \u2194 -y < -x :=\nbegin\n  classical,\n  intros,\n  rw [\u2190not_le, \u2190not_le, not_iff_not],\n  apply le_iff_neg_ge\nend\n\ntheorem zero_le_iff_neg_le_zero {x : pgame} : 0 \u2264 x \u2194 -x \u2264 0 :=\nbegin\n  convert le_iff_neg_ge,\n  rw neg_zero\nend\n\ntheorem le_zero_iff_zero_le_neg {x : pgame} : x \u2264 0 \u2194 0 \u2264 -x :=\nbegin\n  convert le_iff_neg_ge,\n  rw neg_zero\nend\n\n/-- The sum of `x = {xL | xR}` and `y = {yL | yR}` is `{xL + y, x + yL | xR + y, x + yR}`. -/\ndef add (x y : pgame) : pgame :=\nbegin\n  induction x with xl xr xL xR IHxl IHxr generalizing y,\n  induction y with yl yr yL yR IHyl IHyr,\n  have y := mk yl yr yL yR,\n  refine \u27e8xl \u2295 yl, xr \u2295 yr, sum.rec _ _, sum.rec _ _\u27e9,\n  { exact \u03bb i, IHxl i y },\n  { exact \u03bb i, IHyl i },\n  { exact \u03bb i, IHxr i y },\n  { exact \u03bb i, IHyr i }\nend\n\ninstance : has_add pgame := \u27e8add\u27e9\n\n/-- `x + 0` has exactly the same moves as `x`. -/\ndef add_zero_relabelling : \u03a0 (x : pgame.{u}), relabelling (x + 0) x\n| (mk xl xr xL xR) :=\nbegin\n  refine \u27e8equiv.sum_empty xl pempty, equiv.sum_empty xr pempty, _, _\u27e9,\n  { rintro (\u27e8i\u27e9|\u27e8\u27e8\u27e9\u27e9),\n    apply add_zero_relabelling, },\n  { rintro j,\n    apply add_zero_relabelling, }\nend\n\n/-- `x + 0` is equivalent to `x`. -/\nlemma add_zero_equiv (x : pgame.{u}) : x + 0 \u2248 x :=\n(add_zero_relabelling x).equiv\n\n/-- `0 + x` has exactly the same moves as `x`. -/\ndef zero_add_relabelling : \u03a0 (x : pgame.{u}), relabelling (0 + x) x\n| (mk xl xr xL xR) :=\nbegin\n  refine \u27e8equiv.empty_sum pempty xl, equiv.empty_sum pempty xr, _, _\u27e9,\n  { rintro (\u27e8\u27e8\u27e9\u27e9|\u27e8i\u27e9),\n    apply zero_add_relabelling, },\n  { rintro j,\n    apply zero_add_relabelling, }\nend\n\n/-- `0 + x` is equivalent to `x`. -/\nlemma zero_add_equiv (x : pgame.{u}) : 0 + x \u2248 x :=\n(zero_add_relabelling x).equiv\n\n/-- An explicit equivalence between the moves for Left in `x + y` and the type-theory sum\n    of the moves for Left in `x` and in `y`. -/\ndef left_moves_add (x y : pgame) : (x + y).left_moves \u2243 x.left_moves \u2295 y.left_moves :=\nby { cases x, cases y, refl, }\n\n/-- An explicit equivalence between the moves for Right in `x + y` and the type-theory sum\n    of the moves for Right in `x` and in `y`. -/\ndef right_moves_add (x y : pgame) : (x + y).right_moves \u2243 x.right_moves \u2295 y.right_moves :=\nby { cases x, cases y, refl, }\n\n@[simp] lemma mk_add_move_left_inl {xl xr yl yr} {xL xR yL yR} {i} :\n  (mk xl xr xL xR + mk yl yr yL yR).move_left (sum.inl i) =\n    (mk xl xr xL xR).move_left i + (mk yl yr yL yR) :=\nrfl\n@[simp] lemma add_move_left_inl {x y : pgame} {i} :\n  (x + y).move_left ((@left_moves_add x y).symm (sum.inl i)) = x.move_left i + y :=\nby { cases x, cases y, refl, }\n\n@[simp] lemma mk_add_move_right_inl {xl xr yl yr} {xL xR yL yR} {i} :\n  (mk xl xr xL xR + mk yl yr yL yR).move_right (sum.inl i) =\n    (mk xl xr xL xR).move_right i + (mk yl yr yL yR) :=\nrfl\n@[simp] lemma add_move_right_inl {x y : pgame} {i} :\n  (x + y).move_right ((@right_moves_add x y).symm (sum.inl i)) = x.move_right i + y :=\nby { cases x, cases y, refl, }\n\n@[simp] lemma mk_add_move_left_inr {xl xr yl yr} {xL xR yL yR} {i} :\n  (mk xl xr xL xR + mk yl yr yL yR).move_left (sum.inr i) =\n    (mk xl xr xL xR) + (mk yl yr yL yR).move_left i :=\nrfl\n@[simp] lemma add_move_left_inr {x y : pgame} {i : y.left_moves} :\n  (x + y).move_left ((@left_moves_add x y).symm (sum.inr i)) = x + y.move_left i :=\nby { cases x, cases y, refl, }\n\n@[simp] lemma mk_add_move_right_inr {xl xr yl yr} {xL xR yL yR} {i} :\n  (mk xl xr xL xR + mk yl yr yL yR).move_right (sum.inr i) =\n    (mk xl xr xL xR) + (mk yl yr yL yR).move_right i :=\nrfl\n@[simp] lemma add_move_right_inr {x y : pgame} {i} :\n  (x + y).move_right ((@right_moves_add x y).symm (sum.inr i)) = x + y.move_right i :=\nby { cases x, cases y, refl, }\n\n/-- If `w` has the same moves as `x` and `y` has the same moves as `z`,\nthen `w + y` has the same moves as `x + z`. -/\ndef relabelling.add_congr : \u2200 {w x y z : pgame.{u}},\n  w.relabelling x \u2192 y.relabelling z \u2192 (w + y).relabelling (x + z)\n| (mk wl wr wL wR) (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR)\n  \u27e8L_equiv\u2081, R_equiv\u2081, L_relabelling\u2081, R_relabelling\u2081\u27e9\n  \u27e8L_equiv\u2082, R_equiv\u2082, L_relabelling\u2082, R_relabelling\u2082\u27e9 :=\nbegin\n  refine \u27e8equiv.sum_congr L_equiv\u2081 L_equiv\u2082, equiv.sum_congr R_equiv\u2081 R_equiv\u2082, _, _\u27e9,\n  { rintro (i|j),\n    { exact relabelling.add_congr\n        (L_relabelling\u2081 i)\n        (\u27e8L_equiv\u2082, R_equiv\u2082, L_relabelling\u2082, R_relabelling\u2082\u27e9) },\n    { exact relabelling.add_congr\n        (\u27e8L_equiv\u2081, R_equiv\u2081, L_relabelling\u2081, R_relabelling\u2081\u27e9)\n        (L_relabelling\u2082 j) }},\n  { rintro (i|j),\n    { exact relabelling.add_congr\n        (R_relabelling\u2081 i)\n        (\u27e8L_equiv\u2082, R_equiv\u2082, L_relabelling\u2082, R_relabelling\u2082\u27e9) },\n    { exact relabelling.add_congr\n        (\u27e8L_equiv\u2081, R_equiv\u2081, L_relabelling\u2081, R_relabelling\u2081\u27e9)\n        (R_relabelling\u2082 j) }}\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ninstance : has_sub pgame := \u27e8\u03bb x y, x + -y\u27e9\n\n/-- If `w` has the same moves as `x` and `y` has the same moves as `z`,\nthen `w - y` has the same moves as `x - z`. -/\ndef relabelling.sub_congr {w x y z : pgame}\n  (h\u2081 : w.relabelling x) (h\u2082 : y.relabelling z) : (w - y).relabelling (x - z) :=\nh\u2081.add_congr h\u2082.neg_congr\n\n/-- `-(x+y)` has exactly the same moves as `-x + -y`. -/\ndef neg_add_relabelling : \u03a0 (x y : pgame), relabelling (-(x + y)) (-x + -y)\n| (mk xl xr xL xR) (mk yl yr yL yR) :=\n\u27e8equiv.refl _, equiv.refl _,\n \u03bb j, sum.cases_on j\n   (\u03bb j, neg_add_relabelling (xR j) (mk yl yr yL yR))\n   (\u03bb j, neg_add_relabelling (mk xl xr xL xR) (yR j)),\n \u03bb i, sum.cases_on i\n   (\u03bb i, neg_add_relabelling (xL i) (mk yl yr yL yR))\n   (\u03bb i, neg_add_relabelling (mk xl xr xL xR) (yL i))\u27e9\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ntheorem neg_add_le {x y : pgame} : -(x + y) \u2264 -x + -y :=\n(neg_add_relabelling x y).le\n\n/-- `x+y` has exactly the same moves as `y+x`. -/\ndef add_comm_relabelling : \u03a0 (x y : pgame.{u}), relabelling (x + y) (y + x)\n| (mk xl xr xL xR) (mk yl yr yL yR) :=\nbegin\n  refine \u27e8equiv.sum_comm _ _, equiv.sum_comm _ _, _, _\u27e9;\n  rintros (_|_);\n  { simp [left_moves_add, right_moves_add], apply add_comm_relabelling }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ntheorem add_comm_le {x y : pgame} : x + y \u2264 y + x :=\n(add_comm_relabelling x y).le\n\ntheorem add_comm_equiv {x y : pgame} : x + y \u2248 y + x :=\n(add_comm_relabelling x y).equiv\n\n/-- `(x + y) + z` has exactly the same moves as `x + (y + z)`. -/\ndef add_assoc_relabelling : \u03a0 (x y z : pgame.{u}), relabelling ((x + y) + z) (x + (y + z))\n| (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR) :=\nbegin\n  refine \u27e8equiv.sum_assoc _ _ _, equiv.sum_assoc _ _ _, _, _\u27e9,\n  { rintro (\u27e8i|i\u27e9|i),\n    { apply add_assoc_relabelling, },\n    { change relabelling\n        (mk xl xr xL xR + yL i + mk zl zr zL zR) (mk xl xr xL xR + (yL i + mk zl zr zL zR)),\n      apply add_assoc_relabelling, },\n    { change relabelling\n        (mk xl xr xL xR + mk yl yr yL yR + zL i) (mk xl xr xL xR + (mk yl yr yL yR + zL i)),\n      apply add_assoc_relabelling, } },\n  { rintro (j|\u27e8j|j\u27e9),\n    { apply add_assoc_relabelling, },\n    { change relabelling\n        (mk xl xr xL xR + yR j + mk zl zr zL zR) (mk xl xr xL xR + (yR j + mk zl zr zL zR)),\n      apply add_assoc_relabelling, },\n    { change relabelling\n        (mk xl xr xL xR + mk yl yr yL yR + zR j) (mk xl xr xL xR + (mk yl yr yL yR + zR j)),\n      apply add_assoc_relabelling, } },\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ntheorem add_assoc_equiv {x y z : pgame} : (x + y) + z \u2248 x + (y + z) :=\n(add_assoc_relabelling x y z).equiv\n\ntheorem add_le_add_right : \u03a0 {x y z : pgame} (h : x \u2264 y), x + z \u2264 y + z\n| (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR) :=\nbegin\n  intros h,\n  rw le_def,\n  split,\n  { -- if Left plays first\n    intros i,\n    change xl \u2295 zl at i,\n    cases i,\n    { -- either they play in x\n      rw le_def at h,\n      cases h,\n      have t := h_left i,\n      rcases t with \u27e8i', ih\u27e9 | \u27e8j, jh\u27e9,\n      { left,\n        refine \u27e8(left_moves_add _ _).inv_fun (sum.inl i'), _\u27e9,\n        exact add_le_add_right ih, },\n      { right,\n        refine \u27e8(right_moves_add _ _).inv_fun (sum.inl j), _\u27e9,\n        convert add_le_add_right jh,\n        apply add_move_right_inl } },\n    { -- or play in z\n      left,\n      refine \u27e8(left_moves_add _ _).inv_fun (sum.inr i), _\u27e9,\n      exact add_le_add_right h, }, },\n  { -- if Right plays first\n    intros j,\n    change yr \u2295 zr at j,\n    cases j,\n    { -- either they play in y\n      rw le_def at h,\n      cases h,\n      have t := h_right j,\n      rcases t with \u27e8i, ih\u27e9 | \u27e8j', jh\u27e9,\n      { left,\n        refine \u27e8(left_moves_add _ _).inv_fun (sum.inl i), _\u27e9,\n        convert add_le_add_right ih,\n        apply add_move_left_inl },\n      { right,\n        refine \u27e8(right_moves_add _ _).inv_fun (sum.inl j'), _\u27e9,\n        exact add_le_add_right jh } },\n    { -- or play in z\n      right,\n      refine \u27e8(right_moves_add _ _).inv_fun (sum.inr j), _\u27e9,\n      exact add_le_add_right h } }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ntheorem add_le_add_left {x y z : pgame} (h : y \u2264 z) : x + y \u2264 x + z :=\ncalc x + y \u2264 y + x : add_comm_le\n     ... \u2264 z + x : add_le_add_right h\n     ... \u2264 x + z : add_comm_le\n\ntheorem add_congr {w x y z : pgame} (h\u2081 : w \u2248 x) (h\u2082 : y \u2248 z) : w + y \u2248 x + z :=\n\u27e8calc w + y \u2264 w + z : add_le_add_left h\u2082.1\n        ... \u2264 x + z : add_le_add_right h\u2081.1,\n calc x + z \u2264 x + y : add_le_add_left h\u2082.2\n        ... \u2264 w + y : add_le_add_right h\u2081.2\u27e9\n\ntheorem sub_congr {w x y z : pgame} (h\u2081 : w \u2248 x) (h\u2082 : y \u2248 z) : w - y \u2248 x - z :=\nadd_congr h\u2081 (neg_congr h\u2082)\n\ntheorem add_left_neg_le_zero : \u03a0 {x : pgame}, (-x) + x \u2264 0\n| \u27e8xl, xr, xL, xR\u27e9 :=\nbegin\n  rw [le_def],\n  split,\n  { intro i,\n    change xr \u2295 xl at i,\n    cases i,\n    { -- If Left played in -x, Right responds with the same move in x.\n      right,\n      refine \u27e8(right_moves_add _ _).inv_fun (sum.inr i), _\u27e9,\n      convert @add_left_neg_le_zero (xR i),\n      exact add_move_right_inr },\n    { -- If Left in x, Right responds with the same move in -x.\n      right,\n      dsimp,\n      refine \u27e8(right_moves_add _ _).inv_fun (sum.inl i), _\u27e9,\n      convert @add_left_neg_le_zero (xL i),\n      exact add_move_right_inl }, },\n  { rintro \u27e8\u27e9, }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ntheorem zero_le_add_left_neg : \u03a0 {x : pgame}, 0 \u2264 (-x) + x :=\nbegin\n  intro x,\n  rw [le_iff_neg_ge, neg_zero],\n  exact le_trans neg_add_le add_left_neg_le_zero\nend\n\ntheorem add_left_neg_equiv {x : pgame} : (-x) + x \u2248 0 :=\n\u27e8add_left_neg_le_zero, zero_le_add_left_neg\u27e9\n\ntheorem add_right_neg_le_zero {x : pgame} : x + (-x) \u2264 0 :=\ncalc x + (-x) \u2264 (-x) + x : add_comm_le\n     ... \u2264 0 : add_left_neg_le_zero\n\ntheorem zero_le_add_right_neg {x : pgame} : 0 \u2264 x + (-x) :=\ncalc 0 \u2264 (-x) + x : zero_le_add_left_neg\n     ... \u2264 x + (-x) : add_comm_le\n\ntheorem add_right_neg_equiv {x : pgame} : x + (-x) \u2248 0 :=\n\u27e8add_right_neg_le_zero, zero_le_add_right_neg\u27e9\n\ntheorem add_lt_add_right {x y z : pgame} (h : x < y) : x + z < y + z :=\nsuffices y + z \u2264 x + z \u2192 y \u2264 x, by { rw \u2190not_le at \u22a2 h, exact mt this h },\nassume w,\ncalc y \u2264 y + 0            : (add_zero_relabelling _).symm.le\n     ... \u2264 y + (z + -z)   : add_le_add_left zero_le_add_right_neg\n     ... \u2264 (y + z) + (-z) : (add_assoc_relabelling _ _ _).symm.le\n     ... \u2264 (x + z) + (-z) : add_le_add_right w\n     ... \u2264 x + (z + -z)   : (add_assoc_relabelling _ _ _).le\n     ... \u2264 x + 0          : add_le_add_left add_right_neg_le_zero\n     ... \u2264 x              : (add_zero_relabelling _).le\n\ntheorem add_lt_add_left {x y z : pgame} (h : y < z) : x + y < x + z :=\ncalc x + y \u2264 y + x : add_comm_le\n     ... < z + x   : add_lt_add_right h\n     ... \u2264 x + z   : add_comm_le\n\ntheorem le_iff_sub_nonneg {x y : pgame} : x \u2264 y \u2194 0 \u2264 y - x :=\n\u27e8\u03bb h, le_trans zero_le_add_right_neg (add_le_add_right h),\n \u03bb h,\n  calc x \u2264 0 + x : (zero_add_relabelling x).symm.le\n     ... \u2264 (y - x) + x : add_le_add_right h\n     ... \u2264 y + (-x + x) : (add_assoc_relabelling _ _ _).le\n     ... \u2264 y + 0 : add_le_add_left (add_left_neg_le_zero)\n     ... \u2264 y : (add_zero_relabelling y).le\u27e9\ntheorem lt_iff_sub_pos {x y : pgame} : x < y \u2194 0 < y - x :=\n\u27e8\u03bb h, lt_of_le_of_lt zero_le_add_right_neg (add_lt_add_right h),\n \u03bb h,\n  calc x \u2264 0 + x : (zero_add_relabelling x).symm.le\n     ... < (y - x) + x : add_lt_add_right h\n     ... \u2264 y + (-x + x) : (add_assoc_relabelling _ _ _).le\n     ... \u2264 y + 0 : add_le_add_left (add_left_neg_le_zero)\n     ... \u2264 y : (add_zero_relabelling y).le\u27e9\n\n/-- The pre-game `star`, which is fuzzy/confused with zero. -/\ndef star : pgame := pgame.of_lists [0] [0]\n\ntheorem star_lt_zero : star < 0 :=\nby rw lt_def; exact\nor.inr \u27e8\u27e80, zero_lt_one\u27e9, (by split; rintros \u27e8\u27e9)\u27e9\n\ntheorem zero_lt_star : 0 < star :=\nby rw lt_def; exact\nor.inl \u27e8\u27e80, zero_lt_one\u27e9, (by split; rintros \u27e8\u27e9)\u27e9\n\n/-- The pre-game `\u03c9`. (In fact all ordinals have game and surreal representatives.) -/\ndef omega : pgame := \u27e8ulift \u2115, pempty, \u03bb n, \u2191n.1, pempty.elim\u27e9\n\ntheorem zero_lt_one : (0 : pgame) < 1 :=\nbegin\n  rw lt_def,\n  left,\n  use \u27e8punit.star, by split; rintro \u27e8 \u27e9\u27e9,\nend\n\n/-- The pre-game `half` is defined as `{0 | 1}`. -/\ndef half : pgame := \u27e8punit, punit, 0, 1\u27e9\n\n@[simp] lemma half_move_left : half.move_left punit.star = 0 := rfl\n\n@[simp] lemma half_move_right : half.move_right punit.star = 1 := rfl\n\ntheorem zero_lt_half : 0 < half :=\nbegin\n  rw lt_def,\n  left,\n  use punit.star,\n  split; rintro \u27e8 \u27e9,\nend\n\ntheorem half_lt_one : half < 1 :=\nbegin\n  rw lt_def,\n  right,\n  use punit.star,\n  split; rintro \u27e8 \u27e9,\n  exact zero_lt_one,\nend\n\nend pgame\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/set_theory/pgame.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7172578065672996}}
{"text": "import Sets.Basic \n\nnamespace Func\n\nvariable { \u03b1 \u03b2 \u03b3 : Type }\n\ndef Injective (f : \u03b1 \u2192 \u03b2) : Prop := \u2200 \u2983a\u2081 a\u2082\u2984, f a\u2081 = f a\u2082 \u2192 a\u2081 = a\u2082 \n\ndef Surjective (f : \u03b1 \u2192 \u03b2) : Prop := \u2200 b, \u2203 a, f a = b \n\ndef Bijective (f : \u03b1 \u2192 \u03b2) : Prop :=  Injective f \u2227 Surjective f \n\nstructure LeftInverse (f : \u03b1 \u2192 \u03b2) where \n  to_fun : \u03b2 \u2192 \u03b1  \n  invl : to_fun \u2218 f = id \n\nstructure RightInverse (f : \u03b2 \u2192 \u03b1) where \n  to_fun : \u03b1 \u2192 \u03b2 \n  invr : f \u2218 to_fun = id \n\nstructure Inverse (f : \u03b1 \u2192 \u03b2) where \n  to_fun : \u03b2 \u2192 \u03b1  \n  invl : to_fun \u2218 f = id \n  invr : f \u2218 to_fun = id \n\ndef HasLeftInv (f : \u03b1 \u2192 \u03b2) : Prop := Nonempty (LeftInverse f) \n\ndef HasRightInv (f : \u03b1 \u2192 \u03b2) : Prop := Nonempty (RightInverse f) \n\ndef IdInv : LeftInverse (@id \u03b1) := \u27e8id,by rfl\u27e9 \n\ntheorem inj_comp {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (h\u2081 : Injective f) (h\u2082 : Injective g) : Injective (g \u2218 f) \n  := by \n    intro a\u2081 a\u2082 h\n    have (l\u2081 : f a\u2081 = f a\u2082) := h\u2082 h \n    exact h\u2081 l\u2081  \n\ntheorem surj_comp {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (h\u2081 : Surjective f) (h\u2082 : Surjective g) : Surjective (g \u2218 f) \n  := by \n    intro c \n    have \u27e8b,l\u2081\u27e9 := h\u2082 c \n    have \u27e8a,l\u2082\u27e9 := h\u2081 b \n    have : g (f a) = c := by rw [l\u2082,l\u2081] \n    exact \u27e8a,this\u27e9 \n\ntheorem comp_inj { f : \u03b1 \u2192 \u03b2 } { g : \u03b2 \u2192 \u03b3 } (h : Injective (g \u2218 f)) : Injective f := by \n  intro a\u2081 a\u2082 h\u2081 \n  have : g (f a\u2081) = g (f a\u2082) := congrArg g h\u2081 \n  exact h this \n\ntheorem comp_surj { f : \u03b1 \u2192 \u03b2 } { g : \u03b2 \u2192 \u03b3 } (h : Surjective (g \u2218 f)) : Surjective g := by \n  intro c \n  have \u27e8a,h\u2081\u27e9 : \u2203 a, g (f a) = c := h c \n  exact \u27e8f a, h\u2081\u27e9 \n\ntheorem has_left_inv_injective (f : \u03b1 \u2192 \u03b2) (h : HasLeftInv f) : Injective f := by \n  -- Introduce a pair of arguments and the assumption that \n  -- f evaluates to the same on them \n  intro (a\u2081:\u03b1) (a\u2082:\u03b1) (l\u2081: f a\u2081 = f a\u2082)\n  -- Break up the existence of a left-inverse into a function and a proof it is a\n  -- left inverse\n  have \u27e8g,l\u2082\u27e9 := h \n  -- A calculation block allows us to more efficiently perform equality manipulations\n  calc\n    a\u2081 = id a\u2081        := by rfl \n    _  = (g \u2218 f) a\u2081   := Eq.symm (congrFun l\u2082 a\u2081)\n    _  = (g \u2218 f) a\u2082   := congrArg g l\u2081 \n    _  = id a\u2082        := congrFun l\u2082 a\u2082 \n    _  = a\u2082           := by rfl \n\ndef InvtoLeftInv { f : \u03b1 \u2192 \u03b2 } (g : Inverse f) : LeftInverse f := \u27e8g.to_fun,g.invl\u27e9\n\ndef InvtoRightInv { f : \u03b1 \u2192 \u03b2 } (g : Inverse f) : RightInverse f := \u27e8g.to_fun,g.invr\u27e9\n\ntheorem left_inv_right_inv_eq { f : \u03b1 \u2192 \u03b2 } (g : LeftInverse f) (h : RightInverse f) : \n  g.to_fun = h.to_fun := by\n    apply funext \n    intro (b: \u03b2) \n    calc \n        g.to_fun b = g.to_fun (f (h.to_fun b))  := \n          congrArg g.to_fun (Eq.symm (congrFun h.invr b)) \n        _    = h.to_fun b                       := \n          congrFun g.invl (h.to_fun b)  \n\ntheorem inv_unique (f : \u03b1 \u2192 \u03b2) (g : Inverse f) (h : Inverse f) : g.to_fun = h.to_fun := by \n  calc \n    g.to_fun = (InvtoLeftInv g).to_fun    := by rfl  \n    _        = (InvtoRightInv h).to_fun   := \n      left_inv_right_inv_eq (InvtoLeftInv g) (InvtoRightInv h)   \n    _        = h.to_fun                   := by rfl \n\nnoncomputable def Section (f : \u03b1 \u2192 \u03b2) (l : Nonempty \u03b1) : \u03b2 \u2192 \u03b1 := by \n  intro (b:\u03b2)\n  have a\u2080 : \u03b1 := Classical.choice l \n  have : Decidable (\u2203 a, f a = b) := Classical.propDecidable (\u2203 a, f a = b) \n  exact if h : \u2203 a, f a = b then Classical.choose h else a\u2080 \n\ntheorem inj_has_left_inv (f : \u03b1 \u2192 \u03b2) (l : Nonempty \u03b1) (h : Injective f) : HasLeftInv f := by \n  let g : \u03b2 \u2192 \u03b1 := Section f l \n  suffices u : g \u2218 f = id from \u27e8g,u\u27e9\n  apply funext \n  intro (a:\u03b1) \n  have (v : \u2203 x, f x = f a) := by exists a \n  have (w : g (f a) = Classical.choose v) := dif_pos v   \n  calc \n    g (f a) = Classical.choose v  := w \n    _       = a                   := h (Classical.choose_spec v)\n\ntheorem surj_has_right_inv (f : \u03b1 \u2192 \u03b2) (h : Surjective f) : HasRightInv f := by \n  let g : \u03b2 \u2192 \u03b1 := by \n    intro b \n    have : \u2203 a, f a = b := h b \n    have (a : \u03b1) := Classical.choose this \n    exact a  \n  have (l : f \u2218 g = id) := by \n    apply funext \n    intro b \n    have u : g b = Classical.choose (h b) := by rfl \n    have v : f (Classical.choose (h b)) = b := Classical.choose_spec (h b)\n    calc \n      f (g b) = f (Classical.choose (h b))  := by rw [u] \n      _       = b                           := by rw [v] \n  exact \u27e8g,l\u27e9 \n\ndef empty_bijection_inverse (f : Empty \u2192 \u03b2) (h : Bijective f) : Inverse f := by \n  let g : \u03b2 \u2192 Empty := fun b => by \n    have (a : Empty) := Classical.choose (h.right b)\n    exact Empty.rec a \n  have invl : g \u2218 f = id := by \n    apply funext \n    exact fun a => Empty.rec a \n  have invr : f \u2218 g = id := funext (fun b => Empty.rec (Classical.choose (h.right b)))\n  exact \u27e8g,invl,invr\u27e9 \n\nnoncomputable def inverse (f : \u03b1 \u2192 \u03b2) (h : Bijective f) : Inverse f := \n  have : Decidable (Nonempty \u03b1) := Classical.propDecidable (Nonempty \u03b1)\n  if u : Nonempty \u03b1 then \n    have g : LeftInverse f := Classical.choice (inj_has_left_inv f u h.left) \n    have h : RightInverse f := Classical.choice (surj_has_right_inv f h.right)  \n    have : g.to_fun = h.to_fun := left_inv_right_inv_eq g h \n    have invr' : f \u2218 g.to_fun = id := by {rw [this]; exact h.invr}\n    \u27e8g.to_fun,g.invl,invr'\u27e9  \n  else by  \n    let g : \u03b2 \u2192 \u03b1 := fun b => by  \n      have (p : Nonempty \u03b1) := \u27e8Classical.choose (h.right b)\u27e9  \n      exact False.elim (u p)  \n    have invl : g \u2218 f = id := by \n      apply funext \n      exact fun a => False.elim (u (Nonempty.intro a))\n    have invr : f \u2218 g = id := funext <| fun b => by \n      have (p : Nonempty \u03b1) := \u27e8Classical.choose (h.right b)\u27e9  \n      exact False.elim (u p)\n    exact \u27e8g,invl,invr\u27e9  \n\ntheorem has_right_inv_surjective (f : \u03b1 \u2192 \u03b2) (h : HasRightInv f) : Surjective f := by\n  have \u27e8g,l\u27e9 := h \n  intro (b:\u03b2)\n  exact \u27e8g b, congrFun l b\u27e9 \n\nopen Set \n\ndef Image (f : \u03b1 \u2192 \u03b2) (X : Set \u03b1) : Set \u03b2 := fun b => \u2203 a, a \u2208 X \u2227 f a = b\n-- infix:80 \" '' \" => Image\n--\n-- declare_syntax_cat set_image\n-- syntax set_image \"[\" ident \"]\" : term\n--\n-- syntax ident : binder_construct\n--\n-- macro_rules\n-- | `({ $var:ident [ $var2:ident ]}) => `(Image ($var : $ty) ($body :term) )) \n\ndef PreImage (f : \u03b1 \u2192 \u03b2) (Y : Set \u03b2) : Set \u03b1 := fun a => f a \u2208 Y \ninfix:80 \" \u207b\u00b9 \" => PreImage\n\ntheorem image_sub (f : \u03b1 \u2192 \u03b2) { X X' : Set \u03b1 } (h : X \u2286 X')  : Image f X \u2286 Image f X' := by \n  intro b h'\n  have \u27e8a,h''\u27e9 := h' \n  exact \u27e8a,\u27e8h a h''.left,h''.right\u27e9\u27e9  \n\ntheorem preimage_sub (f : \u03b1 \u2192 \u03b2) { Y Y' : Set \u03b2 } (h : Y \u2286 Y') : f\u207b\u00b9 Y \u2286 f\u207b\u00b9 Y' := by \n  intro a h' \n  exact h (f a) h' \n\ntheorem image_preimage_sub (f : \u03b1 \u2192 \u03b2) (Y : Set \u03b2) : Image f (PreImage f Y) \u2286 Y := by \n  intro b h \n  have \u27e8a,h'\u27e9 := h \n  rw [\u2190h'.right]\n  exact h'.left \n\ntheorem sub_preimage_image (f : \u03b1 \u2192 \u03b2) (X : Set \u03b1) : X \u2286 PreImage f (Image f X) := by \n  intro a h \n  have : f a \u2208 Image f X := \u27e8a,\u27e8h,Eq.refl (f a) \u27e9\u27e9 \n  exact this\n\ntheorem union_preimage (f : \u03b1 \u2192 \u03b2) (Y Y' : Set \u03b2) : f\u207b\u00b9 (Y \u222a Y') = f\u207b\u00b9 Y \u222a f\u207b\u00b9 Y' := by rfl \n\ntheorem inter_preimage (f : \u03b1 \u2192 \u03b2) (Y Y' : Set \u03b2) : f\u207b\u00b9 (Y \u2229 Y') = f\u207b\u00b9 Y \u2229 f\u207b\u00b9 Y' := by rfl \n\ntheorem union_image (f : \u03b1 \u2192 \u03b2) (X X' : Set \u03b1) : Image f (X \u222a X') = Image f X \u222a Image f X' := by \n  set_extensionality b \n  \u00b7 intro h \n    have \u27e8a,h'\u27e9 := h \n    cases h'.left with \n    | inl hl => exact Or.inl \u27e8a,hl,h'.right\u27e9\n    | inr hr => exact Or.inr \u27e8a,hr,h'.right\u27e9 \n  \u00b7 intro h \n    cases h with \n    | inl hl => \n      have \u27e8a,h'\u27e9 := hl \n      exact \u27e8a,\u27e8Or.inl h'.left,h'.right\u27e9\u27e9 \n    | inr hr => \n      have \u27e8a,h'\u27e9 := hr \n      exact \u27e8a,\u27e8Or.inr h'.left,h'.right\u27e9\u27e9 \n\ntheorem inter_image (f : \u03b1 \u2192 \u03b2) (X X' : Set \u03b1) : Image f (X \u2229 X') \u2286 Image f X \u2229 Image f X' := by \n  intro b h \n  have \u27e8a,h'\u27e9 := h \n  exact \u27e8\u27e8a,\u27e8h'.left.left,h'.right\u27e9\u27e9,\u27e8a,\u27e8h'.left.right,h'.right\u27e9\u27e9\u27e9  \n\ndef InBijection (\u03b3 \u03b4 : Type) : Prop := \u2203 (f : \u03b3 \u2192 \u03b4), Bijective f \ninfixl:60 \" \u2245 \" => InBijection\n\ndef circ (f : \u03b1 \u2192 \u03b2) : (\u03b2 \u2192 \u03b3) \u2192 (\u03b1 \u2192 \u03b3) := fun v => v \u2218 f \n\ntheorem identity (f : \u03b1 \u2192 \u03b2) (u : \u03b2 \u2192 \u03b3) : circ f u = u \u2218 f := by rfl \n\ntheorem comp_assoc (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3) (h : \u03b3 \u2192 \u03b4) : (h \u2218 g) \u2218 f = h \u2218 g \u2218 f := by rfl \n\ntheorem bij_comp (h : \u03b1 \u2245 \u03b2) : (\u03b1 \u2192 \u03b3) \u2245 (\u03b2 \u2192 \u03b3) := by \n  have \u27e8f,h'\u27e9 := h \n  have (g : Inverse f) := inverse f h'  \n  have invl : (circ f) \u2218 (circ g.to_fun) = id := by \n    apply funext \n    intro (v: \u03b1 \u2192 \u03b3) \n    dsimp \n    rw [identity g.to_fun v, identity f (v \u2218 g.to_fun)]\n    rw [comp_assoc f g.to_fun v, g.invl] \n    rfl \n  have invr : (circ g.to_fun) \u2218 (circ f) = id := by \n    apply funext \n    intro (v: \u03b2 \u2192 \u03b3) \n    dsimp \n    rw [identity f v, identity g.to_fun (v \u2218 f)]\n    rw [comp_assoc g.to_fun f v, g.invr] \n    rfl \n  have inj : Injective (circ g.to_fun) := has_left_inv_injective (circ g.to_fun) \u27e8(circ f),invl\u27e9 \n  have surj : Surjective (circ g.to_fun) := has_right_inv_surjective (circ g.to_fun) \u27e8(circ f),invr\u27e9 \n  exact \u27e8circ g.to_fun,\u27e8inj,surj\u27e9\u27e9  \nend Func\n", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "homework10", "sha": "1cae069c793159751333e18544ee86777957388f", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework10", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework10/homework10-1cae069c793159751333e18544ee86777957388f/Functions/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7172497039177148}}
{"text": "import plane_separation_world.level05 --hide\nopen IncidencePlane --hide\n\n/-\n# Plane Separation World\n\n## Level 6: on the way to the final level (III).\n\nThis is the third of five lemmas that we need to prove before jumping into the final level of the game! You will be provided with \nits mathematical proof in paper right below. Remember that you can use all the theorem statements from the left-hand side box.\n\n## Mathematical proof in paper...\n\n**Claim:** Given a line \u2113 and the segments A\u00b7B and B\u00b7C, if both segments are on the same side of \u2113, then `A \u2209 \u2113 \u2227 B \u2209 \u2113 \u2227 C \u2209 \u2113`.\n\n**Proof:**\n\nBy the lemma `not_in_line_of_same_side_left`, since the points A and B are on the same side of \u2113, then `A \u2209 \u2113`.\n\nBy the lemma `not_in_line_of_same_side_right`, since the points A and B are on the same side of \u2113, then `B \u2209 \u2113`. \n\nBy the lemma `not_in_line_of_same_side_right`, since the points B and C are on the same side of \u2113, then `C \u2209 \u2113`. \n\nHence, we have shown that `A \u2209 \u2113 \u2227 B \u2209 \u2113 \u2227 C \u2209 \u2113`. \n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nStarting the proof by typing `repeat {split},` may get you going. In case you feel bewildered, do not hesitate\nto click on \"View source\" (located on the top right corner of the game screen) to see the solution.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B C P Q R : \u03a9} --hide\nvariables {\u2113 r s t : Line \u03a9} --hide\n\n/- Lemma :\nGiven a line \u2113 and the segments A\u00b7B and B\u00b7C, if both segments are on the same side of \u2113, then `A \u2209 \u2113 \u2227 B \u2209 \u2113 \u2227 C \u2209 \u2113`. \n-/\nlemma same_side_of_noncollinear_ne_line (hlAB : same_side \u2113 A B) (hlBC : same_side \u2113 B C) : \nA \u2209 \u2113 \u2227 B \u2209 \u2113 \u2227 C \u2209 \u2113 :=\nbegin\n  repeat {split},\n  apply not_in_line_of_same_side_left hlAB,\n  apply not_in_line_of_same_side_right hlAB,\n  apply not_in_line_of_same_side_right hlBC,\nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/plane_separation_world/level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7172496812703222}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Eric Rodriguez\n-/\n\nimport algebra.group_power.lemmas\nimport algebra.order.field\nimport data.nat.cast\nimport data.nat.choose.basic\n\n/-!\n# Inequalities for binomial coefficients\n\nThis file proves exponential bounds on binomial coefficients. We might want to add here the\nbounds `n^r/r^r \u2264 n.choose r \u2264 e^r n^r/r^r` in the future.\n\n## Main declarations\n\n* `nat.choose_le_pow`: `n.choose r \u2264 n^r / r!`\n* `nat.pow_le_choose`: `(n + 1 - r)^r / r! \u2264 n.choose r`. Beware of the fishy \u2115-subtraction.\n-/\n\nopen_locale nat\n\nvariables {\u03b1 : Type*} [linear_ordered_field \u03b1]\n\nnamespace nat\n\nlemma choose_le_pow (r n : \u2115) : (n.choose r : \u03b1) \u2264 n^r / r! :=\nbegin\n  rw le_div_iff',\n  { norm_cast,\n    rw \u2190nat.desc_factorial_eq_factorial_mul_choose,\n    exact n.desc_factorial_le_pow r },\n  exact_mod_cast r.factorial_pos,\nend\n\n-- horrific casting is due to \u2115-subtraction\nlemma pow_le_choose (r n : \u2115) : ((n + 1 - r : \u2115)^r : \u03b1) / r! \u2264 n.choose r :=\nbegin\n  rw div_le_iff',\n  { norm_cast,\n    rw [\u2190nat.desc_factorial_eq_factorial_mul_choose],\n    exact n.pow_sub_le_desc_factorial r },\n  exact_mod_cast r.factorial_pos,\nend\n\nend nat\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/nat/choose/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.717249677115573}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport set_theory.cardinal.ordinal\n\n/-!\n# Cardinality of continuum\n\nIn this file we define `cardinal.continuum` (notation: `\ud835\udd20`, localized in `cardinal`) to be `2 ^ \u2135\u2080`.\nWe also prove some `simp` lemmas about cardinal arithmetic involving `\ud835\udd20`.\n\n## Notation\n\n- `\ud835\udd20` : notation for `cardinal.continuum` in locale `cardinal`.\n-/\n\nnamespace cardinal\n\nuniverses u v\n\nopen_locale cardinal\n\n/-- Cardinality of continuum. -/\ndef continuum : cardinal.{u} := 2 ^ aleph_0.{u}\n\nlocalized \"notation `\ud835\udd20` := cardinal.continuum\" in cardinal\n\n@[simp] lemma two_power_aleph_0 : 2 ^ aleph_0.{u} = continuum.{u} := rfl\n\n@[simp] lemma lift_continuum : lift.{v} \ud835\udd20 = \ud835\udd20 :=\nby rw [\u2190two_power_aleph_0, lift_two_power, lift_aleph_0, two_power_aleph_0]\n\n/-!\n### Inequalities\n-/\n\nlemma aleph_0_lt_continuum : \u2135\u2080 < \ud835\udd20 := cantor \u2135\u2080\n\nlemma aleph_0_le_continuum : \u2135\u2080 \u2264 \ud835\udd20 := aleph_0_lt_continuum.le\n\nlemma nat_lt_continuum (n : \u2115) : \u2191n < \ud835\udd20 := (nat_lt_aleph_0 n).trans aleph_0_lt_continuum\n\nlemma mk_set_nat : #(set \u2115) = \ud835\udd20 := by simp\n\nlemma continuum_pos : 0 < \ud835\udd20 := nat_lt_continuum 0\n\nlemma continuum_ne_zero : \ud835\udd20 \u2260 0 := continuum_pos.ne'\n\nlemma aleph_one_le_continuum : aleph 1 \u2264 \ud835\udd20 :=\nby { rw \u2190succ_aleph_0, exact order.succ_le_of_lt aleph_0_lt_continuum }\n\n@[simp] theorem continuum_to_nat : continuum.to_nat = 0 :=\nto_nat_apply_of_aleph_0_le aleph_0_le_continuum\n\n@[simp] theorem continuum_to_enat : continuum.to_enat = \u22a4 :=\nto_enat_apply_of_aleph_0_le aleph_0_le_continuum\n\n/-!\n### Addition\n-/\n\n@[simp] lemma aleph_0_add_continuum : \u2135\u2080 + \ud835\udd20 = \ud835\udd20 :=\nadd_eq_right aleph_0_le_continuum aleph_0_le_continuum\n\n@[simp] lemma continuum_add_aleph_0 : \ud835\udd20 + \u2135\u2080 = \ud835\udd20 :=\n(add_comm _ _).trans aleph_0_add_continuum\n\n@[simp] lemma continuum_add_self : \ud835\udd20 + \ud835\udd20 = \ud835\udd20 :=\nadd_eq_right aleph_0_le_continuum le_rfl\n\n@[simp] lemma nat_add_continuum (n : \u2115) : \u2191n + \ud835\udd20 = \ud835\udd20 :=\nadd_eq_right aleph_0_le_continuum (nat_lt_continuum n).le\n\n@[simp] lemma continuum_add_nat (n : \u2115) : \ud835\udd20 + n = \ud835\udd20 :=\n(add_comm _ _).trans (nat_add_continuum n)\n\n/-!\n### Multiplication\n-/\n\n@[simp] lemma continuum_mul_self : \ud835\udd20 * \ud835\udd20 = \ud835\udd20 :=\nmul_eq_left aleph_0_le_continuum le_rfl continuum_ne_zero\n\n@[simp] lemma continuum_mul_aleph_0 : \ud835\udd20 * \u2135\u2080 = \ud835\udd20 :=\nmul_eq_left aleph_0_le_continuum aleph_0_le_continuum aleph_0_ne_zero\n\n@[simp] lemma aleph_0_mul_continuum : \u2135\u2080 * \ud835\udd20 = \ud835\udd20 :=\n(mul_comm _ _).trans continuum_mul_aleph_0\n\n@[simp] lemma nat_mul_continuum {n : \u2115} (hn : n \u2260 0) : \u2191n * \ud835\udd20 = \ud835\udd20 :=\nmul_eq_right aleph_0_le_continuum (nat_lt_continuum n).le (nat.cast_ne_zero.2 hn)\n\n@[simp] lemma continuum_mul_nat {n : \u2115} (hn : n \u2260 0) : \ud835\udd20 * n = \ud835\udd20 :=\n(mul_comm _ _).trans (nat_mul_continuum hn)\n\n/-!\n### Power\n-/\n\n@[simp] lemma aleph_0_power_aleph_0 : aleph_0.{u} ^ aleph_0.{u} = \ud835\udd20 :=\npower_self_eq le_rfl\n\n@[simp] lemma nat_power_aleph_0 {n : \u2115} (hn : 2 \u2264 n) : (n ^ aleph_0.{u} : cardinal.{u}) = \ud835\udd20 :=\nnat_power_eq le_rfl hn\n\n@[simp] lemma continuum_power_aleph_0 : continuum.{u} ^ aleph_0.{u} = \ud835\udd20 :=\nby rw [\u2190two_power_aleph_0, \u2190power_mul, mul_eq_left le_rfl le_rfl aleph_0_ne_zero]\n\nend cardinal\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/set_theory/cardinal/continuum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7172496747705345}}
{"text": "import .natural\nimport .integer\n\n--\n-- So here we make use of two new features, quotients and subtypes\n--\n--  Given a type \u03b1 an a property p: \u03b1 \u2192 Prop we can define a new type\n--  { a: \u03b1 // p a }, which is a type where each element is of the form\n--  \u27e8a, h\u27e9, where a : \u03b1 and h : p a.\n--\n--  Given a type \u03b1 and a relation r: \u03b1 \u2192 \u03b1 \u2192 Prop we have new properties\n--    * reflexive r := (\u2200 a : \u03b1, r a a)\n--    * symmetric r := (\u2200 a b : \u03b1, r a b \u2194 r b a)\n--    * transitive r := (\u2200 a b c : \u03b1, r a b \u2227 r b c \u2192 r a c)\n--    * equivalence r := reflexive r \u2227 symmetric r \u2227 transitive r\n--\n--  Given a type \u03b1, a relation r: \u03b1 \u2192 \u03b1 \u2192 Prop and a proof h: equivalence r\n--    * s: setoid \u03b1 is an instance which can be defined as \u27e8r, h\u27e9\n--    * and this defines a new type quotient s\n--    * given any a : \u03b1 we have \u27e6a\u27e7 : quotient s\n--    * given any a b : \u03b1 we have the notation a \u2248 b := r a b\n--    * given any a b : \u03b1 quotient.sound is a proof a \u2248 b \u2192 \u27e6a\u27e7 = \u27e6b\u27e7\n--    * given any a b : \u03b1 quotient.exact is a proof \u27e6a\u27e7 = \u27e6b\u27e7 \u2192 a \u2248 b\n--    * given any f: \u03b1 \u2192 \u03b1 and a proof h: \u2200 a b : \u03b1, a \u2248 b \u2192 f a \u2248 f b then\n--      given x : quotient s, then quotient.lift_on x f h : quotient s, defined\n--      such that quotient.lift_on \u27e6a\u27e7 f h = \u27e6f a\u27e7\n--    * given any p: (quotient s) \u2192 Prop and a proof h: \u2200 a : \u03b1, p \u27e6a\u27e7 then\n--      for any x : (quotient s), quotient.induction_on x h is a proof of p x\n--\n--   quotient.lift_on\u2082 and quotient.lift_on\u2083 are shorthands for using quotient.lift_on\n--   repeatedly on a function \u03b1 \u2192 \u03b1 \u2192 \u03b1 or \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 \u03b1 respectively.\n--\n\n-- Here we go! Fractions!\n\nstructure int_nat_pair := (n: \ud835\udc19) (d: \ud835\udc0d)\n\ndef fraction := {x: int_nat_pair // (x.d \u2260 0)}\n\nnamespace fraction\n\nopen fraction\n\ndef n: fraction \u2192 \ud835\udc19 := \u03bb x: fraction, x.val.n\n\ndef d: fraction \u2192 \ud835\udc0d := \u03bb x: fraction, x.val.d\n\ndef nz (x: fraction): (x.d \u2260 0) := x.2\n\nprotected lemma eq: \u2200 {x y : fraction}, x.n = y.n \u2192 x.d = y.d \u2192 x = y\n| \u27e8\u27e8xn, xd\u27e9, hx\u27e9 \u27e8\u27e8.(xn), .(xd)\u27e9, hy\u27e9 rfl rfl := rfl\n\ndef equiv (x y: fraction): Prop := x.n * y.d = y.n * x.d\n\nlemma equiv_refl: reflexive equiv := assume x: fraction, eq.refl (x.n * x.d)\n\nlemma equiv_symm: symmetric equiv :=\n    assume x y: fraction,\n    assume h: x.n * \u2191y.d = y.n * \u2191x.d,\n    eq.symm h\n\nlemma equiv_trans: transitive equiv :=\n    assume x y z: fraction,\n    assume hxy: x.n * \u2191y.d = y.n * \u2191x.d,\n    assume hyz: y.n * \u2191z.d = z.n * \u2191y.d,\n    have hnz: (integer.from_natural y.d) \u2260 0, from\n        assume hc,\n        have y.d = 0, by injection hc,\n        absurd this y.nz,\n    if hyn: y.n = 0 then\n        have hxy: x.n * \u2191y.d = 0 * \u2191y.d, from calc\n            x.n * \u2191y.d = y.n * \u2191x.d  : by rw hxy\n            ...        = 0 * \u2191x.d    : by rw hyn\n            ...        = 0           : by rw integer.zero_mult\n            ...        = 0 * \u2191y.d    : by rw integer.zero_mult,\n        have hyz: z.n * \u2191y.d = 0 * \u2191y.d, from calc\n            z.n * \u2191y.d = y.n * \u2191z.d  : by rw hyz\n            ...        = 0 * \u2191z.d    : by rw hyn\n            ...        = 0           : by rw integer.zero_mult\n            ...        = 0 * \u2191y.d    : by rw integer.zero_mult,\n        have hxy: x.n = 0, from integer.mult_elim_right hnz hxy,\n        have hyz: z.n = 0, from integer.mult_elim_right hnz hyz,\n        calc\n            x.n * \u2191z.d = 0 * \u2191z.d   : by rw hxy\n            ...        = 0          : by rw integer.zero_mult\n            ...        = 0 * \u2191x.d   : by rw integer.zero_mult\n            ...        = z.n * \u2191x.d : by rw hyz\n    else\n        have y.n * \u2191y.d \u2260 0, from\n            assume hc: y.n * \u2191y.d = 0,\n            have hc: y.n * \u2191y.d = 0 * \u2191y.d, from\n                calc\n                    y.n * \u2191y.d = 0        : by rw hc\n                    ...        = \u2191y.d * 0 : by rw integer.mult_zero \u2191y.d\n                    ...        = 0 * \u2191y.d : by rw integer.mul_com \u2191y.d,\n            have y.n = 0, from integer.mult_elim_right hnz hc,\n            absurd \u2039y.n = 0\u203a hyn,\n        suffices (x.n * \u2191z.d) * (y.n * \u2191y.d) = (z.n * \u2191x.d) * (y.n * \u2191y.d), from integer.mult_elim_right \u2039y.n * \u2191y.d \u2260 0\u203a this,\n        calc\n            (x.n * \u2191z.d) * (y.n * \u2191y.d) = (x.n * \u2191y.d) * (y.n * \u2191z.d)  : by rw [integer.mul_com y.n, integer.mul_asoc, \u2190integer.mul_asoc x.n, integer.mul_com (\u2191z.d), integer.mul_asoc, \u2190integer.mul_asoc, integer.mul_com (\u2191z.d)]\n            ...                         = (y.n * \u2191x.d) * (z.n * \u2191y.d)  : by rw [hxy, hyz]\n            ...                         = (z.n * \u2191x.d) * (y.n * \u2191y.d)  : by rw [integer.mul_asoc, \u2190integer.mul_asoc y.n, integer.mul_com (\u2191x.d), integer.mul_com y.n, integer.mul_asoc]\n\nlemma equiv_equiv: equivalence equiv := \u27e8equiv_refl, equiv_symm, equiv_trans\u27e9\n\ninstance fraction_setoid: setoid fraction := \u27e8equiv, equiv_equiv\u27e9\n\ninstance equiv_decidable: \u2200 x y: fraction, decidable (x \u2248 y) :=\n    assume x y: fraction,\n    if h: x.n*y.d = y.n*x.d then\n        is_true h\n    else\n        is_false h\n\ndef add (x y: fraction): fraction := \u27e8\u27e8((x.n * y.d) + (y.n * x.d)), (x.d*y.d)\u27e9, natural.mult_nz x.nz y.nz\u27e9\ninstance fraction_has_add: has_add fraction  := \u27e8add\u27e9\n\nlemma add_asoc (x y z : fraction): (x + y) + z = x + (y + z) :=\nhave hn: ((x + y) + z).n = (x + (y + z)).n, from (\n    calc\n        ((x + y) + z).n = (x+y).n*z.d + z.n*(x+y).d                    : by refl\n        ...             = (x.n*y.d + y.n*x.d)*z.d + z.n*(x.d*y.d)      : by refl\n        ...             = x.n*y.d*z.d + y.n*x.d*z.d + z.n*x.d*y.d      : by simp only [integer.add_mult, integer.mul_asoc]\n        ...             = x.n*(y.d*z.d) + (y.n*x.d*z.d + z.n*x.d*y.d)  : by rw [integer.add_asoc, integer.mul_asoc]\n        ...             = x.n*(y.d*z.d) + (y.n*z.d*x.d + z.n*y.d*x.d)  : by rw [\u2190integer.mul_asoc y.n, integer.mul_com x.d, integer.mul_asoc y.n, \u2190integer.mul_asoc z.n, integer.mul_com x.d, integer.mul_asoc z.n]\n        ...             = x.n*(y.d*z.d) + (y.n*z.d + z.n*y.d)*x.d      : by rw integer.add_mult\n        ...             = x.n*(y + z).d + (y + z).n*x.d                : by refl\n        ...             = (x + (y + z)).n                              : by refl\n),\nhave hd: ((x + y) + z).d = (x + (y + z)).d, from (show x.d*y.d*z.d = x.d*(y.d*z.d), by rw natural.mult_asoc),\nfraction.eq hn hd\n\n\nlemma add_com (x y : fraction): x + y = y + x :=\nhave hn: (x + y).n = (y + x).n, from (show x.n*y.d + y.n*x.d = y.n*x.d + x.n*y.d, by rw integer.add_com),\nhave hd: (x + y).d = (y + x).d, from (show x.d*y.d = y.d*x.d, by rw natural.mult_com),\nfraction.eq hn hd\n\nlemma add_invariant (x\u2081 y\u2081 x\u2082 y\u2082: fraction): x\u2081 \u2248 x\u2082 \u2192 y\u2081 \u2248 y\u2082 \u2192 \u27e6x\u2081+y\u2081\u27e7 = \u27e6x\u2082+y\u2082\u27e7 :=\n    assume hx: x\u2081.n * x\u2082.d = x\u2082.n * x\u2081.d,\n    assume hy: y\u2081.n * y\u2082.d = y\u2082.n * y\u2081.d,\n    suffices (x\u2081+y\u2081).n * (x\u2082+y\u2082).d = (x\u2082+y\u2082).n * (x\u2081+y\u2081).d, from quotient.sound this,\n    calc\n        (x\u2081+y\u2081).n * (x\u2082+y\u2082).d = ((x\u2081.n * y\u2081.d) + (y\u2081.n * x\u2081.d)) * (x\u2082.d * y\u2082.d)            : by refl\n        ...                   = (x\u2081.n * y\u2081.d)*(x\u2082.d * y\u2082.d) + (y\u2081.n * x\u2081.d)*(x\u2082.d * y\u2082.d)  : by rw integer.add_mult\n        ...                   = (x\u2081.n * y\u2081.d)*(x\u2082.d * y\u2082.d) + (y\u2081.n * x\u2081.d)*(y\u2082.d * x\u2082.d)  : by rw integer.mul_com x\u2082.d\n        ...                   = ((x\u2081.n * y\u2081.d)*x\u2082.d)*y\u2082.d + ((y\u2081.n * x\u2081.d)*y\u2082.d)*x\u2082.d      : by rw [integer.mul_asoc, integer.mul_asoc]\n        ...                   = (x\u2081.n*(y\u2081.d*x\u2082.d))*y\u2082.d + (y\u2081.n*(x\u2081.d*y\u2082.d))*x\u2082.d          : by rw [integer.mul_asoc, integer.mul_asoc]\n        ...                   = (x\u2081.n*(x\u2082.d*y\u2081.d))*y\u2082.d + (y\u2081.n*(y\u2082.d*x\u2081.d))*x\u2082.d          : by rw [integer.mul_com (y\u2081.d), integer.mul_com (x\u2081.d)]\n        ...                   = (x\u2081.n*x\u2082.d)*(y\u2081.d*y\u2082.d) + (y\u2081.n*y\u2082.d)*(x\u2081.d*x\u2082.d)          : by rw [integer.mul_asoc, integer.mul_asoc, integer.mul_asoc, integer.mul_asoc]\n        ...                   = (x\u2082.n*x\u2081.d)*(y\u2081.d*y\u2082.d) + (y\u2082.n*y\u2081.d)*(x\u2081.d*x\u2082.d)          : by rw [hx, hy]\n        ...                   = (x\u2082.n*y\u2082.d)*(x\u2081.d*y\u2081.d) + (y\u2082.n*y\u2081.d)*(x\u2081.d*x\u2082.d)          : by rw [integer.mul_com y\u2081.d, integer.mul_asoc, \u2190integer.mul_asoc x\u2082.n, integer.mul_com x\u2081.d, integer.mul_asoc, \u2190integer.mul_asoc]\n        ...                   = (x\u2082.n*y\u2082.d)*(x\u2081.d*y\u2081.d) + (y\u2082.n*y\u2081.d)*(x\u2082.d*x\u2081.d)          : by rw [\u2190integer.mul_com x\u2081.d]\n        ...                   = (x\u2082.n*y\u2082.d)*(x\u2081.d*y\u2081.d) + (y\u2082.n*x\u2082.d)*(x\u2081.d*y\u2081.d)          : by rw [integer.mul_asoc (y\u2082.n*y\u2081.d), \u2190integer.mul_asoc y\u2082.n, integer.mul_com y\u2081.d, integer.mul_asoc y\u2082.n, \u2190integer.mul_asoc (y\u2082.n*x\u2082.d), integer.mul_com y\u2081.d]\n        ...                   = ((x\u2082.n*y\u2082.d)+(y\u2082.n*x\u2082.d))*(x\u2081.d*y\u2081.d)                      : by rw integer.add_mult\n        ...                   = (x\u2082+y\u2082).n * (x\u2081+y\u2081).d                                      : by refl\n\n\ndef neg (x: fraction): fraction := \u27e8\u27e8-x.n, x.d\u27e9, x.nz\u27e9\ninstance fraction_has_neg: has_neg fraction  := \u27e8neg\u27e9\n\nlemma neg_invariant (x y: fraction): x \u2248 y \u2192 \u27e6-x\u27e7 = \u27e6-y\u27e7 :=\n    assume h: x.n * y.d = y.n * x.d,\n    suffices -x.n * y.d = -y.n * x.d, from quotient.sound this,\n    calc\n        -x.n * y.d = -(x.n * y.d)  : by rw integer.neg_mult\n        ...        = -(y.n * x.d)  : by rw h\n        ...        = -y.n * x.d    : by rw integer.neg_mult\n\nlemma neg_neg (x: fraction): -(-x) = x :=\n    suffices (-(-x)).n = x.n, from fraction.eq this rfl,\n    show -(-x.n) = x.n, by rw \u2190integer.neg_neg x.n\n\n#check integer.to_UnitRing.mul_one\n\nlemma neg_add (x: fraction): -x + x \u2248 \u27e8\u27e80, 1\u27e9, assume h, natural.no_confusion h\u27e9 :=\ncalc\n    ((-(x.n))*\u2191x.d + x.n*\u2191x.d)*1  = (-(x.n))*\u2191x.d + x.n*\u2191x.d      : by rw integer.to_UnitRing.mul_one\n    ...                           = (-(x.n) + x.n)*\u2191x.d           : by rw \u2190integer.to_Ring.add_mul\n    ...                           = (0)*\u2191x.d                      : by rw integer.to_Ring.neg_add\n    ...                           = 0                             : by rw integer.to_Ring.zero_mul\n    ...                           = 0*(-x + x).d                  : by rw integer.to_Ring.zero_mul\n\ndef mult (x y: fraction): fraction := \u27e8\u27e8x.n * y.n, x.d * y.d\u27e9, natural.mult_nz x.nz y.nz\u27e9\ninstance fraction_has_mult: has_mul fraction := \u27e8mult\u27e9\n\nlemma mult_invariant (x\u2081 y\u2081 x\u2082 y\u2082: fraction): x\u2081 \u2248 x\u2082 \u2192 y\u2081 \u2248 y\u2082 \u2192 \u27e6x\u2081*y\u2081\u27e7 = \u27e6x\u2082*y\u2082\u27e7 :=\n    assume hx: x\u2081.n * x\u2082.d = x\u2082.n * x\u2081.d,\n    assume hy: y\u2081.n * y\u2082.d = y\u2082.n * y\u2081.d,\n    suffices (x\u2081.n*y\u2081.n)*(x\u2082.d*y\u2082.d) = (x\u2082.n*y\u2082.n)*(x\u2081.d*y\u2081.d), from quotient.sound this,\n    calc\n        (x\u2081.n*y\u2081.n)*(x\u2082.d*y\u2082.d) = (x\u2081.n*x\u2082.d)*(y\u2081.n*y\u2082.d)  : by simp\n        ...                     = (x\u2082.n*x\u2081.d)*(y\u2082.n*y\u2081.d)  : by rw [hx, hy]\n        ...                     = (x\u2082.n*y\u2082.n)*(x\u2081.d*y\u2081.d)  : by simp\n\nlemma mult_asoc (x y z: fraction): (x * y) * z = x * (y * z) :=\n    have hn: ((x*y)*z).n = (x*(y*z)).n, from (show (x.n*y.n)*z.n = x.n*(y.n*z.n), by rw integer.mul_asoc),\n    have hd: ((x*y)*z).d = (x*(y*z)).d, from (show (x.d*y.d)*z.d = x.d*(y.d*z.d), by rw natural.mult_asoc),\n    fraction.eq hn hd\n\nlemma mult_com (x y: fraction): x * y = y * x :=\n    have hn: (x*y).n = (y*x).n, from (show x.n*y.n = y.n*x.n, by rw integer.mul_com),\n    have hd: (x*y).d = (y*x).d, from (show x.d*y.d = y.d*x.d, by rw natural.mult_com),\n    fraction.eq hn hd\n\ndef non_zero_fraction := {f: fraction // (f.n \u2260 0)}\ndef inv (x: non_zero_fraction): non_zero_fraction :=\n    have (integer.sgn x.val.n) * x.val.d \u2260 0, from integer.nz_mult_nz_nz (mt (iff.elim_right integer.sgn_zero) x.property) (integer.nz_impl_coe_nz x.val.nz),\n    \u27e8\u27e8\u27e8(integer.sgn x.val.n) * x.val.d, integer.abs x.val.n\u27e9, mt (iff.elim_right integer.abs_zero) x.property\u27e9, by assumption\u27e9\n\nlemma inv_invariant {x y: non_zero_fraction}: x.val \u2248 y.val \u2192 (inv x).val \u2248 (inv y).val :=\n    assume h: x.val.n*y.val.d = y.val.n*x.val.d,\n    have hsgn: integer.sgn x.val.n = integer.sgn y.val.n, from (\n        calc\n            integer.sgn x.val.n = integer.sgn (x.val.n * y.val.d)   : by rw integer.sgn_mult_nat y.val.nz\n            ...                 = integer.sgn (y.val.n * x.val.d)   : by rw h\n            ...                 = integer.sgn y.val.n               : by rw \u2190integer.sgn_mult_nat x.val.nz\n    ),\n    calc\n        (inv x).val.n*(inv y).val.d = (integer.sgn x.val.n * x.val.d)*(integer.abs y.val.n)  : by refl\n        ...                         = (integer.sgn x.val.n * integer.abs y.val.n) * x.val.d  : by rw [\u2190integer.mul_asoc, integer.mul_com (x.val.d), integer.mul_asoc]\n        ...                         = (integer.sgn y.val.n * integer.abs y.val.n) * x.val.d  : by rw [hsgn]\n        ...                         = y.val.n * x.val.d                                      : by rw integer.sgn_mult_abs\n        ...                         = x.val.n * y.val.d                                      : by rw h\n        ...                         = (integer.sgn x.val.n * integer.abs x.val.n) * y.val.d  : by rw integer.sgn_mult_abs\n        ...                         = (integer.sgn y.val.n * integer.abs x.val.n) * y.val.d  : by rw hsgn\n        ...                         = (integer.sgn y.val.n * y.val.d) * integer.abs x.val.n  : by rw [\u2190integer.mul_asoc, \u2190integer.mul_com (y.val.d), integer.mul_asoc]\n        ...                         = (inv y).val.n*(inv x).val.d                            : by refl\n\ndef over_one (x: \ud835\udc19): fraction := \u27e8\u27e8x, 1\u27e9, assume h, natural.no_confusion h\u27e9\n\nlemma int_mult (a: \ud835\udc19) (y: fraction): (over_one a) * y = \u27e8\u27e8a*y.n, y.d\u27e9, y.nz\u27e9 := show (\u27e8\u27e8a*y.n, 1*y.d\u27e9, natural.mult_nz (assume h, natural.no_confusion h) (y.nz)\u27e9 : fraction) = \u27e8\u27e8a*y.n, y.d\u27e9, y.nz\u27e9, from fraction.eq (rfl) (natural.one_mult y.d)\n\nend fraction\n\n\ndef rational: Type := quotient fraction.fraction_setoid\n\nnotation `\ud835\udc10` := rational\n\nnamespace rational\n\nopen rational\n\nnotation n `\u00f7` d := \u27e6\u27e8\u27e8n, d\u27e9, (assume h, natural.no_confusion h)\u27e9\u27e7\n\ninstance has_coe_integer_rational: has_coe integer rational := \u27e8assume n: \ud835\udc19, (n \u00f7 1)\u27e9\n\ndef zero : \ud835\udc10 := \u2191(0: \ud835\udc19)\ndef one  : \ud835\udc10 := \u2191(1: \ud835\udc19)\n\ninstance rational_has_zero: has_zero rational := \u27e8zero\u27e9\ninstance rational_has_one: has_one rational := \u27e8one\u27e9\ninstance rational_has_zero_: has_zero (quotient fraction.fraction_setoid) := \u27e8zero\u27e9\ninstance rational_has_one_: has_one (quotient fraction.fraction_setoid) := \u27e8one\u27e9\n\n\ninstance rational_of_fraction_decidable_equality (x y : fraction): decidable (\u27e6x\u27e7 = \u27e6y\u27e7) :=\n    if h: x \u2248 y then is_true (quotient.sound h) else is_false (mt quotient.exact h)\n\nprotected lemma eq {x y: fraction} (h: x.n*y.d = y.n*x.d): \u27e6x\u27e7 = \u27e6y\u27e7 := suffices x \u2248 y, from quotient.sound this, h\n\nlemma eq_zero {x: fraction}: \u27e6x\u27e7 = 0 \u2194 x.n = 0 :=\niff.intro (\n    assume h: \u27e6x\u27e7 = 0,\n    have h: x \u2248 \u27e8\u27e80, 1\u27e9, (assume h, natural.no_confusion h)\u27e9, from quotient.exact h,\n    have h: x.n*1 = 0*x.d, from h,\n    show x.n = 0, by rw [\u2190integer.mult_one x.n, h, integer.zero_mult]\n) (\n    assume h: x.n = 0,\n    suffices x \u2248 \u27e8\u27e80, 1\u27e9, (assume h, natural.no_confusion h)\u27e9, from quotient.sound this,\n    show x.n*1 = 0*x.d, by rw [integer.mult_one, h, integer.zero_mult]\n)\n\nlemma zero_ne_one: rational.zero \u2260 rational.one :=\n    assume h: (0 : rational) = \u27e6\u27e8\u27e81, 1\u27e9, assume h, natural.no_confusion h\u27e9\u27e7,\n    have h: fraction.n (\u27e8\u27e81, 1\u27e9, assume h, natural.no_confusion h\u27e9 : fraction) = 0, from iff.elim_left eq_zero (eq.symm h),\n    have h: (1 : \ud835\udc19) = 0, from h,\n    have h: (1 : \ud835\udc0d) = 0, by injection h,\n    natural.no_confusion h\n\n-- addition\n\ndef add (x y: \ud835\udc10): \ud835\udc10 := quotient.lift_on\u2082 x y (\u03bb f g: fraction, \u27e6f + g\u27e7) fraction.add_invariant\ninstance rational_has_add: has_add rational := \u27e8add\u27e9\ninstance rational_has_add_: has_add (quotient fraction.fraction_setoid) := \u27e8add\u27e9\n\nlemma add_asoc (x y z: \ud835\udc10): (x + y) + z = x + (y + z) := quotient.induction_on\u2083 x y z (assume a b c: fraction, show \u27e6(a+b)+c\u27e7 = \u27e6a+(b+c)\u27e7, by rw fraction.add_asoc)\nlemma add_com (x y: \ud835\udc10): x + y = y + x := quotient.induction_on\u2082 x y (assume a b: fraction, show \u27e6a+b\u27e7 = \u27e6b+a\u27e7, by rw fraction.add_com)\nlemma zero_add (x: \ud835\udc10): 0 + x = x := quotient.induction_on x (\n    assume \u27e8\u27e8n, d\u27e9, hnz\u27e9,\n    suffices (\u27e8\u27e80, 1\u27e9, assume h, natural.no_confusion h\u27e9 + \u27e8\u27e8n, d\u27e9, hnz\u27e9 : fraction) \u2248 \u27e8\u27e8n, d\u27e9, hnz\u27e9, from quotient.sound this,\n    suffices (\u27e8\u27e80, 1\u27e9, assume h, natural.no_confusion h\u27e9 + \u27e8\u27e8n, d\u27e9, hnz\u27e9 : fraction) = \u27e8\u27e8n, d\u27e9, hnz\u27e9, from (eq.symm this) \u25b8 (fraction.equiv_refl \u27e8\u27e8n, d\u27e9, hnz\u27e9),\n    suffices (\u27e8\u27e80, 1\u27e9, assume h, natural.no_confusion h\u27e9 + \u27e8\u27e8n, d\u27e9, hnz\u27e9 : fraction).n = n \u2227 (\u27e8\u27e80, 1\u27e9, assume h, natural.no_confusion h\u27e9 + \u27e8\u27e8n, d\u27e9, hnz\u27e9 : fraction).d = d, from fraction.eq this.left this.right,\n    and.intro (\n        calc\n            (\u27e8\u27e80, 1\u27e9, assume h, natural.no_confusion h\u27e9 + \u27e8\u27e8n, d\u27e9, hnz\u27e9 : fraction).n = 0*d + n*1  : by refl\n            ...                                                                       = 0 + n*1    : by rw integer.to_Ring.zero_mul\n            ...                                                                       = n*1        : by rw integer.to_Ring.zero_add\n            ...                                                                       = n          : by rw integer.to_UnitRing.mul_one\n    ) (\n        calc\n            (\u27e8\u27e80, 1\u27e9, assume h, natural.no_confusion h\u27e9 + \u27e8\u27e8n, d\u27e9, hnz\u27e9 : fraction).d = 1*d  : by refl\n            ...                                                                       = d    : by rw natural.one_mult\n    )\n)\n\n-- negation\n\ndef neg (x : \ud835\udc10): \ud835\udc10 := quotient.lift_on x (\u03bb f:fraction, \u27e6-f\u27e7) fraction.neg_invariant\ninstance rational_has_neg: has_neg rational := \u27e8neg\u27e9\n\nlemma neg_neg (x : \ud835\udc10): -(-x) = x := quotient.induction_on x (assume a: fraction, show \u27e6-(-a)\u27e7 = \u27e6a\u27e7, by rw fraction.neg_neg)\nlemma neg_add (x : \ud835\udc10): -x + x = 0 := quotient.induction_on x (\n    assume a: fraction,\n    suffices -a + a \u2248 \u27e8\u27e80, 1\u27e9, (assume h, natural.no_confusion h)\u27e9, from quotient.sound this,\n    fraction.neg_add a\n)\n\n-- subtraction\n\ndef sub (x y: \ud835\udc10): \ud835\udc10 := x + -y\n\n-- multiplication\n\ndef mult (x y: \ud835\udc10): \ud835\udc10 := quotient.lift_on\u2082 x y (\u03bb f g: fraction, \u27e6f*g\u27e7) fraction.mult_invariant\ninstance rational_has_mult: has_mul rational := \u27e8mult\u27e9\ninstance rational_has_mult_: has_mul (quotient fraction.fraction_setoid) := \u27e8mult\u27e9\n\nlemma mult_asoc (x y z: \ud835\udc10): (x*y)*z = x*(y*z) := quotient.induction_on\u2083 x y z (assume a b c: fraction, show \u27e6(a*b)*c\u27e7 = \u27e6a*(b*c)\u27e7, by rw fraction.mult_asoc)\nlemma mult_com (x y: \ud835\udc10): x*y = y*x := quotient.induction_on\u2082 x y (assume a b: fraction, show \u27e6a*b\u27e7 = \u27e6b*a\u27e7, by rw fraction.mult_com)\n\nlemma one_mult (x: \ud835\udc10): 1*x = x := quotient.induction_on x (\n    assume y,\n    show \u27e6(fraction.over_one 1) * y\u27e7 = \u27e6y\u27e7, from\n    suffices (\u27e6\u27e8\u27e81*y.n, y.d\u27e9, y.nz\u27e9\u27e7 : rational) = \u27e6y\u27e7, from calc\n        \u27e6(fraction.over_one 1) * y\u27e7 = \u27e6\u27e8\u27e81*y.n, y.d\u27e9, y.nz\u27e9\u27e7 : by rw \u2190fraction.int_mult 1\n        ...                        =  \u27e6y\u27e7  : by rw this\n    ,\n    rational.eq (\n        show 1 * y.n * y.d = y.n * y.d, by rw integer.to_UnitRing.one_mul\n    )\n)\nlemma mult_add (x y z: \ud835\udc10): z*(x + y) = z*x + z*y := quotient.induction_on\u2083 x y z (\n    assume a b c : fraction,\n    show \u27e6c * (a + b)\u27e7 = \u27e6c*a + c*b\u27e7, from\n    suffices (c* (a + b)).n * (c*a + c*b).d = (c*a + c*b).n * (c* (a + b)).d, from rational.eq this,\n    calc\n        (c* (a + b)).n * (c*a + c*b).d = (c.n * (a.n*b.d + b.n*a.d)) * ((c.d*a.d)*(c.d*b.d))         : by refl\n        ...                            = (c.n*(a.n*b.d) + c.n*(b.n*a.d)) * ((c.d*a.d)*(c.d*b.d))     : by rw Ring.mul_add\n        ...                            = ((c.n*a.n)*b.d + (c.n*b.n)*a.d) * ((c.d*a.d)*(c.d*b.d))     : by rw [Ring.mul_assoc \ud835\udc19 c.n, Ring.mul_assoc \ud835\udc19 c.n]\n        ...                            = (((c.n*a.n)*b.d + (c.n*b.n)*a.d) * c.d)*(a.d*(c.d*b.d))     : by rw [Ring.mul_assoc \ud835\udc19 c.d, Ring.mul_assoc \ud835\udc19 ((c.n*a.n)*b.d + (c.n*b.n)*a.d)]\n        ...                            = ((c.n*a.n)*b.d*c.d + (c.n*b.n)*a.d*c.d)*(a.d*(c.d*b.d))     : by rw [Ring.add_mul]\n        ...                            = ((c.n*a.n)*(b.d*c.d) + (c.n*b.n)*(a.d*c.d))*(a.d*(c.d*b.d)) : by rw [Ring.mul_assoc \ud835\udc19, Ring.mul_assoc \ud835\udc19 (c.n*b.n)]\n        ...                            = ((c.n*a.n)*(c.d*b.d) + (c.n*b.n)*(c.d*a.d))*(a.d*(c.d*b.d)) : by rw [CommRing.mul_comm \ud835\udc19 b.d, CommRing.mul_comm \ud835\udc19 a.d]\n        ...                            = ((c*a).n*(c*b).d + (c*b).n*(c*a).d)*(a.d*(c.d*b.d))         : by refl\n        ...                            = (c*a + c*b).n*(a.d*(c.d*b.d))                               : by refl\n        ...                            = (c*a + c*b).n*((a.d*c.d)*b.d)                               : by rw [Ring.mul_assoc \ud835\udc19]\n        ...                            = (c*a + c*b).n*((c.d*a.d)*b.d)                               : by rw [CommRing.mul_comm \ud835\udc19 a.d]\n        ...                            = (c*a + c*b).n*(c.d*(a.d*b.d))                               : by rw [Ring.mul_assoc \ud835\udc19]\n        ...                            = (c*a + c*b).n * (c* (a + b)).d                              : by refl\n)\nlemma no_zero_divisors (x y : \ud835\udc10): x*y = 0 \u2192 x \u2260 0 \u2192 y = 0 := quotient.induction_on\u2082 x y (\n    assume a b : fraction,\n    assume h: \u27e6a * b\u27e7 = 0,\n    assume ha: \u27e6a\u27e7 \u2260 0,\n    have h: (a * b).n = 0, from iff.elim_left eq_zero h,\n    have h: a.n * b.n = 0, from h,\n    have ha: a.n \u2260 0, from (mt (iff.elim_right eq_zero)) ha,\n    suffices b.n = 0, from iff.elim_right eq_zero this,\n    integer.to_NZDRing.no_zero_divisors h ha\n)\n\n-- inverse\n\nprivate def inv_frac_rat (a: fraction) : \ud835\udc10 :=\nif h: a.n = 0 then\n    (0: \ud835\udc10)\nelse\n    \u27e6(fraction.inv \u27e8a, h\u27e9).val\u27e7\n\nlemma inv_frac_rat_nz (x: fraction): (x.n \u2260 0) \u2192 inv_frac_rat x = \u27e6(fraction.inv \u27e8x, \u2039x.n \u2260 0\u203a\u27e9).val\u27e7 :=\nmatch x with\n| \u27e8\u27e80, d\u27e9, h\u27e9                          := assume h, absurd (eq.refl 0) h\n| \u27e8\u27e8integer.from_natural (n+1), d\u27e9, h\u27e9 := assume h, by refl\n| \u27e8\u27e8-[n+1], d\u27e9, h\u27e9                     := assume h, by refl\nend\n\nlemma inv_frac_rat_invariant (a b: fraction): a \u2248 b \u2192 inv_frac_rat a = inv_frac_rat b :=\nassume h: a.n*b.d = b.n*a.d,\nif ha: a.n = 0 then\n    have hb: b.n = 0, from (\n        suffices b.n*a.d = 0, from integer.mult_nz_eq_z_imp_z this (integer.nz_impl_coe_nz a.nz),\n        calc\n            b.n*a.d = a.n*b.d  : by rw h\n            ...     = 0*b.d    : by rw ha\n            ...     = 0        : by rw integer.zero_mult\n    ),\n    calc\n        inv_frac_rat a = inv_frac_rat \u27e8\u27e8a.n, a.d\u27e9, a.nz\u27e9  : by refl\n        ...            = inv_frac_rat \u27e8\u27e80, a.d\u27e9, a.nz\u27e9    : by rw ha\n        ...            = 0                                : by refl\n        ...            = inv_frac_rat \u27e8\u27e80, b.d\u27e9, b.nz\u27e9    : by refl\n        ...            = inv_frac_rat \u27e8\u27e8b.n, b.d\u27e9, b.nz\u27e9  : by rw hb\n        ...            = inv_frac_rat b                   : by refl\nelse\n    have hb: b.n \u2260 0, from (\n        assume hc: b.n = 0,\n        suffices a.n = 0, from absurd this ha,\n        suffices a.n*b.d = 0, from integer.mult_nz_eq_z_imp_z this (integer.nz_impl_coe_nz b.nz),\n        calc\n            a.n*b.d = b.n*a.d : by rw h\n            ...     = 0*a.d   : by rw hc\n            ...     = 0       : by rw integer.zero_mult\n    ),\n    have hs: (fraction.inv \u27e8a, ha\u27e9).val \u2248 (fraction.inv \u27e8b, hb\u27e9).val, from fraction.inv_invariant h,\n    calc\n        inv_frac_rat a = \u27e6(fraction.inv \u27e8a, ha\u27e9).val\u27e7  : by rw inv_frac_rat_nz a ha\n        ...            = \u27e6(fraction.inv \u27e8b, hb\u27e9).val\u27e7  : by rw quotient.sound hs\n        ...            = inv_frac_rat b                : by rw inv_frac_rat_nz b hb\n\ndef inv (x: \ud835\udc10): \ud835\udc10 := quotient.lift_on x (\u03bb f, inv_frac_rat f) inv_frac_rat_invariant\ninstance: has_inv \ud835\udc10 := \u27e8inv\u27e9\n\nlemma inv_nz_is_nz {x: \ud835\udc10}: x \u2260 0 \u2192 x\u207b\u00b9 \u2260 0 := quotient.induction_on x (\n    assume a: fraction,\n    assume ha: \u27e6a\u27e7 \u2260 0,\n    have ha: a.n \u2260 0, from mt (iff.elim_right eq_zero) ha,\n    show inv_frac_rat a \u2260 0, from\n    suffices \u27e6(fraction.inv \u27e8a, ha\u27e9).val\u27e7 \u2260 0, from eq.symm (inv_frac_rat_nz a ha) \u25b8 this,\n    suffices (fraction.inv \u27e8a, ha\u27e9).val.n \u2260 0, from mt (iff.elim_left eq_zero) this,\n    assume hc: ((fraction.inv \u27e8a, ha\u27e9).val).n = 0,\n    suffices (a.d : \ud835\udc0d) = 0, from absurd this a.nz,\n    suffices (a.d : \ud835\udc19) = 0, by injection this,\n    have hc: (integer.sgn a.n) * a.d = 0, from hc,\n    have integer.sgn a.n \u2260 0, from mt (iff.elim_right integer.sgn_zero) ha,\n    integer.to_NZDRing.no_zero_divisors hc \u2039integer.sgn a.n \u2260 0\u203a\n)\n\nlemma inv_mul {x: \ud835\udc10}: x \u2260 0 \u2192 x\u207b\u00b9 * x = 1 := quotient.induction_on x (\n    assume a: fraction,\n    assume ha: \u27e6a\u27e7 \u2260 0,\n    have ha: a.n \u2260 0, from mt (iff.elim_right eq_zero) ha,\n    show inv_frac_rat a * \u27e6a\u27e7 = 1, from\n    suffices \u27e6(fraction.inv \u27e8a, ha\u27e9).val\u27e7 * \u27e6a\u27e7 = (1 : \ud835\udc10), by rw [inv_frac_rat_nz, this],\n    suffices \u27e6(fraction.inv \u27e8a, ha\u27e9).val * a\u27e7 = (1 : \ud835\udc10), from this,\n    suffices ((fraction.inv \u27e8a, ha\u27e9).val * a).n*1 = 1*((fraction.inv \u27e8a, ha\u27e9).val * a).d, from rational.eq this,\n    calc\n        ((fraction.inv \u27e8a, ha\u27e9).val * a).n*1 = ((fraction.inv \u27e8a, ha\u27e9).val * a).n                             : by rw integer.to_UnitRing.mul_one\n        ...                                  = ((fraction.inv \u27e8a, ha\u27e9).val).n * a.n                           : by refl\n        ...                                  = (integer.sgn a.n * a.d) * a.n                                  : by refl\n        ...                                  = (integer.sgn a.n * a.d) * (integer.sgn a.n * integer.abs a.n)  : by rw integer.sgn_mult_abs\n        ...                                  = (integer.sgn a.n * integer.sgn a.n) * (integer.abs a.n * a.d)  : by rw [Ring.mul_assoc, CommRing.mul_comm \ud835\udc19 a.d, Ring.mul_assoc, Ring.mul_assoc]\n        ...                                  = 1 * (integer.abs a.n * a.d)                                    : by rw integer.sgn_mult_sgn ha\n)\n\ninstance rational_decidable_equal: decidable_eq \ud835\udc10 := quotient.decidable_eq\n\n-- \ud835\udc10 is a field\ndef to_Field: Field \ud835\udc10 :=\n{\n    is_set := assume x y, if h:x = y then or.intro_left _ h else or.intro_right _ h,\n    add_assoc := add_asoc,\n    add_comm := add_com,\n    left_zero := zero_add,\n    left_neg := neg_add,\n    mul_assoc := mult_asoc,\n    mul_comm := mult_com,\n    left_distrib := mult_add,\n    left_one := one_mult,\n    nzd := no_zero_divisors,\n    inv_nz_is_nz := @inv_nz_is_nz,\n    left_inv := @inv_mul,\n    zero_ne_one := zero_ne_one,\n}\n\nend rational\n", "meta": {"author": "jamespbarrett", "repo": "basicmaths", "sha": "4f5ac79b14d1139cb1fb31ca455a15f37f5967f2", "save_path": "github-repos/lean/jamespbarrett-basicmaths", "path": "github-repos/lean/jamespbarrett-basicmaths/basicmaths-4f5ac79b14d1139cb1fb31ca455a15f37f5967f2/rational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7172345423145884}}
{"text": "-- Union_de_pares_e_impares.lean\n-- Uni\u00f3n de pares e impares\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 31 de mayo de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Los conjuntos de los n\u00fameros naturales, de los pares y de los impares\n-- se definen por\n--    def naturales : set \u2115 := {n | true}\n--    def pares     : set \u2115 := {n | even n}\n--    def impares   : set \u2115 := {n | \u00ac even n}\n--\n-- Demostrar que\n--    pares \u222a impares = naturales\n-- ----------------------------------------------------------------------\n\nimport data.nat.parity\nimport data.set.basic\nimport tactic\n\nopen set\n\ndef naturales : set \u2115 := {n | true}\ndef pares     : set \u2115 := {n | even n}\ndef impares   : set \u2115 := {n | \u00ac even n}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : pares \u222a impares = naturales :=\nbegin\n  unfold pares impares naturales,\n  ext n,\n  simp,\n  apply classical.em,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : pares \u222a impares = naturales :=\nbegin\n  unfold pares impares naturales,\n  ext n,\n  finish,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : pares \u222a impares = naturales :=\nby finish [pares, impares, naturales, ext_iff]\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Union_de_pares_e_impares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7172345387577502}}
{"text": "import tactic\n\n/-\nThe goal for next week is to introduce the last major piece of the Lean language that's used \nregularly in mathlib. This is the **type class** system. But before we do that, lets finish talking\nabout the underlying logic of Lean.\n\nFirst recall how we got here: Proving theorems in Lean amounts to constructing terms of the right \ntype. For example we prove the next example four times. But fundamentall all 4 proofs are exactly\nthe same\n-/\nlemma lemma1 {P Q : Prop} (h : P \u2227 Q) : Q \u2227 P := and.intro (and.elim_right h) (and.elim_left h) \n\nlemma lemma2 {P Q : Prop} (h : P \u2227 Q) : Q \u2227 P := and.intro (h.right) (h.left)\n\nlemma lemma3 {P Q : Prop} : P \u2227 Q \u2192 Q \u2227 P := \u03bbh, \u27e8h.2, h.1\u27e9\n\nlemma lemma4 {P Q : Prop} : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\nintro h,\ncases h with p q,\nsplit,\nexact q,\nexact p,\nend\n\n#print lemma1\n#print lemma2\n#print lemma3\n#print lemma4\n/-\nThe expressiveness of Lean that allows it to formalize more complicated mathematics than just simple\nlogical puzzles like those above comes from its support for a couple of pieces of type theory:\n**dependent types** and **inductive data types**. \n\nLets focus on dependent types first. \n-/\n\n\n\n\n\n\n\n\n\n\n\n\n\n/-\nThere are likely others, but in your daily life working on proofs in mathlib there are basically \nonly two kinds of dependent types you'll run into: _dependent products_ and _dependent sums_. \n\nA dependent product is kind of like a function type, but the function's values map into different\nplaces depending on the input. For example, consider the type of fixed-length lists:\n-/\nstructure len_list (n : \u2115) :=\n(carrier : list \u2115)\n(len_eq_n : carrier.length = n)\n\n#check len_list 3 -- List of natural numbers of length 3\n\n/-\nConsider the function which adds 0 to the front of a list\n-/\ndef F (n : \u2115) : len_list n \u2192 len_list (n + 1) := \u03bbL, \n{ carrier  := 0 :: L.carrier,\n  len_eq_n := by simp [L.len_eq_n] } -- Notice we actually had to prove something!\n\n#check F\n/-\nNote the type of `F`. The `\u03a0` in the output is exactly the dependent product. Think about what you\nwould want the type of `F` to be... It takes an input `n : \u2115` and the output is a function type\n`len_list n \u2192 len_list (n + 1)`. You would expect that this means the type of `F` should be \n\n`\u2115 \u2192 len_list n \u2192 len_list (n + 1)`\n\nBut of course this doesn't make sense because until we know the first argument, `n` has no meaning.\nThe way we should think about this is in terms of a _dependent product_ or _dependent function type_\nIn general, the dependent product is often times written as `\u03a0\u03b1, \u03b2` in the CS literature which \nconfuses me until I realize that `\u03b2` can actually depend on \n\nAn even easier example that this shows up in is the `cons` function for lists (we usually write it\nas `(::)`, for example `0 :: L.carrier` above)\n-/\n\n#check @list.cons\n/-\nShowing all the implicit arguments reveals that the `cons` function is a dependent type.\n\nThe way this appears in formalizing mathematics is in terms of the `\u2200` symbol. In fact, according\nto lean `\u03a0` and `\u2200` are synonyms. For example consider the following lemma\n-/\n\nexample : \u2200 (N : \u2115), N + 1 > N := lt_add_one\n/-\nThe conclusion `N + 1 > N` is a type of type `Prop`, which _depends on a natural number N_. This is\nexactly a _dependent function type_ of type `\u03a0\u2115, Prop`. he usual function type is just a dependent \nfunction type where the output type does not depend on the input.\n\n\nWhy do we also use the dependent product terminology? We can kind of think of a dependent product \nas a big infinite product over the input.\n-/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/-\nThe other kind of dependent type is the _dependent sum_ type `\u03a3`. In this case, coming up with a non\ncontrived CS example is a little tough, so I'll jump straight to the _logical_ analogue `\u2203`. \n\nConsider this example:\n-/\n\nexample : \u2203(M : \u2115), M > 2 := sorry\n\n/-\nAgain, the type `M > 2` has type `Prop`, but it doesn't make sense unless we already have an `M : \u2115`\nin context. In this case we say this example has type `\u03a3\u2115, Prop`. \n\nIn general the dependent product of the form `\u03a3\u03b1, \u03b2` (here `\u03b2` could depend on `\u03b1`) is the type of\npairs `(a, b)` where `a : \u03b1` and `b : \u03b2(\u03b1)`. In the above example the type is all the pairs\n\n`(3, by norm_num)`,\n`(4, _)`, \n`(5, _)`, \n...\nwhere the underscores can be filled in with any term proving `M > 2`. \n-/\n\nexample : \u2200(n : \u2115), \u2203(M : \u2115), M > n := sorry\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/-\nReasoning about these quantifiers almost always boils down to the following rules:\n\n* Have a `\u2200` in my goal? Use `intro` to eliminate it.\n-/\nexample : \u2200 (N : \u2115), N + 1 > N :=\nbegin\n  sorry\nend\n\n/-\n* Have a `\u2200` in a hypothesis `h`, and want to use it in a particular instance `x`? Use \n`specialize h x`\n-/\nexample (f : \u2115 \u2192 \u2115) (h1 : \u2200(n : \u2115), f n > n) (h2 : \u2200(n : \u2115), f n < n + 2) : \u2200n , f n = n + 1 := \nbegin\n  sorry\nend\n/-\n* Have a `\u2203` in a goal? Find some witness of the property `x` and `use x`:\n-/\nexample : \u2203 (z : \u2124), \u2200(n : \u2115), z < n :=\nbegin\n  sorry\nend\n\n/-\n* Have a `\u2203` in a hypothesis? Use `cases` to split it up into the witness, and the proposition it \nsatisfies.\n-/\nexample (S : set \u2115) (h : \u2203n, n \u2208 S) : S.nonempty :=\nbegin\n  sorry\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/-\nWe've already spent time talking about inductive data types and structures, but just to recall \nbriefly look at the following two examples.\n-/\n\ninductive mynat\n| zero : mynat\n| succ : mynat \u2192 mynat\n\n#print prefix mynat\n\nstructure bdd_func :=\n(to_fun : \u2115 \u2192 \u2115)\n(bdd : \u2203(M : \u2115), \u2200(n : \u2115), to_fun n < M)\n\n#print prefix bdd_func\n\nvariable f : bdd_func\n\n-- #check f 3\n\ninstance : has_coe_to_fun bdd_func (\u03bb_, \u2115 \u2192 \u2115) := {\n  coe := \u03bbf, f.to_fun\n}\n\n#check f.bdd\n\n\n/-\nIf we have time, lets try to prove this more involved example:\n-/\ninstance : has_add bdd_func := sorry", "meta": {"author": "mpenciak", "repo": "Lean-Seminar-Sp2022", "sha": "49437bb35643bf43e90afddb2e7702a749a725e4", "save_path": "github-repos/lean/mpenciak-Lean-Seminar-Sp2022", "path": "github-repos/lean/mpenciak-Lean-Seminar-Sp2022/Lean-Seminar-Sp2022-49437bb35643bf43e90afddb2e7702a749a725e4/src/week6/demo6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7172345360291429}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.free_module.rank\nimport linear_algebra.free_module.finite.basic\n\n/-!\n\n# Rank of finite free modules\n\nThis is a basic API for the rank of finite free modules.\n\n-/\n\n--TODO: `linear_algebra/finite_dimensional` should import this file, and a lot of results should\n--be moved here.\n\nuniverses u v w\n\nvariables (R : Type u) (M : Type v) (N : Type w)\n\nopen_locale tensor_product direct_sum big_operators cardinal\n\nopen cardinal finite_dimensional fintype\n\nnamespace module.free\n\nsection ring\n\nvariables [ring R] [strong_rank_condition R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M]\nvariables [add_comm_group N] [module R N] [module.free R N] [module.finite R N]\n\n/-- The rank of a finite and free module is finite. -/\nlemma rank_lt_omega : module.rank R M < \u03c9 :=\nbegin\n  letI := nontrivial_of_invariant_basis_number R,\n  rw [\u2190 (choose_basis R M).mk_eq_dim'', lt_omega_iff_fintype],\n  exact nonempty.intro infer_instance\nend\n\n/-- If `M` is finite and free, `finrank M = rank M`. -/\n@[simp] lemma finrank_eq_rank : \u2191(finrank R M) = module.rank R M :=\nby { rw [finrank, cast_to_nat_of_lt_omega (rank_lt_omega R M)] }\n\n/-- The finrank of a free module `M` over `R` is the cardinality of `choose_basis_index R M`. -/\nlemma finrank_eq_card_choose_basis_index : finrank R M = @card (choose_basis_index R M)\n  (@choose_basis_index.fintype R M _ _ _ _ (nontrivial_of_invariant_basis_number R) _) :=\nbegin\n  letI := nontrivial_of_invariant_basis_number R,\n  simp [finrank, rank_eq_card_choose_basis_index]\nend\n\n/-- The finrank of `(\u03b9 \u2192\u2080 R)` is `fintype.card \u03b9`. -/\n@[simp] lemma finrank_finsupp {\u03b9 : Type v} [fintype \u03b9] : finrank R (\u03b9 \u2192\u2080 R) = card \u03b9 :=\nby { rw [finrank, rank_finsupp, \u2190 mk_to_nat_eq_card, to_nat_lift] }\n\n/-- The finrank of `(\u03b9 \u2192 R)` is `fintype.card \u03b9`. -/\nlemma finrank_pi {\u03b9 : Type v} [fintype \u03b9] : finrank R (\u03b9 \u2192 R) = card \u03b9 :=\nby simp [finrank]\n\n/-- The finrank of the direct sum is the sum of the finranks. -/\n@[simp] lemma finrank_direct_sum  {\u03b9 : Type v} [fintype \u03b9] (M : \u03b9 \u2192 Type w)\n  [\u03a0 (i : \u03b9), add_comm_group (M i)] [\u03a0 (i : \u03b9), module R (M i)] [\u03a0 (i : \u03b9), module.free R (M i)]\n  [\u03a0 (i : \u03b9), module.finite R (M i)] : finrank R (\u2a01 i, M i) = \u2211 i, finrank R (M i) :=\nbegin\n  letI := nontrivial_of_invariant_basis_number R,\n  simp only [finrank, \u03bb i, rank_eq_card_choose_basis_index R (M i), rank_direct_sum,\n    \u2190 mk_sigma, mk_to_nat_eq_card, card_sigma],\nend\n\n/-- The finrank of `M \u00d7 N` is `(finrank R M) + (finrank R N)`. -/\n@[simp] lemma finrank_prod : finrank R (M \u00d7 N) = (finrank R M) + (finrank R N) :=\nby { simp [finrank, rank_lt_omega R M, rank_lt_omega R N] }\n\n/-- The finrank of a finite product is the sum of the finranks. -/\n--TODO: this should follow from `linear_equiv.finrank_eq`, that is over a field.\nlemma finrank_pi_fintype {\u03b9 : Type v} [fintype \u03b9] {M : \u03b9 \u2192 Type w}\n  [\u03a0 (i : \u03b9), add_comm_group (M i)] [\u03a0 (i : \u03b9), module R (M i)] [\u03a0 (i : \u03b9), module.free R (M i)]\n  [\u03a0 (i : \u03b9), module.finite R (M i)] : finrank R (\u03a0 i, M i) = \u2211 i, finrank R (M i) :=\nbegin\n  letI := nontrivial_of_invariant_basis_number R,\n  simp only [finrank, \u03bb i, rank_eq_card_choose_basis_index R (M i), rank_pi_fintype,\n    \u2190 mk_sigma, mk_to_nat_eq_card, card_sigma],\nend\n\n/-- If `n` and `m` are `fintype`, the finrank of `n \u00d7 m` matrices is\n  `(fintype.card n) * (fintype.card m)`. -/\nlemma finrank_matrix (n : Type v) [fintype n] (m : Type w) [fintype m] :\n  finrank R (matrix n m R) = (card n) * (card m) :=\nby { simp [finrank] }\n\nend ring\n\nsection comm_ring\n\nvariables [comm_ring R] [strong_rank_condition R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M]\nvariables [add_comm_group N] [module R N] [module.free R N] [module.finite R N]\n\n/-- The finrank of `M \u2192\u2097[R] N` is `(finrank R M) * (finrank R N)`. -/\n--TODO: this should follow from `linear_equiv.finrank_eq`, that is over a field.\nlemma finrank_linear_hom : finrank R (M \u2192\u2097[R] N) = (finrank R M) * (finrank R N) :=\nbegin\n  classical,\n  letI := nontrivial_of_invariant_basis_number R,\n  have h := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)),\n  let b := (matrix.std_basis _ _ _).map h.symm,\n  rw [finrank, dim_eq_card_basis b, \u2190 mk_fintype, mk_to_nat_eq_card, finrank, finrank,\n    rank_eq_card_choose_basis_index, rank_eq_card_choose_basis_index, mk_to_nat_eq_card,\n    mk_to_nat_eq_card, card_prod, mul_comm]\nend\n\n/-- The finrank of `M \u2297[R] N` is `(finrank R M) * (finrank R N)`. -/\n@[simp] lemma finrank_tensor_product (M : Type v) (N : Type w) [add_comm_group M] [module R M]\n  [module.free R M] [add_comm_group N] [module R N] [module.free R N] :\nfinrank R (M \u2297[R] N) = (finrank R M) * (finrank R N) :=\nby { simp [finrank] }\n\nend comm_ring\n\nend module.free\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/free_module/finite/rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7172345305719281}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n-/\nimport analysis.special_functions.exp\nimport data.nat.factorization.basic\n\n/-!\n# Real logarithm\n\nIn this file we define `real.log` to be the logarithm of a real number. As usual, we extend it from\nits domain `(0, +\u221e)` to a globally defined function. We choose to do it so that `log 0 = 0` and\n`log (-x) = log x`.\n\nWe prove some basic properties of this function and show that it is continuous.\n\n## Tags\n\nlogarithm, continuity\n-/\n\nopen set filter function\nopen_locale topology\nnoncomputable theory\n\nnamespace real\n\nvariables {x y : \u211d}\n\n/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,\nto `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to\n`(-\u221e, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and\nthe derivative of `log` is `1/x` away from `0`. -/\n@[pp_nodot] noncomputable def log (x : \u211d) : \u211d :=\nif hx : x = 0 then 0 else exp_order_iso.symm \u27e8|x|, abs_pos.2 hx\u27e9\n\nlemma log_of_ne_zero (hx : x \u2260 0) : log x = exp_order_iso.symm \u27e8|x|, abs_pos.2 hx\u27e9 := dif_neg hx\n\nlemma log_of_pos (hx : 0 < x) : log x = exp_order_iso.symm \u27e8x, hx\u27e9 :=\nby { rw [log_of_ne_zero hx.ne'], congr, exact abs_of_pos hx }\n\nlemma exp_log_eq_abs (hx : x \u2260 0) : exp (log x) = |x| :=\nby rw [log_of_ne_zero hx, \u2190 coe_exp_order_iso_apply, order_iso.apply_symm_apply, subtype.coe_mk]\n\nlemma exp_log (hx : 0 < x) : exp (log x) = x :=\nby { rw exp_log_eq_abs hx.ne', exact abs_of_pos hx }\n\nlemma exp_log_of_neg (hx : x < 0) : exp (log x) = -x :=\nby { rw exp_log_eq_abs (ne_of_lt hx), exact abs_of_neg hx }\n\nlemma le_exp_log (x : \u211d) : x \u2264 exp (log x) :=\nbegin\n  by_cases h_zero : x = 0,\n  { rw [h_zero, log, dif_pos rfl, exp_zero], exact zero_le_one, },\n  { rw exp_log_eq_abs h_zero, exact le_abs_self _, },\nend\n@[simp] lemma log_exp (x : \u211d) : log (exp x) = x :=\nexp_injective $ exp_log (exp_pos x)\n\nlemma surj_on_log : surj_on log (Ioi 0) univ :=\n\u03bb x _, \u27e8exp x, exp_pos x, log_exp x\u27e9\n\nlemma log_surjective : surjective log :=\n\u03bb x, \u27e8exp x, log_exp x\u27e9\n\n@[simp] lemma range_log : range log = univ :=\nlog_surjective.range_eq\n\n@[simp] lemma log_zero : log 0 = 0 := dif_pos rfl\n\n@[simp] lemma log_one : log 1 = 0 :=\nexp_injective $ by rw [exp_log zero_lt_one, exp_zero]\n\n@[simp] lemma log_abs (x : \u211d) : log (|x|) = log x :=\nbegin\n  by_cases h : x = 0,\n  { simp [h] },\n  { rw [\u2190 exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] }\nend\n\n@[simp] lemma log_neg_eq_log (x : \u211d) : log (-x) = log x :=\nby rw [\u2190 log_abs x, \u2190 log_abs (-x), abs_neg]\n\nlemma sinh_log {x : \u211d} (hx : 0 < x) : sinh (log x) = (x - x\u207b\u00b9) / 2 :=\nby rw [sinh_eq, exp_neg, exp_log hx]\n\nlemma cosh_log {x : \u211d} (hx : 0 < x) : cosh (log x) = (x + x\u207b\u00b9) / 2 :=\nby rw [cosh_eq, exp_neg, exp_log hx]\n\nlemma surj_on_log' : surj_on log (Iio 0) univ :=\n\u03bb x _, \u27e8-exp x, neg_lt_zero.2 $ exp_pos x, by rw [log_neg_eq_log, log_exp]\u27e9\n\nlemma log_mul (hx : x \u2260 0) (hy : y \u2260 0) : log (x * y) = log x + log y :=\nexp_injective $\nby rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]\n\nlemma log_div (hx : x \u2260 0) (hy : y \u2260 0) : log (x / y) = log x - log y :=\nexp_injective $\nby rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]\n\n@[simp] lemma log_inv (x : \u211d) : log (x\u207b\u00b9) = -log x :=\nbegin\n  by_cases hx : x = 0, { simp [hx] },\n  rw [\u2190 exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]\nend\n\nlemma log_le_log (h : 0 < x) (h\u2081 : 0 < y) : log x \u2264 log y \u2194 x \u2264 y :=\nby rw [\u2190 exp_le_exp, exp_log h, exp_log h\u2081]\n\nlemma log_lt_log (hx : 0 < x) : x < y \u2192 log x < log y :=\nby { intro h, rwa [\u2190 exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] }\n\nlemma log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y \u2194 x < y :=\nby { rw [\u2190 exp_lt_exp, exp_log hx, exp_log hy] }\n\nlemma log_le_iff_le_exp (hx : 0 < x) : log x \u2264 y \u2194 x \u2264 exp y := by rw [\u2190exp_le_exp, exp_log hx]\n\nlemma log_lt_iff_lt_exp (hx : 0 < x) : log x < y \u2194 x < exp y := by rw [\u2190exp_lt_exp, exp_log hx]\n\nlemma le_log_iff_exp_le (hy : 0 < y) : x \u2264 log y \u2194 exp x \u2264 y := by rw [\u2190exp_le_exp, exp_log hy]\n\nlemma lt_log_iff_exp_lt (hy : 0 < y) : x < log y \u2194 exp x < y := by rw [\u2190exp_lt_exp, exp_log hy]\n\nlemma log_pos_iff (hx : 0 < x) : 0 < log x \u2194 1 < x :=\nby { rw \u2190 log_one, exact log_lt_log_iff zero_lt_one hx }\n\nlemma log_pos (hx : 1 < x) : 0 < log x :=\n(log_pos_iff (lt_trans zero_lt_one hx)).2 hx\n\nlemma log_neg_iff (h : 0 < x) : log x < 0 \u2194 x < 1 :=\nby { rw \u2190 log_one, exact log_lt_log_iff h zero_lt_one }\n\nlemma log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1\n\nlemma log_nonneg_iff (hx : 0 < x) : 0 \u2264 log x \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, log_neg_iff hx, not_lt]\n\nlemma log_nonneg (hx : 1 \u2264 x) : 0 \u2264 log x :=\n(log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx\n\nlemma log_nonpos_iff (hx : 0 < x) : log x \u2264 0 \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, log_pos_iff hx, not_lt]\n\nlemma log_nonpos_iff' (hx : 0 \u2264 x) : log x \u2264 0 \u2194 x \u2264 1 :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { simp [le_refl, zero_le_one] },\n  exact log_nonpos_iff hx\nend\n\nlemma log_nonpos (hx : 0 \u2264 x) (h'x : x \u2264 1) : log x \u2264 0 :=\n(log_nonpos_iff' hx).2 h'x\n\nlemma strict_mono_on_log : strict_mono_on log (set.Ioi 0) :=\n\u03bb x hx y hy hxy, log_lt_log hx hxy\n\n\n\nlemma log_inj_on_pos : set.inj_on log (set.Ioi 0) :=\nstrict_mono_on_log.inj_on\n\nlemma eq_one_of_pos_of_log_eq_zero {x : \u211d} (h\u2081 : 0 < x) (h\u2082 : log x = 0) : x = 1 :=\nlog_inj_on_pos (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one) (h\u2082.trans real.log_one.symm)\n\nlemma log_ne_zero_of_pos_of_ne_one {x : \u211d} (hx_pos : 0 < x) (hx : x \u2260 1) : log x \u2260 0 :=\nmt (eq_one_of_pos_of_log_eq_zero hx_pos) hx\n\n@[simp] lemma log_eq_zero {x : \u211d} : log x = 0 \u2194 x = 0 \u2228 x = 1 \u2228 x = -1 :=\nbegin\n  split,\n  { intros h,\n    rcases lt_trichotomy x 0 with x_lt_zero | rfl | x_gt_zero,\n    { refine or.inr (or.inr (neg_eq_iff_eq_neg.mp _)),\n      rw [\u2190log_neg_eq_log x] at h,\n      exact eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h, },\n    { exact or.inl rfl },\n    { exact or.inr (or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h)), }, },\n  { rintro (rfl|rfl|rfl); simp only [log_one, log_zero, log_neg_eq_log], }\nend\n\n@[simp] lemma log_pow (x : \u211d) (n : \u2115) : log (x ^ n) = n * log x :=\nbegin\n  induction n with n ih,\n  { simp },\n  rcases eq_or_ne x 0 with rfl | hx,\n  { simp },\n  rw [pow_succ', log_mul (pow_ne_zero _ hx) hx, ih, nat.cast_succ, add_mul, one_mul],\nend\n\n@[simp] lemma log_zpow (x : \u211d) (n : \u2124) : log (x ^ n) = n * log x :=\nbegin\n  induction n,\n  { rw [int.of_nat_eq_coe, zpow_coe_nat, log_pow, int.cast_coe_nat] },\n  rw [zpow_neg_succ_of_nat, log_inv, log_pow, int.cast_neg_succ_of_nat, nat.cast_add_one,\n    neg_mul_eq_neg_mul],\nend\n\nlemma log_sqrt {x : \u211d} (hx : 0 \u2264 x) : log (sqrt x) = log x / 2 :=\nby { rw [eq_div_iff, mul_comm, \u2190 nat.cast_two, \u2190 log_pow, sq_sqrt hx], exact two_ne_zero }\n\nlemma log_le_sub_one_of_pos {x : \u211d} (hx : 0 < x) : log x \u2264 x - 1 :=\nbegin\n  rw le_sub_iff_add_le,\n  convert add_one_le_exp (log x),\n  rw exp_log hx,\nend\n\n/-- Bound for `|log x * x|` in the interval `(0, 1]`. -/\nlemma abs_log_mul_self_lt (x: \u211d) (h1 : 0 < x) (h2 : x \u2264 1) : |log x * x| < 1 :=\nbegin\n  have : 0 < 1/x := by simpa only [one_div, inv_pos] using h1,\n  replace := log_le_sub_one_of_pos this,\n  replace : log (1 / x) < 1/x := by linarith,\n  rw [log_div one_ne_zero h1.ne', log_one, zero_sub, lt_div_iff h1] at this,\n  have aux : 0 \u2264 -log x * x,\n  { refine mul_nonneg _ h1.le, rw \u2190log_inv, apply log_nonneg,\n    rw [\u2190(le_inv h1 zero_lt_one), inv_one], exact h2, },\n  rw [\u2190(abs_of_nonneg aux), neg_mul, abs_neg] at this, exact this,\nend\n\n/-- The real logarithm function tends to `+\u221e` at `+\u221e`. -/\nlemma tendsto_log_at_top : tendsto log at_top at_top :=\ntendsto_comp_exp_at_top.1 $ by simpa only [log_exp] using tendsto_id\n\nlemma tendsto_log_nhds_within_zero : tendsto log (\ud835\udcdd[\u2260] 0) at_bot :=\nbegin\n  rw [\u2190 (show _ = log, from funext log_abs)],\n  refine tendsto.comp _ tendsto_abs_nhds_within_zero,\n  simpa [\u2190 tendsto_comp_exp_at_bot] using tendsto_id\nend\n\nlemma continuous_on_log : continuous_on log {0}\u1d9c :=\nbegin\n  rw [continuous_on_iff_continuous_restrict, restrict],\n  conv in (log _) { rw [log_of_ne_zero (show (x : \u211d) \u2260 0, from x.2)] },\n  exact exp_order_iso.symm.continuous.comp (continuous_subtype_coe.norm.subtype_mk _)\nend\n\n@[continuity] lemma continuous_log : continuous (\u03bb x : {x : \u211d // x \u2260 0}, log x) :=\ncontinuous_on_iff_continuous_restrict.1 $ continuous_on_log.mono $ \u03bb x hx, hx\n\n@[continuity] lemma continuous_log' : continuous (\u03bb x : {x : \u211d // 0 < x}, log x) :=\ncontinuous_on_iff_continuous_restrict.1 $ continuous_on_log.mono $ \u03bb x hx, ne_of_gt hx\n\nlemma continuous_at_log (hx : x \u2260 0) : continuous_at log x :=\n(continuous_on_log x hx).continuous_at $ is_open.mem_nhds is_open_compl_singleton hx\n\n@[simp] lemma continuous_at_log_iff : continuous_at log x \u2194 x \u2260 0 :=\nbegin\n  refine \u27e8_, continuous_at_log\u27e9,\n  rintros h rfl,\n  exact not_tendsto_nhds_of_tendsto_at_bot tendsto_log_nhds_within_zero _\n    (h.tendsto.mono_left inf_le_left)\nend\n\nopen_locale big_operators\n\nlemma log_prod {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) (hf : \u2200 x \u2208 s, f x \u2260 0):\n  log (\u220f i in s, f i) = \u2211 i in s, log (f i) :=\nbegin\n  induction s using finset.cons_induction_on with a s ha ih,\n  { simp },\n  { rw [finset.forall_mem_cons] at hf,\n    simp [ih hf.2, log_mul hf.1 (finset.prod_ne_zero_iff.2 hf.2)] }\nend\n\nlemma log_nat_eq_sum_factorization (n : \u2115) : log n = n.factorization.sum (\u03bb p t, t * log p) :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn,\n  { simp },\n  nth_rewrite 0 [\u2190nat.factorization_prod_pow_eq_self hn],\n  rw [finsupp.prod, nat.cast_prod, log_prod _ _ (\u03bb p hp, _), finsupp.sum],\n  { simp_rw [nat.cast_pow, log_pow] },\n  { norm_cast,\n    exact pow_ne_zero _ (nat.prime_of_mem_factorization hp).ne_zero },\nend\n\nlemma tendsto_pow_log_div_mul_add_at_top (a b : \u211d) (n : \u2115) (ha : a \u2260 0) :\n  tendsto (\u03bb x, log x ^ n / (a * x + b)) at_top (\ud835\udcdd 0) :=\n((tendsto_div_pow_mul_exp_add_at_top a b n ha.symm).comp tendsto_log_at_top).congr'\n  (by filter_upwards [eventually_gt_at_top (0 : \u211d)] with x hx using by simp [exp_log hx])\n\nlemma is_o_pow_log_id_at_top {n : \u2115} : (\u03bb x, log x ^ n) =o[at_top] id :=\nbegin\n  rw asymptotics.is_o_iff_tendsto',\n  { simpa using tendsto_pow_log_div_mul_add_at_top 1 0 n one_ne_zero },\n  filter_upwards [eventually_ne_at_top (0 : \u211d)] with x h\u2081 h\u2082 using (h\u2081 h\u2082).elim,\nend\n\nlemma is_o_log_id_at_top : log =o[at_top] id := is_o_pow_log_id_at_top.congr_left (\u03bb x, pow_one _)\n\nend real\n\nsection continuity\n\nopen real\nvariables {\u03b1 : Type*}\n\nlemma filter.tendsto.log {f : \u03b1 \u2192 \u211d} {l : filter \u03b1} {x : \u211d} (h : tendsto f l (\ud835\udcdd x)) (hx : x \u2260 0) :\n  tendsto (\u03bb x, log (f x)) l (\ud835\udcdd (log x)) :=\n(continuous_at_log hx).tendsto.comp h\n\nvariables [topological_space \u03b1] {f : \u03b1 \u2192 \u211d} {s : set \u03b1} {a : \u03b1}\n\nlemma continuous.log (hf : continuous f) (h\u2080 : \u2200 x, f x \u2260 0) : continuous (\u03bb x, log (f x)) :=\ncontinuous_on_log.comp_continuous hf h\u2080\n\nlemma continuous_at.log (hf : continuous_at f a) (h\u2080 : f a \u2260 0) :\n  continuous_at (\u03bb x, log (f x)) a :=\nhf.log h\u2080\n\nlemma continuous_within_at.log (hf : continuous_within_at f s a) (h\u2080 : f a \u2260 0) :\n  continuous_within_at (\u03bb x, log (f x)) s a :=\nhf.log h\u2080\n\nlemma continuous_on.log (hf : continuous_on f s) (h\u2080 : \u2200 x \u2208 s, f x \u2260 0) :\n  continuous_on (\u03bb x, log (f x)) s :=\n\u03bb x hx, (hf x hx).log (h\u2080 x hx)\n\nend continuity\n\n\nsection tendsto_comp_add_sub\n\nopen filter\nnamespace real\n\nlemma tendsto_log_comp_add_sub_log (y : \u211d) :\n  tendsto (\u03bb x:\u211d, log (x + y) - log x) at_top (\ud835\udcdd 0) :=\nbegin\n  refine tendsto.congr' (_ :  \u2200\u1da0 (x : \u211d) in at_top, log (1 + y / x) = _) _,\n  { refine eventually.mp ((eventually_ne_at_top 0).and (eventually_gt_at_top (-y)))\n    (eventually_of_forall (\u03bb x hx, _)),\n    rw \u2190 log_div _ hx.1,\n    { congr' 1,\n      field_simp [hx.1] },\n    { linarith [hx.2] } },\n  { suffices : tendsto (\u03bb (x : \u211d), log (1 + y / x)) at_top (\ud835\udcdd (log (1 + 0))), by simpa,\n    refine tendsto.log _ (by simp),\n    exact tendsto_const_nhds.add (tendsto_const_nhds.div_at_top tendsto_id) },\nend\n\nlemma tendsto_log_nat_add_one_sub_log : tendsto (\u03bb (k : \u2115), log (k + 1) - log k) at_top (\ud835\udcdd 0) :=\n(tendsto_log_comp_add_sub_log 1).comp tendsto_coe_nat_at_top_at_top\n\nend real\nend tendsto_comp_add_sub\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/log/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7172345240425683}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro\n-/\nimport algebra.order.ring.defs\nimport algebra.order.sub.canonical\nimport group_theory.group_action.defs\n\n/-!\n# Canoncially ordered rings and semirings.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n* `canonically_ordered_comm_semiring`\n  - `canonically_ordered_add_monoid` & multiplication & `*` respects `\u2264` & no zero divisors\n  - `comm_semiring` & `a \u2264 b \u2194 \u2203 c, b = a + c` & no zero divisors\n\n## TODO\n\nWe're still missing some typeclasses, like\n* `canonically_ordered_semiring`\nThey have yet to come up in practice.\n-/\n\nopen function\n\nset_option old_structure_cmd true\n\nuniverse u\nvariables {\u03b1 : Type u} {\u03b2 : Type*}\n\n\n/-- A canonically ordered commutative semiring is an ordered, commutative semiring in which `a \u2264 b`\niff there exists `c` with `b = a + c`. This is satisfied by the natural numbers, for example, but\nnot the integers or other ordered groups. -/\n@[protect_proj, ancestor canonically_ordered_add_monoid comm_semiring]\nclass canonically_ordered_comm_semiring (\u03b1 : Type*) extends\n  canonically_ordered_add_monoid \u03b1, comm_semiring \u03b1 :=\n(eq_zero_or_eq_zero_of_mul_eq_zero : \u2200 {a b : \u03b1}, a * b = 0 \u2192 a = 0 \u2228 b = 0)\n\nsection strict_ordered_semiring\nvariables [strict_ordered_semiring \u03b1] {a b c d : \u03b1}\n\nsection has_exists_add_of_le\nvariables [has_exists_add_of_le \u03b1]\n\n/-- Binary **rearrangement inequality**. -/\nlemma mul_add_mul_le_mul_add_mul (hab : a \u2264 b) (hcd : c \u2264 d) : a * d + b * c \u2264 a * c + b * d :=\nbegin\n  obtain \u27e8b, rfl\u27e9 := exists_add_of_le hab,\n  obtain \u27e8d, rfl\u27e9 := exists_add_of_le hcd,\n  rw [mul_add, add_right_comm, mul_add, \u2190add_assoc],\n  exact add_le_add_left (mul_le_mul_of_nonneg_right hab $ (le_add_iff_nonneg_right _).1 hcd) _,\nend\n\n/-- Binary **rearrangement inequality**. -/\nlemma mul_add_mul_le_mul_add_mul' (hba : b \u2264 a) (hdc : d \u2264 c) : a \u2022 d + b \u2022 c \u2264 a \u2022 c + b \u2022 d :=\nby { rw [add_comm (a \u2022 d), add_comm (a \u2022 c)], exact mul_add_mul_le_mul_add_mul hba hdc }\n\n/-- Binary strict **rearrangement inequality**. -/\nlemma mul_add_mul_lt_mul_add_mul (hab : a < b) (hcd : c < d) : a * d + b * c < a * c + b * d :=\nbegin\n  obtain \u27e8b, rfl\u27e9 := exists_add_of_le hab.le,\n  obtain \u27e8d, rfl\u27e9 := exists_add_of_le hcd.le,\n  rw [mul_add, add_right_comm, mul_add, \u2190add_assoc],\n  exact add_lt_add_left (mul_lt_mul_of_pos_right hab $ (lt_add_iff_pos_right _).1 hcd) _,\nend\n\n/-- Binary **rearrangement inequality**. -/\nlemma mul_add_mul_lt_mul_add_mul' (hba : b < a) (hdc : d < c) : a \u2022 d + b \u2022 c < a \u2022 c + b \u2022 d :=\nby { rw [add_comm (a \u2022 d), add_comm (a \u2022 c)], exact mul_add_mul_lt_mul_add_mul hba hdc }\n\nend has_exists_add_of_le\n\nend strict_ordered_semiring\n\nnamespace canonically_ordered_comm_semiring\nvariables [canonically_ordered_comm_semiring \u03b1] {a b : \u03b1}\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_no_zero_divisors : no_zero_divisors \u03b1 :=\n\u27e8\u03bb a b h, canonically_ordered_comm_semiring.eq_zero_or_eq_zero_of_mul_eq_zero h\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_covariant_mul_le : covariant_class \u03b1 \u03b1 (*) (\u2264) :=\nbegin\n  refine \u27e8\u03bb a b c h, _\u27e9,\n  rcases exists_add_of_le h with \u27e8c, rfl\u27e9,\n  rw mul_add,\n  apply self_le_add_right\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_ordered_comm_monoid : ordered_comm_monoid \u03b1 :=\n{ mul_le_mul_left := \u03bb _ _, mul_le_mul_left',\n  .. \u2039canonically_ordered_comm_semiring \u03b1\u203a }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_ordered_comm_semiring : ordered_comm_semiring \u03b1 :=\n{ zero_le_one := zero_le _,\n  mul_le_mul_of_nonneg_left := \u03bb a b c h _, mul_le_mul_left' h _,\n  mul_le_mul_of_nonneg_right := \u03bb a b c h _, mul_le_mul_right' h _,\n  ..\u2039canonically_ordered_comm_semiring \u03b1\u203a }\n\n@[simp] lemma mul_pos : 0 < a * b \u2194 (0 < a) \u2227 (0 < b) :=\nby simp only [pos_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib]\n\n\nend canonically_ordered_comm_semiring\n\nsection sub\n\nvariables [canonically_ordered_comm_semiring \u03b1] {a b c : \u03b1}\nvariables [has_sub \u03b1] [has_ordered_sub \u03b1]\n\nvariables [is_total \u03b1 (\u2264)]\n\nnamespace add_le_cancellable\nprotected lemma mul_tsub (h : add_le_cancellable (a * c)) :\n  a * (b - c) = a * b - a * c :=\nbegin\n  cases total_of (\u2264) b c with hbc hcb,\n  { rw [tsub_eq_zero_iff_le.2 hbc, mul_zero, tsub_eq_zero_iff_le.2 (mul_le_mul_left' hbc a)] },\n  { apply h.eq_tsub_of_add_eq, rw [\u2190 mul_add, tsub_add_cancel_of_le hcb] }\nend\n\nprotected lemma tsub_mul (h : add_le_cancellable (b * c)) : (a - b) * c = a * c - b * c :=\nby { simp only [mul_comm _ c] at *, exact h.mul_tsub }\n\nend add_le_cancellable\n\nvariables [contravariant_class \u03b1 \u03b1 (+) (\u2264)]\n\nlemma mul_tsub (a b c : \u03b1) : a * (b - c) = a * b - a * c :=\ncontravariant.add_le_cancellable.mul_tsub\n\nlemma tsub_mul (a b c : \u03b1) : (a - b) * c = a * c - b * c :=\ncontravariant.add_le_cancellable.tsub_mul\n\nend sub\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/ring/canonical.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7172345183414393}}
{"text": "/-\nCopyright (c) 2018  Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Chris Hughes, Michael Howes\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.group.hom\nimport Mathlib.data.equiv.mul_add_aut\nimport Mathlib.PostPort\n\nuniverses u u_1 v \n\nnamespace Mathlib\n\n/-!\n# Conjugacy of group elements\n\nSee also `mul_aut.conj` and `quandle.conj`.\n-/\n\n/-- We say that `a` is conjugate to `b` if for some `c` we have `c * a * c\u207b\u00b9 = b`. -/\ndef is_conj {\u03b1 : Type u} [group \u03b1] (a : \u03b1) (b : \u03b1) := \u2203 (c : \u03b1), c * a * (c\u207b\u00b9) = b\n\ntheorem is_conj_refl {\u03b1 : Type u} [group \u03b1] (a : \u03b1) : is_conj a a := sorry\n\ntheorem is_conj_symm {\u03b1 : Type u} [group \u03b1] {a : \u03b1} {b : \u03b1} : is_conj a b \u2192 is_conj b a := sorry\n\ntheorem is_conj_trans {\u03b1 : Type u} [group \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} :\n    is_conj a b \u2192 is_conj b c \u2192 is_conj a c :=\n  sorry\n\n@[simp] theorem is_conj_one_right {\u03b1 : Type u} [group \u03b1] {a : \u03b1} : is_conj 1 a \u2194 a = 1 := sorry\n\n@[simp] theorem is_conj_one_left {\u03b1 : Type u} [group \u03b1] {a : \u03b1} : is_conj a 1 \u2194 a = 1 :=\n  iff.trans { mp := is_conj_symm, mpr := is_conj_symm } is_conj_one_right\n\n@[simp] theorem conj_inv {\u03b1 : Type u} [group \u03b1] {a : \u03b1} {b : \u03b1} :\n    b * a * (b\u207b\u00b9)\u207b\u00b9 = b * (a\u207b\u00b9) * (b\u207b\u00b9) :=\n  Eq.symm (mul_equiv.map_inv (coe_fn mul_aut.conj b) a)\n\n@[simp] theorem conj_mul {\u03b1 : Type u} [group \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} :\n    b * a * (b\u207b\u00b9) * (b * c * (b\u207b\u00b9)) = b * (a * c) * (b\u207b\u00b9) :=\n  Eq.symm (mul_equiv.map_mul (coe_fn mul_aut.conj b) a c)\n\ntheorem conj_injective {\u03b1 : Type u} [group \u03b1] {x : \u03b1} :\n    function.injective fun (g : \u03b1) => x * g * (x\u207b\u00b9) :=\n  mul_equiv.injective (coe_fn mul_aut.conj x)\n\n@[simp] theorem is_conj_iff_eq {\u03b1 : Type u_1} [comm_group \u03b1] {a : \u03b1} {b : \u03b1} :\n    is_conj a b \u2194 a = b :=\n  sorry\n\nprotected theorem monoid_hom.map_is_conj {\u03b1 : Type u} {\u03b2 : Type v} [group \u03b1] [group \u03b2] (f : \u03b1 \u2192* \u03b2)\n    {a : \u03b1} {b : \u03b1} : is_conj a b \u2192 is_conj (coe_fn f a) (coe_fn f b) :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/group/conj_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7172178340693983}}
{"text": "/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n\nUseful logical identities. Since we are not using propositional extensionality, some of the\ncalculations use the type class support provided by logic.instances.\n-/\nimport logic.connectives logic.quantifiers logic.cast\nopen decidable\n\ntheorem or.right_comm (a b c : Prop) : (a \u2228 b) \u2228 c \u2194 (a \u2228 c) \u2228 b :=\ncalc\n  (a \u2228 b) \u2228 c \u2194 a \u2228 (b \u2228 c) : or.assoc\n    ... \u2194 a \u2228 (c \u2228 b)       : {or.comm}\n     ... \u2194 (a \u2228 c) \u2228 b      : iff.symm or.assoc\n\ntheorem and.right_comm (a b c : Prop) : (a \u2227 b) \u2227 c \u2194 (a \u2227 c) \u2227 b :=\ncalc\n  (a \u2227 b) \u2227 c \u2194 a \u2227 (b \u2227 c) : and.assoc\n    ... \u2194 a \u2227 (c \u2227 b)       : {and.comm}\n     ... \u2194 (a \u2227 c) \u2227 b      : iff.symm and.assoc\n\ntheorem or_not_self_iff (a : Prop) [D : decidable a] : a \u2228 \u00ac a \u2194 true :=\niff.intro (assume H, trivial) (assume H, em a)\n\ntheorem not_or_self_iff (a : Prop) [D : decidable a] : \u00ac a \u2228 a \u2194 true :=\niff.intro (\u03bb H, trivial) (\u03bb H, or.swap (em a))\n\ntheorem and_not_self_iff (a : Prop) : a \u2227 \u00ac a \u2194 false :=\niff.intro (assume H, (and.right H) (and.left H)) (assume H, false.elim H)\n\ntheorem not_and_self_iff (a : Prop) : \u00ac a \u2227 a \u2194 false :=\niff.intro (\u03bb H, and.elim H (by contradiction)) (\u03bb H, false.elim H)\n\ntheorem not_not_iff (a : Prop) [D : decidable a] : \u00ac\u00aca \u2194 a :=\niff.intro by_contradiction not_not_intro\n\ntheorem not_not_elim {a : Prop} [D : decidable a] : \u00ac\u00aca \u2192 a :=\nby_contradiction\n\ntheorem not_or_iff_not_and_not (a b : Prop) : \u00ac(a \u2228 b) \u2194 \u00aca \u2227 \u00acb :=\nor.imp_distrib\n\ntheorem not_or_not_of_not_and {a b : Prop} [Da : decidable a] (H : \u00ac (a \u2227 b)) : \u00ac a \u2228 \u00ac b :=\nby_cases (\u03bbHa, or.inr (not.mto (and.intro Ha) H)) or.inl\n\ntheorem not_or_not_of_not_and' {a b : Prop} [Db : decidable b] (H : \u00ac (a \u2227 b)) : \u00ac a \u2228 \u00ac b :=\nby_cases (\u03bbHb, or.inl (\u03bbHa, H (and.intro Ha Hb))) or.inr\n\ntheorem not_and_iff_not_or_not (a b : Prop) [Da : decidable a] :\n  \u00ac(a \u2227 b) \u2194 \u00aca \u2228 \u00acb :=\niff.intro\n  not_or_not_of_not_and\n  (or.rec (not.mto and.left) (not.mto and.right))\n\ntheorem or_iff_not_and_not (a b : Prop) [Da : decidable a] [Db : decidable b] :\n  a \u2228 b \u2194 \u00ac (\u00aca \u2227 \u00acb) :=\nby rewrite [-not_or_iff_not_and_not, not_not_iff]\n\ntheorem and_iff_not_or_not (a b : Prop) [Da : decidable a] [Db : decidable b] :\n  a \u2227 b \u2194 \u00ac (\u00ac a \u2228 \u00ac b) :=\nby rewrite [-not_and_iff_not_or_not, not_not_iff]\n\ntheorem imp_iff_not_or (a b : Prop) [Da : decidable a] : (a \u2192 b) \u2194 \u00aca \u2228 b :=\niff.intro\n  (by_cases (\u03bbHa H, or.inr (H Ha)) (\u03bbHa H, or.inl Ha))\n  (or.rec not.elim imp.intro)\n\ntheorem not_implies_iff_and_not (a b : Prop) [Da : decidable a] :\n  \u00ac(a \u2192 b) \u2194 a \u2227 \u00acb :=\ncalc\n  \u00ac(a \u2192 b) \u2194 \u00ac(\u00aca \u2228 b) : {imp_iff_not_or a b}\n       ... \u2194 \u00ac\u00aca \u2227 \u00acb  : not_or_iff_not_and_not\n       ... \u2194 a \u2227 \u00acb    : {not_not_iff a}\n\ntheorem and_not_of_not_implies {a b : Prop} [Da : decidable a] (H : \u00ac (a \u2192 b)) : a \u2227 \u00ac b :=\niff.mp !not_implies_iff_and_not H\n\ntheorem not_implies_of_and_not {a b : Prop} [Da : decidable a] (H : a \u2227 \u00ac b) : \u00ac (a \u2192 b) :=\niff.mpr !not_implies_iff_and_not H\n\ntheorem peirce (a b : Prop) [D : decidable a] : ((a \u2192 b) \u2192 a) \u2192 a :=\nby_cases imp.intro (imp.syl imp.mp not.elim)\n\ntheorem forall_not_of_not_exists {A : Type} {p : A \u2192 Prop} [D : \u2200x, decidable (p x)]\n  (H : \u00ac\u2203x, p x) : \u2200x, \u00acp x :=\ntake x, by_cases\n  (assume Hp : p x, absurd (exists.intro x Hp) H)\n  imp.id\n\ntheorem forall_of_not_exists_not {A : Type} {p : A \u2192 Prop} [D : decidable_pred p] :\n  \u00ac(\u2203 x, \u00acp x) \u2192 \u2200 x, p x :=\nimp.syl (forall_imp_forall (\u03bba, not_not_elim)) forall_not_of_not_exists\n\ntheorem exists_not_of_not_forall {A : Type} {p : A \u2192 Prop} [D : \u2200x, decidable (p x)]\n    [D' : decidable (\u2203x, \u00acp x)] (H : \u00ac\u2200x, p x) :\n  \u2203x, \u00acp x :=\nby_contradiction (\u03bbH1, absurd (\u03bbx, not_not_elim (forall_not_of_not_exists H1 x)) H)\n\ntheorem exists_of_not_forall_not {A : Type} {p : A \u2192 Prop} [D : \u2200x, decidable (p x)]\n    [D' : decidable (\u2203x, p x)] (H : \u00ac\u2200x, \u00ac p x) :\n  \u2203x, p x :=\nby_contradiction (imp.syl H forall_not_of_not_exists)\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/logic/identities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388252252041, "lm_q2_score": 0.8652240721511739, "lm_q1q2_score": 0.7172178259255614}}
{"text": "/-\nCopyright (c) 2021 Vladimir Goryachev. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Vladimir Goryachev, Kyle Miller, Scott Morrison, Eric Rodriguez\n\n! This file was ported from Lean 3 source module data.nat.count\n! leanprover-community/mathlib commit 1ead22342e1a078bd44744ace999f85756555d35\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.SetTheory.Cardinal.Basic\nimport Mathbin.Tactic.Ring\n\n/-!\n# Counting on \u2115\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the `count` function, which gives, for any predicate on the natural numbers,\n\"how many numbers under `k` satisfy this predicate?\".\nWe then prove several expected lemmas about `count`, relating it to the cardinality of other\nobjects, and helping to evaluate it for specific `k`.\n\n-/\n\n\nopen Finset\n\nnamespace Nat\n\nvariable (p : \u2115 \u2192 Prop)\n\nsection Count\n\nvariable [DecidablePred p]\n\n#print Nat.count /-\n/-- Count the number of naturals `k < n` satisfying `p k`. -/\ndef count (n : \u2115) : \u2115 :=\n  (List.range n).countp p\n#align nat.count Nat.count\n-/\n\n#print Nat.count_zero /-\n@[simp]\ntheorem count_zero : count p 0 = 0 := by rw [count, List.range_zero, List.countp]\n#align nat.count_zero Nat.count_zero\n-/\n\n#print Nat.CountSet.fintype /-\n/-- A fintype instance for the set relevant to `nat.count`. Locally an instance in locale `count` -/\ndef CountSet.fintype (n : \u2115) : Fintype { i // i < n \u2227 p i } :=\n  by\n  apply Fintype.ofFinset ((Finset.range n).filter\u2093 p)\n  intro x\n  rw [mem_filter, mem_range]\n  rfl\n#align nat.count_set.fintype Nat.CountSet.fintype\n-/\n\nscoped[Count] attribute [instance] Nat.CountSet.fintype\n\n#print Nat.count_eq_card_filter_range /-\ntheorem count_eq_card_filter_range (n : \u2115) : count p n = ((range n).filter\u2093 p).card :=\n  by\n  rw [count, List.countp_eq_length_filter]\n  rfl\n#align nat.count_eq_card_filter_range Nat.count_eq_card_filter_range\n-/\n\n#print Nat.count_eq_card_fintype /-\n/-- `count p n` can be expressed as the cardinality of `{k // k < n \u2227 p k}`. -/\ntheorem count_eq_card_fintype (n : \u2115) : count p n = Fintype.card { k : \u2115 // k < n \u2227 p k } :=\n  by\n  rw [count_eq_card_filter_range, \u2190 Fintype.card_ofFinset, \u2190 count_set.fintype]\n  rfl\n#align nat.count_eq_card_fintype Nat.count_eq_card_fintype\n-/\n\n#print Nat.count_succ /-\ntheorem count_succ (n : \u2115) : count p (n + 1) = count p n + if p n then 1 else 0 := by\n  split_ifs <;> simp [count, List.range_succ, h]\n#align nat.count_succ Nat.count_succ\n-/\n\n#print Nat.count_monotone /-\n@[mono]\ntheorem count_monotone : Monotone (count p) :=\n  monotone_nat_of_le_succ fun n => by by_cases h : p n <;> simp [count_succ, h]\n#align nat.count_monotone Nat.count_monotone\n-/\n\n#print Nat.count_add /-\ntheorem count_add (a b : \u2115) : count p (a + b) = count p a + count (fun k => p (a + k)) b :=\n  by\n  have : Disjoint ((range a).filter\u2093 p) (((range b).map <| addLeftEmbedding a).filter\u2093 p) :=\n    by\n    apply disjoint_filter_filter\n    rw [Finset.disjoint_left]\n    simp_rw [mem_map, mem_range, addLeftEmbedding_apply]\n    rintro x hx \u27e8c, _, rfl\u27e9\n    exact (self_le_add_right _ _).not_lt hx\n  simp_rw [count_eq_card_filter_range, range_add, filter_union, card_disjoint_union this,\n    filter_map, addLeftEmbedding, card_map]\n  rfl\n#align nat.count_add Nat.count_add\n-/\n\n#print Nat.count_add' /-\ntheorem count_add' (a b : \u2115) : count p (a + b) = count (fun k => p (k + b)) a + count p b :=\n  by\n  rw [add_comm, count_add, add_comm]\n  simp_rw [add_comm b]\n#align nat.count_add' Nat.count_add'\n-/\n\n#print Nat.count_one /-\ntheorem count_one : count p 1 = if p 0 then 1 else 0 := by simp [count_succ]\n#align nat.count_one Nat.count_one\n-/\n\n#print Nat.count_succ' /-\ntheorem count_succ' (n : \u2115) :\n    count p (n + 1) = count (fun k => p (k + 1)) n + if p 0 then 1 else 0 := by\n  rw [count_add', count_one]\n#align nat.count_succ' Nat.count_succ'\n-/\n\nvariable {p}\n\n#print Nat.count_lt_count_succ_iff /-\n@[simp]\ntheorem count_lt_count_succ_iff {n : \u2115} : count p n < count p (n + 1) \u2194 p n := by\n  by_cases h : p n <;> simp [count_succ, h]\n#align nat.count_lt_count_succ_iff Nat.count_lt_count_succ_iff\n-/\n\n#print Nat.count_succ_eq_succ_count_iff /-\ntheorem count_succ_eq_succ_count_iff {n : \u2115} : count p (n + 1) = count p n + 1 \u2194 p n := by\n  by_cases h : p n <;> simp [h, count_succ]\n#align nat.count_succ_eq_succ_count_iff Nat.count_succ_eq_succ_count_iff\n-/\n\n#print Nat.count_succ_eq_count_iff /-\ntheorem count_succ_eq_count_iff {n : \u2115} : count p (n + 1) = count p n \u2194 \u00acp n := by\n  by_cases h : p n <;> simp [h, count_succ]\n#align nat.count_succ_eq_count_iff Nat.count_succ_eq_count_iff\n-/\n\nalias count_succ_eq_succ_count_iff \u2194 _ count_succ_eq_succ_count\n#align nat.count_succ_eq_succ_count Nat.count_succ_eq_succ_count\n\nalias count_succ_eq_count_iff \u2194 _ count_succ_eq_count\n#align nat.count_succ_eq_count Nat.count_succ_eq_count\n\n/- warning: nat.count_le_cardinal -> Nat.count_le_cardinal is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat -> Prop} [_inst_1 : DecidablePred.{1} Nat p] (n : Nat), LE.le.{1} Cardinal.{0} Cardinal.hasLe.{0} ((fun (a : Type) (b : Type.{1}) [self : HasLiftT.{1, 2} a b] => self.0) Nat Cardinal.{0} (HasLiftT.mk.{1, 2} Nat Cardinal.{0} (CoeTC\u2093.coe.{1, 2} Nat Cardinal.{0} (Nat.castCoe.{1} Cardinal.{0} Cardinal.hasNatCast.{0}))) (Nat.count p (fun (a : Nat) => _inst_1 a) n)) (Cardinal.mk.{0} (coeSort.{1, 2} (Set.{0} Nat) Type (Set.hasCoeToSort.{0} Nat) (setOf.{0} Nat (fun (k : Nat) => p k))))\nbut is expected to have type\n  forall {p : Nat -> Prop} [_inst_1 : DecidablePred.{1} Nat p] (n : Nat), LE.le.{1} Cardinal.{0} Cardinal.instLECardinal.{0} (Nat.cast.{1} Cardinal.{0} Cardinal.instNatCastCardinal.{0} (Nat.count p (fun (a : Nat) => _inst_1 a) n)) (Cardinal.mk.{0} (Set.Elem.{0} Nat (setOf.{0} Nat (fun (k : Nat) => p k))))\nCase conversion may be inaccurate. Consider using '#align nat.count_le_cardinal Nat.count_le_cardinal\u2093'. -/\ntheorem count_le_cardinal (n : \u2115) : (count p n : Cardinal) \u2264 Cardinal.mk { k | p k } :=\n  by\n  rw [count_eq_card_fintype, \u2190 Cardinal.mk_fintype]\n  exact Cardinal.mk_subtype_mono fun x hx => hx.2\n#align nat.count_le_cardinal Nat.count_le_cardinal\n\n#print Nat.lt_of_count_lt_count /-\ntheorem lt_of_count_lt_count {a b : \u2115} (h : count p a < count p b) : a < b :=\n  (count_monotone p).reflect_lt h\n#align nat.lt_of_count_lt_count Nat.lt_of_count_lt_count\n-/\n\n#print Nat.count_strict_mono /-\ntheorem count_strict_mono {m n : \u2115} (hm : p m) (hmn : m < n) : count p m < count p n :=\n  (count_lt_count_succ_iff.2 hm).trans_le <| count_monotone _ (Nat.succ_le_iff.2 hmn)\n#align nat.count_strict_mono Nat.count_strict_mono\n-/\n\n#print Nat.count_injective /-\ntheorem count_injective {m n : \u2115} (hm : p m) (hn : p n) (heq : count p m = count p n) : m = n :=\n  by\n  by_contra' h : m \u2260 n\n  wlog hmn : m < n\n  \u00b7 exact this hn hm HEq.symm h.symm (h.lt_or_lt.resolve_left hmn)\n  \u00b7 simpa [HEq] using count_strict_mono hm hmn\n#align nat.count_injective Nat.count_injective\n-/\n\n#print Nat.count_le_card /-\ntheorem count_le_card (hp : (setOf p).Finite) (n : \u2115) : count p n \u2264 hp.toFinset.card :=\n  by\n  rw [count_eq_card_filter_range]\n  exact Finset.card_mono fun x hx => hp.mem_to_finset.2 (mem_filter.1 hx).2\n#align nat.count_le_card Nat.count_le_card\n-/\n\n#print Nat.count_lt_card /-\ntheorem count_lt_card {n : \u2115} (hp : (setOf p).Finite) (hpn : p n) : count p n < hp.toFinset.card :=\n  (count_lt_count_succ_iff.2 hpn).trans_le (count_le_card hp _)\n#align nat.count_lt_card Nat.count_lt_card\n-/\n\nvariable {q : \u2115 \u2192 Prop}\n\nvariable [DecidablePred q]\n\n#print Nat.count_mono_left /-\ntheorem count_mono_left {n : \u2115} (hpq : \u2200 k, p k \u2192 q k) : count p n \u2264 count q n :=\n  by\n  simp only [count_eq_card_filter_range]\n  exact card_le_of_subset ((range n).monotone_filter_right hpq)\n#align nat.count_mono_left Nat.count_mono_left\n-/\n\nend Count\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8289388167733099, "lm_q1q2_score": 0.7172178214935817}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Sets in Lean, example sheet 2 : the empty set and the \"universal set\".\n\nWe know what the empty subset of `X` is, and the Lean notation for\nit is `\u2205`, or, if you want to say which type we're the empty subset\nof, it's `\u2205 : set X`. \n\nAt the other extreme, the subset of `X` containing all the terms of type `X`\nis...well...mathematicians would just call it `X`, but `X` is a type, and\nso if we want a set it's called `set.univ : set X`, or just `univ : set X` if\nwe have opened the `set` namespace. Let's do that now.\n\n-/\n\nopen set\n\n/-\n\n## Important\n\n`x \u2208 \u2205` is *by definition* equal to `false` and `x \u2208 univ` is *by definition*\nequal to `true`. You can use the `change` tactic to make these changes\nif you like. But you don't have to.\n\n## Tactics you will need\n\nYou've seen them already. `trivial` proves `\u22a2 true` and `exfalso`\nchanges `\u22a2 P` to `\u22a2 false`.\n\n-/\n\n\n-- set up variables\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D E : set X) -- A,B,C,D,E are subsets of `X`\n  (x y z : X) -- x,y,z are elements of `X` or, more precisely, terms of type `X`\n\n/-\n\nIf `x : X` then `x \u2208 \u2205` is *by definition* `false`, and `x \u2208 univ` is\n*by definition* `true`. So you can use the `change` tactic to change\nbetween these things, for example if your goal is\n\n```\n\u22a2 x \u2208 univ\n```\n\nthen `change true` will change the goal to\n\n```\n\u22a2 true\n```\n\nand you can now prove this goal with `trivial`. However you can prove\nit with `trivial` even without `change`ing it.\n\n-/\n\nopen set\n\nexample : x \u2208 (univ : set X) := \nbegin\n  trivial,\nend\n\nexample : x \u2208 (\u2205 : set X) \u2192 false :=\nbegin\n  intro h,\n  exact h,\nend\n\nexample : \u2200 x : X, x \u2208 A \u2192 x \u2208 (univ : set X) :=\nbegin\n  intros x h,\n  trivial,\nend\n\nexample : \u2200 x : X, x \u2208 (\u2205 : set X) \u2192 x \u2208 A :=\nbegin\n  intros x h,\n  exfalso,\n  exact h,\nend\n\n", "meta": {"author": "Siesta233", "repo": "LeanPractice", "sha": "3795eeb8763edacf2c74b9c8925f642d6cc56daf", "save_path": "github-repos/lean/Siesta233-LeanPractice", "path": "github-repos/lean/Siesta233-LeanPractice/LeanPractice-3795eeb8763edacf2c74b9c8925f642d6cc56daf/src/sets/Sets2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7172178207179932}}
{"text": "-- always import the tactics, we are mathematicians\nimport tactic\n-- import the theory of G-module homomorphisms, for G a group\nimport algebra.group_action_hom\n\n/-\n\n# Introduction to G-modules in Lean\n\nLet `G` be a group (with group law `*`) and let `M` be an abelian\ngroup (with group law `+`). A `G`-action on `M` is just a group\nhomomorphism from `G` to the group automorphisms\nof `M`, or in other words an action `\u2022` of `G` on `M` (in the sense\nof groups acting on sets/types) satisfying\nthe axiom `smul_add g m n : g \u2022 (m + n) = g \u2022 m + g \u2022 n`.\n\nThe goal of this workshop will be to set up a cohomology theory\nfor G-modules. We will just do H\u2070 (G-invariant elements)\nand H\u00b9 (1-cocycles modulo coboundaries), but clearly one\ncould go on to 2-cocycles, n-cocycles etc.\n\n### typeclass comments (\"will it work for monoids/add_monoids?\")\n\nNote that the definition of G-module does not mention `g\u207b\u00b9` at all, so\nwe can even define it for monoids `G`, which we will. Loads\nof the theory works for `G` a monoid in fact (certainly everything\nwe do in this workshop). But we use subtraction on `M` quite a\nlot in practice when we get to `H\u00b9` (e.g. the coboundary `g b - b`\nneeds subtraction) so I've assumed that `M` is an abelian group throughout for\npedagogical reasons (and because it solved some typeclass issue at some point).\n\nThe `G`-module structure on `M` is called `distrib_mul_action G M` in Lean.\n-/\n\nsection distrib_mul_action_stuff\n\n/- \n\n## The interface for G-modules, i.e. the theory of `\u2022`\n\nIn Lean we learn about the typeclass `[distrib_mul_action G M]`, \nwhich gives us the notation `\u2022` for an action of `G` on `M`,\nand all the axioms.\n\nNotation for this section:\n\nLet `G` be a group. Let `M` be an abelian group and furthermore\nassume `M` is a `G`-module. We use the usual notation `(g\u2081 * g\u2082) \u2022 (m\u2081 + m\u2082)`\n\n-/\n\nvariables\n  {G : Type} [monoid G] --`*`\n  {M : Type} [add_comm_group M] --`+`\n  [distrib_mul_action G M] --`\u2022`\n\n-- Let `g`'ish variables be elements of `G`, and let `m`ish variables be\n-- elements of `M`.\nvariables (g g1 g2 g\u2081 g\u2082 : G) (m m1 m2 m\u2081 m\u2082 : M)\n\n/-\n\n### The interface for `\u2022`\n\nBelow are the names of the theorem proofs which you will need\nto know when manipulating an element of a fixed `G`-module,\nfor example the element `(g\u2081 * g\u2082) \u2022 (m\u2081 + m\u2082)`.\n\nI have explained the names of the proofs in the form\nof examples. The syntax for the examples is this:\n\n`example : <Theorem statement> := <name of proof function> input1 input2 ...`\n\nSo these examples tell you the names of the proofs of the theorems.\nThe proofs are functions which need inputs, and the inputs are\nthe variables used in the theorem statement. I also mention\nwhether Lean's \"rw-machine\" (the `simp` tactic) knows about these theorems.\n\n-/\n\nexample : g \u2022 (0 : M) = 0 := smul_zero g -- a simp lemma\nexample : g \u2022 (m\u2081 + m\u2082) = g \u2022 m\u2081 + g \u2022 m\u2082 := smul_add g m\u2081 m\u2082 -- a simp lemma \nexample : g \u2022 (-m) = -(g \u2022 m) := smul_neg g m -- a simp lemma\nexample : (1 : G) \u2022 m = m := one_smul G m -- a simp lemma\nexample : g \u2022 (m\u2081 - m\u2082) = g \u2022 m\u2081 - g \u2022 m\u2082 := smul_sub g m\u2081 m\u2082 -- at the time of writing not a simp lemma\nexample : (g\u2081 * g\u2082) \u2022 m = g\u2081 \u2022 g\u2082 \u2022 m := mul_smul g\u2081 g\u2082 m -- not a simp lemma\n\n-- try some examples for yourself.\nexample : (g1 * g2) \u2022 (m1 + m2) = g1 \u2022 g2 \u2022 m1 + g1 \u2022 g2 \u2022 m2 :=\nbegin\n  sorry\nend\n\nexample : (1 * 1 * 1 : G) \u2022 m = m :=\nbegin\n  sorry\nend \n\nend distrib_mul_action_stuff\n\n/-\n\n### Entirely optional digression on `simp`\n\nSome of those lemmas above were \"simp lemmas\" (if you `#print one_smul`\nyou'll see it has a `@[simp]` tag). What makes a good simp lemma?\n\nThe most important rule is that, unless you really know what you're\ndoing, it should be of the form `A = B` or `A \u2194 B`.\n\nThe second rule is that the right hand side should in some sense\nbe \"simpler than\" the left hand side.\nso the lemma should say `A simplifies_to B`, indicating a flow towards\na solution.\n\nFor example `one_mul : 1 * a = a` is a `simp` lemma for groups (and\nfor monoids), because it is an equality, and the right hand side\nis unarguably simpler than the left hand side. \n\nLater on we'll be making some of our own structures, and\nwe will want to train Lean's simplifier to use those structures. The better\nyou understand how the simplifier works on your structures, the easier you\nwill find it to type \"mathematics as the mathematician thinks about it\"\ninto Lean.\n\n-/\n\n/-\n\n### The `simp` tactic\n\nA lemma is, by definition, a `simp` lemma, if its proof term is tagged\nwith the `@[simp]` attribute (you can check a term's attributes with `#print`)\n\n`simp` is an algorithm which will \"follow its nose\", doing\nstuff like expanding out brackets automatically and tidying up.\nIt would tidy up by simplifying `g \u2022 0` to `0` for example,\nand it would expand out by changing `g \u2022 (m\u2081 + m\u2082)` to `g \u2022 m\u2081 + g \u2022 m\u2082`.\nIn general `simp` tries to rewrite equivalences, e.g. things of the\nform `A = B` or `A \u2194 B`, with in each case `B` the \"simplified\" or\n\"expanded out\" version of `A`. The equivalences it rewrites\nwith are the ones in its database of a few thousand (*shrug?)\nso-called \"`simp` lemmas\" For example, if `\u21d10 : G \u2192 M` is the\nzero function then `zero_val g : \u21d10 g = 0` would be a good `simp`\nlemma, which is why it is tagged with the `@[simp]` attribute,\nmaking it part of the database.\n\nNote that `simp` does not have \"ideas\". It will never apply\ncommutativity or associativity, for example, for fear that\nit might be a waste of time which would have to be undone later.\n`simp` will solve `x + 0 = x` but it will not solve `m + n = n + m`,\nbecause it is not so clear that the right hand side is any simpler\nthan the left hand side. problems like that you need `abel`.\n\nTo learn more about `simp`, check out the simp docs on\nthe leanprover-community website.\n-- TODO when online -- add link to simp docs in API at leanprover-community website\n\n## A note on `abel`\n\n`abel` should be able to solve all problems in abelian groups\nof the form \u2200 a b c, a + (c + -b) = (a - b) + c etc.\nNote however that it *cannot use hypotheses*. It will only\nprove identities which are true in all abelian groups. \n\n-/\nexample (M : Type) [add_comm_group M] (a b c : M) :\n  a + (c + -b) = (a - b) + c := by abel\n\n/-\n## The interface for morphisms of G-modules, i.e. the theory of `\u2192+[_]`\n\nLean uses notation `M \u2192+[G] N` and name `distrib_mul_action_hom`,\nbut you don't need to remember the name, it should work in the \nbackground for you.\n\nThe type of G-module homs from `M` to `N`, i.e. the set\nthat a mathematician would call something like $$\\Hom_G(M,N)$$,\nis in Lean called `M \u2192+[G] N`. The non-notation name for this function\ntype is `distrib_mul_action_hom G M N`, which is why you see this word in\nnamespaces or mentioned in sections.\n\nTerms of this type are `G`-module morphisms from `M` to `N`.\nSo when we see `\u03c6 : M \u2192+[G] N` it means that `\u03c6` is a G-module hom\nfrom `M` to `N`. We will often only be using `\u03c6` only in terms of its\nassociated function `\u21d1\u03c6 : M \u2192 N`. `\u03c6` itself is a package, consisting\nof a function and a bunch of theorems about that function.\n\n-/\n\nnamespace distrib_mul_action_hom\n\n-- let's do the variables\nvariables \n-- let `G` be a group (or a monoid)\n{G : Type} [monoid G]\n\n{M : Type}  [add_comm_group M] [distrib_mul_action G M] -- let `M` be a `G`-module\n{N : Type}  [add_comm_group N] [distrib_mul_action G N] -- let `N` be a `G`-module\n(\u03c6 : M \u2192+[G] N) -- let \u03c6 be a morphism of G-modules\n(g : G) (m m\u2081 m\u2082 m1 m2 : M) -- random useful variable names\n\n/-\n\n### API for `M \u2192+[G] N`\n\nHere are the names of the proofs of the basic axioms for G-module\nmorphisms. The proofs are in the `\u2192+[_]` namespace, so you can\nwrite things like `\u03c6.map_smul` to access them easily.\n\n-/\nexample : \u03c6 (g \u2022 m) = g \u2022 (\u03c6 m) := \u03c6.map_smul g m -- a simp lemma\nexample (m\u2081 m\u2082 : M) : \u03c6 (m\u2081 + m\u2082) = \u03c6 m\u2081 + \u03c6 m\u2082 := \u03c6.map_add m\u2081 m\u2082 -- a simp lemma\n\nexample : \u03c6 (g \u2022 (m\u2081 + m\u2082)) = g \u2022 \u03c6 m\u2081 + g \u2022 \u03c6 m\u2082 :=\nbegin\n  -- what will you rewrite? Will you rewrite at all?\n  sorry\nend\n\n/-\n\n\n## A G-module morphism is a pair of things\n\nA G-module morphism `\u03c6 : M \u2192+[G] N` is two things.\n1) a function `\u21d1\u03c6 : M \u2192 N`\n2) the dot notation system for `\u03c6`, a database where\nall the axioms and theorems for G-module homs as applied to `\u03c6` are stored.\n\nFor example, the type of \u03c6.map_smul is *actually* a theorem about `\u21d1\u03c6`.\n\n`\u03c6.map_smul g m : \u21d1\u03c6 (g \u2022 m) = g \u2022 \u21d1\u03c6 m`\n\n\n-/\n\nexample (\u03c6 : M \u2192+[G] N) : \u03c6 0 = 0 :=\nbegin\n  -- library_search will take some time (I don't know why)\n  -- but will eventually find the answer to this one. \n  -- But you can guess it quicker!\n  -- what will you rewrite?\n  sorry\nend\n\n-- Can you solve it in term mode like in those earlier examples?\nexample : \u03c6 0 = 0 := sorry\n\n-- Can you change `sorry` to the name of a tactic?\nexample : \u03c6 0 = 0 := by sorry\n\n/-\n\n### Composition of G-module morphisms\n\nYou know how to compose functions, you just write `\u03c8 (\u03c6 a)`\nor whatever. Composition in the category of G-modules is\ndone with the `comp` method for `G`-module morphisms.\n\n-/\n\n-- let P be another G-module\nvariables {P : Type} [add_comm_monoid P] [distrib_mul_action G P]\n\n-- Recall `\u03c6 : M \u2192+[G] N` from earlier.\n-- let \u03c8 : N \u2192 P be another G-module morphism\nvariable (\u03c8 : N \u2192+[G] P) -- his is notation for `\u03c8 : distrib_mul_action_hom G N P`\n\n-- let's make function composition notation\ninfixr ` \u2218\u1d4d `:90 := distrib_mul_action_hom.comp\n\n-- how to compose G-module maps\nexample : M \u2192+[G] P := \u03c8 \u2218\u1d4d \u03c6\n\n-- You should think of \u03c6 and \u03c8 as morphisms in the category\n-- of `G`-modules. They are functions, but they also have\n-- some extra category-theoretic baggage (proofs that they\n-- are G-linear maps) which needs to be moved around.\n\n-- KB NOTE TO SELF do we ever actually compose morphisms?\n-- My definition of short exact sequence of G-modules\n-- is \"image = kernel\" , which is highly category-theoretic.\n-- and functional evaluation often takes place after that.\n\n-- The important fact is that `(\u03c8 \u2218 \u03c6) m = \u03c8 (\u03c6 m)`, as\n-- terms of type `P`. Rather nicely, this theorem is called\n-- `\u03c8.comp_apply` but it is also a `simp` lemma, and \n-- furthermore true by definition\nexample (m : M) :\n  (\u03c8 \u2218\u1d4d \u03c6) m = \u03c8 (\u03c6 m) := \u03c8.comp_apply \u03c6 m -- and `rfl` works too and `by simp`\n\nexample (m : M) :\n  -- normal function composition\n  (\u03c8 \u2218 \u03c6) m = \u03c8 (\u03c6 m) := \u03c8.comp_apply \u03c6 m -- and `rfl` works too and `by simp`\n\n-- By the way, `squeeze_simp` is a version of `simp` which tells you \n-- which rewrites it did. Give it a try!\nexample :\n  (\u03c8 \u2218\u1d4d \u03c6) (g \u2022 (m1 + m2)) = g \u2022 (\u03c8 (\u03c6 m1) + \u03c8 (\u03c6 m2)) :=\nbegin\n  simp,\nend\n\nend distrib_mul_action_hom\n\nsection exactness_stuff\n\n/-\n\n## A half-developed API for exact sequences\n\nI will do this one because right now we are missing some definitions.\nSOME OF THE SORRYS IN THIS SECTION ARE CURRENTLY UNSOLVABLE -- JUST\nLEAVE THEM ALL ALONE\n\n-/\n\n-- Let M, N and P be G-modules\nvariables {G M N P : Type}\n  [monoid G] [add_comm_group M] [add_comm_group N] [add_comm_group P]\n  [distrib_mul_action G M] [distrib_mul_action G N] [distrib_mul_action G P]\n\n/-\n\n### Stubbing out a theory\n \nI need to talk about kernels and images as G-module maps.\nJobo is writing this. I just stub out the theory and\nsorry the proofs I need, but sorrying definitions comes\nwith problems.\n\n-/\n\n-- THE WRONG DEFINITION\nstructure sub_distrib_mul_action\n  (G : Type) [monoid G]\n  (M : Type) [add_comm_group M] [distrib_mul_action G M] :=\n(carrier : set M)\n\n-- LEAVE THESE FOUR SORRYS ALONE\ndef distrib_mul_action_hom.ker (\u03c6 : M \u2192+[G] N) :\n  sub_distrib_mul_action G M :=\n\u27e8{m | \u03c6 m = 0}\u27e9\n\ndef distrib_mul_action_hom.range (\u03c6 : M \u2192+[G] N) :\n  sub_distrib_mul_action G N :=\n\u27e8set.range \u03c6\u27e9\n\ninstance : has_coe (sub_distrib_mul_action G M) (set M) :=\n\u27e8sub_distrib_mul_action.carrier\u27e9\n\ntheorem sub_distrib_mul_action.ext_iff {A B : sub_distrib_mul_action G M} :\n  A = B \u2194 \u2200 m : M, m \u2208 (A : set M) \u2194 m \u2208 (B : set M) := sorry\n\n/-\n\nThat stuff above will all be deleted at some point\n\n-/\n\n-- It doesn't matter what the internal definition because the end user\n-- will only be using `is_short_exact` for G-modules.\ndefinition is_exact (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) : Prop :=\n\u03c6.range = \u03c8.ker\n\n/-\n\n### Mathematicians have more than one \"definition\" of `is_exact`\n\nOf course exactness means the image is the kernel, of course it\nmeans for every n, n is in the image iff n is in the kernel,\nand of course it means `\u2200 n : N, (\u2203 m : M, \u03c6 m = n) \u2194 \u03c8 n` because\nto a mathematician all of these ideas are *the same thing*.\n\nIn Lean some of these things are definitionally equal, some\nequivalences involve coercions, some use set extensionality.\nBut we need to make sure that we offer the mathematician all\npossible useful definitions of being \"true by definition\" . \n\n-/\n\n\n-- definition of exact in category theory world\n@[simp] lemma is_exact.def_cat (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) :\n  is_exact \u03c6 \u03c8 \u2194 \u03c6.range = \u03c8.ker := iff.rfl\n\n-- THIS SORRIED THEOREM CANNOT BE SOLVED UNTIL THE SORRIED DEFS ARE MADE\n-- definition of exact in set theory world\n@[simp] lemma is_exact.def_set (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) :\n  is_exact \u03c6 \u03c8 \u2194 \u2200 n : N, (\u2203 m : M, \u03c6 m = n) \u2194 \u03c8 n = 0 :=\nbegin\n  rw is_exact.def_cat,\n  rw sub_distrib_mul_action.ext_iff, \n  sorry, -- will be refl once we have sub-G-modules.\nend\n\n/-\n\n## Making an API for short exact sequences.\n\nThis is just basic logic and should be accessible to anyone who knows\nthe mathematics and has played the natural number game.\n\n-/\nopen function\n\n-- here is the docstring for short exact sequences\n\n/--\nFundamental to cohomology theory is the concept of a short\nexact sequence. If `\u03c6 : M \u2192+[G] N` and\n`\u03c8 : N \u2192+[G] P` are G-module morphisms, `is_short_exact \u03c6 \u03c8` \nis the proposition stating that `0 \u2192 M -\u03c6\u2192 N -\u03c8\u2192 P \u2192 0` is short exact\nin the usual sense, that is:\n\n*) `\u03c6` is injective, \n*) the range of `\u03c6` equals the kernel of `\u03c8`,\n*) `\u03c8` is surjective. \n\nIf `h : is_short_exact \u03c6 \u03c8` then you can access various standard\nfacts about `\u03c6` and `\u03c8` using dot notation with `h`. For example\n`h.injective` is the proof that `\u03c6` is injective, and \n`h.exact_set` is the proof of some expanded-out version of the\nstatement that an element `n` is in the image\nof `\u03c6` if and only if it is in the kernel of `\u03c8`. A rather more\ncompact definition is `h.exact_cat`.\n-/\n-- This will do for an internal definition. The user should\n-- never have to think about that though.\ndef is_short_exact (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P) : Prop :=\n  is_exact \u03c6 \u03c8 \u2227 injective \u03c6 \u2227 surjective \u03c8\n\n-- We need to make a nice API for this, it's easy and fun.\n\nvariables (\u03c6 : M \u2192+[G] N) (\u03c8 : N \u2192+[G] P)\n\n-- useful for rewrites when we're making the API, but the user\n-- should never see this.\nprotected lemma is_short_exact_def :\n  is_short_exact \u03c6 \u03c8 \u2194 is_exact \u03c6 \u03c8 \u2227 injective \u03c6 \u2227 surjective \u03c8 :=\n-- true by definition\niff.rfl\n\n-- I marked it protected because the end user should never have\n-- to use this lemma in this repo, they should always use the `h.injective`\n-- dot notation.\n\n-- Now the proper API\nnamespace is_short_exact\n\n-- We are making the API so we are allowed to unfold stuff\n\nvariables {\u03c6} {\u03c8} (h : is_short_exact \u03c6 \u03c8)\n\ninclude h\ndef injective : injective \u03c6 :=\nbegin\n  /- put your infoview filter onto only props.\n     You see\n\n     h: is_short_exact \u03c6 \u03c8\n     \u22a2 injective \u21d1\u03c6\n  \n     That's the question. You can take `h` apart\n     with `cases`, and even more effectively with\n     `rcases`.\n  -/\n  sorry,\nend\n\n\ndef surjective : surjective \u03c8 :=\nbegin\n  sorry,\nend\n\n-- again we don't really want the user messing\n-- with this internal function, it should be thought\n-- of as \"an abbreviation for several things\".\nprotected def exact : is_exact \u03c6 \u03c8 := h.1\n\n-- now `h.exact` is the proof that the short exact sequence\n-- corresponding to `h` is exact.\n\n/--\nIn a short exact sequence `short_exact_sequence \u03c6 \u03c8`,\nan element of the middle module is in the\nimage of `\u03c6` if and only if it is in the kernel of `\u03c8`.   -/\ntheorem exact_set : \u2200 n : N, (\u2203 m : M, \u03c6 m = n) \u2194 \u03c8 n = 0 :=\nbegin\n  sorry,\nend\n\n/--\nIn a short exact sequence `short_exact_sequence \u03c6 \u03c8`,\nthe image of `\u03c6` equals kernel of `\u03c8`.   -/\ndef exact_cat : \u03c6.range = \u03c8.ker :=\nbegin\n  sorry,\nend\n\n/-\n\n### Some more API for short exact sequences.\n\nIt's convenient to define a noncomputable function using axiom of choice,\nwhich is a random splitting of the surjection \u03c8 : P \u2192 N and hence a\none-sided inverse. We will need such a function when doing boundary maps.\nWe call this function `inverse_\u03c8` and prove `\u03c8 (inverse_\u03c8 p) = p` .\nWe also define `inverse_\u03c6` -- given `n : N` and a proof that \nit's in the image of `\u03c6`, I pull back `n` to some explicit `inverse_\u03c6 n : M`\nand prove `\u03c6 (inverse_\u03c6 n) = n`. \n\nThis use of the axiom of choice is a bit delicate so I'll do it.\n-/\n\nnoncomputable def inverse_\u03c8 : P \u2192 N := \u03bb p, classical.some (h.surjective p)\n\n@[simp] lemma inverse_\u03c8_spec (p : P) : \u03c8 (h.inverse_\u03c8 p) = p :=\nclassical.some_spec (h.surjective p)\n\n-- now the same sort of thing for the injection \u03c6 : M \u2192 N; this is\n-- the map from the image of \u03c6 back to M.\nnoncomputable def inverse_\u03c6 (h : is_short_exact \u03c6 \u03c8) (n : N)\n  (hn : \u2203 m : M, \u03c6 m = n) : M :=\nclassical.some hn\n\n@[simp]\nlemma inverse_\u03c6_def (h : is_short_exact \u03c6 \u03c8) {n : N} (hn : \u2203 m : M, \u03c6 m = n) :\n  \u03c6 (h.inverse_\u03c6 n hn) = n :=\nclassical.some_spec hn\n\n-- injectivity implies it's independent of choice, but we used choice anyway\n@[simp] lemma inverse_\u03c6_spec (h : is_short_exact \u03c6 \u03c8) {n : N} {m : M}\n  (hm : \u03c6 m = n) : h.inverse_\u03c6 _ \u27e8m, hm\u27e9 = m :=\nbegin\n  apply h.injective,\n  rw hm,\n  exact classical.some_spec \u27e8m, hm\u27e9,\nend\n\nend is_short_exact\n\nend exactness_stuff\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_8/Part_A_G_modules.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7172178076436053}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n-/\nimport data.real.sqrt\n\n/-!\n# The complex numbers\n\nThe complex numbers are modelled as \u211d^2 in the obvious way and it is shown that they form a field\nof characteristic zero. The result that the complex numbers are algebraically closed, see\n`field_theory.algebraic_closure`.\n-/\n\nopen_locale big_operators\n\n/-! ### Definition and basic arithmmetic -/\n\n/-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\nopen_locale complex_conjugate\n\nnoncomputable instance : decidable_eq \u2102 := classical.dec_eq _\n\n/-- The equivalence between the complex numbers and `\u211d \u00d7 \u211d`. -/\n@[simps] def equiv_real_prod : \u2102 \u2243 (\u211d \u00d7 \u211d) :=\n{ to_fun := \u03bb z, \u27e8z.re, z.im\u27e9,\n  inv_fun := \u03bb p, \u27e8p.1, p.2\u27e9,\n  left_inv := \u03bb \u27e8x, y\u27e9, rfl,\n  right_inv := \u03bb \u27e8x, y\u27e9, rfl }\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8a, b\u27e9 := rfl\n\n@[ext]\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\ninstance : has_coe \u211d \u2102 := \u27e8\u03bb r, \u27e8r, 0\u27e9\u27e9\n\n@[simp, norm_cast] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\nlemma of_real_def (r : \u211d) : (r : \u2102) = \u27e8r, 0\u27e9 := rfl\n\n@[simp, norm_cast] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\ntheorem of_real_injective : function.injective (coe : \u211d \u2192 \u2102) :=\n\u03bb z w, congr_arg re\n\ninstance : can_lift \u2102 \u211d :=\n{ cond := \u03bb z, z.im = 0,\n  coe := coe,\n  prf := \u03bb z hz, \u27e8z.re, ext rfl hz.symm\u27e9 }\n\n/-- The product of a set on the real axis and a set on the imaginary axis of the complex plane,\ndenoted by `s \u00d7\u2102 t`. -/\ndef _root_.set.re_prod_im (s t : set \u211d) : set \u2102 := re \u207b\u00b9' s \u2229 im \u207b\u00b9' t\n\ninfix ` \u00d7\u2102 `:72 := set.re_prod_im\n\ninstance : has_zero \u2102 := \u27e8(0 : \u211d)\u27e9\ninstance : inhabited \u2102 := \u27e80\u27e9\n\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\ninstance : has_one \u2102 := \u27e8(1 : \u211d)\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\n@[simp] theorem of_real_eq_one {z : \u211d} : (z : \u2102) = 1 \u2194 z = 1 := of_real_inj\ntheorem of_real_ne_one {z : \u211d} : (z : \u2102) \u2260 1 \u2194 z \u2260 1 := not_congr of_real_eq_one\n\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n\n@[simp] lemma bit0_re (z : \u2102) : (bit0 z).re = bit0 z.re := rfl\n@[simp] lemma bit1_re (z : \u2102) : (bit1 z).re = bit1 z.re := rfl\n@[simp] lemma bit0_im (z : \u2102) : (bit0 z).im = bit0 z.im := eq.refl _\n@[simp] lemma bit1_im (z : \u2102) : (bit1 z).im = bit0 z.im := add_zero _\n\n@[simp, norm_cast] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s :=\next_iff.2 $ by simp\n\n@[simp, norm_cast] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r :=\next_iff.2 $ by simp [bit0]\n\n@[simp, norm_cast] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r :=\next_iff.2 $ by simp [bit1]\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n@[simp, norm_cast] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\ninstance : has_sub \u2102 := \u27e8\u03bb z w, \u27e8z.re - w.re, z.im - w.im\u27e9\u27e9\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp, norm_cast] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\nlemma of_real_mul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp\nlemma of_real_mul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp\nlemma of_real_mul' (r : \u211d) (z : \u2102) : (\u2191r * z) = \u27e8r * z.re, r * z.im\u27e9 :=\next (of_real_mul_re _ _) (of_real_mul_im _ _)\n\n/-! ### The imaginary unit, `I` -/\n\n/-- The imaginary unit. -/\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := rfl\n@[simp] lemma I_im : I.im = 1 := rfl\n\n@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp\nlemma I_mul (z : \u2102) : I * z = \u27e8-z.im, z.re\u27e9 :=\next_iff.2 $ by simp\n\nlemma I_ne_zero : (I : \u2102) \u2260 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\next_iff.2 $ by simp\n\n/-! ### Commutative ring instance and lemmas -/\n\n/- We use a nonstandard formula for the `\u2115` and `\u2124` actions to make sure there is no\ndiamond from the other actions they inherit through the `\u211d`-action on `\u2102` and action transitivity\ndefined in `data.complex.module.lean`. -/\ninstance : comm_ring \u2102 :=\nby refine_struct\n  { zero := (0 : \u2102),\n    add := (+),\n    neg := has_neg.neg,\n    sub := has_sub.sub,\n    one := 1,\n    mul := (*),\n    zero_add := \u03bb z, by { apply ext_iff.2, simp },\n    add_zero := \u03bb z, by { apply ext_iff.2, simp },\n    nsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9,\n    npow := @npow_rec _ \u27e8(1 : \u2102)\u27e9 \u27e8(*)\u27e9,\n    zsmul := \u03bb n z, \u27e8n \u2022 z.re - 0 * z.im, n \u2022 z.im + 0 * z.re\u27e9 };\nintros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}\n\n/-- This shortcut instance ensures we do not find `ring` via the noncomputable `complex.field`\ninstance. -/\ninstance : ring \u2102 := by apply_instance\n\n/-- The \"real part\" map, considered as an additive group homomorphism. -/\ndef re_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := re,\n  map_zero' := zero_re,\n  map_add' := add_re }\n\n@[simp] lemma coe_re_add_group_hom : (re_add_group_hom : \u2102 \u2192 \u211d) = re := rfl\n\n/-- The \"imaginary part\" map, considered as an additive group homomorphism. -/\ndef im_add_group_hom : \u2102 \u2192+ \u211d :=\n{ to_fun := im,\n  map_zero' := zero_im,\n  map_add' := add_im }\n\n@[simp] lemma coe_im_add_group_hom : (im_add_group_hom : \u2102 \u2192 \u211d) = im := rfl\n\n@[simp] lemma I_pow_bit0 (n : \u2115) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [pow_bit0', I_mul_I]\n\n@[simp] lemma I_pow_bit1 (n : \u2115) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [pow_bit1', I_mul_I]\n\n/-! ### Complex conjugation -/\n\n/-- This defines the complex conjugate as the `star` operation of the `star_ring \u2102`. It\nis recommended to use the ring endomorphism version `star_ring_end`, available under the\nnotation `conj` in the locale `complex_conjugate`. -/\ninstance : star_ring \u2102 :=\n{ star := \u03bb z, \u27e8z.re, -z.im\u27e9,\n  star_involutive := \u03bb x, by simp only [eta, neg_neg],\n  star_mul := \u03bb a b, by ext; simp [add_comm]; ring,\n  star_add := \u03bb a b, by ext; simp [add_comm] }\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := rfl\n\nlemma conj_of_real (r : \u211d) : conj (r : \u2102) = r := ext_iff.2 $ by simp [conj]\n\n@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp\n\nlemma conj_bit0 (z : \u2102) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]\nlemma conj_bit1 (z : \u2102) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0]\n\n@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp\n\nlemma eq_conj_iff_real {z : \u2102} : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n\u27e8\u03bb h, \u27e8z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)\u27e9,\n \u03bb \u27e8h, e\u27e9, by rw [e, conj_of_real]\u27e9\n\nlemma eq_conj_iff_re {z : \u2102} : conj z = z \u2194 (z.re : \u2102) = z :=\neq_conj_iff_real.trans \u27e8by rintro \u27e8r, rfl\u27e9; simp, \u03bb h, \u27e8_, h.symm\u27e9\u27e9\n\nlemma eq_conj_iff_im {z : \u2102} : conj z = z \u2194 z.im = 0 :=\n\u27e8\u03bb h, add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)),\n  \u03bb h, ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))\u27e9\n\n-- `simp_nf` complains about this being provable by `is_R_or_C.star_def` even\n-- though it's not imported by this file.\n@[simp, nolint simp_nf] lemma star_def : (has_star.star : \u2102 \u2192 \u2102) = conj := rfl\n\n/-! ### Norm squared -/\n\n/-- The norm squared function. -/\n@[pp_nodot] def norm_sq : \u2102 \u2192*\u2080 \u211d :=\n{ to_fun := \u03bb z, z.re * z.re + z.im * z.im,\n  map_zero' := by simp,\n  map_one' := by simp,\n  map_mul' := \u03bb z w, by { dsimp, ring } }\n\nlemma norm_sq_apply (z : \u2102) : norm_sq z = z.re * z.re + z.im * z.im := rfl\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mk (x y : \u211d) : norm_sq \u27e8x, y\u27e9 = x * x + y * y := rfl\n\nlemma norm_sq_add_mul_I (x y : \u211d) : norm_sq (x + y * I) = x ^ 2 + y ^ 2 :=\nby rw [\u2190 mk_eq_add_mul_I, norm_sq_mk, sq, sq]\n\nlemma norm_sq_eq_conj_mul_self {z : \u2102} : (norm_sq z : \u2102) = conj z * z :=\nby { ext; simp [norm_sq, mul_comm], }\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := norm_sq.map_zero\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := norm_sq.map_one\n@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\nlemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\n\u27e8\u03bb h, ext\n  (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n  (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),\n \u03bb h, h.symm \u25b8 norm_sq_zero\u27e9\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\n(norm_sq_nonneg z).lt_iff_ne.trans $ not_congr (eq_comm.trans norm_sq_eq_zero)\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\nlemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nnorm_sq.map_mul z w\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nby dsimp [norm_sq]; ring\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\next_iff.2 $ by simp [two_mul]\n\n/-- The coercion `\u211d \u2192 \u2102` as a `ring_hom`. -/\ndef of_real : \u211d \u2192+* \u2102 := \u27e8coe, of_real_one, of_real_mul, of_real_zero, of_real_add\u27e9\n\n@[simp] lemma of_real_eq_coe (r : \u211d) : of_real r = r := rfl\n\n@[simp] lemma I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]\n\n@[simp] lemma sub_re (z w : \u2102) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : \u2102) : (z - w).im = z.im - w.im := rfl\n@[simp, norm_cast] lemma of_real_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s := ext_iff.2 $ by simp\n@[simp, norm_cast] lemma of_real_pow (r : \u211d) (n : \u2115) : ((r ^ n : \u211d) : \u2102) = r ^ n :=\nby induction n; simp [*, of_real_mul, pow_succ]\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\next_iff.2 $ by simp [two_mul, sub_eq_add_neg]\n\nlemma norm_sq_sub (z w : \u2102) : norm_sq (z - w) =\n  norm_sq z + norm_sq w - 2 * (z * conj w).re :=\nby { rw [sub_eq_add_neg, norm_sq_add],\n     simp only [ring_hom.map_neg, mul_neg, neg_re,\n                tactic.ring.add_neg_eq_sub, norm_sq_neg] }\n\n/-! ### Inversion -/\n\nnoncomputable instance : has_inv \u2102 := \u27e8\u03bb z, conj z * ((norm_sq z)\u207b\u00b9:\u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((norm_sq z)\u207b\u00b9:\u211d) := rfl\n@[simp] lemma inv_re (z : \u2102) : (z\u207b\u00b9).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : \u2102) : (z\u207b\u00b9).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\n@[simp, norm_cast] lemma of_real_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = r\u207b\u00b9 :=\next_iff.2 $ by simp\n\nprotected \n\nprotected theorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nby rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 of_real_mul,\n  mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]\n\n/-! ### Field instance and lemmas -/\n\nnoncomputable instance : field \u2102 :=\n{ inv := has_inv.inv,\n  exists_pair_ne := \u27e80, 1, mt (congr_arg re) zero_ne_one\u27e9,\n  mul_inv_cancel := @complex.mul_inv_cancel,\n  inv_zero := complex.inv_zero,\n  ..complex.comm_ring }\n\n@[simp] lemma I_zpow_bit0 (n : \u2124) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [zpow_bit0', I_mul_I]\n\n@[simp] lemma I_zpow_bit1 (n : \u2124) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [zpow_bit1', I_mul_I]\n\nlemma div_re (z w : \u2102) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]\nlemma div_im (z w : \u2102) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w :=\nby simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]\n\nlemma conj_inv (x : \u2102) : conj (x\u207b\u00b9) = (conj x)\u207b\u00b9 := star_inv' _\n\n@[simp, norm_cast] lemma of_real_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\nof_real.map_div r s\n\n@[simp, norm_cast] lemma of_real_zpow (r : \u211d) (n : \u2124) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n :=\nof_real.map_zpow r n\n\n@[simp] lemma div_I (z : \u2102) : z / I = -(z * I) :=\n(div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc]\n\n@[simp] lemma inv_I : I\u207b\u00b9 = -I :=\nby simp [inv_eq_one_div]\n\n@[simp] lemma norm_sq_inv (z : \u2102) : norm_sq z\u207b\u00b9 = (norm_sq z)\u207b\u00b9 :=\nnorm_sq.map_inv z\n\n@[simp] lemma norm_sq_div (z w : \u2102) : norm_sq (z / w) = norm_sq z / norm_sq w :=\nnorm_sq.map_div z w\n\n/-! ### Cast lemmas -/\n\n@[simp, norm_cast] theorem of_real_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\nmap_nat_cast of_real n\n\n@[simp, norm_cast] lemma nat_cast_re (n : \u2115) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_nat_cast, of_real_re]\n\n@[simp, norm_cast] lemma nat_cast_im (n : \u2115) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_nat_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_int_cast (n : \u2124) : ((n : \u211d) : \u2102) = n :=\nof_real.map_int_cast n\n\n@[simp, norm_cast] lemma int_cast_re (n : \u2124) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_int_cast, of_real_re]\n\n@[simp, norm_cast] lemma int_cast_im (n : \u2124) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_int_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_rat_cast (n : \u211a) : ((n : \u211d) : \u2102) = n :=\nof_real.map_rat_cast n\n\n@[simp, norm_cast] lemma rat_cast_re (q : \u211a) : (q : \u2102).re = q :=\nby rw [\u2190 of_real_rat_cast, of_real_re]\n\n@[simp, norm_cast] lemma rat_cast_im (q : \u211a) : (q : \u2102).im = 0 :=\nby rw [\u2190 of_real_rat_cast, of_real_im]\n\n/-! ### Characteristic zero -/\n\ninstance char_zero_complex : char_zero \u2102 :=\nchar_zero_of_inj_zero $ \u03bb n h,\nby rwa [\u2190 of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h\n\n/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 :=\nby simp only [add_conj, of_real_mul, of_real_one, of_real_bit0,\n     mul_div_cancel_left (z.re:\u2102) two_ne_zero']\n\n/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/\ntheorem im_eq_sub_conj (z : \u2102) : (z.im : \u2102) = (z - conj(z))/(2 * I) :=\nby simp only [sub_conj, of_real_mul, of_real_one, of_real_bit0, mul_right_comm,\n     mul_div_cancel_left _ (mul_ne_zero two_ne_zero' I_ne_zero : 2 * I \u2260 0)]\n\n/-! ### Absolute value -/\n\n/-- The complex absolute value function, defined as the square root of the norm squared. -/\n@[pp_nodot] noncomputable def abs (z : \u2102) : \u211d := (norm_sq z).sqrt\n\nlocal notation `abs'` := has_abs.abs\n\n@[simp, norm_cast] lemma abs_of_real (r : \u211d) : abs r = |r| :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\nlemma abs_of_nat (n : \u2115) : complex.abs n = n :=\ncalc complex.abs n = complex.abs (n:\u211d) : by rw [of_real_nat_cast]\n  ... = _ : abs_of_nonneg (nat.cast_nonneg n)\n\nlemma mul_self_abs (z : \u2102) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\nlemma sq_abs (z : \u2102) : abs z ^ 2 = norm_sq z :=\nreal.sq_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma sq_abs_sub_sq_re (z : \u2102) : abs z ^ 2 - z.re ^ 2 = z.im ^ 2 :=\nby rw [sq_abs, norm_sq_apply, \u2190 sq, \u2190 sq, add_sub_cancel']\n\n@[simp] lemma sq_abs_sub_sq_im (z : \u2102) : abs z ^ 2 - z.im ^ 2 = z.re ^ 2 :=\nby rw [\u2190 sq_abs_sub_sq_re, sub_sub_cancel]\n\n@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]\n@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]\n@[simp] lemma abs_I : abs I = 1 := by simp [abs]\n\n@[simp] lemma abs_two : abs 2 = 2 :=\ncalc abs 2 = abs (2 : \u211d) : by rw [of_real_bit0, of_real_one]\n... = (2 : \u211d) : abs_of_nonneg (by norm_num)\n\nlemma abs_nonneg (z : \u2102) : 0 \u2264 abs z :=\nreal.sqrt_nonneg _\n\n@[simp] lemma abs_eq_zero {z : \u2102} : abs z = 0 \u2194 z = 0 :=\n(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero\n\nlemma abs_ne_zero {z : \u2102} : abs z \u2260 0 \u2194 z \u2260 0 :=\nnot_congr abs_eq_zero\n\n@[simp] lemma abs_conj (z : \u2102) : abs (conj z) = abs z :=\nby simp [abs]\n\n@[simp] lemma abs_mul (z w : \u2102) : abs (z * w) = abs z * abs w :=\nby rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl\n\n/-- `complex.abs` as a `monoid_with_zero_hom`. -/\n@[simps] noncomputable def abs_hom : \u2102 \u2192*\u2080 \u211d :=\n{ to_fun := abs,\n  map_zero' := abs_zero,\n  map_one' := abs_one,\n  map_mul' := abs_mul }\n\n@[simp] lemma abs_prod {\u03b9 : Type*} (s : finset \u03b9) (f : \u03b9 \u2192 \u2102) :\n  abs (s.prod f) = s.prod (\u03bb i, abs (f i)) :=\nmap_prod abs_hom _ _\n\n@[simp] lemma abs_pow (z : \u2102) (n : \u2115) : abs (z ^ n) = abs z ^ n :=\nmap_pow abs_hom z n\n\n@[simp] lemma abs_zpow (z : \u2102) (n : \u2124) : abs (z ^ n) = abs z ^ n :=\nabs_hom.map_zpow z n\n\nlemma abs_re_le_abs (z : \u2102) : |z.re| \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply re_sq_le_norm_sq\n\nlemma abs_im_le_abs (z : \u2102) : |z.im| \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply im_sq_le_norm_sq\n\nlemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : \u2102) : z.im \u2264 abs z :=\n(abs_le.1 (abs_im_le_abs _)).2\n\n/--\nThe **triangle inequality** for complex numbers.\n-/\nlemma abs_add (z w : \u2102) : abs (z + w) \u2264 abs z + abs w :=\n(mul_self_le_mul_self_iff (abs_nonneg _)\n  (add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $\nbegin\n  rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,\n      add_right_comm, norm_sq_add, add_le_add_iff_left,\n      mul_assoc, mul_le_mul_left (@zero_lt_two \u211d _ _)],\n  simpa [-mul_re] using re_le_abs (z * conj w)\nend\n\ninstance : is_absolute_value abs :=\n{ abv_nonneg  := abs_nonneg,\n  abv_eq_zero := \u03bb _, abs_eq_zero,\n  abv_add     := abs_add,\n  abv_mul     := abs_mul }\nopen is_absolute_value\n\n@[simp] lemma abs_abs (z : \u2102) : |(abs z)| = abs z :=\n_root_.abs_of_nonneg (abs_nonneg _)\n\n@[simp] lemma abs_pos {z : \u2102} : 0 < abs z \u2194 z \u2260 0 := abv_pos abs\n@[simp] lemma abs_neg : \u2200 z, abs (-z) = abs z := abv_neg abs\nlemma abs_sub_comm : \u2200 z w, abs (z - w) = abs (w - z) := abv_sub abs\nlemma abs_sub_le : \u2200 a b c, abs (a - c) \u2264 abs (a - b) + abs (b - c) := abv_sub_le abs\n@[simp] theorem abs_inv : \u2200 z, abs z\u207b\u00b9 = (abs z)\u207b\u00b9 := abv_inv abs\n@[simp] theorem abs_div : \u2200 z w, abs (z / w) = abs z / abs w := abv_div abs\n\nlemma abs_abs_sub_le_abs_sub : \u2200 z w, |abs z - abs w| \u2264 abs (z - w) :=\nabs_abv_sub_le_abv_sub abs\n\nlemma abs_le_abs_re_add_abs_im (z : \u2102) : abs z \u2264 |z.re| + |z.im| :=\nby simpa [re_add_im] using abs_add z.re (z.im * I)\n\nlemma abs_re_div_abs_le_one (z : \u2102) : |z.re / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }\n\nlemma abs_im_div_abs_le_one (z : \u2102) : |z.im / z.abs| \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }\n\n@[simp, norm_cast] lemma abs_cast_nat (n : \u2115) : abs (n : \u2102) = n :=\nby rw [\u2190 of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]\n\n@[simp, norm_cast] lemma int_cast_abs (n : \u2124) : \u2191|n| = abs n :=\nby rw [\u2190 of_real_int_cast, abs_of_real, int.cast_abs]\n\nlemma norm_sq_eq_abs (x : \u2102) : norm_sq x = abs x ^ 2 :=\nby rw [abs, sq, real.mul_self_sqrt (norm_sq_nonneg _)]\n\n/--\nWe put a partial order on \u2102 so that `z \u2264 w` exactly if `w - z` is real and nonnegative.\nComplex numbers with different imaginary parts are incomparable.\n-/\nprotected def partial_order : partial_order \u2102 :=\n{ le := \u03bb z w, z.re \u2264 w.re \u2227 z.im = w.im,\n  lt := \u03bb z w, z.re < w.re \u2227 z.im = w.im,\n  lt_iff_le_not_le := \u03bb z w, by { dsimp, rw lt_iff_le_not_le, tauto },\n  le_refl := \u03bb x, \u27e8le_rfl, rfl\u27e9,\n  le_trans := \u03bb x y z h\u2081 h\u2082, \u27e8h\u2081.1.trans h\u2082.1, h\u2081.2.trans h\u2082.2\u27e9,\n  le_antisymm := \u03bb z w h\u2081 h\u2082, ext (h\u2081.1.antisymm h\u2082.1) h\u2081.2 }\n\nsection complex_order\n\nlocalized \"attribute [instance] complex.partial_order\" in complex_order\n\nlemma le_def {z w : \u2102} : z \u2264 w \u2194 z.re \u2264 w.re \u2227 z.im = w.im := iff.rfl\nlemma lt_def {z w : \u2102} : z < w \u2194 z.re < w.re \u2227 z.im = w.im := iff.rfl\n\n@[simp, norm_cast] lemma real_le_real {x y : \u211d} : (x : \u2102) \u2264 (y : \u2102) \u2194 x \u2264 y := by simp [le_def]\n\n@[simp, norm_cast] lemma real_lt_real {x y : \u211d} : (x : \u2102) < (y : \u2102) \u2194 x < y := by simp [lt_def]\n\n@[simp, norm_cast] lemma zero_le_real {x : \u211d} : (0 : \u2102) \u2264 (x : \u2102) \u2194 0 \u2264 x := real_le_real\n@[simp, norm_cast] lemma zero_lt_real {x : \u211d} : (0 : \u2102) < (x : \u2102) \u2194 0 < x := real_lt_real\n\nlemma not_le_iff {z w : \u2102} : \u00ac(z \u2264 w) \u2194 w.re < z.re \u2228 z.im \u2260 w.im :=\nby rw [le_def, not_and_distrib, not_le]\n\nlemma not_le_zero_iff {z : \u2102} : \u00acz \u2264 0 \u2194 0 < z.re \u2228 z.im \u2260 0 := not_le_iff\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is an ordered ring.\n-/\nprotected def ordered_comm_ring : ordered_comm_ring \u2102 :=\n{ zero_le_one := \u27e8zero_le_one, rfl\u27e9,\n  add_le_add_left := \u03bb w z h y, \u27e8add_le_add_left h.1 _, congr_arg2 (+) rfl h.2\u27e9,\n  mul_pos := \u03bb z w hz hw,\n    by simp [lt_def, mul_re, mul_im, \u2190 hz.2, \u2190 hw.2, mul_pos hz.1 hw.1],\n  .. complex.partial_order,\n  .. complex.comm_ring }\n\nlocalized \"attribute [instance] complex.ordered_comm_ring\" in complex_order\n\n/--\nWith `z \u2264 w` iff `w - z` is real and nonnegative, `\u2102` is a star ordered ring.\n(That is, a star ring in which the nonnegative elements are those of the form `star z * z`.)\n-/\nprotected def star_ordered_ring : star_ordered_ring \u2102 :=\n{ nonneg_iff := \u03bb r, by\n  { refine \u27e8\u03bb hr, \u27e8real.sqrt r.re, _\u27e9, \u03bb h, _\u27e9,\n    { have h\u2081 : 0 \u2264 r.re := by { rw [le_def] at hr, exact hr.1 },\n      have h\u2082 : r.im = 0 := by { rw [le_def] at hr, exact hr.2.symm },\n      ext,\n      { simp only [of_real_im, star_def, of_real_re, sub_zero, conj_re, mul_re, mul_zero,\n                   \u2190real.sqrt_mul h\u2081 r.re, real.sqrt_mul_self h\u2081] },\n      { simp only [h\u2082, add_zero, of_real_im, star_def, zero_mul, conj_im,\n                   mul_im, mul_zero, neg_zero] } },\n    { obtain \u27e8s, rfl\u27e9 := h,\n      simp only [\u2190norm_sq_eq_conj_mul_self, norm_sq_nonneg, zero_le_real, star_def] } },\n  ..complex.ordered_comm_ring }\n\nlocalized \"attribute [instance] complex.star_ordered_ring\" in complex_order\n\nend complex_order\n\n/-! ### Cauchy sequences -/\n\ntheorem is_cau_seq_re (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).re) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n\ntheorem is_cau_seq_im (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).im) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n\n/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_re (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_re f\u27e9\n\n/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_im (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_im f\u27e9\n\nlemma is_cau_seq_abs {f : \u2115 \u2192 \u2102} (hf : is_cau_seq abs f) :\n  is_cau_seq abs' (abs \u2218 f) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := hf \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9\n\n/-- The limit of a Cauchy sequence of complex numbers. -/\nnoncomputable def lim_aux (f : cau_seq \u2102 abs) : \u2102 :=\n\u27e8cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)\u27e9\n\ntheorem equiv_lim_aux (f : cau_seq \u2102 abs) : f \u2248 cau_seq.const abs (lim_aux f) :=\n\u03bb \u03b5 \u03b50, (exists_forall_ge_and\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_re f\u27e9 _ (half_pos \u03b50))\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_im f\u27e9 _ (half_pos \u03b50))).imp $\n\u03bb i H j ij, begin\n  cases H _ ij with H\u2081 H\u2082,\n  apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),\n  dsimp [lim_aux] at *,\n  have := add_lt_add H\u2081 H\u2082,\n  rwa add_halves at this,\nend\n\ninstance : cau_seq.is_complete \u2102 abs :=\n\u27e8\u03bb f, \u27e8lim_aux f, equiv_lim_aux f\u27e9\u27e9\n\nopen cau_seq\n\nlemma lim_eq_lim_im_add_lim_re (f : cau_seq \u2102 abs) : lim f =\n  \u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I :=\nlim_eq_of_equiv_const $\ncalc f \u2248 _ : equiv_lim_aux f\n... = cau_seq.const abs (\u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I) :\n  cau_seq.ext (\u03bb _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))\n\nlemma lim_re (f : cau_seq \u2102 abs) : lim (cau_seq_re f) = (lim f).re :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma lim_im (f : cau_seq \u2102 abs) : lim (cau_seq_im f) = (lim f).im :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma is_cau_seq_conj (f : cau_seq \u2102 abs) : is_cau_seq abs (\u03bb n, conj (f n)) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := f.2 \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, by rw [\u2190 ring_hom.map_sub, abs_conj]; exact hi j hj\u27e9\n\n/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/\nnoncomputable def cau_seq_conj (f : cau_seq \u2102 abs) : cau_seq \u2102 abs :=\n\u27e8_, is_cau_seq_conj f\u27e9\n\nlemma lim_conj (f : cau_seq \u2102 abs) : lim (cau_seq_conj f) = conj (lim f) :=\ncomplex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])\n  (by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)\n\n/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_abs (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_abs f.2\u27e9\n\nlemma lim_abs (f : cau_seq \u2102 abs) : lim (cau_seq_abs f) = abs (lim f) :=\nlim_eq_of_equiv_const (\u03bb \u03b5 \u03b50,\nlet \u27e8i, hi\u27e9 := equiv_lim f \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9)\n\n@[simp, norm_cast] lemma of_real_prod {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) :\n  ((\u220f i in s, f i : \u211d) : \u2102) = \u220f i in s, (f i : \u2102) :=\nring_hom.map_prod of_real _ _\n\n@[simp, norm_cast] lemma of_real_sum {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) :\n  ((\u2211 i in s, f i : \u211d) : \u2102) = \u2211 i in s, (f i : \u2102) :=\nring_hom.map_sum of_real _ _\n\nend complex\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199034, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7171957159968436}}
{"text": "import data.real.basic\nimport tactic\n\nopen function real\n\nnamespace vilnius\n\n\nexample (X Y Z : Type) (f : X \u2192 Y) (g : Y \u2192 Z) \n  (hf : surjective f) (hg : surjective g) : surjective (g \u2218 f) :=\nbegin\n  sorry,\nend\n\n/- ### The \u03bb notation:\nIn Lean (or in Type Theory, rather) the way to define a function is to use \u03bb expressions: here, you\nshould think that `\u03bb = \u2200`: so, the function\n`\u03bb x, 3*x ^ 2 + 1`\nis nothing else that the function\n`f(x)=3*x ^ 2 + 1` or `f : x \u21a6 3*x ^ 2 + 1`.\n\nAs for usual functions, the name of the variable does not matter, so\n`\u03bb x, 3*x ^ 2 + 1` is the same as `\u03bb w, 3*w ^ 2 + 1` \n\nThe tactic to get rid of a `\u03bb` term is\n* `simp only` (possibly: at h)\nbecause it \"evaluates a \u03bb-term\", transforming, for instance\n`(\u03bb x, 2 * x + 1) 3` into `2 * 3 + 1`.\n-/\n\n\ndefinition A : \u2115 \u2192 \u2115 := \u03bb n, n + 1 \n\nexample : injective A :=\nbegin\n  sorry,\nend\n\nexample : \u00ac surjective A := \nbegin\n  sorry,\nend\n\n-- Recall the-\ndefinition is_linear (f : \u211d \u2192 \u211d) : Prop := \u2200 c x y, f (c * x + y) = c * f (x) + f(y) \n\n--as well as\ntheorem linear_at_0 (f : \u211d \u2192 \u211d) (H : is_linear f) : f 0 = 0 := sorry\n\n-- And now a new\n\ndefinition is_linear' (f : \u211d \u2192 \u211d) : Prop :=\n(\u2200 x y, f ( x + y) = f (x) + f (y)) \u2227 (\u2200 c x, f (c * x) = c * f (x))\n\nexample (f : \u211d \u2192 \u211d) : is_linear f \u2194 is_linear' f :=\nbegin\n  sorry,\nend\n\n--Recall the\ndefinition is_affine (f : \u211d \u2192 \u211d) : Prop := \u2203 a, \u2200 x y, f (y) - f(x) = a * (y - x)\n\n-- together with the\ntheorem linear_add_cnst_of_affine (f : \u211d \u2192 \u211d) : is_affine f \u2192 (\u2203 a : \u211d, \u2203 g : \u211d \u2192 \u211d,\n  (f = g + (\u03bb x, a)) \u2227 is_linear g) := sorry\n-- as well as\ntheorem affine_of_linear_add_cnst (f : \u211d \u2192 \u211d) : (\u2203 b : \u211d, \u2203 g : \u211d \u2192 \u211d,\n  (f = g + (\u03bb x, b)) \u2227 is_linear g) \u2192 is_affine f := sorry\n\n-- that we proved in the lesson.\n\nexample (f : \u211d \u2192 \u211d) : is_affine f \u2194 \u2203 a : \u211d, \u2203 g : \u211d \u2192 \u211d, (f = g + (\u03bb x, a)) \u2227 is_linear g := -- iff.intro (linear_add_cnst_of_affine _) (affine_of_linear_add_cnst _)\nbegin\n  sorry,\nend\n\nend vilnius\n", "meta": {"author": "faenuccio", "repo": "May22_Vilnius", "sha": "2ff937dc7568e6118473b1e7f479ccb2a5fa9767", "save_path": "github-repos/lean/faenuccio-May22_Vilnius", "path": "github-repos/lean/faenuccio-May22_Vilnius/May22_Vilnius-2ff937dc7568e6118473b1e7f479ccb2a5fa9767/src/B_Functions/Exercices.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7171957117501735}}
{"text": "import Mathlib\n\n/-!\n# Jet Spaces\n\nThese consist of the value of a function at a point, and the value of its gradient at that point. Smooth functions are functions on jet spaces.\n-/\n\nnoncomputable example : Field \u211d := inferInstance\n\nnamespace Jet\n\nuniverse u\n\n/-- Notation \u211d^n etc -/\ninstance : HPow (Type u) \u2115 (Type u) := \u27e8fun k n \u21a6 Vector k n\u27e9 \n\nstructure Jet (n : \u2115) where \n  value : \u211d \n  gradient : \u211d ^ n\n\n\ninstance  {n : \u2115 } : Add  (\u211d ^ n) := \u27e8fun v\u2081 v\u2082 => \n  Vector.map\u2082 (\u00b7 + \u00b7) v\u2081 v\u2082\u27e9\n\n#check Vector.map\u2082\n\ninstance addJets {n: \u2115} : Add (Jet n) := \n    \u27e8fun j\u2081 j\u2082 => \u27e8j\u2081.value + j\u2082.value, j\u2081.gradient + j\u2082.gradient\u27e9\u27e9\n\ninstance scMul {n : \u2115 } : SMul \u211d  (\u211d ^ n) := \n  \u27e8fun c v => v.map (c * \u00b7)\u27e9\n\ninstance scMulJets {n : \u2115 } : SMul \u211d (Jet n) :=\n  \u27e8fun c j => \u27e8c * j.value, c \u2022 j.gradient\u27e9\u27e9\n\ndef Vector.dot {n: \u2115}(v\u2081 v\u2082 : \u211d ^ n) : \u211d := \n  (Vector.map\u2082 (\u00b7 * \u00b7) v\u2081 v\u2082).toList.sum\n\ninstance liebnitz {n: \u2115} : Mul (Jet n) :=\n  \u27e8fun j\u2081 j\u2082 => \u27e8j\u2081.value * j\u2082.value, j\u2081.value \u2022 j\u2082.gradient + j\u2082.value \u2022 j\u2081.gradient\u27e9\u27e9\n\n/-- Should be replaced by an actual definition eventually -/\nopaque hasGradAt {n: \u2115} (f : \u211d ^ n \u2192 \u211d)(x : \u211d ^n) : Prop \n\n/-- A function `\u211d^n \u2192 \u211d` with its gradient, the commented out condition should be added-/\nstructure SmoothFunction (n : \u2115)(m : \u2115) where\n  asFunc : \u211d ^ n \u2192 \u211d ^ m\n  grad : \u211d ^ n  \u2192 \u211d ^ n \u2192 \u211d ^ m\n  --hasGradAt : \u2200 x, hasGradAt jetMap x\n\ninstance : CoeFun (SmoothFunction n m) (fun _ => \u211d^n \u2192 \u211d^m) where\n  coe := SmoothFunction.asFunc\n\n/-- Should be proved as a theorem -/\naxiom gradient_determined {n: \u2115} {m : \u2115} (f g : SmoothFunction n m) : \n    f.asFunc = g.asFunc \u2192 f = g\n\ndef zeroVector {n : \u2115} : \u211d ^ n := match n with \n  | 0 => Vector.nil\n  | n + 1 => Vector.cons 0 (zeroVector : \u211d ^ n)\n\ninstance {n: \u2115} : Zero (\u211d ^ n) := \u27e8zeroVector\u27e9\n\ndef consVector {n : \u2115} (c : \u211d) : \u211d ^ n := match n with \n  | 0 => Vector.nil\n  | n + 1 => Vector.cons c (zeroVector : \u211d ^ n)\n\ndef Jet.const (n : \u2115) (c : \u211d) : Jet n := \n  \u27e8c, zeroVector\u27e9\n\ndef SmoothFunction.const (n : \u2115) (m : \u2115) (c : \u211d^m) : SmoothFunction n m := \n  \u27e8fun _ => c, fun _ => 0\u27e9\n\ndef Vector.coord (i n : \u2115) : (i < n) \u2192  \u211d ^ n :=\n  fun h => \n  match i, n, h with \n  | 0, k + 1, _ => \n    Vector.cons 1 (zeroVector : \u211d ^ k)\n  | i + 1, k + 1, pf => \n     let tail : \u211d ^ k := Vector.coord i k (Nat.le_of_succ_le_succ pf) \n     Vector.cons 0 tail\n\n/-- The coordinate functions\n-- Fix later\n\ndef SmoothFunction.coord (i n m : \u2115) (h : i < n) : SmoothFunction n m := \n  \u27e8fun v : Vector (Vector \u211d m) n => v.get \u27e8i, h\u27e9, fun _ => 0\u27e9\n-/\n\n-- instance : Coe  \u211d  (\u211d ^ 1) := \u27e8fun c => Vector.cons c Vector.nil\u27e9\n/- instance (l : List \u211d) (n : outParam \u2115)\n         (h : outParam (l.length = n) := by rfl)\n    : CoeDep (List \u211d) l (\u211d^n) where\n  coe := \u27e8l, h\u27e9 -/\n\ninstance : Coe  (\u211d ^ 1) \u211d  := \u27e8fun v => v.get \u27e80, Nat.zero_lt_succ 0\u27e9\u27e9\n\n/-- Composition with a smooth function `\u211d \u2192 \u211d` with chain rule for derivative-/\n\ndef SmoothFunction.comp {n: \u2115} {l : \u2115} {m : \u2115} (g : SmoothFunction m l) (f : SmoothFunction n m)  : SmoothFunction n l := \n  \u27e8fun v => g.asFunc (f.asFunc v), fun v => \n    let g' : \u211d^m \u2192 \u211d^l := g.grad (f.asFunc v )\n    let f' : \u211d^n \u2192 \u211d^m := f.grad v\n    g' \u2022  f'\u27e9\n\n\ninfix:65 \" \u2218 \" => SmoothFunction.comp\n\ndef addVec {n : \u2115} (v1 : \u211d^n) : \u211d := \n  v1.toList.sum\n", "meta": {"author": "DragonSlayerXavier", "repo": "Classical-Mechanics-Lean", "sha": "41a1e874f5125450004e4d2f0792d43a76d8c906", "save_path": "github-repos/lean/DragonSlayerXavier-Classical-Mechanics-Lean", "path": "github-repos/lean/DragonSlayerXavier-Classical-Mechanics-Lean/Classical-Mechanics-Lean-41a1e874f5125450004e4d2f0792d43a76d8c906/ClassicalMechanicsLean/Jetspace_nD.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686645, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7171314225454583}}
{"text": "import .love09_hoare_logic_demo\n\n\n/-! # LoVe Exercise 9: Hoare Logic -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Program Verification\n\nThe following WHILE program is intended to compute the Gaussian sum up to `n`,\nleaving the result in `r`. -/\n\ndef GAUSS : stmt :=\nstmt.assign \"r\" (\u03bbs, 0) ;;\nstmt.while (\u03bbs, s \"n\" \u2260 0)\n  (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"n\") ;;\n   stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n\n/-! The summation function: -/\n\ndef sum_upto : \u2115 \u2192 \u2115\n| 0       := 0\n| (n + 1) := n + 1 + sum_upto n\n\n/-! 1.1. Prove the correctness of `GAUSS` using `vcg`. The main challenge is to\nfigure out which invariant to use for the while loop. The invariant should\ncapture both the work that has been done already (the intermediate result) and\nthe work that remains to be done. -/\n\nlemma GAUSS_correct (n\u2080 : \u2115) :\n  {* \u03bbs, s \"n\" = n\u2080 *} GAUSS {* \u03bbs, s \"r\" = sum_upto n\u2080 *} :=\nsorry\n\n/-! 1.2. The following WHILE program is intended to compute the product of `n`\nand `m`, leaving the result in `r`. Prove its correctness using `vcg`.\n\nHint: If a variable `x` does not change in a program, it might be useful to\nrecord this in the invariant, by adding a conjunct `s \"x\" = x\u2080`. -/\n\ndef MUL : stmt :=\nstmt.assign \"r\" (\u03bbs, 0) ;;\nstmt.while (\u03bbs, s \"n\" \u2260 0)\n  (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"m\") ;;\n   stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n\nlemma MUL_correct (n\u2080 m\u2080 : \u2115) :\n  {* \u03bbs, s \"n\" = n\u2080 \u2227 s \"m\" = m\u2080 *} MUL {* \u03bbs, s \"r\" = n\u2080 * m\u2080 *} :=\nsorry\n\n\n/-! ## Question 2: Hoare Triples for Total Correctness -/\n\ndef total_hoare (P : state \u2192 Prop) (S : stmt) (Q : state \u2192 Prop) : Prop :=\n\u2200s, P s \u2192 \u2203t, (S, s) \u27f9 t \u2227 Q t\n\nnotation `[* ` P : 1 ` *] ` S : 1 ` [* ` Q : 1 ` *]` :=\ntotal_hoare P S Q\n\nnamespace total_hoare\n\n/-! 2.1. Prove the consequence rule. -/\n\nlemma consequence {P P' Q Q' : state \u2192 Prop} {S}\n    (hS : [* P *] S [* Q *]) (hP : \u2200s, P' s \u2192 P s) (hQ : \u2200s, Q s \u2192 Q' s) :\n  [* P' *] S [* Q' *] :=\nsorry\n\n/-! 2.2. Prove the rule for `skip`. -/\n\nlemma skip_intro {P} :\n  [* P *] stmt.skip [* P *] :=\nsorry\n\n/-! 2.3. Prove the rule for `assign`. -/\n\nlemma assign_intro {P : state \u2192 Prop} {x} {a : state \u2192 \u2115} :\n  [* \u03bbs, P (s{x \u21a6 a s}) *] stmt.assign x a [* P *] :=\nsorry\n\n/-! 2.4. Prove the rule for `seq`. -/\n\nlemma seq_intro {P Q R S T} (hS : [* P *] S [* Q *]) (hT : [* Q *] T [* R *]) :\n  [* P *] S ;; T [* R *] :=\nsorry\n\n/-! 2.5. Complete the proof of the rule for `ite`.\n\nHint: This requires a case distinction on the truth value of `b s`. -/\n\nlemma ite_intro {b P Q : state \u2192 Prop} {S T}\n    (hS : [* \u03bbs, P s \u2227 b s *] S [* Q *])\n    (hT : [* \u03bbs, P s \u2227 \u00ac b s *] T [* Q *]) :\n  [* P *] stmt.ite b S T [* Q *] :=\nsorry\n\n/-! 2.6 (**optional**). Try to prove the rule for `while`.\n\nThe rule is parameterized by a loop invariant `I` and by a variant `V` that\ndecreases with each iteration of the loop body.\n\nBefore we prove the desired lemma, we introduce an auxiliary lemma. Its proof\nrequires well-founded induction. When using `while_var_intro_aux` as induction\nhypothesis we recommend to do it directly after proving that the argument is\nless than `v\u2080`:\n\n    have ih : \u2203u, (stmt.while b S, t) \u27f9 u \u2227 I u \u2227 \u00ac b u :=\n      have V t < v\u2080 :=\n        \u2026,\n      while_var_intro_aux (V t) \u2026,\n\nSimilarly to `ite`, the proof requires a case distinction on `b s \u2228 \u00ac b s`. -/\n\nlemma while_var_intro_aux {b : state \u2192 Prop} (I : state \u2192 Prop) (V : state \u2192 \u2115)\n  {S} (h_inv : \u2200v\u2080, [* \u03bbs, I s \u2227 b s \u2227 V s = v\u2080 *] S [* \u03bbs, I s \u2227 V s < v\u2080 *]) :\n  \u2200v\u2080 s, V s = v\u2080 \u2192 I s \u2192 \u2203t, (stmt.while b S, s) \u27f9 t \u2227 I t \u2227 \u00ac b t\n| v\u2080 s V_eq hs :=\nsorry\n\nlemma while_var_intro {b : state \u2192 Prop} (I : state \u2192 Prop) (V : state \u2192 \u2115) {S}\n  (hinv : \u2200v\u2080, [* \u03bbs, I s \u2227 b s \u2227 V s = v\u2080 *] S [* \u03bbs, I s \u2227 V s < v\u2080 *]) :\n  [* I *] stmt.while b S [* \u03bbs, I s \u2227 \u00ac b s *] :=\nsorry\n\nend total_hoare\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2021", "sha": "23b469c79afd482fa66da82e4726a317e3a7b5d5", "save_path": "github-repos/lean/blanchette-logical_verification_2021", "path": "github-repos/lean/blanchette-logical_verification_2021/logical_verification_2021-23b469c79afd482fa66da82e4726a317e3a7b5d5/lean/love09_hoare_logic_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7170595453400032}}
{"text": "-- Las_relaciones_definidas_por_particiones_son_reflexivas.lean\n-- Las relaciones definidas por particiones son reflexivas\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 9 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Para cada partici\u00f3n se define una relaci\u00f3n de forma que un par de\n-- elementos est\u00e1n relacionados si pertenecen al mismo bloque de la\n-- partici\u00f3n. En Lena,\n--    def relacion : (particion A) \u2192 (A \u2192 A \u2192 Prop) :=\n--      \u03bb P a b, \u2200 X \u2208 Bloques P, a \u2208 X \u2192 b \u2208 X\n--\n-- Demostrar que la relaci\u00f3n definida por la partici\u00f3n P es reflexiva.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n@[ext] structure particion (A : Type) :=\n(Bloques    : set (set A))\n(Hno_vacios : \u2200 X \u2208 Bloques, (X : set A).nonempty)\n(Hrecubren  : \u2200 a, \u2203 X \u2208 Bloques, a \u2208 X)\n(Hdisjuntos : \u2200 X Y \u2208 Bloques, (X \u2229 Y : set A).nonempty \u2192 X = Y)\n\nnamespace particion\n\nvariable  {A : Type}\n\ndef relacion : (particion A) \u2192 (A \u2192 A \u2192 Prop) :=\n  \u03bb P a b, \u2200 X \u2208 Bloques P, a \u2208 X \u2192 b \u2208 X\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (P : particion A)\n  : reflexive (relacion P) :=\nbegin\n  rw reflexive,\n  intro a,\n  unfold relacion,\n  intros X hXC haX,\n  exact haX,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (P : particion A)\n  : reflexive (relacion P) :=\nbegin\n  intro a,\n  intros X hXC haX,\n  exact haX,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (P : particion A)\n  : reflexive (relacion P) :=\nbegin\n  intros a X hXC haX,\n  exact haX,\nend\n\n-- 4\u00aa demostraci\u00f3n\nlemma reflexiva\n  (P : particion A)\n  : reflexive (relacion P) :=\n\u03bb a X hXC haX, haX\n\nend particion\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Las_relaciones_definidas_por_particiones_son_reflexivas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.7170595434760566}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module group_theory.perm.fin\n! leanprover-community/mathlib commit 7e1c1263b6a25eb90bf16e80d8f47a657e403c4c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.GroupTheory.Perm.Cycle.Type\nimport Mathbin.GroupTheory.Perm.Option\nimport Mathbin.Logic.Equiv.Fin\nimport Mathbin.Logic.Equiv.Fintype\n\n/-!\n# Permutations of `fin n`\n-/\n\n\nopen Equiv\n\n/-- Permutations of `fin (n + 1)` are equivalent to fixing a single\n`fin (n + 1)` and permuting the remaining with a `perm (fin n)`.\nThe fixed `fin (n + 1)` is swapped with `0`. -/\ndef Equiv.Perm.decomposeFin {n : \u2115} : Perm (Fin n.succ) \u2243 Fin n.succ \u00d7 Perm (Fin n) :=\n  ((Equiv.permCongr <| finSuccEquiv n).trans Equiv.Perm.decomposeOption).trans\n    (Equiv.prodCongr (finSuccEquiv n).symm (Equiv.refl _))\n#align equiv.perm.decompose_fin Equiv.Perm.decomposeFin\n\n@[simp]\ntheorem Equiv.Perm.decomposeFin_symm_of_refl {n : \u2115} (p : Fin (n + 1)) :\n    Equiv.Perm.decomposeFin.symm (p, Equiv.refl _) = swap 0 p := by\n  simp [Equiv.Perm.decomposeFin, Equiv.permCongr_def]\n#align equiv.perm.decompose_fin_symm_of_refl Equiv.Perm.decomposeFin_symm_of_refl\n\n@[simp]\ntheorem Equiv.Perm.decomposeFin_symm_of_one {n : \u2115} (p : Fin (n + 1)) :\n    Equiv.Perm.decomposeFin.symm (p, 1) = swap 0 p :=\n  Equiv.Perm.decomposeFin_symm_of_refl p\n#align equiv.perm.decompose_fin_symm_of_one Equiv.Perm.decomposeFin_symm_of_one\n\n@[simp]\ntheorem Equiv.Perm.decomposeFin_symm_apply_zero {n : \u2115} (p : Fin (n + 1)) (e : Perm (Fin n)) :\n    Equiv.Perm.decomposeFin.symm (p, e) 0 = p := by simp [Equiv.Perm.decomposeFin]\n#align equiv.perm.decompose_fin_symm_apply_zero Equiv.Perm.decomposeFin_symm_apply_zero\n\n@[simp]\ntheorem Equiv.Perm.decomposeFin_symm_apply_succ {n : \u2115} (e : Perm (Fin n)) (p : Fin (n + 1))\n    (x : Fin n) : Equiv.Perm.decomposeFin.symm (p, e) x.succ = swap 0 p (e x).succ :=\n  by\n  refine' Fin.cases _ _ p\n  \u00b7 simp [Equiv.Perm.decomposeFin, EquivFunctor.map]\n  \u00b7 intro i\n    by_cases h : i = e x\n    \u00b7 simp [h, Equiv.Perm.decomposeFin, EquivFunctor.map]\n    \u00b7 have h' : some (e x) \u2260 some i := fun H => h (Option.some_injective _ H).symm\n      have h'' : (e x).succ \u2260 i.succ := fun H => h (Fin.succ_injective _ H).symm\n      simp [h, h'', Fin.succ_ne_zero, Equiv.Perm.decomposeFin, EquivFunctor.map,\n        swap_apply_of_ne_of_ne, swap_apply_of_ne_of_ne (Option.some_ne_none (e x)) h']\n#align equiv.perm.decompose_fin_symm_apply_succ Equiv.Perm.decomposeFin_symm_apply_succ\n\n@[simp]\ntheorem Equiv.Perm.decomposeFin_symm_apply_one {n : \u2115} (e : Perm (Fin (n + 1))) (p : Fin (n + 2)) :\n    Equiv.Perm.decomposeFin.symm (p, e) 1 = swap 0 p (e 0).succ := by\n  rw [\u2190 Fin.succ_zero_eq_one, Equiv.Perm.decomposeFin_symm_apply_succ e p 0]\n#align equiv.perm.decompose_fin_symm_apply_one Equiv.Perm.decomposeFin_symm_apply_one\n\n@[simp]\ntheorem Equiv.Perm.decomposeFin.symm_sign {n : \u2115} (p : Fin (n + 1)) (e : Perm (Fin n)) :\n    Perm.sign (Equiv.Perm.decomposeFin.symm (p, e)) = ite (p = 0) 1 (-1) * Perm.sign e := by\n  refine' Fin.cases _ _ p <;> simp [Equiv.Perm.decomposeFin, Fin.succ_ne_zero]\n#align equiv.perm.decompose_fin.symm_sign Equiv.Perm.decomposeFin.symm_sign\n\n/-- The set of all permutations of `fin (n + 1)` can be constructed by augmenting the set of\npermutations of `fin n` by each element of `fin (n + 1)` in turn. -/\ntheorem Finset.univ_perm_fin_succ {n : \u2115} :\n    @Finset.univ (Perm <| Fin n.succ) _ =\n      (Finset.univ : Finset <| Fin n.succ \u00d7 Perm (Fin n)).map\n        Equiv.Perm.decomposeFin.symm.toEmbedding :=\n  (Finset.univ_map_equiv_to_embedding _).symm\n#align finset.univ_perm_fin_succ Finset.univ_perm_fin_succ\n\nsection CycleRange\n\n/-! ### `cycle_range` section\n\nDefine the permutations `fin.cycle_range i`, the cycle `(0 1 2 ... i)`.\n-/\n\n\nopen Equiv.Perm\n\n#print finRotate_succ /-\ntheorem finRotate_succ {n : \u2115} : finRotate n.succ = decomposeFin.symm (1, finRotate n) :=\n  by\n  ext i\n  cases n; \u00b7 simp\n  refine' Fin.cases _ (fun i => _) i\n  \u00b7 simp\n  rw [coe_finRotate, decompose_fin_symm_apply_succ, if_congr i.succ_eq_last_succ rfl rfl]\n  split_ifs with h\n  \u00b7 simp [h]\n  \u00b7\n    rw [Fin.val_succ, Function.Injective.map_swap Fin.val_injective, Fin.val_succ, coe_finRotate,\n      if_neg h, Fin.val_zero, Fin.val_one,\n      swap_apply_of_ne_of_ne (Nat.succ_ne_zero _) (Nat.succ_succ_ne_one _)]\n#align fin_rotate_succ finRotate_succ\n-/\n\n@[simp]\ntheorem sign_finRotate (n : \u2115) : Perm.sign (finRotate (n + 1)) = (-1) ^ n :=\n  by\n  induction' n with n ih\n  \u00b7 simp\n  \u00b7 rw [finRotate_succ]\n    simp [ih, pow_succ]\n#align sign_fin_rotate sign_finRotate\n\n@[simp]\ntheorem support_finRotate {n : \u2115} : support (finRotate (n + 2)) = Finset.univ :=\n  by\n  ext\n  simp\n#align support_fin_rotate support_finRotate\n\ntheorem support_finRotate_of_le {n : \u2115} (h : 2 \u2264 n) : support (finRotate n) = Finset.univ :=\n  by\n  obtain \u27e8m, rfl\u27e9 := exists_add_of_le h\n  rw [add_comm, support_finRotate]\n#align support_fin_rotate_of_le support_finRotate_of_le\n\ntheorem isCycle_finRotate {n : \u2115} : IsCycle (finRotate (n + 2)) :=\n  by\n  refine' \u27e80, by decide, fun x hx' => \u27e8x, _\u27e9\u27e9\n  clear hx'\n  cases' x with x hx\n  rw [coe_coe, zpow_ofNat, Fin.ext_iff, Fin.val_mk]\n  induction' x with x ih; \u00b7 rfl\n  rw [pow_succ, perm.mul_apply, coe_finRotate_of_ne_last, ih (lt_trans x.lt_succ_self hx)]\n  rw [Ne.def, Fin.ext_iff, ih (lt_trans x.lt_succ_self hx), Fin.val_last]\n  exact ne_of_lt (Nat.lt_of_succ_lt_succ hx)\n#align is_cycle_fin_rotate isCycle_finRotate\n\ntheorem isCycle_finRotate_of_le {n : \u2115} (h : 2 \u2264 n) : IsCycle (finRotate n) :=\n  by\n  obtain \u27e8m, rfl\u27e9 := exists_add_of_le h\n  rw [add_comm]\n  exact isCycle_finRotate\n#align is_cycle_fin_rotate_of_le isCycle_finRotate_of_le\n\n@[simp]\ntheorem cycleType_finRotate {n : \u2115} : cycleType (finRotate (n + 2)) = {n + 2} :=\n  by\n  rw [is_cycle_fin_rotate.cycle_type, support_finRotate, \u2190 Fintype.card, Fintype.card_fin]\n  rfl\n#align cycle_type_fin_rotate cycleType_finRotate\n\ntheorem cycleType_finRotate_of_le {n : \u2115} (h : 2 \u2264 n) : cycleType (finRotate n) = {n} :=\n  by\n  obtain \u27e8m, rfl\u27e9 := exists_add_of_le h\n  rw [add_comm, cycleType_finRotate]\n#align cycle_type_fin_rotate_of_le cycleType_finRotate_of_le\n\nnamespace Fin\n\n/-- `fin.cycle_range i` is the cycle `(0 1 2 ... i)` leaving `(i+1 ... (n-1))` unchanged. -/\ndef cycleRange {n : \u2115} (i : Fin n) : Perm (Fin n) :=\n  (finRotate (i + 1)).extendDomain\n    (Equiv.ofLeftInverse' (Fin.castLe (Nat.succ_le_of_lt i.is_lt)).toEmbedding coe\n      (by\n        intro x\n        ext\n        simp))\n#align fin.cycle_range Fin.cycleRange\n\ntheorem cycleRange_of_gt {n : \u2115} {i j : Fin n.succ} (h : i < j) : cycleRange i j = j :=\n  by\n  rw [cycle_range, of_left_inverse'_eq_of_injective, \u2190\n    Function.Embedding.toEquivRange_eq_ofInjective, \u2190 via_fintype_embedding,\n    via_fintype_embedding_apply_not_mem_range]\n  simpa\n#align fin.cycle_range_of_gt Fin.cycleRange_of_gt\n\ntheorem cycleRange_of_le {n : \u2115} {i j : Fin n.succ} (h : j \u2264 i) :\n    cycleRange i j = if j = i then 0 else j + 1 :=\n  by\n  cases n\n  \u00b7 simp\n  have :\n    j =\n      (Fin.castLe (Nat.succ_le_of_lt i.is_lt)).toEmbedding\n        \u27e8j, lt_of_le_of_lt h (Nat.lt_succ_self i)\u27e9 :=\n    by simp\n  ext\n  rw [this, cycle_range, of_left_inverse'_eq_of_injective, \u2190\n    Function.Embedding.toEquivRange_eq_ofInjective, \u2190 via_fintype_embedding,\n    via_fintype_embedding_apply_image, RelEmbedding.coeFn_toEmbedding, coe_cast_le, coe_finRotate]\n  simp only [Fin.ext_iff, coe_last, coe_mk, coe_zero, Fin.eta, apply_ite coe, cast_le_mk]\n  split_ifs with heq\n  \u00b7 rfl\n  \u00b7 rw [Fin.val_add_one_of_lt]\n    exact lt_of_lt_of_le (lt_of_le_of_ne h (mt (congr_arg coe) HEq)) (le_last i)\n#align fin.cycle_range_of_le Fin.cycleRange_of_le\n\ntheorem coe_cycleRange_of_le {n : \u2115} {i j : Fin n.succ} (h : j \u2264 i) :\n    (cycleRange i j : \u2115) = if j = i then 0 else j + 1 :=\n  by\n  rw [cycle_range_of_le h]\n  split_ifs with h'\n  \u00b7 rfl\n  exact\n    coe_add_one_of_lt\n      (calc\n        (j : \u2115) < i := fin.lt_iff_coe_lt_coe.mp (lt_of_le_of_ne h h')\n        _ \u2264 n := nat.lt_succ_iff.mp i.2\n        )\n#align fin.coe_cycle_range_of_le Fin.coe_cycleRange_of_le\n\ntheorem cycleRange_of_lt {n : \u2115} {i j : Fin n.succ} (h : j < i) : cycleRange i j = j + 1 := by\n  rw [cycle_range_of_le h.le, if_neg h.ne]\n#align fin.cycle_range_of_lt Fin.cycleRange_of_lt\n\ntheorem coe_cycleRange_of_lt {n : \u2115} {i j : Fin n.succ} (h : j < i) :\n    (cycleRange i j : \u2115) = j + 1 := by rw [coe_cycle_range_of_le h.le, if_neg h.ne]\n#align fin.coe_cycle_range_of_lt Fin.coe_cycleRange_of_lt\n\ntheorem cycleRange_of_eq {n : \u2115} {i j : Fin n.succ} (h : j = i) : cycleRange i j = 0 := by\n  rw [cycle_range_of_le h.le, if_pos h]\n#align fin.cycle_range_of_eq Fin.cycleRange_of_eq\n\n@[simp]\ntheorem cycleRange_self {n : \u2115} (i : Fin n.succ) : cycleRange i i = 0 :=\n  cycleRange_of_eq rfl\n#align fin.cycle_range_self Fin.cycleRange_self\n\ntheorem cycleRange_apply {n : \u2115} (i j : Fin n.succ) :\n    cycleRange i j = if j < i then j + 1 else if j = i then 0 else j :=\n  by\n  split_ifs with h\u2081 h\u2082\n  \u00b7 exact cycle_range_of_lt h\u2081\n  \u00b7 exact cycle_range_of_eq h\u2082\n  \u00b7 exact cycle_range_of_gt (lt_of_le_of_ne (le_of_not_gt h\u2081) (Ne.symm h\u2082))\n#align fin.cycle_range_apply Fin.cycleRange_apply\n\n@[simp]\ntheorem cycleRange_zero (n : \u2115) : cycleRange (0 : Fin n.succ) = 1 :=\n  by\n  ext j\n  refine' Fin.cases _ (fun j => _) j\n  \u00b7 simp\n  \u00b7 rw [cycle_range_of_gt (Fin.succ_pos j), one_apply]\n#align fin.cycle_range_zero Fin.cycleRange_zero\n\n@[simp]\ntheorem cycleRange_last (n : \u2115) : cycleRange (last n) = finRotate (n + 1) :=\n  by\n  ext i\n  rw [coe_cycle_range_of_le (le_last _), coe_finRotate]\n#align fin.cycle_range_last Fin.cycleRange_last\n\n@[simp]\ntheorem cycleRange_zero' {n : \u2115} (h : 0 < n) : cycleRange \u27e80, h\u27e9 = 1 :=\n  by\n  cases' n with n\n  \u00b7 cases h\n  exact cycle_range_zero n\n#align fin.cycle_range_zero' Fin.cycleRange_zero'\n\n@[simp]\ntheorem sign_cycleRange {n : \u2115} (i : Fin n) : Perm.sign (cycleRange i) = (-1) ^ (i : \u2115) := by\n  simp [cycle_range]\n#align fin.sign_cycle_range Fin.sign_cycleRange\n\n@[simp]\ntheorem succAbove_cycleRange {n : \u2115} (i j : Fin n) :\n    i.succ.succAbove (i.cycleRange j) = swap 0 i.succ j.succ :=\n  by\n  cases n\n  \u00b7 rcases j with \u27e8_, \u27e8\u27e9\u27e9\n  rcases lt_trichotomy j i with (hlt | heq | hgt)\n  \u00b7 have : (j + 1).cast_succ = j.succ := by\n      ext\n      rw [coe_cast_succ, coe_succ, Fin.val_add_one_of_lt (lt_of_lt_of_le hlt i.le_last)]\n    rw [Fin.cycleRange_of_lt hlt, Fin.succAbove_below, this, swap_apply_of_ne_of_ne]\n    \u00b7 apply Fin.succ_ne_zero\n    \u00b7 exact (Fin.succ_injective _).Ne hlt.ne\n    \u00b7 rw [Fin.lt_iff_val_lt_val]\n      simpa [this] using hlt\n  \u00b7 rw [HEq, Fin.cycleRange_self, Fin.succAbove_below, swap_apply_right, Fin.castSucc_zero]\n    \u00b7 rw [Fin.castSucc_zero]\n      apply Fin.succ_pos\n  \u00b7 rw [Fin.cycleRange_of_gt hgt, Fin.succAbove_above, swap_apply_of_ne_of_ne]\n    \u00b7 apply Fin.succ_ne_zero\n    \u00b7 apply (Fin.succ_injective _).Ne hgt.ne.symm\n    \u00b7 simpa [Fin.le_iff_val_le_val] using hgt\n#align fin.succ_above_cycle_range Fin.succAbove_cycleRange\n\n@[simp]\ntheorem cycleRange_succAbove {n : \u2115} (i : Fin (n + 1)) (j : Fin n) :\n    i.cycleRange (i.succAbove j) = j.succ :=\n  by\n  cases' lt_or_ge j.cast_succ i with h h\n  \u00b7 rw [Fin.succAbove_below _ _ h, Fin.cycleRange_of_lt h, Fin.coeSucc_eq_succ]\n  \u00b7 rw [Fin.succAbove_above _ _ h, Fin.cycleRange_of_gt (fin.le_cast_succ_iff.mp h)]\n#align fin.cycle_range_succ_above Fin.cycleRange_succAbove\n\n@[simp]\ntheorem cycleRange_symm_zero {n : \u2115} (i : Fin (n + 1)) : i.cycleRange.symm 0 = i :=\n  i.cycleRange.Injective (by simp)\n#align fin.cycle_range_symm_zero Fin.cycleRange_symm_zero\n\n@[simp]\ntheorem cycleRange_symm_succ {n : \u2115} (i : Fin (n + 1)) (j : Fin n) :\n    i.cycleRange.symm j.succ = i.succAbove j :=\n  i.cycleRange.Injective (by simp)\n#align fin.cycle_range_symm_succ Fin.cycleRange_symm_succ\n\ntheorem isCycle_cycleRange {n : \u2115} {i : Fin (n + 1)} (h0 : i \u2260 0) : IsCycle (cycleRange i) :=\n  by\n  cases' i with i hi\n  cases i\n  \u00b7 exact (h0 rfl).elim\n  exact is_cycle_fin_rotate.extend_domain _\n#align fin.is_cycle_cycle_range Fin.isCycle_cycleRange\n\n@[simp]\ntheorem cycleType_cycleRange {n : \u2115} {i : Fin (n + 1)} (h0 : i \u2260 0) :\n    cycleType (cycleRange i) = {i + 1} :=\n  by\n  cases' i with i hi\n  cases i\n  \u00b7 exact (h0 rfl).elim\n  rw [cycle_range, cycle_type_extend_domain]\n  exact cycleType_finRotate\n#align fin.cycle_type_cycle_range Fin.cycleType_cycleRange\n\ntheorem isThreeCycle_cycleRange_two {n : \u2115} : IsThreeCycle (cycleRange 2 : Perm (Fin (n + 3))) := by\n  rw [is_three_cycle, cycle_type_cycle_range] <;> decide\n#align fin.is_three_cycle_cycle_range_two Fin.isThreeCycle_cycleRange_two\n\nend Fin\n\nend CycleRange\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/GroupTheory/Perm/Fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7170595412631702}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\n\nimport number_theory.zsqrtd.gaussian_int\n\n/-!\n# Sums of two squares\n\nProof of Fermat's theorem on the sum of two squares. Every prime congruent to 1 mod 4 is the sum\nof two squares.\n\n# Todo\n\nFully characterize the natural numbers that are the sum of two squares: those such that for every\nprime p congruent to 3 mod 4, the largest power of p dividing them is even.\n-/\n\nopen gaussian_int\n\n/-- **Fermat's theorem on the sum of two squares**. Every prime congruent to 1 mod 4 is the sum\nof two squares. Also known as **Fermat's Christmas theorem**. -/\nlemma nat.prime.sq_add_sq {p : \u2115} [fact p.prime] (hp : p % 4 = 1) :\n  \u2203 a b : \u2115, a ^ 2 + b ^ 2 = p :=\nbegin\n  apply sq_add_sq_of_nat_prime_of_not_irreducible p,\n  rw [principal_ideal_ring.irreducible_iff_prime, prime_iff_mod_four_eq_three_of_nat_prime p, hp],\n  norm_num\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/sum_two_squares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7170046229571169}}
{"text": "theorem ex1 (n m : Nat) : 0 + (n, m).1 = n := by\n  simp only\n  rw [Nat.zero_add]\n\ntheorem ex2 (n m : Nat) : 0 + (n, m).1 = n := by\n  simp\n\ntheorem ex3 (n m : Nat) : 0 + (n, m).1 + 0 = n := by\n  simp only [Nat.add_zero]\n  rw [Nat.zero_add]\n\ntheorem ex4 (n m : Nat) : 0 + (n, m).1 + 0 = n := by\n  simp\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/simpOnly.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7170046204308579}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Heather Macbeth\n-/\nimport analysis.convex.cone\nimport analysis.normed_space.is_R_or_C\nimport analysis.normed_space.extend\n\n/-!\n# Hahn-Banach theorem\n\nIn this file we prove a version of Hahn-Banach theorem for continuous linear\nfunctions on normed spaces over `\u211d` and `\u2102`.\n\nIn order to state and prove its corollaries uniformly, we prove the statements for a field `\ud835\udd5c`\nsatisfying `is_R_or_C \ud835\udd5c`.\n\nIn this setting, `exists_dual_vector` states that, for any nonzero `x`, there exists a continuous\nlinear form `g` of norm `1` with `g x = \u2225x\u2225` (where the norm has to be interpreted as an element\nof `\ud835\udd5c`).\n\n-/\n\nuniverses u v\n\nnamespace real\nvariables {E : Type*} [semi_normed_group E] [normed_space \u211d E]\n\n/-- Hahn-Banach theorem for continuous linear functions over `\u211d`. -/\ntheorem exists_extension_norm_eq (p : subspace \u211d E) (f : p \u2192L[\u211d] \u211d) :\n  \u2203 g : E \u2192L[\u211d] \u211d, (\u2200 x : p, g x = f x) \u2227 \u2225g\u2225 = \u2225f\u2225 :=\nbegin\n  rcases exists_extension_of_le_sublinear \u27e8p, f\u27e9 (\u03bb x, \u2225f\u2225 * \u2225x\u2225)\n    (\u03bb c hc x, by simp only [norm_smul c x, real.norm_eq_abs, abs_of_pos hc, mul_left_comm])\n    (\u03bb x y, _) (\u03bb x, le_trans (le_abs_self _) (f.le_op_norm _))\n    with \u27e8g, g_eq, g_le\u27e9,\n  set g' := g.mk_continuous (\u2225f\u2225)\n    (\u03bb x, abs_le.2 \u27e8neg_le.1 $ g.map_neg x \u25b8 norm_neg x \u25b8 g_le (-x), g_le x\u27e9),\n  { refine \u27e8g', g_eq, _\u27e9,\n    { apply le_antisymm (g.mk_continuous_norm_le (norm_nonneg f) _),\n      refine f.op_norm_le_bound (norm_nonneg _) (\u03bb x, _),\n      dsimp at g_eq,\n      rw \u2190 g_eq,\n      apply g'.le_op_norm } },\n  { simp only [\u2190 mul_add],\n    exact mul_le_mul_of_nonneg_left (norm_add_le x y) (norm_nonneg f) }\nend\n\nend real\n\nsection is_R_or_C\nopen is_R_or_C\n\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {F : Type*} [semi_normed_group F] [normed_space \ud835\udd5c F]\n\n/-- Hahn-Banach theorem for continuous linear functions over `\ud835\udd5c` satisyfing `is_R_or_C \ud835\udd5c`. -/\ntheorem exists_extension_norm_eq (p : subspace \ud835\udd5c F) (f : p \u2192L[\ud835\udd5c] \ud835\udd5c) :\n  \u2203 g : F \u2192L[\ud835\udd5c] \ud835\udd5c, (\u2200 x : p, g x = f x) \u2227 \u2225g\u2225 = \u2225f\u2225 :=\nbegin\n  letI : module \u211d F := restrict_scalars.module \u211d \ud835\udd5c F,\n  letI : is_scalar_tower \u211d \ud835\udd5c F := restrict_scalars.is_scalar_tower _ _ _,\n  letI : normed_space \u211d F := normed_space.restrict_scalars _ \ud835\udd5c _,\n  -- Let `fr: p \u2192L[\u211d] \u211d` be the real part of `f`.\n  let fr := re_clm.comp (f.restrict_scalars \u211d),\n  have fr_apply : \u2200 x, fr x = re (f x), by { assume x, refl },\n  -- Use the real version to get a norm-preserving extension of `fr`, which\n  -- we'll call `g : F \u2192L[\u211d] \u211d`.\n  rcases real.exists_extension_norm_eq (p.restrict_scalars \u211d) fr with \u27e8g, \u27e8hextends, hnormeq\u27e9\u27e9,\n  -- Now `g` can be extended to the `F \u2192L[\ud835\udd5c] \ud835\udd5c` we need.\n  refine \u27e8g.extend_to_\ud835\udd5c, _\u27e9,\n  -- It is an extension of `f`.\n  have h : \u2200 x : p, g.extend_to_\ud835\udd5c x = f x,\n  { assume x,\n    rw [continuous_linear_map.extend_to_\ud835\udd5c_apply, \u2190submodule.coe_smul, hextends, hextends],\n    have : (fr x : \ud835\udd5c) - I * \u2191(fr (I \u2022 x)) = (re (f x) : \ud835\udd5c) - (I : \ud835\udd5c) * (re (f ((I : \ud835\udd5c) \u2022 x))),\n      by refl,\n    rw this,\n    apply ext,\n    { simp only [add_zero, algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add,\n        zero_sub, I_im', zero_mul, of_real_re, eq_self_iff_true, sub_zero, mul_neg_eq_neg_mul_symm,\n        of_real_neg, mul_re, mul_zero, sub_neg_eq_add, continuous_linear_map.map_smul] },\n    { simp only [algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add, zero_sub, I_im',\n        zero_mul, of_real_re, mul_neg_eq_neg_mul_symm, mul_im, zero_add, of_real_neg, mul_re,\n        sub_neg_eq_add, continuous_linear_map.map_smul] } },\n  -- And we derive the equality of the norms by bounding on both sides.\n  refine \u27e8h, le_antisymm _ _\u27e9,\n  { calc \u2225g.extend_to_\ud835\udd5c\u2225\n        \u2264 \u2225g\u2225 : g.extend_to_\ud835\udd5c.op_norm_le_bound g.op_norm_nonneg (norm_bound _)\n    ... = \u2225fr\u2225 : hnormeq\n    ... \u2264 \u2225re_clm\u2225 * \u2225f\u2225 : continuous_linear_map.op_norm_comp_le _ _\n    ... = \u2225f\u2225 : by rw [re_clm_norm, one_mul] },\n  { exact f.op_norm_le_bound g.extend_to_\ud835\udd5c.op_norm_nonneg (\u03bb x, h x \u25b8 g.extend_to_\ud835\udd5c.le_op_norm x) }\nend\n\nend is_R_or_C\n\nsection dual_vector\nvariables (\ud835\udd5c : Type v) [is_R_or_C \ud835\udd5c]\nvariables {E : Type u} [normed_group E] [normed_space \ud835\udd5c E]\n\nopen continuous_linear_equiv submodule\nopen_locale classical\n\nlemma coord_norm' {x : E} (h : x \u2260 0) : \u2225(\u2225x\u2225 : \ud835\udd5c) \u2022 coord \ud835\udd5c x h\u2225 = 1 :=\nby rw [norm_smul, is_R_or_C.norm_coe_norm, coord_norm, mul_inv_cancel (mt norm_eq_zero.mp h)]\n\n/-- Corollary of Hahn-Banach.  Given a nonzero element `x` of a normed space, there exists an\n    element of the dual space, of norm `1`, whose value on `x` is `\u2225x\u2225`. -/\ntheorem exists_dual_vector (x : E) (h : x \u2260 0) : \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 = 1 \u2227 g x = \u2225x\u2225 :=\nbegin\n  let p : submodule \ud835\udd5c E := \ud835\udd5c \u2219 x,\n  let f := (\u2225x\u2225 : \ud835\udd5c) \u2022 coord \ud835\udd5c x h,\n  obtain \u27e8g, hg\u27e9 := exists_extension_norm_eq p f,\n  refine \u27e8g, _, _\u27e9,\n  { rw [hg.2, coord_norm'] },\n  { calc g x = g (\u27e8x, mem_span_singleton_self x\u27e9 : \ud835\udd5c \u2219 x) : by rw coe_mk\n    ... = ((\u2225x\u2225 : \ud835\udd5c) \u2022 coord \ud835\udd5c x h) (\u27e8x, mem_span_singleton_self x\u27e9 : \ud835\udd5c \u2219 x) : by rw \u2190 hg.1\n    ... = \u2225x\u2225 : by simp }\nend\n\n/-- Variant of Hahn-Banach, eliminating the hypothesis that `x` be nonzero, and choosing\n    the dual element arbitrarily when `x = 0`. -/\ntheorem exists_dual_vector' [nontrivial E] (x : E) :\n  \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 = 1 \u2227 g x = \u2225x\u2225 :=\nbegin\n  by_cases hx : x = 0,\n  { obtain \u27e8y, hy\u27e9 := exists_ne (0 : E),\n    obtain \u27e8g, hg\u27e9 : \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 = 1 \u2227 g y = \u2225y\u2225 := exists_dual_vector \ud835\udd5c y hy,\n    refine \u27e8g, hg.left, _\u27e9,\n    simp [hx] },\n  { exact exists_dual_vector \ud835\udd5c x hx }\nend\n\n/-- Variant of Hahn-Banach, eliminating the hypothesis that `x` be nonzero, but only ensuring that\n    the dual element has norm at most `1` (this can not be improved for the trivial\n    vector space). -/\ntheorem exists_dual_vector'' (x : E) :\n  \u2203 g : E \u2192L[\ud835\udd5c] \ud835\udd5c, \u2225g\u2225 \u2264 1 \u2227 g x = \u2225x\u2225 :=\nbegin\n  by_cases hx : x = 0,\n  { refine \u27e80, by simp, _\u27e9,\n    symmetry,\n    simp [hx], },\n  { rcases exists_dual_vector \ud835\udd5c x hx with \u27e8g, g_norm, g_eq\u27e9,\n    exact \u27e8g, g_norm.le, g_eq\u27e9 }\nend\n\nend dual_vector\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/normed_space/hahn_banach.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.716944128103746}}
{"text": "import ring_theory.noetherian\n\nvariables {R M : Type*} [semiring R] [add_comm_monoid M] [module R M]\n\nnamespace submodule\n\nnoncomputable\ndef min_generator_card (p : submodule R M) : \u2115 :=\n\u2a05 s : { s : set M // s.finite \u2227 span R s = p}, s.2.1.to_finset.card\n\nnoncomputable\ndef spanrank (p : submodule R M) : with_top \u2115 :=\n\u2a05 s : { s : set M // s.finite \u2227 span R s = p}, s.2.1.to_finset.card\n\nlemma spanrank_ne_top_iff {p : submodule R M} :\n  p.spanrank \u2260 \u22a4 \u2194 p.fg :=\nbegin\n  simp [spanrank, submodule.fg_def],\nend\n\nlemma fg_iff_card_finset_nonempty {p : submodule R M} :\n  p.fg \u2194 set.nonempty (finset.card '' { s : finset M | span R (s : set M) = p }) :=\nset.nonempty_image_iff.symm\n\nlemma fg_iff_spanrank_eq {p : submodule R M} :\n  p.fg \u2194 p.spanrank = p.min_generator_card :=\nbegin\n  split,\n  { intro h,\n    haveI : nonempty {s : set M // s.finite \u2227 span R s = p},\n    { rwa [nonempty_subtype, \u2190 fg_def] },\n    exact (with_top.coe_infi _).symm },\n  { intro e, rw [\u2190 spanrank_ne_top_iff, e], exact with_top.coe_ne_top }\nend\n\nalias fg_iff_spanrank_eq \u2194 fg.spanrank_eq _\n\nlemma fg.exists_generator_eq_min_generator_card {p : submodule R M} (h : p.fg) :\n  \u2203 f : fin p.min_generator_card \u2192 M, span R (set.range f) = p :=\nbegin\n  obtain \u27e8\u27e8s, h\u2081, h\u2082\u27e9, h\u2083 : h\u2081.to_finset.card = _\u27e9 : p.min_generator_card \u2208 _ := nat.Inf_mem _,\n  { rw \u2190 h\u2083,\n    refine \u27e8subtype.val \u2218 h\u2081.to_finset.equiv_fin.symm, _\u27e9,\n    rw [set.range_comp, set.range_iff_surjective.mpr (equiv.surjective _), set.image_univ,\n      subtype.range_val, \u2190 h\u2082],\n    congr' 1,\n    ext, exact h\u2081.mem_to_finset },\n  { rwa [set.range_nonempty_iff_nonempty, nonempty_subtype, \u2190 submodule.fg_def] }\nend\n\nlemma fg.min_generator_card_le_iff_exists {p : submodule R M} {n : \u2115} :\n  p.spanrank \u2264 n \u2194 \u2203 f : fin n \u2192 M, span R (set.range f) = p :=\nbegin\n  classical,\n  split,\n  { intro e,\n    have h := spanrank_ne_top_iff.mp (e.trans_lt (with_top.coe_lt_top n)).ne,\n    rw [h.spanrank_eq, with_top.coe_le_coe] at e,\n    obtain \u27e8f, hf\u27e9 := h.exists_generator_eq_min_generator_card,\n    let f' : fin n \u2192 M := \u03bb i, if h : i.1 < p.min_generator_card then f (fin.cast_lt i h) else 0,\n    use f',\n    rw \u2190 hf,\n    apply le_antisymm; rw submodule.span_le; rintros _ \u27e8x, rfl\u27e9,\n    { dsimp only [f'],\n      split_ifs,\n      { apply submodule.subset_span, exact set.mem_range_self _ },\n      { exact (span R (set.range f)).zero_mem } },\n    { apply submodule.subset_span, use fin.cast_le e x, dsimp [f'], rw dif_pos x.is_lt, congr' 1,\n      ext, refl } },\n  { rintros \u27e8f, hf\u27e9,\n    let s : { s : set M // s.finite \u2227 span R s = p} :=\n      \u27e8set.range f, set.finite.intro infer_instance, hf\u27e9,\n    calc p.spanrank\n        \u2264 s.2.1.to_finset.card : cInf_le (order_bot.bdd_below _) (set.mem_range_self _)\n    ... = (finset.univ.image f).card : by { congr' 2, ext, simp }\n    ... \u2264 n : by { rw with_top.coe_le_coe, convert finset.card_image_le,\n                    rw [finset.card_univ, fintype.card_fin] } }\nend\n\nnoncomputable\ndef fg.min_generator {p : submodule R M} (h : p.fg) : fin p.min_generator_card \u2192 M :=\nh.exists_generator_eq_min_generator_card.some\n\nlemma fg.span_min_generator_range {p : submodule R M} (h : p.fg) :\n  span R (set.range h.min_generator) = p :=\nh.exists_generator_eq_min_generator_card.some_spec\n\nlemma fg.min_generator_mem {p : submodule R M} (h : p.fg) (i) : h.min_generator i \u2208 p :=\nby { conv_rhs { rw \u2190 h.span_min_generator_range }, exact subset_span (set.mem_range_self i) }\n\nend submodule\n", "meta": {"author": "erdOne", "repo": "lean-AG-morphisms", "sha": "bfb65e7d5c17f333abd7b1806717f12cd29427fd", "save_path": "github-repos/lean/erdOne-lean-AG-morphisms", "path": "github-repos/lean/erdOne-lean-AG-morphisms/lean-AG-morphisms-bfb65e7d5c17f333abd7b1806717f12cd29427fd/src/dimension_theory/min_generator_card.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7169441197225951}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam\n-/\n\nimport data.mv_polynomial.variables\nimport algebra.module.basic\nimport tactic.ring\n\n/-!\n# Partial derivatives of polynomials\n\nThis file defines the notion of the formal *partial derivative* of a polynomial,\nthe derivative with respect to a single variable.\nThis derivative is not connected to the notion of derivative from analysis.\nIt is based purely on the polynomial exponents and coefficients.\n\n## Main declarations\n\n* `mv_polynomial.pderiv i p` : the partial derivative of `p` with respect to `i`.\n\n## Notation\n\nAs in other polynomial files, we typically use the notation:\n\n+ `\u03c3 : Type*` (indexing the variables)\n\n+ `R : Type*` `[comm_ring R]` (the coefficients)\n\n+ `s : \u03c3 \u2192\u2080 \u2115`, a function from `\u03c3` to `\u2115` which is zero away from a finite set.\nThis will give rise to a monomial in `mv_polynomial \u03c3 R` which mathematicians might call `X^s`\n\n+ `a : R`\n\n+ `i : \u03c3`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians\n\n+ `p : mv_polynomial \u03c3 R`\n\n-/\n\nnoncomputable theory\n\nopen_locale classical big_operators\n\nopen set function finsupp add_monoid_algebra\nopen_locale big_operators\n\nuniverses u\nvariables {R : Type u}\n\nnamespace mv_polynomial\nvariables {\u03c3 : Type*} {a a' a\u2081 a\u2082 : R} {s : \u03c3 \u2192\u2080 \u2115}\n\nsection pderiv\n\nvariables {R} [comm_semiring R]\n\n/-- `pderiv i p` is the partial derivative of `p` with respect to `i` -/\ndef pderiv (i : \u03c3) : mv_polynomial \u03c3 R \u2192\u2097[R] mv_polynomial \u03c3 R :=\n{ to_fun := \u03bb p, p.sum (\u03bb A B, monomial (A - single i 1) (B * (A i))),\n  map_smul' := begin\n    intros c x,\n    rw [sum_smul_index', smul_sum],\n    { simp_rw [monomial, smul_single, smul_eq_mul, mul_assoc] },\n    { intros s,\n      simp only [monomial_zero, zero_mul] }\n  end,\n  map_add' := \u03bb f g, sum_add_index (by simp only [monomial_zero, forall_const, zero_mul])\n    (by simp only [add_mul, forall_const, eq_self_iff_true, monomial_add]), }\n\n@[simp]\nlemma pderiv_monomial {i : \u03c3} :\n  pderiv i (monomial s a) = monomial (s - single i 1) (a * (s i)) :=\nby simp only [pderiv, monomial_zero, sum_monomial, zero_mul, linear_map.coe_mk]\n\n\n@[simp]\nlemma pderiv_C {i : \u03c3} : pderiv i (C a) = 0 :=\nsuffices pderiv i (monomial 0 a) = 0, by simpa,\nby simp only [monomial_zero, pderiv_monomial, nat.cast_zero, mul_zero, zero_apply]\n\n@[simp]\nlemma pderiv_one {i : \u03c3} : pderiv i (1 : mv_polynomial \u03c3 R) = 0 := pderiv_C\n\nlemma pderiv_eq_zero_of_not_mem_vars {i : \u03c3} {f : mv_polynomial \u03c3 R} (h : i \u2209 f.vars) :\n  pderiv i f = 0 :=\nbegin\n  change (pderiv i) f = 0,\n  rw [f.as_sum, linear_map.map_sum],\n  apply finset.sum_eq_zero,\n  intros x H,\n  simp [mem_support_not_mem_vars_zero H h],\nend\n\nlemma pderiv_X {i j : \u03c3} : pderiv i (X j : mv_polynomial \u03c3 R) = if i = j then 1 else 0 :=\nbegin\n  dsimp [pderiv],\n  erw finsupp.sum_single_index,\n  simp only [mul_boole, if_congr, finsupp.single_apply, nat.cast_zero, nat.cast_one, nat.cast_ite],\n  by_cases h : i = j,\n  { rw [if_pos h, if_pos h.symm],\n    subst h,\n    congr,\n    ext j,\n    simp, },\n  { rw [if_neg h, if_neg (ne.symm h)],\n    simp, },\n  { simp, },\nend\n\n@[simp] lemma pderiv_X_self {i : \u03c3} : pderiv i (X i : mv_polynomial \u03c3 R) = 1 :=\nby simp [pderiv_X]\n\nlemma pderiv_monomial_single {i : \u03c3} {n : \u2115} :\n  pderiv i (monomial (single i n) a) = monomial (single i (n-1)) (a * n) :=\nby simp\n\nprivate lemma monomial_sub_single_one_add {i : \u03c3} {s' : \u03c3 \u2192\u2080 \u2115} :\n  monomial (s - single i 1 + s') (a * (s i) * a') =\n    monomial (s + s' - single i 1) (a * (s i) * a') :=\nby by_cases h : s i = 0; simp [h, sub_single_one_add]\n\nprivate lemma monomial_add_sub_single_one {i : \u03c3} {s' : \u03c3 \u2192\u2080 \u2115} :\n  monomial (s + (s' - single i 1)) (a * (a' * (s' i))) =\n    monomial (s + s' - single i 1) (a * (a' * (s' i))) :=\nby by_cases h : s' i = 0; simp [h, add_sub_single_one]\n\nlemma pderiv_monomial_mul {i : \u03c3} {s' : \u03c3 \u2192\u2080 \u2115} :\n  pderiv i (monomial s a * monomial s' a') =\n    pderiv i (monomial s a) * monomial s' a' + monomial s a * pderiv i (monomial s' a') :=\nbegin\n  simp [monomial_sub_single_one_add, monomial_add_sub_single_one],\n  congr,\n  ring,\nend\n\n@[simp]\nlemma pderiv_mul {i : \u03c3} {f g : mv_polynomial \u03c3 R} :\n  pderiv i (f * g) = pderiv i f * g + f * pderiv i g :=\nbegin\n  apply induction_on' f,\n  { apply induction_on' g,\n    { intros u r u' r', exact pderiv_monomial_mul },\n    { intros p q hp hq u r,\n      rw [mul_add, linear_map.map_add, hp, hq, mul_add, linear_map.map_add],\n      ring } },\n  { intros p q hp hq,\n    simp [add_mul, hp, hq],\n    ring, }\nend\n\n@[simp]\nlemma pderiv_C_mul {f : mv_polynomial \u03c3 R} {i : \u03c3} :\n  pderiv i (C a * f) = C a * pderiv i f :=\nby convert linear_map.map_smul (pderiv i) a f; rw C_mul'\n\n@[simp]\nlemma pderiv_pow {i : \u03c3} {f : mv_polynomial \u03c3 R} {n : \u2115} :\n  pderiv i (f^n) = n * pderiv i f * f^(n-1) :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp only [nat.succ_sub_succ_eq_sub, nat.cast_succ, nat.sub_zero, mv_polynomial.pderiv_mul,\n      pow_succ, ih],\n    cases n,\n    { simp, },\n    { simp only [nat.succ_eq_add_one, nat.add_succ_sub_one, add_zero, nat.cast_add, nat.cast_one,\n        pow_succ],\n      ring, }, },\nend\n\n@[simp]\nlemma pderiv_nat_cast {i : \u03c3} {n : \u2115} : pderiv i (n : mv_polynomial \u03c3 R) = 0 :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih], },\nend\n\nend pderiv\n\nend mv_polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/mv_polynomial/pderiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7169441183601398}}
{"text": "/-\nCopyright (c) 2020 Kevin Lacker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Lacker\n-/\n\nimport data.nat.fib\nimport tactic.linarith\n\n/-!\n# IMO 1981 Q3\n\nDetermine the maximum value of `m ^ 2 + n ^ 2`, where `m` and `n` are integers in\n`{1, 2, ..., 1981}` and `(n ^ 2 - m * n - m ^ 2) ^ 2 = 1`.\n\nThe trick to this problem is that `m` and `n` have to be consecutive Fibonacci numbers,\nbecause you can reduce any solution to a smaller one using the Fibonacci recurrence.\n-/\n\n/-\nFirst, define the problem in terms of finding the maximum of a set.\n\nWe first generalize the problem to `{1, 2, ..., N}` and specialize to `N = 1981` at the very end.\n-/\n\nopen int nat set\nsection\nvariable (N : \u2115) -- N = 1981\n\n@[mk_iff] structure problem_predicate (m n : \u2124) : Prop :=\n(m_range : m \u2208 Ioc 0 (N : \u2124))\n(n_range : n \u2208 Ioc 0 (N : \u2124))\n(eq_one : (n ^ 2 - m * n - m ^ 2) ^ 2 = 1)\n\ndef specified_set : set \u2124 :=\n{k : \u2124 | \u2203 m : \u2124, \u2203 n : \u2124, k = m ^ 2 + n ^ 2 \u2227 problem_predicate N m n}\n\n/-\nWe want to reduce every solution to a smaller solution. Specifically,\nwe show that when `(m, n)` is a solution, `(n - m, m)` is also a solution,\nexcept for the base case of `(1, 1)`.\n-/\nnamespace problem_predicate\nvariable {N}\n\nlemma m_le_n {m n : \u2124} (h1 : problem_predicate N m n) : m \u2264 n :=\nbegin\n  by_contradiction h2,\n  have h3 : 1 = (n * (n - m) - m ^ 2) ^ 2,\n  { calc 1 = (n ^ 2 - m * n - m ^ 2) ^ 2 : h1.eq_one.symm\n       ... = (n * (n - m) - m ^ 2) ^ 2   : by ring },\n  have h4 : n * (n - m) - m ^ 2 < -1, by nlinarith [h1.n_range.left],\n  have h5 : 1 < (n * (n - m) - m ^ 2) ^ 2, by nlinarith,\n  exact h5.ne h3\nend\n\nlemma eq_imp_1 {n : \u2124} (h1 : problem_predicate N n n) : n = 1 :=\nbegin\n  have : n * (n * (n * n)) = 1,\n  { calc _ = (n ^ 2 - n * n - n ^ 2) ^ 2 : by simp [sq, mul_assoc]\n       ... = 1                           : h1.eq_one },\n  exact eq_one_of_mul_eq_one_right h1.m_range.left.le this,\nend\n\nlemma reduction {m n : \u2124} (h1 : problem_predicate N m n) (h2 : 1 < n) :\nproblem_predicate N (n - m) m :=\nbegin\n  obtain (rfl : m = n) | (h3 : m < n) := h1.m_le_n.eq_or_lt,\n  { have h4 : m = 1, from h1.eq_imp_1,\n    exact absurd h4.symm h2.ne },\n  refine_struct { n_range := h1.m_range, .. },\n  -- m_range:\n  { have h5 : 0 < n - m, from sub_pos.mpr h3,\n    have h6 : n - m < N,\n    { calc _ < n : sub_lt_self n h1.m_range.left\n         ... \u2264 N : h1.n_range.right },\n    exact \u27e8h5, h6.le\u27e9 },\n  -- eq_one:\n  { calc _ = (n ^ 2 - m * n - m ^ 2) ^ 2 : by ring\n       ... = 1                           : h1.eq_one },\nend\n\nend problem_predicate\n\n/-\nIt will be convenient to have the lemmas above in their natural number form.\nMost of these can be proved with the `norm_cast` family of tactics.\n-/\n\ndef nat_predicate (m n : \u2115) : Prop := problem_predicate N \u2191m \u2191n\n\nnamespace nat_predicate\nvariable {N}\n\nlemma m_le_n {m n : \u2115} (h1 : nat_predicate N m n) : m \u2264 n :=\nby exact_mod_cast h1.m_le_n\n\nlemma eq_imp_1 {n : \u2115} (h1 : nat_predicate N n n) : n = 1 :=\nby exact_mod_cast h1.eq_imp_1\n\nlemma reduction {m n : \u2115} (h1 : nat_predicate N m n) (h2 : 1 < n) :\n  nat_predicate N (n - m) m :=\nhave m \u2264 n, from h1.m_le_n,\nby exact_mod_cast h1.reduction (by exact_mod_cast h2)\n\nlemma n_pos {m n : \u2115} (h1 : nat_predicate N m n) : 0 < n :=\nby exact_mod_cast h1.n_range.left\n\nlemma m_pos {m n : \u2115} (h1 : nat_predicate N m n) : 0 < m :=\nby exact_mod_cast h1.m_range.left\n\nlemma n_le_N {m n : \u2115} (h1 : nat_predicate N m n) : n \u2264 N :=\nby exact_mod_cast h1.n_range.right\n\n/-\nNow we can use induction to show that solutions must be Fibonacci numbers.\n-/\nlemma imp_fib {n : \u2115} : \u2200 m : \u2115, nat_predicate N m n \u2192\n  \u2203 k : \u2115, m = fib k \u2227 n = fib (k + 1) :=\nbegin\n  apply nat.strong_induction_on n _,\n  intros n h1 m h2,\n  have h3 : m \u2264 n, from h2.m_le_n,\n  obtain (rfl : 1 = n) | (h4 : 1 < n) := (succ_le_iff.mpr h2.n_pos).eq_or_lt,\n  { use 1,\n    have h5 : 1 \u2264 m, from succ_le_iff.mpr h2.m_pos,\n    simpa [fib_one, fib_two] using (h3.antisymm h5 : m = 1) },\n  { obtain (rfl : m = n) | (h6 : m < n) := h3.eq_or_lt,\n    { exact absurd h2.eq_imp_1 (ne_of_gt h4) },\n    { have h7 : nat_predicate N (n - m) m, from h2.reduction h4,\n      obtain \u27e8k : \u2115, hnm : n - m = fib k, rfl : m = fib (k+1)\u27e9 := h1 m h6 (n - m) h7,\n      use [k + 1, rfl],\n      rw [fib_succ_succ, \u2190 hnm, nat.sub_add_cancel h3] } }\nend\n\nend nat_predicate\n\n/-\nNext, we prove that if `N < fib K + fib (K+1)`, then the largest `m` and `n`\nsatisfying `nat_predicate m n N` are `fib K` and `fib (K+1)`, respectively.\n-/\n\nvariables {K : \u2115} (HK : N < fib K + fib (K+1)) {N}\ninclude HK\n\nlemma m_n_bounds {m n : \u2115} (h1 : nat_predicate N m n) : m \u2264 fib K \u2227 n \u2264 fib (K+1) :=\nbegin\n  obtain \u27e8k : \u2115, hm : m = fib k, hn : n = fib (k+1)\u27e9 := h1.imp_fib m,\n  by_cases h2 : k < K + 1,\n  { have h3 : k \u2264 K, from lt_succ_iff.mp h2,\n    split,\n    { calc m = fib k : hm\n         ... \u2264 fib K : fib_mono h3, },\n    { have h6 : k + 1 \u2264 K + 1, from succ_le_succ h3,\n      calc n = fib (k+1) : hn\n         ... \u2264 fib (K+1) : fib_mono h6 } },\n  { have h7 : N < n,\n    { have h8 : K + 2 \u2264 k + 1, from succ_le_succ (not_lt.mp h2),\n      calc N < fib (K+2) : HK\n         ... \u2264 fib (k+1) : fib_mono h8\n         ... = n         : hn.symm, },\n    have h9 : n \u2264 N, from h1.n_le_N,\n    exact absurd h7 h9.not_lt }\nend\n\n/-\nWe spell out the consequences of this result for `specified_set N` here.\n-/\n\nvariables {M : \u2115} (HM : M = (fib K) ^ 2 + (fib (K+1)) ^ 2)\ninclude HM\n\nlemma k_bound {m n : \u2124} (h1 : problem_predicate N m n) : m ^ 2 + n ^ 2 \u2264 M :=\nbegin\n  have h2 : 0 \u2264 m, from h1.m_range.left.le,\n  have h3 : 0 \u2264 n, from h1.n_range.left.le,\n  rw [\u2190 nat_abs_of_nonneg h2, \u2190 nat_abs_of_nonneg h3] at h1, clear h2 h3,\n  obtain \u27e8h4 : m.nat_abs \u2264 fib K, h5 : n.nat_abs \u2264 fib (K+1)\u27e9 := m_n_bounds HK h1,\n  have h6 : m ^ 2 \u2264 (fib K) ^ 2, from nat_abs_le_iff_sq_le.mp h4,\n  have h7 : n ^ 2 \u2264 (fib (K+1)) ^ 2, from nat_abs_le_iff_sq_le.mp h5,\n  linarith\nend\n\nlemma solution_bound : \u2200 {k : \u2124}, k \u2208 specified_set N \u2192 k \u2264 M\n| _ \u27e8_, _, rfl, h\u27e9 := k_bound HK HM h\n\ntheorem solution_greatest (H : problem_predicate N (fib K) (fib (K + 1))) :\n  is_greatest (specified_set N) M :=\n\u27e8\u27e8fib K, fib (K+1), by simp [HM], H\u27e9, \u03bb k h, solution_bound HK HM h\u27e9\n\nend\n\n/-\nNow we just have to demonstrate that 987 and 1597 are in fact the largest Fibonacci\nnumbers in this range, and thus provide the maximum of `specified_set`.\n-/\n\ntheorem imo1981_q3 : is_greatest (specified_set 1981) 3524578 :=\nbegin\n  have := \u03bb h, @solution_greatest 1981 16 h 3524578,\n  simp only [show fib (16:\u2115) = 987 \u2227 fib (16+1:\u2115) = 1597,\n    by norm_num [fib_succ_succ]] at this,\n  apply_mod_cast this; norm_num [problem_predicate_iff],\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/imo/imo1981_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.7169441042040462}}
{"text": "import Category.Init\n\n\n/-!\n# Category **FPL**\n\n`Fpl` is the **FPL** category:\n- objects are all `int`, `real`, `bool` and `unit`, and\n- arrows are the following operations:\n  - identity on all four objects\n  - `isZero : int \u2192 bool`\n  - `not : bool \u2192 bool`\n  - `succ\u1d62 : int \u2192 int`\n  - `succ\u1d63 : real \u2192 real`\n  - `toReal : int \u2192 real`\n  - `zero : unit \u2192 int`\n  - `true : unit \u2192 Bool`\n  - `false : unit \u2192 Bool`\n  - `unit : unit \u2192 unit`\n-/\n\n\n\nnamespace Fpl\n\nopen Lean (Rat)\n\n\n\ninductive Obj : Type 1\n  --- Naturals.\n  | N\n  --- Rationals.\n  | R\n  --- Bool.\n  | B\n  --- Unit.\n  | U\nderiving Inhabited, BEq\n\nabbrev nat :=\n  Obj.N\nabbrev rat :=\n  Obj.R\nabbrev bool :=\n  Obj.B\nabbrev unit :=\n  Obj.U\n\nabbrev Obj.concrete : Obj \u2192 Type\n  | N => Nat\n  | R => Rat\n  | B => Bool\n  | U => Unit\n\n\n\ninductive Val\n  | N : Obj.N.concrete \u2192 Val\n  | R : Obj.R.concrete \u2192 Val\n  | B : Obj.B.concrete \u2192 Val\n  | U : Obj.U.concrete \u2192 Val\nderiving Inhabited, BEq\n\nabbrev Val.type : Val \u2192 Obj\n  | N _ => Obj.N\n  | R _ => Obj.R\n  | B _ => Obj.B\n  | U _ => Obj.U\n\n\n\nabbrev F (\u03b1 \u03b2 : Obj) : Type :=\n  \u03b1.concrete \u2192 \u03b2.concrete\n\ninfix:min \" \u21d2 \" => F\n\n\n\nabbrev F.id (\u03b1 : Obj) : \u03b1 \u21d2 \u03b1 :=\n  fun val => val\n\n\n\nabbrev F.tru : unit \u21d2 bool :=\n  \ud835\udd42 true\n\nabbrev F.fls : unit \u21d2 bool :=\n  \ud835\udd42 false\n\nabbrev F.not : bool \u21d2 bool :=\n  fun b => !b\n\n\n\nabbrev F.isZero : nat \u21d2 bool :=\n  fun\n    | 0 => true\n    | _ + 1 => false\n\nabbrev F.succ\u1d62 : nat \u21d2 nat :=\n  (\u00b7 + 1)\n\nabbrev F.zero : unit \u21d2 nat :=\n  \ud835\udd42 0\n\nabbrev F.toRat : nat \u21d2 rat :=\n  (Lean.mkRat \u00b7 1)\n\n\n\nabbrev F.succ\u1d63 : rat \u21d2 rat :=\n  (\u00b7 + 1)\n\n\n\n@[reducible]\ninductive A : Obj \u2192 Obj \u2192 Type 1\n  | id : {\u03b3 : Obj} \u2192 A \u03b3 \u03b3\n  | tru : A unit bool\n  | fls : A unit bool\n  | not : A bool bool\n  | isZero : A nat bool\n  | succ\u1d62 : A nat nat\n  | zero : A unit nat\n  | toRat : A nat rat\n  | succ\u1d63 : A rat rat\n  | comp : (A \u03b2 \u03b3) \u2192 (A \u03b1 \u03b2) \u2192 A \u03b1 \u03b3\n\nabbrev A.concrete : A \u03b1 \u03b2 \u2192 (\u03b1 \u21d2 \u03b2)\n  | id => F.id \u03b1\n  | tru => F.tru\n  | fls => F.fls\n  | not => F.not\n  | isZero => F.isZero\n  | succ\u1d62 => F.succ\u1d62\n  | zero => F.zero\n  | toRat => F.toRat\n  | succ\u1d63 => F.succ\u1d63\n  | comp f g => f.concrete \u2218 g.concrete\nabbrev A.\u03c7 :=\n  @A.concrete\n\n\n\ntheorem A.concrete_comp\n  (f : A \u03b2 \u03b3)\n  (g : A \u03b1 \u03b2)\n: f.\u03c7 \u2218 g.\u03c7 = (f.comp g).\u03c7\n:=\n  rfl\n\ntheorem A.concrete_comp_assoc\n  (f : A \u03b3 \u03b4)\n  (g : A \u03b2 \u03b3)\n  (h : A \u03b1 \u03b2)\n: (f.comp (g.comp h)).\u03c7 = ((f.comp g).comp h).\u03c7\n:=\n  rfl\n\n\n\ntheorem A.id_comp\n  (f : A \u03b1 \u03b2)\n: (id.comp f).\u03c7 = f.\u03c7\n:=\n  rfl\ntheorem A.comp_id\n  (f : A \u03b1 \u03b2)\n: (f.comp id).\u03c7 = f.\u03c7\n:=\n  rfl\n\n\n\ntheorem A.comp_not_not\n: (not.comp not).\u03c7 = id.\u03c7\n:=\n  funext (by simp)\ntheorem A.comp_not_tru\n: (not.comp tru).\u03c7 = fls.\u03c7\n:=\n  rfl\ntheorem A.comp_not_fls\n: (not.comp fls).\u03c7 = tru.\u03c7\n:=\n  rfl\n\n\n\ntheorem A.comp_isZero_zero\n: (isZero.comp zero).\u03c7 = tru.\u03c7\n:=\n  rfl\n\ntheorem A.comp_isZero_succ\u1d62\n: (isZero.comp (succ\u1d62.comp f)).\u03c7 = fls.\u03c7\n:=\n  rfl\n\n\n\nend Fpl\n\n\n/-! ## FPL is a category -/\n\ndef Cat.Fpl : Cat Fpl.Obj Fpl.Obj.concrete Fpl.A Fpl.F where\n  aConcrete :=\n    Fpl.A.concrete\n\n  compose :=\n    Fpl.A.comp\n  compose_assoc :=\n    Fpl.A.concrete_comp_assoc\n\n  id :=\n    Fpl.A.id\n  id_compose :=\n    Fpl.A.id_comp\n  compose_id :=\n    Fpl.A.comp_id\n\n", "meta": {"author": "AdrienChampion", "repo": "experimentalean4", "sha": "5071a8b007029f61b2e996d9ac89d90999603fcc", "save_path": "github-repos/lean/AdrienChampion-experimentalean4", "path": "github-repos/lean/AdrienChampion-experimentalean4/experimentalean4-5071a8b007029f61b2e996d9ac89d90999603fcc/category/Category/Fpl.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088004, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7169441003540844}}
{"text": "import game.world10.level7 -- hide\nnamespace mynat -- hide\n/- \n\n# Inequality world. \n\n## Level 8: `succ_le_succ`\n\nAnother straightforward one. \n-/\n\n/- Lemma\nFor all naturals $a$ and $b$, if $a\\le b$, then $\\operatorname{succ}(a)\\le\\operatorname{succ}(b)$. \n-/\nlemma succ_le_succ (a b : mynat) (h : a \u2264 b) : succ a \u2264 succ b :=\nbegin [nat_num_game]\n  cases h with c hc,\n  use c,\n  rw hc,\n  rw succ_add,\n  refl,\n  \n\nend\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world10/level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248140158417, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.7169301889687848}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n\n! This file was ported from Lean 3 source module number_theory.divisors\n! leanprover-community/mathlib commit 68d1483e8a718ec63219f0e227ca3f0140361086\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.BigOperators.Order\nimport Mathbin.Data.Nat.Interval\nimport Mathbin.Data.Nat.Factors\n\n/-!\n# Divisor finsets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines sets of divisors of a natural number. This is particularly useful as background\nfor defining Dirichlet convolution.\n\n## Main Definitions\nLet `n : \u2115`. All of the following definitions are in the `nat` namespace:\n * `divisors n` is the `finset` of natural numbers that divide `n`.\n * `proper_divisors n` is the `finset` of natural numbers that divide `n`, other than `n`.\n * `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n * `perfect n` is true when `n` is positive and the sum of `proper_divisors n` is `n`.\n\n## Implementation details\n * `divisors 0`, `proper_divisors 0`, and `divisors_antidiagonal 0` are defined to be `\u2205`.\n\n## Tags\ndivisors, perfect numbers\n\n-/\n\n\nopen Classical\n\nopen BigOperators\n\nopen Finset\n\nnamespace Nat\n\nvariable (n : \u2115)\n\n#print Nat.divisors /-\n/-- `divisors n` is the `finset` of divisors of `n`. As a special case, `divisors 0 = \u2205`. -/\ndef divisors : Finset \u2115 :=\n  Finset.filter (fun x : \u2115 => x \u2223 n) (Finset.Ico 1 (n + 1))\n#align nat.divisors Nat.divisors\n-/\n\n#print Nat.properDivisors /-\n/-- `proper_divisors n` is the `finset` of divisors of `n`, other than `n`.\n  As a special case, `proper_divisors 0 = \u2205`. -/\ndef properDivisors : Finset \u2115 :=\n  Finset.filter (fun x : \u2115 => x \u2223 n) (Finset.Ico 1 n)\n#align nat.proper_divisors Nat.properDivisors\n-/\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n#print Nat.divisorsAntidiagonal /-\n/-- `divisors_antidiagonal n` is the `finset` of pairs `(x,y)` such that `x * y = n`.\n  As a special case, `divisors_antidiagonal 0 = \u2205`. -/\ndef divisorsAntidiagonal : Finset (\u2115 \u00d7 \u2115) :=\n  (Ico 1 (n + 1) \u00d7\u02e2 Ico 1 (n + 1)).filter\u2093 fun x => x.fst * x.snd = n\n#align nat.divisors_antidiagonal Nat.divisorsAntidiagonal\n-/\n\nvariable {n}\n\n/- warning: nat.filter_dvd_eq_divisors -> Nat.filter_dvd_eq_divisors is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} (Finset.{0} Nat) (Finset.filter.{0} Nat (fun (_x : Nat) => Dvd.Dvd.{0} Nat Nat.hasDvd _x n) (fun (a : Nat) => Nat.decidableDvd a n) (Finset.range (Nat.succ n))) (Nat.divisors n))\nbut is expected to have type\n  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} (Finset.{0} Nat) (Finset.filter.{0} Nat (fun (_x : Nat) => Dvd.dvd.{0} Nat Nat.instDvdNat _x n) (fun (a : Nat) => Nat.decidable_dvd a n) (Finset.range (Nat.succ n))) (Nat.divisors n))\nCase conversion may be inaccurate. Consider using '#align nat.filter_dvd_eq_divisors Nat.filter_dvd_eq_divisors\u2093'. -/\n@[simp]\ntheorem filter_dvd_eq_divisors (h : n \u2260 0) : (Finset.range n.succ).filter\u2093 (\u00b7 \u2223 n) = n.divisors :=\n  by\n  ext\n  simp only [divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]\n  exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)\n#align nat.filter_dvd_eq_divisors Nat.filter_dvd_eq_divisors\n\n/- warning: nat.filter_dvd_eq_proper_divisors -> Nat.filter_dvd_eq_properDivisors is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} (Finset.{0} Nat) (Finset.filter.{0} Nat (fun (_x : Nat) => Dvd.Dvd.{0} Nat Nat.hasDvd _x n) (fun (a : Nat) => Nat.decidableDvd a n) (Finset.range n)) (Nat.properDivisors n))\nbut is expected to have type\n  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} (Finset.{0} Nat) (Finset.filter.{0} Nat (fun (_x : Nat) => Dvd.dvd.{0} Nat Nat.instDvdNat _x n) (fun (a : Nat) => Nat.decidable_dvd a n) (Finset.range n)) (Nat.properDivisors n))\nCase conversion may be inaccurate. Consider using '#align nat.filter_dvd_eq_proper_divisors Nat.filter_dvd_eq_properDivisors\u2093'. -/\n@[simp]\ntheorem filter_dvd_eq_properDivisors (h : n \u2260 0) :\n    (Finset.range n).filter\u2093 (\u00b7 \u2223 n) = n.properDivisors :=\n  by\n  ext\n  simp only [proper_divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]\n  exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)\n#align nat.filter_dvd_eq_proper_divisors Nat.filter_dvd_eq_properDivisors\n\n#print Nat.properDivisors.not_self_mem /-\ntheorem properDivisors.not_self_mem : \u00acn \u2208 properDivisors n := by simp [proper_divisors]\n#align nat.proper_divisors.not_self_mem Nat.properDivisors.not_self_mem\n-/\n\n#print Nat.mem_properDivisors /-\n@[simp]\ntheorem mem_properDivisors {m : \u2115} : n \u2208 properDivisors m \u2194 n \u2223 m \u2227 n < m :=\n  by\n  rcases eq_or_ne m 0 with (rfl | hm); \u00b7 simp [proper_divisors]\n  simp only [and_comm', \u2190 filter_dvd_eq_proper_divisors hm, mem_filter, mem_range]\n#align nat.mem_proper_divisors Nat.mem_properDivisors\n-/\n\n/- warning: nat.insert_self_proper_divisors -> Nat.insert_self_properDivisors is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} (Finset.{0} Nat) (Insert.insert.{0, 0} Nat (Finset.{0} Nat) (Finset.hasInsert.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b)) n (Nat.properDivisors n)) (Nat.divisors n))\nbut is expected to have type\n  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} (Finset.{0} Nat) (Insert.insert.{0, 0} Nat (Finset.{0} Nat) (Finset.instInsertFinset.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b)) n (Nat.properDivisors n)) (Nat.divisors n))\nCase conversion may be inaccurate. Consider using '#align nat.insert_self_proper_divisors Nat.insert_self_properDivisors\u2093'. -/\ntheorem insert_self_properDivisors (h : n \u2260 0) : insert n (properDivisors n) = divisors n := by\n  rw [divisors, proper_divisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h),\n    Finset.filter_insert, if_pos (dvd_refl n)]\n#align nat.insert_self_proper_divisors Nat.insert_self_properDivisors\n\n#print Nat.cons_self_properDivisors /-\ntheorem cons_self_properDivisors (h : n \u2260 0) :\n    cons n (properDivisors n) properDivisors.not_self_mem = divisors n := by\n  rw [cons_eq_insert, insert_self_proper_divisors h]\n#align nat.cons_self_proper_divisors Nat.cons_self_properDivisors\n-/\n\n#print Nat.mem_divisors /-\n@[simp]\ntheorem mem_divisors {m : \u2115} : n \u2208 divisors m \u2194 n \u2223 m \u2227 m \u2260 0 :=\n  by\n  rcases eq_or_ne m 0 with (rfl | hm); \u00b7 simp [divisors]\n  simp only [hm, Ne.def, not_false_iff, and_true_iff, \u2190 filter_dvd_eq_divisors hm, mem_filter,\n    mem_range, and_iff_right_iff_imp, lt_succ_iff]\n  exact le_of_dvd hm.bot_lt\n#align nat.mem_divisors Nat.mem_divisors\n-/\n\n#print Nat.one_mem_divisors /-\ntheorem one_mem_divisors : 1 \u2208 divisors n \u2194 n \u2260 0 := by simp\n#align nat.one_mem_divisors Nat.one_mem_divisors\n-/\n\n#print Nat.mem_divisors_self /-\ntheorem mem_divisors_self (n : \u2115) (h : n \u2260 0) : n \u2208 n.divisors :=\n  mem_divisors.2 \u27e8dvd_rfl, h\u27e9\n#align nat.mem_divisors_self Nat.mem_divisors_self\n-/\n\n#print Nat.dvd_of_mem_divisors /-\ntheorem dvd_of_mem_divisors {m : \u2115} (h : n \u2208 divisors m) : n \u2223 m :=\n  by\n  cases m\n  \u00b7 apply dvd_zero\n  \u00b7 simp [mem_divisors.1 h]\n#align nat.dvd_of_mem_divisors Nat.dvd_of_mem_divisors\n-/\n\n#print Nat.mem_divisorsAntidiagonal /-\n@[simp]\ntheorem mem_divisorsAntidiagonal {x : \u2115 \u00d7 \u2115} :\n    x \u2208 divisorsAntidiagonal n \u2194 x.fst * x.snd = n \u2227 n \u2260 0 :=\n  by\n  simp only [divisors_antidiagonal, Finset.mem_Ico, Ne.def, Finset.mem_filter, Finset.mem_product]\n  rw [and_comm']\n  apply and_congr_right\n  rintro rfl\n  constructor <;> intro h\n  \u00b7 contrapose! h\n    simp [h]\n  \u00b7 rw [Nat.lt_add_one_iff, Nat.lt_add_one_iff]\n    rw [mul_eq_zero, Decidable.not_or_iff_and_not] at h\n    simp only [succ_le_of_lt (Nat.pos_of_ne_zero h.1), succ_le_of_lt (Nat.pos_of_ne_zero h.2),\n      true_and_iff]\n    exact\n      \u27e8le_mul_of_pos_right (Nat.pos_of_ne_zero h.2), le_mul_of_pos_left (Nat.pos_of_ne_zero h.1)\u27e9\n#align nat.mem_divisors_antidiagonal Nat.mem_divisorsAntidiagonal\n-/\n\nvariable {n}\n\n#print Nat.divisor_le /-\ntheorem divisor_le {m : \u2115} : n \u2208 divisors m \u2192 n \u2264 m :=\n  by\n  cases m\n  \u00b7 simp\n  simp only [mem_divisors, m.succ_ne_zero, and_true_iff, Ne.def, not_false_iff]\n  exact Nat.le_of_dvd (Nat.succ_pos m)\n#align nat.divisor_le Nat.divisor_le\n-/\n\n#print Nat.divisors_subset_of_dvd /-\ntheorem divisors_subset_of_dvd {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) : divisors m \u2286 divisors n :=\n  Finset.subset_iff.2 fun x hx => Nat.mem_divisors.mpr \u27e8(Nat.mem_divisors.mp hx).1.trans h, hzero\u27e9\n#align nat.divisors_subset_of_dvd Nat.divisors_subset_of_dvd\n-/\n\n#print Nat.divisors_subset_properDivisors /-\ntheorem divisors_subset_properDivisors {m : \u2115} (hzero : n \u2260 0) (h : m \u2223 n) (hdiff : m \u2260 n) :\n    divisors m \u2286 properDivisors n := by\n  apply Finset.subset_iff.2\n  intro x hx\n  exact\n    Nat.mem_properDivisors.2\n      \u27e8(Nat.mem_divisors.1 hx).1.trans h,\n        lt_of_le_of_lt (divisor_le hx)\n          (lt_of_le_of_ne (divisor_le (Nat.mem_divisors.2 \u27e8h, hzero\u27e9)) hdiff)\u27e9\n#align nat.divisors_subset_proper_divisors Nat.divisors_subset_properDivisors\n-/\n\n#print Nat.divisors_zero /-\n@[simp]\ntheorem divisors_zero : divisors 0 = \u2205 := by\n  ext\n  simp\n#align nat.divisors_zero Nat.divisors_zero\n-/\n\n#print Nat.properDivisors_zero /-\n@[simp]\ntheorem properDivisors_zero : properDivisors 0 = \u2205 :=\n  by\n  ext\n  simp\n#align nat.proper_divisors_zero Nat.properDivisors_zero\n-/\n\n#print Nat.properDivisors_subset_divisors /-\ntheorem properDivisors_subset_divisors : properDivisors n \u2286 divisors n :=\n  filter_subset_filter _ <| Ico_subset_Ico_right n.le_succ\n#align nat.proper_divisors_subset_divisors Nat.properDivisors_subset_divisors\n-/\n\n#print Nat.divisors_one /-\n@[simp]\ntheorem divisors_one : divisors 1 = {1} := by\n  ext\n  simp\n#align nat.divisors_one Nat.divisors_one\n-/\n\n#print Nat.properDivisors_one /-\n@[simp]\ntheorem properDivisors_one : properDivisors 1 = \u2205 := by rw [proper_divisors, Ico_self, filter_empty]\n#align nat.proper_divisors_one Nat.properDivisors_one\n-/\n\n#print Nat.pos_of_mem_divisors /-\ntheorem pos_of_mem_divisors {m : \u2115} (h : m \u2208 n.divisors) : 0 < m :=\n  by\n  cases m\n  \u00b7 rw [mem_divisors, zero_dvd_iff] at h\n    cases h.2 h.1\n  apply Nat.succ_pos\n#align nat.pos_of_mem_divisors Nat.pos_of_mem_divisors\n-/\n\n#print Nat.pos_of_mem_properDivisors /-\ntheorem pos_of_mem_properDivisors {m : \u2115} (h : m \u2208 n.properDivisors) : 0 < m :=\n  pos_of_mem_divisors (properDivisors_subset_divisors h)\n#align nat.pos_of_mem_proper_divisors Nat.pos_of_mem_properDivisors\n-/\n\n#print Nat.one_mem_properDivisors_iff_one_lt /-\ntheorem one_mem_properDivisors_iff_one_lt : 1 \u2208 n.properDivisors \u2194 1 < n := by\n  rw [mem_proper_divisors, and_iff_right (one_dvd _)]\n#align nat.one_mem_proper_divisors_iff_one_lt Nat.one_mem_properDivisors_iff_one_lt\n-/\n\n#print Nat.divisorsAntidiagonal_zero /-\n@[simp]\ntheorem divisorsAntidiagonal_zero : divisorsAntidiagonal 0 = \u2205 :=\n  by\n  ext\n  simp\n#align nat.divisors_antidiagonal_zero Nat.divisorsAntidiagonal_zero\n-/\n\n#print Nat.divisorsAntidiagonal_one /-\n@[simp]\ntheorem divisorsAntidiagonal_one : divisorsAntidiagonal 1 = {(1, 1)} :=\n  by\n  ext\n  simp [Nat.mul_eq_one_iff, Prod.ext_iff]\n#align nat.divisors_antidiagonal_one Nat.divisorsAntidiagonal_one\n-/\n\n#print Nat.swap_mem_divisorsAntidiagonal /-\n@[simp]\ntheorem swap_mem_divisorsAntidiagonal {x : \u2115 \u00d7 \u2115} :\n    x.symm \u2208 divisorsAntidiagonal n \u2194 x \u2208 divisorsAntidiagonal n := by\n  rw [mem_divisors_antidiagonal, mem_divisors_antidiagonal, mul_comm, Prod.swap]\n#align nat.swap_mem_divisors_antidiagonal Nat.swap_mem_divisorsAntidiagonal\n-/\n\n#print Nat.fst_mem_divisors_of_mem_antidiagonal /-\ntheorem fst_mem_divisors_of_mem_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisorsAntidiagonal n) :\n    x.fst \u2208 divisors n := by\n  rw [mem_divisors_antidiagonal] at h\n  simp [Dvd.intro _ h.1, h.2]\n#align nat.fst_mem_divisors_of_mem_antidiagonal Nat.fst_mem_divisors_of_mem_antidiagonal\n-/\n\n#print Nat.snd_mem_divisors_of_mem_antidiagonal /-\ntheorem snd_mem_divisors_of_mem_antidiagonal {x : \u2115 \u00d7 \u2115} (h : x \u2208 divisorsAntidiagonal n) :\n    x.snd \u2208 divisors n := by\n  rw [mem_divisors_antidiagonal] at h\n  simp [Dvd.intro_left _ h.1, h.2]\n#align nat.snd_mem_divisors_of_mem_antidiagonal Nat.snd_mem_divisors_of_mem_antidiagonal\n-/\n\n#print Nat.map_swap_divisorsAntidiagonal /-\n@[simp]\ntheorem map_swap_divisorsAntidiagonal :\n    (divisorsAntidiagonal n).map (Equiv.prodComm _ _).toEmbedding = divisorsAntidiagonal n :=\n  by\n  rw [\u2190 coe_inj, coe_map, Equiv.coe_toEmbedding, Equiv.coe_prodComm,\n    Set.image_swap_eq_preimage_swap]\n  ext\n  exact swap_mem_divisors_antidiagonal\n#align nat.map_swap_divisors_antidiagonal Nat.map_swap_divisorsAntidiagonal\n-/\n\n/- warning: nat.image_fst_divisors_antidiagonal -> Nat.image_fst_divisorsAntidiagonal is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat}, Eq.{1} (Finset.{0} Nat) (Finset.image.{0, 0} (Prod.{0, 0} Nat Nat) Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (Prod.fst.{0, 0} Nat Nat) (Nat.divisorsAntidiagonal n)) (Nat.divisors n)\nbut is expected to have type\n  forall {n : Nat}, Eq.{1} (Finset.{0} Nat) (Finset.image.{0, 0} (Prod.{0, 0} Nat Nat) Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (Prod.fst.{0, 0} Nat Nat) (Nat.divisorsAntidiagonal n)) (Nat.divisors n)\nCase conversion may be inaccurate. Consider using '#align nat.image_fst_divisors_antidiagonal Nat.image_fst_divisorsAntidiagonal\u2093'. -/\n@[simp]\ntheorem image_fst_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.fst = divisors n :=\n  by\n  ext\n  simp [Dvd.Dvd, @eq_comm _ n (_ * _)]\n#align nat.image_fst_divisors_antidiagonal Nat.image_fst_divisorsAntidiagonal\n\n/- warning: nat.image_snd_divisors_antidiagonal -> Nat.image_snd_divisorsAntidiagonal is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat}, Eq.{1} (Finset.{0} Nat) (Finset.image.{0, 0} (Prod.{0, 0} Nat Nat) Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (Prod.snd.{0, 0} Nat Nat) (Nat.divisorsAntidiagonal n)) (Nat.divisors n)\nbut is expected to have type\n  forall {n : Nat}, Eq.{1} (Finset.{0} Nat) (Finset.image.{0, 0} (Prod.{0, 0} Nat Nat) Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (Prod.snd.{0, 0} Nat Nat) (Nat.divisorsAntidiagonal n)) (Nat.divisors n)\nCase conversion may be inaccurate. Consider using '#align nat.image_snd_divisors_antidiagonal Nat.image_snd_divisorsAntidiagonal\u2093'. -/\n@[simp]\ntheorem image_snd_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.snd = divisors n :=\n  by\n  rw [\u2190 map_swap_divisors_antidiagonal, map_eq_image, image_image]\n  exact image_fst_divisors_antidiagonal\n#align nat.image_snd_divisors_antidiagonal Nat.image_snd_divisorsAntidiagonal\n\n#print Nat.map_div_right_divisors /-\ntheorem map_div_right_divisors :\n    n.divisors.map \u27e8fun d => (d, n / d), fun p\u2081 p\u2082 => congr_arg Prod.fst\u27e9 =\n      n.divisorsAntidiagonal :=\n  by\n  ext \u27e8d, nd\u27e9\n  simp only [mem_map, mem_divisors_antidiagonal, Function.Embedding.coeFn_mk, mem_divisors,\n    Prod.ext_iff, exists_prop, and_left_comm, exists_eq_left]\n  constructor\n  \u00b7 rintro \u27e8\u27e8\u27e8k, rfl\u27e9, hn\u27e9, rfl\u27e9\n    rw [Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt]\n    exact \u27e8rfl, hn\u27e9\n  \u00b7 rintro \u27e8rfl, hn\u27e9\n    exact \u27e8\u27e8dvd_mul_right _ _, hn\u27e9, Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt\u27e9\n#align nat.map_div_right_divisors Nat.map_div_right_divisors\n-/\n\n#print Nat.map_div_left_divisors /-\ntheorem map_div_left_divisors :\n    n.divisors.map \u27e8fun d => (n / d, d), fun p\u2081 p\u2082 => congr_arg Prod.snd\u27e9 =\n      n.divisorsAntidiagonal :=\n  by\n  apply Finset.map_injective (Equiv.prodComm _ _).toEmbedding\n  rw [map_swap_divisors_antidiagonal, \u2190 map_div_right_divisors, Finset.map_map]\n  rfl\n#align nat.map_div_left_divisors Nat.map_div_left_divisors\n-/\n\n#print Nat.sum_divisors_eq_sum_properDivisors_add_self /-\ntheorem sum_divisors_eq_sum_properDivisors_add_self :\n    (\u2211 i in divisors n, i) = (\u2211 i in properDivisors n, i) + n :=\n  by\n  rcases Decidable.eq_or_ne n 0 with (rfl | hn)\n  \u00b7 simp\n  \u00b7 rw [\u2190 cons_self_proper_divisors hn, Finset.sum_cons, add_comm]\n#align nat.sum_divisors_eq_sum_proper_divisors_add_self Nat.sum_divisors_eq_sum_properDivisors_add_self\n-/\n\n#print Nat.Perfect /-\n/-- `n : \u2115` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`\n  is positive. -/\ndef Perfect (n : \u2115) : Prop :=\n  (\u2211 i in properDivisors n, i) = n \u2227 0 < n\n#align nat.perfect Nat.Perfect\n-/\n\n#print Nat.perfect_iff_sum_properDivisors /-\ntheorem perfect_iff_sum_properDivisors (h : 0 < n) : Perfect n \u2194 (\u2211 i in properDivisors n, i) = n :=\n  and_iff_left h\n#align nat.perfect_iff_sum_proper_divisors Nat.perfect_iff_sum_properDivisors\n-/\n\n#print Nat.perfect_iff_sum_divisors_eq_two_mul /-\ntheorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) :\n    Perfect n \u2194 (\u2211 i in divisors n, i) = 2 * n :=\n  by\n  rw [perfect_iff_sum_proper_divisors h, sum_divisors_eq_sum_proper_divisors_add_self, two_mul]\n  constructor <;> intro h\n  \u00b7 rw [h]\n  \u00b7 apply add_right_cancel h\n#align nat.perfect_iff_sum_divisors_eq_two_mul Nat.perfect_iff_sum_divisors_eq_two_mul\n-/\n\n#print Nat.mem_divisors_prime_pow /-\ntheorem mem_divisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) {x : \u2115} :\n    x \u2208 divisors (p ^ k) \u2194 \u2203 (j : \u2115)(H : j \u2264 k), x = p ^ j := by\n  rw [mem_divisors, Nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))]\n#align nat.mem_divisors_prime_pow Nat.mem_divisors_prime_pow\n-/\n\n/- warning: nat.prime.divisors -> Nat.Prime.divisors is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (Nat.Prime p) -> (Eq.{1} (Finset.{0} Nat) (Nat.divisors p) (Insert.insert.{0, 0} Nat (Finset.{0} Nat) (Finset.hasInsert.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Singleton.singleton.{0, 0} Nat (Finset.{0} Nat) (Finset.hasSingleton.{0} Nat) p)))\nbut is expected to have type\n  forall {p : Nat}, (Nat.Prime p) -> (Eq.{1} (Finset.{0} Nat) (Nat.divisors p) (Insert.insert.{0, 0} Nat (Finset.{0} Nat) (Finset.instInsertFinset.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) (Singleton.singleton.{0, 0} Nat (Finset.{0} Nat) (Finset.instSingletonFinset.{0} Nat) p)))\nCase conversion may be inaccurate. Consider using '#align nat.prime.divisors Nat.Prime.divisors\u2093'. -/\ntheorem Prime.divisors {p : \u2115} (pp : p.Prime) : divisors p = {1, p} :=\n  by\n  ext\n  rw [mem_divisors, dvd_prime pp, and_iff_left pp.ne_zero, Finset.mem_insert, Finset.mem_singleton]\n#align nat.prime.divisors Nat.Prime.divisors\n\n#print Nat.Prime.properDivisors /-\ntheorem Prime.properDivisors {p : \u2115} (pp : p.Prime) : properDivisors p = {1} := by\n  rw [\u2190 erase_insert proper_divisors.not_self_mem, insert_self_proper_divisors pp.ne_zero,\n    pp.divisors, pair_comm, erase_insert fun con => pp.ne_one (mem_singleton.1 Con)]\n#align nat.prime.proper_divisors Nat.Prime.properDivisors\n-/\n\n#print Nat.divisors_prime_pow /-\ntheorem divisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) :\n    divisors (p ^ k) = (Finset.range (k + 1)).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\n  by\n  ext\n  simp [mem_divisors_prime_pow, pp, Nat.lt_succ_iff, @eq_comm _ a]\n#align nat.divisors_prime_pow Nat.divisors_prime_pow\n-/\n\n#print Nat.eq_properDivisors_of_subset_of_sum_eq_sum /-\ntheorem eq_properDivisors_of_subset_of_sum_eq_sum {s : Finset \u2115} (hsub : s \u2286 n.properDivisors) :\n    ((\u2211 x in s, x) = \u2211 x in n.properDivisors, x) \u2192 s = n.properDivisors :=\n  by\n  cases n\n  \u00b7 rw [proper_divisors_zero, subset_empty] at hsub\n    simp [hsub]\n  classical\n    rw [\u2190 sum_sdiff hsub]\n    intro h\n    apply subset.antisymm hsub\n    rw [\u2190 sdiff_eq_empty_iff_subset]\n    contrapose h\n    rw [\u2190 Ne.def, \u2190 nonempty_iff_ne_empty] at h\n    apply ne_of_lt\n    rw [\u2190 zero_add (\u2211 x in s, x), \u2190 add_assoc, add_zero]\n    apply add_lt_add_right\n    have hlt :=\n      sum_lt_sum_of_nonempty h fun x hx => pos_of_mem_proper_divisors (sdiff_subset _ _ hx)\n    simp only [sum_const_zero] at hlt\n    apply hlt\n#align nat.eq_proper_divisors_of_subset_of_sum_eq_sum Nat.eq_properDivisors_of_subset_of_sum_eq_sum\n-/\n\n#print Nat.sum_properDivisors_dvd /-\ntheorem sum_properDivisors_dvd (h : (\u2211 x in n.properDivisors, x) \u2223 n) :\n    (\u2211 x in n.properDivisors, x) = 1 \u2228 (\u2211 x in n.properDivisors, x) = n :=\n  by\n  cases n\n  \u00b7 simp\n  cases n\n  \u00b7 contrapose! h\n    simp\n  rw [or_iff_not_imp_right]\n  intro ne_n\n  have hlt : (\u2211 x in n.succ.succ.proper_divisors, x) < n.succ.succ :=\n    lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h) ne_n\n  symm\n  rw [\u2190 mem_singleton,\n    eq_proper_divisors_of_subset_of_sum_eq_sum\n      (singleton_subset_iff.2 (mem_proper_divisors.2 \u27e8h, hlt\u27e9)) sum_singleton,\n    mem_proper_divisors]\n  refine' \u27e8one_dvd _, Nat.succ_lt_succ (Nat.succ_pos _)\u27e9\n#align nat.sum_proper_divisors_dvd Nat.sum_properDivisors_dvd\n-/\n\n#print Nat.Prime.prod_properDivisors /-\n@[simp, to_additive]\ntheorem Prime.prod_properDivisors {\u03b1 : Type _} [CommMonoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.Prime) :\n    (\u220f x in p.properDivisors, f x) = f 1 := by simp [h.proper_divisors]\n#align nat.prime.prod_proper_divisors Nat.Prime.prod_properDivisors\n#align nat.prime.sum_proper_divisors Nat.Prime.sum_properDivisors\n-/\n\n/- warning: nat.prime.prod_divisors -> Nat.Prime.prod_divisors is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CommMonoid.{u1} \u03b1] {p : Nat} {f : Nat -> \u03b1}, (Nat.Prime p) -> (Eq.{succ u1} \u03b1 (Finset.prod.{u1, 0} \u03b1 Nat _inst_1 (Nat.divisors p) (fun (x : Nat) => f x)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (CommMonoid.toMonoid.{u1} \u03b1 _inst_1)))) (f p) (f (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CommMonoid.{u1} \u03b1] {p : Nat} {f : Nat -> \u03b1}, (Nat.Prime p) -> (Eq.{succ u1} \u03b1 (Finset.prod.{u1, 0} \u03b1 Nat _inst_1 (Nat.divisors p) (fun (x : Nat) => f x)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (CommMonoid.toMonoid.{u1} \u03b1 _inst_1)))) (f p) (f (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))))\nCase conversion may be inaccurate. Consider using '#align nat.prime.prod_divisors Nat.Prime.prod_divisors\u2093'. -/\n@[simp, to_additive]\ntheorem Prime.prod_divisors {\u03b1 : Type _} [CommMonoid \u03b1] {p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.Prime) :\n    (\u220f x in p.divisors, f x) = f p * f 1 := by\n  rw [\u2190 cons_self_proper_divisors h.ne_zero, prod_cons, h.prod_proper_divisors]\n#align nat.prime.prod_divisors Nat.Prime.prod_divisors\n#align nat.prime.sum_divisors Nat.Prime.sum_divisors\n\n#print Nat.properDivisors_eq_singleton_one_iff_prime /-\ntheorem properDivisors_eq_singleton_one_iff_prime : n.properDivisors = {1} \u2194 n.Prime :=\n  \u27e8fun h => by\n    have h1 := mem_singleton.2 rfl\n    rw [\u2190 h, mem_proper_divisors] at h1\n    refine' nat.prime_def_lt''.mpr \u27e8h1.2, fun m hdvd => _\u27e9\n    rw [\u2190 mem_singleton, \u2190 h, mem_proper_divisors]\n    have hle := Nat.le_of_dvd (lt_trans (Nat.succ_pos _) h1.2) hdvd\n    exact Or.imp_left (fun hlt => \u27e8hdvd, hlt\u27e9) hle.lt_or_eq, Prime.properDivisors\u27e9\n#align nat.proper_divisors_eq_singleton_one_iff_prime Nat.properDivisors_eq_singleton_one_iff_prime\n-/\n\n#print Nat.sum_properDivisors_eq_one_iff_prime /-\ntheorem sum_properDivisors_eq_one_iff_prime : (\u2211 x in n.properDivisors, x) = 1 \u2194 n.Prime :=\n  by\n  cases n\n  \u00b7 simp [Nat.not_prime_zero]\n  cases n\n  \u00b7 simp [Nat.not_prime_one]\n  rw [\u2190 proper_divisors_eq_singleton_one_iff_prime]\n  refine' \u27e8fun h => _, fun h => h.symm \u25b8 sum_singleton\u27e9\n  rw [@eq_comm (Finset \u2115) _ _]\n  apply\n    eq_proper_divisors_of_subset_of_sum_eq_sum\n      (singleton_subset_iff.2\n        (one_mem_proper_divisors_iff_one_lt.2 (succ_lt_succ (Nat.succ_pos _))))\n      (Eq.trans sum_singleton h.symm)\n#align nat.sum_proper_divisors_eq_one_iff_prime Nat.sum_properDivisors_eq_one_iff_prime\n-/\n\n#print Nat.mem_properDivisors_prime_pow /-\ntheorem mem_properDivisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) {x : \u2115} :\n    x \u2208 properDivisors (p ^ k) \u2194 \u2203 (j : \u2115)(H : j < k), x = p ^ j :=\n  by\n  rw [mem_proper_divisors, Nat.dvd_prime_pow pp, \u2190 exists_and_right]\n  simp only [exists_prop, and_assoc']\n  apply exists_congr\n  intro a\n  constructor <;> intro h\n  \u00b7 rcases h with \u27e8h_left, rfl, h_right\u27e9\n    rwa [pow_lt_pow_iff pp.one_lt] at h_right\n    simpa\n  \u00b7 rcases h with \u27e8h_left, rfl\u27e9\n    rwa [pow_lt_pow_iff pp.one_lt]\n    simp [h_left, le_of_lt]\n#align nat.mem_proper_divisors_prime_pow Nat.mem_properDivisors_prime_pow\n-/\n\n#print Nat.properDivisors_prime_pow /-\ntheorem properDivisors_prime_pow {p : \u2115} (pp : p.Prime) (k : \u2115) :\n    properDivisors (p ^ k) = (Finset.range k).map \u27e8pow p, pow_right_injective pp.two_le\u27e9 :=\n  by\n  ext\n  simp [mem_proper_divisors_prime_pow, pp, Nat.lt_succ_iff, @eq_comm _ a]\n#align nat.proper_divisors_prime_pow Nat.properDivisors_prime_pow\n-/\n\n#print Nat.prod_properDivisors_prime_pow /-\n@[simp, to_additive]\ntheorem prod_properDivisors_prime_pow {\u03b1 : Type _} [CommMonoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1}\n    (h : p.Prime) : (\u220f x in (p ^ k).properDivisors, f x) = \u220f x in range k, f (p ^ x) := by\n  simp [h, proper_divisors_prime_pow]\n#align nat.prod_proper_divisors_prime_pow Nat.prod_properDivisors_prime_pow\n#align nat.sum_proper_divisors_prime_nsmul Nat.sum_properDivisors_prime_nsmul\n-/\n\n#print Nat.prod_divisors_prime_pow /-\n@[simp, to_additive sum_divisors_prime_pow]\ntheorem prod_divisors_prime_pow {\u03b1 : Type _} [CommMonoid \u03b1] {k p : \u2115} {f : \u2115 \u2192 \u03b1} (h : p.Prime) :\n    (\u220f x in (p ^ k).divisors, f x) = \u220f x in range (k + 1), f (p ^ x) := by\n  simp [h, divisors_prime_pow]\n#align nat.prod_divisors_prime_pow Nat.prod_divisors_prime_pow\n#align nat.sum_divisors_prime_pow Nat.sum_divisors_prime_pow\n-/\n\n#print Nat.prod_divisorsAntidiagonal /-\n@[to_additive]\ntheorem prod_divisorsAntidiagonal {M : Type _} [CommMonoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n    (\u220f i in n.divisorsAntidiagonal, f i.1 i.2) = \u220f i in n.divisors, f i (n / i) :=\n  by\n  rw [\u2190 map_div_right_divisors, Finset.prod_map]\n  rfl\n#align nat.prod_divisors_antidiagonal Nat.prod_divisorsAntidiagonal\n#align nat.sum_divisors_antidiagonal Nat.sum_divisorsAntidiagonal\n-/\n\n#print Nat.prod_divisorsAntidiagonal' /-\n@[to_additive]\ntheorem prod_divisorsAntidiagonal' {M : Type _} [CommMonoid M] (f : \u2115 \u2192 \u2115 \u2192 M) {n : \u2115} :\n    (\u220f i in n.divisorsAntidiagonal, f i.1 i.2) = \u220f i in n.divisors, f (n / i) i :=\n  by\n  rw [\u2190 map_swap_divisors_antidiagonal, Finset.prod_map]\n  exact prod_divisors_antidiagonal fun i j => f j i\n#align nat.prod_divisors_antidiagonal' Nat.prod_divisorsAntidiagonal'\n#align nat.sum_divisors_antidiagonal' Nat.sum_divisorsAntidiagonal'\n-/\n\n/- warning: nat.prime_divisors_eq_to_filter_divisors_prime -> Nat.prime_divisors_eq_to_filter_divisors_prime is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat), Eq.{1} (Finset.{0} Nat) (List.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (Nat.factors n)) (Finset.filter.{0} Nat Nat.Prime (fun (a : Nat) => Nat.decidablePrime a) (Nat.divisors n))\nbut is expected to have type\n  forall (n : Nat), Eq.{1} (Finset.{0} Nat) (List.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (Nat.factors n)) (Finset.filter.{0} Nat Nat.Prime (fun (a : Nat) => Nat.decidablePrime a) (Nat.divisors n))\nCase conversion may be inaccurate. Consider using '#align nat.prime_divisors_eq_to_filter_divisors_prime Nat.prime_divisors_eq_to_filter_divisors_prime\u2093'. -/\n/-- The factors of `n` are the prime divisors -/\ntheorem prime_divisors_eq_to_filter_divisors_prime (n : \u2115) :\n    n.factors.toFinset = (divisors n).filter\u2093 Prime :=\n  by\n  rcases n.eq_zero_or_pos with (rfl | hn)\n  \u00b7 simp\n  \u00b7 ext q\n    simpa [hn, hn.ne', mem_factors] using and_comm' (Prime q) (q \u2223 n)\n#align nat.prime_divisors_eq_to_filter_divisors_prime Nat.prime_divisors_eq_to_filter_divisors_prime\n\n/- warning: nat.image_div_divisors_eq_divisors -> Nat.image_div_divisors_eq_divisors is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat), Eq.{1} (Finset.{0} Nat) (Finset.image.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (fun (x : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) n x) (Nat.divisors n)) (Nat.divisors n)\nbut is expected to have type\n  forall (n : Nat), Eq.{1} (Finset.{0} Nat) (Finset.image.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (fun (x : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) n x) (Nat.divisors n)) (Nat.divisors n)\nCase conversion may be inaccurate. Consider using '#align nat.image_div_divisors_eq_divisors Nat.image_div_divisors_eq_divisors\u2093'. -/\n@[simp]\ntheorem image_div_divisors_eq_divisors (n : \u2115) :\n    image (fun x : \u2115 => n / x) n.divisors = n.divisors :=\n  by\n  by_cases hn : n = 0; \u00b7 simp [hn]\n  ext\n  constructor\n  \u00b7 rw [mem_image]\n    rintro \u27e8x, hx1, hx2\u27e9\n    rw [mem_divisors] at *\n    refine' \u27e8_, hn\u27e9\n    rw [\u2190 hx2]\n    exact div_dvd_of_dvd hx1.1\n  \u00b7 rw [mem_divisors, mem_image]\n    rintro \u27e8h1, -\u27e9\n    exact \u27e8n / a, mem_divisors.mpr \u27e8div_dvd_of_dvd h1, hn\u27e9, Nat.div_div_self h1 hn\u27e9\n#align nat.image_div_divisors_eq_divisors Nat.image_div_divisors_eq_divisors\n\n#print Nat.prod_div_divisors /-\n@[simp, to_additive sum_div_divisors]\ntheorem prod_div_divisors {\u03b1 : Type _} [CommMonoid \u03b1] (n : \u2115) (f : \u2115 \u2192 \u03b1) :\n    (\u220f d in n.divisors, f (n / d)) = n.divisors.Prod f :=\n  by\n  by_cases hn : n = 0; \u00b7 simp [hn]\n  rw [\u2190 prod_image]\n  \u00b7 exact prod_congr (image_div_divisors_eq_divisors n) (by simp)\n  \u00b7 intro x hx y hy h\n    rw [mem_divisors] at hx hy\n    exact (div_eq_iff_eq_of_dvd_dvd hn hx.1 hy.1).mp h\n#align nat.prod_div_divisors Nat.prod_div_divisors\n#align nat.sum_div_divisors Nat.sum_div_divisors\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/Divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7169209507665558}}
{"text": "/-\nThis file defines the boolean XOR constraint on n variables.\n\nAuthors: Cayden Codel, Marijn Heule, Jeremy Avigad\nCarnegie Mellon University\n-/\n\nimport basic\nimport cnf.literal cnf.assignment cnf.clause cnf.cnf cnf.explode\nimport data.list.basic data.finset.basic\n\nuniverse u\n\n-- Represents the type of the variable stored in the literal\nvariables {V : Type u}\n\n/- An n-variable XOR constraint is a map from a list of bools to an output bool -/\ndef Xor (l : list bool) : bool := l.foldr bxor ff\n\nnamespace Xor\n\nopen clause\nopen nat list\n\n/-! # eval -/\nsection eval\n\nvariables (\u03c4 : assignment V) (l l\u2081 l\u2082 : list (literal V)) (lit : literal V)\n\n/- Evaluate the variables under the assignment according to typical XOR -/\nprotected def eval : bool := Xor (l.map (literal.eval \u03c4))\n\n@[simp] theorem eval_nil : Xor.eval \u03c4 [] = ff := rfl\n\n@[simp] theorem eval_singleton : Xor.eval \u03c4 [lit] = lit.eval \u03c4 :=\nby simp only [Xor.eval, Xor, map, bool.bxor_ff_right, foldr]\n\ntheorem eval_cons : Xor.eval \u03c4 (lit :: l) = bxor (lit.eval \u03c4) (Xor.eval \u03c4 l) :=\nby simp only [Xor.eval, Xor, foldr, foldr_map]\n\ntheorem eval_append : \n  Xor.eval \u03c4 (l\u2081 ++ l\u2082) = bxor (Xor.eval \u03c4 l\u2081) (Xor.eval \u03c4 l\u2082) :=\nbegin\n  induction l\u2081 with l ls ih,\n  { simp only [bool.bxor_ff_left, eval_nil, nil_append] },\n  { simp only [eval_cons, ih, cons_append, bool.bxor_assoc] }\nend\n\n/- Evaluates to true if an odd number of literals evaluates to true -/\ntheorem eval_eq_bodd_count_tt : Xor.eval \u03c4 l = bodd (clause.count_tt \u03c4 l) :=\nbegin\n  induction l with l ls ih,\n  { simp only [bodd_zero, eval_nil, count_tt_nil] },\n  { cases h : (l.eval \u03c4); { simp [Xor.eval_cons, count_tt_cons, h, ih] } }\nend\n\ntheorem eval_eq_of_perm {l\u2081 l\u2082 : list (literal V)} : l\u2081 ~ l\u2082 \u2192 \n  \u2200 (\u03c4 : assignment V), Xor.eval \u03c4 l\u2081 = Xor.eval \u03c4 l\u2082 :=\nbegin\n  intros hp \u03c4,\n  induction hp with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082,\n  { refl },\n  { simp [eval_cons, IH] },\n  { simp [eval_cons, \u2190 bool.bxor_assoc],\n    rw bool.bxor_comm (literal.eval \u03c4 y) (literal.eval \u03c4 x) },\n  { exact eq.trans IH\u2081 IH\u2082 }\nend\n\nopen assignment\n\ntheorem eval_eq_of_eqod [decidable_eq V] {\u03c4\u2081 \u03c4\u2082 : assignment V} {l : list (literal V)} :\n  (eqod \u03c4\u2081 \u03c4\u2082 (clause.vars l)) \u2192 Xor.eval \u03c4\u2081 l = Xor.eval \u03c4\u2082 l :=\nbegin\n  induction l with l ls ih,\n  { simp only [eqod_nil, Xor.eval_nil, forall_true_left, clause.vars_nil] },\n  { intro h,\n    simp only [Xor.eval_cons],\n    rw eval_eq_of_eqod_of_var_mem h (mem_vars_of_mem (mem_cons_self l ls)),\n    rw ih (eqod_subset (vars_subset_of_vars_cons l ls) h) }\nend\n\nend eval\n\nend Xor", "meta": {"author": "chasenorman", "repo": "verified-encodings-social-choice", "sha": "72f88c5a31ce30df5a04a99f726244c327b9a6f6", "save_path": "github-repos/lean/chasenorman-verified-encodings-social-choice", "path": "github-repos/lean/chasenorman-verified-encodings-social-choice/verified-encodings-social-choice-72f88c5a31ce30df5a04a99f726244c327b9a6f6/src/xor/xor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8080672112416736, "lm_q1q2_score": 0.7169209394358081}}
{"text": "open classical\n\nnamespace classical.tools\n\nvariables p q : Prop\nvariables (\u03b1 : Type) (r s : \u03b1 \u2192 Prop)\nvariables a : \u03b1\n\nlemma neg_imp_as_conj : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n\u03bb (h : \u00ac(p \u2192 q)),\n  or.cases_on (em q)\n    (\u03bb (hq : q), absurd (\u03bb (hhh : p), hq) h)\n    (\u03bb (hnq : \u00acq),\n       or.cases_on (em p)\n         (\u03bb (hp : p), \u27e8hp, hnq\u27e9)\n         (\u03bb (hnp : \u00acp), absurd (\u03bb (hp : p), absurd hp hnp) h))\n\nlemma conj_as_neg_imp : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q):=\n  \u03bb (h : p \u2227 \u00acq), id (\u03bb (c : p \u2192 q), absurd (c (h.left)) (h.right))\n\nlemma rev_imp : (p \u2192 q) \u2192 \u00ac q \u2192 \u00ac p :=\n  \u03bb (hpq : p \u2192 q) (hnq : \u00acq), id (\u03bb (hp : p), absurd (hpq hp) hnq)\n\nlemma dne (h : \u00ac \u00ac p) : p :=\n  by_contradiction (assume h1: \u00ac p, show false, from h h1)\n\nlemma neg_universal_as_ex : \u00ac (\u2200 x, \u00ac r x) \u2192 \u2203 x, r x :=\n  \u03bb (h : \u00ac\u2200 (x : \u03b1), \u00acr x),\n    by_contradiction\n      (\u03bb (c : \u00ac\u2203 (x : \u03b1), r x),\n        rev_imp (\u00ac\u2203 (x : \u03b1), r x) (\u2200 (x : \u03b1), \u00acr x) forall_not_of_not_exists h c)\n\nlemma dne_under_univ : (\u2200 z, \u00ac \u00ac r z) \u2192 (\u2200 z, r z) :=\n  \u03bb (h : \u2200 (z : \u03b1), \u00ac\u00acr z) (z : \u03b1), dne (r z) (h z)\n\nlemma contra_pos : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n  \u03bb (cp : \u00acq \u2192 \u00acp) (hp : p), dne q (id (\u03bb (hnq : \u00acq), absurd hp (cp hnq)))\n\nlemma demorgan_or : \u00ac (p \u2228 q) \u2192 \u00ac p \u2227 \u00ac q :=\n  assume h : \u00ac (p \u2228 q),\n    \u27e8\u03bb hp : p, h (or.inl hp), \u03bb hq : q, h (or.inr hq)\u27e9\n\nend classical.tools\n", "meta": {"author": "JaredCorduan", "repo": "ramsey", "sha": "6215fc93f72e700a98d0e839e768e20d765d56af", "save_path": "github-repos/lean/JaredCorduan-ramsey", "path": "github-repos/lean/JaredCorduan-ramsey/ramsey-6215fc93f72e700a98d0e839e768e20d765d56af/src/classical/tools.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.716920939076241}}
{"text": "/-\nCopyright (c) 2020 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann\n\n! This file was ported from Lean 3 source module algebra.continued_fractions.computation.approximations\n! leanprover-community/mathlib commit a7e36e48519ab281320c4d192da6a7b348ce40ad\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.ContinuedFractions.Computation.CorrectnessTerminating\nimport Mathbin.Data.Nat.Fib\nimport Mathbin.Tactic.SolveByElim\n\n/-!\n# Approximations for Continued Fraction Computations (`generalized_continued_fraction.of`)\n\n## Summary\n\nThis file contains useful approximations for the values involved in the continued fractions\ncomputation `generalized_continued_fraction.of`. In particular, we derive the so-called\n*determinant formula* for `generalized_continued_fraction.of`:\n`A\u2099 * B\u2099\u208a\u2081 - B\u2099 * A\u2099\u208a\u2081 = (-1)^(n + 1)`.\n\nMoreover, we derive some upper bounds for the error term when computing a continued fraction up a\ngiven position, i.e. bounds for the term\n`|v - (generalized_continued_fraction.of v).convergents n|`. The derived bounds will show us that\nthe error term indeed gets smaller. As a corollary, we will be able to show that\n`(generalized_continued_fraction.of v).convergents` converges to `v` in\n`algebra.continued_fractions.computation.approximation_corollaries`.\n\n## Main Theorems\n\n- `generalized_continued_fraction.of_part_num_eq_one`: shows that all partial numerators `a\u1d62` are\n  equal to one.\n- `generalized_continued_fraction.exists_int_eq_of_part_denom`: shows that all partial denominators\n  `b\u1d62` correspond to an integer.\n- `generalized_continued_fraction.one_le_of_nth_part_denom`: shows that `1 \u2264 b\u1d62`.\n- `generalized_continued_fraction.succ_nth_fib_le_of_nth_denom`: shows that the `n`th denominator\n  `B\u2099` is greater than or equal to the `n + 1`th fibonacci number `nat.fib (n + 1)`.\n- `generalized_continued_fraction.le_of_succ_nth_denom`: shows that `b\u2099 * B\u2099 \u2264 B\u2099\u208a\u2081`, where `b\u2099` is\n  the `n`th partial denominator of the continued fraction.\n- `generalized_continued_fraction.abs_sub_convergents_le`: shows that\n  `|v - A\u2099 / B\u2099| \u2264 1 / (B\u2099 * B\u2099\u208a\u2081)`, where `A\u2099` is the nth partial numerator.\n\n## References\n\n- [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction]\n- https://en.wikipedia.org/wiki/Generalized_continued_fraction#The_determinant_formula\n\n-/\n\n\nnamespace GeneralizedContinuedFraction\n\nopen GeneralizedContinuedFraction (of)\n\nopen Int\n\nvariable {K : Type _} {v : K} {n : \u2115} [LinearOrderedField K] [FloorRing K]\n\nnamespace IntFractPair\n\n/-!\nWe begin with some lemmas about the stream of `int_fract_pair`s, which presumably are not\nof great interest for the end user.\n-/\n\n\n/-- Shows that the fractional parts of the stream are in `[0,1)`. -/\ntheorem nth_stream_fr_nonneg_lt_one {ifp_n : IntFractPair K}\n    (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 \u2264 ifp_n.fr \u2227 ifp_n.fr < 1 :=\n  by\n  cases n\n  case zero =>\n    have : int_fract_pair.of v = ifp_n := by injection nth_stream_eq\n    rw [\u2190 this, int_fract_pair.of]\n    exact \u27e8fract_nonneg _, fract_lt_one _\u27e9\n  case\n    succ =>\n    rcases succ_nth_stream_eq_some_iff.elim_left nth_stream_eq with \u27e8_, _, _, ifp_of_eq_ifp_n\u27e9\n    rw [\u2190 ifp_of_eq_ifp_n, int_fract_pair.of]\n    exact \u27e8fract_nonneg _, fract_lt_one _\u27e9\n#align generalized_continued_fraction.int_fract_pair.nth_stream_fr_nonneg_lt_one GeneralizedContinuedFraction.IntFractPair.nth_stream_fr_nonneg_lt_one\n\n/-- Shows that the fractional parts of the stream are nonnegative. -/\ntheorem nth_stream_fr_nonneg {ifp_n : IntFractPair K}\n    (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 \u2264 ifp_n.fr :=\n  (nth_stream_fr_nonneg_lt_one nth_stream_eq).left\n#align generalized_continued_fraction.int_fract_pair.nth_stream_fr_nonneg GeneralizedContinuedFraction.IntFractPair.nth_stream_fr_nonneg\n\n/-- Shows that the fractional parts of the stream are smaller than one. -/\ntheorem nth_stream_fr_lt_one {ifp_n : IntFractPair K}\n    (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : ifp_n.fr < 1 :=\n  (nth_stream_fr_nonneg_lt_one nth_stream_eq).right\n#align generalized_continued_fraction.int_fract_pair.nth_stream_fr_lt_one GeneralizedContinuedFraction.IntFractPair.nth_stream_fr_lt_one\n\n/-- Shows that the integer parts of the stream are at least one. -/\ntheorem one_le_succ_nth_stream_b {ifp_succ_n : IntFractPair K}\n    (succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : 1 \u2264 ifp_succ_n.b :=\n  by\n  obtain \u27e8ifp_n, nth_stream_eq, stream_nth_fr_ne_zero, \u27e8-\u27e9\u27e9 :\n    \u2203 ifp_n,\n      int_fract_pair.stream v n = some ifp_n \u2227\n        ifp_n.fr \u2260 0 \u2227 int_fract_pair.of ifp_n.fr\u207b\u00b9 = ifp_succ_n\n  exact succ_nth_stream_eq_some_iff.elim_left succ_nth_stream_eq\n  suffices 1 \u2264 ifp_n.fr\u207b\u00b9 by\n    rw_mod_cast [le_floor]\n    assumption\n  suffices ifp_n.fr \u2264 1\n    by\n    have h : 0 < ifp_n.fr :=\n      lt_of_le_of_ne (nth_stream_fr_nonneg nth_stream_eq) stream_nth_fr_ne_zero.symm\n    apply one_le_inv h this\n  simp only [le_of_lt (nth_stream_fr_lt_one nth_stream_eq)]\n#align generalized_continued_fraction.int_fract_pair.one_le_succ_nth_stream_b GeneralizedContinuedFraction.IntFractPair.one_le_succ_nth_stream_b\n\n/--\nShows that the `n + 1`th integer part `b\u2099\u208a\u2081` of the stream is smaller or equal than the inverse of\nthe `n`th fractional part `fr\u2099` of the stream.\nThis result is straight-forward as `b\u2099\u208a\u2081` is defined as the floor of `1 / fr\u2099`\n-/\ntheorem succ_nth_stream_b_le_nth_stream_fr_inv {ifp_n ifp_succ_n : IntFractPair K}\n    (nth_stream_eq : IntFractPair.stream v n = some ifp_n)\n    (succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) :\n    (ifp_succ_n.b : K) \u2264 ifp_n.fr\u207b\u00b9 :=\n  by\n  suffices (\u230aifp_n.fr\u207b\u00b9\u230b : K) \u2264 ifp_n.fr\u207b\u00b9\n    by\n    cases' ifp_n with _ ifp_n_fr\n    have : ifp_n_fr \u2260 0 := by\n      intro h\n      simpa [h, int_fract_pair.stream, nth_stream_eq] using succ_nth_stream_eq\n    have : int_fract_pair.of ifp_n_fr\u207b\u00b9 = ifp_succ_n := by\n      simpa [this, int_fract_pair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq\n    rwa [\u2190 this]\n  exact floor_le ifp_n.fr\u207b\u00b9\n#align generalized_continued_fraction.int_fract_pair.succ_nth_stream_b_le_nth_stream_fr_inv GeneralizedContinuedFraction.IntFractPair.succ_nth_stream_b_le_nth_stream_fr_inv\n\nend IntFractPair\n\n/-!\nNext we translate above results about the stream of `int_fract_pair`s to the computed continued\nfraction `generalized_continued_fraction.of`.\n-/\n\n\n/-- Shows that the integer parts of the continued fraction are at least one. -/\ntheorem of_one_le_nth_part_denom {b : K}\n    (nth_part_denom_eq : (of v).partialDenominators.get? n = some b) : 1 \u2264 b :=\n  by\n  obtain \u27e8gp_n, nth_s_eq, \u27e8-\u27e9\u27e9 : \u2203 gp_n, (of v).s.get? n = some gp_n \u2227 gp_n.b = b;\n  exact exists_s_b_of_part_denom nth_part_denom_eq\n  obtain \u27e8ifp_n, succ_nth_stream_eq, ifp_n_b_eq_gp_n_b\u27e9 :\n    \u2203 ifp, int_fract_pair.stream v (n + 1) = some ifp \u2227 (ifp.b : K) = gp_n.b\n  exact int_fract_pair.exists_succ_nth_stream_of_gcf_of_nth_eq_some nth_s_eq\n  rw [\u2190 ifp_n_b_eq_gp_n_b]\n  exact_mod_cast int_fract_pair.one_le_succ_nth_stream_b succ_nth_stream_eq\n#align generalized_continued_fraction.of_one_le_nth_part_denom GeneralizedContinuedFraction.of_one_le_nth_part_denom\n\n/--\nShows that the partial numerators `a\u1d62` of the continued fraction are equal to one and the partial\ndenominators `b\u1d62` correspond to integers.\n-/\ntheorem of_part_num_eq_one_and_exists_int_part_denom_eq {gp : GeneralizedContinuedFraction.Pair K}\n    (nth_s_eq : (of v).s.get? n = some gp) : gp.a = 1 \u2227 \u2203 z : \u2124, gp.b = (z : K) :=\n  by\n  obtain \u27e8ifp, stream_succ_nth_eq, -\u27e9 : \u2203 ifp, int_fract_pair.stream v (n + 1) = some ifp \u2227 _\n  exact int_fract_pair.exists_succ_nth_stream_of_gcf_of_nth_eq_some nth_s_eq\n  have : gp = \u27e81, ifp.b\u27e9 :=\n    by\n    have : (of v).s.get? n = some \u27e81, ifp.b\u27e9 :=\n      nth_of_eq_some_of_succ_nth_int_fract_pair_stream stream_succ_nth_eq\n    have : some gp = some \u27e81, ifp.b\u27e9 := by rwa [nth_s_eq] at this\n    injection this\n  simp [this]\n#align generalized_continued_fraction.of_part_num_eq_one_and_exists_int_part_denom_eq GeneralizedContinuedFraction.of_part_num_eq_one_and_exists_int_part_denom_eq\n\n/-- Shows that the partial numerators `a\u1d62` are equal to one. -/\ntheorem of_part_num_eq_one {a : K} (nth_part_num_eq : (of v).partialNumerators.get? n = some a) :\n    a = 1 :=\n  by\n  obtain \u27e8gp, nth_s_eq, gp_a_eq_a_n\u27e9 : \u2203 gp, (of v).s.get? n = some gp \u2227 gp.a = a\n  exact exists_s_a_of_part_num nth_part_num_eq\n  have : gp.a = 1 := (of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).left\n  rwa [gp_a_eq_a_n] at this\n#align generalized_continued_fraction.of_part_num_eq_one GeneralizedContinuedFraction.of_part_num_eq_one\n\n/-- Shows that the partial denominators `b\u1d62` correspond to an integer. -/\ntheorem exists_int_eq_of_part_denom {b : K}\n    (nth_part_denom_eq : (of v).partialDenominators.get? n = some b) : \u2203 z : \u2124, b = (z : K) :=\n  by\n  obtain \u27e8gp, nth_s_eq, gp_b_eq_b_n\u27e9 : \u2203 gp, (of v).s.get? n = some gp \u2227 gp.b = b\n  exact exists_s_b_of_part_denom nth_part_denom_eq\n  have : \u2203 z : \u2124, gp.b = (z : K) := (of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).right\n  rwa [gp_b_eq_b_n] at this\n#align generalized_continued_fraction.exists_int_eq_of_part_denom GeneralizedContinuedFraction.exists_int_eq_of_part_denom\n\n/-!\nOne of our next goals is to show that `b\u2099 * B\u2099 \u2264 B\u2099\u208a\u2081`. For this, we first show that the partial\ndenominators `B\u2099` are bounded from below by the fibonacci sequence `nat.fib`. This then implies that\n`0 \u2264 B\u2099` and hence `B\u2099\u208a\u2082 = b\u2099\u208a\u2081 * B\u2099\u208a\u2081 + B\u2099 \u2265 b\u2099\u208a\u2081 * B\u2099\u208a\u2081 + 0 = b\u2099\u208a\u2081 * B\u2099\u208a\u2081`.\n-/\n\n\n-- open `nat` as we will make use of fibonacci numbers.\nopen Nat\n\ntheorem fib_le_of_continuantsAux_b :\n    n \u2264 1 \u2228 \u00ac(of v).TerminatedAt (n - 2) \u2192 (fib n : K) \u2264 ((of v).continuantsAux n).b :=\n  Nat.strong_induction_on n\n    (by\n      clear n\n      intro n IH hyp\n      rcases n with (_ | _ | n)\n      \u00b7 simp [fib_add_two, continuants_aux]\n      -- case n = 0\n      \u00b7 simp [fib_add_two, continuants_aux]\n      -- case n = 1\n      \u00b7 let g := of v\n        -- case 2 \u2264 n\n        have : \u00acn + 2 \u2264 1 := by linarith\n        have not_terminated_at_n : \u00acg.terminated_at n := Or.resolve_left hyp this\n        obtain \u27e8gp, s_ppred_nth_eq\u27e9 : \u2203 gp, g.s.nth n = some gp\n        exact option.ne_none_iff_exists'.mp not_terminated_at_n\n        set pconts := g.continuants_aux (n + 1) with pconts_eq\n        set ppconts := g.continuants_aux n with ppconts_eq\n        -- use the recurrence of continuants_aux\n        suffices (fib n : K) + fib (n + 1) \u2264 gp.a * ppconts.b + gp.b * pconts.b by\n          simpa [fib_add_two, add_comm,\n            continuants_aux_recurrence s_ppred_nth_eq ppconts_eq pconts_eq]\n        -- make use of the fact that gp.a = 1\n        suffices (fib n : K) + fib (n + 1) \u2264 ppconts.b + gp.b * pconts.b by\n          simpa [of_part_num_eq_one <| part_num_eq_s_a s_ppred_nth_eq]\n        have not_terminated_at_pred_n : \u00acg.terminated_at (n - 1) :=\n          mt (terminated_stable <| Nat.sub_le n 1) not_terminated_at_n\n        have not_terminated_at_ppred_n : \u00acterminated_at g (n - 2) :=\n          mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n\n        -- use the IH to get the inequalities for `pconts` and `ppconts`\n        have : (fib (n + 1) : K) \u2264 pconts.b :=\n          IH _ (Nat.lt.base <| n + 1) (Or.inr not_terminated_at_pred_n)\n        have ppred_nth_fib_le_ppconts_B : (fib n : K) \u2264 ppconts.b :=\n          IH n (lt_trans (Nat.lt.base n) <| Nat.lt.base <| n + 1) (Or.inr not_terminated_at_ppred_n)\n        suffices : (fib (n + 1) : K) \u2264 gp.b * pconts.b\n        solve_by_elim [add_le_add ppred_nth_fib_le_ppconts_B]\n        -- finally use the fact that 1 \u2264 gp.b to solve the goal\n        suffices 1 * (fib (n + 1) : K) \u2264 gp.b * pconts.b by rwa [one_mul] at this\n        have one_le_gp_b : (1 : K) \u2264 gp.b :=\n          of_one_le_nth_part_denom (part_denom_eq_s_b s_ppred_nth_eq)\n        have : (0 : K) \u2264 fib (n + 1) := by exact_mod_cast (fib (n + 1)).zero_le\n        have : (0 : K) \u2264 gp.b := le_trans zero_le_one one_le_gp_b\n        mono)\n#align generalized_continued_fraction.fib_le_of_continuants_aux_b GeneralizedContinuedFraction.fib_le_of_continuantsAux_b\n\n/-- Shows that the `n`th denominator is greater than or equal to the `n + 1`th fibonacci number,\nthat is `nat.fib (n + 1) \u2264 B\u2099`. -/\ntheorem succ_nth_fib_le_of_nth_denom (hyp : n = 0 \u2228 \u00ac(of v).TerminatedAt (n - 1)) :\n    (fib (n + 1) : K) \u2264 (of v).denominators n :=\n  by\n  rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux]\n  have : n + 1 \u2264 1 \u2228 \u00ac(of v).TerminatedAt (n - 1) :=\n    by\n    cases n\n    case zero => exact Or.inl <| le_refl 1\n    case succ => exact Or.inr (Or.resolve_left hyp n.succ_ne_zero)\n  exact fib_le_of_continuants_aux_b this\n#align generalized_continued_fraction.succ_nth_fib_le_of_nth_denom GeneralizedContinuedFraction.succ_nth_fib_le_of_nth_denom\n\n/-! As a simple consequence, we can now derive that all denominators are nonnegative. -/\n\n\ntheorem zero_le_of_continuantsAux_b : 0 \u2264 ((of v).continuantsAux n).b :=\n  by\n  let g := of v\n  induction' n with n IH\n  case zero => rfl\n  case succ =>\n    cases' Decidable.em <| g.terminated_at (n - 1) with terminated not_terminated\n    \u00b7 cases n\n      -- terminating case\n      \u00b7 simp [zero_le_one]\n      \u00b7 have : g.continuants_aux (n + 2) = g.continuants_aux (n + 1) :=\n          continuants_aux_stable_step_of_terminated terminated\n        simp only [this, IH]\n    \u00b7\n      calc\n        -- non-terminating case\n            (0 : K) \u2264\n            fib (n + 1) :=\n          by exact_mod_cast (n + 1).fib.zero_le\n        _ \u2264 ((of v).continuantsAux (n + 1)).b := fib_le_of_continuants_aux_b (Or.inr not_terminated)\n        \n#align generalized_continued_fraction.zero_le_of_continuants_aux_b GeneralizedContinuedFraction.zero_le_of_continuantsAux_b\n\n/-- Shows that all denominators are nonnegative. -/\ntheorem zero_le_of_denom : 0 \u2264 (of v).denominators n :=\n  by\n  rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux]\n  exact zero_le_of_continuants_aux_b\n#align generalized_continued_fraction.zero_le_of_denom GeneralizedContinuedFraction.zero_le_of_denom\n\ntheorem le_of_succ_succ_nth_continuantsAux_b {b : K}\n    (nth_part_denom_eq : (of v).partialDenominators.get? n = some b) :\n    b * ((of v).continuantsAux <| n + 1).b \u2264 ((of v).continuantsAux <| n + 2).b :=\n  by\n  obtain \u27e8gp_n, nth_s_eq, rfl\u27e9 : \u2203 gp_n, (of v).s.get? n = some gp_n \u2227 gp_n.b = b\n  exact exists_s_b_of_part_denom nth_part_denom_eq\n  simp [of_part_num_eq_one (part_num_eq_s_a nth_s_eq), zero_le_of_continuants_aux_b,\n    GeneralizedContinuedFraction.continuantsAux_recurrence nth_s_eq rfl rfl]\n#align generalized_continued_fraction.le_of_succ_succ_nth_continuants_aux_b GeneralizedContinuedFraction.le_of_succ_succ_nth_continuantsAux_b\n\n/-- Shows that `b\u2099 * B\u2099 \u2264 B\u2099\u208a\u2081`, where `b\u2099` is the `n`th partial denominator and `B\u2099\u208a\u2081` and `B\u2099` are\nthe `n + 1`th and `n`th denominator of the continued fraction. -/\ntheorem le_of_succ_nth_denom {b : K}\n    (nth_part_denom_eq : (of v).partialDenominators.get? n = some b) :\n    b * (of v).denominators n \u2264 (of v).denominators (n + 1) :=\n  by\n  rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux]\n  exact le_of_succ_succ_nth_continuants_aux_b nth_part_denom_eq\n#align generalized_continued_fraction.le_of_succ_nth_denom GeneralizedContinuedFraction.le_of_succ_nth_denom\n\n/-- Shows that the sequence of denominators is monotone, that is `B\u2099 \u2264 B\u2099\u208a\u2081`. -/\ntheorem of_denom_mono : (of v).denominators n \u2264 (of v).denominators (n + 1) :=\n  by\n  let g := of v\n  cases' Decidable.em <| g.partial_denominators.terminated_at n with terminated not_terminated\n  \u00b7 have : g.partial_denominators.nth n = none := by rwa [Stream'.Seq.TerminatedAt] at terminated\n    have : g.terminated_at n :=\n      terminated_at_iff_part_denom_none.elim_right (by rwa [Stream'.Seq.TerminatedAt] at terminated)\n    have : g.denominators (n + 1) = g.denominators n :=\n      denominators_stable_of_terminated n.le_succ this\n    rw [this]\n  \u00b7 obtain \u27e8b, nth_part_denom_eq\u27e9 : \u2203 b, g.partial_denominators.nth n = some b\n    exact option.ne_none_iff_exists'.mp not_terminated\n    have : 1 \u2264 b := of_one_le_nth_part_denom nth_part_denom_eq\n    calc\n      g.denominators n \u2264 b * g.denominators n := by\n        simpa using mul_le_mul_of_nonneg_right this zero_le_of_denom\n      _ \u2264 g.denominators (n + 1) := le_of_succ_nth_denom nth_part_denom_eq\n      \n#align generalized_continued_fraction.of_denom_mono GeneralizedContinuedFraction.of_denom_mono\n\nsection Determinant\n\n/-!\n### Determinant Formula\n\nNext we prove the so-called *determinant formula* for `generalized_continued_fraction.of`:\n`A\u2099 * B\u2099\u208a\u2081 - B\u2099 * A\u2099\u208a\u2081 = (-1)^(n + 1)`.\n-/\n\n\ntheorem determinant_aux (hyp : n = 0 \u2228 \u00ac(of v).TerminatedAt (n - 1)) :\n    ((of v).continuantsAux n).a * ((of v).continuantsAux (n + 1)).b -\n        ((of v).continuantsAux n).b * ((of v).continuantsAux (n + 1)).a =\n      (-1) ^ n :=\n  by\n  induction' n with n IH\n  case zero => simp [continuants_aux]\n  case\n    succ =>\n    -- set up some shorthand notation\n    let g := of v\n    let conts := continuants_aux g (n + 2)\n    set pred_conts := continuants_aux g (n + 1) with pred_conts_eq\n    set ppred_conts := continuants_aux g n with ppred_conts_eq\n    let pA := pred_conts.a\n    let pB := pred_conts.b\n    let ppA := ppred_conts.a\n    let ppB := ppred_conts.b\n    -- let's change the goal to something more readable\n    change pA * conts.b - pB * conts.a = (-1) ^ (n + 1)\n    have not_terminated_at_n : \u00acterminated_at g n := Or.resolve_left hyp n.succ_ne_zero\n    obtain \u27e8gp, s_nth_eq\u27e9 : \u2203 gp, g.s.nth n = some gp\n    exact option.ne_none_iff_exists'.elim_left not_terminated_at_n\n    -- unfold the recurrence relation for `conts` once and simplify to derive the following\n    suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)\n      by\n      simp only [conts, continuants_aux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq]\n      have gp_a_eq_one : gp.a = 1 := of_part_num_eq_one (part_num_eq_s_a s_nth_eq)\n      rw [gp_a_eq_one, this.symm]\n      ring\n    suffices : pA * ppB - pB * ppA = (-1) ^ (n + 1)\n    calc\n      pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) =\n          pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA :=\n        by ring\n      _ = pA * ppB - pB * ppA := by ring\n      _ = (-1) ^ (n + 1) := by assumption\n      \n    suffices ppA * pB - ppB * pA = (-1) ^ n\n      by\n      have pow_succ_n : (-1 : K) ^ (n + 1) = -1 * (-1) ^ n := pow_succ (-1) n\n      rw [pow_succ_n, \u2190 this]\n      ring\n    exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1) not_terminated_at_n\n#align generalized_continued_fraction.determinant_aux GeneralizedContinuedFraction.determinant_aux\n\n/-- The determinant formula `A\u2099 * B\u2099\u208a\u2081 - B\u2099 * A\u2099\u208a\u2081 = (-1)^(n + 1)` -/\ntheorem determinant (not_terminated_at_n : \u00ac(of v).TerminatedAt n) :\n    (of v).numerators n * (of v).denominators (n + 1) -\n        (of v).denominators n * (of v).numerators (n + 1) =\n      (-1) ^ (n + 1) :=\n  determinant_aux <| Or.inr <| not_terminated_at_n\n#align generalized_continued_fraction.determinant GeneralizedContinuedFraction.determinant\n\nend Determinant\n\nsection ErrorTerm\n\n/-!\n### Approximation of Error Term\n\nNext we derive some approximations for the error term when computing a continued fraction up a given\nposition, i.e. bounds for the term `|v - (generalized_continued_fraction.of v).convergents n|`.\n-/\n\n\n/-- This lemma follows from the finite correctness proof, the determinant equality, and\nby simplifying the difference. -/\ntheorem sub_convergents_eq {ifp : IntFractPair K}\n    (stream_nth_eq : IntFractPair.stream v n = some ifp) :\n    let g := of v\n    let B := (g.continuantsAux (n + 1)).b\n    let pB := (g.continuantsAux n).b\n    v - g.convergents n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr\u207b\u00b9 * B + pB)) :=\n  by\n  -- set up some shorthand notation\n  let g := of v\n  let conts := g.continuants_aux (n + 1)\n  let pred_conts := g.continuants_aux n\n  have g_finite_correctness :\n    v = GeneralizedContinuedFraction.compExactValue pred_conts conts ifp.fr :=\n    comp_exact_value_correctness_of_stream_eq_some stream_nth_eq\n  cases' Decidable.em (ifp.fr = 0) with ifp_fr_eq_zero ifp_fr_ne_zero\n  \u00b7 suffices v - g.convergents n = 0 by simpa [ifp_fr_eq_zero]\n    replace g_finite_correctness : v = g.convergents n\n    \u00b7 simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_eq_zero] using g_finite_correctness\n    exact sub_eq_zero.elim_right g_finite_correctness\n  \u00b7 -- more shorthand notation\n    let A := conts.a\n    let B := conts.b\n    let pA := pred_conts.a\n    let pB := pred_conts.b\n    -- first, let's simplify the goal as `ifp.fr \u2260 0`\n    suffices v - A / B = (-1) ^ n / (B * (ifp.fr\u207b\u00b9 * B + pB)) by simpa [ifp_fr_ne_zero]\n    -- now we can unfold `g.comp_exact_value` to derive the following equality for `v`\n    replace g_finite_correctness : v = (pA + ifp.fr\u207b\u00b9 * A) / (pB + ifp.fr\u207b\u00b9 * B)\n    \u00b7\n      simpa [GeneralizedContinuedFraction.compExactValue, ifp_fr_ne_zero, next_continuants,\n        next_numerator, next_denominator, add_comm] using g_finite_correctness\n    -- let's rewrite this equality for `v` in our goal\n    suffices\n      (pA + ifp.fr\u207b\u00b9 * A) / (pB + ifp.fr\u207b\u00b9 * B) - A / B = (-1) ^ n / (B * (ifp.fr\u207b\u00b9 * B + pB)) by\n      rwa [g_finite_correctness]\n    -- To continue, we need use the determinant equality. So let's derive the needed hypothesis.\n    have n_eq_zero_or_not_terminated_at_pred_n : n = 0 \u2228 \u00acg.terminated_at (n - 1) :=\n      by\n      cases' n with n'\n      \u00b7 simp\n      \u00b7 have : int_fract_pair.stream v (n' + 1) \u2260 none := by simp [stream_nth_eq]\n        have : \u00acg.terminated_at n' :=\n          (not_congr of_terminated_at_n_iff_succ_nth_int_fract_pair_stream_eq_none).right this\n        exact Or.inr this\n    have determinant_eq : pA * B - pB * A = (-1) ^ n :=\n      determinant_aux n_eq_zero_or_not_terminated_at_pred_n\n    -- now all we got to do is to rewrite this equality in our goal and re-arrange terms;\n    -- however, for this, we first have to derive quite a few tedious inequalities.\n    have pB_ineq : (fib n : K) \u2264 pB :=\n      haveI : n \u2264 1 \u2228 \u00acg.terminated_at (n - 2) :=\n        by\n        cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n\n        \u00b7 simp [n_eq_zero]\n        \u00b7 exact Or.inr <| mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n\n      fib_le_of_continuants_aux_b this\n    have B_ineq : (fib (n + 1) : K) \u2264 B :=\n      haveI : n + 1 \u2264 1 \u2228 \u00acg.terminated_at (n + 1 - 2) :=\n        by\n        cases' n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n\n        \u00b7 simp [n_eq_zero, le_refl]\n        \u00b7 exact Or.inr not_terminated_at_pred_n\n      fib_le_of_continuants_aux_b this\n    have zero_lt_B : 0 < B :=\n      haveI : 1 \u2264 B :=\n        le_trans (by exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm))\n          B_ineq\n      lt_of_lt_of_le zero_lt_one this\n    have zero_ne_B : 0 \u2260 B := ne_of_lt zero_lt_B\n    have : 0 \u2260 pB + ifp.fr\u207b\u00b9 * B :=\n      by\n      have : (0 : K) \u2264 fib n := by exact_mod_cast (fib n).zero_le\n      -- 0 \u2264 fib n \u2264 pB\n      have zero_le_pB : 0 \u2264 pB := le_trans this pB_ineq\n      have : 0 < ifp.fr\u207b\u00b9 := by\n        suffices 0 < ifp.fr by rwa [inv_pos]\n        have : 0 \u2264 ifp.fr := int_fract_pair.nth_stream_fr_nonneg stream_nth_eq\n        change ifp.fr \u2260 0 at ifp_fr_ne_zero\n        exact lt_of_le_of_ne this ifp_fr_ne_zero.symm\n      have : 0 < ifp.fr\u207b\u00b9 * B := mul_pos this zero_lt_B\n      have : 0 < pB + ifp.fr\u207b\u00b9 * B := add_pos_of_nonneg_of_pos zero_le_pB this\n      exact ne_of_lt this\n    -- finally, let's do the rewriting\n    calc\n      (pA + ifp.fr\u207b\u00b9 * A) / (pB + ifp.fr\u207b\u00b9 * B) - A / B =\n          ((pA + ifp.fr\u207b\u00b9 * A) * B - (pB + ifp.fr\u207b\u00b9 * B) * A) / ((pB + ifp.fr\u207b\u00b9 * B) * B) :=\n        by rw [div_sub_div _ _ this.symm zero_ne_B.symm]\n      _ = (pA * B + ifp.fr\u207b\u00b9 * A * B - (pB * A + ifp.fr\u207b\u00b9 * B * A)) / _ := by repeat' rw [add_mul]\n      _ = (pA * B - pB * A) / ((pB + ifp.fr\u207b\u00b9 * B) * B) := by ring\n      _ = (-1) ^ n / ((pB + ifp.fr\u207b\u00b9 * B) * B) := by rw [determinant_eq]\n      _ = (-1) ^ n / (B * (ifp.fr\u207b\u00b9 * B + pB)) := by ac_rfl\n      \n#align generalized_continued_fraction.sub_convergents_eq GeneralizedContinuedFraction.sub_convergents_eq\n\n/-- Shows that `|v - A\u2099 / B\u2099| \u2264 1 / (B\u2099 * B\u2099\u208a\u2081)` -/\ntheorem abs_sub_convergents_le (not_terminated_at_n : \u00ac(of v).TerminatedAt n) :\n    |v - (of v).convergents n| \u2264 1 / ((of v).denominators n * ((of v).denominators <| n + 1)) :=\n  by\n  -- shorthand notation\n  let g := of v\n  let nextConts := g.continuants_aux (n + 2)\n  set conts := continuants_aux g (n + 1) with conts_eq\n  set pred_conts := continuants_aux g n with pred_conts_eq\n  -- change the goal to something more readable\n  change |v - convergents g n| \u2264 1 / (conts.b * nextConts.b)\n  obtain \u27e8gp, s_nth_eq\u27e9 : \u2203 gp, g.s.nth n = some gp\n  exact option.ne_none_iff_exists'.elim_left not_terminated_at_n\n  have gp_a_eq_one : gp.a = 1 := of_part_num_eq_one (part_num_eq_s_a s_nth_eq)\n  -- unfold the recurrence relation for `nextConts.b`\n  have nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b := by\n    simp [nextConts, continuants_aux_recurrence s_nth_eq pred_conts_eq conts_eq, gp_a_eq_one,\n      pred_conts_eq.symm, conts_eq.symm, add_comm]\n  let denom := conts.b * (pred_conts.b + gp.b * conts.b)\n  suffices |v - g.convergents n| \u2264 1 / denom\n    by\n    rw [nextConts_b_eq]\n    congr 1\n  obtain \u27e8ifp_succ_n, succ_nth_stream_eq, ifp_succ_n_b_eq_gp_b\u27e9 :\n    \u2203 ifp_succ_n, int_fract_pair.stream v (n + 1) = some ifp_succ_n \u2227 (ifp_succ_n.b : K) = gp.b\n  exact int_fract_pair.exists_succ_nth_stream_of_gcf_of_nth_eq_some s_nth_eq\n  obtain \u27e8ifp_n, stream_nth_eq, stream_nth_fr_ne_zero, if_of_eq_ifp_succ_n\u27e9 :\n    \u2203 ifp_n,\n      int_fract_pair.stream v n = some ifp_n \u2227\n        ifp_n.fr \u2260 0 \u2227 int_fract_pair.of ifp_n.fr\u207b\u00b9 = ifp_succ_n\n  exact int_fract_pair.succ_nth_stream_eq_some_iff.elim_left succ_nth_stream_eq\n  let denom' := conts.b * (pred_conts.b + ifp_n.fr\u207b\u00b9 * conts.b)\n  -- now we can use `sub_convergents_eq` to simplify our goal\n  suffices |(-1) ^ n / denom'| \u2264 1 / denom\n    by\n    have : v - g.convergents n = (-1) ^ n / denom' :=\n      by\n      -- apply `sub_convergens_eq` and simplify the result\n      have tmp := sub_convergents_eq stream_nth_eq\n      delta at tmp\n      simp only [stream_nth_fr_ne_zero, conts_eq.symm, pred_conts_eq.symm] at tmp\n      rw [tmp]\n      simp only [denom']\n      ring_nf\n    rwa [this]\n  -- derive some tedious inequalities that we need to rewrite our goal\n  have nextConts_b_ineq : (fib (n + 2) : K) \u2264 pred_conts.b + gp.b * conts.b :=\n    by\n    have : (fib (n + 2) : K) \u2264 nextConts.b :=\n      fib_le_of_continuants_aux_b (Or.inr not_terminated_at_n)\n    rwa [nextConts_b_eq] at this\n  have conts_b_ineq : (fib (n + 1) : K) \u2264 conts.b :=\n    haveI : \u00acg.terminated_at (n - 1) := mt (terminated_stable n.pred_le) not_terminated_at_n\n    fib_le_of_continuants_aux_b <| Or.inr this\n  have zero_lt_conts_b : 0 < conts.b :=\n    haveI : (0 : K) < fib (n + 1) := by\n      exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm)\n    lt_of_lt_of_le this conts_b_ineq\n  -- `denom'` is positive, so we can remove `|\u2b1d|` from our goal\n  suffices 1 / denom' \u2264 1 / denom\n    by\n    have : |(-1) ^ n / denom'| = 1 / denom' :=\n      by\n      suffices 1 / |denom'| = 1 / denom' by rwa [abs_div, abs_neg_one_pow n]\n      have : 0 < denom' :=\n        by\n        have : 0 \u2264 pred_conts.b :=\n          haveI : (fib n : K) \u2264 pred_conts.b :=\n            haveI : \u00acg.terminated_at (n - 2) :=\n              mt (terminated_stable (n.sub_le 2)) not_terminated_at_n\n            fib_le_of_continuants_aux_b <| Or.inr this\n          le_trans (by exact_mod_cast (fib n).zero_le) this\n        have : 0 < ifp_n.fr\u207b\u00b9 :=\n          haveI zero_le_ifp_n_fract : 0 \u2264 ifp_n.fr :=\n            int_fract_pair.nth_stream_fr_nonneg stream_nth_eq\n          inv_pos.elim_right (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm)\n        any_goals repeat' first |apply mul_pos|apply add_pos_of_nonneg_of_pos <;> assumption\n      rwa [abs_of_pos this]\n    rwa [this]\n  suffices : 0 < denom \u2227 denom \u2264 denom'\n  exact div_le_div_of_le_left zero_le_one this.left this.right\n  constructor\n  \u00b7 have : 0 < pred_conts.b + gp.b * conts.b :=\n      lt_of_lt_of_le\n        (by exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.succ.zero_le n.succ.succ_ne_zero.symm))\n        nextConts_b_ineq\n    solve_by_elim [mul_pos]\n  \u00b7 -- we can cancel multiplication by `conts.b` and addition with `pred_conts.b`\n    suffices : gp.b * conts.b \u2264 ifp_n.fr\u207b\u00b9 * conts.b\n    exact (mul_le_mul_left zero_lt_conts_b).right <| (add_le_add_iff_left pred_conts.b).right this\n    suffices (ifp_succ_n.b : K) * conts.b \u2264 ifp_n.fr\u207b\u00b9 * conts.b by rwa [\u2190 ifp_succ_n_b_eq_gp_b]\n    have : (ifp_succ_n.b : K) \u2264 ifp_n.fr\u207b\u00b9 :=\n      int_fract_pair.succ_nth_stream_b_le_nth_stream_fr_inv stream_nth_eq succ_nth_stream_eq\n    have : 0 \u2264 conts.b := le_of_lt zero_lt_conts_b\n    mono\n#align generalized_continued_fraction.abs_sub_convergents_le GeneralizedContinuedFraction.abs_sub_convergents_le\n\n/-- Shows that `|v - A\u2099 / B\u2099| \u2264 1 / (b\u2099 * B\u2099 * B\u2099)`. This bound is worse than the one shown in\n`gcf.abs_sub_convergents_le`, but sometimes it is easier to apply and sufficient for one's use case.\n -/\ntheorem abs_sub_convergents_le' {b : K}\n    (nth_part_denom_eq : (of v).partialDenominators.get? n = some b) :\n    |v - (of v).convergents n| \u2264 1 / (b * (of v).denominators n * (of v).denominators n) :=\n  by\n  have not_terminated_at_n : \u00ac(of v).TerminatedAt n := by\n    simp [terminated_at_iff_part_denom_none, nth_part_denom_eq]\n  refine' (abs_sub_convergents_le not_terminated_at_n).trans _\n  -- One can show that `0 < (generalized_continued_fraction.of v).denominators n` but it's easier\n  -- to consider the case `(generalized_continued_fraction.of v).denominators n = 0`.\n  rcases zero_le_of_denom.eq_or_gt with\n    ((hB : (GeneralizedContinuedFraction.of v).denominators n = 0) | hB)\n  \u00b7 simp only [hB, MulZeroClass.mul_zero, MulZeroClass.zero_mul, div_zero]\n  \u00b7 apply one_div_le_one_div_of_le\n    \u00b7 have : 0 < b := zero_lt_one.trans_le (of_one_le_nth_part_denom nth_part_denom_eq)\n      apply_rules [mul_pos]\n    \u00b7 conv_rhs => rw [mul_comm]\n      exact mul_le_mul_of_nonneg_right (le_of_succ_nth_denom nth_part_denom_eq) hB.le\n#align generalized_continued_fraction.abs_sub_convergents_le' GeneralizedContinuedFraction.abs_sub_convergents_le'\n\nend ErrorTerm\n\nend GeneralizedContinuedFraction\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/ContinuedFractions/Computation/Approximations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7169209260546509}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Patrick Massot, Casper Putz, Anne Baanen\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.diagonal\n! leanprover-community/mathlib commit 2bbc7e3884ba234309d2a43b19144105a753292e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.Matrix.ToLin\n\n/-!\n# Diagonal matrices\n\nThis file contains some results on the linear map corresponding to a\ndiagonal matrix (`range`, `ker` and `rank`).\n\n## Tags\n\nmatrix, diagonal, linear_map\n-/\n\n\nnoncomputable section\n\nopen LinearMap Matrix Set Submodule\n\nopen BigOperators\n\nopen Matrix\n\nuniverse u v w\n\nnamespace Matrix\n\nsection CommRing\n\nvariable {n : Type _} [Fintype n] [DecidableEq n] {R : Type v} [CommRing R]\n\ntheorem proj_diagonal (i : n) (w : n \u2192 R) : (proj i).comp (toLin' (diagonal w)) = w i \u2022 proj i :=\n  LinearMap.ext fun j => mulVec_diagonal _ _ _\n#align matrix.proj_diagonal Matrix.proj_diagonal\n\ntheorem diagonal_comp_stdBasis (w : n \u2192 R) (i : n) :\n    (diagonal w).toLin'.comp (LinearMap.stdBasis R (fun _ : n => R) i) =\n      w i \u2022 LinearMap.stdBasis R (fun _ : n => R) i :=\n  LinearMap.ext fun x => (diagonal_mulVec_single w _ _).trans (Pi.single_smul' i (w i) x)\n#align matrix.diagonal_comp_std_basis Matrix.diagonal_comp_stdBasis\n\ntheorem diagonal_toLin' (w : n \u2192 R) :\n    (diagonal w).toLin' = LinearMap.pi fun i => w i \u2022 LinearMap.proj i :=\n  LinearMap.ext fun v => funext fun i => mulVec_diagonal _ _ _\n#align matrix.diagonal_to_lin' Matrix.diagonal_toLin'\n\nend CommRing\n\nsection Field\n\nvariable {m n : Type _} [Fintype m] [Fintype n]\n\nvariable {K : Type u} [Field K]\n\n-- maybe try to relax the universe constraint\ntheorem ker_diagonal_toLin' [DecidableEq m] (w : m \u2192 K) :\n    ker (diagonal w).toLin' = \u2a06 i \u2208 { i | w i = 0 }, range (LinearMap.stdBasis K (fun i => K) i) :=\n  by\n  rw [\u2190 comap_bot, \u2190 infi_ker_proj, comap_infi]\n  have := fun i : m => ker_comp (to_lin' (diagonal w)) (proj i)\n  simp only [comap_infi, \u2190 this, proj_diagonal, ker_smul']\n  have : univ \u2286 { i : m | w i = 0 } \u222a { i : m | w i = 0 }\u1d9c := by rw [Set.union_compl_self]\n  exact\n    (supr_range_std_basis_eq_infi_ker_proj K (fun i : m => K) disjoint_compl_right this\n        (Set.toFinite _)).symm\n#align matrix.ker_diagonal_to_lin' Matrix.ker_diagonal_toLin'\n\ntheorem range_diagonal [DecidableEq m] (w : m \u2192 K) :\n    (diagonal w).toLin'.range =\n      \u2a06 i \u2208 { i | w i \u2260 0 }, (LinearMap.stdBasis K (fun i => K) i).range :=\n  by\n  dsimp only [mem_set_of_eq]\n  rw [\u2190 Submodule.map_top, \u2190 supr_range_std_basis, Submodule.map_sup\u1d62]\n  congr ; funext i\n  rw [\u2190 LinearMap.range_comp, diagonal_comp_std_basis, \u2190 range_smul']\n#align matrix.range_diagonal Matrix.range_diagonal\n\ntheorem rank_diagonal [DecidableEq m] [DecidableEq K] (w : m \u2192 K) :\n    rank (diagonal w).toLin' = Fintype.card { i // w i \u2260 0 } :=\n  by\n  have hu : univ \u2286 { i : m | w i = 0 }\u1d9c \u222a { i : m | w i = 0 } := by rw [Set.compl_union_self]\n  have hd : Disjoint { i : m | w i \u2260 0 } { i : m | w i = 0 } := disjoint_compl_left\n  have B\u2081 := supr_range_std_basis_eq_infi_ker_proj K (fun i : m => K) hd hu (Set.toFinite _)\n  have B\u2082 := @infi_ker_proj_equiv K _ _ (fun i : m => K) _ _ _ _ (by simp <;> infer_instance) hd hu\n  rw [rank, range_diagonal, B\u2081, \u2190 @dim_fun' K]\n  apply LinearEquiv.dim_eq\n  apply B\u2082\n#align matrix.rank_diagonal Matrix.rank_diagonal\n\nend Field\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/Diagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7169209260546509}}
{"text": "import tactic.interactive tactic.find data.list.basic\n\ndef my_list_bexists {\u03b1 : Type} (p : \u03b1 \u2192 bool) : \u2200 l : list \u03b1, bool \n| list.nil := ff\n| (list.cons a l) := bor (p a)  (my_list_bexists l)\n\ndef my_list_pexists {\u03b1 : Type} (p : \u03b1 \u2192 Prop) : \u2200 l : list \u03b1, Prop\n| list.nil := false\n| (list.cons a l) := (p a) \u2228 (my_list_pexists l)\n\ndef my_list_pexists' {\u03b1 : Type} (p : \u03b1 \u2192 Prop) (l : list \u03b1) : Prop := \n \u2203 (i : \u2115) (i_is_lt : i < l.length), p (l.nth_le i i_is_lt)\n\nlemma my_list_pexists_nil {\u03b1 : Type} (p : \u03b1 \u2192 Prop) : \n \u00ac my_list_pexists' p list.nil := by {rintro \u27e8i,\u27e8\u27e8_\u27e9,_\u27e9\u27e9}\n\nlemma my_list_pexists_succ {\u03b1 : Type} (p : \u03b1 \u2192 Prop) (a : \u03b1) (l : list \u03b1) :\n my_list_pexists' p (a :: l) \u2194 (p a \u2228 (my_list_pexists' p l)) := begin\n unfold my_list_pexists',\n split,\n {rintro \u27e8_|i,\u27e8i_is_lt,pi\u27e9\u27e9,\n  {left,exact pi},\n  {let i_is_lt' := nat.lt_of_succ_lt_succ i_is_lt,\n  right,use i,use i_is_lt',\n  exact pi,}\n },{\n  rintro (pa | \u27e8i,\u27e8i_is_lt,pi\u27e9\u27e9),\n  {use 0,use nat.zero_lt_succ l.length,exact pa},\n  {use i.succ,use nat.succ_lt_succ i_is_lt,exact pi}\n }\nend\n\nlemma my_list_pexists_iff {\u03b1 : Type} (p : \u03b1 \u2192 Prop) : \u2200 (l : list \u03b1),\n my_list_pexists p l \u2194 my_list_pexists' p l\n| list.nil := ((iff_false _).mpr (my_list_pexists_nil p)).symm\n| (a :: l) := by {rw[my_list_pexists_succ,\u2190 my_list_pexists_iff l],refl,}\n\ninstance my_list_pexists_decidable \n {\u03b1 : Type} (p : \u03b1 \u2192 Prop) [decidable_pred p] : \u2200 (l : list \u03b1), \n  decidable (my_list_pexists p l)\n| list.nil := by { dsimp[my_list_pexists],apply_instance, }\n| (a :: l) := by { \n    dsimp[my_list_pexists],\n    haveI := my_list_pexists_decidable l, \n    apply_instance, }\n\ninstance my_list_pexists'_decidable \n {\u03b1 : Type} (p : \u03b1 \u2192 Prop) [decidable_pred p] (l : list \u03b1) :\n  decidable (my_list_pexists' p l) := \n   decidable_of_iff _ (my_list_pexists_iff p l)\n\n\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/exercises/mathcomp_book/chapter_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7168780115452531}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.calculus.mean_value\nimport analysis.special_functions.exp_log\n\n/-!\n# Gr\u00f6nwall's inequality\n\nThe main technical result of this file is the Gr\u00f6nwall-like inequality\n`norm_le_gronwall_bound_of_norm_deriv_right_le`. It states that if `f : \u211d \u2192 E` satisfies `\u2225f a\u2225 \u2264 \u03b4`\nand `\u2200 x \u2208 [a, b), \u2225f' x\u2225 \u2264 K * \u2225f x\u2225 + \u03b5`, then for all `x \u2208 [a, b]` we have `\u2225f x\u2225 \u2264 \u03b4 * exp (K *\nx) + (\u03b5 / K) * (exp (K * x) - 1)`.\n\nThen we use this inequality to prove some estimates on the possible rate of growth of the distance\nbetween two approximate or exact solutions of an ordinary differential equation.\n\nThe proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*,\nSec. 4.5][HubbardWest-ode], where `norm_le_gronwall_bound_of_norm_deriv_right_le` is called\n\u201cFundamental Inequality\u201d.\n\n## TODO\n\n- Once we have FTC, prove an inequality for a function satisfying `\u2225f' x\u2225 \u2264 K x * \u2225f x\u2225 + \u03b5`,\n  or more generally `liminf_{y\u2192x+0} (f y - f x)/(y - x) \u2264 K x * f x + \u03b5` with any sign\n  of `K x` and `f x`.\n-/\n\nvariables {E : Type*} [normed_group E] [normed_space \u211d E]\n          {F : Type*} [normed_group F] [normed_space \u211d F]\n\nopen metric set asymptotics filter real\nopen_locale classical topological_space nnreal\n\n/-! ### Technical lemmas about `gronwall_bound` -/\n\n/-- Upper bound used in several Gr\u00f6nwall-like inequalities. -/\nnoncomputable def gronwall_bound (\u03b4 K \u03b5 x : \u211d) : \u211d :=\nif K = 0 then \u03b4 + \u03b5 * x else \u03b4 * exp (K * x) + (\u03b5 / K) * (exp (K * x) - 1)\n\nlemma gronwall_bound_K0 (\u03b4 \u03b5 : \u211d) : gronwall_bound \u03b4 0 \u03b5 = \u03bb x, \u03b4 + \u03b5 * x :=\nfunext $ \u03bb x, if_pos rfl\n\nlemma gronwall_bound_of_K_ne_0 {\u03b4 K \u03b5 : \u211d} (hK : K \u2260 0) :\n  gronwall_bound \u03b4 K \u03b5 = \u03bb x, \u03b4 * exp (K * x) + (\u03b5 / K) * (exp (K * x) - 1) :=\nfunext $ \u03bb x, if_neg hK\n\nlemma has_deriv_at_gronwall_bound (\u03b4 K \u03b5 x : \u211d) :\n  has_deriv_at (gronwall_bound \u03b4 K \u03b5) (K * (gronwall_bound \u03b4 K \u03b5 x) + \u03b5) x :=\nbegin\n  by_cases hK : K = 0,\n  { subst K,\n    simp only [gronwall_bound_K0, zero_mul, zero_add],\n    convert ((has_deriv_at_id x).const_mul \u03b5).const_add \u03b4,\n    rw [mul_one] },\n  { simp only [gronwall_bound_of_K_ne_0 hK],\n    convert (((has_deriv_at_id x).const_mul K).exp.const_mul \u03b4).add\n      ((((has_deriv_at_id x).const_mul K).exp.sub_const 1).const_mul (\u03b5 / K)) using 1,\n    simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel' _ hK],\n    ring }\nend\n\nlemma has_deriv_at_gronwall_bound_shift (\u03b4 K \u03b5 x a : \u211d) :\n  has_deriv_at (\u03bb y, gronwall_bound \u03b4 K \u03b5 (y - a)) (K * (gronwall_bound \u03b4 K \u03b5 (x - a)) + \u03b5) x :=\nbegin\n  convert (has_deriv_at_gronwall_bound \u03b4 K \u03b5 _).comp x ((has_deriv_at_id x).sub_const a),\n  rw [id, mul_one]\nend\n\nlemma gronwall_bound_x0 (\u03b4 K \u03b5 : \u211d) : gronwall_bound \u03b4 K \u03b5 0 = \u03b4 :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound, if_pos hK, mul_zero, add_zero] },\n  { simp only [gronwall_bound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] }\nend\n\nlemma gronwall_bound_\u03b50 (\u03b4 K x : \u211d) : gronwall_bound \u03b4 K 0 x = \u03b4 * exp (K * x) :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] },\n  { simp only [gronwall_bound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] }\nend\n\nlemma gronwall_bound_\u03b50_\u03b40 (K x : \u211d) : gronwall_bound 0 K 0 x = 0 :=\nby simp only [gronwall_bound_\u03b50, zero_mul]\n\nlemma gronwall_bound_continuous_\u03b5 (\u03b4 K x : \u211d) : continuous (\u03bb \u03b5, gronwall_bound \u03b4 K \u03b5 x) :=\nbegin\n  by_cases hK : K = 0,\n  { simp only [gronwall_bound_K0, hK],\n    exact continuous_const.add (continuous_id.mul continuous_const) },\n  { simp only [gronwall_bound_of_K_ne_0 hK],\n    exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) }\nend\n\n/-! ### Inequality and corollaries -/\n\n/-- A Gr\u00f6nwall-like inequality: if `f : \u211d \u2192 \u211d` is continuous on `[a, b]` and satisfies\nthe inequalities `f a \u2264 \u03b4` and\n`\u2200 x \u2208 [a, b), liminf_{z\u2192x+0} (f z - f x)/(z - x) \u2264 K * (f x) + \u03b5`, then `f x`\nis bounded by `gronwall_bound \u03b4 K \u03b5 (x - a)` on `[a, b]`.\n\nSee also `norm_le_gronwall_bound_of_norm_deriv_right_le` for a version bounding `\u2225f x\u2225`,\n`f : \u211d \u2192 E`. -/\ntheorem le_gronwall_bound_of_liminf_deriv_right_le {f f' : \u211d \u2192 \u211d} {\u03b4 K \u03b5 : \u211d} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 x \u2208 Ico a b, \u2200 r, f' x < r \u2192\n    \u2203\u1da0 z in \ud835\udcdd[Ioi x] x, (z - x)\u207b\u00b9 * (f z - f x) < r)\n  (ha : f a \u2264 \u03b4) (bound : \u2200 x \u2208 Ico a b, f' x \u2264 K * f x + \u03b5) :\n  \u2200 x \u2208 Icc a b, f x \u2264 gronwall_bound \u03b4 K \u03b5 (x - a) :=\nbegin\n  have H : \u2200 x \u2208 Icc a b, \u2200 \u03b5' \u2208 Ioi \u03b5, f x \u2264 gronwall_bound \u03b4 K \u03b5' (x - a),\n  { assume x hx \u03b5' h\u03b5',\n    apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf',\n    { rwa [sub_self, gronwall_bound_x0] },\n    { exact \u03bb x, has_deriv_at_gronwall_bound_shift \u03b4 K \u03b5' x a },\n    { assume x hx hfB,\n      rw [\u2190 hfB],\n      apply lt_of_le_of_lt (bound x hx),\n      exact add_lt_add_left h\u03b5' _ },\n    { exact hx } },\n  assume x hx,\n  change f x \u2264 (\u03bb \u03b5', gronwall_bound \u03b4 K \u03b5' (x - a)) \u03b5,\n  convert continuous_within_at_const.closure_le _ _ (H x hx),\n  { simp only [closure_Ioi, left_mem_Ici] },\n  exact (gronwall_bound_continuous_\u03b5 \u03b4 K (x - a)).continuous_within_at\nend\n\n/-- A Gr\u00f6nwall-like inequality: if `f : \u211d \u2192 E` is continuous on `[a, b]`, has right derivative\n`f' x` at every point `x \u2208 [a, b)`, and satisfies the inequalities `\u2225f a\u2225 \u2264 \u03b4`,\n`\u2200 x \u2208 [a, b), \u2225f' x\u2225 \u2264 K * \u2225f x\u2225 + \u03b5`, then `\u2225f x\u2225` is bounded by `gronwall_bound \u03b4 K \u03b5 (x - a)`\non `[a, b]`. -/\ntheorem norm_le_gronwall_bound_of_norm_deriv_right_le {f f' : \u211d \u2192 E} {\u03b4 K \u03b5 : \u211d} {a b : \u211d}\n  (hf : continuous_on f (Icc a b)) (hf' : \u2200 x \u2208 Ico a b, has_deriv_within_at f (f' x) (Ici x) x)\n  (ha : \u2225f a\u2225 \u2264 \u03b4) (bound : \u2200 x \u2208 Ico a b, \u2225f' x\u2225 \u2264 K * \u2225f x\u2225 + \u03b5) :\n  \u2200 x \u2208 Icc a b, \u2225f x\u2225 \u2264 gronwall_bound \u03b4 K \u03b5 (x - a) :=\nle_gronwall_bound_of_liminf_deriv_right_le (continuous_norm.comp_continuous_on hf)\n  (\u03bb x hx r hr, (hf' x hx).liminf_right_slope_norm_le hr) ha bound\n\n/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in some time-dependent set `s t`,\nand assumes that the solutions never leave this set. -/\ntheorem dist_le_of_approx_trajectories_ODE_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g f' g' : \u211d \u2192 E} {a b : \u211d} {\u03b5f \u03b5g \u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (f' t) (Ici t) t)\n  (f_bound : \u2200 t \u2208 Ico a b, dist (f' t) (v t (f t)) \u2264 \u03b5f)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (g' t) (Ici t) t)\n  (g_bound : \u2200 t \u2208 Ico a b, dist (g' t) (v t (g t)) \u2264 \u03b5g)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 gronwall_bound \u03b4 K (\u03b5f + \u03b5g) (t - a) :=\nbegin\n  simp only [dist_eq_norm] at ha \u22a2,\n  have h_deriv : \u2200 t \u2208 Ico a b, has_deriv_within_at (\u03bb t, f t - g t) (f' t - g' t) (Ici t) t,\n    from \u03bb t ht, (hf' t ht).sub (hg' t ht),\n  apply norm_le_gronwall_bound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha,\n  assume t ht,\n  have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)),\n  rw [dist_eq_norm] at this,\n  apply le_trans this,\n  apply le_trans (add_le_add (add_le_add (f_bound t ht) (g_bound t ht))\n    (hv t (f t) (g t) (hfs t ht) (hgs t ht))),\n  rw [dist_eq_norm, add_comm]\nend\n\n/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in the whole space. -/\ntheorem dist_le_of_approx_trajectories_ODE {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g f' g' : \u211d \u2192 E} {a b : \u211d} {\u03b5f \u03b5g \u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (f' t) (Ici t) t)\n  (f_bound : \u2200 t \u2208 Ico a b, dist (f' t) (v t (f t)) \u2264 \u03b5f)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (g' t) (Ici t) t)\n  (g_bound : \u2200 t \u2208 Ico a b, dist (g' t) (v t (g t)) \u2264 \u03b5g)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 gronwall_bound \u03b4 K (\u03b5f + \u03b5g) (t - a) :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\ndist_le_of_approx_trajectories_ODE_of_mem_set (\u03bb t x y hx hy, (hv t).dist_le_mul x y)\n  hf hf' f_bound hfs hg hg' g_bound (\u03bb t ht, trivial) ha\n\n/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in some time-dependent set `s t`,\nand assumes that the solutions never leave this set. -/\ntheorem dist_le_of_trajectories_ODE_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g : \u211d \u2192 E} {a b : \u211d} {\u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 \u03b4 * exp (K * (t - a)) :=\nbegin\n  have f_bound : \u2200 t \u2208 Ico a b, dist (v t (f t)) (v t (f t)) \u2264 0,\n    by { intros, rw [dist_self] },\n  have g_bound : \u2200 t \u2208 Ico a b, dist (v t (g t)) (v t (g t)) \u2264 0,\n    by { intros, rw [dist_self] },\n  assume t ht,\n  have := dist_le_of_approx_trajectories_ODE_of_mem_set hv hf hf' f_bound hfs hg hg' g_bound\n    hgs ha t ht,\n  rwa [zero_add, gronwall_bound_\u03b50] at this,\nend\n\n/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them\ncan't grow faster than exponentially. This is a simple corollary of Gr\u00f6nwall's inequality, and some\npeople call this Gr\u00f6nwall's inequality too.\n\nThis version assumes all inequalities to be true in the whole space. -/\ntheorem dist_le_of_trajectories_ODE {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g : \u211d \u2192 E} {a b : \u211d} {\u03b4 : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (ha : dist (f a) (g a) \u2264 \u03b4) :\n  \u2200 t \u2208 Icc a b, dist (f t) (g t) \u2264 \u03b4 * exp (K * (t - a)) :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\ndist_le_of_trajectories_ODE_of_mem_set (\u03bb t x y hx hy, (hv t).dist_le_mul x y)\n  hf hf' hfs hg hg' (\u03bb t ht, trivial) ha\n\n/-- There exists only one solution of an ODE \\(\\dot x=v(t, x)\\) in a set `s \u2286 \u211d \u00d7 E` with\na given initial value provided that RHS is Lipschitz continuous in `x` within `s`,\nand we consider only solutions included in `s`. -/\ntheorem ODE_solution_unique_of_mem_set {v : \u211d \u2192 E \u2192 E} {s : \u211d \u2192 set E}\n  {K : \u211d} (hv : \u2200 t, \u2200 x y \u2208 s t, dist (v t x) (v t y) \u2264 K * dist x y)\n  {f g : \u211d \u2192 E} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hfs : \u2200 t \u2208 Ico a b, f t \u2208 s t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (hgs : \u2200 t \u2208 Ico a b, g t \u2208 s t)\n  (ha : f a = g a) :\n  \u2200 t \u2208 Icc a b, f t = g t :=\nbegin\n  assume t ht,\n  have := dist_le_of_trajectories_ODE_of_mem_set hv hf hf' hfs hg hg' hgs\n    (dist_le_zero.2 ha) t ht,\n  rwa [zero_mul, dist_le_zero] at this\nend\n\n/-- There exists only one solution of an ODE \\(\\dot x=v(t, x)\\) with\na given initial value provided that RHS is Lipschitz continuous in `x`. -/\ntheorem ODE_solution_unique {v : \u211d \u2192 E \u2192 E}\n  {K : \u211d\u22650} (hv : \u2200 t, lipschitz_with K (v t))\n  {f g : \u211d \u2192 E} {a b : \u211d}\n  (hf : continuous_on f (Icc a b))\n  (hf' : \u2200 t \u2208 Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)\n  (hg : continuous_on g (Icc a b))\n  (hg' : \u2200 t \u2208 Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)\n  (ha : f a = g a) :\n  \u2200 t \u2208 Icc a b, f t = g t :=\nhave hfs : \u2200 t \u2208 Ico a b, f t \u2208 (@univ E), from \u03bb t ht, trivial,\nODE_solution_unique_of_mem_set (\u03bb t x y hx hy, (hv t).dist_le_mul x y)\n  hf hf' hfs hg hg' (\u03bb t ht, trivial) ha\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/ODE/gronwall.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7168779949783115}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.multiset.nodup\nimport Mathlib.data.list.nat_antidiagonal\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# The \"antidiagonal\" {(0,n), (1,n-1), ..., (n,0)} as a multiset.\n-/\n\nnamespace multiset\n\n\nnamespace nat\n\n\n/-- The antidiagonal of a natural number `n` is\n    the multiset of pairs `(i,j)` such that `i+j = n`. -/\ndef antidiagonal (n : \u2115) : multiset (\u2115 \u00d7 \u2115) := \u2191(list.nat.antidiagonal n)\n\n/-- A pair (i,j) is contained in the antidiagonal of `n` if and only if `i+j=n`. -/\n@[simp] theorem mem_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} :\n    x \u2208 antidiagonal n \u2194 prod.fst x + prod.snd x = n :=\n  sorry\n\n/-- The cardinality of the antidiagonal of `n` is `n+1`. -/\n@[simp] theorem card_antidiagonal (n : \u2115) : coe_fn card (antidiagonal n) = n + 1 := sorry\n\n/-- The antidiagonal of `0` is the list `[(0,0)]` -/\n@[simp] theorem antidiagonal_zero : antidiagonal 0 = singleton (0, 0) := rfl\n\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\n@[simp] theorem nodup_antidiagonal (n : \u2115) : nodup (antidiagonal n) :=\n  iff.mpr coe_nodup (list.nat.nodup_antidiagonal n)\n\n@[simp] theorem antidiagonal_succ {n : \u2115} :\n    antidiagonal (n + 1) = (0, n + 1) ::\u2098 map (prod.map Nat.succ id) (antidiagonal n) :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/multiset/nat_antidiagonal_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.716709021446523}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis, S\u00e9bastien Gou\u00ebzel\nCharacterize completeness of metric spaces in terms of Cauchy sequences.\nIn particular, reconcile the filter notion of Cauchy-ness with the cau_seq notion on normed spaces.\n-/\n\nimport topology.uniform_space.basic analysis.normed_space.basic data.real.cau_seq analysis.specific_limits\nimport tactic.linarith\n\nuniverses u v\nopen set filter classical emetric\n\nvariable {\u03b2 : Type v}\n\n/- We show that a metric space in which all Cauchy sequences converge is complete, i.e., all\nCauchy filters converge. For this, we approximate any Cauchy filter by a Cauchy sequence,\ntaking advantage of the fact that there is a sequence tending to `0` in \u211d. The proof also gives\na more precise result, that to get completeness it is enough to have the convergence\nof all sequence that are Cauchy in a fixed quantitative sense, for instance satisfying\n`dist (u n) (u m) < 2^{- min m n}`. The classical argument to obtain this criterion is to start\nfrom a Cauchy sequence, extract a subsequence that satisfies this property, deduce the convergence\nof the subsequence, and then the convergence of the original sequence. All this argument is\ncompletely bypassed by the following proof, which avoids any use of subsequences and is written\npartly in terms of filters. -/\n\nnamespace ennreal\n\n/-In this paragraph, we prove useful properties of the sequence `half_pow n := 2^{-n}` in ennreal.\nSome of them are instrumental in this file to get Cauchy sequences, but others are proved\nhere only for use in further applications of the completeness criterion\n`emetric.complete_of_convergent_controlled_sequences` below. -/\n\n/-- An auxiliary positive sequence that tends to `0` in `ennreal`, with good behavior. -/\nnoncomputable def half_pow (n : \u2115) : ennreal := ennreal.of_real ((1 / 2) ^ n)\n\nlemma half_pow_pos (n : \u2115) : 0 < half_pow n :=\nbegin\n  have : (0 : real) < (1/2)^n := pow_pos (by norm_num) _,\n  simpa [half_pow] using this\nend\n\nlemma half_pow_tendsto_zero : tendsto (\u03bbn, half_pow n) at_top (nhds 0) :=\nbegin\n  unfold half_pow,\n  rw \u2190 ennreal.of_real_zero,\n  apply ennreal.tendsto_of_real,\n  exact tendsto_pow_at_top_nhds_0_of_lt_1 (by norm_num) (by norm_num)\nend\n\nlemma half_pow_add_succ (n : \u2115) : half_pow (n+1) + half_pow (n+1) = half_pow n :=\nbegin\n  have : (0 : real) \u2264 (1/2)^(n+1) := (le_of_lt (pow_pos (by norm_num) _)),\n  simp only [half_pow, eq.symm (ennreal.of_real_add this this)],\n  apply congr_arg,\n  simp only [pow_add, one_div_eq_inv, pow_one],\n  ring,\nend\n\nlemma half_pow_mono (m k : \u2115) (h : m \u2264 k) : half_pow k \u2264 half_pow m :=\nennreal.of_real_le_of_real (pow_le_pow_of_le_one (by norm_num) (by norm_num) h)\n\nlemma edist_le_two_mul_half_pow [emetric_space \u03b2] {k l N : \u2115} (hk : N \u2264 k) (hl : N \u2264 l)\n  {u : \u2115 \u2192 \u03b2} (h : \u2200n, edist (u n) (u (n+1)) \u2264 half_pow n) :\n  edist (u k) (u l) \u2264 2 * half_pow N :=\nbegin\n  have ineq_rec : \u2200m, \u2200k\u2265m, half_pow k + edist (u m) (u (k+1)) \u2264 2 * half_pow m,\n  { assume m,\n    refine nat.le_induction _ (\u03bbk km hk, _),\n    { calc half_pow m + edist (u m) (u (m+1)) \u2264 half_pow m + half_pow m : add_le_add_left' (h m)\n      ... = 2 * half_pow m : by simp [(mul_two _).symm, mul_comm] },\n    { calc half_pow (k + 1) + edist (u m) (u (k + 1 + 1))\n      \u2264 half_pow (k+1) + (edist (u m) (u (k+1)) + edist (u (k+1)) (u (k+2))) :\n        add_le_add_left' (edist_triangle _ _ _)\n      ... \u2264 half_pow (k+1) + (edist (u m) (u (k+1)) + half_pow (k+1)) :\n        add_le_add_left' (add_le_add_left' (h (k+1)))\n      ... = (half_pow(k+1) + half_pow(k+1)) + edist (u m) (u (k+1)) : by simp [add_comm]\n      ... = half_pow k + edist (u m) (u (k+1)) : by rw half_pow_add_succ\n      ... \u2264 2 * half_pow m : hk }},\n  have Imk : \u2200m, \u2200k\u2265m, edist (u m) (u k) \u2264 2 * half_pow m,\n  { assume m k hk,\n    by_cases h : m = k,\n    { simp [h, le_of_lt (half_pow_pos k)] },\n    { have I : m < k := lt_of_le_of_ne hk h,\n      have : 0 < k := lt_of_le_of_lt (nat.zero_le _) \u2039m < k\u203a,\n      let l := nat.pred k,\n      have : k = l+1 := (nat.succ_pred_eq_of_pos \u20390 < k\u203a).symm,\n      rw this,\n      have : m \u2264 l := begin rw this at I, apply nat.le_of_lt_succ I end,\n      calc edist (u m) (u (l+1)) \u2264 half_pow l + edist (u m) (u (l+1)) : le_add_left (le_refl _)\n        ... \u2264 2 * half_pow m : ineq_rec m l \u2039m \u2264 l\u203a }},\n  by_cases h : k \u2264 l,\n  { calc edist (u k) (u l) \u2264 2 * half_pow k : Imk k l h\n      ... \u2264 2 * half_pow N :\n        canonically_ordered_semiring.mul_le_mul (le_refl _) (half_pow_mono N k hk) },\n  { simp at h,\n    calc edist (u k) (u l) = edist (u l) (u k) : edist_comm _ _\n      ... \u2264 2 * half_pow l : Imk l k (le_of_lt h)\n      ... \u2264 2 * half_pow N :\n        canonically_ordered_semiring.mul_le_mul (le_refl _) (half_pow_mono N l hl) }\nend\n\nlemma cauchy_seq_of_edist_le_half_pow [emetric_space \u03b2]\n  {u : \u2115 \u2192 \u03b2} (h : \u2200n, edist (u n) (u (n+1)) \u2264 half_pow n) : cauchy_seq u :=\nbegin\n  refine emetric.cauchy_seq_iff_le_tendsto_0.2 \u27e8\u03bbn:\u2115, 2 * half_pow n, \u27e8_, _\u27e9\u27e9,\n  { exact \u03bbk l N hk hl, edist_le_two_mul_half_pow hk hl h },\n  { have : tendsto (\u03bbn, 2 * half_pow n) at_top (nhds (2 * 0)) :=\n      ennreal.tendsto_mul_right half_pow_tendsto_zero (by simp),\n    simpa using this }\nend\n\nend ennreal\n\nnamespace sequentially_complete\n\nsection\n/- We fix a cauchy filter `f`, and a bounding sequence `B` made of positive numbers. We will\nprove that, if all sequences satisfying `dist (u n) (u m) < B (min n m)` converge, then\nthe cauchy filter `f` is converging. The idea is to construct from `f` a Cauchy sequence\nthat satisfies this property, therefore converges, and then to deduce the convergence of\n`f` from this.\nWe give the argument in the more general setting of emetric spaces, and specialize it to\nmetric spaces at the end.\n-/\nvariables [emetric_space \u03b2] {f : filter \u03b2} (hf : cauchy f) (B : \u2115 \u2192 ennreal) (hB : \u2200n, 0 < B n)\nopen ennreal\n\n/--Auxiliary sequence, which is bounded by `B`, positive, and tends to `0`.-/\nnoncomputable def B2 (B : \u2115 \u2192 ennreal) (hB : \u2200n, 0 < B n) (n : \u2115) :=\n  (half_pow n) \u2293 (B n)\n\nlemma B2_pos (n : \u2115) : 0 < B2 B hB n :=\nby unfold B2; simp [half_pow_pos n, hB n]\n\nlemma B2_lim : tendsto (\u03bbn, B2 B hB n) at_top (nhds 0) :=\nbegin\n  have : \u2200n, B2 B hB n \u2264 half_pow n := \u03bbn, lattice.inf_le_left,\n  exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds half_pow_tendsto_zero\n    (by simp) (by simp [this])\nend\n\n/-- Define a decreasing sequence of sets in the filter `f`, of diameter bounded by `B2 n`. -/\ndef set_seq_of_cau_filter : \u2115 \u2192 set \u03b2\n| 0 := some ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB 0))\n| (n+1) := (set_seq_of_cau_filter n) \u2229 some ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB (n + 1)))\n\n/-- These sets are in the filter. -/\nlemma set_seq_of_cau_filter_mem_sets : \u2200 n, set_seq_of_cau_filter hf B hB n \u2208 f\n| 0 := some (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB 0)))\n| (n+1) := inter_mem_sets (set_seq_of_cau_filter_mem_sets n)\n             (some (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB (n + 1)))))\n\n/-- These sets are nonempty. -/\nlemma set_seq_of_cau_filter_inhabited (n : \u2115) : \u2203 x, x \u2208 set_seq_of_cau_filter hf B hB n :=\ninhabited_of_mem_sets (emetric.cauchy_iff.1 hf).1 (set_seq_of_cau_filter_mem_sets hf B hB n)\n\n/-- By construction, their diameter is controlled by `B2 n`. -/\nlemma set_seq_of_cau_filter_spec : \u2200 n, \u2200 {x y},\n  x \u2208 set_seq_of_cau_filter hf B hB n \u2192 y \u2208 set_seq_of_cau_filter hf B hB n \u2192 edist x y < B2 B hB n\n| 0 := some_spec (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB 0)))\n| (n+1) := \u03bb x y hx hy,\n  some_spec (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB (n+1)))) x y\n    (mem_of_mem_inter_right hx) (mem_of_mem_inter_right hy)\n\n-- this must exist somewhere, no?\nprivate lemma mono_of_mono_succ_aux {\u03b1} [partial_order \u03b1] (f : \u2115 \u2192 \u03b1) (h : \u2200 n, f (n+1) \u2264 f n) (m : \u2115) :\n  \u2200 n, f (m + n) \u2264 f m\n| 0 := le_refl _\n| (k+1) := le_trans (h _) (mono_of_mono_succ_aux _)\n\nlemma mono_of_mono_succ {\u03b1} [partial_order \u03b1] (f : \u2115 \u2192 \u03b1) (h : \u2200 n, f (n+1) \u2264 f n) {m n : \u2115}\n  (hmn : m \u2264 n) : f n \u2264 f m :=\nlet \u27e8k, hk\u27e9 := nat.exists_eq_add_of_le hmn in\nby simpa [hk] using mono_of_mono_succ_aux f h m k\n\nlemma set_seq_of_cau_filter_monotone' (n : \u2115) :\n  set_seq_of_cau_filter hf B hB (n+1) \u2286 set_seq_of_cau_filter hf B hB n :=\ninter_subset_left _ _\n\n/-- These sets are nested. -/\nlemma set_seq_of_cau_filter_monotone {n k : \u2115} (hle : n \u2264 k) :\n  set_seq_of_cau_filter hf B hB k \u2286 set_seq_of_cau_filter hf B hB n :=\nmono_of_mono_succ (set_seq_of_cau_filter hf B hB) (set_seq_of_cau_filter_monotone' hf B hB) hle\n\n/-- Define the approximating Cauchy sequence for the Cauchy filter `f`,\nobtained by taking a point in each set. -/\nnoncomputable def seq_of_cau_filter (n : \u2115) : \u03b2 :=\nsome (set_seq_of_cau_filter_inhabited hf B hB n)\n\n/-- The approximating sequence indeed belong to our good sets. -/\nlemma seq_of_cau_filter_mem_set_seq (n : \u2115) : seq_of_cau_filter hf B hB n \u2208 set_seq_of_cau_filter hf B hB n :=\nsome_spec (set_seq_of_cau_filter_inhabited hf B hB n)\n\n/-- The distance between points in the sequence is bounded by `B2 N`. -/\nlemma seq_of_cau_filter_bound {N n k : \u2115} (hn : N \u2264 n) (hk : N \u2264 k) :\n  edist (seq_of_cau_filter hf B hB n) (seq_of_cau_filter hf B hB k) < B2 B hB N :=\nset_seq_of_cau_filter_spec hf B hB N\n  (set_seq_of_cau_filter_monotone hf B hB hn (seq_of_cau_filter_mem_set_seq hf B hB n))\n  (set_seq_of_cau_filter_monotone hf B hB hk (seq_of_cau_filter_mem_set_seq hf B hB k))\n\n/-- The approximating sequence is indeed Cauchy as `B2 n` tends to `0` with `n`. -/\nlemma seq_of_cau_filter_is_cauchy :\n  cauchy_seq (seq_of_cau_filter hf B hB) :=\nemetric.cauchy_seq_iff_le_tendsto_0.2 \u27e8B2 B hB,\n  \u03bb n m N hn hm, le_of_lt (seq_of_cau_filter_bound hf B hB hn hm), B2_lim B hB\u27e9\n\n/-- If the approximating Cauchy sequence is converging, to a limit `y`, then the\noriginal Cauchy filter `f` is also converging, to the same limit.\nGiven `t1` in the filter `f` and `t2` a neighborhood of `y`, it suffices to show that `t1 \u2229 t2` is\nnonempty.\nPick `\u03b5` so that the \u03b5-eball around `y` is contained in `t2`.\nPick `n` with `B2 n < \u03b5/2`, and `n2` such that `dist(seq n2, y) < \u03b5/2`. Let `N = max(n, n2)`.\nWe defined `seq` by looking at a decreasing sequence of sets of `f` with shrinking radius.\nThe Nth one has radius `< B2 N < \u03b5/2`. This set is in `f`, so we can find an element `x` that's\nalso in `t1`.\n`dist(x, seq N) < \u03b5/2` since `seq N` is in this set, and `dist (seq N, y) < \u03b5/2`,\nso `x` is in the \u03b5-ball around `y`, and thus in `t2`. -/\nlemma le_nhds_cau_filter_lim {y : \u03b2} (H : tendsto (seq_of_cau_filter hf B hB) at_top (nhds y)) :\n  f \u2264 nhds y :=\nbegin\n  refine (le_nhds_iff_adhp_of_cauchy hf).2 _,\n  refine forall_sets_neq_empty_iff_neq_bot.1 (\u03bbs hs, _),\n  rcases filter.mem_inf_sets.2 hs with \u27e8t1, ht1, t2, ht2, ht1t2\u27e9,\n  rcases emetric.mem_nhds_iff.1 ht2 with \u27e8\u03b5, h\u03b5, ht2'\u27e9,\n  cases emetric.cauchy_iff.1 hf with hfb _,\n  have : \u03b5 / 2 > 0 := ennreal.half_pos h\u03b5,\n  rcases inhabited_of_mem_sets (by simp) ((tendsto_orderable.1 (B2_lim B hB)).2 _ this)\n    with \u27e8n, hn\u03b5\u27e9,\n  simp only [set.mem_set_of_eq] at hn\u03b5, -- hn\u03b5 : \u03b5 / 2 > B2 B hB n\n  cases (emetric.tendsto_at_top _).1 H _ this with n2 hn2,\n  let N := max n n2,\n  have ht1sn : t1 \u2229 set_seq_of_cau_filter hf B hB N \u2208 f,\n    from inter_mem_sets ht1 (set_seq_of_cau_filter_mem_sets hf B hB _),\n  have hts1n_ne : t1 \u2229 set_seq_of_cau_filter hf B hB N \u2260 \u2205,\n    from forall_sets_neq_empty_iff_neq_bot.2 hfb _ ht1sn,\n  cases exists_mem_of_ne_empty hts1n_ne with x hx,\n  -- x : \u03b2,  hx : x \u2208 t1 \u2229 set_seq_of_cau_filter hf B hB N\n  -- we still have to show that x \u2208 t2, i.e., edist x y < \u03b5\n  have I1 : seq_of_cau_filter hf B hB N \u2208 set_seq_of_cau_filter hf B hB n :=\n    (set_seq_of_cau_filter_monotone hf B hB (le_max_left n n2)) (seq_of_cau_filter_mem_set_seq hf B hB N),\n  have I2 : x \u2208 set_seq_of_cau_filter hf B hB n :=\n    (set_seq_of_cau_filter_monotone hf B hB (le_max_left n n2)) hx.2,\n  have hdist1 : edist x (seq_of_cau_filter hf B hB N) < B2 B hB n :=\n    set_seq_of_cau_filter_spec hf B hB _ I2 I1,\n  have hdist2 : edist (seq_of_cau_filter hf B hB N) y < \u03b5 / 2 :=\n    hn2 N (le_max_right _ _),\n  have hdist : edist x y < \u03b5 := calc\n    edist x y \u2264 edist x (seq_of_cau_filter hf B hB N) + edist (seq_of_cau_filter hf B hB N) y : edist_triangle _ _ _\n          ... < B2 B hB n + \u03b5/2 : ennreal.add_lt_add hdist1 hdist2\n          ... \u2264 \u03b5/2 + \u03b5/2 : add_le_add_right' (le_of_lt hn\u03b5)\n          ... = \u03b5 : ennreal.add_halves _,\n  have hxt2 : x \u2208 t2, from ht2' hdist,\n  exact ne_empty_iff_exists_mem.2 \u27e8x, ht1t2 (mem_inter hx.left hxt2)\u27e9\nend\n\nend\nend sequentially_complete\n\n/-- An emetric space in which every Cauchy sequence converges is complete. -/\ntheorem complete_of_cauchy_seq_tendsto {\u03b1 : Type u} [emetric_space \u03b1]\n  (H : \u2200u : \u2115 \u2192 \u03b1, cauchy_seq u \u2192 \u2203x, tendsto u at_top (nhds x)) :\n  complete_space \u03b1 :=\n\u27e8begin\n  -- Consider a Cauchy filter `f`\n  intros f hf,\n  -- Introduce a sequence `u` approximating the filter `f`. We don't need the bound `B`,\n  -- so take for instance `B n = 1` for all `n`.\n  let u := sequentially_complete.seq_of_cau_filter hf (\u03bbn, 1) (\u03bbn, ennreal.zero_lt_one),\n  -- It is Cauchy.\n  have : cauchy_seq u := sequentially_complete.seq_of_cau_filter_is_cauchy hf (\u03bbn, 1) (\u03bbn, ennreal.zero_lt_one),\n  -- Therefore, it converges by assumption. Let `x` be its limit.\n  rcases H u this with \u27e8x, hx\u27e9,\n  -- The original filter also converges to `x`.\n  exact \u27e8x, sequentially_complete.le_nhds_cau_filter_lim hf (\u03bbn, 1) (\u03bbn, ennreal.zero_lt_one) hx\u27e9\nend\u27e9\n\n/-- A very useful criterion to show that a space is complete is to show that all sequences\nwhich satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m \u2265 N` are\nconverging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to\n`0`, which makes it possible to use arguments of converging series, while this is impossible\nto do in general for arbitrary Cauchy sequences. -/\ntheorem emetric.complete_of_convergent_controlled_sequences {\u03b1 : Type u} [emetric_space \u03b1]\n  (B : \u2115 \u2192 ennreal) (hB : \u2200n, 0 < B n)\n  (H : \u2200u : \u2115 \u2192 \u03b1, (\u2200N n m : \u2115, N \u2264 n \u2192 N \u2264 m \u2192 edist (u n) (u m) < B N) \u2192 \u2203x, tendsto u at_top (nhds x)) :\n  complete_space \u03b1 :=\n\u27e8begin\n  -- Consider a Cauchy filter `f`.\n  intros f hf,\n  -- Introduce a sequence `u` approximating the filter `f`.\n  let u := sequentially_complete.seq_of_cau_filter hf B hB,\n  -- It satisfies the required bound.\n  have : \u2200N n m : \u2115, N \u2264 n \u2192 N \u2264 m \u2192 edist (u n) (u m) < B N := \u03bbN n m hn hm, calc\n    edist (u n) (u m) < sequentially_complete.B2 B hB N :\n      sequentially_complete.seq_of_cau_filter_bound hf B hB hn hm\n    ... \u2264 B N : lattice.inf_le_right,\n  -- Therefore, it converges by assumption. Let `x` be its limit.\n  rcases H u this with \u27e8x, hx\u27e9,\n  -- The original filter also converges to `x`.\n  exact \u27e8x, sequentially_complete.le_nhds_cau_filter_lim hf B hB hx\u27e9\nend\u27e9\n\n/-- A very useful criterion to show that a space is complete is to show that all sequences\nwhich satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m \u2265 N` are\nconverging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to\n`0`, which makes it possible to use arguments of converging series, while this is impossible\nto do in general for arbitrary Cauchy sequences. -/\ntheorem metric.complete_of_convergent_controlled_sequences {\u03b1 : Type u} [metric_space \u03b1]\n  (B : \u2115 \u2192 real) (hB : \u2200n, 0 < B n)\n  (H : \u2200u : \u2115 \u2192 \u03b1, (\u2200N n m : \u2115, N \u2264 n \u2192 N \u2264 m \u2192 dist (u n) (u m) < B N) \u2192 \u2203x, tendsto u at_top (nhds x)) :\n  complete_space \u03b1 :=\nbegin\n  -- this follows from the same criterion in emetric spaces. We just need to translate\n  -- the convergence assumption from `dist` to `edist`\n  apply emetric.complete_of_convergent_controlled_sequences (\u03bbn, ennreal.of_real (B n)),\n  { simp [hB] },\n  { assume u Hu,\n    apply H,\n    assume N n m hn hm,\n    have Z := Hu N n m hn hm,\n    rw [edist_dist, ennreal.of_real_lt_of_real_iff] at Z,\n    exact Z,\n    exact hB N }\nend\n\nsection\n\n/- Now, we will apply these results to `cau_seq`, i.e., \"Cauchy sequences\" defined by a\nmultiplicative absolute value on normed fields. -/\n\nlemma tendsto_limit [normed_ring \u03b2] [hn : is_absolute_value (norm : \u03b2 \u2192 \u211d)]\n  (f : cau_seq \u03b2 norm) [cau_seq.is_complete \u03b2 norm] :\n  tendsto f at_top (nhds f.lim) :=\n_root_.tendsto_nhds.mpr\nbegin\n  intros s os lfs,\n  suffices : \u2203 (a : \u2115), \u2200 (b : \u2115), b \u2265 a \u2192 f b \u2208 s, by simpa using this,\n  rcases metric.is_open_iff.1 os _ lfs with \u27e8\u03b5, \u27e8h\u03b5, h\u03b5s\u27e9\u27e9,\n  cases setoid.symm (cau_seq.equiv_lim f) _ h\u03b5 with N hN,\n  existsi N,\n  intros b hb,\n  apply h\u03b5s,\n  dsimp [metric.ball], rw [dist_comm, dist_eq_norm],\n  solve_by_elim\nend\n\nvariables [normed_field \u03b2]\n\n/-\n This section shows that if we have a uniform space generated by an absolute value, topological\n completeness and Cauchy sequence completeness coincide. The problem is that there isn't\n a good notion of \"uniform space generated by an absolute value\", so right now this is\n specific to norm. Furthermore, norm only instantiates is_absolute_value on normed_field.\n This needs to be fixed, since it prevents showing that \u2124_[hp] is complete\n-/\n\ninstance normed_field.is_absolute_value : is_absolute_value (norm : \u03b2 \u2192 \u211d) :=\n{ abv_nonneg := norm_nonneg,\n  abv_eq_zero := norm_eq_zero,\n  abv_add := norm_triangle,\n  abv_mul := normed_field.norm_mul }\n\nopen metric\n\nlemma cauchy_of_filter_cauchy (f : \u2115 \u2192 \u03b2) (hf : cauchy_seq f) :\n  is_cau_seq norm f :=\nbegin\n  cases cauchy_iff.1 hf with hf1 hf2,\n  intros \u03b5 h\u03b5,\n  rcases hf2 {x | dist x.1 x.2 < \u03b5} (dist_mem_uniformity h\u03b5) with \u27e8t, \u27e8ht, htsub\u27e9\u27e9,\n  simp at ht, cases ht with N hN,\n  existsi N,\n  intros j hj,\n  rw \u2190dist_eq_norm,\n  apply @htsub (f j, f N),\n  apply set.mk_mem_prod; solve_by_elim [le_refl]\nend\n\nlemma filter_cauchy_of_cauchy (f : cau_seq \u03b2 norm) : cauchy_seq f :=\nbegin\n  apply cauchy_iff.2,\n  split,\n  { exact map_ne_bot at_top_ne_bot },\n  { intros s hs,\n    rcases mem_uniformity_dist.1 hs with \u27e8\u03b5, \u27e8h\u03b5, h\u03b5s\u27e9\u27e9,\n    cases cau_seq.cauchy\u2082 f h\u03b5 with N hN,\n    existsi {n | n \u2265 N}.image f,\n    simp, split,\n    { existsi N, intros b hb, existsi b, simp [hb] },\n    { rintros \u27e8a, b\u27e9 \u27e8\u27e8a', \u27e8ha'1, ha'2\u27e9\u27e9, \u27e8b', \u27e8hb'1, hb'2\u27e9\u27e9\u27e9,\n      dsimp at ha'1 ha'2 hb'1 hb'2,\n      rw [\u2190ha'2, \u2190hb'2],\n      apply h\u03b5s,\n      rw dist_eq_norm,\n      apply hN; assumption }},\nend\n\n/-- In a normed field, `cau_seq` coincides with the usual notion of Cauchy sequences. -/\nlemma cau_seq_iff_cauchy_seq {\u03b1 : Type u} [normed_field \u03b1] {u : \u2115 \u2192 \u03b1} :\n  is_cau_seq norm u \u2194 cauchy_seq u :=\n\u27e8\u03bbh, filter_cauchy_of_cauchy \u27e8u, h\u27e9,\n \u03bbh, cauchy_of_filter_cauchy u h\u27e9\n\n/-- A complete normed field is complete as a metric space, as Cauchy sequences converge by\nassumption and this suffices to characterize completeness. -/\ninstance complete_space_of_cau_seq_complete [cau_seq.is_complete \u03b2 norm] : complete_space \u03b2 :=\nbegin\n  apply complete_of_cauchy_seq_tendsto,\n  assume u hu,\n  have C : is_cau_seq norm u := cau_seq_iff_cauchy_seq.2 hu,\n  existsi cau_seq.lim \u27e8u, C\u27e9,\n  rw metric.tendsto_at_top,\n  assume \u03b5 \u03b5pos,\n  cases (cau_seq.equiv_lim \u27e8u, C\u27e9) _ \u03b5pos with N hN,\n  existsi N,\n  simpa [dist_eq_norm] using hN\nend\n\nend\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/topology/metric_space/cau_seq_filter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7167090155266849}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.algebra.subalgebra\nimport topology.algebra.module\n\n/-!\n# Topological (sub)algebras\n\nA topological algebra over a topological semiring `R` is a topological ring with a compatible\ncontinuous scalar multiplication by elements of `R`. We reuse typeclass `has_continuous_smul` for\ntopological algebras.\n\n## Results\n\nThis is just a minimal stub for now!\n\nThe topological closure of a subalgebra is still a subalgebra,\nwhich as an algebra is a topological algebra.\n-/\n\nopen classical set topological_space algebra\nopen_locale classical\n\nuniverses u v w\n\nsection topological_algebra\nvariables (R : Type*) [topological_space R] [comm_semiring R]\nvariables (A : Type u) [topological_space A]\nvariables [semiring A]\n\nlemma continuous_algebra_map_iff_smul [algebra R A] [topological_ring A] :\n  continuous (algebra_map R A) \u2194 continuous (\u03bb p : R \u00d7 A, p.1 \u2022 p.2) :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { simp only [algebra.smul_def], exact (h.comp continuous_fst).mul continuous_snd },\n  { rw algebra_map_eq_smul_one', exact h.comp (continuous_id.prod_mk continuous_const) }\nend\n\n@[continuity]\nlemma continuous_algebra_map [algebra R A] [topological_ring A] [has_continuous_smul R A] :\n  continuous (algebra_map R A) :=\n(continuous_algebra_map_iff_smul R A).2 continuous_smul\n\nlemma has_continuous_smul_of_algebra_map [algebra R A] [topological_ring A]\n  (h : continuous (algebra_map R A)) :\n  has_continuous_smul R A :=\n\u27e8(continuous_algebra_map_iff_smul R A).1 h\u27e9\n\nend topological_algebra\n\nsection topological_algebra\nvariables {R : Type*} [comm_semiring R]\nvariables {A : Type u} [topological_space A]\nvariables [semiring A]\nvariables [algebra R A] [topological_ring A]\n\n/-- The closure of a subalgebra in a topological algebra as a subalgebra. -/\ndef subalgebra.topological_closure (s : subalgebra R A) : subalgebra R A :=\n{ carrier := closure (s : set A),\n  algebra_map_mem' := \u03bb r, s.to_subsemiring.subring_topological_closure (s.algebra_map_mem r),\n  .. s.to_subsemiring.topological_closure }\n\n@[simp] lemma subalgebra.topological_closure_coe (s : subalgebra R A) :\n  (s.topological_closure : set A) = closure (s : set A) :=\nrfl\n\ninstance subalgebra.topological_closure_topological_ring (s : subalgebra R A) :\n  topological_ring (s.topological_closure) :=\ns.to_subsemiring.topological_closure_topological_ring\n\ninstance subalgebra.topological_closure_topological_algebra\n  [topological_space R] [has_continuous_smul R A] (s : subalgebra R A) :\n  has_continuous_smul R (s.topological_closure) :=\ns.to_submodule.topological_closure_has_continuous_smul\n\nlemma subalgebra.subalgebra_topological_closure (s : subalgebra R A) :\n  s \u2264 s.topological_closure :=\nsubset_closure\n\nlemma subalgebra.is_closed_topological_closure (s : subalgebra R A) :\n  is_closed (s.topological_closure : set A) :=\nby convert is_closed_closure\n\nlemma subalgebra.topological_closure_minimal\n  (s : subalgebra R A) {t : subalgebra R A} (h : s \u2264 t) (ht : is_closed (t : set A)) :\n  s.topological_closure \u2264 t :=\nclosure_minimal h ht\n\n/--\nThis is really a statement about topological algebra isomorphisms,\nbut we don't have those, so we use the clunky approach of talking about\nan algebra homomorphism, and a separate homeomorphism,\nalong with a witness that as functions they are the same.\n-/\nlemma subalgebra.topological_closure_comap'_homeomorph\n  (s : subalgebra R A)\n  {B : Type*} [topological_space B] [ring B] [topological_ring B] [algebra R B]\n  (f : B \u2192\u2090[R] A) (f' : B \u2243\u209c A) (w : (f : B \u2192 A) = f') :\n  s.topological_closure.comap' f = (s.comap' f).topological_closure :=\nbegin\n  apply set_like.ext',\n  simp only [subalgebra.topological_closure_coe],\n  simp only [subalgebra.coe_comap, subsemiring.coe_comap, alg_hom.coe_to_ring_hom],\n  rw [w],\n  exact f'.preimage_closure _,\nend\n\nend topological_algebra\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/algebra/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.716709009755837}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro and Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Kevin Buzzard\n-/\n\nimport data.equiv.algebra\nimport linear_algebra.linear_combination\nimport ring_theory.ideal_operations\nimport ring_theory.subring\n\nopen set lattice\n\nnamespace submodule\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [ring \u03b1] [add_comm_group \u03b2] [module \u03b1 \u03b2]\n\ndef fg (s : submodule \u03b1 \u03b2) : Prop := \u2203 t : finset \u03b2, submodule.span \u03b1 \u2191t = s\n\ntheorem fg_def {s : submodule \u03b1 \u03b2} :\n  s.fg \u2194 \u2203 t : set \u03b2, finite t \u2227 span \u03b1 t = s :=\n\u27e8\u03bb \u27e8t, h\u27e9, \u27e8_, finset.finite_to_set t, h\u27e9, begin\n  rintro \u27e8t', h, rfl\u27e9,\n  rcases finite.exists_finset_coe h with \u27e8t, rfl\u27e9,\n  exact \u27e8t, rfl\u27e9\nend\u27e9\n\n/-- Nakayama's Lemma. Atiyah-Macdonald 2.5, Eisenbud 4.7, Matsumura 2.2, Stacks 00DV -/\ntheorem exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul {R : Type*} [comm_ring R]\n  {M : Type*} [add_comm_group M] [module R M]\n  (I : ideal R) (N : submodule R M) (hn : N.fg) (hin : N \u2264 I \u2022 N) :\n  \u2203 r : R, r - 1 \u2208 I \u2227 \u2200 n \u2208 N, r \u2022 n = (0 : M) :=\nbegin\n  rw fg_def at hn, rcases hn with \u27e8s, hfs, hs\u27e9,\n  have : \u2203 r : R, r - 1 \u2208 I \u2227 N \u2264 (I \u2022 span R s).comap (linear_map.lsmul R M r) \u2227 s \u2286 N,\n  { refine \u27e81, _, _, _\u27e9,\n    { rw sub_self, exact I.zero_mem },\n    { rw [hs], intros n hn, rw [mem_coe, mem_comap], change (1:R) \u2022 n \u2208 I \u2022 N, rw one_smul, exact hin hn },\n    { rw [\u2190 span_le, hs], exact le_refl N } },\n  clear hin hs, revert this,\n  refine set.finite.dinduction_on hfs (\u03bb H, _) (\u03bb i s his hfs ih H, _),\n  { rcases H with \u27e8r, hr1, hrn, hs\u27e9, refine \u27e8r, hr1, \u03bb n hn, _\u27e9, specialize hrn hn,\n    rwa [mem_coe, mem_comap, span_empty, smul_bot, mem_bot] at hrn },\n  apply ih, rcases H with \u27e8r, hr1, hrn, hs\u27e9,\n  rw [\u2190 set.singleton_union, span_union, smul_sup] at hrn,\n  rw [set.insert_subset] at hs,\n  have : \u2203 c : R, c - 1 \u2208 I \u2227 c \u2022 i \u2208 I \u2022 span R s,\n  { specialize hrn hs.1, rw [mem_coe, mem_comap, mem_sup] at hrn,\n    rcases hrn with \u27e8y, hy, z, hz, hyz\u27e9, change y + z = r \u2022 i at hyz,\n    rw mem_smul_span_singleton at hy, rcases hy with \u27e8c, hci, rfl\u27e9,\n    use r-c, split,\n    { rw [sub_right_comm], exact I.sub_mem hr1 hci },\n    { rw [sub_smul, \u2190 hyz, add_sub_cancel'], exact hz } },\n  rcases this with \u27e8c, hc1, hci\u27e9, refine \u27e8c * r, _, _, hs.2\u27e9,\n  { rw [\u2190 ideal.quotient.eq, ideal.quotient.mk_one] at hr1 hc1 \u22a2,\n    rw [ideal.quotient.mk_mul, hc1, hr1, mul_one] },\n  { intros n hn, specialize hrn hn, rw [mem_coe, mem_comap, mem_sup] at hrn,\n    rcases hrn with \u27e8y, hy, z, hz, hyz\u27e9, change y + z = r \u2022 n at hyz,\n    rw mem_smul_span_singleton at hy, rcases hy with \u27e8d, hdi, rfl\u27e9,\n    change _ \u2022 _ \u2208 I \u2022 span R s,\n    rw [mul_smul, \u2190 hyz, smul_add, smul_smul, mul_comm, mul_smul],\n    exact add_mem _ (smul_mem _ _ hci) (smul_mem _ _ hz) }\nend\n\ntheorem fg_bot : (\u22a5 : submodule \u03b1 \u03b2).fg :=\n\u27e8\u2205, by rw [finset.coe_empty, span_empty]\u27e9\n\ntheorem fg_sup {s\u2081 s\u2082 : submodule \u03b1 \u03b2}\n  (hs\u2081 : s\u2081.fg) (hs\u2082 : s\u2082.fg) : (s\u2081 \u2294 s\u2082).fg :=\nlet \u27e8t\u2081, ht\u2081\u27e9 := fg_def.1 hs\u2081, \u27e8t\u2082, ht\u2082\u27e9 := fg_def.1 hs\u2082 in\nfg_def.2 \u27e8t\u2081 \u222a t\u2082, finite_union ht\u2081.1 ht\u2082.1, by rw [span_union, ht\u2081.2, ht\u2082.2]\u27e9\n\nvariables {\u03b3 : Type*} [add_comm_group \u03b3] [module \u03b1 \u03b3]\nvariables {f : \u03b2 \u2192\u2097[\u03b1] \u03b3}\n\ntheorem fg_map {s : submodule \u03b1 \u03b2} (hs : s.fg) : (s.map f).fg :=\nlet \u27e8t, ht\u27e9 := fg_def.1 hs in fg_def.2 \u27e8f '' t, finite_image _ ht.1, by rw [span_image, ht.2]\u27e9\n\ntheorem fg_prod {sb : submodule \u03b1 \u03b2} {sc : submodule \u03b1 \u03b3}\n  (hsb : sb.fg) (hsc : sc.fg) : (sb.prod sc).fg :=\nlet \u27e8tb, htb\u27e9 := fg_def.1 hsb, \u27e8tc, htc\u27e9 := fg_def.1 hsc in\nfg_def.2 \u27e8prod.inl '' tb \u222a prod.inr '' tc,\n  finite_union (finite_image _ htb.1) (finite_image _ htc.1),\n  by rw [linear_map.span_inl_union_inr, htb.2, htc.2]\u27e9\n\nvariable (f)\n/-- If 0 \u2192 M' \u2192 M \u2192 M'' \u2192 0 is exact and M' and M'' are\nfinitely generated then so is M. -/\ntheorem fg_of_fg_map_of_fg_inf_ker {s : submodule \u03b1 \u03b2}\n  (hs1 : (s.map f).fg) (hs2 : (s \u2293 f.ker).fg) : s.fg :=\nbegin\n  haveI := classical.dec_eq \u03b2, haveI := classical.dec_eq \u03b3,\n  cases hs1 with t1 ht1, cases hs2 with t2 ht2,\n  have : \u2200 y \u2208 t1, \u2203 x \u2208 s, f x = y,\n  { intros y hy,\n    have : y \u2208 map f s, { rw \u2190 ht1, exact subset_span hy },\n    rcases mem_map.1 this with \u27e8x, hx1, hx2\u27e9,\n    exact \u27e8x, hx1, hx2\u27e9 },\n  have : \u2203 g : \u03b3 \u2192 \u03b2, \u2200 y \u2208 t1, g y \u2208 s \u2227 f (g y) = y,\n  { choose g hg1 hg2,\n    existsi \u03bb y, if H : y \u2208 t1 then g y H else 0,\n    intros y H, split,\n    { simp only [dif_pos H], apply hg1 },\n    { simp only [dif_pos H], apply hg2 } },\n  cases this with g hg, clear this,\n  existsi t1.image g \u222a t2,\n  rw [finset.coe_union, span_union, finset.coe_image],\n  apply le_antisymm,\n  { refine sup_le (span_le.2 $ image_subset_iff.2 _) (span_le.2 _),\n    { intros y hy, exact (hg y hy).1 },\n    { intros x hx, have := subset_span hx,\n      rw ht2 at this,\n      exact this.1 } },\n  intros x hx,\n  have : f x \u2208 map f s, { rw mem_map, exact \u27e8x, hx, rfl\u27e9 },\n  rw [\u2190 ht1, mem_span_iff_lc] at this,\n  rcases this with \u27e8l, hl1, hl2\u27e9,\n  refine mem_sup.2 \u27e8lc.total \u03b1 \u03b2 ((lc.map \u03b1 g : lc \u03b1 \u03b3 \u2192 lc \u03b1 \u03b2) l), _,\n    x - lc.total \u03b1 \u03b2 ((lc.map \u03b1 g : lc \u03b1 \u03b3 \u2192 lc \u03b1 \u03b2) l), _, add_sub_cancel'_right _ _\u27e9,\n  { rw mem_span_iff_lc, refine \u27e8_, _, rfl\u27e9,\n    rw [\u2190 lc.map_supported g, mem_map],\n    exact \u27e8_, hl1, rfl\u27e9 },\n  rw [ht2, mem_inf], split,\n  { apply s.sub_mem hx,\n    rw [lc.total_apply, lc.map_apply, finsupp.sum_map_domain_index],\n    refine s.sum_mem _,\n    { intros y hy, exact s.smul_mem _ (hg y (hl1 hy)).1 },\n    { exact zero_smul _ }, { exact \u03bb _ _ _, add_smul _ _ _ } },\n  { rw [linear_map.mem_ker, f.map_sub, \u2190 hl2],\n    rw [lc.total_apply, lc.total_apply, lc.map_apply],\n    rw [finsupp.sum_map_domain_index, finsupp.sum, finsupp.sum, f.map_sum],\n    rw sub_eq_zero,\n    refine finset.sum_congr rfl (\u03bb y hy, _),\n    rw [f.map_smul, (hg y (hl1 hy)).2],\n    { exact zero_smul _ }, { exact \u03bb _ _ _, add_smul _ _ _ } }\nend\n\nend submodule\n\nclass is_noetherian (\u03b1 \u03b2) [ring \u03b1] [add_comm_group \u03b2] [module \u03b1 \u03b2] : Prop :=\n(noetherian : \u2200 (s : submodule \u03b1 \u03b2), s.fg)\n\nsection\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\nvariables [ring \u03b1] [add_comm_group \u03b2] [add_comm_group \u03b3]\nvariables [module \u03b1 \u03b2] [module \u03b1 \u03b3]\nopen is_noetherian\ninclude \u03b1\n\ntheorem is_noetherian_submodule {N : submodule \u03b1 \u03b2} :\n  is_noetherian \u03b1 N \u2194 \u2200 s : submodule \u03b1 \u03b2, s \u2264 N \u2192 s.fg :=\n\u27e8\u03bb \u27e8hn\u27e9, \u03bb s hs, have s \u2264 N.subtype.range, from (N.range_subtype).symm \u25b8 hs,\n  linear_map.map_comap_eq_self this \u25b8 submodule.fg_map (hn _),\n\u03bb h, \u27e8\u03bb s, submodule.fg_of_fg_map_of_fg_inf_ker N.subtype (h _ $ submodule.map_subtype_le _ _) $\n  by rw [submodule.ker_subtype, inf_bot_eq]; exact submodule.fg_bot\u27e9\u27e9\n\ntheorem is_noetherian_submodule_left {N : submodule \u03b1 \u03b2} :\n  is_noetherian \u03b1 N \u2194 \u2200 s : submodule \u03b1 \u03b2, (N \u2293 s).fg :=\nis_noetherian_submodule.trans\n\u27e8\u03bb H s, H _ inf_le_left, \u03bb H s hs, (inf_of_le_right hs) \u25b8 H _\u27e9\n\ntheorem is_noetherian_submodule_right {N : submodule \u03b1 \u03b2} :\n  is_noetherian \u03b1 N \u2194 \u2200 s : submodule \u03b1 \u03b2, (s \u2293 N).fg :=\nis_noetherian_submodule.trans\n\u27e8\u03bb H s, H _ inf_le_right, \u03bb H s hs, (inf_of_le_left hs) \u25b8 H _\u27e9\n\nvariable (\u03b2)\ntheorem is_noetherian_of_surjective (f : \u03b2 \u2192\u2097[\u03b1] \u03b3) (hf : f.range = \u22a4)\n  [is_noetherian \u03b1 \u03b2] : is_noetherian \u03b1 \u03b3 :=\n\u27e8\u03bb s, have (s.comap f).map f = s, from linear_map.map_comap_eq_self $ hf.symm \u25b8 le_top,\nthis \u25b8 submodule.fg_map $ noetherian _\u27e9\nvariable {\u03b2}\n\ntheorem is_noetherian_of_linear_equiv (f : \u03b2 \u2243\u2097[\u03b1] \u03b3)\n  [is_noetherian \u03b1 \u03b2] : is_noetherian \u03b1 \u03b3 :=\nis_noetherian_of_surjective _ f.to_linear_map f.range\n\ninstance is_noetherian_prod [is_noetherian \u03b1 \u03b2]\n  [is_noetherian \u03b1 \u03b3] : is_noetherian \u03b1 (\u03b2 \u00d7 \u03b3) :=\n\u27e8\u03bb s, submodule.fg_of_fg_map_of_fg_inf_ker (linear_map.snd \u03b1 \u03b2 \u03b3) (noetherian _) $\nhave s \u2293 linear_map.ker (linear_map.snd \u03b1 \u03b2 \u03b3) \u2264 linear_map.range (linear_map.inl \u03b1 \u03b2 \u03b3),\nfrom \u03bb x \u27e8hx1, hx2\u27e9, \u27e8x.1, trivial, prod.ext rfl $ eq.symm $ linear_map.mem_ker.1 hx2\u27e9,\nlinear_map.map_comap_eq_self this \u25b8 submodule.fg_map (noetherian _)\u27e9\n\ninstance is_noetherian_pi {\u03b1 \u03b9 : Type*} {\u03b2 : \u03b9 \u2192 Type*} [ring \u03b1]\n  [\u03a0 i, add_comm_group (\u03b2 i)] [\u03a0 i, module \u03b1 (\u03b2 i)] [fintype \u03b9]\n  [\u2200 i, is_noetherian \u03b1 (\u03b2 i)] : is_noetherian \u03b1 (\u03a0 i, \u03b2 i) :=\nbegin\n  haveI := classical.dec_eq \u03b9,\n  suffices : \u2200 s : finset \u03b9, is_noetherian \u03b1 (\u03a0 i : (\u2191s : set \u03b9), \u03b2 i),\n  { letI := this finset.univ,\n    refine @is_noetherian_of_linear_equiv _ _ _ _ _ _ _ _\n      \u27e8_, _, _, _, _, _\u27e9 (this finset.univ),\n    { exact \u03bb f i, f \u27e8i, finset.mem_univ _\u27e9 },\n    { intros, ext, refl },\n    { intros, ext, refl },\n    { exact \u03bb f i, f i.1 },\n    { intro, ext i, cases i, refl },\n    { intro, ext i, refl } },\n  intro s,\n  induction s using finset.induction with a s has ih,\n  { split, intro s, convert submodule.fg_bot, apply eq_bot_iff.2,\n    intros x hx, refine (submodule.mem_bot \u03b1).2 _, ext i, cases i.2 },\n  refine @is_noetherian_of_linear_equiv _ _ _ _ _ _ _ _\n    \u27e8_, _, _, _, _, _\u27e9 (@is_noetherian_prod _ (\u03b2 a) _ _ _ _ _ _ _ ih),\n  { exact \u03bb f i, or.by_cases (finset.mem_insert.1 i.2)\n      (\u03bb h : i.1 = a, show \u03b2 i.1, from (eq.rec_on h.symm f.1))\n      (\u03bb h : i.1 \u2208 s, show \u03b2 i.1, from f.2 \u27e8i.1, h\u27e9) },\n  { intros f g, ext i, unfold or.by_cases, cases i with i hi,\n    rcases finset.mem_insert.1 hi with rfl | h,\n    { change _ = _ + _, simp only [dif_pos], refl },\n    { change _ = _ + _, have : \u00aci = a, { rintro rfl, exact has h },\n      simp only [dif_neg this, dif_pos h], refl } },\n  { intros c f, ext i, unfold or.by_cases, cases i with i hi,\n    rcases finset.mem_insert.1 hi with rfl | h,\n    { change _ = c \u2022 _, simp only [dif_pos], refl },\n    { change _ = c \u2022 _, have : \u00aci = a, { rintro rfl, exact has h },\n      simp only [dif_neg this, dif_pos h], refl } },\n  { exact \u03bb f, (f \u27e8a, finset.mem_insert_self _ _\u27e9, \u03bb i, f \u27e8i.1, finset.mem_insert_of_mem i.2\u27e9) },\n  { intro f, apply prod.ext,\n    { simp only [or.by_cases, dif_pos] },\n    { ext i, cases i with i his,\n      have : \u00aci = a, { rintro rfl, exact has his },\n      dsimp only [or.by_cases], change i \u2208 s at his,\n      rw [dif_neg this, dif_pos his] } },\n  { intro f, ext i, cases i with i hi,\n    rcases finset.mem_insert.1 hi with rfl | h,\n    { simp only [or.by_cases, dif_pos], refl },\n    { have : \u00aci = a, { rintro rfl, exact has h },\n      simp only [or.by_cases, dif_neg this, dif_pos h], refl } }\nend\n\nend\n\nopen is_noetherian\n\ntheorem is_noetherian_iff_well_founded\n  {\u03b1 \u03b2} [ring \u03b1] [add_comm_group \u03b2] [module \u03b1 \u03b2] :\n  is_noetherian \u03b1 \u03b2 \u2194 well_founded ((>) : submodule \u03b1 \u03b2 \u2192 submodule \u03b1 \u03b2 \u2192 Prop) :=\n\u27e8\u03bb h, begin\n  apply order_embedding.well_founded_iff_no_descending_seq.2,\n  swap, { apply is_strict_order.swap },\n  rintro \u27e8\u27e8N, hN\u27e9\u27e9,\n  let M := \u2a06 n, N n,\n  resetI,\n  rcases submodule.fg_def.1 (noetherian M) with \u27e8t, h\u2081, h\u2082\u27e9,\n  have hN' : \u2200 {a b}, a \u2264 b \u2192 N a \u2264 N b :=\n    \u03bb a b, (le_iff_le_of_strict_mono N (\u03bb _ _, hN.1)).2,\n  have : t \u2286 \u22c3 i, (N i : set \u03b2),\n  { rw [\u2190 submodule.Union_coe_of_directed _ N _],\n    { show t \u2286 M, rw \u2190 h\u2082,\n      apply submodule.subset_span },\n    { apply_instance },\n    { exact \u03bb i j, \u27e8max i j,\n        hN' (le_max_left _ _),\n        hN' (le_max_right _ _)\u27e9 } },\n  simp [subset_def] at this,\n  choose f hf using show \u2200 x : t, \u2203 (i : \u2115), x.1 \u2208 N i, { simpa },\n  cases h\u2081 with h\u2081,\n  let A := finset.sup (@finset.univ t h\u2081) f,\n  have : M \u2264 N A,\n  { rw \u2190 h\u2082, apply submodule.span_le.2,\n    exact \u03bb x h, hN' (finset.le_sup (@finset.mem_univ t h\u2081 _))\n      (hf \u27e8x, h\u27e9) },\n  exact not_le_of_lt (hN.1 (nat.lt_succ_self A))\n    (le_trans (le_supr _ _) this)\n  end,\n  begin\n    assume h, split, assume N,\n    suffices : \u2200 M \u2264 N, \u2203 s, finite s \u2227 M \u2294 submodule.span \u03b1 s = N,\n    { rcases this \u22a5 bot_le with \u27e8s, hs, e\u27e9,\n      exact submodule.fg_def.2 \u27e8s, hs, by simpa using e\u27e9 },\n    refine \u03bb M, h.induction M _, intros M IH MN,\n    letI := classical.dec,\n    by_cases h : \u2200 x, x \u2208 N \u2192 x \u2208 M,\n    { cases le_antisymm MN h, exact \u27e8\u2205, by simp\u27e9 },\n    { simp [not_forall] at h,\n      rcases h with \u27e8x, h, h\u2082\u27e9,\n      have : \u00acM \u2294 submodule.span \u03b1 {x} \u2264 M,\n      { intro hn, apply h\u2082,\n        have := le_trans le_sup_right hn,\n        exact submodule.span_le.1 this (mem_singleton x) },\n      rcases IH (M \u2294 submodule.span \u03b1 {x})\n        \u27e8@le_sup_left _ _ M _, this\u27e9\n        (sup_le MN (submodule.span_le.2 (by simpa))) with \u27e8s, hs, hs\u2082\u27e9,\n      refine \u27e8insert x s, finite_insert _ hs, _\u27e9,\n      rw [\u2190 hs\u2082, sup_assoc, \u2190 submodule.span_union], simp }\n  end\u27e9\n\nlemma well_founded_submodule_gt {\u03b1 \u03b2} [ring \u03b1] [add_comm_group \u03b2] [module \u03b1 \u03b2] :\n  \u2200 [is_noetherian \u03b1 \u03b2], well_founded ((>) : submodule \u03b1 \u03b2 \u2192 submodule \u03b1 \u03b2 \u2192 Prop) :=\nis_noetherian_iff_well_founded.mp\n\n@[class] def is_noetherian_ring (\u03b1) [ring \u03b1] : Prop := is_noetherian \u03b1 \u03b1\n\ninstance is_noetherian_ring.to_is_noetherian {\u03b1 : Type*} [ring \u03b1] :\n  \u2200 [is_noetherian_ring \u03b1], is_noetherian \u03b1 \u03b1 := id\n\ninstance ring.is_noetherian_of_fintype (R M) [ring R] [add_comm_group M] [module R M] [fintype M] : is_noetherian R M :=\nby letI := classical.dec; exact\n\u27e8assume s, \u27e8to_finset s, by rw [finset.coe_to_finset', submodule.span_eq]\u27e9\u27e9\n\ntheorem ring.is_noetherian_of_zero_eq_one {R} [ring R] (h01 : (0 : R) = 1) : is_noetherian_ring R :=\nby haveI := subsingleton_of_zero_eq_one R h01;\n   haveI := fintype.of_subsingleton (0:R);\n   exact ring.is_noetherian_of_fintype _ _\n\ntheorem is_noetherian_of_submodule_of_noetherian (R M) [ring R] [add_comm_group M] [module R M] (N : submodule R M)\n  (h : is_noetherian R M) : is_noetherian R N :=\nbegin\n  rw is_noetherian_iff_well_founded at h \u22a2,\n  convert order_embedding.well_founded (order_embedding.rsymm (submodule.map_subtype.lt_order_embedding N)) h\nend\n\ntheorem is_noetherian_of_quotient_of_noetherian (R) [ring R] (M) [add_comm_group M] [module R M] (N : submodule R M)\n  (h : is_noetherian R M) : is_noetherian R N.quotient :=\nbegin\n  rw is_noetherian_iff_well_founded at h \u22a2,\n  convert order_embedding.well_founded (order_embedding.rsymm (submodule.comap_mkq.lt_order_embedding N)) h\nend\n\ntheorem is_noetherian_of_fg_of_noetherian {R M} [ring R] [add_comm_group M] [module R M] (N : submodule R M)\n  [is_noetherian_ring R] (hN : N.fg) : is_noetherian R N :=\nlet \u27e8s, hs\u27e9 := hN in\nbegin\n  haveI := classical.dec_eq M,\n  letI : is_noetherian R R := by apply_instance,\n  have : \u2200 x \u2208 s, x \u2208 N, from \u03bb x hx, hs \u25b8 submodule.subset_span hx,\n  refine @@is_noetherian_of_surjective ((\u2191s : set M) \u2192 R) _ _ _ (pi.module _)\n    _ _ _ is_noetherian_pi,\n  { fapply linear_map.mk,\n    { exact \u03bb f, \u27e8s.attach.sum (\u03bb i, f i \u2022 i.1), N.sum_mem (\u03bb c _, N.smul_mem _ $ this _ c.2)\u27e9 },\n    { intros f g, apply subtype.eq,\n      change s.attach.sum (\u03bb i, (f i + g i) \u2022 _) = _,\n      simp only [add_smul, finset.sum_add_distrib], refl },\n    { intros c f, apply subtype.eq,\n      change s.attach.sum (\u03bb i, (c \u2022 f i) \u2022 _) = _,\n      simp only [smul_eq_mul, mul_smul],\n      exact finset.sum_hom _ } },\n  rw linear_map.range_eq_top,\n  rintro \u27e8n, hn\u27e9, change n \u2208 N at hn,\n  rw [\u2190 hs, mem_span_iff_lc] at hn,\n  rcases hn with \u27e8l, hl1, hl2\u27e9,\n  refine \u27e8\u03bb x, l x.1, subtype.eq _\u27e9,\n  change s.attach.sum (\u03bb i, l i.1 \u2022 i.1) = n,\n  rw [@finset.sum_attach M M s _ (\u03bb i, l i \u2022 i), \u2190 hl2,\n      lc.total_apply, finsupp.sum, eq_comm],\n  refine finset.sum_subset hl1 (\u03bb x _ hx, _),\n  rw [finsupp.not_mem_support_iff.1 hx, zero_smul]\nend\n\ntheorem is_noetherian_ring_of_surjective (R) [comm_ring R] (S) [comm_ring S]\n  (f : R \u2192 S) [is_ring_hom f] (hf : function.surjective f)\n  [H : is_noetherian_ring R] : is_noetherian_ring S :=\nbegin\n  unfold is_noetherian_ring at H \u22a2,\n  rw is_noetherian_iff_well_founded at H \u22a2,\n  convert order_embedding.well_founded (order_embedding.rsymm (ideal.lt_order_embedding_of_surjective f hf)) H\nend\n\ninstance is_noetherian_ring_range {R} [comm_ring R] {S} [comm_ring S] (f : R \u2192 S) [is_ring_hom f]\n  [is_noetherian_ring R] : is_noetherian_ring (set.range f) :=\n@is_noetherian_ring_of_surjective R _ (set.range f) _ (\u03bb x, \u27e8f x, x, rfl\u27e9)\n  (\u27e8subtype.eq (is_ring_hom.map_one f),\n    \u03bb _ _, subtype.eq (is_ring_hom.map_mul f),\n    \u03bb _ _, subtype.eq (is_ring_hom.map_add f)\u27e9)\n  (\u03bb \u27e8x, y, hy\u27e9, \u27e8y, subtype.eq hy\u27e9) _\n\ntheorem is_noetherian_ring_of_ring_equiv (R) [comm_ring R] {S} [comm_ring S]\n  (f : R \u2243r S) [is_noetherian_ring R] : is_noetherian_ring S :=\nis_noetherian_ring_of_surjective R S f.1 f.1.surjective\n\nnamespace is_noetherian_ring\n\nvariables {\u03b1 : Type*} [integral_domain \u03b1] [is_noetherian_ring \u03b1]\nopen associates nat\n\nlocal attribute [elab_as_eliminator] well_founded.fix\n\nlemma well_founded_dvd_not_unit : well_founded (\u03bb a b : \u03b1, a \u2260 0 \u2227 \u2203 x, \u00acis_unit x \u2227 b = a * x ) :=\nby simp only [ideal.span_singleton_lt_span_singleton.symm];\n   exact inv_image.wf (\u03bb a, ideal.span ({a} : set \u03b1)) well_founded_submodule_gt\n\nlemma exists_irreducible_factor {a : \u03b1} (ha : \u00ac is_unit a) (ha0 : a \u2260 0) :\n  \u2203 i, irreducible i \u2227 i \u2223 a :=\n(irreducible_or_factor a ha).elim (\u03bb hai, \u27e8a, hai, dvd_refl _\u27e9)\n  (well_founded.fix\n    well_founded_dvd_not_unit\n    (\u03bb a ih ha ha0 \u27e8x, y, hx, hy, hxy\u27e9,\n      have hx0 : x \u2260 0, from \u03bb hx0, ha0 (by rw [\u2190 hxy, hx0, zero_mul]),\n      (irreducible_or_factor x hx).elim\n        (\u03bb hxi, \u27e8x, hxi, hxy \u25b8 by simp\u27e9)\n        (\u03bb hxf, let \u27e8i, hi\u27e9 := ih x \u27e8hx0, y, hy, hxy.symm\u27e9 hx hx0 hxf in\n          \u27e8i, hi.1, dvd.trans hi.2 (hxy \u25b8 by simp)\u27e9)) a ha ha0)\n\n@[elab_as_eliminator] lemma irreducible_induction_on {P : \u03b1 \u2192 Prop} (a : \u03b1)\n  (h0 : P 0) (hu : \u2200 u : \u03b1, is_unit u \u2192 P u)\n  (hi : \u2200 a i : \u03b1, a \u2260 0 \u2192 irreducible i \u2192 P a \u2192 P (i * a)) :\n  P a :=\nby haveI := classical.dec; exact\nwell_founded.fix well_founded_dvd_not_unit\n  (\u03bb a ih, if ha0 : a = 0 then ha0.symm \u25b8 h0\n    else if hau : is_unit a then hu a hau\n    else let \u27e8i, hii, \u27e8b, hb\u27e9\u27e9 := exists_irreducible_factor hau ha0 in\n      have hb0 : b \u2260 0, from \u03bb hb0, by simp * at *,\n      hb.symm \u25b8 hi _ _ hb0 hii (ih _ \u27e8hb0, i,\n        hii.1, by rw [hb, mul_comm]\u27e9))\n  a\n\nlemma exists_factors (a : \u03b1) : a \u2260 0 \u2192\n  \u2203f:multiset \u03b1, (\u2200b\u2208f, irreducible b) \u2227 associated a f.prod :=\nis_noetherian_ring.irreducible_induction_on a\n  (\u03bb h, (h rfl).elim)\n  (\u03bb u hu _, \u27e80, by simp [associated_one_iff_is_unit, hu]\u27e9)\n  (\u03bb a i ha0 hii ih hia0,\n    let \u27e8s, hs\u27e9 := ih ha0 in\n    \u27e8i::s, \u27e8by clear _let_match; finish,\n      by rw multiset.prod_cons;\n        exact associated_mul_mul (by refl) hs.2\u27e9\u27e9)\n\nend is_noetherian_ring\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/ring_theory/noetherian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7167090091477404}}
{"text": "/-\n  The lemmas in this file may be soon be in mathlib, if not already\n-/\n\nimport data.list.basic\nimport data.int.basic\nimport tactic.ring\nimport tactic.linarith\n\nopen list nat int\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n\nlemma reverse_range'_map_range' (a b : \u2115) : reverse (range' a (b+1-a)) = map (\u03bb i, a+b-i) (range' a (b+1-a)) :=\nbegin\n  rw [reverse_range', range'_eq_map_range, list.map_map],\n  apply map_congr, intros i H,\n  simp at *,\n  rw [nat.add_sub_add_left, nat.add_sub_cancel'], {refl},\n  apply le_of_not_le (\u03bb h, _),\n  rw sub_eq_zero_of_le h at H,\n  exact not_lt_zero _ H\nend\n\nlemma filter_ext {\u03b1 : Type*} {r: list \u03b1} (P P') [decidable_pred P] [decidable_pred P']\n  (HP : \u2200 i \u2208 r, P i = P' i) : filter P r = filter P' r :=\nbegin\n  induction r with h t IH,\n  { simp },\n  { have HPh : P h = P' h := HP h (by simp),\n    have : \u2200 (i : \u03b1), i \u2208 t \u2192 P i = P' i,\n    { intros i i_t,\n      exact (HP i $ by simp [i_t]) },\n    by_cases H : P h,\n    { have H' : P' h := HPh \u25b8 H,\n      simp [H, H', IH this] },\n    { have H' : \u00ac P' h := HPh \u25b8 H,\n      simp [H, H', IH this] } }\nend\n\nlemma foldr_congr' {\u03b1 : Type*} {\u03b2 : Type*} {l : list \u03b1} (f f' : \u03b1 \u2192 \u03b2 \u2192 \u03b2) (s : \u03b2)\n  (H : \u2200 a \u2208 l, \u2200 b : \u03b2, f a b = f' a b) : foldr f s l = foldr f' s l :=\nby induction l; simp * {contextual := tt}\n\nlemma range'_add_map (a b k : \u2115) : range' (a+k) b = map (\u03bb x, x + k) (range' a b) :=\nbegin\n  revert a,\n  induction b with b IH; intro a,\n  { refl },\n  { simpa using (IH $ a + 1) }\nend\n\nlemma range'_sub_map (a b k : \u2115) : range' a b = map (\u03bb x, x - k) (range' (a+k) b) :=\nbegin\n  suffices : (\u03bb (x : \u2115), x - k) \u2218 (\u03bb (x : \u2115), x + k) = id,\n  { rw [range'_add_map, list.map_map, this, map_id] },\n  { funext, simp [nat.add_sub_cancel_left] }\nend\n\n\nlemma filter_map_comm {I : Type*} {J : Type*} (f : I \u2192 J) (P : J \u2192 Prop) (r: list I) [decidable_pred P] :\n  filter P (map f r) = map f (filter (P \u2218 f) r) :=\nbegin\n  induction r with h _ IH,\n  { simp },\n  { by_cases H : P (f h) ; simp [filter_cons_of_pos, filter_cons_of_neg, H, IH] }\nend\n\nlemma list.eq_nil_iff_not_mem {\u03b1 : Type*} (l : list \u03b1) : l = [] \u2194 \u2200 x, x \u2209 l :=\n\u27e8\u03bb h, by simp[h],\n  begin\n    intro H,\n    cases l with h t,\n    refl,\n    exfalso,\n    specialize H h,\n    have : h \u2208 list.cons h t, by simp,\n    exact H this\n  end\u27e9\n\nlemma list.range_eq_nil (n : \u2115) : list.range n = [] \u2194 n = 0 :=\nbegin\n  rw list.eq_nil_iff_not_mem,\n  simp [mem_range],\n  split ; intro h,\n  { exact eq_zero_of_le_zero (h 0) },\n  { rw h,\n    exact nat.zero_le }\nend\n\n@[simp]\nlemma to_nat_zero : to_nat 0 = 0 := rfl\n\nlemma to_nat_eq_zero (a) : to_nat a = 0 \u2194 a \u2264 0 :=\nbegin\n  induction a with n,\n  { change n = 0 \u2194 of_nat n \u2264 0,\n    split ; intro h,\n    { rw h,\n      refl },\n    { apply eq_zero_of_le_zero,\n      rwa \u2190coe_nat_le_coe_nat_iff n 0 } },\n  { simp[to_nat] },\nend\n\nlemma to_nat_sub_eq_zero (a b : \u2124) : to_nat (b - a) = 0 \u2194 b \u2264 a :=\nby rw [\u2190sub_nonpos, to_nat_eq_zero]\n\nlemma int.range_eq_nil (a b) : int.range a b = [] \u2194 b \u2264 a :=\nby unfold int.range ; rw [list.map_eq_nil, list.range_eq_nil, to_nat_sub_eq_zero]\n\nlemma int.range_shift (a b k) : int.range (a+k) (b+k) = map (\u03bb x, x+k) (int.range a b) :=\nbegin\n  unfold int.range,\n  rw [list.map_map, show b + k - (a + k) = b - a , by ring],\n  congr,\n  ext n,\n  simp\nend\n\nlemma reverse_int_range_map_int_range (a b) : reverse (int.range a b) = map (\u03bb i, a+b-i-(1 : \u2124)) (int.range a b) :=\nbegin\n  by_cases h : a \u2264 b,\n  { unfold int.range,\n    rw [\u2190list.map_reverse, range_eq_range', reverse_range'],\n    repeat { rw list.map_map },\n    change map (\u03bb (x : \u2115), a + \u2191(0 + to_nat (b - a) - 1 - x)) (range (to_nat (b - a))) =\n      map (\u03bb (x : \u2115), a + b - (a + x) - 1) (range' 0 (to_nat (b - a))),\n    rw [zero_add, range_eq_range'],\n    apply map_congr,\n    intros n n_in,\n    have n_lt := (list.mem_range'.1 n_in).right,\n    rw zero_add at n_lt,\n    have key : \u2191(to_nat (b - a) - 1 - n) = b - a - 1 - n,\n    { rw [nat.sub_sub, int.coe_nat_sub, to_nat_of_nonneg (sub_nonneg_of_le h), int.coe_nat_add],\n      simp, \n      linarith },\n    rw key,\n    ring },\n   { rw (int.range_eq_nil a b).2 (le_of_not_le h),\n     simp }\nend\n\nlemma to_nat_succ {a : \u2124} (h : 0 \u2264 a) : to_nat a + 1 = to_nat (a+1) :=\nbegin\n  cases a,\n  { refl },\n  { exfalso,\n    exact h }\nend\n\nlemma int_range_eq_concat {a b} (h : a < b) : int.range a b = concat (int.range a (b-1)) (b-1) :=\nbegin\n  unfold int.range,\n  have h' : 0 \u2264 b - a - 1, by have := add_one_le_of_lt h ; linarith,\n  have : b - 1 = (\u03bb (r : \u2115), a + \u2191r) (to_nat (b - a-1)),\n  { change b - 1 = a + \u2191(to_nat (b - a - 1)),\n    rw to_nat_of_nonneg h',\n    ring },\n  rw [this, \u2190map_concat],\n  congr,\n  simp only [function.comp_app],\n  rw [to_nat_of_nonneg h', concat_eq_append, show a + (b - a - 1) - a = b - a - 1, by simp],\n  convert list.range_concat _,\n  rw to_nat_succ h',\n  congr,\n  ring\nend\n\n@[simp]\nprotected lemma int.length_range (a b) : length (int.range a b) = to_nat (b-a) :=\nby unfold int.range ; rw [length_map, length_range]\n\n@[simp]\nlemma nth_le_int_range (a b n h) : nth_le (int.range a b) n h = a + n :=\nbegin\n  unfold int.range,\n  rw nth_le_map,\n  { simp },\n  { simpa using h }\nend\n\n@[simp]\nlemma filter_mem {\u03b1 : Type*} (l : list \u03b1) [decidable_pred (\u03bb i, i \u2208 l)] :\n  filter (\u03bb i, i \u2208 l) l = l :=\nby simp [filter_eq_self.2]\n\n@[simp]\nlemma filter_true {\u03b1 : Type*} (l : list \u03b1) : filter (\u03bb i, true) l = l :=\nby simp [filter_eq_self.2]\n\nlemma nth_le_cons {\u03b1 : Type*} (a : \u03b1) (t n h) :\n  nth_le (a :: t) (n+1) h = nth_le t n (lt_of_succ_lt_succ h) := rfl", "meta": {"author": "PatrickMassot", "repo": "bigop", "sha": "af53ad615b619e3c05fe119f98f939ff010f7e6d", "save_path": "github-repos/lean/PatrickMassot-bigop", "path": "github-repos/lean/PatrickMassot-bigop/bigop-af53ad615b619e3c05fe119f98f939ff010f7e6d/src/pending_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7167090018627194}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.sqrt\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\nnamespace int\n\n\n/-- `sqrt n` is the square root of an integer `n`. If `n` is not a\n  perfect square, and is positive, it returns the largest `k:\u2124` such\n  that `k*k \u2264 n`. If it is negative, it returns 0. For example,\n  `sqrt 2 = 1` and `sqrt 1 = 1` and `sqrt (-1) = 0` -/\ndef sqrt (n : \u2124) : \u2124 := \u2191(nat.sqrt (to_nat n))\n\ntheorem sqrt_eq (n : \u2124) : sqrt (n * n) = \u2191(nat_abs n) := sorry\n\ntheorem exists_mul_self (x : \u2124) : (\u2203 (n : \u2124), n * n = x) \u2194 sqrt x * sqrt x = x := sorry\n\ntheorem sqrt_nonneg (n : \u2124) : 0 \u2264 sqrt n := coe_nat_nonneg (nat.sqrt (to_nat n))\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/int/sqrt_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.7166677673120406}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\n! This file was ported from Lean 3 source module data.pnat.xgcd\n! leanprover-community/mathlib commit 6afc9b06856ad973f6a2619e3e8a0a8d537a58f2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Tactic.Ring\nimport Mathlib.Data.PNat.Prime\n\n/-!\n# Euclidean algorithm for \u2115\n\nThis file sets up a version of the Euclidean algorithm that only works with natural numbers.\nGiven `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold:\n* `a = (w + x) d`\n* `b = (y + z) d`\n* `w * z = x * y + 1`\n`d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime.\n\nThis story is closely related to the structure of SL\u2082(\u2115) (as a free monoid on two generators) and\nthe theory of continued fractions.\n\n## Main declarations\n\n* `XgcdType`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp`\n  `zp`, `ap`, `bp` are the variables getting changed through the algorithm.\n* `IsSpecial`: States `wp * zp = x * y + 1`\n* `IsReduced`: States `ap = a \u2227 bp = b`\n\n## Notes\n\nSee `Nat.Xgcd` for a very similar algorithm allowing values in `\u2124`.\n-/\n\n\nopen Nat\n\nnamespace PNat\n\n/-- A term of `XgcdType` is a system of six naturals.  They should\n be thought of as representing the matrix\n [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]\n together with the vector [a, b] = [ap + 1, bp + 1].\n-/\nstructure XgcdType where\n  /-- `wp` is a variable which changes through the algorithm. -/\n  wp : \u2115\n  /-- `x` satisfies `a / d = w + x` at the final step. -/\n  x : \u2115\n  /-- `y` satisfies `b / d = z + y` at the final step. -/\n  y : \u2115\n  /-- `zp` is a variable which changes through the algorithm. -/\n  zp : \u2115\n  /-- `ap` is a variable which changes through the algorithm. -/\n  ap : \u2115\n  /-- `bp` is a variable which changes through the algorithm. -/\n  bp : \u2115\n  deriving Inhabited\n#align pnat.xgcd_type PNat.XgcdType\n\nnamespace XgcdType\n\nvariable (u : XgcdType)\n\ninstance : SizeOf XgcdType :=\n  \u27e8fun u => u.bp\u27e9\n\n/-- The `Repr` instance converts terms to strings in a way that\n reflects the matrix/vector interpretation as above. -/\ninstance : Repr XgcdType where\n  reprPrec\n  | g, _ => s!\"[[[ {repr (g.wp + 1)}, {(repr g.x)} ], [\" ++\n            s!\"{repr g.y}, {repr (g.zp + 1)}]], [\" ++\n            s!\"{repr (g.ap + 1)}, {repr (g.bp + 1)}]]\"\n\n/-- Another `mk` using \u2115 and \u2115+ -/\ndef mk' (w : \u2115+) (x : \u2115) (y : \u2115) (z : \u2115+) (a : \u2115+) (b : \u2115+) : XgcdType :=\n  mk w.val.pred x y z.val.pred a.val.pred b.val.pred\n#align pnat.xgcd_type.mk' PNat.XgcdType.mk'\n\n/-- `w = wp + 1` -/\ndef w : \u2115+ :=\n  succPNat u.wp\n#align pnat.xgcd_type.w PNat.XgcdType.w\n\n/-- `z = zp + 1` -/\ndef z : \u2115+ :=\n  succPNat u.zp\n#align pnat.xgcd_type.z PNat.XgcdType.z\n\n/-- `a = ap + 1` -/\ndef a : \u2115+ :=\n  succPNat u.ap\n#align pnat.xgcd_type.a PNat.XgcdType.a\n\n/-- `b = bp + 1` -/\ndef b : \u2115+ :=\n  succPNat u.bp\n#align pnat.xgcd_type.b PNat.XgcdType.b\n\n/-- `r = a % b`: remainder -/\ndef r : \u2115 :=\n  (u.ap + 1) % (u.bp + 1)\n#align pnat.xgcd_type.r PNat.XgcdType.r\n\n/-- `q = ap / bp`: quotient -/\ndef q : \u2115 :=\n  (u.ap + 1) / (u.bp + 1)\n#align pnat.xgcd_type.q PNat.XgcdType.q\n\n/-- `qp = q - 1` -/\ndef qp : \u2115 :=\n  u.q - 1\n#align pnat.xgcd_type.qp PNat.XgcdType.qp\n\n/-- The map `v` gives the product of the matrix\n [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]\n and the vector [a, b] = [ap + 1, bp + 1].  The map\n `vp` gives [sp, tp] such that v = [sp + 1, tp + 1].\n-/\ndef vp : \u2115 \u00d7 \u2115 :=\n  \u27e8u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp, u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp\u27e9\n#align pnat.xgcd_type.vp PNat.XgcdType.vp\n\n/-- `v = [sp + 1, tp + 1]`, check `vp` -/\ndef v : \u2115 \u00d7 \u2115 :=\n  \u27e8u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.b\u27e9\n#align pnat.xgcd_type.v PNat.XgcdType.v\n\n/-- `succ\u2082 [t.1, t.2] = [t.1.succ, t.2.succ]` -/\ndef succ\u2082 (t : \u2115 \u00d7 \u2115) : \u2115 \u00d7 \u2115 :=\n  \u27e8t.1.succ, t.2.succ\u27e9\n#align pnat.xgcd_type.succ\u2082 PNat.XgcdType.succ\u2082\n\ntheorem v_eq_succ_vp : u.v = succ\u2082 u.vp := by\n  ext <;> dsimp [v, vp, w, z, a, b, succ\u2082] <;> (repeat' rw [Nat.succ_eq_add_one]; ring_nf)\n#align pnat.xgcd_type.v_eq_succ_vp PNat.XgcdType.v_eq_succ_vp\n\n/-- `IsSpecial` holds if the matrix has determinant one. -/\ndef IsSpecial : Prop :=\n  u.wp + u.zp + u.wp * u.zp = u.x * u.y\n#align pnat.xgcd_type.is_special PNat.XgcdType.IsSpecial\n\n/-- `IsSpecial'` is an alternative of `IsSpecial`. -/\ndef IsSpecial' : Prop :=\n  u.w * u.z = succPNat (u.x * u.y)\n#align pnat.xgcd_type.is_special' PNat.XgcdType.IsSpecial'\n\ntheorem isSpecial_iff : u.IsSpecial \u2194 u.IsSpecial' := by\n  dsimp [IsSpecial, IsSpecial']\n  let \u27e8wp, x, y, zp, ap, bp\u27e9 := u\n  constructor <;> intro h <;> simp [w, z, succPNat] at * <;>\n    simp only [\u2190 coe_inj, mul_coe, mk_coe] at *\n  . simp_all [\u2190 h, Nat.mul, Nat.succ_eq_add_one]; ring\n  . simp [Nat.succ_eq_add_one, Nat.mul_add, Nat.add_mul, \u2190 Nat.add_assoc] at h; rw [\u2190 h]; ring\n  -- Porting note: Old code has been removed as it was much more longer.\n#align pnat.xgcd_type.is_special_iff PNat.XgcdType.isSpecial_iff\n\n/-- `IsReduced` holds if the two entries in the vector are the\n same.  The reduction algorithm will produce a system with this\n property, whose product vector is the same as for the original\n system. -/\ndef IsReduced : Prop :=\n  u.ap = u.bp\n#align pnat.xgcd_type.is_reduced PNat.XgcdType.IsReduced\n\n/-- `IsReduced'` is an alternative of `IsReduced`. -/\ndef IsReduced' : Prop :=\n  u.a = u.b\n#align pnat.xgcd_type.is_reduced' PNat.XgcdType.IsReduced'\n\ntheorem isReduced_iff : u.IsReduced \u2194 u.IsReduced' :=\n  succPNat_inj.symm\n#align pnat.xgcd_type.is_reduced_iff PNat.XgcdType.isReduced_iff\n\n/-- `flip` flips the placement of variables during the algorithm. -/\ndef flip : XgcdType where\n  wp := u.zp\n  x := u.y\n  y := u.x\n  zp := u.wp\n  ap := u.bp\n  bp := u.ap\n#align pnat.xgcd_type.flip PNat.XgcdType.flip\n\n@[simp]\ntheorem flip_w : (flip u).w = u.z :=\n  rfl\n#align pnat.xgcd_type.flip_w PNat.XgcdType.flip_w\n\n@[simp]\ntheorem flip_x : (flip u).x = u.y :=\n  rfl\n#align pnat.xgcd_type.flip_x PNat.XgcdType.flip_x\n\n@[simp]\ntheorem flip_y : (flip u).y = u.x :=\n  rfl\n#align pnat.xgcd_type.flip_y PNat.XgcdType.flip_y\n\n@[simp]\ntheorem flip_z : (flip u).z = u.w :=\n  rfl\n#align pnat.xgcd_type.flip_z PNat.XgcdType.flip_z\n\n@[simp]\ntheorem flip_a : (flip u).a = u.b :=\n  rfl\n#align pnat.xgcd_type.flip_a PNat.XgcdType.flip_a\n\n@[simp]\ntheorem flip_b : (flip u).b = u.a :=\n  rfl\n#align pnat.xgcd_type.flip_b PNat.XgcdType.flip_b\n\ntheorem flip_isReduced : (flip u).IsReduced \u2194 u.IsReduced := by\n  dsimp [IsReduced, flip]\n  constructor <;> intro h <;> exact h.symm\n#align pnat.xgcd_type.flip_is_reduced PNat.XgcdType.flip_isReduced\n\ntheorem flip_isSpecial : (flip u).IsSpecial \u2194 u.IsSpecial := by\n  dsimp [IsSpecial, flip]\n  rw [mul_comm u.x, mul_comm u.zp, add_comm u.zp]\n#align pnat.xgcd_type.flip_is_special PNat.XgcdType.flip_isSpecial\n\ntheorem flip_v : (flip u).v = u.v.swap := by\n  dsimp [v]\n  ext\n  \u00b7 simp only\n    ring\n  \u00b7 simp only\n    ring\n#align pnat.xgcd_type.flip_v PNat.XgcdType.flip_v\n\n/-- Properties of division with remainder for a / b.  -/\ntheorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 :=\n  Nat.mod_add_div (u.ap + 1) (u.bp + 1)\n#align pnat.xgcd_type.rq_eq PNat.XgcdType.rq_eq\n\ntheorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 := by\n  by_cases hq : u.q = 0\n  \u00b7 let h := u.rq_eq\n    rw [hr, hq, mul_zero, add_zero] at h\n    cases h\n  \u00b7 exact (Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hq)).symm\n#align pnat.xgcd_type.qp_eq PNat.XgcdType.qp_eq\n\n/-- The following function provides the starting point for\n our algorithm.  We will apply an iterative reduction process\n to it, which will produce a system satisfying IsReduced.\n The gcd can be read off from this final system.\n-/\ndef start (a b : \u2115+) : XgcdType :=\n  \u27e80, 0, 0, 0, a - 1, b - 1\u27e9\n#align pnat.xgcd_type.start PNat.XgcdType.start\n\ntheorem start_isSpecial (a b : \u2115+) : (start a b).IsSpecial := by\n  dsimp [start, IsSpecial]\n#align pnat.xgcd_type.start_is_special PNat.XgcdType.start_isSpecial\n\ntheorem start_v (a b : \u2115+) : (start a b).v = \u27e8a, b\u27e9 := by\n  dsimp [start, v, XgcdType.a, XgcdType.b, w, z]\n  have : succ 0 = 1 := rfl\n  rw [this, one_mul, one_mul, zero_mul, zero_mul, zero_add, add_zero]\n  rw [\u2190 Nat.pred_eq_sub_one, \u2190 Nat.pred_eq_sub_one]\n  rw [Nat.succ_pred_eq_of_pos a.pos, Nat.succ_pred_eq_of_pos b.pos]\n#align pnat.xgcd_type.start_v PNat.XgcdType.start_v\n\n/-- `finish` happens when the reducing process ends. -/\ndef finish : XgcdType :=\n  XgcdType.mk u.wp ((u.wp + 1) * u.qp + u.x) u.y (u.y * u.qp + u.zp) u.bp u.bp\n#align pnat.xgcd_type.finish PNat.XgcdType.finish\n\ntheorem finish_isReduced : u.finish.IsReduced := by\n  dsimp [IsReduced]\n  rfl\n#align pnat.xgcd_type.finish_is_reduced PNat.XgcdType.finish_isReduced\n\ntheorem finish_isSpecial (hs : u.IsSpecial) : u.finish.IsSpecial := by\n  dsimp [IsSpecial, finish] at hs\u22a2\n  rw [add_mul _ _ u.y, add_comm _ (u.x * u.y), \u2190 hs]\n  ring\n#align pnat.xgcd_type.finish_is_special PNat.XgcdType.finish_isSpecial\n\ntheorem finish_v (hr : u.r = 0) : u.finish.v = u.v := by\n  let ha : u.r + u.b * u.q = u.a := u.rq_eq\n  rw [hr, zero_add] at ha\n  ext\n  \u00b7 change (u.wp + 1) * u.b + ((u.wp + 1) * u.qp + u.x) * u.b = u.w * u.a + u.x * u.b\n    have : u.wp + 1 = u.w := rfl\n    rw [this, \u2190 ha, u.qp_eq hr]\n    ring_nf\n  \u00b7 change u.y * u.b + (u.y * u.qp + u.z) * u.b = u.y * u.a + u.z * u.b\n    rw [\u2190 ha, u.qp_eq hr]\n    ring\n#align pnat.xgcd_type.finish_v PNat.XgcdType.finish_v\n\n/-- This is the main reduction step, which is used when u.r \u2260 0, or\n equivalently b does not divide a. -/\ndef step : XgcdType :=\n  XgcdType.mk (u.y * u.q + u.zp) u.y ((u.wp + 1) * u.q + u.x) u.wp u.bp (u.r - 1)\n#align pnat.xgcd_type.step PNat.XgcdType.step\n\n/-- We will apply the above step recursively.  The following result\n is used to ensure that the process terminates. -/\ntheorem step_wf (hr : u.r \u2260 0) : SizeOf.sizeOf u.step < SizeOf.sizeOf u := by\n  change u.r - 1 < u.bp\n  have h\u2080 : u.r - 1 + 1 = u.r := Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hr)\n  have h\u2081 : u.r < u.bp + 1 := Nat.mod_lt (u.ap + 1) u.bp.succ_pos\n  rw [\u2190 h\u2080] at h\u2081\n  exact lt_of_succ_lt_succ h\u2081\n#align pnat.xgcd_type.step_wf PNat.XgcdType.step_wf\n\ntheorem step_isSpecial (hs : u.IsSpecial) : u.step.IsSpecial := by\n  dsimp [IsSpecial, step] at hs\u22a2\n  rw [mul_add, mul_comm u.y u.x, \u2190 hs]\n  ring\n#align pnat.xgcd_type.step_is_special PNat.XgcdType.step_isSpecial\n\n/-- The reduction step does not change the product vector. -/\ntheorem step_v (hr : u.r \u2260 0) : u.step.v = u.v.swap := by\n  let ha : u.r + u.b * u.q = u.a := u.rq_eq\n  let hr : u.r - 1 + 1 = u.r := (add_comm _ 1).trans (add_tsub_cancel_of_le (Nat.pos_of_ne_zero hr))\n  ext\n  \u00b7 change ((u.y * u.q + u.z) * u.b + u.y * (u.r - 1 + 1) : \u2115) = u.y * u.a + u.z * u.b\n    rw [\u2190 ha, hr]\n    ring\n  \u00b7 change ((u.w * u.q + u.x) * u.b + u.w * (u.r - 1 + 1) : \u2115) = u.w * u.a + u.x * u.b\n    rw [\u2190 ha, hr]\n    ring\n#align pnat.xgcd_type.step_v PNat.XgcdType.step_v\n\n-- Porting note: removed 'have' and added decreasing_by to avoid lint errors\n/-- We can now define the full reduction function, which applies\n step as long as possible, and then applies finish. Note that the\n \"have\" statement puts a fact in the local context, and the\n equation compiler uses this fact to help construct the full\n definition in terms of well-founded recursion.  The same fact\n needs to be introduced in all the inductive proofs of properties\n given below. -/\ndef reduce (u : XgcdType) : XgcdType :=\n  dite (u.r = 0) (fun _ => u.finish) fun _h =>\n    flip (reduce u.step)\ndecreasing_by apply u.step_wf _h\n#align pnat.xgcd_type.reduce PNat.XgcdType.reduce\n\ntheorem reduce_a {u : XgcdType} (h : u.r = 0) : u.reduce = u.finish := by\n  rw [reduce]\n  exact if_pos h\n#align pnat.xgcd_type.reduce_a PNat.XgcdType.reduce_a\n\ntheorem reduce_b {u : XgcdType} (h : u.r \u2260 0) : u.reduce = u.step.reduce.flip := by\n  rw [reduce]\n  exact if_neg h\n#align pnat.xgcd_type.reduce_b PNat.XgcdType.reduce_b\n\ntheorem reduce_isReduced : \u2200 u : XgcdType, u.reduce.IsReduced\n  | u =>\n    dite (u.r = 0)\n      (fun h => by\n        rw [reduce_a h]\n        exact u.finish_isReduced)\n      fun h => by\n      have : SizeOf.sizeOf u.step < SizeOf.sizeOf u := u.step_wf h\n      rw [reduce_b h, flip_isReduced]\n      apply reduce_isReduced\n#align pnat.xgcd_type.reduce_reduced PNat.XgcdType.reduce_isReduced\n\ntheorem reduce_isReduced' (u : XgcdType) : u.reduce.IsReduced' :=\n  (isReduced_iff _).mp u.reduce_isReduced\n#align pnat.xgcd_type.reduce_reduced' PNat.XgcdType.reduce_isReduced'\n\ntheorem reduce_isSpecial : \u2200 u : XgcdType, u.IsSpecial \u2192 u.reduce.IsSpecial\n  | u =>\n    dite (u.r = 0)\n      (fun h hs => by\n        rw [reduce_a h]\n        exact u.finish_isSpecial hs)\n      fun h hs => by\n      have : SizeOf.sizeOf u.step < SizeOf.sizeOf u := u.step_wf h\n      rw [reduce_b h]\n      exact (flip_isSpecial _).mpr (reduce_isSpecial _ (u.step_isSpecial hs))\n#align pnat.xgcd_type.reduce_special PNat.XgcdType.reduce_isSpecial\n\ntheorem reduce_isSpecial' (u : XgcdType) (hs : u.IsSpecial) : u.reduce.IsSpecial' :=\n  (isSpecial_iff _).mp (u.reduce_isSpecial hs)\n#align pnat.xgcd_type.reduce_special' PNat.XgcdType.reduce_isSpecial'\n\ntheorem reduce_v : \u2200 u : XgcdType, u.reduce.v = u.v\n  | u =>\n    dite (u.r = 0) (fun h => by rw [reduce_a h, finish_v u h]) fun h =>\n      by\n      have : SizeOf.sizeOf u.step < SizeOf.sizeOf u := u.step_wf h\n      rw [reduce_b h, flip_v, reduce_v (step u), step_v u h, Prod.swap_swap]\n#align pnat.xgcd_type.reduce_v PNat.XgcdType.reduce_v\n\nend XgcdType\n\nsection gcd\n\nvariable (a b : \u2115+)\n\n/-- Extended Euclidean algorithm -/\ndef xgcd : XgcdType :=\n  (XgcdType.start a b).reduce\n#align pnat.xgcd PNat.xgcd\n\n/-- `gcdD a b = gcd a b` -/\ndef gcdD : \u2115+ :=\n  (xgcd a b).a\n#align pnat.gcd_d PNat.gcdD\n\n/-- Final value of `w` -/\ndef gcdW : \u2115+ :=\n  (xgcd a b).w\n#align pnat.gcd_w PNat.gcdW\n\n/-- Final value of `x` -/\ndef gcdX : \u2115 :=\n  (xgcd a b).x\n#align pnat.gcd_x PNat.gcdX\n\n/-- Final value of `y` -/\ndef gcdY : \u2115 :=\n  (xgcd a b).y\n#align pnat.gcd_y PNat.gcdY\n\n/-- Final value of `z` -/\ndef gcdZ : \u2115+ :=\n  (xgcd a b).z\n#align pnat.gcd_z PNat.gcdZ\n\n/-- Final value of `a / d` -/\ndef gcdA' : \u2115+ :=\n  succPNat ((xgcd a b).wp + (xgcd a b).x)\n#align pnat.gcd_a' PNat.gcdA'\n\n/-- Final value of `b / d` -/\ndef gcdB' : \u2115+ :=\n  succPNat ((xgcd a b).y + (xgcd a b).zp)\n#align pnat.gcd_b' PNat.gcdB'\n\ntheorem gcdA'_coe : (gcdA' a b : \u2115) = gcdW a b + gcdX a b :=\n  by\n  dsimp [gcdA', gcdX, gcdW, XgcdType.w]\n  rw [Nat.succ_eq_add_one, Nat.succ_eq_add_one, add_right_comm]\n#align pnat.gcd_a'_coe PNat.gcdA'_coe\n\ntheorem gcdB'_coe : (gcdB' a b : \u2115) = gcdY a b + gcdZ a b := by\n  dsimp [gcdB', gcdY, gcdZ, XgcdType.z]\n  rw [Nat.succ_eq_add_one, Nat.succ_eq_add_one, add_assoc]\n#align pnat.gcd_b'_coe PNat.gcdB'_coe\n\ntheorem gcd_props :\n    let d := gcdD a b\n    let w := gcdW a b\n    let x := gcdX a b\n    let y := gcdY a b\n    let z := gcdZ a b\n    let a' := gcdA' a b\n    let b' := gcdB' a b\n    w * z = succPNat (x * y) \u2227\n      a = a' * d \u2227\n        b = b' * d \u2227\n          z * a' = succPNat (x * b') \u2227\n            w * b' = succPNat (y * a') \u2227 (z * a : \u2115) = x * b + d \u2227 (w * b : \u2115) = y * a + d := by\n  intros d w x y z a' b'\n  let u := XgcdType.start a b\n  let ur := u.reduce\n\n  have _ : d = ur.a := rfl\n  have hb : d = ur.b := u.reduce_isReduced'\n  have ha' : (a' : \u2115) = w + x := gcdA'_coe a b\n  have hb' : (b' : \u2115) = y + z := gcdB'_coe a b\n  have hdet : w * z = succPNat (x * y) := u.reduce_isSpecial' rfl\n  constructor\n  exact hdet\n  have hdet' : (w * z : \u2115) = x * y + 1 := by rw [\u2190 mul_coe, hdet, succPNat_coe]\n  have _ : u.v = \u27e8a, b\u27e9 := XgcdType.start_v a b\n  let hv : Prod.mk (w * d + x * ur.b : \u2115) (y * d + z * ur.b : \u2115) = \u27e8a, b\u27e9 :=\n    u.reduce_v.trans (XgcdType.start_v a b)\n  rw [\u2190 hb, \u2190 add_mul, \u2190 add_mul, \u2190 ha', \u2190 hb'] at hv\n  have ha'' : (a : \u2115) = a' * d := (congr_arg Prod.fst hv).symm\n  have hb'' : (b : \u2115) = b' * d := (congr_arg Prod.snd hv).symm\n  constructor\n  exact eq ha''\n  constructor\n  exact eq hb''\n  have hza' : (z * a' : \u2115) = x * b' + 1 := by\n    rw [ha', hb', mul_add, mul_add, mul_comm (z : \u2115), hdet']\n    ring\n  have hwb' : (w * b' : \u2115) = y * a' + 1 := by\n    rw [ha', hb', mul_add, mul_add, hdet']\n    ring\n  constructor\n  \u00b7 apply eq\n    rw [succPNat_coe, Nat.succ_eq_add_one, mul_coe, hza']\n  constructor\n  \u00b7 apply eq\n    rw [succPNat_coe, Nat.succ_eq_add_one, mul_coe, hwb']\n  rw [ha'', hb'']\n  repeat' rw [\u2190 @mul_assoc]\n  rw [hza', hwb']\n  constructor <;> ring\n#align pnat.gcd_props PNat.gcd_props\n\ntheorem gcd_eq : gcdD a b = gcd a b :=\n  by\n  rcases gcd_props a b with \u27e8_, h\u2081, h\u2082, _, _, h\u2085, _\u27e9\n  apply dvd_antisymm\n  \u00b7 apply dvd_gcd\n    exact Dvd.intro (gcdA' a b) (h\u2081.trans (mul_comm _ _)).symm\n    exact Dvd.intro (gcdB' a b) (h\u2082.trans (mul_comm _ _)).symm\n  \u00b7 have h\u2087 : (gcd a b : \u2115) \u2223 gcdZ a b * a := (Nat.gcd_dvd_left a b).trans (dvd_mul_left _ _)\n    have h\u2088 : (gcd a b : \u2115) \u2223 gcdX a b * b := (Nat.gcd_dvd_right a b).trans (dvd_mul_left _ _)\n    rw [h\u2085] at h\u2087\n    rw [dvd_iff]\n    exact (Nat.dvd_add_iff_right h\u2088).mpr h\u2087\n#align pnat.gcd_eq PNat.gcd_eq\n\ntheorem gcd_det_eq : gcdW a b * gcdZ a b = succPNat (gcdX a b * gcdY a b) :=\n  (gcd_props a b).1\n#align pnat.gcd_det_eq PNat.gcd_det_eq\n\n\n\ntheorem gcd_b_eq : b = gcdB' a b * gcd a b :=\n  gcd_eq a b \u25b8 (gcd_props a b).2.2.1\n#align pnat.gcd_b_eq PNat.gcd_b_eq\n\ntheorem gcd_rel_left' : gcdZ a b * gcdA' a b = succPNat (gcdX a b * gcdB' a b) :=\n  (gcd_props a b).2.2.2.1\n#align pnat.gcd_rel_left' PNat.gcd_rel_left'\n\ntheorem gcd_rel_right' : gcdW a b * gcdB' a b = succPNat (gcdY a b * gcdA' a b) :=\n  (gcd_props a b).2.2.2.2.1\n#align pnat.gcd_rel_right' PNat.gcd_rel_right'\n\ntheorem gcd_rel_left : (gcdZ a b * a : \u2115) = gcdX a b * b + gcd a b :=\n  gcd_eq a b \u25b8 (gcd_props a b).2.2.2.2.2.1\n#align pnat.gcd_rel_left PNat.gcd_rel_left\n\ntheorem gcd_rel_right : (gcdW a b * b : \u2115) = gcdY a b * a + gcd a b :=\n  gcd_eq a b \u25b8 (gcd_props a b).2.2.2.2.2.2\n#align pnat.gcd_rel_right PNat.gcd_rel_right\n\nend gcd\n\nend PNat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/PNat/Xgcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7166677513187506}}
{"text": "import combinatorics.simple_graph.coloring\n\n\n--OUTPUT 1\ntheorem graph_2_colorable {G : Type*} [graph G] : (\u2203 c : G \u2192 \u2124, c G = 2) \u2194 \u2203 V1 V2 : set G, bipartite_graph G V1 V2 :=\nbegin\n  -- ...\nend\n\n--OUTPUT 2\ntheorem bipartite_graph_two_colorable {G : Type} [graph G] : 2-colorable G \u2194 bipartite G :=\nbegin\n  -- $G$ is 2-colorable, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color.\n  have h1 : 2-colorable G \u2192 \u2203 (R : set G) (B : set G), \u2200 v : G, v \u2208 R \u2228 v \u2208 B \u2227 \u2200 e : edge G, (e.1 \u2208 R \u2227 e.2 \u2208 B) \u2228 (e.1 \u2208 B \u2227 e.2 \u2208 R), from by auto [two_colorable_def],\n\n  -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n  have h2 : 2-colorable G \u2192 \u2203 (A : set G) (B : set G), \u2200 v : G, v \u2208 A \u2228 v \u2208 B \u2227 \u2200 e : edge G, (e.1 \u2208 A \u2227 e.2 \u2208 B) \u2228 (e.1 \u2208 B \u2227 e.2 \u2208 A), from by auto [two_colorable_def, h1],\n\n  -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n  have h3 : 2-colorable G \u2192 \u2203 (A : set G) (B : set G), \u2200 v : G, v \u2208 A \u2228 v \u2208 B \u2227 \u2200 e : edge G, (e.1 \u2208 A \u2227 e.2 \u2208 B) \u2228 (e.1 \u2208 B \u2227 e.2 \u2208 A) \u2227 \u2200 e : edge G, e.1 \u2209 A \u2228 e.2 \u2209 A \u2227 e.1 \u2209 B \u2228 e.2 \u2209 B, from by auto [h2, two_colorable_def],\n\n  -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  have h4 : 2-colorable G \u2192 bipartite G, from by auto [h3, bipartite_def],\n\n  show 2-colorable G \u2194 bipartite G, from by auto [h4, two_colorable_def, bipartite_def],\nend\n\n--OUTPUT 3\ntheorem bipartite_graph_is_two_colorable (G : Type*) [graph G] : \u2200 A B : set G,\n  is_bipartite_graph_aux G A B \u2194 is_two_colorable_graph_aux G A B :=\nbegin\n  -- Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  assume (A : set G) (B : set G),\n  split,\n    -- Suppose $G$ is 2-colorable, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color.\n    assume h1 : is_two_colorable_graph_aux G A B,\n    -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n    -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n    have h2 : \u2200 x \u2208 A, \u2200 y \u2208 A, x \u2260 y \u2192 \u00ac E x y, from by auto [h1.2],\n    have h3 : \u2200 x \u2208 B, \u2200 y \u2208 B, x \u2260 y \u2192 \u00ac E x y, from by auto [h1.3],\n    -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n    have h4 : \u2200 x \u2208 A, \u2200 y \u2208 B, x \u2260 y \u2192 E x y, from by auto [h1.1],\n\n    show is_bipartite_graph_aux G A B, from by auto [is_bipartite_graph_aux, h2, h3, h4],\n\n    -- Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$. Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n    assume h1 : is_bipartite_graph_aux G A B,\n    -- Suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$.\n    -- Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n    -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n    have h2 : \u2200 x \u2208 A, \u2200 y \u2208 A, x \u2260 y \u2192 \u00ac E x y, from by auto [h1.1],\n    have h3 : \u2200 x \u2208 B, \u2200 y \u2208 B, x \u2260 y \u2192 \u00ac E x y, from by auto [h1.2],\n    -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n    have h4 : \u2200 x \u2208 A, \u2200 y \u2208 B, x \u2260 y \u2192 E x y, from by auto [h1.3],\n\n    show is_two_colorable_graph_aux G A B, from by auto [is_two_colorable_graph_aux, h2, h3, h4],\nend\n\n--OUTPUT 4\ntheorem bipartite_graph_two_colorable {G : Type*} : G.two_colorable \u2194 G.bipartite :=\nbegin\n  -- Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue,\n  -- and no edge will have both endpoints colored the same color.\n  assume h1 : G.two_colorable,\n  -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n  have h2 : \u2203 A B : set G.V, (\u2200 v : G.V, v \u2208 A \u2228 v \u2208 B) \u2227 (\u2200 v : G.V, v \u2208 A \u2192 \u00ac (v \u2208 B)) \u2227 (\u2200 v : G.V, v \u2208 B \u2192 \u00ac (v \u2208 A)) \u2227 (\u2200 v w : G.V, (v \u2260 w) \u2192 (v \u2208 A \u2227 w \u2208 B) \u2228 (v \u2208 B \u2227 w \u2208 A)), from by auto using [h1, two_colorable.def],\n  -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n  have h3 : \u2200 v w : G.V, v \u2208 A \u2192 w \u2208 A \u2192 (v, w) \u2209 G.E, from by auto using [h2],\n  have h4 : \u2200 v w : G.V, v \u2208 B \u2192 w \u2208 B \u2192 (v, w) \u2209 G.E, from by auto using [h2],\n  -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  have h5 : \u2200 v w : G.V, (v, w) \u2208 G.E \u2192 (v \u2208 A \u2227 w \u2208 B) \u2228 (v \u2208 B \u2227 w \u2208 A), from by auto using [h2, h3, h4],\n  show G.bipartite, from by auto using [bipartite.def, h2, h5],\n  -- Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$\n  -- every edge has one endpoint in $V_{1}$ and the other in $V_{2}$.\n  assume h1 : G.bipartite,\n  have h2 : \u2203 A B : set G.V, (\u2200 v : G.V, v \u2208 A \u2228 v \u2208 B) \u2227 (\u2200 v : G.V, v \u2208 A \u2192 \u00ac (v \u2208 B)) \u2227 (\u2200 v : G.V, v \u2208 B \u2192 \u00ac (v \u2208 A)) \u2227 (\u2200 v w : G.V, (v \u2260 w) \u2192 (v \u2208 A \u2227 w \u2208 B) \u2228 (v \u2208 B \u2227 w \u2208 A)), from by auto using [h1, bipartite.def],\n  -- Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring,\n  have h3 : \u2200 v : G.V, v \u2208 A \u2192 (\u2200 w : G.V, (v, w) \u2208 G.E \u2192 w \u2209 A), from by auto using [h2],\n  have h4 : \u2200 v : G.V, v \u2208 B \u2192 (\u2200 w : G.V, (v, w) \u2208 G.E \u2192 w \u2209 B), from by auto using [h2],\n  -- so $G$ is 2-colorable.\n  show G.two_colorable, from by auto using [two_colorable.def, h2, h3, h4],\nend\n\n--OUTPUT 5\ntheorem bipartite_if_two_colorable {G : Type*} [graph G] (h1 : is_bipartite G) : is_two_colorable G :=\nbegin\n  -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n  have h2 : \u2203 A B : set G, is_coloring G A B, from by auto [h1],\n  obtain A B h3, from h2,\n  -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n  have h4 : \u2200 (u v : G), u \u2208 A \u2192 v \u2208 A \u2192 \u00ac edge G u v, from by auto [h3],\n  have h5 : \u2200 (u v : G), u \u2208 B \u2192 v \u2208 B \u2192 \u00ac edge G u v, from by auto [h3],\n  -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  show is_bipartite G, from by auto [h1, h3, h4, h5],\nend\n\n--OUTPUT 6\ntheorem bipartite_iff_two_colorable (G : Type*) [graph G] : bipartite G \u2194 two_colorable G :=\nbegin\n  -- There exists a subset $A$ of vertices of $G$ such that there are no edges within $A$ and all edges with one endpoint in $A$ have the other endpoint in $B$\n  have h1 : bipartite G \u2192 \u2203 A : set G, no_edges_in A \u2227 (\u2200 (a : G) (b : G), a \u2208 A \u2227 (a,b) \u2208 E G \u2192 b \u2208 B G), from by auto [bipartite],\n  -- There exists a subset $B$ of vertices of $G$ such that there are no edges within $B$ and all edges with one endpoint in $B$ have the other endpoint in $A$\n  have h2 : bipartite G \u2192 \u2203 B : set G, no_edges_in B \u2227 (\u2200 (a : G) (b : G), a \u2208 B \u2227 (a,b) \u2208 E G \u2192 b \u2208 A G), from by auto [bipartite],\n\n  -- If $G$ is 2-colorable, then we can color every vertex either red or blue, and no edge will have both endpoints colored the same color\n  have h3 : two_colorable G \u2192 \u2203 (r : set G) (b : set G), no_edges_in r \u2227 no_edges_in b \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 r \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 b \u2227 b \u2208 b \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 b \u2192 (a,b) \u2208 E G), from by auto [two_colorable],\n\n  -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue\n  have h4 : two_colorable G \u2192 \u2200 (r : set G) (b : set G), no_edges_in r \u2227 no_edges_in b \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 r \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 b \u2227 b \u2208 b \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 b \u2192 (a,b) \u2208 E G) \u2192 \u2203 A : set G, no_edges_in A \u2227 (\u2200 (a : G) (b : G), a \u2208 A \u2227 (a,b) \u2208 E G \u2192 b \u2208 B G), from by auto [h3],\n\n  -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$\n  have h5 : two_colorable G \u2192 \u2200 (r : set G) (b : set G), no_edges_in r \u2227 no_edges_in b \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 r \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 b \u2227 b \u2208 b \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 b \u2192 (a,b) \u2208 E G) \u2192 \u2203 B : set G, no_edges_in B \u2227 (\u2200 (a : G) (b : G), a \u2208 B \u2227 (a,b) \u2208 E G \u2192 b \u2208 A G), from by auto [h3],\n  -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite\n  have h6 : two_colorable G \u2192 \u2200 (r : set G) (b : set G), no_edges_in r \u2227 no_edges_in b \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 r \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 b \u2227 b \u2208 b \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 r \u2227 b \u2208 b \u2192 (a,b) \u2208 E G) \u2192 bipartite G, from by auto [h3],\n\n  -- Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$\n  have h7 : bipartite G \u2192 \u2203 (A : set G) (B : set G), no_edges_in A \u2227 no_edges_in B \u2227 (\u2200 (a : G) (b : G), a \u2208 A \u2227 b \u2208 A \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 B \u2227 b \u2208 B \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 A \u2227 b \u2208 B \u2192 (a,b) \u2208 E G), from by auto [h1, h2],\n  -- Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable\n  have h8 : bipartite G \u2192 \u2200 (A : set G) (B : set G), no_edges_in A \u2227 no_edges_in B \u2227 (\u2200 (a : G) (b : G), a \u2208 A \u2227 b \u2208 A \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 B \u2227 b \u2208 B \u2192 (a,b) \u2209 E G) \u2227 (\u2200 (a : G) (b : G), a \u2208 A \u2227 b \u2208 B \u2192 (a,b) \u2208 E G) \u2192 two_colorable G, from by auto [h7],\n\n  show bipartite G \u2194 two_colorable G, from by auto [h3, h7],\nend\n\n--OUTPUT 7\ntheorem graph_bipartite_two_colorable (G : Type*) [graph G] : two_colorable G \u2194 bipartite G :=\nbegin\n  -- $G$ is 2-colorable graph\n  assume h1 : two_colorable G,\n\n  -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n  have h2 : \u2203 A B : set G, \u2200 v : G, (v \u2208 A \u2227 v \u2209 B) \u2228 (v \u2208 B \u2227 v \u2209 A), from by auto [h1],\n  cases h2 with A h2,\n  cases h2 with B h2,\n\n  -- Since all vertices of $A$ are red, there are no edges within $A$\n  have h3 : \u2200 a b : G, (a \u2208 A \u2227 b \u2208 A) \u2192 (a,b) \u2209 E, from by auto [h2],\n\n  -- Similarly for $B$\n  have h4 : \u2200 a b : G, (a \u2208 B \u2227 b \u2208 B) \u2192 (a,b) \u2209 E, from by auto [h2],\n\n  -- This implies that every edge has one endpoint in $A$ and the other in $B$\n  have h5 : \u2200 a b : G, (a,b) \u2208 E \u2192 ((a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)), from by auto [h3, h4],\n\n  -- which means $G$ is bipartite.\n  have h6 : bipartite G, from by auto [h2, h5],\n\n  show two_colorable G \u2194 bipartite G, from by auto [h6] using [iff_def],\nend\n\n--OUTPUT 8\ntheorem bipartite_graph_two_colorable {G : Type*} : bipartite G \u2194 two_colorable G :=\nbegin\n  -- $G$ is 2-colorable, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color.\n  have h1 : two_colorable G \u2192 \u2203 A B : set G, (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)), from by auto using [two_colorable.def, two_colorable.def],\n\n  -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n  have h2 : two_colorable G \u2192 \u2203 A B : set G, (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)) \u2227 (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)), from by auto [h1],\n\n  -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n  have h3 : two_colorable G \u2192 \u2203 A B : set G, (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)) \u2227 (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 a \u2208 A) \u2228 (b \u2208 B \u2227 b \u2208 B) \u2192 false), from by auto using [h2],\n\n  -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  have h4 : two_colorable G \u2192 \u2203 A B : set G, (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)) \u2227 (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 a \u2208 A) \u2228 (b \u2208 B \u2227 b \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)), from by auto using [h3],\n\n  -- Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$.\n  have h5 : bipartite G \u2192 \u2203 A B : set G, (\u2200 a : G, a \u2208 A \u2228 a \u2208 B) \u2227 (\u2200 a : G, (a \u2208 A \u2227 a \u2208 B) \u2192 false) \u2227 (\u2200 a b : G, (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A)), from by auto using [bipartite.def],\n\n  -- Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n  have h6 : bipartite G \u2192 two_colorable G, from by auto using [h5],\n\n  -- We have proved our theorem\n  show bipartite G \u2194 two_colorable G, from by auto [h4, h6],\nend\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  -- Then $A \u2286 S$ and $B \u2286 S$, by power set definition\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],\n  -- Then $(A \u2229 B) \u2286 A$, by intersection of set is a subset\n  have h2 : (A \u2229 B) \u2286 A, from by auto [set.inter_subset_left],\n  -- Then $(A \u2229 B) \u2286 S$, by subset relation is transitive \n  have h3 : (A \u2229 B) \u2286 S, from by auto [set.subset.trans],\n  -- Hence $(A \u2229 B) \u2208  \ud835\udcab S$, by power set definition\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by auto [set.mem_powerset],\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  -- expand the power\n  calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]\n  -- distributive property of multiplication over addition gives:\n  ... = x*(x+y) + y*(x+y) : by auto [add_mul]\n  -- applying the above property further gives:\n  ... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]\n  -- rearranging the terms using commutativity and adding gives:\n  ... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring]\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  -- Group has Latin Square Property\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by auto using [use (a\u207b\u00b9 * b)],\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by auto using [use b * a\u207b\u00b9], \n\n  -- Setting $b = a$, this becomes:\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from by auto [h1],\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from by auto [h2],\n\n  -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one],\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul],\n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)],\nend\n\n/--`theorem`\nBipartite Graph is two colorable\nLet $G$ be a graph. Then $G$ is 2-colorable if and only if $G$ is bipartite.\n`proof`\nLet $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n\nConversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$. Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n\nQED\n\n-/\ntheorem \nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_auto_with_comments-Natural-Language-Proof-Translation/lean_proof_auto_with_comments-3_few_shot_temperature_0.6_max_tokens_2000_n_8/clean_files/Bipartite Graph is two colorable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7166677512714851}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard,\nAmelia Livingston, Yury Kudryashov\nPorted by: Anatole Dedecker\n\n! This file was ported from Lean 3 source module group_theory.submonoid.basic\n! leanprover-community/mathlib commit feb99064803fd3108e37c18b0f77d0a8344677a3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Hom.Group\nimport Mathlib.Algebra.Group.Units\nimport Mathlib.GroupTheory.Subsemigroup.Basic\n\n/-!\n# Submonoids: definition and `CompleteLattice` structure\n\nThis file defines bundled multiplicative and additive submonoids. We also define\na `CompleteLattice` structure on `Submonoid`s, define the closure of a set as the minimal submonoid\nthat includes this set, and prove a few results about extending properties from a dense set (i.e.\na set with `closure s = \u22a4`) to the whole monoid, see `Submonoid.dense_induction` and\n`MonoidHom.ofClosureEqTopLeft`/`MonoidHom.ofClosureEqTopRight`.\n\n## Main definitions\n\n* `Submonoid M`: the type of bundled submonoids of a monoid `M`; the underlying set is given in\n  the `carrier` field of the structure, and should be accessed through coercion as in `(S : Set M)`.\n* `AddSubmonoid M` : the type of bundled submonoids of an additive monoid `M`.\n\nFor each of the following definitions in the `Submonoid` namespace, there is a corresponding\ndefinition in the `AddSubmonoid` namespace.\n\n* `Submonoid.copy` : copy of a submonoid with `carrier` replaced by a set that is equal but possibly\n  not definitionally equal to the carrier of the original `Submonoid`.\n* `Submonoid.closure` :  monoid closure of a set, i.e., the least submonoid that includes the set.\n* `Submonoid.gi` : `closure : Set M \u2192 Submonoid M` and coercion `coe : Submonoid M \u2192 Set M`\n  form a `GaloisInsertion`;\n* `MonoidHom.eqLocus`: the submonoid of elements `x : M` such that `f x = g x`;\n* `MonoidHom.ofClosureEqTopRight`:  if a map `f : M \u2192 N` between two monoids satisfies\n  `f 1 = 1` and `f (x * y) = f x * f y` for `y` from some dense set `s`, then `f` is a monoid\n  homomorphism. E.g., if `f : \u2115 \u2192 M` satisfies `f 0 = 0` and `f (x + 1) = f x + f 1`, then `f` is\n  an additive monoid homomorphism.\n\n## Implementation notes\n\nSubmonoid inclusion is denoted `\u2264` rather than `\u2286`, although `\u2208` is defined as\nmembership of a submonoid's underlying set.\n\nNote that `Submonoid M` does not actually require `Monoid M`, instead requiring only the weaker\n`MulOneClass M`.\n\nThis file is designed to have very few dependencies. In particular, it should not use natural\nnumbers. `Submonoid` is implemented by extending `Subsemigroup` requiring `one_mem'`.\n\n## Tags\nsubmonoid, submonoids\n-/\n\n\n-- Only needed for notation\n-- Only needed for notation\nvariable {M : Type _} {N : Type _}\n\nvariable {A : Type _}\n\nsection NonAssoc\n\nvariable [MulOneClass M] {s : Set M}\n\nvariable [AddZeroClass A] {t : Set A}\n\n/-- `OneMemClass S M` says `S` is a type of subsets `s \u2264 M`, such that `1 \u2208 s` for all `s`. -/\nclass OneMemClass (S : Type _) (M : Type _) [One M] [SetLike S M] : Prop where\n  /-- By definition, if we have `OneMemClass S M`, we have `1 \u2208 s` for all `s : S`. -/\n  one_mem : \u2200 s : S, (1 : M) \u2208 s\n#align one_mem_class OneMemClass\n\nexport OneMemClass (one_mem)\n\n/-- `ZeroMemClass S M` says `S` is a type of subsets `s \u2264 M`, such that `0 \u2208 s` for all `s`. -/\nclass ZeroMemClass (S : Type _) (M : Type _) [Zero M] [SetLike S M] : Prop where\n  /-- By definition, if we have `ZeroMemClass S M`, we have `0 \u2208 s` for all `s : S`. -/\n  zero_mem : \u2200 s : S, (0 : M) \u2208 s\n#align zero_mem_class ZeroMemClass\n\nexport ZeroMemClass (zero_mem)\n\nattribute [to_additive] OneMemClass\n\nsection\n\n/-- A submonoid of a monoid `M` is a subset containing 1 and closed under multiplication. -/\nstructure Submonoid (M : Type _) [MulOneClass M] extends Subsemigroup M where\n  /-- A submonoid contains `1`. -/\n  one_mem' : (1 : M) \u2208 carrier\n#align submonoid Submonoid\n\nend\n\n/-- A submonoid of a monoid `M` can be considered as a subsemigroup of that monoid. -/\nadd_decl_doc Submonoid.toSubsemigroup\n#align submonoid.to_subsemigroup Submonoid.toSubsemigroup\n\n/-- `SubmonoidClass S M` says `S` is a type of subsets `s \u2264 M` that contain `1`\nand are closed under `(*)` -/\nclass SubmonoidClass (S : Type _) (M : Type _) [MulOneClass M] [SetLike S M] extends\n  MulMemClass S M, OneMemClass S M : Prop\n#align submonoid_class SubmonoidClass\n\nsection\n\n/-- An additive submonoid of an additive monoid `M` is a subset containing 0 and\n  closed under addition. -/\nstructure AddSubmonoid (M : Type _) [AddZeroClass M] extends AddSubsemigroup M where\n  /-- An additive submonoid contains `0`. -/\n  zero_mem' : (0 : M) \u2208 carrier\n#align add_submonoid AddSubmonoid\n\nend\n\n/-- An additive submonoid of an additive monoid `M` can be considered as an\nadditive subsemigroup of that additive monoid. -/\nadd_decl_doc AddSubmonoid.toAddSubsemigroup\n#align add_submonoid.to_add_subsemigroup AddSubmonoid.toAddSubsemigroup\n\n/-- `AddSubmonoidClass S M` says `S` is a type of subsets `s \u2264 M` that contain `0`\nand are closed under `(+)` -/\nclass AddSubmonoidClass (S : Type _) (M : Type _) [AddZeroClass M] [SetLike S M] extends\n  AddMemClass S M, ZeroMemClass S M : Prop\n#align add_submonoid_class AddSubmonoidClass\n\nattribute [to_additive] Submonoid SubmonoidClass\n\n@[to_additive]\ntheorem pow_mem {M A} [Monoid M] [SetLike A M] [SubmonoidClass A M] {S : A} {x : M}\n    (hx : x \u2208 S) : \u2200 n : \u2115, x ^ n \u2208 S\n  | 0 => by\n    rw [pow_zero]\n    exact OneMemClass.one_mem S\n  | n + 1 => by\n    rw [pow_succ]\n    exact mul_mem hx (pow_mem hx n)\n#align pow_mem pow_mem\n#align nsmul_mem nsmul_mem\n\nnamespace Submonoid\n\n@[to_additive]\ninstance : SetLike (Submonoid M) M where\n  coe s := s.carrier\n  coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\n@[to_additive]\ninstance : SubmonoidClass (Submonoid M) M where\n  one_mem := Submonoid.one_mem'\n  mul_mem {s} := s.mul_mem'\n\ninitialize_simps_projections Submonoid (carrier \u2192 coe)\n\ninitialize_simps_projections AddSubmonoid (carrier \u2192 coe)\n\n@[to_additive (attr := simp)]\ntheorem mem_toSubsemigroup {s : Submonoid M} {x : M} : x \u2208 s.toSubsemigroup \u2194 x \u2208 s :=\n  Iff.rfl\n\n-- Porting note: `x \u2208 s.carrier` is now syntactically `x \u2208 s.toSubsemigroup.carrier`,\n-- which `simp` already simplifies to `x \u2208 s.toSubsemigroup`. So we remove the `@[simp]` attribute\n-- here, and instead add the simp lemma `mem_toSubsemigroup` to allow `simp` to do this exact\n-- simplification transitively.\n@[to_additive]\ntheorem mem_carrier {s : Submonoid M} {x : M} : x \u2208 s.carrier \u2194 x \u2208 s :=\n  Iff.rfl\n#align submonoid.mem_carrier Submonoid.mem_carrier\n#align add_submonoid.mem_carrier AddSubmonoid.mem_carrier\n\n@[to_additive (attr := simp)]\ntheorem mem_mk {s : Set M} {x : M} (h_one) (h_mul) : x \u2208 mk \u27e8s, h_mul\u27e9 h_one \u2194 x \u2208 s :=\n  Iff.rfl\n#align submonoid.mem_mk Submonoid.mem_mk\n#align add_submonoid.mem_mk AddSubmonoid.mem_mk\n\n@[to_additive (attr := simp)]\ntheorem coe_set_mk {s : Set M} (h_one) (h_mul) : (mk \u27e8s, h_mul\u27e9 h_one : Set M) = s :=\n  rfl\n#align submonoid.coe_set_mk Submonoid.coe_set_mk\n#align add_submonoid.coe_set_mk AddSubmonoid.coe_set_mk\n\n@[to_additive (attr := simp)]\ntheorem mk_le_mk {s t : Set M} (h_one) (h_mul) (h_one') (h_mul') :\n    mk \u27e8s, h_mul\u27e9 h_one \u2264 mk \u27e8t, h_mul'\u27e9 h_one' \u2194 s \u2286 t :=\n  Iff.rfl\n#align submonoid.mk_le_mk Submonoid.mk_le_mk\n#align add_submonoid.mk_le_mk AddSubmonoid.mk_le_mk\n\n/-- Two submonoids are equal if they have the same elements. -/\n@[to_additive (attr := ext) \"Two `AddSubmonoid`s are equal if they have the same elements.\"]\ntheorem ext {S T : Submonoid M} (h : \u2200 x, x \u2208 S \u2194 x \u2208 T) : S = T :=\n  SetLike.ext h\n#align submonoid.ext Submonoid.ext\n#align add_submonoid.ext AddSubmonoid.ext\n\n/-- Copy a submonoid replacing `carrier` with a set that is equal to it. -/\n@[to_additive \"Copy an additive submonoid replacing `carrier` with a set that is equal to it.\"]\nprotected def copy (S : Submonoid M) (s : Set M) (hs : s = S) : Submonoid M where\n  carrier := s\n  one_mem' := show 1 \u2208 s from hs.symm \u25b8 S.one_mem'\n  mul_mem' := hs.symm \u25b8 S.mul_mem'\n#align submonoid.copy Submonoid.copy\n#align add_submonoid.copy AddSubmonoid.copy\n\nvariable {S : Submonoid M}\n\n@[to_additive (attr := simp)]\ntheorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s :=\n  rfl\n#align submonoid.coe_copy Submonoid.coe_copy\n#align add_submonoid.coe_copy AddSubmonoid.coe_copy\n\n@[to_additive]\ntheorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S :=\n  SetLike.coe_injective hs\n#align submonoid.copy_eq Submonoid.copy_eq\n#align add_submonoid.copy_eq AddSubmonoid.copy_eq\n\nvariable (S)\n\n/-- A submonoid contains the monoid's 1. -/\n@[to_additive \"An `AddSubmonoid` contains the monoid's 0.\"]\nprotected theorem one_mem : (1 : M) \u2208 S :=\n  one_mem S\n#align submonoid.one_mem Submonoid.one_mem\n#align add_submonoid.zero_mem AddSubmonoid.zero_mem\n\n/-- A submonoid is closed under multiplication. -/\n@[to_additive \"An `AddSubmonoid` is closed under addition.\"]\nprotected theorem mul_mem {x y : M} : x \u2208 S \u2192 y \u2208 S \u2192 x * y \u2208 S :=\n  mul_mem\n#align submonoid.mul_mem Submonoid.mul_mem\n#align add_submonoid.add_mem AddSubmonoid.add_mem\n\n/-- The submonoid `M` of the monoid `M`. -/\n@[to_additive \"The additive submonoid `M` of the `AddMonoid M`.\"]\ninstance : Top (Submonoid M) :=\n  \u27e8{  carrier := Set.univ\n      one_mem' := Set.mem_univ 1\n      mul_mem' := fun _ _ => Set.mem_univ _ }\u27e9\n\n/-- The trivial submonoid `{1}` of an monoid `M`. -/\n@[to_additive \"The trivial `AddSubmonoid` `{0}` of an `AddMonoid` `M`.\"]\ninstance : Bot (Submonoid M) :=\n  \u27e8{  carrier := {1}\n      one_mem' := Set.mem_singleton 1\n      mul_mem' := fun ha hb => by\n        simp only [Set.mem_singleton_iff] at *\n        rw [ha, hb, mul_one] }\u27e9\n\n@[to_additive]\ninstance : Inhabited (Submonoid M) :=\n  \u27e8\u22a5\u27e9\n\n@[to_additive (attr := simp)]\ntheorem mem_bot {x : M} : x \u2208 (\u22a5 : Submonoid M) \u2194 x = 1 :=\n  Set.mem_singleton_iff\n#align submonoid.mem_bot Submonoid.mem_bot\n#align add_submonoid.mem_bot AddSubmonoid.mem_bot\n\n@[to_additive (attr := simp)]\ntheorem mem_top (x : M) : x \u2208 (\u22a4 : Submonoid M) :=\n  Set.mem_univ x\n#align submonoid.mem_top Submonoid.mem_top\n#align add_submonoid.mem_top AddSubmonoid.mem_top\n\n@[to_additive (attr := simp)]\ntheorem coe_top : ((\u22a4 : Submonoid M) : Set M) = Set.univ :=\n  rfl\n#align submonoid.coe_top Submonoid.coe_top\n#align add_submonoid.coe_top AddSubmonoid.coe_top\n\n@[to_additive (attr := simp)]\ntheorem coe_bot : ((\u22a5 : Submonoid M) : Set M) = {1} :=\n  rfl\n#align submonoid.coe_bot Submonoid.coe_bot\n#align add_submonoid.coe_bot AddSubmonoid.coe_bot\n\n/-- The inf of two submonoids is their intersection. -/\n@[to_additive \"The inf of two `AddSubmonoid`s is their intersection.\"]\ninstance : Inf (Submonoid M) :=\n  \u27e8fun S\u2081 S\u2082 =>\n    { carrier := S\u2081 \u2229 S\u2082\n      one_mem' := \u27e8S\u2081.one_mem, S\u2082.one_mem\u27e9\n      mul_mem' := fun \u27e8hx, hx'\u27e9 \u27e8hy, hy'\u27e9 => \u27e8S\u2081.mul_mem hx hy, S\u2082.mul_mem hx' hy'\u27e9 }\u27e9\n\n@[to_additive (attr := simp)]\ntheorem coe_inf (p p' : Submonoid M) : ((p \u2293 p' : Submonoid M) : Set M) = (p : Set M) \u2229 p' :=\n  rfl\n#align submonoid.coe_inf Submonoid.coe_inf\n#align add_submonoid.coe_inf AddSubmonoid.coe_inf\n\n@[to_additive (attr := simp)]\ntheorem mem_inf {p p' : Submonoid M} {x : M} : x \u2208 p \u2293 p' \u2194 x \u2208 p \u2227 x \u2208 p' :=\n  Iff.rfl\n#align submonoid.mem_inf Submonoid.mem_inf\n#align add_submonoid.mem_inf AddSubmonoid.mem_inf\n\n@[to_additive]\ninstance : InfSet (Submonoid M) :=\n  \u27e8fun s =>\n    { carrier := \u22c2 t \u2208 s, \u2191t\n      one_mem' := Set.mem_binter\u1d62 fun i _ => i.one_mem\n      mul_mem' := fun hx hy =>\n        Set.mem_binter\u1d62 fun i h =>\n          i.mul_mem (by apply Set.mem_inter\u1d62\u2082.1 hx i h) (by apply Set.mem_inter\u1d62\u2082.1 hy i h) }\u27e9\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_inf\u209b (S : Set (Submonoid M)) : ((inf\u209b S : Submonoid M) : Set M) = \u22c2 s \u2208 S, \u2191s :=\n  rfl\n#align submonoid.coe_Inf Submonoid.coe_inf\u209b\n#align add_submonoid.coe_Inf AddSubmonoid.coe_inf\u209b\n\n@[to_additive]\ntheorem mem_inf\u209b {S : Set (Submonoid M)} {x : M} : x \u2208 inf\u209b S \u2194 \u2200 p \u2208 S, x \u2208 p :=\n  Set.mem_inter\u1d62\u2082\n#align submonoid.mem_Inf Submonoid.mem_inf\u209b\n#align add_submonoid.mem_Inf AddSubmonoid.mem_inf\u209b\n\n@[to_additive]\ntheorem mem_inf\u1d62 {\u03b9 : Sort _} {S : \u03b9 \u2192 Submonoid M} {x : M} : (x \u2208 \u2a05 i, S i) \u2194 \u2200 i, x \u2208 S i := by\n  simp only [inf\u1d62, mem_inf\u209b, Set.forall_range_iff]\n#align submonoid.mem_infi Submonoid.mem_inf\u1d62\n#align add_submonoid.mem_infi AddSubmonoid.mem_inf\u1d62\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_inf\u1d62 {\u03b9 : Sort _} {S : \u03b9 \u2192 Submonoid M} : (\u2191(\u2a05 i, S i) : Set M) = \u22c2 i, S i := by\n  simp only [inf\u1d62, coe_inf\u209b, Set.binter\u1d62_range]\n#align submonoid.coe_infi Submonoid.coe_inf\u1d62\n#align add_submonoid.coe_infi AddSubmonoid.coe_inf\u1d62\n\n/-- Submonoids of a monoid form a complete lattice. -/\n@[to_additive \"The `AddSubmonoid`s of an `AddMonoid` form a complete lattice.\"]\ninstance : CompleteLattice (Submonoid M) :=\n  { (completeLatticeOfInf (Submonoid M)) fun _ =>\n      IsGLB.of_image (f := (SetLike.coe : Submonoid M \u2192 Set M))\n        (@fun S T => show (S : Set M) \u2264 T \u2194 S \u2264 T from SetLike.coe_subset_coe)\n        isGLB_binf\u1d62 with\n    le := (\u00b7 \u2264 \u00b7)\n    lt := (\u00b7 < \u00b7)\n    bot := \u22a5\n    bot_le := fun S _ hx => (mem_bot.1 hx).symm \u25b8 S.one_mem\n    top := \u22a4\n    le_top := fun _ x _ => mem_top x\n    inf := (\u00b7 \u2293 \u00b7)\n    inf\u209b := InfSet.inf\u209b\n    le_inf := fun _ _ _ ha hb _ hx => \u27e8ha hx, hb hx\u27e9\n    inf_le_left := fun _ _ _ => And.left\n    inf_le_right := fun _ _ _ => And.right }\n\n@[to_additive (attr := simp)]\ntheorem subsingleton_iff : Subsingleton (Submonoid M) \u2194 Subsingleton M :=\n  \u27e8fun h =>\n    \u27e8fun x y =>\n      have : \u2200 i : M, i = 1 := fun i =>\n        mem_bot.mp <| Subsingleton.elim (\u22a4 : Submonoid M) \u22a5 \u25b8 mem_top i\n      (this x).trans (this y).symm\u27e9,\n    fun h =>\n    \u27e8fun x y => Submonoid.ext fun i => Subsingleton.elim 1 i \u25b8 by simp [Submonoid.one_mem]\u27e9\u27e9\n#align submonoid.subsingleton_iff Submonoid.subsingleton_iff\n#align add_submonoid.subsingleton_iff AddSubmonoid.subsingleton_iff\n\n@[to_additive (attr := simp)]\ntheorem nontrivial_iff : Nontrivial (Submonoid M) \u2194 Nontrivial M :=\n  not_iff_not.mp\n    ((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans\n      not_nontrivial_iff_subsingleton.symm)\n#align submonoid.nontrivial_iff Submonoid.nontrivial_iff\n#align add_submonoid.nontrivial_iff AddSubmonoid.nontrivial_iff\n\n@[to_additive]\ninstance [Subsingleton M] : Unique (Submonoid M) :=\n  \u27e8\u27e8\u22a5\u27e9, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr \u2039_\u203a) a _\u27e9\n\n@[to_additive]\ninstance [Nontrivial M] : Nontrivial (Submonoid M) :=\n  nontrivial_iff.mpr \u2039_\u203a\n\n/-- The `Submonoid` generated by a set. -/\n@[to_additive \"The `add_submonoid` generated by a set\"]\ndef closure (s : Set M) : Submonoid M :=\n  inf\u209b { S | s \u2286 S }\n#align submonoid.closure Submonoid.closure\n#align add_submonoid.closure AddSubmonoid.closure\n\n@[to_additive]\ntheorem mem_closure {x : M} : x \u2208 closure s \u2194 \u2200 S : Submonoid M, s \u2286 S \u2192 x \u2208 S :=\n  mem_inf\u209b\n#align submonoid.mem_closure Submonoid.mem_closure\n#align add_submonoid.mem_closure AddSubmonoid.mem_closure\n\n/-- The submonoid generated by a set includes the set. -/\n@[to_additive (attr := simp) \"The `AddSubmonoid` generated by a set includes the set.\"]\ntheorem subset_closure : s \u2286 closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx\n#align submonoid.subset_closure Submonoid.subset_closure\n#align add_submonoid.subset_closure AddSubmonoid.subset_closure\n\n@[to_additive]\ntheorem not_mem_of_not_mem_closure {P : M} (hP : P \u2209 closure s) : P \u2209 s := fun h =>\n  hP (subset_closure h)\n#align submonoid.not_mem_of_not_mem_closure Submonoid.not_mem_of_not_mem_closure\n#align add_submonoid.not_mem_of_not_mem_closure AddSubmonoid.not_mem_of_not_mem_closure\n\nvariable {S}\n\nopen Set\n\n/-- A submonoid `S` includes `closure s` if and only if it includes `s`. -/\n@[to_additive (attr := simp)\n\"An additive submonoid `S` includes `closure s` if and only if it includes `s`\"]\ntheorem closure_le : closure s \u2264 S \u2194 s \u2286 S :=\n  \u27e8Subset.trans subset_closure, fun h => inf\u209b_le h\u27e9\n#align submonoid.closure_le Submonoid.closure_le\n#align add_submonoid.closure_le AddSubmonoid.closure_le\n\n/-- Submonoid closure of a set is monotone in its argument: if `s \u2286 t`,\nthen `closure s \u2264 closure t`. -/\n@[to_additive\n      \"Additive submonoid closure of a set is monotone in its argument: if `s \u2286 t`,\n      then `closure s \u2264 closure t`\"]\ntheorem closure_mono \u2983s t : Set M\u2984 (h : s \u2286 t) : closure s \u2264 closure t :=\n  closure_le.2 <| Subset.trans h subset_closure\n#align submonoid.closure_mono Submonoid.closure_mono\n#align add_submonoid.closure_mono AddSubmonoid.closure_mono\n\n@[to_additive]\ntheorem closure_eq_of_le (h\u2081 : s \u2286 S) (h\u2082 : S \u2264 closure s) : closure s = S :=\n  le_antisymm (closure_le.2 h\u2081) h\u2082\n#align submonoid.closure_eq_of_le Submonoid.closure_eq_of_le\n#align add_submonoid.closure_eq_of_le AddSubmonoid.closure_eq_of_le\n\nvariable (S)\n\n/-- An induction principle for closure membership. If `p` holds for `1` and all elements of `s`, and\nis preserved under multiplication, then `p` holds for all elements of the closure of `s`. -/\n@[to_additive (attr := elab_as_elim)\n      \"An induction principle for additive closure membership. If `p` holds for `0` and all\n      elements of `s`, and is preserved under addition, then `p` holds for all elements of the\n      additive closure of `s`.\"]\ntheorem closure_induction {p : M \u2192 Prop} {x} (h : x \u2208 closure s) (Hs : \u2200 x \u2208 s, p x) (H1 : p 1)\n    (Hmul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) : p x :=\n  (@closure_le _ _ _ \u27e8\u27e8p, Hmul _ _\u27e9, H1\u27e9).2 Hs h\n#align submonoid.closure_induction Submonoid.closure_induction\n#align add_submonoid.closure_induction AddSubmonoid.closure_induction\n\n/-- A dependent version of `Submonoid.closure_induction`.  -/\n@[to_additive (attr := elab_as_elim) \"A dependent version of `AddSubmonoid.closure_induction`. \"]\ntheorem closure_induction' (s : Set M) {p : \u2200 x, x \u2208 closure s \u2192 Prop}\n    (Hs : \u2200 (x) (h : x \u2208 s), p x (subset_closure h)) (H1 : p 1 (one_mem _))\n    (Hmul : \u2200 x hx y hy, p x hx \u2192 p y hy \u2192 p (x * y) (mul_mem hx hy)) {x} (hx : x \u2208 closure s) :\n    p x hx := by\n  refine' Exists.elim _ fun (hx : x \u2208 closure s) (hc : p x hx) => hc\n  exact\n    closure_induction hx (fun x hx => \u27e8_, Hs x hx\u27e9) \u27e8_, H1\u27e9 fun x y \u27e8hx', hx\u27e9 \u27e8hy', hy\u27e9 =>\n      \u27e8_, Hmul _ _ _ _ hx hy\u27e9\n#align submonoid.closure_induction' Submonoid.closure_induction'\n#align add_submonoid.closure_induction' AddSubmonoid.closure_induction'\n\n/-- An induction principle for closure membership for predicates with two arguments.  -/\n@[to_additive (attr := elab_as_elim)\n      \"An induction principle for additive closure membership for predicates with two arguments.\"]\ntheorem closure_induction\u2082 {p : M \u2192 M \u2192 Prop} {x} {y : M} (hx : x \u2208 closure s) (hy : y \u2208 closure s)\n    (Hs : \u2200 x \u2208 s, \u2200 y \u2208 s, p x y) (H1_left : \u2200 x, p 1 x) (H1_right : \u2200 x, p x 1)\n    (Hmul_left : \u2200 x y z, p x z \u2192 p y z \u2192 p (x * y) z)\n    (Hmul_right : \u2200 x y z, p z x \u2192 p z y \u2192 p z (x * y)) : p x y :=\n  closure_induction hx\n    (fun x xs =>\n      closure_induction hy (Hs x xs) (H1_right x) fun z _ h\u2081 h\u2082 => Hmul_right z _ _ h\u2081 h\u2082)\n    (H1_left y) fun _ _ h\u2081 h\u2082 => Hmul_left _ _ _ h\u2081 h\u2082\n#align submonoid.closure_induction\u2082 Submonoid.closure_induction\u2082\n#align add_submonoid.closure_induction\u2082 AddSubmonoid.closure_induction\u2082\n\n/-- If `s` is a dense set in a monoid `M`, `Submonoid.closure s = \u22a4`, then in order to prove that\nsome predicate `p` holds for all `x : M` it suffices to verify `p x` for `x \u2208 s`, verify `p 1`,\nand verify that `p x` and `p y` imply `p (x * y)`. -/\n@[to_additive (attr := elab_as_elim)\n      \"If `s` is a dense set in an additive monoid `M`, `AddSubmonoid.closure s = \u22a4`, then in\n      order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for\n      `x \u2208 s`, verify `p 0`, and verify that `p x` and `p y` imply `p (x + y)`.\"]\ntheorem dense_induction {p : M \u2192 Prop} (x : M) {s : Set M} (hs : closure s = \u22a4) (Hs : \u2200 x \u2208 s, p x)\n    (H1 : p 1) (Hmul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) : p x := by\n  have : \u2200 x \u2208 closure s, p x := fun x hx => closure_induction hx Hs H1 Hmul\n  simpa [hs] using this x\n#align submonoid.dense_induction Submonoid.dense_induction\n#align add_submonoid.dense_induction AddSubmonoid.dense_induction\n\nvariable (M)\n\n/-- `closure` forms a Galois insertion with the coercion to set. -/\n@[to_additive \"`closure` forms a Galois insertion with the coercion to set.\"]\nprotected def gi : GaloisInsertion (@closure M _) SetLike.coe where\n  choice s _ := closure s\n  gc _ _ := closure_le\n  le_l_u _ := subset_closure\n  choice_eq _ _ := rfl\n#align submonoid.gi Submonoid.gi\n#align add_submonoid.gi AddSubmonoid.gi\n\nvariable {M}\n\n/-- Closure of a submonoid `S` equals `S`. -/\n@[to_additive (attr := simp) \"Additive closure of an additive submonoid `S` equals `S`\"]\ntheorem closure_eq : closure (S : Set M) = S :=\n  (Submonoid.gi M).l_u_eq S\n#align submonoid.closure_eq Submonoid.closure_eq\n#align add_submonoid.closure_eq AddSubmonoid.closure_eq\n\n@[to_additive (attr := simp)]\ntheorem closure_empty : closure (\u2205 : Set M) = \u22a5 :=\n  (Submonoid.gi M).gc.l_bot\n#align submonoid.closure_empty Submonoid.closure_empty\n#align add_submonoid.closure_empty AddSubmonoid.closure_empty\n\n@[to_additive (attr := simp)]\ntheorem closure_univ : closure (univ : Set M) = \u22a4 :=\n  @coe_top M _ \u25b8 closure_eq \u22a4\n#align submonoid.closure_univ Submonoid.closure_univ\n#align add_submonoid.closure_univ AddSubmonoid.closure_univ\n\n@[to_additive]\ntheorem closure_union (s t : Set M) : closure (s \u222a t) = closure s \u2294 closure t :=\n  (Submonoid.gi M).gc.l_sup\n#align submonoid.closure_union Submonoid.closure_union\n#align add_submonoid.closure_union AddSubmonoid.closure_union\n\n@[to_additive]\ntheorem closure_union\u1d62 {\u03b9} (s : \u03b9 \u2192 Set M) : closure (\u22c3 i, s i) = \u2a06 i, closure (s i) :=\n  (Submonoid.gi M).gc.l_sup\u1d62\n#align submonoid.closure_Union Submonoid.closure_union\u1d62\n#align add_submonoid.closure_Union AddSubmonoid.closure_union\u1d62\n\n-- Porting note: `simp` can now prove this, so we remove the `@[simp]` attribute\n@[to_additive]\ntheorem closure_singleton_le_iff_mem (m : M) (p : Submonoid M) : closure {m} \u2264 p \u2194 m \u2208 p := by\n  rw [closure_le, singleton_subset_iff, SetLike.mem_coe]\n#align submonoid.closure_singleton_le_iff_mem Submonoid.closure_singleton_le_iff_mem\n#align add_submonoid.closure_singleton_le_iff_mem AddSubmonoid.closure_singleton_le_iff_mem\n\n@[to_additive]\ntheorem mem_sup\u1d62 {\u03b9 : Sort _} (p : \u03b9 \u2192 Submonoid M) {m : M} :\n    (m \u2208 \u2a06 i, p i) \u2194 \u2200 N, (\u2200 i, p i \u2264 N) \u2192 m \u2208 N := by\n  rw [\u2190 closure_singleton_le_iff_mem, le_sup\u1d62_iff]\n  simp only [closure_singleton_le_iff_mem]\n#align submonoid.mem_supr Submonoid.mem_sup\u1d62\n#align add_submonoid.mem_supr AddSubmonoid.mem_sup\u1d62\n\n@[to_additive]\ntheorem sup\u1d62_eq_closure {\u03b9 : Sort _} (p : \u03b9 \u2192 Submonoid M) :\n    (\u2a06 i, p i) = Submonoid.closure (\u22c3 i, (p i : Set M)) := by\n  simp_rw [Submonoid.closure_union\u1d62, Submonoid.closure_eq]\n#align submonoid.supr_eq_closure Submonoid.sup\u1d62_eq_closure\n#align add_submonoid.supr_eq_closure AddSubmonoid.sup\u1d62_eq_closure\n\n@[to_additive]\ntheorem disjoint_def {p\u2081 p\u2082 : Submonoid M} : Disjoint p\u2081 p\u2082 \u2194 \u2200 {x : M}, x \u2208 p\u2081 \u2192 x \u2208 p\u2082 \u2192 x = 1 :=\n  by simp_rw [disjoint_iff_inf_le, SetLike.le_def, mem_inf, and_imp, mem_bot]\n#align submonoid.disjoint_def Submonoid.disjoint_def\n#align add_submonoid.disjoint_def AddSubmonoid.disjoint_def\n\n@[to_additive]\ntheorem disjoint_def' {p\u2081 p\u2082 : Submonoid M} :\n    Disjoint p\u2081 p\u2082 \u2194 \u2200 {x y : M}, x \u2208 p\u2081 \u2192 y \u2208 p\u2082 \u2192 x = y \u2192 x = 1 :=\n  disjoint_def.trans \u27e8fun h _ _ hx hy hxy => h hx <| hxy.symm \u25b8 hy, fun h _ hx hx' => h hx hx' rfl\u27e9\n#align submonoid.disjoint_def' Submonoid.disjoint_def'\n#align add_submonoid.disjoint_def' AddSubmonoid.disjoint_def'\n\nend Submonoid\n\nnamespace MonoidHom\n\nvariable [MulOneClass N]\n\nopen Submonoid\n\n/-- The submonoid of elements `x : M` such that `f x = g x` -/\n@[to_additive \"The additive submonoid of elements `x : M` such that `f x = g x`\"]\ndef eqLocusM (f g : M \u2192* N) : Submonoid M where\n  carrier := { x | f x = g x }\n  one_mem' := by rw [Set.mem_setOf_eq, f.map_one, g.map_one]\n  mul_mem' (hx : _ = _) (hy : _ = _) := by simp [*]\n#align monoid_hom.eq_mlocus MonoidHom.eqLocusM\n#align add_monoid_hom.eq_mlocus AddMonoidHom.eqLocusM\n\n@[to_additive (attr := simp)]\ntheorem eqLocusM_same (f : M \u2192* N) : f.eqLocusM f = \u22a4 :=\n  SetLike.ext fun _ => eq_self_iff_true _\n#align monoid_hom.eq_mlocus_same MonoidHom.eqLocusM_same\n#align add_monoid_hom.eq_mlocus_same AddMonoidHom.eqLocusM_same\n\n/-- If two monoid homomorphisms are equal on a set, then they are equal on its submonoid closure. -/\n@[to_additive\n      \"If two monoid homomorphisms are equal on a set, then they are equal on its submonoid\n      closure.\"]\ntheorem eqOn_closureM {f g : M \u2192* N} {s : Set M} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) :=\n  show closure s \u2264 f.eqLocusM g from closure_le.2 h\n#align monoid_hom.eq_on_mclosure MonoidHom.eqOn_closureM\n#align add_monoid_hom.eq_on_mclosure AddMonoidHom.eqOn_closureM\n\n@[to_additive]\ntheorem eq_of_eqOn_topM {f g : M \u2192* N} (h : Set.EqOn f g (\u22a4 : Submonoid M)) : f = g :=\n  ext fun _ => h trivial\n#align monoid_hom.eq_of_eq_on_mtop MonoidHom.eq_of_eqOn_topM\n#align add_monoid_hom.eq_of_eq_on_mtop AddMonoidHom.eq_of_eqOn_topM\n\n@[to_additive]\ntheorem eq_of_eqOn_denseM {s : Set M} (hs : closure s = \u22a4) {f g : M \u2192* N} (h : s.EqOn f g) :\n    f = g :=\n  eq_of_eqOn_topM <| hs \u25b8 eqOn_closureM h\n#align monoid_hom.eq_of_eq_on_mdense MonoidHom.eq_of_eqOn_denseM\n#align add_monoid_hom.eq_of_eq_on_mdense AddMonoidHom.eq_of_eqOn_denseM\n\nend MonoidHom\n\nend NonAssoc\n\nsection Assoc\n\nvariable [Monoid M] [Monoid N] {s : Set M}\n\nsection IsUnit\n\n/-- The submonoid consisting of the units of a monoid -/\n@[to_additive \"The additive submonoid consisting of the additive units of an additive monoid\"]\ndef IsUnit.submonoid (M : Type _) [Monoid M] : Submonoid M where\n  carrier := setOf IsUnit\n  one_mem' := by simp only [isUnit_one, Set.mem_setOf_eq]\n  mul_mem' := by\n    intro a b ha hb\n    rw [Set.mem_setOf_eq] at *\n    exact IsUnit.mul ha hb\n#align is_unit.submonoid IsUnit.submonoid\n#align is_add_unit.add_submonoid IsAddUnit.addSubmonoid\n\n@[to_additive]\ntheorem IsUnit.mem_submonoid_iff {M : Type _} [Monoid M] (a : M) :\n    a \u2208 IsUnit.submonoid M \u2194 IsUnit a := by\n  change a \u2208 setOf IsUnit \u2194 IsUnit a\n  rw [Set.mem_setOf_eq]\n#align is_unit.mem_submonoid_iff IsUnit.mem_submonoid_iff\n#align is_add_unit.mem_add_submonoid_iff IsAddUnit.mem_addSubmonoid_iff\n\nend IsUnit\n\nnamespace MonoidHom\n\nopen Submonoid\n\n/-- Let `s` be a subset of a monoid `M` such that the closure of `s` is the whole monoid.\nThen `MonoidHom.ofClosureEqTopLeft` defines a monoid homomorphism from `M` asking for\na proof of `f (x * y) = f x * f y` only for `x \u2208 s`. -/\n@[to_additive\n      \"Let `s` be a subset of an additive monoid `M` such that the closure of `s` is\n      the whole monoid. Then `AddMonoidHom.ofClosureEqTopLeft` defines an additive monoid\n      homomorphism from `M` asking for a proof of `f (x + y) = f x + f y` only for `x \u2208 s`. \"]\ndef ofClosureMEqTopLeft {M N} [Monoid M] [Monoid N] {s : Set M} (f : M \u2192 N) (hs : closure s = \u22a4)\n    (h1 : f 1 = 1) (hmul : \u2200 x \u2208 s, \u2200 (y), f (x * y) = f x * f y) :\n    M \u2192* N where\n  toFun := f\n  map_one' := h1\n  map_mul' x :=\n    (dense_induction (p := _) x hs hmul fun y => by rw [one_mul, h1, one_mul]) fun a b ha hb y => by\n      rw [mul_assoc, ha, ha, hb, mul_assoc]\n#align monoid_hom.of_mclosure_eq_top_left MonoidHom.ofClosureMEqTopLeft\n#align add_monoid_hom.of_mclosure_eq_top_left AddMonoidHom.ofClosureMEqTopLeft\n\n@[to_additive (attr := simp, norm_cast)]\n\n\n/-- Let `s` be a subset of a monoid `M` such that the closure of `s` is the whole monoid.\nThen `MonoidHom.ofClosureEqTopRight` defines a monoid homomorphism from `M` asking for\na proof of `f (x * y) = f x * f y` only for `y \u2208 s`. -/\n@[to_additive\n      \"Let `s` be a subset of an additive monoid `M` such that the closure of `s` is\n      the whole monoid. Then `AddMonoidHom.ofClosureEqTopRight` defines an additive monoid\n      homomorphism from `M` asking for a proof of `f (x + y) = f x + f y` only for `y \u2208 s`. \"]\ndef ofClosureMEqTopRight {M N} [Monoid M] [Monoid N] {s : Set M} (f : M \u2192 N) (hs : closure s = \u22a4)\n    (h1 : f 1 = 1) (hmul : \u2200 (x), \u2200 y \u2208 s, f (x * y) = f x * f y) :\n    M \u2192* N where\n  toFun := f\n  map_one' := h1\n  map_mul' x y :=\n    dense_induction y hs (fun y hy x => hmul x y hy) (by simp [h1])\n      (fun y\u2081 y\u2082 (h\u2081 : \u2200 x, f _ = f _ * f _) (h\u2082 : \u2200 x, f _ = f _ * f _) x => by\n        simp [\u2190 mul_assoc, h\u2081, h\u2082]) x\n#align monoid_hom.of_mclosure_eq_top_right MonoidHom.ofClosureMEqTopRight\n#align add_monoid_hom.of_mclosure_eq_top_right AddMonoidHom.ofClosureMEqTopRight\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_ofClosureMEqTopRight (f : M \u2192 N) (hs : closure s = \u22a4) (h1 hmul) :\n    \u21d1(ofClosureMEqTopRight f hs h1 hmul) = f :=\n  rfl\n#align monoid_hom.coe_of_mclosure_eq_top_right MonoidHom.coe_ofClosureMEqTopRight\n#align add_monoid_hom.coe_of_mclosure_eq_top_right AddMonoidHom.coe_ofClosureMEqTopRight\n\nend MonoidHom\n\nend Assoc\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/Submonoid/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.716651112949982}}
{"text": "/-\n(1) Boo! Happy Halloween!\n(2) You gotta love the \u2115s!\n(3) Notes from Tue in IN\n(4) Weather warning.\n(3) No exam on Tuesday. \n-/\n\n/-\nReview: We define day to be a type.\n-/\ninductive day : Type\n/-\nType is the type of *computational* types.\nConstructors define the values of the type.\n-/\n| mon \n| tue\n| wed\n| thu\n| fri\n| sat\n| sun\n\n/-\nNow we can define variables of this type.\n-/\n\nopen day \n\ndef d : day :=\n    tue\n\n/-\nNEW IDEA: another syntax for defintions\nDefinition now given by a \"PROOF SCRIPT\"\n-/\n\ndef d' : day := \nbegin\n    exact sat,\nend\n\n\n\n/-\n***************************************\nPropositions as Types, Proofs as Values\n***************************************\n-/\n\n\n/-\nWe define emily's_from_cville to be a new\nkind of type: a logical type as opposed to\na computational type. We understand this\n*type* to represent a proposition. Now the\nquestion, is what does it mean to have a\nproof of such a proposition? \n\nInformally, we might say that we'll take\na driver's license, passport, or utility\nbill as a proof. We can formalize this idea\nby defining drivers_license, passport, and\nproof to be *values* of this type! We have\na proof of a proposition if we can produce\na value of its type!\n-/\ninductive emily's_from_cville : Prop\n/- \nConstructors define the values, which we \nnow accept as \"proofs\" of the proposition\nProofs in Lean are values of *logical* types.\n-/\n| drivers_license \n| passport\n| utility_bill\n\nopen emily's_from_cville \n\n\n-- Proofs represented formally as *values*\ndef a_proof : emily's_from_cville  := \n    passport\n\ntheorem a_proof' : emily's_from_cville :=\n    utility_bill\n\ntheorem a_proof'' : emily's_from_cville  :=\nbegin\n    exact utility_bill,\nend\n\n/-\nNote the use of def in the first example and\ntheorem in the second. There is no practical\ndifference. We use \"theorem\" to inform the\nreader that we intend to produce a proof of\na proposition.\n-/\n\n\n/-\n****************************************\nPredicates as parameterized propositions\n****************************************\n-/\n\n/-\nHere's aother data (computational) type.\n-/\ninductive person : Type\n| mari\n| jose\n| jane\n| bill\n\nopen person\n\ninductive mari_is_from_cville : Prop\n| yes_she_is\n\n#check mari_is_from_cville \n\nopen mari_is_from_cville\n\ntheorem mari_proof : mari_is_from_cville := yes_she_is\n\n/-\nWe can generalize from a specific proposition,\nsuch as *emily* is from charlottesville to one\nthat allows us to assert that any given person\nis from charlottesville. We do this by adding \na parameter.\n\nThe result is what we call a predicate. We can\nsay that a predicate is a proposition with a \nparameter. When applied to an argument of the \nright type, the result is again a proposition. \n\nEx: inductive is_from_cville : person \u2192 Prop\n\nThe constructors of the parameterized type define \nthe set of proofs that can be produced for  each\nof the corresponding propositions.\n-/\n\ninductive is_from_cville : person \u2192 Prop\n| proof_for : \n    \u2200 (p : person), \n        p = mari \u2192 is_from_cville p\n\n#check is_from_cville\n#check is_from_cville mari\n#check is_from_cville jose\n#check is_from_cville jane\n#check is_from_cville bill\n\nopen is_from_cville \n\n#check proof_for\n/-\nThink of a proof of a \"\u2200\" proposition \nas being like a function. A constructor\nis a proof. In particular, proof_for can\nbe understood as a proof of the \u2200 claim.\nSo we can treat proof_for as a function\nthat takes a person as an argument and\nthat returns a proposition, obtained by\napplying the predicate on the right of \nthe comma to the given argument.\n-/  \n#check proof_for mari\n#check proof_for jose\n#check proof_for bill\n\ntheorem mifc : is_from_cville mari := \nbegin\n    apply proof_for _ _,\n    apply eq.refl mari,\nend\n\ntheorem bifc : is_from_cville bill := \nbegin\n    apply proof_for,\n    _\nend\n\n/-\nWhat we're seeing here is what we call\nthe elimination principle for proofs of\n\u2200 propositions. We can treat such a proof\nas a function and apply it to a particular\nobject of the quantified type to get a\nproof for the stated proposition *about\nthat particular object*.\n\nHere' we get back proofs of proposition\nsuch as mari = mari \u2192 is_from_cvill mari\nand bill = mari \u2192 is_from_cville bill. \n\nEach of these is a proof of an implication,\nof the form P \u2192 Q, which we can also treat\nas a kind of function: if we can produce a\nproof of a premise, then we can apply the\nproof-of-implication/function to it to get\na proof of the conclusion. \n\nIn this case, we will be able to construct\nand thereby obtain a proof of mari = mari,\nbut there is no proof of bill = mari, so we\nwill be able to construct a proof of the\nproposition, (is_from_cville mari) but not\none of (is_from_cville bill).\n-/\n\n/-\nUnderstand that the constructors of a type are to\nbe understood as the \"axioms,\" or fundamental rules\nof reasoning, for a given type. They tell us exactly\nhow we can produce values (or proofs) of a given type\n(or proposition, understood as a type).\n-/\n\n/-\nAs an example, suppose we to prove the proposition\nthat mari is from cville. Formally we'd state this\nas the proposition (is_from_cville mari). To prove it, \nwe need to construct a proof. To do that, we have to\nuse the only available \"reasoning rule\", which is\ngiven by the one constructor for this type, namely:\n\nproof_for : \u2200 (p : person), p = mari \u2192 is_from_cville p\n\nWhat this says is that for any person, p, *if* you\nhave a proof that (p = mari) then you can derive a\nproof of (is_from_cville mari).\n\nIn plain English, the proof would thus go like this:\n\n\"To produce a proof of (is_from_cville mari) we first\napply the `proof_for' rule to mari to conclude that\n(mari = mari) \u2192 is_from_cville mari. To prove the\nconclusion, it will suffice to produce a proof of\n(mari = mari). But this follows from the reflexivity\nof the equality relation. QED.\"\n\nNow look at what happens if we try to prove jane is \nfrom cville. We apply proof_for to jane, yielding the \nproposition, (jane = mari) \u2192 is_from_cville jane. The\nconclusion is what we want, but to reach it, we have\nto produce a proof of (jane = mari), and there is no\nway to do that because jane and mari are different\npeople. So we are stuck, with no way to build the \nproof we require.\n-/\n\n/-\n******************************************\nPredicates define properties and relations\n****************************************** \n-/\n\n/-\nThe is_from_cville predicate defines the\n\"property\" of being from Charlottesville.\nOnly mari has this property according to\nour definitions, because only for mari is\nthere a proof.\n\nA predicate of one argument defines proofs\nfor none, some, or all values of its argument\ntype and thereby identifies those with the\ngiven property.\n\nA predicate of two arguments similarly \ndefines a *relation*: a set of pairs of\nvalues that have a given property. The\nequality relation is a very good example.\n\nWe accept as an axiom that there is a \nproof for every proposition of the form,\na = a, no matter what type of thing a is,\nand that there are no other proofs of\nequalities. (Slight footnote here.)\n\nThis idea is formalized in Lean with a\npredicate called that takes two arguments \n(of any given type -- it's polymorphic),\nfor which there's a proof only if both\nare the same. Convention infix notation\nuses the = operator.\n-/\n\n#check eq 4 4\n#check eq 4 5\n#check 4 = 5\n#check eq \"Hi\" \"Hi\"\n\n/-\nEach of these terms is a proposition/type.\nThere are proofs for those that are true!\nThe proofs are constructed by a constructor\ncalled refl defined for the eq type. We\nrefer to it as eq.refl. It takes *one*\nargument, a, and yields a proof/value of\ntype a = a. It's thus impossible to create\na proof of a = b unless a and b are really\nequal to each other!\n-/\n\n#check (eq.refl 3)\n#check (eq.refl \"Hi\")\n#check (eq.refl mari)\n\n/-\nThe term, (proof_for mari (eq.refl mari)), is accepted\nas a value of type (is_from_cville mari), i.e., as a \nproof that mari is from charlottesville. Can we construct\na proof\n-/\n\ntheorem mari_is_from_cville' : is_from_cville mari :=\nbegin\n    apply proof_for mari _,\n    exact (eq.refl mari),\n    _\nend\n\n-- YAY!\n\ntheorem mari_is_from_cville'' : is_from_cville mari :=\nbegin\n    apply proof_for _ _,    -- lean infer first arg!\n    --exact mari,\n    exact (eq.refl mari),\nend\n\ntheorem bill_is_from_cville : is_from_cville bill :=\nbegin\n    apply proof_for _ _,    -- lean infer first arg!\n    --exact mari,\n    exact (eq.refl mari),   -- no way\nend\n\n/-\nEnd of lecture\n-/\n\n\n/-\nSome comments about function definitions.\nConsider the following simple definition.\n-/\n\ndef evenb (n : \u2115) : bool :=    \n    n % 2 = 0\n\n#eval evenb 3\n#eval evenb 4\n\n#check evenb\n\ndef evenb' : \u2115 \u2192 bool :=\n    \u03bb n, n % 2 = 0\n\ndef evenb'' : \u03a0 (n : \u2115), bool :=\n    \u03bb n, n % 2 = 0\n\n#eval evenb'' 5\n\ndef evenb''' : \u2200 (n : \u2115), bool :=\n    \u03bb n, n % 2 = 0\n\n#eval evenb''' 6\n\n/-\nPredicates are often used to represent properties\nof objects, here, a property of people, namely\nthe property of a person being from Cville.\n-/\n\ninductive is_zero : \u2115 \u2192 Prop\n| zmk: \u2200 (n : \u2115), n = 0 \u2192 is_zero n\n\nopen is_zero\n\ntheorem zero_is_zero_0 : is_zero 0 :=\n    zmk 0 (eq.refl 0)\n\n/-\nEven: inductively defined proofs\n-/\n\ninductive is_even : \u2115 \u2192 Prop\n| pf_zero_is_even : (is_even 0)\n| pf_even_plus_two_is_even : \n    \u2200 (n : \u2115), is_even n \u2192 is_even (nat.succ (nat.succ n))\n\nopen is_even \n\ntheorem zero_is_even : is_even 0 :=\n    pf_zero_is_even\n\ntheorem zero_is_even' : is_even 0 :=\nbegin\n    exact pf_zero_is_even\nend\n\n/-\nInductive\n-/\n\ntheorem two_is_even : is_even 2 :=\n    pf_even_plus_two_is_even 0 zero_is_even\n\ntheorem four_is_even : is_even 4 :=\n    pf_even_plus_two_is_even 2 two_is_even\n\ntheorem ten_is_even : is_even 1000 :=\nbegin\n    repeat { apply pf_even_plus_two_is_even },\n    exact pf_zero_is_even,\nend\n\n#print ten_is_even\n\n\ntheorem two_is_even' : is_even 2 :=\nbegin\n    apply pf_even_plus_two_is_even 0 zero_is_even,\nend\n\ntheorem two_is_even'' : is_even 2 :=\nbegin\n    apply pf_even_plus_two_is_even 0 _,\n    exact zero_is_even,\nend\n\n\ntheorem two_is_even''' : is_even 2 :=\nbegin\n    apply pf_even_plus_two_is_even _ _,\n    exact zero_is_even,\nend\n\ntheorem two_is_even'''' : is_even 2 :=\nbegin\n    apply pf_even_plus_two_is_even,\n    exact zero_is_even,\nend\n\n\n\ntheorem four_is_even' : is_even 4 :=\n    pf_even_plus_two_is_even 2 two_is_even\n\ntheorem four_is_even'' : is_even 4 :=\nbegin\n    apply pf_even_plus_two_is_even 2 two_is_even, \nend \n\ntheorem four_is_even''' : is_even 4 :=\nbegin\n    apply pf_even_plus_two_is_even, \n    apply two_is_even,\nend \n\ntheorem four_is_even'''' : is_even 4 :=\nbegin\n    apply pf_even_plus_two_is_even, \n    apply pf_even_plus_two_is_even, \n    apply zero_is_even,    \nend \n\ntheorem ten_is_even' : is_even 10 :=\nbegin\n    apply pf_even_plus_two_is_even, \n    apply pf_even_plus_two_is_even, \n    apply pf_even_plus_two_is_even, \n    apply pf_even_plus_two_is_even, \n    apply pf_even_plus_two_is_even, \n    exact zero_is_even,    \nend \n\n#print ten_is_even'\n\n-- Here's some automation in Lean\ntheorem ten_is_even'' : is_even 10 :=\nbegin\n    repeat {apply pf_even_plus_two_is_even},\n    exact zero_is_even,    \nend \n\ninductive successor_of : \u2115 \u2192 \u2115 \u2192 Prop\n| mk : \u2200 (n : \u2115), successor_of (nat.succ n) n\n\ntheorem five_succ_four : successor_of 5 4 :=\n    successor_of.mk 4\n\ninductive equal_to_nat : \u2115 \u2192 \u2115 \u2192 Prop\n| refl : \u2200 (n : \u2115), equal_to_nat n n\n\ntheorem five_equals_five : equal_to_nat 5 5 :=\n    equal_to_nat.refl 5\n\ntheorem five_equals_five' : equal_to_nat 5 5 :=\nbegin\n    apply equal_to_nat.refl _,\nend\n\ninductive equal_to_nat' (n : \u2115) :  \u2115 \u2192 Prop\n| refl : \u2200 (n : \u2115), equal_to_nat' n \n\n#check equal_to_nat \n#check equal_to_nat'\n\ntheorem five_eq_five'' : equal_to_nat' 5 5 :=\n    equal_to_nat'.refl 5 5\n\ninductive equal_to {\u03b1 : Type} : \u03b1 \u2192 \u03b1 \u2192 Prop\n| refl : \u2200 (a : \u03b1), equal_to a a", "meta": {"author": "kevinsullivan", "repo": "uva-cs-dm-f19", "sha": "09a950752884bd7ade4be33e9e89a2c4b1927167", "save_path": "github-repos/lean/kevinsullivan-uva-cs-dm-f19", "path": "github-repos/lean/kevinsullivan-uva-cs-dm-f19/uva-cs-dm-f19-09a950752884bd7ade4be33e9e89a2c4b1927167/instructor-notes/2019.10.29.props_and_proofs/2019.10.31.props_and_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7166501086448749}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module probability.independence\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Constructions.Pi\n\n/-!\n# Independence of sets of sets and measure spaces (\u03c3-algebras)\n\n* A family of sets of sets `\u03c0 : \u03b9 \u2192 set (set \u03a9)` is independent with respect to a measure `\u03bc` if for\n  any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 \u2208 \u03c0 i_1, ..., f i_n \u2208 \u03c0 i_n`,\n  `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i) `. It will be used for families of \u03c0-systems.\n* A family of measurable space structures (i.e. of \u03c3-algebras) is independent with respect to a\n  measure `\u03bc` (typically defined on a finer \u03c3-algebra) if the family of sets of measurable sets they\n  define is independent. I.e., `m : \u03b9 \u2192 measurable_space \u03a9` is independent with respect to a\n  measure `\u03bc` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets\n  `f i_1 \u2208 m i_1, ..., f i_n \u2208 m i_n`, then `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i)`.\n* Independence of sets (or events in probabilistic parlance) is defined as independence of the\n  measurable space structures they generate: a set `s` generates the measurable space structure with\n  measurable sets `\u2205, s, s\u1d9c, univ`.\n* Independence of functions (or random variables) is also defined as independence of the measurable\n  space structures they generate: a function `f` for which we have a measurable space `m` on the\n  codomain generates `measurable_space.comap f m`.\n\n## Main statements\n\n* `Indep_sets.Indep`: if \u03c0-systems are independent as sets of sets, then the\n  measurable space structures they generate are independent.\n* `indep_sets.indep`: variant with two \u03c0-systems.\n* `measure_zero_or_one_of_measurable_set_limsup_at_top`: Kolmogorov's 0-1 law. Any set which is\n  measurable with respect to the tail \u03c3-algebra `limsup s at_top` of an independent sequence of\n  \u03c3-algebras `s` has probability 0 or 1.\n\n## Implementation notes\n\nWe provide one main definition of independence:\n* `Indep_sets`: independence of a family of sets of sets `pi : \u03b9 \u2192 set (set \u03a9)`.\nThree other independence notions are defined using `Indep_sets`:\n* `Indep`: independence of a family of measurable space structures `m : \u03b9 \u2192 measurable_space \u03a9`,\n* `Indep_set`: independence of a family of sets `s : \u03b9 \u2192 set \u03a9`,\n* `Indep_fun`: independence of a family of functions. For measurable spaces\n  `m : \u03a0 (i : \u03b9), measurable_space (\u03b2 i)`, we consider functions `f : \u03a0 (i : \u03b9), \u03a9 \u2192 \u03b2 i`.\n\nAdditionally, we provide four corresponding statements for two measurable space structures (resp.\nsets of sets, sets, functions) instead of a family. These properties are denoted by the same names\nas for a family, but without a capital letter, for example `indep_fun` is the version of `Indep_fun`\nfor two functions.\n\nThe definition of independence for `Indep_sets` uses finite sets (`finset`). An alternative and\nequivalent way of defining independence would have been to use countable sets.\nTODO: prove that equivalence.\n\nMost of the definitions and lemma in this file list all variables instead of using the `variables`\nkeyword at the beginning of a section, for example\n`lemma indep.symm {\u03a9} {m\u2081 m\u2082 : measurable_space \u03a9} [measurable_space \u03a9] {\u03bc : measure \u03a9} ...` .\nThis is intentional, to be able to control the order of the `measurable_space` variables. Indeed\nwhen defining `\u03bc` in the example above, the measurable space used is the last one defined, here\n`[measurable_space \u03a9]`, and not `m\u2081` or `m\u2082`.\n\n## References\n\n* Williams, David. Probability with martingales. Cambridge university press, 1991.\nPart A, Chapter 4.\n-/\n\n\nopen MeasureTheory MeasurableSpace\n\nopen BigOperators MeasureTheory ENNReal\n\nnamespace ProbabilityTheory\n\nvariable {\u03a9 \u03b9 : Type _}\n\nsection Definitions\n\n/-- A family of sets of sets `\u03c0 : \u03b9 \u2192 set (set \u03a9)` is independent with respect to a measure `\u03bc` if\nfor any finite set of indices `s = {i_1, ..., i_n}`, for any sets\n`f i_1 \u2208 \u03c0 i_1, ..., f i_n \u2208 \u03c0 i_n`, then `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i) `.\nIt will be used for families of pi_systems. -/\ndef IndepSets [MeasurableSpace \u03a9] (\u03c0 : \u03b9 \u2192 Set (Set \u03a9))\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  \u2200 (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03a9} (H : \u2200 i, i \u2208 s \u2192 f i \u2208 \u03c0 i),\n    \u03bc (\u22c2 i \u2208 s, f i) = \u220f i in s, \u03bc (f i)\n#align probability_theory.Indep_sets ProbabilityTheory.IndepSets\n\n/-- Two sets of sets `s\u2081, s\u2082` are independent with respect to a measure `\u03bc` if for any sets\n`t\u2081 \u2208 p\u2081, t\u2082 \u2208 s\u2082`, then `\u03bc (t\u2081 \u2229 t\u2082) = \u03bc (t\u2081) * \u03bc (t\u2082)` -/\ndef IndepSetsCat [MeasurableSpace \u03a9] (s1 s2 : Set (Set \u03a9))\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  \u2200 t1 t2 : Set \u03a9, t1 \u2208 s1 \u2192 t2 \u2208 s2 \u2192 \u03bc (t1 \u2229 t2) = \u03bc t1 * \u03bc t2\n#align probability_theory.indep_sets ProbabilityTheory.IndepSetsCat\n\n/-- A family of measurable space structures (i.e. of \u03c3-algebras) is independent with respect to a\nmeasure `\u03bc` (typically defined on a finer \u03c3-algebra) if the family of sets of measurable sets they\ndefine is independent. `m : \u03b9 \u2192 measurable_space \u03a9` is independent with respect to measure `\u03bc` if\nfor any finite set of indices `s = {i_1, ..., i_n}`, for any sets\n`f i_1 \u2208 m i_1, ..., f i_n \u2208 m i_n`, then `\u03bc (\u22c2 i in s, f i) = \u220f i in s, \u03bc (f i) `. -/\ndef Indep (m : \u03b9 \u2192 MeasurableSpace \u03a9) [MeasurableSpace \u03a9]\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  IndepSets (fun x => { s | measurable_set[m x] s }) \u03bc\n#align probability_theory.Indep ProbabilityTheory.Indep\n\n/-- Two measurable space structures (or \u03c3-algebras) `m\u2081, m\u2082` are independent with respect to a\nmeasure `\u03bc` (defined on a third \u03c3-algebra) if for any sets `t\u2081 \u2208 m\u2081, t\u2082 \u2208 m\u2082`,\n`\u03bc (t\u2081 \u2229 t\u2082) = \u03bc (t\u2081) * \u03bc (t\u2082)` -/\ndef IndepCat (m\u2081 m\u2082 : MeasurableSpace \u03a9) [MeasurableSpace \u03a9]\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  IndepSetsCat { s | measurable_set[m\u2081] s } { s | measurable_set[m\u2082] s } \u03bc\n#align probability_theory.indep ProbabilityTheory.IndepCat\n\n/-- A family of sets is independent if the family of measurable space structures they generate is\nindependent. For a set `s`, the generated measurable space has measurable sets `\u2205, s, s\u1d9c, univ`. -/\ndef IndepSet [MeasurableSpace \u03a9] (s : \u03b9 \u2192 Set \u03a9)\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  Indep (fun i => generateFrom {s i}) \u03bc\n#align probability_theory.Indep_set ProbabilityTheory.IndepSet\n\n/-- Two sets are independent if the two measurable space structures they generate are independent.\nFor a set `s`, the generated measurable space structure has measurable sets `\u2205, s, s\u1d9c, univ`. -/\ndef IndepSetCat [MeasurableSpace \u03a9] (s t : Set \u03a9)\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  IndepCat (generateFrom {s}) (generateFrom {t}) \u03bc\n#align probability_theory.indep_set ProbabilityTheory.IndepSetCat\n\n/-- A family of functions defined on the same space `\u03a9` and taking values in possibly different\nspaces, each with a measurable space structure, is independent if the family of measurable space\nstructures they generate on `\u03a9` is independent. For a function `g` with codomain having measurable\nspace structure `m`, the generated measurable space structure is `measurable_space.comap g m`. -/\ndef IndepFun [MeasurableSpace \u03a9] {\u03b2 : \u03b9 \u2192 Type _} (m : \u2200 x : \u03b9, MeasurableSpace (\u03b2 x))\n    (f : \u2200 x : \u03b9, \u03a9 \u2192 \u03b2 x) (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  Indep (fun x => MeasurableSpace.comap (f x) (m x)) \u03bc\n#align probability_theory.Indep_fun ProbabilityTheory.IndepFun\n\n/-- Two functions are independent if the two measurable space structures they generate are\nindependent. For a function `f` with codomain having measurable space structure `m`, the generated\nmeasurable space structure is `measurable_space.comap f m`. -/\ndef IndepFunCat {\u03b2 \u03b3} [MeasurableSpace \u03a9] [m\u03b2 : MeasurableSpace \u03b2] [m\u03b3 : MeasurableSpace \u03b3]\n    (f : \u03a9 \u2192 \u03b2) (g : \u03a9 \u2192 \u03b3) (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : Prop :=\n  IndepCat (MeasurableSpace.comap f m\u03b2) (MeasurableSpace.comap g m\u03b3) \u03bc\n#align probability_theory.indep_fun ProbabilityTheory.IndepFunCat\n\nend Definitions\n\nsection Indep\n\n@[symm]\ntheorem IndepSetsCat.symm {s\u2081 s\u2082 : Set (Set \u03a9)} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h : IndepSetsCat s\u2081 s\u2082 \u03bc) : IndepSetsCat s\u2082 s\u2081 \u03bc :=\n  by\n  intro t1 t2 ht1 ht2\n  rw [Set.inter_comm, mul_comm]\n  exact h t2 t1 ht2 ht1\n#align probability_theory.indep_sets.symm ProbabilityTheory.IndepSetsCat.symm\n\n@[symm]\ntheorem IndepCat.symm {m\u2081 m\u2082 : MeasurableSpace \u03a9} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h : IndepCat m\u2081 m\u2082 \u03bc) : IndepCat m\u2082 m\u2081 \u03bc :=\n  IndepSetsCat.symm h\n#align probability_theory.indep.symm ProbabilityTheory.IndepCat.symm\n\ntheorem indepBotRight (m' : MeasurableSpace \u03a9) {m : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9}\n    [IsProbabilityMeasure \u03bc] : IndepCat m' \u22a5 \u03bc :=\n  by\n  intro s t hs ht\n  rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht\n  cases ht\n  \u00b7 rw [ht, Set.inter_empty, measure_empty, MulZeroClass.mul_zero]\n  \u00b7 rw [ht, Set.inter_univ, measure_univ, mul_one]\n#align probability_theory.indep_bot_right ProbabilityTheory.indepBotRight\n\ntheorem indepBotLeft (m' : MeasurableSpace \u03a9) {m : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9}\n    [IsProbabilityMeasure \u03bc] : IndepCat \u22a5 m' \u03bc :=\n  (indepBotRight m').symm\n#align probability_theory.indep_bot_left ProbabilityTheory.indepBotLeft\n\ntheorem indepSetEmptyRight {m : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} [IsProbabilityMeasure \u03bc]\n    (s : Set \u03a9) : IndepSetCat s \u2205 \u03bc :=\n  by\n  simp only [indep_set, generate_from_singleton_empty]\n  exact indep_bot_right _\n#align probability_theory.indep_set_empty_right ProbabilityTheory.indepSetEmptyRight\n\ntheorem indepSetEmptyLeft {m : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} [IsProbabilityMeasure \u03bc]\n    (s : Set \u03a9) : IndepSetCat \u2205 s \u03bc :=\n  (indepSetEmptyRight s).symm\n#align probability_theory.indep_set_empty_left ProbabilityTheory.indepSetEmptyLeft\n\ntheorem indepSetsOfIndepSetsOfLeLeft {s\u2081 s\u2082 s\u2083 : Set (Set \u03a9)} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h_indep : IndepSetsCat s\u2081 s\u2082 \u03bc) (h31 : s\u2083 \u2286 s\u2081) : IndepSetsCat s\u2083 s\u2082 \u03bc := fun t1 t2 ht1 ht2 =>\n  h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2\n#align probability_theory.indep_sets_of_indep_sets_of_le_left ProbabilityTheory.indepSetsOfIndepSetsOfLeLeft\n\ntheorem indepSetsOfIndepSetsOfLeRight {s\u2081 s\u2082 s\u2083 : Set (Set \u03a9)} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h_indep : IndepSetsCat s\u2081 s\u2082 \u03bc) (h32 : s\u2083 \u2286 s\u2082) : IndepSetsCat s\u2081 s\u2083 \u03bc := fun t1 t2 ht1 ht2 =>\n  h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2)\n#align probability_theory.indep_sets_of_indep_sets_of_le_right ProbabilityTheory.indepSetsOfIndepSetsOfLeRight\n\ntheorem indepOfIndepOfLeLeft {m\u2081 m\u2082 m\u2083 : MeasurableSpace \u03a9} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h_indep : IndepCat m\u2081 m\u2082 \u03bc) (h31 : m\u2083 \u2264 m\u2081) : IndepCat m\u2083 m\u2082 \u03bc := fun t1 t2 ht1 ht2 =>\n  h_indep t1 t2 (h31 _ ht1) ht2\n#align probability_theory.indep_of_indep_of_le_left ProbabilityTheory.indepOfIndepOfLeLeft\n\ntheorem indepOfIndepOfLeRight {m\u2081 m\u2082 m\u2083 : MeasurableSpace \u03a9} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h_indep : IndepCat m\u2081 m\u2082 \u03bc) (h32 : m\u2083 \u2264 m\u2082) : IndepCat m\u2081 m\u2083 \u03bc := fun t1 t2 ht1 ht2 =>\n  h_indep t1 t2 ht1 (h32 _ ht2)\n#align probability_theory.indep_of_indep_of_le_right ProbabilityTheory.indepOfIndepOfLeRight\n\ntheorem IndepSetsCat.union [MeasurableSpace \u03a9] {s\u2081 s\u2082 s' : Set (Set \u03a9)} {\u03bc : Measure \u03a9}\n    (h\u2081 : IndepSetsCat s\u2081 s' \u03bc) (h\u2082 : IndepSetsCat s\u2082 s' \u03bc) : IndepSetsCat (s\u2081 \u222a s\u2082) s' \u03bc :=\n  by\n  intro t1 t2 ht1 ht2\n  cases' (Set.mem_union _ _ _).mp ht1 with ht1\u2081 ht1\u2082\n  \u00b7 exact h\u2081 t1 t2 ht1\u2081 ht2\n  \u00b7 exact h\u2082 t1 t2 ht1\u2082 ht2\n#align probability_theory.indep_sets.union ProbabilityTheory.IndepSetsCat.union\n\n@[simp]\ntheorem IndepSetsCat.union_iff [MeasurableSpace \u03a9] {s\u2081 s\u2082 s' : Set (Set \u03a9)} {\u03bc : Measure \u03a9} :\n    IndepSetsCat (s\u2081 \u222a s\u2082) s' \u03bc \u2194 IndepSetsCat s\u2081 s' \u03bc \u2227 IndepSetsCat s\u2082 s' \u03bc :=\n  \u27e8fun h =>\n    \u27e8indepSetsOfIndepSetsOfLeLeft h (Set.subset_union_left s\u2081 s\u2082),\n      indepSetsOfIndepSetsOfLeLeft h (Set.subset_union_right s\u2081 s\u2082)\u27e9,\n    fun h => IndepSetsCat.union h.left h.right\u27e9\n#align probability_theory.indep_sets.union_iff ProbabilityTheory.IndepSetsCat.union_iff\n\n/- warning: probability_theory.indep_sets.Union clashes with probability_theory.indep_sets.union -> ProbabilityTheory.IndepSetsCat.union\nwarning: probability_theory.indep_sets.Union -> ProbabilityTheory.IndepSetsCat.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03a9 : Type.{u_1}} {\u03b9 : Type.{u_2}} [_inst_1 : MeasurableSpace.{u_1} \u03a9] {s : \u03b9 -> (Set.{u_1} (Set.{u_1} \u03a9))} {s' : Set.{u_1} (Set.{u_1} \u03a9)} {\u03bc : MeasureTheory.Measure.{u_1} \u03a9 _inst_1}, (forall (n : \u03b9), ProbabilityTheory.IndepSetsCat.{u_1} \u03a9 _inst_1 (s n) s' \u03bc) -> (ProbabilityTheory.IndepSetsCat.{u_1} \u03a9 _inst_1 (Set.union\u1d62.{u_1, succ u_2} (Set.{u_1} \u03a9) \u03b9 (fun (n : \u03b9) => s n)) s' \u03bc)\nbut is expected to have type\n  PUnit.{0}\nCase conversion may be inaccurate. Consider using '#align probability_theory.indep_sets.Union ProbabilityTheory.IndepSetsCat.union\u2093'. -/\ntheorem IndepSetsCat.union [MeasurableSpace \u03a9] {s : \u03b9 \u2192 Set (Set \u03a9)} {s' : Set (Set \u03a9)}\n    {\u03bc : Measure \u03a9} (hyp : \u2200 n, IndepSetsCat (s n) s' \u03bc) : IndepSetsCat (\u22c3 n, s n) s' \u03bc :=\n  by\n  intro t1 t2 ht1 ht2\n  rw [Set.mem_union\u1d62] at ht1\n  cases' ht1 with n ht1\n  exact hyp n t1 t2 ht1 ht2\n#align probability_theory.indep_sets.Union ProbabilityTheory.IndepSetsCat.union\n\ntheorem IndepSetsCat.bUnion [MeasurableSpace \u03a9] {s : \u03b9 \u2192 Set (Set \u03a9)} {s' : Set (Set \u03a9)}\n    {\u03bc : Measure \u03a9} {u : Set \u03b9} (hyp : \u2200 n \u2208 u, IndepSetsCat (s n) s' \u03bc) :\n    IndepSetsCat (\u22c3 n \u2208 u, s n) s' \u03bc := by\n  intro t1 t2 ht1 ht2\n  simp_rw [Set.mem_union\u1d62] at ht1\n  rcases ht1 with \u27e8n, hpn, ht1\u27e9\n  exact hyp n hpn t1 t2 ht1 ht2\n#align probability_theory.indep_sets.bUnion ProbabilityTheory.IndepSetsCat.bUnion\n\ntheorem IndepSetsCat.inter [MeasurableSpace \u03a9] {s\u2081 s' : Set (Set \u03a9)} (s\u2082 : Set (Set \u03a9))\n    {\u03bc : Measure \u03a9} (h\u2081 : IndepSetsCat s\u2081 s' \u03bc) : IndepSetsCat (s\u2081 \u2229 s\u2082) s' \u03bc :=\n  fun t1 t2 ht1 ht2 => h\u2081 t1 t2 ((Set.mem_inter_iff _ _ _).mp ht1).left ht2\n#align probability_theory.indep_sets.inter ProbabilityTheory.IndepSetsCat.inter\n\n/- warning: probability_theory.indep_sets.Inter clashes with probability_theory.indep_sets.inter -> ProbabilityTheory.IndepSetsCat.inter\nwarning: probability_theory.indep_sets.Inter -> ProbabilityTheory.IndepSetsCat.inter is a dubious translation:\nlean 3 declaration is\n  forall {\u03a9 : Type.{u_1}} {\u03b9 : Type.{u_2}} [_inst_1 : MeasurableSpace.{u_1} \u03a9] {s : \u03b9 -> (Set.{u_1} (Set.{u_1} \u03a9))} {s' : Set.{u_1} (Set.{u_1} \u03a9)} {\u03bc : MeasureTheory.Measure.{u_1} \u03a9 _inst_1}, (Exists.{succ u_2} \u03b9 (fun (n : \u03b9) => ProbabilityTheory.IndepSetsCat.{u_1} \u03a9 _inst_1 (s n) s' \u03bc)) -> (ProbabilityTheory.IndepSetsCat.{u_1} \u03a9 _inst_1 (Set.inter\u1d62.{u_1, succ u_2} (Set.{u_1} \u03a9) \u03b9 (fun (n : \u03b9) => s n)) s' \u03bc)\nbut is expected to have type\n  PUnit.{0}\nCase conversion may be inaccurate. Consider using '#align probability_theory.indep_sets.Inter ProbabilityTheory.IndepSetsCat.inter\u2093'. -/\ntheorem IndepSetsCat.inter [MeasurableSpace \u03a9] {s : \u03b9 \u2192 Set (Set \u03a9)} {s' : Set (Set \u03a9)}\n    {\u03bc : Measure \u03a9} (h : \u2203 n, IndepSetsCat (s n) s' \u03bc) : IndepSetsCat (\u22c2 n, s n) s' \u03bc :=\n  by\n  intro t1 t2 ht1 ht2\n  cases' h with n h\n  exact h t1 t2 (set.mem_Inter.mp ht1 n) ht2\n#align probability_theory.indep_sets.Inter ProbabilityTheory.IndepSetsCat.inter\n\ntheorem IndepSetsCat.bInter [MeasurableSpace \u03a9] {s : \u03b9 \u2192 Set (Set \u03a9)} {s' : Set (Set \u03a9)}\n    {\u03bc : Measure \u03a9} {u : Set \u03b9} (h : \u2203 n \u2208 u, IndepSetsCat (s n) s' \u03bc) :\n    IndepSetsCat (\u22c2 n \u2208 u, s n) s' \u03bc := by\n  intro t1 t2 ht1 ht2\n  rcases h with \u27e8n, hn, h\u27e9\n  exact h t1 t2 (Set.binter\u1d62_subset_of_mem hn ht1) ht2\n#align probability_theory.indep_sets.bInter ProbabilityTheory.IndepSetsCat.bInter\n\ntheorem indepSetsCat_singleton_iff [MeasurableSpace \u03a9] {s t : Set \u03a9} {\u03bc : Measure \u03a9} :\n    IndepSetsCat {s} {t} \u03bc \u2194 \u03bc (s \u2229 t) = \u03bc s * \u03bc t :=\n  \u27e8fun h => h s t rfl rfl, fun h s1 t1 hs1 ht1 => by\n    rwa [set.mem_singleton_iff.mp hs1, set.mem_singleton_iff.mp ht1]\u27e9\n#align probability_theory.indep_sets_singleton_iff ProbabilityTheory.indepSetsCat_singleton_iff\n\nend Indep\n\n/-! ### Deducing `indep` from `Indep` -/\n\n\nsection FromIndepToIndep\n\ntheorem IndepSets.indepSets {s : \u03b9 \u2192 Set (Set \u03a9)} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h_indep : IndepSets s \u03bc) {i j : \u03b9} (hij : i \u2260 j) : IndepSetsCat (s i) (s j) \u03bc := by\n  classical\n    intro t\u2081 t\u2082 ht\u2081 ht\u2082\n    have hf_m : \u2200 x : \u03b9, x \u2208 {i, j} \u2192 ite (x = i) t\u2081 t\u2082 \u2208 s x :=\n      by\n      intro x hx\n      cases' finset.mem_insert.mp hx with hx hx\n      \u00b7 simp [hx, ht\u2081]\n      \u00b7 simp [finset.mem_singleton.mp hx, hij.symm, ht\u2082]\n    have h1 : t\u2081 = ite (i = i) t\u2081 t\u2082 := by simp only [if_true, eq_self_iff_true]\n    have h2 : t\u2082 = ite (j = i) t\u2081 t\u2082 := by simp only [hij.symm, if_false]\n    have h_inter :\n      (\u22c2 (t : \u03b9) (H : t \u2208 ({i, j} : Finset \u03b9)), ite (t = i) t\u2081 t\u2082) =\n        ite (i = i) t\u2081 t\u2082 \u2229 ite (j = i) t\u2081 t\u2082 :=\n      by simp only [Finset.set_binter\u1d62_singleton, Finset.set_binter\u1d62_insert]\n    have h_prod :\n      (\u220f t : \u03b9 in ({i, j} : Finset \u03b9), \u03bc (ite (t = i) t\u2081 t\u2082)) =\n        \u03bc (ite (i = i) t\u2081 t\u2082) * \u03bc (ite (j = i) t\u2081 t\u2082) :=\n      by\n      simp only [hij, Finset.prod_singleton, Finset.prod_insert, not_false_iff,\n        Finset.mem_singleton]\n    rw [h1]\n    nth_rw 2 [h2]\n    nth_rw 4 [h2]\n    rw [\u2190 h_inter, \u2190 h_prod, h_indep {i, j} hf_m]\n#align probability_theory.Indep_sets.indep_sets ProbabilityTheory.IndepSets.indepSets\n\ntheorem Indep.indep {m : \u03b9 \u2192 MeasurableSpace \u03a9} [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9}\n    (h_indep : Indep m \u03bc) {i j : \u03b9} (hij : i \u2260 j) : IndepCat (m i) (m j) \u03bc :=\n  by\n  change indep_sets ((fun x => measurable_set[m x]) i) ((fun x => measurable_set[m x]) j) \u03bc\n  exact Indep_sets.indep_sets h_indep hij\n#align probability_theory.Indep.indep ProbabilityTheory.Indep.indep\n\ntheorem IndepFun.indepFun {m\u2080 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} {\u03b2 : \u03b9 \u2192 Type _}\n    {m : \u2200 x, MeasurableSpace (\u03b2 x)} {f : \u2200 i, \u03a9 \u2192 \u03b2 i} (hf_Indep : IndepFun m f \u03bc) {i j : \u03b9}\n    (hij : i \u2260 j) : IndepFunCat (f i) (f j) \u03bc :=\n  hf_Indep.indep hij\n#align probability_theory.Indep_fun.indep_fun ProbabilityTheory.IndepFun.indepFun\n\nend FromIndepToIndep\n\n/-!\n## \u03c0-system lemma\n\nIndependence of measurable spaces is equivalent to independence of generating \u03c0-systems.\n-/\n\n\nsection FromMeasurableSpacesToSetsOfSets\n\n/-! ### Independence of measurable space structures implies independence of generating \u03c0-systems -/\n\n\ntheorem Indep.indepSets [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9} {m : \u03b9 \u2192 MeasurableSpace \u03a9}\n    {s : \u03b9 \u2192 Set (Set \u03a9)} (hms : \u2200 n, m n = generateFrom (s n)) (h_indep : Indep m \u03bc) :\n    IndepSets s \u03bc := fun S f hfs =>\n  h_indep S fun x hxS =>\n    ((hms x).symm \u25b8 measurableSet_generateFrom (hfs x hxS) : measurable_set[m x] (f x))\n#align probability_theory.Indep.Indep_sets ProbabilityTheory.Indep.indepSets\n\ntheorem IndepCat.indepSets [MeasurableSpace \u03a9] {\u03bc : Measure \u03a9} {s1 s2 : Set (Set \u03a9)}\n    (h_indep : IndepCat (generateFrom s1) (generateFrom s2) \u03bc) : IndepSetsCat s1 s2 \u03bc :=\n  fun t1 t2 ht1 ht2 =>\n  h_indep t1 t2 (measurableSet_generateFrom ht1) (measurableSet_generateFrom ht2)\n#align probability_theory.indep.indep_sets ProbabilityTheory.IndepCat.indepSets\n\nend FromMeasurableSpacesToSetsOfSets\n\nsection FromPiSystemsToMeasurableSpaces\n\n/-! ### Independence of generating \u03c0-systems implies independence of measurable space structures -/\n\n\nprivate theorem indep_sets.indep_aux {m2 : MeasurableSpace \u03a9} {m : MeasurableSpace \u03a9}\n    {\u03bc : Measure \u03a9} [IsProbabilityMeasure \u03bc] {p1 p2 : Set (Set \u03a9)} (h2 : m2 \u2264 m)\n    (hp2 : IsPiSystem p2) (hpm2 : m2 = generateFrom p2) (hyp : IndepSetsCat p1 p2 \u03bc) {t1 t2 : Set \u03a9}\n    (ht1 : t1 \u2208 p1) (ht2m : measurable_set[m2] t2) : \u03bc (t1 \u2229 t2) = \u03bc t1 * \u03bc t2 :=\n  by\n  let \u03bc_inter := \u03bc.restrict t1\n  let \u03bd := \u03bc t1 \u2022 \u03bc\n  have h_univ : \u03bc_inter Set.univ = \u03bd Set.univ := by\n    rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one]\n  haveI : is_finite_measure \u03bc_inter := @restrict.is_finite_measure \u03a9 _ t1 \u03bc \u27e8measure_lt_top \u03bc t1\u27e9\n  rw [Set.inter_comm, \u2190 measure.restrict_apply (h2 t2 ht2m)]\n  refine' ext_on_measurable_space_of_generate_finite m p2 (fun t ht => _) h2 hpm2 hp2 h_univ ht2m\n  have ht2 : measurable_set[m] t := by\n    refine' h2 _ _\n    rw [hpm2]\n    exact measurable_set_generate_from ht\n  rw [measure.restrict_apply ht2, measure.smul_apply, Set.inter_comm]\n  exact hyp t1 t ht1 ht\n#align probability_theory.indep_sets.indep_aux probability_theory.indep_sets.indep_aux\n\ntheorem IndepSetsCat.indep {m1 m2 : MeasurableSpace \u03a9} {m : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9}\n    [IsProbabilityMeasure \u03bc] {p1 p2 : Set (Set \u03a9)} (h1 : m1 \u2264 m) (h2 : m2 \u2264 m) (hp1 : IsPiSystem p1)\n    (hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2)\n    (hyp : IndepSetsCat p1 p2 \u03bc) : IndepCat m1 m2 \u03bc :=\n  by\n  intro t1 t2 ht1 ht2\n  let \u03bc_inter := \u03bc.restrict t2\n  let \u03bd := \u03bc t2 \u2022 \u03bc\n  have h_univ : \u03bc_inter Set.univ = \u03bd Set.univ := by\n    rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one]\n  haveI : is_finite_measure \u03bc_inter := @restrict.is_finite_measure \u03a9 _ t2 \u03bc \u27e8measure_lt_top \u03bc t2\u27e9\n  rw [mul_comm, \u2190 measure.restrict_apply (h1 t1 ht1)]\n  refine' ext_on_measurable_space_of_generate_finite m p1 (fun t ht => _) h1 hpm1 hp1 h_univ ht1\n  have ht1 : measurable_set[m] t := by\n    refine' h1 _ _\n    rw [hpm1]\n    exact measurable_set_generate_from ht\n  rw [measure.restrict_apply ht1, measure.smul_apply, smul_eq_mul, mul_comm]\n  exact indep_sets.indep_aux h2 hp2 hpm2 hyp ht ht2\n#align probability_theory.indep_sets.indep ProbabilityTheory.IndepSetsCat.indep\n\ntheorem IndepSetsCat.indep' {m : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} [IsProbabilityMeasure \u03bc]\n    {p1 p2 : Set (Set \u03a9)} (hp1m : \u2200 s \u2208 p1, MeasurableSet s) (hp2m : \u2200 s \u2208 p2, MeasurableSet s)\n    (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSetsCat p1 p2 \u03bc) :\n    IndepCat (generateFrom p1) (generateFrom p2) \u03bc :=\n  hyp.indep (generateFrom_le hp1m) (generateFrom_le hp2m) hp1 hp2 rfl rfl\n#align probability_theory.indep_sets.indep' ProbabilityTheory.IndepSetsCat.indep'\n\nvariable {m0 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9}\n\ntheorem indepSetsPiUnionInterOfDisjoint [IsProbabilityMeasure \u03bc] {s : \u03b9 \u2192 Set (Set \u03a9)} {S T : Set \u03b9}\n    (h_indep : IndepSets s \u03bc) (hST : Disjoint S T) :\n    IndepSetsCat (piUnion\u1d62Inter s S) (piUnion\u1d62Inter s T) \u03bc :=\n  by\n  rintro t1 t2 \u27e8p1, hp1, f1, ht1_m, ht1_eq\u27e9 \u27e8p2, hp2, f2, ht2_m, ht2_eq\u27e9\n  classical\n    let g i := ite (i \u2208 p1) (f1 i) Set.univ \u2229 ite (i \u2208 p2) (f2 i) Set.univ\n    have h_P_inter : \u03bc (t1 \u2229 t2) = \u220f n in p1 \u222a p2, \u03bc (g n) :=\n      by\n      have hgm : \u2200 i \u2208 p1 \u222a p2, g i \u2208 s i :=\n        by\n        intro i hi_mem_union\n        rw [Finset.mem_union] at hi_mem_union\n        cases' hi_mem_union with hi1 hi2\n        \u00b7 have hi2 : i \u2209 p2 := fun hip2 => set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2)\n          simp_rw [g, if_pos hi1, if_neg hi2, Set.inter_univ]\n          exact ht1_m i hi1\n        \u00b7 have hi1 : i \u2209 p1 := fun hip1 => set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1)\n          simp_rw [g, if_neg hi1, if_pos hi2, Set.univ_inter]\n          exact ht2_m i hi2\n      have h_p1_inter_p2 :\n        ((\u22c2 x \u2208 p1, f1 x) \u2229 \u22c2 x \u2208 p2, f2 x) =\n          \u22c2 i \u2208 p1 \u222a p2, ite (i \u2208 p1) (f1 i) Set.univ \u2229 ite (i \u2208 p2) (f2 i) Set.univ :=\n        by\n        ext1 x\n        simp only [Set.mem_ite_univ_right, Set.mem_inter_iff, Set.mem_inter\u1d62, Finset.mem_union]\n        exact\n          \u27e8fun h i _ => \u27e8h.1 i, h.2 i\u27e9, fun h =>\n            \u27e8fun i hi => (h i (Or.inl hi)).1 hi, fun i hi => (h i (Or.inr hi)).2 hi\u27e9\u27e9\n      rw [ht1_eq, ht2_eq, h_p1_inter_p2, \u2190 h_indep _ hgm]\n    have h_\u03bcg : \u2200 n, \u03bc (g n) = ite (n \u2208 p1) (\u03bc (f1 n)) 1 * ite (n \u2208 p2) (\u03bc (f2 n)) 1 :=\n      by\n      intro n\n      simp_rw [g]\n      split_ifs\n      \u00b7 exact absurd rfl (set.disjoint_iff_forall_ne.mp hST _ (hp1 h) _ (hp2 h_1))\n      all_goals simp only [measure_univ, one_mul, mul_one, Set.inter_univ, Set.univ_inter]\n    simp_rw [h_P_inter, h_\u03bcg, Finset.prod_mul_distrib,\n      Finset.prod_ite_mem (p1 \u222a p2) p1 fun x => \u03bc (f1 x), Finset.union_inter_cancel_left,\n      Finset.prod_ite_mem (p1 \u222a p2) p2 fun x => \u03bc (f2 x), Finset.union_inter_cancel_right, ht1_eq, \u2190\n      h_indep p1 ht1_m, ht2_eq, \u2190 h_indep p2 ht2_m]\n#align probability_theory.indep_sets_pi_Union_Inter_of_disjoint ProbabilityTheory.indepSetsPiUnionInterOfDisjoint\n\ntheorem IndepSet.indepGenerateFromOfDisjoint [IsProbabilityMeasure \u03bc] {s : \u03b9 \u2192 Set \u03a9}\n    (hsm : \u2200 n, MeasurableSet (s n)) (hs : IndepSet s \u03bc) (S T : Set \u03b9) (hST : Disjoint S T) :\n    IndepCat (generateFrom { t | \u2203 n \u2208 S, s n = t }) (generateFrom { t | \u2203 k \u2208 T, s k = t }) \u03bc :=\n  by\n  rw [\u2190 generateFrom_piUnion\u1d62Inter_singleton_left, \u2190 generateFrom_piUnion\u1d62Inter_singleton_left]\n  refine'\n    indep_sets.indep'\n      (fun t ht => generateFrom_piUnion\u1d62Inter_le _ _ _ _ (measurable_set_generate_from ht))\n      (fun t ht => generateFrom_piUnion\u1d62Inter_le _ _ _ _ (measurable_set_generate_from ht)) _ _ _\n  \u00b7 exact fun k => generate_from_le fun t ht => (Set.mem_singleton_iff.1 ht).symm \u25b8 hsm k\n  \u00b7 exact fun k => generate_from_le fun t ht => (Set.mem_singleton_iff.1 ht).symm \u25b8 hsm k\n  \u00b7 exact isPiSystem_piUnion\u1d62Inter _ (fun k => IsPiSystem.singleton _) _\n  \u00b7 exact isPiSystem_piUnion\u1d62Inter _ (fun k => IsPiSystem.singleton _) _\n  \u00b7 classical exact indep_sets_pi_Union_Inter_of_disjoint (Indep.Indep_sets (fun n => rfl) hs) hST\n#align probability_theory.Indep_set.indep_generate_from_of_disjoint ProbabilityTheory.IndepSet.indepGenerateFromOfDisjoint\n\ntheorem indepSuprOfDisjoint [IsProbabilityMeasure \u03bc] {m : \u03b9 \u2192 MeasurableSpace \u03a9}\n    (h_le : \u2200 i, m i \u2264 m0) (h_indep : Indep m \u03bc) {S T : Set \u03b9} (hST : Disjoint S T) :\n    IndepCat (\u2a06 i \u2208 S, m i) (\u2a06 i \u2208 T, m i) \u03bc :=\n  by\n  refine'\n    indep_sets.indep (sup\u1d62\u2082_le fun i _ => h_le i) (sup\u1d62\u2082_le fun i _ => h_le i) _ _\n      (generateFrom_piUnion\u1d62Inter_measurableSet m S).symm\n      (generateFrom_piUnion\u1d62Inter_measurableSet m T).symm _\n  \u00b7 exact isPiSystem_piUnion\u1d62Inter _ (fun n => @is_pi_system_measurable_set \u03a9 (m n)) _\n  \u00b7 exact isPiSystem_piUnion\u1d62Inter _ (fun n => @is_pi_system_measurable_set \u03a9 (m n)) _\n  \u00b7 classical exact indep_sets_pi_Union_Inter_of_disjoint h_indep hST\n#align probability_theory.indep_supr_of_disjoint ProbabilityTheory.indepSuprOfDisjoint\n\ntheorem indepSuprOfDirectedLe {\u03a9} {m : \u03b9 \u2192 MeasurableSpace \u03a9} {m' m0 : MeasurableSpace \u03a9}\n    {\u03bc : Measure \u03a9} [IsProbabilityMeasure \u03bc] (h_indep : \u2200 i, IndepCat (m i) m' \u03bc)\n    (h_le : \u2200 i, m i \u2264 m0) (h_le' : m' \u2264 m0) (hm : Directed (\u00b7 \u2264 \u00b7) m) : IndepCat (\u2a06 i, m i) m' \u03bc :=\n  by\n  let p : \u03b9 \u2192 Set (Set \u03a9) := fun n => { t | measurable_set[m n] t }\n  have hp : \u2200 n, IsPiSystem (p n) := fun n => @is_pi_system_measurable_set \u03a9 (m n)\n  have h_gen_n : \u2200 n, m n = generate_from (p n) := fun n =>\n    (@generate_from_measurable_set \u03a9 (m n)).symm\n  have hp_supr_pi : IsPiSystem (\u22c3 n, p n) := isPiSystem_union\u1d62_of_directed_le p hp hm\n  let p' := { t : Set \u03a9 | measurable_set[m'] t }\n  have hp'_pi : IsPiSystem p' := @is_pi_system_measurable_set \u03a9 m'\n  have h_gen' : m' = generate_from p' := (@generate_from_measurable_set \u03a9 m').symm\n  -- the \u03c0-systems defined are independent\n  have h_pi_system_indep : indep_sets (\u22c3 n, p n) p' \u03bc :=\n    by\n    refine' indep_sets.Union _\n    simp_rw [h_gen_n, h_gen'] at h_indep\n    exact fun n => (h_indep n).IndepSetsCat\n  -- now go from \u03c0-systems to \u03c3-algebras\n  refine' indep_sets.indep (sup\u1d62_le h_le) h_le' hp_supr_pi hp'_pi _ h_gen' h_pi_system_indep\n  exact (generate_from_Union_measurable_set _).symm\n#align probability_theory.indep_supr_of_directed_le ProbabilityTheory.indepSuprOfDirectedLe\n\ntheorem IndepSet.indepGenerateFromLt [Preorder \u03b9] [IsProbabilityMeasure \u03bc] {s : \u03b9 \u2192 Set \u03a9}\n    (hsm : \u2200 n, MeasurableSet (s n)) (hs : IndepSet s \u03bc) (i : \u03b9) :\n    IndepCat (generateFrom {s i}) (generateFrom { t | \u2203 j < i, s j = t }) \u03bc :=\n  by\n  convert hs.indep_generate_from_of_disjoint hsm {i} { j | j < i }\n      (set.disjoint_singleton_left.mpr (lt_irrefl _))\n  simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton']\n#align probability_theory.Indep_set.indep_generate_from_lt ProbabilityTheory.IndepSet.indepGenerateFromLt\n\ntheorem IndepSet.indepGenerateFromLe [LinearOrder \u03b9] [IsProbabilityMeasure \u03bc] {s : \u03b9 \u2192 Set \u03a9}\n    (hsm : \u2200 n, MeasurableSet (s n)) (hs : IndepSet s \u03bc) (i : \u03b9) {k : \u03b9} (hk : i < k) :\n    IndepCat (generateFrom {s k}) (generateFrom { t | \u2203 j \u2264 i, s j = t }) \u03bc :=\n  by\n  convert hs.indep_generate_from_of_disjoint hsm {k} { j | j \u2264 i }\n      (set.disjoint_singleton_left.mpr hk.not_le)\n  simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton']\n#align probability_theory.Indep_set.indep_generate_from_le ProbabilityTheory.IndepSet.indepGenerateFromLe\n\ntheorem IndepSet.indepGenerateFromLeNat [IsProbabilityMeasure \u03bc] {s : \u2115 \u2192 Set \u03a9}\n    (hsm : \u2200 n, MeasurableSet (s n)) (hs : IndepSet s \u03bc) (n : \u2115) :\n    IndepCat (generateFrom {s (n + 1)}) (generateFrom { t | \u2203 k \u2264 n, s k = t }) \u03bc :=\n  hs.indepGenerateFromLe hsm _ n.lt_succ_self\n#align probability_theory.Indep_set.indep_generate_from_le_nat ProbabilityTheory.IndepSet.indepGenerateFromLeNat\n\ntheorem indepSuprOfMonotone [SemilatticeSup \u03b9] {\u03a9} {m : \u03b9 \u2192 MeasurableSpace \u03a9}\n    {m' m0 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} [IsProbabilityMeasure \u03bc]\n    (h_indep : \u2200 i, IndepCat (m i) m' \u03bc) (h_le : \u2200 i, m i \u2264 m0) (h_le' : m' \u2264 m0)\n    (hm : Monotone m) : IndepCat (\u2a06 i, m i) m' \u03bc :=\n  indepSuprOfDirectedLe h_indep h_le h_le' (Monotone.directed_le hm)\n#align probability_theory.indep_supr_of_monotone ProbabilityTheory.indepSuprOfMonotone\n\ntheorem indepSuprOfAntitone [SemilatticeInf \u03b9] {\u03a9} {m : \u03b9 \u2192 MeasurableSpace \u03a9}\n    {m' m0 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} [IsProbabilityMeasure \u03bc]\n    (h_indep : \u2200 i, IndepCat (m i) m' \u03bc) (h_le : \u2200 i, m i \u2264 m0) (h_le' : m' \u2264 m0)\n    (hm : Antitone m) : IndepCat (\u2a06 i, m i) m' \u03bc :=\n  indepSuprOfDirectedLe h_indep h_le h_le' (directed_of_inf hm)\n#align probability_theory.indep_supr_of_antitone ProbabilityTheory.indepSuprOfAntitone\n\ntheorem IndepSets.piUnionInterOfNotMem {\u03c0 : \u03b9 \u2192 Set (Set \u03a9)} {a : \u03b9} {S : Finset \u03b9}\n    (hp_ind : IndepSets \u03c0 \u03bc) (haS : a \u2209 S) : IndepSetsCat (piUnion\u1d62Inter \u03c0 S) (\u03c0 a) \u03bc :=\n  by\n  rintro t1 t2 \u27e8s, hs_mem, ft1, hft1_mem, ht1_eq\u27e9 ht2_mem_pia\n  rw [Finset.coe_subset] at hs_mem\n  classical\n    let f n := ite (n = a) t2 (ite (n \u2208 s) (ft1 n) Set.univ)\n    have h_f_mem : \u2200 n \u2208 insert a s, f n \u2208 \u03c0 n :=\n      by\n      intro n hn_mem_insert\n      simp_rw [f]\n      cases' finset.mem_insert.mp hn_mem_insert with hn_mem hn_mem\n      \u00b7 simp [hn_mem, ht2_mem_pia]\n      \u00b7 have hn_ne_a : n \u2260 a := by\n          rintro rfl\n          exact haS (hs_mem hn_mem)\n        simp [hn_ne_a, hn_mem, hft1_mem n hn_mem]\n    have h_f_mem_pi : \u2200 n \u2208 s, f n \u2208 \u03c0 n := fun x hxS => h_f_mem x (by simp [hxS])\n    have h_t1 : t1 = \u22c2 n \u2208 s, f n :=\n      by\n      suffices h_forall : \u2200 n \u2208 s, f n = ft1 n\n      \u00b7 rw [ht1_eq]\n        congr with (n x)\n        congr with (hns y)\n        simp only [(h_forall n hns).symm]\n      intro n hnS\n      have hn_ne_a : n \u2260 a := by\n        rintro rfl\n        exact haS (hs_mem hnS)\n      simp_rw [f, if_pos hnS, if_neg hn_ne_a]\n    have h_\u03bc_t1 : \u03bc t1 = \u220f n in s, \u03bc (f n) := by rw [h_t1, \u2190 hp_ind s h_f_mem_pi]\n    have h_t2 : t2 = f a := by\n      simp_rw [f]\n      simp\n    have h_\u03bc_inter : \u03bc (t1 \u2229 t2) = \u220f n in insert a s, \u03bc (f n) :=\n      by\n      have h_t1_inter_t2 : t1 \u2229 t2 = \u22c2 n \u2208 insert a s, f n := by\n        rw [h_t1, h_t2, Finset.set_binter\u1d62_insert, Set.inter_comm]\n      rw [h_t1_inter_t2, \u2190 hp_ind (insert a s) h_f_mem]\n    have has : a \u2209 s := fun has_mem => haS (hs_mem Membership)\n    rw [h_\u03bc_inter, Finset.prod_insert has, h_t2, mul_comm, h_\u03bc_t1]\n#align probability_theory.Indep_sets.pi_Union_Inter_of_not_mem ProbabilityTheory.IndepSets.piUnionInterOfNotMem\n\n/-- The measurable space structures generated by independent pi-systems are independent. -/\ntheorem IndepSets.indep [IsProbabilityMeasure \u03bc] (m : \u03b9 \u2192 MeasurableSpace \u03a9) (h_le : \u2200 i, m i \u2264 m0)\n    (\u03c0 : \u03b9 \u2192 Set (Set \u03a9)) (h_pi : \u2200 n, IsPiSystem (\u03c0 n))\n    (h_generate : \u2200 i, m i = generateFrom (\u03c0 i)) (h_ind : IndepSets \u03c0 \u03bc) : Indep m \u03bc := by\n  classical\n    refine' Finset.induction _ _\n    \u00b7\n      simp only [measure_univ, imp_true_iff, Set.inter\u1d62_false, Set.inter\u1d62_univ, Finset.prod_empty,\n        eq_self_iff_true]\n    intro a S ha_notin_S h_rec f hf_m\n    have hf_m_S : \u2200 x \u2208 S, measurable_set[m x] (f x) := fun x hx => hf_m x (by simp [hx])\n    rw [Finset.set_binter\u1d62_insert, Finset.prod_insert ha_notin_S, \u2190 h_rec hf_m_S]\n    let p := piUnion\u1d62Inter \u03c0 S\n    set m_p := generate_from p with hS_eq_generate\n    have h_indep : indep m_p (m a) \u03bc :=\n      by\n      have hp : IsPiSystem p := isPiSystem_piUnion\u1d62Inter \u03c0 h_pi S\n      have h_le' : \u2200 i, generate_from (\u03c0 i) \u2264 m0 := fun i => (h_generate i).symm.trans_le (h_le i)\n      have hm_p : m_p \u2264 m0 := generateFrom_piUnion\u1d62Inter_le \u03c0 h_le' S\n      exact\n        indep_sets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a)\n          (h_ind.pi_Union_Inter_of_not_mem ha_notin_S)\n    refine' h_indep.symm (f a) (\u22c2 n \u2208 S, f n) (hf_m a (Finset.mem_insert_self a S)) _\n    have h_le_p : \u2200 i \u2208 S, m i \u2264 m_p := by\n      intro n hn\n      rw [hS_eq_generate, h_generate n]\n      exact le_generateFrom_piUnion\u1d62Inter S hn\n    have h_S_f : \u2200 i \u2208 S, measurable_set[m_p] (f i) := fun i hi => (h_le_p i hi) (f i) (hf_m_S i hi)\n    exact S.measurable_set_bInter h_S_f\n#align probability_theory.Indep_sets.Indep ProbabilityTheory.IndepSets.indep\n\nend FromPiSystemsToMeasurableSpaces\n\nsection IndepSet\n\n/-! ### Independence of measurable sets\n\nWe prove the following equivalences on `indep_set`, for measurable sets `s, t`.\n* `indep_set s t \u03bc \u2194 \u03bc (s \u2229 t) = \u03bc s * \u03bc t`,\n* `indep_set s t \u03bc \u2194 indep_sets {s} {t} \u03bc`.\n-/\n\n\nvariable {s t : Set \u03a9} (S T : Set (Set \u03a9))\n\ntheorem indepSetCat_iff_indepSetsCat_singleton {m0 : MeasurableSpace \u03a9} (hs_meas : MeasurableSet s)\n    (ht_meas : MeasurableSet t) (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume)\n    [IsProbabilityMeasure \u03bc] : IndepSetCat s t \u03bc \u2194 IndepSetsCat {s} {t} \u03bc :=\n  \u27e8IndepCat.indepSets, fun h =>\n    IndepSetsCat.indep (generateFrom_le fun u hu => by rwa [set.mem_singleton_iff.mp hu])\n      (generateFrom_le fun u hu => by rwa [set.mem_singleton_iff.mp hu]) (IsPiSystem.singleton s)\n      (IsPiSystem.singleton t) rfl rfl h\u27e9\n#align probability_theory.indep_set_iff_indep_sets_singleton ProbabilityTheory.indepSetCat_iff_indepSetsCat_singleton\n\ntheorem indepSetCat_iff_measure_inter_eq_mul {m0 : MeasurableSpace \u03a9} (hs_meas : MeasurableSet s)\n    (ht_meas : MeasurableSet t) (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume)\n    [IsProbabilityMeasure \u03bc] : IndepSetCat s t \u03bc \u2194 \u03bc (s \u2229 t) = \u03bc s * \u03bc t :=\n  (indepSetCat_iff_indepSetsCat_singleton hs_meas ht_meas \u03bc).trans indepSetsCat_singleton_iff\n#align probability_theory.indep_set_iff_measure_inter_eq_mul ProbabilityTheory.indepSetCat_iff_measure_inter_eq_mul\n\ntheorem IndepSetsCat.indepSetOfMem {m0 : MeasurableSpace \u03a9} (hs : s \u2208 S) (ht : t \u2208 T)\n    (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t)\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) [IsProbabilityMeasure \u03bc]\n    (h_indep : IndepSetsCat S T \u03bc) : IndepSetCat s t \u03bc :=\n  (indepSetCat_iff_measure_inter_eq_mul hs_meas ht_meas \u03bc).mpr (h_indep s t hs ht)\n#align probability_theory.indep_sets.indep_set_of_mem ProbabilityTheory.IndepSetsCat.indepSetOfMem\n\ntheorem IndepCat.indepSetOfMeasurableSet {m\u2081 m\u2082 m0 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9}\n    (h_indep : IndepCat m\u2081 m\u2082 \u03bc) {s t : Set \u03a9} (hs : measurable_set[m\u2081] s)\n    (ht : measurable_set[m\u2082] t) : IndepSetCat s t \u03bc :=\n  by\n  refine' fun s' t' hs' ht' => h_indep s' t' _ _\n  \u00b7 refine' generate_from_induction (fun u => measurable_set[m\u2081] u) {s} _ _ _ _ hs'\n    \u00b7 simp only [hs, Set.mem_singleton_iff, Set.mem_setOf_eq, forall_eq]\n    \u00b7 exact @MeasurableSet.empty _ m\u2081\n    \u00b7 exact fun u hu => hu.compl\n    \u00b7 exact fun f hf => MeasurableSet.union\u1d62 hf\n  \u00b7 refine' generate_from_induction (fun u => measurable_set[m\u2082] u) {t} _ _ _ _ ht'\n    \u00b7 simp only [ht, Set.mem_singleton_iff, Set.mem_setOf_eq, forall_eq]\n    \u00b7 exact @MeasurableSet.empty _ m\u2082\n    \u00b7 exact fun u hu => hu.compl\n    \u00b7 exact fun f hf => MeasurableSet.union\u1d62 hf\n#align probability_theory.indep.indep_set_of_measurable_set ProbabilityTheory.IndepCat.indepSetOfMeasurableSet\n\ntheorem indepCat_iff_forall_indepSetCat (m\u2081 m\u2082 : MeasurableSpace \u03a9) {m0 : MeasurableSpace \u03a9}\n    (\u03bc : Measure \u03a9) :\n    IndepCat m\u2081 m\u2082 \u03bc \u2194 \u2200 s t, measurable_set[m\u2081] s \u2192 measurable_set[m\u2082] t \u2192 IndepSetCat s t \u03bc :=\n  \u27e8fun h => fun s t hs ht => h.indepSetOfMeasurableSet hs ht, fun h s t hs ht =>\n    h s t hs ht s t (measurableSet_generateFrom (Set.mem_singleton s))\n      (measurableSet_generateFrom (Set.mem_singleton t))\u27e9\n#align probability_theory.indep_iff_forall_indep_set ProbabilityTheory.indepCat_iff_forall_indepSetCat\n\nend IndepSet\n\nsection IndepFun\n\n/-! ### Independence of random variables\n\n-/\n\n\nvariable {\u03b2 \u03b2' \u03b3 \u03b3' : Type _} {m\u03a9 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} {f : \u03a9 \u2192 \u03b2} {g : \u03a9 \u2192 \u03b2'}\n\ntheorem indepFunCat_iff_measure_inter_preimage_eq_mul {m\u03b2 : MeasurableSpace \u03b2}\n    {m\u03b2' : MeasurableSpace \u03b2'} :\n    IndepFunCat f g \u03bc \u2194\n      \u2200 s t,\n        MeasurableSet s \u2192 MeasurableSet t \u2192 \u03bc (f \u207b\u00b9' s \u2229 g \u207b\u00b9' t) = \u03bc (f \u207b\u00b9' s) * \u03bc (g \u207b\u00b9' t) :=\n  by\n  constructor <;> intro h\n  \u00b7 refine' fun s t hs ht => h (f \u207b\u00b9' s) (g \u207b\u00b9' t) \u27e8s, hs, rfl\u27e9 \u27e8t, ht, rfl\u27e9\n  \u00b7 rintro _ _ \u27e8s, hs, rfl\u27e9 \u27e8t, ht, rfl\u27e9\n    exact h s t hs ht\n#align probability_theory.indep_fun_iff_measure_inter_preimage_eq_mul ProbabilityTheory.indepFunCat_iff_measure_inter_preimage_eq_mul\n\ntheorem indepFun_iff_measure_inter_preimage_eq_mul {\u03b9 : Type _} {\u03b2 : \u03b9 \u2192 Type _}\n    (m : \u2200 x, MeasurableSpace (\u03b2 x)) (f : \u2200 i, \u03a9 \u2192 \u03b2 i) :\n    IndepFun m f \u03bc \u2194\n      \u2200 (S : Finset \u03b9) {sets : \u2200 i : \u03b9, Set (\u03b2 i)} (H : \u2200 i, i \u2208 S \u2192 measurable_set[m i] (sets i)),\n        \u03bc (\u22c2 i \u2208 S, f i \u207b\u00b9' sets i) = \u220f i in S, \u03bc (f i \u207b\u00b9' sets i) :=\n  by\n  refine' \u27e8fun h S sets h_meas => h _ fun i hi_mem => \u27e8sets i, h_meas i hi_mem, rfl\u27e9, _\u27e9\n  intro h S sets\u03a9 h_meas\n  classical\n    let sets\u03b2 : \u2200 i : \u03b9, Set (\u03b2 i) := fun i =>\n      dite (i \u2208 S) (fun hi_mem => (h_meas i hi_mem).some) fun _ => Set.univ\n    have h_meas\u03b2 : \u2200 i \u2208 S, measurable_set[m i] (sets\u03b2 i) :=\n      by\n      intro i hi_mem\n      simp_rw [sets\u03b2, dif_pos hi_mem]\n      exact (h_meas i hi_mem).choose_spec.1\n    have h_preim : \u2200 i \u2208 S, sets\u03a9 i = f i \u207b\u00b9' sets\u03b2 i :=\n      by\n      intro i hi_mem\n      simp_rw [sets\u03b2, dif_pos hi_mem]\n      exact (h_meas i hi_mem).choose_spec.2.symm\n    have h_left_eq : \u03bc (\u22c2 i \u2208 S, sets\u03a9 i) = \u03bc (\u22c2 i \u2208 S, f i \u207b\u00b9' sets\u03b2 i) :=\n      by\n      congr with (i x)\n      simp only [Set.mem_inter\u1d62]\n      constructor <;> intro h hi_mem <;> specialize h hi_mem\n      \u00b7 rwa [h_preim i hi_mem] at h\n      \u00b7 rwa [h_preim i hi_mem]\n    have h_right_eq : (\u220f i in S, \u03bc (sets\u03a9 i)) = \u220f i in S, \u03bc (f i \u207b\u00b9' sets\u03b2 i) :=\n      by\n      refine' Finset.prod_congr rfl fun i hi_mem => _\n      rw [h_preim i hi_mem]\n    rw [h_left_eq, h_right_eq]\n    exact h S h_meas\u03b2\n#align probability_theory.Indep_fun_iff_measure_inter_preimage_eq_mul ProbabilityTheory.indepFun_iff_measure_inter_preimage_eq_mul\n\ntheorem indepFunCat_iff_indepSetCat_preimage {m\u03b2 : MeasurableSpace \u03b2} {m\u03b2' : MeasurableSpace \u03b2'}\n    [IsProbabilityMeasure \u03bc] (hf : Measurable f) (hg : Measurable g) :\n    IndepFunCat f g \u03bc \u2194\n      \u2200 s t, MeasurableSet s \u2192 MeasurableSet t \u2192 IndepSetCat (f \u207b\u00b9' s) (g \u207b\u00b9' t) \u03bc :=\n  by\n  refine' indep_fun_iff_measure_inter_preimage_eq_mul.trans _\n  constructor <;> intro h s t hs ht <;> specialize h s t hs ht\n  \u00b7 rwa [indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) \u03bc]\n  \u00b7 rwa [\u2190 indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) \u03bc]\n#align probability_theory.indep_fun_iff_indep_set_preimage ProbabilityTheory.indepFunCat_iff_indepSetCat_preimage\n\n@[symm]\ntheorem IndepFunCat.symm {m\u03b2 : MeasurableSpace \u03b2} {f g : \u03a9 \u2192 \u03b2} (hfg : IndepFunCat f g \u03bc) :\n    IndepFunCat g f \u03bc :=\n  hfg.symm\n#align probability_theory.indep_fun.symm ProbabilityTheory.IndepFunCat.symm\n\ntheorem IndepFunCat.aeEq {m\u03b2 : MeasurableSpace \u03b2} {f g f' g' : \u03a9 \u2192 \u03b2} (hfg : IndepFunCat f g \u03bc)\n    (hf : f =\u1d50[\u03bc] f') (hg : g =\u1d50[\u03bc] g') : IndepFunCat f' g' \u03bc :=\n  by\n  rintro _ _ \u27e8A, hA, rfl\u27e9 \u27e8B, hB, rfl\u27e9\n  have h1 : f \u207b\u00b9' A =\u1d50[\u03bc] f' \u207b\u00b9' A := hf.fun_comp A\n  have h2 : g \u207b\u00b9' B =\u1d50[\u03bc] g' \u207b\u00b9' B := hg.fun_comp B\n  rw [\u2190 measure_congr h1, \u2190 measure_congr h2, \u2190 measure_congr (h1.inter h2)]\n  exact hfg _ _ \u27e8_, hA, rfl\u27e9 \u27e8_, hB, rfl\u27e9\n#align probability_theory.indep_fun.ae_eq ProbabilityTheory.IndepFunCat.aeEq\n\ntheorem IndepFunCat.comp {m\u03b2 : MeasurableSpace \u03b2} {m\u03b2' : MeasurableSpace \u03b2'}\n    {m\u03b3 : MeasurableSpace \u03b3} {m\u03b3' : MeasurableSpace \u03b3'} {\u03c6 : \u03b2 \u2192 \u03b3} {\u03c8 : \u03b2' \u2192 \u03b3'}\n    (hfg : IndepFunCat f g \u03bc) (h\u03c6 : Measurable \u03c6) (h\u03c8 : Measurable \u03c8) :\n    IndepFunCat (\u03c6 \u2218 f) (\u03c8 \u2218 g) \u03bc :=\n  by\n  rintro _ _ \u27e8A, hA, rfl\u27e9 \u27e8B, hB, rfl\u27e9\n  apply hfg\n  \u00b7 exact \u27e8\u03c6 \u207b\u00b9' A, h\u03c6 hA, set.preimage_comp.symm\u27e9\n  \u00b7 exact \u27e8\u03c8 \u207b\u00b9' B, h\u03c8 hB, set.preimage_comp.symm\u27e9\n#align probability_theory.indep_fun.comp ProbabilityTheory.IndepFunCat.comp\n\n/-- If `f` is a family of mutually independent random variables (`Indep_fun m f \u03bc`) and `S, T` are\ntwo disjoint finite index sets, then the tuple formed by `f i` for `i \u2208 S` is independent of the\ntuple `(f i)_i` for `i \u2208 T`. -/\ntheorem IndepFun.indepFunFinset [IsProbabilityMeasure \u03bc] {\u03b9 : Type _} {\u03b2 : \u03b9 \u2192 Type _}\n    {m : \u2200 i, MeasurableSpace (\u03b2 i)} {f : \u2200 i, \u03a9 \u2192 \u03b2 i} (S T : Finset \u03b9) (hST : Disjoint S T)\n    (hf_Indep : IndepFun m f \u03bc) (hf_meas : \u2200 i, Measurable (f i)) :\n    IndepFunCat (fun a (i : S) => f i a) (fun a (i : T) => f i a) \u03bc :=\n  by\n  -- We introduce \u03c0-systems, build from the \u03c0-system of boxes which generates `measurable_space.pi`.\n  let \u03c0S\u03b2 :=\n    Set.pi (Set.univ : Set S) ''\n      Set.pi (Set.univ : Set S) fun i => { s : Set (\u03b2 i) | measurable_set[m i] s }\n  let \u03c0S := { s : Set \u03a9 | \u2203 t \u2208 \u03c0S\u03b2, (fun a (i : S) => f i a) \u207b\u00b9' t = s }\n  have h\u03c0S_pi : IsPiSystem \u03c0S := is_pi_system_pi.comap fun a i => f i a\n  have h\u03c0S_gen : (measurable_space.pi.comap fun a (i : S) => f i a) = generate_from \u03c0S :=\n    by\n    rw [generate_from_pi.symm, comap_generate_from]\n    \u00b7 congr with s\n      simp only [Set.mem_image, Set.mem_setOf_eq, exists_prop]\n    \u00b7 infer_instance\n  let \u03c0T\u03b2 :=\n    Set.pi (Set.univ : Set T) ''\n      Set.pi (Set.univ : Set T) fun i => { s : Set (\u03b2 i) | measurable_set[m i] s }\n  let \u03c0T := { s : Set \u03a9 | \u2203 t \u2208 \u03c0T\u03b2, (fun a (i : T) => f i a) \u207b\u00b9' t = s }\n  have h\u03c0T_pi : IsPiSystem \u03c0T := is_pi_system_pi.comap fun a i => f i a\n  have h\u03c0T_gen : (measurable_space.pi.comap fun a (i : T) => f i a) = generate_from \u03c0T :=\n    by\n    rw [generate_from_pi.symm, comap_generate_from]\n    \u00b7 congr with s\n      simp only [Set.mem_image, Set.mem_setOf_eq, exists_prop]\n    \u00b7 infer_instance\n  -- To prove independence, we prove independence of the generating \u03c0-systems.\n  refine'\n    indep_sets.indep (Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i))\n      (Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i)) h\u03c0S_pi h\u03c0T_pi h\u03c0S_gen h\u03c0T_gen\n      _\n  rintro _ _ \u27e8s, \u27e8sets_s, hs1, hs2\u27e9, rfl\u27e9 \u27e8t, \u27e8sets_t, ht1, ht2\u27e9, rfl\u27e9\n  simp only [Set.mem_univ_pi, Set.mem_setOf_eq] at hs1 ht1\n  rw [\u2190 hs2, \u2190 ht2]\n  classical\n    let sets_s' : \u2200 i : \u03b9, Set (\u03b2 i) := fun i =>\n      dite (i \u2208 S) (fun hi => sets_s \u27e8i, hi\u27e9) fun _ => Set.univ\n    have h_sets_s'_eq : \u2200 {i} (hi : i \u2208 S), sets_s' i = sets_s \u27e8i, hi\u27e9 :=\n      by\n      intro i hi\n      simp_rw [sets_s', dif_pos hi]\n    have h_sets_s'_univ : \u2200 {i} (hi : i \u2208 T), sets_s' i = Set.univ :=\n      by\n      intro i hi\n      simp_rw [sets_s', dif_neg (finset.disjoint_right.mp hST hi)]\n    let sets_t' : \u2200 i : \u03b9, Set (\u03b2 i) := fun i =>\n      dite (i \u2208 T) (fun hi => sets_t \u27e8i, hi\u27e9) fun _ => Set.univ\n    have h_sets_t'_univ : \u2200 {i} (hi : i \u2208 S), sets_t' i = Set.univ :=\n      by\n      intro i hi\n      simp_rw [sets_t', dif_neg (finset.disjoint_left.mp hST hi)]\n    have h_meas_s' : \u2200 i \u2208 S, MeasurableSet (sets_s' i) :=\n      by\n      intro i hi\n      rw [h_sets_s'_eq hi]\n      exact hs1 _\n    have h_meas_t' : \u2200 i \u2208 T, MeasurableSet (sets_t' i) :=\n      by\n      intro i hi\n      simp_rw [sets_t', dif_pos hi]\n      exact ht1 _\n    have h_eq_inter_S :\n      (fun (\u03c9 : \u03a9) (i : \u21a5S) => f (\u2191i) \u03c9) \u207b\u00b9' Set.pi Set.univ sets_s = \u22c2 i \u2208 S, f i \u207b\u00b9' sets_s' i :=\n      by\n      ext1 x\n      simp only [Set.mem_preimage, Set.mem_univ_pi, Set.mem_inter\u1d62]\n      constructor <;> intro h\n      \u00b7 intro i hi\n        rw [h_sets_s'_eq hi]\n        exact h \u27e8i, hi\u27e9\n      \u00b7 rintro \u27e8i, hi\u27e9\n        specialize h i hi\n        rw [h_sets_s'_eq hi] at h\n        exact h\n    have h_eq_inter_T :\n      (fun (\u03c9 : \u03a9) (i : \u21a5T) => f (\u2191i) \u03c9) \u207b\u00b9' Set.pi Set.univ sets_t = \u22c2 i \u2208 T, f i \u207b\u00b9' sets_t' i :=\n      by\n      ext1 x\n      simp only [Set.mem_preimage, Set.mem_univ_pi, Set.mem_inter\u1d62]\n      constructor <;> intro h\n      \u00b7 intro i hi\n        simp_rw [sets_t', dif_pos hi]\n        exact h \u27e8i, hi\u27e9\n      \u00b7 rintro \u27e8i, hi\u27e9\n        specialize h i hi\n        simp_rw [sets_t', dif_pos hi] at h\n        exact h\n    rw [Indep_fun_iff_measure_inter_preimage_eq_mul] at hf_Indep\n    rw [h_eq_inter_S, h_eq_inter_T, hf_Indep S h_meas_s', hf_Indep T h_meas_t']\n    have h_Inter_inter :\n      ((\u22c2 i \u2208 S, f i \u207b\u00b9' sets_s' i) \u2229 \u22c2 i \u2208 T, f i \u207b\u00b9' sets_t' i) =\n        \u22c2 i \u2208 S \u222a T, f i \u207b\u00b9' (sets_s' i \u2229 sets_t' i) :=\n      by\n      ext1 x\n      simp only [Set.mem_inter_iff, Set.mem_inter\u1d62, Set.mem_preimage, Finset.mem_union]\n      constructor <;> intro h\n      \u00b7 intro i hi\n        cases hi\n        \u00b7 rw [h_sets_t'_univ hi]\n          exact \u27e8h.1 i hi, Set.mem_univ _\u27e9\n        \u00b7 rw [h_sets_s'_univ hi]\n          exact \u27e8Set.mem_univ _, h.2 i hi\u27e9\n      \u00b7 exact \u27e8fun i hi => (h i (Or.inl hi)).1, fun i hi => (h i (Or.inr hi)).2\u27e9\n    rw [h_Inter_inter, hf_Indep (S \u222a T)]\n    swap\n    \u00b7 intro i hi_mem\n      rw [Finset.mem_union] at hi_mem\n      cases hi_mem\n      \u00b7 rw [h_sets_t'_univ hi_mem, Set.inter_univ]\n        exact h_meas_s' i hi_mem\n      \u00b7 rw [h_sets_s'_univ hi_mem, Set.univ_inter]\n        exact h_meas_t' i hi_mem\n    rw [Finset.prod_union hST]\n    congr 1\n    \u00b7 refine' Finset.prod_congr rfl fun i hi => _\n      rw [h_sets_t'_univ hi, Set.inter_univ]\n    \u00b7 refine' Finset.prod_congr rfl fun i hi => _\n      rw [h_sets_s'_univ hi, Set.univ_inter]\n#align probability_theory.Indep_fun.indep_fun_finset ProbabilityTheory.IndepFun.indepFunFinset\n\ntheorem IndepFun.indepFunProd [IsProbabilityMeasure \u03bc] {\u03b9 : Type _} {\u03b2 : \u03b9 \u2192 Type _}\n    {m : \u2200 i, MeasurableSpace (\u03b2 i)} {f : \u2200 i, \u03a9 \u2192 \u03b2 i} (hf_Indep : IndepFun m f \u03bc)\n    (hf_meas : \u2200 i, Measurable (f i)) (i j k : \u03b9) (hik : i \u2260 k) (hjk : j \u2260 k) :\n    IndepFunCat (fun a => (f i a, f j a)) (f k) \u03bc := by\n  classical\n    have h_right :\n      f k =\n        (fun p : \u2200 j : ({k} : Finset \u03b9), \u03b2 j => p \u27e8k, Finset.mem_singleton_self k\u27e9) \u2218\n          fun a (j : ({k} : Finset \u03b9)) => f j a :=\n      rfl\n    have h_meas_right :\n      Measurable fun p : \u2200 j : ({k} : Finset \u03b9), \u03b2 j => p \u27e8k, Finset.mem_singleton_self k\u27e9 :=\n      measurable_pi_apply \u27e8k, Finset.mem_singleton_self k\u27e9\n    let s : Finset \u03b9 := {i, j}\n    have h_left :\n      (fun \u03c9 => (f i \u03c9, f j \u03c9)) =\n        (fun p : \u2200 l : s, \u03b2 l =>\n            (p \u27e8i, Finset.mem_insert_self i _\u27e9,\n              p \u27e8j, Finset.mem_insert_of_mem (Finset.mem_singleton_self _)\u27e9)) \u2218\n          fun a (j : s) => f j a :=\n      by\n      ext1 a\n      simp only [Prod.mk.inj_iff]\n      constructor <;> rfl\n    have h_meas_left :\n      Measurable fun p : \u2200 l : s, \u03b2 l =>\n        (p \u27e8i, Finset.mem_insert_self i _\u27e9,\n          p \u27e8j, Finset.mem_insert_of_mem (Finset.mem_singleton_self _)\u27e9) :=\n      Measurable.prod (measurable_pi_apply \u27e8i, Finset.mem_insert_self i {j}\u27e9)\n        (measurable_pi_apply \u27e8j, Finset.mem_insert_of_mem (Finset.mem_singleton_self j)\u27e9)\n    rw [h_left, h_right]\n    refine' (hf_Indep.indep_fun_finset s {k} _ hf_meas).comp h_meas_left h_meas_right\n    rw [Finset.disjoint_singleton_right]\n    simp only [Finset.mem_insert, Finset.mem_singleton, not_or]\n    exact \u27e8hik.symm, hjk.symm\u27e9\n#align probability_theory.Indep_fun.indep_fun_prod ProbabilityTheory.IndepFun.indepFunProd\n\n@[to_additive]\ntheorem IndepFun.mul [IsProbabilityMeasure \u03bc] {\u03b9 : Type _} {\u03b2 : Type _} {m : MeasurableSpace \u03b2}\n    [Mul \u03b2] [HasMeasurableMul\u2082 \u03b2] {f : \u03b9 \u2192 \u03a9 \u2192 \u03b2} (hf_Indep : IndepFun (fun _ => m) f \u03bc)\n    (hf_meas : \u2200 i, Measurable (f i)) (i j k : \u03b9) (hik : i \u2260 k) (hjk : j \u2260 k) :\n    IndepFunCat (f i * f j) (f k) \u03bc :=\n  by\n  have : indep_fun (fun \u03c9 => (f i \u03c9, f j \u03c9)) (f k) \u03bc :=\n    hf_Indep.indep_fun_prod hf_meas i j k hik hjk\n  change indep_fun ((fun p : \u03b2 \u00d7 \u03b2 => p.fst * p.snd) \u2218 fun \u03c9 => (f i \u03c9, f j \u03c9)) (id \u2218 f k) \u03bc\n  exact indep_fun.comp this (measurable_fst.mul measurable_snd) measurable_id\n#align probability_theory.Indep_fun.mul ProbabilityTheory.IndepFun.mul\n#align probability_theory.Indep_fun.add ProbabilityTheory.IndepFun.add\n\n@[to_additive]\ntheorem IndepFun.indepFunFinsetProdOfNotMem [IsProbabilityMeasure \u03bc] {\u03b9 : Type _} {\u03b2 : Type _}\n    {m : MeasurableSpace \u03b2} [CommMonoid \u03b2] [HasMeasurableMul\u2082 \u03b2] {f : \u03b9 \u2192 \u03a9 \u2192 \u03b2}\n    (hf_Indep : IndepFun (fun _ => m) f \u03bc) (hf_meas : \u2200 i, Measurable (f i)) {s : Finset \u03b9} {i : \u03b9}\n    (hi : i \u2209 s) : IndepFunCat (\u220f j in s, f j) (f i) \u03bc := by\n  classical\n    have h_right :\n      f i =\n        (fun p : \u2200 j : ({i} : Finset \u03b9), \u03b2 => p \u27e8i, Finset.mem_singleton_self i\u27e9) \u2218\n          fun a (j : ({i} : Finset \u03b9)) => f j a :=\n      rfl\n    have h_meas_right :\n      Measurable fun p : \u2200 j : ({i} : Finset \u03b9), \u03b2 => p \u27e8i, Finset.mem_singleton_self i\u27e9 :=\n      measurable_pi_apply \u27e8i, Finset.mem_singleton_self i\u27e9\n    have h_left : (\u220f j in s, f j) = (fun p : \u2200 j : s, \u03b2 => \u220f j, p j) \u2218 fun a (j : s) => f j a :=\n      by\n      ext1 a\n      simp only [Function.comp_apply]\n      have : (\u220f j : \u21a5s, f (\u2191j) a) = (\u220f j : \u21a5s, f \u2191j) a := by rw [Finset.prod_apply]\n      rw [this, Finset.prod_coe_sort]\n    have h_meas_left : Measurable fun p : \u2200 j : s, \u03b2 => \u220f j, p j :=\n      finset.univ.measurable_prod fun (j : \u21a5s) (H : j \u2208 Finset.univ) => measurable_pi_apply j\n    rw [h_left, h_right]\n    exact\n      (hf_Indep.indep_fun_finset s {i} (finset.disjoint_singleton_left.mpr hi).symm hf_meas).comp\n        h_meas_left h_meas_right\n#align probability_theory.Indep_fun.indep_fun_finset_prod_of_not_mem ProbabilityTheory.IndepFun.indepFunFinsetProdOfNotMem\n#align probability_theory.Indep_fun.indep_fun_finset_sum_of_not_mem ProbabilityTheory.IndepFun.indep_fun_finset_sum_of_not_mem\n\n@[to_additive]\ntheorem IndepFun.indepFunProdRangeSucc [IsProbabilityMeasure \u03bc] {\u03b2 : Type _} {m : MeasurableSpace \u03b2}\n    [CommMonoid \u03b2] [HasMeasurableMul\u2082 \u03b2] {f : \u2115 \u2192 \u03a9 \u2192 \u03b2} (hf_Indep : IndepFun (fun _ => m) f \u03bc)\n    (hf_meas : \u2200 i, Measurable (f i)) (n : \u2115) : IndepFunCat (\u220f j in Finset.range n, f j) (f n) \u03bc :=\n  hf_Indep.indepFunFinsetProdOfNotMem hf_meas Finset.not_mem_range_self\n#align probability_theory.Indep_fun.indep_fun_prod_range_succ ProbabilityTheory.IndepFun.indepFunProdRangeSucc\n#align probability_theory.Indep_fun.indep_fun_sum_range_succ ProbabilityTheory.IndepFun.indep_fun_sum_range_succ\n\ntheorem IndepSet.indepFunIndicator [Zero \u03b2] [One \u03b2] {m : MeasurableSpace \u03b2} {s : \u03b9 \u2192 Set \u03a9}\n    (hs : IndepSet s \u03bc) : IndepFun (fun n => m) (fun n => (s n).indicator fun \u03c9 => 1) \u03bc := by\n  classical\n    rw [Indep_fun_iff_measure_inter_preimage_eq_mul]\n    rintro S \u03c0 h\u03c0\n    simp_rw [Set.indicator_const_preimage_eq_union]\n    refine' @hs S (fun i => ite (1 \u2208 \u03c0 i) (s i) \u2205 \u222a ite ((0 : \u03b2) \u2208 \u03c0 i) (s i\u1d9c) \u2205) fun i hi => _\n    have hsi : measurable_set[generate_from {s i}] (s i) :=\n      measurable_set_generate_from (Set.mem_singleton _)\n    refine'\n      MeasurableSet.union (MeasurableSet.ite' (fun _ => hsi) fun _ => _)\n        (MeasurableSet.ite' (fun _ => hsi.compl) fun _ => _)\n    \u00b7 exact @MeasurableSet.empty _ (generate_from {s i})\n    \u00b7 exact @MeasurableSet.empty _ (generate_from {s i})\n#align probability_theory.Indep_set.Indep_fun_indicator ProbabilityTheory.IndepSet.indepFunIndicator\n\nend IndepFun\n\n/-! ### Kolmogorov's 0-1 law\n\nLet `s : \u03b9 \u2192 measurable_space \u03a9` be an independent sequence of sub-\u03c3-algebras. Then any set which\nis measurable with respect to the tail \u03c3-algebra `limsup s at_top` has probability 0 or 1.\n-/\n\n\nsection ZeroOneLaw\n\nvariable {m m0 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9}\n\ntheorem measure_eq_zero_or_one_or_top_of_indepSetCat_self {t : Set \u03a9}\n    (h_indep : IndepSetCat t t \u03bc) : \u03bc t = 0 \u2228 \u03bc t = 1 \u2228 \u03bc t = \u221e :=\n  by\n  specialize\n    h_indep t t (measurable_set_generate_from (Set.mem_singleton t))\n      (measurable_set_generate_from (Set.mem_singleton t))\n  by_cases h0 : \u03bc t = 0\n  \u00b7 exact Or.inl h0\n  by_cases h_top : \u03bc t = \u221e\n  \u00b7 exact Or.inr (Or.inr h_top)\n  rw [\u2190 one_mul (\u03bc (t \u2229 t)), Set.inter_self, ENNReal.mul_eq_mul_right h0 h_top] at h_indep\n  exact Or.inr (Or.inl h_indep.symm)\n#align probability_theory.measure_eq_zero_or_one_or_top_of_indep_set_self ProbabilityTheory.measure_eq_zero_or_one_or_top_of_indepSetCat_self\n\ntheorem measure_eq_zero_or_one_of_indepSetCat_self [IsFiniteMeasure \u03bc] {t : Set \u03a9}\n    (h_indep : IndepSetCat t t \u03bc) : \u03bc t = 0 \u2228 \u03bc t = 1 :=\n  by\n  have h_0_1_top := measure_eq_zero_or_one_or_top_of_indep_set_self h_indep\n  simpa [measure_ne_top \u03bc] using h_0_1_top\n#align probability_theory.measure_eq_zero_or_one_of_indep_set_self ProbabilityTheory.measure_eq_zero_or_one_of_indepSetCat_self\n\nvariable [IsProbabilityMeasure \u03bc] {s : \u03b9 \u2192 MeasurableSpace \u03a9}\n\nopen Filter\n\ntheorem indepBsuprCompl (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) (t : Set \u03b9) :\n    IndepCat (\u2a06 n \u2208 t, s n) (\u2a06 n \u2208 t\u1d9c, s n) \u03bc :=\n  indepSuprOfDisjoint h_le h_indep disjoint_compl_right\n#align probability_theory.indep_bsupr_compl ProbabilityTheory.indepBsuprCompl\n\nsection Abstract\n\nvariable {\u03b1 : Type _} {p : Set \u03b9 \u2192 Prop} {f : Filter \u03b9} {ns : \u03b1 \u2192 Set \u03b9}\n\n/-! We prove a version of Kolmogorov's 0-1 law for the \u03c3-algebra `limsup s f` where `f` is a filter\nfor which we can define the following two functions:\n* `p : set \u03b9 \u2192 Prop` such that for a set `t`, `p t \u2192 t\u1d9c \u2208 f`,\n* `ns : \u03b1 \u2192 set \u03b9` a directed sequence of sets which all verify `p` and such that\n  `\u22c3 a, ns a = set.univ`.\n\nFor the example of `f = at_top`, we can take `p = bdd_above` and `ns : \u03b9 \u2192 set \u03b9 := \u03bb i, set.Iic i`.\n-/\n\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic filter.is_bounded_default -/\ntheorem indepBsuprLimsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f)\n    {t : Set \u03b9} (ht : p t) : IndepCat (\u2a06 n \u2208 t, s n) (limsup s f) \u03bc :=\n  by\n  refine' indep_of_indep_of_le_right (indep_bsupr_compl h_le h_indep t) _\n  refine'\n    Limsup_le_of_le\n      (by\n        run_tac\n          is_bounded_default)\n      _\n  simp only [Set.mem_compl_iff, eventually_map]\n  exact eventually_of_mem (hf t ht) le_sup\u1d62\u2082\n#align probability_theory.indep_bsupr_limsup ProbabilityTheory.indepBsuprLimsup\n\ntheorem indepSuprDirectedLimsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc)\n    (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f) (hns : Directed (\u00b7 \u2264 \u00b7) ns) (hnsp : \u2200 a, p (ns a)) :\n    IndepCat (\u2a06 a, \u2a06 n \u2208 ns a, s n) (limsup s f) \u03bc :=\n  by\n  refine' indep_supr_of_directed_le _ _ _ _\n  \u00b7 exact fun a => indep_bsupr_limsup h_le h_indep hf (hnsp a)\n  \u00b7 exact fun a => sup\u1d62\u2082_le fun n hn => h_le n\n  \u00b7 exact limsup_le_supr.trans (sup\u1d62_le h_le)\n  \u00b7 intro a b\n    obtain \u27e8c, hc\u27e9 := hns a b\n    refine' \u27e8c, _, _\u27e9 <;> refine' sup\u1d62_mono fun n => sup\u1d62_mono' fun hn => \u27e8_, le_rfl\u27e9\n    \u00b7 exact hc.1 hn\n    \u00b7 exact hc.2 hn\n#align probability_theory.indep_supr_directed_limsup ProbabilityTheory.indepSuprDirectedLimsup\n\ntheorem indepSuprLimsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f)\n    (hns : Directed (\u00b7 \u2264 \u00b7) ns) (hnsp : \u2200 a, p (ns a)) (hns_univ : \u2200 n, \u2203 a, n \u2208 ns a) :\n    IndepCat (\u2a06 n, s n) (limsup s f) \u03bc :=\n  by\n  suffices (\u2a06 a, \u2a06 n \u2208 ns a, s n) = \u2a06 n, s n by\n    rw [\u2190 this]\n    exact indep_supr_directed_limsup h_le h_indep hf hns hnsp\n  rw [sup\u1d62_comm]\n  refine' sup\u1d62_congr fun n => _\n  have : (\u2a06 (i : \u03b1) (H : n \u2208 ns i), s n) = \u2a06 h : \u2203 i, n \u2208 ns i, s n := by rw [sup\u1d62_exists]\n  haveI : Nonempty (\u2203 i : \u03b1, n \u2208 ns i) := \u27e8hns_univ n\u27e9\n  rw [this, sup\u1d62_const]\n#align probability_theory.indep_supr_limsup ProbabilityTheory.indepSuprLimsup\n\ntheorem indepLimsupSelf (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f)\n    (hns : Directed (\u00b7 \u2264 \u00b7) ns) (hnsp : \u2200 a, p (ns a)) (hns_univ : \u2200 n, \u2203 a, n \u2208 ns a) :\n    IndepCat (limsup s f) (limsup s f) \u03bc :=\n  indepOfIndepOfLeLeft (indepSuprLimsup h_le h_indep hf hns hnsp hns_univ) limsup_le_sup\u1d62\n#align probability_theory.indep_limsup_self ProbabilityTheory.indepLimsupSelf\n\ntheorem measure_zero_or_one_of_measurableSet_limsup (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc)\n    (hf : \u2200 t, p t \u2192 t\u1d9c \u2208 f) (hns : Directed (\u00b7 \u2264 \u00b7) ns) (hnsp : \u2200 a, p (ns a))\n    (hns_univ : \u2200 n, \u2203 a, n \u2208 ns a) {t : Set \u03a9} (ht_tail : measurable_set[limsup s f] t) :\n    \u03bc t = 0 \u2228 \u03bc t = 1 :=\n  measure_eq_zero_or_one_of_indepSetCat_self\n    ((indepLimsupSelf h_le h_indep hf hns hnsp hns_univ).indepSetOfMeasurableSet ht_tail ht_tail)\n#align probability_theory.measure_zero_or_one_of_measurable_set_limsup ProbabilityTheory.measure_zero_or_one_of_measurableSet_limsup\n\nend Abstract\n\nsection AtTop\n\nvariable [SemilatticeSup \u03b9] [NoMaxOrder \u03b9] [Nonempty \u03b9]\n\ntheorem indepLimsupAtTopSelf (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) :\n    IndepCat (limsup s atTop) (limsup s atTop) \u03bc :=\n  by\n  let ns : \u03b9 \u2192 Set \u03b9 := Set.Iic\n  have hnsp : \u2200 i, BddAbove (ns i) := fun i => bddAbove_Iic\n  refine' indep_limsup_self h_le h_indep _ _ hnsp _\n  \u00b7 simp only [mem_at_top_sets, ge_iff_le, Set.mem_compl_iff, BddAbove, upperBounds, Set.Nonempty]\n    rintro t \u27e8a, ha\u27e9\n    obtain \u27e8b, hb\u27e9 : \u2203 b, a < b := exists_gt a\n    refine' \u27e8b, fun c hc hct => _\u27e9\n    suffices : \u2200 i \u2208 t, i < c\n    exact lt_irrefl c (this c hct)\n    exact fun i hi => (ha hi).trans_lt (hb.trans_le hc)\n  \u00b7 exact Monotone.directed_le fun i j hij k hki => le_trans hki hij\n  \u00b7 exact fun n => \u27e8n, le_rfl\u27e9\n#align probability_theory.indep_limsup_at_top_self ProbabilityTheory.indepLimsupAtTopSelf\n\n/-- **Kolmogorov's 0-1 law** : any event in the tail \u03c3-algebra of an independent sequence of\nsub-\u03c3-algebras has probability 0 or 1.\nThe tail \u03c3-algebra `limsup s at_top` is the same as `\u22c2 n, \u22c3 i \u2265 n, s i`. -/\ntheorem measure_zero_or_one_of_measurableSet_limsup_atTop (h_le : \u2200 n, s n \u2264 m0)\n    (h_indep : Indep s \u03bc) {t : Set \u03a9} (ht_tail : measurable_set[limsup s atTop] t) :\n    \u03bc t = 0 \u2228 \u03bc t = 1 :=\n  measure_eq_zero_or_one_of_indepSetCat_self\n    ((indepLimsupAtTopSelf h_le h_indep).indepSetOfMeasurableSet ht_tail ht_tail)\n#align probability_theory.measure_zero_or_one_of_measurable_set_limsup_at_top ProbabilityTheory.measure_zero_or_one_of_measurableSet_limsup_atTop\n\nend AtTop\n\nsection AtBot\n\nvariable [SemilatticeInf \u03b9] [NoMinOrder \u03b9] [Nonempty \u03b9]\n\ntheorem indepLimsupAtBotSelf (h_le : \u2200 n, s n \u2264 m0) (h_indep : Indep s \u03bc) :\n    IndepCat (limsup s atBot) (limsup s atBot) \u03bc :=\n  by\n  let ns : \u03b9 \u2192 Set \u03b9 := Set.Ici\n  have hnsp : \u2200 i, BddBelow (ns i) := fun i => bddBelow_Ici\n  refine' indep_limsup_self h_le h_indep _ _ hnsp _\n  \u00b7 simp only [mem_at_bot_sets, ge_iff_le, Set.mem_compl_iff, BddBelow, lowerBounds, Set.Nonempty]\n    rintro t \u27e8a, ha\u27e9\n    obtain \u27e8b, hb\u27e9 : \u2203 b, b < a := exists_lt a\n    refine' \u27e8b, fun c hc hct => _\u27e9\n    suffices : \u2200 i \u2208 t, c < i\n    exact lt_irrefl c (this c hct)\n    exact fun i hi => hc.trans_lt (hb.trans_le (ha hi))\n  \u00b7 exact directed_of_inf fun i j hij k hki => hij.trans hki\n  \u00b7 exact fun n => \u27e8n, le_rfl\u27e9\n#align probability_theory.indep_limsup_at_bot_self ProbabilityTheory.indepLimsupAtBotSelf\n\n/-- **Kolmogorov's 0-1 law** : any event in the tail \u03c3-algebra of an independent sequence of\nsub-\u03c3-algebras has probability 0 or 1. -/\ntheorem measure_zero_or_one_of_measurableSet_limsup_atBot (h_le : \u2200 n, s n \u2264 m0)\n    (h_indep : Indep s \u03bc) {t : Set \u03a9} (ht_tail : measurable_set[limsup s atBot] t) :\n    \u03bc t = 0 \u2228 \u03bc t = 1 :=\n  measure_eq_zero_or_one_of_indepSetCat_self\n    ((indepLimsupAtBotSelf h_le h_indep).indepSetOfMeasurableSet ht_tail ht_tail)\n#align probability_theory.measure_zero_or_one_of_measurable_set_limsup_at_bot ProbabilityTheory.measure_zero_or_one_of_measurableSet_limsup_atBot\n\nend AtBot\n\nend ZeroOneLaw\n\nend ProbabilityTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Probability/Independence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7166501082537172}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n-/\nimport analysis.special_functions.exp\n\n/-!\n# Real logarithm\n\nIn this file we define `real.log` to be the logarithm of a real number. As usual, we extend it from\nits domain `(0, +\u221e)` to a globally defined function. We choose to do it so that `log 0 = 0` and\n`log (-x) = log x`.\n\nWe prove some basic properties of this function and show that it is continuous.\n\n## Tags\n\nlogarithm, continuity\n-/\n\nopen set filter function\nopen_locale topological_space\nnoncomputable theory\n\nnamespace real\n\nvariables {x y : \u211d}\n\n/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,\nto `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to\n`(-\u221e, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and\nthe derivative of `log` is `1/x` away from `0`. -/\n@[pp_nodot] noncomputable def log (x : \u211d) : \u211d :=\nif hx : x = 0 then 0 else exp_order_iso.symm \u27e8|x|, abs_pos.2 hx\u27e9\n\nlemma log_of_ne_zero (hx : x \u2260 0) : log x = exp_order_iso.symm \u27e8|x|, abs_pos.2 hx\u27e9 := dif_neg hx\n\nlemma log_of_pos (hx : 0 < x) : log x = exp_order_iso.symm \u27e8x, hx\u27e9 :=\nby { rw [log_of_ne_zero hx.ne'], congr, exact abs_of_pos hx }\n\nlemma exp_log_eq_abs (hx : x \u2260 0) : exp (log x) = |x| :=\nby rw [log_of_ne_zero hx, \u2190 coe_exp_order_iso_apply, order_iso.apply_symm_apply, subtype.coe_mk]\n\nlemma exp_log (hx : 0 < x) : exp (log x) = x :=\nby { rw exp_log_eq_abs hx.ne', exact abs_of_pos hx }\n\nlemma exp_log_of_neg (hx : x < 0) : exp (log x) = -x :=\nby { rw exp_log_eq_abs (ne_of_lt hx), exact abs_of_neg hx }\n\n@[simp] lemma log_exp (x : \u211d) : log (exp x) = x :=\nexp_injective $ exp_log (exp_pos x)\n\nlemma surj_on_log : surj_on log (Ioi 0) univ :=\n\u03bb x _, \u27e8exp x, exp_pos x, log_exp x\u27e9\n\nlemma log_surjective : surjective log :=\n\u03bb x, \u27e8exp x, log_exp x\u27e9\n\n@[simp] lemma range_log : range log = univ :=\nlog_surjective.range_eq\n\n@[simp] lemma log_zero : log 0 = 0 := dif_pos rfl\n\n@[simp] lemma log_one : log 1 = 0 :=\nexp_injective $ by rw [exp_log zero_lt_one, exp_zero]\n\n@[simp] lemma log_abs (x : \u211d) : log (|x|) = log x :=\nbegin\n  by_cases h : x = 0,\n  { simp [h] },\n  { rw [\u2190 exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] }\nend\n\n@[simp] lemma log_neg_eq_log (x : \u211d) : log (-x) = log x :=\nby rw [\u2190 log_abs x, \u2190 log_abs (-x), abs_neg]\n\nlemma surj_on_log' : surj_on log (Iio 0) univ :=\n\u03bb x _, \u27e8-exp x, neg_lt_zero.2 $ exp_pos x, by rw [log_neg_eq_log, log_exp]\u27e9\n\nlemma log_mul (hx : x \u2260 0) (hy : y \u2260 0) : log (x * y) = log x + log y :=\nexp_injective $\nby rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]\n\nlemma log_div (hx : x \u2260 0) (hy : y \u2260 0) : log (x / y) = log x - log y :=\nexp_injective $\nby rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]\n\n@[simp] lemma log_inv (x : \u211d) : log (x\u207b\u00b9) = -log x :=\nbegin\n  by_cases hx : x = 0, { simp [hx] },\n  rw [\u2190 exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]\nend\n\nlemma log_le_log (h : 0 < x) (h\u2081 : 0 < y) : real.log x \u2264 real.log y \u2194 x \u2264 y :=\nby rw [\u2190 exp_le_exp, exp_log h, exp_log h\u2081]\n\nlemma log_lt_log (hx : 0 < x) : x < y \u2192 log x < log y :=\nby { intro h, rwa [\u2190 exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] }\n\nlemma log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y \u2194 x < y :=\nby { rw [\u2190 exp_lt_exp, exp_log hx, exp_log hy] }\n\nlemma log_le_iff_le_exp (hx : 0 < x) : log x \u2264 y \u2194 x \u2264 exp y := by rw [\u2190exp_le_exp, exp_log hx]\n\nlemma log_lt_iff_lt_exp (hx : 0 < x) : log x < y \u2194 x < exp y := by rw [\u2190exp_lt_exp, exp_log hx]\n\nlemma le_log_iff_exp_le (hy : 0 < y) : x \u2264 log y \u2194 exp x \u2264 y := by rw [\u2190exp_le_exp, exp_log hy]\n\nlemma lt_log_iff_exp_lt (hy : 0 < y) : x < log y \u2194 exp x < y := by rw [\u2190exp_lt_exp, exp_log hy]\n\nlemma log_pos_iff (hx : 0 < x) : 0 < log x \u2194 1 < x :=\nby { rw \u2190 log_one, exact log_lt_log_iff zero_lt_one hx }\n\nlemma log_pos (hx : 1 < x) : 0 < log x :=\n(log_pos_iff (lt_trans zero_lt_one hx)).2 hx\n\nlemma log_neg_iff (h : 0 < x) : log x < 0 \u2194 x < 1 :=\nby { rw \u2190 log_one, exact log_lt_log_iff h zero_lt_one }\n\nlemma log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1\n\nlemma log_nonneg_iff (hx : 0 < x) : 0 \u2264 log x \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, log_neg_iff hx, not_lt]\n\nlemma log_nonneg (hx : 1 \u2264 x) : 0 \u2264 log x :=\n(log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx\n\nlemma log_nonpos_iff (hx : 0 < x) : log x \u2264 0 \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, log_pos_iff hx, not_lt]\n\nlemma log_nonpos_iff' (hx : 0 \u2264 x) : log x \u2264 0 \u2194 x \u2264 1 :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { simp [le_refl, zero_le_one] },\n  exact log_nonpos_iff hx\nend\n\nlemma log_nonpos (hx : 0 \u2264 x) (h'x : x \u2264 1) : log x \u2264 0 :=\n(log_nonpos_iff' hx).2 h'x\n\nlemma strict_mono_on_log : strict_mono_on log (set.Ioi 0) :=\n\u03bb x hx y hy hxy, log_lt_log hx hxy\n\nlemma strict_anti_on_log : strict_anti_on log (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 log_abs y, \u2190 log_abs x],\n  refine log_lt_log (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]\nend\n\nlemma log_inj_on_pos : set.inj_on log (set.Ioi 0) :=\nstrict_mono_on_log.inj_on\n\nlemma eq_one_of_pos_of_log_eq_zero {x : \u211d} (h\u2081 : 0 < x) (h\u2082 : log x = 0) : x = 1 :=\nlog_inj_on_pos (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one) (h\u2082.trans real.log_one.symm)\n\nlemma log_ne_zero_of_pos_of_ne_one {x : \u211d} (hx_pos : 0 < x) (hx : x \u2260 1) : log x \u2260 0 :=\nmt (eq_one_of_pos_of_log_eq_zero hx_pos) hx\n\n@[simp] lemma log_eq_zero {x : \u211d} : log x = 0 \u2194 x = 0 \u2228 x = 1 \u2228 x = -1 :=\nbegin\n  split,\n  { intros h,\n    rcases lt_trichotomy x 0 with x_lt_zero | rfl | x_gt_zero,\n    { refine or.inr (or.inr (eq_neg_iff_eq_neg.mp _)),\n      rw [\u2190log_neg_eq_log x] at h,\n      exact (eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h).symm, },\n    { exact or.inl rfl },\n    { exact or.inr (or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h)), }, },\n  { rintro (rfl|rfl|rfl); simp only [log_one, log_zero, log_neg_eq_log], }\nend\n\n/-- The real logarithm function tends to `+\u221e` at `+\u221e`. -/\nlemma tendsto_log_at_top : tendsto log at_top at_top :=\ntendsto_comp_exp_at_top.1 $ by simpa only [log_exp] using tendsto_id\n\nlemma tendsto_log_nhds_within_zero : tendsto log (\ud835\udcdd[{0}\u1d9c] 0) at_bot :=\nbegin\n  rw [\u2190 (show _ = log, from funext log_abs)],\n  refine tendsto.comp _ tendsto_abs_nhds_within_zero,\n  simpa [\u2190 tendsto_comp_exp_at_bot] using tendsto_id\nend\n\nlemma continuous_on_log : continuous_on log {0}\u1d9c :=\nbegin\n  rw [continuous_on_iff_continuous_restrict, restrict],\n  conv in (log _) { rw [log_of_ne_zero (show (x : \u211d) \u2260 0, from x.2)] },\n  exact exp_order_iso.symm.continuous.comp (continuous_subtype_mk _ continuous_subtype_coe.norm)\nend\n\n@[continuity] lemma continuous_log : continuous (\u03bb x : {x : \u211d // x \u2260 0}, log x) :=\ncontinuous_on_iff_continuous_restrict.1 $ continuous_on_log.mono $ \u03bb x hx, hx\n\n@[continuity] lemma continuous_log' : continuous (\u03bb x : {x : \u211d // 0 < x}, log x) :=\ncontinuous_on_iff_continuous_restrict.1 $ continuous_on_log.mono $ \u03bb x hx, ne_of_gt hx\n\nlemma continuous_at_log (hx : x \u2260 0) : continuous_at log x :=\n(continuous_on_log x hx).continuous_at $ is_open.mem_nhds is_open_compl_singleton hx\n\n@[simp] lemma continuous_at_log_iff : continuous_at log x \u2194 x \u2260 0 :=\nbegin\n  refine \u27e8_, continuous_at_log\u27e9,\n  rintros h rfl,\n  exact not_tendsto_nhds_of_tendsto_at_bot tendsto_log_nhds_within_zero _\n    (h.tendsto.mono_left inf_le_left)\nend\n\nend real\n\nsection continuity\n\nopen real\nvariables {\u03b1 : Type*}\n\nlemma filter.tendsto.log {f : \u03b1 \u2192 \u211d} {l : filter \u03b1} {x : \u211d} (h : tendsto f l (\ud835\udcdd x)) (hx : x \u2260 0) :\n  tendsto (\u03bb x, log (f x)) l (\ud835\udcdd (log x)) :=\n(continuous_at_log hx).tendsto.comp h\n\nvariables [topological_space \u03b1] {f : \u03b1 \u2192 \u211d} {s : set \u03b1} {a : \u03b1}\n\nlemma continuous.log (hf : continuous f) (h\u2080 : \u2200 x, f x \u2260 0) : continuous (\u03bb x, log (f x)) :=\ncontinuous_on_log.comp_continuous hf h\u2080\n\nlemma continuous_at.log (hf : continuous_at f a) (h\u2080 : f a \u2260 0) :\n  continuous_at (\u03bb x, log (f x)) a :=\nhf.log h\u2080\n\nlemma continuous_within_at.log (hf : continuous_within_at f s a) (h\u2080 : f a \u2260 0) :\n  continuous_within_at (\u03bb x, log (f x)) s a :=\nhf.log h\u2080\n\nlemma continuous_on.log (hf : continuous_on f s) (h\u2080 : \u2200 x \u2208 s, f x \u2260 0) :\n  continuous_on (\u03bb x, log (f x)) s :=\n\u03bb x hx, (hf x hx).log (h\u2080 x hx)\n\nend continuity\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/special_functions/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7166501024999052}}
{"text": "-- Suma_por_diferencia.lean\n-- Suma por diferencia.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 26-agosto-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si a y b son n\u00fameros reales, entonces\n--    (a + b) * (a - b) = a^2 - b^2\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b c d : \u211d\n\n-- 1\u00aa demostraci\u00f3n\nexample : (a + b) * (a - b) = a^2 - b^2 :=\ncalc\n  (a + b) * (a - b)\n      = a * (a - b) + b * (a - b)         : by rw add_mul\n  ... = (a * a - a * b) + b * (a - b)     : by rw mul_sub\n  ... = (a^2 - a * b) + b * (a - b)       : by rw \u2190 pow_two\n  ... = (a^2 - a * b) + (b * a - b * b)   : by rw mul_sub\n  ... = (a^2 - a * b) + (b * a - b^2)     : by rw \u2190 pow_two\n  ... = (a^2 + -(a * b)) + (b * a - b^2)  : by ring\n  ... = a^2 + (-(a * b) + (b * a - b^2))  : by rw add_assoc\n  ... = a^2 + (-(a * b) + (b * a + -b^2)) : by ring\n  ... = a^2 + ((-(a * b) + b * a) + -b^2) : by rw \u2190 add_assoc\n                                               (-(a * b)) (b * a) (-b^2)\n  ... = a^2 + ((-(a * b) + a * b) + -b^2) : by rw mul_comm\n  ... = a^2 + (0 + -b^2)                  : by rw neg_add_self (a * b)\n  ... = (a^2 + 0) + -b^2                  : by rw \u2190 add_assoc\n  ... = a^2 + -b^2                        : by rw add_zero\n  ... = a^2 - b^2                         : by linarith\n\n\n-- 2\u00aa demostraci\u00f3n\nexample : (a + b) * (a - b) = a^2 - b^2 :=\ncalc\n  (a + b) * (a - b)\n      = a * (a - b) + b * (a - b)         : by ring\n  ... = (a * a - a * b) + b * (a - b)     : by ring\n  ... = (a^2 - a * b) + b * (a - b)       : by ring\n  ... = (a^2 - a * b) + (b * a - b * b)   : by ring\n  ... = (a^2 - a * b) + (b * a - b^2)     : by ring\n  ... = (a^2 + -(a * b)) + (b * a - b^2)  : by ring\n  ... = a^2 + (-(a * b) + (b * a - b^2))  : by ring\n  ... = a^2 + (-(a * b) + (b * a + -b^2)) : by ring\n  ... = a^2 + ((-(a * b) + b * a) + -b^2) : by ring\n  ... = a^2 + ((-(a * b) + a * b) + -b^2) : by ring\n  ... = a^2 + (0 + -b^2)                  : by ring\n  ... = (a^2 + 0) + -b^2                  : by ring\n  ... = a^2 + -b^2                        : by ring\n  ... = a^2 - b^2                         : by ring\n\n-- 3\u00aa demostraci\u00f3n\nexample : (a + b) * (a - b) = a^2 - b^2 :=\nby ring\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Suma_por_diferencia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7166097190028715}}
{"text": "/-\nThis file is intended for Lean beginners. The goal is to demonstrate what it feels like to prove\nthings using Lean and mathlib. Complicated definitions and theory building are not covered.\n-/\n\n-- We want real numbers and their basic properties\nimport data.real.basic\n\n-- We want to be able to define functions using the law of excluded middle\nnoncomputable theory\nopen_locale classical\n\n\n/- \nOur first goal is to define the set of upper bounds of a set of real numbers.\nThis is already defined in mathlib (in a more general context), but we repeat \nit for the sake of exposition. Right-click \"upper_bounds\" below to get offered\nto jump to mathlib's version\n-/\n#check upper_bounds\n\n/-- The set of upper bounds of a set of real numbers \u211d -/\ndef up_bounds (A : set \u211d) := { x : \u211d | \u2200 a \u2208 A, a \u2264 x}\n\n/-- Predicate `is_max a A` means `a` is a maximum of `A` -/\ndef is_max (a : \u211d) (A : set \u211d) := a \u2208 A \u2227 a \u2208 up_bounds A\n\n/- \nIn the above definition, the symbol `\u2227` means \"and\". We also see the most \nvisible difference between set theoretic foundations and type theoretic ones \n(used by almost all proof assistants). In set theory, everything is a set, and the\nonly relation you get from foundations are `=` and `\u2208`. In type theory, there is \na meta-theoretic relation of \"typing\": `a : \u211d` reads \"`a` is a real number\" or,\nmore precisely, \"the type of `a` is `\u211d`\". Here \"meta-theoretic\" means this is not a \nstatement you can prove or disprove inside the theory, it's a fact that is true or\nnot. Here we impose this fact, in other circumstances, it would be checked by the\nLean kernel.\nBy contrast, `a \u2208 A` is a statement inside the theory. Here it's part of the \ndefinition, in other circumstances it could be something proven inside Lean.\n-/\n\n/- For illustrative purposes, we now define an infix version of the above predicate.\nIt will allow us to write `a is_a_max_of A`, which is closer to a sentence.\n-/\ninfix `is_a_max_of`:55 := is_max\n\n/-\nLet's prove something now! A set of real number has at most one maximum. Here \neverything left of the final `:` is introducing the objects and assumption. The equality\n`x = y` right of the colon is the conclusion.\n-/\nlemma unique_max (A : set \u211d) (x y : \u211d) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=\nbegin\n  -- We first break our assumptions in their two constituent pieces. \n  -- We are free to choose the name following `with`\n  cases hx with x_in x_up,\n  cases hy with y_in y_up,\n  -- Assumption `x_up` means x isn't less than elements of A, let's apply this to y\n  specialize x_up y,\n  -- Assumption `x_up` now needs the information that `y` is indeed in `A`.\n  specialize x_up y_in,\n  -- Let's do this quicker with roles swapped\n  specialize y_up x x_in,\n  -- We explained to Lean the idea of this proof. \n  -- Now we know `x \u2264 y` and `y \u2264 x`, and Lean shouldn't need more help.\n  -- `linarith` proves equalities and inequalities that follow linearly from\n  -- assumption we have.\n  linarith,\nend\n\n/-\nThe above proof is too long, even if you remove comments. We don't really need the\nunpacking steps at the beginning, we can access both parts of the assumption\n`hx : x is_a_max_of A` using shortcuts `h.1` and `h.2`. We can also improve\nreadability without assistance from the tactic state display, clearly announcing\nintermediate goals using `have`. This way we get to the following version of the\nsame proof.\n-/\n\nexample (A : set \u211d) (x y : \u211d) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=\nbegin\n  have : x \u2264 y, from hy.2 x hx.1,\n  have : y \u2264 x, from hx.2 y hy.1,\n  linarith,\nend\n\n/-\nNotice how mathematics based on type theory treats the assumption \n`\u2200 a \u2208 A, a \u2264 y` as a function turning an element `a` of `A` into the statement\n`a \u2264 y`. More precisely, this assumption is the abbreviation of\n`\u2200 a : \u211d, a \u2208 A \u2192 a \u2264 y`. The expression `hy.2 x` appearing in the above proof\nis then the statement `x \u2208 A \u2192 x \u2264 y`, which itself is a function turning a\nstatement `x \u2208 A` into `x \u2264 y` so that the full expression `hy.2 x hx.1` is\nindeed a proof of `x \u2264 y`.\nOne could argue a three line long proof of this lemma is still two lines too long.\nThis is debatable, but mathlib's style is to write very short proofs for trivial\nlemmas. Those proofs are not easy to read but they are meant to indicate that the \nproof is probably not worth reading.\nIn order to reach this stage, we need to know what linarith did for us. It invoked\nthe lemma `le_antisymm` which says: `x \u2264 y \u2192 y \u2264 x \u2192 x = y`. This arrow, which\nis used both for function and implication, is right associative. So the statement is\n`x \u2264 y \u2192 (y \u2264 x \u2192 x = y)` which reads: I will send a proof `p` of `x \u2264 y` to a function\nsending a proof `p'` of `y \u2264 x` to a proof of `x = y`. Hence `le_antisymm p p'` is a\nproof of `x = y`.\nUsing this we can get our one-line proof:\n-/\n\nexample (A : set \u211d) (x y : \u211d) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=\nle_antisymm (hy.2 x hx.1) (hx.2 y hy.1)\n\n/-\nSuch a proof is called a proof term (or a \"term mode\" proof). Notice it has no `begin`\nand `end`. It is directly the kind of low level proof that the Lean kernel is\nconsuming. Commands like `cases`, `specialize` or `linarith` are called tactics, they\nhelp users constructing proof terms that could be very tedious to write directly. \nThe most efficient proof style combines tactics with proof terms like our previous\n`have : x \u2264 y, from hy.2 x hx.1` where `hy.2 x hx.1` is a proof term embeded inside\na tactic mode proof.\nIn the remaining of this file, we'll be characterizing infima of sets of real numbers\nin term of sequences.\n-/\n\n/-- The set of lower bounds of a set of real numbers \u211d -/\ndef low_bounds (A : set \u211d) := { x : \u211d | \u2200 a \u2208 A, x \u2264 a}\n\n/-\nWe now define `a` is an infimum of `A`. Again there is already a more general version\nin mathlib.\n-/\ndef is_inf (x : \u211d) (A : set \u211d) := x is_a_max_of (low_bounds A)\ninfix `is_an_inf_of`:55 := is_inf\n\n/-\nWe need to prove that any number which is greater than the infimum of A is greater\nthan some element of A.\n-/\n\nlemma inf_lt {A : set \u211d} {x : \u211d} (hx : x is_an_inf_of A) :\n  \u2200 y, x < y \u2192 \u2203 a \u2208 A, a < y :=\nbegin\n  -- Let `y` be any real number.\n  intro y,\n  -- Let's prove the contrapositive\n  contrapose,\n  -- The symbol `\u00ac` means negation. Let's ask Lean to rewrite the goal without negation,\n  -- pushing negation through quantifiers and inequalities\n  push_neg,\n  -- Let's assume the premise, calling the assumption `h`\n  intro h,\n  -- `h` is exactly saying `y` is a lower bound of `A` so the second part of\n  -- the infimum assumption `hx` applied to `y` and `h` is exactly what we want.\n  exact hx.2 y h\nend\n\n/-\nIn the above proof, the sequence `contrapose, push_neg` is so common it can be \nabbreviated to `contrapose!`. With these commands, we enter the gray zone between\nproof checking and proof finding. Practical computer proof checking crucially needs\nthe computer to handle tedious proof steps. In the next proof, we'll start using\n`linarith` a bit more seriously, going one step further into automation.\nOur next real goal is to prove inequalities for limits of sequences. We extract the\nfollowing lemma: if `y \u2264 x + \u03b5` for all positive `\u03b5` then `y \u2264 x`.\n-/\n\n\nlemma le_of_le_add_eps {x y : \u211d} : (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  -- Let's prove the contrapositive, asking Lean to push negations right away.\n  contrapose!,\n  -- Assume `h : x < y`.\n  intro h,\n  -- We need to find `\u03b5` such that `\u03b5` is positive and `x + \u03b5 < y`.\n  -- Let's use `(y-x)/2`\n  use ((y-x)/2),\n  -- we now have two properties to prove. Let's do both in turn, using `linarith`\n  split,\n  linarith,\n  linarith,\nend\n\n/- \nNote how `linarith` was used for both sub-goals at the end of the above proof.\nWe could have shortened that using the semi-colon combinator instead of comma, \nwriting `split ; linarith`. \nNext we will study a compressed version of that proof:\n-/\n\nexample {x y : \u211d} : (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  contrapose!,\n  exact assume h, \u27e8(y-x)/2, by linarith, by linarith\u27e9,\nend\n\n/-\nThe angle brackets `\u27e8` and `\u27e9` introduce compound data or proofs. A proof\nof a `\u2203 z, P z` statemement is composed of a witness `z\u2080` and a proof `z` of\n`P z\u2080`. The compound is denoted by `\u27e8z\u2080, h\u27e9`. In the example above, the predicate is\nitself compound, it is a conjunction `P z \u2227 Q z`. So the proof term should read\n`\u27e8z\u2080, \u27e8h\u2081, h\u2082\u27e9\u27e9` where `h\u2081` (resp. `h\u2082`) is a proof of `P z\u2080` (resp. `Q z\u2080`). \nBut these so-called \"anonymous constructor\" brackets are right-associative, so we can\nget rid of the nested brackets. \nThe keyword `by` introduces tactic mode inside term mode, it is a shorter version\nof the `begin`/`end` pair, which is more convenient for single tactic blocks.\nIn this example, `begin` enters tactic mode, `exact` leaves it, `by` re-enters it.\nGoing all the way to a proof term would make the proof much longer, because we \ncrucially use automation with `contrapose!` and `linarith`. We can still get a one-line\nproof using curly braces to gather several tactic invocation, and the `by` abbreviation\ninstead of `begin`/`end`:\n-/\n\nexample {x y : \u211d} : (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nby { contrapose!, exact assume h, \u27e8(y-x)/2, by linarith, by linarith\u27e9 }\n\n/-\nOne could argue that the above proof is a bit too terse, and we are relying too much\non linarith. Let's have more `linarith` calls for smaller steps. For the sake\nof (tiny) variation, we will also assume the premise and argue by contradiction\ninstead of contraposing.\n-/\n\nexample {x y : \u211d} : (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  intro h,\n  -- Assume the conclusion is false, and call this assumption H.\n  by_contradiction H,\n  push_neg at H,\n  -- Now let's compute. \n  have key := calc\n  -- Each line must end with a colon followed by a proof term\n  -- We want to specialize our assumption `h` to `\u03b5 = (y-x)/2` but this is long to\n  -- type, so let's put a hole `_` that Lean will fill in by comparing the \n  -- statement we want to prove and our proof term with a hole. As usual,\n  -- positivity of `(y-x)/2` is proved by `linarith`\n    y   \u2264 x + (y-x)/2 : h _ (by linarith)\n    ... = x/2 + y/2   : by linarith\n    ... < y           : by linarith,\n  -- our key now says `y < y` (notice how the sequence `\u2264`, `=`, `<` was correctly\n  -- merged into a `<`). Let `linarith` find the desired contradiction now.\n  linarith,\n  -- alternatively, we could have provided the proof term\n  -- `exact lt_irrefl y key`\nend\n\n/-\nNow we are ready for some analysis. Let's setup notation for absolute value\n-/\n\nlocal notation `|`x`|` := abs x\n\n/-\nAnd let's define convergence of sequences of real numbers (of course there is\na much more general definition in mathlib).\n-/\n\n/-- The sequence `u` tends to `l` -/\ndef limit (u : \u2115 \u2192 \u211d) (l : \u211d) := \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\n/-\nIn the above definition, `u n` denotes the n-th term of the sequence. We can\nadd parentheses to get `u(n)` but we try to avoid parentheses because they pile up \nvery quickly\n-/\n\n-- If y \u2264 u n for all n and u n goes to x then y \u2264 x\nlemma le_lim {x y : \u211d} {u : \u2115 \u2192 \u211d} (hu : limit u x) (ineq : \u2200 n, y \u2264 u n) : y \u2264 x :=\nbegin\n  -- Let's apply our previous lemma\n  apply le_of_le_add_eps,\n  -- We need to prove y \u2264 x + \u03b5 for all positive \u03b5. \n  -- Let \u03b5 be any positive real\n  intros \u03b5 \u03b5_pos,\n  -- we now specialize our limit assumption to this `\u03b5`, and immediately\n  -- fix a `N` as promised by the definition.\n  cases hu \u03b5 \u03b5_pos with N HN,\n  -- Now we only need to compute until reaching the conclusion\n  calc\n  y \u2264 u N             : ineq N\n  ... = x + (u N - x) : by linarith\n    -- We'll need `add_le_add` which says `a \u2264 b` and `c \u2264 d` implies `a + c \u2264 b + d`\n    -- We need a lemma saying `z \u2264 |z|`. Because we don't know the name of this lemma,\n    -- let's use `library_search`. Because searching thourgh the library is slow,\n    -- Lean will write what it found in the Lean message window when cursor is on\n    -- that line, so that we can replace it by the lemma. We see `le_max_left` which \n    -- says `a \u2264 max a b`. Actually there is a more specific lemma `le_abs_self`\n  ... \u2264 x + |u N - x| : add_le_add (by linarith) (by library_search)\n  ... \u2264 x + \u03b5         : add_le_add (by linarith) (HN N (by linarith)),\nend\n\n/-\nThe next lemma has been extracted from the main proof in order to discuss numbers.\nIn ordinary maths, we know that \u2115 is *not* contained in `\u211d`, whatever the \nconstruction of real numbers that we use. For instance a natural number is not \nan equivalence class of Cauchy sequences. But it's very easy to\npretend otherwise. Formal maths requires slightly more care. In the statement below,\nthe \"type ascription\" `(n + 1 : \u211d)` forces Lean to convert the natural number\n`n+1` into a real number.  The \"inclusion\" map will be displayed in tactic state\nas `\u2191`. There are various lemmas asserting this map is compatible with addition and\nmonotone, but we don't want to bother writing their names. The `norm_cast`\ntactic is designed to wisely apply those lemmas for us.\n-/\n\nlemma inv_succ_pos : \u2200 n : \u2115, 1/(n+1 : \u211d) > 0 :=\nbegin\n  -- Let `n` be any integer\n  intro n,\n  -- Since we don't know the name of the relevant lemma, asserting that the inverse of \n  -- a positive number is positive, let's state that is suffices\n  -- to prove that `n+1`, seen as a real number, is positive, and ask `library_search`\n  suffices : (n + 1 : \u211d) > 0,\n  { library_search },\n  -- Now we want to reduce to a statement about natural numbers, not real numbers \n  -- coming from natural numbers.\n  norm_cast,\n  -- and then get the usual help from `linarith`\n  linarith,\nend\n\n/-\nThat was a pretty long proof for an obvious fact. And stating it as a lemma feels \nstupid, so let's find a way to write it on one line in case we want to include it\nin some other proof without stating a lemma. First the `library_search` call\nabove displays the name of the relevant lemma: `one_div_pos_of_pos`. We can also\nreplace the `linarith` call on the last line by `library_search` to learn the name\nof the lemma `nat.succ_pos` asserting that the successor of a natural number is \npositive. There is also a variant on `norm_cast` that combines it with `exact`.\nThe term mode analogue of `intro` is `\u03bb`. We get down to:\n-/\n\nexample : \u2200 n : \u2115, 1/(n+1 : \u211d) > 0 :=\n\u03bb n, one_div_pos_of_pos (by exact_mod_cast nat.succ_pos n)\n\n/-\nThe next proof uses mostly known things, so we will commment only new aspects.\n-/\n\nlemma limit_inv_succ : \u2200 \u03b5 > 0, \u2203 N : \u2115, \u2200 n \u2265 N, 1/(n + 1 : \u211d) \u2264 \u03b5 :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  suffices : \u2203 N : \u2115, 1/\u03b5 \u2264 N,\n  { -- Because we didn't provide a name for the above statement, Lean called it `this`. \n    -- Let's fix an `N` that works.\n    cases this with N HN,\n    use N,\n    intros n Hn,\n    -- Now we want to rewrite the goal using lemmas\n    -- `div_le_iff' : 0 < b \u2192  (a / b \u2264 c \u2194 a \u2264 b * c)`\n    -- `div_le_iff : 0 < b \u2192  (a / b \u2264 c \u2194 a \u2264 c * b)`\n    -- the second one will be rewritten from right to left, as indicated by `\u2190`.\n    -- Lean will create a side goal for the required positivity assumption that \n    -- we don't provide for `div_le_iff'`.\n    rw [div_le_iff', \u2190 div_le_iff \u03b5_pos],\n    -- We want to replace assumption `Hn` by its real counter-part so that\n    -- linarith can find what it needs.\n    replace Hn : (N : \u211d) \u2264 n, exact_mod_cast Hn,\n    linarith,\n    -- we are still left with the positivity assumption, but already discussed \n    -- how to prove it in the precedining lemma\n    exact_mod_cast nat.succ_pos n },\n  -- Now we need to prove that sufficient statement. \n  -- We want to use that `\u211d` is archimedean. So we start typing \n  -- `exact archimedean_` and hit Ctrl-space to see what completion Lean proposes\n  -- the lemma `archimedean_iff_nat_le` sounds promising. We select the left to\n  -- right implication using `.1`. This a generic lemma for fields equiped with\n  -- a linear (ie total) order. We need to provide a proof that `\u211d` is indeed\n  -- archimedean. This is done using the `apply_instance` tactic that will be \n  -- covered elsewhere.\n  exact archimedean_iff_nat_le.1 (by apply_instance) (1/\u03b5),\nend\n\n/-\nWe can now put all pieces together, with almost no new things to explain.\n-/\n\nlemma inf_seq (A : set \u211d) (x : \u211d) :\n  (x is_an_inf_of A) \u2194 (x \u2208 low_bounds A \u2227 \u2203 u : \u2115 \u2192 \u211d, limit u x \u2227 \u2200 n, u n \u2208 A ) :=\nbegin\n  split,\n  { intro h,\n    split,\n    { exact h.1 },\n    -- On the next line, we don't need to tell Lean to treat `n+1` as a real number because\n    -- we add `x` to it, so Lean knows there is only one way to make sense of this expression.\n    have key : \u2200 n : \u2115, \u2203 a \u2208 A, a < x + 1/(n+1),\n    { intro n,\n      -- we can use the lemma we proved above\n      apply inf_lt h,\n      -- and another one we proved!\n      have : 0 < 1/(n+1 : \u211d), from inv_succ_pos n,\n      linarith },\n    -- Now we need to use axiom of (countable) choice\n    choose u hu using key,\n    use u,\n    split,\n    { intros \u03b5 \u03b5_pos,\n      -- again we use a lemma we proved, specializing it to our fixed `\u03b5`, and fixing a `N`\n      cases limit_inv_succ \u03b5 \u03b5_pos with N H,\n      use N,\n      intros n hn,\n      have : x \u2264 u n, from h.1 _ (hu n).1,\n      have := calc \n        u n < x + 1/(n + 1) : (hu n).2\n        ... \u2264 x + \u03b5         : add_le_add (le_refl x) (H n hn),\n      rw abs_of_nonneg ; linarith },\n    { intro n,\n      exact (hu n).1 } },\n  { intro h,\n    -- Assumption `h` is made of nested compound statements. We can use the \n    -- recursive version of `cases` to unpack it in one go.\n    rcases h with \u27e8x_min, u, lim, huA\u27e9,\n    split,\n    exact x_min,\n    intros y y_mino,\n    apply le_lim lim,\n    intro n,\n    exact y_mino (u n) (huA n) },\nend", "meta": {"author": "iceplant", "repo": "Mermin_Peres", "sha": "d7ea59b5767157420b0fae9dfc09f22ad2826564", "save_path": "github-repos/lean/iceplant-Mermin_Peres", "path": "github-repos/lean/iceplant-Mermin_Peres/Mermin_Peres-d7ea59b5767157420b0fae9dfc09f22ad2826564/src/mathlib_tutorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7165863057902875}}
{"text": "import hom.quotient data.setoid.partition\n\nopen setoid set\n\nnamespace mygroup \n\nnamespace lagrange\n\nopen mygroup.quotient mygroup.subgroup fincard function\n\nvariables {G : Type} [group G] {H : subgroup G}\n\ndef is_lcoset (H : subgroup G) (B : set G) := \u2203 g : G, B = lcoset g H\n\ndef lcosets (H : subgroup G) := { B : set G // is_lcoset H B }\n\ndef lcoset_setoid (H : subgroup G) : setoid G := \n{ r := lcoset_rel H,\n  iseqv := lcoset_iseqv H }\n\nlemma lcoset_setoid_classes : \n  (lcoset_setoid H).classes = { B | \u2203 g : G, B = lcoset g H } :=\nbegin\n  ext, split; rintro \u27e8g, rfl\u27e9; refine \u27e8g, _\u27e9, apply eq.symm,\n  all_goals { show _ = { h | lcoset_rel H h g },\n              ext, split; intro hx,\n                { exact lcoset_digj (self_mem_coset x H) hx },\n                { rw [mem_set_of_eq, lcoset_rel_def] at hx,\n                  rw \u2190 hx, exact self_mem_coset _ _ } }\nend\n\n/-- The left cosets of a subgroup `H` form a partition -/\ndef lcoset_partition (H : subgroup G) : \n  is_partition { B | \u2203 g : G, B = lcoset g H } := \nbegin\n  rw \u2190 lcoset_setoid_classes,\n  exact is_partition_classes (lcoset_setoid H)\nend\n\n/-- Let `H` be a subgroup of the finite group `G`, then the cardinality of `G` \nequals the cardinality of `H` multiplied with the number of left cosets of `H` -/\ntheorem lagrange [fintype G] : \n  fincard G = fincard H * fincard (lcosets H) := \nbegin\n  change fincard G = \n    fincard H * fincard { B | \u2203 g : G, B = lcoset g H },\n  rw [card_eq_finsum_partition (lcoset_partition H), \n    mul_comm, finsum_const_nat],\n  rintros x \u27e8g, rfl\u27e9,\n  exact eq_card_of_lcoset.symm\nend\n\ndef to_lcosets (N : normal G) : G /\u2098 N \u2192 lcosets (N : subgroup G) :=\n\u03bb x, let f : G \u2192 lcosets (N : subgroup G) := \u03bb g, \u27e8g \u22c6 N, \u27e8g, rfl\u27e9\u27e9 in \n  lift_on x f (\u03bb a b h, by simpa [h])\n\nlemma to_lcosets_mk {N : normal G} (g : G) : \n  (to_lcosets N (g : G /\u2098 N)).val = lcoset g N := rfl\n\nlemma bijective_to_lcosets {N : normal G} : bijective (to_lcosets N) :=\nbegin\n  split,\n    { intros x y hxy,\n      rcases exists_mk x with \u27e8x, rfl\u27e9,\n      rcases exists_mk y with \u27e8y, rfl\u27e9,\n      rw [mk_eq, \u2190 to_lcosets_mk, hxy, to_lcosets_mk] },\n    { rintro \u27e8_, g, rfl\u27e9, exact \u27e8g, subtype.eq (to_lcosets_mk g)\u27e9 }\nend\n\nnoncomputable def to_lcosets_equiv (N : normal G) : \n  G /\u2098 N \u2243 { B | \u2203 g : G, B = lcoset g N } :=\nequiv.of_bijective (to_lcosets N) bijective_to_lcosets\n\ntheorem card_quotient_eq_mul [fintype G] (N : normal G) : \n  fincard G = fincard N * fincard (G /\u2098 N) :=\nbegin\n  rw @lagrange _ _ (N : subgroup G),\n  congr' 1, exact of_equiv (to_lcosets_equiv N).symm\nend\n\nend lagrange\n\nend mygroup", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/src/subgroup/lagrange.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7165439517643571}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.star.basic\nimport analysis.normed_space.spectrum\nimport analysis.normed_space.star.exponential\nimport analysis.special_functions.exponential\nimport algebra.star.star_alg_hom\n\n/-! # Spectral properties in C\u22c6-algebras\nIn this file, we establish various properties related to the spectrum of elements in C\u22c6-algebras.\n-/\n\nlocal postfix `\u22c6`:std.prec.max_plus := star\n\nsection\n\nopen_locale topology ennreal\nopen filter ennreal spectrum cstar_ring\n\nsection unitary_spectrum\n\nvariables\n{\ud835\udd5c : Type*} [normed_field \ud835\udd5c]\n{E : Type*} [normed_ring E] [star_ring E] [cstar_ring E]\n[normed_algebra \ud835\udd5c E] [complete_space E]\n\nlemma unitary.spectrum_subset_circle (u : unitary E) :\n  spectrum \ud835\udd5c (u : E) \u2286 metric.sphere 0 1 :=\nbegin\n  nontriviality E,\n  refine \u03bb k hk, mem_sphere_zero_iff_norm.mpr (le_antisymm _ _),\n  { simpa only [cstar_ring.norm_coe_unitary u] using norm_le_norm_of_mem hk },\n  { rw \u2190unitary.coe_to_units_apply u at hk,\n    have hnk := ne_zero_of_mem_of_unit hk,\n    rw [\u2190inv_inv (unitary.to_units u), \u2190spectrum.map_inv, set.mem_inv] at hk,\n    have : \u2016k\u2016\u207b\u00b9 \u2264 \u2016\u2191((unitary.to_units u)\u207b\u00b9)\u2016, simpa only [norm_inv] using norm_le_norm_of_mem hk,\n    simpa using inv_le_of_inv_le (norm_pos_iff.mpr hnk) this }\nend\n\nlemma spectrum.subset_circle_of_unitary {u : E} (h : u \u2208 unitary E) :\n  spectrum \ud835\udd5c u \u2286 metric.sphere 0 1 :=\nunitary.spectrum_subset_circle \u27e8u, h\u27e9\n\nend unitary_spectrum\n\nsection complex_scalars\n\nopen complex\n\nvariables {A : Type*}\n[normed_ring A] [normed_algebra \u2102 A] [complete_space A] [star_ring A] [cstar_ring A]\n\nlocal notation `\u2191\u2090` := algebra_map \u2102 A\n\nlemma is_self_adjoint.spectral_radius_eq_nnnorm {a : A}\n  (ha : is_self_adjoint a) :\n  spectral_radius \u2102 a = \u2016a\u2016\u208a :=\nbegin\n  have hconst : tendsto (\u03bb n : \u2115, (\u2016a\u2016\u208a : \u211d\u22650\u221e)) at_top _ := tendsto_const_nhds,\n  refine tendsto_nhds_unique _ hconst,\n  convert (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a : A)).comp\n      (nat.tendsto_pow_at_top_at_top_of_one_lt one_lt_two),\n  refine funext (\u03bb n, _),\n  rw [function.comp_app, ha.nnnorm_pow_two_pow, ennreal.coe_pow, \u2190rpow_nat_cast,\n    \u2190rpow_mul],\n  simp,\nend\n\nlemma is_star_normal.spectral_radius_eq_nnnorm (a : A) [is_star_normal a] :\n  spectral_radius \u2102 a = \u2016a\u2016\u208a :=\nbegin\n  refine (ennreal.pow_strict_mono two_ne_zero).injective _,\n  have heq : (\u03bb n : \u2115, ((\u2016(a\u22c6 * a) ^ n\u2016\u208a ^ (1 / n : \u211d)) : \u211d\u22650\u221e))\n    = (\u03bb x, x ^ 2) \u2218 (\u03bb n : \u2115, ((\u2016a ^ n\u2016\u208a ^ (1 / n : \u211d)) : \u211d\u22650\u221e)),\n  { funext,\n    rw [function.comp_apply, \u2190rpow_nat_cast, \u2190rpow_mul, mul_comm, rpow_mul, rpow_nat_cast,\n      \u2190coe_pow, sq, \u2190nnnorm_star_mul_self, commute.mul_pow (star_comm_self' a), star_pow], },\n  have h\u2082 := ((ennreal.continuous_pow 2).tendsto (spectral_radius \u2102 a)).comp\n    (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius a),\n  rw \u2190heq at h\u2082,\n  convert tendsto_nhds_unique h\u2082 (pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a\u22c6 * a)),\n  rw [(is_self_adjoint.star_mul_self a).spectral_radius_eq_nnnorm, sq, nnnorm_star_mul_self,\n    coe_mul],\nend\n\n/-- Any element of the spectrum of a selfadjoint is real. -/\ntheorem is_self_adjoint.mem_spectrum_eq_re [star_module \u2102 A] {a : A}\n  (ha : is_self_adjoint a) {z : \u2102} (hz : z \u2208 spectrum \u2102 a) : z = z.re :=\nbegin\n  have hu := exp_mem_unitary_of_mem_skew_adjoint \u2102 (ha.smul_mem_skew_adjoint conj_I),\n  let Iu := units.mk0 I I_ne_zero,\n  have : exp \u2102 (I \u2022 z) \u2208 spectrum \u2102 (exp \u2102 (I \u2022 a)),\n    by simpa only [units.smul_def, units.coe_mk0]\n      using spectrum.exp_mem_exp (Iu \u2022 a) (smul_mem_smul_iff.mpr hz),\n  exact complex.ext (of_real_re _)\n    (by simpa only [\u2190complex.exp_eq_exp_\u2102, mem_sphere_zero_iff_norm, norm_eq_abs, abs_exp,\n      real.exp_eq_one_iff, smul_eq_mul, I_mul, neg_eq_zero]\n      using spectrum.subset_circle_of_unitary hu this),\nend\n\n/-- Any element of the spectrum of a selfadjoint is real. -/\ntheorem self_adjoint.mem_spectrum_eq_re [star_module \u2102 A]\n  (a : self_adjoint A) {z : \u2102} (hz : z \u2208 spectrum \u2102 (a : A)) : z = z.re :=\na.prop.mem_spectrum_eq_re hz\n\n/-- The spectrum of a selfadjoint is real -/\ntheorem is_self_adjoint.coe_re_map_spectrum [star_module \u2102 A] {a : A}\n  (ha : is_self_adjoint a) : spectrum \u2102 a = (coe \u2218 re '' (spectrum \u2102 a) : set \u2102) :=\nle_antisymm (\u03bb z hz, \u27e8z, hz, (ha.mem_spectrum_eq_re hz).symm\u27e9) (\u03bb z, by\n  { rintros \u27e8z, hz, rfl\u27e9,\n    simpa only [(ha.mem_spectrum_eq_re hz).symm, function.comp_app] using hz })\n\n/-- The spectrum of a selfadjoint is real -/\ntheorem self_adjoint.coe_re_map_spectrum [star_module \u2102 A] (a : self_adjoint A) :\n  spectrum \u2102 (a : A) = (coe \u2218 re '' (spectrum \u2102 (a : A)) : set \u2102) :=\na.property.coe_re_map_spectrum\n\nend complex_scalars\n\nnamespace star_alg_hom\n\nvariables {F A B : Type*}\n[normed_ring A] [normed_algebra \u2102 A] [complete_space A] [star_ring A] [cstar_ring A]\n[normed_ring B] [normed_algebra \u2102 B] [complete_space B] [star_ring B] [cstar_ring B]\n[hF : star_alg_hom_class F \u2102 A B] (\u03c6 : F)\ninclude hF\n\n/-- A star algebra homomorphism of complex C\u22c6-algebras is norm contractive. -/\nlemma nnnorm_apply_le (a : A) : \u2016(\u03c6 a : B)\u2016\u208a \u2264 \u2016a\u2016\u208a :=\nbegin\n  suffices : \u2200 s : A, is_self_adjoint s \u2192 \u2016\u03c6 s\u2016\u208a \u2264 \u2016s\u2016\u208a,\n  { exact nonneg_le_nonneg_of_sq_le_sq zero_le'\n      (by simpa only [nnnorm_star_mul_self, map_star, map_mul]\n      using this _ (is_self_adjoint.star_mul_self a)) },\n  { intros s hs,\n    simpa only [hs.spectral_radius_eq_nnnorm, (hs.star_hom_apply \u03c6).spectral_radius_eq_nnnorm,\n      coe_le_coe] using (show spectral_radius \u2102 (\u03c6 s) \u2264 spectral_radius \u2102 s,\n      from supr_le_supr_of_subset (alg_hom.spectrum_apply_subset \u03c6 s)) }\nend\n\n/-- A star algebra homomorphism of complex C\u22c6-algebras is norm contractive. -/\nlemma norm_apply_le (a : A) : \u2016(\u03c6 a : B)\u2016 \u2264 \u2016a\u2016 := nnnorm_apply_le \u03c6 a\n\n/-- Star algebra homomorphisms between C\u22c6-algebras are continuous linear maps.\nSee note [lower instance priority] -/\n@[priority 100]\nnoncomputable instance : continuous_linear_map_class F \u2102 A B :=\n{ map_continuous := \u03bb \u03c6, add_monoid_hom_class.continuous_of_bound \u03c6 1\n    (by simpa only [one_mul] using nnnorm_apply_le \u03c6),\n  .. alg_hom_class.linear_map_class }\n\nend star_alg_hom\n\nend\n\nnamespace weak_dual\n\nopen continuous_map complex\nopen_locale complex_star_module\n\nvariables {F A : Type*} [normed_ring A] [normed_algebra \u2102 A] [complete_space A]\n  [star_ring A] [cstar_ring A] [star_module \u2102 A] [hF : alg_hom_class F \u2102 A \u2102]\n\ninclude hF\n\n/-- This instance is provided instead of `star_alg_hom_class` to avoid type class inference loops.\nSee note [lower instance priority] -/\n@[priority 100]\nnoncomputable instance : star_hom_class F A \u2102 :=\n{ coe := \u03bb \u03c6, \u03c6,\n  coe_injective' := fun_like.coe_injective',\n  map_star := \u03bb \u03c6 a,\n  begin\n    suffices hsa : \u2200 s : self_adjoint A, (\u03c6 s)\u22c6 = \u03c6 s,\n    { rw \u2190real_part_add_I_smul_imaginary_part a,\n      simp only [map_add, map_smul, star_add, star_smul, hsa, self_adjoint.star_coe_eq] },\n    { intros s,\n      have := alg_hom.apply_mem_spectrum \u03c6 (s : A),\n      rw self_adjoint.coe_re_map_spectrum s at this,\n      rcases this with \u27e8\u27e8_, _\u27e9, _, heq\u27e9,\n      rw [\u2190heq, is_R_or_C.star_def, is_R_or_C.conj_of_real] }\n  end }\n\n/-- This is not an instance to avoid type class inference loops. See\n`weak_dual.complex.star_hom_class`. -/\nnoncomputable def _root_.alg_hom_class.star_alg_hom_class : star_alg_hom_class F \u2102 A \u2102 :=\n{ coe := \u03bb f, f,\n  .. weak_dual.complex.star_hom_class,\n  .. hF }\n\nomit hF\n\nnamespace character_space\n\nnoncomputable instance : star_alg_hom_class (character_space \u2102 A) \u2102 A \u2102 :=\n{ coe := \u03bb f, f,\n  .. alg_hom_class.star_alg_hom_class }\n\nend character_space\n\nend weak_dual\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/star/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7165439498944598}}
{"text": "import data.vector .list .string\n\nvariables {\u03b1 : Type} {k m n : nat}\n\nnamespace vector\n\ndef dot_prod [ring \u03b1] : \u2200 {k}, vector \u03b1 k \u2192 vector \u03b1 k \u2192 \u03b1 \n| 0 v w     := 0\n| (k+1) v w := v.head * w.head + dot_prod v.tail w.tail\ninfix `\u2b1d` := dot_prod\n\ndef pad_length [has_repr \u03b1] : \u2200 {n}, vector \u03b1 n \u2192 nat \n| 0 x := 0\n| (n+1) x := max (has_repr.repr x.head).length x.tail.pad_length\n\ndef singleton (a : \u03b1) : vector \u03b1 1 := \u27e8[a],rfl\u27e9 \n\ndef add [has_add \u03b1] : \u2200 {k : nat}, vector \u03b1 k \u2192 vector \u03b1 k \u2192 vector \u03b1 k \n| 0 x y := nil \n| (k+1) x y :=\n  let x' : vector \u03b1 k := x.tail in\n  let y' : vector \u03b1 k := y.tail in\n  cons (x.head + y.head) (add x' y')\n\ninstance has_add [has_add \u03b1] : has_add (vector \u03b1 k) := \u27e8add\u27e9 \n\ndef sub [has_sub \u03b1] : \u2200 {k : nat}, vector \u03b1 k \u2192 vector \u03b1 k \u2192 vector \u03b1 k \n| 0 x y := nil \n| (k+1) x y :=\n  let x' : vector \u03b1 k := x.tail in\n  let y' : vector \u03b1 k := y.tail in\n  cons (x.head - y.head) (sub x' y')\n\ninstance has_sub [has_sub \u03b1] : has_sub (vector \u03b1 k) := \u27e8sub\u27e9 \n\ndef halve {k} (x : vector \u03b1 (2^(k+1))) : \n  vector \u03b1 (2^k) \u00d7 vector \u03b1 (2^k) := \n( \u27e8x.val.take (2^k), \n  begin \n    rw [list.length_take, x.property, min_eq_left],\n    rw [nat.pow_succ, nat.mul_succ], apply nat.le_add_left\n  end\u27e9, \n  \u27e8x.val.drop (2^k), \n  begin\n    rw [list.length_drop, x.property, nat.pow_succ, \n      nat.mul_succ, nat.add_sub_cancel], simp\n  end\u27e9 ) \n\ndef double {k} : \n  (vector \u03b1 (2^k) \u00d7 vector \u03b1 (2^k)) \u2192 vector \u03b1 (2^(k+1)) \n| \u27e8x,y\u27e9 := \n  \u27e8x.val ++ y.val, \n   begin\n     rw [list.length_append, x.property, y.property,\n       nat.pow_succ, nat.mul_succ], simp\n   end\u27e9 \n\nlemma double_halve {k} (x : vector \u03b1 (2^(k+1))) :\n  double (halve x) = x := \nbegin\n  apply vector.eq, simp [double, halve, to_list], \n  apply list.append_take_drop\nend\n\nend vector\n\ndef row_to_string [has_repr \u03b1] (l) : \u2200 {n}, vector \u03b1 n \u2192 string\n| 0 x     := \" |\" \n| (n+1) x := \n  \" | \" ++ (has_repr.repr x.head).pad l ++ row_to_string x.tail\n\n\n\n\n #exit \n\ndef split (m n) (x : vector \u03b1 (m+n)) : (vector \u03b1 m \u00d7 vector \u03b1 n) :=\n( \u27e8(x.val.split m).fst, list.length_fst_split _ n _ x.property\u27e9, \n  \u27e8(x.val.split m).snd, list.length_snd_split _ n _ x.property\u27e9 )\n\nlemma append_split (m n) (x : vector \u03b1 (m+n)) :\n  append (split m n x).fst (split m n x).snd = x :=\nbegin\n  simp [split, append], apply vector.eq, \n  simp [to_list], apply list.append_split\nend\n", "meta": {"author": "skbaek", "repo": "strassen", "sha": "396c94805360b10896d436813c1e4d0190885840", "save_path": "github-repos/lean/skbaek-strassen", "path": "github-repos/lean/skbaek-strassen/strassen-396c94805360b10896d436813c1e4d0190885840/vector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7165439417501562}}
{"text": "/-\nThis file defines the I-adic topology on a commutative ring R with ideal I.\n\nThe ring is wrapped in `adic_ring I := R`, which then receive all relevant type classes.\nThe end-product is `instance : topological_ring (adic_ring I)`.\n-/\n\nimport tactic.ring\nimport data.pnat\nimport ring_theory.ideal_operations\nimport analysis.topology.topological_groups\n\nopen filter set\n\nvariables {R : Type*} [comm_ring R] \n\nnamespace filter\n-- This will be the filter `nhds 0` in our adic-ring\n-- The first mathematical key fact is this is indeed a filter\ndef of_ideal (I : ideal R): filter R :=\n{ sets := {s : set R | \u2203 n : \u2115, (I^n).carrier \u2286 s},\n  univ_sets := \u27e80, by simp\u27e9,\n  sets_of_superset := assume s t \u27e8n, hn\u27e9 st, \u27e8n, subset.trans hn st\u27e9,\n  inter_sets := assume s t \u27e8n, hn\u27e9 \u27e8m, hm\u27e9, \n    have (I ^ (n + m)).carrier \u2286 (I^n).carrier \u2229 (I^m).carrier, \n    by rw pow_add ; exact ideal.mul_le_inf, \n    \u27e8n + m, subset.trans this (inter_subset_inter hn hm)\u27e9 }\n\nlemma mem_of_ideal_sets {I : ideal R} (s : set R) : \n  s \u2208 (filter.of_ideal I).sets \u2194 \u2203 n : \u2115, (I^n).carrier \u2286 s := iff.rfl\n\nlemma mem_of_ideal_sets' {I : ideal R} (s : set R) : \n  s \u2208 (filter.of_ideal I).sets \u2194 \u2203 n > 0, (I^n).carrier \u2286 s := \nbegin\n  split,\n  { rintros \u27e8n, H\u27e9,\n    cases n with n H,\n    { rw univ_subset_iff.1 H,\n      use [1, nat.one_pos],\n      simp },\n    { use [n+1, nat.add_pos_right n nat.one_pos, H] } },\n  { rintros \u27e8n, npos, H\u27e9,\n    use [n, H] },\nend\n\n-- Next lemma is currently unused, but relates to standard mathlib definition style\nlemma of_ideal_eq_infi (I : ideal R) :\n  filter.of_ideal I = \u2a05 n : \u2115, principal (I^n : ideal R) :=\nbegin\n  apply filter_eq,\n  rw infi_sets_eq,\n  { ext U,\n    simp [mem_of_ideal_sets, mem_Union, mem_principal_sets],\n    exact iff.refl _ },\n  { rintros n m,\n    have : (I ^ (n + m)).carrier \u2286 (I^n).carrier \u2229 (I^m).carrier, \n    by rw pow_add ; exact ideal.mul_le_inf, \n    cases (subset_inter_iff.1 this),\n    use n+m,\n    split ; intros U U_sub ; rw mem_principal_sets at * ;\n    exact subset.trans (by assumption) U_sub },\n  exact \u27e81\u27e9\nend\nend filter\n\n-- Here we check our I-adic neighborhood of zero filter has the required properties to\n-- be (nhds 0) in a uniform additive group\ndef add_group_with_zero_nhd.of_ideal (I : ideal R) : add_group_with_zero_nhd R :=\n{ Z := filter.of_ideal I,\n  zero_Z := assume U \u27e8n, H\u27e9, mem_pure $ H (I^n).zero_mem,\n  sub_Z := begin\n             rw tendsto_prod_self_iff,\n             rintros U \u27e8n, h\u27e9,\n             use [(I^n).carrier, n],\n             intros x x' x_in x'_in,\n             exact h ((I^n).sub_mem x_in x'_in),\n           end,\n  ..\u2039comm_ring R\u203a}\n\ndef adic_topology (I : ideal R) : topological_space R :=  \n  @add_group_with_zero_nhd.topological_space R (add_group_with_zero_nhd.of_ideal I)\n\ndef adic_ring (I : ideal R) := R\n\nnamespace adic_ring\nvariable {I : ideal R}\n\ninstance : comm_ring (adic_ring I) := by unfold adic_ring ; apply_instance\ninstance : topological_space (adic_ring I) := adic_topology I\n\nlemma nhds_zero_eq (I : ideal R) : (nhds (0 : adic_ring I)).sets = {s : set R | \u2203 n : \u2115, (I^n).carrier \u2286 s} := \nbegin\n  rw add_group_with_zero_nhd.nhds_eq,\n  dsimp [adic_ring],\n  ext s,\n  simp [filter.mem_of_ideal_sets], \n  finish,\nend\n\nlemma nhds_eq (I : ideal R) {s : set (adic_ring I)} {a : adic_ring I}: \n  s \u2208 (nhds a).sets \u2194 \u2203 n : \u2115, (\u03bb b, b + a) '' (I^n).carrier \u2286 s :=\nbegin\n  rw [add_group_with_zero_nhd.nhds_eq, mem_map, \u2190add_group_with_zero_nhd.nhds_zero_eq_Z, nhds_zero_eq],\n  split ;\n  { rintros \u27e8n, h\u27e9,\n    use n,\n    rwa image_subset_iff at * }\nend\n\n-- This is the second mathematical key fact: multiplication is continuous in I-adic topology\nlemma continuous_mul' : continuous (\u03bb (p : adic_ring I \u00d7 adic_ring I), p.fst * p.snd) :=\ncontinuous_iff_tendsto.2 $ assume \u27e8x\u2080, y\u2080\u27e9,\nbegin\n  rw nhds_prod_eq,\n  rw tendsto_prod_iff,\n  simp [adic_ring.nhds_eq I] at *,\n  rintros V n hV,\n  let J := I^n,\n  use [has_add.add x\u2080 '' J.carrier, n],\n  use [has_add.add y\u2080 '' J.carrier, n],\n  rintros x y \u27e8a, a_in, x\u2080a\u27e9 \u27e8b, b_in, y\u2080b\u27e9,\n  apply hV,\n  have key : (x\u2080*b + y\u2080*a + a*b) + x\u2080*y\u2080 = x*y, by rw [\u2190x\u2080a, \u2190y\u2080b] ; ring,\n  use x\u2080*b + y\u2080*a + a*b,\n  exact\n  \u27e8J.add_mem \n     (J.add_mem (J.mul_mem_left b_in) (J.mul_mem_left a_in))\n     (J.mul_mem_left b_in),\n   key\u27e9,\nend\n\ninstance : topological_add_group (adic_ring I) :=  by apply add_group_with_zero_nhd.topological_add_group\ninstance : uniform_space (adic_ring I) := topological_add_group.to_uniform_space _\ninstance : uniform_add_group (adic_ring I) := topological_add_group_is_uniform\ninstance : topological_ring (adic_ring I) :=\n{ continuous_add := continuous_add',\n  continuous_mul := continuous_mul',\n  continuous_neg := continuous_neg' }\nend adic_ring", "meta": {"author": "mr-infty", "repo": "perfectoid-spaces", "sha": "1a49b3897ec3c7b871d8c970926c00f727a4e2a6", "save_path": "github-repos/lean/mr-infty-perfectoid-spaces", "path": "github-repos/lean/mr-infty-perfectoid-spaces/perfectoid-spaces-1a49b3897ec3c7b871d8c970926c00f727a4e2a6/src/for_mathlib/adic_topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7165439409052853}}
{"text": "import automata.dfa\nimport regular.regex\nimport data.list.basic\nimport regular.list_lemmas\n\nopen DFA list\n\nnamespace pumping\n\nvariables {S : Type} {Q : Type} {L : set (list S)} [fintype S] [fintype Q] [decidable_eq Q]\nvariables {w : list S}\n\nlemma dfa_word_split (d : DFA S Q) (st : Q) (w : list S):\n    (fintype.card Q) \u2264 length w \u2192  \n    \u2203 (x y z : list S) (t : Q), x ++ y ++ z = w \u2227 (x ++ y).length \u2264 (fintype.card Q) \u2227 y \u2260 [] \u2227 go d st x = t \u2227 go d t y = t := \nbegin\n    rintro hlen,\n    have tmp2 : (finset.univ : finset Q).card < (finset.range (fintype.card Q + 1)).card, from by {\n        simp only [hlen, finset.card_range],\n        rw nat.lt_succ_iff,\n        refl,\n    },\n    have tmp3 := finset.exists_ne_map_eq_of_card_lt_of_maps_to tmp2,\n    specialize tmp3 (\u03bb a _, finset.mem_univ (go d st (take a w))),\n    rcases tmp3 with \u27e8x, hx, y, hy, x_ne_y, go_xy_eq\u27e9,\n    rw finset.mem_range at hx hy,\n    replace hx := nat.le_of_lt_succ hx,\n    replace hy := nat.le_of_lt_succ hy,\n    \n    wlog x_lt_y : x \u2264 y,\n    replace x_lt_y := nat.lt_of_le_and_ne x_lt_y x_ne_y,\n    \n    use [take x $ take y w, drop x $ take y w, drop y w, go d st (take x w)],\n    simp only [true_and, take_append_drop, eq_self_iff_true], \n    refine \u27e8_, _, _, _\u27e9, {\n        rwa [length_take, min_eq_left (le_trans hy hlen)],\n    }, {\n        exact drop_of_take_of_lt_ne_nil x_lt_y (le_trans hy hlen),\n    }, {\n        rw [take_take, min_eq_left_of_lt x_lt_y],\n    }, {\n        rw [\u2190 dfa_go_append', go_xy_eq],\n        congr,\n        exact take_append_drop_of_lt x_lt_y,\n    }\nend  \n\n\nlemma dfa_go_repeat {d : DFA S Q} {st : Q} {w: list S} {k : \u2115} :\n    go d st w = st \u2192 go d st (repeat w k).join = st :=\nbegin\n    intro go_base,\n    induction k, {\n        simp only [join, go_finish, repeat],\n    }, {\n        simp only [join, repeat_succ],\n        rwa [dfa_go_append', go_base],\n    }\nend\n\nlemma pumping_lemma :\n    dfa_lang L \u2192 \n        (\u2203 (n : \u2115), \u2200 w, w \u2208 L \u2192 n \u2264 length w \u2192\n        (\u2203 (x y z : list S), x ++ y ++ z = w \u2227 y \u2260 [] \u2227 (x ++ y).length \u2264 n \u2227\n        \u2200 (k : \u2115), x ++ (repeat y k).join ++ z \u2208 L)) :=\nbegin\n    rintro \u27e8Q, _, _, dfa, rfl\u27e9,\n    resetI,\n    use fintype.card Q,\n    rintro w w_dfa w_len,\n    \n    rcases dfa_word_split dfa dfa.start w w_len with \u27e8x, y, z, t, xyz, xy_len, ynil, hx, hy\u27e9,\n    \n    refine \u27e8x, y, z, xyz, ynil, xy_len, \u03bb k, _\u27e9,     \n    simp only [lang_of_dfa, dfa_accepts_word, set.mem_set_of_eq] at w_dfa \u22a2,\n    rw \u2190 xyz at w_dfa,\n    rw [append_assoc, dfa_go_append', hx, dfa_go_append'] at w_dfa \u22a2,\n    rw dfa_go_repeat hy,\n    rwa hy at w_dfa, \nend\n\nlemma pumping_lemma_negation {L : set (list S)} :\n    (\u2200 n : \u2115, \u2203 (w : list S), w \u2208 L \u2227 n \u2264 length w \u2227\n     \u2200 (x y z : list S), x ++ y ++ z = w \u2192 y \u2260 [] \u2192 (x ++ y).length \u2264 n \u2192\n     \u2203 k : \u2115, x ++ (repeat y k).join ++ z \u2209 L) \u2192 \u00acdfa_lang L:=\nbegin\n    contrapose,\n    push_neg,\n    refine pumping_lemma,\nend\n\nend pumping", "meta": {"author": "VArtem", "repo": "lean-regular-languages", "sha": "e877243188253d0ac17ccf0ae2da7bf608686ff0", "save_path": "github-repos/lean/VArtem-lean-regular-languages", "path": "github-repos/lean/VArtem-lean-regular-languages/lean-regular-languages-e877243188253d0ac17ccf0ae2da7bf608686ff0/src/regular/pumping_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7165439388552322}}
{"text": "import MyNat.Definition\nimport MyNat.Addition\nimport Mathlib.Tactic.Relation.Symm\nnamespace MyNat\nopen MyNat\n\naxiom zero_ne_succ (a : MyNat) : 0 \u2260 succ a\n\n/-!\n\n# Advanced Addition World\n\n## Level 9: `succ_ne_zero`\n\nIn this level we will use a new tactic, the [symm tactic](../Tactics/symm.lean.md).\n\n`symm` turns goals of the form `\u22a2 A = B` to `\u22a2 B = A`.\nThis tactic is extensible, meaning you can add new `@[symm]`\nattributes to things to teach `symm` new tricks, like we\ndid with the `simp` tactic.  To teach it how to deal with\n`\u2260` we write this:\n-/\n\n@[symm] def neqSymm {\u03b1 : Type} (a b: \u03b1) : a \u2260 b \u2192 b \u2260 a := Ne.symm\n\n/-!\n\nLevels 9 to 13 introduce the last axiom of Peano, namely\nthat `0 \u2260 succ a`. The proof of this is called `zero_ne_succ a`.\n\n`zero_ne_succ (a : MyNat) : 0 \u2260 succ a`\n\nWe can simply use the `symm` tactic to flip this goal into\n`succ a \u2260 0` which then matches our `zero_ne_succ` axiom.\n\n## Theorem : succ_ne_zero\nZero is not the successor of any natural number.\n-/\n\ntheorem succ_ne_zero (a : MyNat) : succ a \u2260 0 := by\n  symm\n  apply (zero_ne_succ a)\n\n/-!\nNext up [Level 10](./Level10.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/AdvancedAdditionWorld/Level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.7853085783754369, "lm_q1q2_score": 0.716543938432797}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.pairing\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Sqrt\nimport Mathbin.Data.Set.Lattice\nimport Mathbin.Algebra.Group.Prod\nimport Mathbin.Algebra.Order.Monoid.MinMax\n\n/-!\n#  Naturals pairing function\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines a pairing function for the naturals as follows:\n```text\n 0  1  4  9 16\n 2  3  5 10 17\n 6  7  8 11 18\n12 13 14 15 19\n20 21 22 23 24\n```\n\nIt has the advantage of being monotone in both directions and sending `\u27e60, n^2 - 1\u27e7` to\n`\u27e60, n - 1\u27e7\u00b2`.\n-/\n\n\nopen Prod Decidable Function\n\nnamespace Nat\n\n#print Nat.pair /-\n/-- Pairing function for the natural numbers. -/\n@[pp_nodot]\ndef pair (a b : \u2115) : \u2115 :=\n  if a < b then b * b + a else a * a + a + b\n#align nat.mkpair Nat.pair\n-/\n\n#print Nat.unpair /-\n/-- Unpairing function for the natural numbers. -/\n@[pp_nodot]\ndef unpair (n : \u2115) : \u2115 \u00d7 \u2115 :=\n  let s := sqrt n\n  if n - s * s < s then (n - s * s, s) else (s, n - s * s - s)\n#align nat.unpair Nat.unpair\n-/\n\n#print Nat.pair_unpair /-\n@[simp]\ntheorem pair_unpair (n : \u2115) : pair (unpair n).1 (unpair n).2 = n :=\n  by\n  dsimp only [unpair]; set s := sqrt n\n  have sm : s * s + (n - s * s) = n := add_tsub_cancel_of_le (sqrt_le _)\n  split_ifs\n  \u00b7 simp [mkpair, h, sm]\n  \u00b7 have hl : n - s * s - s \u2264 s :=\n      tsub_le_iff_left.mpr (tsub_le_iff_left.mpr <| by rw [\u2190 add_assoc] <;> apply sqrt_le_add)\n    simp [mkpair, hl.not_lt, add_assoc, add_tsub_cancel_of_le (le_of_not_gt h), sm]\n#align nat.mkpair_unpair Nat.pair_unpair\n-/\n\n#print Nat.pair_unpair' /-\ntheorem pair_unpair' {n a b} (H : unpair n = (a, b)) : pair a b = n := by\n  simpa [H] using mkpair_unpair n\n#align nat.mkpair_unpair' Nat.pair_unpair'\n-/\n\n#print Nat.unpair_pair /-\n@[simp]\ntheorem unpair_pair (a b : \u2115) : unpair (pair a b) = (a, b) :=\n  by\n  dsimp only [mkpair]; split_ifs\n  \u00b7 show unpair (b * b + a) = (a, b)\n    have be : sqrt (b * b + a) = b := sqrt_add_eq _ (le_trans (le_of_lt h) (Nat.le_add_left _ _))\n    simp [unpair, be, add_tsub_cancel_right, h]\n  \u00b7 show unpair (a * a + a + b) = (a, b)\n    have ae : sqrt (a * a + (a + b)) = a :=\n      by\n      rw [sqrt_add_eq]\n      exact add_le_add_left (le_of_not_gt h) _\n    simp [unpair, ae, Nat.not_lt_zero, add_assoc]\n#align nat.unpair_mkpair Nat.unpair_pair\n-/\n\n#print Nat.pairEquiv /-\n/-- An equivalence between `\u2115 \u00d7 \u2115` and `\u2115`. -/\n@[simps (config := { fullyApplied := false })]\ndef pairEquiv : \u2115 \u00d7 \u2115 \u2243 \u2115 :=\n  \u27e8uncurry pair, unpair, fun \u27e8a, b\u27e9 => unpair_pair a b, pair_unpair\u27e9\n#align nat.mkpair_equiv Nat.pairEquiv\n-/\n\n#print Nat.surjective_unpair /-\ntheorem surjective_unpair : Surjective unpair :=\n  pairEquiv.symm.Surjective\n#align nat.surjective_unpair Nat.surjective_unpair\n-/\n\n#print Nat.pair_eq_pair /-\n@[simp]\ntheorem pair_eq_pair {a b c d : \u2115} : pair a b = pair c d \u2194 a = c \u2227 b = d :=\n  pairEquiv.Injective.eq_iff.trans (@Prod.ext_iff \u2115 \u2115 (a, b) (c, d))\n#align nat.mkpair_eq_mkpair Nat.pair_eq_pair\n-/\n\n#print Nat.unpair_lt /-\ntheorem unpair_lt {n : \u2115} (n1 : 1 \u2264 n) : (unpair n).1 < n :=\n  by\n  let s := sqrt n\n  simp [unpair]; change sqrt n with s\n  by_cases h : n - s * s < s <;> simp [h]\n  \u00b7 exact lt_of_lt_of_le h (sqrt_le_self _)\n  \u00b7 simp at h\n    have s0 : 0 < s := sqrt_pos.2 n1\n    exact lt_of_le_of_lt h (tsub_lt_self n1 (mul_pos s0 s0))\n#align nat.unpair_lt Nat.unpair_lt\n-/\n\n#print Nat.unpair_zero /-\n@[simp]\ntheorem unpair_zero : unpair 0 = 0 := by\n  rw [unpair]\n  simp\n#align nat.unpair_zero Nat.unpair_zero\n-/\n\n#print Nat.unpair_left_le /-\ntheorem unpair_left_le : \u2200 n : \u2115, (unpair n).1 \u2264 n\n  | 0 => by simp\n  | n + 1 => le_of_lt (unpair_lt (Nat.succ_pos _))\n#align nat.unpair_left_le Nat.unpair_left_le\n-/\n\n#print Nat.left_le_pair /-\ntheorem left_le_pair (a b : \u2115) : a \u2264 pair a b := by simpa using unpair_left_le (mkpair a b)\n#align nat.left_le_mkpair Nat.left_le_pair\n-/\n\n#print Nat.right_le_pair /-\ntheorem right_le_pair (a b : \u2115) : b \u2264 pair a b :=\n  by\n  by_cases h : a < b <;> simp [mkpair, h]\n  exact le_trans (le_mul_self _) (Nat.le_add_right _ _)\n#align nat.right_le_mkpair Nat.right_le_pair\n-/\n\n#print Nat.unpair_right_le /-\ntheorem unpair_right_le (n : \u2115) : (unpair n).2 \u2264 n := by\n  simpa using right_le_mkpair n.unpair.1 n.unpair.2\n#align nat.unpair_right_le Nat.unpair_right_le\n-/\n\n#print Nat.pair_lt_pair_left /-\ntheorem pair_lt_pair_left {a\u2081 a\u2082} (b) (h : a\u2081 < a\u2082) : pair a\u2081 b < pair a\u2082 b :=\n  by\n  by_cases h\u2081 : a\u2081 < b <;> simp [mkpair, h\u2081, add_assoc]\n  \u00b7 by_cases h\u2082 : a\u2082 < b <;> simp [mkpair, h\u2082, h]\n    simp at h\u2082\n    apply add_lt_add_of_le_of_lt\n    exact mul_self_le_mul_self h\u2082\n    exact lt_add_right _ _ _ h\n  \u00b7 simp at h\u2081\n    simp [not_lt_of_gt (lt_of_le_of_lt h\u2081 h)]\n    apply add_lt_add\n    exact mul_self_lt_mul_self h\n    apply add_lt_add_right <;> assumption\n#align nat.mkpair_lt_mkpair_left Nat.pair_lt_pair_left\n-/\n\n#print Nat.pair_lt_pair_right /-\ntheorem pair_lt_pair_right (a) {b\u2081 b\u2082} (h : b\u2081 < b\u2082) : pair a b\u2081 < pair a b\u2082 :=\n  by\n  by_cases h\u2081 : a < b\u2081 <;> simp [mkpair, h\u2081, add_assoc]\n  \u00b7 simp [mkpair, lt_trans h\u2081 h, h]\n    exact mul_self_lt_mul_self h\n  \u00b7 by_cases h\u2082 : a < b\u2082 <;> simp [mkpair, h\u2082, h]\n    simp at h\u2081\n    rw [add_comm, add_comm _ a, add_assoc, add_lt_add_iff_left]\n    rwa [add_comm, \u2190 sqrt_lt, sqrt_add_eq]\n    exact le_trans h\u2081 (Nat.le_add_left _ _)\n#align nat.mkpair_lt_mkpair_right Nat.pair_lt_pair_right\n-/\n\n/- warning: nat.mkpair_lt_max_add_one_sq -> Nat.pair_lt_max_add_one_sq is a dubious translation:\nlean 3 declaration is\n  forall (m : Nat) (n : Nat), LT.lt.{0} Nat Nat.hasLt (Nat.pair m n) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (LinearOrder.max.{0} Nat Nat.linearOrder m n) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne)))))\nbut is expected to have type\n  forall (m : Nat) (n : Nat), LT.lt.{0} Nat instLTNat (Nat.pair m n) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Max.max.{0} Nat Nat.instMaxNat m n) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)))\nCase conversion may be inaccurate. Consider using '#align nat.mkpair_lt_max_add_one_sq Nat.pair_lt_max_add_one_sq\u2093'. -/\ntheorem pair_lt_max_add_one_sq (m n : \u2115) : pair m n < (max m n + 1) ^ 2 :=\n  by\n  rw [mkpair, add_sq, mul_one, two_mul, sq, add_assoc, add_assoc]\n  cases lt_or_le m n\n  \u00b7 rw [if_pos h, max_eq_right h.le, add_lt_add_iff_left, add_assoc]\n    exact h.trans_le (self_le_add_right n _)\n  \u00b7 rw [if_neg h.not_lt, max_eq_left h, add_lt_add_iff_left, add_assoc, add_lt_add_iff_left]\n    exact lt_succ_of_le h\n#align nat.mkpair_lt_max_add_one_sq Nat.pair_lt_max_add_one_sq\n\n/- warning: nat.max_sq_add_min_le_mkpair -> Nat.max_sq_add_min_le_pair is a dubious translation:\nlean 3 declaration is\n  forall (m : Nat) (n : Nat), LE.le.{0} Nat Nat.hasLe (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) (LinearOrder.max.{0} Nat Nat.linearOrder m n) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.min.{0} Nat Nat.linearOrder m n)) (Nat.pair m n)\nbut is expected to have type\n  forall (m : Nat) (n : Nat), LE.le.{0} Nat instLENat (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) (Max.max.{0} Nat Nat.instMaxNat m n) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) (Min.min.{0} Nat instMinNat m n)) (Nat.pair m n)\nCase conversion may be inaccurate. Consider using '#align nat.max_sq_add_min_le_mkpair Nat.max_sq_add_min_le_pair\u2093'. -/\ntheorem max_sq_add_min_le_pair (m n : \u2115) : max m n ^ 2 + min m n \u2264 pair m n :=\n  by\n  rw [mkpair]\n  cases lt_or_le m n\n  \u00b7 rw [if_pos h, max_eq_right h.le, min_eq_left h.le, sq]\n  \u00b7 rw [if_neg h.not_lt, max_eq_left h, min_eq_right h, sq, add_assoc, add_le_add_iff_left]\n    exact le_add_self\n#align nat.max_sq_add_min_le_mkpair Nat.max_sq_add_min_le_pair\n\n#print Nat.add_le_pair /-\ntheorem add_le_pair (m n : \u2115) : m + n \u2264 pair m n :=\n  (max_sq_add_min_le_pair _ _).trans' <|\n    by\n    rw [sq, \u2190 min_add_max, add_comm, add_le_add_iff_right]\n    exact le_mul_self _\n#align nat.add_le_mkpair Nat.add_le_pair\n-/\n\n#print Nat.unpair_add_le /-\ntheorem unpair_add_le (n : \u2115) : (unpair n).1 + (unpair n).2 \u2264 n :=\n  (add_le_pair _ _).trans_eq (pair_unpair _)\n#align nat.unpair_add_le Nat.unpair_add_le\n-/\n\nend Nat\n\nopen Nat\n\nsection CompleteLattice\n\n/- warning: supr_unpair -> sup\u1d62_unpair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] (f : Nat -> Nat -> \u03b1), Eq.{succ u1} \u03b1 (sup\u1d62.{u1, 1} \u03b1 (CompleteSemilatticeSup.toHasSup.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeSup.{u1} \u03b1 _inst_1)) Nat (fun (n : Nat) => f (Prod.fst.{0, 0} Nat Nat (Nat.unpair n)) (Prod.snd.{0, 0} Nat Nat (Nat.unpair n)))) (sup\u1d62.{u1, 1} \u03b1 (CompleteSemilatticeSup.toHasSup.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeSup.{u1} \u03b1 _inst_1)) Nat (fun (i : Nat) => sup\u1d62.{u1, 1} \u03b1 (CompleteSemilatticeSup.toHasSup.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeSup.{u1} \u03b1 _inst_1)) Nat (fun (j : Nat) => f i j)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] (f : Nat -> Nat -> \u03b1), Eq.{succ u1} \u03b1 (sup\u1d62.{u1, 1} \u03b1 (CompleteLattice.toSupSet.{u1} \u03b1 _inst_1) Nat (fun (n : Nat) => f (Prod.fst.{0, 0} Nat Nat (Nat.unpair n)) (Prod.snd.{0, 0} Nat Nat (Nat.unpair n)))) (sup\u1d62.{u1, 1} \u03b1 (CompleteLattice.toSupSet.{u1} \u03b1 _inst_1) Nat (fun (i : Nat) => sup\u1d62.{u1, 1} \u03b1 (CompleteLattice.toSupSet.{u1} \u03b1 _inst_1) Nat (fun (j : Nat) => f i j)))\nCase conversion may be inaccurate. Consider using '#align supr_unpair sup\u1d62_unpair\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\ntheorem sup\u1d62_unpair {\u03b1} [CompleteLattice \u03b1] (f : \u2115 \u2192 \u2115 \u2192 \u03b1) :\n    (\u2a06 n : \u2115, f n.unpair.1 n.unpair.2) = \u2a06 (i : \u2115) (j : \u2115), f i j := by\n  rw [\u2190 (sup\u1d62_prod : (\u2a06 i : \u2115 \u00d7 \u2115, f i.1 i.2) = _), \u2190 nat.surjective_unpair.supr_comp]\n#align supr_unpair sup\u1d62_unpair\n\n/- warning: infi_unpair -> inf\u1d62_unpair is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] (f : Nat -> Nat -> \u03b1), Eq.{succ u1} \u03b1 (inf\u1d62.{u1, 1} \u03b1 (CompleteSemilatticeInf.toHasInf.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)) Nat (fun (n : Nat) => f (Prod.fst.{0, 0} Nat Nat (Nat.unpair n)) (Prod.snd.{0, 0} Nat Nat (Nat.unpair n)))) (inf\u1d62.{u1, 1} \u03b1 (CompleteSemilatticeInf.toHasInf.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)) Nat (fun (i : Nat) => inf\u1d62.{u1, 1} \u03b1 (CompleteSemilatticeInf.toHasInf.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)) Nat (fun (j : Nat) => f i j)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] (f : Nat -> Nat -> \u03b1), Eq.{succ u1} \u03b1 (inf\u1d62.{u1, 1} \u03b1 (CompleteLattice.toInfSet.{u1} \u03b1 _inst_1) Nat (fun (n : Nat) => f (Prod.fst.{0, 0} Nat Nat (Nat.unpair n)) (Prod.snd.{0, 0} Nat Nat (Nat.unpair n)))) (inf\u1d62.{u1, 1} \u03b1 (CompleteLattice.toInfSet.{u1} \u03b1 _inst_1) Nat (fun (i : Nat) => inf\u1d62.{u1, 1} \u03b1 (CompleteLattice.toInfSet.{u1} \u03b1 _inst_1) Nat (fun (j : Nat) => f i j)))\nCase conversion may be inaccurate. Consider using '#align infi_unpair inf\u1d62_unpair\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\ntheorem inf\u1d62_unpair {\u03b1} [CompleteLattice \u03b1] (f : \u2115 \u2192 \u2115 \u2192 \u03b1) :\n    (\u2a05 n : \u2115, f n.unpair.1 n.unpair.2) = \u2a05 (i : \u2115) (j : \u2115), f i j :=\n  sup\u1d62_unpair (show \u2115 \u2192 \u2115 \u2192 \u03b1\u1d52\u1d48 from f)\n#align infi_unpair inf\u1d62_unpair\n\nend CompleteLattice\n\nnamespace Set\n\n/- warning: set.Union_unpair_prod -> Set.union\u1d62_unpair_prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {s : Nat -> (Set.{u1} \u03b1)} {t : Nat -> (Set.{u2} \u03b2)}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2)) (Set.union\u1d62.{max u1 u2, 1} (Prod.{u1, u2} \u03b1 \u03b2) Nat (fun (n : Nat) => Set.prod.{u1, u2} \u03b1 \u03b2 (s (Prod.fst.{0, 0} Nat Nat (Nat.unpair n))) (t (Prod.snd.{0, 0} Nat Nat (Nat.unpair n))))) (Set.prod.{u1, u2} \u03b1 \u03b2 (Set.union\u1d62.{u1, 1} \u03b1 Nat (fun (n : Nat) => s n)) (Set.union\u1d62.{u2, 1} \u03b2 Nat (fun (n : Nat) => t n)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} {s : Nat -> (Set.{u2} \u03b1)} {t : Nat -> (Set.{u1} \u03b2)}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Prod.{u2, u1} \u03b1 \u03b2)) (Set.union\u1d62.{max u1 u2, 1} (Prod.{u2, u1} \u03b1 \u03b2) Nat (fun (n : Nat) => Set.prod.{u2, u1} \u03b1 \u03b2 (s (Prod.fst.{0, 0} Nat Nat (Nat.unpair n))) (t (Prod.snd.{0, 0} Nat Nat (Nat.unpair n))))) (Set.prod.{u2, u1} \u03b1 \u03b2 (Set.union\u1d62.{u2, 1} \u03b1 Nat (fun (n : Nat) => s n)) (Set.union\u1d62.{u1, 1} \u03b2 Nat (fun (n : Nat) => t n)))\nCase conversion may be inaccurate. Consider using '#align set.Union_unpair_prod Set.union\u1d62_unpair_prod\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem union\u1d62_unpair_prod {\u03b1 \u03b2} {s : \u2115 \u2192 Set \u03b1} {t : \u2115 \u2192 Set \u03b2} :\n    (\u22c3 n : \u2115, s n.unpair.fst \u00d7\u02e2 t n.unpair.snd) = (\u22c3 n, s n) \u00d7\u02e2 \u22c3 n, t n :=\n  by\n  rw [\u2190 Union_prod]\n  convert surjective_unpair.Union_comp _\n  rfl\n#align set.Union_unpair_prod Set.union\u1d62_unpair_prod\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\n#print Set.union\u1d62_unpair /-\ntheorem union\u1d62_unpair {\u03b1} (f : \u2115 \u2192 \u2115 \u2192 Set \u03b1) :\n    (\u22c3 n : \u2115, f n.unpair.1 n.unpair.2) = \u22c3 (i : \u2115) (j : \u2115), f i j :=\n  sup\u1d62_unpair f\n#align set.Union_unpair Set.union\u1d62_unpair\n-/\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\n#print Set.inter\u1d62_unpair /-\ntheorem inter\u1d62_unpair {\u03b1} (f : \u2115 \u2192 \u2115 \u2192 Set \u03b1) :\n    (\u22c2 n : \u2115, f n.unpair.1 n.unpair.2) = \u22c2 (i : \u2115) (j : \u2115), f i j :=\n  inf\u1d62_unpair f\n#align set.Inter_unpair Set.inter\u1d62_unpair\n-/\n\nend Set\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Pairing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.716528514873393}}
{"text": "/-\nCopyright (c) 2022 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module probability.moments\n! leanprover-community/mathlib commit 85453a2a14be8da64caf15ca50930cf4c6e5d8de\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Probability.Variance\n\n/-!\n# Moments and moment generating function\n\n## Main definitions\n\n* `probability_theory.moment X p \u03bc`: `p`th moment of a real random variable `X` with respect to\n  measure `\u03bc`, `\u03bc[X^p]`\n* `probability_theory.central_moment X p \u03bc`:`p`th central moment of `X` with respect to measure `\u03bc`,\n  `\u03bc[(X - \u03bc[X])^p]`\n* `probability_theory.mgf X \u03bc t`: moment generating function of `X` with respect to measure `\u03bc`,\n  `\u03bc[exp(t*X)]`\n* `probability_theory.cgf X \u03bc t`: cumulant generating function, logarithm of the moment generating\n  function\n\n## Main results\n\n* `probability_theory.indep_fun.mgf_add`: if two real random variables `X` and `Y` are independent\n  and their mgf are defined at `t`, then `mgf (X + Y) \u03bc t = mgf X \u03bc t * mgf Y \u03bc t`\n* `probability_theory.indep_fun.cgf_add`: if two real random variables `X` and `Y` are independent\n  and their mgf are defined at `t`, then `cgf (X + Y) \u03bc t = cgf X \u03bc t + cgf Y \u03bc t`\n* `probability_theory.measure_ge_le_exp_cgf` and `probability_theory.measure_le_le_exp_cgf`:\n  Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that\n  the cgf exists, `\u2119(\u03b5 \u2264 X) \u2264 exp(- t*\u03b5 + cgf X \u2119 t)`. See also\n  `probability_theory.measure_ge_le_exp_mul_mgf` and\n  `probability_theory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead\n  of `cgf`.\n\n-/\n\n\nopen MeasureTheory Filter Finset Real\n\nnoncomputable section\n\nopen BigOperators MeasureTheory ProbabilityTheory ENNReal NNReal\n\nnamespace ProbabilityTheory\n\nvariable {\u03a9 \u03b9 : Type _} {m : MeasurableSpace \u03a9} {X : \u03a9 \u2192 \u211d} {p : \u2115} {\u03bc : Measure \u03a9}\n\ninclude m\n\n/-- Moment of a real random variable, `\u03bc[X ^ p]`. -/\ndef moment (X : \u03a9 \u2192 \u211d) (p : \u2115) (\u03bc : Measure \u03a9) : \u211d :=\n  \u03bc[X ^ p]\n#align probability_theory.moment ProbabilityTheory.moment\n\n/-- Central moment of a real random variable, `\u03bc[(X - \u03bc[X]) ^ p]`. -/\ndef centralMoment (X : \u03a9 \u2192 \u211d) (p : \u2115) (\u03bc : Measure \u03a9) : \u211d :=\n  \u03bc[(X - fun x => \u03bc[X]) ^ p]\n#align probability_theory.central_moment ProbabilityTheory.centralMoment\n\n@[simp]\ntheorem moment_zero (hp : p \u2260 0) : moment 0 p \u03bc = 0 := by\n  simp only [moment, hp, zero_pow', Ne.def, not_false_iff, Pi.zero_apply, integral_const,\n    Algebra.id.smul_eq_mul, MulZeroClass.mul_zero]\n#align probability_theory.moment_zero ProbabilityTheory.moment_zero\n\n@[simp]\ntheorem centralMoment_zero (hp : p \u2260 0) : centralMoment 0 p \u03bc = 0 := by\n  simp only [central_moment, hp, Pi.zero_apply, integral_const, Algebra.id.smul_eq_mul,\n    MulZeroClass.mul_zero, zero_sub, Pi.pow_apply, Pi.neg_apply, neg_zero, zero_pow', Ne.def,\n    not_false_iff]\n#align probability_theory.central_moment_zero ProbabilityTheory.centralMoment_zero\n\ntheorem centralMoment_one' [IsFiniteMeasure \u03bc] (h_int : Integrable X \u03bc) :\n    centralMoment X 1 \u03bc = (1 - (\u03bc Set.univ).toReal) * \u03bc[X] :=\n  by\n  simp only [central_moment, Pi.sub_apply, pow_one]\n  rw [integral_sub h_int (integrable_const _)]\n  simp only [sub_mul, integral_const, Algebra.id.smul_eq_mul, one_mul]\n#align probability_theory.central_moment_one' ProbabilityTheory.centralMoment_one'\n\n@[simp]\ntheorem centralMoment_one [IsProbabilityMeasure \u03bc] : centralMoment X 1 \u03bc = 0 :=\n  by\n  by_cases h_int : integrable X \u03bc\n  \u00b7 rw [central_moment_one' h_int]\n    simp only [measure_univ, ENNReal.one_toReal, sub_self, MulZeroClass.zero_mul]\n  \u00b7 simp only [central_moment, Pi.sub_apply, pow_one]\n    have : \u00acintegrable (fun x => X x - integral \u03bc X) \u03bc :=\n      by\n      refine' fun h_sub => h_int _\n      have h_add : X = (fun x => X x - integral \u03bc X) + fun x => integral \u03bc X :=\n        by\n        ext1 x\n        simp\n      rw [h_add]\n      exact h_sub.add (integrable_const _)\n    rw [integral_undef this]\n#align probability_theory.central_moment_one ProbabilityTheory.centralMoment_one\n\ntheorem centralMoment_two_eq_variance [IsFiniteMeasure \u03bc] (hX : Mem\u2112p X 2 \u03bc) :\n    centralMoment X 2 \u03bc = variance X \u03bc :=\n  by\n  rw [hX.variance_eq]\n  rfl\n#align probability_theory.central_moment_two_eq_variance ProbabilityTheory.centralMoment_two_eq_variance\n\nsection MomentGeneratingFunction\n\nvariable {t : \u211d}\n\n/-- Moment generating function of a real random variable `X`: `\u03bb t, \u03bc[exp(t*X)]`. -/\ndef mgf (X : \u03a9 \u2192 \u211d) (\u03bc : Measure \u03a9) (t : \u211d) : \u211d :=\n  \u03bc[fun \u03c9 => exp (t * X \u03c9)]\n#align probability_theory.mgf ProbabilityTheory.mgf\n\n/-- Cumulant generating function of a real random variable `X`: `\u03bb t, log \u03bc[exp(t*X)]`. -/\ndef cgf (X : \u03a9 \u2192 \u211d) (\u03bc : Measure \u03a9) (t : \u211d) : \u211d :=\n  log (mgf X \u03bc t)\n#align probability_theory.cgf ProbabilityTheory.cgf\n\n@[simp]\ntheorem mgf_zero_fun : mgf 0 \u03bc t = (\u03bc Set.univ).toReal := by\n  simp only [mgf, Pi.zero_apply, MulZeroClass.mul_zero, exp_zero, integral_const,\n    Algebra.id.smul_eq_mul, mul_one]\n#align probability_theory.mgf_zero_fun ProbabilityTheory.mgf_zero_fun\n\n@[simp]\ntheorem cgf_zero_fun : cgf 0 \u03bc t = log (\u03bc Set.univ).toReal := by simp only [cgf, mgf_zero_fun]\n#align probability_theory.cgf_zero_fun ProbabilityTheory.cgf_zero_fun\n\n@[simp]\ntheorem mgf_zero_measure : mgf X (0 : Measure \u03a9) t = 0 := by simp only [mgf, integral_zero_measure]\n#align probability_theory.mgf_zero_measure ProbabilityTheory.mgf_zero_measure\n\n@[simp]\ntheorem cgf_zero_measure : cgf X (0 : Measure \u03a9) t = 0 := by\n  simp only [cgf, log_zero, mgf_zero_measure]\n#align probability_theory.cgf_zero_measure ProbabilityTheory.cgf_zero_measure\n\n@[simp]\ntheorem mgf_const' (c : \u211d) : mgf (fun _ => c) \u03bc t = (\u03bc Set.univ).toReal * exp (t * c) := by\n  simp only [mgf, integral_const, Algebra.id.smul_eq_mul]\n#align probability_theory.mgf_const' ProbabilityTheory.mgf_const'\n\n@[simp]\ntheorem mgf_const (c : \u211d) [IsProbabilityMeasure \u03bc] : mgf (fun _ => c) \u03bc t = exp (t * c) := by\n  simp only [mgf_const', measure_univ, ENNReal.one_toReal, one_mul]\n#align probability_theory.mgf_const ProbabilityTheory.mgf_const\n\n@[simp]\ntheorem cgf_const' [IsFiniteMeasure \u03bc] (h\u03bc : \u03bc \u2260 0) (c : \u211d) :\n    cgf (fun _ => c) \u03bc t = log (\u03bc Set.univ).toReal + t * c :=\n  by\n  simp only [cgf, mgf_const']\n  rw [log_mul _ (exp_pos _).ne']\n  \u00b7 rw [log_exp _]\n  \u00b7 rw [Ne.def, ENNReal.toReal_eq_zero_iff, measure.measure_univ_eq_zero]\n    simp only [h\u03bc, measure_ne_top \u03bc Set.univ, or_self_iff, not_false_iff]\n#align probability_theory.cgf_const' ProbabilityTheory.cgf_const'\n\n@[simp]\ntheorem cgf_const [IsProbabilityMeasure \u03bc] (c : \u211d) : cgf (fun _ => c) \u03bc t = t * c := by\n  simp only [cgf, mgf_const, log_exp]\n#align probability_theory.cgf_const ProbabilityTheory.cgf_const\n\n@[simp]\ntheorem mgf_zero' : mgf X \u03bc 0 = (\u03bc Set.univ).toReal := by\n  simp only [mgf, MulZeroClass.zero_mul, exp_zero, integral_const, Algebra.id.smul_eq_mul, mul_one]\n#align probability_theory.mgf_zero' ProbabilityTheory.mgf_zero'\n\n@[simp]\ntheorem mgf_zero [IsProbabilityMeasure \u03bc] : mgf X \u03bc 0 = 1 := by\n  simp only [mgf_zero', measure_univ, ENNReal.one_toReal]\n#align probability_theory.mgf_zero ProbabilityTheory.mgf_zero\n\n@[simp]\ntheorem cgf_zero' : cgf X \u03bc 0 = log (\u03bc Set.univ).toReal := by simp only [cgf, mgf_zero']\n#align probability_theory.cgf_zero' ProbabilityTheory.cgf_zero'\n\n@[simp]\ntheorem cgf_zero [IsProbabilityMeasure \u03bc] : cgf X \u03bc 0 = 0 := by\n  simp only [cgf_zero', measure_univ, ENNReal.one_toReal, log_one]\n#align probability_theory.cgf_zero ProbabilityTheory.cgf_zero\n\ntheorem mgf_undef (hX : \u00acIntegrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) : mgf X \u03bc t = 0 := by\n  simp only [mgf, integral_undef hX]\n#align probability_theory.mgf_undef ProbabilityTheory.mgf_undef\n\ntheorem cgf_undef (hX : \u00acIntegrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) : cgf X \u03bc t = 0 := by\n  simp only [cgf, mgf_undef hX, log_zero]\n#align probability_theory.cgf_undef ProbabilityTheory.cgf_undef\n\ntheorem mgf_nonneg : 0 \u2264 mgf X \u03bc t :=\n  by\n  refine' integral_nonneg _\n  intro \u03c9\n  simp only [Pi.zero_apply]\n  exact (exp_pos _).le\n#align probability_theory.mgf_nonneg ProbabilityTheory.mgf_nonneg\n\ntheorem mgf_pos' (h\u03bc : \u03bc \u2260 0) (h_int_X : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) : 0 < mgf X \u03bc t :=\n  by\n  simp_rw [mgf]\n  have : (\u222b x : \u03a9, exp (t * X x) \u2202\u03bc) = \u222b x : \u03a9 in Set.univ, exp (t * X x) \u2202\u03bc := by\n    simp only [measure.restrict_univ]\n  rw [this, set_integral_pos_iff_support_of_nonneg_ae _ _]\n  \u00b7 have h_eq_univ : (Function.support fun x : \u03a9 => exp (t * X x)) = Set.univ :=\n      by\n      ext1 x\n      simp only [Function.mem_support, Set.mem_univ, iff_true_iff]\n      exact (exp_pos _).ne'\n    rw [h_eq_univ, Set.inter_univ _]\n    refine' Ne.bot_lt _\n    simp only [h\u03bc, ENNReal.bot_eq_zero, Ne.def, measure.measure_univ_eq_zero, not_false_iff]\n  \u00b7 refine' eventually_of_forall fun x => _\n    rw [Pi.zero_apply]\n    exact (exp_pos _).le\n  \u00b7 rwa [integrable_on_univ]\n#align probability_theory.mgf_pos' ProbabilityTheory.mgf_pos'\n\ntheorem mgf_pos [IsProbabilityMeasure \u03bc] (h_int_X : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) :\n    0 < mgf X \u03bc t :=\n  mgf_pos' (IsProbabilityMeasure.ne_zero \u03bc) h_int_X\n#align probability_theory.mgf_pos ProbabilityTheory.mgf_pos\n\ntheorem mgf_neg : mgf (-X) \u03bc t = mgf X \u03bc (-t) := by simp_rw [mgf, Pi.neg_apply, mul_neg, neg_mul]\n#align probability_theory.mgf_neg ProbabilityTheory.mgf_neg\n\ntheorem cgf_neg : cgf (-X) \u03bc t = cgf X \u03bc (-t) := by simp_rw [cgf, mgf_neg]\n#align probability_theory.cgf_neg ProbabilityTheory.cgf_neg\n\n/-- This is a trivial application of `indep_fun.comp` but it will come up frequently. -/\ntheorem IndepFunCat.expMul {X Y : \u03a9 \u2192 \u211d} (h_indep : IndepFunCat X Y \u03bc) (s t : \u211d) :\n    IndepFunCat (fun \u03c9 => exp (s * X \u03c9)) (fun \u03c9 => exp (t * Y \u03c9)) \u03bc :=\n  by\n  have h_meas : \u2200 t, Measurable fun x => exp (t * x) := fun t => (measurable_id'.const_mul t).exp\n  change indep_fun ((fun x => exp (s * x)) \u2218 X) ((fun x => exp (t * x)) \u2218 Y) \u03bc\n  exact indep_fun.comp h_indep (h_meas s) (h_meas t)\n#align probability_theory.indep_fun.exp_mul ProbabilityTheory.IndepFunCat.expMul\n\ntheorem IndepFunCat.mgf_add {X Y : \u03a9 \u2192 \u211d} (h_indep : IndepFunCat X Y \u03bc)\n    (hX : AeStronglyMeasurable (fun \u03c9 => exp (t * X \u03c9)) \u03bc)\n    (hY : AeStronglyMeasurable (fun \u03c9 => exp (t * Y \u03c9)) \u03bc) :\n    mgf (X + Y) \u03bc t = mgf X \u03bc t * mgf Y \u03bc t :=\n  by\n  simp_rw [mgf, Pi.add_apply, mul_add, exp_add]\n  exact (h_indep.exp_mul t t).integral_mul hX hY\n#align probability_theory.indep_fun.mgf_add ProbabilityTheory.IndepFunCat.mgf_add\n\ntheorem IndepFunCat.mgf_add' {X Y : \u03a9 \u2192 \u211d} (h_indep : IndepFunCat X Y \u03bc)\n    (hX : AeStronglyMeasurable X \u03bc) (hY : AeStronglyMeasurable Y \u03bc) :\n    mgf (X + Y) \u03bc t = mgf X \u03bc t * mgf Y \u03bc t :=\n  by\n  have A : Continuous fun x : \u211d => exp (t * x) := by continuity\n  have h'X : ae_strongly_measurable (fun \u03c9 => exp (t * X \u03c9)) \u03bc :=\n    A.ae_strongly_measurable.comp_ae_measurable hX.ae_measurable\n  have h'Y : ae_strongly_measurable (fun \u03c9 => exp (t * Y \u03c9)) \u03bc :=\n    A.ae_strongly_measurable.comp_ae_measurable hY.ae_measurable\n  exact h_indep.mgf_add h'X h'Y\n#align probability_theory.indep_fun.mgf_add' ProbabilityTheory.IndepFunCat.mgf_add'\n\ntheorem IndepFunCat.cgf_add {X Y : \u03a9 \u2192 \u211d} (h_indep : IndepFunCat X Y \u03bc)\n    (h_int_X : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc)\n    (h_int_Y : Integrable (fun \u03c9 => exp (t * Y \u03c9)) \u03bc) : cgf (X + Y) \u03bc t = cgf X \u03bc t + cgf Y \u03bc t :=\n  by\n  by_cases h\u03bc : \u03bc = 0\n  \u00b7 simp [h\u03bc]\n  simp only [cgf, h_indep.mgf_add h_int_X.ae_strongly_measurable h_int_Y.ae_strongly_measurable]\n  exact log_mul (mgf_pos' h\u03bc h_int_X).ne' (mgf_pos' h\u03bc h_int_Y).ne'\n#align probability_theory.indep_fun.cgf_add ProbabilityTheory.IndepFunCat.cgf_add\n\ntheorem aeStronglyMeasurableExpMulAdd {X Y : \u03a9 \u2192 \u211d}\n    (h_int_X : AeStronglyMeasurable (fun \u03c9 => exp (t * X \u03c9)) \u03bc)\n    (h_int_Y : AeStronglyMeasurable (fun \u03c9 => exp (t * Y \u03c9)) \u03bc) :\n    AeStronglyMeasurable (fun \u03c9 => exp (t * (X + Y) \u03c9)) \u03bc :=\n  by\n  simp_rw [Pi.add_apply, mul_add, exp_add]\n  exact ae_strongly_measurable.mul h_int_X h_int_Y\n#align probability_theory.ae_strongly_measurable_exp_mul_add ProbabilityTheory.aeStronglyMeasurableExpMulAdd\n\ntheorem aeStronglyMeasurableExpMulSum {X : \u03b9 \u2192 \u03a9 \u2192 \u211d} {s : Finset \u03b9}\n    (h_int : \u2200 i \u2208 s, AeStronglyMeasurable (fun \u03c9 => exp (t * X i \u03c9)) \u03bc) :\n    AeStronglyMeasurable (fun \u03c9 => exp (t * (\u2211 i in s, X i) \u03c9)) \u03bc := by\n  classical\n    induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int\n    \u00b7 simp only [Pi.zero_apply, sum_apply, sum_empty, MulZeroClass.mul_zero, exp_zero]\n      exact ae_strongly_measurable_const\n    \u00b7 have : \u2200 i : \u03b9, i \u2208 s \u2192 ae_strongly_measurable (fun \u03c9 : \u03a9 => exp (t * X i \u03c9)) \u03bc := fun i hi =>\n        h_int i (mem_insert_of_mem hi)\n      specialize h_rec this\n      rw [sum_insert hi_notin_s]\n      apply ae_strongly_measurable_exp_mul_add (h_int i (mem_insert_self _ _)) h_rec\n#align probability_theory.ae_strongly_measurable_exp_mul_sum ProbabilityTheory.aeStronglyMeasurableExpMulSum\n\ntheorem IndepFunCat.integrableExpMulAdd {X Y : \u03a9 \u2192 \u211d} (h_indep : IndepFunCat X Y \u03bc)\n    (h_int_X : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc)\n    (h_int_Y : Integrable (fun \u03c9 => exp (t * Y \u03c9)) \u03bc) :\n    Integrable (fun \u03c9 => exp (t * (X + Y) \u03c9)) \u03bc :=\n  by\n  simp_rw [Pi.add_apply, mul_add, exp_add]\n  exact (h_indep.exp_mul t t).integrableMul h_int_X h_int_Y\n#align probability_theory.indep_fun.integrable_exp_mul_add ProbabilityTheory.IndepFunCat.integrableExpMulAdd\n\ntheorem IndepFun.integrableExpMulSum [IsProbabilityMeasure \u03bc] {X : \u03b9 \u2192 \u03a9 \u2192 \u211d}\n    (h_indep : IndepFun (fun i => inferInstance) X \u03bc) (h_meas : \u2200 i, Measurable (X i))\n    {s : Finset \u03b9} (h_int : \u2200 i \u2208 s, Integrable (fun \u03c9 => exp (t * X i \u03c9)) \u03bc) :\n    Integrable (fun \u03c9 => exp (t * (\u2211 i in s, X i) \u03c9)) \u03bc := by\n  classical\n    induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int\n    \u00b7 simp only [Pi.zero_apply, sum_apply, sum_empty, MulZeroClass.mul_zero, exp_zero]\n      exact integrable_const _\n    \u00b7 have : \u2200 i : \u03b9, i \u2208 s \u2192 integrable (fun \u03c9 : \u03a9 => exp (t * X i \u03c9)) \u03bc := fun i hi =>\n        h_int i (mem_insert_of_mem hi)\n      specialize h_rec this\n      rw [sum_insert hi_notin_s]\n      refine' indep_fun.integrable_exp_mul_add _ (h_int i (mem_insert_self _ _)) h_rec\n      exact (h_indep.indep_fun_finset_sum_of_not_mem h_meas hi_notin_s).symm\n#align probability_theory.Indep_fun.integrable_exp_mul_sum ProbabilityTheory.IndepFun.integrableExpMulSum\n\ntheorem IndepFun.mgf_sum [IsProbabilityMeasure \u03bc] {X : \u03b9 \u2192 \u03a9 \u2192 \u211d}\n    (h_indep : IndepFun (fun i => inferInstance) X \u03bc) (h_meas : \u2200 i, Measurable (X i))\n    (s : Finset \u03b9) : mgf (\u2211 i in s, X i) \u03bc t = \u220f i in s, mgf (X i) \u03bc t := by\n  classical\n    induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int\n    \u00b7 simp only [sum_empty, mgf_zero_fun, measure_univ, ENNReal.one_toReal, prod_empty]\n    \u00b7 have h_int' : \u2200 i : \u03b9, ae_strongly_measurable (fun \u03c9 : \u03a9 => exp (t * X i \u03c9)) \u03bc := fun i =>\n        ((h_meas i).const_mul t).exp.AeStronglyMeasurable\n      rw [sum_insert hi_notin_s,\n        indep_fun.mgf_add (h_indep.indep_fun_finset_sum_of_not_mem h_meas hi_notin_s).symm\n          (h_int' i) (ae_strongly_measurable_exp_mul_sum fun i hi => h_int' i),\n        h_rec, prod_insert hi_notin_s]\n#align probability_theory.Indep_fun.mgf_sum ProbabilityTheory.IndepFun.mgf_sum\n\ntheorem IndepFun.cgf_sum [IsProbabilityMeasure \u03bc] {X : \u03b9 \u2192 \u03a9 \u2192 \u211d}\n    (h_indep : IndepFun (fun i => inferInstance) X \u03bc) (h_meas : \u2200 i, Measurable (X i))\n    {s : Finset \u03b9} (h_int : \u2200 i \u2208 s, Integrable (fun \u03c9 => exp (t * X i \u03c9)) \u03bc) :\n    cgf (\u2211 i in s, X i) \u03bc t = \u2211 i in s, cgf (X i) \u03bc t :=\n  by\n  simp_rw [cgf]\n  rw [\u2190 log_prod _ _ fun j hj => _]\n  \u00b7 rw [h_indep.mgf_sum h_meas]\n  \u00b7 exact (mgf_pos (h_int j hj)).ne'\n#align probability_theory.Indep_fun.cgf_sum ProbabilityTheory.IndepFun.cgf_sum\n\n/-- **Chernoff bound** on the upper tail of a real random variable. -/\ntheorem measure_ge_le_exp_mul_mgf [IsFiniteMeasure \u03bc] (\u03b5 : \u211d) (ht : 0 \u2264 t)\n    (h_int : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) :\n    (\u03bc { \u03c9 | \u03b5 \u2264 X \u03c9 }).toReal \u2264 exp (-t * \u03b5) * mgf X \u03bc t :=\n  by\n  cases' ht.eq_or_lt with ht_zero_eq ht_pos\n  \u00b7 rw [ht_zero_eq.symm]\n    simp only [neg_zero, MulZeroClass.zero_mul, exp_zero, mgf_zero', one_mul]\n    rw [ENNReal.toReal_le_toReal (measure_ne_top \u03bc _) (measure_ne_top \u03bc _)]\n    exact measure_mono (Set.subset_univ _)\n  calc\n    (\u03bc { \u03c9 | \u03b5 \u2264 X \u03c9 }).toReal = (\u03bc { \u03c9 | exp (t * \u03b5) \u2264 exp (t * X \u03c9) }).toReal :=\n      by\n      congr with \u03c9\n      simp only [exp_le_exp, eq_iff_iff]\n      exact\n        \u27e8fun h => mul_le_mul_of_nonneg_left h ht_pos.le, fun h => le_of_mul_le_mul_left h ht_pos\u27e9\n    _ \u2264 (exp (t * \u03b5))\u207b\u00b9 * \u03bc[fun \u03c9 => exp (t * X \u03c9)] :=\n      by\n      have :\n        exp (t * \u03b5) * (\u03bc { \u03c9 | exp (t * \u03b5) \u2264 exp (t * X \u03c9) }).toReal \u2264 \u03bc[fun \u03c9 => exp (t * X \u03c9)] :=\n        mul_meas_ge_le_integral_of_nonneg (fun x => (exp_pos _).le) h_int _\n      rwa [mul_comm (exp (t * \u03b5))\u207b\u00b9, \u2190 div_eq_mul_inv, le_div_iff' (exp_pos _)]\n    _ = exp (-t * \u03b5) * mgf X \u03bc t := by\n      rw [neg_mul, exp_neg]\n      rfl\n    \n#align probability_theory.measure_ge_le_exp_mul_mgf ProbabilityTheory.measure_ge_le_exp_mul_mgf\n\n/-- **Chernoff bound** on the lower tail of a real random variable. -/\ntheorem measure_le_le_exp_mul_mgf [IsFiniteMeasure \u03bc] (\u03b5 : \u211d) (ht : t \u2264 0)\n    (h_int : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) :\n    (\u03bc { \u03c9 | X \u03c9 \u2264 \u03b5 }).toReal \u2264 exp (-t * \u03b5) * mgf X \u03bc t :=\n  by\n  rw [\u2190 neg_neg t, \u2190 mgf_neg, neg_neg, \u2190 neg_mul_neg (-t)]\n  refine' Eq.trans_le _ (measure_ge_le_exp_mul_mgf (-\u03b5) (neg_nonneg.mpr ht) _)\n  \u00b7 congr with \u03c9\n    simp only [Pi.neg_apply, neg_le_neg_iff]\n  \u00b7 simp_rw [Pi.neg_apply, neg_mul_neg]\n    exact h_int\n#align probability_theory.measure_le_le_exp_mul_mgf ProbabilityTheory.measure_le_le_exp_mul_mgf\n\n/-- **Chernoff bound** on the upper tail of a real random variable. -/\ntheorem measure_ge_le_exp_cgf [IsFiniteMeasure \u03bc] (\u03b5 : \u211d) (ht : 0 \u2264 t)\n    (h_int : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) :\n    (\u03bc { \u03c9 | \u03b5 \u2264 X \u03c9 }).toReal \u2264 exp (-t * \u03b5 + cgf X \u03bc t) :=\n  by\n  refine' (measure_ge_le_exp_mul_mgf \u03b5 ht h_int).trans _\n  rw [exp_add]\n  exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le\n#align probability_theory.measure_ge_le_exp_cgf ProbabilityTheory.measure_ge_le_exp_cgf\n\n/-- **Chernoff bound** on the lower tail of a real random variable. -/\ntheorem measure_le_le_exp_cgf [IsFiniteMeasure \u03bc] (\u03b5 : \u211d) (ht : t \u2264 0)\n    (h_int : Integrable (fun \u03c9 => exp (t * X \u03c9)) \u03bc) :\n    (\u03bc { \u03c9 | X \u03c9 \u2264 \u03b5 }).toReal \u2264 exp (-t * \u03b5 + cgf X \u03bc t) :=\n  by\n  refine' (measure_le_le_exp_mul_mgf \u03b5 ht h_int).trans _\n  rw [exp_add]\n  exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le\n#align probability_theory.measure_le_le_exp_cgf ProbabilityTheory.measure_le_le_exp_cgf\n\nend MomentGeneratingFunction\n\nend ProbabilityTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Probability/Moments.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7981867729389245, "lm_q1q2_score": 0.7165285061049919}}
{"text": "/-\nCopyright (c) 2022 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n-/\nimport analysis.inner_product_space.adjoint\n\n/-!\n# Positive operators\n\nIn this file we define positive operators in a Hilbert space. We follow Bourbaki's choice\nof requiring self adjointness in the definition.\n\n## Main definitions\n\n* `is_positive` : a continuous linear map is positive if it is self adjoint and\n  `\u2200 x, 0 \u2264 re \u27eaT x, x\u27eb`\n\n## Main statements\n\n* `continuous_linear_map.is_positive.conj_adjoint` : if `T : E \u2192L[\ud835\udd5c] E` is positive,\n  then for any `S : E \u2192L[\ud835\udd5c] F`, `S \u2218L T \u2218L S\u2020` is also positive.\n* `continuous_linear_map.is_positive_iff_complex` : in a ***complex*** hilbert space,\n  checking that `\u27eaT x, x\u27eb` is a nonnegative real number for all `x` suffices to prove that\n  `T` is positive\n\n## References\n\n* [Bourbaki, *Topological Vector Spaces*][bourbaki1987]\n\n## Tags\n\nPositive operator\n-/\n\nopen inner_product_space is_R_or_C continuous_linear_map\nopen_locale inner_product complex_conjugate\n\nnamespace continuous_linear_map\n\nvariables {\ud835\udd5c E F : Type*} [is_R_or_C \ud835\udd5c]\nvariables [normed_add_comm_group E] [normed_add_comm_group F]\nvariables [inner_product_space \ud835\udd5c E] [inner_product_space \ud835\udd5c F]\nvariables [complete_space E] [complete_space F]\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\n\n/-- A continuous linear endomorphism `T` of a Hilbert space is **positive** if it is self adjoint\n  and `\u2200 x, 0 \u2264 re \u27eaT x, x\u27eb`. -/\ndef is_positive (T : E \u2192L[\ud835\udd5c] E) : Prop :=\n  is_self_adjoint T \u2227 \u2200 x, 0 \u2264 T.re_apply_inner_self x\n\nlemma is_positive.is_self_adjoint {T : E \u2192L[\ud835\udd5c] E} (hT : is_positive T) :\n  is_self_adjoint T :=\nhT.1\n\nlemma is_positive.inner_nonneg_left {T : E \u2192L[\ud835\udd5c] E} (hT : is_positive T) (x : E) :\n  0 \u2264 re \u27eaT x, x\u27eb :=\nhT.2 x\n\nlemma is_positive.inner_nonneg_right {T : E \u2192L[\ud835\udd5c] E} (hT : is_positive T) (x : E) :\n  0 \u2264 re \u27eax, T x\u27eb :=\nby rw inner_re_symm; exact hT.inner_nonneg_left x\n\nlemma is_positive_zero : is_positive (0 : E \u2192L[\ud835\udd5c] E) :=\nbegin\n  refine \u27e8is_self_adjoint_zero _, \u03bb x, _\u27e9,\n  change 0 \u2264 re \u27ea_, _\u27eb,\n  rw [zero_apply, inner_zero_left, zero_hom_class.map_zero]\nend\n\nlemma is_positive_one : is_positive (1 : E \u2192L[\ud835\udd5c] E) :=\n\u27e8is_self_adjoint_one _, \u03bb x, inner_self_nonneg\u27e9\n\nlemma is_positive.add {T S : E \u2192L[\ud835\udd5c] E} (hT : T.is_positive)\n  (hS : S.is_positive) : (T + S).is_positive :=\nbegin\n  refine \u27e8hT.is_self_adjoint.add hS.is_self_adjoint, \u03bb x, _\u27e9,\n  rw [re_apply_inner_self, add_apply, inner_add_left, map_add],\n  exact add_nonneg (hT.inner_nonneg_left x) (hS.inner_nonneg_left x)\nend\n\nlemma is_positive.conj_adjoint {T : E \u2192L[\ud835\udd5c] E}\n  (hT : T.is_positive) (S : E \u2192L[\ud835\udd5c] F) : (S \u2218L T \u2218L S\u2020).is_positive :=\nbegin\n  refine \u27e8hT.is_self_adjoint.conj_adjoint S, \u03bb x, _\u27e9,\n  rw [re_apply_inner_self, comp_apply, \u2190 adjoint_inner_right],\n  exact hT.inner_nonneg_left _\nend\n\nlemma is_positive.adjoint_conj {T : E \u2192L[\ud835\udd5c] E}\n  (hT : T.is_positive) (S : F \u2192L[\ud835\udd5c] E) : (S\u2020 \u2218L T \u2218L S).is_positive :=\nbegin\n  convert hT.conj_adjoint (S\u2020),\n  rw adjoint_adjoint\nend\n\nlemma is_positive.conj_orthogonal_projection (U : submodule \ud835\udd5c E) {T : E \u2192L[\ud835\udd5c] E}\n  (hT : T.is_positive) [complete_space U] :\n  (U.subtypeL \u2218L orthogonal_projection U \u2218L T \u2218L U.subtypeL \u2218L\n    orthogonal_projection U).is_positive :=\nbegin\n  have := hT.conj_adjoint (U.subtypeL \u2218L orthogonal_projection U),\n  rwa (orthogonal_projection_is_self_adjoint U).adjoint_eq at this\nend\n\nlemma is_positive.orthogonal_projection_comp {T : E \u2192L[\ud835\udd5c] E}\n  (hT : T.is_positive) (U : submodule \ud835\udd5c E) [complete_space U] :\n  (orthogonal_projection U \u2218L T \u2218L U.subtypeL).is_positive :=\nbegin\n  have := hT.conj_adjoint (orthogonal_projection U : E \u2192L[\ud835\udd5c] U),\n  rwa [U.adjoint_orthogonal_projection] at this,\nend\n\nsection complex\n\nvariables {E' : Type*} [normed_add_comm_group E'] [inner_product_space \u2102 E'] [complete_space E']\n\nlemma is_positive_iff_complex (T : E' \u2192L[\u2102] E') :\n  is_positive T \u2194 \u2200 x, (re \u27eaT x, x\u27eb_\u2102 : \u2102) = \u27eaT x, x\u27eb_\u2102 \u2227 0 \u2264 re \u27eaT x, x\u27eb_\u2102 :=\nbegin\n  simp_rw [is_positive, forall_and_distrib, is_self_adjoint_iff_is_symmetric,\n    linear_map.is_symmetric_iff_inner_map_self_real, eq_conj_iff_re],\n  refl\nend\n\nend complex\n\nend continuous_linear_map\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/inner_product_space/positive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7165285038904999}}
{"text": "section pred_logic\n\nvariables X Y Z : Prop\n\n/- *** FORALL and ARROW *** -/\n\n-- \u2192 and \u2200 \ndef arrow_all_equiv   := (\u2200 (x : X), Y) \u2194 (X \u2192 Y)\n\n/-\nTo prove either (\u2200 (x : X), Y) or (X \u2192 Y), you first assume  \nthat you're given an arbitrary but specific proof of X, and\nin that context, you show that you can derive a proof (thus \ndeducing the truth) of Y. It's exactly the same reasoning in\neach case. This is the *introduction* rule for \u2200 and \u2192. \n-/\n\n/-\nIn fact, in constructive logic, X \u2192 Y is simply a notation\n*defined* as \u2200 (x : X), Y. What each of these propositions \nstates in constructive logic is that \"From *any* proof, x, \nof X, we can derive a proof of Y.\" In fact, in Lean, these\npropositions are not only equivalent but equal. \n-/\n\n#check X \u2192 Y          -- Lean confirms this is a proposition\n#check \u2200 (x : X), Y   -- Lean understands this to say X \u2192 Y!\n\n\n\n/- OPTIONAL\nAs an aside, here's a proof that these propositions are \nactually equal. This proof uses an inference rule, rfl, for \nequality that we've not yet studied. Don't worry about the \n\"rfl\" for now, but trust that we're giving a correct proof\nof the equality of these two propositions in Lean\n-/\ntheorem all_imp_equal : (\u2200 (x : X), Y) = (X \u2192 Y) := rfl \n\n/-\nThe reason it's super-helpful to know these propositions \nare equivalent is that it tells you that you can *use* a \nproof of a \u2200 proposition or of a \u2192 proposition in exactly\nthe same way. So let's turn to the *elimination* rules for\n\u2192 and \u2200. \n-/\n\ndef arrow_elim        := (X \u2192 Y)        \u2192 X   \u2192 Y\ndef all_elim          := (\u2200 (x : X), Y) \u2192 X   \u2192 Y\n\n/-\nThe idea underlying these rules date to ancient times. \nThey both say \"if from the truth or a proof of X you \ncan derive a proof or the truth of Y, and if you also \nhave a proof, or know the truth, of X, then you can (in\nconstructive logic) derive a proof of Y (or deduce the\ntruth of Y.\" \n\nHere's an example. What we want to say in logic is\nthat if every ball is blue and b is some specific \nball then b is blue. The elimination rule for \u2200 and\n\u2192 applies a generalization to a specific instance to\ndeduce that the generalized statement specialized to\na particular instance is true.\n\nNote: In this example, Y is a proposition obtained by \nplugging \"x\" into a one-argument predicate. So suppose \n(\u2200 (x : X), Y) is read as \"for any Ball x, x is blue.\"  \nHere X is \"Ball;\" x is an arbitrary but specific Ball; \nand Y is read as \"x is blue.\" \n  \nNow suppose that, in this context, you're given a \n*particular* ball, (b : X). What the overall rules\nsays is that you now conclude that \"b is blue.\"\n\nThe elimination rule works by *applying* a proof of\na universal generalization (showing that something\nis true of *every* object of a particular kind) to \na *specific* object of that kind, to deduce that the \ngeneralized statement is also true of that specific\nobject.\n\nIf every ball is blue, and if b is a ball, then b\nmust be blue. Another way to say it that makes a\nbit more sense for the (X \u2192 Y) notation is that \n\"if being any ball, x, implies that x is blue, and \nif b is some particular ball, then b is blue.\n-/\n\n/-\nAs an example, consider a predicate, (isBlue _), where you can fill\nin the blank/argument with any Ball-type object. If b is a specific\nBall-type object, then (isBlue b) is a proposition, representing the\nEnglish-language claim that b is blue. Here's how we represent this\npredicate in Lean.\n-/\n\nvariable Ball : Type            -- Ball is a type of object\nvariable isBlue : Ball \u2192 Prop\n/-\nFirst we Ball to be the name of a type of object (like int or \nbool). Then we define isBlue to be a construct (think function!)\nthat when given any object of type Ball as an argument yields a\nproposition. To see how this works, suppose we have some specific\nballs, b1 and b2.\n-/\nvariables (b1 b2 : Ball)\n/-\nNow let's use isBlue to make some propositions!\n-/\n#check isBlue                               -- a predicate\n#check isBlue b1                            -- a proposition about b1\n#check isBlue b2                            -- a proposition about b2\n#check (\u2200 (x : Ball), isBlue x)             -- generalization\nvariable all_balls_blue : (\u2200 (x : Ball), isBlue x)   -- proof of it\n#check all_balls_blue b1                    -- proof b1 is blue\n#check all_balls_blue b2                    -- proof b2 is blue\n\n/-\nHere's an English-language version.\n\nSuppose b1 and b2 are objects of some type, Ball, and that isBlue \nis one-place predicate taking any Ball, b, as an argument, and that\nreduces to a proposition, denoted (isBlue b), that we understand as\nasserting that the particular ball, b, is blue. Next (295), we take\nall_balls_blue as a proof that all balls are blue. Finally (296 and\n297), we see that we can can use this proof/truth by *applying* it\nto any particular ball, b, to obtain a proof/truth that b is blue. \n\nFor any type S, given any X: (\u2200 s : S), T and any s : S, the \u2200 \nand \u2192 elimination rule(s) say that you can derive a value/proof of \ntype T; moreover this operation is basically done by *applying* ,\nviewed as a function from parameter value to proposition, to the \nactual parameter, s (in Lean denoted as (X s)), to obtain a value\n(proof) of (type) T. Modus ponens is like function application. In\nconstructive logic, a proof of the \u2200 proposition *is* a function.\nHere you begin to see how profound is that proofs in constructive \nlogic tell you not only that a proposition is true but why. Here a\nproof of X \u2192 Y or of \u2200 (x : X), Y, is a program that when given any\nvalue/proof of X as an argument returns a value/proof of Y. If you \ncan produce a function that turns any proof of X into a proof of Y,\nthen you've shown that whenever X is true, so is Y; and that's just\nwhat X \u2192 Y is meant to say (similarly for \u2200 (x : X), Y). \n-/\n\n/-\nWalk-away message: Applying a proof/truth of a universal\ngeneralization to a specific object yields a proof of the\ngeneralization *specialized* to that particular object. That\nis in the higher-order predicate logic of Lean. \n-/\n\n/-\nFinally, let's compare our elimination rule, in the higher-order\npredicate logic of Lean, with its first-order logic counterpart.\n\nThere are two big differences, first, in first-order logic, you \nhave to present the rule outside of the logic: you can't write \nrules like this, \u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y), in first-order\nlogic because in first order logic you can't quantify over types,\npropositions, predicates, functions. Here we do just this with the\n\"\u2200 (X Y : Prop).\" By contrast, in the higher-order logic of Lean,\nwe can represent the rules of first-order logic with no problem: \ne.g., \"\u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y).\"\n\nSecond, as we've discussed, using Lean's higher-order logic, you\ncan think of a proof of \"\u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y)\" as a \nfunction. Each variable bound by a \u2200 and each implication premise\nis an argument, with the type of the return value at the end of \nthe line. So, here, a proof of this proposition can be taken as \na function that takes two propositions, X and Y as arguments, then\na proof (value) of (type) X, then a proof (value) of type Y, and\nthat finally returns a proof (value) X \u2227 Y. Whereas the proof of\n\u2200 (X Y : Prop), X \u2192 Y \u2192 (X \u2227 Y) is a function the returned proof\nof (X \u2227 Y) is a pair-like data structure. Proofs in constructive\nlogic are *computational*, and you can even compute with them, as\nyou do when you *apply* a proof of a certain kind to an argument\nto obtain a resulting proof/value.\n-/\n\n/-\nQuiz questions:\n\nFirst-order logic. I know that every natural number is\nbeautiful (\u2200 n, NaturalNumber(n) \u2192 Beautiful(n) : true), \nand I want to prove (7 is beautiful : true). Prove it.\nName the inference rule and identify the arguments you\ngive it to prove it.\n\nConstructive logic. Suppose I have a proof, pf, that every \nnatural number is beautiful (\u2200 (n : \u2115), beautiful n), and I \nneed a proof that 7 is beautiful. How can I get the proof \nI need? Answer in both English and with a Lean expression.\n\nFormalize this story: All people are mortal, and Plato \nis a person, therefore Plato is Mortal.\n-/\n\n/- Quick exercise. Give a proof of this (in English, and \ngive it a try in Lean as well.\n-/\n\ndef arrow_trans       := (X \u2192 Y) \u2192 (Y \u2192 Z) \u2192 (X \u2192 Z)\n\nend pred_logic\n", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/02_Predicate_Logic/01_Inference_Rules_and_Proofs/05_rules_for_all_and_arrow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.716528501705863}}
{"text": "import linear_algebra.matrix.spectrum\n\nnamespace linear_map\n\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] [decidable_eq \ud835\udd5c]\nvariables {E : Type*} [inner_product_space \ud835\udd5c E]\nvariables [finite_dimensional \ud835\udd5c E]\nvariables {n : \u2115} (hn : finite_dimensional.finrank \ud835\udd5c E = n)\nvariables {T : E \u2192\u2097[\ud835\udd5c] E}\n\n-- TODO: move analysis.inner_product_space.spectrum\n-- TODO: can be used to prove version 2.\n/-- *Diagonalization theorem*, *spectral theorem*; version 3: A self-adjoint operator `T` on a\nfinite-dimensional inner product space `E` acts diagonally on the identification of `E` with\nEuclidean space induced by an orthonormal basis of eigenvectors of `T`. -/\nlemma spectral_theorem' (v : E) (i : fin n)\n  (xs : orthonormal_basis (fin n) \ud835\udd5c E) (as : fin n \u2192 \u211d)\n  (hxs : \u2200 j, module.End.has_eigenvector T (as j) (xs j)) :\n  xs.repr (T v) i = as i * xs.repr v i :=\nbegin\n  suffices : \u2200 w : euclidean_space \ud835\udd5c (fin n),\n    T (xs.repr.symm w) = xs.repr.symm (\u03bb i, as i * w i),\n  { simpa only [linear_isometry_equiv.symm_apply_apply, linear_isometry_equiv.apply_symm_apply]\n      using congr_arg (\u03bb (v : E), (xs.repr) v i) (this ((xs.repr) v)) },\n  intros w,\n  simp_rw [\u2190 orthonormal_basis.sum_repr_symm, linear_map.map_sum,\n    linear_map.map_smul, \u03bb j, module.End.mem_eigenspace_iff.mp (hxs j).1, smul_smul, mul_comm]\nend\n\nend linear_map\n", "meta": {"author": "verified-optimization", "repo": "optlib", "sha": "b5d69678be5a4be8284ed15d376d6d973c64ea72", "save_path": "github-repos/lean/verified-optimization-optlib", "path": "github-repos/lean/verified-optimization-optlib/optlib-b5d69678be5a4be8284ed15d376d6d973c64ea72/src/missing/analysis/inner_product_space/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.716513829523848}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n\n! This file was ported from Lean 3 source module topology.instances.int\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Int.Interval\nimport Mathlib.Topology.MetricSpace.Basic\nimport Mathlib.Order.Filter.Archimedean\n\n/-!\n# Topology on the integers\n\nThe structure of a metric space on `\u2124` is introduced in this file, induced from `\u211d`.\n-/\n\n\nnoncomputable section\n\nopen Metric Set Filter\n\nnamespace Int\n\ninstance : Dist \u2124 :=\n  \u27e8fun x y => dist (x : \u211d) y\u27e9\n\ntheorem dist_eq (x y : \u2124) : dist x y = |(x : \u211d) - y| := rfl\n#align int.dist_eq Int.dist_eq\n\ntheorem dist_eq' (m n : \u2124) : dist m n = |m - n| := by rw [dist_eq]; norm_cast\n\n@[norm_cast, simp]\ntheorem dist_cast_real (x y : \u2124) : dist (x : \u211d) y = dist x y :=\n  rfl\n#align int.dist_cast_real Int.dist_cast_real\n\ntheorem pairwise_one_le_dist : Pairwise fun m n : \u2124 => 1 \u2264 dist m n := by\n  intro m n hne\n  rw [dist_eq]; norm_cast; rwa [\u2190 zero_add (1 : \u2124), Int.add_one_le_iff, abs_pos, sub_ne_zero]\n#align int.pairwise_one_le_dist Int.pairwise_one_le_dist\n\ntheorem uniformEmbedding_coe_real : UniformEmbedding ((\u2191) : \u2124 \u2192 \u211d) :=\n  uniformEmbedding_bot_of_pairwise_le_dist zero_lt_one pairwise_one_le_dist\n#align int.uniform_embedding_coe_real Int.uniformEmbedding_coe_real\n\ntheorem closedEmbedding_coe_real : ClosedEmbedding ((\u2191) : \u2124 \u2192 \u211d) :=\n  closedEmbedding_of_pairwise_le_dist zero_lt_one pairwise_one_le_dist\n#align int.closed_embedding_coe_real Int.closedEmbedding_coe_real\n\ninstance : MetricSpace \u2124 := Int.uniformEmbedding_coe_real.comapMetricSpace _\n\ntheorem preimage_ball (x : \u2124) (r : \u211d) : (\u2191) \u207b\u00b9' ball (x : \u211d) r = ball x r := rfl\n#align int.preimage_ball Int.preimage_ball\n\n\n\ntheorem ball_eq_Ioo (x : \u2124) (r : \u211d) : ball x r = Ioo \u230a\u2191x - r\u230b \u2308\u2191x + r\u2309 := by\n  rw [\u2190 preimage_ball, Real.ball_eq_Ioo, preimage_Ioo]\n#align int.ball_eq_Ioo Int.ball_eq_Ioo\n\ntheorem closedBall_eq_Icc (x : \u2124) (r : \u211d) : closedBall x r = Icc \u2308\u2191x - r\u2309 \u230a\u2191x + r\u230b := by\n  rw [\u2190 preimage_closedBall, Real.closedBall_eq_Icc, preimage_Icc]\n#align int.closed_ball_eq_Icc Int.closedBall_eq_Icc\n\ninstance : ProperSpace \u2124 :=\n  \u27e8fun x r => by\n    rw [closedBall_eq_Icc]\n    exact (Set.finite_Icc _ _).isCompact\u27e9\n\n@[simp]\ntheorem cocompact_eq : cocompact \u2124 = atBot \u2294 atTop := by\n  simp_rw [\u2190 comap_dist_right_atTop_eq_cocompact (0 : \u2124), dist_eq', sub_zero,\n    \u2190 comap_abs_atTop, \u2190 @Int.comap_cast_atTop \u211d, comap_comap]; rfl\n#align int.cocompact_eq Int.cocompact_eq\n\n@[simp]\ntheorem cofinite_eq : (cofinite : Filter \u2124) = atBot \u2294 atTop := by\n  rw [\u2190 cocompact_eq_cofinite, cocompact_eq]\n#align int.cofinite_eq Int.cofinite_eq\n\nend Int\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/Instances/Int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7165138249873638}}
{"text": "namespace Sec_4_6\n\n  namespace exercise1\n    variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n    example : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := iff.intro\n      (assume h : \u2200 x, p x \u2227 q x,\n        and.intro \n        (assume w,\n          show p w, from (h w).left)\n        (assume w,\n          show q w, from (h w).right))\n      (assume h : (\u2200 x, p x) \u2227 (\u2200 x, q x),\n        assume w,\n        \u27e8(h.left w), (h.right w)\u27e9)\n\n\n    example : (\u2200 x, (p x \u2192 q x)) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := \n      assume h\u2081 : \u2200 x, (p x \u2192 q x),\n      assume h\u2082 : (\u2200 x, p x),\n      assume w,\n      have h\u2083 : p w, from h\u2082 w,\n      show q w, from h\u2081 w h\u2083\n\n    example : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 (\u2200 x, p x \u2228 q x) := \n      assume h: (\u2200 x, p x) \u2228 (\u2200 x, q x),\n      assume w,\n        or.elim h\n          (assume hl : \u2200 x, p x,\n            show p w \u2228 q w, from or.intro_left _ (hl w))\n          (assume hr : \u2200 x, q x,\n            show p w \u2228 q w, from or.intro_right _ (hr w))\n  \n  end exercise1\n\n\n    \nend Sec_4_6\n", "meta": {"author": "williamdemeo", "repo": "LEAN_wjd", "sha": "13826c75c06ef435166a26a72e76fe984c15bad7", "save_path": "github-repos/lean/williamdemeo-LEAN_wjd", "path": "github-repos/lean/williamdemeo-LEAN_wjd/LEAN_wjd-13826c75c06ef435166a26a72e76fe984c15bad7/theorem_proving/04-exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7165138123583178}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Fabian Gl\u00f6ckle, Kyle Miller\n-/\nimport linear_algebra.finite_dimensional\nimport linear_algebra.projection\nimport linear_algebra.sesquilinear_form\nimport ring_theory.finiteness\nimport linear_algebra.free_module.finite.basic\n\n/-!\n# Dual vector spaces\n\nThe dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \\to R$.\n\n## Main definitions\n\n* Duals and transposes:\n  * `module.dual R M` defines the dual space of the `R`-module `M`, as `M \u2192\u2097[R] R`.\n  * `module.dual_pairing R M` is the canonical pairing between `dual R M` and `M`.\n  * `module.dual.eval R M : M \u2192\u2097[R] dual R (dual R)` is the canonical map to the double dual.\n  * `module.dual.transpose` is the linear map from `M \u2192\u2097[R] M'` to `dual R M' \u2192\u2097[R] dual R M`.\n  * `linear_map.dual_map` is `module.dual.transpose` of a given linear map, for dot notation.\n  * `linear_equiv.dual_map` is for the dual of an equivalence.\n* Bases:\n  * `basis.to_dual` produces the map `M \u2192\u2097[R] dual R M` associated to a basis for an `R`-module `M`.\n  * `basis.to_dual_equiv` is the equivalence `M \u2243\u2097[R] dual R M` associated to a finite basis.\n  * `basis.dual_basis` is a basis for `dual R M` given a finite basis for `M`.\n  * `module.dual_bases e \u03b5` is the proposition that the families `e` of vectors and `\u03b5` of dual\n    vectors have the characteristic properties of a basis and a dual.\n* Submodules:\n  * `submodule.dual_restrict W` is the transpose `dual R M \u2192\u2097[R] dual R W` of the inclusion map.\n  * `submodule.dual_annihilator W` is the kernel of `W.dual_restrict`. That is, it is the submodule\n    of `dual R M` whose elements all annihilate `W`.\n  * `submodule.dual_restrict_comap W'` is the dual annihilator of `W' : submodule R (dual R M)`,\n    pulled back along `module.dual.eval R M`.\n  * `submodule.dual_copairing W` is the canonical pairing between `W.dual_annihilator` and `M \u29f8 W`.\n    It is nondegenerate for vector spaces (`subspace.dual_copairing_nondegenerate`).\n  * `submodule.dual_pairing W` is the canonical pairing between `dual R M \u29f8 W.dual_annihilator`\n    and `W`. It is nondegenerate for vector spaces (`subspace.dual_pairing_nondegenerate`).\n* Vector spaces:\n  * `subspace.dual_lift W` is an arbitrary section (using choice) of `submodule.dual_restrict W`.\n\n## Main results\n\n* Bases:\n  * `module.dual_basis.basis` and `module.dual_basis.coe_basis`: if `e` and `\u03b5` form a dual pair,\n    then `e` is a basis.\n  * `module.dual_basis.coe_dual_basis`: if `e` and `\u03b5` form a dual pair,\n    then `\u03b5` is a basis.\n* Annihilators:\n  * `module.dual_annihilator_gc R M` is the antitone Galois correspondence between\n    `submodule.dual_annihilator` and `submodule.dual_coannihilator`.\n  * `linear_map.ker_dual_map_eq_dual_annihilator_range` says that\n    `f.dual_map.ker = f.range.dual_annihilator`\n  * `linear_map.range_dual_map_eq_dual_annihilator_ker_of_subtype_range_surjective` says that\n    `f.dual_map.range = f.ker.dual_annihilator`; this is specialized to vector spaces in\n    `linear_map.range_dual_map_eq_dual_annihilator_ker`.\n  * `submodule.dual_quot_equiv_dual_annihilator` is the equivalence\n    `dual R (M \u29f8 W) \u2243\u2097[R] W.dual_annihilator`\n* Vector spaces:\n  * `subspace.dual_annihilator_dual_coannihilator_eq` says that the double dual annihilator,\n    pulled back ground `module.dual.eval`, is the original submodule.\n  * `subspace.dual_annihilator_gci` says that `module.dual_annihilator_gc R M` is an\n    antitone Galois coinsertion.\n  * `subspace.quot_annihilator_equiv` is the equivalence\n    `dual K V \u29f8 W.dual_annihilator \u2243\u2097[K] dual K W`.\n  * `linear_map.dual_pairing_nondegenerate` says that `module.dual_pairing` is nondegenerate.\n  * `subspace.is_compl_dual_annihilator` says that the dual annihilator carries complementary\n    subspaces to complementary subspaces.\n* Finite-dimensional vector spaces:\n  * `module.eval_equiv` is the equivalence `V \u2243\u2097[K] dual K (dual K V)`\n  * `module.map_eval_equiv` is the order isomorphism between subspaces of `V` and\n    subspaces of `dual K (dual K V)`.\n  * `subspace.quot_dual_equiv_annihilator W` is the equivalence\n    `(dual K V \u29f8 W.dual_lift.range) \u2243\u2097[K] W.dual_annihilator`, where `W.dual_lift.range` is a copy\n    of `dual K W` inside `dual K V`.\n  * `subspace.quot_equiv_annihilator W` is the equivalence `(V \u29f8 W) \u2243\u2097[K] W.dual_annihilator`\n  * `subspace.dual_quot_distrib W` is an equivalence\n    `dual K (V\u2081 \u29f8 W) \u2243\u2097[K] dual K V\u2081 \u29f8 W.dual_lift.range` from an arbitrary choice of\n    splitting of `V\u2081`.\n\n## TODO\n\nErd\u00f6s-Kaplansky theorem about the dimension of a dual vector space in case of infinite dimension.\n-/\n\nnoncomputable theory\n\nnamespace module\n\nvariables (R : Type*) (M : Type*)\nvariables [comm_semiring R] [add_comm_monoid M] [module R M]\n\n/-- The dual space of an R-module M is the R-module of linear maps `M \u2192 R`. -/\n@[derive [add_comm_monoid, module R]] def dual := M \u2192\u2097[R] R\n\ninstance {S : Type*} [comm_ring S] {N : Type*} [add_comm_group N] [module S N] :\n  add_comm_group (dual S N) := linear_map.add_comm_group\n\ninstance : linear_map_class (dual R M) R M R :=\nlinear_map.semilinear_map_class\n\n/-- The canonical pairing of a vector space and its algebraic dual. -/\ndef dual_pairing (R M) [comm_semiring R] [add_comm_monoid M] [module R M] :\n  module.dual R M \u2192\u2097[R] M \u2192\u2097[R] R := linear_map.id\n\n@[simp] lemma dual_pairing_apply (v x) : dual_pairing R M v x = v x := rfl\n\nnamespace dual\n\ninstance : inhabited (dual R M) := linear_map.inhabited\n\ninstance : has_coe_to_fun (dual R M) (\u03bb _, M \u2192 R) := \u27e8linear_map.to_fun\u27e9\n\n/-- Maps a module M to the dual of the dual of M. See `module.erange_coe` and\n`module.eval_equiv`. -/\ndef eval : M \u2192\u2097[R] (dual R (dual R M)) := linear_map.flip linear_map.id\n\n@[simp] lemma eval_apply (v : M) (a : dual R M) : eval R M v a = a v := rfl\n\nvariables {R M} {M' : Type*} [add_comm_monoid M'] [module R M']\n\n/-- The transposition of linear maps, as a linear map from `M \u2192\u2097[R] M'` to\n`dual R M' \u2192\u2097[R] dual R M`. -/\ndef transpose : (M \u2192\u2097[R] M') \u2192\u2097[R] (dual R M' \u2192\u2097[R] dual R M) :=\n(linear_map.llcomp R M M' R).flip\n\nlemma transpose_apply (u : M \u2192\u2097[R] M') (l : dual R M') : transpose u l = l.comp u := rfl\n\nvariables {M'' : Type*} [add_comm_monoid M''] [module R M'']\n\nlemma transpose_comp (u : M' \u2192\u2097[R] M'') (v : M \u2192\u2097[R] M') :\n  transpose (u.comp v) = (transpose v).comp (transpose u) := rfl\n\nend dual\n\nsection prod\nvariables (M' : Type*) [add_comm_monoid M'] [module R M']\n\n/-- Taking duals distributes over products. -/\n@[simps] def dual_prod_dual_equiv_dual :\n  (module.dual R M \u00d7 module.dual R M') \u2243\u2097[R] module.dual R (M \u00d7 M') :=\nlinear_map.coprod_equiv R\n\n@[simp] lemma dual_prod_dual_equiv_dual_apply (\u03c6 : module.dual R M) (\u03c8 : module.dual R M') :\n  dual_prod_dual_equiv_dual R M M' (\u03c6, \u03c8) = \u03c6.coprod \u03c8 := rfl\n\nend prod\n\nend module\n\nsection dual_map\nopen module\n\nvariables {R : Type*} [comm_semiring R] {M\u2081 : Type*} {M\u2082 : Type*}\nvariables [add_comm_monoid M\u2081] [module R M\u2081] [add_comm_monoid M\u2082] [module R M\u2082]\n\n/-- Given a linear map `f : M\u2081 \u2192\u2097[R] M\u2082`, `f.dual_map` is the linear map between the dual of\n`M\u2082` and `M\u2081` such that it maps the functional `\u03c6` to `\u03c6 \u2218 f`. -/\ndef linear_map.dual_map (f : M\u2081 \u2192\u2097[R] M\u2082) : dual R M\u2082 \u2192\u2097[R] dual R M\u2081 :=\nmodule.dual.transpose f\n\nlemma linear_map.dual_map_def (f : M\u2081 \u2192\u2097[R] M\u2082) : f.dual_map = module.dual.transpose f := rfl\n\nlemma linear_map.dual_map_apply' (f : M\u2081 \u2192\u2097[R] M\u2082) (g : dual R M\u2082) :\n  f.dual_map g = g.comp f := rfl\n\n@[simp] lemma linear_map.dual_map_apply (f : M\u2081 \u2192\u2097[R] M\u2082) (g : dual R M\u2082) (x : M\u2081) :\n  f.dual_map g x = g (f x) := rfl\n\n@[simp] lemma linear_map.dual_map_id :\n  (linear_map.id : M\u2081 \u2192\u2097[R] M\u2081).dual_map = linear_map.id :=\nby { ext, refl }\n\nlemma linear_map.dual_map_comp_dual_map {M\u2083 : Type*} [add_comm_group M\u2083] [module R M\u2083]\n  (f : M\u2081 \u2192\u2097[R] M\u2082) (g : M\u2082 \u2192\u2097[R] M\u2083) :\n  f.dual_map.comp g.dual_map = (g.comp f).dual_map :=\nrfl\n\n/-- If a linear map is surjective, then its dual is injective. -/\nlemma linear_map.dual_map_injective_of_surjective {f : M\u2081 \u2192\u2097[R] M\u2082} (hf : function.surjective f) :\n  function.injective f.dual_map :=\nbegin\n  intros \u03c6 \u03c8 h,\n  ext x,\n  obtain \u27e8y, rfl\u27e9 := hf x,\n  exact congr_arg (\u03bb (g : module.dual R M\u2081), g y) h,\nend\n\n/-- The `linear_equiv` version of `linear_map.dual_map`. -/\ndef linear_equiv.dual_map (f : M\u2081 \u2243\u2097[R] M\u2082) : dual R M\u2082 \u2243\u2097[R] dual R M\u2081 :=\n{ inv_fun := f.symm.to_linear_map.dual_map,\n  left_inv :=\n    begin\n      intro \u03c6, ext x,\n      simp only [linear_map.dual_map_apply, linear_equiv.coe_to_linear_map,\n                 linear_map.to_fun_eq_coe, linear_equiv.apply_symm_apply]\n    end,\n  right_inv :=\n    begin\n      intro \u03c6, ext x,\n      simp only [linear_map.dual_map_apply, linear_equiv.coe_to_linear_map,\n                 linear_map.to_fun_eq_coe, linear_equiv.symm_apply_apply]\n    end,\n  .. f.to_linear_map.dual_map }\n\n@[simp] lemma linear_equiv.dual_map_apply (f : M\u2081 \u2243\u2097[R] M\u2082) (g : dual R M\u2082) (x : M\u2081) :\n  f.dual_map g x = g (f x) := rfl\n\n@[simp] lemma linear_equiv.dual_map_refl :\n  (linear_equiv.refl R M\u2081).dual_map = linear_equiv.refl R (dual R M\u2081) :=\nby { ext, refl }\n\n@[simp] lemma linear_equiv.dual_map_symm {f : M\u2081 \u2243\u2097[R] M\u2082} :\n  (linear_equiv.dual_map f).symm = linear_equiv.dual_map f.symm := rfl\n\nlemma linear_equiv.dual_map_trans {M\u2083 : Type*} [add_comm_group M\u2083] [module R M\u2083]\n  (f : M\u2081 \u2243\u2097[R] M\u2082) (g : M\u2082 \u2243\u2097[R] M\u2083) :\n  g.dual_map.trans f.dual_map = (f.trans g).dual_map :=\nrfl\n\nend dual_map\n\nnamespace basis\n\nuniverses u v w\n\nopen module module.dual submodule linear_map cardinal function\nopen_locale big_operators\n\nvariables {R M K V \u03b9 : Type*}\n\nsection comm_semiring\n\nvariables [comm_semiring R] [add_comm_monoid M] [module R M] [decidable_eq \u03b9]\nvariables (b : basis \u03b9 R M)\n\n/-- The linear map from a vector space equipped with basis to its dual vector space,\ntaking basis elements to corresponding dual basis elements. -/\ndef to_dual : M \u2192\u2097[R] module.dual R M :=\nb.constr \u2115 $ \u03bb v, b.constr \u2115 $ \u03bb w, if w = v then (1 : R) else 0\n\nlemma to_dual_apply (i j : \u03b9) :\n  b.to_dual (b i) (b j) = if i = j then 1 else 0 :=\nby { erw [constr_basis b, constr_basis b], ac_refl }\n\n@[simp] lemma to_dual_total_left (f : \u03b9 \u2192\u2080 R) (i : \u03b9) :\n  b.to_dual (finsupp.total \u03b9 M R b f) (b i) = f i :=\nbegin\n  rw [finsupp.total_apply, finsupp.sum, linear_map.map_sum, linear_map.sum_apply],\n  simp_rw [linear_map.map_smul, linear_map.smul_apply, to_dual_apply, smul_eq_mul,\n           mul_boole, finset.sum_ite_eq'],\n  split_ifs with h,\n  { refl },\n  { rw finsupp.not_mem_support_iff.mp h }\nend\n\n@[simp] lemma to_dual_total_right (f : \u03b9 \u2192\u2080 R) (i : \u03b9) :\n  b.to_dual (b i) (finsupp.total \u03b9 M R b f) = f i :=\nbegin\n  rw [finsupp.total_apply, finsupp.sum, linear_map.map_sum],\n  simp_rw [linear_map.map_smul, to_dual_apply, smul_eq_mul, mul_boole, finset.sum_ite_eq],\n  split_ifs with h,\n  { refl },\n  { rw finsupp.not_mem_support_iff.mp h }\nend\n\nlemma to_dual_apply_left (m : M) (i : \u03b9) : b.to_dual m (b i) = b.repr m i :=\nby rw [\u2190 b.to_dual_total_left, b.total_repr]\n\nlemma to_dual_apply_right (i : \u03b9) (m : M) : b.to_dual (b i) m = b.repr m i :=\nby rw [\u2190 b.to_dual_total_right, b.total_repr]\n\nlemma coe_to_dual_self (i : \u03b9) : b.to_dual (b i) = b.coord i :=\nby { ext, apply to_dual_apply_right }\n\n/-- `h.to_dual_flip v` is the linear map sending `w` to `h.to_dual w v`. -/\ndef to_dual_flip (m : M) : (M \u2192\u2097[R] R) := b.to_dual.flip m\n\nlemma to_dual_flip_apply (m\u2081 m\u2082 : M) : b.to_dual_flip m\u2081 m\u2082 = b.to_dual m\u2082 m\u2081 := rfl\n\nlemma to_dual_eq_repr (m : M) (i : \u03b9) : b.to_dual m (b i) = b.repr m i :=\nb.to_dual_apply_left m i\n\nlemma to_dual_eq_equiv_fun [fintype \u03b9] (m : M) (i : \u03b9) : b.to_dual m (b i) = b.equiv_fun m i :=\nby rw [b.equiv_fun_apply, to_dual_eq_repr]\n\nlemma to_dual_inj (m : M) (a : b.to_dual m = 0) : m = 0 :=\nbegin\n  rw [\u2190 mem_bot R, \u2190 b.repr.ker, mem_ker, linear_equiv.coe_coe],\n  apply finsupp.ext,\n  intro b,\n  rw [\u2190 to_dual_eq_repr, a],\n  refl\nend\n\ntheorem to_dual_ker : b.to_dual.ker = \u22a5 :=\nker_eq_bot'.mpr b.to_dual_inj\n\ntheorem to_dual_range [_root_.finite \u03b9] : b.to_dual.range = \u22a4 :=\nbegin\n  casesI nonempty_fintype \u03b9,\n  refine eq_top_iff'.2 (\u03bb f, _),\n  rw linear_map.mem_range,\n  let lin_comb : \u03b9 \u2192\u2080 R := finsupp.equiv_fun_on_finite.symm (\u03bb i, f.to_fun (b i)),\n  refine \u27e8finsupp.total \u03b9 M R b lin_comb, b.ext $ \u03bb i, _\u27e9,\n  rw [b.to_dual_eq_repr _ i, repr_total b],\n  refl,\nend\n\nend comm_semiring\n\nsection\n\nvariables [comm_semiring R] [add_comm_monoid M] [module R M] [fintype \u03b9]\nvariables (b : basis \u03b9 R M)\n\n@[simp] lemma sum_dual_apply_smul_coord (f : module.dual R M) : \u2211 x, f (b x) \u2022 b.coord x = f :=\nbegin\n  ext m,\n  simp_rw [linear_map.sum_apply, linear_map.smul_apply, smul_eq_mul, mul_comm (f _), \u2190smul_eq_mul,\n    \u2190f.map_smul, \u2190f.map_sum, basis.coord_apply, basis.sum_repr],\nend\n\nend\n\nsection comm_ring\n\nvariables [comm_ring R] [add_comm_group M] [module R M] [decidable_eq \u03b9]\nvariables (b : basis \u03b9 R M)\n\nsection finite\nvariables [_root_.finite \u03b9]\n\n/-- A vector space is linearly equivalent to its dual space. -/\n@[simps]\ndef to_dual_equiv : M \u2243\u2097[R] dual R M :=\nlinear_equiv.of_bijective b.to_dual\n  \u27e8ker_eq_bot.mp b.to_dual_ker, range_eq_top.mp b.to_dual_range\u27e9\n\n/-- Maps a basis for `V` to a basis for the dual space. -/\ndef dual_basis : basis \u03b9 R (dual R M) := b.map b.to_dual_equiv\n\n-- We use `j = i` to match `basis.repr_self`\nlemma dual_basis_apply_self (i j : \u03b9) : b.dual_basis i (b j) = if j = i then 1 else 0 :=\nby { convert b.to_dual_apply i j using 2, rw @eq_comm _ j i }\n\nlemma total_dual_basis (f : \u03b9 \u2192\u2080 R) (i : \u03b9) :\n  finsupp.total \u03b9 (dual R M) R b.dual_basis f (b i) = f i :=\nbegin\n  casesI nonempty_fintype \u03b9,\n  rw [finsupp.total_apply, finsupp.sum_fintype, linear_map.sum_apply],\n  { simp_rw [linear_map.smul_apply, smul_eq_mul, dual_basis_apply_self, mul_boole,\n      finset.sum_ite_eq, if_pos (finset.mem_univ i)] },\n  { intro, rw zero_smul },\nend\n\nlemma dual_basis_repr (l : dual R M) (i : \u03b9) : b.dual_basis.repr l i = l (b i) :=\nby rw [\u2190 total_dual_basis b, basis.total_repr b.dual_basis l]\n\nlemma dual_basis_apply (i : \u03b9) (m : M) : b.dual_basis i m = b.repr m i := b.to_dual_apply_right i m\n\n@[simp] lemma coe_dual_basis : \u21d1b.dual_basis = b.coord := by { ext i x, apply dual_basis_apply }\n\n@[simp] lemma to_dual_to_dual : b.dual_basis.to_dual.comp b.to_dual = dual.eval R M :=\nbegin\n  refine b.ext (\u03bb i, b.dual_basis.ext (\u03bb j, _)),\n  rw [linear_map.comp_apply, to_dual_apply_left, coe_to_dual_self, \u2190 coe_dual_basis,\n      dual.eval_apply, basis.repr_self, finsupp.single_apply, dual_basis_apply_self]\nend\n\nend finite\n\nlemma dual_basis_equiv_fun [fintype \u03b9] (l : dual R M) (i : \u03b9) :\n  b.dual_basis.equiv_fun l i = l (b i) :=\nby rw [basis.equiv_fun_apply, dual_basis_repr]\n\ntheorem eval_ker {\u03b9 : Type*} (b : basis \u03b9 R M) :\n  (dual.eval R M).ker = \u22a5 :=\nbegin\n  rw ker_eq_bot',\n  intros m hm,\n  simp_rw [linear_map.ext_iff, dual.eval_apply, zero_apply] at hm,\n  exact (basis.forall_coord_eq_zero_iff _).mp (\u03bb i, hm (b.coord i))\nend\n\nlemma eval_range {\u03b9 : Type*} [_root_.finite \u03b9] (b : basis \u03b9 R M) : (eval R M).range = \u22a4 :=\nbegin\n  classical,\n  casesI nonempty_fintype \u03b9,\n  rw [\u2190 b.to_dual_to_dual, range_comp, b.to_dual_range, submodule.map_top, to_dual_range _],\n  apply_instance\nend\n\n/-- A module with a basis is linearly equivalent to the dual of its dual space. -/\ndef eval_equiv  {\u03b9 : Type*} [_root_.finite \u03b9] (b : basis \u03b9 R M) : M \u2243\u2097[R] dual R (dual R M) :=\nlinear_equiv.of_bijective (eval R M)\n  \u27e8ker_eq_bot.mp b.eval_ker, range_eq_top.mp b.eval_range\u27e9\n\n@[simp] lemma eval_equiv_to_linear_map {\u03b9 : Type*} [_root_.finite \u03b9] (b : basis \u03b9 R M) :\n  (b.eval_equiv).to_linear_map = dual.eval R M := rfl\n\nsection\n\nopen_locale classical\n\nvariables [finite R M] [free R M] [nontrivial R]\n\ninstance dual_free : free R (dual R M) := free.of_basis (free.choose_basis R M).dual_basis\n\ninstance dual_finite : finite R (dual R M) := finite.of_basis (free.choose_basis R M).dual_basis\n\nend\n\nend comm_ring\n\n/-- `simp` normal form version of `total_dual_basis` -/\n@[simp] lemma total_coord [comm_ring R] [add_comm_group M] [module R M] [_root_.finite \u03b9]\n  (b : basis \u03b9 R M) (f : \u03b9 \u2192\u2080 R) (i : \u03b9) :\n  finsupp.total \u03b9 (dual R M) R b.coord f (b i) = f i :=\nby { haveI := classical.dec_eq \u03b9, rw [\u2190 coe_dual_basis, total_dual_basis] }\n\nlemma dual_dim_eq [comm_ring K] [add_comm_group V] [module K V] [_root_.finite \u03b9]\n  (b : basis \u03b9 K V) :\n  cardinal.lift (module.rank K V) = module.rank K (dual K V) :=\nbegin\n  classical,\n  casesI nonempty_fintype \u03b9,\n  have := linear_equiv.lift_dim_eq b.to_dual_equiv,\n  simp only [cardinal.lift_umax] at this,\n  rw [this, \u2190 cardinal.lift_umax],\n  apply cardinal.lift_id,\nend\n\nend basis\n\nnamespace module\n\nvariables {K V : Type*}\nvariables [field K] [add_comm_group V] [module K V]\nopen module module.dual submodule linear_map cardinal basis finite_dimensional\n\nsection\nvariables (K) (V)\n\ntheorem eval_ker : (eval K V).ker = \u22a5 :=\nby { classical, exact (basis.of_vector_space K V).eval_ker }\n\ntheorem map_eval_injective : (submodule.map (eval K V)).injective :=\nbegin\n  apply submodule.map_injective_of_injective,\n  rw \u2190 linear_map.ker_eq_bot,\n  apply eval_ker K V, -- elaborates faster than `exact`\nend\n\ntheorem comap_eval_surjective : (submodule.comap (eval K V)).surjective :=\nbegin\n  apply submodule.comap_surjective_of_injective,\n  rw \u2190 linear_map.ker_eq_bot,\n  apply eval_ker K V, -- elaborates faster than `exact`\nend\n\nend\n\nsection\nvariable (K)\n\ntheorem eval_apply_eq_zero_iff (v : V) : (eval K V) v = 0 \u2194 v = 0 :=\nby simpa only using set_like.ext_iff.mp (eval_ker K V) v\n\ntheorem eval_apply_injective : function.injective (eval K V) :=\n(injective_iff_map_eq_zero' (eval K V)).mpr (eval_apply_eq_zero_iff K)\n\ntheorem forall_dual_apply_eq_zero_iff (v : V) : (\u2200 (\u03c6 : module.dual K V), \u03c6 v = 0) \u2194 v = 0 :=\nby { rw [\u2190 eval_apply_eq_zero_iff K v, linear_map.ext_iff], refl }\n\nend\n\n-- TODO(jmc): generalize to rings, once `module.rank` is generalized\ntheorem dual_dim_eq [finite_dimensional K V] :\n  cardinal.lift (module.rank K V) = module.rank K (dual K V) :=\n(basis.of_vector_space K V).dual_dim_eq\n\nlemma erange_coe [finite_dimensional K V] : (eval K V).range = \u22a4 :=\nbegin\n  letI : is_noetherian K V := is_noetherian.iff_fg.2 infer_instance,\n  exact (basis.of_vector_space K V).eval_range\nend\n\nvariables (K V)\n\n/-- A vector space is linearly equivalent to the dual of its dual space. -/\ndef eval_equiv [finite_dimensional K V] : V \u2243\u2097[K] dual K (dual K V) :=\nlinear_equiv.of_bijective (eval K V)\n  -- 60x faster elaboration than using `ker_eq_bot.mp eval_ker` directly:\n  \u27e8by { rw \u2190 ker_eq_bot, apply eval_ker K V }, range_eq_top.mp erange_coe\u27e9\n\n/-- The isomorphism `module.eval_equiv` induces an order isomorphism on subspaces. -/\ndef map_eval_equiv [finite_dimensional K V] : subspace K V \u2243o subspace K (dual K (dual K V)) :=\nsubmodule.order_iso_map_comap (eval_equiv K V)\n\nvariables {K V}\n\n@[simp] lemma eval_equiv_to_linear_map [finite_dimensional K V] :\n  (eval_equiv K V).to_linear_map = dual.eval K V := rfl\n\n@[simp] lemma map_eval_equiv_apply [finite_dimensional K V] (W : subspace K V) :\n  map_eval_equiv K V W = W.map (eval K V) := rfl\n\n@[simp] lemma map_eval_equiv_symm_apply [finite_dimensional K V]\n  (W'' : subspace K (dual K (dual K V))) :\n  (map_eval_equiv K V).symm W'' = W''.comap (eval K V) := rfl\n\nend module\n\nsection dual_bases\n\nopen module\n\nvariables {R M \u03b9 : Type*}\nvariables [comm_semiring R] [add_comm_monoid M] [module R M] [decidable_eq \u03b9]\n\n/-- Try using `set.to_finite` to dispatch a `set.finite` goal. -/\n-- TODO: In Lean 4 we can remove this and use `by { intros; exact Set.toFinite _ }` as a default\n-- argument.\nmeta def use_finite_instance : tactic unit := `[intros, exact set.to_finite _]\n\n/-- `e` and `\u03b5` have characteristic properties of a basis and its dual -/\n@[nolint has_nonempty_instance]\nstructure module.dual_bases (e : \u03b9 \u2192 M) (\u03b5 : \u03b9 \u2192 (dual R M)) : Prop :=\n(eval : \u2200 i j : \u03b9, \u03b5 i (e j) = if i = j then 1 else 0)\n(total : \u2200 {m : M}, (\u2200 i, \u03b5 i m = 0) \u2192 m = 0)\n(finite : \u2200 m : M, {i | \u03b5 i m \u2260 0}.finite . use_finite_instance)\n\nend dual_bases\n\nnamespace module.dual_bases\n\nopen module module.dual linear_map function\n\nvariables {R M \u03b9 : Type*}\nvariables [comm_ring R] [add_comm_group M] [module R M]\nvariables {e : \u03b9 \u2192 M} {\u03b5 : \u03b9 \u2192 dual R M}\n\n/-- The coefficients of `v` on the basis `e` -/\ndef coeffs [decidable_eq \u03b9] (h : dual_bases e \u03b5) (m : M) : \u03b9 \u2192\u2080 R :=\n{ to_fun := \u03bb i, \u03b5 i m,\n  support := (h.finite m).to_finset,\n  mem_support_to_fun := by { intro i, rw [set.finite.mem_to_finset, set.mem_set_of_eq] } }\n\n@[simp] \n\n/-- linear combinations of elements of `e`.\nThis is a convenient abbreviation for `finsupp.total _ M R e l` -/\ndef lc {\u03b9} (e : \u03b9 \u2192 M) (l : \u03b9 \u2192\u2080 R) : M := l.sum (\u03bb (i : \u03b9) (a : R), a \u2022 (e i))\n\nlemma lc_def (e : \u03b9 \u2192 M) (l : \u03b9 \u2192\u2080 R) : lc e l = finsupp.total _ _ _ e l := rfl\n\nopen module\n\nvariables [decidable_eq \u03b9] (h : dual_bases e \u03b5)\ninclude h\n\nlemma dual_lc (l : \u03b9 \u2192\u2080 R) (i : \u03b9) : \u03b5 i (dual_bases.lc e l) = l i :=\nbegin\n  erw linear_map.map_sum,\n  simp only [h.eval, map_smul, smul_eq_mul],\n  rw finset.sum_eq_single i,\n  { simp },\n  { intros q q_in q_ne,\n    simp [q_ne.symm] },\n  { intro p_not_in,\n    simp [finsupp.not_mem_support_iff.1 p_not_in] },\nend\n\n@[simp]\nlemma coeffs_lc (l : \u03b9 \u2192\u2080 R) : h.coeffs (dual_bases.lc e l) = l :=\nby { ext i, rw [h.coeffs_apply, h.dual_lc] }\n\n/-- For any m : M n, \\sum_{p \u2208 Q n} (\u03b5 p m) \u2022 e p = m -/\n@[simp]\nlemma lc_coeffs (m : M) : dual_bases.lc e (h.coeffs m) = m :=\nbegin\n  refine eq_of_sub_eq_zero (h.total _),\n  intros i,\n  simp [-sub_eq_add_neg, linear_map.map_sub, h.dual_lc, sub_eq_zero]\nend\n\n/-- `(h : dual_bases e \u03b5).basis` shows the family of vectors `e` forms a basis. -/\n@[simps]\ndef basis : basis \u03b9 R M :=\nbasis.of_repr\n{ to_fun := coeffs h,\n  inv_fun := lc e,\n  left_inv := lc_coeffs h,\n  right_inv := coeffs_lc h,\n  map_add' := \u03bb v w, by { ext i, exact (\u03b5 i).map_add v w },\n  map_smul' := \u03bb c v, by { ext i, exact (\u03b5 i).map_smul c v } }\n\n@[simp] lemma coe_basis : \u21d1h.basis = e :=\nby { ext i, rw basis.apply_eq_iff, ext j,\n     rw [h.basis_repr_apply, coeffs_apply, h.eval, finsupp.single_apply],\n     convert if_congr eq_comm rfl rfl } -- `convert` to get rid of a `decidable_eq` mismatch\n\nlemma mem_of_mem_span {H : set \u03b9} {x : M} (hmem : x \u2208 submodule.span R (e '' H)) :\n  \u2200 i : \u03b9, \u03b5 i x \u2260 0 \u2192 i \u2208 H :=\nbegin\n  intros i hi,\n  rcases (finsupp.mem_span_image_iff_total _).mp hmem with \u27e8l, supp_l, rfl\u27e9,\n  apply not_imp_comm.mp ((finsupp.mem_supported' _ _).mp supp_l i),\n  rwa [\u2190 lc_def, h.dual_lc] at hi\nend\n\nlemma coe_dual_basis [fintype \u03b9] : \u21d1h.basis.dual_basis = \u03b5 :=\nfunext (\u03bb i, h.basis.ext (\u03bb j, by rw [h.basis.dual_basis_apply_self, h.coe_basis, h.eval,\n                                      if_congr eq_comm rfl rfl]))\n\nend module.dual_bases\n\nnamespace submodule\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} [comm_semiring R] [add_comm_monoid M] [module R M]\nvariable {W : submodule R M}\n\n/-- The `dual_restrict` of a submodule `W` of `M` is the linear map from the\n  dual of `M` to the dual of `W` such that the domain of each linear map is\n  restricted to `W`. -/\ndef dual_restrict (W : submodule R M) :\n  module.dual R M \u2192\u2097[R] module.dual R W :=\nlinear_map.dom_restrict' W\n\nlemma dual_restrict_def (W : submodule R M) : W.dual_restrict = W.subtype.dual_map := rfl\n\n@[simp] lemma dual_restrict_apply\n  (W : submodule R M) (\u03c6 : module.dual R M) (x : W) :\n  W.dual_restrict \u03c6 x = \u03c6 (x : M) := rfl\n\n/-- The `dual_annihilator` of a submodule `W` is the set of linear maps `\u03c6` such\n  that `\u03c6 w = 0` for all `w \u2208 W`. -/\ndef dual_annihilator {R : Type u} {M : Type v} [comm_semiring R] [add_comm_monoid M]\n  [module R M] (W : submodule R M) : submodule R $ module.dual R M :=\nW.dual_restrict.ker\n\n@[simp] lemma mem_dual_annihilator (\u03c6 : module.dual R M) :\n  \u03c6 \u2208 W.dual_annihilator \u2194 \u2200 w \u2208 W, \u03c6 w = 0 :=\nbegin\n  refine linear_map.mem_ker.trans _,\n  simp_rw [linear_map.ext_iff, dual_restrict_apply],\n  exact \u27e8\u03bb h w hw, h \u27e8w, hw\u27e9, \u03bb h w, h w.1 w.2\u27e9\nend\n\n/-- That $\\operatorname{ker}(\\iota^* : V^* \\to W^*) = \\operatorname{ann}(W)$.\nThis is the definition of the dual annihilator of the submodule $W$. -/\nlemma dual_restrict_ker_eq_dual_annihilator (W : submodule R M) :\n  W.dual_restrict.ker = W.dual_annihilator :=\nrfl\n\n/-- The `dual_annihilator` of a submodule of the dual space pulled back along the evaluation map\n`module.dual.eval`. -/\ndef dual_coannihilator (\u03a6 : submodule R (module.dual R M)) : submodule R M :=\n\u03a6.dual_annihilator.comap (module.dual.eval R M)\n\nlemma mem_dual_coannihilator {\u03a6 : submodule R (module.dual R M)} (x : M) :\n  x \u2208 \u03a6.dual_coannihilator \u2194 \u2200 \u03c6 \u2208 \u03a6, (\u03c6 x : R) = 0 :=\nby simp_rw [dual_coannihilator, mem_comap, mem_dual_annihilator, module.dual.eval_apply]\n\nlemma dual_annihilator_gc (R M : Type*) [comm_semiring R] [add_comm_monoid M] [module R M] :\n  galois_connection\n    (order_dual.to_dual \u2218 (dual_annihilator : submodule R M \u2192 submodule R (module.dual R M)))\n    (dual_coannihilator \u2218 order_dual.of_dual) :=\nbegin\n  intros a b,\n  induction b using order_dual.rec,\n  simp only [function.comp_app, order_dual.to_dual_le_to_dual, order_dual.of_dual_to_dual],\n  split;\n  { intros h x hx,\n    simp only [mem_dual_annihilator, mem_dual_coannihilator],\n    intros y hy,\n    have := h hy,\n    simp only [mem_dual_annihilator, mem_dual_coannihilator] at this,\n    exact this x hx },\nend\n\nlemma le_dual_annihilator_iff_le_dual_coannihilator\n  {U : submodule R (module.dual R M)} {V : submodule R M} :\n  U \u2264 V.dual_annihilator \u2194 V \u2264 U.dual_coannihilator :=\n(dual_annihilator_gc R M).le_iff_le\n\n@[simp] lemma dual_annihilator_bot : (\u22a5 : submodule R M).dual_annihilator = \u22a4 :=\n(dual_annihilator_gc R M).l_bot\n\n@[simp] lemma dual_annihilator_top : (\u22a4 : submodule R M).dual_annihilator = \u22a5 :=\nbegin\n  rw eq_bot_iff,\n  intro v,\n  simp_rw [mem_dual_annihilator, mem_bot, mem_top, forall_true_left],\n  exact \u03bb h, linear_map.ext h,\nend\n\n@[simp] lemma dual_coannihilator_bot :\n  (\u22a5 : submodule R (module.dual R M)).dual_coannihilator = \u22a4 :=\n(dual_annihilator_gc R M).u_top\n\n@[mono] lemma dual_annihilator_anti {U V : submodule R M} (hUV : U \u2264 V) :\n  V.dual_annihilator \u2264 U.dual_annihilator :=\n(dual_annihilator_gc R M).monotone_l hUV\n\n@[mono] lemma dual_coannihilator_anti {U V : submodule R (module.dual R M)} (hUV : U \u2264 V) :\n  V.dual_coannihilator \u2264 U.dual_coannihilator :=\n(dual_annihilator_gc R M).monotone_u hUV\n\nlemma le_dual_annihilator_dual_coannihilator (U : submodule R M) :\n  U \u2264 U.dual_annihilator.dual_coannihilator :=\n(dual_annihilator_gc R M).le_u_l U\n\nlemma le_dual_coannihilator_dual_annihilator (U : submodule R (module.dual R M)) :\n  U \u2264 U.dual_coannihilator.dual_annihilator :=\n(dual_annihilator_gc R M).l_u_le U\n\nlemma dual_annihilator_dual_coannihilator_dual_annihilator\n  (U : submodule R M) :\n  U.dual_annihilator.dual_coannihilator.dual_annihilator = U.dual_annihilator :=\n(dual_annihilator_gc R M).l_u_l_eq_l U\n\nlemma dual_coannihilator_dual_annihilator_dual_coannihilator\n  (U : submodule R (module.dual R M)) :\n  U.dual_coannihilator.dual_annihilator.dual_coannihilator = U.dual_coannihilator :=\n(dual_annihilator_gc R M).u_l_u_eq_u U\n\nlemma dual_annihilator_sup_eq (U V : submodule R M) :\n  (U \u2294 V).dual_annihilator = U.dual_annihilator \u2293 V.dual_annihilator :=\n(dual_annihilator_gc R M).l_sup\n\nlemma dual_coannihilator_sup_eq (U V : submodule R (module.dual R M)) :\n  (U \u2294 V).dual_coannihilator = U.dual_coannihilator \u2293 V.dual_coannihilator :=\n(dual_annihilator_gc R M).u_inf\n\nlemma dual_annihilator_supr_eq {\u03b9 : Type*} (U : \u03b9 \u2192 submodule R M) :\n  (\u2a06 (i : \u03b9), U i).dual_annihilator = \u2a05 (i : \u03b9), (U i).dual_annihilator :=\n(dual_annihilator_gc R M).l_supr\n\nlemma dual_coannihilator_supr_eq {\u03b9 : Type*} (U : \u03b9 \u2192 submodule R (module.dual R M)) :\n  (\u2a06 (i : \u03b9), U i).dual_coannihilator = \u2a05 (i : \u03b9), (U i).dual_coannihilator :=\n(dual_annihilator_gc R M).u_infi\n\n/-- See also `subspace.dual_annihilator_inf_eq` for vector subspaces. -/\nlemma sup_dual_annihilator_le_inf (U V : submodule R M) :\n  U.dual_annihilator \u2294 V.dual_annihilator \u2264 (U \u2293 V).dual_annihilator :=\nbegin\n  rw [le_dual_annihilator_iff_le_dual_coannihilator, dual_coannihilator_sup_eq],\n  apply' inf_le_inf; exact le_dual_annihilator_dual_coannihilator _,\nend\n\n/-- See also `subspace.dual_annihilator_infi_eq` for vector subspaces when `\u03b9` is finite. -/\nlemma supr_dual_annihilator_le_infi {\u03b9 : Type*} (U : \u03b9 \u2192 submodule R M) :\n  (\u2a06 (i : \u03b9), (U i).dual_annihilator) \u2264 (\u2a05 (i : \u03b9), U i).dual_annihilator :=\nbegin\n  rw [le_dual_annihilator_iff_le_dual_coannihilator, dual_coannihilator_supr_eq],\n  apply' infi_mono,\n  exact \u03bb (i : \u03b9), le_dual_annihilator_dual_coannihilator (U i),\nend\n\nend submodule\n\nnamespace subspace\n\nopen submodule linear_map\n\nuniverses u v w\n\n-- We work in vector spaces because `exists_is_compl` only hold for vector spaces\nvariables {K : Type u} {V : Type v} [field K] [add_comm_group V] [module K V]\n\n@[simp] lemma dual_coannihilator_top (W : subspace K V) :\n  (\u22a4 : subspace K (module.dual K W)).dual_coannihilator = \u22a5 :=\nby rw [dual_coannihilator, dual_annihilator_top, comap_bot, module.eval_ker]\n\nlemma dual_annihilator_dual_coannihilator_eq {W : subspace K V} :\n  W.dual_annihilator.dual_coannihilator = W :=\nbegin\n  refine le_antisymm _ (le_dual_annihilator_dual_coannihilator _),\n  intro v,\n  simp only [mem_dual_annihilator, mem_dual_coannihilator],\n  contrapose!,\n  intro hv,\n  obtain \u27e8W', hW\u27e9 := submodule.exists_is_compl W,\n  obtain \u27e8\u27e8w, w'\u27e9, rfl, -\u27e9 := exists_unique_add_of_is_compl_prod hW v,\n  have hw'n : (w' : V) \u2209 W := by { contrapose! hv, exact submodule.add_mem W w.2 hv },\n  have hw'nz : w' \u2260 0 := by { rintro rfl, exact hw'n (submodule.zero_mem W) },\n  rw [ne.def, \u2190 module.forall_dual_apply_eq_zero_iff K w'] at hw'nz,\n  push_neg at hw'nz,\n  obtain \u27e8\u03c6, h\u03c6\u27e9 := hw'nz,\n  existsi ((linear_map.of_is_compl_prod hW).comp (linear_map.inr _ _ _)) \u03c6,\n  simp only [coe_comp, coe_inr, function.comp_app, of_is_compl_prod_apply, map_add,\n    of_is_compl_left_apply, zero_apply, of_is_compl_right_apply, zero_add, ne.def],\n  refine \u27e8_, h\u03c6\u27e9,\n  intros v hv,\n  apply linear_map.of_is_compl_left_apply hW \u27e8v, hv\u27e9, -- exact elaborates slowly\nend\n\ntheorem forall_mem_dual_annihilator_apply_eq_zero_iff (W : subspace K V) (v : V) :\n  (\u2200 (\u03c6 : module.dual K V), \u03c6 \u2208 W.dual_annihilator \u2192 \u03c6 v = 0) \u2194 v \u2208 W :=\nby rw [\u2190 set_like.ext_iff.mp dual_annihilator_dual_coannihilator_eq v,\n       mem_dual_coannihilator]\n\n/-- `submodule.dual_annihilator` and `submodule.dual_coannihilator` form a Galois coinsertion. -/\ndef dual_annihilator_gci (K V : Type*) [field K] [add_comm_group V] [module K V] :\n  galois_coinsertion\n    (order_dual.to_dual \u2218 (dual_annihilator : subspace K V \u2192 subspace K (module.dual K V)))\n    (dual_coannihilator \u2218 order_dual.of_dual) :=\n{ choice := \u03bb W h, dual_coannihilator W,\n  gc := dual_annihilator_gc K V,\n  u_l_le := \u03bb W, dual_annihilator_dual_coannihilator_eq.le,\n  choice_eq := \u03bb W h, rfl }\n\nlemma dual_annihilator_le_dual_annihilator_iff {W W' : subspace K V} :\n  W.dual_annihilator \u2264 W'.dual_annihilator \u2194 W' \u2264 W :=\n(dual_annihilator_gci K V).l_le_l_iff\n\nlemma dual_annihilator_inj {W W' : subspace K V} :\n  W.dual_annihilator = W'.dual_annihilator \u2194 W = W' :=\nbegin\n  split,\n  { apply (dual_annihilator_gci K V).l_injective },\n  { rintro rfl, refl },\nend\n\n/-- Given a subspace `W` of `V` and an element of its dual `\u03c6`, `dual_lift W \u03c6` is\nan arbitrary extension of `\u03c6` to an element of the dual of `V`.\nThat is, `dual_lift W \u03c6` sends `w \u2208 W` to `\u03c6 x` and `x` in a chosen complement of `W` to `0`. -/\nnoncomputable def dual_lift (W : subspace K V) :\n  module.dual K W \u2192\u2097[K] module.dual K V :=\nlet h := classical.indefinite_description _ W.exists_is_compl in\n  (linear_map.of_is_compl_prod h.2).comp (linear_map.inl _ _ _)\n\nvariable {W : subspace K V}\n\n@[simp] lemma dual_lift_of_subtype {\u03c6 : module.dual K W} (w : W) :\n  W.dual_lift \u03c6 (w : V) = \u03c6 w :=\nby { erw of_is_compl_left_apply _ w, refl }\n\nlemma dual_lift_of_mem {\u03c6 : module.dual K W} {w : V} (hw : w \u2208 W) :\n  W.dual_lift \u03c6 w = \u03c6 \u27e8w, hw\u27e9 :=\nby convert dual_lift_of_subtype \u27e8w, hw\u27e9\n\n@[simp] lemma dual_restrict_comp_dual_lift (W : subspace K V) :\n  W.dual_restrict.comp W.dual_lift = 1 :=\nby { ext \u03c6 x, simp }\n\nlemma dual_restrict_left_inverse (W : subspace K V) :\n  function.left_inverse W.dual_restrict W.dual_lift :=\n\u03bb x, show W.dual_restrict.comp W.dual_lift x = x,\n  by { rw [dual_restrict_comp_dual_lift], refl }\n\nlemma dual_lift_right_inverse (W : subspace K V) :\n  function.right_inverse W.dual_lift W.dual_restrict :=\nW.dual_restrict_left_inverse\n\nlemma dual_restrict_surjective :\n  function.surjective W.dual_restrict :=\nW.dual_lift_right_inverse.surjective\n\nlemma dual_lift_injective : function.injective W.dual_lift :=\nW.dual_restrict_left_inverse.injective\n\n/-- The quotient by the `dual_annihilator` of a subspace is isomorphic to the\n  dual of that subspace. -/\nnoncomputable def quot_annihilator_equiv (W : subspace K V) :\n  (module.dual K V \u29f8 W.dual_annihilator) \u2243\u2097[K] module.dual K W :=\n(quot_equiv_of_eq _ _ W.dual_restrict_ker_eq_dual_annihilator).symm.trans $\n  W.dual_restrict.quot_ker_equiv_of_surjective dual_restrict_surjective\n\n@[simp] lemma quot_annihilator_equiv_apply (W : subspace K V) (\u03c6 : module.dual K V) :\n  W.quot_annihilator_equiv (submodule.quotient.mk \u03c6) = W.dual_restrict \u03c6 :=\nby { ext, refl }\n\n/-- The natural isomorphism from the dual of a subspace `W` to `W.dual_lift.range`. -/\nnoncomputable def dual_equiv_dual (W : subspace K V) :\n  module.dual K W \u2243\u2097[K] W.dual_lift.range :=\nlinear_equiv.of_injective _ dual_lift_injective\n\nlemma dual_equiv_dual_def (W : subspace K V) :\n  W.dual_equiv_dual.to_linear_map = W.dual_lift.range_restrict := rfl\n\n@[simp] lemma dual_equiv_dual_apply (\u03c6 : module.dual K W) :\n  W.dual_equiv_dual \u03c6 = \u27e8W.dual_lift \u03c6, mem_range.2 \u27e8\u03c6, rfl\u27e9\u27e9 := rfl\n\nsection\n\nopen_locale classical\n\nopen finite_dimensional\n\nvariables {V\u2081 : Type*} [add_comm_group V\u2081] [module K V\u2081]\n\ninstance [H : finite_dimensional K V] : finite_dimensional K (module.dual K V) :=\nby apply_instance\n\nvariables [finite_dimensional K V] [finite_dimensional K V\u2081]\n\nlemma dual_annihilator_dual_annihilator_eq (W : subspace K V) :\n  W.dual_annihilator.dual_annihilator = module.map_eval_equiv K V W :=\nbegin\n  have : _ = W := subspace.dual_annihilator_dual_coannihilator_eq,\n  rw [dual_coannihilator, \u2190 module.map_eval_equiv_symm_apply] at this,\n  rwa \u2190 order_iso.symm_apply_eq,\nend\n\n-- TODO(kmill): https://github.com/leanprover-community/mathlib/pull/17521#discussion_r1083241963\n@[simp] lemma dual_finrank_eq :\n  finrank K (module.dual K V) = finrank K V :=\nlinear_equiv.finrank_eq (basis.of_vector_space K V).to_dual_equiv.symm\n\n/-- The quotient by the dual is isomorphic to its dual annihilator.  -/\nnoncomputable def quot_dual_equiv_annihilator (W : subspace K V) :\n  (module.dual K V \u29f8 W.dual_lift.range) \u2243\u2097[K] W.dual_annihilator :=\nlinear_equiv.quot_equiv_of_quot_equiv $\n  linear_equiv.trans W.quot_annihilator_equiv W.dual_equiv_dual\n\n/-- The quotient by a subspace is isomorphic to its dual annihilator. -/\nnoncomputable def quot_equiv_annihilator (W : subspace K V) :\n  (V \u29f8 W) \u2243\u2097[K] W.dual_annihilator :=\nbegin\n  refine _ \u226a\u226b\u2097 W.quot_dual_equiv_annihilator,\n  refine linear_equiv.quot_equiv_of_equiv _ (basis.of_vector_space K V).to_dual_equiv,\n  exact (basis.of_vector_space K W).to_dual_equiv.trans W.dual_equiv_dual\nend\n\nopen finite_dimensional\n\n@[simp]\nlemma finrank_dual_coannihilator_eq {\u03a6 : subspace K (module.dual K V)} :\n  finrank K \u03a6.dual_coannihilator = finrank K \u03a6.dual_annihilator :=\nbegin\n  rw [submodule.dual_coannihilator, \u2190 module.eval_equiv_to_linear_map],\n  exact linear_equiv.finrank_eq (linear_equiv.of_submodule' _ _),\nend\n\nlemma finrank_add_finrank_dual_coannihilator_eq\n  (W : subspace K (module.dual K V)) :\n  finrank K W + finrank K W.dual_coannihilator = finrank K V :=\nbegin\n  rw [finrank_dual_coannihilator_eq, W.quot_equiv_annihilator.finrank_eq.symm, add_comm,\n      submodule.finrank_quotient_add_finrank, subspace.dual_finrank_eq],\nend\n\nend\n\nend subspace\n\nopen module\n\nnamespace linear_map\nvariables {R : Type*} [comm_semiring R] {M\u2081 : Type*} {M\u2082 : Type*}\nvariables [add_comm_monoid M\u2081] [module R M\u2081] [add_comm_monoid M\u2082] [module R M\u2082]\n\nvariable (f : M\u2081 \u2192\u2097[R] M\u2082)\n\nlemma ker_dual_map_eq_dual_annihilator_range :\n  f.dual_map.ker = f.range.dual_annihilator :=\nbegin\n  ext \u03c6, split; intro h\u03c6,\n  { rw mem_ker at h\u03c6,\n    rw submodule.mem_dual_annihilator,\n    rintro y \u27e8x, rfl\u27e9,\n    rw [\u2190 dual_map_apply, h\u03c6, zero_apply] },\n  { ext x,\n    rw dual_map_apply,\n    rw submodule.mem_dual_annihilator at h\u03c6,\n    exact h\u03c6 (f x) \u27e8x, rfl\u27e9 }\nend\n\nlemma range_dual_map_le_dual_annihilator_ker :\n  f.dual_map.range \u2264 f.ker.dual_annihilator :=\nbegin\n  rintro _ \u27e8\u03c8, rfl\u27e9,\n  simp_rw [submodule.mem_dual_annihilator, mem_ker],\n  rintro x hx,\n  rw [dual_map_apply, hx, map_zero]\nend\n\nend linear_map\n\nsection comm_ring\n\nvariables {R M M' : Type*}\nvariables [comm_ring R] [add_comm_group M] [module R M] [add_comm_group M'] [module R M']\n\nnamespace submodule\n\n/-- Given a submodule, corestrict to the pairing on `M \u29f8 W` by\nsimultaneously restricting to `W.dual_annihilator`.\n\nSee `subspace.dual_copairing_nondegenerate`. -/\ndef dual_copairing (W : submodule R M) :\n  W.dual_annihilator \u2192\u2097[R] M \u29f8 W \u2192\u2097[R] R :=\nlinear_map.flip $ W.liftq ((module.dual_pairing R M).dom_restrict W.dual_annihilator).flip\n  (by { intros w hw, ext \u27e8\u03c6, h\u03c6\u27e9, exact (mem_dual_annihilator \u03c6).mp h\u03c6 w hw })\n\n@[simp] lemma dual_copairing_apply {W : submodule R M} (\u03c6 : W.dual_annihilator) (x : M) :\n  W.dual_copairing \u03c6 (quotient.mk x) = \u03c6 x := rfl\n\n/-- Given a submodule, restrict to the pairing on `W` by\nsimultaneously corestricting to `module.dual R M \u29f8 W.dual_annihilator`.\nThis is `submodule.dual_restrict` factored through the quotient by its kernel (which\nis `W.dual_annihilator` by definition).\n\nSee `subspace.dual_pairing_nondegenerate`. -/\ndef dual_pairing (W : submodule R M) :\n  module.dual R M \u29f8 W.dual_annihilator \u2192\u2097[R] W \u2192\u2097[R] R :=\nW.dual_annihilator.liftq W.dual_restrict le_rfl\n\n@[simp] lemma dual_pairing_apply {W : submodule R M} (\u03c6 : module.dual R M) (x : W) :\n  W.dual_pairing (quotient.mk \u03c6) x = \u03c6 x := rfl\n\n/-- That $\\operatorname{im}(q^* : (V/W)^* \\to V^*) = \\operatorname{ann}(W)$. -/\nlemma range_dual_map_mkq_eq (W : submodule R M) :\n  W.mkq.dual_map.range = W.dual_annihilator :=\nbegin\n  ext \u03c6,\n  rw linear_map.mem_range,\n  split,\n  { rintro \u27e8\u03c8, rfl\u27e9,\n    have := linear_map.mem_range_self W.mkq.dual_map \u03c8,\n    simpa only [ker_mkq] using linear_map.range_dual_map_le_dual_annihilator_ker W.mkq this, },\n  { intro h\u03c6,\n    existsi W.dual_copairing \u27e8\u03c6, h\u03c6\u27e9,\n    ext,\n    refl, }\nend\n\n/-- Equivalence $(M/W)^* \\approx \\operatorname{ann}(W)$. That is, there is a one-to-one\ncorrespondence between the dual of `M \u29f8 W` and those elements of the dual of `M` that\nvanish on `W`.\n\nThe inverse of this is `submodule.dual_copairing`. -/\ndef dual_quot_equiv_dual_annihilator (W : submodule R M) :\n  module.dual R (M \u29f8 W) \u2243\u2097[R] W.dual_annihilator :=\nlinear_equiv.of_linear\n  (W.mkq.dual_map.cod_restrict W.dual_annihilator $\n    \u03bb \u03c6, W.range_dual_map_mkq_eq \u25b8 W.mkq.dual_map.mem_range_self \u03c6)\n  W.dual_copairing\n  (by { ext, refl}) (by { ext, refl })\n\n@[simp] lemma dual_quot_equiv_dual_annihilator_apply (W : submodule R M)\n  (\u03c6 : module.dual R (M \u29f8 W)) (x : M) :\n  dual_quot_equiv_dual_annihilator W \u03c6 x = \u03c6 (quotient.mk x) := rfl\n\nlemma dual_copairing_eq (W : submodule R M) :\n  W.dual_copairing = (dual_quot_equiv_dual_annihilator W).symm.to_linear_map := rfl\n\n@[simp] lemma dual_quot_equiv_dual_annihilator_symm_apply_mk (W : submodule R M)\n  (\u03c6 : W.dual_annihilator) (x : M) :\n  (dual_quot_equiv_dual_annihilator W).symm \u03c6 (quotient.mk x) = \u03c6 x := rfl\n\nend submodule\n\nnamespace linear_map\nopen submodule\n\nlemma range_dual_map_eq_dual_annihilator_ker_of_surjective\n  (f : M \u2192\u2097[R] M') (hf : function.surjective f) :\n  f.dual_map.range = f.ker.dual_annihilator :=\nbegin\n  rw \u2190 f.ker.range_dual_map_mkq_eq,\n  let f' := linear_map.quot_ker_equiv_of_surjective f hf,\n  transitivity linear_map.range (f.dual_map.comp f'.symm.dual_map.to_linear_map),\n  { rw linear_map.range_comp_of_range_eq_top,\n    apply linear_equiv.range },\n  { apply congr_arg,\n    ext \u03c6 x,\n    simp only [linear_map.coe_comp, linear_equiv.coe_to_linear_map, linear_map.dual_map_apply,\n      linear_equiv.dual_map_apply, mkq_apply, f', linear_map.quot_ker_equiv_of_surjective,\n      linear_equiv.trans_symm, linear_equiv.trans_apply, linear_equiv.of_top_symm_apply,\n      linear_map.quot_ker_equiv_range_symm_apply_image, mkq_apply], }\nend\n\n-- Note, this can be specialized to the case where `R` is an injective `R`-module, or when\n-- `f.coker` is a projective `R`-module.\nlemma range_dual_map_eq_dual_annihilator_ker_of_subtype_range_surjective\n  (f : M \u2192\u2097[R] M') (hf : function.surjective f.range.subtype.dual_map) :\n  f.dual_map.range = f.ker.dual_annihilator :=\nbegin\n  have rr_surj : function.surjective f.range_restrict,\n  { rw [\u2190 linear_map.range_eq_top, linear_map.range_range_restrict] },\n  have := range_dual_map_eq_dual_annihilator_ker_of_surjective f.range_restrict rr_surj,\n  convert this using 1,\n  { change ((submodule.subtype f.range).comp f.range_restrict).dual_map.range = _,\n    rw [\u2190 linear_map.dual_map_comp_dual_map, linear_map.range_comp_of_range_eq_top],\n    rwa linear_map.range_eq_top, },\n  { apply congr_arg,\n    exact (linear_map.ker_range_restrict f).symm, },\nend\n\nend linear_map\n\nend comm_ring\n\nsection vector_space\n\nvariables {K : Type*} [field K] {V\u2081 : Type*} {V\u2082 : Type*}\nvariables [add_comm_group V\u2081] [module K V\u2081] [add_comm_group V\u2082] [module K V\u2082]\n\nnamespace linear_map\n\nlemma dual_pairing_nondegenerate : (dual_pairing K V\u2081).nondegenerate :=\n\u27e8separating_left_iff_ker_eq_bot.mpr ker_id, \u03bb x, (forall_dual_apply_eq_zero_iff K x).mp\u27e9\n\nlemma dual_map_surjective_of_injective {f : V\u2081 \u2192\u2097[K] V\u2082} (hf : function.injective f) :\n  function.surjective f.dual_map :=\nbegin\n  intro \u03c6,\n  let f' := linear_equiv.of_injective f hf,\n  use subspace.dual_lift (range f) (f'.symm.dual_map \u03c6),\n  ext x,\n  rw [linear_map.dual_map_apply, subspace.dual_lift_of_mem (mem_range_self f x),\n    linear_equiv.dual_map_apply],\n  congr' 1,\n  exact linear_equiv.symm_apply_apply f' x,\nend\n\nlemma range_dual_map_eq_dual_annihilator_ker (f : V\u2081 \u2192\u2097[K] V\u2082) :\n  f.dual_map.range = f.ker.dual_annihilator :=\nrange_dual_map_eq_dual_annihilator_ker_of_subtype_range_surjective f $\n  dual_map_surjective_of_injective (range f).injective_subtype\n\n/-- For vector spaces, `f.dual_map` is surjective if and only if `f` is injective -/\n@[simp] lemma dual_map_surjective_iff {f : V\u2081 \u2192\u2097[K] V\u2082} :\n  function.surjective f.dual_map \u2194 function.injective f :=\nby rw [\u2190 linear_map.range_eq_top, range_dual_map_eq_dual_annihilator_ker,\n       \u2190 submodule.dual_annihilator_bot, subspace.dual_annihilator_inj, linear_map.ker_eq_bot]\n\nend linear_map\n\nnamespace subspace\nopen submodule\n\nlemma dual_pairing_eq (W : subspace K V\u2081) :\n  W.dual_pairing = W.quot_annihilator_equiv.to_linear_map :=\nby { ext, refl }\n\nlemma dual_pairing_nondegenerate (W : subspace K V\u2081) : W.dual_pairing.nondegenerate :=\nbegin\n  split,\n  { rw [linear_map.separating_left_iff_ker_eq_bot, dual_pairing_eq],\n    apply linear_equiv.ker, },\n  { intros x h,\n    rw \u2190 forall_dual_apply_eq_zero_iff K x,\n    intro \u03c6,\n    simpa only [submodule.dual_pairing_apply, dual_lift_of_subtype]\n      using h (submodule.quotient.mk (W.dual_lift \u03c6)), }\nend\n\nlemma dual_copairing_nondegenerate (W : subspace K V\u2081) : W.dual_copairing.nondegenerate :=\nbegin\n  split,\n  { rw [linear_map.separating_left_iff_ker_eq_bot, dual_copairing_eq],\n    apply linear_equiv.ker, },\n  { rintro \u27e8x\u27e9,\n    simp only [quotient.quot_mk_eq_mk, dual_copairing_apply, quotient.mk_eq_zero],\n    rw [\u2190 forall_mem_dual_annihilator_apply_eq_zero_iff, set_like.forall],\n    exact id, }\nend\n\n-- Argument from https://math.stackexchange.com/a/2423263/172988\nlemma dual_annihilator_inf_eq (W W' : subspace K V\u2081) :\n  (W \u2293 W').dual_annihilator = W.dual_annihilator \u2294 W'.dual_annihilator :=\nbegin\n  refine le_antisymm _ (sup_dual_annihilator_le_inf W W'),\n  let F : V\u2081 \u2192\u2097[K] (V\u2081 \u29f8 W) \u00d7 (V\u2081 \u29f8 W') := (submodule.mkq W).prod (submodule.mkq W'),\n  have : F.ker = W \u2293 W' := by simp only [linear_map.ker_prod, ker_mkq],\n  rw [\u2190 this, \u2190 linear_map.range_dual_map_eq_dual_annihilator_ker],\n  intro \u03c6,\n  rw [linear_map.mem_range],\n  rintro \u27e8x, rfl\u27e9,\n  rw [submodule.mem_sup],\n  obtain \u27e8\u27e8a, b\u27e9, rfl\u27e9 := (dual_prod_dual_equiv_dual K (V\u2081 \u29f8 W) (V\u2081 \u29f8 W')).surjective x,\n  obtain \u27e8a', rfl\u27e9 := (dual_quot_equiv_dual_annihilator W).symm.surjective a,\n  obtain \u27e8b', rfl\u27e9 := (dual_quot_equiv_dual_annihilator W').symm.surjective b,\n  use [a', a'.property, b', b'.property],\n  refl,\nend\n\n-- This is also true if `V\u2081` is finite dimensional since one can restrict `\u03b9` to some subtype\n-- for which the infi and supr are the same.\n--\n-- The obstruction to the `dual_annihilator_inf_eq` argument carrying through is that we need\n-- for `module.dual R (\u03a0 (i : \u03b9), V \u29f8 W i) \u2243\u2097[K] \u03a0 (i : \u03b9), module.dual R (V \u29f8 W i)`, which is not\n-- true for infinite `\u03b9`. One would need to add additional hypothesis on `W` (for example, it might\n-- be true when the family is inf-closed).\nlemma dual_annihilator_infi_eq {\u03b9 : Type*} [_root_.finite \u03b9] (W : \u03b9 \u2192 subspace K V\u2081) :\n  (\u2a05 (i : \u03b9), W i).dual_annihilator = (\u2a06 (i : \u03b9), (W i).dual_annihilator) :=\nbegin\n  unfreezingI { revert \u03b9 },\n  refine finite.induction_empty_option _ _ _,\n  { intros \u03b1 \u03b2 h hyp W,\n    rw [\u2190 h.infi_comp, hyp (W \u2218 h), \u2190 h.supr_comp], },\n  { intro W,\n    rw [supr_of_empty', infi_of_empty', Inf_empty, Sup_empty, dual_annihilator_top], },\n  { introsI \u03b1 _ h W,\n    rw [infi_option, supr_option, dual_annihilator_inf_eq, h], }\nend\n\n/-- For vector spaces, dual annihilators carry direct sum decompositions\nto direct sum decompositions. -/\nlemma is_compl_dual_annihilator {W W' : subspace K V\u2081} (h : is_compl W W') :\n  is_compl W.dual_annihilator W'.dual_annihilator :=\nbegin\n  rw [is_compl_iff, disjoint_iff, codisjoint_iff] at h \u22a2,\n  rw [\u2190 dual_annihilator_inf_eq, \u2190 dual_annihilator_sup_eq, h.1, h.2,\n    dual_annihilator_top, dual_annihilator_bot],\n  exact \u27e8rfl, rfl\u27e9\nend\n\n/-- For finite-dimensional vector spaces, one can distribute duals over quotients by identifying\n`W.dual_lift.range` with `W`. Note that this depends on a choice of splitting of `V\u2081`. -/\ndef dual_quot_distrib [finite_dimensional K V\u2081] (W : subspace K V\u2081) :\n  module.dual K (V\u2081 \u29f8 W) \u2243\u2097[K] (module.dual K V\u2081 \u29f8 W.dual_lift.range) :=\nW.dual_quot_equiv_dual_annihilator.trans W.quot_dual_equiv_annihilator.symm\n\nend subspace\n\nsection finite_dimensional\n\nopen finite_dimensional linear_map\n\nvariable [finite_dimensional K V\u2082]\n\nnamespace linear_map\n\n-- TODO(kmill) remove finite_dimensional if possible\n-- see https://github.com/leanprover-community/mathlib/pull/17521#discussion_r1083242551\n@[simp] lemma finrank_range_dual_map_eq_finrank_range (f : V\u2081 \u2192\u2097[K] V\u2082) :\n  finrank K f.dual_map.range = finrank K f.range :=\nbegin\n  have := submodule.finrank_quotient_add_finrank f.range,\n  rw [(subspace.quot_equiv_annihilator f.range).finrank_eq,\n      \u2190 ker_dual_map_eq_dual_annihilator_range] at this,\n  conv_rhs at this { rw \u2190 subspace.dual_finrank_eq },\n  refine add_left_injective (finrank K f.dual_map.ker) _,\n  change _ + _ = _ + _,\n  rw [finrank_range_add_finrank_ker f.dual_map, add_comm, this],\nend\n\n/-- `f.dual_map` is injective if and only if `f` is surjective -/\n@[simp] lemma dual_map_injective_iff {f : V\u2081 \u2192\u2097[K] V\u2082} :\n  function.injective f.dual_map \u2194 function.surjective f :=\nbegin\n  refine \u27e8_, \u03bb h, dual_map_injective_of_surjective h\u27e9,\n  rw [\u2190 range_eq_top, \u2190 ker_eq_bot],\n  intro h,\n  apply finite_dimensional.eq_top_of_finrank_eq,\n  rw \u2190 finrank_eq_zero at h,\n  rw [\u2190 add_zero (finite_dimensional.finrank K f.range), \u2190 h,\n      \u2190 linear_map.finrank_range_dual_map_eq_finrank_range,\n      linear_map.finrank_range_add_finrank_ker, subspace.dual_finrank_eq],\nend\n\n/-- `f.dual_map` is bijective if and only if `f` is -/\n@[simp] lemma dual_map_bijective_iff {f : V\u2081 \u2192\u2097[K] V\u2082} :\n  function.bijective f.dual_map \u2194 function.bijective f :=\nby simp_rw [function.bijective, dual_map_surjective_iff, dual_map_injective_iff, and.comm]\n\nend linear_map\n\nend finite_dimensional\n\nend vector_space\n\nnamespace tensor_product\n\nvariables (R : Type*) (M : Type*) (N : Type*)\n\nvariables {\u03b9 \u03ba : Type*}\nvariables [decidable_eq \u03b9] [decidable_eq \u03ba]\nvariables [fintype \u03b9] [fintype \u03ba]\n\nopen_locale big_operators\nopen_locale tensor_product\n\nlocal attribute [ext] tensor_product.ext\n\nopen tensor_product\nopen linear_map\n\nsection\nvariables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid N]\nvariables [module R M] [module R N]\n\n/--\nThe canonical linear map from `dual M \u2297 dual N` to `dual (M \u2297 N)`,\nsending `f \u2297 g` to the composition of `tensor_product.map f g` with\nthe natural isomorphism `R \u2297 R \u2243 R`.\n-/\ndef dual_distrib : (dual R M) \u2297[R] (dual R N) \u2192\u2097[R] dual R (M \u2297[R] N) :=\n(comp_right \u2191(tensor_product.lid R R)) \u2218\u2097 hom_tensor_hom_map R M N R R\n\nvariables {R M N}\n\n@[simp]\nlemma dual_distrib_apply (f : dual R M) (g : dual R N) (m : M) (n : N) :\n  dual_distrib R M N (f \u2297\u209c g) (m \u2297\u209c n) = f m * g n :=\nrfl\n\nend\n\nvariables {R M N}\nvariables [comm_ring R] [add_comm_group M] [add_comm_group N]\nvariables [module R M] [module R N]\n\n/--\nAn inverse to `dual_tensor_dual_map` given bases.\n-/\nnoncomputable\ndef dual_distrib_inv_of_basis (b : basis \u03b9 R M) (c : basis \u03ba R N) :\n  dual R (M \u2297[R] N) \u2192\u2097[R] (dual R M) \u2297[R] (dual R N) :=\n\u2211 i j, (ring_lmap_equiv_self R \u2115 _).symm (b.dual_basis i \u2297\u209c c.dual_basis j)\n    \u2218\u2097 apply\u2097 (c j) \u2218\u2097 apply\u2097 (b i) \u2218\u2097 (lcurry R M N R)\n\n@[simp]\nlemma dual_distrib_inv_of_basis_apply (b : basis \u03b9 R M) (c : basis \u03ba R N)\n  (f : dual R (M \u2297[R] N)) : dual_distrib_inv_of_basis b c f =\n  \u2211 i j, (f (b i \u2297\u209c c j)) \u2022 (b.dual_basis i \u2297\u209c c.dual_basis j) :=\nby simp [dual_distrib_inv_of_basis]\n\n/--\nA linear equivalence between `dual M \u2297 dual N` and `dual (M \u2297 N)` given bases for `M` and `N`.\nIt sends `f \u2297 g` to the composition of `tensor_product.map f g` with the natural\nisomorphism `R \u2297 R \u2243 R`.\n-/\n@[simps]\nnoncomputable def dual_distrib_equiv_of_basis (b : basis \u03b9 R M) (c : basis \u03ba R N) :\n  (dual R M) \u2297[R] (dual R N) \u2243\u2097[R] dual R (M \u2297[R] N) :=\nbegin\n  refine linear_equiv.of_linear\n    (dual_distrib R M N) (dual_distrib_inv_of_basis b c) _ _,\n  { ext f m n,\n    have h : \u2200 (r s : R), r \u2022 s = s \u2022 r := is_commutative.comm,\n    simp only [compr\u2082_apply, mk_apply, comp_apply, id_apply, dual_distrib_inv_of_basis_apply,\n      linear_map.map_sum, map_smul, sum_apply, smul_apply, dual_distrib_apply, h (f _) _,\n      \u2190 f.map_smul, \u2190f.map_sum, \u2190smul_tmul_smul, \u2190tmul_sum, \u2190sum_tmul, basis.coe_dual_basis,\n      basis.coord_apply, basis.sum_repr] },\n  { ext f g,\n    simp only [compr\u2082_apply, mk_apply, comp_apply, id_apply, dual_distrib_inv_of_basis_apply,\n      dual_distrib_apply, \u2190smul_tmul_smul, \u2190tmul_sum, \u2190sum_tmul, basis.coe_dual_basis,\n      basis.sum_dual_apply_smul_coord] }\nend\n\nvariables (R M N)\nvariables [module.finite R M] [module.finite R N] [module.free R M] [module.free R N]\nvariables [nontrivial R]\n\nopen_locale classical\n\n/--\nA linear equivalence between `dual M \u2297 dual N` and `dual (M \u2297 N)` when `M` and `N` are finite free\nmodules. It sends `f \u2297 g` to the composition of `tensor_product.map f g` with the natural\nisomorphism `R \u2297 R \u2243 R`.\n-/\n@[simp]\nnoncomputable\ndef dual_distrib_equiv : (dual R M) \u2297[R] (dual R N) \u2243\u2097[R] dual R (M \u2297[R] N) :=\ndual_distrib_equiv_of_basis (module.free.choose_basis R M) (module.free.choose_basis R N)\n\nend tensor_product\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/dual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7164951963381063}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport field_theory.abel_ruffini\n\n/-\n\n## Insolvability of the quintic\n\nThere exist polynomials whose solutions cannot be expressed by radicals.\n\nLet `E` be a field and assume `p : E[X]` is a polynomial \n-/\n\nopen_locale polynomial\n\nvariables (E : Type) [field E] (p : E[X])\n\n-- The Galois group of `p` is the Galois group of `F/E` where `F` is the splitting field of `p`.\n\nopen polynomial\n\nexample : p.gal = ((splitting_field p) \u2243\u2090[E] (splitting_field p)) := rfl\n\n/- \nIf F/E is any field extension at all, then `solvable_by_rad E F` is the intermediate field consisting\nof elements which can be built using n'th roots and the field operations, starting from `E`. Here\nis the rather beautiful definition of the underlying set of this intermediate field:\n\n```\n/-- Inductive definition of solvable by radicals -/\ninductive is_solvable_by_rad : E \u2192 Prop\n| base (a : F) : is_solvable_by_rad (algebra_map F E a)\n| add (a b : E) : is_solvable_by_rad a \u2192 is_solvable_by_rad b \u2192 is_solvable_by_rad (a + b)\n| neg (\u03b1 : E) : is_solvable_by_rad \u03b1 \u2192 is_solvable_by_rad (-\u03b1)\n| mul (\u03b1 \u03b2 : E) : is_solvable_by_rad \u03b1 \u2192 is_solvable_by_rad \u03b2 \u2192 is_solvable_by_rad (\u03b1 * \u03b2)\n| inv (\u03b1 : E) : is_solvable_by_rad \u03b1 \u2192 is_solvable_by_rad \u03b1\u207b\u00b9\n| rad (\u03b1 : E) (n : \u2115) (hn : n \u2260 0) : is_solvable_by_rad (\u03b1^n) \u2192 is_solvable_by_rad \u03b1\n``` \n\n-/\n\nvariables  (F : Type) [field F] [algebra E F]\nexample : intermediate_field E F := solvable_by_rad E F \n\n-- The Abel-Ruffini theorem is that the min poly of an element in `solvable_by_rad E F` has solvable Galois group\n\nexample (a : solvable_by_rad E F) : is_solvable ((minpoly E a).gal) := solvable_by_rad.is_solvable a \n\n-- This was hard won! It was only finished a year or so ago.\n\n-- A symmetric group of size 5 or more is known not to be solvable:\n\nexample (X : Type) (hX : 5 \u2264 cardinal.mk X) : \u00acis_solvable (equiv.perm X) := equiv.perm.not_solvable X hX \n\n-- Using a root of x^5-4x+2 and the machinery in this section, Browning proves\n\nexample : \u2203 x : \u2102, is_algebraic \u211a x \u2227 \u00ac is_solvable_by_rad \u211a x := sorry\n\n-- See the file `archive.100-theorems-list.16_abel_ruffini`. \n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section21galois_theory/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7164951877916431}}
{"text": "/-\nCopyright (c) 2018 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\nimport topology.continuous_on\nimport order.filter.partial\n\n/-!\n# Partial functions and topological spaces\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove properties of `filter.ptendsto` etc in topological spaces. We also introduce\n`pcontinuous`, a version of `continuous` for partially defined functions.\n-/\n\nopen filter\nopen_locale topology\n\nvariables {\u03b1 \u03b2 : Type*} [topological_space \u03b1]\n\ntheorem rtendsto_nhds {r : rel \u03b2 \u03b1} {l : filter \u03b2} {a : \u03b1} :\n  rtendsto r l (\ud835\udcdd a) \u2194 (\u2200 s, is_open s \u2192 a \u2208 s \u2192 r.core s \u2208 l) :=\nall_mem_nhds_filter _ _ (\u03bb s t, id) _\n\ntheorem rtendsto'_nhds {r : rel \u03b2 \u03b1} {l : filter \u03b2} {a : \u03b1} :\n  rtendsto' r l (\ud835\udcdd a) \u2194 (\u2200 s, is_open s \u2192 a \u2208 s \u2192 r.preimage s \u2208 l) :=\nby { rw [rtendsto'_def], apply all_mem_nhds_filter, apply rel.preimage_mono }\n\ntheorem ptendsto_nhds {f : \u03b2 \u2192. \u03b1} {l : filter \u03b2} {a : \u03b1} :\n  ptendsto f l (\ud835\udcdd a) \u2194 (\u2200 s, is_open s \u2192 a \u2208 s \u2192 f.core s \u2208 l) :=\nrtendsto_nhds\n\ntheorem ptendsto'_nhds {f : \u03b2 \u2192. \u03b1} {l : filter \u03b2} {a : \u03b1} :\n  ptendsto' f l (\ud835\udcdd a) \u2194 (\u2200 s, is_open s \u2192 a \u2208 s \u2192 f.preimage s \u2208 l) :=\nrtendsto'_nhds\n\n/-! ### Continuity and partial functions -/\n\nvariable [topological_space \u03b2]\n\n/-- Continuity of a partial function -/\ndef pcontinuous (f : \u03b1 \u2192. \u03b2) := \u2200 s, is_open s \u2192 is_open (f.preimage s)\n\nlemma open_dom_of_pcontinuous {f : \u03b1 \u2192. \u03b2} (h : pcontinuous f) : is_open f.dom :=\nby rw [\u2190pfun.preimage_univ]; exact h _ is_open_univ\n\nlemma pcontinuous_iff' {f : \u03b1 \u2192. \u03b2} :\n  pcontinuous f \u2194 \u2200 {x y} (h : y \u2208 f x), ptendsto' f (\ud835\udcdd x) (\ud835\udcdd y) :=\nbegin\n  split,\n  { intros h x y h',\n    simp only [ptendsto'_def, mem_nhds_iff],\n    rintros s \u27e8t, tsubs, opent, yt\u27e9,\n    exact \u27e8f.preimage t, pfun.preimage_mono _ tsubs, h _ opent, \u27e8y, yt, h'\u27e9\u27e9 },\n  intros hf s os,\n  rw is_open_iff_nhds,\n  rintros x \u27e8y, ys, fxy\u27e9 t,\n  rw [mem_principal],\n  assume h : f.preimage s \u2286 t,\n  change t \u2208 \ud835\udcdd x,\n  apply mem_of_superset _ h,\n  have h' : \u2200 s \u2208 \ud835\udcdd y, f.preimage s \u2208 \ud835\udcdd x,\n  { intros s hs,\n     have : ptendsto' f (\ud835\udcdd x) (\ud835\udcdd y) := hf fxy,\n     rw ptendsto'_def at this,\n     exact this s hs },\n  show f.preimage s \u2208 \ud835\udcdd x,\n  apply h', rw mem_nhds_iff, exact \u27e8s, set.subset.refl _, os, ys\u27e9\nend\n\ntheorem continuous_within_at_iff_ptendsto_res (f : \u03b1 \u2192 \u03b2) {x : \u03b1} {s : set \u03b1} :\n  continuous_within_at f s x \u2194 ptendsto (pfun.res f s) (\ud835\udcdd x) (\ud835\udcdd (f x)) :=\ntendsto_iff_ptendsto _ _ _ _\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/partial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7164951812686223}}
{"text": "/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport algebra.category.Group.epi_mono\nimport algebra.category.Module.epi_mono\nimport algebra.module.injective\nimport category_theory.preadditive.injective\nimport group_theory.divisible\nimport ring_theory.principal_ideal_domain\n\n/-!\n# Injective objects in the category of abelian groups\n\nIn this file we prove that divisible groups are injective object in category of (additive) abelian\ngroups.\n\n-/\n\nopen category_theory\nopen_locale pointwise\n\nuniverse u\n\nvariables (A : Type u) [add_comm_group A]\n\nnamespace AddCommGroup\n\nlemma injective_of_injective_as_module [injective (\u27e8A\u27e9 : Module \u2124)] :\n  category_theory.injective (\u27e8A\u27e9 : AddCommGroup) :=\n{ factors := \u03bb X Y g f m,\n  begin\n    resetI,\n    let G : (\u27e8X\u27e9 : Module \u2124) \u27f6 \u27e8A\u27e9 :=\n      { map_smul' := by { intros, rw [ring_hom.id_apply, g.to_fun_eq_coe, map_zsmul], }, ..g },\n    let F : (\u27e8X\u27e9 : Module \u2124) \u27f6 \u27e8Y\u27e9 :=\n      { map_smul' := by { intros, rw [ring_hom.id_apply, f.to_fun_eq_coe, map_zsmul], }, ..f },\n    haveI : mono F,\n    { refine \u27e8\u03bb Z \u03b1 \u03b2 eq1, _\u27e9,\n      let \u03b1' : AddCommGroup.of Z \u27f6 X := \u03b1.to_add_monoid_hom,\n      let \u03b2' : AddCommGroup.of Z \u27f6 X := \u03b2.to_add_monoid_hom,\n      have eq2 : \u03b1' \u226b f = \u03b2' \u226b f,\n      { ext,\n        simp only [category_theory.comp_apply, linear_map.to_add_monoid_hom_coe],\n        simpa only [Module.coe_comp, linear_map.coe_mk,\n          function.comp_app] using fun_like.congr_fun eq1 x },\n      rw cancel_mono at eq2,\n      ext, simpa only using fun_like.congr_fun eq2 x, },\n    refine \u27e8(injective.factor_thru G F).to_add_monoid_hom, _\u27e9,\n    ext, convert fun_like.congr_fun (injective.comp_factor_thru G F) x,\n  end }\n\nlemma injective_as_module_of_injective_as_Ab [injective (\u27e8A\u27e9 : AddCommGroup)] :\n  injective (\u27e8A\u27e9 : Module \u2124) :=\n{ factors := \u03bb X Y g f m,\n  begin\n    resetI,\n    let G : (\u27e8X\u27e9 : AddCommGroup) \u27f6 \u27e8A\u27e9 := g.to_add_monoid_hom,\n    let F : (\u27e8X\u27e9 : AddCommGroup) \u27f6 \u27e8Y\u27e9 := f.to_add_monoid_hom,\n    haveI : mono F,\n    { rw mono_iff_injective, intros _ _ h, exact ((Module.mono_iff_injective f).mp m) h, },\n    refine \u27e8{map_smul' := _, ..injective.factor_thru G F}, _\u27e9,\n    { intros m x, rw [add_monoid_hom.to_fun_eq_coe, ring_hom.id_apply],\n      induction m using int.induction_on with n hn n hn,\n      { rw [zero_smul],\n        convert map_zero _,\n        convert zero_smul _ x, },\n      { simp only [add_smul, map_add, hn, one_smul], },\n      { simp only [sub_smul, map_sub, hn, one_smul] }, },\n    ext, convert fun_like.congr_fun (injective.comp_factor_thru G F) x,\n  end }\n\ninstance injective_of_divisible [divisible_by A \u2124] :\n  category_theory.injective (\u27e8A\u27e9 : AddCommGroup) :=\n@@injective_of_injective_as_module A _ $\n@@module.injective_object_of_injective_module \u2124 _ A _ _ $\nmodule.Baer.injective $\n\u03bb I g, begin\n  rcases is_principal_ideal_ring.principal I with \u27e8m, rfl\u27e9,\n  by_cases m_eq_zero : m = 0,\n  { subst m_eq_zero,\n    refine \u27e8{ to_fun := _, map_add' := _, map_smul' := _ }, \u03bb n hn, _\u27e9,\n    { intros n, exact g 0, },\n    { intros n1 n2,\n      simp only [map_zero, add_zero] },\n    { intros n1 n2,\n      simp only [map_zero, smul_zero], },\n    { rw [submodule.span_singleton_eq_bot.mpr rfl, submodule.mem_bot] at hn,\n      simp only [hn, map_zero],\n      symmetry,\n      convert map_zero _, }, },\n  { set g\u2098 := g \u27e8m, submodule.subset_span (set.mem_singleton _)\u27e9 with gm_eq,\n    refine \u27e8{ to_fun := _, map_add' := _, map_smul' := _ }, \u03bb n hn, _\u27e9,\n    { intros n,\n      exact n \u2022 divisible_by.div g\u2098 m, },\n    { intros n1 n2, simp only [add_smul], },\n    { intros n1 n2,\n      rw [ring_hom.id_apply, smul_eq_mul, mul_smul], },\n    { rw submodule.mem_span_singleton at hn,\n      rcases hn with \u27e8n, rfl\u27e9,\n      simp only [gm_eq, algebra.id.smul_eq_mul, linear_map.coe_mk],\n      rw [mul_smul, divisible_by.div_cancel (g \u27e8m, _\u27e9) m_eq_zero, \u2190linear_map.map_smul],\n      congr, }, },\nend\n\nend AddCommGroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/category/Group/injective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7164951783397954}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport data.fintype.basic\nimport group_theory.subgroup.basic\n\n/-!\n# Free groups\n\nThis file defines free groups over a type. Furthermore, it is shown that the free group construction\nis an instance of a monad. For the result that `free_group` is the left adjoint to the forgetful\nfunctor from groups to types, see `algebra/category/Group/adjunctions`.\n\n## Main definitions\n\n* `free_group`: the free group associated to a type `\u03b1` defined as the words over `a : \u03b1 \u00d7 bool`\n  modulo the relation `a * x * x\u207b\u00b9 * b = a * b`.\n* `free_group.mk`: the canonical quotient map `list (\u03b1 \u00d7 bool) \u2192 free_group \u03b1`.\n* `free_group.of`: the canoical injection `\u03b1 \u2192 free_group \u03b1`.\n* `free_group.lift f`: the canonical group homomorphism `free_group \u03b1 \u2192* G`\n  given a group `G` and a function `f : \u03b1 \u2192 G`.\n\n## Main statements\n\n* `free_group.church_rosser`: The Church-Rosser theorem for word reduction\n  (also known as Newman's diamond lemma).\n* `free_group.free_group_unit_equiv_int`: The free group over the one-point type\n  is isomorphic to the integers.\n* The free group construction is an instance of a monad.\n\n## Implementation details\n\nFirst we introduce the one step reduction relation `free_group.red.step`:\n`w * x * x\u207b\u00b9 * v   ~>   w * v`, its reflexive transitive closure `free_group.red.trans`\nand prove that its join is an equivalence relation. Then we introduce `free_group \u03b1` as a quotient\nover `free_group.red.step`.\n\n## Tags\n\nfree group, Newman's diamond lemma, Church-Rosser theorem\n-/\n\nopen relation\n\nuniverses u v w\n\nvariables {\u03b1 : Type u}\n\nlocal attribute [simp] list.append_eq_has_append\n\nnamespace free_group\nvariables {L L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)}\n\n/-- Reduction step: `w * x * x\u207b\u00b9 * v ~> w * v` -/\ninductive red.step : list (\u03b1 \u00d7 bool) \u2192 list (\u03b1 \u00d7 bool) \u2192 Prop\n| bnot {L\u2081 L\u2082 x b} : red.step (L\u2081 ++ (x, b) :: (x, bnot b) :: L\u2082) (L\u2081 ++ L\u2082)\nattribute [simp] red.step.bnot\n\n/-- Reflexive-transitive closure of red.step -/\ndef red : list (\u03b1 \u00d7 bool) \u2192 list (\u03b1 \u00d7 bool) \u2192 Prop := refl_trans_gen red.step\n\n@[refl] lemma red.refl : red L L := refl_trans_gen.refl\n@[trans] lemma red.trans : red L\u2081 L\u2082 \u2192 red L\u2082 L\u2083 \u2192 red L\u2081 L\u2083 := refl_trans_gen.trans\n\nnamespace red\n\n/-- Predicate asserting that word `w\u2081` can be reduced to `w\u2082` in one step, i.e. there are words\n`w\u2083 w\u2084` and letter `x` such that `w\u2081 = w\u2083xx\u207b\u00b9w\u2084` and `w\u2082 = w\u2083w\u2084`  -/\ntheorem step.length : \u2200 {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 L\u2082.length + 2 = L\u2081.length\n| _ _ (@red.step.bnot _ L1 L2 x b) := by rw [list.length_append, list.length_append]; refl\n\n@[simp] lemma step.bnot_rev {x b} : step (L\u2081 ++ (x, bnot b) :: (x, b) :: L\u2082) (L\u2081 ++ L\u2082) :=\nby cases b; from step.bnot\n\n@[simp] lemma step.cons_bnot {x b} : red.step ((x, b) :: (x, bnot b) :: L) L :=\n@step.bnot _ [] _ _ _\n\n@[simp] lemma step.cons_bnot_rev {x b} : red.step ((x, bnot b) :: (x, b) :: L) L :=\n@red.step.bnot_rev _ [] _ _ _\n\ntheorem step.append_left : \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)}, step L\u2082 L\u2083 \u2192 step (L\u2081 ++ L\u2082) (L\u2081 ++ L\u2083)\n| _ _ _ red.step.bnot := by rw [\u2190 list.append_assoc, \u2190 list.append_assoc]; constructor\n\ntheorem step.cons {x} (H : red.step L\u2081 L\u2082) : red.step (x :: L\u2081) (x :: L\u2082) :=\n@step.append_left _ [x] _ _ H\n\ntheorem step.append_right : \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 step (L\u2081 ++ L\u2083) (L\u2082 ++ L\u2083)\n| _ _ _ red.step.bnot := by simp\n\nlemma not_step_nil : \u00ac step [] L :=\nbegin\n  generalize h' : [] = L',\n  assume h,\n  cases h with L\u2081 L\u2082,\n  simp [list.nil_eq_append_iff] at h',\n  contradiction\nend\n\nlemma step.cons_left_iff {a : \u03b1} {b : bool} :\n  step ((a, b) :: L\u2081) L\u2082 \u2194 (\u2203L, step L\u2081 L \u2227 L\u2082 = (a, b) :: L) \u2228 (L\u2081 = (a, bnot b)::L\u2082) :=\nbegin\n  split,\n  { generalize hL : ((a, b) :: L\u2081 : list _) = L,\n    assume h,\n    rcases h with \u27e8_ | \u27e8p, s'\u27e9, e, a', b'\u27e9,\n    { simp at hL, simp [*] },\n    { simp at hL,\n      rcases hL with \u27e8rfl, rfl\u27e9,\n      refine or.inl \u27e8s' ++ e, step.bnot, _\u27e9,\n      simp } },\n  { assume h,\n    rcases h with \u27e8L, h, rfl\u27e9 | rfl,\n    { exact step.cons h },\n    { exact step.cons_bnot } }\nend\n\nlemma not_step_singleton : \u2200 {p : \u03b1 \u00d7 bool}, \u00ac step [p] L\n| (a, b) := by simp [step.cons_left_iff, not_step_nil]\n\nlemma step.cons_cons_iff : \u2200{p : \u03b1 \u00d7 bool}, step (p :: L\u2081) (p :: L\u2082) \u2194 step L\u2081 L\u2082 :=\nby simp [step.cons_left_iff, iff_def, or_imp_distrib] {contextual := tt}\n\nlemma step.append_left_iff : \u2200L, step (L ++ L\u2081) (L ++ L\u2082) \u2194 step L\u2081 L\u2082\n| [] := by simp\n| (p :: l) := by simp [step.append_left_iff l, step.cons_cons_iff]\n\nprivate theorem step.diamond_aux : \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)} {x1 b1 x2 b2},\n  L\u2081 ++ (x1, b1) :: (x1, bnot b1) :: L\u2082 = L\u2083 ++ (x2, b2) :: (x2, bnot b2) :: L\u2084 \u2192\n  L\u2081 ++ L\u2082 = L\u2083 ++ L\u2084 \u2228 \u2203 L\u2085, red.step (L\u2081 ++ L\u2082) L\u2085 \u2227 red.step (L\u2083 ++ L\u2084) L\u2085\n| []        _ []        _ _ _ _ _ H := by injections; subst_vars; simp\n| []        _ [(x3,b3)] _ _ _ _ _ H := by injections; subst_vars; simp\n| [(x3,b3)] _ []        _ _ _ _ _ H := by injections; subst_vars; simp\n| []                     _ ((x3,b3)::(x4,b4)::tl) _ _ _ _ _ H :=\n  by injections; subst_vars; simp; right; exact \u27e8_, red.step.bnot, red.step.cons_bnot\u27e9\n| ((x3,b3)::(x4,b4)::tl) _ []                     _ _ _ _ _ H :=\n  by injections; subst_vars; simp; right; exact \u27e8_, red.step.cons_bnot, red.step.bnot\u27e9\n| ((x3,b3)::tl) _ ((x4,b4)::tl2) _ _ _ _ _ H :=\n  let \u27e8H1, H2\u27e9 := list.cons.inj H in\n  match step.diamond_aux H2 with\n    | or.inl H3 := or.inl $ by simp [H1, H3]\n    | or.inr \u27e8L\u2085, H3, H4\u27e9 := or.inr\n      \u27e8_, step.cons H3, by simpa [H1] using step.cons H4\u27e9\n  end\n\ntheorem step.diamond : \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)},\n  red.step L\u2081 L\u2083 \u2192 red.step L\u2082 L\u2084 \u2192 L\u2081 = L\u2082 \u2192\n  L\u2083 = L\u2084 \u2228 \u2203 L\u2085, red.step L\u2083 L\u2085 \u2227 red.step L\u2084 L\u2085\n| _ _ _ _ red.step.bnot red.step.bnot H := step.diamond_aux H\n\nlemma step.to_red : step L\u2081 L\u2082 \u2192 red L\u2081 L\u2082 :=\nrefl_trans_gen.single\n\n/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces\nto `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`\nrespectively. This is also known as Newman's diamond lemma. -/\ntheorem church_rosser : red L\u2081 L\u2082 \u2192 red L\u2081 L\u2083 \u2192 join red L\u2082 L\u2083 :=\nrelation.church_rosser (assume a b c hab hac,\nmatch b, c, red.step.diamond hab hac rfl with\n| b, _, or.inl rfl           := \u27e8b, by refl, by refl\u27e9\n| b, c, or.inr \u27e8d, hbd, hcd\u27e9 := \u27e8d, refl_gen.single hbd, hcd.to_red\u27e9\nend)\n\nlemma cons_cons {p} : red L\u2081 L\u2082 \u2192 red (p :: L\u2081) (p :: L\u2082) :=\nrefl_trans_gen.lift (list.cons p) (assume a b, step.cons)\n\nlemma cons_cons_iff (p) : red (p :: L\u2081) (p :: L\u2082) \u2194 red L\u2081 L\u2082 :=\niff.intro\n  begin\n    generalize eq\u2081 : (p :: L\u2081 : list _) = LL\u2081,\n    generalize eq\u2082 : (p :: L\u2082 : list _) = LL\u2082,\n    assume h,\n    induction h using relation.refl_trans_gen.head_induction_on\n      with L\u2081 L\u2082 h\u2081\u2082 h ih\n      generalizing L\u2081 L\u2082,\n    { subst_vars, cases eq\u2082, constructor },\n    { subst_vars,\n      cases p with a b,\n      rw [step.cons_left_iff] at h\u2081\u2082,\n      rcases h\u2081\u2082 with \u27e8L, h\u2081\u2082, rfl\u27e9 | rfl,\n      { exact (ih rfl rfl).head h\u2081\u2082 },\n      { exact (cons_cons h).tail step.cons_bnot_rev } }\n  end\n  cons_cons\n\nlemma append_append_left_iff : \u2200L, red (L ++ L\u2081) (L ++ L\u2082) \u2194 red L\u2081 L\u2082\n| []       := iff.rfl\n| (p :: L) := by simp [append_append_left_iff L, cons_cons_iff]\n\nlemma append_append (h\u2081 : red L\u2081 L\u2083) (h\u2082 : red L\u2082 L\u2084) : red (L\u2081 ++ L\u2082) (L\u2083 ++ L\u2084) :=\n(h\u2081.lift (\u03bbL, L ++ L\u2082) (assume a b, step.append_right)).trans ((append_append_left_iff _).2 h\u2082)\n\nlemma to_append_iff : red L (L\u2081 ++ L\u2082) \u2194 (\u2203L\u2083 L\u2084, L = L\u2083 ++ L\u2084 \u2227 red L\u2083 L\u2081 \u2227 red L\u2084 L\u2082) :=\niff.intro\n  begin\n    generalize eq : L\u2081 ++ L\u2082 = L\u2081\u2082,\n    assume h,\n    induction h with L' L\u2081\u2082 hLL' h ih generalizing L\u2081 L\u2082,\n    { exact \u27e8_, _, eq.symm, by refl, by refl\u27e9 },\n    { cases h with s e a b,\n      rcases list.append_eq_append_iff.1 eq with \u27e8s', rfl, rfl\u27e9 | \u27e8e', rfl, rfl\u27e9,\n      { have : L\u2081 ++ (s' ++ ((a, b) :: (a, bnot b) :: e)) =\n                 (L\u2081 ++ s') ++ ((a, b) :: (a, bnot b) :: e),\n        { simp },\n        rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9,\n        exact \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082.tail step.bnot\u27e9 },\n      { have : (s ++ ((a, b) :: (a, bnot b) :: e')) ++ L\u2082 =\n                 s ++ ((a, b) :: (a, bnot b) :: (e' ++ L\u2082)),\n        { simp },\n        rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9,\n        exact \u27e8w\u2081, w\u2082, rfl, h\u2081.tail step.bnot, h\u2082\u27e9 }, }\n  end\n  (assume \u27e8L\u2083, L\u2084, eq, h\u2083, h\u2084\u27e9, eq.symm \u25b8 append_append h\u2083 h\u2084)\n\n/-- The empty word `[]` only reduces to itself. -/\ntheorem nil_iff : red [] L \u2194 L = [] :=\nrefl_trans_gen_iff_eq (assume l, red.not_step_nil)\n\n/-- A letter only reduces to itself. -/\ntheorem singleton_iff {x} : red [x] L\u2081 \u2194 L\u2081 = [x] :=\nrefl_trans_gen_iff_eq (assume l, not_step_singleton)\n\n/-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces\nto `x\u207b\u00b9` -/\ntheorem cons_nil_iff_singleton {x b} : red ((x, b) :: L) [] \u2194 red L [(x, bnot b)] :=\niff.intro\n  (assume h,\n    have h\u2081 : red ((x, bnot b) :: (x, b) :: L) [(x, bnot b)], from cons_cons h,\n    have h\u2082 : red ((x, bnot b) :: (x, b) :: L) L, from refl_trans_gen.single step.cons_bnot_rev,\n    let \u27e8L', h\u2081, h\u2082\u27e9 := church_rosser h\u2081 h\u2082 in\n    by rw [singleton_iff] at h\u2081; subst L'; assumption)\n  (assume h, (cons_cons h).tail step.cons_bnot)\n\ntheorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) \u2260 (x2, b2)) :\n  red [(x1, bnot b1), (x2, b2)] L \u2194 L = [(x1, bnot b1), (x2, b2)] :=\nbegin\n  apply refl_trans_gen_iff_eq,\n  generalize eq : [(x1, bnot b1), (x2, b2)] = L',\n  assume L h',\n  cases h',\n  simp [list.cons_eq_append_iff, list.nil_eq_append_iff] at eq,\n  rcases eq with \u27e8rfl, \u27e8rfl, rfl\u27e9, \u27e8rfl, rfl\u27e9, rfl\u27e9, subst_vars,\n  simp at h,\n  contradiction\nend\n\n/-- If `x` and `y` are distinct letters and `w\u2081 w\u2082` are words such that `xw\u2081` reduces to `yw\u2082`, then\n`w\u2081` reduces to `x\u207b\u00b9yw\u2082`. -/\ntheorem inv_of_red_of_ne {x1 b1 x2 b2}\n  (H1 : (x1, b1) \u2260 (x2, b2))\n  (H2 : red ((x1, b1) :: L\u2081) ((x2, b2) :: L\u2082)) :\n  red L\u2081 ((x1, bnot b1) :: (x2, b2) :: L\u2082) :=\nbegin\n  have : red ((x1, b1) :: L\u2081) ([(x2, b2)] ++ L\u2082), from H2,\n  rcases to_append_iff.1 this with \u27e8_ | \u27e8p, L\u2083\u27e9, L\u2084, eq, h\u2081, h\u2082\u27e9,\n  { simp [nil_iff] at h\u2081, contradiction },\n  { cases eq,\n    show red (L\u2083 ++ L\u2084) ([(x1, bnot b1), (x2, b2)] ++ L\u2082),\n    apply append_append _ h\u2082,\n    have h\u2081 : red ((x1, bnot b1) :: (x1, b1) :: L\u2083) [(x1, bnot b1), (x2, b2)],\n    { exact cons_cons h\u2081 },\n    have h\u2082 : red ((x1, bnot b1) :: (x1, b1) :: L\u2083) L\u2083,\n    { exact step.cons_bnot_rev.to_red },\n    rcases church_rosser h\u2081 h\u2082 with \u27e8L', h\u2081, h\u2082\u27e9,\n    rw [red_iff_irreducible H1] at h\u2081,\n    rwa [h\u2081] at h\u2082 }\nend\n\ntheorem step.sublist (H : red.step L\u2081 L\u2082) : L\u2082 <+ L\u2081 :=\nby cases H; simp; constructor; constructor; refl\n\n/-- If `w\u2081 w\u2082` are words such that `w\u2081` reduces to `w\u2082`, then `w\u2082` is a sublist of `w\u2081`. -/\ntheorem sublist : red L\u2081 L\u2082 \u2192 L\u2082 <+ L\u2081 :=\nrefl_trans_gen_of_transitive_reflexive\n  (\u03bbl, list.sublist.refl l) (\u03bba b c hab hbc, list.sublist.trans hbc hab) (\u03bba b, red.step.sublist)\n\ntheorem sizeof_of_step : \u2200 {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 L\u2082.sizeof < L\u2081.sizeof\n| _ _ (@step.bnot _ L1 L2 x b) :=\n  begin\n    induction L1 with hd tl ih,\n    case list.nil\n    { dsimp [list.sizeof],\n      have H : 1 + sizeof (x, b) + (1 + sizeof (x, bnot b) + list.sizeof L2)\n        = (list.sizeof L2 + 1) + (sizeof (x, b) + sizeof (x, bnot b) + 1),\n      { ac_refl },\n      rw H,\n      exact nat.le_add_right _ _ },\n    case list.cons\n    { dsimp [list.sizeof],\n      exact nat.add_lt_add_left ih _ }\n  end\n\ntheorem length (h : red L\u2081 L\u2082) : \u2203 n, L\u2081.length = L\u2082.length + 2 * n :=\nbegin\n  induction h with L\u2082 L\u2083 h\u2081\u2082 h\u2082\u2083 ih,\n  { exact \u27e80, rfl\u27e9 },\n  { rcases ih with \u27e8n, eq\u27e9,\n    existsi (1 + n),\n    simp [mul_add, eq, (step.length h\u2082\u2083).symm, add_assoc] }\nend\n\ntheorem antisymm (h\u2081\u2082 : red L\u2081 L\u2082) : red L\u2082 L\u2081 \u2192 L\u2081 = L\u2082 :=\nmatch L\u2081, h\u2081\u2082.cases_head with\n| _,  or.inl rfl            := assume h, rfl\n| L\u2081, or.inr \u27e8L\u2083, h\u2081\u2083, h\u2083\u2082\u27e9 := assume h\u2082\u2081,\n  let \u27e8n, eq\u27e9 := length (h\u2083\u2082.trans h\u2082\u2081) in\n  have list.length L\u2083 + 0 = list.length L\u2083 + (2 * n + 2),\n    by simpa [(step.length h\u2081\u2083).symm, add_comm, add_assoc] using eq,\n  (nat.no_confusion $ nat.add_left_cancel this)\nend\n\nend red\n\ntheorem equivalence_join_red : equivalence (join (@red \u03b1)) :=\nequivalence_join_refl_trans_gen $ assume a b c hab hac,\n(match b, c, red.step.diamond hab hac rfl with\n| b, _, or.inl rfl           := \u27e8b, by refl, by refl\u27e9\n| b, c, or.inr \u27e8d, hbd, hcd\u27e9 := \u27e8d, refl_gen.single hbd, refl_trans_gen.single hcd\u27e9\nend)\n\ntheorem join_red_of_step (h : red.step L\u2081 L\u2082) : join red L\u2081 L\u2082 :=\njoin_of_single reflexive_refl_trans_gen h.to_red\n\ntheorem eqv_gen_step_iff_join_red : eqv_gen red.step L\u2081 L\u2082 \u2194 join red L\u2081 L\u2082 :=\niff.intro\n  (assume h,\n    have eqv_gen (join red) L\u2081 L\u2082 := h.mono (assume a b, join_red_of_step),\n    equivalence_join_red.eqv_gen_iff.1 this)\n  (join_of_equivalence (eqv_gen.is_equivalence _) $ assume a b,\n    refl_trans_gen_of_equivalence (eqv_gen.is_equivalence _) eqv_gen.rel)\n\nend free_group\n\n/-- The free group over a type, i.e. the words formed by the elements of the type and their formal\ninverses, quotient by one step reduction. -/\ndef free_group (\u03b1 : Type u) : Type u :=\nquot $ @free_group.red.step \u03b1\n\nnamespace free_group\n\nvariables {\u03b1} {L L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)}\n\n/-- The canonical map from `list (\u03b1 \u00d7 bool)` to the free group on `\u03b1`. -/\ndef mk (L) : free_group \u03b1 := quot.mk red.step L\n\n@[simp] lemma quot_mk_eq_mk : quot.mk red.step L = mk L := rfl\n\n@[simp] lemma quot_lift_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 \u03b2)\n  (H : \u2200 L\u2081 L\u2082, red.step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) :\nquot.lift f H (mk L) = f L := rfl\n\n@[simp] lemma quot_lift_on_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 \u03b2)\n  (H : \u2200 L\u2081 L\u2082, red.step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) :\nquot.lift_on (mk L) f H = f L := rfl\n\n@[simp] lemma quot_map_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 list (\u03b2 \u00d7 bool))\n  (H : (red.step \u21d2 red.step) f f) :\nquot.map f H (mk L) = mk (f L) := rfl\n\ninstance : has_one (free_group \u03b1) := \u27e8mk []\u27e9\nlemma one_eq_mk : (1 : free_group \u03b1) = mk [] := rfl\n\ninstance : inhabited (free_group \u03b1) := \u27e81\u27e9\n\ninstance : has_mul (free_group \u03b1) :=\n\u27e8\u03bb x y, quot.lift_on x\n    (\u03bb L\u2081, quot.lift_on y (\u03bb L\u2082, mk $ L\u2081 ++ L\u2082) (\u03bb L\u2082 L\u2083 H, quot.sound $ red.step.append_left H))\n    (\u03bb L\u2081 L\u2082 H, quot.induction_on y $ \u03bb L\u2083, quot.sound $ red.step.append_right H)\u27e9\n@[simp] lemma mul_mk : mk L\u2081 * mk L\u2082 = mk (L\u2081 ++ L\u2082) := rfl\n\ninstance : has_inv (free_group \u03b1) :=\n\u27e8\u03bbx, quot.lift_on x (\u03bb L, mk (L.map $ \u03bb x : \u03b1 \u00d7 bool, (x.1, bnot x.2)).reverse)\n  (assume a b h, quot.sound $ by cases h; simp)\u27e9\n@[simp] lemma inv_mk : (mk L)\u207b\u00b9 = mk (L.map $ \u03bb x : \u03b1 \u00d7 bool, (x.1, bnot x.2)).reverse := rfl\n\ninstance : group (free_group \u03b1) :=\n{ mul := (*),\n  one := 1,\n  inv := has_inv.inv,\n  mul_assoc := by rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9 \u27e8L\u2083\u27e9; simp,\n  one_mul := by rintros \u27e8L\u27e9; refl,\n  mul_one := by rintros \u27e8L\u27e9; simp [one_eq_mk],\n  mul_left_inv := by rintros \u27e8L\u27e9; exact (list.rec_on L rfl $\n    \u03bb \u27e8x, b\u27e9 tl ih, eq.trans (quot.sound $ by simp [one_eq_mk]) ih) }\n\n/-- `of` is the canonical injection from the type to the free group over that type by sending each\nelement to the equivalence class of the letter that is the element. -/\ndef of (x : \u03b1) : free_group \u03b1 :=\nmk [(x, tt)]\n\ntheorem red.exact : mk L\u2081 = mk L\u2082 \u2194 join red L\u2081 L\u2082 :=\ncalc (mk L\u2081 = mk L\u2082) \u2194 eqv_gen red.step L\u2081 L\u2082 : iff.intro (quot.exact _) quot.eqv_gen_sound\n  ... \u2194 join red L\u2081 L\u2082 : eqv_gen_step_iff_join_red\n\n/-- The canonical injection from the type to the free group is an injection. -/\ntheorem of_injective : function.injective (@of \u03b1) :=\n\u03bb _ _ H, let \u27e8L\u2081, hx, hy\u27e9 := red.exact.1 H in\n  by simp [red.singleton_iff] at hx hy; cc\n\nsection lift\n\nvariables {\u03b2 : Type v} [group \u03b2] (f : \u03b1 \u2192 \u03b2) {x y : free_group \u03b1}\n\n/-- Given `f : \u03b1 \u2192 \u03b2` with `\u03b2` a group, the canonical map `list (\u03b1 \u00d7 bool) \u2192 \u03b2` -/\ndef lift.aux : list (\u03b1 \u00d7 bool) \u2192 \u03b2 :=\n\u03bb L, list.prod $ L.map $ \u03bb x, cond x.2 (f x.1) (f x.1)\u207b\u00b9\n\ntheorem red.step.lift {f : \u03b1 \u2192 \u03b2} (H : red.step L\u2081 L\u2082) :\n  lift.aux f L\u2081 = lift.aux f L\u2082 :=\nby cases H with _ _ _ b; cases b; simp [lift.aux]\n\n\n/-- If `\u03b2` is a group, then any function from `\u03b1` to `\u03b2`\nextends uniquely to a group homomorphism from\nthe free group over `\u03b1` to `\u03b2` -/\n@[simps symm_apply]\ndef lift : (\u03b1 \u2192 \u03b2) \u2243 (free_group \u03b1 \u2192* \u03b2) :=\n{ to_fun := \u03bb f,\n    monoid_hom.mk' (quot.lift (lift.aux f) $ \u03bb L\u2081 L\u2082, red.step.lift) $ begin\n      rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9, simp [lift.aux],\n    end,\n  inv_fun := \u03bb g, g \u2218 of,\n  left_inv := \u03bb f, one_mul _,\n  right_inv := \u03bb g, monoid_hom.ext $ begin\n    rintros \u27e8L\u27e9,\n    apply list.rec_on L,\n    { exact g.map_one.symm, },\n    { rintros \u27e8x, _ | _\u27e9 t (ih : _ = g (mk t)),\n      { show _ = g ((of x)\u207b\u00b9 * mk t),\n        simpa [lift.aux] using ih },\n      { show _ = g (of x * mk t),\n        simpa [lift.aux] using ih }, },\n  end }\nvariable {f}\n\n@[simp] lemma lift.mk : lift f (mk L) =\n  list.prod (L.map $ \u03bb x, cond x.2 (f x.1) (f x.1)\u207b\u00b9) :=\nrfl\n\n@[simp] lemma lift.of {x} : lift f (of x) = f x :=\none_mul _\n\ntheorem lift.unique (g : free_group \u03b1 \u2192* \u03b2)\n  (hg : \u2200 x, g (of x) = f x) : \u2200{x}, g x = lift f x :=\nmonoid_hom.congr_fun $ (lift.symm_apply_eq).mp (funext hg : g \u2218 of = f)\n\n/-- Two homomorphisms out of a free group are equal if they are equal on generators.\n\nSee note [partially-applied ext lemmas]. -/\n@[ext]\nlemma ext_hom {G : Type*} [group G] (f g : free_group \u03b1 \u2192* G) (h : \u2200 a, f (of a) = g (of a)) :\n  f = g :=\nlift.symm.injective $ funext h\n\ntheorem lift.of_eq (x : free_group \u03b1) : lift of x = x :=\nmonoid_hom.congr_fun (lift.apply_symm_apply (monoid_hom.id _)) x\n\ntheorem lift.range_subset {s : subgroup \u03b2} (H : set.range f \u2286 s) :\n  set.range (lift f) \u2286 s :=\nby rintros _ \u27e8\u27e8L\u27e9, rfl\u27e9; exact list.rec_on L s.one_mem\n(\u03bb \u27e8x, b\u27e9 tl ih, bool.rec_on b\n    (by simp at ih \u22a2; from s.mul_mem\n      (s.inv_mem $ H \u27e8x, rfl\u27e9) ih)\n    (by simp at ih \u22a2; from s.mul_mem (H \u27e8x, rfl\u27e9) ih))\n\ntheorem closure_subset {G : Type*} [group G] {s : set G} {t : subgroup G}\n  (h : s \u2286 t) : subgroup.closure s \u2264 t :=\nbegin\n  simp only [h, subgroup.closure_le],\nend\n\ntheorem lift.range_eq_closure :\n  set.range (lift f) = subgroup.closure (set.range f) :=\nset.subset.antisymm\n  (lift.range_subset subgroup.subset_closure)\n  begin\n    suffices : (subgroup.closure (set.range f)) \u2264 monoid_hom.range (lift f),\n      simpa,\n    rw subgroup.closure_le,\n    rintros y \u27e8x, hx\u27e9,\n    exact \u27e8of x, by simpa\u27e9\n  end\n\nend lift\n\nsection map\n\nvariables {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) {x y : free_group \u03b1}\n\n/-- Any function from `\u03b1` to `\u03b2` extends uniquely\nto a group homomorphism from the free group\nver `\u03b1` to the free group over `\u03b2`. -/\ndef map : free_group \u03b1 \u2192* free_group \u03b2 :=\nmonoid_hom.mk'\n  (quot.map (list.map $ \u03bb x, (f x.1, x.2)) $ \u03bb L\u2081 L\u2082 H, by cases H; simp)\n  (by { rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9, simp })\n\nvariable {f}\n\n@[simp] lemma map.mk : map f (mk L) = mk (L.map (\u03bb x, (f x.1, x.2))) :=\nrfl\n\n@[simp] lemma map.id (x : free_group \u03b1) : map id x = x :=\nby rcases x with \u27e8L\u27e9; simp [list.map_id']\n\n@[simp] lemma map.id' (x : free_group \u03b1) : map (\u03bb z, z) x = x := map.id x\n\ntheorem map.comp {\u03b3 : Type w} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3) (x) :\n  map g (map f x) = map (g \u2218 f) x :=\nby rcases x with \u27e8L\u27e9; simp\n\n@[simp] lemma map.of {x} : map f (of x) = of (f x) := rfl\n\ntheorem map.unique (g : free_group \u03b1 \u2192* free_group \u03b2)\n  (hg : \u2200 x, g (of x) = of (f x)) : \u2200{x}, g x = map f x :=\nby rintros \u27e8L\u27e9; exact list.rec_on L g.map_one\n(\u03bb \u27e8x, b\u27e9 t (ih : g (mk t) = map f (mk t)), bool.rec_on b\n  (show g ((of x)\u207b\u00b9 * mk t) = map f ((of x)\u207b\u00b9 * mk t),\n     by simp [g.map_mul, g.map_inv, hg, ih])\n  (show g (of x * mk t) = map f (of x * mk t),\n     by simp [g.map_mul, hg, ih]))\n\ntheorem map_eq_lift : map f x = lift (of \u2218 f) x :=\neq.symm $ map.unique _ $ \u03bb x, by simp\n\n/-- Equivalent types give rise to multiplicatively equivalent free groups.\n\nThe converse can be found in `group_theory.free_abelian_group_finsupp`,\nas `equiv.of_free_group_equiv`\n -/\n@[simps apply]\ndef free_group_congr {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) : free_group \u03b1 \u2243* free_group \u03b2 :=\n{ to_fun := map e, inv_fun := map e.symm,\n  left_inv := \u03bb x, by simp [function.comp, map.comp],\n  right_inv := \u03bb x, by simp [function.comp, map.comp],\n  map_mul' := monoid_hom.map_mul _ }\n\n@[simp] lemma free_group_congr_refl : free_group_congr (equiv.refl \u03b1) = mul_equiv.refl _ :=\nmul_equiv.ext map.id\n\n@[simp] lemma free_group_congr_symm {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) :\n  (free_group_congr e).symm = free_group_congr e.symm :=\nrfl\n\nlemma free_group_congr_trans {\u03b1 \u03b2 \u03b3} (e : \u03b1 \u2243 \u03b2) (f : \u03b2 \u2243 \u03b3) :\n  (free_group_congr e).trans (free_group_congr f) = free_group_congr (e.trans f) :=\nmul_equiv.ext $ map.comp _ _\n\nend map\n\nsection prod\n\nvariables [group \u03b1] (x y : free_group \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1`\nextends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the multiplicative\nversion of `sum`. -/\ndef prod : free_group \u03b1 \u2192* \u03b1 := lift id\n\nvariables {x y}\n\n@[simp] lemma prod_mk :\n  prod (mk L) = list.prod (L.map $ \u03bb x, cond x.2 x.1 x.1\u207b\u00b9) :=\nrfl\n\n@[simp] lemma prod.of {x : \u03b1} : prod (of x) = x :=\nlift.of\n\nlemma prod.unique (g : free_group \u03b1 \u2192* \u03b1)\n  (hg : \u2200 x, g (of x) = x) {x} :\n  g x = prod x :=\nlift.unique g hg\n\nend prod\n\ntheorem lift_eq_prod_map {\u03b2 : Type v} [group \u03b2] {f : \u03b1 \u2192 \u03b2} {x} :\n  lift f x = prod (map f x) :=\nbegin\n  rw \u2190lift.unique (prod.comp (map f)),\n  { refl },\n  { simp }\nend\n\nsection sum\n\nvariables [add_group \u03b1] (x y : free_group \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1`\nextends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the additive\nversion of `prod`. -/\ndef sum : \u03b1 :=\n@prod (multiplicative _) _ x\n\nvariables {x y}\n\n@[simp] lemma sum_mk :\n  sum (mk L) = list.sum (L.map $ \u03bb x, cond x.2 x.1 (-x.1)) :=\nrfl\n\n@[simp] lemma sum.of {x : \u03b1} : sum (of x) = x :=\nprod.of\n\n-- note: there are no bundled homs with different notation in the domain and codomain, so we copy\n-- these manually\n@[simp] lemma sum.map_mul : sum (x * y) = sum x + sum y :=\n(@prod (multiplicative _) _).map_mul _ _\n\n@[simp] lemma sum.map_one : sum (1:free_group \u03b1) = 0 :=\n(@prod (multiplicative _) _).map_one\n\n@[simp] lemma sum.map_inv : sum x\u207b\u00b9 = -sum x :=\n(@prod (multiplicative _) _).map_inv _\n\nend sum\n\n/-- The bijection between the free group on the empty type, and a type with one element. -/\ndef free_group_empty_equiv_unit : free_group empty \u2243 unit :=\n{ to_fun    := \u03bb _, (),\n  inv_fun   := \u03bb _, 1,\n  left_inv  := by rintros \u27e8_ | \u27e8\u27e8\u27e8\u27e9, _\u27e9, _\u27e9\u27e9; refl,\n  right_inv := \u03bb \u27e8\u27e9, rfl }\n\n/-- The bijection between the free group on a singleton, and the integers. -/\ndef free_group_unit_equiv_int : free_group unit \u2243 \u2124 :=\n{ to_fun    := \u03bb x,\n   sum begin revert x, apply monoid_hom.to_fun,\n    apply map (\u03bb _, (1 : \u2124)),\n  end,\n  inv_fun   := \u03bb x, of () ^ x,\n  left_inv  :=\n  begin\n    rintros \u27e8L\u27e9,\n    refine list.rec_on L rfl _,\n    exact (\u03bb \u27e8\u27e8\u27e9, b\u27e9 tl ih, by cases b; simp [zpow_add] at ih \u22a2; rw ih; refl),\n  end,\n  right_inv :=\n    \u03bb x, int.induction_on x (by simp)\n    (\u03bb i ih, by simp at ih; simp [zpow_add, ih])\n    (\u03bb i ih, by simp at ih; simp [zpow_add, ih, sub_eq_add_neg, -int.add_neg_one]) }\n\nsection category\n\nvariables {\u03b2 : Type u}\n\ninstance : monad free_group.{u} :=\n{ pure := \u03bb \u03b1, of,\n  map := \u03bb \u03b1 \u03b2 f, (map f),\n  bind := \u03bb \u03b1 \u03b2 x f, lift f x }\n\n@[elab_as_eliminator]\nprotected theorem induction_on\n  {C : free_group \u03b1 \u2192 Prop}\n  (z : free_group \u03b1)\n  (C1 : C 1)\n  (Cp : \u2200 x, C $ pure x)\n  (Ci : \u2200 x, C (pure x) \u2192 C (pure x)\u207b\u00b9)\n  (Cm : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) : C z :=\nquot.induction_on z $ \u03bb L, list.rec_on L C1 $ \u03bb \u27e8x, b\u27e9 tl ih,\nbool.rec_on b (Cm _ _ (Ci _ $ Cp x) ih) (Cm _ _ (Cp x) ih)\n\n@[simp] lemma map_pure (f : \u03b1 \u2192 \u03b2) (x : \u03b1) : f <$> (pure x : free_group \u03b1) = pure (f x) :=\nmap.of\n\n@[simp] lemma map_one (f : \u03b1 \u2192 \u03b2) : f <$> (1 : free_group \u03b1) = 1 :=\n(map f).map_one\n\n@[simp] lemma map_mul (f : \u03b1 \u2192 \u03b2) (x y : free_group \u03b1) : f <$> (x * y) = f <$> x * f <$> y :=\n(map f).map_mul x y\n\n@[simp] lemma map_inv (f : \u03b1 \u2192 \u03b2) (x : free_group \u03b1) : f <$> (x\u207b\u00b9) = (f <$> x)\u207b\u00b9 :=\n(map f).map_inv x\n\n@[simp] lemma pure_bind (f : \u03b1 \u2192 free_group \u03b2) (x) : pure x >>= f = f x :=\nlift.of\n\n@[simp] lemma one_bind (f : \u03b1 \u2192 free_group \u03b2) : 1 >>= f = 1 :=\n(lift f).map_one\n\n@[simp] lemma mul_bind (f : \u03b1 \u2192 free_group \u03b2) (x y : free_group \u03b1) :\n  x * y >>= f = (x >>= f) * (y >>= f) :=\n(lift f).map_mul _ _\n\n@[simp] lemma inv_bind (f : \u03b1 \u2192 free_group \u03b2) (x : free_group \u03b1) : x\u207b\u00b9 >>= f = (x >>= f)\u207b\u00b9 :=\n(lift f).map_inv _\n\ninstance : is_lawful_monad free_group.{u} :=\n{ id_map := \u03bb \u03b1 x, free_group.induction_on x (map_one id) (\u03bb x, map_pure id x)\n    (\u03bb x ih, by rw [map_inv, ih]) (\u03bb x y ihx ihy, by rw [map_mul, ihx, ihy]),\n  pure_bind := \u03bb \u03b1 \u03b2 x f, pure_bind f x,\n  bind_assoc := \u03bb \u03b1 \u03b2 \u03b3 x f g, free_group.induction_on x\n    (by iterate 3 { rw one_bind }) (\u03bb x, by iterate 2 { rw pure_bind })\n    (\u03bb x ih, by iterate 3 { rw inv_bind }; rw ih)\n    (\u03bb x y ihx ihy, by iterate 3 { rw mul_bind }; rw [ihx, ihy]),\n  bind_pure_comp_eq_map := \u03bb \u03b1 \u03b2 f x, free_group.induction_on x\n    (by rw [one_bind, map_one]) (\u03bb x, by rw [pure_bind, map_pure])\n    (\u03bb x ih, by rw [inv_bind, map_inv, ih]) (\u03bb x y ihx ihy, by rw [mul_bind, map_mul, ihx, ihy]) }\n\nend category\n\nsection reduce\n\nvariable [decidable_eq \u03b1]\n\n/-- The maximal reduction of a word. It is computable\niff `\u03b1` has decidable equality. -/\ndef reduce (L : list (\u03b1 \u00d7 bool)) : list (\u03b1 \u00d7 bool) :=\nlist.rec_on L [] $ \u03bb hd1 tl1 ih,\nlist.cases_on ih [hd1] $ \u03bb hd2 tl2,\nif hd1.1 = hd2.1 \u2227 hd1.2 = bnot hd2.2 then tl2\nelse hd1 :: hd2 :: tl2\n\n@[simp] lemma reduce.cons (x) : reduce (x :: L) =\n  list.cases_on (reduce L) [x] (\u03bb hd tl,\n  if x.1 = hd.1 \u2227 x.2 = bnot hd.2 then tl\n  else x :: hd :: tl) := rfl\n\n/-- The first theorem that characterises the function\n`reduce`: a word reduces to its maximal reduction. -/\ntheorem reduce.red : red L (reduce L) :=\nbegin\n  induction L with hd1 tl1 ih,\n  case list.nil\n  { constructor },\n  case list.cons\n  { dsimp,\n    revert ih,\n    generalize htl : reduce tl1 = TL,\n    intro ih,\n    cases TL with hd2 tl2,\n    case list.nil\n    { exact red.cons_cons ih },\n    case list.cons\n    { dsimp,\n      by_cases h : hd1.fst = hd2.fst \u2227 hd1.snd = bnot (hd2.snd),\n      { rw [if_pos h],\n        transitivity,\n        { exact red.cons_cons ih },\n        { cases hd1, cases hd2, cases h,\n          dsimp at *, subst_vars,\n          exact red.step.cons_bnot_rev.to_red } },\n      { rw [if_neg h],\n        exact red.cons_cons ih } } }\nend\n\ntheorem reduce.not {p : Prop} :\n  \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)} {x b}, reduce L\u2081 = L\u2082 ++ (x, b) :: (x, bnot b) :: L\u2083 \u2192 p\n| [] L2 L3 _ _ := \u03bb h, by cases L2; injections\n| ((x,b)::L1) L2 L3 x' b' := begin\n  dsimp,\n  cases r : reduce L1,\n  { dsimp, intro h,\n    have := congr_arg list.length h,\n    simp [-add_comm] at this,\n    exact absurd this dec_trivial },\n  cases hd with y c,\n  by_cases x = y \u2227 b = bnot c; simp [h]; intro H,\n  { rw H at r,\n    exact @reduce.not L1 ((y,c)::L2) L3 x' b' r },\n  rcases L2 with _|\u27e8a, L2\u27e9,\n  { injections, subst_vars,\n    simp at h, cc },\n  { refine @reduce.not L1 L2 L3 x' b' _,\n    injection H with _ H,\n    rw [r, H], refl }\nend\n\n/-- The second theorem that characterises the\nfunction `reduce`: the maximal reduction of a word\nonly reduces to itself. -/\ntheorem reduce.min (H : red (reduce L\u2081) L\u2082) : reduce L\u2081 = L\u2082 :=\nbegin\n  induction H with L1 L' L2 H1 H2 ih,\n  { refl },\n  { cases H1 with L4 L5 x b,\n    exact reduce.not H2 }\nend\n\n/-- `reduce` is idempotent, i.e. the maximal reduction\nof the maximal reduction of a word is the maximal\nreduction of the word. -/\ntheorem reduce.idem : reduce (reduce L) = reduce L :=\neq.symm $ reduce.min reduce.red\n\ntheorem reduce.step.eq (H : red.step L\u2081 L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, HR13, HR23\u27e9 := red.church_rosser reduce.red (reduce.red.head H) in\n(reduce.min HR13).trans (reduce.min HR23).symm\n\n/-- If a word reduces to another word, then they have\na common maximal reduction. -/\ntheorem reduce.eq_of_red (H : red L\u2081 L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, HR13, HR23\u27e9 := red.church_rosser reduce.red (red.trans H reduce.red) in\n(reduce.min HR13).trans (reduce.min HR23).symm\n\n/-- If two words correspond to the same element in\nthe free group, then they have a common maximal\nreduction. This is the proof that the function that\nsends an element of the free group to its maximal\nreduction is well-defined. -/\ntheorem reduce.sound (H : mk L\u2081 = mk L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, H13, H23\u27e9 := red.exact.1 H in\n(reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm\n\n/-- If two words have a common maximal reduction,\nthen they correspond to the same element in the free group. -/\ntheorem reduce.exact (H : reduce L\u2081 = reduce L\u2082) : mk L\u2081 = mk L\u2082 :=\nred.exact.2 \u27e8reduce L\u2082, H \u25b8 reduce.red, reduce.red\u27e9\n\n/-- A word and its maximal reduction correspond to\nthe same element of the free group. -/\ntheorem reduce.self : mk (reduce L) = mk L :=\nreduce.exact reduce.idem\n\n/-- If words `w\u2081 w\u2082` are such that `w\u2081` reduces to `w\u2082`,\nthen `w\u2082` reduces to the maximal reduction of `w\u2081`. -/\ntheorem reduce.rev (H : red L\u2081 L\u2082) : red L\u2082 (reduce L\u2081) :=\n(reduce.eq_of_red H).symm \u25b8 reduce.red\n\n/-- The function that sends an element of the free\ngroup to its maximal reduction. -/\ndef to_word : free_group \u03b1 \u2192 list (\u03b1 \u00d7 bool) :=\nquot.lift reduce $ \u03bb L\u2081 L\u2082 H, reduce.step.eq H\n\nlemma to_word.mk : \u2200{x : free_group \u03b1}, mk (to_word x) = x :=\nby rintros \u27e8L\u27e9; exact reduce.self\n\nlemma to_word.inj : \u2200(x y : free_group \u03b1), to_word x = to_word y \u2192 x = y :=\nby rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9; exact reduce.exact\n\n/-- Constructive Church-Rosser theorem (compare `church_rosser`). -/\ndef reduce.church_rosser (H12 : red L\u2081 L\u2082) (H13 : red L\u2081 L\u2083) :\n  { L\u2084 // red L\u2082 L\u2084 \u2227 red L\u2083 L\u2084 } :=\n\u27e8reduce L\u2081, reduce.rev H12, reduce.rev H13\u27e9\n\ninstance : decidable_eq (free_group \u03b1) :=\nfunction.injective.decidable_eq to_word.inj\n\ninstance red.decidable_rel : decidable_rel (@red \u03b1)\n| [] []          := is_true red.refl\n| [] (hd2::tl2)  := is_false $ \u03bb H, list.no_confusion (red.nil_iff.1 H)\n| ((x,b)::tl) [] := match red.decidable_rel tl [(x, bnot b)] with\n  | is_true H  := is_true $ red.trans (red.cons_cons H) $\n    (@red.step.bnot _ [] [] _ _).to_red\n  | is_false H := is_false $ \u03bb H2, H $ red.cons_nil_iff_singleton.1 H2\n  end\n| ((x1,b1)::tl1) ((x2,b2)::tl2) := if h : (x1, b1) = (x2, b2)\n  then match red.decidable_rel tl1 tl2 with\n    | is_true H  := is_true $ h \u25b8 red.cons_cons H\n    | is_false H := is_false $ \u03bb H2, H $ h \u25b8 (red.cons_cons_iff _).1 $ H2\n    end\n  else match red.decidable_rel tl1 ((x1,bnot b1)::(x2,b2)::tl2) with\n    | is_true H  := is_true $ (red.cons_cons H).tail red.step.cons_bnot\n    | is_false H := is_false $ \u03bb H2, H $ red.inv_of_red_of_ne h H2\n    end\n\n/-- A list containing every word that `w\u2081` reduces to. -/\ndef red.enum (L\u2081 : list (\u03b1 \u00d7 bool)) : list (list (\u03b1 \u00d7 bool)) :=\nlist.filter (\u03bb L\u2082, red L\u2081 L\u2082) (list.sublists L\u2081)\n\ntheorem red.enum.sound (H : L\u2082 \u2208 red.enum L\u2081) : red L\u2081 L\u2082 :=\nlist.of_mem_filter H\n\ntheorem red.enum.complete (H : red L\u2081 L\u2082) : L\u2082 \u2208 red.enum L\u2081 :=\nlist.mem_filter_of_mem (list.mem_sublists.2 $ red.sublist H) H\n\ninstance : fintype { L\u2082 // red L\u2081 L\u2082 } :=\nfintype.subtype (list.to_finset $ red.enum L\u2081) $\n\u03bb L\u2082, \u27e8\u03bb H, red.enum.sound $ list.mem_to_finset.1 H,\n  \u03bb H, list.mem_to_finset.2 $ red.enum.complete H\u27e9\n\nend reduce\n\nend free_group\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/group_theory/free_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.716450771551744}}
{"text": "/-\nCopyright (c) 2022 Peter Nelson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Peter Nelson\n-/\nimport order.antichain\n\n/-!\n# Orders with involution\n\nThis file concerns orders that admit an order-reversing involution. In the case of a lattice,\nthese are sometimes referred to as 'i-lattices' or 'lattices with involution'. Such an involution\nis more general than a `boolean_algebra` complement, but retains many of its properties. Other than\na boolean algebra, an example is the subspace lattice of the vector space `\ud835\udd42\u207f` for `\ud835\udd42` of nonzero\ncharacteristic, where for each subspace `W` we have `invo W = {x \u2208 V | \u2200 w \u2208 W, w\u1d40x = 0}`; this is\nnot a complement in the stronger sense because `invo W` can intersect `W`.\n\n## Main declarations\n\n* `has_involution`: typeclass applying to types with a `preorder` that admit an antitone involution.\n\n* `\u2071` : postfix notation for the function `invo : \u03b1 \u2192 \u03b1` given a type `\u03b1` with `[has_involution \u03b1]`\n\n## TODO\n\nProvide instances other than the one from `boolean_algebra`.\n-/\n\nuniverse u\n\nclass has_involution (\u03b1 : Type u) [preorder \u03b1]  :=\n(invo : \u03b1 \u2192 \u03b1)\n(invo_antitone' : \u2200 (x y : \u03b1), x \u2264 y \u2192 invo y \u2264 invo x)\n(invo_involutive' : function.involutive invo)\n\nopen has_involution\n\nvariables {\u03b1 : Type u}\n\npostfix `\u2071`:(max+1) := invo\n\nsection preorder\n\nvariables [preorder \u03b1] [has_involution \u03b1] {x y : \u03b1}\n\n@[simp] lemma invo_invo (x : \u03b1) : x\u2071\u2071 = x :=  invo_involutive' x\n\nlemma invo_eq_iff_invo_eq : x\u2071 = y \u2194 y\u2071 = x :=\nby {rw [eq_comm], exact invo_involutive'.eq_iff.symm}\n\nlemma eq_invo_iff_eq_invo : x = y\u2071 \u2194 y = x\u2071 :=\nby rw [\u2190 invo_invo x, invo_eq_iff_invo_eq, invo_invo, invo_invo]\n\nlemma invo_le_invo (hxy : x \u2264 y) : y\u2071 \u2264 x\u2071 := invo_antitone' _ _ hxy\n\nlemma le_of_invo_le (hx : x\u2071 \u2264 y\u2071) : y \u2264 x :=\nby {rw [\u2190invo_invo x, \u2190invo_invo y], exact invo_le_invo hx,}\n\nlemma invo_le_invo_iff_le : x\u2071 \u2264 y\u2071 \u2194 y \u2264 x := \u27e8le_of_invo_le, invo_le_invo\u27e9\n\nlemma le_invo_iff_le_invo : x \u2264 y\u2071 \u2194 y \u2264 x\u2071 := by rw [\u2190invo_le_invo_iff_le, invo_invo]\n\nlemma invo_le_iff_invo_le : x\u2071 \u2264 y \u2194 y\u2071 \u2264 x := by rw [\u2190invo_le_invo_iff_le, invo_invo]\n\nlemma invo_inj (h : x\u2071 = y\u2071) : x = y := invo_involutive'.injective h\n\nlemma invo_lt_invo_iff_lt : x\u2071 < y\u2071 \u2194 y < x := by simp [lt_iff_le_not_le, invo_le_invo_iff_le]\n\nlemma lt_invo_iff_lt_invo : x < y\u2071 \u2194 y < x\u2071 := by rw [\u2190invo_lt_invo_iff_lt, invo_invo]\n\nlemma invo_lt_iff_invo_lt : x\u2071 < y \u2194 y\u2071 < x := by rw [\u2190invo_lt_invo_iff_lt, invo_invo]\n\nlemma le_invo_of_le_invo (h : y \u2264 x\u2071) : x \u2264 y\u2071 := le_invo_iff_le_invo.mp h\n\nlemma invo_le_of_invo_le (h : y\u2071 \u2264 x) : x\u2071 \u2264 y := invo_le_iff_invo_le.mp h\n\nlemma invo_involutive : function.involutive (has_involution.invo : \u03b1 \u2192 \u03b1) := invo_invo\n\nlemma invo_bijective : function.bijective (invo : \u03b1 \u2192 \u03b1) := invo_involutive.bijective\n\nlemma invo_surjective : function.surjective (invo : \u03b1 \u2192 \u03b1) := invo_involutive.surjective\n\nlemma invo_injective : function.injective (invo : \u03b1 \u2192 \u03b1) := invo_involutive.injective\n\nlemma invo_antitone : antitone (invo: \u03b1 \u2192 \u03b1) := \u03bb a b, invo_le_invo\n\n@[simp] lemma invo_inj_iff : x\u2071 = y\u2071 \u2194 x = y := invo_injective.eq_iff\n\nlemma invo_comp_invo : invo \u2218 invo = @id \u03b1 := funext invo_invo\n\nend preorder\n\nsection lattice\n\nvariables [lattice \u03b1] [has_involution \u03b1]\n\n@[simp] lemma invo_inf (x y : \u03b1) : (x \u2293 y)\u2071 = x\u2071 \u2294 y\u2071 :=\nle_antisymm (invo_le_iff_invo_le.mpr (le_inf (invo_le_iff_invo_le.mp le_sup_left)\n    ((invo_le_iff_invo_le.mp le_sup_right))))\n      (sup_le (invo_le_invo inf_le_left) (invo_le_invo inf_le_right))\n\n@[simp] lemma invo_sup (x y : \u03b1) : (x \u2294 y)\u2071 = x\u2071 \u2293 y\u2071 :=\nby rw [invo_eq_iff_invo_eq, invo_inf, invo_invo, invo_invo]\n\nend lattice\n\nsection boolean_algebra\n\n@[priority 100]\ninstance boolean_algebra.to_has_involution [boolean_algebra \u03b1] : has_involution \u03b1 :=\n{ invo := compl,\n  invo_antitone' := \u03bb _ _, compl_le_compl,\n  invo_involutive' := compl_involutive }\n\nend boolean_algebra\n\nsection hom\n\nvariables (\u03b1) [preorder \u03b1] [has_involution \u03b1]\n\ninstance order_dual.has_involution : has_involution \u03b1\u1d52\u1d48 :=\n{ invo := \u03bb x, order_dual.to_dual (order_dual.of_dual x)\u2071,\n  invo_antitone' := \u03bb a b h, @invo_antitone' \u03b1 _ _ b a h,\n  invo_involutive' := invo_involutive' }\n\n/-- Taking the involution as an order isomorphism to the order dual. -/\n@[simps]\ndef order_iso.invo : \u03b1 \u2243o \u03b1\u1d52\u1d48 :=\n{ to_fun := order_dual.to_dual \u2218 invo,\n  inv_fun := invo \u2218 order_dual.of_dual,\n  left_inv := invo_invo,\n  right_inv := invo_invo,\n  map_rel_iff' := \u03bb _ _, invo_le_invo_iff_le }\n\nlemma invo_strict_anti : strict_anti (invo : \u03b1 \u2192 \u03b1) := (order_iso.invo \u03b1).strict_mono\n\nend hom\n\nsection antichain\n\nvariables [preorder \u03b1] [has_involution \u03b1] {s : set \u03b1}\n\nlemma is_antichain.image_invo (hs : is_antichain (\u2264) s) :\n  is_antichain (\u2264) (invo '' s) :=\n(hs.image_embedding (order_iso.invo \u03b1).to_order_embedding).flip\n\nlemma is_antichain.preimage_invo (hs : is_antichain (\u2264) s) :\n  is_antichain (\u2264) (invo \u207b\u00b9' s) :=\n\u03bb a ha a' ha' hne hle, hs ha' ha (\u03bb h, hne (invo_inj_iff.mp h.symm)) (invo_le_invo hle)\n\nend antichain\n", "meta": {"author": "apnelson1", "repo": "matroids", "sha": "8068a4d03b9c39a8fe0cc8871ae571890f7ad489", "save_path": "github-repos/lean/apnelson1-matroids", "path": "github-repos/lean/apnelson1-matroids/matroids-8068a4d03b9c39a8fe0cc8871ae571890f7ad489/src/old/has_involution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7164507691866573}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_69\n  (r s : \u2115+)\n  (h\u2080 : \u2191r * \u2191s = (450:\u2124))\n  (h\u2081 : (\u2191r + 5) * (\u2191s - 3) = (450:\u2124)) :\n  r = 25 :=\nbegin\n  apply subtype.ext,\n  norm_num [add_mul] at *,\n  nlinarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p69.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894717137997, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7164507671774979}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport order.complete_boolean_algebra\nimport order.directed\nimport order.galois_connection\n\n/-!\n# The set lattice\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides usual set notation for unions and intersections, a `complete_lattice` instance\nfor `set \u03b1`, and some more set constructions.\n\n## Main declarations\n\n* `set.Union`: Union of an indexed family of sets.\n* `set.Inter`: Intersection of an indexed family of sets.\n* `set.sInter`: **s**et **Inter**. Intersection of sets belonging to a set of sets.\n* `set.sUnion`: **s**et **Union**. Union of sets belonging to a set of sets. This is actually\n  defined in core Lean.\n* `set.sInter_eq_bInter`, `set.sUnion_eq_bInter`: Shows that `\u22c2\u2080 s = \u22c2 x \u2208 s, x` and\n  `\u22c3\u2080 s = \u22c3 x \u2208 s, x`.\n* `set.complete_boolean_algebra`: `set \u03b1` is a `complete_boolean_algebra` with `\u2264 = \u2286`, `< = \u2282`,\n  `\u2293 = \u2229`, `\u2294 = \u222a`, `\u2a05 = \u22c2`, `\u2a06 = \u22c3` and `\\` as the set difference. See `set.boolean_algebra`.\n* `set.kern_image`: For a function `f : \u03b1 \u2192 \u03b2`, `s.kern_image f` is the set of `y` such that\n  `f \u207b\u00b9 y \u2286 s`.\n* `set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union\n  of `f '' t` over all `f \u2208 s`, where `t : set \u03b1` and `s : set (\u03b1 \u2192 \u03b2)`.\n* `set.Union_eq_sigma_of_disjoint`: Equivalence between `\u22c3 i, t i` and `\u03a3 i, t i`, where `t` is an\n  indexed family of disjoint sets.\n\n## Naming convention\n\nIn lemma names,\n* `\u22c3 i, s i` is called `Union`\n* `\u22c2 i, s i` is called `Inter`\n* `\u22c3 i j, s i j` is called `Union\u2082`. This is a `Union` inside a `Union`.\n* `\u22c2 i j, s i j` is called `Inter\u2082`. This is an `Inter` inside an `Inter`.\n* `\u22c3 i \u2208 s, t i` is called `bUnion` for \"bounded `Union`\". This is the special case of `Union\u2082`\n  where `j : i \u2208 s`.\n* `\u22c2 i \u2208 s, t i` is called `bInter` for \"bounded `Inter`\". This is the special case of `Inter\u2082`\n  where `j : i \u2208 s`.\n\n## Notation\n\n* `\u22c3`: `set.Union`\n* `\u22c2`: `set.Inter`\n* `\u22c3\u2080`: `set.sUnion`\n* `\u22c2\u2080`: `set.sInter`\n-/\n\nopen function tactic set\n\nuniverses u\nvariables {\u03b1 \u03b2 \u03b3 : Type*} {\u03b9 \u03b9' \u03b9\u2082 : Sort*} {\u03ba \u03ba\u2081 \u03ba\u2082 : \u03b9 \u2192 Sort*} {\u03ba' : \u03b9' \u2192 Sort*}\n\nnamespace set\n\n/-! ### Complete lattice and complete Boolean algebra instances -/\n\ninstance : has_Inf (set \u03b1) := \u27e8\u03bb s, {a | \u2200 t \u2208 s, a \u2208 t}\u27e9\ninstance : has_Sup (set \u03b1) := \u27e8\u03bb s, {a | \u2203 t \u2208 s, a \u2208 t}\u27e9\n\n/-- Intersection of a set of sets. -/\ndef sInter (S : set (set \u03b1)) : set \u03b1 := Inf S\n\n/-- Union of a set of sets. -/\ndef sUnion (S : set (set \u03b1)) : set \u03b1 := Sup S\n\nprefix `\u22c2\u2080 `:110 := sInter\nprefix `\u22c3\u2080 `:110 := sUnion\n\n@[simp] theorem mem_sInter {x : \u03b1} {S : set (set \u03b1)} : x \u2208 \u22c2\u2080 S \u2194 \u2200 t \u2208 S, x \u2208 t := iff.rfl\n@[simp] theorem mem_sUnion {x : \u03b1} {S : set (set \u03b1)} : x \u2208 \u22c3\u2080 S \u2194 \u2203 t \u2208 S, x \u2208 t := iff.rfl\n\n/-- Indexed union of a family of sets -/\ndef Union (s : \u03b9 \u2192 set \u03b2) : set \u03b2 := supr s\n\n/-- Indexed intersection of a family of sets -/\ndef Inter (s : \u03b9 \u2192 set \u03b2) : set \u03b2 := infi s\n\nnotation `\u22c3` binders `, ` r:(scoped f, Union f) := r\nnotation `\u22c2` binders `, ` r:(scoped f, Inter f) := r\n\n@[simp] lemma Sup_eq_sUnion (S : set (set \u03b1)) : Sup S = \u22c3\u2080 S := rfl\n@[simp] lemma Inf_eq_sInter (S : set (set \u03b1)) : Inf S = \u22c2\u2080 S := rfl\n@[simp] lemma supr_eq_Union (s : \u03b9 \u2192 set \u03b1) : supr s = Union s := rfl\n@[simp] lemma infi_eq_Inter (s : \u03b9 \u2192 set \u03b1) : infi s = Inter s := rfl\n\n@[simp] lemma mem_Union {x : \u03b1} {s : \u03b9 \u2192 set \u03b1} : x \u2208 (\u22c3 i, s i) \u2194 \u2203 i, x \u2208 s i :=\n\u27e8\u03bb \u27e8t, \u27e8\u27e8a, (t_eq : s a = t)\u27e9, (h : x \u2208 t)\u27e9\u27e9, \u27e8a, t_eq.symm \u25b8 h\u27e9,\n  \u03bb \u27e8a, h\u27e9, \u27e8s a, \u27e8\u27e8a, rfl\u27e9, h\u27e9\u27e9\u27e9\n\n@[simp] lemma mem_Inter {x : \u03b1} {s : \u03b9 \u2192 set \u03b1} : x \u2208 (\u22c2 i, s i) \u2194 \u2200 i, x \u2208 s i :=\n\u27e8\u03bb (h : \u2200 a \u2208 {a : set \u03b1 | \u2203 i, s i = a}, x \u2208 a) a, h (s a) \u27e8a, rfl\u27e9,\n  \u03bb h t \u27e8a, (eq : s a = t)\u27e9, eq \u25b8 h a\u27e9\n\nlemma mem_Union\u2082 {x : \u03b3} {s : \u03a0 i, \u03ba i \u2192 set \u03b3} : x \u2208 (\u22c3 i j, s i j) \u2194 \u2203 i j, x \u2208 s i j :=\nby simp_rw mem_Union\n\nlemma mem_Inter\u2082 {x : \u03b3} {s : \u03a0 i, \u03ba i \u2192 set \u03b3} : x \u2208 (\u22c2 i j, s i j) \u2194 \u2200 i j, x \u2208 s i j :=\nby simp_rw mem_Inter\n\nlemma mem_Union_of_mem {s : \u03b9 \u2192 set \u03b1} {a : \u03b1} (i : \u03b9) (ha : a \u2208 s i) : a \u2208 \u22c3 i, s i :=\nmem_Union.2 \u27e8i, ha\u27e9\n\nlemma mem_Union\u2082_of_mem {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {a : \u03b1} {i : \u03b9} (j : \u03ba i) (ha : a \u2208 s i j) :\n  a \u2208 \u22c3 i j, s i j :=\nmem_Union\u2082.2 \u27e8i, j, ha\u27e9\n\nlemma mem_Inter_of_mem {s : \u03b9 \u2192 set \u03b1} {a : \u03b1} (h : \u2200 i, a \u2208 s i) : a \u2208 \u22c2 i, s i := mem_Inter.2 h\n\nlemma mem_Inter\u2082_of_mem {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {a : \u03b1} (h : \u2200 i j, a \u2208 s i j) : a \u2208 \u22c2 i j, s i j :=\nmem_Inter\u2082.2 h\n\ninstance : complete_boolean_algebra (set \u03b1) :=\n{ Sup    := Sup,\n  Inf    := Inf,\n  le_Sup := \u03bb s t t_in a a_in, \u27e8t, \u27e8t_in, a_in\u27e9\u27e9,\n  Sup_le := \u03bb s t h a \u27e8t', \u27e8t'_in, a_in\u27e9\u27e9, h t' t'_in a_in,\n  le_Inf := \u03bb s t h a a_in t' t'_in, h t' t'_in a_in,\n  Inf_le := \u03bb s t t_in a h, h _ t_in,\n  infi_sup_le_sup_Inf := \u03bb s S x, iff.mp $ by simp [forall_or_distrib_left],\n  inf_Sup_le_supr_inf := \u03bb s S x, iff.mp $ by simp [exists_and_distrib_left],\n  .. set.boolean_algebra }\n\nsection galois_connection\nvariables {f : \u03b1 \u2192 \u03b2}\n\nprotected lemma image_preimage : galois_connection (image f) (preimage f) :=\n\u03bb a b, image_subset_iff\n\n/-- `kern_image f s` is the set of `y` such that `f \u207b\u00b9 y \u2286 s`. -/\ndef kern_image (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) : set \u03b2 := {y | \u2200 \u2983x\u2984, f x = y \u2192 x \u2208 s}\n\nprotected lemma preimage_kern_image : galois_connection (preimage f) (kern_image f) :=\n\u03bb a b,\n\u27e8 \u03bb h x hx y hy, have f y \u2208 a, from hy.symm \u25b8 hx, h this,\n  \u03bb h x (hx : f x \u2208 a), h hx rfl\u27e9\n\nend galois_connection\n\n/-! ### Union and intersection over an indexed family of sets -/\n\ninstance : order_top (set \u03b1) :=\n{ top := univ,\n  le_top := by simp }\n\n@[congr] theorem Union_congr_Prop {p q : Prop} {f\u2081 : p \u2192 set \u03b1} {f\u2082 : q \u2192 set \u03b1}\n  (pq : p \u2194 q) (f : \u2200x, f\u2081 (pq.mpr x) = f\u2082 x) : Union f\u2081 = Union f\u2082 :=\nsupr_congr_Prop pq f\n\n@[congr] theorem Inter_congr_Prop {p q : Prop} {f\u2081 : p \u2192 set \u03b1} {f\u2082 : q \u2192 set \u03b1}\n  (pq : p \u2194 q) (f : \u2200x, f\u2081 (pq.mpr x) = f\u2082 x) : Inter f\u2081 = Inter f\u2082 :=\ninfi_congr_Prop pq f\n\nlemma Union_plift_up (f : plift \u03b9 \u2192 set \u03b1) : (\u22c3 i, f (plift.up i)) = \u22c3 i, f i := supr_plift_up _\nlemma Union_plift_down (f : \u03b9 \u2192 set \u03b1) : (\u22c3 i, f (plift.down i)) = \u22c3 i, f i := supr_plift_down _\nlemma Inter_plift_up (f : plift \u03b9 \u2192 set \u03b1) : (\u22c2 i, f (plift.up i)) = \u22c2 i, f i := infi_plift_up _\nlemma Inter_plift_down (f : \u03b9 \u2192 set \u03b1) : (\u22c2 i, f (plift.down i)) = \u22c2 i, f i := infi_plift_down _\n\nlemma Union_eq_if {p : Prop} [decidable p] (s : set \u03b1) :\n  (\u22c3 h : p, s) = if p then s else \u2205 :=\nsupr_eq_if _\n\nlemma Union_eq_dif {p : Prop} [decidable p] (s : p \u2192 set \u03b1) :\n  (\u22c3 (h : p), s h) = if h : p then s h else \u2205 :=\nsupr_eq_dif _\n\nlemma Inter_eq_if {p : Prop} [decidable p] (s : set \u03b1) :\n  (\u22c2 h : p, s) = if p then s else univ :=\ninfi_eq_if _\n\nlemma Infi_eq_dif {p : Prop} [decidable p] (s : p \u2192 set \u03b1) :\n  (\u22c2 (h : p), s h) = if h : p then s h else univ :=\ninfi_eq_dif _\n\nlemma exists_set_mem_of_union_eq_top {\u03b9 : Type*} (t : set \u03b9) (s : \u03b9 \u2192 set \u03b2)\n  (w : (\u22c3 i \u2208 t, s i) = \u22a4) (x : \u03b2) :\n  \u2203 (i \u2208 t), x \u2208 s i :=\nbegin\n  have p : x \u2208 \u22a4 := set.mem_univ x,\n  simpa only [\u2190w, set.mem_Union] using p,\nend\n\nlemma nonempty_of_union_eq_top_of_nonempty\n  {\u03b9 : Type*} (t : set \u03b9) (s : \u03b9 \u2192 set \u03b1) (H : nonempty \u03b1) (w : (\u22c3 i \u2208 t, s i) = \u22a4) :\n  t.nonempty :=\nbegin\n  obtain \u27e8x, m, -\u27e9 := exists_set_mem_of_union_eq_top t s w H.some,\n  exact \u27e8x, m\u27e9,\nend\n\ntheorem set_of_exists (p : \u03b9 \u2192 \u03b2 \u2192 Prop) : {x | \u2203 i, p i x} = \u22c3 i, {x | p i x} :=\next $ \u03bb i, mem_Union.symm\n\ntheorem set_of_forall (p : \u03b9 \u2192 \u03b2 \u2192 Prop) : {x | \u2200 i, p i x} = \u22c2 i, {x | p i x} :=\next $ \u03bb i, mem_Inter.symm\n\nlemma Union_subset {s : \u03b9 \u2192 set \u03b1} {t : set \u03b1} (h : \u2200 i, s i \u2286 t) : (\u22c3 i, s i) \u2286 t :=\n@supr_le (set \u03b1) _ _ _ _ h\n\nlemma Union\u2082_subset {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : set \u03b1} (h : \u2200 i j, s i j \u2286 t) :\n  (\u22c3 i j, s i j) \u2286 t :=\nUnion_subset $ \u03bb x, Union_subset (h x)\n\ntheorem subset_Inter {t : set \u03b2} {s : \u03b9 \u2192 set \u03b2} (h : \u2200 i, t \u2286 s i) : t \u2286 \u22c2 i, s i :=\n@le_infi (set \u03b2) _ _ _ _ h\n\nlemma subset_Inter\u2082 {s : set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b1} (h : \u2200 i j, s \u2286 t i j) : s \u2286 \u22c2 i j, t i j :=\nsubset_Inter $ \u03bb x, subset_Inter $ h x\n\n@[simp] lemma Union_subset_iff {s : \u03b9 \u2192 set \u03b1} {t : set \u03b1} : (\u22c3 i, s i) \u2286 t \u2194 \u2200 i, s i \u2286 t :=\n\u27e8\u03bb h i, subset.trans (le_supr s _) h, Union_subset\u27e9\n\nlemma Union\u2082_subset_iff {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : set \u03b1} :\n  (\u22c3 i j, s i j) \u2286 t \u2194 \u2200 i j, s i j \u2286 t :=\nby simp_rw Union_subset_iff\n\n@[simp] lemma subset_Inter_iff {s : set \u03b1} {t : \u03b9 \u2192 set \u03b1} : s \u2286 (\u22c2 i, t i) \u2194 \u2200 i, s \u2286 t i :=\n@le_infi_iff (set \u03b1) _ _ _ _\n\n@[simp] lemma subset_Inter\u2082_iff {s : set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b1} :\n  s \u2286 (\u22c2 i j, t i j) \u2194 \u2200 i j, s \u2286 t i j :=\nby simp_rw subset_Inter_iff\n\nlemma subset_Union : \u2200 (s : \u03b9 \u2192 set \u03b2) (i : \u03b9), s i \u2286 \u22c3 i, s i := le_supr\nlemma Inter_subset : \u2200 (s : \u03b9 \u2192 set \u03b2) (i : \u03b9), (\u22c2 i, s i) \u2286 s i := infi_le\n\nlemma subset_Union\u2082 {s : \u03a0 i, \u03ba i \u2192 set \u03b1} (i : \u03b9) (j : \u03ba i) : s i j \u2286 \u22c3 i j, s i j :=\n@le_supr\u2082 (set \u03b1) _ _ _ _ i j\n\nlemma Inter\u2082_subset {s : \u03a0 i, \u03ba i \u2192 set \u03b1} (i : \u03b9) (j : \u03ba i) : (\u22c2 i j, s i j) \u2286 s i j :=\n@infi\u2082_le (set \u03b1) _ _ _ _ i j\n\n/-- This rather trivial consequence of `subset_Union`is convenient with `apply`, and has `i`\nexplicit for this purpose. -/\nlemma subset_Union_of_subset {s : set \u03b1} {t : \u03b9 \u2192 set \u03b1} (i : \u03b9) (h : s \u2286 t i) : s \u2286 \u22c3 i, t i :=\n@le_supr_of_le (set \u03b1) _ _ _ _ i h\n\n/-- This rather trivial consequence of `Inter_subset`is convenient with `apply`, and has `i`\nexplicit for this purpose. -/\nlemma Inter_subset_of_subset {s : \u03b9 \u2192 set \u03b1} {t : set \u03b1} (i : \u03b9) (h : s i \u2286 t) : (\u22c2 i, s i) \u2286 t :=\n@infi_le_of_le (set \u03b1) _ _ _ _ i h\n\n/-- This rather trivial consequence of `subset_Union\u2082` is convenient with `apply`, and has `i` and\n`j` explicit for this purpose. -/\nlemma subset_Union\u2082_of_subset {s : set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b1} (i : \u03b9) (j : \u03ba i) (h : s \u2286 t i j) :\n  s \u2286 \u22c3 i j, t i j :=\n@le_supr\u2082_of_le (set \u03b1) _ _ _ _ _ i j h\n\n/-- This rather trivial consequence of `Inter\u2082_subset` is convenient with `apply`, and has `i` and\n`j` explicit for this purpose. -/\nlemma Inter\u2082_subset_of_subset {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : set \u03b1} (i : \u03b9) (j : \u03ba i) (h : s i j \u2286 t) :\n  (\u22c2 i j, s i j) \u2286 t :=\n@infi\u2082_le_of_le (set \u03b1) _ _ _ _ _ i j h\n\nlemma Union_mono {s t : \u03b9 \u2192 set \u03b1} (h : \u2200 i, s i \u2286 t i) : (\u22c3 i, s i) \u2286 \u22c3 i, t i :=\n@supr_mono (set \u03b1) _ _ s t h\n\nlemma Union\u2082_mono {s t : \u03a0 i, \u03ba i \u2192 set \u03b1} (h : \u2200 i j, s i j \u2286 t i j) :\n  (\u22c3 i j, s i j) \u2286 \u22c3 i j, t i j :=\n@supr\u2082_mono (set \u03b1) _ _ _ s t h\n\nlemma Inter_mono {s t : \u03b9 \u2192 set \u03b1} (h : \u2200 i, s i \u2286 t i) : (\u22c2 i, s i) \u2286 \u22c2 i, t i :=\n@infi_mono (set \u03b1) _ _ s t h\n\nlemma Inter\u2082_mono {s t : \u03a0 i, \u03ba i \u2192 set \u03b1} (h : \u2200 i j, s i j \u2286 t i j) :\n  (\u22c2 i j, s i j) \u2286 \u22c2 i j, t i j :=\n@infi\u2082_mono (set \u03b1) _ _ _ s t h\n\nlemma Union_mono' {s : \u03b9 \u2192 set \u03b1} {t : \u03b9\u2082 \u2192 set \u03b1} (h : \u2200 i, \u2203 j, s i \u2286 t j) :\n  (\u22c3 i, s i) \u2286 \u22c3 i, t i :=\n@supr_mono' (set \u03b1) _ _ _ s t h\n\nlemma Union\u2082_mono' {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : \u03a0 i', \u03ba' i' \u2192 set \u03b1}\n  (h : \u2200 i j, \u2203 i' j', s i j \u2286 t i' j') :\n  (\u22c3 i j, s i j) \u2286 \u22c3 i' j', t i' j' :=\n@supr\u2082_mono' (set \u03b1) _ _ _ _ _ s t h\n\nlemma Inter_mono' {s : \u03b9 \u2192 set \u03b1} {t : \u03b9' \u2192 set \u03b1} (h : \u2200 j, \u2203 i, s i \u2286 t j) :\n  (\u22c2 i, s i) \u2286 (\u22c2 j, t j) :=\nset.subset_Inter $ \u03bb j, let \u27e8i, hi\u27e9 := h j in Inter_subset_of_subset i hi\n\nlemma Inter\u2082_mono' {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : \u03a0 i', \u03ba' i' \u2192 set \u03b1}\n  (h : \u2200 i' j', \u2203 i j, s i j \u2286 t i' j') :\n  (\u22c2 i j, s i j) \u2286 \u22c2 i' j', t i' j' :=\nsubset_Inter\u2082_iff.2 $ \u03bb i' j', let \u27e8i, j, hst\u27e9 := h i' j' in (Inter\u2082_subset _ _).trans hst\n\nlemma Union\u2082_subset_Union (\u03ba : \u03b9 \u2192 Sort*) (s : \u03b9 \u2192 set \u03b1) : (\u22c3 i (j : \u03ba i), s i) \u2286 \u22c3 i, s i :=\nUnion_mono $ \u03bb i, Union_subset $ \u03bb h, subset.rfl\n\nlemma Inter_subset_Inter\u2082 (\u03ba : \u03b9 \u2192 Sort*) (s : \u03b9 \u2192 set \u03b1) : (\u22c2 i, s i) \u2286 \u22c2 i (j : \u03ba i), s i :=\nInter_mono $ \u03bb i, subset_Inter $ \u03bb h, subset.rfl\n\nlemma Union_set_of (P : \u03b9 \u2192 \u03b1 \u2192 Prop) : (\u22c3 i, {x : \u03b1 | P i x}) = {x : \u03b1 | \u2203 i, P i x} :=\nby { ext, exact mem_Union }\n\nlemma Inter_set_of (P : \u03b9 \u2192 \u03b1 \u2192 Prop) : (\u22c2 i, {x : \u03b1 | P i x}) = {x : \u03b1 | \u2200 i, P i x} :=\nby { ext, exact mem_Inter }\n\nlemma Union_congr_of_surjective {f : \u03b9 \u2192 set \u03b1} {g : \u03b9\u2082 \u2192 set \u03b1} (h : \u03b9 \u2192 \u03b9\u2082)\n  (h1 : surjective h) (h2 : \u2200 x, g (h x) = f x) : (\u22c3 x, f x) = \u22c3 y, g y :=\nh1.supr_congr h h2\n\nlemma Inter_congr_of_surjective {f : \u03b9 \u2192 set \u03b1} {g : \u03b9\u2082 \u2192 set \u03b1} (h : \u03b9 \u2192 \u03b9\u2082)\n  (h1 : surjective h) (h2 : \u2200 x, g (h x) = f x) : (\u22c2 x, f x) = \u22c2 y, g y :=\nh1.infi_congr h h2\n\nlemma Union_congr {s t : \u03b9 \u2192 set \u03b1} (h : \u2200 i, s i = t i) : (\u22c3 i, s i) = \u22c3 i, t i := supr_congr h\nlemma Inter_congr {s t : \u03b9 \u2192 set \u03b1} (h : \u2200 i, s i = t i) : (\u22c2 i, s i) = \u22c2 i, t i := infi_congr h\n\nlemma Union\u2082_congr {s t : \u03a0 i, \u03ba i \u2192 set \u03b1} (h : \u2200 i j, s i j = t i j) :\n  (\u22c3 i j, s i j) = \u22c3 i j, t i j :=\nUnion_congr $ \u03bb i, Union_congr $ h i\n\nlemma Inter\u2082_congr {s t : \u03a0 i, \u03ba i \u2192 set \u03b1} (h : \u2200 i j, s i j = t i j) :\n  (\u22c2 i j, s i j) = \u22c2 i j, t i j :=\nInter_congr $ \u03bb i, Inter_congr $ h i\n\nsection nonempty\nvariables [nonempty \u03b9] {f : \u03b9 \u2192 set \u03b1} {s : set \u03b1}\n\nlemma Union_const (s : set \u03b2) : (\u22c3 i : \u03b9, s) = s := supr_const\nlemma Inter_const (s : set \u03b2) : (\u22c2 i : \u03b9, s) = s := infi_const\n\nlemma Union_eq_const (hf : \u2200 i, f i = s) : (\u22c3 i, f i) = s := (Union_congr hf).trans $ Union_const _\nlemma Inter_eq_const (hf : \u2200 i, f i = s) : (\u22c2 i, f i) = s := (Inter_congr hf).trans $ Inter_const _\n\nend nonempty\n\n@[simp] theorem compl_Union (s : \u03b9 \u2192 set \u03b2) : (\u22c3 i, s i)\u1d9c = (\u22c2 i, (s i)\u1d9c) :=\ncompl_supr\n\nlemma compl_Union\u2082 (s : \u03a0 i, \u03ba i \u2192 set \u03b1) : (\u22c3 i j, s i j)\u1d9c = \u22c2 i j, (s i j)\u1d9c :=\nby simp_rw compl_Union\n\n@[simp] theorem compl_Inter (s : \u03b9 \u2192 set \u03b2) : (\u22c2 i, s i)\u1d9c = (\u22c3 i, (s i)\u1d9c) :=\ncompl_infi\n\nlemma compl_Inter\u2082 (s : \u03a0 i, \u03ba i \u2192 set \u03b1) : (\u22c2 i j, s i j)\u1d9c = \u22c3 i j, (s i j)\u1d9c :=\nby simp_rw compl_Inter\n\n-- classical -- complete_boolean_algebra\ntheorem Union_eq_compl_Inter_compl (s : \u03b9 \u2192 set \u03b2) : (\u22c3 i, s i) = (\u22c2 i, (s i)\u1d9c)\u1d9c :=\nby simp only [compl_Inter, compl_compl]\n\n-- classical -- complete_boolean_algebra\ntheorem Inter_eq_compl_Union_compl (s : \u03b9 \u2192 set \u03b2) : (\u22c2 i, s i) = (\u22c3 i, (s i)\u1d9c)\u1d9c :=\nby simp only [compl_Union, compl_compl]\n\ntheorem inter_Union (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  s \u2229 (\u22c3 i, t i) = \u22c3 i, s \u2229 t i :=\ninf_supr_eq _ _\n\ntheorem Union_inter (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  (\u22c3 i, t i) \u2229 s = \u22c3 i, t i \u2229 s :=\nsupr_inf_eq _ _\n\ntheorem Union_union_distrib (s : \u03b9 \u2192 set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  (\u22c3 i, s i \u222a t i) = (\u22c3 i, s i) \u222a (\u22c3 i, t i) :=\nsupr_sup_eq\n\ntheorem Inter_inter_distrib (s : \u03b9 \u2192 set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  (\u22c2 i, s i \u2229 t i) = (\u22c2 i, s i) \u2229 (\u22c2 i, t i) :=\ninfi_inf_eq\n\ntheorem union_Union [nonempty \u03b9] (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  s \u222a (\u22c3 i, t i) = \u22c3 i, s \u222a t i :=\nsup_supr\n\ntheorem Union_union [nonempty \u03b9] (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  (\u22c3 i, t i) \u222a s = \u22c3 i, t i \u222a s :=\nsupr_sup\n\ntheorem inter_Inter [nonempty \u03b9] (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  s \u2229 (\u22c2 i, t i) = \u22c2 i, s \u2229 t i :=\ninf_infi\n\ntheorem Inter_inter [nonempty \u03b9] (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  (\u22c2 i, t i) \u2229 s = \u22c2 i, t i \u2229 s :=\ninfi_inf\n\n-- classical\ntheorem union_Inter (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  s \u222a (\u22c2 i, t i) = \u22c2 i, s \u222a t i :=\nsup_infi_eq _ _\n\ntheorem Inter_union (s : \u03b9 \u2192 set \u03b2) (t : set \u03b2) :\n  (\u22c2 i, s i) \u222a t = \u22c2 i, s i \u222a t :=\ninfi_sup_eq _ _\n\ntheorem Union_diff (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  (\u22c3 i, t i) \\ s = \u22c3 i, t i \\ s :=\nUnion_inter _ _\n\ntheorem diff_Union [nonempty \u03b9] (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  s \\ (\u22c3 i, t i) = \u22c2 i, s \\ t i :=\nby rw [diff_eq, compl_Union, inter_Inter]; refl\n\ntheorem diff_Inter (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) :\n  s \\ (\u22c2 i, t i) = \u22c3 i, s \\ t i :=\nby rw [diff_eq, compl_Inter, inter_Union]; refl\n\nlemma directed_on_Union {r} {f : \u03b9 \u2192 set \u03b1} (hd : directed (\u2286) f)\n  (h : \u2200 x, directed_on r (f x)) : directed_on r (\u22c3 x, f x) :=\nby simp only [directed_on, exists_prop, mem_Union, exists_imp_distrib]; exact\n\u03bb a\u2081 b\u2081 fb\u2081 a\u2082 b\u2082 fb\u2082,\nlet \u27e8z, zb\u2081, zb\u2082\u27e9 := hd b\u2081 b\u2082,\n    \u27e8x, xf, xa\u2081, xa\u2082\u27e9 := h z a\u2081 (zb\u2081 fb\u2081) a\u2082 (zb\u2082 fb\u2082) in\n\u27e8x, \u27e8z, xf\u27e9, xa\u2081, xa\u2082\u27e9\n\nlemma Union_inter_subset {\u03b9 \u03b1} {s t : \u03b9 \u2192 set \u03b1} : (\u22c3 i, s i \u2229 t i) \u2286 (\u22c3 i, s i) \u2229 (\u22c3 i, t i) :=\nle_supr_inf_supr s t\n\nlemma Union_inter_of_monotone {\u03b9 \u03b1} [preorder \u03b9] [is_directed \u03b9 (\u2264)] {s t : \u03b9 \u2192 set \u03b1}\n  (hs : monotone s) (ht : monotone t) : (\u22c3 i, s i \u2229 t i) = (\u22c3 i, s i) \u2229 (\u22c3 i, t i) :=\nsupr_inf_of_monotone hs ht\n\nlemma Union_inter_of_antitone {\u03b9 \u03b1} [preorder \u03b9] [is_directed \u03b9 (swap (\u2264))] {s t : \u03b9 \u2192 set \u03b1}\n  (hs : antitone s) (ht : antitone t) : (\u22c3 i, s i \u2229 t i) = (\u22c3 i, s i) \u2229 (\u22c3 i, t i) :=\nsupr_inf_of_antitone hs ht\n\nlemma Inter_union_of_monotone {\u03b9 \u03b1} [preorder \u03b9] [is_directed \u03b9 (swap (\u2264))] {s t : \u03b9 \u2192 set \u03b1}\n  (hs : monotone s) (ht : monotone t) : (\u22c2 i, s i \u222a t i) = (\u22c2 i, s i) \u222a (\u22c2 i, t i) :=\ninfi_sup_of_monotone hs ht\n\nlemma Inter_union_of_antitone {\u03b9 \u03b1} [preorder \u03b9] [is_directed \u03b9 (\u2264)] {s t : \u03b9 \u2192 set \u03b1}\n  (hs : antitone s) (ht : antitone t) : (\u22c2 i, s i \u222a t i) = (\u22c2 i, s i) \u222a (\u22c2 i, t i) :=\ninfi_sup_of_antitone hs ht\n\n/-- An equality version of this lemma is `Union_Inter_of_monotone` in `data.set.finite`. -/\nlemma Union_Inter_subset {s : \u03b9 \u2192 \u03b9' \u2192 set \u03b1} : (\u22c3 j, \u22c2 i, s i j) \u2286 \u22c2 i, \u22c3 j, s i j :=\nsupr_infi_le_infi_supr (flip s)\n\nlemma Union_option {\u03b9} (s : option \u03b9 \u2192 set \u03b1) : (\u22c3 o, s o) = s none \u222a \u22c3 i, s (some i) :=\nsupr_option s\n\nlemma Inter_option {\u03b9} (s : option \u03b9 \u2192 set \u03b1) : (\u22c2 o, s o) = s none \u2229 \u22c2 i, s (some i) :=\ninfi_option s\n\nsection\n\nvariables (p : \u03b9 \u2192 Prop) [decidable_pred p]\n\nlemma Union_dite (f : \u03a0 i, p i \u2192 set \u03b1) (g : \u03a0 i, \u00acp i \u2192 set \u03b1) :\n  (\u22c3 i, if h : p i then f i h else g i h) = (\u22c3 i (h : p i), f i h) \u222a (\u22c3 i (h : \u00ac p i), g i h) :=\nsupr_dite _ _ _\n\nlemma Union_ite (f g : \u03b9 \u2192 set \u03b1) :\n  (\u22c3 i, if p i then f i else g i) = (\u22c3 i (h : p i), f i) \u222a (\u22c3 i (h : \u00ac p i), g i) :=\nUnion_dite _ _ _\n\nlemma Inter_dite (f : \u03a0 i, p i \u2192 set \u03b1) (g : \u03a0 i, \u00acp i \u2192 set \u03b1) :\n  (\u22c2 i, if h : p i then f i h else g i h) = (\u22c2 i (h : p i), f i h) \u2229 (\u22c2 i (h : \u00ac p i), g i h) :=\ninfi_dite _ _ _\n\nlemma Inter_ite (f g : \u03b9 \u2192 set \u03b1) :\n  (\u22c2 i, if p i then f i else g i) = (\u22c2 i (h : p i), f i) \u2229 (\u22c2 i (h : \u00ac p i), g i) :=\nInter_dite _ _ _\n\nend\n\nlemma image_projection_prod {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} {v : \u03a0 (i : \u03b9), set (\u03b1 i)}\n  (hv : (pi univ v).nonempty) (i : \u03b9) :\n  (\u03bb (x : \u03a0 (i : \u03b9), \u03b1 i), x i) '' (\u22c2 k, (\u03bb (x : \u03a0 (j : \u03b9), \u03b1 j), x k) \u207b\u00b9' v k) = v i:=\nbegin\n  classical,\n  apply subset.antisymm,\n  { simp [Inter_subset] },\n  { intros y y_in,\n    simp only [mem_image, mem_Inter, mem_preimage],\n    rcases hv with \u27e8z, hz\u27e9,\n    refine \u27e8function.update z i y, _, update_same i y z\u27e9,\n    rw @forall_update_iff \u03b9 \u03b1 _ z i y (\u03bb i t, t \u2208 v i),\n    exact \u27e8y_in, \u03bb j hj, by simpa using hz j\u27e9 },\nend\n\n/-! ### Unions and intersections indexed by `Prop` -/\n\ntheorem Inter_false {s : false \u2192 set \u03b1} : Inter s = univ := infi_false\ntheorem Union_false {s : false \u2192 set \u03b1} : Union s = \u2205 := supr_false\n\n@[simp] theorem Inter_true {s : true \u2192 set \u03b1} : Inter s = s trivial := infi_true\n\n@[simp] theorem Union_true {s : true \u2192 set \u03b1} : Union s = s trivial := supr_true\n\n@[simp] theorem Inter_exists {p : \u03b9 \u2192 Prop} {f : Exists p \u2192 set \u03b1} :\n  (\u22c2 x, f x) = (\u22c2 i (h : p i), f \u27e8i, h\u27e9) :=\ninfi_exists\n\n@[simp] theorem Union_exists {p : \u03b9 \u2192 Prop} {f : Exists p \u2192 set \u03b1} :\n  (\u22c3 x, f x) = (\u22c3 i (h : p i), f \u27e8i, h\u27e9) :=\nsupr_exists\n\n@[simp] lemma Union_empty : (\u22c3 i : \u03b9, \u2205 : set \u03b1) = \u2205 := supr_bot\n\n@[simp] lemma Inter_univ : (\u22c2 i : \u03b9, univ : set \u03b1) = univ := infi_top\n\nsection\n\nvariables {s : \u03b9 \u2192 set \u03b1}\n\n@[simp] lemma Union_eq_empty : (\u22c3 i, s i) = \u2205 \u2194 \u2200 i, s i = \u2205 := supr_eq_bot\n\n@[simp] lemma Inter_eq_univ : (\u22c2 i, s i) = univ \u2194 \u2200 i, s i = univ := infi_eq_top\n\n@[simp] lemma nonempty_Union : (\u22c3 i, s i).nonempty \u2194 \u2203 i, (s i).nonempty :=\nby simp [nonempty_iff_ne_empty]\n\n@[simp] lemma nonempty_bUnion {t : set \u03b1} {s : \u03b1 \u2192 set \u03b2} :\n  (\u22c3 i \u2208 t, s i).nonempty \u2194 \u2203 i \u2208 t, (s i).nonempty :=\nby simp [nonempty_iff_ne_empty]\n\nlemma Union_nonempty_index (s : set \u03b1) (t : s.nonempty \u2192 set \u03b2) :\n  (\u22c3 h, t h) = \u22c3 x \u2208 s, t \u27e8x, \u2039_\u203a\u27e9 :=\nsupr_exists\n\nend\n\n@[simp] theorem Inter_Inter_eq_left {b : \u03b2} {s : \u03a0 x : \u03b2, x = b \u2192 set \u03b1} :\n  (\u22c2 x (h : x = b), s x h) = s b rfl :=\ninfi_infi_eq_left\n\n@[simp] theorem Inter_Inter_eq_right {b : \u03b2} {s : \u03a0 x : \u03b2, b = x \u2192 set \u03b1} :\n  (\u22c2 x (h : b = x), s x h) = s b rfl :=\ninfi_infi_eq_right\n\n@[simp] theorem Union_Union_eq_left {b : \u03b2} {s : \u03a0 x : \u03b2, x = b \u2192 set \u03b1} :\n  (\u22c3 x (h : x = b), s x h) = s b rfl :=\nsupr_supr_eq_left\n\n@[simp] theorem Union_Union_eq_right {b : \u03b2} {s : \u03a0 x : \u03b2, b = x \u2192 set \u03b1} :\n  (\u22c3 x (h : b = x), s x h) = s b rfl :=\nsupr_supr_eq_right\n\ntheorem Inter_or {p q : Prop} (s : p \u2228 q \u2192 set \u03b1) :\n  (\u22c2 h, s h) = (\u22c2 h : p, s (or.inl h)) \u2229 (\u22c2 h : q, s (or.inr h)) :=\ninfi_or\n\ntheorem Union_or {p q : Prop} (s : p \u2228 q \u2192 set \u03b1) :\n  (\u22c3 h, s h) = (\u22c3 i, s (or.inl i)) \u222a (\u22c3 j, s (or.inr j)) :=\nsupr_or\n\ntheorem Union_and {p q : Prop} (s : p \u2227 q \u2192 set \u03b1) :\n  (\u22c3 h, s h) = \u22c3 hp hq, s \u27e8hp, hq\u27e9 :=\nsupr_and\n\ntheorem Inter_and {p q : Prop} (s : p \u2227 q \u2192 set \u03b1) :\n  (\u22c2 h, s h) = \u22c2 hp hq, s \u27e8hp, hq\u27e9 :=\ninfi_and\n\nlemma Union_comm (s : \u03b9 \u2192 \u03b9' \u2192 set \u03b1) : (\u22c3 i i', s i i') = \u22c3 i' i, s i i' := supr_comm\nlemma Inter_comm (s : \u03b9 \u2192 \u03b9' \u2192 set \u03b1) : (\u22c2 i i', s i i') = \u22c2 i' i, s i i' := infi_comm\n\nlemma Union\u2082_comm (s : \u03a0 i\u2081, \u03ba\u2081 i\u2081 \u2192 \u03a0 i\u2082, \u03ba\u2082 i\u2082 \u2192 set \u03b1) :\n  (\u22c3 i\u2081 j\u2081 i\u2082 j\u2082, s i\u2081 j\u2081 i\u2082 j\u2082) = \u22c3 i\u2082 j\u2082 i\u2081 j\u2081, s i\u2081 j\u2081 i\u2082 j\u2082 :=\nsupr\u2082_comm _\n\nlemma Inter\u2082_comm (s : \u03a0 i\u2081, \u03ba\u2081 i\u2081 \u2192 \u03a0 i\u2082, \u03ba\u2082 i\u2082 \u2192 set \u03b1) :\n  (\u22c2 i\u2081 j\u2081 i\u2082 j\u2082, s i\u2081 j\u2081 i\u2082 j\u2082) = \u22c2 i\u2082 j\u2082 i\u2081 j\u2081, s i\u2081 j\u2081 i\u2082 j\u2082 :=\ninfi\u2082_comm _\n\n@[simp] theorem bUnion_and (p : \u03b9 \u2192 Prop) (q : \u03b9 \u2192 \u03b9' \u2192 Prop) (s : \u03a0 x y, p x \u2227 q x y \u2192 set \u03b1) :\n  (\u22c3 (x : \u03b9) (y : \u03b9') (h : p x \u2227 q x y), s x y h) =\n    \u22c3 (x : \u03b9) (hx : p x) (y : \u03b9') (hy : q x y), s x y \u27e8hx, hy\u27e9 :=\nby simp only [Union_and, @Union_comm _ \u03b9']\n\n@[simp] theorem bUnion_and' (p : \u03b9' \u2192 Prop) (q : \u03b9 \u2192 \u03b9' \u2192 Prop) (s : \u03a0 x y, p y \u2227 q x y \u2192 set \u03b1) :\n  (\u22c3 (x : \u03b9) (y : \u03b9') (h : p y \u2227 q x y), s x y h) =\n    \u22c3 (y : \u03b9') (hy : p y) (x : \u03b9) (hx : q x y), s x y \u27e8hy, hx\u27e9 :=\nby simp only [Union_and, @Union_comm _ \u03b9]\n\n@[simp] theorem bInter_and (p : \u03b9 \u2192 Prop) (q : \u03b9 \u2192 \u03b9' \u2192 Prop) (s : \u03a0 x y, p x \u2227 q x y \u2192 set \u03b1) :\n  (\u22c2 (x : \u03b9) (y : \u03b9') (h : p x \u2227 q x y), s x y h) =\n    \u22c2 (x : \u03b9) (hx : p x) (y : \u03b9') (hy : q x y), s x y \u27e8hx, hy\u27e9 :=\nby simp only [Inter_and, @Inter_comm _ \u03b9']\n\n@[simp] theorem bInter_and' (p : \u03b9' \u2192 Prop) (q : \u03b9 \u2192 \u03b9' \u2192 Prop) (s : \u03a0 x y, p y \u2227 q x y \u2192 set \u03b1) :\n  (\u22c2 (x : \u03b9) (y : \u03b9') (h : p y \u2227 q x y), s x y h) =\n    \u22c2 (y : \u03b9') (hy : p y) (x : \u03b9) (hx : q x y), s x y \u27e8hy, hx\u27e9 :=\nby simp only [Inter_and, @Inter_comm _ \u03b9]\n\n@[simp] theorem Union_Union_eq_or_left {b : \u03b2} {p : \u03b2 \u2192 Prop} {s : \u03a0 x : \u03b2, (x = b \u2228 p x) \u2192 set \u03b1} :\n  (\u22c3 x h, s x h) = s b (or.inl rfl) \u222a \u22c3 x (h : p x), s x (or.inr h) :=\nby simp only [Union_or, Union_union_distrib, Union_Union_eq_left]\n\n@[simp] theorem Inter_Inter_eq_or_left {b : \u03b2} {p : \u03b2 \u2192 Prop} {s : \u03a0 x : \u03b2, (x = b \u2228 p x) \u2192 set \u03b1} :\n  (\u22c2 x h, s x h) = s b (or.inl rfl) \u2229 \u22c2 x (h : p x), s x (or.inr h) :=\nby simp only [Inter_or, Inter_inter_distrib, Inter_Inter_eq_left]\n\n/-! ### Bounded unions and intersections -/\n\n/-- A specialization of `mem_Union\u2082`. -/\ntheorem mem_bUnion {s : set \u03b1} {t : \u03b1 \u2192 set \u03b2} {x : \u03b1} {y : \u03b2} (xs : x \u2208 s) (ytx : y \u2208 t x) :\n  y \u2208 \u22c3 x \u2208 s, t x :=\nmem_Union\u2082_of_mem xs ytx\n\n/-- A specialization of `mem_Inter\u2082`. -/\ntheorem mem_bInter {s : set \u03b1} {t : \u03b1 \u2192 set \u03b2} {y : \u03b2} (h : \u2200 x \u2208 s, y \u2208 t x) :\n  y \u2208 \u22c2 x \u2208 s, t x :=\nmem_Inter\u2082_of_mem h\n\n/-- A specialization of `subset_Union\u2082`. -/\ntheorem subset_bUnion_of_mem {s : set \u03b1} {u : \u03b1 \u2192 set \u03b2} {x : \u03b1} (xs : x \u2208 s) :\n  u x \u2286 (\u22c3 x \u2208 s, u x) :=\nsubset_Union\u2082 x xs\n\n/-- A specialization of `Inter\u2082_subset`. -/\ntheorem bInter_subset_of_mem {s : set \u03b1} {t : \u03b1 \u2192 set \u03b2} {x : \u03b1} (xs : x \u2208 s) :\n  (\u22c2 x \u2208 s, t x) \u2286 t x :=\nInter\u2082_subset x xs\n\ntheorem bUnion_subset_bUnion_left {s s' : set \u03b1} {t : \u03b1 \u2192 set \u03b2}\n  (h : s \u2286 s') : (\u22c3 x \u2208 s, t x) \u2286 (\u22c3 x \u2208 s', t x) :=\nUnion\u2082_subset $ \u03bb x hx, subset_bUnion_of_mem $ h hx\n\ntheorem bInter_subset_bInter_left {s s' : set \u03b1} {t : \u03b1 \u2192 set \u03b2}\n  (h : s' \u2286 s) : (\u22c2 x \u2208 s, t x) \u2286 (\u22c2 x \u2208 s', t x) :=\nsubset_Inter\u2082 $ \u03bb x hx, bInter_subset_of_mem $ h hx\n\nlemma bUnion_mono {s s' : set \u03b1} {t t' : \u03b1 \u2192 set \u03b2} (hs : s' \u2286 s) (h : \u2200 x \u2208 s, t x \u2286 t' x) :\n  (\u22c3 x \u2208 s', t x) \u2286 \u22c3 x \u2208 s, t' x :=\n(bUnion_subset_bUnion_left hs).trans $ Union\u2082_mono h\n\nlemma bInter_mono {s s' : set \u03b1} {t t' : \u03b1 \u2192 set \u03b2} (hs : s \u2286 s') (h : \u2200 x \u2208 s, t x \u2286 t' x) :\n  (\u22c2 x \u2208 s', t x) \u2286 (\u22c2 x \u2208 s, t' x) :=\n(bInter_subset_bInter_left hs).trans $ Inter\u2082_mono h\n\ntheorem bUnion_eq_Union (s : set \u03b1) (t : \u03a0 x \u2208 s, set \u03b2) :\n  (\u22c3 x \u2208 s, t x \u2039_\u203a) = (\u22c3 x : s, t x x.2) :=\nsupr_subtype'\n\ntheorem bInter_eq_Inter (s : set \u03b1) (t : \u03a0 x \u2208 s, set \u03b2) :\n  (\u22c2 x \u2208 s, t x \u2039_\u203a) = (\u22c2 x : s, t x x.2) :=\ninfi_subtype'\n\ntheorem Union_subtype (p : \u03b1 \u2192 Prop) (s : {x // p x} \u2192 set \u03b2) :\n  (\u22c3 x : {x // p x}, s x) = \u22c3 x (hx : p x), s \u27e8x, hx\u27e9 :=\nsupr_subtype\n\ntheorem Inter_subtype (p : \u03b1 \u2192 Prop) (s : {x // p x} \u2192 set \u03b2) :\n  (\u22c2 x : {x // p x}, s x) = \u22c2 x (hx : p x), s \u27e8x, hx\u27e9 :=\ninfi_subtype\n\ntheorem bInter_empty (u : \u03b1 \u2192 set \u03b2) : (\u22c2 x \u2208 (\u2205 : set \u03b1), u x) = univ :=\ninfi_emptyset\n\ntheorem bInter_univ (u : \u03b1 \u2192 set \u03b2) : (\u22c2 x \u2208 @univ \u03b1, u x) = \u22c2 x, u x :=\ninfi_univ\n\n@[simp] lemma bUnion_self (s : set \u03b1) : (\u22c3 x \u2208 s, s) = s :=\nsubset.antisymm (Union\u2082_subset $ \u03bb x hx, subset.refl s) (\u03bb x hx, mem_bUnion hx hx)\n\n@[simp] lemma Union_nonempty_self (s : set \u03b1) : (\u22c3 h : s.nonempty, s) = s :=\nby rw [Union_nonempty_index, bUnion_self]\n\n-- TODO(Jeremy): here is an artifact of the encoding of bounded intersection:\n-- without dsimp, the next theorem fails to type check, because there is a lambda\n-- in a type that needs to be contracted. Using simp [eq_of_mem_singleton xa] also works.\n\ntheorem bInter_singleton (a : \u03b1) (s : \u03b1 \u2192 set \u03b2) : (\u22c2 x \u2208 ({a} : set \u03b1), s x) = s a :=\ninfi_singleton\n\ntheorem bInter_union (s t : set \u03b1) (u : \u03b1 \u2192 set \u03b2) :\n  (\u22c2 x \u2208 s \u222a t, u x) = (\u22c2 x \u2208 s, u x) \u2229 (\u22c2 x \u2208 t, u x) :=\ninfi_union\n\ntheorem bInter_insert (a : \u03b1) (s : set \u03b1) (t : \u03b1 \u2192 set \u03b2) :\n  (\u22c2 x \u2208 insert a s, t x) = t a \u2229 (\u22c2 x \u2208 s, t x) :=\nby simp\n\n-- TODO(Jeremy): another example of where an annotation is needed\n\ntheorem bInter_pair (a b : \u03b1) (s : \u03b1 \u2192 set \u03b2) :\n  (\u22c2 x \u2208 ({a, b} : set \u03b1), s x) = s a \u2229 s b :=\nby rw [bInter_insert, bInter_singleton]\n\nlemma bInter_inter {\u03b9 \u03b1 : Type*} {s : set \u03b9} (hs : s.nonempty) (f : \u03b9 \u2192 set \u03b1) (t : set \u03b1) :\n  (\u22c2 i \u2208 s, f i \u2229 t) = (\u22c2 i \u2208 s, f i) \u2229 t :=\nbegin\n  haveI : nonempty s := hs.to_subtype,\n  simp [bInter_eq_Inter, \u2190 Inter_inter]\nend\n\nlemma inter_bInter {\u03b9 \u03b1 : Type*} {s : set \u03b9} (hs : s.nonempty) (f : \u03b9 \u2192 set \u03b1) (t : set \u03b1) :\n  (\u22c2 i \u2208 s, t \u2229 f i) = t \u2229 \u22c2 i \u2208 s, f i :=\nbegin\n  rw [inter_comm, \u2190 bInter_inter hs],\n  simp [inter_comm]\nend\n\ntheorem bUnion_empty (s : \u03b1 \u2192 set \u03b2) : (\u22c3 x \u2208 (\u2205 : set \u03b1), s x) = \u2205 :=\nsupr_emptyset\n\ntheorem bUnion_univ (s : \u03b1 \u2192 set \u03b2) : (\u22c3 x \u2208 @univ \u03b1, s x) = \u22c3 x, s x :=\nsupr_univ\n\ntheorem bUnion_singleton (a : \u03b1) (s : \u03b1 \u2192 set \u03b2) : (\u22c3 x \u2208 ({a} : set \u03b1), s x) = s a :=\nsupr_singleton\n\n@[simp] theorem bUnion_of_singleton (s : set \u03b1) : (\u22c3 x \u2208 s, {x}) = s :=\next $ by simp\n\ntheorem bUnion_union (s t : set \u03b1) (u : \u03b1 \u2192 set \u03b2) :\n  (\u22c3 x \u2208 s \u222a t, u x) = (\u22c3 x \u2208 s, u x) \u222a (\u22c3 x \u2208 t, u x) :=\nsupr_union\n\n@[simp] lemma Union_coe_set {\u03b1 \u03b2 : Type*} (s : set \u03b1) (f : s \u2192 set \u03b2) :\n  (\u22c3 i, f i) = \u22c3 i \u2208 s, f \u27e8i, \u2039i \u2208 s\u203a\u27e9 :=\nUnion_subtype _ _\n\n@[simp] lemma Inter_coe_set {\u03b1 \u03b2 : Type*} (s : set \u03b1) (f : s \u2192 set \u03b2) :\n  (\u22c2 i, f i) = \u22c2 i \u2208 s, f \u27e8i, \u2039i \u2208 s\u203a\u27e9 :=\nInter_subtype _ _\n\ntheorem bUnion_insert (a : \u03b1) (s : set \u03b1) (t : \u03b1 \u2192 set \u03b2) :\n  (\u22c3 x \u2208 insert a s, t x) = t a \u222a (\u22c3 x \u2208 s, t x) :=\nby simp\n\ntheorem bUnion_pair (a b : \u03b1) (s : \u03b1 \u2192 set \u03b2) :\n  (\u22c3 x \u2208 ({a, b} : set \u03b1), s x) = s a \u222a s b :=\nby simp\n\nlemma inter_Union\u2082 (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b1) : s \u2229 (\u22c3 i j, t i j) = \u22c3 i j, s \u2229 t i j :=\nby simp only [inter_Union]\n\nlemma Union\u2082_inter (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b1) : (\u22c3 i j, s i j) \u2229 t = \u22c3 i j, s i j \u2229 t :=\nby simp_rw Union_inter\n\nlemma union_Inter\u2082 (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b1) : s \u222a (\u22c2 i j, t i j) = \u22c2 i j, s \u222a t i j :=\nby simp_rw union_Inter\n\nlemma Inter\u2082_union (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b1) : (\u22c2 i j, s i j) \u222a t = \u22c2 i j, s i j \u222a t :=\nby simp_rw Inter_union\n\ntheorem mem_sUnion_of_mem {x : \u03b1} {t : set \u03b1} {S : set (set \u03b1)} (hx : x \u2208 t) (ht : t \u2208 S) :\n  x \u2208 \u22c3\u2080 S :=\n\u27e8t, ht, hx\u27e9\n\n-- is this theorem really necessary?\ntheorem not_mem_of_not_mem_sUnion {x : \u03b1} {t : set \u03b1} {S : set (set \u03b1)}\n  (hx : x \u2209 \u22c3\u2080 S) (ht : t \u2208 S) : x \u2209 t :=\n\u03bb h, hx \u27e8t, ht, h\u27e9\n\ntheorem sInter_subset_of_mem {S : set (set \u03b1)} {t : set \u03b1} (tS : t \u2208 S) : \u22c2\u2080 S \u2286 t :=\nInf_le tS\n\ntheorem subset_sUnion_of_mem {S : set (set \u03b1)} {t : set \u03b1} (tS : t \u2208 S) : t \u2286 \u22c3\u2080 S :=\nle_Sup tS\n\nlemma subset_sUnion_of_subset {s : set \u03b1} (t : set (set \u03b1)) (u : set \u03b1) (h\u2081 : s \u2286 u)\n  (h\u2082 : u \u2208 t) : s \u2286 \u22c3\u2080 t :=\nsubset.trans h\u2081 (subset_sUnion_of_mem h\u2082)\n\ntheorem sUnion_subset {S : set (set \u03b1)} {t : set \u03b1} (h : \u2200 t' \u2208 S, t' \u2286 t) : (\u22c3\u2080 S) \u2286 t :=\nSup_le h\n\n@[simp] theorem sUnion_subset_iff {s : set (set \u03b1)} {t : set \u03b1} : \u22c3\u2080 s \u2286 t \u2194 \u2200 t' \u2208 s, t' \u2286 t :=\n@Sup_le_iff (set \u03b1) _ _ _\n\ntheorem subset_sInter {S : set (set \u03b1)} {t : set \u03b1} (h : \u2200 t' \u2208 S, t \u2286 t') : t \u2286 (\u22c2\u2080 S) :=\nle_Inf h\n\n@[simp] theorem subset_sInter_iff {S : set (set \u03b1)} {t : set \u03b1} : t \u2286 (\u22c2\u2080 S) \u2194 \u2200 t' \u2208 S, t \u2286 t' :=\n@le_Inf_iff (set \u03b1) _ _ _\n\ntheorem sUnion_subset_sUnion {S T : set (set \u03b1)} (h : S \u2286 T) : \u22c3\u2080 S \u2286 \u22c3\u2080 T :=\nsUnion_subset $ \u03bb s hs, subset_sUnion_of_mem (h hs)\n\ntheorem sInter_subset_sInter {S T : set (set \u03b1)} (h : S \u2286 T) : \u22c2\u2080 T \u2286 \u22c2\u2080 S :=\nsubset_sInter $ \u03bb s hs, sInter_subset_of_mem (h hs)\n\n@[simp] theorem sUnion_empty : \u22c3\u2080 \u2205 = (\u2205 : set \u03b1) := Sup_empty\n\n@[simp] theorem sInter_empty : \u22c2\u2080 \u2205 = (univ : set \u03b1) := Inf_empty\n\n@[simp] theorem sUnion_singleton (s : set \u03b1) : \u22c3\u2080 {s} = s := Sup_singleton\n\n@[simp] theorem sInter_singleton (s : set \u03b1) : \u22c2\u2080 {s} = s := Inf_singleton\n\n@[simp] theorem sUnion_eq_empty {S : set (set \u03b1)} : (\u22c3\u2080 S) = \u2205 \u2194 \u2200 s \u2208 S, s = \u2205 := Sup_eq_bot\n\n@[simp] theorem sInter_eq_univ {S : set (set \u03b1)} : (\u22c2\u2080 S) = univ \u2194 \u2200 s \u2208 S, s = univ := Inf_eq_top\n\n@[simp] theorem nonempty_sUnion {S : set (set \u03b1)} : (\u22c3\u2080 S).nonempty \u2194 \u2203 s \u2208 S, set.nonempty s :=\nby simp [nonempty_iff_ne_empty]\n\nlemma nonempty.of_sUnion {s : set (set \u03b1)} (h : (\u22c3\u2080 s).nonempty) : s.nonempty :=\nlet \u27e8s, hs, _\u27e9 := nonempty_sUnion.1 h in \u27e8s, hs\u27e9\n\nlemma nonempty.of_sUnion_eq_univ [nonempty \u03b1] {s : set (set \u03b1)} (h : \u22c3\u2080 s = univ) : s.nonempty :=\nnonempty.of_sUnion $ h.symm \u25b8 univ_nonempty\n\ntheorem sUnion_union (S T : set (set \u03b1)) : \u22c3\u2080 (S \u222a T) = \u22c3\u2080 S \u222a \u22c3\u2080 T := Sup_union\n\ntheorem sInter_union (S T : set (set \u03b1)) : \u22c2\u2080 (S \u222a T) = \u22c2\u2080 S \u2229 \u22c2\u2080 T := Inf_union\n\n@[simp] theorem sUnion_insert (s : set \u03b1) (T : set (set \u03b1)) : \u22c3\u2080 (insert s T) = s \u222a \u22c3\u2080 T :=\nSup_insert\n\n@[simp] theorem sInter_insert (s : set \u03b1) (T : set (set \u03b1)) : \u22c2\u2080 (insert s T) = s \u2229 \u22c2\u2080 T :=\nInf_insert\n\n@[simp] lemma sUnion_diff_singleton_empty (s : set (set \u03b1)) : \u22c3\u2080 (s \\ {\u2205}) = \u22c3\u2080 s :=\nSup_diff_singleton_bot s\n\n@[simp] lemma sInter_diff_singleton_univ (s : set (set \u03b1)) : \u22c2\u2080 (s \\ {univ}) = \u22c2\u2080 s :=\nInf_diff_singleton_top s\n\ntheorem sUnion_pair (s t : set \u03b1) : \u22c3\u2080 {s, t} = s \u222a t :=\nSup_pair\n\ntheorem sInter_pair (s t : set \u03b1) : \u22c2\u2080 {s, t} = s \u2229 t :=\nInf_pair\n\n@[simp] theorem sUnion_image (f : \u03b1 \u2192 set \u03b2) (s : set \u03b1) : \u22c3\u2080 (f '' s) = \u22c3 x \u2208 s, f x := Sup_image\n\n@[simp] theorem sInter_image (f : \u03b1 \u2192 set \u03b2) (s : set \u03b1) : \u22c2\u2080 (f '' s) = \u22c2 x \u2208 s, f x := Inf_image\n\n@[simp] theorem sUnion_range (f : \u03b9 \u2192 set \u03b2) : \u22c3\u2080 (range f) = \u22c3 x, f x := rfl\n\n@[simp] theorem sInter_range (f : \u03b9 \u2192 set \u03b2) : \u22c2\u2080 (range f) = \u22c2 x, f x := rfl\n\nlemma Union_eq_univ_iff {f : \u03b9 \u2192 set \u03b1} : (\u22c3 i, f i) = univ \u2194 \u2200 x, \u2203 i, x \u2208 f i :=\nby simp only [eq_univ_iff_forall, mem_Union]\n\nlemma Union\u2082_eq_univ_iff {s : \u03a0 i, \u03ba i \u2192 set \u03b1} : (\u22c3 i j, s i j) = univ \u2194 \u2200 a, \u2203 i j, a \u2208 s i j :=\nby simp only [Union_eq_univ_iff, mem_Union]\n\nlemma sUnion_eq_univ_iff {c : set (set \u03b1)} :\n  \u22c3\u2080 c = univ \u2194 \u2200 a, \u2203 b \u2208 c, a \u2208 b :=\nby simp only [eq_univ_iff_forall, mem_sUnion]\n\n-- classical\nlemma Inter_eq_empty_iff {f : \u03b9 \u2192 set \u03b1} : (\u22c2 i, f i) = \u2205 \u2194 \u2200 x, \u2203 i, x \u2209 f i :=\nby simp [set.eq_empty_iff_forall_not_mem]\n\n-- classical\nlemma Inter\u2082_eq_empty_iff {s : \u03a0 i, \u03ba i \u2192 set \u03b1} : (\u22c2 i j, s i j) = \u2205 \u2194 \u2200 a, \u2203 i j, a \u2209 s i j :=\nby simp only [eq_empty_iff_forall_not_mem, mem_Inter, not_forall]\n\n-- classical\nlemma sInter_eq_empty_iff {c : set (set \u03b1)} :\n  \u22c2\u2080 c = \u2205 \u2194 \u2200 a, \u2203 b \u2208 c, a \u2209 b :=\nby simp [set.eq_empty_iff_forall_not_mem]\n\n-- classical\n@[simp] theorem nonempty_Inter {f : \u03b9 \u2192 set \u03b1} : (\u22c2 i, f i).nonempty \u2194 \u2203 x, \u2200 i, x \u2208 f i :=\nby simp [nonempty_iff_ne_empty, Inter_eq_empty_iff]\n\n-- classical\n@[simp] lemma nonempty_Inter\u2082 {s : \u03a0 i, \u03ba i \u2192 set \u03b1} :\n  (\u22c2 i j, s i j).nonempty \u2194 \u2203 a, \u2200 i j, a \u2208 s i j :=\nby simp [nonempty_iff_ne_empty, Inter_eq_empty_iff]\n\n-- classical\n@[simp] theorem nonempty_sInter {c : set (set \u03b1)}:\n  (\u22c2\u2080 c).nonempty \u2194 \u2203 a, \u2200 b \u2208 c, a \u2208 b :=\nby simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]\n\n-- classical\ntheorem compl_sUnion (S : set (set \u03b1)) :\n  (\u22c3\u2080 S)\u1d9c = \u22c2\u2080 (compl '' S) :=\next $ \u03bb x, by simp\n\n-- classical\ntheorem sUnion_eq_compl_sInter_compl (S : set (set \u03b1)) :\n  \u22c3\u2080 S = (\u22c2\u2080 (compl '' S))\u1d9c :=\nby rw [\u2190compl_compl (\u22c3\u2080 S), compl_sUnion]\n\n-- classical\ntheorem compl_sInter (S : set (set \u03b1)) :\n  (\u22c2\u2080 S)\u1d9c = \u22c3\u2080 (compl '' S) :=\nby rw [sUnion_eq_compl_sInter_compl, compl_compl_image]\n\n-- classical\ntheorem sInter_eq_compl_sUnion_compl (S : set (set \u03b1)) :\n   \u22c2\u2080 S = (\u22c3\u2080 (compl '' S))\u1d9c :=\nby rw [\u2190compl_compl (\u22c2\u2080 S), compl_sInter]\n\ntheorem inter_empty_of_inter_sUnion_empty {s t : set \u03b1} {S : set (set \u03b1)} (hs : t \u2208 S)\n    (h : s \u2229 \u22c3\u2080 S = \u2205) :\n  s \u2229 t = \u2205 :=\neq_empty_of_subset_empty $ by rw \u2190 h; exact\ninter_subset_inter_right _ (subset_sUnion_of_mem hs)\n\ntheorem range_sigma_eq_Union_range {\u03b3 : \u03b1 \u2192 Type*} (f : sigma \u03b3 \u2192 \u03b2) :\n  range f = \u22c3 a, range (\u03bb b, f \u27e8a, b\u27e9) :=\nset.ext $ by simp\n\ntheorem Union_eq_range_sigma (s : \u03b1 \u2192 set \u03b2) : (\u22c3 i, s i) = range (\u03bb a : \u03a3 i, s i, a.2) :=\nby simp [set.ext_iff]\n\ntheorem Union_eq_range_psigma (s : \u03b9 \u2192 set \u03b2) : (\u22c3 i, s i) = range (\u03bb a : \u03a3' i, s i, a.2) :=\nby simp [set.ext_iff]\n\ntheorem Union_image_preimage_sigma_mk_eq_self {\u03b9 : Type*} {\u03c3 : \u03b9 \u2192 Type*} (s : set (sigma \u03c3)) :\n  (\u22c3 i, sigma.mk i '' (sigma.mk i \u207b\u00b9' s)) = s :=\nbegin\n  ext x,\n  simp only [mem_Union, mem_image, mem_preimage],\n  split,\n  { rintro \u27e8i, a, h, rfl\u27e9, exact h },\n  { intro h, cases x with i a, exact \u27e8i, a, h, rfl\u27e9 }\nend\n\nlemma sigma.univ (X : \u03b1 \u2192 Type*) : (set.univ : set (\u03a3 a, X a)) = \u22c3 a, range (sigma.mk a) :=\nset.ext $ \u03bb x, iff_of_true trivial \u27e8range (sigma.mk x.1), set.mem_range_self _, x.2, sigma.eta x\u27e9\n\nlemma sUnion_mono {s t : set (set \u03b1)} (h : s \u2286 t) : (\u22c3\u2080 s) \u2286 (\u22c3\u2080 t) :=\nsUnion_subset $ \u03bb t' ht', subset_sUnion_of_mem $ h ht'\n\nlemma Union_subset_Union_const {s : set \u03b1} (h : \u03b9 \u2192 \u03b9\u2082) : (\u22c3 i : \u03b9, s) \u2286 (\u22c3 j : \u03b9\u2082, s) :=\n@supr_const_mono (set \u03b1) \u03b9 \u03b9\u2082 _ s h\n\n@[simp] lemma Union_singleton_eq_range {\u03b1 \u03b2 : Type*} (f : \u03b1 \u2192 \u03b2) :\n  (\u22c3 (x : \u03b1), {f x}) = range f :=\nby { ext x, simp [@eq_comm _ x] }\n\nlemma Union_of_singleton (\u03b1 : Type*) : (\u22c3 x, {x} : set \u03b1) = univ :=\nby simp\n\nlemma Union_of_singleton_coe (s : set \u03b1) :\n  (\u22c3 (i : s), {i} : set \u03b1) = s :=\nby simp\n\nlemma sUnion_eq_bUnion {s : set (set \u03b1)} : (\u22c3\u2080 s) = (\u22c3 (i : set \u03b1) (h : i \u2208 s), i) :=\nby rw [\u2190 sUnion_image, image_id']\n\nlemma sInter_eq_bInter {s : set (set \u03b1)} : (\u22c2\u2080 s) = (\u22c2 (i : set \u03b1) (h : i \u2208 s), i) :=\nby rw [\u2190 sInter_image, image_id']\n\nlemma sUnion_eq_Union {s : set (set \u03b1)} : (\u22c3\u2080 s) = (\u22c3 (i : s), i) :=\nby simp only [\u2190sUnion_range, subtype.range_coe]\n\nlemma sInter_eq_Inter {s : set (set \u03b1)} : (\u22c2\u2080 s) = (\u22c2 (i : s), i) :=\nby simp only [\u2190sInter_range, subtype.range_coe]\n\n@[simp] lemma Union_of_empty [is_empty \u03b9] (s : \u03b9 \u2192 set \u03b1) : (\u22c3 i, s i) = \u2205 := supr_of_empty _\n@[simp] lemma Inter_of_empty [is_empty \u03b9] (s : \u03b9 \u2192 set \u03b1) : (\u22c2 i, s i) = univ := infi_of_empty _\n\nlemma union_eq_Union {s\u2081 s\u2082 : set \u03b1} : s\u2081 \u222a s\u2082 = \u22c3 b : bool, cond b s\u2081 s\u2082 :=\nsup_eq_supr s\u2081 s\u2082\n\nlemma inter_eq_Inter {s\u2081 s\u2082 : set \u03b1} : s\u2081 \u2229 s\u2082 = \u22c2 b : bool, cond b s\u2081 s\u2082 :=\ninf_eq_infi s\u2081 s\u2082\n\nlemma sInter_union_sInter {S T : set (set \u03b1)} :\n  (\u22c2\u2080 S) \u222a (\u22c2\u2080 T) = (\u22c2 p \u2208 S \u00d7\u02e2 T, (p : (set \u03b1) \u00d7 (set \u03b1)).1 \u222a p.2) :=\nInf_sup_Inf\n\nlemma sUnion_inter_sUnion {s t : set (set \u03b1)} :\n  (\u22c3\u2080 s) \u2229 (\u22c3\u2080 t) = (\u22c3 p \u2208 s \u00d7\u02e2 t, (p : (set \u03b1) \u00d7 (set \u03b1 )).1 \u2229 p.2) :=\nSup_inf_Sup\n\nlemma bUnion_Union (s : \u03b9 \u2192 set \u03b1) (t : \u03b1 \u2192 set \u03b2) :\n  (\u22c3 x \u2208 \u22c3 i, s i, t x) = \u22c3 i (x \u2208 s i), t x :=\nby simp [@Union_comm _ \u03b9]\n\nlemma bInter_Union (s : \u03b9 \u2192 set \u03b1) (t : \u03b1 \u2192 set \u03b2) :\n  (\u22c2 x \u2208 \u22c3 i, s i, t x) = \u22c2 i (x \u2208 s i), t x :=\nby simp [@Inter_comm _ \u03b9]\n\nlemma sUnion_Union (s : \u03b9 \u2192 set (set \u03b1)) : \u22c3\u2080 (\u22c3 i, s i) = \u22c3 i, \u22c3\u2080 (s i) :=\nby simp only [sUnion_eq_bUnion, bUnion_Union]\n\ntheorem sInter_Union (s : \u03b9 \u2192 set (set \u03b1)) : \u22c2\u2080 (\u22c3 i, s i) = \u22c2 i, \u22c2\u2080 s i :=\nby simp only [sInter_eq_bInter, bInter_Union]\n\nlemma Union_range_eq_sUnion {\u03b1 \u03b2 : Type*} (C : set (set \u03b1))\n  {f : \u2200 (s : C), \u03b2 \u2192 s} (hf : \u2200 (s : C), surjective (f s)) :\n  (\u22c3 (y : \u03b2), range (\u03bb (s : C), (f s y).val)) = \u22c3\u2080 C :=\nbegin\n  ext x, split,\n  { rintro \u27e8s, \u27e8y, rfl\u27e9, \u27e8s, hs\u27e9, rfl\u27e9, refine \u27e8_, hs, _\u27e9, exact (f \u27e8s, hs\u27e9 y).2 },\n  { rintro \u27e8s, hs, hx\u27e9, cases hf \u27e8s, hs\u27e9 \u27e8x, hx\u27e9 with y hy, refine \u27e8_, \u27e8y, rfl\u27e9, \u27e8s, hs\u27e9, _\u27e9,\n    exact congr_arg subtype.val hy }\nend\n\n\n\nlemma union_distrib_Inter_left (s : \u03b9 \u2192 set \u03b1) (t : set \u03b1) : t \u222a (\u22c2 i, s i) = (\u22c2 i, t \u222a s i) :=\nsup_infi_eq _ _\n\nlemma union_distrib_Inter\u2082_left (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b1) :\n  s \u222a (\u22c2 i j, t i j) = \u22c2 i j, s \u222a t i j :=\nby simp_rw union_distrib_Inter_left\n\nlemma union_distrib_Inter_right (s : \u03b9 \u2192 set \u03b1) (t : set \u03b1) : (\u22c2 i, s i) \u222a t = (\u22c2 i, s i \u222a t) :=\ninfi_sup_eq _ _\n\nlemma union_distrib_Inter\u2082_right (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b1) :\n  (\u22c2 i j, s i j) \u222a t = \u22c2 i j, s i j \u222a t :=\nby simp_rw union_distrib_Inter_right\n\n\nsection function\n\n/-! ### `maps_to` -/\n\nlemma maps_to_sUnion {S : set (set \u03b1)} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2} (H : \u2200 s \u2208 S, maps_to f s t) :\n  maps_to f (\u22c3\u2080 S) t :=\n\u03bb x \u27e8s, hs, hx\u27e9, H s hs hx\n\nlemma maps_to_Union {s : \u03b9 \u2192 set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2} (H : \u2200 i, maps_to f (s i) t) :\n  maps_to f (\u22c3 i, s i) t :=\nmaps_to_sUnion $ forall_range_iff.2 H\n\nlemma maps_to_Union\u2082 {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i j, maps_to f (s i j) t) :\n  maps_to f (\u22c3 i j, s i j) t :=\nmaps_to_Union $ \u03bb i, maps_to_Union (H i)\n\nlemma maps_to_Union_Union {s : \u03b9 \u2192 set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i, maps_to f (s i) (t i)) :\n  maps_to f (\u22c3 i, s i) (\u22c3 i, t i) :=\nmaps_to_Union $ \u03bb i, (H i).mono (subset.refl _) (subset_Union t i)\n\nlemma maps_to_Union\u2082_Union\u2082 {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i j, maps_to f (s i j) (t i j)) :\n  maps_to f (\u22c3 i j, s i j) (\u22c3 i j, t i j) :=\nmaps_to_Union_Union $ \u03bb i, maps_to_Union_Union (H i)\n\nlemma maps_to_sInter {s : set \u03b1} {T : set (set \u03b2)} {f : \u03b1 \u2192 \u03b2} (H : \u2200 t \u2208 T, maps_to f s t) :\n  maps_to f s (\u22c2\u2080 T) :=\n\u03bb x hx t ht, H t ht hx\n\nlemma maps_to_Inter {s : set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2} (H : \u2200 i, maps_to f s (t i)) :\n  maps_to f s (\u22c2 i, t i) :=\n\u03bb x hx, mem_Inter.2 $ \u03bb i, H i hx\n\nlemma maps_to_Inter\u2082 {s : set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i j, maps_to f s (t i j)) :\n  maps_to f s (\u22c2 i j, t i j) :=\nmaps_to_Inter $ \u03bb i, maps_to_Inter (H i)\n\nlemma maps_to_Inter_Inter {s : \u03b9 \u2192 set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i, maps_to f (s i) (t i)) :\n  maps_to f (\u22c2 i, s i) (\u22c2 i, t i) :=\nmaps_to_Inter $ \u03bb i, (H i).mono (Inter_subset s i) (subset.refl _)\n\nlemma maps_to_Inter\u2082_Inter\u2082 {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i j, maps_to f (s i j) (t i j)) :\n  maps_to f (\u22c2 i j, s i j) (\u22c2 i j, t i j) :=\nmaps_to_Inter_Inter $ \u03bb i, maps_to_Inter_Inter (H i)\n\nlemma image_Inter_subset (s : \u03b9 \u2192 set \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  f '' (\u22c2 i, s i) \u2286 \u22c2 i, f '' (s i) :=\n(maps_to_Inter_Inter $ \u03bb i, maps_to_image f (s i)).image_subset\n\nlemma image_Inter\u2082_subset (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  f '' (\u22c2 i j, s i j) \u2286 \u22c2 i j, f '' s i j :=\n(maps_to_Inter\u2082_Inter\u2082 $ \u03bb i hi, maps_to_image f (s i hi)).image_subset\n\nlemma image_sInter_subset (S : set (set \u03b1)) (f : \u03b1 \u2192 \u03b2) :\n  f '' (\u22c2\u2080 S) \u2286 \u22c2 s \u2208 S, f '' s :=\nby { rw sInter_eq_bInter, apply image_Inter\u2082_subset }\n\n/-! ### `restrict_preimage` -/\nsection\n\nopen function\n\nvariables (s : set \u03b2) {f : \u03b1 \u2192 \u03b2} {U : \u03b9 \u2192 set \u03b2} (hU : Union U = univ)\n\ninclude hU\n\nlemma injective_iff_injective_of_Union_eq_univ :\n  injective f \u2194 \u2200 i, injective ((U i).restrict_preimage f) :=\nbegin\n  refine \u27e8\u03bb H i, (U i).restrict_preimage_injective H, \u03bb H x y e, _\u27e9,\n  obtain \u27e8i, hi\u27e9 := set.mem_Union.mp (show f x \u2208 set.Union U, by { rw hU, triv }),\n  injection @H i \u27e8x, hi\u27e9 \u27e8y, show f y \u2208 U i, from e \u25b8 hi\u27e9 (subtype.ext e)\nend\n\nlemma surjective_iff_surjective_of_Union_eq_univ :\n  surjective f \u2194 \u2200 i, surjective ((U i).restrict_preimage f) :=\nbegin\n  refine \u27e8\u03bb H i, (U i).restrict_preimage_surjective H, \u03bb H x, _\u27e9,\n  obtain \u27e8i, hi\u27e9 := set.mem_Union.mp (show x \u2208 set.Union U, by { rw hU, triv }),\n  exact \u27e8_, congr_arg subtype.val (H i \u27e8x, hi\u27e9).some_spec\u27e9\nend\n\nlemma bijective_iff_bijective_of_Union_eq_univ :\n  bijective f \u2194 \u2200 i, bijective ((U i).restrict_preimage f) :=\nby simp_rw [bijective, forall_and_distrib, injective_iff_injective_of_Union_eq_univ hU,\n  surjective_iff_surjective_of_Union_eq_univ hU]\nend\n\n/-! ### `inj_on` -/\n\nlemma inj_on.image_Inter_eq [nonempty \u03b9] {s : \u03b9 \u2192 set \u03b1} {f : \u03b1 \u2192 \u03b2} (h : inj_on f (\u22c3 i, s i)) :\n  f '' (\u22c2 i, s i) = \u22c2 i, f '' (s i) :=\nbegin\n  inhabit \u03b9,\n  refine subset.antisymm (image_Inter_subset s f) (\u03bb y hy, _),\n  simp only [mem_Inter, mem_image_iff_bex] at hy,\n  choose x hx hy using hy,\n  refine \u27e8x default, mem_Inter.2 $ \u03bb i, _, hy _\u27e9,\n  suffices : x default = x i,\n  { rw this, apply hx },\n  replace hx : \u2200 i, x i \u2208 \u22c3 j, s j := \u03bb i, (subset_Union _ _) (hx i),\n  apply h (hx _) (hx _),\n  simp only [hy]\nend\n\nlemma inj_on.image_bInter_eq {p : \u03b9 \u2192 Prop} {s : \u03a0 i (hi : p i), set \u03b1} (hp : \u2203 i, p i) {f : \u03b1 \u2192 \u03b2}\n  (h : inj_on f (\u22c3 i hi, s i hi)) :\n  f '' (\u22c2 i hi, s i hi) = \u22c2 i hi, f '' (s i hi) :=\nbegin\n  simp only [Inter, infi_subtype'],\n  haveI : nonempty {i // p i} := nonempty_subtype.2 hp,\n  apply inj_on.image_Inter_eq,\n  simpa only [Union, supr_subtype'] using h\nend\n\nlemma image_Inter {f : \u03b1 \u2192 \u03b2} (hf : bijective f) (s : \u03b9 \u2192 set \u03b1) :\n  f '' (\u22c2 i, s i) = \u22c2 i, f '' s i :=\nbegin\n  casesI is_empty_or_nonempty \u03b9,\n  { simp_rw [Inter_of_empty, image_univ_of_surjective hf.surjective] },\n  { exact (hf.injective.inj_on _).image_Inter_eq }\nend\n\nlemma image_Inter\u2082 {f : \u03b1 \u2192 \u03b2} (hf : bijective f) (s : \u03a0 i, \u03ba i \u2192 set \u03b1) :\n  f '' (\u22c2 i j, s i j) = \u22c2 i j, f '' s i j :=\nby simp_rw image_Inter hf\n\nlemma inj_on_Union_of_directed {s : \u03b9 \u2192 set \u03b1} (hs : directed (\u2286) s)\n  {f : \u03b1 \u2192 \u03b2} (hf : \u2200 i, inj_on f (s i)) :\n  inj_on f (\u22c3 i, s i) :=\nbegin\n  intros x hx y hy hxy,\n  rcases mem_Union.1 hx with \u27e8i, hx\u27e9,\n  rcases mem_Union.1 hy with \u27e8j, hy\u27e9,\n  rcases hs i j with \u27e8k, hi, hj\u27e9,\n  exact hf k (hi hx) (hj hy) hxy\nend\n\n/-! ### `surj_on` -/\n\nlemma surj_on_sUnion {s : set \u03b1} {T : set (set \u03b2)} {f : \u03b1 \u2192 \u03b2} (H : \u2200 t \u2208 T, surj_on f s t) :\n  surj_on f s (\u22c3\u2080 T) :=\n\u03bb x \u27e8t, ht, hx\u27e9, H t ht hx\n\nlemma surj_on_Union {s : set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2} (H : \u2200 i, surj_on f s (t i)) :\n  surj_on f s (\u22c3 i, t i) :=\nsurj_on_sUnion $ forall_range_iff.2 H\n\nlemma surj_on_Union_Union {s : \u03b9 \u2192 set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i, surj_on f (s i) (t i)) :\n  surj_on f (\u22c3 i, s i) (\u22c3 i, t i) :=\nsurj_on_Union $ \u03bb i, (H i).mono (subset_Union _ _) (subset.refl _)\n\nlemma surj_on_Union\u2082 {s : set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i j, surj_on f s (t i j)) :\n  surj_on f s (\u22c3 i j, t i j) :=\nsurj_on_Union $ \u03bb i, surj_on_Union (H i)\n\nlemma surj_on_Union\u2082_Union\u2082 {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i j, surj_on f (s i j) (t i j)) :\n  surj_on f (\u22c3 i j, s i j) (\u22c3 i j, t i j) :=\nsurj_on_Union_Union $ \u03bb i, surj_on_Union_Union (H i)\n\nlemma surj_on_Inter [hi : nonempty \u03b9] {s : \u03b9 \u2192 set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i, surj_on f (s i) t) (Hinj : inj_on f (\u22c3 i, s i)) :\n  surj_on f (\u22c2 i, s i) t :=\nbegin\n  intros y hy,\n  rw [Hinj.image_Inter_eq, mem_Inter],\n  exact \u03bb i, H i hy\nend\n\nlemma surj_on_Inter_Inter [hi : nonempty \u03b9] {s : \u03b9 \u2192 set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i, surj_on f (s i) (t i)) (Hinj : inj_on f (\u22c3 i, s i)) :\n  surj_on f (\u22c2 i, s i) (\u22c2 i, t i) :=\nsurj_on_Inter (\u03bb i, (H i).mono (subset.refl _) (Inter_subset _ _)) Hinj\n\n/-! ### `bij_on` -/\n\nlemma bij_on_Union {s : \u03b9 \u2192 set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2} (H : \u2200 i, bij_on f (s i) (t i))\n  (Hinj : inj_on f (\u22c3 i, s i)) :\n  bij_on f (\u22c3 i, s i) (\u22c3 i, t i) :=\n\u27e8maps_to_Union_Union $ \u03bb i, (H i).maps_to, Hinj, surj_on_Union_Union $ \u03bb i, (H i).surj_on\u27e9\n\nlemma bij_on_Inter [hi :nonempty \u03b9] {s : \u03b9 \u2192 set \u03b1} {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i, bij_on f (s i) (t i)) (Hinj : inj_on f (\u22c3 i, s i)) :\n  bij_on f (\u22c2 i, s i) (\u22c2 i, t i) :=\n\u27e8maps_to_Inter_Inter $ \u03bb i, (H i).maps_to, hi.elim $ \u03bb i, (H i).inj_on.mono (Inter_subset _ _),\n  surj_on_Inter_Inter (\u03bb i, (H i).surj_on) Hinj\u27e9\n\nlemma bij_on_Union_of_directed {s : \u03b9 \u2192 set \u03b1} (hs : directed (\u2286) s) {t : \u03b9 \u2192 set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (H : \u2200 i, bij_on f (s i) (t i)) :\n  bij_on f (\u22c3 i, s i) (\u22c3 i, t i) :=\nbij_on_Union H $ inj_on_Union_of_directed hs (\u03bb i, (H i).inj_on)\n\nlemma bij_on_Inter_of_directed [nonempty \u03b9] {s : \u03b9 \u2192 set \u03b1} (hs : directed (\u2286) s) {t : \u03b9 \u2192 set \u03b2}\n  {f : \u03b1 \u2192 \u03b2} (H : \u2200 i, bij_on f (s i) (t i)) :\n  bij_on f (\u22c2 i, s i) (\u22c2 i, t i) :=\nbij_on_Inter H $ inj_on_Union_of_directed hs (\u03bb i, (H i).inj_on)\n\nend function\n\n/-! ### `image`, `preimage` -/\n\nsection image\n\nlemma image_Union {f : \u03b1 \u2192 \u03b2} {s : \u03b9 \u2192 set \u03b1} : f '' (\u22c3 i, s i) = (\u22c3 i, f '' s i) :=\nbegin\n  ext1 x,\n  simp [image, \u2190 exists_and_distrib_right, @exists_swap \u03b1]\nend\n\nlemma image_Union\u2082 (f : \u03b1 \u2192 \u03b2) (s : \u03a0 i, \u03ba i \u2192 set \u03b1) : f '' (\u22c3 i j, s i j) = \u22c3 i j, f '' s i j :=\nby simp_rw image_Union\n\nlemma univ_subtype {p : \u03b1 \u2192 Prop} : (univ : set (subtype p)) = (\u22c3 x (h : p x), {\u27e8x, h\u27e9}) :=\nset.ext $ \u03bb \u27e8x, h\u27e9, by simp [h]\n\nlemma range_eq_Union {\u03b9} (f : \u03b9 \u2192 \u03b1) : range f = (\u22c3 i, {f i}) :=\nset.ext $ \u03bb a, by simp [@eq_comm \u03b1 a]\n\nlemma image_eq_Union (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) : f '' s = (\u22c3 i \u2208 s, {f i}) :=\nset.ext $ \u03bb b, by simp [@eq_comm \u03b2 b]\n\nlemma bUnion_range {f : \u03b9 \u2192 \u03b1} {g : \u03b1 \u2192 set \u03b2} : (\u22c3 x \u2208 range f, g x) = (\u22c3 y, g (f y)) :=\nsupr_range\n\n@[simp] lemma Union_Union_eq' {f : \u03b9 \u2192 \u03b1} {g : \u03b1 \u2192 set \u03b2} :\n  (\u22c3 x y (h : f y = x), g x) = \u22c3 y, g (f y) :=\nby simpa using bUnion_range\n\nlemma bInter_range {f : \u03b9 \u2192 \u03b1} {g : \u03b1 \u2192 set \u03b2} : (\u22c2 x \u2208 range f, g x) = (\u22c2 y, g (f y)) :=\ninfi_range\n\n@[simp] lemma Inter_Inter_eq' {f : \u03b9 \u2192 \u03b1} {g : \u03b1 \u2192 set \u03b2} :\n  (\u22c2 x y (h : f y = x), g x) = \u22c2 y, g (f y) :=\nby simpa using bInter_range\n\nvariables {s : set \u03b3} {f : \u03b3 \u2192 \u03b1} {g : \u03b1 \u2192 set \u03b2}\n\nlemma bUnion_image : (\u22c3 x \u2208 f '' s, g x) = (\u22c3 y \u2208 s, g (f y)) :=\nsupr_image\n\nlemma bInter_image : (\u22c2 x \u2208 f '' s, g x) = (\u22c2 y \u2208 s, g (f y)) :=\ninfi_image\n\nend image\n\nsection preimage\n\ntheorem monotone_preimage {f : \u03b1 \u2192 \u03b2} : monotone (preimage f) := \u03bb a b h, preimage_mono h\n\n@[simp] lemma preimage_Union {f : \u03b1 \u2192 \u03b2} {s : \u03b9 \u2192 set \u03b2} : f \u207b\u00b9' (\u22c3 i, s i) = (\u22c3 i, f \u207b\u00b9' s i) :=\nset.ext $ by simp [preimage]\n\nlemma preimage_Union\u2082 {f : \u03b1 \u2192 \u03b2} {s : \u03a0 i, \u03ba i \u2192 set \u03b2} :\n  f \u207b\u00b9' (\u22c3 i j, s i j) = \u22c3 i j, f \u207b\u00b9' s i j :=\nby simp_rw preimage_Union\n\n@[simp] theorem preimage_sUnion {f : \u03b1 \u2192 \u03b2} {s : set (set \u03b2)} :\n  f \u207b\u00b9' (\u22c3\u2080 s) = (\u22c3 t \u2208 s, f \u207b\u00b9' t) :=\nby rw [sUnion_eq_bUnion, preimage_Union\u2082]\n\nlemma preimage_Inter {f : \u03b1 \u2192 \u03b2} {s : \u03b9 \u2192 set \u03b2} : f \u207b\u00b9' (\u22c2 i, s i) = (\u22c2 i, f \u207b\u00b9' s i) :=\nby ext; simp\n\nlemma preimage_Inter\u2082 {f : \u03b1 \u2192 \u03b2} {s : \u03a0 i, \u03ba i \u2192 set \u03b2} :\n  f \u207b\u00b9' (\u22c2 i j, s i j) = \u22c2 i j, f \u207b\u00b9' s i j :=\nby simp_rw preimage_Inter\n\n@[simp] lemma preimage_sInter {f : \u03b1 \u2192 \u03b2} {s : set (set \u03b2)} : f \u207b\u00b9' (\u22c2\u2080 s) = \u22c2 t \u2208 s, f \u207b\u00b9' t :=\nby rw [sInter_eq_bInter, preimage_Inter\u2082]\n\n@[simp] lemma bUnion_preimage_singleton (f : \u03b1 \u2192 \u03b2) (s : set \u03b2) : (\u22c3 y \u2208 s, f \u207b\u00b9' {y}) = f \u207b\u00b9' s :=\nby rw [\u2190 preimage_Union\u2082, bUnion_of_singleton]\n\nlemma bUnion_range_preimage_singleton (f : \u03b1 \u2192 \u03b2) : (\u22c3 y \u2208 range f, f \u207b\u00b9' {y}) = univ :=\nby rw [bUnion_preimage_singleton, preimage_range]\n\nend preimage\n\nsection prod\n\nlemma prod_Union {s : set \u03b1} {t : \u03b9 \u2192 set \u03b2} : s \u00d7\u02e2 (\u22c3 i, t i) = \u22c3 i, s \u00d7\u02e2 (t i) := by { ext, simp }\n\nlemma prod_Union\u2082 {s : set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b2} : s \u00d7\u02e2 (\u22c3 i j, t i j) = \u22c3 i j, s \u00d7\u02e2 t i j :=\nby simp_rw [prod_Union]\n\nlemma prod_sUnion {s : set \u03b1} {C : set (set \u03b2)} : s \u00d7\u02e2 (\u22c3\u2080 C) = \u22c3\u2080 ((\u03bb t, s \u00d7\u02e2 t) '' C) :=\nby simp_rw [sUnion_eq_bUnion, bUnion_image, prod_Union\u2082]\n\nlemma Union_prod_const {s : \u03b9 \u2192 set \u03b1} {t : set \u03b2} : (\u22c3 i, s i) \u00d7\u02e2 t = \u22c3 i, s i \u00d7\u02e2 t :=\nby { ext, simp }\n\nlemma Union\u2082_prod_const {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : set \u03b2} :\n  (\u22c3 i j, s i j) \u00d7\u02e2 t = \u22c3 i j, s i j \u00d7\u02e2 t :=\nby simp_rw [Union_prod_const]\n\nlemma sUnion_prod_const {C : set (set \u03b1)} {t : set \u03b2} :\n  (\u22c3\u2080 C) \u00d7\u02e2 t = \u22c3\u2080 ((\u03bb s : set \u03b1, s \u00d7\u02e2 t) '' C) :=\nby simp only [sUnion_eq_bUnion, Union\u2082_prod_const, bUnion_image]\n\nlemma Union_prod {\u03b9 \u03b9' \u03b1 \u03b2} (s : \u03b9 \u2192 set \u03b1) (t : \u03b9' \u2192 set \u03b2) :\n  (\u22c3 (x : \u03b9 \u00d7 \u03b9'), s x.1 \u00d7\u02e2 t x.2) = (\u22c3 (i : \u03b9), s i) \u00d7\u02e2 (\u22c3 (i : \u03b9'), t i) :=\nby { ext, simp }\n\nlemma Union_prod_of_monotone [semilattice_sup \u03b1] {s : \u03b1 \u2192 set \u03b2} {t : \u03b1 \u2192 set \u03b3}\n  (hs : monotone s) (ht : monotone t) : (\u22c3 x, s x \u00d7\u02e2 t x) = (\u22c3 x, s x) \u00d7\u02e2 (\u22c3 x, t x) :=\nbegin\n  ext \u27e8z, w\u27e9, simp only [mem_prod, mem_Union, exists_imp_distrib, and_imp, iff_def], split,\n  { intros x hz hw, exact \u27e8\u27e8x, hz\u27e9, x, hw\u27e9 },\n  { intros x hz x' hw, exact \u27e8x \u2294 x', hs le_sup_left hz, ht le_sup_right hw\u27e9 }\nend\n\nlemma sInter_prod_sInter_subset (S : set (set \u03b1)) (T : set (set \u03b2)) :\n  \u22c2\u2080 S \u00d7\u02e2 \u22c2\u2080 T \u2286 \u22c2 r \u2208 S \u00d7\u02e2 T, r.1 \u00d7\u02e2 r.2 :=\nsubset_Inter\u2082 (\u03bb x hx y hy, \u27e8hy.1 x.1 hx.1, hy.2 x.2 hx.2\u27e9)\n\nlemma sInter_prod_sInter {S : set (set \u03b1)} {T : set (set \u03b2)} (hS : S.nonempty) (hT : T.nonempty) :\n  \u22c2\u2080 S \u00d7\u02e2 \u22c2\u2080 T = \u22c2 r \u2208 S \u00d7\u02e2 T, r.1 \u00d7\u02e2 r.2 :=\nbegin\n  obtain \u27e8s\u2081, h\u2081\u27e9 := hS,\n  obtain \u27e8s\u2082, h\u2082\u27e9 := hT,\n  refine set.subset.antisymm (sInter_prod_sInter_subset S T) (\u03bb x hx, _),\n  rw mem_Inter\u2082 at hx,\n  exact \u27e8\u03bb s\u2080 h\u2080, (hx (s\u2080, s\u2082) \u27e8h\u2080, h\u2082\u27e9).1, \u03bb s\u2080 h\u2080, (hx (s\u2081, s\u2080) \u27e8h\u2081, h\u2080\u27e9).2\u27e9,\nend\n\nlemma sInter_prod {S : set (set \u03b1)} (hS : S.nonempty) (t : set \u03b2) :\n  \u22c2\u2080 S \u00d7\u02e2 t = \u22c2 s \u2208 S, s \u00d7\u02e2 t :=\nbegin\n  rw [\u2190sInter_singleton t, sInter_prod_sInter hS (singleton_nonempty t), sInter_singleton],\n  simp_rw [prod_singleton, mem_image, Inter_exists, bInter_and', Inter_Inter_eq_right],\nend\n\nlemma prod_sInter {T : set (set \u03b2)} (hT : T.nonempty) (s : set \u03b1) :\n  s \u00d7\u02e2 \u22c2\u2080 T = \u22c2 t \u2208 T, s \u00d7\u02e2 t :=\nbegin\n  rw [\u2190sInter_singleton s, sInter_prod_sInter (singleton_nonempty s) hT, sInter_singleton],\n  simp_rw [singleton_prod, mem_image, Inter_exists, bInter_and', Inter_Inter_eq_right],\nend\nend prod\n\nsection image2\n\nvariables (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) {s : set \u03b1} {t : set \u03b2}\n\nlemma Union_image_left : (\u22c3 a \u2208 s, f a '' t) = image2 f s t :=\nby { ext y, split; simp only [mem_Union]; rintro \u27e8a, ha, x, hx, ax\u27e9; exact \u27e8a, x, ha, hx, ax\u27e9 }\n\nlemma Union_image_right : (\u22c3 b \u2208 t, (\u03bb a, f a b) '' s) = image2 f s t :=\nby { ext y, split; simp only [mem_Union]; rintro \u27e8a, b, c, d, e\u27e9, exact \u27e8c, a, d, b, e\u27e9,\n     exact \u27e8b, d, a, c, e\u27e9 }\n\nlemma image2_Union_left (s : \u03b9 \u2192 set \u03b1) (t : set \u03b2) :\n  image2 f (\u22c3 i, s i) t = \u22c3 i, image2 f (s i) t :=\nby simp only [\u2190 image_prod, Union_prod_const, image_Union]\n\nlemma image2_Union_right (s : set \u03b1) (t : \u03b9 \u2192 set \u03b2) :\n  image2 f s (\u22c3 i, t i) = \u22c3 i, image2 f s (t i) :=\nby simp only [\u2190 image_prod, prod_Union, image_Union]\n\nlemma image2_Union\u2082_left (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b2) :\n  image2 f (\u22c3 i j, s i j) t = \u22c3 i j, image2 f (s i j) t :=\nby simp_rw image2_Union_left\n\nlemma image2_Union\u2082_right (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b2) :\n  image2 f s (\u22c3 i j, t i j) = \u22c3 i j, image2 f s (t i j) :=\nby simp_rw image2_Union_right\n\nlemma image2_Inter_subset_left (s : \u03b9 \u2192 set \u03b1) (t : set \u03b2) :\n  image2 f (\u22c2 i, s i) t \u2286 \u22c2 i, image2 f (s i) t :=\nby { simp_rw [image2_subset_iff, mem_Inter], exact \u03bb x hx y hy i, mem_image2_of_mem (hx _) hy }\n\nlemma image2_Inter_subset_right (s : set \u03b1) (t : \u03b9 \u2192 set \u03b2) :\n  image2 f s (\u22c2 i, t i) \u2286 \u22c2 i, image2 f s (t i) :=\nby { simp_rw [image2_subset_iff, mem_Inter], exact \u03bb x hx y hy i, mem_image2_of_mem hx (hy _) }\n\nlemma image2_Inter\u2082_subset_left (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b2) :\n  image2 f (\u22c2 i j, s i j) t \u2286 \u22c2 i j, image2 f (s i j) t :=\nby { simp_rw [image2_subset_iff, mem_Inter], exact \u03bb x hx y hy i j, mem_image2_of_mem (hx _ _) hy }\n\nlemma image2_Inter\u2082_subset_right (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b2) :\n  image2 f s (\u22c2 i j, t i j) \u2286 \u22c2 i j, image2 f s (t i j) :=\nby { simp_rw [image2_subset_iff, mem_Inter], exact \u03bb x hx y hy i j, mem_image2_of_mem hx (hy _ _) }\n\n/-- The `set.image2` version of `set.image_eq_Union` -/\nlemma image2_eq_Union (s : set \u03b1) (t : set \u03b2) : image2 f s t = \u22c3 (i \u2208 s) (j \u2208 t), {f i j} :=\nby simp_rw [\u2190image_eq_Union, Union_image_left]\n\nlemma prod_eq_bUnion_left : s \u00d7\u02e2 t = \u22c3 a \u2208 s, (\u03bb b, (a, b)) '' t :=\nby rw [Union_image_left, image2_mk_eq_prod]\n\nlemma prod_eq_bUnion_right : s \u00d7\u02e2 t = \u22c3 b \u2208 t, (\u03bb a, (a, b)) '' s :=\nby rw [Union_image_right, image2_mk_eq_prod]\n\nend image2\n\nsection seq\n\n/-- Given a set `s` of functions `\u03b1 \u2192 \u03b2` and `t : set \u03b1`, `seq s t` is the union of `f '' t` over\nall `f \u2208 s`. -/\ndef seq (s : set (\u03b1 \u2192 \u03b2)) (t : set \u03b1) : set \u03b2 := {b | \u2203 f \u2208 s, \u2203 a \u2208 t, (f : \u03b1 \u2192 \u03b2) a = b}\n\nlemma seq_def {s : set (\u03b1 \u2192 \u03b2)} {t : set \u03b1} : seq s t = \u22c3 f \u2208 s, f '' t :=\nset.ext $ by simp [seq]\n\n@[simp] lemma mem_seq_iff {s : set (\u03b1 \u2192 \u03b2)} {t : set \u03b1} {b : \u03b2} :\n  b \u2208 seq s t \u2194 \u2203 (f \u2208 s) (a \u2208 t), (f : \u03b1 \u2192 \u03b2) a = b :=\niff.rfl\n\nlemma seq_subset {s : set (\u03b1 \u2192 \u03b2)} {t : set \u03b1} {u : set \u03b2} :\n  seq s t \u2286 u \u2194 (\u2200 f \u2208 s, \u2200 a \u2208 t, (f : \u03b1 \u2192 \u03b2) a \u2208 u) :=\niff.intro\n  (\u03bb h f hf a ha, h \u27e8f, hf, a, ha, rfl\u27e9)\n  (\u03bb h b \u27e8f, hf, a, ha, eq\u27e9, eq \u25b8 h f hf a ha)\n\nlemma seq_mono {s\u2080 s\u2081 : set (\u03b1 \u2192 \u03b2)} {t\u2080 t\u2081 : set \u03b1} (hs : s\u2080 \u2286 s\u2081) (ht : t\u2080 \u2286 t\u2081) :\n  seq s\u2080 t\u2080 \u2286 seq s\u2081 t\u2081 :=\n\u03bb b \u27e8f, hf, a, ha, eq\u27e9, \u27e8f, hs hf, a, ht ha, eq\u27e9\n\nlemma singleton_seq {f : \u03b1 \u2192 \u03b2} {t : set \u03b1} : set.seq {f} t = f '' t :=\nset.ext $ by simp\n\nlemma seq_singleton {s : set (\u03b1 \u2192 \u03b2)} {a : \u03b1} : set.seq s {a} = (\u03bb f : \u03b1 \u2192 \u03b2, f a) '' s :=\nset.ext $ by simp\n\nlemma seq_seq {s : set (\u03b2 \u2192 \u03b3)} {t : set (\u03b1 \u2192 \u03b2)} {u : set \u03b1} :\n  seq s (seq t u) = seq (seq ((\u2218) '' s) t) u :=\nbegin\n  refine set.ext (\u03bb c, iff.intro _ _),\n  { rintro \u27e8f, hfs, b, \u27e8g, hg, a, hau, rfl\u27e9, rfl\u27e9,\n    exact \u27e8f \u2218 g, \u27e8(\u2218) f, mem_image_of_mem _ hfs, g, hg, rfl\u27e9, a, hau, rfl\u27e9 },\n  { rintro \u27e8fg, \u27e8fc, \u27e8f, hfs, rfl\u27e9, g, hgt, rfl\u27e9, a, ha, rfl\u27e9,\n    exact \u27e8f, hfs, g a, \u27e8g, hgt, a, ha, rfl\u27e9, rfl\u27e9 }\nend\n\nlemma image_seq {f : \u03b2 \u2192 \u03b3} {s : set (\u03b1 \u2192 \u03b2)} {t : set \u03b1} :\n  f '' seq s t = seq ((\u2218) f '' s) t :=\nby rw [\u2190 singleton_seq, \u2190 singleton_seq, seq_seq, image_singleton]\n\nlemma prod_eq_seq {s : set \u03b1} {t : set \u03b2} : s \u00d7\u02e2 t = (prod.mk '' s).seq t :=\nbegin\n  ext \u27e8a, b\u27e9,\n  split,\n  { rintro \u27e8ha, hb\u27e9, exact \u27e8prod.mk a, \u27e8a, ha, rfl\u27e9, b, hb, rfl\u27e9 },\n  { rintro \u27e8f, \u27e8x, hx, rfl\u27e9, y, hy, eq\u27e9, rw \u2190 eq, exact \u27e8hx, hy\u27e9 }\nend\n\nlemma prod_image_seq_comm (s : set \u03b1) (t : set \u03b2) :\n  (prod.mk '' s).seq t = seq ((\u03bb b a, (a, b)) '' t) s :=\nby rw [\u2190 prod_eq_seq, \u2190 image_swap_prod, prod_eq_seq, image_seq, \u2190 image_comp, prod.swap]\n\nlemma image2_eq_seq (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (s : set \u03b1) (t : set \u03b2) : image2 f s t = seq (f '' s) t :=\nby { ext, simp }\n\nend seq\n\nsection pi\n\nvariables {\u03c0 : \u03b1 \u2192 Type*}\n\nlemma pi_def (i : set \u03b1) (s : \u03a0 a, set (\u03c0 a)) :\n  pi i s = (\u22c2 a \u2208 i, eval a \u207b\u00b9' s a) :=\nby { ext, simp }\n\nlemma univ_pi_eq_Inter (t : \u03a0 i, set (\u03c0 i)) : pi univ t = \u22c2 i, eval i \u207b\u00b9' t i :=\nby simp only [pi_def, Inter_true, mem_univ]\n\nlemma pi_diff_pi_subset (i : set \u03b1) (s t : \u03a0 a, set (\u03c0 a)) :\n  pi i s \\ pi i t \u2286 \u22c3 a \u2208 i, (eval a \u207b\u00b9' (s a \\ t a)) :=\nbegin\n  refine diff_subset_comm.2 (\u03bb x hx a ha, _),\n  simp only [mem_diff, mem_pi, mem_Union, not_exists, mem_preimage, not_and, not_not, eval_apply]\n    at hx,\n  exact hx.2 _ ha (hx.1 _ ha)\nend\n\nlemma Union_univ_pi (t : \u03a0 i, \u03b9 \u2192 set (\u03c0 i)) :\n  (\u22c3 (x : \u03b1 \u2192 \u03b9), pi univ (\u03bb i, t i (x i))) = pi univ (\u03bb i, \u22c3 (j : \u03b9), t i j) :=\nby { ext, simp [classical.skolem] }\n\nend pi\n\nend set\n\nnamespace function\nnamespace surjective\n\nlemma Union_comp {f : \u03b9 \u2192 \u03b9\u2082} (hf : surjective f) (g : \u03b9\u2082 \u2192 set \u03b1) :\n  (\u22c3 x, g (f x)) = \u22c3 y, g y :=\nhf.supr_comp g\n\nlemma Inter_comp {f : \u03b9 \u2192 \u03b9\u2082} (hf : surjective f) (g : \u03b9\u2082 \u2192 set \u03b1) :\n  (\u22c2 x, g (f x)) = \u22c2 y, g y :=\nhf.infi_comp g\n\nend surjective\nend function\n\n/-!\n### Disjoint sets\n\nWe define some lemmas in the `disjoint` namespace to be able to use projection notation.\n-/\n\nsection disjoint\n\nvariables {s t u : set \u03b1} {f : \u03b1 \u2192 \u03b2}\n\nnamespace set\n\n@[simp] theorem disjoint_Union_left {\u03b9 : Sort*} {s : \u03b9 \u2192 set \u03b1} :\n  disjoint (\u22c3 i, s i) t \u2194 \u2200 i, disjoint (s i) t :=\nsupr_disjoint_iff\n\n@[simp] theorem disjoint_Union_right {\u03b9 : Sort*} {s : \u03b9 \u2192 set \u03b1} :\n  disjoint t (\u22c3 i, s i) \u2194 \u2200 i, disjoint t (s i) :=\ndisjoint_supr_iff\n\n@[simp] lemma disjoint_Union\u2082_left {s : \u03a0 i, \u03ba i \u2192 set \u03b1} {t : set \u03b1} :\n  disjoint (\u22c3 i j, s i j) t \u2194 \u2200 i j, disjoint (s i j) t :=\nsupr\u2082_disjoint_iff\n\n@[simp] lemma disjoint_Union\u2082_right {s : set \u03b1} {t : \u03a0 i, \u03ba i \u2192 set \u03b1} :\n  disjoint s (\u22c3 i j, t i j) \u2194 \u2200 i j, disjoint s (t i j) :=\ndisjoint_supr\u2082_iff\n\n@[simp] lemma disjoint_sUnion_left {S : set (set \u03b1)} {t : set \u03b1} :\n  disjoint (\u22c3\u2080 S) t \u2194 \u2200 s \u2208 S, disjoint s t :=\nSup_disjoint_iff\n\n@[simp] lemma disjoint_sUnion_right {s : set \u03b1} {S : set (set \u03b1)} :\n  disjoint s (\u22c3\u2080 S) \u2194 \u2200 t \u2208 S, disjoint s t :=\ndisjoint_Sup_iff\n\nend set\n\nend disjoint\n\n/-! ### Intervals -/\n\nnamespace set\nvariables [complete_lattice \u03b1]\n\nlemma Ici_supr (f : \u03b9 \u2192 \u03b1) : Ici (\u2a06 i, f i) = \u22c2 i, Ici (f i) :=\next $ \u03bb _, by simp only [mem_Ici, supr_le_iff, mem_Inter]\n\nlemma Iic_infi (f : \u03b9 \u2192 \u03b1) : Iic (\u2a05 i, f i) = \u22c2 i, Iic (f i) :=\next $ \u03bb _, by simp only [mem_Iic, le_infi_iff, mem_Inter]\n\nlemma Ici_supr\u2082 (f : \u03a0 i, \u03ba i \u2192 \u03b1) : Ici (\u2a06 i j, f i j) = \u22c2 i j, Ici (f i j) := by simp_rw Ici_supr\nlemma Iic_infi\u2082 (f : \u03a0 i, \u03ba i \u2192 \u03b1) : Iic (\u2a05 i j, f i j) = \u22c2 i j, Iic (f i j) := by simp_rw Iic_infi\n\nlemma Ici_Sup (s : set \u03b1) : Ici (Sup s) = \u22c2 a \u2208 s, Ici a := by rw [Sup_eq_supr, Ici_supr\u2082]\nlemma Iic_Inf (s : set \u03b1) : Iic (Inf s) = \u22c2 a \u2208 s, Iic a := by rw [Inf_eq_infi, Iic_infi\u2082]\n\nend set\n\nnamespace set\nvariables (t : \u03b1 \u2192 set \u03b2)\n\nlemma bUnion_diff_bUnion_subset (s\u2081 s\u2082 : set \u03b1) :\n  (\u22c3 x \u2208 s\u2081, t x) \\ (\u22c3 x \u2208 s\u2082, t x) \u2286 (\u22c3 x \u2208 s\u2081 \\ s\u2082, t x) :=\nbegin\n  simp only [diff_subset_iff, \u2190 bUnion_union],\n  apply bUnion_subset_bUnion_left,\n  rw union_diff_self,\n  apply subset_union_right\nend\n\n/-- If `t` is an indexed family of sets, then there is a natural map from `\u03a3 i, t i` to `\u22c3 i, t i`\nsending `\u27e8i, x\u27e9` to `x`. -/\ndef sigma_to_Union (x : \u03a3 i, t i) : (\u22c3 i, t i) := \u27e8x.2, mem_Union.2 \u27e8x.1, x.2.2\u27e9\u27e9\n\nlemma sigma_to_Union_surjective : surjective (sigma_to_Union t)\n| \u27e8b, hb\u27e9 := have \u2203 a, b \u2208 t a, by simpa using hb, let \u27e8a, hb\u27e9 := this in \u27e8\u27e8a, b, hb\u27e9, rfl\u27e9\n\nlemma sigma_to_Union_injective (h : \u2200 i j, i \u2260 j \u2192 disjoint (t i) (t j)) :\n  injective (sigma_to_Union t)\n| \u27e8a\u2081, b\u2081, h\u2081\u27e9 \u27e8a\u2082, b\u2082, h\u2082\u27e9 eq :=\n  have b_eq : b\u2081 = b\u2082, from congr_arg subtype.val eq,\n  have a_eq : a\u2081 = a\u2082, from classical.by_contradiction $ \u03bb ne,\n    have b\u2081 \u2208 t a\u2081 \u2229 t a\u2082, from \u27e8h\u2081, b_eq.symm \u25b8 h\u2082\u27e9,\n    (h _ _ ne).le_bot this,\n  sigma.eq a_eq $ subtype.eq $ by subst b_eq; subst a_eq\n\nlemma sigma_to_Union_bijective (h : \u2200 i j, i \u2260 j \u2192 disjoint (t i) (t j)) :\n  bijective (sigma_to_Union t) :=\n\u27e8sigma_to_Union_injective t h, sigma_to_Union_surjective t\u27e9\n\n/-- Equivalence between a disjoint union and a dependent sum. -/\nnoncomputable def Union_eq_sigma_of_disjoint {t : \u03b1 \u2192 set \u03b2}\n  (h : \u2200 i j, i \u2260 j \u2192 disjoint (t i) (t j)) : (\u22c3 i, t i) \u2243 (\u03a3 i, t i) :=\n(equiv.of_bijective _ $ sigma_to_Union_bijective t h).symm\n\nlemma Union_ge_eq_Union_nat_add (u : \u2115 \u2192 set \u03b1) (n : \u2115) : (\u22c3 i \u2265 n, u i) = \u22c3 i, u (i + n) :=\nsupr_ge_eq_supr_nat_add u n\n\nlemma Inter_ge_eq_Inter_nat_add (u : \u2115 \u2192 set \u03b1) (n : \u2115) : (\u22c2 i \u2265 n, u i) = \u22c2 i, u (i + n) :=\ninfi_ge_eq_infi_nat_add u n\n\nlemma _root_.monotone.Union_nat_add {f : \u2115 \u2192 set \u03b1} (hf : monotone f) (k : \u2115) :\n  (\u22c3 n, f (n + k)) = \u22c3 n, f n :=\nhf.supr_nat_add k\n\nlemma _root_.antitone.Inter_nat_add {f : \u2115 \u2192 set \u03b1} (hf : antitone f) (k : \u2115) :\n  (\u22c2 n, f (n + k)) = \u22c2 n, f n :=\nhf.infi_nat_add k\n\n@[simp] lemma Union_Inter_ge_nat_add (f : \u2115 \u2192 set \u03b1) (k : \u2115) :\n  (\u22c3 n, \u22c2 i \u2265 n, f (i + k)) = \u22c3 n, \u22c2 i \u2265 n, f i :=\nsupr_infi_ge_nat_add f k\n\nlemma union_Union_nat_succ (u : \u2115 \u2192 set \u03b1) : u 0 \u222a (\u22c3 i, u (i + 1)) = \u22c3 i, u i :=\nsup_supr_nat_succ u\n\nlemma inter_Inter_nat_succ (u : \u2115 \u2192 set \u03b1) : u 0 \u2229 (\u22c2 i, u (i + 1)) = \u22c2 i, u i :=\ninf_infi_nat_succ u\n\nend set\n\nopen set\n\nvariables [complete_lattice \u03b2]\n\nlemma supr_Union (s : \u03b9 \u2192 set \u03b1) (f : \u03b1 \u2192 \u03b2) : (\u2a06 a \u2208 (\u22c3 i, s i), f a) = \u2a06 i (a \u2208 s i), f a :=\nby { rw supr_comm, simp_rw [mem_Union, supr_exists] }\n\nlemma infi_Union (s : \u03b9 \u2192 set \u03b1) (f : \u03b1 \u2192 \u03b2) : (\u2a05 a \u2208 (\u22c3 i, s i), f a) = \u2a05 i (a \u2208 s i), f a :=\n@supr_Union \u03b1 \u03b2\u1d52\u1d48 _ _ s f\n\nlemma Sup_sUnion (s : set (set \u03b2)) : Sup (\u22c3\u2080 s) = \u2a06 t \u2208 s, Sup t :=\nby simp only [sUnion_eq_bUnion, Sup_eq_supr, supr_Union]\n\nlemma Inf_sUnion (s : set (set \u03b2)) : Inf (\u22c3\u2080 s) = \u2a05 t \u2208 s, Inf t := @Sup_sUnion \u03b2\u1d52\u1d48 _ _\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/set/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7164507583103624}}
{"text": "import Mathlib.Init.Data.Nat.Basic\nimport Mathlib.Init.Data.Nat.Lemmas\nimport Mathlib.Tactic.Basic\nimport Mathlib.Logic.Basic\n\nnamespace Nat\n\nattribute [simp] succ_ne_zero lt_succ_self\n\n-- TODO: in mathlib, this is done for ordered monoids\nprotected lemma pos_iff_ne_zero {n : \u2115} : 0 < n \u2194 n \u2260 0 := by\n  refine \u27e8?_, Nat.pos_of_ne_zero\u27e9\n  cases n with\n  | zero   => intro h; contradiction\n  | succ n => intro _; apply succ_ne_zero\n\nprotected lemma not_lt_of_le {n m : \u2115} (h\u2081 : m \u2264 n) : \u00ac n < m\n| h\u2082 => Nat.not_le_of_gt h\u2082 h\u2081\n\nprotected lemma not_le_of_lt {n m : \u2115} : m < n \u2192 \u00ac n \u2264 m  := Nat.not_le_of_gt\n\nprotected lemma lt_of_not_le {a b : \u2115} : \u00ac a \u2264 b \u2192 b < a := (Nat.lt_or_ge b a).resolve_right\n\nprotected lemma le_of_not_lt {a b : \u2115} : \u00ac a < b \u2192 b \u2264 a := (Nat.lt_or_ge a b).resolve_left\n\nprotected lemma le_or_le (a b : \u2115) : a \u2264 b \u2228 b \u2264 a := (Nat.lt_or_ge _ _).imp_left Nat.le_of_lt\n\nprotected lemma le_of_not_le {a b : \u2115} : \u00ac a \u2264 b \u2192 b \u2264 a := (Nat.le_or_le _ _).resolve_left\n\nprotected lemma not_lt {n m : \u2115} : \u00ac n < m \u2194 m \u2264 n :=\n\u27e8Nat.le_of_not_lt, Nat.not_lt_of_le\u27e9\n\nprotected lemma not_le {n m : \u2115} : \u00ac n \u2264 m \u2194 m < n :=\n\u27e8Nat.lt_of_not_le, Nat.not_le_of_lt\u27e9\n\nprotected lemma lt_or_eq_of_le {n m : \u2115} (h : n \u2264 m) : n < m \u2228 n = m :=\n(Nat.lt_or_ge _ _).imp_right (Nat.le_antisymm h)\n\ntheorem le_zero_iff {i : \u2115} : i \u2264 0 \u2194 i = 0 :=\n  \u27e8Nat.eq_zero_of_le_zero, \u03bb h => h \u25b8 le_refl i\u27e9\n\ntheorem lt_succ_iff {m n : \u2115} : m < succ n \u2194 m \u2264 n :=\n\u27e8le_of_lt_succ, lt_succ_of_le\u27e9\n\n/-! ### `succ` -/\n\nlemma succ_eq_one_add (n : \u2115) : n.succ = 1 + n := by\n  rw [Nat.succ_eq_add_one, Nat.add_comm]\n\ntheorem succ_inj' {n m : \u2115} : succ n = succ m \u2194 n = m :=\n\u27e8succ.inj, congr_arg _\u27e9\n\n/- sub properties -/\n\nlemma sub_lt_self {a b : \u2115} (h\u2080 : 0 < a) (h\u2081 : a \u2264 b) : b - a < b := by\n  apply sub_lt _ h\u2080\n  apply Nat.lt_of_lt_of_le h\u2080 h\u2081\n\nprotected lemma add_sub_cancel' {n m : \u2115} (h : m \u2264 n) : m + (n - m) = n :=\nby rw [Nat.add_comm, Nat.sub_add_cancel h]\n\nprotected lemma sub_lt_sub_left : \u2200 {k m n : \u2115} (H : k < m) (h : k < n), m - n < m - k\n| 0, m+1, n+1, _, _ => by rw [Nat.add_sub_add_right]; exact lt_succ_of_le (Nat.sub_le _ _)\n| k+1, m+1, n+1, h1, h2 => by\n  rw [Nat.add_sub_add_right, Nat.add_sub_add_right]\n  exact Nat.sub_lt_sub_left (Nat.lt_of_succ_lt_succ h1) (Nat.lt_of_succ_lt_succ h2)\n\nprotected lemma sub_lt_left_of_lt_add {n k m : \u2115} (H : n \u2264 k) (h : k < n + m) : k - n < m := by\n  have := Nat.sub_le_sub_right (succ_le_of_lt h) n\n  rwa [Nat.add_sub_cancel_left, Nat.succ_sub H] at this\n\nprotected lemma add_le_of_le_sub_left {n k m : \u2115} (H : m \u2264 k) (h : n \u2264 k - m) : m + n \u2264 k :=\n  Nat.not_lt.1 fun h' => Nat.not_lt.2 h (Nat.sub_lt_left_of_lt_add H h')\n\nlemma le_sub_iff_add_le {x y k : \u2115} (h : k \u2264 y) : x \u2264 y - k \u2194 x + k \u2264 y :=\nby rw [\u2190 Nat.add_sub_cancel x k, Nat.sub_le_sub_right_iff h, Nat.add_sub_cancel]\n\nprotected lemma min_comm (a b : \u2115) : Nat.min a b = Nat.min b a := by\n  simp [Nat.min]\n  by_cases h\u2081 : a \u2264 b <;> by_cases h\u2082 : b \u2264 a <;> simp [h\u2081, h\u2082]\n  \u00b7 exact Nat.le_antisymm h\u2081 h\u2082\n  \u00b7 cases not_or_intro h\u2081 h\u2082 <| Nat.le_or_le _ _\n\nprotected lemma min_le_left (a b : \u2115) : Nat.min a b \u2264 a := by\n  simp [Nat.min]; by_cases a \u2264 b <;> simp [h]\n  exact Nat.le_of_not_le h\n\nprotected lemma min_eq_left (h : a \u2264 b) : Nat.min a b = a :=\nby simp [Nat.min, h]\n\nprotected lemma min_eq_right (h : b \u2264 a) : Nat.min a b = b :=\nby rw [Nat.min_comm a b]; exact Nat.min_eq_left h\n\nprotected def case_strong_rec_on {p : \u2115 \u2192 Sort u} (a : \u2115)\n  (hz : p 0) (hi : \u2200 n, (\u2200 m, m \u2264 n \u2192 p m) \u2192 p (succ n)) : p a :=\nNat.strong_rec_on a fun | 0, _ => hz | n+1, ih => hi n (\u03bb m w => ih m (lt_succ_of_le w))\n\n/- div -/\n\nlemma mul_div_le (m n : \u2115) : n * (m / n) \u2264 m := by\n  match n, Nat.eq_zero_or_pos n with\n  | _, Or.inl rfl => rw [Nat.zero_mul]; exact m.zero_le\n  | n, Or.inr h => rw [Nat.mul_comm, \u2190 Nat.le_div_iff_mul_le h]; exact Nat.le_refl _\n\n/- Up -/\n\n/-- A well-ordered relation for \"upwards\" induction on the natural numbers up to some bound `ub`. -/\ndef Up (ub a i : \u2115) := i < a \u2227 i < ub\n\nlemma Up.next {ub i} (h : i < ub) : Up ub (i+1) i := \u27e8Nat.lt_succ_self _, h\u27e9\n\nlemma Up.WF (ub) : WellFounded (Up ub) :=\n  Subrelation.wf (h\u2082 := (measure (ub - .)).wf) @fun a i \u27e8ia, iu\u27e9 => Nat.sub_lt_sub_left iu ia\n\n/-- A well-ordered relation for \"upwards\" induction on the natural numbers up to some bound `ub`. -/\ndef upRel (ub : \u2115) : WellFoundedRelation Nat := \u27e8Up ub, Up.WF ub\u27e9\n\nend Nat\n", "meta": {"author": "JOSHCLUNE", "repo": "Keller_reduction", "sha": "dc392b3da352fc1ffcfbecb1d4717d05f5faed4a", "save_path": "github-repos/lean/JOSHCLUNE-Keller_reduction", "path": "github-repos/lean/JOSHCLUNE-Keller_reduction/Keller_reduction-dc392b3da352fc1ffcfbecb1d4717d05f5faed4a/Lean4_Clique/Mathlib/Mathlib/Data/Nat/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7164507580730773}}
{"text": "import .topological_semantics ..K.semantics\nopen nnf\n\n-- local attribute [instance] classical.prop_decidable\n\n@[simp] def topo_to_kripke {\u03b1 : Type} (tm : topo_model \u03b1) : kripke \u03b1 := \n{ rel := \u03bb s t, s \u2208 @_root_.closure _ tm.to_topological_space {t},\n  val := \u03bb n s, tm.v n s }\n\ntheorem trans_force_left {\u03b1 : Type} {tm : topo_model \u03b1} : \u03a0 {s} {\u03c6 : nnf}, (topo_force tm s \u03c6) \u2192 force (topo_to_kripke tm) s \u03c6\n| s (var n)   h := by dsimp at h; simp [h]\n| s (neg n)   h := by dsimp at h; simp [h]\n| s (and \u03c6 \u03c8) h := begin cases h with l r, split, apply trans_force_left l, apply trans_force_left r end\n| s (or \u03c6 \u03c8)  h := begin cases h, left, apply trans_force_left h, right, apply trans_force_left h end\n| s (box \u03c6)   h := \nbegin\n  rcases h with \u27e8w, hw, hmem\u27e9,\n  intros s' hs',\n  apply trans_force_left,\n  apply hw.2,\n  rw \u2190set.inter_singleton_nonempty,\n  have := (@mem_closure_iff _ tm.to_topological_space _ _).1,\n  swap 3, exact {s'}, apply this, simpa using hs',\n  exact hw.1, exact hmem\nend\n| s (dia \u03c6)   h := \nbegin\n  let ts := tm.to_topological_space, \n  let o := \u22c2\u2080 {x : set \u03b1 | s \u2208 x \u2227 @is_open _ ts x},\n  have openo: @is_open _ ts o, \n    { apply tm.is_alex, intros, exact H.2 },\n  have hmem : s \u2208 o,\n    { rw set.mem_sInter, intros, exact H.1 },\n  have ex := (@mem_closure_iff _ tm.to_topological_space _ _).1 h o openo hmem,\n  cases ex with w hw, dsimp,\n  split, split, swap 3, \n  { exact w },\n  rw (@mem_closure_iff _ tm.to_topological_space _ _),\n  { --apply to_bool_true,\n    intros o' hopen' hmem',\n    have : o \u2286 o',\n      { intro x, intro hx, rw set.mem_sInter at hx, apply hx, split, repeat {assumption} },\n  rw set.inter_singleton_nonempty,\n  apply this hw.1 },\n  { exact trans_force_left hw.2 }\nend\n\ntheorem sat_of_topo_sat {\u0393 : list nnf} \n{\u03b1 : Type} (tm : topo_model \u03b1) (s) (h : topo_sat tm s \u0393) : \nsat (topo_to_kripke tm) s \u0393 := \u03bb \u03c6 h\u03c6, trans_force_left $ h \u03c6 h\u03c6\n\ntheorem unsat_topo_of_unsat {\u0393 : list nnf} : unsatisfiable \u0393 \u2192 topo_unsatisfiable \u0393 := \n\u03bb h, (\u03bb \u03b1 tm s hsat, @h _ (topo_to_kripke tm) s (sat_of_topo_sat _ _ hsat))\n\ndef not_topo_force_of_unsat {\u03c6} : unsatisfiable [\u03c6] \u2192 \u2200 (\u03b1) (tm : topo_model \u03b1) s, \u00ac topo_force tm s \u03c6 := \n\u03bb h, topo_unsat_singleton $ unsat_topo_of_unsat h\n\n", "meta": {"author": "minchaowu", "repo": "ModalTab", "sha": "9bb0bf17faf0554d907ef7bdd639648742889178", "save_path": "github-repos/lean/minchaowu-ModalTab", "path": "github-repos/lean/minchaowu-ModalTab/ModalTab-9bb0bf17faf0554d907ef7bdd639648742889178/src/apps/topo_translation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7164080810226581}}
{"text": "variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\niff.intro\n    (assume h : (\u2200 x, p x \u2227 q x),\n        show (\u2200 x, p x) \u2227 (\u2200 x, q x), from\n        and.intro\n            (assume z : \u03b1,\n                (h z).left)\n            (assume z : \u03b1,\n                (h z).right))\n    (assume h : (\u2200 x, p x) \u2227 (\u2200 x, q x),\n        show (\u2200 x, p x \u2227 q x), from\n        assume z : \u03b1,\n            and.intro (h.left z) (h.right z))\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\nassume h1 : (\u2200 x, p x \u2192 q x),\nshow (\u2200 x, p x) \u2192 (\u2200 x, q x), from\n    assume h2 : (\u2200 x, p x),\n    show (\u2200 x, q x), from\n        assume z : \u03b1,\n        (h1 z) (h2 z)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\nassume h : (\u2200 x, p x) \u2228 (\u2200 x, q x),\nshow \u2200 x, p x \u2228 q x, from\n    assume z : \u03b1,\n    or.elim h\n        (assume hl : \u2200 x, p x,\n            or.inl (hl z))\n        (assume hr : \u2200 x, q x,\n            or.inr (hr z))\n\n", "meta": {"author": "hyponymous", "repo": "theorem-proving-in-lean-solutions", "sha": "a95320ae81c90c1b15da04574602cd378794400d", "save_path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions", "path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions/theorem-proving-in-lean-solutions-a95320ae81c90c1b15da04574602cd378794400d/4.6.1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7164080698875827}}
{"text": "-- Propiedad_reflexiva_del_subconjunto.lean\n-- Para cualquier conjunto s, s \u2286 s.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 18-noviembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que para cualquier conjunto s, s \u2286 s.\n-- ----------------------------------------------------------------------\n\nimport tactic\nvariables {\u03b1 : Type*} (s : set \u03b1)\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 s :=\nbegin\n  assume x,\n  assume xs: x \u2208 s,\n  show x \u2208 s,\n    by exact xs,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 s :=\nbegin\n  intros x xs,\n  exact xs,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 s :=\n\u03bb x (xs : x \u2208 s), xs\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 s :=\n-- by library_search\nrfl.subset\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 s :=\n-- by hint\nby refl\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Propiedad_reflexiva_del_subconjunto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7163789657262263}}
{"text": "import game.world_07_advanced_proposition\nnamespace mynat\n\ntheorem succ_inj' {a b : mynat} (hs : succ(a) = succ(b)) :  a = b := begin[nat_num_game]\n  exact succ_inj hs,\nend\n\ntheorem succ_succ_inj {a b : mynat} (h : succ(succ(a)) = succ(succ(b))) : a = b := begin[nat_num_game]\n  apply succ_inj \u2218 succ_inj,\n  exact h,\nend\n\ntheorem succ_eq_succ_of_eq {a b : mynat} : a = b \u2192 succ(a) = succ(b) := begin[nat_num_game]\n  intro h,\n  rwa h,\nend\n\ntheorem succ_eq_succ_iff (a b : mynat) : succ a = succ b \u2194 a = b := begin[nat_num_game]\n  split,\n  exact succ_inj,\n  exact succ_eq_succ_of_eq,\nend\n\ntheorem add_right_cancel (a t b : mynat) : a + t = b + t \u2192 a = b := begin[nat_num_game]\n  intro h,\n  induction t,\n  rwa add_zero at h, {\n    apply t_ih,\n    rwa [add_succ, add_succ] at h,\n    cc\n  }\nend\n\ntheorem add_left_cancel (t a b : mynat) : t + a = t + b \u2192 a = b := begin[nat_num_game]\n  rw [add_comm t, add_comm t],\n  apply add_right_cancel,\nend\n\ntheorem add_right_cancel_iff (t a b : mynat) :  a + t = b + t \u2194 a = b := begin[nat_num_game]\n  split,\n  apply add_right_cancel, {\n    intro h,\n    rwa h,\n  }\nend\n\nlemma eq_zero_of_add_right_eq_self {a b : mynat} : a + b = a \u2192 b = 0 := begin[nat_num_game]\n  intros h,\n  induction a, {\n    rw zero_add at h,\n    apply h\n  }, {\n    apply a_ih,\n    rw succ_add at h,\n    apply succ_inj h\n  }\nend\n\ntheorem succ_ne_zero (a : mynat) : succ a \u2260 0 := begin[nat_num_game]\n  symmetry,\n  apply zero_ne_succ,\nend\n\nlemma add_left_eq_zero {{a b : mynat}} (H : a + b = 0) : b = 0 := begin[nat_num_game]\n  cases b,\n  refl, {\n    exfalso,\n    rw add_succ at H,\n    apply succ_ne_zero,\n    apply H\n  }\nend\n\nlemma add_right_eq_zero {a b : mynat} : a + b = 0 \u2192 a = 0 := begin[nat_num_game]\n  rw add_comm,\n  apply add_left_eq_zero,\nend\n\ntheorem add_one_eq_succ (d : mynat) : d + 1 = succ d := begin[nat_num_game]\n  symmetry,\n  apply succ_eq_add_one,\nend\n\nlemma ne_succ_self (n : mynat) : n \u2260 succ n := begin[nat_num_game]\n  induction n,\n  apply zero_ne_succ, {\n    intro h,\n    apply n_ih,\n    apply succ_inj,\n    apply h\n  }\nend\n\nend mynat\n", "meta": {"author": "lacrosse", "repo": "natural_number_game", "sha": "400179cde1d3fcc9744901dabff98813ba2b544f", "save_path": "github-repos/lean/lacrosse-natural_number_game", "path": "github-repos/lean/lacrosse-natural_number_game/natural_number_game-400179cde1d3fcc9744901dabff98813ba2b544f/src/game/world_08_advanced_addition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7163789493396666}}
{"text": "import data.real.basic\n\nexample : \u2203 x : \u211d, 2 < x \u2227 x < 3 :=\nbegin\n  use 5/2,\n  norm_num,\nend\n\nsection\ndef fn_ub (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, f x \u2264 a\ndef fn_lb (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, a \u2264 f x\n\ndef fn_has_ub (f : \u211d \u2192 \u211d) := \u2203 a, fn_ub f a\ndef fn_has_lb (f : \u211d \u2192 \u211d) := \u2203 a, fn_lb f a\n\nvariables {f g : \u211d \u2192 \u211d}\n\ntheorem fn_ub_add {f g : \u211d \u2192 \u211d} {a b : \u211d}\n    (hfa : fn_ub f a) (hgb : fn_ub g b) :\n  fn_ub (\u03bb x, f x + g x) (a + b) :=\n\u03bb x, add_le_add (hfa x) (hgb x)\n\ntheorem fn_lb_add {f g : \u211d \u2192 \u211d} {a b : \u211d} (hfa : fn_lb f a) \n  (hgb : fn_lb g b) : fn_lb (\u03bb x, f x + g x) (a + b) :=\nbegin \n  intro x,\n  change a + b \u2264 f x + g x,\n  apply add_le_add,\n  apply hfa,\n  apply hgb,\nend\n\ntheorem fn_ub_mul {f g : \u211d \u2192 \u211d} {a b : \u211d} (hfa : fn_ub f a) \n  (hfb : fn_ub g b) (nng : fn_lb g 0) (nna : 0 \u2264 a) :\n  fn_ub (\u03bb x, f x * g x) (a * b) :=\nbegin \n  intro x,\n  change f x * g x \u2264 a * b,\n  apply mul_le_mul,\n  apply hfa,\n  apply hfb,\n  apply nng,\n  exact nna,\nend\n\nexample (ubf : fn_has_ub f) (ubg : fn_has_ub g) :\n  fn_has_ub (\u03bb x, f x + g x) :=\nbegin \n  cases ubf with a ubfa,\n  cases ubg with b ubgb,\n  use a + b,\n  apply fn_ub_add ubfa ubgb,\nend\n\n\nexample (lbf : fn_has_lb f) (lbg : fn_has_lb g) :\n  fn_has_lb (\u03bb x, f x + g x) :=\nbegin \n  cases lbf with a lbfa,\n  cases lbg with b lbgb,\n  use a + b,\n  apply fn_lb_add lbfa lbgb,\nend\n\nexample {c : \u211d} (ubf : fn_has_ub f) (h : c \u2265 0):\n  fn_has_ub (\u03bb x, c * f x) :=\nbegin \n  cases ubf with a ubfa,\n  use c * a,\n  intro x,\n  dsimp,\n  apply mul_le_mul_of_nonneg_left,\n  apply ubfa,\n  exact h,\nend\n\n\nexample (ubf : fn_has_ub f) (ubg : fn_has_ub g) :\n  fn_has_ub (\u03bb x, f x + g x) :=\nbegin \n  rcases ubf with \u27e8a, ubfa\u27e9,\n  rcases ubg with \u27e8b, ubgb\u27e9,\n  use a + b,\n  apply fn_ub_add ubfa ubgb, \nend\n\nexample : fn_has_ub f \u2192 fn_has_ub g \u2192\n  fn_has_ub (\u03bb x, f x + g x) :=\nbegin \n  rintros \u27e8a, ubfa\u27e9 \u27e8b, ubgb\u27e9 ,\n  use a + b,\n  apply fn_ub_add ubfa ubgb,\nend\n\nexample : fn_has_ub f \u2192 fn_has_ub g \u2192\n  fn_has_ub (\u03bb x, f x + g x) :=\n\u03bb \u27e8a, ubfa\u27e9 \u27e8b, ubfb\u27e9, \u27e8a + b, fn_ub_add ubfa ubfb\u27e9\n\n\nend \n\n\n\nsection\nvariables {\u03b1 : Type*} [comm_ring \u03b1]\n\ndef sum_of_squares (x : \u03b1) := \u2203 a b, x = a^2 + b^2\n\ntheorem sum_of_squares_mul {x y : \u03b1}\n    (sosx : sum_of_squares x) (sosy : sum_of_squares y) :\n  sum_of_squares (x * y) :=\nbegin\n  rcases sosx with \u27e8a, b, xeq\u27e9,\n  rcases sosy with \u27e8c, d, yeq\u27e9,\n  rw [xeq, yeq],\n  use [a*c - b*d, a*d + b*c],\n  ring,\nend\n\ntheorem sum_of_squares_mul' {x y : \u03b1}\n    (sosx : sum_of_squares x) (sosy : sum_of_squares y) :\n  sum_of_squares (x * y) :=\nbegin\n  rcases sosx with \u27e8a, b, rfl\u27e9,\n  rcases sosy with \u27e8c, d, rfl\u27e9,\n  use [a*c - b*d, a*d + b*c],\n  ring\nend\n\nend\n\n\n\nsection\nvariables {a b c : \u2115}\n\nexample (divab : a \u2223 b) (divbc : b \u2223 c) : a \u2223 c :=\nbegin\n  cases divab with d beq,\n  cases divbc with e ceq,\n  rw [ceq, beq],\n  use (d * e), ring\nend\n\n\nexample (divab : a \u2223 b) (divac : a \u2223 c) : a \u2223 (b + c) :=\nbegin \n  rcases divab with \u27e8d, rfl\u27e9,\n  rcases divac with \u27e8e, rfl\u27e9,\n  use d + e,\n  ring,\nend\n\nend\n\n\nsection\nopen function\n\n\nexample {c : \u211d} : surjective (\u03bb x, x + c) :=\nbegin\n  intro y,\n  dsimp,\n  use y - c,\n  ring,\nend\n\nexample {c : \u211d} (h : c \u2260 0) : surjective (\u03bb x, c * x) :=\nbegin\n  intro y,\n  dsimp,\n  use c\u207b\u00b9 * y,\n  apply mul_inv_cancel_left\u2080,\n  exact h,\nend\n\nexample (x y : \u211d) (h : x - y \u2260 0) : (x^2 - y^2) / (x - y) = x + y :=\nby { field_simp [h], ring }\n\nexample {f : \u211d \u2192 \u211d} (h : surjective f) : \u2203 x, (f x)^2 = 4 :=\nbegin\n  cases h 2 with x hx,\n  use x,\n  rw hx,\n  norm_num,\nend\n\nend\n\n\nsection\nopen function\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\nvariables {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2}\n\nexample (surjg : surjective g) (surjf : surjective f) :\n  surjective (\u03bb x, g (f x)) :=\nbegin \n  intro y,\n  cases surjg y with b hgb,\n  cases surjf b with a hfa,\n  use a,\n  dsimp,\n  rw hfa,\n  apply hgb,\nend\n\nend", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/03_Logic/02_Existencial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190938, "lm_q2_score": 0.8333245973817159, "lm_q1q2_score": 0.7163789427850427}}
{"text": "import data.real.irrational\n\nlemma avg_between {a b : \u211d} (hab : a < b) :\n  (a + b) / 2 \u2208 set.Ioo a b :=\nbegin\n  split,\n  { calc a = (a + a) / 2 : by field_simp\n    ... < (a + b) / 2 : (div_lt_div_right (by norm_num)).mpr (by linarith) },\n  { calc (a + b) / 2 < (b + b) / 2 : (div_lt_div_right (by norm_num)).mpr (by linarith)\n    ... = b : by field_simp }\nend\n\nexample {a b : \u211d} (ha : irrational a) (hb : irrational b) (hab : a < b) :\n  \u2203 c, irrational c \u2227 c \u2208 set.Ioo a b :=\nbegin\n  set c := (a + b) / 2,\n  let h\u2081 := avg_between hab,\n  by_cases irrational c,\n  { exact exists.intro c \u27e8h, h\u2081\u27e9 },\n  { use (a + c) / 2,\n    unfold irrational at h,\n    push_neg at h,\n    obtain \u27e8q, hq\u27e9 := h,\n    -- idk an easy way to prove this\n    have : \u2191(2 : \u2115) = (2 : \u211d) := by simp,\n    exact \u27e8\n      this \u25b8 hq \u25b8 irrational.div_nat (irrational.add_rat q ha) two_ne_zero,\n      let h\u2082 := avg_between h\u2081.1 in \u27e8h\u2082.1, lt_trans h\u2082.2 h\u2081.2\u27e9\u27e9 },\nend", "meta": {"author": "greysome", "repo": "lean-practice", "sha": "00729df4b18a2538cd3f63f68ab9c59308e3a6c2", "save_path": "github-repos/lean/greysome-lean-practice", "path": "github-repos/lean/greysome-lean-practice/lean-practice-00729df4b18a2538cd3f63f68ab9c59308e3a6c2/src/new/ma1100t midterms/6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.716369409688524}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.finset.lattice\n! leanprover-community/mathlib commit 1c857a1f6798cb054be942199463c2cf904cb937\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Fold\nimport Mathlib.Data.Finset.Option\nimport Mathlib.Data.Finset.Prod\nimport Mathlib.Data.Multiset.Lattice\nimport Mathlib.Order.CompleteLattice\n\n/-!\n# Lattice operations on finsets\n-/\n\n\nvariable {\u03b1 \u03b2 \u03b3 \u03b9 : Type _}\n\nnamespace Finset\n\nopen Multiset OrderDual\n\n/-! ### sup -/\n\n\nsection Sup\n\n-- TODO: define with just `[Bot \u03b1]` where some lemmas hold without requiring `[OrderBot \u03b1]`\nvariable [SemilatticeSup \u03b1] [OrderBot \u03b1]\n\n/-- Supremum of a finite set: `sup {a, b, c} f = f a \u2294 f b \u2294 f c` -/\ndef sup (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) : \u03b1 :=\n  s.fold (\u00b7 \u2294 \u00b7) \u22a5 f\n#align finset.sup Finset.sup\n\nvariable {s s\u2081 s\u2082 : Finset \u03b2} {f g : \u03b2 \u2192 \u03b1} {a : \u03b1}\n\ntheorem sup_def : s.sup f = (s.1.map f).sup :=\n  rfl\n#align finset.sup_def Finset.sup_def\n\n@[simp]\ntheorem sup_empty : (\u2205 : Finset \u03b2).sup f = \u22a5 :=\n  fold_empty\n#align finset.sup_empty Finset.sup_empty\n\n@[simp]\ntheorem sup_cons {b : \u03b2} (h : b \u2209 s) : (cons b s h).sup f = f b \u2294 s.sup f :=\n  fold_cons h\n#align finset.sup_cons Finset.sup_cons\n\n@[simp]\ntheorem sup_insert [DecidableEq \u03b2] {b : \u03b2} : (insert b s : Finset \u03b2).sup f = f b \u2294 s.sup f :=\n  fold_insert_idem\n#align finset.sup_insert Finset.sup_insert\n\ntheorem sup_image [DecidableEq \u03b2] (s : Finset \u03b3) (f : \u03b3 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n    (s.image f).sup g = s.sup (g \u2218 f) :=\n  fold_image_idem\n#align finset.sup_image Finset.sup_image\n\n@[simp]\ntheorem sup_map (s : Finset \u03b3) (f : \u03b3 \u21aa \u03b2) (g : \u03b2 \u2192 \u03b1) : (s.map f).sup g = s.sup (g \u2218 f) :=\n  fold_map\n#align finset.sup_map Finset.sup_map\n\n@[simp]\ntheorem sup_singleton {b : \u03b2} : ({b} : Finset \u03b2).sup f = f b :=\n  Multiset.sup_singleton\n#align finset.sup_singleton Finset.sup_singleton\n\ntheorem sup_union [DecidableEq \u03b2] : (s\u2081 \u222a s\u2082).sup f = s\u2081.sup f \u2294 s\u2082.sup f :=\n  Finset.induction_on s\u2081\n    (by rw [empty_union, sup_empty, bot_sup_eq])\n    (fun a s _ ih => by rw [insert_union, sup_insert, sup_insert, ih, sup_assoc])\n#align finset.sup_union Finset.sup_union\n\ntheorem sup_sup : s.sup (f \u2294 g) = s.sup f \u2294 s.sup g := by\n  refine' Finset.cons_induction_on s _ fun b t _ h => _\n  \u00b7 rw [sup_empty, sup_empty, sup_empty, bot_sup_eq]\n  \u00b7 rw [sup_cons, sup_cons, sup_cons, h]\n    exact sup_sup_sup_comm _ _ _ _\n#align finset.sup_sup Finset.sup_sup\n\ntheorem sup_congr {f g : \u03b2 \u2192 \u03b1} (hs : s\u2081 = s\u2082) (hfg : \u2200 a \u2208 s\u2082, f a = g a) :\n    s\u2081.sup f = s\u2082.sup g := by\n  subst hs\n  exact Finset.fold_congr hfg\n#align finset.sup_congr Finset.sup_congr\n\n@[simp]\nprotected theorem sup_le_iff {a : \u03b1} : s.sup f \u2264 a \u2194 \u2200 b \u2208 s, f b \u2264 a := by\n  apply Iff.trans Multiset.sup_le\n  simp only [Multiset.mem_map, and_imp, exists_imp]\n  exact \u27e8fun k b hb => k _ _ hb rfl, fun k a' b hb h => h \u25b8 k _ hb\u27e9\n#align finset.sup_le_iff Finset.sup_le_iff\n\nalias Finset.sup_le_iff \u2194 _ sup_le\n#align finset.sup_le Finset.sup_le\n\n-- Porting note: removed `attribute [protected] sup_le`\n\ntheorem sup_const_le : (s.sup fun _ => a) \u2264 a :=\n  Finset.sup_le fun _ _ => le_rfl\n#align finset.sup_const_le Finset.sup_const_le\n\ntheorem le_sup {b : \u03b2} (hb : b \u2208 s) : f b \u2264 s.sup f :=\n  Finset.sup_le_iff.1 le_rfl _ hb\n#align finset.le_sup Finset.le_sup\n\n@[simp]\ntheorem sup_bunion\u1d62 [DecidableEq \u03b2] (s : Finset \u03b3) (t : \u03b3 \u2192 Finset \u03b2) :\n    (s.bunion\u1d62 t).sup f = s.sup fun x => (t x).sup f :=\n  eq_of_forall_ge_iff fun c => by simp [@forall_swap _ \u03b2]\n#align finset.sup_bUnion Finset.sup_bunion\u1d62\n\ntheorem sup_const {s : Finset \u03b2} (h : s.Nonempty) (c : \u03b1) : (s.sup fun _ => c) = c :=\n  eq_of_forall_ge_iff (fun _ => Finset.sup_le_iff.trans h.forall_const)\n#align finset.sup_const Finset.sup_const\n\n@[simp]\ntheorem sup_bot (s : Finset \u03b2) : (s.sup fun _ => \u22a5) = (\u22a5 : \u03b1) := by\n  obtain rfl | hs := s.eq_empty_or_nonempty\n  \u00b7 exact sup_empty\n  \u00b7 exact sup_const hs _\n#align finset.sup_bot Finset.sup_bot\n\ntheorem sup_ite (p : \u03b2 \u2192 Prop) [DecidablePred p] :\n    (s.sup fun i => ite (p i) (f i) (g i)) = (s.filter p).sup f \u2294 (s.filter fun i => \u00acp i).sup g :=\n  fold_ite _\n#align finset.sup_ite Finset.sup_ite\n\ntheorem sup_mono_fun {g : \u03b2 \u2192 \u03b1} (h : \u2200 b \u2208 s, f b \u2264 g b) : s.sup f \u2264 s.sup g :=\n  Finset.sup_le fun b hb => le_trans (h b hb) (le_sup hb)\n#align finset.sup_mono_fun Finset.sup_mono_fun\n\ntheorem sup_mono (h : s\u2081 \u2286 s\u2082) : s\u2081.sup f \u2264 s\u2082.sup f :=\n  Finset.sup_le (fun _ hb => le_sup (h hb))\n#align finset.sup_mono Finset.sup_mono\n\nprotected theorem sup_comm (s : Finset \u03b2) (t : Finset \u03b3) (f : \u03b2 \u2192 \u03b3 \u2192 \u03b1) :\n    (s.sup fun b => t.sup (f b)) = t.sup fun c => s.sup fun b => f b c := by\n  refine' eq_of_forall_ge_iff fun a => _\n  simp_rw [Finset.sup_le_iff]\n  exact \u27e8fun h c hc b hb => h b hb c hc, fun h b hb c hc => h c hc b hb\u27e9\n#align finset.sup_comm Finset.sup_comm\n\n@[simp, nolint simpNF] -- Porting note: linter claims that LHS does not simplify\ntheorem sup_attach (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) : (s.attach.sup fun x => f x) = s.sup f :=\n  (s.attach.sup_map (Function.Embedding.subtype _) f).symm.trans <| congr_arg _ attach_map_val\n#align finset.sup_attach Finset.sup_attach\n\n/-- See also `Finset.product_bunion\u1d62`. -/\ntheorem sup_product_left (s : Finset \u03b2) (t : Finset \u03b3) (f : \u03b2 \u00d7 \u03b3 \u2192 \u03b1) :\n    (s \u00d7\u1da0 t).sup f = s.sup fun i => t.sup fun i' => f \u27e8i, i'\u27e9 := by\n  simp only [le_antisymm_iff, Finset.sup_le_iff, mem_product, and_imp, Prod.forall]\n  -- Porting note: was one expression.\n  refine \u27e8fun b c hb hc => ?_, fun b hb c hc => ?_\u27e9\n  \u00b7 refine (le_sup hb).trans' ?_\n    exact @le_sup _ _ _ _ _ (fun c => f (b, c)) c hc\n  \u00b7 exact le_sup <| mem_product.2 \u27e8hb, hc\u27e9\n#align finset.sup_product_left Finset.sup_product_left\n\ntheorem sup_product_right (s : Finset \u03b2) (t : Finset \u03b3) (f : \u03b2 \u00d7 \u03b3 \u2192 \u03b1) :\n    (s \u00d7\u1da0 t).sup f = t.sup fun i' => s.sup fun i => f \u27e8i, i'\u27e9 := by\n  rw [sup_product_left, Finset.sup_comm]\n#align finset.sup_product_right Finset.sup_product_right\n\n@[simp]\ntheorem sup_erase_bot [DecidableEq \u03b1] (s : Finset \u03b1) : (s.erase \u22a5).sup id = s.sup id := by\n  refine' (sup_mono (s.erase_subset _)).antisymm (Finset.sup_le_iff.2 fun a ha => _)\n  obtain rfl | ha' := eq_or_ne a \u22a5\n  \u00b7 exact bot_le\n  \u00b7 exact le_sup (mem_erase.2 \u27e8ha', ha\u27e9)\n#align finset.sup_erase_bot Finset.sup_erase_bot\n\ntheorem sup_sdiff_right {\u03b1 \u03b2 : Type _} [GeneralizedBooleanAlgebra \u03b1] (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1)\n    (a : \u03b1) : (s.sup fun b => f b \\ a) = s.sup f \\ a := by\n  refine' Finset.cons_induction_on s _ fun b t _ h => _\n  \u00b7 rw [sup_empty, sup_empty, bot_sdiff]\n  \u00b7 rw [sup_cons, sup_cons, h, sup_sdiff]\n#align finset.sup_sdiff_right Finset.sup_sdiff_right\n\ntheorem comp_sup_eq_sup_comp [SemilatticeSup \u03b3] [OrderBot \u03b3] {s : Finset \u03b2} {f : \u03b2 \u2192 \u03b1} (g : \u03b1 \u2192 \u03b3)\n    (g_sup : \u2200 x y, g (x \u2294 y) = g x \u2294 g y) (bot : g \u22a5 = \u22a5) : g (s.sup f) = s.sup (g \u2218 f) :=\n  Finset.cons_induction_on s bot fun c t hc ih => by\n    rw [sup_cons, sup_cons, g_sup, ih, Function.comp_apply]\n#align finset.comp_sup_eq_sup_comp Finset.comp_sup_eq_sup_comp\n\n/-- Computing `sup` in a subtype (closed under `sup`) is the same as computing it in `\u03b1`. -/\ntheorem sup_coe {P : \u03b1 \u2192 Prop} {Pbot : P \u22a5} {Psup : \u2200 \u2983x y\u2984, P x \u2192 P y \u2192 P (x \u2294 y)} (t : Finset \u03b2)\n    (f : \u03b2 \u2192 { x : \u03b1 // P x }) :\n    (@sup { x // P x } _ (Subtype.semilatticeSup Psup) (Subtype.orderBot Pbot) t f : \u03b1) =\n      t.sup fun x => \u2191(f x) := by\n  letI := Subtype.semilatticeSup Psup\n  letI := Subtype.orderBot Pbot\n  apply comp_sup_eq_sup_comp Subtype.val <;> intros <;> rfl\n#align finset.sup_coe Finset.sup_coe\n\n@[simp]\ntheorem sup_toFinset {\u03b1 \u03b2} [DecidableEq \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 Multiset \u03b2) :\n    (s.sup f).toFinset = s.sup fun x => (f x).toFinset :=\n  comp_sup_eq_sup_comp Multiset.toFinset toFinset_union rfl\n#align finset.sup_to_finset Finset.sup_toFinset\n\ntheorem _root_.List.foldr_sup_eq_sup_toFinset [DecidableEq \u03b1] (l : List \u03b1) :\n    l.foldr (\u00b7 \u2294 \u00b7) \u22a5 = l.toFinset.sup id := by\n  rw [\u2190 coe_fold_r, \u2190 Multiset.fold_dedup_idem, sup_def, \u2190 List.toFinset_coe, toFinset_val,\n    Multiset.map_id]\n  rfl\n#align list.foldr_sup_eq_sup_to_finset List.foldr_sup_eq_sup_toFinset\n\ntheorem subset_range_sup_succ (s : Finset \u2115) : s \u2286 range (s.sup id).succ := fun _ hn =>\n  mem_range.2 <| Nat.lt_succ_of_le <| @le_sup _ _ _ _ _ id _ hn\n#align finset.subset_range_sup_succ Finset.subset_range_sup_succ\n\ntheorem exists_nat_subset_range (s : Finset \u2115) : \u2203 n : \u2115, s \u2286 range n :=\n  \u27e8_, s.subset_range_sup_succ\u27e9\n#align finset.exists_nat_subset_range Finset.exists_nat_subset_range\n\ntheorem sup_induction {p : \u03b1 \u2192 Prop} (hb : p \u22a5) (hp : \u2200 a\u2081, p a\u2081 \u2192 \u2200 a\u2082, p a\u2082 \u2192 p (a\u2081 \u2294 a\u2082))\n    (hs : \u2200 b \u2208 s, p (f b)) : p (s.sup f) := by\n  induction' s using Finset.cons_induction with c s hc ih\n  \u00b7 exact hb\n  \u00b7 rw [sup_cons]\n    apply hp\n    \u00b7 exact hs c (mem_cons.2 (Or.inl rfl))\n    \u00b7 exact ih fun b h => hs b (mem_cons.2 (Or.inr h))\n#align finset.sup_induction Finset.sup_induction\n\ntheorem sup_le_of_le_directed {\u03b1 : Type _} [SemilatticeSup \u03b1] [OrderBot \u03b1] (s : Set \u03b1)\n    (hs : s.Nonempty) (hdir : DirectedOn (\u00b7 \u2264 \u00b7) s) (t : Finset \u03b1) :\n    (\u2200 x \u2208 t, \u2203 y \u2208 s, x \u2264 y) \u2192 \u2203 x, x \u2208 s \u2227 t.sup id \u2264 x := by\n  classical\n    induction' t using Finset.induction_on with a r _ ih h\n    \u00b7 simpa only [forall_prop_of_true, and_true_iff, forall_prop_of_false, bot_le, not_false_iff,\n        sup_empty, forall_true_iff, not_mem_empty]\n    \u00b7 intro h\n      have incs : (r : Set \u03b1) \u2286 \u2191(insert a r) := by\n        rw [Finset.coe_subset]\n        apply Finset.subset_insert\n      -- x \u2208 s is above the sup of r\n      obtain \u27e8x, \u27e8hxs, hsx_sup\u27e9\u27e9 := ih fun x hx => h x <| incs hx\n      -- y \u2208 s is above a\n      obtain \u27e8y, hys, hay\u27e9 := h a (Finset.mem_insert_self a r)\n      -- z \u2208 s is above x and y\n      obtain \u27e8z, hzs, \u27e8hxz, hyz\u27e9\u27e9 := hdir x hxs y hys\n      use z, hzs\n      rw [sup_insert, id.def, sup_le_iff]\n      exact \u27e8le_trans hay hyz, le_trans hsx_sup hxz\u27e9\n#align finset.sup_le_of_le_directed Finset.sup_le_of_le_directed\n\n-- If we acquire sublattices\n-- the hypotheses should be reformulated as `s : SubsemilatticeSupBot`\ntheorem sup_mem (s : Set \u03b1) (w\u2081 : \u22a5 \u2208 s) (w\u2082 : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s), x \u2294 y \u2208 s)\n    {\u03b9 : Type _} (t : Finset \u03b9) (p : \u03b9 \u2192 \u03b1) (h : \u2200 i \u2208 t, p i \u2208 s) : t.sup p \u2208 s :=\n  @sup_induction _ _ _ _ _ _ (\u00b7 \u2208 s) w\u2081 w\u2082 h\n#align finset.sup_mem Finset.sup_mem\n\n@[simp]\ntheorem sup_eq_bot_iff (f : \u03b2 \u2192 \u03b1) (S : Finset \u03b2) : S.sup f = \u22a5 \u2194 \u2200 s \u2208 S, f s = \u22a5 := by\n  classical induction' S using Finset.induction with a S _ hi <;> simp [*]\n#align finset.sup_eq_bot_iff Finset.sup_eq_bot_iff\n\nend Sup\n\ntheorem sup_eq_sup\u1d62 [CompleteLattice \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 \u03b2) : s.sup f = \u2a06 a \u2208 s, f a :=\n  le_antisymm\n    (Finset.sup_le (fun a ha => le_sup\u1d62_of_le a <| le_sup\u1d62 (fun _ => f a) ha))\n    (sup\u1d62_le fun _ => sup\u1d62_le fun ha => le_sup ha)\n#align finset.sup_eq_supr Finset.sup_eq_sup\u1d62\n\ntheorem sup_id_eq_sup\u209b [CompleteLattice \u03b1] (s : Finset \u03b1) : s.sup id = sup\u209b s := by\n  simp [sup\u209b_eq_sup\u1d62, sup_eq_sup\u1d62]\n#align finset.sup_id_eq_Sup Finset.sup_id_eq_sup\u209b\n\ntheorem sup_id_set_eq_union\u209b (s : Finset (Set \u03b1)) : s.sup id = \u22c3\u2080 \u2191s :=\n  sup_id_eq_sup\u209b _\n#align finset.sup_id_set_eq_sUnion Finset.sup_id_set_eq_union\u209b\n\n@[simp]\ntheorem sup_set_eq_bunion\u1d62 (s : Finset \u03b1) (f : \u03b1 \u2192 Set \u03b2) : s.sup f = \u22c3 x \u2208 s, f x :=\n  sup_eq_sup\u1d62 _ _\n#align finset.sup_set_eq_bUnion Finset.sup_set_eq_bunion\u1d62\n\ntheorem sup_eq_sup\u209b_image [CompleteLattice \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 \u03b2) :\n    s.sup f = sup\u209b (f '' s) :=\n  by classical rw [\u2190 Finset.coe_image, \u2190 sup_id_eq_sup\u209b, sup_image, Function.comp.left_id]\n#align finset.sup_eq_Sup_image Finset.sup_eq_sup\u209b_image\n\n/-! ### inf -/\n\n\nsection Inf\n\n-- TODO: define with just `[Top \u03b1]` where some lemmas hold without requiring `[OrderTop \u03b1]`\nvariable [SemilatticeInf \u03b1] [OrderTop \u03b1]\n\n/-- Infimum of a finite set: `inf {a, b, c} f = f a \u2293 f b \u2293 f c` -/\ndef inf (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) : \u03b1 :=\n  s.fold (\u00b7 \u2293 \u00b7) \u22a4 f\n#align finset.inf Finset.inf\n\nvariable {s s\u2081 s\u2082 : Finset \u03b2} {f g : \u03b2 \u2192 \u03b1} {a : \u03b1}\n\ntheorem inf_def : s.inf f = (s.1.map f).inf :=\n  rfl\n#align finset.inf_def Finset.inf_def\n\n@[simp]\ntheorem inf_empty : (\u2205 : Finset \u03b2).inf f = \u22a4 :=\n  fold_empty\n#align finset.inf_empty Finset.inf_empty\n\n@[simp]\ntheorem inf_cons {b : \u03b2} (h : b \u2209 s) : (cons b s h).inf f = f b \u2293 s.inf f :=\n  @sup_cons \u03b1\u1d52\u1d48 _ _ _ _ _ _ h\n#align finset.inf_cons Finset.inf_cons\n\n@[simp]\ntheorem inf_insert [DecidableEq \u03b2] {b : \u03b2} : (insert b s : Finset \u03b2).inf f = f b \u2293 s.inf f :=\n  fold_insert_idem\n#align finset.inf_insert Finset.inf_insert\n\ntheorem inf_image [DecidableEq \u03b2] (s : Finset \u03b3) (f : \u03b3 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n    (s.image f).inf g = s.inf (g \u2218 f) :=\n  fold_image_idem\n#align finset.inf_image Finset.inf_image\n\n@[simp]\ntheorem inf_map (s : Finset \u03b3) (f : \u03b3 \u21aa \u03b2) (g : \u03b2 \u2192 \u03b1) : (s.map f).inf g = s.inf (g \u2218 f) :=\n  fold_map\n#align finset.inf_map Finset.inf_map\n\n@[simp]\ntheorem inf_singleton {b : \u03b2} : ({b} : Finset \u03b2).inf f = f b :=\n  Multiset.inf_singleton\n#align finset.inf_singleton Finset.inf_singleton\n\ntheorem inf_union [DecidableEq \u03b2] : (s\u2081 \u222a s\u2082).inf f = s\u2081.inf f \u2293 s\u2082.inf f :=\n  @sup_union \u03b1\u1d52\u1d48 _ _ _ _ _ _ _\n#align finset.inf_union Finset.inf_union\n\ntheorem inf_inf : s.inf (f \u2293 g) = s.inf f \u2293 s.inf g :=\n  @sup_sup \u03b1\u1d52\u1d48 _ _ _ _ _ _\n#align finset.inf_inf Finset.inf_inf\n\ntheorem inf_congr {f g : \u03b2 \u2192 \u03b1} (hs : s\u2081 = s\u2082) (hfg : \u2200 a \u2208 s\u2082, f a = g a) :\n    s\u2081.inf f = s\u2082.inf g := by\n  subst hs\n  exact Finset.fold_congr hfg\n#align finset.inf_congr Finset.inf_congr\n\n@[simp]\ntheorem inf_bunion\u1d62 [DecidableEq \u03b2] (s : Finset \u03b3) (t : \u03b3 \u2192 Finset \u03b2) :\n    (s.bunion\u1d62 t).inf f = s.inf fun x => (t x).inf f :=\n  @sup_bunion\u1d62 \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ _\n#align finset.inf_bUnion Finset.inf_bunion\u1d62\n\ntheorem inf_const {s : Finset \u03b2} (h : s.Nonempty) (c : \u03b1) : (s.inf fun _ => c) = c :=\n  @sup_const \u03b1\u1d52\u1d48 _ _ _ _ h _\n#align finset.inf_const Finset.inf_const\n\n@[simp]\ntheorem inf_top (s : Finset \u03b2) : (s.inf fun _ => \u22a4) = (\u22a4 : \u03b1) :=\n  @sup_bot \u03b1\u1d52\u1d48 _ _ _ _\n#align finset.inf_top Finset.inf_top\n\nprotected theorem le_inf_iff {a : \u03b1} : a \u2264 s.inf f \u2194 \u2200 b \u2208 s, a \u2264 f b :=\n  @Finset.sup_le_iff \u03b1\u1d52\u1d48 _ _ _ _ _ _\n#align finset.le_inf_iff Finset.le_inf_iff\n\nalias Finset.le_inf_iff \u2194 _ le_inf\n#align finset.le_inf Finset.le_inf\n\n-- Porting note: removed attribute [protected] le_inf\n\ntheorem le_inf_const_le : a \u2264 s.inf fun _ => a :=\n  Finset.le_inf fun _ _ => le_rfl\n#align finset.le_inf_const_le Finset.le_inf_const_le\n\ntheorem inf_le {b : \u03b2} (hb : b \u2208 s) : s.inf f \u2264 f b :=\n  Finset.le_inf_iff.1 le_rfl _ hb\n#align finset.inf_le Finset.inf_le\n\ntheorem inf_mono_fun {g : \u03b2 \u2192 \u03b1} (h : \u2200 b \u2208 s, f b \u2264 g b) : s.inf f \u2264 s.inf g :=\n  Finset.le_inf fun b hb => le_trans (inf_le hb) (h b hb)\n#align finset.inf_mono_fun Finset.inf_mono_fun\n\ntheorem inf_mono (h : s\u2081 \u2286 s\u2082) : s\u2082.inf f \u2264 s\u2081.inf f :=\n  Finset.le_inf (fun _ hb => inf_le (h hb))\n#align finset.inf_mono Finset.inf_mono\n\ntheorem inf_attach (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) : (s.attach.inf fun x => f x) = s.inf f :=\n  @sup_attach \u03b1\u1d52\u1d48 _ _ _ _ _\n#align finset.inf_attach Finset.inf_attach\n\nprotected theorem inf_comm (s : Finset \u03b2) (t : Finset \u03b3) (f : \u03b2 \u2192 \u03b3 \u2192 \u03b1) :\n    (s.inf fun b => t.inf (f b)) = t.inf fun c => s.inf fun b => f b c :=\n  @Finset.sup_comm \u03b1\u1d52\u1d48 _ _ _ _ _ _ _\n#align finset.inf_comm Finset.inf_comm\n\ntheorem inf_product_left (s : Finset \u03b2) (t : Finset \u03b3) (f : \u03b2 \u00d7 \u03b3 \u2192 \u03b1) :\n    (s \u00d7\u1da0 t).inf f = s.inf fun i => t.inf fun i' => f \u27e8i, i'\u27e9 :=\n  @sup_product_left \u03b1\u1d52\u1d48 _ _ _ _ _ _ _\n#align finset.inf_product_left Finset.inf_product_left\n\ntheorem inf_product_right (s : Finset \u03b2) (t : Finset \u03b3) (f : \u03b2 \u00d7 \u03b3 \u2192 \u03b1) :\n    (s \u00d7\u1da0 t).inf f = t.inf fun i' => s.inf fun i => f \u27e8i, i'\u27e9 :=\n  @sup_product_right \u03b1\u1d52\u1d48 _ _ _ _ _ _ _\n#align finset.inf_product_right Finset.inf_product_right\n\n@[simp]\ntheorem inf_erase_top [DecidableEq \u03b1] (s : Finset \u03b1) : (s.erase \u22a4).inf id = s.inf id :=\n  @sup_erase_bot \u03b1\u1d52\u1d48 _ _ _ _\n#align finset.inf_erase_top Finset.inf_erase_top\n\ntheorem sup_sdiff_left {\u03b1 \u03b2 : Type _} [BooleanAlgebra \u03b1] (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) (a : \u03b1) :\n    (s.sup fun b => a \\ f b) = a \\ s.inf f := by\n  refine' Finset.cons_induction_on s _ fun b t _ h => _\n  \u00b7 rw [sup_empty, inf_empty, sdiff_top]\n  \u00b7 rw [sup_cons, inf_cons, h, sdiff_inf]\n#align finset.sup_sdiff_left Finset.sup_sdiff_left\n\ntheorem inf_sdiff_left {\u03b1 \u03b2 : Type _} [BooleanAlgebra \u03b1] {s : Finset \u03b2} (hs : s.Nonempty)\n    (f : \u03b2 \u2192 \u03b1) (a : \u03b1) : (s.inf fun b => a \\ f b) = a \\ s.sup f := by\n  induction' hs using Finset.Nonempty.cons_induction with b b t _ _ h\n  \u00b7 rw [sup_singleton, inf_singleton]\n  \u00b7 rw [sup_cons, inf_cons, h, sdiff_sup]\n#align finset.inf_sdiff_left Finset.inf_sdiff_left\n\ntheorem inf_sdiff_right {\u03b1 \u03b2 : Type _} [BooleanAlgebra \u03b1] {s : Finset \u03b2} (hs : s.Nonempty)\n    (f : \u03b2 \u2192 \u03b1) (a : \u03b1) : (s.inf fun b => f b \\ a) = s.inf f \\ a := by\n  induction' hs using Finset.Nonempty.cons_induction with b b t _ _ h\n  \u00b7 rw [inf_singleton, inf_singleton]\n  \u00b7 rw [inf_cons, inf_cons, h, inf_sdiff]\n#align finset.inf_sdiff_right Finset.inf_sdiff_right\n\ntheorem comp_inf_eq_inf_comp [SemilatticeInf \u03b3] [OrderTop \u03b3] {s : Finset \u03b2} {f : \u03b2 \u2192 \u03b1} (g : \u03b1 \u2192 \u03b3)\n    (g_inf : \u2200 x y, g (x \u2293 y) = g x \u2293 g y) (top : g \u22a4 = \u22a4) : g (s.inf f) = s.inf (g \u2218 f) :=\n  @comp_sup_eq_sup_comp \u03b1\u1d52\u1d48 _ \u03b3\u1d52\u1d48 _ _ _ _ _ _ _ g_inf top\n#align finset.comp_inf_eq_inf_comp Finset.comp_inf_eq_inf_comp\n\n/-- Computing `inf` in a subtype (closed under `inf`) is the same as computing it in `\u03b1`. -/\ntheorem inf_coe {P : \u03b1 \u2192 Prop} {Ptop : P \u22a4} {Pinf : \u2200 \u2983x y\u2984, P x \u2192 P y \u2192 P (x \u2293 y)} (t : Finset \u03b2)\n    (f : \u03b2 \u2192 { x : \u03b1 // P x }) :\n    (@inf { x // P x } _ (Subtype.semilatticeInf Pinf) (Subtype.orderTop Ptop) t f : \u03b1) =\n      t.inf fun x => \u2191(f x) :=\n  @sup_coe \u03b1\u1d52\u1d48 _ _ _ _ Ptop Pinf t f\n#align finset.inf_coe Finset.inf_coe\n\ntheorem _root_.List.foldr_inf_eq_inf_toFinset [DecidableEq \u03b1] (l : List \u03b1) :\n    l.foldr (\u00b7 \u2293 \u00b7) \u22a4 = l.toFinset.inf id :=\n  by\n  rw [\u2190 coe_fold_r, \u2190 Multiset.fold_dedup_idem, inf_def, \u2190 List.toFinset_coe, toFinset_val,\n    Multiset.map_id]\n  rfl\n#align list.foldr_inf_eq_inf_to_finset List.foldr_inf_eq_inf_toFinset\n\ntheorem inf_induction {p : \u03b1 \u2192 Prop} (ht : p \u22a4) (hp : \u2200 a\u2081, p a\u2081 \u2192 \u2200 a\u2082, p a\u2082 \u2192 p (a\u2081 \u2293 a\u2082))\n    (hs : \u2200 b \u2208 s, p (f b)) : p (s.inf f) :=\n  @sup_induction \u03b1\u1d52\u1d48 _ _ _ _ _ _ ht hp hs\n#align finset.inf_induction Finset.inf_induction\n\ntheorem inf_mem (s : Set \u03b1) (w\u2081 : \u22a4 \u2208 s) (w\u2082 : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s), x \u2293 y \u2208 s)\n    {\u03b9 : Type _} (t : Finset \u03b9) (p : \u03b9 \u2192 \u03b1) (h : \u2200 i \u2208 t, p i \u2208 s) : t.inf p \u2208 s :=\n  @inf_induction _ _ _ _ _ _ (\u00b7 \u2208 s) w\u2081 w\u2082 h\n#align finset.inf_mem Finset.inf_mem\n\n@[simp]\ntheorem inf_eq_top_iff (f : \u03b2 \u2192 \u03b1) (S : Finset \u03b2) : S.inf f = \u22a4 \u2194 \u2200 s \u2208 S, f s = \u22a4 :=\n  @Finset.sup_eq_bot_iff \u03b1\u1d52\u1d48 _ _ _ _ _\n#align finset.inf_eq_top_iff Finset.inf_eq_top_iff\n\nend Inf\n\n@[simp]\ntheorem toDual_sup [SemilatticeSup \u03b1] [OrderBot \u03b1] (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) :\n    toDual (s.sup f) = s.inf (toDual \u2218 f) :=\n  rfl\n#align finset.to_dual_sup Finset.toDual_sup\n\n@[simp]\ntheorem toDual_inf [SemilatticeInf \u03b1] [OrderTop \u03b1] (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) :\n    toDual (s.inf f) = s.sup (toDual \u2218 f) :=\n  rfl\n#align finset.to_dual_inf Finset.toDual_inf\n\n@[simp]\ntheorem ofDual_sup [SemilatticeInf \u03b1] [OrderTop \u03b1] (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1\u1d52\u1d48) :\n    ofDual (s.sup f) = s.inf (ofDual \u2218 f) :=\n  rfl\n#align finset.of_dual_sup Finset.ofDual_sup\n\n@[simp]\ntheorem ofDual_inf [SemilatticeSup \u03b1] [OrderBot \u03b1] (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1\u1d52\u1d48) :\n    ofDual (s.inf f) = s.sup (ofDual \u2218 f) :=\n  rfl\n#align finset.of_dual_inf Finset.ofDual_inf\n\nsection DistribLattice\n\nvariable [DistribLattice \u03b1]\n\nsection OrderBot\n\nvariable [OrderBot \u03b1] {s : Finset \u03b2} {f : \u03b2 \u2192 \u03b1} {a : \u03b1}\n\ntheorem sup_inf_distrib_left (s : Finset \u03b9) (f : \u03b9 \u2192 \u03b1) (a : \u03b1) :\n    a \u2293 s.sup f = s.sup fun i => a \u2293 f i := by\n  induction' s using Finset.cons_induction with i s hi h\n  \u00b7 simp_rw [Finset.sup_empty, inf_bot_eq]\n  \u00b7 rw [sup_cons, sup_cons, inf_sup_left, h]\n#align finset.sup_inf_distrib_left Finset.sup_inf_distrib_left\n\ntheorem sup_inf_distrib_right (s : Finset \u03b9) (f : \u03b9 \u2192 \u03b1) (a : \u03b1) :\n    s.sup f \u2293 a = s.sup fun i => f i \u2293 a := by\n  rw [_root_.inf_comm, s.sup_inf_distrib_left]\n  simp_rw [_root_.inf_comm]\n#align finset.sup_inf_distrib_right Finset.sup_inf_distrib_right\n\nprotected theorem disjoint_sup_right : Disjoint a (s.sup f) \u2194 \u2200 i \u2208 s, Disjoint a (f i) := by\n  simp only [disjoint_iff, sup_inf_distrib_left, sup_eq_bot_iff]\n#align finset.disjoint_sup_right Finset.disjoint_sup_right\n\nprotected theorem disjoint_sup_left : Disjoint (s.sup f) a \u2194 \u2200 i \u2208 s, Disjoint (f i) a := by\n  simp only [disjoint_iff, sup_inf_distrib_right, sup_eq_bot_iff]\n#align finset.disjoint_sup_left Finset.disjoint_sup_left\n\nend OrderBot\n\nsection OrderTop\n\nvariable [OrderTop \u03b1]\n\ntheorem inf_sup_distrib_left (s : Finset \u03b9) (f : \u03b9 \u2192 \u03b1) (a : \u03b1) :\n    a \u2294 s.inf f = s.inf fun i => a \u2294 f i :=\n  @sup_inf_distrib_left \u03b1\u1d52\u1d48 _ _ _ _ _ _\n#align finset.inf_sup_distrib_left Finset.inf_sup_distrib_left\n\ntheorem inf_sup_distrib_right (s : Finset \u03b9) (f : \u03b9 \u2192 \u03b1) (a : \u03b1) :\n    s.inf f \u2294 a = s.inf fun i => f i \u2294 a :=\n  @sup_inf_distrib_right \u03b1\u1d52\u1d48 _ _ _ _ _ _\n#align finset.inf_sup_distrib_right Finset.inf_sup_distrib_right\n\nend OrderTop\n\nend DistribLattice\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1]\n\nsection OrderBot\n\nvariable [OrderBot \u03b1] {s : Finset \u03b9} {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem comp_sup_eq_sup_comp_of_is_total [SemilatticeSup \u03b2] [OrderBot \u03b2] (g : \u03b1 \u2192 \u03b2)\n    (mono_g : Monotone g) (bot : g \u22a5 = \u22a5) : g (s.sup f) = s.sup (g \u2218 f) :=\n  comp_sup_eq_sup_comp g mono_g.map_sup bot\n#align finset.comp_sup_eq_sup_comp_of_is_total Finset.comp_sup_eq_sup_comp_of_is_total\n\n@[simp]\nprotected theorem le_sup_iff (ha : \u22a5 < a) : a \u2264 s.sup f \u2194 \u2203 b \u2208 s, a \u2264 f b := by\n  apply Iff.intro\n  \u00b7 induction s using cons_induction with\n    | empty => exact (absurd \u00b7 (not_le_of_lt ha))\n    | @cons c t hc ih =>\n      rw [sup_cons, le_sup_iff]\n      exact fun\n      | Or.inl h => \u27e8c, mem_cons.2 (Or.inl rfl), h\u27e9\n      | Or.inr h => let \u27e8b, hb, hle\u27e9 := ih h; \u27e8b, mem_cons.2 (Or.inr hb), hle\u27e9\n  \u00b7 exact fun \u27e8b, hb, hle\u27e9 => le_trans hle (le_sup hb)\n#align finset.le_sup_iff Finset.le_sup_iff\n\n@[simp]\nprotected theorem lt_sup_iff : a < s.sup f \u2194 \u2203 b \u2208 s, a < f b := by\n  apply Iff.intro\n  \u00b7 induction s using cons_induction with\n    | empty => exact (absurd \u00b7 not_lt_bot)\n    | @cons c t hc ih =>\n      rw [sup_cons, lt_sup_iff]\n      exact fun\n      | Or.inl h => \u27e8c, mem_cons.2 (Or.inl rfl), h\u27e9\n      | Or.inr h => let \u27e8b, hb, hlt\u27e9 := ih h; \u27e8b, mem_cons.2 (Or.inr hb), hlt\u27e9\n  \u00b7 exact fun \u27e8b, hb, hlt\u27e9 => lt_of_lt_of_le hlt (le_sup hb)\n#align finset.lt_sup_iff Finset.lt_sup_iff\n\n@[simp]\nprotected theorem sup_lt_iff (ha : \u22a5 < a) : s.sup f < a \u2194 \u2200 b \u2208 s, f b < a :=\n  \u27e8fun hs b hb => lt_of_le_of_lt (le_sup hb) hs,\n    Finset.cons_induction_on s (fun _ => ha) fun c t hc => by\n      simpa only [sup_cons, sup_lt_iff, mem_cons, forall_eq_or_imp] using And.imp_right\u27e9\n#align finset.sup_lt_iff Finset.sup_lt_iff\n\nend OrderBot\n\nsection OrderTop\n\nvariable [OrderTop \u03b1] {s : Finset \u03b9} {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\ntheorem comp_inf_eq_inf_comp_of_is_total [SemilatticeInf \u03b2] [OrderTop \u03b2] (g : \u03b1 \u2192 \u03b2)\n    (mono_g : Monotone g) (top : g \u22a4 = \u22a4) : g (s.inf f) = s.inf (g \u2218 f) :=\n  comp_inf_eq_inf_comp g mono_g.map_inf top\n#align finset.comp_inf_eq_inf_comp_of_is_total Finset.comp_inf_eq_inf_comp_of_is_total\n\n@[simp]\nprotected theorem inf_le_iff (ha : a < \u22a4) : s.inf f \u2264 a \u2194 \u2203 b \u2208 s, f b \u2264 a :=\n  @Finset.le_sup_iff \u03b1\u1d52\u1d48 _ _ _ _ _ _ ha\n#align finset.inf_le_iff Finset.inf_le_iff\n\n@[simp]\nprotected theorem inf_lt_iff : s.inf f < a \u2194 \u2203 b \u2208 s, f b < a :=\n  @Finset.lt_sup_iff \u03b1\u1d52\u1d48 _ _ _ _ _ _\n#align finset.inf_lt_iff Finset.inf_lt_iff\n\n@[simp]\nprotected theorem lt_inf_iff (ha : a < \u22a4) : a < s.inf f \u2194 \u2200 b \u2208 s, a < f b :=\n  @Finset.sup_lt_iff \u03b1\u1d52\u1d48 _ _ _ _ _ _ ha\n#align finset.lt_inf_iff Finset.lt_inf_iff\n\nend OrderTop\n\nend LinearOrder\n\ntheorem inf_eq_inf\u1d62 [CompleteLattice \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 \u03b2) : s.inf f = \u2a05 a \u2208 s, f a :=\n  @sup_eq_sup\u1d62 _ \u03b2\u1d52\u1d48 _ _ _\n#align finset.inf_eq_infi Finset.inf_eq_inf\u1d62\n\ntheorem inf_id_eq_inf\u209b [CompleteLattice \u03b1] (s : Finset \u03b1) : s.inf id = inf\u209b s :=\n  @sup_id_eq_sup\u209b \u03b1\u1d52\u1d48 _ _\n#align finset.inf_id_eq_Inf Finset.inf_id_eq_inf\u209b\n\ntheorem inf_id_set_eq_inter\u209b (s : Finset (Set \u03b1)) : s.inf id = \u22c2\u2080 \u2191s :=\n  inf_id_eq_inf\u209b _\n#align finset.inf_id_set_eq_sInter Finset.inf_id_set_eq_inter\u209b\n\n@[simp]\ntheorem inf_set_eq_inter\u1d62 (s : Finset \u03b1) (f : \u03b1 \u2192 Set \u03b2) : s.inf f = \u22c2 x \u2208 s, f x :=\n  inf_eq_inf\u1d62 _ _\n#align finset.inf_set_eq_bInter Finset.inf_set_eq_inter\u1d62\n\ntheorem inf_eq_inf\u209b_image [CompleteLattice \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 \u03b2) :\n    s.inf f = inf\u209b (f '' s) :=\n  @sup_eq_sup\u209b_image _ \u03b2\u1d52\u1d48 _ _ _\n#align finset.inf_eq_Inf_image Finset.inf_eq_inf\u209b_image\n\nsection Sup'\n\nvariable [SemilatticeSup \u03b1]\n\ntheorem sup_of_mem {s : Finset \u03b2} (f : \u03b2 \u2192 \u03b1) {b : \u03b2} (h : b \u2208 s) :\n    \u2203 a : \u03b1, s.sup ((\u2191) \u2218 f : \u03b2 \u2192 WithBot \u03b1) = \u2191a :=\n  Exists.imp (fun _ => And.left) (@le_sup (WithBot \u03b1) _ _ _ _ _ _ h (f b) rfl)\n#align finset.sup_of_mem Finset.sup_of_mem\n\n/-- Given nonempty finset `s` then `s.sup' H f` is the supremum of its image under `f` in (possibly\nunbounded) join-semilattice `\u03b1`, where `H` is a proof of nonemptiness. If `\u03b1` has a bottom element\nyou may instead use `Finset.sup` which does not require `s` nonempty. -/\ndef sup' (s : Finset \u03b2) (H : s.Nonempty) (f : \u03b2 \u2192 \u03b1) : \u03b1 :=\n  WithBot.unbot (s.sup ((\u2191) \u2218 f)) (by simpa using H)\n#align finset.sup' Finset.sup'\n\nvariable {s : Finset \u03b2} (H : s.Nonempty) (f : \u03b2 \u2192 \u03b1)\n\n@[simp]\ntheorem coe_sup' : ((s.sup' H f : \u03b1) : WithBot \u03b1) = s.sup ((\u2191) \u2218 f) := by\n  rw [sup', WithBot.coe_unbot]\n#align finset.coe_sup' Finset.coe_sup'\n\n@[simp]\ntheorem sup'_cons {b : \u03b2} {hb : b \u2209 s} {h : (cons b s hb).Nonempty} :\n    (cons b s hb).sup' h f = f b \u2294 s.sup' H f := by\n  rw [\u2190 WithBot.coe_eq_coe]\n  simp [WithBot.coe_sup]\n#align finset.sup'_cons Finset.sup'_cons\n\n@[simp]\ntheorem sup'_insert [DecidableEq \u03b2] {b : \u03b2} {h : (insert b s).Nonempty} :\n    (insert b s).sup' h f = f b \u2294 s.sup' H f := by\n  rw [\u2190 WithBot.coe_eq_coe]\n  simp [WithBot.coe_sup]\n#align finset.sup'_insert Finset.sup'_insert\n\n@[simp]\ntheorem sup'_singleton {b : \u03b2} {h : ({b} : Finset \u03b2).Nonempty} : ({b} : Finset \u03b2).sup' h f = f b :=\n  rfl\n#align finset.sup'_singleton Finset.sup'_singleton\n\ntheorem sup'_le {a : \u03b1} (hs : \u2200 b \u2208 s, f b \u2264 a) : s.sup' H f \u2264 a := by\n  rw [\u2190 WithBot.coe_le_coe, coe_sup']\n  exact Finset.sup_le fun b h => WithBot.coe_le_coe.2 <| hs b h\n#align finset.sup'_le Finset.sup'_le\n\ntheorem le_sup' {b : \u03b2} (h : b \u2208 s) : f b \u2264 s.sup' \u27e8b, h\u27e9 f := by\n  rw [\u2190 WithBot.coe_le_coe, coe_sup']\n  exact le_sup (f := fun c => WithBot.some (f c)) h\n#align finset.le_sup' Finset.le_sup'\n\n@[simp]\ntheorem sup'_const (a : \u03b1) : s.sup' H (fun _ => a) = a := by\n  apply le_antisymm\n  \u00b7 apply sup'_le\n    intros\n    exact le_rfl\n  \u00b7 apply le_sup' (fun _ => a) H.choose_spec\n#align finset.sup'_const Finset.sup'_const\n\n@[simp]\ntheorem sup'_le_iff {a : \u03b1} : s.sup' H f \u2264 a \u2194 \u2200 b \u2208 s, f b \u2264 a :=\n  Iff.intro (fun h _ hb => le_trans (le_sup' f hb) h) (sup'_le H f)\n#align finset.sup'_le_iff Finset.sup'_le_iff\n\ntheorem sup'_bunion\u1d62 [DecidableEq \u03b2] {s : Finset \u03b3} (Hs : s.Nonempty) {t : \u03b3 \u2192 Finset \u03b2}\n    (Ht : \u2200 b, (t b).Nonempty) :\n    (s.bunion\u1d62 t).sup' (Hs.bunion\u1d62 fun b _ => Ht b) f = s.sup' Hs (fun b => (t b).sup' (Ht b) f) :=\n  eq_of_forall_ge_iff fun c => by simp [@forall_swap _ \u03b2]\n#align finset.sup'_bUnion Finset.sup'_bunion\u1d62\n\ntheorem comp_sup'_eq_sup'_comp [SemilatticeSup \u03b3] {s : Finset \u03b2} (H : s.Nonempty) {f : \u03b2 \u2192 \u03b1}\n    (g : \u03b1 \u2192 \u03b3) (g_sup : \u2200 x y, g (x \u2294 y) = g x \u2294 g y) : g (s.sup' H f) = s.sup' H (g \u2218 f) := by\n  rw [\u2190 WithBot.coe_eq_coe, coe_sup']\n  let g' := WithBot.map g\n  show g' \u2191(s.sup' H f) = s.sup fun a => g' \u2191(f a)\n  rw [coe_sup']\n  refine' comp_sup_eq_sup_comp g' _ rfl\n  intro f\u2081 f\u2082\n  cases f\u2081 using WithBot.recBotCoe with\n  | bot =>\n    rw [bot_sup_eq]\n    exact bot_sup_eq.symm\n  | coe f\u2081 =>\n    cases f\u2082 using WithBot.recBotCoe with\n    | bot => rfl\n    | coe f\u2082 => exact congr_arg _ (g_sup f\u2081 f\u2082)\n#align finset.comp_sup'_eq_sup'_comp Finset.comp_sup'_eq_sup'_comp\n\ntheorem sup'_induction {p : \u03b1 \u2192 Prop} (hp : \u2200 a\u2081, p a\u2081 \u2192 \u2200 a\u2082, p a\u2082 \u2192 p (a\u2081 \u2294 a\u2082))\n    (hs : \u2200 b \u2208 s, p (f b)) : p (s.sup' H f) := by\n  show @WithBot.recBotCoe \u03b1 (fun _ => Prop) True p \u2191(s.sup' H f)\n  rw [coe_sup']\n  refine' sup_induction trivial _ hs\n  rintro (_ | a\u2081) h\u2081 a\u2082 h\u2082\n  \u00b7 rw [WithBot.none_eq_bot, bot_sup_eq]\n    exact h\u2082\n  \u00b7 cases a\u2082 using WithBot.recBotCoe with\n    | bot => exact h\u2081\n    | coe a\u2082 => exact hp a\u2081 h\u2081 a\u2082 h\u2082\n#align finset.sup'_induction Finset.sup'_induction\n\ntheorem sup'_mem (s : Set \u03b1) (w : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s), x \u2294 y \u2208 s) {\u03b9 : Type _}\n    (t : Finset \u03b9) (H : t.Nonempty) (p : \u03b9 \u2192 \u03b1) (h : \u2200 i \u2208 t, p i \u2208 s) : t.sup' H p \u2208 s :=\n  sup'_induction H p w h\n#align finset.sup'_mem Finset.sup'_mem\n\n@[congr]\ntheorem sup'_congr {t : Finset \u03b2} {f g : \u03b2 \u2192 \u03b1} (h\u2081 : s = t) (h\u2082 : \u2200 x \u2208 s, f x = g x) :\n    s.sup' H f = t.sup' (h\u2081 \u25b8 H) g := by\n  subst s\n  refine' eq_of_forall_ge_iff fun c => _\n  simp (config := { contextual := true }) only [sup'_le_iff, h\u2082]\n#align finset.sup'_congr Finset.sup'_congr\n\n@[simp]\ntheorem sup'_map {s : Finset \u03b3} {f : \u03b3 \u21aa \u03b2} (g : \u03b2 \u2192 \u03b1) (hs : (s.map f).Nonempty)\n    (hs' : s.Nonempty := Finset.map_nonempty.mp hs) : (s.map f).sup' hs g = s.sup' hs' (g \u2218 f) := by\n  rw [\u2190 WithBot.coe_eq_coe, coe_sup', sup_map, coe_sup']\n  rfl\n#align finset.sup'_map Finset.sup'_map\n\nend Sup'\n\nsection Inf'\n\nvariable [SemilatticeInf \u03b1]\n\ntheorem inf_of_mem {s : Finset \u03b2} (f : \u03b2 \u2192 \u03b1) {b : \u03b2} (h : b \u2208 s) :\n    \u2203 a : \u03b1, s.inf ((\u2191) \u2218 f : \u03b2 \u2192 WithTop \u03b1) = \u2191a :=\n  @sup_of_mem \u03b1\u1d52\u1d48 _ _ _ f _ h\n#align finset.inf_of_mem Finset.inf_of_mem\n\n/-- Given nonempty finset `s` then `s.inf' H f` is the infimum of its image under `f` in (possibly\nunbounded) meet-semilattice `\u03b1`, where `H` is a proof of nonemptiness. If `\u03b1` has a top element you\nmay instead use `Finset.inf` which does not require `s` nonempty. -/\ndef inf' (s : Finset \u03b2) (H : s.Nonempty) (f : \u03b2 \u2192 \u03b1) : \u03b1 :=\n  WithTop.untop (s.inf ((\u2191) \u2218 f)) (by simpa using H)\n#align finset.inf' Finset.inf'\n\nvariable {s : Finset \u03b2} (H : s.Nonempty) (f : \u03b2 \u2192 \u03b1)\n\n@[simp]\ntheorem coe_inf' : ((s.inf' H f : \u03b1) : WithTop \u03b1) = s.inf ((\u2191) \u2218 f) :=\n  @coe_sup' \u03b1\u1d52\u1d48 _ _ _ H f\n#align finset.coe_inf' Finset.coe_inf'\n\n@[simp]\ntheorem inf'_cons {b : \u03b2} {hb : b \u2209 s} {h : (cons b s hb).Nonempty} :\n    (cons b s hb).inf' h f = f b \u2293 s.inf' H f :=\n  @sup'_cons \u03b1\u1d52\u1d48 _ _ _ H f _ _ h\n#align finset.inf'_cons Finset.inf'_cons\n\n@[simp]\ntheorem inf'_insert [DecidableEq \u03b2] {b : \u03b2} {h : (insert b s).Nonempty} :\n    (insert b s).inf' h f = f b \u2293 s.inf' H f :=\n  @sup'_insert \u03b1\u1d52\u1d48 _ _ _ H f _ _ h\n#align finset.inf'_insert Finset.inf'_insert\n\n@[simp]\ntheorem inf'_singleton {b : \u03b2} {h : ({b} : Finset \u03b2).Nonempty} : ({b} : Finset \u03b2).inf' h f = f b :=\n  rfl\n#align finset.inf'_singleton Finset.inf'_singleton\n\ntheorem le_inf' {a : \u03b1} (hs : \u2200 b \u2208 s, a \u2264 f b) : a \u2264 s.inf' H f :=\n  sup'_le (\u03b1 := \u03b1\u1d52\u1d48) H f hs\n#align finset.le_inf' Finset.le_inf'\n\ntheorem inf'_le {b : \u03b2} (h : b \u2208 s) : s.inf' \u27e8b, h\u27e9 f \u2264 f b :=\n  le_sup' (\u03b1 := \u03b1\u1d52\u1d48) f h\n#align finset.inf'_le Finset.inf'_le\n\n@[simp]\ntheorem inf'_const (a : \u03b1) : (s.inf' H fun _ => a) = a :=\n  sup'_const (\u03b1 := \u03b1\u1d52\u1d48) H a\n#align finset.inf'_const Finset.inf'_const\n\n@[simp]\ntheorem le_inf'_iff {a : \u03b1} : a \u2264 s.inf' H f \u2194 \u2200 b \u2208 s, a \u2264 f b :=\n  sup'_le_iff (\u03b1 := \u03b1\u1d52\u1d48) H f\n#align finset.le_inf'_iff Finset.le_inf'_iff\n\ntheorem inf'_bunion\u1d62 [DecidableEq \u03b2] {s : Finset \u03b3} (Hs : s.Nonempty) {t : \u03b3 \u2192 Finset \u03b2}\n    (Ht : \u2200 b, (t b).Nonempty) :\n    (s.bunion\u1d62 t).inf' (Hs.bunion\u1d62 fun b _ => Ht b) f = s.inf' Hs (fun b => (t b).inf' (Ht b) f) :=\n  sup'_bunion\u1d62 (\u03b1 := \u03b1\u1d52\u1d48) _ Hs Ht\n#align finset.inf'_bUnion Finset.inf'_bunion\u1d62\n\ntheorem comp_inf'_eq_inf'_comp [SemilatticeInf \u03b3] {s : Finset \u03b2} (H : s.Nonempty) {f : \u03b2 \u2192 \u03b1}\n    (g : \u03b1 \u2192 \u03b3) (g_inf : \u2200 x y, g (x \u2293 y) = g x \u2293 g y) : g (s.inf' H f) = s.inf' H (g \u2218 f) :=\n  comp_sup'_eq_sup'_comp (\u03b1 := \u03b1\u1d52\u1d48) (\u03b3 := \u03b3\u1d52\u1d48) H g g_inf\n#align finset.comp_inf'_eq_inf'_comp Finset.comp_inf'_eq_inf'_comp\n\ntheorem inf'_induction {p : \u03b1 \u2192 Prop} (hp : \u2200 a\u2081, p a\u2081 \u2192 \u2200 a\u2082, p a\u2082 \u2192 p (a\u2081 \u2293 a\u2082))\n    (hs : \u2200 b \u2208 s, p (f b)) : p (s.inf' H f) :=\n  sup'_induction (\u03b1 := \u03b1\u1d52\u1d48) H f hp hs\n#align finset.inf'_induction Finset.inf'_induction\n\ntheorem inf'_mem (s : Set \u03b1) (w : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s), x \u2293 y \u2208 s) {\u03b9 : Type _}\n    (t : Finset \u03b9) (H : t.Nonempty) (p : \u03b9 \u2192 \u03b1) (h : \u2200 i \u2208 t, p i \u2208 s) : t.inf' H p \u2208 s :=\n  inf'_induction H p w h\n#align finset.inf'_mem Finset.inf'_mem\n\n@[congr]\ntheorem inf'_congr {t : Finset \u03b2} {f g : \u03b2 \u2192 \u03b1} (h\u2081 : s = t) (h\u2082 : \u2200 x \u2208 s, f x = g x) :\n    s.inf' H f = t.inf' (h\u2081 \u25b8 H) g :=\n  sup'_congr (\u03b1 := \u03b1\u1d52\u1d48) H h\u2081 h\u2082\n#align finset.inf'_congr Finset.inf'_congr\n\n@[simp]\ntheorem inf'_map {s : Finset \u03b3} {f : \u03b3 \u21aa \u03b2} (g : \u03b2 \u2192 \u03b1) (hs : (s.map f).Nonempty)\n    (hs' : s.Nonempty := Finset.map_nonempty.mp hs) : (s.map f).inf' hs g = s.inf' hs' (g \u2218 f) :=\n  sup'_map (\u03b1 := \u03b1\u1d52\u1d48) _ hs hs'\n#align finset.inf'_map Finset.inf'_map\n\nend Inf'\n\nsection Sup\n\nvariable [SemilatticeSup \u03b1] [OrderBot \u03b1]\n\ntheorem sup'_eq_sup {s : Finset \u03b2} (H : s.Nonempty) (f : \u03b2 \u2192 \u03b1) : s.sup' H f = s.sup f :=\n  le_antisymm (sup'_le H f fun _ => le_sup) (Finset.sup_le fun _ => le_sup' f)\n#align finset.sup'_eq_sup Finset.sup'_eq_sup\n\ntheorem sup_closed_of_sup_closed {s : Set \u03b1} (t : Finset \u03b1) (htne : t.Nonempty) (h_subset : \u2191t \u2286 s)\n    (h : \u2200 (a) (_ : a \u2208 s) (b) (_ : b \u2208 s), a \u2294 b \u2208 s) : t.sup id \u2208 s :=\n  sup'_eq_sup htne id \u25b8 sup'_induction _ _ h h_subset\n#align finset.sup_closed_of_sup_closed Finset.sup_closed_of_sup_closed\n\ntheorem coe_sup_of_nonempty {s : Finset \u03b2} (h : s.Nonempty) (f : \u03b2 \u2192 \u03b1) :\n    (\u2191(s.sup f) : WithBot \u03b1) = s.sup ((\u2191) \u2218 f) := by simp only [\u2190 sup'_eq_sup h, coe_sup' h]\n#align finset.coe_sup_of_nonempty Finset.coe_sup_of_nonempty\n\nend Sup\n\nsection Inf\n\nvariable [SemilatticeInf \u03b1] [OrderTop \u03b1]\n\ntheorem inf'_eq_inf {s : Finset \u03b2} (H : s.Nonempty) (f : \u03b2 \u2192 \u03b1) : s.inf' H f = s.inf f :=\n  sup'_eq_sup (\u03b1 := \u03b1\u1d52\u1d48) H f\n#align finset.inf'_eq_inf Finset.inf'_eq_inf\n\ntheorem inf_closed_of_inf_closed {s : Set \u03b1} (t : Finset \u03b1) (htne : t.Nonempty) (h_subset : \u2191t \u2286 s)\n    (h : \u2200 (a) (_ : a \u2208 s) (b) (_ : b \u2208 s), a \u2293 b \u2208 s) : t.inf id \u2208 s :=\n  sup_closed_of_sup_closed (\u03b1 := \u03b1\u1d52\u1d48) t htne h_subset h\n#align finset.inf_closed_of_inf_closed Finset.inf_closed_of_inf_closed\n\ntheorem coe_inf_of_nonempty {s : Finset \u03b2} (h : s.Nonempty) (f : \u03b2 \u2192 \u03b1) :\n    (\u2191(s.inf f) : WithTop \u03b1) = s.inf ((\u2191) \u2218 f) :=\n  coe_sup_of_nonempty (\u03b1 := \u03b1\u1d52\u1d48) h f\n#align finset.coe_inf_of_nonempty Finset.coe_inf_of_nonempty\n\nend Inf\n\n@[simp]\nprotected theorem sup_apply {C : \u03b2 \u2192 Type _} [\u2200 b : \u03b2, SemilatticeSup (C b)]\n    [\u2200 b : \u03b2, OrderBot (C b)] (s : Finset \u03b1) (f : \u03b1 \u2192 \u2200 b : \u03b2, C b) (b : \u03b2) :\n    s.sup f b = s.sup fun a => f a b :=\n  comp_sup_eq_sup_comp (fun x : \u2200 b : \u03b2, C b => x b) (fun _ _ => rfl) rfl\n#align finset.sup_apply Finset.sup_apply\n\n@[simp]\nprotected theorem inf_apply {C : \u03b2 \u2192 Type _} [\u2200 b : \u03b2, SemilatticeInf (C b)]\n    [\u2200 b : \u03b2, OrderTop (C b)] (s : Finset \u03b1) (f : \u03b1 \u2192 \u2200 b : \u03b2, C b) (b : \u03b2) :\n    s.inf f b = s.inf fun a => f a b :=\n  Finset.sup_apply (C := fun b => (C b)\u1d52\u1d48) s f b\n#align finset.inf_apply Finset.inf_apply\n\n@[simp]\nprotected theorem sup'_apply {C : \u03b2 \u2192 Type _} [\u2200 b : \u03b2, SemilatticeSup (C b)]\n    {s : Finset \u03b1} (H : s.Nonempty) (f : \u03b1 \u2192 \u2200 b : \u03b2, C b) (b : \u03b2) :\n    s.sup' H f b = s.sup' H fun a => f a b :=\n  comp_sup'_eq_sup'_comp H (fun x : \u2200 b : \u03b2, C b => x b) fun _ _ => rfl\n#align finset.sup'_apply Finset.sup'_apply\n\n@[simp]\nprotected theorem inf'_apply {C : \u03b2 \u2192 Type _} [\u2200 b : \u03b2, SemilatticeInf (C b)]\n    {s : Finset \u03b1} (H : s.Nonempty) (f : \u03b1 \u2192 \u2200 b : \u03b2, C b) (b : \u03b2) :\n    s.inf' H f b = s.inf' H fun a => f a b :=\n  Finset.sup'_apply (C := fun b => (C b)\u1d52\u1d48) H f b\n#align finset.inf'_apply Finset.inf'_apply\n\n@[simp]\ntheorem toDual_sup' [SemilatticeSup \u03b1] {s : Finset \u03b9} (hs : s.Nonempty) (f : \u03b9 \u2192 \u03b1) :\n    toDual (s.sup' hs f) = s.inf' hs (toDual \u2218 f) :=\n  rfl\n#align finset.to_dual_sup' Finset.toDual_sup'\n\n@[simp]\ntheorem toDual_inf' [SemilatticeInf \u03b1] {s : Finset \u03b9} (hs : s.Nonempty) (f : \u03b9 \u2192 \u03b1) :\n    toDual (s.inf' hs f) = s.sup' hs (toDual \u2218 f) :=\n  rfl\n#align finset.to_dual_inf' Finset.toDual_inf'\n\n@[simp]\ntheorem ofDual_sup' [SemilatticeInf \u03b1] {s : Finset \u03b9} (hs : s.Nonempty) (f : \u03b9 \u2192 \u03b1\u1d52\u1d48) :\n    ofDual (s.sup' hs f) = s.inf' hs (ofDual \u2218 f) :=\n  rfl\n#align finset.of_dual_sup' Finset.ofDual_sup'\n\n@[simp]\ntheorem ofDual_inf' [SemilatticeSup \u03b1] {s : Finset \u03b9} (hs : s.Nonempty) (f : \u03b9 \u2192 \u03b1\u1d52\u1d48) :\n    ofDual (s.inf' hs f) = s.sup' hs (ofDual \u2218 f) :=\n  rfl\n#align finset.of_dual_inf' Finset.ofDual_inf'\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] {s : Finset \u03b9} (H : s.Nonempty) {f : \u03b9 \u2192 \u03b1} {a : \u03b1}\n\n@[simp]\ntheorem le_sup'_iff : a \u2264 s.sup' H f \u2194 \u2203 b \u2208 s, a \u2264 f b := by\n  rw [\u2190 WithBot.coe_le_coe, coe_sup', Finset.le_sup_iff (WithBot.bot_lt_coe a)]\n  exact exists_congr (fun _ => and_congr_right' WithBot.coe_le_coe)\n#align finset.le_sup'_iff Finset.le_sup'_iff\n\n@[simp]\ntheorem lt_sup'_iff : a < s.sup' H f \u2194 \u2203 b \u2208 s, a < f b := by\n  rw [\u2190 WithBot.coe_lt_coe, coe_sup', Finset.lt_sup_iff]\n  exact exists_congr (fun _ => and_congr_right' WithBot.coe_lt_coe)\n#align finset.lt_sup'_iff Finset.lt_sup'_iff\n\n@[simp]\ntheorem sup'_lt_iff : s.sup' H f < a \u2194 \u2200 i \u2208 s, f i < a := by\n  rw [\u2190 WithBot.coe_lt_coe, coe_sup', Finset.sup_lt_iff (WithBot.bot_lt_coe a)]\n  exact ball_congr (fun _ _ => WithBot.coe_lt_coe)\n#align finset.sup'_lt_iff Finset.sup'_lt_iff\n\n@[simp]\ntheorem inf'_le_iff : s.inf' H f \u2264 a \u2194 \u2203 i \u2208 s, f i \u2264 a :=\n  le_sup'_iff (\u03b1 := \u03b1\u1d52\u1d48) H\n#align finset.inf'_le_iff Finset.inf'_le_iff\n\n@[simp]\ntheorem inf'_lt_iff : s.inf' H f < a \u2194 \u2203 i \u2208 s, f i < a :=\n  lt_sup'_iff (\u03b1 := \u03b1\u1d52\u1d48) H\n#align finset.inf'_lt_iff Finset.inf'_lt_iff\n\n@[simp]\ntheorem lt_inf'_iff : a < s.inf' H f \u2194 \u2200 i \u2208 s, a < f i :=\n  sup'_lt_iff (\u03b1 := \u03b1\u1d52\u1d48) H\n#align finset.lt_inf'_iff Finset.lt_inf'_iff\n\ntheorem exists_mem_eq_sup' (f : \u03b9 \u2192 \u03b1) : \u2203 i, i \u2208 s \u2227 s.sup' H f = f i := by\n  refine' H.cons_induction (fun c => _) fun c s hc hs ih => _\n  \u00b7 exact \u27e8c, mem_singleton_self c, rfl\u27e9\n  \u00b7 rcases ih with \u27e8b, hb, h'\u27e9\n    rw [sup'_cons hs, h']\n    cases le_total (f b) (f c) with\n    | inl h => exact \u27e8c, mem_cons.2 (Or.inl rfl), sup_eq_left.2 h\u27e9\n    | inr h => exact \u27e8b, mem_cons.2 (Or.inr hb), sup_eq_right.2 h\u27e9\n#align finset.exists_mem_eq_sup' Finset.exists_mem_eq_sup'\n\ntheorem exists_mem_eq_inf' (f : \u03b9 \u2192 \u03b1) : \u2203 i, i \u2208 s \u2227 s.inf' H f = f i :=\n  exists_mem_eq_sup' (\u03b1 := \u03b1\u1d52\u1d48) H f\n#align finset.exists_mem_eq_inf' Finset.exists_mem_eq_inf'\n\ntheorem exists_mem_eq_sup [OrderBot \u03b1] (s : Finset \u03b9) (h : s.Nonempty) (f : \u03b9 \u2192 \u03b1) :\n    \u2203 i, i \u2208 s \u2227 s.sup f = f i :=\n  sup'_eq_sup h f \u25b8 exists_mem_eq_sup' h f\n#align finset.exists_mem_eq_sup Finset.exists_mem_eq_sup\n\ntheorem exists_mem_eq_inf [OrderTop \u03b1] (s : Finset \u03b9) (h : s.Nonempty) (f : \u03b9 \u2192 \u03b1) :\n    \u2203 i, i \u2208 s \u2227 s.inf f = f i :=\n  exists_mem_eq_sup (\u03b1 := \u03b1\u1d52\u1d48) s h f\n#align finset.exists_mem_eq_inf Finset.exists_mem_eq_inf\n\nend LinearOrder\n\n/-! ### max and min of finite sets -/\n\n\nsection MaxMin\n\nvariable [LinearOrder \u03b1]\n\n/-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty,\nand `\u22a5` otherwise. It belongs to `WithBot \u03b1`. If you want to get an element of `\u03b1`, see\n`s.max'`. -/\nprotected def max (s : Finset \u03b1) : WithBot \u03b1 :=\n  sup s (\u2191)\n#align finset.max Finset.max\n\ntheorem max_eq_sup_coe {s : Finset \u03b1} : s.max = s.sup (\u2191) :=\n  rfl\n#align finset.max_eq_sup_coe Finset.max_eq_sup_coe\n\ntheorem max_eq_sup_withBot (s : Finset \u03b1) : s.max = sup s (\u2191) :=\n  rfl\n#align finset.max_eq_sup_with_bot Finset.max_eq_sup_withBot\n\n@[simp]\ntheorem max_empty : (\u2205 : Finset \u03b1).max = \u22a5 :=\n  rfl\n#align finset.max_empty Finset.max_empty\n\n@[simp]\ntheorem max_insert {a : \u03b1} {s : Finset \u03b1} : (insert a s).max = max \u2191a s.max :=\n  fold_insert_idem\n#align finset.max_insert Finset.max_insert\n\n@[simp]\ntheorem max_singleton {a : \u03b1} : Finset.max {a} = (a : WithBot \u03b1) := by\n  rw [\u2190 insert_emptyc_eq]\n  exact max_insert\n#align finset.max_singleton Finset.max_singleton\n\ntheorem max_of_mem {s : Finset \u03b1} {a : \u03b1} (h : a \u2208 s) : \u2203 b : \u03b1, s.max = b := by\n  obtain \u27e8b, h, _\u27e9 := le_sup (\u03b1 := WithBot \u03b1) h _ rfl\n  exact \u27e8b, h\u27e9\n#align finset.max_of_mem Finset.max_of_mem\n\n\n\ntheorem max_eq_bot {s : Finset \u03b1} : s.max = \u22a5 \u2194 s = \u2205 :=\n  \u27e8fun h \u21a6 s.eq_empty_or_nonempty.elim id fun H \u21a6 by\n      obtain \u27e8a, ha\u27e9 := max_of_nonempty H\n      rw [h] at ha; cases ha; done, -- Porting note: error without `done`\n    fun h \u21a6 h.symm \u25b8 max_empty\u27e9\n#align finset.max_eq_bot Finset.max_eq_bot\n\ntheorem mem_of_max {s : Finset \u03b1} : \u2200 {a : \u03b1}, s.max = a \u2192 a \u2208 s := by\n  induction' s using Finset.induction_on with b s _ ih\n  \u00b7 intro _ H; cases H\n  \u00b7 intro a h\n    by_cases p : b = a\n    \u00b7 induction p\n      exact mem_insert_self b s\n    \u00b7 cases' max_choice (\u2191b) s.max with q q <;> rw [max_insert, q] at h\n      \u00b7 cases h\n        cases p rfl\n      \u00b7 exact mem_insert_of_mem (ih h)\n#align finset.mem_of_max Finset.mem_of_max\n\ntheorem le_max {a : \u03b1} {s : Finset \u03b1} (as : a \u2208 s) : \u2191a \u2264 s.max :=\n  le_sup as\n#align finset.le_max Finset.le_max\n\ntheorem not_mem_of_max_lt_coe {a : \u03b1} {s : Finset \u03b1} (h : s.max < a) : a \u2209 s :=\n  mt le_max h.not_le\n#align finset.not_mem_of_max_lt_coe Finset.not_mem_of_max_lt_coe\n\ntheorem le_max_of_eq {s : Finset \u03b1} {a b : \u03b1} (h\u2081 : a \u2208 s) (h\u2082 : s.max = b) : a \u2264 b :=\n  WithBot.coe_le_coe.mp <| (le_max h\u2081).trans h\u2082.le\n#align finset.le_max_of_eq Finset.le_max_of_eq\n\ntheorem not_mem_of_max_lt {s : Finset \u03b1} {a b : \u03b1} (h\u2081 : b < a) (h\u2082 : s.max = \u2191b) : a \u2209 s :=\n  Finset.not_mem_of_max_lt_coe <| h\u2082.trans_lt <| WithBot.coe_lt_coe.mpr h\u2081\n#align finset.not_mem_of_max_lt Finset.not_mem_of_max_lt\n\ntheorem max_mono {s t : Finset \u03b1} (st : s \u2286 t) : s.max \u2264 t.max :=\n  sup_mono st\n#align finset.max_mono Finset.max_mono\n\nprotected theorem max_le {M : WithBot \u03b1} {s : Finset \u03b1} (st : \u2200 a \u2208 s, (a : WithBot \u03b1) \u2264 M) :\n    s.max \u2264 M :=\n  Finset.sup_le st\n#align finset.max_le Finset.max_le\n\n/-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty,\nand `\u22a4` otherwise. It belongs to `WithTop \u03b1`. If you want to get an element of `\u03b1`, see\n`s.min'`. -/\nprotected def min (s : Finset \u03b1) : WithTop \u03b1 :=\n  inf s (\u2191)\n#align finset.min Finset.min\n\ntheorem min_eq_inf_withTop (s : Finset \u03b1) : s.min = inf s (\u2191) :=\n  rfl\n#align finset.min_eq_inf_with_top Finset.min_eq_inf_withTop\n\n@[simp]\ntheorem min_empty : (\u2205 : Finset \u03b1).min = \u22a4 :=\n  rfl\n#align finset.min_empty Finset.min_empty\n\n@[simp]\ntheorem min_insert {a : \u03b1} {s : Finset \u03b1} : (insert a s).min = min (\u2191a) s.min :=\n  fold_insert_idem\n#align finset.min_insert Finset.min_insert\n\n@[simp]\ntheorem min_singleton {a : \u03b1} : Finset.min {a} = (a : WithTop \u03b1) := by\n  rw [\u2190 insert_emptyc_eq]\n  exact min_insert\n#align finset.min_singleton Finset.min_singleton\n\ntheorem min_of_mem {s : Finset \u03b1} {a : \u03b1} (h : a \u2208 s) : \u2203 b : \u03b1, s.min = b := by\n  obtain \u27e8b, h, _\u27e9 := inf_le (\u03b1 := WithTop \u03b1) h _ rfl\n  exact \u27e8b, h\u27e9\n#align finset.min_of_mem Finset.min_of_mem\n\ntheorem min_of_nonempty {s : Finset \u03b1} (h : s.Nonempty) : \u2203 a : \u03b1, s.min = a :=\n  let \u27e8_, h\u27e9 := h\n  min_of_mem h\n#align finset.min_of_nonempty Finset.min_of_nonempty\n\ntheorem min_eq_top {s : Finset \u03b1} : s.min = \u22a4 \u2194 s = \u2205 :=\n  \u27e8fun h =>\n    s.eq_empty_or_nonempty.elim id fun H =>\n      by\n      let \u27e8a, ha\u27e9 := min_of_nonempty H\n      rw [h] at ha; cases ha; done, -- Porting note: error without `done`\n    fun h => h.symm \u25b8 min_empty\u27e9\n#align finset.min_eq_top Finset.min_eq_top\n\ntheorem mem_of_min {s : Finset \u03b1} : \u2200 {a : \u03b1}, s.min = a \u2192 a \u2208 s :=\n  @mem_of_max \u03b1\u1d52\u1d48 _ s\n#align finset.mem_of_min Finset.mem_of_min\n\ntheorem min_le {a : \u03b1} {s : Finset \u03b1} (as : a \u2208 s) : s.min \u2264 a :=\n  inf_le as\n#align finset.min_le Finset.min_le\n\ntheorem not_mem_of_coe_lt_min {a : \u03b1} {s : Finset \u03b1} (h : \u2191a < s.min) : a \u2209 s :=\n  mt min_le h.not_le\n#align finset.not_mem_of_coe_lt_min Finset.not_mem_of_coe_lt_min\n\ntheorem min_le_of_eq {s : Finset \u03b1} {a b : \u03b1} (h\u2081 : b \u2208 s) (h\u2082 : s.min = a) : a \u2264 b :=\n  WithTop.coe_le_coe.mp <| h\u2082.ge.trans (min_le h\u2081)\n#align finset.min_le_of_eq Finset.min_le_of_eq\n\ntheorem not_mem_of_lt_min {s : Finset \u03b1} {a b : \u03b1} (h\u2081 : a < b) (h\u2082 : s.min = \u2191b) : a \u2209 s :=\n  Finset.not_mem_of_coe_lt_min <| (WithTop.coe_lt_coe.mpr h\u2081).trans_eq h\u2082.symm\n#align finset.not_mem_of_lt_min Finset.not_mem_of_lt_min\n\ntheorem min_mono {s t : Finset \u03b1} (st : s \u2286 t) : t.min \u2264 s.min :=\n  inf_mono st\n#align finset.min_mono Finset.min_mono\n\nprotected theorem le_min {m : WithTop \u03b1} {s : Finset \u03b1} (st : \u2200 a : \u03b1, a \u2208 s \u2192 m \u2264 a) : m \u2264 s.min :=\n  Finset.le_inf st\n#align finset.le_min Finset.le_min\n\n/-- Given a nonempty finset `s` in a linear order `\u03b1`, then `s.min' h` is its minimum, as an\nelement of `\u03b1`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`,\ntaking values in `WithTop \u03b1`. -/\ndef min' (s : Finset \u03b1) (H : s.Nonempty) : \u03b1 :=\n  inf' s H id\n#align finset.min' Finset.min'\n\n/-- Given a nonempty finset `s` in a linear order `\u03b1`, then `s.max' h` is its maximum, as an\nelement of `\u03b1`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`,\ntaking values in `WithBot \u03b1`. -/\ndef max' (s : Finset \u03b1) (H : s.Nonempty) : \u03b1 :=\n  sup' s H id\n#align finset.max' Finset.max'\n\nvariable (s : Finset \u03b1) (H : s.Nonempty) {x : \u03b1}\n\ntheorem min'_mem : s.min' H \u2208 s :=\n  mem_of_min <| by simp only [Finset.min, min', id_eq, coe_inf']; rfl\n#align finset.min'_mem Finset.min'_mem\n\ntheorem min'_le (x) (H2 : x \u2208 s) : s.min' \u27e8x, H2\u27e9 \u2264 x :=\n  min_le_of_eq H2 (WithTop.coe_untop _ _).symm\n#align finset.min'_le Finset.min'_le\n\ntheorem le_min' (x) (H2 : \u2200 y \u2208 s, x \u2264 y) : x \u2264 s.min' H :=\n  H2 _ <| min'_mem _ _\n#align finset.le_min' Finset.le_min'\n\ntheorem isLeast_min' : IsLeast (\u2191s) (s.min' H) :=\n  \u27e8min'_mem _ _, min'_le _\u27e9\n#align finset.is_least_min' Finset.isLeast_min'\n\n@[simp]\ntheorem le_min'_iff {x} : x \u2264 s.min' H \u2194 \u2200 y \u2208 s, x \u2264 y :=\n  le_isGLB_iff (isLeast_min' s H).isGLB\n#align finset.le_min'_iff Finset.le_min'_iff\n\n/-- `{a}.min' _` is `a`. -/\n@[simp]\ntheorem min'_singleton (a : \u03b1) : ({a} : Finset \u03b1).min' (singleton_nonempty _) = a := by simp [min']\n#align finset.min'_singleton Finset.min'_singleton\n\ntheorem max'_mem : s.max' H \u2208 s :=\n  mem_of_max <| by simp only [max', Finset.max, id_eq, coe_sup']; rfl\n#align finset.max'_mem Finset.max'_mem\n\ntheorem le_max' (x) (H2 : x \u2208 s) : x \u2264 s.max' \u27e8x, H2\u27e9 :=\n  le_max_of_eq H2 (WithBot.coe_unbot _ _).symm\n#align finset.le_max' Finset.le_max'\n\ntheorem max'_le (x) (H2 : \u2200 y \u2208 s, y \u2264 x) : s.max' H \u2264 x :=\n  H2 _ <| max'_mem _ _\n#align finset.max'_le Finset.max'_le\n\ntheorem isGreatest_max' : IsGreatest (\u2191s) (s.max' H) :=\n  \u27e8max'_mem _ _, le_max' _\u27e9\n#align finset.is_greatest_max' Finset.isGreatest_max'\n\n@[simp]\ntheorem max'_le_iff {x} : s.max' H \u2264 x \u2194 \u2200 y \u2208 s, y \u2264 x :=\n  isLUB_le_iff (isGreatest_max' s H).isLUB\n#align finset.max'_le_iff Finset.max'_le_iff\n\n@[simp]\ntheorem max'_lt_iff {x} : s.max' H < x \u2194 \u2200 y \u2208 s, y < x :=\n  \u27e8fun Hlt y hy => (s.le_max' y hy).trans_lt Hlt, fun H => H _ <| s.max'_mem _\u27e9\n#align finset.max'_lt_iff Finset.max'_lt_iff\n\n@[simp]\ntheorem lt_min'_iff : x < s.min' H \u2194 \u2200 y \u2208 s, x < y :=\n  @max'_lt_iff \u03b1\u1d52\u1d48 _ _ H _\n#align finset.lt_min'_iff Finset.lt_min'_iff\n\ntheorem max'_eq_sup' : s.max' H = s.sup' H id :=\n  eq_of_forall_ge_iff fun _ => (max'_le_iff _ _).trans (sup'_le_iff _ _).symm\n#align finset.max'_eq_sup' Finset.max'_eq_sup'\n\ntheorem min'_eq_inf' : s.min' H = s.inf' H id :=\n  @max'_eq_sup' \u03b1\u1d52\u1d48 _ s H\n#align finset.min'_eq_inf' Finset.min'_eq_inf'\n\n/-- `{a}.max' _` is `a`. -/\n@[simp]\ntheorem max'_singleton (a : \u03b1) : ({a} : Finset \u03b1).max' (singleton_nonempty _) = a := by simp [max']\n#align finset.max'_singleton Finset.max'_singleton\n\ntheorem min'_lt_max' {i j} (H1 : i \u2208 s) (H2 : j \u2208 s) (H3 : i \u2260 j) :\n    s.min' \u27e8i, H1\u27e9 < s.max' \u27e8i, H1\u27e9 :=\n  isGLB_lt_isLUB_of_ne (s.isLeast_min' _).isGLB (s.isGreatest_max' _).isLUB H1 H2 H3\n#align finset.min'_lt_max' Finset.min'_lt_max'\n\n/-- If there's more than 1 element, the min' is less than the max'. An alternate version of\n`min'_lt_max'` which is sometimes more convenient.\n-/\ntheorem min'_lt_max'_of_card (h\u2082 : 1 < card s) :\n    s.min' (Finset.card_pos.mp <| lt_trans zero_lt_one h\u2082) <\n      s.max' (Finset.card_pos.mp <| lt_trans zero_lt_one h\u2082) := by\n  rcases one_lt_card.1 h\u2082 with \u27e8a, ha, b, hb, hab\u27e9\n  exact s.min'_lt_max' ha hb hab\n#align finset.min'_lt_max'_of_card Finset.min'_lt_max'_of_card\n\ntheorem map_ofDual_min (s : Finset \u03b1\u1d52\u1d48) : s.min.map ofDual = (s.image ofDual).max := by\n  rw [max_eq_sup_withBot, sup_image]\n  exact congr_fun Option.map_id _\n#align finset.map_of_dual_min Finset.map_ofDual_min\n\ntheorem map_ofDual_max (s : Finset \u03b1\u1d52\u1d48) : s.max.map ofDual = (s.image ofDual).min := by\n  rw [min_eq_inf_withTop, inf_image]\n  exact congr_fun Option.map_id _\n#align finset.map_of_dual_max Finset.map_ofDual_max\n\ntheorem map_toDual_min (s : Finset \u03b1) : s.min.map toDual = (s.image toDual).max := by\n  rw [max_eq_sup_withBot, sup_image]\n  exact congr_fun Option.map_id _\n#align finset.map_to_dual_min Finset.map_toDual_min\n\ntheorem map_toDual_max (s : Finset \u03b1) : s.max.map toDual = (s.image toDual).min := by\n  rw [min_eq_inf_withTop, inf_image]\n  exact congr_fun Option.map_id _\n#align finset.map_to_dual_max Finset.map_toDual_max\n\n-- Porting note: new proofs without `convert` for the next four theorems.\n\ntheorem ofDual_min' {s : Finset \u03b1\u1d52\u1d48} (hs : s.Nonempty) :\n    ofDual (min' s hs) = max' (s.image ofDual) (hs.image _) := by\n  rw [\u2190 WithBot.coe_eq_coe]\n  simp only [min'_eq_inf', id_eq, ofDual_inf', Function.comp_apply, coe_sup', max'_eq_sup',\n    sup_image]\n  rfl\n#align finset.of_dual_min' Finset.ofDual_min'\n\ntheorem ofDual_max' {s : Finset \u03b1\u1d52\u1d48} (hs : s.Nonempty) :\n    ofDual (max' s hs) = min' (s.image ofDual) (hs.image _) := by\n  rw [\u2190 WithTop.coe_eq_coe]\n  simp only [max'_eq_sup', id_eq, ofDual_sup', Function.comp_apply, coe_inf', min'_eq_inf',\n    inf_image]\n  rfl\n#align finset.of_dual_max' Finset.ofDual_max'\n\ntheorem toDual_min' {s : Finset \u03b1} (hs : s.Nonempty) :\n    toDual (min' s hs) = max' (s.image toDual) (hs.image _) := by\n  rw [\u2190 WithBot.coe_eq_coe]\n  simp only [min'_eq_inf', id_eq, toDual_inf', Function.comp_apply, coe_sup', max'_eq_sup',\n    sup_image]\n  rfl\n#align finset.to_dual_min' Finset.toDual_min'\n\ntheorem toDual_max' {s : Finset \u03b1} (hs : s.Nonempty) :\n    toDual (max' s hs) = min' (s.image toDual) (hs.image _) := by\n  rw [\u2190 WithTop.coe_eq_coe]\n  simp only [max'_eq_sup', id_eq, toDual_sup', Function.comp_apply, coe_inf', min'_eq_inf',\n    inf_image]\n  rfl\n#align finset.to_dual_max' Finset.toDual_max'\n\ntheorem max'_subset {s t : Finset \u03b1} (H : s.Nonempty) (hst : s \u2286 t) :\n    s.max' H \u2264 t.max' (H.mono hst) :=\n  le_max' _ _ (hst (s.max'_mem H))\n#align finset.max'_subset Finset.max'_subset\n\ntheorem min'_subset {s t : Finset \u03b1} (H : s.Nonempty) (hst : s \u2286 t) :\n    t.min' (H.mono hst) \u2264 s.min' H :=\n  min'_le _ _ (hst (s.min'_mem H))\n#align finset.min'_subset Finset.min'_subset\n\ntheorem max'_insert (a : \u03b1) (s : Finset \u03b1) (H : s.Nonempty) :\n    (insert a s).max' (s.insert_nonempty a) = max (s.max' H) a :=\n  (isGreatest_max' _ _).unique <| by\n    rw [coe_insert, max_comm]\n    exact (isGreatest_max' _ _).insert _\n#align finset.max'_insert Finset.max'_insert\n\ntheorem min'_insert (a : \u03b1) (s : Finset \u03b1) (H : s.Nonempty) :\n    (insert a s).min' (s.insert_nonempty a) = min (s.min' H) a :=\n  (isLeast_min' _ _).unique <| by\n    rw [coe_insert, min_comm]\n    exact (isLeast_min' _ _).insert _\n#align finset.min'_insert Finset.min'_insert\n\ntheorem lt_max'_of_mem_erase_max' [DecidableEq \u03b1] {a : \u03b1} (ha : a \u2208 s.erase (s.max' H)) :\n    a < s.max' H :=\n  lt_of_le_of_ne (le_max' _ _ (mem_of_mem_erase ha)) <| ne_of_mem_of_not_mem ha <| not_mem_erase _ _\n#align finset.lt_max'_of_mem_erase_max' Finset.lt_max'_of_mem_erase_max'\n\ntheorem min'_lt_of_mem_erase_min' [DecidableEq \u03b1] {a : \u03b1} (ha : a \u2208 s.erase (s.min' H)) :\n    s.min' H < a :=\n  @lt_max'_of_mem_erase_max' \u03b1\u1d52\u1d48 _ s H _ a ha\n#align finset.min'_lt_of_mem_erase_min' Finset.min'_lt_of_mem_erase_min'\n\n@[simp]\ntheorem max'_image [LinearOrder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Monotone f) (s : Finset \u03b1)\n    (h : (s.image f).Nonempty) : (s.image f).max' h = f (s.max' ((Nonempty.image_iff f).mp h)) := by\n  refine'\n    le_antisymm (max'_le _ _ _ fun y hy => _) (le_max' _ _ (mem_image.mpr \u27e8_, max'_mem _ _, rfl\u27e9))\n  obtain \u27e8x, hx, rfl\u27e9 := mem_image.mp hy\n  exact hf (le_max' _ _ hx)\n#align finset.max'_image Finset.max'_image\n\n@[simp]\ntheorem min'_image [LinearOrder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Monotone f) (s : Finset \u03b1)\n    (h : (s.image f).Nonempty) : (s.image f).min' h = f (s.min' ((Nonempty.image_iff f).mp h)) := by\n  refine'\n    le_antisymm (min'_le _ _ (mem_image.mpr \u27e8_, min'_mem _ _, rfl\u27e9)) (le_min' _ _ _ fun y hy => _)\n  obtain \u27e8x, hx, rfl\u27e9 := mem_image.mp hy\n  exact hf (min'_le _ _ hx)\n#align finset.min'_image Finset.min'_image\n\ntheorem coe_max' {s : Finset \u03b1} (hs : s.Nonempty) : \u2191(s.max' hs) = s.max :=\n  coe_sup' hs id\n#align finset.coe_max' Finset.coe_max'\n\ntheorem coe_min' {s : Finset \u03b1} (hs : s.Nonempty) : \u2191(s.min' hs) = s.min :=\n  coe_inf' hs id\n#align finset.coe_min' Finset.coe_min'\n\ntheorem max_mem_image_coe {s : Finset \u03b1} (hs : s.Nonempty) :\n    s.max \u2208 (s.image (\u2191) : Finset (WithBot \u03b1)) :=\n  mem_image.2 \u27e8max' s hs, max'_mem _ _, coe_max' hs\u27e9\n#align finset.max_mem_image_coe Finset.max_mem_image_coe\n\ntheorem min_mem_image_coe {s : Finset \u03b1} (hs : s.Nonempty) :\n    s.min \u2208 (s.image (\u2191) : Finset (WithTop \u03b1)) :=\n  mem_image.2 \u27e8min' s hs, min'_mem _ _, coe_min' hs\u27e9\n#align finset.min_mem_image_coe Finset.min_mem_image_coe\n\ntheorem max_mem_insert_bot_image_coe (s : Finset \u03b1) :\n    s.max \u2208 (insert \u22a5 (s.image (\u2191)) : Finset (WithBot \u03b1)) :=\n  mem_insert.2 <| s.eq_empty_or_nonempty.imp max_eq_bot.2 max_mem_image_coe\n#align finset.max_mem_insert_bot_image_coe Finset.max_mem_insert_bot_image_coe\n\ntheorem min_mem_insert_top_image_coe (s : Finset \u03b1) :\n    s.min \u2208 (insert \u22a4 (s.image (\u2191)) : Finset (WithTop \u03b1)) :=\n  mem_insert.2 <| s.eq_empty_or_nonempty.imp min_eq_top.2 min_mem_image_coe\n#align finset.min_mem_insert_top_image_coe Finset.min_mem_insert_top_image_coe\n\ntheorem max'_erase_ne_self {s : Finset \u03b1} (s0 : (s.erase x).Nonempty) : (s.erase x).max' s0 \u2260 x :=\n  ne_of_mem_erase (max'_mem _ s0)\n#align finset.max'_erase_ne_self Finset.max'_erase_ne_self\n\ntheorem min'_erase_ne_self {s : Finset \u03b1} (s0 : (s.erase x).Nonempty) : (s.erase x).min' s0 \u2260 x :=\n  ne_of_mem_erase (min'_mem _ s0)\n#align finset.min'_erase_ne_self Finset.min'_erase_ne_self\n\ntheorem max_erase_ne_self {s : Finset \u03b1} : (s.erase x).max \u2260 x := by\n  by_cases s0 : (s.erase x).Nonempty\n  \u00b7 refine' ne_of_eq_of_ne (coe_max' s0).symm _\n    exact WithBot.coe_eq_coe.not.mpr (max'_erase_ne_self _)\n  \u00b7 rw [not_nonempty_iff_eq_empty.mp s0, max_empty]\n    exact WithBot.bot_ne_coe\n#align finset.max_erase_ne_self Finset.max_erase_ne_self\n\ntheorem min_erase_ne_self {s : Finset \u03b1} : (s.erase x).min \u2260 x := by\n  -- Porting note: old proof `convert @max_erase_ne_self \u03b1\u1d52\u1d48 _ _ _`\n  convert @max_erase_ne_self \u03b1\u1d52\u1d48 _ (toDual x) (s.map toDual.toEmbedding) using 1\n  apply congr_arg -- porting note: forces unfolding to see `Finset.min` is `Finset.max`\n  congr!\n  \u00b7 ext; simp only [mem_map_equiv]; exact Iff.rfl\n#align finset.min_erase_ne_self Finset.min_erase_ne_self\n\ntheorem exists_next_right {x : \u03b1} {s : Finset \u03b1} (h : \u2203 y \u2208 s, x < y) :\n    \u2203 y \u2208 s, x < y \u2227 \u2200 z \u2208 s, x < z \u2192 y \u2264 z :=\n  have Hne : (s.filter ((\u00b7 < \u00b7) x)).Nonempty := h.imp fun y hy => mem_filter.2 (by simpa)\n  have aux := (mem_filter.1 (min'_mem _ Hne))\n  \u27e8min' _ Hne, aux.1, by simp, fun z hzs hz => min'_le _ _ <| mem_filter.2 \u27e8hzs, by simpa\u27e9\u27e9\n#align finset.exists_next_right Finset.exists_next_right\n\ntheorem exists_next_left {x : \u03b1} {s : Finset \u03b1} (h : \u2203 y \u2208 s, y < x) :\n    \u2203 y \u2208 s, y < x \u2227 \u2200 z \u2208 s, z < x \u2192 z \u2264 y :=\n  @exists_next_right \u03b1\u1d52\u1d48 _ x s h\n#align finset.exists_next_left Finset.exists_next_left\n\n/-- If finsets `s` and `t` are interleaved, then `Finset.card s \u2264 Finset.card t + 1`. -/\ntheorem card_le_of_interleaved {s t : Finset \u03b1}\n    (h : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s),\n        x < y \u2192 (\u2200 z \u2208 s, z \u2209 Set.Ioo x y) \u2192 \u2203 z \u2208 t, x < z \u2227 z < y) :\n    s.card \u2264 t.card + 1 := by\n  replace h : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s), x < y \u2192 \u2203 z \u2208 t, x < z \u2227 z < y\n  \u00b7 intro x hx y hy hxy\n    rcases exists_next_right \u27e8y, hy, hxy\u27e9 with \u27e8a, has, hxa, ha\u27e9\n    rcases h x hx a has hxa fun z hzs hz => hz.2.not_le <| ha _ hzs hz.1 with \u27e8b, hbt, hxb, hba\u27e9\n    exact \u27e8b, hbt, hxb, hba.trans_le <| ha _ hy hxy\u27e9\n  set f : \u03b1 \u2192 WithTop \u03b1 := fun x => (t.filter fun y => x < y).min\n  have f_mono : StrictMonoOn f s := by\n    intro x hx y hy hxy\n    rcases h x hx y hy hxy with \u27e8a, hat, hxa, hay\u27e9\n    calc\n      f x \u2264 a := min_le (mem_filter.2 \u27e8hat, by simpa\u27e9)\n      _ < f y :=\n        (Finset.lt_inf_iff <| WithTop.coe_lt_top a).2 fun b hb =>\n          WithTop.coe_lt_coe.2 <| hay.trans (by simpa using (mem_filter.1 hb).2)\n\n  calc\n    s.card = (s.image f).card := (card_image_of_injOn f_mono.injOn).symm\n    _ \u2264 (insert \u22a4 (t.image (\u2191)) : Finset (WithTop \u03b1)).card :=\n      card_mono <| image_subset_iff.2 fun x _ =>\n          insert_subset_insert _ (image_subset_image <| filter_subset _ _)\n            (min_mem_insert_top_image_coe _)\n    _ \u2264 t.card + 1 := (card_insert_le _ _).trans (add_le_add_right card_image_le _)\n#align finset.card_le_of_interleaved Finset.card_le_of_interleaved\n\n/-- If finsets `s` and `t` are interleaved, then `Finset.card s \u2264 Finset.card (t \\ s) + 1`. -/\ntheorem card_le_diff_of_interleaved {s t : Finset \u03b1}\n    (h :\n      \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s),\n        x < y \u2192 (\u2200 z \u2208 s, z \u2209 Set.Ioo x y) \u2192 \u2203 z \u2208 t, x < z \u2227 z < y) :\n    s.card \u2264 (t \\ s).card + 1 :=\n  card_le_of_interleaved fun x hx y hy hxy hs =>\n    let \u27e8z, hzt, hxz, hzy\u27e9 := h x hx y hy hxy hs\n    \u27e8z, mem_sdiff.2 \u27e8hzt, fun hzs => hs z hzs \u27e8hxz, hzy\u27e9\u27e9, hxz, hzy\u27e9\n#align finset.card_le_diff_of_interleaved Finset.card_le_diff_of_interleaved\n\n/-- Induction principle for `Finset`s in a linearly ordered type: a predicate is true on all\n`s : Finset \u03b1` provided that:\n\n* it is true on the empty `Finset`,\n* for every `s : Finset \u03b1` and an element `a` strictly greater than all elements of `s`, `p s`\n  implies `p (insert a s)`. -/\n@[elab_as_elim]\ntheorem induction_on_max [DecidableEq \u03b1] {p : Finset \u03b1 \u2192 Prop} (s : Finset \u03b1) (h0 : p \u2205)\n    (step : \u2200 a s, (\u2200 x \u2208 s, x < a) \u2192 p s \u2192 p (insert a s)) : p s := by\n  induction' s using Finset.strongInductionOn with s ihs\n  rcases s.eq_empty_or_nonempty with (rfl | hne)\n  \u00b7 exact h0\n  \u00b7 have H : s.max' hne \u2208 s := max'_mem s hne\n    rw [\u2190 insert_erase H]\n    exact step _ _ (fun x => s.lt_max'_of_mem_erase_max' hne) (ihs _ <| erase_ssubset H)\n#align finset.induction_on_max Finset.induction_on_max\n\n/-- Induction principle for `Finset`s in a linearly ordered type: a predicate is true on all\n`s : Finset \u03b1` provided that:\n\n* it is true on the empty `Finset`,\n* for every `s : Finset \u03b1` and an element `a` strictly less than all elements of `s`, `p s`\n  implies `p (insert a s)`. -/\n@[elab_as_elim]\ntheorem induction_on_min [DecidableEq \u03b1] {p : Finset \u03b1 \u2192 Prop} (s : Finset \u03b1) (h0 : p \u2205)\n    (step : \u2200 a s, (\u2200 x \u2208 s, a < x) \u2192 p s \u2192 p (insert a s)) : p s :=\n  @induction_on_max \u03b1\u1d52\u1d48 _ _ _ s h0 step\n#align finset.induction_on_min Finset.induction_on_min\n\nend MaxMin\n\nsection MaxMinInductionValue\n\nvariable [LinearOrder \u03b1] [LinearOrder \u03b2]\n\n/-- Induction principle for `Finset`s in any type from which a given function `f` maps to a linearly\nordered type : a predicate is true on all `s : Finset \u03b1` provided that:\n\n* it is true on the empty `Finset`,\n* for every `s : Finset \u03b1` and an element `a` such that for elements of `s` denoted by `x` we have\n  `f x \u2264 f a`, `p s` implies `p (insert a s)`. -/\n@[elab_as_elim]\ntheorem induction_on_max_value [DecidableEq \u03b9] (f : \u03b9 \u2192 \u03b1) {p : Finset \u03b9 \u2192 Prop} (s : Finset \u03b9)\n    (h0 : p \u2205) (step : \u2200 a s, a \u2209 s \u2192 (\u2200 x \u2208 s, f x \u2264 f a) \u2192 p s \u2192 p (insert a s)) : p s :=\n  by\n  induction' s using Finset.strongInductionOn with s ihs\n  rcases(s.image f).eq_empty_or_nonempty with (hne | hne)\n  \u00b7 simp only [image_eq_empty] at hne\n    simp only [hne, h0]\n  \u00b7 have H : (s.image f).max' hne \u2208 s.image f := max'_mem (s.image f) hne\n    simp only [mem_image, exists_prop] at H\n    rcases H with \u27e8a, has, hfa\u27e9\n    rw [\u2190 insert_erase has]\n    refine' step _ _ (not_mem_erase a s) (fun x hx => _) (ihs _ <| erase_ssubset has)\n    rw [hfa]\n    exact le_max' _ _ (mem_image_of_mem _ <| mem_of_mem_erase hx)\n#align finset.induction_on_max_value Finset.induction_on_max_value\n\n/-- Induction principle for `Finset`s in any type from which a given function `f` maps to a linearly\nordered type : a predicate is true on all `s : Finset \u03b1` provided that:\n\n* it is true on the empty `Finset`,\n* for every `s : Finset \u03b1` and an element `a` such that for elements of `s` denoted by `x` we have\n  `f a \u2264 f x`, `p s` implies `p (insert a s)`. -/\n@[elab_as_elim]\ntheorem induction_on_min_value [DecidableEq \u03b9] (f : \u03b9 \u2192 \u03b1) {p : Finset \u03b9 \u2192 Prop} (s : Finset \u03b9)\n    (h0 : p \u2205) (step : \u2200 a s, a \u2209 s \u2192 (\u2200 x \u2208 s, f a \u2264 f x) \u2192 p s \u2192 p (insert a s)) : p s :=\n  @induction_on_max_value \u03b1\u1d52\u1d48 \u03b9 _ _ _ _ s h0 step\n#align finset.induction_on_min_value Finset.induction_on_min_value\n\nend MaxMinInductionValue\n\nsection ExistsMaxMin\n\nvariable [LinearOrder \u03b1]\n\ntheorem exists_max_image (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) (h : s.Nonempty) :\n    \u2203 x \u2208 s, \u2200 x' \u2208 s, f x' \u2264 f x := by\n  cases' max_of_nonempty (h.image f) with y hy\n  rcases mem_image.mp (mem_of_max hy) with \u27e8x, hx, rfl\u27e9\n  exact \u27e8x, hx, fun x' hx' => le_max_of_eq (mem_image_of_mem f hx') hy\u27e9\n#align finset.exists_max_image Finset.exists_max_image\n\ntheorem exists_min_image (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) (h : s.Nonempty) :\n    \u2203 x \u2208 s, \u2200 x' \u2208 s, f x \u2264 f x' :=\n  @exists_max_image \u03b1\u1d52\u1d48 \u03b2 _ s f h\n#align finset.exists_min_image Finset.exists_min_image\n\nend ExistsMaxMin\n\n-- TODO names\n\ntheorem is_glb_iff_is_least [LinearOrder \u03b1] (i : \u03b1) (s : Finset \u03b1) (hs : s.Nonempty) :\n    IsGLB (s : Set \u03b1) i \u2194 IsLeast (\u2191s) i := by\n  refine' \u27e8fun his => _, IsLeast.isGLB\u27e9\n  suffices i = min' s hs by\n    rw [this]\n    exact isLeast_min' s hs\n  rw [IsGLB, IsGreatest, mem_lowerBounds, mem_upperBounds] at his\n  exact le_antisymm (his.1 (Finset.min' s hs) (Finset.min'_mem s hs)) (his.2 _ (Finset.min'_le s))\n#align finset.is_glb_iff_is_least Finset.is_glb_iff_is_least\n\ntheorem is_lub_iff_is_greatest [LinearOrder \u03b1] (i : \u03b1) (s : Finset \u03b1) (hs : s.Nonempty) :\n    IsLUB (s : Set \u03b1) i \u2194 IsGreatest (\u2191s) i :=\n  @is_glb_iff_is_least \u03b1\u1d52\u1d48 _ i s hs\n#align finset.is_lub_iff_is_greatest Finset.is_lub_iff_is_greatest\n\ntheorem is_glb_mem [LinearOrder \u03b1] {i : \u03b1} (s : Finset \u03b1) (his : IsGLB (s : Set \u03b1) i)\n    (hs : s.Nonempty) : i \u2208 s := by\n  rw [\u2190 mem_coe]\n  exact ((is_glb_iff_is_least i s hs).mp his).1\n#align finset.is_glb_mem Finset.is_glb_mem\n\ntheorem is_lub_mem [LinearOrder \u03b1] {i : \u03b1} (s : Finset \u03b1) (his : IsLUB (s : Set \u03b1) i)\n    (hs : s.Nonempty) : i \u2208 s :=\n  @is_glb_mem \u03b1\u1d52\u1d48 _ i s his hs\n#align finset.is_lub_mem Finset.is_lub_mem\n\nend Finset\n\nnamespace Multiset\n\ntheorem map_finset_sup [DecidableEq \u03b1] [DecidableEq \u03b2] (s : Finset \u03b3) (f : \u03b3 \u2192 Multiset \u03b2)\n    (g : \u03b2 \u2192 \u03b1) (hg : Function.Injective g) : map g (s.sup f) = s.sup (map g \u2218 f) :=\n  Finset.comp_sup_eq_sup_comp _ (fun _ _ => map_union hg) (map_zero _)\n#align multiset.map_finset_sup Multiset.map_finset_sup\n\ntheorem count_finset_sup [DecidableEq \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 Multiset \u03b2) (b : \u03b2) :\n    count b (s.sup f) = s.sup fun a => count b (f a) := by\n  letI := Classical.decEq \u03b1\n  refine' s.induction _ _\n  \u00b7 exact count_zero _\n  \u00b7 intro i s _ ih\n    rw [Finset.sup_insert, sup_eq_union, count_union, Finset.sup_insert, ih]\n    rfl\n#align multiset.count_finset_sup Multiset.count_finset_sup\n\ntheorem mem_sup {\u03b1 \u03b2} [DecidableEq \u03b2] {s : Finset \u03b1} {f : \u03b1 \u2192 Multiset \u03b2} {x : \u03b2} :\n    x \u2208 s.sup f \u2194 \u2203 v \u2208 s, x \u2208 f v := by\n  classical\n    induction' s using Finset.induction_on with a s has hxs\n    \u00b7 simp\n    \u00b7 rw [Finset.sup_insert, Multiset.sup_eq_union, Multiset.mem_union]\n      constructor\n      \u00b7 intro hxi\n        cases' hxi with hf hf\n        \u00b7 refine' \u27e8a, _, hf\u27e9\n          simp only [true_or_iff, eq_self_iff_true, Finset.mem_insert]\n        \u00b7 rcases hxs.mp hf with \u27e8v, hv, hfv\u27e9\n          refine' \u27e8v, _, hfv\u27e9\n          simp only [hv, or_true_iff, Finset.mem_insert]\n      \u00b7 rintro \u27e8v, hv, hfv\u27e9\n        rw [Finset.mem_insert] at hv\n        rcases hv with (rfl | hv)\n        \u00b7 exact Or.inl hfv\n        \u00b7 refine' Or.inr (hxs.mpr \u27e8v, hv, hfv\u27e9)\n#align multiset.mem_sup Multiset.mem_sup\n\nend Multiset\n\nnamespace Finset\n\ntheorem mem_sup {\u03b1 \u03b2} [DecidableEq \u03b2] {s : Finset \u03b1} {f : \u03b1 \u2192 Finset \u03b2} {x : \u03b2} :\n    x \u2208 s.sup f \u2194 \u2203 v \u2208 s, x \u2208 f v :=\n  by\n  change _ \u2194 \u2203 v \u2208 s, x \u2208 (f v).val\n  rw [\u2190 Multiset.mem_sup, \u2190 Multiset.mem_toFinset, sup_toFinset]\n  simp_rw [val_toFinset]\n#align finset.mem_sup Finset.mem_sup\n\ntheorem sup_eq_bunion\u1d62 {\u03b1 \u03b2} [DecidableEq \u03b2] (s : Finset \u03b1) (t : \u03b1 \u2192 Finset \u03b2) :\n    s.sup t = s.bunion\u1d62 t := by\n  ext\n  rw [mem_sup, mem_bunion\u1d62]\n#align finset.sup_eq_bUnion Finset.sup_eq_bunion\u1d62\n\n@[simp]\ntheorem sup_singleton'' [DecidableEq \u03b1] (s : Finset \u03b2) (f : \u03b2 \u2192 \u03b1) :\n    (s.sup fun b => {f b}) = s.image f := by\n  ext a\n  rw [mem_sup, mem_image]\n  simp only [mem_singleton, eq_comm]\n#align finset.sup_singleton'' Finset.sup_singleton''\n\n@[simp]\ntheorem sup_singleton' [DecidableEq \u03b1] (s : Finset \u03b1) : s.sup singleton = s :=\n  (s.sup_singleton'' _).trans image_id\n#align finset.sup_singleton' Finset.sup_singleton'\n\nend Finset\n\nsection Lattice\n\nvariable {\u03b9' : Sort _} [CompleteLattice \u03b1]\n\n/-- Supremum of `s i`, `i : \u03b9`, is equal to the supremum over `t : Finset \u03b9` of suprema\n`\u2a06 i \u2208 t, s i`. This version assumes `\u03b9` is a `Type _`. See `sup\u1d62_eq_sup\u1d62_finset'` for a version\nthat works for `\u03b9 : Sort*`. -/\ntheorem sup\u1d62_eq_sup\u1d62_finset (s : \u03b9 \u2192 \u03b1) : (\u2a06 i, s i) = \u2a06 t : Finset \u03b9, \u2a06 i \u2208 t, s i := by\n  classical\n    refine le_antisymm ?_ ?_\n    exact sup\u1d62_le fun b => le_sup\u1d62_of_le {b} <| le_sup\u1d62_of_le b <| le_sup\u1d62_of_le (by simp) <| le_rfl\n    exact sup\u1d62_le fun t => sup\u1d62_le fun b => sup\u1d62_le fun _ => le_sup\u1d62 _ _\n#align supr_eq_supr_finset sup\u1d62_eq_sup\u1d62_finset\n\n/-- Supremum of `s i`, `i : \u03b9`, is equal to the supremum over `t : Finset \u03b9` of suprema\n`\u2a06 i \u2208 t, s i`. This version works for `\u03b9 : Sort*`. See `sup\u1d62_eq_sup\u1d62_finset` for a version\nthat assumes `\u03b9 : Type _` but has no `plift`s. -/\ntheorem sup\u1d62_eq_sup\u1d62_finset' (s : \u03b9' \u2192 \u03b1) :\n    (\u2a06 i, s i) = \u2a06 t : Finset (PLift \u03b9'), \u2a06 i \u2208 t, s (PLift.down i) := by\n  rw [\u2190 sup\u1d62_eq_sup\u1d62_finset, \u2190 Equiv.plift.surjective.sup\u1d62_comp]; rfl\n#align supr_eq_supr_finset' sup\u1d62_eq_sup\u1d62_finset'\n\n/-- Infimum of `s i`, `i : \u03b9`, is equal to the infimum over `t : Finset \u03b9` of infima\n`\u2a05 i \u2208 t, s i`. This version assumes `\u03b9` is a `Type _`. See `inf\u1d62_eq_inf\u1d62_finset'` for a version\nthat works for `\u03b9 : Sort*`. -/\ntheorem inf\u1d62_eq_inf\u1d62_finset (s : \u03b9 \u2192 \u03b1) : (\u2a05 i, s i) = \u2a05 (t : Finset \u03b9) (i \u2208 t), s i :=\n  @sup\u1d62_eq_sup\u1d62_finset \u03b1\u1d52\u1d48 _ _ _\n#align infi_eq_infi_finset inf\u1d62_eq_inf\u1d62_finset\n\n/-- Infimum of `s i`, `i : \u03b9`, is equal to the infimum over `t : Finset \u03b9` of infima\n`\u2a05 i \u2208 t, s i`. This version works for `\u03b9 : Sort*`. See `inf\u1d62_eq_inf\u1d62_finset` for a version\nthat assumes `\u03b9 : Type _` but has no `plift`s. -/\ntheorem inf\u1d62_eq_inf\u1d62_finset' (s : \u03b9' \u2192 \u03b1) :\n    (\u2a05 i, s i) = \u2a05 t : Finset (PLift \u03b9'), \u2a05 i \u2208 t, s (PLift.down i) :=\n  @sup\u1d62_eq_sup\u1d62_finset' \u03b1\u1d52\u1d48 _ _ _\n#align infi_eq_infi_finset' inf\u1d62_eq_inf\u1d62_finset'\n\nend Lattice\n\nnamespace Set\n\nvariable {\u03b9' : Sort _}\n\n/-- Union of an indexed family of sets `s : \u03b9 \u2192 Set \u03b1` is equal to the union of the unions\nof finite subfamilies. This version assumes `\u03b9 : Type _`. See also `union\u1d62_eq_union\u1d62_finset'` for\na version that works for `\u03b9 : Sort*`. -/\ntheorem union\u1d62_eq_union\u1d62_finset (s : \u03b9 \u2192 Set \u03b1) : (\u22c3 i, s i) = \u22c3 t : Finset \u03b9, \u22c3 i \u2208 t, s i :=\n  sup\u1d62_eq_sup\u1d62_finset s\n#align set.Union_eq_Union_finset Set.union\u1d62_eq_union\u1d62_finset\n\n/-- Union of an indexed family of sets `s : \u03b9 \u2192 Set \u03b1` is equal to the union of the unions\nof finite subfamilies. This version works for `\u03b9 : Sort*`. See also `union\u1d62_eq_union\u1d62_finset` for\na version that assumes `\u03b9 : Type _` but avoids `plift`s in the right hand side. -/\ntheorem union\u1d62_eq_union\u1d62_finset' (s : \u03b9' \u2192 Set \u03b1) :\n    (\u22c3 i, s i) = \u22c3 t : Finset (PLift \u03b9'), \u22c3 i \u2208 t, s (PLift.down i) :=\n  sup\u1d62_eq_sup\u1d62_finset' s\n#align set.Union_eq_Union_finset' Set.union\u1d62_eq_union\u1d62_finset'\n\n/-- Intersection of an indexed family of sets `s : \u03b9 \u2192 Set \u03b1` is equal to the intersection of the\nintersections of finite subfamilies. This version assumes `\u03b9 : Type _`. See also\n`inter\u1d62_eq_inter\u1d62_finset'` for a version that works for `\u03b9 : Sort*`. -/\ntheorem inter\u1d62_eq_inter\u1d62_finset (s : \u03b9 \u2192 Set \u03b1) : (\u22c2 i, s i) = \u22c2 t : Finset \u03b9, \u22c2 i \u2208 t, s i :=\n  inf\u1d62_eq_inf\u1d62_finset s\n#align set.Inter_eq_Inter_finset Set.inter\u1d62_eq_inter\u1d62_finset\n\n/-- Intersection of an indexed family of sets `s : \u03b9 \u2192 Set \u03b1` is equal to the intersection of the\nintersections of finite subfamilies. This version works for `\u03b9 : Sort*`. See also\n`inter\u1d62_eq_inter\u1d62_finset` for a version that assumes `\u03b9 : Type _` but avoids `plift`s in the right\nhand side. -/\ntheorem inter\u1d62_eq_inter\u1d62_finset' (s : \u03b9' \u2192 Set \u03b1) :\n    (\u22c2 i, s i) = \u22c2 t : Finset (PLift \u03b9'), \u22c2 i \u2208 t, s (PLift.down i) :=\n  inf\u1d62_eq_inf\u1d62_finset' s\n#align set.Inter_eq_Inter_finset' Set.inter\u1d62_eq_inter\u1d62_finset'\n\nend Set\n\nnamespace Finset\n\n/-! ### Interaction with ordered algebra structures -/\n\n\ntheorem sup_mul_le_mul_sup_of_nonneg [LinearOrderedSemiring \u03b1] [OrderBot \u03b1] {a b : \u03b9 \u2192 \u03b1}\n    (s : Finset \u03b9) (ha : \u2200 i \u2208 s, 0 \u2264 a i) (hb : \u2200 i \u2208 s, 0 \u2264 b i) :\n    s.sup (a * b) \u2264 s.sup a * s.sup b :=\n  Finset.sup_le fun _i hi =>\n    mul_le_mul (le_sup hi) (le_sup hi) (hb _ hi) ((ha _ hi).trans <| le_sup hi)\n#align finset.sup_mul_le_mul_sup_of_nonneg Finset.sup_mul_le_mul_sup_of_nonneg\n\ntheorem mul_inf_le_inf_mul_of_nonneg [LinearOrderedSemiring \u03b1] [OrderTop \u03b1] {a b : \u03b9 \u2192 \u03b1}\n    (s : Finset \u03b9) (ha : \u2200 i \u2208 s, 0 \u2264 a i) (hb : \u2200 i \u2208 s, 0 \u2264 b i) :\n    s.inf a * s.inf b \u2264 s.inf (a * b) :=\n  Finset.le_inf fun i hi => mul_le_mul (inf_le hi) (inf_le hi) (Finset.le_inf hb) (ha i hi)\n#align finset.mul_inf_le_inf_mul_of_nonneg Finset.mul_inf_le_inf_mul_of_nonneg\n\ntheorem sup'_mul_le_mul_sup'_of_nonneg [LinearOrderedSemiring \u03b1] {a b : \u03b9 \u2192 \u03b1} (s : Finset \u03b9)\n    (H : s.Nonempty) (ha : \u2200 i \u2208 s, 0 \u2264 a i) (hb : \u2200 i \u2208 s, 0 \u2264 b i) :\n    s.sup' H (a * b) \u2264 s.sup' H a * s.sup' H b :=\n  (sup'_le _ _) fun _i hi =>\n    mul_le_mul (le_sup' _ hi) (le_sup' _ hi) (hb _ hi) ((ha _ hi).trans <| le_sup' _ hi)\n#align finset.sup'_mul_le_mul_sup'_of_nonneg Finset.sup'_mul_le_mul_sup'_of_nonneg\n\ntheorem inf'_mul_le_mul_inf'_of_nonneg [LinearOrderedSemiring \u03b1] {a b : \u03b9 \u2192 \u03b1} (s : Finset \u03b9)\n    (H : s.Nonempty) (ha : \u2200 i \u2208 s, 0 \u2264 a i) (hb : \u2200 i \u2208 s, 0 \u2264 b i) :\n    s.inf' H a * s.inf' H b \u2264 s.inf' H (a * b) :=\n  (le_inf' _ _) fun _i hi => mul_le_mul (inf'_le _ hi) (inf'_le _ hi) (le_inf' _ _ hb) (ha _ hi)\n#align finset.inf'_mul_le_mul_inf'_of_nonneg Finset.inf'_mul_le_mul_inf'_of_nonneg\n\nopen Function\n\n/-! ### Interaction with big lattice/set operations -/\n\n\nsection Lattice\n\ntheorem sup\u1d62_coe [SupSet \u03b2] (f : \u03b1 \u2192 \u03b2) (s : Finset \u03b1) : (\u2a06 x \u2208 (\u2191s : Set \u03b1), f x) = \u2a06 x \u2208 s, f x :=\n  rfl\n#align finset.supr_coe Finset.sup\u1d62_coe\n\ntheorem inf\u1d62_coe [InfSet \u03b2] (f : \u03b1 \u2192 \u03b2) (s : Finset \u03b1) : (\u2a05 x \u2208 (\u2191s : Set \u03b1), f x) = \u2a05 x \u2208 s, f x :=\n  rfl\n#align finset.infi_coe Finset.inf\u1d62_coe\n\nvariable [CompleteLattice \u03b2]\n\ntheorem sup\u1d62_singleton (a : \u03b1) (s : \u03b1 \u2192 \u03b2) : (\u2a06 x \u2208 ({a} : Finset \u03b1), s x) = s a := by simp\n#align finset.supr_singleton Finset.sup\u1d62_singleton\n\ntheorem inf\u1d62_singleton (a : \u03b1) (s : \u03b1 \u2192 \u03b2) : (\u2a05 x \u2208 ({a} : Finset \u03b1), s x) = s a := by simp\n#align finset.infi_singleton Finset.inf\u1d62_singleton\n\ntheorem sup\u1d62_option_toFinset (o : Option \u03b1) (f : \u03b1 \u2192 \u03b2) : (\u2a06 x \u2208 o.toFinset, f x) = \u2a06 x \u2208 o, f x :=\n  by simp\n#align finset.supr_option_to_finset Finset.sup\u1d62_option_toFinset\n\ntheorem inf\u1d62_option_toFinset (o : Option \u03b1) (f : \u03b1 \u2192 \u03b2) : (\u2a05 x \u2208 o.toFinset, f x) = \u2a05 x \u2208 o, f x :=\n  @sup\u1d62_option_toFinset _ \u03b2\u1d52\u1d48 _ _ _\n#align finset.infi_option_to_finset Finset.inf\u1d62_option_toFinset\n\nvariable [DecidableEq \u03b1]\n\ntheorem sup\u1d62_union {f : \u03b1 \u2192 \u03b2} {s t : Finset \u03b1} :\n    (\u2a06 x \u2208 s \u222a t, f x) = (\u2a06 x \u2208 s, f x) \u2294 \u2a06 x \u2208 t, f x := by simp [sup\u1d62_or, sup\u1d62_sup_eq]\n#align finset.supr_union Finset.sup\u1d62_union\n\ntheorem inf\u1d62_union {f : \u03b1 \u2192 \u03b2} {s t : Finset \u03b1} :\n    (\u2a05 x \u2208 s \u222a t, f x) = (\u2a05 x \u2208 s, f x) \u2293 \u2a05 x \u2208 t, f x :=\n  @sup\u1d62_union \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ _\n#align finset.infi_union Finset.inf\u1d62_union\n\ntheorem sup\u1d62_insert (a : \u03b1) (s : Finset \u03b1) (t : \u03b1 \u2192 \u03b2) :\n    (\u2a06 x \u2208 insert a s, t x) = t a \u2294 \u2a06 x \u2208 s, t x := by\n  rw [insert_eq]\n  simp only [sup\u1d62_union, Finset.sup\u1d62_singleton]\n#align finset.supr_insert Finset.sup\u1d62_insert\n\ntheorem inf\u1d62_insert (a : \u03b1) (s : Finset \u03b1) (t : \u03b1 \u2192 \u03b2) :\n    (\u2a05 x \u2208 insert a s, t x) = t a \u2293 \u2a05 x \u2208 s, t x :=\n  @sup\u1d62_insert \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ _\n#align finset.infi_insert Finset.inf\u1d62_insert\n\ntheorem sup\u1d62_finset_image {f : \u03b3 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b2} {s : Finset \u03b3} :\n    (\u2a06 x \u2208 s.image f, g x) = \u2a06 y \u2208 s, g (f y) := by rw [\u2190 sup\u1d62_coe, coe_image, sup\u1d62_image, sup\u1d62_coe]\n#align finset.supr_finset_image Finset.sup\u1d62_finset_image\n\ntheorem sup_finset_image {\u03b2 \u03b3 : Type _} [SemilatticeSup \u03b2] [OrderBot \u03b2] (f : \u03b3 \u2192 \u03b1) (g : \u03b1 \u2192 \u03b2)\n    (s : Finset \u03b3) : (s.image f).sup g = s.sup (g \u2218 f) := by\n  classical induction' s using Finset.induction_on with a s' _ ih <;> simp [*]\n#align finset.sup_finset_image Finset.sup_finset_image\n\ntheorem inf\u1d62_finset_image {f : \u03b3 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b2} {s : Finset \u03b3} :\n    (\u2a05 x \u2208 s.image f, g x) = \u2a05 y \u2208 s, g (f y) := by rw [\u2190 inf\u1d62_coe, coe_image, inf\u1d62_image, inf\u1d62_coe]\n#align finset.infi_finset_image Finset.inf\u1d62_finset_image\n\ntheorem sup\u1d62_insert_update {x : \u03b1} {t : Finset \u03b1} (f : \u03b1 \u2192 \u03b2) {s : \u03b2} (hx : x \u2209 t) :\n    (\u2a06 i \u2208 insert x t, Function.update f x s i) = s \u2294 \u2a06 i \u2208 t, f i :=\n  by\n  simp only [Finset.sup\u1d62_insert, update_same]\n  rcongr (i hi); apply update_noteq; rintro rfl; exact hx hi\n#align finset.supr_insert_update Finset.sup\u1d62_insert_update\n\ntheorem inf\u1d62_insert_update {x : \u03b1} {t : Finset \u03b1} (f : \u03b1 \u2192 \u03b2) {s : \u03b2} (hx : x \u2209 t) :\n    (\u2a05 i \u2208 insert x t, update f x s i) = s \u2293 \u2a05 i \u2208 t, f i :=\n  @sup\u1d62_insert_update \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ f _ hx\n#align finset.infi_insert_update Finset.inf\u1d62_insert_update\n\ntheorem sup\u1d62_bunion\u1d62 (s : Finset \u03b3) (t : \u03b3 \u2192 Finset \u03b1) (f : \u03b1 \u2192 \u03b2) :\n    (\u2a06 y \u2208 s.bunion\u1d62 t, f y) = \u2a06 (x \u2208 s) (y \u2208 t x), f y := by simp [@sup\u1d62_comm _ \u03b1, sup\u1d62_and]\n#align finset.supr_bUnion Finset.sup\u1d62_bunion\u1d62\n\ntheorem inf\u1d62_bunion\u1d62 (s : Finset \u03b3) (t : \u03b3 \u2192 Finset \u03b1) (f : \u03b1 \u2192 \u03b2) :\n    (\u2a05 y \u2208 s.bunion\u1d62 t, f y) = \u2a05 (x \u2208 s) (y \u2208 t x), f y :=\n  @sup\u1d62_bunion\u1d62 _ \u03b2\u1d52\u1d48 _ _ _ _ _ _\n#align finset.infi_bUnion Finset.inf\u1d62_bunion\u1d62\n\nend Lattice\n\ntheorem set_bunion\u1d62_coe (s : Finset \u03b1) (t : \u03b1 \u2192 Set \u03b2) : (\u22c3 x \u2208 (\u2191s : Set \u03b1), t x) = \u22c3 x \u2208 s, t x :=\n  rfl\n#align finset.set_bUnion_coe Finset.set_bunion\u1d62_coe\n\ntheorem set_binter\u1d62_coe (s : Finset \u03b1) (t : \u03b1 \u2192 Set \u03b2) : (\u22c2 x \u2208 (\u2191s : Set \u03b1), t x) = \u22c2 x \u2208 s, t x :=\n  rfl\n#align finset.set_bInter_coe Finset.set_binter\u1d62_coe\n\ntheorem set_bunion\u1d62_singleton (a : \u03b1) (s : \u03b1 \u2192 Set \u03b2) : (\u22c3 x \u2208 ({a} : Finset \u03b1), s x) = s a :=\n  sup\u1d62_singleton a s\n#align finset.set_bUnion_singleton Finset.set_bunion\u1d62_singleton\n\ntheorem set_binter\u1d62_singleton (a : \u03b1) (s : \u03b1 \u2192 Set \u03b2) : (\u22c2 x \u2208 ({a} : Finset \u03b1), s x) = s a :=\n  inf\u1d62_singleton a s\n#align finset.set_bInter_singleton Finset.set_binter\u1d62_singleton\n\n@[simp]\ntheorem set_bunion\u1d62_preimage_singleton (f : \u03b1 \u2192 \u03b2) (s : Finset \u03b2) :\n    (\u22c3 y \u2208 s, f \u207b\u00b9' {y}) = f \u207b\u00b9' s :=\n  Set.bunion\u1d62_preimage_singleton f s\n#align finset.set_bUnion_preimage_singleton Finset.set_bunion\u1d62_preimage_singleton\n\ntheorem set_bunion\u1d62_option_toFinset (o : Option \u03b1) (f : \u03b1 \u2192 Set \u03b2) :\n    (\u22c3 x \u2208 o.toFinset, f x) = \u22c3 x \u2208 o, f x :=\n  sup\u1d62_option_toFinset o f\n#align finset.set_bUnion_option_to_finset Finset.set_bunion\u1d62_option_toFinset\n\ntheorem set_binter\u1d62_option_toFinset (o : Option \u03b1) (f : \u03b1 \u2192 Set \u03b2) :\n    (\u22c2 x \u2208 o.toFinset, f x) = \u22c2 x \u2208 o, f x :=\n  inf\u1d62_option_toFinset o f\n#align finset.set_bInter_option_to_finset Finset.set_binter\u1d62_option_toFinset\n\ntheorem subset_set_bunion\u1d62_of_mem {s : Finset \u03b1} {f : \u03b1 \u2192 Set \u03b2} {x : \u03b1} (h : x \u2208 s) :\n    f x \u2286 \u22c3 y \u2208 s, f y :=\n  show f x \u2264 \u2a06 y \u2208 s, f y from le_sup\u1d62_of_le x <| by simp only [h, sup\u1d62_pos, le_refl]\n#align finset.subset_set_bUnion_of_mem Finset.subset_set_bunion\u1d62_of_mem\n\nvariable [DecidableEq \u03b1]\n\ntheorem set_bunion\u1d62_union (s t : Finset \u03b1) (u : \u03b1 \u2192 Set \u03b2) :\n    (\u22c3 x \u2208 s \u222a t, u x) = (\u22c3 x \u2208 s, u x) \u222a \u22c3 x \u2208 t, u x :=\n  sup\u1d62_union\n#align finset.set_bUnion_union Finset.set_bunion\u1d62_union\n\ntheorem set_binter\u1d62_inter (s t : Finset \u03b1) (u : \u03b1 \u2192 Set \u03b2) :\n    (\u22c2 x \u2208 s \u222a t, u x) = (\u22c2 x \u2208 s, u x) \u2229 \u22c2 x \u2208 t, u x :=\n  inf\u1d62_union\n#align finset.set_bInter_inter Finset.set_binter\u1d62_inter\n\ntheorem set_bunion\u1d62_insert (a : \u03b1) (s : Finset \u03b1) (t : \u03b1 \u2192 Set \u03b2) :\n    (\u22c3 x \u2208 insert a s, t x) = t a \u222a \u22c3 x \u2208 s, t x :=\n  sup\u1d62_insert a s t\n#align finset.set_bUnion_insert Finset.set_bunion\u1d62_insert\n\ntheorem set_binter\u1d62_insert (a : \u03b1) (s : Finset \u03b1) (t : \u03b1 \u2192 Set \u03b2) :\n    (\u22c2 x \u2208 insert a s, t x) = t a \u2229 \u22c2 x \u2208 s, t x :=\n  inf\u1d62_insert a s t\n#align finset.set_bInter_insert Finset.set_binter\u1d62_insert\n\ntheorem set_bunion\u1d62_finset_image {f : \u03b3 \u2192 \u03b1} {g : \u03b1 \u2192 Set \u03b2} {s : Finset \u03b3} :\n    (\u22c3 x \u2208 s.image f, g x) = \u22c3 y \u2208 s, g (f y) :=\n  sup\u1d62_finset_image\n#align finset.set_bUnion_finset_image Finset.set_bunion\u1d62_finset_image\n\ntheorem set_binter\u1d62_finset_image {f : \u03b3 \u2192 \u03b1} {g : \u03b1 \u2192 Set \u03b2} {s : Finset \u03b3} :\n    (\u22c2 x \u2208 s.image f, g x) = \u22c2 y \u2208 s, g (f y) :=\n  inf\u1d62_finset_image\n#align finset.set_bInter_finset_image Finset.set_binter\u1d62_finset_image\n\ntheorem set_bunion\u1d62_insert_update {x : \u03b1} {t : Finset \u03b1} (f : \u03b1 \u2192 Set \u03b2) {s : Set \u03b2} (hx : x \u2209 t) :\n    (\u22c3 i \u2208 insert x t, @update _ _ _ f x s i) = s \u222a \u22c3 i \u2208 t, f i :=\n  sup\u1d62_insert_update f hx\n#align finset.set_bUnion_insert_update Finset.set_bunion\u1d62_insert_update\n\ntheorem set_binter\u1d62_insert_update {x : \u03b1} {t : Finset \u03b1} (f : \u03b1 \u2192 Set \u03b2) {s : Set \u03b2} (hx : x \u2209 t) :\n    (\u22c2 i \u2208 insert x t, @update _ _ _ f x s i) = s \u2229 \u22c2 i \u2208 t, f i :=\n  inf\u1d62_insert_update f hx\n#align finset.set_bInter_insert_update Finset.set_binter\u1d62_insert_update\n\ntheorem set_bunion\u1d62_bunion\u1d62 (s : Finset \u03b3) (t : \u03b3 \u2192 Finset \u03b1) (f : \u03b1 \u2192 Set \u03b2) :\n    (\u22c3 y \u2208 s.bunion\u1d62 t, f y) = \u22c3 (x \u2208 s) (y \u2208 t x), f y :=\n  sup\u1d62_bunion\u1d62 s t f\n#align finset.set_bUnion_bUnion Finset.set_bunion\u1d62_bunion\u1d62\n\ntheorem set_binter\u1d62_bunion\u1d62 (s : Finset \u03b3) (t : \u03b3 \u2192 Finset \u03b1) (f : \u03b1 \u2192 Set \u03b2) :\n    (\u22c2 y \u2208 s.bunion\u1d62 t, f y) = \u22c2 (x \u2208 s) (y \u2208 t x), f y :=\n  inf\u1d62_bunion\u1d62 s t f\n#align finset.set_bInter_bUnion Finset.set_binter\u1d62_bunion\u1d62\n\nend Finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Finset/Lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7163146032459167}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\nimport combinatorics.simple_graph.basic\nimport algebra.big_operators.basic\nimport data.nat.parity\nimport data.zmod.parity\n\n/-!\n# Degree-sum formula and handshaking lemma\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe degree-sum formula is that the sum of the degrees of the vertices in\na finite graph is equal to twice the number of edges.  The handshaking lemma,\na corollary, is that the number of odd-degree vertices is even.\n\n## Main definitions\n\n- `simple_graph.sum_degrees_eq_twice_card_edges` is the degree-sum formula.\n- `simple_graph.even_card_odd_degree_vertices` is the handshaking lemma.\n- `simple_graph.odd_card_odd_degree_vertices_ne` is that the number of odd-degree\n  vertices different from a given odd-degree vertex is odd.\n- `simple_graph.exists_ne_odd_degree_of_exists_odd_degree` is that the existence of an\n  odd-degree vertex implies the existence of another one.\n\n## Implementation notes\n\nWe give a combinatorial proof by using the facts that (1) the map from\ndarts to vertices is such that each fiber has cardinality the degree\nof the corresponding vertex and that (2) the map from darts to edges is 2-to-1.\n\n## Tags\n\nsimple graphs, sums, degree-sum formula, handshaking lemma\n-/\nopen finset\n\nopen_locale big_operators\n\nnamespace simple_graph\nuniverses u\nvariables {V : Type u} (G : simple_graph V)\n\nsection degree_sum\nvariables [fintype V] [decidable_rel G.adj]\n\nlemma dart_fst_fiber [decidable_eq V] (v : V) :\n  univ.filter (\u03bb d : G.dart, d.fst = v) = univ.image (G.dart_of_neighbor_set v) :=\nbegin\n  ext d,\n  simp only [mem_image, true_and, mem_filter, set_coe.exists, mem_univ, exists_prop_of_true],\n  split,\n  { rintro rfl,\n    exact \u27e8_, d.is_adj, by ext; refl\u27e9, },\n  { rintro \u27e8e, he, rfl\u27e9,\n    refl, },\nend\n\nlemma dart_fst_fiber_card_eq_degree [decidable_eq V] (v : V) :\n  (univ.filter (\u03bb d : G.dart, d.fst = v)).card = G.degree v :=\nby simpa only [dart_fst_fiber, finset.card_univ, card_neighbor_set_eq_degree]\n     using card_image_of_injective univ (G.dart_of_neighbor_set_injective v)\n\nlemma dart_card_eq_sum_degrees : fintype.card G.dart = \u2211 v, G.degree v :=\nbegin\n  haveI := classical.dec_eq V,\n  simp only [\u2190card_univ, \u2190dart_fst_fiber_card_eq_degree],\n  exact card_eq_sum_card_fiberwise (by simp),\nend\n\nvariables {G} [decidable_eq V]\n\nlemma dart.edge_fiber (d : G.dart) :\n  (univ.filter (\u03bb (d' : G.dart), d'.edge = d.edge)) = {d, d.symm} :=\nfinset.ext (\u03bb d', by simpa using dart_edge_eq_iff d' d)\n\nvariables (G)\n\nlemma dart_edge_fiber_card (e : sym2 V) (h : e \u2208 G.edge_set) :\n  (univ.filter (\u03bb (d : G.dart), d.edge = e)).card = 2 :=\nbegin\n  refine sym2.ind (\u03bb v w h, _) e h,\n  let d : G.dart := \u27e8(v, w), h\u27e9,\n  convert congr_arg card d.edge_fiber,\n  rw [card_insert_of_not_mem, card_singleton],\n  rw [mem_singleton],\n  exact d.symm_ne.symm,\nend\n\nlemma dart_card_eq_twice_card_edges : fintype.card G.dart = 2 * G.edge_finset.card :=\nbegin\n  rw \u2190card_univ,\n  rw @card_eq_sum_card_fiberwise _ _ _ dart.edge _ G.edge_finset\n    (\u03bb d h, by { rw mem_edge_finset, apply dart.edge_mem }),\n  rw [\u2190mul_comm, sum_const_nat],\n  intros e h,\n  apply G.dart_edge_fiber_card e,\n  rwa \u2190mem_edge_finset,\nend\n\n/-- The degree-sum formula.  This is also known as the handshaking lemma, which might\nmore specifically refer to `simple_graph.even_card_odd_degree_vertices`. -/\ntheorem sum_degrees_eq_twice_card_edges : \u2211 v, G.degree v = 2 * G.edge_finset.card :=\nG.dart_card_eq_sum_degrees.symm.trans G.dart_card_eq_twice_card_edges\n\nend degree_sum\n\n/-- The handshaking lemma.  See also `simple_graph.sum_degrees_eq_twice_card_edges`. -/\ntheorem even_card_odd_degree_vertices [fintype V] [decidable_rel G.adj] :\n  even (univ.filter (\u03bb v, odd (G.degree v))).card :=\nbegin\n  classical,\n  have h := congr_arg ((\u03bb n, \u2191n) : \u2115 \u2192 zmod 2) G.sum_degrees_eq_twice_card_edges,\n  simp only [zmod.nat_cast_self, zero_mul, nat.cast_mul] at h,\n  rw [nat.cast_sum, \u2190sum_filter_ne_zero] at h,\n  rw @sum_congr _ _ _ _ (\u03bb v, (G.degree v : zmod 2)) (\u03bb v, (1 : zmod 2)) _ rfl at h,\n  { simp only [filter_congr_decidable, mul_one, nsmul_eq_mul, sum_const, ne.def] at h,\n    rw \u2190zmod.eq_zero_iff_even,\n    convert h,\n    ext v,\n    rw \u2190zmod.ne_zero_iff_odd, },\n  { intros v,\n    simp only [true_and, mem_filter, mem_univ, ne.def],\n    rw [zmod.eq_zero_iff_even, zmod.eq_one_iff_odd, nat.odd_iff_not_even, imp_self],\n    trivial }\nend\n\nlemma odd_card_odd_degree_vertices_ne [fintype V] [decidable_eq V] [decidable_rel G.adj]\n  (v : V) (h : odd (G.degree v)) :\n  odd (univ.filter (\u03bb w, w \u2260 v \u2227 odd (G.degree w))).card :=\nbegin\n  rcases G.even_card_odd_degree_vertices with \u27e8k, hg\u27e9,\n  have hk : 0 < k,\n  { have hh : (filter (\u03bb (v : V), odd (G.degree v)) univ).nonempty,\n    { use v,\n      simp only [true_and, mem_filter, mem_univ],\n      use h, },\n    rwa [\u2190card_pos, hg, \u2190 two_mul, zero_lt_mul_left] at hh,\n    exact zero_lt_two, },\n  have hc : (\u03bb (w : V), w \u2260 v \u2227 odd (G.degree w)) = (\u03bb (w : V), odd (G.degree w) \u2227 w \u2260 v),\n  { ext w,\n    rw and_comm, },\n  simp only [hc, filter_congr_decidable],\n  rw [\u2190filter_filter, filter_ne', card_erase_of_mem],\n  { refine \u27e8k - 1, tsub_eq_of_eq_add $ hg.trans _\u27e9,\n    rw [add_assoc, one_add_one_eq_two, \u2190nat.mul_succ, \u2190 two_mul],\n    congr,\n    exact (tsub_add_cancel_of_le $ nat.succ_le_iff.2 hk).symm },\n  { simpa only [true_and, mem_filter, mem_univ] },\nend\n\nlemma exists_ne_odd_degree_of_exists_odd_degree [fintype V] [decidable_rel G.adj]\n  (v : V) (h : odd (G.degree v)) :\n  \u2203 (w : V), w \u2260 v \u2227 odd (G.degree w) :=\nbegin\n  haveI := classical.dec_eq V,\n  rcases G.odd_card_odd_degree_vertices_ne v h with \u27e8k, hg\u27e9,\n  have hg' : (filter (\u03bb (w : V), w \u2260 v \u2227 odd (G.degree w)) univ).card > 0,\n  { rw hg,\n    apply nat.succ_pos, },\n  rcases card_pos.mp hg' with \u27e8w, hw\u27e9,\n  simp only [true_and, mem_filter, mem_univ, ne.def] at hw,\n  exact \u27e8w, hw\u27e9,\nend\n\nend simple_graph\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/simple_graph/degree_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7163146032049}}
{"text": "-- Reflexive transitive closure\n inductive rtc {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : \u03b1 \u2192 \u03b1 \u2192 Prop\n| base : \u2200 a : \u03b1, rtc a a\n| next : \u2200 a b c : \u03b1, rtc a b \u2192 r b c \u2192 rtc a c\n\nlemma rtc_reflexive {\u03b1 : Type} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} :\n    \u2200a : \u03b1, rtc r a a := assume a, rtc.base r a\n\nlemma rtc_left_next {\u03b1 : Type} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} :\n    \u2200{a b c: \u03b1}, r a b \u2192 rtc r b c \u2192 rtc r a c := begin\n    intros a b c r_a_b rtc_r_b_c,\n    induction rtc_r_b_c,\n        case rtc.base : x {\n            apply rtc.next,\n            apply rtc.base,\n            assumption\n        },\n        case rtc.next : b x c rtc_r_b_x r_x_c {\n            apply rtc.next,\n            apply rtc_r_b_c_ih,\n            assumption,\n            assumption\n        }\nend\n\nlemma rtc_transitive {\u03b1 : Type} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} :\n    \u2200{a b c: \u03b1}, rtc r a b \u2192 rtc r b c \u2192 rtc r a c := begin\n    intros a b c rtc_r_a_b rtc_r_b_c,\n    induction rtc_r_a_b,\n        case rtc.base : x {\n            assumption\n        },\n        case rtc.next : a x b rtc_r_a_x r_x_b {\n            apply rtc_r_a_b_ih,\n            apply rtc_left_next,\n            assumption,\n            assumption\n        }\nend\n\n-- Main Lemma\ndefinition weakly_confluent {\u03b1 : Type} (lt: \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop :=\n    \u2200 {a b c : \u03b1}, lt b a \u2192 lt c a \u2192 \u2203 d : \u03b1, rtc lt d b \u2227 rtc lt d c\n\ndefinition confluent {\u03b1 : Type} (lt: \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop :=\n    \u2200 {a b c : \u03b1}, rtc lt b a \u2192 rtc lt c a \u2192 \u2203 d : \u03b1, rtc lt d b \u2227 rtc lt d c\n\nlemma newmans_lemma {\u03b1 : Type}\n    {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n    (wc : weakly_confluent r)\n    (wf : well_founded r) :\n    confluent r :=\n    well_founded.fix wf begin\n        intros a ih b c r_b_a r_c_b,\n        cases r_b_a,\n            case rtc.base {\n                existsi c,\n                constructor,\n                assumption,\n                apply rtc.base\n            },\n        -- main case\n        case rtc.next : x rtc_r_b_x r_x_a {\n            cases r_c_b,\n                case rtc.base {\n                    existsi b,\n                    constructor,\n                    apply rtc.base,\n                    apply rtc.next,\n                    assumption,\n                    assumption\n                },\n        -- main case\n        case rtc.next : y rtc_r_c_y r_y_a {\n            -- step 1: Get d1 from weak confluence\n            have d1exists : \u2203d1, rtc r d1 x \u2227 rtc r d1 y := \n                wc r_x_a r_y_a,\n            cases d1exists with d1 rtc_r_d1_xandy,\n            cases rtc_r_d1_xandy with rtc_r_d1_x rtc_r_d1_y,\n            -- step 2: Get d2 from induction hypothesis\n            have d2exists : \u2203d2, rtc r d2 b \u2227 rtc r d2 d1 :=\n                ih x r_x_a rtc_r_b_x rtc_r_d1_x,\n            cases d2exists with d2 rtc_r_d2_bandd1,\n            cases rtc_r_d2_bandd1 with rtc_r_d2_b rtc_r_d2_d1,\n            have rtc_r_d2_y : rtc r d2 y :=\n                rtc_transitive rtc_r_d2_d1 rtc_r_d1_y,\n            -- step 3: Get d3 from induction hypothesis\n            have d3exists : \u2203d3, rtc r d3 c \u2227 rtc r d3 d2 :=\n                ih y r_y_a rtc_r_c_y rtc_r_d2_y,\n            cases d3exists with d3 rtc_r_d3_candd2,\n            cases rtc_r_d3_candd2 with rtc_r_d3_c rtc_r_d3_d2,\n            -- step 4: Show d3 is the confluent point\n            existsi d3,\n            split, {\n                exact rtc_transitive rtc_r_d3_d2 rtc_r_d2_b,\n            }, {\n                assumption\n            }\n        }}\n    end\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/zeptometer/tlc/newmans_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7163146022988233}}
{"text": "/-\nCopyright (c) 2022 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n-/\nimport analysis.special_functions.log.basic\nimport analysis.special_functions.pow\nimport data.int.log\n\n/-!\n# Real logarithm base `b`\n\nIn this file we define `real.logb` to be the logarithm of a real number in a given base `b`. We\ndefine this as the division of the natural logarithms of the argument and the base, so that we have\na globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and\n`logb (-b) x = logb b x`.\n\nWe prove some basic properties of this function and its relation to `rpow`.\n\n## Tags\n\nlogarithm, continuity\n-/\n\nopen set filter function\nopen_locale topological_space\nnoncomputable theory\n\nnamespace real\n\nvariables {b x y : \u211d}\n\n/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to\nbe `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/\n@[pp_nodot] noncomputable def logb (b x : \u211d) : \u211d := log x / log b\n\nlemma log_div_log : log x / log b = logb b x := rfl\n\n@[simp] lemma logb_zero : logb b 0 = 0 := by simp [logb]\n\n@[simp] lemma logb_one : logb b 1 = 0 := by simp [logb]\n\n@[simp] lemma logb_abs (x : \u211d) : logb b (|x|) = logb b x := by rw [logb, logb, log_abs]\n\n@[simp] lemma logb_neg_eq_logb (x : \u211d) : logb b (-x) = logb b x :=\nby rw [\u2190 logb_abs x, \u2190 logb_abs (-x), abs_neg]\n\nlemma logb_mul (hx : x \u2260 0) (hy : y \u2260 0) : logb b (x * y) = logb b x + logb b y :=\nby simp_rw [logb, log_mul hx hy, add_div]\n\nlemma logb_div (hx : x \u2260 0) (hy : y \u2260 0) : logb b (x / y) = logb b x - logb b y :=\nby simp_rw [logb, log_div hx hy, sub_div]\n\n@[simp] lemma logb_inv (x : \u211d) : logb b (x\u207b\u00b9) = -logb b x := by simp [logb, neg_div]\n\nsection b_pos_and_ne_one\n\nvariable (b_pos : 0 < b)\nvariable (b_ne_one : b \u2260 1)\ninclude b_pos b_ne_one\n\nprivate lemma log_b_ne_zero : log b \u2260 0 :=\nbegin\n  have b_ne_zero : b \u2260 0, linarith,\n  have b_ne_minus_one : b \u2260 -1, linarith,\n  simp [b_ne_one, b_ne_zero, b_ne_minus_one],\nend\n\n@[simp] lemma logb_rpow :\n  logb b (b ^ x) = x :=\nbegin\n  rw [logb, div_eq_iff, log_rpow b_pos],\n  exact log_b_ne_zero b_pos b_ne_one,\nend\n\nlemma rpow_logb_eq_abs (hx : x \u2260 0) : b ^ (logb b x) = |x| :=\nbegin\n  apply log_inj_on_pos,\n  simp only [set.mem_Ioi],\n  apply rpow_pos_of_pos b_pos,\n  simp only [abs_pos, mem_Ioi, ne.def, hx, not_false_iff],\n  rw [log_rpow b_pos, logb, log_abs],\n  field_simp [log_b_ne_zero b_pos b_ne_one],\nend\n\n@[simp] lemma rpow_logb (hx : 0 < x) : b ^ (logb b x) = x :=\nby { rw rpow_logb_eq_abs b_pos b_ne_one (hx.ne'), exact abs_of_pos hx, }\n\nlemma rpow_logb_of_neg (hx : x < 0) : b ^ (logb b x) = -x :=\nby { rw rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx), exact abs_of_neg hx }\n\nlemma surj_on_logb : surj_on (logb b) (Ioi 0) univ :=\n\u03bb x _, \u27e8rpow b x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one\u27e9\n\nlemma logb_surjective : surjective (logb b) :=\n\u03bb x, \u27e8b ^ x, logb_rpow b_pos b_ne_one\u27e9\n\n@[simp] lemma range_logb : range (logb b) = univ :=\n(logb_surjective b_pos b_ne_one).range_eq\n\nlemma surj_on_logb' : surj_on (logb b) (Iio 0) univ :=\nbegin\n  intros x x_in_univ,\n  use -b ^ x,\n  split,\n  { simp only [right.neg_neg_iff, set.mem_Iio], apply rpow_pos_of_pos b_pos, },\n  { rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one], },\nend\n\nend b_pos_and_ne_one\n\nsection one_lt_b\n\nvariable (hb : 1 < b)\ninclude hb\n\nprivate lemma b_pos : 0 < b := by linarith\n\nprivate \n\n@[simp] lemma logb_le_logb (h : 0 < x) (h\u2081 : 0 < y) :\n  logb b x \u2264 logb b y \u2194 x \u2264 y :=\nby { rw [logb, logb, div_le_div_right (log_pos hb), log_le_log h h\u2081], }\n\nlemma logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y :=\nby { rw [logb, logb, div_lt_div_right (log_pos hb)], exact log_lt_log hx hxy, }\n\n@[simp] lemma logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) :\n  logb b x < logb b y \u2194 x < y :=\nby { rw [logb, logb, div_lt_div_right (log_pos hb)], exact log_lt_log_iff hx hy, }\n\nlemma logb_le_iff_le_rpow (hx : 0 < x) : logb b x \u2264 y \u2194 x \u2264 b ^ y :=\nby rw [\u2190rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hx]\n\nlemma logb_lt_iff_lt_rpow (hx : 0 < x) : logb b x < y \u2194 x < b ^ y :=\nby rw [\u2190rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hx]\n\nlemma le_logb_iff_rpow_le (hy : 0 < y) : x \u2264 logb b y \u2194 b ^ x \u2264 y :=\nby rw [\u2190rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hy]\n\nlemma lt_logb_iff_rpow_lt (hy : 0 < y) : x < logb b y \u2194 b ^ x < y :=\nby rw [\u2190rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hy]\n\nlemma logb_pos_iff (hx : 0 < x) : 0 < logb b x \u2194 1 < x :=\nby { rw \u2190 @logb_one b, rw logb_lt_logb_iff hb zero_lt_one hx, }\n\nlemma logb_pos (hx : 1 < x) : 0 < logb b x :=\nby { rw logb_pos_iff hb (lt_trans zero_lt_one hx), exact hx, }\n\nlemma logb_neg_iff (h : 0 < x) : logb b x < 0 \u2194 x < 1 :=\nby { rw \u2190 logb_one, exact logb_lt_logb_iff hb h zero_lt_one, }\n\nlemma logb_neg (h0 : 0 < x) (h1 : x < 1) : logb b x < 0 :=\n(logb_neg_iff hb h0).2 h1\n\nlemma logb_nonneg_iff (hx : 0 < x) : 0 \u2264 logb b x \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, logb_neg_iff hb hx, not_lt]\n\nlemma logb_nonneg (hx : 1 \u2264 x) : 0 \u2264 logb b x :=\n(logb_nonneg_iff hb (zero_lt_one.trans_le hx)).2 hx\n\nlemma logb_nonpos_iff (hx : 0 < x) : logb b x \u2264 0 \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, logb_pos_iff hb hx, not_lt]\n\nlemma logb_nonpos_iff' (hx : 0 \u2264 x) : logb b x \u2264 0 \u2194 x \u2264 1 :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { simp [le_refl, zero_le_one] },\n  exact logb_nonpos_iff hb hx,\nend\n\nlemma logb_nonpos (hx : 0 \u2264 x) (h'x : x \u2264 1) : logb b x \u2264 0 :=\n(logb_nonpos_iff' hb hx).2 h'x\n\nlemma strict_mono_on_logb : strict_mono_on (logb b) (set.Ioi 0) :=\n\u03bb x hx y hy hxy, logb_lt_logb hb hx hxy\n\nlemma strict_anti_on_logb : strict_anti_on (logb b) (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 logb_abs y, \u2190 logb_abs x],\n  refine logb_lt_logb hb (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff],\nend\n\nlemma logb_inj_on_pos : set.inj_on (logb b) (set.Ioi 0) :=\n(strict_mono_on_logb hb).inj_on\n\nlemma eq_one_of_pos_of_logb_eq_zero (h\u2081 : 0 < x) (h\u2082 : logb b x = 0) :\nx = 1 :=\nlogb_inj_on_pos hb (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one)\n  (h\u2082.trans real.logb_one.symm)\n\nlemma logb_ne_zero_of_pos_of_ne_one (hx_pos : 0 < x) (hx : x \u2260 1) :\n  logb b x \u2260 0 :=\nmt (eq_one_of_pos_of_logb_eq_zero hb hx_pos) hx\n\nlemma tendsto_logb_at_top : tendsto (logb b) at_top at_top :=\ntendsto.at_top_div_const (log_pos hb) tendsto_log_at_top\n\nend one_lt_b\n\nsection b_pos_and_b_lt_one\n\nvariable (b_pos : 0 < b)\nvariable (b_lt_one : b < 1)\ninclude b_lt_one\n\nprivate lemma b_ne_one : b \u2260 1 := by linarith\n\ninclude b_pos\n\n@[simp] lemma logb_le_logb_of_base_lt_one (h : 0 < x) (h\u2081 : 0 < y) :\n  logb b x \u2264 logb b y \u2194 y \u2264 x :=\nby { rw [logb, logb, div_le_div_right_of_neg (log_neg b_pos b_lt_one), log_le_log h\u2081 h], }\n\nlemma logb_lt_logb_of_base_lt_one (hx : 0 < x) (hxy : x < y) : logb b y < logb b x :=\nby { rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)], exact log_lt_log hx hxy, }\n\n@[simp] lemma logb_lt_logb_iff_of_base_lt_one (hx : 0 < x) (hy : 0 < y) :\n  logb b x < logb b y \u2194 y < x :=\nby { rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)], exact log_lt_log_iff hy hx }\n\nlemma logb_le_iff_le_rpow_of_base_lt_one (hx : 0 < x) : logb b x \u2264 y \u2194 b ^ y \u2264 x :=\nby rw [\u2190rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]\n\nlemma logb_lt_iff_lt_rpow_of_base_lt_one (hx : 0 < x) : logb b x < y \u2194 b ^ y < x :=\nby rw [\u2190rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]\n\nlemma le_logb_iff_rpow_le_of_base_lt_one (hy : 0 < y) : x \u2264 logb b y \u2194 y \u2264 b ^ x :=\nby rw [\u2190rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]\n\nlemma lt_logb_iff_rpow_lt_of_base_lt_one (hy : 0 < y) : x < logb b y \u2194 y < b ^ x :=\nby rw [\u2190rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]\n\nlemma logb_pos_iff_of_base_lt_one (hx : 0 < x) : 0 < logb b x \u2194 x < 1 :=\nby rw [\u2190 @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one zero_lt_one hx]\n\nlemma logb_pos_of_base_lt_one (hx : 0 < x) (hx' : x < 1) : 0 < logb b x :=\nby { rw logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, exact hx', }\n\nlemma logb_neg_iff_of_base_lt_one (h : 0 < x) : logb b x < 0 \u2194 1 < x :=\nby rw [\u2190 @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one h zero_lt_one]\n\nlemma logb_neg_of_base_lt_one (h1 : 1 < x) : logb b x < 0 :=\n(logb_neg_iff_of_base_lt_one b_pos b_lt_one (lt_trans zero_lt_one h1)).2 h1\n\nlemma logb_nonneg_iff_of_base_lt_one (hx : 0 < x) : 0 \u2264 logb b x \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, logb_neg_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]\n\nlemma logb_nonneg_of_base_lt_one (hx : 0 < x) (hx' : x \u2264 1) : 0 \u2264 logb b x :=\nby {rw [logb_nonneg_iff_of_base_lt_one b_pos b_lt_one hx], exact hx' }\n\nlemma logb_nonpos_iff_of_base_lt_one (hx : 0 < x) : logb b x \u2264 0 \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]\n\nlemma strict_anti_on_logb_of_base_lt_one : strict_anti_on (logb b) (set.Ioi 0) :=\n\u03bb x hx y hy hxy, logb_lt_logb_of_base_lt_one b_pos b_lt_one hx hxy\n\nlemma strict_mono_on_logb_of_base_lt_one : strict_mono_on (logb b) (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 logb_abs y, \u2190 logb_abs x],\n  refine logb_lt_logb_of_base_lt_one b_pos b_lt_one (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff],\nend\n\nlemma logb_inj_on_pos_of_base_lt_one : set.inj_on (logb b) (set.Ioi 0) :=\n(strict_anti_on_logb_of_base_lt_one b_pos b_lt_one).inj_on\n\nlemma eq_one_of_pos_of_logb_eq_zero_of_base_lt_one (h\u2081 : 0 < x) (h\u2082 : logb b x = 0) :\nx = 1 :=\nlogb_inj_on_pos_of_base_lt_one b_pos b_lt_one (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one)\n  (h\u2082.trans real.logb_one.symm)\n\nlemma logb_ne_zero_of_pos_of_ne_one_of_base_lt_one (hx_pos : 0 < x) (hx : x \u2260 1) :\n  logb b x \u2260 0 :=\nmt (eq_one_of_pos_of_logb_eq_zero_of_base_lt_one b_pos b_lt_one hx_pos) hx\n\nlemma tendsto_logb_at_top_of_base_lt_one : tendsto (logb b) at_top at_bot :=\nbegin\n  rw tendsto_at_top_at_bot,\n  intro e,\n  use 1 \u2294 b ^ e,\n  intro a,\n  simp only [and_imp, sup_le_iff],\n  intro ha,\n  rw logb_le_iff_le_rpow_of_base_lt_one b_pos b_lt_one,\n  tauto,\n  exact lt_of_lt_of_le zero_lt_one ha,\nend\n\nend b_pos_and_b_lt_one\n\nlemma floor_logb_nat_cast {b : \u2115} {r : \u211d} (hb : 1 < b) (hr : 0 \u2264 r) : \u230alogb b r\u230b = int.log b r :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [logb_zero, int.log_zero_right, int.floor_zero] },\n  have hb1' : 1 < (b : \u211d) := nat.one_lt_cast.mpr hb,\n  apply le_antisymm,\n  { rw [\u2190int.zpow_le_iff_le_log hb hr, \u2190rpow_int_cast b],\n    refine le_of_le_of_eq _ (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr),\n    exact rpow_le_rpow_of_exponent_le hb1'.le (int.floor_le _) },\n  { rw [int.le_floor, le_logb_iff_rpow_le hb1' hr, rpow_int_cast],\n    exact int.zpow_log_le_self hb hr }\nend\n\nlemma ceil_logb_nat_cast {b : \u2115} {r : \u211d} (hb : 1 < b) (hr : 0 \u2264 r) : \u2308logb b r\u2309 = int.clog b r :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [logb_zero, int.clog_zero_right, int.ceil_zero] },\n  have hb1' : 1 < (b : \u211d) := nat.one_lt_cast.mpr hb,\n  apply le_antisymm,\n  { rw [int.ceil_le, logb_le_iff_le_rpow hb1' hr, rpow_int_cast],\n    refine int.self_le_zpow_clog hb r },\n  { rw [\u2190int.le_zpow_iff_clog_le hb hr, \u2190rpow_int_cast b],\n    refine (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr).symm.trans_le _,\n    exact rpow_le_rpow_of_exponent_le hb1'.le (int.le_ceil _) },\nend\n\n@[simp] lemma logb_eq_zero :\n  logb b x = 0 \u2194 b = 0 \u2228 b = 1 \u2228 b = -1 \u2228 x = 0 \u2228 x = 1 \u2228 x = -1 :=\nbegin\n  simp_rw [logb, div_eq_zero_iff, log_eq_zero],\n  tauto,\nend\n\n/- TODO add other limits and continuous API lemmas analogous to those in log.lean -/\n\nopen_locale big_operators\n\nlemma logb_prod {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) (hf : \u2200 x \u2208 s, f x \u2260 0):\n  logb b (\u220f i in s, f i) = \u2211 i in s, logb b (f i) :=\nbegin\n  classical,\n  induction s using finset.induction_on with a s ha ih,\n  { simp },\n  simp only [finset.mem_insert, forall_eq_or_imp] at hf,\n  simp [ha, ih hf.2, logb_mul hf.1 (finset.prod_ne_zero_iff.2 hf.2)],\nend\n\nend real\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/special_functions/log/base.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7163145976248791}}
{"text": "-- Groups, a fundemental structure of algebra.\n--\n-- Lean has them built in of course, but I'm going to redefine them\n-- myself for the hell of it in keeping with my \"from first principles\"\n-- approach\n\n-- These will be useful within this file\nprivate variable {\u03b1 : Type}\nprivate variable {op : \u03b1 \u2192 \u03b1 \u2192 \u03b1}\nprivate variable {id: \u03b1}\nprivate variable {inv: \u03b1 \u2192 \u03b1}\nlocal infix `\u2218` := op\nlocal postfix `\u207b`:1025 := inv\n\n-- The standard lean library uses lowercase names for all thse things, so to avoid confusion\n-- let's use Camelcase\n\ndef Associative {\u03b1 : Type} (f: \u03b1 \u2192 \u03b1 \u2192 \u03b1):= \u2200 a b c : \u03b1, f (f a b) c = f a (f b c)\ndef Commutative {\u03b1 : Type} (f: \u03b1 \u2192 \u03b1 \u2192 \u03b1):= \u2200 a b : \u03b1, f a b = f b a\ndef LeftIdentity {\u03b1 : Type} (f: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) := \u2200 a : \u03b1, f id a = a\ndef RightIdentity {\u03b1 : Type} (f: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) := \u2200 a : \u03b1, f a id = a\ndef LeftInverse {\u03b1: Type} (f: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) (inv: \u03b1 \u2192 \u03b1) := \u2200 a : \u03b1, f (inv a) a = id\ndef RightInverse {\u03b1: Type} (f: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) (inv: \u03b1 \u2192 \u03b1) := \u2200 a : \u03b1, f a (inv a) = id\n\n-- So we'll define our group as a class, so that it can be inferred when needed\n-- I'll also create multiplicative and additive versions of the same, for convenience\n--\n-- We begin with the most basic of group-like objects, the semi-group\nclass Semigroup {\u03b1: Type} (op: \u03b1 \u2192 \u03b1 \u2192 \u03b1) := (assoc: (Associative op))\n\nlemma Semigroup.op_assoc (s: Semigroup op) (a b c: \u03b1): (a\u2218b)\u2218c = a\u2218(b\u2218c) := Semigroup.assoc op a b c\n\n-- And then the commutative semigroup\nclass CommSemigroup {\u03b1: Type} (op: \u03b1 \u2192 \u03b1 \u2192 \u03b1) extends Semigroup op := (comm: Commutative op)\n\ndef CommSemigroup.op_assoc (csg: CommSemigroup op) [s: Semigroup op] := s.op_assoc\nlemma CommSemigroup.op_comm (csg: CommSemigroup op) (a b : \u03b1): a \u2218 b = b \u2218 a := CommSemigroup.comm op a b\n\n-- Right so from a Semigroup we can form a Monoid\nclass Monoid {\u03b1: Type} (op: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) extends Semigroup op := (left_id: LeftIdentity op id) (right_id: RightIdentity op id)\n\nnamespace Monoid\ndef op_assoc (m: Monoid op id) [s: Semigroup op] := s.op_assoc\nlemma op_id (m:Monoid op id) (a: \u03b1): a\u2218id = a := Monoid.right_id op id a\nlemma id_op (m: Monoid op id) (a: \u03b1): id\u2218a = a := Monoid.left_id op id a\n\nlemma id_unique (m: Monoid op id) {e: \u03b1}: (\u2200 a:\u03b1, e\u2218a = a) \u2192 e = id :=\nassume hl,\ncalc\n    e   = e\u2218id  : by rw op_id m e\n    ... = id    : by rw hl id\n\n\nend Monoid\n\n-- And a Commutative Monoid\nclass CommMonoid {\u03b1: Type} (op: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) extends CommSemigroup op := (left_id: LeftIdentity op id)\ninstance CommMonoidIsMonoid {\u03b1: Type} (op: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) [cm: CommMonoid op id]: Monoid op id := {assoc:=cm.assoc, left_id:=cm.left_id, right_id:=assume a, by rw [cm.comm, cm.left_id]}\n\ndef CommMonoid.op_assoc (m: CommMonoid op id) [m: Monoid op id] := m.op_assoc\ndef CommMonoid.op_comm (ag: CommMonoid op id) [csg: CommSemigroup op] := csg.op_comm\ndef CommMonoid.op_id (m: CommMonoid op id) [m: Monoid op id] := m.op_id\ndef CommMonoid.id_op (m: CommMonoid op id) [m: Monoid op id] := m.id_op\n\n-- And from a monoid we can go to a full Group!\nclass Group {\u03b1: Type} (op: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) (inv: \u03b1 \u2192 \u03b1) extends Monoid op id := (left_inv: LeftInverse op id inv) (right_inv: RightInverse op id inv)\n\nnamespace Group\ndef op_assoc (g: Group op id inv) [s: Semigroup op] := s.op_assoc\ndef op_id (g: Group op id inv) [m: Monoid op id] := m.op_id\ndef id_op (g: Group op id inv) [m: Monoid op id] := m.id_op\n\nlemma op_inv (g: Group op id inv) (a : \u03b1): a\u2218a\u207b = id := Group.right_inv op id inv a\n\nlemma inv_op (g: Group op id inv) (a : \u03b1): a\u207b\u2218a = id := Group.left_inv op id inv a\n\nprivate lemma inv_op_elm_op (g: Group op id inv) (a b: \u03b1): a = b\u207b \u2218 (b \u2218 a) :=\ncalc\n    a   = op id a       : by rw g.id_op\n    ... = (b\u207b\u2218b) \u2218 a    : by rw g.inv_op\n    ... = b\u207b \u2218 (b \u2218 a)  : by rw g.op_assoc\nlemma cancel_left (g: Group op id inv) {a b c: \u03b1}: a\u2218b = a\u2218c \u2194 b = c :=\niff.intro (\n    assume h: a\u2218b = a\u2218c,\n    by rw [inv_op_elm_op g b, h, \u2190inv_op_elm_op g c]\n) (\n    assume h: b = c,\n    by rw h\n)\n\nprivate lemma op_elm_op_inv (g: Group op id inv) (a b: \u03b1): a = (a \u2218 b) \u2218 b\u207b :=\ncalc\n    a   = a \u2218 id        : by rw g.op_id\n    ... = a \u2218 (b \u2218 b\u207b)  : by rw g.op_inv\n    ... = (a \u2218 b) \u2218 b\u207b  : by rw g.op_assoc\nlemma cancel_right (g: Group op id inv) {a b c: \u03b1}: b\u2218a = c\u2218a \u2194 b = c :=\niff.intro (\n    assume h: b\u2218a = c\u2218a,\n    by rw [op_elm_op_inv g b, h, \u2190op_elm_op_inv g c]\n) (\n    assume h: b = c,\n    by rw h\n)\n\nlemma id_unique (g: Group op id inv) [m: Monoid op id] {e: \u03b1}: (\u2200 a:\u03b1, e\u2218a = a) \u2192 e = id := m.id_unique\n\nlemma inv_unique (g: Group op id inv) {a b: \u03b1}: b \u2218 a = id \u2192 b = a\u207b :=\nassume h: b \u2218 a = id,\nsuffices b \u2218 a = a\u207b \u2218 a, from iff.elim_left (cancel_right g) this,\nby rw [h, inv_op g]\n\nlemma inv_inv (g: Group op id inv) (a : \u03b1): (a\u207b)\u207b = a :=\ncalc\n    (a\u207b)\u207b = id \u2218 (a\u207b)\u207b        : by rw g.id_op\n    ...   = (a \u2218 a\u207b) \u2218 (a\u207b)\u207b  : by rw g.op_inv\n    ...   = a \u2218 (a\u207b \u2218 (a\u207b)\u207b)  : by rw g.op_assoc\n    ...   = a \u2218 id            : by rw g.op_inv\n    ...   = a                 : by rw g.op_id\n\nend Group\n\n-- And now an abelian group\nclass AbelianGroup {\u03b1: Type} (op: \u03b1 \u2192 \u03b1 \u2192 \u03b1) (id: \u03b1) (inv: \u03b1 \u2192 \u03b1) extends CommMonoid op id := (left_inv: LeftInverse op id inv)\ndef AbelianGroup.to_Group {\u03b1: Type} {op: \u03b1 \u2192 \u03b1 \u2192 \u03b1} {id: \u03b1} {inv: \u03b1 \u2192 \u03b1} (ag: AbelianGroup op id inv): Group op id inv := {assoc:=ag.assoc, left_id:=ag.left_id, right_id:=assume a, by rw [ag.comm, ag.left_id], left_inv:=ag.left_inv, right_inv:=assume a, by rw [ag.comm, ag.left_inv]}\ninstance AbelianGroupIsGroup {\u03b1: Type} {op: \u03b1 \u2192 \u03b1 \u2192 \u03b1} {id: \u03b1} {inv: \u03b1 \u2192 \u03b1} [ag: AbelianGroup op id inv]: Group op id inv := ag.to_Group\n\ndef AbelianGroup.op_assoc (ag: AbelianGroup op id inv) [s: Semigroup op] := s.op_assoc\ndef AbelianGroup.op_comm (ag: AbelianGroup op id inv) [cm: CommMonoid op id] := cm.op_comm\ndef AbelianGroup.op_id (ag: AbelianGroup op id inv) [m: Monoid op id] := m.op_id\ndef AbelianGroup.id_op (ag: AbelianGroup op id inv) [m: Monoid op id] := m.id_op\ndef AbelianGroup.op_inv (ag: AbelianGroup op id inv) [g: Group op id inv] := g.op_inv\ndef AbelianGroup.inv_op (ag: AbelianGroup op id inv) [g: Group op id inv] := g.inv_op\nlemma AbelianGroup.cancel_left (ag: AbelianGroup op id inv) [g: Group op id inv] {a b c: \u03b1}: a\u2218b = a\u2218c \u2194 b = c := g.cancel_left\nlemma AbelianGroup.cancel_right (ag: AbelianGroup op id inv) [g: Group op id inv] {a b c: \u03b1}: b\u2218a = c\u2218a \u2194 b = c := g.cancel_right\n\n-- Some special versions for additive work\nclass AdditiveSemigroup (\u03b1: Type) extends has_add \u03b1 := (add_assoc_: (Associative add))\ninstance AdditiveSemigroupIsSemigroup (\u03b1: Type) [asg: AdditiveSemigroup \u03b1]: Semigroup asg.add := {assoc := asg.add_assoc_}\nlemma AdditiveSemigroup.add_assoc {\u03b1 : Type} (asg: AdditiveSemigroup \u03b1) [sg: Semigroup asg.add] (a b c: \u03b1): (a+b)+c = a+(b+c) := sg.op_assoc a b c\nclass AdditiveMonoid (\u03b1: Type) extends has_zero \u03b1, has_add \u03b1 := (assoc: Associative add) (left_id: LeftIdentity add 0) (right_id: RightIdentity add 0)\ninstance AdditiveMonoidIsMonoid (\u03b1: Type) [am: AdditiveMonoid \u03b1]: Monoid am.add am.zero := {assoc := am.assoc, left_id := am.left_id , right_id := am.right_id}\nlemma AdditiveMonoid.add_zero {\u03b1: Type} (am: AdditiveMonoid \u03b1) [m: Monoid am.add am.zero] (a: \u03b1): a + 0 = a := m.op_id a\nlemma AdditiveMonoid.zero_add {\u03b1: Type} (am: AdditiveMonoid \u03b1) [m: Monoid am.add am.zero] (a: \u03b1): 0 + a = a := m.id_op a\nclass AdditiveGroup (\u03b1: Type) extends AdditiveMonoid \u03b1, has_neg \u03b1 := (left_inv: \u2200 a : \u03b1, (-a) + a = 0) (right_inv: \u2200 a : \u03b1, a  + (-a) = 0)\ninstance AdditiveGroupIsGroup (\u03b1: Type) [ag: AdditiveGroup \u03b1]: Group ag.add ag.zero ag.neg := {assoc:=ag.assoc, left_id:=ag.left_id, right_id:=ag.right_id, left_inv:=ag.left_inv, right_inv:=ag.right_inv}\nlemma AdditiveGroup.add_neg {\u03b1: Type} (ag: AdditiveGroup \u03b1) [g: Group ag.add ag.zero ag.neg] (a: \u03b1): a + -a = 0 := g.op_inv a\nlemma AdditiveGroup.neg_add {\u03b1: Type} (ag: AdditiveGroup \u03b1) [g: Group ag.add ag.zero ag.neg] (a: \u03b1): -a + a = 0 := g.inv_op a\nlemma AdditiveGroup.cancel_left {\u03b1: Type} (ag: AdditiveGroup \u03b1) [g: Group ag.add ag.zero ag.neg] {a b c: \u03b1}: a + b = a + c \u2194 b = c := g.cancel_left\nlemma AdditiveGroup.cancel_right {\u03b1: Type} (ag: AdditiveGroup \u03b1) [g: Group ag.add ag.zero ag.neg] {a b c: \u03b1}: b + a = c + a \u2194 b = c := g.cancel_right\nclass AdditiveAbelianGroup (\u03b1: Type) extends AdditiveGroup \u03b1 := (comm: Commutative add)\ndef AdditiveAbelianGroup.to_AbelianGroup {\u03b1: Type} (aag: AdditiveAbelianGroup \u03b1): AbelianGroup aag.add aag.zero aag.neg := {assoc:=aag.assoc, left_id:=aag.left_id, left_inv:=aag.left_inv, comm:=aag.comm}\ninstance AdditiveAbelianGroupIsAbelianGroup {\u03b1: Type} [aag: AdditiveAbelianGroup \u03b1]: AbelianGroup aag.add aag.zero aag.neg := aag.to_AbelianGroup\ndef AdditiveAbelianGroup.to_Group {\u03b1: Type} (aag: AdditiveAbelianGroup \u03b1): Group aag.add aag.zero aag.neg := aag.to_AbelianGroup.to_Group\nlemma AdditiveAbelianGroup.add_comm (aag: AdditiveAbelianGroup \u03b1) [ag: AbelianGroup aag.add aag.zero aag.neg] (a b : \u03b1): a + b = b + a := ag.op_comm a b\n\n-- Some specialised versions for multiplicative work\nclass MultiplicativeSemigroup (\u03b1: Type) extends has_mul \u03b1 := (mul_assoc_: (Associative mul))\ninstance MultiplicativeSemigroupIsSemigroup (\u03b1: Type) [msg: MultiplicativeSemigroup \u03b1]: Semigroup msg.mul := {assoc := msg.mul_assoc_}\nlemma MultiplicativeSemigroup.mul_assoc {\u03b1 : Type} (msg: MultiplicativeSemigroup \u03b1) [sg: Semigroup msg.mul] (a b c: \u03b1): (a*b)*c = a*(b*c) := sg.op_assoc a b c\nclass MultiplicativeMonoid (\u03b1: Type) extends has_one \u03b1, has_mul \u03b1 := (assoc: Associative mul) (left_id: \u2200 a : \u03b1, 1*a = a) (right_id: \u2200 a : \u03b1, a*1 = a)\ninstance MultiplicativeMonoidIsMonoid (\u03b1: Type) [mm: MultiplicativeMonoid \u03b1]: Monoid mm.mul mm.one := {assoc := mm.assoc, left_id := mm.left_id, right_id := mm.right_id}\nlemma MultiplicativeMonoid.mul_one {\u03b1: Type} (mm: MultiplicativeMonoid \u03b1) [m: Monoid mm.mul mm.one] (a: \u03b1): a*1 = a := m.op_id a\nlemma MultiplicativeMonoid.one_mul {\u03b1: Type} (mm: MultiplicativeMonoid \u03b1) [m: Monoid mm.mul mm.one] (a: \u03b1): 1*a = a := m.id_op a\nclass MultiplicativeGroup (\u03b1: Type) extends MultiplicativeMonoid \u03b1, has_inv \u03b1 := (left_inv: \u2200 a : \u03b1, a\u207b\u00b9*a = 1) (right_inv: \u2200 a : \u03b1, a*a\u207b\u00b9 = 1)\ninstance MultiplicativeGroupIsGroup (\u03b1: Type) [mg: MultiplicativeGroup \u03b1]: Group mg.mul mg.one mg.inv := {assoc:=mg.assoc, left_id:=mg.left_id, right_id:=mg.right_id, left_inv:=mg.left_inv, right_inv:=mg.right_inv}\nlemma MultiplicativeGroup.mul_inv {\u03b1: Type} (mg: MultiplicativeGroup \u03b1) [g: Group mg.mul mg.one mg.inv] (a: \u03b1): a*a\u207b\u00b9 = 1 := g.op_inv a\nlemma MultiplicativeGroup.inv_mul {\u03b1: Type} (mg: MultiplicativeGroup \u03b1) [g: Group mg.mul mg.one mg.inv] (a: \u03b1): a\u207b\u00b9*a = 1 := g.inv_op a\nlemma MultiplicativeGroup.cancel_left {\u03b1: Type} (mg: MultiplicativeGroup \u03b1) [g: Group mg.mul mg.one mg.inv] {a b c: \u03b1}: a*b = a*c \u2194 b = c := g.cancel_left\nlemma MultiplicativeGroup.cancel_right {\u03b1: Type} (mg: MultiplicativeGroup \u03b1) [g: Group mg.mul mg.one mg.inv] {a b c: \u03b1}: b*a = c*a \u2194 b = c := g.cancel_right\nclass MultiplicativeAbelianGroup (\u03b1: Type) extends MultiplicativeGroup \u03b1 := (comm: Commutative mul)\ninstance MultiplicativeAbelianGroupIsAbelianGroup (\u03b1: Type) [mag: MultiplicativeAbelianGroup \u03b1]: AbelianGroup mag.mul mag.one mag.inv := {assoc:=mag.assoc, left_id:=mag.left_id, left_inv:=mag.left_inv, comm:=mag.comm}\nlemma MultiplicativeAbelianGroup.mul_comm (mag: MultiplicativeAbelianGroup \u03b1) [ag: AbelianGroup mag.mul mag.one mag.inv] (a b : \u03b1): a * b = b * a := ag.op_comm a b\n", "meta": {"author": "jamespbarrett", "repo": "basicmaths", "sha": "4f5ac79b14d1139cb1fb31ca455a15f37f5967f2", "save_path": "github-repos/lean/jamespbarrett-basicmaths", "path": "github-repos/lean/jamespbarrett-basicmaths/basicmaths-4f5ac79b14d1139cb1fb31ca455a15f37f5967f2/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7162792669903227}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.real.basic\nimport data.real.sqrt\nimport data.nat.prime\nimport number_theory.primes_congruent_one\nimport number_theory.quadratic_reciprocity\nimport tactic.linear_combination\n\n/-!\n# IMO 2008 Q3\nProve that there exist infinitely many positive integers `n` such that `n^2 + 1` has a prime\ndivisor which is greater than `2n + \u221a(2n)`.\n\n# Solution\nWe first prove the following lemma: for every prime `p > 20`, satisfying `p \u2261 1 [MOD 4]`,\nthere exists `n \u2208 \u2115` such that `p \u2223 n^2 + 1` and `p > 2n + \u221a(2n)`. Then the statement of the\nproblem follows from the fact that there exist infinitely many primes `p \u2261 1 [MOD 4]`.\n\nTo prove the lemma, notice that `p \u2261 1 [MOD 4]` implies `\u2203 n \u2208 \u2115` such that `n^2 \u2261 -1 [MOD p]`\nand we can take this `n` such that `n \u2264 p/2`. Let `k = p - 2n \u2265 0`. Then we have:\n`k^2 + 4 = (p - 2n)^2 + 4 \u2263 4n^2 + 4 \u2261 0 [MOD p]`. Then `k^2 + 4 \u2265 p` and so `k \u2265 \u221a(p - 4) > 4`.\nThen `p = 2n + k \u2265 2n + \u221a(p - 4) = 2n + \u221a(2n + k - 4) > \u221a(2n)` and we are done.\n-/\n\nopen real\n\nlemma p_lemma (p : \u2115) (hpp : nat.prime p) (hp_mod_4_eq_1 : p \u2261 1 [MOD 4]) (hp_gt_20 : p > 20) :\n  \u2203 n : \u2115, p \u2223 n ^ 2 + 1 \u2227 (p : \u211d) > 2 * n + sqrt(2 * n) :=\nbegin\n  haveI := fact.mk hpp,\n  have hp_mod_4_ne_3 : p % 4 \u2260 3, { linarith [(show p % 4 = 1, by exact hp_mod_4_eq_1)] },\n  obtain \u27e8y, hy\u27e9 := (zmod.exists_sq_eq_neg_one_iff_mod_four_ne_three p).mpr hp_mod_4_ne_3,\n\n  let m := zmod.val_min_abs y,\n  let n := int.nat_abs m,\n\n  have hnat\u2081 : p \u2223 n ^ 2 + 1,\n  { refine int.coe_nat_dvd.mp _,\n    simp only [int.nat_abs_sq, int.coe_nat_pow, int.coe_nat_succ, int.coe_nat_dvd.mp],\n    refine (zmod.int_coe_zmod_eq_zero_iff_dvd (m ^ 2 + 1) p).mp _,\n    simp only [int.cast_pow, int.cast_add, int.cast_one, zmod.coe_val_min_abs],\n    rw hy, exact add_left_neg 1 },\n\n  have hnat\u2082 : n \u2264 p / 2 := zmod.nat_abs_val_min_abs_le y,\n  have hnat\u2083 : p \u2265 2 * n, { linarith [nat.div_mul_le_self p 2] },\n\n  set k : \u2115 := p - 2 * n with hnat\u2084,\n\n  have hnat\u2085 : p \u2223 k ^ 2 + 4,\n  { cases hnat\u2081 with x hx,\n    have : (p:\u2124) \u2223 k ^ 2 + 4,\n    { use (p:\u2124) - 4 * n + 4 * x,\n      have hcast\u2081 : (k:\u2124) = p - 2 * n, { assumption_mod_cast },\n      have hcast\u2082 : (n:\u2124) ^ 2 + 1 = p * x, { assumption_mod_cast },\n      linear_combination (hcast\u2081, (k:\u2124) + p - 2 * n) (hcast\u2082, 4) },\n    assumption_mod_cast },\n\n  have hnat\u2086 : k ^ 2 + 4 \u2265 p := nat.le_of_dvd (k ^ 2 + 3).succ_pos hnat\u2085,\n\n  have hreal\u2081 : (k:\u211d) = p - 2 * n, { assumption_mod_cast },\n  have hreal\u2082 : (p:\u211d) > 20,        { assumption_mod_cast },\n  have hreal\u2083 : (k:\u211d) ^ 2 + 4 \u2265 p, { assumption_mod_cast },\n\n  have hreal\u2085 : (k:\u211d) > 4,\n  { apply lt_of_pow_lt_pow 2 k.cast_nonneg,\n    linarith only [hreal\u2082, hreal\u2083] },\n\n  have hreal\u2086 : (k:\u211d) > sqrt (2 * n),\n  { apply lt_of_pow_lt_pow 2 k.cast_nonneg,\n    rw sq_sqrt (mul_nonneg zero_le_two n.cast_nonneg),\n    linarith only [hreal\u2081, hreal\u2083, hreal\u2085] },\n\n  exact \u27e8n, hnat\u2081, by linarith only [hreal\u2086, hreal\u2081]\u27e9,\nend\n\ntheorem imo2008_q3 : \u2200 N : \u2115, \u2203 n : \u2115, n \u2265 N \u2227\n  \u2203 p : \u2115, nat.prime p \u2227 p \u2223 n ^ 2 + 1 \u2227 (p : \u211d) > 2 * n + sqrt(2 * n) :=\nbegin\n  intro N,\n  obtain \u27e8p, hpp, hineq\u2081, hpmod4\u27e9 := nat.exists_prime_ge_modeq_one 4 (N ^ 2 + 21) zero_lt_four,\n  obtain \u27e8n, hnat, hreal\u27e9 := p_lemma p hpp hpmod4 (by linarith [hineq\u2081, nat.zero_le (N ^ 2)]),\n\n  have hineq\u2082  : n ^ 2 + 1 \u2265 p := nat.le_of_dvd (n ^ 2).succ_pos hnat,\n  have hineq\u2083  : n * n \u2265 N * N, { linarith [hineq\u2081, hineq\u2082] },\n  have hn_ge_N : n \u2265 N := nat.mul_self_le_mul_self_iff.mpr hineq\u2083,\n\n  exact \u27e8n, hn_ge_N, p, hpp, hnat, hreal\u27e9,\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/archive/imo/imo2008_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7162792583784262}}
{"text": "import data.finset algebra.big_operators tactic.ring\n\nnamespace maths_challenges\n\n-- the n'th odd number (we start counting at zero)\ndef odd (n : \u2115) := 2 * n + 1\n\n-- finset.range n is the finite set {0,1,2,...,n-1}\ntheorem challenge05 (n : \u2115) : (finset.range n).sum (odd) = n ^ 2 :=\nbegin\n  induction n with d hd,\n    refl,\n  rw finset.sum_range_succ,\n  rw hd,\n  change (2 * d + 1) + d ^ 2 = (d + 1) ^ 2,\n  ring,\nend\n\nend maths_challenges\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Maths_Challenges/src/solutions/solution05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240125464114, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7162424467309865}}
{"text": "import .group_representation\nimport .morphism\nimport .sub_module\nuniverse variables u v w w' w'' w'''\n\nvariables {G : Type u} [group G] {R : Type v}[ring R] \nvariables {M1 : Type w}  [add_comm_group M1] [module R M1]\n          {M2 : Type w'} [add_comm_group M2] [module R M2] \n          {\u03c11 : group_representation G R M1} \n          {\u03c12  : group_representation G R M2}\n          (f  : \u03c11 \u27f6  \u03c12 )\n\nopen stability morphism\nnamespace Kernel\n/--\n   The kernel of `f : \u03c11 \u27f6 \u03c12` is define to be the kernel of `\u2191f : M1 \u2192\u2097[R] M2`\n-/\ndef Ker := linear_map.ker (f.\u2113)   /-- bof -/\nlemma Ker_ext_iff(x : M1) : x \u2208 Ker f \u2194 x \u2208 linear_map.ker (f.\u2113)   := iff.rfl    --- brouh  not good !\nlemma mem_ker (x : M1) : x \u2208 Ker f \u2194 f x = 0 := linear_map.mem_ker\nlemma Ker_ext  (x : M1 )  : f  x = 0  \u2192  x \u2208  Ker f := \nbegin \n    intros, rw Ker_ext_iff,rw linear_map.mem_ker,assumption, \nend\nlemma Ker_f_mem (x : M1) : (x \u2208  Ker f) \u2192  f x  =0 := begin \n    rw \u2190 mem_ker,intros, assumption, \nend  \n/--\n   The kernel of `f : \u03c11 \u27f6 \u03c12` is an stable sub-stape of M1.\n-/\ntheorem ker_is_stable_submodule : stable_submodule \u03c11 (Ker f) := begin \n    intros g,intros x,apply Ker_ext, rw morphism.commute_apply,\n    rw Ker_f_mem,rw (\u03c12 g).map_zero,\n    rcases x,unfold Ker at \u22a2 x_property , assumption,\nend\n/--\n    The Kernel of `f : \u03c11 \u27f6 \u03c12` has representation.\n-/\ndef ker : group_representation G R (Ker f) := Res (ker_is_stable_submodule f)\n\nend Kernel\nnamespace range\nopen linear_map\n/--\n    Range is stable. Let `y \u2208 Im f`, let `g \u2208 G`, we want : `\u03c1 g y \u2208 Im f`. \n    Take `x \u2208 M1` s.t `f x = y`.  We have (from `f.commute`) :\n            `(f \u2218 \u03c11 g) x = \u03c12 g \u2218 f x`\n    i.e `\u03c12 g y = f ( \u03c11 g x)` and so  `\u03c12 g y \u2208 Im f` \n-/\n\ntheorem range_is_stable_submodule : stable_submodule \u03c12 (range (f.\u2113  : M1\u2192\u2097[R] M2)) := begin\n    intros g,intros y,rcases y with \u27e8y, \u27e8x,hyp\u27e9\u27e9,  \n    apply linear_map.mem_range.mpr,\n        use \u03c11 g x, \n    erw commute_apply,\n    exact congr_arg \u21d1(\u03c12 g) hyp.right, \nend\n/--\n  For a morphism `f : \u03c11 \u27f6 \u03c12` between `representation` we define a sub representation of `M2`\n-/\ndef Range  : group_representation G R (range (f.\u2113  : M1\u2192\u2097[R] M2)) := Res (range_is_stable_submodule f)\n\nend range ", "meta": {"author": "Or7ando", "repo": "group_representation", "sha": "9b576984f17764ebf26c8caa2a542d248f1b50d2", "save_path": "github-repos/lean/Or7ando-group_representation", "path": "github-repos/lean/Or7ando-group_representation/group_representation-9b576984f17764ebf26c8caa2a542d248f1b50d2/group_rep1/kernel.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464114, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7162424467309865}}
{"text": "/-\nCopyright (c) 2014 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthors: Floris van Doorn, Jeremy Avigad\nDistance function on the natural numbers.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.basic\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\nnamespace nat\n\n\n/- distance -/\n\n/-- Distance (absolute value of difference) between natural numbers. -/\ndef dist (n : \u2115) (m : \u2115) : \u2115 := n - m + (m - n)\n\ntheorem dist.def (n : \u2115) (m : \u2115) : dist n m = n - m + (m - n) := rfl\n\ntheorem dist_comm (n : \u2115) (m : \u2115) : dist n m = dist m n := sorry\n\n@[simp] theorem dist_self (n : \u2115) : dist n n = 0 := sorry\n\ntheorem eq_of_dist_eq_zero {n : \u2115} {m : \u2115} (h : dist n m = 0) : n = m := sorry\n\ntheorem dist_eq_zero {n : \u2115} {m : \u2115} (h : n = m) : dist n m = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (dist n m = 0)) h))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (dist m m = 0)) (dist_self m))) (Eq.refl 0))\n\ntheorem dist_eq_sub_of_le {n : \u2115} {m : \u2115} (h : n \u2264 m) : dist n m = m - n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (dist n m = m - n)) (dist.def n m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (n - m + (m - n) = m - n)) (sub_eq_zero_of_le h)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 + (m - n) = m - n)) (zero_add (m - n))))\n        (Eq.refl (m - n))))\n\ntheorem dist_eq_sub_of_le_right {n : \u2115} {m : \u2115} (h : m \u2264 n) : dist n m = n - m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (dist n m = n - m)) (dist_comm n m))) (dist_eq_sub_of_le h)\n\ntheorem dist_tri_left (n : \u2115) (m : \u2115) : m \u2264 dist n m + n :=\n  le_trans (nat.le_sub_add m n) (add_le_add_right (le_add_left (m - n) (n - m)) n)\n\ntheorem dist_tri_right (n : \u2115) (m : \u2115) : m \u2264 n + dist n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (m \u2264 n + dist n m)) (add_comm n (dist n m)))) (dist_tri_left n m)\n\ntheorem dist_tri_left' (n : \u2115) (m : \u2115) : n \u2264 dist n m + m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (n \u2264 dist n m + m)) (dist_comm n m))) (dist_tri_left m n)\n\ntheorem dist_tri_right' (n : \u2115) (m : \u2115) : n \u2264 m + dist n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (n \u2264 m + dist n m)) (dist_comm n m))) (dist_tri_right m n)\n\ntheorem dist_zero_right (n : \u2115) : dist n 0 = n :=\n  Eq.trans (dist_eq_sub_of_le_right (zero_le n)) (nat.sub_zero n)\n\ntheorem dist_zero_left (n : \u2115) : dist 0 n = n :=\n  Eq.trans (dist_eq_sub_of_le (zero_le n)) (nat.sub_zero n)\n\ntheorem dist_add_add_right (n : \u2115) (k : \u2115) (m : \u2115) : dist (n + k) (m + k) = dist n m := sorry\n\ntheorem dist_add_add_left (k : \u2115) (n : \u2115) (m : \u2115) : dist (k + n) (k + m) = dist n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (dist (k + n) (k + m) = dist n m)) (add_comm k n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (dist (n + k) (k + m) = dist n m)) (add_comm k m)))\n      (dist_add_add_right n k m))\n\ntheorem dist_eq_intro {n : \u2115} {m : \u2115} {k : \u2115} {l : \u2115} (h : n + m = k + l) : dist n k = dist l m :=\n  sorry\n\nprotected theorem sub_lt_sub_add_sub (n : \u2115) (m : \u2115) (k : \u2115) : n - k \u2264 n - m + (m - k) := sorry\n\ntheorem dist.triangle_inequality (n : \u2115) (m : \u2115) (k : \u2115) : dist n k \u2264 dist n m + dist m k := sorry\n\ntheorem dist_mul_right (n : \u2115) (k : \u2115) (m : \u2115) : dist (n * k) (m * k) = dist n m * k := sorry\n\ntheorem dist_mul_left (k : \u2115) (n : \u2115) (m : \u2115) : dist (k * n) (k * m) = k * dist n m := sorry\n\n-- TODO(Jeremy): do when we have max and minx\n\n--theorem dist_eq_max_sub_min {i j : nat} : dist i j = (max i j) - min i j :=\n\n--sorry\n\n/-\nor.elim (lt_or_ge i j)\n  (assume : i < j,\n    by rw [max_eq_right_of_lt this, min_eq_left_of_lt this, dist_eq_sub_of_lt this])\n  (assume : i \u2265 j,\n    by rw [max_eq_left this , min_eq_right this, dist_eq_sub_of_le_right this])\n-/\n\ntheorem dist_succ_succ {i : \u2115} {j : \u2115} : dist (Nat.succ i) (Nat.succ j) = dist i j := sorry\n\ntheorem dist_pos_of_ne {i : \u2115} {j : \u2115} : i \u2260 j \u2192 0 < dist i j := sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/nat/dist_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7160615104573553}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.option.basic\nimport data.nat.basic\n/-!\n# Partial predecessor and partial subtraction on the natural numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe usual definition of natural number subtraction (`nat.sub`) returns 0 as a \"garbage value\" for\n`a - b` when `a < b`. Similarly, `nat.pred 0` is defined to be `0`. The functions in this file\nwrap the result in an `option` type instead:\n\n## Main definitions\n\n- `nat.ppred`: a partial predecessor operation\n- `nat.psub`: a partial subtraction operation\n\n-/\nnamespace nat\n\n/-- Partial predecessor operation. Returns `ppred n = some m`\n  if `n = m + 1`, otherwise `none`. -/\n@[simp] def ppred : \u2115 \u2192 option \u2115\n| 0     := none\n| (n+1) := some n\n\n/-- Partial subtraction operation. Returns `psub m n = some k`\n  if `m = n + k`, otherwise `none`. -/\n@[simp] def psub (m : \u2115) : \u2115 \u2192 option \u2115\n| 0     := some m\n| (n+1) := psub n >>= ppred\n\ntheorem pred_eq_ppred (n : \u2115) : pred n = (ppred n).get_or_else 0 :=\nby cases n; refl\n\ntheorem sub_eq_psub (m : \u2115) : \u2200 n, m - n = (psub m n).get_or_else 0\n| 0     := rfl\n| (n+1) := (pred_eq_ppred (m-n)).trans $\n  by rw [sub_eq_psub, psub]; cases psub m n; refl\n\n@[simp] theorem ppred_eq_some {m : \u2115} : \u2200 {n}, ppred n = some m \u2194 succ m = n\n| 0     := by split; intro h; contradiction\n| (n+1) := by dsimp; split; intro h; injection h; subst n\n\n@[simp] theorem ppred_eq_none : \u2200 {n : \u2115}, ppred n = none \u2194 n = 0\n| 0     := by simp\n| (n+1) := by dsimp; split; contradiction\n\ntheorem psub_eq_some {m : \u2115} : \u2200 {n k}, psub m n = some k \u2194 k + n = m\n| 0     k := by simp [eq_comm]\n| (n+1) k :=\n  begin\n    dsimp,\n    apply option.bind_eq_some.trans,\n    simp [psub_eq_some, add_comm, add_left_comm, nat.succ_eq_add_one]\n  end\n\ntheorem psub_eq_none {m n : \u2115} : psub m n = none \u2194 m < n :=\nbegin\n  cases s : psub m n; simp [eq_comm],\n  { show m < n, refine lt_of_not_ge (\u03bb h, _),\n    cases le.dest h with k e,\n    injection s.symm.trans (psub_eq_some.2 $ (add_comm _ _).trans e) },\n  { show n \u2264 m, rw \u2190 psub_eq_some.1 s, apply nat.le_add_left }\nend\n\ntheorem ppred_eq_pred {n} (h : 0 < n) : ppred n = some (pred n) :=\nppred_eq_some.2 $ succ_pred_eq_of_pos h\n\ntheorem psub_eq_sub {m n} (h : n \u2264 m) : psub m n = some (m - n) :=\npsub_eq_some.2 $ nat.sub_add_cancel h\n\ntheorem psub_add (m n k) : psub m (n + k) = do x \u2190 psub m n, psub x k :=\nby induction k; simp [*, add_succ, bind_assoc]\n\n/-- Same as `psub`, but with a more efficient implementation. -/\n@[inline] def psub' (m n : \u2115) : option \u2115 := if n \u2264 m then some (m - n) else none\n\ntheorem psub'_eq_psub (m n) : psub' m n = psub m n :=\nby rw [psub']; split_ifs;\n  [exact (psub_eq_sub h).symm, exact (psub_eq_none.2 (not_le.1 h)).symm]\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/psub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7160615075025399}}
{"text": "/-\nCopyright (c) 2020 Shing Tak Lam. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam\n\n! This file was ported from Lean 3 source module group_theory.specific_groups.dihedral\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Zmod.Basic\nimport Mathbin.GroupTheory.Exponent\n\n/-!\n# Dihedral Groups\n\nWe define the dihedral groups `dihedral_group n`, with elements `r i` and `sr i` for `i : zmod n`.\n\nFor `n \u2260 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`\nrepresents the rotations of the `n`-gon by `2\u03c0i/n`, and `sr i` represents the reflections of the\n`n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.\n-/\n\n\n/-- For `n \u2260 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon.\n`r i` represents the rotations of the `n`-gon by `2\u03c0i/n`, and `sr i` represents the reflections of\nthe `n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.\n-/\ninductive DihedralGroup (n : \u2115) : Type\n  | r : ZMod n \u2192 DihedralGroup\n  | sr : ZMod n \u2192 DihedralGroup\n  deriving DecidableEq\n#align dihedral_group DihedralGroup\n\nnamespace DihedralGroup\n\nvariable {n : \u2115}\n\n/-- Multiplication of the dihedral group.\n-/\nprivate def mul : DihedralGroup n \u2192 DihedralGroup n \u2192 DihedralGroup n\n  | r i, r j => r (i + j)\n  | r i, sr j => sr (j - i)\n  | sr i, r j => sr (i + j)\n  | sr i, sr j => r (j - i)\n#align dihedral_group.mul dihedral_group.mul\n\n/-- The identity `1` is the rotation by `0`.\n-/\nprivate def one : DihedralGroup n :=\n  r 0\n#align dihedral_group.one dihedral_group.one\n\ninstance : Inhabited (DihedralGroup n) :=\n  \u27e8one\u27e9\n\n/-- The inverse of a an element of the dihedral group.\n-/\nprivate def inv : DihedralGroup n \u2192 DihedralGroup n\n  | r i => r (-i)\n  | sr i => sr i\n#align dihedral_group.inv dihedral_group.inv\n\n/-- The group structure on `dihedral_group n`.\n-/\ninstance : Group (DihedralGroup n) where\n  mul := mul\n  mul_assoc := by rintro (a | a) (b | b) (c | c) <;> simp only [mul] <;> ring\n  one := one\n  one_mul := by\n    rintro (a | a)\n    exact congr_arg r (zero_add a)\n    exact congr_arg sr (sub_zero a)\n  mul_one := by\n    rintro (a | a)\n    exact congr_arg r (add_zero a)\n    exact congr_arg sr (add_zero a)\n  inv := inv\n  mul_left_inv := by\n    rintro (a | a)\n    exact congr_arg r (neg_add_self a)\n    exact congr_arg r (sub_self a)\n\n@[simp]\ntheorem r_mul_r (i j : ZMod n) : r i * r j = r (i + j) :=\n  rfl\n#align dihedral_group.r_mul_r DihedralGroup.r_mul_r\n\n@[simp]\ntheorem r_mul_sr (i j : ZMod n) : r i * sr j = sr (j - i) :=\n  rfl\n#align dihedral_group.r_mul_sr DihedralGroup.r_mul_sr\n\n@[simp]\ntheorem sr_mul_r (i j : ZMod n) : sr i * r j = sr (i + j) :=\n  rfl\n#align dihedral_group.sr_mul_r DihedralGroup.sr_mul_r\n\n@[simp]\ntheorem sr_mul_sr (i j : ZMod n) : sr i * sr j = r (j - i) :=\n  rfl\n#align dihedral_group.sr_mul_sr DihedralGroup.sr_mul_sr\n\ntheorem one_def : (1 : DihedralGroup n) = r 0 :=\n  rfl\n#align dihedral_group.one_def DihedralGroup.one_def\n\nprivate def fintype_helper : Sum (ZMod n) (ZMod n) \u2243 DihedralGroup n\n    where\n  invFun i :=\n    match i with\n    | r j => Sum.inl j\n    | sr j => Sum.inr j\n  toFun i :=\n    match i with\n    | Sum.inl j => r j\n    | Sum.inr j => sr j\n  left_inv := by rintro (x | x) <;> rfl\n  right_inv := by rintro (x | x) <;> rfl\n#align dihedral_group.fintype_helper dihedral_group.fintype_helper\n\n/-- If `0 < n`, then `dihedral_group n` is a finite group.\n-/\ninstance [NeZero n] : Fintype (DihedralGroup n) :=\n  Fintype.ofEquiv _ fintypeHelper\n\ninstance : Nontrivial (DihedralGroup n) :=\n  \u27e8\u27e8r 0, sr 0, by decide\u27e9\u27e9\n\n/-- If `0 < n`, then `dihedral_group n` has `2n` elements.\n-/\ntheorem card [NeZero n] : Fintype.card (DihedralGroup n) = 2 * n := by\n  rw [\u2190 fintype.card_eq.mpr \u27e8fintype_helper\u27e9, Fintype.card_sum, ZMod.card, two_mul]\n#align dihedral_group.card DihedralGroup.card\n\n@[simp]\ntheorem r_one_pow (k : \u2115) : (r 1 : DihedralGroup n) ^ k = r k :=\n  by\n  induction' k with k IH\n  \u00b7 rw [Nat.cast_zero]\n    rfl\n  \u00b7 rw [pow_succ, IH, r_mul_r]\n    congr 1\n    norm_cast\n    rw [Nat.one_add]\n#align dihedral_group.r_one_pow DihedralGroup.r_one_pow\n\n@[simp]\ntheorem r_one_pow_n : r (1 : ZMod n) ^ n = 1 :=\n  by\n  rw [r_one_pow, one_def]\n  congr 1\n  exact ZMod.nat_cast_self _\n#align dihedral_group.r_one_pow_n DihedralGroup.r_one_pow_n\n\n@[simp]\ntheorem sr_mul_self (i : ZMod n) : sr i * sr i = 1 := by rw [sr_mul_sr, sub_self, one_def]\n#align dihedral_group.sr_mul_self DihedralGroup.sr_mul_self\n\n/-- If `0 < n`, then `sr i` has order 2.\n-/\n@[simp]\ntheorem orderOf_sr (i : ZMod n) : orderOf (sr i) = 2 :=\n  by\n  rw [orderOf_eq_prime _ _]\n  \u00b7 exact \u27e8Nat.prime_two\u27e9\n  rw [sq, sr_mul_self]\n  decide\n#align dihedral_group.order_of_sr DihedralGroup.orderOf_sr\n\n/-- If `0 < n`, then `r 1` has order `n`.\n-/\n@[simp]\ntheorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n :=\n  by\n  rcases eq_zero_or_neZero n with (rfl | hn)\n  \u00b7 rw [orderOf_eq_zero_iff']\n    intro n hn\n    rw [r_one_pow, one_def]\n    apply mt r.inj\n    simpa using hn.ne'\n  \u00b7 skip\n    apply\n      (Nat.le_of_dvd (NeZero.pos n) <|\n            orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left\n    intro h\n    have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _\n    rw [r_one_pow] at h1\n    injection h1 with h2\n    rw [\u2190 ZMod.val_eq_zero, ZMod.val_nat_cast, Nat.mod_eq_of_lt h] at h2\n    exact absurd h2.symm (orderOf_pos _).Ne\n#align dihedral_group.order_of_r_one DihedralGroup.orderOf_r_one\n\n/-- If `0 < n`, then `i : zmod n` has order `n / gcd n i`.\n-/\ntheorem orderOf_r [NeZero n] (i : ZMod n) : orderOf (r i) = n / Nat.gcd n i.val :=\n  by\n  conv_lhs => rw [\u2190 ZMod.nat_cast_zmod_val i]\n  rw [\u2190 r_one_pow, orderOf_pow, order_of_r_one]\n#align dihedral_group.order_of_r DihedralGroup.orderOf_r\n\ntheorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 :=\n  by\n  rcases eq_zero_or_neZero n with (rfl | hn)\n  \u00b7 exact Monoid.exponent_eq_zero_of_order_zero order_of_r_one\n  skip\n  apply Nat.dvd_antisymm\n  \u00b7 apply Monoid.exponent_dvd_of_forall_pow_eq_one\n    rintro (m | m)\n    \u00b7 rw [\u2190 orderOf_dvd_iff_pow_eq_one, order_of_r]\n      refine' Nat.dvd_trans \u27e8gcd n m.val, _\u27e9 (dvd_lcm_left n 2)\n      \u00b7 exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm\n    \u00b7 rw [\u2190 orderOf_dvd_iff_pow_eq_one, order_of_sr]\n      exact dvd_lcm_right n 2\n  \u00b7 apply lcm_dvd\n    \u00b7 convert Monoid.order_dvd_exponent (r 1)\n      exact order_of_r_one.symm\n    \u00b7 convert Monoid.order_dvd_exponent (sr 0)\n      exact (order_of_sr 0).symm\n#align dihedral_group.exponent DihedralGroup.exponent\n\nend DihedralGroup\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/GroupTheory/SpecificGroups/Dihedral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.8311430562234878, "lm_q1q2_score": 0.7160615063494532}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Floris van Doorn, S\u00e9bastien Gou\u00ebzel, Alex J. Best\n\n! This file was ported from Lean 3 source module data.list.big_operators.basic\n! leanprover-community/mathlib commit 6c5f73fd6f6cc83122788a80a27cdd54663609f4\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Int.Order.Basic\nimport Mathlib.Data.List.Forall2\n\n/-!\n# Sums and products from lists\n\nThis file provides basic results about `List.prod`, `List.sum`, which calculate the product and sum\nof elements of a list and `List.alternating_prod`, `List.alternating_sum`, their alternating\ncounterparts. These are defined in [`Data.List.Defs`](./defs).\n-/\n\n\nvariable {\u03b9 \u03b1 M N P M\u2080 G R : Type _}\n\nnamespace List\n\nsection Monoid\n\nvariable [Monoid M] [Monoid N] [Monoid P] {l l\u2081 l\u2082 : List M} {a : M}\n\n@[to_additive (attr := simp)]\ntheorem prod_nil : ([] : List M).prod = 1 :=\n  rfl\n#align list.prod_nil List.prod_nil\n#align list.sum_nil List.sum_nil\n\n@[to_additive]\ntheorem prod_singleton : [a].prod = a :=\n  one_mul a\n#align list.prod_singleton List.prod_singleton\n#align list.sum_singleton List.sum_singleton\n\n@[to_additive (attr := simp)]\ntheorem prod_cons : (a :: l).prod = a * l.prod :=\n  calc\n    (a :: l).prod = foldl (\u00b7 * \u00b7) (a * 1) l :=\n      by simp only [List.prod, foldl_cons, one_mul, mul_one]\n    _ = _ := foldl_assoc\n\n#align list.prod_cons List.prod_cons\n#align list.sum_cons List.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_append : (l\u2081 ++ l\u2082).prod = l\u2081.prod * l\u2082.prod :=\n  calc\n    (l\u2081 ++ l\u2082).prod = foldl (\u00b7 * \u00b7) (foldl (\u00b7 * \u00b7) 1 l\u2081 * 1) l\u2082 := by simp [List.prod]\n    _ = l\u2081.prod * l\u2082.prod := foldl_assoc\n\n#align list.prod_append List.prod_append\n#align list.sum_append List.sum_append\n\n@[to_additive]\ntheorem prod_concat : (l.concat a).prod = l.prod * a := by\n  rw [concat_eq_append, prod_append, prod_singleton]\n#align list.prod_concat List.prod_concat\n#align list.sum_concat List.sum_concat\n\n@[to_additive (attr := simp)]\ntheorem prod_join {l : List (List M)} : l.join.prod = (l.map List.prod).prod := by\n  induction l <;> [rfl, simp only [*, List.join, map, prod_append, prod_cons]]\n#align list.prod_join List.prod_join\n#align list.sum_join List.sum_join\n\n@[to_additive]\ntheorem prod_eq_foldr : \u2200 {l : List M}, l.prod = foldr (\u00b7 * \u00b7) 1 l\n  | [] => rfl\n  | cons a l => by rw [prod_cons, foldr_cons, prod_eq_foldr]\n#align list.prod_eq_foldr List.prod_eq_foldr\n#align list.sum_eq_foldr List.sum_eq_foldr\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : \u2115) (a : M) : (replicate n a).prod = a ^ n := by\n  induction' n with n ih\n  \u00b7 rw [pow_zero]\n    rfl\n  \u00b7 rw [replicate_succ, prod_cons, ih, pow_succ]\n#align list.prod_replicate List.prod_replicate\n#align list.sum_replicate List.sum_replicate\n\n@[to_additive sum_eq_card_nsmul]\n\n\n@[to_additive]\ntheorem prod_hom_rel (l : List \u03b9) {r : M \u2192 N \u2192 Prop} {f : \u03b9 \u2192 M} {g : \u03b9 \u2192 N} (h\u2081 : r 1 1)\n    (h\u2082 : \u2200 \u2983i a b\u2984, r a b \u2192 r (f i * a) (g i * b)) : r (l.map f).prod (l.map g).prod :=\n  List.recOn l h\u2081 fun a l hl => by simp only [map_cons, prod_cons, h\u2082 hl]\n#align list.prod_hom_rel List.prod_hom_rel\n#align list.sum_hom_rel List.sum_hom_rel\n\n@[to_additive]\ntheorem prod_hom (l : List M) {F : Type _} [MonoidHomClass F M N] (f : F) :\n    (l.map f).prod = f l.prod := by\n  simp only [prod, foldl_map, \u2190 map_one f]\n  exact l.foldl_hom f (. * .) (. * f .) 1 (fun x y => (map_mul f x y).symm)\n#align list.prod_hom List.prod_hom\n#align list.sum_hom List.sum_hom\n\n@[to_additive]\ntheorem prod_hom\u2082 (l : List \u03b9) (f : M \u2192 N \u2192 P) (hf : \u2200 a b c d, f (a * b) (c * d) = f a c * f b d)\n    (hf' : f 1 1 = 1) (f\u2081 : \u03b9 \u2192 M) (f\u2082 : \u03b9 \u2192 N) :\n    (l.map fun i => f (f\u2081 i) (f\u2082 i)).prod = f (l.map f\u2081).prod (l.map f\u2082).prod := by\n  simp only [prod, foldl_map]\n  -- Porting note: next 3 lines used to be\n  -- convert l.foldl_hom\u2082 (fun a b => f a b) _ _ _ _ _ fun a b i => _\n  -- \u00b7 exact hf'.symm\n  -- \u00b7 exact hf _ _ _ _\n  rw [\u2190 l.foldl_hom\u2082 (fun a b => f a b), hf']\n  intros\n  exact hf _ _ _ _\n#align list.prod_hom\u2082 List.prod_hom\u2082\n#align list.sum_hom\u2082 List.sum_hom\u2082\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul {\u03b1 : Type _} [CommMonoid \u03b1] {l : List \u03b9} {f g : \u03b9 \u2192 \u03b1} :\n    (l.map fun i => f i * g i).prod = (l.map f).prod * (l.map g).prod :=\n  l.prod_hom\u2082 (\u00b7 * \u00b7) mul_mul_mul_comm (mul_one _) _ _\n#align list.prod_map_mul List.prod_map_mul\n#align list.sum_map_add List.sum_map_add\n\n@[simp]\ntheorem prod_map_neg {\u03b1} [CommMonoid \u03b1] [HasDistribNeg \u03b1] (l : List \u03b1) :\n    (l.map Neg.neg).prod = (-1) ^ l.length * l.prod := by\n  simpa only [id_eq, neg_mul, one_mul, map_const', prod_replicate, map_id]\n    using @prod_map_mul \u03b1 \u03b1 _ l (fun _ => -1) id\n#align list.prod_map_neg List.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_hom (L : List \u03b9) (f : \u03b9 \u2192 M) {G : Type _} [MonoidHomClass G M N] (g : G) :\n    (L.map (g \u2218 f)).prod = g (L.map f).prod := by rw [\u2190 prod_hom, map_map]\n#align list.prod_map_hom List.prod_map_hom\n#align list.sum_map_hom List.sum_map_hom\n\n@[to_additive]\ntheorem prod_isUnit : \u2200 {L : List M} (_ : \u2200 m \u2208 L, IsUnit m), IsUnit L.prod\n  | [], _ => by simp\n  | h :: t, u => by\n    simp only [List.prod_cons]\n    exact IsUnit.mul (u h (mem_cons_self h t)) (prod_isUnit fun m mt => u m (mem_cons_of_mem h mt))\n#align list.prod_is_unit List.prod_isUnit\n#align list.sum_is_add_unit List.sum_isAddUnit\n\n@[to_additive]\ntheorem prod_isUnit_iff {\u03b1 : Type _} [CommMonoid \u03b1] {L : List \u03b1} :\n    IsUnit L.prod \u2194 \u2200 m \u2208 L, IsUnit m := by\n  refine' \u27e8fun h => _, prod_isUnit\u27e9\n  induction' L with m L ih\n  \u00b7 exact fun m' h' => False.elim (not_mem_nil m' h')\n  rw [prod_cons, IsUnit.mul_iff] at h\n  exact fun m' h' => Or.elim (eq_or_mem_of_mem_cons h') (fun H => H.substr h.1) fun H => ih h.2 _ H\n#align list.prod_is_unit_iff List.prod_isUnit_iff\n#align list.sum_is_add_unit_iff List.sum_isAddUnit_iff\n\n@[to_additive (attr := simp)]\ntheorem prod_take_mul_prod_drop : \u2200 (L : List M) (i : \u2115), (L.take i).prod * (L.drop i).prod = L.prod\n  | [], i => by simp [Nat.zero_le]\n  | L, 0 => by simp\n  | h :: t, n + 1 => by\n    dsimp\n    rw [prod_cons, prod_cons, mul_assoc, prod_take_mul_prod_drop t]\n#align list.prod_take_mul_prod_drop List.prod_take_mul_prod_drop\n#align list.sum_take_add_sum_drop List.sum_take_add_sum_drop\n\n@[to_additive (attr := simp)]\ntheorem prod_take_succ :\n    \u2200 (L : List M) (i : \u2115) (p), (L.take (i + 1)).prod = (L.take i).prod * L.nthLe i p\n  | [], i, p => by cases p\n  | h :: t, 0, _ => rfl\n  | h :: t, n + 1, p => by\n    dsimp\n    rw [prod_cons, prod_cons, prod_take_succ t n (Nat.lt_of_succ_lt_succ p), mul_assoc,\n      nthLe_cons, dif_neg (Nat.add_one_ne_zero _)]\n    simp\n\n#align list.prod_take_succ List.prod_take_succ\n#align list.sum_take_succ List.sum_take_succ\n\n/-- A list with product not one must have positive length. -/\n@[to_additive \"A list with sum not zero must have positive length.\"]\ntheorem length_pos_of_prod_ne_one (L : List M) (h : L.prod \u2260 1) : 0 < L.length := by\n  cases L\n  \u00b7 contrapose h\n    simp\n  \u00b7 simp\n#align list.length_pos_of_prod_ne_one List.length_pos_of_prod_ne_one\n#align list.length_pos_of_sum_ne_zero List.length_pos_of_sum_ne_zero\n\n/-- A list with product greater than one must have positive length. -/\n@[to_additive length_pos_of_sum_pos \"A list with positive sum must have positive length.\"]\ntheorem length_pos_of_one_lt_prod [Preorder M] (L : List M) (h : 1 < L.prod) : 0 < L.length :=\n  length_pos_of_prod_ne_one L h.ne'\n#align list.length_pos_of_one_lt_prod List.length_pos_of_one_lt_prod\n#align list.length_pos_of_sum_pos List.length_pos_of_sum_pos\n\n/-- A list with product less than one must have positive length. -/\n@[to_additive \"A list with negative sum must have positive length.\"]\ntheorem length_pos_of_prod_lt_one [Preorder M] (L : List M) (h : L.prod < 1) : 0 < L.length :=\n  length_pos_of_prod_ne_one L h.ne\n#align list.length_pos_of_prod_lt_one List.length_pos_of_prod_lt_one\n#align list.length_pos_of_sum_neg List.length_pos_of_sum_neg\n\n@[to_additive]\ntheorem prod_set :\n    \u2200 (L : List M) (n : \u2115) (a : M),\n      (L.set n a).prod =\n        ((L.take n).prod * if n < L.length then a else 1) * (L.drop (n + 1)).prod\n  | x :: xs, 0, a => by simp [set]\n  | x :: xs, i + 1, a => by simp [set, prod_set xs i a, mul_assoc, Nat.succ_eq_add_one]\n  | [], _, _ => by simp [set, (Nat.zero_le _).not_lt, Nat.zero_le]\n#align list.prod_update_nth List.prod_set\n#align list.sum_update_nth List.sum_set\n\nopen MulOpposite\n\n/-- We'd like to state this as `L.headI * L.tail.prod = L.prod`, but because `L.headI` relies on an\ninhabited instance to return a garbage value on the empty list, this is not possible.\nInstead, we write the statement in terms of `(L.get? 0).getD 1`.\n-/\n@[to_additive \"We'd like to state this as `L.headI + L.tail.sum = L.sum`, but because `L.headI`\n  relies on an inhabited instance to return a garbage value on the empty list, this is not possible.\n  Instead, we write the statement in terms of `(L.get? 0).getD 0`.\"]\ntheorem get?_zero_mul_tail_prod (l : List M) : (l.get? 0).getD 1 * l.tail.prod = l.prod := by\n  cases l <;> simp\n#align list.nth_zero_mul_tail_prod List.get?_zero_mul_tail_prod\n#align list.nth_zero_add_tail_sum List.get?_zero_add_tail_sum\n\n/-- Same as `get?_zero_mul_tail_prod`, but avoiding the `List.headI` garbage complication by\n  requiring the list to be nonempty. -/\n@[to_additive \"Same as `get?_zero_add_tail_sum`, but avoiding the `List.headI` garbage complication\n  by requiring the list to be nonempty.\"]\ntheorem headI_mul_tail_prod_of_ne_nil [Inhabited M] (l : List M) (h : l \u2260 []) :\n    l.headI * l.tail.prod = l.prod := by cases l <;> [contradiction, simp]\n#align list.head_mul_tail_prod_of_ne_nil List.headI_mul_tail_prod_of_ne_nil\n#align list.head_add_tail_sum_of_ne_nil List.headI_add_tail_sum_of_ne_nil\n\n@[to_additive]\ntheorem _root_.Commute.list_prod_right (l : List M) (y : M) (h : \u2200 x \u2208 l, Commute y x) :\n    Commute y l.prod := by\n  induction' l with z l IH\n  \u00b7 simp\n  \u00b7 rw [List.forall_mem_cons] at h\n    rw [List.prod_cons]\n    exact Commute.mul_right h.1 (IH h.2)\n#align commute.list_prod_right Commute.list_prod_right\n#align add_commute.list_sum_right AddCommute.list_sum_right\n\n@[to_additive]\ntheorem _root_.Commute.list_prod_left (l : List M) (y : M) (h : \u2200 x \u2208 l, Commute x y) :\n    Commute l.prod y :=\n  ((Commute.list_prod_right _ _) fun _ hx => (h _ hx).symm).symm\n#align commute.list_prod_left Commute.list_prod_left\n#align add_commute.list_sum_left AddCommute.list_sum_left\n\n@[to_additive sum_le_sum]\ntheorem Forall\u2082.prod_le_prod' [Preorder M] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] {l\u2081 l\u2082 : List M} (h : Forall\u2082 (\u00b7 \u2264 \u00b7) l\u2081 l\u2082) :\n    l\u2081.prod \u2264 l\u2082.prod := by\n  induction' h with a b la lb hab ih ih'\n  \u00b7 rfl\n  \u00b7 simpa only [prod_cons] using mul_le_mul' hab ih'\n#align list.forall\u2082.prod_le_prod' List.Forall\u2082.prod_le_prod'\n#align list.forall\u2082.sum_le_sum List.Forall\u2082.sum_le_sum\n\n/-- If `l\u2081` is a sublist of `l\u2082` and all elements of `l\u2082` are greater than or equal to one, then\n`l\u2081.prod \u2264 l\u2082.prod`. One can prove a stronger version assuming `\u2200 a \u2208 l\u2082.diff l\u2081, 1 \u2264 a` instead\nof `\u2200 a \u2208 l\u2082, 1 \u2264 a` but this lemma is not yet in `mathlib`. -/\n@[to_additive sum_le_sum \"If `l\u2081` is a sublist of `l\u2082` and all elements of `l\u2082` are nonnegative,\n  then `l\u2081.sum \u2264 l\u2082.sum`.\n  One can prove a stronger version assuming `\u2200 a \u2208 l\u2082.diff l\u2081, 0 \u2264 a` instead of `\u2200 a \u2208 l\u2082, 0 \u2264 a`\n  but this lemma is not yet in `mathlib`.\"]\ntheorem Sublist.prod_le_prod' [Preorder M] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] {l\u2081 l\u2082 : List M} (h : l\u2081 <+ l\u2082)\n    (h\u2081 : \u2200 a \u2208 l\u2082, (1 : M) \u2264 a) : l\u2081.prod \u2264 l\u2082.prod := by\n  induction h\n  case slnil => rfl\n  case cons l\u2081 l\u2082 a _ ih' =>\n    simp only [prod_cons, forall_mem_cons] at h\u2081\u22a2\n    exact (ih' h\u2081.2).trans (le_mul_of_one_le_left' h\u2081.1)\n  case cons\u2082 l\u2081 l\u2082 a _ ih' =>\n    simp only [prod_cons, forall_mem_cons] at h\u2081\u22a2\n    exact mul_le_mul_left' (ih' h\u2081.2) _\n#align list.sublist.prod_le_prod' List.Sublist.prod_le_prod'\n#align list.sublist.sum_le_sum List.Sublist.sum_le_sum\n\n@[to_additive sum_le_sum]\ntheorem SublistForall\u2082.prod_le_prod' [Preorder M]\n    [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)] [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)]\n    {l\u2081 l\u2082 : List M} (h : SublistForall\u2082 (\u00b7 \u2264 \u00b7) l\u2081 l\u2082) (h\u2081 : \u2200 a \u2208 l\u2082, (1 : M) \u2264 a) :\n    l\u2081.prod \u2264 l\u2082.prod :=\n  let \u27e8_, hall, hsub\u27e9 := sublistForall\u2082_iff.1 h\n  hall.prod_le_prod'.trans <| hsub.prod_le_prod' h\u2081\n#align list.sublist_forall\u2082.prod_le_prod' List.SublistForall\u2082.prod_le_prod'\n#align list.sublist_forall\u2082.sum_le_sum List.SublistForall\u2082.sum_le_sum\n\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' [Preorder M] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] {l : List \u03b9} {f g : \u03b9 \u2192 M} (h : \u2200 i \u2208 l, f i \u2264 g i) :\n    (l.map f).prod \u2264 (l.map g).prod :=\n  Forall\u2082.prod_le_prod' <| by simpa\n#align list.prod_le_prod' List.prod_le_prod'\n#align list.sum_le_sum List.sum_le_sum\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' [Preorder M] [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 < \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)]\n    [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)] {l : List \u03b9} (f g : \u03b9 \u2192 M)\n    (h\u2081 : \u2200 i \u2208 l, f i \u2264 g i) (h\u2082 : \u2203 i \u2208 l, f i < g i) : (l.map f).prod < (l.map g).prod := by\n  induction' l with i l ihl\n  \u00b7 rcases h\u2082 with \u27e8_, \u27e8\u27e9, _\u27e9\n  simp only [forall_mem_cons, exists_mem_cons, map_cons, prod_cons] at h\u2081 h\u2082\u22a2\n  cases h\u2082\n  \u00b7 exact mul_lt_mul_of_lt_of_le \u2039_\u203a (prod_le_prod' h\u2081.2)\n  \u00b7 exact mul_lt_mul_of_le_of_lt h\u2081.1 <| ihl h\u2081.2 \u2039_\u203a\n#align list.prod_lt_prod' List.prod_lt_prod'\n#align list.sum_lt_sum List.sum_lt_sum\n\n@[to_additive]\ntheorem prod_lt_prod_of_ne_nil [Preorder M] [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 < \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)]\n    [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)] {l : List \u03b9} (hl : l \u2260 []) (f g : \u03b9 \u2192 M)\n    (hlt : \u2200 i \u2208 l, f i < g i) : (l.map f).prod < (l.map g).prod :=\n  (prod_lt_prod' f g fun i hi => (hlt i hi).le) <|\n    (exists_mem_of_ne_nil l hl).imp fun i hi => \u27e8hi, hlt i hi\u27e9\n#align list.prod_lt_prod_of_ne_nil List.prod_lt_prod_of_ne_nil\n#align list.sum_lt_sum_of_ne_nil List.sum_lt_sum_of_ne_nil\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card [Preorder M] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (l : List M) (n : M) (h : \u2200 x \u2208 l, x \u2264 n) :\n    l.prod \u2264 n ^ l.length := by\n      simpa only [map_id'', map_const', prod_replicate] using prod_le_prod' h\n#align list.prod_le_pow_card List.prod_le_pow_card\n#align list.sum_le_card_nsmul List.sum_le_card_nsmul\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' [LinearOrder M] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] {l : List \u03b9} (f g : \u03b9 \u2192 M)\n    (h : (l.map f).prod < (l.map g).prod) : \u2203 i \u2208 l, f i < g i := by\n  contrapose! h\n  exact prod_le_prod' h\n#align list.exists_lt_of_prod_lt' List.exists_lt_of_prod_lt'\n#align list.exists_lt_of_sum_lt List.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' [LinearOrder M] [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 < \u00b7)]\n    [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)]\n    [CovariantClass M M (Function.swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)] {l : List \u03b9} (hl : l \u2260 []) (f g : \u03b9 \u2192 M)\n    (h : (l.map f).prod \u2264 (l.map g).prod) : \u2203 x \u2208 l, f x \u2264 g x := by\n  contrapose! h\n  exact prod_lt_prod_of_ne_nil hl _ _ h\n#align list.exists_le_of_prod_le' List.exists_le_of_prod_le'\n#align list.exists_le_of_sum_le List.exists_le_of_sum_le\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le [Preorder M] [CovariantClass M M (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] {l : List M}\n    (hl\u2081 : \u2200 x \u2208 l, (1 : M) \u2264 x) : 1 \u2264 l.prod := by\n  -- We don't use `pow_card_le_prod` to avoid assumption\n  -- [covariant_class M M (function.swap (*)) (\u2264)]\n  induction' l with hd tl ih\n  \u00b7 rfl\n  rw [prod_cons]\n  exact one_le_mul (hl\u2081 hd (mem_cons_self hd tl)) (ih fun x h => hl\u2081 x (mem_cons_of_mem hd h))\n#align list.one_le_prod_of_one_le List.one_le_prod_of_one_le\n#align list.sum_nonneg List.sum_nonneg\n\nend Monoid\n\nsection MonoidWithZero\n\nvariable [MonoidWithZero M\u2080]\n\n/-- If zero is an element of a list `L`, then `List.prod L = 0`. If the domain is a nontrivial\nmonoid with zero with no divisors, then this implication becomes an `iff`, see\n`List.prod_eq_zero_iff`. -/\ntheorem prod_eq_zero {L : List M\u2080} (h : (0 : M\u2080) \u2208 L) : L.prod = 0 := by\n  induction' L with a L ihL\n  \u00b7 exact absurd h (not_mem_nil _)\n  \u00b7 rw [prod_cons]\n    cases' mem_cons.1 h with ha hL\n    exacts[mul_eq_zero_of_left ha.symm _, mul_eq_zero_of_right _ (ihL hL)]\n#align list.prod_eq_zero List.prod_eq_zero\n\n/-- Product of elements of a list `L` equals zero if and only if `0 \u2208 L`. See also\n`List.prod_eq_zero` for an implication that needs weaker typeclass assumptions. -/\n@[simp]\ntheorem prod_eq_zero_iff [Nontrivial M\u2080] [NoZeroDivisors M\u2080] {L : List M\u2080} :\n    L.prod = 0 \u2194 (0 : M\u2080) \u2208 L := by\n  induction' L with a L ihL\n  \u00b7 simp\n  \u00b7 rw [prod_cons, mul_eq_zero, ihL, mem_cons, eq_comm]\n#align list.prod_eq_zero_iff List.prod_eq_zero_iff\n\ntheorem prod_ne_zero [Nontrivial M\u2080] [NoZeroDivisors M\u2080] {L : List M\u2080} (hL : (0 : M\u2080) \u2209 L) :\n    L.prod \u2260 0 :=\n  mt prod_eq_zero_iff.1 hL\n#align list.prod_ne_zero List.prod_ne_zero\n\nend MonoidWithZero\n\nsection Group\n\nvariable [Group G]\n\n/-- This is the `List.prod` version of `mul_inv_rev` -/\n@[to_additive \"This is the `List.sum` version of `add_neg_rev`\"]\ntheorem prod_inv_reverse : \u2200 L : List G, L.prod\u207b\u00b9 = (L.map fun x => x\u207b\u00b9).reverse.prod\n  | [] => by simp\n  | x :: xs => by simp [prod_inv_reverse xs]\n#align list.prod_inv_reverse List.prod_inv_reverse\n#align list.sum_neg_reverse List.sum_neg_reverse\n\n/-- A non-commutative variant of `List.prod_reverse` -/\n@[to_additive \"A non-commutative variant of `List.sum_reverse`\"]\ntheorem prod_reverse_noncomm : \u2200 L : List G, L.reverse.prod = (L.map fun x => x\u207b\u00b9).prod\u207b\u00b9 := by\n  simp [prod_inv_reverse]\n#align list.prod_reverse_noncomm List.prod_reverse_noncomm\n#align list.sum_reverse_noncomm List.sum_reverse_noncomm\n\nset_option linter.deprecated false in\n/-- Counterpart to `List.prod_take_succ` when we have an inverse operation -/\n@[to_additive (attr := simp)\n  \"Counterpart to `List.sum_take_succ` when we have an negation operation\"]\ntheorem prod_drop_succ :\n    \u2200 (L : List G) (i : \u2115) (p), (L.drop (i + 1)).prod = (L.nthLe i p)\u207b\u00b9 * (L.drop i).prod\n  | [], i, p => False.elim (Nat.not_lt_zero _ p)\n  | x :: xs, 0, _ => by simp [nthLe]\n  | x :: xs, i + 1, p => prod_drop_succ xs i _\n#align list.prod_drop_succ List.prod_drop_succ\n#align list.sum_drop_succ List.sum_drop_succ\n\nend Group\n\nsection CommGroup\n\nvariable [CommGroup G]\n\n/-- This is the `List.prod` version of `mul_inv` -/\n@[to_additive \"This is the `List.sum` version of `add_neg`\"]\ntheorem prod_inv : \u2200 L : List G, L.prod\u207b\u00b9 = (L.map fun x => x\u207b\u00b9).prod\n  | [] => by simp\n  | x :: xs => by simp [mul_comm, prod_inv xs]\n#align list.prod_inv List.prod_inv\n#align list.sum_neg List.sum_neg\n\n/-- Alternative version of `List.prod_set` when the list is over a group -/\n@[to_additive \"Alternative version of `List.sum_set` when the list is over a group\"]\ntheorem prod_set' (L : List G) (n : \u2115) (a : G) :\n    (L.set n a).prod = L.prod * if hn : n < L.length then (L.nthLe n hn)\u207b\u00b9 * a else 1 := by\n  refine (prod_set L n a).trans ?_\n  split_ifs with hn\n  \u00b7 rw [mul_comm _ a, mul_assoc a, prod_drop_succ L n hn, mul_comm _ (drop n L).prod, \u2190\n      mul_assoc (take n L).prod, prod_take_mul_prod_drop, mul_comm a, mul_assoc]\n  \u00b7 simp only [take_all_of_le (le_of_not_lt hn), prod_nil, mul_one,\n      drop_eq_nil_of_le ((le_of_not_lt hn).trans n.le_succ)]\n#align list.prod_update_nth' List.prod_set'\n#align list.sum_update_nth' List.sum_set'\n\nend CommGroup\n\n@[to_additive]\ntheorem eq_of_prod_take_eq [LeftCancelMonoid M] {L L' : List M} (h : L.length = L'.length)\n    (h' : \u2200 i \u2264 L.length, (L.take i).prod = (L'.take i).prod) : L = L' := by\n  refine ext_get h fun i h\u2081 h\u2082 => ?_\n  have : (L.take (i + 1)).prod = (L'.take (i + 1)).prod := h' _ (Nat.succ_le_of_lt h\u2081)\n  rw [prod_take_succ L i h\u2081, prod_take_succ L' i h\u2082, h' i (le_of_lt h\u2081)] at this\n  convert mul_left_cancel this\n#align list.eq_of_prod_take_eq List.eq_of_prod_take_eq\n#align list.eq_of_sum_take_eq List.eq_of_sum_take_eq\n\n@[to_additive]\ntheorem monotone_prod_take [CanonicallyOrderedMonoid M] (L : List M) :\n    Monotone fun i => (L.take i).prod := by\n  refine' monotone_nat_of_le_succ fun n => _\n  cases' lt_or_le n L.length with h h\n  \u00b7 rw [prod_take_succ _ _ h]\n    exact le_self_mul\n  \u00b7 simp [take_all_of_le h, take_all_of_le (le_trans h (Nat.le_succ _))]\n#align list.monotone_prod_take List.monotone_prod_take\n#align list.monotone_sum_take List.monotone_sum_take\n\n@[to_additive sum_pos]\ntheorem one_lt_prod_of_one_lt [OrderedCommMonoid M] :\n    \u2200 (l : List M) (_ : \u2200 x \u2208 l, (1 : M) < x) (_ : l \u2260 []), 1 < l.prod\n  | [], _, h => (h rfl).elim\n  | [b], h, _ => by simpa using h\n  | a :: b :: l, hl\u2081, _ =>\n    by\n    simp only [forall_eq_or_imp, List.mem_cons] at hl\u2081\n    rw [List.prod_cons]\n    apply one_lt_mul_of_lt_of_le' hl\u2081.1\n    apply le_of_lt ((b :: l).one_lt_prod_of_one_lt _ (l.cons_ne_nil b))\n    intro x hx; cases hx\n    \u00b7 exact hl\u2081.2.1\n    \u00b7 exact hl\u2081.2.2 _ \u2039_\u203a\n#align list.one_lt_prod_of_one_lt List.one_lt_prod_of_one_lt\n#align list.sum_pos List.sum_pos\n\n@[to_additive]\ntheorem single_le_prod [OrderedCommMonoid M] {l : List M} (hl\u2081 : \u2200 x \u2208 l, (1 : M) \u2264 x) :\n    \u2200 x \u2208 l, x \u2264 l.prod := by\n  induction l\n  \u00b7 simp\n  simp_rw [prod_cons, forall_mem_cons] at hl\u2081\u22a2\n  constructor\n  case cons.left => exact le_mul_of_one_le_right' (one_le_prod_of_one_le hl\u2081.2)\n  case cons.right hd tl ih => exact fun x H => le_mul_of_one_le_of_le hl\u2081.1 (ih hl\u2081.right x H)\n#align list.single_le_prod List.single_le_prod\n#align list.single_le_sum List.single_le_sum\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one [OrderedCommMonoid M] {l : List M}\n    (hl\u2081 : \u2200 x \u2208 l, (1 : M) \u2264 x) (hl\u2082 : l.prod = 1) {x : M} (hx : x \u2208 l) : x = 1 :=\n  _root_.le_antisymm (hl\u2082 \u25b8 single_le_prod hl\u2081 _ hx) (hl\u2081 x hx)\n#align list.all_one_of_le_one_le_of_prod_eq_one List.all_one_of_le_one_le_of_prod_eq_one\n#align list.all_zero_of_le_zero_le_of_sum_eq_zero List.all_zero_of_le_zero_le_of_sum_eq_zero\n\n/-- Slightly more general version of `List.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n      \"Slightly more general version of `List.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [Monoid M] {l : List M} (hl : \u2200 x \u2208 l, x = (1 : M)) : l.prod = 1 := by\n  induction' l with i l hil\n  \u00b7 rfl\n  rw [List.prod_cons, hil fun x hx => hl _ (mem_cons_of_mem i hx), hl _ (mem_cons_self i l),\n    one_mul]\n#align list.prod_eq_one List.prod_eq_one\n#align list.sum_eq_zero List.sum_eq_zero\n\n@[to_additive]\ntheorem exists_mem_ne_one_of_prod_ne_one [Monoid M] {l : List M} (h : l.prod \u2260 1) :\n    \u2203 x \u2208 l, x \u2260 (1 : M) := by simpa only [not_forall, exists_prop] using mt prod_eq_one h\n#align list.exists_mem_ne_one_of_prod_ne_one List.exists_mem_ne_one_of_prod_ne_one\n#align list.exists_mem_ne_zero_of_sum_ne_zero List.exists_mem_ne_zero_of_sum_ne_zero\n\n-- TODO: develop theory of tropical rings\ntheorem sum_le_foldr_max [AddMonoid M] [AddMonoid N] [LinearOrder N] (f : M \u2192 N) (h0 : f 0 \u2264 0)\n    (hadd : \u2200 x y, f (x + y) \u2264 max (f x) (f y)) (l : List M) : f l.sum \u2264 (l.map f).foldr max 0 := by\n  induction' l with hd tl IH\n  \u00b7 simpa using h0\n  simp only [List.sum_cons, List.foldr_map, List.foldr] at IH\u22a2\n  exact (hadd _ _).trans (max_le_max le_rfl IH)\n#align list.sum_le_foldr_max List.sum_le_foldr_max\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq M] [CommMonoid M] {a} :\n    \u2200 {l : List M}, a \u2208 l \u2192 a * (l.erase a).prod = l.prod\n  | b :: l, h => by\n    obtain rfl | \u27e8ne, h\u27e9 := Decidable.List.eq_or_ne_mem_of_mem h\n    \u00b7 simp only [List.erase, if_pos, prod_cons, beq_self_eq_true]\n    \u00b7 simp only [List.erase, beq_false_of_ne ne.symm, prod_cons, prod_erase h, mul_left_comm a b]\n#align list.prod_erase List.prod_erase\n#align list.sum_erase List.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq \u03b9] [CommMonoid M] (f : \u03b9 \u2192 M) {a} :\n    \u2200 {l : List \u03b9}, a \u2208 l \u2192 f a * ((l.erase a).map f).prod = (l.map f).prod\n  | b :: l, h => by\n    obtain rfl | \u27e8ne, h\u27e9 := Decidable.List.eq_or_ne_mem_of_mem h\n    \u00b7 simp only [map, erase_cons_head, prod_cons]\n    \u00b7 simp only [map, erase_cons_tail _ ne.symm, prod_cons, prod_map_erase _ h,\n        mul_left_comm (f a) (f b)]\n#align list.prod_map_erase List.prod_map_erase\n#align list.sum_map_erase List.sum_map_erase\n\ntheorem sum_const_nat (m n : \u2115) : sum (replicate m n) = m * n :=\n  sum_replicate m n\n#align list.sum_const_nat List.sum_const_nat\n\n/-- The product of a list of positive natural numbers is positive,\nand likewise for any nontrivial ordered semiring. -/\ntheorem prod_pos [StrictOrderedSemiring R] (l : List R) (h : \u2200 a \u2208 l, (0 : R) < a) :\n    0 < l.prod := by\n  induction' l with a l ih\n  \u00b7 simp\n  \u00b7 rw [prod_cons]\n    exact mul_pos (h _ <| mem_cons_self _ _) (ih fun a ha => h a <| mem_cons_of_mem _ ha)\n#align list.prod_pos List.prod_pos\n\n/-- A variant of `List.prod_pos` for `CanonicallyOrderedCommSemiring`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.list_prod_pos\n    {\u03b1 : Type _} [CanonicallyOrderedCommSemiring \u03b1] [Nontrivial \u03b1] :\n    \u2200 {l : List \u03b1}, 0 < l.prod \u2194 (\u2200 x \u2208 l, (0 : \u03b1) < x)\n  | [] => by simp\n  | (x :: xs) => by simp_rw [prod_cons, forall_mem_cons, CanonicallyOrderedCommSemiring.mul_pos,\n    list_prod_pos]\n#align canonically_ordered_comm_semiring.list_prod_pos CanonicallyOrderedCommSemiring.list_prod_pos\n\n/-!\nSeveral lemmas about sum/head/tail for `List \u2115`.\nThese are hard to generalize well, as they rely on the fact that `default \u2115 = 0`.\nIf desired, we could add a class stating that `default = 0`.\n-/\n\n/-- This relies on `default \u2115 = 0`. -/\ntheorem headI_add_tail_sum (L : List \u2115) : L.headI + L.tail.sum = L.sum := by\n  cases L <;> simp\n#align list.head_add_tail_sum List.headI_add_tail_sum\n\n/-- This relies on `default \u2115 = 0`. -/\ntheorem headI_le_sum (L : List \u2115) : L.headI \u2264 L.sum :=\n  Nat.le.intro (headI_add_tail_sum L)\n#align list.head_le_sum List.headI_le_sum\n\n/-- This relies on `default \u2115 = 0`. -/\ntheorem tail_sum (L : List \u2115) : L.tail.sum = L.sum - L.headI := by\n  rw [\u2190 headI_add_tail_sum L, add_comm, @add_tsub_cancel_right]\n#align list.tail_sum List.tail_sum\n\nsection Alternating\n\nsection\n\nvariable [One \u03b1] [Mul \u03b1] [Inv \u03b1]\n\n@[to_additive (attr := simp)]\ntheorem alternatingProd_nil : alternatingProd ([] : List \u03b1) = 1 :=\n  rfl\n#align list.alternating_prod_nil List.alternatingProd_nil\n#align list.alternating_sum_nil List.alternatingSum_nil\n\n@[to_additive (attr := simp)]\ntheorem alternatingProd_singleton (a : \u03b1) : alternatingProd [a] = a :=\n  rfl\n#align list.alternating_prod_singleton List.alternatingProd_singleton\n#align list.alternating_sum_singleton List.alternatingSum_singleton\n\n@[to_additive]\ntheorem alternatingProd_cons_cons' (a b : \u03b1) (l : List \u03b1) :\n    alternatingProd (a :: b :: l) = a * b\u207b\u00b9 * alternatingProd l :=\n  rfl\n#align list.alternating_prod_cons_cons' List.alternatingProd_cons_cons'\n#align list.alternating_sum_cons_cons' List.alternatingSum_cons_cons'\n\nend\n\n@[to_additive]\ntheorem alternatingProd_cons_cons [DivInvMonoid \u03b1] (a b : \u03b1) (l : List \u03b1) :\n    alternatingProd (a :: b :: l) = a / b * alternatingProd l := by\n  rw [div_eq_mul_inv, alternatingProd_cons_cons']\n#align list.alternating_prod_cons_cons List.alternatingProd_cons_cons\n#align list.alternating_sum_cons_cons List.alternatingSum_cons_cons\n\nvariable [CommGroup \u03b1]\n\n@[to_additive]\ntheorem alternatingProd_cons' :\n    \u2200 (a : \u03b1) (l : List \u03b1), alternatingProd (a :: l) = a * (alternatingProd l)\u207b\u00b9\n  | a, [] => by rw [alternatingProd_nil, inv_one, mul_one, alternatingProd_singleton]\n  | a, b :: l => by\n    rw [alternatingProd_cons_cons', alternatingProd_cons' b l, mul_inv, inv_inv, mul_assoc]\n#align list.alternating_prod_cons' List.alternatingProd_cons'\n#align list.alternating_sum_cons' List.alternatingSum_cons'\n\n@[to_additive (attr := simp)]\ntheorem alternatingProd_cons (a : \u03b1) (l : List \u03b1) :\n    alternatingProd (a :: l) = a / alternatingProd l := by\n  rw [div_eq_mul_inv, alternatingProd_cons']\n#align list.alternating_prod_cons List.alternatingProd_cons\n#align list.alternating_sum_cons List.alternatingSum_cons\n\nend Alternating\n\nlemma sum_nat_mod (l : List \u2115) (n : \u2115) : l.sum % n = (l.map (\u00b7 % n)).sum % n := by\n  induction l <;> simp [Nat.add_mod, *]\n#align list.sum_nat_mod List.sum_nat_mod\n\nlemma prod_nat_mod (l : List \u2115) (n : \u2115) : l.prod % n = (l.map (\u00b7 % n)).prod % n := by\n  induction l <;> simp [Nat.mul_mod, *]\n#align list.prod_nat_mod List.prod_nat_mod\n\nlemma sum_int_mod (l : List \u2124) (n : \u2124) : l.sum % n = (l.map (\u00b7 % n)).sum % n := by\n  induction l <;> simp [Int.add_emod, *]\n#align list.sum_int_mod List.sum_int_mod\n\nlemma prod_int_mod (l : List \u2124) (n : \u2124) : l.prod % n = (l.map (\u00b7 % n)).prod % n := by\n  induction l <;> simp [Int.mul_emod, *]\n#align list.prod_int_mod List.prod_int_mod\n\nend List\n\nsection MonoidHom\n\nvariable [Monoid M] [Monoid N]\n\n@[to_additive]\ntheorem map_list_prod {F : Type _} [MonoidHomClass F M N] (f : F) (l : List M) :\n    f l.prod = (l.map f).prod :=\n  (l.prod_hom f).symm\n#align map_list_prod map_list_prod\n#align map_list_sum map_list_sum\n\nnamespace MonoidHom\n\n/-- Deprecated, use `_root_.map_list_prod` instead. -/\n@[to_additive \"Deprecated, use `_root_.map_list_sum` instead.\"]\nprotected theorem map_list_prod (f : M \u2192* N) (l : List M) : f l.prod = (l.map f).prod :=\n  map_list_prod f l\n#align monoid_hom.map_list_prod MonoidHom.map_list_prod\n#align add_monoid_hom.map_list_sum AddMonoidHom.map_list_sum\n\nend MonoidHom\n\nend MonoidHom\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/List/BigOperators/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7160614986380937}}
{"text": "\nsection chap3ex1\n    variables p q r : Prop\n\n    example : p \u2227 q \u2194 q \u2227 p :=\n    begin\n        apply iff.intro,\n        repeat {\n          intro h,\n            exact and.intro h.right h.left,\n        }\n    end\n\n    example : p \u2228 q \u2194 q \u2228 p :=\n    begin\n        apply iff.intro,\n          intro h,\n          apply or.elim h,\n            intro hp,\n            right, exact hp,\n            intro hq,\n            left, exact hq,\n        intro h,\n        apply or.elim h,\n          intro hp,\n          right, exact hp,\n        intro hq,\n        left, exact hq\n    end\n\n    example : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n    begin\n        apply iff.intro,\n        intro h,\n        exact and.intro h.left.left \u27e8h.left.right, h.right\u27e9,\n        intro h,\n        exact and.intro \u27e8h.left, h.right.left\u27e9 h.right.right\n    end\n\n    example : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n    begin\n        apply iff.intro,\n        { intro h,\n          cases h with hpq hr,\n          { cases hpq with hp hq,\n            { left, assumption },\n            { right, left, assumption }},\n          { right, right, exact hr }},\n        intro h,\n        cases h with hp hqr,\n        { left, left, exact hp },\n        { cases hqr with hq hr,\n          { left, right, exact hq },\n          { right, exact hr }}\n    end\n\n    example : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n    begin\n        apply iff.intro,\n        { intro h,\n          have hp : p, from h.left,\n          have hqr : q \u2228 r, from h.right,\n          cases hqr with hq hr,\n          { left, constructor, assumption, assumption },\n          right, constructor, assumption, assumption },\n        intro h,\n        cases h with hpq hpr,\n          { constructor, exact hpq.left, left, exact hpq.right },\n        constructor, exact hpr.left, right, exact hpr.right\n    end\n\n    example : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n    begin\n      apply iff.intro,\n      { intro h,\n        cases h with hp hqr,\n        { constructor, repeat { left, exact hp } },\n        { constructor; right, exact hqr.left, exact hqr.right } },\n      intro h,\n      have pq : p \u2228 q, from h.left,\n      have pr : p \u2228 r, from h.right,\n      cases pq with hp hq,\n      { left, exact hp },\n      have hq : q, from hq,\n      cases pr with hp hr,\n      { left, exact hp },\n      right, constructor, exact hq, exact hr\n    end\n\n    example : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n    begin\n      apply iff.intro,\n      { intros h1 h2, exact h1 h2.left h2.right  },\n      intros h1 hp hq,\n      have pq : p \u2227 q, { constructor, repeat { assumption }},\n      exact h1 pq\n    end\n\n    example : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\n    begin\n      apply iff.intro,\n      { intro h,\n        constructor ;\n        { intro h1,\n          have pq : p \u2228 q, { { left, exact h1 } <|> { right, exact h1 } },\n          exact h pq }},\n      intros h1 h2,\n      cases h2 with hp hq,\n        exact h1.left hp,\n      exact h1.right hq\n    end\n\n    example : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n    begin\n      apply iff.intro,\n      { intro hnpq,\n        constructor ;\n        { intro h1,\n          have hpq : p \u2228 q, { { left <|> right, exact h1 } <|> { right, exact h1 } },\n          exact absurd hpq hnpq }},\n      intros h hc,\n      have hnp : \u00ac p, from h.left,\n      have hnq : \u00ac q, from h.right,\n      cases hc with hp hq;\n      { apply absurd, exact hp <|> exact hq, assumption}\n    end\n\n    example : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n    begin\n      intros hdis hconj,\n      cases hdis with hnp hnq,\n        { exact absurd hconj.left hnp },\n      exact absurd hconj.right hnq\n    end\n\n    example : \u00ac(p \u2227 \u00acp) :=\n    begin\n      intro h,\n      exact absurd h.left h.right\n    end\n\n    example : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n    begin\n      intros hconj hn,\n      have hq : q, { exact hn hconj.left },\n      exact absurd hq hconj.right\n    end\n\n    example : \u00acp \u2192 (p \u2192 q) :=\n    begin\n      intros hnp hp,\n      exact (false.elim $ hnp hp)\n    end\n\n    example : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n    begin\n      intros hdis hp,\n      cases hdis with hnp hq,\n      { exact absurd hp hnp },\n      assumption\n    end\n\n    example : p \u2228 false \u2194 p :=\n    begin\n      apply iff.intro,\n      { intro h, cases h with hp hfalse, assumption, exact false.elim hfalse },\n      intro hp, left, exact hp\n    end\n\n    example : p \u2227 false \u2194 false :=\n    begin\n      apply iff.intro,\n      { intro h, exact h.right },\n      intro hfalse, exact false.elim hfalse\n    end\n\n    example : \u00ac(p \u2194 \u00acp) :=\n    begin\n      intro h,\n      have l : p \u2192 \u00acp, { exact iff.elim_left h },\n      have r : \u00acp \u2192 p, { exact iff.elim_right h },\n      have hnp : \u00acp, { intro hp, exact absurd hp (l hp) },\n      exact absurd (r hnp) hnp,\n    end\n\n    example : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n    begin\n      intros hptoq hnq hp,\n      exact absurd (hptoq hp) hnq\n    end\n\n\nend chap3ex1\n\nsection chap3ex2\n    open classical\n\n    variables p q r s : Prop\n\n    example : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n    begin\n      intro h,\n      cases (em p) with hp hnp,\n      { cases (h hp) with hr hs,\n        { left, exact (\u03bb hp, hr) },\n        right, exact (\u03bb hp, hs)},\n      left,\n      intro hp,\n      contradiction\n    end\n\n    example : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n    begin\n      intro h,\n      cases (em p) with hp hnp,\n      { cases (em q) with hq hnq,\n        { exact (false.elim $ h \u27e8hp, hq\u27e9) },\n        right, exact hnq },\n      left, exact hnp\n    end\n\n    example : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n    begin\n      intro h,\n      cases (em p) with hp hnp,\n      { cases (em q) with hq hnq,\n        { have  ptoq : (p \u2192 q), from \u03bb hp, hq,\n          contradiction },\n        constructor, assumption, assumption },\n      cases (em q) with hq hnq,\n      { have ptoq : p \u2192 q, from \u03bb hp, absurd hp hnp,\n        contradiction },\n      have ptoq : p \u2192 q, { intro hp, contradiction },\n      contradiction\n    end\n\n    example : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n    begin\n      intro h,\n      cases (em p) with hp hnp,\n      { right, exact h hp },\n      left, exact hnp\n    end\n\n    example : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n    begin\n      intro h,\n      cases (em q) with hq hnq,\n        { exact (\u03bb hp, hq) },\n      have hnp : \u00acp, from h hnq,\n      exact (\u03bb hp, absurd hp hnp)\n    end\n\n    example : p \u2228 \u00acp :=\n    begin\n      cases (em p) with hp hnp,\n      { left, assumption },\n      right, assumption\n    end\n\n    example : (((p \u2192 q) \u2192 p) \u2192 p) :=\n    begin\n      intro h,\n      cases (em p) with hp hnp,\n      { assumption },\n      have ptoq : p \u2192 q, { intro hp, contradiction },\n      exact h ptoq\n    end\n\nend chap3ex2\n\nsection chap3ex3\n\n  example { p : Prop } : \u00ac(p \u2194 \u00acp) :=\n  begin\n    intro h,\n    have nptop : \u00acp \u2192 p, from iff.elim_right h,\n    have ptonp : p \u2192 \u00acp, from iff.elim_left h,\n    have np : \u00acp, { intro hp, exact absurd hp (ptonp hp) },\n    exact absurd (nptop np) np\n  end\n\nend chap3ex3\n\nsection chap4ex1\n\n  variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\n  example : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\n  begin\n    apply iff.intro,\n    { intro h,\n      constructor,\n      repeat {\n        intro ha,\n        let h1 := h ha,\n        exact h1.left <|> exact h1.right\n      }},\n    intros h ha,\n    constructor,\n    { exact h.left ha },\n    exact h.right ha\n  end\n\n  example : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\n  begin\n    intros h1 h2 hx,\n    exact (h1 hx $ h2 hx)\n  end\n\n  example : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\n  begin\n    intros h1 hx,\n    cases h1 with hpx hqx,\n    { left, exact hpx hx },\n    right, exact hqx hx\n  end\n\nend chap4ex1\n\nsection chap4ex2\n\n  variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n  variable r : Prop\n\n  example : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) :=\n  begin\n    intro ha,\n    apply iff.intro,\n    { intro hr, exact hr ha },\n    intros hr hx,\n    assumption\n  end\n\n  -- one branch requires classical logic\n  example : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r :=\n  begin\n    apply iff.intro,\n    { intros h,\n      cases (classical.em r) with hr hnr,\n      { right, assumption },\n      left,\n      intro hx,\n      cases (h hx), assumption, contradiction },\n    intros h hx,\n    cases h with hpx hr,\n    { left, exact hpx hx },\n    right, exact hr\n  end\n\n  example : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\n  begin\n    apply iff.intro,\n    { intros h hr hx, exact h hx hr },\n    intros h hx hr, exact (h hr) hx\n  end\n\nend chap4ex2\n\nsection chap4ex3\n\n  variables (men : Type) (barber : men)\n  variable  (shaves : men \u2192 men \u2192 Prop)\n\n  example (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : false :=\n  begin\n    have barber_case : shaves barber barber \u2194 \u00ac shaves barber barber, from h barber,\n    have barber_doesnt_shave_himself: \u00ac(shaves barber barber),\n      begin\n        intro h1,\n        have : \u00ac shaves barber barber, from (iff.elim_left barber_case) h1,\n        contradiction\n      end,\n    have does_he_though : shaves barber barber, from (iff.elim_right barber_case) barber_doesnt_shave_himself,\n    contradiction\n  end\n\nend chap4ex3\n\n-- chap4ex4 doesn't involve any proof\n\nsection chap4ex5\n\n  open classical\n\n  variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n  variable a : \u03b1\n  variable r : Prop\n\n  include a\n\n  example : (\u2203 x : \u03b1, r) \u2192 r :=\n  begin\n    intro h,\n    cases h,\n    assumption\n  end\n\n  example : r \u2192 (\u2203 x : \u03b1, r) :=\n  begin\n    intro h,\n    constructor, exact a, exact h\n  end\n\n\n  example : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r :=\n  begin\n    apply iff.intro,\n    { intro h,\n      cases h with ha hconj,\n      constructor,\n      { existsi ha, exact hconj.left },\n      exact hconj.right },\n    intro h,\n    have ex : \u2203 x, p x, from h.left,\n    cases ex with hx hpx,\n    existsi hx,\n    constructor,\n    { exact hpx },\n    exact h.right,\n  end\n\n  example : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\n  begin\n    apply iff.intro,\n    { intro h,\n      cases h with hx hdisj,\n      cases hdisj with hpx hqx,\n      { left, existsi hx, exact hpx },\n      right, existsi hx, exact hqx },\n    intro h,\n    cases h with hpx hqx,\n    { cases hpx with hx hpx', existsi hx, left, exact hpx' },\n    cases hqx with hx hqx', existsi hx, right, exact hqx'\n  end\n\n  def forall_px_not_exists_not_px : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) :=\n  begin\n    apply iff.intro,\n    { intros h hcon,\n      cases hcon with hx hnpx,\n      have hpx : p hx, from h hx,\n      contradiction },\n    intros h hx,\n    cases (classical.em (p hx)) with _ hnpx,\n    { show p hx, by assumption },\n    show p hx,\n    have : \u2203 x, \u00acp x, { existsi hx, exact hnpx },\n    contradiction\n  end\n\n  example : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := @forall_px_not_exists_not_px \u03b1 p a\n\n  def exists_p_x_not_forall_not_px : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) :=\n  begin\n    apply iff.intro,\n    { intros h hcon,\n      cases h with hx hpx,\n      have hnpx : \u00ac p hx, { exact hcon hx },\n      contradiction },\n    show \u00ac(\u2200 x, \u00acp x) \u2192 (\u2203 x, p x),\n    intro h,\n    cases (classical.em (\u2203 x, p x)) with _ hnex,\n    { assumption },\n    have hcont : \u2200x, \u00acp x, {\n        intros hx hpx,\n        have hex : \u2203 x, p x, { existsi hx, exact hpx },\n        contradiction\n      },\n    contradiction\n  end\n\n  example : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := @exists_p_x_not_forall_not_px \u03b1 p a\n\n  example : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) :=\n  begin\n    apply iff.intro,\n    { intros h hx,\n      cases (em (p hx)) with hpx hnpx,\n      { have : \u2203 x, p x, from \u27e8hx, hpx\u27e9,\n        contradiction },\n      assumption },\n    intros h hcont,\n    cases hcont with hx hpx,\n    have nphx : \u00ac p hx, from h hx,\n    contradiction\n  end\n\n  def not_forall_exists_not_equivalence : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) :=\n  begin\n    apply iff.intro,\n    { intro h,\n      cases (em (p a)) with hpa hnpa,\n      { cases (em \u2203 x, \u00ac p x) with hexists hnexists,\n        { assumption },\n        have : \u2200 x, p x, from iff.elim_right (@forall_px_not_exists_not_px \u03b1 p a) hnexists,\n        contradiction },\n      existsi a, exact hnpa },\n    intros h hcont,\n    cases h with hx hnpx,\n    have hpx : p hx, from hcont hx,\n    contradiction\n  end\n\n  example : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := @not_forall_exists_not_equivalence \u03b1 p a\n\n  example : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r :=\n  begin\n    apply iff.intro,\n    { intros h hex,\n      cases hex with hx hpx,\n      exact h hx hpx},\n    intros h hx hphx,\n    have : \u2203 x, p x, from \u27e8hx, hphx\u27e9,\n    exact h this\n  end\n\n  example : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r :=\n  begin\n    apply iff.intro,\n    { intros hex hfa,\n      cases hex with hx hphx,\n      have hhx : p hx, from hfa hx,\n      exact hphx hhx },\n    intros h,\n    cases (em (\u2200 (x : \u03b1), p x)) with hyes hno,\n    { existsi a, intro hpa, exact h hyes },\n    have : (\u2203 x, \u00ac p x), from iff.elim_left (@not_forall_exists_not_equivalence \u03b1 p a) hno,\n    cases this with hx hnpx,\n    existsi hx, intro hpx, contradiction\n  end\n\n  example : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) :=\n  begin\n    apply iff.intro,\n    { intros hex hr,\n      cases hex with hx hrtopx,\n      existsi hx, exact hrtopx hr },\n    intro h,\n    cases (em r) with hr hnr,\n    { have : (\u2203 (x : \u03b1), p x), from h hr,\n      cases this with hx hpx,\n      existsi hx, intro hr, exact hpx },\n    existsi a, intro hr, contradiction\n  end\n\nend chap4ex5\n\nsection chap4ex6\n  variables (real : Type) [ordered_ring real]\n  variables (log exp : real \u2192 real)\n  variable  log_exp_eq : \u2200 x, log (exp x) = x\n  variable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\n  variable  exp_pos    : \u2200 x, exp x > 0\n  variable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n  -- this ensures the assumptions are available in tactic proofs\n  include log_exp_eq exp_log_eq exp_pos exp_add\n\n  example (x y z : real) :\n    exp (x + y + z) = exp x * exp y * exp z :=\n  by rw [exp_add, exp_add]\n\n  example (y : real) (h : y > 0)  : exp (log y) = y :=\n  exp_log_eq h\n\n  theorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n    log (x * y) = log x + log y :=\n  let x := x, y := y in\n  begin\n    have s1 : log (x * y) = log (x * y), by reflexivity,\n    have s2 : log (x * y) = log (exp (log x) * (exp (log y))), by { rw (exp_log_eq hx), rw (exp_log_eq hy) },\n    have s3 : log (exp (log x) * (exp (log y))) = log (exp (log x + log y)), by { rw exp_add },\n    have s4 : log (exp (log x + log y)) = log x + log y, by rw log_exp_eq,\n    show log (x * y) = log x + log y, by rw [s1, s2, s3, s4],\n  end\n\nend chap4ex6\n\nsection chap4ex7\n\n  #check sub_self\n\n  example (x : \u2124) : x * 0 = 0 :=\n  calc\n    x * 0 = 0 * x : by rw [mul_comm]\n      ... = (x - x) * x : by rw sub_self\n      ... = (x * x) - (x * x) : by rw sub_mul\n      ... = 0 : by rw sub_self\n\nend chap4ex7\n\nsection chap5ex2\n\n  example (p q r : Prop) (hp : p) :\n  (p \u2228 q \u2228 r) \u2227 (q \u2228 p \u2228 r) \u2227 (q \u2228 r \u2228 p) :=\n  by repeat { constructor, repeat { { left, exact hp } <|> { right, left, exact hp } <|> { right, right, exact hp } } }\n\nend chap5ex2\n", "meta": {"author": "tomhoule", "repo": "theorem-proving-in-lean-exercises", "sha": "60ccc71b8a6df6924e7cc90aab713b804f78da9f", "save_path": "github-repos/lean/tomhoule-theorem-proving-in-lean-exercises", "path": "github-repos/lean/tomhoule-theorem-proving-in-lean-exercises/theorem-proving-in-lean-exercises-60ccc71b8a6df6924e7cc90aab713b804f78da9f/theorem-proving-in-lean/src/chap_5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7160614879719182}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level6 -- add_right_comm\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 11: `add_le_add_right`\n\nIf you're faced with a goal of the form `forall t, ...`, then the next\nline is \"so let `t` be arbitrary\". The way to do this in Lean is `intro t`.\n\n## Lemma : add_le_add_right\nFor all naturals `a` and `b`, `a \u2264 b` implies that for all naturals `t`,\n`a+t \u2264 b+t`.\n-/\ntheorem add_le_add_right {a b : MyNat} : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) := by\n  intro h\n  cases h with\n  | _ c hc =>\n    intro t\n    use c\n    rw [hc]\n    rw [add_right_comm]\n\n/-!\nNext up [Level 12](./Level12.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.7160586347070635}}
{"text": "import tactic.ring data.nat.basic data.nat.modeq tactic.linarith\n\n/-- digit b n d is the d'th digit of n in base b \n    (where the 0th digit is the units digit of n) -/\ndefinition digit (b : \u2115) : \u2115 \u2192 \u2115 \u2192 \u2115\n| n 0 := n % b\n| n (e + 1) := digit (n / b) e\n\ndef dec_digit (n : \u2115) (d : \u2115) := digit 10 n d\n\n-- n congruent mod b to 0th digit\nlemma digit_zero (b n) :\ndigit b n 0 = n % b := rfl\n\n-- d+1'st digit of n = d'th digit of n / b\nlemma digit_succ (b n d : \u2115) :\ndigit b n (d + 1) = digit b (n / b) d := rfl\n\n-- digits are all less than b.\nlemma digit_lt_base (b : \u2115) (hb : b \u2265 1) (d : \u2115) :\n\u2200 n, digit b n d < b :=\nbegin\n  induction d with e He,\n    -- base case\n    intro n, exact nat.mod_lt n hb,\n  -- inductive step\n  intro n, exact He _\nend\n\nlemma irritating (M : \u2115) : 10 ^ (M + 1) - 1 = 10 * (10 ^ M - 1) + 9 :=\nbegin\n  rw [nat.pow_succ,nat.mul_sub_left_distrib,mul_comm,mul_one],\n  apply nat.sub_eq_of_eq_add,\n  rw [add_comm,add_assoc],\n  refine (nat.sub_add_cancel _).symm,\n  suffices : 10 * 10 ^ M \u2265 10 * 1,\n    rwa mul_one at this,\n  apply nat.mul_le_mul_left,\n  show 10 ^ M > 0,\n  apply nat.pow_pos,\n  exact dec_trivial\nend\n\nlemma all_nines_ends_in_nine (L : \u2115) (HL : L \u2265 1) : (10 ^ L - 1) % 10 = 9 :=\nbegin\n  cases L with M, cases HL,\n  rw [irritating,add_comm,nat.add_mul_mod_self_left],\n  refl,\nend\n\ntheorem zero_digit_sum (M m n : \u2115) (hmn : m + n = 10 ^ (M + 1) - 1) :\nm % 10 + n % 10 = 9 :=\nbegin\n  have m9 : dec_digit m 0 \u2264 9 := by unfold dec_digit; exact nat.le_of_lt_succ (digit_lt_base 10 (dec_trivial) 0 m),\n  have n9 : dec_digit n 0 \u2264 9 := by unfold dec_digit; exact nat.le_of_lt_succ (digit_lt_base 10 (dec_trivial) 0 n),\n  have mn : (dec_digit m 0 + dec_digit n 0) % 10 = 9,\n    unfold dec_digit,rw digit_zero,rw digit_zero,\n    rw [\u2190all_nines_ends_in_nine (nat.succ M) (dec_trivial),\u2190hmn],\n    apply nat.modeq.modeq_add,\n      exact nat.modeq.mod_modeq m 10,\n      exact nat.modeq.mod_modeq n 10,\n  have : dec_digit m 0 + dec_digit n 0 \u2264 18 := by linarith,\n  generalize h2 : dec_digit m 0 + dec_digit n 0 = e,\n  rw h2 at this mn,\n  rw \u2190nat.mod_add_div e 10 at this,\n  rw mn at this,\n  suffices h3 : e / 10 = 0,\n    rw \u2190nat.mod_add_div e 10,\n    rw h3,\n    rw mn,\n    refl,\n  replace this := nat.le_sub_left_of_add_le this,\n  change _ \u2264 9 at this,\n  generalize h4 : e / 10 = f,\n  rw h4 at this,\n  cases f with g,refl,exfalso,\n  revert this,\n  apply not_le_of_gt,\n  change 10 * (g + 1) > 9,\n  rw mul_add,\n  exact nat.lt_add_left _ _ _ (dec_trivial),\nend\n\ntheorem digit_sum (L m n : \u2115) (hmn : m + n = 10 ^ L - 1) :\n\u2200 d, d < L \u2192 dec_digit m d + dec_digit n d = 9 :=\nbegin\n  -- induction on length\n  revert m n,\n  induction L with M HM,\n    -- base case empty\n    intros m n hmn d Hd,cases Hd, -- no cases\n  intros m n hmn d,\n  induction d with e He,\n    -- done base case already\n    intro zzz, exact zero_digit_sum M m n hmn,\n  -- succ\n  intro Hem,\n  unfold dec_digit, rw digit_succ,rw digit_succ,\n  apply HM,\n  { rw \u2190nat.mul_left_inj (show 10 > 0, from dec_trivial),\n    rw [mul_add,nat.mul_sub_left_distrib,mul_one],\n    rw [mul_comm _ (10 ^ M),\u2190nat.pow_succ],\n    apply @nat.add_right_cancel _ (m % 10 + n % 10),\n    rw [\u2190add_assoc,add_assoc _ _ (m % 10),add_comm _ (m % 10),\u2190add_assoc (10 * (m / 10))],\n    rw [add_comm _ (m % 10),nat.mod_add_div],\n    rw [add_assoc,add_comm _ (n % 10),nat.mod_add_div],\n    rw zero_digit_sum _ _ _ hmn,\n    rw hmn,\n    rw [irritating M,nat.mul_sub_left_distrib,mul_one,nat.pow_succ,mul_comm] },\n  exact nat.lt_of_succ_lt_succ Hem\nend", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/PLUS/digit_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7160211020941547}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\nSome proofs and docs came from `algebra/commute` (c) Neil Strickland\n-/\nimport algebra.group.units\n\n/-!\n# Semiconjugate elements of a semigroup\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\nWe say that `x` is semiconjugate to `y` by `a` (`semiconj_by a x y`), if `a * x = y * a`.\nIn this file we  provide operations on `semiconj_by _ _ _`.\n\nIn the names of these operations, we treat `a` as the \u201cleft\u201d argument, and both `x` and `y` as\n\u201cright\u201d arguments. This way most names in this file agree with the names of the corresponding lemmas\nfor `commute a b = semiconj_by a b b`. As a side effect, some lemmas have only `_right` version.\n\nLean does not immediately recognise these terms as equations, so for rewriting we need syntax like\n`rw [(h.pow_right 5).eq]` rather than just `rw [h.pow_right 5]`.\n\nThis file provides only basic operations (`mul_left`, `mul_right`, `inv_right` etc). Other\noperations (`pow_right`, field inverse etc) are in the files that define corresponding notions.\n-/\n\nuniverses u v\nvariables {G : Type*}\n\n/-- `x` is semiconjugate to `y` by `a`, if `a * x = y * a`. -/\n@[to_additive add_semiconj_by \"`x` is additive semiconjugate to `y` by `a` if `a + x = y + a`\"]\ndef semiconj_by {M : Type u} [has_mul M] (a x y : M) : Prop := a * x = y * a\n\nnamespace semiconj_by\n\n/-- Equality behind `semiconj_by a x y`; useful for rewriting. -/\n@[to_additive \"Equality behind `add_semiconj_by a x y`; useful for rewriting.\"]\nprotected lemma eq {S : Type u} [has_mul S] {a x y : S} (h : semiconj_by a x y) :\n  a * x = y * a := h\n\nsection semigroup\n\nvariables {S : Type u} [semigroup S] {a b x y z x' y' : S}\n\n/-- If `a` semiconjugates `x` to `y` and `x'` to `y'`,\nthen it semiconjugates `x * x'` to `y * y'`. -/\n@[simp, to_additive \"If `a` semiconjugates `x` to `y` and `x'` to `y'`, then it semiconjugates\n`x + x'` to `y + y'`.\"]\nlemma mul_right (h : semiconj_by a x y) (h' : semiconj_by a x' y') :\n  semiconj_by a (x * x') (y * y') :=\nby unfold semiconj_by; assoc_rw [h.eq, h'.eq]\n\n/-- If both `a` and `b` semiconjugate `x` to `y`, then so does `a * b`. -/\n@[to_additive \"If both `a` and `b` semiconjugate `x` to `y`, then so does `a + b`.\"]\nlemma mul_left (ha : semiconj_by a y z) (hb : semiconj_by b x y) : semiconj_by (a * b) x z :=\nby unfold semiconj_by; assoc_rw [hb.eq, ha.eq, mul_assoc]\n\n/-- The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on a semigroup\nis transitive. -/\n@[to_additive \"The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on an additive\nsemigroup is transitive.\"]\nprotected lemma transitive : transitive (\u03bb a b : S, \u2203 c, semiconj_by c a b) :=\n\u03bb a b c \u27e8x, hx\u27e9 \u27e8y, hy\u27e9, \u27e8y * x, hy.mul_left hx\u27e9\n\nend semigroup\n\nsection mul_one_class\n\nvariables {M : Type u} [mul_one_class M]\n\n/-- Any element semiconjugates `1` to `1`. -/\n@[simp, to_additive \"Any element additively semiconjugates `0` to `0`.\"]\n\n\n/-- One semiconjugates any element to itself. -/\n@[simp, to_additive \"Zero additively semiconjugates any element to itself.\"]\nlemma one_left (x : M) : semiconj_by 1 x x := eq.symm $ one_right x\n\n/-- The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on a monoid (or, more\ngenerally, on ` mul_one_class` type) is reflexive. -/\n@[to_additive \"The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on an additive\nmonoid (or, more generally, on a `add_zero_class` type) is reflexive.\"]\nprotected lemma reflexive : reflexive (\u03bb a b : M, \u2203 c, semiconj_by c a b) :=\n\u03bb a, \u27e81, one_left a\u27e9\n\nend mul_one_class\n\nsection monoid\n\nvariables {M : Type u} [monoid M]\n\n/-- If `a` semiconjugates a unit `x` to a unit `y`, then it semiconjugates `x\u207b\u00b9` to `y\u207b\u00b9`. -/\n@[to_additive \"If `a` semiconjugates an additive unit `x` to an additive unit `y`, then it\nsemiconjugates `-x` to `-y`.\"]\nlemma units_inv_right {a : M} {x y : M\u02e3} (h : semiconj_by a x y) : semiconj_by a \u2191x\u207b\u00b9 \u2191y\u207b\u00b9 :=\ncalc a * \u2191x\u207b\u00b9 = \u2191y\u207b\u00b9 * (y * a) * \u2191x\u207b\u00b9 : by rw [units.inv_mul_cancel_left]\n          ... = \u2191y\u207b\u00b9 * a              : by rw [\u2190 h.eq, mul_assoc, units.mul_inv_cancel_right]\n\n@[simp, to_additive] lemma units_inv_right_iff {a : M} {x y : M\u02e3} :\n  semiconj_by a \u2191x\u207b\u00b9 \u2191y\u207b\u00b9 \u2194 semiconj_by a x y :=\n\u27e8units_inv_right, units_inv_right\u27e9\n\n/-- If a unit `a` semiconjugates `x` to `y`, then `a\u207b\u00b9` semiconjugates `y` to `x`. -/\n@[to_additive \"If an additive unit `a` semiconjugates `x` to `y`, then `-a` semiconjugates `y` to\n`x`.\"]\nlemma units_inv_symm_left {a : M\u02e3} {x y : M} (h : semiconj_by \u2191a x y) :\n  semiconj_by \u2191a\u207b\u00b9 y x :=\ncalc \u2191a\u207b\u00b9 * y = \u2191a\u207b\u00b9 * (y * a * \u2191a\u207b\u00b9) : by rw [units.mul_inv_cancel_right]\n          ... = x * \u2191a\u207b\u00b9              : by rw [\u2190 h.eq, \u2190 mul_assoc, units.inv_mul_cancel_left]\n\n@[simp, to_additive] lemma units_inv_symm_left_iff {a : M\u02e3} {x y : M} :\n  semiconj_by \u2191a\u207b\u00b9 y x \u2194 semiconj_by \u2191a x y :=\n\u27e8units_inv_symm_left, units_inv_symm_left\u27e9\n\n@[to_additive] theorem units_coe {a x y : M\u02e3} (h : semiconj_by a x y) :\n  semiconj_by (a : M) x y :=\ncongr_arg units.val h\n\n@[to_additive] theorem units_of_coe {a x y : M\u02e3} (h : semiconj_by (a : M) x y) :\n  semiconj_by a x y :=\nunits.ext h\n\n@[simp, to_additive] theorem units_coe_iff {a x y : M\u02e3} :\n  semiconj_by (a : M) x y \u2194 semiconj_by a x y :=\n\u27e8units_of_coe, units_coe\u27e9\n\n@[simp, to_additive]\nlemma pow_right {a x y : M} (h : semiconj_by a x y) (n : \u2115) : semiconj_by a (x^n) (y^n) :=\nbegin\n  induction n with n ih,\n  { rw [pow_zero, pow_zero], exact semiconj_by.one_right _ },\n  { rw [pow_succ, pow_succ],\n    exact h.mul_right ih }\nend\n\nend monoid\n\nsection division_monoid\nvariables [division_monoid G] {a x y : G}\n\n@[simp, to_additive] lemma inv_inv_symm_iff : semiconj_by a\u207b\u00b9 x\u207b\u00b9 y\u207b\u00b9 \u2194 semiconj_by a y x :=\ninv_involutive.injective.eq_iff.symm.trans $ by simp_rw [mul_inv_rev, inv_inv, eq_comm, semiconj_by]\n\n@[to_additive] lemma inv_inv_symm : semiconj_by a x y \u2192 semiconj_by a\u207b\u00b9 y\u207b\u00b9 x\u207b\u00b9 :=\ninv_inv_symm_iff.2\n\nend division_monoid\n\nsection group\n\nvariables [group G] {a x y : G}\n\n@[simp, to_additive] lemma inv_right_iff : semiconj_by a x\u207b\u00b9 y\u207b\u00b9 \u2194 semiconj_by a x y :=\n@units_inv_right_iff G _ a \u27e8x, x\u207b\u00b9, mul_inv_self x, inv_mul_self x\u27e9\n  \u27e8y, y\u207b\u00b9, mul_inv_self y, inv_mul_self y\u27e9\n\n@[to_additive] lemma inv_right : semiconj_by a x y \u2192 semiconj_by a x\u207b\u00b9 y\u207b\u00b9 :=\ninv_right_iff.2\n\n@[simp, to_additive] lemma inv_symm_left_iff : semiconj_by a\u207b\u00b9 y x \u2194 semiconj_by a x y :=\n@units_inv_symm_left_iff G _ \u27e8a, a\u207b\u00b9, mul_inv_self a, inv_mul_self a\u27e9 _ _\n\n@[to_additive] lemma inv_symm_left : semiconj_by a x y \u2192 semiconj_by a\u207b\u00b9 y x :=\ninv_symm_left_iff.2\n\n/-- `a` semiconjugates `x` to `a * x * a\u207b\u00b9`. -/\n@[to_additive \"`a` semiconjugates `x` to `a + x + -a`.\"]\nlemma conj_mk (a x : G) : semiconj_by a x (a * x * a\u207b\u00b9) :=\nby unfold semiconj_by; rw [mul_assoc, inv_mul_self, mul_one]\n\nend group\n\nend semiconj_by\n\n@[simp, to_additive add_semiconj_by_iff_eq]\nlemma semiconj_by_iff_eq {M : Type u} [cancel_comm_monoid M] {a x y : M} :\n  semiconj_by a x y \u2194 x = y :=\n\u27e8\u03bb h, mul_left_cancel (h.trans (mul_comm _ _)), \u03bb h, by rw [h, semiconj_by, mul_comm] \u27e9\n\n/-- `a` semiconjugates `x` to `a * x * a\u207b\u00b9`. -/\n@[to_additive \"`a` semiconjugates `x` to `a + x + -a`.\"]\nlemma units.mk_semiconj_by {M : Type u} [monoid M] (u : M\u02e3) (x : M) :\n  semiconj_by \u2191u x (u * x * \u2191u\u207b\u00b9) :=\nby unfold semiconj_by; rw [units.inv_mul_cancel_right]\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/group/semiconj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7160210941423765}}
{"text": "import lib.m154\n\n/-\nCe fichier concerne la d\u00e9finition de limite d'une suite (de nombres r\u00e9els).\nUne suite u est une fonction de \u2115 dans \u211d, Lean \u00e9crit donc u : \u2115 \u2192 \u211d\n-/\n\n-- D\u00e9finition de \u00ab u tend vers l \u00bb\ndef limite_suite (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\n/-\nOn notera dans la d\u00e9finition ci-dessus l'utilisation de \u00ab \u2200 \u03b5 > 0, ... \u00bb\nqui est une abbr\u00e9viation de \u00ab \u2200 \u03b5, \u03b5 > 0 \u2192 ... \u00bb.\n\nEn particulier un \u00e9nonc\u00e9 de la forme \u00ab h : \u2200 \u03b5 > 0, ... \u00bb se sp\u00e9cialise \u00e0\nun \u03b5\u2080 fix\u00e9 par la commande \u00ab Par h on obtient \u03b5\u2080 tel que h\u03b5\u2080 \u00bb o\u00f9 h\u03b5\u2080 est\nune d\u00e9monstration de \u03b5\u2080 > 0.\n\nLe lemme demi_pos ci-dessous sera utile pour transformer une d\u00e9monstration\nde \u03b5 > 0 en une d\u00e9monstration de \u03b5/2 > 0 lorsque l'on sp\u00e9cialise un \u00e9nonc\u00e9\navec \u03b5/2 au lieu de \u03b5.\n\nLa d\u00e9monstration n'est pas tr\u00e8s \u00e9clairante car Lean fait le travail\nautomatiquement, mais c'est l'occasion de rappeler que la commande\n`On conclut` accepte ce type de travail d'ajustement tr\u00e8s direct.\n-/\n\nlemma demi_pos { \u03b5 : \u211d } : \u03b5 > 0 \u2192 \u03b5/2 > 0 :=\nbegin\n  Supposons hyp : \u03b5 > 0,\n  On conclut par hyp,\nend\n\n-- Dans toute la suite, u, v et w sont des suites tandis que l et l' sont des\n-- nombres r\u00e9els\nvariables (u v w : \u2115 \u2192 \u211d) (l l' : \u211d)\n\n-- Si u est constante de valeur l, alors u tend vers l\nexample : (\u2200 n, u n = l) \u2192 limite_suite u l :=\nbegin\n  sorry\nend\n\n/- Concernant les valeurs absolues, on pourra utiliser les lemmes\n\n`abs_inferieur_ssi (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y`\n\n`ineg_triangle (x y : \u211d) : |x + y| \u2264 |x| + |y|`\n\n`abs_diff (x y : \u211d) : |x - y| = |y - x|`\n\nIl est conseill\u00e9 de noter ces lemmes sur une feuille car ils\npeuvent \u00eatre utiles dans chaque exercice.\n-/\n\n-- Si u tend vers l strictement positif, alors u n \u2265 l/2 pour n assez grand.\nexample (hl : l > 0) : limite_suite u l \u2192 \u2203 N, \u2200 n \u2265 N, u n \u2265 l/2 :=\nbegin\n  sorry\nend\n\n/- Concernant le maximum de deux nombres, on pourra utiliser les lemmes\n\n`superieur_max_ssi (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q`\n\n`inferieur_max_gauche p q : p \u2264 max p q`\n\n`inferieur_max_droite p q : q \u2264 max p q`\n\nIl est conseill\u00e9 de noter ces lemmes sur une feuille car ils\npeuvent \u00eatre utiles dans chaque exercice.\n\nDans l'exemple suivant, notez particuli\u00e8rement la fa\u00e7on dont\n`demi_pos` est utilis\u00e9 : sachant que `\u03b5` est fix\u00e9 et qu'on a une\nhypoth\u00e8se `\u03b5_pos : \u03b5 > 0`, on peut former l'expression\n`demi_pos \u03b5_pos : \u03b5/2 > 0`.\n\nNotez aussi l'utilisation de `superieur_max_ssi` qui reviendra\ntr\u00e8s souvent, et la fa\u00e7on d'annoncer \u00e0 l'avance des in\u00e9galit\u00e9s\ninterm\u00e9diaire avant de la combiner par `On combine`.\n-/\n\n-- Si u tend vers l et v tend vers l' alors u+v tend vers l+l'\nexample (hu : limite_suite u l) (hv : limite_suite v l') :\nlimite_suite (u + v) (l + l') :=\nbegin\n  Soit \u03b5 > 0,\n  Par hu appliqu\u00e9 \u00e0 [\u03b5/2, demi_pos \u03b5_pos] on obtient N\u2081\n      tel que hN\u2081 : \u2200 n \u2265 N\u2081, |u n - l| \u2264 \u03b5 / 2,\n  Par hv appliqu\u00e9 \u00e0 [\u03b5/2, demi_pos \u03b5_pos] on obtient N\u2082\n      tel que hN\u2082 : \u2200 n \u2265 N\u2082, |v n - l'| \u2264 \u03b5 / 2,\n  Montrons que max N\u2081 N\u2082 convient : \u2200 n \u2265 max N\u2081 N\u2082, |(u + v) n - (l + l')| \u2264 \u03b5,\n  Soit n \u2265 max N\u2081 N\u2082,\n  On r\u00e9\u00e9crit via superieur_max_ssi dans n_ge,\n  Par n_ge on obtient (hn\u2081 : n \u2265 N\u2081) (hn\u2082 : n \u2265 N\u2082),\n  Fait fait\u2081 : |u n - l| \u2264 \u03b5/2,\n    On applique hN\u2081,\n  Fait fait\u2082 : |v n - l'| \u2264 \u03b5/2,\n    On conclut par hN\u2082 appliqu\u00e9 \u00e0 [n, hn\u2082],  -- Notez la variante Lean par rapport \u00e0 fait\u2081\n  calc\n  |(u + v) n - (l + l')| = |(u n - l) + (v n - l')| : by On calcule\n                     ... \u2264 |u n - l| + |v n - l'| : by On applique ineg_triangle\n                     ... \u2264  \u03b5/2 + \u03b5/2             : by On combine [fait\u2081, fait\u2082]\n                     ... =  \u03b5                     : by On calcule,\nend\n\nexample (hu : limite_suite u l) (hw : limite_suite w l)\n(h : \u2200 n, u n \u2264 v n)\n(h' : \u2200 n, v n \u2264 w n) : limite_suite v l :=\nbegin\n  sorry\n\nend\n\n-- La derni\u00e8re in\u00e9galit\u00e9 dans la d\u00e9finition de limite peut \u00eatre remplac\u00e9e par\n-- une in\u00e9galit\u00e9 stricte.\nexample (u l) : limite_suite u l \u2194\n \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5 :=\nbegin\n  sorry\nend\n\n/- Dans l'exercice suivant, on pourra utiliser le lemme\n\n`egal_si_abs_eps (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y`\n-/\n\n-- Une suite u admet au plus une limite\nexample : limite_suite u l \u2192 limite_suite u l' \u2192 l = l' :=\nbegin\n  sorry\nend\n\n-- D\u00e9finition de \u00ab la suite u est croissante \u00bb\ndef croissante (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- D\u00e9finition de \u00ab M est borne sup\u00e9rieure des termes de la suite u  \u00bb\ndef est_borne_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n-- Toute suite croissante ayant une borne sup\u00e9rieure tend vers cette borne\nexample (M : \u211d) (h : est_borne_sup M u) (h' : croissante u) :\nlimite_suite u M :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "PatrickMassot", "repo": "MDD154", "sha": "00defe82a4b6b7992ed522a92f62abd685e8c943", "save_path": "github-repos/lean/PatrickMassot-MDD154", "path": "github-repos/lean/PatrickMassot-MDD154/MDD154-00defe82a4b6b7992ed522a92f62abd685e8c943/src/05_limite_suite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.7160210856525914}}
{"text": "/-\nCopyright (c) 2019 Michael Howes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Howes\n\n! This file was ported from Lean 3 source module group_theory.presented_group\n! leanprover-community/mathlib commit d90e4e186f1d18e375dcd4e5b5f6364b01cb3e46\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.GroupTheory.FreeGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n/-!\n# Defining a group given by generators and relations\n\nGiven a subset `rels` of relations of the free group on a type `\u03b1`, this file constructs the group\ngiven by generators `x : \u03b1` and relations `r \u2208 rels`.\n\n## Main definitions\n\n* `PresentedGroup rels`: the quotient group of the free group on a type `\u03b1` by a subset `rels` of\n  relations of the free group on `\u03b1`.\n* `of`: The canonical map from `\u03b1` to a presented group with generators `\u03b1`.\n* `toGroup f`: the canonical group homomorphism `PresentedGroup rels \u2192 G`, given a function\n  `f : \u03b1 \u2192 G` from a type `\u03b1` to a group `G` which satisfies the relations `rels`.\n\n## Tags\n\ngenerators, relations, group presentations\n-/\n\n\nvariable {\u03b1 : Type _}\n\n/-- Given a set of relations, `rels`, over a type `\u03b1`, `PresentedGroup` constructs the group with\ngenerators `x : \u03b1` and relations `rels` as a quotient of `FreeGroup \u03b1`. -/\ndef PresentedGroup (rels : Set (FreeGroup \u03b1)) :=\n  FreeGroup \u03b1 \u29f8 Subgroup.normalClosure rels\n#align presented_group PresentedGroup\n\nnamespace PresentedGroup\n\ninstance (rels : Set (FreeGroup \u03b1)) : Group (PresentedGroup rels) :=\n  QuotientGroup.Quotient.group _\n\n/-- `of` is the canonical map from `\u03b1` to a presented group with generators `x : \u03b1`. The term `x` is\nmapped to the equivalence class of the image of `x` in `FreeGroup \u03b1`. -/\ndef of {rels : Set (FreeGroup \u03b1)} (x : \u03b1) : PresentedGroup rels :=\n  QuotientGroup.mk (FreeGroup.of x)\n#align presented_group.of PresentedGroup.of\n\nsection ToGroup\n\n/-\nPresented groups satisfy a universal property. If `G` is a group and `f : \u03b1 \u2192 G` is a map such that\nthe images of `f` satisfy all the given relations, then `f` extends uniquely to a group homomorphism\nfrom `PresentedGroup rels` to `G`.\n-/\nvariable {G : Type _} [Group G] {f : \u03b1 \u2192 G} {rels : Set (FreeGroup \u03b1)}\n\n-- mathport name: exprF\nlocal notation \"F\" => FreeGroup.lift f\n\n-- Porting note: `F` has been expanded, because `F r = 1` produces a sorry.\nvariable (h : \u2200 r \u2208 rels, FreeGroup.lift f r = 1)\n\ntheorem closure_rels_subset_ker : Subgroup.normalClosure rels \u2264 MonoidHom.ker F :=\n  Subgroup.normalClosure_le_normal fun x w \u21a6 (MonoidHom.mem_ker _).2 (h x w)\n#align presented_group.closure_rels_subset_ker PresentedGroup.closure_rels_subset_ker\n\ntheorem to_group_eq_one_of_mem_closure : \u2200 x \u2208 Subgroup.normalClosure rels, F x = 1 :=\n  fun _ w \u21a6 (MonoidHom.mem_ker _).1 <| closure_rels_subset_ker h w\n#align presented_group.to_group_eq_one_of_mem_closure PresentedGroup.to_group_eq_one_of_mem_closure\n\n/-- The extension of a map `f : \u03b1 \u2192 G` that satisfies the given relations to a group homomorphism\nfrom `PresentedGroup rels \u2192 G`. -/\ndef toGroup : PresentedGroup rels \u2192* G :=\n  QuotientGroup.lift (Subgroup.normalClosure rels) F (to_group_eq_one_of_mem_closure h)\n#align presented_group.to_group PresentedGroup.toGroup\n\n@[simp]\ntheorem toGroup.of {x : \u03b1} : toGroup h (of x) = f x :=\n  FreeGroup.lift.of\n#align presented_group.to_group.of PresentedGroup.toGroup.of\n\ntheorem toGroup.unique (g : PresentedGroup rels \u2192* G)\n    (hg : \u2200 x : \u03b1, g (PresentedGroup.of x) = f x) : \u2200 {x}, g x = toGroup h x := by\n  intro x\n  refine' QuotientGroup.induction_on x _\n  exact fun _ \u21a6 FreeGroup.lift.unique (g.comp (QuotientGroup.mk' _)) hg\n#align presented_group.to_group.unique PresentedGroup.toGroup.unique\n\nend ToGroup\n\ninstance (rels : Set (FreeGroup \u03b1)) : Inhabited (PresentedGroup rels) :=\n  \u27e81\u27e9\n\nend PresentedGroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/PresentedGroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.716021081055601}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Patrick Stevens\n\n! This file was ported from Lean 3 source module data.nat.choose.dvd\n! leanprover-community/mathlib commit 966e0cf0685c9cedf8a3283ac69eef4d5f2eaca2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Prime\n\n/-!\n# Divisibility properties of binomial coefficients\n-/\n\n\nnamespace Nat\n\nopen Nat\n\nnamespace Prime\n\nvariable {p a b k : \u2115}\n\ntheorem dvd_choose_add (hp : Prime p) (hap : a < p) (hbp : b < p) (h : p \u2264 a + b) :\n    p \u2223 choose (a + b) a := by\n  have h\u2081 : p \u2223 (a + b)! := hp.dvd_factorial.2 h\n  rw [\u2190 add_choose_mul_factorial_mul_factorial, \u2190 choose_symm_add, hp.dvd_mul, hp.dvd_mul,\n    hp.dvd_factorial, hp.dvd_factorial] at h\u2081\n  exact (h\u2081.resolve_right hbp.not_le).resolve_right hap.not_le\n#align nat.prime.dvd_choose_add Nat.Prime.dvd_choose_add\n\nlemma dvd_choose (hp : Prime p) (ha : a < p) (hab : b - a < p) (h : p \u2264 b) : p \u2223 choose b a :=\n  have : a + (b - a) = b := Nat.add_sub_of_le (ha.le.trans h)\n  this \u25b8 hp.dvd_choose_add ha hab (this.symm \u25b8 h)\n#align nat.prime.dvd_choose Nat.Prime.dvd_choose\n\nlemma dvd_choose_self (hp : Prime p) (hk : k \u2260 0) (hkp : k < p) : p \u2223 choose p k :=\n  hp.dvd_choose hkp (sub_lt ((zero_le _).trans_lt hkp) hk.bot_lt) le_rfl\n#align nat.prime.dvd_choose_self Nat.Prime.dvd_choose_self\n\nend Prime\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Choose/Dvd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7160210791092035}}
{"text": "import algebra.big_operators\nimport analysis.specific_limits\n\n-- Sum of a Geometric Series\n\nopen finset\n\ntheorem t066_finite {\u03b1} [division_ring \u03b1] {x : \u03b1} : \u03a0 (h : x \u2260 1) (n : \u2115),\n  (range n).sum (\u03bb i, x^i) = (x^n-1)/(x-1)\n:= geom_sum\n\nlemma t066_infinite {r : \u211d} : \u03a0 (h\u2081 : 0 \u2264 r) (h\u2082 : r < 1),\n  has_sum (\u03bbn:\u2115, r ^ n) (1 - r)\u207b\u00b9\n:= has_sum_geometric\n", "meta": {"author": "AtnNn", "repo": "lean-sandbox", "sha": "8c68afbdc09213173aef1be195da7a9a86060a97", "save_path": "github-repos/lean/AtnNn-lean-sandbox", "path": "github-repos/lean/AtnNn-lean-sandbox/lean-sandbox-8c68afbdc09213173aef1be195da7a9a86060a97/src/100_theorems/t066.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7160210745853348}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Stoll\n\n! This file was ported from Lean 3 source module number_theory.legendre_symbol.quadratic_char\n! leanprover-community/mathlib commit d11893b411025250c8e61ff2f12ccbd7ee35ab15\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Fintype.Parity\nimport Mathbin.NumberTheory.LegendreSymbol.ZmodChar\nimport Mathbin.FieldTheory.Finite.Basic\nimport Mathbin.NumberTheory.LegendreSymbol.GaussSum\n\n/-!\n# Quadratic characters of finite fields\n\nThis file defines the quadratic character on a finite field `F` and proves\nsome basic statements about it.\n\n## Tags\n\nquadratic character\n-/\n\n\n/-!\n### Definition of the quadratic character\n\nWe define the quadratic character of a finite field `F` with values in \u2124.\n-/\n\n\nsection Define\n\n/-- Define the quadratic character with values in \u2124 on a monoid with zero `\u03b1`.\nIt takes the value zero at zero; for non-zero argument `a : \u03b1`, it is `1`\nif `a` is a square, otherwise it is `-1`.\n\nThis only deserves the name \"character\" when it is multiplicative,\ne.g., when `\u03b1` is a finite field. See `quadratic_char_fun_mul`.\n\nWe will later define `quadratic_char` to be a multiplicative character\nof type `mul_char F \u2124`, when the domain is a finite field `F`.\n-/\ndef quadraticCharFun (\u03b1 : Type _) [MonoidWithZero \u03b1] [DecidableEq \u03b1]\n    [DecidablePred (IsSquare : \u03b1 \u2192 Prop)] (a : \u03b1) : \u2124 :=\n  if a = 0 then 0 else if IsSquare a then 1 else -1\n#align quadratic_char_fun quadraticCharFun\n\nend Define\n\n/-!\n### Basic properties of the quadratic character\n\nWe prove some properties of the quadratic character.\nWe work with a finite field `F` here.\nThe interesting case is when the characteristic of `F` is odd.\n-/\n\n\nsection quadraticChar\n\nopen MulChar\n\nvariable {F : Type _} [Field F] [Fintype F] [DecidableEq F]\n\n/-- Some basic API lemmas -/\ntheorem quadraticCharFun_eq_zero_iff {a : F} : quadraticCharFun F a = 0 \u2194 a = 0 :=\n  by\n  simp only [quadraticCharFun]\n  by_cases ha : a = 0\n  \u00b7 simp only [ha, eq_self_iff_true, if_true]\n  \u00b7 simp only [ha, if_false, iff_false_iff]\n    split_ifs <;> simp only [neg_eq_zero, one_ne_zero, not_false_iff]\n#align quadratic_char_fun_eq_zero_iff quadraticCharFun_eq_zero_iff\n\n@[simp]\ntheorem quadraticCharFun_zero : quadraticCharFun F 0 = 0 := by\n  simp only [quadraticCharFun, eq_self_iff_true, if_true, id.def]\n#align quadratic_char_fun_zero quadraticCharFun_zero\n\n@[simp]\ntheorem quadraticCharFun_one : quadraticCharFun F 1 = 1 := by\n  simp only [quadraticCharFun, one_ne_zero, isSquare_one, if_true, if_false, id.def]\n#align quadratic_char_fun_one quadraticCharFun_one\n\n/-- If `ring_char F = 2`, then `quadratic_char_fun F` takes the value `1` on nonzero elements. -/\ntheorem quadraticCharFun_eq_one_of_char_two (hF : ringChar F = 2) {a : F} (ha : a \u2260 0) :\n    quadraticCharFun F a = 1 :=\n  by\n  simp only [quadraticCharFun, ha, if_false, ite_eq_left_iff]\n  exact fun h => False.ndrec _ (h (FiniteField.isSquare_of_char_two hF a))\n#align quadratic_char_fun_eq_one_of_char_two quadraticCharFun_eq_one_of_char_two\n\n/-- If `ring_char F` is odd, then `quadratic_char_fun F a` can be computed in\nterms of `a ^ (fintype.card F / 2)`. -/\ntheorem quadraticCharFun_eq_pow_of_char_ne_two (hF : ringChar F \u2260 2) {a : F} (ha : a \u2260 0) :\n    quadraticCharFun F a = if a ^ (Fintype.card F / 2) = 1 then 1 else -1 :=\n  by\n  simp only [quadraticCharFun, ha, if_false]\n  simp_rw [FiniteField.isSquare_iff hF ha]\n#align quadratic_char_fun_eq_pow_of_char_ne_two quadraticCharFun_eq_pow_of_char_ne_two\n\n/-- The quadratic character is multiplicative. -/\ntheorem quadraticCharFun_mul (a b : F) :\n    quadraticCharFun F (a * b) = quadraticCharFun F a * quadraticCharFun F b :=\n  by\n  by_cases ha : a = 0\n  \u00b7 rw [ha, MulZeroClass.zero_mul, quadraticCharFun_zero, MulZeroClass.zero_mul]\n  -- now `a \u2260 0`\n  by_cases hb : b = 0\n  \u00b7 rw [hb, MulZeroClass.mul_zero, quadraticCharFun_zero, MulZeroClass.mul_zero]\n  -- now `a \u2260 0` and `b \u2260 0`\n  have hab := mul_ne_zero ha hb\n  by_cases hF : ringChar F = 2\n  \u00b7-- case `ring_char F = 2`\n    rw [quadraticCharFun_eq_one_of_char_two hF ha, quadraticCharFun_eq_one_of_char_two hF hb,\n      quadraticCharFun_eq_one_of_char_two hF hab, mul_one]\n  \u00b7 -- case of odd characteristic\n    rw [quadraticCharFun_eq_pow_of_char_ne_two hF ha, quadraticCharFun_eq_pow_of_char_ne_two hF hb,\n      quadraticCharFun_eq_pow_of_char_ne_two hF hab, mul_pow]\n    cases' FiniteField.pow_dichotomy hF hb with hb' hb'\n    \u00b7 simp only [hb', mul_one, eq_self_iff_true, if_true]\n    \u00b7 have h := Ring.neg_one_ne_one_of_char_ne_two hF\n      -- `-1 \u2260 1`\n      simp only [hb', h, mul_neg, mul_one, if_false, ite_mul, neg_mul]\n      cases' FiniteField.pow_dichotomy hF ha with ha' ha' <;>\n        simp only [ha', h, neg_neg, eq_self_iff_true, if_true, if_false]\n#align quadratic_char_fun_mul quadraticCharFun_mul\n\nvariable (F)\n\n/-- The quadratic character as a multiplicative character. -/\n@[simps]\ndef quadraticChar : MulChar F \u2124 where\n  toFun := quadraticCharFun F\n  map_one' := quadraticCharFun_one\n  map_mul' := quadraticCharFun_mul\n  map_nonunit' a ha := by\n    rw [of_not_not (mt Ne.isUnit ha)]\n    exact quadraticCharFun_zero\n#align quadratic_char quadraticChar\n\nvariable {F}\n\n/-- The value of the quadratic character on `a` is zero iff `a = 0`. -/\ntheorem quadraticChar_eq_zero_iff {a : F} : quadraticChar F a = 0 \u2194 a = 0 :=\n  quadraticCharFun_eq_zero_iff\n#align quadratic_char_eq_zero_iff quadraticChar_eq_zero_iff\n\n@[simp]\ntheorem quadraticChar_zero : quadraticChar F 0 = 0 := by\n  simp only [quadraticChar_apply, quadraticCharFun_zero]\n#align quadratic_char_zero quadraticChar_zero\n\n/-- For nonzero `a : F`, `quadratic_char F a = 1 \u2194 is_square a`. -/\ntheorem quadraticChar_one_iff_isSquare {a : F} (ha : a \u2260 0) : quadraticChar F a = 1 \u2194 IsSquare a :=\n  by\n  simp only [quadraticChar_apply, quadraticCharFun, ha, (by decide : (-1 : \u2124) \u2260 1), if_false,\n    ite_eq_left_iff, imp_false, Classical.not_not]\n#align quadratic_char_one_iff_is_square quadraticChar_one_iff_isSquare\n\n/-- The quadratic character takes the value `1` on nonzero squares. -/\ntheorem quadraticChar_sq_one' {a : F} (ha : a \u2260 0) : quadraticChar F (a ^ 2) = 1 := by\n  simp only [quadraticCharFun, ha, pow_eq_zero_iff, Nat.succ_pos', IsSquare_sq, if_true, if_false,\n    quadraticChar_apply]\n#align quadratic_char_sq_one' quadraticChar_sq_one'\n\n/-- The square of the quadratic character on nonzero arguments is `1`. -/\ntheorem quadraticChar_sq_one {a : F} (ha : a \u2260 0) : quadraticChar F a ^ 2 = 1 := by\n  rwa [pow_two, \u2190 map_mul, \u2190 pow_two, quadraticChar_sq_one']\n#align quadratic_char_sq_one quadraticChar_sq_one\n\n/-- The quadratic character is `1` or `-1` on nonzero arguments. -/\ntheorem quadraticChar_dichotomy {a : F} (ha : a \u2260 0) :\n    quadraticChar F a = 1 \u2228 quadraticChar F a = -1 :=\n  sq_eq_one_iff.1 <| quadraticChar_sq_one ha\n#align quadratic_char_dichotomy quadraticChar_dichotomy\n\n/-- The quadratic character is `1` or `-1` on nonzero arguments. -/\ntheorem quadraticChar_eq_neg_one_iff_not_one {a : F} (ha : a \u2260 0) :\n    quadraticChar F a = -1 \u2194 \u00acquadraticChar F a = 1 :=\n  by\n  refine' \u27e8fun h => _, fun h\u2082 => (or_iff_right h\u2082).mp (quadraticChar_dichotomy ha)\u27e9\n  rw [h]\n  norm_num\n#align quadratic_char_eq_neg_one_iff_not_one quadraticChar_eq_neg_one_iff_not_one\n\n/-- For `a : F`, `quadratic_char F a = -1 \u2194 \u00ac is_square a`. -/\ntheorem quadraticChar_neg_one_iff_not_isSquare {a : F} : quadraticChar F a = -1 \u2194 \u00acIsSquare a :=\n  by\n  by_cases ha : a = 0\n  \u00b7 simp only [ha, isSquare_zero, MulChar.map_zero, zero_eq_neg, one_ne_zero, not_true]\n  \u00b7 rw [quadraticChar_eq_neg_one_iff_not_one ha, quadraticChar_one_iff_isSquare ha]\n#align quadratic_char_neg_one_iff_not_is_square quadraticChar_neg_one_iff_not_isSquare\n\n/-- If `F` has odd characteristic, then `quadratic_char F` takes the value `-1`. -/\ntheorem quadraticChar_exists_neg_one (hF : ringChar F \u2260 2) : \u2203 a, quadraticChar F a = -1 :=\n  (FiniteField.exists_nonsquare hF).imp fun b h\u2081 => quadraticChar_neg_one_iff_not_isSquare.mpr h\u2081\n#align quadratic_char_exists_neg_one quadraticChar_exists_neg_one\n\n/-- If `ring_char F = 2`, then `quadratic_char F` takes the value `1` on nonzero elements. -/\ntheorem quadraticChar_eq_one_of_char_two (hF : ringChar F = 2) {a : F} (ha : a \u2260 0) :\n    quadraticChar F a = 1 :=\n  quadraticCharFun_eq_one_of_char_two hF ha\n#align quadratic_char_eq_one_of_char_two quadraticChar_eq_one_of_char_two\n\n/-- If `ring_char F` is odd, then `quadratic_char F a` can be computed in\nterms of `a ^ (fintype.card F / 2)`. -/\ntheorem quadraticChar_eq_pow_of_char_ne_two (hF : ringChar F \u2260 2) {a : F} (ha : a \u2260 0) :\n    quadraticChar F a = if a ^ (Fintype.card F / 2) = 1 then 1 else -1 :=\n  quadraticCharFun_eq_pow_of_char_ne_two hF ha\n#align quadratic_char_eq_pow_of_char_ne_two quadraticChar_eq_pow_of_char_ne_two\n\ntheorem quadraticChar_eq_pow_of_char_ne_two' (hF : ringChar F \u2260 2) (a : F) :\n    (quadraticChar F a : F) = a ^ (Fintype.card F / 2) :=\n  by\n  by_cases ha : a = 0\n  \u00b7 have : 0 < Fintype.card F / 2 := Nat.div_pos Fintype.one_lt_card two_pos\n    simp only [ha, zero_pow this, quadraticChar_apply, quadraticChar_zero, Int.cast_zero]\n  \u00b7 rw [quadraticChar_eq_pow_of_char_ne_two hF ha]\n    by_cases ha' : a ^ (Fintype.card F / 2) = 1\n    \u00b7 simp only [ha', eq_self_iff_true, if_true, Int.cast_one]\n    \u00b7 have ha'' := Or.resolve_left (FiniteField.pow_dichotomy hF ha) ha'\n      simp only [ha'', Int.cast_ite, Int.cast_one, Int.cast_neg, ite_eq_right_iff]\n      exact Eq.symm\n#align quadratic_char_eq_pow_of_char_ne_two' quadraticChar_eq_pow_of_char_ne_two'\n\nvariable (F)\n\n/-- The quadratic character is quadratic as a multiplicative character. -/\ntheorem quadraticChar_isQuadratic : (quadraticChar F).IsQuadratic :=\n  by\n  intro a\n  by_cases ha : a = 0\n  \u00b7 left\n    rw [ha]\n    exact quadraticChar_zero\n  \u00b7 right\n    exact quadraticChar_dichotomy ha\n#align quadratic_char_is_quadratic quadraticChar_isQuadratic\n\nvariable {F}\n\n/-- The quadratic character is nontrivial as a multiplicative character\nwhen the domain has odd characteristic. -/\ntheorem quadraticChar_isNontrivial (hF : ringChar F \u2260 2) : (quadraticChar F).IsNontrivial :=\n  by\n  rcases quadraticChar_exists_neg_one hF with \u27e8a, ha\u27e9\n  have hu : IsUnit a := by\n    by_contra hf\n    rw [map_nonunit _ hf] at ha\n    norm_num at ha\n  refine' \u27e8hu.unit, (_ : quadraticChar F a \u2260 1)\u27e9\n  rw [ha]\n  norm_num\n#align quadratic_char_is_nontrivial quadraticChar_isNontrivial\n\n/-- The number of solutions to `x^2 = a` is determined by the quadratic character. -/\ntheorem quadraticChar_card_sqrts (hF : ringChar F \u2260 2) (a : F) :\n    \u2191{ x : F | x ^ 2 = a }.toFinset.card = quadraticChar F a + 1 :=\n  by\n  -- we consider the cases `a = 0`, `a` is a nonzero square and `a` is a nonsquare in turn\n  by_cases h\u2080 : a = 0\n  \u00b7\n    simp only [h\u2080, pow_eq_zero_iff, Nat.succ_pos', Int.ofNat_succ, Int.ofNat_zero, MulChar.map_zero,\n      Set.setOf_eq_eq_singleton, Set.toFinset_card, Set.card_singleton]\n  \u00b7 set s := { x : F | x ^ 2 = a }.toFinset with hs\n    by_cases h : IsSquare a\n    \u00b7 rw [(quadraticChar_one_iff_isSquare h\u2080).mpr h]\n      rcases h with \u27e8b, h\u27e9\n      rw [h, mul_self_eq_zero] at h\u2080\n      have h\u2081 : s = [b, -b].toFinset := by\n        ext x\n        simp only [Finset.mem_filter, Finset.mem_univ, true_and_iff, List.toFinset_cons,\n          List.toFinset_nil, insert_emptyc_eq, Finset.mem_insert, Finset.mem_singleton]\n        rw [\u2190 pow_two] at h\n        simp only [hs, Set.mem_toFinset, Set.mem_setOf_eq, h]\n        constructor\n        \u00b7 exact eq_or_eq_neg_of_sq_eq_sq _ _\n        \u00b7 rintro (h\u2082 | h\u2082) <;> rw [h\u2082]\n          simp only [neg_sq]\n      norm_cast\n      rw [h\u2081, List.toFinset_cons, List.toFinset_cons, List.toFinset_nil]\n      exact Finset.card_doubleton (Ne.symm (mt (Ring.eq_self_iff_eq_zero_of_char_ne_two hF).mp h\u2080))\n    \u00b7 rw [quadratic_char_neg_one_iff_not_is_square.mpr h]\n      simp only [Int.coe_nat_eq_zero, Finset.card_eq_zero, Set.toFinset_card, Fintype.card_ofFinset,\n        Set.mem_setOf_eq, add_left_neg]\n      ext x\n      simp only [iff_false_iff, Finset.mem_filter, Finset.mem_univ, true_and_iff,\n        Finset.not_mem_empty]\n      rw [isSquare_iff_exists_sq] at h\n      exact fun h' => h \u27e8_, h'.symm\u27e9\n#align quadratic_char_card_sqrts quadraticChar_card_sqrts\n\nopen BigOperators\n\n/-- The sum over the values of the quadratic character is zero when the characteristic is odd. -/\ntheorem quadraticChar_sum_zero (hF : ringChar F \u2260 2) : (\u2211 a : F, quadraticChar F a) = 0 :=\n  IsNontrivial.sum_eq_zero (quadraticChar_isNontrivial hF)\n#align quadratic_char_sum_zero quadraticChar_sum_zero\n\nend quadraticChar\n\n/-!\n### Special values of the quadratic character\n\nWe express `quadratic_char F (-1)` in terms of `\u03c7\u2084`.\n-/\n\n\nsection SpecialValues\n\nopen ZMod MulChar\n\nvariable {F : Type _} [Field F] [Fintype F]\n\n/-- The value of the quadratic character at `-1` -/\ntheorem quadraticChar_neg_one [DecidableEq F] (hF : ringChar F \u2260 2) :\n    quadraticChar F (-1) = \u03c7\u2084 (Fintype.card F) :=\n  by\n  have h := quadraticChar_eq_pow_of_char_ne_two hF (neg_ne_zero.mpr one_ne_zero)\n  rw [h, \u03c7\u2084_eq_neg_one_pow (FiniteField.odd_card_of_char_ne_two hF)]\n  set n := Fintype.card F / 2\n  cases' Nat.even_or_odd n with h\u2082 h\u2082\n  \u00b7 simp only [Even.neg_one_pow h\u2082, eq_self_iff_true, if_true]\n  \u00b7 simp only [Odd.neg_one_pow h\u2082, ite_eq_right_iff]\n    exact fun hf => False.ndrec (1 = -1) (Ring.neg_one_ne_one_of_char_ne_two hF hf)\n#align quadratic_char_neg_one quadraticChar_neg_one\n\n/-- `-1` is a square in `F` iff `#F` is not congruent to `3` mod `4`. -/\ntheorem FiniteField.isSquare_neg_one_iff : IsSquare (-1 : F) \u2194 Fintype.card F % 4 \u2260 3 := by\n  classical\n    -- suggested by the linter (instead of `[decidable_eq F]`)\n    by_cases hF : ringChar F = 2\n    \u00b7 simp only [FiniteField.isSquare_of_char_two hF, Ne.def, true_iff_iff]\n      exact fun hf =>\n        one_ne_zero <|\n          (Nat.odd_of_mod_four_eq_three hf).symm.trans <| FiniteField.even_card_of_char_two hF\n    \u00b7 have h\u2081 := FiniteField.odd_card_of_char_ne_two hF\n      rw [\u2190 quadraticChar_one_iff_isSquare (neg_ne_zero.mpr (one_ne_zero' F)),\n        quadraticChar_neg_one hF, \u03c7\u2084_nat_eq_if_mod_four, h\u2081]\n      simp only [Nat.one_ne_zero, if_false, ite_eq_left_iff, Ne.def, (by decide : (-1 : \u2124) \u2260 1),\n        imp_false, Classical.not_not]\n      exact\n        \u27e8fun h => ne_of_eq_of_ne h (by decide : 1 \u2260 3),\n          Or.resolve_right (nat.odd_mod_four_iff.mp h\u2081)\u27e9\n#align finite_field.is_square_neg_one_iff FiniteField.isSquare_neg_one_iff\n\n/-- The value of the quadratic character at `2` -/\ntheorem quadraticChar_two [DecidableEq F] (hF : ringChar F \u2260 2) :\n    quadraticChar F 2 = \u03c7\u2088 (Fintype.card F) :=\n  IsQuadratic.eq_of_eq_coe (quadraticChar_isQuadratic F) isQuadratic_\u03c7\u2088 hF\n    ((quadraticChar_eq_pow_of_char_ne_two' hF 2).trans (FiniteField.two_pow_card hF))\n#align quadratic_char_two quadraticChar_two\n\n/-- `2` is a square in `F` iff `#F` is not congruent to `3` or `5` mod `8`. -/\ntheorem FiniteField.isSquare_two_iff :\n    IsSquare (2 : F) \u2194 Fintype.card F % 8 \u2260 3 \u2227 Fintype.card F % 8 \u2260 5 := by\n  classical\n    by_cases hF : ringChar F = 2\n    focus\n      have h := FiniteField.even_card_of_char_two hF\n      simp only [FiniteField.isSquare_of_char_two hF, true_iff_iff]\n    rotate_left\n    focus\n      have h := FiniteField.odd_card_of_char_ne_two hF\n      rw [\u2190 quadraticChar_one_iff_isSquare (Ring.two_ne_zero hF), quadraticChar_two hF,\n        \u03c7\u2088_nat_eq_if_mod_eight]\n      simp only [h, Nat.one_ne_zero, if_false, ite_eq_left_iff, Ne.def, (by decide : (-1 : \u2124) \u2260 1),\n        imp_false, Classical.not_not]\n    all_goals\n      rw [\u2190 Nat.mod_mod_of_dvd _ (by norm_num : 2 \u2223 8)] at h\n      have h\u2081 := Nat.mod_lt (Fintype.card F) (by decide : 0 < 8)\n      revert h\u2081 h\n      generalize Fintype.card F % 8 = n\n      decide!\n#align finite_field.is_square_two_iff FiniteField.isSquare_two_iff\n\n/-- The value of the quadratic character at `-2` -/\ntheorem quadraticChar_neg_two [DecidableEq F] (hF : ringChar F \u2260 2) :\n    quadraticChar F (-2) = \u03c7\u2088' (Fintype.card F) := by\n  rw [(by norm_num : (-2 : F) = -1 * 2), map_mul, \u03c7\u2088'_eq_\u03c7\u2084_mul_\u03c7\u2088, quadraticChar_neg_one hF,\n    quadraticChar_two hF, @cast_nat_cast _ (ZMod 4) _ _ _ (by norm_num : 4 \u2223 8)]\n#align quadratic_char_neg_two quadraticChar_neg_two\n\n/-- `-2` is a square in `F` iff `#F` is not congruent to `5` or `7` mod `8`. -/\ntheorem FiniteField.isSquare_neg_two_iff :\n    IsSquare (-2 : F) \u2194 Fintype.card F % 8 \u2260 5 \u2227 Fintype.card F % 8 \u2260 7 := by\n  classical\n    by_cases hF : ringChar F = 2\n    focus\n      have h := FiniteField.even_card_of_char_two hF\n      simp only [FiniteField.isSquare_of_char_two hF, true_iff_iff]\n    rotate_left\n    focus\n      have h := FiniteField.odd_card_of_char_ne_two hF\n      rw [\u2190 quadraticChar_one_iff_isSquare (neg_ne_zero.mpr (Ring.two_ne_zero hF)),\n        quadraticChar_neg_two hF, \u03c7\u2088'_nat_eq_if_mod_eight]\n      simp only [h, Nat.one_ne_zero, if_false, ite_eq_left_iff, Ne.def, (by decide : (-1 : \u2124) \u2260 1),\n        imp_false, Classical.not_not]\n    all_goals\n      rw [\u2190 Nat.mod_mod_of_dvd _ (by norm_num : 2 \u2223 8)] at h\n      have h\u2081 := Nat.mod_lt (Fintype.card F) (by decide : 0 < 8)\n      revert h\u2081 h\n      generalize Fintype.card F % 8 = n\n      decide!\n#align finite_field.is_square_neg_two_iff FiniteField.isSquare_neg_two_iff\n\n/-- The relation between the values of the quadratic character of one field `F` at the\ncardinality of another field `F'` and of the quadratic character of `F'` at the cardinality\nof `F`. -/\ntheorem quadraticChar_card_card [DecidableEq F] (hF : ringChar F \u2260 2) {F' : Type _} [Field F']\n    [Fintype F'] [DecidableEq F'] (hF' : ringChar F' \u2260 2) (h : ringChar F' \u2260 ringChar F) :\n    quadraticChar F (Fintype.card F') = quadraticChar F' (quadraticChar F (-1) * Fintype.card F) :=\n  by\n  let \u03c7 := (quadraticChar F).ringHomComp (algebraMap \u2124 F')\n  have h\u03c7\u2081 : \u03c7.is_nontrivial :=\n    by\n    obtain \u27e8a, ha\u27e9 := quadraticChar_exists_neg_one hF\n    have hu : IsUnit a := by\n      contrapose ha\n      exact ne_of_eq_of_ne (map_nonunit (quadraticChar F) ha) (mt zero_eq_neg.mp one_ne_zero)\n    use hu.unit\n    simp only [IsUnit.unit_spec, ring_hom_comp_apply, eq_intCast, Ne.def, ha]\n    rw [Int.cast_neg, Int.cast_one]\n    exact Ring.neg_one_ne_one_of_char_ne_two hF'\n  have h\u03c7\u2082 : \u03c7.is_quadratic := is_quadratic.comp (quadraticChar_isQuadratic F) _\n  have h := Char.card_pow_card h\u03c7\u2081 h\u03c7\u2082 h hF'\n  rw [\u2190 quadraticChar_eq_pow_of_char_ne_two' hF'] at h\n  exact\n    (is_quadratic.eq_of_eq_coe (quadraticChar_isQuadratic F') (quadraticChar_isQuadratic F) hF'\n        h).symm\n#align quadratic_char_card_card quadraticChar_card_card\n\n/-- The value of the quadratic character at an odd prime `p` different from `ring_char F`. -/\ntheorem quadraticChar_odd_prime [DecidableEq F] (hF : ringChar F \u2260 2) {p : \u2115} [Fact p.Prime]\n    (hp\u2081 : p \u2260 2) (hp\u2082 : ringChar F \u2260 p) :\n    quadraticChar F p = quadraticChar (ZMod p) (\u03c7\u2084 (Fintype.card F) * Fintype.card F) :=\n  by\n  rw [\u2190 quadraticChar_neg_one hF]\n  have h :=\n    quadraticChar_card_card hF (ne_of_eq_of_ne (ring_char_zmod_n p) hp\u2081)\n      (ne_of_eq_of_ne (ring_char_zmod_n p) hp\u2082.symm)\n  rwa [card p] at h\n#align quadratic_char_odd_prime quadraticChar_odd_prime\n\n/-- An odd prime `p` is a square in `F` iff the quadratic character of `zmod p` does not\ntake the value `-1` on `\u03c7\u2084(#F) * #F`. -/\ntheorem FiniteField.isSquare_odd_prime_iff (hF : ringChar F \u2260 2) {p : \u2115} [Fact p.Prime]\n    (hp : p \u2260 2) :\n    IsSquare (p : F) \u2194 quadraticChar (ZMod p) (\u03c7\u2084 (Fintype.card F) * Fintype.card F) \u2260 -1 := by\n  classical\n    by_cases hFp : ringChar F = p\n    \u00b7 rw [show (p : F) = 0 by\n          rw [\u2190 hFp]\n          exact ringChar.Nat.cast_ringChar]\n      simp only [isSquare_zero, Ne.def, true_iff_iff, map_mul]\n      obtain \u27e8n, _, hc\u27e9 := FiniteField.card F (ringChar F)\n      have hchar : ringChar F = ringChar (ZMod p) :=\n        by\n        rw [hFp]\n        exact (ring_char_zmod_n p).symm\n      conv =>\n        congr\n        lhs\n        congr\n        skip\n        rw [hc, Nat.cast_pow, map_pow, hchar, map_ring_char]\n      simp only [zero_pow n.pos, MulZeroClass.mul_zero, zero_eq_neg, one_ne_zero, not_false_iff]\n    \u00b7 rw [\u2190 Iff.not_left (@quadraticChar_neg_one_iff_not_isSquare F _ _ _ _),\n        quadraticChar_odd_prime hF hp]\n      exact hFp\n#align finite_field.is_square_odd_prime_iff FiniteField.isSquare_odd_prime_iff\n\nend SpecialValues\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/LegendreSymbol/QuadraticChar.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7160126931775668}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport data.sigma.lex\nimport order.bounded_order\n\n/-!\n# Orders on a sigma type\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines two orders on a sigma type:\n* The disjoint sum of orders. `a` is less `b` iff `a` and `b` are in the same summand and `a` is\n  less than `b` there.\n* The lexicographical order. `a` is less than `b` if its summand is strictly less than the summand\n  of `b` or they are in the same summand and `a` is less than `b` there.\n\nWe make the disjoint sum of orders the default set of instances. The lexicographic order goes on a\ntype synonym.\n\n## Notation\n\n* `\u03a3\u2097 i, \u03b1 i`: Sigma type equipped with the lexicographic order. Type synonym of `\u03a3 i, \u03b1 i`.\n\n## See also\n\nRelated files are:\n* `data.finset.colex`: Colexicographic order on finite sets.\n* `data.list.lex`: Lexicographic order on lists.\n* `data.pi.lex`: Lexicographic order on `\u03a0\u2097 i, \u03b1 i`.\n* `data.psigma.order`: Lexicographic order on `\u03a3\u2097' i, \u03b1 i`. Basically a twin of this file.\n* `data.prod.lex`: Lexicographic order on `\u03b1 \u00d7 \u03b2`.\n\n## TODO\n\nUpgrade `equiv.sigma_congr_left`, `equiv.sigma_congr`, `equiv.sigma_assoc`,\n`equiv.sigma_prod_of_equiv`, `equiv.sigma_equiv_prod`, ... to order isomorphisms.\n-/\n\nnamespace sigma\nvariables {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*}\n\n/-! ### Disjoint sum of orders on `sigma` -/\n\n/-- Disjoint sum of orders. `\u27e8i, a\u27e9 \u2264 \u27e8j, b\u27e9` iff `i = j` and `a \u2264 b`. -/\ninductive le [\u03a0 i, has_le (\u03b1 i)] : \u03a0 a b : \u03a3 i, \u03b1 i, Prop\n| fiber (i : \u03b9) (a b : \u03b1 i) : a \u2264 b \u2192 le \u27e8i, a\u27e9 \u27e8i, b\u27e9\n\n/-- Disjoint sum of orders. `\u27e8i, a\u27e9 < \u27e8j, b\u27e9` iff `i = j` and `a < b`. -/\ninductive lt [\u03a0 i, has_lt (\u03b1 i)] : \u03a0 a b : \u03a3 i, \u03b1 i, Prop\n| fiber (i : \u03b9) (a b : \u03b1 i) : a < b \u2192 lt \u27e8i, a\u27e9 \u27e8i, b\u27e9\n\ninstance [\u03a0 i, has_le (\u03b1 i)] : has_le (\u03a3 i, \u03b1 i) := \u27e8le\u27e9\ninstance [\u03a0 i, has_lt (\u03b1 i)] : has_lt (\u03a3 i, \u03b1 i) := \u27e8lt\u27e9\n\n@[simp] lemma mk_le_mk_iff [\u03a0 i, has_le (\u03b1 i)] {i : \u03b9} {a b : \u03b1 i} :\n  (\u27e8i, a\u27e9 : sigma \u03b1) \u2264 \u27e8i, b\u27e9 \u2194 a \u2264 b :=\n\u27e8\u03bb \u27e8_, _, _, h\u27e9, h, le.fiber _ _ _\u27e9\n\n@[simp] lemma mk_lt_mk_iff [\u03a0 i, has_lt (\u03b1 i)] {i : \u03b9} {a b : \u03b1 i} :\n  (\u27e8i, a\u27e9 : sigma \u03b1) < \u27e8i, b\u27e9 \u2194 a < b :=\n\u27e8\u03bb \u27e8_, _, _, h\u27e9, h, lt.fiber _ _ _\u27e9\n\n\n\nlemma lt_def [\u03a0 i, has_lt (\u03b1 i)] {a b : \u03a3 i, \u03b1 i} : a < b \u2194 \u2203 h : a.1 = b.1, h.rec a.2 < b.2 :=\nbegin\n  split,\n  { rintro \u27e8i, a, b, h\u27e9,\n    exact \u27e8rfl, h\u27e9 },\n  { obtain \u27e8i, a\u27e9 := a,\n    obtain \u27e8j, b\u27e9 := b,\n    rintro \u27e8(rfl : i = j), h\u27e9,\n    exact lt.fiber _ _ _ h }\nend\n\ninstance [\u03a0 i, preorder (\u03b1 i)] : preorder (\u03a3 i, \u03b1 i) :=\n{ le_refl := \u03bb \u27e8i, a\u27e9, le.fiber i a a le_rfl,\n  le_trans := begin\n    rintro _ _ _ \u27e8i, a, b, hab\u27e9 \u27e8_, _, c, hbc\u27e9,\n    exact le.fiber i a c (hab.trans hbc),\n  end,\n  lt_iff_le_not_le := \u03bb _ _, begin\n    split,\n    { rintro \u27e8i, a, b, hab\u27e9,\n      rwa [mk_le_mk_iff, mk_le_mk_iff, \u2190lt_iff_le_not_le] },\n    { rintro \u27e8\u27e8i, a, b, hab\u27e9, h\u27e9,\n      rw mk_le_mk_iff at h,\n      exact mk_lt_mk_iff.2 (hab.lt_of_not_le h) }\n  end,\n  .. sigma.has_le,\n  .. sigma.has_lt }\n\ninstance [\u03a0 i, partial_order (\u03b1 i)] : partial_order (\u03a3 i, \u03b1 i) :=\n{ le_antisymm := begin\n    rintro _ _ \u27e8i, a, b, hab\u27e9 \u27e8_, _, _, hba\u27e9,\n    exact ext rfl (heq_of_eq $ hab.antisymm hba),\n  end,\n  .. sigma.preorder }\n\ninstance [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, densely_ordered (\u03b1 i)] : densely_ordered (\u03a3 i, \u03b1 i) :=\n\u27e8begin\n  rintro \u27e8i, a\u27e9 \u27e8_, _\u27e9 \u27e8_, _, b, h\u27e9,\n  obtain \u27e8c, ha, hb\u27e9 := exists_between h,\n  exact \u27e8\u27e8i, c\u27e9, lt.fiber i a c ha, lt.fiber i c b hb\u27e9,\nend\u27e9\n\n/-! ### Lexicographical order on `sigma` -/\n\nnamespace lex\n\nnotation `\u03a3\u2097` binders `, ` r:(scoped p, _root_.lex (sigma p)) := r\n\n/-- The lexicographical `\u2264` on a sigma type. -/\ninstance has_le [has_lt \u03b9] [\u03a0 i, has_le (\u03b1 i)] : has_le (\u03a3\u2097 i, \u03b1 i) := \u27e8lex (<) (\u03bb i, (\u2264))\u27e9\n\n/-- The lexicographical `<` on a sigma type. -/\ninstance has_lt [has_lt \u03b9] [\u03a0 i, has_lt (\u03b1 i)] : has_lt (\u03a3\u2097 i, \u03b1 i) := \u27e8lex (<) (\u03bb i, (<))\u27e9\n\nlemma le_def [has_lt \u03b9] [\u03a0 i, has_le (\u03b1 i)] {a b : \u03a3\u2097 i, \u03b1 i} :\n  a \u2264 b \u2194 a.1 < b.1 \u2228 \u2203 (h : a.1 = b.1), h.rec a.2 \u2264 b.2 := sigma.lex_iff\n\nlemma lt_def [has_lt \u03b9] [\u03a0 i, has_lt (\u03b1 i)] {a b : \u03a3\u2097 i, \u03b1 i} :\n  a < b \u2194 a.1 < b.1 \u2228 \u2203 (h : a.1 = b.1), h.rec a.2 < b.2 := sigma.lex_iff\n\n/-- The lexicographical preorder on a sigma type. -/\ninstance preorder [preorder \u03b9] [\u03a0 i, preorder (\u03b1 i)] : preorder (\u03a3\u2097 i, \u03b1 i) :=\n{ le_refl := \u03bb \u27e8i, a\u27e9, lex.right a a le_rfl,\n  le_trans := \u03bb _ _ _, trans_of (lex (<) $ \u03bb _, (\u2264)),\n  lt_iff_le_not_le := begin\n    refine \u03bb a b, \u27e8\u03bb hab, \u27e8hab.mono_right (\u03bb i a b, le_of_lt), _\u27e9, _\u27e9,\n    { rintro (\u27e8b, a, hji\u27e9 | \u27e8b, a, hba\u27e9);\n        obtain (\u27e8_, _, hij\u27e9 | \u27e8_, _, hab\u27e9) := hab,\n      { exact hij.not_lt hji },\n      { exact lt_irrefl _ hji },\n      { exact lt_irrefl _ hij },\n      { exact hab.not_le hba } },\n    { rintro \u27e8\u27e8a, b, hij\u27e9 | \u27e8a, b, hab\u27e9, hba\u27e9,\n      { exact lex.left _ _ hij },\n      { exact lex.right _ _ (hab.lt_of_not_le $ \u03bb h, hba $ lex.right _ _ h) } }\n  end,\n  .. lex.has_le,\n  .. lex.has_lt }\n\n/-- The lexicographical partial order on a sigma type. -/\ninstance partial_order [preorder \u03b9] [\u03a0 i, partial_order (\u03b1 i)] :\n  partial_order (\u03a3\u2097 i, \u03b1 i) :=\n{ le_antisymm := \u03bb _ _, antisymm_of (lex (<) $ \u03bb _, (\u2264)),\n  .. lex.preorder }\n\n/-- The lexicographical linear order on a sigma type. -/\ninstance linear_order [linear_order \u03b9] [\u03a0 i, linear_order (\u03b1 i)] :\n  linear_order (\u03a3\u2097 i, \u03b1 i) :=\n{ le_total := total_of (lex (<) $ \u03bb _, (\u2264)),\n  decidable_eq := sigma.decidable_eq,\n  decidable_le := lex.decidable _ _,\n  .. lex.partial_order }\n\n/-- The lexicographical linear order on a sigma type. -/\ninstance order_bot [partial_order \u03b9] [order_bot \u03b9] [\u03a0 i, preorder (\u03b1 i)] [order_bot (\u03b1 \u22a5)] :\n  order_bot (\u03a3\u2097 i, \u03b1 i) :=\n{ bot := \u27e8\u22a5, \u22a5\u27e9,\n  bot_le := \u03bb \u27e8a, b\u27e9, begin\n    obtain rfl | ha := eq_bot_or_bot_lt a,\n    { exact lex.right _ _ bot_le },\n    { exact lex.left _ _ ha }\n  end }\n\n/-- The lexicographical linear order on a sigma type. -/\ninstance order_top [partial_order \u03b9] [order_top \u03b9] [\u03a0 i, preorder (\u03b1 i)] [order_top (\u03b1 \u22a4)] :\n  order_top (\u03a3\u2097 i, \u03b1 i) :=\n{ top := \u27e8\u22a4, \u22a4\u27e9,\n  le_top := \u03bb \u27e8a, b\u27e9, begin\n    obtain rfl | ha := eq_top_or_lt_top a,\n    { exact lex.right _ _ le_top },\n    { exact lex.left _ _ ha }\n  end }\n\n/-- The lexicographical linear order on a sigma type. -/\ninstance bounded_order [partial_order \u03b9] [bounded_order \u03b9] [\u03a0 i, preorder (\u03b1 i)]\n  [order_bot (\u03b1 \u22a5)] [order_top (\u03b1 \u22a4)] :\n  bounded_order (\u03a3\u2097 i, \u03b1 i) :=\n{ .. lex.order_bot, .. lex.order_top }\n\ninstance densely_ordered [preorder \u03b9] [densely_ordered \u03b9] [\u03a0 i, nonempty (\u03b1 i)]\n  [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, densely_ordered (\u03b1 i)] :\n  densely_ordered (\u03a3\u2097 i, \u03b1 i) :=\n\u27e8begin\n  rintro \u27e8i, a\u27e9 \u27e8j, b\u27e9 (\u27e8_, _, h\u27e9 | \u27e8_, b, h\u27e9),\n  { obtain \u27e8k, hi, hj\u27e9 := exists_between h,\n    obtain \u27e8c\u27e9 : nonempty (\u03b1 k) := infer_instance,\n    exact \u27e8\u27e8k, c\u27e9, left _ _ hi, left _ _ hj\u27e9 },\n  { obtain \u27e8c, ha, hb\u27e9 := exists_between h,\n    exact \u27e8\u27e8i, c\u27e9, right _ _ ha, right _ _ hb\u27e9 }\nend\u27e9\n\ninstance densely_ordered_of_no_max_order [preorder \u03b9] [\u03a0 i, preorder (\u03b1 i)]\n  [\u03a0 i, densely_ordered (\u03b1 i)] [\u03a0 i, no_max_order (\u03b1 i)] :\n  densely_ordered (\u03a3\u2097 i, \u03b1 i) :=\n\u27e8begin\n  rintro \u27e8i, a\u27e9 \u27e8j, b\u27e9 (\u27e8_, _, h\u27e9 | \u27e8_, b, h\u27e9),\n  { obtain \u27e8c, ha\u27e9 := exists_gt a,\n    exact \u27e8\u27e8i, c\u27e9, right _ _ ha, left _ _ h\u27e9 },\n  { obtain \u27e8c, ha, hb\u27e9 := exists_between h,\n    exact \u27e8\u27e8i, c\u27e9, right _ _ ha, right _ _ hb\u27e9 }\nend\u27e9\n\ninstance densely_ordered_of_no_min_order [preorder \u03b9] [\u03a0 i, preorder (\u03b1 i)]\n  [\u03a0 i, densely_ordered (\u03b1 i)] [\u03a0 i, no_min_order (\u03b1 i)] :\n  densely_ordered (\u03a3\u2097 i, \u03b1 i) :=\n\u27e8begin\n  rintro \u27e8i, a\u27e9 \u27e8j, b\u27e9 (\u27e8_, _, h\u27e9 | \u27e8_, b, h\u27e9),\n  { obtain \u27e8c, hb\u27e9 := exists_lt b,\n    exact \u27e8\u27e8j, c\u27e9, left _ _ h, right _ _ hb\u27e9 },\n  { obtain \u27e8c, ha, hb\u27e9 := exists_between h,\n    exact \u27e8\u27e8i, c\u27e9, right _ _ ha, right _ _ hb\u27e9 }\nend\u27e9\n\ninstance no_max_order_of_nonempty [preorder \u03b9] [\u03a0 i, preorder (\u03b1 i)] [no_max_order \u03b9]\n  [\u03a0 i, nonempty (\u03b1 i)] :\n  no_max_order (\u03a3\u2097 i, \u03b1 i) :=\n\u27e8begin\n  rintro \u27e8i, a\u27e9,\n  obtain \u27e8j, h\u27e9 := exists_gt i,\n  obtain \u27e8b\u27e9 : nonempty (\u03b1 j) := infer_instance,\n  exact \u27e8\u27e8j, b\u27e9, left _ _ h\u27e9\nend\u27e9\n\ninstance no_min_order_of_nonempty [preorder \u03b9] [\u03a0 i, preorder (\u03b1 i)] [no_max_order \u03b9]\n  [\u03a0 i, nonempty (\u03b1 i)] :\n  no_max_order (\u03a3\u2097 i, \u03b1 i) :=\n\u27e8begin\n  rintro \u27e8i, a\u27e9,\n  obtain \u27e8j, h\u27e9 := exists_gt i,\n  obtain \u27e8b\u27e9 : nonempty (\u03b1 j) := infer_instance,\n  exact \u27e8\u27e8j, b\u27e9, left _ _ h\u27e9\nend\u27e9\n\ninstance no_max_order [preorder \u03b9] [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, no_max_order (\u03b1 i)] :\n  no_max_order (\u03a3\u2097 i, \u03b1 i) :=\n\u27e8by { rintro \u27e8i, a\u27e9, obtain \u27e8b, h\u27e9 := exists_gt a, exact \u27e8\u27e8i, b\u27e9, right _ _ h\u27e9 }\u27e9\n\ninstance no_min_order [preorder \u03b9] [\u03a0 i, preorder (\u03b1 i)] [\u03a0 i, no_min_order (\u03b1 i)] :\n  no_min_order (\u03a3\u2097 i, \u03b1 i) :=\n\u27e8by { rintro \u27e8i, a\u27e9, obtain \u27e8b, h\u27e9 := exists_lt a, exact \u27e8\u27e8i, b\u27e9, right _ _ h\u27e9 }\u27e9\n\nend lex\nend sigma\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/sigma/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7160126833825669}}
{"text": "/-\nCopyright (c) 2019 Rohan Mitta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport analysis.specific_limits.basic\nimport data.setoid.basic\nimport dynamics.fixed_points.topology\n\n/-!\n# Contracting maps\n\nA Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*.\nIn this file we prove the Banach fixed point theorem, some explicit estimates on the rate\nof convergence, and some properties of the map sending a contracting map to its fixed point.\n\n## Main definitions\n\n* `contracting_with K f` : a Lipschitz continuous self-map with `K < 1`;\n* `efixed_point` : given a contracting map `f` on a complete emetric space and a point `x`\n  such that `edist x (f x) \u2260 \u221e`, `efixed_point f hf x hx` is the unique fixed point of `f`\n  in `emetric.ball x \u221e`;\n* `fixed_point` : the unique fixed point of a contracting map on a complete nonempty metric space.\n\n## Tags\n\ncontracting map, fixed point, Banach fixed point theorem\n-/\n\nopen_locale nnreal topological_space classical ennreal\nopen filter function\n\nvariables {\u03b1 : Type*}\n\n/-- A map is said to be `contracting_with K`, if `K < 1` and `f` is `lipschitz_with K`. -/\ndef contracting_with [emetric_space \u03b1] (K : \u211d\u22650) (f : \u03b1 \u2192 \u03b1) :=\n(K < 1) \u2227 lipschitz_with K f\n\nnamespace contracting_with\n\nvariables [emetric_space \u03b1] [cs : complete_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1}\n\nopen emetric set\n\nlemma to_lipschitz_with (hf : contracting_with K f) : lipschitz_with K f := hf.2\n\nlemma one_sub_K_pos' (hf : contracting_with K f) : (0:\u211d\u22650\u221e) < 1 - K := by simp [hf.1]\n\nlemma one_sub_K_ne_zero (hf : contracting_with K f) : (1:\u211d\u22650\u221e) - K \u2260 0 :=\nne_of_gt hf.one_sub_K_pos'\n\nlemma one_sub_K_ne_top : (1:\u211d\u22650\u221e) - K \u2260 \u221e :=\nby { norm_cast, exact ennreal.coe_ne_top }\n\nlemma edist_inequality (hf : contracting_with K f) {x y} (h : edist x y \u2260 \u221e) :\n  edist x y \u2264 (edist x (f x) + edist y (f y)) / (1 - K) :=\nsuffices edist x y \u2264 edist x (f x) + edist y (f y) + K * edist x y,\n  by rwa [ennreal.le_div_iff_mul_le (or.inl hf.one_sub_K_ne_zero) (or.inl one_sub_K_ne_top),\n    mul_comm, ennreal.sub_mul (\u03bb _ _, h), one_mul, tsub_le_iff_right],\ncalc edist x y \u2264 edist x (f x) + edist (f x) (f y) + edist (f y) y : edist_triangle4 _ _ _ _\n  ... = edist x (f x) + edist y (f y) + edist (f x) (f y) : by rw [edist_comm y, add_right_comm]\n  ... \u2264 edist x (f x) + edist y (f y) + K * edist x y : add_le_add le_rfl (hf.2 _ _)\n\nlemma edist_le_of_fixed_point (hf : contracting_with K f) {x y}\n  (h : edist x y \u2260 \u221e) (hy : is_fixed_pt f y) :\n  edist x y \u2264 (edist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h\n\nlemma eq_or_edist_eq_top_of_fixed_points (hf : contracting_with K f) {x y}\n  (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) :\n  x = y \u2228 edist x y = \u221e :=\nbegin\n  refine or_iff_not_imp_right.2 (\u03bb h, edist_le_zero.1 _),\n  simpa only [hx.eq, edist_self, add_zero, ennreal.zero_div]\n    using hf.edist_le_of_fixed_point h hy\nend\n\n/-- If a map `f` is `contracting_with K`, and `s` is a forward-invariant set, then\nrestriction of `f` to `s` is `contracting_with K` as well. -/\nlemma restrict (hf : contracting_with K f) {s : set \u03b1} (hs : maps_to f s s) :\n  contracting_with K (hs.restrict f s s) :=\n\u27e8hf.1, \u03bb x y, hf.2 x y\u27e9\n\ninclude cs\n\n/-- Banach fixed-point theorem, contraction mapping theorem, `emetric_space` version.\nA contracting map on a complete metric space has a fixed point.\nWe include more conclusions in this theorem to avoid proving them again later.\n\nThe main API for this theorem are the functions `efixed_point` and `fixed_point`,\nand lemmas about these functions. -/\ntheorem exists_fixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) \u2260 \u221e) :\n  \u2203 y, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nhave cauchy_seq (\u03bb n, f^[n] x),\nfrom cauchy_seq_of_edist_le_geometric K (edist x (f x)) (ennreal.coe_lt_one_iff.2 hf.1)\n  hx (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x),\nlet \u27e8y, hy\u27e9 := cauchy_seq_tendsto_of_complete this in\n\u27e8y, is_fixed_pt_of_tendsto_iterate hy hf.2.continuous.continuous_at, hy,\n  edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x))\n    (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x) hy\u27e9\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map,\nand `edist x (f x) \u2260 \u221e`. Then `efixed_point` is the unique fixed point of `f`\nin `emetric.ball x \u221e`. -/\nnoncomputable def efixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) \u2260 \u221e) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point x hx\n\nvariables {f}\n\nlemma efixed_point_is_fixed_pt (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  is_fixed_pt f (efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).1\n\nlemma tendsto_iterate_efixed_point (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.1\n\nlemma apriori_edist_iterate_efixed_point_le (hf : contracting_with K f)\n  {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) (n : \u2115) :\n  edist (f^[n] x) (efixed_point f hf x hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.2 n\n\nlemma edist_efixed_point_le (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point f hf x hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le hx 0, simp only [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point f hf x hx) < \u221e :=\n(hf.edist_efixed_point_le hx).trans_lt (ennreal.mul_lt_top hx $\n  ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\nlemma efixed_point_eq_of_edist_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e)\n  {y : \u03b1} (hy : edist y (f y) \u2260 \u221e) (h : edist x y \u2260 \u221e) :\n  efixed_point f hf x hx = efixed_point f hf y hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, exact hf.edist_efixed_point_lt_top hx },\n  transitivity y,\n  exacts [lt_top_iff_ne_top.2 h, hf.edist_efixed_point_lt_top hy]\nend\n\nomit cs\n\n/-- Banach fixed-point theorem for maps contracting on a complete subset. -/\ntheorem exists_fixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  \u2203 y \u2208 s, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nbegin\n  haveI := hsc.complete_space_coe,\n  rcases hf.exists_fixed_point \u27e8x, hxs\u27e9 hx with \u27e8y, hfy, h_tendsto, hle\u27e9,\n  refine \u27e8y, y.2, subtype.ext_iff_val.1 hfy, _, \u03bb n, _\u27e9,\n  { convert (continuous_subtype_coe.tendsto _).comp h_tendsto, ext n,\n    simp only [(\u2218), maps_to.iterate_restrict, maps_to.coe_restrict_apply, subtype.coe_mk] },\n  { convert hle n,\n    rw [maps_to.iterate_restrict, eq_comm, maps_to.coe_restrict_apply, subtype.coe_mk] }\nend\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s`\nand `x \u2208 s` satisfies `edist x (f x) \u2260 \u221e`, then `efixed_point'` is the unique fixed point\nof the restriction of `f` to `s \u2229 emetric.ball x \u221e`. -/\nnoncomputable def efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) (x : \u03b1) (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point' hsc hsf hxs hx\n\nvariables {f}\n\nlemma efixed_point_mem' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  efixed_point' f hsc hsf hf x hxs hx \u2208 s :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).fst\n\nlemma efixed_point_is_fixed_pt' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  is_fixed_pt f (efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.1\n\nlemma tendsto_iterate_efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.1\n\nlemma apriori_edist_iterate_efixed_point_le' {s : set \u03b1} (hsc : is_complete s)\n  (hsf : maps_to f s s) (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s)\n  (hx : edist x (f x) \u2260 \u221e) (n : \u2115) :\n  edist (f^[n] x) (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.2 n\n\nlemma edist_efixed_point_le' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le' hsc hsf hxs hx 0,\n  rw [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) < \u221e :=\n(hf.edist_efixed_point_le' hsc hsf hxs hx).trans_lt (ennreal.mul_lt_top hx $\n  ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\n/-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`,\nand `x \u2208 s` is at a finite distance from `y \u2208 t`, then the `efixed_point'` constructed by `x`\nis the same as the `efixed_point'` constructed by `y`.\n\nThis lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way\nit can be used to prove the desired equality with non-trivial proofs of these facts. -/\nlemma efixed_point_eq_of_edist_lt_top' (hf : contracting_with K f)\n  {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hfs : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e)\n  {t : set \u03b1} (htc : is_complete t) (htf : maps_to f t t)\n  (hft : contracting_with K $ htf.restrict f t t) {y : \u03b1} (hyt : y \u2208 t) (hy : edist y (f y) \u2260 \u221e)\n  (hxy : edist x y \u2260 \u221e) :\n  efixed_point' f hsc hsf hfs x hxs hx = efixed_point' f htc htf hft y hyt hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt' },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, apply edist_efixed_point_lt_top' },\n  transitivity y,\n  exact lt_top_iff_ne_top.2 hxy,\n  apply edist_efixed_point_lt_top'\nend\n\nend contracting_with\n\nnamespace contracting_with\n\nvariables [metric_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1} (hf : contracting_with K f)\ninclude hf\n\nlemma one_sub_K_pos (hf : contracting_with K f) : (0:\u211d) < 1 - K := sub_pos.2 hf.1\n\nlemma dist_le_mul (x y : \u03b1) : dist (f x) (f y) \u2264 K * dist x y :=\nhf.to_lipschitz_with.dist_le_mul x y\n\nlemma dist_inequality (x y) : dist x y \u2264 (dist x (f x) + dist y (f y)) / (1 - K) :=\nsuffices dist x y \u2264 dist x (f x) + dist y (f y) + K * dist x y,\n  by rwa [le_div_iff hf.one_sub_K_pos, mul_comm, sub_mul, one_mul, sub_le_iff_le_add],\ncalc dist x y \u2264 dist x (f x) + dist y (f y) + dist (f x) (f y) : dist_triangle4_right _ _ _ _\n          ... \u2264 dist x (f x) + dist y (f y) + K * dist x y :\n  add_le_add_left (hf.dist_le_mul _ _) _\n\nlemma dist_le_of_fixed_point (x) {y} (hy : is_fixed_pt f y) :\n  dist x y \u2264 (dist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, dist_self, add_zero] using hf.dist_inequality x y\n\ntheorem fixed_point_unique' {x y} (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) : x = y :=\n(hf.eq_or_edist_eq_top_of_fixed_points hx hy).resolve_right (edist_ne_top _ _)\n\n/-- Let `f` be a contracting map with constant `K`; let `g` be another map uniformly\n`C`-close to `f`. If `x` and `y` are their fixed points, then `dist x y \u2264 C / (1 - K)`. -/\n\n\nnoncomputable theory\n\nvariables [nonempty \u03b1] [complete_space \u03b1]\n\nvariable (f)\n/-- The unique fixed point of a contracting map in a nonempty complete metric space. -/\ndef fixed_point : \u03b1 :=\nefixed_point f hf _ (edist_ne_top (classical.choice \u2039nonempty \u03b1\u203a) _)\nvariable {f}\n\n/-- The point provided by `contracting_with.fixed_point` is actually a fixed point. -/\nlemma fixed_point_is_fixed_pt : is_fixed_pt f (fixed_point f hf) :=\nhf.efixed_point_is_fixed_pt _\n\nlemma fixed_point_unique {x} (hx : is_fixed_pt f x) : x = fixed_point f hf :=\nhf.fixed_point_unique' hx hf.fixed_point_is_fixed_pt\n\nlemma dist_fixed_point_le (x) : dist x (fixed_point f hf) \u2264 (dist x (f x)) / (1 - K) :=\nhf.dist_le_of_fixed_point x hf.fixed_point_is_fixed_pt\n\n/-- Aposteriori estimates on the convergence of iterates to the fixed point. -/\nlemma aposteriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist (f^[n] x) (f^[n+1] x)) / (1 - K) :=\nby { rw [iterate_succ'], apply hf.dist_fixed_point_le }\n\nlemma apriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist x (f x)) * K^n / (1 - K) :=\nle_trans (hf.aposteriori_dist_iterate_fixed_point_le x n) $\n  (div_le_div_right hf.one_sub_K_pos).2 $\n    hf.to_lipschitz_with.dist_iterate_succ_le_geometric x n\n\nlemma tendsto_iterate_fixed_point (x) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ fixed_point f hf) :=\nbegin\n  convert tendsto_iterate_efixed_point hf (edist_ne_top x _),\n  refine (fixed_point_unique _ _).symm,\n  apply efixed_point_is_fixed_pt\nend\n\nlemma fixed_point_lipschitz_in_map {g : \u03b1 \u2192 \u03b1} (hg : contracting_with K g)\n  {C} (hfg : \u2200 z, dist (f z) (g z) \u2264 C) :\n  dist (fixed_point f hf) (fixed_point g hg) \u2264 C / (1 - K) :=\nhf.dist_fixed_point_fixed_point_of_dist_le' g hf.fixed_point_is_fixed_pt\n  hg.fixed_point_is_fixed_pt hfg\n\nomit hf\n\n/-- If a map `f` has a contracting iterate `f^[n]`, then the fixed point of `f^[n]` is also a fixed\npoint of `f`. -/\nlemma is_fixed_pt_fixed_point_iterate {n : \u2115} (hf : contracting_with K (f^[n])) :\n  is_fixed_pt f (hf.fixed_point (f^[n])) :=\nbegin\n  set x := hf.fixed_point (f^[n]),\n  have hx : (f^[n] x) = x := hf.fixed_point_is_fixed_pt,\n  have := hf.to_lipschitz_with.dist_le_mul x (f x),\n  rw [\u2190 iterate_succ_apply, iterate_succ_apply', hx] at this,\n  contrapose! this,\n  have := dist_pos.2 (ne.symm this),\n  simpa only [nnreal.coe_one, one_mul, nnreal.val_eq_coe] using (mul_lt_mul_right this).mpr hf.left\nend\n\nend contracting_with\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/topology/metric_space/contracting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797081106935, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7159711548891134}}
{"text": "/-\nCopyright (c) 2019 Rohan Mitta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport analysis.specific_limits\nimport data.setoid.basic\nimport dynamics.fixed_points.topology\n\n/-!\n# Contracting maps\n\nA Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*.\nIn this file we prove the Banach fixed point theorem, some explicit estimates on the rate\nof convergence, and some properties of the map sending a contracting map to its fixed point.\n\n## Main definitions\n\n* `contracting_with K f` : a Lipschitz continuous self-map with `K < 1`;\n* `efixed_point` : given a contracting map `f` on a complete emetric space and a point `x`\n  such that `edist x (f x) \u2260 \u221e`, `efixed_point f hf x hx` is the unique fixed point of `f`\n  in `emetric.ball x \u221e`;\n* `fixed_point` : the unique fixed point of a contracting map on a complete nonempty metric space.\n\n## Tags\n\ncontracting map, fixed point, Banach fixed point theorem\n-/\n\nopen_locale nnreal topological_space classical ennreal\nopen filter function\n\nvariables {\u03b1 : Type*}\n\n/-- A map is said to be `contracting_with K`, if `K < 1` and `f` is `lipschitz_with K`. -/\ndef contracting_with [emetric_space \u03b1] (K : \u211d\u22650) (f : \u03b1 \u2192 \u03b1) :=\n(K < 1) \u2227 lipschitz_with K f\n\nnamespace contracting_with\n\nvariables [emetric_space \u03b1] [cs : complete_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1}\n\nopen emetric set\n\nlemma to_lipschitz_with (hf : contracting_with K f) : lipschitz_with K f := hf.2\n\nlemma one_sub_K_pos' (hf : contracting_with K f) : (0:\u211d\u22650\u221e) < 1 - K := by simp [hf.1]\n\nlemma one_sub_K_ne_zero (hf : contracting_with K f) : (1:\u211d\u22650\u221e) - K \u2260 0 :=\nne_of_gt hf.one_sub_K_pos'\n\nlemma one_sub_K_ne_top : (1:\u211d\u22650\u221e) - K \u2260 \u221e :=\nby { norm_cast, exact ennreal.coe_ne_top }\n\nlemma edist_inequality (hf : contracting_with K f) {x y} (h : edist x y \u2260 \u221e) :\n  edist x y \u2264 (edist x (f x) + edist y (f y)) / (1 - K) :=\nsuffices edist x y \u2264 edist x (f x) + edist y (f y) + K * edist x y,\n  by rwa [ennreal.le_div_iff_mul_le (or.inl hf.one_sub_K_ne_zero) (or.inl one_sub_K_ne_top),\n    mul_comm, ennreal.sub_mul (\u03bb _ _, h), one_mul, tsub_le_iff_right],\ncalc edist x y \u2264 edist x (f x) + edist (f x) (f y) + edist (f y) y : edist_triangle4 _ _ _ _\n  ... = edist x (f x) + edist y (f y) + edist (f x) (f y) : by rw [edist_comm y, add_right_comm]\n  ... \u2264 edist x (f x) + edist y (f y) + K * edist x y : add_le_add (le_refl _) (hf.2 _ _)\n\nlemma edist_le_of_fixed_point (hf : contracting_with K f) {x y}\n  (h : edist x y \u2260 \u221e) (hy : is_fixed_pt f y) :\n  edist x y \u2264 (edist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h\n\nlemma eq_or_edist_eq_top_of_fixed_points (hf : contracting_with K f) {x y}\n  (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) :\n  x = y \u2228 edist x y = \u221e :=\nbegin\n  refine or_iff_not_imp_right.2 (\u03bb h, edist_le_zero.1 _),\n  simpa only [hx.eq, edist_self, add_zero, ennreal.zero_div]\n    using hf.edist_le_of_fixed_point h hy\nend\n\n/-- If a map `f` is `contracting_with K`, and `s` is a forward-invariant set, then\nrestriction of `f` to `s` is `contracting_with K` as well. -/\nlemma restrict (hf : contracting_with K f) {s : set \u03b1} (hs : maps_to f s s) :\n  contracting_with K (hs.restrict f s s) :=\n\u27e8hf.1, \u03bb x y, hf.2 x y\u27e9\n\ninclude cs\n\n/-- Banach fixed-point theorem, contraction mapping theorem, `emetric_space` version.\nA contracting map on a complete metric space has a fixed point.\nWe include more conclusions in this theorem to avoid proving them again later.\n\nThe main API for this theorem are the functions `efixed_point` and `fixed_point`,\nand lemmas about these functions. -/\ntheorem exists_fixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) \u2260 \u221e) :\n  \u2203 y, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nhave cauchy_seq (\u03bb n, f^[n] x),\nfrom cauchy_seq_of_edist_le_geometric K (edist x (f x)) (ennreal.coe_lt_one_iff.2 hf.1)\n  hx (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x),\nlet \u27e8y, hy\u27e9 := cauchy_seq_tendsto_of_complete this in\n\u27e8y, is_fixed_pt_of_tendsto_iterate hy hf.2.continuous.continuous_at, hy,\n  edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x))\n    (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x) hy\u27e9\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map,\nand `edist x (f x) \u2260 \u221e`. Then `efixed_point` is the unique fixed point of `f`\nin `emetric.ball x \u221e`. -/\nnoncomputable def efixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) \u2260 \u221e) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point x hx\n\nvariables {f}\n\nlemma efixed_point_is_fixed_pt (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  is_fixed_pt f (efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).1\n\nlemma tendsto_iterate_efixed_point (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.1\n\nlemma apriori_edist_iterate_efixed_point_le (hf : contracting_with K f)\n  {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) (n : \u2115) :\n  edist (f^[n] x) (efixed_point f hf x hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.2 n\n\nlemma edist_efixed_point_le (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point f hf x hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le hx 0, simp only [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point f hf x hx) < \u221e :=\n(hf.edist_efixed_point_le hx).trans_lt (ennreal.mul_lt_top hx $\n  ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\nlemma efixed_point_eq_of_edist_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e)\n  {y : \u03b1} (hy : edist y (f y) \u2260 \u221e) (h : edist x y \u2260 \u221e) :\n  efixed_point f hf x hx = efixed_point f hf y hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, exact hf.edist_efixed_point_lt_top hx },\n  transitivity y,\n  exacts [lt_top_iff_ne_top.2 h, hf.edist_efixed_point_lt_top hy]\nend\n\nomit cs\n\n/-- Banach fixed-point theorem for maps contracting on a complete subset. -/\ntheorem exists_fixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  \u2203 y \u2208 s, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nbegin\n  haveI := hsc.complete_space_coe,\n  rcases hf.exists_fixed_point \u27e8x, hxs\u27e9 hx with \u27e8y, hfy, h_tendsto, hle\u27e9,\n  refine \u27e8y, y.2, subtype.ext_iff_val.1 hfy, _, \u03bb n, _\u27e9,\n  { convert (continuous_subtype_coe.tendsto _).comp h_tendsto, ext n,\n    simp only [(\u2218), maps_to.iterate_restrict, maps_to.coe_restrict_apply, subtype.coe_mk] },\n  { convert hle n,\n    rw [maps_to.iterate_restrict, eq_comm, maps_to.coe_restrict_apply, subtype.coe_mk] }\nend\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s`\nand `x \u2208 s` satisfies `edist x (f x) \u2260 \u221e`, then `efixed_point'` is the unique fixed point\nof the restriction of `f` to `s \u2229 emetric.ball x \u221e`. -/\nnoncomputable def efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) (x : \u03b1) (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point' hsc hsf hxs hx\n\nvariables {f}\n\nlemma efixed_point_mem' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  efixed_point' f hsc hsf hf x hxs hx \u2208 s :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).fst\n\nlemma efixed_point_is_fixed_pt' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  is_fixed_pt f (efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.1\n\nlemma tendsto_iterate_efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.1\n\nlemma apriori_edist_iterate_efixed_point_le' {s : set \u03b1} (hsc : is_complete s)\n  (hsf : maps_to f s s) (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s)\n  (hx : edist x (f x) \u2260 \u221e) (n : \u2115) :\n  edist (f^[n] x) (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.2 n\n\nlemma edist_efixed_point_le' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le' hsc hsf hxs hx 0,\n  rw [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) < \u221e :=\n(hf.edist_efixed_point_le' hsc hsf hxs hx).trans_lt (ennreal.mul_lt_top hx $\n  ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\n/-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`,\nand `x \u2208 s` is at a finite distance from `y \u2208 t`, then the `efixed_point'` constructed by `x`\nis the same as the `efixed_point'` constructed by `y`.\n\nThis lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way\nit can be used to prove the desired equality with non-trivial proofs of these facts. -/\nlemma efixed_point_eq_of_edist_lt_top' (hf : contracting_with K f)\n  {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hfs : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e)\n  {t : set \u03b1} (htc : is_complete t) (htf : maps_to f t t)\n  (hft : contracting_with K $ htf.restrict f t t) {y : \u03b1} (hyt : y \u2208 t) (hy : edist y (f y) \u2260 \u221e)\n  (hxy : edist x y \u2260 \u221e) :\n  efixed_point' f hsc hsf hfs x hxs hx = efixed_point' f htc htf hft y hyt hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt' },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, apply edist_efixed_point_lt_top' },\n  transitivity y,\n  exact lt_top_iff_ne_top.2 hxy,\n  apply edist_efixed_point_lt_top'\nend\n\nend contracting_with\n\nnamespace contracting_with\n\nvariables [metric_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1} (hf : contracting_with K f)\ninclude hf\n\nlemma one_sub_K_pos (hf : contracting_with K f) : (0:\u211d) < 1 - K := sub_pos.2 hf.1\n\nlemma dist_le_mul (x y : \u03b1) : dist (f x) (f y) \u2264 K * dist x y :=\nhf.to_lipschitz_with.dist_le_mul x y\n\nlemma dist_inequality (x y) : dist x y \u2264 (dist x (f x) + dist y (f y)) / (1 - K) :=\nsuffices dist x y \u2264 dist x (f x) + dist y (f y) + K * dist x y,\n  by rwa [le_div_iff hf.one_sub_K_pos, mul_comm, sub_mul, one_mul, sub_le_iff_le_add],\ncalc dist x y \u2264 dist x (f x) + dist y (f y) + dist (f x) (f y) : dist_triangle4_right _ _ _ _\n          ... \u2264 dist x (f x) + dist y (f y) + K * dist x y :\n  add_le_add_left (hf.dist_le_mul _ _) _\n\nlemma dist_le_of_fixed_point (x) {y} (hy : is_fixed_pt f y) :\n  dist x y \u2264 (dist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, dist_self, add_zero] using hf.dist_inequality x y\n\ntheorem fixed_point_unique' {x y} (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) : x = y :=\n(hf.eq_or_edist_eq_top_of_fixed_points hx hy).resolve_right (edist_ne_top _ _)\n\n/-- Let `f` be a contracting map with constant `K`; let `g` be another map uniformly\n`C`-close to `f`. If `x` and `y` are their fixed points, then `dist x y \u2264 C / (1 - K)`. -/\n\n\nnoncomputable theory\n\nvariables [nonempty \u03b1] [complete_space \u03b1]\n\nvariable (f)\n/-- The unique fixed point of a contracting map in a nonempty complete metric space. -/\ndef fixed_point : \u03b1 :=\nefixed_point f hf _ (edist_ne_top (classical.choice \u2039nonempty \u03b1\u203a) _)\nvariable {f}\n\n/-- The point provided by `contracting_with.fixed_point` is actually a fixed point. -/\nlemma fixed_point_is_fixed_pt : is_fixed_pt f (fixed_point f hf) :=\nhf.efixed_point_is_fixed_pt _\n\nlemma fixed_point_unique {x} (hx : is_fixed_pt f x) : x = fixed_point f hf :=\nhf.fixed_point_unique' hx hf.fixed_point_is_fixed_pt\n\nlemma dist_fixed_point_le (x) : dist x (fixed_point f hf) \u2264 (dist x (f x)) / (1 - K) :=\nhf.dist_le_of_fixed_point x hf.fixed_point_is_fixed_pt\n\n/-- Aposteriori estimates on the convergence of iterates to the fixed point. -/\nlemma aposteriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist (f^[n] x) (f^[n+1] x)) / (1 - K) :=\nby { rw [iterate_succ'], apply hf.dist_fixed_point_le }\n\nlemma apriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist x (f x)) * K^n / (1 - K) :=\nle_trans (hf.aposteriori_dist_iterate_fixed_point_le x n) $\n  (div_le_div_right hf.one_sub_K_pos).2 $\n    hf.to_lipschitz_with.dist_iterate_succ_le_geometric x n\n\nlemma tendsto_iterate_fixed_point (x) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ fixed_point f hf) :=\nbegin\n  convert tendsto_iterate_efixed_point hf (edist_ne_top x _),\n  refine (fixed_point_unique _ _).symm,\n  apply efixed_point_is_fixed_pt\nend\n\nlemma fixed_point_lipschitz_in_map {g : \u03b1 \u2192 \u03b1} (hg : contracting_with K g)\n  {C} (hfg : \u2200 z, dist (f z) (g z) \u2264 C) :\n  dist (fixed_point f hf) (fixed_point g hg) \u2264 C / (1 - K) :=\nhf.dist_fixed_point_fixed_point_of_dist_le' g hf.fixed_point_is_fixed_pt\n  hg.fixed_point_is_fixed_pt hfg\n\nomit hf\n\n/-- If a map `f` has a contracting iterate `f^[n]`, then the fixed point of `f^[n]` is also a fixed\npoint of `f`. -/\nlemma is_fixed_pt_fixed_point_iterate {n : \u2115} (hf : contracting_with K (f^[n])) :\n  is_fixed_pt f (hf.fixed_point (f^[n])) :=\nbegin\n  set x := hf.fixed_point (f^[n]),\n  have hx : (f^[n] x) = x := hf.fixed_point_is_fixed_pt,\n  have := hf.to_lipschitz_with.dist_le_mul x (f x),\n  rw [\u2190 iterate_succ_apply, iterate_succ_apply', hx] at this,\n  contrapose! this,\n  have := dist_pos.2 (ne.symm this),\n  simpa only [nnreal.coe_one, one_mul, nnreal.val_eq_coe] using (mul_lt_mul_right this).mpr hf.left\nend\n\nend contracting_with\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/metric_space/contracting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.715971150704539}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.instances.real\nimport order.filter.archimedean\n\n/-!\n# Convergence of subadditive sequences\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA subadditive sequence `u : \u2115 \u2192 \u211d` is a sequence satisfying `u (m + n) \u2264 u m + u n` for all `m, n`.\nWe define this notion as `subadditive u`, and prove in `subadditive.tendsto_lim` that, if `u n / n`\nis bounded below, then it converges to a limit (that we denote by `subadditive.lim` for\nconvenience). This result is known as Fekete's lemma in the literature.\n-/\n\nnoncomputable theory\nopen set filter\nopen_locale topology\n\n/-- A real-valued sequence is subadditive if it satisfies the inequality `u (m + n) \u2264 u m + u n`\nfor all `m, n`. -/\ndef subadditive (u : \u2115 \u2192 \u211d) : Prop :=\n\u2200 m n, u (m + n) \u2264 u m + u n\n\nnamespace subadditive\n\nvariables {u : \u2115 \u2192 \u211d} (h : subadditive u)\ninclude h\n\n/-- The limit of a bounded-below subadditive sequence. The fact that the sequence indeed tends to\nthis limit is given in `subadditive.tendsto_lim` -/\n@[irreducible, nolint unused_arguments]\nprotected def lim := Inf ((\u03bb (n : \u2115), u n / n) '' (Ici 1))\n\nlemma lim_le_div (hbdd : bdd_below (range (\u03bb n, u n / n))) {n : \u2115} (hn : n \u2260 0) :\n  h.lim \u2264 u n / n :=\nbegin\n  rw subadditive.lim,\n  apply cInf_le _ _,\n  { rcases hbdd with \u27e8c, hc\u27e9,\n    exact \u27e8c, \u03bb x hx, hc (image_subset_range _ _ hx)\u27e9 },\n  { apply mem_image_of_mem,\n    exact zero_lt_iff.2 hn }\nend\n\nlemma apply_mul_add_le (k n r) : u (k * n + r) \u2264 k * u n + u r :=\nbegin\n  induction k with k IH, { simp only [nat.cast_zero, zero_mul, zero_add] },\n  calc\n  u ((k+1) * n + r)\n      = u (n + (k * n + r)) : by { congr' 1, ring }\n  ... \u2264 u n + u (k * n + r) : h _ _\n  ... \u2264 u n + (k * u n + u r) : add_le_add_left IH _\n  ... = (k+1 : \u2115) * u n + u r : by simp; ring\nend\n\nlemma eventually_div_lt_of_div_lt {L : \u211d} {n : \u2115} (hn : n \u2260 0) (hL : u n / n < L) :\n  \u2200\u1da0 p in at_top, u p / p < L :=\nbegin\n  have I : \u2200 (i : \u2115), 0 < i \u2192 (i : \u211d) \u2260 0,\n  { assume i hi, simp only [hi.ne', ne.def, nat.cast_eq_zero, not_false_iff] },\n  obtain \u27e8w, nw, wL\u27e9 : \u2203 w, u n / n < w \u2227 w < L := exists_between hL,\n  obtain \u27e8x, hx\u27e9 : \u2203 x, \u2200 i < n, u i - i * w \u2264 x,\n  { obtain \u27e8x, hx\u27e9 : bdd_above (\u2191(finset.image (\u03bb i, u i - i * w) (finset.range n))) :=\n      finset.bdd_above _,\n    refine \u27e8x, \u03bb i hi, _\u27e9,\n    simp only [upper_bounds, mem_image, and_imp, forall_exists_index, mem_set_of_eq,\n      forall_apply_eq_imp_iff\u2082, finset.mem_range, finset.mem_coe, finset.coe_image] at hx,\n    exact hx _ hi },\n  have A : \u2200 (p : \u2115), u p \u2264 p * w + x,\n  { assume p,\n    let s := p / n,\n    let r := p % n,\n    have hp : p = s * n + r, by rw [mul_comm, nat.div_add_mod],\n    calc u p = u (s * n + r) : by rw hp\n    ... \u2264 s * u n + u r : h.apply_mul_add_le _ _ _\n    ... = s * n * (u n / n) + u r : by { field_simp [I _ hn.bot_lt], ring }\n    ... \u2264 s * n * w + u r : add_le_add_right\n      (mul_le_mul_of_nonneg_left nw.le (mul_nonneg (nat.cast_nonneg _) (nat.cast_nonneg _))) _\n    ... = (s * n + r) * w + (u r - r * w) : by ring\n    ... = p * w + (u r - r * w) : by { rw hp, simp only [nat.cast_add, nat.cast_mul] }\n    ... \u2264 p * w + x : add_le_add_left (hx _ (nat.mod_lt _ hn.bot_lt)) _ },\n  have B : \u2200\u1da0 p in at_top, u p / p \u2264 w + x / p,\n  { refine eventually_at_top.2 \u27e81, \u03bb p hp, _\u27e9,\n    simp only [I p hp, ne.def, not_false_iff] with field_simps,\n    refine div_le_div_of_le_of_nonneg _ (nat.cast_nonneg _),\n    rw mul_comm,\n    exact A _ },\n  have C : \u2200\u1da0 (p : \u2115) in at_top, w + x / p < L,\n  { have : tendsto (\u03bb (p : \u2115), w + x / p) at_top (\ud835\udcdd (w + 0)) :=\n      tendsto_const_nhds.add (tendsto_const_nhds.div_at_top tendsto_coe_nat_at_top_at_top),\n    rw add_zero at this,\n    exact (tendsto_order.1 this).2 _ wL },\n  filter_upwards [B, C] with _ hp h'p using hp.trans_lt h'p,\nend\n\n/-- Fekete's lemma: a subadditive sequence which is bounded below converges. -/\ntheorem tendsto_lim (hbdd : bdd_below (range (\u03bb n, u n / n))) :\n  tendsto (\u03bb n, u n / n) at_top (\ud835\udcdd h.lim) :=\nbegin\n  refine tendsto_order.2 \u27e8\u03bb l hl, _, \u03bb L hL, _\u27e9,\n  { refine eventually_at_top.2\n      \u27e81, \u03bb n hn, hl.trans_le (h.lim_le_div hbdd ((zero_lt_one.trans_le hn).ne'))\u27e9 },\n  { obtain \u27e8n, npos, hn\u27e9 : \u2203 (n : \u2115), 0 < n \u2227 u n / n < L,\n    { rw subadditive.lim at hL,\n      rcases exists_lt_of_cInf_lt (by simp) hL with \u27e8x, hx, xL\u27e9,\n      rcases (mem_image _ _ _).1 hx with \u27e8n, hn, rfl\u27e9,\n      exact \u27e8n, zero_lt_one.trans_le hn, xL\u27e9 },\n    exact h.eventually_div_lt_of_div_lt npos.ne' hn }\nend\n\nend subadditive\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/subadditive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7159711481610342}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.calculus.mean_value\nimport analysis.special_functions.pow_deriv\n\n/-!\n# Collection of convex functions\n\nIn this file we prove that the following functions are convex:\n\n* `strict_convex_on_exp` : The exponential function is strictly convex.\n* `even.convex_on_pow`, `even.strict_convex_on_pow` : For an even `n : \u2115`, `\u03bb x, x ^ n` is convex\n  and strictly convex when `2 \u2264 n`.\n* `convex_on_pow`, `strict_convex_on_pow` : For `n : \u2115`, `\u03bb x, x ^ n` is convex on $[0, +\u221e)$ and\n  strictly convex when `2 \u2264 n`.\n* `convex_on_zpow`, `strict_convex_on_zpow` : For `m : \u2124`, `\u03bb x, x ^ m` is convex on $[0, +\u221e)$ and\n  strictly convex when `m \u2260 0, 1`.\n* `convex_on_rpow`, `strict_convex_on_rpow` : For `p : \u211d`, `\u03bb x, x ^ p` is convex on $[0, +\u221e)$ when\n  `1 \u2264 p` and strictly convex when `1 < p`.\n* `strict_concave_on_log_Ioi`, `strict_concave_on_log_Iio`: `real.log` is strictly concave on\n  $(0, +\u221e)$ and $(-\u221e, 0)$ respectively.\n\n## TODO\n\nFor `p : \u211d`, prove that `\u03bb x, x ^ p` is concave when `0 \u2264 p \u2264 1` and strictly concave when\n`0 < p < 1`.\n-/\n\nopen real set\nopen_locale big_operators\n\n/-- `exp` is strictly convex on the whole real line. -/\nlemma strict_convex_on_exp : strict_convex_on \u211d univ exp :=\nstrict_convex_on_univ_of_deriv2_pos differentiable_exp (\u03bb x, (iter_deriv_exp 2).symm \u25b8 exp_pos x)\n\n/-- `exp` is convex on the whole real line. -/\nlemma convex_on_exp : convex_on \u211d univ exp := strict_convex_on_exp.convex_on\n\n/-- `x^n`, `n : \u2115` is convex on the whole real line whenever `n` is even -/\nlemma even.convex_on_pow {n : \u2115} (hn : even n) : convex_on \u211d set.univ (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_univ_of_deriv2_nonneg differentiable_pow,\n  { simp only [deriv_pow', differentiable.mul, differentiable_const, differentiable_pow] },\n  { intro x,\n    obtain \u27e8k, hk\u27e9 := (hn.tsub $ even_bit0 _).exists_two_nsmul _,\n    rw [iter_deriv_pow, finset.prod_range_cast_nat_sub, hk, nsmul_eq_mul, pow_mul'],\n    exact mul_nonneg (nat.cast_nonneg _) (pow_two_nonneg _) }\nend\n\n/-- `x^n`, `n : \u2115` is strictly convex on the whole real line whenever `n \u2260 0` is even. -/\nlemma even.strict_convex_on_pow {n : \u2115} (hn : even n) (h : n \u2260 0) :\n  strict_convex_on \u211d set.univ (\u03bb x : \u211d, x^n) :=\nbegin\n  apply strict_mono.strict_convex_on_univ_of_deriv differentiable_pow,\n  rw deriv_pow',\n  replace h := nat.pos_of_ne_zero h,\n  exact strict_mono.const_mul (odd.strict_mono_pow $ nat.even.sub_odd h hn $ nat.odd_iff.2 rfl)\n    (nat.cast_pos.2 h),\nend\n\n/-- `x^n`, `n : \u2115` is convex on `[0, +\u221e)` for all `n` -/\nlemma convex_on_pow (n : \u2115) : convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_of_deriv2_nonneg (convex_Ici _) (continuous_pow n).continuous_on\n    differentiable_on_pow,\n  { simp only [deriv_pow'], exact (@differentiable_on_pow \u211d _ _ _).const_mul (n : \u211d) },\n  { intros x hx,\n    rw [iter_deriv_pow, finset.prod_range_cast_nat_sub],\n    exact mul_nonneg (nat.cast_nonneg _) (pow_nonneg (interior_subset hx) _) }\nend\n\n/-- `x^n`, `n : \u2115` is strictly convex on `[0, +\u221e)` for all `n` greater than `2`. -/\nlemma strict_convex_on_pow {n : \u2115} (hn : 2 \u2264 n) : strict_convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^n) :=\nbegin\n  apply strict_mono_on.strict_convex_on_of_deriv (convex_Ici _) (continuous_on_pow _)\n    differentiable_on_pow,\n  rw [deriv_pow', interior_Ici],\n  exact \u03bb x (hx : 0 < x) y hy hxy, mul_lt_mul_of_pos_left (pow_lt_pow_of_lt_left hxy hx.le $\n    nat.sub_pos_of_lt hn) (nat.cast_pos.2 $ zero_lt_two.trans_le hn),\nend\n\nlemma finset.prod_nonneg_of_card_nonpos_even\n  {\u03b1 \u03b2 : Type*} [linear_ordered_comm_ring \u03b2]\n  {f : \u03b1 \u2192 \u03b2} [decidable_pred (\u03bb x, f x \u2264 0)]\n  {s : finset \u03b1} (h0 : even (s.filter (\u03bb x, f x \u2264 0)).card) :\n  0 \u2264 \u220f x in s, f x :=\ncalc 0 \u2264 (\u220f x in s, ((if f x \u2264 0 then (-1:\u03b2) else 1) * f x)) :\n  finset.prod_nonneg (\u03bb x _, by\n    { split_ifs with hx hx, by simp [hx], simp at hx \u22a2, exact le_of_lt hx })\n... = _ : by rw [finset.prod_mul_distrib, finset.prod_ite, finset.prod_const_one,\n  mul_one, finset.prod_const, neg_one_pow_eq_pow_mod_two, nat.even_iff.1 h0, pow_zero, one_mul]\n\nlemma int_prod_range_nonneg (m : \u2124) (n : \u2115) (hn : even n) :\n  0 \u2264 \u220f k in finset.range n, (m - k) :=\nbegin\n  rcases hn with \u27e8n, rfl\u27e9,\n  induction n with n ihn, { simp },\n  rw \u2190 two_mul at ihn,\n  rw [\u2190 two_mul, nat.succ_eq_add_one, mul_add, mul_one, bit0, \u2190 add_assoc, finset.prod_range_succ,\n    finset.prod_range_succ, mul_assoc],\n  refine mul_nonneg ihn _, generalize : (1 + 1) * n = k,\n  cases le_or_lt m k with hmk hmk,\n  { have : m \u2264 k + 1, from hmk.trans (lt_add_one \u2191k).le,\n    exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) (sub_nonpos_of_le this) },\n  { exact mul_nonneg (sub_nonneg_of_le hmk.le) (sub_nonneg_of_le hmk) }\nend\n\nlemma int_prod_range_pos {m : \u2124} {n : \u2115} (hn : even n) (hm : m \u2209 Ico (0 : \u2124) n) :\n  0 < \u220f k in finset.range n, (m - k) :=\nbegin\n  refine (int_prod_range_nonneg m n hn).lt_of_ne (\u03bb h, hm _),\n  rw [eq_comm, finset.prod_eq_zero_iff] at h,\n  obtain \u27e8a, ha, h\u27e9 := h,\n  rw sub_eq_zero.1 h,\n  exact \u27e8int.coe_zero_le _, int.coe_nat_lt.2 $ finset.mem_range.1 ha\u27e9,\nend\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` -/\nlemma convex_on_zpow (m : \u2124) : convex_on \u211d (Ioi 0) (\u03bb x : \u211d, x^m) :=\nbegin\n  have : \u2200 n : \u2124, differentiable_on \u211d (\u03bb x, x ^ n) (Ioi (0 : \u211d)),\n    from \u03bb n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),\n  apply convex_on_of_deriv2_nonneg (convex_Ioi 0);\n    try { simp only [interior_Ioi, deriv_zpow'] },\n  { exact (this _).continuous_on },\n  { exact this _ },\n  { exact (this _).const_mul _ },\n  { intros x hx,\n    rw iter_deriv_zpow,\n    refine mul_nonneg _ (zpow_nonneg (le_of_lt hx) _),\n    exact_mod_cast int_prod_range_nonneg _ _ (even_bit0 1) }\nend\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` except `0` and `1`. -/\nlemma strict_convex_on_zpow {m : \u2124} (hm\u2080 : m \u2260 0) (hm\u2081 : m \u2260 1) :\n  strict_convex_on \u211d (Ioi 0) (\u03bb x : \u211d, x^m) :=\nbegin\n  have : \u2200 n : \u2124, differentiable_on \u211d (\u03bb x, x ^ n) (Ioi (0 : \u211d)),\n    from \u03bb n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),\n  apply strict_convex_on_of_deriv2_pos (convex_Ioi 0),\n  { exact (this _).continuous_on },\n   all_goals { rw interior_Ioi },\n  { exact this _ },\n  intros x hx,\n  rw iter_deriv_zpow,\n  refine mul_pos _ (zpow_pos_of_pos hx _),\n  exact_mod_cast int_prod_range_pos (even_bit0 1) (\u03bb hm, _),\n  norm_cast at hm,\n  rw \u2190 finset.coe_Ico at hm,\n  fin_cases hm; cc,\nend\n\nlemma convex_on_rpow {p : \u211d} (hp : 1 \u2264 p) : convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  have A : deriv (\u03bb (x : \u211d), x ^ p) = \u03bb x, p * x^(p-1), by { ext x, simp [hp] },\n  apply convex_on_of_deriv2_nonneg (convex_Ici 0),\n  { exact continuous_on_id.rpow_const (\u03bb x _, or.inr (zero_le_one.trans hp)) },\n  { exact (differentiable_rpow_const hp).differentiable_on },\n  { rw A,\n    assume x hx,\n    replace hx : x \u2260 0, by { simp at hx, exact ne_of_gt hx },\n    simp [differentiable_at.differentiable_within_at, hx] },\n  { assume x hx,\n    replace hx : 0 < x, by simpa using hx,\n    suffices : 0 \u2264 p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],\n    apply mul_nonneg (le_trans zero_le_one hp),\n    exact mul_nonneg (sub_nonneg_of_le hp) (rpow_nonneg_of_nonneg hx.le _) }\nend\n\nlemma strict_convex_on_rpow {p : \u211d} (hp : 1 < p) : strict_convex_on \u211d (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  have A : deriv (\u03bb (x : \u211d), x ^ p) = \u03bb x, p * x^(p-1), by { ext x, simp [hp.le] },\n  apply strict_convex_on_of_deriv2_pos (convex_Ici 0),\n  { exact continuous_on_id.rpow_const (\u03bb x _, or.inr (zero_le_one.trans hp.le)) },\n  { exact (differentiable_rpow_const hp.le).differentiable_on },\n  rw interior_Ici,\n  rintro x (hx : 0 < x),\n  suffices : 0 < p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],\n  exact mul_pos (zero_lt_one.trans hp) (mul_pos (sub_pos_of_lt hp) (rpow_pos_of_pos hx _)),\nend\n\nlemma strict_concave_on_log_Ioi : strict_concave_on \u211d (Ioi 0) log :=\nbegin\n  have h\u2081 : Ioi 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { exact \u03bb x (hx : 0 < x) (hx' : x = 0), hx.ne' hx' },\n  refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 0) is_open_Ioi\n    (differentiable_on_log.mono h\u2081) (\u03bb x (hx : 0 < x), _),\n  rw [function.iterate_succ, function.iterate_one],\n  change (deriv (deriv log)) x < 0,\n  rw [deriv_log', deriv_inv],\n  exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne'),\nend\n\nlemma strict_concave_on_log_Iio : strict_concave_on \u211d (Iio 0) log :=\nbegin\n  have h\u2081 : Iio 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { exact \u03bb x (hx : x < 0) (hx' : x = 0), hx.ne hx' },\n  refine strict_concave_on_open_of_deriv2_neg (convex_Iio 0) is_open_Iio\n    (differentiable_on_log.mono h\u2081) (\u03bb x (hx : x < 0), _),\n  rw [function.iterate_succ, function.iterate_one],\n  change (deriv (deriv log)) x < 0,\n  rw [deriv_log', deriv_inv],\n  exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne),\nend\n\nsection sqrt_mul_log\n\nlemma deriv_sqrt_mul_log (x : \u211d) (hx : 0 < x) :\n  deriv (\u03bb x, sqrt x * log x) x = (2 + log x) / (2 * sqrt x) :=\nbegin\n  simp only [sqrt_eq_rpow],\n  refine (deriv_mul (has_deriv_at_rpow_const (or.inl hx.ne')).differentiable_at\n    (differentiable_at_log hx.ne')).trans _,\n  rw [deriv_rpow_const (or.inl hx.ne'), deriv_log, add_comm],\n  simp only [div_eq_mul_inv, mul_inv, \u2190rpow_neg hx.le, \u2190rpow_neg_one x, \u2190rpow_add hx],\n  rw [add_mul, mul_comm (log x), \u2190mul_assoc],\n  norm_num,\nend\n\nlemma deriv2_sqrt_mul_log (x : \u211d) (hx : 0 < x) :\n  deriv^[2] (\u03bb x, sqrt x * log x) x = -log x / (4 * sqrt x ^ 3) :=\nbegin\n  let h := (has_deriv_at_rpow_const (or.inl hx.ne')).differentiable_at,\n  rw [function.iterate_succ, function.iterate_one, function.comp_app,\n      \u2190deriv_within_of_open is_open_Ioi (set.mem_Ioi.mpr hx)],\n  refine (deriv_within_congr (unique_diff_on_Ioi 0 x hx) deriv_sqrt_mul_log\n    (deriv_sqrt_mul_log x hx)).trans _,\n  simp only [sqrt_eq_rpow],\n  rw [deriv_within_of_open is_open_Ioi (set.mem_Ioi.mpr hx),\n      deriv_div ((differentiable_at_log hx.ne').const_add 2) (h.const_mul 2)\n      (ne_of_gt (mul_pos two_pos (rpow_pos_of_pos hx 0.5))), deriv_const_add, deriv_log,\n      deriv_const_mul 2 h, deriv_rpow_const (or.inl hx.ne'), one_div, mul_comm x\u207b\u00b9, mul_assoc,\n      mul_inv_cancel_left\u2080 (show (2 : \u211d) \u2260 (0 : \u211d), from two_ne_zero), \u2190div_eq_mul_inv,\n      \u2190rpow_sub_one hx.ne', \u2190sub_mul, sub_add_cancel', mul_pow, \u2190div_div_eq_mul_div, \u2190mul_div],\n    simp only [mul_pow, pow_succ, pow_zero, mul_one, \u2190rpow_add hx, \u2190rpow_sub hx],\n    norm_num,\nend\n\nlemma strict_concave_on_sqrt_mul_log_Ioi : strict_concave_on \u211d (set.Ioi 1) (\u03bb x, sqrt x * log x) :=\nbegin\n  refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 1) is_open_Ioi\n    (\u03bb x hx, differentiable_within_at_of_deriv_within_ne_zero _) (\u03bb x hx, _),\n  { rw [deriv_within_of_open is_open_Ioi hx, deriv_sqrt_mul_log x (zero_lt_one.trans hx)],\n    refine div_ne_zero _ (mul_ne_zero two_ne_zero (sqrt_ne_zero'.mpr (zero_lt_one.trans hx))),\n    linarith [log_pos hx] },\n  { rw deriv2_sqrt_mul_log x (zero_lt_one.trans hx),\n    exact div_neg_of_neg_of_pos (neg_neg_of_pos (log_pos hx))\n      (mul_pos four_pos (pow_pos (sqrt_pos.mpr (zero_lt_one.trans hx)) 3)) },\nend\n\nend sqrt_mul_log\n\nopen_locale real\n\nlemma strict_concave_on_sin_Icc : strict_concave_on \u211d (Icc 0 \u03c0) sin :=\nbegin\n  apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_sin\n    differentiable_sin.differentiable_on (\u03bb x hx, _),\n  rw interior_Icc at hx,\n  simp [sin_pos_of_mem_Ioo hx],\nend\n\nlemma strict_concave_on_cos_Icc : strict_concave_on \u211d (Icc (-(\u03c0/2)) (\u03c0/2)) cos :=\nbegin\n  apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_cos\n    differentiable_cos.differentiable_on (\u03bb x hx, _),\n  rw interior_Icc at hx,\n  simp [cos_pos_of_mem_Ioo hx],\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/convex/specific_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.7159711461645528}}
{"text": "import algebra.order.group\nimport tactic\n\n\n\nprivate def only_those {T : Type} (cond : T \u2192 T \u2192 Prop) [\u2200 n, \u2200 m, decidable (cond n m)] : T \u2192 list T \u2192 list T\n| p []        := []\n| p (x :: xs) := if (cond x p) then x :: only_those p xs else only_those p xs\n\nprivate lemma size_cap {T : Type} {cond : T \u2192 T \u2192 Prop} [\u2200 n, \u2200 m, decidable (cond n m)] {pivot : T} {lizt : list T} :\n  (only_those cond pivot lizt).sizeof < (pivot :: lizt).sizeof  :=\nbegin\n  induction lizt with head tail ih,\n    unfold only_those,\n    unfold list.sizeof,\n    linarith,\n\n    unfold list.sizeof,\n    by_cases cond head pivot,\n\n      -- here `cond` holds\n      have unwrap_yes : only_those cond pivot (head :: tail) = head :: only_those cond pivot tail,\n      {\n        unfold only_those,\n        simp,\n        contrapose!,\n        intro _,\n        exact h,\n      },\n      calc (only_those cond pivot (head :: tail)).sizeof \n           = (head :: only_those cond pivot tail).sizeof             : by rw unwrap_yes\n      ...  = 1 + (sizeof head) + (only_those cond pivot tail).sizeof : by unfold list.sizeof\n      ...  < 1 + (sizeof head) + (pivot :: tail).sizeof              : by linarith  -- uses `ih` and `add_le_add` afaik\n      ...  = 1 + (sizeof head) + (1 + (sizeof pivot) + tail.sizeof)  : by unfold list.sizeof,\n      \n      -- here `cond` does not hold\n      have unwrap_no : only_those cond pivot (head :: tail) = only_those cond pivot tail,\n      {\n        unfold only_those,\n        simp,\n        contrapose,\n        intro _,\n        exact h,\n      },\n      calc (only_those cond pivot (head :: tail)).sizeof \n           = (only_those cond pivot tail).sizeof                    : by rw unwrap_no\n      ...  < (pivot :: tail).sizeof                                 : ih\n      ...  =                     (1 + (sizeof pivot) + tail.sizeof) : by unfold list.sizeof\n      ...  \u2264 1 + (sizeof head) + (1 + (sizeof pivot) + tail.sizeof) : le_add_self\nend\n\n\nvariable {L : Type}\nvariable [linear_order L]\n\nprivate def only_le : L \u2192 list L \u2192 list L :=\n  only_those (\u2264)\n\nprivate def only_gt : L \u2192 list L \u2192 list L :=\n  only_those (>)\n\n\ndef kviksort : list L \u2192 list L\n| []        := []\n| (x :: xs) := have (only_le x xs).sizeof < (x :: xs).sizeof, from size_cap,\n               have (only_gt x xs).sizeof < (x :: xs).sizeof, from size_cap,\n               kviksort (only_le x xs) ++ [x] ++ kviksort (only_gt x xs)\n\n\n#eval kviksort [14, 8, 2, 20, 15, 0, 11, 18, 7, 6, 3, 13, 10, 17, 1, 4, 5, 9, 19, 12, 16, 10]\n-- Result should be a sequence of integers 0..20 where 10 is twice.\n", "meta": {"author": "madvorak", "repo": "Lean-first-steps", "sha": "4cfee162afaa53b589ec7a94986d78d75cf1c85e", "save_path": "github-repos/lean/madvorak-Lean-first-steps", "path": "github-repos/lean/madvorak-Lean-first-steps/Lean-first-steps-4cfee162afaa53b589ec7a94986d78d75cf1c85e/src/Quicksort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7159283946497291}}
{"text": "--import data.set\nimport tactic\n\n-- dEAduction tactics\nimport structures2      -- hypo_analysis, targets_analysis\nimport utils            -- no_meta_vars\nimport user_notations   -- notations that can be used in deaduction UI for a new object\n\n-- dEAduction definitions\nimport set_definitions\n\n-- General principles :\n-- Type should be defined as parameters, in order to be implicit everywhere\n-- other parameters are implicit in definitions, i.e. defined using '{}' (e.g. {A : set X} )\n-- but explicit everywhere else, i.e. defined using '()' (e.g. (A : set X) )\n-- each definition must be an iff statement (since it will be called with 'rw' or 'symp_rw')\n\n---------------------\n-- Course metadata --\n---------------------\n-- logic names ['and', 'or', 'negate', 'implicate', 'iff', 'forall', 'exists', 'equal', 'map']\n-- proofs names ['use_proof_methods', 'new_object']\n-- proof methods names ['cbr', 'contrapose', 'absurdum', 'sorry']\n-- magic names ['compute', 'assumption']\n\n\n\n/- dEAduction\nTitle\n    exercices de math\u00e9matiques discretes.\nAuthor\n    Alice Laroche\nInstitution\n    \nAvailableMagic\n    ALL\nDescription\n    Exercices d'un cours de maths discr\u00e8tes \u00e0 Sorbonne Universit\u00e9.\n    Les num\u00e9ros de questions font r\u00e9f\u00e9rence \u00e0 la feuille de TD.\n-/\n\nnamespace set\n\n-- def disjoint {X : Type} (A B : set X) : Prop := A \u2229 B = \u2205\n\ndef partition {X :Type} (A : set (set X)) := (\u2200A\u2081 \u2208 A , A\u2081 \u2260 \u2205) \u2227 (\u2200A\u2081 A\u2082 \u2208 A, (A\u2081 \u2229 A\u2082 = \u2205) \u2228 A\u2081 = A\u2082) \u2227 (\u2200x, \u2203A\u2081 \u2208 A, x \u2208 A\u2081)\n\nend set\n\nnamespace relation\n\ndef inv {X Y : Type} (R : set (X \u00d7 Y)) : set (Y \u00d7 X)\n| (x, y) := (y, x) \u2208 R\n\ndef product {X Y Z : Type} (R : set (X \u00d7 Y)) (R' : set (Y \u00d7 Z)) : set (X \u00d7 Z)\n| (x, y) := \u2203z, (x, z) \u2208 R \u2227 (z, y) \u2208 R'\n\ndef identite {X: Type} : set (X \u00d7 X)\n| (x, y) := x = y\n\ndef reflexive {X : Type} (R : set (X \u00d7 X)) := \u2200x, (x, x) \u2208 R\n\ndef transitive {X : Type} (R: set (X \u00d7 X)) := \u2200x y z, (x, y) \u2208 R \u2227 (y, z) \u2208 R \u2192 (x, z) \u2208 R\n\ndef symetrique {X : Type} (R : set (X \u00d7 X)) := \u2200x y, (x, y) \u2208 R \u2192 (y, x) \u2208 R\n\ndef antisymetrique {X : Type} (R : set (X \u00d7 X)) := \u2200x y, (x, y) \u2208 R \u2227 (y, x) \u2208 R \u2192 x = y\n\ndef relation_equivalence {X : Type} (R : set (X \u00d7 X)) := reflexive R \u2227 transitive R \u2227 symetrique R\n\ndef relation_ordre {X : Type} (R : set (X \u00d7 X)) := reflexive R \u2227 transitive R \u2227 antisymetrique R\n\ndef classe_equivalence {X : Type} (R : set (X \u00d7 X)) (h1 : relation_equivalence R) (e : X) : set X\n| e' :=  (e, e')  \u2208 R\n\n\ndef deterministe {X Y : Type} (R : set (X \u00d7 Y)) := \u2200x y z, (x, y) \u2208 R \u2227 (x, z) \u2208 R \u2192 y = z \n\ndef total_gauche {X Y : Type} (R : set (X \u00d7 Y)) := \u2200x, \u2203y, (x, y) \u2208 R \n\ndef application {X Y : Type} (R : set (X \u00d7 Y)) := deterministe R \u2227 total_gauche R\n\ndef injective {X Y : Type} (R : set (X \u00d7 Y)) := \u2200x y z, (x, z) \u2208 R \u2227 (y, z) \u2208 R \u2192 x = y\n\ndef surjective {X Y : Type} (R : set (X \u00d7 Y)) := \u2200y, \u2203x, (x, y) \u2208 R\n\ndef application_injective {X Y : Type} (R : set (X \u00d7 Y)) := application R \u2227 injective R\n\ndef application_surjective {X Y : Type} (R : set (X \u00d7 Y)) := application R \u2227 surjective R\n\ndef application_bijective {X Y : Type} (R : set (X \u00d7 Y)) := application R \u2227 injective R \u2227 surjective R\n\ndef image {X Y : Type} (R : set (X \u00d7 Y)) (x : X) (y : Y) := (x, y) \u2208 R \n\nend relation\n\n\nlocal attribute [instance] classical.prop_decidable\n\n---------------------------------------------\n-- global parameters = implicit variables --\n---------------------------------------------\nsection course\nparameters {X Y Z: Type}\n\nopen set\nopen relation\n\nnotation [parsing_only] R `.` S := relation.product R S\n\nnotation R `\u207b\u00b9`  := relation.inv R\nnotation R `dot` S := relation.product R S\n\n\n------------------\n-- COURSE TITLE --\n------------------\nnamespace math_discretes\n/- dEAduction\nPrettyName\n    Math\u00e9matiques discr\u00e8tes\n-/\n\nnamespace generalites\n/- dEAduction\nPrettyName\n    G\u00e9n\u00e9ralit\u00e9s\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\nlemma definition.inclusion {A B : set X} : A \u2286 B \u2194 \u2200 {x:X}, x \u2208 A \u2192 x \u2208 B :=\n/- dEAduction\nPrettyName\n    Inclusion\nImplicitUse\n    True    \n-/\nbegin\n    todo,\nend\n\nlemma definition.egalite_deux_ensembles {A A' : set X} :\n(A = A') \u2194 ( \u2200 x, x \u2208 A \u2194 x \u2208 A' ) :=\n/- dEAduction\nPrettyName\n    Egalit\u00e9 de deux ensembles\nImplicitUse\n    True\n-/\nbegin\n    exact set.ext_iff,\nend\n\n-- lemma definition.inegalite_deux_ensembles {A A' : set X} :\n-- (A \u2260 A') \u2194 ( \u2203x, (x \u2208 A \u2227 x \u2209 A') \u2228 (x \u2208 A' \u2227 x \u2209 A)) :=\n-- /- dEAduction\n-- PrettyName\n--     In\u00e9galit\u00e9 de deux ensembles\n-- -/\n-- begin\n--     todo,\n-- end\n\nlemma definition.ensemble_vide\n(A: set X) :\n(A = \u2205) \u2194 \u2200 x : X, x \u2209 A\n:=\nbegin\n    exact eq_empty_iff_forall_not_mem,\nend\n\nlemma definition.ensemble_extension {X: Type}  {P : X \u2192 Prop} {x:X} :\n x \u2208 {x | P x} \u2194 P x\n:=\n/- dEAduction\nPrettyName\n    Ensemble en extension\n-/\nbegin\n    refl,\nend\n\nlemma definition.singleton : \u2200 {X : Type} {x y : X}, x \u2208 ({y} : set X) \u2194 x = y\n:=\n/- dEAduction\nPrettyName\n    Singleton\n-/\nbegin\n    intros X x y, exact mem_singleton_iff,\nend\n\nlemma definition.double_inclusion (A A' : set X) :\nA = A' \u2194 (A \u2286 A' \u2227 A' \u2286 A) :=\n/- dEAduction\nPrettyName\n    Double inclusion\nImplicitUse\n    True\n-/\nbegin\n    exact set.subset.antisymm_iff,\nend\n\nlemma definition.ensemble_partie (A A' : set X) :\nA' \u2208 \ud835\udcab(A) \u2194  A' \u2286 A\n:= \n/- dEAduction\nPrettyName\n    Ensemble des parties\n-/\nbegin\n    refl,\nend\n\nend generalites\n\n\nnamespace union_intersection\n/- dEAduction\nPrettyName\n    Unions et intersections\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\n\nlemma definition.intersection_deux_ensembles {A B : set X} {x : X} :\nx \u2208 A \u2229 B \u2194 ( x \u2208 A \u2227 x \u2208 B) :=\n/- dEAduction\nPrettyName\n    Intersection de deux ensembles\nImplicitUse\n    True\n-/\nbegin\n    exact iff.rfl,\nend\n\nlemma definition.intersection_union (A B C : set X) :\nA \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\n/- dEAduction\nPrettyName\n   Intersection avec une union\nImplicitUse\n    True\n-/\nbegin\n  exact set.inter_distrib_left A B C,\nend\n\nlemma definition.partition \n {P : set (set X)} : \n partition P \u2194 (\u2200A\u2081 \u2208 P , A\u2081 \u2260 \u2205) \u2227 (\u2200A\u2081 A\u2082 \u2208 P, (A\u2081 \u2229 A\u2082 = \u2205) \u2228 A\u2081 = A\u2082) \u2227 (\u2200x, \u2203A\u2081 \u2208 P, x \u2208 A\u2081)\n:=\n/- dEAduction\nPrettyName\n   Partition\n-/\nbegin\n    todo\nend\n-- lemma definition.intersection_videI (A : set X) :\n-- A \u2229 \u2205 = \u2205 :=\n-- /- dEAduction\n-- PrettyName\n--     Intersection avec l'ensemble vide I \n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact inter_empty A,\n-- end\n\n-- lemma definition.intersection_videII (A : set X) :\n-- \u2205 \u2229 A = \u2205 :=\n-- /- dEAduction\n-- PrettyName\n--     Intersection avec l'ensemble vide II\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact empty_inter A,\n-- end\n\n-- lemma definition.union_deux_ensembles  {A : set X} {B : set X} {x : X} :\n-- x \u2208 A \u222a B \u2194 ( x \u2208 A \u2228 x \u2208 B) :=\n-- /- dEAduction\n-- PrettyName\n--     Union de deux ensembles\n-- ImplicitUse\n--     True\n-- -/\n-- begin\n--     exact iff.rfl,\n-- end\n\n-- lemma definition.union_intersection (A B C : set X) :\n-- A \u222a (B \u2229 C) = (A \u222a B) \u2229 (A \u222a C) :=\n-- /- dEAduction\n-- PrettyName\n--    Union avec une intersection\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--   exact set.union_distrib_left A B C,\n-- end\n\n-- lemma definition.union_videI (A : set X) :\n-- A \u222a \u2205 = A :=\n-- /- dEAduction\n-- PrettyName\n--     Union avec l'ensemble vide I\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact union_empty A,\n-- end\n\n-- lemma definition.union_videII (A : set X) :\n-- \u2205 \u222a A = A :=\n-- /- dEAduction\n-- PrettyName\n--     Union avec l'ensemble vide II\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact empty_union A,\n-- end\n\nend union_intersection\n\nnamespace complementaire\n/- dEAduction\nPrettyName\n    Compl\u00e9mentaire\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\n\nlemma definition.complement {A : set X} {x : X} : x \u2208 set.compl A \u2194 x \u2209 A :=\n/- dEAduction\nPrettyName\n    Complementaire\nImplicitUse\n    False\n-/\nbegin\n    finish,\nend\n\nlemma definition.difference {A A' : set X} {x : X} : x \u2208 set.diff A A' \u2194 x \u2208 A \u2227 x \u2209 A' :=\n/- dEAduction\nPrettyName\n    Diff\u00e9rence\nImplicitUse\n    False\n-/\nbegin\n    finish,\nend\n-- lemma definition.complement_complement {A : set X} : (set.compl (set.compl A)) = A :=\n-- /- dEAduction\n-- PrettyName\n--     Complementaire du complementaire\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact compl_compl',\n-- end\n\n-- lemma definition.complement_intersection {A B : set X} :\n-- set.compl (A \u2229 B) = (set.compl A) \u222a (set.compl B) :=\n-- /- dEAduction\n-- PrettyName\n--     Complementaire d'une intersection\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact compl_inter A B,\n-- end\n\n-- lemma definition.intersection_complement {A : set X} :\n-- A \u2229 set.compl (A) = \u2205 :=\n-- /- dEAduction\n-- PrettyName\n--     Intersection avec le compl\u00e9mentaire\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact inter_compl_self A,\n-- end\n\n-- lemma definition.complement_union {A B : set X} :\n-- set.compl (A \u222a B) = (set.compl A) \u2229 (set.compl B) :=\n-- /- dEAduction\n-- PrettyName\n--     Complementaire d'une union\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact compl_union A B,\n-- end\n\n-- lemma definition.union_complement {A : set X} :\n-- A \u222a set.compl (A) = univ :=\n-- /- dEAduction\n-- PrettyName\n--     Union avec le compl\u00e9mentaire\n-- ImplicitUse\n--     False\n-- -/\n-- begin\n--     exact union_compl_self A,\n-- end\n\nend complementaire\n\nnamespace produits_cartesiens\n/- dEAduction\nPrettyName\n    Produits cart\u00e9siens\n-/\n\n-- lemma definition.type_produit :\n-- \u2200 z:X \u00d7 Y, \u2203 x:X, \u2203 y:Y, z = (x,y) :=\n-- /- dEAduction\n-- PrettyName\n--     Element d'un produit cart\u00e9sien de deux ensembles\n-- -/\n-- begin\n--     todo\n-- end\n\n\nlemma definition.produit_de_parties {A : set X} {B : set Y} {x:X} {y:Y} :\n(x,y) \u2208 set.prod A B \u2194 x \u2208 A \u2227 y \u2208 B :=\n/- dEAduction\nPrettyName\n    Produit cart\u00e9sien de deux parties\n-/\nbegin\n    todo\nend\n\nend produits_cartesiens\n\nnamespace relations\n/- dEAduction\nPrettyName\n    Relations\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\n\nlemma definition.inv {R : set (X \u00d7 Y)} {x : X} {y : Y} :\n(y,x) \u2208 (inv R) \u2194 (x,y) \u2208 R :=\n/- dEAduction\nPrettyName\n    Inverse d'une relation\n-/\nbegin\n    refl,\nend\n\nlemma definition.prod {R : set (X \u00d7 Y)} {S : set (Y \u00d7 Z)} {x : X} {z : Z} :\n(x,z) \u2208 (product R S) \u2194 \u2203y, (x,y) \u2208 R \u2227 (y,z) \u2208 S :=\n/- dEAduction\nPrettyName\n    Produit de deux relations\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.id {x : X} {y : X} :\n(x,y) \u2208 (identite : set (X \u00d7 X))  \u2194 x = y :=\n/- dEAduction\nPrettyName\n    Relation identit\u00e9\n-/\nbegin\n    refl,\nend\n\nlemma theorem.id :\n\u2200 x:X,  (x,x) \u2208 (identite : set (X \u00d7 X)) :=\n/- dEAduction\nPrettyName\n    Relation identit\u00e9\n-/\nbegin\n    intro x, rw definition.id,\nend\n\nlemma definition.reflexive {R : set (X \u00d7 X)} :\nreflexive R \u2194 \u2200x, (x, x) \u2208 R :=\n/- dEAduction\nPrettyName\n    R\u00e9flexivit\u00e9\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.transitive {R : set (X \u00d7 X)} :\ntransitive R \u2194 \u2200x y z, (x, y) \u2208 R \u2227 (y, z) \u2208 R \u2192 (x, z) \u2208 R :=\n/- dEAduction\nPrettyName\n    Transitivit\u00e9\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.symetrique {R : set (X \u00d7 X)} :\nsymetrique R \u2194 \u2200x y, (x, y) \u2208 R \u2192 (y, x) \u2208 R:=\n/- dEAduction\nPrettyName\n    Sym\u00e9trie\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.antisymetrique {R : set (X \u00d7 X)} :\nantisymetrique R \u2194 \u2200x y, (x, y) \u2208 R \u2227 (y, x) \u2208 R \u2192 x = y :=\n/- dEAduction\nPrettyName\n    Antisym\u00e9trie\n-/\nbegin\n    refl,\nend\n\nlemma definition.equivalence {R : set (X \u00d7 X)} :\nrelation_equivalence R \u2194 reflexive R \u2227 transitive R \u2227 symetrique R :=\n/- dEAduction\nPrettyName\n    Relation d'\u00e9quivalence\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.ordre {R : set (X \u00d7 X)} :\nrelation_ordre R \u2194 reflexive R \u2227 transitive R \u2227 antisymetrique R :=\n/- dEAduction\nPrettyName\n    Relation d'ordre\n-/\nbegin\n    refl,\nend\n\nlemma definition.classe_equivalence {x y : X} {R : set (X \u00d7 X)} {h1 : relation_equivalence R}:\ny \u2208 classe_equivalence R h1 x \u2194 (x, y) \u2208 R :=\n/- dEAduction\nPrettyName\n    Classe d'\u00e9quivalence\n-/\nbegin\n    refl,\nend \nend relations\n\n-- namespace applications\n\n-- lemma definition.deterministe {X Y : Type} (R : set (X \u00d7 Y)) \n-- : deterministe R \u2194 \u2200x y z, (x, y) \u2208 R \u2227 (x, z) \u2208 R \u2192 y = z :=\n-- /- dEAduction\n-- PrettyName\n--     Relation d\u00e9terministe\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.total_gauche {X Y : Type} (R : set (X \u00d7 Y)) :\n-- total_gauche R \u2194 \u2200x, \u2203y, (x, y) \u2208 R :=\n-- /- dEAduction\n-- PrettyName\n--     Relation totale\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application R \u2194 deterministe R \u2227 total_gauche R :=\n-- /- dEAduction\n-- PrettyName\n--      Relation et application\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.relation_injective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- relation.injective R \u2194 \u2200x y z, (x, z) \u2208 R \u2227 (y, z) \u2208 R \u2192 x = y :=\n-- /- dEAduction\n-- PrettyName\n--     Relation injective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.relation_surjective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- relation.surjective R \u2194 \u2200y, \u2203x, (x, y) \u2208 R :=\n-- /- dEAduction\n-- PrettyName\n--     Relation surjective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application_injective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application_injective R \u2194 application R \u2227 relation.injective R :=\n-- /- dEAduction\n-- PrettyName\n--     Application injective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application_surjective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application_surjective R \u2194 application R \u2227 relation.surjective R :=\n-- /- dEAduction\n-- PrettyName\n--     Application surjective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.application_bijective {X Y : Type} (R : set (X \u00d7 Y)) :\n-- application_bijective R \u2194 application R \u2227 relation.injective R \u2227 relation.surjective R :=\n-- /- dEAduction\n-- PrettyName\n--     Application bijective\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- lemma definition.image {X Y : Type} (R : set (X \u00d7 Y)) (x : X) (y : Y) : \n-- image R x y \u2194 (x, y) \u2208 R :=\n-- /- dEAduction\n-- PrettyName\n--     Image d'une relation\n-- -/\n-- begin\n--     refl,\n-- end\n\n-- end applications\n\n---------------\n-- EXERCICES --\n---------------\nnamespace exercices \n/- dEAduction\nPrettyName\n    Exercices\n-/\n\nvariables  {A B C : set X}\n\nnamespace exercice2\n/- dEAduction\nPrettyName\n    Exercice 2\n-/\n\nlemma exercise.question1 :\n(A \u2229 compl (A \u2229 B)) = (A \u2229 compl B) :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question2 :\nA \u2229 B = A \u2229 C \u2192 A \u2229 compl B = A \u2229 compl C :=\n/- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 :\nA \u2229 B = A \u2229 C \u2194 A \u2229 (compl B) = A \u2229 (compl C) :=\n/- dEAduction\nPrettyName\n    Question 3\nDescription\n    Deduire de la question pr\u00e9cedente l'\u00e9quivalence des deux \u00e9nonc\u00e9s.\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question4 :\nA \u222a B \u2286 A \u222a C \u2227 A \u2229 B \u2286 A \u2229 C \u2192 B \u2286 C :=\n/- dEAduction\nPrettyName\n    Question 4\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question5 : \nset.prod A (B \u222a C) = set.prod A B \u222a set.prod A C :=\n/- dEAduction\nPrettyName\n    Question 5\n-/ \nbegin\n    todo,\nend\n\n-- lemma exercise.question61 :\n-- \ud835\udcab(A \u222a B) = \ud835\udcab(A) \u222a \ud835\udcab(B) \u2228 \u00ac\ud835\udcab(A \u222a B) = \ud835\udcab(A) \u222a \ud835\udcab(B) :=  \n-- /- dEAduction\n-- PrettyName\n--     Question 6.1\n-- OpenQuestion\n--     True\n-- -/\n-- begin\n--     todo,\n-- end\n\nlemma exercise.question62 :\n\ud835\udcab(A \u2229 B) = \ud835\udcab(A) \u2229 \ud835\udcab(B) :=  \n/- dEAduction\nPrettyName\n    Question 6.2\n-/\nbegin\n    todo,\nend\n\n--\ud835\udcab(E \u222a {x}) = \ud835\udcab(E) \u222a {A' | \u2203A \u2208 \ud835\udcab(E), A' = A \u222a {x}} :=\nlemma exercise.question7 (F : Type) (E : set F) (x : F) (h : x \u2209 E) :\n\ud835\udcab(E \u222a {x}) = \ud835\udcab(E) \u222a {A' | \u2203A \u2286 E, A' = A \u222a {x}} :=\n/- dEAduction\nPrettyName\n    Question 7\n-/\nbegin\n    todo,\nend\n\nend exercice2\n\nnamespace exercice5\n/- dEAduction\nPrettyName\n    Exercice 5\n-/\n\nlemma exercise.question2_produit_inverse (X Y Z : Type) (R : set (X \u00d7 Y)) (S : set (Y \u00d7 Z)) :\n (R dot S) \u207b\u00b9 = ((S \u207b\u00b9) dot (R \u207b\u00b9)) :=\n /- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\nend exercice5\n\nnamespace exercice6\n/- dEAduction\nPrettyName\n    Exercice 6\n-/\n\nlemma exercise.question1 (X: Type) (R : set (X \u00d7 X)) :\nreflexive R \u2194 identite \u2286 R :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question2 (X: Type) (R : set (X \u00d7 X)) :\nsymetrique R \u2194 R = inv R  :=\n/- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 (X: Type) (R : set (X \u00d7 X)) :\nantisymetrique R \u2194 (R \u2229 (inv R)) \u2286 identite :=\n/- dEAduction\nPrettyName\n    Question 3\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question4 (X: Type) (R : set (X \u00d7 X)) :\ntransitive R \u2194 (product R R) \u2286 R :=\n/- dEAduction\nPrettyName\n    Question 4\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question5 (X: Type) (R : set (X \u00d7 X)) :\nreflexive R \u2192 R \u2286 (R dot R) \u2227 reflexive (R dot R) :=\n/- dEAduction\nPrettyName\n    Question 5\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question6 (X: Type) (R : set (X \u00d7 X)) :\nsymetrique R \u2192 (R \u207b\u00b9 dot R) = (R dot R \u207b\u00b9) :=\n/- dEAduction\nPrettyName\n    Question 6\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question7 (X: Type) (R : set (X \u00d7 X)) :\ntransitive R \u2192 transitive (R dot R) :=\n/- dEAduction\nPrettyName\n    Question 7\n-/\nbegin\n    todo,\nend\nend exercice6\n\nnamespace exercice8\n/- dEAduction\nPrettyName\n    Exercice 8\n-/\n\nlemma exercise.question1 (A : Type) (R : set (A \u00d7 A)) (h1 : relation_equivalence R) :\n\u2200a, a \u2208 classe_equivalence R h1 a :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question2 (A : Type) (R : set (A \u00d7 A)) (h1 : relation_equivalence R) (a b : A) :\nclasse_equivalence R h1 a = classe_equivalence R h1 b \u2194 (a,b) \u2208 R :=\n/- dEAduction\nPrettyName\n    Question 2\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 (A : Type) (R : set (A \u00d7 A)) (h1 : relation_equivalence R) (a b : A) :\nclasse_equivalence R h1 a \u2260 classe_equivalence R h1 b \u2192 classe_equivalence R h1 a \u2229 classe_equivalence R h1 b = \u2205 :=\n/- dEAduction\nPrettyName\n    Question 3\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question5 (A : Type) (R : set (A \u00d7 A)) (h1 : relation_equivalence R) :\npartition {A\u2081 | \u2203x, A\u2081 = classe_equivalence R h1 x} :=\n/- dEAduction\nPrettyName\n    Question 5\n-/\nbegin\n    todo,\nend\n\nend exercice8\n\n-- namespace exercice15\n-- /- dEAduction\n-- PrettyName\n--     Exercice 15\n-- -/\n\n-- -- TODO: int\u00e9grer les defs pour applications (composition, id, bijective)\n-- lemma exercise.question (X : Type) (f : X \u2192 X) :\n-- ((composition f f) = id : X \u2192 X) \u2192 bijective f:=\n-- /- dEAduction\n-- PrettyName\n--     Question 1\n-- -/\n-- begin\n--     todo,\n-- end\n-- end exercice15\n\nnamespace exercice22\n/- dEAduction\nPrettyName\n    Exercice 22\n-/\n\nlemma exercise.question1 (X Y : Type) (f : X \u2192 Y) (R : set (X \u00d7 X)) (H1 : \u2200x x', (x, x') \u2208 R \u2194 f x = f x') :\nrelation_equivalence R :=\n/- dEAduction\nPrettyName\n    Question 1\n-/\nbegin\n    todo,\nend\n\nlemma exercise.question3 (X Y : Type) (f : X \u2192 Y) (R : set (X \u00d7 X)) (H1 : \u2200x x', (x, x') \u2208 R \u2194 f x = f x')\n(H2: relation_equivalence R) :\n\u2200x y, x \u2208 classe_equivalence R H2 y \u2192 classe_equivalence R H2 x = classe_equivalence R H2 y :=\n/- dEAduction\nPrettyName\n    Question 3\n-/\nbegin\n    todo,\nend\n\n-- lemma exercise.question41 (E F : Type) (f : set (E \u00d7 F)) (h1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (S : set (E \u00d7 (set E))) (h6 : \u2200x y, relation.image S x y \u2194 y = classe_equivalence Rf h3 x) :\n-- relation.injective S \u2228 \u00acrelation.injective S :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 4.1\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question42 (E F : Type) (f : set (E \u00d7 F)) (h1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (S : set (E \u00d7 (set E))) (h6 : \u2200x y, relation.image S x y \u2194 y = classe_equivalence Rf h3 x) :\n-- relation.surjective S \u2228 \u00acrelation.surjective S :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 4.2\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question5 (E F : Type) (f : set (E \u00d7 F)) (h1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (f' : set ((set E) \u00d7 F)) (h6 : \u2200X y, (X, y) \u2208 f' \u2194 \u2203x \u2208 X, relation.image f x y) :\n-- application f' :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 5\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question61 (E F : Type) (f : set (E \u00d7 F)) (h1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (f' : set ((set E) \u00d7 F)) (h6 : \u2200X y, (X, y) \u2208 f' \u2194 \u2203x \u2208 X, relation.image f x y) :\n-- relation.injective f' \u2228 \u00ac relation.injective f' :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 6.1\n-- -/\n-- begin\n--     todo,\n-- end\n\n-- lemma exercise.question62 (E F : Type) (f : set (E \u00d7 F)) (h1 : application f) \n-- (Rf : set (E \u00d7 E)) (h2 : \u2200x y, (x,y) \u2208 Rf \u2194 (\u2203z, image f x z \u2227 image f y z)) (h3 : relation_equivalence Rf)\n-- (h4 : \u00acrelation.injective Rf) (h5 : \u00acrelation.surjective Rf)\n-- (f' : set ((set E) \u00d7 F)) (h6 : \u2200X y, (X, y) \u2208 f' \u2194 \u2203x \u2208 X, relation.image f x y) :\n-- relation.injective f' \u2228 \u00ac relation.injective f' :=\n-- /- dEAduction\n-- PrettyName\n--     ** Question 6.2\n-- -/\n-- begin\n--     todo,\n-- end\n\n\nend exercice22\n\nend exercices\n\n\nend math_discretes\nend course\n\n", "meta": {"author": "dEAduction", "repo": "dEAduction-lean", "sha": "4fe1d642078fc94f9081ccbed08e047e86a741fd", "save_path": "github-repos/lean/dEAduction-dEAduction-lean", "path": "github-repos/lean/dEAduction-dEAduction-lean/dEAduction-lean-4fe1d642078fc94f9081ccbed08e047e86a741fd/snippets/new_exercises_about_to_be_released/exercices_math_discretes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7159283878625746}}
{"text": "/-\nCopyright (c) 2021 Kalle Kyt\u00f6l\u00e4. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kyt\u00f6l\u00e4\n-/\nimport measure_theory.measure.probability_measure\nimport measure_theory.measure.lebesgue\n\n/-!\n# Characterizations of weak convergence of finite measures and probability measures\n\nThis file will provide portmanteau characterizations of the weak convergence of finite measures\nand of probability measures, i.e., the standard characterizations of convergence in distribution.\n\n## Main definitions\n\nThis file does not introduce substantial new definitions: the topologies of weak convergence on\nthe types of finite measures and probability measures are already defined in their corresponding\nfiles.\n\n## Main results\n\nThe main result will be the portmanteau theorem providing various characterizations of the\nweak convergence of measures. The separate implications are:\n * `measure_theory.finite_measure.limsup_measure_closed_le_of_tendsto` proves that weak convergence\n   implies a limsup-condition for closed sets.\n * `measure_theory.limsup_measure_closed_le_iff_liminf_measure_open_ge` proves for probability\n   measures the equivalence of the limsup condition for closed sets and the liminf condition for\n   open sets.\n * `measure_theory.tendsto_measure_of_null_frontier` proves that the liminf condition for open\n   sets (which is equivalent to the limsup condition for closed sets) implies the convergence of\n   probabilities of sets whose boundary carries no mass under the limit measure.\n * `measure_theory.probability_measure.tendsto_measure_of_null_frontier_of_tendsto` is a\n   combination of earlier implications, which shows that weak convergence of probability measures\n   implies the convergence of probabilities of sets whose boundary carries no mass under the\n   limit measure.\n\nTODO:\n * Prove the rest of the implications.\n\n## Implementation notes\n\nMany of the characterizations of weak convergence hold for finite measures and are proven in that\ngenerality and then specialized to probability measures. Some implications hold with slightly\nweaker assumptions than usually stated. The full portmanteau theorem, however, is most convenient\nfor probability measures on metrizable spaces with their Borel sigmas.\n\nSome specific considerations on the assumptions in the different implications:\n * `measure_theory.finite_measure.limsup_measure_closed_le_of_tendsto` assumes\n   `pseudo_emetric_space`. The only reason is to have bounded continuous pointwise approximations\n   to the indicator function of a closed set. Clearly for example metrizability or\n   pseudo-emetrizability would be sufficient assumptions. The typeclass assumptions should be later\n   adjusted in a way that takes into account use cases, but the proof will presumably remain\n   essentially the same.\n * Where formulations are currently only provided for probability measures, one can obtain the\n   finite measure formulations using the characterization of convergence of finite measures by\n   their total masses and their probability-normalized versions, i.e., by\n   `measure_theory.finite_measure.tendsto_normalize_iff_tendsto`.\n\n## References\n\n* [Billingsley, *Convergence of probability measures*][billingsley1999]\n\n## Tags\n\nweak convergence of measures, convergence in distribution, convergence in law, finite measure,\nprobability measure\n\n-/\n\nnoncomputable theory\nopen measure_theory\nopen set\nopen filter\nopen bounded_continuous_function\nopen_locale topology ennreal nnreal bounded_continuous_function\n\nnamespace measure_theory\n\nsection limsup_closed_le_and_le_liminf_open\n/-! ### Portmanteau: limsup condition for closed sets iff liminf condition for open sets\n\nIn this section we prove that for a sequence of Borel probability measures on a topological space\nand its candidate limit measure, the following two conditions are equivalent:\n  (C) For any closed set `F` in `\u03a9` the limsup of the measures of `F` is at most the limit\n      measure of `F`.\n  (O) For any open set `G` in `\u03a9` the liminf of the measures of `G` is at least the limit\n      measure of `G`.\nEither of these will later be shown to be equivalent to the weak convergence of the sequence\nof measures.\n-/\n\nvariables {\u03a9 : Type*} [measurable_space \u03a9]\n\nlemma le_measure_compl_liminf_of_limsup_measure_le\n  {\u03b9 : Type*} {L : filter \u03b9} {\u03bc : measure \u03a9} {\u03bcs : \u03b9 \u2192 measure \u03a9}\n  [is_probability_measure \u03bc] [\u2200 i, is_probability_measure (\u03bcs i)]\n  {E : set \u03a9} (E_mble : measurable_set E) (h : L.limsup (\u03bb i, \u03bcs i E) \u2264 \u03bc E) :\n  \u03bc E\u1d9c \u2264 L.liminf (\u03bb i, \u03bcs i E\u1d9c) :=\nbegin\n  by_cases L_bot : L = \u22a5,\n  { simp only [L_bot, le_top,\n      (show liminf (\u03bb i, \u03bcs i E\u1d9c) \u22a5 = \u22a4, by simp only [liminf, filter.map_bot, Liminf_bot])], },\n  haveI : L.ne_bot, from {ne' := L_bot},\n  have meas_Ec : \u03bc E\u1d9c = 1 - \u03bc E,\n  { simpa only [measure_univ] using measure_compl E_mble (measure_lt_top \u03bc E).ne, },\n  have meas_i_Ec : \u2200 i, \u03bcs i E\u1d9c = 1 - \u03bcs i E,\n  { intro i,\n    simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (\u03bcs i) E).ne, },\n  simp_rw [meas_Ec, meas_i_Ec],\n  have obs : L.liminf (\u03bb (i : \u03b9), 1 - \u03bcs i E) = L.liminf ((\u03bb x, 1 - x) \u2218 (\u03bb (i : \u03b9), \u03bcs i E)),\n    by refl,\n  rw obs,\n  simp_rw \u2190 antitone_const_tsub.map_limsup_of_continuous_at (\u03bb i, \u03bcs i E)\n            (ennreal.continuous_sub_left ennreal.one_ne_top).continuous_at,\n  exact antitone_const_tsub h,\nend\n\nlemma le_measure_liminf_of_limsup_measure_compl_le\n  {\u03b9 : Type*} {L : filter \u03b9} {\u03bc : measure \u03a9} {\u03bcs : \u03b9 \u2192 measure \u03a9}\n  [is_probability_measure \u03bc] [\u2200 i, is_probability_measure (\u03bcs i)]\n  {E : set \u03a9} (E_mble : measurable_set E) (h : L.limsup (\u03bb i, \u03bcs i E\u1d9c) \u2264 \u03bc E\u1d9c) :\n  \u03bc E \u2264 L.liminf (\u03bb i, \u03bcs i E) :=\ncompl_compl E \u25b8 (le_measure_compl_liminf_of_limsup_measure_le (measurable_set.compl E_mble) h)\n\nlemma limsup_measure_compl_le_of_le_liminf_measure\n  {\u03b9 : Type*} {L : filter \u03b9} {\u03bc : measure \u03a9} {\u03bcs : \u03b9 \u2192 measure \u03a9}\n  [is_probability_measure \u03bc] [\u2200 i, is_probability_measure (\u03bcs i)]\n  {E : set \u03a9} (E_mble : measurable_set E) (h : \u03bc E \u2264 L.liminf (\u03bb i, \u03bcs i E)) :\n  L.limsup (\u03bb i, \u03bcs i E\u1d9c) \u2264 \u03bc E\u1d9c :=\nbegin\n  by_cases L_bot : L = \u22a5,\n  { simp only [L_bot, bot_le,\n      (show limsup (\u03bb i, \u03bcs i E\u1d9c) \u22a5 = \u22a5, by simp only [limsup, filter.map_bot, Limsup_bot])], },\n  haveI : L.ne_bot, from {ne' := L_bot},\n  have meas_Ec : \u03bc E\u1d9c = 1 - \u03bc E,\n  { simpa only [measure_univ] using measure_compl E_mble (measure_lt_top \u03bc E).ne, },\n  have meas_i_Ec : \u2200 i, \u03bcs i E\u1d9c = 1 - \u03bcs i E,\n  { intro i,\n    simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (\u03bcs i) E).ne, },\n  simp_rw [meas_Ec, meas_i_Ec],\n  have obs : L.limsup (\u03bb (i : \u03b9), 1 - \u03bcs i E) = L.limsup ((\u03bb x, 1 - x) \u2218 (\u03bb (i : \u03b9), \u03bcs i E)),\n    by refl,\n  rw obs,\n  simp_rw \u2190 antitone_const_tsub.map_liminf_of_continuous_at (\u03bb i, \u03bcs i E)\n            (ennreal.continuous_sub_left ennreal.one_ne_top).continuous_at,\n  exact antitone_const_tsub h,\nend\n\nlemma limsup_measure_le_of_le_liminf_measure_compl\n  {\u03b9 : Type*} {L : filter \u03b9} {\u03bc : measure \u03a9} {\u03bcs : \u03b9 \u2192 measure \u03a9}\n  [is_probability_measure \u03bc] [\u2200 i, is_probability_measure (\u03bcs i)]\n  {E : set \u03a9} (E_mble : measurable_set E) (h : \u03bc E\u1d9c \u2264 L.liminf (\u03bb i, \u03bcs i E\u1d9c)) :\n  L.limsup (\u03bb i, \u03bcs i E) \u2264 \u03bc E :=\ncompl_compl E \u25b8 (limsup_measure_compl_le_of_le_liminf_measure (measurable_set.compl E_mble) h)\n\nvariables [topological_space \u03a9] [opens_measurable_space \u03a9]\n\n/-- One pair of implications of the portmanteau theorem:\nFor a sequence of Borel probability measures, the following two are equivalent:\n\n(C) The limsup of the measures of any closed set is at most the measure of the closed set\nunder a candidate limit measure.\n\n(O) The liminf of the measures of any open set is at least the measure of the open set\nunder a candidate limit measure.\n-/\nlemma limsup_measure_closed_le_iff_liminf_measure_open_ge\n  {\u03b9 : Type*} {L : filter \u03b9} {\u03bc : measure \u03a9} {\u03bcs : \u03b9 \u2192 measure \u03a9}\n  [is_probability_measure \u03bc] [\u2200 i, is_probability_measure (\u03bcs i)] :\n  (\u2200 F, is_closed F \u2192 L.limsup (\u03bb i, \u03bcs i F) \u2264 \u03bc F)\n    \u2194 (\u2200 G, is_open G \u2192 \u03bc G \u2264 L.liminf (\u03bb i, \u03bcs i G)) :=\nbegin\n  split,\n  { intros h G G_open,\n    exact le_measure_liminf_of_limsup_measure_compl_le\n          G_open.measurable_set (h G\u1d9c (is_closed_compl_iff.mpr G_open)), },\n  { intros h F F_closed,\n    exact limsup_measure_le_of_le_liminf_measure_compl\n          F_closed.measurable_set (h F\u1d9c (is_open_compl_iff.mpr F_closed)), },\nend\n\nend limsup_closed_le_and_le_liminf_open -- section\n\nsection tendsto_of_null_frontier\n/-! ### Portmanteau: limit of measures of Borel sets whose boundary carries no mass in the limit\n\nIn this section we prove that for a sequence of Borel probability measures on a topological space\nand its candidate limit measure, either of the following equivalent conditions:\n  (C) For any closed set `F` in `\u03a9` the limsup of the measures of `F` is at most the limit\n      measure of `F`\n  (O) For any open set `G` in `\u03a9` the liminf of the measures of `G` is at least the limit\n      measure of `G`\nimplies that\n  (B) For any Borel set `E` in `\u03a9` whose boundary `\u2202E` carries no mass under the candidate limit\n      measure, we have that the limit of measures of `E` is the measure of `E` under the\n      candidate limit measure.\n-/\n\nvariables {\u03a9 : Type*} [measurable_space \u03a9]\n\nlemma tendsto_measure_of_le_liminf_measure_of_limsup_measure_le\n  {\u03b9 : Type*} {L : filter \u03b9} {\u03bc : measure \u03a9} {\u03bcs : \u03b9 \u2192 measure \u03a9}\n  {E\u2080 E E\u2081 : set \u03a9} (E\u2080_subset : E\u2080 \u2286 E) (subset_E\u2081 : E \u2286 E\u2081) (nulldiff : \u03bc (E\u2081 \\ E\u2080) = 0)\n  (h_E\u2080 : \u03bc E\u2080 \u2264 L.liminf (\u03bb i, \u03bcs i E\u2080)) (h_E\u2081 : L.limsup (\u03bb i, \u03bcs i E\u2081) \u2264 \u03bc E\u2081) :\n  L.tendsto (\u03bb i, \u03bcs i E) (\ud835\udcdd (\u03bc E)) :=\nbegin\n  apply tendsto_of_le_liminf_of_limsup_le,\n  { have E\u2080_ae_eq_E : E\u2080 =\u1d50[\u03bc] E,\n      from eventually_le.antisymm E\u2080_subset.eventually_le\n            (subset_E\u2081.eventually_le.trans (ae_le_set.mpr nulldiff)),\n    calc  \u03bc(E)\n        = \u03bc(E\u2080)                      : measure_congr E\u2080_ae_eq_E.symm\n    ... \u2264 L.liminf (\u03bb i, \u03bcs i E\u2080)    : h_E\u2080\n    ... \u2264 L.liminf (\u03bb i, \u03bcs i E)     : _,\n    { refine liminf_le_liminf (eventually_of_forall (\u03bb _, measure_mono E\u2080_subset)) _,\n      apply_auto_param, }, },\n  { have E_ae_eq_E\u2081 : E =\u1d50[\u03bc] E\u2081,\n      from eventually_le.antisymm subset_E\u2081.eventually_le\n            ((ae_le_set.mpr nulldiff).trans E\u2080_subset.eventually_le),\n    calc  L.limsup (\u03bb i, \u03bcs i E)\n        \u2264 L.limsup (\u03bb i, \u03bcs i E\u2081)    : _\n    ... \u2264 \u03bc E\u2081                       : h_E\u2081\n    ... = \u03bc E                        : measure_congr E_ae_eq_E\u2081.symm,\n    { refine limsup_le_limsup (eventually_of_forall (\u03bb _, measure_mono subset_E\u2081)) _,\n      apply_auto_param, }, },\nend\n\nvariables [topological_space \u03a9] [opens_measurable_space \u03a9]\n\n/-- One implication of the portmanteau theorem:\nFor a sequence of Borel probability measures, if the liminf of the measures of any open set is at\nleast the measure of the open set under a candidate limit measure, then for any set whose\nboundary carries no probability mass under the candidate limit measure, then its measures under the\nsequence converge to its measure under the candidate limit measure.\n-/\nlemma tendsto_measure_of_null_frontier\n  {\u03b9 : Type*} {L : filter \u03b9} {\u03bc : measure \u03a9} {\u03bcs : \u03b9 \u2192 measure \u03a9}\n  [is_probability_measure \u03bc] [\u2200 i, is_probability_measure (\u03bcs i)]\n  (h_opens : \u2200 G, is_open G \u2192 \u03bc G \u2264 L.liminf (\u03bb i, \u03bcs i G))\n  {E : set \u03a9} (E_nullbdry : \u03bc (frontier E) = 0) :\n  L.tendsto (\u03bb i, \u03bcs i E) (\ud835\udcdd (\u03bc E)) :=\nbegin\n  have h_closeds : \u2200 F, is_closed F \u2192 L.limsup (\u03bb i, \u03bcs i F) \u2264 \u03bc F,\n    from limsup_measure_closed_le_iff_liminf_measure_open_ge.mpr h_opens,\n  exact tendsto_measure_of_le_liminf_measure_of_limsup_measure_le\n        interior_subset subset_closure E_nullbdry\n        (h_opens _ is_open_interior) (h_closeds _ is_closed_closure),\nend\n\nend tendsto_of_null_frontier --section\n\nsection convergence_implies_limsup_closed_le\n/-! ### Portmanteau implication: weak convergence implies a limsup condition for closed sets\n\nIn this section we prove, under the assumption that the underlying topological space `\u03a9` is\npseudo-emetrizable, that the weak convergence of measures on `measure_theory.finite_measure \u03a9`\nimplies that for any closed set `F` in `\u03a9` the limsup of the measures of `F` is at most the\nlimit measure of `F`. This is one implication of the portmanteau theorem characterizing weak\nconvergence of measures.\n\nCombining with an earlier implication we also get that weak convergence implies that for any Borel\nset `E` in `\u03a9` whose boundary `\u2202E` carries no mass under the limit measure, the limit of measures\nof `E` is the measure of `E` under the limit measure.\n-/\n\nvariables {\u03a9 : Type*} [measurable_space \u03a9]\n\n/-- If bounded continuous functions tend to the indicator of a measurable set and are\nuniformly bounded, then their integrals against a finite measure tend to the measure of the set.\nThis formulation assumes:\n * the functions tend to a limit along a countably generated filter;\n * the limit is in the almost everywhere sense;\n * boundedness holds almost everywhere.\n-/\nlemma measure_of_cont_bdd_of_tendsto_filter_indicator {\u03b9 : Type*} {L : filter \u03b9}\n  [L.is_countably_generated] [topological_space \u03a9] [opens_measurable_space \u03a9]\n  (\u03bc : measure \u03a9) [is_finite_measure \u03bc] {c : \u211d\u22650} {E : set \u03a9} (E_mble : measurable_set E)\n  (fs : \u03b9 \u2192 (\u03a9 \u2192\u1d47 \u211d\u22650)) (fs_bdd : \u2200\u1da0 i in L, \u2200\u1d50 (\u03c9 : \u03a9) \u2202\u03bc, fs i \u03c9 \u2264 c)\n  (fs_lim : \u2200\u1d50 (\u03c9 : \u03a9) \u2202\u03bc,\n            tendsto (\u03bb (i : \u03b9), (coe_fn : (\u03a9 \u2192\u1d47 \u211d\u22650) \u2192 (\u03a9 \u2192 \u211d\u22650)) (fs i) \u03c9) L\n                    (\ud835\udcdd (indicator E (\u03bb x, (1 : \u211d\u22650)) \u03c9))) :\n  tendsto (\u03bb n, lintegral \u03bc (\u03bb \u03c9, fs n \u03c9)) L (\ud835\udcdd (\u03bc E)) :=\nbegin\n  convert finite_measure.tendsto_lintegral_nn_filter_of_le_const \u03bc fs_bdd fs_lim,\n  have aux : \u2200 \u03c9, indicator E (\u03bb \u03c9, (1 : \u211d\u22650\u221e)) \u03c9 = \u2191(indicator E (\u03bb \u03c9, (1 : \u211d\u22650)) \u03c9),\n  from \u03bb \u03c9, by simp only [ennreal.coe_indicator, ennreal.coe_one],\n  simp_rw [\u2190aux, lintegral_indicator _ E_mble],\n  simp only [lintegral_one, measure.restrict_apply, measurable_set.univ, univ_inter],\nend\n\n/-- If a sequence of bounded continuous functions tends to the indicator of a measurable set and\nthe functions are uniformly bounded, then their integrals against a finite measure tend to the\nmeasure of the set.\n\nA similar result with more general assumptions is\n`measure_theory.measure_of_cont_bdd_of_tendsto_filter_indicator`.\n-/\nlemma measure_of_cont_bdd_of_tendsto_indicator\n  [topological_space \u03a9] [opens_measurable_space \u03a9]\n  (\u03bc : measure \u03a9) [is_finite_measure \u03bc] {c : \u211d\u22650} {E : set \u03a9} (E_mble : measurable_set E)\n  (fs : \u2115 \u2192 (\u03a9 \u2192\u1d47 \u211d\u22650)) (fs_bdd : \u2200 n \u03c9, fs n \u03c9 \u2264 c)\n  (fs_lim : tendsto (\u03bb (n : \u2115), (coe_fn : (\u03a9 \u2192\u1d47 \u211d\u22650) \u2192 (\u03a9 \u2192 \u211d\u22650)) (fs n))\n            at_top (\ud835\udcdd (indicator E (\u03bb x, (1 : \u211d\u22650))))) :\n  tendsto (\u03bb n, lintegral \u03bc (\u03bb \u03c9, fs n \u03c9)) at_top (\ud835\udcdd (\u03bc E)) :=\nbegin\n  have fs_lim' : \u2200 \u03c9, tendsto (\u03bb (n : \u2115), (fs n \u03c9 : \u211d\u22650))\n                 at_top (\ud835\udcdd (indicator E (\u03bb x, (1 : \u211d\u22650)) \u03c9)),\n  by { rw tendsto_pi_nhds at fs_lim, exact \u03bb \u03c9, fs_lim \u03c9, },\n  apply measure_of_cont_bdd_of_tendsto_filter_indicator \u03bc E_mble fs\n      (eventually_of_forall (\u03bb n, eventually_of_forall (fs_bdd n))) (eventually_of_forall fs_lim'),\nend\n\n/-- The integrals of thickened indicators of a closed set against a finite measure tend to the\nmeasure of the closed set if the thickening radii tend to zero.\n-/\nlemma tendsto_lintegral_thickened_indicator_of_is_closed\n  {\u03a9 : Type*} [measurable_space \u03a9] [pseudo_emetric_space \u03a9] [opens_measurable_space \u03a9]\n  (\u03bc : measure \u03a9) [is_finite_measure \u03bc] {F : set \u03a9} (F_closed : is_closed F) {\u03b4s : \u2115 \u2192 \u211d}\n  (\u03b4s_pos : \u2200 n, 0 < \u03b4s n) (\u03b4s_lim : tendsto \u03b4s at_top (\ud835\udcdd 0)) :\n  tendsto (\u03bb n, lintegral \u03bc (\u03bb \u03c9, (thickened_indicator (\u03b4s_pos n) F \u03c9 : \u211d\u22650\u221e)))\n          at_top (\ud835\udcdd (\u03bc F)) :=\nbegin\n  apply measure_of_cont_bdd_of_tendsto_indicator \u03bc F_closed.measurable_set\n          (\u03bb n, thickened_indicator (\u03b4s_pos n) F)\n          (\u03bb n \u03c9, thickened_indicator_le_one (\u03b4s_pos n) F \u03c9),\n  have key := thickened_indicator_tendsto_indicator_closure \u03b4s_pos \u03b4s_lim F,\n  rwa F_closed.closure_eq at key,\nend\n\n/-- One implication of the portmanteau theorem:\nWeak convergence of finite measures implies that the limsup of the measures of any closed set is\nat most the measure of the closed set under the limit measure.\n-/\nlemma finite_measure.limsup_measure_closed_le_of_tendsto\n  {\u03a9 \u03b9 : Type*} {L : filter \u03b9}\n  [measurable_space \u03a9] [pseudo_emetric_space \u03a9] [opens_measurable_space \u03a9]\n  {\u03bc : finite_measure \u03a9} {\u03bcs : \u03b9 \u2192 finite_measure \u03a9}\n  (\u03bcs_lim : tendsto \u03bcs L (\ud835\udcdd \u03bc)) {F : set \u03a9} (F_closed : is_closed F) :\n  L.limsup (\u03bb i, (\u03bcs i : measure \u03a9) F) \u2264 (\u03bc : measure \u03a9) F :=\nbegin\n  by_cases L = \u22a5,\n  { simp only [h, limsup, filter.map_bot, Limsup_bot, ennreal.bot_eq_zero, zero_le], },\n  apply ennreal.le_of_forall_pos_le_add,\n  intros \u03b5 \u03b5_pos \u03bc_F_finite,\n  set \u03b4s := \u03bb (n : \u2115), (1 : \u211d) / (n+1) with def_\u03b4s,\n  have \u03b4s_pos : \u2200 n, 0 < \u03b4s n, from \u03bb n, nat.one_div_pos_of_nat,\n  have \u03b4s_lim : tendsto \u03b4s at_top (\ud835\udcdd 0), from tendsto_one_div_add_at_top_nhds_0_nat,\n  have key\u2081 := tendsto_lintegral_thickened_indicator_of_is_closed\n                  (\u03bc : measure \u03a9) F_closed \u03b4s_pos \u03b4s_lim,\n  have room\u2081 : (\u03bc : measure \u03a9) F < (\u03bc : measure \u03a9) F + \u03b5 / 2,\n  { apply ennreal.lt_add_right (measure_lt_top (\u03bc : measure \u03a9) F).ne\n          ((ennreal.div_pos_iff.mpr\n              \u27e8(ennreal.coe_pos.mpr \u03b5_pos).ne.symm, ennreal.two_ne_top\u27e9).ne.symm), },\n  rcases eventually_at_top.mp (eventually_lt_of_tendsto_lt room\u2081 key\u2081) with \u27e8M, hM\u27e9,\n  have key\u2082 := finite_measure.tendsto_iff_forall_lintegral_tendsto.mp\n                \u03bcs_lim (thickened_indicator (\u03b4s_pos M) F),\n  have room\u2082 : lintegral (\u03bc : measure \u03a9) (\u03bb a, thickened_indicator (\u03b4s_pos M) F a)\n                < lintegral (\u03bc : measure \u03a9) (\u03bb a, thickened_indicator (\u03b4s_pos M) F a) + \u03b5 / 2,\n  { apply ennreal.lt_add_right\n          (lintegral_lt_top_of_bounded_continuous_to_nnreal (\u03bc : measure \u03a9) _).ne\n          ((ennreal.div_pos_iff.mpr\n              \u27e8(ennreal.coe_pos.mpr \u03b5_pos).ne.symm, ennreal.two_ne_top\u27e9).ne.symm), },\n  have ev_near := eventually.mono (eventually_lt_of_tendsto_lt room\u2082 key\u2082) (\u03bb n, le_of_lt),\n  have aux := \u03bb n, le_trans (measure_le_lintegral_thickened_indicator\n                            (\u03bcs n : measure \u03a9) F_closed.measurable_set (\u03b4s_pos M)),\n  have ev_near' := eventually.mono ev_near aux,\n  apply (filter.limsup_le_limsup ev_near').trans,\n  haveI : ne_bot L, from \u27e8h\u27e9,\n  rw limsup_const,\n  apply le_trans (add_le_add (hM M rfl.le).le (le_refl (\u03b5/2 : \u211d\u22650\u221e))),\n  simp only [add_assoc, ennreal.add_halves, le_refl],\nend\n\n/-- One implication of the portmanteau theorem:\nWeak convergence of probability measures implies that the limsup of the measures of any closed\nset is at most the measure of the closed set under the limit probability measure.\n-/\nlemma probability_measure.limsup_measure_closed_le_of_tendsto\n  {\u03a9 \u03b9 : Type*} {L : filter \u03b9}\n  [measurable_space \u03a9] [pseudo_emetric_space \u03a9] [opens_measurable_space \u03a9]\n  {\u03bc : probability_measure \u03a9} {\u03bcs : \u03b9 \u2192 probability_measure \u03a9}\n  (\u03bcs_lim : tendsto \u03bcs L (\ud835\udcdd \u03bc)) {F : set \u03a9} (F_closed : is_closed F) :\n  L.limsup (\u03bb i, (\u03bcs i : measure \u03a9) F) \u2264 (\u03bc : measure \u03a9) F :=\nby apply finite_measure.limsup_measure_closed_le_of_tendsto\n         ((probability_measure.tendsto_nhds_iff_to_finite_measures_tendsto_nhds L).mp \u03bcs_lim)\n         F_closed\n\n/-- One implication of the portmanteau theorem:\nWeak convergence of probability measures implies that the liminf of the measures of any open set\nis at least the measure of the open set under the limit probability measure.\n-/\nlemma probability_measure.le_liminf_measure_open_of_tendsto\n  {\u03a9 \u03b9 : Type*} {L : filter \u03b9}\n  [measurable_space \u03a9] [pseudo_emetric_space \u03a9] [opens_measurable_space \u03a9]\n  {\u03bc : probability_measure \u03a9} {\u03bcs : \u03b9 \u2192 probability_measure \u03a9}\n  (\u03bcs_lim : tendsto \u03bcs L (\ud835\udcdd \u03bc)) {G : set \u03a9} (G_open : is_open G) :\n  (\u03bc : measure \u03a9) G \u2264 L.liminf (\u03bb i, (\u03bcs i : measure \u03a9) G) :=\nbegin\n  have h_closeds : \u2200 F, is_closed F \u2192 L.limsup (\u03bb i, (\u03bcs i : measure \u03a9) F) \u2264 (\u03bc : measure \u03a9) F,\n    from \u03bb F F_closed, probability_measure.limsup_measure_closed_le_of_tendsto \u03bcs_lim F_closed,\n  exact le_measure_liminf_of_limsup_measure_compl_le\n        G_open.measurable_set (h_closeds _ (is_closed_compl_iff.mpr G_open)),\nend\n\nlemma probability_measure.tendsto_measure_of_null_frontier_of_tendsto'\n  {\u03a9 \u03b9 : Type*} {L : filter \u03b9}\n  [measurable_space \u03a9] [pseudo_emetric_space \u03a9] [opens_measurable_space \u03a9]\n  {\u03bc : probability_measure \u03a9} {\u03bcs : \u03b9 \u2192 probability_measure \u03a9}\n  (\u03bcs_lim : tendsto \u03bcs L (\ud835\udcdd \u03bc)) {E : set \u03a9} (E_nullbdry : (\u03bc : measure \u03a9) (frontier E) = 0) :\n  tendsto (\u03bb i, (\u03bcs i : measure \u03a9) E) L (\ud835\udcdd ((\u03bc : measure \u03a9) E)) :=\nbegin\n  have h_opens : \u2200 G, is_open G \u2192 (\u03bc : measure \u03a9) G \u2264 L.liminf (\u03bb i, (\u03bcs i : measure \u03a9) G),\n    from \u03bb G G_open, probability_measure.le_liminf_measure_open_of_tendsto \u03bcs_lim G_open,\n  exact tendsto_measure_of_null_frontier h_opens E_nullbdry,\nend\n\n/-- One implication of the portmanteau theorem:\nWeak convergence of probability measures implies that if the boundary of a Borel set\ncarries no probability mass under the limit measure, then the limit of the measures of the set\nequals the measure of the set under the limit probability measure.\n\nA version with coercions to ordinary `\u211d\u22650\u221e`-valued measures is\n`measure_theory.probability_measure.tendsto_measure_of_null_frontier_of_tendsto'`.\n-/\nlemma probability_measure.tendsto_measure_of_null_frontier_of_tendsto\n  {\u03a9 \u03b9 : Type*} {L : filter \u03b9}\n  [measurable_space \u03a9] [pseudo_emetric_space \u03a9] [opens_measurable_space \u03a9]\n  {\u03bc : probability_measure \u03a9} {\u03bcs : \u03b9 \u2192 probability_measure \u03a9}\n  (\u03bcs_lim : tendsto \u03bcs L (\ud835\udcdd \u03bc)) {E : set \u03a9} (E_nullbdry : \u03bc (frontier E) = 0) :\n  tendsto (\u03bb i, \u03bcs i E) L (\ud835\udcdd (\u03bc E)) :=\nbegin\n  have E_nullbdry' : (\u03bc : measure \u03a9) (frontier E) = 0,\n    by rw [\u2190 probability_measure.ennreal_coe_fn_eq_coe_fn_to_measure, E_nullbdry, ennreal.coe_zero],\n  have key := probability_measure.tendsto_measure_of_null_frontier_of_tendsto' \u03bcs_lim E_nullbdry',\n  exact (ennreal.tendsto_to_nnreal (measure_ne_top \u2191\u03bc E)).comp key,\nend\n\nend convergence_implies_limsup_closed_le --section\n\nsection limit_borel_implies_limsup_closed_le\n/-! ### Portmanteau implication: limit condition for Borel sets implies limsup for closed sets\n\nTODO: The proof of the implication is not yet here. Add it.\n-/\n\nvariables {\u03a9 : Type*} [pseudo_emetric_space \u03a9] [measurable_space \u03a9] [opens_measurable_space \u03a9]\n\nlemma exists_null_frontier_thickening\n  (\u03bc : measure \u03a9) [sigma_finite \u03bc] (s : set \u03a9) {a b : \u211d} (hab : a < b) :\n  \u2203 r \u2208 Ioo a b, \u03bc (frontier (metric.thickening r s)) = 0 :=\nbegin\n  have mbles : \u2200 (r : \u211d), measurable_set (frontier (metric.thickening r s)),\n    from \u03bb r, (is_closed_frontier).measurable_set,\n  have disjs := metric.frontier_thickening_disjoint s,\n  have key := @measure.countable_meas_pos_of_disjoint_Union \u03a9 _ _ \u03bc _ _ mbles disjs,\n  have aux := @measure_diff_null \u211d _ volume (Ioo a b) _ (set.countable.measure_zero key volume),\n  have len_pos : 0 < ennreal.of_real (b - a), by simp only [hab, ennreal.of_real_pos, sub_pos],\n  rw [\u2190 real.volume_Ioo, \u2190 aux] at len_pos,\n  rcases nonempty_of_measure_ne_zero len_pos.ne.symm with \u27e8r, \u27e8r_in_Ioo, hr\u27e9\u27e9,\n  refine \u27e8r, r_in_Ioo, _\u27e9,\n  simpa only [mem_set_of_eq, not_lt, le_zero_iff] using hr,\nend\n\nlemma exists_null_frontiers_thickening (\u03bc : measure \u03a9) [sigma_finite \u03bc] (s : set \u03a9) :\n  \u2203 (rs : \u2115 \u2192 \u211d), tendsto rs at_top (\ud835\udcdd 0) \u2227\n                  \u2200 n, 0 < rs n \u2227 \u03bc (frontier (metric.thickening (rs n) s)) = 0 :=\nbegin\n  rcases exists_seq_strict_anti_tendsto (0 : \u211d) with \u27e8Rs, \u27e8rubbish, \u27e8Rs_pos, Rs_lim\u27e9\u27e9\u27e9,\n  have obs := \u03bb (n : \u2115), exists_null_frontier_thickening \u03bc s (Rs_pos n),\n  refine \u27e8(\u03bb (n : \u2115), (obs n).some), \u27e8_, _\u27e9\u27e9,\n  { exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds Rs_lim\n              (\u03bb n, (obs n).some_spec.some.1.le) (\u03bb n, (obs n).some_spec.some.2.le), },\n  { exact \u03bb n, \u27e8(obs n).some_spec.some.1, (obs n).some_spec.some_spec\u27e9, },\nend\n\nend limit_borel_implies_limsup_closed_le --section\n\nend measure_theory --namespace\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/measure/portmanteau.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7159283807627936}}
{"text": "/-\nThis file contains the definition of a Boolean (disjunctive) clause.\nThis particular implementation has clauses as lists.\n\nAuthors: Cayden Codel, Jeremy Avigad, Marijn Heule\nCarnegie Mellon Univeristy\n-/\n\nimport cnf.literal\nimport cnf.assignment\nimport basic\n\nimport data.list.basic\n\n-- Represents the parametric type of the variable stored in the literal\nvariables {V : Type*}\n\n/- Disjunctive clauses are lists of literals, joined by logical ORs. -/\ndef clause (V : Type*) := list (literal V)\n\n-- Note that the above definition allows for duplication of literals, whereas\n-- a set definition would not. Lists also allow for computable functions,\n-- while Lean sets are noncomputable by default\n\nnamespace clause\n\nopen function\nopen literal\nopen list\n\n/-! # Properties -/\n\n-- Many of these properties follow directly from lists\n\ninstance [inhabited V] : inhabited (clause V) := \u27e8[arbitrary (literal V)]\u27e9\n\ninstance has_decidable_eq [decidable_eq V] : decidable_eq (clause V)\n| []        []        := is_true rfl\n| (a :: as) []        := is_false (\u03bb h, list.no_confusion h)\n| []        (b :: bs) := is_false (\u03bb h, list.no_confusion h)\n| (a :: as) (b :: bs) :=\n  match (literal.decidable_eq V) a b with\n  | is_true hab  :=\n    match has_decidable_eq as bs with\n    | is_true h := is_true (eq.subst hab (eq.subst h rfl))\n    | is_false hf := is_false (\u03bb h, list.no_confusion h (\u03bb _ ha, absurd ha hf))\n    end\n  | is_false hf := is_false (\u03bb h, list.no_confusion h (\u03bb hab _, absurd hab hf))\n  end\n\ninstance : has_mem (literal V) (clause V) := \u27e8list.mem\u27e9\ninstance : has_emptyc (clause V) := \u27e8list.nil\u27e9 -- Refactor empty into [] below?\ninstance [decidable_eq V] : has_union (clause V) := \u27e8list.union\u27e9\ninstance [decidable_eq V] : has_inter (clause V) := \u27e8list.inter\u27e9\ninstance : has_singleton (literal V) (clause V) := \u27e8\u03bb l, [l]\u27e9 \ninstance [decidable_eq V] : has_insert (literal V) (clause V) := \u27e8list.insert\u27e9\ninstance : has_append (clause V) := \u27e8list.append\u27e9\ninstance : has_subset (clause V) := \u27e8list.subset\u27e9\ninstance [has_repr V] : has_repr (clause V) := \u27e8list.repr\u27e9\n\ninstance [decidable_eq V] (l : literal V) (c : clause V) : decidable (l \u2208 c) :=\nby apply_instance\n\n/-! # eval -/\nsection eval\n\nvariables (\u03c4 : assignment V) (l : literal V) (c c\u2081 c\u2082 : clause V)\n\nprotected def eval : bool := c.foldr (\u03bb l b, b || (l.eval \u03c4)) ff\n\n@[simp] theorem eval_nil : clause.eval \u03c4 [] = ff := rfl\n\n@[simp] theorem eval_singleton : clause.eval \u03c4 [l] = l.eval \u03c4 :=\nby simp only [clause.eval, foldr, ff_bor]\n\n@[simp] theorem eval_cons : clause.eval \u03c4 (l :: c) = (l.eval \u03c4) || (c.eval \u03c4) :=\nby simp only [clause.eval, foldr, bool.bor_comm]\n\ntheorem eval_append : clause.eval \u03c4 (c\u2081 ++ c\u2082) = c\u2081.eval \u03c4 || c\u2082.eval \u03c4 :=\nbegin\n  unfold clause.eval,\n  rw foldr_append,\n  cases foldr (\u03bb l b, b || literal.eval \u03c4 l) ff c\u2082,\n  { rw bor_ff },\n  { rw [bor_tt, foldr_bor_tt] }\nend\n\ntheorem eval_tt_iff_exists_literal_eval_tt {\u03c4 : assignment V} {c : clause V} : \n  c.eval \u03c4 = tt \u2194 \u2203 l, l \u2208 c \u2227 literal.eval \u03c4 l = tt :=\nbegin\n  induction c with l ls ih,\n  { simp only [eval_nil, not_mem_nil, false_and, exists_false] },\n  { simp only [eval_cons, bor_eq_true_eq_eq_tt_or_eq_tt, mem_cons_iff],\n    split,\n    { rintros (h | h),\n      { use [l, or.inl rfl, h] },\n      { rcases ih.mp h with \u27e8l\u2082, hl, he\u27e9,\n        use [l\u2082, mem_cons_of_mem l hl, he] } },\n    { rintros \u27e8l\u2082, (rfl | hl), he\u27e9,\n      { exact or.inl he },\n      { exact or.inr (ih.mpr \u27e8l\u2082, hl, he\u27e9) } } }\nend\n\ntheorem eval_ff_iff_forall_literal_eval_ff {\u03c4 : assignment V} {c : clause V} : \n  c.eval \u03c4 = ff \u2194 \u2200 l, l \u2208 c \u2192 literal.eval \u03c4 l = ff :=\nbegin\n  induction c with l ls ih,\n  { simp only [eval_nil, eq_self_iff_true, not_mem_nil, is_empty.forall_iff, implies_true_iff] },\n  { simp only [ih, eval_cons, bor_eq_false_eq_eq_ff_and_eq_ff, mem_cons_iff, forall_eq_or_imp] }\nend\n\ntheorem eval_tautology {c : clause V} {l : literal V} : \n  l \u2208 c \u2192 l.flip \u2208 c \u2192 \u2200 (\u03c4 : assignment V), clause.eval \u03c4 c = tt :=\nbegin\n  intros hl hlf \u03c4,\n  apply eval_tt_iff_exists_literal_eval_tt.mpr,\n  cases h : (literal.eval \u03c4 l),\n  { exact \u27e8l.flip, hlf, eval_flip_of_eval h\u27e9 },\n  { exact \u27e8l, hl, h\u27e9 }\nend\n\ntheorem eval_tt_of_subset_eval_tt {\u03c4 : assignment V} {c\u2081 c\u2082 : clause V} :\n  c\u2081 \u2286 c\u2082 \u2192 clause.eval \u03c4 c\u2081 = tt \u2192 clause.eval \u03c4 c\u2082 = tt :=\nbegin\n  intros h\u2081 h\u2082,\n  apply eval_tt_iff_exists_literal_eval_tt.mpr,\n  rcases eval_tt_iff_exists_literal_eval_tt.mp h\u2082 with \u27e8l, hl, he\u27e9,\n  exact \u27e8l, h\u2081 hl, he\u27e9\nend\n\ntheorem eval_ff_of_superset_eval_ff {\u03c4 : assignment V} {c\u2081 c\u2082 : clause V} :\n  c\u2081 \u2286 c\u2082 \u2192 clause.eval \u03c4 c\u2082 = ff \u2192 clause.eval \u03c4 c\u2081 = ff :=\nbegin\n  intros h\u2081 h\u2082,\n  apply eval_ff_iff_forall_literal_eval_ff.mpr,\n  intros l hl,\n  exact (eval_ff_iff_forall_literal_eval_ff.mp h\u2082) l (h\u2081 hl)\nend\n\ntheorem eval_tt_of_sublist_eval_tt {\u03c4 : assignment V} {c\u2081 c\u2082 : clause V} :\n  c\u2081 <+ c\u2082 \u2192 clause.eval \u03c4 c\u2081 = tt \u2192 clause.eval \u03c4 c\u2082 = tt :=\nassume h\u2081, eval_tt_of_subset_eval_tt (sublist.subset h\u2081)\n\ntheorem eval_ff_of_superlist_eval_ff {\u03c4 : assignment V} {c\u2081 c\u2082 : clause V} :\n  c\u2081 <+ c\u2082 \u2192 clause.eval \u03c4 c\u2082 = ff \u2192 clause.eval \u03c4 c\u2081 = ff :=\nassume h\u2081, eval_ff_of_superset_eval_ff (sublist.subset h\u2081)\n\ntheorem eval_tt_cons_of_eval_tt {\u03c4 : assignment V} {c : clause V} (l : literal V) :\n  clause.eval \u03c4 c = tt \u2192 clause.eval \u03c4 (l :: c) = tt :=\nassume h, eval_tt_of_sublist_eval_tt (sublist_cons l c) h\n\ntheorem eval_ff_of_eval_ff_cons {\u03c4 : assignment V} {c : clause V} {l : literal V} :\n  clause.eval \u03c4 (l :: c) = ff \u2192 clause.eval \u03c4 c = ff :=\nassume h, eval_ff_of_superlist_eval_ff (sublist_cons l c) h\n\nend eval\n\n/-! ### Counting -/\nsection counting\n\nvariables (\u03c4 : assignment V) (l : literal V) (c c\u2081 c\u2082 : clause V)\n\nprotected def count_tt : nat := c.countp (literal.is_true \u03c4)\nprotected def count_ff : nat := c.countp (literal.is_false \u03c4)\n\ndef count_pos (c : clause V) : nat := c.countp literal.is_pos\ndef count_neg (c : clause V) : nat := c.countp literal.is_neg\n\n@[simp] lemma count_tt_nil : clause.count_tt \u03c4 [] = 0 := rfl\n@[simp] lemma count_ff_nil : clause.count_ff \u03c4 [] = 0 := rfl\n@[simp] lemma count_pos_nil : count_pos ([] : clause V) = 0 := rfl\n@[simp] lemma count_neg_nil : count_neg ([] : clause V) = 0 := rfl\n\n@[simp] theorem count_tt_singleton : clause.count_tt \u03c4 [l] = cond (l.eval \u03c4) 1 0 :=\nby cases h : (l.eval \u03c4); simp [h, clause.count_tt, literal.is_true]\n\n@[simp] theorem count_ff_singleton : clause.count_ff \u03c4 [l] = cond (l.eval \u03c4) 0 1 :=\nby cases h : (l.eval \u03c4); simp [h, clause.count_ff, literal.is_false]\n\n@[simp] theorem count_pos_singleton : count_pos [l] = cond l.is_pos 1 0 :=\nby cases l; simp [count_pos, literal.is_pos]\n\n@[simp] theorem count_neg_singleton : count_neg [l] = cond l.is_neg 1 0 :=\nby cases l; simp [count_neg, literal.is_neg]\n\n@[simp] theorem count_tt_cons : clause.count_tt \u03c4 (l :: c) = cond (l.eval \u03c4) (1 + c.count_tt \u03c4) (c.count_tt \u03c4) :=\nby cases h : (l.eval \u03c4); simp [h, literal.is_true, clause.count_tt, add_comm]\n\n@[simp] theorem count_ff_cons : clause.count_ff \u03c4 (l :: c) = cond (l.eval \u03c4) (c.count_ff \u03c4) (1 + c.count_ff \u03c4) :=\nby cases h : (l.eval \u03c4); simp [h, literal.is_false, clause.count_ff, add_comm]\n\n@[simp] theorem count_pos_cons : count_pos (l :: c) = cond l.is_pos (1 + c.count_pos) c.count_pos :=\nby cases l; simp [count_pos, literal.is_pos, add_comm]\n\n@[simp] theorem count_neg_cons : count_neg (l :: c) = cond l.is_neg (1 + c.count_neg) c.count_neg :=\nby cases l; simp [count_neg, literal.is_neg, add_comm]\n\ntheorem count_tt_append : clause.count_tt \u03c4 (c\u2081 ++ c\u2082) = clause.count_tt \u03c4 c\u2081 + clause.count_tt \u03c4 c\u2082 :=\nbegin\n  induction c\u2081 with l ls ih,\n  { simp only [count_tt_nil, zero_add, nil_append] },\n  { cases h : (literal.eval \u03c4 l); simp [h, ih, add_assoc] }\nend\n\ntheorem count_ff_append : clause.count_ff \u03c4 (c\u2081 ++ c\u2082) = clause.count_ff \u03c4 c\u2081 + clause.count_ff \u03c4 c\u2082 :=\nbegin\n  induction c\u2081 with l ls ih,\n  { simp only [count_ff_nil, zero_add, nil_append] },\n  { cases h : (literal.eval \u03c4 l); { simp [h, ih, add_assoc] } }\nend\n\ntheorem count_pos_append : clause.count_pos (c\u2081 ++ c\u2082) = clause.count_pos c\u2081 + clause.count_pos c\u2082 :=\nbegin\n  induction c\u2081 with l ls ih,\n  { simp only [nil_append, count_pos_nil, zero_add] },\n  { cases l; simp [ih, literal.is_pos, add_assoc] }\nend\n\ntheorem count_neg_append : clause.count_neg (c\u2081 ++ c\u2082) = clause.count_neg c\u2081 + clause.count_neg c\u2082 :=\nbegin\n  induction c\u2081 with l ls ih,\n  { simp only [nil_append, count_neg_nil, zero_add] },\n  { cases l; { simp [ih, literal.is_neg, add_assoc] } }\nend\n\ntheorem count_tt_le_length : c.count_tt \u03c4 \u2264 c.length :=\nby simp only [clause.count_tt, countp_eq_length_filter, length_filter]\n\ntheorem count_ff_le_length : c.count_ff \u03c4 \u2264 c.length :=\nby simp only [clause.count_ff, countp_eq_length_filter, length_filter]\n\ntheorem count_pos_le_length : c.count_pos \u2264 c.length :=\nby simp only [count_pos, countp_eq_length_filter, length_filter]\n\ntheorem count_neg_le_length : c.count_neg \u2264 c.length :=\nby simp only [count_neg, countp_eq_length_filter, length_filter]\n\ntheorem count_tt_plus_count_ff_eq_length (\u03c4 : assignment V) (c : clause V) :\n  c.count_tt \u03c4 + c.count_ff \u03c4 = c.length :=\nbegin\n  induction c with l ls ih,\n  { simp },\n  { cases h : (l.eval \u03c4);\n    simp [count_tt_cons, count_ff_cons, h, \u2190 ih],\n    { rw [add_assoc, add_comm (clause.count_ff \u03c4 ls) 1] },\n    { rw [add_comm (clause.count_tt \u03c4 ls + clause.count_ff \u03c4 ls) 1, \u2190 add_assoc] } }\nend\n\ntheorem count_tt_eq_length_sub_count_ff : c.count_tt \u03c4 = c.length - c.count_ff \u03c4 :=\neq_tsub_of_add_eq (count_tt_plus_count_ff_eq_length \u03c4 c)\n\ntheorem count_ff_eq_length_sub_count_tt : c.count_ff \u03c4 = c.length - c.count_tt \u03c4 :=\neq_tsub_of_add_eq (add_comm (c.count_tt \u03c4) (c.count_ff \u03c4) \u25b8 count_tt_plus_count_ff_eq_length \u03c4 c)\n\ntheorem count_pos_plus_count_neg_eq_length : c.count_pos + c.count_neg = c.length :=\nbegin\n  induction c with l ls ih,\n  { simp },\n  { cases l;\n    simp [count_pos_cons, count_neg_cons, literal.is_pos, literal.is_neg, \u2190 ih],\n    { rw [add_comm (count_pos ls + count_neg ls) 1, \u2190 add_assoc] },\n    { rw [add_assoc, add_comm 1] } }\nend\n\ntheorem count_pos_eq_length_sub_count_neg : c.count_pos = c.length - c.count_neg :=\neq_tsub_of_add_eq (count_pos_plus_count_neg_eq_length c)\n\ntheorem count_neg_eq_length_sub_count_pos : c.count_neg = c.length - c.count_pos :=\neq_tsub_of_add_eq (add_comm (c.count_pos) (c.count_neg) \u25b8 count_pos_plus_count_neg_eq_length c)\n\ntheorem count_tt_eq_zero_iff_eval_ff {\u03c4 : assignment V} {c : clause V} : \n  c.count_tt \u03c4 = 0 \u2194 c.eval \u03c4 = ff :=\nbegin\n  rw [clause.count_tt, countp_eq_zero, eval_ff_iff_forall_literal_eval_ff],\n  split,\n  { intros hc l hl,\n    have := hc l hl,\n    rw [literal.is_true, eq_ff_eq_not_eq_tt] at this,\n    exact this },\n  { intros hl a ha, simp [literal.is_true, hl a ha] }\nend\n\ntheorem count_tt_gt_zero_iff_eval_tt {\u03c4 : assignment V} {c : clause V} :\n  c.count_tt \u03c4 > 0 \u2194 c.eval \u03c4 = tt :=\nbegin\n  rw [clause.count_tt, eval_tt_iff_exists_literal_eval_tt],\n  split,\n  { intro hp,\n    rcases (countp_pos _).mp hp with \u27e8l, hl, he\u27e9,\n    exact \u27e8l, hl, he\u27e9 },\n  { rintro \u27e8l, hl, he\u27e9,\n    exact (countp_pos _).mpr \u27e8l, hl, he\u27e9 } \nend\n\nend counting\n\n/-! # falsify and truthify -/\nsection falsify\n\nvariables (\u03c4 : assignment V) (v : V) (l : list V) {c c\u2081 c\u2082 : clause V}\n\n-- For any assignment and variables, there is a clause that evaluates to false\n-- Simply map each variable in the list to the literal which evaluates to false\ndef falsify : clause V := l.map (\u03bb v, cond (\u03c4 v) (Neg v) (Pos v))\ndef truthify : clause V := l.map (\u03bb v, cond (\u03c4 v) (Pos v) (Neg v))\n\n@[simp] lemma falsify_nil : falsify \u03c4 [] = [] := rfl\n@[simp] lemma truthify_nil : truthify \u03c4 [] = [] := rfl\n\n@[simp] lemma falsify_singleton : falsify \u03c4 [v] = cond (\u03c4 v) [Neg v] [Pos v] :=\nby cases h : \u03c4 v; simp [h, falsify]\n\n@[simp] lemma truthify_singleton : truthify \u03c4 [v] = cond (\u03c4 v) [Pos v] [Neg v] :=\nby cases h : \u03c4 v; simp [h, truthify]\n\n@[simp] theorem falsify_cons : falsify \u03c4 (v :: l) = cond (\u03c4 v) (Neg v :: falsify \u03c4 l) (Pos v :: falsify \u03c4 l) :=\nby cases h : \u03c4 v; simp [falsify, map_cons, h]\n\n@[simp] theorem truthify_cons : truthify \u03c4 (v :: l) = cond (\u03c4 v) (Pos v :: truthify \u03c4 l) (Neg v :: truthify \u03c4 l) :=\nby cases h : \u03c4 v; simp [truthify, map_cons, h]\n\ntheorem falsify_eval_ff : clause.eval \u03c4 (falsify \u03c4 l) = ff :=\nbegin\n  induction l with v vs ih,\n  { rw [falsify_nil, eval_nil] },\n  { cases h : (\u03c4 v); simp [h, eval_cons, literal.eval, ih] }\nend\n\ntheorem truthify_eval_tt {l : list V} (hl : l \u2260 []) : clause.eval \u03c4 (truthify \u03c4 l) = tt :=\nbegin\n  induction l with v vs ih,\n  { contradiction },\n  { cases h : (\u03c4 v); simp [h, literal.eval, eval_cons] }\nend\n\ntheorem flip_truthify_eq_falsify : map literal.flip (truthify \u03c4 l) = falsify \u03c4 l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : (\u03c4 v); simp [h, literal.eval, ih, literal.flip] }\nend\n\ntheorem falsify_map_var_eq : map var (falsify \u03c4 l) = l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : (\u03c4 v);\n    { simp only [falsify_cons, map_cons, h, var, true_and, eq_self_iff_true, cond],\n      exact ih } }\nend\n\ntheorem truthify_map_var_eq : map var (truthify \u03c4 l) = l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : (\u03c4 v);\n    { simp only [truthify_cons, map_cons, h, var, true_and, eq_self_iff_true, cond],\n      exact ih } }\nend\n\ntheorem count_tt_falsify : clause.count_tt \u03c4 (falsify \u03c4 l) = 0 :=\ncount_tt_eq_zero_iff_eval_ff.mpr (falsify_eval_ff \u03c4 l)\n\nlemma count_tt_truthify : clause.count_tt \u03c4 (truthify \u03c4 l) = length l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : \u03c4 v; simp [literal.eval, h, ih, add_comm] }\nend\n\ntheorem count_tt_sublist : c\u2081 <+ c\u2082 \u2192 c\u2081.count_tt \u03c4 \u2264 c\u2082.count_tt \u03c4 :=\nassume h, by simp [clause.count_tt, sublist.countp_le (literal.is_true \u03c4) h]\n\ntheorem count_ff_sublist : c\u2081 <+ c\u2082 \u2192 c\u2081.count_ff \u03c4 \u2264 c\u2082.count_ff \u03c4 :=\nassume h, by simp [clause.count_ff, sublist.countp_le (literal.is_false \u03c4) h]\n\ntheorem count_pos_sublist : c\u2081 <+ c\u2082 \u2192 c\u2081.count_pos \u2264 c\u2082.count_pos :=\nassume h, by simp [count_pos, sublist.countp_le literal.is_pos h]\n\ntheorem count_neg_sublist : c\u2081 <+ c\u2082 \u2192 c\u2081.count_neg \u2264 c\u2082.count_neg :=\nassume h, by simp [count_neg, sublist.countp_le literal.is_neg h]\n\ntheorem pos_count_tt_iff_exists_tt {\u03c4} : c.count_tt \u03c4 > 0 \u2194 \u2203 l, l \u2208 c \u2227 literal.is_true \u03c4 l :=\nby simp [clause.count_tt, countp_pos]\n\ntheorem pos_count_ff_iff_exists_ff {\u03c4} : c.count_ff \u03c4 > 0 \u2194 \u2203 l, l \u2208 c \u2227 literal.is_false \u03c4 l :=\nby simp [clause.count_ff, countp_pos]\n\ntheorem pos_count_pos_iff_exists_pos : c.count_pos > 0 \u2194 \u2203 l, l \u2208 c \u2227 literal.is_pos l :=\nby simp [count_pos, countp_pos]\n\ntheorem pos_count_neg_iff_exists_neg : c.count_neg > 0 \u2194 \u2203 l, l \u2208 c \u2227 literal.is_neg l :=\nby simp [count_neg, countp_pos]\n\ntheorem count_tt_perm : c\u2081 ~ c\u2082 \u2192 \u2200 (\u03c4 : assignment V), c\u2081.count_tt \u03c4 = c\u2082.count_tt \u03c4 :=\nbegin\n  intros hp \u03c4,\n  induction hp with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082,\n  { refl },\n  { simp [count_tt_cons, IH] },\n  { simp [count_tt_cons], cases literal.eval \u03c4 x; cases literal.eval \u03c4 y; simp },\n  { exact eq.trans IH\u2081 IH\u2082 }\nend\n\nend falsify\n\n/-! # Flip counting -/\nsection flips\n\nvariables [decidable_eq V]\n\n-- If two clauses have the same length, literals can be compared at each\n-- position. If they are literal.flip's of each other, increment a counter\ndef count_flips : clause V \u2192 clause V \u2192 nat\n| []         _        := 0\n| _         []        := 0\n| (l :: ls) (m :: ms) := ite (l.flip = m) \n                         (1 + count_flips ls ms) (count_flips ls ms)\n\n@[simp] lemma count_flips_nil (c : clause V) : count_flips [] c = 0 :=\nby cases c; refl\n\n@[simp] theorem count_flips_cons (c\u2081 c\u2082 : clause V) (l\u2081 l\u2082 : literal V) :\n  count_flips (l\u2081 :: c\u2081) (l\u2082 :: c\u2082) = ite (l\u2081.flip = l\u2082) \n    (1 + count_flips c\u2081 c\u2082) (count_flips c\u2081 c\u2082) :=\nby by_cases l\u2081.flip = l\u2082; simp only [count_flips]\n\n@[simp] theorem count_flips_self (c : clause V) : count_flips c c = 0 :=\nbegin\n  induction c with l ls ih,\n  { refl },\n  { simp [count_flips, flip_ne, ih] }\nend\n\ntheorem count_flips_comm (c\u2081 c\u2082 : clause V) : count_flips c\u2081 c\u2082 = count_flips c\u2082 c\u2081 :=\nbegin\n  induction c\u2081 with l ls ih generalizing c\u2082,\n  { cases c\u2082; simp [count_flips] },\n  { cases c\u2082,\n    { refl },\n    { simp [count_flips, ih c\u2082_tl],\n      by_cases h : (l.flip = c\u2082_hd),\n      { simp [h, flip_eq_iff_eq_flip.mp h, flip_flip] },\n      { simp [h, ne.symm (flip_ne_iff_ne_flip.mp h), flip_flip] } } }\nend\n\ntheorem count_flips_pos_of_map_var_eq_of_neq {c\u2081 c\u2082 : clause V} :\n  map var c\u2081 = map var c\u2082 \u2192 c\u2081 \u2260 c\u2082 \u2192 count_flips c\u2081 c\u2082 > 0 :=\nbegin\n  intros h hne,\n  induction c\u2081 with l ls ih generalizing c\u2082,\n  { exact absurd (eq_nil_of_map_eq_nil h.symm).symm hne },\n  { rcases exists_map_cons_of_map_cons h.symm with \u27e8x, xs, rfl, hxl, hxs\u27e9,\n    unfold count_flips,\n    rcases var_eq_iff_eq_or_flip_eq.mp hxl with rfl | rfl,\n    { simp [ih (tail_eq_of_cons_eq h) (ne_tail_of_eq_head_of_ne hne rfl)] },\n    { simp [flip_flip, nat.zero_lt_one_add] } }\nend\n\ntheorem count_flips_falsify_eq_count_tt (\u03c4 : assignment V) (c : clause V) :\n  count_flips c (falsify \u03c4 (map var c)) = clause.count_tt \u03c4 c :=\nbegin\n  induction c with l ls ih,\n  { simp },\n  { cases l; { cases h : (\u03c4 l); { simp [var, h, literal.eval, literal.flip, ih] } } }\nend\n\n/-! ## Parity reasoning for evaluation -/\n\ntheorem eval_tt_of_map_var_eq_of_tt_ne_neg {\u03c4 : assignment V} {l : list V} {c : clause V} :\n  map var c = l \u2192 clause.count_tt \u03c4 (map Pos l) \u2260 count_neg c \u2192 c.eval \u03c4 = tt :=\nbegin\n  induction l with v vs ih generalizing c,\n  { rw map_eq_nil, rintro rfl, contradiction },\n  { intros hc hne,\n    rcases exists_cons_of_map_cons hc with \u27e8l, ls, rfl, rfl, hls\u27e9,\n    cases l,\n    { cases h : \u03c4 l,\n      { simp [literal.eval, var, literal.is_neg, h] at hne,\n        exact eval_tt_cons_of_eval_tt _ (ih hls hne) },\n      { simp [literal.eval, h] } },\n    { cases h : \u03c4 l,\n      { simp [literal.eval, h] },\n      { simp [literal.eval, var, literal.is_neg, h] at hne,\n        exact eval_tt_cons_of_eval_tt _ (ih hls hne) } } }\nend\n\n-- Corollary of the above wrt parity reasoning\ntheorem eval_tt_of_map_var_eq_of_ne_parity {\u03c4 : assignment V} {l : list V} {c : clause V} : \n  map var c = l \u2192 (clause.count_tt \u03c4 (map Pos l)).bodd \u2260 (count_neg c).bodd \u2192 c.eval \u03c4 = tt :=\n\u03bb hc hcount, eval_tt_of_map_var_eq_of_tt_ne_neg hc (ne_of_apply_ne nat.bodd hcount)\n\n-- Parity reasoning based on flips rather than negs\ntheorem eval_tt_of_ne_flips {\u03c4 : assignment V} {c\u2081 c\u2082 : clause V} :\n  map var c\u2081 = map var c\u2082 \u2192 c\u2081.count_tt \u03c4 \u2260 count_flips c\u2081 c\u2082 \u2192 c\u2082.eval \u03c4 = tt :=\nbegin\n  induction c\u2081 with l ls ih generalizing c\u2082,\n  { simp },\n  { intros hc\u2082 hne,\n    rcases exists_map_cons_of_map_cons hc\u2082.symm with \u27e8m, ms, rfl, hm, hms\u27e9,\n    cases m,\n    { cases h : (\u03c4 m),\n      { cases l;\n        { unfold var at hm,\n          simp [literal.eval, literal.flip, \u2190 hm, h] at hne,\n          exact eval_tt_cons_of_eval_tt _ (ih hms.symm hne) } },\n      { simp only [eval_cons, literal.eval, hm, h, tt_bor] } },\n    { cases h : (\u03c4 m),\n      { simp only [eval_cons, literal.eval, hm, h, bnot, tt_bor] },\n      { cases l;\n        { unfold var at hm,\n          simp [literal.eval, literal.flip, \u2190 hm, h] at hne,\n          exact eval_tt_cons_of_eval_tt _ (ih hms.symm hne) } } } }\nend\n\nend flips\n\n/-! # vars -/\nsection vars\n\nvariables [decidable_eq V]\n\nprotected def vars : clause V \u2192 finset V\n| []        := \u2205\n| (l :: ls) := {l.var} \u222a (vars ls) \n--| (l :: ls) := insert l.var (vars ls) -- Use insert instead?\n\n@[simp] theorem vars_nil : clause.vars ([] : clause V) = \u2205 := rfl\n@[simp] theorem vars_singleton (l : literal V) : clause.vars [l] = {l.var} := rfl\n@[simp] theorem vars_cons (l : literal V) (c : clause V) : clause.vars (l :: c) = {l.var} \u222a c.vars := rfl\n\ntheorem mem_vars_cons_self (l : literal V) (c : clause V) : l.var \u2208 clause.vars (l :: c) :=\nfinset.mem_union_left _ (finset.mem_singleton_self l.var)\n\ntheorem mem_vars_cons_of_mem_vars {c : clause V} (l : literal V) {v : V} : \n  v \u2208 c.vars \u2192 v \u2208 clause.vars (l :: c) :=\nassume h, finset.mem_union.mpr (or.inr h)\n\ntheorem vars_cons_of_mem {l : literal V} {c : clause V} : l.var \u2208 c.vars \u2192\n  clause.vars (l :: c) = c.vars :=\nbegin\n  intro h,\n  rw vars_cons,\n  apply finset.ext_iff.mpr, intro v,\n  split,\n  { intro hv,\n    rcases finset.mem_union.mp hv with (hmem | hmem),\n    { rw finset.mem_singleton at hmem,\n      subst hmem,\n      exact h },\n    { exact hmem } },\n  { exact finset.mem_union_right _ }\nend\n\ntheorem vars_append (c\u2081 c\u2082 : clause V) : (c\u2081 ++ c\u2082).vars = c\u2081.vars \u222a c\u2082.vars :=\nbegin\n  induction c\u2081 with l ls ih,\n  { simp only [finset.empty_union, vars_nil, nil_append] },\n  { simp only [cons_append, clause.vars, ih, finset.union_assoc], }\nend\n\ntheorem vars_perm {c\u2081 c\u2082 : clause V} : c\u2081 ~ c\u2082 \u2192 c\u2081.vars = c\u2082.vars :=\nbegin\n  intro hp,\n  induction hp with _ _ _ _ IH  x y _  _ _ _ _ _ IH\u2081 IH\u2082,\n  { refl },\n  { unfold clause.vars, rw IH },\n  { unfold clause.vars,\n    rw [\u2190 finset.union_assoc, \u2190 finset.union_assoc, finset.union_comm {x.var} {y.var}] },\n  { exact eq.trans IH\u2081 IH\u2082 }\nend\n\ntheorem mem_vars_of_mem {c : clause V} {l : literal V} : l \u2208 c \u2192 l.var \u2208 c.vars :=\nbegin\n  induction c with d ds ih,\n  { simp },\n  { intro hl,\n    rcases eq_or_ne_mem_of_mem hl with rfl | hm,\n    { exact finset.mem_union.mpr (or.inl (finset.mem_singleton_self l.var)) },\n    { exact finset.mem_union.mpr (or.inr (ih hm.2)) } }\nend\n\ntheorem exists_mem_clause_of_mem_vars {c : clause V} {v : V} : \n  v \u2208 c.vars \u2192 \u2203 (l : literal V), l \u2208 c \u2227 l.var = v :=\nbegin\n  induction c with l ls ih,\n  { simp },\n  { intro hmem, \n    by_cases h : (l.var = v),\n    { use [l, mem_cons_self l ls, h] },\n    { rcases finset.mem_union.mp hmem with h\u2081| h\u2082,\n      { exact absurd (finset.mem_singleton.mp h\u2081).symm h },\n      { rcases ih h\u2082 with \u27e8m, hm, hv\u27e9, use [m, mem_cons_of_mem l hm, hv] } } }\nend\n\ntheorem vars_subset_of_vars_cons (l : literal V) (c : clause V) : c.vars \u2286 clause.vars (l :: c) :=\nfinset.subset_union_right _ _\n\ntheorem vars_subset_of_subset {c\u2081 c\u2082 : clause V} : c\u2081 \u2286 c\u2082 \u2192 c\u2081.vars \u2286 c\u2082.vars :=\nbegin\n  intros h v hv,\n  rcases exists_mem_clause_of_mem_vars hv with \u27e8l, hl, rfl\u27e9,\n  exact mem_vars_of_mem (h hl)\nend\n\nsection mem_vars_lemmas\n\nvariables {v : V} {c : clause V}\n\n-- (map var c) and vars c are equivalent from a set perspective\ntheorem mem_vars_iff_mem_map_vars : v \u2208 c.vars \u2194 v \u2208 map var c :=\nbegin\n  split,\n  { intro h,\n    exact mem_map.mpr (exists_mem_clause_of_mem_vars h) },\n  { intro h,\n    rcases mem_map.mp h with \u27e8l, hmem, hv\u27e9,\n    exact hv \u25b8 mem_vars_of_mem hmem }\nend\n\ntheorem not_mem_vars_iff_not_mem_map_vars : v \u2209 map var c \u2194 v \u2209 c.vars :=\nby simp [mem_vars_iff_mem_map_vars]\n\ntheorem mem_vars_iff_pos_or_neg_mem_clause : v \u2208 c.vars \u2194 (Pos v) \u2208 c \u2228 (Neg v) \u2208 c :=\nbegin\n  split,\n  { intro h,\n    rcases exists_mem_clause_of_mem_vars h with \u27e8l, hmem, hv\u27e9,\n    cases l; { rw \u2190 hv, simp [var, hmem] } },\n  { rintros (h | h); { exact mem_vars_of_mem h } }\nend\n\ntheorem vars_append_subset_left (c\u2081 c\u2082 : clause V) : c\u2081.vars \u2286 (c\u2081 ++ c\u2082).vars :=\nby { rw vars_append, exact finset.subset_union_left _ _ }\n\ntheorem vars_append_subset_right (c\u2081 c\u2082 : clause V) : c\u2082.vars \u2286 (c\u2081 ++ c\u2082).vars :=\nby { rw vars_append, exact finset.subset_union_right _ _ }\n\ntheorem mem_vars_append_left {c\u2081 : clause V} (c\u2082) : v \u2208 c\u2081.vars \u2192 v \u2208 (c\u2081 ++ c\u2082).vars :=\nassume h, vars_append_subset_left c\u2081 c\u2082 h\n\ntheorem mem_vars_append_right (c\u2081) {c\u2082 : clause V} : v \u2208 c\u2082.vars \u2192 v \u2208 (c\u2081 ++ c\u2082).vars :=\nassume h, vars_append_subset_right c\u2081 c\u2082 h\n\ntheorem mem_left_or_right_of_mem_vars_append {c\u2081 c\u2082 : clause V} :\n  v \u2208 (c\u2081 ++ c\u2082).vars \u2192 (v \u2208 c\u2081.vars) \u2228 (v \u2208 c\u2082.vars) :=\nby { rw vars_append, exact finset.mem_union.mp }\n\ntheorem not_mem_vars_append_left {c\u2081 c\u2082 : clause V} : v \u2209 (c\u2081 ++ c\u2082).vars \u2192 v \u2209 c\u2081.vars :=\nassume h, mt (mem_vars_append_left c\u2082) h\n\ntheorem not_mem_vars_append_right {c\u2081 c\u2082 : clause V} : v \u2209 (c\u2081 ++ c\u2082).vars \u2192 v \u2209 c\u2082.vars :=\nassume h, mt (mem_vars_append_right c\u2081) h\n\ntheorem not_mem_vars_append_of_not_mem_of_not_mem {c\u2081 c\u2082 : clause V} :\n  v \u2209 c\u2081.vars \u2192 v \u2209 c\u2082.vars \u2192 v \u2209 (c\u2081 ++ c\u2082).vars :=\nbegin\n  intros h\u2081 h\u2082 hcon,\n  rcases mem_left_or_right_of_mem_vars_append hcon; { contradiction }\nend\n\nend mem_vars_lemmas\n\nopen assignment\n\nvariables {\u03c4\u2081 \u03c4\u2082 : assignment V} {c : clause V}\n\ntheorem eval_eq_of_agree_on : (agree_on \u03c4\u2081 \u03c4\u2082 c.vars) \u2192 c.eval \u03c4\u2081 = c.eval \u03c4\u2082 :=\nbegin\n  intro h,\n  cases hev : (c.eval \u03c4\u2082),\n  { rw eval_ff_iff_forall_literal_eval_ff at hev,\n    apply eval_ff_iff_forall_literal_eval_ff.mpr,\n    intros l hl,\n    exact hev l hl \u25b8 eval_eq_of_agree_on_of_var_mem h (mem_vars_of_mem hl) },\n  { rcases eval_tt_iff_exists_literal_eval_tt.mp hev with \u27e8l, hl, htt\u27e9,\n    apply eval_tt_iff_exists_literal_eval_tt.mpr,\n    use [l, hl],\n    exact htt \u25b8 eval_eq_of_agree_on_of_var_mem h (mem_vars_of_mem hl) }  \nend\n\ntheorem nth_eval_eq_of_agree_on {l : list (literal V)} {i : nat} (hi : i < length l) :\n  (agree_on \u03c4\u2081 \u03c4\u2082 (clause.vars l)) \u2192 (l.nth_le i hi).eval \u03c4\u2081 = (l.nth_le i hi).eval \u03c4\u2082 :=\nassume hagree_on, eval_eq_of_agree_on_of_var_mem hagree_on (mem_vars_of_mem (nth_le_mem _ _ _))\n\ntheorem agree_on_of_agree_on_vars_cons {l : literal V} : \n  (agree_on \u03c4\u2081 \u03c4\u2082 (clause.vars (l :: c))) \u2192 agree_on \u03c4\u2081 \u03c4\u2082 (clause.vars c) :=\nassume hagree_on v hv, hagree_on _ (finset.mem_union_right _ hv)\n\ntheorem count_tt_eq_of_agree_on : (agree_on \u03c4\u2081 \u03c4\u2082 c.vars) \u2192 c.count_tt \u03c4\u2081 = c.count_tt \u03c4\u2082 :=\nbegin\n  induction c with l ls ih,\n  { simp only [count_tt_nil, agree_on_nil, vars_nil, forall_true_left] },\n  { intro h,\n    rw clause.vars at h,\n    cases l;\n    { rw literal.var at h,\n      simp [literal.eval, agree_on_union_left h l (finset.mem_singleton_self l), ih (agree_on_union_right h)] } }\nend\n\ntheorem count_tt_ite (c : clause V) : c.count_tt (aite c.vars \u03c4\u2081 \u03c4\u2082) = c.count_tt \u03c4\u2081 :=\ncount_tt_eq_of_agree_on (aite_agree_on c.vars \u03c4\u2081 \u03c4\u2082)\n\nend vars\n\nend clause", "meta": {"author": "ccodel", "repo": "verified-encodings", "sha": "ee22a6a04ee56cc568f91fbee5a70d39e5e261f8", "save_path": "github-repos/lean/ccodel-verified-encodings", "path": "github-repos/lean/ccodel-verified-encodings/verified-encodings-ee22a6a04ee56cc568f91fbee5a70d39e5e261f8/src/cnf/clause.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7157956064904245}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport group_theory.perm.list\nimport data.list.cycle\nimport group_theory.perm.cycle_type\n\n/-!\n\n# Properties of cyclic permutations constructed from lists/cycles\n\nIn the following, `{\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1]`.\n\n## Main definitions\n\n* `cycle.form_perm`: the cyclic permutation created by looping over a `cycle \u03b1`\n* `equiv.perm.to_list`: the list formed by iterating application of a permutation\n* `equiv.perm.to_cycle`: the cycle formed by iterating application of a permutation\n* `equiv.perm.iso_cycle`: the equivalence between cyclic permutations `f : perm \u03b1`\n  and the terms of `cycle \u03b1` that correspond to them\n* `equiv.perm.iso_cycle'`: the same equivalence as `equiv.perm.iso_cycle`\n  but with evaluation via choosing over fintypes\n* The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)`\n* A `has_repr` instance for any `perm \u03b1`, by representing the `finset` of\n  `cycle \u03b1` that correspond to the cycle factors.\n\n## Main results\n\n* `list.is_cycle_form_perm`: a nontrivial list without duplicates, when interpreted as\n  a permutation, is cyclic\n* `equiv.perm.is_cycle.exists_unique_cycle`: there is only one nontrivial `cycle \u03b1`\n  corresponding to each cyclic `f : perm \u03b1`\n\n## Implementation details\n\nThe forward direction of `equiv.perm.iso_cycle'` uses `fintype.choose` of the uniqueness\nresult, relying on the `fintype` instance of a `cycle.nodup` subtype.\nIt is unclear if this works faster than the `equiv.perm.to_cycle`, which relies\non recursion over `finset.univ`.\nRunning `#eval` on even a simple noncyclic permutation `c[(1 : fin 7), 2, 3] * c[0, 5]`\nto show it takes a long time. TODO: is this because computing the cycle factors is slow?\n\n-/\n\nopen equiv equiv.perm list\n\nnamespace list\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] {l l' : list \u03b1}\n\nlemma form_perm_disjoint_iff (hl : nodup l) (hl' : nodup l')\n  (hn : 2 \u2264 l.length) (hn' : 2 \u2264 l'.length) :\n  perm.disjoint (form_perm l) (form_perm l') \u2194 l.disjoint l' :=\nbegin\n  rw [disjoint_iff_eq_or_eq, list.disjoint],\n  split,\n  { rintro h x hx hx',\n    specialize h x,\n    rw [form_perm_apply_mem_eq_self_iff _ hl _ hx,\n        form_perm_apply_mem_eq_self_iff _ hl' _ hx'] at h,\n    rcases h with hl | hl'; linarith },\n  { intros h x,\n    by_cases hx : x \u2208 l, by_cases hx' : x \u2208 l',\n    { exact (h hx hx').elim },\n    all_goals { have := form_perm_eq_self_of_not_mem _ _ \u2039_\u203a, tauto } }\nend\n\nlemma is_cycle_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) :\n  is_cycle (form_perm l) :=\nbegin\n  cases l with x l,\n  { norm_num at hn },\n  induction l with y l IH generalizing x,\n  { norm_num at hn },\n  { use x,\n    split,\n    { rwa form_perm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _) },\n    { intros w hw,\n      have : w \u2208 (x :: y :: l) := mem_of_form_perm_ne_self _ _ hw,\n      obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem this,\n      use k,\n      simp only [zpow_coe_nat, form_perm_pow_apply_head _ _ hl k, nat.mod_eq_of_lt hk] } }\nend\n\nlemma pairwise_same_cycle_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) :\n  pairwise (l.form_perm.same_cycle) l :=\npairwise.imp_mem.mpr (pairwise_of_forall (\u03bb x y hx hy, (is_cycle_form_perm hl hn).same_cycle\n  ((form_perm_apply_mem_ne_self_iff _ hl _ hx).mpr hn)\n  ((form_perm_apply_mem_ne_self_iff _ hl _ hy).mpr hn)))\n\nlemma cycle_of_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) (x) :\n  cycle_of l.attach.form_perm x = l.attach.form_perm :=\nhave hn : 2 \u2264 l.attach.length := by rwa \u2190 length_attach at hn,\nhave hl : l.attach.nodup := by rwa \u2190 nodup_attach at hl,\n(is_cycle_form_perm hl hn).cycle_of_eq\n  ((form_perm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn)\n\nlemma cycle_type_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) :\n  cycle_type l.attach.form_perm = {l.length} :=\nbegin\n  rw \u2190length_attach at hn,\n  rw \u2190nodup_attach at hl,\n  rw cycle_type_eq [l.attach.form_perm],\n  { simp only [map, function.comp_app],\n    rw [support_form_perm_of_nodup _ hl, card_to_finset, erase_dup_eq_self.mpr hl],\n    { simpa },\n    { intros x h,\n      simpa [h, nat.succ_le_succ_iff] using hn } },\n  { simp },\n  { simpa using is_cycle_form_perm hl hn },\n  { simp }\nend\n\nlemma form_perm_apply_mem_eq_next (hl : nodup l) (x : \u03b1) (hx : x \u2208 l) :\n  form_perm l x = next l x hx :=\nbegin\n  obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx,\n  rw [next_nth_le _ hl, form_perm_apply_nth_le _ hl]\nend\n\nend list\n\nnamespace cycle\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] (s s' : cycle \u03b1)\n\n/--\nA cycle `s : cycle \u03b1` , given `nodup s` can be interpreted as a `equiv.perm \u03b1`\nwhere each element in the list is permuted to the next one, defined as `form_perm`.\n-/\ndef form_perm : \u03a0 (s : cycle \u03b1) (h : nodup s), equiv.perm \u03b1 :=\n\u03bb s, quot.hrec_on s (\u03bb l h, form_perm l)\n  (\u03bb l\u2081 l\u2082 (h : l\u2081 ~r l\u2082),\n    begin\n      ext,\n      { exact h.nodup_iff },\n      { intros h\u2081 h\u2082 _,\n        exact heq_of_eq (form_perm_eq_of_is_rotated h\u2081 h) }\n    end)\n\n@[simp] lemma form_perm_coe (l : list \u03b1) (hl : l.nodup) :\n  form_perm (l : cycle \u03b1) hl = l.form_perm := rfl\n\nlemma form_perm_subsingleton (s : cycle \u03b1) (h : subsingleton s) :\n  form_perm s h.nodup = 1 :=\nbegin\n  induction s using quot.induction_on,\n  simp only [form_perm_coe, mk_eq_coe],\n  simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h,\n  cases s with hd tl,\n  { simp },\n  { simp only [length_eq_zero, add_le_iff_nonpos_left, list.length, nonpos_iff_eq_zero] at h,\n    simp [h] }\nend\n\nlemma is_cycle_form_perm (s : cycle \u03b1) (h : nodup s) (hn : nontrivial s) :\n  is_cycle (form_perm s h) :=\nbegin\n  induction s using quot.induction_on,\n  exact list.is_cycle_form_perm h (length_nontrivial hn)\nend\n\nlemma support_form_perm [fintype \u03b1] (s : cycle \u03b1) (h : nodup s) (hn : nontrivial s) :\n  support (form_perm s h) = s.to_finset :=\nbegin\n  induction s using quot.induction_on,\n  refine support_form_perm_of_nodup s h _,\n  rintro _ rfl,\n  simpa [nat.succ_le_succ_iff] using length_nontrivial hn\nend\n\nlemma form_perm_eq_self_of_not_mem (s : cycle \u03b1) (h : nodup s) (x : \u03b1) (hx : x \u2209 s) :\n  form_perm s h x = x :=\nbegin\n  induction s using quot.induction_on,\n  simpa using list.form_perm_eq_self_of_not_mem _ _ hx\nend\n\nlemma form_perm_apply_mem_eq_next (s : cycle \u03b1) (h : nodup s) (x : \u03b1) (hx : x \u2208 s) :\n  form_perm s h x = next s h x hx :=\nbegin\n  induction s using quot.induction_on,\n  simpa using list.form_perm_apply_mem_eq_next h _ _\nend\n\nlemma form_perm_reverse (s : cycle \u03b1) (h : nodup s) :\n  form_perm s.reverse (nodup_reverse_iff.mpr h) = (form_perm s h)\u207b\u00b9 :=\nbegin\n  induction s using quot.induction_on,\n  simpa using form_perm_reverse _ h\nend\n\nlemma form_perm_eq_form_perm_iff {\u03b1 : Type*} [decidable_eq \u03b1]\n  {s s' : cycle \u03b1} {hs : s.nodup} {hs' : s'.nodup} :\n  s.form_perm hs = s'.form_perm hs' \u2194 s = s' \u2228 s.subsingleton \u2227 s'.subsingleton :=\nbegin\n  rw [cycle.length_subsingleton_iff, cycle.length_subsingleton_iff],\n  revert s s',\n  intros s s',\n  apply quotient.induction_on\u2082' s s',\n  intros l l',\n  simpa using form_perm_eq_form_perm_iff\nend\n\nend cycle\nvariables {\u03b1 : Type*}\n\nnamespace equiv.perm\n\nvariables [fintype \u03b1] [decidable_eq \u03b1] (p : equiv.perm \u03b1) (x : \u03b1)\n\n/--\n`equiv.perm.to_list (f : perm \u03b1) (x : \u03b1)` generates the list `[x, f x, f (f x), ...]`\nuntil looping. That means when `f x = x`, `to_list f x = []`.\n-/\ndef to_list : list \u03b1 :=\n(list.range (cycle_of p x).support.card).map (\u03bb k, (p ^ k) x)\n\n@[simp] lemma to_list_one : to_list (1 : perm \u03b1) x = [] :=\nby simp [to_list, cycle_of_one]\n\n@[simp] lemma to_list_eq_nil_iff {p : perm \u03b1} {x} : to_list p x = [] \u2194 x \u2209 p.support :=\nby simp [to_list]\n\n@[simp] lemma length_to_list : length (to_list p x) = (cycle_of p x).support.card :=\nby simp [to_list]\n\nlemma to_list_ne_singleton (y : \u03b1) : to_list p x \u2260 [y] :=\nbegin\n  intro H,\n  simpa [card_support_ne_one] using congr_arg length H\nend\n\nlemma two_le_length_to_list_iff_mem_support {p : perm \u03b1} {x : \u03b1} :\n  2 \u2264 length (to_list p x) \u2194 x \u2208 p.support :=\nby simp\n\nlemma length_to_list_pos_of_mem_support (h : x \u2208 p.support) : 0 < length (to_list p x) :=\nzero_lt_two.trans_le (two_le_length_to_list_iff_mem_support.mpr h)\n\nlemma nth_le_to_list (n : \u2115) (hn : n < length (to_list p x)) :\n  nth_le (to_list p x) n hn = (p ^ n) x :=\nby simp [to_list]\n\nlemma to_list_nth_le_zero (h : x \u2208 p.support) :\n  (to_list p x).nth_le 0 (length_to_list_pos_of_mem_support _ _ h) = x :=\nby simp [to_list]\n\nvariables {p} {x}\n\nlemma mem_to_list_iff {y : \u03b1} :\n  y \u2208 to_list p x \u2194 same_cycle p x y \u2227 x \u2208 p.support :=\nbegin\n  simp only [to_list, mem_range, mem_map],\n  split,\n  { rintro \u27e8n, hx, rfl\u27e9,\n    refine \u27e8\u27e8n, rfl\u27e9, _\u27e9,\n    contrapose! hx,\n    rw \u2190support_cycle_of_eq_nil_iff at hx,\n    simp [hx] },\n  { rintro \u27e8h, hx\u27e9,\n    simpa using same_cycle.nat_of_mem_support _ h hx }\nend\n\nlemma nodup_to_list (p : perm \u03b1) (x : \u03b1) :\n  nodup (to_list p x) :=\nbegin\n  by_cases hx : p x = x,\n  { rw [\u2190not_mem_support, \u2190to_list_eq_nil_iff] at hx,\n    simp [hx] },\n  have hc : is_cycle (cycle_of p x) := is_cycle_cycle_of p hx,\n  rw nodup_iff_nth_le_inj,\n  rintros n m hn hm,\n  rw [length_to_list, \u2190order_of_is_cycle hc] at hm hn,\n  rw [\u2190cycle_of_apply_self, \u2190ne.def, \u2190mem_support] at hx,\n  rw [nth_le_to_list, nth_le_to_list,\n      \u2190cycle_of_pow_apply_self p x n, \u2190cycle_of_pow_apply_self p x m],\n  cases n; cases m,\n  { simp },\n  { rw [\u2190hc.mem_support_pos_pow_iff_of_lt_order_of m.zero_lt_succ hm,\n        mem_support, cycle_of_pow_apply_self] at hx,\n    simp [hx.symm] },\n  { rw [\u2190hc.mem_support_pos_pow_iff_of_lt_order_of n.zero_lt_succ hn,\n        mem_support, cycle_of_pow_apply_self] at hx,\n    simp [hx] },\n  intro h,\n  have hn' : \u00ac order_of (p.cycle_of x) \u2223 n.succ := nat.not_dvd_of_pos_of_lt n.zero_lt_succ hn,\n  have hm' : \u00ac order_of (p.cycle_of x) \u2223 m.succ := nat.not_dvd_of_pos_of_lt m.zero_lt_succ hm,\n  rw \u2190hc.support_pow_eq_iff at hn' hm',\n  rw [\u2190nat.mod_eq_of_lt hn, \u2190nat.mod_eq_of_lt hm, \u2190pow_inj_mod],\n  refine support_congr _ _,\n  { rw [hm', hn'],\n    exact finset.subset.refl _ },\n  { rw hm',\n    intros y hy,\n    obtain \u27e8k, rfl\u27e9 := hc.exists_pow_eq (mem_support.mp hx) (mem_support.mp hy),\n    rw [\u2190mul_apply, (commute.pow_pow_self _ _ _).eq, mul_apply, h, \u2190mul_apply, \u2190mul_apply,\n        (commute.pow_pow_self _ _ _).eq] }\nend\n\nlemma next_to_list_eq_apply (p : perm \u03b1) (x y : \u03b1) (hy : y \u2208 to_list p x) :\n  next (to_list p x) y hy = p y :=\nbegin\n  rw mem_to_list_iff at hy,\n  obtain \u27e8k, hk, hk'\u27e9 := hy.left.nat_of_mem_support _ hy.right,\n  rw \u2190nth_le_to_list p x k (by simpa using hk) at hk',\n  simp_rw \u2190hk',\n  rw [next_nth_le _ (nodup_to_list _ _), nth_le_to_list, nth_le_to_list, \u2190mul_apply, \u2190pow_succ,\n      length_to_list, pow_apply_eq_pow_mod_order_of_cycle_of_apply p (k + 1), order_of_is_cycle],\n  exact is_cycle_cycle_of _ (mem_support.mp hy.right)\nend\n\nlemma to_list_pow_apply_eq_rotate (p : perm \u03b1) (x : \u03b1) (k : \u2115) :\n  p.to_list ((p ^ k) x) = (p.to_list x).rotate k :=\nbegin\n  apply ext_le,\n  { simp },\n  { intros n hn hn',\n    rw [nth_le_to_list, nth_le_rotate, nth_le_to_list, length_to_list,\n        pow_mod_card_support_cycle_of_self_apply, pow_add, mul_apply] }\nend\n\nlemma same_cycle.to_list_is_rotated {f : perm \u03b1} {x y : \u03b1} (h : same_cycle f x y) :\n  to_list f x ~r to_list f y :=\nbegin\n  by_cases hx : x \u2208 f.support,\n  { obtain \u27e8_ | k, hk, hy\u27e9 := h.nat_of_mem_support _ hx,\n    { simp only [coe_one, id.def, pow_zero] at hy,\n      simp [hy] },\n    use k.succ,\n    rw [\u2190to_list_pow_apply_eq_rotate, hy] },\n  { rw [to_list_eq_nil_iff.mpr hx, is_rotated_nil_iff', eq_comm, to_list_eq_nil_iff],\n    rwa \u2190h.mem_support_iff }\nend\n\nlemma pow_apply_mem_to_list_iff_mem_support {n : \u2115} :\n  (p ^ n) x \u2208 p.to_list x \u2194 x \u2208 p.support :=\nbegin\n  rw [mem_to_list_iff, and_iff_right_iff_imp],\n  refine \u03bb _, same_cycle.symm _,\n  rw same_cycle_pow_left_iff\nend\n\nlemma to_list_form_perm_nil (x : \u03b1) :\n  to_list (form_perm ([] : list \u03b1)) x = [] :=\nby simp\n\nlemma to_list_form_perm_singleton (x y : \u03b1) :\n  to_list (form_perm [x]) y = [] :=\nby simp\n\nlemma to_list_form_perm_nontrivial (l : list \u03b1) (hl : 2 \u2264 l.length) (hn : nodup l) :\n  to_list (form_perm l) (l.nth_le 0 (zero_lt_two.trans_le hl)) = l :=\nbegin\n  have hc : l.form_perm.is_cycle := list.is_cycle_form_perm hn hl,\n  have hs : l.form_perm.support = l.to_finset,\n  { refine support_form_perm_of_nodup _ hn _,\n    rintro _ rfl,\n    simpa [nat.succ_le_succ_iff] using hl },\n  rw [to_list, hc.cycle_of_eq (mem_support.mp _), hs, card_to_finset, erase_dup_eq_self.mpr hn],\n  { refine list.ext_le (by simp) (\u03bb k hk hk', _),\n    simp [form_perm_pow_apply_nth_le _ hn, nat.mod_eq_of_lt hk'] },\n  { simpa [hs] using nth_le_mem _ _ _ }\nend\n\nlemma to_list_form_perm_is_rotated_self (l : list \u03b1) (hl : 2 \u2264 l.length) (hn : nodup l)\n  (x : \u03b1) (hx : x \u2208 l):\n  to_list (form_perm l) x ~r l :=\nbegin\n  obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx,\n  have hr : l ~r l.rotate k := \u27e8k, rfl\u27e9,\n  rw form_perm_eq_of_is_rotated hn hr,\n  rw \u2190nth_le_rotate' l k k,\n  simp only [nat.mod_eq_of_lt hk, tsub_add_cancel_of_le hk.le, nat.mod_self],\n  rw [to_list_form_perm_nontrivial],\n  { simp },\n  { simpa using hl },\n  { simpa using hn }\nend\n\nlemma form_perm_to_list (f : perm \u03b1) (x : \u03b1) :\n  form_perm (to_list f x) = f.cycle_of x :=\nbegin\n  by_cases hx : f x = x,\n  { rw [(cycle_of_eq_one_iff f).mpr hx, to_list_eq_nil_iff.mpr (not_mem_support.mpr hx),\n        form_perm_nil] },\n  ext y,\n  by_cases hy : same_cycle f x y,\n  { obtain \u27e8k, hk, rfl\u27e9 := hy.nat_of_mem_support _ (mem_support.mpr hx),\n    rw [cycle_of_apply_apply_pow_self, list.form_perm_apply_mem_eq_next (nodup_to_list f x),\n        next_to_list_eq_apply, pow_succ, mul_apply],\n    rw mem_to_list_iff,\n    exact \u27e8\u27e8k, rfl\u27e9, mem_support.mpr hx\u27e9 },\n  { rw [cycle_of_apply_of_not_same_cycle hy, form_perm_apply_of_not_mem],\n    simp [mem_to_list_iff, hy] }\nend\n\nlemma is_cycle.exists_unique_cycle {f : perm \u03b1} (hf : is_cycle f) :\n  \u2203! (s : cycle \u03b1), \u2203 (h : s.nodup), s.form_perm h = f :=\nbegin\n  obtain \u27e8x, hx, hy\u27e9 := id hf,\n  refine \u27e8f.to_list x, \u27e8nodup_to_list f x, _\u27e9, _\u27e9,\n  { simp [form_perm_to_list, hf.cycle_of_eq hx] },\n  { rintro \u27e8l\u27e9 \u27e8hn, rfl\u27e9,\n    simp only [cycle.mk_eq_coe, cycle.coe_eq_coe, subtype.coe_mk, cycle.form_perm_coe],\n    refine (to_list_form_perm_is_rotated_self _ _ hn _ _).symm,\n    { contrapose! hx,\n      suffices : form_perm l = 1,\n      { simp [this] },\n      rw form_perm_eq_one_iff _ hn,\n      exact nat.le_of_lt_succ hx },\n    { rw \u2190mem_to_finset,\n      refine support_form_perm_le l _,\n      simpa using hx } }\nend\n\nlemma is_cycle.exists_unique_cycle_subtype {f : perm \u03b1} (hf : is_cycle f) :\n  \u2203! (s : {s : cycle \u03b1 // s.nodup}), (s : cycle \u03b1).form_perm s.prop = f :=\nbegin\n  obtain \u27e8s, \u27e8hs, rfl\u27e9, hs'\u27e9 := hf.exists_unique_cycle,\n  refine \u27e8\u27e8s, hs\u27e9, rfl, _\u27e9,\n  rintro \u27e8t, ht\u27e9 ht',\n  simpa using hs' _ \u27e8ht, ht'\u27e9\nend\n\nlemma is_cycle.exists_unique_cycle_nontrivial_subtype {f : perm \u03b1} (hf : is_cycle f) :\n  \u2203! (s : {s : cycle \u03b1 // s.nodup \u2227 s.nontrivial}), (s : cycle \u03b1).form_perm s.prop.left = f :=\nbegin\n  obtain \u27e8\u27e8s, hn\u27e9, hs, hs'\u27e9 := hf.exists_unique_cycle_subtype,\n  refine \u27e8\u27e8s, hn, _\u27e9, _, _\u27e9,\n  { rw hn.nontrivial_iff,\n    subst f,\n    intro H,\n    refine hf.ne_one _,\n    simpa using cycle.form_perm_subsingleton _ H },\n  { simpa using hs },\n  { rintro \u27e8t, ht, ht'\u27e9 ht'',\n    simpa using hs' \u27e8t, ht\u27e9 ht'' }\nend\n\n/--\nGiven a cyclic `f : perm \u03b1`, generate the `cycle \u03b1` in the order\nof application of `f`. Implemented by finding an element `x : \u03b1`\nin the support of `f` in `finset.univ`, and iterating on using\n`equiv.perm.to_list f x`.\n-/\ndef to_cycle (f : perm \u03b1) (hf : is_cycle f) : cycle \u03b1 :=\nmultiset.rec_on (finset.univ : finset \u03b1).val\n  (quot.mk _ [])\n  (\u03bb x s l, if f x = x then l else to_list f x)\n  (by { intros x y m s,\n    refine heq_of_eq _,\n    split_ifs with hx hy hy; try { refl },\n    { have hc : same_cycle f x y := is_cycle.same_cycle hf hx hy,\n      exact quotient.sound' hc.to_list_is_rotated }})\n\nlemma to_cycle_eq_to_list (f : perm \u03b1) (hf : is_cycle f) (x : \u03b1) (hx : f x \u2260 x) :\n  to_cycle f hf = to_list f x :=\nbegin\n  have key : (finset.univ : finset \u03b1).val = x ::\u2098 finset.univ.val.erase x,\n  { simp },\n  rw [to_cycle, key],\n  simp [hx]\nend\n\nlemma nodup_to_cycle (f : perm \u03b1) (hf : is_cycle f) : (to_cycle f hf).nodup :=\nbegin\n  obtain \u27e8x, hx, -\u27e9 := id hf,\n  simpa [to_cycle_eq_to_list f hf x hx] using nodup_to_list _ _\nend\n\nlemma nontrivial_to_cycle (f : perm \u03b1) (hf : is_cycle f) : (to_cycle f hf).nontrivial :=\nbegin\n  obtain \u27e8x, hx, -\u27e9 := id hf,\n  simp [to_cycle_eq_to_list f hf x hx, hx, cycle.nontrivial_coe_nodup_iff (nodup_to_list _ _)]\nend\n\n/--\nAny cyclic `f : perm \u03b1` is isomorphic to the nontrivial `cycle \u03b1`\nthat corresponds to repeated application of `f`.\nThe forward direction is implemented by `equiv.perm.to_cycle`.\n-/\ndef iso_cycle : {f : perm \u03b1 // is_cycle f} \u2243 {s : cycle \u03b1 // s.nodup \u2227 s.nontrivial} :=\n{ to_fun := \u03bb f, \u27e8to_cycle (f : perm \u03b1) f.prop, nodup_to_cycle f f.prop,\n    nontrivial_to_cycle _ f.prop\u27e9,\n  inv_fun := \u03bb s, \u27e8(s : cycle \u03b1).form_perm s.prop.left,\n    (s : cycle \u03b1).is_cycle_form_perm _ s.prop.right\u27e9,\n  left_inv := \u03bb f, by\n  { obtain \u27e8x, hx, -\u27e9 := id f.prop,\n    simpa [to_cycle_eq_to_list (f : perm \u03b1) f.prop x hx, form_perm_to_list, subtype.ext_iff]\n      using f.prop.cycle_of_eq hx },\n  right_inv := \u03bb s, by\n  { rcases s with \u27e8\u27e8s\u27e9, hn, ht\u27e9,\n    obtain \u27e8x, -, -, hx, -\u27e9 := id ht,\n    have hl : 2 \u2264 s.length := by simpa using cycle.length_nontrivial ht,\n    simp only [cycle.mk_eq_coe, cycle.nodup_coe_iff, cycle.mem_coe_iff, subtype.coe_mk,\n               cycle.form_perm_coe] at hn hx \u22a2,\n    rw to_cycle_eq_to_list _ _ x,\n    { refine quotient.sound' _,\n      exact to_list_form_perm_is_rotated_self _ hl hn _ hx },\n    { rw [\u2190mem_support, support_form_perm_of_nodup _ hn],\n      { simpa using hx },\n      { rintro _ rfl,\n        simpa [nat.succ_le_succ_iff] using hl } } } }\n\n/--\nAny cyclic `f : perm \u03b1` is isomorphic to the nontrivial `cycle \u03b1`\nthat corresponds to repeated application of `f`.\nThe forward direction is implemented by finding this `cycle \u03b1` using `fintype.choose`.\n-/\ndef iso_cycle' : {f : perm \u03b1 // is_cycle f} \u2243 {s : cycle \u03b1 // s.nodup \u2227 s.nontrivial} :=\n{ to_fun := \u03bb f, fintype.choose _ f.prop.exists_unique_cycle_nontrivial_subtype,\n  inv_fun := \u03bb s, \u27e8(s : cycle \u03b1).form_perm s.prop.left,\n    (s : cycle \u03b1).is_cycle_form_perm _ s.prop.right\u27e9,\n  left_inv := \u03bb f, by simpa [subtype.ext_iff]\n    using fintype.choose_spec _ f.prop.exists_unique_cycle_nontrivial_subtype,\n  right_inv := \u03bb \u27e8s, hs, ht\u27e9, by\n  { simp [subtype.coe_mk],\n    convert fintype.choose_subtype_eq (\u03bb (s' : cycle \u03b1), s'.nodup \u2227 s'.nontrivial) _,\n    ext \u27e8s', hs', ht'\u27e9,\n    simp [cycle.form_perm_eq_form_perm_iff, (iff_not_comm.mp hs.nontrivial_iff),\n          (iff_not_comm.mp hs'.nontrivial_iff), ht] } }\n\nnotation `c[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) :=\n  cycle.form_perm \u2191l (cycle.nodup_coe_iff.mpr dec_trivial)\n\ninstance repr_perm [has_repr \u03b1] : has_repr (perm \u03b1) :=\n\u27e8\u03bb f, repr (multiset.pmap (\u03bb (g : perm \u03b1) (hg : g.is_cycle),\n  iso_cycle \u27e8g, hg\u27e9) -- to_cycle is faster?\n  (perm.cycle_factors_finset f).val\n  (\u03bb g hg, (mem_cycle_factors_finset_iff.mp (finset.mem_def.mpr hg)).left))\u27e9\n\nend equiv.perm\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/group_theory/perm/concrete_cycle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7157956037299571}}
{"text": "/-\nThis defines additional operations used to normalize inequalitis.\n-/\nimport ClausalExtraction.ArithTheory.Nat\n\nnamespace Int\n\n-- Thoems only about subNatNat and nat-level operations\n-- We make these private as the intention is that users should not need to directly\n-- work with subNatNat\nsection subNatNat\n\nprivate\ntheorem subNatNat.is_ofNat {x y:Nat} (p:y \u2264 x) : subNatNat x y = ofNat (x - y) := by\n  simp [subNatNat]\n  have h : y - x = 0 := by simp only [Nat.sub_is_zero_is_le, p]\n  simp [h]\n\nprivate theorem subNatNat.is_negSucc {x y:Nat} (p:x < y) : subNatNat x y = negSucc (y - Nat.succ x) := by\n  generalize g: y - x = y_sub_x\n  cases y_sub_x with\n  | zero =>\n    have h : Nat.zero = 0 := rfl\n    simp only [h, Nat.sub_is_zero_is_le] at g\n    exact (False.elim (Nat.not_le_of_gt p g))\n  | succ y_sub_x =>\n    simp only [subNatNat, g, Nat.sub_succ, Nat.pred]\n\nprivate\ntheorem succ_subNatNat_succ (x y : Nat) : subNatNat (Nat.succ x) (Nat.succ y) = subNatNat x y := by\n  match Nat.lt_or_ge x y with\n  | Or.inr p =>\n    have q := Nat.succ_le_succ p\n    simp [subNatNat.is_ofNat, p, q, Nat.succ_sub_succ]\n  | Or.inl p =>\n    have q := Nat.succ_lt_succ p\n    simp [subNatNat.is_negSucc, p, q, Nat.succ_sub_succ]\n\nprivate\ntheorem subNatNat_self (x:Nat) : subNatNat x x = 0 := by\n  induction x with\n  | zero => rfl\n  | succ x ind => simp [succ_subNatNat_succ, ind]\n\nprivate\ntheorem subNatNat_zero (x : Nat) : subNatNat x 0 = ofNat x := by\n  simp [subNatNat.is_ofNat, Nat.zero_le]\n\nprivate\ntheorem zero_subNatNat_succ (x:Nat) : subNatNat 0 (Nat.succ x) = Int.negSucc x := by\n  simp [subNatNat.is_negSucc, Nat.zero_lt_succ, Nat.succ_sub_succ, Nat.sub_zero]\n\nprivate\ntheorem subNatNat_sub_lhs (p : x \u2265 y) (z:Nat) : subNatNat (x - y) z = subNatNat x (y + z) := by\n  match Nat.lt_or_ge x (y+z) with\n  | Or.inr q =>\n    have r : x - y \u2265 z := by simp only [Nat.le_sub_simp p, Nat.add_comm]; exact q\n    simp only [subNatNat.is_ofNat q, subNatNat.is_ofNat r]\n    simp only [Nat.sub_sub_left]\n  | Or.inl q =>\n    have r : x - y < z := by simp only [Nat.sub_lt_simp p]; exact q\n    simp only [subNatNat.is_negSucc q, subNatNat.is_negSucc r]\n    simp only [negSucc.injEq, Nat.sub_succ]\n    simp only [Nat.sub_sub_right p]\n    rw [Nat.add_comm z y]\n\nprivate\ntheorem subNatNat_sub {y z :Nat} (p : z \u2264 y) (x:Nat) : subNatNat x (y - z) = subNatNat (x + z) y := by\n  match Nat.lt_or_ge (x+z) y with\n  | Or.inr q =>\n    have r : y - z \u2264 x := by\n      simp only [Nat.sub_le_simp, Nat.add_comm z x]\n      exact q\n    simp only [subNatNat.is_ofNat q, subNatNat.is_ofNat r]\n    simp only [Nat.sub_sub_right p]\n  | Or.inl q =>\n    have r : Nat.succ x \u2264 y - z := by\n      simp only [Nat.le_sub_simp, p, Nat.succ_add]\n      exact q\n    simp only [subNatNat.is_negSucc q, subNatNat.is_negSucc r, Nat.sub_succ]\n    simp only [Nat.sub_sub_left, Nat.add_comm]\n\nprivate\ntheorem subNatNat_zero_implies_equal {x y :Nat} (q:Int.subNatNat x y = 0) : x = y := by\n  simp [Int.subNatNat] at q\n  have p : y - x = 0 := by\n    generalize g:y-x=z\n    cases z with\n    | zero => rfl\n    | succ z => simp [g] at q\n  simp only [OfNat.ofNat, p, ofNat.injEq] at q\n  revert y\n  induction x with\n  | zero =>\n    intros y p q\n    exact p.symm\n  | succ x ind =>\n    intros y\n    cases y with\n    | zero =>\n      intros p q\n      simp [Nat.sub_zero] at q\n    | succ y =>\n      simp [Nat.succ_sub_succ]\n      exact (@ind y)\n\nprivate\ntheorem subNatNat_eq_zero (x y :Nat) : (Int.subNatNat x y = 0) = (x = y) := by\n  apply propext\n  apply Iff.intro subNatNat_zero_implies_equal\n  intro eq\n  simp only [eq, subNatNat_self]\n\nprivate\ntheorem nonNeg_subNatNat (m n : Nat) : NonNeg (subNatNat m n) = (n <= m) := by\n  apply propext\n  apply Iff.intro\n  case a.mp =>\n    intro p\n    match Nat.lt_or_ge m n with\n    | Or.inr q =>\n      exact q\n    | Or.inl q =>\n      simp [subNatNat.is_negSucc q] at p\n      contradiction\n  case a.mpr =>\n    intro le\n    simp [subNatNat.is_ofNat le]\n    exact (NonNeg.mk _)\n\n\nend subNatNat\n\nsection Addition\n\nprivate theorem ofNat_add_ofNat (m n : Nat) : ofNat m + ofNat n = ofNat (m + n) := by rfl\n\nprivate theorem ofNat_add_negSucc (m n : Nat) : ofNat m + negSucc n = subNatNat m (Nat.succ n) := by rfl\n\nprivate theorem negSucc_add_ofNat (m n : Nat) : negSucc m + ofNat n = subNatNat n (Nat.succ m) := by rfl\n\nprivate theorem negSucc_add_negSucc (m n : Nat) : negSucc m + negSucc n = negSucc (Nat.succ (m + n)) := by rfl\n\n@[simp]\ntheorem zero_add (x : Int) : 0 + x = x :=\n  match x with\n  | ofNat n => congrArg ofNat (Nat.zero_add _)\n  | negSucc n => rfl\n\n@[simp]\ntheorem add_zero (x : Int) : x + 0 = x :=\n  match x with\n  | ofNat n => Eq.refl (ofNat n)\n  | negSucc n => Eq.refl (negSucc n)\n\ntheorem add_comm (x y : Int) : x + y = y + x := by\n  cases x <;> cases y <;> simp only\n    [ofNat_add_ofNat, ofNat_add_negSucc,\n     negSucc_add_ofNat, negSucc_add_negSucc,\n     Nat.add_comm]\n\nprivate\ntheorem ofNat_add_subNatNat (x y z:Nat)\n  : ofNat x + subNatNat y z = subNatNat (x + y) z := by\n    match Nat.lt_or_ge y z with\n    | Or.inl p =>\n      rw [subNatNat.is_negSucc p, ofNat_add_negSucc, Nat.succ_sub p, Nat.succ_sub_succ]\n      exact (subNatNat_sub (Nat.le_of_lt p) _)\n    | Or.inr p =>\n      have q : x + y \u2265 z := Nat.le_trans p (Nat.le_add_left y x)\n      rw [subNatNat.is_ofNat p, ofNat_add_ofNat]\n      rw [subNatNat.is_ofNat q, ofNat.injEq]\n      exact (Nat.add_sub_right p _)\n\nprivate\ntheorem subNatNat_add_ofNat (x y z:Nat) : subNatNat x y + ofNat z = subNatNat (x + z) y := by\n  simp only [add_comm, ofNat_add_subNatNat, Nat.add_comm]\n\nprivate\ntheorem negSucc_add_subNatNat (x y z:Nat) : negSucc x + subNatNat y z = subNatNat y (Nat.succ (x + z)) := by\n  match Nat.lt_or_ge y z with\n  | Or.inr p =>\n    rw [subNatNat.is_ofNat p, negSucc_add_ofNat]\n    simp only [subNatNat_sub_lhs p, Nat.add_succ, Nat.add_comm]\n  | Or.inl p =>\n    rw [subNatNat.is_negSucc p, negSucc_add_negSucc]\n    have r : y < x + z := Nat.le_trans p (Nat.le_add_left z x)\n    have q : y < Nat.succ (x + z) := Nat.le.step r\n    rw [subNatNat.is_negSucc q, negSucc.injEq]\n    rw [Nat.add_sub_right p]\n    rw [Nat.succ_sub r]\n\nprivate\ntheorem subNatNat_add_negSucc (x y z:Nat)\n  : subNatNat x y + negSucc z = subNatNat x (Nat.succ (y + z)) := by\n  simp only [add_comm, negSucc_add_subNatNat, Nat.add_comm]\n\nprivate theorem subNatNat_add_subNatNat (a b c d:Nat)\n  : subNatNat a b + subNatNat c d = subNatNat (a + c) (b + d) := by\n  match Nat.lt_or_ge a b with\n  | Or.inr a_ge_b =>\n    simp only [subNatNat.is_ofNat a_ge_b]\n    match Nat.lt_or_ge c d with\n    | Or.inr c_ge_d =>\n      have ge : a + c \u2265 b + d := Nat.add_le_add a_ge_b c_ge_d\n      rw [subNatNat.is_ofNat c_ge_d, subNatNat.is_ofNat ge]\n      rw [ofNat_add_ofNat, ofNat.injEq]\n      rw [Nat.add_sub_left a_ge_b]\n      rw [Nat.add_sub_right c_ge_d]\n      simp only [Nat.sub_sub_left, Nat.add_comm]\n    | Or.inl c_lt_d =>\n      simp only [subNatNat.is_negSucc c_lt_d]\n      simp only [ofNat_add_negSucc]\n      simp only [Nat.succ_sub c_lt_d, Nat.succ_sub_succ]\n      simp only [subNatNat_sub (Nat.le_of_lt c_lt_d)]\n      simp only [Nat.add_sub_left a_ge_b]\n      have ac_ge_b : a+c \u2265 b := Nat.le_trans a_ge_b (Nat.le_add_right a c)\n      simp only [subNatNat_sub_lhs ac_ge_b]\n  | Or.inl a_lt_b =>\n    simp only [subNatNat.is_negSucc a_lt_b]\n    match Nat.lt_or_ge c d with\n    | Or.inr c_ge_d =>\n      simp only [subNatNat.is_ofNat c_ge_d, negSucc_add_ofNat]\n      simp only [Nat.succ_sub a_lt_b, Nat.succ_sub_succ]\n      simp only [subNatNat_sub_lhs c_ge_d]\n      simp only [Nat.add_sub_right (Nat.le_of_lt a_lt_b)]\n      have db_ge_a : d + b >= a :=\n             Nat.le_trans (Nat.le_of_lt a_lt_b) (Nat.le_add_left b d)\n      simp only [subNatNat_sub db_ge_a]\n      simp only [Nat.add_comm]\n    | Or.inl c_lt_d =>\n      have lt : a + c < b + d := Nat.add_lt_add a_lt_b c_lt_d\n      simp only [subNatNat.is_negSucc c_lt_d, subNatNat.is_negSucc lt]\n      rw [negSucc_add_negSucc, negSucc.injEq]\n      simp only [Nat.add_sub_left a_lt_b]\n      simp only [Nat.add_sub_right c_lt_d]\n      simp only [Nat.sub_sub_left, Nat.succ_add, Nat.add_succ, Nat.add_comm c a]\n      rw [Nat.sub_succ, Nat.sub_succ]\n      have gt1 : Nat.pred (b + d - (a + c)) > 0 := by\n            apply Nat.lt_of_succ_le\n            simp only [Nat.succ_le_pred, Nat.succ_le_sub, Nat.succ_add, Nat.zero_add]\n            rw [(Nat.add_succ _ c).symm, (Nat.succ_add a _).symm]\n            exact Nat.add_le_add a_lt_b c_lt_d\n      simp only [Nat.succ_pred gt1]\n\ntheorem add_assoc (x y z : Int) : x + y + z = x + (y + z) := by\n  cases x <;> cases y <;> cases z <;>  simp only\n    [ofNat_add_ofNat, ofNat_add_negSucc, negSucc_add_ofNat, negSucc_add_negSucc,\n      ofNat_add_subNatNat, subNatNat_add_ofNat,\n      subNatNat_add_negSucc, negSucc_add_subNatNat,\n      Nat.succ_add, Nat.add_succ, Nat.add_assoc]\n\nend Addition\n\n-- Just desugar negOfNat into subNatNat\nsection negOfNat\n\nprivate\ntheorem negOfNat_is_subNatNat (x:Nat) : negOfNat x = subNatNat 0 x := by\n  cases x with\n  | zero => rfl\n  | succ x => rfl\n\nend negOfNat\n\nsection Negation\n\n@[simp]\ntheorem neg_zero : - (0:Int) = 0 := by rfl\n\nprivate\ntheorem neg_ofNat (n:Nat) : -ofNat n = subNatNat 0 n := negOfNat_is_subNatNat n\n\nprivate\ntheorem neg_negSucc (n:Nat) : -negSucc n = ofNat (n+1) := by rfl\n\nprivate\ntheorem neg_subNatNat (m n: Nat) : - (subNatNat m n) = subNatNat n m := by\n  match Nat.lt_or_ge m n with\n  | Or.inl p =>\n    have q : m \u2264 n := Nat.le_of_lt p\n    simp only [subNatNat.is_negSucc p, subNatNat.is_ofNat q, neg_negSucc]\n    simp only [Nat.add_sub_left p, Nat.succ_sub_succ]\n  | Or.inr p =>\n    simp only [subNatNat.is_ofNat p, neg_ofNat]\n    simp only [subNatNat_sub p, Nat.zero_add]\n\ntheorem neg_add (x y : Int) : -(x + y) = -x + -y := by\n  cases x <;> cases y <;> simp only\n         [ofNat_add_ofNat, ofNat_add_negSucc, negSucc_add_ofNat, negSucc_add_negSucc,\n          neg_ofNat, neg_negSucc,\n          subNatNat_add_subNatNat, subNatNat_add_ofNat, ofNat_add_subNatNat,\n          neg_subNatNat,\n          Nat.zero_add, Nat.add_zero, Nat.add_succ, Nat.succ_add]\n\nend Negation\n\nsection Subtraction\n\ntheorem sub_to_add_neg (x : Int) : x - y = x + -y := by rfl\n\ntheorem sub_self (x : Int) : x - x = 0 := by\n  simp only [sub_to_add_neg]\n  cases x with\n  | ofNat x =>\n    simp only [neg_ofNat, negOfNat_is_subNatNat, ofNat_add_subNatNat, Nat.add_zero,\n               subNatNat_self]\n  | negSucc x =>\n    simp only [neg_negSucc, negSucc_add_ofNat, Nat.add_succ, Nat.add_zero,\n               subNatNat_self]\n\ntheorem sub_eq_zero_implies_eq {x y : Int} (q : x - y = 0) : x = y := by\n  cases x with\n  | ofNat x =>\n    cases y with\n    | ofNat y =>\n      simp only [sub_to_add_neg, neg_ofNat, ofNat_add_subNatNat, Nat.add_zero, subNatNat_eq_zero] at q\n      simp only [q]\n    | negSucc y =>\n      simp only [sub_to_add_neg, neg_negSucc, ofNat_add_ofNat] at q\n      simp only [Nat.add_succ, OfNat.ofNat, ofNat.injEq] at q\n  | negSucc x =>\n    cases y with\n    | ofNat y =>\n      simp only [sub_to_add_neg, neg_ofNat, negSucc_add_subNatNat, subNatNat_eq_zero] at q\n    | negSucc y =>\n      simp only [sub_to_add_neg, neg_negSucc, negSucc_add_ofNat, succ_subNatNat_succ,\n                 subNatNat_eq_zero] at q\n      simp only [q]\n\nend Subtraction\n\nprotected theorem lt_or_ge (x y : Int) : x < y \u2228 x \u2265 y := by\n  have h : -1 = Int.negSucc 0 := rfl\n  have succ_le : \u2200(a b), (Nat.succ a \u2264 b) = (a < b) := by\n        intros a b\n        exact propext (Iff.intro id id)\n  simp only [LT.lt, Int.lt, LE.le, GE.ge, Int.le, sub_to_add_neg, neg_add, h]\n  cases x <;> cases y <;> simp only\n    [ neg_ofNat, neg_negSucc,\n      ofNat_add_ofNat, ofNat_add_negSucc, ofNat_add_subNatNat,\n      negSucc_add_ofNat, negSucc_add_subNatNat, subNatNat_add_negSucc,\n      NonNeg.mk,\n      succ_subNatNat_succ, subNatNat_zero,\n      Nat.add_zero, Nat.add_succ,\n      nonNeg_subNatNat, succ_le, Nat.lt_or_ge,\n      or_true, true_or\n    ]\n\nsection Multiplication\n\nprivate theorem ofNat_mul_ofNat (m n : Nat) : ofNat m * ofNat n = ofNat (m * n) := by rfl\n\nprivate theorem ofNat_mul_negSucc (m n : Nat) : ofNat m * negSucc n = subNatNat 0 (m * Nat.succ n) :=\n  negOfNat_is_subNatNat (m * Nat.succ n)\n\nprivate theorem negSucc_mul_ofNat (m n : Nat) : negSucc m * ofNat n = subNatNat 0 (Nat.succ m * n) :=\n  negOfNat_is_subNatNat (Nat.succ m * n)\n\nprivate theorem negSucc_mul_negSucc (m n : Nat) : negSucc m * negSucc n = ofNat (Nat.succ m * Nat.succ n) := by rfl\n\ntheorem zero_mul (x:Int) : 0 * x = 0 := by\n  simp only [OfNat.ofNat]\n  cases x <;> simp only [ofNat_mul_ofNat, ofNat_mul_negSucc, Nat.zero_mul]\n\ntheorem one_mul (x:Int) : 1 * x = x := by\n  simp only [OfNat.ofNat]\n  cases x <;> simp only [ofNat_mul_ofNat, ofNat_mul_negSucc, Nat.one_mul, zero_subNatNat_succ]\n\ntheorem mul_comm (x y : Int) : x * y = y * x := by\n  cases x <;> cases y <;> simp only\n    [ ofNat_mul_ofNat, ofNat_mul_negSucc, negSucc_mul_ofNat, negSucc_mul_negSucc,\n      Nat.mul_comm\n    ]\n\ntheorem mul_zero (x : Int) : x * 0 = 0 := by simp [mul_comm x 0, zero_mul]\n\ntheorem mul_one (x : Int) : x * 1 = x := by simp [mul_comm x 1, one_mul]\n\nprivate\ntheorem ofNat_mul_subNatNat (x y z : Nat) : ofNat x * subNatNat y z = subNatNat (x * y) (x * z) :=\n  match Nat.lt_or_ge y z with\n  | Or.inr p => by\n    have q : x*y \u2265 x*z := Nat.mul_le_mul_left x p\n    simp only [subNatNat.is_ofNat, p, q, ofNat_mul_ofNat, Nat.mul_sub ]\n  | Or.inl p =>\n    match Nat.eq_zero_or_pos x with\n    | Or.inl x_eq_zero => by\n      simp only [x_eq_zero, Nat.zero_mul]\n      exact zero_mul (subNatNat y z)\n    | Or.inr x_pos => by\n      have q : x*y < x*z := Nat.mul_lt_mul_of_pos_left p x_pos\n      simp only [subNatNat.is_negSucc p, subNatNat.is_negSucc q, ofNat_mul_negSucc]\n      have r : x * z \u2265 (x * y + x) := by\n        simp only [(Nat.mul_succ x y).symm]\n        exact Nat.mul_le_mul_left x p\n      simp only [\n        Nat.add_sub_left r,\n        Nat.mul_succ, Nat.mul_sub,  Nat.add_sub_add_self ]\n      rw [subNatNat_sub (Nat.le_of_lt q), Nat.zero_add, subNatNat.is_negSucc q]\n\nprivate\ntheorem negSucc_mul_subNatNat (x y z : Nat) : negSucc x * subNatNat y z = subNatNat (Nat.succ x * z) (Nat.succ x * y) :=\n  match Nat.lt_or_ge y z with\n  | Or.inr p => by\n    have q : Nat.succ x*y \u2265 Nat.succ x*z := Nat.mul_le_mul_left (Nat.succ x) p\n    simp only [subNatNat.is_ofNat, p, q]\n    simp only [negSucc_mul_ofNat, Nat.mul_sub]\n    simp only [subNatNat_sub q, Nat.zero_add]\n  | Or.inl p => by\n    have q : Nat.succ x*y < Nat.succ x*z := Nat.mul_lt_mul_of_pos_left p (Nat.zero_lt_succ x)\n    simp only [subNatNat.is_negSucc p, subNatNat.is_ofNat (Nat.le_of_lt q)]\n    simp only [negSucc_mul_negSucc, Nat.succ_sub p, Nat.succ_sub_succ]\n    simp only [Nat.mul_sub]\n\nprivate\ntheorem subNatNat_mul_ofNat (x y z : Nat) : subNatNat x y * ofNat z = subNatNat (x * z) (y * z) := by\n  simp [mul_comm, ofNat_mul_subNatNat, Nat.mul_comm]\n\nprivate\ntheorem subNatNat_mul_negSucc (x y z : Nat) : subNatNat x y * negSucc z = subNatNat (y * Nat.succ z) (x * Nat.succ z)  := by\n  simp [mul_comm, negSucc_mul_subNatNat, Nat.mul_comm]\n\ntheorem neg_one_mul (x:Int) : -1 * x = -x := by\n  simp only [OfNat.ofNat]\n  have h : Nat.succ 0 = 1 := rfl\n  cases x <;> simp only\n    [neg_ofNat, negSucc_mul_ofNat, negSucc_mul_negSucc, h, neg_negSucc,\n     subNatNat_mul_ofNat, subNatNat_mul_negSucc,\n     Nat.zero_mul, Nat.one_mul, subNatNat_zero\n     ]\n\ntheorem mul_assoc (x y z : Int) : x * y * z = x * (y * z) := by\n  cases x <;> cases y <;> cases z <;> simp only\n    [ ofNat_mul_ofNat, ofNat_mul_negSucc, negSucc_mul_ofNat, negSucc_mul_negSucc,\n      ofNat_mul_subNatNat, subNatNat_mul_ofNat,\n      negSucc_mul_subNatNat, subNatNat_mul_negSucc,\n      subNatNat_zero,\n      Nat.mul_assoc, Nat.mul_zero, Nat.zero_mul]\n\ntheorem add_mul (x y z : Int) : (x + y) * z = x * z + y * z := by\n  cases x <;> cases y <;> cases z <;> simp only\n    [ ofNat_add_ofNat, ofNat_mul_ofNat,\n      ofNat_add_negSucc, ofNat_mul_negSucc,\n      negSucc_add_ofNat, negSucc_mul_ofNat,\n      negSucc_add_negSucc, negSucc_mul_negSucc,\n      ofNat_add_subNatNat, subNatNat_add_ofNat, subNatNat_add_subNatNat,\n      subNatNat_mul_ofNat, subNatNat_mul_negSucc,\n      (Nat.add_mul _ _ _).symm,\n      Nat.succ_add, Nat.add_succ, Nat.zero_add, Nat.add_zero\n    ]\n\ntheorem mul_add  (x y z : Int) : x * (y + z) = x * y + x * z := by\n  cases x <;> cases y <;> cases z <;> simp only\n    [ ofNat_add_ofNat, ofNat_mul_ofNat,\n      ofNat_add_negSucc, ofNat_mul_negSucc,\n      negSucc_add_ofNat, negSucc_mul_ofNat,\n      negSucc_add_negSucc, negSucc_mul_negSucc,\n      ofNat_add_subNatNat, subNatNat_add_ofNat, subNatNat_add_subNatNat,\n      ofNat_mul_subNatNat, negSucc_mul_subNatNat,\n      (Nat.mul_add _ _ _).symm,\n      Nat.succ_add, Nat.add_succ, Nat.zero_add, Nat.add_zero\n    ]\n\ntheorem neg_mul (x y : Int) : -(x * y) = -x * y := by\n  cases x <;> cases y <;> simp only\n    [ neg_ofNat, neg_negSucc,\n      ofNat_mul_ofNat,\n      ofNat_mul_negSucc,\n      negSucc_mul_ofNat,\n      negSucc_mul_negSucc,\n      subNatNat_mul_ofNat,\n      subNatNat_mul_negSucc,\n      neg_subNatNat,\n      subNatNat_zero,\n      Nat.zero_mul\n    ]\n\ntheorem mul_neg (x y : Int) : x * -y = -x * y := by\n  cases x <;> cases y <;> simp only\n    [ neg_ofNat, neg_negSucc,\n      ofNat_mul_ofNat,\n      negSucc_mul_ofNat,\n      ofNat_mul_negSucc,\n      ofNat_mul_subNatNat,\n      subNatNat_mul_ofNat,\n      subNatNat_mul_negSucc,\n      negSucc_mul_subNatNat,\n      subNatNat_zero,\n      Nat.zero_mul, Nat.mul_zero, Nat.add_succ, Nat.add_zero\n    ]\n\nend Multiplication\n\nsection NeZero\n-- Special cases\n\ntheorem neg_ne_zero {x:Int} : x \u2260 0 \u2192 -x \u2260 0 := by\n  intro p eq\n  apply p; clear p\n  revert eq\n  match x with\n  | ofNat 0 =>\n    simp\n  | ofNat (Nat.succ x) =>\n    simp only [neg_ofNat]\n    intro p\n    simp only [subNatNat_eq_zero] at p\n  | negSucc x =>\n    intro eq\n    simp [OfNat.ofNat, neg_negSucc, Nat.add_succ, Nat.add_zero] at eq\n\ntheorem mul_ne_zero {x y:Int} : x \u2260 0 \u2192 y \u2260 0 \u2192 x * y \u2260 0 :=\n  have h : \u2200(n:Nat), ofNat (Nat.succ n) \u2260 0 := by\n    intro n\n    simp [OfNat.ofNat]\n  match x, y with\n  | ofNat 0, y  => by\n    intro ne\n    contradiction\n  | _, 0 => by\n    intro _ ne\n    simp only [] at ne\n  | ofNat (Nat.succ x), ofNat (Nat.succ y) => by\n    intros p q\n    simp only [ofNat_mul_ofNat, Nat.succ_mul, Nat.add_succ, OfNat.ofNat, ne_eq, ofNat.injEq]\n  | ofNat (Nat.succ x), negSucc y => by\n    intros p q eq\n    simp only [ofNat_mul_negSucc, negOfNat_is_subNatNat] at eq\n    simp only [subNatNat_eq_zero] at eq\n    simp only [Nat.succ_mul, Nat.add_succ, OfNat.ofNat] at eq\n  | negSucc x, ofNat (Nat.succ y) => by\n    intros p q eq\n    simp only [negSucc_mul_ofNat, negOfNat_is_subNatNat, subNatNat_eq_zero] at eq\n    simp only [Nat.succ_mul, Nat.add_succ, OfNat.ofNat] at eq\n  | negSucc x, negSucc y => by\n    intros p q\n    simp only [negSucc_mul_negSucc, Nat.succ_mul, Nat.add_succ, OfNat.ofNat, ne_eq, ofNat.injEq]\n\nend NeZero\n\nsection Comparison\n\ntheorem nonNeg_of_nat_le {x y : Nat} (p : x \u2264 y)\n  : NonNeg (OfNat.ofNat y - OfNat.ofNat x) := by\n  simp [OfNat.ofNat, Int.sub_to_add_neg]\n  simp only [neg_ofNat]\n  simp only [ofNat_add_subNatNat, Nat.add_zero]\n  simp only [subNatNat.is_ofNat p]\n  apply NonNeg.mk\n\nend Comparison\n\nend Int", "meta": {"author": "joehendrix", "repo": "lean-arith-solver", "sha": "95041be7b67fa1525644ad60896ae71881efdd29", "save_path": "github-repos/lean/joehendrix-lean-arith-solver", "path": "github-repos/lean/joehendrix-lean-arith-solver/lean-arith-solver-95041be7b67fa1525644ad60896ae71881efdd29/lib/ClausalExtraction/ArithTheory/Int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7157956018333934}}
{"text": "import tactic\n\n/--\n`injective` Basic definition of injectivity.\n-/\ndef injective {X Y} (f : X \u2192 Y) := \u2200 x\u2081 x\u2082, f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082\n\n/--\n`comp_inj_is_inj` Demonstrates the composition of injective functions is injective.\n-/\ntheorem comp_inj_is_inj \n{X Y Z} (f : X \u2192 Y) (g : Y \u2192 Z)\n(p1 : injective f) \n(p2 : injective g) \n:  injective (g \u2218 f)\n:= \nbegin\n  introv x p3,\n  change g (f x) = g (f x\u2082) at p3,\n  apply p1,\n  apply p2, \n  apply p3,\nend\n\n/--\n`succ_greater_than_nat` Simple statement that n + 1 > n.\n-/\nlemma succ_greater_than_nat \n(n : \u2115) \n: nat.succ n > n\n:= \nbegin\n  rw nat.succ_eq_add_one,\n  linarith\nend\n\n\nlemma ge_zero_witness_k\n(n k : \u2115 )\n(p : k \u2265 0)\n(p2 : n > k)\n: n > 0\n:=\nbegin\nexact lt_of_le_of_lt p p2,\nend\n\n\nlemma ge_zero\n(k : \u2115)\n: k \u2265 0\n:= begin\nexact bot_le,\nend\n\nlemma minus_one_both_sides_eq\n{n m k : \u2115 }\n(p : k \u2265 0)\n(p2 : m > k)\n(p3 : n > k)\n(p4: m - 1 = n - 1)\n: m = n \n:=\nbegin\nhave m_ge_zero  := (ge_zero_witness_k m k p p2),\nhave n_ge_zero := (ge_zero_witness_k n k p p3), \nexact nat.pred_inj m_ge_zero n_ge_zero p4,\nend\n\n\n\nlemma my_le_trans\n(j k m : \u2115)\n(p1: k < m)\n(p2: j \u2264 k)\n(p3 m > 0)\n: j < m - 1\n:=\nbegin\n  intros,\n  \n  /-\n  induction j with d hd, \n  {\n    induction m with dm hdm,\n    {exact lt_of_le_of_lt p2 p1},\n    {\n      \n    }\n  },\n  {\n    induction m with dm hdm,\n    {linarith,},\n    {\n      \n    }\n  },\n  -/\n  sorry,\nend\n\n\n\nlemma downward_ineq\n(j m : \u2115)\n(p: j < m)\n(p2: 0 < j)\n: j - 1 < m - 1\n:= \nbegin\n  intros,\n  exact nat.sub_mono_left_strict p2 p,\nend\n\n\n/--\nType of pairs (k,p) where k\nis a natural number and p is a witness to the proof that k < n.\n-/\ndef finite_subset (n : \u2115) := { k // k < n }\n\n/--\nEvery pair that lives in finite_subest m lives in finite_subset n\nwhere m < n\n-/\ndef lift_finite \n(m n : \u2115) \n(p : m < n) \n: finite_subset m \u2192 finite_subset n\n:= \n  \u03bb k, \u27e8k.1, lt.trans k.2 p\u27e9\n\n\n/--\n`lift_one` Application of lift_finite from m to m + 1\n-/\ndef lift_one\n(m : \u2115)\n: finite_subset m \u2192 finite_subset (m + 1)\n:= \n  (lift_finite m (m+1) (succ_greater_than_nat m))\n\n\n/--\n`lift_one_fst` Establishes that lifting preserves the first half of the pair.\n-/\nlemma lift_one_fst {m} (j : finite_subset m) : (lift_one m j).1 = j.1 \n:=\nbegin\n  refl,\nend\n\n/--\n`ext_iff` Extensionality theorem for finite subsets as pairs.\n-/\nlemma ext_iff \n(n : \u2115) \n(a b : finite_subset n) \n: a = b \u2194 a.1 = b.1 \n:=\nbegin\n  cases a,\n  cases b,\n  split,\n  { intro h, rw h},\n  { intro h, cases h, refl,}\nend\n\n\n/--\n`lift_finite_injective` Demonstrates the lifting function is injective.\n-/\ntheorem lift_finite_injective \n(m n : \u2115) \n(p : m < n) \n: injective (lift_finite m n p) \n:=\nbegin\n  intros x\u2081 x\u2082 h,\n  rw ext_iff at \u22a2 h,\n  exact h\nend\n\n\n/--\n`lift_one_injective` Direct lemma of `lift_finite_injective`\n-/\nlemma lift_one_injective (m : \u2115) \n: injective (lift_one m) \n:= \nbegin\n  apply lift_finite_injective m (m + 1) (succ_greater_than_nat m),\nend\n\n\n\n/--\nSmall proof of the `j.1 < m - 1` in the `then` case below.\n-/\nlemma relabel_inequality_lower_case\n(m k : \u2115) \n(h : k < m) \n(j : finite_subset m) \n(p : j.1 \u2264 k)\n: j.1 < m - 1\n:= \nbegin\nlet witness := (ge_zero_witness_k m k (ge_zero k) h),\nlet reason := my_le_trans j.1 k m h p m m witness, \napply reason, \napply witness, \nend\n\n/--\n`relabel` Given an element `\u27e8 k , k < m \u27e9` that is missing from the a collection of\n`finite_subset m`, this function can 'squash' the collection into\n`finite_subset (m - 1)`.\n-/\ndef relabel \n(m k : \u2115) \n(h : k < m) \n(j : finite_subset m) \n: finite_subset (m - 1) \n:=\n  if H : j.1 \u2264 k \n  then \u27e8j.1, relabel_inequality_lower_case m k h j H\u27e9 \n  else \u27e8j.1 - 1, downward_ineq j.1 m j.2 sorry\u27e9\n\n\n\n/--\n`miss_proof` Proof that `f : [m + 2] -> [m + 1]` restricted \nto `[m + 1] = {0, 1, ..., m}` does not hit `f (m + 1)`\n-/\nlemma miss_proof\n(m : \u2115) \n(f : finite_subset (m + 2) \u2192 finite_subset (m + 1))\n(inj : injective f)\n(pf: m + 1 < m + 2)\n: \u2200 j : finite_subset (m + 1), (f \u2218 lift_one (m + 1)) j \u2260 f \u27e8m + 1,  pf\u27e9\n:= \nbegin\n  introv p,\n  change f (lift_one (m+1) j) = f \u27e8m + 1,  pf\u27e9 at p,\n  let p2 := inj (lift_one (m+1) j) \u27e8m + 1,  pf\u27e9,\n  let p3 := p2 p,\n  rw ext_iff at p3,\n  rw lift_one_fst at p3,\n  let p4 := j.2,\n  linarith,\nend\n\n/--\n`relabel_behavior` Given `m k : \u2115`, `h : k < m`, `x y : finite_subset m`,\nand `(relabel m k h) x = (relabel m k h) y`, the `if-then-else` structure\nof `relabel` yields that either the values of `x, y` must either be less than \nor equal to `k` or vice versa \n-/\nlemma relabel_behavior \n(m k : \u2115) \n(h : k < m) \n(x y : finite_subset m) \n(hxy : relabel m k h x = relabel m k h y) \n: (x.1 \u2264 k \u2227 y.1 \u2264 k) \u2228 (x.1 \u2265 k \u2227 y.1 \u2265 k) \n:=\nbegin\n  unfold relabel at hxy,\n  split_ifs at hxy with hxk hyk hyk,\n  { \n    left; split; assumption \n  },\n  { right; split,\n    { rw subtype.mk_eq_mk at hxy,    \n      cases lt_or_eq_of_le hxk with hxlk hxek,\n      { \n        rw hxy at hxlk, \n        exact absurd (nat.le_of_pred_lt hxlk) hyk,\n      },\n\n      { \n        exact ge_of_eq hxek \n      }, \n    },\n\n    { \n      exact le_of_not_ge hyk \n    },\n  },\n  { right; split,\n    { \n      exact le_of_not_ge hxk \n    },\n\n    { rw subtype.mk_eq_mk at hxy,\n      cases lt_or_eq_of_le hyk with hylk hyek,\n      { \n        rw \u2190 hxy at hylk, exact absurd (nat.le_of_pred_lt hylk) hxk \n      },\n      { exact ge_of_eq hyek \n      }, \n    },\n  },\n\n  { \n    right; split; apply le_of_not_ge; assumption \n  },\n\n\nend\n\n\n/--\n`apply_relabel_lt` Lemma that describes the behavior of \n`relabel m k h` when the argument is less than `k`. \n-/\nlemma apply_relabel_lt \n(m k : \u2115) \n(hkm : k < m) \n(z : finite_subset m)  \n(h2 : z.1 \u2264 k)\n: (relabel m k hkm z).1 = z.1 :=\nbegin\n  unfold relabel, \n  rw dif_pos h2,\nend\n\n\n/--\n`apply_relabel_lt` Lemma that describes the behavior of \n`relabel m k h` when the argument is greater than `k`. \n-/\nlemma apply_relabel_gt \n(m k : \u2115) \n(hkm : k < m) \n(z : finite_subset m) \n(h2 : k < z.1)\n: (relabel m k hkm z).1 = z.1 - 1\n:= \nbegin\n  unfold relabel,\n  rw dif_neg (not_le_of_lt h2),\nend\n\n/--\n`relabel_inj` This formalizes the notion that when `f` is injective and misses `k` \nin the codomain, then when we relabel to bring `m` to `m - 1`, \ncomposition is in fact injective.\n-/\nlemma relabel_inj (m k : \u2115) (hkm : k < m + 1) \n(f: finite_subset (m + 2) \u2192 finite_subset (m + 1)) \n(inj : injective f)\n(pf : (f \u27e8 m + 1, succ_greater_than_nat (m + 1)\u27e9 ).1 < m + 1) \n(miss : \u2200 j : finite_subset (m + 1), (f \u2218 lift_one (m + 1)) j \u2260 f \u27e8m + 1,  succ_greater_than_nat (m + 1)\u27e9 ) \n: injective ((relabel (m + 1) (f \u27e8m + 1, succ_greater_than_nat (m + 1)\u27e9).1 pf) \u2218 f \u2218 lift_one (m + 1)) \n:=\nbegin\n  intros x y h,\n  change (relabel (m + 1) (f \u27e8 m + 1, succ_greater_than_nat (m + 1)\u27e9 ).1 pf (f (lift_one (m + 1) x))) = (relabel (m + 1) (f \u27e8 m + 1, succ_greater_than_nat (m + 1)\u27e9 ).1 pf (f (lift_one (m + 1) y))) at h,\n  rcases relabel_behavior _ _ _ _ _ h with \u27e8h1, h2\u27e9 | \u27e8h1, h2\u27e9; unfold relabel at h,\n  { \n    rw [dif_pos h1, dif_pos h2, subtype.mk_eq_mk] at h, \n    rw \u2190 subtype.ext at h,\n\n    let comp_inj := comp_inj_is_inj (lift_one (m + 1)) f (lift_one_injective (m + 1)) inj,\n    change (f \u2218 lift_one (m + 1)) x = (f \u2218 lift_one (m + 1)) y at h,\n    apply comp_inj, \n    apply h,  \n  },\n\n  {\n    have m_x := (miss x),\n    replace m_x := mt subtype.eq m_x,\n    have m_y := (miss y),\n    replace m_y := mt subtype.eq m_y,\n\n    have h1_strict := lt_of_le_of_ne h1 (ne.symm m_x),\n    have h2_strict := lt_of_le_of_ne h2 (ne.symm m_y),\n\n    rw dif_neg (not_le.mpr h1_strict) at h,\n    rw dif_neg (not_le.mpr h2_strict) at h,\n\n    let comp_inj := comp_inj_is_inj (lift_one (m + 1)) f (lift_one_injective (m + 1)) inj,\n\n    rw ext_iff at h, \n\n    let k_ge_zero := ge_zero (f \u27e8 m + 1, succ_greater_than_nat (m + 1)\u27e9).val,\n    let h_final := minus_one_both_sides_eq k_ge_zero h1_strict h2_strict h,\n    rw \u2190 ext_iff at h_final, \n    apply comp_inj,\n    apply h_final,\n  },\n\nend\n\n\n\n\n\n\n/--\n`pigeonhole_principle` The pigeonhole principle, which states\nthat among `n` pigeons, there must be at least `n` cages \nfor the pigeons to reside in order for every pigeon to have its \nown unique page.  Stated more formally, the pigeonhole principle\nasserts that there exists no injective function from any finite set\nof `n` elements to any set with fewer than `n` elements.\n-/\ntheorem pigeonhole_principle\n(n m : \u2115)\n(f : finite_subset n \u2192 finite_subset m)\n: (n > m) \u2192 \u00ac(injective f)\n:= \nbegin\n\n  intros n_gt_m f_injective,\n  induction n with d hd,\n  { linarith, /- case d = 0 -/ },\n\n\n  let g := f \u2218 (lift_one d),\n  let hd' := hd g,\n\n  rcases lt_or_eq_of_le (nat.lt_succ_iff.1 n_gt_m) with h | rfl,\n\n  {   /- case where d > m -/\n      /- prove injective g -/ \n    apply hd' h, \n    let g_injective := comp_inj_is_inj (lift_one d) f (lift_one_injective d) f_injective,\n    exact g_injective,\n  },\n\n  {   /- case where d = m -/\n      /- prove f : finite_subset (nat.succ m) \u2192 finite_subset m is not injective -/ \n\n    induction m with l hl,\n    \n    {\n      let e:= f \u27e80,_ \u27e9,\n      let e2 := e.2,\n      linarith,\n      exact n_gt_m,\n    },\n\n    let k := f \u27e8l + 1, succ_greater_than_nat (l + 1)\u27e9, \n    let violator := f \u2218 (lift_one (l + 1)),\n    let restriction := (relabel (l + 1) k.1 k.2) \u2218 violator,\n    let violator_is_inj := comp_inj_is_inj (lift_one (l + 1)) f (lift_one_injective (l + 1)) f_injective,\n    let miss := miss_proof l f f_injective (succ_greater_than_nat (l + 1)),\n    let res_is_inj := relabel_inj l k.1 k.2 f f_injective k.2 miss,\n\n    refine hl _ _ _ _ ,\n    {\n      intros,\n      linarith,\n    },\n    {\n      exact restriction,\n    },\n    {\n      exact succ_greater_than_nat _,\n    },\n    {\n      exact res_is_inj,\n    },\n  }\nend", "meta": {"author": "AlexKontorovich", "repo": "Spring2020Math492", "sha": "659108c5d864ff5c75b9b3b13b847aa5cff4348a", "save_path": "github-repos/lean/AlexKontorovich-Spring2020Math492", "path": "github-repos/lean/AlexKontorovich-Spring2020Math492/Spring2020Math492-659108c5d864ff5c75b9b3b13b847aa5cff4348a/pigeonhole_final.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7157793139476037}}
{"text": "import incidence_world.level06 --hide\nopen IncidencePlane --hide\n\n/- Axiom :\ncollinear_of_between : (A * B * C) \u2192 \u2203 \u2113 : Line \u03a9, A \u2208 \u2113 \u2227 B \u2208 \u2113 \u2227 C \u2208 \u2113\n-/\n\n/- Axiom :\nbetween_of_collinear (h: \u2203 (\u2113 : Line \u03a9), A \u2208 \u2113 \u2227 B \u2208 \u2113 \u2227 C \u2208 \u2113) : xor3 (A * B * C) ( B * A * C ) (A * C * B)\n-/\n\n/-\n# Betweenness World\n\n## Level 1: The axioms of order\n\nAlso called the axioms of betweenness, the axioms of order were formalized by David Hilbert (1862-1943 AD) on the occasion of studying the Euclid's `Elements`.\nWhen it comes to them, there are up to four axioms of order. Their learning involves the definition of **segment**, **betweenness**, **line separation** and\n**plane separation**, among others. In written mathematics, the notion of **betweenness** is represented by the **`*`** symbol. Now, let's take a look at the axioms of order.\n\n**B.1)** If A \u2217 B \u2217 C, then A, B, C are three distinct points all lying on the same line, and C \u2217 B \u2217 A.\n\n**B.2)** Given two distinct collinear points A and B, there is a third point C such that A * B * C.\n\n**B.3)** Given 3 distinct collinear points A B C, exactly one of them is between the other two. \n\n**B.4)** [This axiom will be learned in the following world.]\n\nIn Level 5 of Betweenness World, we will learn the definition of **segment**, which can be inferred from the first three axioms of order. \n\n## The axioms of order in Lean\n\nTo solve the levels of this world, we may need to use the first three axioms of order. Because of this reason, they are presented right below in Lean format. \n\nThe first axiom of order is divided into three statements: \n\n* `between_symmetric {A B C : \u03a9} : (A * B * C) \u2194 (C * B * A)`\n\n* `different_of_between {A B C : \u03a9} : (A * B * C) \u2192 (A \u2260 B \u2227 A \u2260 C \u2227 B \u2260 C)`\n\n* `collinear_of_between {A B C : \u03a9} : (A * B * C) \u2192 \u2203 \u2113 : Line \u03a9, A \u2208 \u2113 \u2227 B \u2208 \u2113 \u2227 C \u2208 \u2113`\n\nThe second axiom of order is represented as follows:\n\n* `point_on_ray {A B : \u03a9} (h: A \u2260 B) : \u2203 (C : \u03a9), A * B * C`\n\nTo finish with, here it comes the third axiom of order in Lean: \n\n* `between_of_collinear {A B C : \u03a9} (h: \u2203(\u2113 : Line \u03a9), A \u2208 \u2113 \u2227 B \u2208 \u2113 \u2227 C \u2208 \u2113) : xor3 (A * B * C) ( B * A * C ) (A * C * B)`\n\nRegarding this last axiom of order, you may be wondering what **xor3** means. This is a logic proposition that is defined as follows: \n\n* `xor3 (p q r : Prop) : Prop := (p \u2227 \u00ac q \u2227 \u00ac r) \u2228 (\u00ac p \u2227 q \u2227 \u00ac r) \u2228 (\u00ac p \u2227 \u00ac q \u2227 r)`\n\n[**Rule of thumb:** Whenever you see `xor3` in Lean, use the `unfold` tactic. In this way, it will be easier to understand what it means. If it is \nlocated at the hypothesis `h2`, for example, then `unfold xor3 at h2,` will make progress. If it is located at the goal, then `unfold xor3,` will be enough \nto rewrite the goal.]\n\n## Let's solve this level! \n\nTo solve this level, you will need to use two axioms of order. Because of this reason, two theorem statements have been added to the list. Display the\nbox called \"Betweenness World\" to take a look at them. Try to think of a mathematical proof in paper before typing your solution in Lean. In case you \nget stuck, click right below for a hint.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nYou can assume that exactly one point is between the other two by typing `have h2 : xor3 (A * B * C) ( B * A * C ) (A * C * B),`. Then, use the theorem\nstatements commented above to prove that `h2` is true. After that, remember the **rule of thumb** of this level. To finish with, the `tauto` tactic may \nfinish the proof. In case you want to see how to avoid the `tauto` tactic, click on \"View source\" (located on the top right\ncorner of the game screen).\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B C P Q R : \u03a9} --hide\nvariables {\u2113 r s t : Line \u03a9} --hide\n\n\n/- Lemma :\nGiven three distinct collinear points A, B and C, if B lies between A and C, then A does not lie between B and C.\n-/\nlemma not_between_of_between : (A * B * C) \u2192 \u00ac (B * A * C) :=\nbegin\n\n  intro h,\n  have h2 : xor3 (A * B * C) ( B * A * C ) (A * C * B),\n  {\n    apply between_of_collinear,\n    exact collinear_of_between h,\n  },\n  unfold xor3 at h2,\n  cases h2 with hA hB,\n  {\n    exact hA.2.1,\n  },\n  cases hB with hB1 hB2,\n  {\n  exfalso,\n  exact hB1.1 h,\n  },\n  exact hB2.2.1,\n  \nend\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/betweenness_world/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7157296919914288}}
{"text": "import .square_root\n\n-- Checked over by:\n-- Dan\n-- Hans\n\n/-\nThe goal of this file is to show that (T\u2020 T), the Gram operator of T, has a square root:\n-/\n\n\nvariables {n : \u2115} (T : L\u2102^n)\n\nopen_locale big_operators complex_conjugate matrix\n\nlocalized \"postfix `\u2020`:1000 := linear_map.adjoint\" in src\nnamespace inner_product_space\n\n/-\nThe Gram operator is self-adjoint\n-/\nlemma gram_sa :\n  inner_product_space.is_self_adjoint (T\u2020 * T) :=\nbegin\n  intros x y,\n  rw [\u2190 linear_map.adjoint_inner_right, mul_adjoint, linear_map.adjoint_adjoint],\nend\n\n/-\nThe Gram operator is positive\n-/\nlemma gram_pos :\n  is_positive (T\u2020 * T) :=\nbegin\n  intro x,\n  rw [linear_map.mul_apply, linear_map.adjoint_inner_left, inner_self_eq_norm_sq_to_K],\n  norm_cast,\n  exact \u27e8 sq_nonneg (\u2225 T x \u2225), rfl \u27e9,\nend\n\n/-\nThe Gram operator has a square root\n-/\nlemma sqrt_gram_exists :\n  \u2203 (R : L\u2102^n), (R^2 = T\u2020 * T) \u2227 (inner_product_space.is_self_adjoint R) \u2227 (is_positive R) := \n    sqrt_exists (gram_sa _) (gram_pos _)\n  \nend inner_product_space", "meta": {"author": "hparshall", "repo": "lean-matrix-analysis", "sha": "cc1b9949065257b6c19f047a5a996bfac29f178e", "save_path": "github-repos/lean/hparshall-lean-matrix-analysis", "path": "github-repos/lean/hparshall-lean-matrix-analysis/lean-matrix-analysis-cc1b9949065257b6c19f047a5a996bfac29f178e/src/gram_sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7157296852330746}}
{"text": "import kb_real_defs --hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 8\n-/\n\n\n/- \nThis is a very basic example of working with intervals of real numbers in Lean.\nAn interval `[a, b]` that is closed at both endpoints $a$ and $b$ can be \nconstructed using `set.Icc a b`. For an open-closed interval `(a, b]`,\nthe notation\nis `set.Ioc a b`, etc. The usual closed-interval notation, using square\nbrackets, is used here as a wrapper around these definitions. We have\nthe following lemma:\n\n\n\n```\nmem_Icc_iff : x \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b\n```\n-/\n\n/- Axiom : mem_Icc_iff :\nx \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b\n-/\n\n/-\nAfter rewriting it, the `split` tactic will isolate the two conditions for \nmembership. Each inequality goals can be solved with the `norm_num` tactic,\nwhich closes goals which are equalities or inequalities between explicit\nreal numbers.\n-/\n\n/- Pro tip : semicolons\nIf instead of a comma, you end a line with a semicolon, then\nLean will apply the next tactic to all the goals created by the\nprevious tactic, rather than just the top one.\n-/\n\n/- Pro tip : definitional equality\n`mem_Icc_iff` is true by definition, so you don't actually\nhave to even rewrite it.\n-/\n\nnotation `[` a `,` b `]`  := set.Icc a b\n\n/- Lemma : no-side-bar\n$2 \u2208 [0,5]$\n-/\nexample : (2 : \u211d) \u2208 [(0 : \u211d), 5] := \nbegin\n    rw mem_Icc_iff,\n    split;\n    norm_num,\nend\n\n\n\n/-\nrw mem_Icc_iff,\n    split;\n    norm_num,\n-/", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/sets/sets_level08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7156988228520581}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world2.level6 -- hide\nnamespace mynat -- hide\n\n/- Axiom : succ_inj {a b : mynat} :\n  succ(a) = succ(b) \u2192 a = b\n-/\n\n/-\n\n# Advanced Addition World\n\n## Level 1: `succ_inj`. A function.\n\nPeano's original collection of axioms for the natural numbers contained two further\nassumptions, which have not yet been mentioned in the game:\n\n```\nsucc_inj {a b : mynat} :\n  succ(a) = succ(b) \u2192 a = b\n\nzero_ne_succ (a : mynat) :\n  zero \u2260 succ(a)\n ```\n\nThe reason they have not been used yet is that they are both implications,\nthat is,\nof the form $P\\implies Q$. This is clear for `succ_inj a b`, which\nsays that for all $a$ and $b$ we have $succ(a)=succ(b)\\implies a=b$.\nFor `zero_ne_succ` the trick is that $X\\ne Y$ is *defined to mean*\n$X = Y\\implies{\\tt false}$. If you have played through Proposition world,\nyou now have the required Lean skills (i.e., you know the required\ntactics) to work with these implications.\nLet's finally learn how to use `succ_inj`. You should know a couple\nof ways to prove the below -- one directly using an `exact`,\nand one which uses an `apply` first. But either way you'll need to use `succ_inj`.\n-/\n\n/- Theorem : no-side-bar\nFor all naturals $a$ and $b$, if we assume $succ(a)=succ(b)$, then we can\ndeduce $a=b$. \n-/\ntheorem succ_inj' {a b : mynat} (hs : succ(a) = succ(b)) :  a = b := \nbegin [nat_num_game]\n    exact succ_inj(hs),\n\n\n\nend\n\n/-\n## Important thing.\n\nYou can rewrite proofs of *equalities*. If `h : A = B` then `rw h` changes `A`s to `B`s.\nBut you *cannot rewrite proofs of implications*. `rw succ_inj` will *never work*\nbecause `succ_inj` isn't of the form $A = B$, it's of the form $A\\implies B$. This is one\nof the most common mistakes I see from beginners. $\\implies$ and $=$ are *two different things*\nand you need to be clear about which one you are using.\n-/\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world8/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7156988228520581}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport tactic\n\n/-!\n# Conjuntos\n-/\n\n/- Definimos un tipo `\u03a9` y tres conjuntos `X`, `Y`, `Z` cuyos elementos son de tipo `\u03a9`.\n  Para nuestro modelo mental, podemos pensar que estamos definiendo un conjunto `\u03a9` y tres \n  subconjuntos `X`, `Y`, `Z` del mismo.\n  Definimos tambi\u00e9n elementos `a, b, c, x, y, z` de `\u03a9`.\n -/\nvariables (\u03a9 : Type) (X Y Z : set \u03a9) (a b c x y z : \u03a9)\n\n-- Abrimos un `namespace` para evitar conflictos con los nombres.\nnamespace conjuntos\n\n/-!\n\n# Subconjuntos\n\nEl s\u00edmbolo `\u2286` se escribe mediante `\\sub` o `\\ss`\n-/\n\n-- `X \u2286 Y` significa `\u2200 a, a \u2208 X \u2192 a \u2208 Y`, por definici\u00f3n.\n\nlemma subset_def : X \u2286 Y \u2194 \u2200 a, a \u2208 X \u2192 a \u2208 Y :=\nbegin\n  refl -- por definici\u00f3n\nend\n\nlemma subset_refl : X \u2286 X :=\nbegin\n  refl,\nend\n\n/- En este lema, tras empezar con `rw subset_def at *`, la hip\u00f3tesis `hYZ` se transforma en\n`hYZ : \u2200 (a : \u03a9), a \u2208 Y \u2192 a \u2208 Z` (y similarmente para `hXY`).\nComo `hYZ` es una implicaci\u00f3n, una vez reducimos la meta a `a \u2208 Z`, podemos avanzar en la \ndemostraci\u00f3n utilizando `apply hYZ`.\nFrecuentemente, tambi\u00e9n es \u00fatil pensar en `hYZ` como una funci\u00f3n, que dados un t\u00e9rmino `a` de\ntipo `\u03a9` y una demostraci\u00f3n `haY` de que `a \u2208 Y`, devuelve una demostraci\u00f3n `haZ` de `a \u2208 Z`.\n-/\nlemma subset_trans (hXY : X \u2286 Y) (hYZ : Y \u2286 Z) : X \u2286 Z :=\nbegin\n  rw subset_def at *,\n  intros a ha,\n  apply hYZ,\n  exact hXY a ha,\nend\n\n/-!\n# Igualdad de conjuntos\nDos conjuntos son iguales si y s\u00f3lo si tienen los mismos elementos.\nEn Lean, el nombre de este lema es `set.ext_iff`.\n-/\n\nexample : X = Y \u2194 (\u2200 a, a \u2208 X \u2194 a \u2208 Y) :=\nbegin\n  exact set.ext_iff\nend\n\n/- Cuando queremos reducir la meta `\u22a2 X = Y` a demostrar `a \u2208 X \u2194 a \u2208 Y` para `a : \u03a9`\n  arbitrario, utilizamos la t\u00e1ctica `ext`. -/\n\nlemma subset.antisymm (hXY : X \u2286 Y) (hYX : Y \u2286 X) : X = Y :=\nbegin\n  ext a,\n  split,\n  { apply hXY },\n  { apply hYX }\nend\n\n/-!\n\n### Uniones e intersecciones\n\nNotaci\u00f3n: `\\cup` o `\\un` para obtener `\u222a`, y `\\cap` o `\\i` para `\u2229`\n\n-/\n\nlemma union_def : a \u2208 X \u222a Y \u2194 a \u2208 X \u2228 a \u2208 Y :=\nbegin\n  refl,\nend\n\nlemma inter_def : a \u2208 X \u2229 Y \u2194 a \u2208 X \u2227 a \u2208 Y :=\nbegin\n  refl,\nend\n\n/- Uniones. -/\n\nlemma union_self : X \u222a X = X :=\nbegin\n  ext x,\n  rw union_def,\n  /- Podr\u00edamos terminar con `rw or_self`, pero para practicar con otras pr\u00e1cticas, hagamos : -/\n  split; -- Al terminar con `;`, la siguiente t\u00e1ctica se aplica a todas las metas.\n  intro hX,\n  { cases hX with hX hX;\n    exact hX, },\n  { left,\n    exact hX }\nend\n\nlemma subset_union_left : X \u2286 X \u222a Y :=\nbegin\n  intros x hx,\n  rw union_def,\n  left,\n  exact hx,\nend\n\nlemma subset_union_right : Y \u2286 X \u222a Y :=\nbegin\n  intros y hy,\n  right,\n  assumption,\nend\n\nlemma union_subset_iff : X \u222a Y \u2286 Z \u2194 X \u2286 Z \u2227 Y \u2286 Z :=\nbegin\n  split,\n  { intro h,\n    split,\n    { intros x hx,\n      apply h,\n      exact subset_union_left \u03a9 X Y hx },\n    { intros y hy,\n      apply h,\n      right,\n      assumption }},\n  { rintros \u27e8hXZ, hYZ\u27e9 a (haX | haY),\n    { exact hXZ haX },\n    { exact hYZ haY }}\nend\n\nvariable (W : set \u03a9)\n\nlemma union_subset_union (hWX : W \u2286 X) (hYZ : Y \u2286 Z) : W \u222a Y \u2286 X \u222a Z :=\nbegin\n  rintros a (haW | haY),\n  { left,\n    exact hWX haW },\n  { right,\n    exact hYZ haY }\nend\n\nlemma union_subset_union_left (hXY : X \u2286 Y) : X \u222a Z \u2286 Y \u222a Z :=\nbegin\n  apply union_subset_union,\n  { exact hXY },\n  { exact subset_refl \u03a9 Z },\nend\n\n/- Intersecciones -/\n\nlemma inter_subset_left : X \u2229 Y \u2286 X :=\nbegin\n  rintros x \u27e8hxX, hxY\u27e9,\n  exact hxX,\nend\n\nlemma inter_self : X \u2229 X = X :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8hx, -\u27e9,\n    exact hx, },\n  { intro hx,\n    exact \u27e8hx, hx\u27e9 }\nend\n\nlemma inter_comm : X \u2229 Y = Y \u2229 X :=\nbegin\n  ext,\n  split,\n  { rintro \u27e8hX, hY\u27e9,\n    exact \u27e8hY, hX\u27e9, },\n  { rintro \u27e8hY, hX\u27e9,\n    exact \u27e8hX, hY\u27e9 }\nend\n\nlemma inter_assoc : X \u2229 (Y \u2229 Z) = (X \u2229 Y) \u2229 Z :=\nbegin\n  ext,\n  split,\n  { rintro \u27e8hX, \u27e8hY, hZ\u27e9\u27e9, \n    exact \u27e8\u27e8hX, hY\u27e9, hZ\u27e9 },\n  { rintro \u27e8\u27e8hX, hY\u27e9, hZ\u27e9,\n    exact \u27e8hX, \u27e8hY, hZ\u27e9\u27e9 },\nend\n\n/-!\n\n### Para todo y existe\n\n-/\n\nlemma not_exists_iff_forall_not : \u00ac (\u2203 a, a \u2208 X) \u2194 \u2200 b, \u00ac (b \u2208 X) :=\nbegin\n  split,\n  { intros hX b hb,\n    apply hX,\n    use [b, hb], },\n  { intros h1 h2,\n    cases h2 with b hb,\n    exact h1 b hb },\nend\n\nexample : \u00ac (\u2200 a, a \u2208 X) \u2194 \u2203 b, \u00ac (b \u2208 X) :=\nbegin\n  split,\n  { intro hX,\n    by_contra hnX,\n    apply hX,\n    intro a,\n    by_contra ha,\n    apply hnX,\n    use a, },\n  { rintro \u27e8b, hb\u27e9 hX,\n    exact hb (hX b), }\nend\n\nend conjuntos", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_2/soluciones/conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888613, "lm_q2_score": 0.8289388167733099, "lm_q1q2_score": 0.7156988224974556}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport easy_mode.sheet07\n\n/-\n\n# A general way to produce equivalence relations\n\nThere is some general way to produce an equivalence relation from a function: Given a \nfunction `f : X \u2192 Y`, one can define `x_1 \u2248 x_2` iff `f (x_1) = f(x_2)`. One can even \nassume the function `f` to be surjective, i.e. there exists a `Z` and a surjective \nfunction `g : X \u2192 Z` such that `x_1 \u2248 x_2` iff `g (x_1) = g(x_2)`. Let's try to prove \nthis in Lean.\n\n-/\n\ndef function.to_rel {X Y : Type} (f : X \u2192 Y) (x_1 x_2 : X) : Prop :=\nf x_1 = f x_2\n\nlemma function.to_rel_def {X Y : Type} (f : X \u2192 Y) (x_1 x_2 : X) :\n(function.to_rel f) x_1 x_2 \u2194 f x_1 = f x_2 :=\nbegin\n  sorry\nend\n\nlemma function.to_rel_refl {X Y : Type} (f : X \u2192 Y) : reflexive (function.to_rel f) :=\nbegin\n  sorry\nend\n\nlemma function.to_rel_symm {X Y : Type} (f : X \u2192 Y) : symmetric (function.to_rel f) :=\nbegin\n  sorry\nend\n\nlemma function.to_rel_trans {X Y : Type} (f : X \u2192 Y) : transitive (function.to_rel f) :=\nbegin\n  sorry\nend\n\nlemma function.to_rel_equiv {X Y : Type} (f : X \u2192 Y) : equivalence (function.to_rel f) :=\nbegin\n  sorry\nend\n\ninstance function.to_setoid {X Y : Type} (f : X \u2192 Y) : setoid X :=\n{ r := function.to_rel f,\n  iseqv := function.to_rel_equiv f }\n\nlemma exists_surjective {X Y : Type} (f : X \u2192 Y) : \u2203 (Z : Type) (g : X \u2192 Z), \nfunction.surjective g \u2227 \u2200 x x' : X, f x = f x' \u2194 g x = g x' :=\nbegin\n  sorry\nend\n\n/-\n\nIf you need a bit more practice, here is a slightly more general situation. Given an \nequivalence relation on a type Y and a function f : X \u2192 Y, there is an equivalence relation \non X, pulled back from Y, given by two elements of X being related iff there images under \nf are related. What we did up until now on this sheet is a special case where the equivalence \nrelation on Y is given by equality. \n\n-/\n\ndef fun_rel.to_rel {X Y : Type} (S : Y \u2192 Y \u2192 Prop) (f : X \u2192 Y) \n  (x1 x2 : X) : Prop :=\nS (f x1) (f x2)\n\nlemma fun_rel.to_rel_def {X Y : Type} (S : Y \u2192 Y \u2192 Prop) (f : X \u2192 Y) \n(x_1 x_2 : X) : (fun_rel.to_rel S f) x_1 x_2 \u2194 S (f x_1) (f x_2) :=\nbegin\n  sorry\nend\n\nlemma fun_rel.to_rel_refl {X Y : Type} {S : Y \u2192 Y \u2192 Prop} (hS : reflexive S) (f : X \u2192 Y) : \n  reflexive (fun_rel.to_rel S f) :=\nbegin\n  sorry\nend\n\nlemma fun_rel.to_rel_symm {X Y : Type} {S : Y \u2192 Y \u2192 Prop} (hS : symmetric S) (f : X \u2192 Y) : \n  symmetric (fun_rel.to_rel S f) :=\nbegin\n  sorry\nend\n\nlemma fun_rel.to_rel_trans {X Y : Type} {S : Y \u2192 Y \u2192 Prop} (hS : transitive S) (f : X \u2192 Y) : \n  transitive (fun_rel.to_rel S f) :=\nbegin\n  sorry\nend\n\nlemma fun_rel.to_rel_equiv {X Y : Type} {S : Y \u2192 Y \u2192 Prop} (hS : equivalence S) (f : X \u2192 Y) : \n  equivalence (fun_rel.to_rel S f) :=\nbegin\n  sorry\nend\n\ninstance fun_rel.to_setoid {X Y : Type} {S : Y \u2192 Y \u2192 Prop} (hS : equivalence S) (f : X \u2192 Y) : \n  setoid X :=\n{ r := fun_rel.to_rel S f,\n  iseqv := fun_rel.to_rel_equiv hS f }\n\n\n/- \n\nAnd here is another situation which we will encounter soon. Given an equivalence relation R on \nX and an equivalence relation S on Y, there is an equivalence relation on X \u00d7 Y in which \ntwo pairs are related if and only if there first and second entry are related. \n\n\n-/\n\ndef prod_rel {X Y : Type} (R : X \u2192 X \u2192 Prop) (S : Y \u2192 Y \u2192 Prop) \n  (u v : X \u00d7 Y) : Prop :=\nR u.1 v.1 \u2227 S u.2 v.2\n\nlemma prod_rel_def {X Y : Type} {R : X \u2192 X \u2192 Prop} {S : Y \u2192 Y \u2192 Prop} (u v : X \u00d7 Y) :\n  prod_rel R S u v \u2194 R u.1 v.1 \u2227 S u.2 v.2 := \nbegin \n  sorry\nend\n\nlemma prod_rel_refl {X Y : Type} {R : X \u2192 X \u2192 Prop} {S : Y \u2192 Y \u2192 Prop} (hR : reflexive R)\n  (hS : reflexive S) : reflexive (prod_rel R S) :=\nbegin \n  sorry\nend\n\nlemma prod_rel_symm {X Y : Type} {R : X \u2192 X \u2192 Prop} {S : Y \u2192 Y \u2192 Prop} (hR : symmetric R)\n  (hS : symmetric S) : symmetric (prod_rel R S) :=\nbegin\n  sorry\nend\n\nlemma prod_rel_trans {X Y : Type} {R : X \u2192 X \u2192 Prop} {S : Y \u2192 Y \u2192 Prop} (hR : transitive R)\n  (hS : transitive S) : transitive (prod_rel R S) :=\nbegin\n  sorry\nend\n\nlemma prod_rel_equiv {X Y : Type} {R : X \u2192 X \u2192 Prop} {S : Y \u2192 Y \u2192 Prop} (hR : equivalence R)\n  (hS : equivalence S) : equivalence (prod_rel R S) :=\nbegin\n  sorry \nend\n", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/easy_mode/sheet08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7156988192034107}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.multiset.basic\nimport data.list.range\n\n/-! # `multiset.range n` gives `{0, 1, ..., n-1}` as a multiset. -/\n\nopen list nat\n\nnamespace multiset\n\n/- range -/\n\n/-- `range n` is the multiset lifted from the list `range n`,\n  that is, the set `{0, 1, ..., n-1}`. -/\ndef range (n : \u2115) : multiset \u2115 := range n\n\n@[simp] theorem range_zero : range 0 = 0 := rfl\n\n@[simp] theorem range_succ (n : \u2115) : range (succ n) = n ::\u2098 range n :=\nby rw [range, range_succ, \u2190 coe_add, add_comm]; refl\n\n@[simp] theorem card_range (n : \u2115) : card (range n) = n := length_range _\n\ntheorem range_subset {m n : \u2115} : range m \u2286 range n \u2194 m \u2264 n := range_subset\n\n@[simp] theorem mem_range {m n : \u2115} : m \u2208 range n \u2194 m < n := mem_range\n\n@[simp] theorem not_mem_range_self {n : \u2115} : n \u2209 range n := not_mem_range_self\n\ntheorem self_mem_range_succ (n : \u2115) : n \u2208 range (n + 1) := list.self_mem_range_succ n\n\nend multiset\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/multiset/range.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888613, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7156988170244847}}
{"text": "/-\nCopyright (c) 2021 Jon Eugster. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jon Eugster, Eric Wieser\n\n! This file was ported from Lean 3 source module algebra.char_p.algebra\n! leanprover-community/mathlib commit 96782a2d6dcded92116d8ac9ae48efb41d46a27c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.CharP.Basic\nimport Mathlib.RingTheory.Localization.FractionRing\nimport Mathlib.Algebra.FreeAlgebra\n\n/-!\n# Characteristics of algebras\n\nIn this file we describe the characteristic of `R`-algebras.\n\nIn particular we are interested in the characteristic of free algebras over `R`\nand the fraction field `FractionRing R`.\n\n\n## Main results\n\n- `charP_of_injective_algebraMap` If `R \u2192+* A` is an injective algebra map\n  then `A` has the same characteristic as `R`.\n\nInstances constructed from this result:\n- Any `FreeAlgebra R X` has the same characteristic as `R`.\n- The `FractionRing R` of an integral domain `R` has the same characteristic as `R`.\n\n-/\n\n\n/-- If the algebra map `R \u2192+* A` is injective then `A` has the same characteristic as `R`. -/\ntheorem charP_of_injective_algebraMap {R A : Type _} [CommSemiring R] [Semiring A] [Algebra R A]\n    (h : Function.Injective (algebraMap R A)) (p : \u2115) [CharP R p] : CharP A p :=\n  { cast_eq_zero_iff' := fun x => by\n      rw [\u2190 CharP.cast_eq_zero_iff R p x]\n      change algebraMap \u2115 A x = 0 \u2194 algebraMap \u2115 R x = 0\n      rw [IsScalarTower.algebraMap_apply \u2115 R A x]\n      refine' Iff.trans _ h.eq_iff\n      rw [RingHom.map_zero] }\n#align char_p_of_injective_algebra_map charP_of_injective_algebraMap\n\ntheorem charP_of_injective_algebraMap' (R A : Type _) [Field R] [Semiring A] [Algebra R A]\n    [Nontrivial A] (p : \u2115) [CharP R p] : CharP A p :=\n  charP_of_injective_algebraMap (algebraMap R A).injective p\n#align char_p_of_injective_algebra_map' charP_of_injective_algebraMap'\n\n/-- If the algebra map `R \u2192+* A` is injective and `R` has characteristic zero then so does `A`. -/\ntheorem charZero_of_injective_algebraMap {R A : Type _} [CommSemiring R] [Semiring A] [Algebra R A]\n    (h : Function.Injective (algebraMap R A)) [CharZero R] : CharZero A :=\n  { cast_injective := fun x y hxy => by\n      change algebraMap \u2115 A x = algebraMap \u2115 A y at hxy\n      rw [IsScalarTower.algebraMap_apply \u2115 R A x] at hxy\n      rw [IsScalarTower.algebraMap_apply \u2115 R A y] at hxy\n      exact CharZero.cast_injective (h hxy) }\n#align char_zero_of_injective_algebra_map charZero_of_injective_algebraMap\n\n/-!\nAs an application, a `\u211a`-algebra has characteristic zero.\n-/\n\n\n-- `CharP.charP_to_charZero A _ (charP_of_injective_algebraMap h 0)` does not work\n-- here as it would require `ring A`.\nsection QAlgebra\n\nvariable (R : Type _) [Nontrivial R]\n\n/-- A nontrivial `\u211a`-algebra has `CharP` equal to zero.\n\nThis cannot be a (local) instance because it would immediately form a loop with the\ninstance `algebraRat`. It's probably easier to go the other way: prove `CharZero R` and\nautomatically receive an `Algebra \u211a R` instance.\n-/\ntheorem algebraRat.charP_zero [Semiring R] [Algebra \u211a R] : CharP R 0 :=\n  charP_of_injective_algebraMap (algebraMap \u211a R).injective 0\n#align algebra_rat.char_p_zero algebraRat.charP_zero\n\n/-- A nontrivial `\u211a`-algebra has characteristic zero.\n\nThis cannot be a (local) instance because it would immediately form a loop with the\ninstance `algebraRat`. It's probably easier to go the other way: prove `CharZero R` and\nautomatically receive an `Algebra \u211a R` instance.\n-/\ntheorem algebraRat.charZero [Ring R] [Algebra \u211a R] : CharZero R :=\n  @CharP.charP_to_charZero R _ (algebraRat.charP_zero R)\n#align algebra_rat.char_zero algebraRat.charZero\n\nend QAlgebra\n\n/-!\nAn algebra over a field has the same characteristic as the field.\n-/\n\n\nsection\n\nvariable (K L : Type _) [Field K] [CommSemiring L] [Nontrivial L] [Algebra K L]\n\ntheorem Algebra.charP_iff (p : \u2115) : CharP K p \u2194 CharP L p :=\n  (algebraMap K L).charP_iff_charP p\n#align algebra.char_p_iff Algebra.charP_iff\n\ntheorem Algebra.ringChar_eq : ringChar K = ringChar L := by\n  rw [ringChar.eq_iff, Algebra.charP_iff K L]\n  apply ringChar.charP\n#align algebra.ring_char_eq Algebra.ringChar_eq\n\nend\n\nnamespace FreeAlgebra\n\nvariable {R X : Type _} [CommSemiring R] (p : \u2115)\n\n/-- If `R` has characteristic `p`, then so does `FreeAlgebra R X`. -/\ninstance charP [CharP R p] : CharP (FreeAlgebra R X) p :=\n  charP_of_injective_algebraMap FreeAlgebra.algebraMap_leftInverse.injective p\n#align free_algebra.char_p FreeAlgebra.charP\n\n/-- If `R` has characteristic `0`, then so does `FreeAlgebra R X`. -/\ninstance charZero [CharZero R] : CharZero (FreeAlgebra R X) :=\n  charZero_of_injective_algebraMap FreeAlgebra.algebraMap_leftInverse.injective\n#align free_algebra.char_zero FreeAlgebra.charZero\n\nend FreeAlgebra\n\nnamespace IsFractionRing\n\nvariable (R : Type _) {K : Type _} [CommRing R] [Field K] [Algebra R K] [IsFractionRing R K]\n\nvariable (p : \u2115)\n\n/-- If `R` has characteristic `p`, then so does Frac(R). -/\ntheorem charP_of_isFractionRing [CharP R p] : CharP K p :=\n  charP_of_injective_algebraMap (IsFractionRing.injective R K) p\n#align is_fraction_ring.char_p_of_is_fraction_ring IsFractionRing.charP_of_isFractionRing\n\n/-- If `R` has characteristic `0`, then so does Frac(R). -/\ntheorem charZero_of_isFractionRing [CharZero R] : CharZero K :=\n  @CharP.charP_to_charZero K _ (charP_of_isFractionRing R 0)\n#align is_fraction_ring.char_zero_of_is_fraction_ring IsFractionRing.charZero_of_isFractionRing\n\nvariable [IsDomain R]\n\n/-- If `R` has characteristic `p`, then so does `FractionRing R`. -/\ninstance charP [CharP R p] : CharP (FractionRing R) p :=\n  charP_of_isFractionRing R p\n#align is_fraction_ring.char_p IsFractionRing.charP\n\n/-- If `R` has characteristic `0`, then so does `FractionRing R`. -/\ninstance charZero [CharZero R] : CharZero (FractionRing R) :=\n  charZero_of_isFractionRing R\n#align is_fraction_ring.char_zero IsFractionRing.charZero\n\nend IsFractionRing\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/CharP/Algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7156988152001611}}
{"text": "/-\nCopyright (c) 2020 Markus Himmel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Markus Himmel\n\n! This file was ported from Lean 3 source module algebra.category.Module.kernels\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Category.Module.EpiMono\nimport Mathbin.CategoryTheory.ConcreteCategory.Elementwise\n\n/-!\n# The concrete (co)kernels in the category of modules are (co)kernels in the categorical sense.\n-/\n\n\nopen CategoryTheory\n\nopen CategoryTheory.Limits\n\nuniverse u v\n\nnamespace ModuleCat\n\nvariable {R : Type u} [Ring R]\n\nsection\n\nvariable {M N : ModuleCat.{v} R} (f : M \u27f6 N)\n\n/-- The kernel cone induced by the concrete kernel. -/\ndef kernelCone : KernelFork f :=\n  KernelFork.of\u03b9 (asHom f.ker.Subtype) <| by tidy\n#align Module.kernel_cone ModuleCat.kernelCone\n\n/-- The kernel of a linear map is a kernel in the categorical sense. -/\ndef kernelIsLimit : IsLimit (kernelCone f) :=\n  Fork.IsLimit.mk _\n    (fun s =>\n      LinearMap.codRestrict f.ker (Fork.\u03b9 s) fun c =>\n        LinearMap.mem_ker.2 <|\n          by\n          rw [\u2190 @Function.comp_apply _ _ _ f (fork.\u03b9 s) c, \u2190 coe_comp, fork.condition,\n            has_zero_morphisms.comp_zero (fork.\u03b9 s) N]\n          rfl)\n    (fun s => LinearMap.subtype_comp_codRestrict _ _ _) fun s m h =>\n    LinearMap.ext fun x => Subtype.ext_iff_val.2 (by simpa [\u2190 h] )\n#align Module.kernel_is_limit ModuleCat.kernelIsLimit\n\n/-- The cokernel cocone induced by the projection onto the quotient. -/\ndef cokernelCocone : CokernelCofork f :=\n  CokernelCofork.of\u03c0 (asHom f.range.mkQ) <| LinearMap.range_mkQ_comp _\n#align Module.cokernel_cocone ModuleCat.cokernelCocone\n\n/-- The projection onto the quotient is a cokernel in the categorical sense. -/\ndef cokernelIsColimit : IsColimit (cokernelCocone f) :=\n  Cofork.IsColimit.mk _\n    (fun s =>\n      f.range.liftQ (Cofork.\u03c0 s) <| LinearMap.range_le_ker_iff.2 <| CokernelCofork.condition s)\n    (fun s => f.range.liftQ_mkQ (Cofork.\u03c0 s) _) fun s m h =>\n    by\n    haveI : epi (as_hom f.range.mkq) := (epi_iff_range_eq_top _).mpr (Submodule.range_mkQ _)\n    apply (cancel_epi (as_hom f.range.mkq)).1\n    convert h\n    exact Submodule.liftQ_mkQ _ _ _\n#align Module.cokernel_is_colimit ModuleCat.cokernelIsColimit\n\nend\n\n/-- The category of R-modules has kernels, given by the inclusion of the kernel submodule. -/\ntheorem hasKernels_moduleCat : HasKernels (ModuleCat R) :=\n  \u27e8fun X Y f => HasLimit.mk \u27e8_, kernelIsLimit f\u27e9\u27e9\n#align Module.has_kernels_Module ModuleCat.hasKernels_moduleCat\n\n/-- The category or R-modules has cokernels, given by the projection onto the quotient. -/\ntheorem hasCokernels_moduleCat : HasCokernels (ModuleCat R) :=\n  \u27e8fun X Y f => HasColimit.mk \u27e8_, cokernelIsColimit f\u27e9\u27e9\n#align Module.has_cokernels_Module ModuleCat.hasCokernels_moduleCat\n\nopen ModuleCat\n\nattribute [local instance] has_kernels_Module\n\nattribute [local instance] has_cokernels_Module\n\nvariable {G H : ModuleCat.{v} R} (f : G \u27f6 H)\n\n/-- The categorical kernel of a morphism in `Module`\nagrees with the usual module-theoretical kernel.\n-/\nnoncomputable def kernelIsoKer {G H : ModuleCat.{v} R} (f : G \u27f6 H) :\n    kernel f \u2245 ModuleCat.of R f.ker :=\n  limit.isoLimitCone \u27e8_, kernelIsLimit f\u27e9\n#align Module.kernel_iso_ker ModuleCat.kernelIsoKer\n\n-- We now show this isomorphism commutes with the inclusion of the kernel into the source.\n@[simp, elementwise]\ntheorem kernelIsoKer_inv_kernel_\u03b9 : (kernelIsoKer f).inv \u226b kernel.\u03b9 f = f.ker.Subtype :=\n  limit.isoLimitCone_inv_\u03c0 _ _\n#align Module.kernel_iso_ker_inv_kernel_\u03b9 ModuleCat.kernelIsoKer_inv_kernel_\u03b9\n\n@[simp, elementwise]\ntheorem kernelIsoKer_hom_ker_subtype : (kernelIsoKer f).hom \u226b f.ker.Subtype = kernel.\u03b9 f :=\n  IsLimit.conePointUniqueUpToIso_inv_comp _ (limit.isLimit _) WalkingParallelPair.zero\n#align Module.kernel_iso_ker_hom_ker_subtype ModuleCat.kernelIsoKer_hom_ker_subtype\n\n/-- The categorical cokernel of a morphism in `Module`\nagrees with the usual module-theoretical quotient.\n-/\nnoncomputable def cokernelIsoRangeQuotient {G H : ModuleCat.{v} R} (f : G \u27f6 H) :\n    cokernel f \u2245 ModuleCat.of R (H \u29f8 f.range) :=\n  colimit.isoColimitCocone \u27e8_, cokernelIsColimit f\u27e9\n#align Module.cokernel_iso_range_quotient ModuleCat.cokernelIsoRangeQuotient\n\n-- We now show this isomorphism commutes with the projection of target to the cokernel.\n@[simp, elementwise]\ntheorem cokernel_\u03c0_cokernelIsoRangeQuotient_hom :\n    cokernel.\u03c0 f \u226b (cokernelIsoRangeQuotient f).hom = f.range.mkQ := by\n  convert colimit.iso_colimit_cocone_\u03b9_hom _ _ <;> rfl\n#align Module.cokernel_\u03c0_cokernel_iso_range_quotient_hom ModuleCat.cokernel_\u03c0_cokernelIsoRangeQuotient_hom\n\n@[simp, elementwise]\ntheorem range_mkQ_cokernelIsoRangeQuotient_inv :\n    \u21bff.range.mkQ \u226b (cokernelIsoRangeQuotient f).inv = cokernel.\u03c0 f := by\n  convert colimit.iso_colimit_cocone_\u03b9_inv \u27e8_, cokernel_is_colimit f\u27e9 _ <;> rfl\n#align Module.range_mkq_cokernel_iso_range_quotient_inv ModuleCat.range_mkQ_cokernelIsoRangeQuotient_inv\n\ntheorem cokernel_\u03c0_ext {M N : ModuleCat.{u} R} (f : M \u27f6 N) {x y : N} (m : M) (w : x = y + f m) :\n    cokernel.\u03c0 f x = cokernel.\u03c0 f y := by\n  subst w\n  simp\n#align Module.cokernel_\u03c0_ext ModuleCat.cokernel_\u03c0_ext\n\nend ModuleCat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Category/Module/Kernels.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7156988104620504}}
{"text": "/-\nCopyright (c) 2022 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module linear_algebra.clifford_algebra.star\n! leanprover-community/mathlib commit 4d66277cfec381260ba05c68f9ae6ce2a118031d\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.CliffordAlgebra.Conjugation\n\n/-!\n# Star structure on `clifford_algebra`\n\nThis file defines the \"clifford conjugation\", equal to `reverse (involute x)`, and assigns it the\n`star` notation.\n\nThis choice is somewhat non-canonical; a star structure is also possible under `reverse` alone.\nHowever, defining it gives us access to constructions like `unitary`.\n\nMost results about `star` can be obtained by unfolding it via `clifford_algebra.star_def`.\n\n## Main definitions\n\n* `clifford_algebra.star_ring`\n\n-/\n\n\nvariable {R : Type _} [CommRing R]\n\nvariable {M : Type _} [AddCommGroup M] [Module R M]\n\nvariable {Q : QuadraticForm R M}\n\nnamespace CliffordAlgebra\n\ninstance : StarRing (CliffordAlgebra Q)\n    where\n  unit x := reverse (involute x)\n  star_involutive x := by\n    simp only [reverse_involute_commute.eq, reverse_reverse, involute_involute]\n  star_mul x y := by simp only [map_mul, reverse.map_mul]\n  star_add x y := by simp only [map_add]\n\ntheorem star_def (x : CliffordAlgebra Q) : star x = reverse (involute x) :=\n  rfl\n#align clifford_algebra.star_def CliffordAlgebra.star_def\n\ntheorem star_def' (x : CliffordAlgebra Q) : star x = involute (reverse x) :=\n  reverse_involute _\n#align clifford_algebra.star_def' CliffordAlgebra.star_def'\n\n@[simp]\ntheorem star_\u03b9 (m : M) : star (\u03b9 Q m) = -\u03b9 Q m := by rw [star_def, involute_\u03b9, map_neg, reverse_\u03b9]\n#align clifford_algebra.star_\u03b9 CliffordAlgebra.star_\u03b9\n\n/-- Note that this not match the `star_smul` implied by `star_module`; it certainly could if we\nalso conjugated all the scalars, but there appears to be nothing in the literature that advocates\ndoing this. -/\n@[simp]\ntheorem star_smul (r : R) (x : CliffordAlgebra Q) : star (r \u2022 x) = r \u2022 star x := by\n  rw [star_def, star_def, map_smul, map_smul]\n#align clifford_algebra.star_smul CliffordAlgebra.star_smul\n\n@[simp]\ntheorem star_algebraMap (r : R) :\n    star (algebraMap R (CliffordAlgebra Q) r) = algebraMap R (CliffordAlgebra Q) r := by\n  rw [star_def, involute.commutes, reverse.commutes]\n#align clifford_algebra.star_algebra_map CliffordAlgebra.star_algebraMap\n\nend CliffordAlgebra\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/CliffordAlgebra/Star.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7156988046344767}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n\n! This file was ported from Lean 3 source module category_theory.functor.reflects_isomorphisms\n! leanprover-community/mathlib commit 32253a1a1071173b33dc7d6a218cf722c6feb514\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.Balanced\nimport Mathlib.CategoryTheory.Functor.EpiMono\nimport Mathlib.CategoryTheory.Functor.FullyFaithful\n\n/-!\n# Functors which reflect isomorphisms\n\nA functor `F` reflects isomorphisms if whenever `F.map f` is an isomorphism, `f` was too.\n\nIt is formalized as a `Prop` valued typeclass `ReflectsIsomorphisms F`.\n\nAny fully faithful functor reflects isomorphisms.\n-/\n\n\nopen CategoryTheory CategoryTheory.Functor\n\nnamespace CategoryTheory\n\nuniverse v\u2081 v\u2082 v\u2083 u\u2081 u\u2082 u\u2083\n\nvariable {C : Type u\u2081} [Category.{v\u2081} C]\n\nsection ReflectsIso\n\nvariable {D : Type u\u2082} [Category.{v\u2082} D]\n\nvariable {E : Type u\u2083} [Category.{v\u2083} E]\n\n/-- Define what it means for a functor `F : C \u2964 D` to reflect isomorphisms: for any\nmorphism `f : A \u27f6 B`, if `F.map f` is an isomorphism then `f` is as well.\nNote that we do not assume or require that `F` is faithful.\n-/\nclass ReflectsIsomorphisms (F : C \u2964 D) : Prop where\n  /-- For any `f`, if `F.map f` is an iso, then so was `f`-/\n  reflects : \u2200 {A B : C} (f : A \u27f6 B) [IsIso (F.map f)], IsIso f\n#align category_theory.reflects_isomorphisms CategoryTheory.ReflectsIsomorphisms\n\n/-- If `F` reflects isos and `F.map f` is an iso, then `f` is an iso. -/\ntheorem isIso_of_reflects_iso {A B : C} (f : A \u27f6 B) (F : C \u2964 D) [IsIso (F.map f)]\n    [ReflectsIsomorphisms F] : IsIso f :=\n  ReflectsIsomorphisms.reflects F f\n#align category_theory.is_iso_of_reflects_iso CategoryTheory.isIso_of_reflects_iso\n\ninstance (priority := 100) of_full_and_faithful (F : C \u2964 D) [Full F] [Faithful F] :\n    ReflectsIsomorphisms F\n    where reflects f i :=\n    \u27e8\u27e8F.preimage (inv (F.map f)), \u27e8F.map_injective (by simp), F.map_injective (by simp)\u27e9\u27e9\u27e9\n#align category_theory.of_full_and_faithful CategoryTheory.of_full_and_faithful\n\ninstance (F : C \u2964 D) (G : D \u2964 E) [ReflectsIsomorphisms F] [ReflectsIsomorphisms G] :\n    ReflectsIsomorphisms (F \u22d9 G) :=\n  \u27e8fun f (hf : IsIso (G.map _)) => by\n    skip\n    haveI := isIso_of_reflects_iso (F.map f) G\n    exact isIso_of_reflects_iso f F\u27e9\n\ninstance (priority := 100) reflectsIsomorphisms_of_reflectsMonomorphisms_of_reflectsEpimorphisms\n    [Balanced C] (F : C \u2964 D) [ReflectsMonomorphisms F] [ReflectsEpimorphisms F] :\n    ReflectsIsomorphisms F where\n  reflects f hf := by\n    skip\n    haveI : Epi f := epi_of_epi_map F inferInstance\n    haveI : Mono f := mono_of_mono_map F inferInstance\n    exact isIso_of_mono_of_epi f\n#align category_theory.reflects_isomorphisms_of_reflects_monomorphisms_of_reflects_epimorphisms CategoryTheory.reflectsIsomorphisms_of_reflectsMonomorphisms_of_reflectsEpimorphisms\n\nend ReflectsIso\n\nend CategoryTheory\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Functor/ReflectsIso.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7156497646006539}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson, Jalex Stark\n-/\nimport algebra.order.with_zero\nimport data.polynomial.monic\n/-!\n# Lemmas for the interaction between polynomials and `\u2211` and `\u220f`.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nRecall that `\u2211` and `\u220f` are notation for `finset.sum` and `finset.prod` respectively.\n\n## Main results\n\n- `polynomial.nat_degree_prod_of_monic` : the degree of a product of monic polynomials is the\n  product of degrees. We prove this only for `[comm_semiring R]`,\n  but it ought to be true for `[semiring R]` and `list.prod`.\n- `polynomial.nat_degree_prod` : for polynomials over an integral domain,\n  the degree of the product is the sum of degrees.\n- `polynomial.leading_coeff_prod` : for polynomials over an integral domain,\n  the leading coefficient is the product of leading coefficients.\n- `polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing\n  the second coefficient of the characteristic polynomial.\n-/\n\nopen finset\nopen multiset\n\nopen_locale big_operators polynomial\n\nuniverses u w\n\nvariables {R : Type u} {\u03b9 : Type w}\n\nnamespace polynomial\n\nvariables (s : finset \u03b9)\n\nsection semiring\n\nvariables {S : Type*} [semiring S]\n\nlemma nat_degree_list_sum_le (l : list S[X]) :\n  nat_degree l.sum \u2264 (l.map nat_degree).foldr max 0 :=\nlist.sum_le_foldr_max nat_degree (by simp) nat_degree_add_le _\n\nlemma nat_degree_multiset_sum_le (l : multiset S[X]) :\n  nat_degree l.sum \u2264 (l.map nat_degree).foldr max max_left_comm 0 :=\nquotient.induction_on l (by simpa using nat_degree_list_sum_le)\n\nlemma nat_degree_sum_le (f : \u03b9 \u2192 S[X]) :\n  nat_degree (\u2211 i in s, f i) \u2264 s.fold max 0 (nat_degree \u2218 f) :=\nby simpa using nat_degree_multiset_sum_le (s.val.map f)\n\nlemma degree_list_sum_le (l : list S[X]) :\n  degree l.sum \u2264 (l.map nat_degree).maximum :=\nbegin\n  by_cases h : l.sum = 0,\n  { simp [h] },\n  { rw degree_eq_nat_degree h,\n    suffices : (l.map nat_degree).maximum = ((l.map nat_degree).foldr max 0 : \u2115),\n    { rw this,\n      simpa [this] using nat_degree_list_sum_le l },\n    rw \u2190 list.foldr_max_of_ne_nil,\n    { congr },\n    contrapose! h,\n    rw [list.map_eq_nil] at h,\n    simp [h] }\nend\n\n\n\nlemma degree_list_prod_le (l : list S[X]) :\n  degree l.prod \u2264 (l.map degree).sum :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simpa using (degree_mul_le _ _).trans (add_le_add_left IH _) }\nend\n\nlemma coeff_list_prod_of_nat_degree_le (l : list S[X]) (n : \u2115)\n  (hl : \u2200 p \u2208 l, nat_degree p \u2264 n) :\n  coeff (list.prod l) (l.length * n) = (l.map (\u03bb p, coeff p n)).prod :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { have hl' : \u2200 (p \u2208 tl), nat_degree p \u2264 n := \u03bb p hp, hl p (list.mem_cons_of_mem _ hp),\n    simp only [list.prod_cons, list.map, list.length],\n    rw [add_mul, one_mul, add_comm, \u2190IH hl', mul_comm tl.length],\n    have h : nat_degree tl.prod \u2264 n * tl.length,\n    { refine (nat_degree_list_prod_le _).trans _,\n      rw [\u2190tl.length_map nat_degree, mul_comm],\n      refine list.sum_le_card_nsmul _ _ _,\n      simpa using hl' },\n    have hdn : nat_degree hd \u2264 n := hl _ (list.mem_cons_self _ _),\n    rcases hdn.eq_or_lt with rfl|hdn',\n    { cases h.eq_or_lt with h' h',\n      { rw [\u2190h', coeff_mul_degree_add_degree, leading_coeff, leading_coeff] },\n      { rw [coeff_eq_zero_of_nat_degree_lt, coeff_eq_zero_of_nat_degree_lt h', mul_zero],\n        exact nat_degree_mul_le.trans_lt (add_lt_add_left h' _) } },\n    { rw [coeff_eq_zero_of_nat_degree_lt hdn', coeff_eq_zero_of_nat_degree_lt, zero_mul],\n      exact nat_degree_mul_le.trans_lt (add_lt_add_of_lt_of_le hdn' h) } }\nend\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R] (f : \u03b9 \u2192 R[X]) (t : multiset R[X])\n\nlemma nat_degree_multiset_prod_le :\n  t.prod.nat_degree \u2264 (t.map nat_degree).sum :=\nquotient.induction_on t (by simpa using nat_degree_list_prod_le)\n\nlemma nat_degree_prod_le : (\u220f i in s, f i).nat_degree \u2264 \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_le (s.1.map f)\n\n/--\nThe degree of a product of polynomials is at most the sum of the degrees,\nwhere the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_multiset_prod_le :\n  t.prod.degree \u2264 (t.map polynomial.degree).sum :=\nquotient.induction_on t (by simpa using degree_list_prod_le)\n\nlemma degree_prod_le : (\u220f i in s, f i).degree \u2264 \u2211 i in s, (f i).degree :=\nby simpa only [multiset.map_map] using degree_multiset_prod_le (s.1.map f)\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_multiset_prod' (h : (t.map leading_coeff).prod \u2260 0) :\n  t.prod.leading_coeff = (t.map leading_coeff).prod :=\nbegin\n  induction t using multiset.induction_on with a t ih, { simp },\n  simp only [multiset.map_cons, multiset.prod_cons] at h \u22a2,\n  rw polynomial.leading_coeff_mul'; { rwa ih, apply right_ne_zero_of_mul h }\nend\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod' (s.1.map f) (by simpa using h)\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_multiset_prod' (h : (t.map (\u03bb f, leading_coeff f)).prod \u2260 0) :\n  t.prod.nat_degree = (t.map (\u03bb f, nat_degree f)).sum :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _), { simp },\n  rw [multiset.map_cons, multiset.prod_cons] at ht \u22a2,\n  rw [multiset.sum_cons, polynomial.nat_degree_mul', ih],\n  { apply right_ne_zero_of_mul ht },\n  { rwa polynomial.leading_coeff_multiset_prod', apply right_ne_zero_of_mul ht },\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod' (s.1.map f) (by simpa using h)\n\nlemma nat_degree_multiset_prod_of_monic (h : \u2200 f \u2208 t, monic f) :\n  t.prod.nat_degree = (t.map nat_degree).sum :=\nbegin\n  nontriviality R,\n  apply nat_degree_multiset_prod',\n  suffices : (t.map (\u03bb f, leading_coeff f)).prod = 1, { rw this, simp },\n  convert prod_replicate t.card (1 : R),\n  { simp only [eq_replicate, multiset.card_map, eq_self_iff_true, true_and],\n    rintros i hi,\n    obtain \u27e8i, hi, rfl\u27e9 := multiset.mem_map.mp hi,\n    apply h, assumption },\n  { simp }\nend\n\nlemma nat_degree_prod_of_monic (h : \u2200 i \u2208 s, (f i).monic) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_of_monic (s.1.map f) (by simpa using h)\n\nlemma coeff_multiset_prod_of_nat_degree_le (n : \u2115)\n  (hl : \u2200 p \u2208 t, nat_degree p \u2264 n) :\n  coeff t.prod (t.card * n) = (t.map (\u03bb p, coeff p n)).prod :=\nbegin\n  induction t using quotient.induction_on,\n  simpa using coeff_list_prod_of_nat_degree_le _ _ hl\nend\n\nlemma coeff_prod_of_nat_degree_le (f : \u03b9 \u2192 R[X]) (n : \u2115)\n  (h : \u2200 p \u2208 s, nat_degree (f p) \u2264 n) :\n  coeff (\u220f i in s, f i) (s.card * n) = \u220f i in s, coeff (f i) n :=\nbegin\n  cases s with l hl,\n  convert coeff_multiset_prod_of_nat_degree_le (l.map f) _ _,\n  { simp },\n  { simp },\n  { simpa using h }\nend\n\nlemma coeff_zero_multiset_prod :\n  t.prod.coeff 0 = (t.map (\u03bb f, coeff f 0)).prod :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ht, _), { simp },\n  rw [multiset.prod_cons, multiset.map_cons, multiset.prod_cons, polynomial.mul_coeff_zero, ht]\nend\n\nlemma coeff_zero_prod :\n  (\u220f i in s, f i).coeff 0 = \u220f i in s, (f i).coeff 0 :=\nby simpa using coeff_zero_multiset_prod (s.1.map f)\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nopen monic\n-- Eventually this can be generalized with Vieta's formulas\n-- plus the connection between roots and factorization.\nlemma multiset_prod_X_sub_C_next_coeff (t : multiset R) :\n  next_coeff (t.map (\u03bb x, X - C x)).prod = -t.sum :=\nbegin\n  rw next_coeff_multiset_prod,\n  { simp only [next_coeff_X_sub_C],\n    exact t.sum_hom (-add_monoid_hom.id R) },\n  { intros, apply monic_X_sub_C }\nend\n\nlemma prod_X_sub_C_next_coeff {s : finset \u03b9} (f : \u03b9 \u2192 R) :\n  next_coeff \u220f i in s, (X - C (f i)) = -\u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_next_coeff (s.1.map f)\n\nlemma multiset_prod_X_sub_C_coeff_card_pred (t : multiset R) (ht : 0 < t.card) :\n  (t.map (\u03bb x, (X - C x))).prod.coeff (t.card - 1) = -t.sum :=\nbegin\n  nontriviality R,\n  convert multiset_prod_X_sub_C_next_coeff (by assumption),\n  rw next_coeff, split_ifs,\n  { rw nat_degree_multiset_prod_of_monic at h; simp only [multiset.mem_map] at *,\n    swap, { rintros _ \u27e8_, _, rfl\u27e9, apply monic_X_sub_C },\n    simp_rw [multiset.sum_eq_zero_iff, multiset.mem_map] at h,\n    contrapose! h,\n    obtain \u27e8x, hx\u27e9 := card_pos_iff_exists_mem.mp ht,\n    exact \u27e8_, \u27e8_, \u27e8x, hx, rfl\u27e9, nat_degree_X_sub_C _\u27e9, one_ne_zero\u27e9 },\n  congr, rw nat_degree_multiset_prod_of_monic; { simp [nat_degree_X_sub_C, monic_X_sub_C] },\nend\n\nlemma prod_X_sub_C_coeff_card_pred (s : finset \u03b9) (f : \u03b9 \u2192 R) (hs : 0 < s.card) :\n  (\u220f i in s, (X - C (f i))).coeff (s.card - 1) = - \u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_coeff_card_pred (s.1.map f) (by simpa using hs)\n\nend comm_ring\n\nsection no_zero_divisors\n\nsection semiring\nvariables [semiring R] [no_zero_divisors R]\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n`[nontrivial R]` is needed, otherwise for `l = []` we have `\u22a5` in the LHS and `0` in the RHS.\n-/\nlemma degree_list_prod [nontrivial R] (l : list R[X]) :\n  l.prod.degree = (l.map degree).sum :=\nmap_list_prod (@degree_monoid_hom R _ _ _) l\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R] [no_zero_divisors R] (f : \u03b9 \u2192 R[X]) (t : multiset R[X])\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees.\n\nSee `polynomial.nat_degree_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma nat_degree_prod (h : \u2200 i \u2208 s, f i \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nbegin\n  nontriviality R,\n  apply nat_degree_prod',\n  rw prod_ne_zero_iff,\n  intros x hx, simp [h x hx]\nend\n\nlemma nat_degree_multiset_prod (h : (0 : R[X]) \u2209 t) :\n  nat_degree t.prod = (t.map nat_degree).sum :=\nbegin\n  nontriviality R,\n  rw nat_degree_multiset_prod',\n  simp_rw [ne.def, multiset.prod_eq_zero_iff, multiset.mem_map, leading_coeff_eq_zero],\n  rintro \u27e8_, h, rfl\u27e9,\n  contradiction\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_multiset_prod [nontrivial R] :\n  t.prod.degree = (t.map (\u03bb f, degree f)).sum :=\nmap_multiset_prod (@degree_monoid_hom R _ _ _) _\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_prod [nontrivial R] : (\u220f i in s, f i).degree = \u2211 i in s, (f i).degree :=\nmap_prod (@degree_monoid_hom R _ _ _) _ _\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_multiset_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_multiset_prod :\n  t.prod.leading_coeff = (t.map (\u03bb f, leading_coeff f)).prod :=\nby { rw [\u2190 leading_coeff_hom_apply, monoid_hom.map_multiset_prod], refl }\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_prod :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod (s.1.map f)\n\nend comm_semiring\n\nend no_zero_divisors\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/polynomial/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7156497527968614}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport analysis.convex.star\nimport analysis.normed_space.pointwise\nimport analysis.seminorm\n\n/-!\n# The Minkowksi functional\n\nThis file defines the Minkowski functional, aka gauge.\n\nThe Minkowski functional of a set `s` is the function which associates each point to how much you\nneed to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is\na seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This\ninduces the equivalence of seminorms and locally convex topological vector spaces.\n\n## Main declarations\n\nFor a real vector space,\n* `gauge`: Aka Minkowksi functional. `gauge s x` is the least (actually, an infimum) `r` such\n  that `x \u2208 r \u2022 s`.\n* `gauge_seminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and\n  absorbent.\n\n## References\n\n* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]\n\n## Tags\n\nMinkowski functional, gauge\n-/\n\nopen normed_field set\nopen_locale pointwise\n\nnoncomputable theory\n\nvariables {E : Type*}\n\nsection add_comm_group\nvariables [add_comm_group E] [module \u211d E]\n\n/--The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional\nwhich sends `x : E` to the smallest `r : \u211d` such that `x` is in `s` scaled by `r`. -/\ndef gauge (s : set E) (x : E) : \u211d := Inf {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 s}\n\nvariables {s t : set E} {a : \u211d} {x : E}\n\nlemma gauge_def : gauge s x = Inf {r \u2208 set.Ioi 0 | x \u2208 r \u2022 s} := rfl\n\n/-- An alternative definition of the gauge using scalar multiplication on the element rather than on\nthe set. -/\nlemma gauge_def' : gauge s x = Inf {r \u2208 set.Ioi 0 | r\u207b\u00b9 \u2022 x \u2208 s} :=\nbegin\n  unfold gauge,\n  congr' 1,\n  ext r,\n  exact and_congr_right (\u03bb hr, mem_smul_set_iff_inv_smul_mem\u2080 hr.ne' _ _),\nend\n\nprivate lemma gauge_set_bdd_below : bdd_below {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 s} := \u27e80, \u03bb r hr, hr.1.le\u27e9\n\n/-- If the given subset is `absorbent` then the set we take an infimum over in `gauge` is nonempty,\nwhich is useful for proving many properties about the gauge.  -/\nlemma absorbent.gauge_set_nonempty (absorbs : absorbent \u211d s) :\n  {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 s}.nonempty :=\nlet \u27e8r, hr\u2081, hr\u2082\u27e9 := absorbs x in \u27e8r, hr\u2081, hr\u2082 r (real.norm_of_nonneg hr\u2081.le).ge\u27e9\n\nlemma gauge_mono (hs : absorbent \u211d s) (h : s \u2286 t) : gauge t \u2264 gauge s :=\n\u03bb x, cInf_le_cInf gauge_set_bdd_below hs.gauge_set_nonempty $ \u03bb r hr, \u27e8hr.1, smul_set_mono h hr.2\u27e9\n\nlemma exists_lt_of_gauge_lt (absorbs : absorbent \u211d s) (h : gauge s x < a) :\n  \u2203 b, 0 < b \u2227 b < a \u2227 x \u2208 b \u2022 s :=\nbegin\n  obtain \u27e8b, \u27e8hb, hx\u27e9, hba\u27e9 := exists_lt_of_cInf_lt absorbs.gauge_set_nonempty h,\n  exact \u27e8b, hb, hba, hx\u27e9,\nend\n\n/-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s`\nbut, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/\n@[simp] lemma gauge_zero : gauge s 0 = 0 :=\nbegin\n  rw gauge_def',\n  by_cases (0 : E) \u2208 s,\n  { simp only [smul_zero, sep_true, h, cInf_Ioi] },\n  { simp only [smul_zero, sep_false, h, real.Inf_empty] }\nend\n\n@[simp] lemma gauge_zero' : gauge (0 : set E) = 0 :=\nbegin\n  ext,\n  rw gauge_def',\n  obtain rfl | hx := eq_or_ne x 0,\n  { simp only [cInf_Ioi, mem_zero, pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] },\n  { simp only [mem_zero, pi.zero_apply, inv_eq_zero, smul_eq_zero],\n    convert real.Inf_empty,\n    exact eq_empty_iff_forall_not_mem.2 (\u03bb r hr, hr.2.elim (ne_of_gt hr.1) hx) }\nend\n\n@[simp] lemma gauge_empty : gauge (\u2205 : set E) = 0 :=\nby { ext, simp only [gauge_def', real.Inf_empty, mem_empty_eq, pi.zero_apply, sep_false] }\n\nlemma gauge_of_subset_zero (h : s \u2286 0) : gauge s = 0 :=\nby { obtain rfl | rfl := subset_singleton_iff_eq.1 h, exacts [gauge_empty, gauge_zero'] }\n\n/-- The gauge is always nonnegative. -/\nlemma gauge_nonneg (x : E) : 0 \u2264 gauge s x := real.Inf_nonneg _ $ \u03bb x hx, hx.1.le\n\nlemma gauge_neg (symmetric : \u2200 x \u2208 s, -x \u2208 s) (x : E) : gauge s (-x) = gauge s x :=\nbegin\n  have : \u2200 x, -x \u2208 s \u2194 x \u2208 s := \u03bb x, \u27e8\u03bb h, by simpa using symmetric _ h, symmetric x\u27e9,\n  rw [gauge_def', gauge_def'],\n  simp_rw [smul_neg, this],\nend\n\nlemma gauge_le_of_mem (ha : 0 \u2264 a) (hx : x \u2208 a \u2022 s) : gauge s x \u2264 a :=\nbegin\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [mem_singleton_iff.1 (zero_smul_subset _ hx), gauge_zero] },\n  { exact cInf_le gauge_set_bdd_below \u27e8ha', hx\u27e9 }\nend\n\nlemma gauge_le_eq (hs\u2081 : convex \u211d s) (hs\u2080 : (0 : E) \u2208 s) (hs\u2082 : absorbent \u211d s) (ha : 0 \u2264 a) :\n  {x | gauge s x \u2264 a} = \u22c2 (r : \u211d) (H : a < r), r \u2022 s :=\nbegin\n  ext,\n  simp_rw [set.mem_Inter, set.mem_set_of_eq],\n  refine \u27e8\u03bb h r hr, _, \u03bb h, le_of_forall_pos_lt_add (\u03bb \u03b5 h\u03b5, _)\u27e9,\n  { have hr' := ha.trans_lt hr,\n    rw mem_smul_set_iff_inv_smul_mem\u2080 hr'.ne',\n    obtain \u27e8\u03b4, \u03b4_pos, h\u03b4r, h\u03b4\u27e9 := exists_lt_of_gauge_lt hs\u2082 (h.trans_lt hr),\n    suffices : (r\u207b\u00b9 * \u03b4) \u2022 \u03b4\u207b\u00b9 \u2022 x \u2208 s,\n    { rwa [smul_smul, mul_inv_cancel_right\u2080 \u03b4_pos.ne'] at this },\n    rw mem_smul_set_iff_inv_smul_mem\u2080 \u03b4_pos.ne' at h\u03b4,\n    refine hs\u2081.smul_mem_of_zero_mem hs\u2080 h\u03b4\n      \u27e8mul_nonneg (inv_nonneg.2 hr'.le) \u03b4_pos.le, _\u27e9,\n    rw [inv_mul_le_iff hr', mul_one],\n    exact h\u03b4r.le },\n  { have h\u03b5' := (lt_add_iff_pos_right a).2 (half_pos h\u03b5),\n    exact (gauge_le_of_mem (ha.trans h\u03b5'.le) $ h _ h\u03b5').trans_lt\n      (add_lt_add_left (half_lt_self h\u03b5) _) }\nend\n\nlemma gauge_lt_eq' (absorbs : absorbent \u211d s) (a : \u211d) :\n  {x | gauge s x < a} = \u22c3 (r : \u211d) (H : 0 < r) (H : r < a), r \u2022 s :=\nbegin\n  ext,\n  simp_rw [mem_set_of_eq, mem_Union, exists_prop],\n  exact \u27e8exists_lt_of_gauge_lt absorbs,\n    \u03bb \u27e8r, hr\u2080, hr\u2081, hx\u27e9, (gauge_le_of_mem hr\u2080.le hx).trans_lt hr\u2081\u27e9,\nend\n\nlemma gauge_lt_eq (absorbs : absorbent \u211d s) (a : \u211d) :\n  {x | gauge s x < a} = \u22c3 (r \u2208 set.Ioo 0 (a : \u211d)), r \u2022 s :=\nbegin\n  ext,\n  simp_rw [mem_set_of_eq, mem_Union, exists_prop, mem_Ioo, and_assoc],\n  exact \u27e8exists_lt_of_gauge_lt absorbs,\n    \u03bb \u27e8r, hr\u2080, hr\u2081, hx\u27e9, (gauge_le_of_mem hr\u2080.le hx).trans_lt hr\u2081\u27e9,\nend\n\nlemma gauge_lt_one_subset_self (hs : convex \u211d s) (h\u2080 : (0 : E) \u2208 s) (absorbs : absorbent \u211d s) :\n  {x | gauge s x < 1} \u2286 s :=\nbegin\n  rw gauge_lt_eq absorbs,\n  refine set.Union\u2082_subset (\u03bb r hr _, _),\n  rintro \u27e8y, hy, rfl\u27e9,\n  exact hs.smul_mem_of_zero_mem h\u2080 hy (Ioo_subset_Icc_self hr),\nend\n\nlemma gauge_le_one_of_mem {x : E} (hx : x \u2208 s) : gauge s x \u2264 1 :=\ngauge_le_of_mem zero_le_one $ by rwa one_smul\n\nlemma self_subset_gauge_le_one : s \u2286 {x | gauge s x \u2264 1} := \u03bb x, gauge_le_one_of_mem\n\nlemma convex.gauge_le (hs : convex \u211d s) (h\u2080 : (0 : E) \u2208 s) (absorbs : absorbent \u211d s) (a : \u211d) :\n  convex \u211d {x | gauge s x \u2264 a} :=\nbegin\n  by_cases ha : 0 \u2264 a,\n  { rw gauge_le_eq hs h\u2080 absorbs ha,\n    exact convex_Inter (\u03bb i, convex_Inter (\u03bb hi, hs.smul _)) },\n  { convert convex_empty,\n    exact eq_empty_iff_forall_not_mem.2 (\u03bb x hx, ha $ (gauge_nonneg _).trans hx) }\nend\n\nlemma balanced.star_convex (hs : balanced \u211d s) : star_convex \u211d 0 s :=\nstar_convex_zero_iff.2 $ \u03bb x hx a ha\u2080 ha\u2081,\n  hs _ (by rwa real.norm_of_nonneg ha\u2080) (smul_mem_smul_set hx)\n\nlemma le_gauge_of_not_mem (hs\u2080 : star_convex \u211d 0 s) (hs\u2082 : absorbs \u211d s {x}) (hx : x \u2209 a \u2022 s) :\n  a \u2264 gauge s x :=\nbegin\n  rw star_convex_zero_iff at hs\u2080,\n  obtain \u27e8r, hr, h\u27e9 := hs\u2082,\n  refine le_cInf \u27e8r, hr, singleton_subset_iff.1 $ h _ (real.norm_of_nonneg hr.le).ge\u27e9 _,\n  rintro b \u27e8hb, x, hx', rfl\u27e9,\n  refine not_lt.1 (\u03bb hba, hx _),\n  have ha := hb.trans hba,\n  refine \u27e8(a\u207b\u00b9 * b) \u2022 x, hs\u2080 hx' (mul_nonneg (inv_nonneg.2 ha.le) hb.le) _, _\u27e9,\n  { rw \u2190div_eq_inv_mul,\n    exact div_le_one_of_le hba.le ha.le },\n  { rw [\u2190mul_smul, mul_inv_cancel_left\u2080 ha.ne'] }\nend\n\nlemma one_le_gauge_of_not_mem (hs\u2081 : star_convex \u211d 0 s) (hs\u2082 : absorbs \u211d s {x}) (hx : x \u2209 s) :\n  1 \u2264 gauge s x :=\nle_gauge_of_not_mem hs\u2081 hs\u2082 $ by rwa one_smul\n\nsection linear_ordered_field\nvariables {\u03b1 : Type*} [linear_ordered_field \u03b1] [mul_action_with_zero \u03b1 \u211d] [ordered_smul \u03b1 \u211d]\n\nlemma gauge_smul_of_nonneg [mul_action_with_zero \u03b1 E] [is_scalar_tower \u03b1 \u211d (set E)] {s : set E}\n  {a : \u03b1} (ha : 0 \u2264 a) (x : E) :\n  gauge s (a \u2022 x) = a \u2022 gauge s x :=\nbegin\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul, gauge_zero, zero_smul] },\n  rw [gauge_def', gauge_def', \u2190real.Inf_smul_of_nonneg ha],\n  congr' 1,\n  ext r,\n  simp_rw [set.mem_smul_set, set.mem_sep_eq],\n  split,\n  { rintro \u27e8hr, hx\u27e9,\n    simp_rw mem_Ioi at \u22a2 hr,\n    rw \u2190mem_smul_set_iff_inv_smul_mem\u2080 hr.ne' at hx,\n    have := smul_pos (inv_pos.2 ha') hr,\n    refine \u27e8a\u207b\u00b9 \u2022 r, \u27e8this, _\u27e9, smul_inv_smul\u2080 ha'.ne' _\u27e9,\n    rwa [\u2190mem_smul_set_iff_inv_smul_mem\u2080 this.ne', smul_assoc,\n      mem_smul_set_iff_inv_smul_mem\u2080 (inv_ne_zero ha'.ne'), inv_inv] },\n  { rintro \u27e8r, \u27e8hr, hx\u27e9, rfl\u27e9,\n    rw mem_Ioi at \u22a2 hr,\n    rw \u2190mem_smul_set_iff_inv_smul_mem\u2080 hr.ne' at hx,\n    have := smul_pos ha' hr,\n    refine \u27e8this, _\u27e9,\n    rw [\u2190mem_smul_set_iff_inv_smul_mem\u2080 this.ne', smul_assoc],\n    exact smul_mem_smul_set hx }\nend\n\n/-- In textbooks, this is the homogeneity of the Minkowksi functional. -/\nlemma gauge_smul [module \u03b1 E] [is_scalar_tower \u03b1 \u211d (set E)] {s : set E}\n  (symmetric : \u2200 x \u2208 s, -x \u2208 s) (r : \u03b1) (x : E) :\n  gauge s (r \u2022 x) = abs r \u2022 gauge s x :=\nbegin\n  rw \u2190gauge_smul_of_nonneg (abs_nonneg r),\n  obtain h | h := abs_choice r,\n  { rw h },\n  { rw [h, neg_smul, gauge_neg symmetric] },\n  { apply_instance }\nend\n\nlemma gauge_smul_left_of_nonneg [mul_action_with_zero \u03b1 E] [smul_comm_class \u03b1 \u211d \u211d]\n  [is_scalar_tower \u03b1 \u211d \u211d] [is_scalar_tower \u03b1 \u211d E] {s : set E} {a : \u03b1} (ha : 0 \u2264 a) :\n  gauge (a \u2022 s) = a\u207b\u00b9 \u2022 gauge s :=\nbegin\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_subset _)] },\n  ext,\n  rw [gauge_def', pi.smul_apply, gauge_def', \u2190real.Inf_smul_of_nonneg (inv_nonneg.2 ha)],\n  congr' 1,\n  ext r,\n  simp_rw [set.mem_smul_set, set.mem_sep_eq],\n  split,\n  { rintro \u27e8hr, y, hy, h\u27e9,\n    simp_rw [mem_Ioi] at \u22a2 hr,\n    refine \u27e8a \u2022 r, \u27e8smul_pos ha' hr, _\u27e9, inv_smul_smul\u2080 ha'.ne' _\u27e9,\n    rwa [smul_inv\u2080, smul_assoc, \u2190h, inv_smul_smul\u2080 ha'.ne'] },\n  { rintro \u27e8r, \u27e8hr, hx\u27e9, rfl\u27e9,\n    rw mem_Ioi at \u22a2 hr,\n    have := smul_pos ha' hr,\n    refine \u27e8smul_pos (inv_pos.2 ha') hr, r\u207b\u00b9 \u2022 x, hx, _\u27e9,\n    rw [smul_inv\u2080, smul_assoc, inv_inv] }\nend\n\nlemma gauge_smul_left [module \u03b1 E] [smul_comm_class \u03b1 \u211d \u211d] [is_scalar_tower \u03b1 \u211d \u211d]\n  [is_scalar_tower \u03b1 \u211d E] {s : set E} (symmetric : \u2200 x \u2208 s, -x \u2208 s) (a : \u03b1) :\n  gauge (a \u2022 s) = |a|\u207b\u00b9 \u2022 gauge s :=\nbegin\n  rw \u2190gauge_smul_left_of_nonneg (abs_nonneg a),\n  obtain h | h := abs_choice a,\n  { rw h },\n  { rw [h, set.neg_smul_set, \u2190set.smul_set_neg],\n    congr,\n    ext y,\n    refine \u27e8symmetric _, \u03bb hy, _\u27e9,\n    rw \u2190neg_neg y,\n    exact symmetric _ hy },\n  { apply_instance }\nend\n\nend linear_ordered_field\n\nsection topological_space\nvariables [topological_space E] [has_continuous_smul \u211d E]\n\nlemma interior_subset_gauge_lt_one (s : set E) : interior s \u2286 {x | gauge s x < 1} :=\nbegin\n  intros x hx,\n  let f : \u211d \u2192 E := \u03bb t, t \u2022 x,\n  have hf : continuous f,\n  { continuity },\n  let s' := f \u207b\u00b9' (interior s),\n  have hs' : is_open s' := hf.is_open_preimage _ is_open_interior,\n  have one_mem : (1 : \u211d) \u2208 s',\n  { simpa only [s', f, set.mem_preimage, one_smul] },\n  obtain \u27e8\u03b5, h\u03b5\u2080, h\u03b5\u27e9 := (metric.nhds_basis_closed_ball.1 _).1\n    (is_open_iff_mem_nhds.1 hs' 1 one_mem),\n  rw real.closed_ball_eq_Icc at h\u03b5,\n  have h\u03b5\u2081 : 0 < 1 + \u03b5 := h\u03b5\u2080.trans (lt_one_add \u03b5),\n  have : (1 + \u03b5)\u207b\u00b9 < 1,\n  { rw inv_lt_one_iff,\n    right,\n    linarith },\n  refine (gauge_le_of_mem (inv_nonneg.2 h\u03b5\u2081.le) _).trans_lt this,\n  rw mem_inv_smul_set_iff\u2080 h\u03b5\u2081.ne',\n  exact interior_subset\n    (h\u03b5 \u27e8(sub_le_self _ h\u03b5\u2080.le).trans ((le_add_iff_nonneg_right _).2 h\u03b5\u2080.le), le_rfl\u27e9),\nend\n\nlemma gauge_lt_one_eq_self_of_open (hs\u2081 : convex \u211d s) (hs\u2080 : (0 : E) \u2208 s) (hs\u2082 : is_open s) :\n  {x | gauge s x < 1} = s :=\nbegin\n  refine (gauge_lt_one_subset_self hs\u2081 \u2039_\u203a $ absorbent_nhds_zero $ hs\u2082.mem_nhds hs\u2080).antisymm _,\n  convert interior_subset_gauge_lt_one s,\n  exact hs\u2082.interior_eq.symm,\nend\n\nlemma gauge_lt_one_of_mem_of_open (hs\u2081 : convex \u211d s) (hs\u2080 : (0 : E) \u2208 s) (hs\u2082 : is_open s)\n  {x : E} (hx : x \u2208 s) :\n  gauge s x < 1 :=\nby rwa \u2190gauge_lt_one_eq_self_of_open hs\u2081 hs\u2080 hs\u2082 at hx\n\nlemma gauge_lt_of_mem_smul (x : E) (\u03b5 : \u211d) (h\u03b5 : 0 < \u03b5) (hs\u2080 : (0 : E) \u2208 s)\n  (hs\u2081 : convex \u211d s) (hs\u2082 : is_open s) (hx : x \u2208 \u03b5 \u2022 s) :\n  gauge s x < \u03b5 :=\nbegin\n  have : \u03b5\u207b\u00b9 \u2022 x \u2208 s,\n  { rwa \u2190mem_smul_set_iff_inv_smul_mem\u2080 h\u03b5.ne' },\n  have h_gauge_lt := gauge_lt_one_of_mem_of_open hs\u2081 hs\u2080 hs\u2082 this,\n  rwa [gauge_smul_of_nonneg (inv_nonneg.2 h\u03b5.le), smul_eq_mul, inv_mul_lt_iff h\u03b5, mul_one]\n    at h_gauge_lt,\n  apply_instance\nend\n\nend topological_space\n\nlemma gauge_add_le (hs : convex \u211d s) (absorbs : absorbent \u211d s) (x y : E) :\n  gauge s (x + y) \u2264 gauge s x + gauge s y :=\nbegin\n  refine le_of_forall_pos_lt_add (\u03bb \u03b5 h\u03b5, _),\n  obtain \u27e8a, ha, ha', hx\u27e9 := exists_lt_of_gauge_lt absorbs\n    (lt_add_of_pos_right (gauge s x) (half_pos h\u03b5)),\n  obtain \u27e8b, hb, hb', hy\u27e9 := exists_lt_of_gauge_lt absorbs\n    (lt_add_of_pos_right (gauge s y) (half_pos h\u03b5)),\n  rw mem_smul_set_iff_inv_smul_mem\u2080 ha.ne' at hx,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hb.ne' at hy,\n  suffices : gauge s (x + y) \u2264 a + b,\n  { linarith },\n  have hab : 0 < a + b := add_pos ha hb,\n  apply gauge_le_of_mem hab.le,\n  have := convex_iff_div.1 hs hx hy ha.le hb.le hab,\n  rwa [smul_smul, smul_smul, mul_comm_div', mul_comm_div', \u2190mul_div_assoc, \u2190mul_div_assoc,\n    mul_inv_cancel ha.ne', mul_inv_cancel hb.ne', \u2190smul_add, one_div,\n    \u2190mem_smul_set_iff_inv_smul_mem\u2080 hab.ne'] at this,\nend\n\n/-- `gauge s` as a seminorm when `s` is symmetric, convex and absorbent. -/\n@[simps] def gauge_seminorm (hs\u2080 : \u2200 x \u2208 s, -x \u2208 s) (hs\u2081 : convex \u211d s) (hs\u2082 : absorbent \u211d s) :\n  seminorm \u211d E :=\n{ to_fun := gauge s,\n  smul' := \u03bb r x, by rw [gauge_smul hs\u2080, real.norm_eq_abs, smul_eq_mul]; apply_instance,\n  triangle' := gauge_add_le hs\u2081 hs\u2082 }\n\nsection gauge_seminorm\nvariables {hs\u2080 : \u2200 x \u2208 s, -x \u2208 s} {hs\u2081 : convex \u211d s} {hs\u2082 : absorbent \u211d s}\n\nsection topological_space\nvariables [topological_space E] [has_continuous_smul \u211d E]\n\nlemma gauge_seminorm_lt_one_of_open (hs : is_open s) {x : E} (hx : x \u2208 s) :\n  gauge_seminorm hs\u2080 hs\u2081 hs\u2082 x < 1 :=\ngauge_lt_one_of_mem_of_open hs\u2081 hs\u2082.zero_mem hs hx\n\nend topological_space\nend gauge_seminorm\n\n/-- Any seminorm arises as the gauge of its unit ball. -/\n@[simp] protected lemma seminorm.gauge_ball (p : seminorm \u211d E) : gauge (p.ball 0 1) = p :=\nbegin\n  ext,\n  obtain hp | hp := {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 p.ball 0 1}.eq_empty_or_nonempty,\n  { rw [gauge, hp, real.Inf_empty],\n    by_contra,\n    have hpx : 0 < p x := (p.nonneg x).lt_of_ne h,\n    have hpx\u2082 : 0 < 2 * p x := mul_pos zero_lt_two hpx,\n    refine hp.subset \u27e8hpx\u2082, (2 * p x)\u207b\u00b9 \u2022 x, _, smul_inv_smul\u2080 hpx\u2082.ne' _\u27e9,\n    rw [p.mem_ball_zero, p.smul, real.norm_eq_abs, abs_of_pos (inv_pos.2 hpx\u2082), inv_mul_lt_iff hpx\u2082,\n      mul_one],\n    exact lt_mul_of_one_lt_left hpx one_lt_two },\n  refine is_glb.cInf_eq \u27e8\u03bb r, _, \u03bb r hr, le_of_forall_pos_le_add $ \u03bb \u03b5 h\u03b5, _\u27e9 hp,\n  { rintro \u27e8hr, y, hy, rfl\u27e9,\n    rw p.mem_ball_zero at hy,\n    rw [p.smul, real.norm_eq_abs, abs_of_pos hr],\n    exact mul_le_of_le_one_right hr.le hy.le },\n  { have hp\u03b5 : 0 < p x + \u03b5 := add_pos_of_nonneg_of_pos (p.nonneg _) h\u03b5,\n    refine hr \u27e8hp\u03b5, (p x + \u03b5)\u207b\u00b9 \u2022 x, _, smul_inv_smul\u2080 hp\u03b5.ne' _\u27e9,\n    rw [p.mem_ball_zero, p.smul, real.norm_eq_abs, abs_of_pos (inv_pos.2 hp\u03b5), inv_mul_lt_iff hp\u03b5,\n      mul_one],\n    exact lt_add_of_pos_right _ h\u03b5 }\nend\n\nlemma seminorm.gauge_seminorm_ball (p : seminorm \u211d E) :\n  gauge_seminorm (\u03bb x, p.symmetric_ball_zero 1) (p.convex_ball 0 1)\n    (p.absorbent_ball_zero zero_lt_one) = p := fun_like.coe_injective p.gauge_ball\n\nend add_comm_group\n\nsection norm\nvariables [semi_normed_group E] [normed_space \u211d E] {s : set E} {r : \u211d} {x : E}\n\nlemma gauge_unit_ball (x : E) : gauge (metric.ball (0 : E) 1) x = \u2225x\u2225 :=\nbegin\n  obtain rfl | hx := eq_or_ne x 0,\n  { rw [norm_zero, gauge_zero] },\n  refine (le_of_forall_pos_le_add $ \u03bb \u03b5 h\u03b5, _).antisymm _,\n  { have := add_pos_of_nonneg_of_pos (norm_nonneg x) h\u03b5,\n    refine gauge_le_of_mem this.le _,\n    rw [smul_ball this.ne', smul_zero, real.norm_of_nonneg this.le, mul_one, mem_ball_zero_iff],\n    exact lt_add_of_pos_right _ h\u03b5 },\n  refine le_gauge_of_not_mem balanced_ball_zero.star_convex\n    (absorbent_ball_zero zero_lt_one).absorbs (\u03bb h, _),\n  obtain hx' | hx' := eq_or_ne (\u2225x\u2225) 0,\n  { rw hx' at h,\n    exact hx (zero_smul_subset _ h) },\n  { rw [mem_smul_set_iff_inv_smul_mem\u2080 hx', mem_ball_zero_iff, norm_smul, norm_inv, norm_norm,\n      inv_mul_cancel hx'] at h,\n    exact lt_irrefl _ h }\nend\n\nlemma gauge_ball (hr : 0 < r) (x : E) : gauge (metric.ball (0 : E) r) x = \u2225x\u2225 / r :=\nbegin\n  rw [\u2190smul_unit_ball_of_pos hr, gauge_smul_left, pi.smul_apply, gauge_unit_ball, smul_eq_mul,\n    abs_of_nonneg hr.le, div_eq_inv_mul],\n  simp_rw [mem_ball_zero_iff, norm_neg],\n  exact \u03bb _, id,\nend\n\nlemma mul_gauge_le_norm (hs : metric.ball (0 : E) r \u2286 s) : r * gauge s x \u2264 \u2225x\u2225 :=\nbegin\n  obtain hr | hr := le_or_lt r 0,\n  { exact (mul_nonpos_of_nonpos_of_nonneg hr $ gauge_nonneg _).trans (norm_nonneg _) },\n  rw [mul_comm, \u2190le_div_iff hr, \u2190gauge_ball hr],\n  exact gauge_mono (absorbent_ball_zero hr) hs x,\nend\n\nend norm\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/convex/gauge.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436727, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7156497516194174}}
{"text": "\n-- use hints --hide\n/-\n## The setup\nWelcome to Lean! You should see a different windows on this page, they will contain part of using Lean,\nlets go through them one-by-one.\n\nThe middle one is where you tell Lean what steps you want to make in your proof.\nBy typing statements here in precise language we instruct Lean how we want the proof to go.\nRight now this text is frozen, but at the bottom you will be able to type your first Lean\nproof.\n\n**Scroll down now and delete the word sorry from the box at the very bottom** this will\nactivate Lean for you so we can introduce the different components.\n**Then scroll back up and carry on reading from here**.\n\nOn the right hand side you can see a window with `goal` at the top.\nThis panel represents what Lean thinks the current state of your proof is, most importantly\nthe facts and hypothesis you already know, and the statement (or statements) you are trying to show, these come after\nthe `\u22a2` symbol to make it clear which is which.\nFor example a valid state might look like\n```\nn : \u2115\nh : is_even n\n\u22a2 is_odd (n + 1)\n```\nwhich means that we have assumed `n` is a natural number and that `n` is even, and we are trying to show that `n + 1` is\nodd.\nIn order to prove this we will need to use more than what is written here however, we might need the definition of\nan even and an odd number, so in addition to the current hypotheses we also will make use of a library of lemmas that\nwe have proved so far.\n\nBelow this there will be more information about the word your cursor is currently on, and feedback about any errors\nin your current proof.\nAs you move your cursor around by clicking different parts of the proof the goal will update, we can\nalways step backwards and forwards through the proof using the arrow keys to check what we were\nproving before.\nIf you write some syntax Lean doesn't understand, or a proof step that doesn't make sense, Lean will\nreturn an error in the bottom right, the most common error being `tactic failed, there are unsolved goals`\nwhich just means that you aren't finished with the proof yet!\n\nOn the left of the screen you will find a list of *theorems* and *tactics* you can use to prove\nresults, this is here to remind you the things we've talked about so far.\n\nLet's now discuss the language Lean uses to represent statements.\n\n## The language\n\nA lemma in Lean is written using a specific syntax, that is designed to look similar to written\nmathematics, but is more restricted in how statements can be constructed.\nHere is an example of a lemma statement in Lean:\n-/\n\nnamespace boop --hide\nlemma add_comm : \u2200 (x : \u2115) (y : \u2115), x + y = y + x\n:= nat.add_comm --hide\n\n/-\nThis lemma states that for all natural numbers `x` and `y` that addition of `x` and `y` commutes,\nhopefully you agree that this is a straightforward, but very useful fact!\nNote the first word `lemma` is a keyword (highlighted in blue) and means we are stating a new\nlemma.\nThe second word is simply a name we give to the lemma so we can refer to it later, naming lemmas\nworks much better than numbering lemmas when you need to refer back to many things.\nThis is especially helpful if you give the lemmas sensible names, so that you can remember them\nlater, and so that when you use them you can tell what the lemma does from its name.\nIn this case `add_comm` says that addition is commutative, so it seems like a pretty good choice.\n\nThe symbol `:` is used to say that `x` and `y` are natural numbers, this is similar to how we\nnormally write `x \u2208 \u2115`, and you should think of `:` as meaning `\u2208`.\nThe symbol `:` is also used after the name of the lemma, and it has the same meaning!\nHere within the lemma `x : \u2115` gives a name to a natural number and\n`add_comm : \u2200 x y, x + y = y + x` gives a name to the statement that addition is commutative.\n\nThe lemma `add_comm` is a \"for all\" statement, so in order to get the statement that addition\ncommutes for a _specific_ pair of natural numbers rather than variables `x` and `y`,\nwe place the naturals we want to refer to after the name,\nfor instance `add_comm 2 3` means `2 + 3 = 3 + 2`.\nHere we used 2 and 3, but we could apply this lemma with variables too by using their names\ninstead of 2 and 3.\n\n\n### Rewriting\nRewriting is one of the most basic methods of proof, we substitute one object we know equals another\ninside what we want to prove, by doing this we can get closer to something that we already know to\nbe true,\nor get to a point where things cancel out or simplify.\n\nFor example if `h` is a name for the fact that `X = Y`, then `rewrite h,` will change\nall `X`s in the goal to `Y`s (the comma at the end is important, it tells Lean you are done\nwith one step of your proof).\nOn the left hand side in the tactics panel there is a dropdown with a lot more details about\n`rewrite`, you don't need to read it now, but it's there if you ever want to check the syntax\nagain.\n\nNow try to use a sequence of `rewrite` steps to prove the lemma below by typing them into the box\nunderneath, between the `begin` and `end` lines that tell Lean you are starting and finishing a\nproof.\n\n-/\n\n/- Tactic : rewrite\n## Summary\n\nIf `h` is a proof of `X = Y`, then `rewrite h,` will change\nall `X`s in the goal to `Y`s.\n\nAs this is such a common proof step we also have a short name, `rw` instead of `rewrite` for this\nstep, to save us from too much typing.\n\nVariants: `rw \u2190 h` (type `\u2190` using `\\l` for left) changes\n`Y` to `X` and\n`rw h at h2` changes `X` to `Y` in hypothesis `h2` instead\nof the goal.\n\n## Details\n\nThe `rw` tactic is a way to do \"substituting in\". There\nare two distinct situations where use this tactics.\n\n1) If `h : A = B` is a hypothesis (i.e., a proof of `A = B`)\nin your local context (the box in the top right)\nand if your goal contains one or more `A`s, then `rw h`\nwill change them all to `B`'s.\n\n2) The `rw` tactic will also work with proofs of theorems\nwhich are equalities (look for them in the drop down\nmenu on the left, within Theorem Statements).\n\nImportant note: if `h` is not a proof of the form `A = B`\nor `A \u2194 B` (for example if `h` is a function, an implication,\nor perhaps even a proposition itself rather than its proof),\nthen `rw` is not the tactic you want to use. For example,\n`rw (P = Q)` is never correct: `P = Q` is the true-false\nstatement itself, not the proof.\nIf `h : P = Q` is its proof, then `rw h` will work.\n\nPro tip 1: If `h : A = B` and you want to change\n`B`s to `A`s instead, try `rw \u2190h` (get the arrow with `\\l`,\nnote that this is a small letter L, not a number 1).\n\n### Example:\nIf it looks like this in the top right hand box:\n```\nA B C : set X\nh : A = B \u222a C\n\u22a2 A \u222a B = B \u222a C\n```\n\nthen\n\n`rw h,`\n\nwill change the goal into `\u22a2 B \u222a C \u222a B = B \u222a C`.\n\n### Example:\nYou can use `rw` to change a hypothesis as well.\nFor example, if your local context looks like this:\n```\nA B C D : set X\nh1 : A = B \u2229 C\nh2 : B \u222a A = D\n\u22a2 D = B\n```\nthen `rw h1 at h2` will turn `h2` into `h2 : B \u222a B \u2229 C = D` (remember operator precedence).-/\n\n/- Axiom : The commutativity of addition\nadd_comm : \u2200 x y, x + y = y + x\n-/\n\n\n/- Hint : Click here for a hint, in case you get stuck.\nDelete `sorry` and type `rewrite add_comm x y,` (don't forget the comma!).\nThat is the first step of the proof, after typing the comma you should see the goal (on the right)\nchange so the sides of the equation look closer to each other.\nThe next two steps of the proof go on the next lines, and are similar to the first, can you work\nthem out?\n-/\n\n/- Lemma : no-side-bar\n-/\nlemma level1 (x y z w : \u2115) : x + y + (z + w) = (w + z) + (y + x) :=\nbegin\n  rw add_comm x y,\n  rw add_comm w z,\n  rw add_comm,\n\n\n\n\n\n\n\nend\nend boop --hide\n", "meta": {"author": "alexjbest", "repo": "CAP-game", "sha": "d823def7325d7142d61e766b2e027f936685a8ff", "save_path": "github-repos/lean/alexjbest-CAP-game", "path": "github-repos/lean/alexjbest-CAP-game/CAP-game-d823def7325d7142d61e766b2e027f936685a8ff/src/intro/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7156185940970679}}
{"text": "theorem add_le_add_right {a b : mynat} : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) :=\nbegin\nintro h,\nintro t,\ninduction t with d hd,\nrw add_zero,\nrw add_zero,\nexact h,\nrw add_succ,\nrw add_succ,\napply succ_le_succ,\nexact hd,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world10/level11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7155970665768887}}
{"text": "import algebra.group.basic\nimport tactic\nimport group_theory.subgroup.basic\nimport data.set_like.basic\nimport chapter2.set_theory_cosets\n\nvariables {A:Type} [has_mul A]\n\ndefinition normalizes (a:A) (S:set A) : Prop := lcoset (A) (a) (S) = rcoset (A) (S) (a)\n\ndefinition is_normal (S: set A) : Prop := \u2200a, normalizes a S\n\ndefinition normalizer (S : set A) : set A := { a : A | normalizes a S} --this definition will also work for subgroups! \n\ndefinition is_normal_in (S T : set A) : Prop := T \u2286 normalizer S\n\nlemma lcoset_eq_rcoset (a : A) (S : set A) (H : is_normal S) : lcoset (A) (a) (S) = rcoset (A) (S) (a) :=\nbegin\nunfold is_normal at H, specialize H a, exact H,\nend --this helps get a feel for these new definitions. \n\nlemma lcoset_eq_rcoset_of_mem {a:A} (S:set A) {T:set A} (H : is_normal_in S T) (amemT : a \u2208 T) : lcoset (A) (a) (S) = rcoset (A) (S) (a) :=\nbegin\nunfold is_normal_in at H, specialize H amemT, exact H, --was curious if lean would understand this.\nend\n\n\n\n\n", "meta": {"author": "jam-1057", "repo": "dummit_and_foote_lean", "sha": "1d910d38cad9f2cbb3160d3947d116e93f2a1f14", "save_path": "github-repos/lean/jam-1057-dummit_and_foote_lean", "path": "github-repos/lean/jam-1057-dummit_and_foote_lean/dummit_and_foote_lean-1d910d38cad9f2cbb3160d3947d116e93f2a1f14/src/chapter2/set_theory_normal_cosets_and_normalizer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.715597054236795}}
{"text": "-- Razonamiento_sobre_arboles_binarios_Aplanamiento_e_imagen_especular.lean\n-- Razonamiento sobre \u00e1rboles binarios: Aplanamiento e imagen especular\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 13 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- El \u00e1rbol correspondiente a\n--        3\n--       / \\\n--      2   4\n--     / \\\n--    1   5\n-- se puede representar por el t\u00e9rmino\n--    nodo 3 (nodo 2 (hoja 1) (hoja 5)) (hoja 4)\n-- usando el tipo de dato arbol definido por\n--    inductive arbol (\u03b1 : Type) : Type\n--    | hoja : \u03b1 \u2192 arbol\n--    | nodo : \u03b1 \u2192 arbol \u2192 arbol \u2192 arbol\n--\n-- La imagen especular del \u00e1rbol anterior es\n--      3\n--     / \\\n--    4   2\n--       / \\\n--      5   1\n-- y la lista obtenida aplan\u00e1ndolo (recorri\u00e9ndolo en orden infijo) es\n--    [4, 3, 5, 2, 1]\n--\n-- La definici\u00f3n de la funci\u00f3n que calcula la imagen especular es\n--    def espejo : arbol \u03b1 \u2192 arbol \u03b1\n--    | (hoja x)     := hoja x\n--    | (nodo x i d) := nodo x (espejo d) (espejo i)\n-- y la que aplana el \u00e1rbol es\n--    def aplana : arbol \u03b1 \u2192 list \u03b1\n--    | (hoja x)     := [x]\n--    | (nodo x i d) := (aplana i) ++ [x] ++ (aplana d)\n--\n-- Demostrar que\n--    aplana (espejo a) = rev (aplana a)\n-- ---------------------------------------------------------------------\n\nimport tactic\nopen list\n\nvariable {\u03b1 : Type}\n\n-- Para que no use la notaci\u00f3n con puntos\nset_option pp.structure_projections false\n\ninductive arbol (\u03b1 : Type) : Type\n| hoja : \u03b1 \u2192 arbol\n| nodo : \u03b1 \u2192 arbol \u2192 arbol \u2192 arbol\n\nnamespace arbol\n\nvariables (a i d : arbol \u03b1)\nvariable  (x : \u03b1)\n\ndef espejo : arbol \u03b1 \u2192 arbol \u03b1\n| (hoja x)     := hoja x\n| (nodo x i d) := nodo x (espejo d) (espejo i)\n\n@[simp]\nlemma espejo_1 :\n  espejo (hoja x) = hoja x :=\nrfl\n\n@[simp]\nlemma espejo_2 :\n  espejo (nodo x i d) = nodo x (espejo d) (espejo i) :=\nrfl\n\ndef aplana : arbol \u03b1 \u2192 list \u03b1\n| (hoja x)     := [x]\n| (nodo x i d) := (aplana i) ++ [x] ++ (aplana d)\n\n@[simp]\nlemma aplana_1 :\n  aplana (hoja x) = [x] :=\nrfl\n\n@[simp]\nlemma aplana_2 :\n  aplana (nodo x i d) = (aplana i) ++ [x] ++ (aplana d) :=\nrfl\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\nbegin\n  induction a with x x i d Hi Hd,\n  { rw espejo_1,\n    rw aplana_1,\n    rw reverse_singleton, },\n  { rw espejo_2,\n    rw aplana_2,\n    rw [Hi, Hd],\n    rw aplana_2,\n    rw reverse_append,\n    rw reverse_append,\n    rw reverse_singleton,\n    rw append_assoc, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\nbegin\n  induction a with x x i d Hi Hd,\n  { calc aplana (espejo (hoja x))\n         = aplana (hoja x)\n             : congr_arg aplana (espejo_1 x)\n     ... = [x]\n             : aplana_1 x\n     ... = reverse [x]\n             : reverse_singleton x\n     ... = reverse (aplana (hoja x))\n             : congr_arg reverse (aplana_1 x).symm, },\n  { calc aplana (espejo (nodo x i d))\n         = aplana (nodo x (espejo d) (espejo i))\n             : congr_arg aplana (espejo_2 i d x)\n     ... = (aplana (espejo d) ++ [x]) ++ aplana (espejo i)\n             : aplana_2 (espejo d) (espejo i) x\n     ... = (reverse (aplana d) ++ [x]) ++ aplana (espejo i)\n             : congr_arg2 (++) (congr_arg2 (++) Hd rfl) rfl\n     ... = (reverse (aplana d) ++ [x]) ++ reverse (aplana i)\n             : congr_arg2 (++) rfl Hi\n     ... = (reverse (aplana d) ++ reverse [x]) ++ reverse (aplana i)\n             : congr_arg2 (++) (congr_arg2 (++) rfl (reverse_singleton x).symm) rfl\n     ... = reverse ([x] ++ aplana d) ++ reverse (aplana i)\n             : congr_arg2 (++) (reverse_append [x] (aplana d)).symm rfl\n     ... = reverse (aplana i ++ ([x] ++ aplana d))\n             : (reverse_append (aplana i) ([x] ++ aplana d)).symm\n     ... = reverse ((aplana i ++ [x]) ++ aplana d)\n             : congr_arg reverse (append_assoc (aplana i) [x] (aplana d)).symm\n     ... = reverse (aplana (nodo x i d))\n             : congr_arg reverse (aplana_2 i d x), },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\nbegin\n  induction a with x x i d Hi Hd,\n  { calc aplana (espejo (hoja x))\n         = aplana (hoja x)\n             : by simp only [espejo_1]\n     ... = [x]\n             : by rw aplana_1\n     ... = reverse [x]\n             : by rw reverse_singleton\n     ... = reverse (aplana (hoja x))\n             : by simp only [aplana_1], },\n  { calc aplana (espejo (nodo x i d))\n         = aplana (nodo x (espejo d) (espejo i))\n             : by simp only [espejo_2]\n     ... = aplana (espejo d) ++ [x] ++ aplana (espejo i)\n             : by rw aplana_2\n     ... = reverse (aplana d) ++ [x] ++ reverse (aplana i)\n             : by rw [Hi, Hd]\n     ... = reverse (aplana d) ++ reverse [x] ++ reverse (aplana i)\n             : by simp only [reverse_singleton]\n     ... = reverse ([x] ++ aplana d) ++ reverse (aplana i)\n             : by simp only [reverse_append]\n     ... = reverse (aplana i ++ ([x] ++ aplana d))\n             : by simp only [reverse_append]\n     ... = reverse (aplana i ++ [x] ++ aplana d)\n             : by simp only [append_assoc]\n     ... = reverse (aplana (nodo x i d))\n             : by simp only [aplana_2], },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\nbegin\n  induction a with x x i d Hi Hd,\n  { calc aplana (espejo (hoja x))\n         = aplana (hoja x)           : by simp\n     ... = [x]                       : by simp\n     ... = reverse [x]               : by simp\n     ... = reverse (aplana (hoja x)) : by simp, },\n  { calc aplana (espejo (nodo x i d))\n         = aplana (nodo x (espejo d) (espejo i))\n             : by simp\n     ... = aplana (espejo d) ++ [x] ++ aplana (espejo i)\n             : by simp\n     ... = reverse (aplana d) ++ [x] ++ reverse (aplana i)\n             : by simp [Hi, Hd]\n     ... = reverse (aplana d) ++ reverse [x] ++ reverse (aplana i)\n             : by simp\n     ... = reverse ([x] ++ aplana d) ++ reverse (aplana i)\n             : by simp\n     ... = reverse (aplana i ++ ([x] ++ aplana d))\n             : by simp\n     ... = reverse (aplana i ++ [x] ++ aplana d)\n             : by simp\n     ... = reverse (aplana (nodo x i d))\n             : by simp },\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\nbegin\n  induction a with x x i d Hi Hd,\n  { simp, },\n  { calc aplana (espejo (nodo x i d))\n         = reverse (aplana d) ++ [x] ++ reverse (aplana i)\n             : by simp [Hi, Hd]\n     ... = reverse (aplana (nodo x i d))\n             : by simp },\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\nbegin\n  induction a with x x i d Hi Hd,\n  { simp, },\n  { simp [Hi, Hd], },\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\nby induction a ; simp [*]\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\narbol.rec_on a\n  ( assume x,\n    calc aplana (espejo (hoja x))\n         = aplana (hoja x)\n             : by simp only [espejo_1]\n     ... = [x]\n             : by rw aplana_1\n     ... = reverse [x]\n             : by rw reverse_singleton\n     ... = reverse (aplana (hoja x))\n             : by simp only [aplana_1])\n  ( assume x i d,\n    assume Hi : aplana (espejo i) = reverse (aplana i),\n    assume Hd : aplana (espejo d) = reverse (aplana d),\n    calc aplana (espejo (nodo x i d))\n         = aplana (nodo x (espejo d) (espejo i))\n             : by simp only [espejo_2]\n     ... = aplana (espejo d) ++ [x] ++ aplana (espejo i)\n             : by rw aplana_2\n     ... = reverse (aplana d) ++ [x] ++ reverse (aplana i)\n             : by rw [Hi, Hd]\n     ... = reverse (aplana d) ++ reverse [x] ++ reverse (aplana i)\n             : by simp only [reverse_singleton]\n     ... = reverse ([x] ++ aplana d) ++ reverse (aplana i)\n             : by simp only [reverse_append]\n     ... = reverse (aplana i ++ ([x] ++ aplana d))\n             : by simp only [reverse_append]\n     ... = reverse (aplana i ++ [x] ++ aplana d)\n             : by simp only [append_assoc]\n     ... = reverse (aplana (nodo x i d))\n             : by simp only [aplana_2])\n\n-- 9\u00aa demostraci\u00f3n\nexample :\n  aplana (espejo a) = reverse (aplana a) :=\narbol.rec_on a\n  (\u03bb x, by simp)\n  (\u03bb x i d Hi Hd, by simp [Hi, Hd])\n\n-- 10\u00aa demostraci\u00f3n\nlemma aplana_espejo :\n  \u2200 a : arbol \u03b1, aplana (espejo a) = reverse (aplana a)\n| (hoja x)     := by simp\n| (nodo x i d) := by simp [aplana_espejo i,\n                           aplana_espejo d]\n\nend arbol\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Razonamiento_sobre_arboles_binarios_Aplanamiento_e_imagen_especular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7155958433260831}}
{"text": "namespace prop_logic\n\n/-\nThis assignment has five problems. The first\nis to extend our propositional logic syntax\nand semantics to support the three additional\nconnectives, exclusive or (\u2295), implies (which \nwe will write as \u21d2), and if and only iff (\u2194).\nWe first give you the definitions developed\nin class. You are to extend/modify them to\nsupport expressions with the new connectives.\nThe remaining problems use this definition of\nour language of expressions in propositional\nlogic.  \n-/\n\n\n/-\n1. Extend our syntax and semantics\nfor propositional logic to support\nthe xor, implies, and iff and only\niff connectives/operators.\n\nA. Add support for the exclusive or\nconnective/operator. Define the symbol, \n\u2295, as an infix notation.\n\nHere are specific steps to take for the\nexclusive or connective, as an example.\n\n1. Add new binary connective, xorOp\n2. Add pXor as shorthand for binOpExp xorOp\n3. Add \u2295 as an infix notation for pXor\n4. Specify the interpretation of \u2295 to be bxor\n5. Extend interpBinOp to handle the new case \n\nThen add support for the implies connective,\nusing the symbol, \u21d2, as an infix operator.\nWe can't use \u2192 because it's reserved by Lean\nand cannot be overloaded. Lean does not have \na Boolean implies operator (analogous to bor),\nso you will have to define one. Call it bimpl.\n\nFinally add support for if and only iff. Use\nthe symbol \u2194 as an infix notation. You will\nhave to define a Boolean function as Lean \ndoes not provide one for iff. Call it biff.\n\nHere is the code as developed in class.\nNow review the step-by-step instructions,\nand proceed to read and midify this logic\nas required. We've bracketed areas where\nnew material will have to be added. \n-/\n\n/-    *** SYNTAX ***    -/\n\ninductive var : Type \n| mkVar : \u2115 \u2192 var\n\ninductive unOp : Type\n| notOp\n\ninductive binOp : Type\n| andOp\n| orOp\n\n/-HW-/\n-- add new binOps here\n| xorOp\n| impOp\n| iffOp\n/-HW-/\n\ninductive pExp : Type\n| litExp : bool \u2192 pExp\n| varExp : var \u2192 pExp\n| unOpExp : unOp \u2192 pExp \u2192 pExp\n| binOpExp : binOp \u2192 pExp \u2192 pExp \u2192 pExp\n\nopen var\nopen pExp\nopen unOp\nopen binOp\n\n-- Shorthand notations\ndef pTrue := litExp tt\ndef pFalse := litExp ff\ndef pNot := unOpExp notOp\ndef pAnd := binOpExp andOp\ndef pOr := binOpExp orOp\n\n/-HW-/\n-- Add new operator application\n-- shorthands here.\n-- Add pXor as shorthand for binOpExp xorOp\ndef pXor := binOpExp xorOp\ndef pImple := binOpExp impOp\ndef pIff := binOpExp iffOp\n/-HW-/\n\n-- conventional notation\n\nnotation e1 \u2227 e2 :=  pAnd e1 e2\nnotation e1 \u2228 e2 :=  pOr e1 e2\nnotation \u00ac e := pNot e\n\n/-HW-/\n-- Add new notations here\n-- Add \u2295 as an infix notation for pXor\nnotation e1 \u2295 e2 := pXor e1 e2 \nnotation e1 \u21d2 e2 := pImple e1 e2\nnotation e1 \u2194 e2 := pIff e1 e2\n/-HW-/\n\n/-\n    *****************\n    *** SEMANTICS ***\n    *****************\n-/\n\ndef interpUnOp : unOp \u2192 (bool \u2192 bool) \n| notOp := bnot\n\n/-HW-/\n-- Add Boolean function definitions here\n-- Specify the interpretation of \u2295 to be bxor\n\ndef bimpl : bool \u2192 bool \u2192 bool\n| tt tt := tt  \n| tt ff := ff\n| ff tt := tt\n| ff ff := tt\n\ndef biff : bool \u2192 bool \u2192 bool\n| tt tt := tt  \n| tt ff := ff\n| ff tt := ff\n| ff ff := tt\n/-HW-/\n\ndef interpBinOp : binOp \u2192 (bool \u2192 bool \u2192 bool) \n| andOp := band\n| orOp := bor\n| xorOp := bxor\n| impOp := bimpl\n| iffOp := biff\n/-HW-/\n-- Add cases for new binOps here\n-- Extend interpBinOp to handle the new case\n/-HW-/\n\n\n/-  *** SEMANTICS ***   -/\n\n\n/-\nGiven a pExp and an interpretation\nfor the variables, compute and return\nthe Boolean value of the expression.\n-/\ndef pEval : pExp \u2192 (var \u2192 bool) \u2192 bool \n| (litExp b) i := b\n| (varExp v) i := i v\n| (unOpExp op e) i := \n    (interpUnOp op) (pEval e i)\n| (binOpExp op e1 e2) i := \n     (interpBinOp op)\n        (pEval e1 i) \n        (pEval e2 i)\n\n\n/-\nNote: You are free to use pEval, if you\nwish to, to check answers to some of the\nquestions below. It is not mandatory and\nyou will not be marked down for not doing\nthis.\n-/\n\n/-\n#2. Define X, Y, and Z to be variable\nexpressions bound to a different variable\nexpression terms. Hint: Look at the\nprop_logic_test.lean file to remind\nyourself how we did this in class.\n-/\ndef varX := mkVar 0\ndef varY := mkVar 1\ndef varZ := mkVar 2\n\ndef X : pExp:= varExp varX\ndef Y : pExp := varExp varY\ndef Z : pExp := varExp varZ\n\n\n\n/-\n#3. Here are some English language \nsentences that you are to re-express\nin propositional logic. Here's one\nexample.\n-/\n\n/-\nEXAMPLE:\n\nFormalize the following proposition,\nas a formula in propositional logic:\nIf it's raining then it's raining.\n-/\n\n-- Use R to represent \"it's raining\"\ndef R : pExp := varExp (mkVar 4)\n\n-- Solution here\ndef ex1 := R \u21d2 R\n\n\n/-\nExplanation: We first choose to represent\nthe smaller proposition, \"it's raining\", \nby the variable expression, R. We then\nformalize the overall natural language\nexpression, if R then R, as the formula,\nR \u21d2 R.\n\nNote: R \u21d2 R can be pronounced as any of:\n- if R is true then R is true \n- if R then R\n- the truth of R implies the truth of R\n- R implies R  \n\nThe second and fourth pronounciations\nare the two that we prefer to use. \n-/\n\n/-\nFor the remaining problems, use the \nvariables expressions, X, Y, and Z, \nas already defined. Use parentheses\nif needed to group sub-expressions.\n-/\n\n/-\nA.\n\nIf it's raining and the streets are\nwet then it's raining.\n-/\n\ndef p2 : pExp := (X \u2227 Y) \u21d2 X\n\n/-\nB. If it's raining and the streets\nare wet, then the streets are wet\nand it's raining. \n-/\n\ndef p3 := (X \u2227 Y) \u21d2 (Y \u2227 X) \n\n\n/-\nC. If it's raining then if the\nstreets are wet then it's raining\nand the streets are wet.\n-/\ndef p4 := X \u21d2 (Y \u21d2  (X \u2227 Y))\n\n/-\nD. If it's raining then it's\nraining or the moon is made of\ngreen cheese.\n-/\ndef p5 := X \u21d2 (X \u2228 Z)\n\n/-\nE. If it's raining, then if it's\nraining implies that the streets \nare wet, then the streets are wet.\n-/\ndef p6 := X \u21d2 (X \u21d2 Y) \u21d2 Y\n\n\n/-\n#4. For each of the propositional\nlogic expressions below, write a truth\ntable and based on your result, state\nwhether the expression is unsatisfiable,\nsatisfiable but not valid, or valid. \n\nHere's an example solution for the\nexpression, (X \u2227 Y) \u21d2 Y.\n\nX   Y   X \u2227 Y   (X \u2227 Y) \u21d2 Y\n-   -   -----   -----------\nT   T   T       T\nT   F   F       T\nF   T   F       T\nF   F   F       T\nThe proposition is valid.\n-/\n\n/-\nA. After each \"#check\" give your \nanswer for the specified proposition.\nThat is, write a truth table in a\ncomment and then say whether given the\nproposition is valid, satisfiable but\nnot valid, or unsatisifiable. \n\nNote: This expression reqires that \nyou  have properly specified \u00ac and\n\u21d2 as notations in our pExp language.\nThe errors indicated in many of the\nfollowing lines will go away once \nyou have these notations properly\ndefined.\n-/\n\n#check (X \u21d2 Y) \u21d2 (\u00ac X \u21d2 \u00ac Y)\n\n/-\n-- Answer here\nX   Y   X \u21d2 Y \u00ac X   \u00ac Y       (\u00ac X \u21d2 \u00ac Y)  (X \u21d2 Y) \u21d2 (\u00ac X \u21d2 \u00ac Y)\n-   -   -----   -     -        -----------   ----------------------\nT   T   T       F     F        T                T        \nT   F   F       F     T        T                T\nF   T   T       T     F        F                F\nF   F   T       T     T        T                T\nSatifiable\n-/\n\n\n/-\nB.\n-/\n#check ((X \u21d2 Y) \u2227 (Y \u21d2 X)) \u21d2 (X \u21d2 Z)\n\n/-\n-- Answer here\n\nX   Y   X \u21d2 Y  Y \u21d2 X    (X \u21d2 Y) \u2227 (Y \u21d2 X) Z    (X \u21d2 Z) ((X \u21d2 Y) \u2227 (Y \u21d2 X)) \u21d2 (X \u21d2 Z)\n-   -   -----   -----    -----------------  -     -----   ----------------------------\nT   T   T       T        T                  T      T          T                             \nT   F   F       T        F                  F      F          T \nF   T   T       F        F                  T      T          T             \nF   F   T       T        T                  F      T          T \n\nValid\n-/\n\n/-\nC.\n-/\n#check pFalse \u21d2 (X \u2227 \u00ac X)\n\n/-\n-- Answer here\n\npFalse   X   \u00ac X    (X \u2227 \u00ac X)    pFalse \u21d2(X \u2227 \u00ac X)\n------   -   ---     -------     -----------------\nF        T     F        F                T                  \nF        F     T        F                T           \n\nValid\n-/\n\n\n/-\nD.\u2260\n-/\n\n#check pTrue \u21d2(X \u2227 \u00ac X)\n\n-- Answer here\n/-\npTrue    X   \u00ac X    (X \u2227 \u00ac X)    pFalse \u21d2(X \u2227 \u00ac X)\n------   -   ---     -------     -----------------\nT        T     F        F                F                  \nT        F     T        F                F \n\nUnsatisfiable\n-/\n\n/-\nE.\n-/\n\n#check (X \u2228 Y) \u2227 X \u21d2 \u00ac Y\n\n-- Answer here\n/-\nX    Y   X \u2228 Y    (X \u2228 Y) \u2227 X   \u00ac Y    (X \u2228 Y) \u2227 X \u21d2 \u00ac Y\n-    -   ------    ----------    --     ----------------\nT    T    T         T             F      F                     \nT    F    T         T             T      T                  \nF    T    T         F             F      T                       \nF    F    F         F             T      T\n\nSatisfiable but not valid\n-/\n\n/-\n#5. \n\nA. Find and present an interpretation\nthat causes the following proposition\nto be satisfied (to evaluate to true).\n\n(X \u2228 Y) \u2227 (\u00ac Y \u2228 Z)\n\nAnswer:\n\nX   Y   X \u2228 Y   \u00ac Y   Z    \u00ac Y \u2228 Z    (X \u2228 Y) \u2227 (\u00ac Y \u2228 Z)\n-   -   -----   ---   -    -------     ------------------\nT   T   T       F     T    T            T                     \nT   F   T       T     T    T            T                        \nF   T   T       F     F    F            F                    \nF   F   F       T     F    T            F\n\nThe proposition will be true when X=T, Y=T, Z=T\nB. Count and state how many of the\npossible interpretations satisfy the\nformula.\n\n\nAnswer;  2\n-/\n\n\ntheorem prove_false_elim {pFalse : Prop}: false \u2192 pFalse :=\nbegin\n    assume a,\n    apply false.elim a,\nend\n\nend prop_logic\n\n", "meta": {"author": "derekjohnsonva", "repo": "CS2102", "sha": "b3f507d4be824a2511838a1054d04fc9aef3304c", "save_path": "github-repos/lean/derekjohnsonva-CS2102", "path": "github-repos/lean/derekjohnsonva-CS2102/CS2102-b3f507d4be824a2511838a1054d04fc9aef3304c/HW/hw6_prop_logic_and_satifiability.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7155958399100695}}
{"text": "import .quantum_state\nimport data.complex.exponential\n\nnamespace quantum\n\nvariables {n m p q : \u2115} \n\n-- measurement operators in are hermitian\ndef hermitian (U : matrix (fin n) (fin n) \u2102) : Prop :=\n U = U\u2020\n\n-- time evolution operators are usually unitary\ndef unitary (U : matrix (fin n) (fin n) \u2102) : Prop :=\n U\u2020 \u2b1d U = 1\n\n-- a weaker condition than unitary that may be useful\ndef normal (U : matrix (fin n) (fin n) \u2102) : Prop :=\n (U\u2020 \u2b1d U) = (U \u2b1d U\u2020)\n\ndef Id : matrix (fin 2) (fin 2) \u2102 :=\n  ![![1, 0],\n    ![0, 1]]\n\n-- The pauli spin matrix in the x direction\ndef \u03c3_x : matrix (fin 2) (fin 2) \u2102 := \n ![![0,  1],\n   ![1, 0]]\n\n-- The pauli spin matrix in the y direction\ndef \u03c3_y : matrix (fin 2) (fin 2) \u2102 := \n ![![0,  -im],\n   ![im, 0]]\n\n-- The pauli spin matrix in the z direction\ndef \u03c3_z : matrix (fin 2) (fin 2) \u2102 := \n ![![1,  0],\n   ![0, -1]]\n\n-- corresponds to measurement in z direction\nlemma z_plus_eigenval_\u03c3_z : \u03c3_z \u2b1d |z\u208a\u27e9 = |z\u208a\u27e9 :=\nbegin\n  rw [\u03c3_z, quantum.z_plus, matrix.mul],\n  funext i j,\n  simp,\nend\n\nlemma z_minus_eigenval_\u03c3_z : \u03c3_z \u2b1d |z\u208b\u27e9 = -|z\u208b\u27e9 :=\nbegin\n  rw [\u03c3_z, quantum.z_minus, matrix.mul],\n  funext i j,\n  simp,\nend\n\nend quantum", "meta": {"author": "brayden-gg", "repo": "Quantum_FPV", "sha": "2c5cb1804e99c4644ce7adc79c37ed8a09690116", "save_path": "github-repos/lean/brayden-gg-Quantum_FPV", "path": "github-repos/lean/brayden-gg-Quantum_FPV/Quantum_FPV-2c5cb1804e99c4644ce7adc79c37ed8a09690116/src/operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7155572476873379}}
{"text": "def fun.im {A B : Type _} (f : A \u2192 B) := { b : B | \u2203 a, f a = b }\ndef set.finite {T : Type _} (S : set T) := \u2203 n (f : fin n \u2192 T), function.injective f \u2227 (S = fun.im f)\n\ndef LEM := \u2200 P : Prop, P \u2228 \u00ac P\ndef finite_subsets := \u2200 {T : Type} {S S' : set T}, S \u2286 S' \u2192 set.finite S' \u2192 set.finite S\n\nlemma zero_only_elem_fin_1 : \u2200 x : fin 1, x = \u27e80,nat.zero_lt_one\u27e9\n| \u27e80,   h\u27e9 := rfl\n| \u27e8n+1, h\u27e9 := \n  have 1 + n < 1 + 0,\n  from nat.add_comm n 1 \u25b8 h,\n  have n < 0,\n  from nat.lt_of_add_lt_add_left this,\n  absurd this (nat.not_lt_zero n)\n\ntheorem finite_subsets_are_finite_imp_LEM (fin_sub : finite_subsets) : LEM :=\n\u03bb P,\n  let f1 : fin 1 \u2192 nat := \u03bb _, 0 in\n  have f1_i : \u2200 x y, f1 x = f1 y \u2192 x = y,\n  from \u03bb x y _, eq.trans (zero_only_elem_fin_1 x)\n              $ eq.symm $ zero_only_elem_fin_1 y,\n  have f1_s.helper : \u2200 x, (x = 0) \u2194 (\u2203 k, f1 k = x),\n  from \u03bb x, iff.intro (\u03bb h, eq.symm h \u25b8 \u27e8\u27e80, zero_lt_one\u27e9, rfl\u27e9)\n                      (\u03bb h, exists.elim h (\u03bb _ h', eq.symm h')),\n  have f1_s : { y : nat | y = 0 } = { b : \u2115 | \u2203 k, f1 k = b },\n  from funext (\u03bb x, propext $ f1_s.helper x),\n  have h1 : set.finite { y : nat | y = 0 },\n  from \u27e81, f1, f1_i, f1_s\u27e9,\n  have h2 : {y : nat | y = 0 \u2227 P} \u2286 { y : nat | y = 0 },\n  from \u03bb x h, h.left,\n  have h3 : set.finite {y : nat | y = 0 \u2227 P },\n  from fin_sub h2 h1,\n  have im_empty : \u2200 (f : fin 0 \u2192 nat) x, fun.im f x \u2192 false,\n  from \u03bb f x h, exists.elim h $ \u03bb a, fin.elim0 a,\n  have neg_case : (\u2203 (f : fin 0 \u2192 nat), function.injective f \u2227 {y : nat | y = 0 \u2227 P} = fun.im f) \u2192 \u00acP,\n  from \u03bb e, exists.elim e (\u03bb f \u27e8_, h\u27e9 hp, im_empty f 0 $ h \u25b8 \u27e8rfl, hp\u27e9),\n  have pos_case : \u2200 k, 0 < k \u2192 (\u2203 (f : fin k \u2192 nat), function.injective f \u2227 {y : nat | y = 0 \u2227 P} = fun.im f) \u2192 P,\n  from \u03bb k hk e, exists.elim e $ \u03bb f \u27e8_, h\u27e9,\n          have h' : fun.im f (f \u27e80, hk\u27e9),\n          from \u27e8\u27e80, hk\u27e9, rfl\u27e9,\n          have h'' : { y : nat | y = 0 \u2227 P } (f \u27e80, hk\u27e9), \n          from eq.symm h \u25b8 h',\n          and.right h'',\n  exists.elim h3 $\n    \u03bb k, match nat.decidable_eq 0 k with\n         | is_true h := h \u25b8 \u03bb x, or.inr $ neg_case x\n         | is_false h :=  \n          have k_pos : 0 < k,\n          from nat.pos_of_ne_zero (ne.symm h),\n          \u03bb x, or.inl $ pos_case k k_pos x\n         end", "meta": {"author": "Shamrock-Frost", "repo": "boolean_rings", "sha": "5da11beeaa37ec186c1deff946f2dbf7594fceb4", "save_path": "github-repos/lean/Shamrock-Frost-boolean_rings", "path": "github-repos/lean/Shamrock-Frost-boolean_rings/boolean_rings-5da11beeaa37ec186c1deff946f2dbf7594fceb4/finite_subsets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7155572476873379}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world2.level4 -- hide\nnamespace mynat -- hide\n\n/- Axiom : one_eq_succ_zero\n1 = succ(0)\n-/\n\n/-\n\n# Addition World\n\n## Level 5: `succ_eq_add_one`\n\nI've just added `one_eq_succ_zero` (a proof of `1 = succ(0)`) to your list of theorems; this is true\nby definition of $1$, but we didn't need it until now.\n\nLevels 5 and 6 are the two last levels in Addition World.\nLevel 5 involves the number $1$. When you see a $1$ in your goal,\nyou can write `rw one_eq_succ_zero` to get back\nto something which only mentions `0`. This is a good move because $0$ is easier for us to\nmanipulate than $1$ right now, because we have\nsome theorems about $0$ (`zero_add`, `add_zero`), but, other than `1 = succ(0)`,\nno theorems at all which mention $1$. Let's prove one now.\n-/\n\n/- Theorem\nFor any natural number $n$, we have\n$$ \\operatorname{succ}(n) = n+1. $$\n-/\ntheorem succ_eq_add_one (n : mynat) : succ n = n + 1 :=\nbegin [nat_num_game]\n  rw one_eq_succ_zero,\n  rw add_succ,\n  rw add_zero,\n  refl,\nend\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world2/level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.7853085884247212, "lm_q1q2_score": 0.7155572442941639}}
{"text": "import data.real.basic\n\nvariables {x y : \u211d}\n\n#check le_or_lt\n#check @abs_of_neg\n#check @abs_of_nonneg\n\n-- BEGIN\nexample : x < abs y \u2192 x < y \u2228 x < -y :=\nbegin\n  cases le_or_gt 0 y with h1 h2, \n  { rw abs_of_nonneg h1,\n    intro h, \n    left, \n    exact h },\n  rw abs_of_neg h2,\n  intro h, \n  right, \n  exact h,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/4_cases/4.3_cases_disjunc/ex2_cases_x_lt_abs_y.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7155572401108714}}
{"text": "-- 5.8 Exercises\n-- #1\n-- Go back to the exercises in Chapter 3 and Chapter 4 and redo as many as you can now with tactic proofs, \n-- using also rw and simp as appropriate.\n\n\n-- 4.6 Exercises\n-- #6\n-- Give a calculational proof of the theorem log_mul below.\n\nimport data.real.basic\n\nvariables log exp     : real \u2192 real\nvariable  log_exp_eq : \u2200 x, log (exp x) = x\nvariable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\nvariable  exp_pos    : \u2200 x, exp x > 0\nvariable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n\n-- this ensures the assumptions are available in tactic proofs\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\nexample (x y z : real) :\n  exp (x + y + z) = exp x * exp y * exp z :=\nby rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\nexp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\ncalc\n  log (x * y) = log ((exp (log x)) * y)             : by rw (exp_log_eq hx)\n  ...         = log ((exp (log x)) * (exp (log y))) : by rw (exp_log_eq hy)\n  ...         = log (exp ((log x) + (log y)))       : by rw exp_add\n  ...         = (log x) + (log y)                   : by rw log_exp_eq\n\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/05-Tactics/example-5.8-8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7853085733507947, "lm_q1q2_score": 0.7155572362414578}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\n\nimport data.nat.units\nimport data.int.basic\nimport algebra.ring.units\n\n/-!\n# Lemmas about units in `\u2124`.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nnamespace int\n\n/-! ### units -/\n\n@[simp] theorem units_nat_abs (u : \u2124\u02e3) : nat_abs u = 1 :=\nunits.ext_iff.1 $ nat.units_eq_one \u27e8nat_abs u, nat_abs \u2191u\u207b\u00b9,\n  by rw [\u2190 nat_abs_mul, units.mul_inv]; refl,\n  by rw [\u2190 nat_abs_mul, units.inv_mul]; refl\u27e9\n\ntheorem units_eq_one_or (u : \u2124\u02e3) : u = 1 \u2228 u = -1 :=\nby simpa only [units.ext_iff, units_nat_abs] using nat_abs_eq u\n\nlemma is_unit_eq_one_or {a : \u2124} : is_unit a \u2192 a = 1 \u2228 a = -1\n| \u27e8x, hx\u27e9 := hx \u25b8 (units_eq_one_or _).imp (congr_arg coe) (congr_arg coe)\n\nlemma is_unit_iff {a : \u2124} : is_unit a \u2194 a = 1 \u2228 a = -1 :=\nbegin\n  refine \u27e8\u03bb h, is_unit_eq_one_or h, \u03bb h, _\u27e9,\n  rcases h with rfl | rfl,\n  { exact is_unit_one },\n  { exact is_unit_one.neg }\nend\n\nlemma is_unit_eq_or_eq_neg {a b : \u2124} (ha : is_unit a) (hb : is_unit b) : a = b \u2228 a = -b :=\nbegin\n  rcases is_unit_eq_one_or hb with rfl | rfl,\n  { exact is_unit_eq_one_or ha },\n  { rwa [or_comm, neg_neg, \u2190is_unit_iff] },\nend\n\nlemma eq_one_or_neg_one_of_mul_eq_one {z w : \u2124} (h : z * w = 1) : z = 1 \u2228 z = -1 :=\nis_unit_iff.mp (is_unit_of_mul_eq_one z w h)\n\nlemma eq_one_or_neg_one_of_mul_eq_one' {z w : \u2124} (h : z * w = 1) :\n  (z = 1 \u2227 w = 1) \u2228 (z = -1 \u2227 w = -1) :=\nbegin\n  have h' : w * z = 1 := (mul_comm z w) \u25b8 h,\n  rcases eq_one_or_neg_one_of_mul_eq_one h with rfl | rfl;\n  rcases eq_one_or_neg_one_of_mul_eq_one h' with rfl | rfl;\n  tauto,\nend\n\ntheorem eq_of_mul_eq_one {z w : \u2124} (h : z * w = 1) : z = w :=\n(eq_one_or_neg_one_of_mul_eq_one' h).elim (\u03bb h, h.1.trans h.2.symm) (\u03bb h, h.1.trans h.2.symm)\n\nlemma mul_eq_one_iff_eq_one_or_neg_one {z w : \u2124} :\n  z * w = 1 \u2194 z = 1 \u2227 w = 1 \u2228 z = -1 \u2227 w = -1 :=\nbegin\n  refine \u27e8eq_one_or_neg_one_of_mul_eq_one', \u03bb h, or.elim h (\u03bb H, _) (\u03bb H, _)\u27e9;\n  rcases H with \u27e8rfl, rfl\u27e9;\n  refl,\nend\n\nlemma eq_one_or_neg_one_of_mul_eq_neg_one' {z w : \u2124} (h : z * w = -1) :\n  z = 1 \u2227 w = -1 \u2228 z = -1 \u2227 w = 1 :=\nbegin\n  rcases is_unit_eq_one_or (is_unit.mul_iff.mp (int.is_unit_iff.mpr (or.inr h))).1 with rfl | rfl,\n  { exact or.inl \u27e8rfl, one_mul w \u25b8 h\u27e9, },\n  { exact or.inr \u27e8rfl, neg_inj.mp (neg_one_mul w \u25b8 h)\u27e9, }\nend\n\nlemma mul_eq_neg_one_iff_eq_one_or_neg_one {z w : \u2124} :\n  z * w = -1 \u2194 z = 1 \u2227 w = -1 \u2228 z = -1 \u2227 w = 1 :=\nbegin\n  refine \u27e8eq_one_or_neg_one_of_mul_eq_neg_one', \u03bb h, or.elim h (\u03bb H, _) (\u03bb H, _)\u27e9;\n  rcases H with \u27e8rfl, rfl\u27e9;\n  refl,\nend\n\ntheorem is_unit_iff_nat_abs_eq {n : \u2124} : is_unit n \u2194 n.nat_abs = 1 :=\nby simp [nat_abs_eq_iff, is_unit_iff, nat.cast_zero]\n\nalias is_unit_iff_nat_abs_eq \u2194 is_unit.nat_abs_eq _\n\n@[norm_cast]\nlemma of_nat_is_unit {n : \u2115} : is_unit (n : \u2124) \u2194 is_unit n :=\nby rw [nat.is_unit_iff, is_unit_iff_nat_abs_eq, nat_abs_of_nat]\n\nlemma is_unit_mul_self {a : \u2124} (ha : is_unit a) : a * a = 1 :=\n(is_unit_eq_one_or ha).elim (\u03bb h, h.symm \u25b8 rfl) (\u03bb h, h.symm \u25b8 rfl)\n\nlemma is_unit_add_is_unit_eq_is_unit_add_is_unit {a b c d : \u2124}\n  (ha : is_unit a) (hb : is_unit b) (hc : is_unit c) (hd : is_unit d) :\n  a + b = c + d \u2194 a = c \u2227 b = d \u2228 a = d \u2227 b = c :=\nbegin\n  rw is_unit_iff at ha hb hc hd,\n  cases ha; cases hb; cases hc; cases hd;\n  subst ha; subst hb; subst hc; subst hd;\n  tidy,\nend\n\n\n\nend int\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7155275414916583}}
{"text": "universe u\n\ndef f1 (n m : Nat) (x : Fin n) (h : n = m) : Fin m :=\nh \u25b8 x\n\ndef f2 (n m : Nat) (x : Fin n) (h : m = n) : Fin m :=\nh \u25b8 x\n\ntheorem ex1 {\u03b1 : Sort u} {a b c : \u03b1} (h\u2081 : a = b) (h\u2082 : b = c) : a = c :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex2 {\u03b1 : Sort u} {a b : \u03b1} (h : a = b) : b = a :=\nh \u25b8 rfl\n\ntheorem ex3 {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex3b {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082.symm \u25b8 h\u2081\n\ntheorem ex3c {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082.symm.symm \u25b8 h\u2081\n\ntheorem ex4 {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : a = b) (h\u2082 : r b c) : r a c :=\nh\u2081 \u25b8 h\u2082\n\ntheorem ex5 {p : Prop} (h : p = True) : p :=\nh \u25b8 trivial\n\ntheorem ex6 {p : Prop} (h : p = False) : \u00acp :=\nfun hp => h \u25b8 hp\n\ntheorem ex7 {\u03b1} {a b c d : \u03b1} (h\u2081 : a = c) (h\u2082 : b = d) (h\u2083 : c \u2260 d) : a \u2260 b :=\nh\u2081 \u25b8 h\u2082 \u25b8 h\u2083\n\ntheorem ex8 (n m k : Nat) (h : Nat.succ n + m = Nat.succ n + k) : Nat.succ (n + m) = Nat.succ (n + k) :=\nNat.succ_add .. \u25b8 Nat.succ_add .. \u25b8 h\n\ntheorem ex9 (a b : Nat) (h\u2081 : a = a + b) (h\u2082 : a = b) : a = b + a  :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex10 (a b : Nat) (h : a = b) : b = a :=\nh \u25b8 rfl\n\ndef ex11  {\u03b1 : Type u} {n : Nat} (a : Array \u03b1) (i : Nat) (h\u2081 : a.size = n) (h\u2082 : i < n) : \u03b1 :=\n  a.get \u27e8i, h\u2081 \u25b8 h\u2082\u27e9\n\ntheorem ex12 {\u03b1 : Type u} {n : Nat}\n  (a b : Array \u03b1)\n  (hsz\u2081 : a.size = n) (hsz\u2082 : b.size = n)\n  (h : \u2200 (i : Nat) (hi : i < n), a.getLit i hsz\u2081 hi = b.getLit i hsz\u2082 hi) : a = b :=\nArray.ext a b (hsz\u2081.trans hsz\u2082.symm) fun i hi\u2081 hi\u2082 => h i (hsz\u2081 \u25b8 hi\u2081)\n\ndef toArrayLit {\u03b1 : Type u} (a : Array \u03b1) (n : Nat) (hsz : a.size = n) : Array \u03b1 :=\nList.toArray $ Array.toListLitAux a n hsz n (hsz \u25b8 Nat.le_refl _) []\n\npartial def isEqvAux {\u03b1} (a b : Array \u03b1) (hsz : a.size = b.size) (p : \u03b1 \u2192 \u03b1 \u2192 Bool) (i : Nat) : Bool :=\n  if h : i < a.size then\n     let aidx : Fin a.size := \u27e8i, h\u27e9\n     let bidx : Fin b.size := \u27e8i, hsz \u25b8 h\u27e9\n     match p (a.get aidx) (b.get bidx) with\n     | true  => isEqvAux a b hsz p (i+1)\n     | false => false\n  else\n    true\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/subst.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7155275334934785}}
{"text": "import tactic\n\n-- Comments follow [Set Theory: An Open Introduction][1] and, only where\n-- specified, [An Introduction To Set Theory][2].\n--\n-- [1]: https://st.openlogicproject.org/settheory-screen.pdf\n-- [2]: https://www.math.toronto.edu/weiss/set_theory.pdf\n\n/-\n\nAn Introduction To Set Theory introduces abbreviations for working with\nclasses. A class is a string of symbols of the form `{x : \u03c6}` where `x`\nis a variable and `\u03c6` is a formula. We write:\n\n    x \u2208 {y : \u03c6} instead of \u03c6[y / x]\n    x = {y : \u03c6} instead of \u2200 z, z \u2208 x \u2194 \u03c6[y / z]\n    {x : \u03c6} = y instead of \u2200 z, \u03c6[x / z] \u2194 z \u2208 y\n    {x : \u03c6} = {y : \u03c8} instead of \u2200 z, \u03c6[x / z] \u2194 \u03c8[y / z]\n    {x : \u03c6} \u2208 y instead of \u2203 z, z \u2208 y \u2227 \u2200 x, x \u2208 z \u2194 \u03c6\n    {x : \u03c6} \u2208 {y : \u03c8} instead of \u2203 z, \u03c8[y / z] \u2227 \u2200 x, x \u2208 z \u2194 \u03c6\n\nwhere `z` is always fresh, i.e., `z` is neither `x` nor `y` and occurs in\nneither `\u03c6` or `\u03c8`.\n\nWhenever we have a finite number of classes or variables `a\u2081`, `a\u2082`, ..., `a\u2099`\nthe notation `{a\u2081, a\u2082, ..., a\u2099}` is used as an abbreviation for the class:\n\n    {x : x = a\u2081 \u2228 x = a\u2082 \u2228 ... \u2228 x = a\u2099}\n\nWe also abbreviate the following:\n\n    a \u222a b for {x : x \u2208 a \u2228 x \u2208 b}\n    a \u2229 b for {x : x \u2208 a \u2227 x \u2208 b}\n    a \\ b for {x : x \u2208 a \u2227 x \u2209 b}\n    \u27e8a, b\u27e9 for {{a}, {a, b}}\n    a \u00d7 b for {p : \u2203 x y, x \u2208 a \u2227 y \u2208 b \u2227 p = \u27e8a, b\u27e9}\n    dom(f) for {x : \u2203 y, \u27e8x, y\u27e9 \u2208 f}\n    rng(f) for {y : \u2203 x, \u27e8x, y\u27e9 \u2208 f}\n\nExamples:\n\n    \u00ac \u2203 z, z = {x : x \u2209 x}\n    \u00ac \u2203 z, \u2200 y, y \u2208 z \u2194 y \u2209 y\n    \u00ac \u2203 z, \u2200 x, x \u2208 z \u2194 x \u2209 x\n\n    \u2200 a, a \u2208 {a, b}\n    \u2200 a, a \u2208 {x : x = a \u2228 x = b}\n    \u2200 a, a = a \u2228 a = b\n\n    \u2203 z, z = \u2205\n    \u2203 z, z = {x : x \u2260 x}\n    \u2203 z, \u2200 x, x \u2208 z \u2194 x \u2260 x\n    ...\n    \u2203 z, \u2200 x, x \u2209 z\n\n    \u2200 x y, \u2203 z, z = {x, y}\n    \u2200 x y, \u2203 z, z = {w : w = x \u2228 w = y}\n    \u2200 x y, \u2203 z, \u2200 w, w \u2208 z \u2194 w = x \u2228 w = y\n\n-/\n\n-- Stages-are-key. Every set is formed at some stage.\n--\n-- Stages-are-ordered. Stages are ordered: some come before others.\n--\n-- Stages-accumulate. For any stage S, and for any sets which were formed\n-- before stage S: a set is formed at stage S whose members are exactly those\n-- sets. Nothing else is formed at stage S.\n--\n-- Stages-keep-going. There is no last stage.\n--\n-- Stages-hit-infinity. There is an infinite stage. That is, there is a stage\n-- which (a) is not the first stage, and which (b) has some stages before it,\n-- but which (c) has no immediate predecessor.\n\nnoncomputable theory\n\naxiom Set : Type\naxiom mem : Set \u2192 Set \u2192 Prop\ninstance : has_mem Set Set := \u27e8mem\u27e9\n\ndef subset (A B : Set) := \u2200 \u2983x\u2984, x \u2208 A \u2192 x \u2208 B\ninstance : has_subset Set := \u27e8subset\u27e9\n\ntheorem russell's_paradox : \u00ac \u2203 z : Set, \u2200 x, x \u2208 z \u2194 x \u2209 x :=\nbegin\n  rintros \u27e8z, hz\u27e9,\n  specialize hz z,\n  simpa using hz\nend\n\n-- Axiom (Extensionality). For any sets A and B: \u2200 x (x \u2208 A \u2194 x \u2208 B) \u2192 A = B\n@[ext] axiom extensionality {A B : Set} (h : \u2200 x, x \u2208 A \u2194 x \u2208 B) : A = B\n\n-- The axiom of equality, as presented in An Introduction To Set Theory.\nexample (a b : Set) (h : a = b) : \u2200 x : Set, a \u2208 x \u2194 b \u2208 x :=\nby simp [h]\n\n-- The axiom of extensionality, as presented in An Introduction To Set Theory.\nlemma ext_iff {A B : Set} : A = B \u2194 \u2200 x, x \u2208 A \u2194 x \u2208 B :=\n\u27e8\u03bb h, by simp [h], extensionality\u27e9\n\n-- Axiom (Pairs). For any sets a, b, the set {a, b} exists.\n-- \u2200 a \u2200 b \u2203 P \u2200 x (x \u2208 P \u2194 (x = a \u2228 x = b))\naxiom pairing (a b : Set) : \u2203 P : Set, \u2200 x, x \u2208 P \u2194 x = a \u2228 x = b\n\n-- https://en.wikipedia.org/wiki/Extension_by_definitions\nexample (a b : Set) : \u2203! P : Set, \u2200 x, x \u2208 P \u2194 x = a \u2228 x = b :=\nbegin\n  obtain \u27e8P, hP\u27e9 := pairing a b,\n  refine \u27e8P, hP, _\u27e9,\n  intros P' hP',\n  ext x,\n  specialize hP x,\n  specialize hP' x,\n  rw [hP, hP']\nend\n\n-- Given the above we could add the following, making a conservative extension\n-- of ZFC.\n--axiom pair (a b : Set) : Set\n--axiom pair_spec (a b : Set) : \u2200 x, x \u2208 pair a b \u2194 x = a \u2228 x = b\n\nexample {\u03c6 : Set \u2192 Prop} {H : \u2203 z, \u03c6 z} {\u03c7 : Prop} (h : \u2200 z, \u03c6 z \u2192 \u03c7) : \u2203 z, \u03c6 z \u2227 \u03c7 :=\nbegin\n  obtain \u27e8z, hz\u27e9 := H,\n  exact \u27e8z, hz, h z hz\u27e9\nend\n\nexample {\u03c6 : Set \u2192 Prop} {\u03c7 : Prop} (h : \u2203 z, \u03c6 z \u2227 \u03c7) : \u2200 z, \u03c6 z \u2192 \u03c7 :=\nbegin\n  obtain \u27e8z, hz, h\u27e9 := h,\n  exact \u03bb _ _, h\nend\n\n-- Using the abbreviations defined in An Introduction To Set Theory:\n--\n--      \u2200 a b, \u2203 P, P = {a, b}\n--      \u2200 a b, \u2203 P, P = {x : x = a \u2228 x = b}\n--      \u2200 a b, \u2203 P, \u2200 x, x \u2208 P \u2194 x = a \u2228 x = b\n--\nexample (a b : Set) : \u2203 P : Set, \u2200 x, x \u2208 P \u2194 x = a \u2228 x = b :=\npairing a b\n\n-- Using the abbreviations defined in An Introduction To Set Theory:\n--\n--      \u2200 a b, \u2203 P, P = \u27e8a, b\u27e9\n--      \u2200 a b, \u2203 P, P = {{a}, {a, b}}\n--      \u2200 a b, \u2203 P, P = {x : x = {a} \u2228 x = {a, b}}\n--      \u2200 a b, \u2203 P, \u2200 x, x \u2208 P \u2194 x = {a} \u2228 x = {a, b}\n--      \u2200 a b, \u2203 P, \u2200 x, x \u2208 P \u2194 x = {y : y = a} \u2228 x = {y : y = a \u2228 y = b}\n--      \u2200 a b, \u2203 P, \u2200 x, x \u2208 P \u2194 (\u2200 z, z \u2208 x \u2194 z = a) \u2228 (\u2200 z, z \u2208 x \u2194 z = a \u2228 z = b)\n--\nlemma pair (a b : Set) :\n  \u2203 P : Set, \u2200 x, x \u2208 P \u2194 (\u2200 z, z \u2208 x \u2194 z = a) \u2228 (\u2200 z, z \u2208 x \u2194 z = a \u2228 z = b) :=\nbegin\n  obtain \u27e8P\u2081, hP\u2081\u27e9 := pairing a a,\n  simp only [or_self] at hP\u2081,\n  obtain \u27e8P\u2082, hP\u2082\u27e9 := pairing a b,\n  obtain \u27e8P, hP\u27e9 := pairing P\u2081 P\u2082,\n  use P,\n  intro x,\n  rw hP x,\n  clear hP,\n  split,\n  { rintro (rfl | rfl),\n    { left, assumption },\n    { right, assumption } },\n  { rintro (h | h),\n    { left, ext y, rw hP\u2081 y, exact h y },\n    { right, ext y, rw hP\u2082 y, exact h y } }\nend\n\n-- Using the abbreviations defined in An Introduction To Set Theory:\n--\n--      \u2200 a\u2081 a\u2082 b\u2081 b\u2082, \u27e8a\u2081, b\u2081\u27e9 = \u27e8a\u2082, b\u2082\u27e9 \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082\n--      \u2200 a\u2081 a\u2082 b\u2081 b\u2082, {{a\u2081}, {a\u2081, b\u2081}} = {{a\u2082}, {a\u2082, b\u2082}} \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082\n--      \u2200 a\u2081 a\u2082 b\u2081 b\u2082, {x : x = {a\u2081} \u2228 x = {a\u2081, b\u2081}} = {y : y = {a\u2082} \u2228 y = {a\u2082, b\u2082}} \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082\n--      \u2200 a\u2081 a\u2082 b\u2081 b\u2082, (\u2200 z, z = {a\u2081} \u2228 z = {a\u2081, b\u2081}} \u2194 z = {a\u2082} \u2228 z = {a\u2082, b\u2082}) \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082\n--      \u2200 a\u2081 a\u2082 b\u2081 b\u2082, (\u2200 z, z = {w : w = a\u2081} \u2228 z = {w : w = a\u2081 \u2228 w = b\u2081}} \u2194 z = {w : w = a\u2082} \u2228 z = {w : w = a\u2082 \u2228 w = b\u2082}) \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082\n--      \u2200 a\u2081 a\u2082 b\u2081 b\u2082, (\u2200 z, (\u2200 w, w \u2208 z \u2194 w = a\u2081) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2081 \u2228 w = b\u2081) \u2194 (\u2200 w, w \u2208 z \u2194 w = a\u2082) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2082 \u2228 w = b\u2082)) \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082\n--\nlemma fst_eq_fst_of_pair_eq_pair {a\u2081 a\u2082 b\u2081 b\u2082 : Set}\n  (h : \u2200 z : Set, (\u2200 w, w \u2208 z \u2194 w = a\u2081) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2081 \u2228 w = b\u2081) \u2194\n                  (\u2200 w, w \u2208 z \u2194 w = a\u2082) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2082 \u2228 w = b\u2082)) : a\u2081 = a\u2082 :=\nbegin\n  obtain \u27e8P\u2081, hP\u2081\u27e9 := pairing a\u2081 a\u2081,\n  obtain \u27e8P\u2082, hP\u2082\u27e9 := pairing a\u2082 a\u2082,\n  have h\u2081 := h P\u2081,\n  have h\u2082 := h P\u2082,\n  finish\nend\n\nlemma snd_eq_snd_of_pair_eq_pair {a\u2081 a\u2082 b\u2081 b\u2082 : Set}\n  (h : \u2200 z : Set, (\u2200 w, w \u2208 z \u2194 w = a\u2081) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2081 \u2228 w = b\u2081) \u2194\n                  (\u2200 w, w \u2208 z \u2194 w = a\u2082) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2082 \u2228 w = b\u2082)) : b\u2081 = b\u2082 :=\nbegin\n  obtain rfl := fst_eq_fst_of_pair_eq_pair h,\n  rename a\u2081 a,\n  obtain \u27e8P\u2081, hP\u2081\u27e9 := pairing a b\u2081,\n  obtain \u27e8P\u2082, hP\u2082\u27e9 := pairing a b\u2082,\n  have h\u2081 := h P\u2081, simp [hP\u2081] at h\u2081, clear hP\u2081 P\u2081,\n  have h\u2082 := h P\u2082, simp [hP\u2082] at h\u2082, clear hP\u2082 P\u2082,\n  clear h,\n  cases h\u2081; cases h\u2082,\n  { rw [h\u2081, h\u2082] },\n  { tidy },\n  { tidy },\n  { specialize h\u2081 b\u2081, simp at h\u2081,\n    specialize h\u2082 b\u2082, simp at h\u2082,\n    cases h\u2081; cases h\u2082; tidy }\nend\n\nexample {a\u2081 a\u2082 b\u2081 b\u2082 : Set} :\n  (\u2200 z : Set, (\u2200 w, w \u2208 z \u2194 w = a\u2081) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2081 \u2228 w = b\u2081) \u2194\n              (\u2200 w, w \u2208 z \u2194 w = a\u2082) \u2228 (\u2200 w, w \u2208 z \u2194 w = a\u2082 \u2228 w = b\u2082)) \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082 :=\nbegin\n  split; intro h,\n  { simp [fst_eq_fst_of_pair_eq_pair h, snd_eq_snd_of_pair_eq_pair h] },\n  { simp [h] }\nend", "meta": {"author": "pedrominicz", "repo": "logic", "sha": "0945200787b9ab8ca8e8f91e2c8de7e7a75efe3a", "save_path": "github-repos/lean/pedrominicz-logic", "path": "github-repos/lean/pedrominicz-logic/logic-0945200787b9ab8ca8e8f91e2c8de7e7a75efe3a/src/set_theory_an_open_introduction/09_steps_towards_z_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.7155275187493574}}
{"text": "/-\nCopyright (c) 2021 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\n\nimport data.fin.basic\nimport data.finset.sort\nimport data.prod.lex\n\n/-!\n\n# Sorting tuples by their values\n\nGiven an `n`-tuple `f : fin n \u2192 \u03b1` where `\u03b1` is ordered,\nwe may want to turn it into a sorted `n`-tuple.\nThis file provides an API for doing so, with the sorted `n`-tuple given by\n`f \u2218 tuple.sort f`.\n\n## Main declarations\n\n* `tuple.sort`: given `f : fin n \u2192 \u03b1`, produces a permutation on `fin n`\n* `tuple.monotone_sort`: `f \u2218 tuple.sort f` is `monotone`\n\n-/\n\nnamespace tuple\n\nvariables {n : \u2115}\nvariables {\u03b1 : Type*} [linear_order \u03b1]\n\n/--\n`graph f` produces the finset of pairs `(f i, i)`\nequipped with the lexicographic order.\n-/\ndef graph (f : fin n \u2192 \u03b1) : finset (\u03b1 \u00d7\u2097 (fin n)) :=\nfinset.univ.image (\u03bb i, (f i, i))\n\n/--\nGiven `p : \u03b1 \u00d7\u2097 (fin n) := (f i, i)` with `p \u2208 graph f`,\n`graph.proj p` is defined to be `f i`.\n-/\ndef graph.proj {f : fin n \u2192 \u03b1} : graph f \u2192 \u03b1 := \u03bb p, p.1.1\n\n@[simp] lemma graph.card (f : fin n \u2192 \u03b1) : (graph f).card = n :=\nbegin\n  rw [graph, finset.card_image_of_injective],\n  { exact finset.card_fin _ },\n  { intros _ _,\n    simp }\nend\n\n/--\n`graph_equiv\u2081 f` is the natural equivalence between `fin n` and `graph f`,\nmapping `i` to `(f i, i)`. -/\ndef graph_equiv\u2081 (f : fin n \u2192 \u03b1) : fin n \u2243 graph f :=\n{ to_fun := \u03bb i, \u27e8(f i, i), by simp [graph]\u27e9,\n  inv_fun := \u03bb p, p.1.2,\n  left_inv := \u03bb i, by simp,\n  right_inv := \u03bb \u27e8\u27e8x, i\u27e9, h\u27e9, by simpa [graph] using h }\n\n@[simp] lemma proj_equiv\u2081' (f : fin n \u2192 \u03b1) : graph.proj \u2218 graph_equiv\u2081 f = f :=\nrfl\n\n/--\n`graph_equiv\u2082 f` is an equivalence between `fin n` and `graph f` that respects the order.\n-/\ndef graph_equiv\u2082 (f : fin n \u2192 \u03b1) : fin n \u2243o graph f :=\nfinset.order_iso_of_fin _ (by simp)\n\n/-- `sort f` is the permutation that orders `fin n` according to the order of the outputs of `f`. -/\ndef sort (f : fin n \u2192 \u03b1) : equiv.perm (fin n) :=\n(graph_equiv\u2082 f).to_equiv.trans (graph_equiv\u2081 f).symm\n\nlemma self_comp_sort (f : fin n \u2192 \u03b1) : f \u2218 sort f = graph.proj \u2218 graph_equiv\u2082 f :=\nshow graph.proj \u2218 ((graph_equiv\u2081 f) \u2218 (graph_equiv\u2081 f).symm) \u2218 (graph_equiv\u2082 f).to_equiv = _,\n  by simp\n\n\nlemma monotone_proj (f : fin n \u2192 \u03b1) : monotone (graph.proj : graph f \u2192 \u03b1) :=\nbegin\n  rintro \u27e8\u27e8x, i\u27e9, hx\u27e9 \u27e8\u27e8y, j\u27e9, hy\u27e9 (h|h),\n  { exact le_of_lt \u2039_\u203a },\n  { simp [graph.proj] },\nend\n\nlemma monotone_sort (f : fin n \u2192 \u03b1) : monotone (f \u2218 sort f) :=\nbegin\n  rw [self_comp_sort],\n  exact (monotone_proj f).comp (graph_equiv\u2082 f).monotone,\nend\n\nend tuple\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/fin/tuple/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7154895747703567}}
{"text": "-- Math 52: Week 5\n\nimport .utils\nopen classical\n\n-- The following lemmas may be useful for the next proof.\n-- mul_lt_mul_of_pos_left (a b c : \u211d) : a < b \u2192 0 < c \u2192 c * a < c * b\n-- mul_lt_mul_of_pos_right (a b c : \u211d) : a < b \u2192 0 < c \u2192 a * c < b * c\n\n-- Lakins 2.1.2: For all real numbers a and b, if 0 < a < b, then a\u00b2 < b\u00b2.\ntheorem L212 : \u2200 (a b : \u211d), 0 < a \u2227 a < b \u2192 a * a < b * b :=\nbegin\nsorry\nend\n\n-- The following lemmas may be useful for the next proof.\n-- mul_le_mul_of_nonneg_left (a b c : \u211d) : a \u2264 b \u2192 0 \u2264 c \u2192 c * a \u2264 c * b\n-- mul_le_mul_of_nonneg_right (a b c : \u211d) : a \u2264 b \u2192 0 \u2264 c \u2192 a * c \u2264 b * c\n-- mul_le_mul_of_nonpos_left (a b c : \u211d) : b \u2264 a \u2192 c \u2264 0 \u2192 c * a \u2264 c * b\n-- mul_le_mul_of_nonpos_right (a b c : \u211d) : b \u2264 a \u2192 c \u2264 0 \u2192 a * c \u2264 b * c\n\n-- Lakins 2.1.6: For all real numbers x, 0 \u2264 x\u00b2.\ntheorem L216 : \u2200 (x : \u211d), 0 \u2264 x * x :=\nbegin\nsorry\nend\n\n-- The following lemmas may be useful in the following proof.\n-- div_le_of_le_mul_of_pos (a b c : \u211d) : a \u2264 b * c \u2192 c > 0 \u2192 a / c \u2264 b\n-- le_div_of_mul_le_of_pos (a b c : \u211d) : a * c \u2264 b \u2192 c > 0 \u2192 a \u2264 b / c\n\n-- Lakins 2.1.11: For all real numbers x and y, if x \u2264 y then x \u2264 (x + y)/2 \u2264 y.\ntheorem L2111 : \u2200 (x y : \u211d), x \u2264 y \u2192 x \u2264 (x + y)/2 \u2227 (x + y)/2 \u2264 y :=\nbegin\nsorry\nend\n\n-- The following lemmas may be useful in the next proof.\n-- ne_of_lt (a b : \u211d) : a < b \u2192 a \u2260 b\n-- mul_pos (a b : \u211d) : a > 0 \u2192 b > 0 \u2192 a * b > 0\n-- mul_neg_of_pos_of_neg (a b : \u211d) : a > 0 \u2192 b < 0 \u2192 a * b < 0\n-- mul_neg_of_neg_of_pos (a b : \u211d) : a < 0 \u2192 b > 0 \u2192 a * b < 0\n-- mul_pos_of_neg_of_neg (a b : \u211d) : a < 0 \u2192 b < 0 \u2192 a * b > 0\n\n-- Lakins 2.1.7: For all real numbers x and y, if xy = 0, then x = 0 or y = 0.\ntheorem L217 : \u2200 (x y : \u211d), x * y = 0 \u2192 x = 0 \u2228 y = 0 :=\nbegin\nsorry\nend \n\n-- This is a really tricky proof!\n-- Lakins 2.1.9: For all real numbers x and y, if x\u00b2 = y\u00b2, then x = y or x = \u2212y; i.e., x = \u00b1y.\ntheorem L219 : \u2200 (x y : \u211d), x * x = y * y \u2192 x = y \u2228 x = -y :=\nbegin\nintros x y H,\nhave L : x - y = 0 \u2228 x + y = 0,\nbegin\napply L217,\ncalc (x - y) * (x + y)\n= x * (x + y) - y * (x + y) : by rw sub_mul ...\n= (x * x + x * y) - y * (x + y) : by rw mul_add ...\n= (x * x + x * y) - (y * x + y * y) : by rw mul_add ...\n= ((x * x + x * y) - y * x) - y * y : by rw sub_sub ...\n= ((x * x + x * y) - x * y) - y * y : by ac_refl ...\n= x * x - y * y : by rw add_sub_cancel ...\n= x * x - x * x : by rw H ...\n= 0 : by rw sub_self,\nend,\ncases L,\n{ left,\n  apply eq_of_sub_eq_zero,\n  assumption\n},\n{ right,\n  apply eq_of_sub_eq_zero,\n  rw sub_neg_eq_add,\n  assumption,\n},\nend\n", "meta": {"author": "UVM-M52", "repo": "week-5-maddiehutchinson", "sha": "7fd99c56b0a9a313ed1b462e9a8e50c0d66857aa", "save_path": "github-repos/lean/UVM-M52-week-5-maddiehutchinson", "path": "github-repos/lean/UVM-M52-week-5-maddiehutchinson/week-5-maddiehutchinson-7fd99c56b0a9a313ed1b462e9a8e50c0d66857aa/src/week05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7154895600976955}}
{"text": "-- Interseccion_con_la_imagen_inversa.lean\n-- Intersecci\u00f3n con la imagen inversa\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 21 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    s \u2229 f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u2229 v)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariable  s : set \u03b1\nvariable  v : set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u2229 v) :=\nbegin\n  intros x hx,\n  rw mem_preimage,\n  split,\n  { apply mem_image_of_mem,\n    exact hx.1, },\n  { rw \u2190 mem_preimage,\n    exact hx.2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u2229 v) :=\nbegin\n  rintros x \u27e8xs, xv\u27e9,\n  split,\n  { exact mem_image_of_mem f xs, },\n  { exact xv, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u2229 v) :=\nbegin\n  rintros x \u27e8xs, xv\u27e9,\n  exact \u27e8mem_image_of_mem f xs, xv\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u2229 v) :=\nbegin\n  rintros x \u27e8xs, xv\u27e9,\n  show f x \u2208 f '' s \u2229 v,\n  split,\n  { use [x, xs, rfl] },\n  { exact xv },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' v \u2286 f \u207b\u00b9' (f '' s \u2229 v) :=\ninter_preimage_subset s v f\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Interseccion_con_la_imagen_inversa.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7154137187561957}}
{"text": "/-\nCopyright (c) 2022 Jun Yoshida. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n-/\n\nimport Algdata.Init.Nat\n\n/-!\n# A variety of recursions on `Nat`\n-/\n\nuniverse u\n\nnamespace Nat\n\n/-!\n## Complete induction\n\nGiven a predicate `p : Nat \u2192 Prop`, one can conclude `\u2200 n, p n` provided `\u2200 n, (\u2200 k, k < n \u2192 p k) \u2192 p n`.\n-/\n\n/-- Complete induction using well-founded recursion -/\n@[inline]\ndef recCompleteWF {motive : Nat \u2192 Sort u} (ind : (n : Nat) \u2192 (\u2200 (k : Nat), k < n \u2192 motive k) \u2192 motive n) (n : Nat) : motive n :=\n  ind n (\u03bb k _ => recCompleteWF ind k)\n\n/-- Complete induction without well-founded recursion -/\n@[implemented_by recCompleteWF]\ndef recComplete {motive : Nat \u2192 Sort u} (ind : (n : Nat) \u2192 (\u2200 (k : Nat), k < n \u2192 motive k) \u2192 motive n) (n : Nat) : motive n :=\n  let rec aux : (n k : Nat) \u2192 k \u2264 n \u2192 motive k\n  | 0, k, hk =>\n    have : k = 0 := Nat.eq_zero_of_le_zero hk\n    ind k (\u03bb l hl => absurd (this \u25b8 hl) l.not_lt_zero)\n  | _+1, 0, _ => ind 0 (\u03bb k hk => absurd hk k.not_lt_zero)\n  | n+1, k+1, hk =>\n    ind (k+1) (\u03bb l hl => aux n l (Nat.le_of_lt_succ $ Trans.trans hl hk))\n  aux n n n.le_refl\n\n/-- Proof that the two implememtations of the complete induction are equivalent. -/\ntheorem recComplete_eq {motive : Nat \u2192 Sort u} {ind : (n : Nat) \u2192 (\u2200 (k : Nat), k < n \u2192 motive k) \u2192 motive n} {n : Nat} : recComplete (motive:=motive) ind n = recCompleteWF (motive:=motive) ind n := by\n  suffices \u2200 k (hk : k \u2264 n), recComplete.aux (motive:=motive) ind n k hk = recCompleteWF (motive:=motive) ind k\n    from this n n.le_refl\n  intro k hk\n  induction n generalizing k\n  case zero =>\n    dsimp [recComplete.aux]; unfold recCompleteWF\n    have : k = 0 := k.eq_zero_of_le_zero hk\n    cases this\n    apply congrArg; funext k hk; cases hk\n  case succ n h_ind =>\n    cases k\n    case zero =>\n      dsimp [recComplete.aux]; unfold recCompleteWF\n      apply congrArg; funext k hk; cases hk\n    case succ k =>\n      dsimp [recComplete.aux]; unfold recCompleteWF\n      apply congrArg; funext k hk; rw [h_ind]\n  \n\n/-!\n## Ascending recursion with upper bound. -/\n\ndef recAscend {motive : Nat \u2192 Sort u} {n : Nat} (ceil : motive n) (ascend : \u2200 (k : Nat), k < n \u2192 motive k.succ \u2192 motive k) (k : Nat) (h : k \u2264 n) : motive k :=\n  if hlt : k < n\n    then ascend k hlt (recAscend ceil ascend k.succ (Nat.succ_le_of_lt hlt))\n    else\n      have : k = n := Nat.le_antisymm h (Nat.le_of_not_lt hlt)\n      this \u25b8 ceil\ntermination_by _ => n-k\n\n\n/-!\n### Recursion on base2 digits\n-/\n\n@[inline]\ndef recBase2 {motive : Nat \u2192 Sort u} (zero : motive 0) (one : motive 1) (div2 : (n : Nat) \u2192 motive (n/2 + 1) \u2192 motive (n + 2)) (n : Nat) : motive n :=\n  n.recComplete $ \u03bb n ind =>\n    match n with\n    | 0 => zero\n    | 1 => one\n    | n+2 =>\n      have : n/2 + 1 < n+2 := calc\n        n/2 + 1 = (n+2)/2 := Eq.symm $ Nat.add_div_right _ (Nat.zero_lt_succ 1)\n        _       < n+2     := Nat.div_lt_self (Nat.zero_lt_succ _) (Nat.lt.base 1)\n      div2 n (ind _ this)\n\nsection recBase2_rec\n\nvariable {motive : Nat \u2192 Sort u} {zero : motive 0} {one : motive 1} {div2 : (n : Nat) \u2192 motive (n/2 + 1) \u2192 motive (n+2)}\n\ntheorem recBase2_zero : recBase2 zero one div2 0 = zero := rfl\ntheorem recBase2_one : recBase2 zero one div2 1 = one := rfl\ntheorem recBase2_div2 {n : Nat} : recBase2 zero one div2 (n+2) = div2 n (recBase2 zero one div2 (n/2+1)) := by\n  unfold recBase2; rw [recComplete_eq, recComplete_eq]\n  conv =>\n    lhs; unfold recCompleteWF\n\nend recBase2_rec\n\nend Nat\n", "meta": {"author": "Junology", "repo": "algdata", "sha": "ef0e552747c3f1004705755a3afc7ccedec92bf6", "save_path": "github-repos/lean/Junology-algdata", "path": "github-repos/lean/Junology-algdata/algdata-ef0e552747c3f1004705755a3afc7ccedec92bf6/Algdata/Data/Nat/Rec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272544, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.715413704697298}}
{"text": "import .lovelib\n\n\n/- # LoVe Homework 8: Operational Semantics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1 (6 points + 1 bonus point): Semantics of the REPEAT Language\n\nWe introduce REPEAT, a programming language that resembles the WHILE language\nbut whose defining feature is a `repeat` loop.\n\nThe Lean definition of its abstract syntax tree follows: -/\n\ninductive stmt : Type\n| skip   : stmt\n| assign : string \u2192 (state \u2192 \u2115) \u2192 stmt\n| seq    : stmt \u2192 stmt \u2192 stmt\n| unless : (state \u2192 Prop) \u2192 stmt \u2192 stmt\n| repeat : \u2115 \u2192 stmt \u2192 stmt\n\ninfixr ` ;; ` : 90 := stmt.seq\n\n/- The `skip`, `assign`, and `S ;; T` statements have the same syntax and\nsemantics as in the WHILE language.\n\nThe `unless b S` statement executes `S` unless `b` is true\u2014i.e., it executes `S`\nif `b` is false. Otherwise, `unless b S` does nothing. This construct is\ninspired by the Perl language.\n\nThe `repeat n S` statement executes `S` exactly `n` times. Thus, `repeat 5 S` is\nequivalent to `S ;; S ;; S ;; S ;; S` (in terms of a big-step semantics at\nleast) and `repeat 0 S` is equivalent to `skip`.\n\n1.1 (1.5 points). Complete the following definition of a big-step\nsemantics: -/\n\ninductive big_step : stmt \u00d7 state \u2192 state \u2192 Prop\n| skip {s} :\n  big_step (stmt.skip, s) s\n-- enter the missing cases here\n\ninfix ` \u27f9 ` : 110 := big_step\n\n/- 1.2 (1.5 points). Complete the following definition of a small-step\nsemantics: -/\n\ninductive small_step : stmt \u00d7 state \u2192 stmt \u00d7 state \u2192 Prop\n| assign {x a s} :\n  small_step (stmt.assign x a, s) (stmt.skip, s{x \u21a6 a s})\n-- enter the missing cases here\n\ninfixr ` \u21d2 ` := small_step\ninfixr ` \u21d2* ` : 100 := star small_step\n\n/- 1.3 (1 point). We will now attempt to prove termination of the REPEAT\nlanguage. More precisely, we will show that there cannot be infinite chains of\nthe form\n\n    `(S\u2080, s\u2080) \u21d2 (S\u2081, s\u2081) \u21d2 (S\u2082, s\u2082) \u21d2 \u22ef`\n\nTowards this goal, you are asked to define a __measure__ function: a function\n`mess` that takes a statement `S` and that returns a natural number indicating\nhow \"big\" the statement is. The measure should be defined so that it strictly\ndecreases with each small-step transition. -/\n\ndef mess : stmt \u2192 \u2115\n| stmt.skip         := 0\n-- enter the missing cases here\n\n/- 1.4 (1 point). Consider the following program `S\u2080`: -/\n\ndef incr (x : string) : stmt :=\nstmt.assign x (\u03bbs, s x + 1)\n\ndef S\u2080 : stmt :=\nstmt.repeat 1 (incr \"m\" ;; incr \"n\")\n\n/- Check that `mess` strictly decreases with each step of its small-step\nevaluation, by giving `S\u2080`, `S\u2081`, `S\u2082`, \u2026, as well as the corresponding values\nof `mess` (which you can obtain using `#eval`). -/\n\n-- enter your answer here\n\n/- 1.5 (1 point). Prove that the measure decreases with each small-step\ntransition. If necessary, revise your answer to question 1.3. -/\n\nlemma small_step_mess_decreases {Ss Tt : stmt \u00d7 state} (h : Ss \u21d2 Tt) :\n  mess (prod.fst Ss) > mess (prod.fst Tt) :=\nsorry\n\n/- 1.6 (1 bonus point). Prove that the inverse of the `\u21d2` relation is well\nfounded. The inverse is simply `\u03bbTt Ss, Ss \u21d2 Tt`. A relation `\u227a` is well founded\nif there exist no infinite left-descending chains of the form\n\n    `\u22ef \u227a x\u2082 \u227a x\u2081 \u227a x\u2080`\n\nProof strategy: The `measure` function from `mathlib` converts a function to `\u2115`\nto a relation, using `<` to compare two numbers. Hence, start by proving that\n`measure mess`, or rather `measure (mess \u2218 prod.fst)`, is well founded. Here,\n`library_search` can help, or just search manually in `wf.lean`, close to the\ndefinition of `measure`. Then prove that `\u03bbTt Ss, Ss \u21d2 Tt` is a subrelation of\n`measure (mess \u2218 prod.fst)` (using lemma `small_step_mess_decreases` from\nquestion 1.4) and therefore (using another lemma from `wf.lean`) that it must be\nwell founded. -/\n\nlemma small_step_wf :\n  well_founded (\u03bbTt Ss, Ss \u21d2 Tt) :=\nsorry\n\n\n/- ## Question 2 (3 points): Inversion Rules\n\n2.1 (1 point). Prove the following inversion rule for the big-step semantics\nof `unless`. -/\n\nlemma big_step_ite_iff {b S s t} :\n  (stmt.unless b S, s) \u27f9 t \u2194 (b s \u2227 s = t) \u2228 (\u00ac b s \u2227 (S, s) \u27f9 t) :=\nsorry\n\n/- 2.2 (2 points). Prove the following inversion rule for the big-step\nsemantics of `repeat`. -/\n\nlemma big_step_repeat_iff {n S s u} :\n  (stmt.repeat n S, s) \u27f9 u \u2194\n  (n = 0 \u2227 u = s)\n  \u2228 (\u2203m t, n = m + 1 \u2227 (S, s) \u27f9 t \u2227 (stmt.repeat m S, t) \u27f9 u) :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love08_operational_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733955639775, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7154136916804701}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.derivative\nimport tactic.ring_exp\n\n/-!\n# Theory of univariate polynomials\n\nThe main def is `binom_expansion`.\n-/\n\nnoncomputable theory\n\nnamespace polynomial\nuniverses u v w x y z\nvariables {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type x} {k : Type y} {A : Type z}\n  {a b : R} {m n : \u2115}\n\nsection identities\n\n/- @TODO: pow_add_expansion and pow_sub_pow_factor are not specific to polynomials.\n  These belong somewhere else. But not in group_power because they depend on tactic.ring_exp\n\nMaybe use data.nat.choose to prove it.\n -/\n/--\n`(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring.\n-/\ndef pow_add_expansion {R : Type*} [comm_semiring R] (x y : R) : \u2200 (n : \u2115),\n  {k // (x + y)^n = x^n + n*x^(n-1)*y + k * y^2}\n| 0 := \u27e80, by simp\u27e9\n| 1 := \u27e80, by simp\u27e9\n| (n+2) :=\n  begin\n    cases pow_add_expansion (n+1) with z hz,\n    existsi x*z + (n+1)*x^n+z*y,\n    calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) : by ring_exp\n    ... = (x + y) * (x ^ (n + 1) + \u2191(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) : by rw hz\n    ... = x ^ (n + 2) + \u2191(n + 2) * x ^ (n + 1) * y + (x*z + (n+1)*x^n+z*y) * y ^ 2 :\n      by { push_cast, ring_exp! }\n  end\n\nvariables [comm_ring R]\n\nprivate def poly_binom_aux1 (x y : R) (e : \u2115) (a : R) :\n  {k : R // a * (x + y)^e = a * (x^e + e*x^(e-1)*y + k*y^2)} :=\nbegin\n  existsi (pow_add_expansion x y e).val,\n  congr,\n  apply (pow_add_expansion _ _ _).property\nend\n\nprivate lemma poly_binom_aux2 (f : polynomial R) (x y : R) :\n  f.eval (x + y) = f.sum (\u03bb e a, a * (x^e + e*x^(e-1)*y + (poly_binom_aux1 x y e a).val*y^2)) :=\nbegin\n  unfold eval eval\u2082, congr' with n z,\n  apply (poly_binom_aux1 x y _ _).property\nend\n\nprivate lemma poly_binom_aux3 (f : polynomial R) (x y : R) : f.eval (x + y) =\n  f.sum (\u03bb e a, a * x^e) +\n  f.sum (\u03bb e a, (a * e * x^(e-1)) * y) +\n  f.sum (\u03bb e a, (a *(poly_binom_aux1 x y e a).val)*y^2) :=\nby { rw poly_binom_aux2, simp [left_distrib, sum_add, mul_assoc] }\n\n/--\nA polynomial `f` evaluated at `x + y` can be expressed as\nthe evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`,\nplus some element `k : R` times `y^2`.\n-/\ndef binom_expansion (f : polynomial R) (x y : R) :\n  {k : R // f.eval (x + y) = f.eval x + (f.derivative.eval x) * y + k * y^2} :=\nbegin\n  existsi f.sum (\u03bb e a, a *((poly_binom_aux1 x y e a).val)),\n  rw poly_binom_aux3,\n  congr,\n  { rw [\u2190eval_eq_sum], },\n  { rw derivative_eval, exact finset.sum_mul.symm },\n  { exact finset.sum_mul.symm }\nend\n\n/--\n`x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring.\n-/\ndef pow_sub_pow_factor (x y : R) : \u03a0 (i : \u2115), {z : R // x^i - y^i = z * (x - y)}\n| 0 := \u27e80, by simp\u27e9\n| 1 := \u27e81, by simp\u27e9\n| (k+2) :=\n  begin\n    cases @pow_sub_pow_factor (k+1) with z hz,\n    existsi z*x + y^(k+1),\n    calc x ^ (k + 2) - y ^ (k + 2)\n        = x * (x ^ (k + 1) - y ^ (k + 1)) + (x * y ^ (k + 1) - y ^ (k + 2)) : by ring_exp\n    ... = x * (z * (x - y)) + (x * y ^ (k + 1) - y ^ (k + 2)) : by rw hz\n    ... = (z * x + y ^ (k + 1)) * (x - y) : by ring_exp\n  end\n\n/--\nFor any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)`\nfor some `z` in the ring.\n-/\ndef eval_sub_factor (f : polynomial R) (x y : R) :\n  {z : R // f.eval x - f.eval y = z * (x - y)} :=\nbegin\n  refine \u27e8f.sum (\u03bb i r, r * (pow_sub_pow_factor x y i).val), _\u27e9,\n  delta eval eval\u2082,\n  simp only [sum, \u2190 finset.sum_sub_distrib, finset.sum_mul],\n  dsimp,\n  congr' with i r,\n  rw [mul_assoc, \u2190(pow_sub_pow_factor x y _).prop, mul_sub],\nend\n\nend identities\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/polynomial/identities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7153932197796039}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport category_theory.elements\nimport category_theory.is_connected\nimport category_theory.single_obj\nimport group_theory.group_action.basic\nimport group_theory.semidirect_product\n\n/-!\n# Actions as functors and as categories\n\nFrom a multiplicative action M \u21bb X, we can construct a functor from M to the category of\ntypes, mapping the single object of M to X and an element `m : M` to map `X \u2192 X` given by\nmultiplication by `m`.\n  This functor induces a category structure on X -- a special case of the category of elements.\nA morphism `x \u27f6 y` in this category is simply a scalar `m : M` such that `m \u2022 x = y`. In the case\nwhere M is a group, this category is a groupoid -- the `action groupoid'.\n-/\n\nopen mul_action semidirect_product\nnamespace category_theory\n\nuniverses u\n\nvariables (M : Type*) [monoid M] (X : Type u) [mul_action M X]\n\n/-- A multiplicative action M \u21bb X viewed as a functor mapping the single object of M to X\n  and an element `m : M` to the map `X \u2192 X` given by multiplication by `m`. -/\n@[simps]\ndef action_as_functor : single_obj M \u2964 Type u :=\n{ obj := \u03bb _, X,\n  map := \u03bb _ _, (\u2022),\n  map_id' := \u03bb _, funext $ mul_action.one_smul,\n  map_comp' := \u03bb _ _ _ f g, funext $ \u03bb x, (smul_smul g f x).symm }\n\n/-- A multiplicative action M \u21bb X induces a category strucure on X, where a morphism\n from x to y is a scalar taking x to y. Due to implementation details, the object type\n of this category is not equal to X, but is in bijection with X. -/\n@[derive category]\ndef action_category := (action_as_functor M X).elements\n\nnamespace action_category\n\n/-- The projection from the action category to the monoid, mapping a morphism to its\n  label. -/\ndef \u03c0 : action_category M X \u2964 single_obj M :=\ncategory_of_elements.\u03c0 _\n\n@[simp]\nlemma \u03c0_map (p q : action_category M X) (f : p \u27f6 q) : (\u03c0 M X).map f = f.val := rfl\n\n@[simp]\nlemma \u03c0_obj (p : action_category M X) : (\u03c0 M X).obj p = single_obj.star M :=\nunit.ext\n\nvariables {M X}\n/-- The canonical map `action_category M X \u2192 X`. It is given by `\u03bb x, x.snd`, but\n  has a more explicit type. -/\nprotected def back : action_category M X \u2192 X :=\n\u03bb x, x.snd\n\ninstance : has_coe_t X (action_category M X) :=\n\u27e8\u03bb x, \u27e8(), x\u27e9\u27e9\n\n@[simp] lemma coe_back (x : X) : (\u2191x : action_category M X).back = x := rfl\n@[simp] lemma back_coe (x : action_category M X) : \u2191(x.back) = x := by ext; refl\n\nvariables (M X)\n\n/-- An object of the action category given by M \u21bb X corresponds to an element of X. -/\ndef obj_equiv : X \u2243 action_category M X :=\n{ to_fun := coe,\n  inv_fun := \u03bb x, x.back,\n  left_inv := coe_back,\n  right_inv := back_coe }\n\nlemma hom_as_subtype (p q : action_category M X) :\n  (p \u27f6 q) = { m : M // m \u2022 p.back = q.back } := rfl\n\ninstance [inhabited X] : inhabited (action_category M X) :=\n{ default := \u2191(default X) }\n\ninstance [nonempty X] : nonempty (action_category M X) :=\nnonempty.map (obj_equiv M X) infer_instance\n\nvariables {X} (x : X)\n/-- The stabilizer of a point is isomorphic to the endomorphism monoid at the\n  corresponding point. In fact they are definitionally equivalent. -/\ndef stabilizer_iso_End : stabilizer.submonoid M x \u2243* End (\u2191x : action_category M X) :=\nmul_equiv.refl _\n\n@[simp]\nlemma stabilizer_iso_End_apply (f : stabilizer.submonoid M x) :\n  (stabilizer_iso_End M x).to_fun f = f := rfl\n\n@[simp]\nlemma stabilizer_iso_End_symm_apply (f : End _) :\n  (stabilizer_iso_End M x).inv_fun f = f := rfl\n\nvariables {M X}\n\n@[simp] protected \n\n@[simp] protected lemma comp_val {x y z : action_category M X}\n  (f : x \u27f6 y) (g : y \u27f6 z) : (f \u226b g).val = g.val * f.val := rfl\n\ninstance [is_pretransitive M X] [nonempty X] : is_connected (action_category M X) :=\nzigzag_is_connected $ \u03bb x y, relation.refl_trans_gen.single $ or.inl $\n  nonempty_subtype.mpr (show _, from exists_smul_eq M x.back y.back)\n\nsection group\n\nvariables {G : Type*} [group G] [mul_action G X]\n\nnoncomputable instance : groupoid (action_category G X) :=\ncategory_theory.groupoid_of_elements _\n\n/-- Any subgroup of `G` is a vertex group in its action groupoid. -/\ndef End_mul_equiv_subgroup (H : subgroup G) :\n  End (obj_equiv G (quotient_group.quotient H) \u2191(1 : G)) \u2243* H :=\nmul_equiv.trans\n  (stabilizer_iso_End G ((1 : G) : quotient_group.quotient H)).symm\n  (mul_equiv.subgroup_congr $ stabilizer_quotient H)\n\n/-- A target vertex `t` and a scalar `g` determine a morphism in the action groupoid. -/\ndef hom_of_pair (t : X) (g : G) : \u2191(g\u207b\u00b9 \u2022 t) \u27f6 (t : action_category G X) :=\nsubtype.mk g (smul_inv_smul g t)\n\n@[simp] lemma hom_of_pair.val (t : X) (g : G) : (hom_of_pair t g).val = g := rfl\n\n/-- Any morphism in the action groupoid is given by some pair. -/\nprotected def cases {P : \u03a0 \u2983a b : action_category G X\u2984, (a \u27f6 b) \u2192 Sort*}\n  (hyp : \u2200 t g, P (hom_of_pair t g)) \u2983a b\u2984 (f : a \u27f6 b) : P f :=\nbegin\n  refine cast _ (hyp b.back f.val),\n  rcases a with \u27e8\u27e8\u27e9, a : X\u27e9,\n  rcases b with \u27e8\u27e8\u27e9, b : X\u27e9,\n  rcases f with \u27e8g : G, h : g \u2022 a = b\u27e9,\n  cases (inv_smul_eq_iff.mpr h.symm),\n  refl\nend\n\nvariables {H : Type*} [group H]\n\n/-- Given `G` acting on `X`, a functor from the corresponding action groupoid to a group `H`\n    can be curried to a group homomorphism `G \u2192* (X \u2192 H) \u22ca G`. -/\n@[simps] def curry (F : action_category G X \u2964 single_obj H) :\n  G \u2192* (X \u2192 H) \u22ca[mul_aut_arrow] G :=\nhave F_map_eq : \u2200 {a b} {f : a \u27f6 b}, F.map f = (F.map (hom_of_pair b.back f.val) : H) :=\n  action_category.cases (\u03bb _ _, rfl),\n{ to_fun := \u03bb g, \u27e8\u03bb b, F.map (hom_of_pair b g), g\u27e9,\n  map_one' := by { congr, funext, exact F_map_eq.symm.trans (F.map_id b) },\n  map_mul' := begin\n    intros g h,\n    congr, funext,\n    exact F_map_eq.symm.trans (F.map_comp (hom_of_pair (g\u207b\u00b9 \u2022 b) h) (hom_of_pair b g)),\n  end }\n\n/-- Given `G` acting on `X`, a group homomorphism `\u03c6 : G \u2192* (X \u2192 H) \u22ca G` can be uncurried to\n    a functor from the action groupoid to `H`, provided that `\u03c6 g = (_, g)` for all `g`. -/\n@[simps] def uncurry (F : G \u2192* (X \u2192 H) \u22ca[mul_aut_arrow] G) (sane : \u2200 g, (F g).right = g) :\n  action_category G X \u2964 single_obj H :=\n{ obj := \u03bb _, (),\n  map := \u03bb a b f, ((F f.val).left b.back),\n  map_id' := by { intro x, rw [action_category.id_val, F.map_one], refl },\n  map_comp' := begin\n    intros x y z f g, revert y z g,\n    refine action_category.cases _,\n    simp [single_obj.comp_as_mul, sane],\n  end }\n\nend group\n\nend action_category\nend category_theory\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/category_theory/action.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7153932002573523}}
{"text": "/-\nCopyright (c) 2020 Ashvni Narayanan. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ashvni Narayanan\n-/\n\nimport deprecated.subring\nimport group_theory.subgroup\nimport ring_theory.subsemiring\n\n/-!\n# Subrings\n\nLet `R` be a ring. This file defines the \"bundled\" subring type `subring R`, a type\nwhose terms correspond to subrings of `R`. This is the preferred way to talk\nabout subrings in mathlib. Unbundled subrings (`s : set R` and `is_subring s`)\nare not in this file, and they will ultimately be deprecated.\n\nWe prove that subrings are a complete lattice, and that you can `map` (pushforward) and\n`comap` (pull back) them along ring homomorphisms.\n\nWe define the `closure` construction from `set R` to `subring R`, sending a subset of `R`\nto the subring it generates, and prove that it is a Galois insertion.\n\n## Main definitions\n\nNotation used here:\n\n`(R : Type u) [ring R] (S : Type u) [ring S] (f g : R \u2192+* S)`\n`(A : subring R) (B : subring S) (s : set R)`\n\n* `subring R` : the type of subrings of a ring `R`.\n\n* `instance : complete_lattice (subring R)` : the complete lattice structure on the subrings.\n\n* `subring.closure` : subring closure of a set, i.e., the smallest subring that includes the set.\n\n* `subring.gi` : `closure : set M \u2192 subring M` and coercion `coe : subring M \u2192 set M`\n  form a `galois_insertion`.\n\n* `comap f B : subring A` : the preimage of a subring `B` along the ring homomorphism `f`\n\n* `map f A : subring B` : the image of a subring `A` along the ring homomorphism `f`.\n\n* `prod A B : subring (R \u00d7 S)` : the product of subrings\n\n* `f.range : subring B` : the range of the ring homomorphism `f`.\n\n* `eq_locus f g : subring R` : given ring homomorphisms `f g : R \u2192+* S`,\n     the subring of `R` where `f x = g x`\n\n## Implementation notes\n\nA subring is implemented as a subsemiring which is also an additive subgroup.\nThe initial PR was as a submonoid which is also an additive subgroup.\n\nLattice inclusion (e.g. `\u2264` and `\u2293`) is used rather than set notation (`\u2286` and `\u2229`), although\n`\u2208` is defined as membership of a subring's underlying set.\n\n## Tags\nsubring, subrings\n-/\n\nopen_locale big_operators\nuniverses u v w\n\nvariables {R : Type u} {S : Type v} {T : Type w} [ring R] [ring S] [ring T]\n\nset_option old_structure_cmd true\n\n/-- `subring R` is the type of subrings of `R`. A subring of `R` is a subset `s` that is a\n  multiplicative submonoid and an additive subgroup. Note in particular that it shares the\n  same 0 and 1 as R. -/\nstructure subring (R : Type u) [ring R] extends subsemiring R, add_subgroup R\n\n/-- Reinterpret a `subring` as a `subsemiring`. -/\nadd_decl_doc subring.to_subsemiring\n\n/-- Reinterpret a `subring` as an `add_subgroup`. -/\nadd_decl_doc subring.to_add_subgroup\n\nnamespace subring\n\n/-- The underlying submonoid of a subring. -/\ndef to_submonoid (s : subring R) : submonoid R :=\n{ carrier := s.carrier,\n  ..s.to_subsemiring.to_submonoid }\n\ninstance : set_like (subring R) R :=\n\u27e8subring.carrier, \u03bb p q h, by cases p; cases q; congr'\u27e9\n\n@[simp]\nlemma mem_carrier {s : subring R} {x : R} : x \u2208 s.carrier \u2194 x \u2208 s := iff.rfl\n\n/-- Two subrings are equal if they have the same elements. -/\n@[ext] theorem ext {S T : subring R} (h : \u2200 x, x \u2208 S \u2194 x \u2208 T) : S = T := set_like.ext h\n\n/-- Copy of a subring with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : subring R) (s : set R) (hs : s = \u2191S) : subring R :=\n{ carrier := s,\n  neg_mem' := hs.symm \u25b8 S.neg_mem',\n  ..S.to_subsemiring.copy s hs }\n\nlemma to_subsemiring_injective : function.injective (to_subsemiring : subring R \u2192 subsemiring R)\n| r s h := ext (set_like.ext_iff.mp h : _)\n\n@[mono]\nlemma to_subsemiring_strict_mono : strict_mono (to_subsemiring : subring R \u2192 subsemiring R) :=\n\u03bb _ _, id\n\n@[mono]\nlemma to_subsemiring_mono : monotone (to_subsemiring : subring R \u2192 subsemiring R) :=\nto_subsemiring_strict_mono.monotone\n\nlemma to_add_subgroup_injective : function.injective (to_add_subgroup : subring R \u2192 add_subgroup R)\n| r s h := ext (set_like.ext_iff.mp h : _)\n\n@[mono]\nlemma to_add_subgroup_strict_mono : strict_mono (to_add_subgroup : subring R \u2192 add_subgroup R) :=\n\u03bb _ _, id\n\n@[mono]\nlemma to_add_subgroup_mono : monotone (to_add_subgroup : subring R \u2192 add_subgroup R) :=\nto_add_subgroup_strict_mono.monotone\n\nlemma to_submonoid_injective : function.injective (to_submonoid : subring R \u2192 submonoid R)\n| r s h := ext (set_like.ext_iff.mp h : _)\n\n@[mono]\nlemma to_submonoid_strict_mono : strict_mono (to_submonoid : subring R \u2192 submonoid R) :=\n\u03bb _ _, id\n\n@[mono]\nlemma to_submonoid_mono : monotone (to_submonoid : subring R \u2192 submonoid R) :=\nto_submonoid_strict_mono.monotone\n\n/-- Construct a `subring R` from a set `s`, a submonoid `sm`, and an additive\nsubgroup `sa` such that `x \u2208 s \u2194 x \u2208 sm \u2194 x \u2208 sa`. -/\nprotected def mk' (s : set R) (sm : submonoid R) (sa : add_subgroup R)\n  (hm : \u2191sm = s) (ha : \u2191sa = s) :\n  subring R :=\n{ carrier := s,\n  zero_mem' := ha \u25b8 sa.zero_mem,\n  one_mem' := hm \u25b8 sm.one_mem,\n  add_mem' := \u03bb x y, by simpa only [\u2190 ha] using sa.add_mem,\n  mul_mem' := \u03bb x y, by simpa only [\u2190 hm] using sm.mul_mem,\n  neg_mem' := \u03bb x, by simpa only [\u2190 ha] using sa.neg_mem, }\n\n@[simp] lemma coe_mk' {s : set R} {sm : submonoid R} (hm : \u2191sm = s)\n  {sa : add_subgroup R} (ha : \u2191sa = s) :\n  (subring.mk' s sm sa hm ha : set R) = s := rfl\n\n@[simp] lemma mem_mk' {s : set R} {sm : submonoid R} (hm : \u2191sm = s)\n  {sa : add_subgroup R} (ha : \u2191sa = s) {x : R} :\n  x \u2208 subring.mk' s sm sa hm ha \u2194 x \u2208 s :=\niff.rfl\n\n@[simp] lemma mk'_to_submonoid {s : set R} {sm : submonoid R} (hm : \u2191sm = s)\n  {sa : add_subgroup R} (ha : \u2191sa = s) :\n  (subring.mk' s sm sa hm ha).to_submonoid = sm :=\nset_like.coe_injective hm.symm\n\n@[simp] lemma mk'_to_add_subgroup {s : set R} {sm : submonoid R} (hm : \u2191sm = s)\n  {sa : add_subgroup R} (ha : \u2191sa  =s) :\n  (subring.mk' s sm sa hm ha).to_add_subgroup = sa :=\nset_like.coe_injective ha.symm\n\nend subring\n\n/-- Construct a `subring` from a set satisfying `is_subring`. -/\ndef set.to_subring (S : set R) [is_subring S] : subring R :=\n{ carrier := S,\n  one_mem' := is_submonoid.one_mem,\n  mul_mem' := \u03bb a b, is_submonoid.mul_mem,\n  zero_mem' := is_add_submonoid.zero_mem,\n  add_mem' := \u03bb a b, is_add_submonoid.add_mem,\n  neg_mem' := \u03bb a, is_add_subgroup.neg_mem }\n\n/-- A `subsemiring` containing -1 is a `subring`. -/\ndef subsemiring.to_subring (s : subsemiring R) (hneg : (-1 : R) \u2208 s) : subring R :=\n{ neg_mem' := by { rintros x, rw <-neg_one_mul, apply subsemiring.mul_mem, exact hneg, }\n..s.to_submonoid, ..s.to_add_submonoid }\n\nnamespace subring\n\nvariables (s : subring R)\n\n/-- A subring contains the ring's 1. -/\ntheorem one_mem : (1 : R) \u2208 s := s.one_mem'\n\n/-- A subring contains the ring's 0. -/\ntheorem zero_mem : (0 : R) \u2208 s := s.zero_mem'\n\n/-- A subring is closed under multiplication. -/\ntheorem mul_mem : \u2200 {x y : R}, x \u2208 s \u2192 y \u2208 s \u2192 x * y \u2208 s := s.mul_mem'\n\n/-- A subring is closed under addition. -/\ntheorem add_mem : \u2200 {x y : R}, x \u2208 s \u2192 y \u2208 s \u2192 x + y \u2208 s := s.add_mem'\n\n/-- A subring is closed under negation. -/\ntheorem neg_mem : \u2200 {x : R}, x \u2208 s \u2192 -x \u2208 s := s.neg_mem'\n\n/-- A subring is closed under subtraction -/\ntheorem sub_mem {x y : R} (hx : x \u2208 s) (hy : y \u2208 s) : x - y \u2208 s :=\nby { rw sub_eq_add_neg, exact s.add_mem hx (s.neg_mem hy) }\n\n/-- Product of a list of elements in a subring is in the subring. -/\nlemma list_prod_mem {l : list R} : (\u2200x \u2208 l, x \u2208 s) \u2192 l.prod \u2208 s :=\ns.to_submonoid.list_prod_mem\n\n/-- Sum of a list of elements in a subring is in the subring. -/\nlemma list_sum_mem {l : list R} : (\u2200x \u2208 l, x \u2208 s) \u2192 l.sum \u2208 s :=\ns.to_add_subgroup.list_sum_mem\n\n/-- Product of a multiset of elements in a subring of a `comm_ring` is in the subring. -/\nlemma multiset_prod_mem {R} [comm_ring R] (s : subring R) (m : multiset R) :\n  (\u2200a \u2208 m, a \u2208 s) \u2192 m.prod \u2208 s :=\ns.to_submonoid.multiset_prod_mem m\n\n/-- Sum of a multiset of elements in an `subring` of a `ring` is\nin the `subring`. -/\nlemma multiset_sum_mem {R} [ring R] (s : subring R) (m : multiset R) :\n  (\u2200a \u2208 m, a \u2208 s) \u2192 m.sum \u2208 s :=\ns.to_add_subgroup.multiset_sum_mem m\n\n/-- Product of elements of a subring of a `comm_ring` indexed by a `finset` is in the\n    subring. -/\nlemma prod_mem {R : Type*} [comm_ring R] (s : subring R)\n  {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 R} (h : \u2200c \u2208 t, f c \u2208 s) :\n  \u220f i in t, f i \u2208 s :=\ns.to_submonoid.prod_mem h\n\n/-- Sum of elements in a `subring` of a `ring` indexed by a `finset`\nis in the `subring`. -/\nlemma sum_mem {R : Type*} [ring R] (s : subring R)\n  {\u03b9 : Type*} {t : finset \u03b9} {f : \u03b9 \u2192 R} (h : \u2200c \u2208 t, f c \u2208 s) :\n  \u2211 i in t, f i \u2208 s :=\ns.to_add_subgroup.sum_mem h\n\nlemma pow_mem {x : R} (hx : x \u2208 s) (n : \u2115) : x^n \u2208 s := s.to_submonoid.pow_mem hx n\n\nlemma gsmul_mem {x : R} (hx : x \u2208 s) (n : \u2124) :\n  n \u2022 x \u2208 s := s.to_add_subgroup.gsmul_mem hx n\n\nlemma coe_int_mem (n : \u2124) : (n : R) \u2208 s :=\nby simp only [\u2190 gsmul_one, gsmul_mem, one_mem]\n\n/-- A subring of a ring inherits a ring structure -/\ninstance to_ring : ring s :=\n{ right_distrib := \u03bb x y z, subtype.eq $ right_distrib x y z,\n  left_distrib := \u03bb x y z, subtype.eq $ left_distrib x y z,\n  .. s.to_submonoid.to_monoid, .. s.to_add_subgroup.to_add_comm_group }\n\n@[simp, norm_cast] lemma coe_add (x y : s) : (\u2191(x + y) : R) = \u2191x + \u2191y := rfl\n@[simp, norm_cast] lemma coe_neg (x : s) : (\u2191(-x) : R) = -\u2191x := rfl\n@[simp, norm_cast] lemma coe_mul (x y : s) : (\u2191(x * y) : R) = \u2191x * \u2191y := rfl\n@[simp, norm_cast] lemma coe_zero : ((0 : s) : R) = 0 := rfl\n@[simp, norm_cast] lemma coe_one : ((1 : s) : R) = 1 := rfl\n@[simp, norm_cast] lemma coe_pow (x : s) (n : \u2115) : (\u2191(x ^ n) : R) = x ^ n :=\ns.to_submonoid.coe_pow x n\n\n@[simp] lemma coe_eq_zero_iff {x : s} : (x : R) = 0 \u2194 x = 0 :=\n\u27e8\u03bb h, subtype.ext (trans h s.coe_zero.symm),\n \u03bb h, h.symm \u25b8 s.coe_zero\u27e9\n\n/-- A subring of a `comm_ring` is a `comm_ring`. -/\ninstance to_comm_ring {R} [comm_ring R] (s : subring R) : comm_ring s :=\n{ mul_comm := \u03bb _ _, subtype.eq $ mul_comm _ _, ..subring.to_ring s}\n\n/-- A subring of a non-trivial ring is non-trivial. -/\ninstance {R} [ring R] [nontrivial R] (s : subring R) : nontrivial s :=\ns.to_subsemiring.nontrivial\n\n/-- A subring of a ring with no zero divisors has no zero divisors. -/\ninstance {R} [ring R] [no_zero_divisors R] (s : subring R) : no_zero_divisors s :=\ns.to_subsemiring.no_zero_divisors\n\n/-- A subring of an integral domain is an integral domain. -/\ninstance {R} [integral_domain R] (s : subring R) : integral_domain s :=\n{ .. s.nontrivial, .. s.no_zero_divisors, .. s.to_comm_ring }\n\n/-- A subring of an `ordered_ring` is an `ordered_ring`. -/\ninstance to_ordered_ring {R} [ordered_ring R] (s : subring R) : ordered_ring s :=\nsubtype.coe_injective.ordered_ring coe rfl rfl (\u03bb _ _, rfl) (\u03bb _ _, rfl) (\u03bb _, rfl) (\u03bb _ _, rfl)\n\n/-- A subring of an `ordered_comm_ring` is an `ordered_comm_ring`. -/\ninstance to_ordered_comm_ring {R} [ordered_comm_ring R] (s : subring R) : ordered_comm_ring s :=\nsubtype.coe_injective.ordered_comm_ring coe rfl rfl\n  (\u03bb _ _, rfl) (\u03bb _ _, rfl) (\u03bb _, rfl) (\u03bb _ _, rfl)\n\n/-- A subring of a `linear_ordered_ring` is a `linear_ordered_ring`. -/\ninstance to_linear_ordered_ring {R} [linear_ordered_ring R] (s : subring R) :\n  linear_ordered_ring s :=\nsubtype.coe_injective.linear_ordered_ring coe rfl rfl\n  (\u03bb _ _, rfl) (\u03bb _ _, rfl) (\u03bb _, rfl) (\u03bb _ _, rfl)\n\n/-- A subring of a `linear_ordered_comm_ring` is a `linear_ordered_comm_ring`. -/\ninstance to_linear_ordered_comm_ring {R} [linear_ordered_comm_ring R] (s : subring R) :\n  linear_ordered_comm_ring s :=\nsubtype.coe_injective.linear_ordered_comm_ring coe rfl rfl\n  (\u03bb _ _, rfl) (\u03bb _ _, rfl) (\u03bb _, rfl) (\u03bb _ _, rfl)\n\n/-- The natural ring hom from a subring of ring `R` to `R`. -/\ndef subtype (s : subring R) : s \u2192+* R :=\n{ to_fun := coe,\n .. s.to_submonoid.subtype, .. s.to_add_subgroup.subtype }\n\n@[simp] theorem coe_subtype : \u21d1s.subtype = coe := rfl\n@[simp, norm_cast] lemma coe_nat_cast (n : \u2115) : ((n : s) : R) = n :=\ns.subtype.map_nat_cast n\n@[simp, norm_cast] lemma coe_int_cast (n : \u2124) : ((n : s) : R) = n :=\ns.subtype.map_int_cast n\n\n/-! # Partial order -/\n\n@[simp] lemma mem_to_submonoid {s : subring R} {x : R} : x \u2208 s.to_submonoid \u2194 x \u2208 s := iff.rfl\n@[simp] lemma coe_to_submonoid (s : subring R) : (s.to_submonoid : set R) = s := rfl\n@[simp] lemma mem_to_add_subgroup {s : subring R} {x : R} :\n  x \u2208 s.to_add_subgroup \u2194 x \u2208 s := iff.rfl\n@[simp] lemma coe_to_add_subgroup (s : subring R) : (s.to_add_subgroup : set R) = s := rfl\n\n/-! # top -/\n\n/-- The subring `R` of the ring `R`. -/\ninstance : has_top (subring R) :=\n\u27e8{ .. (\u22a4 : submonoid R), .. (\u22a4 : add_subgroup R) }\u27e9\n\n@[simp] lemma mem_top (x : R) : x \u2208 (\u22a4 : subring R) := set.mem_univ x\n\n@[simp] lemma coe_top : ((\u22a4 : subring R) : set R) = set.univ := rfl\n\n/-! # comap -/\n\n/-- The preimage of a subring along a ring homomorphism is a subring. -/\ndef comap {R : Type u} {S : Type v} [ring R] [ring S]\n  (f : R \u2192+* S) (s : subring S) : subring R :=\n{ carrier := f \u207b\u00b9' s.carrier,\n .. s.to_submonoid.comap (f : R \u2192* S),\n  .. s.to_add_subgroup.comap (f : R \u2192+ S) }\n\n@[simp] lemma coe_comap (s : subring S) (f : R \u2192+* S) : (s.comap f : set R) = f \u207b\u00b9' s := rfl\n\n@[simp]\nlemma mem_comap {s : subring S} {f : R \u2192+* S} {x : R} : x \u2208 s.comap f \u2194 f x \u2208 s := iff.rfl\n\nlemma comap_comap (s : subring T) (g : S \u2192+* T) (f : R \u2192+* S) :\n  (s.comap g).comap f = s.comap (g.comp f) :=\nrfl\n\n/-! # map -/\n\n/-- The image of a subring along a ring homomorphism is a subring. -/\ndef map {R : Type u} {S : Type v} [ring R] [ring S]\n  (f : R \u2192+* S) (s : subring R) : subring S :=\n  { carrier := f '' s.carrier,\n.. s.to_submonoid.map (f : R \u2192* S),\n.. s.to_add_subgroup.map (f : R \u2192+ S) }\n\n@[simp] lemma coe_map (f : R \u2192+* S) (s : subring R) : (s.map f : set S) = f '' s := rfl\n\n@[simp] lemma mem_map {f : R \u2192+* S} {s : subring R} {y : S} :\n  y \u2208 s.map f \u2194 \u2203 x \u2208 s, f x = y :=\nset.mem_image_iff_bex\n\nlemma map_map (g : S \u2192+* T) (f : R \u2192+* S) : (s.map f).map g = s.map (g.comp f) :=\nset_like.coe_injective $ set.image_image _ _ _\n\nlemma map_le_iff_le_comap {f : R \u2192+* S} {s : subring R} {t : subring S} :\n  s.map f \u2264 t \u2194 s \u2264 t.comap f :=\nset.image_subset_iff\n\nlemma gc_map_comap (f : R \u2192+* S) : galois_connection (map f) (comap f) :=\n\u03bb S T, map_le_iff_le_comap\n\nend subring\n\nnamespace ring_hom\n\nvariables (g : S \u2192+* T) (f : R \u2192+* S)\n\n/-! # range -/\n\n/-- The range of a ring homomorphism, as a subring of the target. See Note [range copy pattern]. -/\ndef range {R : Type u} {S : Type v} [ring R] [ring S] (f : R \u2192+* S) : subring S :=\n((\u22a4 : subring R).map f).copy (set.range f) set.image_univ.symm\n\n@[simp] lemma coe_range : (f.range : set S) = set.range f := rfl\n\n@[simp] lemma mem_range {f : R \u2192+* S} {y : S} : y \u2208 f.range \u2194 \u2203 x, f x = y := iff.rfl\n\nlemma range_eq_map (f : R \u2192+* S) : f.range = subring.map f \u22a4 :=\nby { ext, simp }\n\nlemma mem_range_self (f : R \u2192+* S) (x : R) : f x \u2208 f.range :=\nmem_range.mpr \u27e8x, rfl\u27e9\n\nlemma map_range : f.range.map g = (g.comp f).range :=\nby simpa only [range_eq_map] using (\u22a4 : subring R).map_map g f\n\n-- TODO -- rename to `cod_restrict` when is_ring_hom is deprecated\n/-- Restrict the codomain of a ring homomorphism to a subring that includes the range. -/\ndef cod_restrict' {R : Type u} {S : Type v} [ring R] [ring S] (f : R \u2192+* S)\n  (s : subring S) (h : \u2200 x, f x \u2208 s) : R \u2192+* s :=\n{ to_fun := \u03bb x, \u27e8f x, h x\u27e9,\n  map_add' := \u03bb x y, subtype.eq $ f.map_add x y,\n  map_zero' := subtype.eq f.map_zero,\n  map_mul' := \u03bb x y, subtype.eq $ f.map_mul x y,\n  map_one' := subtype.eq f.map_one }\n\nend ring_hom\n\nnamespace subring\n\n/-! # bot -/\n\ninstance : has_bot (subring R) := \u27e8(int.cast_ring_hom R).range\u27e9\n\ninstance : inhabited (subring R) := \u27e8\u22a5\u27e9\n\nlemma coe_bot : ((\u22a5 : subring R) : set R) = set.range (coe : \u2124 \u2192 R) :=\nring_hom.coe_range (int.cast_ring_hom R)\n\nlemma mem_bot {x : R} : x \u2208 (\u22a5 : subring R) \u2194 \u2203 (n : \u2124), \u2191n = x :=\nring_hom.mem_range\n\n/-! # inf -/\n\n/-- The inf of two subrings is their intersection. -/\ninstance : has_inf (subring R) :=\n\u27e8\u03bb s t,\n  { carrier := s \u2229 t,\n    .. s.to_submonoid \u2293 t.to_submonoid,\n    .. s.to_add_subgroup \u2293 t.to_add_subgroup }\u27e9\n\n@[simp] lemma coe_inf (p p' : subring R) : ((p \u2293 p' : subring R) : set R) = p \u2229 p' := rfl\n\n@[simp] lemma mem_inf {p p' : subring R} {x : R} : x \u2208 p \u2293 p' \u2194 x \u2208 p \u2227 x \u2208 p' := iff.rfl\n\ninstance : has_Inf (subring R) :=\n\u27e8\u03bb s, subring.mk' (\u22c2 t \u2208 s, \u2191t) (\u2a05 t \u2208 s, subring.to_submonoid t )\n  (\u2a05 t \u2208 s, subring.to_add_subgroup t) (by simp) (by simp)\u27e9\n\n@[simp, norm_cast] lemma coe_Inf (S : set (subring R)) :\n  ((Inf S : subring R) : set R) = \u22c2 s \u2208 S, \u2191s := rfl\n\nlemma mem_Inf {S : set (subring R)} {x : R} : x \u2208 Inf S \u2194 \u2200 p \u2208 S, x \u2208 p := set.mem_bInter_iff\n\n@[simp] lemma Inf_to_submonoid (s : set (subring R)) :\n  (Inf s).to_submonoid = \u2a05 t \u2208 s, subring.to_submonoid t := mk'_to_submonoid _ _\n\n@[simp] lemma Inf_to_add_subgroup (s : set (subring R)) :\n  (Inf s).to_add_subgroup = \u2a05 t \u2208 s, subring.to_add_subgroup t := mk'_to_add_subgroup _ _\n\n/-- Subrings of a ring form a complete lattice. -/\ninstance : complete_lattice (subring R) :=\n{ bot := (\u22a5),\n  bot_le := \u03bb s x hx, let \u27e8n, hn\u27e9 := mem_bot.1 hx in hn \u25b8 s.coe_int_mem n,\n  top := (\u22a4),\n  le_top := \u03bb s x hx, trivial,\n  inf := (\u2293),\n  inf_le_left := \u03bb s t x, and.left,\n  inf_le_right := \u03bb s t x, and.right,\n  le_inf := \u03bb s t\u2081 t\u2082 h\u2081 h\u2082 x hx, \u27e8h\u2081 hx, h\u2082 hx\u27e9,\n  .. complete_lattice_of_Inf (subring R)\n    (\u03bb s, is_glb.of_image (\u03bb s t,\n      show (s : set R) \u2264 t \u2194 s \u2264 t, from set_like.coe_subset_coe) is_glb_binfi)}\n\nlemma eq_top_iff' (A : subring R) : A = \u22a4 \u2194 \u2200 x : R, x \u2208 A :=\neq_top_iff.trans \u27e8\u03bb h m, h $ mem_top m, \u03bb h m _, h m\u27e9\n\n/-! # subring closure of a subset -/\n\n/-- The `subring` generated by a set. -/\ndef closure (s : set R) : subring R := Inf {S | s \u2286 S}\n\nlemma mem_closure {x : R} {s : set R} : x \u2208 closure s \u2194 \u2200 S : subring R, s \u2286 S \u2192 x \u2208 S :=\nmem_Inf\n\n/-- The subring generated by a set includes the set. -/\n@[simp] lemma subset_closure {s : set R} : s \u2286 closure s := \u03bb x hx, mem_closure.2 $ \u03bb S hS, hS hx\n\n/-- A subring `t` includes `closure s` if and only if it includes `s`. -/\n@[simp]\nlemma closure_le {s : set R} {t : subring R} : closure s \u2264 t \u2194 s \u2286 t :=\n\u27e8set.subset.trans subset_closure, \u03bb h, Inf_le h\u27e9\n\n/-- Subring closure of a set is monotone in its argument: if `s \u2286 t`,\nthen `closure s \u2264 closure t`. -/\nlemma closure_mono \u2983s t : set R\u2984 (h : s \u2286 t) : closure s \u2264 closure t :=\nclosure_le.2 $ set.subset.trans h subset_closure\n\nlemma closure_eq_of_le {s : set R} {t : subring R} (h\u2081 : s \u2286 t) (h\u2082 : t \u2264 closure s) :\n  closure s = t :=\nle_antisymm (closure_le.2 h\u2081) h\u2082\n\n/-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements\nof `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all\nelements of the closure of `s`. -/\n@[elab_as_eliminator]\nlemma closure_induction {s : set R} {p : R \u2192 Prop} {x} (h : x \u2208 closure s)\n  (Hs : \u2200 x \u2208 s, p x) (H0 : p 0) (H1 : p 1)\n  (Hadd : \u2200 x y, p x \u2192 p y \u2192 p (x + y))\n  (Hneg : \u2200 (x : R), p x \u2192 p (-x))\n  (Hmul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) : p x :=\n(@closure_le _ _ _ \u27e8p, H1, Hmul, H0, Hadd, Hneg\u27e9).2 Hs h\n\nlemma mem_closure_iff {s : set R} {x} :\n  x \u2208 closure s \u2194 x \u2208 add_subgroup.closure (submonoid.closure s : set R) :=\n\u27e8 \u03bb h, closure_induction h (\u03bb x hx, add_subgroup.subset_closure $ submonoid.subset_closure hx )\n (add_subgroup.zero_mem _)\n (add_subgroup.subset_closure ( submonoid.one_mem (submonoid.closure s)) )\n (\u03bb x y hx hy, add_subgroup.add_mem _ hx hy )\n (\u03bb x hx, add_subgroup.neg_mem _ hx )\n ( \u03bb x y hx hy, add_subgroup.closure_induction hy\n  (\u03bb q hq, add_subgroup.closure_induction hx\n    ( \u03bb p hp, add_subgroup.subset_closure ((submonoid.closure s).mul_mem hp hq) )\n    ( begin rw zero_mul q, apply add_subgroup.zero_mem _, end )\n    ( \u03bb p\u2081 p\u2082 ihp\u2081 ihp\u2082, begin rw add_mul p\u2081 p\u2082 q, apply add_subgroup.add_mem _ ihp\u2081 ihp\u2082, end )\n    ( \u03bb x hx, begin have f : -x * q = -(x*q) :=\n      by simp, rw f, apply add_subgroup.neg_mem _ hx, end ) )\n  ( begin rw mul_zero x, apply add_subgroup.zero_mem _, end )\n  ( \u03bb q\u2081 q\u2082 ihq\u2081 ihq\u2082, begin rw mul_add x q\u2081 q\u2082, apply add_subgroup.add_mem _ ihq\u2081 ihq\u2082 end )\n  ( \u03bb z hz, begin have f : x * -z = -(x*z) := by simp,\n            rw f, apply add_subgroup.neg_mem _ hz, end ) ),\n \u03bb h, add_subgroup.closure_induction h\n ( \u03bb x hx, submonoid.closure_induction hx\n  ( \u03bb x hx, subset_closure hx )\n  ( one_mem _ )\n  ( \u03bb x y hx hy, mul_mem _ hx hy ) )\n ( zero_mem _ )\n (\u03bb x y hx hy, add_mem _ hx hy)\n ( \u03bb x hx, neg_mem _ hx ) \u27e9\n\ntheorem exists_list_of_mem_closure {s : set R} {x : R} (h : x \u2208 closure s) :\n  (\u2203 L : list (list R), (\u2200 t \u2208 L, \u2200 y \u2208 t, y \u2208 s \u2228 y = (-1:R)) \u2227 (L.map list.prod).sum = x) :=\nadd_subgroup.closure_induction (mem_closure_iff.1 h)\n  (\u03bb x hx, let \u27e8l, hl, h\u27e9 :=submonoid.exists_list_of_mem_closure hx in \u27e8[l], by simp [h];\n    clear_aux_decl; tauto!\u27e9)\n  \u27e8[], by simp\u27e9\n  (\u03bb x y \u27e8l, hl1, hl2\u27e9 \u27e8m, hm1, hm2\u27e9, \u27e8l ++ m, \u03bb t ht, (list.mem_append.1 ht).elim (hl1 t) (hm1 t),\n    by simp [hl2, hm2]\u27e9)\n  (\u03bb x \u27e8L, hL\u27e9, \u27e8L.map (list.cons (-1)), list.forall_mem_map_iff.2 $ \u03bb j hj, list.forall_mem_cons.2\n    \u27e8or.inr rfl, hL.1 j hj\u27e9, hL.2 \u25b8 list.rec_on L (by simp)\n      (by simp [list.map_cons, add_comm] {contextual := tt})\u27e9)\n\nvariable (R)\n/-- `closure` forms a Galois insertion with the coercion to set. -/\nprotected def gi : galois_insertion (@closure R _) coe :=\n{ choice := \u03bb s _, closure s,\n  gc := \u03bb s t, closure_le,\n  le_l_u := \u03bb s, subset_closure,\n  choice_eq := \u03bb s h, rfl }\n\nvariable {R}\n\n/-- Closure of a subring `S` equals `S`. -/\nlemma closure_eq (s : subring R) : closure (s : set R) = s := (subring.gi R).l_u_eq s\n\n@[simp] lemma closure_empty : closure (\u2205 : set R) = \u22a5 := (subring.gi R).gc.l_bot\n\n@[simp] lemma closure_univ : closure (set.univ : set R) = \u22a4 := @coe_top R _ \u25b8 closure_eq \u22a4\n\nlemma closure_union (s t : set R) : closure (s \u222a t) = closure s \u2294 closure t :=\n(subring.gi R).gc.l_sup\n\nlemma closure_Union {\u03b9} (s : \u03b9 \u2192 set R) : closure (\u22c3 i, s i) = \u2a06 i, closure (s i) :=\n(subring.gi R).gc.l_supr\n\nlemma closure_sUnion (s : set (set R)) : closure (\u22c3\u2080 s) = \u2a06 t \u2208 s, closure t :=\n(subring.gi R).gc.l_Sup\n\nlemma map_sup (s t : subring R) (f : R \u2192+* S) : (s \u2294 t).map f = s.map f \u2294 t.map f :=\n(gc_map_comap f).l_sup\n\nlemma map_supr {\u03b9 : Sort*} (f : R \u2192+* S) (s : \u03b9 \u2192 subring R) :\n  (supr s).map f = \u2a06 i, (s i).map f :=\n(gc_map_comap f).l_supr\n\nlemma comap_inf (s t : subring S) (f : R \u2192+* S) : (s \u2293 t).comap f = s.comap f \u2293 t.comap f :=\n(gc_map_comap f).u_inf\n\nlemma comap_infi {\u03b9 : Sort*} (f : R \u2192+* S) (s : \u03b9 \u2192 subring S) :\n  (infi s).comap f = \u2a05 i, (s i).comap f :=\n(gc_map_comap f).u_infi\n\n@[simp] lemma map_bot (f : R \u2192+* S) : (\u22a5 : subring R).map f = \u22a5 :=\n(gc_map_comap f).l_bot\n\n@[simp] lemma comap_top (f : R \u2192+* S) : (\u22a4 : subring S).comap f = \u22a4 :=\n(gc_map_comap f).u_top\n\n/-- Given `subring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s \u00d7 t`\nas a subring of `R \u00d7 S`. -/\ndef prod (s : subring R) (t : subring S) : subring (R \u00d7 S) :=\n{ carrier := (s : set R).prod t,\n  .. s.to_submonoid.prod t.to_submonoid, .. s.to_add_subgroup.prod t.to_add_subgroup}\n\n@[norm_cast]\nlemma coe_prod (s : subring R) (t : subring S) :\n  (s.prod t : set (R \u00d7 S)) = (s : set R).prod (t : set S) :=\nrfl\n\nlemma mem_prod {s : subring R} {t : subring S} {p : R \u00d7 S} :\n  p \u2208 s.prod t \u2194 p.1 \u2208 s \u2227 p.2 \u2208 t := iff.rfl\n\n@[mono] lemma prod_mono \u2983s\u2081 s\u2082 : subring R\u2984 (hs : s\u2081 \u2264 s\u2082) \u2983t\u2081 t\u2082 : subring S\u2984\n  (ht : t\u2081 \u2264 t\u2082) : s\u2081.prod t\u2081 \u2264 s\u2082.prod t\u2082 :=\nset.prod_mono hs ht\n\nlemma prod_mono_right (s : subring R) : monotone (\u03bb t : subring S, s.prod t) :=\nprod_mono (le_refl s)\n\nlemma prod_mono_left (t : subring S) : monotone (\u03bb s : subring R, s.prod t) :=\n\u03bb s\u2081 s\u2082 hs, prod_mono hs (le_refl t)\n\nlemma prod_top (s : subring R) :\n  s.prod (\u22a4 : subring S) = s.comap (ring_hom.fst R S) :=\next $ \u03bb x, by simp [mem_prod, monoid_hom.coe_fst]\n\nlemma top_prod (s : subring S) :\n  (\u22a4 : subring R).prod s = s.comap (ring_hom.snd R S) :=\next $ \u03bb x, by simp [mem_prod, monoid_hom.coe_snd]\n\n@[simp]\nlemma top_prod_top : (\u22a4 : subring R).prod (\u22a4 : subring S) = \u22a4 :=\n(top_prod _).trans $ comap_top _\n\n/-- Product of subrings is isomorphic to their product as rings. -/\ndef prod_equiv (s : subring R) (t : subring S) : s.prod t \u2243+* s \u00d7 t :=\n{ map_mul' := \u03bb x y, rfl, map_add' := \u03bb x y, rfl, .. equiv.set.prod \u2191s \u2191t }\n\n/-- The underlying set of a non-empty directed Sup of subrings is just a union of the subrings.\n  Note that this fails without the directedness assumption (the union of two subrings is\n  typically not a subring) -/\nlemma mem_supr_of_directed {\u03b9} [h\u03b9 : nonempty \u03b9] {S : \u03b9 \u2192 subring R} (hS : directed (\u2264) S)\n  {x : R} :\n  x \u2208 (\u2a06 i, S i) \u2194 \u2203 i, x \u2208 S i :=\nbegin\n  refine \u27e8_, \u03bb \u27e8i, hi\u27e9, (set_like.le_def.1 $ le_supr S i) hi\u27e9,\n  let U : subring R := subring.mk' (\u22c3 i, (S i : set R))\n    (\u2a06 i, (S i).to_submonoid) (\u2a06 i, (S i).to_add_subgroup)\n    (submonoid.coe_supr_of_directed $ hS.mono_comp _ (\u03bb _ _, id))\n    (add_subgroup.coe_supr_of_directed $ hS.mono_comp _ (\u03bb _ _, id)),\n  suffices : (\u2a06 i, S i) \u2264 U, by simpa using @this x,\n  exact supr_le (\u03bb i x hx, set.mem_Union.2 \u27e8i, hx\u27e9),\nend\n\nlemma coe_supr_of_directed {\u03b9} [h\u03b9 : nonempty \u03b9] {S : \u03b9 \u2192 subring R} (hS : directed (\u2264) S) :\n  ((\u2a06 i, S i : subring R) : set R) = \u22c3 i, \u2191(S i) :=\nset.ext $ \u03bb x, by simp [mem_supr_of_directed hS]\n\nlemma mem_Sup_of_directed_on {S : set (subring R)} (Sne : S.nonempty)\n  (hS : directed_on (\u2264) S) {x : R} :\n  x \u2208 Sup S \u2194 \u2203 s \u2208 S, x \u2208 s :=\nbegin\n  haveI : nonempty S := Sne.to_subtype,\n  simp only [Sup_eq_supr', mem_supr_of_directed hS.directed_coe, set_coe.exists, subtype.coe_mk]\nend\n\nlemma coe_Sup_of_directed_on {S : set (subring R)} (Sne : S.nonempty) (hS : directed_on (\u2264) S) :\n  (\u2191(Sup S) : set R) = \u22c3 s \u2208 S, \u2191s :=\nset.ext $ \u03bb x, by simp [mem_Sup_of_directed_on Sne hS]\n\nend subring\n\nnamespace ring_hom\n\nvariables [ring T] {s : subring R}\n\nopen subring\n\n/-- Restriction of a ring homomorphism to a subring of the domain. -/\ndef restrict (f : R \u2192+* S) (s : subring R) : s \u2192+* S := f.comp s.subtype\n\n@[simp] lemma restrict_apply (f : R \u2192+* S) (x : s) : f.restrict s x = f x := rfl\n\n/-- Restriction of a ring homomorphism to its range interpreted as a subsemiring.\n\nThis is the bundled version of `set.range_factorization`. -/\ndef range_restrict (f : R \u2192+* S) : R \u2192+* f.range :=\nf.cod_restrict' f.range $ \u03bb x, \u27e8x, rfl\u27e9\n\n@[simp] lemma coe_range_restrict (f : R \u2192+* S) (x : R) : (f.range_restrict x : S) = f x := rfl\n\nlemma range_restrict_surjective (f : R \u2192+* S) : function.surjective f.range_restrict :=\n\u03bb \u27e8y, hy\u27e9, let \u27e8x, hx\u27e9 := mem_range.mp hy in \u27e8x, subtype.ext hx\u27e9\n\nlemma range_top_iff_surjective {f : R \u2192+* S} :\n  f.range = (\u22a4 : subring S) \u2194 function.surjective f :=\nset_like.ext'_iff.trans $ iff.trans (by rw [coe_range, coe_top]) set.range_iff_surjective\n\n/-- The range of a surjective ring homomorphism is the whole of the codomain. -/\nlemma range_top_of_surjective (f : R \u2192+* S) (hf : function.surjective f) :\n  f.range = (\u22a4 : subring S) :=\nrange_top_iff_surjective.2 hf\n\n/-- The subring of elements `x : R` such that `f x = g x`, i.e.,\n  the equalizer of f and g as a subring of R -/\ndef eq_locus (f g : R \u2192+* S) : subring R :=\n{ carrier := {x | f x = g x}, .. (f : R \u2192* S).eq_mlocus g, .. (f : R \u2192+ S).eq_locus g }\n\n/-- If two ring homomorphisms are equal on a set, then they are equal on its subring closure. -/\nlemma eq_on_set_closure {f g : R \u2192+* S} {s : set R} (h : set.eq_on f g s) :\n  set.eq_on f g (closure s) :=\nshow closure s \u2264 f.eq_locus g, from closure_le.2 h\n\nlemma eq_of_eq_on_set_top {f g : R \u2192+* S} (h : set.eq_on f g (\u22a4 : subring R)) :\n  f = g :=\next $ \u03bb x, h trivial\n\nlemma eq_of_eq_on_set_dense {s : set R} (hs : closure s = \u22a4) {f g : R \u2192+* S} (h : s.eq_on f g) :\n  f = g :=\neq_of_eq_on_set_top $ hs \u25b8 eq_on_set_closure h\n\nlemma closure_preimage_le (f : R \u2192+* S) (s : set S) :\n  closure (f \u207b\u00b9' s) \u2264 (closure s).comap f :=\nclosure_le.2 $ \u03bb x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx\n\n/-- The image under a ring homomorphism of the subring generated by a set equals\nthe subring generated by the image of the set. -/\nlemma map_closure (f : R \u2192+* S) (s : set R) :\n  (closure s).map f = closure (f '' s) :=\nle_antisymm\n  (map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _)\n    (closure_preimage_le _ _))\n  (closure_le.2 $ set.image_subset _ subset_closure)\n\nend ring_hom\n\nnamespace subring\n\nopen ring_hom\n\n/-- The ring homomorphism associated to an inclusion of subrings. -/\ndef inclusion {S T : subring R} (h : S \u2264 T) : S \u2192* T :=\nS.subtype.cod_restrict' _ (\u03bb x, h x.2)\n\n@[simp] lemma range_subtype (s : subring R) : s.subtype.range = s :=\nset_like.coe_injective $ (coe_srange _).trans subtype.range_coe\n\n@[simp]\nlemma range_fst : (fst R S).srange = \u22a4 :=\n(fst R S).srange_top_of_surjective $ prod.fst_surjective\n\n@[simp]\nlemma range_snd : (snd R S).srange = \u22a4 :=\n(snd R S).srange_top_of_surjective $ prod.snd_surjective\n\n@[simp]\nlemma prod_bot_sup_bot_prod (s : subring R) (t : subring S) :\n  (s.prod \u22a5) \u2294 (prod \u22a5 t) = s.prod t :=\nle_antisymm (sup_le (prod_mono_right s bot_le) (prod_mono_left t bot_le)) $\nassume p hp, prod.fst_mul_snd p \u25b8 mul_mem _\n  ((le_sup_left : s.prod \u22a5 \u2264 s.prod \u22a5 \u2294 prod \u22a5 t) \u27e8hp.1, set_like.mem_coe.2 $ one_mem \u22a5\u27e9)\n  ((le_sup_right : prod \u22a5 t \u2264 s.prod \u22a5 \u2294 prod \u22a5 t) \u27e8set_like.mem_coe.2 $ one_mem \u22a5, hp.2\u27e9)\n\nend subring\n\nnamespace ring_equiv\n\nvariables {s t : subring R}\n\n/-- Makes the identity isomorphism from a proof two subrings of a multiplicative\n    monoid are equal. -/\ndef subring_congr (h : s = t) : s \u2243+* t :=\n{ map_mul' :=  \u03bb _ _, rfl, map_add' := \u03bb _ _, rfl, ..equiv.set_congr $ congr_arg _ h }\n\n/-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its\n`ring_hom.range`. -/\ndef of_left_inverse {g : S \u2192 R} {f : R \u2192+* S} (h : function.left_inverse g f) :\n  R \u2243+* f.range :=\n{ to_fun := \u03bb x, f.range_restrict x,\n  inv_fun := \u03bb x, (g \u2218 f.range.subtype) x,\n  left_inv := h,\n  right_inv := \u03bb x, subtype.ext $\n    let \u27e8x', hx'\u27e9 := ring_hom.mem_range.mp x.prop in\n    show f (g x) = x, by rw [\u2190hx', h x'],\n  ..f.range_restrict }\n\n@[simp] lemma of_left_inverse_apply\n  {g : S \u2192 R} {f : R \u2192+* S} (h : function.left_inverse g f) (x : R) :\n  \u2191(of_left_inverse h x) = f x := rfl\n\n@[simp] lemma of_left_inverse_symm_apply\n  {g : S \u2192 R} {f : R \u2192+* S} (h : function.left_inverse g f) (x : f.range) :\n  (of_left_inverse h).symm x = g x := rfl\n\nend ring_equiv\n\nnamespace subring\n\nvariables {s : set R}\nlocal attribute [reducible] closure\n\n@[elab_as_eliminator]\nprotected theorem in_closure.rec_on {C : R \u2192 Prop} {x : R} (hx : x \u2208 closure s)\n  (h1 : C 1) (hneg1 : C (-1)) (hs : \u2200 z \u2208 s, \u2200 n, C n \u2192 C (z * n))\n  (ha : \u2200 {x y}, C x \u2192 C y \u2192 C (x + y)) : C x :=\nbegin\n  have h0 : C 0 := add_neg_self (1:R) \u25b8 ha h1 hneg1,\n  rcases exists_list_of_mem_closure hx with \u27e8L, HL, rfl\u27e9, clear hx,\n  induction L with hd tl ih, { exact h0 },\n  rw list.forall_mem_cons at HL,\n  suffices : C (list.prod hd),\n  { rw [list.map_cons, list.sum_cons],\n    exact ha this (ih HL.2) },\n  replace HL := HL.1, clear ih tl,\n  suffices : \u2203 L : list R, (\u2200 x \u2208 L, x \u2208 s) \u2227\n    (list.prod hd = list.prod L \u2228 list.prod hd = -list.prod L),\n  { rcases this with \u27e8L, HL', HP | HP\u27e9,\n    { rw HP, clear HP HL hd, induction L with hd tl ih, { exact h1 },\n      rw list.forall_mem_cons at HL',\n      rw list.prod_cons,\n      exact hs _ HL'.1 _ (ih HL'.2) },\n    rw HP, clear HP HL hd, induction L with hd tl ih, { exact hneg1 },\n    rw [list.prod_cons, neg_mul_eq_mul_neg],\n    rw list.forall_mem_cons at HL',\n    exact hs _ HL'.1 _ (ih HL'.2) },\n  induction hd with hd tl ih,\n  { exact \u27e8[], list.forall_mem_nil _, or.inl rfl\u27e9 },\n  rw list.forall_mem_cons at HL,\n  rcases ih HL.2 with \u27e8L, HL', HP | HP\u27e9; cases HL.1 with hhd hhd,\n  { exact \u27e8hd :: L, list.forall_mem_cons.2 \u27e8hhd, HL'\u27e9, or.inl $\n      by rw [list.prod_cons, list.prod_cons, HP]\u27e9 },\n  { exact \u27e8L, HL', or.inr $ by rw [list.prod_cons, hhd, neg_one_mul, HP]\u27e9 },\n  { exact \u27e8hd :: L, list.forall_mem_cons.2 \u27e8hhd, HL'\u27e9, or.inr $\n      by rw [list.prod_cons, list.prod_cons, HP, neg_mul_eq_mul_neg]\u27e9 },\n  { exact \u27e8L, HL', or.inl $ by rw [list.prod_cons, hhd, HP, neg_one_mul, neg_neg]\u27e9 }\nend\n\nlemma closure_preimage_le (f : R \u2192+* S) (s : set S) :\n  closure (f \u207b\u00b9' s) \u2264 (closure s).comap f :=\nclosure_le.2 $ \u03bb x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx\n\nend subring\n\nlemma add_subgroup.int_mul_mem {G : add_subgroup R} (k : \u2124) {g : R} (h : g \u2208 G) :\n  (k : R) * g \u2208 G :=\nby { convert add_subgroup.gsmul_mem G h k, simp }\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/subring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7153931894483939}}
{"text": "/-\n  Copyright 2020 Grayson Burton\n  License available in the LICENSE file.\n-/\nimport data.set tactic .between\n\nsection\nuniverse u\nparameters {\u03b1 : Type u} [has_betweenness \u03b1]\n\n/-- The convex hull of a set. -/\n/- thanks chris hughes -/\ninductive convex_hull (s : set \u03b1) : set \u03b1\n| of_set : \u2200 {v}, v \u2208 s \u2192 convex_hull v\n| intrv : \u2200 {v\u2081 v\u2082 v\u2083}, convex_hull v\u2081 \u2192 convex_hull v\u2082 \u2192\n  v\u2083 \u2208 interval v\u2081 v\u2082 \u2192 convex_hull v\u2083\n\ninductive affine_hull (s : set \u03b1) : set \u03b1\n| of_set : \u2200 {v}, v \u2208 s \u2192 affine_hull v\n| of_line : \u2200 {v\u2081 v\u2082 v\u2083}, affine_hull v\u2081 \u2192 affine_hull v\u2082 \u2192 v\u2083 \u2208 line v\u2081 v\u2082 \u2192 affine_hull v\u2083\n\ndef lin_indep_sets (s\u2081 s\u2082 : set \u03b1) : Prop :=\ndisjoint (affine_hull s\u2081) (affine_hull s\u2082)\n\ndef lin_indep (s : set \u03b1) : Prop :=\n\u2200 p \u2208 s, p \u2209 affine_hull (s \\ {p})\n\n/-- A set is convex if it is equal to its own convex hull. -/\n@[reducible]\ndef is_convex (s : set \u03b1) : Prop :=\nconvex_hull s = s\n\n@[reducible]\ndef is_affine (s : set \u03b1) : Prop :=\naffine_hull s = s\n\nend\n\nsection\nuniverse u\nparameters {\u03b1 : Type u} [has_betweenness \u03b1]\n\n@[simp]\ntheorem is_convex.convex_def (s : set \u03b1) : is_convex s = (convex_hull s = s) :=\nrfl\n\n@[simp]\ntheorem is_affine.affine_def (s : set \u03b1) : is_affine s = (affine_hull s = s) :=\nrfl\n\nnamespace convex_hull\n/-- `x` is in a convex hull of a set iff it's in the original set or it is on a\n    line segment between two points that are also in the convex hull. -/\n@[simp]\ntheorem mem_iff {s : set \u03b1} (x : \u03b1) :\n  x \u2208 convex_hull s \u2194 x \u2208 s \u2228 \u2203 (v\u2081 v\u2082 \u2208 convex_hull s), x \u2208 interval v\u2081 v\u2082 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n    { rcases h with \u27e8_, h\u27e9 | \u27e8_, _, _, hv\u2081, hv\u2082, h\u27e9,\n        { exact or.inl h },\n        { exact or.inr \u27e8_, _, hv\u2081, hv\u2082, h\u27e9 }},\n    { rcases h with \u27e8h\u27e9 | \u27e8_, _, hv\u2081, hv\u2082, h\u27e9,\n        { exact of_set h },\n        { exact intrv hv\u2081 hv\u2082 h }}\nend\n\ntheorem mem_iff' {s : set \u03b1} (x : \u03b1) :\n  convex_hull s x \u2194 x \u2208 s \u2228 \u2203 (v\u2081 v\u2082 \u2208 convex_hull s), x \u2208 interval v\u2081 v\u2082 :=\nmem_iff x\n\n/-- Taking the convex hull of a convex hull is idempotent. -/\n@[simp]\ntheorem idempotent (s : set \u03b1) : convex_hull (convex_hull s) = convex_hull s :=\nbegin\n  apply set.eq_of_subset_of_subset (\u03bb _ h, _) (\u03bb _ h, _),\n    { induction h with _ _ _ _ _ _ _ h hv\u2081 hv\u2082,\n        { assumption },\n        { exact intrv hv\u2081 hv\u2082 h }},\n    { rcases h with \u27e8_, h\u27e9 | \u27e8_, _, _, hv\u2081, hv\u2082, h\u27e9,\n        { exact of_set (of_set h) },\n        { exact intrv (of_set hv\u2081) (of_set hv\u2082) h }}\nend\n\n/-- Every set is a subset of its convex hull. -/\ntheorem self_subs_hull (s : set \u03b1) : s \u2286 convex_hull s :=\n\u03bb _, of_set\n\ntheorem eq_of_hull_subs {s : set \u03b1} (h : convex_hull s \u2286 s) : is_convex s :=\nset.eq_of_subset_of_subset h (self_subs_hull s)\n\n/-- Every convex hull is convex. -/\ntheorem convex (s : set \u03b1) : is_convex (convex_hull s) :=\nidempotent s\n\n/-- If `S\u2081 \u2286 S\u2082`, then the convex hull of `S\u2081` is also a subset of the convex\n    hull of `S\u2082`. -/\ntheorem is_mono {s t : set \u03b1} (hs : s \u2286 t) : convex_hull s \u2286 convex_hull t :=\nbegin\n  intros x h,\n  induction h with _ h _ _ _ _ _ h hv\u2081 hv\u2082,\n    { exact self_subs_hull _ (hs h) },\n    { exact intrv hv\u2081 hv\u2082 h }\nend\n\n/-- If `S\u2081 \u2282 S\u2082` and both are convex, then the convex hull of `S\u2081` is also a\n    strict subset of the convex hull of `S\u2082`. -/\ntheorem is_mono_convex {s t : set \u03b1} (hs : is_convex s) (ht : is_convex t) :\n  s \u2282 t \u2192 convex_hull s \u2282 convex_hull t :=\n\u03bb h, by rw is_convex.convex_def at hs ht; rwa [hs, ht]\n\n/-- If `S\u2081` and `S\u2082` are both convex, then `S\u2081 \u2282 S\u2082` iff the same is true of\n    their convex hulls. -/\ntheorem iff_ssubs_of_convex {s t : set \u03b1} (hs : is_convex s) (ht : is_convex t) :\n  s \u2282 t \u2194 convex_hull s \u2282 convex_hull t :=\nby rw is_convex.convex_def at hs ht; rwa [hs, ht]\n\n@[simp]\ntheorem of_empty : @convex_hull \u03b1 _ \u2205 = \u2205 :=\nbegin\n  apply eq_of_hull_subs (\u03bb _ h, _),\n  induction h with _ _ _ _ _ _ _ _ h, { assumption },\n  exact (set.not_mem_empty _) h\nend\n\n@[simp]\ntheorem is_empty_iff (s : set \u03b1) : (@convex_hull \u03b1 _ s = \u2205) \u2194 s = \u2205 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, by rw h; exact of_empty\u27e9,\n  rw [\u2190set.subset_empty_iff, \u2190h],\n  apply self_subs_hull\nend\n\n@[simp]\ntheorem of_singleton (p : \u03b1) : @convex_hull \u03b1 _ {p} = {p} :=\nbegin\n  apply eq_of_hull_subs (\u03bb _ h, _),\n  induction h with _ h\u2082 _ _ _ _ _ h hv\u2081 hv\u2082, { assumption },\n  rw [set.mem_singleton_iff] at hv\u2081 hv\u2082, rw [hv\u2081, hv\u2082] at h,\n  exact interval.eq_of_mem_same h\nend\n\n@[simp]\ntheorem of_univ : @convex_hull \u03b1 _ set.univ = set.univ :=\nset.eq_univ_of_subset (self_subs_hull set.univ) rfl\n\nend convex_hull\n\nnamespace affine_hull\n\n/-- `x` is in a affine_hull of a set iff it's in the original set or it is on a line\n    between two points that are also in the affine_hull. -/\n@[simp]\ntheorem mem_iff {s : set \u03b1} (x : \u03b1) : x \u2208 affine_hull s \u2194 x \u2208 s \u2228 \u2203 (v\u2081 v\u2082 \u2208 affine_hull s), x \u2208 line v\u2081 v\u2082 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n    { rcases h with \u27e8_, h\u27e9 | \u27e8_, _, _, hv\u2081, hv\u2082, h\u27e9,\n        { exact or.inl h },\n        { exact or.inr \u27e8_, _, hv\u2081, hv\u2082, h\u27e9 }},\n    { rcases h with \u27e8h\u27e9 | \u27e8_, _, hv\u2081, hv\u2082, h\u27e9,\n        { exact of_set h },\n        { exact of_line hv\u2081 hv\u2082 h }}\nend\n\ntheorem mem_iff' {s : set \u03b1} (x : \u03b1) : affine_hull s x \u2194 x \u2208 s \u2228 \u2203 (v\u2081 v\u2082 \u2208 affine_hull s), x \u2208 line v\u2081 v\u2082 :=\nmem_iff x\n\n@[simp]\ntheorem idempotent (s : set \u03b1) : affine_hull (affine_hull s) = affine_hull s :=\nbegin\n  apply set.eq_of_subset_of_subset (\u03bb _ h, _) (\u03bb _ h, _),\n    { induction h with _ _ _ _ _ _ _ h hv\u2081 hv\u2082,\n        { assumption },\n        { exact of_line hv\u2081 hv\u2082 h }},\n    { rcases h with \u27e8_, h\u27e9 | \u27e8_, _, _, hv\u2081, hv\u2082, h\u27e9,\n        { exact of_set (of_set h) },\n        { exact of_line (of_set hv\u2081) (of_set hv\u2082) h }}\nend\n\n/-- Every set is a subset of its affine_hull. -/\ntheorem self_subs_span (s : set \u03b1) : s \u2286 affine_hull s :=\n\u03bb _, of_set\n\n/-- If `S\u2081 \u2286 S\u2082`, then the affine_hull of `S\u2081` is also a subset of the affine_hull of `S\u2082`. -/\ntheorem is_mono {s t : set \u03b1} (hs : s \u2286 t) : affine_hull s \u2286 affine_hull t :=\nbegin\n  intros x h,\n  induction h with _ h _ _ _ _ _ h hv\u2081 hv\u2082,\n    { exact self_subs_span _ (hs h) },\n    { exact of_line hv\u2081 hv\u2082 h }\n    \nend\n\n@[simp]\ntheorem of_empty : @affine_hull \u03b1 _ \u2205 = \u2205 :=\nbegin\n  rw set.eq_empty_iff_forall_not_mem,\n  intros _ h,\n  induction h with _ _ _ _ _ _ _ _ h, repeat { assumption }\nend\n\n@[simp]\ntheorem is_empty_iff (s : set \u03b1) : (@affine_hull \u03b1 _ s = \u2205) \u2194 s = \u2205 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, by rw h; exact of_empty\u27e9,\n  rw [\u2190set.subset_empty_iff, \u2190h],\n  apply self_subs_span\nend\n\n@[simp]\ntheorem eq_iff_span_subs (s : set \u03b1) : affine_hull s = s \u2194 affine_hull s \u2286 s :=\nbegin\n  refine \u27e8\u03bb h, by rw h; refl, \u03bb h, set.eq_of_subset_of_subset h _\u27e9,\n  exact self_subs_span _\nend\n\n@[simp]\ntheorem of_singleton (p : \u03b1) : @affine_hull \u03b1 _ {p} = {p} :=\nbegin\n  rw eq_iff_span_subs,\n  intros _ h,\n  induction h with _ h\u2082 _ _ _ _ _ h hv\u2081 hv\u2082, { assumption },\n  rw [set.mem_singleton_iff] at hv\u2081 hv\u2082, rw [hv\u2081, hv\u2082] at h,\n  exact line.eq_of_mem_same h\nend\n\n@[simp]\ntheorem of_univ : @affine_hull \u03b1 _ set.univ = set.univ :=\nset.eq_univ_of_subset (self_subs_span set.univ) rfl\n\ntheorem convex_subs_span (s : set \u03b1) : convex_hull s \u2286 affine_hull s :=\nbegin\n  intros _ h,\n  induction h with _ h _ _ _ _ _ h hv\u2081 hv\u2082, { exact of_set h },\n  exact of_line hv\u2081 hv\u2082 (line.intrv_subs _ _ h)\nend\n\ntheorem affine (s : set \u03b1) : is_affine (affine_hull s) :=\nby rw [is_affine, idempotent]\n\n\nend affine_hull\n\nnamespace lin_indep_sets\n\ntheorem indep_def (s\u2081 s\u2082 : set \u03b1) : lin_indep_sets s\u2081 s\u2082 = disjoint (affine_hull s\u2081) (affine_hull s\u2082) :=\nrfl\n\ntheorem symm_iff (s\u2081 s\u2082 : set \u03b1) : lin_indep_sets s\u2081 s\u2082 \u2194 lin_indep_sets s\u2082 s\u2081 :=\nby rw [indep_def, indep_def]; exact disjoint.comm\n\ntheorem symm {s\u2081 s\u2082 : set \u03b1} : lin_indep_sets s\u2081 s\u2082 \u2192 lin_indep_sets s\u2082 s\u2081 :=\n(symm_iff s\u2081 s\u2082).mp\n\ntheorem of_empty (s : set \u03b1) : lin_indep_sets \u2205 s :=\nby rw [indep_def, affine_hull.of_empty]; apply set.empty_disjoint\n\ntheorem of_empty' (s : set \u03b1) : lin_indep_sets s \u2205 :=\nby rw symm_iff; apply of_empty\n\n@[simp]\ntheorem of_singletons (p q : \u03b1) : @lin_indep_sets \u03b1 _ {p} {q} \u2194 p \u2260 q :=\nby rw [indep_def, affine_hull.of_singleton, affine_hull.of_singleton, set.disjoint_singleton_left]; refl\n\n@[simp]\ntheorem of_singleton_left (p : \u03b1) (s : set \u03b1) : lin_indep_sets {p} s \u2194 p \u2209 affine_hull s :=\nby rw [indep_def, affine_hull.of_singleton, set.disjoint_singleton_left]\n\n@[simp]\ntheorem of_singleton_right (p : \u03b1) (s : set \u03b1) : lin_indep_sets s {p} \u2194 p \u2209 affine_hull s :=\nby rw [indep_def, affine_hull.of_singleton, set.disjoint_singleton_right]\n\nend lin_indep_sets\n\nnamespace lin_indep\n\ntheorem indep_def (s : set \u03b1) : lin_indep s = \u2200 p \u2208 s, p \u2209 affine_hull (s \\ {p}) :=\nrfl\n\ntheorem indep_iff_indep_sets (s : set \u03b1) : lin_indep s \u2194 \u2200 p \u2208 s, lin_indep_sets {p} (s \\ {p}) :=\nbegin\n  rw indep_def,\n  refine \u27e8\u03bb h _ hp, _, \u03bb h _ hp, _\u27e9,\n    { rw lin_indep_sets.of_singleton_left, exact h _ hp },\n    { exact (lin_indep_sets.of_singleton_left _ _).mp (h _ hp) }\nend\n\nlemma of_singleton (p : \u03b1) : lin_indep ({p} : set \u03b1) :=\nby intros _ h; induction h; simp\n\ntheorem not_iff_ex_in_span (s : set \u03b1) : \u00ac lin_indep s \u2194 \u2203 p \u2208 s, p \u2208 affine_hull (s \\ {p}) :=\nby rw indep_def; push_neg; tauto\n\ntheorem not_iff_ex_in_line (s : set \u03b1) :\n  \u00ac lin_indep s \u2194 \u2203 (p \u2208 s) (q r \u2208 affine_hull (s \\ {p})), p \u2208 line q r :=\nbegin\n  rw not_iff_ex_in_span,\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n    { rcases h with \u27e8_, h, h'\u27e9,\n      refine \u27e8_, h, _\u27e9,\n      rcases h' with \u27e8_, h'\u27e9 | \u27e8_, _, _, h\u2081, h\u2082, h'\u27e9, { exact (h'.right rfl).elim },\n      exact \u27e8_, _, h\u2081, h\u2082, h'\u27e9 },\n    { rcases h with \u27e8_, h, _, _, h\u2080, h\u2081, h\u2082\u27e9, exact \u27e8_, h, affine_hull.of_line h\u2080 h\u2081 h\u2082\u27e9 }\nend\n\ntheorem of_sup {s\u2081 s\u2082 : set \u03b1} (h : s\u2081 \u2286 s\u2082) (hs\u2082 : lin_indep s\u2082) : lin_indep s\u2081 :=\nbegin\n  rw indep_def at hs\u2082 \u22a2,\n  intros _ hp hps,\n  specialize hs\u2082 _ (h hp),\n  exact hs\u2082 ((affine_hull.is_mono $ set.diff_subset_diff_left h) hps)\nend\n\nlemma empty : lin_indep (\u2205 : set \u03b1) :=\n\u03bb _ h, (set.not_mem_empty _ h).elim\n\nend lin_indep\n\nnamespace is_convex\n\n/-- Every convex hull is convex. -/\ntheorem hulls_are_convex (s : set \u03b1) : is_convex (convex_hull s) :=\nconvex_hull.convex s\n\ntheorem ex_set_convex_eq_of_convex {s : set \u03b1} (h : is_convex s) : \u2203 s', convex_hull s' = s :=\n\u27e8s, h\u27e9\n\ntheorem convex_iff_ex_set_convex_eq (s : set \u03b1) : is_convex s \u2194 \u2203 s', convex_hull s' = s :=\nbegin\n  refine \u27e8ex_set_convex_eq_of_convex, _\u27e9,\n  rintro \u27e8_, h\u27e9,\n  rw [is_convex, \u2190h, convex_hull.idempotent]\nend\n\n/-- If `S` is convex, then every point in `s` lies on some line segment in\n    `S`. -/\ntheorem mem_intrv_of_convex {s : set \u03b1} :\n  is_convex s \u2192 \u2200 {x}, x \u2208 s \u2192 \u2203 v\u2081 v\u2082 \u2208 s, x \u2208 interval v\u2081 v\u2082 :=\nbegin\n  intros hs x h,\n  rw convex_def at hs,\n  rw \u2190hs at h,\n  rcases h with \u27e8_, h\u27e9 | \u27e8_, _, _, hv\u2081, hv\u2082, h\u27e9,\n    { exact \u27e8x, x, h, h, interval.end_mem_intrv_left _ _\u27e9 },\n  rw \u2190hs,\n  exact \u27e8_, _, hv\u2081, hv\u2082, h\u27e9\nend\n\n/-- If `S` is convex, then every point in `s` lies on some line segment in\n    `S`. -/\ntheorem iff_mem_intrv_of_convex {s : set \u03b1} :\n  is_convex s \u2192 \u2200 {x}, x \u2208 s \u2194 \u2203 v\u2081 v\u2082 \u2208 s, x \u2208 interval v\u2081 v\u2082 :=\nbegin\n  intros hs x,\n  apply iff.intro (mem_intrv_of_convex hs),\n  rw convex_def at hs,\n  rintro \u27e8_, _, hv\u2081, hv\u2082, h\u27e9,\n  rw \u2190hs at *,\n  exact convex_hull.intrv hv\u2081 hv\u2082 h\nend\n\ntheorem of_convex_subs (s : set \u03b1) : is_convex s \u2194 convex_hull s \u2286 s :=\nbegin\n  refine \u27e8\u03bb h _ h', _, \u03bb h, set.eq_of_subset_of_subset h $ convex_hull.self_subs_hull _\u27e9,\n  change _ = _ at h,\n  rwa h at h'\nend\n\n/-- A set `S` is convex iff, for any point `x`, `x \u2208 S` is equivalent to there\n    being two more points in `S` such that `x` is on the line segment between\n    them. -/\ntheorem iff_mem_intrv_iff_convex (s : set \u03b1) :\n  is_convex s \u2194 \u2200 {x}, x \u2208 s \u2194 \u2203 v\u2081 v\u2082 \u2208 s, x \u2208 interval v\u2081 v\u2082 :=\nbegin\n  apply iff.intro iff_mem_intrv_of_convex (\u03bb hs, _),\n  apply set.eq_of_subset_of_subset (\u03bb _ h, _) (\u03bb _, convex_hull.of_set),\n  induction h with _ h\u2082 _ _ _ _ _ h hv\u2081 hv\u2082,\n    { assumption },\n    { exact hs.mpr \u27e8_, _, hv\u2081, hv\u2082, h\u27e9 }\nend\n\ntheorem intersect_closed {s\u2081 s\u2082 : set \u03b1} (hs\u2081 : is_convex s\u2081) (hs\u2082 : is_convex s\u2082) :\n  is_convex (s\u2081 \u2229 s\u2082) :=\nbegin\n  apply (iff_mem_intrv_iff_convex _).mpr (\u03bb _, \u27e8\u03bb hp, _, \u03bb hp, _\u27e9),\n    { exact \u27e8_, _, hp, hp, interval.end_mem_intrv_left _ _\u27e9 },\n  rcases hp with \u27e8_, _, hq, hr, hpqr\u27e9,\n  rw iff_mem_intrv_iff_convex at hs\u2081 hs\u2082,\n  split,\n    { rw hs\u2081, exact \u27e8_, _, hq.left, hr.left, hpqr\u27e9 },\n    { rw hs\u2082, exact \u27e8_, _, hq.right, hr.right, hpqr\u27e9 }\nend\n\ntheorem convex_of_ex_hull_eq (s : set \u03b1) : is_convex s \u2194 \u2203 s\u2081, s = convex_hull s\u2081 :=\nbegin\n  refine \u27e8\u03bb h, \u27e8s, eq.symm h\u27e9, \u03bb h, _\u27e9,\n  cases h with _ h, rw h,\n  apply hulls_are_convex\nend\n\nprotected theorem univ : @is_convex \u03b1 _ set.univ :=\nconvex_hull.of_univ\n\nend is_convex\n\ntheorem convex_hull.eq_bInter_convex (s : set \u03b1) :\n  convex_hull s = \u22c2 (s\u2081 \u2287 s) (h : is_convex s\u2081), s\u2081 :=\nbegin\n  apply set.eq_of_subset_of_subset (\u03bb _ h, _) (\u03bb _ h, _),\n    { simp only [is_convex.convex_def, set.mem_Inter],\n      intros _ hs\u2081 hs\u2082, rw \u2190hs\u2082,\n      exact convex_hull.is_mono hs\u2081 h },\n    { simp only [set.mem_Inter] at h,\n      specialize h _ (convex_hull.self_subs_hull _),\n      exact h (is_convex.hulls_are_convex _) }\nend\n\nnamespace is_affine\n\n/-- Every linear affine_hull is a linear subspace. -/\ntheorem spans_are_affines (s : set \u03b1) : is_affine (affine_hull s) :=\naffine_hull.affine s\n\ntheorem ex_set_span_eq_of_affine {s : set \u03b1} (h : is_affine s) : \u2203 s', affine_hull s' = s :=\n\u27e8s, h\u27e9\n\ntheorem affine_iff_ex_set_span_eq (s : set \u03b1) : is_affine s \u2194 \u2203 s', affine_hull s' = s :=\nbegin\n  refine \u27e8ex_set_span_eq_of_affine\n, _\u27e9,\n  rintro \u27e8_, h\u27e9,\n  rw [is_affine\n, \u2190h, affine_hull.idempotent]\nend\n\n/-- If `S` is a linear subspace, then every point in `S` lies on some line\n    intersecting `S`. -/\ntheorem mem_line_of_mem {s : set \u03b1} (hs : is_affine s) {x : \u03b1} (h : x \u2208 s) :\n  \u2203 v\u2081 v\u2082 \u2208 s, x \u2208 line v\u2081 v\u2082 :=\n\u27e8_, _, h, h, line.end_mem_line_left _ _\u27e9\n\n/-- If `S` is a linear subspace, then a point is in `S` iff it is on a line\n    intersecting two points in `S`. -/\ntheorem mem_iff_mem_line {s : set \u03b1} (hs : is_affine s) (x : \u03b1) :\n  x \u2208 s \u2194 \u2203 v\u2081 v\u2082 \u2208 s, x \u2208 line v\u2081 v\u2082 :=\nbegin\n  apply iff.intro (mem_line_of_mem hs),\n  rw affine_def at hs,\n  rintro \u27e8_, _, hv\u2081, hv\u2082, h\u27e9,\n  rw \u2190hs at *,\n  exact affine_hull.of_line hv\u2081 hv\u2082 h\nend\n\n/-- A set `S` is a linear subspace iff, for any point `x`, `x \u2208 S` is equivalent\n    to there being two more points in `S` such that `x` is on the line between\n    them. -/\ntheorem affine_iff_mem_iff_mem_line (s : set \u03b1) :\n  is_affine\n s \u2194 \u2200 x, x \u2208 s \u2194 \u2203 v\u2081 v\u2082 \u2208 s, x \u2208 line v\u2081 v\u2082 :=\nbegin\n  apply iff.intro mem_iff_mem_line (\u03bb hs, _),\n  apply set.eq_of_subset_of_subset (\u03bb _ h, _) (\u03bb _, affine_hull.of_set),\n  induction h with _ h\u2082 _ _ _ _ _ h hv\u2081 hv\u2082,\n    { assumption },\n    { exact (hs _).mpr \u27e8_, _, hv\u2081, hv\u2082, h\u27e9 }\nend\n\nprotected theorem is_convex (s : set \u03b1) : is_convex $ affine_hull s :=\nbegin\n  apply set.eq_of_subset_of_subset (\u03bb _ h, _) (convex_hull.self_subs_hull _),\n  induction h with _ h _ _ _ _ _ h hv\u2081 hv\u2082, { assumption },\n  exact affine_hull.of_line hv\u2081 hv\u2082 (line.intrv_subs _ _ h)\nend\n\nprotected theorem univ : @is_affine \u03b1 _ set.univ :=\naffine_hull.of_univ\n\nend is_affine\n\ntheorem affine_hull.eq_bInter_affine (s : set \u03b1) :\n  affine_hull s = \u22c2 (s\u2081 \u2287 s) (h : is_affine s\u2081), s\u2081 :=\nbegin\n  apply set.eq_of_subset_of_subset (\u03bb _ h, _) (\u03bb _ h, _),\n    { simp only [is_affine.affine_def, set.mem_Inter],\n      intros _ hs\u2081 hs\u2082, rw \u2190hs\u2082,\n      exact affine_hull.is_mono hs\u2081 h },\n    { simp only [set.mem_Inter] at h,\n      specialize h _ (affine_hull.self_subs_span _),\n      exact h (affine_hull.affine\n     _) }\nend\nend\n", "meta": {"author": "ocornoc", "repo": "geodude", "sha": "e63c87db67f1686c902e9bcd1863e74e1a29457f", "save_path": "github-repos/lean/ocornoc-geodude", "path": "github-repos/lean/ocornoc-geodude/geodude-e63c87db67f1686c902e9bcd1863e74e1a29457f/src/ordered/convex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7153760042320882}}
{"text": "\n#print nat.less_than_or_equal\n\nexample : 7 <= 19 :=\nbegin\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.refl,\nend\n\nexample : 7 <= 19 :=\nbegin\nrepeat { \n  apply nat.less_than_or_equal.step;\n  try  { apply nat.less_than_or_equal.refl } \n},\nend\n\n#print gt\n#print nat.lt\n\nexample : \u2200 n : \u2115, nat.succ n > n :=\nbegin\nintro n,\nunfold gt,\napply nat.less_than_or_equal.refl,\nend\n\n#print nat.add_succ\n\nlemma foo : \n  \u2200 n m, nat.succ (n + m) = n + nat.succ m :=\nbegin\n  intros n m,\n  apply eq.symm,\n  rw nat.add_comm,\n  simp,\nend\n\ntheorem sum_inequality (a b : nat) : \n  a > b \u2192 a + a > b + b :=\nbegin\nintro h,\nchange b < a at h,\nchange nat.succ b <= a at h,\nchange b + b < a + a,\nchange nat.succ (b + b) <= a + a,\ninduction h,\n\nrewrite nat.add_succ,\nsimp [nat.add],\nrewrite foo,\napply nat.less_than_or_equal.step,\napply nat.less_than_or_equal.refl,\n\n\nend", "meta": {"author": "kevinsullivan", "repo": "cs-dm-lean", "sha": "a06a94e98be77170ca1df486c8189338b16cf6c6", "save_path": "github-repos/lean/kevinsullivan-cs-dm-lean", "path": "github-repos/lean/kevinsullivan-cs-dm-lean/cs-dm-lean-a06a94e98be77170ca1df486c8189338b16cf6c6/src/13_Relations/less_than.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7153759998688661}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\nFrom https://github.com/leanprover-community/mathlib/blob/71b1be63560d43c689b2c1338ed1366619ce2940/src/linear_algebra/clifford_algebra/grading.lean\n-/\nimport linear_algebra.clifford_algebra.basic\nimport data.zmod.basic\n\nimport cicm2022.internal.graded_ring\n\n/-!\n# Results about the grading structure of the clifford algebra\n\nThe main result is `clifford_algebra.graded_algebra`, which says that the clifford algebra is a\n\u2124\u2082-graded algebra (or \"superalgebra\").\n-/\n\nnamespace clifford_algebra\nvariables {R M : Type*} [comm_ring R] [add_comm_group M] [module R M]\nvariables {Q : quadratic_form R M}\n\nopen_locale direct_sum\n\nvariables (Q)\n\n/-- The even or odd submodule, defined as the supremum of the even or odd powers of\n`(\u03b9 Q).range`. `even_odd 0` is the even submodule, and `even_odd 1` is the odd submodule. -/\ndef even_odd (i : zmod 2) : submodule R (clifford_algebra Q) :=\n\u2a06 (j : {n : \u2115 // \u2191n = i}), (\u03b9 Q).range ^ (j : \u2115)\n\nlemma one_le_even_odd_zero : 1 \u2264 even_odd Q 0 :=\nbegin\n  refine le_trans _ (le_supr _ \u27e80, nat.cast_zero\u27e9),\n  exact (pow_zero _).ge,\nend\n\nlemma range_\u03b9_le_even_odd_one : (\u03b9 Q).range \u2264 even_odd Q 1 :=\nbegin\n  refine le_trans _ (le_supr _ \u27e81, nat.cast_one\u27e9),\n  exact (pow_one _).ge,\nend\n\nlemma \u03b9_mem_even_odd_one (m : M) : \u03b9 Q m \u2208 even_odd Q 1 :=\nrange_\u03b9_le_even_odd_one Q $ linear_map.mem_range_self _ m\n\nlemma \u03b9_mul_\u03b9_mem_even_odd_zero (m\u2081 m\u2082 : M) :\n  \u03b9 Q m\u2081 * \u03b9 Q m\u2082 \u2208 even_odd Q 0 :=\nsubmodule.mem_supr_of_mem \u27e82, rfl\u27e9 begin\n  rw [subtype.coe_mk, pow_two],\n  exact submodule.mul_mem_mul ((\u03b9 Q).mem_range_self m\u2081) ((\u03b9 Q).mem_range_self m\u2082),\nend\n\nlemma even_odd_mul_le (i j : zmod 2) : even_odd Q i * even_odd Q j \u2264 even_odd Q (i + j) :=\nbegin\n  simp_rw [even_odd, submodule.supr_eq_span, submodule.span_mul_span],\n  apply submodule.span_mono,\n  intros z hz,\n  obtain \u27e8x, y, hx, hy, rfl\u27e9 := hz,\n  obtain \u27e8xi, hx'\u27e9 := set.mem_Union.mp hx,\n  obtain \u27e8yi, hy'\u27e9 := set.mem_Union.mp hy,\n  refine set.mem_Union.mpr \u27e8\u27e8xi + yi, by simp only [nat.cast_add, xi.prop, yi.prop]\u27e9, _\u27e9,\n  simp only [subtype.coe_mk, nat.cast_add, pow_add],\n  exact submodule.mul_mem_mul hx' hy',\nend\n\ninstance even_odd.graded_monoid : set_like.graded_monoid (even_odd Q) :=\n{ one_mem := submodule.one_le.mp (one_le_even_odd_zero Q),\n  mul_mem := \u03bb i j p q hp hq, submodule.mul_le.mp (even_odd_mul_le Q _ _) _ hp _ hq }\n\n/-- A version of `clifford_algebra.\u03b9` that maps directly into the graded structure. This is\nprimarily an auxiliary construction used to provide `clifford_algebra.graded_algebra`. -/\ndef graded_algebra.\u03b9 : M \u2192\u2097[R] \u2a01 i : zmod 2, even_odd Q i :=\ndirect_sum.lof R (zmod 2) (\u03bb i, \u21a5(even_odd Q i)) 1 \u2218\u2097 (\u03b9 Q).cod_restrict _ (\u03b9_mem_even_odd_one Q)\n\nlemma graded_algebra.\u03b9_apply (m : M) :\n  graded_algebra.\u03b9 Q m = direct_sum.of (\u03bb i, \u21a5(even_odd Q i)) 1 (\u27e8\u03b9 Q m, \u03b9_mem_even_odd_one Q m\u27e9) :=\nrfl\n\nlemma graded_algebra.\u03b9_sq_scalar (m : M) :\n  graded_algebra.\u03b9 Q m * graded_algebra.\u03b9 Q m = algebra_map R _ (Q m) :=\nbegin\n  rw [graded_algebra.\u03b9_apply, direct_sum.of_mul_of, direct_sum.algebra_map_apply],\n  refine direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext rfl $ \u03b9_sq_scalar _ _),\nend\n\nlemma graded_algebra.lift_\u03b9_eq (i' : zmod 2) (x' : even_odd Q i') :\n  lift Q \u27e8graded_algebra.\u03b9 Q, graded_algebra.\u03b9_sq_scalar Q\u27e9 x' =\n    direct_sum.of (\u03bb i, even_odd Q i) i' x' :=\nbegin\n  cases x' with x' hx',\n  dsimp only [subtype.coe_mk, direct_sum.lof_eq_of],\n  refine submodule.supr_induction' _ (\u03bb i x hx, _) _ (\u03bb x y hx hy ihx ihy, _) hx',\n  { obtain \u27e8i, rfl\u27e9 := i,\n    dsimp only [subtype.coe_mk] at hx,\n    refine submodule.pow_induction_on_left' _\n      (\u03bb r, _) (\u03bb x y i hx hy ihx ihy, _) (\u03bb m hm i x hx ih, _) hx,\n    { rw [alg_hom.commutes, direct_sum.algebra_map_apply], refl },\n    { rw [alg_hom.map_add, ihx, ihy, \u2190map_add], refl },\n    { obtain \u27e8_, rfl\u27e9 := hm,\n      rw [alg_hom.map_mul, ih, lift_\u03b9_apply, graded_algebra.\u03b9_apply, direct_sum.of_mul_of],\n      refine direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext _ _);\n        dsimp only [graded_monoid.mk, subtype.coe_mk],\n      { rw [nat.succ_eq_add_one, add_comm, nat.cast_add, nat.cast_one] },\n      refl } },\n  { rw alg_hom.map_zero,\n    apply eq.symm,\n    apply dfinsupp.single_eq_zero.mpr, refl, },\n  { rw [alg_hom.map_add, ihx, ihy, \u2190map_add], refl },\nend\n\n/-- The clifford algebra is graded by the even and odd parts. -/\ninstance graded_algebra : graded_algebra (even_odd Q) :=\ngraded_algebra.of_alg_hom (even_odd Q)\n  (lift _ \u27e8graded_algebra.\u03b9 Q, graded_algebra.\u03b9_sq_scalar Q\u27e9)\n  -- the proof from here onward is mostly similar to the `tensor_algebra` case, with some extra\n  -- handling for the `supr` in `even_odd`.\n  (begin\n    ext m,\n    dsimp only [linear_map.comp_apply, alg_hom.to_linear_map_apply, alg_hom.comp_apply,\n      alg_hom.id_apply],\n    rw [lift_\u03b9_apply, graded_algebra.\u03b9_apply, direct_sum.coe_alg_hom_of, subtype.coe_mk],\n  end)\n  (by exact graded_algebra.lift_\u03b9_eq Q)\n\nlemma supr_\u03b9_range_eq_top : (\u2a06 i : \u2115, (\u03b9 Q).range ^ i) = \u22a4 :=\nbegin\n  rw [\u2190 (direct_sum.decomposition.is_internal (even_odd Q)).submodule_supr_eq_top, eq_comm],\n  calc    (\u2a06 (i : zmod 2) (j : {n // \u2191n = i}), (\u03b9 Q).range ^ \u2191j)\n        = (\u2a06 (i : \u03a3 i : zmod 2, {n : \u2115 // \u2191n = i}), (\u03b9 Q).range ^ (i.2 : \u2115)) : by rw supr_sigma\n    ... = (\u2a06 (i : \u2115), (\u03b9 Q).range ^ i)\n        : function.surjective.supr_congr (\u03bb i, i.2) (\u03bb i, \u27e8\u27e8_, i, rfl\u27e9, rfl\u27e9) (\u03bb _, rfl),\nend\n\nlemma even_odd_is_compl : is_compl (even_odd Q 0) (even_odd Q 1) :=\n(direct_sum.decomposition.is_internal (even_odd Q)).is_compl zero_ne_one $ begin\n  have : (finset.univ : finset (zmod 2)) = {0, 1} := rfl,\n  simpa using congr_arg (coe : finset (zmod 2) \u2192 set (zmod 2)) this,\nend\n\n/-- To show a property is true on the even or odd part, it suffices to show it is true on the\nscalars or vectors (respectively), closed under addition, and under left-multiplication by a pair\nof vectors. -/\n@[elab_as_eliminator]\nlemma even_odd_induction (n : zmod 2) {P : \u03a0 x, x \u2208 even_odd Q n \u2192 Prop}\n  (hr : \u2200 v (h : v \u2208 (\u03b9 Q).range ^ n.val),\n    P v (submodule.mem_supr_of_mem \u27e8n.val, n.nat_cast_zmod_val\u27e9 h))\n  (hadd : \u2200 {x y hx hy}, P x hx \u2192 P y hy \u2192 P (x + y) (submodule.add_mem _ hx hy))\n  (h\u03b9\u03b9_mul : \u2200 m\u2081 m\u2082 {x hx}, P x hx \u2192 P (\u03b9 Q m\u2081 * \u03b9 Q m\u2082 * x)\n    (zero_add n \u25b8 set_like.graded_monoid.mul_mem (\u03b9_mul_\u03b9_mem_even_odd_zero Q m\u2081 m\u2082) hx))\n  (x : clifford_algebra Q) (hx : x \u2208 even_odd Q n) : P x hx :=\nbegin\n  apply submodule.supr_induction' _ _ (hr 0 (submodule.zero_mem _)) @hadd,\n  refine subtype.rec _,\n  simp_rw [subtype.coe_mk, zmod.nat_coe_zmod_eq_iff, add_comm n.val],\n  rintros n' \u27e8k, rfl\u27e9 xv,\n  simp_rw [pow_add, pow_mul],\n  refine submodule.mul_induction_on' _ _,\n  { intros a ha b hb,\n    refine submodule.pow_induction_on_left' ((\u03b9 Q).range ^ 2) _ _ _ ha,\n    { intro r,\n      simp_rw \u2190algebra.smul_def,\n      exact hr _ (submodule.smul_mem _ _ hb), },\n    { intros x y n hx hy,\n      simp_rw add_mul,\n      apply hadd, },\n    { intros x hx n y hy ihy,\n      revert hx,\n      simp_rw pow_two,\n      refine submodule.mul_induction_on' _ _,\n      { simp_rw linear_map.mem_range,\n        rintros _ \u27e8m\u2081, rfl\u27e9 _ \u27e8m\u2082, rfl\u27e9,\n        simp_rw mul_assoc _ y b,\n        refine h\u03b9\u03b9_mul _ _ ihy, },\n      { intros x hx y hy ihx ihy,\n        simp_rw add_mul,\n        apply hadd ihx ihy } } },\n  { intros x y hx hy,\n    apply hadd }\nend\n\n/-- To show a property is true on the even parts, it suffices to show it is true on the\nscalars, closed under addition, and under left-multiplication by a pair of vectors. -/\n@[elab_as_eliminator]\nlemma even_induction  {P : \u03a0 x, x \u2208 even_odd Q 0 \u2192 Prop}\n  (hr : \u2200 r : R, P (algebra_map _ _ r) (set_like.has_graded_one.algebra_map_mem _ _))\n  (hadd : \u2200 {x y hx hy}, P x hx \u2192 P y hy \u2192 P (x + y) (submodule.add_mem _ hx hy))\n  (h\u03b9\u03b9_mul : \u2200 m\u2081 m\u2082 {x hx}, P x hx \u2192 P (\u03b9 Q m\u2081 * \u03b9 Q m\u2082 * x)\n    (zero_add 0 \u25b8 set_like.graded_monoid.mul_mem (\u03b9_mul_\u03b9_mem_even_odd_zero Q m\u2081 m\u2082) hx))\n  (x : clifford_algebra Q) (hx : x \u2208 even_odd Q 0) : P x hx :=\nbegin\n  refine even_odd_induction Q 0 (\u03bb rx, _) @hadd h\u03b9\u03b9_mul x hx,\n  simp_rw [zmod.val_zero, pow_zero],\n  rintro \u27e8r, rfl\u27e9,\n  exact hr r,\nend\n\n/-- To show a property is true on the odd parts, it suffices to show it is true on the\nvectors, closed under addition, and under left-multiplication by a pair of vectors. -/\n@[elab_as_eliminator]\nlemma odd_induction {P : \u03a0 x, x \u2208 even_odd Q 1 \u2192 Prop}\n  (h\u03b9 : \u2200 v, P (\u03b9 Q v) (\u03b9_mem_even_odd_one _ _))\n  (hadd : \u2200 {x y hx hy}, P x hx \u2192 P y hy \u2192 P (x + y) (submodule.add_mem _ hx hy))\n  (h\u03b9\u03b9_mul : \u2200 m\u2081 m\u2082 {x hx}, P x hx \u2192 P (\u03b9 Q m\u2081 * \u03b9 Q m\u2082 * x)\n    (zero_add (1 : zmod 2) \u25b8 set_like.graded_monoid.mul_mem (\u03b9_mul_\u03b9_mem_even_odd_zero Q m\u2081 m\u2082) hx))\n  (x : clifford_algebra Q) (hx : x \u2208 even_odd Q 1) : P x hx :=\nbegin\n  refine even_odd_induction Q 1 (\u03bb \u03b9v, _) @hadd h\u03b9\u03b9_mul x hx,\n  simp_rw [zmod.val_one, pow_one],\n  rintro \u27e8v, rfl\u27e9,\n  exact h\u03b9 v,\nend\n\nend clifford_algebra", "meta": {"author": "eric-wieser", "repo": "lean-graded-rings", "sha": "53bccd2553ee2052907ff9519e63f1945e6add4c", "save_path": "github-repos/lean/eric-wieser-lean-graded-rings", "path": "github-repos/lean/eric-wieser-lean-graded-rings/lean-graded-rings-53bccd2553ee2052907ff9519e63f1945e6add4c/src/cicm2022/examples/clifford_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.715375991203013}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport combinatorics.simple_graph.clique\n\n/-!\n# Triangles in graphs\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA *triangle* in a simple graph is a `3`-clique, namely a set of three vertices that are\npairwise adjacent.\n\nThis module defines and proves properties about triangles in simple graphs.\n\n## Main declarations\n\n* `simple_graph.far_from_triangle_free`: Predicate for a graph to have enough triangles that, to\n  remove all of them, one must one must remove a lot of edges. This is the crux of the Triangle\n  Removal lemma.\n\n## TODO\n\n* Generalise `far_from_triangle_free` to other graphs, to state and prove the Graph Removal Lemma.\n* Find a better name for `far_from_triangle_free`. Added 4/26/2022. Remove this TODO if it gets old.\n-/\n\nopen finset fintype nat\nopen_locale classical\n\nnamespace simple_graph\nvariables {\u03b1 \ud835\udd5c : Type*} [fintype \u03b1] [linear_ordered_field \ud835\udd5c] {G H : simple_graph \u03b1} {\u03b5 \u03b4 : \ud835\udd5c}\n  {n : \u2115} {s : finset \u03b1}\n\n/-- A simple graph is *`\u03b5`-triangle-free far* if one must remove at least `\u03b5 * (card \u03b1)^2` edges to\nmake it triangle-free. -/\ndef far_from_triangle_free (G : simple_graph \u03b1) (\u03b5 : \ud835\udd5c) : Prop :=\nG.delete_far (\u03bb H, H.clique_free 3) $ \u03b5 * (card \u03b1^2 : \u2115)\n\nlemma far_from_triangle_free_iff :\n  G.far_from_triangle_free \u03b5 \u2194\n    \u2200 \u2983H\u2984, H \u2264 G \u2192 H.clique_free 3 \u2192 \u03b5 * (card \u03b1^2 : \u2115) \u2264 G.edge_finset.card - H.edge_finset.card :=\ndelete_far_iff\n\nalias far_from_triangle_free_iff \u2194 far_from_triangle_free.le_card_sub_card _\n\nlemma far_from_triangle_free.mono (h\u03b5 : G.far_from_triangle_free \u03b5) (h : \u03b4 \u2264 \u03b5) :\n  G.far_from_triangle_free \u03b4 :=\nh\u03b5.mono $ mul_le_mul_of_nonneg_right h $ cast_nonneg _\n\nlemma far_from_triangle_free.clique_finset_nonempty' (hH : H \u2264 G) (hG : G.far_from_triangle_free \u03b5)\n  (hcard : (G.edge_finset.card - H.edge_finset.card : \ud835\udd5c) < \u03b5 * (card \u03b1 ^ 2 : \u2115)) :\n  (H.clique_finset 3).nonempty :=\nnonempty_of_ne_empty $ H.clique_finset_eq_empty_iff.not.2 $ \u03bb hH',\n  (hG.le_card_sub_card hH hH').not_lt hcard\n\nvariables [nonempty \u03b1]\n\nlemma far_from_triangle_free.nonpos (h\u2080 : G.far_from_triangle_free \u03b5) (h\u2081 : G.clique_free 3) :\n  \u03b5 \u2264 0 :=\nbegin\n  have := h\u2080 (empty_subset _),\n  rw [coe_empty, finset.card_empty, cast_zero, delete_edges_empty_eq] at this,\n  exact nonpos_of_mul_nonpos_left (this h\u2081) (cast_pos.2 $ sq_pos_of_pos fintype.card_pos),\nend\n\nlemma clique_free.not_far_from_triangle_free (hG : G.clique_free 3) (h\u03b5 : 0 < \u03b5) :\n  \u00ac G.far_from_triangle_free \u03b5 :=\n\u03bb h, (h.nonpos hG).not_lt h\u03b5\n\nlemma far_from_triangle_free.not_clique_free (hG : G.far_from_triangle_free \u03b5) (h\u03b5 : 0 < \u03b5) :\n  \u00ac G.clique_free 3 :=\n\u03bb h, (hG.nonpos h).not_lt h\u03b5\n\nlemma far_from_triangle_free.clique_finset_nonempty (hG : G.far_from_triangle_free \u03b5) (h\u03b5 : 0 < \u03b5) :\n  (G.clique_finset 3).nonempty :=\nnonempty_of_ne_empty $ G.clique_finset_eq_empty_iff.not.2 $ hG.not_clique_free h\u03b5\n\nend simple_graph\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/simple_graph/triangle/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7153759889305146}}
{"text": "import data.list.range\nimport data.list.join\n\n@[reducible]\ndef fibonacci : \u2115 \u2192 \u2115\n| 0 := 0\n| 1 := 1\n| (n+2) := fibonacci n + fibonacci (n+1)\n\nopen nat list\n---\n@[reducible]\ndef fib_sum (n : \u2115) : \u2115 :=\n((range n).map fibonacci).sum\n\n@[reducible]\ndef fib_odd_sum (n : \u2115) : \u2115 :=\n((range n).map (\u03bb m, fibonacci (2*m + 1))).sum\n\n@[reducible]\ndef fib_even_sum (n : \u2115) : \u2115 :=\n((range n).map (\u03bb m, fibonacci (2*m))).sum\n---\ntheorem fib_odd_sum_eq : \u2200 (n : \u2115),\n  fib_odd_sum n = fibonacci (2*n)\n| 0 := rfl\n| (n+1) := by rw [fib_odd_sum,\n  sum_range_succ,\n  \u2190fib_odd_sum,\n  fib_odd_sum_eq,\n  mul_add,\n  mul_one,\n  fibonacci]\n---\ntheorem fib_even_sum_eq : \u2200 {n : \u2115} (h : n > 0),\n  fib_even_sum n + 1 = fibonacci (2*n - 1)\n| 0 h := (gt_irrefl 0 h).elim\n| 1 _ := rfl\n| (n+2) _ :=\nhave H : fib_even_sum (n+1) + 1 = fibonacci (2*(n+1) - 1) :=\n  fib_even_sum_eq (succ_pos n),\nbegin\n  rw [fib_even_sum,\n    sum_range_succ,\n    \u2190fib_even_sum,\n    add_right_comm,\n    H,\n    mul_add,\n    mul_one,\n    mul_add],\n  change fibonacci (2*n + 1) + fibonacci (2*n + 1 + 1) =\n    fibonacci (2*n + 1 + 2),\n  rw [\u2190fibonacci],\nend\n---\ntheorem fib_sum_eq : \u2200 (n : \u2115),\n  fib_sum n + 1 = fibonacci (n+1)\n| 0 := rfl\n| (n+1) :=\nbegin\n  rw [fibonacci,\n    \u2190fib_sum_eq n],\n  simp [range_succ, fib_sum,\n    add_left_comm, add_comm],\nend\n\ninductive bee : Type\n| queen : bee\n| worker : bee\n| drone : bee\n\nopen bee list\n\ninstance : has_repr bee :=\n\u27e8\u03bb s, match s with\n| queen := \"Q\"\n| worker := \"W\"\n| drone := \"D\"\nend\u27e9\n---\nnamespace bee\n\ndef parents : bee \u2192 list bee\n| queen := [queen, drone]\n| worker := [queen, drone]\n| drone := [queen]\n\ndef ancestors (b : bee) : \u2115 \u2192 list bee\n| 0 := [b]\n| (n+1) := ((ancestors n).map parents).join\n---\ndef tree_json : bee \u2192 \u2115 \u2192 string\n| b 0 := \"{\\\"name\\\":\\\"\" ++ repr b ++ \"\\\"}\"\n| b (n+1) := \"{\\\"name\\\":\\\"\" ++ repr b ++ \"\\\",\\\"children\\\":[\" ++\n  string.intercalate \",\" (b.parents.map (\u03bb p, p.tree_json n)) ++ \"]}\"\n---\nlemma drone_ancestors_concat : \u2200 (n : \u2115),\n  drone.ancestors (n+2) = drone.ancestors (n+1) ++ drone.ancestors n\n| 0 := rfl\n| (n+1) := begin\n  change ((ancestors _ (n+2)).map _).join = _,\n  conv { to_lhs,\n    rw [drone_ancestors_concat n,\n      map_append,\n      join_append], },\n  refl,\nend\n---\ntheorem drone_ancestors_length_eq_fib_succ : \u2200 (n : \u2115),\n  (drone.ancestors n).length = fibonacci (n+1)\n| 0 := rfl\n| 1 := rfl\n| (n+2) := begin\n  rw [drone_ancestors_concat,\n    length_append,\n    drone_ancestors_length_eq_fib_succ n,\n    drone_ancestors_length_eq_fib_succ (n+1),\n    add_comm],\n  refl,\nend\n\nend bee\n---\ninductive car : Type\n| rabbit : car\n| cadillac : car\n\nopen car list nat\n\ninstance : has_repr car :=\n\u27e8\u03bb s, match s with\n| rabbit := \"R\"\n| cadillac := \"C\"\nend\u27e9\n---\nnamespace car\n\n@[reducible]\ndef size : car \u2192 \u2115\n| rabbit := 1\n| cadillac := 2\n\n@[reducible]\ndef sum_size (cs : list car) : \u2115 :=\n(cs.map size).sum\n\nlemma sum_size_cons (c : car) (cs : list car) :\n  sum_size (c :: cs) = sum_size cs + c.size :=\nby simp only [sum_size, sum_cons, map, add_comm]\n---\n@[reducible]\ndef packings : \u2115 \u2192 list (list car)\n| 0 := [[]]\n| 1 := [[rabbit]]\n| (n+2) := (packings (n+1)).map (cons rabbit) ++\n  (packings n).map (cons cadillac)\n---\ntheorem num_packings_eq_fib : \u2200 (n : \u2115),\n  (packings n).length = fibonacci (n+1)\n| 0 := rfl\n| 1 := rfl\n| (n+2) :=\nbegin\n  simp [packings, fibonacci, add_left_comm, add_comm],\n  rw [num_packings_eq_fib n,\n    num_packings_eq_fib (n+1),\n    add_left_comm,\n    add_right_inj,\n    fibonacci],\nend\n---\ntheorem packings_size : \u2200 {n : \u2115} {cs : list car} (h : cs \u2208 packings n),\n  sum_size cs = n\n| 0 cs h :=\nbegin\n  rw mem_singleton.1 h,\n  refl,\nend\n| 1 cs h :=\nbegin\n  rw mem_singleton.1 h,\n  refl,\nend\n| (n+2) cs h :=\nbegin\n  simp [packings] at h,\n  rcases h with \u27e8cs', h\u2081, h\u2082\u27e9 | \u27e8cs', h\u2081, h\u2082\u27e9,\n  all_goals { rw [\u2190h\u2082,\n    sum_size_cons,\n    size,\n    packings_size h\u2081], },\nend\n---\nlemma car_size_ne_zero (c : car) : size c \u2260 0 :=\nby cases c; contradiction\n\nlemma sum_size_zero : \u2200 {cs : list car} (h : sum_size cs = 0),\n  cs = []\n| [] _ := rfl\n| (c::cs) h :=\nbegin\n  exfalso,\n  rw [sum_size_cons,\n      add_eq_zero_iff] at h,\n  exact car_size_ne_zero c h.2,\nend\n---\nlemma sum_size_one : \u2200 {cs : list car} (h : sum_size cs = 1),\n  cs = [rabbit]\n| [] h := by contradiction\n| (rabbit::cs) h :=\nbegin\n  rw [sum_size_cons] at h,\n  simp,\n  exact sum_size_zero (succ.inj h),\nend\n| (cadillac::cs) h :=\nbegin\n  rw [sum_size_cons] at h,\n  have : sum_size cs + 1 = 0 := succ.inj h,\n  contradiction,\nend\n---\ntheorem all_packings : \u2200 {n : \u2115} {cs : list car} (h : sum_size cs = n),\n  cs \u2208 packings n\n| 0 cs h := by simp [packings, sum_size_zero h]\n| 1 cs h := by simp [packings, sum_size_one h]\n| (n+2) [] h := by contradiction\n| (n+2) (rabbit::cs) h :=\nbegin\n  rw [sum_size_cons,\n    add_left_inj 1] at h,\n  simp [packings, all_packings, h],\nend\n| (n+2) (cadillac::cs) h :=\nbegin\n  rw [sum_size_cons,\n    add_left_inj 2] at h,\n  simp [packings, all_packings, h],\nend\n\nend car\n", "meta": {"author": "bryangingechen", "repo": "lean-fibonacci", "sha": "8ac73044b17ff0c5f6b50cab7ee10456d54dba87", "save_path": "github-repos/lean/bryangingechen-lean-fibonacci", "path": "github-repos/lean/bryangingechen-lean-fibonacci/lean-fibonacci-8ac73044b17ff0c5f6b50cab7ee10456d54dba87/src/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7153475949706285}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport analysis.inner_product_space.projection\nimport linear_algebra.orientation\n\n/-!\n# Orientations of real inner product spaces.\n\nThis file provides definitions and proves lemmas about orientations of real inner product spaces.\n\n## Main definitions\n\n* `orientation.fin_orthonormal_basis` is an orthonormal basis, indexed by `fin n`, with the given\norientation.\n\n-/\n\nnoncomputable theory\n\nvariables {E : Type*} [inner_product_space \u211d E]\nvariables {\u03b9 : Type*} [fintype \u03b9] [decidable_eq \u03b9]\n\nopen finite_dimensional\n\n/-- `basis.adjust_to_orientation`, applied to an orthonormal basis, produces an orthonormal\nbasis. -/\nlemma orthonormal.orthonormal_adjust_to_orientation [nonempty \u03b9] {e : basis \u03b9 \u211d E}\n  (h : orthonormal \u211d e) (x : orientation \u211d E \u03b9) : orthonormal \u211d (e.adjust_to_orientation x) :=\nh.orthonormal_of_forall_eq_or_eq_neg (e.adjust_to_orientation_apply_eq_or_eq_neg x)\n\n/-- An orthonormal basis, indexed by `fin n`, with the given orientation. -/\nprotected def orientation.fin_orthonormal_basis {n : \u2115} (hn : 0 < n) (h : finrank \u211d E = n)\n  (x : orientation \u211d E (fin n)) : basis (fin n) \u211d E :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  haveI := finite_dimensional_of_finrank (h.symm \u25b8 hn : 0 < finrank \u211d E),\n  exact (fin_orthonormal_basis h).adjust_to_orientation x\nend\n\n/-- `orientation.fin_orthonormal_basis` is orthonormal. -/\nprotected lemma orientation.fin_orthonormal_basis_orthonormal {n : \u2115} (hn : 0 < n)\n  (h : finrank \u211d E = n) (x : orientation \u211d E (fin n)) :\n  orthonormal \u211d (x.fin_orthonormal_basis hn h) :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  haveI := finite_dimensional_of_finrank (h.symm \u25b8 hn : 0 < finrank \u211d E),\n  exact (fin_orthonormal_basis_orthonormal h).orthonormal_adjust_to_orientation _\nend\n\n/-- `orientation.fin_orthonormal_basis` gives a basis with the required orientation. -/\n@[simp] lemma orientation.fin_orthonormal_basis_orientation {n : \u2115} (hn : 0 < n)\n  (h : finrank \u211d E = n) (x : orientation \u211d E (fin n)) :\n  (x.fin_orthonormal_basis hn h).orientation = x :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  exact basis.orientation_adjust_to_orientation _ _\nend\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/inner_product_space/orientation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.7153475858493166}}
{"text": "import data.real.basic data.real.sqrt tactic.fin_cases\n\nnamespace loh\n\nlemma real_sq_nonneg (x : \u211d) : 0 \u2264 x ^ 2 := sq_nonneg x\n\nlemma no_nat_half : \u00ac \u2203 (n : \u2115), 2 * n = 1 := \nbegin \n  rintro \u27e8n,hn\u27e9,\n  cases n; cases hn\nend\n\nlemma int_domain : \u2200 (n m : \u2124), n * m = 0 \u2192 n = 0 \u2228 m = 0 := \n  \u03bb n m h, int.eq_zero_or_eq_zero_of_mul_eq_zero h\n\nsection root_set \n\nvariables {u : \u211d} (hu : u > 0)\ninclude hu\n\ndef root_set := { x : \u211d | x ^ 2 = u }\nnoncomputable def pos_root : root_set hu := \n  \u27e8real.sqrt u, real.sq_sqrt (le_of_lt hu)\u27e9 \nnoncomputable def neg_root : root_set hu := \n  \u27e8- real.sqrt u, by { change _ ^ 2  = _, rw[neg_sq, real.sq_sqrt (le_of_lt hu)] } \u27e9 \n\nlemma coe_pos_root : ((pos_root hu) : \u211d) = real.sqrt u := rfl\nlemma coe_neg_root : ((neg_root hu) : \u211d) = - real.sqrt u := rfl\n\nlemma pos_root_pos : (pos_root hu : \u211d) > 0 := real.sqrt_pos.mpr hu\nlemma neg_root_neg : \u00ac ((neg_root hu : \u211d) > 0) := \n  not_lt_of_gt (neg_neg_of_pos (pos_root_pos hu))\n\nlemma sq_pos_root : (pos_root hu : \u211d) ^ 2 = u := (pos_root hu).property\nlemma sq_neg_root : (neg_root hu : \u211d) ^ 2 = u := (neg_root hu).property\n\nnoncomputable def root_set_to : root_set hu \u2192 fin 2 := \u03bb u, ite ((u : \u211d) > 0) 0 1\nnoncomputable def root_set_of : fin 2 \u2192 root_set hu := \u03bb i, ite (i = 0) (pos_root hu) (neg_root hu)\n\nlemma coe_root_set_of : \u2200 (i : fin 2), ((root_set_of hu i) : \u211d) = ite (i = 0) (real.sqrt u) (- real.sqrt u) := \nbegin\n  intro i, dsimp[root_set_of], split_ifs; refl\nend\n\nlemma root_set_els : \u2200 (x : root_set hu), x = (pos_root hu) \u2228 x = (neg_root hu) := \nbegin\n  rintro \u27e8x, hx : x ^ 2 = u\u27e9,\n  let v := real.sqrt u,\n  rw[\u2190 sub_eq_zero, \u2190 (real.sq_sqrt (le_of_lt hu))] at hx,\n  have : x ^ 2 - v ^ 2 = (x - v) * (x - (- v)) := by ring, \n  rw[this] at hx,\n  replace hx := eq_zero_or_eq_zero_of_mul_eq_zero hx,\n  rw[sub_eq_zero, sub_eq_zero] at hx,\n  cases hx with hx hx,\n  { left , ext, change x = _, rw[coe_pos_root], exact hx },\n  { right, ext, change x = _, rw[coe_neg_root], exact hx }\nend\n\nnoncomputable def root_set.equiv : (root_set hu) \u2243 (fin 2) := {\n  to_fun := root_set_to hu,\n  inv_fun := root_set_of hu,\n  left_inv := begin\n    intro x,\n    cases root_set_els hu x with hp hn,\n    { rw[hp], dsimp[root_set_to], rw[if_pos (pos_root_pos hu)], refl },\n    { rw[hn], dsimp[root_set_to], rw[if_neg (neg_root_neg hu)], refl }\n  end,\n  right_inv := begin\n    intro i,\n    dsimp[root_set_of],\n    split_ifs,\n    { dsimp[root_set_to], rw[h, if_pos (pos_root_pos hu)] },\n    { dsimp[root_set_to], rw[if_neg (neg_root_neg hu)], \n      fin_cases i; trivial,\n    }\n  end\n}\nend root_set \n\nexample (x : \u211d) (h : 0 \u2264 x) : (abs x) = x := by library_search\n\nnoncomputable def abs_cases (x : \u211d) : { u : \u211d // 0 \u2264 u \u2227 (abs x) = u \u2227 (x = u \u2228 x = -u) } := \nbegin \n  use (abs x), split, exact (abs_nonneg x), split, refl,\n  by_cases h : x \u2265 0,\n  {left, rw[abs_eq_self.mpr h]},\n  {right, rw[abs_eq_neg_self.mpr (le_of_not_ge h), neg_neg] }\nend\n\nlemma tri_ineq (x y : \u211d) : abs (x + y) \u2264 (abs x) + (abs y) := sorry\n\ndef conv_to (x : \u2115 \u2192 \u211d) (a : \u211d) : Prop := \n  \u2200 (\u03b5 : \u211d) (h\u03b5 : \u03b5 > 0), \u2203 (N : \u2115), \u2200 (n : \u2115), n \u2265 N \u2192 (abs (x n - a) < \u03b5)\n\nsection jective\n\nvariables {X Y : Type*} (f : X \u2192 Y)\n\ndef inj (f : X \u2192 Y) := \u2200 x\u2080 x\u2081 : X, f x\u2080 = f x\u2081 \u2192 x\u2080 = x\u2081\n\ndef surj (f : X \u2192 Y) := \u2200 y : Y, \u2203 x : X, f x = y\n\ndef bij (f : X \u2192 Y) := (inj f) \u2227 (surj f)\n\nlemma inj_of_bij {f : X \u2192 Y} (h : bij f) : inj f := h.1\n\nlemma surj_of_bij {f : X \u2192 Y} (h : bij f) : surj f := h.2\n\nlemma bij_of_inj_of_surj {f : X \u2192 Y} (hi : inj f) (hs : surj f) : bij f := \u27e8hi, hs\u27e9\n\n\n\nend jective\n\nend loh\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/exercises/loh/exercises_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384593, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7153186667347894}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module topology.fiber_bundle.is_homeomorphic_trivial_bundle\n! leanprover-community/mathlib commit be2c24f56783935652cefffb4bfca7e4b25d167e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.Homeomorph\n\n/-!\n# Maps equivariantly-homeomorphic to projection in a product\n\nThis file contains the definition `IsHomeomorphicTrivialFiberBundle F p`, a Prop saying that a\nmap `p : Z \u2192 B` between topological spaces is a \"trivial fiber bundle\" in the sense that there\nexists a homeomorphism `h : Z \u2243\u209c B \u00d7 F` such that `proj x = (h x).1`.  This is an abstraction which\nis occasionally convenient in showing that a map is open, a quotient map, etc.\n\nThis material was formerly linked to the main definition of fiber bundles, but after a series of\nrefactors, there is no longer a direct connection.\n-/\n\n\nvariable {B : Type _} (F : Type _) {Z : Type _} [TopologicalSpace B] [TopologicalSpace F]\n  [TopologicalSpace Z]\n\n/-- A trivial fiber bundle with fiber `F` over a base `B` is a space `Z`\nprojecting on `B` for which there exists a homeomorphism to `B \u00d7 F` that sends `proj`\nto `prod.fst`. -/\ndef IsHomeomorphicTrivialFiberBundle (proj : Z \u2192 B) : Prop :=\n  \u2203 e : Z \u2243\u209c B \u00d7 F, \u2200 x, (e x).1 = proj x\n#align is_homeomorphic_trivial_fiber_bundle IsHomeomorphicTrivialFiberBundle\n\nnamespace IsHomeomorphicTrivialFiberBundle\n\nvariable {F} {proj : Z \u2192 B}\n\nprotected theorem proj_eq (h : IsHomeomorphicTrivialFiberBundle F proj) :\n    \u2203 e : Z \u2243\u209c B \u00d7 F, proj = Prod.fst \u2218 e :=\n  \u27e8h.choose, (funext h.choose_spec).symm\u27e9\n#align is_homeomorphic_trivial_fiber_bundle.proj_eq IsHomeomorphicTrivialFiberBundle.proj_eq\n\n/-- The projection from a trivial fiber bundle to its base is surjective. -/\nprotected theorem surjective_proj [Nonempty F] (h : IsHomeomorphicTrivialFiberBundle F proj) :\n    Function.Surjective proj := by\n  obtain \u27e8e, rfl\u27e9 := h.proj_eq\n  exact Prod.fst_surjective.comp e.surjective\n#align is_homeomorphic_trivial_fiber_bundle.surjective_proj IsHomeomorphicTrivialFiberBundle.surjective_proj\n\n/-- The projection from a trivial fiber bundle to its base is continuous. -/\nprotected theorem continuous_proj (h : IsHomeomorphicTrivialFiberBundle F proj) : Continuous proj :=\n  by obtain \u27e8e, rfl\u27e9 := h.proj_eq; exact continuous_fst.comp e.continuous\n#align is_homeomorphic_trivial_fiber_bundle.continuous_proj IsHomeomorphicTrivialFiberBundle.continuous_proj\n\n/-- The projection from a trivial fiber bundle to its base is open. -/\nprotected theorem isOpenMap_proj (h : IsHomeomorphicTrivialFiberBundle F proj) : IsOpenMap proj :=\n  by obtain \u27e8e, rfl\u27e9 := h.proj_eq; exact isOpenMap_fst.comp e.isOpenMap\n#align is_homeomorphic_trivial_fiber_bundle.is_open_map_proj IsHomeomorphicTrivialFiberBundle.isOpenMap_proj\n\n/-- The projection from a trivial fiber bundle to its base is open. -/\nprotected theorem quotientMap_proj [Nonempty F] (h : IsHomeomorphicTrivialFiberBundle F proj) :\n    QuotientMap proj :=\n  h.isOpenMap_proj.to_quotientMap h.continuous_proj h.surjective_proj\n#align is_homeomorphic_trivial_fiber_bundle.quotient_map_proj IsHomeomorphicTrivialFiberBundle.quotientMap_proj\n\nend IsHomeomorphicTrivialFiberBundle\n\n/-- The first projection in a product is a trivial fiber bundle. -/\ntheorem isHomeomorphicTrivialFiberBundle_fst :\n    IsHomeomorphicTrivialFiberBundle F (Prod.fst : B \u00d7 F \u2192 B) :=\n  \u27e8Homeomorph.refl _, fun _x => rfl\u27e9\n#align is_homeomorphic_trivial_fiber_bundle_fst isHomeomorphicTrivialFiberBundle_fst\n\n/-- The second projection in a product is a trivial fiber bundle. -/\ntheorem isHomeomorphicTrivialFiberBundle_snd :\n    IsHomeomorphicTrivialFiberBundle F (Prod.snd : F \u00d7 B \u2192 B) :=\n  \u27e8Homeomorph.prodComm _ _, fun _x => rfl\u27e9\n#align is_homeomorphic_trivial_fiber_bundle_snd isHomeomorphicTrivialFiberBundle_snd\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/FiberBundle/IsHomeomorphicTrivialBundle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.715318660691037}}
{"text": "import group_theory.group_action group_theory.coset\nimport hp.tactic.hp_interactive\n\nnamespace examples\n\nsection\nvariables {G H I : Type} [group G] [group H] [group I]\nvariables {f : G \u2192 H} {g : H \u2192 I}\n\ndef is_hom (f : G \u2192 H) := \u2200 (x y : G), f (x * y) = f x * f y\nattribute [class] is_hom\nvariables [is_hom f]\nlemma is_hom.one : f 1 = 1 :=\nbegin\n  apply mul_right_eq_self.1,\n  show (f 1) * (f 1) = (f 1),\n  rw \u2190\u2039is_hom f\u203a,\n  simp,\nend\n\nlemma is_hom.inv (f : G \u2192 H) [is_hom f] {x} : f (x\u207b\u00b9) = (f x)\u207b\u00b9 :=\nbegin\n  have : f x * f (x\u207b\u00b9) = f x * (f x)\u207b\u00b9,\n  rw \u2190\u2039is_hom f\u203a, simp, apply is_hom.one,\n  exact mul_left_cancel this\nend\n\nexample : is_hom f \u2192 is_hom g \u2192 is_hom (g \u2218 f) :=\nbegin\n  intros hf hg x y,\n  simp,\n  rewrite [hf,hg]\nend\n\nexample : is_hom f \u2192 is_hom g \u2192 is_hom (g \u2218 f) :=\nbegin\n  -- intros, simp, rw [\u2039is_hom f\u203a, \u2039is_hom g\u203a],\n  assume : is_hom f,\n  assume : is_hom g,\n  assume (x y : G),\n  calc g (f (x * y)) = g (f x * f y)         : by rewrite \u2039is_hom f\u203a\n                 ... = (g (f x)) * (g (f y)) : by rewrite \u2039is_hom g\u203a,\nend\n\n-- def kernel (f : G \u2192 H) [is_hom f ] := {g : G | f g = 1}\n\ndef kernel (f : G \u2192 H) [h\u2081 : is_hom f] : subgroup G :=\nbegin\n  refine {carrier := {g : G | f g = 1}, ..},\n  apply is_hom.one,\n    show \u2200 (a b : G) (ha : f a = 1) (hb : f b = 1), f (a * b) = 1,\n    intros,\n    rw [\u2039is_hom f\u203a, ha, hb],\n    simp,\n  show \u2200 (a : G) (ha : f a = 1), f a\u207b\u00b9 = 1,\n  intros,\n  rw (is_hom.inv f),\n  rw ha,\n  simp\nend\n\nexample (f : G \u2192 H) [h\u2081 : is_hom f] : subgroup.normal (kernel f) :=\nbegin\n  split,\n  show \u2200 (k : G) (h\u2082 : k \u2208 kernel f) (g : G), (f (g * k * g\u207b\u00b9) = 1),\n  intros,\n  have h\u2083 : f k = 1, from \u2039k \u2208 kernel f\u203a,\n  calc f (g * k * g\u207b\u00b9) = f (g * k) * f g\u207b\u00b9 : by rewrite \u2039is_hom f\u203a\n                   ... = f g * f k * f g\u207b\u00b9 : by rewrite \u2039is_hom f\u203a\n                   ... = f g * 1 * f g\u207b\u00b9   : by rewrite h\u2083\n                   ... = f g * 1 * (f g)\u207b\u00b9 : by rewrite (is_hom.inv f)\n                   ... = 1                 : by simp\nend\n\nend\n\nsection\n\nvariables {G : Type} [group G] {H : Type}\n\nlemma test_1 (x y : G) (z : H) : \u03a0 (a b : G), x = x :=\nbegin [hp]\n  trace_writeup,\n  unroll,\nend\n\nvariables {H : subgroup G} {a b : G}\n\nlemma mem_own_left_coset : a \u2208 left_coset a H :=\nbegin [hp]\n\n  -- show \u2203 (h : G), (h \u2208 H) \u2227 a * h = a,\n  -- use (1 : G),\n  -- split,\n  -- show (1 : G) \u2208 H,\n  --   apply subgroup.one_mem,\n  -- show a * (1 : G) = a,\n  --   simp\nend\n\ntheorem G1 : (left_coset a H = left_coset b H) \u2194 b\u207b\u00b9 * a \u2208 H :=\nbegin\n  split,\n  { assume he : left_coset a H = left_coset b H,\n    obtain \u27e8h,hH,p\u27e9 : \u2203 (h : G), h \u2208 H \u2227 b * h = a,\n      have : a \u2208 left_coset a H,\n        apply mem_own_left_coset,\n      have : a \u2208 left_coset b H,\n        rw he at this,\n        apply this,\n      apply this,\n    have : b\u207b\u00b9 * a = h,\n      rw \u2190 p, simp,\n    rw this,\n    assumption,\n  },\n  { intro H1,\n    apply set.eq_of_subset_of_subset,\n    { rintros g \u27e8h,hH,e\u27e9,\n      refine \u27e8(b\u207b\u00b9 * a) * h,_,_\u27e9,\n      apply subgroup.mul_mem, apply H1, apply hH,\n      simp at e,\n      rw [mul_assoc, e], simp,\n    },\n    { rintros g \u27e8h,hH,e\u27e9,\n      refine \u27e8_,_,_\u27e9,\n      rotate 2,\n      rw \u2190 e,\n      simp,\n      apply mul_eq_of_eq_inv_mul,\n      refl,\n      rw [\u2190mul_assoc],\n      apply subgroup.mul_mem,\n      refine (subgroup.inv_mem_iff H).1 _,\n      simp, apply H1, apply hH\n    }\n  }\nend\n\n/- Every kernel is a normal subgroup -/\n\n-- def kernel {H G : Type} [group H] [group G] (f : H \u2192 G) [group_hom]\n\n-- example :\n\n-- /- This one is too classical.\n\n--  -/\n-- -- example : (\u00ac disjoint (left_coset a H) (left_coset b H)) \u2192 left_coset a H = left_coset b H :=\n-- -- begin\n-- --   intros h\u2081,\n-- --   refine (G1 ).2 _,\n-- --   apply set.disjoint.union_left\n-- -- end\n\nend\n\n\nend examples", "meta": {"author": "EdAyers", "repo": "lean-humanproof-thesis", "sha": "ce8331df1883f286ab8cc7b61a328afdc006a059", "save_path": "github-repos/lean/EdAyers-lean-humanproof-thesis", "path": "github-repos/lean/EdAyers-lean-humanproof-thesis/lean-humanproof-thesis-ce8331df1883f286ab8cc7b61a328afdc006a059/src/examples/groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7153186560515785}}
{"text": "import tactic.tidy\n\nimport category_theory.category\nimport set_category.diagram_lemmas\nimport help_functions\n\n\n\n\nnamespace Equalizer\n\nopen set \n     diagram_lemmas\n     classical\n     function\n     help_functions\n     category_theory\n\n\nuniverses v u\n\nlocal notation f ` \u229a `:80 g:80 := category_struct.comp g f\n\ndef is_equalizer {X : Type v} [category X]\n    {A B E : X} (f g : A \u27f6 B)\n                (e : E \u27f6 A) : Prop := \n    f \u229a e = g \u229a e \u2227 \n    \u03a0 {Q : X} (q : Q \u27f6 A),\n        f \u229a q = g \u229a q \u2192\n            \u2203! h : Q \u27f6 E, q = e \u229a h\n\n\nlemma equalizer_is_mono {X : Type v} [category X]\n    {A B E : X} (f\u2081 f\u2082 : A \u27f6 B)\n    (e : E \u27f6 A) (equaliz : is_equalizer f\u2081 f\u2082 e):\n    mono e :=\n    \u27e8\n        begin\n            intros Q g\u2081 g\u2082 m,\n            have s1 : f\u2081 \u229a (e \u229a g\u2081) = f\u2082 \u229a (e \u229a g\u2081) := by tidy,\n            have compit : _ := equaliz.2 (e \u229a g\u2081) s1,\n            cases compit with h spec_h,\n            have g\u2081_h : g\u2081 = h := spec_h.2 g\u2081 rfl,\n            have g\u2082_h : g\u2082 = h := spec_h.2 g\u2082 m,\n            simp [g\u2081_h , g\u2082_h]\n        end\n    \u27e9 \n\nvariables {A B : Type u}\nvariables (f g : A \u27f6 B)\n\ndef equalizer_set : set A := \u03bb a, f a = g a\n\n\nlemma eqaulizer_set_is_equalizer : \n    is_equalizer f g ((equalizer_set f g) \u21aa A) :=\n    let E := equalizer_set f g in\n    let e := E \u21aa A in\n    \u27e8 \n        have elements : \u2200 a, (f \u2218 e) a = (g \u2218 e) a := \n                \u03bb a, a.property,\n        funext elements\n        ,\n        begin\n            intros Q q fq_gq,\n            have s0 : \u2200 b : Q , (f \u229a q) b = (g \u229a q) b := \n                            assume b, by rw fq_gq,\n            have s1 : \u2200 b : Q , q b \u2208 E := \n                        assume b, s0 b,\n            let h : Q \u2192 E := \u03bb b, \u27e8q b, s1 b\u27e9,\n            have q_eh : q = e \u2218 h := by tidy,\n            use h,\n            split,\n            exact q_eh, \n            intros h\u2081 spec_h\u2081,\n            tidy,\n            have inj : injective e := inj_inclusion A E,\n            have ey_eh: e \u2218 h\u2081 = e \u2218 h := by rw [\u2190 spec_h\u2081 , q_eh],\n            have elements : \u2200 b, (e \u2218 h\u2081) b = (e \u2218 h) b := \n                    assume a, by rw ey_eh,\n            dsimp at *, \n            solve_by_elim\n        end\n    \u27e9 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend Equalizer", "meta": {"author": "QaisHamarneh", "repo": "Coalgebra-in-Lean", "sha": "bd0452df98bc64b608e5dfd7babc42c301bb6a46", "save_path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean", "path": "github-repos/lean/QaisHamarneh-Coalgebra-in-Lean/Coalgebra-in-Lean-bd0452df98bc64b608e5dfd7babc42c301bb6a46/src/set_category/limits/Equalizer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7153186541895667}}
{"text": "import lib.m154\n\n/-\n# Quantificateur universel et disjonctions\n\nCe fichier est consacr\u00e9 au quantificateur universel, symbolis\u00e9 par `\u2200`\net au connecteur logique de disjonction, not\u00e9 simplement \u00ab ou \u00bb sur papier\net `\u2228` dans Lean ainsi que dans les livres de logique pure. \n\nOn rappelle qu'un *pr\u00e9dicat* sur un type d'objets math\u00e9matiques `X` est un \u00e9nonc\u00e9\nd\u00e9pendant d'un objet `x` de type `X`. Le plus souvent pour nous `X = \u211d`, le type\ndes nombres r\u00e9els. Un pr\u00e9dicat n'est donc pas un \u00e9nonc\u00e9 math\u00e9matique autonome.\n\n\u00c0 partir d'un pr\u00e9dicat `P` sur `X`, on peut former l'\u00e9nonc\u00e9 autonome : \n\u00ab Pour tout x, P x \u00bb, qu'on note `\u2200 x, P x`. La d\u00e9finition suivante\nconstruit un \u00e9nonc\u00e9, portant sur une fonction `f` fix\u00e9e, \u00e0 partir du pr\u00e9dicat \nsur `\u211d` qui associe \u00e0 tout nombre r\u00e9el `x` l'\u00e9nonc\u00e9 `f (-x) = f x` \n(notons que Lean est \u00e9conome en parenth\u00e8ses ici).\n-/\n\ndef paire (f : \u211d \u2192 \u211d) := \u2200 x, f (-x) = f x\n\n/-\nDans l'\u00e9nonc\u00e9 `\u2200 x, f(-x) = f x`, le type `\u211d` de `x` n'apparait pas explicitement\ncar on peut le d\u00e9duire de l'information que `f` est une fonction de `\u211d` dans `\u211d`\nqui est visiblement appliqu\u00e9e \u00e0 `x`.\n\nCependant il peut \u00eatre plus clair de l'indiquer explicitement, et ce serait\nindispensable sans l'indication fournie par `f x`. Sur papier on \u00e9crit\n\u00ab \u2200 x \u2208 \u211d, \u00bb plut\u00f4t que \u00ab \u2200 x : \u211d, \u00bb\n-/\n\ndef impaire (f : \u211d \u2192 \u211d) := \u2200 x : \u211d, f (-x) = -f x\n\n/-\nPour *d\u00e9montrer* un \u00e9nonc\u00e9 de la forme `\u2200 x, P x` o\u00f9 `P` est un pr\u00e9dicat, \nil faut se donner un \u00e9l\u00e9ment `x` arbitraire et d\u00e9montrer l'\u00e9nonc\u00e9 `P x`.\nDans Lean on utilisera la commande `Soit x`, pour se donner un \u00e9l\u00e9ment `x`.\nPour plus de clart\u00e9, on peut indiquer le type d'objet `x` consid\u00e9r\u00e9 en \u00e9crivant\n`Soit x : \u211d,`. Sur paper on \u00e9crirait plut\u00f4t : \u00ab Soit x un nombre r\u00e9el \u00bb,\nou bien \u00ab Soit x \u2208 \u211d \u00bb.\n\nPour *utiliser* un tel \u00e9nonc\u00e9, on peut le sp\u00e9cialiser \u00e0 n'importe quel objet `x`\nde type `X`. Dans l'exemple suivant, on nomme `x\u2080` le nombre r\u00e9el introduit\npar la commande `Soit` pour insister sur le fait qu'il est fix\u00e9 et bien voir \nqu'apr\u00e8s la ligne `On applique hf \u00e0 x\u2080`, l'hypoth\u00e8se `hf` ne porte plus que \nsur ce seul nombre.\n-/\n\n\n\n-- Si f et g sont paires alors leur somme l'est aussi.\nexample (f g : \u211d \u2192 \u211d) : paire f \u2192 paire g \u2192  paire (f + g) :=\nbegin\n  Supposons (hf : \u2200 x, f (-x) = f x) (hg : \u2200 x, g (-x) = g x),\n  Montrons que \u2200 x, (f+g) (-x) = (f+g) x,\n  Soit x\u2080 : \u211d,\n  On applique hf \u00e0 x\u2080,\n  On applique hg \u00e0 x\u2080,\n  calc (f + g) (-x\u2080) = f (-x\u2080) + g (-x\u2080) : by On calcule\n  ... = f x\u2080 + g (-x\u2080) : by On r\u00e9\u00e9crit via hf \n  ... = f x\u2080 + g x\u2080 : by On r\u00e9\u00e9crit via hg \n  ... = (f + g) x\u2080 : by On calcule\nend\n\n/-\nDans la d\u00e9monstration pr\u00e9c\u00e9dente, la ligne commen\u00e7ant par \"Montrons que\"\nest purement psychologique, Lean n'en a pas besoin du tout.\nDe plus on n'est pas oblig\u00e9 d'expliciter la d\u00e9finition de \"paire\"\ndans la premi\u00e8re ligne. On peut donc aussi utiliser la version ci-dessous.\n\nDe plus Lean n'a pas vraiment besoin qu'on lui dise\n\u00e0 quel r\u00e9el appliquer les hypoth\u00e8ses de parit\u00e9, il\nlui suffit de chercher dans le but en cours donc les lignes\nde sp\u00e9cialisation `On applique` sont inutiles.\n-/\n\n-- Si f et g sont paires alors leur somme l'est aussi, avec une d\u00e9monstration moins bavarde.\nexample (f g : \u211d \u2192 \u211d) : paire f \u2192 paire g \u2192  paire (f + g) :=\nbegin\n  Supposons (hf : paire f) (hg : paire g),\n  Soit x,\n  calc (f + g) (-x) = f (-x) + g (-x) : by On calcule\n  ... = f x + g (-x) : by On r\u00e9\u00e9crit via hf\n  ... = f x + g x : by On r\u00e9\u00e9crit via hg\n  ... = (f + g) x : by On calcule,\nend\n\nexample (f g : \u211d \u2192 \u211d) : paire f \u2192 paire (g \u2218 f) :=\nbegin\n  sorry\nend\n\nexample (f g : \u211d \u2192 \u211d) : impaire f \u2192 impaire g \u2192  impaire (g \u2218 f) :=\nbegin\n  sorry\nend\n\n/-\nVoyons maintenant comment manipuler des pr\u00e9dicats plus complexes. \nOn se donne une fonction `f : \u211d \u2192 \u211d` et on forme le pr\u00e9dicat\nportant sur deux nombres `x\u2081\u0300` et `x\u2082` auxquels on associe\nl'\u00e9nonc\u00e9 `x\u2081 \u2264 x\u2082 \u2192 f x\u2081 \u2264 f x\u2082` (Si x\u2081 \u2264 x\u2082 alors f(x\u2081) \u2264 f(x\u2082)).\n\nOn peut embo\u00eeter deux quantificateurs universels pour obtenir la d\u00e9finition\nde fonction croissante.\n-/\n\ndef croissante (f : \u211d \u2192 \u211d) := \u2200 x\u2081, (\u2200 x\u2082, x\u2081 \u2264 x\u2082 \u2192 f x\u2081 \u2264 f x\u2082)\n\n/-\nUn tel embo\u00eetement est un peu lourd \u00e0 lire, on peut l'abr\u00e9ger comme\ndans la d\u00e9finition suivante.\n-/\n\ndef decroissante (f : \u211d \u2192 \u211d) := \u2200 x\u2081 x\u2082, x\u2081 \u2264 x\u2082 \u2192 f x\u2081 \u2265 f x\u2082\n\n/-\nDans l'exemple suivant, la commande \n`On conclut par (hf : croissante f) appliqu\u00e9 \u00e0 [x\u2081, x\u2082, h],`\nsp\u00e9cialise en vol l'\u00e9nonc\u00e9 `hf` en lui fournissant deux nombres r\u00e9els\net une hypoth\u00e8se d'in\u00e9galit\u00e9.\nLe rappel du contenu de `hf` n'est l\u00e0 que pour faciliter la lecture, on\naurait pu \u00e9crire\n`On conclut par hf appliqu\u00e9 \u00e0 [x\u2081, x\u2082, h],`\n-/\n\nexample (f g : \u211d \u2192 \u211d) (hf : croissante f) (hg : croissante g) : croissante (g \u2218 f) :=\nbegin\n  Soit x\u2081 x\u2082, \n  Supposons h : x\u2081 \u2264 x\u2082,\n  Montrons que g (f x\u2081) \u2264 g (f x\u2082), -- Cette ligne est facultative mais facilite la lecture\n  Fait F1 : f x\u2081 \u2264 f x\u2082,\n    On conclut par (hf : croissante f) appliqu\u00e9 \u00e0 [x\u2081, x\u2082, h],\n  On conclut par (hg : croissante g) appliqu\u00e9 \u00e0 [f x\u2081, f x\u2082, F1],\nend\n\n/-\nOn peut aussi utiliser la commande `Par ... appliqu\u00e9 \u00e0 ... on obtient`\npour sp\u00e9cialiser un \u00e9nonc\u00e9 quantifi\u00e9 universellement, comme dans \nla variante suivante.\n-/\n\nexample (f g : \u211d \u2192 \u211d) (hf : croissante f) (hg : croissante g) : croissante (g \u2218 f) :=\nbegin\n  Soit x\u2081 x\u2082, \n  Supposons h : x\u2081 \u2264 x\u2082,\n  Montrons que g (f x\u2081) \u2264 g (f x\u2082),\n  Par hf appliqu\u00e9 \u00e0 [x\u2081, x\u2082, h] on obtient hf' : f x\u2081 \u2264 f x\u2082,\n  On conclut par hg appliqu\u00e9 \u00e0 [f x\u2081, f x\u2082, hf'],\nend\n\n/-\nDans le morceau de commande `on obtient hf' : f x\u2081 \u2264 f x\u2082`,\nla partie `: f x\u2081 \u2264 f x\u2082` est facultative, car Lean sait bien\nce qu'on obtient en appliquant `hf`, mais elle aide \u00e0 passer \u00e0\nla r\u00e9daction sur papier. On peut donc commencer par ne pas \nl'utiliser lors de la recherche de d\u00e9monstration puis la rajouter\navant de passer sur papier.\n\nVoici encore une autre variante, avec `On applique` : \n-/\nexample (f g : \u211d \u2192 \u211d) (hf : croissante f) (hg : croissante g) : croissante (g \u2218 f) :=\nbegin\n  Soit x\u2081 x\u2082, \n  Supposons h : x\u2081 \u2264 x\u2082,\n  Montrons que g (f x\u2081) \u2264 g (f x\u2082),\n  On applique hf \u00e0 [x\u2081, x\u2082, h],\n  On conclut par hg appliqu\u00e9 \u00e0 [f x\u2081, f x\u2082, hf],\nend\n\n/- Le m\u00eame en raisonnant vers l'arri\u00e8re. On remarquera que Lean se d\u00e9brouille pour comprendre \u00e0\nquels nombres r\u00e9els appliquer les hypoth\u00e8ses de croissance. -/\nexample (f g : \u211d \u2192 \u211d) (hf : croissante f) (hg : croissante g) : croissante (g \u2218 f) :=\nbegin\n  Soit x\u2081 x\u2082, \n  Supposons h : x\u2081 \u2264 x\u2082,\n  Montrons que (g \u2218 f) x\u2081 \u2264 (g \u2218 f) x\u2082,\n  Par hg il suffit de montrer que f x\u2081 \u2264 f x\u2082,\n  Par hf il suffit de montrer que x\u2081 \u2264 x\u2082,\n  On conclut par h,\nend\n\nexample (f g : \u211d \u2192 \u211d) (hf : croissante f) (hg : decroissante g) : decroissante (g \u2218 f) :=\nbegin\n  sorry\nend\n\n/-\nLe symbole `\u2228` (qui n'est pas un v) d\u00e9signe le connecteur logique \u00ab ou \u00bb.\nPour *utiliser* une hypoth\u00e8se de la forme\n`hyp : P \u2228 Q`\nlors de la d\u00e9monstration d'un but `R`, on tape\n`On discute en utilisant hyp,`\n(ou bien `On discute en utilisant (hyp : P \u2228 Q),` pour plus de clart\u00e9)\nqui cr\u00e9e deux branches dans la d\u00e9monstration :\nune branche o\u00f9 il faut d\u00e9montrer `P \u2192 R`\net l'autre o\u00f9 il faut d\u00e9montrer `Q \u2192 R`.\n\nPour *d\u00e9montrer* un but de la forme `P \u2228 Q`, on utilise \n`Montrons que P` et on d\u00e9montre P ou `Montrons que Q` et\non d\u00e9montre Q (il faut donc faire un choix strat\u00e9gique).\n\nDans l'exemple suivant, on utilise aussi\nla commande `On combine` suivie d'une liste d'hypoth\u00e8ses,\nqui cherche \u00e0 d\u00e9montrer une \u00e9galit\u00e9 ou une in\u00e9galit\u00e9 \npar combinaison lin\u00e9aire de ces hypoth\u00e8ses. \nSi la liste ne consiste qu'en une seule hypoth\u00e8se,\nil est plus naturel d'utiliser `On conclut par`.\nCette commande permet aussi de d\u00e9duire `a \u2264 b` de `a < b`\nou d'autres trivialit\u00e9s de ce genre.\n\nEnfin on utilise le lemme\n`mul_eq_zero : a*b = 0 \u2194 a = 0 \u2228 b = 0`\nqui servira aussi dans l'exercice suivant.\n-/\n\nexample (a b : \u211d) : a = a*b \u2192 a = 0 \u2228 b = 1 :=\nbegin\n  Supposons hyp : a=a*b,\n  Fait H : a*(1 - b) = 0,\n    calc a*(1 - b) = a - a*b : by On calcule\n               ... = 0       : by On conclut par hyp,\n  On r\u00e9\u00e9crit via mul_eq_zero dans H qui devient a = 0 \u2228 1 - b = 0,\n  On discute en utilisant (H : a = 0 \u2228 1 - b = 0),\n    Supposons H : a = 0,\n    Montrons que a = 0,\n    On conclut par H,\n  Supposons H : 1 - b = 0,\n  Montrons que b = 1,\n  On conclut par H,\nend\n\nexample (x y : \u211d) : x^2 = y^2 \u2192 x = y \u2228 x = -y :=\nbegin\n  sorry\nend\n\n/-\nOn va maintenant combiner le quantificateur universel\net la disjonction dans deux exercices plus int\u00e9ressants.\n\nDans l'exercice suivant, on pourra utiliser le lemme\n`eq_or_lt_of_le : x \u2264 y \u2192 x = y \u2228 x < y`\n-/\nexample (f : \u211d \u2192 \u211d) : croissante f \u2194 \u2200 x y, x < y \u2192 f x \u2264 f y :=\nbegin\n  sorry\nend\n\n/-\nDans l'exercice suivant, on pourra utiliser le lemme\n`le_total x y : x \u2264 y \u2228 y \u2264 x`\n\nCet exercice n\u00e9cessite de r\u00e9fl\u00e9chir un peu plus que les\npr\u00e9c\u00e9dents, l'\u00e9nonc\u00e9 n'\u00e9tant pas compl\u00e8tement \u00e9vident.\n-/\nexample (f : \u211d \u2192 \u211d) (h : croissante f) (h' : \u2200 x, f (f x) = x) : \u2200 x, f x = x :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "PatrickMassot", "repo": "MDD154", "sha": "00defe82a4b6b7992ed522a92f62abd685e8c943", "save_path": "github-repos/lean/PatrickMassot-MDD154", "path": "github-repos/lean/PatrickMassot-MDD154/MDD154-00defe82a4b6b7992ed522a92f62abd685e8c943/src/03_pour_tout_ou.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117983401363, "lm_q2_score": 0.8652240947405565, "lm_q1q2_score": 0.7152909673301819}}
{"text": "import tactic\nimport data.set.finite\n\nopen set\n\n-- Definition d'un espace topologique :\n@[ext]\nclass topological_space (X : Type) :=\n  (is_open  : set X \u2192 Prop)\n  (univ_mem : is_open univ)\n  (union    : \u2200 (B : set (set X)) (h : \u2200 b \u2208 B, is_open b), is_open (\u22c3\u2080 B))\n  (inter    : \u2200 {A B : set X} (hA : is_open A) (hB : is_open B), is_open (A \u2229 B))\n\nnamespace topological_space\n\n-- Ferm\u00e9s :\ndef is_closed {X : Type} [topological_space X] : set X \u2192 Prop := \u03bb F, is_open (compl F)\n\n-- Preuve que l'ensemble vide est un ouvert \u00e0 partir des autres axiomes :\nlemma empty_mem {X : Type} [topological_space X] : is_open (\u2205 : set X) :=\nbegin\n  have : (\u2205 : set X) = \u22c3\u2080 \u2205, simp, rw this,\n  apply union,\n  intros b hb, exfalso, exact hb,\nend\n\n-- Toute intersection finie d'ouverts est un ouvert :\nlemma finite_inter {X : Type} [topological_space X] :\n\u2200 (B : set (set X)) (hB : finite B) (h : \u2200 b \u2208 B, is_open b), is_open (\u22c2\u2080 B) :=\nbegin\n  intros b hB,\n  apply finite.induction_on hB,\n  simp, exact univ_mem,\n  intros a s ha hs h1 h2,\n  have clef : \u22c2\u2080insert a s = \u22c2\u2080s \u2229 a,\n  { apply le_antisymm,\n    { intros x hx,\n      split,\n      intros b hb,\n      apply hx, right, exact hb,\n      apply hx, left, refl, },\n    { intros x hx,\n      intros b hb,\n      cases hb with hb1 hb2,\n      rw hb1,\n      exact hx.2,\n      exact hx.1 b hb2, }, },\n  rw clef,\n  apply inter,\n  { apply h1,\n    intros b hb,\n    apply h2 b,\n    right,\n    exact hb, },\n  { apply h2 a,\n    left,\n    refl, },\nend\n\n-- Topologie discrete :\ndef discrete (X : Type) : topological_space X :=\n{ is_open  := \u03bb U, true,\n  univ_mem := trivial,\n  union    := begin intros B h, trivial, end,\n  inter    := begin intros A hA B hB, trivial, end }\n\n-- Definition d'un espace discret :\nclass discrete_space (X : Type) [topological_space X] := \n(all_open : \u2200 U : set X, is_open U)\n\n-- Topologie engendr\u00e9e par un ensemble de parties :\ninductive generated_open (X : Type) (g : set (set X)) : set X \u2192 Prop\n| generator : \u2200 A \u2208 g, generated_open A\n| inter     : \u2200 A B, generated_open A \u2192 generated_open B \u2192 generated_open (A \u2229 B)\n| union     : \u2200 (B : set (set X)), (\u2200 b \u2208 B, generated_open b) \u2192 generated_open (\u22c3\u2080 B)\n| univ      : generated_open univ\n\ndef generate_from (X : Type) (g : set (set X)) : topological_space X :=\n{ is_open   := generated_open X g,\n  univ_mem  := generated_open.univ,\n  inter     := generated_open.inter,\n  union     := generated_open.union }\n\n-- Topologie grossi\u00e8re :\ndef indiscrete (X : Type) : topological_space X :=\n  generate_from X {\u2205, univ}\n\nend topological_space\n\nopen topological_space\n\n-- Topologie produit :\ninstance prod.topological_space (X Y : Type) [topological_space X]\n  [topological_space Y] : topological_space (X \u00d7 Y) :=\ntopological_space.generate_from (X \u00d7 Y) {U | \u2203 (Ux : set X) (Uy : set Y)\n  (hx : is_open Ux) (hy : is_open Uy), U = set.prod Ux Uy}\n\n-- Les ouverts pour la topologie produit sont les r\u00e9unions d'ouverts \u00e9l\u00e9mentaires :\nlemma is_open_prod_iff {X Y : Type} [topological_space X] [topological_space Y]\n  {s : set (X \u00d7 Y)} :\nis_open s \u2194 (\u2200a b, (a, b) \u2208 s \u2192 \u2203u v, is_open u \u2227 is_open v \u2227\n                                  a \u2208 u \u2227 b \u2208 v \u2227 set.prod u v \u2286 s) :=\nbegin\n  split,\n  { intros hyp a b hab,\n    induction hyp with U hU A B hA1 hB1 hA2 hB2 C hC1 hC2,\n    { rcases hU with \u27e8 Ux, Uy, hx, hy, hs \u27e9,\n      rw hs at hab,\n      use [Ux, Uy, hx, hy, hab.1, hab.2],\n      rw hs, },\n    { rcases hA2 hab.1 with \u27e8u1, v1, \u27e8h1a, h1b, h1c, h1d, h1e\u27e9\u27e9,\n      rcases hB2 hab.2 with \u27e8u2, v2, \u27e8h2a, h2b, h2c, h2d, h2e\u27e9\u27e9,\n      refine \u27e8u1 \u2229 u2, v1 \u2229 v2, inter h1a h2a, inter h1b h2b, \u27e8h1c, h2c\u27e9,\n      \u27e8h1d, h2d\u27e9,_\u27e9,\n      intros uv huv, split,\n      apply h1e, split, exact huv.1.1, exact huv.2.1,\n      apply h2e, split, exact huv.1.2, exact huv.2.2, },\n    { rcases hab with \u27e8c, hcC, habc \u27e9,\n      rcases hC2 c hcC habc with \u27e8u, v, \u27e8ha, hb, hc, hd, he\u27e9\u27e9,\n      use [u, v, ha, hb, hc, hd],\n      intros uv huv, use c, split, exact hcC, exact he huv, },\n    { use [univ, univ],\n      simp, split; exact univ_mem, }, },\n  { intro hyp,\n    choose f1 f2 hfa hfb hfc hfd hfe using hyp,\n    have clef : s = \u22c3\u2080 {(f1 a b hab).prod (f2 a b hab) | (a : X) (b : Y) (hab : (a, b) \u2208 s)},\n    { apply le_antisymm,\n      { rintros \u27e8a, b\u27e9 hab,\n        use ((f1 a b hab).prod (f2 a b hab)),\n        use [a, b, hab, hfc a b hab, hfd a b hab], },\n      { rintros uv \u27e8 UV, \u27e8 \u27e8a, b, hab, h\u27e9, huv \u27e9\u27e9,\n        rw \u2190 h at huv,\n        exact (hfe a b hab) huv }, },\n    rw clef,\n    apply union,\n    rintros UV \u27e8a, b, hab, h\u27e9,\n    rw \u2190 h,\n    apply generated_open.generator,\n    use [f1 a b hab, f2 a b hab, hfa a b hab, hfb a b hab], },\nend\n\nnamespace topological_space\n\n-- Definition d'une topologie \u00e0 partir de ses ferm\u00e9s :\ndef mk_closed_sets\n  (X : Type)\n  (\u03c3 : set (set X))\n  (empty_mem : \u2205 \u2208 \u03c3)\n  (univ_mem : univ \u2208 \u03c3)\n  (inter : \u2200 B \u2286 \u03c3, \u22c2\u2080 B \u2208 \u03c3)\n  (union : \u2200 (A \u2208 \u03c3) (B \u2208 \u03c3), A \u222a B \u2208 \u03c3) :\ntopological_space X := {\n  is_open := \u03bb U, U \u2208 compl '' \u03c3,\n  univ_mem :=\n  begin\n    apply (mem_compl_image _ _).2,\n    rw compl_univ,\n    exact empty_mem\n  end,\n  union :=\n  begin\n    intros B hB,\n    apply (mem_compl_image _ _).2,\n    rw compl_sUnion,\n    apply inter,\n    intros cb hcb,\n    rw \u2190 compl_compl cb,\n    exact (mem_compl_image _ _).1 (hB (compl cb) ((mem_compl_image _ _).1 hcb)),\n  end,\n  inter :=\n  begin\n    intros A B hA hB,\n    apply (mem_compl_image _ _).2,\n    rw compl_inter,\n    exact union (compl A) ((mem_compl_image _ _).1 hA) (compl B) ((mem_compl_image _ _).1 hB),\n  end,\n  }\n\nend topological_space", "meta": {"author": "amesnard0", "repo": "lean-topology", "sha": "e8f6a720c435cb59d098579a26f6eb70ea05f91a", "save_path": "github-repos/lean/amesnard0-lean-topology", "path": "github-repos/lean/amesnard0-lean-topology/lean-topology-e8f6a720c435cb59d098579a26f6eb70ea05f91a/src/topological_spaces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7152909517333987}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Eric Rodriguez\n-/\n\nimport algebra.group_power.lemmas\nimport algebra.order.field.basic\nimport data.nat.choose.basic\n\n/-!\n# Inequalities for binomial coefficients\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves exponential bounds on binomial coefficients. We might want to add here the\nbounds `n^r/r^r \u2264 n.choose r \u2264 e^r n^r/r^r` in the future.\n\n## Main declarations\n\n* `nat.choose_le_pow`: `n.choose r \u2264 n^r / r!`\n* `nat.pow_le_choose`: `(n + 1 - r)^r / r! \u2264 n.choose r`. Beware of the fishy \u2115-subtraction.\n-/\n\nopen_locale nat\n\nvariables {\u03b1 : Type*} [linear_ordered_semifield \u03b1]\n\nnamespace nat\n\nlemma choose_le_pow (r n : \u2115) : (n.choose r : \u03b1) \u2264 n^r / r! :=\nbegin\n  rw le_div_iff',\n  { norm_cast,\n    rw \u2190nat.desc_factorial_eq_factorial_mul_choose,\n    exact n.desc_factorial_le_pow r },\n  exact_mod_cast r.factorial_pos,\nend\n\n-- horrific casting is due to \u2115-subtraction\nlemma pow_le_choose (r n : \u2115) : ((n + 1 - r : \u2115)^r : \u03b1) / r! \u2264 n.choose r :=\nbegin\n  rw div_le_iff',\n  { norm_cast,\n    rw [\u2190nat.desc_factorial_eq_factorial_mul_choose],\n    exact n.pow_sub_le_desc_factorial r },\n  exact_mod_cast r.factorial_pos,\nend\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/choose/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7152909509124195}}
{"text": "\n\nabbrev N := Nat\n\ndef f : N \u2192 Nat\n| 0   => 1\n| n+1 => n\n\ntheorem ex1 : f 0 = 1 :=\nrfl\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/def3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7152820974772306}}
{"text": "theorem le_trans (a b c : mynat) (hab : a \u2264 b) (hbc : b \u2264 c) : a \u2264 c :=\nbegin\ncases hab with s hs,\ncases hbc with t ht,\nuse (s + t),\nrwa [ht, hs, add_assoc],\nend\n", "meta": {"author": "chanha-park", "repo": "naturalNumberGame", "sha": "4e0d7100ce4575e1add92feefa38b1250431b879", "save_path": "github-repos/lean/chanha-park-naturalNumberGame", "path": "github-repos/lean/chanha-park-naturalNumberGame/naturalNumberGame-4e0d7100ce4575e1add92feefa38b1250431b879/Inequality/5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.7152820889324221}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module topology.metric_space.hausdorff_dimension\n! leanprover-community/mathlib commit 57ac39bd365c2f80589a700f9fbb664d3a1a30c2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.Hausdorff\n\n/-!\n# Hausdorff dimension\n\nThe Hausdorff dimension of a set `X` in an (extended) metric space is the unique number\n`dimH s : \u211d\u22650\u221e` such that for any `d : \u211d\u22650` we have\n\n- `\u03bcH[d] s = 0` if `dimH s < d`, and\n- `\u03bcH[d] s = \u221e` if `d < dimH s`.\n\nIn this file we define `dimH s` to be the Hausdorff dimension of `s`, then prove some basic\nproperties of Hausdorff dimension.\n\n## Main definitions\n\n* `measure_theory.dimH`: the Hausdorff dimension of a set. For the Hausdorff dimension of the whole\n  space we use `measure_theory.dimH (set.univ : set X)`.\n\n## Main results\n\n### Basic properties of Hausdorff dimension\n\n* `hausdorff_measure_of_lt_dimH`, `dimH_le_of_hausdorff_measure_ne_top`,\n  `le_dimH_of_hausdorff_measure_eq_top`, `hausdorff_measure_of_dimH_lt`, `measure_zero_of_dimH_lt`,\n  `le_dimH_of_hausdorff_measure_ne_zero`, `dimH_of_hausdorff_measure_ne_zero_ne_top`: various forms\n  of the characteristic property of the Hausdorff dimension;\n* `dimH_union`: the Hausdorff dimension of the union of two sets is the maximum of their Hausdorff\n  dimensions.\n* `dimH_Union`, `dimH_bUnion`, `dimH_sUnion`: the Hausdorff dimension of a countable union of sets\n  is the supremum of their Hausdorff dimensions;\n* `dimH_empty`, `dimH_singleton`, `set.subsingleton.dimH_zero`, `set.countable.dimH_zero` : `dimH s\n  = 0` whenever `s` is countable;\n\n### (Pre)images under (anti)lipschitz and H\u00f6lder continuous maps\n\n* `holder_with.dimH_image_le` etc: if `f : X \u2192 Y` is H\u00f6lder continuous with exponent `r > 0`, then\n  for any `s`, `dimH (f '' s) \u2264 dimH s / r`. We prove versions of this statement for `holder_with`,\n  `holder_on_with`, and locally H\u00f6lder maps, as well as for `set.image` and `set.range`.\n* `lipschitz_with.dimH_image_le` etc: Lipschitz continuous maps do not increase the Hausdorff\n  dimension of sets.\n* for a map that is known to be both Lipschitz and antilipschitz (e.g., for an `isometry` or\n  a `continuous_linear_equiv`) we also prove `dimH (f '' s) = dimH s`.\n\n### Hausdorff measure in `\u211d\u207f`\n\n* `real.dimH_of_nonempty_interior`: if `s` is a set in a finite dimensional real vector space `E`\n  with nonempty interior, then the Hausdorff dimension of `s` is equal to the dimension of `E`.\n* `dense_compl_of_dimH_lt_finrank`: if `s` is a set in a finite dimensional real vector space `E`\n  with Hausdorff dimension strictly less than the dimension of `E`, the `s` has a dense complement.\n* `cont_diff.dense_compl_range_of_finrank_lt_finrank`: the complement to the range of a `C\u00b9`\n  smooth map is dense provided that the dimension of the domain is strictly less than the dimension\n  of the codomain.\n\n## Notations\n\nWe use the following notation localized in `measure_theory`. It is defined in\n`measure_theory.measure.hausdorff`.\n\n- `\u03bcH[d]` : `measure_theory.measure.hausdorff_measure d`\n\n## Implementation notes\n\n* The definition of `dimH` explicitly uses `borel X` as a measurable space structure. This way we\n  can formulate lemmas about Hausdorff dimension without assuming that the environment has a\n  `[measurable_space X]` instance that is equal but possibly not defeq to `borel X`.\n\n  Lemma `dimH_def` unfolds this definition using whatever `[measurable_space X]` instance we have in\n  the environment (as long as it is equal to `borel X`).\n\n* The definition `dimH` is irreducible; use API lemmas or `dimH_def` instead.\n\n## Tags\n\nHausdorff measure, Hausdorff dimension, dimension\n-/\n\n\nopen MeasureTheory ENNReal NNReal Topology\n\nopen MeasureTheory MeasureTheory.Measure Set TopologicalSpace FiniteDimensional Filter\n\nvariable {\u03b9 X Y : Type _} [EMetricSpace X] [EMetricSpace Y]\n\n/-- Hausdorff dimension of a set in an (e)metric space. -/\nnoncomputable irreducible_def dimH (s : Set X) : \u211d\u22650\u221e :=\n  by\n  borelize X\n  exact \u2a06 (d : \u211d\u22650) (hd : @hausdorff_measure X _ _ \u27e8rfl\u27e9 d s = \u221e), d\n#align dimH dimH\n\n/-!\n### Basic properties\n-/\n\n\nsection Measurable\n\nvariable [MeasurableSpace X] [BorelSpace X]\n\n/-- Unfold the definition of `dimH` using `[measurable_space X] [borel_space X]` from the\nenvironment. -/\ntheorem dimH_def (s : Set X) : dimH s = \u2a06 (d : \u211d\u22650) (hd : \u03bcH[d] s = \u221e), d :=\n  by\n  borelize X\n  rw [dimH]\n#align dimH_def dimH_def\n\ntheorem hausdorffMeasure_of_lt_dimH {s : Set X} {d : \u211d\u22650} (h : \u2191d < dimH s) : \u03bcH[d] s = \u221e :=\n  by\n  simp only [dimH_def, lt_sup\u1d62_iff] at h\n  rcases h with \u27e8d', hsd', hdd'\u27e9\n  rw [ENNReal.coe_lt_coe, \u2190 NNReal.coe_lt_coe] at hdd'\n  exact top_unique (hsd' \u25b8 hausdorff_measure_mono hdd'.le _)\n#align hausdorff_measure_of_lt_dimH hausdorffMeasure_of_lt_dimH\n\ntheorem dimH_le {s : Set X} {d : \u211d\u22650\u221e} (H : \u2200 d' : \u211d\u22650, \u03bcH[d'] s = \u221e \u2192 \u2191d' \u2264 d) : dimH s \u2264 d :=\n  (dimH_def s).trans_le <| sup\u1d62\u2082_le H\n#align dimH_le dimH_le\n\ntheorem dimH_le_of_hausdorffMeasure_ne_top {s : Set X} {d : \u211d\u22650} (h : \u03bcH[d] s \u2260 \u221e) : dimH s \u2264 d :=\n  le_of_not_lt <| mt hausdorffMeasure_of_lt_dimH h\n#align dimH_le_of_hausdorff_measure_ne_top dimH_le_of_hausdorffMeasure_ne_top\n\ntheorem le_dimH_of_hausdorffMeasure_eq_top {s : Set X} {d : \u211d\u22650} (h : \u03bcH[d] s = \u221e) : \u2191d \u2264 dimH s :=\n  by\n  rw [dimH_def]\n  exact le_sup\u1d62\u2082 d h\n#align le_dimH_of_hausdorff_measure_eq_top le_dimH_of_hausdorffMeasure_eq_top\n\ntheorem hausdorffMeasure_of_dimH_lt {s : Set X} {d : \u211d\u22650} (h : dimH s < d) : \u03bcH[d] s = 0 :=\n  by\n  rw [dimH_def] at h\n  rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with \u27e8d', hsd', hd'd\u27e9\n  rw [ENNReal.coe_lt_coe, \u2190 NNReal.coe_lt_coe] at hd'd\n  exact (hausdorff_measure_zero_or_top hd'd s).resolve_right fun h => hsd'.not_le <| le_sup\u1d62\u2082 d' h\n#align hausdorff_measure_of_dimH_lt hausdorffMeasure_of_dimH_lt\n\ntheorem measure_zero_of_dimH_lt {\u03bc : Measure X} {d : \u211d\u22650} (h : \u03bc \u226a \u03bcH[d]) {s : Set X}\n    (hd : dimH s < d) : \u03bc s = 0 :=\n  h <| hausdorffMeasure_of_dimH_lt hd\n#align measure_zero_of_dimH_lt measure_zero_of_dimH_lt\n\ntheorem le_dimH_of_hausdorffMeasure_ne_zero {s : Set X} {d : \u211d\u22650} (h : \u03bcH[d] s \u2260 0) : \u2191d \u2264 dimH s :=\n  le_of_not_lt <| mt hausdorffMeasure_of_dimH_lt h\n#align le_dimH_of_hausdorff_measure_ne_zero le_dimH_of_hausdorffMeasure_ne_zero\n\ntheorem dimH_of_hausdorffMeasure_ne_zero_ne_top {d : \u211d\u22650} {s : Set X} (h : \u03bcH[d] s \u2260 0)\n    (h' : \u03bcH[d] s \u2260 \u221e) : dimH s = d :=\n  le_antisymm (dimH_le_of_hausdorffMeasure_ne_top h') (le_dimH_of_hausdorffMeasure_ne_zero h)\n#align dimH_of_hausdorff_measure_ne_zero_ne_top dimH_of_hausdorffMeasure_ne_zero_ne_top\n\nend Measurable\n\n@[mono]\ntheorem dimH_mono {s t : Set X} (h : s \u2286 t) : dimH s \u2264 dimH t :=\n  by\n  borelize X\n  exact dimH_le fun d hd => le_dimH_of_hausdorffMeasure_eq_top <| top_unique <| hd \u25b8 measure_mono h\n#align dimH_mono dimH_mono\n\ntheorem dimH_subsingleton {s : Set X} (h : s.Subsingleton) : dimH s = 0 :=\n  by\n  borelize X\n  apply le_antisymm _ (zero_le _)\n  refine' dimH_le_of_hausdorffMeasure_ne_top _\n  exact ((hausdorff_measure_le_one_of_subsingleton h le_rfl).trans_lt ENNReal.one_lt_top).Ne\n#align dimH_subsingleton dimH_subsingleton\n\nalias dimH_subsingleton \u2190 Set.Subsingleton.dimH_zero\n#align set.subsingleton.dimH_zero Set.Subsingleton.dimH_zero\n\n@[simp]\ntheorem dimH_empty : dimH (\u2205 : Set X) = 0 :=\n  subsingleton_empty.dimH_zero\n#align dimH_empty dimH_empty\n\n@[simp]\ntheorem dimH_singleton (x : X) : dimH ({x} : Set X) = 0 :=\n  subsingleton_singleton.dimH_zero\n#align dimH_singleton dimH_singleton\n\n@[simp]\ntheorem dimH_union\u1d62 [Encodable \u03b9] (s : \u03b9 \u2192 Set X) : dimH (\u22c3 i, s i) = \u2a06 i, dimH (s i) :=\n  by\n  borelize X\n  refine' le_antisymm (dimH_le fun d hd => _) (sup\u1d62_le fun i => dimH_mono <| subset_Union _ _)\n  contrapose! hd\n  have : \u2200 i, \u03bcH[d] (s i) = 0 := fun i =>\n    hausdorffMeasure_of_dimH_lt ((le_sup\u1d62 (fun i => dimH (s i)) i).trans_lt hd)\n  rw [measure_Union_null this]\n  exact ENNReal.zero_ne_top\n#align dimH_Union dimH_union\u1d62\n\n@[simp]\ntheorem dimH_bUnion {s : Set \u03b9} (hs : s.Countable) (t : \u03b9 \u2192 Set X) :\n    dimH (\u22c3 i \u2208 s, t i) = \u2a06 i \u2208 s, dimH (t i) :=\n  by\n  haveI := hs.to_encodable\n  rw [bUnion_eq_Union, dimH_union\u1d62, \u2190 sup\u1d62_subtype'']\n#align dimH_bUnion dimH_bUnion\n\n@[simp]\ntheorem dimH_union\u209b {S : Set (Set X)} (hS : S.Countable) : dimH (\u22c3\u2080 S) = \u2a06 s \u2208 S, dimH s := by\n  rw [sUnion_eq_bUnion, dimH_bUnion hS]\n#align dimH_sUnion dimH_union\u209b\n\n@[simp]\ntheorem dimH_union (s t : Set X) : dimH (s \u222a t) = max (dimH s) (dimH t) := by\n  rw [union_eq_Union, dimH_union\u1d62, sup\u1d62_bool_eq, cond, cond, ENNReal.sup_eq_max]\n#align dimH_union dimH_union\n\ntheorem dimH_countable {s : Set X} (hs : s.Countable) : dimH s = 0 :=\n  bunion\u1d62_of_singleton s \u25b8 by simp only [dimH_bUnion hs, dimH_singleton, ENNReal.sup\u1d62_zero_eq_zero]\n#align dimH_countable dimH_countable\n\nalias dimH_countable \u2190 Set.Countable.dimH_zero\n#align set.countable.dimH_zero Set.Countable.dimH_zero\n\ntheorem dimH_finite {s : Set X} (hs : s.Finite) : dimH s = 0 :=\n  hs.Countable.dimH_zero\n#align dimH_finite dimH_finite\n\nalias dimH_finite \u2190 Set.Finite.dimH_zero\n#align set.finite.dimH_zero Set.Finite.dimH_zero\n\n@[simp]\ntheorem dimH_coe_finset (s : Finset X) : dimH (s : Set X) = 0 :=\n  s.finite_toSet.dimH_zero\n#align dimH_coe_finset dimH_coe_finset\n\nalias dimH_coe_finset \u2190 Finset.dimH_zero\n#align finset.dimH_zero Finset.dimH_zero\n\n/-!\n### Hausdorff dimension as the supremum of local Hausdorff dimensions\n-/\n\n\nsection\n\nvariable [SecondCountableTopology X]\n\n/-- If `r` is less than the Hausdorff dimension of a set `s` in an (extended) metric space with\nsecond countable topology, then there exists a point `x \u2208 s` such that every neighborhood\n`t` of `x` within `s` has Hausdorff dimension greater than `r`. -/\ntheorem exists_mem_nhdsWithin_lt_dimH_of_lt_dimH {s : Set X} {r : \u211d\u22650\u221e} (h : r < dimH s) :\n    \u2203 x \u2208 s, \u2200 t \u2208 \ud835\udcdd[s] x, r < dimH t := by\n  contrapose! h; choose! t htx htr using h\n  rcases countable_cover_nhds_within htx with \u27e8S, hSs, hSc, hSU\u27e9\n  calc\n    dimH s \u2264 dimH (\u22c3 x \u2208 S, t x) := dimH_mono hSU\n    _ = \u2a06 x \u2208 S, dimH (t x) := (dimH_bUnion hSc _)\n    _ \u2264 r := sup\u1d62\u2082_le fun x hx => htr x <| hSs hx\n    \n#align exists_mem_nhds_within_lt_dimH_of_lt_dimH exists_mem_nhdsWithin_lt_dimH_of_lt_dimH\n\n/-- In an (extended) metric space with second countable topology, the Hausdorff dimension\nof a set `s` is the supremum over `x \u2208 s` of the limit superiors of `dimH t` along\n`(\ud835\udcdd[s] x).small_sets`. -/\ntheorem bsupr_limsup_dimH (s : Set X) : (\u2a06 x \u2208 s, limsup dimH (\ud835\udcdd[s] x).smallSets) = dimH s :=\n  by\n  refine' le_antisymm (sup\u1d62\u2082_le fun x hx => _) _\n  \u00b7 refine' Limsup_le_of_le (by infer_param) (eventually_map.2 _)\n    exact eventually_small_sets.2 \u27e8s, self_mem_nhdsWithin, fun t => dimH_mono\u27e9\n  \u00b7 refine' le_of_forall_ge_of_dense fun r hr => _\n    rcases exists_mem_nhdsWithin_lt_dimH_of_lt_dimH hr with \u27e8x, hxs, hxr\u27e9\n    refine' le_sup\u1d62\u2082_of_le x hxs _\n    rw [limsup_eq]\n    refine' le_inf\u209b fun b hb => _\n    rcases eventually_small_sets.1 hb with \u27e8t, htx, ht\u27e9\n    exact (hxr t htx).le.trans (ht t subset.rfl)\n#align bsupr_limsup_dimH bsupr_limsup_dimH\n\n/-- In an (extended) metric space with second countable topology, the Hausdorff dimension\nof a set `s` is the supremum over all `x` of the limit superiors of `dimH t` along\n`(\ud835\udcdd[s] x).small_sets`. -/\ntheorem sup\u1d62_limsup_dimH (s : Set X) : (\u2a06 x, limsup dimH (\ud835\udcdd[s] x).smallSets) = dimH s :=\n  by\n  refine' le_antisymm (sup\u1d62_le fun x => _) _\n  \u00b7 refine' Limsup_le_of_le (by infer_param) (eventually_map.2 _)\n    exact eventually_small_sets.2 \u27e8s, self_mem_nhdsWithin, fun t => dimH_mono\u27e9\n  \u00b7 rw [\u2190 bsupr_limsup_dimH]\n    exact sup\u1d62\u2082_le_sup\u1d62 _ _\n#align supr_limsup_dimH sup\u1d62_limsup_dimH\n\nend\n\n/-!\n### Hausdorff dimension and H\u00f6lder continuity\n-/\n\n\nvariable {C K r : \u211d\u22650} {f : X \u2192 Y} {s t : Set X}\n\n/-- If `f` is a H\u00f6lder continuous map with exponent `r > 0`, then `dimH (f '' s) \u2264 dimH s / r`. -/\ntheorem HolderOnWith.dimH_image_le (h : HolderOnWith C r f s) (hr : 0 < r) :\n    dimH (f '' s) \u2264 dimH s / r := by\n  borelize X Y\n  refine' dimH_le fun d hd => _\n  have := h.hausdorff_measure_image_le hr d.coe_nonneg\n  rw [hd, ENNReal.coe_rpow_of_nonneg _ d.coe_nonneg, top_le_iff] at this\n  have Hrd : \u03bcH[(r * d : \u211d\u22650)] s = \u22a4 := by\n    contrapose this\n    exact ENNReal.mul_ne_top ENNReal.coe_ne_top this\n  rw [ENNReal.le_div_iff_mul_le, mul_comm, \u2190 ENNReal.coe_mul]\n  exacts[le_dimH_of_hausdorffMeasure_eq_top Hrd, Or.inl (mt ENNReal.coe_eq_zero.1 hr.ne'),\n    Or.inl ENNReal.coe_ne_top]\n#align holder_on_with.dimH_image_le HolderOnWith.dimH_image_le\n\nnamespace HolderWith\n\n/-- If `f : X \u2192 Y` is H\u00f6lder continuous with a positive exponent `r`, then the Hausdorff dimension\nof the image of a set `s` is at most `dimH s / r`. -/\ntheorem dimH_image_le (h : HolderWith C r f) (hr : 0 < r) (s : Set X) :\n    dimH (f '' s) \u2264 dimH s / r :=\n  (h.HolderOnWith s).dimH_image_le hr\n#align holder_with.dimH_image_le HolderWith.dimH_image_le\n\n/-- If `f` is a H\u00f6lder continuous map with exponent `r > 0`, then the Hausdorff dimension of its\nrange is at most the Hausdorff dimension of its domain divided by `r`. -/\ntheorem dimH_range_le (h : HolderWith C r f) (hr : 0 < r) :\n    dimH (range f) \u2264 dimH (univ : Set X) / r :=\n  @image_univ _ _ f \u25b8 h.dimH_image_le hr univ\n#align holder_with.dimH_range_le HolderWith.dimH_range_le\n\nend HolderWith\n\n/-- If `s` is a set in a space `X` with second countable topology and `f : X \u2192 Y` is H\u00f6lder\ncontinuous in a neighborhood within `s` of every point `x \u2208 s` with the same positive exponent `r`\nbut possibly different coefficients, then the Hausdorff dimension of the image `f '' s` is at most\nthe Hausdorff dimension of `s` divided by `r`. -/\ntheorem dimH_image_le_of_locally_holder_on [SecondCountableTopology X] {r : \u211d\u22650} {f : X \u2192 Y}\n    (hr : 0 < r) {s : Set X} (hf : \u2200 x \u2208 s, \u2203 C : \u211d\u22650, \u2203 t \u2208 \ud835\udcdd[s] x, HolderOnWith C r f t) :\n    dimH (f '' s) \u2264 dimH s / r := by\n  choose! C t htn hC using hf\n  rcases countable_cover_nhds_within htn with \u27e8u, hus, huc, huU\u27e9\n  replace huU := inter_eq_self_of_subset_left huU; rw [inter_Union\u2082] at huU\n  rw [\u2190 huU, image_Union\u2082, dimH_bUnion huc, dimH_bUnion huc]; simp only [ENNReal.sup\u1d62_div]\n  exact sup\u1d62\u2082_mono fun x hx => ((hC x (hus hx)).mono (inter_subset_right _ _)).dimH_image_le hr\n#align dimH_image_le_of_locally_holder_on dimH_image_le_of_locally_holder_on\n\n/-- If `f : X \u2192 Y` is H\u00f6lder continuous in a neighborhood of every point `x : X` with the same\npositive exponent `r` but possibly different coefficients, then the Hausdorff dimension of the range\nof `f` is at most the Hausdorff dimension of `X` divided by `r`. -/\ntheorem dimH_range_le_of_locally_holder_on [SecondCountableTopology X] {r : \u211d\u22650} {f : X \u2192 Y}\n    (hr : 0 < r) (hf : \u2200 x : X, \u2203 C : \u211d\u22650, \u2203 s \u2208 \ud835\udcdd x, HolderOnWith C r f s) :\n    dimH (range f) \u2264 dimH (univ : Set X) / r :=\n  by\n  rw [\u2190 image_univ]\n  refine' dimH_image_le_of_locally_holder_on hr fun x _ => _\n  simpa only [exists_prop, nhdsWithin_univ] using hf x\n#align dimH_range_le_of_locally_holder_on dimH_range_le_of_locally_holder_on\n\n/-!\n### Hausdorff dimension and Lipschitz continuity\n-/\n\n\n/-- If `f : X \u2192 Y` is Lipschitz continuous on `s`, then `dimH (f '' s) \u2264 dimH s`. -/\ntheorem LipschitzOnWith.dimH_image_le (h : LipschitzOnWith K f s) : dimH (f '' s) \u2264 dimH s := by\n  simpa using h.holder_on_with.dimH_image_le zero_lt_one\n#align lipschitz_on_with.dimH_image_le LipschitzOnWith.dimH_image_le\n\nnamespace LipschitzWith\n\n/-- If `f` is a Lipschitz continuous map, then `dimH (f '' s) \u2264 dimH s`. -/\ntheorem dimH_image_le (h : LipschitzWith K f) (s : Set X) : dimH (f '' s) \u2264 dimH s :=\n  (h.LipschitzOnWith s).dimH_image_le\n#align lipschitz_with.dimH_image_le LipschitzWith.dimH_image_le\n\n/-- If `f` is a Lipschitz continuous map, then the Hausdorff dimension of its range is at most the\nHausdorff dimension of its domain. -/\ntheorem dimH_range_le (h : LipschitzWith K f) : dimH (range f) \u2264 dimH (univ : Set X) :=\n  @image_univ _ _ f \u25b8 h.dimH_image_le univ\n#align lipschitz_with.dimH_range_le LipschitzWith.dimH_range_le\n\nend LipschitzWith\n\n/-- If `s` is a set in an extended metric space `X` with second countable topology and `f : X \u2192 Y`\nis Lipschitz in a neighborhood within `s` of every point `x \u2208 s`, then the Hausdorff dimension of\nthe image `f '' s` is at most the Hausdorff dimension of `s`. -/\ntheorem dimH_image_le_of_locally_lipschitz_on [SecondCountableTopology X] {f : X \u2192 Y} {s : Set X}\n    (hf : \u2200 x \u2208 s, \u2203 C : \u211d\u22650, \u2203 t \u2208 \ud835\udcdd[s] x, LipschitzOnWith C f t) : dimH (f '' s) \u2264 dimH s :=\n  by\n  have : \u2200 x \u2208 s, \u2203 C : \u211d\u22650, \u2203 t \u2208 \ud835\udcdd[s] x, HolderOnWith C 1 f t := by\n    simpa only [holderOnWith_one] using hf\n  simpa only [ENNReal.coe_one, div_one] using dimH_image_le_of_locally_holder_on zero_lt_one this\n#align dimH_image_le_of_locally_lipschitz_on dimH_image_le_of_locally_lipschitz_on\n\n/-- If `f : X \u2192 Y` is Lipschitz in a neighborhood of each point `x : X`, then the Hausdorff\ndimension of `range f` is at most the Hausdorff dimension of `X`. -/\ntheorem dimH_range_le_of_locally_lipschitz_on [SecondCountableTopology X] {f : X \u2192 Y}\n    (hf : \u2200 x : X, \u2203 C : \u211d\u22650, \u2203 s \u2208 \ud835\udcdd x, LipschitzOnWith C f s) :\n    dimH (range f) \u2264 dimH (univ : Set X) :=\n  by\n  rw [\u2190 image_univ]\n  refine' dimH_image_le_of_locally_lipschitz_on fun x _ => _\n  simpa only [exists_prop, nhdsWithin_univ] using hf x\n#align dimH_range_le_of_locally_lipschitz_on dimH_range_le_of_locally_lipschitz_on\n\nnamespace AntilipschitzWith\n\ntheorem dimH_preimage_le (hf : AntilipschitzWith K f) (s : Set Y) : dimH (f \u207b\u00b9' s) \u2264 dimH s :=\n  by\n  borelize X Y\n  refine' dimH_le fun d hd => le_dimH_of_hausdorffMeasure_eq_top _\n  have := hf.hausdorff_measure_preimage_le d.coe_nonneg s\n  rw [hd, top_le_iff] at this\n  contrapose! this\n  exact ENNReal.mul_ne_top (by simp) this\n#align antilipschitz_with.dimH_preimage_le AntilipschitzWith.dimH_preimage_le\n\ntheorem le_dimH_image (hf : AntilipschitzWith K f) (s : Set X) : dimH s \u2264 dimH (f '' s) :=\n  calc\n    dimH s \u2264 dimH (f \u207b\u00b9' (f '' s)) := dimH_mono (subset_preimage_image _ _)\n    _ \u2264 dimH (f '' s) := hf.dimH_preimage_le _\n    \n#align antilipschitz_with.le_dimH_image AntilipschitzWith.le_dimH_image\n\nend AntilipschitzWith\n\n/-!\n### Isometries preserve Hausdorff dimension\n-/\n\n\ntheorem Isometry.dimH_image (hf : Isometry f) (s : Set X) : dimH (f '' s) = dimH s :=\n  le_antisymm (hf.lipschitz.dimH_image_le _) (hf.antilipschitz.le_dimH_image _)\n#align isometry.dimH_image Isometry.dimH_image\n\nnamespace IsometryEquiv\n\n@[simp]\ntheorem dimH_image (e : X \u2243\u1d62 Y) (s : Set X) : dimH (e '' s) = dimH s :=\n  e.Isometry.dimH_image s\n#align isometry_equiv.dimH_image IsometryEquiv.dimH_image\n\n@[simp]\ntheorem dimH_preimage (e : X \u2243\u1d62 Y) (s : Set Y) : dimH (e \u207b\u00b9' s) = dimH s := by\n  rw [\u2190 e.image_symm, e.symm.dimH_image]\n#align isometry_equiv.dimH_preimage IsometryEquiv.dimH_preimage\n\ntheorem dimH_univ (e : X \u2243\u1d62 Y) : dimH (univ : Set X) = dimH (univ : Set Y) := by\n  rw [\u2190 e.dimH_preimage univ, preimage_univ]\n#align isometry_equiv.dimH_univ IsometryEquiv.dimH_univ\n\nend IsometryEquiv\n\nnamespace ContinuousLinearEquiv\n\nvariable {\ud835\udd5c E F : Type _} [NontriviallyNormedField \ud835\udd5c] [NormedAddCommGroup E] [NormedSpace \ud835\udd5c E]\n  [NormedAddCommGroup F] [NormedSpace \ud835\udd5c F]\n\n@[simp]\ntheorem dimH_image (e : E \u2243L[\ud835\udd5c] F) (s : Set E) : dimH (e '' s) = dimH s :=\n  le_antisymm (e.lipschitz.dimH_image_le s) <| by\n    simpa only [e.symm_image_image] using e.symm.lipschitz.dimH_image_le (e '' s)\n#align continuous_linear_equiv.dimH_image ContinuousLinearEquiv.dimH_image\n\n@[simp]\ntheorem dimH_preimage (e : E \u2243L[\ud835\udd5c] F) (s : Set F) : dimH (e \u207b\u00b9' s) = dimH s := by\n  rw [\u2190 e.image_symm_eq_preimage, e.symm.dimH_image]\n#align continuous_linear_equiv.dimH_preimage ContinuousLinearEquiv.dimH_preimage\n\ntheorem dimH_univ (e : E \u2243L[\ud835\udd5c] F) : dimH (univ : Set E) = dimH (univ : Set F) := by\n  rw [\u2190 e.dimH_preimage, preimage_univ]\n#align continuous_linear_equiv.dimH_univ ContinuousLinearEquiv.dimH_univ\n\nend ContinuousLinearEquiv\n\n/-!\n### Hausdorff dimension in a real vector space\n-/\n\n\nnamespace Real\n\nvariable {E : Type _} [Fintype \u03b9] [NormedAddCommGroup E] [NormedSpace \u211d E] [FiniteDimensional \u211d E]\n\ntheorem dimH_ball_pi (x : \u03b9 \u2192 \u211d) {r : \u211d} (hr : 0 < r) : dimH (Metric.ball x r) = Fintype.card \u03b9 :=\n  by\n  cases isEmpty_or_nonempty \u03b9\n  \u00b7 rwa [dimH_subsingleton, eq_comm, Nat.cast_eq_zero, Fintype.card_eq_zero_iff]\n    exact fun x _ y _ => Subsingleton.elim x y\n  \u00b7 rw [\u2190 ENNReal.coe_nat]\n    have : \u03bcH[Fintype.card \u03b9] (Metric.ball x r) = ENNReal.ofReal ((2 * r) ^ Fintype.card \u03b9) := by\n      rw [hausdorff_measure_pi_real, Real.volume_pi_ball _ hr]\n    refine' dimH_of_hausdorffMeasure_ne_zero_ne_top _ _ <;> rw [NNReal.coe_nat_cast, this]\n    \u00b7 simp [pow_pos (mul_pos (zero_lt_two' \u211d) hr)]\n    \u00b7 exact ENNReal.ofReal_ne_top\n#align real.dimH_ball_pi Real.dimH_ball_pi\n\ntheorem dimH_ball_pi_fin {n : \u2115} (x : Fin n \u2192 \u211d) {r : \u211d} (hr : 0 < r) :\n    dimH (Metric.ball x r) = n := by rw [dimH_ball_pi x hr, Fintype.card_fin]\n#align real.dimH_ball_pi_fin Real.dimH_ball_pi_fin\n\ntheorem dimH_univ_pi (\u03b9 : Type _) [Fintype \u03b9] : dimH (univ : Set (\u03b9 \u2192 \u211d)) = Fintype.card \u03b9 := by\n  simp only [\u2190 Metric.union\u1d62_ball_nat_succ (0 : \u03b9 \u2192 \u211d), dimH_union\u1d62,\n    dimH_ball_pi _ (Nat.cast_add_one_pos _), sup\u1d62_const]\n#align real.dimH_univ_pi Real.dimH_univ_pi\n\ntheorem dimH_univ_pi_fin (n : \u2115) : dimH (univ : Set (Fin n \u2192 \u211d)) = n := by\n  rw [dimH_univ_pi, Fintype.card_fin]\n#align real.dimH_univ_pi_fin Real.dimH_univ_pi_fin\n\ntheorem dimH_of_mem_nhds {x : E} {s : Set E} (h : s \u2208 \ud835\udcdd x) : dimH s = finrank \u211d E :=\n  by\n  have e : E \u2243L[\u211d] Fin (finrank \u211d E) \u2192 \u211d :=\n    ContinuousLinearEquiv.ofFinrankEq (FiniteDimensional.finrank_fin_fun \u211d).symm\n  rw [\u2190 e.dimH_image]\n  refine' le_antisymm _ _\n  \u00b7 exact (dimH_mono (subset_univ _)).trans_eq (dimH_univ_pi_fin _)\n  \u00b7 have : e '' s \u2208 \ud835\udcdd (e x) := by\n      rw [\u2190 e.map_nhds_eq]\n      exact image_mem_map h\n    rcases metric.nhds_basis_ball.mem_iff.1 this with \u27e8r, hr0, hr\u27e9\n    simpa only [dimH_ball_pi_fin (e x) hr0] using dimH_mono hr\n#align real.dimH_of_mem_nhds Real.dimH_of_mem_nhds\n\ntheorem dimH_of_nonempty_interior {s : Set E} (h : (interior s).Nonempty) : dimH s = finrank \u211d E :=\n  let \u27e8x, hx\u27e9 := h\n  dimH_of_mem_nhds (mem_interior_iff_mem_nhds.1 hx)\n#align real.dimH_of_nonempty_interior Real.dimH_of_nonempty_interior\n\nvariable (E)\n\ntheorem dimH_univ_eq_finrank : dimH (univ : Set E) = finrank \u211d E :=\n  dimH_of_mem_nhds (@univ_mem _ (\ud835\udcdd 0))\n#align real.dimH_univ_eq_finrank Real.dimH_univ_eq_finrank\n\ntheorem dimH_univ : dimH (univ : Set \u211d) = 1 := by\n  rw [dimH_univ_eq_finrank \u211d, FiniteDimensional.finrank_self, Nat.cast_one]\n#align real.dimH_univ Real.dimH_univ\n\nend Real\n\nvariable {E F : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] [FiniteDimensional \u211d E]\n  [NormedAddCommGroup F] [NormedSpace \u211d F]\n\ntheorem dense_compl_of_dimH_lt_finrank {s : Set E} (hs : dimH s < finrank \u211d E) : Dense (s\u1d9c) :=\n  by\n  refine' fun x => mem_closure_iff_nhds.2 fun t ht => nonempty_iff_ne_empty.2 fun he => hs.not_le _\n  rw [\u2190 diff_eq, diff_eq_empty] at he\n  rw [\u2190 Real.dimH_of_mem_nhds ht]\n  exact dimH_mono he\n#align dense_compl_of_dimH_lt_finrank dense_compl_of_dimH_lt_finrank\n\n/-!\n### Hausdorff dimension and `C\u00b9`-smooth maps\n\n`C\u00b9`-smooth maps are locally Lipschitz continuous, hence they do not increase the Hausdorff\ndimension of sets.\n-/\n\n\n/-- Let `f` be a function defined on a finite dimensional real normed space. If `f` is `C\u00b9`-smooth\non a convex set `s`, then the Hausdorff dimension of `f '' s` is less than or equal to the Hausdorff\ndimension of `s`.\n\nTODO: do we actually need `convex \u211d s`? -/\ntheorem ContDiffOn.dimH_image_le {f : E \u2192 F} {s t : Set E} (hf : ContDiffOn \u211d 1 f s)\n    (hc : Convex \u211d s) (ht : t \u2286 s) : dimH (f '' t) \u2264 dimH t :=\n  dimH_image_le_of_locally_lipschitz_on fun x hx =>\n    let \u27e8C, u, hu, hf\u27e9 := (hf x (ht hx)).exists_lipschitzOnWith hc\n    \u27e8C, u, nhdsWithin_mono _ ht hu, hf\u27e9\n#align cont_diff_on.dimH_image_le ContDiffOn.dimH_image_le\n\n/-- The Hausdorff dimension of the range of a `C\u00b9`-smooth function defined on a finite dimensional\nreal normed space is at most the dimension of its domain as a vector space over `\u211d`. -/\ntheorem ContDiff.dimH_range_le {f : E \u2192 F} (h : ContDiff \u211d 1 f) : dimH (range f) \u2264 finrank \u211d E :=\n  calc\n    dimH (range f) = dimH (f '' univ) := by rw [image_univ]\n    _ \u2264 dimH (univ : Set E) := (h.ContDiffOn.dimH_image_le convex_univ Subset.rfl)\n    _ = finrank \u211d E := Real.dimH_univ_eq_finrank E\n    \n#align cont_diff.dimH_range_le ContDiff.dimH_range_le\n\n/-- A particular case of Sard's Theorem. Let `f : E \u2192 F` be a map between finite dimensional real\nvector spaces. Suppose that `f` is `C\u00b9` smooth on a convex set `s` of Hausdorff dimension strictly\nless than the dimension of `F`. Then the complement of the image `f '' s` is dense in `F`. -/\ntheorem ContDiffOn.dense_compl_image_of_dimH_lt_finrank [FiniteDimensional \u211d F] {f : E \u2192 F}\n    {s t : Set E} (h : ContDiffOn \u211d 1 f s) (hc : Convex \u211d s) (ht : t \u2286 s)\n    (htF : dimH t < finrank \u211d F) : Dense ((f '' t)\u1d9c) :=\n  dense_compl_of_dimH_lt_finrank <| (h.dimH_image_le hc ht).trans_lt htF\n#align cont_diff_on.dense_compl_image_of_dimH_lt_finrank ContDiffOn.dense_compl_image_of_dimH_lt_finrank\n\n/-- A particular case of Sard's Theorem. If `f` is a `C\u00b9` smooth map from a real vector space to a\nreal vector space `F` of strictly larger dimension, then the complement of the range of `f` is dense\nin `F`. -/\ntheorem ContDiff.dense_compl_range_of_finrank_lt_finrank [FiniteDimensional \u211d F] {f : E \u2192 F}\n    (h : ContDiff \u211d 1 f) (hEF : finrank \u211d E < finrank \u211d F) : Dense (range f\u1d9c) :=\n  dense_compl_of_dimH_lt_finrank <| h.dimH_range_le.trans_lt <| Nat.cast_lt.2 hEF\n#align cont_diff.dense_compl_range_of_finrank_lt_finrank ContDiff.dense_compl_range_of_finrank_lt_finrank\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/MetricSpace/HausdorffDimension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8006920020959545, "lm_q1q2_score": 0.7152656968248046}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro\n-/\nimport algebra.ordered_group\nimport algebra.invertible\nimport data.set.intervals.basic\n\nset_option old_structure_cmd true\n\nuniverse u\nvariable {\u03b1 : Type u}\n\n/-- An `ordered_semiring \u03b1` is a semiring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\n@[protect_proj]\nclass ordered_semiring (\u03b1 : Type u) extends semiring \u03b1, ordered_cancel_add_comm_monoid \u03b1 :=\n(zero_le_one : 0 \u2264 (1 : \u03b1))\n(mul_lt_mul_of_pos_left :  \u2200 a b c : \u03b1, a < b \u2192 0 < c \u2192 c * a < c * b)\n(mul_lt_mul_of_pos_right : \u2200 a b c : \u03b1, a < b \u2192 0 < c \u2192 a * c < b * c)\n\nsection ordered_semiring\nvariables [ordered_semiring \u03b1] {a b c d : \u03b1}\n\nlemma zero_le_one : 0 \u2264 (1:\u03b1) :=\nordered_semiring.zero_le_one\n\nlemma zero_le_two : 0 \u2264 (2:\u03b1) :=\nadd_nonneg zero_le_one zero_le_one\n\nlemma one_le_two : 1 \u2264 (2:\u03b1) :=\ncalc (1:\u03b1) = 0 + 1 : (zero_add _).symm\n       ... \u2264 1 + 1 : add_le_add_right zero_le_one _\n\nsection nontrivial\n\nvariables [nontrivial \u03b1]\n\nlemma zero_lt_one : 0 < (1 : \u03b1) :=\nlt_of_le_of_ne zero_le_one zero_ne_one\n\nlemma zero_lt_two : 0 < (2:\u03b1) := add_pos zero_lt_one zero_lt_one\n\n@[field_simps] lemma two_ne_zero : (2:\u03b1) \u2260 0 :=\nne.symm (ne_of_lt zero_lt_two)\n\nlemma one_lt_two : 1 < (2:\u03b1) :=\ncalc (2:\u03b1) = 1+1 : one_add_one_eq_two\n     ...   > 1+0 : add_lt_add_left zero_lt_one _\n     ...   = 1   : add_zero 1\n\nlemma zero_lt_three : 0 < (3:\u03b1) := add_pos zero_lt_two zero_lt_one\n\nlemma zero_lt_four : 0 < (4:\u03b1) := add_pos zero_lt_two zero_lt_two\n\nend nontrivial\n\nlemma mul_lt_mul_of_pos_left (h\u2081 : a < b) (h\u2082 : 0 < c) : c * a < c * b :=\nordered_semiring.mul_lt_mul_of_pos_left a b c h\u2081 h\u2082\n\nlemma mul_lt_mul_of_pos_right (h\u2081 : a < b) (h\u2082 : 0 < c) : a * c < b * c :=\nordered_semiring.mul_lt_mul_of_pos_right a b c h\u2081 h\u2082\n\nlemma mul_le_mul_of_nonneg_left (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c * a \u2264 c * b :=\nbegin\n  cases classical.em (b \u2264 a), { simp [h.antisymm h\u2081] },\n  cases classical.em (c \u2264 0), { simp [h_1.antisymm h\u2082] },\n  exact (mul_lt_mul_of_pos_left (h\u2081.lt_of_not_le h) (h\u2082.lt_of_not_le h_1)).le,\nend\n\nlemma mul_le_mul_of_nonneg_right (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : a * c \u2264 b * c :=\nbegin\n  cases classical.em (b \u2264 a), { simp [h.antisymm h\u2081] },\n  cases classical.em (c \u2264 0), { simp [h_1.antisymm h\u2082] },\n  exact (mul_lt_mul_of_pos_right (h\u2081.lt_of_not_le h) (h\u2082.lt_of_not_le h_1)).le,\nend\n\n-- TODO: there are four variations, depending on which variables we assume to be nonneg\nlemma mul_le_mul (hac : a \u2264 c) (hbd : b \u2264 d) (nn_b : 0 \u2264 b) (nn_c : 0 \u2264 c) : a * b \u2264 c * d :=\ncalc\n  a * b \u2264 c * b : mul_le_mul_of_nonneg_right hac nn_b\n    ... \u2264 c * d : mul_le_mul_of_nonneg_left hbd nn_c\n\nlemma mul_nonneg_le_one_le {\u03b1 : Type*} [ordered_semiring \u03b1] {a b c : \u03b1}\n  (h\u2081 : 0 \u2264 c) (h\u2082 : a \u2264 c) (h\u2083 : 0 \u2264 b) (h\u2084 : b \u2264 1) : a * b \u2264 c :=\nby simpa only [mul_one] using mul_le_mul h\u2082 h\u2084 h\u2083 h\u2081\n\nlemma mul_nonneg (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a * b :=\nhave h : 0 * b \u2264 a * b, from mul_le_mul_of_nonneg_right ha hb,\nby rwa [zero_mul] at h\n\nlemma mul_nonpos_of_nonneg_of_nonpos (ha : 0 \u2264 a) (hb : b \u2264 0) : a * b \u2264 0 :=\nhave h : a * b \u2264 a * 0, from mul_le_mul_of_nonneg_left hb ha,\nby rwa mul_zero at h\n\nlemma mul_nonpos_of_nonpos_of_nonneg (ha : a \u2264 0) (hb : 0 \u2264 b) : a * b \u2264 0 :=\nhave h : a * b \u2264 0 * b, from mul_le_mul_of_nonneg_right ha hb,\nby rwa zero_mul at h\n\nlemma mul_lt_mul (hac : a < c) (hbd : b \u2264 d) (pos_b : 0 < b) (nn_c : 0 \u2264 c) : a * b < c * d :=\ncalc\n  a * b < c * b : mul_lt_mul_of_pos_right hac pos_b\n    ... \u2264 c * d : mul_le_mul_of_nonneg_left hbd nn_c\n\nlemma mul_lt_mul' (h1 : a \u2264 c) (h2 : b < d) (h3 : 0 \u2264 b) (h4 : 0 < c) : a * b < c * d :=\ncalc\n   a * b \u2264 c * b : mul_le_mul_of_nonneg_right h1 h3\n     ... < c * d : mul_lt_mul_of_pos_left h2 h4\n\nlemma mul_pos (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=\nhave h : 0 * b < a * b, from mul_lt_mul_of_pos_right ha hb,\nby rwa zero_mul at h\n\nlemma mul_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a * b < 0 :=\nhave h : a * b < a * 0, from mul_lt_mul_of_pos_left hb ha,\nby rwa mul_zero at h\n\nlemma mul_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a * b < 0 :=\nhave h : a * b < 0 * b, from mul_lt_mul_of_pos_right ha hb,\nby rwa zero_mul at  h\n\nlemma mul_self_lt_mul_self (h1 : 0 \u2264 a) (h2 : a < b) : a * a < b * b :=\nmul_lt_mul' h2.le h2 h1 $ h1.trans_lt h2\n\nlemma strict_mono_incr_on_mul_self : strict_mono_incr_on (\u03bb x : \u03b1, x * x) (set.Ici 0) :=\n\u03bb x hx y hy hxy, mul_self_lt_mul_self hx hxy\n\nlemma mul_self_le_mul_self (h1 : 0 \u2264 a) (h2 : a \u2264 b) : a * a \u2264 b * b :=\nmul_le_mul h2 h2 h1 $ h1.trans h2\n\nlemma mul_lt_mul'' (h1 : a < c) (h2 : b < d) (h3 : 0 \u2264 a) (h4 : 0 \u2264 b) : a * b < c * d :=\n(lt_or_eq_of_le h4).elim\n  (\u03bb b0, mul_lt_mul h1 h2.le b0 $ h3.trans h1.le)\n  (\u03bb b0, by rw [\u2190 b0, mul_zero]; exact\n    mul_pos (h3.trans_lt h1) (h4.trans_lt h2))\n\nlemma le_mul_of_one_le_right (hb : 0 \u2264 b) (h : 1 \u2264 a) : b \u2264 b * a :=\nsuffices b * 1 \u2264 b * a, by rwa mul_one at this,\nmul_le_mul_of_nonneg_left h hb\n\nlemma le_mul_of_one_le_left (hb : 0 \u2264 b) (h : 1 \u2264 a) : b \u2264 a * b :=\nsuffices 1 * b \u2264 a * b, by rwa one_mul at this,\nmul_le_mul_of_nonneg_right h hb\n\nlemma lt_mul_of_one_lt_right (hb : 0 < b) (h : 1 < a) : b < b * a :=\nsuffices b * 1 < b * a, by rwa mul_one at this,\nmul_lt_mul' (le_refl _) h zero_le_one hb\n\nlemma lt_mul_of_one_lt_left (hb : 0 < b) (h : 1 < a) : b < a * b :=\nsuffices 1 * b < a * b, by rwa one_mul at this,\nmul_lt_mul h (le_refl _) hb (zero_le_one.trans h.le)\n\nlemma add_le_mul_two_add {a b : \u03b1}\n  (a2 : 2 \u2264 a) (b0 : 0 \u2264 b) : a + (2 + b) \u2264 a * (2 + b) :=\ncalc a + (2 + b) \u2264 a + (a + a * b) :\n      add_le_add_left (add_le_add a2 (le_mul_of_one_le_left b0 (one_le_two.trans a2))) a\n             ... \u2264 a * (2 + b) : by rw [mul_add, mul_two, add_assoc]\n\nlemma one_le_mul_of_one_le_of_one_le {a b : \u03b1} (a1 : 1 \u2264 a) (b1 : 1 \u2264 b) :\n  (1 : \u03b1) \u2264 a * b :=\n(mul_one (1 : \u03b1)).symm.le.trans (mul_le_mul a1 b1 zero_le_one (zero_le_one.trans a1))\n\n/-- Pullback an `ordered_semiring` under an injective map. -/\ndef function.injective.ordered_semiring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_semiring \u03b2 :=\n{ zero_le_one := show f 0 \u2264 f 1, by simp only [zero, one, zero_le_one],\n  mul_lt_mul_of_pos_left := \u03bb  a b c ab c0, show f (c * a) < f (c * b),\n    begin\n      rw [mul, mul],\n      refine mul_lt_mul_of_pos_left ab _,\n      rwa \u2190 zero,\n    end,\n  mul_lt_mul_of_pos_right := \u03bb a b c ab c0, show f (a * c) < f (b * c),\n    begin\n      rw [mul, mul],\n      refine mul_lt_mul_of_pos_right ab _,\n      rwa \u2190 zero,\n    end,\n  ..hf.ordered_cancel_add_comm_monoid f zero add,\n  ..hf.semiring f zero one add mul }\n\nsection\nvariable [nontrivial \u03b1]\n\nlemma bit1_pos (h : 0 \u2264 a) : 0 < bit1 a :=\nlt_add_of_le_of_pos (add_nonneg h h) zero_lt_one\n\nlemma lt_add_one (a : \u03b1) : a < a + 1 :=\nlt_add_of_le_of_pos le_rfl zero_lt_one\n\nlemma lt_one_add (a : \u03b1) : a < 1 + a :=\nby { rw [add_comm], apply lt_add_one }\n\nend\n\nlemma bit1_pos' (h : 0 < a) : 0 < bit1 a :=\nbegin\n  nontriviality,\n  exact bit1_pos h.le,\nend\n\nlemma one_lt_mul (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\nbegin\n  nontriviality,\n  exact (one_mul (1 : \u03b1)) \u25b8 mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)\nend\n\nlemma mul_le_one (ha : a \u2264 1) (hb' : 0 \u2264 b) (hb : b \u2264 1) : a * b \u2264 1 :=\nbegin rw \u2190 one_mul (1 : \u03b1), apply mul_le_mul; {assumption <|> apply zero_le_one} end\n\nlemma one_lt_mul_of_le_of_lt (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\nbegin\n  nontriviality,\n  calc 1 = 1 * 1 : by rw one_mul\n     ... < a * b : mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)\nend\n\nlemma one_lt_mul_of_lt_of_le (ha : 1 < a) (hb : 1 \u2264 b) : 1 < a * b :=\nbegin\n  nontriviality,\n  calc 1 = 1 * 1 : by rw one_mul\n    ... < a * b : mul_lt_mul ha hb zero_lt_one $ zero_le_one.trans ha.le\nend\n\nlemma mul_le_of_le_one_right (ha : 0 \u2264 a) (hb1 : b \u2264 1) : a * b \u2264 a :=\ncalc a * b \u2264 a * 1 : mul_le_mul_of_nonneg_left hb1 ha\n... = a : mul_one a\n\nlemma mul_le_of_le_one_left (hb : 0 \u2264 b) (ha1 : a \u2264 1) : a * b \u2264 b :=\ncalc a * b \u2264 1 * b : mul_le_mul ha1 le_rfl hb zero_le_one\n... = b : one_mul b\n\nlemma mul_lt_one_of_nonneg_of_lt_one_left (ha0 : 0 \u2264 a) (ha : a < 1) (hb : b \u2264 1) : a * b < 1 :=\ncalc a * b \u2264 a : mul_le_of_le_one_right ha0 hb\n... < 1 : ha\n\nlemma mul_lt_one_of_nonneg_of_lt_one_right (ha : a \u2264 1) (hb0 : 0 \u2264 b) (hb : b < 1) : a * b < 1 :=\ncalc a * b \u2264 b : mul_le_of_le_one_left hb0 ha\n... < 1 : hb\n\nend ordered_semiring\n\nsection ordered_comm_semiring\n\n/-- An `ordered_comm_semiring \u03b1` is a commutative semiring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\n@[protect_proj]\nclass ordered_comm_semiring (\u03b1 : Type u) extends ordered_semiring \u03b1, comm_semiring \u03b1\n\n/-- Pullback an `ordered_comm_semiring` under an injective map. -/\ndef function.injective.ordered_comm_semiring [ordered_comm_semiring \u03b1] {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  ordered_comm_semiring \u03b2 :=\n{ ..hf.comm_semiring f zero one add mul,\n  ..hf.ordered_semiring f zero one add mul }\n\nend ordered_comm_semiring\n\n/--\nA `linear_ordered_semiring \u03b1` is a nontrivial semiring `\u03b1` with a linear order\nsuch that multiplication with a positive number and addition are monotone.\n-/\n-- It's not entirely clear we should assume `nontrivial` at this point;\n-- it would be reasonable to explore changing this,\n-- but be warned that the instances involving `domain` may cause\n-- typeclass search loops.\n@[protect_proj]\nclass linear_ordered_semiring (\u03b1 : Type u) extends ordered_semiring \u03b1, linear_order \u03b1, nontrivial \u03b1\n\nsection linear_ordered_semiring\nvariables [linear_ordered_semiring \u03b1] {a b c d : \u03b1}\n\n-- `norm_num` expects the lemma stating `0 < 1` to have a single typeclass argument\n-- (see `norm_num.prove_pos_nat`).\n-- Rather than working out how to relax that assumption,\n-- we provide a synonym for `zero_lt_one` (which needs both `ordered_semiring \u03b1` and `nontrivial \u03b1`)\n-- with only a `linear_ordered_semiring` typeclass argument.\nlemma zero_lt_one' : 0 < (1 : \u03b1) := zero_lt_one\n\nlemma lt_of_mul_lt_mul_left (h : c * a < c * b) (hc : 0 \u2264 c) : a < b :=\nlt_of_not_ge\n  (assume h1 : b \u2264 a,\n   have h2 : c * b \u2264 c * a, from mul_le_mul_of_nonneg_left h1 hc,\n   h2.not_lt h)\n\nlemma lt_of_mul_lt_mul_right (h : a * c < b * c) (hc : 0 \u2264 c) : a < b :=\nlt_of_not_ge\n  (assume h1 : b \u2264 a,\n   have h2 : b * c \u2264 a * c, from mul_le_mul_of_nonneg_right h1 hc,\n   h2.not_lt h)\n\nlemma le_of_mul_le_mul_left (h : c * a \u2264 c * b) (hc : 0 < c) : a \u2264 b :=\nle_of_not_gt\n  (assume h1 : b < a,\n   have h2 : c * b < c * a, from mul_lt_mul_of_pos_left h1 hc,\n   h2.not_le h)\n\nlemma le_of_mul_le_mul_right (h : a * c \u2264 b * c) (hc : 0 < c) : a \u2264 b :=\nle_of_not_gt\n  (assume h1 : b < a,\n   have h2 : b * c < a * c, from mul_lt_mul_of_pos_right h1 hc,\n   h2.not_le h)\n\nlemma pos_and_pos_or_neg_and_neg_of_mul_pos (hab : 0 < a * b) :\n  (0 < a \u2227 0 < b) \u2228 (a < 0 \u2227 b < 0) :=\nbegin\n  rcases lt_trichotomy 0 a with (ha|rfl|ha),\n  { refine or.inl \u27e8ha, _\u27e9,\n    contrapose! hab,\n    exact mul_nonpos_of_nonneg_of_nonpos ha.le hab },\n  { rw [zero_mul] at hab, exact hab.false.elim },\n  { refine or.inr \u27e8ha, _\u27e9,\n    contrapose! hab,\n    exact mul_nonpos_of_nonpos_of_nonneg ha.le hab }\nend\n\nlemma nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg (hab : 0 \u2264 a * b) :\n    (0 \u2264 a \u2227 0 \u2264 b) \u2228 (a \u2264 0 \u2227 b \u2264 0) :=\nbegin\n  contrapose! hab,\n  rcases lt_trichotomy 0 a with (ha|rfl|ha),\n  exacts [mul_neg_of_pos_of_neg ha (hab.1 ha.le), ((hab.1 le_rfl).asymm (hab.2 le_rfl)).elim,\n    mul_neg_of_neg_of_pos ha (hab.2 ha.le)]\nend\n\nlemma pos_of_mul_pos_left (h : 0 < a * b) (ha : 0 \u2264 a) : 0 < b :=\n((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ \u03bb h, h.1.not_le ha).2\n\nlemma pos_of_mul_pos_right (h : 0 < a * b) (hb : 0 \u2264 b) : 0 < a :=\n((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ \u03bb h, h.2.not_le hb).1\n\n@[simp] lemma inv_of_pos [invertible a] : 0 < \u215fa \u2194 0 < a :=\nbegin\n  have : 0 < a * \u215fa, by simp only [mul_inv_of_self, zero_lt_one],\n  exact \u27e8\u03bb h, pos_of_mul_pos_right this h.le, \u03bb h, pos_of_mul_pos_left this h.le\u27e9\nend\n\n@[simp] lemma inv_of_nonpos [invertible a] : \u215fa \u2264 0 \u2194 a \u2264 0 :=\nby simp only [\u2190 not_lt, inv_of_pos]\n\nlemma nonneg_of_mul_nonneg_left (h : 0 \u2264 a * b) (h1 : 0 < a) : 0 \u2264 b :=\nle_of_not_gt (assume h2 : b < 0, (mul_neg_of_pos_of_neg h1 h2).not_le h)\n\nlemma nonneg_of_mul_nonneg_right (h : 0 \u2264 a * b) (h1 : 0 < b) : 0 \u2264 a :=\nle_of_not_gt (assume h2 : a < 0, (mul_neg_of_neg_of_pos h2 h1).not_le h)\n\n@[simp] lemma inv_of_nonneg [invertible a] : 0 \u2264 \u215fa \u2194 0 \u2264 a :=\nbegin\n  have : 0 < a * \u215fa, by simp only [mul_inv_of_self, zero_lt_one],\n  exact \u27e8\u03bb h, (pos_of_mul_pos_right this h).le, \u03bb h, (pos_of_mul_pos_left this h).le\u27e9\nend\n\n@[simp] lemma inv_of_lt_zero [invertible a] : \u215fa < 0 \u2194 a < 0 :=\nby simp only [\u2190 not_le, inv_of_nonneg]\n\n@[simp] lemma inv_of_le_one [invertible a] (h : 1 \u2264 a) : \u215fa \u2264 1 :=\nmul_inv_of_self a \u25b8 le_mul_of_one_le_left (inv_of_nonneg.2 $ zero_le_one.trans h) h\n\nlemma neg_of_mul_neg_left (h : a * b < 0) (h1 : 0 \u2264 a) : b < 0 :=\nlt_of_not_ge (assume h2 : b \u2265 0, (mul_nonneg h1 h2).not_lt h)\n\nlemma neg_of_mul_neg_right (h : a * b < 0) (h1 : 0 \u2264 b) : a < 0 :=\nlt_of_not_ge (assume h2 : a \u2265 0, (mul_nonneg h2 h1).not_lt h)\n\nlemma nonpos_of_mul_nonpos_left (h : a * b \u2264 0) (h1 : 0 < a) : b \u2264 0 :=\nle_of_not_gt (assume h2 : b > 0, (mul_pos h1 h2).not_le h)\n\nlemma nonpos_of_mul_nonpos_right (h : a * b \u2264 0) (h1 : 0 < b) : a \u2264 0 :=\nle_of_not_gt (assume h2 : a > 0, (mul_pos h2 h1).not_le h)\n\n@[simp] lemma mul_le_mul_left (h : 0 < c) : c * a \u2264 c * b \u2194 a \u2264 b :=\n\u27e8\u03bb h', le_of_mul_le_mul_left h' h, \u03bb h', mul_le_mul_of_nonneg_left h' h.le\u27e9\n\n@[simp] lemma mul_le_mul_right (h : 0 < c) : a * c \u2264 b * c \u2194 a \u2264 b :=\n\u27e8\u03bb h', le_of_mul_le_mul_right h' h, \u03bb h', mul_le_mul_of_nonneg_right h' h.le\u27e9\n\n@[simp] lemma mul_lt_mul_left (h : 0 < c) : c * a < c * b \u2194 a < b :=\n\u27e8lt_imp_lt_of_le_imp_le $ \u03bb h', mul_le_mul_of_nonneg_left h' h.le,\n \u03bb h', mul_lt_mul_of_pos_left h' h\u27e9\n\n@[simp] lemma mul_lt_mul_right (h : 0 < c) : a * c < b * c \u2194 a < b :=\n\u27e8lt_imp_lt_of_le_imp_le $ \u03bb h', mul_le_mul_of_nonneg_right h' h.le,\n \u03bb h', mul_lt_mul_of_pos_right h' h\u27e9\n\n@[simp] lemma zero_le_mul_left (h : 0 < c) : 0 \u2264 c * b \u2194 0 \u2264 b :=\nby { convert mul_le_mul_left h, simp }\n\n@[simp] lemma zero_le_mul_right (h : 0 < c) : 0 \u2264 b * c \u2194 0 \u2264 b :=\nby { convert mul_le_mul_right h, simp }\n\n@[simp] lemma zero_lt_mul_left (h : 0 < c) : 0 < c * b \u2194 0 < b :=\nby { convert mul_lt_mul_left h, simp }\n\n@[simp] lemma zero_lt_mul_right (h : 0 < c) : 0 < b * c \u2194 0 < b :=\nby { convert mul_lt_mul_right h, simp }\n\nlemma add_le_mul_of_left_le_right (a2 : 2 \u2264 a) (ab : a \u2264 b) : a + b \u2264 a * b :=\nhave 0 < b, from\ncalc 0 < 2 : zero_lt_two\n   ... \u2264 a : a2\n   ... \u2264 b : ab,\ncalc a + b \u2264 b + b : add_le_add_right ab b\n       ... = 2 * b : (two_mul b).symm\n       ... \u2264 a * b : (mul_le_mul_right this).mpr a2\n\nlemma add_le_mul_of_right_le_left (b2 : 2 \u2264 b) (ba : b \u2264 a) : a + b \u2264 a * b :=\nhave 0 < a, from\ncalc 0 < 2 : zero_lt_two\n   ... \u2264 b : b2\n   ... \u2264 a : ba,\ncalc a + b \u2264 a + a : add_le_add_left ba a\n       ... = a * 2 : (mul_two a).symm\n       ... \u2264 a * b : (mul_le_mul_left this).mpr b2\n\nlemma add_le_mul (a2 : 2 \u2264 a) (b2 : 2 \u2264 b) : a + b \u2264 a * b :=\nif hab : a \u2264 b then add_le_mul_of_left_le_right a2 hab\n               else add_le_mul_of_right_le_left b2 (le_of_not_le hab)\n\nlemma add_le_mul' (a2 : 2 \u2264 a) (b2 : 2 \u2264 b) : a + b \u2264 b * a :=\n(le_of_eq (add_comm _ _)).trans (add_le_mul b2 a2)\n\nsection\nvariables [nontrivial \u03b1]\n\n@[simp] lemma bit0_le_bit0 : bit0 a \u2264 bit0 b \u2194 a \u2264 b :=\nby rw [bit0, bit0, \u2190 two_mul, \u2190 two_mul, mul_le_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma bit0_lt_bit0 : bit0 a < bit0 b \u2194 a < b :=\nby rw [bit0, bit0, \u2190 two_mul, \u2190 two_mul, mul_lt_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma bit1_le_bit1 : bit1 a \u2264 bit1 b \u2194 a \u2264 b :=\n(add_le_add_iff_right 1).trans bit0_le_bit0\n\n@[simp] lemma bit1_lt_bit1 : bit1 a < bit1 b \u2194 a < b :=\n(add_lt_add_iff_right 1).trans bit0_lt_bit0\n\n@[simp] lemma one_le_bit1 : (1 : \u03b1) \u2264 bit1 a \u2194 0 \u2264 a :=\nby rw [bit1, le_add_iff_nonneg_left, bit0, \u2190 two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma one_lt_bit1 : (1 : \u03b1) < bit1 a \u2194 0 < a :=\nby rw [bit1, lt_add_iff_pos_left, bit0, \u2190 two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma zero_le_bit0 : (0 : \u03b1) \u2264 bit0 a \u2194 0 \u2264 a :=\nby rw [bit0, \u2190 two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\n@[simp] lemma zero_lt_bit0 : (0 : \u03b1) < bit0 a \u2194 0 < a :=\nby rw [bit0, \u2190 two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:\u03b1))]\n\nend\n\nlemma le_mul_iff_one_le_left (hb : 0 < b) : b \u2264 a * b \u2194 1 \u2264 a :=\nsuffices 1 * b \u2264 a * b \u2194 1 \u2264 a, by rwa one_mul at this,\nmul_le_mul_right hb\n\nlemma lt_mul_iff_one_lt_left (hb : 0 < b) : b < a * b \u2194 1 < a :=\nsuffices 1 * b < a * b \u2194 1 < a, by rwa one_mul at this,\nmul_lt_mul_right hb\n\nlemma le_mul_iff_one_le_right (hb : 0 < b) : b \u2264 b * a \u2194 1 \u2264 a :=\nsuffices b * 1 \u2264 b * a \u2194 1 \u2264 a, by rwa mul_one at this,\nmul_le_mul_left hb\n\nlemma lt_mul_iff_one_lt_right (hb : 0 < b) : b < b * a \u2194 1 < a :=\nsuffices b * 1 < b * a \u2194 1 < a, by rwa mul_one at this,\nmul_lt_mul_left hb\n\ntheorem mul_nonneg_iff_right_nonneg_of_pos (h : 0 < a) : 0 \u2264 b * a \u2194 0 \u2264 b :=\n\u27e8assume : 0 \u2264 b * a, nonneg_of_mul_nonneg_right this h, assume : 0 \u2264 b, mul_nonneg this h.le\u27e9\n\nlemma mul_le_iff_le_one_left (hb : 0 < b) : a * b \u2264 b \u2194 a \u2264 1 :=\n\u27e8 \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).2 h.not_lt),\n  \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).1 h.not_lt) \u27e9\n\nlemma mul_lt_iff_lt_one_left (hb : 0 < b) : a * b < b \u2194 a < 1 :=\n\u27e8 \u03bb h, lt_of_not_ge (mt (le_mul_iff_one_le_left hb).2 h.not_le),\n  \u03bb h, lt_of_not_ge (mt (le_mul_iff_one_le_left hb).1 h.not_le) \u27e9\n\nlemma mul_le_iff_le_one_right (hb : 0 < b) : b * a \u2264 b \u2194 a \u2264 1 :=\n\u27e8 \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).2 h.not_lt),\n  \u03bb h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).1 h.not_lt) \u27e9\n\nlemma mul_lt_iff_lt_one_right (hb : 0 < b) : b * a < b \u2194 a < 1 :=\n\u27e8 \u03bb h, lt_of_not_ge (mt (le_mul_iff_one_le_right hb).2 h.not_le),\n  \u03bb h, lt_of_not_ge (mt (le_mul_iff_one_le_right hb).1 h.not_le) \u27e9\n\nlemma nonpos_of_mul_nonneg_left (h : 0 \u2264 a * b) (hb : b < 0) : a \u2264 0 :=\nle_of_not_gt (\u03bb ha, absurd h (mul_neg_of_pos_of_neg ha hb).not_le)\n\nlemma nonpos_of_mul_nonneg_right (h : 0 \u2264 a * b) (ha : a < 0) : b \u2264 0 :=\nle_of_not_gt (\u03bb hb, absurd h (mul_neg_of_neg_of_pos ha hb).not_le)\n\nlemma neg_of_mul_pos_left (h : 0 < a * b) (hb : b \u2264 0) : a < 0 :=\nlt_of_not_ge (\u03bb ha, absurd h (mul_nonpos_of_nonneg_of_nonpos ha hb).not_lt)\n\nlemma neg_of_mul_pos_right (h : 0 < a * b) (ha : a \u2264 0) : b < 0 :=\nlt_of_not_ge (\u03bb hb, absurd h (mul_nonpos_of_nonpos_of_nonneg ha hb).not_lt)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_semiring.to_no_top_order {\u03b1 : Type*} [linear_ordered_semiring \u03b1] :\n  no_top_order \u03b1 :=\n\u27e8assume a, \u27e8a + 1, lt_add_of_pos_right _ zero_lt_one\u27e9\u27e9\n\n/-- Pullback a `linear_ordered_semiring` under an injective map. -/\ndef function.injective.linear_ordered_semiring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [nontrivial \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y) :\n  linear_ordered_semiring \u03b2 :=\n{ ..linear_order.lift f hf,\n  ..\u2039nontrivial \u03b2\u203a,\n  ..hf.ordered_semiring f zero one add mul }\n\nend linear_ordered_semiring\n\nsection mono\nvariables {\u03b2 : Type*} [linear_ordered_semiring \u03b1] [preorder \u03b2] {f g : \u03b2 \u2192 \u03b1} {a : \u03b1}\n\nlemma monotone_mul_left_of_nonneg (ha : 0 \u2264 a) : monotone (\u03bb x, a*x) :=\nassume b c b_le_c, mul_le_mul_of_nonneg_left b_le_c ha\n\nlemma monotone_mul_right_of_nonneg (ha : 0 \u2264 a) : monotone (\u03bb x, x*a) :=\nassume b c b_le_c, mul_le_mul_of_nonneg_right b_le_c ha\n\nlemma monotone.mul_const (hf : monotone f) (ha : 0 \u2264 a) :\n  monotone (\u03bb x, (f x) * a) :=\n(monotone_mul_right_of_nonneg ha).comp hf\n\nlemma monotone.const_mul (hf : monotone f) (ha : 0 \u2264 a) :\n  monotone (\u03bb x, a * (f x)) :=\n(monotone_mul_left_of_nonneg ha).comp hf\n\nlemma monotone.mul (hf : monotone f) (hg : monotone g) (hf0 : \u2200 x, 0 \u2264 f x) (hg0 : \u2200 x, 0 \u2264 g x) :\n  monotone (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)\n\nlemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (\u03bb x, a * x) :=\nassume b c b_lt_c, (mul_lt_mul_left ha).2 b_lt_c\n\nlemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (\u03bb x, x * a) :=\nassume b c b_lt_c, (mul_lt_mul_right ha).2 b_lt_c\n\nlemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) :\n  strict_mono (\u03bb x, (f x) * a) :=\n(strict_mono_mul_right_of_pos ha).comp hf\n\nlemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) :\n  strict_mono (\u03bb x, a * (f x)) :=\n(strict_mono_mul_left_of_pos ha).comp hf\n\nlemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : \u2200 x, 0 \u2264 f x)\n  (hg0 : \u2200 x, 0 < g x) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul (hf h) (hg h.le) (hg0 x) (hf0 y)\n\nlemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : \u2200 x, 0 < f x)\n  (hg0 : \u2200 x, 0 \u2264 g x) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul' (hf h.le) (hg h) (hg0 x) (hf0 y)\n\nlemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : \u2200 x, 0 \u2264 f x)\n  (hg0 : \u2200 x, 0 \u2264 g x) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)\n\nend mono\n\nsection linear_ordered_semiring\nvariables [linear_ordered_semiring \u03b1] {a b c : \u03b1}\n\n@[simp] lemma decidable.mul_le_mul_left (h : 0 < c) : c * a \u2264 c * b \u2194 a \u2264 b :=\ndecidable.le_iff_le_iff_lt_iff_lt.2 $ mul_lt_mul_left h\n\n@[simp] lemma decidable.mul_le_mul_right (h : 0 < c) : a * c \u2264 b * c \u2194 a \u2264 b :=\ndecidable.le_iff_le_iff_lt_iff_lt.2 $ mul_lt_mul_right h\n\nlemma mul_max_of_nonneg (b c : \u03b1) (ha : 0 \u2264 a) : a * max b c = max (a * b) (a * c) :=\n(monotone_mul_left_of_nonneg ha).map_max\n\nlemma mul_min_of_nonneg (b c : \u03b1) (ha : 0 \u2264 a) : a * min b c = min (a * b) (a * c) :=\n(monotone_mul_left_of_nonneg ha).map_min\n\nlemma max_mul_of_nonneg (a b : \u03b1) (hc : 0 \u2264 c) : max a b * c = max (a * c) (b * c) :=\n(monotone_mul_right_of_nonneg hc).map_max\n\nlemma min_mul_of_nonneg (a b : \u03b1) (hc : 0 \u2264 c) : min a b * c = min (a * c) (b * c) :=\n(monotone_mul_right_of_nonneg hc).map_min\n\nend linear_ordered_semiring\n\n/-- An `ordered_ring \u03b1` is a ring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\n@[protect_proj]\nclass ordered_ring (\u03b1 : Type u) extends ring \u03b1, ordered_add_comm_group \u03b1 :=\n(zero_le_one : 0 \u2264 (1 : \u03b1))\n(mul_pos     : \u2200 a b : \u03b1, 0 < a \u2192 0 < b \u2192 0 < a * b)\n\nsection ordered_ring\nvariables [ordered_ring \u03b1] {a b c : \u03b1}\n\nlemma ordered_ring.mul_nonneg (a b : \u03b1) (h\u2081 : 0 \u2264 a) (h\u2082 : 0 \u2264 b) : 0 \u2264 a * b :=\nbegin\n  cases classical.em (a \u2264 0), { simp [le_antisymm h h\u2081] },\n  cases classical.em (b \u2264 0), { simp [le_antisymm h_1 h\u2082] },\n  exact (le_not_le_of_lt (ordered_ring.mul_pos a b (h\u2081.lt_of_not_le h) (h\u2082.lt_of_not_le h_1))).left,\nend\n\nlemma ordered_ring.mul_le_mul_of_nonneg_left (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c * a \u2264 c * b :=\nbegin\n  rw [\u2190 sub_nonneg, \u2190 mul_sub],\n  exact ordered_ring.mul_nonneg c (b - a) h\u2082 (sub_nonneg.2 h\u2081),\nend\n\nlemma ordered_ring.mul_le_mul_of_nonneg_right (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : a * c \u2264 b * c :=\nbegin\n  rw [\u2190 sub_nonneg, \u2190 sub_mul],\n  exact ordered_ring.mul_nonneg _ _ (sub_nonneg.2 h\u2081) h\u2082,\nend\n\nlemma ordered_ring.mul_lt_mul_of_pos_left (h\u2081 : a < b) (h\u2082 : 0 < c) : c * a < c * b :=\nbegin\n  rw [\u2190 sub_pos, \u2190 mul_sub],\n  exact ordered_ring.mul_pos _ _ h\u2082 (sub_pos.2 h\u2081),\nend\n\nlemma ordered_ring.mul_lt_mul_of_pos_right (h\u2081 : a < b) (h\u2082 : 0 < c) : a * c < b * c :=\nbegin\n  rw [\u2190 sub_pos, \u2190 sub_mul],\n  exact ordered_ring.mul_pos _ _ (sub_pos.2 h\u2081) h\u2082,\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance ordered_ring.to_ordered_semiring : ordered_semiring \u03b1 :=\n{ mul_zero                   := mul_zero,\n  zero_mul                   := zero_mul,\n  add_left_cancel            := @add_left_cancel \u03b1 _,\n  le_of_add_le_add_left      := @le_of_add_le_add_left \u03b1 _,\n  mul_lt_mul_of_pos_left     := @ordered_ring.mul_lt_mul_of_pos_left \u03b1 _,\n  mul_lt_mul_of_pos_right    := @ordered_ring.mul_lt_mul_of_pos_right \u03b1 _,\n  ..\u2039ordered_ring \u03b1\u203a }\n\nlemma mul_le_mul_of_nonpos_left {a b c : \u03b1} (h : b \u2264 a) (hc : c \u2264 0) : c * a \u2264 c * b :=\nhave -c \u2265 0,              from neg_nonneg_of_nonpos hc,\nhave -c * b \u2264 -c * a,     from mul_le_mul_of_nonneg_left h this,\nhave -(c * b) \u2264 -(c * a), by rwa [\u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul] at this,\nle_of_neg_le_neg this\n\nlemma mul_le_mul_of_nonpos_right {a b c : \u03b1} (h : b \u2264 a) (hc : c \u2264 0) : a * c \u2264 b * c :=\nhave -c \u2265 0,              from neg_nonneg_of_nonpos hc,\nhave b * -c \u2264 a * -c,     from mul_le_mul_of_nonneg_right h this,\nhave -(b * c) \u2264 -(a * c), by rwa [\u2190 neg_mul_eq_mul_neg, \u2190 neg_mul_eq_mul_neg] at this,\nle_of_neg_le_neg this\n\nlemma mul_nonneg_of_nonpos_of_nonpos {a b : \u03b1} (ha : a \u2264 0) (hb : b \u2264 0) : 0 \u2264 a * b :=\nhave 0 * b \u2264 a * b, from mul_le_mul_of_nonpos_right ha hb,\nby rwa zero_mul at this\n\nlemma mul_lt_mul_of_neg_left {a b c : \u03b1} (h : b < a) (hc : c < 0) : c * a < c * b :=\nhave -c > 0,              from neg_pos_of_neg hc,\nhave -c * b < -c * a,     from mul_lt_mul_of_pos_left h this,\nhave -(c * b) < -(c * a), by rwa [\u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul] at this,\nlt_of_neg_lt_neg this\n\nlemma mul_lt_mul_of_neg_right {a b c : \u03b1} (h : b < a) (hc : c < 0) : a * c < b * c :=\nhave -c > 0,              from neg_pos_of_neg hc,\nhave b * -c < a * -c,     from mul_lt_mul_of_pos_right h this,\nhave -(b * c) < -(a * c), by rwa [\u2190 neg_mul_eq_mul_neg, \u2190 neg_mul_eq_mul_neg] at this,\nlt_of_neg_lt_neg this\n\nlemma mul_pos_of_neg_of_neg {a b : \u03b1} (ha : a < 0) (hb : b < 0) : 0 < a * b :=\nhave 0 * b < a * b, from mul_lt_mul_of_neg_right ha hb,\nby rwa zero_mul at this\n\n/-- Pullback an `ordered_ring` under an injective map. -/\ndef function.injective.ordered_ring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (- x) = - f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  ordered_ring \u03b2 :=\n{ mul_pos := \u03bb a b a0 b0, show f 0 < f (a * b), by { rw [zero, mul], apply mul_pos; rwa \u2190 zero },\n  ..hf.ordered_semiring f zero one add mul,\n  ..hf.ring f zero one add mul neg sub }\n\nend ordered_ring\n\nsection ordered_comm_ring\n\n/-- An `ordered_comm_ring \u03b1` is a commutative ring `\u03b1` with a partial order such that\nmultiplication with a positive number and addition are monotone. -/\n@[protect_proj]\nclass ordered_comm_ring (\u03b1 : Type u) extends ordered_ring \u03b1, ordered_comm_semiring \u03b1, comm_ring \u03b1\n\n/-- Pullback an `ordered_comm_ring` under an injective map. -/\ndef function.injective.ordered_comm_ring [ordered_comm_ring \u03b1] {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (- x) = - f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  ordered_comm_ring \u03b2 :=\n{ ..hf.ordered_comm_semiring f zero one add mul,\n  ..hf.ordered_ring f zero one add mul neg sub,\n  ..hf.comm_ring f zero one add mul neg sub }\n\nend ordered_comm_ring\n\n/-- A `linear_ordered_ring \u03b1` is a ring `\u03b1` with a linear order such that\nmultiplication with a positive number and addition are monotone. -/\n@[protect_proj] class linear_ordered_ring (\u03b1 : Type u)\n  extends ordered_ring \u03b1, linear_order \u03b1, nontrivial \u03b1\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_ring.to_linear_ordered_add_comm_group [s : linear_ordered_ring \u03b1] :\n  linear_ordered_add_comm_group \u03b1 :=\n{ .. s }\n\nsection linear_ordered_ring\nvariables [linear_ordered_ring \u03b1] {a b c : \u03b1}\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semiring \u03b1 :=\n{ mul_zero                   := mul_zero,\n  zero_mul                   := zero_mul,\n  add_left_cancel            := @add_left_cancel \u03b1 _,\n  le_of_add_le_add_left      := @le_of_add_le_add_left \u03b1 _,\n  mul_lt_mul_of_pos_left     := @mul_lt_mul_of_pos_left \u03b1 _,\n  mul_lt_mul_of_pos_right    := @mul_lt_mul_of_pos_right \u03b1 _,\n  le_total                   := linear_ordered_ring.le_total,\n  ..\u2039linear_ordered_ring \u03b1\u203a }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_ring.to_domain : domain \u03b1 :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero :=\n    begin\n      intros a b hab,\n      contrapose! hab,\n      cases (lt_or_gt_of_ne hab.1) with ha ha; cases (lt_or_gt_of_ne hab.2) with hb hb,\n      exacts [(mul_pos_of_neg_of_neg ha hb).ne.symm, (mul_neg_of_neg_of_pos ha hb).ne,\n        (mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne.symm]\n    end,\n  .. \u2039linear_ordered_ring \u03b1\u203a }\n\n@[simp] lemma abs_one : abs (1 : \u03b1) = 1 := abs_of_pos zero_lt_one\n@[simp] lemma abs_two : abs (2 : \u03b1) = 2 := abs_of_pos zero_lt_two\n\nlemma abs_mul (a b : \u03b1) : abs (a * b) = abs a * abs b :=\nbegin\n  rw [abs_eq (mul_nonneg (abs_nonneg a) (abs_nonneg b))],\n  cases le_total a 0 with ha ha; cases le_total b 0 with hb hb;\n    simp [abs_of_nonpos, abs_of_nonneg, *]\nend\n\n/-- `abs` as a `monoid_with_zero_hom`. -/\ndef abs_hom : monoid_with_zero_hom \u03b1 \u03b1 := \u27e8abs, abs_zero, abs_one, abs_mul\u27e9\n\n@[simp] lemma abs_mul_abs_self (a : \u03b1) : abs a * abs a = a * a :=\nabs_by_cases (\u03bb x, x * x = a * a) rfl (neg_mul_neg a a)\n\n@[simp] lemma abs_mul_self (a : \u03b1) : abs (a * a) = a * a :=\nby rw [abs_mul, abs_mul_abs_self]\n\nlemma mul_pos_iff : 0 < a * b \u2194 0 < a \u2227 0 < b \u2228 a < 0 \u2227 b < 0 :=\n\u27e8pos_and_pos_or_neg_and_neg_of_mul_pos,\n  \u03bb h, h.elim (and_imp.2 mul_pos) (and_imp.2 mul_pos_of_neg_of_neg)\u27e9\n\nlemma mul_neg_iff : a * b < 0 \u2194 0 < a \u2227 b < 0 \u2228 a < 0 \u2227 0 < b :=\nby rw [\u2190 neg_pos, neg_mul_eq_mul_neg, mul_pos_iff, neg_pos, neg_lt_zero]\n\nlemma mul_nonneg_iff : 0 \u2264 a * b \u2194 0 \u2264 a \u2227 0 \u2264 b \u2228 a \u2264 0 \u2227 b \u2264 0 :=\n\u27e8nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg,\n  \u03bb h, h.elim (and_imp.2 mul_nonneg) (and_imp.2 mul_nonneg_of_nonpos_of_nonpos)\u27e9\n\nlemma mul_nonpos_iff : a * b \u2264 0 \u2194 0 \u2264 a \u2227 b \u2264 0 \u2228 a \u2264 0 \u2227 0 \u2264 b :=\nby rw [\u2190 neg_nonneg, neg_mul_eq_mul_neg, mul_nonneg_iff, neg_nonneg, neg_nonpos]\n\nlemma mul_self_nonneg (a : \u03b1) : 0 \u2264 a * a :=\nabs_mul_self a \u25b8 abs_nonneg _\n\n@[simp] lemma neg_le_self_iff : -a \u2264 a \u2194 0 \u2264 a :=\nby simp [neg_le_iff_add_nonneg, \u2190 two_mul, mul_nonneg_iff, zero_le_one, (@zero_lt_two \u03b1 _ _).not_le]\n\n@[simp] lemma neg_lt_self_iff : -a < a \u2194 0 < a :=\nby simp [neg_lt_iff_pos_add, \u2190 two_mul, mul_pos_iff, zero_lt_one, (@zero_lt_two \u03b1 _ _).not_lt]\n\n@[simp] lemma le_neg_self_iff : a \u2264 -a \u2194 a \u2264 0 :=\ncalc a \u2264 -a \u2194 -(-a) \u2264 -a : by rw neg_neg\n... \u2194 0 \u2264 -a : neg_le_self_iff\n... \u2194 a \u2264 0 : neg_nonneg\n\n@[simp] lemma lt_neg_self_iff : a < -a \u2194 a < 0 :=\ncalc a < -a \u2194 -(-a) < -a : by rw neg_neg\n... \u2194 0 < -a : neg_lt_self_iff\n... \u2194 a < 0 : neg_pos\n\n@[simp] lemma abs_eq_self : abs a = a \u2194 0 \u2264 a := by simp [abs]\n\n@[simp] lemma abs_eq_neg_self : abs a = -a \u2194 a \u2264 0 := by simp [abs]\n\nlemma gt_of_mul_lt_mul_neg_left (h : c * a < c * b) (hc : c \u2264 0) : b < a :=\nhave nhc : 0 \u2264 -c, from neg_nonneg_of_nonpos hc,\nhave h2 : -(c * b) < -(c * a), from neg_lt_neg h,\nhave h3 : (-c) * b < (-c) * a, from calc\n     (-c) * b = - (c * b)    : by rewrite neg_mul_eq_neg_mul\n          ... < -(c * a)     : h2\n          ... = (-c) * a     : by rewrite neg_mul_eq_neg_mul,\nlt_of_mul_lt_mul_left h3 nhc\n\nlemma neg_one_lt_zero : -1 < (0:\u03b1) := neg_lt_zero.2 zero_lt_one\n\nlemma le_of_mul_le_of_one_le {a b c : \u03b1} (h : a * c \u2264 b) (hb : 0 \u2264 b) (hc : 1 \u2264 c) :\n  a \u2264 b :=\nhave h' : a * c \u2264 b * c, from calc\n     a * c \u2264 b : h\n       ... = b * 1 : by rewrite mul_one\n       ... \u2264 b * c : mul_le_mul_of_nonneg_left hc hb,\nle_of_mul_le_mul_right h' (zero_lt_one.trans_le hc)\n\nlemma nonneg_le_nonneg_of_sq_le_sq {a b : \u03b1} (hb : 0 \u2264 b) (h : a * a \u2264 b * b) : a \u2264 b :=\nle_of_not_gt (\u03bbhab, (mul_self_lt_mul_self hb hab).not_le h)\n\nlemma mul_self_le_mul_self_iff {a b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a \u2264 b \u2194 a * a \u2264 b * b :=\n\u27e8mul_self_le_mul_self h1, nonneg_le_nonneg_of_sq_le_sq h2\u27e9\n\nlemma mul_self_lt_mul_self_iff {a b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a < b \u2194 a * a < b * b :=\n((@strict_mono_incr_on_mul_self \u03b1 _).lt_iff_lt h1 h2).symm\n\nlemma mul_self_inj {a b : \u03b1} (h1 : 0 \u2264 a) (h2 : 0 \u2264 b) : a * a = b * b \u2194 a = b :=\n(@strict_mono_incr_on_mul_self \u03b1 _).inj_on.eq_iff h1 h2\n\n@[simp] lemma mul_le_mul_left_of_neg {a b c : \u03b1} (h : c < 0) : c * a \u2264 c * b \u2194 b \u2264 a :=\n\u27e8le_imp_le_of_lt_imp_lt $ \u03bb h', mul_lt_mul_of_neg_left h' h,\n  \u03bb h', mul_le_mul_of_nonpos_left h' h.le\u27e9\n\n@[simp] lemma mul_le_mul_right_of_neg {a b c : \u03b1} (h : c < 0) : a * c \u2264 b * c \u2194 b \u2264 a :=\n\u27e8le_imp_le_of_lt_imp_lt $ \u03bb h', mul_lt_mul_of_neg_right h' h,\n  \u03bb h', mul_le_mul_of_nonpos_right h' h.le\u27e9\n\n@[simp] lemma mul_lt_mul_left_of_neg {a b c : \u03b1} (h : c < 0) : c * a < c * b \u2194 b < a :=\nlt_iff_lt_of_le_iff_le (mul_le_mul_left_of_neg h)\n\n@[simp] lemma mul_lt_mul_right_of_neg {a b c : \u03b1} (h : c < 0) : a * c < b * c \u2194 b < a :=\nlt_iff_lt_of_le_iff_le (mul_le_mul_right_of_neg h)\n\nlemma sub_one_lt (a : \u03b1) : a - 1 < a :=\nsub_lt_iff_lt_add.2 (lt_add_one a)\n\nlemma mul_self_pos {a : \u03b1} (ha : a \u2260 0) : 0 < a * a :=\nby rcases lt_trichotomy a 0 with h|h|h;\n   [exact mul_pos_of_neg_of_neg h h, exact (ha h).elim, exact mul_pos h h]\n\nlemma mul_self_le_mul_self_of_le_of_neg_le {x y : \u03b1} (h\u2081 : x \u2264 y) (h\u2082 : -x \u2264 y) : x * x \u2264 y * y :=\nbegin\n  rw [\u2190 abs_mul_abs_self x],\n  exact mul_self_le_mul_self (abs_nonneg x) (abs_le.2 \u27e8neg_le.2 h\u2082, h\u2081\u27e9)\nend\n\nlemma nonneg_of_mul_nonpos_left {a b : \u03b1} (h : a * b \u2264 0) (hb : b < 0) : 0 \u2264 a :=\nle_of_not_gt (\u03bb ha, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)\n\nlemma nonneg_of_mul_nonpos_right {a b : \u03b1} (h : a * b \u2264 0) (ha : a < 0) : 0 \u2264 b :=\nle_of_not_gt (\u03bb hb, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)\n\nlemma pos_of_mul_neg_left {a b : \u03b1} (h : a * b < 0) (hb : b \u2264 0) : 0 < a :=\nlt_of_not_ge (\u03bb ha, absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)\n\nlemma pos_of_mul_neg_right {a b : \u03b1} (h : a * b < 0) (ha : a \u2264 0) : 0 < b :=\nlt_of_not_ge (\u03bb hb, absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)\n\n/-- The sum of two squares is zero iff both elements are zero. -/\nlemma mul_self_add_mul_self_eq_zero {x y : \u03b1} : x * x + y * y = 0 \u2194 x = 0 \u2227 y = 0 :=\nby rw [add_eq_zero_iff', mul_self_eq_zero, mul_self_eq_zero]; apply mul_self_nonneg\n\nlemma eq_zero_of_mul_self_add_mul_self_eq_zero (h : a * a + b * b = 0) : a = 0 :=\n(mul_self_add_mul_self_eq_zero.mp h).left\n\nlemma abs_eq_iff_mul_self_eq : abs a = abs b \u2194 a * a = b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm,\nend\n\nlemma abs_lt_iff_mul_self_lt : abs a < abs b \u2194 a * a < b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)\nend\n\nlemma abs_le_iff_mul_self_le : abs a \u2264 abs b \u2194 a * a \u2264 b * b :=\nbegin\n  rw [\u2190 abs_mul_abs_self, \u2190 abs_mul_abs_self b],\n  exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)\nend\n\nlemma abs_le_one_iff_mul_self_le_one : abs a \u2264 1 \u2194 a * a \u2264 1 :=\nby simpa only [abs_one, one_mul] using @abs_le_iff_mul_self_le \u03b1 _ a 1\n\n/-- Pullback a `linear_ordered_ring` under an injective map. -/\ndef function.injective.linear_ordered_ring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2] [nontrivial \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  linear_ordered_ring \u03b2 :=\n{ ..linear_order.lift f hf,\n  ..\u2039nontrivial \u03b2\u203a,\n  ..hf.ordered_ring f zero one add mul neg sub }\n\nend linear_ordered_ring\n\n/-- A `linear_ordered_comm_ring \u03b1` is a commutative ring `\u03b1` with a linear order\nsuch that multiplication with a positive number and addition are monotone. -/\n@[protect_proj]\nclass linear_ordered_comm_ring (\u03b1 : Type u) extends linear_ordered_ring \u03b1, comm_monoid \u03b1\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_comm_ring.to_ordered_comm_ring [d : linear_ordered_comm_ring \u03b1] :\n  ordered_comm_ring \u03b1 :=\n-- One might hope that `{ ..linear_ordered_ring.to_linear_ordered_semiring, ..d }`\n-- achieved the same result here.\n-- Unfortunately with that definition we see mismatched instances in `algebra.star.chsh`.\nlet s : linear_ordered_semiring \u03b1 := @linear_ordered_ring.to_linear_ordered_semiring \u03b1 _ in\n{ zero_mul                   := @linear_ordered_semiring.zero_mul \u03b1 s,\n  mul_zero                   := @linear_ordered_semiring.mul_zero \u03b1 s,\n  add_left_cancel            := @linear_ordered_semiring.add_left_cancel \u03b1 s,\n  le_of_add_le_add_left      := @linear_ordered_semiring.le_of_add_le_add_left \u03b1 s,\n  mul_lt_mul_of_pos_left     := @linear_ordered_semiring.mul_lt_mul_of_pos_left \u03b1 s,\n  mul_lt_mul_of_pos_right    := @linear_ordered_semiring.mul_lt_mul_of_pos_right \u03b1 s,\n  ..d }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_comm_ring.to_integral_domain [s : linear_ordered_comm_ring \u03b1] :\n  integral_domain \u03b1 :=\n{ ..linear_ordered_ring.to_domain, ..s }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_comm_ring.to_linear_ordered_semiring [d : linear_ordered_comm_ring \u03b1] :\n   linear_ordered_semiring \u03b1 :=\n-- One might hope that `{ ..linear_ordered_ring.to_linear_ordered_semiring, ..d }`\n-- achieved the same result here.\n-- Unfortunately with that definition we see mismatched `preorder \u211d` instances in\n-- `topology.metric_space.basic`.\nlet s : linear_ordered_semiring \u03b1 := @linear_ordered_ring.to_linear_ordered_semiring \u03b1 _ in\n{ zero_mul                   := @linear_ordered_semiring.zero_mul \u03b1 s,\n  mul_zero                   := @linear_ordered_semiring.mul_zero \u03b1 s,\n  add_left_cancel            := @linear_ordered_semiring.add_left_cancel \u03b1 s,\n  le_of_add_le_add_left      := @linear_ordered_semiring.le_of_add_le_add_left \u03b1 s,\n  mul_lt_mul_of_pos_left     := @linear_ordered_semiring.mul_lt_mul_of_pos_left \u03b1 s,\n  mul_lt_mul_of_pos_right    := @linear_ordered_semiring.mul_lt_mul_of_pos_right \u03b1 s,\n  ..d }\n\nsection linear_ordered_comm_ring\n\nvariables [linear_ordered_comm_ring \u03b1] {a b c d : \u03b1}\n\nlemma max_mul_mul_le_max_mul_max (b c : \u03b1) (ha : 0 \u2264 a) (hd: 0 \u2264 d) :\n  max (a * b) (d * c) \u2264 max a c * max d b :=\nhave ba : b * a \u2264 max d b * max c a,\n  from mul_le_mul (le_max_right d b) (le_max_right c a) ha (le_trans hd (le_max_left d b)),\nhave cd : c * d \u2264 max a c * max b d,\n  from mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c)),\nmax_le\n  (by simpa [mul_comm, max_comm] using ba)\n  (by simpa [mul_comm, max_comm] using cd)\n\nlemma abs_sub_sq (a b : \u03b1) : abs (a - b) * abs (a - b) = a * a + b * b - (1 + 1) * a * b :=\nbegin\n  rw abs_mul_abs_self,\n  simp [left_distrib, right_distrib, add_assoc, add_comm, add_left_comm, mul_comm, sub_eq_add_neg],\nend\n\n/-- Pullback a `linear_ordered_comm_ring` under an injective map. -/\ndef function.injective.linear_ordered_comm_ring {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2] [nontrivial \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y) :\n  linear_ordered_comm_ring \u03b2 :=\n{ ..linear_order.lift f hf,\n  ..\u2039nontrivial \u03b2\u203a,\n  ..hf.ordered_comm_ring f zero one add mul neg sub }\n\nend linear_ordered_comm_ring\n\n/-- Extend `nonneg_add_comm_group` to support ordered rings\n  specified by their nonnegative elements -/\nclass nonneg_ring (\u03b1 : Type*) extends ring \u03b1, nonneg_add_comm_group \u03b1 :=\n(one_nonneg : nonneg 1)\n(mul_nonneg : \u2200 {a b}, nonneg a \u2192 nonneg b \u2192 nonneg (a * b))\n(mul_pos : \u2200 {a b}, pos a \u2192 pos b \u2192 pos (a * b))\n\n/-- Extend `nonneg_add_comm_group` to support linearly ordered rings\n  specified by their nonnegative elements -/\nclass linear_nonneg_ring (\u03b1 : Type*) extends domain \u03b1, nonneg_add_comm_group \u03b1 :=\n(one_pos : pos 1)\n(mul_nonneg : \u2200 {a b}, nonneg a \u2192 nonneg b \u2192 nonneg (a * b))\n(nonneg_total : \u2200 a, nonneg a \u2228 nonneg (-a))\n\nnamespace nonneg_ring\nopen nonneg_add_comm_group\nvariable [nonneg_ring \u03b1]\n\n/-- `to_linear_nonneg_ring` shows that a `nonneg_ring` with a total order is a `domain`,\nhence a `linear_nonneg_ring`. -/\ndef to_linear_nonneg_ring [nontrivial \u03b1]\n  (nonneg_total : \u2200 a : \u03b1, nonneg a \u2228 nonneg (-a))\n  : linear_nonneg_ring \u03b1 :=\n{ one_pos := (pos_iff 1).mpr \u27e8one_nonneg, \u03bb h, zero_ne_one (nonneg_antisymm one_nonneg h).symm\u27e9,\n  nonneg_total := nonneg_total,\n  eq_zero_or_eq_zero_of_mul_eq_zero :=\n    suffices \u2200 {a} b : \u03b1, nonneg a \u2192 a * b = 0 \u2192 a = 0 \u2228 b = 0,\n    from \u03bb a b, (nonneg_total a).elim (this b)\n      (\u03bb na, by simpa using this b na),\n    suffices \u2200 {a b : \u03b1}, nonneg a \u2192 nonneg b \u2192 a * b = 0 \u2192 a = 0 \u2228 b = 0,\n    from \u03bb a b na, (nonneg_total b).elim (this na)\n      (\u03bb nb, by simpa using this na nb),\n    \u03bb a b na nb z, classical.by_cases\n      (\u03bb nna : nonneg (-a), or.inl (nonneg_antisymm na nna))\n      (\u03bb pa, classical.by_cases\n        (\u03bb nnb : nonneg (-b), or.inr (nonneg_antisymm nb nnb))\n        (\u03bb pb, absurd z $ ne_of_gt $ pos_def.1 $ mul_pos\n          ((pos_iff _).2 \u27e8na, pa\u27e9)\n          ((pos_iff _).2 \u27e8nb, pb\u27e9))),\n  ..\u2039nontrivial \u03b1\u203a,\n  ..\u2039nonneg_ring \u03b1\u203a }\n\nend nonneg_ring\n\nnamespace linear_nonneg_ring\nopen nonneg_add_comm_group\nvariable [linear_nonneg_ring \u03b1]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_nonneg_ring : nonneg_ring \u03b1 :=\n{ one_nonneg := ((pos_iff _).mp one_pos).1,\n  mul_pos := \u03bb a b pa pb,\n  let \u27e8a1, a2\u27e9 := (pos_iff a).1 pa,\n      \u27e8b1, b2\u27e9 := (pos_iff b).1 pb in\n  have ab : nonneg (a * b), from mul_nonneg a1 b1,\n  (pos_iff _).2 \u27e8ab, \u03bb hn,\n    have a * b = 0, from nonneg_antisymm ab hn,\n    (eq_zero_or_eq_zero_of_mul_eq_zero _ _ this).elim\n      (ne_of_gt (pos_def.1 pa))\n      (ne_of_gt (pos_def.1 pb))\u27e9,\n  ..\u2039linear_nonneg_ring \u03b1\u203a }\n\n/-- Construct `linear_order` from `linear_nonneg_ring`. This is not an instance\nbecause we don't use it in `mathlib`. -/\nlocal attribute [instance]\ndef to_linear_order [decidable_pred (nonneg : \u03b1 \u2192 Prop)] : linear_order \u03b1 :=\n{ le_total := nonneg_total_iff.1 nonneg_total,\n  decidable_le := by apply_instance,\n  decidable_lt := by apply_instance,\n  ..\u2039linear_nonneg_ring \u03b1\u203a, ..(infer_instance : ordered_add_comm_group \u03b1) }\n\n/-- Construct `linear_ordered_ring` from `linear_nonneg_ring`.\nThis is not an instance because we don't use it in `mathlib`. -/\nlocal attribute [instance]\ndef to_linear_ordered_ring [decidable_pred (nonneg : \u03b1 \u2192 Prop)] : linear_ordered_ring \u03b1 :=\n{ mul_pos := by simp [pos_def.symm]; exact @nonneg_ring.mul_pos _ _,\n  zero_le_one := le_of_lt $ lt_of_not_ge $ \u03bb (h : nonneg (0 - 1)), begin\n    rw [zero_sub] at h,\n    have := mul_nonneg h h, simp at this,\n    exact zero_ne_one (nonneg_antisymm this h).symm\n  end,\n  ..\u2039linear_nonneg_ring \u03b1\u203a, ..(infer_instance : ordered_add_comm_group \u03b1),\n  ..(infer_instance : linear_order \u03b1) }\n\n/-- Convert a `linear_nonneg_ring` with a commutative multiplication and\ndecidable non-negativity into a `linear_ordered_comm_ring` -/\ndef to_linear_ordered_comm_ring\n  [decidable_pred (@nonneg \u03b1 _)]\n  [comm : @is_commutative \u03b1 (*)]\n  : linear_ordered_comm_ring \u03b1 :=\n{ mul_comm := is_commutative.comm,\n  ..@linear_nonneg_ring.to_linear_ordered_ring _ _ _ }\n\nend linear_nonneg_ring\n\n/-- A canonically ordered commutative semiring is an ordered, commutative semiring\nin which `a \u2264 b` iff there exists `c` with `b = a + c`. This is satisfied by the\nnatural numbers, for example, but not the integers or other ordered groups. -/\n@[protect_proj]\nclass canonically_ordered_comm_semiring (\u03b1 : Type*) extends\n  canonically_ordered_add_monoid \u03b1, comm_semiring \u03b1 :=\n(eq_zero_or_eq_zero_of_mul_eq_zero : \u2200 a b : \u03b1, a * b = 0 \u2192 a = 0 \u2228 b = 0)\n\nnamespace canonically_ordered_semiring\nvariables [canonically_ordered_comm_semiring \u03b1] {a b : \u03b1}\n\nopen canonically_ordered_add_monoid (le_iff_exists_add)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance canonically_ordered_comm_semiring.to_no_zero_divisors :\n  no_zero_divisors \u03b1 :=\n\u27e8canonically_ordered_comm_semiring.eq_zero_or_eq_zero_of_mul_eq_zero\u27e9\n\nlemma mul_le_mul {a b c d : \u03b1} (hab : a \u2264 b) (hcd : c \u2264 d) : a * c \u2264 b * d :=\nbegin\n  rcases (le_iff_exists_add _ _).1 hab with \u27e8b, rfl\u27e9,\n  rcases (le_iff_exists_add _ _).1 hcd with \u27e8d, rfl\u27e9,\n  suffices : a * c \u2264 a * c + (a * d + b * c + b * d), by simpa [mul_add, add_mul, add_assoc],\n  exact (le_iff_exists_add _ _).2 \u27e8_, rfl\u27e9\nend\n\nlemma mul_le_mul_left' {b c : \u03b1} (h : b \u2264 c) (a : \u03b1) : a * b \u2264 a * c :=\nmul_le_mul le_rfl h\n\nlemma mul_le_mul_right' {b c : \u03b1} (h : b \u2264 c) (a : \u03b1) : b * a \u2264 c * a :=\nmul_le_mul h le_rfl\n\n/-- A version of `zero_lt_one : 0 < 1` for a `canonically_ordered_comm_semiring`. -/\nlemma zero_lt_one [nontrivial \u03b1] : (0:\u03b1) < 1 := (zero_le 1).lt_of_ne zero_ne_one\n\nlemma mul_pos : 0 < a * b \u2194 (0 < a) \u2227 (0 < b) :=\nby simp only [pos_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib]\n\nend canonically_ordered_semiring\n\nnamespace with_top\n\ninstance [nonempty \u03b1] : nontrivial (with_top \u03b1) :=\noption.nontrivial\n\nvariable [decidable_eq \u03b1]\n\nsection has_mul\n\nvariables [has_zero \u03b1] [has_mul \u03b1]\n\ninstance : mul_zero_class (with_top \u03b1) :=\n{ zero := 0,\n  mul := \u03bbm n, if m = 0 \u2228 n = 0 then 0 else m.bind (\u03bba, n.bind $ \u03bbb, \u2191(a * b)),\n  zero_mul := assume a, if_pos $ or.inl rfl,\n  mul_zero := assume a, if_pos $ or.inr rfl }\n\nlemma mul_def {a b : with_top \u03b1} :\n  a * b = if a = 0 \u2228 b = 0 then 0 else a.bind (\u03bba, b.bind $ \u03bbb, \u2191(a * b)) := rfl\n\n@[simp] lemma mul_top {a : with_top \u03b1} (h : a \u2260 0) : a * \u22a4 = \u22a4 :=\nby cases a; simp [mul_def, h]; refl\n\n@[simp] lemma top_mul {a : with_top \u03b1} (h : a \u2260 0) : \u22a4 * a = \u22a4 :=\nby cases a; simp [mul_def, h]; refl\n\n@[simp] lemma top_mul_top : (\u22a4 * \u22a4 : with_top \u03b1) = \u22a4 :=\ntop_mul top_ne_zero\n\nend has_mul\n\nsection mul_zero_class\n\nvariables [mul_zero_class \u03b1]\n\n@[norm_cast] lemma coe_mul {a b : \u03b1} : (\u2191(a * b) : with_top \u03b1) = a * b :=\ndecidable.by_cases (assume : a = 0, by simp [this]) $ assume ha,\ndecidable.by_cases (assume : b = 0, by simp [this]) $ assume hb,\nby { simp [*, mul_def], refl }\n\nlemma mul_coe {b : \u03b1} (hb : b \u2260 0) : \u2200{a : with_top \u03b1}, a * b = a.bind (\u03bba:\u03b1, \u2191(a * b))\n| none     := show (if (\u22a4:with_top \u03b1) = 0 \u2228 (b:with_top \u03b1) = 0 then 0 else \u22a4 : with_top \u03b1) = \u22a4,\n    by simp [hb]\n| (some a) := show \u2191a * \u2191b = \u2191(a * b), from coe_mul.symm\n\n@[simp] lemma mul_eq_top_iff {a b : with_top \u03b1} : a * b = \u22a4 \u2194 (a \u2260 0 \u2227 b = \u22a4) \u2228 (a = \u22a4 \u2227 b \u2260 0) :=\nbegin\n  cases a; cases b; simp only [none_eq_top, some_eq_coe],\n  { simp [\u2190 coe_mul] },\n  { suffices : \u22a4 * (b : with_top \u03b1) = \u22a4 \u2194 b \u2260 0, by simpa,\n    by_cases hb : b = 0; simp [hb] },\n  { suffices : (a : with_top \u03b1) * \u22a4 = \u22a4 \u2194 a \u2260 0, by simpa,\n    by_cases ha : a = 0; simp [ha] },\n  { simp [\u2190 coe_mul] }\nend\n\nend mul_zero_class\n\nsection no_zero_divisors\n\nvariables [mul_zero_class \u03b1] [no_zero_divisors \u03b1]\n\ninstance : no_zero_divisors (with_top \u03b1) :=\n\u27e8\u03bb a b, by cases a; cases b; dsimp [mul_def]; split_ifs;\n  simp [*, none_eq_top, some_eq_coe, mul_eq_zero] at *\u27e9\n\nend no_zero_divisors\n\nvariables [canonically_ordered_comm_semiring \u03b1]\n\nprivate lemma comm (a b : with_top \u03b1) : a * b = b * a :=\nbegin\n  by_cases ha : a = 0, { simp [ha] },\n  by_cases hb : b = 0, { simp [hb] },\n  simp [ha, hb, mul_def, option.bind_comm a b, mul_comm]\nend\n\nprivate lemma distrib' (a b c : with_top \u03b1) : (a + b) * c = a * c + b * c :=\nbegin\n  cases c,\n  { show (a + b) * \u22a4 = a * \u22a4 + b * \u22a4,\n    by_cases ha : a = 0; simp [ha] },\n  { show (a + b) * c = a * c + b * c,\n    by_cases hc : c = 0, { simp [hc] },\n    simp [mul_coe hc], cases a; cases b,\n    repeat { refl <|> exact congr_arg some (add_mul _ _ _) } }\nend\n\nprivate lemma assoc (a b c : with_top \u03b1) : (a * b) * c = a * (b * c) :=\nbegin\n  cases a,\n  { by_cases hb : b = 0; by_cases hc : c = 0;\n      simp [*, none_eq_top] },\n  cases b,\n  { by_cases ha : a = 0; by_cases hc : c = 0;\n      simp [*, none_eq_top, some_eq_coe] },\n  cases c,\n  { by_cases ha : a = 0; by_cases hb : b = 0;\n      simp [*, none_eq_top, some_eq_coe] },\n  simp [some_eq_coe, coe_mul.symm, mul_assoc]\nend\n\n-- `nontrivial \u03b1` is needed here as otherwise\n-- we have `1 * \u22a4 = \u22a4` but also `= 0 * \u22a4 = 0`.\nprivate lemma one_mul' [nontrivial \u03b1] : \u2200a : with_top \u03b1, 1 * a = a\n| none     := show ((1:\u03b1) : with_top \u03b1) * \u22a4 = \u22a4, by simp [-with_top.coe_one]\n| (some a) := show ((1:\u03b1) : with_top \u03b1) * a = a, by simp [coe_mul.symm, -with_top.coe_one]\n\ninstance [nontrivial \u03b1] : canonically_ordered_comm_semiring (with_top \u03b1) :=\n{ one             := (1 : \u03b1),\n  right_distrib   := distrib',\n  left_distrib    := assume a b c, by rw [comm, distrib', comm b, comm c]; refl,\n  mul_assoc       := assoc,\n  mul_comm        := comm,\n  one_mul         := one_mul',\n  mul_one         := assume a, by rw [comm, one_mul'],\n  .. with_top.add_comm_monoid, .. with_top.mul_zero_class,\n  .. with_top.canonically_ordered_add_monoid,\n  .. with_top.no_zero_divisors, .. with_top.nontrivial }\n\nlemma mul_lt_top [nontrivial \u03b1] {a b : with_top \u03b1} (ha : a < \u22a4) (hb : b < \u22a4) : a * b < \u22a4 :=\nbegin\n  lift a to \u03b1 using ne_top_of_lt ha,\n  lift b to \u03b1 using ne_top_of_lt hb,\n  simp only [\u2190 coe_mul, coe_lt_top]\nend\n\nend with_top\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/ordered_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7152543657032036}}
{"text": "import linear_algebra.matrix.hermitian\nimport missing.linear_algebra.matrix.nonsingular_inverse\n\nvariables {m n \u03b1 : Type*} \n\nnamespace matrix\nopen_locale matrix\nvariables [ring \u03b1] [star_ring \u03b1]\n\nlemma is_hermitian_conj_transpose_mul_mul [fintype m] {A : matrix m m \u03b1} (B : matrix m n \u03b1)\n  (hA : A.is_hermitian) : (B\u1d34 \u2b1d A \u2b1d B).is_hermitian :=\nby simp only [is_hermitian, conj_transpose_mul, conj_transpose_conj_transpose, hA.eq,\n  matrix.mul_assoc]\n\nlemma is_hermitian_mul_mul_conj_transpose [fintype m] {A : matrix m m \u03b1} (B : matrix n m \u03b1)\n  (hA : A.is_hermitian) : (B \u2b1d A \u2b1d B\u1d34).is_hermitian :=\nby simp only [is_hermitian, conj_transpose_mul, conj_transpose_conj_transpose, hA.eq,\n  matrix.mul_assoc]\n\nlemma is_hermitian_transpose_iff (A : matrix n n \u03b1) :\n  A\u1d40.is_hermitian \u2194 A.is_hermitian :=\n\u27e8by { intro h, rw [\u2190 transpose_transpose A], exact is_hermitian.transpose h },\n  is_hermitian.transpose\u27e9\n\nlemma is_hermitian_conj_transpose_iff (A : matrix n n \u03b1) :\n  A\u1d34.is_hermitian \u2194 A.is_hermitian :=\n\u27e8by { intro h, rw [\u2190 conj_transpose_conj_transpose A], exact is_hermitian.conj_transpose h },\n  is_hermitian.conj_transpose\u27e9\n\n@[simp] lemma is_hermitian_submatrix_equiv {A : matrix n n \u03b1} (e : m \u2243 n) :\n  (A.submatrix e e).is_hermitian \u2194 A.is_hermitian :=\n\u27e8\u03bb h, by simpa using h.submatrix e.symm, \u03bb h, h.submatrix _\u27e9\n\n\nend matrix\n\nnamespace matrix\nopen_locale matrix\nsection comm_ring\n\nvariables [comm_ring \u03b1] [star_ring \u03b1]\n\nlemma is_hermitian.inv [fintype m] [decidable_eq m] {A : matrix m m \u03b1}\n  (hA : A.is_hermitian) : A\u207b\u00b9.is_hermitian :=\nby simp [is_hermitian, conj_transpose_nonsing_inv, hA.eq]\n\nlemma is_hermitian_inv [fintype m] [decidable_eq m] (A : matrix m m \u03b1) [invertible A]:\n  (A\u207b\u00b9).is_hermitian \u2194 A.is_hermitian :=\n\u27e8\u03bb h, by {rw [\u2190 inv_inv_of_invertible A], exact is_hermitian.inv h }, is_hermitian.inv\u27e9\n\nlemma is_hermitian.adjugate [fintype m] [decidable_eq m] {A : matrix m m \u03b1}\n  (hA : A.is_hermitian) : A.adjugate.is_hermitian :=\nby simp [is_hermitian, adjugate_conj_transpose, hA.eq]\n\nend comm_ring\n\nend matrix", "meta": {"author": "verified-optimization", "repo": "optlib", "sha": "b5d69678be5a4be8284ed15d376d6d973c64ea72", "save_path": "github-repos/lean/verified-optimization-optlib", "path": "github-repos/lean/verified-optimization-optlib/optlib-b5d69678be5a4be8284ed15d376d6d973c64ea72/src/missing/linear_algebra/matrix/hermitian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7152318149414489}}
{"text": "import tactic\nimport data.real.basic\n\n/- \nLean is a programming language which can be used to prove maths theorems.\n\nHere we will prove a theorem from 1st year analysis: \n\n  If `x\u2099 \u2192 s` and `y\u2099 \u2192 t` then `x\u2099 + y\u2099 \u2192 s + t`  \n\n(Don't worry if the code below doesn't mean anything to you, this example is\nsimply intended to show you what Lean can do.)\n\n-/\n\ndef limit (x : \u2115 \u2192 \u211d) (l : \u211d) : Prop := \n\u2200 \u03b5 > 0, \u2203 K, \u2200 n, n \u2265 K \u2192 |x n - l| < \u03b5 \n\n\ntheorem sum_limits (x y : \u2115 \u2192 \u211d) (s t : \u211d)  (hx : limit x s) (hy : limit y t) :\n  limit (\u03bb n, x n + y n) (s + t) :=\nbegin\n  intros \u03b5 h\u03b5,                     -- Given \u03b5 \u2208 \u211d satisyfing \u03b5 > 0\n  dsimp,                           -- simplify for the reader\n  specialize hx (\u03b5/2),             -- use the hypothesis x\u2099 \u2192 s with \u03b5/2\n  specialize hy (\u03b5/2),             -- use the hypothesis y\u2099 \u2192 t with \u03b5/2 \n  have : (\u03b5/2) > 0 := by linarith, -- need to check that \u03b5/2 > 0 \n  cases hx this with A hA,         -- obtain A \u2208 \u2115 using \u03b5/2 > 0 and x\u2099 \u2192 s\n  cases hy this with B hB,         -- obtain B \u2208 \u2115 using \u03b5/2 > 0 and y\u2099 \u2192 t\n  clear hx h\u03b5 hy this,             -- clear statements we no longer need\n  use max A B,                     -- use the max(A,B) as our \"K\"\n  intros n hn,                     -- given n \u2208 \u2115 with n \u2265 max(A,B) need to prove..\n  -- we can prove intermediate results and use them later\n  have AleM : A \u2264 max A B := le_max_left A B, -- A \u2264 max(A,B)\n  -- We now have `A \u2264 max(A,B)`and `max(A,B) \u2264 n` so Lean can deduce `A \u2264 n`\n  have Alen : A \u2264 n := by linarith,  \n  specialize hA n Alen, \n  specialize hB n (le_trans (le_max_right A B) hn), \n  -- Need to rearrange terms -- use the `ring` tactic \n  have rearrange: x(n) + y(n) - (s + t) = (x(n) - s) + (y(n) - t) := by ring,\n  rw rearrange,  -- rewrite this rearranged expression in the goal\n  -- Now apply triangle-inequality\n  have tri: |x(n) - s + (y(n) - t)| \u2264 |x(n) - s| + | y(n) - t| := abs_add _ _,\n  linarith, -- finally result follows from linear inequalities in our context.\nend\n\n-- #print sum_limits\n", "meta": {"author": "jt496", "repo": "Lean_Club", "sha": "391289884977a76dff5a0549f74742ca3d533fbb", "save_path": "github-repos/lean/jt496-Lean_Club", "path": "github-repos/lean/jt496-Lean_Club/Lean_Club-391289884977a76dff5a0549f74742ca3d533fbb/src/1_types_functions/example_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377237352755, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.7152023827917647}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n\n! This file was ported from Lean 3 source module topology.algebra.with_zero_topology\n! leanprover-community/mathlib commit 3e0c4d76b6ebe9dfafb67d16f7286d2731ed6064\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.WithZero\nimport Mathlib.Topology.Algebra.GroupWithZero\nimport Mathlib.Topology.Order.Basic\nimport Mathlib.Tactic.WLOG\n\n/-!\n# The topology on linearly ordered commutative groups with zero\n\nLet `\u0393\u2080` be a linearly ordered commutative group to which we have adjoined a zero element.  Then\n`\u0393\u2080` may naturally be endowed with a topology that turns `\u0393\u2080` into a topological monoid.\nNeighborhoods of zero are sets containing `{ \u03b3 | \u03b3 < \u03b3\u2080 }` for some invertible element `\u03b3\u2080` and\nevery invertible element is open.  In particular the topology is the following: \"a subset `U \u2286 \u0393\u2080`\nis open if `0 \u2209 U` or if there is an invertible `\u03b3\u2080 \u2208 \u0393\u2080` such that `{ \u03b3 | \u03b3 < \u03b3\u2080 } \u2286 U`\", see\n`WithZeroTopology.isOpen_iff`.\n\nWe prove this topology is ordered and T\u2085 (in addition to be compatible with the monoid\nstructure).\n\nAll this is useful to extend a valuation to a completion. This is an abstract version of how the\nabsolute value (resp. `p`-adic absolute value) on `\u211a` is extended to `\u211d` (resp. `\u211a\u209a`).\n\n## Implementation notes\n\nThis topology is defined as a scoped instance since it may not be the desired topology on\na linearly ordered commutative group with zero. You can locally activate this topology using\n`open WithZeroTopology`.\n-/\n\nopen Topology Filter TopologicalSpace Filter Set Function\n\nnamespace WithZeroTopology\n\nvariable {\u03b1 \u0393\u2080 : Type _} [LinearOrderedCommGroupWithZero \u0393\u2080] {\u03b3 \u03b3\u2081 \u03b3\u2082 : \u0393\u2080} {l : Filter \u03b1}\n  {f : \u03b1 \u2192 \u0393\u2080}\n\n/-- The topology on a linearly ordered commutative group with a zero element adjoined.\nA subset U is open if 0 \u2209 U or if there is an invertible element \u03b3\u2080 such that {\u03b3 | \u03b3 < \u03b3\u2080} \u2286 U. -/\nscoped instance (priority := 100) topologicalSpace : TopologicalSpace \u0393\u2080 :=\n  TopologicalSpace.mkOfNhds <| update pure 0 <| \u2a05 (\u03b3) (_h : \u03b3 \u2260 0), \ud835\udcdf (Iio \u03b3)\n#align with_zero_topology.topological_space WithZeroTopology.topologicalSpace\n\ntheorem nhds_eq_update : (\ud835\udcdd : \u0393\u2080 \u2192 Filter \u0393\u2080) = update pure 0 (\u2a05 (\u03b3) (_h : \u03b3 \u2260 0), \ud835\udcdf (Iio \u03b3)) :=\n  funext <| nhds_mkOfNhds_single <| le_inf\u1d62\u2082 fun _ h\u2080 => le_principal_iff.2 <| zero_lt_iff.2 h\u2080\n#align with_zero_topology.nhds_eq_update WithZeroTopology.nhds_eq_update\n\n/-!\n### Neighbourhoods of zero\n-/\n\ntheorem nhds_zero : \ud835\udcdd (0 : \u0393\u2080) = \u2a05 (\u03b3) (_h : \u03b3 \u2260 0), \ud835\udcdf (Iio \u03b3) := by\n  rw [nhds_eq_update, update_same]\n#align with_zero_topology.nhds_zero WithZeroTopology.nhds_zero\n\n/-- In a linearly ordered group with zero element adjoined, `U` is a neighbourhood of `0` if and\nonly if there exists a nonzero element `\u03b3\u2080` such that `Iio \u03b3\u2080 \u2286 U`. -/\ntheorem hasBasis_nhds_zero : (\ud835\udcdd (0 : \u0393\u2080)).HasBasis (fun \u03b3 : \u0393\u2080 => \u03b3 \u2260 0) Iio := by\n  rw [nhds_zero]\n  refine' hasBasis_binf\u1d62_principal _ \u27e81, one_ne_zero\u27e9\n  exact directedOn_iff_directed.2 (directed_of_inf fun a b hab => Iio_subset_Iio hab)\n#align with_zero_topology.has_basis_nhds_zero WithZeroTopology.hasBasis_nhds_zero\n\ntheorem Iio_mem_nhds_zero (h\u03b3 : \u03b3 \u2260 0) : Iio \u03b3 \u2208 \ud835\udcdd (0 : \u0393\u2080) :=\n  hasBasis_nhds_zero.mem_of_mem h\u03b3\n#align with_zero_topology.Iio_mem_nhds_zero WithZeroTopology.Iio_mem_nhds_zero\n\n/-- If `\u03b3` is an invertible element of a linearly ordered group with zero element adjoined, then\n`Iio (\u03b3 : \u0393\u2080)` is a neighbourhood of `0`. -/\ntheorem nhds_zero_of_units (\u03b3 : \u0393\u2080\u02e3) : Iio \u2191\u03b3 \u2208 \ud835\udcdd (0 : \u0393\u2080) :=\n  Iio_mem_nhds_zero \u03b3.ne_zero\n#align with_zero_topology.nhds_zero_of_units WithZeroTopology.nhds_zero_of_units\n\ntheorem tendsto_zero : Tendsto f l (\ud835\udcdd (0 : \u0393\u2080)) \u2194 \u2200 (\u03b3\u2080) (_ : \u03b3\u2080 \u2260 0), \u2200\u1da0 x in l, f x < \u03b3\u2080 := by\n  simp [nhds_zero]\n#align with_zero_topology.tendsto_zero WithZeroTopology.tendsto_zero\n\n/-!\n### Neighbourhoods of non-zero elements\n-/\n\n/-- The neighbourhood filter of a nonzero element consists of all sets containing that\nelement. -/\n@[simp]\ntheorem nhds_of_ne_zero {\u03b3 : \u0393\u2080} (h\u2080 : \u03b3 \u2260 0) : \ud835\udcdd \u03b3 = pure \u03b3 := by\n  rw [nhds_eq_update, update_noteq h\u2080]\n#align with_zero_topology.nhds_of_ne_zero WithZeroTopology.nhds_of_ne_zero\n\n/-- The neighbourhood filter of an invertible element consists of all sets containing that\nelement. -/\ntheorem nhds_coe_units (\u03b3 : \u0393\u2080\u02e3) : \ud835\udcdd (\u03b3 : \u0393\u2080) = pure (\u03b3 : \u0393\u2080) :=\n  nhds_of_ne_zero \u03b3.ne_zero\n#align with_zero_topology.nhds_coe_units WithZeroTopology.nhds_coe_units\n\n/-- If `\u03b3` is an invertible element of a linearly ordered group with zero element adjoined, then\n`{\u03b3}` is a neighbourhood of `\u03b3`. -/\ntheorem singleton_mem_nhds_of_units (\u03b3 : \u0393\u2080\u02e3) : ({\u2191\u03b3} : Set \u0393\u2080) \u2208 \ud835\udcdd (\u03b3 : \u0393\u2080) := by simp\n#align with_zero_topology.singleton_mem_nhds_of_units WithZeroTopology.singleton_mem_nhds_of_units\n\n/-- If `\u03b3` is a nonzero element of a linearly ordered group with zero element adjoined, then `{\u03b3}`\nis a neighbourhood of `\u03b3`. -/\ntheorem singleton_mem_nhds_of_ne_zero (h : \u03b3 \u2260 0) : ({\u03b3} : Set \u0393\u2080) \u2208 \ud835\udcdd (\u03b3 : \u0393\u2080) := by simp [h]\n#align with_zero_topology.singleton_mem_nhds_of_ne_zero WithZeroTopology.singleton_mem_nhds_of_ne_zero\n\ntheorem hasBasis_nhds_of_ne_zero {x : \u0393\u2080} (h : x \u2260 0) :\n    HasBasis (\ud835\udcdd x) (fun _ : Unit => True) fun _ => {x} := by\n  rw [nhds_of_ne_zero h]\n  exact hasBasis_pure _\n#align with_zero_topology.has_basis_nhds_of_ne_zero WithZeroTopology.hasBasis_nhds_of_ne_zero\n\ntheorem hasBasis_nhds_units (\u03b3 : \u0393\u2080\u02e3) :\n    HasBasis (\ud835\udcdd (\u03b3 : \u0393\u2080)) (fun _ : Unit => True) fun _ => {\u2191\u03b3} :=\n  hasBasis_nhds_of_ne_zero \u03b3.ne_zero\n#align with_zero_topology.has_basis_nhds_units WithZeroTopology.hasBasis_nhds_units\n\ntheorem tendsto_of_ne_zero {\u03b3 : \u0393\u2080} (h : \u03b3 \u2260 0) : Tendsto f l (\ud835\udcdd \u03b3) \u2194 \u2200\u1da0 x in l, f x = \u03b3 := by\n  rw [nhds_of_ne_zero h, tendsto_pure]\n#align with_zero_topology.tendsto_of_ne_zero WithZeroTopology.tendsto_of_ne_zero\n\ntheorem tendsto_units {\u03b3\u2080 : \u0393\u2080\u02e3} : Tendsto f l (\ud835\udcdd (\u03b3\u2080 : \u0393\u2080)) \u2194 \u2200\u1da0 x in l, f x = \u03b3\u2080 :=\n  tendsto_of_ne_zero \u03b3\u2080.ne_zero\n#align with_zero_topology.tendsto_units WithZeroTopology.tendsto_units\n\ntheorem Iio_mem_nhds (h : \u03b3\u2081 < \u03b3\u2082) : Iio \u03b3\u2082 \u2208 \ud835\udcdd \u03b3\u2081 := by\n  rcases eq_or_ne \u03b3\u2081 0 with (rfl | h\u2080) <;> simp [*, h.ne', Iio_mem_nhds_zero]\n#align with_zero_topology.Iio_mem_nhds WithZeroTopology.Iio_mem_nhds\n\n/-!\n### Open/closed sets\n-/\n\n\n\ntheorem isClosed_iff {s : Set \u0393\u2080} : IsClosed s \u2194 (0 : \u0393\u2080) \u2208 s \u2228 \u2203 \u03b3, \u03b3 \u2260 0 \u2227 s \u2286 Ici \u03b3 := by\n  simp only [\u2190 isOpen_compl_iff, isOpen_iff, mem_compl_iff, not_not, \u2190 compl_Ici,\n    compl_subset_compl]\n#align with_zero_topology.is_closed_iff WithZeroTopology.isClosed_iff\n\ntheorem isOpen_Iio {a : \u0393\u2080} : IsOpen (Iio a) :=\n  isOpen_iff.mpr <| imp_iff_not_or.mp fun ha => \u27e8a, ne_of_gt ha, Subset.rfl\u27e9\n#align with_zero_topology.is_open_Iio WithZeroTopology.isOpen_Iio\n\n/-!\n### Instances\n-/\n\n/-- The topology on a linearly ordered group with zero element adjoined is compatible with the order\nstructure: the set `{p : \u0393\u2080 \u00d7 \u0393\u2080 | p.1 \u2264 p.2}` is closed. -/\n@[nolint defLemma]\nscoped instance (priority := 100) orderClosedTopology : OrderClosedTopology \u0393\u2080 where\n  isClosed_le' := by\n    simp only [\u2190 isOpen_compl_iff, compl_setOf, not_le, isOpen_iff_mem_nhds]\n    rintro \u27e8a, b\u27e9 (hab : b < a)\n    rw [nhds_prod_eq, nhds_of_ne_zero (zero_le'.trans_lt hab).ne', pure_prod]\n    exact Iio_mem_nhds hab\n#align with_zero_topology.order_closed_topology WithZeroTopology.orderClosedTopology\n\n/-- The topology on a linearly ordered group with zero element adjoined is T\u2085. -/\n@[nolint defLemma]\nscoped instance (priority := 100) t5Space : T5Space \u0393\u2080 where\n  completely_normal := fun s t h\u2081 h\u2082 => by\n    by_cases hs : 0 \u2208 s\n    \u00b7 have ht : 0 \u2209 t := fun ht => disjoint_left.1 h\u2081 (subset_closure hs) ht\n      rwa [(isOpen_iff.2 (.inl ht)).nhdsSet_eq, disjoint_nhdsSet_principal]\n    \u00b7 rwa [(isOpen_iff.2 (.inl hs)).nhdsSet_eq, disjoint_principal_nhdsSet]\n\n/-- The topology on a linearly ordered group with zero element adjoined is T\u2083. -/\n@[deprecated t5Space] lemma t3Space : T3Space \u0393\u2080 := inferInstance\n#align with_zero_topology.t3_space WithZeroTopology.t3Space\n\n/-- The topology on a linearly ordered group with zero element adjoined makes it a topological\nmonoid. -/\n@[nolint defLemma]\nscoped instance (priority := 100) : ContinuousMul \u0393\u2080 where\n  continuous_mul := by\n    simp only [continuous_iff_continuousAt, ContinuousAt]\n    rintro \u27e8x, y\u27e9\n    wlog hle : x \u2264 y generalizing x y\n    \u00b7 have := (this y x (le_of_not_le hle)).comp (continuous_swap.tendsto (x, y))\n      simpa only [mul_comm, Function.comp, Prod.swap] using this\n    rcases eq_or_ne x 0 with (rfl | hx) <;> [rcases eq_or_ne y 0 with (rfl | hy), skip]\n    \u00b7 rw [zero_mul]\n      refine ((hasBasis_nhds_zero.prod_nhds hasBasis_nhds_zero).tendsto_iff hasBasis_nhds_zero).2\n        fun \u03b3 h\u03b3 => \u27e8(\u03b3, 1), \u27e8h\u03b3, one_ne_zero\u27e9, ?_\u27e9\n      rintro \u27e8x, y\u27e9 \u27e8hx : x < \u03b3, hy : y < 1\u27e9\n      exact (mul_lt_mul\u2080 hx hy).trans_eq (mul_one \u03b3)\n    \u00b7 rw [zero_mul, nhds_prod_eq, nhds_of_ne_zero hy, prod_pure, tendsto_map'_iff]\n      refine' (hasBasis_nhds_zero.tendsto_iff hasBasis_nhds_zero).2 fun \u03b3 h\u03b3 => _\n      refine' \u27e8\u03b3 / y, div_ne_zero h\u03b3 hy, fun x hx => _\u27e9\n      calc x * y < \u03b3 / y * y := mul_lt_right\u2080 _ hx hy\n      _ = \u03b3 := div_mul_cancel _ hy\n    \u00b7 have hy : y \u2260 0 := ((zero_lt_iff.mpr hx).trans_le hle).ne'\n      rw [nhds_prod_eq, nhds_of_ne_zero hx, nhds_of_ne_zero hy, prod_pure_pure]\n      exact pure_le_nhds (x * y)\n\n@[nolint defLemma]\nscoped instance (priority := 100) : HasContinuousInv\u2080 \u0393\u2080 :=\n  \u27e8fun \u03b3 h => by\n    rw [ContinuousAt, nhds_of_ne_zero h]\n    exact pure_le_nhds \u03b3\u207b\u00b9\u27e9\n\nend WithZeroTopology\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/Algebra/WithZeroTopology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7151891852555154}}
{"text": "variables {\u03b1 : Type*} (P : \u03b1 \u2192 Prop)\n\n/- Tactics you may consider\n-intro\n-exact\n-apply\n-by_contra\n-/\n\nexample (h : \u00ac \u2203 x, P x) : \u2200 x, \u00ac P x :=\nbegin \n  intro x,\n  by_contra h',\n  exact h \u27e8x, h'\u27e9,\nend\n\nexample (h : \u2200 x, \u00ac P x) : \u00ac \u2203 x, P x :=\nbegin\n  intro h,\n  cases h with x p,\n  exact h x p,\nend\n\nexample (h : \u00ac \u2200 x, P x) : \u2203 x, \u00ac P x :=\nbegin\n  by_contra h',\n  apply h,\n  intro x,\n  show P x,\n  by_contra h'',\n  exact h' \u27e8x, h''\u27e9, \nend\n\nexample (h : \u2203 x, \u00ac P x) : \u00ac \u2200 x, P x :=\nbegin\n  intro h',\n  cases h with x np,\n  exact np (h' x),\nend", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/9_Tactics used for classical reasoning/9.1_by_contra/ex2_np.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7151891771764973}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport data.finsupp.multiset\nimport data.multiset.antidiagonal\n\n/-!\n# The `finsupp` counterpart of `multiset.antidiagonal`.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe antidiagonal of `s : \u03b1 \u2192\u2080 \u2115` consists of\nall pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)` such that `t\u2081 + t\u2082 = s`.\n-/\n\nnoncomputable theory\nopen_locale classical big_operators\n\nnamespace finsupp\n\nopen finset\nvariables {\u03b1 : Type*}\n\n/-- The `finsupp` counterpart of `multiset.antidiagonal`: the antidiagonal of\n`s : \u03b1 \u2192\u2080 \u2115` consists of all pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)` such that `t\u2081 + t\u2082 = s`.\nThe finitely supported function `antidiagonal s` is equal to the multiplicities of these pairs. -/\ndef antidiagonal' (f : \u03b1 \u2192\u2080 \u2115) : ((\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)) \u2192\u2080 \u2115 :=\n(f.to_multiset.antidiagonal.map (prod.map multiset.to_finsupp multiset.to_finsupp)).to_finsupp\n\n/-- The antidiagonal of `s : \u03b1 \u2192\u2080 \u2115` is the finset of all pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)`\nsuch that `t\u2081 + t\u2082 = s`. -/\ndef antidiagonal (f : \u03b1 \u2192\u2080 \u2115) : finset ((\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)) :=\nf.antidiagonal'.support\n\n@[simp] lemma mem_antidiagonal {f : \u03b1 \u2192\u2080 \u2115} {p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)} :\n  p \u2208 antidiagonal f \u2194 p.1 + p.2 = f :=\nbegin\n  rcases p with \u27e8p\u2081, p\u2082\u27e9,\n  simp [antidiagonal, antidiagonal', \u2190 and.assoc, \u2190 finsupp.to_multiset.apply_eq_iff_eq]\nend\n\nlemma swap_mem_antidiagonal {n : \u03b1 \u2192\u2080 \u2115} {f : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)} :\n  f.swap \u2208 antidiagonal n \u2194 f \u2208 antidiagonal n :=\nby simp only [mem_antidiagonal, add_comm, prod.swap]\n\nlemma antidiagonal_filter_fst_eq (f g : \u03b1 \u2192\u2080 \u2115)\n  [D : \u03a0 (p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)), decidable (p.1 = g)] :\n  (antidiagonal f).filter (\u03bb p, p.1 = g) = if g \u2264 f then {(g, f - g)} else \u2205 :=\nbegin\n  ext \u27e8a, b\u27e9,\n  suffices : a = g \u2192 (a + b = f \u2194 g \u2264 f \u2227 b = f - g),\n  { simpa [apply_ite ((\u2208) (a, b)), \u2190 and.assoc, @and.right_comm _ (a = _), and.congr_left_iff] },\n  unfreezingI {rintro rfl}, split,\n  { rintro rfl, exact \u27e8le_add_right le_rfl, (add_tsub_cancel_left _ _).symm\u27e9 },\n  { rintro \u27e8h, rfl\u27e9, exact add_tsub_cancel_of_le h }\nend\n\nlemma antidiagonal_filter_snd_eq (f g : \u03b1 \u2192\u2080 \u2115)\n  [D : \u03a0 (p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)), decidable (p.2 = g)] :\n  (antidiagonal f).filter (\u03bb p, p.2 = g) = if g \u2264 f then {(f - g, g)} else \u2205 :=\nbegin\n  ext \u27e8a, b\u27e9,\n  suffices : b = g \u2192 (a + b = f \u2194 g \u2264 f \u2227 a = f - g),\n  { simpa [apply_ite ((\u2208) (a, b)), \u2190 and.assoc, and.congr_left_iff] },\n  unfreezingI {rintro rfl}, split,\n  { rintro rfl, exact \u27e8le_add_left le_rfl, (add_tsub_cancel_right _ _).symm\u27e9 },\n  { rintro \u27e8h, rfl\u27e9, exact tsub_add_cancel_of_le h }\nend\n\n@[simp] lemma antidiagonal_zero : antidiagonal (0 : \u03b1 \u2192\u2080 \u2115) = singleton (0,0) :=\nby rw [antidiagonal, antidiagonal', multiset.to_finsupp_support]; refl\n\n@[to_additive]\nlemma prod_antidiagonal_swap {M : Type*} [comm_monoid M] (n : \u03b1 \u2192\u2080 \u2115)\n  (f : (\u03b1 \u2192\u2080 \u2115) \u2192 (\u03b1 \u2192\u2080 \u2115) \u2192 M) :\n  \u220f p in antidiagonal n, f p.1 p.2 = \u220f p in antidiagonal n, f p.2 p.1 :=\nfinset.prod_bij (\u03bb p hp, p.swap) (\u03bb p, swap_mem_antidiagonal.2) (\u03bb p hp, rfl)\n  (\u03bb p\u2081 p\u2082 _ _ h, prod.swap_injective h)\n  (\u03bb p hp, \u27e8p.swap, swap_mem_antidiagonal.2 hp, p.swap_swap.symm\u27e9)\n\nend finsupp\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/finsupp/antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427860270573, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7151891752316452}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Kevin Buzzard\n\n! This file was ported from Lean 3 source module ring_theory.ideal.idempotent_fg\n! leanprover-community/mathlib commit 25cf7631da8ddc2d5f957c388bf5e4b25a77d8dc\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Ring.Idempotents\nimport Mathlib.RingTheory.Finiteness\n\n/-!\n## Lemmas on idempotent finitely generated ideals\n-/\n\n\nnamespace Ideal\n\n/-- A finitely generated idempotent ideal is generated by an idempotent element -/\ntheorem isIdempotentElem_iff_of_fg {R : Type _} [CommRing R] (I : Ideal R) (h : I.Fg) :\n    IsIdempotentElem I \u2194 \u2203 e : R, IsIdempotentElem e \u2227 I = R \u2219 e := by\n  constructor\n  \u00b7 intro e\n    obtain \u27e8r, hr, hr'\u27e9 :=\n      Submodule.exists_mem_and_smul_eq_self_of_fg_of_le_smul I I h\n        (by\n          rw [smul_eq_mul]\n          exact e.ge)\n    simp_rw [smul_eq_mul] at hr'\n    refine' \u27e8r, hr' r hr, antisymm _ ((Submodule.span_singleton_le_iff_mem _ _).mpr hr)\u27e9\n    intro x hx\n    rw [\u2190 hr' x hx]\n    exact Ideal.mem_span_singleton'.mpr \u27e8_, mul_comm _ _\u27e9\n  \u00b7 rintro \u27e8e, he, rfl\u27e9\n    simp [IsIdempotentElem, Ideal.span_singleton_mul_span_singleton, he.eq]\n#align ideal.is_idempotent_elem_iff_of_fg Ideal.isIdempotentElem_iff_of_fg\n\ntheorem isIdempotentElem_iff_eq_bot_or_top {R : Type _} [CommRing R] [IsDomain R] (I : Ideal R)\n    (h : I.Fg) : IsIdempotentElem I \u2194 I = \u22a5 \u2228 I = \u22a4 := by\n  constructor\n  \u00b7 intro H\n    obtain \u27e8e, he, rfl\u27e9 := (I.isIdempotentElem_iff_of_fg h).mp H\n    simp only [Ideal.submodule_span_eq, Ideal.span_singleton_eq_bot]\n    apply Or.imp id _ (IsIdempotentElem.iff_eq_zero_or_one.mp he)\n    rintro rfl\n    simp\n  \u00b7 rintro (rfl | rfl) <;> simp [IsIdempotentElem]\n#align ideal.is_idempotent_elem_iff_eq_bot_or_top Ideal.isIdempotentElem_iff_eq_bot_or_top\n\nend Ideal\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/Ideal/IdempotentFg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.715189173211891}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport order.upper_lower\nimport topology.separation\n\n/-!\n# Priestley spaces\n\nThis file defines Priestley spaces. A Priestley space is an ordered compact topological space such\nthat any two distinct points can be separated by a clopen upper set.\n\n## Main declarations\n\n* `priestley_space`: Prop-valued mixin stating the Priestley separation axiom: Any two distinct\n  points can be separated by a clopen upper set.\n\n## Implementation notes\n\nWe do not include compactness in the definition, so a Priestley space is to be declared as follows:\n`[preorder \u03b1] [topological_space \u03b1] [compact_space \u03b1] [priestley_space \u03b1]`\n\n## References\n\n* [Wikipedia, *Priestley space*](https://en.wikipedia.org/wiki/Priestley_space)\n* [Davey, Priestley *Introduction to Lattices and Order*][davey_priestley]\n-/\n\nopen set\n\nvariables {\u03b1 : Type*}\n\n/-- A Priestley space is an ordered topological space such that any two distinct points can be\nseparated by a clopen upper set. Compactness is often assumed, but we do not include it here. -/\nclass priestley_space (\u03b1 : Type*) [preorder \u03b1] [topological_space \u03b1] :=\n(priestley {x y : \u03b1} : \u00ac x \u2264 y \u2192 \u2203 U : set \u03b1, is_clopen U \u2227 is_upper_set U \u2227 x \u2208 U \u2227 y \u2209 U)\n\nvariables [topological_space \u03b1]\n\nsection preorder\nvariables [preorder \u03b1] [priestley_space \u03b1] {x y : \u03b1}\n\nlemma exists_clopen_upper_of_not_le :\n  \u00ac x \u2264 y \u2192 \u2203 U : set \u03b1, is_clopen U \u2227 is_upper_set U \u2227 x \u2208 U \u2227 y \u2209 U :=\npriestley_space.priestley\n\nlemma exists_clopen_lower_of_not_le (h : \u00ac x \u2264 y) :\n  \u2203 U : set \u03b1, is_clopen U \u2227 is_lower_set U \u2227 x \u2209 U \u2227 y \u2208 U :=\nlet \u27e8U, hU, hU', hx, hy\u27e9 := exists_clopen_upper_of_not_le h in\n  \u27e8U\u1d9c, hU.compl, hU'.compl, not_not.2 hx, hy\u27e9\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] [priestley_space \u03b1] {x y : \u03b1}\n\nlemma exists_clopen_upper_or_lower_of_ne (h : x \u2260 y) :\n  \u2203 U : set \u03b1, is_clopen U \u2227 (is_upper_set U \u2228 is_lower_set U) \u2227 x \u2208 U \u2227 y \u2209 U :=\nbegin\n  obtain (h | h) := h.not_le_or_not_le,\n  { exact (exists_clopen_upper_of_not_le h).imp (\u03bb U, and.imp_right $ and.imp_left or.inl) },\n  { obtain \u27e8U, hU, hU', hy, hx\u27e9 := exists_clopen_lower_of_not_le h,\n    exact \u27e8U, hU, or.inr hU', hx, hy\u27e9 }\nend\n\n@[priority 100] -- See note [lower instance priority]\ninstance priestley_space.to_t2_space : t2_space \u03b1 :=\n\u27e8\u03bb x y h, let \u27e8U, hU, _, hx, hy\u27e9 := exists_clopen_upper_or_lower_of_ne h in\n   \u27e8U, U\u1d9c, hU.is_open, hU.compl.is_open, hx, hy, inter_compl_self _\u27e9\u27e9\n\nend partial_order\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/topology/order/priestley.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7151536731656941}}
{"text": "import tactic\nimport group_theory.quotient_group\nimport group_theory.subgroup.basic\n\nnamespace my_group_iso\n\nvariables {G : Type} [group G]\n\n/-- f is the natural embedding of S in SN -/\ndef f {G : Type} [group G] {S N : subgroup G} [N.normal] :\n  S \u2192* (S \u2294 N : subgroup G) :=\n    subgroup.inclusion le_sup_left\n\n/-- g is the map from S to SN\u29f8N -/\ndef g {G : Type} [group G] (S N : subgroup G) [N.normal] :\n  S \u2192* (S \u2294 N : subgroup G)\u29f8(N.comap (S \u2294 N).subtype) :=\n    -- Composition of the map f: S \u2192 SN with the quotient homomorphism SN \u2192 SN/N\n    monoid_hom.comp (quotient_group.mk' (N.comap (S \u2294 N).subtype)) f\n\n/-- The group homomorphism g: S \u2192 SN\u29f8N is surjective\n  The proof is based on the one from mathlib -/\nlemma g_is_surjective {S N : subgroup G} [N.normal] :\n  function.surjective (g S N) :=\nbegin\n  rw function.surjective,\n  -- deconstruct \u2200\n  -- \u00b7 y : G\n  -- \u00b7 hypothesis y \u2208 SN\n  rintro \u27e8y, (hy : y \u2208 \u2191(S \u2294 N))\u27e9,\n  -- As N normal, y \u2208 (S \u2294 N) means y \u2208 S*N\n  rw subgroup.mul_normal S N at hy,\n  -- Deconstruct y \u2208 S*N\n  -- s,n : G such that s \u2208 S and n \u2208 N\n  -- s*n = y\n  -- rfl changes instances of y to s*n\n  rcases hy with \u27e8s, n, hs, hn, rfl\u27e9,\n  use s,\n  exact hs,\n  -- Pullback on the quotient map and move from g(s) to f(s)\n  apply quotient.eq.mpr,\n  -- I do not totally understand why it is definitionally equivalent to\n  change s\u207b\u00b9 * (s * n) \u2208 N,\n  -- Rebracket\n  rw \u2190 mul_assoc,\n  -- Cancel inverses\n  rw inv_mul_self,\n  -- simplify multiplication by identity\n  rw one_mul,\n  exact hn,\nend\n\n/- Proof that the kernel of g is S\u2229N -/\nlemma g_ker_eq_S_intersect_N (S N : subgroup G) [N.normal] :\n  ((g S N).ker : subgroup S) = (N.comap S.subtype) :=\nbegin\n  ext,\n  simp,\n  split, {\n    -- ker(g) \u2286 S\u2229N\n    -- x \u2208 ker(g)\n    intro hxk,\n    -- Being in the kernel is definitionally equal to sending an element\n    -- to the identity\n    change (g S N) x = 1 at hxk,\n    -- Simplify g(x) = 1 to f(x) = 1\n    dsimp [g] at hxk,\n    simp at hxk,\n    exact hxk,\n  }, {\n    -- S\u2229N \u2286 ker(g)\n    -- hx : x \u2208 N\n    intro hx,\n    -- Being in the kernel is definitionally equal to sending an element\n    -- to the identity\n    change (g S N) x = 1,\n    -- Simplify g(x) = 1 to f(x) = 1\n    dsimp [g],\n    simp,\n    exact hx,\n  }\nend\n\n/--!\n - # The second isomorphism theorem for groups\n - If S, N \u2264 G, and N is normal, then S\u29f8(S\u2229N) \u2245 (SN)\u29f8N\n -/\nnoncomputable def second_iso (S N : subgroup G) [N.normal]:\n  S \u29f8 (N.comap S.subtype) \u2243* (S \u2294 N : subgroup G) \u29f8 (N.comap (S \u2294 N).subtype) :=\nbegin\n  -- Get the isomorphism via the 1st isomorphism theorem where the LHS\n  -- is quotiented by the kernel of the surjective homomorphism\n  let e1 := quotient_group.quotient_ker_equiv_of_surjective (g S N) g_is_surjective,\n  -- Claim that S\u29f8(S\u2229N) \u2245 S\u29f8(ker(g))\n  have h : \u21a5S \u29f8 subgroup.comap S.subtype N \u2243* \u21a5S \u29f8 (g S N).ker,\n  let e2 := quotient_group.equiv_quotient_of_eq (g_ker_eq_S_intersect_N S N),\n  exact e2.symm,\n  -- Transitivity of isomorphisms\n  exact mul_equiv.trans h e1,\nend\n\nend my_group_iso", "meta": {"author": "Girgias", "repo": "lean-cw1", "sha": "2545bbe0b64f311b50ac41d35f40cf5608eadbc1", "save_path": "github-repos/lean/Girgias-lean-cw1", "path": "github-repos/lean/Girgias-lean-cw1/lean-cw1-2545bbe0b64f311b50ac41d35f40cf5608eadbc1/src/group-iso-thm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7151536719336191}}
{"text": "import tactic.ext linear_algebra.affine_space.basic\nimport algebra.module linear_algebra.basis\nimport .affine_coordinate_space \n\n\n/-\nThis file defines:\n\n(1) a generic affine frame: an origin in X and a basis for V.\n(2) new types that wrap values in X and V with a polymorphic frame argument \n(3) lifting of operations on points and vectors to this derived type\n(4) a proof that the lifted point and vector objects for an affine space\n-/\n\nnamespace affine_frame\n\nuniverses u v w x\n\nvariables \n    (X : Type u) \n    (K : Type v) \n    (V : Type w) \n    (n : \u2115) \n    (k : K)\n    (\u03b9 : Type*)\n    (s : finset \u03b9) \n    (g : \u03b9 \u2192 K) \n    (v : \u03b9 \u2192 V) \n    [inhabited K] \n    [field K] \n    [add_comm_group V] \n    [module K V] \n    [vector_space K V] \n    [affine_space V X]\n    [is_basis K v] \n    [affine_space V X]\n\nopen vecl\n\n/-\nAn affine frame comprises an origin point\nand a basis for the vector space.\n-/\nstructure affine_frame :=\n(origin : X)\n(basis : \u03b9 \u2192 V)\n(proof_is_basis : is_basis K basis)\n\n/-\nCode to manufacture a standard basis for a given affine space.\n-/\nabbreviation zero := zero_vector K n\n\ndef list.to_basis_vec : fin n \u2192 list K := \u03bb x, (zero K n).update_nth (x.1 + 1) 1\n\nlemma len_basis_vec_fixed (x : fin n) : (list.to_basis_vec K n x).length = n + 1 := sorry\n\nlemma head_basis_vec_fixed (x : fin n) : (list.to_basis_vec K n x).head = 0 := sorry\n\ndef std_basis : fin n \u2192 aff_vec_coord_tuple K n :=\n\u03bb x, \u27e8list.to_basis_vec K n x, len_basis_vec_fixed K n x, head_basis_vec_fixed K n x\u27e9\n\nlemma std_is_basis : is_basis K (std_basis K n) := sorry\n\n/-\nHere we equip any generic affine coordinate space with a standard frame\n-/\ndef aff_coord_space_std_frame : \n    affine_frame (aff_pt_coord_tuple K n) K (aff_vec_coord_tuple K n) (fin n) := \n        \u27e8pt_zero K n, std_basis K n, std_is_basis K n\u27e9\n\nend affine_frame\n\n\n\n\n\n", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/old/old_affine/affine_frame.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7151536717335865}}
{"text": "import data.real.basic data.set.intervals.basic\n\nopen set\n\ndef continuous_at (f : \u211d \u2192 \u211d) (a : \u211d) :=\n  \u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, abs (x - a) < \u03b4 \u2192 abs (f x - f a) < \u03b5\n\ntheorem continuous_function_about_an_open_interval {f a}\n  (hcont : continuous_at f a) (hgt : f a > 0) :\n  \u2203 b c : \u211d, a \u2208 Ioo b c \u2227 \u2200 x \u2208 Ioo b c, f x > 0 := begin\n  obtain \u27e8\u03b4, \u03b4pos, h\u03b4\u27e9 := hcont (f a / 2) (half_pos hgt),\n  use [a-\u03b4, a+\u03b4],\n  split, \n    split; by {norm_num, assumption},\n\n  intros x hx1,\n  have hx2 : |x - a| < \u03b4 := by {\n    rw abs_sub_lt_iff,\n    dsimp [Ioo] at hx1,\n    split; linarith,\n  },\n  have hfx := h\u03b4 x hx2,\n  cases abs_sub_lt_iff.mp hfx with hfx1 hfx2,\n  linarith [hfx2],\nend", "meta": {"author": "greysome", "repo": "lean-practice", "sha": "00729df4b18a2538cd3f63f68ab9c59308e3a6c2", "save_path": "github-repos/lean/greysome-lean-practice", "path": "github-repos/lean/greysome-lean-practice/lean-practice-00729df4b18a2538cd3f63f68ab9c59308e3a6c2/src/new/contposinterval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9546474155747541, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.7151141720400697}}
{"text": "import tactic\n\n/-\n# Level 8 : Proving if-then\n-/\n\nnamespace math3345 -- hide\n\n/-\nP and Q and R are propositions.\n-/\n\nvariable P : Prop\nvariable Q : Prop\nvariable R : Prop\n\n/- Lemma : no-side-bar\n\nWe are given hypotheses `hPQ` and `hQR` stating that `P` implies `Q`\nand stating that `Q` implies `R`.  From this, we can deduce that `P`\nimplies `R`, but how do we convince Lean of this?\n\nTo prove `P \u2192 R`, we begin with `intro hP` to introduce a hypothesis\n`hP` asserting that `P` is true.  If we can use this hypothesis to\ndeduce `R`, then we have proved `P \u2192 R`.\n\nWe could use `exact hPQ(hP)` if we were trying to prove `Q`.  How can\nwe also make use of the assumption that `hQR`?\n\n-/\nlemma proving_an_implication (hPQ : P \u2192 Q) (hQR : Q \u2192 R) : P \u2192 R :=\nbegin\n  intro hP,\n  sorry,\n\nend\n\nend math3345 -- hide\n\n", "meta": {"author": "kisonecat", "repo": "math3345-game", "sha": "d64159d864c4264b71e64a812f05e7ce21f485b8", "save_path": "github-repos/lean/kisonecat-math3345-game", "path": "github-repos/lean/kisonecat-math3345-game/math3345-game-d64159d864c4264b71e64a812f05e7ce21f485b8/src/propositions/level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7151003355030529}}
{"text": "import definitions subgroups basic \n\nnamespace Algebra\n\nnamespace coset \n\nvariables {G : Type} [group G] {K : subgroup G} \n{a b g h: G}\n\ndef left_coset (g : G) (H : subgroup G) : set G := \n{g' | \u2203 h \u2208 H,  g + h = g'}\n\ndef right_coset (g : G) (H : subgroup G) : set G := \n{g' | \u2203 h \u2208 H,  h + g = g'}\n\ndef in_left_coset {g\u2081 g\u2082 g\u2083: G} {H : subgroup G} (h\u2081 : g\u2083 \u2208 H) (h\u2082 : g\u2081 + g\u2083 = g\u2082) : g\u2082 \u2208 left_coset g\u2081 H := \nby {rw left_coset, simp, exact \u27e8g\u2083, h\u2081,h\u2082\u27e9}\n\n\ndef left_cosets_exists_iff_exists\n(H' : left_coset a K = left_coset b K) : \n(\u2203 (h : G), h \u2208 K \u2227 a + h = g) \u2192 (\u2203 (h : G), h \u2208 K \u2227 b + h = g) :=  begin rintros \u27e8w, H1, H2\u27e9,\n    have H3: g \u2208 left_coset a K, \n      from in_left_coset H1 H2,\n    have H4: g \u2208 left_coset b K, \n      by {rw \u2190 H', assumption},\n    cases H4 with w' H4, cases H4 with H5 H4,\n    use w', split, assumption, assumption\nend \n\ndef left_cosets_eq_iff {a b : G} {K : subgroup G}: \n  left_coset a K = left_coset b K \u2194 \n   \u2200 g : G, \n      (\u2203 h : G, h \u2208 K \u2227 a + h = g) \u2194 \n      (\u2203 h : G, h \u2208 K \u2227  b + h = g) := \nbegin \n  split, \n  { intro H', intro g, split,\n    {apply left_cosets_exists_iff_exists H'},\n    {apply left_cosets_exists_iff_exists H'.symm}},\n  { intro H', repeat {rw left_coset},\n    ext, simp, split,\n    {   intro H1,\n        replace H' := H' x,\n        apply H'.mp, exact H1,},\n    { intro H1, replace H' := H' x, apply H'.mpr, exact H1,}}\nend \n\n\nvariables {g\u2081 g\u2082 : G}\n\nlemma right_inv_cosets_eq_of_left_cosets_eq (H : left_coset a K = left_coset b K) :\n  right_coset (-a) K = right_coset (-b) K := \nbegin  \n  replace H := left_cosets_eq_iff.mp H,\n  ext,\n  split, \n  { \n    intro H,\n  }\nend \n\n\nend coset \nend Algebra ", "meta": {"author": "loganrjmurphy", "repo": "lean-algebra", "sha": "474ac0c2714b7c0ad544a90c0d0807b92a0da227", "save_path": "github-repos/lean/loganrjmurphy-lean-algebra", "path": "github-repos/lean/loganrjmurphy-lean-algebra/lean-algebra-474ac0c2714b7c0ad544a90c0d0807b92a0da227/src/cosets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7151003309363955}}
{"text": "\n\n/-\n01_first.lean\n-/\n\ntheorem my_second_theorem : \n        \u2200 p q : Prop, p \u2192 q \u2192 p \n    :=\nbegin\n  intros p q proof_of_p proof_of_q,\n  exact proof_of_p,\nend\n\n/-\n03_haskell.lean\n\ntheorem map_id_is_the_same (a:Type) (xs:L a) : \n    map id xs = xs :=\nbegin\n    induction xs,\n    {\n        rw map,\n    },\n    {\n        rw map,\n        rw id,\n        rw xs_ih,\n    }\nend\n\n-/\n\n\n/-\n04_fol.lean\n-/\n\n/- Given! -/\n\ntheorem p_implies_p_or_q (p q:Prop) : \n    p \u2192 p \u2228 q := \nbegin\n    intro proof_of_p,\n    left,\n    exact proof_of_p,\nend\n\n/- Actual Solutions -/\n\ntheorem q_implies_p_or_q_or_r (p q r :Prop) : \n    q \u2192 (p \u2228 q) \u2228 r := \nbegin\n    intro proof_of_q,\n    left,\n    right,\n    exact proof_of_q,\nend\n\n\ntheorem p_implies_p_or_not_p (p:Prop) : p \u2192 p \u2228 (\u00ac p) :=\nbegin\n    exact p_implies_p_or_q _ _, \n    -- alternative, if you want to know what lean filled the _ with.\n    -- exact p_implies_p_or_q p (\u00ac p)\nend", "meta": {"author": "alcides", "repo": "lean3_tutorial", "sha": "7a871e00c4fd5cb000929a59e1bd804a626ef277", "save_path": "github-repos/lean/alcides-lean3_tutorial", "path": "github-repos/lean/alcides-lean3_tutorial/lean3_tutorial-7a871e00c4fd5cb000929a59e1bd804a626ef277/src/solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7150610046771677}}
{"text": "/-\nCopyright (c) 2021 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n-/\nimport analysis.normed_space.ordered\nimport analysis.asymptotics.asymptotics\n\n/-!\n# A collection of specific asymptotic results\n\nThis file contains specific lemmas about asymptotics which don't have their place in the general\ntheory developped in `analysis.asymptotics.asymptotics`.\n-/\n\nopen filter asymptotics\nopen_locale topological_space\n\nsection normed_field\n\n/-- If `f : \ud835\udd5c \u2192 E` is bounded in a punctured neighborhood of `a`, then `f(x) = o((x - a)\u207b\u00b9)` as\n`x \u2192 a`, `x \u2260 a`. -/\nlemma filter.is_bounded_under.is_o_sub_self_inv {\ud835\udd5c E : Type*} [normed_field \ud835\udd5c] [has_norm E]\n  {a : \ud835\udd5c} {f : \ud835\udd5c \u2192 E} (h : is_bounded_under (\u2264) (\ud835\udcdd[\u2260] a) (norm \u2218 f)) :\n  is_o f (\u03bb x, (x - a)\u207b\u00b9) (\ud835\udcdd[\u2260] a) :=\nbegin\n  refine (h.is_O_const (@one_ne_zero \u211d _ _)).trans_is_o (is_o_const_left.2 $ or.inr _),\n  simp only [(\u2218), norm_inv],\n  exact (tendsto_norm_sub_self_punctured_nhds a).inv_tendsto_zero\nend\n\nend normed_field\n\nsection linear_ordered_field\n\nvariables {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c]\n\nlemma pow_div_pow_eventually_eq_at_top {p q : \u2115} :\n  (\u03bb x : \ud835\udd5c, x^p / x^q) =\u1da0[at_top] (\u03bb x, x^((p : \u2124) -q)) :=\nbegin\n  apply ((eventually_gt_at_top (0 : \ud835\udd5c)).mono (\u03bb x hx, _)),\n  simp [zpow_sub\u2080 hx.ne'],\nend\n\nlemma pow_div_pow_eventually_eq_at_bot {p q : \u2115} :\n  (\u03bb x : \ud835\udd5c, x^p / x^q) =\u1da0[at_bot] (\u03bb x, x^((p : \u2124) -q)) :=\nbegin\n  apply ((eventually_lt_at_bot (0 : \ud835\udd5c)).mono (\u03bb x hx, _)),\n  simp [zpow_sub\u2080 hx.ne'.symm],\nend\n\nlemma tendsto_zpow_at_top_at_top {n : \u2124}\n  (hn : 0 < n) : tendsto (\u03bb x : \ud835\udd5c, x^n) at_top at_top :=\nbegin\n  lift n to \u2115 using hn.le,\n  simp only [zpow_coe_nat],\n  exact tendsto_pow_at_top (nat.succ_le_iff.mpr $int.coe_nat_pos.mp hn)\nend\n\nlemma tendsto_pow_div_pow_at_top_at_top {p q : \u2115}\n  (hpq : q < p) : tendsto (\u03bb x : \ud835\udd5c, x^p / x^q) at_top at_top :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma tendsto_pow_div_pow_at_top_zero [topological_space \ud835\udd5c] [order_topology \ud835\udd5c] {p q : \u2115}\n  (hpq : p < q) : tendsto (\u03bb x : \ud835\udd5c, x^p / x^q) at_top (\ud835\udcdd 0) :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_zpow_at_top_zero,\n  linarith\nend\n\nend linear_ordered_field\n\nsection normed_linear_ordered_field\n\nvariables {\ud835\udd5c : Type*} [normed_linear_ordered_field \ud835\udd5c]\n\nlemma asymptotics.is_o_pow_pow_at_top_of_lt\n  [order_topology \ud835\udd5c] {p q : \u2115} (hpq : p < q) :\n  is_o (\u03bb x : \ud835\udd5c, x^p) (\u03bb x, x^q) at_top :=\nbegin\n  refine (is_o_iff_tendsto' _).mpr (tendsto_pow_div_pow_at_top_zero hpq),\n  exact (eventually_gt_at_top 0).mono (\u03bb x hx hxq, (pow_ne_zero q hx.ne' hxq).elim),\nend\n\nlemma asymptotics.is_O.trans_tendsto_norm_at_top {\u03b1 : Type*} {u v : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n  (huv : is_O u v l) (hu : tendsto (\u03bb x, \u2225u x\u2225) l at_top) : tendsto (\u03bb x, \u2225v x\u2225) l at_top :=\nbegin\n  rcases huv.exists_pos with \u27e8c, hc, hcuv\u27e9,\n  rw is_O_with at hcuv,\n  convert tendsto.at_top_div_const hc (tendsto_at_top_mono' l hcuv hu),\n  ext x,\n  rw mul_div_cancel_left _ hc.ne.symm,\nend\n\nend normed_linear_ordered_field\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/asymptotics/specific_asymptotics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220291, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7150609955662901}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport data.polynomial.erase_lead\n/-!\n# Denominators of evaluation of polynomials at ratios\n\nLet `i : R \u2192 K` be a homomorphism of semirings.  Assume that `K` is commutative.  If `a` and\n`b` are elements of `R` such that `i b \u2208 K` is invertible, then for any polynomial\n`f \u2208 polynomial R` the \"mathematical\" expression `b ^ f.nat_degree * f (a / b) \u2208 K` is in\nthe image of the homomorphism `i`.\n-/\n\nopen polynomial finset\n\nsection denoms_clearable\n\nvariables {R K : Type*} [semiring R] [comm_semiring K] {i : R \u2192+* K}\nvariables {a b : R} {bi : K}\n-- TODO: use hypothesis (ub : is_unit (i b)) to work with localizations.\n\n/-- `denoms_clearable` formalizes the property that `b ^ N * f (a / b)`\ndoes not have denominators, if the inequality `f.nat_degree \u2264 N` holds.\n\nThe definition asserts the existence of an element `D` of `R` and an\nelement `bi = 1 / i b` of `K` such that clearing the denominators of\nthe fraction equals `i D`.\n-/\ndef denoms_clearable (a b : R) (N : \u2115) (f : polynomial R) (i : R \u2192+* K) : Prop :=\n  \u2203 (D : R) (bi : K), bi * i b = 1 \u2227 i D = i b ^ N * eval (i a * bi) (f.map i)\n\nlemma denoms_clearable_zero (N : \u2115) (a : R) (bu : bi * i b = 1) :\n  denoms_clearable a b N 0 i :=\n\u27e80, bi, bu, by simp only [eval_zero, ring_hom.map_zero, mul_zero, map_zero]\u27e9\n\nlemma denoms_clearable_C_mul_X_pow {N : \u2115} (a : R) (bu : bi * i b = 1) {n : \u2115} (r : R)\n  (nN : n \u2264 N) : denoms_clearable a b N (C r * X ^ n) i :=\nbegin\n  refine \u27e8r * a ^ n * b ^ (N - n), bi, bu, _\u27e9,\n  rw [C_mul_X_pow_eq_monomial, map_monomial, \u2190 C_mul_X_pow_eq_monomial, eval_mul, eval_pow, eval_C],\n  rw [ring_hom.map_mul, ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_pow, eval_X, mul_comm],\n  rw [\u2190 nat.sub_add_cancel nN] {occs := occurrences.pos [2]},\n  rw [pow_add, mul_assoc, mul_comm (i b ^ n), mul_pow, mul_assoc, mul_assoc (i a ^ n), \u2190 mul_pow],\n  rw [bu, one_pow, mul_one],\nend\n\nlemma denoms_clearable.add {N : \u2115} {f g : polynomial R} :\n  denoms_clearable a b N f i \u2192 denoms_clearable a b N g i \u2192 denoms_clearable a b N (f + g) i :=\n\u03bb \u27e8Df, bf, bfu, Hf\u27e9 \u27e8Dg, bg, bgu, Hg\u27e9, \u27e8Df + Dg, bf, bfu,\n  begin\n    rw [ring_hom.map_add, polynomial.map_add, eval_add, mul_add, Hf, Hg],\n    congr,\n    refine @inv_unique K _ (i b) bg bf _ _;\n    rwa mul_comm,\n  end \u27e9\n\nlemma denoms_clearable_of_nat_degree_le (N : \u2115) (a : R) (bu : bi * i b = 1) :\n  \u2200 (f : polynomial R), f.nat_degree \u2264 N \u2192 denoms_clearable a b N f i :=\ninduction_with_nat_degree_le N\n  (denoms_clearable_zero N a bu)\n  (\u03bb N_1 r r0, denoms_clearable_C_mul_X_pow a bu r)\n  (\u03bb f g fN gN df dg, df.add dg)\n\n/-- If `i : R \u2192 K` is a ring homomorphism, `f` is a polynomial with coefficients in `R`,\n`a, b` are elements of `R`, with `i b` invertible, then there is a `D \u2208 R` such that\n`b ^ f.nat_degree * f (a / b)` equals `i D`. -/\ntheorem denoms_clearable_nat_degree\n  (i : R \u2192+* K) (f : polynomial R) (a : R) (bu : bi * i b = 1) :\n  denoms_clearable a b f.nat_degree f i :=\ndenoms_clearable_of_nat_degree_le f.nat_degree a bu f le_rfl\n\nend denoms_clearable\n\nopen ring_hom\n\n/--  Evaluating a polynomial with integer coefficients at a rational number and clearing\ndenominators, yields a number greater than or equal to one.  The target can be any\n`linear_ordered_field K`.\nThe assumption on `K` could be weakened to `linear_ordered_comm_ring` assuming that the\nimage of the denominator is invertible in `K`. -/\nlemma one_le_pow_mul_abs_eval_div {K : Type*} [linear_ordered_field K] {f : polynomial \u2124}\n  {a b : \u2124} (b0 : 0 < b) (fab : eval ((a : K) / b) (f.map (algebra_map \u2124 K)) \u2260 0) :\n  (1 : K) \u2264 b ^ f.nat_degree * abs (eval ((a : K) / b) (f.map (algebra_map \u2124 K))) :=\nbegin\n  obtain \u27e8ev, bi, bu, hF\u27e9 := @denoms_clearable_nat_degree _ _ _ _ b _ (algebra_map \u2124 K)\n    f a (by { rw [eq_int_cast, one_div_mul_cancel], rw [int.cast_ne_zero], exact (b0.ne.symm) }),\n  obtain Fa := congr_arg abs hF,\n  rw [eq_one_div_of_mul_eq_one_left bu, eq_int_cast, eq_int_cast, abs_mul] at Fa,\n  rw [abs_of_pos (pow_pos (int.cast_pos.mpr b0) _ : 0 < (b : K) ^ _), one_div, eq_int_cast] at Fa,\n  rw [div_eq_mul_inv, \u2190 Fa, \u2190 int.cast_abs, \u2190 int.cast_one, int.cast_le],\n  refine int.le_of_lt_add_one ((lt_add_iff_pos_left 1).mpr (abs_pos.mpr (\u03bb F0, fab _))),\n  rw [eq_one_div_of_mul_eq_one_left bu, F0, one_div, eq_int_cast, int.cast_zero, zero_eq_mul] at hF,\n  cases hF with hF hF,\n  { exact (not_le.mpr b0 (le_of_eq (int.cast_eq_zero.mp (pow_eq_zero hF)))).elim },\n  { rwa div_eq_mul_inv }\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/polynomial/denoms_clearable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7150609929877553}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n! This file was ported from Lean 3 source module algebra.order.group.bounds\n! leanprover-community/mathlib commit d012cd09a9b256d870751284dd6a29882b0be105\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Bounds.Basic\nimport Mathlib.Algebra.Order.Group.Defs\n\n/-!\n# Least upper bound and the greatest lower bound in linear ordered additive commutative groups\n-/\n\nsection LinearOrderedAddCommGroup\n\nvariable [LinearOrderedAddCommGroup \u03b1] {s : Set \u03b1} {a \u03b5 : \u03b1}\n\ntheorem IsGLB.exists_between_self_add (h : IsGLB s a) (h\u03b5 : 0 < \u03b5) : \u2203 b \u2208 s, a \u2264 b \u2227 b < a + \u03b5 :=\n  h.exists_between <| lt_add_of_pos_right _ h\u03b5\n#align is_glb.exists_between_self_add IsGLB.exists_between_self_add\n\ntheorem IsGLB.exists_between_self_add' (h : IsGLB s a) (h\u2082 : a \u2209 s) (h\u03b5 : 0 < \u03b5) :\n    \u2203 b \u2208 s, a < b \u2227 b < a + \u03b5 :=\n  h.exists_between' h\u2082 <| lt_add_of_pos_right _ h\u03b5\n#align is_glb.exists_between_self_add' IsGLB.exists_between_self_add'\n\ntheorem IsLUB.exists_between_sub_self (h : IsLUB s a) (h\u03b5 : 0 < \u03b5) : \u2203 b \u2208 s, a - \u03b5 < b \u2227 b \u2264 a :=\n  h.exists_between <| sub_lt_self _ h\u03b5\n#align is_lub.exists_between_sub_self IsLUB.exists_between_sub_self\n\ntheorem IsLUB.exists_between_sub_self' (h : IsLUB s a) (h\u2082 : a \u2209 s) (h\u03b5 : 0 < \u03b5) :\n    \u2203 b \u2208 s, a - \u03b5 < b \u2227 b < a :=\n  h.exists_between' h\u2082 <| sub_lt_self _ h\u03b5\n#align is_lub.exists_between_sub_self' IsLUB.exists_between_sub_self'\n\nend LinearOrderedAddCommGroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/Group/Bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7150495592954343}}
{"text": "/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Haitao Zhang\n\nThe propositional connectives. See also init.datatypes and init.logic.\n-/\nopen eq.ops\n\nvariables {a b c d : Prop}\n\n/- implies -/\n\ndefinition imp (a b : Prop) : Prop := a \u2192 b\n\ntheorem imp.id (H : a) : a := H\n\ntheorem imp.intro (H : a) (H\u2082 : b) : a := H\n\ntheorem imp.mp (H : a) (H\u2082 : a \u2192 b) : b :=\nH\u2082 H\n\ntheorem imp.syl (H : a \u2192 b) (H\u2082 : c \u2192 a) (Hc : c) : b :=\nH (H\u2082 Hc)\n\ntheorem imp.left (H : a \u2192 b) (H\u2082 : b \u2192 c) (Ha : a) : c :=\nH\u2082 (H Ha)\n\ntheorem imp_true (a : Prop) : (a \u2192 true) \u2194 true :=\niff_true_intro (imp.intro trivial)\n\ntheorem true_imp (a : Prop) : (true \u2192 a) \u2194 a :=\niff.intro (assume H, H trivial) imp.intro\n\ntheorem imp_false (a : Prop) : (a \u2192 false) \u2194 \u00ac a := iff.rfl\n\ntheorem false_imp (a : Prop) : (false \u2192 a) \u2194 true :=\niff_true_intro false.elim\n\n/- not -/\n\ntheorem not.elim {A : Type} (H1 : \u00aca) (H2 : a) : A := absurd H2 H1\n\ntheorem not.mto {a b : Prop} : (a \u2192 b) \u2192 \u00acb \u2192 \u00aca := imp.left\n\ntheorem not_imp_not_of_imp {a b : Prop} : (a \u2192 b) \u2192 \u00acb \u2192 \u00aca := not.mto\n\ntheorem not_not_of_not_implies : \u00ac(a \u2192 b) \u2192 \u00ac\u00aca :=\nnot.mto not.elim\n\ntheorem not_of_not_implies : \u00ac(a \u2192 b) \u2192 \u00acb :=\nnot.mto imp.intro\n\ntheorem not_not_em : \u00ac\u00ac(a \u2228 \u00aca) :=\nassume not_em : \u00ac(a \u2228 \u00aca),\nnot_em (or.inr (not.mto or.inl not_em))\n\ntheorem not_iff_not (H : a \u2194 b) : \u00aca \u2194 \u00acb :=\niff.intro (not.mto (iff.mpr H)) (not.mto (iff.mp H))\n\n/- and -/\n\ndefinition not_and_of_not_left (b : Prop) : \u00aca \u2192 \u00ac(a \u2227 b) :=\nnot.mto and.left\n\ndefinition not_and_of_not_right (a : Prop) {b : Prop} : \u00acb \u2192  \u00ac(a \u2227 b) :=\nnot.mto and.right\n\ntheorem and.imp_left (H : a \u2192 b) : a \u2227 c \u2192 b \u2227 c :=\nand.imp H imp.id\n\ntheorem and.imp_right (H : a \u2192 b) : c \u2227 a \u2192 c \u2227 b :=\nand.imp imp.id H\n\ntheorem and_of_and_of_imp_of_imp (H\u2081 : a \u2227 b) (H\u2082 : a \u2192 c) (H\u2083 : b \u2192 d) : c \u2227 d :=\nand.imp H\u2082 H\u2083 H\u2081\n\ntheorem and_of_and_of_imp_left (H\u2081 : a \u2227 c) (H : a \u2192 b) : b \u2227 c :=\nand.imp_left H H\u2081\n\ntheorem and_of_and_of_imp_right (H\u2081 : c \u2227 a) (H : a \u2192 b) : c \u2227 b :=\nand.imp_right H H\u2081\n\ntheorem and_imp_iff (a b c : Prop) : (a \u2227 b \u2192 c) \u2194 (a \u2192 b \u2192 c) :=\niff.intro (\u03bbH a b, H (and.intro a b)) and.rec\n\ntheorem and_imp_eq (a b c : Prop) : (a \u2227 b \u2192 c) = (a \u2192 b \u2192 c) :=\npropext !and_imp_iff\n\n/- or -/\n\ndefinition not_or : \u00aca \u2192 \u00acb \u2192 \u00ac(a \u2228 b) := or.rec\n\ntheorem or_of_or_of_imp_of_imp (H\u2081 : a \u2228 b) (H\u2082 : a \u2192 c) (H\u2083 : b \u2192 d) : c \u2228 d :=\nor.imp H\u2082 H\u2083 H\u2081\n\ntheorem or_of_or_of_imp_left (H\u2081 : a \u2228 c) (H : a \u2192 b) : b \u2228 c :=\nor.imp_left H H\u2081\n\ntheorem or_of_or_of_imp_right (H\u2081 : c \u2228 a) (H : a \u2192 b) : c \u2228 b :=\nor.imp_right H H\u2081\n\ntheorem or.elim3 (H : a \u2228 b \u2228 c) (Ha : a \u2192 d) (Hb : b \u2192 d) (Hc : c \u2192 d) : d :=\nor.elim H Ha (assume H\u2082, or.elim H\u2082 Hb Hc)\n\ntheorem or_resolve_right (H\u2081 : a \u2228 b) (H\u2082 : \u00aca) : b :=\nor.elim H\u2081 (not.elim H\u2082) imp.id\n\ntheorem or_resolve_left (H\u2081 : a \u2228 b) : \u00acb \u2192 a :=\nor_resolve_right (or.swap H\u2081)\n\ntheorem or.imp_distrib : ((a \u2228 b) \u2192 c) \u2194 ((a \u2192 c) \u2227 (b \u2192 c)) :=\niff.intro\n  (\u03bbH, and.intro (imp.syl H or.inl) (imp.syl H or.inr))\n  (and.rec or.rec)\n\ntheorem or_iff_right_of_imp {a b : Prop} (Ha : a \u2192 b) : (a \u2228 b) \u2194 b :=\niff.intro (or.rec Ha imp.id) or.inr\n\ntheorem or_iff_left_of_imp {a b : Prop} (Hb : b \u2192 a) : (a \u2228 b) \u2194 a :=\niff.intro (or.rec imp.id Hb) or.inl\n\ntheorem or_iff_or (H1 : a \u2194 c) (H2 : b \u2194 d) : (a \u2228 b) \u2194 (c \u2228 d) :=\niff.intro (or.imp (iff.mp H1) (iff.mp H2)) (or.imp (iff.mpr H1) (iff.mpr H2))\n\n/- distributivity -/\n\ntheorem and.left_distrib (a b c : Prop) : a \u2227 (b \u2228 c) \u2194 (a \u2227 b) \u2228 (a \u2227 c) :=\niff.intro\n  (and.rec (\u03bbH, or.imp (and.intro H) (and.intro H)))\n  (or.rec (and.imp_right or.inl) (and.imp_right or.inr))\n\ntheorem and.right_distrib (a b c : Prop) : (a \u2228 b) \u2227 c \u2194 (a \u2227 c) \u2228 (b \u2227 c) :=\niff.trans (iff.trans !and.comm !and.left_distrib) (or_iff_or !and.comm !and.comm)\n\ntheorem or.left_distrib (a b c : Prop) : a \u2228 (b \u2227 c) \u2194 (a \u2228 b) \u2227 (a \u2228 c) :=\niff.intro\n  (or.rec (\u03bbH, and.intro (or.inl H) (or.inl H)) (and.imp or.inr or.inr))\n  (and.rec (or.rec (imp.syl imp.intro or.inl) (imp.syl or.imp_right and.intro)))\n\ntheorem or.right_distrib (a b c : Prop) : (a \u2227 b) \u2228 c \u2194 (a \u2228 c) \u2227 (b \u2228 c) :=\niff.trans (iff.trans !or.comm !or.left_distrib) (and_congr !or.comm !or.comm)\n\n/- iff -/\n\ndefinition iff.def : (a \u2194 b) = ((a \u2192 b) \u2227 (b \u2192 a)) := rfl\n\ntheorem forall_imp_forall {A : Type} {P Q : A \u2192 Prop} (H : \u2200a, (P a \u2192 Q a)) (p : \u2200a, P a) (a : A)\n  : Q a :=\n(H a) (p a)\n\ntheorem forall_iff_forall {A : Type} {P Q : A \u2192 Prop} (H : \u2200a, (P a \u2194 Q a))\n  : (\u2200a, P a) \u2194 (\u2200a, Q a) :=\niff.intro (\u03bbp a, iff.elim_left (H a) (p a)) (\u03bbq a, iff.elim_right (H a) (q a))\n\ntheorem imp_iff {P : Prop} (Q : Prop) (p : P) : (P \u2192 Q) \u2194 Q :=\niff.intro (\u03bbf, f p) imp.intro\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/logic/connectives.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973932, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7150495544706685}}
{"text": "import data.set\n\nopen set\n\nnamespace mth1001\n\nsection emtpy_set\n\nvariable A : Type*\n\n/-\nIn this very short file, we show that for every set `S`, the empty set is a subset of `S`.\n-/\n\nexample (S : set A) : \u2205 \u2286 S :=\nbegin\n  intro x, -- Assume `x : A`. The goal is to prove `x \u2208 \u2205 \u2192 x \u2208 S`.\n  intro h, -- Assume `h : x \u2208 \u2205`.\n  exfalso, -- By false introduction, it suffices to prove `\u22a5`,\n  apply h, -- which follows from `h`.\nend\n\nend emtpy_set\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_24_empty_set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.7149708061627958}}
{"text": "import game.world3.level3 -- hide\nnamespace mynat -- hide\n\n/-\n# Multiplication World\n\n## Level 4: `mul_add`\n\nWhere are we going? Well we want to prove `mul_comm`\nand `mul_assoc`, i.e. that `a * b = b * a` and\n`(a * b) * c = a * (b * c)`. But we *also* want to\nestablish the way multiplication interacts with addition,\ni.e. we want to prove that we can \"expand out the brackets\"\nand show `a * (b + c) = (a * b) + (a * c)`.\nThe technical term for this is \"left distributivity of\nmultiplication over addition\" (there is also right distributivity,\nwhich we'll get to later).\n\nNote the name of this proof -- `mul_add`. And note the left\nhand side -- `a * (b + c)`, a multiplication and then an addition.\nI think `mul_add` is much easier to remember than \"left_distrib\",\nan alternative name for the proof of this lemma.\n-/\n\n/- Lemma\nMultiplication is distributive over addition.\nIn other words, for all natural numbers $a$, $b$ and $t$, we have\n$$ t(a + b) = ta + tb. $$\n-/\n\nlemma mul_add (t a b : mynat) : t * (a + b) = t * a + t * b :=\nbegin [nat_num_game]\n  induction b with d hd,\n  { rewrite [add_zero, mul_zero, add_zero],\n  },\n  {\n    rw add_succ,\n    rw mul_succ,\n    rw hd,\n    rw mul_succ,\n    rw add_assoc, -- ;-)\n    refl,\n\n\n  }\nend\n\ndef left_distrib := mul_add -- the \"proper\" name for this lemma\n-- I just don't instinctively know what left_distrib means -- hide\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world3/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.7149707963236039}}
{"text": "import data.finset.basic\nimport data.finset.nat_antidiagonal\nimport tactic\n\nopen_locale big_operators\n\nopen finset\n\n-- some convenient `nat` lemmas\nlemma nat.lt_succ_of_add_right_eq {a b n : \u2115} (h : a + b = n) : a < n.succ :=\n  nat.lt_succ_of_le (h \u25b8 nat.le_add_right a b)\n\nlemma nat.lt_succ_of_add_left_eq {a b n : \u2115} (h : a + b = n) : b < n.succ :=\n  nat.lt_succ_of_le (h \u25b8 nat.le_add_left b a)\n\ndef catalan : \u2115 \u2192 \u2115\n| 0 := 1\n| (n + 1) := \u2211 p in finset.nat.antidiagonal n, \n  if h : p.1 + p.2 = n then\n    let h\u2081 : p.1 < n + 1 := nat.lt_succ_of_add_right_eq h in\n    let h\u2082 : p.2 < n + 1 := nat.lt_succ_of_add_left_eq h in\n    catalan p.1 * catalan p.2\n  else 0\n\nnamespace catalan\n\n@[simp] lemma catalan_zero : catalan 0 = 1 := by rw catalan\n@[simp] lemma catalan_succ {n : \u2115} : catalan n.succ = \u2211 p in finset.nat.antidiagonal n, \n  catalan p.1 * catalan p.2 := \nbegin\n  rw [catalan, sum_congr rfl],\n  simp_rw nat.mem_antidiagonal,\n  rintro \u27e8x, y\u27e9 rfl,\n  simp only [dif_pos rfl],\nend\n\n-- TODO: catalan n = C(2n, n) - C(2n, n - 1) = C(2n, n) / (n + 1)\n\nend catalan\n", "meta": {"author": "VArtem", "repo": "lean-catalan", "sha": "7cf17acf3bdddddf8819dc3ff23774bfaa3f5d92", "save_path": "github-repos/lean/VArtem-lean-catalan", "path": "github-repos/lean/VArtem-lean-catalan/lean-catalan-7cf17acf3bdddddf8819dc3ff23774bfaa3f5d92/src/catalan.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7149707898806086}}
{"text": "import .le\nimport ..myset.basic\n\nnamespace hidden\n\ndef is_upper_bound (S : myset real) (a : real) :=\n\u2200 x : real, x \u2208 S \u2192 x \u2264 a\n\ndef is_least (S : myset real) (a : real) :=\na \u2208 S \u2227 \u2200 x : real, x \u2208 S \u2192 a \u2264 x\n\ndef upper_bounds (S : myset real) : myset real :=\n\u03bb x, is_upper_bound S x\n\ndef is_least_upper_bound (S : myset real) (a : real) :=\nis_least (upper_bounds S) a\n\ndef bounded_above (S : myset real) :=\n\u2203 a : real, is_upper_bound S a\n\ntheorem least_upper_bound_property (S : myset real) :\nbounded_above S \u2192 \u2203 x : real, is_least_upper_bound S x :=\nsorry\n\nopen classical\n\nnoncomputable def sup (S : myset real) (h : bounded_above S) :=\nsome (least_upper_bound_property S h)\n\nvariables {S : myset real} (h : bounded_above S)\n\ntheorem sup_is_ub : is_upper_bound S (sup S h) := sorry\n\ntheorem sup_is_lub : is_least_upper_bound S (sup S h) := sorry\n\nend hidden\n", "meta": {"author": "Sterrs", "repo": "leaning", "sha": "3901cc953694b33adda86cb88ca30ba99594db31", "save_path": "github-repos/lean/Sterrs-leaning", "path": "github-repos/lean/Sterrs-leaning/leaning-3901cc953694b33adda86cb88ca30ba99594db31/src/principia/real/completeness.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922387, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.7149457106656015}}
{"text": "/-\nCopyright (c) 2019 Seul Baek. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Seul Baek\n\n! This file was ported from Lean 3 source module tactic.omega.term\n! leanprover-community/mathlib commit 2558b3b31d33969bb3ef330982ff131533eebfdd\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Tactic.Omega.Coeffs\n\n/-\nNormalized linear integer arithmetic terms.\n-/\nnamespace Omega\n\n/-- Shadow syntax of normalized terms. The first element\n    represents the constant term and the list represents\n    the coefficients. -/\ndef Term : Type :=\n  Int \u00d7 List Int deriving Inhabited\n#align omega.term Omega.Term\n\nunsafe instance : has_reflect Term :=\n  prod.has_reflect _ _\n\nnamespace Term\n\n/-- Evaluate a term using the valuation v. -/\n@[simp]\ndef val (v : Nat \u2192 Int) : Term \u2192 Int\n  | (b, as) => b + Coeffs.val v as\n#align omega.term.val Omega.Term.val\n\n@[simp]\ndef neg : Term \u2192 Term\n  | (b, as) => (-b, List.Func.neg as)\n#align omega.term.neg Omega.Term.neg\n\n@[simp]\ndef add : Term \u2192 Term \u2192 Term\n  | (c1, cfs1), (c2, cfs2) => (c1 + c2, List.Func.add cfs1 cfs2)\n#align omega.term.add Omega.Term.add\n\n@[simp]\ndef sub : Term \u2192 Term \u2192 Term\n  | (c1, cfs1), (c2, cfs2) => (c1 - c2, List.Func.sub cfs1 cfs2)\n#align omega.term.sub Omega.Term.sub\n\n@[simp]\ndef mul (i : Int) : Term \u2192 Term\n  | (b, as) => (i * b, as.map ((\u00b7 * \u00b7) i))\n#align omega.term.mul Omega.Term.mul\n\n@[simp]\ndef div (i : Int) : Term \u2192 Term\n  | (b, as) => (b / i, as.map fun x => x / i)\n#align omega.term.div Omega.Term.div\n\ntheorem val_neg {v : Nat \u2192 Int} {t : Term} : (neg t).val v = -t.val v :=\n  by\n  cases' t with b as\n  simp only [val, neg_add, neg, val, coeffs.val_neg]\n#align omega.term.val_neg Omega.Term.val_neg\n\n@[simp]\ntheorem val_sub {v : Nat \u2192 Int} {t1 t2 : Term} : (sub t1 t2).val v = t1.val v - t2.val v :=\n  by\n  cases t1; cases t2\n  simp only [add_assoc, coeffs.val_sub, neg_add_rev, val, sub, add_comm, add_left_comm,\n    sub_eq_add_neg]\n#align omega.term.val_sub Omega.Term.val_sub\n\n@[simp]\ntheorem val_add {v : Nat \u2192 Int} {t1 t2 : Term} : (add t1 t2).val v = t1.val v + t2.val v :=\n  by\n  cases t1; cases t2\n  simp only [coeffs.val_add, add, val, add_comm, add_left_comm]\n#align omega.term.val_add Omega.Term.val_add\n\n@[simp]\ntheorem val_mul {v : Nat \u2192 Int} {i : Int} {t : Term} : val v (mul i t) = i * val v t :=\n  by\n  cases t\n  simp only [mul, mul_add, add_mul, List.length_map, coeffs.val, coeffs.val_between_map_mul, val,\n    List.map]\n#align omega.term.val_mul Omega.Term.val_mul\n\ntheorem val_div {v : Nat \u2192 Int} {i b : Int} {as : List Int} :\n    i \u2223 b \u2192 (\u2200 x \u2208 as, i \u2223 x) \u2192 (div i (b, as)).val v = val v (b, as) / i :=\n  by\n  intro h1 h2; simp only [val, div, List.map]\n  rw [Int.add_ediv_of_dvd_left h1]\n  apply fun_mono_2 rfl\n  rw [\u2190 coeffs.val_map_div h2]\n#align omega.term.val_div Omega.Term.val_div\n\n/-- Fresh de Brujin index not used by any variable ocurring in the term -/\ndef freshIndex (t : Term) : Nat :=\n  t.snd.length\n#align omega.term.fresh_index Omega.Term.freshIndex\n\ndef toString (t : Term) : String :=\n  t.2.enum.foldr (fun \u27e8i, n\u27e9 r => toString n ++ \" * x\" ++ toString i ++ \" + \" ++ r) (toString t.1)\n#align omega.term.to_string Omega.Term.toString\n\ninstance : ToString Term :=\n  \u27e8toString\u27e9\n\nend Term\n\n/-- Fresh de Brujin index not used by any variable ocurring in the list of terms -/\ndef Terms.freshIndex : List Term \u2192 Nat\n  | [] => 0\n  | t :: ts => max t.freshIndex (terms.fresh_index ts)\n#align omega.terms.fresh_index Omega.Terms.freshIndex\n\nend Omega\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Tactic/Omega/Term.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7148996039668044}}
{"text": "section\n    variable A : Type\n    variable f : A \u2192 A\n    variable P : A \u2192 Prop\n    variable h : \u2200 x, P x \u2192 P (f x)\n\n    include h\n\n    -- Show the following:\n    example : \u2200 y, P y \u2192 P (f (f y)) :=\n        begin\n            intros,\n            have h1 : P y \u2192 P (f y), from h y,\n            have h2 : P (f y), from h1 a,\n            have h3 : P (f y) \u2192 P (f (f y)), from h (f y),\n            have h4 : P (f (f y)), from h3 h2,\n            assumption\n        end\nend\n\nsection\n    variable U : Type\n    variables A B : U \u2192 Prop\n\n    example : (\u2200 x, A x \u2227 B x) \u2192 \u2200 x, A x :=\n        begin\n            intro, \n            intro,\n            exact (a x).left\n        end\nend\n\nsection\n    variable U : Type\n    variables A B C : U \u2192 Prop\n\n    variable h1 : \u2200 x, A x \u2228 B x\n    variable h2 : \u2200 x, A x \u2192 C x\n    variable h3 : \u2200 x, B x \u2192 C x\n\n    include h1 h2 h3\n\n    example : \u2200 x, C x :=\n        begin\n            intro x,\n            have h4, from h1 x,\n            cases h4,\n                exact h2 x h4,\n            exact h3 x h4\n        end\nend\n\nopen classical   -- not needed, but you can use it\n\n-- This is an exercise from Chapter 4. Use it as an axiom here.\naxiom not_iff_not_self (P : Prop) : \u00ac (P \u2194 \u00ac P)\n\nexample (Q : Prop) : \u00ac (Q \u2194 \u00ac Q) :=\nnot_iff_not_self Q\n\nsection\n    variable Person : Type\n    variable shaves : Person \u2192 Person \u2192 Prop\n    variable barber : Person\n    variable h : \u2200 x, shaves barber x \u2194 \u00ac shaves x x\n    \n    include Person shaves barber h\n\n    -- Show the following:\n    example : false :=\n        begin\n            have h1, from h barber,\n            have h2, from iff.elim_left h1,\n            have h3, from iff.elim_right h1,\n            have h5, from\n                assume h4 : shaves barber barber,\n                show false, from (h2 h4) h4,            \n            have h6, from\n                by_contradiction\n                (assume h4 : \u00ac shaves barber barber,\n                show false, from h4 (h3 h4)),\n            exact h5 h6       \n        end\nend\n", "meta": {"author": "lucasresck", "repo": "Discrete-Mathematics", "sha": "0a08081c5f393e5765259d3f1253c3a6dd043dac", "save_path": "github-repos/lean/lucasresck-Discrete-Mathematics", "path": "github-repos/lean/lucasresck-Discrete-Mathematics/Discrete-Mathematics-0a08081c5f393e5765259d3f1253c3a6dd043dac/Exercises/9. First Order Logic in Lean (tactics).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7148996039668044}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\n\nimport algebra.squarefree\nimport data.polynomial.expand\nimport data.polynomial.splits\nimport field_theory.minpoly.field\nimport ring_theory.power_basis\n\n/-!\n\n# Separable polynomials\n\nWe define a polynomial to be separable if it is coprime with its derivative. We prove basic\nproperties about separable polynomials here.\n\n## Main definitions\n\n* `polynomial.separable f`: a polynomial `f` is separable iff it is coprime with its derivative.\n\n-/\n\nuniverses u v w\nopen_locale classical big_operators polynomial\nopen finset\n\nnamespace polynomial\n\nsection comm_semiring\n\nvariables {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S]\n\n/-- A polynomial is separable iff it is coprime with its derivative. -/\ndef separable (f : R[X]) : Prop :=\nis_coprime f f.derivative\n\nlemma separable_def (f : R[X]) :\n  f.separable \u2194 is_coprime f f.derivative :=\niff.rfl\n\nlemma separable_def' (f : R[X]) :\n  f.separable \u2194 \u2203 a b : R[X], a * f + b * f.derivative = 1 :=\niff.rfl\n\nlemma not_separable_zero [nontrivial R] : \u00ac separable (0 : R[X]) :=\nbegin\n  rintro \u27e8x, y, h\u27e9,\n  simpa only [derivative_zero, mul_zero, add_zero, zero_ne_one] using h,\nend\n\nlemma separable_one : (1 : R[X]).separable :=\nis_coprime_one_left\n\n@[nontriviality] lemma separable_of_subsingleton [subsingleton R] (f : R[X]) :\n  f.separable := by simp [separable]\n\nlemma separable_X_add_C (a : R) : (X + C a).separable :=\nby { rw [separable_def, derivative_add, derivative_X, derivative_C, add_zero],\n  exact is_coprime_one_right }\n\nlemma separable_X : (X : R[X]).separable :=\nby { rw [separable_def, derivative_X], exact is_coprime_one_right }\n\nlemma separable_C (r : R) : (C r).separable \u2194 is_unit r :=\nby rw [separable_def, derivative_C, is_coprime_zero_right, is_unit_C]\n\nlemma separable.of_mul_left {f g : R[X]} (h : (f * g).separable) : f.separable :=\nbegin\n  have := h.of_mul_left_left, rw derivative_mul at this,\n  exact is_coprime.of_mul_right_left (is_coprime.of_add_mul_left_right this)\nend\n\nlemma separable.of_mul_right {f g : R[X]} (h : (f * g).separable) : g.separable :=\nby { rw mul_comm at h, exact h.of_mul_left }\n\nlemma separable.of_dvd {f g : R[X]} (hf : f.separable) (hfg : g \u2223 f) : g.separable :=\nby { rcases hfg with \u27e8f', rfl\u27e9, exact separable.of_mul_left hf }\n\nlemma separable_gcd_left {F : Type*} [field F] {f : F[X]}\n  (hf : f.separable) (g : F[X]) : (euclidean_domain.gcd f g).separable :=\nseparable.of_dvd hf (euclidean_domain.gcd_dvd_left f g)\n\nlemma separable_gcd_right {F : Type*} [field F] {g : F[X]}\n  (f : F[X]) (hg : g.separable) : (euclidean_domain.gcd f g).separable :=\nseparable.of_dvd hg (euclidean_domain.gcd_dvd_right f g)\n\nlemma separable.is_coprime {f g : R[X]} (h : (f * g).separable) : is_coprime f g :=\nbegin\n  have := h.of_mul_left_left, rw derivative_mul at this,\n  exact is_coprime.of_mul_right_right (is_coprime.of_add_mul_left_right this)\nend\n\ntheorem separable.of_pow' {f : R[X]} :\n  \u2200 {n : \u2115} (h : (f ^ n).separable), is_unit f \u2228 (f.separable \u2227 n = 1) \u2228 n = 0\n| 0     := \u03bb h, or.inr $ or.inr rfl\n| 1     := \u03bb h, or.inr $ or.inl \u27e8pow_one f \u25b8 h, rfl\u27e9\n| (n+2) := \u03bb h, by { rw [pow_succ, pow_succ] at h,\n    exact or.inl (is_coprime_self.1 h.is_coprime.of_mul_right_left) }\n\ntheorem separable.of_pow {f : R[X]} (hf : \u00acis_unit f) {n : \u2115} (hn : n \u2260 0)\n  (hfs : (f ^ n).separable) : f.separable \u2227 n = 1 :=\n(hfs.of_pow'.resolve_left hf).resolve_right hn\n\ntheorem separable.map {p : R[X]} (h : p.separable) {f : R \u2192+* S} : (p.map f).separable :=\nlet \u27e8a, b, H\u27e9 := h in \u27e8a.map f, b.map f,\nby rw [derivative_map, \u2190 polynomial.map_mul, \u2190 polynomial.map_mul, \u2190 polynomial.map_add, H,\n       polynomial.map_one]\u27e9\n\nvariables (p q : \u2115)\n\nlemma is_unit_of_self_mul_dvd_separable {p q : R[X]}\n  (hp : p.separable) (hq : q * q \u2223 p) : is_unit q :=\nbegin\n  obtain \u27e8p, rfl\u27e9 := hq,\n  apply is_coprime_self.mp,\n  have : is_coprime (q * (q * p)) (q * (q.derivative * p + q.derivative * p + q * p.derivative)),\n  { simp only [\u2190 mul_assoc, mul_add],\n    convert hp,\n    rw [derivative_mul, derivative_mul],\n    ring },\n  exact is_coprime.of_mul_right_left (is_coprime.of_mul_left_left this)\nend\n\nlemma multiplicity_le_one_of_separable {p q : R[X]} (hq : \u00ac is_unit q)\n  (hsep : separable p) : multiplicity q p \u2264 1 :=\nbegin\n  contrapose! hq,\n  apply is_unit_of_self_mul_dvd_separable hsep,\n  rw \u2190 sq,\n  apply multiplicity.pow_dvd_of_le_multiplicity,\n  simpa only [nat.cast_one, nat.cast_bit0] using part_enat.add_one_le_of_lt hq\nend\n\nlemma separable.squarefree {p : R[X]} (hsep : separable p) : squarefree p :=\nbegin\n  rw multiplicity.squarefree_iff_multiplicity_le_one p,\n  intro f,\n  by_cases hunit : is_unit f,\n  { exact or.inr hunit },\n  exact or.inl (multiplicity_le_one_of_separable hunit hsep)\nend\n\nend comm_semiring\n\nsection comm_ring\n\nvariables {R : Type u} [comm_ring R]\n\nlemma separable_X_sub_C {x : R} : separable (X - C x) :=\nby simpa only [sub_eq_add_neg, C_neg] using separable_X_add_C (-x)\n\nlemma separable.mul {f g : R[X]} (hf : f.separable) (hg : g.separable)\n  (h : is_coprime f g) : (f * g).separable :=\nby { rw [separable_def, derivative_mul], exact ((hf.mul_right h).add_mul_left_right _).mul_left\n  ((h.symm.mul_right hg).mul_add_right_right _) }\n\nlemma separable_prod' {\u03b9 : Sort*} {f : \u03b9 \u2192 R[X]} {s : finset \u03b9} :\n  (\u2200x\u2208s, \u2200y\u2208s, x \u2260 y \u2192 is_coprime (f x) (f y)) \u2192 (\u2200x\u2208s, (f x).separable) \u2192\n  (\u220f x in s, f x).separable :=\nfinset.induction_on s (\u03bb _ _, separable_one) $ \u03bb a s has ih h1 h2, begin\n  simp_rw [finset.forall_mem_insert, forall_and_distrib] at h1 h2, rw prod_insert has,\n  exact h2.1.mul (ih h1.2.2 h2.2) (is_coprime.prod_right $ \u03bb i his, h1.1.2 i his $\n    ne.symm $ ne_of_mem_of_not_mem his has)\nend\n\nlemma separable_prod {\u03b9 : Sort*} [fintype \u03b9] {f : \u03b9 \u2192 R[X]}\n  (h1 : pairwise (is_coprime on f)) (h2 : \u2200 x, (f x).separable) : (\u220f x, f x).separable :=\nseparable_prod' (\u03bb x hx y hy hxy, h1 hxy) (\u03bb x hx, h2 x)\n\nlemma separable.inj_of_prod_X_sub_C [nontrivial R] {\u03b9 : Sort*} {f : \u03b9 \u2192 R} {s : finset \u03b9}\n  (hfs : (\u220f i in s, (X - C (f i))).separable)\n  {x y : \u03b9} (hx : x \u2208 s) (hy : y \u2208 s) (hfxy : f x = f y) : x = y :=\nbegin\n  by_contra hxy,\n  rw [\u2190 insert_erase hx, prod_insert (not_mem_erase _ _),\n      \u2190 insert_erase (mem_erase_of_ne_of_mem (ne.symm hxy) hy),\n      prod_insert (not_mem_erase _ _), \u2190 mul_assoc, hfxy, \u2190 sq] at hfs,\n  cases (hfs.of_mul_left.of_pow (by exact not_is_unit_X_sub_C _) two_ne_zero).2\nend\n\nlemma separable.injective_of_prod_X_sub_C [nontrivial R] {\u03b9 : Sort*} [fintype \u03b9] {f : \u03b9 \u2192 R}\n  (hfs : (\u220f i, (X - C (f i))).separable) : function.injective f :=\n\u03bb x y hfxy, hfs.inj_of_prod_X_sub_C (mem_univ _) (mem_univ _) hfxy\n\nlemma nodup_of_separable_prod [nontrivial R] {s : multiset R}\n  (hs : separable (multiset.map (\u03bb a, X - C a) s).prod) : s.nodup :=\nbegin\n  rw multiset.nodup_iff_ne_cons_cons,\n  rintros a t rfl,\n  refine not_is_unit_X_sub_C a (is_unit_of_self_mul_dvd_separable hs _),\n  simpa only [multiset.map_cons, multiset.prod_cons] using mul_dvd_mul_left _ (dvd_mul_right _ _)\nend\n\n/--If `is_unit n` in a `comm_ring R`, then `X ^ n - u` is separable for any unit `u`. -/\nlemma separable_X_pow_sub_C_unit {n : \u2115} (u : R\u02e3) (hn : is_unit (n : R)) :\n  separable (X ^ n - C (u : R)) :=\nbegin\n  nontriviality R,\n  rcases n.eq_zero_or_pos with rfl | hpos,\n  { simpa using hn },\n  apply (separable_def' (X ^ n - C (u : R))).2,\n  obtain \u27e8n', hn'\u27e9 := hn.exists_left_inv,\n  refine \u27e8-C \u2191u\u207b\u00b9, C \u2191u\u207b\u00b9 * C n' * X, _\u27e9,\n  rw [derivative_sub, derivative_C, sub_zero, derivative_pow X n, derivative_X, mul_one],\n  calc  - C \u2191u\u207b\u00b9 * (X ^ n - C \u2191u) + C \u2191u\u207b\u00b9 * C n' * X * (\u2191n * X ^ (n - 1))\n      = C (\u2191u\u207b\u00b9 * \u2191 u) - C \u2191u\u207b\u00b9 * X^n + C \u2191 u \u207b\u00b9 * C (n' * \u2191n) * (X * X ^ (n - 1)) :\n    by { simp only [C.map_mul, C_eq_nat_cast], ring }\n  ... = 1 : by simp only [units.inv_mul, hn', C.map_one, mul_one, \u2190 pow_succ,\n              nat.sub_add_cancel (show 1 \u2264 n, from hpos), sub_add_cancel]\nend\n\nlemma root_multiplicity_le_one_of_separable [nontrivial R] {p : R[X]}\n  (hsep : separable p) (x : R) : root_multiplicity x p \u2264 1 :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp], },\n  rw [root_multiplicity_eq_multiplicity, dif_neg hp, \u2190 part_enat.coe_le_coe, part_enat.coe_get,\n    nat.cast_one],\n  exact multiplicity_le_one_of_separable (not_is_unit_X_sub_C _) hsep\nend\n\nend comm_ring\n\nsection is_domain\n\nvariables {R : Type u} [comm_ring R] [is_domain R]\n\nlemma count_roots_le_one {p : R[X]} (hsep : separable p) (x : R) :\n  p.roots.count x \u2264 1 :=\nbegin\n  rw count_roots p,\n  exact root_multiplicity_le_one_of_separable hsep x\nend\n\nlemma nodup_roots {p : R[X]} (hsep : separable p) : p.roots.nodup :=\nmultiset.nodup_iff_count_le_one.mpr (count_roots_le_one hsep)\n\nend is_domain\n\nsection field\n\nvariables {F : Type u} [field F] {K : Type v} [field K]\n\ntheorem separable_iff_derivative_ne_zero {f : F[X]} (hf : irreducible f) :\n  f.separable \u2194 f.derivative \u2260 0 :=\n\u27e8\u03bb h1 h2, hf.not_unit $ is_coprime_zero_right.1 $ h2 \u25b8 h1,\n  \u03bb h, euclidean_domain.is_coprime_of_dvd (mt and.right h) $ \u03bb g hg1 hg2 \u27e8p, hg3\u27e9 hg4,\nlet \u27e8u, hu\u27e9 := (hf.is_unit_or_is_unit hg3).resolve_left hg1 in\n  have f \u2223 f.derivative, by { conv_lhs { rw [hg3, \u2190 hu] }, rwa units.mul_right_dvd },\n  not_lt_of_le (nat_degree_le_of_dvd this h) $\n  nat_degree_derivative_lt $ mt derivative_of_nat_degree_zero h\u27e9\n\ntheorem separable_map (f : F \u2192+* K) {p : F[X]} : (p.map f).separable \u2194 p.separable :=\nby simp_rw [separable_def, derivative_map, is_coprime_map]\n\nlemma separable_prod_X_sub_C_iff' {\u03b9 : Sort*} {f : \u03b9 \u2192 F} {s : finset \u03b9} :\n  (\u220f i in s, (X - C (f i))).separable \u2194 (\u2200 (x \u2208 s) (y \u2208 s), f x = f y \u2192 x = y) :=\n\u27e8\u03bb hfs x hx y hy hfxy, hfs.inj_of_prod_X_sub_C hx hy hfxy,\n\u03bb H, by { rw \u2190 prod_attach, exact separable_prod' (\u03bb x hx y hy hxy,\n    @pairwise_coprime_X_sub_C _ _ { x // x \u2208 s } (\u03bb x, f x)\n      (\u03bb x y hxy, subtype.eq $ H x.1 x.2 y.1 y.2 hxy) _ _ hxy)\n  (\u03bb _ _, separable_X_sub_C) }\u27e9\n\nlemma separable_prod_X_sub_C_iff {\u03b9 : Sort*} [fintype \u03b9] {f : \u03b9 \u2192 F} :\n  (\u220f i, (X - C (f i))).separable \u2194 function.injective f :=\nseparable_prod_X_sub_C_iff'.trans $ by simp_rw [mem_univ, true_implies_iff, function.injective]\n\nsection char_p\n\nvariables (p : \u2115) [HF : char_p F p]\ninclude HF\n\ntheorem separable_or {f : F[X]} (hf : irreducible f) : f.separable \u2228\n  \u00acf.separable \u2227 \u2203 g : F[X], irreducible g \u2227 expand F p g = f :=\nif H : f.derivative = 0 then\nbegin\n  unfreezingI { rcases p.eq_zero_or_pos with rfl | hp },\n  { haveI := char_p.char_p_to_char_zero F,\n    have := nat_degree_eq_zero_of_derivative_eq_zero H,\n    have := (nat_degree_pos_iff_degree_pos.mpr $ degree_pos_of_irreducible hf).ne',\n    contradiction },\n  haveI := is_local_ring_hom_expand F hp,\n  exact or.inr\n        \u27e8by rw [separable_iff_derivative_ne_zero hf, not_not, H],\n        contract p f,\n        of_irreducible_map \u2191(expand F p) (by rwa \u2190 expand_contract p H hp.ne' at hf),\n        expand_contract p H hp.ne'\u27e9\nend\nelse or.inl $ (separable_iff_derivative_ne_zero hf).2 H\n\ntheorem exists_separable_of_irreducible {f : F[X]} (hf : irreducible f) (hp : p \u2260 0) :\n  \u2203 (n : \u2115) (g : F[X]), g.separable \u2227 expand F (p ^ n) g = f :=\nbegin\n  replace hp : p.prime := (char_p.char_is_prime_or_zero F p).resolve_right hp,\n  unfreezingI\n  { induction hn : f.nat_degree using nat.strong_induction_on with N ih generalizing f },\n  rcases separable_or p hf with h | \u27e8h1, g, hg, hgf\u27e9,\n  { refine \u27e80, f, h, _\u27e9, rw [pow_zero, expand_one] },\n  { cases N with N,\n    { rw [nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff] at hn,\n      rw [hn, separable_C, is_unit_iff_ne_zero, not_not] at h1,\n      have hf0 : f \u2260 0 := hf.ne_zero,\n      rw [h1, C_0] at hn, exact absurd hn hf0 },\n    have hg1 : g.nat_degree * p = N.succ,\n    { rwa [\u2190 nat_degree_expand, hgf] },\n    have hg2 : g.nat_degree \u2260 0,\n    { intro this, rw [this, zero_mul] at hg1, cases hg1 },\n    have hg3 : g.nat_degree < N.succ,\n    { rw [\u2190 mul_one g.nat_degree, \u2190 hg1],\n      exact nat.mul_lt_mul_of_pos_left hp.one_lt hg2.bot_lt },\n    rcases ih _ hg3 hg rfl with \u27e8n, g, hg4, rfl\u27e9, refine \u27e8n+1, g, hg4, _\u27e9,\n    rw [\u2190 hgf, expand_expand, pow_succ] }\nend\n\ntheorem is_unit_or_eq_zero_of_separable_expand {f : F[X]} (n : \u2115) (hp : 0 < p)\n  (hf : (expand F (p ^ n) f).separable) : is_unit f \u2228 n = 0 :=\nbegin\n  rw or_iff_not_imp_right,\n  rintro hn : n \u2260 0,\n  have hf2 : (expand F (p ^ n) f).derivative = 0,\n  { rw [derivative_expand, nat.cast_pow, char_p.cast_eq_zero,\n      zero_pow hn.bot_lt, zero_mul, mul_zero] },\n  rw [separable_def, hf2, is_coprime_zero_right, is_unit_iff] at hf,\n  rcases hf with \u27e8r, hr, hrf\u27e9,\n  rw [eq_comm, expand_eq_C (pow_pos hp _)] at hrf,\n  rwa [hrf, is_unit_C]\nend\n\ntheorem unique_separable_of_irreducible {f : F[X]} (hf : irreducible f) (hp : 0 < p)\n  (n\u2081 : \u2115) (g\u2081 : F[X]) (hg\u2081 : g\u2081.separable) (hgf\u2081 : expand F (p ^ n\u2081) g\u2081 = f)\n  (n\u2082 : \u2115) (g\u2082 : F[X]) (hg\u2082 : g\u2082.separable) (hgf\u2082 : expand F (p ^ n\u2082) g\u2082 = f) :\n  n\u2081 = n\u2082 \u2227 g\u2081 = g\u2082 :=\nbegin\n  revert g\u2081 g\u2082,\n  wlog hn : n\u2081 \u2264 n\u2082,\n  { intros g\u2081 g\u2082 hg\u2081 Hg\u2081 hg\u2082 Hg\u2082,\n    simpa only [eq_comm] using this hf hp n\u2082 n\u2081 (le_of_not_le hn) g\u2082 g\u2081 hg\u2082 Hg\u2082 hg\u2081 Hg\u2081 },\n  have hf0 : f \u2260 0 := hf.ne_zero,\n  unfreezingI { intros, rw le_iff_exists_add at hn, rcases hn with \u27e8k, rfl\u27e9,\n    rw [\u2190 hgf\u2081, pow_add, expand_mul, expand_inj (pow_pos hp n\u2081)] at hgf\u2082, subst hgf\u2082,\n    subst hgf\u2081,\n    rcases is_unit_or_eq_zero_of_separable_expand p k hp hg\u2081 with h | rfl,\n    { rw is_unit_iff at h, rcases h with \u27e8r, hr, rfl\u27e9,\n      simp_rw expand_C at hf, exact absurd (is_unit_C.2 hr) hf.1 },\n    { rw [add_zero, pow_zero, expand_one], split; refl } },\nend\n\nend char_p\n\n/--If `n \u2260 0` in `F`, then ` X ^ n - a` is separable for any `a \u2260 0`. -/\nlemma separable_X_pow_sub_C {n : \u2115} (a : F) (hn : (n : F) \u2260 0) (ha : a \u2260 0) :\n  separable (X ^ n - C a) :=\nseparable_X_pow_sub_C_unit (units.mk0 a ha) (is_unit.mk0 n hn)\n\n-- this can possibly be strengthened to making `separable_X_pow_sub_C_unit` a\n-- bi-implication, but it is nontrivial!\n/-- In a field `F`, `X ^ n - 1` is separable iff `\u2191n \u2260 0`. -/\nlemma X_pow_sub_one_separable_iff {n : \u2115} :\n  (X ^ n - 1 : F[X]).separable \u2194 (n : F) \u2260 0 :=\nbegin\n  refine \u27e8_, \u03bb h, separable_X_pow_sub_C_unit 1 (is_unit.mk0 \u2191n h)\u27e9,\n  rw [separable_def', derivative_sub, derivative_X_pow, derivative_one, sub_zero],\n  -- Suppose `(n : F) = 0`, then the derivative is `0`, so `X ^ n - 1` is a unit, contradiction.\n  rintro (h : is_coprime _ _) hn',\n  rw [hn', C_0, zero_mul, is_coprime_zero_right] at h,\n  exact not_is_unit_X_pow_sub_one F n h\nend\n\nsection splits\n\nlemma card_root_set_eq_nat_degree [algebra F K] {p : F[X]} (hsep : p.separable)\n  (hsplit : splits (algebra_map F K) p) : fintype.card (p.root_set K) = p.nat_degree :=\nbegin\n  simp_rw [root_set_def, finset.coe_sort_coe, fintype.card_coe],\n  rw [multiset.to_finset_card_of_nodup, \u2190nat_degree_eq_card_roots hsplit],\n  exact nodup_roots hsep.map,\nend\n\nvariable {i : F \u2192+* K}\n\nlemma eq_X_sub_C_of_separable_of_root_eq {x : F} {h : F[X]}\n  (h_sep : h.separable) (h_root : h.eval x = 0) (h_splits : splits i h)\n  (h_roots : \u2200 y \u2208 (h.map i).roots, y = i x) : h = (C (leading_coeff h)) * (X - C x) :=\nbegin\n  have h_ne_zero : h \u2260 0 := by { rintro rfl, exact not_separable_zero h_sep },\n  apply polynomial.eq_X_sub_C_of_splits_of_single_root i h_splits,\n  apply finset.mk.inj,\n  { change _ = {i x},\n    rw finset.eq_singleton_iff_unique_mem,\n    split,\n    { apply finset.mem_mk.mpr,\n      rw mem_roots (show h.map i \u2260 0, by exact map_ne_zero h_ne_zero),\n      rw [is_root.def,\u2190eval\u2082_eq_eval_map,eval\u2082_hom,h_root],\n      exact ring_hom.map_zero i },\n    { exact h_roots } },\n  { exact nodup_roots (separable.map h_sep) },\nend\n\nlemma exists_finset_of_splits\n  (i : F \u2192+* K) {f : F[X]} (sep : separable f) (sp : splits i f) :\n  \u2203 (s : finset K), f.map i = C (i f.leading_coeff) * (s.prod (\u03bb a : K, X - C a)) :=\nbegin\n  obtain \u27e8s, h\u27e9 := (splits_iff_exists_multiset _).1 sp,\n  use s.to_finset,\n  rw [h, finset.prod_eq_multiset_prod, \u2190multiset.to_finset_eq],\n  apply nodup_of_separable_prod,\n  apply separable.of_mul_right,\n  rw \u2190h,\n  exact sep.map,\nend\n\nend splits\n\ntheorem _root_.irreducible.separable [char_zero F] {f : F[X]}\n  (hf : irreducible f) : f.separable :=\nbegin\n  rw [separable_iff_derivative_ne_zero hf, ne, \u2190 degree_eq_bot, degree_derivative_eq],\n  { rintro \u27e8\u27e9 },\n  rw [pos_iff_ne_zero, ne, nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff],\n  refine \u03bb hf1, hf.not_unit _,\n  rw [hf1, is_unit_C, is_unit_iff_ne_zero],\n  intro hf2,\n  rw [hf2, C_0] at hf1,\n  exact absurd hf1 hf.ne_zero\nend\n\nend field\n\nend polynomial\n\nopen polynomial\n\nsection comm_ring\n\nvariables (F K : Type*) [comm_ring F] [ring K] [algebra F K]\n\n-- TODO: refactor to allow transcendental extensions?\n-- See: https://en.wikipedia.org/wiki/Separable_extension#Separability_of_transcendental_extensions\n-- Note that right now a Galois extension (class `is_galois`) is defined to be an extension which\n-- is separable and normal, so if the definition of separable changes here at some point\n-- to allow non-algebraic extensions, then the definition of `is_galois` must also be changed.\n\n/-- Typeclass for separable field extension: `K` is a separable field extension of `F` iff\nthe minimal polynomial of every `x : K` is separable.\n\nWe define this for general (commutative) rings and only assume `F` and `K` are fields if this\nis needed for a proof.\n-/\nclass is_separable : Prop :=\n(is_integral' (x : K) : is_integral F x)\n(separable' (x : K) : (minpoly F x).separable)\n\nvariables (F) {K}\n\ntheorem is_separable.is_integral [is_separable F K] :\n  \u2200 x : K, is_integral F x := is_separable.is_integral'\n\ntheorem is_separable.separable [is_separable F K] :\n  \u2200 x : K, (minpoly F x).separable := is_separable.separable'\n\nvariables {F K}\n\ntheorem is_separable_iff : is_separable F K \u2194 \u2200 x : K, is_integral F x \u2227 (minpoly F x).separable :=\n\u27e8\u03bb h x, \u27e8@@is_separable.is_integral F _ _ _ h x, @@is_separable.separable F _ _ _ h x\u27e9,\n \u03bb h, \u27e8\u03bb x, (h x).1, \u03bb x, (h x).2\u27e9\u27e9\n\nend comm_ring\n\ninstance is_separable_self (F : Type*) [field F] : is_separable F F :=\n\u27e8\u03bb x, is_integral_algebra_map, \u03bb x, by { rw minpoly.eq_X_sub_C', exact separable_X_sub_C }\u27e9\n\n/-- A finite field extension in characteristic 0 is separable. -/\n@[priority 100] -- See note [lower instance priority]\ninstance is_separable.of_finite (F K : Type*) [field F] [field K] [algebra F K]\n  [finite_dimensional F K] [char_zero F] : is_separable F K :=\nhave \u2200 (x : K), is_integral F x,\nfrom \u03bb x, algebra.is_integral_of_finite _ _ _,\n\u27e8this, \u03bb x, (minpoly.irreducible (this x)).separable\u27e9\n\nsection is_separable_tower\nvariables (F K E : Type*) [field F] [field K] [field E] [algebra F K] [algebra F E]\n  [algebra K E] [is_scalar_tower F K E]\n\nlemma is_separable_tower_top_of_is_separable [is_separable F E] : is_separable K E :=\n\u27e8\u03bb x, is_integral_of_is_scalar_tower (is_separable.is_integral F x),\n \u03bb x, (is_separable.separable F x).map.of_dvd (minpoly.dvd_map_of_is_scalar_tower _ _ _)\u27e9\n\nlemma is_separable_tower_bot_of_is_separable [h : is_separable F E] : is_separable F K :=\nis_separable_iff.2 $ \u03bb x, begin\n  refine (is_separable_iff.1 h (algebra_map K E x)).imp\n    is_integral_tower_bot_of_is_integral_field (\u03bb hs, _),\n  obtain \u27e8q, hq\u27e9 := minpoly.dvd F x\n    ((aeval_algebra_map_eq_zero_iff _ _ _).mp (minpoly.aeval F ((algebra_map K E) x))),\n  rw hq at hs,\n  exact hs.of_mul_left\nend\n\nvariables {E}\n\nlemma is_separable.of_alg_hom (E' : Type*) [field E'] [algebra F E']\n  (f : E \u2192\u2090[F] E') [is_separable F E'] : is_separable F E :=\nbegin\n  letI : algebra E E' := ring_hom.to_algebra f.to_ring_hom,\n  haveI : is_scalar_tower F E E' := is_scalar_tower.of_algebra_map_eq (\u03bb x, (f.commutes x).symm),\n  exact is_separable_tower_bot_of_is_separable F E E',\nend\n\nend is_separable_tower\n\nsection card_alg_hom\n\nvariables {R S T : Type*} [comm_ring S]\nvariables {K L F : Type*} [field K] [field L] [field F]\nvariables [algebra K S] [algebra K L]\n\nlemma alg_hom.card_of_power_basis (pb : power_basis K S) (h_sep : (minpoly K pb.gen).separable)\n  (h_splits : (minpoly K pb.gen).splits (algebra_map K L)) :\n  @fintype.card (S \u2192\u2090[K] L) (power_basis.alg_hom.fintype pb) = pb.dim :=\nbegin\n  let s := ((minpoly K pb.gen).map (algebra_map K L)).roots.to_finset,\n  have H := \u03bb x, multiset.mem_to_finset,\n  rw [fintype.card_congr pb.lift_equiv', fintype.card_of_subtype s H,\n      \u2190 pb.nat_degree_minpoly, nat_degree_eq_card_roots h_splits, multiset.to_finset_card_of_nodup],\n  exact nodup_roots ((separable_map (algebra_map K L)).mpr h_sep)\nend\n\nend card_alg_hom\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/field_theory/separable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7148996008545946}}
{"text": "theorem not_not (P : Prop) : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  intro HP,\n  intro HnP,\n  apply HnP,\n  exact HP\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1F/problem_bank/PB0008/S0008.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.714863482257201}}
{"text": "import tutorial_world.level08_use --hide\nopen IncidencePlane --hide\n/- Tactic : have\n\n## Summary\n`have h : P,` will create a new goal of creating a term of type `P`, and will add `h : P` to the hypotheses for the goal you were working on.\n\n## Details\nIf you want to name a term of some type (because you want it in your local context for some reason), and if you have the formula for the term, you can use have to give the term a name.\n\n## Example (have q := ... or have q : Q := ...)\nIf the local context contains\n\n```\nf : P \u2192 Q\np : P\n```\nthen the tactic `have q := f(p),` will add `q` to our local context, leaving it like this:\n\n```\nf : P \u2192 Q\np : P\nq : Q\n```\n\nIf you think about it, you don't ever really need `q`, because whenever you think you need it you coudl just use `f(p)` instead. But it's good that we can introduce convenient notation like this.\n\n## Example (have q : Q,)\nA variant of this tactic can be used where you just declare the type of the term you want to have, finish the tactic statement with a comma and no :=, and then Lean just adds it as a new goal. The number of goals goes up by one if you use `have` like this.\n\nFor example if the local context is\n\n```\nP Q R : Prop/Type,\nf : P \u2192 Q,\ng : Q \u2192 R,\np : P\n\u22a2 R\n```\nthen after `have q : Q,`, there will be the new goal\n\n```\nf : P \u2192 Q,\ng : Q \u2192 R,\np : P,\n\u22a2 Q\n```\nand your original goal will have `q : Q` added to the list of hypotheses.\n-/\n\n/-\nIn this level we introduce the new tactic `have`. It is used to add a new hypothesis\nto the context (of course, you will have to prove it!). This is sometimes useful to\nstructure our proofs. In this particular level, it is convenient to prove first that\n`r = line_through B C`, then that `s = line_through B C` and that allows us to\nfinish the prove very easily.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\n\n/- Lemma : no-side-bar\nIf two lines share two distinct points then they are the same\n-/\nlemma equal_lines_example (B C : \u03a9) (h : B \u2260 C) (r s : Line \u03a9)\n(h1 :  B \u2208 r \u2227 C \u2208 r)\n(h2 : B \u2208 s \u2227 C \u2208 s)\n: r = s :=\nbegin\n  have hr : r = line_through B C,\n  {\n    exact incidence h h1.1 h1.2,\n  },\n  rw hr,\n  have hs : s = line_through B C,\n  {\n    exact incidence h h2.1 h2.2,\n  },\n  rw hs,\nend\n", "meta": {"author": "mmasdeu", "repo": "hilbertgame", "sha": "0557019a1b7220bab7fe35729646c25bf73f0447", "save_path": "github-repos/lean/mmasdeu-hilbertgame", "path": "github-repos/lean/mmasdeu-hilbertgame/hilbertgame-0557019a1b7220bab7fe35729646c25bf73f0447/src/tutorial_world/level09_have.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7148379774104904}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau, Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes\n-/\nimport data.finset.order\nimport algebra.direct_sum.module\nimport ring_theory.free_comm_ring\nimport ring_theory.ideal.operations\n/-!\n# Direct limit of modules, abelian groups, rings, and fields.\n\nSee Atiyah-Macdonald PP.32-33, Matsumura PP.269-270\n\nGeneralizes the notion of \"union\", or \"gluing\", of incomparable modules over the same ring,\nor incomparable abelian groups, or rings, or fields.\n\nIt is constructed as a quotient of the free module (for the module case) or quotient of\nthe free commutative ring (for the ring case) instead of a quotient of the disjoint union\nso as to make the operations (addition etc.) \"computable\".\n\n## Main definitions\n\n* `directed_system f`\n* `module.direct_limit G f`\n* `add_comm_group.direct_limit G f`\n* `ring.direct_limit G f`\n\n-/\nuniverses u v w u\u2081\n\nopen submodule\n\nvariables {R : Type u} [ring R]\nvariables {\u03b9 : Type v}\nvariables [dec_\u03b9 : decidable_eq \u03b9] [preorder \u03b9]\nvariables (G : \u03b9 \u2192 Type w)\n\n/-- A directed system is a functor from a category (directed poset) to another category. -/\nclass directed_system (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192 G j) : Prop :=\n(map_self [] : \u2200 i x h, f i i h x = x)\n(map_map [] : \u2200 {i j k} hij hjk x, f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x)\n\nnamespace module\n\nvariables [\u03a0 i, add_comm_group (G i)] [\u03a0 i, module R (G i)]\n\nvariables {G} (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192\u2097[R] G j)\n\n/-- A copy of `directed_system.map_self` specialized to linear maps, as otherwise the\n`\u03bb i j h, f i j h` can confuse the simplifier. -/\nlemma directed_system.map_self [directed_system G (\u03bb i j h, f i j h)] (i x h) :\n  f i i h x = x :=\ndirected_system.map_self (\u03bb i j h, f i j h) i x h\n\n/-- A copy of `directed_system.map_map` specialized to linear maps, as otherwise the\n`\u03bb i j h, f i j h` can confuse the simplifier. -/\nlemma directed_system.map_map [directed_system G (\u03bb i j h, f i j h)] {i j k} (hij hjk x) :\n  f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x :=\ndirected_system.map_map (\u03bb i j h, f i j h) hij hjk x\n\nvariables (G)\n\ninclude dec_\u03b9\n\n/-- The direct limit of a directed system is the modules glued together along the maps. -/\ndef direct_limit : Type (max v w) :=\ndirect_sum \u03b9 G \u29f8 (span R $ { a | \u2203 (i j) (H : i \u2264 j) x,\n  direct_sum.lof R \u03b9 G i x - direct_sum.lof R \u03b9 G j (f i j H x) = a })\n\nnamespace direct_limit\n\ninstance : add_comm_group (direct_limit G f) := quotient.add_comm_group _\ninstance : module R (direct_limit G f) := quotient.module _\n\ninstance : inhabited (direct_limit G f) := \u27e80\u27e9\n\nvariables (R \u03b9)\n/-- The canonical map from a component to the direct limit. -/\ndef of (i) : G i \u2192\u2097[R] direct_limit G f :=\n(mkq _).comp $ direct_sum.lof R \u03b9 G i\nvariables {R \u03b9 G f}\n\n@[simp] lemma of_f {i j hij x} : (of R \u03b9 G f j (f i j hij x)) = of R \u03b9 G f i x :=\neq.symm $ (submodule.quotient.eq _).2 $ subset_span \u27e8i, j, hij, x, rfl\u27e9\n\n/-- Every element of the direct limit corresponds to some element in\nsome component of the directed system. -/\n\n\n@[elab_as_eliminator]\nprotected theorem induction_on [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {C : direct_limit G f \u2192 Prop}\n  (z : direct_limit G f)\n  (ih : \u2200 i x, C (of R \u03b9 G f i x)) : C z :=\nlet \u27e8i, x, h\u27e9 := exists_of z in h \u25b8 ih i x\n\nvariables {P : Type u\u2081} [add_comm_group P] [module R P] (g : \u03a0 i, G i \u2192\u2097[R] P)\nvariables (Hg : \u2200 i j hij x, g j (f i j hij x) = g i x)\ninclude Hg\n\nvariables (R \u03b9 G f)\n/-- The universal property of the direct limit: maps from the components to another module\nthat respect the directed system structure (i.e. make some diagram commute) give rise\nto a unique map out of the direct limit. -/\ndef lift : direct_limit G f \u2192\u2097[R] P :=\nliftq _ (direct_sum.to_module R \u03b9 P g)\n  (span_le.2 $ \u03bb a \u27e8i, j, hij, x, hx\u27e9, by rw [\u2190 hx, set_like.mem_coe, linear_map.sub_mem_ker_iff,\n    direct_sum.to_module_lof, direct_sum.to_module_lof, Hg])\nvariables {R \u03b9 G f}\n\nomit Hg\nlemma lift_of {i} (x) : lift R \u03b9 G f g Hg (of R \u03b9 G f i x) = g i x :=\ndirect_sum.to_module_lof R _ _\n\ntheorem lift_unique [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (F : direct_limit G f \u2192\u2097[R] P) (x) :\n  F x = lift R \u03b9 G f (\u03bb i, F.comp $ of R \u03b9 G f i)\n    (\u03bb i j hij x, by rw [linear_map.comp_apply, of_f]; refl) x :=\ndirect_limit.induction_on x $ \u03bb i x, by rw lift_of; refl\n\nsection totalize\nopen_locale classical\nvariables (G f)\nomit dec_\u03b9\n\n/-- `totalize G f i j` is a linear map from `G i` to `G j`, for *every* `i` and `j`.\nIf `i \u2264 j`, then it is the map `f i j` that comes with the directed system `G`,\nand otherwise it is the zero map. -/\nnoncomputable def totalize (i j) : G i \u2192\u2097[R] G j :=\nif h : i \u2264 j then f i j h else 0\nvariables {G f}\n\nlemma totalize_of_le {i j} (h : i \u2264 j) : totalize G f i j = f i j h := dif_pos h\n\nlemma totalize_of_not_le {i j} (h : \u00ac(i \u2264 j)) : totalize G f i j = 0 := dif_neg h\n\nend totalize\n\nvariables [directed_system G (\u03bb i j h, f i j h)]\nopen_locale classical\n\nlemma to_module_totalize_of_le {x : direct_sum \u03b9 G} {i j : \u03b9}\n  (hij : i \u2264 j) (hx : \u2200 k \u2208 x.support, k \u2264 i) :\n  direct_sum.to_module R \u03b9 (G j) (\u03bb k, totalize G f k j) x =\n  f i j hij (direct_sum.to_module R \u03b9 (G i) (\u03bb k, totalize G f k i) x) :=\nbegin\n  rw [\u2190 @dfinsupp.sum_single \u03b9 G _ _ _ x],\n  unfold dfinsupp.sum,\n  simp only [linear_map.map_sum],\n  refine finset.sum_congr rfl (\u03bb k hk, _),\n  rw [direct_sum.single_eq_lof R k (x k), direct_sum.to_module_lof, direct_sum.to_module_lof,\n    totalize_of_le (hx k hk), totalize_of_le (le_trans (hx k hk) hij), directed_system.map_map],\nend\n\nlemma of.zero_exact_aux [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {x : direct_sum \u03b9 G}\n  (H : submodule.quotient.mk x = (0 : direct_limit G f)) :\n  \u2203 j, (\u2200 k \u2208 x.support, k \u2264 j) \u2227\n    direct_sum.to_module R \u03b9 (G j) (\u03bb i, totalize G f i j) x = (0 : G j) :=\nnonempty.elim (by apply_instance) $ assume ind : \u03b9,\nspan_induction ((quotient.mk_eq_zero _).1 H)\n  (\u03bb x \u27e8i, j, hij, y, hxy\u27e9, let \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n    \u27e8k, begin\n      clear_,\n      subst hxy,\n      split,\n      { intros i0 hi0,\n        rw [dfinsupp.mem_support_iff, direct_sum.sub_apply, \u2190 direct_sum.single_eq_lof,\n            \u2190 direct_sum.single_eq_lof, dfinsupp.single_apply, dfinsupp.single_apply] at hi0,\n        split_ifs at hi0 with hi hj hj, { rwa hi at hik }, { rwa hi at hik }, { rwa hj at hjk },\n        exfalso, apply hi0, rw sub_zero },\n      simp [linear_map.map_sub, totalize_of_le, hik, hjk,\n        directed_system.map_map, direct_sum.apply_eq_component,\n        direct_sum.component.of],\n    end\u27e9)\n  \u27e8ind, \u03bb _ h, (finset.not_mem_empty _ h).elim, linear_map.map_zero _\u27e9\n  (\u03bb x y \u27e8i, hi, hxi\u27e9 \u27e8j, hj, hyj\u27e9,\n    let \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n    \u27e8k, \u03bb l hl,\n      (finset.mem_union.1 (dfinsupp.support_add hl)).elim\n        (\u03bb hl, le_trans (hi _ hl) hik)\n        (\u03bb hl, le_trans (hj _ hl) hjk),\n      by simp [linear_map.map_add, hxi, hyj,\n          to_module_totalize_of_le hik hi,\n          to_module_totalize_of_le hjk hj]\u27e9)\n  (\u03bb a x \u27e8i, hi, hxi\u27e9,\n    \u27e8i, \u03bb k hk, hi k (direct_sum.support_smul _ _ hk),\n      by simp [linear_map.map_smul, hxi]\u27e9)\n\n/-- A component that corresponds to zero in the direct limit is already zero in some\nbigger module in the directed system. -/\ntheorem of.zero_exact [is_directed \u03b9 (\u2264)] {i x} (H : of R \u03b9 G f i x = 0) :\n  \u2203 j hij, f i j hij x = (0 : G j) :=\nby haveI : nonempty \u03b9 := \u27e8i\u27e9; exact\nlet \u27e8j, hj, hxj\u27e9 := of.zero_exact_aux H in\nif hx0 : x = 0 then \u27e8i, le_rfl, by simp [hx0]\u27e9\nelse\n  have hij : i \u2264 j, from hj _ $\n    by simp [direct_sum.apply_eq_component, hx0],\n  \u27e8j, hij, by simpa [totalize_of_le hij] using hxj\u27e9\n\nend direct_limit\n\nend module\n\n\nnamespace add_comm_group\n\nvariables [\u03a0 i, add_comm_group (G i)]\ninclude dec_\u03b9\n\n/-- The direct limit of a directed system is the abelian groups glued together along the maps. -/\ndef direct_limit (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192+ G j) : Type* :=\n@module.direct_limit \u2124 _ \u03b9 _ _ G _ _\n  (\u03bb i j hij, (f i j hij).to_int_linear_map)\n\nnamespace direct_limit\n\nvariables (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192+ G j)\n\nomit dec_\u03b9\n\nprotected lemma directed_system [h : directed_system G (\u03bb i j h, f i j h)] :\n  directed_system G (\u03bb i j hij, (f i j hij).to_int_linear_map) :=\nh\n\ninclude dec_\u03b9\n\nlocal attribute [instance] direct_limit.directed_system\n\ninstance : add_comm_group (direct_limit G f) :=\nmodule.direct_limit.add_comm_group G (\u03bb i j hij, (f i j hij).to_int_linear_map)\n\ninstance : inhabited (direct_limit G f) := \u27e80\u27e9\n\n/-- The canonical map from a component to the direct limit. -/\ndef of (i) : G i \u2192\u2097[\u2124] direct_limit G f :=\nmodule.direct_limit.of \u2124 \u03b9 G (\u03bb i j hij, (f i j hij).to_int_linear_map) i\nvariables {G f}\n\n@[simp] lemma of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=\nmodule.direct_limit.of_f\n\n@[elab_as_eliminator]\nprotected theorem induction_on [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {C : direct_limit G f \u2192 Prop}\n  (z : direct_limit G f) (ih : \u2200 i x, C (of G f i x)) : C z :=\nmodule.direct_limit.induction_on z ih\n\n/-- A component that corresponds to zero in the direct limit is already zero in some\nbigger module in the directed system. -/\ntheorem of.zero_exact [is_directed \u03b9 (\u2264)] [directed_system G (\u03bb i j h, f i j h)] (i x)\n  (h : of G f i x = 0) :\n  \u2203 j hij, f i j hij x = 0 :=\nmodule.direct_limit.of.zero_exact h\n\nvariables (P : Type u\u2081) [add_comm_group P]\nvariables (g : \u03a0 i, G i \u2192+ P)\nvariables (Hg : \u2200 i j hij x, g j (f i j hij x) = g i x)\n\nvariables (G f)\n/-- The universal property of the direct limit: maps from the components to another abelian group\nthat respect the directed system structure (i.e. make some diagram commute) give rise\nto a unique map out of the direct limit. -/\ndef lift : direct_limit G f \u2192\u2097[\u2124] P :=\nmodule.direct_limit.lift \u2124 \u03b9 G (\u03bb i j hij, (f i j hij).to_int_linear_map)\n  (\u03bb i, (g i).to_int_linear_map) Hg\nvariables {G f}\n\n@[simp] lemma lift_of (i x) : lift G f P g Hg (of G f i x) = g i x :=\nmodule.direct_limit.lift_of _ _ _\n\nlemma lift_unique [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (F : direct_limit G f \u2192+ P) (x) :\n  F x = lift G f P (\u03bb i, F.comp (of G f i).to_add_monoid_hom)\n    (\u03bb i j hij x, by simp) x :=\ndirect_limit.induction_on x $ \u03bb i x, by simp\n\nend direct_limit\n\nend add_comm_group\n\n\nnamespace ring\n\nvariables [\u03a0 i, comm_ring (G i)]\n\nsection\nvariables (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192 G j)\n\nopen free_comm_ring\n\n/-- The direct limit of a directed system is the rings glued together along the maps. -/\ndef direct_limit : Type (max v w) :=\nfree_comm_ring (\u03a3 i, G i) \u29f8 (ideal.span { a |\n  (\u2203 i j H x, of (\u27e8j, f i j H x\u27e9 : \u03a3 i, G i) - of \u27e8i, x\u27e9 = a) \u2228\n  (\u2203 i, of (\u27e8i, 1\u27e9 : \u03a3 i, G i) - 1 = a) \u2228\n  (\u2203 i x y, of (\u27e8i, x + y\u27e9 : \u03a3 i, G i) - (of \u27e8i, x\u27e9 + of \u27e8i, y\u27e9) = a) \u2228\n  (\u2203 i x y, of (\u27e8i, x * y\u27e9 : \u03a3 i, G i) - (of \u27e8i, x\u27e9 * of \u27e8i, y\u27e9) = a) })\n\nnamespace direct_limit\n\ninstance : comm_ring (direct_limit G f) :=\nideal.quotient.comm_ring _\n\ninstance : ring (direct_limit G f) :=\ncomm_ring.to_ring _\n\ninstance : inhabited (direct_limit G f) := \u27e80\u27e9\n\n/-- The canonical map from a component to the direct limit. -/\ndef of (i) : G i \u2192+* direct_limit G f :=\nring_hom.mk'\n{ to_fun := \u03bb x, ideal.quotient.mk _ (of (\u27e8i, x\u27e9 : \u03a3 i, G i)),\n  map_one' := ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inl \u27e8i, rfl\u27e9,\n  map_mul' := \u03bb x y, ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inr $ or.inr \u27e8i, x, y, rfl\u27e9, }\n(\u03bb x y, ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inr $ or.inl \u27e8i, x, y, rfl\u27e9)\n\nvariables {G f}\n\n@[simp] lemma of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=\nideal.quotient.eq.2 $ subset_span $ or.inl \u27e8i, j, hij, x, rfl\u27e9\n\n/-- Every element of the direct limit corresponds to some element in\nsome component of the directed system. -/\ntheorem exists_of [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (z : direct_limit G f) :\n  \u2203 i x, of G f i x = z :=\nnonempty.elim (by apply_instance) $ assume ind : \u03b9,\nquotient.induction_on' z $ \u03bb x, free_abelian_group.induction_on x\n  \u27e8ind, 0, (of _ _ ind).map_zero\u27e9\n  (\u03bb s, multiset.induction_on s\n    \u27e8ind, 1, (of _ _ ind).map_one\u27e9\n    (\u03bb a s ih, let \u27e8i, x\u27e9 := a, \u27e8j, y, hs\u27e9 := ih, \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n      \u27e8k, f i k hik x * f j k hjk y, by rw [(of _ _ _).map_mul, of_f, of_f, hs]; refl\u27e9))\n  (\u03bb s \u27e8i, x, ih\u27e9, \u27e8i, -x, by rw [(of _ _ _).map_neg, ih]; refl\u27e9)\n  (\u03bb p q \u27e8i, x, ihx\u27e9 \u27e8j, y, ihy\u27e9, let \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n    \u27e8k, f i k hik x + f j k hjk y, by rw [(of _ _ _).map_add, of_f, of_f, ihx, ihy]; refl\u27e9)\n\n\nsection\nopen_locale classical\nopen polynomial\n\nvariables {f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j}\n\ntheorem polynomial.exists_of [nonempty \u03b9] [is_directed \u03b9 (\u2264)]\n  (q : polynomial (direct_limit G (\u03bb i j h, f' i j h))) :\n  \u2203 i p, polynomial.map (of G (\u03bb i j h, f' i j h) i) p = q :=\npolynomial.induction_on q\n  (\u03bb z, let \u27e8i, x, h\u27e9 := exists_of z in \u27e8i, C x, by rw [map_C, h]\u27e9)\n  (\u03bb q\u2081 q\u2082 \u27e8i\u2081, p\u2081, ih\u2081\u27e9 \u27e8i\u2082, p\u2082, ih\u2082\u27e9, let \u27e8i, h1, h2\u27e9 := exists_ge_ge i\u2081 i\u2082 in\n    \u27e8i, p\u2081.map (f' i\u2081 i h1) + p\u2082.map (f' i\u2082 i h2),\n     by { rw [polynomial.map_add, map_map, map_map, \u2190 ih\u2081, \u2190 ih\u2082],\n      congr' 2; ext x; simp_rw [ring_hom.comp_apply, of_f] }\u27e9)\n  (\u03bb n z ih, let \u27e8i, x, h\u27e9 := exists_of z in \u27e8i, C x * X ^ (n + 1),\n    by rw [polynomial.map_mul, map_C, h, polynomial.map_pow, map_X]\u27e9)\n\nend\n\n@[elab_as_eliminator] theorem induction_on [nonempty \u03b9] [is_directed \u03b9 (\u2264)]\n  {C : direct_limit G f \u2192 Prop}\n  (z : direct_limit G f) (ih : \u2200 i x, C (of G f i x)) : C z :=\nlet \u27e8i, x, hx\u27e9 := exists_of z in hx \u25b8 ih i x\n\nsection of_zero_exact\nopen_locale classical\n\nvariables (f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j)\nvariables [directed_system G (\u03bb i j h, f' i j h)]\nvariables (G f)\n\nlemma of.zero_exact_aux2 {x : free_comm_ring \u03a3 i, G i} {s t} (hxs : is_supported x s) {j k}\n  (hj : \u2200 z : \u03a3 i, G i, z \u2208 s \u2192 z.1 \u2264 j) (hk : \u2200 z : \u03a3 i, G i, z \u2208 t \u2192 z.1 \u2264 k)\n  (hjk : j \u2264 k) (hst : s \u2286 t) :\n  f' j k hjk (lift (\u03bb ix : s, f' ix.1.1 j (hj ix ix.2) ix.1.2) (restriction s x)) =\n  lift (\u03bb ix : t, f' ix.1.1 k (hk ix ix.2) ix.1.2) (restriction t x) :=\nbegin\n  refine subring.in_closure.rec_on hxs _ _ _ _,\n  { rw [(restriction _).map_one, (free_comm_ring.lift _).map_one, (f' j k hjk).map_one,\n        (restriction _).map_one, (free_comm_ring.lift _).map_one] },\n  { rw [(restriction _).map_neg, (restriction _).map_one,\n        (free_comm_ring.lift _).map_neg, (free_comm_ring.lift _).map_one,\n        (f' j k hjk).map_neg, (f' j k hjk).map_one,\n        (restriction _).map_neg, (restriction _).map_one,\n        (free_comm_ring.lift _).map_neg, (free_comm_ring.lift _).map_one] },\n  { rintros _ \u27e8p, hps, rfl\u27e9 n ih,\n    rw [(restriction _).map_mul, (free_comm_ring.lift _).map_mul,\n        (f' j k hjk).map_mul, ih,\n        (restriction _).map_mul, (free_comm_ring.lift _).map_mul,\n        restriction_of, dif_pos hps, lift_of, restriction_of, dif_pos (hst hps), lift_of],\n    dsimp only,\n    have := directed_system.map_map (\u03bb i j h, f' i j h),\n    dsimp only at this,\n    rw this, refl },\n  { rintros x y ihx ihy,\n    rw [(restriction _).map_add, (free_comm_ring.lift _).map_add,\n        (f' j k hjk).map_add, ihx, ihy,\n        (restriction _).map_add, (free_comm_ring.lift _).map_add] }\nend\nvariables {G f f'}\n\nlemma of.zero_exact_aux [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {x : free_comm_ring \u03a3 i, G i}\n  (H : ideal.quotient.mk _ x = (0 : direct_limit G (\u03bb i j h, f' i j h))) :\n  \u2203 j s, \u2203 H : (\u2200 k : \u03a3 i, G i, k \u2208 s \u2192 k.1 \u2264 j), is_supported x s \u2227\n    lift (\u03bb ix : s, f' ix.1.1 j (H ix ix.2) ix.1.2) (restriction s x) = (0 : G j) :=\nbegin\n  refine span_induction (ideal.quotient.eq_zero_iff_mem.1 H) _ _ _ _,\n  { rintros x (\u27e8i, j, hij, x, rfl\u27e9 | \u27e8i, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9),\n    { refine \u27e8j, {\u27e8i, x\u27e9, \u27e8j, f' i j hij x\u27e9}, _,\n        is_supported_sub (is_supported_of.2 $ or.inr rfl) (is_supported_of.2 $ or.inl rfl), _\u27e9,\n      { rintros k (rfl | \u27e8rfl | _\u27e9), exact hij, refl },\n      { rw [(restriction _).map_sub, (free_comm_ring.lift _).map_sub,\n            restriction_of, dif_pos, restriction_of, dif_pos, lift_of, lift_of],\n        dsimp only,\n        have := directed_system.map_map (\u03bb i j h, f' i j h),\n        dsimp only at this,\n        rw this, exact sub_self _,\n        exacts [or.inr rfl, or.inl rfl] } },\n    { refine \u27e8i, {\u27e8i, 1\u27e9}, _, is_supported_sub (is_supported_of.2 rfl) is_supported_one, _\u27e9,\n      { rintros k (rfl|h), refl },\n      { rw [(restriction _).map_sub, (free_comm_ring.lift _).map_sub, restriction_of, dif_pos,\n          (restriction _).map_one, lift_of, (free_comm_ring.lift _).map_one],\n        dsimp only, rw [(f' i i _).map_one, sub_self],\n        { exact set.mem_singleton _ } } },\n    { refine \u27e8i, {\u27e8i, x+y\u27e9, \u27e8i, x\u27e9, \u27e8i, y\u27e9}, _,\n        is_supported_sub (is_supported_of.2 $ or.inl rfl)\n          (is_supported_add (is_supported_of.2 $ or.inr $ or.inl rfl)\n            (is_supported_of.2 $ or.inr $ or.inr rfl)), _\u27e9,\n      { rintros k (rfl | \u27e8rfl | \u27e8rfl | hk\u27e9\u27e9); refl },\n      { rw [(restriction _).map_sub, (restriction _).map_add,\n            restriction_of, restriction_of, restriction_of,\n            dif_pos, dif_pos, dif_pos,\n            (free_comm_ring.lift _).map_sub, (free_comm_ring.lift _).map_add,\n            lift_of, lift_of, lift_of],\n        dsimp only, rw (f' i i _).map_add, exact sub_self _,\n        exacts [or.inl rfl, or.inr (or.inr rfl), or.inr (or.inl rfl)] } },\n    { refine \u27e8i, {\u27e8i, x*y\u27e9, \u27e8i, x\u27e9, \u27e8i, y\u27e9}, _,\n        is_supported_sub (is_supported_of.2 $ or.inl rfl)\n          (is_supported_mul (is_supported_of.2 $ or.inr $ or.inl rfl)\n            (is_supported_of.2 $ or.inr $ or.inr rfl)), _\u27e9,\n      { rintros k (rfl | \u27e8rfl | \u27e8rfl | hk\u27e9\u27e9); refl },\n      { rw [(restriction _).map_sub, (restriction _).map_mul,\n            restriction_of, restriction_of, restriction_of,\n            dif_pos, dif_pos, dif_pos,\n            (free_comm_ring.lift _).map_sub, (free_comm_ring.lift _).map_mul,\n            lift_of, lift_of, lift_of],\n        dsimp only, rw (f' i i _).map_mul,\n        exacts [sub_self _, or.inl rfl, or.inr (or.inr rfl),\n          or.inr (or.inl rfl)] } } },\n  { refine nonempty.elim (by apply_instance) (assume ind : \u03b9, _),\n    refine \u27e8ind, \u2205, \u03bb _, false.elim, is_supported_zero, _\u27e9,\n    rw [(restriction _).map_zero, (free_comm_ring.lift _).map_zero] },\n  { rintros x y \u27e8i, s, hi, hxs, ihs\u27e9 \u27e8j, t, hj, hyt, iht\u27e9,\n    obtain \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j,\n    have : \u2200 z : \u03a3 i, G i, z \u2208 s \u222a t \u2192 z.1 \u2264 k,\n    { rintros z (hz | hz), exact le_trans (hi z hz) hik, exact le_trans (hj z hz) hjk },\n    refine \u27e8k, s \u222a t, this, is_supported_add (is_supported_upwards hxs $ set.subset_union_left s t)\n      (is_supported_upwards hyt $ set.subset_union_right s t), _\u27e9,\n    { rw [(restriction _).map_add, (free_comm_ring.lift _).map_add,\n        \u2190 of.zero_exact_aux2 G f' hxs hi this hik (set.subset_union_left s t),\n        \u2190 of.zero_exact_aux2 G f' hyt hj this hjk (set.subset_union_right s t),\n        ihs, (f' i k hik).map_zero, iht, (f' j k hjk).map_zero, zero_add] } },\n  { rintros x y \u27e8j, t, hj, hyt, iht\u27e9, rw smul_eq_mul,\n    rcases exists_finset_support x with \u27e8s, hxs\u27e9,\n    rcases (s.image sigma.fst).exists_le with \u27e8i, hi\u27e9,\n    obtain \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j,\n    have : \u2200 z : \u03a3 i, G i, z \u2208 \u2191s \u222a t \u2192 z.1 \u2264 k,\n    { rintros z (hz | hz),\n      exacts [(hi z.1 $ finset.mem_image.2 \u27e8z, hz, rfl\u27e9).trans hik, (hj z hz).trans hjk] },\n    refine \u27e8k, \u2191s \u222a t, this, is_supported_mul\n      (is_supported_upwards hxs $ set.subset_union_left \u2191s t)\n      (is_supported_upwards hyt $ set.subset_union_right \u2191s t), _\u27e9,\n    rw [(restriction _).map_mul, (free_comm_ring.lift _).map_mul,\n        \u2190 of.zero_exact_aux2 G f' hyt hj this hjk (set.subset_union_right \u2191s t),\n        iht, (f' j k hjk).map_zero, mul_zero] }\nend\n\n/-- A component that corresponds to zero in the direct limit is already zero in some\nbigger module in the directed system. -/\nlemma of.zero_exact [is_directed \u03b9 (\u2264)] {i x} (hix : of G (\u03bb i j h, f' i j h) i x = 0) :\n  \u2203 j (hij : i \u2264 j), f' i j hij x = 0 :=\nby haveI : nonempty \u03b9 := \u27e8i\u27e9; exact\nlet \u27e8j, s, H, hxs, hx\u27e9 := of.zero_exact_aux hix in\nhave hixs : (\u27e8i, x\u27e9 : \u03a3 i, G i) \u2208 s, from is_supported_of.1 hxs,\n\u27e8j, H \u27e8i, x\u27e9 hixs, by rw [restriction_of, dif_pos hixs, lift_of] at hx; exact hx\u27e9\nend of_zero_exact\n\nvariables (f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j)\n\n/-- If the maps in the directed system are injective, then the canonical maps\nfrom the components to the direct limits are injective. -/\ntheorem of_injective [is_directed \u03b9 (\u2264)] [directed_system G (\u03bb i j h, f' i j h)]\n  (hf : \u2200 i j hij, function.injective (f' i j hij)) (i) :\n  function.injective (of G (\u03bb i j h, f' i j h) i) :=\nbegin\n  suffices : \u2200 x, of G (\u03bb i j h, f' i j h) i x = 0 \u2192 x = 0,\n  { intros x y hxy, rw \u2190 sub_eq_zero, apply this,\n    rw [(of G _ i).map_sub, hxy, sub_self] },\n  intros x hx, rcases of.zero_exact hx with \u27e8j, hij, hfx\u27e9,\n  apply hf i j hij, rw [hfx, (f' i j hij).map_zero]\nend\n\nvariables (P : Type u\u2081) [comm_ring P]\nvariables (g : \u03a0 i, G i \u2192+* P)\nvariables (Hg : \u2200 i j hij x, g j (f i j hij x) = g i x)\ninclude Hg\n\nopen free_comm_ring\n\nvariables (G f)\n/-- The universal property of the direct limit: maps from the components to another ring\nthat respect the directed system structure (i.e. make some diagram commute) give rise\nto a unique map out of the direct limit.\n-/\ndef lift : direct_limit G f \u2192+* P :=\nideal.quotient.lift _ (free_comm_ring.lift $ \u03bb (x : \u03a3 i, G i), g x.1 x.2) begin\n  suffices : ideal.span _ \u2264\n    ideal.comap (free_comm_ring.lift (\u03bb (x : \u03a3 (i : \u03b9), G i), g (x.fst) (x.snd))) \u22a5,\n  { intros x hx, exact (mem_bot P).1 (this hx) },\n  rw ideal.span_le, intros x hx,\n  rw [set_like.mem_coe, ideal.mem_comap, mem_bot],\n  rcases hx with \u27e8i, j, hij, x, rfl\u27e9 | \u27e8i, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9;\n  simp only [ring_hom.map_sub, lift_of, Hg, ring_hom.map_one, ring_hom.map_add, ring_hom.map_mul,\n      (g i).map_one, (g i).map_add, (g i).map_mul, sub_self]\nend\n\nvariables {G f}\nomit Hg\n\n@[simp] lemma lift_of (i x) : lift G f P g Hg (of G f i x) = g i x := free_comm_ring.lift_of _ _\n\ntheorem lift_unique [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (F : direct_limit G f \u2192+* P) (x) :\n  F x = lift G f P (\u03bb i, F.comp $ of G f i) (\u03bb i j hij x, by simp) x :=\ndirect_limit.induction_on x $ \u03bb i x, by simp\n\nend direct_limit\n\nend\n\nend ring\n\n\nnamespace field\n\nvariables [nonempty \u03b9] [is_directed \u03b9 (\u2264)] [\u03a0 i, field (G i)]\nvariables (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192 G j)\nvariables (f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j)\n\nnamespace direct_limit\n\ninstance nontrivial [directed_system G (\u03bb i j h, f' i j h)] :\n  nontrivial (ring.direct_limit G (\u03bb i j h, f' i j h)) :=\n\u27e8\u27e80, 1, nonempty.elim (by apply_instance) $ assume i : \u03b9, begin\n  change (0 : ring.direct_limit G (\u03bb i j h, f' i j h)) \u2260 1,\n  rw \u2190 (ring.direct_limit.of _ _ _).map_one,\n  intros H, rcases ring.direct_limit.of.zero_exact H.symm with \u27e8j, hij, hf\u27e9,\n  rw (f' i j hij).map_one at hf,\n  exact one_ne_zero hf\nend \u27e9\u27e9\n\ntheorem exists_inv {p : ring.direct_limit G f} : p \u2260 0 \u2192 \u2203 y, p * y = 1 :=\nring.direct_limit.induction_on p $ \u03bb i x H,\n\u27e8ring.direct_limit.of G f i (x\u207b\u00b9), by erw [\u2190 (ring.direct_limit.of _ _ _).map_mul,\n    mul_inv_cancel (assume h : x = 0, H $ by rw [h, (ring.direct_limit.of _ _ _).map_zero]),\n    (ring.direct_limit.of _ _ _).map_one]\u27e9\n\nsection\nopen_locale classical\n\n/-- Noncomputable multiplicative inverse in a direct limit of fields. -/\nnoncomputable def inv (p : ring.direct_limit G f) : ring.direct_limit G f :=\nif H : p = 0 then 0 else classical.some (direct_limit.exists_inv G f H)\n\nprotected theorem mul_inv_cancel {p : ring.direct_limit G f} (hp : p \u2260 0) : p * inv G f p = 1 :=\nby rw [inv, dif_neg hp, classical.some_spec (direct_limit.exists_inv G f hp)]\n\nprotected theorem inv_mul_cancel {p : ring.direct_limit G f} (hp : p \u2260 0) : inv G f p * p = 1 :=\nby rw [_root_.mul_comm, direct_limit.mul_inv_cancel G f hp]\n\n/-- Noncomputable field structure on the direct limit of fields.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected noncomputable def field [directed_system G (\u03bb i j h, f' i j h)] :\n  field (ring.direct_limit G (\u03bb i j h, f' i j h)) :=\n{ inv := inv G (\u03bb i j h, f' i j h),\n  mul_inv_cancel := \u03bb p, direct_limit.mul_inv_cancel G (\u03bb i j h, f' i j h),\n  inv_zero := dif_pos rfl,\n  .. ring.direct_limit.comm_ring G (\u03bb i j h, f' i j h),\n  .. direct_limit.nontrivial G (\u03bb i j h, f' i j h) }\n\nend\n\nend direct_limit\n\nend field\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/direct_limit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7148379728197164}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Chris Hughes, Morenikeji Neri\n-/\nimport ring_theory.noetherian\nimport ring_theory.unique_factorization_domain\n/-!\n# Principal ideal rings and principal ideal domains\n\nA principal ideal ring (PIR) is a commutative ring in which all ideals are principal. A\nprincipal ideal domain (PID) is an integral domain which is a principal ideal ring.\n\n# Main definitions\n\nNote that for principal ideal domains, one should use\n`[integral domain R] [is_principal_ideal_ring R]`. There is no explicit definition of a PID.\nTheorems about PID's are in the `principal_ideal_ring` namespace.\n\n- `is_principal_ideal_ring`: a predicate on commutative rings, saying that every\n  ideal is principal.\n- `generator`: a generator of a principal ideal (or more generally submodule)\n- `to_unique_factorization_monoid`: a PID is a unique factorization domain\n\n# Main results\n\n- `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.\n- `euclidean_domain.to_principal_ideal_domain` : a Euclidean domain is a PID.\n\n-/\nuniverses u v\nvariables {R : Type u} {M : Type v}\n\nopen set function\nopen submodule\nopen_locale classical\n\n/-- An `R`-submodule of `M` is principal if it is generated by one element. -/\nclass submodule.is_principal [ring R] [add_comm_group M] [module R M] (S : submodule R M) : Prop :=\n(principal [] : \u2203 a, S = span R {a})\n\n/-- A commutative ring is a principal ideal ring if all ideals are principal. -/\nclass is_principal_ideal_ring (R : Type u) [comm_ring R] : Prop :=\n(principal : \u2200 (S : ideal R), S.is_principal)\n\nattribute [instance] is_principal_ideal_ring.principal\n\nnamespace submodule.is_principal\n\nvariables [comm_ring R] [add_comm_group M] [module R M]\n\n/-- `generator I`, if `I` is a principal submodule, is an `x \u2208 M` such that `span R {x} = I` -/\nnoncomputable def generator (S : submodule R M) [S.is_principal] : M :=\nclassical.some (principal S)\n\nlemma span_singleton_generator (S : submodule R M) [S.is_principal] : span R {generator S} = S :=\neq.symm (classical.some_spec (principal S))\n\n@[simp] lemma generator_mem (S : submodule R M) [S.is_principal] : generator S \u2208 S :=\nby { conv_rhs { rw \u2190 span_singleton_generator S }, exact subset_span (mem_singleton _) }\n\nlemma mem_iff_eq_smul_generator (S : submodule R M) [S.is_principal] {x : M} :\n  x \u2208 S \u2194 \u2203 s : R, x = s \u2022 generator S :=\nby simp_rw [@eq_comm _ x, \u2190 mem_span_singleton, span_singleton_generator]\n\nlemma mem_iff_generator_dvd (S : ideal R) [S.is_principal] {x : R} : x \u2208 S \u2194 generator S \u2223 x :=\n(mem_iff_eq_smul_generator S).trans (exists_congr (\u03bb a, by simp only [mul_comm, smul_eq_mul]))\n\nlemma eq_bot_iff_generator_eq_zero (S : submodule R M) [S.is_principal] :\n  S = \u22a5 \u2194 generator S = 0 :=\nby rw [\u2190 @span_singleton_eq_bot R M, span_singleton_generator]\n\nend submodule.is_principal\n\nnamespace ideal.is_prime\nopen submodule.is_principal ideal\n\n-- TODO -- for a non-ID one could perhaps prove that if p < q are prime then q maximal;\n-- 0 isn't prime in a non-ID PIR but the Krull dimension is still <= 1.\n-- The below result follows from this, but we could also use the below result to\n-- prove this (quotient out by p).\nlemma to_maximal_ideal [integral_domain R] [is_principal_ideal_ring R] {S : ideal R}\n  [hpi : is_prime S] (hS : S \u2260 \u22a5) : is_maximal S :=\nis_maximal_iff.2 \u27e8(ne_top_iff_one S).1 hpi.1, begin\n  assume T x hST hxS hxT,\n  cases (mem_iff_generator_dvd _).1 (hST $ generator_mem S) with z hz,\n  cases hpi.mem_or_mem (show generator T * z \u2208 S, from hz \u25b8 generator_mem S),\n  { have hTS : T \u2264 S, rwa [\u2190 span_singleton_generator T, submodule.span_le, singleton_subset_iff],\n    exact (hxS $ hTS hxT).elim },\n  cases (mem_iff_generator_dvd _).1 h with y hy,\n  have : generator S \u2260 0 := mt (eq_bot_iff_generator_eq_zero _).2 hS,\n  rw [\u2190 mul_one (generator S), hy, mul_left_comm, mul_right_inj' this] at hz,\n  exact hz.symm \u25b8 T.mul_mem_right _ (generator_mem T)\nend\u27e9\n\nend ideal.is_prime\n\nsection\nopen euclidean_domain\nvariable [euclidean_domain R]\n\nlemma mod_mem_iff {S : ideal R} {x y : R} (hy : y \u2208 S) : x % y \u2208 S \u2194 x \u2208 S :=\n\u27e8\u03bb hxy, div_add_mod x y \u25b8 S.add_mem (S.mul_mem_right _ hy) hxy,\n  \u03bb hx, (mod_eq_sub_mul_div x y).symm \u25b8 S.sub_mem hx (S.mul_mem_right _ hy)\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance euclidean_domain.to_principal_ideal_domain : is_principal_ideal_ring R :=\n{ principal := \u03bb S, by exactI\n    \u27e8if h : {x : R | x \u2208 S \u2227 x \u2260 0}.nonempty\n    then\n    have wf : well_founded (euclidean_domain.r : R \u2192 R \u2192 Prop) := euclidean_domain.r_well_founded,\n    have hmin : well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h \u2208 S \u2227\n        well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h \u2260 0,\n      from well_founded.min_mem wf {x : R | x \u2208 S \u2227 x \u2260 0} h,\n    \u27e8well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h,\n      submodule.ext $ \u03bb x,\n      \u27e8\u03bb hx, div_add_mod x (well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h) \u25b8\n        (ideal.mem_span_singleton.2 $ dvd_add (dvd_mul_right _ _) $\n        have (x % (well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h) \u2209 {x : R | x \u2208 S \u2227 x \u2260 0}),\n          from \u03bb h\u2081, well_founded.not_lt_min wf _ h h\u2081 (mod_lt x hmin.2),\n        have x % well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h = 0, by finish [(mod_mem_iff hmin.1).2 hx],\n        by simp *),\n      \u03bb hx, let \u27e8y, hy\u27e9 := ideal.mem_span_singleton.1 hx in hy.symm \u25b8 S.mul_mem_right _ hmin.1\u27e9\u27e9\n    else \u27e80, submodule.ext $ \u03bb a, by rw [\u2190 @submodule.bot_coe R R _ _ _, span_eq, submodule.mem_bot]; exact\n      \u27e8\u03bb haS, by_contradiction $ \u03bb ha0, h \u27e8a, \u27e8haS, ha0\u27e9\u27e9,\n      \u03bb h\u2081, h\u2081.symm \u25b8 S.zero_mem\u27e9\u27e9\u27e9 }\n\nend\n\nnamespace principal_ideal_ring\nopen is_principal_ideal_ring\n\nvariables [integral_domain R] [is_principal_ideal_ring R]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_noetherian_ring : is_noetherian_ring R :=\nis_noetherian_ring_iff.2 \u27e8assume s : ideal R,\nbegin\n  rcases (is_principal_ideal_ring.principal s).principal with \u27e8a, rfl\u27e9,\n  rw [\u2190 finset.coe_singleton],\n  exact \u27e8{a}, submodule.coe_injective rfl\u27e9\nend\u27e9\n\nlemma is_maximal_of_irreducible {p : R} (hp : irreducible p) :\n  ideal.is_maximal (span R ({p} : set R)) :=\n\u27e8\u27e8mt ideal.span_singleton_eq_top.1 hp.1, \u03bb I hI, begin\n  rcases principal I with \u27e8a, rfl\u27e9,\n  erw ideal.span_singleton_eq_top,\n  unfreezingI { rcases ideal.span_singleton_le_span_singleton.1 (le_of_lt hI) with \u27e8b, rfl\u27e9 },\n  refine (of_irreducible_mul hp).resolve_right (mt (\u03bb hb, _) (not_le_of_lt hI)),\n  erw [ideal.span_singleton_le_span_singleton, is_unit.mul_right_dvd hb]\nend\u27e9\u27e9\n\nlemma irreducible_iff_prime {p : R} : irreducible p \u2194 prime p :=\n\u27e8\u03bb hp, (ideal.span_singleton_prime hp.ne_zero).1 $\n    (is_maximal_of_irreducible hp).is_prime,\n  irreducible_of_prime\u27e9\n\nlemma associates_irreducible_iff_prime : \u2200{p : associates R}, irreducible p \u2194 prime p :=\nassociates.irreducible_iff_prime_iff.1 (\u03bb _, irreducible_iff_prime)\n\nsection\nopen_locale classical\n\n/-- `factors a` is a multiset of irreducible elements whose product is `a`, up to units -/\nnoncomputable def factors (a : R) : multiset R :=\nif h : a = 0 then \u2205 else classical.some (wf_dvd_monoid.exists_factors a h)\n\nlemma factors_spec (a : R) (h : a \u2260 0) :\n  (\u2200b\u2208factors a, irreducible b) \u2227 associated (factors a).prod a :=\nbegin\n  unfold factors, rw [dif_neg h],\n  exact classical.some_spec (wf_dvd_monoid.exists_factors a h)\nend\n\nlemma ne_zero_of_mem_factors {R : Type v} [integral_domain R] [is_principal_ideal_ring R] {a b : R}\n  (ha : a \u2260 0) (hb : b \u2208 factors a) : b \u2260 0 := irreducible.ne_zero ((factors_spec a ha).1 b hb)\n\nlemma mem_submonoid_of_factors_subset_of_units_subset (s : submonoid R)\n  {a : R} (ha : a \u2260 0) (hfac : \u2200 b \u2208 factors a, b \u2208 s) (hunit : \u2200 c : units R, (c : R) \u2208 s) :\n  a \u2208 s :=\nbegin\n  rcases ((factors_spec a ha).2) with \u27e8c, hc\u27e9,\n  rw [\u2190 hc],\n  exact submonoid.mul_mem _ (submonoid.multiset_prod_mem _ _ hfac) (hunit _),\nend\n\n/-- If a `ring_hom` maps all units and all factors of an element `a` into a submonoid `s`, then it\nalso maps `a` into that submonoid. -/\nlemma ring_hom_mem_submonoid_of_factors_subset_of_units_subset {R S : Type*}\n  [integral_domain R] [is_principal_ideal_ring R] [semiring S]\n  (f : R \u2192+* S) (s : submonoid S) (a : R) (ha : a \u2260 0)\n  (h : \u2200 b \u2208 factors a, f b \u2208 s) (hf: \u2200 c : units R, f c \u2208 s) :\n  f a \u2208 s :=\nmem_submonoid_of_factors_subset_of_units_subset (s.comap f.to_monoid_hom) ha h hf\n\n/-- A principal ideal domain has unique factorization -/\n@[priority 100] -- see Note [lower instance priority]\ninstance to_unique_factorization_monoid : unique_factorization_monoid R :=\n{ irreducible_iff_prime := \u03bb _, principal_ideal_ring.irreducible_iff_prime\n  .. (is_noetherian_ring.wf_dvd_monoid : wf_dvd_monoid R) }\n\nend\n\nend principal_ideal_ring\n\nopen submodule\n\n@[simp] lemma ideal.span_image {R S : Type*}\n  [comm_ring R] [comm_ring S] (f : R \u2192+* S) (s : set R) :\n  ideal.span (f '' s) = ideal.map f (ideal.span s) :=\nspan_eq_of_le _\n  (\u03bb y \u27e8x, hy, x_eq\u27e9, x_eq \u25b8 ideal.mem_map_of_mem (subset_span hy))\n  (ideal.map_le_iff_le_comap.2 $ span_le.2 $ image_subset_iff.1 subset_span)\n\n@[simp] lemma ideal.span_image' {R S : Type*}\n  [comm_ring R] [comm_ring S] (f : R \u2192+* S) (s : set R) :\n  submodule.span S (f '' s) = ideal.map f (submodule.span R s) :=\nideal.span_image f s\n\nlemma ideal.is_principal.of_comap {R S : Type*}\n  [comm_ring R] [comm_ring S]\n  (f : R \u2192+* S) (hf : function.surjective f)\n  (I : ideal S) [hI : is_principal (I.comap f)] :\n  is_principal I :=\n\u27e8\u27e8f (is_principal.generator (I.comap f)),\n  by rw [\u2190 set.image_singleton, ideal.span_image',\n         is_principal.span_singleton_generator, ideal.map_comap_of_surjective f hf]\u27e9\u27e9\n\n/-- The surjective image of a principal ideal ring is again a principal ideal ring. -/\nlemma is_principal_ideal_ring.of_surjective {R S : Type*}\n  [comm_ring R] [comm_ring S] [is_principal_ideal_ring R]\n  (f : R \u2192+* S) (hf : function.surjective f) :\n  is_principal_ideal_ring S :=\n\u27e8\u03bb I, ideal.is_principal.of_comap f hf I\u27e9\n", "meta": {"author": "lean-forward", "repo": "class-number", "sha": "812ff19e6fbde86f8d71689851adaa2bbae9695e", "save_path": "github-repos/lean/lean-forward-class-number", "path": "github-repos/lean/lean-forward-class-number/class-number-812ff19e6fbde86f8d71689851adaa2bbae9695e/src/principal_ideal_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7148379717451946}}
{"text": "/-\nCopyright (c) 2017 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Mario Carneiro, Johannes H\u00f6lzl, Chris Hughes, Jens Wagemaker, Jon Eugster\n\n! This file was ported from Lean 3 source module algebra.group.units\n! leanprover-community/mathlib commit 369525b73f229ccd76a6ec0e0e0bf2be57599768\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Basic\nimport Mathlib.Logic.Nontrivial\nimport Mathlib.Logic.Unique\nimport Mathlib.Tactic.Nontriviality\nimport Mathlib.Tactic.Simps.Basic\nimport Mathlib.Tactic.Lift\n\n/-!\n# Units (i.e., invertible elements) of a monoid\n\nAn element of a `Monoid` is a unit if it has a two-sided inverse.\n\n## Main declarations\n\n* `Units M`: the group of units (i.e., invertible elements) of a monoid.\n* `IsUnit x`: a predicate asserting that `x` is a unit (i.e., invertible element) of a monoid.\n\nFor both declarations, there is an additive counterpart: `AddUnits` and `IsAddUnit`.\nSee also `Prime`, `Associated`, and `Irreducible` in `Mathlib.Algebra.Associated`.\n\n## Notation\n\nWe provide `M\u02e3` as notation for `Units M`,\nresembling the notation $R^{\\times}$ for the units of a ring, which is common in mathematics.\n\n-/\n\n\nopen Function\n\nuniverse u\n\nvariable {\u03b1 : Type u}\n\n/-- Units of a `Monoid`, bundled version. Notation: `\u03b1\u02e3`.\n\nAn element of a `Monoid` is a unit if it has a two-sided inverse.\nThis version bundles the inverse element so that it can be computed.\nFor a predicate see `IsUnit`. -/\nstructure Units (\u03b1 : Type u) [Monoid \u03b1] where\n  /-- The underlying value in the base `Monoid`. -/\n  val : \u03b1\n  /-- The inverse value of `val` in the base `Monoid`. -/\n  inv : \u03b1\n  /-- `inv` is the right inverse of `val` in the base `Monoid`. -/\n  val_inv : val * inv = 1\n  /-- `inv` is the left inverse of `val` in the base `Monoid`. -/\n  inv_val : inv * val = 1\n#align units Units\n#align units.val Units.val\n#align units.inv Units.inv\n#align units.val_inv Units.val_inv\n#align units.inv_val Units.inv_val\n\nattribute [coe] Units.val\n\n@[inherit_doc]\npostfix:1024 \"\u02e3\" => Units\n\n-- We don't provide notation for the additive version, because its use is somewhat rare.\n/-- Units of an `AddMonoid`, bundled version.\n\nAn element of an `AddMonoid` is a unit if it has a two-sided additive inverse.\nThis version bundles the inverse element so that it can be computed.\nFor a predicate see `isAddUnit`. -/\nstructure AddUnits (\u03b1 : Type u) [AddMonoid \u03b1] where\n  /-- The underlying value in the base `AddMonoid`. -/\n  val : \u03b1\n  /-- The additive inverse value of `val` in the base `AddMonoid`. -/\n  neg : \u03b1\n  /-- `neg` is the right additive inverse of `val` in the base `AddMonoid`. -/\n  val_neg : val + neg = 0\n  /-- `neg` is the left additive inverse of `val` in the base `AddMonoid`. -/\n  neg_val : neg + val = 0\n#align add_units AddUnits\n#align add_units.val AddUnits.val\n#align add_units.neg AddUnits.neg\n#align add_units.val_neg AddUnits.val_neg\n#align add_units.neg_val AddUnits.neg_val\n\nattribute [to_additive] Units\nattribute [coe] AddUnits.val\n\nsection HasElem\n\n@[to_additive]\ntheorem unique_one {\u03b1 : Type _} [Unique \u03b1] [One \u03b1] : default = (1 : \u03b1) :=\n  Unique.default_eq 1\n#align unique_has_one unique_one\n#align unique_has_zero unique_zero\n\nend HasElem\n\nnamespace Units\n\nvariable [Monoid \u03b1]\n\n-- Porting note: unclear whether this should be a `CoeHead` or `CoeTail`\n/-- A unit can be interpreted as a term in the base `Monoid`. -/\n@[to_additive \"An additive unit can be interpreted as a term in the base `AddMonoid`.\"]\ninstance : CoeHead \u03b1\u02e3 \u03b1 :=\n  \u27e8val\u27e9\nattribute [instance] AddUnits.instCoeHeadAddUnits\n\n/-- The inverse of a unit in a `Monoid`. -/\n@[to_additive \"The additive inverse of an additive unit in an `AddMonoid`.\"]\ninstance : Inv \u03b1\u02e3 :=\n  \u27e8fun u => \u27e8u.2, u.1, u.4, u.3\u27e9\u27e9\nattribute [instance] AddUnits.instNegAddUnits\n\n/- porting note: the result of these definitions is syntactically equal to `Units.val` and\n`Units.inv` because of the way coercions work in Lean 4, so there is no need for these custom\n`simp` projections. -/\n#noalign units.simps.coe\n#noalign add_units.simps.coe\n#noalign units.simps.coe_inv\n#noalign add_units.simps.coe_neg\n\n-- Porting note: removed `simp` tag because of the tautology\n@[to_additive]\ntheorem val_mk (a : \u03b1) (b h\u2081 h\u2082) : \u2191(Units.mk a b h\u2081 h\u2082) = a :=\n  rfl\n#align units.coe_mk Units.val_mk\n#align add_units.coe_mk AddUnits.val_mk\n\n@[to_additive (attr := ext)]\ntheorem ext : Function.Injective (fun (u : \u03b1\u02e3) => (u : \u03b1))\n  | \u27e8v, i\u2081, vi\u2081, iv\u2081\u27e9, \u27e8v', i\u2082, vi\u2082, iv\u2082\u27e9, e => by\n    simp only at e; subst v'; congr;\n    simpa only [iv\u2082, vi\u2081, one_mul, mul_one] using mul_assoc i\u2082 v i\u2081\n#align units.ext Units.ext\n\n#align add_units.ext AddUnits.ext\n\n@[to_additive (attr := norm_cast)]\ntheorem eq_iff {a b : \u03b1\u02e3} : (a : \u03b1) = b \u2194 a = b :=\n  ext.eq_iff\n#align units.eq_iff Units.eq_iff\n#align add_units.eq_iff AddUnits.eq_iff\n\n@[to_additive]\ntheorem ext_iff {a b : \u03b1\u02e3} : a = b \u2194 (a : \u03b1) = b :=\n  eq_iff.symm\n#align units.ext_iff Units.ext_iff\n#align add_units.ext_iff AddUnits.ext_iff\n\n/-- Units have decidable equality if the base `Monoid` has deciable equality. -/\n@[to_additive \"Additive units have decidable equality\nif the base `AddMonoid` has deciable equality.\"]\ninstance [DecidableEq \u03b1] : DecidableEq \u03b1\u02e3 := fun _ _ => decidable_of_iff' _ ext_iff\nattribute [instance] AddUnits.instDecidableEqAddUnits\n\n@[to_additive (attr := simp)]\ntheorem mk_val (u : \u03b1\u02e3) (y h\u2081 h\u2082) : mk (u : \u03b1) y h\u2081 h\u2082 = u :=\n  ext rfl\n#align units.mk_coe Units.mk_val\n#align add_units.mk_coe Units.mk_val\n\n/-- Copy a unit, adjusting definition equalities. -/\n@[to_additive (attr := simps) \"Copy an `AddUnit`, adjusting definitional equalities.\"]\ndef copy (u : \u03b1\u02e3) (val : \u03b1) (hv : val = u) (inv : \u03b1) (hi : inv = \u2191u\u207b\u00b9) : \u03b1\u02e3 :=\n  { val, inv, inv_val := hv.symm \u25b8 hi.symm \u25b8 u.inv_val, val_inv := hv.symm \u25b8 hi.symm \u25b8 u.val_inv }\n#align units.copy Units.copy\n#align add_units.copy AddUnits.copy\n\n@[to_additive]\ntheorem copy_eq (u : \u03b1\u02e3) (val hv inv hi) : u.copy val hv inv hi = u :=\n  ext hv\n#align units.copy_eq Units.copy_eq\n#align add_units.copy_eq AddUnits.copy_eq\n\n/-- Units of a monoid form have a multiplication and multiplicative identity. -/\n@[to_additive \"Additive units of an additive monoid have an addition and an additive identity.\"]\ninstance : MulOneClass \u03b1\u02e3 where\n  mul u\u2081 u\u2082 :=\n    \u27e8u\u2081.val * u\u2082.val, u\u2082.inv * u\u2081.inv,\n      by rw [mul_assoc, \u2190 mul_assoc u\u2082.val, val_inv, one_mul, val_inv],\n      by rw [mul_assoc, \u2190 mul_assoc u\u2081.inv, inv_val, one_mul, inv_val]\u27e9\n  one := \u27e81, 1, one_mul 1, one_mul 1\u27e9\n  one_mul u := ext <| one_mul (u : \u03b1)\n  mul_one u := ext <| mul_one (u : \u03b1)\nattribute [instance] AddUnits.instAddZeroClassAddUnits\n\n/-- Units of a monoid form a group. -/\n@[to_additive \"Additive units of an additive monoid form an additive group.\"]\ninstance : Group \u03b1\u02e3 :=\n  { (inferInstance : MulOneClass \u03b1\u02e3) with\n    one := 1,\n    mul_assoc := fun _ _ _ => ext <| mul_assoc _ _ _,\n    inv := Inv.inv, mul_left_inv := fun u => ext u.inv_val }\nattribute [instance] AddUnits.instAddGroupAddUnits\n\n/-- Units of a commutative monoid form a commutative group. -/\n@[to_additive \"Additive units of an additive commutative monoid form\nan additive commutative group.\"]\ninstance {\u03b1} [CommMonoid \u03b1] : CommGroup \u03b1\u02e3 :=\n  { (inferInstance : Group \u03b1\u02e3) with\n    mul_comm := fun _ _ => ext <| mul_comm _ _ }\nattribute [instance] AddUnits.instAddCommGroupAddUnitsToAddMonoid\n#align units.comm_group Units.instCommGroupUnitsToMonoid\n#align add_units.add_comm_group AddUnits.instAddCommGroupAddUnitsToAddMonoid\n\n/-- Units of a monoid are inhabited because `1` is a unit. -/\n@[to_additive \"Additive units of an additive monoid are inhabited because `0` is an additive unit.\"]\ninstance : Inhabited \u03b1\u02e3 :=\n  \u27e81\u27e9\nattribute [instance] AddUnits.instInhabitedAddUnits\n\n/-- Units of a monoid have a representation of the base value in the `Monoid`. -/\n@[to_additive \"Additive units of an addditive monoid have a representation of the base value in\nthe `AddMonoid`.\"]\ninstance [Repr \u03b1] : Repr \u03b1\u02e3 :=\n  \u27e8reprPrec \u2218 val\u27e9\nattribute [instance] AddUnits.instReprAddUnits\n\nvariable (a b c : \u03b1\u02e3) {u : \u03b1\u02e3}\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem val_mul : (\u2191(a * b) : \u03b1) = a * b :=\n  rfl\n#align units.coe_mul Units.val_mul\n#align add_units.coe_add AddUnits.val_add\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem val_one : ((1 : \u03b1\u02e3) : \u03b1) = 1 :=\n  rfl\n#align units.coe_one Units.val_one\n#align add_units.coe_zero AddUnits.val_zero\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem val_eq_one {a : \u03b1\u02e3} : (a : \u03b1) = 1 \u2194 a = 1 := by rw [\u2190 Units.val_one, eq_iff]\n#align units.coe_eq_one Units.val_eq_one\n#align add_units.coe_eq_zero AddUnits.val_eq_zero\n\n@[to_additive (attr := simp)]\ntheorem inv_mk (x y : \u03b1) (h\u2081 h\u2082) : (mk x y h\u2081 h\u2082)\u207b\u00b9 = mk y x h\u2082 h\u2081 :=\n  rfl\n#align units.inv_mk Units.inv_mk\n#align add_units.neg_mk AddUnits.neg_mk\n\n-- Porting note: coercions are now eagerly elaborated, so no need for `val_eq_coe`\n#noalign units.val_eq_coe\n#noalign add_units.val_eq_coe\n\n@[to_additive]\ntheorem inv_eq_val_inv : a.inv = ((a\u207b\u00b9 : \u03b1\u02e3) : \u03b1) :=\n  rfl\n-- Porting note: the lower priority is needed to appease the `simpNF` linter\n-- Note that `to_additive` doesn't copy `simp` priorities, so we use this as a workaround\nattribute [simp 900] Units.inv_eq_val_inv AddUnits.neg_eq_val_neg\n#align units.inv_eq_coe_inv Units.inv_eq_val_inv\n#align add_units.neg_eq_coe_neg AddUnits.neg_eq_val_neg\n\n@[to_additive (attr := simp)]\ntheorem inv_mul : (\u2191a\u207b\u00b9 * a : \u03b1) = 1 :=\n  inv_val _\n#align units.inv_mul Units.inv_mul\n#align add_units.neg_add AddUnits.neg_add\n\n@[to_additive (attr := simp)]\ntheorem mul_inv : (a * \u2191a\u207b\u00b9 : \u03b1) = 1 :=\n  val_inv _\n#align units.mul_inv Units.mul_inv\n#align add_units.add_neg AddUnits.add_neg\n\n@[to_additive]\ntheorem inv_mul_of_eq {a : \u03b1} (h : \u2191u = a) : \u2191u\u207b\u00b9 * a = 1 := by rw [\u2190 h, u.inv_mul]\n#align units.inv_mul_of_eq Units.inv_mul_of_eq\n#align add_units.neg_add_of_eq AddUnits.neg_add_of_eq\n\n@[to_additive]\ntheorem mul_inv_of_eq {a : \u03b1} (h : \u2191u = a) : a * \u2191u\u207b\u00b9 = 1 := by rw [\u2190 h, u.mul_inv]\n#align units.mul_inv_of_eq Units.mul_inv_of_eq\n#align add_units.add_neg_of_eq AddUnits.add_neg_of_eq\n\n@[to_additive (attr := simp)]\ntheorem mul_inv_cancel_left (a : \u03b1\u02e3) (b : \u03b1) : (a : \u03b1) * (\u2191a\u207b\u00b9 * b) = b := by\n  rw [\u2190 mul_assoc, mul_inv, one_mul]\n#align units.mul_inv_cancel_left Units.mul_inv_cancel_left\n#align add_units.add_neg_cancel_left AddUnits.add_neg_cancel_left\n\n@[to_additive (attr := simp)]\ntheorem inv_mul_cancel_left (a : \u03b1\u02e3) (b : \u03b1) : (\u2191a\u207b\u00b9 : \u03b1) * (a * b) = b := by\n  rw [\u2190 mul_assoc, inv_mul, one_mul]\n#align units.inv_mul_cancel_left Units.inv_mul_cancel_left\n#align add_units.neg_add_cancel_left AddUnits.neg_add_cancel_left\n\n@[to_additive (attr := simp)]\ntheorem mul_inv_cancel_right (a : \u03b1) (b : \u03b1\u02e3) : a * b * \u2191b\u207b\u00b9 = a := by\n  rw [mul_assoc, mul_inv, mul_one]\n#align units.mul_inv_cancel_right Units.mul_inv_cancel_right\n#align add_units.add_neg_cancel_right AddUnits.add_neg_cancel_right\n\n@[to_additive (attr := simp)]\ntheorem inv_mul_cancel_right (a : \u03b1) (b : \u03b1\u02e3) : a * \u2191b\u207b\u00b9 * b = a := by\n  rw [mul_assoc, inv_mul, mul_one]\n#align units.inv_mul_cancel_right Units.inv_mul_cancel_right\n#align add_units.neg_add_cancel_right AddUnits.neg_add_cancel_right\n\n@[to_additive (attr := simp)]\ntheorem mul_right_inj (a : \u03b1\u02e3) {b c : \u03b1} : (a : \u03b1) * b = a * c \u2194 b = c :=\n  \u27e8fun h => by simpa only [inv_mul_cancel_left] using congr_arg (fun x : \u03b1 => \u2191(a\u207b\u00b9 : \u03b1\u02e3) * x) h,\n    congr_arg _\u27e9\n#align units.mul_right_inj Units.mul_right_inj\n#align add_units.add_right_inj AddUnits.add_right_inj\n\n@[to_additive (attr := simp)]\ntheorem mul_left_inj (a : \u03b1\u02e3) {b c : \u03b1} : b * a = c * a \u2194 b = c :=\n  \u27e8fun h => by simpa only [mul_inv_cancel_right] using congr_arg (fun x : \u03b1 => x * \u2191(a\u207b\u00b9 : \u03b1\u02e3)) h,\n    congr_arg (\u00b7 * a.val)\u27e9\n#align units.mul_left_inj Units.mul_left_inj\n#align add_units.add_left_inj AddUnits.add_left_inj\n\n@[to_additive]\ntheorem eq_mul_inv_iff_mul_eq {a b : \u03b1} : a = b * \u2191c\u207b\u00b9 \u2194 a * c = b :=\n  \u27e8fun h => by rw [h, inv_mul_cancel_right], fun h => by rw [\u2190 h, mul_inv_cancel_right]\u27e9\n#align units.eq_mul_inv_iff_mul_eq Units.eq_mul_inv_iff_mul_eq\n#align add_units.eq_add_neg_iff_add_eq AddUnits.eq_add_neg_iff_add_eq\n\n@[to_additive]\ntheorem eq_inv_mul_iff_mul_eq {a c : \u03b1} : a = \u2191b\u207b\u00b9 * c \u2194 \u2191b * a = c :=\n  \u27e8fun h => by rw [h, mul_inv_cancel_left], fun h => by rw [\u2190 h, inv_mul_cancel_left]\u27e9\n#align units.eq_inv_mul_iff_mul_eq Units.eq_inv_mul_iff_mul_eq\n#align add_units.eq_neg_add_iff_add_eq AddUnits.eq_neg_add_iff_add_eq\n\n@[to_additive]\ntheorem inv_mul_eq_iff_eq_mul {b c : \u03b1} : \u2191a\u207b\u00b9 * b = c \u2194 b = a * c :=\n  \u27e8fun h => by rw [\u2190 h, mul_inv_cancel_left], fun h => by rw [h, inv_mul_cancel_left]\u27e9\n#align units.inv_mul_eq_iff_eq_mul Units.inv_mul_eq_iff_eq_mul\n#align add_units.neg_add_eq_iff_eq_add AddUnits.neg_add_eq_iff_eq_add\n\n@[to_additive]\ntheorem mul_inv_eq_iff_eq_mul {a c : \u03b1} : a * \u2191b\u207b\u00b9 = c \u2194 a = c * b :=\n  \u27e8fun h => by rw [\u2190 h, inv_mul_cancel_right], fun h => by rw [h, mul_inv_cancel_right]\u27e9\n#align units.mul_inv_eq_iff_eq_mul Units.mul_inv_eq_iff_eq_mul\n#align add_units.add_neg_eq_iff_eq_add AddUnits.add_neg_eq_iff_eq_add\n\n-- Porting note: have to explicitly type annotate the 1\n@[to_additive]\nprotected \n\n\n-- Porting note: have to explicitly type annotate the 1\n@[to_additive]\nprotected theorem inv_eq_of_mul_eq_one_right {a : \u03b1} (h : \u2191u * a = 1) : \u2191u\u207b\u00b9 = a :=\n  calc\n    \u2191u\u207b\u00b9 = \u2191u\u207b\u00b9 * (1 : \u03b1) := by rw [mul_one]\n    _ = a := by rw [\u2190 h, inv_mul_cancel_left]\n#align units.inv_eq_of_mul_eq_one_right Units.inv_eq_of_mul_eq_one_right\n#align add_units.neg_eq_of_add_eq_zero_right AddUnits.neg_eq_of_add_eq_zero_right\n\n\n@[to_additive]\nprotected theorem eq_inv_of_mul_eq_one_left {a : \u03b1} (h : \u2191u * a = 1) : a = \u2191u\u207b\u00b9 :=\n  (Units.inv_eq_of_mul_eq_one_right h).symm\n#align units.eq_inv_of_mul_eq_one_left Units.eq_inv_of_mul_eq_one_left\n#align add_units.eq_neg_of_add_eq_zero_left AddUnits.eq_neg_of_add_eq_zero_left\n\n@[to_additive]\nprotected theorem eq_inv_of_mul_eq_one_right {a : \u03b1} (h : a * u = 1) : a = \u2191u\u207b\u00b9 :=\n  (Units.inv_eq_of_mul_eq_one_left h).symm\n#align units.eq_inv_of_mul_eq_one_right Units.eq_inv_of_mul_eq_one_right\n#align add_units.eq_neg_of_add_eq_zero_right AddUnits.eq_neg_of_add_eq_zero_right\n\n@[to_additive (attr := simp)]\ntheorem mul_inv_eq_one {a : \u03b1} : a * \u2191u\u207b\u00b9 = 1 \u2194 a = u :=\n  \u27e8inv_inv u \u25b8 Units.eq_inv_of_mul_eq_one_right, fun h => mul_inv_of_eq h.symm\u27e9\n#align units.mul_inv_eq_one Units.mul_inv_eq_one\n#align add_units.add_neg_eq_zero AddUnits.add_neg_eq_zero\n\n@[to_additive (attr := simp)]\ntheorem inv_mul_eq_one {a : \u03b1} : \u2191u\u207b\u00b9 * a = 1 \u2194 \u2191u = a :=\n  \u27e8inv_inv u \u25b8 Units.inv_eq_of_mul_eq_one_right, inv_mul_of_eq\u27e9\n#align units.inv_mul_eq_one Units.inv_mul_eq_one\n#align add_units.neg_add_eq_zero AddUnits.neg_add_eq_zero\n\n@[to_additive]\ntheorem mul_eq_one_iff_eq_inv {a : \u03b1} : a * u = 1 \u2194 a = \u2191u\u207b\u00b9 := by rw [\u2190 mul_inv_eq_one, inv_inv]\n#align units.mul_eq_one_iff_eq_inv Units.mul_eq_one_iff_eq_inv\n#align add_units.add_eq_zero_iff_eq_neg AddUnits.add_eq_zero_iff_eq_neg\n\n@[to_additive]\ntheorem mul_eq_one_iff_inv_eq {a : \u03b1} : \u2191u * a = 1 \u2194 \u2191u\u207b\u00b9 = a := by rw [\u2190 inv_mul_eq_one, inv_inv]\n#align units.mul_eq_one_iff_inv_eq Units.mul_eq_one_iff_inv_eq\n#align add_units.add_eq_zero_iff_neg_eq AddUnits.add_eq_zero_iff_neg_eq\n\n@[to_additive]\ntheorem inv_unique {u\u2081 u\u2082 : \u03b1\u02e3} (h : (\u2191u\u2081 : \u03b1) = \u2191u\u2082) : (\u2191u\u2081\u207b\u00b9 : \u03b1) = \u2191u\u2082\u207b\u00b9 :=\n  Units.inv_eq_of_mul_eq_one_right <| by rw [h, u\u2082.mul_inv]\n#align units.inv_unique Units.inv_unique\n#align add_units.neg_unique AddUnits.neg_unique\n\n@[to_additive (attr := simp)]\ntheorem val_inv_eq_inv_val {M : Type _} [DivisionMonoid M] (u : Units M) : \u2191u\u207b\u00b9 = (u\u207b\u00b9 : M) :=\n  Eq.symm <| inv_eq_of_mul_eq_one_right u.mul_inv\n#align units.coe_inv Units.val_inv_eq_inv_val\n\nend Units\n\n/-- For `a, b` in a `CommMonoid` such that `a * b = 1`, makes a unit out of `a`. -/\n@[to_additive\n  \"For `a, b` in an `AddCommMonoid` such that `a + b = 0`, makes an add_unit out of `a`.\"]\ndef Units.mkOfMulEqOne [CommMonoid \u03b1] (a b : \u03b1) (hab : a * b = 1) : \u03b1\u02e3 :=\n  \u27e8a, b, hab, (mul_comm b a).trans hab\u27e9\n#align units.mk_of_mul_eq_one Units.mkOfMulEqOne\n#align add_units.mk_of_add_eq_zero AddUnits.mkOfAddEqZero\n\n@[to_additive (attr := simp)]\ntheorem Units.val_mkOfMulEqOne [CommMonoid \u03b1] {a b : \u03b1} (h : a * b = 1) :\n    (Units.mkOfMulEqOne a b h : \u03b1) = a :=\n  rfl\n#align units.coe_mk_of_mul_eq_one Units.val_mkOfMulEqOne\n#align add_units.coe_mk_of_add_eq_zero AddUnits.val_mkOfAddEqZero\n\nsection Monoid\n\nvariable [Monoid \u03b1] {a b c : \u03b1}\n\n/-- Partial division. It is defined when the\n  second argument is invertible, and unlike the division operator\n  in `DivisionRing` it is not totalized at zero. -/\ndef divp (a : \u03b1) (u : Units \u03b1) : \u03b1 :=\n  a * (u\u207b\u00b9 : \u03b1\u02e3)\n#align divp divp\n\n@[inherit_doc]\ninfixl:70 \" /\u209a \" => divp\n\n@[simp]\ntheorem divp_self (u : \u03b1\u02e3) : (u : \u03b1) /\u209a u = 1 :=\n  Units.mul_inv _\n#align divp_self divp_self\n\n@[simp]\ntheorem divp_one (a : \u03b1) : a /\u209a 1 = a :=\n  mul_one _\n#align divp_one divp_one\n\ntheorem divp_assoc (a b : \u03b1) (u : \u03b1\u02e3) : a * b /\u209a u = a * (b /\u209a u) :=\n  mul_assoc _ _ _\n#align divp_assoc divp_assoc\n\n/-- `field_simp` needs the reverse direction of `divp_assoc` to move all `/\u209a` to the right. -/\n@[field_simps]\ntheorem divp_assoc' (x y : \u03b1) (u : \u03b1\u02e3) : x * (y /\u209a u) = x * y /\u209a u :=\n  (divp_assoc _ _ _).symm\n#align divp_assoc' divp_assoc'\n\n@[simp]\ntheorem divp_inv (u : \u03b1\u02e3) : a /\u209a u\u207b\u00b9 = a * u :=\n  rfl\n#align divp_inv divp_inv\n\n@[simp]\ntheorem divp_mul_cancel (a : \u03b1) (u : \u03b1\u02e3) : a /\u209a u * u = a :=\n  (mul_assoc _ _ _).trans <| by rw [Units.inv_mul, mul_one]\n#align divp_mul_cancel divp_mul_cancel\n\n@[simp]\ntheorem mul_divp_cancel (a : \u03b1) (u : \u03b1\u02e3) : a * u /\u209a u = a :=\n  (mul_assoc _ _ _).trans <| by rw [Units.mul_inv, mul_one]\n#align mul_divp_cancel mul_divp_cancel\n\n@[simp]\ntheorem divp_left_inj (u : \u03b1\u02e3) {a b : \u03b1} : a /\u209a u = b /\u209a u \u2194 a = b :=\n  Units.mul_left_inj _\n#align divp_left_inj divp_left_inj\n\n@[field_simps]\ntheorem divp_divp_eq_divp_mul (x : \u03b1) (u\u2081 u\u2082 : \u03b1\u02e3) : x /\u209a u\u2081 /\u209a u\u2082 = x /\u209a (u\u2082 * u\u2081) := by\n  simp only [divp, mul_inv_rev, Units.val_mul, mul_assoc]\n#align divp_divp_eq_divp_mul divp_divp_eq_divp_mul\n\n/- Port note: to match the mathlib3 behavior, this needs to have higher simp\npriority than eq_divp_iff_mul_eq. -/\n@[field_simps 1010]\ntheorem divp_eq_iff_mul_eq {x : \u03b1} {u : \u03b1\u02e3} {y : \u03b1} : x /\u209a u = y \u2194 y * u = x :=\n  u.mul_left_inj.symm.trans <| by rw [divp_mul_cancel]; exact \u27e8Eq.symm, Eq.symm\u27e9\n#align divp_eq_iff_mul_eq divp_eq_iff_mul_eq\n\n@[field_simps]\ntheorem eq_divp_iff_mul_eq {x : \u03b1} {u : \u03b1\u02e3} {y : \u03b1} : x = y /\u209a u \u2194 x * u = y := by\n  rw [eq_comm, divp_eq_iff_mul_eq]\n#align eq_divp_iff_mul_eq eq_divp_iff_mul_eq\n\ntheorem divp_eq_one_iff_eq {a : \u03b1} {u : \u03b1\u02e3} : a /\u209a u = 1 \u2194 a = u :=\n  (Units.mul_left_inj u).symm.trans <| by rw [divp_mul_cancel, one_mul]\n#align divp_eq_one_iff_eq divp_eq_one_iff_eq\n\n@[simp]\ntheorem one_divp (u : \u03b1\u02e3) : 1 /\u209a u = \u2191u\u207b\u00b9 :=\n  one_mul _\n#align one_divp one_divp\n\n/-- Used for `field_simp` to deal with inverses of units. -/\n@[field_simps]\ntheorem inv_eq_one_divp (u : \u03b1\u02e3) : \u2191u\u207b\u00b9 = 1 /\u209a u := by rw [one_divp]\n#align inv_eq_one_divp inv_eq_one_divp\n\n/-- Used for `field_simp` to deal with inverses of units. This form of the lemma\nis essential since `field_simp` likes to use `inv_eq_one_div` to rewrite\n`\u2191u\u207b\u00b9 = \u2191(1 / u)`.\n-/\n@[field_simps]\ntheorem inv_eq_one_divp' (u : \u03b1\u02e3) : ((1 / u : \u03b1\u02e3) : \u03b1) = 1 /\u209a u := by\n  rw [one_div, one_divp]\n#align inv_eq_one_divp' inv_eq_one_divp'\n\n/-- `field_simp` moves division inside `\u03b1\u02e3` to the right, and this lemma\nlifts the calculation to `\u03b1`.\n-/\n@[field_simps]\ntheorem val_div_eq_divp (u\u2081 u\u2082 : \u03b1\u02e3) : \u2191(u\u2081 / u\u2082) = \u2191u\u2081 /\u209a u\u2082 := by\n  rw [divp, division_def, Units.val_mul]\n#align coe_div_eq_divp val_div_eq_divp\n\nend Monoid\n\nsection CommMonoid\n\nvariable [CommMonoid \u03b1]\n\n@[field_simps]\ntheorem divp_mul_eq_mul_divp (x y : \u03b1) (u : \u03b1\u02e3) : x /\u209a u * y = x * y /\u209a u := by\n  rw [divp, divp, mul_right_comm]\n#align divp_mul_eq_mul_divp divp_mul_eq_mul_divp\n\n-- Theoretically redundant as `field_simp` lemma.\n@[field_simps]\ntheorem divp_eq_divp_iff {x y : \u03b1} {ux uy : \u03b1\u02e3} : x /\u209a ux = y /\u209a uy \u2194 x * uy = y * ux := by\n  rw [divp_eq_iff_mul_eq, divp_mul_eq_mul_divp, divp_eq_iff_mul_eq]\n#align divp_eq_divp_iff divp_eq_divp_iff\n\n-- Theoretically redundant as `field_simp` lemma.\n@[field_simps]\ntheorem divp_mul_divp (x y : \u03b1) (ux uy : \u03b1\u02e3) : x /\u209a ux * (y /\u209a uy) = x * y /\u209a (ux * uy) := by\n  rw [divp_mul_eq_mul_divp, divp_assoc', divp_divp_eq_divp_mul]\n#align divp_mul_divp divp_mul_divp\n\nend CommMonoid\n\n/-!\n# `IsUnit` predicate\n-/\n\n\nsection IsUnit\n\nvariable {M : Type _} {N : Type _}\n\n/-- An element `a : M` of a `Monoid` is a unit if it has a two-sided inverse.\nThe actual definition says that `a` is equal to some `u : M\u02e3`, where\n`M\u02e3` is a bundled version of `IsUnit`. -/\n@[to_additive\n      \"An element `a : M` of an `AddMonoid` is an `AddUnit` if it has a two-sided additive inverse.\n      The actual definition says that `a` is equal to some `u : AddUnits M`,\n      where `AddUnits M` is a bundled version of `IsAddUnit`.\"]\ndef IsUnit [Monoid M] (a : M) : Prop :=\n  \u2203 u : M\u02e3, (u : M) = a\n#align is_unit IsUnit\n#align is_add_unit IsAddUnit\n\n@[to_additive (attr := nontriviality)]\ntheorem isUnit_of_subsingleton [Monoid M] [Subsingleton M] (a : M) : IsUnit a :=\n  \u27e8\u27e8a, a, Subsingleton.elim _ _, Subsingleton.elim _ _\u27e9, rfl\u27e9\n#align is_unit_of_subsingleton isUnit_of_subsingleton\n#align is_add_unit_of_subsingleton isAddUnit_of_subsingleton\n\nattribute [nontriviality] isAddUnit_of_subsingleton\n\n@[to_additive]\ninstance [Monoid M] : CanLift M M\u02e3 Units.val IsUnit :=\n{ prf := fun _ \u21a6 id }\n\n/-- A subsingleton `Monoid` has a unique unit. -/\n@[to_additive \"A subsingleton `AddMonoid` has a unique additive unit.\"]\ninstance [Monoid M] [Subsingleton M] : Unique M\u02e3 where\n  default := 1\n  uniq a := Units.val_eq_one.mp <| Subsingleton.elim (a : M) 1\n\n\n@[to_additive (attr := simp)]\nprotected theorem Units.isUnit [Monoid M] (u : M\u02e3) : IsUnit (u : M) :=\n  \u27e8u, rfl\u27e9\n#align units.is_unit Units.isUnit\n#align add_units.is_add_unit_add_unit AddUnits.isAddUnit\n\n@[to_additive (attr := simp)]\ntheorem isUnit_one [Monoid M] : IsUnit (1 : M) :=\n  \u27e81, rfl\u27e9\n#align is_unit_one isUnit_one\n#align is_add_unit_zero isAddUnit_zero\n\n@[to_additive]\ntheorem isUnit_of_mul_eq_one [CommMonoid M] (a b : M) (h : a * b = 1) : IsUnit a :=\n  \u27e8Units.mkOfMulEqOne a b h, rfl\u27e9\n#align is_unit_of_mul_eq_one isUnit_of_mul_eq_one\n#align is_add_unit_of_add_eq_zero isAddUnit_of_add_eq_zero\n\n@[to_additive IsAddUnit.exists_neg]\ntheorem IsUnit.exists_right_inv [Monoid M] {a : M} (h : IsUnit a) : \u2203 b, a * b = 1 := by\n  rcases h with \u27e8\u27e8a, b, hab, _\u27e9, rfl\u27e9\n  exact \u27e8b, hab\u27e9\n#align is_unit.exists_right_inv IsUnit.exists_right_inv\n#align is_add_unit.exists_neg IsAddUnit.exists_neg\n\n@[to_additive IsAddUnit.exists_neg']\ntheorem IsUnit.exists_left_inv [Monoid M] {a : M} (h : IsUnit a) : \u2203 b, b * a = 1 := by\n  rcases h with \u27e8\u27e8a, b, _, hba\u27e9, rfl\u27e9\n  exact \u27e8b, hba\u27e9\n#align is_unit.exists_left_inv IsUnit.exists_left_inv\n#align is_add_unit.exists_neg' IsAddUnit.exists_neg'\n\n@[to_additive]\ntheorem isUnit_iff_exists_inv [CommMonoid M] {a : M} : IsUnit a \u2194 \u2203 b, a * b = 1 :=\n  \u27e8fun h => h.exists_right_inv, fun \u27e8b, hab\u27e9 => isUnit_of_mul_eq_one _ b hab\u27e9\n#align is_unit_iff_exists_inv isUnit_iff_exists_inv\n#align is_add_unit_iff_exists_neg isAddUnit_iff_exists_neg\n\n-- Porting note: `to_additive` complains if using `simp [isUnit_iff_exists_inv, mul_comm]` proof\n@[to_additive]\ntheorem isUnit_iff_exists_inv' [CommMonoid M] {a : M} : IsUnit a \u2194 \u2203 b, b * a = 1 := by\n  rw [isUnit_iff_exists_inv]\n  simp [mul_comm]\n#align is_unit_iff_exists_inv' isUnit_iff_exists_inv'\n#align is_add_unit_iff_exists_neg' isAddUnit_iff_exists_neg'\n\n@[to_additive]\ntheorem IsUnit.mul [Monoid M] {x y : M} : IsUnit x \u2192 IsUnit y \u2192 IsUnit (x * y) := by\n  rintro \u27e8x, rfl\u27e9 \u27e8y, rfl\u27e9\n  exact \u27e8x * y, Units.val_mul _ _\u27e9\n#align is_unit.mul IsUnit.mul\n#align is_add_unit.add IsAddUnit.add\n\n/-- Multiplication by a `u : M\u02e3` on the right doesn't affect `IsUnit`. -/\n@[to_additive (attr := simp)\n\"Addition of a `u : AddUnits M` on the right doesn't affect `IsAddUnit`.\"]\ntheorem Units.isUnit_mul_units [Monoid M] (a : M) (u : M\u02e3) : IsUnit (a * u) \u2194 IsUnit a :=\n  Iff.intro\n    (fun \u27e8v, hv\u27e9 => by\n      have : IsUnit (a * \u2191u * \u2191u\u207b\u00b9) := by exists v * u\u207b\u00b9; rw [\u2190 hv, Units.val_mul]\n      rwa [mul_assoc, Units.mul_inv, mul_one] at this)\n    fun v => v.mul u.isUnit\n#align units.is_unit_mul_units Units.isUnit_mul_units\n#align add_units.is_add_unit_add_add_units AddUnits.isAddUnit_add_addUnits\n\n/-- Multiplication by a `u : M\u02e3` on the left doesn't affect `IsUnit`. -/\n@[to_additive (attr := simp)\n\"Addition of a `u : AddUnits M` on the left doesn't affect `IsAddUnit`.\"]\ntheorem Units.isUnit_units_mul {M : Type _} [Monoid M] (u : M\u02e3) (a : M) :\n    IsUnit (\u2191u * a) \u2194 IsUnit a :=\n  Iff.intro\n    (fun \u27e8v, hv\u27e9 => by\n      have : IsUnit (\u2191u\u207b\u00b9 * (\u2191u * a)) := by exists u\u207b\u00b9 * v; rw [\u2190 hv, Units.val_mul]\n      rwa [\u2190 mul_assoc, Units.inv_mul, one_mul] at this)\n    u.isUnit.mul\n#align units.is_unit_units_mul Units.isUnit_units_mul\n#align add_units.is_add_unit_add_units_add AddUnits.isAddUnit_addUnits_add\n\n@[to_additive]\ntheorem isUnit_of_mul_isUnit_left [CommMonoid M] {x y : M} (hu : IsUnit (x * y)) : IsUnit x :=\n  let \u27e8z, hz\u27e9 := isUnit_iff_exists_inv.1 hu\n  isUnit_iff_exists_inv.2 \u27e8y * z, by rwa [\u2190 mul_assoc]\u27e9\n#align is_unit_of_mul_is_unit_left isUnit_of_mul_isUnit_left\n#align is_add_unit_of_add_is_add_unit_left isAddUnit_of_add_isAddUnit_left\n\n@[to_additive]\ntheorem isUnit_of_mul_isUnit_right [CommMonoid M] {x y : M} (hu : IsUnit (x * y)) : IsUnit y :=\n  @isUnit_of_mul_isUnit_left _ _ y x <| by rwa [mul_comm]\n#align is_unit_of_mul_is_unit_right isUnit_of_mul_isUnit_right\n#align is_add_unit_of_add_is_add_unit_right isAddUnit_of_add_isAddUnit_right\n\nnamespace IsUnit\n\n@[to_additive (attr := simp)]\ntheorem mul_iff [CommMonoid M] {x y : M} : IsUnit (x * y) \u2194 IsUnit x \u2227 IsUnit y :=\n  \u27e8fun h => \u27e8isUnit_of_mul_isUnit_left h, isUnit_of_mul_isUnit_right h\u27e9,\n   fun h => IsUnit.mul h.1 h.2\u27e9\n#align is_unit.mul_iff IsUnit.mul_iff\n#align is_add_unit.add_iff IsAddUnit.add_iff\n\nsection Monoid\n\nvariable [Monoid M] {a b c : M}\n\n/-- The element of the group of units, corresponding to an element of a monoid which is a unit. When\n`\u03b1` is a `DivisionMonoid`, use `IsUnit.unit'` instead. -/\nprotected noncomputable def unit (h : IsUnit a) : M\u02e3 :=\n  (Classical.choose h).copy a (Classical.choose_spec h).symm _ rfl\n#align is_unit.unit IsUnit.unit\n\n-- Porting note: `to_additive` doesn't carry over `noncomputable` so we make an explicit defn\n/-- \"The element of the additive group of additive units, corresponding to an element of\nan additive monoid which is an additive unit. When `\u03b1` is a `SubtractionMonoid`, use\n`IsAddUnit.addUnit'` instead. -/\nprotected noncomputable def _root_.IsAddUnit.addUnit [AddMonoid N] {a : N} (h : IsAddUnit a) :\n    AddUnits N :=\n  (Classical.choose h).copy a (Classical.choose_spec h).symm _ rfl\n#align is_add_unit.add_unit IsAddUnit.addUnit\nattribute [to_additive existing] IsUnit.unit\n\n@[to_additive (attr := simp)]\ntheorem unit_of_val_units {a : M\u02e3} (h : IsUnit (a : M)) : h.unit = a :=\n  Units.ext <| rfl\n#align is_unit.unit_of_coe_units IsUnit.unit_of_val_units\n#align is_add_unit.add_unit_of_coe_add_units IsAddUnit.addUnit_of_val_addUnits\n\n@[to_additive (attr := simp)]\ntheorem unit_spec (h : IsUnit a) : \u2191h.unit = a :=\n  rfl\n#align is_unit.unit_spec IsUnit.unit_spec\n#align is_add_unit.add_unit_spec IsAddUnit.addUnit_spec\n\n@[to_additive (attr := simp)]\ntheorem val_inv_mul (h : IsUnit a) : \u2191h.unit\u207b\u00b9 * a = 1 :=\n  Units.mul_inv _\n#align is_unit.coe_inv_mul IsUnit.val_inv_mul\n#align is_add_unit.coe_neg_add IsAddUnit.val_neg_add\n\n@[to_additive (attr := simp)]\ntheorem mul_val_inv (h : IsUnit a) : a * \u2191h.unit\u207b\u00b9 = 1 := by\n  rw [\u2190h.unit.mul_inv]; congr\n#align is_unit.mul_coe_inv IsUnit.mul_val_inv\n#align is_add_unit.add_coe_neg IsAddUnit.add_val_neg\n\n/-- `IsUnit x` is decidable if we can decide if `x` comes from `M\u02e3`. -/\n@[to_additive \"`IsAddUnit x` is decidable if we can decide if `x` comes from `AddUnits M`.\"]\ninstance (x : M) [h : Decidable (\u2203 u : M\u02e3, \u2191u = x)] : Decidable (IsUnit x) :=\n  h\nattribute [instance] IsAddUnit.instDecidableIsAddUnit\n\n@[to_additive]\ntheorem mul_left_inj (h : IsUnit a) : b * a = c * a \u2194 b = c :=\n  let \u27e8u, hu\u27e9 := h\n  hu \u25b8 u.mul_left_inj\n#align is_unit.mul_left_inj IsUnit.mul_left_inj\n#align is_add_unit.add_left_inj IsAddUnit.add_left_inj\n\n@[to_additive]\ntheorem mul_right_inj (h : IsUnit a) : a * b = a * c \u2194 b = c :=\n  let \u27e8u, hu\u27e9 := h\n  hu \u25b8 u.mul_right_inj\n#align is_unit.mul_right_inj IsUnit.mul_right_inj\n#align is_add_unit.add_right_inj IsAddUnit.add_right_inj\n\n@[to_additive]\nprotected theorem mul_left_cancel (h : IsUnit a) : a * b = a * c \u2192 b = c :=\n  h.mul_right_inj.1\n#align is_unit.mul_left_cancel IsUnit.mul_left_cancel\n#align is_add_unit.add_left_cancel IsAddUnit.add_left_cancel\n\n@[to_additive]\nprotected theorem mul_right_cancel (h : IsUnit b) : a * b = c * b \u2192 a = c :=\n  h.mul_left_inj.1\n#align is_unit.mul_right_cancel IsUnit.mul_right_cancel\n#align is_add_unit.add_right_cancel IsAddUnit.add_right_cancel\n\n@[to_additive]\nprotected theorem mul_right_injective (h : IsUnit a) : Injective ((\u00b7 * \u00b7) a) :=\n  fun _ _ => h.mul_left_cancel\n#align is_unit.mul_right_injective IsUnit.mul_right_injective\n#align is_add_unit.add_right_injective IsAddUnit.add_right_injective\n\n@[to_additive]\nprotected theorem mul_left_injective (h : IsUnit b) : Injective (\u00b7 * b) :=\n  fun _ _ => h.mul_right_cancel\n#align is_unit.mul_left_injective IsUnit.mul_left_injective\n#align is_add_unit.add_left_injective IsAddUnit.add_left_injective\n\nend Monoid\n\nvariable [DivisionMonoid M] {a : M}\n\n@[to_additive (attr := simp)]\nprotected theorem inv_mul_cancel : IsUnit a \u2192 a\u207b\u00b9 * a = 1 := by\n  rintro \u27e8u, rfl\u27e9\n  rw [\u2190 Units.val_inv_eq_inv_val, Units.inv_mul]\n#align is_unit.inv_mul_cancel IsUnit.inv_mul_cancel\n#align is_add_unit.neg_add_cancel IsAddUnit.neg_add_cancel\n\n@[to_additive (attr := simp)]\nprotected theorem mul_inv_cancel : IsUnit a \u2192 a * a\u207b\u00b9 = 1 := by\n  rintro \u27e8u, rfl\u27e9\n  rw [\u2190 Units.val_inv_eq_inv_val, Units.mul_inv]\n#align is_unit.mul_inv_cancel IsUnit.mul_inv_cancel\n#align is_add_unit.add_neg_cancel IsAddUnit.add_neg_cancel\n\nend IsUnit\n\n-- namespace\nend IsUnit\n\n-- section\nsection NoncomputableDefs\n\nvariable {M : Type _}\n\n/-- Constructs a `Group` structure on a `Monoid` consisting only of units. -/\nnoncomputable def groupOfIsUnit [hM : Monoid M] (h : \u2200 a : M, IsUnit a) : Group M :=\n  { hM with\n    inv := fun a => \u2191(h a).unit\u207b\u00b9,\n    mul_left_inv := fun a => by\n      change \u2191(h a).unit\u207b\u00b9 * a = 1\n      rw [Units.inv_mul_eq_iff_eq_mul, (h a).unit_spec, mul_one] }\n#align group_of_is_unit groupOfIsUnit\n\n/-- Constructs a `CommGroup` structure on a `CommMonoid` consisting only of units. -/\nnoncomputable def commGroupOfIsUnit [hM : CommMonoid M] (h : \u2200 a : M, IsUnit a) : CommGroup M :=\n  { hM with\n    inv := fun a => \u2191(h a).unit\u207b\u00b9,\n    mul_left_inv := fun a => by\n      change \u2191(h a).unit\u207b\u00b9 * a = 1\n      rw [Units.inv_mul_eq_iff_eq_mul, (h a).unit_spec, mul_one] }\n#align comm_group_of_is_unit commGroupOfIsUnit\n\nend NoncomputableDefs\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Group/Units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021706, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7148379708940544}}
{"text": "/-\nCopyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Adam Topaz, Bryan Gin-ge Chen, Ya\u00ebl Dillies\nPorted by: Fr\u00e9d\u00e9ric Dupuis\n\n! This file was ported from Lean 3 source module order.symm_diff\n! leanprover-community/mathlib commit 6eb334bd8f3433d5b08ba156b8ec3e6af47e1904\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.BooleanAlgebra\nimport Mathlib.Logic.Equiv.Basic\n\n/-!\n# Symmetric difference and bi-implication\n\nThis file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras.\n\n## Examples\n\nSome examples are\n* The symmetric difference of two sets is the set of elements that are in either but not both.\n* The symmetric difference on propositions is `Xor'`.\n* The symmetric difference on `Bool` is `Bool.xor`.\n* The equivalence of propositions. Two propositions are equivalent if they imply each other.\n* The symmetric difference translates to addition when considering a Boolean algebra as a Boolean\n  ring.\n\n## Main declarations\n\n* `symmDiff`: The symmetric difference operator, defined as `(a \\ b) \u2294 (b \\ a)`\n* `bihimp`: The bi-implication operator, defined as `(b \u21e8 a) \u2293 (a \u21e8 b)`\n\nIn generalized Boolean algebras, the symmetric difference operator is:\n\n* `symmDiff_comm`: commutative, and\n* `symmDiff_assoc`: associative.\n\n## Notations\n\n* `a \u2206 b`: `symmDiff a b`\n* `a \u21d4 b`: `bihimp a b`\n\n## References\n\nThe proof of associativity follows the note \"Associativity of the Symmetric Difference of Sets: A\nProof from the Book\" by John McCuan:\n\n* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>\n\n## Tags\n\nboolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication,\nHeyting\n-/\n\n\nopen Function OrderDual\n\nvariable {\u03b9 \u03b1 \u03b2 : Type _} {\u03c0 : \u03b9 \u2192 Type _}\n\n/-- The symmetric difference operator on a type with `\u2294` and `\\` is `(A \\ B) \u2294 (B \\ A)`. -/\ndef symmDiff [Sup \u03b1] [SDiff \u03b1] (a b : \u03b1) : \u03b1 :=\n  a \\ b \u2294 b \\ a\n#align symm_diff symmDiff\n\n/-- The Heyting bi-implication is `(b \u21e8 a) \u2293 (a \u21e8 b)`. This generalizes equivalence of\npropositions. -/\ndef bihimp [Inf \u03b1] [HImp \u03b1] (a b : \u03b1) : \u03b1 :=\n  (b \u21e8 a) \u2293 (a \u21e8 b)\n#align bihimp bihimp\n\n/- This notation might conflict with the Laplacian once we have it. Feel free to put it in locale\n  `order` or `symm_diff` if that happens. -/\n/-- Notation for symmDiff -/\ninfixl:100 \" \u2206 \" =>  symmDiff\n\n/-- Notation for bihimp -/\ninfixl:100 \" \u21d4 \" => bihimp\n\ntheorem symmDiff_def [Sup \u03b1] [SDiff \u03b1] (a b : \u03b1) : a \u2206 b = a \\ b \u2294 b \\ a :=\n  rfl\n#align symm_diff_def symmDiff_def\n\ntheorem bihimp_def [Inf \u03b1] [HImp \u03b1] (a b : \u03b1) : a \u21d4 b = (b \u21e8 a) \u2293 (a \u21e8 b) :=\n  rfl\n#align bihimp_def bihimp_def\n\ntheorem symmDiff_eq_Xor' (p q : Prop) : p \u2206 q = Xor' p q :=\n  rfl\n#align symm_diff_eq_xor symmDiff_eq_Xor'\n\n@[simp]\ntheorem bihimp_iff_iff {p q : Prop} : p \u21d4 q \u2194 (p \u2194 q) :=\n  (iff_iff_implies_and_implies _ _).symm.trans Iff.comm\n#align bihimp_iff_iff bihimp_iff_iff\n\n@[simp]\ntheorem Bool.symmDiff_eq_xor : \u2200 p q : Bool, p \u2206 q = xor p q := by decide\n#align bool.symm_diff_eq_bxor Bool.symmDiff_eq_xor\n\nsection GeneralizedCoheytingAlgebra\n\nvariable [GeneralizedCoheytingAlgebra \u03b1] (a b c d : \u03b1)\n\n@[simp]\ntheorem toDual_symmDiff : toDual (a \u2206 b) = toDual a \u21d4 toDual b :=\n  rfl\n#align to_dual_symm_diff toDual_symmDiff\n\n@[simp]\ntheorem ofDual_bihimp (a b : \u03b1\u1d52\u1d48) : ofDual (a \u21d4 b) = ofDual a \u2206 ofDual b :=\n  rfl\n#align of_dual_bihimp ofDual_bihimp\n\ntheorem symmDiff_comm : a \u2206 b = b \u2206 a := by simp only [symmDiff, sup_comm]\n#align symm_diff_comm symmDiff_comm\n\ninstance symmDiff_isCommutative : IsCommutative \u03b1 (\u00b7 \u2206 \u00b7) :=\n  \u27e8symmDiff_comm\u27e9\n#align symm_diff_is_comm symmDiff_isCommutative\n\n@[simp]\ntheorem symmDiff_self : a \u2206 a = \u22a5 := by rw [symmDiff, sup_idem, sdiff_self]\n#align symm_diff_self symmDiff_self\n\n@[simp]\ntheorem symmDiff_bot : a \u2206 \u22a5 = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq]\n#align symm_diff_bot symmDiff_bot\n\n@[simp]\ntheorem bot_symmDiff : \u22a5 \u2206 a = a := by rw [symmDiff_comm, symmDiff_bot]\n#align bot_symm_diff bot_symmDiff\n\n@[simp]\ntheorem symmDiff_eq_bot {a b : \u03b1} : a \u2206 b = \u22a5 \u2194 a = b := by\n  simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff]\n#align symm_diff_eq_bot symmDiff_eq_bot\n\ntheorem symmDiff_of_le {a b : \u03b1} (h : a \u2264 b) : a \u2206 b = b \\ a := by\n  rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq]\n#align symm_diff_of_le symmDiff_of_le\n\ntheorem symmDiff_of_ge {a b : \u03b1} (h : b \u2264 a) : a \u2206 b = a \\ b := by\n  rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq]\n#align symm_diff_of_ge symmDiff_of_ge\n\ntheorem symmDiff_le {a b c : \u03b1} (ha : a \u2264 b \u2294 c) (hb : b \u2264 a \u2294 c) : a \u2206 b \u2264 c :=\n  sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb\n#align symm_diff_le symmDiff_le\n\ntheorem symmDiff_le_iff {a b c : \u03b1} : a \u2206 b \u2264 c \u2194 a \u2264 b \u2294 c \u2227 b \u2264 a \u2294 c := by\n  simp_rw [symmDiff, sup_le_iff, sdiff_le_iff]\n#align symm_diff_le_iff symmDiff_le_iff\n\n@[simp]\ntheorem symmDiff_le_sup {a b : \u03b1} : a \u2206 b \u2264 a \u2294 b :=\n  sup_le_sup sdiff_le sdiff_le\n#align symm_diff_le_sup symmDiff_le_sup\n\ntheorem symmDiff_eq_sup_sdiff_inf : a \u2206 b = (a \u2294 b) \\ (a \u2293 b) := by simp [sup_sdiff, symmDiff]\n#align symm_diff_eq_sup_sdiff_inf symmDiff_eq_sup_sdiff_inf\n\ntheorem Disjoint.symmDiff_eq_sup {a b : \u03b1} (h : Disjoint a b) : a \u2206 b = a \u2294 b := by\n  rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right]\n#align disjoint.symm_diff_eq_sup Disjoint.symmDiff_eq_sup\n\ntheorem symmDiff_sdiff : a \u2206 b \\ c = a \\ (b \u2294 c) \u2294 b \\ (a \u2294 c) := by\n  rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left]\n#align symm_diff_sdiff symmDiff_sdiff\n\n@[simp]\ntheorem symmDiff_sdiff_inf : a \u2206 b \\ (a \u2293 b) = a \u2206 b := by\n  rw [symmDiff_sdiff]\n  simp [symmDiff]\n#align symm_diff_sdiff_inf symmDiff_sdiff_inf\n\n@[simp]\ntheorem symmDiff_sdiff_eq_sup : a \u2206 (b \\ a) = a \u2294 b := by\n  rw [symmDiff, sdiff_idem]\n  exact\n    le_antisymm (sup_le_sup sdiff_le sdiff_le)\n      (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup)\n#align symm_diff_sdiff_eq_sup symmDiff_sdiff_eq_sup\n\n@[simp]\ntheorem sdiff_symmDiff_eq_sup : (a \\ b) \u2206 b = a \u2294 b := by\n  rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm]\n#align sdiff_symm_diff_eq_sup sdiff_symmDiff_eq_sup\n\n@[simp]\ntheorem symmDiff_sup_inf : a \u2206 b \u2294 a \u2293 b = a \u2294 b := by\n  refine' le_antisymm (sup_le symmDiff_le_sup inf_le_sup) _\n  rw [sup_inf_left, symmDiff]\n  refine' sup_le (le_inf le_sup_right _) (le_inf _ le_sup_right)\n  \u00b7 rw [sup_right_comm]\n    exact le_sup_of_le_left le_sdiff_sup\n  \u00b7 rw [sup_assoc]\n    exact le_sup_of_le_right le_sdiff_sup\n#align symm_diff_sup_inf symmDiff_sup_inf\n\n@[simp]\ntheorem inf_sup_symmDiff : a \u2293 b \u2294 a \u2206 b = a \u2294 b := by rw [sup_comm, symmDiff_sup_inf]\n#align inf_sup_symm_diff inf_sup_symmDiff\n\n@[simp]\ntheorem symmDiff_symmDiff_inf : a \u2206 b \u2206 (a \u2293 b) = a \u2294 b := by\n  rw [\u2190 symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf]\n#align symm_diff_symm_diff_inf symmDiff_symmDiff_inf\n\n@[simp]\ntheorem inf_symmDiff_symmDiff : (a \u2293 b) \u2206 (a \u2206 b) = a \u2294 b := by\n  rw [symmDiff_comm, symmDiff_symmDiff_inf]\n#align inf_symm_diff_symm_diff inf_symmDiff_symmDiff\n\ntheorem symmDiff_triangle : a \u2206 c \u2264 a \u2206 b \u2294 b \u2206 c := by\n  refine' (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq _\n  rw [@sup_comm _ _ (c \\ b), sup_sup_sup_comm, symmDiff, symmDiff]\n#align symm_diff_triangle symmDiff_triangle\n\nend GeneralizedCoheytingAlgebra\n\nsection GeneralizedHeytingAlgebra\n\nvariable [GeneralizedHeytingAlgebra \u03b1] (a b c d : \u03b1)\n\n@[simp]\ntheorem toDual_bihimp : toDual (a \u21d4 b) = toDual a \u2206 toDual b :=\n  rfl\n#align to_dual_bihimp toDual_bihimp\n\n@[simp]\ntheorem ofDual_symmDiff (a b : \u03b1\u1d52\u1d48) : ofDual (a \u2206 b) = ofDual a \u21d4 ofDual b :=\n  rfl\n#align of_dual_symm_diff ofDual_symmDiff\n\ntheorem bihimp_comm : a \u21d4 b = b \u21d4 a := by simp only [(\u00b7 \u21d4 \u00b7), inf_comm]\n#align bihimp_comm bihimp_comm\n\ninstance bihimp_isCommutative : IsCommutative \u03b1 (\u00b7 \u21d4 \u00b7) :=\n  \u27e8bihimp_comm\u27e9\n#align bihimp_is_comm bihimp_isCommutative\n\n@[simp]\ntheorem bihimp_self : a \u21d4 a = \u22a4 := by rw [bihimp, inf_idem, himp_self]\n#align bihimp_self bihimp_self\n\n@[simp]\ntheorem bihimp_top : a \u21d4 \u22a4 = a := by rw [bihimp, himp_top, top_himp, inf_top_eq]\n#align bihimp_top bihimp_top\n\n@[simp]\ntheorem top_bihimp : \u22a4 \u21d4 a = a := by rw [bihimp_comm, bihimp_top]\n#align top_bihimp top_bihimp\n\n@[simp]\ntheorem bihimp_eq_top {a b : \u03b1} : a \u21d4 b = \u22a4 \u2194 a = b :=\n  @symmDiff_eq_bot \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_eq_top bihimp_eq_top\n\ntheorem bihimp_of_le {a b : \u03b1} (h : a \u2264 b) : a \u21d4 b = b \u21e8 a := by\n  rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq]\n#align bihimp_of_le bihimp_of_le\n\ntheorem bihimp_of_ge {a b : \u03b1} (h : b \u2264 a) : a \u21d4 b = a \u21e8 b := by\n  rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq]\n#align bihimp_of_ge bihimp_of_ge\n\ntheorem le_bihimp {a b c : \u03b1} (hb : a \u2293 b \u2264 c) (hc : a \u2293 c \u2264 b) : a \u2264 b \u21d4 c :=\n  le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb\n#align le_bihimp le_bihimp\n\ntheorem le_bihimp_iff {a b c : \u03b1} : a \u2264 b \u21d4 c \u2194 a \u2293 b \u2264 c \u2227 a \u2293 c \u2264 b := by\n  simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm]\n#align le_bihimp_iff le_bihimp_iff\n\n@[simp]\ntheorem inf_le_bihimp {a b : \u03b1} : a \u2293 b \u2264 a \u21d4 b :=\n  inf_le_inf le_himp le_himp\n#align inf_le_bihimp inf_le_bihimp\n\ntheorem bihimp_eq_inf_himp_inf : a \u21d4 b = a \u2294 b \u21e8 a \u2293 b := by simp [himp_inf_distrib, bihimp]\n#align bihimp_eq_inf_himp_inf bihimp_eq_inf_himp_inf\n\ntheorem Codisjoint.bihimp_eq_inf {a b : \u03b1} (h : Codisjoint a b) : a \u21d4 b = a \u2293 b := by\n  rw [bihimp, h.himp_eq_left, h.himp_eq_right]\n#align codisjoint.bihimp_eq_inf Codisjoint.bihimp_eq_inf\n\ntheorem himp_bihimp : a \u21e8 b \u21d4 c = (a \u2293 c \u21e8 b) \u2293 (a \u2293 b \u21e8 c) := by\n  rw [bihimp, himp_inf_distrib, himp_himp, himp_himp]\n#align himp_bihimp himp_bihimp\n\n@[simp]\ntheorem sup_himp_bihimp : a \u2294 b \u21e8 a \u21d4 b = a \u21d4 b := by\n  rw [himp_bihimp]\n  simp [bihimp]\n#align sup_himp_bihimp sup_himp_bihimp\n\n@[simp]\ntheorem bihimp_himp_eq_inf : a \u21d4 (a \u21e8 b) = a \u2293 b :=\n  @symmDiff_sdiff_eq_sup \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_himp_eq_inf bihimp_himp_eq_inf\n\n@[simp]\ntheorem himp_bihimp_eq_inf : (b \u21e8 a) \u21d4 b = a \u2293 b :=\n  @sdiff_symmDiff_eq_sup \u03b1\u1d52\u1d48 _ _ _\n#align himp_bihimp_eq_inf himp_bihimp_eq_inf\n\n@[simp]\ntheorem bihimp_inf_sup : a \u21d4 b \u2293 (a \u2294 b) = a \u2293 b :=\n  @symmDiff_sup_inf \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_inf_sup bihimp_inf_sup\n\n@[simp]\ntheorem sup_inf_bihimp : (a \u2294 b) \u2293 a \u21d4 b = a \u2293 b :=\n  @inf_sup_symmDiff \u03b1\u1d52\u1d48 _ _ _\n#align sup_inf_bihimp sup_inf_bihimp\n\n@[simp]\ntheorem bihimp_bihimp_sup : a \u21d4 b \u21d4 (a \u2294 b) = a \u2293 b :=\n  @symmDiff_symmDiff_inf \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_bihimp_sup bihimp_bihimp_sup\n\n@[simp]\ntheorem sup_bihimp_bihimp : (a \u2294 b) \u21d4 (a \u21d4 b) = a \u2293 b :=\n  @inf_symmDiff_symmDiff \u03b1\u1d52\u1d48 _ _ _\n#align sup_bihimp_bihimp sup_bihimp_bihimp\n\ntheorem bihimp_triangle : a \u21d4 b \u2293 b \u21d4 c \u2264 a \u21d4 c :=\n  @symmDiff_triangle \u03b1\u1d52\u1d48 _ _ _ _\n#align bihimp_triangle bihimp_triangle\n\nend GeneralizedHeytingAlgebra\n\nsection CoheytingAlgebra\n\nvariable [CoheytingAlgebra \u03b1] (a : \u03b1)\n\n@[simp]\ntheorem symmDiff_top' : a \u2206 \u22a4 = \uffe2a := by simp [symmDiff]\n#align symm_diff_top' symmDiff_top'\n\n@[simp]\ntheorem top_symmDiff' : \u22a4 \u2206 a = \uffe2a := by simp [symmDiff]\n#align top_symm_diff' top_symmDiff'\n\n@[simp]\ntheorem hnot_symmDiff_self : (\uffe2a) \u2206 a = \u22a4 := by\n  rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self]\n  exact Codisjoint.top_le codisjoint_hnot_left\n#align hnot_symm_diff_self hnot_symmDiff_self\n\n@[simp]\ntheorem symmDiff_hnot_self : a \u2206 (\uffe2a) = \u22a4 := by rw [symmDiff_comm, hnot_symmDiff_self]\n#align symm_diff_hnot_self symmDiff_hnot_self\n\ntheorem IsCompl.symmDiff_eq_top {a b : \u03b1} (h : IsCompl a b) : a \u2206 b = \u22a4 := by\n  rw [h.eq_hnot, hnot_symmDiff_self]\n#align is_compl.symm_diff_eq_top IsCompl.symmDiff_eq_top\n\nend CoheytingAlgebra\n\nsection HeytingAlgebra\n\nvariable [HeytingAlgebra \u03b1] (a : \u03b1)\n\n@[simp]\ntheorem bihimp_bot : a \u21d4 \u22a5 = a\u1d9c := by simp [bihimp]\n#align bihimp_bot bihimp_bot\n\n@[simp]\ntheorem bot_bihimp : \u22a5 \u21d4 a = a\u1d9c := by simp [bihimp]\n#align bot_bihimp bot_bihimp\n\n@[simp]\ntheorem compl_bihimp_self : a\u1d9c \u21d4 a = \u22a5 :=\n  @hnot_symmDiff_self \u03b1\u1d52\u1d48 _ _\n#align compl_bihimp_self compl_bihimp_self\n\n@[simp]\ntheorem bihimp_hnot_self : a \u21d4 a\u1d9c = \u22a5 :=\n  @symmDiff_hnot_self \u03b1\u1d52\u1d48 _ _\n#align bihimp_hnot_self bihimp_hnot_self\n\ntheorem IsCompl.bihimp_eq_bot {a b : \u03b1} (h : IsCompl a b) : a \u21d4 b = \u22a5 := by\n  rw [h.eq_compl, compl_bihimp_self]\n#align is_compl.bihimp_eq_bot IsCompl.bihimp_eq_bot\n\nend HeytingAlgebra\n\nsection GeneralizedBooleanAlgebra\n\nvariable [GeneralizedBooleanAlgebra \u03b1] (a b c d : \u03b1)\n\n@[simp]\ntheorem sup_sdiff_symmDiff : (a \u2294 b) \\ a \u2206 b = a \u2293 b :=\n  sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf])\n#align sup_sdiff_symm_diff sup_sdiff_symmDiff\n\ntheorem disjoint_symmDiff_inf : Disjoint (a \u2206 b) (a \u2293 b) := by\n  rw [symmDiff_eq_sup_sdiff_inf]\n  exact disjoint_sdiff_self_left\n#align disjoint_symm_diff_inf disjoint_symmDiff_inf\n\ntheorem inf_symmDiff_distrib_left : a \u2293 b \u2206 c = (a \u2293 b) \u2206 (a \u2293 c) := by\n  rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left,\n    symmDiff_eq_sup_sdiff_inf]\n#align inf_symm_diff_distrib_left inf_symmDiff_distrib_left\n\ntheorem inf_symmDiff_distrib_right : a \u2206 b \u2293 c = (a \u2293 c) \u2206 (b \u2293 c) := by\n  simp_rw [@inf_comm _ _ _ c, inf_symmDiff_distrib_left]\n#align inf_symm_diff_distrib_right inf_symmDiff_distrib_right\n\ntheorem sdiff_symmDiff : c \\ a \u2206 b = c \u2293 a \u2293 b \u2294 c \\ a \u2293 c \\ b := by\n  simp only [(\u00b7 \u2206 \u00b7), sdiff_sdiff_sup_sdiff']\n#align sdiff_symm_diff sdiff_symmDiff\n\ntheorem sdiff_symmDiff' : c \\ a \u2206 b = c \u2293 a \u2293 b \u2294 c \\ (a \u2294 b) := by\n  rw [sdiff_symmDiff, sdiff_sup, sup_comm]\n#align sdiff_symm_diff' sdiff_symmDiff'\n\n@[simp]\ntheorem symmDiff_sdiff_left : a \u2206 b \\ a = b \\ a := by\n  rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]\n#align symm_diff_sdiff_left symmDiff_sdiff_left\n\n@[simp]\ntheorem symmDiff_sdiff_right : a \u2206 b \\ b = a \\ b := by rw [symmDiff_comm, symmDiff_sdiff_left]\n#align symm_diff_sdiff_right symmDiff_sdiff_right\n\n@[simp]\ntheorem sdiff_symmDiff_left : a \\ a \u2206 b = a \u2293 b := by simp [sdiff_symmDiff]\n#align sdiff_symm_diff_left sdiff_symmDiff_left\n\n@[simp]\ntheorem sdiff_symmDiff_right : b \\ a \u2206 b = a \u2293 b := by\n  rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left]\n#align sdiff_symm_diff_right sdiff_symmDiff_right\n\ntheorem symmDiff_eq_sup : a \u2206 b = a \u2294 b \u2194 Disjoint a b := by\n  refine' \u27e8fun h => _, Disjoint.symmDiff_eq_sup\u27e9\n  rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h\n  exact h.of_disjoint_inf_of_le le_sup_left\n#align symm_diff_eq_sup symmDiff_eq_sup\n\n@[simp]\ntheorem le_symmDiff_iff_left : a \u2264 a \u2206 b \u2194 Disjoint a b := by\n  refine' \u27e8fun h => _, fun h => h.symmDiff_eq_sup.symm \u25b8 le_sup_left\u27e9\n  rw [symmDiff_eq_sup_sdiff_inf] at h\n  exact disjoint_iff_inf_le.mpr (le_sdiff_iff.1 <| inf_le_of_left_le h).le\n#align le_symm_diff_iff_left le_symmDiff_iff_left\n\n@[simp]\ntheorem le_symmDiff_iff_right : b \u2264 a \u2206 b \u2194 Disjoint a b := by\n  rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm]\n#align le_symm_diff_iff_right le_symmDiff_iff_right\n\ntheorem symmDiff_symmDiff_left :\n    a \u2206 b \u2206 c = a \\ (b \u2294 c) \u2294 b \\ (a \u2294 c) \u2294 c \\ (a \u2294 b) \u2294 a \u2293 b \u2293 c :=\n  calc\n    a \u2206 b \u2206 c = a \u2206 b \\ c \u2294 c \\ a \u2206 b := symmDiff_def _ _\n    _ = a \\ (b \u2294 c) \u2294 b \\ (a \u2294 c) \u2294 (c \\ (a \u2294 b) \u2294 c \u2293 a \u2293 b) := by\n        { rw [sdiff_symmDiff', @sup_comm _ _ (c \u2293 a \u2293 b), symmDiff_sdiff] }\n    _ = a \\ (b \u2294 c) \u2294 b \\ (a \u2294 c) \u2294 c \\ (a \u2294 b) \u2294 a \u2293 b \u2293 c := by ac_rfl\n#align symm_diff_symm_diff_left symmDiff_symmDiff_left\n\ntheorem symmDiff_symmDiff_right :\n    a \u2206 (b \u2206 c) = a \\ (b \u2294 c) \u2294 b \\ (a \u2294 c) \u2294 c \\ (a \u2294 b) \u2294 a \u2293 b \u2293 c :=\n  calc\n    a \u2206 (b \u2206 c) = a \\ b \u2206 c \u2294 b \u2206 c \\ a := symmDiff_def _ _\n    _ = a \\ (b \u2294 c) \u2294 a \u2293 b \u2293 c \u2294 (b \\ (c \u2294 a) \u2294 c \\ (b \u2294 a)) := by\n        { rw [sdiff_symmDiff', @sup_comm _ _ (a \u2293 b \u2293 c), symmDiff_sdiff] }\n    _ = a \\ (b \u2294 c) \u2294 b \\ (a \u2294 c) \u2294 c \\ (a \u2294 b) \u2294 a \u2293 b \u2293 c := by ac_rfl\n#align symm_diff_symm_diff_right symmDiff_symmDiff_right\n\ntheorem symmDiff_assoc : a \u2206 b \u2206 c = a \u2206 (b \u2206 c) := by\n  rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right]\n#align symm_diff_assoc symmDiff_assoc\n\ninstance symmDiff_isAssociative : IsAssociative \u03b1 (\u00b7 \u2206 \u00b7) :=\n  \u27e8symmDiff_assoc\u27e9\n#align symm_diff_is_assoc symmDiff_isAssociative\n\ntheorem symmDiff_left_comm : a \u2206 (b \u2206 c) = b \u2206 (a \u2206 c) := by\n  simp_rw [\u2190 symmDiff_assoc, symmDiff_comm]\n#align symm_diff_left_comm symmDiff_left_comm\n\ntheorem symmDiff_right_comm : a \u2206 b \u2206 c = a \u2206 c \u2206 b := by simp_rw [symmDiff_assoc, symmDiff_comm]\n#align symm_diff_right_comm symmDiff_right_comm\n\ntheorem symmDiff_symmDiff_symmDiff_comm : a \u2206 b \u2206 (c \u2206 d) = a \u2206 c \u2206 (b \u2206 d) := by\n  simp_rw [symmDiff_assoc, symmDiff_left_comm]\n#align symm_diff_symm_diff_symm_diff_comm symmDiff_symmDiff_symmDiff_comm\n\n@[simp]\ntheorem symmDiff_symmDiff_cancel_left : a \u2206 (a \u2206 b) = b := by simp [\u2190 symmDiff_assoc]\n#align symm_diff_symm_diff_cancel_left symmDiff_symmDiff_cancel_left\n\n@[simp]\ntheorem symmDiff_symmDiff_cancel_right : b \u2206 a \u2206 a = b := by simp [symmDiff_assoc]\n#align symm_diff_symm_diff_cancel_right symmDiff_symmDiff_cancel_right\n\n@[simp]\ntheorem symmDiff_symmDiff_self' : a \u2206 b \u2206 a = b := by\n  rw [symmDiff_comm, symmDiff_symmDiff_cancel_left]\n#align symm_diff_symm_diff_self' symmDiff_symmDiff_self'\n\ntheorem symmDiff_left_involutive (a : \u03b1) : Involutive (\u00b7 \u2206 a) :=\n  symmDiff_symmDiff_cancel_right _\n#align symm_diff_left_involutive symmDiff_left_involutive\n\ntheorem symmDiff_right_involutive (a : \u03b1) : Involutive ((\u00b7 \u2206 \u00b7) a) :=\n  symmDiff_symmDiff_cancel_left _\n#align symm_diff_right_involutive symmDiff_right_involutive\n\ntheorem symmDiff_left_injective (a : \u03b1) : Injective (\u00b7 \u2206 a) :=\n  Function.Involutive.injective (symmDiff_left_involutive a)\n#align symm_diff_left_injective symmDiff_left_injective\n\ntheorem symmDiff_right_injective (a : \u03b1) : Injective ((\u00b7 \u2206 \u00b7) a) :=\n  Function.Involutive.injective (symmDiff_right_involutive _)\n#align symm_diff_right_injective symmDiff_right_injective\n\ntheorem symmDiff_left_surjective (a : \u03b1) : Surjective (\u00b7 \u2206 a) :=\n  Function.Involutive.surjective (symmDiff_left_involutive _)\n#align symm_diff_left_surjective symmDiff_left_surjective\n\ntheorem symmDiff_right_surjective (a : \u03b1) : Surjective ((\u00b7 \u2206 \u00b7) a) :=\n  Function.Involutive.surjective (symmDiff_right_involutive _)\n#align symm_diff_right_surjective symmDiff_right_surjective\n\nvariable {a b c}\n\n@[simp]\ntheorem symmDiff_left_inj : a \u2206 b = c \u2206 b \u2194 a = c :=\n  (symmDiff_left_injective _).eq_iff\n#align symm_diff_left_inj symmDiff_left_inj\n\n@[simp]\ntheorem symmDiff_right_inj : a \u2206 b = a \u2206 c \u2194 b = c :=\n  (symmDiff_right_injective _).eq_iff\n#align symm_diff_right_inj symmDiff_right_inj\n\n@[simp]\ntheorem symmDiff_eq_left : a \u2206 b = a \u2194 b = \u22a5 :=\n  calc\n    a \u2206 b = a \u2194 a \u2206 b = a \u2206 \u22a5 := by rw [symmDiff_bot]\n    _ \u2194 b = \u22a5 := by rw [symmDiff_right_inj]\n#align symm_diff_eq_left symmDiff_eq_left\n\n@[simp]\ntheorem symmDiff_eq_right : a \u2206 b = b \u2194 a = \u22a5 := by rw [symmDiff_comm, symmDiff_eq_left]\n#align symm_diff_eq_right symmDiff_eq_right\n\nprotected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) :\n    Disjoint (a \u2206 b) c := by\n  rw [symmDiff_eq_sup_sdiff_inf]\n  exact (ha.sup_left hb).disjoint_sdiff_left\n#align disjoint.symm_diff_left Disjoint.symmDiff_left\n\nprotected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) :\n    Disjoint a (b \u2206 c) :=\n  (ha.symm.symmDiff_left hb.symm).symm\n#align disjoint.symm_diff_right Disjoint.symmDiff_right\n\ntheorem symmDiff_eq_iff_sdiff_eq (ha : a \u2264 c) : a \u2206 b = c \u2194 c \\ a = b := by\n  rw [\u2190 symmDiff_of_le ha]\n  exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm\n#align symm_diff_eq_iff_sdiff_eq symmDiff_eq_iff_sdiff_eq\n\nend GeneralizedBooleanAlgebra\n\nsection BooleanAlgebra\n\nvariable [BooleanAlgebra \u03b1] (a b c d : \u03b1)\n\n/- `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to\nthe `GeneralizedBooleanAlgebra` ones -/\nsection CogeneralizedBooleanAlgebra\n\n@[simp]\ntheorem inf_himp_bihimp : a \u21d4 b \u21e8 a \u2293 b = a \u2294 b :=\n  @sup_sdiff_symmDiff \u03b1\u1d52\u1d48 _ _ _\n#align inf_himp_bihimp inf_himp_bihimp\n\ntheorem codisjoint_bihimp_sup : Codisjoint (a \u21d4 b) (a \u2294 b) :=\n  @disjoint_symmDiff_inf \u03b1\u1d52\u1d48 _ _ _\n#align codisjoint_bihimp_sup codisjoint_bihimp_sup\n\n@[simp]\ntheorem himp_bihimp_left : a \u21e8 a \u21d4 b = a \u21e8 b :=\n  @symmDiff_sdiff_left \u03b1\u1d52\u1d48 _ _ _\n#align himp_bihimp_left himp_bihimp_left\n\n@[simp]\ntheorem himp_bihimp_right : b \u21e8 a \u21d4 b = b \u21e8 a :=\n  @symmDiff_sdiff_right \u03b1\u1d52\u1d48 _ _ _\n#align himp_bihimp_right himp_bihimp_right\n\n@[simp]\ntheorem bihimp_himp_left : a \u21d4 b \u21e8 a = a \u2294 b :=\n  @sdiff_symmDiff_left \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_himp_left bihimp_himp_left\n\n@[simp]\ntheorem bihimp_himp_right : a \u21d4 b \u21e8 b = a \u2294 b :=\n  @sdiff_symmDiff_right \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_himp_right bihimp_himp_right\n\n@[simp]\ntheorem bihimp_eq_inf : a \u21d4 b = a \u2293 b \u2194 Codisjoint a b :=\n  @symmDiff_eq_sup \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_eq_inf bihimp_eq_inf\n\n@[simp]\ntheorem bihimp_le_iff_left : a \u21d4 b \u2264 a \u2194 Codisjoint a b :=\n  @le_symmDiff_iff_left \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_le_iff_left bihimp_le_iff_left\n\n@[simp]\ntheorem bihimp_le_iff_right : a \u21d4 b \u2264 b \u2194 Codisjoint a b :=\n  @le_symmDiff_iff_right \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_le_iff_right bihimp_le_iff_right\n\ntheorem bihimp_assoc : a \u21d4 b \u21d4 c = a \u21d4 (b \u21d4 c) :=\n  @symmDiff_assoc \u03b1\u1d52\u1d48 _ _ _ _\n#align bihimp_assoc bihimp_assoc\n\ninstance bihimp_isAssociative : IsAssociative \u03b1 (\u00b7 \u21d4 \u00b7) :=\n  \u27e8bihimp_assoc\u27e9\n#align bihimp_is_assoc bihimp_isAssociative\n\ntheorem bihimp_left_comm : a \u21d4 (b \u21d4 c) = b \u21d4 (a \u21d4 c) := by simp_rw [\u2190 bihimp_assoc, bihimp_comm]\n#align bihimp_left_comm bihimp_left_comm\n\ntheorem bihimp_right_comm : a \u21d4 b \u21d4 c = a \u21d4 c \u21d4 b := by simp_rw [bihimp_assoc, bihimp_comm]\n#align bihimp_right_comm bihimp_right_comm\n\ntheorem bihimp_bihimp_bihimp_comm : a \u21d4 b \u21d4 (c \u21d4 d) = a \u21d4 c \u21d4 (b \u21d4 d) := by\n  simp_rw [bihimp_assoc, bihimp_left_comm]\n#align bihimp_bihimp_bihimp_comm bihimp_bihimp_bihimp_comm\n\n@[simp]\ntheorem bihimp_bihimp_cancel_left : a \u21d4 (a \u21d4 b) = b := by simp [\u2190 bihimp_assoc]\n#align bihimp_bihimp_cancel_left bihimp_bihimp_cancel_left\n\n@[simp]\ntheorem bihimp_bihimp_cancel_right : b \u21d4 a \u21d4 a = b := by simp [bihimp_assoc]\n#align bihimp_bihimp_cancel_right bihimp_bihimp_cancel_right\n\n@[simp]\ntheorem bihimp_bihimp_self : a \u21d4 b \u21d4 a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left]\n#align bihimp_bihimp_self bihimp_bihimp_self\n\ntheorem bihimp_left_involutive (a : \u03b1) : Involutive (\u00b7 \u21d4 a) :=\n  bihimp_bihimp_cancel_right _\n#align bihimp_left_involutive bihimp_left_involutive\n\ntheorem bihimp_right_involutive (a : \u03b1) : Involutive ((\u00b7 \u21d4 \u00b7) a) :=\n  bihimp_bihimp_cancel_left _\n#align bihimp_right_involutive bihimp_right_involutive\n\ntheorem bihimp_left_injective (a : \u03b1) : Injective (\u00b7 \u21d4 a) :=\n  @symmDiff_left_injective \u03b1\u1d52\u1d48 _ _\n#align bihimp_left_injective bihimp_left_injective\n\ntheorem bihimp_right_injective (a : \u03b1) : Injective ((\u00b7 \u21d4 \u00b7) a) :=\n  @symmDiff_right_injective \u03b1\u1d52\u1d48 _ _\n#align bihimp_right_injective bihimp_right_injective\n\ntheorem bihimp_left_surjective (a : \u03b1) : Surjective (\u00b7 \u21d4 a) :=\n  @symmDiff_left_surjective \u03b1\u1d52\u1d48 _ _\n#align bihimp_left_surjective bihimp_left_surjective\n\ntheorem bihimp_right_surjective (a : \u03b1) : Surjective ((\u00b7 \u21d4 \u00b7) a) :=\n  @symmDiff_right_surjective \u03b1\u1d52\u1d48 _ _\n#align bihimp_right_surjective bihimp_right_surjective\n\nvariable {a b c}\n\n@[simp]\ntheorem bihimp_left_inj : a \u21d4 b = c \u21d4 b \u2194 a = c :=\n  (bihimp_left_injective _).eq_iff\n#align bihimp_left_inj bihimp_left_inj\n\n@[simp]\ntheorem bihimp_right_inj : a \u21d4 b = a \u21d4 c \u2194 b = c :=\n  (bihimp_right_injective _).eq_iff\n#align bihimp_right_inj bihimp_right_inj\n\n@[simp]\ntheorem bihimp_eq_left : a \u21d4 b = a \u2194 b = \u22a4 :=\n  @symmDiff_eq_left \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_eq_left bihimp_eq_left\n\n@[simp]\ntheorem bihimp_eq_right : a \u21d4 b = b \u2194 a = \u22a4 :=\n  @symmDiff_eq_right \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_eq_right bihimp_eq_right\n\nprotected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) :\n    Codisjoint (a \u21d4 b) c :=\n  (ha.inf_left hb).mono_left inf_le_bihimp\n#align codisjoint.bihimp_left Codisjoint.bihimp_left\n\nprotected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) :\n    Codisjoint a (b \u21d4 c) :=\n  (ha.inf_right hb).mono_right inf_le_bihimp\n#align codisjoint.bihimp_right Codisjoint.bihimp_right\n\nend CogeneralizedBooleanAlgebra\n\ntheorem symmDiff_eq : a \u2206 b = a \u2293 b\u1d9c \u2294 b \u2293 a\u1d9c := by simp only [(\u00b7 \u2206 \u00b7), sdiff_eq]\n#align symm_diff_eq symmDiff_eq\n\ntheorem bihimp_eq : a \u21d4 b = (a \u2294 b\u1d9c) \u2293 (b \u2294 a\u1d9c) := by simp only [(\u00b7 \u21d4 \u00b7), himp_eq]\n#align bihimp_eq bihimp_eq\n\ntheorem symmDiff_eq' : a \u2206 b = (a \u2294 b) \u2293 (a\u1d9c \u2294 b\u1d9c) := by\n  rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf]\n#align symm_diff_eq' symmDiff_eq'\n\ntheorem bihimp_eq' : a \u21d4 b = a \u2293 b \u2294 a\u1d9c \u2293 b\u1d9c :=\n  @symmDiff_eq' \u03b1\u1d52\u1d48 _ _ _\n#align bihimp_eq' bihimp_eq'\n\ntheorem symmDiff_top : a \u2206 \u22a4 = a\u1d9c :=\n  symmDiff_top' _\n#align symm_diff_top symmDiff_top\n\ntheorem top_symmDiff : \u22a4 \u2206 a = a\u1d9c :=\n  top_symmDiff' _\n#align top_symm_diff top_symmDiff\n\n@[simp]\ntheorem compl_symmDiff : (a \u2206 b)\u1d9c = a \u21d4 b := by\n  simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm]\n#align compl_symm_diff compl_symmDiff\n\n@[simp]\ntheorem compl_bihimp : (a \u21d4 b)\u1d9c = a \u2206 b :=\n  @compl_symmDiff \u03b1\u1d52\u1d48 _ _ _\n#align compl_bihimp compl_bihimp\n\n@[simp]\ntheorem compl_symmDiff_compl : a\u1d9c \u2206 b\u1d9c = a \u2206 b :=\n  sup_comm.trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq]\n#align compl_symm_diff_compl compl_symmDiff_compl\n\n@[simp]\ntheorem compl_bihimp_compl : a\u1d9c \u21d4 b\u1d9c = a \u21d4 b :=\n  @compl_symmDiff_compl \u03b1\u1d52\u1d48 _ _ _\n#align compl_bihimp_compl compl_bihimp_compl\n\n@[simp]\ntheorem symmDiff_eq_top : a \u2206 b = \u22a4 \u2194 IsCompl a b := by\n  rw [symmDiff_eq', \u2190 compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff,\n    codisjoint_iff, and_comm]\n#align symm_diff_eq_top symmDiff_eq_top\n\n@[simp]\ntheorem bihimp_eq_bot : a \u21d4 b = \u22a5 \u2194 IsCompl a b := by\n  rw [bihimp_eq', \u2190 compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff,\n    codisjoint_iff]\n#align bihimp_eq_bot bihimp_eq_bot\n\n@[simp]\ntheorem compl_symmDiff_self : a\u1d9c \u2206 a = \u22a4 :=\n  hnot_symmDiff_self _\n#align compl_symm_diff_self compl_symmDiff_self\n\n@[simp]\ntheorem symmDiff_compl_self : a \u2206 a\u1d9c = \u22a4 :=\n  symmDiff_hnot_self _\n#align symm_diff_compl_self symmDiff_compl_self\n\ntheorem symmDiff_symmDiff_right' :\n    a \u2206 (b \u2206 c) = a \u2293 b \u2293 c \u2294 a \u2293 b\u1d9c \u2293 c\u1d9c \u2294 a\u1d9c \u2293 b \u2293 c\u1d9c \u2294 a\u1d9c \u2293 b\u1d9c \u2293 c :=\n  calc\n    a \u2206 (b \u2206 c) = a \u2293 (b \u2293 c \u2294 b\u1d9c \u2293 c\u1d9c) \u2294 (b \u2293 c\u1d9c \u2294 c \u2293 b\u1d9c) \u2293 a\u1d9c := by\n        { rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] }\n    _ = a \u2293 b \u2293 c \u2294 a \u2293 b\u1d9c \u2293 c\u1d9c \u2294 b \u2293 c\u1d9c \u2293 a\u1d9c \u2294 c \u2293 b\u1d9c \u2293 a\u1d9c := by\n        { rw [inf_sup_left, inf_sup_right, \u2190 sup_assoc, \u2190 inf_assoc, \u2190 inf_assoc] }\n    _ = a \u2293 b \u2293 c \u2294 a \u2293 b\u1d9c \u2293 c\u1d9c \u2294 a\u1d9c \u2293 b \u2293 c\u1d9c \u2294 a\u1d9c \u2293 b\u1d9c \u2293 c := (by\n      congr 1\n      \u00b7 congr 1\n        rw [inf_comm, inf_assoc]\n      \u00b7 apply inf_left_right_swap)\n#align symm_diff_symm_diff_right' symmDiff_symmDiff_right'\n\nvariable {a b c}\n\ntheorem Disjoint.le_symmDiff_sup_symmDiff_left (h : Disjoint a b) : c \u2264 a \u2206 c \u2294 b \u2206 c := by\n  trans c \\ (a \u2293 b)\n  \u00b7 rw [h.eq_bot, sdiff_bot]\n  \u00b7 rw [sdiff_inf]\n    exact sup_le_sup le_sup_right le_sup_right\n#align disjoint.le_symm_diff_sup_symm_diff_left Disjoint.le_symmDiff_sup_symmDiff_left\n\ntheorem Disjoint.le_symmDiff_sup_symmDiff_right (h : Disjoint b c) : a \u2264 a \u2206 b \u2294 a \u2206 c := by\n  simp_rw [symmDiff_comm a]\n  exact h.le_symmDiff_sup_symmDiff_left\n#align disjoint.le_symm_diff_sup_symm_diff_right Disjoint.le_symmDiff_sup_symmDiff_right\n\ntheorem Codisjoint.bihimp_inf_bihimp_le_left (h : Codisjoint a b) : a \u21d4 c \u2293 b \u21d4 c \u2264 c :=\n  h.dual.le_symmDiff_sup_symmDiff_left\n#align codisjoint.bihimp_inf_bihimp_le_left Codisjoint.bihimp_inf_bihimp_le_left\n\ntheorem Codisjoint.bihimp_inf_bihimp_le_right (h : Codisjoint b c) : a \u21d4 b \u2293 a \u21d4 c \u2264 a :=\n  h.dual.le_symmDiff_sup_symmDiff_right\n#align codisjoint.bihimp_inf_bihimp_le_right Codisjoint.bihimp_inf_bihimp_le_right\n\nend BooleanAlgebra\n\n/-! ### Prod -/\n\n\nsection Prod\n\n@[simp]\ntheorem symmDiff_fst [GeneralizedCoheytingAlgebra \u03b1] [GeneralizedCoheytingAlgebra \u03b2]\n    (a b : \u03b1 \u00d7 \u03b2) : (a \u2206 b).1 = a.1 \u2206 b.1 :=\n  rfl\n#align symm_diff_fst symmDiff_fst\n\n@[simp]\ntheorem symmDiff_snd [GeneralizedCoheytingAlgebra \u03b1] [GeneralizedCoheytingAlgebra \u03b2]\n    (a b : \u03b1 \u00d7 \u03b2) : (a \u2206 b).2 = a.2 \u2206 b.2 :=\n  rfl\n#align symm_diff_snd symmDiff_snd\n\n@[simp]\ntheorem bihimp_fst [GeneralizedHeytingAlgebra \u03b1] [GeneralizedHeytingAlgebra \u03b2] (a b : \u03b1 \u00d7 \u03b2) :\n    (a \u21d4 b).1 = a.1 \u21d4 b.1 :=\n  rfl\n#align bihimp_fst bihimp_fst\n\n@[simp]\ntheorem bihimp_snd [GeneralizedHeytingAlgebra \u03b1] [GeneralizedHeytingAlgebra \u03b2] (a b : \u03b1 \u00d7 \u03b2) :\n    (a \u21d4 b).2 = a.2 \u21d4 b.2 :=\n  rfl\n#align bihimp_snd bihimp_snd\n\nend Prod\n\n/-! ### Pi -/\n\n\nnamespace Pi\n\ntheorem symmDiff_def [\u2200 i, GeneralizedCoheytingAlgebra (\u03c0 i)] (a b : \u2200 i, \u03c0 i) :\n    a \u2206 b = fun i => a i \u2206 b i :=\n  rfl\n#align pi.symm_diff_def Pi.symmDiff_def\n\ntheorem bihimp_def [\u2200 i, GeneralizedHeytingAlgebra (\u03c0 i)] (a b : \u2200 i, \u03c0 i) :\n    a \u21d4 b = fun i => a i \u21d4 b i :=\n  rfl\n#align pi.bihimp_def Pi.bihimp_def\n\n@[simp]\ntheorem symmDiff_apply [\u2200 i, GeneralizedCoheytingAlgebra (\u03c0 i)] (a b : \u2200 i, \u03c0 i) (i : \u03b9) :\n    (a \u2206 b) i = a i \u2206 b i :=\n  rfl\n#align pi.symm_diff_apply Pi.symmDiff_apply\n\n@[simp]\ntheorem bihimp_apply [\u2200 i, GeneralizedHeytingAlgebra (\u03c0 i)] (a b : \u2200 i, \u03c0 i) (i : \u03b9) :\n    (a \u21d4 b) i = a i \u21d4 b i :=\n  rfl\n#align pi.bihimp_apply Pi.bihimp_apply\n\nend Pi\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/SymmDiff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7147992667975959}}
{"text": "import tactic\nimport data.nat.prime\nimport data.nat.parity\nimport algebra.divisibility\nimport algebra.big_operators\nimport data.set.finite\nimport number_theory.bernoulli\nimport data.finset\nimport data.finset.basic\nimport data.nat.basic\nimport data.finset.nat_antidiagonal\n\nimport ring_theory.power_series.basic\n\nopen power_series\n\ntheorem expand_tonelli (n:\u2115):\n(finset.range n).sum(\u03bb k, power_series.mk (\u03bb n, (k:\u211a)^n / n.factorial)) =\npower_series.mk (\u03bb p, (finset.range n).sum(\u03bb k, k^p)/p.factorial) :=\nbegin\n  induction n with n h,\n  { simp only [zero_div, finset.sum_empty, finset.range_zero],\n  refl },\n  rw [finset.sum_range_succ, h],\n  ext,\n  simp only [coeff_mk, linear_map.map_add],\n  rw [finset.sum_range_succ, add_div],\nend\n\ndef expk (k:\u2115) : power_series \u211a := power_series.mk (\u03bb n, (k:\u211a)^n / n.factorial)\n\nlemma expkrw (k:\u2115 ): (expk k) = power_series.mk (\u03bb n, (k:\u211a)^n / n.factorial)\n  := by refl\n\n\n-- some version of this might be useful to have in mathlib?!\nlemma expk' (k:\u2115): (exp \u211a)^k = expk k :=\nbegin\n  induction k with k h,\n  {rw [expk],\n  ext,\n  simp only [coeff_mk, coeff_one, nat.nat_zero_eq_zero, nat.factorial,\n  nat.cast_zero, pow_zero],\n  split_ifs,\n  { simp [h] },\n  { simp [h] } },\n  simp only [pow_succ, h],\n  ext,\n  rw [coeff_mul],\n  simp only [expk, exp, one_div, coeff_mk, nat.factorial, ring_hom.id_apply,\n  nat.cast_succ, rat.algebra_map_rat_rat],\n  have hf: (n.factorial:\u211a) \u2260 0 := by simp only [n.factorial_ne_zero, ne.def,\n  nat.cast_eq_zero, not_false_iff],\n  rw [mul_mul_div ((finset.nat.antidiagonal n).sum\n  (\u03bb (x : \u2115 \u00d7 \u2115), (\u2191(x.fst.factorial))\u207b\u00b9 *\n  (\u2191k ^ x.snd / \u2191(x.snd.factorial)))) hf],\n  rw [\u2190div_eq_mul_one_div, div_left_inj' hf],\n  let  f: \u2115 \u2192  \u2115 \u2192 \u211a := \u03bb a : \u2115, \u03bb b : \u2115,\n  ((\u2191(a.factorial))\u207b\u00b9 * (\u2191k ^ b / \u2191(b.factorial))),\n  simp only [finset.nat.sum_antidiagonal_eq_sum_range_succ f],\n  have hfab: \u2200 (a b:\u2115), f a b =\n  ((\u2191(a.factorial))\u207b\u00b9 * (\u2191k ^ b / \u2191(b.factorial))) :=\n  begin\n    intros,\n    refl,\n  end,\n  rw [add_comm \u2191k, add_pow, finset.sum_mul],\n  have hsucc: n.succ = n + 1 := by refl,\n  simp only [\u2190hsucc],\n  refine finset.sum_congr rfl _,\n  intros m hm,\n  rw [hfab],\n  rw [finset.mem_range] at hm,\n  have hnmn: n - m \u2264 n :=\n  begin\n    apply nat.sub_le_left_of_le_add,\n    apply nat.le_add_left,\n  end,\n  have hnm: m \u2264 n := nat.le_of_lt_succ hm,\n  rw [\u2190nat.choose_symm hnm, nat.choose_eq_factorial_div_factorial hnmn],\n  have hnnm: n - (n - m) = m := nat.sub_sub_self hnm,\n  rw [hnnm],\n  simp only [one_pow, one_mul],\n  rw [mul_comm  ((m.factorial):\u211a)\u207b\u00b9],\n  simp only [nat.factorial_mul_factorial_dvd_factorial hnm],\n  rw \u2190 division_def,\n  rw div_div_eq_div_mul,\n  rw mul_comm,\n  have hfacprod:  \u2191(m.factorial * (n - m).factorial) \u2260  0 :=\n  begin\n    have hmfacnezero: m.factorial \u2260 0:= ne_of_gt m.factorial_pos,\n    have hnmfacnezero: (n-m).factorial \u2260 0 :=\n    begin\n      have hk: \u2203 k, k = n - m:= by simp only [exists_apply_eq_apply],\n      refine ne_of_gt _,\n      cases hk with k hk,\n      have hkfac: k.factorial >0 :=  k.factorial_pos,\n      rw hk at hkfac,\n      exact hkfac,\n    end,\n    have hnn: m.factorial * (n - m).factorial \u2260 0 := mul_ne_zero hmfacnezero hnmfacnezero,\n    simp [hnn],\n  end,\n  rw [nat.cast_dvd, nat.cast_mul],\n  simp only [\u2190 mul_div_assoc, mul_comm],\n  rw mul_comm,\n  exact nat.factorial_mul_factorial_dvd_factorial hnm,\n  simp only [ne.def, nat.cast_eq_zero, mul_eq_zero],\n  simp only [nat.factorial_ne_zero, not_false_iff, or_self],\nend\n\nlemma expk_minus_one_coeff (n m:\u2115): (coeff \u211a m) ((expk n) - 1) =\n( if (m > 0) then ((coeff \u211a m) (expk n)) else (((coeff \u211a 0) (expk n) - 1) ) ):=\nbegin\n  split_ifs with h h,\n  { simp only [coeff_one, linear_map.map_sub],\n  have hnm: \u00ac(m = 0) := by apply ne_of_gt h,\n  simp only [hnm, sub_zero, if_false] },\n  simp only [coeff_one, coeff_zero_eq_constant_coeff, linear_map.map_sub],\n  have hm: m = 0 := by linarith,\n  rw [hm],\n  simp only [if_true, eq_self_iff_true, coeff_zero_eq_constant_coeff],\nend\n\nlemma minus_one_minus_expk (n:\u2115): (1 - expk n) = - ((expk n) - 1) := by ring\n\ntheorem sum_geo_seq (n:\u2115) (\u03c6 : (power_series \u211a)):\n((finset.range n).sum(\u03bb k, \u03c6^k) * (\u03c6 - 1)) = ((\u03c6^n) - 1) :=\nbegin\n  induction n with n h,\n  { simp only [finset.sum_empty, zero_mul, finset.range_zero, pow_zero, sub_self] },\n  simp only [finset.sum_range_succ, pow_succ', add_mul ,h],\n  ring,\nend\n\ntheorem special_sum_inf_geo_seq (n:\u2115):\n (exp \u211a - 1) * (finset.range n).sum(\u03bb k, expk k) = ((expk n) - 1) :=\nbegin\n  have hone: ((finset.range n).sum(\u03bb k, (exp \u211a)^k) * ((exp \u211a) - 1)) =\n  (((exp \u211a)^n) - 1) := sum_geo_seq n ((exp \u211a)),\n  simp only [expk', mul_comm] at *,\n  exact hone,\nend\n\ntheorem expand_fraction (n:\u2115):\n(1 - expk n) * X * (exp \u211a - 1)  = (1 - exp \u211a) * (expk n - 1) * X := by ring\n\ntheorem right_series (n:\u2115):\n(expk n - 1) = X*power_series.mk (\u03bb p, n^p.succ/(p.succ.factorial)) :=\nbegin\n  ext,\n  rw [power_series.coeff_mul],\n  rw [expk_minus_one_coeff],\n  split_ifs with h_ge_zero h_zero,\n  rw [expk],\n  rw [power_series.coeff_mk],\n  simp only [coeff_X, coeff_mk, nat.factorial, boole_mul, nat.cast_succ,\n  nat.factorial_succ, nat.cast_mul],\n  have hnsucc: \u2203 (m:\u2115), m.succ = n_1 :=\n  begin\n    use n_1 - 1,\n    exact nat.succ_pred_eq_of_pos h_ge_zero,\n  end,\n  cases hnsucc with m hm,\n  rw [\u2190hm],\n  rw [finset.nat.sum_antidiagonal_succ],\n  simp only [add_left_eq_self, nat.factorial, nat.cast_succ,\n  nat.factorial_succ, if_false, nat.cast_add, zero_add, nat.cast_one,\n  nat.cast_mul, zero_ne_one],\n  by_cases hmz: m = 0,\n  rw [hmz, finset.nat.antidiagonal_zero],\n  simp,\n  have hmsucc: \u2203 (p:\u2115), p.succ = m :=\n  begin\n    have h_ge_zero: m > 0 :=\n    begin\n      exact nat.pos_of_ne_zero hmz,\n    end,\n    use m - 1,\n    exact nat.succ_pred_eq_of_pos h_ge_zero,\n  end,\n  cases hmsucc with p hp,\n  rw [\u2190hp, finset.nat.sum_antidiagonal_succ],\n  by_cases hpz: p = 0,\n  rw [hpz],\n  simp only [add_zero, if_true, eq_self_iff_true, add_eq_zero_iff,\n  if_false, one_ne_zero, finset.sum_const_zero, and_false],\n  simp only [add_zero, if_true, eq_self_iff_true, nat.cast_succ,\n  add_eq_zero_iff, if_false, one_ne_zero, finset.sum_const_zero,\n  and_false],\n  have hn_1: n_1 = 0 := by linarith,\n  rw [expk],\n  simp only [hn_1],\n  rw [power_series.coeff_mk],\n  simp,\nend\n\nlemma minus_X_fw (\u03c6 \u03c8: power_series \u211a):\n(\u03c6 = \u03c8) \u2192  (\n  mk(\u03bb n, (-1)^n*(coeff \u211a n) \u03c6) =\n  mk(\u03bb n, (-1)^n*(coeff \u211a n) \u03c8)) :=\nbegin\n  rintro rfl,\n  refl,\nend\n\nlemma minus_X (\u03c6 \u03c8: power_series \u211a):\n(\u03c6 = \u03c8) \u2194  (\n  mk(\u03bb n, (-1:\u211a)^n*(coeff \u211a n) \u03c6) =\n  mk(\u03bb n, (-1)^n*(coeff \u211a n) \u03c8)) :=\nbegin\n  split,\n  { exact minus_X_fw \u03c6 \u03c8 },\n  intro h,\n  have g: mk(\u03bb n,\n  (-1:\u211a)^n*(coeff \u211a n) (mk(\u03bb n, (-1)^n*(coeff \u211a n) \u03c6))) =\n  mk(\u03bb n,\n  (-1)^n*(coeff \u211a n) (mk(\u03bb n, (-1)^n*(coeff \u211a n) \u03c8))) := (minus_X_fw (mk(\u03bb n, (-1)^n*(coeff \u211a n) \u03c6))\n  (mk(\u03bb n, (-1)^n*(coeff \u211a n) \u03c8))) h,\n  simp only [coeff_mk] at g,\n  simp only [power_series.ext_iff] at g,\n  simp only [or_self_right, coeff_mk, mul_eq_mul_left_iff] at g,\n  have hpn: \u2200 n:\u2115, ((-1:\u211a)^n) \u2260 0 :=\n  begin\n    intro n,\n    apply pow_ne_zero,\n    rw [ne.def, neg_eq_zero],\n    exact one_ne_zero,\n  end,\n  simp only [hpn, or_false] at g,\n  exact power_series.ext_iff.mpr g,\n end\n\n lemma minus_X_mul (\u03c6 \u03c8: power_series \u211a):\n (mk(\u03bb n, (-1:\u211a)^n*(coeff \u211a n) \u03c6) * mk(\u03bb n, (-1:\u211a)^n*(coeff \u211a n) \u03c8)) =\n mk(\u03bb n, (-1:\u211a)^n*(coeff \u211a n) (\u03c6*\u03c8)) :=\n (ring_hom.map_mul (rescale (-1 : \u211a)) \u03c6 \u03c8).symm\n\n\n-- useful to have in mathlib?\nlemma exp_inv:  (exp \u211a) * mk (\u03bb (n : \u2115), (-1) ^ n * (coeff \u211a n) (exp \u211a))  = 1 :=\nbegin\n  ext,\n  rw [coeff_mul],\n  simp only [one_div, coeff_mk, coeff_one, nat.factorial,\n  coeff_exp, ring_hom.id_apply, rat.algebra_map_rat_rat],\n  have zero_pow_ite_fac: 0^n/((n.factorial:\u211a)) =(ite(n=0) (1:\u211a) 0):=\n  begin\n    induction n with n hn,\n    simp only [mul_one, nat.factorial_zero, if_true, eq_self_iff_true,\n    nat.factorial_one, nat.cast_one, pow_zero],\n    simp only [div_one],\n    have hnsucc_zero: \u00ac n.succ = 0 := nat.succ_ne_zero n,\n    simp only [hnsucc_zero, if_false],\n    have hsuccfac: n.succ.factorial \u2260  0 := ne_of_gt (nat.factorial_pos _),\n    simp only [nat.succ_pos', div_eq_zero_iff, true_or, zero_pow_eq_zero],\n  end,\n  rw [\u2190zero_pow_ite_fac],\n  have one_minus_one_eq_zero: 1 + (-1) = (0:\u211a) :=\n  begin\n    simp only [add_right_neg],\n  end,\n  rw [\u2190one_minus_one_eq_zero],\n  rw [add_pow],\n  let f:\u2115 \u2192 \u2115 \u2192 \u211a := \u03bb a : \u2115, \u03bb b : \u2115,\n  (((a.factorial))\u207b\u00b9 * ((-1) ^ b * ((b.factorial))\u207b\u00b9)),\n  rw [finset.nat.sum_antidiagonal_eq_sum_range_succ f],\n  have hfacnezero: (n.factorial:\u211a)  \u2260 0 := by exact_mod_cast n.factorial_ne_zero,\n  symmetry,\n  rw [div_eq_iff hfacnezero],\n  rw [finset.sum_mul],\n  have hsucc: n.succ = n + 1 := by refl,\n  simp only [\u2190hsucc],\n  refine finset.sum_congr rfl _,\n  intro m,\n  intro hm,\n  simp only [f],\n  have hmn: m \u2264 n :=\n  begin\n     rw [finset.mem_range] at hm,\n     exact nat.le_of_lt_succ hm,\n  end,\n  simp only [nat.choose_eq_factorial_div_factorial hmn],\n  simp only [one_pow, one_mul],\n  rw \u2190 mul_assoc,\n  simp only,\n  ring,\n  simp only [mul_eq_mul_right_iff],\n  left,\n  have hfacprod:  \u2191(m.factorial * (n - m).factorial) \u2260  0 :=\n  begin\n    have hmfacnezero: m.factorial \u2260 0:= ne_of_gt m.factorial_pos,\n    have hnmfacnezero: (n-m).factorial \u2260 0 :=\n    begin\n      have hk: \u2203 k, k = n - m:=\n      begin\n        simp only [exists_apply_eq_apply],\n      end,\n      refine ne_of_gt _,\n      cases hk with k hk,\n      have hkfac: k.factorial >0 :=  k.factorial_pos,\n      rw hk at hkfac,\n      exact hkfac,\n    end,\n    have hnn: m.factorial * (n - m).factorial \u2260 0\n    := mul_ne_zero hmfacnezero hnmfacnezero,\n    simp [hnn],\n  end,\n  rw nat.cast_dvd,\n  simp only [nat.cast_mul],\n  rw \u2190division_def,\n  rw \u2190division_def,\n  rw div_div_eq_div_mul,\n  simp only [mul_comm],\n  exact nat.factorial_mul_factorial_dvd_factorial hmn,\n  simp only [ne.def, nat.cast_eq_zero, mul_eq_zero],\n  simp only [nat.factorial_ne_zero, not_false_iff, or_self],\nend\n\nlemma expmxm1: mk (\u03bb (n : \u2115), (-1:\u211a) ^ n * (coeff \u211a n) (exp \u211a - 1)) =\n (1 - exp \u211a)* mk (\u03bb (n : \u2115), (-1) ^ n * (coeff \u211a n) (exp \u211a)) :=\n begin\n   simp only [sub_mul, exp_inv],\n   ext,\n   simp only [one_div, coeff_mk, coeff_one, one_mul, coeff_exp,\n   ring_hom.id_apply, linear_map.map_sub, rat.algebra_map_rat_rat],\n   cases n,\n   simp only [mul_one, nat.factorial_zero, if_true, eq_self_iff_true,\n   nat.factorial_one, inv_one, nat.cast_one, mul_zero, pow_zero, sub_self],\n   simp only [n.succ_ne_zero, sub_zero, if_false],\n end\n\nvariables {R : Type*} [ring R]\n\n@[simp] lemma neg_one_pow_succ_succ {m : \u2115} : (-1 : R)^m.succ.succ = (-1)^m :=\nbegin\n  change _ ^ (m + 2) = _,\n  simp [pow_add],\nend\n\n@[simp] lemma neg_one_pow_succ_of_odd {m : \u2115}: (-1 : R) ^ (m + 1) = -(-1)^m :=\nby simp [pow_add]\n\n#check @power_series.coeff_zero_mul_X\n#check @power_series.coeff_zero_X_mul\n\n\nlemma power_series.coeff_zero_X_mul (\u03c6 : power_series R) : coeff R 0 (\u03c6 * X) = 0\n:= by simp\n\nlemma aux_exp2: mk (\u03bb (n : \u2115), (-1:\u211a) ^ n * (coeff \u211a n) (X * exp \u211a)) =\n(-X)*mk (\u03bb (n : \u2115), (-1) ^ n * (coeff \u211a n) (exp \u211a)) :=\nbegin\n  ext n,\n  cases n,\n  { simp only [\u2190neg_mul_eq_neg_mul, power_series.coeff_zero_X_mul, coeff_mk,\n      linear_map.map_neg, mul_zero, neg_zero],\n    simp only [zero_mul, constant_coeff_X, coeff_zero_eq_constant_coeff,\n    mul_zero, ring_hom.map_mul, neg_zero], },\n  rw [mul_comm X, \u2190neg_mul_eq_neg_mul, mul_comm X, linear_map.map_neg],\n  simp only [coeff_succ_mul_X, neg_mul_eq_neg_mul_symm, neg_one_pow_succ_of_odd, coeff_mk],\nend\n\n-- useful to have in mathlib?\ntheorem bernoulli_power_series':\n  (exp \u211a - 1) * power_series.mk (\u03bb n,\n  ((-1)^n * bernoulli n / nat.factorial n : \u211a)) = X :=\nbegin\n  have h: power_series.mk (\u03bb n, (bernoulli n / nat.factorial n : \u211a)) * (exp \u211a - 1)\n  = X * exp \u211a :=\n  begin\n    simp only [bernoulli_power_series],\n  end,\n  rw [minus_X, \u2190minus_X_mul, expmxm1, aux_exp2] at h,\n  let f1 := mk (\u03bb (n : \u2115), (-1:\u211a) ^ n * (coeff \u211a n) (mk (\u03bb (n : \u2115), bernoulli n / \u2191(n.factorial)))),\n  let f2 := 1 - exp \u211a,\n  have hf2 : f2 = 1 - exp \u211a := by refl,\n  let f3 := mk (\u03bb (n : \u2115), (-1) ^ n * (coeff \u211a n) (exp \u211a)),\n  rw [\u2190(mul_assoc f1 f2 f3)] at h,\n  have hf3: f3 = mk (\u03bb (n : \u2115), (-1) ^ n * (coeff \u211a n) (exp \u211a)) := by refl,\n  rw [\u2190hf3] at h,\n  have hf3_nonzero: f3 \u2260 0 :=\n  begin\n    rw [hf3],\n    simp [power_series.ext_iff],\n    use 1,\n    simp,\n  end,\n  have g: f1*f2 = -X :=\n  begin\n    apply mul_right_cancel' hf3_nonzero h,\n  end,\n  have hf1: f1 = mk (\u03bb (n : \u2115), (-1:\u211a) ^ n * (coeff \u211a n) (mk (\u03bb (n : \u2115), bernoulli n / \u2191(n.factorial)))) := by refl,\n  simp only [coeff_mk] at hf1,\n  have hf1': f1 = mk (\u03bb (n : \u2115), (-1) ^ n * bernoulli n / \u2191(n.factorial)) :=\n  begin\n    simp only [hf1],\n    simp only [ext_iff, coeff_mk],\n    intro n,\n    rw [mul_div_assoc],\n  end,\n  rw [\u2190hf1'],\n  have hf2':  - f2 = (exp \u211a - 1) :=\n  begin\n    rw [hf2],\n    ring,\n  end,\n  rw [\u2190hf2', \u2190neg_one_mul, mul_assoc, mul_comm f2, g],\n  simp only [neg_mul_eq_neg_mul_symm, one_mul, neg_neg],\nend\n\ntheorem cauchy_prod (n:\u2115):\npower_series.mk (\u03bb n,\n  ((-1)^n* bernoulli n / nat.factorial n : \u211a))*\n  power_series.mk (\u03bb p, (n:\u211a)^p.succ/(p.succ.factorial))  =\n power_series.mk (\u03bbp,\n ((finset.range p.succ).sum(\u03bb i,\n (-1)^i*(bernoulli i)*(p.succ.choose i)*n^(p + 1 - i)/((p.factorial)*(p + 1))))) :=\nbegin\n  ext q,\n  rw [power_series.coeff_mul],\n  simp only [coeff_mk, coeff_mk, nat.factorial, nat.cast_succ,\n  nat.factorial_succ, nat.cast_mul],\n  let f: \u2115 \u2192  \u2115 \u2192 \u211a := \u03bb (a : \u2115), \u03bb (b: \u2115),\n  (-1) ^ a * bernoulli a / \u2191(a.factorial) *\n    (\u2191n ^ b.succ / ((\u2191(b) + 1) * \u2191(b.factorial))),\n  rw [finset.nat.sum_antidiagonal_eq_sum_range_succ f],\n  have h: \u2200 k:\u2115, (k \u2208 (finset.range q.succ)) \u2192\n   (f k (q - k) = (-1) ^ k * bernoulli k * \u2191(q.succ.choose k) *\n  \u2191n ^ (q + 1 - k) / (\u2191(q.factorial) * (\u2191q + 1)) ):=\n  begin\n    simp only [finset.mem_range],\n    intros k g,\n    simp [f],\n    ring,\n    have hfac:\n    ((\u2191(q - k) + 1) * \u2191((q - k).factorial))\u207b\u00b9 * \u2191n ^ (q - k).succ * (\u2191(k.factorial))\u207b\u00b9 =\n  (\u2191(q.factorial) * (\u2191q + (1:\u211a )))\u207b\u00b9 * \u2191n ^ (q + 1 - k) * \u2191(q.succ.choose k):=\n    begin\n      have exp_succ: (q - k).succ = (q + 1 - k) := by omega,\n      rw [exp_succ],\n      have h_choose: (q.succ.choose k) =\n      ((q + 1).factorial)/((k.factorial)*(q + 1 - k).factorial) :=\n      begin\n        rw nat.choose_eq_factorial_div_factorial,\n        exact le_of_lt g,\n      end,\n      rw [h_choose],\n      have h_exp_fac2: (q + 1 - k).factorial\n        =((((q - k)).factorial)*(q - k +1)) :=\n        begin\n          have hqk1: q -k + 1 = (q - k).succ := by refl,\n          rw [hqk1, nat.mul_comm, \u2190nat.factorial_succ],\n          have hq1: q + 1 - k = (q - k).succ := eq.symm exp_succ,\n          rw [hq1],\n        end,\n      rw [h_exp_fac2, mul_comm \u2191(q.factorial)],\n      have hqqsucc: (q:\u211a) + 1 = q.succ := by rw [\u2190nat.cast_succ],\n      have hqqsucc': (q:\u2115) + 1 = q.succ := by simp,\n      simp only [hqqsucc],\n      have hcoeq: ((q.succ):\u211a) * ((q.factorial):\u211a) =(((q.succ.factorial:\u2115)):\u211a) := by norm_cast,\n      rw [hcoeq, mul_comm (\u2191(q.succ.factorial))\u207b\u00b9 , mul_assoc ((n:\u211a) ^ (q + 1 - k))],\n      simp only [div_eq_mul_inv],\n      rw [hqqsucc'],\n      have hqsuccnezero: q.succ \u2260 0 := by contradiction,\n      rw [mul_assoc, inv_eq_one_div \u2191(q.succ.factorial),  \u2190 division_def, div_eq_mul_one_div],\n      have hfacprod:  \u2191(k.factorial * (q + 1 - k).factorial) \u2260  0 :=\n      begin\n        have hmfacnezero: k.factorial \u2260 0:= ne_of_gt k.factorial_pos,\n        have hnmfacnezero: (q + 1 - k).factorial \u2260 0 :=\n          begin\n           have hm: \u2203 m, m = q + 1 - k:=\n            begin\n              simp only [exists_apply_eq_apply],\n           end,\n          refine ne_of_gt _,\n          cases hm with m hm,\n          have hmfac: m.factorial >0 :=  m.factorial_pos,\n          rw hm at hmfac,\n          exact hmfac,\n        end,\n        have hnn: k.factorial * (q + 1 - k).factorial \u2260 0 := mul_ne_zero hmfacnezero hnmfacnezero,\n        simp only [hnn, nat.cast_id, ne.def, not_false_iff],\n      end,\n      rw [\u2190h_exp_fac2, nat.cast_dvd],\n      simp only [\u2190 mul_div_assoc],\n      rw [one_div_mul_cancel, \u2190nat.cast_add_one, \u2190nat.cast_mul,\n      mul_comm (q - k + 1) _, \u2190 h_exp_fac2, mul_comm, \u2190 division_def,\n      div_div_eq_div_mul, nat.cast_mul, mul_comm (\u2191(k.factorial)) _],\n      simp,\n      rw not_or_distrib,\n      split,\n      refine ne.elim _,\n      exact nat.cast_add_one_ne_zero q,\n      refine ne.elim _,\n      exact nat.factorial_ne_zero q,\n      rw hqqsucc',\n      exact nat.factorial_mul_factorial_dvd_factorial (nat.le_of_lt g),\n      simp only [ne.def, nat.cast_eq_zero, mul_eq_zero],\n      simp only [nat.factorial_ne_zero, not_false_iff, or_self],\n      end,\n    rw [hfac],\n  end,\n  refine finset.sum_congr rfl _,\n  exact h,\nend\n\ntheorem power_series_equal (n:\u2115):\n(power_series.mk (\u03bb p, (finset.range n).sum(\u03bbk, (k:\u211a)^p)/(p.factorial))) =\n (power_series.mk (\u03bb p,((finset.range p.succ).sum(\u03bb i,\n (-1)^i*(bernoulli i)*(p.succ.choose i)*n^(p + 1 - i)/((p.factorial)*(p + 1)))))) :=\n begin\n   let left := (power_series.mk (\u03bb p, (finset.range n).sum(\u03bbk, (k:\u211a)^p)/(p.factorial))) ,\n   have hleft: left =(power_series.mk (\u03bb p, (finset.range n).sum(\u03bbk, (k:\u211a)^p)/(p.factorial))) := by refl,\n   let right := (power_series.mk (\u03bb p,((finset.range p.succ).sum(\u03bb i,\n (-1)^i*(bernoulli i)*(p.succ.choose i)*n^(p + 1 - i)/((p.factorial)*(p + 1)))))),\n   have hright: right =(power_series.mk (\u03bb p,((finset.range p.succ).sum(\u03bb i,\n (-1)^i*(bernoulli i)*(p.succ.choose i)*n^(p + 1 - i)/((p.factorial)*(p + 1)))))) := by refl,\n  have h: (exp \u211a - 1)*left = (exp \u211a - 1)*right :=\n  begin\n   rw [hleft, \u2190expand_tonelli],\n   have hfin: (finset.range n).sum (\u03bb (k : \u2115),\n   mk (\u03bb (n : \u2115), (k:\u211a) ^ n / \u2191(n.factorial))) =\n   (finset.range n).sum(\u03bb k, expk k) :=\n   begin\n     simp only [expkrw],\n   end,\n   rw [hfin, special_sum_inf_geo_seq, right_series, \u2190bernoulli_power_series',\n   mul_assoc, cauchy_prod],\n  end,\n  have hexpnezero: (exp \u211a - 1) \u2260 0 :=\n  begin\n    rw [exp],\n    simp only [ext_iff, linear_map.map_zero, one_div, coeff_mk, coeff_one,\n    ring_hom.id_apply, linear_map.map_sub, ne.def, not_forall,\n    rat.algebra_map_rat_rat],\n    use 1,\n    simp only [nat.factorial_one, sub_zero, if_false, inv_one, not_false_iff,\n    one_ne_zero, nat.cast_one],\n  end,\n  apply mul_left_cancel' hexpnezero h,\n end\n\ntheorem faulhaber_long' (n: \u2115): \u2200p,\n(coeff \u211a p) (power_series.mk (\u03bb p, (finset.range n).sum(\u03bbk, (k:\u211a)^p)/(p.factorial))) =\n (coeff \u211a p) (power_series.mk (\u03bbp,\n ((finset.range p.succ).sum(\u03bb i, (-1)^i*(bernoulli i)*\n (p.succ.choose i)*n^(p + 1 - i)/((p.factorial)*(p + 1))))))  :=\n begin\n   exact power_series.ext_iff.mp (power_series_equal n),\n end\n\ntheorem faulhaber' (n p:\u2115):\n(finset.range n).sum(\u03bbk, (k:\u211a)^p) =\n((finset.range p.succ).sum(\u03bb i,\n (-1)^i*(bernoulli i)*(p.succ.choose i)*n^(p + 1 - i)/p.succ)) :=\nbegin\n have hfaulhaber_long': (coeff \u211a p) (power_series.mk (\u03bb p, (finset.range n).sum(\u03bbk, (k:\u211a)^p)/(p.factorial))) =\n (coeff \u211a p) (power_series.mk (\u03bbp,\n ((finset.range p.succ).sum(\u03bb i, (-1)^i*(bernoulli i)*\n (p.succ.choose i)*n^(p + 1 - i)/((p.factorial)*(p + 1)) )))) := faulhaber_long' n p,\n simp only [power_series.coeff_mk] at hfaulhaber_long',\n rw [div_eq_mul_inv, mul_comm ((p.factorial):\u211a ) _] at hfaulhaber_long',\n have hfl: (finset.range n).sum (\u03bb (k : \u2115), \u2191k ^ p) * (\u2191(p.factorial))\u207b\u00b9 =\n  ((finset.range p.succ).sum\n    (\u03bb (i : \u2115), (-1) ^ i * bernoulli i * \u2191(p.succ.choose i) * \u2191n ^ (p + 1 - i))\n    / ((\u2191p + 1) * \u2191(p.factorial))) :=\n    begin\n      simp [hfaulhaber_long'],\n      rw div_eq_mul_one_div,\n      simp only [finset.sum_mul, one_div],\n      refine finset.sum_congr  _ _,\n      refl,\n      intros k hk,\n      rw [div_eq_mul_one_div, one_div],\n    end,\n clear hfaulhaber_long',\n rw [div_mul_eq_div_mul_one_div ] at hfl,\n simp at hfl,\n have hp: (p.factorial) \u2260 0:= nat.factorial_ne_zero p,\n cases hfl,\n simp only [nat.cast_succ],\n rw [hfl, div_eq_mul_one_div],\n simp only [finset.sum_mul, one_div],\n refine finset.sum_congr  _ _,\n refl,\n intro k,\n intro hk,\n rw [div_eq_mul_one_div, one_div],\n by_contradiction,\n exact hp hfl,\nend\n-- useful to have in mathlib?\nlemma bernoulli_fst_snd (n:\u2115): 1 < n \u2192 bernoulli n = (-1)^n * bernoulli n :=\nbegin\n  intro hn,\n  by_cases odd n,\n  rw [bernoulli_odd_eq_zero h hn],\n  simp only [mul_zero],\n  have heven: even n := nat.even_iff_not_odd.mpr h,\n  have heven_power: even n \u2192 (-(1:\u211a))^n = 1 := nat.neg_one_pow_of_even,\n  rw [heven_power heven],\n  simp only [one_mul],\nend\n\nlemma faulhaber (n:\u2115) (p:\u2115) (hp: 0 <p):\n(finset.range n.succ).sum (\u03bb k, \u2191k^p) =\n((finset.range p.succ).sum (\u03bb j, ((bernoulli j)*(nat.choose p.succ j))\n*n^(p + 1 - j)/(p.succ))) :=\nbegin\n  rw [finset.sum_range_succ, faulhaber' n p],\n  have h2: (1:\u2115).succ \u2264 p.succ :=\n  begin\n    apply nat.succ_le_succ,\n    exact nat.one_le_of_lt hp,\n  end,\n  rw [finset.range_eq_Ico],\n  have hsplit:\n  finset.Ico 0 (1:\u2115).succ \u222a finset.Ico (1:\u2115).succ p.succ =\n  finset.Ico 0 p.succ :=\n  finset.Ico.union_consecutive (nat.zero_le (1:\u2115).succ)   h2,\n  have hdisjoint:\n  disjoint (finset.Ico 0 (1:\u2115).succ)  (finset.Ico (1:\u2115).succ p.succ) :=\n  finset.Ico.disjoint_consecutive 0 (1:\u2115).succ p.succ,\n  rw [\u2190hsplit, finset.sum_union hdisjoint, \u2190finset.range_eq_Ico,\n  finset.sum_range_succ],\n  have h_zeroth_summand:\n  (finset.range (1:\u2115)).sum (\u03bb (x : \u2115), (-1) ^ x * bernoulli x *\n  \u2191(p.succ.choose x) * \u2191n ^ (p + 1 - x) / \u2191(p.succ)) =\n  (finset.range 1).sum (\u03bb (x : \u2115), bernoulli x *\n  \u2191(p.succ.choose x) * \u2191n ^ (p + 1 - x) / \u2191(p.succ)) :=\n  begin\n    simp only [one_mul, finset.sum_singleton, finset.range_one, pow_zero],\n  end,\n  have h_fst_summand'':\n  (n:\u211a)^p*(p.succ) + (((-1) ^ 1)  * (bernoulli 1) * (p.succ.choose 1) * n ^(p + 1 - 1)) =\n  ((bernoulli 1) * (p.succ.choose 1) * n ^(p + 1 - 1)) :=\n  begin\n    simp only [neg_mul_eq_neg_mul_symm, one_div, bernoulli_one,\n    neg_one_pow_succ_of_odd, nat.add_succ_sub_one, add_zero, one_mul,\n    nat.choose_one_right, nat.cast_succ, pow_zero],\n    ring,\n  end,\n   have h_fst_summand':\n  ((n:\u211a)^p*(p.succ) + (((-1) ^ 1) * (bernoulli 1) * (p.succ.choose 1) * n ^(p + 1 - 1)))/p.succ =\n  ((bernoulli 1) * (p.succ.choose 1) * n ^(p + 1 - 1))/p.succ :=\n  begin\n    rw [\u2190h_fst_summand''],\n  end,\n   have h_fst_summand:\n  (n:\u211a)^p + (((-1) ^ 1) * (bernoulli 1) * (p.succ.choose 1) * n ^(p + 1 - 1))/p.succ =\n  ((bernoulli 1) * (p.succ.choose 1) * n ^(p + 1 - 1))/p.succ :=\n  begin\n    rw [\u2190h_fst_summand', eq_div_iff_mul_eq],\n    simp only [neg_mul_eq_neg_mul_symm, one_div, bernoulli_one,\n    neg_one_pow_succ_of_odd, nat.add_succ_sub_one, add_zero, one_mul,\n    nat.choose_one_right, nat.cast_succ, pow_zero],\n    rw [add_mul],\n    simp only [add_right_inj],\n    rw [neg_div, neg_mul_eq_neg_mul_symm, mul_assoc],\n    have hpnezero: (p.succ:\u211a)  \u2260 0 :=\n    begin\n      apply ne_of_gt,\n      simp only [gt_iff_lt, nat.cast_succ],\n      exact nat.cast_add_one_pos _,\n    end,\n    simp only [neg_inj],\n    { field_simp, ring },\n    apply ne_of_gt,\n    simp only [gt_iff_lt, nat.cast_succ],\n    exact nat.cast_add_one_pos _,\n  end,\n  have h_large_summands:\n  (finset.Ico (1:\u2115).succ p.succ).sum  (\u03bb (x : \u2115), (-1) ^ x * bernoulli x\n  * \u2191(p.succ.choose x) * \u2191n ^ (p + 1 - x) / \u2191(p.succ)) =\n  (finset.Ico (1:\u2115).succ p.succ).sum  (\u03bb (x : \u2115), bernoulli x\n  * \u2191(p.succ.choose x) * \u2191n ^ (p + 1 - x) / \u2191(p.succ)) :=\n  begin\n    refine finset.sum_congr _ _,\n    refl,\n    intros x hin,\n    have h1x: 1 < x :=\n    begin\n      rw [finset.Ico.mem] at hin,\n      exact_mod_cast hin.1,\n    end,\n    rw [\u2190bernoulli_fst_snd x h1x],\n  end,\n  simp only [\u2190add_assoc, h_zeroth_summand, h_fst_summand, h_large_summands],\n  simp only [\u2190(finset.sum_range_succ (\u03bb (x : \u2115), bernoulli x * \u2191(p.succ.choose x) *\n   \u2191n ^ (p + 1 - x) / \u2191(p.succ)) 1)],\n   rw [finset.range_eq_Ico],\n   have honeone: 1 + 1 = (1:\u2115).succ := rfl,\n   rw [honeone, \u2190finset.sum_union hdisjoint],\nend\n", "meta": {"author": "mo271", "repo": "faulhaber", "sha": "2e39d9cb7bc6fc400a818b2581ee921d41a7871a", "save_path": "github-repos/lean/mo271-faulhaber", "path": "github-repos/lean/mo271-faulhaber/faulhaber-2e39d9cb7bc6fc400a818b2581ee921d41a7871a/src/faulhaber_with_power_series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7147605737725606}}
{"text": "\n\ntheorem Ex004(a b c : Prop):(a \u2192 (b \u2227 c)) \u2192 (a \u2192 b) :=\nassume H1:(a \u2192 (b \u2227 c)),\n  assume H2:a,\n  have A:b \u2227 c, from H1 H2,\n  show b, from and.elim_left A\n\n\n\n", "meta": {"author": "SvenWille", "repo": "LeanLogicExercises", "sha": "2dbc920feadd63bbc50f87e69646c0081db26eba", "save_path": "github-repos/lean/SvenWille-LeanLogicExercises", "path": "github-repos/lean/SvenWille-LeanLogicExercises/LeanLogicExercises-2dbc920feadd63bbc50f87e69646c0081db26eba/src/propLogic/Ex004.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205502, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.7147210112938229}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Johan Commelin\n-/\nimport group_theory.free_abelian_group\n\n/-!\n# Free rings\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe theory of the free ring over a type.\n\n## Main definitions\n\n* `free_ring \u03b1` : the free (not commutative in general) ring over a type.\n* `lift (f : \u03b1 \u2192 R)` : the ring hom `free_ring \u03b1 \u2192+* R` induced by `f`.\n* `map (f : \u03b1 \u2192 \u03b2)` : the ring hom `free_ring \u03b1 \u2192+* free_ring \u03b2` induced by `f`.\n\n## Implementation details\n\n`free_ring \u03b1` is implemented as the free abelian group over the free monoid on `\u03b1`.\n\n## Tags\n\nfree ring\n\n-/\n\nuniverses u v\n\n/-- The free ring over a type `\u03b1`. -/\n@[derive [ring, inhabited]]\ndef free_ring (\u03b1 : Type u) : Type u :=\nfree_abelian_group $ free_monoid \u03b1\n\nnamespace free_ring\n\nvariables {\u03b1 : Type u}\n\n/-- The canonical map from \u03b1 to `free_ring \u03b1`. -/\ndef of (x : \u03b1) : free_ring \u03b1 :=\nfree_abelian_group.of (free_monoid.of x)\n\nlemma of_injective : function.injective (of : \u03b1 \u2192 free_ring \u03b1) :=\nfree_abelian_group.of_injective.comp free_monoid.of_injective\n\n@[elab_as_eliminator] protected lemma induction_on\n  {C : free_ring \u03b1 \u2192 Prop} (z : free_ring \u03b1)\n  (hn1 : C (-1)) (hb : \u2200 b, C (of b))\n  (ha : \u2200 x y, C x \u2192 C y \u2192 C (x + y))\n  (hm : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) : C z :=\nhave hn : \u2200 x, C x \u2192 C (-x), from \u03bb x ih, neg_one_mul x \u25b8 hm _ _ hn1 ih,\nhave h1 : C 1, from neg_neg (1 : free_ring \u03b1) \u25b8 hn _ hn1,\nfree_abelian_group.induction_on z\n  (add_left_neg (1 : free_ring \u03b1) \u25b8 ha _ _ hn1 h1)\n  (\u03bb m, list.rec_on m h1 $ \u03bb a m ih, hm _ _ (hb a) ih)\n  (\u03bb m ih, hn _ ih)\n  ha\n\nsection lift\n\nvariables {R : Type v} [ring R] (f : \u03b1 \u2192 R)\n\n/-- The ring homomorphism `free_ring \u03b1 \u2192+* R` induced from a map `\u03b1 \u2192 R`. -/\ndef lift : (\u03b1 \u2192 R) \u2243 (free_ring \u03b1 \u2192+* R) :=\nfree_monoid.lift.trans free_abelian_group.lift_monoid\n\n@[simp] lemma lift_of (x : \u03b1) : lift f (of x) = f x :=\ncongr_fun (lift.left_inv f) x\n\n@[simp] lemma lift_comp_of (f : free_ring \u03b1 \u2192+* R) : lift (f \u2218 of) = f :=\nlift.right_inv f\n\n@[ext]\nlemma hom_ext \u2983f g : free_ring \u03b1 \u2192+* R\u2984 (h : \u2200 x, f (of x) = g (of x)) :\n  f = g :=\nlift.symm.injective (funext h)\n\nend lift\n\nvariables {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2)\n\n/-- The canonical ring homomorphism `free_ring \u03b1 \u2192+* free_ring \u03b2` generated by a map `\u03b1 \u2192 \u03b2`. -/\ndef map : free_ring \u03b1 \u2192+* free_ring \u03b2 :=\nlift $ of \u2218 f\n\n@[simp]\nlemma map_of (x : \u03b1) : map f (of x) = of (f x) := lift_of _ _\n\nend free_ring\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/free_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467801752451, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7146296911648125}}
{"text": "variable (p q r : Prop)\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\n  \u27e8 \u03bb pq : p \u2227 q => \u27e8pq.2 , pq.1\u27e9\n  , \u03bb qp : q \u2227 p => \u27e8qp.2 , qp.1\u27e9 \u27e9\n\nexample : p \u2228 q \u2194 q \u2228 p :=\n  \u27e8 \u03bb pq : p \u2228 q =>\n    pq.elim\n      (\u03bb x : p => Or.inr x)\n      (\u03bb x : q => Or.inl x)\n  , \u03bb qp : q \u2228 p =>\n    qp.elim\n      (\u03bb x : q => Or.inr x)\n      (\u03bb x : p => Or.inl x) \u27e9\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n  \u27e8 \u03bb x : (p \u2227 q) \u2227 r =>\n    \u27e8x.1.1, \u27e8x.1.2, x.2\u27e9\u27e9\n  , \u03bb x : p \u2227 (q \u2227 r) =>\n    \u27e8\u27e8x.1, x.2.1\u27e9, x.2.2\u27e9 \u27e9\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n  \u27e8 \u03bb pqr : (p \u2228 q) \u2228 r =>\n    pqr.elim\n      (\u03bb pq : p \u2228 q =>\n        pq.elim\n          (\u03bb x : p => Or.inl x)\n          (\u03bb x : q => Or.inr (Or.inl x)))\n      (\u03bb x : r => Or.inr (Or.inr x))\n  , \u03bb pqr : p \u2228 (q \u2228 r) =>\n    pqr.elim\n      (\u03bb x : p => Or.inl (Or.inl x))\n      (\u03bb qr : q \u2228 r =>\n        qr.elim\n          (\u03bb x : q => Or.inl (Or.inr x))\n          (\u03bb x : r => Or.inr x)) \u27e9\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  \u27e8 \u03bb pqr : p \u2227 (q \u2228 r) =>\n    pqr.2.elim\n      (\u03bb y : q =>\n        Or.inl \u27e8pqr.1, y\u27e9 )\n      (\u03bb y : r =>\n        Or.inr \u27e8pqr.1, y\u27e9 )\n  , \u03bb pqpr : (p \u2227 q) \u2228 (p \u2227 r) =>\n    pqpr.elim\n      (\u03bb pq : p \u2227 q =>\n        \u27e8pq.1, Or.inl pq.2\u27e9)\n      (\u03bb pr : p \u2227 r =>\n        \u27e8pr.1, Or.inr pr.2\u27e9)\u27e9\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n  \u27e8 \u03bb pqr : p \u2228 (q \u2227 r) =>\n    pqr.elim\n      (\u03bb x : p =>\n        \u27e8Or.inl x, Or.inl x\u27e9)\n      (\u03bb qr : q \u2227 r =>\n        \u27e8Or.inr qr.1, Or.inr qr.2\u27e9),\n    \u03bb pqpr : (p \u2228 q) \u2227 (p \u2228 r) =>\n      pqpr.1.elim\n        (\u03bb x : p => Or.inl x)\n        (\u03bb x : q =>\n          pqpr.2.elim\n            (\u03bb y : p => Or.inl y)\n            (\u03bb y : r => Or.inr \u27e8x, y\u27e9)) \u27e9\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n  Iff.intro\n    (\u03bb hpqr : p \u2192 q \u2192 r =>\n        \u03bb hpq : p \u2227 q =>\n          hpqr hpq.1 hpq.2)\n    (\u03bb hpqr : (p \u2227 q) \u2192 r =>\n        \u03bb hp : p =>\n          \u03bb hq : q =>\n            hpqr \u27e8hp, hq\u27e9)\n\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\n  \u27e8 \u03bb h : (p \u2228 q) \u2192 r =>\n    \u27e8 \u03bb hp : p =>\n      h (Or.inl hp)\n    , \u03bb hq : q =>\n      h (Or.inr hq) \u27e9\n  , \u03bb h : (p \u2192 r) \u2227 (q \u2192 r) =>\n    \u03bb hpq : p \u2228 q =>\n      hpq.elim h.left h.right\u27e9\n\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n  \u27e8\n    \u03bb h : \u00ac(p \u2228 q) =>\n      \u27e8 \u03bb hp : p => h (Or.inl hp)\n      , \u03bb hq : q => h (Or.inr hq)\u27e9,\n    \u03bb h : \u00acp \u2227 \u00acq =>\n      \u03bb hpq : p \u2228 q =>\n        hpq.elim h.left h.right\n  \u27e9\n\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n  \u03bb h : \u00acp \u2228 \u00acq =>\n    \u03bb hpq : p \u2227 q =>\n      h.elim\n        (\u03bb hnp : \u00acp => hnp hpq.left)\n        (\u03bb hnq : \u00acq => hnq hpq.right)\n\nexample : \u00ac(p \u2227 \u00acp) :=\n  \u03bb h : p \u2227 \u00acp => h.right h.left\n\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n  \u03bb h : p \u2227 \u00acq =>\n    \u03bb npq : p \u2192 q =>\n      h.right (npq h.left)\n\nexample : \u00acp \u2192 (p \u2192 q) :=\n  \u03bb hnp : \u00acp =>\n    \u03bb hp : p =>\n      absurd hp hnp\n\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n  \u03bb h : \u00acp \u2228 q =>\n    \u03bb hp : p =>\n      h.elim\n        (\u03bb hnp : \u00acp => absurd hp hnp)\n        (\u03bb hq : q => hq)\n\nexample : p \u2228 False \u2194 p :=\n  \u27e8\n    \u03bb h : p \u2228 False =>\n      h.elim\n        (\u03bb hp : p => hp)\n        (\u03bb hFalse : False => False.elim hFalse),\n    \u03bb h : p =>\n      Or.inl h\n  \u27e9\n\nexample : p \u2227 False \u2194 False :=\n  \u27e8\n    \u03bb h : p \u2227 False => h.right,\n    \u03bb h : False => \u27e8False.elim h, h\u27e9\n  \u27e9\n\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n  \u03bb h : p \u2192 q =>\n    \u03bb hnq : \u00acq =>\n      \u03bb hp : p =>\n        hnq (h hp)\n\nopen Classical\n\nexample : (p \u2192 q \u2228 r) \u2192 ((p \u2192 q) \u2228 (p \u2192 r)) :=\n  \u03bb h : p \u2192 q \u2228 r =>\n    (em p).elim\n      (\u03bb hp : p =>\n        (h hp).elim\n          (\u03bb hq : q => Or.inl (\u03bb _ : p => hq))\n          (\u03bb hr : r => Or.inr (\u03bb _ : p => hr)))\n      (\u03bb hnp : \u00acp =>\n        Or.inl (\u03bb hp : p => absurd hp hnp))\n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n  \u03bb h : \u00ac(p \u2227 q) =>\n    Or.elim (em p)\n      (\u03bb hp : p =>\n        Or.elim (em q)\n          (\u03bb hq : q => absurd \u27e8hp, hq\u27e9 h )\n          (\u03bb hnq : \u00acq => Or.inr hnq))\n      (\u03bb hnp : \u00acp => Or.inl hnp)\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n  \u03bb h : \u00ac(p \u2192 q) =>\n    Or.elim (em q)\n      (\u03bb hq : q =>\n        absurd (\u03bb _ : p => hq) h)\n      (\u03bb hnq : \u00acq =>\n        Or.elim (em p)\n          (\u03bb hp : p => \u27e8 hp, hnq \u27e9)\n          (\u03bb hnp : \u00acp =>\n            absurd (\u03bb hp : p => absurd hp hnp) h))\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n  \u03bb h : p \u2192 q =>\n    Or.elim (em p)\n      (\u03bb hp : p => Or.inr (h hp))\n      (\u03bb hnp : \u00acp => Or.inl hnp)\n\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n  \u03bb h : \u00acq \u2192 \u00acp =>\n    Or.elim (em p)\n      (\u03bb hp : p =>\n        Or.elim (em q)\n          (\u03bb hq : q =>\n            \u03bb _ : p => hq)\n          (\u03bb hnq : \u00acq => absurd hp (h hnq)))\n      (\u03bb hnp : \u00acp =>\n        \u03bb hp : p => absurd hp hnp)\n\nexample : p \u2228 \u00acp :=\n  em p\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\n  \u03bb h : (p \u2192 q) \u2192 p =>\n    Or.elim (em p)\n      (\u03bb hp : p => hp)\n      (\u03bb hnp : \u00acp =>\n        h (\u03bb hp : p => absurd hp hnp))\n\n-- Prove \u00ac(p \u2194 \u00acp) without using classical logic.\nexample : \u00ac(p \u2194 \u00acp) :=\n  \u03bb \u27e8h1, h2\u27e9 => \n    let hp := h2 (\u03bb hp => (h1 hp) hp)\n    (h1 hp) hp\n     ", "meta": {"author": "aortega0703", "repo": "theorem-proving-in-lean-4-solutions", "sha": "55adab77768bdf9ff4ed49e414bc56ae20d950cb", "save_path": "github-repos/lean/aortega0703-theorem-proving-in-lean-4-solutions", "path": "github-repos/lean/aortega0703-theorem-proving-in-lean-4-solutions/theorem-proving-in-lean-4-solutions-55adab77768bdf9ff4ed49e414bc56ae20d950cb/chapter-3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7146296780460764}}
{"text": "namespace xena\n\ninductive xnat\n| zero : xnat\n| succ (n : xnat) : xnat\n\nopen xnat\n\n--instance : has_zero xnat := \u27e8zero\u27e9\n\ndef add : xnat \u2192 xnat \u2192 xnat\n| m zero := m\n| m (succ n) := succ (add m n)\n\ninstance : has_add xnat := \u27e8add\u27e9\n\nlemma add_zero (n : xnat) : n + zero = n :=\nbegin\n  refl\nend\n\nlemma zero_add (n : xnat) : zero + n = n :=\nbegin\n  induction n with d hd,\n  {\n    refl\n  },\n  {\n    show succ (zero + d) = succ d,\n    rw hd\n  }\nend\n\nlemma add_assoc (a b c : xnat) : (a + b) + c = a + (b + c) :=\nbegin\n  induction c with d hd,\n  { -- (a + b) + zero = a + (b + zero) \n    show (a + b) = a + (b + zero),\n    show a + b = a + b,\n    refl,\n  },\n  { -- (a + b) + succ d = a + (b + succ d)\n    show succ ((a + b) + d) = a + succ (b + d),\n    show succ ((a + b) + d) = succ (a + (b + d)),\n    rw hd,\n  }\nend\n\ndef one := succ zero\ndefinition two := succ one \n\nexample : one + one = two :=\nbegin\nrefl\nend\n\nlemma add_one (n : xnat) : n + one = succ n :=\nbegin\n  refl\nend\n\nlemma one_add (n : xnat) : one + n = succ n :=\nbegin\n  induction n with d hd,\n  {\n    refl\n  },\n  {\n    show succ (one + d) = _,\n    rw hd\n  }\nend\n\n-- trying to prove add_comm immediately fails, because\n-- this is missing:\n\nlemma succ_add (a b : xnat) : succ a + b = succ (a + b) :=\nbegin\n  induction b with d hd,\n  {\n    refl\n  }, \n  {\n    show succ (succ a + d) = _,\n    rw hd,\n    refl\n  }\nend\n\n-- theorem add_succ_equals_succ (a b : xnat) : a + (succ b) = succ (a + b) := sorry\n\nlemma add_comm (a b : xnat) : a + b = b + a :=\nbegin\n  induction b with d hd,\n  {\n    rw zero_add,\n    rw add_zero\n  },\n  {\n    show succ (a + d) = _,\n    rw hd,\n    rw succ_add,\n  }\nend\n\n/-\ntheorem eq_iff_succ_eq_succ (a b : xnat) : succ a = succ b \u2194 a = b :=\nbegin\nsplit,\n  exact succ.inj,\nassume H : a = b,\nrw [H]\nend\n\ntheorem add_cancel_right (a b t : xnat) :  a = b \u2194 a+t = b+t :=\nbegin\nsplit,\nassume H : a = b,\nrw [H],\nassume P : a+t = b+t,\ninduction t with s Qs, \nhave h3: a = a + zero, by exact add_zero a,\nhave h4: b = b+ zero, by exact add_zero b,\nrw [h3, h4], assumption,\nrw [Qs],\nunfold add at P, \nrw [eq_iff_succ_eq_succ] at P,assumption\nend\n\nlemma zero_of_add_eq (a b : \u2115) : a + b = a \u2192 b = 0 :=\nbegin\n  intro h,\n  induction a with a ha,\n    rw zero_add at h, assumption,\n  apply ha,\n  apply succ_inj,\n  rw \u2190h,\n  simp,\nend\n\n\n-/\n\ndef mul : xnat \u2192 xnat \u2192 xnat\n| m zero := zero\n| m (succ n) := mul m n + m\n\ninstance : has_mul xnat := \u27e8mul\u27e9\n-- notation a * b := mul a b\n\nexample : one * one = one := \nbegin\nrefl\nend\n\nlemma mul_zero (m : xnat) : m * zero = zero := rfl\n\nlemma zero_mul (m : xnat) : zero * m = zero :=\nbegin\n  induction m with d hd,\n  {\n    refl\n  },\n  {\n    show zero * d + _ = _,\n    rw hd,\n    refl\n  }\nend\n\nlemma mul_one (m : xnat) : m * one = m :=\nbegin\n  exact zero_add m, -- good exercise: see why this works\nend\n\nlemma one_mul (m : xnat) : one * m = m :=\nbegin\n  induction m with d hd,\n  {\n    refl,\n  },\n  {\n    show one * d + one = _,\n    rw hd,\n    refl\n  }\nend\n\n-- mul_assoc immediately, leads to this:\n-- \u22a2 a * (b * d) + a * b = a * (b * d + b)\n\nlemma mul_add (a b c : xnat) : a * (b + c) = a * b + a * c :=\nbegin\n  induction c with d hd,\n  {\n    refl\n  },\n  {\n    show a * succ (b + d) = _,\n    show a * (b + d) + _ = _,\n    rw hd,\n    apply add_assoc, -- ;-)\n  }\nend\n\nlemma mul_assoc (a b c : xnat) : (a * b) * c = a * (b * c) :=\nbegin\n  induction c with d hd,\n  { \n    refl\n  },\n  {\n    show (a * b) * d + (a * b) = _,\n    rw hd,\n    show _ = a * (b * d + _),\n    rw mul_add\n  }\nend\n\n-- mul_comm leads to \u22a2 a * d + a = succ d * a\n-- so perhaps we need add_mul\n-- but add_mul leads to either a+b+c=a+c+b or (a+b)+(c+d)=(a+c)+(b+d)\n-- (depending on whether we do induction on b or c)\n\nlemma add_right_comm (a b c : xnat) : a + b + c = a + c + b :=\nbegin\n  rw add_assoc,\n  rw add_comm b c,\n  rw \u2190add_assoc,\nend\n\n\nlemma succ_mul (a b : xnat) : succ a * b = a * b + b :=\nbegin\n  induction b with d hd,\n  {\n    refl\n  },\n  {\n    show (succ a) * d + (succ a) = (a * d + a) + _,\n    rw hd,\n    show succ (a * d + d + a) = succ (a * d + a + d),\n    rw add_right_comm\n  }\nend\n\n-- turns out I don't actually need this for mul_comm\nlemma add_mul (a b c : xnat) : (a + b) * c = a * c + b * c :=\nbegin\n  induction b with d hd,\n  { \n    rw zero_mul,\n    refl,\n  },\n  {\n    change succ (a + d) * c = _,\n    rw succ_mul,\n    rw hd,\n    rw succ_mul,\n    rw add_assoc\n  }\nend\n\nlemma mul_comm (a b : xnat) : a * b = b * a :=\nbegin\n  induction b with d hd,\n  {\n    rw zero_mul,\n    refl\n  },\n  {\n    rw succ_mul,\n    rw \u2190hd,\n    show a * (d + one) = _,\n    rw mul_add,\n    rw mul_one    \n  }\nend\n\n-- axiom 4 would follow from\ntheorem mul_pos (a b : xnat) : a \u2260 zero \u2192 b \u2260 zero \u2192 a * b \u2260 zero := sorry\n\n\ninductive le2 : xnat \u2192 xnat \u2192 Prop\n| refl (a : xnat) : le2 a a\n| succ (a b : xnat) : le2 a b \u2192 le2 a (succ b)\n\n/-\n\ndefinition lt : xnat \u2192 xnat \u2192 Prop \n| zero zero := false\n| (succ m) zero := false\n| zero (succ p) := true \n| (succ m) (succ p) := lt m p\n\ndefinition gt : xnat \u2192 xnat \u2192 Prop \n| zero zero := false\n| (succ m) zero := true\n| zero (succ p) := false \n| (succ m) (succ p) := gt m p\n\n-/\n\ninstance : has_le xnat := \u27e8le2\u27e9\n-- notation a < b := lt a b \n-- notation b > a := lt a b\n\nlemma zero_le (a : xnat) : zero \u2264 a :=\nbegin\n  induction a with d hd,\n  {\n    exact le2.refl zero\n  },\n  {\n    exact le2.succ zero d hd\n  }\nend\n\nlemma le_zero (a : xnat) : a \u2264 zero \u2192 a = zero :=\nbegin\n  intro h,\n  cases h,\n  refl\nend\n\nlemma le_refl (a : xnat) : a \u2264 a :=\nbegin\n  exact le2.refl a\nend\n\nlemma succ_le_succ (a b : xnat) (h : a \u2264 b) : succ a \u2264 succ b :=\nbegin\n  revert a,\n  induction b with d hd,\n  {\n    intros a ha,\n    rw le_zero a ha,\n    exact le_refl _\n  },\n  {\n    intros a ha,\n    cases ha with _ _ b hb, -- le2 leakage and random _'s\n    { apply le2.refl,\n    },\n    {\n      apply le2.succ, -- le2 leakage\n      apply hd,\n      assumption\n    }\n  }\nend\n\n-- axiom 1\ntheorem le_add_right (a b t : xnat) : a \u2264 b \u2192 (a + t) \u2264 (b + t) :=\nbegin\n  intro h,\n  induction t with d hd,\n  { \n    exact h\n  },\n  {\n    show succ (a + d) \u2264 succ (b + d),\n    exact succ_le_succ _ _ hd\n  }\nend\n\n-- axiom 2\ntheorem le_trans (a b c : xnat) (hab : a \u2264 b) (hbc : b \u2264 c) : a \u2264 c :=\nbegin\n  revert a b,\n  induction c with d hd,\n  {\n    intros a b hab hb0,\n    cases hb0,\n    cases hab,\n    apply le_refl\n  },\n  {\n    intros a b hab hb,\n    cases hb with _ _ c hc,\n      assumption,\n    apply le2.succ,\n    apply hd a b hab,\n    assumption\n  }  \nend\n\n-- axiom 3.1\ntheorem le_symm_thing (a b : xnat) : a \u2264 b \u2228 b \u2264 a :=\nbegin\n  revert a,\n  induction b with c hc,\n    intro a, right, apply zero_le,\n  intro a,\n  induction a with d hd,\n    left, apply zero_le,\n  cases hc d with h h,\n    left, exact succ_le_succ _ _ h,\n    right, exact succ_le_succ _ _ h,\nend\n\ntheorem le_succ (a : xnat) : a \u2264 succ a :=\nbegin\n  apply le2.succ,\n  apply le2.refl\nend\n\ntheorem le_of_succ_le_succ (a b : xnat) : succ a \u2264 succ b \u2192 a \u2264 b :=\nbegin\n  intro h,\n  cases h with _ _ a ha,\n    apply le_refl,\n  apply le_trans _ _ _ _ ha,\n  apply le_succ\nend\n\n-- axiom 3.2\ntheorem le_symm_other_thing (a b : xnat) : a \u2264 b \u2192 b \u2264 a \u2192 a = b :=\nbegin\n  revert a,\n  induction b with d hd,\n  {\n    intros a ha h,\n    cases ha,\n    refl,\n  },\n  { intro a,\n    cases a with a,\n      intros h1 h2, cases h2,\n    intros had hda,\n    congr,\n    apply hd,\n      exact le_of_succ_le_succ _ _ had,\n      exact le_of_succ_le_succ _ _ hda\n  }\nend\n\n\nend xena\n\n#exit\n\n/-\nimport data.nat.dist -- distance function\nimport data.nat.gcd -- gcd\nimport data.nat.modeq -- modular arithmetic\nimport data.nat.prime -- prime number stuff \nimport data.nat.sqrt  -- square roots\n\n-- factorials\n\nexample (a : \u2115) : fact a > 0 := fact_pos a\n\nexample : fact 4 = 24 := rfl -- factorial \n\n-- distances \n\nexample : dist 6 4 = 2 := rfl -- distance function\n\nexample (a b : \u2115) : a \u2260 b \u2192 dist a b > 0 := dist_pos_of_ne \n\n-- gcd\n\nexample (a b : \u2115) : gcd a b \u2223 a \u2227 gcd a b \u2223 b := gcd_dvd a b \n\nexample : lcm 6 4 = 12 := rfl \n\nexample (a b : \u2115) : lcm a b = lcm b a := lcm_comm a b\nexample (a b : \u2115) : gcd a b * lcm a b = a * b := gcd_mul_lcm a b\n\nexample (a b : \u2115) : (\u2200 k : \u2115, k > 1 \u2192 k \u2223 a \u2192 \u00ac (k \u2223 b) ) \u2192 coprime a b := coprime_of_dvd \n\n-- type the congruence symbol with \\== \n\nexample : 5 \u2261 8 [MOD 3] := rfl\n\nexample (a b c d m : \u2115) : a \u2261 b [MOD m] \u2192 c \u2261 d [MOD m] \u2192 a * c \u2261 b * d [MOD m] := modeq.modeq_mul\n\n-- nat.sqrt is integer square root (it rounds down).\n\n#eval sqrt 1000047\n-- returns 1000\n\nexample (a : \u2115) : sqrt (a * a) = a := sqrt_eq a\n\nexample (a b : \u2115) : sqrt a < b \u2194 a < b * b := sqrt_lt \n\n-- nat.prime n returns whether n is prime or not.\n-- We can prove 59 is prime if we first tell Lean that primality \n-- is decidable. But it's slow because the algorithms are\n-- not optimised for the kernel.\n\ninstance : decidable (prime 59) := decidable_prime_1 59 \nexample : prime 59 := dec_trivial \n\nexample (p : \u2115) : prime p \u2192 p \u2265 2 := prime.ge_two\n\nexample (p : \u2115) : prime p \u2194 p \u2265 2 \u2227 \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac (m \u2223 p) := prime_def_le_sqrt\n\nexample (p : \u2115) : prime p \u2192 (\u2200 m, coprime p m \u2228 p \u2223 m) := coprime_or_dvd_of_prime\n\nexample : \u2200 n, \u2203 p, p \u2265 n \u2227 prime p := exists_infinite_primes \n\n-- min_fac returns the smallest prime factor of n (or junk if it doesn't have one)\n\nexample : min_fac 12 = 2 := rfl \n\n-- `factors n` is the prime factorization of `n`, listed in increasing order.\n-- As far as I can see this isn't decidable, and doesn't seem to reduce either.\n-- But we can evaluate it in the virtual machine using #eval .\n\n#eval factors (2^32+1)\n-- [641, 6700417]\n\nProve every positive integer is uniquely the product of primes?\n\n\nsubtraction with weird notation\n\n-/", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Examples/xnat_complete_with_le.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.8128673087708698, "lm_q1q2_score": 0.7146296643461939}}
{"text": "def hello := \"world\"\n\nvariable (p q : Prop)\n\nvariable (p q r : Prop)\n\nexample (h: p -> q) (nq : \u00acq) : \u00acp :=\n  fun hp : p => nq (h hp)\n\n-- Note that (p->q) -> (not q -> not p) is constructive\n-- But (not q -> not p) -> (p -> q) is classical\n\n\n\n#check Trans\n#check And.intro\n\ndef f (x y z : Nat) : Nat :=\n  match x, y, z with\n  | 5, _, _ => y\n  | _, 5, _ => y\n  | _, _, 5 => y\n  | _, _, _ => 1\n\nexample (x y z : Nat) : x \u2260 5 \u2192 y \u2260 5 \u2192 z \u2260 5 \u2192 z = w \u2192 f x y w = 1 := by\n  intros\n  simp [f]\n  split\n  . contradiction\n  . contradiction\n  . contradiction\n  . rfl\n\nexample (p q : Prop) : p \u2228 q \u2192 q \u2228 p := by\n  intro h\n  cases h with\n  | inl hp => apply Or.inr; exact hp\n  | inr hq => apply Or.inl; exact hq\n\n\nexample (h : p \u2227 q) : q \u2227 p :=\n  have hp: p := h.left;\n  have hq: q := h.right;\n  And.intro hq hp\n\n\n\n\n\n\ninductive NN where\n| zero : NN\n| succ : NN -> NN\nderiving Repr\n\nopen NN\n\ndef leftAdd (n : NN) : (NN -> NN) := \n  match n with \n  | NN.zero => fun (m: NN) => m\n  | NN.succ n1 => fun (m : NN) => (leftAdd n1 m |> NN.succ)\n\n\n\ninstance : Add NN where\n  add := leftAdd\n\ndef leftAddZero (m : NN) : zero + m = m := by rfl;\ndef leftAddZero1 (m : NN) : m = zero + m := by\n  exact Eq.symm (leftAddZero m);\ndef leftAddSucc (n m : NN) : succ n + m = succ (n +m) := by rfl;\n\ntheorem leftAddFromRightByZero (n : NN) : n + NN.zero = n := by \napply NN.recOn (motive := fun x => x + NN.zero = x);\nrfl;\nintro a;\nintro h1;\ncalc \n  ((NN.succ a) + NN.zero) = (a + NN.zero |> NN.succ) := rfl\n  _ = (a |> NN.succ) := by rw [h1];\n\n\ntheorem leftAddFromRightBySucc (n m:NN): n + (NN.succ m) = ((n + m) |> NN.succ) := by\n  apply NN.recOn (motive := fun x => x + (NN.succ m) = ((x + m) |> NN.succ));\n  rfl;\n  intro a;\n  intro h1;\n  calc\n    ((succ a) + (succ m)) = ((a + (succ m)) |> succ) := rfl\n    _ = ((a + m) |> succ |> succ) := by rw [h1]\n\n\ntheorem leftAddCommutative (n m: NN) : n + m = m +n := by \n  apply NN.recOn (motive := fun x => x + m = m + x);\n  calc\n    zero + m = m  := by rfl\n    m = m + zero := by exact leftAddFromRightByZero m |> Eq.symm\n  intro a;\n  intro h1;\n  apply Eq.symm;\n  calc\n    m + succ a = ((m + a) |> succ) := by exact leftAddFromRightBySucc m a\n    _ = ((a + m) |> succ) := by rw [h1]\n--    succ a + m = ((a + m) |> succ) := by rfl\n\ntheorem leftAddAssociative (a b c: NN) : (a + b) + c = a + (b + c) := by\n  apply Eq.symm;\n  apply NN.recOn (motive := fun x => x + (b+c) = (x+b) + c);\n  rfl;\n  intro a;\n  intro h1;\n  calc\n    succ a + (b+c) = succ (a + (b+c)) := rfl\n    _ = succ (a + b+ c) := by rw [h1]\n\n\ntheorem succCancellation (a b : NN) : succ a = succ b -> a = b := by\n  intro h;\n  injection h with h';\n  assumption;\n\n\ntheorem succNotZero (a: NN) : ((succ a) \u2260 NN.zero) := by\n  intro h;\n  injection h;\n  \n\ntheorem leftAddSuccCancellation (a b c: NN) : succ a + b = succ a + c -> a + b = a + c := by\n  intro h1;\n  exact succCancellation (a+b) (a+c) h1;\n\n\ntheorem A (a b: Prop): a -> (a -> b) -> b := by\n  intro a;\n  intro h1;\n  exact h1 a;\n\n\ntheorem leftAddCancellation (a b c: NN) : a + b = a + c -> b = c := by\n  apply NN.recOn (motive := fun a => a + b = a + c -> b = c)\n  rw [leftAddZero b]\n  rw [leftAddZero c]\n  intro h1; exact h1;\n  intro a;\n  intro h1;\n  intro h2;\n  exact h1 ((leftAddSuccCancellation a b c) h2);\n\n\n\ndef isPositive (n : NN) : Prop := \n  n \u2260 zero\n\n\ntheorem constructiveContrapositive (p q: Prop) : (p -> q) -> (\u00acq -> \u00acp) := by\n  intro h1;\n  intro h2;\n  exact fun h : p => h2 (h1 h);\n\n\n\ntheorem sumEqualsZeroImpliesZero (a b : NN) : a + b = zero -> b = zero := by\n  cases a with\n  | zero => intro h; assumption;\n  | succ c => \n    intro h1;\n    have h2 : succ c + b = succ (c+b) := leftAddSucc c b;\n    rw [h2] at h1;\n    have f := succNotZero (c + b) h1;\n    exact False.elim f;\n\n\ntheorem addingToPositiveIsPositive (a b: NN) : isPositive b -> isPositive (a + b) := by\n  exact constructiveContrapositive (a + b = zero) (b = zero) (sumEqualsZeroImpliesZero a b);\n\n\ntheorem addToZeroImpliesZero (a b: NN) : a + b = zero -> a = zero \u2227 b = zero := by\n  simp;\n  intro p;\n  apply And.intro;\n  rw [leftAddCommutative] at p;\n  exact sumEqualsZeroImpliesZero b a p;\n  exact sumEqualsZeroImpliesZero a b p;\n\n\ntheorem reflProducer (t: Sort u) (a: t) : a = a := by\n  rfl;\n\n#check Exists.intro\n\nexample (p q : Nat \u2192 Prop) : (\u2203 x, p x) \u2192 \u2203 x, p x \u2228 q x := by\n  intro h\n  cases h with\n  | intro x px => exists x; apply Or.inl; exact px\n\ntheorem positiveImpliesExistenceSuccInverse (a b: NN) : isPositive b -> \u2203a, succ a = b := by\n  intro h;\n  cases b with \n  | zero => exact False.elim (h rfl);\n  | succ c => \n  exact Exists.intro c (reflProducer NN (succ c));\n\ndef isGTEQThan (m n: NN) : Prop := \n  \u2203a:NN,  m = a + n\n\ndef isGTThan (m n: NN) : Prop := \n  -- (isGTEQThan m n) \u2227 (m \u2260 n)\n  \u2203a:NN,  (m = a + n) \u2227 (isPositive a)\n\n\ntheorem reflexivityOfGTEQ (a : NN) : isGTEQThan a a := by\n  exact Exists.intro zero (leftAddZero1 a);\n\n#check leftAddAssociative\n\ntheorem transitiveOfGTEQ (a b c: NN) \n  (p : isGTEQThan a b) (q : isGTEQThan b c) : isGTEQThan a c := by\n  cases p with \n  | intro x1 p => \n  cases q with\n  | intro x2 q => \n  rw [q] at p;\n  rw [\u2190(leftAddAssociative x1 x2 c)] at p;\n  exact Exists.intro (x1 + x2) (p);\n\n#check leftAddZero\n#check leftAddCancellation\n\n#check leftAddCommutative\n#check addToZeroImpliesZero\n\ntheorem leftAddCancellation1 (a b c: NN) (h : b + a = c + a) : b = c := by\n   rw [leftAddCommutative, leftAddCommutative c a] at h;\n   exact leftAddCancellation a b c h;\n\n\ntheorem antisymmetryOfGTEQ (a b: NN) \n  (p : isGTEQThan a b) (q : isGTEQThan b a) : a = b := by\n  cases p with \n  | intro x1 p => \n  cases q with\n  | intro x2 q => \n  have h1 := leftAddZero a;\n  rw [\u2190h1] at p;\n  rw [q] at p;\n  rw [\u2190(leftAddAssociative x1 x2 a)] at p;\n  have h2 := Eq.symm (leftAddCancellation1 a zero (x1 + x2) p);\n  have h3 := addToZeroImpliesZero x1 x2 h2;\n  have h4 := h3.right;\n  rw [h4] at q;\n  have h5 := leftAddZero a;\n  rw [h5] at q;\n  exact Eq.symm q;\n\ntheorem addConstantToBothSides (a b c: NN) (p : a = b) : c + a = c + b := by\n  rw [p];\n\n\n#check leftAddAssociative\n\ntheorem additionPreservesGTEQ (a b c :NN) (p : isGTEQThan a b): isGTEQThan (c + a) (c + b) := by\n  cases p with \n  | intro x1 p => \n  have h : c + a = x1 + (c + b) := by\n    have h1 := (addConstantToBothSides a (x1 + b) c) p;\n    rw [leftAddCommutative x1 b, \u2190leftAddAssociative c b x1, (leftAddCommutative (c + b) x1)] at h1;\n    exact h1;\n  exact Exists.intro x1 h;\n\ntheorem additionPreservesGTEQ1 (a b c :NN) (p : isGTEQThan (c + a) (c + b)): isGTEQThan a b := by\n  cases p with\n  | intro x1 p => \n  have h1 : a = x1 + b := by sorry;\n  exact Exists.intro x1 h1;\n\ntheorem notEqualImpliesGT (m n: NN) (p : isGTThan m n) : (isGTEQThan m n) \u2227 (m \u2260 n) := by \n  -- same witness\n  sorry\n\n\n\n\ntheorem succGTEQImpliesGT (a b :NN) (p: isGTEQThan b (succ a)) : isGTThan b a := by\n  -- same witness\n  sorry\n\n\n\n\ntheorem trichotomy (a b : NN) : \u2203 c, (a = c + b) \u2228 (b = c + a) := by\n  induction a with\n  | zero =>\n  have h: b = b + zero := by\n    have h1 := leftAddZero1 b;\n    rw [leftAddCommutative] at h1;\n    exact h1; \n  exact Exists.intro (b) (Or.inr h);\n  | succ a h =>\n  cases h with\n  | intro x1 p =>\n  cases p with\n  | inl h1 =>\n  have q : (succ a) = (succ x1) + b := by sorry;\n  exact Exists.intro (succ x1) (Or.inl  q);\n  | inr h1 =>\n  cases x1 with \n  | zero =>\n  have hhh: succ a = (succ zero) + b := by sorry;\n  exact Exists.intro (succ zero) (Or.inl hhh);\n  | succ x1 =>\n  have h2 : b = x1 + succ a := by sorry;\n  exact Exists.intro (x1) (Or.inr h2);\n\n\ntheorem GTEQTrichotomy (a b : NN) : (isGTThan a b) \u2228 a = b \u2228 (isGTThan b a) := by sorry\n\n\ntheorem nothingLessThanZero (m : NN) (p:isGTThan zero m) : False := by sorry\n\ntheorem zeroGTEQThanZero (a : NN) (p: isGTEQThan zero a) : a = zero := by sorry\n\n#check nothingLessThanZero\n#check False.elim\n\ntheorem gtImpliesGTEQSucc {a b :NN} (p: isGTThan (succ b) a) : isGTEQThan b a := by\n  -- same witness\n  sorry\n\n\n\ntheorem GTEQImpliesGTOrEqual {m n: NN} (p: isGTEQThan m n) : (isGTThan m n) \u2228 (m = n) := by\n  sorry\n\n\n--\n-- THIS WAS A FUCKING DISASTER NGL\n--  \ntheorem strongInductionNNBaseZeroPart1 (P : NN -> Prop)\n  (q : \u2200m : NN, (\u2200 m': NN, (isGTThan m m') -> (P m')) -> P m)\n  : \u2200m : NN, (\u2200 m' : NN, (isGTEQThan m m') -> (P m')) := by\n  intro m;\n  induction m with\n  | zero => \n  intro m1;\n  intro h0;\n  have h1 : m1 = zero := zeroGTEQThanZero m1 h0;\n  have p := q zero;\n  --rw [nothingLessThanZero m'] at p;\n  have f : (\u2200 (m' : NN), isGTThan zero m' \u2192 P m') := (fun m: NN => \n  (fun p: isGTThan zero m => (False.elim (nothingLessThanZero m p))));\n  rw [h1];\n  exact p f;\n  | succ m2 h1 =>\n  have h2 : \u2200 (m' : NN), isGTThan (succ m2) m' \u2192 P m' := by\n    exact (fun m' => (fun x => (h1 m') (gtImpliesGTEQSucc x)));\n  --have h3 := q m1;\n  intro m1;\n  intro h6;\n  have h3 := (q (succ m2));\n  have h5 := h3 h2;\n  --have h5 := \n  have h7 : isGTThan (succ m2) m1 \u2228 (succ m2 = m1) := by \n    exact GTEQImpliesGTOrEqual h6;\n  cases h7 with\n  | inl h8 => exact ((h2 m1) h8);\n  | inr h9 => \n    rw [\u2190 h9];\n    exact h5;\n\n-- -- In the future lets make this \n-- -- into a semigroup \n-- -- and then we can just assert that a diferent base \n-- -- will be a new semigroup\n-- theorem strongInductionNNBaseZero (P : NN -> Prop)\n--   (q : \u2200m : NN, (\u2200 m': NN, (isGTThan m m') -> (P m')) -> P m)\n--   : \u2200m : NN, P m := by \n--   intro m;\n--   -- we need to induct with the extra criteria that \n--   -- (\u2200 m': NN, (isGTThan m m') -> (P m'))\n\n\n\n--   intro m1;\n--   induction m1 with\n--   | zero => \n--   have p := q zero;\n--   --rw [nothingLessThanZero m'] at p;\n--   have f : (\u2200 (m' : NN), isGTThan zero m' \u2192 P m') := (fun m: NN => \n--   (fun p: isGTThan zero m => (False.elim (nothingLessThanZero m p))));\n--   exact p f;\n--   | succ m1 h1 =>\n\n\n\n\n-- ======================================================================\n-- ON TO MULTIPLICATION\n\ndef leftMult (n : NN) : NN -> NN :=\n  match n with \n  | zero => fun (_ : NN) => zero\n  | succ n => fun (m : NN) => m + ((leftMult n) m)\n\ninstance : Mul NN where\n  mul := leftMult\n\ntheorem leftMultZero (n : NN) : leftMult zero n = zero := by rfl;\ntheorem leftMultSucc (n m: NN) : leftMult (succ n) m = m + leftMult n m := by rfl;\n\ntheorem leftMultZero1 (n : NN) : leftMult n zero = zero := by\n  induction n with\n  | zero => rfl;\n  | succ n h0 => \n    rw [leftMultSucc]\n    rw [h0]\n    rfl\n\ntheorem leftMultSucc1 (n m: NN) : leftMult m (succ n) = m + leftMult m n := by\n  induction m with\n  | zero => \n    rw [leftMultZero]\n    rw [leftMultZero]\n    rfl;\n  | succ m h0 => \n    rw [leftMultSucc]\n    rw [h0]\n    rw [leftMultSucc]\n    sorry;\n\n\ntheorem leftMultCommutative (n m : NN) : leftMult n m = leftMult m n := by\n  induction n with\n  | zero => rw [leftMultZero1 m]; rfl;\n  | succ n h0 =>\n    rw [leftMultSucc]\n    rw [leftMultSucc1]\n    rw [h0];\n\n#check Or.inl\n\ntheorem leftMultZeroDivisors (n m: NN) (p : leftMult n m = zero) :\n  n = zero \u2228 m = zero := by\n  cases n with\n  | zero => exact Or.inl rfl;\n  | succ n =>\n    rw [leftMultSucc] at p\n    -- m + something = zero implies m = zero\n    have h1 : m = zero := by sorry;\n    exact Or.inr h1; \n\ntheorem leftMultDistributive (a b c: NN) \n  : leftMult a (b+c) = (leftMult a b) + (leftMult a c) := by\n  induction a with\n  | zero => \n    rw [leftMultZero]\n    rw [leftMultZero]\n    rfl\n  | succ a h0 =>\n    rw [leftMultSucc]\n    rw [leftMultSucc]\n    rw [leftMultSucc]\n    rw [h0]\n    sorry -- just addition here\n    \n\ntheorem leftMultDistributive1 (a b c: NN) \n  : leftMult (a + b) c = (leftMult a c) + (leftMult b c) := by\n  induction c with\n  | zero => \n    rw [leftMultZero1]\n    rw [leftMultZero1]\n    rw [leftMultZero1]\n    rfl\n  | succ c h0 =>\n    rw [leftMultSucc1]\n    rw [leftMultSucc1]\n    rw [leftMultSucc1]\n    rw [h0]\n    sorry -- just addition here\n\n\ntheorem leftMultAssoc (a b c: NN)\n  : leftMult (leftMult a b) c = leftMult a (leftMult b c) := by\n  induction a with\n  | zero =>\n    rw [leftMultZero]\n    rw [leftMultZero]\n    rw [leftMultZero]\n  | succ a h0 =>\n    rw [leftMultSucc]\n    rw [leftMultSucc]\n    rw [\u2190h0]\n    rw [leftMultDistributive1]", "meta": {"author": "nice-buns", "repo": "Analysis1", "sha": "4188569a037708af7062cf924d50871618d94d47", "save_path": "github-repos/lean/nice-buns-Analysis1", "path": "github-repos/lean/nice-buns-Analysis1/Analysis1-4188569a037708af7062cf924d50871618d94d47/Tao1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7146296611911612}}
{"text": "/-\nCopyright (c) 2022 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module data.multiset.interval\n! leanprover-community/mathlib commit e97cf15cd1aec9bd5c193b2ffac5a6dc9118912b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.LocallyFinite\nimport Mathlib.Data.Dfinsupp.Interval\nimport Mathlib.Data.Dfinsupp.Multiset\nimport Mathlib.Data.Nat.Interval\n\n/-!\n# Finite intervals of multisets\n\nThis file provides the `LocallyFiniteOrder` instance for `Multiset \u03b1` and calculates the\ncardinality of its finite intervals.\n\n## Implementation notes\n\nWe implement the intervals via the intervals on `Dfinsupp`, rather than via filtering\n`Multiset.Powerset`; this is because `(Multiset.replicate n x).Powerset` has `2^n` entries not `n+1`\nentries as it contains duplicates. We do not go via `Finsupp` as this would be noncomputable, and\nmultisets are typically used computationally.\n\n-/\n\n\nopen Finset Dfinsupp Function\n\nopen BigOperators Pointwise\n\nvariable {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _}\n\nnamespace Multiset\n\nvariable [DecidableEq \u03b1] (f g : Multiset \u03b1)\n\ninstance : LocallyFiniteOrder (Multiset \u03b1) :=\n  LocallyFiniteOrder.ofIcc (Multiset \u03b1)\n    (fun f g =>\n      (Finset.Icc (Multiset.toDfinsupp f) (Multiset.toDfinsupp g)).map\n      Multiset.equivDfinsupp.toEquiv.symm.toEmbedding)\n    fun f g x => by simp\n\ntheorem Icc_eq :\n    Finset.Icc f g =\n      (Finset.Icc (Multiset.toDfinsupp f) (Multiset.toDfinsupp g)).map\n      Multiset.equivDfinsupp.toEquiv.symm.toEmbedding :=\n  rfl\n#align multiset.Icc_eq Multiset.Icc_eq\n\ntheorem card_Icc :\n    (Finset.Icc f g).card = \u220f i in f.toFinset \u222a g.toFinset, (g.count i + 1 - f.count i) := by\n  simp_rw [Icc_eq, Finset.card_map, Dfinsupp.card_Icc, Nat.card_Icc, Multiset.toDfinsupp_apply,\n    toDfinsupp_support]\n#align multiset.card_Icc Multiset.card_Icc\n\ntheorem card_Ico :\n    (Finset.Ico f g).card = \u220f i in f.toFinset \u222a g.toFinset, (g.count i + 1 - f.count i) - 1 := by\n  rw [card_Ico_eq_card_Icc_sub_one, card_Icc]\n#align multiset.card_Ico Multiset.card_Ico\n\ntheorem card_Ioc :\n    (Finset.Ioc f g).card = \u220f i in f.toFinset \u222a g.toFinset, (g.count i + 1 - f.count i) - 1 := by\n  rw [card_Ioc_eq_card_Icc_sub_one, card_Icc]\n#align multiset.card_Ioc Multiset.card_Ioc\n\ntheorem card_Ioo :\n    (Finset.Ioo f g).card = \u220f i in f.toFinset \u222a g.toFinset, (g.count i + 1 - f.count i) - 2 := by\n  rw [card_Ioo_eq_card_Icc_sub_two, card_Icc]\n#align multiset.card_Ioo Multiset.card_Ioo\n\ntheorem card_Iic : (Finset.Iic f).card = \u220f i in f.toFinset, (f.count i + 1) := by\n  simp_rw [Iic_eq_Icc, card_Icc, bot_eq_zero, toFinset_zero, empty_union, count_zero, tsub_zero]\n#align multiset.card_Iic Multiset.card_Iic\n\nend Multiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Multiset/Interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7146232437956017}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Heather Macbeth\n-/\nimport analysis.normed.field.unit_ball\nimport analysis.normed_space.basic\n\n/-!\n# Multiplicative actions of/on balls and spheres\n\nLet `E` be a normed vector space over a normed field `\ud835\udd5c`. In this file we define the following\nmultiplicative actions.\n\n- The closed unit ball in `\ud835\udd5c` acts on open balls and closed balls centered at `0` in `E`.\n- The unit sphere in `\ud835\udd5c` acts on open balls, closed balls, and spheres centered at `0` in `E`.\n-/\nopen metric set\nvariables {\ud835\udd5c \ud835\udd5c' E : Type*} [normed_field \ud835\udd5c] [normed_field \ud835\udd5c']\n  [seminormed_add_comm_group E] [normed_space \ud835\udd5c E] [normed_space \ud835\udd5c' E] {r : \u211d}\n\nsection closed_ball\n\ninstance mul_action_closed_ball_ball : mul_action (closed_ball (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n{ smul := \u03bb c x, \u27e8(c : \ud835\udd5c) \u2022 x, mem_ball_zero_iff.2 $\n    by simpa only [norm_smul, one_mul]\n      using mul_lt_mul' (mem_closed_ball_zero_iff.1 c.2) (mem_ball_zero_iff.1 x.2)\n        (norm_nonneg _) one_pos\u27e9,\n  one_smul := \u03bb x, subtype.ext $ one_smul \ud835\udd5c _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_closed_ball_ball :\n  has_continuous_smul (closed_ball (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n\u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n\ninstance mul_action_closed_ball_closed_ball :\n  mul_action (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n{ smul := \u03bb c x, \u27e8(c : \ud835\udd5c) \u2022 x, mem_closed_ball_zero_iff.2 $\n    by simpa only [norm_smul, one_mul]\n      using mul_le_mul (mem_closed_ball_zero_iff.1 c.2) (mem_closed_ball_zero_iff.1 x.2)\n        (norm_nonneg _) zero_le_one\u27e9,\n  one_smul := \u03bb x, subtype.ext $ one_smul \ud835\udd5c _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_closed_ball_closed_ball :\n  has_continuous_smul (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n\u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n\nend closed_ball\n\nsection sphere\n\ninstance mul_action_sphere_ball : mul_action (sphere (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n{ smul := \u03bb c x, inclusion sphere_subset_closed_ball c \u2022 x,\n  one_smul := \u03bb x, subtype.ext $ one_smul _ _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_sphere_ball :\n  has_continuous_smul (sphere (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n\u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n\ninstance mul_action_sphere_closed_ball : mul_action (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n{ smul := \u03bb c x, inclusion sphere_subset_closed_ball c \u2022 x,\n  one_smul := \u03bb x, subtype.ext $ one_smul _ _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_sphere_closed_ball :\n  has_continuous_smul (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : E) r) :=\n\u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n\ninstance mul_action_sphere_sphere : mul_action (sphere (0 : \ud835\udd5c) 1) (sphere (0 : E) r) :=\n{ smul := \u03bb c x, \u27e8(c : \ud835\udd5c) \u2022 x, mem_sphere_zero_iff_norm.2 $\n    by rw [norm_smul, mem_sphere_zero_iff_norm.1 c.coe_prop, mem_sphere_zero_iff_norm.1 x.coe_prop,\n      one_mul]\u27e9,\n  one_smul := \u03bb x, subtype.ext $ one_smul _ _,\n  mul_smul := \u03bb c\u2081 c\u2082 x, subtype.ext $ mul_smul _ _ _ }\n\ninstance has_continuous_smul_sphere_sphere :\n  has_continuous_smul (sphere (0 : \ud835\udd5c) 1) (sphere (0 : E) r) :=\n\u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n\nend sphere\n\nsection is_scalar_tower\n\nvariables [normed_algebra \ud835\udd5c \ud835\udd5c'] [is_scalar_tower \ud835\udd5c \ud835\udd5c' E]\n\ninstance is_scalar_tower_closed_ball_closed_ball_closed_ball :\n  is_scalar_tower (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (closed_ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance is_scalar_tower_closed_ball_closed_ball_ball :\n  is_scalar_tower (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance is_scalar_tower_sphere_closed_ball_closed_ball :\n  is_scalar_tower (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (closed_ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance is_scalar_tower_sphere_closed_ball_ball :\n  is_scalar_tower (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance is_scalar_tower_sphere_sphere_closed_ball :\n  is_scalar_tower (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (closed_ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance is_scalar_tower_sphere_sphere_ball :\n  is_scalar_tower (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance is_scalar_tower_sphere_sphere_sphere :\n  is_scalar_tower (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (sphere (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance is_scalar_tower_sphere_ball_ball :\n  is_scalar_tower (sphere (0 : \ud835\udd5c) 1) (ball (0 : \ud835\udd5c') 1) (ball (0 : \ud835\udd5c') 1) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : \ud835\udd5c')\u27e9\n\ninstance is_scalar_tower_closed_ball_ball_ball :\n  is_scalar_tower (closed_ball (0 : \ud835\udd5c) 1) (ball (0 : \ud835\udd5c') 1) (ball (0 : \ud835\udd5c') 1) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : \ud835\udd5c')\u27e9\n\nend is_scalar_tower\n\nsection smul_comm_class\n\nvariables [smul_comm_class \ud835\udd5c \ud835\udd5c' E]\n\ninstance smul_comm_class_closed_ball_closed_ball_closed_ball :\n  smul_comm_class (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (closed_ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance smul_comm_class_closed_ball_closed_ball_ball :\n  smul_comm_class (closed_ball (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance smul_comm_class_sphere_closed_ball_closed_ball :\n  smul_comm_class (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (closed_ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance smul_comm_class_sphere_closed_ball_ball :\n  smul_comm_class (sphere (0 : \ud835\udd5c) 1) (closed_ball (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance smul_comm_class_sphere_ball_ball [normed_algebra \ud835\udd5c \ud835\udd5c'] :\n  smul_comm_class (sphere (0 : \ud835\udd5c) 1) (ball (0 : \ud835\udd5c') 1) (ball (0 : \ud835\udd5c') 1) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : \ud835\udd5c')\u27e9\n\ninstance smul_comm_class_sphere_sphere_closed_ball :\n  smul_comm_class (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (closed_ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance smul_comm_class_sphere_sphere_ball :\n  smul_comm_class (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\ninstance smul_comm_class_sphere_sphere_sphere :\n  smul_comm_class (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (sphere (0 : E) r) :=\n\u27e8\u03bb a b c, subtype.ext $ smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n\nend smul_comm_class\n\nvariables (\ud835\udd5c) [char_zero \ud835\udd5c]\n\nlemma ne_neg_of_mem_sphere {r : \u211d} (hr : r \u2260 0) (x : sphere (0:E) r) : x \u2260 - x :=\n\u03bb h, ne_zero_of_mem_sphere hr x ((self_eq_neg \ud835\udd5c _).mp (by { conv_lhs {rw h}, simp }))\n\nlemma ne_neg_of_mem_unit_sphere (x : sphere (0:E) 1) : x \u2260 - x :=\nne_neg_of_mem_sphere \ud835\udd5c one_ne_zero x\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed_space/ball_action.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8175744717487329, "lm_q1q2_score": 0.7146232284438464}}
{"text": "theorem not_succ_le_self (a : mynat) : \u00ac (succ a \u2264 a) :=\nbegin\nintro h,\nhave h2 := (le_antisymm a (succ a)) (le_succ_self a) h,\nexact (ne_succ_self a) h2,\nend", "meta": {"author": "nicholaspun", "repo": "natural-number-game-solutions", "sha": "1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0", "save_path": "github-repos/lean/nicholaspun-natural-number-game-solutions", "path": "github-repos/lean/nicholaspun-natural-number-game-solutions/natural-number-game-solutions-1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0/8-inequality-world/l13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9615338079816756, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.7145811707608576}}
{"text": "import data.finset\nimport algebra.field\nimport order.zorn\nimport Rings.ToMathlib\n\nopen classical\nlocal attribute [instance] prop_decidable\n\nuniverse u\n\n/-- A pregeometry consists of\n  * a type `Carrier`\n  * a closure map `Cl` from the powerset of `Carrier` to itself\n  such that\n  * `Cl` is a morphism of orders (with the natural ordering on the powerset)\n  * `Cl` is idempotent\n  * Any element in the closure is in the closure of some finite subset\n  * The generalized Steinitz exchange works with `Cl` viewed as the span\n-/\nclass Pregeometry : Type (u + 1) :=\n(Carrier : Type u)\n(Cl : set Carrier \u2192 set Carrier)\n(Closure : \u03a0 {U : set Carrier}, U \u2286 Cl U)\n(Mono : \u03a0 {U V : set Carrier}, U \u2286 V \u2192 Cl U \u2286 Cl V)\n(Idem : \u03a0 (U : set Carrier), Cl (Cl U) = Cl U)\n(FinChar : \u03a0 {U} {a : Carrier} (h : a \u2208 Cl U), finset Carrier)\n(FinCharProp : \u03a0 {U} {a} (h : a \u2208 Cl U), \u2191(FinChar h) \u2286 U \u2227 a \u2208 Cl (FinChar h))\n(Exch : \u03a0 {U : set Carrier} {a b : Carrier}, a \u2208 Cl (U \u222a {b}) \u2192 a \u2208 Cl U \u2228 b \u2208 Cl (U \u222a {a}))\n\nnamespace Pregeometry\n  variables\n    {X : Pregeometry} (U V W : set Carrier)\n\n  def Spans : Prop := U \u2286 V \u2227 Cl U = Cl V\n\n  def Indep : Prop := \u03a0 a : Carrier, (a \u2208 U) \u2192 a \u2209 Cl (U \\ {a})\n\n  def Basis : Prop := Spans U V \u2227 Indep U\n\n  def Dep : Prop := \u2203 (a : Carrier) (haU : a \u2208 U), a \u2208 Cl (U \\ {a})\n\n  variables {U} {V} {W}\n\n  lemma SubIndep : Indep V \u2192 \u03a0 (U : set Carrier), U \u2286 V \u2192 Indep U :=\n  begin\n    intros hV U hsub a haU hbot,\n    have haV := hsub haU,\n    apply hV a haV,\n    apply Mono _ hbot,\n    apply set.diff_subset_diff hsub,\n    simp,\n  end\n\n  lemma SpansTrans : Spans U V \u2192 Spans V W \u2192 Spans U W :=\n  begin\n    intros hUV hVW,\n    split,\n    {apply set.subset.trans hUV.1 hVW.1},\n    {rw hUV.2, exact hVW.2}\n  end\n\n  lemma SubClSpans : U \u2286 V \u2192 V \u2286 Cl U \u2192 Spans U V :=\n  begin\n    intros hUV hVCl,\n    split,\n    {exact hUV},\n    {\n      apply set.ext,\n      intro x,\n      split,\n      {apply Mono hUV},\n      {\n        rw \u2190 @Idem _ U,\n        apply Mono hVCl,\n      },\n    }\n  end\n\n  lemma NotIndep : \u00ac Indep U \u2194 Dep U :=\n  begin\n    split,\n    {\n      intro hnIndU,\n      cases not_forall.1 hnIndU with x hx,\n      cases not_imp.1 hx with hxU hnn,\n      rw not_not at hnn,\n      use x,\n      exact \u27e8 hxU , hnn \u27e9\n    },\n    {\n      intros hDep hbot,\n      cases hDep with x hx,\n      cases hx with hxU hxCl,\n      exact hbot x hxU hxCl,\n    }\n  end\n\n  lemma IndepInsert : Indep U \u2192 \u03a0 (a : Carrier), (a \u2209 Cl U) \u2192 Indep (U \u222a {a}) :=\n  begin\n    intros hU a haClU b hbUa hbot,\n    cases hbUa,\n    {\n      have hExch : b \u2208 Cl ((U \\ {b}) \u222a {a}),\n      {\n        apply Mono _ hbot,\n        intros x hx,\n        cases hx with hxUa hxb,\n        cases hxUa with hxU hxa,\n        {\n          left,\n          split,\n          exact hxU,\n          exact hxb,\n        },\n        {\n          right,\n          exact hxa,\n        },\n      },\n      cases Pregeometry.Exch hExch with hb ha,\n      {apply hU b hbUa hb},\n      {\n        apply haClU,\n        apply Mono _ ha,\n        tidy,\n      },\n    },\n    {\n      have hba : b = a := set.mem_singleton_iff.1 hbUa,\n      apply haClU,\n      rw hba at hbot,\n      apply Mono _ hbot,\n      simp,\n    },\n  end\n\n  lemma FinCharIndep :\n    Indep U \u2194 (\u03a0 (F : finset Carrier), (\u2191F \u2286 U) \u2192 Indep (F : set Carrier)) :=\n  begin\n    split,\n    {\n      intros hU F hsub,\n      apply SubIndep hU F hsub,\n    },\n    {\n      intros hFin a haU hbot,\n      have Fp := FinCharProp hbot,\n      cases Fp with hFU haF,\n      have hsub : \u2191(FinChar hbot) \u222a {a} \u2286 U,\n      {\n        intros x hx,\n        cases hx,\n        {\n          have hsub : U \\ {a} \u2286 U := by simp,\n          apply hsub (hFU _),\n          exact hx,\n        },\n        {\n          rw (set.mem_singleton_iff.1 hx),\n          exact haU,\n        },\n      },\n      have ha : a \u2208 (FinChar hbot : set Carrier) \u222a {a} := by simp,\n      have hcoe : (FinChar hbot : set Carrier) \u222a {a} = \u2191(FinChar hbot \u222a {a})\n        := by simp,\n      rw hcoe at hsub ha,\n      apply hFin (FinChar hbot \u222a {a}) hsub a ha,\n      have hsub1 : (FinChar hbot : set Carrier) \u2286 \u2191(FinChar hbot \u222a {a}) \\ {a},\n      {\n        intros x hx,\n        simp,\n        split,\n        {exact hx},\n        {\n          intro hxa,\n          cases hFU hx with _ hr,\n          apply hr,\n          simpa using hxa,\n        },\n      },\n      apply Mono hsub1,\n      exact haF,\n    },\n  end\n\n  lemma BasisBetweenAux : U \u2286 V \u2192 V \u2286 W \u2192 Indep U \u2192 Spans V W \u2192\n    \u2203 (B : set Carrier) (hB : B \u2208 {Y : set Carrier | U \u2286 Y \u2227 Y \u2286 V \u2227 Indep Y}),\n    U \u2286 B \u2227\n    \u2200 (Y : set Carrier), Y \u2208 {Y : set Carrier | U \u2286 Y \u2227 Y \u2286 V \u2227 Indep Y} \u2192 B \u2286 Y \u2192 Y = B :=\n  \u03bb hUV hVW hIndU hSpV,\n    (@zorn.zorn_subset_nonempty Carrier { Y : set Carrier | U \u2286 Y \u2227 Y \u2286 V \u2227 Indep Y }\n      (\u03bb c hcsub hchain hc0,\n        \u27e8\n          -- the upper bound by taking union\n          \u22c3\u2080 c ,\n          \u27e8\n            let hUcup : U \u2286 \u22c3\u2080 c :=\n            begin\n              cases hc0 with Y hY,\n              cases hcsub hY with hUY hand,\n              have hYcup : Y \u2286 \u22c3\u2080 c := \u03bb y hy , \u27e8 Y , hY , hy \u27e9,\n              exact set.subset.trans hUY hYcup,\n            end,\n            hcupV : \u22c3\u2080 c \u2286 V :=\n            begin\n              intros y hy,\n              cases hy with Y hY,\n              cases hY with hYc hyY,\n              cases hcsub hYc with _ hYV,\n              cases hYV with hYV,\n              exact hYV hyY,\n            end,\n            hcupInd : Indep (\u22c3\u2080 c) :=\n            begin\n              rw FinCharIndep,\n              intros F hF,\n              -- F finite \u2192 F \u2286 Y for some Y \u2208 c\n              cases zorn.fin_sub_mem_chain_of_sub_union hchain hc0 F hF with Y hY,\n              cases hY with hYc hFY,\n              cases hcsub hYc with _ hY,\n              cases hY with _ hIndY,\n              apply SubIndep hIndY _ hFY,\n            end in\n            -- the upper bound is in the set\n            \u27e8 hUcup , hcupV , hcupInd \u27e9 ,\n            (\u03bb Y hY y hy, \u27e8 Y , hY , hy \u27e9) -- showing the maximal element is in the set\n          \u27e9\n        \u27e9\n      )\n      U -- give U for the set being non-empty\n      \u27e8 set.subset.refl _ , hUV , hIndU \u27e9)\n\n  -- not sure if it would be better to have a lemma saying maximally independent elements\n  -- are bases, the meat of the name theorem\n\n  lemma BasisBetween : U \u2286 V \u2192 V \u2286 W \u2192 Indep U \u2192 Spans V W \u2192\n    \u2203 (B : set Carrier), Basis B W \u2227 U \u2286 B \u2227 B \u2286 V :=\n  begin\n    intros hUV hVW hIndU hSpV,\n    have hmax := BasisBetweenAux hUV hVW hIndU hSpV,\n    cases hmax with B hB,\n    cases hB with hB hmax,\n    cases hmax with hUB hmax,\n    use B,\n    split,\n    split,\n    { -- B spans W\n      -- it suffices that B spans V\n      apply SpansTrans _ hSpV,\n      -- it suffices that V \u2286 Cl B\n      apply SubClSpans (set.subset.trans hB.2.1 (set.subset.refl _)),\n      intros x hxV,\n      by_cases hxB : x \u2208 B,\n      {exact Closure hxB},\n      {\n        -- we will show that B \u222a {x} is dependent, hence giving us an element y \u2208 B to\n        -- exchange with x\n        have hDep : \u00ac Indep (B \u222a {x}),\n        {\n          intro hInd,\n          have hBx : B \u222a {x} \u2208 {Y : set Carrier | U \u2286 Y \u2227 Y \u2286 V \u2227 Indep Y},\n          {\n            split,\n            {apply (@set.subset.trans _ U B (B \u222a {x}) hUB), simp,},\n            split,\n            {\n              simp only [set.union_singleton, set.insert_subset],\n              exact \u27e8 hxV , hB.2.1 \u27e9,\n            },\n            {exact hInd},\n          },\n          apply hxB,\n          rw \u2190 (hmax (B \u222a {x}) hBx (by simp)),\n          simp,\n        },\n        rw NotIndep at hDep,\n        cases hDep with y hy,\n        cases hy with hyU hyCl,\n        by_cases hxy : x = y,\n        {\n          -- in the case when x = y we just added x to B then removed x again\n          rw \u2190 hxy at hyCl,\n          rw set.remove_insert_not_mem hxB,\n          exact hyCl,\n        },\n        {\n          -- when x \u2260 y we can exchange x for y\n          have hB2 : (B \u222a {x}) \\ {y} = (B \\ {y}) \u222a {x} := set.union_sdiff hxy,\n          rw hB2 at hyCl,\n          have hyB : y \u2208 B,\n          {\n            cases hyU,\n            exact hyU,\n            rw set.mem_singleton_iff at hyU,\n            exfalso,\n            apply hxy,\n            rw hyU\n          },\n          cases Exch hyCl with hy hyCl1,\n          {\n            -- as B is independent the first case is false\n            exfalso,\n            apply hB.2.2 y hyB hy,\n          },\n          {\n            -- now we have just removed and added y from B\n            rw set.remove_insert hyB at hyCl1,\n            exact hyCl1,\n          },\n        },\n      },\n    },\n    {exact hB.2.2},\n    {exact \u27e8 hB.1 , hB.2.1 \u27e9}\n  end\n\n  lemma IndepEmpty : @Indep X \u2205 :=\n  begin\n    intros x hx,\n    cases hx,\n  end\n\n  lemma UnivSpans : @Spans X set.univ set.univ :=\n  begin\n    split,\n    simp,\n  end\n\n  lemma HasBasis : \u2203 (B : set X.Carrier), Basis B set.univ :=\n  begin\n    cases BasisBetween (set.empty_subset _) (set.subset_univ _) IndepEmpty UnivSpans with B hB,\n    exact \u27e8 B , hB.1 \u27e9,\n  end\n\n  def Degree (X) : cardinal := cardinal.mk (@classical.some _ _ (@HasBasis X))\n\nend Pregeometry\n", "meta": {"author": "Jlh18", "repo": "ModelTheoryInLean8", "sha": "fbda7d869d4169b6e739bb74165e99ee03ca63d6", "save_path": "github-repos/lean/Jlh18-ModelTheoryInLean8", "path": "github-repos/lean/Jlh18-ModelTheoryInLean8/ModelTheoryInLean8-fbda7d869d4169b6e739bb74165e99ee03ca63d6/Trash/Pregeometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109622750986, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7145589922299068}}
{"text": "import data.nat.basic\nimport data.nat.prime\nimport data.rat.basic\nimport algebra.field\nimport algebra.char_zero\nimport algebra.char_p\nimport field_theory.separable\nimport field_theory.algebraic_closure\nimport myhelper.char\nimport myhelper.perfect\nimport tactic\n\ndef my_sep_closed (K : Type*) [field K] :=\n\u2200 f : polynomial K, f.separable \u2192 f.degree \u2260 0 \u2192 \u2203 x : K, polynomial.eval\u2082 (ring_hom.id K) x f = 0\n\nlemma alg_closed_implies_sep_closed (K : Type*) [field K] :\nis_alg_closed K \u2192 my_sep_closed K :=\nbegin\n  intros hac f hsep hdeg,\n  have hsplit := @polynomial.splits' K K _ hac _ (ring_hom.id K) f,\n  exact polynomial.exists_root_of_splits (ring_hom.id K) hsplit hdeg,\nend\n\nlemma alg_closed_implies_pow_surj (K : Type*) [field K] [is_alg_closed K] (n : \u2115) (hn : n \u2260 0)\n: nth_power_surjective K n :=\nbegin\n  intro x,\n  let f : polynomial K := polynomial.X^n - (polynomial.C x),\n  have hdeg := calc f.degree = n : polynomial.degree_X_pow_sub_C (nat.pos_of_ne_zero hn) x\n  ... \u2260 0 : by { norm_cast, exact hn, },\n  have hsplit := @polynomial.splits' K K _ _ _ (ring_hom.id K) f,\n  replace hsplit := polynomial.exists_root_of_splits (ring_hom.id K) hsplit hdeg,\n  cases hsplit with y hy,\n  use y,\n  simp at hy,\n  calc y ^ n = x + (y ^ n - x) : by ring\n  ... = x : by { rw hy, ring, },\nend\n\nlemma sep_closed_implies_pow_surj (K : Type*) [field K] (hsc : my_sep_closed K) (n : \u2115) (hn : \u00ac (ring_char K) \u2223 n)\n: nth_power_surjective K n :=\nbegin\n  intro x,\n  have hn' : n \u2260 0 := by { intro h, rw h at hn, simp at hn, exact hn, },\n  by_cases hx : x = 0, {\n    use 0,\n    simp only [hx, hn', ne.def, not_false_iff, zero_pow'],\n  },\n  let f : polynomial K := polynomial.X^n - (polynomial.C x),\n  have hdeg := calc f.degree = n : polynomial.degree_X_pow_sub_C (nat.pos_of_ne_zero hn') x\n  ... \u2260 0 : by { norm_cast, exact hn', },\n  let f' : polynomial K := (polynomial.C (n : K)) * polynomial.X^(n-1),\n  have hf' : f' = f.derivative := by {\n    have : f = (polynomial.C (1 : K)) * polynomial.X^n - (polynomial.C x) := by simp,\n    rw [this, polynomial.derivative_sub, polynomial.derivative_C_mul_X_pow, polynomial.derivative_C],\n    simp,\n  },\n  have hcop : is_coprime f f.derivative := by {\n    rw \u2190 hf',\n    let a : polynomial K := polynomial.C (-(1 : K) / x),\n    let b : polynomial K := polynomial.C ((1 : K) / x / n) * polynomial.X,\n    use [a, b],\n    have hnK : (n : K) \u2260 0 := by {\n      refine ndvd_char_is_non_zero (calc ring_char K = ring_char K : rfl) n _,\n      norm_cast, exact hn,\n    },\n    calc a * f + b * f'\n    = (polynomial.C (-(1 : K) / x)) * polynomial.X^n - (polynomial.C (-(1 : K) / x)) * (polynomial.C x)\n    + polynomial.C ((1 : K) / x / n) * (polynomial.C (n : K)) * (polynomial.X * polynomial.X^(n-1)) : by {\n      rw mul_sub,\n      rw mul_assoc _ polynomial.X,\n      rw \u2190 mul_assoc polynomial.X _,\n      rw mul_comm polynomial.X (polynomial.C (n : K)),\n      repeat { rw \u2190 mul_assoc },\n    }\n    ... = 1 : by {\n      repeat { rw \u2190 polynomial.C_mul },\n      rw \u2190 pow_succ _ (n-1),\n      have := nat.pos_of_ne_zero hn',\n      have : 1 \u2264 n := by linarith,\n      have : n-1+1=n := by { rw nat.sub_add_eq_add_sub this, simp, },\n      rw this,\n      rw sub_add_eq_add_sub,\n      rw \u2190 add_mul,\n      rw \u2190 polynomial.C_add,\n      have : (-1) / x + 1 / x / \u2191n * \u2191n = 0 := by {\n        field_simp [hx, hnK], ring,\n      },\n      rw this,\n      have : (-1) / x * x = -1 := by { field_simp [hx], },\n      rw this,\n      rw polynomial.C_0,\n      rw zero_mul,\n      simp,\n    },\n  },\n  cases hsc f hcop hdeg with y hy,\n  use y,\n  simp at hy,\n  calc y ^ n = x + (y ^ n - x) : by ring\n  ... = x : by { rw hy, ring, },\nend\n", "meta": {"author": "acmepjz", "repo": "my-lean-test", "sha": "fd1bb144adc9ccd23794a867a2dd2cf57648b089", "save_path": "github-repos/lean/acmepjz-my-lean-test", "path": "github-repos/lean/acmepjz-my-lean-test/my-lean-test-fd1bb144adc9ccd23794a867a2dd2cf57648b089/myhelper/separable_closed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907010924213, "lm_q2_score": 0.7853085909370423, "lm_q1q2_score": 0.7145577926326296}}
{"text": "/-\nCopyright (c) 2019 Gabriel Ebner. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gabriel Ebner, S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module analysis.calculus.deriv\n! leanprover-community/mathlib commit 8c8c544bf24ced19b1e76c34bb3262bdae620f82\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Calculus.Fderiv\nimport Mathbin.Data.Polynomial.Derivative\nimport Mathbin.LinearAlgebra.AffineSpace.Slope\n\n/-!\n\n# One-dimensional derivatives\n\nThis file defines the derivative of a function `f : \ud835\udd5c \u2192 F` where `\ud835\udd5c` is a\nnormed field and `F` is a normed space over this field. The derivative of\nsuch a function `f` at a point `x` is given by an element `f' : F`.\n\nThe theory is developed analogously to the [Fr\u00e9chet\nderivatives](./fderiv.html). We first introduce predicates defined in terms\nof the corresponding predicates for Fr\u00e9chet derivatives:\n\n - `has_deriv_at_filter f f' x L` states that the function `f` has the\n    derivative `f'` at the point `x` as `x` goes along the filter `L`.\n\n - `has_deriv_within_at f f' s x` states that the function `f` has the\n    derivative `f'` at the point `x` within the subset `s`.\n\n - `has_deriv_at f f' x` states that the function `f` has the derivative `f'`\n    at the point `x`.\n\n - `has_strict_deriv_at f f' x` states that the function `f` has the derivative `f'`\n    at the point `x` in the sense of strict differentiability, i.e.,\n   `f y - f z = (y - z) \u2022 f' + o (y - z)` as `y, z \u2192 x`.\n\nFor the last two notions we also define a functional version:\n\n  - `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the\n    derivative does not exist, then `deriv_within f s x` equals zero.\n\n  - `deriv f x` is a derivative of `f` at `x`. If the derivative does not\n    exist, then `deriv f x` equals zero.\n\nThe theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the\none-dimensional derivatives coincide with the general Fr\u00e9chet derivatives.\n\nWe also show the existence and compute the derivatives of:\n  - constants\n  - the identity function\n  - linear maps\n  - addition\n  - sum of finitely many functions\n  - negation\n  - subtraction\n  - multiplication\n  - inverse `x \u2192 x\u207b\u00b9`\n  - multiplication of two functions in `\ud835\udd5c \u2192 \ud835\udd5c`\n  - multiplication of a function in `\ud835\udd5c \u2192 \ud835\udd5c` and of a function in `\ud835\udd5c \u2192 E`\n  - composition of a function in `\ud835\udd5c \u2192 F` with a function in `\ud835\udd5c \u2192 \ud835\udd5c`\n  - composition of a function in `F \u2192 E` with a function in `\ud835\udd5c \u2192 F`\n  - inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)\n  - division\n  - polynomials\n\nFor most binary operations we also define `const_op` and `op_const` theorems for the cases when\nthe first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,\nand they more frequently lead to the desired result.\n\nWe set up the simplifier so that it can compute the derivative of simple functions. For instance,\n```lean\nexample (x : \u211d) : deriv (\u03bb x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=\nby { simp, ring }\n```\n\n## Implementation notes\n\nMost of the theorems are direct restatements of the corresponding theorems\nfor Fr\u00e9chet derivatives.\n\nThe strategy to construct simp lemmas that give the simplifier the possibility to compute\nderivatives is the same as the one for differentiability statements, as explained in `fderiv.lean`.\nSee the explanations there.\n-/\n\n\nuniverse u v w\n\nnoncomputable section\n\nopen Classical Topology BigOperators Filter ENNReal Polynomial\n\nopen Filter Asymptotics Set\n\nopen ContinuousLinearMap (smul_right smulRight_one_eq_iff)\n\nvariable {\ud835\udd5c : Type u} [NontriviallyNormedField \ud835\udd5c]\n\nsection\n\nvariable {F : Type v} [NormedAddCommGroup F] [NormedSpace \ud835\udd5c F]\n\nvariable {E : Type w} [NormedAddCommGroup E] [NormedSpace \ud835\udd5c E]\n\n/-- `f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges along the filter `L`.\n-/\ndef HasDerivAtFilter (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) (L : Filter \ud835\udd5c) :=\n  HasFderivAtFilter f (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x L\n#align has_deriv_at_filter HasDerivAtFilter\n\n/-- `f` has the derivative `f'` at the point `x` within the subset `s`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef HasDerivWithinAt (f : \ud835\udd5c \u2192 F) (f' : F) (s : Set \ud835\udd5c) (x : \ud835\udd5c) :=\n  HasDerivAtFilter f f' x (\ud835\udcdd[s] x)\n#align has_deriv_within_at HasDerivWithinAt\n\n/-- `f` has the derivative `f'` at the point `x`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges to `x`.\n-/\ndef HasDerivAt (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) :=\n  HasDerivAtFilter f f' x (\ud835\udcdd x)\n#align has_deriv_at HasDerivAt\n\n/-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability.\n\nThat is, `f y - f z = (y - z) \u2022 f' + o(y - z)` as `y, z \u2192 x`. -/\ndef HasStrictDerivAt (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) :=\n  HasStrictFderivAt f (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x\n#align has_strict_deriv_at HasStrictDerivAt\n\n/-- Derivative of `f` at the point `x` within the set `s`, if it exists.  Zero otherwise.\n\nIf the derivative exists (i.e., `\u2203 f', has_deriv_within_at f f' s x`), then\n`f x' = f x + (x' - x) \u2022 deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef derivWithin (f : \ud835\udd5c \u2192 F) (s : Set \ud835\udd5c) (x : \ud835\udd5c) :=\n  fderivWithin \ud835\udd5c f s x 1\n#align deriv_within derivWithin\n\n/-- Derivative of `f` at the point `x`, if it exists.  Zero otherwise.\n\nIf the derivative exists (i.e., `\u2203 f', has_deriv_at f f' x`), then\n`f x' = f x + (x' - x) \u2022 deriv f x + o(x' - x)` where `x'` converges to `x`.\n-/\ndef deriv (f : \ud835\udd5c \u2192 F) (x : \ud835\udd5c) :=\n  fderiv \ud835\udd5c f x 1\n#align deriv deriv\n\nvariable {f f\u2080 f\u2081 g : \ud835\udd5c \u2192 F}\n\nvariable {f' f\u2080' f\u2081' g' : F}\n\nvariable {x : \ud835\udd5c}\n\nvariable {s t : Set \ud835\udd5c}\n\nvariable {L L\u2081 L\u2082 : Filter \ud835\udd5c}\n\n/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/\ntheorem hasFderivAtFilter_iff_hasDerivAtFilter {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n    HasFderivAtFilter f f' x L \u2194 HasDerivAtFilter f (f' 1) x L := by simp [HasDerivAtFilter]\n#align has_fderiv_at_filter_iff_has_deriv_at_filter hasFderivAtFilter_iff_hasDerivAtFilter\n\ntheorem HasFderivAtFilter.hasDerivAtFilter {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n    HasFderivAtFilter f f' x L \u2192 HasDerivAtFilter f (f' 1) x L :=\n  hasFderivAtFilter_iff_hasDerivAtFilter.mp\n#align has_fderiv_at_filter.has_deriv_at_filter HasFderivAtFilter.hasDerivAtFilter\n\n/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/\ntheorem hasFderivWithinAt_iff_hasDerivWithinAt {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n    HasFderivWithinAt f f' s x \u2194 HasDerivWithinAt f (f' 1) s x :=\n  hasFderivAtFilter_iff_hasDerivAtFilter\n#align has_fderiv_within_at_iff_has_deriv_within_at hasFderivWithinAt_iff_hasDerivWithinAt\n\n/-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/\ntheorem hasDerivWithinAt_iff_hasFderivWithinAt {f' : F} :\n    HasDerivWithinAt f f' s x \u2194 HasFderivWithinAt f (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') s x :=\n  Iff.rfl\n#align has_deriv_within_at_iff_has_fderiv_within_at hasDerivWithinAt_iff_hasFderivWithinAt\n\ntheorem HasFderivWithinAt.hasDerivWithinAt {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n    HasFderivWithinAt f f' s x \u2192 HasDerivWithinAt f (f' 1) s x :=\n  hasFderivWithinAt_iff_hasDerivWithinAt.mp\n#align has_fderiv_within_at.has_deriv_within_at HasFderivWithinAt.hasDerivWithinAt\n\ntheorem HasDerivWithinAt.hasFderivWithinAt {f' : F} :\n    HasDerivWithinAt f f' s x \u2192 HasFderivWithinAt f (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') s x :=\n  hasDerivWithinAt_iff_hasFderivWithinAt.mp\n#align has_deriv_within_at.has_fderiv_within_at HasDerivWithinAt.hasFderivWithinAt\n\n/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/\ntheorem hasFderivAt_iff_hasDerivAt {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} : HasFderivAt f f' x \u2194 HasDerivAt f (f' 1) x :=\n  hasFderivAtFilter_iff_hasDerivAtFilter\n#align has_fderiv_at_iff_has_deriv_at hasFderivAt_iff_hasDerivAt\n\ntheorem HasFderivAt.hasDerivAt {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} : HasFderivAt f f' x \u2192 HasDerivAt f (f' 1) x :=\n  hasFderivAt_iff_hasDerivAt.mp\n#align has_fderiv_at.has_deriv_at HasFderivAt.hasDerivAt\n\ntheorem hasStrictFderivAt_iff_hasStrictDerivAt {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n    HasStrictFderivAt f f' x \u2194 HasStrictDerivAt f (f' 1) x := by\n  simp [HasStrictDerivAt, HasStrictFderivAt]\n#align has_strict_fderiv_at_iff_has_strict_deriv_at hasStrictFderivAt_iff_hasStrictDerivAt\n\nprotected theorem HasStrictFderivAt.hasStrictDerivAt {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n    HasStrictFderivAt f f' x \u2192 HasStrictDerivAt f (f' 1) x :=\n  hasStrictFderivAt_iff_hasStrictDerivAt.mp\n#align has_strict_fderiv_at.has_strict_deriv_at HasStrictFderivAt.hasStrictDerivAt\n\ntheorem hasStrictDerivAt_iff_hasStrictFderivAt :\n    HasStrictDerivAt f f' x \u2194 HasStrictFderivAt f (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x :=\n  Iff.rfl\n#align has_strict_deriv_at_iff_has_strict_fderiv_at hasStrictDerivAt_iff_hasStrictFderivAt\n\nalias hasStrictDerivAt_iff_hasStrictFderivAt \u2194 HasStrictDerivAt.hasStrictFderivAt _\n#align has_strict_deriv_at.has_strict_fderiv_at HasStrictDerivAt.hasStrictFderivAt\n\n/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/\ntheorem hasDerivAt_iff_hasFderivAt {f' : F} :\n    HasDerivAt f f' x \u2194 HasFderivAt f (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x :=\n  Iff.rfl\n#align has_deriv_at_iff_has_fderiv_at hasDerivAt_iff_hasFderivAt\n\nalias hasDerivAt_iff_hasFderivAt \u2194 HasDerivAt.hasFderivAt _\n#align has_deriv_at.has_fderiv_at HasDerivAt.hasFderivAt\n\ntheorem derivWithin_zero_of_not_differentiableWithinAt (h : \u00acDifferentiableWithinAt \ud835\udd5c f s x) :\n    derivWithin f s x = 0 := by\n  unfold derivWithin\n  rw [fderivWithin_zero_of_not_differentiableWithinAt]\n  simp\n  assumption\n#align deriv_within_zero_of_not_differentiable_within_at derivWithin_zero_of_not_differentiableWithinAt\n\ntheorem differentiableWithinAt_of_derivWithin_ne_zero (h : derivWithin f s x \u2260 0) :\n    DifferentiableWithinAt \ud835\udd5c f s x :=\n  not_imp_comm.1 derivWithin_zero_of_not_differentiableWithinAt h\n#align differentiable_within_at_of_deriv_within_ne_zero differentiableWithinAt_of_derivWithin_ne_zero\n\ntheorem deriv_zero_of_not_differentiableAt (h : \u00acDifferentiableAt \ud835\udd5c f x) : deriv f x = 0 :=\n  by\n  unfold deriv\n  rw [fderiv_zero_of_not_differentiableAt]\n  simp\n  assumption\n#align deriv_zero_of_not_differentiable_at deriv_zero_of_not_differentiableAt\n\ntheorem differentiableAt_of_deriv_ne_zero (h : deriv f x \u2260 0) : DifferentiableAt \ud835\udd5c f x :=\n  not_imp_comm.1 deriv_zero_of_not_differentiableAt h\n#align differentiable_at_of_deriv_ne_zero differentiableAt_of_deriv_ne_zero\n\ntheorem UniqueDiffWithinAt.eq_deriv (s : Set \ud835\udd5c) (H : UniqueDiffWithinAt \ud835\udd5c s x)\n    (h : HasDerivWithinAt f f' s x) (h\u2081 : HasDerivWithinAt f f\u2081' s x) : f' = f\u2081' :=\n  smulRight_one_eq_iff.mp <| UniqueDiffWithinAt.eq H h h\u2081\n#align unique_diff_within_at.eq_deriv UniqueDiffWithinAt.eq_deriv\n\ntheorem hasDerivAtFilter_iff_isOCat :\n    HasDerivAtFilter f f' x L \u2194 (fun x' : \ud835\udd5c => f x' - f x - (x' - x) \u2022 f') =o[L] fun x' => x' - x :=\n  Iff.rfl\n#align has_deriv_at_filter_iff_is_o hasDerivAtFilter_iff_isOCat\n\ntheorem hasDerivAtFilter_iff_tendsto :\n    HasDerivAtFilter f f' x L \u2194\n      Tendsto (fun x' : \ud835\udd5c => \u2016x' - x\u2016\u207b\u00b9 * \u2016f x' - f x - (x' - x) \u2022 f'\u2016) L (\ud835\udcdd 0) :=\n  hasFderivAtFilter_iff_tendsto\n#align has_deriv_at_filter_iff_tendsto hasDerivAtFilter_iff_tendsto\n\ntheorem hasDerivWithinAt_iff_isOCat :\n    HasDerivWithinAt f f' s x \u2194\n      (fun x' : \ud835\udd5c => f x' - f x - (x' - x) \u2022 f') =o[\ud835\udcdd[s] x] fun x' => x' - x :=\n  Iff.rfl\n#align has_deriv_within_at_iff_is_o hasDerivWithinAt_iff_isOCat\n\ntheorem hasDerivWithinAt_iff_tendsto :\n    HasDerivWithinAt f f' s x \u2194\n      Tendsto (fun x' => \u2016x' - x\u2016\u207b\u00b9 * \u2016f x' - f x - (x' - x) \u2022 f'\u2016) (\ud835\udcdd[s] x) (\ud835\udcdd 0) :=\n  hasFderivAtFilter_iff_tendsto\n#align has_deriv_within_at_iff_tendsto hasDerivWithinAt_iff_tendsto\n\ntheorem hasDerivAt_iff_isOCat :\n    HasDerivAt f f' x \u2194 (fun x' : \ud835\udd5c => f x' - f x - (x' - x) \u2022 f') =o[\ud835\udcdd x] fun x' => x' - x :=\n  Iff.rfl\n#align has_deriv_at_iff_is_o hasDerivAt_iff_isOCat\n\ntheorem hasDerivAt_iff_tendsto :\n    HasDerivAt f f' x \u2194 Tendsto (fun x' => \u2016x' - x\u2016\u207b\u00b9 * \u2016f x' - f x - (x' - x) \u2022 f'\u2016) (\ud835\udcdd x) (\ud835\udcdd 0) :=\n  hasFderivAtFilter_iff_tendsto\n#align has_deriv_at_iff_tendsto hasDerivAt_iff_tendsto\n\ntheorem HasStrictDerivAt.hasDerivAt (h : HasStrictDerivAt f f' x) : HasDerivAt f f' x :=\n  h.HasFderivAt\n#align has_strict_deriv_at.has_deriv_at HasStrictDerivAt.hasDerivAt\n\n/-- If the domain has dimension one, then Fr\u00e9chet derivative is equivalent to the classical\ndefinition with a limit. In this version we have to take the limit along the subset `-{x}`,\nbecause for `y=x` the slope equals zero due to the convention `0\u207b\u00b9=0`. -/\ntheorem hasDerivAtFilter_iff_tendsto_slope {x : \ud835\udd5c} {L : Filter \ud835\udd5c} :\n    HasDerivAtFilter f f' x L \u2194 Tendsto (slope f x) (L \u2293 \ud835\udcdf ({x}\u1d9c)) (\ud835\udcdd f') :=\n  by\n  conv_lhs =>\n    simp only [hasDerivAtFilter_iff_tendsto, (norm_inv _).symm, (norm_smul _ _).symm,\n      tendsto_zero_iff_norm_tendsto_zero.symm]\n  conv_rhs => rw [\u2190 nhds_translation_sub f', tendsto_comap_iff]\n  refine' (tendsto_inf_principal_nhds_iff_of_forall_eq <| by simp).symm.trans (tendsto_congr' _)\n  refine' (eventually_principal.2 fun z hz => _).filter_mono inf_le_right\n  simp only [(\u00b7 \u2218 \u00b7)]\n  rw [smul_sub, \u2190 mul_smul, inv_mul_cancel (sub_ne_zero.2 hz), one_smul, slope_def_module]\n#align has_deriv_at_filter_iff_tendsto_slope hasDerivAtFilter_iff_tendsto_slope\n\ntheorem hasDerivWithinAt_iff_tendsto_slope :\n    HasDerivWithinAt f f' s x \u2194 Tendsto (slope f x) (\ud835\udcdd[s \\ {x}] x) (\ud835\udcdd f') :=\n  by\n  simp only [HasDerivWithinAt, nhdsWithin, diff_eq, inf_assoc.symm, inf_principal.symm]\n  exact hasDerivAtFilter_iff_tendsto_slope\n#align has_deriv_within_at_iff_tendsto_slope hasDerivWithinAt_iff_tendsto_slope\n\ntheorem hasDerivWithinAt_iff_tendsto_slope' (hs : x \u2209 s) :\n    HasDerivWithinAt f f' s x \u2194 Tendsto (slope f x) (\ud835\udcdd[s] x) (\ud835\udcdd f') :=\n  by\n  convert\u2190 hasDerivWithinAt_iff_tendsto_slope\n  exact diff_singleton_eq_self hs\n#align has_deriv_within_at_iff_tendsto_slope' hasDerivWithinAt_iff_tendsto_slope'\n\ntheorem hasDerivAt_iff_tendsto_slope : HasDerivAt f f' x \u2194 Tendsto (slope f x) (\ud835\udcdd[\u2260] x) (\ud835\udcdd f') :=\n  hasDerivAtFilter_iff_tendsto_slope\n#align has_deriv_at_iff_tendsto_slope hasDerivAt_iff_tendsto_slope\n\ntheorem hasDerivWithinAt_congr_set {s t u : Set \ud835\udd5c} (hu : u \u2208 \ud835\udcdd x) (h : s \u2229 u = t \u2229 u) :\n    HasDerivWithinAt f f' s x \u2194 HasDerivWithinAt f f' t x := by\n  simp_rw [HasDerivWithinAt, nhdsWithin_eq_nhds_within' hu h]\n#align has_deriv_within_at_congr_set hasDerivWithinAt_congr_set\n\nalias hasDerivWithinAt_congr_set \u2194 HasDerivWithinAt.congr_set _\n#align has_deriv_within_at.congr_set HasDerivWithinAt.congr_set\n\n@[simp]\ntheorem hasDerivWithinAt_diff_singleton :\n    HasDerivWithinAt f f' (s \\ {x}) x \u2194 HasDerivWithinAt f f' s x := by\n  simp only [hasDerivWithinAt_iff_tendsto_slope, sdiff_idem]\n#align has_deriv_within_at_diff_singleton hasDerivWithinAt_diff_singleton\n\n@[simp]\ntheorem hasDerivWithinAt_Ioi_iff_Ici [PartialOrder \ud835\udd5c] :\n    HasDerivWithinAt f f' (Ioi x) x \u2194 HasDerivWithinAt f f' (Ici x) x := by\n  rw [\u2190 Ici_diff_left, hasDerivWithinAt_diff_singleton]\n#align has_deriv_within_at_Ioi_iff_Ici hasDerivWithinAt_Ioi_iff_Ici\n\nalias hasDerivWithinAt_Ioi_iff_Ici \u2194 HasDerivWithinAt.Ici_of_Ioi HasDerivWithinAt.Ioi_of_Ici\n#align has_deriv_within_at.Ici_of_Ioi HasDerivWithinAt.Ici_of_Ioi\n#align has_deriv_within_at.Ioi_of_Ici HasDerivWithinAt.Ioi_of_Ici\n\n@[simp]\ntheorem hasDerivWithinAt_Iio_iff_Iic [PartialOrder \ud835\udd5c] :\n    HasDerivWithinAt f f' (Iio x) x \u2194 HasDerivWithinAt f f' (Iic x) x := by\n  rw [\u2190 Iic_diff_right, hasDerivWithinAt_diff_singleton]\n#align has_deriv_within_at_Iio_iff_Iic hasDerivWithinAt_Iio_iff_Iic\n\nalias hasDerivWithinAt_Iio_iff_Iic \u2194 HasDerivWithinAt.Iic_of_Iio HasDerivWithinAt.Iio_of_Iic\n#align has_deriv_within_at.Iic_of_Iio HasDerivWithinAt.Iic_of_Iio\n#align has_deriv_within_at.Iio_of_Iic HasDerivWithinAt.Iio_of_Iic\n\ntheorem HasDerivWithinAt.Ioi_iff_Ioo [LinearOrder \ud835\udd5c] [OrderClosedTopology \ud835\udd5c] {x y : \ud835\udd5c} (h : x < y) :\n    HasDerivWithinAt f f' (Ioo x y) x \u2194 HasDerivWithinAt f f' (Ioi x) x :=\n  hasDerivWithinAt_congr_set (isOpen_Iio.mem_nhds h) <|\n    by\n    rw [Ioi_inter_Iio, inter_eq_left_iff_subset]\n    exact Ioo_subset_Iio_self\n#align has_deriv_within_at.Ioi_iff_Ioo HasDerivWithinAt.Ioi_iff_Ioo\n\nalias HasDerivWithinAt.Ioi_iff_Ioo \u2194 HasDerivWithinAt.Ioi_of_Ioo HasDerivWithinAt.Ioo_of_Ioi\n#align has_deriv_within_at.Ioi_of_Ioo HasDerivWithinAt.Ioi_of_Ioo\n#align has_deriv_within_at.Ioo_of_Ioi HasDerivWithinAt.Ioo_of_Ioi\n\ntheorem hasDerivAt_iff_isOCat_nhds_zero :\n    HasDerivAt f f' x \u2194 (fun h => f (x + h) - f x - h \u2022 f') =o[\ud835\udcdd 0] fun h => h :=\n  hasFderivAt_iff_isOCat_nhds_zero\n#align has_deriv_at_iff_is_o_nhds_zero hasDerivAt_iff_isOCat_nhds_zero\n\ntheorem HasDerivAtFilter.mono (h : HasDerivAtFilter f f' x L\u2082) (hst : L\u2081 \u2264 L\u2082) :\n    HasDerivAtFilter f f' x L\u2081 :=\n  HasFderivAtFilter.mono h hst\n#align has_deriv_at_filter.mono HasDerivAtFilter.mono\n\ntheorem HasDerivWithinAt.mono (h : HasDerivWithinAt f f' t x) (hst : s \u2286 t) :\n    HasDerivWithinAt f f' s x :=\n  HasFderivWithinAt.mono h hst\n#align has_deriv_within_at.mono HasDerivWithinAt.mono\n\ntheorem HasDerivAt.hasDerivAtFilter (h : HasDerivAt f f' x) (hL : L \u2264 \ud835\udcdd x) :\n    HasDerivAtFilter f f' x L :=\n  HasFderivAt.hasFderivAtFilter h hL\n#align has_deriv_at.has_deriv_at_filter HasDerivAt.hasDerivAtFilter\n\ntheorem HasDerivAt.hasDerivWithinAt (h : HasDerivAt f f' x) : HasDerivWithinAt f f' s x :=\n  HasFderivAt.hasFderivWithinAt h\n#align has_deriv_at.has_deriv_within_at HasDerivAt.hasDerivWithinAt\n\ntheorem HasDerivWithinAt.differentiableWithinAt (h : HasDerivWithinAt f f' s x) :\n    DifferentiableWithinAt \ud835\udd5c f s x :=\n  HasFderivWithinAt.differentiableWithinAt h\n#align has_deriv_within_at.differentiable_within_at HasDerivWithinAt.differentiableWithinAt\n\ntheorem HasDerivAt.differentiableAt (h : HasDerivAt f f' x) : DifferentiableAt \ud835\udd5c f x :=\n  HasFderivAt.differentiableAt h\n#align has_deriv_at.differentiable_at HasDerivAt.differentiableAt\n\n@[simp]\ntheorem hasDerivWithinAt_univ : HasDerivWithinAt f f' univ x \u2194 HasDerivAt f f' x :=\n  hasFderivWithinAt_univ\n#align has_deriv_within_at_univ hasDerivWithinAt_univ\n\ntheorem HasDerivAt.unique (h\u2080 : HasDerivAt f f\u2080' x) (h\u2081 : HasDerivAt f f\u2081' x) : f\u2080' = f\u2081' :=\n  smulRight_one_eq_iff.mp <| h\u2080.HasFderivAt.unique h\u2081\n#align has_deriv_at.unique HasDerivAt.unique\n\ntheorem hasDerivWithinAt_inter' (h : t \u2208 \ud835\udcdd[s] x) :\n    HasDerivWithinAt f f' (s \u2229 t) x \u2194 HasDerivWithinAt f f' s x :=\n  hasFderivWithinAt_inter' h\n#align has_deriv_within_at_inter' hasDerivWithinAt_inter'\n\ntheorem hasDerivWithinAt_inter (h : t \u2208 \ud835\udcdd x) :\n    HasDerivWithinAt f f' (s \u2229 t) x \u2194 HasDerivWithinAt f f' s x :=\n  hasFderivWithinAt_inter h\n#align has_deriv_within_at_inter hasDerivWithinAt_inter\n\ntheorem HasDerivWithinAt.union (hs : HasDerivWithinAt f f' s x) (ht : HasDerivWithinAt f f' t x) :\n    HasDerivWithinAt f f' (s \u222a t) x :=\n  hs.HasFderivWithinAt.union ht.HasFderivWithinAt\n#align has_deriv_within_at.union HasDerivWithinAt.union\n\ntheorem HasDerivWithinAt.nhdsWithin (h : HasDerivWithinAt f f' s x) (ht : s \u2208 \ud835\udcdd[t] x) :\n    HasDerivWithinAt f f' t x :=\n  (hasDerivWithinAt_inter' ht).1 (h.mono (inter_subset_right _ _))\n#align has_deriv_within_at.nhds_within HasDerivWithinAt.nhdsWithin\n\ntheorem HasDerivWithinAt.hasDerivAt (h : HasDerivWithinAt f f' s x) (hs : s \u2208 \ud835\udcdd x) :\n    HasDerivAt f f' x :=\n  HasFderivWithinAt.hasFderivAt h hs\n#align has_deriv_within_at.has_deriv_at HasDerivWithinAt.hasDerivAt\n\ntheorem DifferentiableWithinAt.hasDerivWithinAt (h : DifferentiableWithinAt \ud835\udd5c f s x) :\n    HasDerivWithinAt f (derivWithin f s x) s x :=\n  h.HasFderivWithinAt.HasDerivWithinAt\n#align differentiable_within_at.has_deriv_within_at DifferentiableWithinAt.hasDerivWithinAt\n\ntheorem DifferentiableAt.hasDerivAt (h : DifferentiableAt \ud835\udd5c f x) : HasDerivAt f (deriv f x) x :=\n  h.HasFderivAt.HasDerivAt\n#align differentiable_at.has_deriv_at DifferentiableAt.hasDerivAt\n\n@[simp]\ntheorem hasDerivAt_deriv_iff : HasDerivAt f (deriv f x) x \u2194 DifferentiableAt \ud835\udd5c f x :=\n  \u27e8fun h => h.DifferentiableAt, fun h => h.HasDerivAt\u27e9\n#align has_deriv_at_deriv_iff hasDerivAt_deriv_iff\n\n@[simp]\ntheorem hasDerivWithinAt_derivWithin_iff :\n    HasDerivWithinAt f (derivWithin f s x) s x \u2194 DifferentiableWithinAt \ud835\udd5c f s x :=\n  \u27e8fun h => h.DifferentiableWithinAt, fun h => h.HasDerivWithinAt\u27e9\n#align has_deriv_within_at_deriv_within_iff hasDerivWithinAt_derivWithin_iff\n\ntheorem DifferentiableOn.hasDerivAt (h : DifferentiableOn \ud835\udd5c f s) (hs : s \u2208 \ud835\udcdd x) :\n    HasDerivAt f (deriv f x) x :=\n  (h.HasFderivAt hs).HasDerivAt\n#align differentiable_on.has_deriv_at DifferentiableOn.hasDerivAt\n\ntheorem HasDerivAt.deriv (h : HasDerivAt f f' x) : deriv f x = f' :=\n  h.DifferentiableAt.HasDerivAt.unique h\n#align has_deriv_at.deriv HasDerivAt.deriv\n\ntheorem deriv_eq {f' : \ud835\udd5c \u2192 F} (h : \u2200 x, HasDerivAt f (f' x) x) : deriv f = f' :=\n  funext fun x => (h x).deriv\n#align deriv_eq deriv_eq\n\ntheorem HasDerivWithinAt.derivWithin (h : HasDerivWithinAt f f' s x)\n    (hxs : UniqueDiffWithinAt \ud835\udd5c s x) : derivWithin f s x = f' :=\n  hxs.eq_deriv _ h.DifferentiableWithinAt.HasDerivWithinAt h\n#align has_deriv_within_at.deriv_within HasDerivWithinAt.derivWithin\n\ntheorem fderivWithin_derivWithin : (fderivWithin \ud835\udd5c f s x : \ud835\udd5c \u2192 F) 1 = derivWithin f s x :=\n  rfl\n#align fderiv_within_deriv_within fderivWithin_derivWithin\n\ntheorem derivWithin_fderivWithin :\n    smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (derivWithin f s x) = fderivWithin \ud835\udd5c f s x := by simp [derivWithin]\n#align deriv_within_fderiv_within derivWithin_fderivWithin\n\ntheorem fderiv_deriv : (fderiv \ud835\udd5c f x : \ud835\udd5c \u2192 F) 1 = deriv f x :=\n  rfl\n#align fderiv_deriv fderiv_deriv\n\ntheorem deriv_fderiv : smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (deriv f x) = fderiv \ud835\udd5c f x := by simp [deriv]\n#align deriv_fderiv deriv_fderiv\n\ntheorem DifferentiableAt.derivWithin (h : DifferentiableAt \ud835\udd5c f x) (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin f s x = deriv f x := by\n  unfold derivWithin deriv\n  rw [h.fderiv_within hxs]\n#align differentiable_at.deriv_within DifferentiableAt.derivWithin\n\ntheorem HasDerivWithinAt.deriv_eq_zero (hd : HasDerivWithinAt f 0 s x)\n    (H : UniqueDiffWithinAt \ud835\udd5c s x) : deriv f x = 0 :=\n  (em' (DifferentiableAt \ud835\udd5c f x)).elim deriv_zero_of_not_differentiableAt fun h =>\n    H.eq_deriv _ h.HasDerivAt.HasDerivWithinAt hd\n#align has_deriv_within_at.deriv_eq_zero HasDerivWithinAt.deriv_eq_zero\n\ntheorem derivWithin_subset (st : s \u2286 t) (ht : UniqueDiffWithinAt \ud835\udd5c s x)\n    (h : DifferentiableWithinAt \ud835\udd5c f t x) : derivWithin f s x = derivWithin f t x :=\n  ((DifferentiableWithinAt.hasDerivWithinAt h).mono st).derivWithin ht\n#align deriv_within_subset derivWithin_subset\n\n@[simp]\ntheorem derivWithin_univ : derivWithin f univ = deriv f :=\n  by\n  ext\n  unfold derivWithin deriv\n  rw [fderivWithin_univ]\n#align deriv_within_univ derivWithin_univ\n\ntheorem derivWithin_inter (ht : t \u2208 \ud835\udcdd x) (hs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin f (s \u2229 t) x = derivWithin f s x :=\n  by\n  unfold derivWithin\n  rw [fderivWithin_inter ht hs]\n#align deriv_within_inter derivWithin_inter\n\ntheorem derivWithin_of_open (hs : IsOpen s) (hx : x \u2208 s) : derivWithin f s x = deriv f x :=\n  by\n  unfold derivWithin\n  rw [fderivWithin_of_open hs hx]\n  rfl\n#align deriv_within_of_open derivWithin_of_open\n\ntheorem deriv_mem_iff {f : \ud835\udd5c \u2192 F} {s : Set F} {x : \ud835\udd5c} :\n    deriv f x \u2208 s \u2194\n      DifferentiableAt \ud835\udd5c f x \u2227 deriv f x \u2208 s \u2228 \u00acDifferentiableAt \ud835\udd5c f x \u2227 (0 : F) \u2208 s :=\n  by by_cases hx : DifferentiableAt \ud835\udd5c f x <;> simp [deriv_zero_of_not_differentiableAt, *]\n#align deriv_mem_iff deriv_mem_iff\n\ntheorem derivWithin_mem_iff {f : \ud835\udd5c \u2192 F} {t : Set \ud835\udd5c} {s : Set F} {x : \ud835\udd5c} :\n    derivWithin f t x \u2208 s \u2194\n      DifferentiableWithinAt \ud835\udd5c f t x \u2227 derivWithin f t x \u2208 s \u2228\n        \u00acDifferentiableWithinAt \ud835\udd5c f t x \u2227 (0 : F) \u2208 s :=\n  by\n  by_cases hx : DifferentiableWithinAt \ud835\udd5c f t x <;>\n    simp [derivWithin_zero_of_not_differentiableWithinAt, *]\n#align deriv_within_mem_iff derivWithin_mem_iff\n\ntheorem differentiableWithinAt_Ioi_iff_Ici [PartialOrder \ud835\udd5c] :\n    DifferentiableWithinAt \ud835\udd5c f (Ioi x) x \u2194 DifferentiableWithinAt \ud835\udd5c f (Ici x) x :=\n  \u27e8fun h => h.HasDerivWithinAt.Ici_of_Ioi.DifferentiableWithinAt, fun h =>\n    h.HasDerivWithinAt.Ioi_of_Ici.DifferentiableWithinAt\u27e9\n#align differentiable_within_at_Ioi_iff_Ici differentiableWithinAt_Ioi_iff_Ici\n\ntheorem derivWithin_Ioi_eq_Ici {E : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] (f : \u211d \u2192 E)\n    (x : \u211d) : derivWithin f (Ioi x) x = derivWithin f (Ici x) x :=\n  by\n  by_cases H : DifferentiableWithinAt \u211d f (Ioi x) x\n  \u00b7 have A := H.has_deriv_within_at.Ici_of_Ioi\n    have B := (differentiableWithinAt_Ioi_iff_Ici.1 H).HasDerivWithinAt\n    simpa using (uniqueDiffOn_Ici x).Eq le_rfl A B\n  \u00b7 rw [derivWithin_zero_of_not_differentiableWithinAt H,\n      derivWithin_zero_of_not_differentiableWithinAt]\n    rwa [differentiableWithinAt_Ioi_iff_Ici] at H\n#align deriv_within_Ioi_eq_Ici derivWithin_Ioi_eq_Ici\n\nsection congr\n\n/-! ### Congruence properties of derivatives -/\n\n\ntheorem Filter.EventuallyEq.hasDerivAtFilter_iff (h\u2080 : f\u2080 =\u1da0[L] f\u2081) (hx : f\u2080 x = f\u2081 x)\n    (h\u2081 : f\u2080' = f\u2081') : HasDerivAtFilter f\u2080 f\u2080' x L \u2194 HasDerivAtFilter f\u2081 f\u2081' x L :=\n  h\u2080.hasFderivAtFilter_iff hx (by simp [h\u2081])\n#align filter.eventually_eq.has_deriv_at_filter_iff Filter.EventuallyEq.hasDerivAtFilter_iff\n\ntheorem HasDerivAtFilter.congr_of_eventuallyEq (h : HasDerivAtFilter f f' x L) (hL : f\u2081 =\u1da0[L] f)\n    (hx : f\u2081 x = f x) : HasDerivAtFilter f\u2081 f' x L := by rwa [hL.has_deriv_at_filter_iff hx rfl]\n#align has_deriv_at_filter.congr_of_eventually_eq HasDerivAtFilter.congr_of_eventuallyEq\n\ntheorem HasDerivWithinAt.congr_mono (h : HasDerivWithinAt f f' s x) (ht : \u2200 x \u2208 t, f\u2081 x = f x)\n    (hx : f\u2081 x = f x) (h\u2081 : t \u2286 s) : HasDerivWithinAt f\u2081 f' t x :=\n  HasFderivWithinAt.congr_mono h ht hx h\u2081\n#align has_deriv_within_at.congr_mono HasDerivWithinAt.congr_mono\n\ntheorem HasDerivWithinAt.congr (h : HasDerivWithinAt f f' s x) (hs : \u2200 x \u2208 s, f\u2081 x = f x)\n    (hx : f\u2081 x = f x) : HasDerivWithinAt f\u2081 f' s x :=\n  h.congr_mono hs hx (Subset.refl _)\n#align has_deriv_within_at.congr HasDerivWithinAt.congr\n\ntheorem HasDerivWithinAt.congr_of_mem (h : HasDerivWithinAt f f' s x) (hs : \u2200 x \u2208 s, f\u2081 x = f x)\n    (hx : x \u2208 s) : HasDerivWithinAt f\u2081 f' s x :=\n  h.congr hs (hs _ hx)\n#align has_deriv_within_at.congr_of_mem HasDerivWithinAt.congr_of_mem\n\ntheorem HasDerivWithinAt.congr_of_eventuallyEq (h : HasDerivWithinAt f f' s x)\n    (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : f\u2081 x = f x) : HasDerivWithinAt f\u2081 f' s x :=\n  HasDerivAtFilter.congr_of_eventuallyEq h h\u2081 hx\n#align has_deriv_within_at.congr_of_eventually_eq HasDerivWithinAt.congr_of_eventuallyEq\n\ntheorem HasDerivWithinAt.congr_of_eventuallyEq_of_mem (h : HasDerivWithinAt f f' s x)\n    (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : x \u2208 s) : HasDerivWithinAt f\u2081 f' s x :=\n  h.congr_of_eventuallyEq h\u2081 (h\u2081.eq_of_nhdsWithin hx)\n#align has_deriv_within_at.congr_of_eventually_eq_of_mem HasDerivWithinAt.congr_of_eventuallyEq_of_mem\n\ntheorem HasDerivAt.congr_of_eventuallyEq (h : HasDerivAt f f' x) (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd x] f) :\n    HasDerivAt f\u2081 f' x :=\n  HasDerivAtFilter.congr_of_eventuallyEq h h\u2081 (mem_of_mem_nhds h\u2081 : _)\n#align has_deriv_at.congr_of_eventually_eq HasDerivAt.congr_of_eventuallyEq\n\ntheorem Filter.EventuallyEq.derivWithin_eq (hs : UniqueDiffWithinAt \ud835\udd5c s x) (hL : f\u2081 =\u1da0[\ud835\udcdd[s] x] f)\n    (hx : f\u2081 x = f x) : derivWithin f\u2081 s x = derivWithin f s x :=\n  by\n  unfold derivWithin\n  rw [hL.fderiv_within_eq hs hx]\n#align filter.eventually_eq.deriv_within_eq Filter.EventuallyEq.derivWithin_eq\n\ntheorem derivWithin_congr (hs : UniqueDiffWithinAt \ud835\udd5c s x) (hL : \u2200 y \u2208 s, f\u2081 y = f y)\n    (hx : f\u2081 x = f x) : derivWithin f\u2081 s x = derivWithin f s x :=\n  by\n  unfold derivWithin\n  rw [fderivWithin_congr hs hL hx]\n#align deriv_within_congr derivWithin_congr\n\ntheorem Filter.EventuallyEq.deriv_eq (hL : f\u2081 =\u1da0[\ud835\udcdd x] f) : deriv f\u2081 x = deriv f x :=\n  by\n  unfold deriv\n  rwa [Filter.EventuallyEq.fderiv_eq]\n#align filter.eventually_eq.deriv_eq Filter.EventuallyEq.deriv_eq\n\nprotected theorem Filter.EventuallyEq.deriv (h : f\u2081 =\u1da0[\ud835\udcdd x] f) : deriv f\u2081 =\u1da0[\ud835\udcdd x] deriv f :=\n  h.eventuallyEq_nhds.mono fun x h => h.deriv_eq\n#align filter.eventually_eq.deriv Filter.EventuallyEq.deriv\n\nend congr\n\nsection id\n\n/-! ### Derivative of the identity -/\n\n\nvariable (s x L)\n\ntheorem hasDerivAtFilter_id : HasDerivAtFilter id 1 x L :=\n  (hasFderivAtFilter_id x L).HasDerivAtFilter\n#align has_deriv_at_filter_id hasDerivAtFilter_id\n\ntheorem hasDerivWithinAt_id : HasDerivWithinAt id 1 s x :=\n  hasDerivAtFilter_id _ _\n#align has_deriv_within_at_id hasDerivWithinAt_id\n\ntheorem hasDerivAt_id : HasDerivAt id 1 x :=\n  hasDerivAtFilter_id _ _\n#align has_deriv_at_id hasDerivAt_id\n\ntheorem hasDerivAt_id' : HasDerivAt (fun x : \ud835\udd5c => x) 1 x :=\n  hasDerivAtFilter_id _ _\n#align has_deriv_at_id' hasDerivAt_id'\n\ntheorem hasStrictDerivAt_id : HasStrictDerivAt id 1 x :=\n  (hasStrictFderivAt_id x).HasStrictDerivAt\n#align has_strict_deriv_at_id hasStrictDerivAt_id\n\ntheorem deriv_id : deriv id x = 1 :=\n  HasDerivAt.deriv (hasDerivAt_id x)\n#align deriv_id deriv_id\n\n@[simp]\ntheorem deriv_id' : deriv (@id \ud835\udd5c) = fun _ => 1 :=\n  funext deriv_id\n#align deriv_id' deriv_id'\n\n@[simp]\ntheorem deriv_id'' : (deriv fun x : \ud835\udd5c => x) = fun _ => 1 :=\n  deriv_id'\n#align deriv_id'' deriv_id''\n\ntheorem derivWithin_id (hxs : UniqueDiffWithinAt \ud835\udd5c s x) : derivWithin id s x = 1 :=\n  (hasDerivWithinAt_id x s).derivWithin hxs\n#align deriv_within_id derivWithin_id\n\nend id\n\nsection Const\n\n/-! ### Derivative of constant functions -/\n\n\nvariable (c : F) (s x L)\n\ntheorem hasDerivAtFilter_const : HasDerivAtFilter (fun x => c) 0 x L :=\n  (hasFderivAtFilter_const c x L).HasDerivAtFilter\n#align has_deriv_at_filter_const hasDerivAtFilter_const\n\ntheorem hasStrictDerivAt_const : HasStrictDerivAt (fun x => c) 0 x :=\n  (hasStrictFderivAt_const c x).HasStrictDerivAt\n#align has_strict_deriv_at_const hasStrictDerivAt_const\n\ntheorem hasDerivWithinAt_const : HasDerivWithinAt (fun x => c) 0 s x :=\n  hasDerivAtFilter_const _ _ _\n#align has_deriv_within_at_const hasDerivWithinAt_const\n\ntheorem hasDerivAt_const : HasDerivAt (fun x => c) 0 x :=\n  hasDerivAtFilter_const _ _ _\n#align has_deriv_at_const hasDerivAt_const\n\ntheorem deriv_const : deriv (fun x => c) x = 0 :=\n  HasDerivAt.deriv (hasDerivAt_const x c)\n#align deriv_const deriv_const\n\n@[simp]\ntheorem deriv_const' : (deriv fun x : \ud835\udd5c => c) = fun x => 0 :=\n  funext fun x => deriv_const x c\n#align deriv_const' deriv_const'\n\ntheorem derivWithin_const (hxs : UniqueDiffWithinAt \ud835\udd5c s x) : derivWithin (fun x => c) s x = 0 :=\n  (hasDerivWithinAt_const _ _ _).derivWithin hxs\n#align deriv_within_const derivWithin_const\n\nend Const\n\nsection ContinuousLinearMap\n\n/-! ### Derivative of continuous linear maps -/\n\n\nvariable (e : \ud835\udd5c \u2192L[\ud835\udd5c] F)\n\nprotected theorem ContinuousLinearMap.hasDerivAtFilter : HasDerivAtFilter e (e 1) x L :=\n  e.HasFderivAtFilter.HasDerivAtFilter\n#align continuous_linear_map.has_deriv_at_filter ContinuousLinearMap.hasDerivAtFilter\n\nprotected theorem ContinuousLinearMap.hasStrictDerivAt : HasStrictDerivAt e (e 1) x :=\n  e.HasStrictFderivAt.HasStrictDerivAt\n#align continuous_linear_map.has_strict_deriv_at ContinuousLinearMap.hasStrictDerivAt\n\nprotected theorem ContinuousLinearMap.hasDerivAt : HasDerivAt e (e 1) x :=\n  e.HasDerivAtFilter\n#align continuous_linear_map.has_deriv_at ContinuousLinearMap.hasDerivAt\n\nprotected theorem ContinuousLinearMap.hasDerivWithinAt : HasDerivWithinAt e (e 1) s x :=\n  e.HasDerivAtFilter\n#align continuous_linear_map.has_deriv_within_at ContinuousLinearMap.hasDerivWithinAt\n\n@[simp]\nprotected theorem ContinuousLinearMap.deriv : deriv e x = e 1 :=\n  e.HasDerivAt.deriv\n#align continuous_linear_map.deriv ContinuousLinearMap.deriv\n\nprotected theorem ContinuousLinearMap.derivWithin (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin e s x = e 1 :=\n  e.HasDerivWithinAt.derivWithin hxs\n#align continuous_linear_map.deriv_within ContinuousLinearMap.derivWithin\n\nend ContinuousLinearMap\n\nsection LinearMap\n\n/-! ### Derivative of bundled linear maps -/\n\n\nvariable (e : \ud835\udd5c \u2192\u2097[\ud835\udd5c] F)\n\nprotected theorem LinearMap.hasDerivAtFilter : HasDerivAtFilter e (e 1) x L :=\n  e.toContinuousLinearMap\u2081.HasDerivAtFilter\n#align linear_map.has_deriv_at_filter LinearMap.hasDerivAtFilter\n\nprotected theorem LinearMap.hasStrictDerivAt : HasStrictDerivAt e (e 1) x :=\n  e.toContinuousLinearMap\u2081.HasStrictDerivAt\n#align linear_map.has_strict_deriv_at LinearMap.hasStrictDerivAt\n\nprotected theorem LinearMap.hasDerivAt : HasDerivAt e (e 1) x :=\n  e.HasDerivAtFilter\n#align linear_map.has_deriv_at LinearMap.hasDerivAt\n\nprotected theorem LinearMap.hasDerivWithinAt : HasDerivWithinAt e (e 1) s x :=\n  e.HasDerivAtFilter\n#align linear_map.has_deriv_within_at LinearMap.hasDerivWithinAt\n\n@[simp]\nprotected theorem LinearMap.deriv : deriv e x = e 1 :=\n  e.HasDerivAt.deriv\n#align linear_map.deriv LinearMap.deriv\n\nprotected theorem LinearMap.derivWithin (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin e s x = e 1 :=\n  e.HasDerivWithinAt.derivWithin hxs\n#align linear_map.deriv_within LinearMap.derivWithin\n\nend LinearMap\n\nsection Add\n\n/-! ### Derivative of the sum of two functions -/\n\n\ntheorem HasDerivAtFilter.add (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) :\n    HasDerivAtFilter (fun y => f y + g y) (f' + g') x L := by\n  simpa using (hf.add hg).HasDerivAtFilter\n#align has_deriv_at_filter.add HasDerivAtFilter.add\n\ntheorem HasStrictDerivAt.add (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) :\n    HasStrictDerivAt (fun y => f y + g y) (f' + g') x := by simpa using (hf.add hg).HasStrictDerivAt\n#align has_strict_deriv_at.add HasStrictDerivAt.add\n\ntheorem HasDerivWithinAt.add (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) :\n    HasDerivWithinAt (fun y => f y + g y) (f' + g') s x :=\n  hf.add hg\n#align has_deriv_within_at.add HasDerivWithinAt.add\n\ntheorem HasDerivAt.add (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) :\n    HasDerivAt (fun x => f x + g x) (f' + g') x :=\n  hf.add hg\n#align has_deriv_at.add HasDerivAt.add\n\ntheorem derivWithin_add (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (hf : DifferentiableWithinAt \ud835\udd5c f s x)\n    (hg : DifferentiableWithinAt \ud835\udd5c g s x) :\n    derivWithin (fun y => f y + g y) s x = derivWithin f s x + derivWithin g s x :=\n  (hf.HasDerivWithinAt.add hg.HasDerivWithinAt).derivWithin hxs\n#align deriv_within_add derivWithin_add\n\n@[simp]\ntheorem deriv_add (hf : DifferentiableAt \ud835\udd5c f x) (hg : DifferentiableAt \ud835\udd5c g x) :\n    deriv (fun y => f y + g y) x = deriv f x + deriv g x :=\n  (hf.HasDerivAt.add hg.HasDerivAt).deriv\n#align deriv_add deriv_add\n\ntheorem HasDerivAtFilter.add_const (hf : HasDerivAtFilter f f' x L) (c : F) :\n    HasDerivAtFilter (fun y => f y + c) f' x L :=\n  add_zero f' \u25b8 hf.add (hasDerivAtFilter_const x L c)\n#align has_deriv_at_filter.add_const HasDerivAtFilter.add_const\n\ntheorem HasDerivWithinAt.add_const (hf : HasDerivWithinAt f f' s x) (c : F) :\n    HasDerivWithinAt (fun y => f y + c) f' s x :=\n  hf.AddConst c\n#align has_deriv_within_at.add_const HasDerivWithinAt.add_const\n\ntheorem HasDerivAt.add_const (hf : HasDerivAt f f' x) (c : F) :\n    HasDerivAt (fun x => f x + c) f' x :=\n  hf.AddConst c\n#align has_deriv_at.add_const HasDerivAt.add_const\n\ntheorem derivWithin_add_const (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (c : F) :\n    derivWithin (fun y => f y + c) s x = derivWithin f s x := by\n  simp only [derivWithin, fderivWithin_add_const hxs]\n#align deriv_within_add_const derivWithin_add_const\n\ntheorem deriv_add_const (c : F) : deriv (fun y => f y + c) x = deriv f x := by\n  simp only [deriv, fderiv_add_const]\n#align deriv_add_const deriv_add_const\n\n@[simp]\ntheorem deriv_add_const' (c : F) : (deriv fun y => f y + c) = deriv f :=\n  funext fun x => deriv_add_const c\n#align deriv_add_const' deriv_add_const'\n\ntheorem HasDerivAtFilter.const_add (c : F) (hf : HasDerivAtFilter f f' x L) :\n    HasDerivAtFilter (fun y => c + f y) f' x L :=\n  zero_add f' \u25b8 (hasDerivAtFilter_const x L c).add hf\n#align has_deriv_at_filter.const_add HasDerivAtFilter.const_add\n\ntheorem HasDerivWithinAt.const_add (c : F) (hf : HasDerivWithinAt f f' s x) :\n    HasDerivWithinAt (fun y => c + f y) f' s x :=\n  hf.const_add c\n#align has_deriv_within_at.const_add HasDerivWithinAt.const_add\n\ntheorem HasDerivAt.const_add (c : F) (hf : HasDerivAt f f' x) :\n    HasDerivAt (fun x => c + f x) f' x :=\n  hf.const_add c\n#align has_deriv_at.const_add HasDerivAt.const_add\n\ntheorem derivWithin_const_add (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (c : F) :\n    derivWithin (fun y => c + f y) s x = derivWithin f s x := by\n  simp only [derivWithin, fderivWithin_const_add hxs]\n#align deriv_within_const_add derivWithin_const_add\n\ntheorem deriv_const_add (c : F) : deriv (fun y => c + f y) x = deriv f x := by\n  simp only [deriv, fderiv_const_add]\n#align deriv_const_add deriv_const_add\n\n@[simp]\ntheorem deriv_const_add' (c : F) : (deriv fun y => c + f y) = deriv f :=\n  funext fun x => deriv_const_add c\n#align deriv_const_add' deriv_const_add'\n\nend Add\n\nsection Sum\n\n/-! ### Derivative of a finite sum of functions -/\n\n\nopen BigOperators\n\nvariable {\u03b9 : Type _} {u : Finset \u03b9} {A : \u03b9 \u2192 \ud835\udd5c \u2192 F} {A' : \u03b9 \u2192 F}\n\ntheorem HasDerivAtFilter.sum (h : \u2200 i \u2208 u, HasDerivAtFilter (A i) (A' i) x L) :\n    HasDerivAtFilter (fun y => \u2211 i in u, A i y) (\u2211 i in u, A' i) x L := by\n  simpa [ContinuousLinearMap.sum_apply] using (HasFderivAtFilter.sum h).HasDerivAtFilter\n#align has_deriv_at_filter.sum HasDerivAtFilter.sum\n\ntheorem HasStrictDerivAt.sum (h : \u2200 i \u2208 u, HasStrictDerivAt (A i) (A' i) x) :\n    HasStrictDerivAt (fun y => \u2211 i in u, A i y) (\u2211 i in u, A' i) x := by\n  simpa [ContinuousLinearMap.sum_apply] using (HasStrictFderivAt.sum h).HasStrictDerivAt\n#align has_strict_deriv_at.sum HasStrictDerivAt.sum\n\ntheorem HasDerivWithinAt.sum (h : \u2200 i \u2208 u, HasDerivWithinAt (A i) (A' i) s x) :\n    HasDerivWithinAt (fun y => \u2211 i in u, A i y) (\u2211 i in u, A' i) s x :=\n  HasDerivAtFilter.sum h\n#align has_deriv_within_at.sum HasDerivWithinAt.sum\n\ntheorem HasDerivAt.sum (h : \u2200 i \u2208 u, HasDerivAt (A i) (A' i) x) :\n    HasDerivAt (fun y => \u2211 i in u, A i y) (\u2211 i in u, A' i) x :=\n  HasDerivAtFilter.sum h\n#align has_deriv_at.sum HasDerivAt.sum\n\ntheorem derivWithin_sum (hxs : UniqueDiffWithinAt \ud835\udd5c s x)\n    (h : \u2200 i \u2208 u, DifferentiableWithinAt \ud835\udd5c (A i) s x) :\n    derivWithin (fun y => \u2211 i in u, A i y) s x = \u2211 i in u, derivWithin (A i) s x :=\n  (HasDerivWithinAt.sum fun i hi => (h i hi).HasDerivWithinAt).derivWithin hxs\n#align deriv_within_sum derivWithin_sum\n\n@[simp]\ntheorem deriv_sum (h : \u2200 i \u2208 u, DifferentiableAt \ud835\udd5c (A i) x) :\n    deriv (fun y => \u2211 i in u, A i y) x = \u2211 i in u, deriv (A i) x :=\n  (HasDerivAt.sum fun i hi => (h i hi).HasDerivAt).deriv\n#align deriv_sum deriv_sum\n\nend Sum\n\nsection Pi\n\n/-! ### Derivatives of functions `f : \ud835\udd5c \u2192 \u03a0 i, E i` -/\n\n\nvariable {\u03b9 : Type _} [Fintype \u03b9] {E' : \u03b9 \u2192 Type _} [\u2200 i, NormedAddCommGroup (E' i)]\n  [\u2200 i, NormedSpace \ud835\udd5c (E' i)] {\u03c6 : \ud835\udd5c \u2192 \u2200 i, E' i} {\u03c6' : \u2200 i, E' i}\n\n@[simp]\ntheorem hasStrictDerivAt_pi :\n    HasStrictDerivAt \u03c6 \u03c6' x \u2194 \u2200 i, HasStrictDerivAt (fun x => \u03c6 x i) (\u03c6' i) x :=\n  hasStrictFderivAt_pi'\n#align has_strict_deriv_at_pi hasStrictDerivAt_pi\n\n@[simp]\ntheorem hasDerivAtFilter_pi :\n    HasDerivAtFilter \u03c6 \u03c6' x L \u2194 \u2200 i, HasDerivAtFilter (fun x => \u03c6 x i) (\u03c6' i) x L :=\n  hasFderivAtFilter_pi'\n#align has_deriv_at_filter_pi hasDerivAtFilter_pi\n\ntheorem hasDerivAt_pi : HasDerivAt \u03c6 \u03c6' x \u2194 \u2200 i, HasDerivAt (fun x => \u03c6 x i) (\u03c6' i) x :=\n  hasDerivAtFilter_pi\n#align has_deriv_at_pi hasDerivAt_pi\n\ntheorem hasDerivWithinAt_pi :\n    HasDerivWithinAt \u03c6 \u03c6' s x \u2194 \u2200 i, HasDerivWithinAt (fun x => \u03c6 x i) (\u03c6' i) s x :=\n  hasDerivAtFilter_pi\n#align has_deriv_within_at_pi hasDerivWithinAt_pi\n\ntheorem derivWithin_pi (h : \u2200 i, DifferentiableWithinAt \ud835\udd5c (fun x => \u03c6 x i) s x)\n    (hs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin \u03c6 s x = fun i => derivWithin (fun x => \u03c6 x i) s x :=\n  (hasDerivWithinAt_pi.2 fun i => (h i).HasDerivWithinAt).derivWithin hs\n#align deriv_within_pi derivWithin_pi\n\ntheorem deriv_pi (h : \u2200 i, DifferentiableAt \ud835\udd5c (fun x => \u03c6 x i) x) :\n    deriv \u03c6 x = fun i => deriv (fun x => \u03c6 x i) x :=\n  (hasDerivAt_pi.2 fun i => (h i).HasDerivAt).deriv\n#align deriv_pi deriv_pi\n\nend Pi\n\nsection Smul\n\n/-! ### Derivative of the multiplication of a scalar function and a vector function -/\n\n\nvariable {\ud835\udd5c' : Type _} [NontriviallyNormedField \ud835\udd5c'] [NormedAlgebra \ud835\udd5c \ud835\udd5c'] [NormedSpace \ud835\udd5c' F]\n  [IsScalarTower \ud835\udd5c \ud835\udd5c' F] {c : \ud835\udd5c \u2192 \ud835\udd5c'} {c' : \ud835\udd5c'}\n\ntheorem HasDerivWithinAt.smul (hc : HasDerivWithinAt c c' s x) (hf : HasDerivWithinAt f f' s x) :\n    HasDerivWithinAt (fun y => c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) s x := by\n  simpa using (HasFderivWithinAt.smul hc hf).HasDerivWithinAt\n#align has_deriv_within_at.smul HasDerivWithinAt.smul\n\ntheorem HasDerivAt.smul (hc : HasDerivAt c c' x) (hf : HasDerivAt f f' x) :\n    HasDerivAt (fun y => c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.smul hf\n#align has_deriv_at.smul HasDerivAt.smul\n\ntheorem HasStrictDerivAt.smul (hc : HasStrictDerivAt c c' x) (hf : HasStrictDerivAt f f' x) :\n    HasStrictDerivAt (fun y => c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) x := by\n  simpa using (hc.smul hf).HasStrictDerivAt\n#align has_strict_deriv_at.smul HasStrictDerivAt.smul\n\ntheorem derivWithin_smul (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (hc : DifferentiableWithinAt \ud835\udd5c c s x)\n    (hf : DifferentiableWithinAt \ud835\udd5c f s x) :\n    derivWithin (fun y => c y \u2022 f y) s x = c x \u2022 derivWithin f s x + derivWithin c s x \u2022 f x :=\n  (hc.HasDerivWithinAt.smul hf.HasDerivWithinAt).derivWithin hxs\n#align deriv_within_smul derivWithin_smul\n\ntheorem deriv_smul (hc : DifferentiableAt \ud835\udd5c c x) (hf : DifferentiableAt \ud835\udd5c f x) :\n    deriv (fun y => c y \u2022 f y) x = c x \u2022 deriv f x + deriv c x \u2022 f x :=\n  (hc.HasDerivAt.smul hf.HasDerivAt).deriv\n#align deriv_smul deriv_smul\n\ntheorem HasStrictDerivAt.smul_const (hc : HasStrictDerivAt c c' x) (f : F) :\n    HasStrictDerivAt (fun y => c y \u2022 f) (c' \u2022 f) x :=\n  by\n  have := hc.smul (hasStrictDerivAt_const x f)\n  rwa [smul_zero, zero_add] at this\n#align has_strict_deriv_at.smul_const HasStrictDerivAt.smul_const\n\ntheorem HasDerivWithinAt.smul_const (hc : HasDerivWithinAt c c' s x) (f : F) :\n    HasDerivWithinAt (fun y => c y \u2022 f) (c' \u2022 f) s x :=\n  by\n  have := hc.smul (hasDerivWithinAt_const x s f)\n  rwa [smul_zero, zero_add] at this\n#align has_deriv_within_at.smul_const HasDerivWithinAt.smul_const\n\ntheorem HasDerivAt.smul_const (hc : HasDerivAt c c' x) (f : F) :\n    HasDerivAt (fun y => c y \u2022 f) (c' \u2022 f) x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.smul_const f\n#align has_deriv_at.smul_const HasDerivAt.smul_const\n\ntheorem derivWithin_smul_const (hxs : UniqueDiffWithinAt \ud835\udd5c s x)\n    (hc : DifferentiableWithinAt \ud835\udd5c c s x) (f : F) :\n    derivWithin (fun y => c y \u2022 f) s x = derivWithin c s x \u2022 f :=\n  (hc.HasDerivWithinAt.smul_const f).derivWithin hxs\n#align deriv_within_smul_const derivWithin_smul_const\n\ntheorem deriv_smul_const (hc : DifferentiableAt \ud835\udd5c c x) (f : F) :\n    deriv (fun y => c y \u2022 f) x = deriv c x \u2022 f :=\n  (hc.HasDerivAt.smul_const f).deriv\n#align deriv_smul_const deriv_smul_const\n\nend Smul\n\nsection ConstSmul\n\nvariable {R : Type _} [Semiring R] [Module R F] [SMulCommClass \ud835\udd5c R F] [ContinuousConstSMul R F]\n\ntheorem HasStrictDerivAt.const_smul (c : R) (hf : HasStrictDerivAt f f' x) :\n    HasStrictDerivAt (fun y => c \u2022 f y) (c \u2022 f') x := by\n  simpa using (hf.const_smul c).HasStrictDerivAt\n#align has_strict_deriv_at.const_smul HasStrictDerivAt.const_smul\n\ntheorem HasDerivAtFilter.const_smul (c : R) (hf : HasDerivAtFilter f f' x L) :\n    HasDerivAtFilter (fun y => c \u2022 f y) (c \u2022 f') x L := by\n  simpa using (hf.const_smul c).HasDerivAtFilter\n#align has_deriv_at_filter.const_smul HasDerivAtFilter.const_smul\n\ntheorem HasDerivWithinAt.const_smul (c : R) (hf : HasDerivWithinAt f f' s x) :\n    HasDerivWithinAt (fun y => c \u2022 f y) (c \u2022 f') s x :=\n  hf.const_smul c\n#align has_deriv_within_at.const_smul HasDerivWithinAt.const_smul\n\ntheorem HasDerivAt.const_smul (c : R) (hf : HasDerivAt f f' x) :\n    HasDerivAt (fun y => c \u2022 f y) (c \u2022 f') x :=\n  hf.const_smul c\n#align has_deriv_at.const_smul HasDerivAt.const_smul\n\ntheorem derivWithin_const_smul (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (c : R)\n    (hf : DifferentiableWithinAt \ud835\udd5c f s x) :\n    derivWithin (fun y => c \u2022 f y) s x = c \u2022 derivWithin f s x :=\n  (hf.HasDerivWithinAt.const_smul c).derivWithin hxs\n#align deriv_within_const_smul derivWithin_const_smul\n\ntheorem deriv_const_smul (c : R) (hf : DifferentiableAt \ud835\udd5c f x) :\n    deriv (fun y => c \u2022 f y) x = c \u2022 deriv f x :=\n  (hf.HasDerivAt.const_smul c).deriv\n#align deriv_const_smul deriv_const_smul\n\nend ConstSmul\n\nsection Neg\n\n/-! ### Derivative of the negative of a function -/\n\n\ntheorem HasDerivAtFilter.neg (h : HasDerivAtFilter f f' x L) :\n    HasDerivAtFilter (fun x => -f x) (-f') x L := by simpa using h.neg.has_deriv_at_filter\n#align has_deriv_at_filter.neg HasDerivAtFilter.neg\n\ntheorem HasDerivWithinAt.neg (h : HasDerivWithinAt f f' s x) :\n    HasDerivWithinAt (fun x => -f x) (-f') s x :=\n  h.neg\n#align has_deriv_within_at.neg HasDerivWithinAt.neg\n\ntheorem HasDerivAt.neg (h : HasDerivAt f f' x) : HasDerivAt (fun x => -f x) (-f') x :=\n  h.neg\n#align has_deriv_at.neg HasDerivAt.neg\n\ntheorem HasStrictDerivAt.neg (h : HasStrictDerivAt f f' x) :\n    HasStrictDerivAt (fun x => -f x) (-f') x := by simpa using h.neg.has_strict_deriv_at\n#align has_strict_deriv_at.neg HasStrictDerivAt.neg\n\ntheorem derivWithin.neg (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun y => -f y) s x = -derivWithin f s x := by\n  simp only [derivWithin, fderivWithin_neg hxs, ContinuousLinearMap.neg_apply]\n#align deriv_within.neg derivWithin.neg\n\ntheorem deriv.neg : deriv (fun y => -f y) x = -deriv f x := by\n  simp only [deriv, fderiv_neg, ContinuousLinearMap.neg_apply]\n#align deriv.neg deriv.neg\n\n@[simp]\ntheorem deriv.neg' : (deriv fun y => -f y) = fun x => -deriv f x :=\n  funext fun x => deriv.neg\n#align deriv.neg' deriv.neg'\n\nend Neg\n\nsection Neg2\n\n/-! ### Derivative of the negation function (i.e `has_neg.neg`) -/\n\n\nvariable (s x L)\n\ntheorem hasDerivAtFilter_neg : HasDerivAtFilter Neg.neg (-1) x L :=\n  HasDerivAtFilter.neg <| hasDerivAtFilter_id _ _\n#align has_deriv_at_filter_neg hasDerivAtFilter_neg\n\ntheorem hasDerivWithinAt_neg : HasDerivWithinAt Neg.neg (-1) s x :=\n  hasDerivAtFilter_neg _ _\n#align has_deriv_within_at_neg hasDerivWithinAt_neg\n\ntheorem hasDerivAt_neg : HasDerivAt Neg.neg (-1) x :=\n  hasDerivAtFilter_neg _ _\n#align has_deriv_at_neg hasDerivAt_neg\n\ntheorem hasDerivAt_neg' : HasDerivAt (fun x => -x) (-1) x :=\n  hasDerivAtFilter_neg _ _\n#align has_deriv_at_neg' hasDerivAt_neg'\n\ntheorem hasStrictDerivAt_neg : HasStrictDerivAt Neg.neg (-1) x :=\n  HasStrictDerivAt.neg <| hasStrictDerivAt_id _\n#align has_strict_deriv_at_neg hasStrictDerivAt_neg\n\ntheorem deriv_neg : deriv Neg.neg x = -1 :=\n  HasDerivAt.deriv (hasDerivAt_neg x)\n#align deriv_neg deriv_neg\n\n@[simp]\ntheorem deriv_neg' : deriv (Neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) = fun _ => -1 :=\n  funext deriv_neg\n#align deriv_neg' deriv_neg'\n\n@[simp]\ntheorem deriv_neg'' : deriv (fun x : \ud835\udd5c => -x) x = -1 :=\n  deriv_neg x\n#align deriv_neg'' deriv_neg''\n\ntheorem derivWithin_neg (hxs : UniqueDiffWithinAt \ud835\udd5c s x) : derivWithin Neg.neg s x = -1 :=\n  (hasDerivWithinAt_neg x s).derivWithin hxs\n#align deriv_within_neg derivWithin_neg\n\ntheorem differentiable_neg : Differentiable \ud835\udd5c (Neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) :=\n  Differentiable.neg differentiable_id\n#align differentiable_neg differentiable_neg\n\ntheorem differentiableOn_neg : DifferentiableOn \ud835\udd5c (Neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) s :=\n  DifferentiableOn.neg differentiableOn_id\n#align differentiable_on_neg differentiableOn_neg\n\nend Neg2\n\nsection Sub\n\n/-! ### Derivative of the difference of two functions -/\n\n\ntheorem HasDerivAtFilter.sub (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) :\n    HasDerivAtFilter (fun x => f x - g x) (f' - g') x L := by\n  simpa only [sub_eq_add_neg] using hf.add hg.neg\n#align has_deriv_at_filter.sub HasDerivAtFilter.sub\n\ntheorem HasDerivWithinAt.sub (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) :\n    HasDerivWithinAt (fun x => f x - g x) (f' - g') s x :=\n  hf.sub hg\n#align has_deriv_within_at.sub HasDerivWithinAt.sub\n\ntheorem HasDerivAt.sub (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) :\n    HasDerivAt (fun x => f x - g x) (f' - g') x :=\n  hf.sub hg\n#align has_deriv_at.sub HasDerivAt.sub\n\ntheorem HasStrictDerivAt.sub (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) :\n    HasStrictDerivAt (fun x => f x - g x) (f' - g') x := by\n  simpa only [sub_eq_add_neg] using hf.add hg.neg\n#align has_strict_deriv_at.sub HasStrictDerivAt.sub\n\ntheorem derivWithin_sub (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (hf : DifferentiableWithinAt \ud835\udd5c f s x)\n    (hg : DifferentiableWithinAt \ud835\udd5c g s x) :\n    derivWithin (fun y => f y - g y) s x = derivWithin f s x - derivWithin g s x :=\n  (hf.HasDerivWithinAt.sub hg.HasDerivWithinAt).derivWithin hxs\n#align deriv_within_sub derivWithin_sub\n\n@[simp]\ntheorem deriv_sub (hf : DifferentiableAt \ud835\udd5c f x) (hg : DifferentiableAt \ud835\udd5c g x) :\n    deriv (fun y => f y - g y) x = deriv f x - deriv g x :=\n  (hf.HasDerivAt.sub hg.HasDerivAt).deriv\n#align deriv_sub deriv_sub\n\ntheorem HasDerivAtFilter.isO_sub (h : HasDerivAtFilter f f' x L) :\n    (fun x' => f x' - f x) =O[L] fun x' => x' - x :=\n  HasFderivAtFilter.isO_sub h\n#align has_deriv_at_filter.is_O_sub HasDerivAtFilter.isO_sub\n\ntheorem HasDerivAtFilter.isO_sub_rev (hf : HasDerivAtFilter f f' x L) (hf' : f' \u2260 0) :\n    (fun x' => x' - x) =O[L] fun x' => f x' - f x :=\n  suffices AntilipschitzWith \u2016f'\u2016\u208a\u207b\u00b9 (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') from hf.isO_sub_rev this\n  AddMonoidHomClass.antilipschitz_of_bound (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') fun x => by\n    simp [norm_smul, \u2190 div_eq_inv_mul, mul_div_cancel _ (mt norm_eq_zero.1 hf')]\n#align has_deriv_at_filter.is_O_sub_rev HasDerivAtFilter.isO_sub_rev\n\ntheorem HasDerivAtFilter.sub_const (hf : HasDerivAtFilter f f' x L) (c : F) :\n    HasDerivAtFilter (fun x => f x - c) f' x L := by\n  simpa only [sub_eq_add_neg] using hf.add_const (-c)\n#align has_deriv_at_filter.sub_const HasDerivAtFilter.sub_const\n\ntheorem HasDerivWithinAt.sub_const (hf : HasDerivWithinAt f f' s x) (c : F) :\n    HasDerivWithinAt (fun x => f x - c) f' s x :=\n  hf.sub_const c\n#align has_deriv_within_at.sub_const HasDerivWithinAt.sub_const\n\ntheorem HasDerivAt.sub_const (hf : HasDerivAt f f' x) (c : F) :\n    HasDerivAt (fun x => f x - c) f' x :=\n  hf.sub_const c\n#align has_deriv_at.sub_const HasDerivAt.sub_const\n\ntheorem derivWithin_sub_const (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (c : F) :\n    derivWithin (fun y => f y - c) s x = derivWithin f s x := by\n  simp only [derivWithin, fderivWithin_sub_const hxs]\n#align deriv_within_sub_const derivWithin_sub_const\n\ntheorem deriv_sub_const (c : F) : deriv (fun y => f y - c) x = deriv f x := by\n  simp only [deriv, fderiv_sub_const]\n#align deriv_sub_const deriv_sub_const\n\ntheorem HasDerivAtFilter.const_sub (c : F) (hf : HasDerivAtFilter f f' x L) :\n    HasDerivAtFilter (fun x => c - f x) (-f') x L := by\n  simpa only [sub_eq_add_neg] using hf.neg.const_add c\n#align has_deriv_at_filter.const_sub HasDerivAtFilter.const_sub\n\ntheorem HasDerivWithinAt.const_sub (c : F) (hf : HasDerivWithinAt f f' s x) :\n    HasDerivWithinAt (fun x => c - f x) (-f') s x :=\n  hf.const_sub c\n#align has_deriv_within_at.const_sub HasDerivWithinAt.const_sub\n\ntheorem HasStrictDerivAt.const_sub (c : F) (hf : HasStrictDerivAt f f' x) :\n    HasStrictDerivAt (fun x => c - f x) (-f') x := by\n  simpa only [sub_eq_add_neg] using hf.neg.const_add c\n#align has_strict_deriv_at.const_sub HasStrictDerivAt.const_sub\n\ntheorem HasDerivAt.const_sub (c : F) (hf : HasDerivAt f f' x) :\n    HasDerivAt (fun x => c - f x) (-f') x :=\n  hf.const_sub c\n#align has_deriv_at.const_sub HasDerivAt.const_sub\n\ntheorem derivWithin_const_sub (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (c : F) :\n    derivWithin (fun y => c - f y) s x = -derivWithin f s x := by\n  simp [derivWithin, fderivWithin_const_sub hxs]\n#align deriv_within_const_sub derivWithin_const_sub\n\ntheorem deriv_const_sub (c : F) : deriv (fun y => c - f y) x = -deriv f x := by\n  simp only [\u2190 derivWithin_univ,\n    derivWithin_const_sub (uniqueDiffWithinAt_univ : UniqueDiffWithinAt \ud835\udd5c _ _)]\n#align deriv_const_sub deriv_const_sub\n\nend Sub\n\nsection Continuous\n\n/-! ### Continuity of a function admitting a derivative -/\n\n\ntheorem HasDerivAtFilter.tendsto_nhds (hL : L \u2264 \ud835\udcdd x) (h : HasDerivAtFilter f f' x L) :\n    Tendsto f L (\ud835\udcdd (f x)) :=\n  h.tendsto_nhds hL\n#align has_deriv_at_filter.tendsto_nhds HasDerivAtFilter.tendsto_nhds\n\ntheorem HasDerivWithinAt.continuousWithinAt (h : HasDerivWithinAt f f' s x) :\n    ContinuousWithinAt f s x :=\n  HasDerivAtFilter.tendsto_nhds inf_le_left h\n#align has_deriv_within_at.continuous_within_at HasDerivWithinAt.continuousWithinAt\n\ntheorem HasDerivAt.continuousAt (h : HasDerivAt f f' x) : ContinuousAt f x :=\n  HasDerivAtFilter.tendsto_nhds le_rfl h\n#align has_deriv_at.continuous_at HasDerivAt.continuousAt\n\nprotected theorem HasDerivAt.continuousOn {f f' : \ud835\udd5c \u2192 F} (hderiv : \u2200 x \u2208 s, HasDerivAt f (f' x) x) :\n    ContinuousOn f s := fun x hx => (hderiv x hx).ContinuousAt.ContinuousWithinAt\n#align has_deriv_at.continuous_on HasDerivAt.continuousOn\n\nend Continuous\n\nsection CartesianProduct\n\n/-! ### Derivative of the cartesian product of two functions -/\n\n\nvariable {G : Type w} [NormedAddCommGroup G] [NormedSpace \ud835\udd5c G]\n\nvariable {f\u2082 : \ud835\udd5c \u2192 G} {f\u2082' : G}\n\ntheorem HasDerivAtFilter.prod (hf\u2081 : HasDerivAtFilter f\u2081 f\u2081' x L)\n    (hf\u2082 : HasDerivAtFilter f\u2082 f\u2082' x L) : HasDerivAtFilter (fun x => (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x L :=\n  hf\u2081.Prod hf\u2082\n#align has_deriv_at_filter.prod HasDerivAtFilter.prod\n\ntheorem HasDerivWithinAt.prod (hf\u2081 : HasDerivWithinAt f\u2081 f\u2081' s x)\n    (hf\u2082 : HasDerivWithinAt f\u2082 f\u2082' s x) : HasDerivWithinAt (fun x => (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') s x :=\n  hf\u2081.Prod hf\u2082\n#align has_deriv_within_at.prod HasDerivWithinAt.prod\n\ntheorem HasDerivAt.prod (hf\u2081 : HasDerivAt f\u2081 f\u2081' x) (hf\u2082 : HasDerivAt f\u2082 f\u2082' x) :\n    HasDerivAt (fun x => (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x :=\n  hf\u2081.Prod hf\u2082\n#align has_deriv_at.prod HasDerivAt.prod\n\ntheorem HasStrictDerivAt.prod (hf\u2081 : HasStrictDerivAt f\u2081 f\u2081' x) (hf\u2082 : HasStrictDerivAt f\u2082 f\u2082' x) :\n    HasStrictDerivAt (fun x => (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x :=\n  hf\u2081.Prod hf\u2082\n#align has_strict_deriv_at.prod HasStrictDerivAt.prod\n\nend CartesianProduct\n\nsection Composition\n\n/-!\n### Derivative of the composition of a vector function and a scalar function\n\nWe use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`\nin lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also\nbecause the `comp` version with the shorter name will show up much more often in applications).\nThe formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to\nusual multiplication in `comp` lemmas.\n-/\n\n\n/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to\nget confused since there are too many possibilities for composition -/\nvariable {\ud835\udd5c' : Type _} [NontriviallyNormedField \ud835\udd5c'] [NormedAlgebra \ud835\udd5c \ud835\udd5c'] [NormedSpace \ud835\udd5c' F]\n  [IsScalarTower \ud835\udd5c \ud835\udd5c' F] {s' t' : Set \ud835\udd5c'} {h : \ud835\udd5c \u2192 \ud835\udd5c'} {h\u2081 : \ud835\udd5c \u2192 \ud835\udd5c} {h\u2082 : \ud835\udd5c' \u2192 \ud835\udd5c'} {h' h\u2082' : \ud835\udd5c'}\n  {h\u2081' : \ud835\udd5c} {g\u2081 : \ud835\udd5c' \u2192 F} {g\u2081' : F} {L' : Filter \ud835\udd5c'} (x)\n\ntheorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g\u2081 g\u2081' (h x) L')\n    (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :\n    HasDerivAtFilter (g\u2081 \u2218 h) (h' \u2022 g\u2081') x L := by\n  simpa using ((hg.restrict_scalars \ud835\udd5c).comp x hh hL).HasDerivAtFilter\n#align has_deriv_at_filter.scomp HasDerivAtFilter.scomp\n\ntheorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g\u2081 g\u2081' s' (h x))\n    (hh : HasDerivAt h h' x) (hs : \u2200 x, h x \u2208 s') : HasDerivAt (g\u2081 \u2218 h) (h' \u2022 g\u2081') x :=\n  hg.scomp x hh <| tendsto_inf.2 \u27e8hh.ContinuousAt, tendsto_principal.2 <| eventually_of_forall hs\u27e9\n#align has_deriv_within_at.scomp_has_deriv_at HasDerivWithinAt.scomp_hasDerivAt\n\ntheorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g\u2081 g\u2081' t' (h x))\n    (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') :\n    HasDerivWithinAt (g\u2081 \u2218 h) (h' \u2022 g\u2081') s x :=\n  hg.scomp x hh <| hh.ContinuousWithinAt.tendsto_nhdsWithin hst\n#align has_deriv_within_at.scomp HasDerivWithinAt.scomp\n\n/-- The chain rule. -/\ntheorem HasDerivAt.scomp (hg : HasDerivAt g\u2081 g\u2081' (h x)) (hh : HasDerivAt h h' x) :\n    HasDerivAt (g\u2081 \u2218 h) (h' \u2022 g\u2081') x :=\n  hg.scomp x hh hh.ContinuousAt\n#align has_deriv_at.scomp HasDerivAt.scomp\n\ntheorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g\u2081 g\u2081' (h x)) (hh : HasStrictDerivAt h h' x) :\n    HasStrictDerivAt (g\u2081 \u2218 h) (h' \u2022 g\u2081') x := by\n  simpa using ((hg.restrict_scalars \ud835\udd5c).comp x hh).HasStrictDerivAt\n#align has_strict_deriv_at.scomp HasStrictDerivAt.scomp\n\ntheorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g\u2081 g\u2081' (h x))\n    (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g\u2081 \u2218 h) (h' \u2022 g\u2081') s x :=\n  HasDerivWithinAt.scomp x hg.HasDerivWithinAt hh (mapsTo_univ _ _)\n#align has_deriv_at.scomp_has_deriv_within_at HasDerivAt.scomp_hasDerivWithinAt\n\ntheorem derivWithin.scomp (hg : DifferentiableWithinAt \ud835\udd5c' g\u2081 t' (h x))\n    (hh : DifferentiableWithinAt \ud835\udd5c h s x) (hs : MapsTo h s t') (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (g\u2081 \u2218 h) s x = derivWithin h s x \u2022 derivWithin g\u2081 t' (h x) :=\n  (HasDerivWithinAt.scomp x hg.HasDerivWithinAt hh.HasDerivWithinAt hs).derivWithin hxs\n#align deriv_within.scomp derivWithin.scomp\n\ntheorem deriv.scomp (hg : DifferentiableAt \ud835\udd5c' g\u2081 (h x)) (hh : DifferentiableAt \ud835\udd5c h x) :\n    deriv (g\u2081 \u2218 h) x = deriv h x \u2022 deriv g\u2081 (h x) :=\n  (HasDerivAt.scomp x hg.HasDerivAt hh.HasDerivAt).deriv\n#align deriv.scomp deriv.scomp\n\n/-! ### Derivative of the composition of a scalar and vector functions -/\n\n\ntheorem HasDerivAtFilter.comp_hasFderivAtFilter {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} (x) {L'' : Filter E}\n    (hh\u2082 : HasDerivAtFilter h\u2082 h\u2082' (f x) L') (hf : HasFderivAtFilter f f' x L'')\n    (hL : Tendsto f L'' L') : HasFderivAtFilter (h\u2082 \u2218 f) (h\u2082' \u2022 f') x L'' :=\n  by\n  convert(hh\u2082.restrict_scalars \ud835\udd5c).comp x hf hL\n  ext x\n  simp [mul_comm]\n#align has_deriv_at_filter.comp_has_fderiv_at_filter HasDerivAtFilter.comp_hasFderivAtFilter\n\ntheorem HasStrictDerivAt.comp_hasStrictFderivAt {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} (x)\n    (hh : HasStrictDerivAt h\u2082 h\u2082' (f x)) (hf : HasStrictFderivAt f f' x) :\n    HasStrictFderivAt (h\u2082 \u2218 f) (h\u2082' \u2022 f') x :=\n  by\n  rw [HasStrictDerivAt] at hh\n  convert(hh.restrict_scalars \ud835\udd5c).comp x hf\n  ext x\n  simp [mul_comm]\n#align has_strict_deriv_at.comp_has_strict_fderiv_at HasStrictDerivAt.comp_hasStrictFderivAt\n\ntheorem HasDerivAt.comp_hasFderivAt {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} (x)\n    (hh : HasDerivAt h\u2082 h\u2082' (f x)) (hf : HasFderivAt f f' x) : HasFderivAt (h\u2082 \u2218 f) (h\u2082' \u2022 f') x :=\n  hh.comp_hasFderivAtFilter x hf hf.ContinuousAt\n#align has_deriv_at.comp_has_fderiv_at HasDerivAt.comp_hasFderivAt\n\ntheorem HasDerivAt.comp_hasFderivWithinAt {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} {s} (x)\n    (hh : HasDerivAt h\u2082 h\u2082' (f x)) (hf : HasFderivWithinAt f f' s x) :\n    HasFderivWithinAt (h\u2082 \u2218 f) (h\u2082' \u2022 f') s x :=\n  hh.comp_hasFderivAtFilter x hf hf.ContinuousWithinAt\n#align has_deriv_at.comp_has_fderiv_within_at HasDerivAt.comp_hasFderivWithinAt\n\ntheorem HasDerivWithinAt.comp_hasFderivWithinAt {f : E \u2192 \ud835\udd5c'} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c'} {s t} (x)\n    (hh : HasDerivWithinAt h\u2082 h\u2082' t (f x)) (hf : HasFderivWithinAt f f' s x) (hst : MapsTo f s t) :\n    HasFderivWithinAt (h\u2082 \u2218 f) (h\u2082' \u2022 f') s x :=\n  hh.comp_hasFderivAtFilter x hf <| hf.ContinuousWithinAt.tendsto_nhdsWithin hst\n#align has_deriv_within_at.comp_has_fderiv_within_at HasDerivWithinAt.comp_hasFderivWithinAt\n\n/-! ### Derivative of the composition of two scalar functions -/\n\n\ntheorem HasDerivAtFilter.comp (hh\u2082 : HasDerivAtFilter h\u2082 h\u2082' (h x) L')\n    (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :\n    HasDerivAtFilter (h\u2082 \u2218 h) (h\u2082' * h') x L :=\n  by\n  rw [mul_comm]\n  exact hh\u2082.scomp x hh hL\n#align has_deriv_at_filter.comp HasDerivAtFilter.comp\n\ntheorem HasDerivWithinAt.comp (hh\u2082 : HasDerivWithinAt h\u2082 h\u2082' s' (h x))\n    (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') :\n    HasDerivWithinAt (h\u2082 \u2218 h) (h\u2082' * h') s x :=\n  by\n  rw [mul_comm]\n  exact hh\u2082.scomp x hh hst\n#align has_deriv_within_at.comp HasDerivWithinAt.comp\n\n/-- The chain rule. -/\ntheorem HasDerivAt.comp (hh\u2082 : HasDerivAt h\u2082 h\u2082' (h x)) (hh : HasDerivAt h h' x) :\n    HasDerivAt (h\u2082 \u2218 h) (h\u2082' * h') x :=\n  hh\u2082.comp x hh hh.ContinuousAt\n#align has_deriv_at.comp HasDerivAt.comp\n\ntheorem HasStrictDerivAt.comp (hh\u2082 : HasStrictDerivAt h\u2082 h\u2082' (h x)) (hh : HasStrictDerivAt h h' x) :\n    HasStrictDerivAt (h\u2082 \u2218 h) (h\u2082' * h') x :=\n  by\n  rw [mul_comm]\n  exact hh\u2082.scomp x hh\n#align has_strict_deriv_at.comp HasStrictDerivAt.comp\n\ntheorem HasDerivAt.comp_hasDerivWithinAt (hh\u2082 : HasDerivAt h\u2082 h\u2082' (h x))\n    (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (h\u2082 \u2218 h) (h\u2082' * h') s x :=\n  hh\u2082.HasDerivWithinAt.comp x hh (mapsTo_univ _ _)\n#align has_deriv_at.comp_has_deriv_within_at HasDerivAt.comp_hasDerivWithinAt\n\ntheorem derivWithin.comp (hh\u2082 : DifferentiableWithinAt \ud835\udd5c' h\u2082 s' (h x))\n    (hh : DifferentiableWithinAt \ud835\udd5c h s x) (hs : MapsTo h s s') (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (h\u2082 \u2218 h) s x = derivWithin h\u2082 s' (h x) * derivWithin h s x :=\n  (hh\u2082.HasDerivWithinAt.comp x hh.HasDerivWithinAt hs).derivWithin hxs\n#align deriv_within.comp derivWithin.comp\n\ntheorem deriv.comp (hh\u2082 : DifferentiableAt \ud835\udd5c' h\u2082 (h x)) (hh : DifferentiableAt \ud835\udd5c h x) :\n    deriv (h\u2082 \u2218 h) x = deriv h\u2082 (h x) * deriv h x :=\n  (hh\u2082.HasDerivAt.comp x hh.HasDerivAt).deriv\n#align deriv.comp deriv.comp\n\nprotected theorem HasDerivAtFilter.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c} (hf : HasDerivAtFilter f f' x L)\n    (hL : Tendsto f L L) (hx : f x = x) (n : \u2115) : HasDerivAtFilter (f^[n]) (f' ^ n) x L :=\n  by\n  have := hf.iterate hL hx n\n  rwa [ContinuousLinearMap.smulRight_one_pow] at this\n#align has_deriv_at_filter.iterate HasDerivAtFilter.iterate\n\nprotected theorem HasDerivAt.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c} (hf : HasDerivAt f f' x) (hx : f x = x)\n    (n : \u2115) : HasDerivAt (f^[n]) (f' ^ n) x :=\n  by\n  have := HasFderivAt.iterate hf hx n\n  rwa [ContinuousLinearMap.smulRight_one_pow] at this\n#align has_deriv_at.iterate HasDerivAt.iterate\n\nprotected theorem HasDerivWithinAt.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c} (hf : HasDerivWithinAt f f' s x)\n    (hx : f x = x) (hs : MapsTo f s s) (n : \u2115) : HasDerivWithinAt (f^[n]) (f' ^ n) s x :=\n  by\n  have := HasFderivWithinAt.iterate hf hx hs n\n  rwa [ContinuousLinearMap.smulRight_one_pow] at this\n#align has_deriv_within_at.iterate HasDerivWithinAt.iterate\n\nprotected theorem HasStrictDerivAt.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c} (hf : HasStrictDerivAt f f' x)\n    (hx : f x = x) (n : \u2115) : HasStrictDerivAt (f^[n]) (f' ^ n) x :=\n  by\n  have := hf.iterate hx n\n  rwa [ContinuousLinearMap.smulRight_one_pow] at this\n#align has_strict_deriv_at.iterate HasStrictDerivAt.iterate\n\nend Composition\n\nsection CompositionVector\n\n/-! ### Derivative of the composition of a function between vector spaces and a function on `\ud835\udd5c` -/\n\n\nopen ContinuousLinearMap\n\nvariable {l : F \u2192 E} {l' : F \u2192L[\ud835\udd5c] E}\n\nvariable (x)\n\n/-- The composition `l \u2218 f` where `l : F \u2192 E` and `f : \ud835\udd5c \u2192 F`, has a derivative within a set\nequal to the Fr\u00e9chet derivative of `l` applied to the derivative of `f`. -/\ntheorem HasFderivWithinAt.comp_hasDerivWithinAt {t : Set F} (hl : HasFderivWithinAt l l' t (f x))\n    (hf : HasDerivWithinAt f f' s x) (hst : MapsTo f s t) : HasDerivWithinAt (l \u2218 f) (l' f') s x :=\n  by\n  simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (\u00b7 \u2218 \u00b7)] using\n    (hl.comp x hf.has_fderiv_within_at hst).HasDerivWithinAt\n#align has_fderiv_within_at.comp_has_deriv_within_at HasFderivWithinAt.comp_hasDerivWithinAt\n\ntheorem HasFderivAt.comp_hasDerivWithinAt (hl : HasFderivAt l l' (f x))\n    (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (l \u2218 f) (l' f') s x :=\n  hl.HasFderivWithinAt.comp_hasDerivWithinAt x hf (mapsTo_univ _ _)\n#align has_fderiv_at.comp_has_deriv_within_at HasFderivAt.comp_hasDerivWithinAt\n\n/-- The composition `l \u2218 f` where `l : F \u2192 E` and `f : \ud835\udd5c \u2192 F`, has a derivative equal to the\nFr\u00e9chet derivative of `l` applied to the derivative of `f`. -/\ntheorem HasFderivAt.comp_hasDerivAt (hl : HasFderivAt l l' (f x)) (hf : HasDerivAt f f' x) :\n    HasDerivAt (l \u2218 f) (l' f') x :=\n  hasDerivWithinAt_univ.mp <| hl.comp_hasDerivWithinAt x hf.HasDerivWithinAt\n#align has_fderiv_at.comp_has_deriv_at HasFderivAt.comp_hasDerivAt\n\ntheorem HasStrictFderivAt.comp_hasStrictDerivAt (hl : HasStrictFderivAt l l' (f x))\n    (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (l \u2218 f) (l' f') x := by\n  simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (\u00b7 \u2218 \u00b7)] using\n    (hl.comp x hf.has_strict_fderiv_at).HasStrictDerivAt\n#align has_strict_fderiv_at.comp_has_strict_deriv_at HasStrictFderivAt.comp_hasStrictDerivAt\n\ntheorem fderivWithin.comp_derivWithin {t : Set F} (hl : DifferentiableWithinAt \ud835\udd5c l t (f x))\n    (hf : DifferentiableWithinAt \ud835\udd5c f s x) (hs : MapsTo f s t) (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (l \u2218 f) s x = (fderivWithin \ud835\udd5c l t (f x) : F \u2192 E) (derivWithin f s x) :=\n  (hl.HasFderivWithinAt.comp_hasDerivWithinAt x hf.HasDerivWithinAt hs).derivWithin hxs\n#align fderiv_within.comp_deriv_within fderivWithin.comp_derivWithin\n\ntheorem fderiv.comp_deriv (hl : DifferentiableAt \ud835\udd5c l (f x)) (hf : DifferentiableAt \ud835\udd5c f x) :\n    deriv (l \u2218 f) x = (fderiv \ud835\udd5c l (f x) : F \u2192 E) (deriv f x) :=\n  (hl.HasFderivAt.comp_hasDerivAt x hf.HasDerivAt).deriv\n#align fderiv.comp_deriv fderiv.comp_deriv\n\nend CompositionVector\n\nsection Mul\n\n/-! ### Derivative of the multiplication of two functions -/\n\n\nvariable {\ud835\udd5c' \ud835\udd38 : Type _} [NormedField \ud835\udd5c'] [NormedRing \ud835\udd38] [NormedAlgebra \ud835\udd5c \ud835\udd5c'] [NormedAlgebra \ud835\udd5c \ud835\udd38]\n  {c d : \ud835\udd5c \u2192 \ud835\udd38} {c' d' : \ud835\udd38} {u v : \ud835\udd5c \u2192 \ud835\udd5c'}\n\ntheorem HasDerivWithinAt.mul (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) :\n    HasDerivWithinAt (fun y => c y * d y) (c' * d x + c x * d') s x :=\n  by\n  have := (HasFderivWithinAt.mul' hc hd).HasDerivWithinAt\n  rwa [ContinuousLinearMap.add_apply, ContinuousLinearMap.smul_apply,\n    ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply,\n    ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, one_smul, one_smul,\n    add_comm] at this\n#align has_deriv_within_at.mul HasDerivWithinAt.mul\n\ntheorem HasDerivAt.mul (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) :\n    HasDerivAt (fun y => c y * d y) (c' * d x + c x * d') x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.mul hd\n#align has_deriv_at.mul HasDerivAt.mul\n\ntheorem HasStrictDerivAt.mul (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) :\n    HasStrictDerivAt (fun y => c y * d y) (c' * d x + c x * d') x :=\n  by\n  have := (HasStrictFderivAt.mul' hc hd).HasStrictDerivAt\n  rwa [ContinuousLinearMap.add_apply, ContinuousLinearMap.smul_apply,\n    ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply,\n    ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, one_smul, one_smul,\n    add_comm] at this\n#align has_strict_deriv_at.mul HasStrictDerivAt.mul\n\ntheorem derivWithin_mul (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (hc : DifferentiableWithinAt \ud835\udd5c c s x)\n    (hd : DifferentiableWithinAt \ud835\udd5c d s x) :\n    derivWithin (fun y => c y * d y) s x = derivWithin c s x * d x + c x * derivWithin d s x :=\n  (hc.HasDerivWithinAt.mul hd.HasDerivWithinAt).derivWithin hxs\n#align deriv_within_mul derivWithin_mul\n\n@[simp]\ntheorem deriv_mul (hc : DifferentiableAt \ud835\udd5c c x) (hd : DifferentiableAt \ud835\udd5c d x) :\n    deriv (fun y => c y * d y) x = deriv c x * d x + c x * deriv d x :=\n  (hc.HasDerivAt.mul hd.HasDerivAt).deriv\n#align deriv_mul deriv_mul\n\ntheorem HasDerivWithinAt.mul_const (hc : HasDerivWithinAt c c' s x) (d : \ud835\udd38) :\n    HasDerivWithinAt (fun y => c y * d) (c' * d) s x :=\n  by\n  convert hc.mul (hasDerivWithinAt_const x s d)\n  rw [MulZeroClass.mul_zero, add_zero]\n#align has_deriv_within_at.mul_const HasDerivWithinAt.mul_const\n\ntheorem HasDerivAt.mul_const (hc : HasDerivAt c c' x) (d : \ud835\udd38) :\n    HasDerivAt (fun y => c y * d) (c' * d) x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.mul_const d\n#align has_deriv_at.mul_const HasDerivAt.mul_const\n\ntheorem hasDerivAt_mul_const (c : \ud835\udd5c) : HasDerivAt (fun x => x * c) c x := by\n  simpa only [one_mul] using (hasDerivAt_id' x).mul_const c\n#align has_deriv_at_mul_const hasDerivAt_mul_const\n\ntheorem HasStrictDerivAt.mul_const (hc : HasStrictDerivAt c c' x) (d : \ud835\udd38) :\n    HasStrictDerivAt (fun y => c y * d) (c' * d) x :=\n  by\n  convert hc.mul (hasStrictDerivAt_const x d)\n  rw [MulZeroClass.mul_zero, add_zero]\n#align has_strict_deriv_at.mul_const HasStrictDerivAt.mul_const\n\ntheorem derivWithin_mul_const (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (hc : DifferentiableWithinAt \ud835\udd5c c s x)\n    (d : \ud835\udd38) : derivWithin (fun y => c y * d) s x = derivWithin c s x * d :=\n  (hc.HasDerivWithinAt.mul_const d).derivWithin hxs\n#align deriv_within_mul_const derivWithin_mul_const\n\ntheorem deriv_mul_const (hc : DifferentiableAt \ud835\udd5c c x) (d : \ud835\udd38) :\n    deriv (fun y => c y * d) x = deriv c x * d :=\n  (hc.HasDerivAt.mul_const d).deriv\n#align deriv_mul_const deriv_mul_const\n\ntheorem deriv_mul_const_field (v : \ud835\udd5c') : deriv (fun y => u y * v) x = deriv u x * v :=\n  by\n  by_cases hu : DifferentiableAt \ud835\udd5c u x\n  \u00b7 exact deriv_mul_const hu v\n  \u00b7 rw [deriv_zero_of_not_differentiableAt hu, MulZeroClass.zero_mul]\n    rcases eq_or_ne v 0 with (rfl | hd)\n    \u00b7 simp only [MulZeroClass.mul_zero, deriv_const]\n    \u00b7 refine' deriv_zero_of_not_differentiableAt (mt (fun H => _) hu)\n      simpa only [mul_inv_cancel_right\u2080 hd] using H.mul_const v\u207b\u00b9\n#align deriv_mul_const_field deriv_mul_const_field\n\n@[simp]\ntheorem deriv_mul_const_field' (v : \ud835\udd5c') : (deriv fun x => u x * v) = fun x => deriv u x * v :=\n  funext fun _ => deriv_mul_const_field v\n#align deriv_mul_const_field' deriv_mul_const_field'\n\ntheorem HasDerivWithinAt.const_mul (c : \ud835\udd38) (hd : HasDerivWithinAt d d' s x) :\n    HasDerivWithinAt (fun y => c * d y) (c * d') s x :=\n  by\n  convert(hasDerivWithinAt_const x s c).mul hd\n  rw [MulZeroClass.zero_mul, zero_add]\n#align has_deriv_within_at.const_mul HasDerivWithinAt.const_mul\n\ntheorem HasDerivAt.const_mul (c : \ud835\udd38) (hd : HasDerivAt d d' x) :\n    HasDerivAt (fun y => c * d y) (c * d') x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hd.const_mul c\n#align has_deriv_at.const_mul HasDerivAt.const_mul\n\ntheorem HasStrictDerivAt.const_mul (c : \ud835\udd38) (hd : HasStrictDerivAt d d' x) :\n    HasStrictDerivAt (fun y => c * d y) (c * d') x :=\n  by\n  convert(hasStrictDerivAt_const _ _).mul hd\n  rw [MulZeroClass.zero_mul, zero_add]\n#align has_strict_deriv_at.const_mul HasStrictDerivAt.const_mul\n\ntheorem derivWithin_const_mul (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (c : \ud835\udd38)\n    (hd : DifferentiableWithinAt \ud835\udd5c d s x) :\n    derivWithin (fun y => c * d y) s x = c * derivWithin d s x :=\n  (hd.HasDerivWithinAt.const_mul c).derivWithin hxs\n#align deriv_within_const_mul derivWithin_const_mul\n\ntheorem deriv_const_mul (c : \ud835\udd38) (hd : DifferentiableAt \ud835\udd5c d x) :\n    deriv (fun y => c * d y) x = c * deriv d x :=\n  (hd.HasDerivAt.const_mul c).deriv\n#align deriv_const_mul deriv_const_mul\n\ntheorem deriv_const_mul_field (u : \ud835\udd5c') : deriv (fun y => u * v y) x = u * deriv v x := by\n  simp only [mul_comm u, deriv_mul_const_field]\n#align deriv_const_mul_field deriv_const_mul_field\n\n@[simp]\ntheorem deriv_const_mul_field' (u : \ud835\udd5c') : (deriv fun x => u * v x) = fun x => u * deriv v x :=\n  funext fun x => deriv_const_mul_field u\n#align deriv_const_mul_field' deriv_const_mul_field'\n\nend Mul\n\nsection Inverse\n\n/-! ### Derivative of `x \u21a6 x\u207b\u00b9` -/\n\n\ntheorem hasStrictDerivAt_inv (hx : x \u2260 0) : HasStrictDerivAt Inv.inv (-(x ^ 2)\u207b\u00b9) x :=\n  by\n  suffices\n    (fun p : \ud835\udd5c \u00d7 \ud835\udd5c => (p.1 - p.2) * ((x * x)\u207b\u00b9 - (p.1 * p.2)\u207b\u00b9)) =o[\ud835\udcdd (x, x)] fun p =>\n      (p.1 - p.2) * 1\n    by\n    refine' this.congr' _ (eventually_of_forall fun _ => mul_one _)\n    refine' eventually.mono (IsOpen.mem_nhds (is_open_ne.prod isOpen_ne) \u27e8hx, hx\u27e9) _\n    rintro \u27e8y, z\u27e9 \u27e8hy, hz\u27e9\n    simp only [mem_set_of_eq] at hy hz\n    -- hy : y \u2260 0, hz : z \u2260 0\n    field_simp [hx, hy, hz]\n    ring\n  refine' (is_O_refl (fun p : \ud835\udd5c \u00d7 \ud835\udd5c => p.1 - p.2) _).mul_isOCat ((is_o_one_iff _).2 _)\n  rw [\u2190 sub_self (x * x)\u207b\u00b9]\n  exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv\u2080 <| mul_ne_zero hx hx)\n#align has_strict_deriv_at_inv hasStrictDerivAt_inv\n\ntheorem hasDerivAt_inv (x_ne_zero : x \u2260 0) : HasDerivAt (fun y => y\u207b\u00b9) (-(x ^ 2)\u207b\u00b9) x :=\n  (hasStrictDerivAt_inv x_ne_zero).HasDerivAt\n#align has_deriv_at_inv hasDerivAt_inv\n\ntheorem hasDerivWithinAt_inv (x_ne_zero : x \u2260 0) (s : Set \ud835\udd5c) :\n    HasDerivWithinAt (fun x => x\u207b\u00b9) (-(x ^ 2)\u207b\u00b9) s x :=\n  (hasDerivAt_inv x_ne_zero).HasDerivWithinAt\n#align has_deriv_within_at_inv hasDerivWithinAt_inv\n\ntheorem differentiableAt_inv : DifferentiableAt \ud835\udd5c (fun x => x\u207b\u00b9) x \u2194 x \u2260 0 :=\n  \u27e8fun H => NormedField.continuousAt_inv.1 H.ContinuousAt, fun H =>\n    (hasDerivAt_inv H).DifferentiableAt\u27e9\n#align differentiable_at_inv differentiableAt_inv\n\ntheorem differentiableWithinAt_inv (x_ne_zero : x \u2260 0) :\n    DifferentiableWithinAt \ud835\udd5c (fun x => x\u207b\u00b9) s x :=\n  (differentiableAt_inv.2 x_ne_zero).DifferentiableWithinAt\n#align differentiable_within_at_inv differentiableWithinAt_inv\n\ntheorem differentiableOn_inv : DifferentiableOn \ud835\udd5c (fun x : \ud835\udd5c => x\u207b\u00b9) { x | x \u2260 0 } := fun x hx =>\n  differentiableWithinAt_inv hx\n#align differentiable_on_inv differentiableOn_inv\n\ntheorem deriv_inv : deriv (fun x => x\u207b\u00b9) x = -(x ^ 2)\u207b\u00b9 :=\n  by\n  rcases eq_or_ne x 0 with (rfl | hne)\n  \u00b7 simp [deriv_zero_of_not_differentiableAt (mt differentiableAt_inv.1 (Classical.not_not.2 rfl))]\n  \u00b7 exact (hasDerivAt_inv hne).deriv\n#align deriv_inv deriv_inv\n\n@[simp]\ntheorem deriv_inv' : (deriv fun x : \ud835\udd5c => x\u207b\u00b9) = fun x => -(x ^ 2)\u207b\u00b9 :=\n  funext fun x => deriv_inv\n#align deriv_inv' deriv_inv'\n\ntheorem derivWithin_inv (x_ne_zero : x \u2260 0) (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun x => x\u207b\u00b9) s x = -(x ^ 2)\u207b\u00b9 :=\n  by\n  rw [DifferentiableAt.derivWithin (differentiableAt_inv.2 x_ne_zero) hxs]\n  exact deriv_inv\n#align deriv_within_inv derivWithin_inv\n\ntheorem hasFderivAt_inv (x_ne_zero : x \u2260 0) :\n    HasFderivAt (fun x => x\u207b\u00b9) (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x ^ 2)\u207b\u00b9) : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\n  hasDerivAt_inv x_ne_zero\n#align has_fderiv_at_inv hasFderivAt_inv\n\ntheorem hasFderivWithinAt_inv (x_ne_zero : x \u2260 0) :\n    HasFderivWithinAt (fun x => x\u207b\u00b9) (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x ^ 2)\u207b\u00b9) : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) s x :=\n  (hasFderivAt_inv x_ne_zero).HasFderivWithinAt\n#align has_fderiv_within_at_inv hasFderivWithinAt_inv\n\ntheorem fderiv_inv : fderiv \ud835\udd5c (fun x => x\u207b\u00b9) x = smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x ^ 2)\u207b\u00b9) := by\n  rw [\u2190 deriv_fderiv, deriv_inv]\n#align fderiv_inv fderiv_inv\n\ntheorem fderivWithin_inv (x_ne_zero : x \u2260 0) (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    fderivWithin \ud835\udd5c (fun x => x\u207b\u00b9) s x = smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x ^ 2)\u207b\u00b9) :=\n  by\n  rw [DifferentiableAt.fderivWithin (differentiableAt_inv.2 x_ne_zero) hxs]\n  exact fderiv_inv\n#align fderiv_within_inv fderivWithin_inv\n\nvariable {c : \ud835\udd5c \u2192 \ud835\udd5c} {h : E \u2192 \ud835\udd5c} {c' : \ud835\udd5c} {z : E} {S : Set E}\n\ntheorem HasDerivWithinAt.inv (hc : HasDerivWithinAt c c' s x) (hx : c x \u2260 0) :\n    HasDerivWithinAt (fun y => (c y)\u207b\u00b9) (-c' / c x ^ 2) s x :=\n  by\n  convert(hasDerivAt_inv hx).comp_hasDerivWithinAt x hc\n  field_simp\n#align has_deriv_within_at.inv HasDerivWithinAt.inv\n\ntheorem HasDerivAt.inv (hc : HasDerivAt c c' x) (hx : c x \u2260 0) :\n    HasDerivAt (fun y => (c y)\u207b\u00b9) (-c' / c x ^ 2) x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.inv hx\n#align has_deriv_at.inv HasDerivAt.inv\n\ntheorem DifferentiableWithinAt.inv (hf : DifferentiableWithinAt \ud835\udd5c h S z) (hz : h z \u2260 0) :\n    DifferentiableWithinAt \ud835\udd5c (fun x => (h x)\u207b\u00b9) S z :=\n  (differentiableAt_inv.mpr hz).comp_differentiableWithinAt z hf\n#align differentiable_within_at.inv DifferentiableWithinAt.inv\n\n@[simp]\ntheorem DifferentiableAt.inv (hf : DifferentiableAt \ud835\udd5c h z) (hz : h z \u2260 0) :\n    DifferentiableAt \ud835\udd5c (fun x => (h x)\u207b\u00b9) z :=\n  (differentiableAt_inv.mpr hz).comp z hf\n#align differentiable_at.inv DifferentiableAt.inv\n\ntheorem DifferentiableOn.inv (hf : DifferentiableOn \ud835\udd5c h S) (hz : \u2200 x \u2208 S, h x \u2260 0) :\n    DifferentiableOn \ud835\udd5c (fun x => (h x)\u207b\u00b9) S := fun x h => (hf x h).inv (hz x h)\n#align differentiable_on.inv DifferentiableOn.inv\n\n@[simp]\ntheorem Differentiable.inv (hf : Differentiable \ud835\udd5c h) (hz : \u2200 x, h x \u2260 0) :\n    Differentiable \ud835\udd5c fun x => (h x)\u207b\u00b9 := fun x => (hf x).inv (hz x)\n#align differentiable.inv Differentiable.inv\n\ntheorem derivWithin_inv' (hc : DifferentiableWithinAt \ud835\udd5c c s x) (hx : c x \u2260 0)\n    (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun x => (c x)\u207b\u00b9) s x = -derivWithin c s x / c x ^ 2 :=\n  (hc.HasDerivWithinAt.inv hx).derivWithin hxs\n#align deriv_within_inv' derivWithin_inv'\n\n@[simp]\ntheorem deriv_inv'' (hc : DifferentiableAt \ud835\udd5c c x) (hx : c x \u2260 0) :\n    deriv (fun x => (c x)\u207b\u00b9) x = -deriv c x / c x ^ 2 :=\n  (hc.HasDerivAt.inv hx).deriv\n#align deriv_inv'' deriv_inv''\n\nend Inverse\n\nsection Division\n\n/-! ### Derivative of `x \u21a6 c x / d x` -/\n\n\nvariable {\ud835\udd5c' : Type _} [NontriviallyNormedField \ud835\udd5c'] [NormedAlgebra \ud835\udd5c \ud835\udd5c'] {c d : \ud835\udd5c \u2192 \ud835\udd5c'} {c' d' : \ud835\udd5c'}\n\ntheorem HasDerivWithinAt.div (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x)\n    (hx : d x \u2260 0) : HasDerivWithinAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) s x :=\n  by\n  convert hc.mul ((hasDerivAt_inv hx).comp_hasDerivWithinAt x hd)\n  \u00b7 simp only [div_eq_mul_inv]\n  \u00b7 field_simp\n    ring\n#align has_deriv_within_at.div HasDerivWithinAt.div\n\ntheorem HasStrictDerivAt.div (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x)\n    (hx : d x \u2260 0) : HasStrictDerivAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) x :=\n  by\n  convert hc.mul ((hasStrictDerivAt_inv hx).comp x hd)\n  \u00b7 simp only [div_eq_mul_inv]\n  \u00b7 field_simp\n    ring\n#align has_strict_deriv_at.div HasStrictDerivAt.div\n\ntheorem HasDerivAt.div (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) (hx : d x \u2260 0) :\n    HasDerivAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.div hd hx\n#align has_deriv_at.div HasDerivAt.div\n\ntheorem DifferentiableWithinAt.div (hc : DifferentiableWithinAt \ud835\udd5c c s x)\n    (hd : DifferentiableWithinAt \ud835\udd5c d s x) (hx : d x \u2260 0) :\n    DifferentiableWithinAt \ud835\udd5c (fun x => c x / d x) s x :=\n  (hc.HasDerivWithinAt.div hd.HasDerivWithinAt hx).DifferentiableWithinAt\n#align differentiable_within_at.div DifferentiableWithinAt.div\n\n@[simp]\ntheorem DifferentiableAt.div (hc : DifferentiableAt \ud835\udd5c c x) (hd : DifferentiableAt \ud835\udd5c d x)\n    (hx : d x \u2260 0) : DifferentiableAt \ud835\udd5c (fun x => c x / d x) x :=\n  (hc.HasDerivAt.div hd.HasDerivAt hx).DifferentiableAt\n#align differentiable_at.div DifferentiableAt.div\n\ntheorem DifferentiableOn.div (hc : DifferentiableOn \ud835\udd5c c s) (hd : DifferentiableOn \ud835\udd5c d s)\n    (hx : \u2200 x \u2208 s, d x \u2260 0) : DifferentiableOn \ud835\udd5c (fun x => c x / d x) s := fun x h =>\n  (hc x h).div (hd x h) (hx x h)\n#align differentiable_on.div DifferentiableOn.div\n\n@[simp]\ntheorem Differentiable.div (hc : Differentiable \ud835\udd5c c) (hd : Differentiable \ud835\udd5c d) (hx : \u2200 x, d x \u2260 0) :\n    Differentiable \ud835\udd5c fun x => c x / d x := fun x => (hc x).div (hd x) (hx x)\n#align differentiable.div Differentiable.div\n\ntheorem derivWithin_div (hc : DifferentiableWithinAt \ud835\udd5c c s x) (hd : DifferentiableWithinAt \ud835\udd5c d s x)\n    (hx : d x \u2260 0) (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun x => c x / d x) s x =\n      (derivWithin c s x * d x - c x * derivWithin d s x) / d x ^ 2 :=\n  (hc.HasDerivWithinAt.div hd.HasDerivWithinAt hx).derivWithin hxs\n#align deriv_within_div derivWithin_div\n\n@[simp]\ntheorem deriv_div (hc : DifferentiableAt \ud835\udd5c c x) (hd : DifferentiableAt \ud835\udd5c d x) (hx : d x \u2260 0) :\n    deriv (fun x => c x / d x) x = (deriv c x * d x - c x * deriv d x) / d x ^ 2 :=\n  (hc.HasDerivAt.div hd.HasDerivAt hx).deriv\n#align deriv_div deriv_div\n\ntheorem HasDerivAt.div_const (hc : HasDerivAt c c' x) (d : \ud835\udd5c') :\n    HasDerivAt (fun x => c x / d) (c' / d) x := by\n  simpa only [div_eq_mul_inv] using hc.mul_const d\u207b\u00b9\n#align has_deriv_at.div_const HasDerivAt.div_const\n\ntheorem HasDerivWithinAt.div_const (hc : HasDerivWithinAt c c' s x) (d : \ud835\udd5c') :\n    HasDerivWithinAt (fun x => c x / d) (c' / d) s x := by\n  simpa only [div_eq_mul_inv] using hc.mul_const d\u207b\u00b9\n#align has_deriv_within_at.div_const HasDerivWithinAt.div_const\n\ntheorem HasStrictDerivAt.div_const (hc : HasStrictDerivAt c c' x) (d : \ud835\udd5c') :\n    HasStrictDerivAt (fun x => c x / d) (c' / d) x := by\n  simpa only [div_eq_mul_inv] using hc.mul_const d\u207b\u00b9\n#align has_strict_deriv_at.div_const HasStrictDerivAt.div_const\n\ntheorem DifferentiableWithinAt.div_const (hc : DifferentiableWithinAt \ud835\udd5c c s x) (d : \ud835\udd5c') :\n    DifferentiableWithinAt \ud835\udd5c (fun x => c x / d) s x :=\n  (hc.HasDerivWithinAt.div_const _).DifferentiableWithinAt\n#align differentiable_within_at.div_const DifferentiableWithinAt.div_const\n\n@[simp]\ntheorem DifferentiableAt.div_const (hc : DifferentiableAt \ud835\udd5c c x) (d : \ud835\udd5c') :\n    DifferentiableAt \ud835\udd5c (fun x => c x / d) x :=\n  (hc.HasDerivAt.div_const _).DifferentiableAt\n#align differentiable_at.div_const DifferentiableAt.div_const\n\ntheorem DifferentiableOn.div_const (hc : DifferentiableOn \ud835\udd5c c s) (d : \ud835\udd5c') :\n    DifferentiableOn \ud835\udd5c (fun x => c x / d) s := fun x hx => (hc x hx).div_const d\n#align differentiable_on.div_const DifferentiableOn.div_const\n\n@[simp]\ntheorem Differentiable.div_const (hc : Differentiable \ud835\udd5c c) (d : \ud835\udd5c') :\n    Differentiable \ud835\udd5c fun x => c x / d := fun x => (hc x).div_const d\n#align differentiable.div_const Differentiable.div_const\n\ntheorem derivWithin_div_const (hc : DifferentiableWithinAt \ud835\udd5c c s x) (d : \ud835\udd5c')\n    (hxs : UniqueDiffWithinAt \ud835\udd5c s x) : derivWithin (fun x => c x / d) s x = derivWithin c s x / d :=\n  by simp [div_eq_inv_mul, derivWithin_const_mul, hc, hxs]\n#align deriv_within_div_const derivWithin_div_const\n\n@[simp]\ntheorem deriv_div_const (d : \ud835\udd5c') : deriv (fun x => c x / d) x = deriv c x / d := by\n  simp only [div_eq_mul_inv, deriv_mul_const_field]\n#align deriv_div_const deriv_div_const\n\nend Division\n\nsection ClmCompApply\n\n/-! ### Derivative of the pointwise composition/application of continuous linear maps -/\n\n\nopen ContinuousLinearMap\n\nvariable {G : Type _} [NormedAddCommGroup G] [NormedSpace \ud835\udd5c G] {c : \ud835\udd5c \u2192 F \u2192L[\ud835\udd5c] G} {c' : F \u2192L[\ud835\udd5c] G}\n  {d : \ud835\udd5c \u2192 E \u2192L[\ud835\udd5c] F} {d' : E \u2192L[\ud835\udd5c] F} {u : \ud835\udd5c \u2192 F} {u' : F}\n\ntheorem HasStrictDerivAt.clm_comp (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) :\n    HasStrictDerivAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x :=\n  by\n  have := (hc.has_strict_fderiv_at.clm_comp hd.has_strict_fderiv_at).HasStrictDerivAt\n  rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n    one_smul, add_comm] at this\n#align has_strict_deriv_at.clm_comp HasStrictDerivAt.clm_comp\n\ntheorem HasDerivWithinAt.clm_comp (hc : HasDerivWithinAt c c' s x)\n    (hd : HasDerivWithinAt d d' s x) :\n    HasDerivWithinAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') s x :=\n  by\n  have := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).HasDerivWithinAt\n  rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n    one_smul, add_comm] at this\n#align has_deriv_within_at.clm_comp HasDerivWithinAt.clm_comp\n\ntheorem HasDerivAt.clm_comp (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) :\n    HasDerivAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.clm_comp hd\n#align has_deriv_at.clm_comp HasDerivAt.clm_comp\n\ntheorem derivWithin_clm_comp (hc : DifferentiableWithinAt \ud835\udd5c c s x)\n    (hd : DifferentiableWithinAt \ud835\udd5c d s x) (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun y => (c y).comp (d y)) s x =\n      (derivWithin c s x).comp (d x) + (c x).comp (derivWithin d s x) :=\n  (hc.HasDerivWithinAt.clm_comp hd.HasDerivWithinAt).derivWithin hxs\n#align deriv_within_clm_comp derivWithin_clm_comp\n\ntheorem deriv_clm_comp (hc : DifferentiableAt \ud835\udd5c c x) (hd : DifferentiableAt \ud835\udd5c d x) :\n    deriv (fun y => (c y).comp (d y)) x = (deriv c x).comp (d x) + (c x).comp (deriv d x) :=\n  (hc.HasDerivAt.clm_comp hd.HasDerivAt).deriv\n#align deriv_clm_comp deriv_clm_comp\n\ntheorem HasStrictDerivAt.clm_apply (hc : HasStrictDerivAt c c' x) (hu : HasStrictDerivAt u u' x) :\n    HasStrictDerivAt (fun y => (c y) (u y)) (c' (u x) + c x u') x :=\n  by\n  have := (hc.has_strict_fderiv_at.clm_apply hu.has_strict_fderiv_at).HasStrictDerivAt\n  rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n    one_smul, add_comm] at this\n#align has_strict_deriv_at.clm_apply HasStrictDerivAt.clm_apply\n\ntheorem HasDerivWithinAt.clm_apply (hc : HasDerivWithinAt c c' s x)\n    (hu : HasDerivWithinAt u u' s x) :\n    HasDerivWithinAt (fun y => (c y) (u y)) (c' (u x) + c x u') s x :=\n  by\n  have := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).HasDerivWithinAt\n  rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n    one_smul, add_comm] at this\n#align has_deriv_within_at.clm_apply HasDerivWithinAt.clm_apply\n\ntheorem HasDerivAt.clm_apply (hc : HasDerivAt c c' x) (hu : HasDerivAt u u' x) :\n    HasDerivAt (fun y => (c y) (u y)) (c' (u x) + c x u') x :=\n  by\n  have := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).HasDerivAt\n  rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,\n    one_smul, add_comm] at this\n#align has_deriv_at.clm_apply HasDerivAt.clm_apply\n\ntheorem derivWithin_clm_apply (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (hc : DifferentiableWithinAt \ud835\udd5c c s x)\n    (hu : DifferentiableWithinAt \ud835\udd5c u s x) :\n    derivWithin (fun y => (c y) (u y)) s x = derivWithin c s x (u x) + c x (derivWithin u s x) :=\n  (hc.HasDerivWithinAt.clm_apply hu.HasDerivWithinAt).derivWithin hxs\n#align deriv_within_clm_apply derivWithin_clm_apply\n\ntheorem deriv_clm_apply (hc : DifferentiableAt \ud835\udd5c c x) (hu : DifferentiableAt \ud835\udd5c u x) :\n    deriv (fun y => (c y) (u y)) x = deriv c x (u x) + c x (deriv u x) :=\n  (hc.HasDerivAt.clm_apply hu.HasDerivAt).deriv\n#align deriv_clm_apply deriv_clm_apply\n\nend ClmCompApply\n\ntheorem HasStrictDerivAt.hasStrictFderivAt_equiv {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' x : \ud835\udd5c}\n    (hf : HasStrictDerivAt f f' x) (hf' : f' \u2260 0) :\n    HasStrictFderivAt f (ContinuousLinearEquiv.unitsEquivAut \ud835\udd5c (Units.mk0 f' hf') : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\n  hf\n#align has_strict_deriv_at.has_strict_fderiv_at_equiv HasStrictDerivAt.hasStrictFderivAt_equiv\n\ntheorem HasDerivAt.hasFderivAt_equiv {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' x : \ud835\udd5c} (hf : HasDerivAt f f' x)\n    (hf' : f' \u2260 0) :\n    HasFderivAt f (ContinuousLinearEquiv.unitsEquivAut \ud835\udd5c (Units.mk0 f' hf') : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\n  hf\n#align has_deriv_at.has_fderiv_at_equiv HasDerivAt.hasFderivAt_equiv\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'\u207b\u00b9` at `a`\nin the strict sense.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have an\ninverse function. -/\ntheorem HasStrictDerivAt.of_local_left_inverse {f g : \ud835\udd5c \u2192 \ud835\udd5c} {f' a : \ud835\udd5c} (hg : ContinuousAt g a)\n    (hf : HasStrictDerivAt f f' (g a)) (hf' : f' \u2260 0) (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n    HasStrictDerivAt g f'\u207b\u00b9 a :=\n  (hf.hasStrictFderivAt_equiv hf').of_local_left_inverse hg hfg\n#align has_strict_deriv_at.of_local_left_inverse HasStrictDerivAt.of_local_left_inverse\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a\nnonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` has the derivative `f'\u207b\u00b9`\nat `a` in the strict sense.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\ntheorem LocalHomeomorph.hasStrictDerivAt_symm (f : LocalHomeomorph \ud835\udd5c \ud835\udd5c) {a f' : \ud835\udd5c}\n    (ha : a \u2208 f.target) (hf' : f' \u2260 0) (htff' : HasStrictDerivAt f f' (f.symm a)) :\n    HasStrictDerivAt f.symm f'\u207b\u00b9 a :=\n  htff'.of_local_left_inverse (f.symm.ContinuousAt ha) hf' (f.eventually_right_inverse ha)\n#align local_homeomorph.has_strict_deriv_at_symm LocalHomeomorph.hasStrictDerivAt_symm\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a`, then `g` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\ntheorem HasDerivAt.of_local_left_inverse {f g : \ud835\udd5c \u2192 \ud835\udd5c} {f' a : \ud835\udd5c} (hg : ContinuousAt g a)\n    (hf : HasDerivAt f f' (g a)) (hf' : f' \u2260 0) (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n    HasDerivAt g f'\u207b\u00b9 a :=\n  (hf.hasFderivAt_equiv hf').of_local_left_inverse hg hfg\n#align has_deriv_at.of_local_left_inverse HasDerivAt.of_local_left_inverse\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an\nnonzero derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\ntheorem LocalHomeomorph.hasDerivAt_symm (f : LocalHomeomorph \ud835\udd5c \ud835\udd5c) {a f' : \ud835\udd5c} (ha : a \u2208 f.target)\n    (hf' : f' \u2260 0) (htff' : HasDerivAt f f' (f.symm a)) : HasDerivAt f.symm f'\u207b\u00b9 a :=\n  htff'.of_local_left_inverse (f.symm.ContinuousAt ha) hf' (f.eventually_right_inverse ha)\n#align local_homeomorph.has_deriv_at_symm LocalHomeomorph.hasDerivAt_symm\n\ntheorem HasDerivAt.eventually_ne (h : HasDerivAt f f' x) (hf' : f' \u2260 0) :\n    \u2200\u1da0 z in \ud835\udcdd[\u2260] x, f z \u2260 f x :=\n  (hasDerivAt_iff_hasFderivAt.1 h).eventually_ne\n    \u27e8\u2016f'\u2016\u207b\u00b9, fun z => by field_simp [norm_smul, mt norm_eq_zero.1 hf'] \u27e9\n#align has_deriv_at.eventually_ne HasDerivAt.eventually_ne\n\ntheorem HasDerivAt.tendsto_punctured_nhds (h : HasDerivAt f f' x) (hf' : f' \u2260 0) :\n    Tendsto f (\ud835\udcdd[\u2260] x) (\ud835\udcdd[\u2260] f x) :=\n  tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.ContinuousAt.ContinuousWithinAt\n    (h.eventually_ne hf')\n#align has_deriv_at.tendsto_punctured_nhds HasDerivAt.tendsto_punctured_nhds\n\ntheorem not_differentiableWithinAt_of_local_left_inverse_hasDerivWithinAt_zero {f g : \ud835\udd5c \u2192 \ud835\udd5c} {a : \ud835\udd5c}\n    {s t : Set \ud835\udd5c} (ha : a \u2208 s) (hsu : UniqueDiffWithinAt \ud835\udd5c s a) (hf : HasDerivWithinAt f 0 t (g a))\n    (hst : MapsTo g s t) (hfg : f \u2218 g =\u1da0[\ud835\udcdd[s] a] id) : \u00acDifferentiableWithinAt \ud835\udd5c g s a :=\n  by\n  intro hg\n  have := (hf.comp a hg.has_deriv_within_at hst).congr_of_eventuallyEq_of_mem hfg.symm ha\n  simpa using hsu.eq_deriv _ this (hasDerivWithinAt_id _ _)\n#align not_differentiable_within_at_of_local_left_inverse_has_deriv_within_at_zero not_differentiableWithinAt_of_local_left_inverse_hasDerivWithinAt_zero\n\ntheorem not_differentiableAt_of_local_left_inverse_hasDerivAt_zero {f g : \ud835\udd5c \u2192 \ud835\udd5c} {a : \ud835\udd5c}\n    (hf : HasDerivAt f 0 (g a)) (hfg : f \u2218 g =\u1da0[\ud835\udcdd a] id) : \u00acDifferentiableAt \ud835\udd5c g a :=\n  by\n  intro hg\n  have := (hf.comp a hg.has_deriv_at).congr_of_eventuallyEq hfg.symm\n  simpa using this.unique (hasDerivAt_id a)\n#align not_differentiable_at_of_local_left_inverse_has_deriv_at_zero not_differentiableAt_of_local_left_inverse_hasDerivAt_zero\n\nend\n\nnamespace Polynomial\n\n/-! ### Derivative of a polynomial -/\n\n\nvariable {x : \ud835\udd5c} {s : Set \ud835\udd5c}\n\nvariable (p : \ud835\udd5c[X])\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected theorem hasStrictDerivAt (x : \ud835\udd5c) :\n    HasStrictDerivAt (fun x => p.eval x) (p.derivative.eval x) x :=\n  by\n  apply p.induction_on\n  \u00b7 simp [hasStrictDerivAt_const]\n  \u00b7 intro p q hp hq\n    convert hp.add hq <;> simp\n  \u00b7 intro n a h\n    convert h.mul (hasStrictDerivAt_id x)\n    \u00b7 ext y\n      simp [pow_add, mul_assoc]\n    \u00b7 simp only [pow_add, pow_one, derivative_mul, derivative_C, MulZeroClass.zero_mul,\n        derivative_X_pow, derivative_X, mul_one, zero_add, eval_mul, eval_C, eval_add,\n        eval_nat_cast, eval_pow, eval_X, id.def]\n      ring\n#align polynomial.has_strict_deriv_at Polynomial.hasStrictDerivAt\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected theorem hasDerivAt (x : \ud835\udd5c) : HasDerivAt (fun x => p.eval x) (p.derivative.eval x) x :=\n  (p.HasStrictDerivAt x).HasDerivAt\n#align polynomial.has_deriv_at Polynomial.hasDerivAt\n\nprotected theorem hasDerivWithinAt (x : \ud835\udd5c) (s : Set \ud835\udd5c) :\n    HasDerivWithinAt (fun x => p.eval x) (p.derivative.eval x) s x :=\n  (p.HasDerivAt x).HasDerivWithinAt\n#align polynomial.has_deriv_within_at Polynomial.hasDerivWithinAt\n\nprotected theorem differentiableAt : DifferentiableAt \ud835\udd5c (fun x => p.eval x) x :=\n  (p.HasDerivAt x).DifferentiableAt\n#align polynomial.differentiable_at Polynomial.differentiableAt\n\nprotected theorem differentiableWithinAt : DifferentiableWithinAt \ud835\udd5c (fun x => p.eval x) s x :=\n  p.DifferentiableAt.DifferentiableWithinAt\n#align polynomial.differentiable_within_at Polynomial.differentiableWithinAt\n\nprotected theorem differentiable : Differentiable \ud835\udd5c fun x => p.eval x := fun x => p.DifferentiableAt\n#align polynomial.differentiable Polynomial.differentiable\n\nprotected theorem differentiableOn : DifferentiableOn \ud835\udd5c (fun x => p.eval x) s :=\n  p.Differentiable.DifferentiableOn\n#align polynomial.differentiable_on Polynomial.differentiableOn\n\n@[simp]\nprotected theorem deriv : deriv (fun x => p.eval x) x = p.derivative.eval x :=\n  (p.HasDerivAt x).deriv\n#align polynomial.deriv Polynomial.deriv\n\nprotected theorem derivWithin (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun x => p.eval x) s x = p.derivative.eval x :=\n  by\n  rw [DifferentiableAt.derivWithin p.differentiable_at hxs]\n  exact p.deriv\n#align polynomial.deriv_within Polynomial.derivWithin\n\nprotected theorem hasFderivAt (x : \ud835\udd5c) :\n    HasFderivAt (fun x => p.eval x) (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x)) x :=\n  p.HasDerivAt x\n#align polynomial.has_fderiv_at Polynomial.hasFderivAt\n\nprotected theorem hasFderivWithinAt (x : \ud835\udd5c) :\n    HasFderivWithinAt (fun x => p.eval x) (smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x)) s x :=\n  (p.HasFderivAt x).HasFderivWithinAt\n#align polynomial.has_fderiv_within_at Polynomial.hasFderivWithinAt\n\n@[simp]\nprotected theorem fderiv :\n    fderiv \ud835\udd5c (fun x => p.eval x) x = smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x) :=\n  (p.HasFderivAt x).fderiv\n#align polynomial.fderiv Polynomial.fderiv\n\nprotected theorem fderivWithin (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    fderivWithin \ud835\udd5c (fun x => p.eval x) s x = smulRight (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x) :=\n  (p.HasFderivWithinAt x).fderivWithin hxs\n#align polynomial.fderiv_within Polynomial.fderivWithin\n\nend Polynomial\n\nsection Pow\n\n/-! ### Derivative of `x \u21a6 x^n` for `n : \u2115` -/\n\n\nvariable {x : \ud835\udd5c} {s : Set \ud835\udd5c} {c : \ud835\udd5c \u2192 \ud835\udd5c} {c' : \ud835\udd5c}\n\nvariable (n : \u2115)\n\ntheorem hasStrictDerivAt_pow (n : \u2115) (x : \ud835\udd5c) :\n    HasStrictDerivAt (fun x => x ^ n) ((n : \ud835\udd5c) * x ^ (n - 1)) x :=\n  by\n  convert(Polynomial.C (1 : \ud835\udd5c) * Polynomial.X ^ n).HasStrictDerivAt x\n  \u00b7 simp\n  \u00b7 rw [Polynomial.derivative_C_mul_X_pow]\n    simp\n#align has_strict_deriv_at_pow hasStrictDerivAt_pow\n\ntheorem hasDerivAt_pow (n : \u2115) (x : \ud835\udd5c) : HasDerivAt (fun x => x ^ n) ((n : \ud835\udd5c) * x ^ (n - 1)) x :=\n  (hasStrictDerivAt_pow n x).HasDerivAt\n#align has_deriv_at_pow hasDerivAt_pow\n\ntheorem hasDerivWithinAt_pow (n : \u2115) (x : \ud835\udd5c) (s : Set \ud835\udd5c) :\n    HasDerivWithinAt (fun x => x ^ n) ((n : \ud835\udd5c) * x ^ (n - 1)) s x :=\n  (hasDerivAt_pow n x).HasDerivWithinAt\n#align has_deriv_within_at_pow hasDerivWithinAt_pow\n\ntheorem differentiableAt_pow : DifferentiableAt \ud835\udd5c (fun x => x ^ n) x :=\n  (hasDerivAt_pow n x).DifferentiableAt\n#align differentiable_at_pow differentiableAt_pow\n\ntheorem differentiableWithinAt_pow : DifferentiableWithinAt \ud835\udd5c (fun x => x ^ n) s x :=\n  (differentiableAt_pow n).DifferentiableWithinAt\n#align differentiable_within_at_pow differentiableWithinAt_pow\n\ntheorem differentiable_pow : Differentiable \ud835\udd5c fun x : \ud835\udd5c => x ^ n := fun x => differentiableAt_pow n\n#align differentiable_pow differentiable_pow\n\ntheorem differentiableOn_pow : DifferentiableOn \ud835\udd5c (fun x => x ^ n) s :=\n  (differentiable_pow n).DifferentiableOn\n#align differentiable_on_pow differentiableOn_pow\n\ntheorem deriv_pow : deriv (fun x => x ^ n) x = (n : \ud835\udd5c) * x ^ (n - 1) :=\n  (hasDerivAt_pow n x).deriv\n#align deriv_pow deriv_pow\n\n@[simp]\ntheorem deriv_pow' : (deriv fun x => x ^ n) = fun x => (n : \ud835\udd5c) * x ^ (n - 1) :=\n  funext fun x => deriv_pow n\n#align deriv_pow' deriv_pow'\n\ntheorem derivWithin_pow (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun x => x ^ n) s x = (n : \ud835\udd5c) * x ^ (n - 1) :=\n  (hasDerivWithinAt_pow n x s).derivWithin hxs\n#align deriv_within_pow derivWithin_pow\n\ntheorem HasDerivWithinAt.pow (hc : HasDerivWithinAt c c' s x) :\n    HasDerivWithinAt (fun y => c y ^ n) ((n : \ud835\udd5c) * c x ^ (n - 1) * c') s x :=\n  (hasDerivAt_pow n (c x)).comp_hasDerivWithinAt x hc\n#align has_deriv_within_at.pow HasDerivWithinAt.pow\n\ntheorem HasDerivAt.pow (hc : HasDerivAt c c' x) :\n    HasDerivAt (fun y => c y ^ n) ((n : \ud835\udd5c) * c x ^ (n - 1) * c') x :=\n  by\n  rw [\u2190 hasDerivWithinAt_univ] at *\n  exact hc.pow n\n#align has_deriv_at.pow HasDerivAt.pow\n\ntheorem derivWithin_pow' (hc : DifferentiableWithinAt \ud835\udd5c c s x) (hxs : UniqueDiffWithinAt \ud835\udd5c s x) :\n    derivWithin (fun x => c x ^ n) s x = (n : \ud835\udd5c) * c x ^ (n - 1) * derivWithin c s x :=\n  (hc.HasDerivWithinAt.pow n).derivWithin hxs\n#align deriv_within_pow' derivWithin_pow'\n\n@[simp]\ntheorem deriv_pow'' (hc : DifferentiableAt \ud835\udd5c c x) :\n    deriv (fun x => c x ^ n) x = (n : \ud835\udd5c) * c x ^ (n - 1) * deriv c x :=\n  (hc.HasDerivAt.pow n).deriv\n#align deriv_pow'' deriv_pow''\n\nend Pow\n\nsection Zpow\n\n/-! ### Derivative of `x \u21a6 x^m` for `m : \u2124` -/\n\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace \ud835\udd5c E] {x : \ud835\udd5c} {s : Set \ud835\udd5c} {m : \u2124}\n\ntheorem hasStrictDerivAt_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) :\n    HasStrictDerivAt (fun x => x ^ m) ((m : \ud835\udd5c) * x ^ (m - 1)) x :=\n  by\n  have : \u2200 m : \u2124, 0 < m \u2192 HasStrictDerivAt (fun x => x ^ m) ((m : \ud835\udd5c) * x ^ (m - 1)) x :=\n    by\n    intro m hm\n    lift m to \u2115 using le_of_lt hm\n    simp only [zpow_ofNat, Int.cast_ofNat]\n    convert hasStrictDerivAt_pow _ _ using 2\n    rw [\u2190 Int.ofNat_one, \u2190 Int.ofNat_sub, zpow_ofNat]\n    norm_cast  at hm\n    exact Nat.succ_le_of_lt hm\n  rcases lt_trichotomy m 0 with (hm | hm | hm)\n  \u00b7 have hx : x \u2260 0 := h.resolve_right hm.not_le\n    have := (hasStrictDerivAt_inv _).scomp _ (this (-m) (neg_pos.2 hm)) <;> [skip,\n      exact zpow_ne_zero_of_ne_zero hx _]\n    simp only [(\u00b7 \u2218 \u00b7), zpow_neg, one_div, inv_inv, smul_eq_mul] at this\n    convert this using 1\n    rw [sq, mul_inv, inv_inv, Int.cast_neg, neg_mul, neg_mul_neg, \u2190 zpow_add\u2080 hx, mul_assoc, \u2190\n      zpow_add\u2080 hx]\n    congr\n    abel\n  \u00b7 simp only [hm, zpow_zero, Int.cast_zero, MulZeroClass.zero_mul, hasStrictDerivAt_const]\n  \u00b7 exact this m hm\n#align has_strict_deriv_at_zpow hasStrictDerivAt_zpow\n\ntheorem hasDerivAt_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) :\n    HasDerivAt (fun x => x ^ m) ((m : \ud835\udd5c) * x ^ (m - 1)) x :=\n  (hasStrictDerivAt_zpow m x h).HasDerivAt\n#align has_deriv_at_zpow hasDerivAt_zpow\n\ntheorem hasDerivWithinAt_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) (s : Set \ud835\udd5c) :\n    HasDerivWithinAt (fun x => x ^ m) ((m : \ud835\udd5c) * x ^ (m - 1)) s x :=\n  (hasDerivAt_zpow m x h).HasDerivWithinAt\n#align has_deriv_within_at_zpow hasDerivWithinAt_zpow\n\ntheorem differentiableAt_zpow : DifferentiableAt \ud835\udd5c (fun x => x ^ m) x \u2194 x \u2260 0 \u2228 0 \u2264 m :=\n  \u27e8fun H => NormedField.continuousAt_zpow.1 H.ContinuousAt, fun H =>\n    (hasDerivAt_zpow m x H).DifferentiableAt\u27e9\n#align differentiable_at_zpow differentiableAt_zpow\n\ntheorem differentiableWithinAt_zpow (m : \u2124) (x : \ud835\udd5c) (h : x \u2260 0 \u2228 0 \u2264 m) :\n    DifferentiableWithinAt \ud835\udd5c (fun x => x ^ m) s x :=\n  (differentiableAt_zpow.mpr h).DifferentiableWithinAt\n#align differentiable_within_at_zpow differentiableWithinAt_zpow\n\ntheorem differentiableOn_zpow (m : \u2124) (s : Set \ud835\udd5c) (h : (0 : \ud835\udd5c) \u2209 s \u2228 0 \u2264 m) :\n    DifferentiableOn \ud835\udd5c (fun x => x ^ m) s := fun x hxs =>\n  differentiableWithinAt_zpow m x <| h.imp_left <| ne_of_mem_of_not_mem hxs\n#align differentiable_on_zpow differentiableOn_zpow\n\ntheorem deriv_zpow (m : \u2124) (x : \ud835\udd5c) : deriv (fun x => x ^ m) x = m * x ^ (m - 1) :=\n  by\n  by_cases H : x \u2260 0 \u2228 0 \u2264 m\n  \u00b7 exact (hasDerivAt_zpow m x H).deriv\n  \u00b7 rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_zpow.1 H)]\n    push_neg  at H\n    rcases H with \u27e8rfl, hm\u27e9\n    rw [zero_zpow _ ((sub_one_lt _).trans hm).Ne, MulZeroClass.mul_zero]\n#align deriv_zpow deriv_zpow\n\n@[simp]\ntheorem deriv_zpow' (m : \u2124) : (deriv fun x : \ud835\udd5c => x ^ m) = fun x => m * x ^ (m - 1) :=\n  funext <| deriv_zpow m\n#align deriv_zpow' deriv_zpow'\n\ntheorem derivWithin_zpow (hxs : UniqueDiffWithinAt \ud835\udd5c s x) (h : x \u2260 0 \u2228 0 \u2264 m) :\n    derivWithin (fun x => x ^ m) s x = (m : \ud835\udd5c) * x ^ (m - 1) :=\n  (hasDerivWithinAt_zpow m x h s).derivWithin hxs\n#align deriv_within_zpow derivWithin_zpow\n\n@[simp]\ntheorem iter_deriv_zpow' (m : \u2124) (k : \u2115) :\n    ((deriv^[k]) fun x : \ud835\udd5c => x ^ m) = fun x => (\u220f i in Finset.range k, m - i) * x ^ (m - k) :=\n  by\n  induction' k with k ihk\n  \u00b7 simp only [one_mul, Int.ofNat_zero, id, sub_zero, Finset.prod_range_zero, Function.iterate_zero]\n  \u00b7\n    simp only [Function.iterate_succ_apply', ihk, deriv_const_mul_field', deriv_zpow',\n      Finset.prod_range_succ, Int.ofNat_succ, \u2190 sub_sub, Int.cast_sub, Int.cast_ofNat, mul_assoc]\n#align iter_deriv_zpow' iter_deriv_zpow'\n\ntheorem iter_deriv_zpow (m : \u2124) (x : \ud835\udd5c) (k : \u2115) :\n    (deriv^[k]) (fun y => y ^ m) x = (\u220f i in Finset.range k, m - i) * x ^ (m - k) :=\n  congr_fun (iter_deriv_zpow' m k) x\n#align iter_deriv_zpow iter_deriv_zpow\n\ntheorem iter_deriv_pow (n : \u2115) (x : \ud835\udd5c) (k : \u2115) :\n    (deriv^[k]) (fun x : \ud835\udd5c => x ^ n) x = (\u220f i in Finset.range k, n - i) * x ^ (n - k) :=\n  by\n  simp only [\u2190 zpow_ofNat, iter_deriv_zpow, Int.cast_ofNat]\n  cases' le_or_lt k n with hkn hnk\n  \u00b7 rw [Int.ofNat_sub hkn]\n  \u00b7 have : (\u220f i in Finset.range k, (n - i : \ud835\udd5c)) = 0 :=\n      Finset.prod_eq_zero (Finset.mem_range.2 hnk) (sub_self _)\n    simp only [this, MulZeroClass.zero_mul]\n#align iter_deriv_pow iter_deriv_pow\n\n@[simp]\ntheorem iter_deriv_pow' (n k : \u2115) :\n    ((deriv^[k]) fun x : \ud835\udd5c => x ^ n) = fun x => (\u220f i in Finset.range k, n - i) * x ^ (n - k) :=\n  funext fun x => iter_deriv_pow n x k\n#align iter_deriv_pow' iter_deriv_pow'\n\ntheorem iter_deriv_inv (k : \u2115) (x : \ud835\udd5c) :\n    (deriv^[k]) Inv.inv x = (\u220f i in Finset.range k, -1 - i) * x ^ (-1 - k : \u2124) := by\n  simpa only [zpow_neg_one, Int.cast_neg, Int.cast_one] using iter_deriv_zpow (-1) x k\n#align iter_deriv_inv iter_deriv_inv\n\n@[simp]\ntheorem iter_deriv_inv' (k : \u2115) :\n    (deriv^[k]) Inv.inv = fun x : \ud835\udd5c => (\u220f i in Finset.range k, -1 - i) * x ^ (-1 - k : \u2124) :=\n  funext (iter_deriv_inv k)\n#align iter_deriv_inv' iter_deriv_inv'\n\nvariable {f : E \u2192 \ud835\udd5c} {t : Set E} {a : E}\n\ntheorem DifferentiableWithinAt.zpow (hf : DifferentiableWithinAt \ud835\udd5c f t a) (h : f a \u2260 0 \u2228 0 \u2264 m) :\n    DifferentiableWithinAt \ud835\udd5c (fun x => f x ^ m) t a :=\n  (differentiableAt_zpow.2 h).comp_differentiableWithinAt a hf\n#align differentiable_within_at.zpow DifferentiableWithinAt.zpow\n\ntheorem DifferentiableAt.zpow (hf : DifferentiableAt \ud835\udd5c f a) (h : f a \u2260 0 \u2228 0 \u2264 m) :\n    DifferentiableAt \ud835\udd5c (fun x => f x ^ m) a :=\n  (differentiableAt_zpow.2 h).comp a hf\n#align differentiable_at.zpow DifferentiableAt.zpow\n\ntheorem DifferentiableOn.zpow (hf : DifferentiableOn \ud835\udd5c f t) (h : (\u2200 x \u2208 t, f x \u2260 0) \u2228 0 \u2264 m) :\n    DifferentiableOn \ud835\udd5c (fun x => f x ^ m) t := fun x hx =>\n  (hf x hx).zpow <| h.imp_left fun h => h x hx\n#align differentiable_on.zpow DifferentiableOn.zpow\n\ntheorem Differentiable.zpow (hf : Differentiable \ud835\udd5c f) (h : (\u2200 x, f x \u2260 0) \u2228 0 \u2264 m) :\n    Differentiable \ud835\udd5c fun x => f x ^ m := fun x => (hf x).zpow <| h.imp_left fun h => h x\n#align differentiable.zpow Differentiable.zpow\n\nend Zpow\n\n/-! ### Support of derivatives -/\n\n\nsection Support\n\nopen Function\n\nvariable {F : Type _} [NormedAddCommGroup F] [NormedSpace \ud835\udd5c F] {f : \ud835\udd5c \u2192 F}\n\ntheorem support_deriv_subset : support (deriv f) \u2286 tsupport f :=\n  by\n  intro x\n  rw [\u2190 not_imp_not]\n  intro h2x\n  rw [not_mem_tsupport_iff_eventuallyEq] at h2x\n  exact nmem_support.mpr (h2x.deriv_eq.trans (deriv_const x 0))\n#align support_deriv_subset support_deriv_subset\n\ntheorem HasCompactSupport.deriv (hf : HasCompactSupport f) : HasCompactSupport (deriv f) :=\n  hf.mono' support_deriv_subset\n#align has_compact_support.deriv HasCompactSupport.deriv\n\nend Support\n\n/-! ### Upper estimates on liminf and limsup -/\n\n\nsection Real\n\nvariable {f : \u211d \u2192 \u211d} {f' : \u211d} {s : Set \u211d} {x : \u211d} {r : \u211d}\n\ntheorem HasDerivWithinAt.limsup_slope_le (hf : HasDerivWithinAt f f' s x) (hr : f' < r) :\n    \u2200\u1da0 z in \ud835\udcdd[s \\ {x}] x, slope f x z < r :=\n  hasDerivWithinAt_iff_tendsto_slope.1 hf (IsOpen.mem_nhds isOpen_Iio hr)\n#align has_deriv_within_at.limsup_slope_le HasDerivWithinAt.limsup_slope_le\n\ntheorem HasDerivWithinAt.limsup_slope_le' (hf : HasDerivWithinAt f f' s x) (hs : x \u2209 s)\n    (hr : f' < r) : \u2200\u1da0 z in \ud835\udcdd[s] x, slope f x z < r :=\n  (hasDerivWithinAt_iff_tendsto_slope' hs).1 hf (IsOpen.mem_nhds isOpen_Iio hr)\n#align has_deriv_within_at.limsup_slope_le' HasDerivWithinAt.limsup_slope_le'\n\ntheorem HasDerivWithinAt.liminf_right_slope_le (hf : HasDerivWithinAt f f' (Ici x) x)\n    (hr : f' < r) : \u2203\u1da0 z in \ud835\udcdd[>] x, slope f x z < r :=\n  (hf.Ioi_of_Ici.limsup_slope_le' (lt_irrefl x) hr).Frequently\n#align has_deriv_within_at.liminf_right_slope_le HasDerivWithinAt.liminf_right_slope_le\n\nend Real\n\nsection RealSpace\n\nopen Metric\n\nvariable {E : Type u} [NormedAddCommGroup E] [NormedSpace \u211d E] {f : \u211d \u2192 E} {f' : E} {s : Set \u211d}\n  {x r : \u211d}\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`\u2016f z - f x\u2016 / \u2016z - x\u2016` is less than `r` in some neighborhood of `x` within `s`.\nIn other words, the limit superior of this ratio as `z` tends to `x` along `s`\nis less than or equal to `\u2016f'\u2016`. -/\ntheorem HasDerivWithinAt.limsup_norm_slope_le (hf : HasDerivWithinAt f f' s x) (hr : \u2016f'\u2016 < r) :\n    \u2200\u1da0 z in \ud835\udcdd[s] x, \u2016z - x\u2016\u207b\u00b9 * \u2016f z - f x\u2016 < r :=\n  by\n  have hr\u2080 : 0 < r := lt_of_le_of_lt (norm_nonneg f') hr\n  have A : \u2200\u1da0 z in \ud835\udcdd[s \\ {x}] x, \u2016(z - x)\u207b\u00b9 \u2022 (f z - f x)\u2016 \u2208 Iio r :=\n    (hasDerivWithinAt_iff_tendsto_slope.1 hf).norm (IsOpen.mem_nhds isOpen_Iio hr)\n  have B : \u2200\u1da0 z in \ud835\udcdd[{x}] x, \u2016(z - x)\u207b\u00b9 \u2022 (f z - f x)\u2016 \u2208 Iio r :=\n    mem_of_superset self_mem_nhdsWithin (singleton_subset_iff.2 <| by simp [hr\u2080])\n  have C := mem_sup.2 \u27e8A, B\u27e9\n  rw [\u2190 nhdsWithin_union, diff_union_self, nhdsWithin_union, mem_sup] at C\n  filter_upwards [C.1]\n  simp only [norm_smul, mem_Iio, norm_inv]\n  exact fun _ => id\n#align has_deriv_within_at.limsup_norm_slope_le HasDerivWithinAt.limsup_norm_slope_le\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`(\u2016f z\u2016 - \u2016f x\u2016) / \u2016z - x\u2016` is less than `r` in some neighborhood of `x` within `s`.\nIn other words, the limit superior of this ratio as `z` tends to `x` along `s`\nis less than or equal to `\u2016f'\u2016`.\n\nThis lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`\nwhere `\u2016f z\u2016 - \u2016f x\u2016` is replaced by `\u2016f z - f x\u2016`. -/\ntheorem HasDerivWithinAt.limsup_slope_norm_le (hf : HasDerivWithinAt f f' s x) (hr : \u2016f'\u2016 < r) :\n    \u2200\u1da0 z in \ud835\udcdd[s] x, \u2016z - x\u2016\u207b\u00b9 * (\u2016f z\u2016 - \u2016f x\u2016) < r :=\n  by\n  apply (hf.limsup_norm_slope_le hr).mono\n  intro z hz\n  refine' lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz\n  exact inv_nonneg.2 (norm_nonneg _)\n#align has_deriv_within_at.limsup_slope_norm_le HasDerivWithinAt.limsup_slope_norm_le\n\n/-- If `f` has derivative `f'` within `(x, +\u221e)` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`\u2016f z - f x\u2016 / \u2016z - x\u2016` is frequently less than `r` as `z \u2192 x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `\u2016f'\u2016`. See also `has_deriv_within_at.limsup_norm_slope_le`\nfor a stronger version using limit superior and any set `s`. -/\ntheorem HasDerivWithinAt.liminf_right_norm_slope_le (hf : HasDerivWithinAt f f' (Ici x) x)\n    (hr : \u2016f'\u2016 < r) : \u2203\u1da0 z in \ud835\udcdd[>] x, \u2016z - x\u2016\u207b\u00b9 * \u2016f z - f x\u2016 < r :=\n  (hf.Ioi_of_Ici.limsup_norm_slope_le hr).Frequently\n#align has_deriv_within_at.liminf_right_norm_slope_le HasDerivWithinAt.liminf_right_norm_slope_le\n\n/-- If `f` has derivative `f'` within `(x, +\u221e)` at `x`, then for any `r > \u2016f'\u2016` the ratio\n`(\u2016f z\u2016 - \u2016f x\u2016) / (z - x)` is frequently less than `r` as `z \u2192 x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `\u2016f'\u2016`.\n\nSee also\n\n* `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using\n  limit superior and any set `s`;\n* `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using\n  `\u2016f z - f x\u2016` instead of `\u2016f z\u2016 - \u2016f x\u2016`. -/\ntheorem HasDerivWithinAt.liminf_right_slope_norm_le (hf : HasDerivWithinAt f f' (Ici x) x)\n    (hr : \u2016f'\u2016 < r) : \u2203\u1da0 z in \ud835\udcdd[>] x, (z - x)\u207b\u00b9 * (\u2016f z\u2016 - \u2016f x\u2016) < r :=\n  by\n  have := (hf.Ioi_of_Ici.limsup_slope_norm_le hr).Frequently\n  refine' this.mp (eventually.mono self_mem_nhdsWithin _)\n  intro z hxz hz\n  rwa [Real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz\n#align has_deriv_within_at.liminf_right_slope_norm_le HasDerivWithinAt.liminf_right_slope_norm_le\n\nend RealSpace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/Calculus/Deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070109242132, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7145577880606727}}
{"text": "-- Inspired by Patrick Massot\n-- This approach differs from that of Patrick's by using continuity instead of boundedness. As with Caratheodory, this hides norms and epsilon-deltas as much as possible.\n-- Boundedness and continuity for linear operators are equivalent on the most common spaces of study, but may diverge on other spaces.\n-- continuity also provides more general proofs than norm arguments.\n-- admittedly, with the more powerful norm_num, the gap between the two approaches is smaller. I still believe continuous is the right way forward. It still replicates less work than boundedness\n-- TODO: Lean still doesn't have pointwise continuity(!). We want that to make proofs more general. It's pretty simple to do.\n-- TODO: continuous at 0/arbitrary point => continuous everywhere\n-- see http://matrixeditions.com/FA.Chap3.1-4.pdf (among others)\n-- TODO: copy module.lean and linear_map_module.lean\n\n\nimport algebra.field\nimport tactic.norm_num\nimport analysis.topology.continuity\nimport .norm\nimport order.complete_lattice\n\nopen lattice\n\nnoncomputable theory\nlocal attribute [instance] classical.prop_decidable\n\nlocal notation f `\u2192_{`:50 a `}`:0 b := filter.tendsto f (nhds a) (nhds b)\n\nuniverses u v w x\nvariables {k : Type u}\nvariables {E : Type v}\nvariables {F : Type w}\nvariables {G : Type x}\n\nstructure is_continuous_linear_map' {k : Type u} {E : Type v} {F : Type w} [normed_field k] [normed_space k E] [normed_space k F] (L : E \u2192 F) extends is_linear_map L : Prop :=\n(continuous : continuous L)\n\n-- def is_continuous_linear_map' (L : E \u2192 F) := (is_linear_map L) \u2227 (continuous L)\n\n-- ways to combine is_continuous_linear_map' proofs\nnamespace is_continuous_linear_map'\nvariables [normed_field k] [normed_space k E] [normed_space k F] [normed_space k G]\nvariable {L : E \u2192 F}\ninclude k\n\nlemma zero : is_continuous_linear_map' (\u03bb (x:E), (0:F)) :=\n\u27e8is_linear_map.map_zero, continuous_const\u27e9\n\nlemma id : is_continuous_linear_map' (id : E \u2192 E) :=\n\u27e8is_linear_map.id, continuous_id\u27e9\n\n-- Remark: smul and add should follow immediately from the fact that normed vectors spaces are topological vector spaces\n\n-- this seems harder than its bounded counterpart (which is admittedly nontrivial)\nlemma smul (c : k) (H : is_continuous_linear_map' L) : is_continuous_linear_map' (\u03bb e, c\u2022L e) := sorry\n\nlemma neg (H : is_continuous_linear_map' L) :\nis_continuous_linear_map' (\u03bb e, -L e) :=\nbegin\n  rcases H with \u27e8lin, cont\u27e9,\n  split,\n  { exact is_linear_map.map_neg lin },\n  { exact continuous_neg cont }\nend\n\nlemma add {L : E \u2192 F} {M : E \u2192 F} (HL : is_continuous_linear_map' L) (HM : is_continuous_linear_map' M) : \nis_continuous_linear_map' (\u03bb e, L e + M e) :=\nbegin\n  rcases HL with \u27e8lin_L, cont_L\u27e9,\n  rcases HM with \u27e8lin_M , cont_M\u27e9,\n  split,\n  { exact is_linear_map.map_add lin_L lin_M },\n  { exact continuous_add cont_L cont_M }\nend\n\nlemma sub {L : E \u2192 F} {M : E \u2192 F} (HL : is_continuous_linear_map' L) (HM : is_continuous_linear_map' M) : \nis_continuous_linear_map' (\u03bb e, L e - M e) := add HL (neg HM)\n\nlemma comp {L : E \u2192 F} {M : F \u2192 G} (HL : is_continuous_linear_map' L) (HM  : is_continuous_linear_map' M) : is_continuous_linear_map' (M \u2218 L) :=\nbegin\nrcases HL with \u27e8lin_L, cont_L\u27e9,\nrcases HM with \u27e8lin_M, cont_M\u27e9,\nsplit,\n{ exact is_linear_map.comp lin_M lin_L },\n{ exact continuous.comp cont_L cont_M }\nend\n\nend is_continuous_linear_map'\n\n-- some holdover code about bounded linear maps. it will eventually be useful, but not currently used, because is_continuous_linear_map' is better\n\nstructure is_bounded_linear_map {k : Type u} {E : Type v} {F : Type w} [normed_field k] [normed_space k E] [normed_space k F] (L : E \u2192 F) extends is_linear_map L : Prop :=\n(bounded : \u2203 M > 0, \u2200 x : E, \u2225L x\u2225 \u2264 M * \u2225x\u2225)\n\nnamespace is_bounded_linear_map\nvariables [normed_field k] [normed_space k E] [normed_space k F] [normed_space k G]\ninclude k\n\nlemma continuous {L : E \u2192 F} (H : is_bounded_linear_map L) : continuous L :=\nbegin\n  rcases H with \u27e8lin, M, Mpos, ineq\u27e9,\n  apply continuous_iff_tendsto.2,\n  intro x,\n  apply tendsto_iff_norm_tendsto_zero.2,\n  replace ineq := \u03bb e, calc \u2225L e - L x\u2225 = \u2225L (e - x)\u2225 : by rw [\u2190(lin.sub e x)]\n  ... \u2264 M*\u2225e-x\u2225 : ineq (e-x),\n  have lim1 : (\u03bb (x:E), M) \u2192_{x} M := tendsto_const_nhds,\n\n  have lim2 : (\u03bb e, e-x) \u2192_{x} 0 := \n  begin \n    have limId := continuous_iff_tendsto.1 continuous_id x,\n    have limx : (\u03bb (e : E), -x) \u2192_{x} -x := tendsto_const_nhds,\n    have := tendsto_add limId limx, \n    simp at this,\n    simpa using this,\n  end,\n  replace lim2 := filter.tendsto.comp lim2 lim_norm_zero,\n  apply squeeze_zero,\n  { simp[norm_nonneg] },\n  { exact ineq },\n  { simpa using tendsto_mul lim1 lim2 }\nend\n\n-- not sure why this fails now\nlemma lim_zero_bounded_linear_map {L : E \u2192 F} (H : is_bounded_linear_map L) : (L \u2192_{0} 0) :=\nby simpa [H.left.zero] using continuous_iff_tendsto.1 H.continuous 0\n\nend is_bounded_linear_map\n\n-- Next lemma is stated for real normed space but it would work as soon as the base field is an extension of \u211d\nlemma bounded_continuous_linear_map {E : Type*} [normed_space \u211d E] {F : Type*}  [normed_space \u211d F] {L : E \u2192 F} \n(h : is_continuous_linear_map' L) : is_bounded_linear_map L :=\nbegin\n  rcases h with \u27e8lin, cont\u27e9,\n  split,\n  assumption,\n  replace cont := continuous_of_metric.1 cont 1 (by norm_num),\n  swap, exact 0,\n  rw[lin.zero] at cont,\n  rcases cont with \u27e8\u03b4, \u03b4_pos, H\u27e9,\n  revert H,\n  repeat { conv in (_ < _ ) { rw norm_dist } },\n  intro H,\n  existsi (\u03b4/2)\u207b\u00b9,\n  have half_\u03b4_pos := half_pos \u03b4_pos,\n  split,\n  exact (inv_pos half_\u03b4_pos),\n  intro x,\n  by_cases h : x = 0,\n  { simp [h, lin.zero] }, -- case x = 0\n  { -- case x \u2260 0   \n    have norm_x_pos : \u2225x\u2225 > 0 := norm_pos_iff.2 h,\n    have norm_x : \u2225x\u2225 \u2260 0 := mt norm_zero_iff_zero.1 h,\n    \n    let p := \u2225x\u2225*(\u03b4/2)\u207b\u00b9,\n    have p_pos : p > 0 := mul_pos norm_x_pos (inv_pos $ half_\u03b4_pos),\n    have p0 := ne_of_gt p_pos,\n\n    let q := (\u03b4/2)*\u2225x\u2225\u207b\u00b9,\n    have q_pos : q > 0 := div_pos half_\u03b4_pos norm_x_pos,\n    have q0 := ne_of_gt q_pos,\n\n    have triv := calc\n     p*q = \u2225x\u2225*((\u03b4/2)\u207b\u00b9*(\u03b4/2))*\u2225x\u2225\u207b\u00b9 : by simp[mul_assoc]\n     ... = 1 : by simp [(inv_mul_cancel $ ne_of_gt half_\u03b4_pos), mul_inv_cancel norm_x],\n      \n    have norm_calc := calc \u2225q\u2022x\u2225 = abs(q)*\u2225x\u2225 : by {rw norm_smul, refl}\n    ... = q*\u2225x\u2225 : by rw [abs_of_nonneg $ le_of_lt q_pos]\n    ... = \u03b4/2 :  by simp [mul_assoc, inv_mul_cancel norm_x]\n    ... < \u03b4 : half_lt_self \u03b4_pos,\n    \n    exact calc \n    \u2225L x\u2225 = \u2225L (1\u2022x)\u2225: by simp\n    ... = \u2225L ((p*q)\u2022x) \u2225 : by {rw [\u2190triv] }\n    ... = \u2225L (p\u2022q\u2022x) \u2225 : by rw mul_smul\n    ... = \u2225p\u2022L (q\u2022x) \u2225 : by rw lin.smul\n    ... = abs(p)*\u2225L (q\u2022x) \u2225 : by { rw norm_smul, refl}\n    ... = p*\u2225L (q\u2022x) \u2225 : by rw [abs_of_nonneg $ le_of_lt $ p_pos]\n    ... \u2264 p*1 : le_of_lt $ mul_lt_mul_of_pos_left (H norm_calc) p_pos \n    ... = p : by simp\n    ... = (\u03b4/2)\u207b\u00b9*\u2225x\u2225 : by simp[mul_comm] }\nend\n\n/- Continuous Linear Maps -/\n\n-- the following approach is based off that of poly in number_theory/dioph.lean, which also packages together functions with their proofs\n\n-- for now, k is implicit\ndef clm {k : Type*} (E : Type*) (F : Type*) [normed_field k] [normed_space k E] [normed_space k F] := { L : E \u2192 F // is_continuous_linear_map' L }\n\n-- TODO: I think clm should be a structure/class (what's the difference?) that extends linear_map (which isn't a structure/class...) and continuous (which also isn't a structure/class). perhaps it should just be coercible instead\n\nnamespace clm\nvariables [normed_field k] [normed_space k E] [normed_space k F] [normed_space k G]\ninclude k\n\n-- TODO: how to get multiplication notation?\n-- we can treat a clm as a function\ninstance : has_coe_to_fun (clm E F) := \u27e8_, \u03bb L, L.1\u27e9\n\n-- treat clm application as \"multiplication\" and give it the right space\n-- Need it to be tupled so continuity makes sense naturally (could also use the approach in topological_structures.lean)\n-- TODO: this feels really bad. The notation is always exposed. Need to find a better way\ndef clm_app_pair (p : (clm E F) \u00d7 E) := p.1 p.2\nlocal notation L `\u2b1d`:70 v := clm_app_pair \u27e8L, v\u27e9\n@[simp] theorem clm_app_pair_eval (L : clm E F) (v) : (L\u2b1dv) = L v := rfl\n\n-- proof data\n-- isc is short for is_clm\ndef isc (L : clm E F) : is_continuous_linear_map' L := L.2\n\n-- functional extensionality\ndef ext {L M : clm E F} (e : \u2200 v, L\u2b1dv = M\u2b1dv) : L = M := \nsubtype.eq (funext e)\n\n-- construct isc given function that is extensionally equal\ndef subst (L : clm E F) (M : E \u2192 F) (e : \u2200 v, L\u2b1dv = M v) : clm E F :=\n-- TODO: I don't know how the proof part works\n\u27e8M, by rw \u2190 (funext e : coe_fn L = M); exact L.isc\u27e9\n-- TODO: this rewrite rule doesn't typecheck!! (it was taken directly from poly unless I messed that up)\n-- @[simp] theorem subst_eval (L M e v) : subst L M e v = M v := rfl\n\n-- composition\n-- TODO: this should probably be an instance\ndef clm_comp : clm E F \u2192 clm F G \u2192 clm E G := \u03bb L M, \u27e8\u03bb v, M (L v), is_continuous_linear_map'.comp L.2 M.2\u27e9\nlocal notation M `\u2218` L := clm_comp L M\n\n-- each of the identities and operations comes with an instance that tells Lean what it is and a simplification lemma that gives Lean a hint about how to \"evaluate\" it\n\n-- zero map\ndef zero : clm E F := \u27e8\u03bb v, 0, is_continuous_linear_map'.zero\u27e9\ninstance : has_zero (clm E F) := \u27e8clm.zero\u27e9\n@[simp] theorem zero_eval (v) : (0 : clm E F)\u2b1dv = 0 := rfl\n\n-- identity map\n-- TODO: not sure if this is necessary or even desirable\ndef one : clm E E := \u27e8\u03bb v, v, is_continuous_linear_map'.id\u27e9\ninstance : has_one (clm E E) := \u27e8clm.one\u27e9\n@[simp] theorem one_eval (v) : (1 : clm E E)\u2b1dv = v := rfl\n\ndef add : clm E F \u2192 clm E F \u2192 clm E F := \u03bb L M, \u27e8L + M, is_continuous_linear_map'.add L.isc M.isc\u27e9\ninstance : has_add (clm E F) := \u27e8clm.add\u27e9\n@[simp] theorem add_eval : \u03a0 (L M : clm E F) v, (L + M)\u2b1dv = L\u2b1dv + M\u2b1dv\n| \u27e8L, pL\u27e9 \u27e8M, pM\u27e9 v := rfl\n\ndef neg : clm E F \u2192 clm E F := \u03bb L, \u27e8\u03bb v, -(L\u2b1dv), is_continuous_linear_map'.neg L.isc\u27e9\ninstance : has_neg (clm E F) := \u27e8clm.neg\u27e9\n\ndef sub : clm E F \u2192 clm E F \u2192 clm E F := \u03bb L M, L + (-M)\ninstance : has_sub (clm E F) := \u27e8clm.sub\u27e9\n@[simp] theorem sub_eval : \u03a0 (L M : clm E F) v, (L - M)\u2b1dv = L\u2b1dv - M\u2b1dv\n| \u27e8L, pL\u27e9 \u27e8M, pM\u27e9 v := rfl\n\n-- TODO: this proof doesn't work even though it does for poly\n-- possibly b/c neg and sub are defined differently?\n-- TODO: this feels weird being disconnected from neg\n@[simp] theorem neg_eval (L : clm E F) (v) : (-L)\u2b1dv = -(L\u2b1dv) := sorry\n-- show (0 - L) v = _, by simp\n\ndef smul : k \u2192 clm E F \u2192 clm E F := \u03bb c L, \u27e8\u03bb v, c\u2022(L\u2b1dv), is_continuous_linear_map'.smul c L.isc\u27e9\ninstance : has_scalar k (clm E F) := \u27e8clm.smul\u27e9\n-- TODO: prove it\n@[simp] theorem smul_eval : \u03a0 c (L : clm E F) v, (c\u2022L)\u2b1dv = c\u2022(L\u2b1dv) := sorry\n\n-- need these instances up here to prove stuff about the op norm\n-- TODO: go straight to module?\ninstance : add_comm_group (clm E F) := by refine\n{\n  add := (+),\n  zero := 0,\n  neg := has_neg.neg,\n  ..\n};\n{ intros; exact ext (\u03bb v, by simp) }\n\n-- TODO: use refine\ninstance : module k (clm E F) :=\n{\n  smul := (\u2022),\n \n  smul_add := by intros; exact ext (\u03bb v, by simp [smul_add]),\n  add_smul := by intros; exact ext (\u03bb v, by simp [add_smul]),\n  mul_smul := by intros; exact ext (\u03bb v, by simp [mul_smul]),\n  one_smul := by intros; exact ext (\u03bb v, by simp [one_smul]),\n}\n\n/- Operator Norm -/\n\n-- TODO: this might be better in a different section, but we'll keep it here for now\n\n-- TODO: leverage boundedness proof above to show that Inf has a value\n-- TODO: big ops should make this easier to define (I think)\ndef op_norm : clm E F \u2192 \u211d := \u03bb L, Inf { M : \u211d | M \u2265 0 \u2227 \u2200 v : E, \u2225L\u2b1dv\u2225 \u2264 M * \u2225v\u2225 }\n-- TODO: implement has_norm\n-- instance : has_norm (clm E F) := \u27e8clm.op_norm\u27e9\n\n-- an alternate version that allows for easier proofs\ntheorem op_norm_alt : \u2200 L : clm E F, op_norm L = Sup { c : \u211d | \u2203 v, \u2225v\u2225 \u2264 1 \u2227 \u2225L\u2b1dv\u2225 = c } := sorry\n\ntheorem op_norm_inhabited {L : clm E F} : (0:\u211d) \u2208 { c : \u211d | \u2203 v, \u2225v\u2225 \u2264 1 \u2227 \u2225L\u2b1dv\u2225 = c } :=\nbegin\nexistsi (0:E),\nsplit,\nsimp [zero_le_one],\napply norm_zero_iff_zero.2,\n-- follows from L being a linear map\nend\n\n-- TODO: uglier than it should be\ntheorem op_norm_nonneg {L : clm E F} : op_norm L \u2265 0 :=\nbegin\nunfold op_norm ge,\napply real.lb_le_Inf,\n-- bounded\n{\n  simp,\n  have : is_bounded_linear_map L,\n  begin\n  -- TODO: I think what's going wrong here is I should have a companion proof that clms and blms are isomorphic\n    -- exact bounded_continuous_linear_map L.isc,\n    admit\n  end,\n  rcases this with \u27e8linear, M, M_pos, M_bound\u27e9,\n  existsi _,\n  split,\n  apply le_of_lt,\n  assumption,\n  assumption\n},\n{\n  intro,\n  simp,\n  intros,\n  assumption\n}\nend\n\ntheorem op_norm_zero_iff_zero {L : clm E F} : op_norm L = 0 \u2194 L = 0 :=\nbegin\nsplit,\n{\n  rw [op_norm_alt],\n  admit\n},\nadmit\nend\n\ntheorem op_norm_pos_homo : \u2200 c (L : clm E F), op_norm (c\u2022L) = \u2225c\u2225 * op_norm L := sorry\n\ntheorem op_norm_triangle : \u2200 (L M : clm E F), op_norm (L + M) \u2264 op_norm L + op_norm M :=\nbegin\nintros,\nsimp [op_norm_alt],\nadmit\nend\n\n-- TODO: is there a way to get the auto-induced metric from a norm without doing any work? Don't do this for now\n\ndef op_dist : clm E F \u2192 clm E F \u2192 \u211d := \u03bb L M, op_norm (L - M)\n\ntheorem op_dist_self : \u2200 x : clm E F, op_dist x x = 0 :=\nbegin\nintros,\nunfold op_dist,\napply op_norm_zero_iff_zero.2,\nsimp [add_left_neg]\nend\n\ntheorem op_dist_eq_of_dist_eq_zero : \u2200 (x y : clm E F), op_dist x y = 0 \u2192 x = y :=\nbegin\nunfold op_dist,\nintros x y h,\napply sub_eq_zero.1,\napply op_norm_zero_iff_zero.1,\nassumption\nend\n-- TODO: clm is an instance of normed_space\n\ntheorem op_dist_comm : \u2200 (x y : clm E F), op_dist x y = op_dist y x :=\nbegin\nintros,\nsimp [op_dist, op_norm],\ncongr,\nfunext,\nadmit,\n-- the propositions are the same by the pos_homo for the underlying norm\nend\n\ntheorem op_dist_triangle : \u2200 (x y z : clm E F), op_dist x z \u2264 op_dist x y + op_dist y z :=\nbegin\nintros,\nunfold op_dist,\ncalc\nop_norm (x - z) = op_norm ((x - y) + (y - z)) : by simp\n            ... \u2264 op_norm (x - y) + op_norm (y - z) : by apply op_norm_triangle\nend\n\n/- Continuous Linear Maps form a normed vector space. -/\n\n-- This is crucial for differentiation.\n\n-- TODO: solve\ninstance : metric_space (clm E F) :=\n{\n  dist := op_dist,\n  \n  dist_self := op_dist_self,\n  eq_of_dist_eq_zero := op_dist_eq_of_dist_eq_zero,\n  dist_comm := op_dist_comm,\n  dist_triangle := op_dist_triangle\n}\n\ninstance : normed_space k (clm E F) :=\n{\n  norm := op_norm,\n\n  dist_eq := by intros; refl,\n  norm_smul := op_norm_pos_homo\n}\n\nend clm\n", "meta": {"author": "joshpoll", "repo": "differential_geometry", "sha": "57e00a7e37b7c4c73c847429171ff63d3a48def5", "save_path": "github-repos/lean/joshpoll-differential_geometry", "path": "github-repos/lean/joshpoll-differential_geometry/differential_geometry-57e00a7e37b7c4c73c847429171ff63d3a48def5/src/differentiability/normed_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.714557780386378}}
{"text": "import group_theory.quotient_group\nimport category_theory.isomorphism_classes\nimport algebra.category.Group\nimport .subgroup\n\nopen subgroup\n\n@[to_additive is_simple_add]\ndef is_simple (G : Type*) [group G] : Prop :=\n\u2200 (N : subgroup G), N.normal \u2192 N = \u22a5 \u2228 N = \u22a4\n\nvariables {G H : Type*} [group G] [group H]\n\n@[simp, to_additive is_simple_add_coe_AddGroup]\nlemma is_simple_coe_Group : is_simple \u21a5(Group.of G) \u2194 is_simple G := by refl\n\n@[simp, to_additive not_is_simple_add]\nlemma not_is_simple : \u00ac is_simple G \u2194 \u2203 (N : subgroup G), N.normal \u2227 N \u2260 \u22a5 \u2227 N \u2260 \u22a4 :=\nby { dsimp [is_simple], push_neg } \n\n@[to_additive is_simple_add_of_surjetion]\nlemma is_simple_of_surjection (hG : is_simple G) (f : G \u2192* H) (hf : function.surjective f) :\n  is_simple H :=\n\u03bb N hN, begin\n  cases hG (N.comap f) (normal.comap hN f),\n  { left, rw [\u2190 map_bot f, \u2190 h, map_comap_eq hf] },\n  right, rw \u2190 comap_top f at h, rw [\u2190 map_comap_eq hf \u22a4, \u2190 h, map_comap_eq hf],\nend\n\n@[to_additive add_equiv_is_simple_add_iff]\nlemma mul_equiv_is_simple_iff (h : G \u2243* H) : is_simple G \u2194 is_simple H :=\n\u27e8\u03bb hG, is_simple_of_surjection hG h.to_monoid_hom h.right_inv.surjective,\n  \u03bb hH, is_simple_of_surjection hH h.symm.to_monoid_hom h.symm.right_inv.surjective\u27e9\n\nopen category_theory\n\n@[simp, to_additive is_simple_add_class] \ndef is_simple_class (C : isomorphism_classes.obj (Cat.of Group)) : Prop :=\nquotient.lift_on' C (\u03bb (G : Group), is_simple G)\n  (\u03bb G H \u27e8h\u27e9, eq_iff_iff.mpr $ mul_equiv_is_simple_iff (iso.Group_iso_to_mul_equiv h))\n\n@[to_additive is_simple_add_quotient_eq]\ndef is_simple_quotient_eq {N M : subgroup G} [N.normal] [M.normal] (h : N = M) :\n  is_simple (quotient_group.quotient N) = is_simple (quotient_group.quotient M) :=\nby unfreezingI { subst h }\n", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/jordanholder/simple_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7145330465924987}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem induction_nfactltnexpnm1ngt3\n  (n : \u2115)\n  (h\u2080 : 3 \u2264 n) :\n  nat.factorial n < n^(n - 1) :=\nbegin\n  induction h\u2080 with k h\u2080 IH,\n  { norm_num },\n  {\n    have k_ge_one : 1 \u2264 k := le_trans dec_trivial h\u2080,\n    calc k.succ.factorial = k.succ * k.factorial : rfl\n                      ... < k.succ * k ^ (k-1) : (mul_lt_mul_left (nat.succ_pos k)).mpr IH\n                      ... \u2264 k.succ * (k.succ) ^ (k-1): nat.mul_le_mul_left _ $ nat.pow_le_pow_of_le_left (nat.le_succ k) (k-1)\n                      ... = k.succ ^ (k-1 + 1): by rw \u2190 (pow_succ k.succ (k-1))\n                      ... = k.succ ^ k: by rw nat.sub_add_cancel k_ge_one,\n  }\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/misc/miniF2F/induction/nfactltnexpnm1ngt3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.7145330401773922}}
{"text": "import .love02_backward_proofs_exercise_sheet\n\n\n/-! # LoVe Homework 2: Backward Proofs\n\nHomework must be done individually. -/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace backward_proofs\n\n\n/-! ## Question 1 (4 points): Connectives and Quantifiers\n\n1.1 (3 points). Complete the following proofs using basic tactics such as\n`intro`, `apply`, and `exact`. -/\n\nlemma B (a b c : Prop) :\n  (a \u2192 b) \u2192 (c \u2192 a) \u2192 c \u2192 b :=\nbegin\n  intros hab hca hc,\n  apply hab,\n  apply hca,\n  exact hc,\nend\n\nlemma S (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 (a \u2192 b) \u2192 a \u2192 c :=\nbegin\n  intros h hab ha,\n  apply h,\n  { apply ha, },\n  { apply hab,\n    apply ha,\n  }\nend\n\nlemma more_nonsense (a b c d : Prop) :\n  ((a \u2192 b) \u2192 c \u2192 d) \u2192 c \u2192 b \u2192 d :=\nbegin\n  intros h hc hb,\n  apply h,\n  intros ha, exact hb,\n  exact hc,\nend\n\nlemma even_more_nonsense (a b c : Prop) :\n  (a \u2192 b) \u2192 (a \u2192 c) \u2192 a \u2192 b \u2192 c :=\nbegin\n  intros hab hac ha hb,\n  apply hac,\n  exact ha,\nend\n\n/-! 1.2 (1 point). Prove the following lemma using basic tactics. -/\n\nlemma weak_peirce (a b : Prop) :\n  ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nbegin\n  intros h, apply h,\n  intros g, apply g,\n  intros f, apply h,\n  intros g', apply f,\nend\n\n\n/-! ## Question 2 (5 points): Logical Connectives\n\n2.1 (1 point). Prove the following property about double negation using basic\ntactics.\n\nHints:\n\n* Keep in mind that `\u00ac a` is the same as `a \u2192 false`. You can start by\n  invoking `rw not_def` four times if this helps you.\n\n* You will need to apply the elimination rule for `false` at a key point in the\n  proof. -/\n\nlemma herman (a : Prop) :\n  \u00ac\u00ac (\u00ac\u00ac a \u2192 a) :=\nsorry\n\n/-! 2.2 (2 points). Prove the missing link in our chain of classical axiom\nimplications.\n\nHints:\n\n* One way to find the definitions of `double_negation` and `excluded_middle`\n  quickly is to\n\n  1. hold the Control (on Linux and Windows) or Command (on macOS) key pressed;\n  2. move the cursor to the identifier `double_negation` or `excluded_middle`;\n  3. click the identifier.\n\n* You can use `rw double_negation` to unfold the definition of\n  `double_negation`, and similarly for the other definitions.\n\n* You will need to apply the double negation hypothesis for `a \u2228 \u00ac a`. You will\n  also need the left and right introduction rules for `\u2228` at some point. -/\n\n#check double_negation\n#check excluded_middle\n\nlemma em_of_dn :\n  double_negation \u2192 excluded_middle :=\nsorry\n\n/-! 2.3 (2 points). We have proved three of the six possible implications between\n`excluded_middle`, `peirce`, and `double_negation`. State and prove the\nthree missing implications, exploiting the three theorems we already have. -/\n\n#check peirce_of_em\n#check dn_of_peirce\n#check em_of_dn\n\n/-! 2.3 (2 points). We have proved three of the six possible implications\nbetween `excluded_middle`, `peirce`, and `double_negation`. State and prove the\nthree missing implications, exploiting the three theorems we already have. -/\n\n#check peirce_of_em\n#check dn_of_peirce\n#check em_of_dn\n\n-- enter your solution here\n\nend backward_proofs\n\nend LoVe\n", "meta": {"author": "superestos", "repo": "-logical_verification", "sha": "dab8b8704680679a78b83c2f82e1113ff098b34f", "save_path": "github-repos/lean/superestos--logical_verification", "path": "github-repos/lean/superestos--logical_verification/-logical_verification-dab8b8704680679a78b83c2f82e1113ff098b34f/lean/love02_backward_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7145035658882615}}
{"text": "--------------------------------\n-- *Quantifiers and Equality* --\n--------------------------------\n\n------------------------------\n-- The Universal Quantifier --\n------------------------------\nvariable (\u03b1 : Type) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\nvariable (refl_r : \u2200 x, r x x)\nvariable (symm_r : \u2200 {x y}, r x y \u2192 r y x)\nvariable (trans_r : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z)\n\nexample (a b c d : \u03b1) (hab : r a b) (hcb : r c b) (hcd : r c d) : r a d :=\n  trans_r (trans_r hab (symm_r hcb)) hcd \n\nuniverse u\n\n-- Equality --\n#check @Eq.refl.{u}\n#check @Eq.symm.{u}\n#check @Eq.trans.{u}\n\nvariable (\u03b1 \u03b2 : Type)\n\nexample (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : (fun x => f x) a = f a := rfl\nexample (a : \u03b1) (b : \u03b1) : (a, b).1 = a := rfl\nexample : 2 + 3 = 5 := rfl\n\nexample (\u03b1 : Type) (a b : \u03b1) (p : \u03b1 \u2192 Prop)\n        (h1 : a = b) (h2 : p a) : p b :=\n  h1 \u25b8 h2\n\nvariable (\u03b1 : Type)\nvariable (a b : \u03b1)\nvariable (f g : \u03b1 \u2192 Nat)\nvariable (h\u2081 : a = b)\nvariable (h\u2082 : f = g)\n\n#check @congrArg\n#check @congrFun\n#check @congr\n\nexample : f a = f b := congrArg f h\u2081\nexample : f a = g a := congrFun h\u2082 a\nexample : f a = g b := congr h\u2082 h\u2081\n\nexample (x y : Nat) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n  have h1 : (x + y) * (x + y) = (x + y) * x + (x + y) * y :=\n    Nat.mul_add (x + y) x y\n  have h2 : (x + y) * (x + y) = x * x + y * x + (x * y + y * y) :=\n    (Nat.add_mul x y x) \u25b8 (Nat.add_mul x y y) \u25b8 h1\n  h2.trans (Nat.add_assoc (x * x + y * x) (x * y) (y * y)).symm\n  \n\nvariable (a b c d e : Nat)\nvariable (h1 : a = b)\nvariable (h2 : b = c + 1)\nvariable (h3 : c = d)\nvariable (h4 : e = 1 + d)\n\ntheorem T : a = e :=\n  by simp [h1, h2, h3, Nat.add_comm, h4]\n\n-- Calculational Proofs --\n#check @Nat.succ_le_succ\n\nexample (a b c d : Nat) (h1 : a = b) (h2 : b \u2264 c) (h3 : c + 1 < d) : a < d :=\n  calc\n    a = b     := h1\n    _ < b + 1 := Nat.lt_succ_self b\n    _ \u2264 c + 1 := Nat.succ_le_succ h2\n    _ < d     := h3\n\nexample (x y : Nat) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n  calc\n    (x + y) * (x + y) = (x + y) * x + (x + y) * y  := by rw [Nat.mul_add]\n        _ = x * x + y * x + (x + y) * y            := by rw [Nat.add_mul]\n        _ = x * x + y * x + (x * y + y * y)        := by rw [Nat.add_mul]\n        _ = x * x + y * x + x * y + y * y          := by rw [\u2190Nat.add_assoc]\n\n-- \u2190 rewrite in the opposite direction\nexample (x y : Nat) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n  by rw[Nat.mul_add, Nat.add_mul, Nat.add_mul, \u2190Nat.add_assoc]\n\n-- The Existential Quantifier --\n#check @Nat.zero_lt_succ\n#check @Exists.intro\n\nexample : \u2203 x : Nat, x > 0 :=\n  have h : 1 > 0 := Nat.zero_lt_succ 0\n  Exists.intro 1 h\n\nexample (x : Nat) (h : x > 0) : \u2203 y, y < x :=\n  Exists.intro 0 h \n\nexample (x y z : Nat) (hxy : x < y) (hyz : y < z) : \u2203 w, x < w \u2227 w < z :=\n  Exists.intro y (And.intro hxy hyz)\n\n/- We can use the anonymous constructor notation *\u27e8t, h\u27e9* for \nExists.intro t h, when the type is clear from the context. -/\n\nexample : \u2203 x : Nat, x > 0 :=\n  have h : 1 > 0 := Nat.zero_lt_succ 0\n  \u27e81, h\u27e9 \n\nexample (x : Nat) (h : x > 0) : \u2203 y, y < x := \u27e80, h\u27e9  \n\nexample (x y z : Nat) (hxy : x < y) (hyz : y < z) : \u2203 w, x < w \u2227 w < z := \n  \u27e8y, hxy, hyz\u27e9 \n\n\n/- Note that Exists.intro has implicit arguments: Lean has to infer the \npredicate p : \u03b1 \u2192 Prop in the conclusion \u2203 x, p x. This is not a trivial affair. \nFor example, if we have have hg : g 0 0 = 0 and write Exists.intro 0 hg, \nthere are many possible values for the predicate p, corresponding to the \ntheorems \u2203 x, g x x = x, \u2203 x, g x x = 0, \u2203 x, g x 0 = x, etc. \nLean uses the context to infer which one is appropriate. This is illustrated \nin the following example, in which we set the option pp.explicit to true to \nask Lean's pretty-printer to show the implicit arguments.-/\n\nvariable (g : Nat \u2192 Nat \u2192 Nat)\nvariable (hg : g 0 0 = 0)\n\ntheorem gex1 : \u2203 x, g x x = x := \u27e80, hg\u27e9\ntheorem gex2 : \u2203 x, g x 0 = x := \u27e80, hg\u27e9\ntheorem gex3 : \u2203 x, g 0 0 = x := \u27e80, hg\u27e9\ntheorem gex4 : \u2203 x, g x x = 0 := \u27e80, hg\u27e9\n\nset_option pp.explicit true  -- display implicit arguments\n#print gex1\n#print gex2\n#print gex3\n#print gex4\n\n/-\nWe can view Exists.intro as an information-hiding operation, since it hides the \nwitness to the body of the assertion. The existential elimination rule, \n*Exists.elim*, performs the opposite operation. It allows us to prove a \nproposition q from \u2203 x : \u03b1, p x, by showing that q follows from p w for an \narbitrary value w. Roughly speaking, since we know there is an x satisfying p x,\nwe can give it a name, say, w. If q does not mention w, then showing that q \nfollows from p w is tantamount to showing the q follows from the existence \nof any such x. Here is an example: \n-/\n\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\n#check @Exists.elim\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x := \n  Exists.elim h \n  (\n    fun w =>\n    fun hw : p w \u2227 q w =>\n    show \u2203 x, q x \u2227 p x from Exists.intro w (And.intro hw.right hw.left)\n  )\n\n/- \nIt may be helpful to compare the exists-elimination rule to the or-elimination \nrule: the assertion \u2203 x : \u03b1, p x can be thought of as a big disjunction of the \npropositions p a, as a ranges over all the elements of \u03b1. Note that the anonymous \nconstructor notation *\u27e8w, hw.right, hw.left\u27e9* abbreviates a nested constructor \napplication; we could equally well have written *\u27e8w, \u27e8hw.right, hw.left\u27e9\u27e9*.\n-/\n\n/- \nLean provides a more convenient way to eliminate from an existential quantifier \nwith the *match expression*:\n-/\n\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x := \n  match h with \n  | \u27e8w, hw\u27e9 => \u27e8w, hw.right, hw.left\u27e9 \n\n-- We can annotate the types used in the match for greater clarity: \nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x := \n  match h with \n  | \u27e8(w : \u03b1), (hw : p w \u2227 q w)\u27e9 => \u27e8w, hw.right, hw.left\u27e9 \n\n-- We can even use the match statement to decompose the conjunction at the same time:\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x := \n  match h with \n  | \u27e8w, hwl, hwr\u27e9 => \u27e8w, hwr, hwl\u27e9 \n\n-- Lean also provides a pattern-matching let expression:\nexample (h : \u2203 x, p x \u2227 q x) : \u2203 x, q x \u2227 p x := \n  let \u27e8w, hwl, hwr\u27e9 := h \n  \u27e8w, hwr, hwl\u27e9\n\n/- This is essentially just alternative notation for the match construct above. \nLean will even allow us to use an implicit match in the fun expression: -/\nexample : (\u2203 x, p x \u2227 q x) \u2192 \u2203 x, q x \u2227 p x :=\n  fun \u27e8w, hpw, hqw\u27e9 => \u27e8w, hqw, hpw\u27e9\n\n/- In the following example, we define even a as \u2203 b, a = 2 * b, and then we \nshow that the sum of two even numbers is an even number. -/\n\ndef is_even (a : Nat) := \u2203 b, a = 2 * b\n\ntheorem even_plus_even (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\n  Exists.elim h1 \n  (\n    fun w1 => \n    fun hw1 : a = 2 * w1 =>\n    Exists.elim h2 \n    (\n      fun w2 =>\n      fun hw2 : b = 2 * w2 =>\n      Exists.intro (w1 + w2)\n      (\n        calc \n          a + b = 2 * w1 + 2 * w2 := by rw[hw1, hw2]\n          _ = 2 * (w1 + w2) := by rw[Nat.mul_add]\n      )\n    )\n  )\n\n/- \nUsing the various gadgets described in this chapter --- \n*the match statement*, *anonymous constructors*, and the *rewrite tactic*, \nwe can write this proof concisely as follows:\n-/\n\ntheorem even_plus_even' (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\n  match h1, h2 with \n  | \u27e8w1, hw1\u27e9, \u27e8w2, hw2\u27e9 => \u27e8w1 + w2, by rw[hw1, hw2, Nat.mul_add]\u27e9\n\n/-\nJust as the constructive \"or\" is stronger than the classical \"or,\" so, too, is the \nconstructive \"exists\" stronger than the classical \"exists\". For example, the following \nimplication requires classical reasoning because, from a constructive standpoint, \nknowing that it is not the case that every x satisfies \u00ac p is not the same as having\na particular x that satisfies p -/\n\nopen Classical\nvariable (p : \u03b1 \u2192 Prop)\n\nexample (h : \u00ac \u2200 x, \u00ac p x) : \u2203 x, p x :=\n  byContradiction\n  (\n    fun h1 : \u00ac \u2203 x, p x =>\n    have h2 : \u2200 x, \u00ac p x :=\n      fun x =>\n      fun h3 : p x =>\n      have h4 : \u2203 x, p x :=  \u27e8x, h3\u27e9\n      show False from h1 h4\n    show False from h h2)\n\n/-\nWhat follows are some common identities involving the existential quantifier. \nIn the exercises below, we encourage you to prove as many as you can. We also leave it \nto you to determine which are nonconstructive, and hence require some form of \nclassical reasoning.-/\n\nopen Classical\n\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable (r : Prop)\n\nexample : (\u2203 x : \u03b1, r) \u2192 r := fun \u27e8x, r\u27e9 => r  \nexample (a : \u03b1) : r \u2192 (\u2203 x : \u03b1, r) := fun pr : r => \u27e8a, pr\u27e9 \nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := \n  Iff.intro\n  (fun \u27e8x, pxr\u27e9 => \u27e8\u27e8x, And.left pxr\u27e9, And.right pxr\u27e9)\n  (\n    fun h\u2080 : (\u2203 x, p x) \u2227 r =>\n    match And.left h\u2080 with \n    | \u27e8x, px\u27e9 => Exists.intro x (And.intro px (And.right h\u2080))\n  )\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := \n  Iff.intro\n  (\n    fun \u27e8x, hpq\u27e9 =>\n    Or.elim hpq\n      (fun hp : p x => Or.inl (Exists.intro x hp))\n      (fun hq : q x => Or.inr (Exists.intro x hq))\n  )\n  (\n    fun h\u2080 : (\u2203 x, p x) \u2228 (\u2203 x, q x) =>\n    Or.elim h\u2080 \n      (fun \u27e8x, px\u27e9 => \u27e8x, Or.inl px\u27e9)\n      (fun \u27e8x, qx\u27e9 => \u27e8x, Or.inr qx\u27e9)\n  )\n\nexample (a : \u03b1) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r :=\n  Iff.intro\n    (fun \u27e8b, (hb : p b \u2192 r)\u27e9 =>\n     fun h2 : \u2200 x, p x =>\n     show r from  hb (h2 b))\n    (fun h1 : (\u2200 x, p x) \u2192 r =>\n     show \u2203 x, p x \u2192 r from\n       byCases\n         (fun hap : \u2200 x, p x => \u27e8a, \u03bb h' => h1 hap\u27e9)\n         (fun hnap : \u00ac \u2200 x, p x =>\n          byContradiction\n            (fun hnex : \u00ac \u2203 x, p x \u2192 r =>\n              have hap : \u2200 x, p x :=\n                fun x =>\n                byContradiction\n                  (fun hnp : \u00ac p x =>\n                    have hex : \u2203 x, p x \u2192 r := \u27e8x, (fun hp => absurd hp hnp)\u27e9\n                    show False from hnex hex)\n              show False from hnap hap)))\n\n\n-- theorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\n--   Or.elim (em p) \n--     (fun hp : p => hp)\n--     (fun hnp : \u00acp => absurd hnp h)\n\n\ntheorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\n  Or.elim (em p) \n    (fun hp : p => hp)\n    (fun hnp : \u00acp => absurd hnp h)\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := \n  Iff.intro\n  (\n    fun \u27e8x, h\u2080\u27e9 =>\n    byContradiction\n    (\n      fun h\u2081 : \u00ac \u00ac \u2200 x, \u00ac p x =>\n      have h\u2082 : \u2200 x, \u00ac p x := dne h\u2081\n      show False from absurd h\u2080 (h\u2082 x)\n    )\n  )\n  (\n    fun h\u2080 : \u00ac (\u2200 x, \u00ac p x) =>\n    byContradiction\n    (\n      fun h\u2081 : \u00ac \u2203 x, p x =>\n      have h\u2082 : \u2200 x, \u00ac p x :=\n        fun x =>\n        fun h\u2083 : p x =>\n        have h\u2084 : \u2203 x, p x := \u27e8x, h\u2083\u27e9 \n        show False from h\u2081 h\u2084\n      show False from h\u2080 h\u2082\n    )\n  )\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := sorry\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) := sorry\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := sorry\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := sorry\n\nexample (a : \u03b1) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := sorry\n", "meta": {"author": "cristinaborza", "repo": "Logic-in-Lean", "sha": "53b0c76f8e8cab8a465f4a6621f623139c038dc7", "save_path": "github-repos/lean/cristinaborza-Logic-in-Lean", "path": "github-repos/lean/cristinaborza-Logic-in-Lean/Logic-in-Lean-53b0c76f8e8cab8a465f4a6621f623139c038dc7/quantifiers_and_equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757313, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.714503549124808}}
{"text": "\nimport tactic\n/-!\n\n# About Quotients\n\nThere are two ways to define new objets in maths:\n - The first way is tosay what they are\n - The second way is to say what they do\n\nExample 1 the natural numbers \u2115 \nDefinition via \"what they are\"\n  0 = \u2205 \n  1 = {0}\n  2 = {0, 1}\n  3 = {0, 1, 2}\n  [...] \n\nTheorem is that induction works\n\nDef in Lean:\nInductive nat\n| zero : nat\n| succ :  nat -> nat\n\n0 is a natural\nthe succesor of a natural is a natural\n*done*\nto do something for all n \u2208 \u2115 suffices to:\n * do it for 0\n * if done for n can do for succ n\n\n-/\n\n #check \u2115\n #print \u2115\n\n /-!\n ## Product\n\n if X, Y are sets (or types)\n X \u2a2f Y is a set (type)\n (x, y) where x \u2208 X, y \u2208 Y\n which is not equal to {x, y} because order matters\n\n So what is this \n\n\n FACT\n (x\u2081, y\u2081) = (x\u2082, y\u2082) \u2194 x\u2081 = x\u2082 \u2227 y\u2081 = y\u2082\n\n ## Quotients\n\n Lets do Tensor products\n If V and W are vector spaces over \u211d then there exist another vector space V \u2295\u2a2f W\n \u2203 linear map \n\n## Actually Quotients\n\nSet-up: X is a set/type\n~ : equivalence relation on X \ni.e. if a,b \u2208 X a ~ b is a proposition\nand it is reflecive symetric and transitive\n\n\n2500 y ago\nEuclid lists axio;s he'll use:\n and says that equality is an equivalence relation \n \n e.g. colours of shapes is an eq\n e.g. take property that you care from the object and that all of these need to be equal\n\n\n f : X \u2192 Y, define a relation ~ on X by a ~ b \u2194 f(a) = f(b)\n THM: that's an eq relation\n\nConverse:\nSay X is a thing and ~ is an equivalence relation on X\nQ: Can I get a Y and f : X \u2192 Y such that x\u2081 ~ x\u2082 \u2194 f(x\u2081) = f(x\u2082)\n\nA: Yes! [x]~ = Y the set of equivalence classes \n\n\n\u2124/12\u2124 is a set of sets of equivalence relations \n= {{-12, 0, 12, ...}, { -11, 1, 11, ...}, ...}\n\nThe lie X set ~ equiv relation then the quotient X/~ (called Y earlier) ***is*** the set of equivalence classes.\n\nAnother example\nX = set of red & yellow & green & blue plastic shapes\n~ is \"same colour\"\n\nWhat I want : Y & f : X \u2192 Y s.t. a ~b \u2194 f(a) = f(b)\n\"UG model\"\n  Y = {{a red triangle, a red square}, {2 blue triangles, blue pentagone},  ...}\n\nAnother model is:\nY = {red, yellox, green, blue}, f = \"colour\"\n\n  We care about what they do and not what they are\n\n\n  ### Quotients in Lean\n  You can't ask what they are, only ask what they **do**\n  \n -/\n\n-- Let X be a type\nvariable (X : Type)\n#check @quotient X\n\n#check setoid\n\n#check equivalence\n\n-- Let R be an equivalence relation on X\nvariables (R : X \u2192 (X \u2192 Prop)) (h : equivalence R)\n\ndef s : setoid X := { r := R,\n  iseqv := h }\n\n  -- how does Lean make the set Y such that f:X\u2192Y is a surjection\n  -- and f(x\u2081) = f(x\u2082) \u2194 R(x\u2081,x\u2082)\n\n  def Y := @quotient X (s X R h)\n\n  #check Y X R h\n\n-- Let's do a concrete example\n--- equiavalence relation on the integeres\n-- type by \\ then | = \u2223 \ndef C (a b : \u2124) : Prop := 12 \u2223 (a - b)\n\nlemma C_is_equiv : equivalence C :=\nbegin\n  split,\n  {sorry},\n  {split, {sorry}, {sorry}}\nend\n\n\n--instance t : setoid \u2124 := { r := C,\ndef t : setoid \u2124 := { r := C,\n  iseqv := C_is_equiv }\nattribute [instance] t\n\ndef clock := quotient t \n\n  -- we don't know what it is\n  -- It is \"the quotient of the integers by the equivalence realation C\"\n    -- Does it do what it is supposed to do????\n\n#check quotient.mk\n\ndef f : \u2124 \u2192 clock := quotient.mk\n\nexample (a : \u2124) : f a = \u27e6a\u27e7 :=\nbegin\n  refl,\nend\n\nexample (a b : \u2124) : C a b \u2194 a \u2248 b :=\nbegin\n  refl,\nend\n\nexample : f 1 = f 13 :=\nbegin\n  -- quotient.sound says a ~ b \u2192 f a = f b\n  --let h := quotient.sound,\n  apply quotient.sound,\n  change C 1 13,\n  change (12 : \u2124) \u2223 1 - 13,\n  norm_num,\nend\n\n#check quotient.eq\n\nexample (a b : \u2124) : \u27e6a\u27e7 = \u27e6b\u27e7 \u2194 a \u2248 b :=\nbegin\n  exact quotient.eq,\nend\n\n-- surjective_quot_mk from the mathlib\n\n-- What does it mean to be \"well-defined\"\n-- For nagation we need\n-- a ~ b \u21d2 -a ~ -b \n\n/-!\nFor \u2124/12 \u2192 X\n\nFact to give g : \u2124/12\u2124 \u2192 X\nneed two ingredients\n1: g\u2040 : \u2124 \u2192 X \n2: proof that a ~ b then g\u2040(a) = g\u2040(b)\n-/\n\nexample (Z : Type) (gtilde : \u2124 \u2192 Z)\n  (h : \u2200 a b : \u2124, a \u2248 b \u2192 gtilde a = gtilde b)\n  : clock \u2192 Z :=\n  quotient.lift gtilde h\n\n\n", "meta": {"author": "Girgias", "repo": "icl-2022-formalising-mathematics-irl", "sha": "966bdfb8d544275b8b069d49c8dce885593a65e5", "save_path": "github-repos/lean/Girgias-icl-2022-formalising-mathematics-irl", "path": "github-repos/lean/Girgias-icl-2022-formalising-mathematics-irl/icl-2022-formalising-mathematics-irl-966bdfb8d544275b8b069d49c8dce885593a65e5/src/02-08session.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7143631750760514}}
{"text": "/-\nCopyright (c) 2022 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport data.fin.vec_notation\n\n/-!\n# Monotone finite sequences\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove `simp` lemmas that allow to simplify propositions like `monotone ![a, b, c]`.\n-/\n\nopen set fin matrix function\nvariables {\u03b1 : Type*}\n\nlemma lift_fun_vec_cons {n : \u2115} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_trans \u03b1 r] {f : fin (n + 1) \u2192 \u03b1} {a : \u03b1} :\n  ((<) \u21d2 r) (vec_cons a f) (vec_cons a f) \u2194 r a (f 0) \u2227 ((<) \u21d2 r) f f :=\nby simp only [lift_fun_iff_succ r, forall_fin_succ, cons_val_succ, cons_val_zero, \u2190 succ_cast_succ,\n  cast_succ_zero]\n\nvariables [preorder \u03b1] {n : \u2115} {f : fin (n + 1) \u2192 \u03b1} {a : \u03b1}\n\n@[simp] lemma strict_mono_vec_cons : strict_mono (vec_cons a f) \u2194 a < f 0 \u2227 strict_mono f :=\nlift_fun_vec_cons (<)\n\n@[simp] lemma monotone_vec_cons : monotone (vec_cons a f) \u2194 a \u2264 f 0 \u2227 monotone f :=\nby simpa only [monotone_iff_forall_lt] using @lift_fun_vec_cons \u03b1 n (\u2264) _ f a\n\n@[simp] lemma strict_anti_vec_cons : strict_anti (vec_cons a f) \u2194 f 0 < a \u2227 strict_anti f :=\nlift_fun_vec_cons (>)\n\n@[simp] lemma antitone_vec_cons : antitone (vec_cons a f) \u2194 f 0 \u2264 a \u2227 antitone f :=\n@monotone_vec_cons \u03b1\u1d52\u1d48 _ _ _ _\n\nlemma strict_mono.vec_cons (hf : strict_mono f) (ha : a < f 0) :\n  strict_mono (vec_cons a f) :=\nstrict_mono_vec_cons.2 \u27e8ha, hf\u27e9\n\nlemma strict_anti.vec_cons (hf : strict_anti f) (ha : f 0 < a) :\n  strict_anti (vec_cons a f) :=\nstrict_anti_vec_cons.2 \u27e8ha, hf\u27e9\n\nlemma monotone.vec_cons (hf : monotone f) (ha : a \u2264 f 0) :\n  monotone (vec_cons a f) :=\nmonotone_vec_cons.2 \u27e8ha, hf\u27e9\n\nlemma antitone.vec_cons (hf : antitone f) (ha : f 0 \u2264 a) :\n  antitone (vec_cons a f) :=\nantitone_vec_cons.2 \u27e8ha, hf\u27e9\n\nexample : monotone ![1, 2, 2, 3] := by simp [subsingleton.monotone]\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/fin/tuple/monotone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7143631582203575}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport ring_theory.trace\nimport ring_theory.norm\nimport number_theory.number_field\n\n/-!\n# Discriminant of a family of vectors\n\nGiven an `A`-algebra `B` and `b`, an `\u03b9`-indexed family of elements of `B`, we define the\n*discriminant* of `b` as the determinant of the matrix whose `(i j)`-th element is the trace of\n`b i * b j`.\n\n## Main definition\n\n* `algebra.discr A b` : the discriminant of `b : \u03b9 \u2192 B`.\n\n## Main results\n\n* `algebra.discr_zero_of_not_linear_independent` : if `b` is not linear independent, then\n  `algebra.discr A b = 0`.\n* `algebra.discr_of_matrix_vec_mul` and `discr_of_matrix_mul_vec` : formulas relating\n  `algebra.discr A \u03b9 b` with `algebra.discr A ((P.map (algebra_map A B)).vec_mul b)` and\n  `algebra.discr A ((P.map (algebra_map A B)).mul_vec b)`.\n* `algebra.discr_not_zero_of_basis` : over a field, if `b` is a basis, then\n  `algebra.discr K b \u2260 0`.\n* `algebra.discr_eq_det_embeddings_matrix_reindex_pow_two` : if `L/K` is a field extension and\n  `b : \u03b9 \u2192 L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)`\n  coefficient is `\u03c3\u2c7c (b i)`, where `\u03c3\u2c7c : L \u2192\u2090[K] E` is the embedding in an algebraically closed\n  field `E` corresponding to `j : \u03b9` via a bijection `e : \u03b9 \u2243 (L \u2192\u2090[K] E)`.\n* `algebra.discr_of_power_basis_eq_prod` : the discriminant of a power basis.\n* `discr_is_integral` : if `K` and `L` are fields and `is_scalar_tower R K L`, is `b : \u03b9 \u2192 L`\n  satisfies ` \u2200 i, is_integral R (b i)`, then `is_integral R (discr K b)`.\n* `discr_mul_is_integral_mem_adjoin` : let `K` be the fraction field of an integrally closed domain\n  `R` and let `L` be a finite separable extension of `K`. Let `B : power_basis K L` be such that\n  `is_integral R B.gen`. Then for all, `z : L` we have\n  `(discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L)`.\n\n## Implementation details\n\nOur definition works for any `A`-algebra `B`, but note that if `B` is not free as an `A`-module,\nthen `trace A B = 0` by definition, so `discr A b = 0` for any `b`.\n-/\n\nuniverses u v w z\n\nopen_locale matrix big_operators\n\nopen matrix finite_dimensional fintype polynomial finset intermediate_field\n\nnamespace algebra\n\nvariables (A : Type u) {B : Type v} (C : Type z) {\u03b9 : Type w}\nvariables [comm_ring A] [comm_ring B] [algebra A B] [comm_ring C] [algebra A C]\n\nsection discr\n\n/-- Given an `A`-algebra `B` and `b`, an `\u03b9`-indexed family of elements of `B`, we define\n`discr A \u03b9 b` as the determinant of `trace_matrix A \u03b9 b`. -/\nnoncomputable\ndef discr (A : Type u) {B : Type v} [comm_ring A] [comm_ring B] [algebra A B] [fintype \u03b9]\n  (b : \u03b9 \u2192 B) := by { classical, exact (trace_matrix A b).det }\n\nlemma discr_def [decidable_eq \u03b9] [fintype \u03b9] (b : \u03b9 \u2192 B) :\n  discr A b = (trace_matrix A b).det := by convert rfl\n\nvariables {\u03b9' : Type*} [fintype \u03b9'] [fintype \u03b9]\n\nsection basic\n\n@[simp] lemma discr_reindex (b : basis \u03b9 A B) (f : \u03b9 \u2243 \u03b9') :\n  discr A (b \u2218 \u21d1(f.symm)) = discr A b :=\nbegin\n  classical,\n  rw [\u2190 basis.coe_reindex, discr_def, trace_matrix_reindex, det_reindex_self, \u2190 discr_def]\nend\n\n/-- If `b` is not linear independent, then `algebra.discr A b = 0`. -/\nlemma discr_zero_of_not_linear_independent [is_domain A] {b : \u03b9 \u2192 B}\n  (hli : \u00aclinear_independent A b) : discr A b = 0 :=\nbegin\n  classical,\n  obtain \u27e8g, hg, i, hi\u27e9 := fintype.not_linear_independent_iff.1 hli,\n  have : (trace_matrix A b).mul_vec g = 0,\n  { ext i,\n    have : \u2200 j, (trace A B) (b i * b j) * g j = (trace A B) (((g j) \u2022 (b j)) * b i),\n    { intro j, simp [mul_comm], },\n    simp only [mul_vec, dot_product, trace_matrix, pi.zero_apply, trace_form_apply,\n      \u03bb j, this j, \u2190 linear_map.map_sum, \u2190 sum_mul, hg, zero_mul, linear_map.map_zero] },\n  by_contra h,\n  rw discr_def at h,\n  simpa [matrix.eq_zero_of_mul_vec_eq_zero h this] using hi,\nend\n\nvariable {A}\n\n/-- Relation between `algebra.discr A \u03b9 b` and\n`algebra.discr A ((P.map (algebra_map A B)).vec_mul b)`. -/\nlemma discr_of_matrix_vec_mul [decidable_eq \u03b9] (b : \u03b9 \u2192 B) (P : matrix \u03b9 \u03b9 A) :\n  discr A ((P.map (algebra_map A B)).vec_mul b) = P.det ^ 2 * discr A b :=\nby rw [discr_def, trace_matrix_of_matrix_vec_mul, det_mul, det_mul, det_transpose, mul_comm,\n    \u2190 mul_assoc, discr_def, pow_two]\n\n/-- Relation between `algebra.discr A \u03b9 b` and\n`algebra.discr A ((P.map (algebra_map A B)).mul_vec b)`. -/\nlemma discr_of_matrix_mul_vec [decidable_eq \u03b9] (b : \u03b9 \u2192 B) (P : matrix \u03b9 \u03b9 A) :\n  discr A ((P.map (algebra_map A B)).mul_vec b) = P.det ^ 2 * discr A b :=\nby rw [discr_def, trace_matrix_of_matrix_mul_vec, det_mul, det_mul, det_transpose,\n  mul_comm, \u2190 mul_assoc, discr_def, pow_two]\n\nend basic\n\nsection field\n\nvariables (K : Type u) {L : Type v} (E : Type z) [field K] [field L] [field E]\nvariables [algebra K L] [algebra K E]\nvariables [module.finite K L]  [is_alg_closed E]\n\n/-- Over a field, if `b` is a basis, then `algebra.discr K b \u2260 0`. -/\nlemma discr_not_zero_of_basis [is_separable K L] (b : basis \u03b9 K L) : discr K b \u2260 0 :=\nbegin\n  by_cases h : nonempty \u03b9,\n  { classical,\n    have := span_eq_top_of_linear_independent_of_card_eq_finrank b.linear_independent\n      (finrank_eq_card_basis b).symm,\n    rw [discr_def, trace_matrix_def],\n    simp_rw [\u2190 basis.mk_apply b.linear_independent this],\n    rw [\u2190 trace_matrix_def, trace_matrix_of_basis, \u2190 bilin_form.nondegenerate_iff_det_ne_zero],\n    exact trace_form_nondegenerate _ _  },\n  letI := not_nonempty_iff.1 h,\n  simp [discr],\nend\n\n/-- Over a field, if `b` is a basis, then `algebra.discr K b` is a unit. -/\nlemma discr_is_unit_of_basis [is_separable K L] (b : basis \u03b9 K L) : is_unit (discr K b) :=\nis_unit.mk0 _ (discr_not_zero_of_basis _ _)\n\nvariables (b : \u03b9 \u2192 L) (pb : power_basis K L)\n\n/-- If `L/K` is a field extension and `b : \u03b9 \u2192 L`, then `discr K b` is the square of the\ndeterminant of the matrix whose `(i, j)` coefficient is `\u03c3\u2c7c (b i)`, where `\u03c3\u2c7c : L \u2192\u2090[K] E` is the\nembedding in an algebraically closed field `E` corresponding to `j : \u03b9` via a bijection\n`e : \u03b9 \u2243 (L \u2192\u2090[K] E)`. -/\nlemma discr_eq_det_embeddings_matrix_reindex_pow_two [decidable_eq \u03b9] [is_separable K L]\n  (e : \u03b9 \u2243 (L \u2192\u2090[K] E)) : algebra_map K E (discr K b) =\n  (embeddings_matrix_reindex K E b e).det ^ 2 :=\nby rw [discr_def, ring_hom.map_det, ring_hom.map_matrix_apply,\n    trace_matrix_eq_embeddings_matrix_reindex_mul_trans, det_mul, det_transpose, pow_two]\n\n/-- The discriminant of a power basis. -/\nlemma discr_power_basis_eq_prod (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) [is_separable K L] :\n  algebra_map K E (discr K pb.basis) =\n  \u220f i : fin pb.dim, \u220f j in finset.univ.filter (\u03bb j, i < j), (e j pb.gen- (e i pb.gen)) ^ 2 :=\nbegin\n  rw [discr_eq_det_embeddings_matrix_reindex_pow_two K E pb.basis e,\n    embeddings_matrix_reindex_eq_vandermonde, det_transpose, det_vandermonde, \u2190 prod_pow],\n  congr, ext i,\n  rw [\u2190 prod_pow]\nend\n\n/-- A variation of `of_power_basis_eq_prod`. -/\nlemma discr_power_basis_eq_prod' [is_separable K L] (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) :\n  algebra_map K E (discr K pb.basis) =\n  \u220f i : fin pb.dim, \u220f j in finset.univ.filter (\u03bb j, i < j),\n  -((e j pb.gen- (e i pb.gen)) * (e i pb.gen- (e j pb.gen))) :=\nbegin\n  rw [discr_power_basis_eq_prod _ _ _ e],\n  congr, ext i, congr, ext j,\n  ring\nend\n\nlocal notation `n` := finrank K L\n\n/-- A variation of `of_power_basis_eq_prod`. -/\nlemma discr_power_basis_eq_prod'' [is_separable K L] (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) :\n  algebra_map K E (discr K pb.basis) =\n  (-1) ^ (n * (n - 1) / 2) * \u220f i : fin pb.dim, \u220f j in finset.univ.filter (\u03bb j, i < j),\n  ((e j pb.gen- (e i pb.gen)) * (e i pb.gen- (e j pb.gen))) :=\nbegin\n  rw [discr_power_basis_eq_prod' _ _ _ e],\n  simp_rw [\u03bb i j, neg_eq_neg_one_mul ((e j pb.gen- (e i pb.gen)) * (e i pb.gen- (e j pb.gen))),\n    prod_mul_distrib],\n  congr,\n  simp only [prod_pow_eq_pow_sum, prod_const],\n  congr,\n  simp_rw [fin.card_filter_lt],\n  apply (@nat.cast_inj \u211a _ _ _ _ _).1,\n  rw [nat.cast_sum],\n  have : \u2200 (x : fin pb.dim), (\u2191x + 1) \u2264 pb.dim := by simp [nat.succ_le_iff, fin.is_lt],\n  simp_rw [nat.sub_sub],\n  simp only [nat.cast_sub, this, finset.card_fin, nsmul_eq_mul, sum_const, sum_sub_distrib,\n    nat.cast_add, nat.cast_one, sum_add_distrib, mul_one],\n  rw [\u2190 nat.cast_sum, \u2190 @finset.sum_range \u2115 _ pb.dim (\u03bb i, i), sum_range_id ],\n  have hn : n = pb.dim,\n  { rw [\u2190 alg_hom.card K L E, \u2190 fintype.card_fin pb.dim],\n    exact card_congr (equiv.symm e) },\n  have h\u2082 : 2 \u2223 (pb.dim * (pb.dim - 1)) := even_iff_two_dvd.1 (nat.even_mul_self_pred _),\n  have hne : ((2 : \u2115) : \u211a) \u2260 0 := by simp,\n  have hle : 1 \u2264 pb.dim,\n  { rw [\u2190 hn, nat.one_le_iff_ne_zero, \u2190 zero_lt_iff, finite_dimensional.finrank_pos_iff],\n    apply_instance },\n  rw [hn, nat.cast_dvd h\u2082 hne, nat.cast_mul, nat.cast_sub hle],\n  field_simp,\n  ring,\nend\n\n/-- Formula for the discriminant of a power basis using the norm of the field extension. -/\nlemma discr_power_basis_eq_norm [is_separable K L] : discr K pb.basis =\n  (-1) ^ (n * (n - 1) / 2) * (norm K (aeval pb.gen (minpoly K pb.gen).derivative)) :=\nbegin\n  let E := algebraic_closure L,\n  letI := \u03bb (a b : E), classical.prop_decidable (eq a b),\n\n  have e : fin pb.dim \u2243 (L \u2192\u2090[K] E),\n  { refine equiv_of_card_eq _,\n    rw [fintype.card_fin, alg_hom.card],\n    exact (power_basis.finrank pb).symm },\n  have hnodup : (map (algebra_map K E) (minpoly K pb.gen)).roots.nodup :=\n    nodup_roots (separable.map (is_separable.separable K pb.gen)),\n  have hroots : \u2200 \u03c3 : L \u2192\u2090[K] E, \u03c3 pb.gen \u2208 (map (algebra_map K E) (minpoly K pb.gen)).roots,\n  { intro \u03c3,\n    rw [mem_roots, is_root.def, eval_map, \u2190 aeval_def, aeval_alg_hom_apply],\n    repeat { simp [minpoly.ne_zero (is_separable.is_integral K pb.gen)] } },\n\n  apply (algebra_map K E).injective,\n  rw [ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_neg, ring_hom.map_one,\n    discr_power_basis_eq_prod'' _ _ _ e],\n  congr,\n  rw [norm_eq_prod_embeddings, fin.prod_filter_lt_mul_neg_eq_prod_off_diag],\n  conv_rhs { congr, skip, funext,\n    rw [\u2190 aeval_alg_hom_apply, aeval_root_derivative_of_splits (minpoly.monic\n      (is_separable.is_integral K pb.gen)) (is_alg_closed.splits_codomain _) (hroots \u03c3),\n      \u2190 finset.prod_mk _ (hnodup.erase _)] },\n  rw [prod_sigma', prod_sigma'],\n  refine prod_bij (\u03bb i hi, \u27e8e i.2, e i.1 pb.gen\u27e9) (\u03bb i hi, _) (\u03bb i hi, by simp at hi)\n    (\u03bb i j hi hj hij, _) (\u03bb \u03c3 h\u03c3, _),\n  { simp only [true_and, finset.mem_mk, mem_univ, mem_sigma],\n    rw [multiset.mem_erase_of_ne (\u03bb h, _)],\n    { exact hroots _ },\n    { simp only [true_and, mem_filter, mem_univ, ne.def, mem_sigma] at hi,\n      refine hi (equiv.injective e (equiv.injective (power_basis.lift_equiv pb) _)),\n      rw [\u2190 power_basis.lift_equiv_apply_coe, \u2190 power_basis.lift_equiv_apply_coe] at h,\n      exact subtype.eq h } },\n  { simp only [equiv.apply_eq_iff_eq, heq_iff_eq] at hij,\n    have h := hij.2,\n    rw [\u2190 power_basis.lift_equiv_apply_coe, \u2190 power_basis.lift_equiv_apply_coe] at h,\n    refine sigma.eq (equiv.injective e (equiv.injective _ (subtype.eq h))) (by simp [hij.1]) },\n  { simp only [true_and, finset.mem_mk, mem_univ, mem_sigma] at h\u03c3,\n    simp only [sigma.exists, true_and, exists_prop, mem_filter, mem_univ, ne.def, mem_sigma],\n    refine \u27e8e.symm (power_basis.lift pb \u03c3.2 _), e.symm \u03c3.1, \u27e8\u03bb h, _, sigma.eq _ _\u27e9\u27e9,\n    { rw [aeval_def, eval\u2082_eq_eval_map, \u2190 is_root.def, \u2190 mem_roots],\n      { exact multiset.erase_subset _ _ h\u03c3 },\n      { simp [minpoly.ne_zero (is_separable.is_integral K pb.gen)] } },\n    { replace h := alg_hom.congr_fun (equiv.injective _ h) pb.gen,\n      rw [power_basis.lift_gen] at h,\n      rw [\u2190 h] at h\u03c3,\n      exact hnodup.not_mem_erase h\u03c3 },\n    all_goals { simp } }\nend\n\nsection integral\n\nvariables {R : Type z} [comm_ring R] [algebra R K] [algebra R L] [is_scalar_tower R K L]\n\nlocal notation `is_integral` := _root_.is_integral\n\n/-- If `K` and `L` are fields and `is_scalar_tower R K L`, and `b : \u03b9 \u2192 L` satisfies\n` \u2200 i, is_integral R (b i)`, then `is_integral R (discr K b)`. -/\nlemma discr_is_integral {b : \u03b9 \u2192 L} (h : \u2200 i, is_integral R (b i)) :\n  is_integral R (discr K b) :=\nbegin\n  classical,\n  rw [discr_def],\n  exact is_integral.det (\u03bb i j, is_integral_trace (is_integral_mul (h i) (h j)))\nend\n\n/-- If `b` and `b'` are `\u211a`-bases of a number field `K` such that\n`\u2200 i j, is_integral \u2124 (b.to_matrix b' i j)` and `\u2200 i j, is_integral \u2124 (b'.to_matrix b i j)` then\n`discr \u211a b = discr \u211a b'`. -/\nlemma discr_eq_discr_of_to_matrix_coeff_is_integral [number_field K] {b : basis \u03b9 \u211a K}\n  {b' : basis \u03b9' \u211a K} (h : \u2200 i j, is_integral \u2124 (b.to_matrix b' i j))\n  (h' : \u2200 i j, is_integral \u2124 (b'.to_matrix b i j)) :\n  discr \u211a b = discr \u211a b' :=\nbegin\n  replace h' : \u2200 i j, is_integral \u2124 (b'.to_matrix ((b.reindex (b.index_equiv b'))) i j),\n  { intros i j,\n    convert h' i ((b.index_equiv b').symm j),\n    simpa },\n  classical,\n  rw [\u2190 (b.reindex (b.index_equiv b')).to_matrix_map_vec_mul b', discr_of_matrix_vec_mul,\n    \u2190 one_mul (discr \u211a b), basis.coe_reindex, discr_reindex],\n  congr,\n  have hint : is_integral \u2124 (((b.reindex (b.index_equiv b')).to_matrix b').det) :=\n    is_integral.det (\u03bb i j, h _ _),\n  obtain \u27e8r, hr\u27e9 := is_integrally_closed.is_integral_iff.1 hint,\n  have hunit : is_unit r,\n  { have : is_integral \u2124 ((b'.to_matrix (b.reindex (b.index_equiv b'))).det) :=\n      is_integral.det (\u03bb i j, h' _ _),\n    obtain \u27e8r', hr'\u27e9 := is_integrally_closed.is_integral_iff.1 this,\n    refine is_unit_iff_exists_inv.2 \u27e8r', _\u27e9,\n    suffices : algebra_map \u2124 \u211a (r * r') = 1,\n    { rw [\u2190 ring_hom.map_one (algebra_map \u2124 \u211a)] at this,\n      exact (is_fraction_ring.injective \u2124 \u211a) this },\n    rw [ring_hom.map_mul, hr, hr', \u2190 det_mul, basis.to_matrix_mul_to_matrix_flip, det_one] },\n  rw [\u2190 ring_hom.map_one (algebra_map \u2124 \u211a), \u2190 hr],\n  cases int.is_unit_iff.1 hunit with hp hm,\n  { simp [hp] },\n  { simp [hm] }\nend\n\n/-- Let `K` be the fraction field of an integrally closed domain `R` and let `L` be a finite\nseparable extension of `K`. Let `B : power_basis K L` be such that `is_integral R B.gen`.\nThen for all, `z : L` that are integral over `R`, we have\n`(discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L)`. -/\nlemma discr_mul_is_integral_mem_adjoin [is_domain R] [is_separable K L] [is_integrally_closed R]\n  [is_fraction_ring R K] {B : power_basis K L} (hint : is_integral R B.gen) {z : L}\n  (hz : is_integral R z) : (discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L) :=\nbegin\n  have hinv : is_unit (trace_matrix K B.basis).det :=\n    by simpa [\u2190 discr_def] using discr_is_unit_of_basis _ B.basis,\n\n  have H : (trace_matrix K B.basis).det \u2022 (trace_matrix K B.basis).mul_vec (B.basis.equiv_fun z) =\n    (trace_matrix K B.basis).det \u2022 (\u03bb i, trace K L (z * B.basis i)),\n  { congr, exact trace_matrix_of_basis_mul_vec _ _ },\n  have cramer := mul_vec_cramer (trace_matrix K B.basis) (\u03bb i, trace K L (z * B.basis i)),\n\n  suffices : \u2200 i, ((trace_matrix K B.basis).det \u2022 (B.basis.equiv_fun z)) i \u2208 (\u22a5 : subalgebra R K),\n  { rw [\u2190 B.basis.sum_repr z, finset.smul_sum],\n    refine subalgebra.sum_mem _ (\u03bb i hi, _),\n    replace this := this i,\n    rw [\u2190 discr_def, pi.smul_apply, mem_bot] at this,\n    obtain \u27e8r, hr\u27e9 := this,\n    rw [basis.equiv_fun_apply] at hr,\n    rw [\u2190 smul_assoc, \u2190 hr, algebra_map_smul],\n    refine subalgebra.smul_mem _ _ _,\n    rw [B.basis_eq_pow i],\n    refine subalgebra.pow_mem _ (subset_adjoin (set.mem_singleton _)) _},\n  intro i,\n  rw [\u2190 H, \u2190 mul_vec_smul] at cramer,\n  replace cramer := congr_arg (mul_vec (trace_matrix K B.basis)\u207b\u00b9) cramer,\n  rw [mul_vec_mul_vec, nonsing_inv_mul _ hinv, mul_vec_mul_vec, nonsing_inv_mul _ hinv,\n    one_mul_vec, one_mul_vec] at cramer,\n  rw [\u2190 congr_fun cramer i, cramer_apply, det_apply],\n  refine subalgebra.sum_mem _ (\u03bb \u03c3 _, subalgebra.zsmul_mem _ (subalgebra.prod_mem _ (\u03bb j _, _)) _),\n  by_cases hji : j = i,\n  { simp only [update_column_apply, hji, eq_self_iff_true, power_basis.coe_basis],\n    exact mem_bot.2 (is_integrally_closed.is_integral_iff.1 $ is_integral_trace $\n      is_integral_mul hz $ is_integral.pow hint _) },\n  { simp only [update_column_apply, hji, power_basis.coe_basis],\n    exact mem_bot.2 (is_integrally_closed.is_integral_iff.1 $ is_integral_trace\n      $ is_integral_mul (is_integral.pow hint _) (is_integral.pow hint _)) }\nend\n\nend integral\n\nend field\n\nend discr\n\nend algebra\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/discriminant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7143631566029366}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Johannes H\u00f6lzl\n-/\nimport dynamics.fixed_points.basic\nimport topology.separation\n\n/-!\n# Topological properties of fixed points\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nCurrently this file contains two lemmas:\n\n- `is_fixed_pt_of_tendsto_iterate`: if `f^n(x) \u2192 y` and `f` is continuous at `y`, then `f y = y`;\n- `is_closed_fixed_points`: the set of fixed points of a continuous map is a closed set.\n\n## TODO\n\nfixed points, iterates\n-/\n\nvariables {\u03b1 : Type*} [topological_space \u03b1] [t2_space \u03b1] {f : \u03b1 \u2192 \u03b1}\n\nopen function filter\nopen_locale topology\n\n/-- If the iterates `f^[n] x` converge to `y` and `f` is continuous at `y`,\nthen `y` is a fixed point for `f`. -/\nlemma is_fixed_pt_of_tendsto_iterate {x y : \u03b1} (hy : tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y))\n  (hf : continuous_at f y) :\n  is_fixed_pt f y :=\nbegin\n  refine tendsto_nhds_unique ((tendsto_add_at_top_iff_nat 1).1 _) hy,\n  simp only [iterate_succ' f],\n  exact hf.tendsto.comp hy\nend\n\n/-- The set of fixed points of a continuous map is a closed set. -/\nlemma is_closed_fixed_points (hf : continuous f) : is_closed (fixed_points f) :=\nis_closed_eq hf continuous_id\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/dynamics/fixed_points/topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7143631561772636}}
{"text": "/-\nCopyright (c) 2021 Andrew Yang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Andrew Yang, Yury G. Kudryashov\n-/\nimport topology.constructions\n\n/-!\n# Inseparable points\n\nIn this file we require two relations on a topological space: `specializes` (notation : `x \u2933 y`) and\n`inseparable`, then prove some basic lemmas about these relations.\n\n## Main definitions\n\n* `specializes` : `specializes x y` (`x \u2933 y`) means that `x` specializes to `y`, i.e.\n  `y` is in the closure of `x`.\n\n* `specialization_preorder` : specialization gives a preorder on a topological space. In case of a\n  T\u2080 space, this preorder is a partial order, see `specialization_order`.\n\n* `inseparable x y` means that two points can't be separated by an open set.\n-/\n\nopen_locale topological_space\nopen set\n\nvariables {X Y : Type*} [topological_space X] [topological_space Y] {x y z : X}\n\n/-- `x` specializes to `y` if `y` is in the closure of `x`. The notation used is `x \u2933 y`. -/\ndef specializes (x y : X) : Prop := y \u2208 closure ({x} : set X)\n\ninfix ` \u2933 `:300 := specializes\n\nlemma specializes_def (x y : X) : x \u2933 y \u2194 y \u2208 closure ({x} : set X) := iff.rfl\n\nlemma specializes_iff_closure_subset : x \u2933 y \u2194 closure ({y} : set X) \u2286 closure ({x} : set X) :=\nis_closed_closure.mem_iff_closure_subset\n\nlemma specializes_rfl : x \u2933 x := subset_closure (mem_singleton x)\n\nlemma specializes_refl (x : X) : x \u2933 x := specializes_rfl\n\nlemma specializes.trans : x \u2933 y \u2192 y \u2933 z \u2192 x \u2933 z :=\nby { simp_rw specializes_iff_closure_subset, exact \u03bb a b, b.trans a }\n\nlemma specializes_iff_forall_closed :\n  x \u2933 y \u2194 \u2200 (Z : set X) (h : is_closed Z), x \u2208 Z \u2192 y \u2208 Z :=\nbegin\n  split,\n  { intros h Z hZ,\n    rw [hZ.mem_iff_closure_subset, hZ.mem_iff_closure_subset],\n    exact (specializes_iff_closure_subset.mp h).trans },\n  { intro h, exact h _ is_closed_closure (subset_closure $ set.mem_singleton x) }\nend\n\nlemma specializes_iff_forall_open :\n  x \u2933 y \u2194 \u2200 (U : set X) (h : is_open U), y \u2208 U \u2192 x \u2208 U :=\nbegin\n  rw specializes_iff_forall_closed,\n  exact \u27e8\u03bb h U hU, not_imp_not.mp (h _ (is_closed_compl_iff.mpr hU)),\n    \u03bb h U hU, not_imp_not.mp (h _ (is_open_compl_iff.mpr hU))\u27e9,\nend\n\nlemma specializes.map (h : x \u2933 y) {f : X \u2192 Y} (hf : continuous f) : f x \u2933 f y :=\nbegin\n  rw [specializes_def, \u2190 set.image_singleton],\n  exact image_closure_subset_closure_image hf \u27e8_, h, rfl\u27e9,\nend\n\nsection specialize_order\n\nvariable (X)\n\n/-- Specialization forms a preorder on the topological space. -/\ndef specialization_preorder : preorder X :=\n{ le := \u03bb x y, y \u2933 x,\n  le_refl := \u03bb x, specializes_refl x,\n  le_trans := \u03bb _ _ _ h\u2081 h\u2082, specializes.trans h\u2082 h\u2081 }\n\nlocal attribute [instance] specialization_preorder\n\nvariable {X}\n\nlemma specialization_order.monotone_of_continuous (f : X \u2192 Y) (hf : continuous f) : monotone f :=\n\u03bb x y h, specializes.map h hf\n\nend specialize_order\n\n/-- Two points are topologically inseparable if no open set separates them. -/\ndef inseparable (x y : X) : Prop := \u2200 (U : set X) (hU : is_open U), x \u2208 U \u2194 y \u2208 U\n\nlemma inseparable_iff_nhds_eq : inseparable x y \u2194 \ud835\udcdd x = \ud835\udcdd y :=\n\u27e8\u03bb h, by simp only [nhds_def', h _] { contextual := tt },\n  \u03bb h U hU, by simp only [\u2190 hU.mem_nhds_iff, h]\u27e9\n\nalias inseparable_iff_nhds_eq \u2194 inseparable.nhds_eq _\n\nlemma inseparable.map {f : X \u2192 Y} (h : inseparable x y) (hf : continuous f) :\n  inseparable (f x) (f y) :=\n\u03bb U hU, h (f \u207b\u00b9' U) (hU.preimage hf)\n\nlemma inseparable_iff_closed :\n  inseparable x y \u2194 \u2200 (U : set X) (hU : is_closed U), x \u2208 U \u2194 y \u2208 U :=\n\u27e8\u03bb h U hU, not_iff_not.mp (h _ hU.1), \u03bb h U hU, not_iff_not.mp (h _ (is_closed_compl_iff.mpr hU))\u27e9\n\nlemma inseparable_iff_closure (x y : X) :\n  inseparable x y \u2194 x \u2208 closure ({y} : set X) \u2227 y \u2208 closure ({x} : set X) :=\nbegin\n  rw inseparable_iff_closed,\n  exact \u27e8\u03bb h, \u27e8(h _ is_closed_closure).mpr (subset_closure $ set.mem_singleton y),\n      (h _ is_closed_closure).mp (subset_closure $ set.mem_singleton x)\u27e9,\n    \u03bb h U hU, \u27e8\u03bb hx, (is_closed.closure_subset_iff hU).mpr (set.singleton_subset_iff.mpr hx) h.2,\n      \u03bb hy, (is_closed.closure_subset_iff hU).mpr (set.singleton_subset_iff.mpr hy) h.1\u27e9\u27e9\nend\n\nlemma inseparable_iff_specializes_and (x y : X) :\n  inseparable x y \u2194 x \u2933 y \u2227 y \u2933 x :=\n(inseparable_iff_closure x y).trans (and_comm _ _)\n\nlemma subtype_inseparable_iff {U : set X} (x y : U) :\n  inseparable x y \u2194 inseparable (x : X) y :=\nby { simp_rw [inseparable_iff_closure, closure_subtype, image_singleton] }\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/topology/inseparable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7143399410999661}}
{"text": "/-\nCopyright (c) 2021 Kalle Kyt\u00f6l\u00e4. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kyt\u00f6l\u00e4\n-/\nimport measure_theory.integration\nimport topology.metric_space.basic\nimport topology.instances.real\nimport topology.instances.ennreal\nimport topology.instances.nnreal\nimport topology.algebra.infinite_sum\nimport portmanteau_definitions\n\n\n\nnoncomputable theory\nopen set \nopen filter\nopen order\nopen_locale topological_space ennreal big_operators\n\n\nnamespace portmanteau\n\n\n\nsection portmanteau_comeonlean_lemmas\n\n\n\nlemma bdd_ennval_of_le_cst' {\u03b1 : Type*} {f : \u03b1 \u2192 ennreal} {c : nnreal} (h : f \u2264 (\u03bb a , c)) :\n  bdd_ennval f := by { use c , exact h , }\n\n\nlemma bdd_ennval_of_le_cst {\u03b1 : Type*} {f : \u03b1 \u2192 ennreal} {c : ennreal} (h : f \u2264 (\u03bb a , c)) (hc : c \u2260 \u22a4) :\n  bdd_ennval f :=\nbegin\n  use c.to_nnreal ,\n  intros a , \n  have key := h a , \n  rwa \u2190 ennreal.coe_to_nnreal hc at key ,\nend\n\n\nlemma ennreal_eq_top_of_forall_nnreal_ge (z : ennreal) : (\u2200 (x : nnreal) , ennreal.of_real x \u2264 z) \u2192 z = \u22a4 :=\nbegin\n  contrapose ,\n  intros hz ,\n  push_neg ,\n  have key := ennreal.lt_iff_exists_nnreal_btwn.mp (lt_top_iff_ne_top.mpr hz) ,\n  cases key with x hx ,\n  use x ,\n  simp only [hx.1, ennreal.of_real_coe_nnreal] ,\nend\n\n\nlemma ennreal_eq_top_of_forall_real_ge (z : ennreal) : (\u2200 (x : \u211d) , ennreal.of_real x \u2264 z) \u2192 z = \u22a4 :=\nbegin\n  intros h ,\n  apply ennreal_eq_top_of_forall_nnreal_ge ,\n  intros x' ,\n  exact h x' ,\nend\n\n\nlemma ennreal_eq_top_of_forall_nat_ge (z : ennreal) : (\u2200 (n : \u2115) , coe n \u2264 z) \u2192 z = \u22a4 :=\nbegin\n  intro h,\n  suffices : (\u2200 (x : nnreal) , ennreal.of_real x \u2264 z) ,\n  { exact ennreal_eq_top_of_forall_nnreal_ge z this , } ,\n  intros x ,\n  have ex : \u2203 (n : \u2115) , x \u2264 n := exists_nat_ge x ,\n  cases ex with n hn ,\n  apply le_trans (ennreal.of_real_le_of_real hn) ,\n  simp only [h n, nnreal.coe_nat_cast, ennreal.of_real_coe_nat] ,\nend\n\n\nlemma sum_infinitely_many_ones_ennreal : \u2211' (i : \u2115), (1:ennreal) = \u22a4 :=\nbegin\n  apply ennreal_eq_top_of_forall_nat_ge ,\n  intros n ,\n  have ones_summable : summable (\u03bb (n : \u2115) , (1:ennreal)) := ennreal.summable ,\n  have key := sum_le_tsum (finset.range n) (by tidy) ones_summable ,\n  have eq : \u2211 i in (finset.range n) , (1 : ennreal) = n ,\n  { simp only [finset.sum_const, finset.card_range, nat.smul_one_eq_coe] , } ,\n  rwa eq at key ,\nend\n\n\nlemma sum_infinitely_many_pos_const_ennreal' (a : nnreal) (a_pos : 0 < a) : \u2211' (i : \u2115), (a:ennreal) = \u22a4 :=\nbegin\n  apply ennreal_eq_top_of_forall_nnreal_ge ,\n  intros b ,\n  have ex' : \u2203 (n : \u2115) , b/a \u2264 n := exists_nat_ge _ ,\n  have ex : \u2203 (n : \u2115) , b \u2264 n * a ,\n  { cases ex' with m hm ,\n    use m ,\n    have key := mul_le_mul_right' hm a ,\n    have cancancel : b / a * a = b , -- Hide in a corner.\n    { rw [div_mul_eq_mul_div a b a , mul_comm , mul_div_right_comm a b a , div_self (ne_of_gt a_pos)] ,\n      exact one_mul _ , } ,\n    rwa cancancel at key , } ,\n  cases ex with n hn ,\n  have hn' := ennreal.coe_mono hn ,\n  have eq\u2080 : ((a * n : nnreal) : ennreal) = (a : ennreal)*( n: ennreal) := by simp only [ennreal.coe_nat, ennreal.coe_mul],\n  nth_rewrite 1 mul_comm at eq\u2080 ,\n  have eq : \u2211 i in (finset.range n) , (a : ennreal) = n * a ,\n  { simp only [finset.sum_const, nsmul_eq_mul, finset.card_range] , } ,\n  rw \u2190 eq at eq\u2080 ,\n  rw mul_comm at eq\u2080 , -- Hide in another corner.\n  rw eq\u2080 at hn' ,\n  have const_summable : summable (\u03bb (n : \u2115) , (a:ennreal)) := ennreal.summable ,\n  have key := sum_le_tsum (finset.range n) (by tidy) const_summable ,\n  have eq\u2081 : ennreal.of_real b = (b:ennreal) := ennreal.of_real_coe_nnreal ,\n  rw eq\u2081 ,\n  exact le_trans hn' key ,\nend\n\n\nlemma sum_infinitely_many_pos_const_ennreal (a : ennreal) (a_pos : 0 < a) : \u2211' (i : \u2115), (a:ennreal) = \u22a4 :=\nbegin\n  by_cases a_top : a = \u22a4 ,\n  { rw a_top ,\n    exact ennreal.tsum_top , } ,\n  { have eq : ( a.to_nnreal : ennreal) = a := ennreal.coe_to_nnreal a_top ,\n    have a_pos' : 0 < a.to_nnreal := with_top.coe_lt_iff.mp a_pos (ennreal.to_nnreal a) (eq.symm) ,\n    have key := sum_infinitely_many_pos_const_ennreal' a.to_nnreal a_pos' ,\n    rwa eq at key , } ,\nend\n\n\nlemma add_le_add_ennreal {a\u2081 b\u2081 a\u2082 b\u2082 : ennreal} (ha : a\u2081 \u2264 a\u2082) (hb : b\u2081 \u2264 b\u2082) :\n  a\u2081 + b\u2081 \u2264 a\u2082 + b\u2082 := add_le_add ha hb \n\n\nlemma le_self_add_ennreal (a b : ennreal) : a \u2264 a + b :=\nbegin\n  suffices : a + 0 \u2264 a + b ,\n  { simpa [this] , } ,\n  apply add_le_add_ennreal _ _ ,\n  { have a_eq_a : a = a := by refl ,\n    exact le_of_eq a_eq_a , } ,\n  simp only [zero_le, ennreal.bot_eq_zero] ,\nend\n\n\nlemma self_sub_le_self_sub_ennreal (a b\u2081 b\u2082 : ennreal) (hb : b\u2082 \u2264 b\u2081) : a - b\u2081 \u2264 a - b\u2082 :=\nbegin\n  have a_eq_a : a = a := by refl ,\n  apply ennreal.sub_le_sub (le_of_eq a_eq_a) hb ,\nend\n\n\nlemma le_of_self_sub_le_self_sub_ennreal (a b\u2081 b\u2082 : ennreal) (a_ne_top : a \u2260 \u22a4) (hb\u2081 : b\u2081 \u2264 a) (hb\u2082 : b\u2082 \u2264 a)\n  (hb : a - b\u2081 \u2264 a - b\u2082) : b\u2082 \u2264 b\u2081 :=\nbegin\n  have eq\u2081 : a - (a-b\u2081) = b\u2081 := ennreal.sub_sub_cancel (lt_top_iff_ne_top.mpr a_ne_top) hb\u2081 ,\n  have eq\u2082 : a - (a-b\u2082) = b\u2082 := ennreal.sub_sub_cancel (lt_top_iff_ne_top.mpr a_ne_top) hb\u2082 ,\n  rw [\u2190 eq\u2081 , \u2190 eq\u2082] ,\n  apply self_sub_le_self_sub_ennreal a (a-b\u2082) (a-b\u2081) hb ,\nend\n\n\nlemma sub_larger_ennreal (a b : ennreal) (hab : a \u2264 b) : a - b = 0 :=\nbegin\n  exact ennreal.sub_eq_zero_iff_le.mpr hab ,\nend\n\n\nlemma fin_pos_nnreal_of_fin_pos_ennreal \n  (\u03b5 : ennreal) (\u03b5_pos : 0 < \u03b5) (\u03b5_fin : \u03b5 \u2260 \u22a4) :\n    0 < \u03b5.to_nnreal :=\nbegin\n  set \u03b5' := \u03b5.to_nnreal with h\u03b5' ,\n  have eq : ennreal.of_nnreal_hom \u03b5' = \u03b5 := ennreal.coe_to_nnreal \u03b5_fin ,\n  by_contra contra ,\n  simp only [not_lt, le_zero_iff] at contra ,\n  rw contra at eq ,\n  simp only [ennreal.coe_of_nnreal_hom, ennreal.coe_zero] at eq,\n  rw \u2190eq at \u03b5_pos ,\n  have key := ne_of_lt \u03b5_pos ,\n  contradiction ,\nend\n\n\nlemma ennreal_lt_top_iff_ne_top (z : ennreal) : \n  z < \u22a4 \u2194 z \u2260 \u22a4 \n    := lt_top_iff_ne_top\n\n\nlemma ennreal_lt_top_of_ne_top (z : ennreal) (hz : z < \u22a4) : z \u2260 \u22a4 \n    := (ennreal_lt_top_iff_ne_top z).mp hz\n\n\nlemma ennreal_ne_top_of_lt_top (z : ennreal) (hz : z \u2260 \u22a4) : z < \u22a4\n    := (ennreal_lt_top_iff_ne_top z).mpr hz\n\n\nlemma lt_add_pos_ennreal (z \u03b5 : ennreal) (hz : z \u2260 \u22a4) (\u03b5_pos : 0 < \u03b5) : \n  z < z + \u03b5 :=\nbegin\n  by_cases \u03b5_fin : \u03b5 = \u22a4 ,\n  { simp only [\u03b5_fin, ennreal.add_top] ,\n    exact lt_top_iff_ne_top.mpr hz , } ,\n  have key := ((@ennreal.add_lt_add_iff_left z) \u03b5 0 ( (ennreal_lt_top_iff_ne_top z).mpr hz)).mpr \u03b5_pos,\n  simp only [add_zero] at key ,\n  exact key ,\nend\n\n\nlemma nbhd_top_ennreal' (U : set ennreal) (hU : U \u2208 \ud835\udcdd \u221e) :\n  \u2203 (a : nnreal) , Ioi (a : \u211d\u22650\u221e) \u2286 U :=\nbegin\n  have ns := ennreal.nhds_top' ,\n  rw ns at hU ,\n  rw mem_infi_iff' at hU ,\n  rcases hU with \u27e8 I , \u27e8 I_fin , \u27e8v , \u27e8 V_supset_Ioi , inter_V_subset_U \u27e9 \u27e9 \u27e9 \u27e9 ,\n  have ex_ub : \u2203 (b : nnreal) , \u2200 i \u2208 I , i \u2264 b \n    := exists_upper_bound_image I (\u03bb (b : nnreal), b) I_fin , -- don't go to plain sight!\n  cases ex_ub with b hb ,\n  use b ,\n  intros x hx ,\n  rw mem_Ioi at hx,\n  have key : x \u2208 \u22c2 (i \u2208 I) , (v i) ,\n  { rw mem_bInter_iff ,\n    intros i hi ,\n    have key := V_supset_Ioi i hi ,\n    rw mem_principal_sets at key ,\n    exact key (lt_of_le_of_lt (ennreal.coe_mono (hb i hi)) hx) , } ,\n  exact inter_V_subset_U key ,\nend\n\n\nlemma nbhd_top_ennreal (U : set ennreal) (hU : U \u2208 \ud835\udcdd \u221e) :\n  \u2203 (a < \u22a4) , Ioi (a : \u211d\u22650\u221e) \u2286 U :=\nbegin\n  have key := nbhd_top_ennreal' U hU ,\n  cases key with a' ha' ,\n  use a' ,\n  exact \u27e8 ennreal.coe_lt_top , ha' \u27e9 ,\nend\n\n\nlemma continuous_const_sub_nnreal (a : nnreal) :\n  continuous (\u03bb (x : nnreal) , a-x ) :=\nbegin\n  set sub := (\u03bb (p : nnreal \u00d7 nnreal) , p.1 - p.2) with h_sub ,\n  set to_pair := (\u03bb (x : nnreal) , (\u27e8a,x\u27e9 : nnreal \u00d7 nnreal)) with h_to_pair ,\n  have cont_to_pair : continuous to_pair \n    := @continuous.prod_mk nnreal nnreal nnreal _ _ _ (\u03bb x , a) (\u03bb x , x) (continuous_const) (continuous_id') ,\n  have eq : sub \u2218 to_pair = (\u03bb (x : nnreal) , a-x ) := by refl , -- hide in corners\n  rw \u2190 eq ,\n  exact continuous.comp continuous_sub cont_to_pair ,\nend\n\n-- Why could I not find (a symmetric version of) this?\nlemma equality_of_restrictions {\u03b3 \u03b4 : Type*} [topological_space \u03b3] {f g : \u03b3 \u2192 \u03b4} {G : set \u03b3} {x\u2080 : \u03b3} (hfg : \u2200 (x \u2208 G) , f x = g x) (hx\u2080 : x\u2080 \u2208 G) :\n  map f (\ud835\udcdd[G] x\u2080) \u2264 map g (\ud835\udcdd[G] x\u2080) :=\nbegin\n  intros V hV ,\n  rcases hV with \u27e8 U , hU_nhd , \u27e8 T , \u27e8 hT_princ , hUT \u27e9 \u27e9  \u27e9 ,\n  use U ,\n  split , \n  { exact hU_nhd , } ,\n  use G ,\n  split , \n  { exact mem_principal_self G , } ,\n  intros y hy ,\n  have y_in_G : y \u2208 G := mem_of_mem_inter_right hy ,\n  rw mem_preimage ,\n  rw (hfg y (mem_of_mem_inter_right hy)) ,\n  have y_in_bigger : y \u2208 U \u2229 T := inter_subset_inter_right U hT_princ hy , \n  exact hUT y_in_bigger , \nend\n\n\nlemma sub_ennreal_nnreal_continuous_on_ne_top : \n  continuous_on (\u03bb p : ennreal \u00d7 nnreal, p.1 - p.2) { p : ennreal \u00d7 nnreal | p.1 \u2260 \u22a4 } :=\nbegin\n  set proj : ennreal \u00d7 nnreal \u2192 nnreal \u00d7 nnreal := \u03bb p , \u27e8ennreal.to_nnreal(p.1), p.2\u27e9 with h_proj ,\n  have proj_cont : continuous_on proj { p : ennreal \u00d7 nnreal | p.1 \u2260 \u22a4 } ,\n  { have id_cont : continuous_on (\u03bb (z : nnreal) , z) univ := continuous_on_id ,\n    have eq_fun : proj = prod.map ennreal.to_nnreal (\u03bb (z : nnreal) , z) := by refl ,\n    have eq_set : { p : ennreal \u00d7 nnreal | p.1 \u2260 \u22a4 } = { z : ennreal | z \u2260 \u22a4 }.prod (univ : set nnreal) := by tidy ,\n    rw [eq_fun, eq_set] ,\n    exact continuous_on.prod_map ennreal.continuous_on_to_nnreal id_cont , } ,\n  set sub := (\u03bb p : nnreal \u00d7 nnreal, p.1 - p.2) with h_sub ,\n  have eq : \u2200 p \u2208 { p : ennreal \u00d7 nnreal | p.1 \u2260 \u22a4 } , (\u03bb p : ennreal \u00d7 nnreal, p.1 - p.2) p = (coe \u2218 sub \u2218 proj) p ,\n  { intros p hp ,\n    rw [h_proj , h_sub] ,\n    dsimp ,\n    simp only [mem_set_of_eq, ne.def] at hp ,\n    have coes : p.fst = (p.fst.to_nnreal : ennreal) ,\n    { simp only [hp, ne.def, not_false_iff, ennreal.coe_to_nnreal] , } ,\n    nth_rewrite 0 coes ,\n    apply ennreal.coe_sub.symm , } ,\n  suffices : continuous_on (coe \u2218 sub \u2218 proj) { p : ennreal \u00d7 nnreal | p.1 \u2260 \u22a4 } ,\n  { exact (continuous_on_congr (eq_on.symm eq)).mp this , } ,\n  have cont := continuous.comp_continuous_on continuous_sub proj_cont ,\n  apply continuous.comp_continuous_on (ennreal.continuous_coe) cont ,\nend\n\n\nlemma sub_sum_nnreal (a b c : nnreal) : a - (b + c) = a - b - c :=\nbegin\n  have lhs : a - (b + c) = (a.val - b.val - c.val).to_nnreal , --nnreal.of_real (a.val - b.val - c.val) ,\n  { rw nnreal.sub_def ,\n    apply congr_arg ,\n    cases c, \n    cases b, \n    cases a, \n    dsimp at * ,\n    ring , } ,\n  have rhs : a - b - c = (a.val - b.val - c.val).to_nnreal , -- nnreal.of_real (a.val - b.val - c.val) ,\n  { by_cases hab : b \u2264 a ,\n    { have hab' : b.val \u2264 a.val := hab ,\n      have hab'' : 0 \u2264 a.val - b.val := by linarith ,\n      have a_sub_b_val : (a-b).val = a.val - b.val ,\n      { have mx : max (a.val - b.val) 0 = a.val - b.val := max_eq_left hab'' ,\n        rw nnreal.sub_def ,\n        unfold real.to_nnreal ,\n        simp_rw mx ,\n        exact mx , } ,\n      set d := a-b with hd ,\n      rw \u2190a_sub_b_val ,\n      rw nnreal.sub_def ,\n      apply congr_arg ,\n      refl , } ,\n    { simp only [not_le] at hab ,\n      have le : a \u2264 b := le_of_lt hab , -- Such reasoning,\n      have le' : a.val \u2264 b.val := le , -- obviously, is the \n      have le'' : a.val - b.val \u2264 0 := by linarith , -- very\n      have c_nn : 0 \u2264 c.val := c.prop , -- heart of the asserted\n      have le''' : a.val - b.val - c.val \u2264 0 := by linarith , -- fact.\n      have mx : max (a.val - b.val - c.val) 0 = 0 := max_eq_right le''' ,\n      have a_sub_b : a - b = 0 := nnreal.sub_eq_zero le ,\n      have z_sub_c : 0 - c = 0 := le_zero_iff.mp (nnreal.sub_le_self) ,\n      rw [a_sub_b , z_sub_c] ,\n      unfold real.to_nnreal ,\n      simp_rw mx ,\n      refl , } ,\n  } ,\n  rw [lhs, rhs] ,\nend\n\n\nlemma sub_sum_ennreal (a b c : ennreal) : a - (b + c) = a - b - c :=\nbegin\n  by_cases fin : b < \u221e \u2227 c < \u221e ,\n  { have b_eq : (b.to_nnreal : ennreal) = b := ennreal.coe_to_nnreal (ennreal.lt_top_iff_ne_top.mp fin.left) ,\n    have c_eq : (c.to_nnreal : ennreal) = c := ennreal.coe_to_nnreal (ennreal.lt_top_iff_ne_top.mp fin.right) ,\n    rw [\u2190b_eq, \u2190c_eq] ,\n    set \u03b9 := (coe : nnreal \u2192 ennreal) with h\u03b9 ,\n    set b' := b.to_nnreal with hb' ,\n    set c' := c.to_nnreal with hc' ,\n    have eq\u2082 : \u03b9 (b'+c') = \u03b9 b' + \u03b9 c' := @ennreal.coe_add b' c' ,\n    have sum_fin : b + c < \u22a4 \n      := by simp only [fin.left, fin.right, ennreal.add_lt_top, and_self] ,\n    by_cases a_top : a = \u22a4 ,\n    { rw a_top ,\n      have sum_ne_top := ennreal.lt_top_iff_ne_top.mp sum_fin ,\n      have lhs : \u22a4 - \u03b9 (b'+c') = \u22a4 := ennreal.top_sub_coe , -- to a corner\n      have rhs\u2081 : \u22a4-(\u03b9 b') = \u22a4 := ennreal.top_sub_coe , \n      have rhs\u2082 : \u22a4-(\u03b9 c') = \u22a4 := ennreal.top_sub_coe ,\n      rw [rhs\u2081 , rhs\u2082 , \u2190eq\u2082 , lhs] , } ,\n    { have a_eq : (a.to_nnreal : ennreal) = a := ennreal.coe_to_nnreal a_top ,\n      rw [\u2190a_eq] ,\n      set a' := a.to_nnreal with ha' ,\n      have key := sub_sum_nnreal a.to_nnreal b.to_nnreal c.to_nnreal ,\n      have key' := congr_arg (coe : nnreal \u2192 ennreal) key , -- quickly, to another corner\n      have eq\u2081 : \u03b9 (a' - (b'+c')) = (\u03b9 a') - (\u03b9 (b'+c')) := @ennreal.coe_sub (b'+c') a' ,\n      have eq\u2083 : \u03b9 (a' - b' - c') = (\u03b9 (a' - b')) - (\u03b9 (c')) := @ennreal.coe_sub c' (a'-b') ,\n      have eq\u2084 : \u03b9 (a' - b') = (\u03b9 a') - (\u03b9 b') := @ennreal.coe_sub b' a' ,\n      rwa [\u2190eq\u2082, \u2190eq\u2084, \u2190eq\u2081, \u2190eq\u2083] , } ,\n  } ,\n  { rw not_and_distrib at fin , -- hide\n    cases fin with not_fin not_fin ; simp only [not_lt, top_le_iff] at not_fin ,\n    { rw [not_fin , ennreal.top_add] ,\n      simp only [ennreal.sub_infty, ennreal.zero_sub] , } ,\n    { rw [not_fin , ennreal.add_top] ,\n      simp only [ennreal.sub_infty, ennreal.zero_sub] , } ,\n  } ,\nend\n\n\nlemma continuous_sub_ennreal_nnreal : \n  continuous (\u03bb p : ennreal \u00d7 nnreal, p.1 - p.2) :=\nbegin\n  apply continuous_iff_continuous_at.mpr ,\n  intros p ,\n  by_cases fst_top : p.fst = \u22a4 ,\n  { intros V hV ,\n    simp_rw fst_top at hV ,\n    simp only [ennreal.top_sub_coe] at hV ,\n    have V_super := nbhd_top_ennreal' V hV ,\n    cases V_super with v hv ,\n    set U := set.prod (Ioi (p.2 + v + 1 : ennreal)) (Iio (p.2 + 1)) with hU ,\n    have lt\u2081 : (\u22a4 : \u211d\u22650\u221e) \u2208 (Ioi (p.2 + v + 1 : ennreal)) ,\n    { simp only [true_and, ennreal.coe_lt_top, mem_Ioi, ennreal.add_lt_top] ,\n      exact dec_trivial , } ,\n    have nbhd\u2081 : Ioi (p.2+v+1 : ennreal) \u2208 \ud835\udcdd p.1,\n    { rw fst_top ,\n      --exact is_open.mem_nhds (is_open_Ioi) lt\u2081 ,\n      exact Ioi_mem_nhds lt\u2081 , } ,\n    have nbhd\u2082 : Iio (p.2+1) \u2208 \ud835\udcdd p.2 := is_open.mem_nhds (is_open_Iio) (by simp only [mem_Iio, lt_add_iff_pos_right, zero_lt_one]) ,\n      --:= mem_nhds_sets (is_open_Iio) (by simp only [mem_Iio, lt_add_iff_pos_right, zero_lt_one]) ,\n    have nbhd := prod_is_open.mem_nhds nbhd\u2081 nbhd\u2082 ,\n      --: set.prod (Ioi (p.2 + v + 1 : ennreal)) (Iio (p.2 + 1)) \u2208 \ud835\udcdd p\n      --:= by sorry , -- the above works in another version of mathlib\n    rw [\u2190hU , prod.mk.eta] at nbhd , --works in another version of mathlib\n    --have nbhd : U \u2208 \ud835\udcdd p := by sorry , -- again, use the above in a fresh mathlib\n    set f := (\u03bb p : ennreal \u00d7 nnreal, p.1 - p.2) with hf ,\n    have ss : U \u2286 f\u207b\u00b9' V ,\n    { rintros q \u27e8 hq\u2081 , hq\u2082\u27e9 ,\n      simp only [mem_Ioi] at hq\u2081 ,\n      simp only [mem_Iio] at hq\u2082 ,\n      have hq\u2082' : (q.snd : ennreal) < p.snd + 1 := ennreal.coe_lt_coe.mpr hq\u2082 ,\n      have hq\u2081' : (p.snd : ennreal) + 1 < q.fst - v ,\n      { have le : (v : ennreal) \u2264 q.fst ,\n        { apply le_of_lt _ ,\n          calc (v : ennreal) \u2264 (v : ennreal) + (1 + p.snd) : le_self_add_ennreal _ _\n          ... = (p.snd : ennreal) + v + 1                  : by ring\n          ... < q.fst                                      : hq\u2081 , } ,\n        have eq : q.fst - v + v = q.fst := ennreal.sub_add_cancel_of_le le ,\n        have eq' : (p.snd : ennreal) + 1 + v = (p.snd : ennreal) + v + 1 := by ring ,\n        rw [\u2190eq , \u2190eq'] at hq\u2081 ,\n        exact (ennreal.add_lt_add_iff_right (@ennreal.coe_lt_top v)).mp hq\u2081 , } ,\n      have gt : (v : ennreal) < f q ,\n      { rw hf ,\n        dsimp ,\n        have lt := lt_trans hq\u2082' hq\u2081' ,\n        have lt' := ennreal.zero_lt_sub_iff_lt.mpr lt ,\n        have rw\u2080 : q.fst - v - q.snd = q.fst - q.snd - v ,\n        { rw [\u2190(sub_sum_ennreal _ _ _) , \u2190(sub_sum_ennreal _ _ _) , add_comm ] , } ,\n        rw rw\u2080 at lt' ,\n        apply ennreal.zero_lt_sub_iff_lt.mp lt' ,\n      } ,\n      exact hv gt , } ,\n    apply (\ud835\udcdd p).sets_of_superset nbhd ss , } ,\n  { intros V hV ,\n    dsimp at hV ,\n    have key := sub_ennreal_nnreal_continuous_on_ne_top p fst_top hV ,\n    rcases key with \u27e8 U , U_nbhd , \u27e8 T , \u27e8 hT , hUT \u27e9 \u27e9 \u27e9 ,\n    set S := { p : ennreal \u00d7 nnreal | p.1 \u2260 \u22a4 } with hS ,\n    rw mem_principal_sets at hT ,\n    have S_prod : S = {z : ennreal | z \u2260 \u22a4}.prod (univ : set nnreal) ,\n    { ext q ,\n      simp only [and_true, mem_univ, mem_set_of_eq, mem_prod] , } ,\n    have nbhd\u2081 : {z : ennreal | z \u2260 \u22a4} \u2208 \ud835\udcdd p.fst := is_open.mem_nhds (is_open_ne) (fst_top) , -- mem_nhds_sets (is_open_ne) (fst_top) ,\n    have nbhd\u2082 : (univ : set nnreal) \u2208 \ud835\udcdd p.snd := is_open.mem_nhds (is_open_univ) (mem_univ _) ,\n    have S_nbhd : {z : ennreal | z \u2260 \u22a4}.prod (univ : set nnreal) \u2208 \ud835\udcdd (\u27e8p.1, p.2\u27e9 : ennreal \u00d7 nnreal) \n      := prod_is_open.mem_nhds nbhd\u2081 nbhd\u2082 , -- prod_mem_nhds_sets nbhd\u2081 nbhd\u2082 ,\n    rw [\u2190S_prod , prod.mk.eta] at S_nbhd ,\n    have US_nbhd : U \u2229 S \u2208 \ud835\udcdd p := (\ud835\udcdd p).inter_sets U_nbhd S_nbhd ,\n    have US_ss_UT : U \u2229 S \u2286 U \u2229 T := inter_subset_inter_right U hT ,\n    have UT_nbhd : U \u2229 T \u2208 \ud835\udcdd p := (\ud835\udcdd p).sets_of_superset US_nbhd US_ss_UT ,\n    apply (\ud835\udcdd p).sets_of_superset UT_nbhd hUT , } ,\nend\n\n\n-- Remark: \n-- This is not even the right generality for the continuity of\n-- subtraction on a subset of `ennreal \u00d7 ennreal`. I guess we\n-- have continuity on the complement of the singleton `{\u27e8\u221e,\u221e\u27e9}`.\n-- With that, a few of the subsequent corner-hidings would simplify.\n-- But I had surprisingly hard time working with ennreals and \n-- subtraction, so I gave up and just aimed at a sorry-free (TM)\n-- exercise...\nlemma continuous_sub_ennreal_ennreal_snd_ne_top : \n  continuous_on (\u03bb p : ennreal \u00d7 ennreal, p.1 - p.2) { p : ennreal \u00d7 ennreal | p.snd \u2260 \u221e} :=\nbegin\n  have g_cont := continuous_sub_ennreal_nnreal ,\n  set g := (\u03bb p : ennreal \u00d7 nnreal, p.1 - p.2) with hg ,\n  set f := (\u03bb p : ennreal \u00d7 ennreal, p.1 - p.2) with hf ,\n  set \u03c6 := (\u03bb p : ennreal \u00d7 ennreal, ( \u27e8p.1 , (p.2).to_nnreal \u27e9 : ennreal \u00d7 nnreal ) ) with h\u03c6 ,\n  set S := { p : ennreal \u00d7 ennreal | p.snd \u2260 \u221e} with hS ,\n  have \u03c6_cont : continuous_on \u03c6 S ,\n  { have key\u2081' : continuous (\u03bb (z : ennreal) , z ) := continuous_id' ,\n    have key\u2081 : continuous_on (\u03bb (z : ennreal) , z ) univ := continuous.continuous_on key\u2081' ,\n    have key\u2082 := ennreal.continuous_on_to_nnreal ,\n    have \u03c6_prod_map : \u03c6 = prod.map (\u03bb (z : ennreal) , z ) ennreal.to_nnreal := by refl ,\n    have S_prod_set : S = (univ : set ennreal).prod {w : ennreal | w \u2260 \u221e}, \n    { simp only [eq_self_iff_true] at hS , \n      ext p, \n      cases p, \n      dsimp , \n      simp only [true_and, mem_univ] , } ,\n    rw [\u03c6_prod_map , S_prod_set] ,\n    exact continuous_on.prod_map key\u2081 key\u2082 , } ,\n  have comp_cont : continuous_on (g \u2218 \u03c6) S := continuous.comp_continuous_on g_cont \u03c6_cont ,\n  have agree : \u2200 p \u2208 S , f p = (g \u2218 \u03c6) p ,\n  { intros p hpS ,\n    rw [hf , hg , h\u03c6 ] ,\n    simp only [function.comp_app] ,\n    rw ennreal.coe_to_nnreal hpS , } ,\n  have pfun_eq : pfun.res f S = pfun.res (g \u2218 \u03c6) S ,\n  { ext ,\n    rw pfun.mem_res ,\n    rw pfun.mem_res ,\n    split ,\n    { rintros \u27e8 hx , val \u27e9 ,\n      rw agree x hx at val ,\n      exact \u27e8 hx , val \u27e9 , } ,\n    { rintros \u27e8 hx , val \u27e9 ,\n      rw \u2190 agree x hx at val ,\n      exact \u27e8 hx , val \u27e9 , } ,\n  } ,\n  intros p hp ,\n  rw continuous_within_at_iff_ptendsto_res ,\n  rw [pfun_eq , agree p hp] ,\n  rw \u2190 continuous_within_at_iff_ptendsto_res ,\n  exact comp_cont p hp ,\nend\n\n\n-- Remark: This should get an easier proof from the right\n-- continuity result of subtraction on ennreals.\nlemma continuous_on_const_sub_ennreal (a : ennreal) (a_ne_top : a \u2260 \u22a4) :\n  continuous_on (\u03bb (x : ennreal) , a-x ) {z : ennreal | z \u2260 \u22a4} :=\nbegin\n  set f := (\u03bb (x : ennreal) , a-x ) with hf ,\n  set S := { z : ennreal | z \u2260 \u22a4 } with hS ,\n  have cont_cast : continuous_on ennreal.to_nnreal S := ennreal.continuous_on_to_nnreal ,\n  set f\u2080 := (\u03bb (x : nnreal) , a.to_nnreal-x ) with hf\u2080 ,\n  have cont_f\u2080 : continuous f\u2080 := continuous_const_sub_nnreal (ennreal.to_nnreal a) ,\n  have cont_f\u2080' : continuous_on f\u2080 univ := continuous.continuous_on cont_f\u2080 ,\n  have cont_comp' := continuous_on.comp cont_f\u2080' cont_cast (by simp only [preimage_univ, subset_univ]) ,\n  have cont_comp := continuous.comp_continuous_on ennreal.continuous_coe cont_comp' ,\n  have eq\u2080 : ( \u2200 (z \u2208 S) , f z = (coe \u2218 f\u2080 \u2218 ennreal.to_nnreal) z ) ,\n  { intros z hz ,\n    rw [hf , hf\u2080] ,\n    dsimp ,\n    have a_eq := ennreal.coe_to_nnreal a_ne_top ,\n    have z_eq := ennreal.coe_to_nnreal hz ,\n    rw [\u2190a_eq , \u2190z_eq] ,\n    apply ennreal.coe_sub.symm , } ,\n  intros z hzS V hV ,\n  have hV' := hV ,\n  rw (eq\u2080 z hzS) at hV' ,\n  specialize cont_comp z hzS hV' ,\n  have key := equality_of_restrictions eq\u2080 hzS ,\n  exact key cont_comp ,\nend\n\n\n-- Remark: This also should get an easier proof from the right\n-- continuity result of subtraction on ennreals.\nlemma continuous_const_sub_ennreal (a : ennreal) (a_ne_top : a \u2260 \u22a4) :\n  continuous (\u03bb (x : ennreal) , a-x ) :=\nbegin\n  set f := (\u03bb (x : ennreal) , a-x ) with hf ,\n  apply continuous_iff_continuous_at.mpr ,\n  intros x ,\n  by_cases hx : x = \u22a4 ,\n  { rw hx ,\n    have mem_Ioi : \u22a4 \u2208 Ioi a := ennreal.lt_top_iff_ne_top.mpr a_ne_top ,\n    have open_Ioi : is_open (Ioi a) := is_open_Ioi , \n    have nhd_Ioi : Ioi a \u2208 \ud835\udcdd \u22a4 := is_open.mem_nhds open_Ioi mem_Ioi , --mem_nhds_sets open_Ioi mem_Ioi ,\n    intros V hV ,\n    have val_at_top : f \u22a4 = 0 := by simp only [ennreal.sub_eq_zero_iff_le, le_top] ,\n    rw val_at_top at hV ,\n    have mem_V : (0 : ennreal) \u2208 V ,\n    { exact mem_of_mem_nhds hV , } ,\n    have ss_preim : Ioi a \u2286 f\u207b\u00b9' V ,\n    { intros z hz ,\n      have val : f z = 0 := ennreal.sub_eq_zero_iff_le.mpr (le_of_lt hz) ,\n      rwa \u2190 val at mem_V , } ,\n    exact (\ud835\udcdd \u22a4).sets_of_superset nhd_Ioi ss_preim , } ,\n  { set S := { z : ennreal | z \u2260 \u22a4 } with hS ,\n    have nbhd : S \u2208 (\ud835\udcdd x) ,\n    { have opn : is_open S := is_open_ne ,\n      --exact mem_nhds_sets opn good ,\n      exact is_open.mem_nhds opn hx , } ,\n    suffices : continuous_on f S ,\n    { intros V hV ,\n      have key := this x hx hV ,\n      rcases key with \u27e8 U , U_nhd , \u27e8 T , hT , hUT\u27e9 \u27e9 ,\n      rw mem_principal_sets at hT ,\n      have T_nbhd : T \u2208 (\ud835\udcdd x) := (\ud835\udcdd x).sets_of_superset nbhd hT ,\n      have nbhd\u2080 : U \u2229 T \u2208 (\ud835\udcdd x) := inter_mem_sets U_nhd T_nbhd ,\n      rw mem_map ,      \n      apply (\ud835\udcdd x).sets_of_superset nbhd\u2080 hUT , } ,\n    exact continuous_on_const_sub_ennreal a a_ne_top , } ,\nend\n\n\nlemma lim_enn_of_lim_R {s : \u2115 \u2192 \u211d} {l : \u211d} (hlim : tendsto s at_top (\ud835\udcdd l)) : \n  tendsto (ennreal.of_real \u2218 s) at_top (\ud835\udcdd (ennreal.of_real l))\n    := ennreal.tendsto_of_real hlim \n\n\nlemma nnreal_nbhd_finite_ennreal (x : ennreal) :\n  x \u2260 \u22a4 \u2192 { z : ennreal | z \u2260 \u22a4 } \u2208 \ud835\udcdd x :=\nbegin\n  intros hx ,\n  have op : is_open { z : ennreal | z \u2260 \u22a4 } := is_open_ne ,\n  --TODO: depending on mathlib version, one of the following works...\n  --exact mem_nhds_sets op hx ,\n  exact is_open.mem_nhds op hx ,\nend\n\n\nlemma ennreal_to_nnreal_continuous_on_nnreal :\n  continuous_on ennreal.to_nnreal { z : ennreal | z \u2260 \u22a4 } :=\nbegin\n  exact ennreal.continuous_on_to_nnreal , \nend\n\n\nlemma ennreal_to_real_continuous_on_nnreal :\n  continuous_on ennreal.to_real { z : ennreal | z \u2260 \u22a4 } :=\nbegin\n  have eq : ennreal.to_real = nnreal.to_real_hom \u2218 ennreal.to_nnreal := by refl ,\n  rw eq ,\n  intros z hz ,\n  have cont_at_nnreal \n    := continuous_on.continuous_at ennreal.continuous_on_to_nnreal (nnreal_nbhd_finite_ennreal z hz), \n  apply @tendsto.comp _ _ _ _ _ _ (\ud835\udcdd (ennreal.to_nnreal z)) _ ,\n  { simp only [nnreal.coe_to_real_hom, nnreal.tendsto_coe] ,\n    intros U hU ,\n    assumption , } ,\n  { exact tendsto_inf_left cont_at_nnreal , } ,\nend\n\n\nlemma ennreal_ne_top_of_le_nnreal {c : nnreal} {x : ennreal} (h_le : x \u2264 c) : x \u2260 \u22a4 :=\nbegin\n  by_contra contra ,\n  rw not_not at contra ,\n  rw contra at h_le ,\n  simp only [ennreal.not_top_le_coe] at h_le ,\n  exact h_le , \nend\n\n\nlemma finval_of_bdd_ennval {\u03b1 : Type*} {f : \u03b1 \u2192 ennreal} :\n  bdd_ennval f \u2192 \u2200 (a : \u03b1) , f(a) \u2260 \u22a4 :=\nbegin\n  intros f_bdd a ,\n  cases f_bdd with c hc ,\n  exact ennreal_ne_top_of_le_nnreal (hc a) ,\nend\n\n\nlemma bdd_Rval_add {\u03b1 : Type*} {f g : \u03b1 \u2192 \u211d}\n  (f_bdd : bdd_Rval f) (g_bdd : bdd_Rval g) : bdd_Rval (f+g) :=\nbegin\n  cases f_bdd with c hc ,\n  cases g_bdd with d hd ,\n  use (c+d) ,\n  intros x ,\n  apply le_trans (abs_add (f(x)) (g(x))) (add_le_add (hc x) (hd x)) ,\nend\n\n\nlemma bdd_ennval_add {\u03b1 : Type*} {f g : \u03b1 \u2192 ennreal}\n  (f_bdd : bdd_ennval f) (g_bdd : bdd_ennval g) : bdd_ennval (f+g) :=\nbegin\n  cases f_bdd with c hc ,\n  cases g_bdd with d hd ,\n  use (c+d) ,\n  intros x ,\n  exact add_le_add (hc x) (hd x) ,\nend\n\n\nlemma bdd_ennval_of_le_bdd_ennval {\u03b1 : Type*} {f g : \u03b1 \u2192 ennreal}\n  (hfg : f \u2264 g) (g_bdd : bdd_ennval g) : bdd_ennval f :=\nbegin\n  cases g_bdd with c hc ,\n  use c ,\n  intros x ,\n  exact le_trans (hfg x) (hc x) ,\nend\n\n\nlemma bdd_ennval_of_bdd_Rval {\u03b1 : Type*} {f : \u03b1 \u2192 \u211d}\n  (f_bdd : bdd_Rval f) : bdd_ennval (ennreal.of_real \u2218 f) :=\nbegin\n  cases f_bdd with c hc ,\n  use (c.to_nnreal) ,\n  intros x ,\n  apply ennreal.coe_mono ,\n  apply real.to_nnreal_mono (le_trans (le_abs_self (f(x))) (hc x)) ,\nend\n\n\nlemma lim_R_of_lim_enn (s : \u2115 \u2192 ennreal) (l : ennreal) \n  (hlim : tendsto s at_top (\ud835\udcdd l)) (hfin : l \u2260 \u22a4) : \n    tendsto (ennreal.to_real \u2218 s) at_top (\ud835\udcdd (ennreal.to_real l)) :=\nbegin\n  have cont_at : continuous_at ennreal.to_real l\n    := continuous_on.continuous_at ennreal_to_real_continuous_on_nnreal (nnreal_nbhd_finite_ennreal l hfin) , \n  exact tendsto.comp cont_at hlim ,\nend\n\n\nlemma cont_R_of_cont_bdd_enn {\u03b1 : Type*} [topological_space \u03b1]\n  (f : \u03b1 \u2192 ennreal) (f_cont : continuous f) (f_bdd : bdd_ennval f) :\n    continuous (ennreal.to_real \u2218 f) :=\nbegin\n  apply continuous_iff_continuous_at.mpr ,\n  intros a ,\n  set x := f(a) with hx ,\n  have x_fin : x \u2260 \u22a4 := finval_of_bdd_ennval f_bdd a , \n  have cont_at\u2081 := continuous_iff_continuous_at.mp f_cont a ,\n  have cont_at\u2082 : continuous_at ennreal.to_real x\n    := continuous_on.continuous_at ennreal_to_real_continuous_on_nnreal (nnreal_nbhd_finite_ennreal x x_fin) , \n  exact @continuous_at.comp \u03b1 ennreal \u211d _ _ _ ennreal.to_real f a cont_at\u2082 cont_at\u2081 ,\nend\n\n\nlemma cont_enn_of_cont_R {\u03b1 : Type*} [topological_space \u03b1] (f : \u03b1 \u2192 \u211d) (f_cont : continuous f) : \n  continuous (ennreal.of_real \u2218 f) \n    := continuous.comp (ennreal.continuous_of_real) f_cont \n\n\nlemma le_of_forall_pos_le_add_nnreal (a b : nnreal) : \n  (\u2200 (\u03b5 : nnreal) , (\u03b5 > 0) \u2192 (a \u2264 b + \u03b5)) \u2192 a \u2264 b :=\nbegin\n  exact nnreal.le_of_forall_pos_le_add ,\nend\n\n\nlemma tendsto_of_ev_same {\u03b1 \u03b2 : Type*} {F\u03b1 : filter \u03b1} {F\u03b2 : filter \u03b2}\n  (f g : \u03b1 \u2192 \u03b2) (h_ev_eq : \u2203 (S : set \u03b1) , S \u2208 F\u03b1.sets \u2227 \n    \u2200 x , x \u2208 S \u2192 f(x) = g(x) ) :\n      tendsto f F\u03b1 F\u03b2 \u2192 tendsto g F\u03b1 F\u03b2 :=\nbegin\n  intro tends_f ,\n  cases h_ev_eq with S hS ,\n  intros T hT ,\n  have key := F\u03b1.inter_sets hS.1 (tends_f hT),\n  have eq_fg : S \u2229 f\u207b\u00b9' T = S \u2229 g\u207b\u00b9' T ,\n  { ext x ,\n    simp only [mem_inter_eq, mem_preimage, and.congr_right_iff] ,\n    intro hxS ,\n    rwa hS.2 x , } ,  \n  rw eq_fg at key ,\n  exact F\u03b1.sets_of_superset key (set.inter_subset_right _ _ ) ,\nend\n\n\nlemma lim_R_of_ev_same (x y : \u2115 \u2192 \u211d)\n  (hevsame : \u2203 (m : \u2115), \u2200 (k : \u2115) , k \u2265 m \u2192 x(k) = y(k))\n  (hlim : tendsto x at_top (\ud835\udcdd 0)) :\n    tendsto y at_top (\ud835\udcdd 0) :=\nbegin\n  apply tendsto_of_ev_same x y ,\n  { cases hevsame with m hm ,\n    set S := { k : \u2115 | k \u2265 m } ,\n    have mem : S \u2208 at_top.sets := mem_at_top m ,\n    use [ S , mem ] ,\n    exact hm , } , \n  exact hlim ,\nend\n\n\nlemma lim_enn_of_ev_same (x y : \u2115 \u2192 ennreal)\n  (hevsame : \u2203 (m : \u2115), \u2200 (k : \u2115) , k \u2265 m \u2192 x(k) = y(k))\n  (hlim : tendsto x at_top (\ud835\udcdd 0)) :\n    tendsto y at_top (\ud835\udcdd 0) :=\nbegin\n  apply tendsto_of_ev_same x y ,\n  { cases hevsame with m hm ,\n    set S := { k : \u2115 | k \u2265 m } ,\n    have mem : S \u2208 at_top.sets := mem_at_top m ,\n    use [ S , mem ] ,\n    exact hm , } , \n  exact hlim ,\nend\n\n\nlemma of_real_lt_of_lt_to_real {x : \u211d} {z : ennreal} (x_lt_z : x < z.to_real) (x_nn : 0 \u2264 x) : \n  ennreal.of_real(x) < z :=\nbegin\n  by_cases z_top : z = \u22a4 ,\n  { rw z_top ,\n    exact lt_top_iff_ne_top.mpr (@ennreal.of_real_ne_top x) , } ,\n  { have le : ennreal.of_real x \u2264 z := ennreal.of_real_le_of_le_to_real (le_of_lt x_lt_z) ,\n    have neq : ennreal.of_real x \u2260 z ,\n    { by_contra con ,\n      push_neg at con ,\n      rw \u2190con at x_lt_z ,\n      rw (ennreal.to_real_of_real x_nn) at x_lt_z ,\n      linarith , } ,\n    exact (ne.le_iff_lt neq).mp le , } ,\nend\n\n\nlemma of_real_mono : monotone ennreal.of_real :=\nbegin\n  intros x y hxy ,\n  exact ennreal.of_real_le_of_real hxy ,\nend\n\n\nlemma of_real_lt_of_lt {x y : \u211d} (x_nn : 0 \u2264 x) (x_lt_y : x < y) : \n  ennreal.of_real x < ennreal.of_real y :=\nbegin\n  have ne : ennreal.of_real x \u2260 ennreal.of_real y ,\n  { intros h ,\n    have rw_x : (ennreal.of_real x).to_real = x := ennreal.to_real_of_real x_nn ,\n    have rw_y : (ennreal.of_real y).to_real = y := ennreal.to_real_of_real (le_of_lt (lt_of_le_of_lt x_nn x_lt_y)) ,\n    have eq : (ennreal.of_real x).to_real = (ennreal.of_real y).to_real := congr_arg ennreal.to_real h ,\n    rw [rw_x , rw_y] at eq ,\n    apply ne_of_lt x_lt_y ,\n    rwa eq at x_lt_y , } ,\n  have le : ennreal.of_real x \u2264 ennreal.of_real y := of_real_mono (le_of_lt x_lt_y) ,\n  exact (ne.le_iff_lt).mp le ,\nend\n\n\nlemma of_real_lt_of_real {x y : \u211d} (hxy : ennreal.of_real x < ennreal.of_real y) : x < y :=\nbegin\n  have x_ne_top : ennreal.of_real x \u2260 \u22a4 := ennreal.of_real_ne_top ,\n  have y_gt' : 0 < ennreal.of_real y := pos_of_gt hxy ,\n  have y_gt : 0 < y := ennreal.of_real_pos.mp y_gt' ,\n  by_contra x_too_large ,\n  simp only [not_lt] at x_too_large , \n  have x_ge := ennreal.of_real_le_of_real x_too_large ,\n  exact not_lt.mpr (le_refl (ennreal.of_real x)) (lt_of_lt_of_le hxy x_ge) ,\nend\n\n\n\nend portmanteau_comeonlean_lemmas\n\nend portmanteau\n\n", "meta": {"author": "kkytola", "repo": "lean_portmanteau", "sha": "ac55eb4e24be43032cbc082e2b68d8fb8bd63f22", "save_path": "github-repos/lean/kkytola-lean_portmanteau", "path": "github-repos/lean/kkytola-lean_portmanteau/lean_portmanteau-ac55eb4e24be43032cbc082e2b68d8fb8bd63f22/portmanteau_comeonlean_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7143399373145526}}
{"text": "/- Yair Gueta : 208624908 : t4\n    Exercise 4\n-/\nimport data.int.basic\n\nvariable  U : Type\nvariables R : U \u2192 U \u2192 Prop\n\n-- Question 9:\nexample : (\u2203 x, \u2200 y, R x y) \u2192 \u2200 y, \u2203 x, R x y :=\nbegin\n  intro,\n  cases a with x,\n  intro,\n  existsi x, exact a_h y\nend\n\n\n-- Question 10:\ntheorem foo {A : Type} {a b c : A} : a = b \u2192 c = b \u2192 a = c :=\nbegin\n  intros, exact a_1.trans a_2.symm,\nend \n\n-- notice that you can now use foo as a rule. The curly braces mean that\n-- you do not have to give A, a, b, or c\n\nsection\n  variable A : Type\n  variables a b c : A\n\n  example (h1 : a = b) (h2 : c = b) : a = c :=\n  foo h1 h2\nend\n\nsection\n  variable {A : Type}\n  variables {a b c : A}\n\n  -- replace the sorry with a proof, using foo and rfl, without using eq.symm.\n  theorem my_symm (h : b = a) : a = b :=\n  by exact foo (eq.refl a) h\n  \n  -- now use foo and my_symm to prove transitivity\n  theorem my_trans (h1 : a = b) (h2 : b = c) : a = c :=\n  by exact foo h1 (my_symm h2)\nend\n\n-- Question 11:\n-- these are the axioms for a commutative ring\n\n#check @add_assoc\n#check @add_comm\n#check @add_zero\n#check @zero_add\n#check @mul_assoc\n#check @mul_comm\n#check @mul_one\n#check @one_mul\n#check @left_distrib\n#check @right_distrib\n#check @add_left_neg\n#check @add_right_neg\n#check @sub_eq_add_neg\n\nvariables x y z : int\n\ntheorem t1 : x - x = 0 :=\ncalc\nx - x = x + -x : by rw sub_eq_add_neg\n    ... = 0      : by rw add_right_neg\n\ntheorem t2 (h : x + y = x + z) : y = z :=\ncalc\ny     = 0 + y        : by rw zero_add\n    ... = (-x + x) + y : by rw add_left_neg\n    ... = -x + (x + y) : by rw add_assoc\n    ... = -x + (x + z) : by rw h\n    ... = (-x + x) + z : by rw add_assoc\n    ... = 0 + z        : by rw add_left_neg\n    ... = z            : by rw zero_add\n\ntheorem t3 (h : x + y = z + y) : x = z :=\ncalc\nx     = x + 0        : by rw add_zero\n    ... = x + (y + -y) : by rw \u2190 add_right_neg\n    ... = (x + y) + -y : by rw add_assoc\n    ... = (z + y) + -y : by rw h\n    ... = z + (y + -y) : by rw add_assoc\n    ... = z + 0        : by rw add_right_neg\n    ... = z            : by rw add_zero\n\ntheorem t4 (h : x + y = 0) : x = -y :=\ncalc\nx     = x + 0        : by rw add_zero\n    ... = x + (y + -y) : by rw add_right_neg\n    ... = (x + y) + -y : by rw add_assoc\n    ... = 0 + -y       : by rw h\n    ... = -y           : by rw zero_add\n\ntheorem t5 : x * 0 = 0 :=\nhave h1 : x * 0 + x * 0 = x * 0 + 0, from\ncalc\n    x * 0 + x * 0 = x * (0 + 0) : by rw mul_add\n            ... = x * 0       : by rw add_zero\n            ... = x * 0 + 0   : by rw add_zero,\nshow x * 0 = 0, from t2 _ _ _ h1\n\ntheorem t6 : x * (-y) = -(x * y) :=\nhave h1 : x * (-y) + x * y = 0, from\ncalc\n    x * (-y) + x * y = x * (-y + y) : by rw mul_add\n                ... = x * 0        : by rw add_left_neg\n                ... = 0            : by rw t5 x,\nshow x * (-y) = -(x * y), from t4 _ _ h1\n\ntheorem t7 : x + x = 2 * x :=\ncalc\nx + x = 1 * x + 1 * x : by rw one_mul\n    ... = (1 + 1) * x   : by rw add_mul\n    ... = 2 * x         : rfl", "meta": {"author": "yairgueta", "repo": "Lean", "sha": "af8a4fa24f76edfdd0dd33f013db194e611e6a86", "save_path": "github-repos/lean/yairgueta-Lean", "path": "github-repos/lean/yairgueta-Lean/Lean-af8a4fa24f76edfdd0dd33f013db194e611e6a86/src/t5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7143399373145526}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport data.real.basic -- imports the real numbers\nimport solutions.section02reals.sheet5 -- import a bunch of previous stuff\n\n/-\n\n# Harder questions\n\nHere are some harder questions. Don't feel like you have\nto do them. We've seen enough techniques to be able to do\nall of these, but the truth is that we've seen a ton of stuff\nin this course already, so probably you're not on top of all of\nit yet, and furthermore we have not seen\nsome techniques which will enable you to cut corners. If you\nwant to become a real Lean expert then see how many of these\nyou can do. I will go through them all in a solutions video,\nso if you like you can try some of them and then watch me\nsolving them.\n\nGood luck! \n-/\n\n\n/-- If `a(n)` tends to `t` then `37 * a(n)` tends to `37 * t`-/\ntheorem tends_to_thirtyseven_mul (a : \u2115 \u2192 \u211d) (t : \u211d) (h : tends_to a t) :\n  tends_to (\u03bb n, 37 * a n) (37 * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a positive constant then\n`c * a(n)` tends to `c * t`. -/\ntheorem tends_to_pos_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (h : tends_to a t)\n  {c : \u211d} (hc : 0 < c) : tends_to (\u03bb n, c * a n) (c * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a negative constant then\n`c * a(n)` tends to `c * t`. -/\ntheorem tends_to_neg_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (h : tends_to a t)\n  {c : \u211d} (hc : c < 0) : tends_to (\u03bb n, c * a n) (c * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a constant then `c * a(n)` tends\nto `c * t`. -/\ntheorem tends_to_const_mul {a : \u2115 \u2192 \u211d} {t : \u211d} (c : \u211d) (h : tends_to a t) :\n  tends_to (\u03bb n, c * a n) (c * t) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `c` is a constant then `a(n) * c` tends\nto `t * c`. -/\ntheorem tends_to_mul_const {a : \u2115 \u2192 \u211d} {t : \u211d} (c : \u211d) (h : tends_to a t) :\n  tends_to (\u03bb n, a n * c) (t * c) :=\nbegin\n  sorry\nend\n\n-- another proof of this result, showcasing some tactics\n-- which I've not covered yet.\ntheorem tends_to_neg' {a : \u2115 \u2192 \u211d} {t : \u211d} (ha : tends_to a t) :\n  tends_to (\u03bb n, - a n) (-t) :=\nbegin\n  convert tends_to_const_mul (-1) ha, -- read about the `convert` tactic in the course notes!\n  { ext, simp }, -- ext is a generic extensionality tactic. Here it's being\n                 -- used to deduce that two functions are the same if they take\n                 -- the same values everywhere\n  { simp },\nend\n\n/-- If `a(n)-b(n)` tends to `t` and `b(n)` tends to `u` then\n`a(n)` tends to `t + u`. -/\ntheorem tends_to_of_tends_to_sub {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (h1 : tends_to (\u03bb n, a n - b n) t) (h2 : tends_to b u) :\n  tends_to a (t+u) :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` then `a(n)-t` tends to `0`. -/\ntheorem tends_to_sub_lim {a : \u2115 \u2192 \u211d} {t : \u211d}\n  (h : tends_to a t) : tends_to (\u03bb n, a n - t) 0 :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` and `b(n)` both tend to zero, then their product tends\nto zero. -/\ntheorem tends_to_zero_mul_tends_to_zero\n  {a b : \u2115 \u2192 \u211d} (ha : tends_to a 0) (hb : tends_to b 0) :\n  tends_to (\u03bb n, a n * b n) 0 :=\nbegin\n  sorry,\nend\n\n/-- If `a(n)` tends to `t` and `b(n)` tends to `u` then\n`a(n)*b(n)` tends to `t*u`. -/\ntheorem tends_to_mul (a b : \u2115 \u2192 \u211d) (t u : \u211d) (ha : tends_to a t)\n  (hb : tends_to b u) : tends_to (\u03bb n, a n * b n) (t * u) :=\nbegin\n  sorry,\nend\n\n-- something we never used!\n/-- A sequence has at most one limit. -/\ntheorem tends_to_unique (a : \u2115 \u2192 \u211d) (s t : \u211d)\n  (hs : tends_to a s) (ht : tends_to a t) : s = t :=\nbegin\n  sorry,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section02reals/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891218080991, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.7143399311399977}}
{"text": "import data.nat.basic\nimport data.nat.prime\nimport number_theory.padics.padic_norm\n\ntheorem padic_norm_primes {p q: \u2115} [p_prime: fact (nat.prime p)] [q_prime: fact (nat.prime q)]\n  (neq: p \u2260 q): padic_norm p q = 1 :=\nbegin\n  have p: padic_val_rat p q = 0,\n  exact_mod_cast @padic_val_nat_primes p q p_prime q_prime neq,\n  simp [padic_norm, p, q_prime.1, nat.prime.ne_zero _],\nend\n", "meta": {"author": "RaitoBezarius", "repo": "berkovich-spaces", "sha": "0a49f75a599bcb20333ec86b301f84411f04f7cf", "save_path": "github-repos/lean/RaitoBezarius-berkovich-spaces", "path": "github-repos/lean/RaitoBezarius-berkovich-spaces/berkovich-spaces-0a49f75a599bcb20333ec86b301f84411f04f7cf/src/for_mathlib/padic_norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.7142698466502428}}
{"text": "\nset_option profiler true\n\nopen polynomial\n\nexample (R : Type) [comm_ring R] (x : R) :\n  (1 + x^2 + x^4 + x^6) * (1 + x) = 1+x+x^2+x^3+x^4+x^5+x^6+x^7 :=\nby ring -- 5 seconds\n\nexample (R : Type) [comm_ring R] :\n  (1 + X^2 + X^4 + X^6 : polynomial R) * (1 + X) = 1+X+X^2+X^3+X^4+X^5+X^6+X^7 :=\nby ring -- 18 seconds", "meta": {"author": "Or7ando", "repo": "lean", "sha": "d41169cf4e416a0d42092fb6bdc14131cee9dd15", "save_path": "github-repos/lean/Or7ando-lean", "path": "github-repos/lean/Or7ando-lean/lean-d41169cf4e416a0d42092fb6bdc14131cee9dd15/.github/workflows/project_1_a_decrire/foncteur/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248123094438, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.7142698414583522}}
{"text": "/-\nCopyright (c) 2023 Huub Vromen. All rights reserved.\nAuthor: Huub Vromen\n-/\n\nimport order.bounded_lattice\n\n/-- Preorder semantics for Aristotle's assertoric syllogisms. \nThe set-theoretic semantics and first-order logic semantics are orthodox \nsemantics, based on sets of individuals. Now we present a heterodox semantics.\nTerms are regarded to be primitives. They form a meet semi-lattice with bot.\nSee, for instance, Andrade-Lotero (2012, pp. 402-403). \n-/\n\nvariable {\u03b1 : Type} \nvariables [semilattice_inf_bot \u03b1] {A B C : \u03b1}\n-- *** how can I stipulate that these variables are not the bottom element of \u03b1?\n\n/-- semantics of the `a` relation -/\ndef universal_affirmative (A : \u03b1) (B: \u03b1) : Prop :=   A \u2293 B = B\ninfixr ` a ` : 80 := universal_affirmative\n\n/-- semantics of the `e` relation -/\ndef universal_negative (A : \u03b1) (B: \u03b1) : Prop :=   A \u2293 B = \u22a5 \ninfixr ` e ` : 80 := universal_negative\n\n/-- semantics of the `i` relation -/\ndef particular_affirmative (A: \u03b1) (B: \u03b1) : Prop :=   A \u2293 B \u2260 \u22a5 \ninfixr ` i ` : 80 := particular_affirmative\n\n/-- semantics of the `o` relation -/\ndef particular_negative (A: \u03b1) (B: \u03b1) : Prop :=   A \u2293 B \u2260 B\ninfixr ` o ` : 80 := particular_negative\n\n/-- semantics of contradictory: contradictory is defined as negation -/\ndef c (p : Prop) : Prop := \u00ac p\n\n\n/--   We prove the soundness of the axiom system DR -/\n\nlemma Barbara\u2081 : A a B \u2192 B a C \u2192 A a C :=\nbegin\nintros hab hbc,\nrw universal_affirmative at *,\nfinish\nend\n\nlemma Celarent\u2081 : A e B \u2192 B a C \u2192 A e C :=\nbegin\nintros h1 h2,\nsimp [universal_affirmative, universal_negative] at *,\nhave h3 : A \u2293 C \u2264 A \u2293 B, by apply inf_le_inf_left; assumption,\n--have h4 : A \u2293 C \u2264 \u22a5, by finish,\nfinish,\nend\n\nlemma e_conv : A e B \u2192 B e A :=\nbegin\nintro h1,\nrw universal_negative at *,\nrw inf_comm at h1,\nassumption\nend\n\nlemma a_conv : B \u2260 \u22a5 \u2192  A a B \u2192 B i A :=\nbegin\nintros h1 h2 h3,\nrw universal_affirmative at h2,\nrw inf_comm at h3,\nhave h4 : B = \u22a5, from eq.trans (eq.symm h2) h3,\nshow false, from h1 h4\nend \n\nlemma contr {p r : Prop} : (c r \u2192 c p) \u2192 p \u2192 r :=\nbegin\nintros h1,\ncontrapose!,\nassumption\nend\n\n/-- we can also prove the contradictories axioms  -/\n\nlemma contr_a : c (A a B) = A o B := by simp [c, particular_negative, universal_affirmative]\n\nlemma contr_e : c (A e B) = A i B := by simp [c, particular_affirmative, universal_negative]\n\nlemma contr_i : c (A i B) = A e B := by simp [c, particular_affirmative, universal_negative]\n\nlemma contr_o : c (A o B) = A a B := by simp [c, particular_negative, universal_affirmative]\n\n\n/--  it is, of course, also possible to prove the redundant axioms  -/\n\nlemma Darii\u2081 : A a B \u2192 B i C \u2192 A i C :=\nbegin\nintros h1 h2,\nsimp [particular_affirmative, universal_affirmative] at *, \nby_contra h3,\nhave h4 : B \u2293 C \u2264 A \u2293 C, by apply inf_le_inf_right; assumption,\nhave h5 : B \u2293 C = \u22a5, by exact eq_bot_mono h4 h3,\nshow false, from h2 h5\nend\n\n\nlemma Ferio\u2081 : A e B \u2192 B i C \u2192 A o C :=\nbegin\n  intros h1 h2,\n  simp [particular_affirmative, universal_negative] at h1 h2,\n  rw [particular_negative, ne],\n  by_contra h3,\n  rw inf_comm at h1,\n  have h4 : B \u2293 C = \u22a5, by calc B \u2293 C\n      = B \u2293 (A \u2293 C) : by rw h3\n  ... = (B \u2293 A) \u2293 C : by rw inf_assoc \n  ... = \u22a5 \u2293 C : by rw h1\n  ... = \u22a5 : by exact bot_inf_eq,\nshow false, from h2 h4\nend\n\nlemma i_conv : A i B \u2192 B i A :=\nbegin\nintros h1,\nsimp [particular_affirmative] at *,\nrw [inf_comm],\nassumption\nend\n\n#lint\n", "meta": {"author": "hjvromen", "repo": "aristotle", "sha": "fdc6c68ce2edcf6faaa638457cb593e922bfa521", "save_path": "github-repos/lean/hjvromen-aristotle", "path": "github-repos/lean/hjvromen-aristotle/aristotle-fdc6c68ce2edcf6faaa638457cb593e922bfa521/src/aristotle_preorder_semantics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.714269837758204}}
{"text": "import Mathlib.Data.Real.Basic\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.LibrarySearch\n\n\ntheorem dva_krat (n : Nat) : 2 * n = n + n := two_mul n\n\ntheorem tri_krat (n : Nat) : 3 * n = n + n + n := by\n  convert_to 3 * n = 2 * n + n\n  exact symm (dva_krat n)\n  exact Nat.succ_mul 2 n\n\ntheorem tri_krat' (n : Nat) : 3 * n = n + n + n := by ring\n\ntheorem soucet_na_druhou (x y : \u2124) : (x + y) ^ 2 = x^2 + 2*x*y + y^2 := by ring\n\ntheorem rozdil_na_treti (x y : \u211a) : (x - y) ^ 3 = x^3 - 3*x^2*y + 3*x*y^2 - y^3 := by ring\n\ntheorem rozdil_patych_mocnin (x y : \u211d) : x^5 - y^5 = (x - y) * (x^4 + x^3*y + x^2*y^2 + x*y^3 + y^4) := by ring\n\nexample (x y : \u211d) : (x + y) ^ 2 - (x - y) ^ 2 = 4 * x * y := by ring\n\nexample (n : Nat) : 2 ^ (n+3) = 8 * 2^n := by ring\n\nexample (n : Nat) (n_je_pet : n = 5) : n - 1 = 4 := by\n  rw [n_je_pet]\n\nexample (n : Nat) (n_je_pet : 5 = n) : n - 1 = 4 := by\n  rw [symm n_je_pet]\n\nexample (n : Nat) (n_je_pet : 5 = n) : n - 1 = 4 := by\n  rw [\u2190n_je_pet]\n\nexample (a b c : \u211d) (a_je_dva : a = 2) (b_je_tri : b = 3) (c_je_pet : c = 5) : a + b = c := by\n  rw [a_je_dva, b_je_tri, c_je_pet]\n  ring\n\nexample (x : \u211d) (xnn : x \u2260 0) : x^2 / x = x := by\n  field_simp\n  ring\n\ntheorem plus_prevracena (x : \u211d) (xnn : x \u2260 0) : x + 1/x = (x^2 + 1) / x := by\n  field_simp\n  ring\n\nexample (x y z : \u211d) (xnn : x \u2260 0) : x*y*z + 3*y*z*x - 2*z*x*y = y*x*z + x^2*z*y/x := by\n  field_simp\n  ring\n\n\nexample (x y z : \u211d) (xy : x \u2264 y) (yz : y \u2264 z) : x \u2264 z := Trans.simple xy yz\n\nexample (x y z : \u211d) (xy : x < y) (yz : y < z) : x < z := Trans.simple xy yz\n\nexample (x y z : \u211d) (xy : x < y) (yz : y \u2264 z) : x < z := instTransLtToLTLeToLE.proof_1 xy yz\n\nexample (x y z : \u211d) (xy : x \u2264 y) (yz : y < z) : x < z := xy.trans_lt yz\n\nexample (a b c d : \u211d) (abcd : a + b + c \u2264 2 * d) (ab : a \u2264 b) (ac : 2 * a \u2264 c) : 2 * a \u2264 d := by linarith\n\nexample (x y : \u211d) (xy : x \u2264 y) : x \u2264 y + y*y := by nlinarith\n\nexample (x y : \u211d) (x_zaporne : x < 0) (y_zaporne : y < 0) : x * 7 * y > 0 := by nlinarith\n\nexample (x y : \u211d) : x*x - 2*x*y + y*y \u2265 0 := by\n  convert_to (x - y) ^ 2 \u2265 0\n  ring\n  nlinarith\n\nexample (x : \u211d) : 16*x^4 - 96*x^3 + 216*x^2 - 216*x + 81 \u2265 0 := by\n  convert_to ((2*x - 3) ^ 2) ^ 2 \u2265 0\n  ring\n  nlinarith\n\nexample (x : \u211d) : 16*x^4 - 96*x^3 + 216*x^2 - 216*x + 100 \u2265 0 := by\n  have pomocne : 16*x^4 - 96*x^3 + 216*x^2 - 216*x + 81 \u2265 0\n  \u00b7 convert_to ((2*x - 3) ^ 2) ^ 2 \u2265 0\n    \u00b7 ring\n    nlinarith\n  linarith\n\nexample (x : \u211d) : 16*x^4 - 96*x^3 + 216*x^2 - 216*x + 100 \u2265 0 := by\n  have pomocne : 16*x^4 - 96*x^3 + 216*x^2 - 216*x + 81 \u2265 0\n  convert_to ((2*x - 3) ^ 2) ^ 2 \u2265 0\n  ring\n  nlinarith\n  linarith\n\n\nexample (x : \u211d) (xpos : x > 0) : x + 1/x \u2265 2 := by\n  have : (x - 1) ^ 2 \u2265 0\n  \u00b7 exact pow_two_nonneg (x - 1)\n  have : x^2 + 1 - 2*x \u2265 0\n  \u00b7 convert this\n    ring\n  have : x^2 + 1 \u2265 2*x\n  \u00b7 exact le_of_sub_nonneg this\n  have : (x^2 + 1) / x \u2265 (2*x) / x\n  \u00b7 have left_numerator_nneg : x^2 + 1 \u2265 0\n    \u00b7 nlinarith\n    have wtf : x \u2264 x\n    \u00b7 rfl\n    exact div_le_div left_numerator_nneg this xpos wtf\n  convert this\n  \u00b7 ring_nf\n    congr\n    convert_to x = x * x * x\u207b\u00b9\n    ring\n    simp\n  \u00b7 have : (2 : \u211d) = 2 * 1\n    \u00b7 ring\n    have : 2 = 2 * (x / x)\n    \u00b7 convert this\n      have : x \u2260 0\n      \u00b7 exact LT.lt.ne' xpos\n      exact div_self this\n    convert this\n    field_simp\n\nexample (x : \u211d) (predpoklad : x \u2260 -1) : (x^2 + x) / (2*x + 2) = x / 2 := by\n  convert_to (x * (x + 1)) / ((x + 1) * 2) = x / 2\n  \u00b7 ring\n  \u00b7 ring\n  convert_to x * ((x + 1) / ((x + 1) * 2)) = x / 2\n  \u00b7 field_simp\n  have pokraceni : (x + 1) / ((x + 1) * 2) = 1 / 2\n  \u00b7 rw [\u2190div_div, div_self]\n    intro prospor\n    apply predpoklad\n    exact eq_neg_of_add_eq_zero_left prospor\n  rw [pokraceni]\n  rw [mul_div, mul_one]\n\nexample (x y : \u211d) (predpoklad : 3*x + y \u2260 0) : (3*x + y) ^ 5 / (3*x + y) ^ 4 = 3*x + y := by\n  rw [pow_succ, \u2190mul_div, div_self, mul_one]\n  exact pow_ne_zero 4 predpoklad\n", "meta": {"author": "madvorak", "repo": "lean-mam", "sha": "b4e7753e18ee214112900ccda3b32e3d4de48bfb", "save_path": "github-repos/lean/madvorak-lean-mam", "path": "github-repos/lean/madvorak-lean-mam/lean-mam-b4e7753e18ee214112900ccda3b32e3d4de48bfb/mam/Cislo3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7142585392560905}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport data.equiv.basic\nimport tactic.norm_fin\n\n/-!\n# `norm_swap`\n\nEvaluating `swap x y z` for numerals `x y z` that are `\u2115`, `\u2124`, or `\u211a`, via a `norm_num` plugin.\nTerms are passed to `eval`, quickly failing if not of the form `swap x y z`.\nThe expressions for numerals `x y z` are converted to `nat`, and then compared.\nBased on equality of these `nat`s, equality proofs are generated using either\n`equiv.swap_apply_left`, `equiv.swap_apply_right`, or `swap_apply_of_ne_of_ne`.\n-/\n\nopen equiv tactic expr\n\nopen norm_num\n\nnamespace norm_swap\n\n/--\nA `norm_num` plugin for normalizing `equiv.swap a b c`\nwhere `a b c` are numerals of `\u2115`, `\u2124`, `\u211a` or `fin n`.\n\n```\nexample : equiv.swap 1 2 1 = 2 := by norm_num\n```\n-/\n@[norm_num] meta def eval : expr \u2192 tactic (expr \u00d7 expr) := \u03bb e, do\n  (swapt, fun_ty, coe_fn_inst, fexpr, c) \u2190 e.match_app_coe_fn\n    <|> fail \"did not get an app coe_fn expr\",\n  guard (fexpr.get_app_fn.const_name = ``equiv.swap) <|> fail \"coe_fn not of equiv.swap\",\n  [\u03b1, deceq_inst, a, b] \u2190 pure fexpr.get_app_args <|>\n    fail \"swap did not have exactly two args applied\",\n  na \u2190 a.to_rat <|> (do (fa, _) \u2190 norm_fin.eval_fin_num a, fa.to_rat),\n  nb \u2190 b.to_rat <|> (do (fb, _) \u2190 norm_fin.eval_fin_num b, fb.to_rat),\n  nc \u2190 c.to_rat <|> (do (fc, _) \u2190 norm_fin.eval_fin_num c, fc.to_rat),\n  if nc = na then do\n    p \u2190 mk_mapp `equiv.swap_apply_left [\u03b1, deceq_inst, a, b],\n    pure (b, p)\n  else if nc = nb then do\n    p \u2190 mk_mapp `equiv.swap_apply_right [\u03b1, deceq_inst, a, b],\n    pure (a, p)\n  else do\n    nic \u2190 mk_instance_cache \u03b1,\n    hca \u2190 (prod.snd <$> prove_ne nic c a nc na) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c a, pure p),\n    hcb \u2190 (prod.snd <$> prove_ne nic c b nc nb) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c b, pure p),\n    p \u2190 mk_mapp `equiv.swap_apply_of_ne_of_ne [\u03b1, deceq_inst, a, b, c, hca, hcb],\n    pure (c, p)\n\nend norm_swap\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/tactic/norm_swap.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7142585392560904}}
{"text": "/-\nCopyright (c) 2021 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\nimport data.finset.sort\nimport data.list.fin_range\nimport data.prod.lex\nimport group_theory.perm.basic\n\n/-!\n\n# Sorting tuples by their values\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGiven an `n`-tuple `f : fin n \u2192 \u03b1` where `\u03b1` is ordered,\nwe may want to turn it into a sorted `n`-tuple.\nThis file provides an API for doing so, with the sorted `n`-tuple given by\n`f \u2218 tuple.sort f`.\n\n## Main declarations\n\n* `tuple.sort`: given `f : fin n \u2192 \u03b1`, produces a permutation on `fin n`\n* `tuple.monotone_sort`: `f \u2218 tuple.sort f` is `monotone`\n\n-/\n\nnamespace tuple\n\nvariables {n : \u2115}\nvariables {\u03b1 : Type*} [linear_order \u03b1]\n\n/--\n`graph f` produces the finset of pairs `(f i, i)`\nequipped with the lexicographic order.\n-/\ndef graph (f : fin n \u2192 \u03b1) : finset (\u03b1 \u00d7\u2097 (fin n)) :=\nfinset.univ.image (\u03bb i, (f i, i))\n\n/--\nGiven `p : \u03b1 \u00d7\u2097 (fin n) := (f i, i)` with `p \u2208 graph f`,\n`graph.proj p` is defined to be `f i`.\n-/\ndef graph.proj {f : fin n \u2192 \u03b1} : graph f \u2192 \u03b1 := \u03bb p, p.1.1\n\n@[simp] lemma graph.card (f : fin n \u2192 \u03b1) : (graph f).card = n :=\nbegin\n  rw [graph, finset.card_image_of_injective],\n  { exact finset.card_fin _ },\n  { intros _ _,\n    simp }\nend\n\n/--\n`graph_equiv\u2081 f` is the natural equivalence between `fin n` and `graph f`,\nmapping `i` to `(f i, i)`. -/\ndef graph_equiv\u2081 (f : fin n \u2192 \u03b1) : fin n \u2243 graph f :=\n{ to_fun := \u03bb i, \u27e8(f i, i), by simp [graph]\u27e9,\n  inv_fun := \u03bb p, p.1.2,\n  left_inv := \u03bb i, by simp,\n  right_inv := \u03bb \u27e8\u27e8x, i\u27e9, h\u27e9, by simpa [graph] using h }\n\n@[simp] lemma proj_equiv\u2081' (f : fin n \u2192 \u03b1) : graph.proj \u2218 graph_equiv\u2081 f = f :=\nrfl\n\n/--\n`graph_equiv\u2082 f` is an equivalence between `fin n` and `graph f` that respects the order.\n-/\ndef graph_equiv\u2082 (f : fin n \u2192 \u03b1) : fin n \u2243o graph f :=\nfinset.order_iso_of_fin _ (by simp)\n\n/-- `sort f` is the permutation that orders `fin n` according to the order of the outputs of `f`. -/\ndef sort (f : fin n \u2192 \u03b1) : equiv.perm (fin n) :=\n(graph_equiv\u2082 f).to_equiv.trans (graph_equiv\u2081 f).symm\n\nlemma graph_equiv\u2082_apply (f : fin n \u2192 \u03b1) (i : fin n) :\n  graph_equiv\u2082 f i = graph_equiv\u2081 f (sort f i) :=\n((graph_equiv\u2081 f).apply_symm_apply _).symm\n\nlemma self_comp_sort (f : fin n \u2192 \u03b1) : f \u2218 sort f = graph.proj \u2218 graph_equiv\u2082 f :=\nshow graph.proj \u2218 ((graph_equiv\u2081 f) \u2218 (graph_equiv\u2081 f).symm) \u2218 (graph_equiv\u2082 f).to_equiv = _,\n  by simp\n\nlemma monotone_proj (f : fin n \u2192 \u03b1) : monotone (graph.proj : graph f \u2192 \u03b1) :=\nbegin\n  rintro \u27e8\u27e8x, i\u27e9, hx\u27e9 \u27e8\u27e8y, j\u27e9, hy\u27e9 (_|h),\n  { exact le_of_lt \u2039_\u203a },\n  { simp [graph.proj] },\nend\n\nlemma monotone_sort (f : fin n \u2192 \u03b1) : monotone (f \u2218 sort f) :=\nbegin\n  rw [self_comp_sort],\n  exact (monotone_proj f).comp (graph_equiv\u2082 f).monotone,\nend\n\nend tuple\n\nnamespace tuple\n\nopen list\n\nvariables {n : \u2115} {\u03b1 : Type*}\n\n/-- If two permutations of a tuple `f` are both monotone, then they are equal. -/\nlemma unique_monotone [partial_order \u03b1] {f : fin n \u2192 \u03b1} {\u03c3 \u03c4 : equiv.perm (fin n)}\n  (hf\u03c3 : monotone (f \u2218 \u03c3)) (hf\u03c4 : monotone (f \u2218 \u03c4)) : f \u2218 \u03c3 = f \u2218 \u03c4 :=\nof_fn_injective $ eq_of_perm_of_sorted\n  ((\u03c3.of_fn_comp_perm f).trans (\u03c4.of_fn_comp_perm f).symm) hf\u03c3.of_fn_sorted hf\u03c4.of_fn_sorted\n\nvariables [linear_order \u03b1] {f : fin n \u2192 \u03b1} {\u03c3 : equiv.perm (fin n)}\n\n/-- A permutation `\u03c3` equals `sort f` if and only if the map `i \u21a6 (f (\u03c3 i), \u03c3 i)` is\nstrictly monotone (w.r.t. the lexicographic ordering on the target). -/\nlemma eq_sort_iff' : \u03c3 = sort f \u2194 strict_mono (\u03c3.trans $ graph_equiv\u2081 f) :=\nbegin\n  split; intro h,\n  { rw [h, sort, equiv.trans_assoc, equiv.symm_trans_self], exact (graph_equiv\u2082 f).strict_mono },\n  { have := subsingleton.elim (graph_equiv\u2082 f) (h.order_iso_of_surjective _ $ equiv.surjective _),\n    ext1, exact (graph_equiv\u2081 f).apply_eq_iff_eq_symm_apply.1 (fun_like.congr_fun this x).symm },\nend\n\n/-- A permutation `\u03c3` equals `sort f` if and only if `f \u2218 \u03c3` is monotone and whenever `i < j`\nand `f (\u03c3 i) = f (\u03c3 j)`, then `\u03c3 i < \u03c3 j`. This means that `sort f` is the lexicographically\nsmallest permutation `\u03c3` such that `f \u2218 \u03c3` is monotone. -/\nlemma eq_sort_iff : \u03c3 = sort f \u2194 monotone (f \u2218 \u03c3) \u2227 \u2200 i j, i < j \u2192 f (\u03c3 i) = f (\u03c3 j) \u2192 \u03c3 i < \u03c3 j :=\nbegin\n  rw eq_sort_iff',\n  refine \u27e8\u03bb h, \u27e8(monotone_proj f).comp h.monotone, \u03bb i j hij hfij, _\u27e9, \u03bb h i j hij, _\u27e9,\n  { exact (((prod.lex.lt_iff _ _).1 $ h hij).resolve_left hfij.not_lt).2 },\n  { obtain he|hl := (h.1 hij.le).eq_or_lt; apply (prod.lex.lt_iff _ _).2,\n    exacts [or.inr \u27e8he, h.2 i j hij he\u27e9, or.inl hl] },\nend\n\n/-- The permutation that sorts `f` is the identity if and only if `f` is monotone. -/\nlemma sort_eq_refl_iff_monotone : sort f = equiv.refl _ \u2194 monotone f :=\nbegin\n  rw [eq_comm, eq_sort_iff, equiv.coe_refl, function.comp.right_id],\n  simp only [id.def, and_iff_left_iff_imp],\n  exact \u03bb _ _ _ hij _, hij,\nend\n\n/-- A permutation of a tuple `f` is `f` sorted if and only if it is monotone. -/\nlemma comp_sort_eq_comp_iff_monotone : f \u2218 \u03c3 = f \u2218 sort f \u2194 monotone (f \u2218 \u03c3) :=\n\u27e8\u03bb h, h.symm \u25b8 monotone_sort f, \u03bb h, unique_monotone h (monotone_sort f)\u27e9\n\n/-- The sorted versions of a tuple `f` and of any permutation of `f` agree. -/\nlemma comp_perm_comp_sort_eq_comp_sort : (f \u2218 \u03c3) \u2218 (sort (f \u2218 \u03c3)) = f \u2218 sort f :=\nbegin\n  rw [function.comp.assoc, \u2190 equiv.perm.coe_mul],\n  exact unique_monotone (monotone_sort (f \u2218 \u03c3)) (monotone_sort f),\nend\n\n/-- If a permutation `f \u2218 \u03c3` of the tuple `f` is not the same as `f \u2218 sort f`, then `f \u2218 \u03c3`\nhas a pair of strictly decreasing entries. -/\nlemma antitone_pair_of_not_sorted' (h : f \u2218 \u03c3 \u2260 f \u2218 sort f) :\n  \u2203 i j, i < j \u2227 (f \u2218 \u03c3) j < (f \u2218 \u03c3) i :=\nby { contrapose! h, exact comp_sort_eq_comp_iff_monotone.mpr (monotone_iff_forall_lt.mpr h) }\n\n/-- If the tuple `f` is not the same as `f \u2218 sort f`, then `f` has a pair of strictly decreasing\nentries. -/\nlemma antitone_pair_of_not_sorted (h : f \u2260 f \u2218 sort f) : \u2203 i j, i < j \u2227 f j < f i :=\nantitone_pair_of_not_sorted' (id h : f \u2218 equiv.refl _ \u2260 _)\n\nend tuple\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/fin/tuple/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7142585305566171}}
{"text": "import data.real.basic\nimport data.nat.prime\nopen nat\n\ntheorem GcdM : \u2200 a b : nat, b \u2264 a \u2192 \u2203 g : nat, g \u2223 a \u2227 g \u2223 b \u2227 \u2200 h : nat, h \u2223 a \u2227 h \u2223 b \u2192 h \u2223 g :=\nbegin\n  intro a,\n\n  -- As we will prove this by Strong Induction, we state the strong induction hypotheses\n  have StrongInductionHyp : \u2200 n : nat, (\u2200 a < n, \u2200 b : nat, (b \u2264 a \u2192 \u2203 g : nat, g \u2223 a \u2227 g \u2223 b \u2227 \u2200 h : nat, h \u2223 a \u2227 h \u2223 b \u2192 h \u2223 g)) \u2192 \n                  (\u2200 b : nat, b \u2264 n  \u2192 \u2203 g : nat, g \u2223 n \u2227 g \u2223 b \u2227 \u2200 h : nat, h \u2223 n \u2227 h \u2223 b \u2192 h \u2223 g) :=\n  begin\n    -- Proof of the strong induction hypothesis\n\n    intro n,\n    intro HypRec,\n    intro b,\n    intro bn,\n\n    --We have to check the cases b = 0 separately, because n - b wouldn't be less than n in this case\n    cases b with b,\n    \n    -- b = 0 case : just use n as g\n    use n,\n    split,\n    use 1,\n    simp,\n    split,\n    use 0,\n    simp,\n    intro h,\n    intro hh,\n    cases hh,\n    exact hh_left,\n\n    -- b > 0 case\n    -- We define c = n - b.succ\n    have ExistC := le.dest bn,\n    cases ExistC with c K,\n\n    -- Separation of b.succ <= c and c <= b.succ\n    have BC := le_total b.succ c,\n    cases BC,\n\n    --Verifiying that c < n so that we can use HypRec\n    have c_lt_n : c < n :=\n    begin\n      rw add_comm at K,\n      rw \u2190 add_one at K,\n      rw add_comm b 1 at K,\n      rw \u2190 add_assoc at K,\n      have w := Exists.intro b K,\n      have z := le.intro K,\n      exact z,\n    end,\n\n    -- HypRec gives us a g which is gcd(b.succ, c)\n    have G := HypRec c c_lt_n b.succ BC,\n    cases G with g G, -- extraction of g from its existence\n    use g,\n    \n    -- Separation of the 3 conditions of gcd\n    cases G with Gc temp,\n    cases temp with Gbs Gmaxi,\n    \n    split,\n    \n    -- Verification that g \u2223 n, using b.succ + c = n, knowing that g \u2223 b.succ and g \u2223 c\n    cases Gc with r,\n    rw Gc_h at K,\n    cases Gbs with s,\n    rw Gbs_h at K,\n    rw \u2190 mul_add at K,\n    use (s + r),\n    rw eq_comm at K,\n    exact K,\n    \n    split,\n    \n    -- Verification that g \u2223 b.succ, trivial\n    exact Gbs,\n    \n    --Verification that g is the max possible.\n    intro h,\n    intro hdiv,\n    cases hdiv with hdivn hdivmsucc,\n    cases hdivn with k,\n    rw hdivn_h at K,\n    cases hdivmsucc with l,\n    rw hdivmsucc_h at K,\n  \n    -- As we cannot use minus as we work in nat, we have to prove that l \u2264 k. So we begin by proving h * l \u2264 h * k\n    --have hl_le_hk := (le_exist (h * l) (h * k)).2 (Exists.intro c K),\n    have hl_le_hk := le.intro K,\n    \n    -- We will use that we can simplify h * l \u2264 h * k if h \u2260 0 \n    cases h,\n    -- For h = 0\n    exfalso,\n    rw zero_mul at hdivmsucc_h,\n    have q := succ_ne_zero b,\n    exact q hdivmsucc_h,\n    -- For h > 0\n    have temp := (mul_le_mul_left (ne_zero.pos (succ h))).1 hl_le_hk,\n    have l_le_k := le.dest temp,\n    -- Extraction of o = k - l \n    cases l_le_k with o,\n    rw eq_comm at l_le_k_h,\n    rw l_le_k_h at K,\n    rw mul_add at K,\n    have q := add_left_cancel K,\n    have hsdc : h.succ \u2223 c := Exists.intro o q,\n    have hsdms := Exists.intro l hdivmsucc_h,\n    -- Use of recurrence property\n    exact Gmaxi h.succ (and.intro hsdc hsdms),\n    \n    -- Second case : c <= b.succ. It's essentially the same as the first case, so I do not comment it.\n    cases c with C,\n    use n,\n    split,\n    use 1,\n    simp,\n    \n    split,\n    \n    rw add_zero at K,\n    rw K,\n    rw add_zero at K,\n    intro h,\n    intro hn,\n    cases hn,\n    exact hn_left,\n    rw add_succ at K,\n    rw add_comm at K,\n    rw \u2190 add_succ at K,\n    rw add_comm at K,\n    have msltn := le.intro K,\n    have maxi := HypRec b.succ msltn C.succ BC,\n    cases maxi with g,\n    use g,\n    cases maxi_h,\n    split,\n    cases maxi_h_right with ab ac,\n    rw succ_add at K,\n    rw \u2190 add_succ at K,\n    cases ab with k,\n    cases maxi_h_left with l,\n    rw ab_h at K,\n    rw maxi_h_left_h at K,\n    rw \u2190 mul_add at K,\n    use (l + k),\n    rw eq_comm at K,\n    assumption,\n    split,\n    assumption,\n    \n    intro h,\n    intro hnhms,\n    cases hnhms,\n    cases maxi_h_right with gcs mini,\n    rw succ_add at K,\n    rw \u2190 add_succ at K,\n    cases hnhms_left with r R,\n    have hdms := hnhms_right,\n    cases hnhms_right with u mshu,\n    rw mshu at K,\n    rw R at K,\n    cases h with hp,\n    exfalso,\n    rw zero_mul at R,\n    rw R at msltn,\n    have k := zero_lt_succ b.succ,\n    exact le_lt_antisymm msltn k,\n\n    have temp := le.intro K,\n    have ztz := (mul_le_mul_left (ne_zero.pos (succ hp))).1 temp,\n    have urt := le.dest ztz,\n    cases urt with U,\n    rw eq_comm at urt_h,\n    rw urt_h at K,\n    rw mul_add at K,\n    have qw := add_left_cancel K,\n    have hpc : hp.succ \u2223 C.succ := Exists.intro U qw,\n    exact mini hp.succ (and.intro hdms hpc),\n  end,\n\n  -- We apply strong induction\n  exact nat.strong_induction_on a StrongInductionHyp,\nend\n", "meta": {"author": "HurlSly", "repo": "MyFirstProofInLean", "sha": "80f9b288cf1f14add4b7a3be5c1956d6c751e0f8", "save_path": "github-repos/lean/HurlSly-MyFirstProofInLean", "path": "github-repos/lean/HurlSly-MyFirstProofInLean/MyFirstProofInLean-80f9b288cf1f14add4b7a3be5c1956d6c751e0f8/Test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952838963489, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7142585305452277}}
{"text": "import data.real.basic\n\n-- BEGIN\ntheorem aux {x y : \u211d} (h : x^2 + y^2 = 0) : x = 0 :=\nbegin\n  have h' : x^2 = 0 := ((add_eq_zero_iff' (sq_nonneg x) (sq_nonneg y)).mp h).1,\n  exact pow_eq_zero h',\nend\n\nexample (x y : \u211d) : x^2 + y^2 = 0 \u2194 x = 0 \u2227 y = 0 :=\nbegin \n  split;\n  intro h,\n  { split,\n    exact aux h,\n    exact aux (by linarith : y^2 + x^2 = 0), },\n  { cases h with hr1 hr2,\n    rw hr1,\n    rw hr2,\n    norm_num, }\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/5_split/5.3_iff & conjunc/ex3_split_pow_two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7142155434288563}}
{"text": "\nimport subsequence -- Imports sequences and their properties, as well as\n                   -- tools for constructing and manipulating subsequences.\n\nnamespace my_analysis\n\n  /-- Proposition that a sequence is Cauchy, that is that its terms grow arbitrarily close together. -/\n  def seq.cauchy (s : seq) : Prop := \u2200 \u2983\u03b5\u2984, \u03b5 > 0 \u2192 \u2203 B : \u2115, \u2200 \u2983m n\u2984, B \u2264 m \u2192 B \u2264 n \u2192 |s m - s n| < \u03b5\n\n  /-- Proof that Cauchy sequences are bounded. -/\n  theorem cauchy_is_bounded {s : seq} (hc : s.cauchy): s.bounded :=\n  begin\n    cases hc zero_lt_one with B h,\n    have hb : \u2200 \u2983n\u2984, B \u2264 n \u2192 |s n| < 1 + |s B|,\n      intros n hn,\n      have h\u2081 : |s n| \u2264 |s n - s B| + |s B|,\n        conv_lhs { rw [\u2190 sub_add_cancel (s n) (s B)] },\n        exact abs_add (s n - s B) (s B),\n      have h\u2082 : |s n - s B| < 1, from h hn (le_refl B),\n      exact lt_of_le_of_lt h\u2081 (add_lt_add_of_lt_of_le h\u2082 (le_refl _)),\n    apply (bounded_shift s B).mpr,\n    use 1 + |s B|, intros,\n    exact le_of_lt (hb le_add_self)\n  end\n\n  /-- Proof that Cauchy and convergent are equivalent properties. -/\n  theorem convergent_iff_cauchy {s : seq} : s.convergent \u2194 s.cauchy :=\n  begin\n    split,\n    { -- convergent \u2192 cauchy\n      rintros \u27e8x, hx\u27e9 \u03b5 h\u03b5,\n      cases hx (half_pos h\u03b5) with B h,\n      use B, intros m n hm hn,\n      rw [\u2190 add_halves \u03b5],\n      refine lt_of_le_of_lt _ (add_lt_add (h hm) (h hn)),\n      have : |s m - s n| = |(s m - x) + (x - s n)|, ring_nf,\n      rw [this, \u2190 abs_neg (s n - x), neg_sub],\n      exact abs_add (s m - x) (x - s n) },\n    { -- cauchy \u2192 convergent\n      intro hc,\n      -- We get the limit from the convergent subsequence `bolzano_weierstrass` gives us.\n      cases bolzano_weierstrass (cauchy_is_bounded hc) with si hcon,\n      cases hcon with x hx, use x, intros \u03b5 h\u03b5,\n      cases hx (half_pos h\u03b5) with B hB,\n      cases hc (half_pos h\u03b5) with C hC,\n      let k := max B C,\n      have hk : C \u2264 si k,\n        apply (si.unbounded C).trans,\n        by_cases h : C = k,\n        { rw [h] },\n        { exact le_of_lt (si.mono (lt_of_le_of_ne (le_max_right B C) h)) },\n      use C, intros n hn,\n      rw [\u2190 add_halves \u03b5],\n      refine lt_of_le_of_lt _ (add_lt_add (hC hn hk) (hB (le_max_left B C))),\n      have : |s n - x| = |(s n - s.subseq si k) + (s.subseq si k - x)|, ring_nf,\n      rw [this], exact abs_add _ _ }\n  end\n\nend my_analysis\n", "meta": {"author": "Hop311", "repo": "project1", "sha": "92bbb9fc1506b0e7d090f209674e2d4dae6e5c63", "save_path": "github-repos/lean/Hop311-project1", "path": "github-repos/lean/Hop311-project1/project1-92bbb9fc1506b0e7d090f209674e2d4dae6e5c63/src/cauchy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7142155410576619}}
{"text": "-- Definiciones de l\u00edmite\n-- ======================\n\nimport topology.instances.real\n\nnotation `|` x `|` := abs x\n\ndefinition is_limit (a : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < \u03b5\n\nopen filter\n\nopen_locale topological_space\n\nlemma is_limit_iff_tendsto\n  (a : \u2115 \u2192 \u211d)\n  (l : \u211d)\n  : is_limit a l \u2194 tendsto a at_top (\ud835\udcdd l) :=\nbegin\n  split,\n  { intros h X hX,\n    rw mem_nhds_iff_exists_Ioo_subset at hX,\n    rcases hX with \u27e8x, y, \u27e8hxl, hly\u27e9, h2\u27e9,\n    set \u03b5 := min (l - x) (y - l) with h\u03b5,\n    have h\u03b5_pos : 0 < \u03b5 := lt_min (by linarith) (by linarith),\n    obtain \u27e8N, hN\u27e9 := h \u03b5 h\u03b5_pos,\n    rw [mem_map, mem_at_top_sets],\n    use N,\n    intros n hn,\n    specialize hN n hn,\n    apply h2,\n    rw abs_lt at hN,\n    cases hN,\n    have h\u03b51 : \u03b5 \u2264 l - x := min_le_left _ _,\n    have h\u03b52 : \u03b5 \u2264 y - l := min_le_right _ _,\n    split;\n    linarith },\n  { intros h \u03b5 h\u03b5,\n    rw tendsto_nhds at h,\n    specialize h (set.Ioo (l - \u03b5) (l + \u03b5)) (is_open_Ioo) \u27e8by linarith, by linarith\u27e9,\n    rw mem_at_top_sets at h,\n    rcases h with \u27e8N, hN\u27e9,\n    use N,\n    intros n hn,\n    obtain \u27e8h1, h2\u27e9 := hN n hn,\n    rw abs_lt,\n    split; linarith },\nend\n\nexample\n  (a b : \u2115 \u2192 \u211d)\n  (l m : \u211d)\n  : is_limit a l \u2192 is_limit b m \u2192 is_limit (\u03bb n, a n + b n) (l + m) :=\nbegin\n  simp only [is_limit_iff_tendsto],\n  exact tendsto.add,\nend\n\nexample\n  (a b : \u2115 \u2192 \u211d)\n  (l m : \u211d)\n  : is_limit a l \u2192 is_limit b m \u2192 is_limit (\u03bb n, a n * b n) (l * m) :=\nbegin\n  simp only [is_limit_iff_tendsto],\n  exact tendsto.mul,\nend\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Definiciones_de_limite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7142155391097059}}
{"text": "import LeanCodePrompts.ExploreTranslate\nimport Mathlib\n\n/-\ndef eg1 := \"There are infinitely many odd numbers.\"\n\n#eval translate eg1\n\n#eval showLogs 1\n\ndef eg2 := \"Every set of `10` distinct numbers between `1` and `100` contains two disjoint nonempty subsets with the same sum.\"\n\n#eval translate eg2\n\ndef eg3 := \"If a set `S` contains `0` and `1`, and the mean of every finite nonempty subset of `S`, then `S` contains all the rational numbers in the unit interval.\"\n\n#eval translate eg3 \n\n#eval showLogs 1\n\ndef eg4 := \"Every sequence of natural numbers is bounded.\"\n\n#eval translate eg4\n\ndef eg5 := \"Every sequence `x_n` of natural numbers is constant.\"\n\n#eval translate eg5\n\ndef eg6 := \"Every finite sequence `x_1, x_2, ..., x_n` of natural numbers is bounded.\"\n\n#eval translate eg6\n\n#eval showLogs 1\n\ndef eg7 := \"If a set of natural numbers `S` contains `0` and `1`, and the mean of every finite nonempty subset of `S`, then `S` is non-empty.\"\n\n#eval translate eg7\n\n-- #eval showLogs 1\n\n#eval dotName? \"S.nonempty\"\n\ndef eg8 := \"Every complete pseudometric space is a Baire space.\"\n\n#eval translate eg8\n\n-/\n\ndef eg9 := \"If $n$ is a prime number, then $$\\\\Phi_n(x) = 1+x+x^2+\\\\cdots+x^{n-1}=\\\\sum_{k=0}^{n-1}x^k$$, where $\\\\Phi_n$ is the $n$-th cyclotomic polynomial.\"\n\n-- Formula translation incorrectly, must try with partial translation to Lean + Unicode\n#eval translate eg9\n\ndef eg10 := \"The M\u00f6bius inversion formula allows the expression of the $n$-th cyclotomic polynomial $\\\\Phi_n(x)$ as an explicit rational fraction $$\\\\Phi_n(x)=\\\\prod_{d\\\\mid n}(x^d-1)^{\\\\mu \\\\left(\\\\frac{n}{d} \\\\right)$$, where $\\\\mu$ is the M\u00f6bius function.\"\n\n-- not working for some reason\n-- #eval translate eg10\n\ndef eg11 := \"The function `\u03c8 : \u211d \u2192 \u211d` that takes the value $\\\\exp((-1)/(1 - x^2))$ on $(-1, 1)$ and $0$ everywhere else is smooth and compactly supported.\"\n\n#eval translate eg11\n\n-- this example is in `mathlib`\ndef eg12 := \"If `f : \u2102 \u2192 E` is continuous on a closed disc of radius $R$ and is complex differentiable at all but countably many points of its interior, then the integral $\\\\oint_{|z-c|=R} \\\\frac{f(z)}{z-c}\\\\,dz$ is equal to $2\u03c0iy$.\"\n\n#eval translate eg12\n\n-- Initial translation failed to recognise `tangent function` as a synonym/expansion of `tan`. Adding `tan` explicitly seems to have fixed this\ndef eg13 := \"The tangent function `tan` is periodic with period `\u03c0`.\"\n\n#eval translate eg13\n\n#eval showLogs 1\n\n-- this workss\n-- def eg14 := \"The function `exp(-x)` tends to `0` as `x` tends to `\u221e`.\"\n\n-- #eval translate eg14\n\n-- this works\n-- def eg15 := \"Every finite field has non-zero characteristic.\"\n\n-- #eval translate eg15\n\ndef eg16 := \"Functors between categories preserve composition of morphisms.\"\n\n#eval translate eg16\n\ndef eg17 := \"If a function $f:\\\\mathbb{C} \\to \\\\mathbb C}$ is entire and non-constant, then the set of values that $f(z)$ assumes is either the whole complex plane or the plane minus a single point.\"\n\n#eval translate eg17", "meta": {"author": "siddhartha-gadgil", "repo": "LeanAide", "sha": "7862af73ee2f0be08b20fd3e4148e20bf4a81054", "save_path": "github-repos/lean/siddhartha-gadgil-LeanAide", "path": "github-repos/lean/siddhartha-gadgil-LeanAide/LeanAide-7862af73ee2f0be08b20fd3e4148e20bf4a81054/LeanCodePrompts/ExploreTranslateExamples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7142155281002106}}
{"text": "import tactic\nimport data.real.basic\nimport data.pnat.basic\n\nlocal notation `|` x `|` := abs x\n\ndef is_limit (a : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < \u03b5\n\ndef tends_to_plus_infinity (a : \u2115 \u2192 \u211d) : Prop :=\n\u2200 B, \u2203 N, \u2200 n \u2265 N, B < a n \n\ndef is_convergent (a : \u2115 \u2192 \u211d) : Prop :=\n\u2203 l : \u211d, is_limit a l\n\nnamespace sheet_five\n\ntheorem Q1a (x : \u211d) (hx : 0 < x) (n : \u2115) : (1 : \u211d) + n * x \u2264 (1 + x)^n :=\nbegin\n  sorry\nend\n\ntheorem Q1b (x : \u211d) (hx : 0 < x) : is_limit (\u03bb n, (1 + x) ^ (-(n : \u2124))) 0 :=\nbegin\n  intros \u03b5 h\u03b5,\n  obtain \u27e8N, hN\u27e9 := add_one_pow_unbounded_of_pos (1/\u03b5) hx,\n  existsi N,\n  intros n hn,\n  dsimp only,\n  rw sub_zero,\n  have hx2 : 0 < 1 + x,\n    linarith,\n  have hx3 : \u2200 m, (1+x) ^ m > 0,\n    intro m,\n    exact fpow_pos_of_pos hx2 m,\n  rw abs_of_pos (hx3 _),\n  simp,\n  rw \u2190 one_div,\n  rw one_div_lt (pow_pos hx2 n) h\u03b5,\n  refine lt_of_lt_of_le hN _,\n  rw add_comm,\n  apply pow_le_pow,\n    linarith,\n  assumption,\nend\n\ntheorem Q1c (r : \u211d) (hr : r \u2208 set.Ioo (0 : \u211d) 1) : is_limit (\u03bb n, r ^ n) 0 :=\nbegin\n  sorry\nend\n\ntheorem Q1d (r : \u211d) (hr : 1 < r) : tends_to_plus_infinity (\u03bb n, r ^ n) :=\nbegin\n  sorry\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "M40002", "sha": "a499db70323bd5ccae954c680ec9afbf15ffacca", "save_path": "github-repos/lean/ImperialCollegeLondon-M40002", "path": "github-repos/lean/ImperialCollegeLondon-M40002/M40002-a499db70323bd5ccae954c680ec9afbf15ffacca/src/solutions_sheet_five.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7142091249077474}}
{"text": "import data.real.basic\n\n#check \u2200 x y \u03b5 : \u211d, 0 < \u03b5 \u2192 \u03b5 \u2264 1 \u2192 abs x < \u03b5 \u2192 abs y < \u03b5 \u2192 abs (x * y) < \u03b5\n\n\nlemma my_lemma : \u2200 {x y \u03b5 : \u211d},\n  0 < \u03b5 \u2192 \u03b5 \u2264 1 \u2192 abs x < \u03b5 \u2192 abs y < \u03b5 \u2192 abs (x * y) < \u03b5 :=\nbegin\n  intros x y \u03b5 epos ele1 xlt ylt,\n  calc\n    abs (x * y) = abs x * abs y : by rw abs_mul\n    ... \u2264 abs x * \u03b5             : \n      mul_le_mul (le_of_eq (eq.refl (abs x))) (le_of_lt ylt) (abs_nonneg y) (abs_nonneg x)\n    ... < 1 * \u03b5                 : \n      (mul_lt_mul_right epos).mpr (lt_of_lt_of_le xlt ele1)\n    ... = \u03b5                     : one_mul \u03b5\nend\n\n\nsection\nvariables (f g : \u211d \u2192 \u211d) (a b : \u211d)\n\n\ndef fn_ub (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, f x \u2264 a\ndef fn_lb (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, a \u2264 f x\n\nexample (hfa : fn_ub f a) (hgb : fn_ub g b) :\n  fn_ub (\u03bb x, f x + g x) (a + b) :=\nbegin \n  intro x,\n  dsimp,\n  apply add_le_add,\n  apply hfa,\n  apply hgb,\nend\n\n\nexample (hfa : fn_lb f a) (hgb : fn_lb g b) :\n  fn_lb (\u03bb x, f x + g x) (a + b) :=\nbegin \n  intro x,\n  change a + b \u2264 f x + g x,\n  apply add_le_add,\n  apply hfa,\n  apply hgb,\nend\n\nexample (nnf : fn_lb f 0) (nng : fn_lb g 0) :\n  fn_lb (\u03bb x, f x * g x) 0 :=\nbegin \n  intro x,\n  change 0 \u2264 f x * g x,\n  apply mul_nonneg,\n  apply nnf,\n  apply nng,\nend\n\nexample (hfa : fn_ub f a) (hfb : fn_ub g b)\n    (nng : fn_lb g 0) (nna : 0 \u2264 a) :\n  fn_ub (\u03bb x, f x * g x) (a * b) :=\nbegin \n  intro x,\n  change f x * g x \u2264 a * b,\n  apply mul_le_mul,\n  apply hfa,\n  apply hfb,\n  apply nng,\n  exact nna,\nend\n\nend\n\n\nsection\nvariables {\u03b1 : Type*} {R : Type*} [ordered_cancel_add_comm_monoid R]\n\n#check @add_le_add\n\ndef fn_ub' (f : \u03b1 \u2192 R) (a : R) : Prop := \u2200 x, f x \u2264 a\n\ntheorem fn_ub_add {f g : \u03b1 \u2192 R} {a b : R}\n    (hfa : fn_ub' f a) (hgb : fn_ub' g b) :\n  fn_ub' (\u03bb x, f x + g x) (a + b) :=\n\u03bb x, add_le_add (hfa x) (hgb x)\n\nend\n\nsection\nexample (f : \u211d \u2192 \u211d) (h : monotone f) :\n  \u2200 {a b}, a \u2264 b \u2192 f a \u2264 f b := h\n\n\nvariables (f g : \u211d \u2192 \u211d)\n\nexample (mf : monotone f) (mg : monotone g) :\n  monotone (\u03bb x, f x + g x) :=\nbegin\n  intros a b aleb,\n  dsimp,\n  apply add_le_add,\n  apply mf aleb,\n  apply mg aleb,\nend\n\n\nexample {c : \u211d} (mf : monotone f) (nnc : 0 < c) :\n  monotone (\u03bb x, c * f x) :=\nbegin \n  intros a b aleb,\n  dsimp,\n  apply (mul_le_mul_left nnc).mpr,\n  apply mf aleb,\nend \n\nexample (mf : monotone f) (mg : monotone g) :\n  monotone (\u03bb x, f (g x)) :=\n\u03bb a b aleb, mf (mg aleb)\n\n\nend\n\n\n\nsection \nvariables (f g : \u211d \u2192 \u211d)\ndef fn_even (f : \u211d \u2192 \u211d) : Prop := \u2200 x, f x = f (-x)\ndef fn_odd (f : \u211d \u2192 \u211d) : Prop := \u2200 x, f x = - f (-x)\n\nexample (ef : fn_even f) (eg : fn_even g) : fn_even (\u03bb x, f x + g x) :=\nbegin\n  intro x,\n  calc\n    (\u03bb x, f x + g x) x = f x + g x       : rfl\n                    ... = f (-x) + g (-x) : by rw [ef, eg]\nend\n\nexample (of : fn_odd f) (og : fn_odd g) : fn_even (\u03bb x, f x * g x) :=\nbegin \n  intro x,\n  dsimp,\n  rw [of, og],\n  apply neg_mul_neg,\nend\n\nexample (ef : fn_even f) (og : fn_odd g) : fn_odd (\u03bb x, f x * g x) :=\nbegin  \n  intro x,\n  dsimp,\n  rw [ef, og],\n  apply mul_neg,\nend\n\nexample (ef : fn_even f) (og : fn_odd g) : fn_even (\u03bb x, f (g x)) :=\nbegin \n  intro x,\n  dsimp,\n  rw [ef, og],\n  rw neg_neg,\nend\n\n\nend\n\n\n\n/- Sets -/\n\nsection \nvariables {\u03b1 : Type*} (r s t : set \u03b1)\n\nexample : s \u2286 s :=\nby { intros x xs, exact xs }\n\ntheorem subset.refl : s \u2286 s := \u03bb x xs, xs\n\ntheorem subset.trans : r \u2286 s \u2192 s \u2286 t \u2192 r \u2286 t :=\nbegin \n  intros rs st x xin,\n  apply st,\n  apply rs,\n  exact xin,\nend\n\nend\n\n\nsection\nvariables {\u03b1 : Type*} [partial_order \u03b1]\nvariables (s : set \u03b1) (a b : \u03b1)\n\ndef set_ub (s : set \u03b1) (a : \u03b1) := \u2200 x, x \u2208 s \u2192 x \u2264 a\n\nexample (h : set_ub s a) (h' : a \u2264 b) : set_ub s b :=\nbegin \n  intros x xs,\n  apply le_trans,\n  apply h,\n  apply xs,\n  exact h',\nend\n\nend\n\n\n\nsection\nopen function\n\nexample (c : \u211d) : injective (\u03bb x, x + c) :=\nbegin\n  intros x\u2081 x\u2082 h',\n  exact (add_left_inj c).mp h',\nend\n\nexample {c : \u211d} (h : c \u2260 0) : injective (\u03bb x, c * x) :=\nbegin\n  intros a b,\n  dsimp,\n  intro heq,\n  cases (mul_eq_mul_left_iff.mp heq),\n  { assumption,},\n  { contradiction,} \nend\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\nvariables {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2}\n\nexample (injg : injective g) (injf : injective f) :\n  injective (\u03bb x, g (f x)) :=\nbegin \n  intros a b,\n  dsimp,\n  intro heq,\n  apply injf,\n  apply injg,\n  exact heq,\nend\n\nend\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/03_Logic/01_Implication_Universal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025423, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7142091185559378}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module order.partial_sups\n! leanprover-community/mathlib commit d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Lattice\nimport Mathlib.Order.Hom.Basic\nimport Mathlib.Order.ConditionallyCompleteLattice.Finset\n\n/-!\n# The monotone sequence of partial supremums of a sequence\n\nWe define `partialSups : (\u2115 \u2192 \u03b1) \u2192 \u2115 \u2192o \u03b1` inductively. For `f : \u2115 \u2192 \u03b1`, `partialSups f` is\nthe sequence `f 0 `, `f 0 \u2294 f 1`, `f 0 \u2294 f 1 \u2294 f 2`, ... The point of this definition is that\n* it doesn't need a `\u2a06`, as opposed to `\u2a06 (i \u2264 n), f i` (which also means the wrong thing on\n  `ConditionallyCompleteLattice`s).\n* it doesn't need a `\u22a5`, as opposed to `(Finset.range (n + 1)).sup f`.\n* it avoids needing to prove that `Finset.range (n + 1)` is nonempty to use `Finset.sup'`.\n\nEquivalence with those definitions is shown by `partialSups_eq_bsup\u1d62`, `partialSups_eq_sup_range`,\nand `partialSups_eq_sup'_range` respectively.\n\n## Notes\n\nOne might dispute whether this sequence should start at `f 0` or `\u22a5`. We choose the former because :\n* Starting at `\u22a5` requires... having a bottom element.\n* `fun f n \u21a6 (Finset.range n).sup f` is already effectively the sequence starting at `\u22a5`.\n* If we started at `\u22a5` we wouldn't have the Galois insertion. See `partialSups.gi`.\n\n## TODO\n\nOne could generalize `partialSups` to any locally finite bot preorder domain, in place of `\u2115`.\nNecessary for the TODO in the module docstring of `Order.disjointed`.\n-/\n\n\nvariable {\u03b1 : Type _}\n\nsection SemilatticeSup\n\nvariable [SemilatticeSup \u03b1]\n\n/-- The monotone sequence whose value at `n` is the supremum of the `f m` where `m \u2264 n`. -/\ndef partialSups (f : \u2115 \u2192 \u03b1) : \u2115 \u2192o \u03b1 :=\n  \u27e8@Nat.rec (fun _ => \u03b1) (f 0) fun (n : \u2115) (a : \u03b1) => a \u2294 f (n + 1),\n    monotone_nat_of_le_succ fun _ => le_sup_left\u27e9\n#align partial_sups partialSups\n\n@[simp]\ntheorem partialSups_zero (f : \u2115 \u2192 \u03b1) : partialSups f 0 = f 0 :=\n  rfl\n#align partial_sups_zero partialSups_zero\n\n@[simp]\ntheorem partialSups_succ (f : \u2115 \u2192 \u03b1) (n : \u2115) :\n    partialSups f (n + 1) = partialSups f n \u2294 f (n + 1) :=\n  rfl\n#align partial_sups_succ partialSups_succ\n\ntheorem le_partialSups_of_le (f : \u2115 \u2192 \u03b1) {m n : \u2115} (h : m \u2264 n) : f m \u2264 partialSups f n := by\n  induction' n with n ih\n  \u00b7 rw [nonpos_iff_eq_zero.mp h, partialSups_zero]\n  \u00b7 cases' h with h h\n    \u00b7 exact le_sup_right\n    \u00b7 exact (ih h).trans le_sup_left\n#align le_partial_sups_of_le le_partialSups_of_le\n\ntheorem le_partialSups (f : \u2115 \u2192 \u03b1) : f \u2264 partialSups f := fun _n => le_partialSups_of_le f le_rfl\n#align le_partial_sups le_partialSups\n\ntheorem partialSups_le (f : \u2115 \u2192 \u03b1) (n : \u2115) (a : \u03b1) (w : \u2200 m, m \u2264 n \u2192 f m \u2264 a) :\n    partialSups f n \u2264 a := by\n  induction' n with n ih\n  \u00b7 apply w 0 le_rfl\n  \u00b7 exact sup_le (ih fun m p => w m (Nat.le_succ_of_le p)) (w (n + 1) le_rfl)\n#align partial_sups_le partialSups_le\n\n@[simp]\ntheorem bddAbove_range_partialSups {f : \u2115 \u2192 \u03b1} :\n    BddAbove (Set.range (partialSups f)) \u2194 BddAbove (Set.range f) := by\n  apply exists_congr fun a => _\n  intro a\n  constructor\n  \u00b7 rintro h b \u27e8i, rfl\u27e9\n    exact (le_partialSups _ _).trans (h (Set.mem_range_self i))\n  \u00b7 rintro h b \u27e8i, rfl\u27e9\n    exact partialSups_le _ _ _ fun _ _ => h (Set.mem_range_self _)\n#align bdd_above_range_partial_sups bddAbove_range_partialSups\n\ntheorem Monotone.partialSups_eq {f : \u2115 \u2192 \u03b1} (hf : Monotone f) : (partialSups f : \u2115 \u2192 \u03b1) = f := by\n  ext n\n  induction' n with n ih\n  \u00b7 rfl\n  \u00b7 rw [partialSups_succ, ih, sup_eq_right.2 (hf (Nat.le_succ _))]\n#align monotone.partial_sups_eq Monotone.partialSups_eq\n\ntheorem partialSups_mono : Monotone (partialSups : (\u2115 \u2192 \u03b1) \u2192 \u2115 \u2192o \u03b1) := by\n  rintro f g h n\n  induction' n with n ih\n  \u00b7 exact h 0\n  \u00b7 exact sup_le_sup ih (h _)\n#align partial_sups_mono partialSups_mono\n\n/-- `partialSups` forms a Galois insertion with the coercion from monotone functions to functions.\n-/\ndef partialSups.gi : GaloisInsertion (partialSups : (\u2115 \u2192 \u03b1) \u2192 \u2115 \u2192o \u03b1) (\u2191) where\n  choice f h :=\n    \u27e8f, by convert (partialSups f).monotone using 1; exact (le_partialSups f).antisymm h\u27e9\n  gc f g := by\n    refine' \u27e8(le_partialSups f).trans, fun h => _\u27e9\n    convert partialSups_mono h\n    exact OrderHom.ext _ _ g.monotone.partialSups_eq.symm\n  le_l_u f := le_partialSups f\n  choice_eq f h := OrderHom.ext _ _ ((le_partialSups f).antisymm h)\n#align partial_sups.gi partialSups.gi\n\ntheorem partialSups_eq_sup'_range (f : \u2115 \u2192 \u03b1) (n : \u2115) :\n    partialSups f n = (Finset.range (n + 1)).sup' \u27e8n, Finset.self_mem_range_succ n\u27e9 f := by\n  induction' n with n ih\n  \u00b7 simp\n  \u00b7 dsimp [partialSups] at ih\u22a2\n    simp_rw [@Finset.range_succ n.succ]\n    rw [ih, Finset.sup'_insert, sup_comm]\n#align partial_sups_eq_sup'_range partialSups_eq_sup'_range\n\nend SemilatticeSup\n\ntheorem partialSups_eq_sup_range [SemilatticeSup \u03b1] [OrderBot \u03b1] (f : \u2115 \u2192 \u03b1) (n : \u2115) :\n    partialSups f n = (Finset.range (n + 1)).sup f := by\n  induction' n with n ih\n  \u00b7 simp\n  \u00b7 dsimp [partialSups] at ih\u22a2\n    rw [Finset.range_succ, Finset.sup_insert, sup_comm, ih]\n#align partial_sups_eq_sup_range partialSups_eq_sup_range\n\n/- Note this lemma requires a distributive lattice, so is not useful (or true) in situations such as\nsubmodules. -/\ntheorem partialSups_disjoint_of_disjoint [DistribLattice \u03b1] [OrderBot \u03b1] (f : \u2115 \u2192 \u03b1)\n    (h : Pairwise (Disjoint on f)) {m n : \u2115} (hmn : m < n) : Disjoint (partialSups f m) (f n) := by\n  induction' m with m ih\n  \u00b7 exact h hmn.ne\n  \u00b7 rw [partialSups_succ, disjoint_sup_left]\n    exact \u27e8ih (Nat.lt_of_succ_lt hmn), h hmn.ne\u27e9\n#align partial_sups_disjoint_of_disjoint partialSups_disjoint_of_disjoint\n\nsection ConditionallyCompleteLattice\n\nvariable [ConditionallyCompleteLattice \u03b1]\n\ntheorem partialSups_eq_csup\u1d62_Iic (f : \u2115 \u2192 \u03b1) (n : \u2115) : partialSups f n = \u2a06 i : Set.Iic n, f i := by\n  have : Set.Iio (n + 1) = Set.Iic n := Set.ext fun _ => Nat.lt_succ_iff\n  rw [partialSups_eq_sup'_range, Finset.sup'_eq_csup\u209b_image, Finset.coe_range, sup\u1d62, this]\n  simp only [Set.range, Subtype.exists, Set.mem_Iic, exists_prop, (\u00b7 '' \u00b7)]\n#align partial_sups_eq_csupr_Iic partialSups_eq_csup\u1d62_Iic\n\n@[simp]\ntheorem csup\u1d62_partialSups_eq {f : \u2115 \u2192 \u03b1} (h : BddAbove (Set.range f)) :\n    (\u2a06 n, partialSups f n) = \u2a06 n, f n := by\n  refine' (csup\u1d62_le fun n => _).antisymm (csup\u1d62_mono _ <| le_partialSups f)\n  \u00b7 rw [partialSups_eq_csup\u1d62_Iic]\n    exact csup\u1d62_le fun i => le_csup\u1d62 h _\n  \u00b7 rwa [bddAbove_range_partialSups]\n#align csupr_partial_sups_eq csup\u1d62_partialSups_eq\n\nend ConditionallyCompleteLattice\n\nsection CompleteLattice\n\nvariable [CompleteLattice \u03b1]\n\ntheorem partialSups_eq_bsup\u1d62 (f : \u2115 \u2192 \u03b1) (n : \u2115) : partialSups f n = \u2a06 i \u2264 n, f i := by\n  simpa only [sup\u1d62_subtype] using partialSups_eq_csup\u1d62_Iic f n\n#align partial_sups_eq_bsupr partialSups_eq_bsup\u1d62\n\n-- Porting note: simp can prove this @[simp]\ntheorem sup\u1d62_partialSups_eq (f : \u2115 \u2192 \u03b1) : (\u2a06 n, partialSups f n) = \u2a06 n, f n :=\n  csup\u1d62_partialSups_eq <| OrderTop.bddAbove _\n#align supr_partial_sups_eq sup\u1d62_partialSups_eq\n\ntheorem sup\u1d62_le_sup\u1d62_of_partialSups_le_partialSups {f g : \u2115 \u2192 \u03b1}\n    (h : partialSups f \u2264 partialSups g) : (\u2a06 n, f n) \u2264 \u2a06 n, g n := by\n  rw [\u2190 sup\u1d62_partialSups_eq f, \u2190 sup\u1d62_partialSups_eq g]\n  exact sup\u1d62_mono h\n#align supr_le_supr_of_partial_sups_le_partial_sups sup\u1d62_le_sup\u1d62_of_partialSups_le_partialSups\n\ntheorem sup\u1d62_eq_sup\u1d62_of_partialSups_eq_partialSups {f g : \u2115 \u2192 \u03b1}\n    (h : partialSups f = partialSups g) : (\u2a06 n, f n) = \u2a06 n, g n := by\n  simp_rw [\u2190 sup\u1d62_partialSups_eq f, \u2190 sup\u1d62_partialSups_eq g, h]\n#align supr_eq_supr_of_partial_sups_eq_partial_sups sup\u1d62_eq_sup\u1d62_of_partialSups_eq_partialSups\n\nend CompleteLattice\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/PartialSups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.714162452575578}}
{"text": "/-\nCopyright (c) 2020 Jean Lo. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jean Lo\n-/\n\nimport topology.algebra.group\nimport logic.function.iterate\n\n/-!\n# Flows and invariant sets\n\nThis file defines a flow on a topological space `\u03b1` by a topological\nmonoid `\u03c4` as a continuous monoid-act of `\u03c4` on `\u03b1`. Anticipating the\ncases where `\u03c4` is one of `\u2115`, `\u2124`, `\u211d\u207a`, or `\u211d`, we use additive\nnotation for the monoids, though the definition does not require\ncommutativity.\n\nA subset `s` of `\u03b1` is invariant under a family of maps `\u03d5\u209c : \u03b1 \u2192 \u03b1`\nif `\u03d5\u209c s \u2286 s` for all `t`. In many cases `\u03d5` will be a flow on\n`\u03b1`. For the cases where `\u03d5` is a flow by an ordered (additive,\ncommutative) monoid, we additionally define forward invariance, where\n`t` ranges over those elements which are nonnegative.\n\nAdditionally, we define such constructions as the restriction of a\nflow onto an invariant subset, and the time-reveral of a flow by a\ngroup.\n-/\n\nopen set function filter\n\n/-!\n### Invariant sets\n-/\n\nsection invariant\n\nvariables {\u03c4 : Type*} {\u03b1 : Type*}\n\n/-- A set `s \u2286 \u03b1` is invariant under `\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1` if\n    `\u03d5 t s \u2286 s` for all `t` in `\u03c4`. -/\ndef is_invariant (\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1) (s : set \u03b1): Prop := \u2200 t, maps_to (\u03d5 t) s s\n\nvariables (\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1) (s : set \u03b1)\n\nlemma is_invariant_iff_image : is_invariant \u03d5 s \u2194 \u2200 t, \u03d5 t '' s \u2286 s :=\nby simp_rw [is_invariant, maps_to']\n\n/-- A set `s \u2286 \u03b1` is forward-invariant under `\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1` if\n    `\u03d5 t s \u2286 s` for all `t \u2265 0`. -/\ndef is_fw_invariant [preorder \u03c4] [has_zero \u03c4] (\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1) (s : set \u03b1): Prop :=\n\u2200 \u2983t\u2984, 0 \u2264 t \u2192 maps_to (\u03d5 t) s s\n\nlemma is_invariant.is_fw_invariant [preorder \u03c4] [has_zero \u03c4] {\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1} {s : set \u03b1}\n  (h : is_invariant \u03d5 s) : is_fw_invariant \u03d5 s :=\n\u03bb t ht, h t\n\n/-- If `\u03c4` is a `canonically_ordered_add_monoid` (e.g., `\u2115` or `\u211d\u22650`), then the notions\n`is_fw_invariant` and `is_invariant` are equivalent. -/\nlemma is_fw_invariant.is_invariant [canonically_ordered_add_monoid \u03c4] {\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1} {s : set \u03b1}\n  (h : is_fw_invariant \u03d5 s) : is_invariant \u03d5 s :=\n\u03bb t, h (zero_le t)\n\n/-- If `\u03c4` is a `canonically_ordered_add_monoid` (e.g., `\u2115` or `\u211d\u22650`), then the notions\n`is_fw_invariant` and `is_invariant` are equivalent. -/\nlemma is_fw_invariant_iff_is_invariant [canonically_ordered_add_monoid \u03c4]\n  {\u03d5 : \u03c4 \u2192 \u03b1 \u2192 \u03b1} {s : set \u03b1} :\n  is_fw_invariant \u03d5 s \u2194 is_invariant \u03d5 s :=\n\u27e8is_fw_invariant.is_invariant, is_invariant.is_fw_invariant\u27e9\n\nend invariant\n\n/-!\n### Flows\n-/\n\n/-- A flow on a topological space `\u03b1` by an a additive topological\n    monoid `\u03c4` is a continuous monoid action of `\u03c4` on `\u03b1`.-/\nstructure flow\n  (\u03c4 : Type*) [topological_space \u03c4] [add_monoid \u03c4] [has_continuous_add \u03c4]\n  (\u03b1 : Type*) [topological_space \u03b1] :=\n(to_fun    : \u03c4 \u2192 \u03b1 \u2192 \u03b1)\n(cont'     : continuous (uncurry to_fun))\n(map_add'  : \u2200 t\u2081 t\u2082 x, to_fun (t\u2081 + t\u2082) x = to_fun t\u2081 (to_fun t\u2082 x))\n(map_zero' : \u2200 x, to_fun 0 x = x)\n\nnamespace flow\n\nvariables\n{\u03c4 : Type*} [add_monoid \u03c4] [topological_space \u03c4] [has_continuous_add \u03c4]\n{\u03b1 : Type*} [topological_space \u03b1]\n(\u03d5 : flow \u03c4 \u03b1)\n\ninstance : inhabited (flow \u03c4 \u03b1) :=\n\u27e8{ to_fun    := \u03bb _ x, x,\n   cont'     := continuous_snd,\n   map_add'  := \u03bb _ _ _, rfl,\n   map_zero' := \u03bb _, rfl }\u27e9\n\ninstance : has_coe_to_fun (flow \u03c4 \u03b1) (\u03bb _, \u03c4 \u2192 \u03b1 \u2192 \u03b1) := \u27e8flow.to_fun\u27e9\n\n@[ext]\n\n\n@[continuity]\nprotected lemma continuous {\u03b2 : Type*} [topological_space \u03b2]\n  {t : \u03b2 \u2192 \u03c4} (ht : continuous t) {f : \u03b2 \u2192 \u03b1} (hf : continuous f) :\n  continuous (\u03bb x, \u03d5 (t x) (f x)) :=\n\u03d5.cont'.comp (ht.prod_mk hf)\n\nalias flow.continuous \u2190 continuous.flow\n\nlemma map_add (t\u2081 t\u2082 : \u03c4) (x : \u03b1) : \u03d5 (t\u2081 + t\u2082) x = \u03d5 t\u2081 (\u03d5 t\u2082 x) :=\n\u03d5.map_add' _ _ _\n\n@[simp] lemma map_zero : \u03d5 0 = id := funext \u03d5.map_zero'\n\nlemma map_zero_apply (x : \u03b1) : \u03d5 0 x = x := \u03d5.map_zero' x\n\n/-- Iterations of a continuous function from a topological space `\u03b1`\n    to itself defines a semiflow by `\u2115` on `\u03b1`. -/\ndef from_iter {g : \u03b1 \u2192 \u03b1} (h : continuous g) : flow \u2115 \u03b1 :=\n{ to_fun    := \u03bb n x, g^[n] x,\n  cont'     := continuous_uncurry_of_discrete_topology_left (continuous.iterate h),\n  map_add'  := iterate_add_apply _,\n  map_zero' := \u03bb x, rfl }\n\n/-- Restriction of a flow onto an invariant set. -/\ndef restrict {s : set \u03b1} (h : is_invariant \u03d5 s) : flow \u03c4 \u21a5s :=\n{ to_fun    := \u03bb t, (h t).restrict _ _ _,\n  cont'     := continuous_subtype_mk _ (\u03d5.continuous continuous_fst\n    (continuous_subtype_coe.comp continuous_snd)),\n  map_add'  := \u03bb _ _ _, subtype.ext (map_add _ _ _ _),\n  map_zero' := \u03bb _, subtype.ext (map_zero_apply _ _)}\n\nend flow\n\nnamespace flow\n\nvariables\n{\u03c4 : Type*} [add_comm_group \u03c4] [topological_space \u03c4] [topological_add_group \u03c4]\n{\u03b1 : Type*} [topological_space \u03b1]\n(\u03d5 : flow \u03c4 \u03b1)\n\nlemma is_invariant_iff_image_eq (s : set \u03b1) :\n  is_invariant \u03d5 s \u2194 \u2200 t, \u03d5 t '' s = s :=\n(is_invariant_iff_image _ _).trans (iff.intro\n  (\u03bb h t, subset.antisymm (h t) (\u03bb _ hx, \u27e8_, h (-t) \u27e8_, hx, rfl\u27e9, by simp [\u2190 map_add]\u27e9))\n  (\u03bb h t, by rw h t))\n\n/-- The time-reversal of a flow `\u03d5` by a (commutative, additive) group\n    is defined `\u03d5.reverse t x = \u03d5 (-t) x`. -/\ndef reverse : flow \u03c4 \u03b1 :=\n{ to_fun    := \u03bb t, \u03d5 (-t),\n  cont'     := \u03d5.continuous continuous_fst.neg continuous_snd,\n  map_add'  := \u03bb _ _ _, by rw [neg_add, map_add],\n  map_zero' := \u03bb _, by rw [neg_zero, map_zero_apply] }\n\n/-- The map `\u03d5 t` as a homeomorphism. -/\ndef to_homeomorph (t : \u03c4) : \u03b1 \u2243\u209c \u03b1 :=\n{ to_fun := \u03d5 t,\n  inv_fun := \u03d5 (-t),\n  left_inv := \u03bb x, by rw [\u2190 map_add, neg_add_self, map_zero_apply],\n  right_inv := \u03bb x, by rw [\u2190 map_add, add_neg_self, map_zero_apply] }\n\nlemma image_eq_preimage (t : \u03c4) (s : set \u03b1) : \u03d5 t '' s = \u03d5 (-t) \u207b\u00b9' s :=\n(\u03d5.to_homeomorph t).to_equiv.image_eq_preimage s\n\nend flow\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/dynamics/flow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7141624500613346}}
{"text": "namespace chap8ex1\n\n    open function\n\n    #print surjective\n\n    universes u v w\n    variables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n    open function\n\n    lemma composition_check {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} : \u03b1 \u2192 \u03b3 := g \u2218 f\n\n    lemma surjective_comp {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} (hg : surjective g) (hf : surjective f) :\n    surjective (g \u2218 f) :=\n    \u03bb lg,\n    match (hg lg) with exists.intro (b: \u03b2) (beq : g b = lg) :=\n        match (hf b) with exists.intro (a : \u03b1) (aeq : f a = b) :=\n            begin\n                existsi a,\n                simp [aeq, beq]\n            end\n        end\n    end\n\nend chap8ex1\n\nnamespace chap8ex2\n\n    namespace hidden\n\n        open nat (zero succ)\n\n        def addition : \u2115 \u2192 \u2115 \u2192 \u2115\n        | m 0 := m\n        | m (succ n) := succ (addition m n)\n\n        lemma eight_plus_five_is_thirteen : addition 8 5 = 13 := rfl\n\n        lemma zero_add : \u2200 (n : \u2115), addition 0 n = n\n        | 0 := by refl\n        | (succ 0) := by refl\n        | (succ n) := by {\n            have s1 : addition 0 n = n, by rw [zero_add n],\n            have s2 : addition 0 (succ n) = succ (addition 0 n), from rfl,\n            rw [s2, s1]\n        }\n\n        lemma add_zero : \u2200 (n : \u2115), addition n 0 = n\n        | 0 := by refl\n        | (succ n) := by refl\n\n        lemma add_one : \u2200 n, addition n 1 = succ n\n        | 0 := rfl\n        | (succ n) := rfl\n\n        lemma one_add : \u2200 n, addition 1 n = succ n\n        | 0 := by rw [add_zero]\n        | (nat.succ npred) := (\n            have ih : addition 1 npred = succ npred, from one_add npred,\n            have addition 1 (succ npred) = succ (addition 1 npred), from rfl,\n            by rw [this, ih]\n        )\n\n        lemma m_add_succ (m : \u2115) : \u2200 n, addition (succ m) n = succ (addition m n)\n        | 0 := rfl\n        | (nat.succ npred) := by {\n            have ih : addition (succ m) npred = succ (addition m npred), by rw [m_add_succ npred],\n            have s1 : addition (succ m) (succ npred) = succ (addition (succ m) npred), from rfl,\n            have s2 : succ (addition (succ m) npred) = succ (succ (addition m npred)), by rw [ih],\n            have s3 : succ (succ (addition m npred)) = succ (addition m (succ npred)), by refl,\n            rw [s1, s2, s3]\n        }\n\n        lemma one_add' (n : \u2115): addition 1 n = succ n :=\n        have addition 1 n = succ (addition 0 n), by rw m_add_succ,\n        by rw [this, zero_add]\n\n        lemma add_succ_commutes : \u2200 m n, addition (succ m) n = addition m (succ n)\n        | m n := (\n            have f1 : addition (succ m) n = succ (addition m n), by rw [m_add_succ m],\n            have f2 : addition m (succ n) = succ (addition m n), by rw [addition],\n            by simp [f1, f2]\n        )\n\n        theorem addition_comm : \u2200 (m n : \u2115), addition m n = addition n m\n        | 0 n := by rw [add_zero, zero_add]\n        | (succ mpred) n :=\n            calc\n                addition (succ mpred) n = succ (addition mpred n) : by rw m_add_succ\n                    ... = succ (addition n mpred) : by rw [addition_comm]\n                    ... = addition n (succ mpred) : rfl\n\n        theorem addition_assoc : \u2200 (l m n : \u2115), addition (addition l m) n = addition l (addition m n)\n        | l m 0 := by rw [add_zero, add_zero]\n        | l m (succ npred) :=\n            calc\n                addition (addition l m) (succ npred) = succ (addition (addition l m) npred) : rfl\n                    ... = succ (addition l (addition m npred)) : by rw [addition_assoc]\n                    ... = addition l (succ (addition m npred)) : by refl\n                    ... = addition l (addition m (succ npred)) : by refl\n\n\n        -- MULTIPLICATION --\n\n        def multiplication : \u2115 \u2192 \u2115 \u2192 \u2115\n        | 0 n := 0\n        | m 0 := 0\n        | m (succ n) := addition (multiplication m n) m\n\n        lemma two_times_three_is_six : multiplication 2 3 = 6 := rfl\n\n        theorem mul_zero : \u2200 n, multiplication n 0 = 0\n        | 0 := rfl\n        | (succ _) := rfl\n\n        theorem zero_mul : \u2200 n, multiplication 0 n = 0\n        | 0 := rfl\n        | (succ _) := rfl\n\n        theorem mul_one : \u2200 n, multiplication n 1 = n\n        | 0 := rfl\n        | (succ n) :=\n            calc\n                multiplication (succ n) 1 = addition (multiplication (succ n) 0) (succ n) : rfl\n                    ... = addition 0 (succ n) : rfl\n                    ... = succ n : by rw zero_add\n\n        theorem one_mul : \u2200 n, multiplication 1 n = n\n        | 0 := rfl\n        | (succ n) :=\n            calc\n                multiplication 1 (succ n) = multiplication 1 n + 1 : rfl\n                    ... = n + 1 : by rw [one_mul n]\n                    ... = succ n : rfl\n\n        theorem mul_add_once : \u2200 m n, addition (multiplication m n) n = multiplication (succ m) n\n        | 0 0 := rfl\n        | 0 (succ n) := by rw [one_mul, zero_mul, zero_add]\n        | (succ m) 0 := by rw [mul_zero, mul_zero, add_zero]\n        | (succ m) (succ n) :=\n            calc\n                addition (multiplication (succ m) (succ n)) (succ n) = addition (addition (multiplication (succ m) n) (succ m)) (succ n) : rfl\n                    ... = addition (multiplication (succ m) n) (addition (succ m) (succ n)) : by rw [addition_assoc]\n                    ... = addition (multiplication (succ m) n) (addition (succ n) (succ m)) : by rw [addition_comm (succ m)]\n                    ... = addition (addition (multiplication (succ m) n) n) (succ (succ m)) : by rw [add_succ_commutes, addition_assoc]\n                    ... = addition (multiplication (succ (succ m)) n) (succ (succ m)) : by rw [mul_add_once]\n                    ... = multiplication (succ (succ m)) (succ n) : rfl\n\n        theorem mul_comm : \u2200 m n, multiplication m n = multiplication n m\n        | 0 0 := rfl\n        | 0 (succ n) := by rw [zero_mul, mul_zero]\n        | (succ m) 0 := by rw [zero_mul, mul_zero]\n        | (succ m) (succ n) :=\n            calc\n                multiplication (succ m) (succ n) = addition (multiplication (succ m) n) (succ m) : rfl\n                    ... = addition (multiplication n (succ m)) (succ m) : by rw [mul_comm]\n                    ... = multiplication (succ n) (succ m) : by rw [mul_add_once]\n\n        theorem mul_distrib : \u2200 l m n, multiplication l (addition m n) = addition (multiplication l m) (multiplication l n)\n        | 0 _ _ := by rw [zero_mul, zero_mul, zero_mul, add_zero]\n        | _ _ 0 := by rw [add_zero, mul_zero, add_zero]\n        | _ 0 _ := by rw [zero_add, mul_zero, zero_add]\n        | (l+1) (m+1) (n+1) :=\n            let l' := succ l, m' := succ m, n' := succ n in\n            -- Looks terrible, could be made much shorter.\n            calc\n                multiplication l' (addition m' n') = multiplication l' (succ (addition m' n)) : rfl\n                    ... = addition (multiplication l' (addition m' n)) l' : rfl\n                    ... = addition (multiplication l' (succ $ addition m n)) l' : by { rw [add_succ_commutes], refl }\n                    ... = addition (addition (multiplication l' (addition m n)) l') l' : rfl\n                    ... = addition (addition (addition (multiplication l (addition m n)) (addition m n)) l') l' : by rw [mul_add_once]\n                    ... = addition (addition (addition (addition (multiplication l m) (multiplication l n)) (addition m n)) l') l' : by rw [mul_distrib]\n                    ... = addition (addition (addition (multiplication l m) (addition (multiplication l n) (addition m n))) l') l' : by rw [addition_assoc (multiplication l m)]\n                    ... = addition (addition (addition (multiplication l m) (addition (addition (multiplication l n) n) m)) l') l' : by rw [addition_comm m n, addition_assoc (multiplication l n)]\n                    ... = addition (addition (addition (multiplication l m) (addition (multiplication l' n) m)) l') l' : by rw [mul_add_once]\n                    ... = addition (addition (addition (multiplication l m) (addition m (multiplication l' n))) l') l' : by rw [addition_comm (multiplication l' n)]\n                    ... = addition (addition (addition (addition (multiplication l m) m) (multiplication l' n)) l') l' : by rw [\u2190addition_assoc (multiplication l m)]\n                    ... = addition (addition (addition (multiplication l' m) (multiplication l' n)) l') l' : by rw [mul_add_once]\n                    ... = addition (addition (multiplication l' m) (addition (multiplication l' n) l')) l' : by rw [addition_assoc (multiplication l' m)]\n                    ... = addition (addition (multiplication l' m) (multiplication l' n')) l' : rfl\n                    ... = addition l' (addition (multiplication l' m) (multiplication l' n')) : by rw [addition_comm]\n                    ... = addition (addition l' (multiplication l' m)) (multiplication l' n') : by rw [addition_assoc]\n                    ... = addition (addition (multiplication l' m) l') (multiplication l' n') : by rw [addition_comm l']\n                    ... = addition (multiplication l' m') (multiplication l' n') : rfl\n\n        theorem mul_assoc : \u2200 l m n, multiplication (multiplication l m) n = multiplication l (multiplication m n)\n        | 0 _ _ := by rw [zero_mul, zero_mul, zero_mul]\n        | _ 0 _ := by rw [mul_zero, zero_mul, mul_zero]\n        | _ _ 0 := by rw [mul_zero, mul_zero, mul_zero]\n        | (l+1) (m+1) (n+1) :=\n            let l' := succ l, m' := succ m, n' := succ n in\n            -- ditto\n            calc\n                multiplication (multiplication l' m') n' = addition (multiplication (multiplication l' m') n) (multiplication l' m') : rfl\n                    ... = addition (multiplication (addition (multiplication l' m) l') n) (multiplication l' m') : rfl\n                    ... = addition (multiplication (addition (addition (multiplication l m) m) l') n) (multiplication l' m') : by rw [mul_add_once]\n                    ... = addition (multiplication n (addition (addition (multiplication l m) m) l')) (multiplication l' m') : by rw [mul_comm]\n                    ... = addition (addition (multiplication n (addition (multiplication l m) m)) (multiplication n l')) (multiplication l' m') : by rw [mul_distrib n]\n                    ... = addition (addition (addition (multiplication n (multiplication l m)) (multiplication n m)) (multiplication n l')) (multiplication l' m') : by rw [mul_distrib n]\n                    ... = addition (addition (addition (multiplication (multiplication l m) n) (multiplication n m)) (multiplication n l')) (multiplication l' m') : by rw [mul_comm]\n                    ... = addition (addition (addition (multiplication l (multiplication m n)) (multiplication n m)) (multiplication n l')) (multiplication l' m') : by rw [mul_assoc]\n                    ... = addition (addition (addition (multiplication l (multiplication m n)) (multiplication m n)) (multiplication n l')) (multiplication l' m') : by rw [mul_comm m]\n                    ... = addition (addition (multiplication l' (multiplication m n)) (multiplication n l')) (multiplication l' m') : by rw [mul_add_once]\n                    ... = addition (multiplication l' (multiplication m n)) (addition (multiplication n l') (multiplication l' m')) : by rw [addition_assoc]\n                    ... = addition (multiplication l' (multiplication m n)) (addition (multiplication l' n) (multiplication l' m')) : by rw [mul_comm n]\n                    ... = addition (multiplication l' (multiplication m n)) (multiplication l' (addition n m')) : by rw [mul_distrib]\n                    ... = multiplication l' (addition (multiplication m n) (addition n m')) : by rw [\u2190mul_distrib]\n                    ... = multiplication l' (addition (multiplication n m) (addition n m')) : by rw [mul_comm m]\n                    ... = multiplication l' (addition (addition (multiplication n m) n) m') : by rw [addition_assoc]\n                    ... = multiplication l' (addition (addition (multiplication n m) m) n') : by rw [addition_assoc, addition_comm n, add_succ_commutes, \u2190addition_assoc]\n                    ... = multiplication l' (addition (multiplication n' m) n') : by rw [mul_add_once]\n                    ... = multiplication l' (multiplication n' m') : by refl\n                    ... = multiplication l' (multiplication m' n') : by rw [mul_comm n']\n\n\n        -- POW --\n\n        def pow (m : \u2115) : \u2115 \u2192 \u2115\n        | 0 := 1\n        | (n+1) := multiplication (pow n) m\n\n        theorem pow_2_2_is_4 : pow 2 2 = 4 := rfl\n        theorem pow_6_2_is_36 : pow 6 2 = 36 := rfl\n        theorem pow_0_1_is_0 : pow 0 1 = 0 := rfl\n        theorem pow_n_zero_is_1 (n : \u2115) : pow n 0 = 1 := rfl\n        theorem pow_5_3_is_125 : pow 5 3 = 125 := rfl\n\n        theorem pow_0_n_is_0 : \u2200 n, (0 < n) \u2192 pow 0 n = 0\n        | 0 hnpos := by { exact false.elim (lt_irrefl 0 hnpos) }\n        | (n+1) _ :=\n            calc\n                pow 0 (n+1) = multiplication (pow 0 n) 0 : rfl\n                    ... = 0 : by rw [mul_zero]\n\n        theorem pow_n_1_is_n : \u2200 m, (pow m 1) = m\n        | 0 := rfl\n        | (m+1) :=\n            calc\n                pow (m+1) 1 = multiplication (pow m 0) (m+1) : rfl\n                    ... = multiplication 1 (m + 1) : rfl\n                    ... = m+1 : by rw [one_mul]\n\n        theorem pow_1_n_is_one : \u2200 n, pow 1 n = 1\n        | 0 := rfl\n        | (n+1) :=\n            calc\n                pow 1 (n+1) = multiplication (pow 1 n) 1 : rfl\n                    ... = multiplication 1 1 : by rw [pow_1_n_is_one]\n                    ... = 1 : by rw mul_one\n\n        theorem pow_addition_identity : \u2200 (b m n : \u2115), pow b (addition m n) = multiplication (pow b m) (pow b n)\n        | b 0 0 := by rw [add_zero, pow_n_zero_is_1, mul_one]\n        | b (m+1) 0 :=\n            calc\n                pow b (addition (m+1) 0) = pow b (m+1) : by rw [add_zero]\n                    ... = multiplication (pow b (m+1)) 1 : by rw [mul_one]\n                    ... = multiplication (pow b (m+1)) (pow 0 0) : by rw [pow_n_zero_is_1]\n        | b 0 (n+1) :=\n            calc\n                pow b (addition 0 (n+1)) = pow b (n+1) : by rw [zero_add]\n                    ... = multiplication 1 (pow b (n+1)) : by rw [one_mul]\n                    ... = multiplication (pow 0 0) (pow b (n+1)) : by rw [pow_n_zero_is_1]\n        | b (m+1) (n+1) :=\n            calc\n                pow b (addition (m+1) (n+1)) = pow b (succ $ succ $ addition m n) : by rw [m_add_succ, addition_comm m, m_add_succ, addition_comm n]\n                    ... = multiplication (multiplication (pow b (addition m n)) b) b : rfl\n                    ... = multiplication (multiplication (multiplication (pow b m) (pow b n)) b) b : by rw [pow_addition_identity]\n                    ... = multiplication (multiplication (multiplication (pow b m) b) (pow b n)) b : by rw [mul_comm (pow b m), mul_assoc (pow b n), mul_comm (pow b n)]\n                    ... = multiplication (multiplication (pow b (m+1)) (pow b n)) b : by refl\n                    ... = multiplication (pow b (m+1)) (multiplication (pow b n) b) : by rw [mul_assoc]\n                    ... = multiplication (pow b (m+1)) (pow b (n+1)) : by refl\n\n        theorem pow_multiplication_identity : \u2200 (b c n : \u2115), pow (multiplication b c) n = multiplication (pow b n) (pow c n)\n        | _ _ 0 := by rw [pow_n_zero_is_1, pow_n_zero_is_1, pow_n_zero_is_1, mul_one]\n        | b c (n+1) :=\n            calc\n                pow (multiplication b c) (n+1) = multiplication (pow (multiplication b c) n) (multiplication b c) : rfl\n                    ... = multiplication (multiplication (pow b n) (pow c n)) (multiplication b c) : by rw [pow_multiplication_identity]\n                    ... = multiplication (pow b n) (multiplication (pow c n) (multiplication b c)) : by rw [mul_assoc]\n                    ... = multiplication (pow b n) (multiplication (multiplication (pow c n) c) b) : by rw [mul_comm b, mul_assoc]\n                    ... = multiplication (pow b n) (multiplication (pow c (n+1)) b) : by refl\n                    ... = multiplication (multiplication (pow b n) b) (pow c (n+1)) : by rw [mul_comm (pow c (n+1)), mul_assoc]\n                    ... = multiplication (pow b (n+1)) (pow c (n+1)) : rfl\n\n        theorem pow_pow_identity : \u2200 (b m n : \u2115), pow (pow b m) n = pow b (multiplication m n)\n        | _ _ 0 := by rw [pow_n_zero_is_1, mul_zero, pow_n_zero_is_1]\n        | _ 0 (n+1) := by rw [pow_n_zero_is_1, zero_mul, pow_n_zero_is_1, pow_1_n_is_one]\n        | b (m+1) (n+1) :=\n            let m' := m+1, n' := n+1 in\n            calc\n                pow (pow b m') (n+1) = multiplication (pow (pow b m') n) (pow b m') : rfl\n                    ... = multiplication (pow b (multiplication m' n)) (pow b m') : by rw [pow_pow_identity]\n                    ... = pow b (addition (multiplication m' n) m') : by rw [\u2190pow_addition_identity]\n                    ... = pow b (multiplication m' (succ n)) : rfl\n\n    end hidden\n\nend chap8ex2\n\nnamespace chap8ex3\n\n    namespace hidden\n\n        variable {\u03b1 : Type}\n        variables (a b c d : \u03b1)\n\n        def append : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n        | [] snd := snd\n        | (hd::tl) snd := hd::(append tl snd)\n\n        def reverse : list \u03b1 \u2192 list \u03b1\n        | [] := []\n        | (hd::tl) := append (reverse tl) [hd]\n\n        lemma reverse_abcd : reverse [a, b, c, d] = [d, c, b, a] := rfl\n\n        def length : list \u03b1 \u2192 \u2115\n        | [] := 0\n        | (hd::tl) := nat.succ $ length tl\n\n        lemma length_abcd : length [a, b, c, d] = 4 := rfl\n\n        def append_nil : \u2200 (l: list \u03b1), append l [] = l\n        | [] := rfl\n        | (hd::tl) := calc append (hd::tl) [] = hd::(append tl []) : rfl\n            ... = (hd::tl) : by rw [append_nil]\n\n        def nil_append : \u2200 (l : list \u03b1), append [] l = l\n        | [] := rfl\n        | (hd::tl) := rfl\n\n        theorem append_lengths : \u2200 (l m : list \u03b1), length (append l m) = length l + length m\n        | l [] := calc\n            length (append l []) = length l : by rw [append_nil]\n                ... = length l + length [] : rfl\n        | [] m := calc\n            length (append [] m) = length m : by rw [nil_append]\n                ... = 0 + length m : by rw [zero_add]\n                ... = length [] + length m : rfl\n        | (hd::tl) m :=\n            calc length (append (hd::tl) m) = length (hd::(append tl m)) : rfl\n                ... = length (append tl m) + 1 : rfl\n                ... = (length tl + length m) + 1 : by rw [append_lengths]\n                ... = (length tl + 1) + length m : by rw [add_assoc, add_comm (length m), add_assoc]\n                ... = length (hd::tl) + length m : rfl\n\n\n        theorem reverse_preserves_length : \u2200 (l : list \u03b1), length l = length (reverse l)\n        | [] := rfl\n        | (hd::tl) := eq.symm $ calc\n            length (reverse (hd::tl)) = length (append (reverse tl) [hd]) : rfl\n                ... = length (reverse tl) + length [hd] : by rw [append_lengths]\n                ... = length tl + 1 : by { rw [reverse_preserves_length tl], refl }\n                ... = length (hd::tl) : rfl\n\n    end hidden\n\nend chap8ex3\n\nnamespace chap8ex4\n\n    namespace hidden\n\n\n        variable (C : \u2115 \u2192 Type)\n\n        #check @nat.rec C\n\n        #check (@nat.below C : \u2115 \u2192 Type)\n        #check nat.below\n\n        #reduce @nat.below C (3 : nat)\n\n        #check (@nat.brec_on C :\n        \u03a0 (n : \u2115), (\u03a0 (n' : \u2115), nat.below C n' \u2192 C n') \u2192 C n)\n\n        def course_of_value_helper : \u03a0 (n : \u2115), (\u03a0 (n' : \u2115), nat.below C n' \u2192 C n') \u2192 nat.below C n\n        | 0 _ := ()\n        | (n+1) f := \u27e8\u27e8f n (course_of_value_helper n f), course_of_value_helper n f\u27e9, ()\u27e9\n\n        def course_of_value : \u03a0 (n : \u2115), (\u03a0 (n' : \u2115), nat.below C n' \u2192 C n') \u2192 C n\n        | 0 := (\n            \u03bb h,\n            have f : nat.below C 0 \u2192 C 0, from h 0,\n            have nat.below C 0, from (),\n            f this\n        )\n        | (n+1) := (\n            \u03bb h,\n            have f : nat.below C (n+1) \u2192 C (n+1), from h (n+1),\n            have nat.below C (n+1), from \u27e8\u27e8course_of_value n h, course_of_value_helper C n h\u27e9, ()\u27e9,\n            f this\n        )\n\n        def fib_impl : \u03a0 (n : \u2115), nat.below (\u03bb (n : \u2115), \u2115) n \u2192 \u2115\n        | 0 _ := 1\n        | 1 _ := 1\n        | (n+2) \u27e8\u27e8fibn, \u27e8\u27e8fibnplus1, _\u27e9, ()\u27e9\u27e9, ()\u27e9 := by { exact fibn + fibnplus1 }\n\n        def fib : nat \u2192 nat := \u03bb n,\n        @course_of_value (\u03bb (n : \u2115), \u2115) n (\n            \u03bb n' h,\n            @fib_impl n' h\n        )\n\n        example : fib 0 = 1 := rfl\n        example : fib 1 = 1 := rfl\n        example : fib 2 = 2 := rfl\n        example : fib 3 = 3 := rfl\n        example : fib 4 = 5 := rfl\n        example : fib 6 = 13 := rfl\n    end hidden\n\n    --- Well-founded recursion ---\n\n    namespace hidden\n        universes u v\n        variable \u03b1 : Sort u\n        variable r : \u03b1 \u2192 \u03b1 \u2192 Prop\n        variable h : well_founded r\n\n        variable C : \u03b1 \u2192 Sort (u + 1)\n        variable F : \u03a0 x, (\u03a0 (y : \u03b1), r y x \u2192 C y) \u2192 C x\n\n\n        #check @well_founded\n        #check @acc\n\n        #check (@well_founded.fix : \u03a0 {\u03b1 : Sort u} {C : \u03b1 \u2192 Sort (u + 1)} {r : \u03b1 \u2192 \u03b1 \u2192 Prop},\n        well_founded r \u2192 (\u03a0 (x : \u03b1), (\u03a0 (y : \u03b1), r y x \u2192 C y) \u2192 C x) \u2192 \u03a0 (x : \u03b1), C x)\n\n        def well_founded_fix (\u03b1 : Sort u) (C : \u03b1 \u2192 Sort (u + 1)):\n        \u03a0 {r : \u03b1 \u2192 \u03b1 \u2192 Prop}, well_founded r\n        \u2192 (\u03a0 (x : \u03b1), (\u03a0 (y : \u03b1), r y x \u2192 C y) \u2192 C x)\n        \u2192 \u03a0 (x : \u03b1), C x\n        | hr hwellfoundedr hc hx := (\n            have hryxtocy : \u03a0 (y : \u03b1), hr y hx \u2192 C y, from (\n                \u03bb hy hryx,\n                have hr hy hx, from hryx,\n                have acc hr hy, from well_founded.apply hwellfoundedr hy,\n                acc.rec_on this (\u03bb hz _ f, hc hz f)\n            ),\n            hc hx hryxtocy\n        )\n\n        def f : \u03a0 (x : \u03b1), C x := well_founded.fix h F\n        def f' : \u03a0 (x : \u03b1), C x := well_founded_fix \u03b1 C h F\n    end hidden\n\nend chap8ex4\n\nnamespace chap8ex5\n\n    universe u\n    variable {\u03b1 : Type u}\n\n    inductive vector (\u03b1 : Type u) : nat \u2192 Type u\n    | nil {} : vector 0\n    | cons   : \u03a0 {n}, \u03b1 \u2192 vector n \u2192 vector (n+1)\n\n    #print nat.no_confusion\n    #print vector.no_confusion\n    #check @eq.rec\n\n    namespace vector\n        local notation h :: t := cons h t\n    end vector\n\n    def vec_zero_plus_n : \u03a0 (n : \u2115), vector \u03b1 n \u2192 vector \u03b1 (0 + n) :=\n    \u03bb n v,\n    have h1 : vector \u03b1 (n + 0) := v,\n    have h2 : vector \u03b1 (n + 0) = vector \u03b1 (0 + n), by rw [add_comm],\n    eq.rec h1 h2\n\n    -- With the equation compiler\n\n    def append_with_equation_compiler : \u03a0 (m n : \u2115), vector \u03b1 m \u2192 vector \u03b1 n \u2192 vector \u03b1 (m + n)\n    | 0 n vector.nil v2 := vec_zero_plus_n n v2\n    | (m+1) n (vector.cons hd tl) v2 := (\n        have premise : vector \u03b1 (m + n), from append_with_equation_compiler m n tl v2,\n        have shuffle : vector \u03b1 (m + n + 1) = vector \u03b1 (m+1+n), by rw [add_assoc, add_comm n, add_assoc],\n        eq.rec (vector.cons hd premise) shuffle\n    )\n\n    example : append_with_equation_compiler 2 1 (vector.cons 3 (vector.cons 5 vector.nil)) (vector.cons 8 vector.nil) = vector.cons 3 (vector.cons 5 (vector.cons 8 vector.nil)) := rfl\n\n    -- Without the equation compiler\n\n    def uncons : \u03a0 (n : \u2115), vector \u03b1 (n + 1) \u2192 (\u03b1 \u00d7 vector \u03b1 n)\n    | _ (vector.cons hd tl) := prod.mk hd tl\n\n    def uncons' : \u03a0 (m n : \u2115), vector \u03b1 m \u2192 (m = n + 1) \u2192 (\u03b1 \u00d7 vector \u03b1 n) :=\n    \u03bb m n v,\n    @vector.cases_on\n        _\n        (\u03bb {m} v, (m = n + 1) \u2192 (\u03b1 \u00d7 vector \u03b1 n))\n        _\n        v\n        (\u03bb (h : 0 = n + 1), nat.no_confusion h)\n        (\u03bb {n': \u2115} (hd : \u03b1) (tl : vector \u03b1 n'),\n            assume (h : n' + 1 = n + 1),\n            nat.no_confusion h (\n                \u03bb (h1 : n' = n),\n                have vector \u03b1 n' = vector \u03b1 n, by rw [h1],\n                prod.mk hd (eq.rec tl this)\n            )\n        )\n\n\n    def append_with_elbow_grease : \u03a0 (m n : \u2115), vector \u03b1 m \u2192 vector \u03b1 n \u2192 vector \u03b1 (m + n) :=\n    \u03bb m n v1 v2,\n    (\n        nat.rec_on m\n        (show vector \u03b1 0 \u2192 vector \u03b1 (0 + n), from \u03bb _, vec_zero_plus_n n v2)\n        (\u03bb (m' : \u2115) (acc : vector \u03b1 m' \u2192 vector \u03b1 (m' + n)),\n            show vector \u03b1 (m' + 1) \u2192 vector \u03b1 (m' + 1 + n), from (\n                \u03bb v,\n                let \u27e8hd, tl\u27e9 := uncons' _ m' v rfl in\n                have newtl : vector \u03b1 (m' + n), from acc tl,\n                have newvec : vector \u03b1 (m' + n + 1), from vector.cons hd newtl,\n                have shuffle : vector \u03b1 (m' + n + 1) = vector \u03b1 ((m' + 1) + n), by rw [add_assoc, add_comm n, add_assoc],\n                show vector \u03b1 (m' + 1 + n), from eq.rec newvec shuffle\n            )\n        )\n    ) v1\n\n    example : append_with_elbow_grease 2 1 (vector.cons 3 (vector.cons 5 vector.nil)) (vector.cons 8 vector.nil) = vector.cons 3 (vector.cons 5 (vector.cons 8 vector.nil)) := rfl\n\nend chap8ex5\n\nnamespace chap8ex6\n\n    inductive aexpr : Type\n    | const : \u2115 \u2192 aexpr\n    | var : \u2115 \u2192 aexpr\n    | plus : aexpr \u2192 aexpr \u2192 aexpr\n    | times : aexpr \u2192 aexpr \u2192 aexpr\n\n    open aexpr\n\n    def sample_aexpr : aexpr :=\n    plus (times (var 0) (const 7)) (times (const 2) (var 1))\n\n    def aeval (v : \u2115 \u2192 \u2115) : aexpr \u2192 \u2115\n    | (const n)    := n\n    | (var n)      := v n\n    | (plus e\u2081 e\u2082)  := aeval e\u2081 + aeval e\u2082\n    | (times e\u2081 e\u2082) := aeval e\u2081 * aeval e\u2082\n\n    def sample_val : \u2115 \u2192 \u2115\n    | 0 := 5\n    | 1 := 6\n    | _ := 0\n\n    -- Try it out. You should get 47 here.\n    #eval aeval sample_val sample_aexpr\n\n    def simp_const : aexpr \u2192 aexpr\n    | (plus (const n\u2081) (const n\u2082))  := const (n\u2081 + n\u2082)\n    | (times (const n\u2081) (const n\u2082)) := const (n\u2081 * n\u2082)\n    | e                             := e\n\n    theorem simp_const_eq' (v : \u2115 \u2192 \u2115) :\n    \u2200 e : aexpr, aeval v (simp_const e) = aeval v e :=\n    begin\n        intros e,\n        cases e,\n        reflexivity,\n        reflexivity,\n        cases e_a,\n            cases e_a_1,\n            repeat { reflexivity },\n        cases e_a,\n            cases e_a_1,\n            repeat { reflexivity },\n    end\n\n    theorem simp_const_eq (v : \u2115 \u2192 \u2115) :\n    \u2200 e : aexpr, aeval v (simp_const e) = aeval v e\n    | (const _) := rfl\n    | (var _) := rfl\n    | (plus e1 e2) := (\n        match e1 with\n            | (const m) := (\n                match e2 with\n                    | (const n) := (\n                        have h : simp_const (plus (const m) (const n)) = const (m + n), from rfl,\n                        calc\n                            aeval v (simp_const (plus (const m) (const n))) = aeval v (const (m + n)) : by rw [h]\n                                ... = aeval v (plus (const m) (const n)) : rfl\n                    )\n                    | (var n) := rfl\n                    | (plus e1 e2) := rfl\n                    | (times e1 e2) := rfl\n                end\n            )\n            | (var n) := rfl\n            | (plus _ _) := rfl\n            | (times _ _) := rfl\n        end\n    )\n    | (times e1 e2) := (\n        match e1 with\n            | (const m) := (\n                match e2 with\n                    | (const n) := (\n                        have h : simp_const (times (const m) (const n)) = const (m * n), from rfl,\n                        calc\n                            aeval v (simp_const (times (const m) (const n))) = aeval v (const (m * n)) : by rw [h]\n                                ... = aeval v (times (const m) (const n)) : rfl\n                    )\n                    | (var n) := rfl\n                    | (plus e1 e2) := rfl\n                    | (times e1 e2) := rfl\n                end\n            )\n            | (var n) := rfl\n            | (plus _ _) := rfl\n            | (times _ _) := rfl\n        end\n    )\n\n    def fuse : aexpr \u2192 aexpr\n    | (plus (const n1) (const n2)) := simp_const (plus (const n1) (const n2))\n    | (times (const n1) (const n2)) := simp_const (times (const n1) (const n2))\n    | (plus e1 e2) := plus (fuse e1) (fuse e2)\n    | (times e1 e2) := times (fuse e1) (fuse e2)\n    | e := e\n\n    -- This is very repetitive, but I think we need metaprogramming or custom\n    -- tactics to address this.\n    theorem fuse_eq (v : \u2115 \u2192 \u2115) :\n    \u2200 e : aexpr, aeval v (fuse e) = aeval v e :=\n    begin\n        intro e,\n        induction e,\n            case const\n            { reflexivity },\n            case var\n            { reflexivity },\n            case plus : a b iha ihb\n            { cases a,\n              cases b,\n                reflexivity,\n                reflexivity,\n                {\n                    exact calc\n                    aeval v (fuse (plus (const a) (plus b_a b_a_1))) = aeval v (plus (fuse (const a)) (fuse (plus b_a b_a_1))) : rfl\n                        ... = aeval v (fuse (const a)) + aeval v (fuse (plus b_a b_a_1)) : rfl\n                        ... = aeval v (const a) + aeval v (plus b_a b_a_1) : by rw [iha, ihb]\n                        ... = aeval v (plus (const a) (plus b_a b_a_1)) : rfl\n                },\n                {\n                    exact calc\n                    aeval v (fuse (plus (const a) (times b_a b_a_1))) = aeval v (plus (fuse (const a)) (fuse (times b_a b_a_1))) : rfl\n                        ... = aeval v (fuse (const a)) + aeval v (fuse (times b_a b_a_1)) : rfl\n                        ... = aeval v (const a) + aeval v (times b_a b_a_1) : by rw [iha, ihb]\n                        ... = aeval v (plus (const a) (times b_a b_a_1)) : rfl\n                },\n                {\n                    exact calc\n                        aeval v (fuse (plus (var a) b)) = aeval v (plus (fuse (var a)) (fuse b)) : rfl\n                            ... = aeval v (fuse (var a)) + aeval v (fuse b) : rfl\n                            ... = aeval v (var a) + aeval v b : by rw [iha, ihb]\n                            ... = aeval v (plus (var a) b) : rfl\n                },\n                {\n                    exact calc\n                        aeval v (fuse (plus (plus a_a a_a_1) b)) = aeval v (plus (fuse (plus a_a a_a_1)) (fuse b)) : rfl\n                            ... = aeval v (fuse (plus a_a a_a_1)) + aeval v (fuse b) : rfl\n                            ... = aeval v (plus a_a a_a_1) + aeval v b : by rw [iha, ihb]\n                            ... = aeval v (plus (plus a_a a_a_1) b) : rfl\n                },\n                {\n                    exact calc\n                        aeval v (fuse (plus (times a_a a_a_1) b)) = aeval v (plus (fuse (times a_a a_a_1)) (fuse b)) : rfl\n                            ... = aeval v (fuse (times a_a a_a_1)) + aeval v (fuse b) : rfl\n                            ... = aeval v (times a_a a_a_1) + aeval v b : by rw [iha, ihb]\n                            ... = aeval v (plus (times a_a a_a_1) b) : rfl\n                },\n            },\n            case times : a b iha ihb\n            { cases a,\n              cases b,\n                reflexivity,\n                reflexivity,\n                {\n                    exact calc\n                    aeval v (fuse (times (const a) (plus b_a b_a_1))) = aeval v (times (fuse (const a)) (fuse (plus b_a b_a_1))) : rfl\n                        ... = aeval v (fuse (const a)) * aeval v (fuse (plus b_a b_a_1)) : rfl\n                        ... = aeval v (const a) * aeval v (plus b_a b_a_1) : by rw [iha, ihb]\n                        ... = aeval v (times (const a) (plus b_a b_a_1)) : rfl\n                },\n                {\n                    exact calc\n                    aeval v (fuse (times (const a) (times b_a b_a_1))) = aeval v (times (fuse (const a)) (fuse (times b_a b_a_1))) : rfl\n                        ... = aeval v (fuse (const a)) * aeval v (fuse (times b_a b_a_1)) : rfl\n                        ... = aeval v (const a) * aeval v (times b_a b_a_1) : by rw [iha, ihb]\n                        ... = aeval v (times (const a) (times b_a b_a_1)) : rfl\n                },\n                {\n                    exact calc\n                        aeval v (fuse (times (var a) b)) = aeval v (times (fuse (var a)) (fuse b)) : rfl\n                            ... = aeval v (fuse (var a)) * aeval v (fuse b) : rfl\n                            ... = aeval v (var a) * aeval v b : by rw [iha, ihb]\n                            ... = aeval v (times (var a) b) : rfl\n                },\n                {\n                    exact calc\n                        aeval v (fuse (times (plus a_a a_a_1) b)) = aeval v (times (fuse (plus a_a a_a_1)) (fuse b)) : rfl\n                            ... = aeval v (fuse (plus a_a a_a_1)) * aeval v (fuse b) : rfl\n                            ... = aeval v (plus a_a a_a_1) * aeval v b : by rw [iha, ihb]\n                            ... = aeval v (times (plus a_a a_a_1) b) : rfl\n                },\n                {\n                    exact calc\n                        aeval v (fuse (times (times a_a a_a_1) b)) = aeval v (times (fuse (times a_a a_a_1)) (fuse b)) : rfl\n                            ... = aeval v (fuse (times a_a a_a_1)) * aeval v (fuse b) : rfl\n                            ... = aeval v (times a_a a_a_1) * aeval v b : by rw [iha, ihb]\n                            ... = aeval v (times (times a_a a_a_1) b) : rfl\n                },\n            },\n    end\n\nend chap8ex6\n", "meta": {"author": "tomhoule", "repo": "theorem-proving-in-lean-exercises", "sha": "60ccc71b8a6df6924e7cc90aab713b804f78da9f", "save_path": "github-repos/lean/tomhoule-theorem-proving-in-lean-exercises", "path": "github-repos/lean/tomhoule-theorem-proving-in-lean-exercises/theorem-proving-in-lean-exercises-60ccc71b8a6df6924e7cc90aab713b804f78da9f/theorem-proving-in-lean/src/chap_8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7141624434735402}}
{"text": "import tutorial_world.incidenceplane --hide\nopen IncidencePlane --hide\n\n/- Axiom :\nincidence : P \u2260 Q \u2192 P \u2208 \u2113 \u2192 Q \u2208 \u2113 \u2192 \u2113 = line_through P Q\n-/\n\n/- Tactic : intro\n\n## Summary:\n\n`intro p` will turn a goal `\u22a2 P \u2192 Q` into a hypothesis `p : P`\nand goal `\u22a2 Q`. If `P` and `Q` are sets `intro p` means \"let $p$ be an arbitrary element of $P$\".\nIf `P` and `Q` are propositions then `intro p` says \"assume $P$ is true\". \n\n## Details\n\nIf your goal is a function or an implication `\u22a2 P \u2192 Q` then `intro`\nwill always make progress. `intro p` turns\n\n`\u22a2 P \u2192 Q`\n\ninto \n\n```\np : P\n\u22a2 Q\n```\n\nThe opposite tactic to intro is `revert`; given the situation\njust above, `revert p` turns the goal back into `\u22a2 P \u2192 Q`.\n\n**Variant:** Instead of calling `intro` multiple times, you can use\n`intros`. That is, `intros h\u2081 h\u2082` is equivalent to `intro h\u2081, intro h\u2082`.\n\n## Example\n\nIf your goal is an implication $P\\implies Q$ then Lean writes\nthis as `\u22a2 P \u2192 Q`, and `intro p,` can be thought of as meaning\n\"let $p$ be a proof of $P$\", or more informally \"let's assume that\n$P$ is true\". The goal changes to `\u22a2 Q` and the hypothesis `p : P`\nappears in the local context.\n\n-/\n\n/-\nThis level introduces the `intros` tactic. This allows you to introduce\na new hypothesis in the context. You can learn more about it in the side bar.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B : \u03a9} {r s : Line \u03a9} -- hide\n\n/- Lemma :\nIf two lines contain two distinct points, then they are the same\n-/\nlemma equal_lines_of_contain_two_points :\nA \u2260 B \u2192 A \u2208 r \u2192  A \u2208 s \u2192 B \u2208 r \u2192 B \u2208 s \u2192 \tr = s :=\nbegin\n  intros hAB hAr hAs hBr hBs,\n  rw incidence hAB hAr hBr,\n  rw incidence hAB hAs hBs,\n\n\n\n\nend\n\n", "meta": {"author": "mmasdeu", "repo": "hilbertgame", "sha": "0557019a1b7220bab7fe35729646c25bf73f0447", "save_path": "github-repos/lean/mmasdeu-hilbertgame", "path": "github-repos/lean/mmasdeu-hilbertgame/hilbertgame-0557019a1b7220bab7fe35729646c25bf73f0447/src/tutorial_world/level06_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7141327392816743}}
{"text": "import SciLean.Core.Functions\nimport SciLean.Tactic.AutoDiff.Main\n\nnamespace SciLean.Smooth\n\nvariable {\u03b1 \u03b2 \u03b3 : Type}\nvariable {X Y Z W : Type} [Vec X] [Vec Y] [Vec Z] [Vec W]\nvariable {Y\u2081 Y\u2082 : Type} [Vec Y\u2081] [Vec Y\u2082]\n\nset_option maxHeartbeats 900\nset_option synthInstance.maxHeartbeats 300\nset_option synthInstance.maxSize 50\n\n--- Test 0 \n\n-- We want to solve all these in a single pass i.e. linear complexity in the expression size\n-- macro \"diff_simp\" : tactic => `(tactic| simp) -- `(autodiff_core (config := {singlePas\n-- s := true}))\n\n-- I \nexample : \u2202 (\u03bb x : X => x) = \u03bb x dx => dx := by autodiff; done\n\n-- K \nexample : \u2202 (\u03bb (x : X) (y : Y) => x) = \u03bb x dx y => dx := by autodiff; done\nexample (x : X) : \u2202 (\u03bb (y : Y) => x) = \u03bb y dy => (0:X) := by autodiff; done \n\n-- B\nexample \n  : \u2202 (\u03bb (f : Y \u2192 Z) (g : X \u2192 Y) (x : X) => f (g x)) \n    = \n    \u03bb f df g x => df (g x) := by autodiff; done\nexample (f : Y \u2192 Z) [IsSmooth f] \n  : \u2202 (\u03bb (g : X \u2192 Y) (x : X) => f (g x)) \n    = \n    \u03bb g dg x => \u2202 f (g x) (dg x) := by autodiff; done\nexample (f : Y \u2192 Z) [IsSmooth f] \n  (g : X \u2192 Y) [IsSmooth g]\n  : \u2202 (\u03bb (x : X) => f (g x)) \n    = \n    \u03bb x dx => \u2202 f (g x) (\u2202 g x dx) := by autodiff; done\n\n-- C\n-- set_option trace.Meta.synthInstance true in\n-- set_option trace.Meta.Tactic.simp true in\n-- set_option trace.Meta.Tactic.simp.unify false in\nexample \n  : \u2202 (\u03bb (f : X \u2192 Y \u2192 Z) (y : Y) (x : X) => f x y)\n    =\n    \u03bb f df y x => df x y := by autodiff; done\nexample (f : X \u2192 Y \u2192 Z) [\u2200 x, IsSmooth (f x)]\n  : \u2202 (\u03bb (y : Y) (x : X) => f x y)\n    =\n    \u03bb y dy x => \u2202 (f x) y dy := by autodiff; done\nexample (f : X \u2192 Y \u2192 Z) [IsSmooth f] (y : Y)\n  : \u2202 (\u03bb (x : X) => f x y)\n    =\n    \u03bb x dx => \u2202 f x dx y := by autodiff; done\n\n-- S\n-- set_option trace.Meta.Tactic.simp true in\nexample \n  : \u2202 (\u03bb (f : X \u2192 Y \u2192 Z) (g : X \u2192 Y) (x : X) => f x (g x))\n    =\n    \u03bb f df g x => df x (g x) := by autodiff; done\nexample (f : X \u2192 Y \u2192 Z) [\u2200 x, IsSmooth (f x)]\n  : \u2202 (\u03bb (g : X \u2192 Y) (x : X) => f x (g x))\n    =\n    \u03bb g dg x => \u2202 (f x) (g x) (dg x) := by autodiff; done\nexample (f : X \u2192 Y \u2192 Z) [IsSmooth f] [\u2200 x, IsSmooth (f x)]\n  (g : X \u2192 Y) [IsSmooth g]\n  : \u2202 (\u03bb (x : X) => f x (g x))\n    =\n    \u03bb x dx => \u2202 f x dx (g x) + \u2202 (f x) (g x) (\u2202 g x dx) := by autodiff; done\n\n-- diff_of_diag\nexample \n  (f : Y\u2081 \u2192 Y\u2082 \u2192 Z) [IsSmooth f] [\u2200 y\u2081, IsSmooth (f y\u2081)]\n  (g\u2081 : X \u2192 Y\u2081) [IsSmooth g\u2081]\n  (g\u2082 : X \u2192 Y\u2082) [IsSmooth g\u2082]\n  : \u2202 (\u03bb x => f (g\u2081 x) (g\u2082 x)) \n    = \n    \u03bb x dx => \u2202 f (g\u2081 x) (\u2202 g\u2081 x dx) (g\u2082 x) + \n              \u2202 (f (g\u2081 x)) (g\u2082 x) (\u2202 g\u2082 x dx) := by autodiff; done\n\n-- diff_of_parm\nexample \n  (f : X \u2192 \u03b1 \u2192 Y) [IsSmooth f]\n  (a : \u03b1)\n  : \u2202 (\u03bb x => f x a) = \u03bb x dx => \u2202 f x dx a := by autodiff; done\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/test/test0_diff_1_core.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7141295351652631}}
{"text": "-- ----------------\n-- Demostrar que\n--    s \u2229 t = t \u2229 s\n-- ----------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t u : set \u03b1\n\nexample : s \u2229 t = t \u2229 s :=\nsorry\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/enunciados/Conmutatividad_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7141218699035143}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport data.real.basic -- imports the real numbers\nimport solutions.section02reals.sheet3 -- import the definition of `tendsto` from a previous sheet\n\n-- you can maybe do this one now\ntheorem tendsto_neg {a : \u2115 \u2192 \u211d} {t : \u211d} (ha : tendsto a t) :\n  tendsto (\u03bb n, - a n) (-t) :=\nbegin\n  sorry,\nend\n\n/-\n`tendsto_add` is quite a challenge. In a few weeks' time I'll\nshow you a two-line proof using filters, but right now\nas you're still learning I think it's important that you\ntry and suffer and struggle through the first principles proof.\nBIG piece of advice: write down a complete maths proof first,\nwith all the details there. Then, once you know the maths\nproof, try translating it into Lean. Note that a bunch\nof the results we proved in sheet 4 will be helpful. \n-/\n\n/-- If `a(n)` tends to `t` and `b(n)` tends to `u` then `a(n) + b(n)`\ntends to `t + u`. -/\ntheorem tendsto_add {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (\u03bb n, a n + b n) (t + u) :=\nbegin\n  sorry\nend\n\n/-- If `a(n)` tends to t and `b(n)` tends to `u` then `a(n) - b(n)`\ntends to `t - u`. -/\ntheorem tendsto_sub {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (\u03bb n, a n - b n) (t - u) :=\nbegin\n  -- this one follows without too much trouble from earlier results.\n  sorry\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section02reals/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7141053201979495}}
{"text": "/-\nThis file defines the at-most-k Boolean cardinality constraint.\n\nAuthors: Cayden Codel, Jeremy Avigad, Marijn Heule\nCarnegie Mellon University\n-/\n\nimport data.list.basic\nimport cnf.literal\nimport cnf.assignment\nimport cnf.clause\nimport cardinality.distinct\nimport cnf.encoding\n\nvariables {V : Type*} [decidable_eq V] [inhabited V]\n\nopen assignment\nopen clause\nopen list\nopen nat\nopen distinct\n\ndef amk (k : nat) : constraint := \u03bb (l : list bool), l.count tt \u2264 k\n\nnamespace amk\n\n@[simp] theorem amk_nil (k : nat) : amk k [] = tt := rfl\n\n@[simp] theorem amk_singleton_pos (k : nat) (b : bool) : amk (k + 1) [b] = tt :=\nby { cases b; simp [amk, count_singleton'] }\n\nvariables (k : nat) (\u03c4 : assignment V) (l : list (literal V)) (lit : literal V)\n\n@[simp] theorem eval_nil : (amk k).eval \u03c4 [] = tt :=\nby simp only [constraint.eval, amk, count_nil, to_bool_true_eq_tt, zero_le, map_nil]\n\n@[simp] theorem eval_singleton_pos : (amk (k + 1)).eval \u03c4 [lit] = tt :=\nby { cases h : lit.eval \u03c4; simp [constraint.eval, amk, count_singleton', h] }\n\n@[simp] theorem eval_singleton_zero : ((amk 0).eval \u03c4 [lit] = tt) \u2194 lit.eval \u03c4 = ff :=\nbegin\n  cases h : (lit.eval \u03c4),\n  { split,\n    { tautology },\n    { intro _, simp [constraint.eval, amk, h] } },\n  { split,\n    { intro hamk,\n      simp [constraint.eval, amk, h] at hamk,\n      contradiction },\n    { intro h, contradiction } }\nend\n\ntheorem eval_tt_of_ge_length {k : nat} {l : list (literal V)} :\n  k \u2265 length l \u2192 \u2200 (\u03c4 : assignment V), (amk k).eval \u03c4 l = tt :=\nbegin\n  intros hk \u03c4,\n  simp [constraint.eval, amk],\n  have := count_le_length tt (map (literal.eval \u03c4) l),\n  rw length_map at this,\n  exact le_trans this hk\nend\n\ntheorem eval_cons_pos {k : nat} {\u03c4 : assignment V} {lit : literal V} : \n  lit.eval \u03c4 = tt \u2192 \u2200 l, (amk (k + 1)).eval \u03c4 (lit :: l) = (amk k).eval \u03c4 l :=\nassume hlit l, by simp [constraint.eval, amk, hlit, succ_le_succ_iff]\n\ntheorem eval_cons_neg {\u03c4 : assignment V} {lit : literal V} :\n  lit.eval \u03c4 = ff \u2192 \u2200 k l, (amk k).eval \u03c4 (lit :: l) = (amk k).eval \u03c4 l :=\nassume hlit l, by simp [constraint.eval, amk, hlit]\n\ntheorem eval_tt_of_le_of_eval_tt {\u03c4 : assignment V} {l : list (literal V)} \n  {k\u2081 k\u2082 : nat} : k\u2081 \u2264 k\u2082 \u2192 (amk k\u2081).eval \u03c4 l = tt \u2192 (amk k\u2082).eval \u03c4 l = tt :=\nbegin\n  simp only [constraint.eval, amk, ge_iff_le, to_bool_iff],\n  intros hk h\u2081,\n  exact le_trans h\u2081 hk  \nend\n\ntheorem eval_sublist {k : nat} {\u03c4 : assignment V} {l\u2081 l\u2082 : list (literal V)} :\n  l\u2081 <+ l\u2082 \u2192 (amk k).eval \u03c4 l\u2082 = tt \u2192 (amk k).eval \u03c4 l\u2081 = tt :=\nbegin\n  simp [constraint.eval, amk],\n  intros hs h, \n  exact le_trans (sublist.count_le (sublist.map (literal.eval \u03c4) hs) tt) h\nend\n\ntheorem eval_drop {k : nat} {\u03c4 : assignment V} {l : list (literal V)} :\n  (amk k).eval \u03c4 l = tt \u2192 \u2200 (i : nat), (amk k).eval \u03c4 (l.drop i) = tt :=\nassume hamk i, eval_sublist (drop_sublist i l) hamk\n\ntheorem eval_take {k : nat} {\u03c4 : assignment V} {l : list (literal V)} :\n  (amk k).eval \u03c4 l = tt \u2192 \u2200 (i : nat), (amk k).eval \u03c4 (l.take i) = tt :=\nassume hamk i, eval_sublist (take_sublist i l) hamk \n\ntheorem eval_take_tail_pos {\u03c4 : assignment V} {l : list (literal V)} {i : nat} {Hi : i < length l} : \n  (l.nth_le i Hi).eval \u03c4 = tt \u2192 \u2200 (k : nat),\n  (amk (k + 1)).eval \u03c4 (l.take (i + 1)) = (amk k).eval \u03c4 (l.take i) :=\nbegin\n  intros hl k,\n  induction i with i ih generalizing l k,\n  { rw nth_le_zero at hl,\n    simp [take_one_of_ne_nil (ne_nil_of_length_pos Hi), hl, constraint.eval, amk] },\n  { rcases exists_cons_of_ne_nil (ne_nil_of_length_pos (pos_of_gt Hi)) with \u27e8l\u2081, ls, rfl\u27e9,\n    rw nth_le at hl,\n    cases h\u2081 : l\u2081.eval \u03c4,\n    { simp only [take, eval_cons_neg h\u2081, ih _ hl] },\n    { cases k,\n      { simp [constraint.eval, amk, h\u2081, succ_le_succ_iff],\n        simp at Hi,\n        have Hi' := (succ_lt_succ_iff.mp Hi),\n        use [ls.nth_le _ Hi', nth_le_mem_take_of_lt Hi' (lt_succ_self i), hl] },\n      { simp [take, eval_cons_pos h\u2081], exact ih _ hl } } }\nend\n\ntheorem eval_take_tail_neg {\u03c4 : assignment V} {l : list (literal V)} {i : nat} {Hi : i < length l} :\n  (l.nth_le i Hi).eval \u03c4 = ff \u2192 \u2200 (k : nat),\n  (amk k).eval \u03c4 (l.take (i + 1)) = (amk k).eval \u03c4 (l.take i) :=\nbegin\n  intros hl k,\n  induction i with i ih generalizing l k,\n  { rw nth_le_zero at hl,\n    simp [take_one_of_ne_nil (ne_nil_of_length_pos Hi), hl, constraint.eval, amk] },\n  { rcases exists_cons_of_ne_nil (ne_nil_of_length_pos (pos_of_gt Hi)) with \u27e8l\u2081, ls, rfl\u27e9,\n    rw nth_le at hl,\n    cases h\u2081 : l\u2081.eval \u03c4,\n    { simp [take, eval_cons_neg h\u2081, ih _ hl] },\n    { cases k,\n      { simp [take, constraint.eval, amk, h\u2081] },\n      { simp [take, eval_cons_pos h\u2081, ih _ hl] } } }\nend\n\ntheorem eval_tt_of_sublist_of_eval_tt {k : nat} {\u03c4 : assignment V} {l\u2081 l\u2082 : list (literal V)} :\n  l\u2081 <+ l\u2082 \u2192 (amk k).eval \u03c4 l\u2082 = tt \u2192 (amk k).eval \u03c4 l\u2081 = tt :=\nbegin\n  simp [constraint.eval, amk],\n  intros hls h\u2081,\n  exact le_trans (sublist.count_le (sublist.map (literal.eval \u03c4) hls) tt) h\u2081\nend\n\ntheorem eval_take_succ_tt_of_eval_take_tt {i k : nat} :\n  (amk k).eval \u03c4 (l.take (i + 1)) = tt \u2192 (amk k).eval \u03c4 (l.take i) = tt :=\n\u03bb h, eval_tt_of_sublist_of_eval_tt (take_sublist_of_le (le_succ i) l) h\n\n/-! # amz -/\n\ntheorem amz_of_amz_cons {\u03c4 : assignment V} {l : list (literal V)} {lit : literal V} :\n  (amk 0).eval \u03c4 (lit :: l) = tt \u2192 (amk 0).eval \u03c4 l = tt :=\nbegin\n  simp [constraint.eval, amk], cases literal.eval \u03c4 lit; simp\nend\n\n-- The special case where k = 0 is handled\ntheorem amz_eval_tt_iff_forall_eval_ff {\u03c4} {l} :\n  (amk 0).eval \u03c4 l = tt \u2194 (\u2200 \u2983lit : literal V\u2984, lit \u2208 l \u2192 lit.eval \u03c4 = ff) :=\nbegin\n  split,\n  { simp [constraint.eval, amk] },\n  { intro h,\n    rw [constraint.eval, amk, to_bool_iff, le_zero_iff],\n    apply count_eq_zero_of_not_mem,\n    simpa }\nend\n\n-- Can be done with contrapose, somehow\ntheorem amz_eval_ff_iff_exists_eval_tt :\n  (amk 0).eval \u03c4 l = ff \u2194 (\u2203 (lit : literal V), lit \u2208 l \u2227 lit.eval \u03c4 = tt) :=\nbegin\n  split,\n  { contrapose, simp, exact amz_eval_tt_iff_forall_eval_ff.mpr },\n  { contrapose, simp, exact amz_eval_tt_iff_forall_eval_ff.mp }\nend\n\ntheorem eval_cons_pos_zero {\u03c4 : assignment V} {lit : literal V} :\n  lit.eval \u03c4 = tt \u2192 \u2200 l, (amk 0).eval \u03c4 (lit :: l) = ff :=\nbegin\n  intros hlit l,\n  apply (amz_eval_ff_iff_exists_eval_tt \u03c4 (lit :: l)).mpr,\n  use [lit, mem_cons_self _ _, hlit]\nend\n\n-- Can probably be shortened with the correct order of cases\ntheorem exists_amk_split {k : nat} {\u03c4 : assignment V} {l : list (literal V)} : \n  (amk k).eval \u03c4 l = tt \u2192 \u2200 {k\u2081 k\u2082 : nat}, k\u2081 + k\u2082 = k \u2192 \n  \u2203 {l\u2081 l\u2082 : list (literal V)}, l\u2081 ++ l\u2082 = l \u2227\n  (amk k\u2081).eval \u03c4 l\u2081 = tt \u2227 (amk k\u2082).eval \u03c4 l\u2082 = tt :=\nbegin\n  intros hamk k\u2081 k\u2082 hks,\n  induction l with lit\u2081 ls ih generalizing k k\u2081 k\u2082,\n  { use [[], []],\n    simp },\n  { cases k,\n    { cases hlit\u2081 : (literal.eval \u03c4 lit\u2081),\n      { rw eval_cons_neg hlit\u2081 at hamk,\n        rcases ih hamk hks with \u27e8l\u2081, l\u2082, hls, hl\u2081, hl\u2082\u27e9,\n        use [(lit\u2081 :: l\u2081), l\u2082],\n        simp [hls, eval_cons_neg hlit\u2081, hl\u2081, hl\u2082] },\n      { rw [amz_eval_tt_iff_forall_eval_ff] at hamk,\n        rw (hamk (mem_cons_self lit\u2081 ls)) at hlit\u2081,\n        contradiction } },\n    { cases k\u2081,\n      { rw zero_add at hks, subst hks,\n        use [[], lit\u2081 :: ls],\n        simpa },\n      { cases hlit\u2081 : (literal.eval \u03c4 lit\u2081),\n        { rw eval_cons_neg hlit\u2081 at hamk,\n          rcases ih hamk hks with \u27e8l\u2081, l\u2082, hls, hl\u2081, hl\u2082\u27e9,\n          use [(lit\u2081 :: l\u2081), l\u2082],\n          simp [hls, eval_cons_neg hlit\u2081, hl\u2081, hl\u2082] },\n        { rw succ_add at hks,\n          rw eval_cons_pos hlit\u2081 at hamk,\n          rcases ih hamk (succ.inj hks) with \u27e8l\u2081, l\u2082, hls, hl\u2081, hl\u2082\u27e9,\n          use [(lit\u2081 :: l\u2081), l\u2082],\n          simp [hls, eval_cons_pos hlit\u2081, hl\u2081, hl\u2082] } } } }\nend\n\ntheorem eval_eq_of_agree_on {\u03c4\u2081 \u03c4\u2082 : assignment V} {l : list (literal V)} :\n  \u2200 (k : nat), (agree_on \u03c4\u2081 \u03c4\u2082 (clause.vars l)) \u2192 (amk k).eval \u03c4\u2081 l = (amk k).eval \u03c4\u2082 l :=\nbegin\n  intros k hagree_on,\n  induction l with l ls ih generalizing k,\n  { simp only [eval_nil] },\n  { have := eval_eq_of_agree_on_of_var_mem hagree_on (mem_vars_of_mem (mem_cons_self l ls)),\n    cases h : (l.eval \u03c4\u2081),\n    { rw eval_cons_neg h,\n      rw this at h,\n      rw eval_cons_neg h,\n      exact ih (agree_on_subset (vars_subset_of_vars_cons _ _) hagree_on) k },\n    { cases k,\n      { rw eval_cons_pos_zero h,\n        rw this at h,\n        rw eval_cons_pos_zero h },\n      { rw eval_cons_pos h,\n        rw this at h,\n        rw eval_cons_pos h,\n        exact ih (agree_on_subset (vars_subset_of_vars_cons _ _) hagree_on) k } } }\nend\n\n/-! # amo -/\n\ntheorem amo_eval_tt_iff_distinct_eval_ff_of_eval_tt \n  {\u03c4 : assignment V} {l : list (literal V)} :\n  (amk 1).eval \u03c4 l = tt \u2194 (\u2200 {lit\u2081 lit\u2082 : literal V}, \n  distinct lit\u2081 lit\u2082 l \u2192 lit\u2081.eval \u03c4 = tt \u2192 lit\u2082.eval \u03c4 = ff) :=\nbegin\n  induction l with l\u2081 ls ih,\n  { split,\n    { intros _ lit\u2081 lit\u2082 hdis,\n      exact absurd hdis (not_distinct_nil _ _) },\n    { rw eval_nil, tautology } },\n  { cases ls with l\u2082 ls,\n    { split,\n      { intros _ lit\u2081 lit\u2082 hdis,\n        exact absurd hdis (not_distinct_singleton _ _ _) },\n      { rw eval_singleton_pos, tautology } },\n    { split,\n      { intros heval lit\u2081 lit\u2082 hdis h\u2081,\n        have hmem\u2082 := mem_tail_of_distinct_cons hdis,\n        rcases hdis with \u27e8i, j, hi, hj, hij, hil, hjl\u27e9,\n        cases i,\n        { rw nth_le at hil,\n          rw [hil, eval_cons_pos h\u2081, amz_eval_tt_iff_forall_eval_ff] at heval,\n          exact heval hmem\u2082 },\n        { cases j,\n          { linarith },\n          { have : distinct lit\u2081 lit\u2082 (l\u2082 :: ls),\n            { rw [length, succ_lt_succ_iff] at hi hj,\n              rw succ_lt_succ_iff at hij,\n              rw nth_le at hil hjl,\n              exact \u27e8i, j, hi, hj, hij, hil, hjl\u27e9 },\n            cases h : (literal.eval \u03c4 l\u2081),\n            { rw eval_cons_neg h at heval,\n              exact ih.mp heval this h\u2081 },\n            { rw [eval_cons_pos h, amz_eval_tt_iff_forall_eval_ff] at heval,\n              exact heval hmem\u2082 } } } },\n      { intro h,\n        cases h\u2081 : (literal.eval \u03c4 l\u2081),\n        { rw eval_cons_neg h\u2081,\n          apply ih.mpr,\n          intros lit\u2081 lit\u2082 hdis' h\u2081',\n          exact h (distinct_cons_of_distinct l\u2081 hdis') h\u2081' },\n        { rw [eval_cons_pos h\u2081, amz_eval_tt_iff_forall_eval_ff],\n          intros x hx,\n          exact h (distinct_cons_of_mem l\u2081 hx) h\u2081 } } } }\nend\n\nend amk", "meta": {"author": "ccodel", "repo": "verified-encodings", "sha": "ee22a6a04ee56cc568f91fbee5a70d39e5e261f8", "save_path": "github-repos/lean/ccodel-verified-encodings", "path": "github-repos/lean/ccodel-verified-encodings/verified-encodings-ee22a6a04ee56cc568f91fbee5a70d39e5e261f8/src/cardinality/amk.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642804, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7140659847321899}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\nimport analysis.normed.ring.seminorm\nimport analysis.seminorm\n\n/-!\n# Nonarchimedean ring seminorms and algebra norms\n\nIn this file, we define some properties of functions (power-multiplicative, extends, \nnonarchimedean) which will be of special interest to us when applied to ring seminorms or\nadditive group seminorms.\n\nWe prove several properties of nonarchimedean functions.\n\nWe also define algebra norms and multiplicative algebra norms.\n\n## Main Definitions\n* `is_pow_mul` : `f : R \u2192 \u211d` is power-multiplicative if for all `r \u2208 R` and all positive `n \u2208 \u2115`,\n  `f (r ^ n) = (f r) ^ n`.\n* `function_extends` : given an `\u03b1`-algebra `\u03b2`, a function `f : \u03b2 \u2192 \u211d` extends a function \n  `g : \u03b1 \u2192 \u211d` if `\u2200 x : \u03b1, f (algebra_map \u03b1 \u03b2 x) = g x`. \n* `is_nonarchimedean`: a function `f : R \u2192 \u211d\u22650` is nonarchimedean if it satisfies the strong \n  triangle inequality `f (r + s) \u2264 max (f r) (f s)` for all `r s : R`.\n* `algebra_norm` : an algebra norm on an `R`-algebra norm `S` is a ring norm on `S` compatible with\n  the action of `R`.\n* `mul_algebra_norm` : amultiplicative algebra norm on an `R`-algebra norm `S` is a multiplicative\n  ring norm on `S` compatible with the action of `R`. \n\n## Main Results\n* `is_nonarchimedean_multiset_image_add` : given a nonarchimedean additive group seminorm `f` on \n  `\u03b1`, a function `g : \u03b2 \u2192 \u03b1` and a multiset `s : multiset \u03b2`, we can always find `b : \u03b2`, belonging\n  to `s` if `s` is nonempty, such that `f (t.sum g) \u2264 f (g b)` .\n\n## Tags\n\nnorm, nonarchimedean, pow_mul, power-multiplicative, algebra norm\n-/\n\nset_option old_structure_cmd true\n\nopen metric\n\nnamespace nat \n\nlemma one_div_cast_pos {n : \u2115} (hn : n \u2260 0) : 0 < 1/(n : \u211d) := \nbegin\n  rw [one_div, inv_pos, cast_pos],\n  exact nat.pos_of_ne_zero hn,  \nend\n\nlemma one_div_cast_nonneg (n : \u2115): 0 \u2264 1/(n : \u211d) := \nbegin\n  by_cases hn : n = 0,\n  { rw [hn, cast_zero, div_zero] },\n  { refine le_of_lt (one_div_cast_pos hn), }\nend\n\nlemma one_div_cast_ne_zero {n : \u2115} (hn : n \u2260 0) : 1/(n : \u211d) \u2260 0 := \nne_of_gt (one_div_cast_pos hn)\n\nend nat\n\n/-- A function `f : R \u2192 \u211d` is power-multiplicative if for all `r \u2208 R` and all positive `n \u2208 \u2115`,\n  `f (r ^ n) = (f r) ^ n`. -/\ndef is_pow_mul {R : Type*} [ring R] (f : R \u2192 \u211d) :=\n\u2200 (a : R) {n : \u2115} (hn : 1 \u2264 n), f (a^n) = (f a) ^ n\n\n/-- Given an `\u03b1`-algebra `\u03b2`, a function `f : \u03b2 \u2192 \u211d` extends a function `g : \u03b1 \u2192 \u211d` if \n  `\u2200 x : \u03b1, f (algebra_map \u03b1 \u03b2 x) = g x`. -/\ndef function_extends {\u03b1 : Type*} [comm_ring \u03b1] (g : \u03b1 \u2192 \u211d) {\u03b2 : Type*} [ring \u03b2] [algebra \u03b1 \u03b2]\n  (f : \u03b2 \u2192 \u211d) : Prop :=\n\u2200 x : \u03b1, f (algebra_map \u03b1 \u03b2 x) = g x \n\n/-- A function `f : R \u2192 \u211d\u22650` is nonarchimedean if it satisfies the strong triangle inequality\n  `f (r + s) \u2264 max (f r) (f s)` for all `r s : R`. -/\ndef is_nonarchimedean {R : Type*} [add_group R] (f : R \u2192 \u211d) : Prop := \n\u2200 r s, f (r + s) \u2264 max (f r) (f s)\n\n/-- A nonarchimedean function satisfies the triangle inequality. -/\nlemma add_le_of_is_nonarchimedean {\u03b1 : Type*} [add_comm_group \u03b1] {f : \u03b1 \u2192 \u211d} (hf : \u2200 x : \u03b1, 0 \u2264 f x)\n  (hna : is_nonarchimedean f) (a b : \u03b1) : f (a + b) \u2264 f a + f b :=\nbegin\n  apply le_trans (hna _ _),\n  rw [max_le_iff, le_add_iff_nonneg_right, le_add_iff_nonneg_left],\n  exact \u27e8hf _, hf _\u27e9,\nend\n\n/-- If `f` is a nonarchimedean additive group seminorm on `\u03b1`, then for every `n : \u2115` and `a : \u03b1`,\n  we have `f (n \u2022 a) \u2264 (f a)`. -/\nlemma is_nonarchimedean_nsmul {F \u03b1 : Type*} [add_comm_group \u03b1] [add_group_seminorm_class F \u03b1] \n  {f : F} (hna : is_nonarchimedean f) (n : \u2115) (a : \u03b1) : f (n \u2022 a) \u2264 (f a) := \nbegin\n  induction n with n hn,\n  { rw [zero_smul, (map_zero _)], exact map_nonneg _ _ },\n  { have : n.succ \u2022 a = (n + 1) \u2022 a := rfl,\n    rw [this, add_smul, one_smul],\n    exact le_trans (hna _ _) (max_le_iff.mpr \u27e8hn, le_refl _\u27e9) }\nend\n\n/-- If `f` is a nonarchimedean additive group seminorm on `\u03b1`, then for every `n : \u2115` and `a : \u03b1`,\n  we have `f (n * a) \u2264 (f a)`. -/\nlemma is_nonarchimedean_nmul {F \u03b1 : Type*} [ring \u03b1] [add_group_seminorm_class F \u03b1] {f : F}\n  (hna : is_nonarchimedean f) (n : \u2115) (a : \u03b1) : f (n * a) \u2264 (f a) := \nbegin\n  rw \u2190 nsmul_eq_mul,\n  exact is_nonarchimedean_nsmul hna _ _,\nend\n\n/-- If `f` is a nonarchimedean additive group seminorm on `\u03b1` and `x y : \u03b1` are such that\n  `f y \u2260 f x`, then `f (x + y) = max (f x) (f y)`. -/\nlemma is_nonarchimedean_add_eq_max_of_ne {F \u03b1 : Type*} [ring \u03b1] [add_group_seminorm_class F \u03b1]\n  {f : F} (hna : is_nonarchimedean f) {x y : \u03b1} (hne : f y \u2260 f x) :\n  f (x + y) = max (f x) (f y) :=\nbegin\n  wlog hle := le_total (f y) (f x) using [x y],\n  have hlt : f y < f x, from lt_of_le_of_ne hle hne,\n  have : f x \u2264 max (f (x + y)) (f y), from calc\n    f x = f (x + y + (-y)) : by rw [add_neg_cancel_right]\n               ... \u2264 max (f (x + y)) (f (-y)) : hna _ _\n               ... = max (f (x + y)) (f y) : by rw map_neg_eq_map f y,\n  have hnge : f y \u2264 f (x + y),\n  { apply le_of_not_gt,\n    intro hgt,\n    rw max_eq_right_of_lt hgt at this,\n    apply not_lt_of_ge this,\n    assumption },\n  have : f x \u2264 f (x + y), by rwa [max_eq_left hnge] at this,\n  apply le_antisymm,\n  { exact hna _ _ },\n  { rw max_eq_left_of_lt hlt,\n    assumption },\n  rw [add_comm, max_comm], exact this (ne.symm hne),\nend\n\nopen_locale classical\n\n/-- Given a nonarchimedean additive group seminorm `f` on `\u03b1`, a function `g : \u03b2 \u2192 \u03b1` and a finset\n  `t : finset \u03b2`, we can always find `b : \u03b2`, belonging to `t` if `t` is nonempty, such that\n  `f (t.sum g) \u2264 f (g b)` . -/\nlemma is_nonarchimedean_finset_image_add {F \u03b1 : Type*} [ring \u03b1] [add_group_seminorm_class F \u03b1]\n  {f : F} (hna : is_nonarchimedean f) {\u03b2 : Type*} [h\u03b2 : nonempty \u03b2] (g : \u03b2 \u2192 \u03b1) (t : finset \u03b2) :\n  \u2203 (b : \u03b2) (hb : t.nonempty \u2192 b \u2208 t), f (t.sum g) \u2264 f (g b) := \nbegin\n  apply finset.induction_on t,\n  { rw [finset.sum_empty],\n    refine \u27e8h\u03b2.some, by simp only [finset.not_nonempty_empty, is_empty.forall_iff], _\u27e9,\n    rw map_zero f, exact map_nonneg f _ },\n  { rintros a s has \u27e8M, hMs, hM\u27e9,\n    rw [finset.sum_insert has],\n    by_cases hMa : f (g M) \u2264 f (g a),\n    { refine \u27e8a, _, le_trans (hna _ _) (max_le_iff.mpr (\u27e8le_refl _,le_trans hM hMa\u27e9))\u27e9,\n      simp only [finset.nonempty_coe_sort, finset.insert_nonempty, finset.mem_insert,\n        eq_self_iff_true, true_or, forall_true_left] },\n    { rw not_le at hMa,\n      by_cases hs : s.nonempty,\n      { refine \u27e8M, _, le_trans (hna _ _)\n          (max_le_iff.mpr \u27e8le_of_lt hMa, hM\u27e9)\u27e9,\n        simp only [finset.nonempty_coe_sort, finset.insert_nonempty, finset.mem_insert,\n          forall_true_left],\n        exact or.intro_right _ (hMs hs)  },\n      { use a,\n        split,\n        { simp only [finset.insert_nonempty, finset.mem_insert, eq_self_iff_true, true_or,\n            forall_true_left] },\n          have h0 : f (s.sum g) = 0,\n          { rw [finset.not_nonempty_iff_eq_empty.mp hs, finset.sum_empty, map_zero] },\n          apply le_trans (hna _ _),\n          rw h0,\n          exact max_le_iff.mpr \u27e8le_refl _, map_nonneg _ _\u27e9 }}} \nend\n\n/-- Given a nonarchimedean additive group seminorm `f` on `\u03b1`, a function `g : \u03b2 \u2192 \u03b1` and a \n  multiset `s : multiset \u03b2`, we can always find `b : \u03b2`, belonging to `s` if `s` is nonempty, \n  such that `f (t.sum g) \u2264 f (g b)` . -/\nlemma is_nonarchimedean_multiset_image_add {F \u03b1 : Type*} [ring \u03b1] [add_group_seminorm_class F \u03b1]\n  {f : F} (hna : is_nonarchimedean f) {\u03b2 : Type*} [h\u03b2 : nonempty \u03b2] (g : \u03b2 \u2192 \u03b1) (s : multiset \u03b2) :\n  \u2203 (b : \u03b2) (hb : 0 < s.card \u2192 b \u2208 s), f ((multiset.map g s).sum) \u2264 f (g b) := \nbegin\n  apply multiset.induction_on s,\n  { rw [multiset.map_zero, multiset.sum_zero, multiset.card_zero, map_zero f],\n    refine \u27e8h\u03b2.some, by simp only [not_lt_zero', is_empty.forall_iff], map_nonneg _ _\u27e9 },\n  { rintros a t \u27e8M, hMs, hM\u27e9,\n    by_cases hMa : f (g M) \u2264 f (g a),\n    { refine \u27e8a, _, _\u27e9,\n      { simp only [multiset.card_cons, nat.succ_pos', multiset.mem_cons_self, forall_true_left] },\n      { rw [multiset.map_cons, multiset.sum_cons],\n        exact le_trans (hna _ _) (max_le_iff.mpr (\u27e8le_refl _,le_trans hM hMa\u27e9)), }},\n    { rw not_le at hMa,\n      by_cases ht : 0 < t.card,\n      { refine \u27e8M, _, _\u27e9,\n        { simp only [multiset.card_cons, nat.succ_pos', multiset.mem_cons, forall_true_left],\n          exact or.intro_right _ (hMs ht) },\n          rw [multiset.map_cons, multiset.sum_cons],\n          exact le_trans (hna _ _) (max_le_iff.mpr \u27e8le_of_lt hMa, hM\u27e9) },\n      { refine \u27e8a, _, _\u27e9,\n        { simp only [multiset.card_cons, nat.succ_pos', multiset.mem_cons_self, forall_true_left] },\n        { have h0 : f (multiset.map g t).sum = 0,\n          { simp only [not_lt, le_zero_iff, multiset.card_eq_zero] at ht,\n            rw [ht, multiset.map_zero, multiset.sum_zero, map_zero f] },\n          rw [multiset.map_cons, multiset.sum_cons],\n          apply le_trans (hna _ _),\n          rw h0,\n          exact max_le_iff.mpr \u27e8le_refl _, map_nonneg _ _\u27e9 }}}}\nend\n\n/-- Given a nonarchimedean additive group seminorm `f` on `\u03b1`, a number `n : \u2115` and a function \n  `g : \u2115 \u2192 \u03b1`, there exists `m : \u2115` such that `f ((finset.range n).sum g) \u2264 f (g m)`.\n  If `0 < n`, this `m` satisfies `m < n`. -/\nlemma is_nonarchimedean_finset_range_add_le {F \u03b1 : Type*} [ring \u03b1] [add_group_seminorm_class F \u03b1]\n  {f : F} (hna : is_nonarchimedean f) (n : \u2115) (g : \u2115 \u2192 \u03b1) : \u2203 (m : \u2115) (hm : 0 < n \u2192 m < n),\n  f ((finset.range n).sum g) \u2264 f (g m) :=\nbegin\n  obtain \u27e8m, hm, h\u27e9 := is_nonarchimedean_finset_image_add hna g (finset.range n),\n  rw [finset.nonempty_range_iff, \u2190 zero_lt_iff, finset.mem_range] at hm,\n  exact \u27e8m, hm, h\u27e9,\nend\n\n/-- If `f` is a nonarchimedean additive group seminorm on a commutative ring `\u03b1`, `n : \u2115`, and \n  `a b : \u03b1`, then we can find `m : \u2115` such that `m \u2264 n` and \n  `f ((a + b) ^ n) \u2264 (f (a ^ m)) * (f (b ^ (n - m)))`. -/\nlemma is_nonarchimedean_add_pow {F \u03b1 : Type*} [comm_ring \u03b1] [ring_seminorm_class F \u03b1] {f : F}\n  (hna : is_nonarchimedean f) (n : \u2115) (a b : \u03b1) :\n  \u2203 (m : \u2115) (hm : m \u2208 list.range(n + 1)), f ((a + b) ^ n) \u2264 (f (a ^ m)) * (f (b ^ (n - m))) :=\nbegin\n  obtain \u27e8m, hm_lt, hM\u27e9 := is_nonarchimedean_finset_image_add hna \n    (\u03bb (m : \u2115), a ^ m * b ^ (n - m) * \u2191(n.choose m)) (finset.range (n + 1)),\n  simp only [finset.nonempty_range_iff, ne.def, nat.succ_ne_zero, not_false_iff, finset.mem_range,\n    if_true, forall_true_left] at hm_lt,\n  refine \u27e8m, list.mem_range.mpr hm_lt, _\u27e9,\n  simp only [\u2190 add_pow] at hM,\n  rw mul_comm at hM,\n  exact le_trans hM (le_trans (is_nonarchimedean_nmul hna _ _) (map_mul_le_mul _ _ _)),\nend\n\n/-- If `f` is a ring seminorm on `a`, then `\u2200 {n : \u2115}, n \u2260 0 \u2192 f (a ^ n) \u2264 f a ^ n`. -/\nlemma map_pow_le_pow {F \u03b1 : Type*} [ring \u03b1] [ring_seminorm_class F \u03b1] (f : F) (a : \u03b1) :\n  \u2200 {n : \u2115}, n \u2260 0 \u2192 f (a ^ n) \u2264 f a ^ n\n| 0 h       := absurd rfl h\n| 1 h       := by simp only [pow_one]\n| (n + 2) h := by simp only [pow_succ _ (n + 1)]; exact le_trans (map_mul_le_mul f a _)\n                (mul_le_mul_of_nonneg_left (map_pow_le_pow n.succ_ne_zero) (map_nonneg f a))\n\n/-- If `f` is a ring seminorm on `a` with `f 1 \u2264 `, then `\u2200 (n : \u2115), f (a ^ n) \u2264 f a ^ n`. -/\nlemma map_pow_le_pow' {F \u03b1 : Type*} [ring \u03b1] [ring_seminorm_class F \u03b1] {f : F} (hf1 : f 1 \u2264 1) \n  (a : \u03b1) : \u2200 (n : \u2115), f (a ^ n) \u2264 f a ^ n\n| 0       := by simp only [pow_zero, hf1] \n| (n + 1) := by simp only [pow_succ _ n]; exact le_trans (map_mul_le_mul f a _)\n              (mul_le_mul_of_nonneg_left (map_pow_le_pow' n) (map_nonneg f a))\n\n/-- An algebra norm on an `R`-algebra norm `S` is a ring norm on `S` compatible with the\n  action of `R`. -/\nstructure algebra_norm (R : Type*) [semi_normed_comm_ring R] (S : Type*) [ring S] \n  [algebra R S] extends seminorm R S, ring_norm S\n\nattribute [nolint doc_blame] algebra_norm.to_seminorm algebra_norm.to_ring_norm\n\ninstance (K : Type*) [normed_field K] : inhabited (algebra_norm K K) := \n\u27e8{ to_fun   := norm,\n  map_zero' := norm_zero,\n  add_le'   := norm_add_le,\n  neg'      := norm_neg,\n  smul'     := norm_mul,\n  mul_le'   := norm_mul_le,\n  eq_zero_of_map_eq_zero' := \u03bb x, norm_eq_zero.mp}\u27e9\n\n/-- `algebra_norm_class F \u03b1` states that `F` is a type of algebra norms on the ring `\u03b2`.\nYou should extend this class when you extend `algebra_norm`. -/\nclass algebra_norm_class (F : Type*) (R : out_param $ Type*) [semi_normed_comm_ring R]\n  (S : out_param $ Type*) [ring S] [algebra R S]\n  extends seminorm_class F R S, ring_norm_class F S\n\n-- `R` is an `out_param`, so this is a false positive.\nattribute [nolint dangerous_instance] algebra_norm_class.to_ring_norm_class\n\nnamespace algebra_norm\n\nvariables {R : Type*} [semi_normed_comm_ring R]  {S : Type*} [ring S] [algebra R S]\n  {f : algebra_norm R S}\n\n/-- The ring_seminorm underlying an algebra norm. -/\ndef to_ring_seminorm (f : algebra_norm R S) : ring_seminorm S :=\nf.to_ring_norm.to_ring_seminorm\n\ninstance algebra_norm_class : algebra_norm_class (algebra_norm R S) R S :=\n{ coe := \u03bb f, f.to_fun,\n  coe_injective' :=  \u03bb f f' h, \n  begin\n    simp only [ring_norm.to_fun_eq_coe, fun_like.coe_fn_eq] at h,\n    cases f; cases f'; congr',\n  end,\n  map_zero := \u03bb f, f.map_zero',\n  map_add_le_add := \u03bb f, f.add_le',\n  map_mul_le_mul := \u03bb f, f.mul_le',\n  map_neg_eq_map := \u03bb f, f.neg',\n  eq_zero_of_map_eq_zero := \u03bb f, f.eq_zero_of_map_eq_zero',\n  map_smul_eq_mul := \u03bb f, f.smul' }\n\n/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`. -/\ninstance : has_coe_to_fun (algebra_norm R S) (\u03bb _, S \u2192 \u211d) := fun_like.has_coe_to_fun\n\n@[simp] lemma to_fun_eq_coe (p : algebra_norm R S) : p.to_fun = p := rfl\n\n@[ext] lemma ext {p q : algebra_norm R S} : (\u2200 x, p x = q x) \u2192 p = q := fun_like.ext p q\n\n/-- An `R`-algebra norm such that `f 1 = 1` extends the norm on `R`. -/\nlemma extends_norm' {f : algebra_norm R S} (hf1 : f 1 = 1) (a : R) : f (a \u2022 1) = \u2016 a \u2016   :=\nby rw [\u2190 mul_one \u2016 a \u2016 , \u2190 hf1]; exact f.smul' _ _\n\n/-- An `R`-algebra norm such that `f 1 = 1` extends the norm on `R`. -/\nlemma extends_norm {f : algebra_norm R S} (hf1 : f 1 = 1) (a : R) : \n  f (algebra_map R S a) = \u2016 a \u2016  :=\nby rw algebra.algebra_map_eq_smul_one; exact extends_norm' hf1 _\n\nend algebra_norm\n\n/-- A multiplicative algebra norm on an `R`-algebra norm `S` is a multiplicative ring norm on `S`\n  compatible with the action of `R`. -/\nstructure mul_algebra_norm (R : Type*) [semi_normed_comm_ring R] (S : Type*) [ring S] \n  [algebra R S] extends seminorm R S, mul_ring_norm S\n\nattribute [nolint doc_blame] mul_algebra_norm.to_seminorm mul_algebra_norm.to_mul_ring_norm\n\ninstance (K : Type*) [normed_field K] : inhabited (mul_algebra_norm K K) := \n\u27e8{ to_fun   := norm,\n  map_zero' := norm_zero,\n  add_le'   := norm_add_le,\n  neg'      := norm_neg,\n  smul'     := norm_mul,\n  map_one'  := norm_one,\n  map_mul'  := norm_mul,\n  eq_zero_of_map_eq_zero' := \u03bb x, norm_eq_zero.mp}\u27e9\n\n/-- `algebra_norm_class F \u03b1` states that `F` is a type of algebra norms on the ring `\u03b2`.\nYou should extend this class when you extend `algebra_norm`. -/\nclass mul_algebra_norm_class (F : Type*) (R : out_param $ Type*) [semi_normed_comm_ring R]\n  (S : out_param $ Type*) [ring S] [algebra R S]\n  extends seminorm_class F R S, mul_ring_norm_class F S\n\n-- `R` is an `out_param`, so this is a false positive.\nattribute [nolint dangerous_instance] mul_algebra_norm_class.to_mul_ring_norm_class\n\nnamespace mul_algebra_norm\n\nvariables {R S : out_param $ Type*} [semi_normed_comm_ring R] [ring S] [algebra R S]\n  {f : algebra_norm R S}\n\ninstance mul_algebra_norm_class : mul_algebra_norm_class (mul_algebra_norm R S) R S :=\n{ coe := \u03bb f, f.to_fun,\n  coe_injective' :=  \u03bb f f' h, \n  begin\n    simp only [ring_norm.to_fun_eq_coe, fun_like.coe_fn_eq] at h,\n    cases f; cases f'; congr',\n  end,\n  map_zero := \u03bb f, f.map_zero',\n  map_add_le_add := \u03bb f, f.add_le',\n  map_one := \u03bb f, f.map_one',\n  map_mul := \u03bb f, f.map_mul',\n  map_neg_eq_map := \u03bb f, f.neg',\n  eq_zero_of_map_eq_zero := \u03bb f, f.eq_zero_of_map_eq_zero',\n  map_smul_eq_mul := \u03bb f, f.smul' }\n\n/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`. -/\ninstance : has_coe_to_fun (mul_algebra_norm R S) (\u03bb _, S \u2192 \u211d) := fun_like.has_coe_to_fun\n\n@[simp] lemma to_fun_eq_coe (p : mul_algebra_norm R S) : p.to_fun = p := rfl\n\n@[ext] lemma ext {p q : mul_algebra_norm R S} : (\u2200 x, p x = q x) \u2192 p = q := fun_like.ext p q\n\n/-- A multiplicative `R`-algebra norm extends the norm on `R`. -/\nlemma extends_norm' (f : mul_algebra_norm R S) (a : R) : f (a \u2022 1) = \u2016 a \u2016  :=\nby rw [\u2190 mul_one \u2016 a \u2016, \u2190 f.map_one', \u2190 f.smul']; refl\n\n/-- A multiplicative `R`-algebra norm extends the norm on `R`. -/\nlemma extends_norm (f : mul_algebra_norm R S) (a : R) : \n  f (algebra_map R S a) = \u2016 a \u2016 :=\nby rw algebra.algebra_map_eq_smul_one; exact extends_norm' _ _\n\nend mul_algebra_norm\n\nnamespace mul_ring_norm\n\nvariables {R : Type*} [non_assoc_ring R] \n\n/-- The ring norm underlying a multiplicative ring norm. -/\ndef to_ring_norm (f : mul_ring_norm R) : ring_norm R :=\n{ to_fun    := f,\n  map_zero' := f.map_zero',\n  add_le'   := f.add_le',\n  neg'      := f.neg',\n  mul_le'   := \u03bb x y, le_of_eq (f.map_mul' x y),\n  eq_zero_of_map_eq_zero' := f.eq_zero_of_map_eq_zero' }\n\n/-- A multiplicative ring norm is power-multiplicative. -/\nlemma is_pow_mul {A : Type*} [ring A] (f : mul_ring_norm A) : is_pow_mul f := \u03bb x n hn,\nbegin\n  induction n with n ih,\n  { exfalso, linarith },\n  { by_cases hn1 : 1 \u2264 n,\n    { rw [pow_succ, pow_succ, map_mul, ih hn1] },\n    { rw [not_le, nat.lt_one_iff] at hn1,\n      rw [hn1, pow_one, pow_one], }}\nend\n\nend mul_ring_norm\n\n/-- The seminorm on a `semi_normed_ring`, as a `ring_seminorm`. -/\ndef seminormed_ring.to_ring_seminorm (R : Type*) [semi_normed_ring R] :\n  ring_seminorm R :=\n{ to_fun    := norm,\n  map_zero' := norm_zero,\n  add_le'   := norm_add_le,\n  mul_le'   := norm_mul_le,\n  neg'      := norm_neg, }\n\n/-- The norm on a `normed_ring`, as a `ring_norm`. -/\n@[simps] def normed_ring.to_ring_norm (R : Type*) [normed_ring R] :\n  ring_norm R :=\n{ to_fun    := norm,\n  map_zero' := norm_zero,\n  add_le'   := norm_add_le,\n  mul_le'   := norm_mul_le,\n  neg'      := norm_neg,\n  eq_zero_of_map_eq_zero' := \u03bb x hx, by { rw \u2190 norm_eq_zero, exact hx }}\n\n@[simp] lemma normed_ring.to_ring_norm_apply (R : Type*) [normed_ring R] (x : R):\n  (normed_ring.to_ring_norm R) x = \u2016 x \u2016 := rfl\n\n/-- The norm on a `normed_field`, as a `mul_ring_norm`. -/\ndef normed_field.to_mul_ring_norm (R : Type*) [normed_field R] :\n  mul_ring_norm R :=\n{ to_fun    := norm,\n  map_zero' := norm_zero,\n  map_one'  := norm_one,\n  add_le'   := norm_add_le,\n  map_mul'  := norm_mul,\n  neg'      := norm_neg,\n  eq_zero_of_map_eq_zero' := \u03bb x hx, by { rw \u2190 norm_eq_zero, exact hx }}\n", "meta": {"author": "mariainesdff", "repo": "local_fields", "sha": "53a20ab87cf8f6ab27eedef2d9da929898951d82", "save_path": "github-repos/lean/mariainesdff-local_fields", "path": "github-repos/lean/mariainesdff-local_fields/local_fields-53a20ab87cf8f6ab27eedef2d9da929898951d82/src/ring_seminorm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7140659785516629}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.measure_theory.outer_measure\nimport Mathlib.order.filter.countable_Inter\nimport Mathlib.data.set.accumulate\nimport Mathlib.PostPort\n\nuniverses u_6 l u_1 u_2 u_5 u_3 u_4 \n\nnamespace Mathlib\n\n/-!\n# Measure spaces\n\nGiven a measurable space `\u03b1`, a measure on `\u03b1` is a function that sends measurable sets to the\nextended nonnegative reals that satisfies the following conditions:\n1. `\u03bc \u2205 = 0`;\n2. `\u03bc` is countably additive. This means that the measure of a countable union of pairwise disjoint\n   sets is equal to the measure of the individual sets.\n\nEvery measure can be canonically extended to an outer measure, so that it assigns values to\nall subsets, not just the measurable subsets. On the other hand, a measure that is countably\nadditive on measurable sets can be restricted to measurable sets to obtain a measure.\nIn this file a measure is defined to be an outer measure that is countably additive on\nmeasurable sets, with the additional assumption that the outer measure is the canonical\nextension of the restricted measure.\n\nMeasures on `\u03b1` form a complete lattice, and are closed under scalar multiplication with `ennreal`.\n\nWe introduce the following typeclasses for measures:\n\n* `probability_measure \u03bc`: `\u03bc univ = 1`;\n* `finite_measure \u03bc`: `\u03bc univ < \u22a4`;\n* `sigma_finite \u03bc`: there exists a countable collection of measurable sets that cover `univ`\n  where `\u03bc` is finite;\n* `locally_finite_measure \u03bc` : `\u2200 x, \u2203 s \u2208 \ud835\udcdd x, \u03bc s < \u22a4`;\n* `has_no_atoms \u03bc` : `\u2200 x, \u03bc {x} = 0`; possibly should be redefined as\n  `\u2200 s, 0 < \u03bc s \u2192 \u2203 t \u2286 s, 0 < \u03bc t \u2227 \u03bc t < \u03bc s`.\n\nGiven a measure, the null sets are the sets where `\u03bc s = 0`, where `\u03bc` denotes the corresponding\nouter measure (so `s` might not be measurable). We can then define the completion of `\u03bc` as the\nmeasure on the least `\u03c3`-algebra that also contains all null sets, by defining the measure to be `0`\non the null sets.\n\n## Main statements\n\n* `completion` is the completion of a measure to all null measurable sets.\n* `measure.of_measurable` and `outer_measure.to_measure` are two important ways to define a measure.\n\n## Implementation notes\n\nGiven `\u03bc : measure \u03b1`, `\u03bc s` is the value of the *outer measure* applied to `s`.\nThis conveniently allows us to apply the measure to sets without proving that they are measurable.\nWe get countable subadditivity for all sets, but only countable additivity for measurable sets.\n\nYou often don't want to define a measure via its constructor.\nTwo ways that are sometimes more convenient:\n* `measure.of_measurable` is a way to define a measure by only giving its value on measurable sets\n  and proving the properties (1) and (2) mentioned above.\n* `outer_measure.to_measure` is a way of obtaining a measure from an outer measure by showing that\n  all measurable sets in the measurable space are Carath\u00e9odory measurable.\n\nTo prove that two measures are equal, there are multiple options:\n* `ext`: two measures are equal if they are equal on all measurable sets.\n* `ext_of_generate_from_of_Union`: two measures are equal if they are equal on a \u03c0-system generating\n  the measurable sets, if the \u03c0-system contains a spanning increasing sequence of sets where the\n  measures take finite value (in particular the measures are \u03c3-finite). This is a special case of the\n  more general `ext_of_generate_from_of_cover`\n* `ext_of_generate_finite`: two finite measures are equal if they are equal on a \u03c0-system\n  generating the measurable sets. This is a special case of `ext_of_generate_from_of_Union` using\n  `C \u222a {univ}`, but is easier to work with.\n\nA `measure_space` is a class that is a measurable space with a canonical measure.\nThe measure is denoted `volume`.\n\n## References\n\n* <https://en.wikipedia.org/wiki/Measure_(mathematics)>\n* <https://en.wikipedia.org/wiki/Complete_measure>\n* <https://en.wikipedia.org/wiki/Almost_everywhere>\n\n## Tags\n\nmeasure, almost everywhere, measure space, completion, null set, null measurable set\n-/\n\nnamespace measure_theory\n\n\n/-- A measure is defined to be an outer measure that is countably additive on\nmeasurable sets, with the additional assumption that the outer measure is the canonical\nextension of the restricted measure. -/\nstructure measure (\u03b1 : Type u_6) [measurable_space \u03b1] extends outer_measure \u03b1 where\n  m_Union :\n    \u2200 {f : \u2115 \u2192 set \u03b1},\n      (\u2200 (i : \u2115), is_measurable (f i)) \u2192\n        pairwise (disjoint on f) \u2192\n          outer_measure.measure_of _to_outer_measure (set.Union fun (i : \u2115) => f i) =\n            tsum fun (i : \u2115) => outer_measure.measure_of _to_outer_measure (f i)\n  trimmed : outer_measure.trim _to_outer_measure = _to_outer_measure\n\n/-- Measure projections for a measure space.\n\nFor measurable sets this returns the measure assigned by the `measure_of` field in `measure`.\nBut we can extend this to _all_ sets, but using the outer measure. This gives us monotonicity and\nsubadditivity for all sets.\n-/\nprotected instance measure.has_coe_to_fun {\u03b1 : Type u_1} [measurable_space \u03b1] :\n    has_coe_to_fun (measure \u03b1) :=\n  has_coe_to_fun.mk (fun (_x : measure \u03b1) => set \u03b1 \u2192 ennreal)\n    fun (m : measure \u03b1) => \u21d1(measure.to_outer_measure m)\n\nnamespace measure\n\n\n/-! ### General facts about measures -/\n\n/-- Obtain a measure by giving a countably additive function that sends `\u2205` to `0`. -/\ndef of_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] (m : (s : set \u03b1) \u2192 is_measurable s \u2192 ennreal)\n    (m0 : m \u2205 is_measurable.empty = 0)\n    (mU :\n      \u2200 {f : \u2115 \u2192 set \u03b1} (h : \u2200 (i : \u2115), is_measurable (f i)),\n        pairwise (disjoint on f) \u2192\n          m (set.Union fun (i : \u2115) => f i) (of_measurable._proof_1 h) =\n            tsum fun (i : \u2115) => m (f i) (h i)) :\n    measure \u03b1 :=\n  mk\n    (outer_measure.mk (outer_measure.measure_of (induced_outer_measure m is_measurable.empty m0))\n      sorry sorry sorry)\n    sorry sorry\n\ntheorem of_measurable_apply {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {m : (s : set \u03b1) \u2192 is_measurable s \u2192 ennreal} {m0 : m \u2205 is_measurable.empty = 0}\n    {mU :\n      \u2200 {f : \u2115 \u2192 set \u03b1} (h : \u2200 (i : \u2115), is_measurable (f i)),\n        pairwise (disjoint on f) \u2192\n          m (set.Union fun (i : \u2115) => f i) (is_measurable.Union h) =\n            tsum fun (i : \u2115) => m (f i) (h i)}\n    (s : set \u03b1) (hs : is_measurable s) : coe_fn (of_measurable m m0 mU) s = m s hs :=\n  induced_outer_measure_eq m0 mU hs\n\ntheorem to_outer_measure_injective {\u03b1 : Type u_1} [measurable_space \u03b1] :\n    function.injective to_outer_measure :=\n  sorry\n\ntheorem ext {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1} {\u03bc\u2082 : measure \u03b1}\n    (h : \u2200 (s : set \u03b1), is_measurable s \u2192 coe_fn \u03bc\u2081 s = coe_fn \u03bc\u2082 s) : \u03bc\u2081 = \u03bc\u2082 :=\n  sorry\n\ntheorem ext_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1} {\u03bc\u2082 : measure \u03b1} :\n    \u03bc\u2081 = \u03bc\u2082 \u2194 \u2200 (s : set \u03b1), is_measurable s \u2192 coe_fn \u03bc\u2081 s = coe_fn \u03bc\u2082 s :=\n  { mp :=\n      fun (\u1fb0 : \u03bc\u2081 = \u03bc\u2082) (s : set \u03b1) (hs : is_measurable s) => Eq._oldrec (Eq.refl (coe_fn \u03bc\u2081 s)) \u1fb0,\n    mpr := ext }\n\nend measure\n\n\n@[simp] theorem coe_to_outer_measure {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    \u21d1(measure.to_outer_measure \u03bc) = \u21d1\u03bc :=\n  rfl\n\ntheorem to_outer_measure_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} (s : set \u03b1) :\n    coe_fn (measure.to_outer_measure \u03bc) s = coe_fn \u03bc s :=\n  rfl\n\ntheorem measure_eq_trim {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} (s : set \u03b1) :\n    coe_fn \u03bc s = coe_fn (outer_measure.trim (measure.to_outer_measure \u03bc)) s :=\n  sorry\n\ntheorem measure_eq_infi {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} (s : set \u03b1) :\n    coe_fn \u03bc s =\n        infi\n          fun (t : set \u03b1) =>\n            infi fun (st : s \u2286 t) => infi fun (ht : is_measurable t) => coe_fn \u03bc t :=\n  sorry\n\n/-- A variant of `measure_eq_infi` which has a single `infi`. This is useful when applying a\n  lemma next that only works for non-empty infima, in which case you can use\n  `nonempty_measurable_superset`. -/\ntheorem measure_eq_infi' {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) (s : set \u03b1) :\n    coe_fn \u03bc s = infi fun (t : Subtype fun (t : set \u03b1) => s \u2286 t \u2227 is_measurable t) => coe_fn \u03bc \u2191t :=\n  sorry\n\ntheorem measure_eq_induced_outer_measure {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b1} :\n    coe_fn \u03bc s =\n        coe_fn\n          (induced_outer_measure (fun (s : set \u03b1) (_x : is_measurable s) => coe_fn \u03bc s)\n            is_measurable.empty (outer_measure.empty (measure.to_outer_measure \u03bc)))\n          s :=\n  measure_eq_trim s\n\ntheorem to_outer_measure_eq_induced_outer_measure {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} :\n    measure.to_outer_measure \u03bc =\n        induced_outer_measure (fun (s : set \u03b1) (_x : is_measurable s) => coe_fn \u03bc s)\n          is_measurable.empty (outer_measure.empty (measure.to_outer_measure \u03bc)) :=\n  Eq.symm (measure.trimmed \u03bc)\n\ntheorem measure_eq_extend {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    (hs : is_measurable s) :\n    coe_fn \u03bc s = extend (fun (t : set \u03b1) (ht : is_measurable t) => coe_fn \u03bc t) s :=\n  sorry\n\n@[simp] theorem measure_empty {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    coe_fn \u03bc \u2205 = 0 :=\n  outer_measure.empty (measure.to_outer_measure \u03bc)\n\ntheorem nonempty_of_measure_ne_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    (h : coe_fn \u03bc s \u2260 0) : set.nonempty s :=\n  iff.mp set.ne_empty_iff_nonempty fun (h' : s = \u2205) => h (Eq.symm h' \u25b8 measure_empty)\n\ntheorem measure_mono {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s\u2081 : set \u03b1} {s\u2082 : set \u03b1}\n    (h : s\u2081 \u2286 s\u2082) : coe_fn \u03bc s\u2081 \u2264 coe_fn \u03bc s\u2082 :=\n  outer_measure.mono (measure.to_outer_measure \u03bc) h\n\ntheorem measure_mono_null {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s\u2081 : set \u03b1}\n    {s\u2082 : set \u03b1} (h : s\u2081 \u2286 s\u2082) (h\u2082 : coe_fn \u03bc s\u2082 = 0) : coe_fn \u03bc s\u2081 = 0 :=\n  iff.mp nonpos_iff_eq_zero (h\u2082 \u25b8 measure_mono h)\n\ntheorem measure_mono_top {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s\u2081 : set \u03b1}\n    {s\u2082 : set \u03b1} (h : s\u2081 \u2286 s\u2082) (h\u2081 : coe_fn \u03bc s\u2081 = \u22a4) : coe_fn \u03bc s\u2082 = \u22a4 :=\n  top_unique (h\u2081 \u25b8 measure_mono h)\n\ntheorem exists_is_measurable_superset {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    (s : set \u03b1) : \u2203 (t : set \u03b1), s \u2286 t \u2227 is_measurable t \u2227 coe_fn \u03bc t = coe_fn \u03bc s :=\n  sorry\n\n/-- A measurable set `t \u2287 s` such that `\u03bc t = \u03bc s`. -/\ndef to_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) (s : set \u03b1) : set \u03b1 :=\n  classical.some (exists_is_measurable_superset \u03bc s)\n\ntheorem subset_to_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) (s : set \u03b1) :\n    s \u2286 to_measurable \u03bc s :=\n  and.left (classical.some_spec (exists_is_measurable_superset \u03bc s))\n\n@[simp] theorem is_measurable_to_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    (s : set \u03b1) : is_measurable (to_measurable \u03bc s) :=\n  and.left (and.right (classical.some_spec (exists_is_measurable_superset \u03bc s)))\n\n@[simp] theorem measure_to_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    (s : set \u03b1) : coe_fn \u03bc (to_measurable \u03bc s) = coe_fn \u03bc s :=\n  and.right (and.right (classical.some_spec (exists_is_measurable_superset \u03bc s)))\n\ntheorem exists_is_measurable_superset_of_null {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b1} (h : coe_fn \u03bc s = 0) : \u2203 (t : set \u03b1), s \u2286 t \u2227 is_measurable t \u2227 coe_fn \u03bc t = 0 :=\n  sorry\n\ntheorem exists_is_measurable_superset_iff_measure_eq_zero {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} {s : set \u03b1} :\n    (\u2203 (t : set \u03b1), s \u2286 t \u2227 is_measurable t \u2227 coe_fn \u03bc t = 0) \u2194 coe_fn \u03bc s = 0 :=\n  sorry\n\ntheorem measure_Union_le {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b2] (s : \u03b2 \u2192 set \u03b1) :\n    coe_fn \u03bc (set.Union fun (i : \u03b2) => s i) \u2264 tsum fun (i : \u03b2) => coe_fn \u03bc (s i) :=\n  outer_measure.Union (measure.to_outer_measure \u03bc) fun (i : \u03b2) => s i\n\ntheorem measure_bUnion_le {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b2} (hs : set.countable s) (f : \u03b2 \u2192 set \u03b1) :\n    coe_fn \u03bc (set.Union fun (b : \u03b2) => set.Union fun (H : b \u2208 s) => f b) \u2264\n        tsum fun (p : \u21a5s) => coe_fn \u03bc (f \u2191p) :=\n  sorry\n\ntheorem measure_bUnion_finset_le {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    (s : finset \u03b2) (f : \u03b2 \u2192 set \u03b1) :\n    coe_fn \u03bc (set.Union fun (b : \u03b2) => set.Union fun (H : b \u2208 s) => f b) \u2264\n        finset.sum s fun (p : \u03b2) => coe_fn \u03bc (f p) :=\n  sorry\n\ntheorem measure_bUnion_lt_top {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b2} {f : \u03b2 \u2192 set \u03b1} (hs : set.finite s) (hfin : \u2200 (i : \u03b2), i \u2208 s \u2192 coe_fn \u03bc (f i) < \u22a4) :\n    coe_fn \u03bc (set.Union fun (i : \u03b2) => set.Union fun (H : i \u2208 s) => f i) < \u22a4 :=\n  sorry\n\ntheorem measure_Union_null {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b2] {s : \u03b2 \u2192 set \u03b1} :\n    (\u2200 (i : \u03b2), coe_fn \u03bc (s i) = 0) \u2192 coe_fn \u03bc (set.Union fun (i : \u03b2) => s i) = 0 :=\n  outer_measure.Union_null (measure.to_outer_measure \u03bc)\n\ntheorem measure_Union_null_iff {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} :\n    coe_fn \u03bc (set.Union fun (i : \u03b9) => s i) = 0 \u2194 \u2200 (i : \u03b9), coe_fn \u03bc (s i) = 0 :=\n  { mp :=\n      fun (h : coe_fn \u03bc (set.Union fun (i : \u03b9) => s i) = 0) (i : \u03b9) =>\n        measure_mono_null (set.subset_Union s i) h,\n    mpr := measure_Union_null }\n\ntheorem measure_union_le {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} (s\u2081 : set \u03b1)\n    (s\u2082 : set \u03b1) : coe_fn \u03bc (s\u2081 \u222a s\u2082) \u2264 coe_fn \u03bc s\u2081 + coe_fn \u03bc s\u2082 :=\n  outer_measure.union (measure.to_outer_measure \u03bc) s\u2081 s\u2082\n\ntheorem measure_union_null {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s\u2081 : set \u03b1}\n    {s\u2082 : set \u03b1} : coe_fn \u03bc s\u2081 = 0 \u2192 coe_fn \u03bc s\u2082 = 0 \u2192 coe_fn \u03bc (s\u2081 \u222a s\u2082) = 0 :=\n  outer_measure.union_null (measure.to_outer_measure \u03bc)\n\ntheorem measure_union_null_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s\u2081 : set \u03b1}\n    {s\u2082 : set \u03b1} : coe_fn \u03bc (s\u2081 \u222a s\u2082) = 0 \u2194 coe_fn \u03bc s\u2081 = 0 \u2227 coe_fn \u03bc s\u2082 = 0 :=\n  sorry\n\ntheorem measure_Union {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b2] {f : \u03b2 \u2192 set \u03b1} (hn : pairwise (disjoint on f))\n    (h : \u2200 (i : \u03b2), is_measurable (f i)) :\n    coe_fn \u03bc (set.Union fun (i : \u03b2) => f i) = tsum fun (i : \u03b2) => coe_fn \u03bc (f i) :=\n  sorry\n\ntheorem measure_union {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s\u2081 : set \u03b1} {s\u2082 : set \u03b1}\n    (hd : disjoint s\u2081 s\u2082) (h\u2081 : is_measurable s\u2081) (h\u2082 : is_measurable s\u2082) :\n    coe_fn \u03bc (s\u2081 \u222a s\u2082) = coe_fn \u03bc s\u2081 + coe_fn \u03bc s\u2082 :=\n  sorry\n\ntheorem measure_bUnion {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b2} {f : \u03b2 \u2192 set \u03b1} (hs : set.countable s) (hd : set.pairwise_on s (disjoint on f))\n    (h : \u2200 (b : \u03b2), b \u2208 s \u2192 is_measurable (f b)) :\n    coe_fn \u03bc (set.Union fun (b : \u03b2) => set.Union fun (H : b \u2208 s) => f b) =\n        tsum fun (p : \u21a5s) => coe_fn \u03bc (f \u2191p) :=\n  sorry\n\ntheorem measure_sUnion {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {S : set (set \u03b1)}\n    (hs : set.countable S) (hd : set.pairwise_on S disjoint)\n    (h : \u2200 (s : set \u03b1), s \u2208 S \u2192 is_measurable s) :\n    coe_fn \u03bc (\u22c3\u2080S) = tsum fun (s : \u21a5S) => coe_fn \u03bc \u2191s :=\n  sorry\n\ntheorem measure_bUnion_finset {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : finset \u03b9} {f : \u03b9 \u2192 set \u03b1} (hd : set.pairwise_on (\u2191s) (disjoint on f))\n    (hm : \u2200 (b : \u03b9), b \u2208 s \u2192 is_measurable (f b)) :\n    coe_fn \u03bc (set.Union fun (b : \u03b9) => set.Union fun (H : b \u2208 s) => f b) =\n        finset.sum s fun (p : \u03b9) => coe_fn \u03bc (f p) :=\n  sorry\n\n/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures\nof the fibers `f \u207b\u00b9' {y}`. -/\ntheorem tsum_measure_preimage_singleton {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} {s : set \u03b2} (hs : set.countable s) {f : \u03b1 \u2192 \u03b2}\n    (hf : \u2200 (y : \u03b2), y \u2208 s \u2192 is_measurable (f \u207b\u00b9' singleton y)) :\n    (tsum fun (b : \u21a5s) => coe_fn \u03bc (f \u207b\u00b9' singleton \u2191b)) = coe_fn \u03bc (f \u207b\u00b9' s) :=\n  sorry\n\n/-- If `s` is a `finset`, then the measure of its preimage can be found as the sum of measures\nof the fibers `f \u207b\u00b9' {y}`. -/\ntheorem sum_measure_preimage_singleton {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} (s : finset \u03b2) {f : \u03b1 \u2192 \u03b2}\n    (hf : \u2200 (y : \u03b2), y \u2208 s \u2192 is_measurable (f \u207b\u00b9' singleton y)) :\n    (finset.sum s fun (b : \u03b2) => coe_fn \u03bc (f \u207b\u00b9' singleton b)) = coe_fn \u03bc (f \u207b\u00b9' \u2191s) :=\n  sorry\n\ntheorem measure_diff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s\u2081 : set \u03b1} {s\u2082 : set \u03b1}\n    (h : s\u2082 \u2286 s\u2081) (h\u2081 : is_measurable s\u2081) (h\u2082 : is_measurable s\u2082) (h_fin : coe_fn \u03bc s\u2082 < \u22a4) :\n    coe_fn \u03bc (s\u2081 \\ s\u2082) = coe_fn \u03bc s\u2081 - coe_fn \u03bc s\u2082 :=\n  sorry\n\ntheorem measure_compl {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    (h\u2081 : is_measurable s) (h_fin : coe_fn \u03bc s < \u22a4) :\n    coe_fn \u03bc (s\u1d9c) = coe_fn \u03bc set.univ - coe_fn \u03bc s :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (coe_fn \u03bc (s\u1d9c) = coe_fn \u03bc set.univ - coe_fn \u03bc s))\n        (set.compl_eq_univ_diff s)))\n    (measure_diff (set.subset_univ s) is_measurable.univ h\u2081 h_fin)\n\ntheorem sum_measure_le_measure_univ {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} {s : finset \u03b9} {t : \u03b9 \u2192 set \u03b1} (h : \u2200 (i : \u03b9), i \u2208 s \u2192 is_measurable (t i))\n    (H : set.pairwise_on (\u2191s) (disjoint on t)) :\n    (finset.sum s fun (i : \u03b9) => coe_fn \u03bc (t i)) \u2264 coe_fn \u03bc set.univ :=\n  sorry\n\ntheorem tsum_measure_le_measure_univ {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} {s : \u03b9 \u2192 set \u03b1} (hs : \u2200 (i : \u03b9), is_measurable (s i))\n    (H : pairwise (disjoint on s)) : (tsum fun (i : \u03b9) => coe_fn \u03bc (s i)) \u2264 coe_fn \u03bc set.univ :=\n  sorry\n\n/-- Pigeonhole principle for measure spaces: if `\u2211' i, \u03bc (s i) > \u03bc univ`, then\none of the intersections `s i \u2229 s j` is not empty. -/\ntheorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {\u03b1 : Type u_1} {\u03b9 : Type u_5}\n    [measurable_space \u03b1] (\u03bc : measure \u03b1) {s : \u03b9 \u2192 set \u03b1} (hs : \u2200 (i : \u03b9), is_measurable (s i))\n    (H : coe_fn \u03bc set.univ < tsum fun (i : \u03b9) => coe_fn \u03bc (s i)) :\n    \u2203 (i : \u03b9), \u2203 (j : \u03b9), \u2203 (h : i \u2260 j), set.nonempty (s i \u2229 s j) :=\n  sorry\n\n/-- Pigeonhole principle for measure spaces: if `s` is a `finset` and\n`\u2211 i in s, \u03bc (t i) > \u03bc univ`, then one of the intersections `t i \u2229 t j` is not empty. -/\ntheorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {\u03b1 : Type u_1} {\u03b9 : Type u_5}\n    [measurable_space \u03b1] (\u03bc : measure \u03b1) {s : finset \u03b9} {t : \u03b9 \u2192 set \u03b1}\n    (h : \u2200 (i : \u03b9), i \u2208 s \u2192 is_measurable (t i))\n    (H : coe_fn \u03bc set.univ < finset.sum s fun (i : \u03b9) => coe_fn \u03bc (t i)) :\n    \u2203 (i : \u03b9), \u2203 (H : i \u2208 s), \u2203 (j : \u03b9), \u2203 (H : j \u2208 s), \u2203 (h : i \u2260 j), set.nonempty (t i \u2229 t j) :=\n  sorry\n\n/-- Continuity from below: the measure of the union of a directed sequence of measurable sets\nis the supremum of the measures. -/\ntheorem measure_Union_eq_supr {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (h : \u2200 (i : \u03b9), is_measurable (s i))\n    (hd : directed has_subset.subset s) :\n    coe_fn \u03bc (set.Union fun (i : \u03b9) => s i) = supr fun (i : \u03b9) => coe_fn \u03bc (s i) :=\n  sorry\n\ntheorem measure_bUnion_eq_supr {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : \u03b9 \u2192 set \u03b1} {t : set \u03b9} (ht : set.countable t) (h : \u2200 (i : \u03b9), i \u2208 t \u2192 is_measurable (s i))\n    (hd : directed_on (has_subset.subset on s) t) :\n    coe_fn \u03bc (set.Union fun (i : \u03b9) => set.Union fun (H : i \u2208 t) => s i) =\n        supr fun (i : \u03b9) => supr fun (H : i \u2208 t) => coe_fn \u03bc (s i) :=\n  sorry\n\n/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable\nsets is the infimum of the measures. -/\ntheorem measure_Inter_eq_infi {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (h : \u2200 (i : \u03b9), is_measurable (s i)) (hd : directed superset s)\n    (hfin : \u2203 (i : \u03b9), coe_fn \u03bc (s i) < \u22a4) :\n    coe_fn \u03bc (set.Inter fun (i : \u03b9) => s i) = infi fun (i : \u03b9) => coe_fn \u03bc (s i) :=\n  sorry\n\ntheorem measure_eq_inter_diff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (hs : is_measurable s) (ht : is_measurable t) :\n    coe_fn \u03bc s = coe_fn \u03bc (s \u2229 t) + coe_fn \u03bc (s \\ t) :=\n  sorry\n\ntheorem measure_union_add_inter {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (hs : is_measurable s) (ht : is_measurable t) :\n    coe_fn \u03bc (s \u222a t) + coe_fn \u03bc (s \u2229 t) = coe_fn \u03bc s + coe_fn \u03bc t :=\n  sorry\n\n/-- Continuity from below: the measure of the union of an increasing sequence of measurable sets\nis the limit of the measures. -/\ntheorem tendsto_measure_Union {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : \u2115 \u2192 set \u03b1}\n    (hs : \u2200 (n : \u2115), is_measurable (s n)) (hm : monotone s) :\n    filter.tendsto (\u21d1\u03bc \u2218 s) filter.at_top (nhds (coe_fn \u03bc (set.Union fun (n : \u2115) => s n))) :=\n  sorry\n\n/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable\nsets is the limit of the measures. -/\ntheorem tendsto_measure_Inter {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : \u2115 \u2192 set \u03b1}\n    (hs : \u2200 (n : \u2115), is_measurable (s n)) (hm : \u2200 {n m : \u2115}, n \u2264 m \u2192 s m \u2286 s n)\n    (hf : \u2203 (i : \u2115), coe_fn \u03bc (s i) < \u22a4) :\n    filter.tendsto (\u21d1\u03bc \u2218 s) filter.at_top (nhds (coe_fn \u03bc (set.Inter fun (n : \u2115) => s n))) :=\n  sorry\n\n/-- One direction of the Borel-Cantelli lemma: if (s\u1d62) is a sequence of measurable sets such that\n  \u2211 \u03bc s\u1d62 exists, then the limit superior of the s\u1d62 is a null set. -/\ntheorem measure_limsup_eq_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : \u2115 \u2192 set \u03b1}\n    (hs : \u2200 (i : \u2115), is_measurable (s i)) (hs' : (tsum fun (i : \u2115) => coe_fn \u03bc (s i)) \u2260 \u22a4) :\n    coe_fn \u03bc (filter.limsup filter.at_top s) = 0 :=\n  sorry\n\ntheorem measure_if {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] {x : \u03b2} {t : set \u03b2}\n    {s : set \u03b1} {\u03bc : measure \u03b1} :\n    coe_fn \u03bc (ite (x \u2208 t) s \u2205) = set.indicator t (fun (_x : \u03b2) => coe_fn \u03bc s) x :=\n  sorry\n\n/-- Obtain a measure by giving an outer measure where all sets in the \u03c3-algebra are\n  Carath\u00e9odory measurable. -/\ndef outer_measure.to_measure {\u03b1 : Type u_1} [ms : measurable_space \u03b1] (m : outer_measure \u03b1)\n    (h : ms \u2264 outer_measure.caratheodory m) : measure \u03b1 :=\n  measure.of_measurable (fun (s : set \u03b1) (_x : is_measurable s) => coe_fn m s)\n    (outer_measure.empty m) sorry\n\ntheorem le_to_outer_measure_caratheodory {\u03b1 : Type u_1} [ms : measurable_space \u03b1] (\u03bc : measure \u03b1) :\n    ms \u2264 outer_measure.caratheodory (measure.to_outer_measure \u03bc) :=\n  sorry\n\n@[simp] theorem to_measure_to_outer_measure {\u03b1 : Type u_1} [ms : measurable_space \u03b1]\n    (m : outer_measure \u03b1) (h : ms \u2264 outer_measure.caratheodory m) :\n    measure.to_outer_measure (outer_measure.to_measure m h) = outer_measure.trim m :=\n  rfl\n\n@[simp] theorem to_measure_apply {\u03b1 : Type u_1} [ms : measurable_space \u03b1] (m : outer_measure \u03b1)\n    (h : ms \u2264 outer_measure.caratheodory m) {s : set \u03b1} (hs : is_measurable s) :\n    coe_fn (outer_measure.to_measure m h) s = coe_fn m s :=\n  outer_measure.trim_eq m hs\n\ntheorem le_to_measure_apply {\u03b1 : Type u_1} [ms : measurable_space \u03b1] (m : outer_measure \u03b1)\n    (h : ms \u2264 outer_measure.caratheodory m) (s : set \u03b1) :\n    coe_fn m s \u2264 coe_fn (outer_measure.to_measure m h) s :=\n  outer_measure.le_trim m s\n\n@[simp] theorem to_outer_measure_to_measure {\u03b1 : Type u_1} [ms : measurable_space \u03b1]\n    {\u03bc : measure \u03b1} :\n    outer_measure.to_measure (measure.to_outer_measure \u03bc) (le_to_outer_measure_caratheodory \u03bc) =\n        \u03bc :=\n  measure.ext fun (s : set \u03b1) => outer_measure.trim_eq (measure.to_outer_measure \u03bc)\n\nnamespace measure\n\n\nprotected theorem caratheodory {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} {t : set \u03b1}\n    (\u03bc : measure \u03b1) (hs : is_measurable s) : coe_fn \u03bc (t \u2229 s) + coe_fn \u03bc (t \\ s) = coe_fn \u03bc t :=\n  Eq.symm (le_to_outer_measure_caratheodory \u03bc s hs t)\n\n/-! ### The `ennreal`-module of measures -/\n\nprotected instance has_zero {\u03b1 : Type u_1} [measurable_space \u03b1] : HasZero (measure \u03b1) :=\n  { zero := mk 0 sorry outer_measure.trim_zero }\n\n@[simp] theorem zero_to_outer_measure {\u03b1 : Type u_1} [measurable_space \u03b1] :\n    to_outer_measure 0 = 0 :=\n  rfl\n\n@[simp] theorem coe_zero {\u03b1 : Type u_1} [measurable_space \u03b1] : \u21d10 = 0 := rfl\n\ntheorem eq_zero_of_not_nonempty {\u03b1 : Type u_1} [measurable_space \u03b1] (h : \u00acNonempty \u03b1)\n    (\u03bc : measure \u03b1) : \u03bc = 0 :=\n  sorry\n\nprotected instance inhabited {\u03b1 : Type u_1} [measurable_space \u03b1] : Inhabited (measure \u03b1) :=\n  { default := 0 }\n\nprotected instance has_add {\u03b1 : Type u_1} [measurable_space \u03b1] : Add (measure \u03b1) :=\n  { add := fun (\u03bc\u2081 \u03bc\u2082 : measure \u03b1) => mk (to_outer_measure \u03bc\u2081 + to_outer_measure \u03bc\u2082) sorry sorry }\n\n@[simp] theorem add_to_outer_measure {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc\u2081 : measure \u03b1)\n    (\u03bc\u2082 : measure \u03b1) : to_outer_measure (\u03bc\u2081 + \u03bc\u2082) = to_outer_measure \u03bc\u2081 + to_outer_measure \u03bc\u2082 :=\n  rfl\n\n@[simp] theorem coe_add {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc\u2081 : measure \u03b1) (\u03bc\u2082 : measure \u03b1) :\n    \u21d1(\u03bc\u2081 + \u03bc\u2082) = \u21d1\u03bc\u2081 + \u21d1\u03bc\u2082 :=\n  rfl\n\ntheorem add_apply {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc\u2081 : measure \u03b1) (\u03bc\u2082 : measure \u03b1)\n    (s : set \u03b1) : coe_fn (\u03bc\u2081 + \u03bc\u2082) s = coe_fn \u03bc\u2081 s + coe_fn \u03bc\u2082 s :=\n  rfl\n\nprotected instance add_comm_monoid {\u03b1 : Type u_1} [measurable_space \u03b1] :\n    add_comm_monoid (measure \u03b1) :=\n  function.injective.add_comm_monoid to_outer_measure to_outer_measure_injective\n    zero_to_outer_measure add_to_outer_measure\n\nprotected instance has_scalar {\u03b1 : Type u_1} [measurable_space \u03b1] :\n    has_scalar ennreal (measure \u03b1) :=\n  has_scalar.mk fun (c : ennreal) (\u03bc : measure \u03b1) => mk (c \u2022 to_outer_measure \u03bc) sorry sorry\n\n@[simp] theorem smul_to_outer_measure {\u03b1 : Type u_1} [measurable_space \u03b1] (c : ennreal)\n    (\u03bc : measure \u03b1) : to_outer_measure (c \u2022 \u03bc) = c \u2022 to_outer_measure \u03bc :=\n  rfl\n\n@[simp] theorem coe_smul {\u03b1 : Type u_1} [measurable_space \u03b1] (c : ennreal) (\u03bc : measure \u03b1) :\n    \u21d1(c \u2022 \u03bc) = c \u2022 \u21d1\u03bc :=\n  rfl\n\ntheorem smul_apply {\u03b1 : Type u_1} [measurable_space \u03b1] (c : ennreal) (\u03bc : measure \u03b1) (s : set \u03b1) :\n    coe_fn (c \u2022 \u03bc) s = c * coe_fn \u03bc s :=\n  rfl\n\nprotected instance semimodule {\u03b1 : Type u_1} [measurable_space \u03b1] :\n    semimodule ennreal (measure \u03b1) :=\n  function.injective.semimodule ennreal\n    (add_monoid_hom.mk to_outer_measure zero_to_outer_measure add_to_outer_measure)\n    to_outer_measure_injective smul_to_outer_measure\n\n/-! ### The complete lattice of measures -/\n\nprotected instance partial_order {\u03b1 : Type u_1} [measurable_space \u03b1] : partial_order (measure \u03b1) :=\n  partial_order.mk\n    (fun (m\u2081 m\u2082 : measure \u03b1) => \u2200 (s : set \u03b1), is_measurable s \u2192 coe_fn m\u2081 s \u2264 coe_fn m\u2082 s)\n    (preorder.lt._default\n      fun (m\u2081 m\u2082 : measure \u03b1) => \u2200 (s : set \u03b1), is_measurable s \u2192 coe_fn m\u2081 s \u2264 coe_fn m\u2082 s)\n    sorry sorry sorry\n\ntheorem le_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1} {\u03bc\u2082 : measure \u03b1} :\n    \u03bc\u2081 \u2264 \u03bc\u2082 \u2194 \u2200 (s : set \u03b1), is_measurable s \u2192 coe_fn \u03bc\u2081 s \u2264 coe_fn \u03bc\u2082 s :=\n  iff.rfl\n\ntheorem to_outer_measure_le {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1} {\u03bc\u2082 : measure \u03b1} :\n    to_outer_measure \u03bc\u2081 \u2264 to_outer_measure \u03bc\u2082 \u2194 \u03bc\u2081 \u2264 \u03bc\u2082 :=\n  sorry\n\ntheorem le_iff' {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1} {\u03bc\u2082 : measure \u03b1} :\n    \u03bc\u2081 \u2264 \u03bc\u2082 \u2194 \u2200 (s : set \u03b1), coe_fn \u03bc\u2081 s \u2264 coe_fn \u03bc\u2082 s :=\n  iff.symm to_outer_measure_le\n\ntheorem lt_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} :\n    \u03bc < \u03bd \u2194 \u03bc \u2264 \u03bd \u2227 \u2203 (s : set \u03b1), is_measurable s \u2227 coe_fn \u03bc s < coe_fn \u03bd s :=\n  sorry\n\ntheorem lt_iff' {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} :\n    \u03bc < \u03bd \u2194 \u03bc \u2264 \u03bd \u2227 \u2203 (s : set \u03b1), coe_fn \u03bc s < coe_fn \u03bd s :=\n  sorry\n\n-- TODO: add typeclasses for `\u2200 c, monotone ((*) c)` and `\u2200 c, monotone ((+) c)`\n\nprotected theorem add_le_add_left {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1}\n    {\u03bc\u2082 : measure \u03b1} (\u03bd : measure \u03b1) (h\u03bc : \u03bc\u2081 \u2264 \u03bc\u2082) : \u03bd + \u03bc\u2081 \u2264 \u03bd + \u03bc\u2082 :=\n  fun (s : set \u03b1) (hs : is_measurable s) =>\n    add_le_add_left (h\u03bc s hs) (coe_fn (to_outer_measure \u03bd) s)\n\nprotected theorem add_le_add_right {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1}\n    {\u03bc\u2082 : measure \u03b1} (h\u03bc : \u03bc\u2081 \u2264 \u03bc\u2082) (\u03bd : measure \u03b1) : \u03bc\u2081 + \u03bd \u2264 \u03bc\u2082 + \u03bd :=\n  fun (s : set \u03b1) (hs : is_measurable s) =>\n    add_le_add_right (h\u03bc s hs) (coe_fn (to_outer_measure \u03bd) s)\n\nprotected theorem add_le_add {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc\u2081 : measure \u03b1} {\u03bc\u2082 : measure \u03b1}\n    {\u03bd\u2081 : measure \u03b1} {\u03bd\u2082 : measure \u03b1} (h\u03bc : \u03bc\u2081 \u2264 \u03bc\u2082) (h\u03bd : \u03bd\u2081 \u2264 \u03bd\u2082) : \u03bc\u2081 + \u03bd\u2081 \u2264 \u03bc\u2082 + \u03bd\u2082 :=\n  fun (s : set \u03b1) (hs : is_measurable s) => add_le_add (h\u03bc s hs) (h\u03bd s hs)\n\nprotected theorem le_add_left {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {\u03bd' : measure \u03b1} (h : \u03bc \u2264 \u03bd) : \u03bc \u2264 \u03bd' + \u03bd :=\n  fun (s : set \u03b1) (hs : is_measurable s) => le_add_left (h s hs)\n\nprotected theorem le_add_right {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {\u03bd' : measure \u03b1} (h : \u03bc \u2264 \u03bd) : \u03bc \u2264 \u03bd + \u03bd' :=\n  fun (s : set \u03b1) (hs : is_measurable s) => le_add_right (h s hs)\n\ntheorem Inf_caratheodory {\u03b1 : Type u_1} [measurable_space \u03b1] {m : set (measure \u03b1)} (s : set \u03b1)\n    (hs : is_measurable s) :\n    measurable_space.is_measurable' (outer_measure.caratheodory (Inf (to_outer_measure '' m))) s :=\n  sorry\n\nprotected instance has_Inf {\u03b1 : Type u_1} [measurable_space \u03b1] : has_Inf (measure \u03b1) :=\n  has_Inf.mk\n    fun (m : set (measure \u03b1)) =>\n      outer_measure.to_measure (Inf (to_outer_measure '' m)) Inf_caratheodory\n\ntheorem Inf_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} {m : set (measure \u03b1)}\n    (hs : is_measurable s) : coe_fn (Inf m) s = coe_fn (Inf (to_outer_measure '' m)) s :=\n  to_measure_apply (Inf (to_outer_measure '' m)) Inf_caratheodory hs\n\nprotected instance complete_lattice {\u03b1 : Type u_1} [measurable_space \u03b1] :\n    complete_lattice (measure \u03b1) :=\n  complete_lattice.mk complete_lattice.sup complete_lattice.le complete_lattice.lt sorry sorry sorry\n    sorry sorry sorry complete_lattice.inf sorry sorry sorry complete_lattice.top sorry 0 sorry\n    complete_lattice.Sup complete_lattice.Inf sorry sorry sorry sorry\n\n/- Adding an explicit `top` makes `leanchecker` fail, see lean#364, disable for now\n\n  top := (\u22a4 : outer_measure \u03b1).to_measure (by rw [outer_measure.top_caratheodory]; exact le_top),\n  le_top := assume a s hs,\n    by cases s.eq_empty_or_nonempty with h  h;\n      simp [h, to_measure_apply \u22a4 _ hs, outer_measure.top_apply],\n-/\n\nprotected theorem zero_le {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) : 0 \u2264 \u03bc := bot_le\n\ntheorem nonpos_iff_eq_zero' {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} : \u03bc \u2264 0 \u2194 \u03bc = 0 :=\n  has_le.le.le_iff_eq (measure.zero_le \u03bc)\n\n@[simp] theorem measure_univ_eq_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    coe_fn \u03bc set.univ = 0 \u2194 \u03bc = 0 :=\n  sorry\n\n/-! ### Pushforward and pullback -/\n\n/-- Lift a linear map between `outer_measure` spaces such that for each measure `\u03bc` every measurable\nset is caratheodory-measurable w.r.t. `f \u03bc` to a linear map between `measure` spaces. -/\ndef lift_linear {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    (f : linear_map ennreal (outer_measure \u03b1) (outer_measure \u03b2))\n    (hf : \u2200 (\u03bc : measure \u03b1), _inst_2 \u2264 outer_measure.caratheodory (coe_fn f (to_outer_measure \u03bc))) :\n    linear_map ennreal (measure \u03b1) (measure \u03b2) :=\n  linear_map.mk\n    (fun (\u03bc : measure \u03b1) => outer_measure.to_measure (coe_fn f (to_outer_measure \u03bc)) (hf \u03bc)) sorry\n    sorry\n\n@[simp] theorem lift_linear_apply {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {\u03bc : measure \u03b1}\n    {f : linear_map ennreal (outer_measure \u03b1) (outer_measure \u03b2)}\n    (hf : \u2200 (\u03bc : measure \u03b1), _inst_2 \u2264 outer_measure.caratheodory (coe_fn f (to_outer_measure \u03bc)))\n    {s : set \u03b2} (hs : is_measurable s) :\n    coe_fn (coe_fn (lift_linear f hf) \u03bc) s = coe_fn (coe_fn f (to_outer_measure \u03bc)) s :=\n  to_measure_apply (coe_fn f (to_outer_measure \u03bc)) (hf \u03bc) hs\n\ntheorem le_lift_linear_apply {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure \u03b1} {f : linear_map ennreal (outer_measure \u03b1) (outer_measure \u03b2)}\n    (hf : \u2200 (\u03bc : measure \u03b1), _inst_2 \u2264 outer_measure.caratheodory (coe_fn f (to_outer_measure \u03bc)))\n    (s : set \u03b2) :\n    coe_fn (coe_fn f (to_outer_measure \u03bc)) s \u2264 coe_fn (coe_fn (lift_linear f hf) \u03bc) s :=\n  le_to_measure_apply (coe_fn f (to_outer_measure \u03bc)) (hf \u03bc) s\n\n/-- The pushforward of a measure. It is defined to be `0` if `f` is not a measurable function. -/\ndef map {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2] (f : \u03b1 \u2192 \u03b2) :\n    linear_map ennreal (measure \u03b1) (measure \u03b2) :=\n  dite (measurable f) (fun (hf : measurable f) => lift_linear (outer_measure.map f) sorry)\n    fun (hf : \u00acmeasurable f) => 0\n\n/-- We can evaluate the pushforward on measurable sets. For non-measurable sets, see\n  `measure_theory.measure.le_map_apply` and `measurable_equiv.map_apply`. -/\n@[simp] theorem map_apply {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : measurable f) {s : set \u03b2} (hs : is_measurable s) :\n    coe_fn (coe_fn (map f) \u03bc) s = coe_fn \u03bc (f \u207b\u00b9' s) :=\n  sorry\n\n@[simp] theorem map_id {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    coe_fn (map id) \u03bc = \u03bc :=\n  ext fun (s : set \u03b1) => map_apply measurable_id\n\ntheorem map_map {\u03b1 : Type u_1} {\u03b2 : Type u_2} {\u03b3 : Type u_3} [measurable_space \u03b1]\n    [measurable_space \u03b2] [measurable_space \u03b3] {\u03bc : measure \u03b1} {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2}\n    (hg : measurable g) (hf : measurable f) :\n    coe_fn (map g) (coe_fn (map f) \u03bc) = coe_fn (map (g \u2218 f)) \u03bc :=\n  sorry\n\ntheorem map_mono {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : measurable f) (h : \u03bc \u2264 \u03bd) :\n    coe_fn (map f) \u03bc \u2264 coe_fn (map f) \u03bd :=\n  sorry\n\n/-- Even if `s` is not measurable, we can bound `map f \u03bc s` from below.\n  See also `measurable_equiv.map_apply`. -/\ntheorem le_map_apply {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : measurable f) (s : set \u03b2) :\n    coe_fn \u03bc (f \u207b\u00b9' s) \u2264 coe_fn (coe_fn (map f) \u03bc) s :=\n  sorry\n\n/-- Pullback of a `measure`. If `f` sends each `measurable` set to a `measurable` set, then for each\nmeasurable set `s` we have `comap f \u03bc s = \u03bc (f '' s)`. -/\ndef comap {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2] (f : \u03b1 \u2192 \u03b2) :\n    linear_map ennreal (measure \u03b2) (measure \u03b1) :=\n  dite (function.injective f \u2227 \u2200 (s : set \u03b1), is_measurable s \u2192 is_measurable (f '' s))\n    (fun (hf : function.injective f \u2227 \u2200 (s : set \u03b1), is_measurable s \u2192 is_measurable (f '' s)) =>\n      lift_linear (outer_measure.comap f) sorry)\n    fun (hf : \u00ac(function.injective f \u2227 \u2200 (s : set \u03b1), is_measurable s \u2192 is_measurable (f '' s))) =>\n      0\n\ntheorem comap_apply {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {s : set \u03b1} (f : \u03b1 \u2192 \u03b2) (hfi : function.injective f)\n    (hf : \u2200 (s : set \u03b1), is_measurable s \u2192 is_measurable (f '' s)) (\u03bc : measure \u03b2)\n    (hs : is_measurable s) : coe_fn (coe_fn (comap f) \u03bc) s = coe_fn \u03bc (f '' s) :=\n  sorry\n\n/-! ### Restricting a measure -/\n\n/-- Restrict a measure `\u03bc` to a set `s` as an `ennreal`-linear map. -/\ndef restrict\u2097 {\u03b1 : Type u_1} [measurable_space \u03b1] (s : set \u03b1) :\n    linear_map ennreal (measure \u03b1) (measure \u03b1) :=\n  lift_linear (outer_measure.restrict s) sorry\n\n/-- Restrict a measure `\u03bc` to a set `s`. -/\ndef restrict {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) (s : set \u03b1) : measure \u03b1 :=\n  coe_fn (restrict\u2097 s) \u03bc\n\n@[simp] theorem restrict\u2097_apply {\u03b1 : Type u_1} [measurable_space \u03b1] (s : set \u03b1) (\u03bc : measure \u03b1) :\n    coe_fn (restrict\u2097 s) \u03bc = restrict \u03bc s :=\n  rfl\n\n@[simp] theorem restrict_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (ht : is_measurable t) : coe_fn (restrict \u03bc s) t = coe_fn \u03bc (t \u2229 s) :=\n  sorry\n\ntheorem restrict_apply_univ {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} (s : set \u03b1) :\n    coe_fn (restrict \u03bc s) set.univ = coe_fn \u03bc s :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (coe_fn (restrict \u03bc s) set.univ = coe_fn \u03bc s))\n        (restrict_apply is_measurable.univ)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn \u03bc (set.univ \u2229 s) = coe_fn \u03bc s)) (set.univ_inter s)))\n      (Eq.refl (coe_fn \u03bc s)))\n\ntheorem le_restrict_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} (s : set \u03b1)\n    (t : set \u03b1) : coe_fn \u03bc (t \u2229 s) \u2264 coe_fn (restrict \u03bc s) t :=\n  sorry\n\n@[simp] theorem restrict_add {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) (\u03bd : measure \u03b1)\n    (s : set \u03b1) : restrict (\u03bc + \u03bd) s = restrict \u03bc s + restrict \u03bd s :=\n  linear_map.map_add (restrict\u2097 s) \u03bc \u03bd\n\n@[simp] theorem restrict_zero {\u03b1 : Type u_1} [measurable_space \u03b1] (s : set \u03b1) : restrict 0 s = 0 :=\n  linear_map.map_zero (restrict\u2097 s)\n\n@[simp] theorem restrict_smul {\u03b1 : Type u_1} [measurable_space \u03b1] (c : ennreal) (\u03bc : measure \u03b1)\n    (s : set \u03b1) : restrict (c \u2022 \u03bc) s = c \u2022 restrict \u03bc s :=\n  linear_map.map_smul (restrict\u2097 s) c \u03bc\n\n@[simp] theorem restrict_restrict {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (hs : is_measurable s) : restrict (restrict \u03bc t) s = restrict \u03bc (s \u2229 t) :=\n  sorry\n\ntheorem restrict_apply_eq_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (ht : is_measurable t) : coe_fn (restrict \u03bc s) t = 0 \u2194 coe_fn \u03bc (t \u2229 s) = 0 :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (coe_fn (restrict \u03bc s) t = 0 \u2194 coe_fn \u03bc (t \u2229 s) = 0))\n        (restrict_apply ht)))\n    (iff.refl (coe_fn \u03bc (t \u2229 s) = 0))\n\ntheorem measure_inter_eq_zero_of_restrict {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b1} {t : set \u03b1} (h : coe_fn (restrict \u03bc s) t = 0) : coe_fn \u03bc (t \u2229 s) = 0 :=\n  iff.mp nonpos_iff_eq_zero (h \u25b8 le_restrict_apply s t)\n\ntheorem restrict_apply_eq_zero' {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (hs : is_measurable s) : coe_fn (restrict \u03bc s) t = 0 \u2194 coe_fn \u03bc (t \u2229 s) = 0 :=\n  sorry\n\n@[simp] theorem restrict_eq_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    restrict \u03bc s = 0 \u2194 coe_fn \u03bc s = 0 :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (restrict \u03bc s = 0 \u2194 coe_fn \u03bc s = 0))\n        (Eq.symm (propext measure_univ_eq_zero))))\n    (eq.mpr\n      (id\n        (Eq._oldrec (Eq.refl (coe_fn (restrict \u03bc s) set.univ = 0 \u2194 coe_fn \u03bc s = 0))\n          (restrict_apply_univ s)))\n      (iff.refl (coe_fn \u03bc s = 0)))\n\n@[simp] theorem restrict_empty {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    restrict \u03bc \u2205 = 0 :=\n  sorry\n\n@[simp] theorem restrict_univ {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    restrict \u03bc set.univ = \u03bc :=\n  sorry\n\ntheorem restrict_union_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {s' : set \u03b1} {t : set \u03b1} (h : disjoint (t \u2229 s) (t \u2229 s')) (hs : is_measurable s)\n    (hs' : is_measurable s') (ht : is_measurable t) :\n    coe_fn (restrict \u03bc (s \u222a s')) t = coe_fn (restrict \u03bc s) t + coe_fn (restrict \u03bc s') t :=\n  sorry\n\ntheorem restrict_union {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} {t : set \u03b1}\n    (h : disjoint s t) (hs : is_measurable s) (ht : is_measurable t) :\n    restrict \u03bc (s \u222a t) = restrict \u03bc s + restrict \u03bc t :=\n  ext\n    fun (t' : set \u03b1) (ht' : is_measurable t') =>\n      restrict_union_apply (disjoint.mono inf_le_right inf_le_right h) hs ht ht'\n\ntheorem restrict_union_add_inter {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (hs : is_measurable s) (ht : is_measurable t) :\n    restrict \u03bc (s \u222a t) + restrict \u03bc (s \u2229 t) = restrict \u03bc s + restrict \u03bc t :=\n  sorry\n\n@[simp] theorem restrict_add_restrict_compl {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b1} (hs : is_measurable s) : restrict \u03bc s + restrict \u03bc (s\u1d9c) = \u03bc :=\n  sorry\n\n@[simp] theorem restrict_compl_add_restrict {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b1} (hs : is_measurable s) : restrict \u03bc (s\u1d9c) + restrict \u03bc s = \u03bc :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (restrict \u03bc (s\u1d9c) + restrict \u03bc s = \u03bc))\n        (add_comm (restrict \u03bc (s\u1d9c)) (restrict \u03bc s))))\n    (eq.mpr\n      (id\n        (Eq._oldrec (Eq.refl (restrict \u03bc s + restrict \u03bc (s\u1d9c) = \u03bc))\n          (restrict_add_restrict_compl hs)))\n      (Eq.refl \u03bc))\n\ntheorem restrict_union_le {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} (s : set \u03b1)\n    (s' : set \u03b1) : restrict \u03bc (s \u222a s') \u2264 restrict \u03bc s + restrict \u03bc s' :=\n  sorry\n\ntheorem restrict_Union_apply {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (hd : pairwise (disjoint on s))\n    (hm : \u2200 (i : \u03b9), is_measurable (s i)) {t : set \u03b1} (ht : is_measurable t) :\n    coe_fn (restrict \u03bc (set.Union fun (i : \u03b9) => s i)) t =\n        tsum fun (i : \u03b9) => coe_fn (restrict \u03bc (s i)) t :=\n  sorry\n\ntheorem restrict_Union_apply_eq_supr {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (hm : \u2200 (i : \u03b9), is_measurable (s i))\n    (hd : directed has_subset.subset s) {t : set \u03b1} (ht : is_measurable t) :\n    coe_fn (restrict \u03bc (set.Union fun (i : \u03b9) => s i)) t =\n        supr fun (i : \u03b9) => coe_fn (restrict \u03bc (s i)) t :=\n  sorry\n\ntheorem restrict_map {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : measurable f) {s : set \u03b2} (hs : is_measurable s) :\n    restrict (coe_fn (map f) \u03bc) s = coe_fn (map f) (restrict \u03bc (f \u207b\u00b9' s)) :=\n  sorry\n\ntheorem map_comap_subtype_coe {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1}\n    (hs : is_measurable s) : linear_map.comp (map coe) (comap coe) = restrict\u2097 s :=\n  sorry\n\n/-- Restriction of a measure to a subset is monotone both in set and in measure. -/\ntheorem restrict_mono {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} {s' : set \u03b1} (hs : s \u2286 s')\n    {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} (h\u03bc\u03bd : \u03bc \u2264 \u03bd) : restrict \u03bc s \u2264 restrict \u03bd s' :=\n  sorry\n\ntheorem restrict_le_self {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    restrict \u03bc s \u2264 \u03bc :=\n  fun (t : set \u03b1) (ht : is_measurable t) =>\n    trans_rel_right LessEq (restrict_apply ht) (measure_mono (set.inter_subset_left t s))\n\ntheorem restrict_congr_meas {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {s : set \u03b1} (hs : is_measurable s) :\n    restrict \u03bc s = restrict \u03bd s \u2194\n        \u2200 (t : set \u03b1), t \u2286 s \u2192 is_measurable t \u2192 coe_fn \u03bc t = coe_fn \u03bd t :=\n  sorry\n\ntheorem restrict_congr_mono {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {s : set \u03b1} {t : set \u03b1} (hs : s \u2286 t) (hm : is_measurable s) (h : restrict \u03bc t = restrict \u03bd t) :\n    restrict \u03bc s = restrict \u03bd s :=\n  sorry\n\n/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all\nmeasurable subsets of `s \u222a t`. -/\ntheorem restrict_union_congr {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {s : set \u03b1} {t : set \u03b1} (hsm : is_measurable s) (htm : is_measurable t) :\n    restrict \u03bc (s \u222a t) = restrict \u03bd (s \u222a t) \u2194\n        restrict \u03bc s = restrict \u03bd s \u2227 restrict \u03bc t = restrict \u03bd t :=\n  sorry\n\ntheorem restrict_finset_bUnion_congr {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} {s : finset \u03b9} {t : \u03b9 \u2192 set \u03b1}\n    (htm : \u2200 (i : \u03b9), i \u2208 s \u2192 is_measurable (t i)) :\n    restrict \u03bc (set.Union fun (i : \u03b9) => set.Union fun (H : i \u2208 s) => t i) =\n          restrict \u03bd (set.Union fun (i : \u03b9) => set.Union fun (H : i \u2208 s) => t i) \u2194\n        \u2200 (i : \u03b9), i \u2208 s \u2192 restrict \u03bc (t i) = restrict \u03bd (t i) :=\n  sorry\n\ntheorem restrict_Union_congr {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (hm : \u2200 (i : \u03b9), is_measurable (s i)) :\n    restrict \u03bc (set.Union fun (i : \u03b9) => s i) = restrict \u03bd (set.Union fun (i : \u03b9) => s i) \u2194\n        \u2200 (i : \u03b9), restrict \u03bc (s i) = restrict \u03bd (s i) :=\n  sorry\n\ntheorem restrict_bUnion_congr {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} {s : set \u03b9} {t : \u03b9 \u2192 set \u03b1} (hc : set.countable s)\n    (htm : \u2200 (i : \u03b9), i \u2208 s \u2192 is_measurable (t i)) :\n    restrict \u03bc (set.Union fun (i : \u03b9) => set.Union fun (H : i \u2208 s) => t i) =\n          restrict \u03bd (set.Union fun (i : \u03b9) => set.Union fun (H : i \u2208 s) => t i) \u2194\n        \u2200 (i : \u03b9), i \u2208 s \u2192 restrict \u03bc (t i) = restrict \u03bd (t i) :=\n  sorry\n\ntheorem restrict_sUnion_congr {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {S : set (set \u03b1)} (hc : set.countable S) (hm : \u2200 (s : set \u03b1), s \u2208 S \u2192 is_measurable s) :\n    restrict \u03bc (\u22c3\u2080S) = restrict \u03bd (\u22c3\u2080S) \u2194 \u2200 (s : set \u03b1), s \u2208 S \u2192 restrict \u03bc s = restrict \u03bd s :=\n  sorry\n\n/-- This lemma shows that `restrict` and `to_outer_measure` commute. Note that the LHS has a\nrestrict on measures and the RHS has a restrict on outer measures. -/\ntheorem restrict_to_outer_measure_eq_to_outer_measure_restrict {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} {s : set \u03b1} (h : is_measurable s) :\n    to_outer_measure (restrict \u03bc s) = coe_fn (outer_measure.restrict s) (to_outer_measure \u03bc) :=\n  sorry\n\n/-- This lemma shows that `Inf` and `restrict` commute for measures. -/\ntheorem restrict_Inf_eq_Inf_restrict {\u03b1 : Type u_1} [measurable_space \u03b1] {t : set \u03b1}\n    {m : set (measure \u03b1)} (hm : set.nonempty m) (ht : is_measurable t) :\n    restrict (Inf m) t = Inf ((fun (\u03bc : measure \u03b1) => restrict \u03bc t) '' m) :=\n  sorry\n\n/-! ### Extensionality results -/\n\n/-- Two measures are equal if they have equal restrictions on a spanning collection of sets\n  (formulated using `Union`). -/\ntheorem ext_iff_of_Union_eq_univ {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (hm : \u2200 (i : \u03b9), is_measurable (s i))\n    (hs : (set.Union fun (i : \u03b9) => s i) = set.univ) :\n    \u03bc = \u03bd \u2194 \u2200 (i : \u03b9), restrict \u03bc (s i) = restrict \u03bd (s i) :=\n  sorry\n\ntheorem ext_of_Union_eq_univ {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (hm : \u2200 (i : \u03b9), is_measurable (s i))\n    (hs : (set.Union fun (i : \u03b9) => s i) = set.univ) :\n    (\u2200 (i : \u03b9), restrict \u03bc (s i) = restrict \u03bd (s i)) \u2192 \u03bc = \u03bd :=\n  iff.mpr (ext_iff_of_Union_eq_univ hm hs)\n\n/-- Two measures are equal if they have equal restrictions on a spanning collection of sets\n  (formulated using `bUnion`). -/\ntheorem ext_iff_of_bUnion_eq_univ {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} {S : set \u03b9} {s : \u03b9 \u2192 set \u03b1} (hc : set.countable S)\n    (hm : \u2200 (i : \u03b9), i \u2208 S \u2192 is_measurable (s i))\n    (hs : (set.Union fun (i : \u03b9) => set.Union fun (H : i \u2208 S) => s i) = set.univ) :\n    \u03bc = \u03bd \u2194 \u2200 (i : \u03b9), i \u2208 S \u2192 restrict \u03bc (s i) = restrict \u03bd (s i) :=\n  sorry\n\ntheorem ext_of_bUnion_eq_univ {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} {S : set \u03b9} {s : \u03b9 \u2192 set \u03b1} (hc : set.countable S)\n    (hm : \u2200 (i : \u03b9), i \u2208 S \u2192 is_measurable (s i))\n    (hs : (set.Union fun (i : \u03b9) => set.Union fun (H : i \u2208 S) => s i) = set.univ) :\n    (\u2200 (i : \u03b9), i \u2208 S \u2192 restrict \u03bc (s i) = restrict \u03bd (s i)) \u2192 \u03bc = \u03bd :=\n  iff.mpr (ext_iff_of_bUnion_eq_univ hc hm hs)\n\n/-- Two measures are equal if they have equal restrictions on a spanning collection of sets\n  (formulated using `sUnion`). -/\ntheorem ext_iff_of_sUnion_eq_univ {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} {S : set (set \u03b1)} (hc : set.countable S)\n    (hm : \u2200 (s : set \u03b1), s \u2208 S \u2192 is_measurable s) (hs : \u22c3\u2080S = set.univ) :\n    \u03bc = \u03bd \u2194 \u2200 (s : set \u03b1), s \u2208 S \u2192 restrict \u03bc s = restrict \u03bd s :=\n  sorry\n\ntheorem ext_of_sUnion_eq_univ {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {S : set (set \u03b1)} (hc : set.countable S) (hm : \u2200 (s : set \u03b1), s \u2208 S \u2192 is_measurable s)\n    (hs : \u22c3\u2080S = set.univ) : (\u2200 (s : set \u03b1), s \u2208 S \u2192 restrict \u03bc s = restrict \u03bd s) \u2192 \u03bc = \u03bd :=\n  iff.mpr (ext_iff_of_sUnion_eq_univ hc hm hs)\n\ntheorem ext_of_generate_from_of_cover {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} {S : set (set \u03b1)} {T : set (set \u03b1)}\n    (h_gen : _inst_1 = measurable_space.generate_from S) (hc : set.countable T)\n    (h_inter : is_pi_system S) (hm : \u2200 (t : set \u03b1), t \u2208 T \u2192 is_measurable t) (hU : \u22c3\u2080T = set.univ)\n    (htop : \u2200 (t : set \u03b1), t \u2208 T \u2192 coe_fn \u03bc t < \u22a4)\n    (ST_eq : \u2200 (t : set \u03b1), t \u2208 T \u2192 \u2200 (s : set \u03b1), s \u2208 S \u2192 coe_fn \u03bc (s \u2229 t) = coe_fn \u03bd (s \u2229 t))\n    (T_eq : \u2200 (t : set \u03b1), t \u2208 T \u2192 coe_fn \u03bc t = coe_fn \u03bd t) : \u03bc = \u03bd :=\n  sorry\n\n/-- Two measures are equal if they are equal on the \u03c0-system generating the \u03c3-algebra,\n  and they are both finite on a increasing spanning sequence of sets in the \u03c0-system.\n  This lemma is formulated using `sUnion`. -/\ntheorem ext_of_generate_from_of_cover_subset {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} {S : set (set \u03b1)} {T : set (set \u03b1)}\n    (h_gen : _inst_1 = measurable_space.generate_from S) (h_inter : is_pi_system S) (h_sub : T \u2286 S)\n    (hc : set.countable T) (hU : \u22c3\u2080T = set.univ) (htop : \u2200 (s : set \u03b1), s \u2208 T \u2192 coe_fn \u03bc s < \u22a4)\n    (h_eq : \u2200 (s : set \u03b1), s \u2208 S \u2192 coe_fn \u03bc s = coe_fn \u03bd s) : \u03bc = \u03bd :=\n  sorry\n\n/-- Two measures are equal if they are equal on the \u03c0-system generating the \u03c3-algebra,\n  and they are both finite on a increasing spanning sequence of sets in the \u03c0-system.\n  This lemma is formulated using `Union`.\n  `finite_spanning_sets_in.ext` is a reformulation of this lemma. -/\ntheorem ext_of_generate_from_of_Union {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} (C : set (set \u03b1)) (B : \u2115 \u2192 set \u03b1)\n    (hA : _inst_1 = measurable_space.generate_from C) (hC : is_pi_system C)\n    (h1B : (set.Union fun (i : \u2115) => B i) = set.univ) (h2B : \u2200 (i : \u2115), B i \u2208 C)\n    (h\u03bcB : \u2200 (i : \u2115), coe_fn \u03bc (B i) < \u22a4) (h_eq : \u2200 (s : set \u03b1), s \u2208 C \u2192 coe_fn \u03bc s = coe_fn \u03bd s) :\n    \u03bc = \u03bd :=\n  sorry\n\n/-- The dirac measure. -/\ndef dirac {\u03b1 : Type u_1} [measurable_space \u03b1] (a : \u03b1) : measure \u03b1 :=\n  outer_measure.to_measure (outer_measure.dirac a) sorry\n\ntheorem le_dirac_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} {a : \u03b1} :\n    set.indicator s 1 a \u2264 coe_fn (dirac a) s :=\n  outer_measure.dirac_apply a s \u25b8 le_to_measure_apply (outer_measure.dirac a) (dirac._proof_1 a) s\n\n@[simp] theorem dirac_apply' {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} (a : \u03b1)\n    (hs : is_measurable s) : coe_fn (dirac a) s = set.indicator s 1 a :=\n  to_measure_apply (outer_measure.dirac a) (dirac._proof_1 a) hs\n\n@[simp] theorem dirac_apply_of_mem {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} {a : \u03b1}\n    (h : a \u2208 s) : coe_fn (dirac a) s = 1 :=\n  sorry\n\n@[simp] theorem dirac_apply {\u03b1 : Type u_1} [measurable_space \u03b1] [measurable_singleton_class \u03b1]\n    (a : \u03b1) (s : set \u03b1) : coe_fn (dirac a) s = set.indicator s 1 a :=\n  sorry\n\ntheorem map_dirac {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {f : \u03b1 \u2192 \u03b2} (hf : measurable f) (a : \u03b1) : coe_fn (map f) (dirac a) = dirac (f a) :=\n  sorry\n\n/-- Sum of an indexed family of measures. -/\ndef sum {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] (f : \u03b9 \u2192 measure \u03b1) : measure \u03b1 :=\n  outer_measure.to_measure (outer_measure.sum fun (i : \u03b9) => to_outer_measure (f i)) sorry\n\ntheorem le_sum_apply {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] (f : \u03b9 \u2192 measure \u03b1)\n    (s : set \u03b1) : (tsum fun (i : \u03b9) => coe_fn (f i) s) \u2264 coe_fn (sum f) s :=\n  le_to_measure_apply (outer_measure.sum fun (i : \u03b9) => to_outer_measure (f i)) (sum._proof_1 f) s\n\n@[simp] theorem sum_apply {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] (f : \u03b9 \u2192 measure \u03b1)\n    {s : set \u03b1} (hs : is_measurable s) : coe_fn (sum f) s = tsum fun (i : \u03b9) => coe_fn (f i) s :=\n  to_measure_apply (outer_measure.sum fun (i : \u03b9) => to_outer_measure (f i)) (sum._proof_1 f) hs\n\ntheorem le_sum {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] (\u03bc : \u03b9 \u2192 measure \u03b1) (i : \u03b9) :\n    \u03bc i \u2264 sum \u03bc :=\n  sorry\n\ntheorem restrict_Union {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} (hd : pairwise (disjoint on s))\n    (hm : \u2200 (i : \u03b9), is_measurable (s i)) :\n    restrict \u03bc (set.Union fun (i : \u03b9) => s i) = sum fun (i : \u03b9) => restrict \u03bc (s i) :=\n  sorry\n\ntheorem restrict_Union_le {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    [encodable \u03b9] {s : \u03b9 \u2192 set \u03b1} :\n    restrict \u03bc (set.Union fun (i : \u03b9) => s i) \u2264 sum fun (i : \u03b9) => restrict \u03bc (s i) :=\n  sorry\n\n@[simp] theorem sum_bool {\u03b1 : Type u_1} [measurable_space \u03b1] (f : Bool \u2192 measure \u03b1) :\n    sum f = f tt + f false :=\n  sorry\n\n@[simp] theorem sum_cond {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) (\u03bd : measure \u03b1) :\n    (sum fun (b : Bool) => cond b \u03bc \u03bd) = \u03bc + \u03bd :=\n  sum_bool fun (b : Bool) => cond b \u03bc \u03bd\n\n@[simp] theorem restrict_sum {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] (\u03bc : \u03b9 \u2192 measure \u03b1)\n    {s : set \u03b1} (hs : is_measurable s) : restrict (sum \u03bc) s = sum fun (i : \u03b9) => restrict (\u03bc i) s :=\n  sorry\n\n/-- Counting measure on any measurable space. -/\ndef count {\u03b1 : Type u_1} [measurable_space \u03b1] : measure \u03b1 := sum dirac\n\ntheorem le_count_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} :\n    (tsum fun (i : \u21a5s) => 1) \u2264 coe_fn count s :=\n  le_trans\n    (trans_rel_right LessEq (tsum_subtype s 1) (ennreal.tsum_le_tsum fun (x : \u03b1) => le_dirac_apply))\n    (le_sum_apply (fun (i : \u03b1) => dirac i) s)\n\ntheorem count_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} (hs : is_measurable s) :\n    coe_fn count s = tsum fun (i : \u21a5s) => 1 :=\n  sorry\n\n@[simp] theorem count_apply_finset {\u03b1 : Type u_1} [measurable_space \u03b1]\n    [measurable_singleton_class \u03b1] (s : finset \u03b1) : coe_fn count \u2191s = \u2191(finset.card s) :=\n  sorry\n\ntheorem count_apply_finite {\u03b1 : Type u_1} [measurable_space \u03b1] [measurable_singleton_class \u03b1]\n    (s : set \u03b1) (hs : set.finite s) : coe_fn count s = \u2191(finset.card (set.finite.to_finset hs)) :=\n  sorry\n\n/-- `count` measure evaluates to infinity at infinite sets. -/\ntheorem count_apply_infinite {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} (hs : set.infinite s) :\n    coe_fn count s = \u22a4 :=\n  sorry\n\n@[simp] theorem count_apply_eq_top {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1}\n    [measurable_singleton_class \u03b1] : coe_fn count s = \u22a4 \u2194 set.infinite s :=\n  sorry\n\n@[simp] theorem count_apply_lt_top {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1}\n    [measurable_singleton_class \u03b1] : coe_fn count s < \u22a4 \u2194 set.finite s :=\n  iff.trans (iff.trans lt_top_iff_ne_top (not_congr count_apply_eq_top)) not_not\n\n/-! ### The almost everywhere filter -/\n\n/-- The \u201calmost everywhere\u201d filter of co-null sets. -/\ndef ae {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) : filter \u03b1 :=\n  filter.mk (set_of fun (s : set \u03b1) => coe_fn \u03bc (s\u1d9c) = 0) sorry sorry sorry\n\n/-- The filter of sets `s` such that `s\u1d9c` has finite measure. -/\ndef cofinite {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) : filter \u03b1 :=\n  filter.mk (set_of fun (s : set \u03b1) => coe_fn \u03bc (s\u1d9c) < \u22a4) sorry sorry sorry\n\ntheorem mem_cofinite {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    s \u2208 cofinite \u03bc \u2194 coe_fn \u03bc (s\u1d9c) < \u22a4 :=\n  iff.rfl\n\ntheorem compl_mem_cofinite {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    s\u1d9c \u2208 cofinite \u03bc \u2194 coe_fn \u03bc s < \u22a4 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (s\u1d9c \u2208 cofinite \u03bc \u2194 coe_fn \u03bc s < \u22a4)) (propext mem_cofinite)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn \u03bc (s\u1d9c\u1d9c) < \u22a4 \u2194 coe_fn \u03bc s < \u22a4)) (compl_compl s)))\n      (iff.refl (coe_fn \u03bc s < \u22a4)))\n\ntheorem eventually_cofinite {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {p : \u03b1 \u2192 Prop} :\n    filter.eventually (fun (x : \u03b1) => p x) (cofinite \u03bc) \u2194\n        coe_fn \u03bc (set_of fun (x : \u03b1) => \u00acp x) < \u22a4 :=\n  iff.rfl\n\nend measure\n\n\ntheorem mem_ae_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    s \u2208 measure.ae \u03bc \u2194 coe_fn \u03bc (s\u1d9c) = 0 :=\n  iff.rfl\n\ntheorem ae_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {p : \u03b1 \u2192 Prop} :\n    filter.eventually (fun (a : \u03b1) => p a) (measure.ae \u03bc) \u2194\n        coe_fn \u03bc (set_of fun (a : \u03b1) => \u00acp a) = 0 :=\n  iff.rfl\n\ntheorem compl_mem_ae_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    s\u1d9c \u2208 measure.ae \u03bc \u2194 coe_fn \u03bc s = 0 :=\n  sorry\n\ntheorem measure_zero_iff_ae_nmem {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    coe_fn \u03bc s = 0 \u2194 filter.eventually (fun (a : \u03b1) => \u00aca \u2208 s) (measure.ae \u03bc) :=\n  iff.symm compl_mem_ae_iff\n\n@[simp] theorem ae_eq_bot {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    measure.ae \u03bc = \u22a5 \u2194 \u03bc = 0 :=\n  sorry\n\n@[simp] theorem ae_zero {\u03b1 : Type u_1} [measurable_space \u03b1] : measure.ae 0 = \u22a5 :=\n  iff.mpr ae_eq_bot rfl\n\ntheorem ae_of_all {\u03b1 : Type u_1} [measurable_space \u03b1] {p : \u03b1 \u2192 Prop} (\u03bc : measure \u03b1) :\n    (\u2200 (a : \u03b1), p a) \u2192 filter.eventually (fun (a : \u03b1) => p a) (measure.ae \u03bc) :=\n  filter.eventually_of_forall\n\ntheorem ae_mono {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} (h : \u03bc \u2264 \u03bd) :\n    measure.ae \u03bc \u2264 measure.ae \u03bd :=\n  fun (s : set \u03b1) (hs : s \u2208 measure.ae \u03bd) =>\n    bot_unique (trans_rel_left LessEq (iff.mp measure.le_iff' h (s\u1d9c)) hs)\n\nprotected instance measure.ae.countable_Inter_filter {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} : countable_Inter_filter (measure.ae \u03bc) :=\n  countable_Inter_filter.mk\n    fun (S : set (set \u03b1)) (hSc : set.countable S) (hS : \u2200 (s : set \u03b1), s \u2208 S \u2192 s \u2208 measure.ae \u03bc) =>\n      eq.mpr\n        (id\n          (Eq.trans (propext mem_ae_iff)\n            ((fun (a a_1 : ennreal) (e_1 : a = a_1) (\u1fb0 \u1fb0_1 : ennreal) (e_2 : \u1fb0 = \u1fb0_1) =>\n                congr (congr_arg Eq e_1) e_2)\n              (coe_fn \u03bc (\u22c2\u2080S\u1d9c)) (coe_fn \u03bc (set.Union fun (x : \u21a5S) => \u2191x\u1d9c))\n              ((fun (x x_1 : measure \u03b1) (e_1 : x = x_1) (\u1fb0 \u1fb0_1 : set \u03b1) (e_2 : \u1fb0 = \u1fb0_1) =>\n                  congr (congr_arg coe_fn e_1) e_2)\n                \u03bc \u03bc (Eq.refl \u03bc) (\u22c2\u2080S\u1d9c) (set.Union fun (x : \u21a5S) => \u2191x\u1d9c)\n                (Eq.trans (Eq.trans (set.compl_sInter S) (set.sUnion_image compl S))\n                  (set.bUnion_eq_Union S fun (x : set \u03b1) (H : x \u2208 S) => x\u1d9c)))\n              0 0 (Eq.refl 0))))\n        (measure_Union_null\n          (iff.mpr subtype.forall\n            (eq.mp\n              (forall_congr_eq\n                fun (s : set \u03b1) => imp_congr_eq (Eq.refl (s \u2208 S)) (propext mem_ae_iff))\n              hS)))\n\nprotected instance ae_is_measurably_generated {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n    filter.is_measurably_generated (measure.ae \u03bc) :=\n  filter.is_measurably_generated.mk fun (s : set \u03b1) (hs : s \u2208 measure.ae \u03bc) => sorry\n\ntheorem ae_all_iff {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1} [encodable \u03b9]\n    {p : \u03b1 \u2192 \u03b9 \u2192 Prop} :\n    filter.eventually (fun (a : \u03b1) => \u2200 (i : \u03b9), p a i) (measure.ae \u03bc) \u2194\n        \u2200 (i : \u03b9), filter.eventually (fun (a : \u03b1) => p a i) (measure.ae \u03bc) :=\n  eventually_countable_forall\n\ntheorem ae_ball_iff {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1] {\u03bc : measure \u03b1} {S : set \u03b9}\n    (hS : set.countable S) {p : \u03b1 \u2192 (i : \u03b9) \u2192 i \u2208 S \u2192 Prop} :\n    filter.eventually (fun (x : \u03b1) => \u2200 (i : \u03b9) (H : i \u2208 S), p x i H) (measure.ae \u03bc) \u2194\n        \u2200 (i : \u03b9) (H : i \u2208 S), filter.eventually (fun (x : \u03b1) => p x i H) (measure.ae \u03bc) :=\n  eventually_countable_ball hS\n\ntheorem ae_eq_refl {\u03b1 : Type u_1} {\u03b4 : Type u_4} [measurable_space \u03b1] {\u03bc : measure \u03b1} (f : \u03b1 \u2192 \u03b4) :\n    filter.eventually_eq (measure.ae \u03bc) f f :=\n  filter.eventually_eq.rfl\n\ntheorem ae_eq_symm {\u03b1 : Type u_1} {\u03b4 : Type u_4} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b4}\n    {g : \u03b1 \u2192 \u03b4} (h : filter.eventually_eq (measure.ae \u03bc) f g) :\n    filter.eventually_eq (measure.ae \u03bc) g f :=\n  filter.eventually_eq.symm h\n\ntheorem ae_eq_trans {\u03b1 : Type u_1} {\u03b4 : Type u_4} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b4}\n    {g : \u03b1 \u2192 \u03b4} {h : \u03b1 \u2192 \u03b4} (h\u2081 : filter.eventually_eq (measure.ae \u03bc) f g)\n    (h\u2082 : filter.eventually_eq (measure.ae \u03bc) g h) : filter.eventually_eq (measure.ae \u03bc) f h :=\n  filter.eventually_eq.trans h\u2081 h\u2082\n\ntheorem ae_eq_empty {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) s \u2205 \u2194 coe_fn \u03bc s = 0 :=\n  sorry\n\ntheorem ae_le_set {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} {t : set \u03b1} :\n    filter.eventually_le (measure.ae \u03bc) s t \u2194 coe_fn \u03bc (s \\ t) = 0 :=\n  sorry\n\ntheorem union_ae_eq_right {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} : filter.eventually_eq (measure.ae \u03bc) (s \u222a t) t \u2194 coe_fn \u03bc (s \\ t) = 0 :=\n  sorry\n\ntheorem diff_ae_eq_self {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} : filter.eventually_eq (measure.ae \u03bc) (s \\ t) s \u2194 coe_fn \u03bc (s \u2229 t) = 0 :=\n  sorry\n\ntheorem ae_eq_set {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} {t : set \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) s t \u2194 coe_fn \u03bc (s \\ t) = 0 \u2227 coe_fn \u03bc (t \\ s) = 0 :=\n  sorry\n\ntheorem mem_ae_map_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : measurable f) {s : set \u03b2} (hs : is_measurable s) :\n    s \u2208 measure.ae (coe_fn (measure.map f) \u03bc) \u2194 f \u207b\u00b9' s \u2208 measure.ae \u03bc :=\n  sorry\n\ntheorem ae_map_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : measurable f) {p : \u03b2 \u2192 Prop}\n    (hp : is_measurable (set_of fun (x : \u03b2) => p x)) :\n    filter.eventually (fun (x : \u03b2) => p x) (measure.ae (coe_fn (measure.map f) \u03bc)) \u2194\n        filter.eventually (fun (x : \u03b1) => p (f x)) (measure.ae \u03bc) :=\n  mem_ae_map_iff hf hp\n\ntheorem ae_restrict_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {p : \u03b1 \u2192 Prop} (hp : is_measurable (set_of fun (x : \u03b1) => p x)) :\n    filter.eventually (fun (x : \u03b1) => p x) (measure.ae (measure.restrict \u03bc s)) \u2194\n        filter.eventually (fun (x : \u03b1) => x \u2208 s \u2192 p x) (measure.ae \u03bc) :=\n  sorry\n\ntheorem ae_imp_of_ae_restrict {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {p : \u03b1 \u2192 Prop}\n    (h : filter.eventually (fun (x : \u03b1) => p x) (measure.ae (measure.restrict \u03bc s))) :\n    filter.eventually (fun (x : \u03b1) => x \u2208 s \u2192 p x) (measure.ae \u03bc) :=\n  sorry\n\ntheorem ae_restrict_iff' {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {p : \u03b1 \u2192 Prop} (hp : is_measurable s) :\n    filter.eventually (fun (x : \u03b1) => p x) (measure.ae (measure.restrict \u03bc s)) \u2194\n        filter.eventually (fun (x : \u03b1) => x \u2208 s \u2192 p x) (measure.ae \u03bc) :=\n  sorry\n\ntheorem ae_smul_measure {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {p : \u03b1 \u2192 Prop}\n    (h : filter.eventually (fun (x : \u03b1) => p x) (measure.ae \u03bc)) (c : ennreal) :\n    filter.eventually (fun (x : \u03b1) => p x) (measure.ae (c \u2022 \u03bc)) :=\n  sorry\n\ntheorem ae_smul_measure_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {p : \u03b1 \u2192 Prop}\n    {c : ennreal} (hc : c \u2260 0) :\n    filter.eventually (fun (x : \u03b1) => p x) (measure.ae (c \u2022 \u03bc)) \u2194\n        filter.eventually (fun (x : \u03b1) => p x) (measure.ae \u03bc) :=\n  sorry\n\ntheorem ae_add_measure_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {p : \u03b1 \u2192 Prop}\n    {\u03bd : measure \u03b1} :\n    filter.eventually (fun (x : \u03b1) => p x) (measure.ae (\u03bc + \u03bd)) \u2194\n        filter.eventually (fun (x : \u03b1) => p x) (measure.ae \u03bc) \u2227\n          filter.eventually (fun (x : \u03b1) => p x) (measure.ae \u03bd) :=\n  add_eq_zero_iff\n\ntheorem ae_eq_comp {\u03b1 : Type u_1} {\u03b2 : Type u_2} {\u03b4 : Type u_4} [measurable_space \u03b1]\n    [measurable_space \u03b2] {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b4} {g' : \u03b2 \u2192 \u03b4} (hf : measurable f)\n    (h : filter.eventually_eq (measure.ae (coe_fn (measure.map f) \u03bc)) g g') :\n    filter.eventually_eq (measure.ae \u03bc) (g \u2218 f) (g' \u2218 f) :=\n  sorry\n\ntheorem le_ae_restrict {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    measure.ae \u03bc \u2293 filter.principal s \u2264 measure.ae (measure.restrict \u03bc s) :=\n  fun (s_1 : set \u03b1) (hs : s_1 \u2208 measure.ae (measure.restrict \u03bc s)) =>\n    iff.mpr filter.eventually_inf_principal (ae_imp_of_ae_restrict hs)\n\n@[simp] theorem ae_restrict_eq {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    (hs : is_measurable s) :\n    measure.ae (measure.restrict \u03bc s) = measure.ae \u03bc \u2293 filter.principal s :=\n  sorry\n\n@[simp] theorem ae_restrict_eq_bot {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    measure.ae (measure.restrict \u03bc s) = \u22a5 \u2194 coe_fn \u03bc s = 0 :=\n  iff.trans ae_eq_bot measure.restrict_eq_zero\n\n@[simp] theorem ae_restrict_ne_bot {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} :\n    filter.ne_bot (measure.ae (measure.restrict \u03bc s)) \u2194 0 < coe_fn \u03bc s :=\n  iff.trans (not_congr ae_restrict_eq_bot) (iff.symm pos_iff_ne_zero)\n\ntheorem self_mem_ae_restrict {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    (hs : is_measurable s) : s \u2208 measure.ae (measure.restrict \u03bc s) :=\n  sorry\n\n/-- A version of the Borel-Cantelli lemma: if `s\u1d62` is a sequence of measurable sets such that\n`\u2211 \u03bc s\u1d62` exists, then for almost all `x`, `x` does not belong to almost all `s\u1d62`. -/\ntheorem ae_eventually_not_mem {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : \u2115 \u2192 set \u03b1}\n    (hs : \u2200 (i : \u2115), is_measurable (s i)) (hs' : (tsum fun (i : \u2115) => coe_fn \u03bc (s i)) \u2260 \u22a4) :\n    filter.eventually (fun (x : \u03b1) => filter.eventually (fun (n : \u2115) => \u00acx \u2208 s n) filter.at_top)\n        (measure.ae \u03bc) :=\n  sorry\n\ntheorem mem_ae_dirac_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1} {a : \u03b1}\n    (hs : is_measurable s) : s \u2208 measure.ae (measure.dirac a) \u2194 a \u2208 s :=\n  sorry\n\ntheorem ae_dirac_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {a : \u03b1} {p : \u03b1 \u2192 Prop}\n    (hp : is_measurable (set_of fun (x : \u03b1) => p x)) :\n    filter.eventually (fun (x : \u03b1) => p x) (measure.ae (measure.dirac a)) \u2194 p a :=\n  mem_ae_dirac_iff hp\n\n@[simp] theorem ae_dirac_eq {\u03b1 : Type u_1} [measurable_space \u03b1] [measurable_singleton_class \u03b1]\n    (a : \u03b1) : measure.ae (measure.dirac a) = pure a :=\n  sorry\n\ntheorem ae_eq_dirac' {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    [measurable_singleton_class \u03b2] {a : \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : measurable f) :\n    filter.eventually_eq (measure.ae (measure.dirac a)) f (function.const \u03b1 (f a)) :=\n  iff.mpr\n    (ae_dirac_iff\n      ((fun (this : is_measurable (f \u207b\u00b9' singleton (f a))) => this)\n        (hf (is_measurable_singleton (f a)))))\n    rfl\n\ntheorem ae_eq_dirac {\u03b1 : Type u_1} {\u03b4 : Type u_4} [measurable_space \u03b1]\n    [measurable_singleton_class \u03b1] {a : \u03b1} (f : \u03b1 \u2192 \u03b4) :\n    filter.eventually_eq (measure.ae (measure.dirac a)) f (function.const \u03b1 (f a)) :=\n  sorry\n\n/-- If `s \u2286 t` modulo a set of measure `0`, then `\u03bc s \u2264 \u03bc t`. -/\ntheorem measure_mono_ae {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} {t : set \u03b1}\n    (H : filter.eventually_le (measure.ae \u03bc) s t) : coe_fn \u03bc s \u2264 coe_fn \u03bc t :=\n  sorry\n\ntheorem Mathlib.filter.eventually_le.measure_le {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b1} {t : set \u03b1} (H : filter.eventually_le (measure.ae \u03bc) s t) :\n    coe_fn \u03bc s \u2264 coe_fn \u03bc t :=\n  measure_mono_ae\n\n/-- If two sets are equal modulo a set of measure zero, then `\u03bc s = \u03bc t`. -/\ntheorem measure_congr {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} {t : set \u03b1}\n    (H : filter.eventually_eq (measure.ae \u03bc) s t) : coe_fn \u03bc s = coe_fn \u03bc t :=\n  le_antisymm (filter.eventually_le.measure_le (filter.eventually_eq.le H))\n    (filter.eventually_le.measure_le (filter.eventually_eq.le (filter.eventually_eq.symm H)))\n\ntheorem restrict_mono_ae {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1} {t : set \u03b1}\n    (h : filter.eventually_le (measure.ae \u03bc) s t) : measure.restrict \u03bc s \u2264 measure.restrict \u03bc t :=\n  sorry\n\ntheorem restrict_congr_set {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    {t : set \u03b1} (H : filter.eventually_eq (measure.ae \u03bc) s t) :\n    measure.restrict \u03bc s = measure.restrict \u03bc t :=\n  le_antisymm (restrict_mono_ae (filter.eventually_eq.le H))\n    (restrict_mono_ae (filter.eventually_eq.le (filter.eventually_eq.symm H)))\n\n/-- A measure `\u03bc` is called a probability measure if `\u03bc univ = 1`. -/\nclass probability_measure {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) where\n  measure_univ : coe_fn \u03bc set.univ = 1\n\nprotected instance measure.dirac.probability_measure {\u03b1 : Type u_1} [measurable_space \u03b1] {x : \u03b1} :\n    probability_measure (measure.dirac x) :=\n  probability_measure.mk (measure.dirac_apply_of_mem (set.mem_univ x))\n\n/-- A measure `\u03bc` is called finite if `\u03bc univ < \u22a4`. -/\nclass finite_measure {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) where\n  measure_univ_lt_top : coe_fn \u03bc set.univ < \u22a4\n\nprotected instance restrict.finite_measure {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1}\n    (\u03bc : measure \u03b1) [hs : fact (coe_fn \u03bc s < \u22a4)] : finite_measure (measure.restrict \u03bc s) :=\n  finite_measure.mk\n    (eq.mpr\n      (id\n        (Eq.trans\n          ((fun (\u1fb0 \u1fb0_1 : ennreal) (e_2 : \u1fb0 = \u1fb0_1) (\u1fb0_2 \u1fb0_3 : ennreal) (e_3 : \u1fb0_2 = \u1fb0_3) =>\n              congr (congr_arg Less e_2) e_3)\n            (coe_fn (measure.restrict \u03bc s) set.univ) (coe_fn \u03bc s)\n            (Eq.trans\n              (measure.restrict_apply (iff.mpr (iff_true_intro is_measurable.univ) True.intro))\n              ((fun (x x_1 : measure \u03b1) (e_1 : x = x_1) (\u1fb0 \u1fb0_1 : set \u03b1) (e_2 : \u1fb0 = \u1fb0_1) =>\n                  congr (congr_arg coe_fn e_1) e_2)\n                \u03bc \u03bc (Eq.refl \u03bc) (set.univ \u2229 s) s (set.univ_inter s)))\n            \u22a4 \u22a4 (Eq.refl \u22a4))\n          (propext (iff_true_intro (fact.elim hs)))))\n      trivial)\n\n/-- Measure `\u03bc` *has no atoms* if the measure of each singleton is zero.\n\nNB: Wikipedia assumes that for any measurable set `s` with positive `\u03bc`-measure,\nthere exists a measurable `t \u2286 s` such that `0 < \u03bc t < \u03bc s`. While this implies `\u03bc {x} = 0`,\nthe converse is not true. -/\nclass has_no_atoms {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) where\n  measure_singleton : \u2200 (x : \u03b1), coe_fn \u03bc (singleton x) = 0\n\ntheorem measure_lt_top {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) [finite_measure \u03bc]\n    (s : set \u03b1) : coe_fn \u03bc s < \u22a4 :=\n  has_le.le.trans_lt (measure_mono (set.subset_univ s)) finite_measure.measure_univ_lt_top\n\ntheorem measure_ne_top {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) [finite_measure \u03bc]\n    (s : set \u03b1) : coe_fn \u03bc s \u2260 \u22a4 :=\n  ne_of_lt (measure_lt_top \u03bc s)\n\n/-- `le_of_add_le_add_left` is normally applicable to `ordered_cancel_add_comm_monoid`,\nbut it holds for measures with the additional assumption that \u03bc is finite. -/\ntheorem measure.le_of_add_le_add_left {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03bd\u2081 : measure \u03b1} {\u03bd\u2082 : measure \u03b1} [finite_measure \u03bc] (A2 : \u03bc + \u03bd\u2081 \u2264 \u03bc + \u03bd\u2082) : \u03bd\u2081 \u2264 \u03bd\u2082 :=\n  fun (S : set \u03b1) (B1 : is_measurable S) =>\n    ennreal.le_of_add_le_add_left (measure_lt_top \u03bc S) (A2 S B1)\n\nprotected instance probability_measure.to_finite_measure {\u03b1 : Type u_1} [measurable_space \u03b1]\n    (\u03bc : measure \u03b1) [probability_measure \u03bc] : finite_measure \u03bc :=\n  finite_measure.mk\n    (eq.mpr\n      (id\n        (Eq.trans\n          ((fun (\u1fb0 \u1fb0_1 : ennreal) (e_2 : \u1fb0 = \u1fb0_1) (\u1fb0_2 \u1fb0_3 : ennreal) (e_3 : \u1fb0_2 = \u1fb0_3) =>\n              congr (congr_arg Less e_2) e_3)\n            (coe_fn \u03bc set.univ) 1 measure_univ \u22a4 \u22a4 (Eq.refl \u22a4))\n          (propext (iff_true_intro ennreal.one_lt_top))))\n      trivial)\n\ntheorem probability_measure.ne_zero {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [probability_measure \u03bc] : \u03bc \u2260 0 :=\n  sorry\n\ntheorem measure_countable {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    [has_no_atoms \u03bc] (h : set.countable s) : coe_fn \u03bc s = 0 :=\n  sorry\n\ntheorem measure_finite {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    [has_no_atoms \u03bc] (h : set.finite s) : coe_fn \u03bc s = 0 :=\n  measure_countable (set.finite.countable h)\n\ntheorem measure_finset {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    (s : finset \u03b1) : coe_fn \u03bc \u2191s = 0 :=\n  measure_finite (finset.finite_to_set s)\n\ntheorem insert_ae_eq_self {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    (a : \u03b1) (s : set \u03b1) : filter.eventually_eq (measure.ae \u03bc) (insert a s) s :=\n  iff.mpr union_ae_eq_right\n    (measure_mono_null (set.diff_subset (fun (b : \u03b1) => b = a) s) (measure_singleton a))\n\ntheorem Iio_ae_eq_Iic {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} : filter.eventually_eq (measure.ae \u03bc) (set.Iio a) (set.Iic a) :=\n  sorry\n\ntheorem Ioi_ae_eq_Ici {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} : filter.eventually_eq (measure.ae \u03bc) (set.Ioi a) (set.Ici a) :=\n  Iio_ae_eq_Iic\n\ntheorem Ioo_ae_eq_Ioc {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) (set.Ioo a b) (set.Ioc a b) :=\n  filter.eventually_eq.inter (ae_eq_refl fun (x : \u03b1) => preorder.lt a x) Iio_ae_eq_Iic\n\ntheorem Ioc_ae_eq_Icc {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) (set.Ioc a b) (set.Icc a b) :=\n  filter.eventually_eq.inter Ioi_ae_eq_Ici (ae_eq_refl fun (x : \u03b1) => preorder.le x b)\n\ntheorem Ioo_ae_eq_Ico {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) (set.Ioo a b) (set.Ico a b) :=\n  filter.eventually_eq.inter Ioi_ae_eq_Ici (ae_eq_refl fun (x : \u03b1) => preorder.lt x b)\n\ntheorem Ioo_ae_eq_Icc {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) (set.Ioo a b) (set.Icc a b) :=\n  filter.eventually_eq.inter Ioi_ae_eq_Ici Iio_ae_eq_Iic\n\ntheorem Ico_ae_eq_Icc {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) (set.Ico a b) (set.Icc a b) :=\n  filter.eventually_eq.inter (ae_eq_refl fun (x : \u03b1) => preorder.le a x) Iio_ae_eq_Iic\n\ntheorem Ico_ae_eq_Ioc {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} [has_no_atoms \u03bc]\n    [partial_order \u03b1] {a : \u03b1} {b : \u03b1} :\n    filter.eventually_eq (measure.ae \u03bc) (set.Ico a b) (set.Ioc a b) :=\n  filter.eventually_eq.trans (filter.eventually_eq.symm Ioo_ae_eq_Ico) Ioo_ae_eq_Ioc\n\ntheorem ite_ae_eq_of_measure_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03b3 : Type u_2}\n    (f : \u03b1 \u2192 \u03b3) (g : \u03b1 \u2192 \u03b3) (s : set \u03b1) (hs_zero : coe_fn \u03bc s = 0) :\n    filter.eventually_eq (measure.ae \u03bc) (fun (x : \u03b1) => ite (x \u2208 s) (f x) (g x)) g :=\n  sorry\n\ntheorem ite_ae_eq_of_measure_compl_zero {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {\u03b3 : Type u_2} (f : \u03b1 \u2192 \u03b3) (g : \u03b1 \u2192 \u03b3) (s : set \u03b1) (hs_zero : coe_fn \u03bc (s\u1d9c) = 0) :\n    filter.eventually_eq (measure.ae \u03bc) (fun (x : \u03b1) => ite (x \u2208 s) (f x) (g x)) f :=\n  sorry\n\nnamespace measure\n\n\n/-- A measure is called finite at filter `f` if it is finite at some set `s \u2208 f`.\nEquivalently, it is eventually finite at `s` in `f.lift' powerset`. -/\ndef finite_at_filter {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) (f : filter \u03b1) :=\n  \u2203 (s : set \u03b1), \u2203 (H : s \u2208 f), coe_fn \u03bc s < \u22a4\n\ntheorem finite_at_filter_of_finite {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [finite_measure \u03bc] (f : filter \u03b1) : finite_at_filter \u03bc f :=\n  Exists.intro set.univ (Exists.intro filter.univ_mem_sets (measure_lt_top \u03bc set.univ))\n\ntheorem finite_at_filter.exists_mem_basis {\u03b1 : Type u_1} {\u03b9 : Type u_5} [measurable_space \u03b1]\n    {\u03bc : measure \u03b1} {f : filter \u03b1} (h\u03bc : finite_at_filter \u03bc f) {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 set \u03b1}\n    (hf : filter.has_basis f p s) : \u2203 (i : \u03b9), \u2203 (hi : p i), coe_fn \u03bc (s i) < \u22a4 :=\n  sorry\n\ntheorem finite_at_bot {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) : finite_at_filter \u03bc \u22a5 :=\n  sorry\n\n/-- `\u03bc` has finite spanning sets in `C` if there is a countable sequence of sets in `C` that have\n  finite measures. This structure is a type, which is useful if we want to record extra properties\n  about the sets, such as that they are monotone.\n  `sigma_finite` is defined in terms of this: `\u03bc` is \u03c3-finite if there exists a sequence of\n  finite spanning sets in the collection of all measurable sets. -/\nstructure finite_spanning_sets_in {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    (C : set (set \u03b1))\n    where\n  set : \u2115 \u2192 set \u03b1\n  set_mem : \u2200 (i : \u2115), set i \u2208 C\n  finite : \u2200 (i : \u2115), coe_fn \u03bc (set i) < \u22a4\n  spanning : (set.Union fun (i : \u2115) => set i) = set.univ\n\nend measure\n\n\n/-- A measure `\u03bc` is called \u03c3-finite if there is a countable collection of sets\n  `{ A i | i \u2208 \u2115 }` such that `\u03bc (A i) < \u22a4` and `\u22c3 i, A i = s`. -/\ndef sigma_finite {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) :=\n  Nonempty (measure.finite_spanning_sets_in \u03bc (set_of fun (s : set \u03b1) => is_measurable s))\n\n/-- If `\u03bc` is \u03c3-finite it has finite spanning sets in the collection of all measurable sets. -/\ndef measure.to_finite_spanning_sets_in {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [h : sigma_finite \u03bc] :\n    measure.finite_spanning_sets_in \u03bc (set_of fun (s : set \u03b1) => is_measurable s) :=\n  Classical.choice h\n\n/-- A noncomputable way to get a monotone collection of sets that span `univ` and have finite\n  measure using `classical.some`. This definition satisfies monotonicity in addition to all other\n  properties in `sigma_finite`. -/\ndef spanning_sets {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) [sigma_finite \u03bc] (i : \u2115) :\n    set \u03b1 :=\n  set.accumulate (measure.finite_spanning_sets_in.set (measure.to_finite_spanning_sets_in \u03bc)) i\n\ntheorem monotone_spanning_sets {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [sigma_finite \u03bc] : monotone (spanning_sets \u03bc) :=\n  set.monotone_accumulate\n\ntheorem is_measurable_spanning_sets {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [sigma_finite \u03bc] (i : \u2115) : is_measurable (spanning_sets \u03bc i) :=\n  sorry\n\ntheorem measure_spanning_sets_lt_top {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [sigma_finite \u03bc] (i : \u2115) : coe_fn \u03bc (spanning_sets \u03bc i) < \u22a4 :=\n  measure_bUnion_lt_top (set.finite_le_nat i)\n    fun (j : \u2115) (_x : j \u2208 fun (y : \u2115) => nat.less_than_or_equal y i) =>\n      measure.finite_spanning_sets_in.finite (measure.to_finite_spanning_sets_in \u03bc) j\n\ntheorem Union_spanning_sets {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) [sigma_finite \u03bc] :\n    (set.Union fun (i : \u2115) => spanning_sets \u03bc i) = set.univ :=\n  sorry\n\ntheorem is_countably_spanning_spanning_sets {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [sigma_finite \u03bc] : is_countably_spanning (set.range (spanning_sets \u03bc)) :=\n  Exists.intro (spanning_sets \u03bc) { left := set.mem_range_self, right := Union_spanning_sets \u03bc }\n\nnamespace measure\n\n\ntheorem supr_restrict_spanning_sets {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {s : set \u03b1}\n    [sigma_finite \u03bc] (hs : is_measurable s) :\n    (supr fun (i : \u2115) => coe_fn (restrict \u03bc (spanning_sets \u03bc i)) s) = coe_fn \u03bc s :=\n  sorry\n\nnamespace finite_spanning_sets_in\n\n\n/-- If `\u03bc` has finite spanning sets in `C` and `C \u2286 D` then `\u03bc` has finite spanning sets in `D`. -/\nprotected def mono {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {C : set (set \u03b1)}\n    {D : set (set \u03b1)} (h : finite_spanning_sets_in \u03bc C) (hC : C \u2286 D) :\n    finite_spanning_sets_in \u03bc D :=\n  mk (finite_spanning_sets_in.set h) sorry (finite_spanning_sets_in.finite h)\n    (finite_spanning_sets_in.spanning h)\n\n/-- If `\u03bc` has finite spanning sets in the collection of measurable sets `C`, then `\u03bc` is \u03c3-finite.\n-/\nprotected theorem sigma_finite {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {C : set (set \u03b1)}\n    (h : finite_spanning_sets_in \u03bc C) (hC : \u2200 (s : set \u03b1), s \u2208 C \u2192 is_measurable s) :\n    sigma_finite \u03bc :=\n  Nonempty.intro (finite_spanning_sets_in.mono h hC)\n\n/-- An extensionality for measures. It is `ext_of_generate_from_of_Union` formulated in terms of\n`finite_spanning_sets_in`. -/\nprotected theorem ext {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {C : set (set \u03b1)} (hA : _inst_1 = measurable_space.generate_from C) (hC : is_pi_system C)\n    (h : finite_spanning_sets_in \u03bc C) (h_eq : \u2200 (s : set \u03b1), s \u2208 C \u2192 coe_fn \u03bc s = coe_fn \u03bd s) :\n    \u03bc = \u03bd :=\n  ext_of_generate_from_of_Union C (fun (i : \u2115) => finite_spanning_sets_in.set h i) hA hC\n    (finite_spanning_sets_in.spanning h) (finite_spanning_sets_in.set_mem h)\n    (finite_spanning_sets_in.finite h) h_eq\n\nprotected theorem is_countably_spanning {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {C : set (set \u03b1)} (h : finite_spanning_sets_in \u03bc C) : is_countably_spanning C :=\n  Exists.intro (fun (i : \u2115) => finite_spanning_sets_in.set h i)\n    { left := finite_spanning_sets_in.set_mem h, right := finite_spanning_sets_in.spanning h }\n\nend finite_spanning_sets_in\n\n\ntheorem sigma_finite_of_not_nonempty {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    (h\u03b1 : \u00acNonempty \u03b1) : sigma_finite \u03bc :=\n  sorry\n\ntheorem sigma_finite_of_countable {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {S : set (set \u03b1)} (hc : set.countable S) (h\u03bc : \u2200 (s : set \u03b1), s \u2208 S \u2192 coe_fn \u03bc s < \u22a4)\n    (hU : \u22c3\u2080S = set.univ) : sigma_finite \u03bc :=\n  sorry\n\nend measure\n\n\n/-- Every finite measure is \u03c3-finite. -/\nprotected instance finite_measure.to_sigma_finite {\u03b1 : Type u_1} [measurable_space \u03b1]\n    (\u03bc : measure \u03b1) [finite_measure \u03bc] : sigma_finite \u03bc :=\n  Nonempty.intro\n    (measure.finite_spanning_sets_in.mk (fun (_x : \u2115) => set.univ)\n      (fun (_x : \u2115) => is_measurable.univ) (fun (_x : \u2115) => measure_lt_top \u03bc set.univ)\n      (set.Union_const set.univ))\n\nprotected instance restrict.sigma_finite {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    [sigma_finite \u03bc] (s : set \u03b1) : sigma_finite (measure.restrict \u03bc s) :=\n  Nonempty.intro\n    (measure.finite_spanning_sets_in.mk (spanning_sets \u03bc) (is_measurable_spanning_sets \u03bc)\n      (fun (i : \u2115) =>\n        eq.mpr\n          (id\n            (Eq._oldrec (Eq.refl (coe_fn (measure.restrict \u03bc s) (spanning_sets \u03bc i) < \u22a4))\n              (measure.restrict_apply (is_measurable_spanning_sets \u03bc i))))\n          (has_le.le.trans_lt (measure_mono (set.inter_subset_left (spanning_sets \u03bc i) s))\n            (measure_spanning_sets_lt_top \u03bc i)))\n      (Union_spanning_sets \u03bc))\n\nprotected instance sum.sigma_finite {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03b9 : Type u_2} [fintype \u03b9]\n    (\u03bc : \u03b9 \u2192 measure \u03b1) [\u2200 (i : \u03b9), sigma_finite (\u03bc i)] : sigma_finite (measure.sum \u03bc) :=\n  sorry\n\nprotected instance add.sigma_finite {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1)\n    (\u03bd : measure \u03b1) [sigma_finite \u03bc] [sigma_finite \u03bd] : sigma_finite (\u03bc + \u03bd) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (sigma_finite (\u03bc + \u03bd))) (Eq.symm (measure.sum_cond \u03bc \u03bd))))\n    (sum.sigma_finite fun (b : Bool) => cond b \u03bc \u03bd)\n\n/-- A measure is called locally finite if it is finite in some neighborhood of each point. -/\nclass locally_finite_measure {\u03b1 : Type u_1} [measurable_space \u03b1] [topological_space \u03b1]\n    (\u03bc : measure \u03b1)\n    where\n  finite_at_nhds : \u2200 (x : \u03b1), measure.finite_at_filter \u03bc (nhds x)\n\nprotected instance finite_measure.to_locally_finite_measure {\u03b1 : Type u_1} [measurable_space \u03b1]\n    [topological_space \u03b1] (\u03bc : measure \u03b1) [finite_measure \u03bc] : locally_finite_measure \u03bc :=\n  locally_finite_measure.mk fun (x : \u03b1) => measure.finite_at_filter_of_finite \u03bc (nhds x)\n\ntheorem measure.finite_at_nhds {\u03b1 : Type u_1} [measurable_space \u03b1] [topological_space \u03b1]\n    (\u03bc : measure \u03b1) [locally_finite_measure \u03bc] (x : \u03b1) : measure.finite_at_filter \u03bc (nhds x) :=\n  locally_finite_measure.finite_at_nhds x\n\ntheorem measure.smul_finite {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure \u03b1) [finite_measure \u03bc]\n    {c : ennreal} (hc : c < \u22a4) : finite_measure (c \u2022 \u03bc) :=\n  finite_measure.mk\n    (eq.mpr\n      (id (Eq._oldrec (Eq.refl (coe_fn (c \u2022 \u03bc) set.univ < \u22a4)) (measure.smul_apply c \u03bc set.univ)))\n      (ennreal.mul_lt_top hc (measure_lt_top \u03bc set.univ)))\n\ntheorem measure.exists_is_open_measure_lt_top {\u03b1 : Type u_1} [measurable_space \u03b1]\n    [topological_space \u03b1] (\u03bc : measure \u03b1) [locally_finite_measure \u03bc] (x : \u03b1) :\n    \u2203 (s : set \u03b1), x \u2208 s \u2227 is_open s \u2227 coe_fn \u03bc s < \u22a4 :=\n  sorry\n\nprotected instance sigma_finite_of_locally_finite {\u03b1 : Type u_1} [measurable_space \u03b1]\n    [topological_space \u03b1] [topological_space.second_countable_topology \u03b1] {\u03bc : measure \u03b1}\n    [locally_finite_measure \u03bc] : sigma_finite \u03bc :=\n  sorry\n\n/-- If two finite measures give the same mass to the whole space and coincide on a \u03c0-system made\nof measurable sets, then they coincide on all sets in the \u03c3-algebra generated by the \u03c0-system. -/\ntheorem ext_on_measurable_space_of_generate_finite {\u03b1 : Type u_1} (m\u2080 : measurable_space \u03b1)\n    {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} [finite_measure \u03bc] (C : set (set \u03b1))\n    (h\u03bc\u03bd : \u2200 (s : set \u03b1), s \u2208 C \u2192 coe_fn \u03bc s = coe_fn \u03bd s) {m : measurable_space \u03b1} (h : m \u2264 m\u2080)\n    (hA : m = measurable_space.generate_from C) (hC : is_pi_system C)\n    (h_univ : coe_fn \u03bc set.univ = coe_fn \u03bd set.univ) {s : set \u03b1}\n    (hs : measurable_space.is_measurable' m s) : coe_fn \u03bc s = coe_fn \u03bd s :=\n  sorry\n\n/-- Two finite measures are equal if they are equal on the \u03c0-system generating the \u03c3-algebra\n  (and `univ`). -/\ntheorem ext_of_generate_finite {\u03b1 : Type u_1} [measurable_space \u03b1] (C : set (set \u03b1))\n    (hA : _inst_1 = measurable_space.generate_from C) (hC : is_pi_system C) {\u03bc : measure \u03b1}\n    {\u03bd : measure \u03b1} [finite_measure \u03bc] (h\u03bc\u03bd : \u2200 (s : set \u03b1), s \u2208 C \u2192 coe_fn \u03bc s = coe_fn \u03bd s)\n    (h_univ : coe_fn \u03bc set.univ = coe_fn \u03bd set.univ) : \u03bc = \u03bd :=\n  measure.ext\n    fun (s : set \u03b1) (hs : is_measurable s) =>\n      ext_on_measurable_space_of_generate_finite _inst_1 C h\u03bc\u03bd (le_refl _inst_1) hA hC h_univ hs\n\nnamespace measure\n\n\nnamespace finite_at_filter\n\n\ntheorem filter_mono {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1}\n    {g : filter \u03b1} (h : f \u2264 g) : finite_at_filter \u03bc g \u2192 finite_at_filter \u03bc f :=\n  sorry\n\ntheorem inf_of_left {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1}\n    {g : filter \u03b1} (h : finite_at_filter \u03bc f) : finite_at_filter \u03bc (f \u2293 g) :=\n  filter_mono inf_le_left h\n\ntheorem inf_of_right {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1}\n    {g : filter \u03b1} (h : finite_at_filter \u03bc g) : finite_at_filter \u03bc (f \u2293 g) :=\n  filter_mono inf_le_right h\n\n@[simp] theorem inf_ae_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1} :\n    finite_at_filter \u03bc (f \u2293 ae \u03bc) \u2194 finite_at_filter \u03bc f :=\n  sorry\n\ntheorem of_inf_ae {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1} :\n    finite_at_filter \u03bc (f \u2293 ae \u03bc) \u2192 finite_at_filter \u03bc f :=\n  iff.mp inf_ae_iff\n\ntheorem filter_mono_ae {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1}\n    {g : filter \u03b1} (h : f \u2293 ae \u03bc \u2264 g) (hg : finite_at_filter \u03bc g) : finite_at_filter \u03bc f :=\n  iff.mp inf_ae_iff (filter_mono h hg)\n\nprotected theorem measure_mono {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {f : filter \u03b1} (h : \u03bc \u2264 \u03bd) : finite_at_filter \u03bd f \u2192 finite_at_filter \u03bc f :=\n  sorry\n\nprotected theorem mono {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    {f : filter \u03b1} {g : filter \u03b1} (hf : f \u2264 g) (h\u03bc : \u03bc \u2264 \u03bd) :\n    finite_at_filter \u03bd g \u2192 finite_at_filter \u03bc f :=\n  fun (h : finite_at_filter \u03bd g) => finite_at_filter.measure_mono h\u03bc (filter_mono hf h)\n\nprotected theorem eventually {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1}\n    (h : finite_at_filter \u03bc f) :\n    filter.eventually (fun (s : set \u03b1) => coe_fn \u03bc s < \u22a4) (filter.lift' f set.powerset) :=\n  sorry\n\ntheorem filter_sup {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {f : filter \u03b1}\n    {g : filter \u03b1} : finite_at_filter \u03bc f \u2192 finite_at_filter \u03bc g \u2192 finite_at_filter \u03bc (f \u2294 g) :=\n  sorry\n\nend finite_at_filter\n\n\ntheorem finite_at_nhds_within {\u03b1 : Type u_1} [measurable_space \u03b1] [topological_space \u03b1]\n    (\u03bc : measure \u03b1) [locally_finite_measure \u03bc] (x : \u03b1) (s : set \u03b1) :\n    finite_at_filter \u03bc (nhds_within x s) :=\n  finite_at_filter.inf_of_left (finite_at_nhds \u03bc x)\n\n@[simp] theorem finite_at_principal {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n    {s : set \u03b1} : finite_at_filter \u03bc (filter.principal s) \u2194 coe_fn \u03bc s < \u22a4 :=\n  sorry\n\n/-! ### Subtraction of measures -/\n\n/-- The measure `\u03bc - \u03bd` is defined to be the least measure `\u03c4` such that `\u03bc \u2264 \u03c4 + \u03bd`.\nIt is the equivalent of `(\u03bc - \u03bd) \u2294 0` if `\u03bc` and `\u03bd` were signed measures.\nCompare with `ennreal.has_sub`.\nSpecifically, note that if you have `\u03b1 = {1,2}`, and  `\u03bc {1} = 2`, `\u03bc {2} = 0`, and\n`\u03bd {2} = 2`, `\u03bd {1} = 0`, then `(\u03bc - \u03bd) {1, 2} = 2`. However, if `\u03bc \u2264 \u03bd`, and\n`\u03bd univ \u2260 \u22a4`, then `(\u03bc - \u03bd) + \u03bd = \u03bc`. -/\nprotected instance has_sub {\u03b1 : Type u_1} [measurable_space \u03b1] : Sub (measure \u03b1) :=\n  { sub := fun (\u03bc \u03bd : measure \u03b1) => Inf (set_of fun (\u03c4 : measure \u03b1) => \u03bc \u2264 \u03c4 + \u03bd) }\n\ntheorem sub_def {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} :\n    \u03bc - \u03bd = Inf (set_of fun (d : measure \u03b1) => \u03bc \u2264 d + \u03bd) :=\n  rfl\n\ntheorem sub_eq_zero_of_le {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    (h : \u03bc \u2264 \u03bd) : \u03bc - \u03bd = 0 :=\n  sorry\n\n/-- This application lemma only works in special circumstances. Given knowledge of\nwhen `\u03bc \u2264 \u03bd` and `\u03bd \u2264 \u03bc`, a more general application lemma can be written. -/\ntheorem sub_apply {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1} {s : set \u03b1}\n    [finite_measure \u03bd] (h\u2081 : is_measurable s) (h\u2082 : \u03bd \u2264 \u03bc) :\n    coe_fn (\u03bc - \u03bd) s = coe_fn \u03bc s - coe_fn \u03bd s :=\n  sorry\n\ntheorem sub_add_cancel_of_le {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure \u03b1} {\u03bd : measure \u03b1}\n    [finite_measure \u03bd] (h\u2081 : \u03bd \u2264 \u03bc) : \u03bc - \u03bd + \u03bd = \u03bc :=\n  sorry\n\nend measure\n\n\nend measure_theory\n\n\nnamespace measurable_equiv\n\n\n/-! Interactions of measurable equivalences and measures -/\n\n/-- If we map a measure along a measurable equivalence, we can compute the measure on all sets\n  (not just the measurable ones). -/\nprotected theorem map_apply {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure_theory.measure \u03b1} (f : \u03b1 \u2243\u1d50 \u03b2) (s : set \u03b2) :\n    coe_fn (coe_fn (measure_theory.measure.map \u21d1f) \u03bc) s = coe_fn \u03bc (\u21d1f \u207b\u00b9' s) :=\n  sorry\n\n@[simp] theorem map_symm_map {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure_theory.measure \u03b1} (e : \u03b1 \u2243\u1d50 \u03b2) :\n    coe_fn (measure_theory.measure.map \u21d1(symm e)) (coe_fn (measure_theory.measure.map \u21d1e) \u03bc) = \u03bc :=\n  sorry\n\n@[simp] theorem map_map_symm {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bd : measure_theory.measure \u03b2} (e : \u03b1 \u2243\u1d50 \u03b2) :\n    coe_fn (measure_theory.measure.map \u21d1e) (coe_fn (measure_theory.measure.map \u21d1(symm e)) \u03bd) = \u03bd :=\n  sorry\n\ntheorem map_measurable_equiv_injective {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] (e : \u03b1 \u2243\u1d50 \u03b2) : function.injective \u21d1(measure_theory.measure.map \u21d1e) :=\n  sorry\n\ntheorem map_apply_eq_iff_map_symm_apply_eq {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {\u03bc : measure_theory.measure \u03b1} {\u03bd : measure_theory.measure \u03b2}\n    (e : \u03b1 \u2243\u1d50 \u03b2) :\n    coe_fn (measure_theory.measure.map \u21d1e) \u03bc = \u03bd \u2194\n        coe_fn (measure_theory.measure.map \u21d1(symm e)) \u03bd = \u03bc :=\n  sorry\n\nend measurable_equiv\n\n\n/-- A measure is complete if every null set is also measurable.\n  A null set is a subset of a measurable set with measure `0`.\n  Since every measure is defined as a special case of an outer measure, we can more simply state\n  that a set `s` is null if `\u03bc s = 0`. -/\ndef measure_theory.measure.is_complete {\u03b1 : Type u_1} {_x : measurable_space \u03b1}\n    (\u03bc : measure_theory.measure \u03b1) :=\n  \u2200 (s : set \u03b1), coe_fn \u03bc s = 0 \u2192 is_measurable s\n\n/-- A set is null measurable if it is the union of a null set and a measurable set. -/\ndef is_null_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure_theory.measure \u03b1)\n    (s : set \u03b1) :=\n  \u2203 (t : set \u03b1), \u2203 (z : set \u03b1), s = t \u222a z \u2227 is_measurable t \u2227 coe_fn \u03bc z = 0\n\ntheorem is_null_measurable_iff {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1}\n    {s : set \u03b1} :\n    is_null_measurable \u03bc s \u2194 \u2203 (t : set \u03b1), t \u2286 s \u2227 is_measurable t \u2227 coe_fn \u03bc (s \\ t) = 0 :=\n  sorry\n\ntheorem is_null_measurable_measure_eq {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} {t : set \u03b1} (st : t \u2286 s)\n    (hz : coe_fn \u03bc (s \\ t) = 0) : coe_fn \u03bc s = coe_fn \u03bc t :=\n  sorry\n\ntheorem is_measurable.is_null_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1}\n    (\u03bc : measure_theory.measure \u03b1) (hs : is_measurable s) : is_null_measurable \u03bc s :=\n  sorry\n\ntheorem is_null_measurable_of_complete {\u03b1 : Type u_1} [measurable_space \u03b1] {s : set \u03b1}\n    (\u03bc : measure_theory.measure \u03b1) [c : measure_theory.measure.is_complete \u03bc] :\n    is_null_measurable \u03bc s \u2194 is_measurable s :=\n  sorry\n\ntheorem is_null_measurable.union_null {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} {z : set \u03b1} (hs : is_null_measurable \u03bc s)\n    (hz : coe_fn \u03bc z = 0) : is_null_measurable \u03bc (s \u222a z) :=\n  sorry\n\ntheorem null_is_null_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1}\n    {z : set \u03b1} (hz : coe_fn \u03bc z = 0) : is_null_measurable \u03bc z :=\n  sorry\n\ntheorem is_null_measurable.Union_nat {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : \u2115 \u2192 set \u03b1} (hs : \u2200 (i : \u2115), is_null_measurable \u03bc (s i)) :\n    is_null_measurable \u03bc (set.Union s) :=\n  sorry\n\ntheorem is_measurable.diff_null {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1}\n    {s : set \u03b1} {z : set \u03b1} (hs : is_measurable s) (hz : coe_fn \u03bc z = 0) :\n    is_null_measurable \u03bc (s \\ z) :=\n  sorry\n\ntheorem is_null_measurable.diff_null {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} {z : set \u03b1} (hs : is_null_measurable \u03bc s)\n    (hz : coe_fn \u03bc z = 0) : is_null_measurable \u03bc (s \\ z) :=\n  sorry\n\ntheorem is_null_measurable.compl {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1}\n    {s : set \u03b1} (hs : is_null_measurable \u03bc s) : is_null_measurable \u03bc (s\u1d9c) :=\n  sorry\n\ntheorem is_null_measurable_iff_ae {\u03b1 : Type u_1} [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1}\n    {s : set \u03b1} :\n    is_null_measurable \u03bc s \u2194\n        \u2203 (t : set \u03b1), is_measurable t \u2227 filter.eventually_eq (measure_theory.measure.ae \u03bc) s t :=\n  sorry\n\ntheorem is_null_measurable_iff_sandwich {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} :\n    is_null_measurable \u03bc s \u2194\n        \u2203 (t : set \u03b1),\n          \u2203 (u : set \u03b1), is_measurable t \u2227 is_measurable u \u2227 t \u2286 s \u2227 s \u2286 u \u2227 coe_fn \u03bc (u \\ t) = 0 :=\n  sorry\n\ntheorem restrict_apply_of_is_null_measurable {\u03b1 : Type u_1} [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} {t : set \u03b1}\n    (ht : is_null_measurable (measure_theory.measure.restrict \u03bc s) t) :\n    coe_fn (measure_theory.measure.restrict \u03bc s) t = coe_fn \u03bc (t \u2229 s) :=\n  sorry\n\n/-- The measurable space of all null measurable sets. -/\ndef null_measurable {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure_theory.measure \u03b1) :\n    measurable_space \u03b1 :=\n  measurable_space.mk (is_null_measurable \u03bc) sorry sorry sorry\n\n/-- Given a measure we can complete it to a (complete) measure on all null measurable sets. -/\ndef completion {\u03b1 : Type u_1} [measurable_space \u03b1] (\u03bc : measure_theory.measure \u03b1) :\n    measure_theory.measure \u03b1 :=\n  measure_theory.measure.mk (measure_theory.measure.to_outer_measure \u03bc) sorry sorry\n\nprotected instance completion.is_complete {\u03b1 : Type u_1} [measurable_space \u03b1]\n    (\u03bc : measure_theory.measure \u03b1) : measure_theory.measure.is_complete (completion \u03bc) :=\n  fun (z : set \u03b1) (hz : coe_fn (completion \u03bc) z = 0) => null_is_null_measurable hz\n\ntheorem measurable.ae_eq {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure_theory.measure \u03b1} [h\u03bc : measure_theory.measure.is_complete \u03bc] {f : \u03b1 \u2192 \u03b2}\n    {g : \u03b1 \u2192 \u03b2} (hf : measurable f) (hfg : filter.eventually_eq (measure_theory.measure.ae \u03bc) f g) :\n    measurable g :=\n  sorry\n\nnamespace measure_theory\n\n\n/-- A measure space is a measurable space equipped with a\n  measure, referred to as `volume`. -/\nclass measure_space (\u03b1 : Type u_6) extends measurable_space \u03b1 where\n  volume : measure \u03b1\n\n/-- `volume` is the canonical  measure on `\u03b1`. -/\n/-- The tactic `exact volume`, to be used in optional (`auto_param`) arguments. -/\nend measure_theory\n\n\n/-!\n# Almost everywhere measurable functions\n\nA function is almost everywhere measurable if it coincides almost everywhere with a measurable\nfunction. We define this property, called `ae_measurable f \u03bc`, and discuss several of its properties\nthat are analogous to properties of measurable functions.\n-/\n\n/-- A function is almost everywhere measurable if it coincides almost everywhere with a measurable\nfunction. -/\ndef ae_measurable {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    (f : \u03b1 \u2192 \u03b2)\n    (\u03bc :\n      autoParam (measure_theory.measure \u03b1)\n        (Lean.Syntax.ident Lean.SourceInfo.none\n          (String.toSubstring \"Mathlib.measure_theory.volume_tac\")\n          (Lean.Name.mkStr\n            (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous \"Mathlib\") \"measure_theory\")\n            \"volume_tac\")\n          [])) :=\n  \u2203 (g : \u03b1 \u2192 \u03b2), measurable g \u2227 filter.eventually_eq (measure_theory.measure.ae \u03bc) f g\n\ntheorem measurable.ae_measurable {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} (h : measurable f) :\n    ae_measurable f :=\n  Exists.intro f { left := h, right := measure_theory.ae_eq_refl f }\n\ntheorem subsingleton.ae_measurable {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} [subsingleton \u03b1] :\n    ae_measurable f :=\n  measurable.ae_measurable subsingleton.measurable\n\n@[simp] theorem ae_measurable_zero {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} : ae_measurable f :=\n  sorry\n\ntheorem ae_measurable_iff_measurable {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1}\n    [measure_theory.measure.is_complete \u03bc] : ae_measurable f \u2194 measurable f :=\n  sorry\n\nnamespace ae_measurable\n\n\n/-- Given an almost everywhere measurable function `f`, associate to it a measurable function\nthat coincides with it almost everywhere. `f` is explicit in the definition to make sure that\nit shows in pretty-printing. -/\ndef mk {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure_theory.measure \u03b1} (f : \u03b1 \u2192 \u03b2) (h : ae_measurable f) : \u03b1 \u2192 \u03b2 :=\n  classical.some h\n\ntheorem measurable_mk {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} (h : ae_measurable f) : measurable (mk f h) :=\n  and.left (classical.some_spec h)\n\ntheorem ae_eq_mk {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {\u03bc : measure_theory.measure \u03b1} (h : ae_measurable f) :\n    filter.eventually_eq (measure_theory.measure.ae \u03bc) f (mk f h) :=\n  and.right (classical.some_spec h)\n\ntheorem congr {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {g : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} (hf : ae_measurable f)\n    (h : filter.eventually_eq (measure_theory.measure.ae \u03bc) f g) : ae_measurable g :=\n  Exists.intro (mk f hf)\n    { left := measurable_mk hf,\n      right := filter.eventually_eq.trans (filter.eventually_eq.symm h) (ae_eq_mk hf) }\n\ntheorem mono_measure {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} {\u03bd : measure_theory.measure \u03b1} (h : ae_measurable f)\n    (h' : \u03bd \u2264 \u03bc) : ae_measurable f :=\n  Exists.intro (mk f h)\n    { left := measurable_mk h,\n      right := filter.eventually.filter_mono (measure_theory.ae_mono h') (ae_eq_mk h) }\n\ntheorem mono_set {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} {t : set \u03b1} (h : s \u2286 t) (ht : ae_measurable f) :\n    ae_measurable f :=\n  mono_measure ht (measure_theory.measure.restrict_mono h le_rfl)\n\ntheorem ae_mem_imp_eq_mk {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} (h : ae_measurable f) :\n    filter.eventually (fun (x : \u03b1) => x \u2208 s \u2192 f x = mk f h x) (measure_theory.measure.ae \u03bc) :=\n  measure_theory.ae_imp_of_ae_restrict (ae_eq_mk h)\n\ntheorem ae_inf_principal_eq_mk {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1}\n    (h : ae_measurable f) :\n    filter.eventually_eq (measure_theory.measure.ae \u03bc \u2293 filter.principal s) f (mk f h) :=\n  measure_theory.le_ae_restrict (ae_eq_mk h)\n\ntheorem add_measure {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure_theory.measure \u03b1} {\u03bd : measure_theory.measure \u03b1} {f : \u03b1 \u2192 \u03b2} (h\u03bc : ae_measurable f)\n    (h\u03bd : ae_measurable f) : ae_measurable f :=\n  sorry\n\ntheorem smul_measure {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} (h : ae_measurable f) (c : ennreal) :\n    ae_measurable f :=\n  Exists.intro (mk f h)\n    { left := measurable_mk h, right := measure_theory.ae_smul_measure (ae_eq_mk h) c }\n\ntheorem comp_measurable {\u03b1 : Type u_1} {\u03b2 : Type u_2} {\u03b4 : Type u_4} [measurable_space \u03b1]\n    [measurable_space \u03b2] {\u03bc : measure_theory.measure \u03b1} [measurable_space \u03b4] {f : \u03b1 \u2192 \u03b4} {g : \u03b4 \u2192 \u03b2}\n    (hg : ae_measurable g) (hf : measurable f) : ae_measurable (g \u2218 f) :=\n  Exists.intro (mk g hg \u2218 f)\n    { left := measurable.comp (measurable_mk hg) hf,\n      right := measure_theory.ae_eq_comp hf (ae_eq_mk hg) }\n\ntheorem prod_mk {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {\u03bc : measure_theory.measure \u03b1} {\u03b3 : Type u_3} [measurable_space \u03b3] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3}\n    (hf : ae_measurable f) (hg : ae_measurable g) : ae_measurable fun (x : \u03b1) => (f x, g x) :=\n  Exists.intro (fun (a : \u03b1) => (mk f hf a, mk g hg a))\n    { left := measurable.prod_mk (measurable_mk hf) (measurable_mk hg),\n      right := filter.eventually_eq.prod_mk (ae_eq_mk hf) (ae_eq_mk hg) }\n\ntheorem is_null_measurable {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} (h : ae_measurable f) {s : set \u03b2}\n    (hs : is_measurable s) : is_null_measurable \u03bc (f \u207b\u00b9' s) :=\n  sorry\n\nend ae_measurable\n\n\ntheorem ae_measurable_congr {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1] [measurable_space \u03b2]\n    {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1}\n    (h : filter.eventually_eq (measure_theory.measure.ae \u03bc) f g) :\n    ae_measurable f \u2194 ae_measurable g :=\n  { mp := fun (hf : ae_measurable f) => ae_measurable.congr hf h,\n    mpr := fun (hg : ae_measurable g) => ae_measurable.congr hg (filter.eventually_eq.symm h) }\n\n@[simp] theorem ae_measurable_add_measure_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} {\u03bd : measure_theory.measure \u03b1} :\n    ae_measurable f \u2194 ae_measurable f \u2227 ae_measurable f :=\n  sorry\n\n@[simp] theorem ae_measurable_const {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {\u03bc : measure_theory.measure \u03b1} {b : \u03b2} : ae_measurable fun (a : \u03b1) => b :=\n  measurable.ae_measurable measurable_const\n\n@[simp] theorem ae_measurable_smul_measure_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} {\u03bc : measure_theory.measure \u03b1} {c : ennreal} (hc : c \u2260 0) :\n    ae_measurable f \u2194 ae_measurable f :=\n  sorry\n\ntheorem measurable.comp_ae_measurable {\u03b1 : Type u_1} {\u03b2 : Type u_2} {\u03b4 : Type u_4}\n    [measurable_space \u03b1] [measurable_space \u03b2] {\u03bc : measure_theory.measure \u03b1} [measurable_space \u03b4]\n    {f : \u03b1 \u2192 \u03b4} {g : \u03b4 \u2192 \u03b2} (hg : measurable g) (hf : ae_measurable f) : ae_measurable (g \u2218 f) :=\n  Exists.intro (g \u2218 ae_measurable.mk f hf)\n    { left := measurable.comp hg (ae_measurable.measurable_mk hf),\n      right := filter.eventually_eq.fun_comp (ae_measurable.ae_eq_mk hf) g }\n\ntheorem ae_measurable_of_zero_measure {\u03b1 : Type u_1} {\u03b2 : Type u_2} [measurable_space \u03b1]\n    [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} : ae_measurable f :=\n  dite (Nonempty \u03b1) (fun (h : Nonempty \u03b1) => ae_measurable.congr ae_measurable_const rfl)\n    fun (h : \u00acNonempty \u03b1) => measurable.ae_measurable (measurable_of_not_nonempty h f)\n\nnamespace is_compact\n\n\ntheorem finite_measure_of_nhds_within {\u03b1 : Type u_1} [topological_space \u03b1] [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} (hs : is_compact s) :\n    (\u2200 (a : \u03b1), a \u2208 s \u2192 measure_theory.measure.finite_at_filter \u03bc (nhds_within a s)) \u2192\n        coe_fn \u03bc s < \u22a4 :=\n  sorry\n\ntheorem finite_measure {\u03b1 : Type u_1} [topological_space \u03b1] [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} [measure_theory.locally_finite_measure \u03bc]\n    (hs : is_compact s) : coe_fn \u03bc s < \u22a4 :=\n  finite_measure_of_nhds_within hs\n    fun (a : \u03b1) (ha : a \u2208 s) => measure_theory.measure.finite_at_nhds_within \u03bc a s\n\ntheorem measure_zero_of_nhds_within {\u03b1 : Type u_1} [topological_space \u03b1] [measurable_space \u03b1]\n    {\u03bc : measure_theory.measure \u03b1} {s : set \u03b1} (hs : is_compact s) :\n    (\u2200 (a : \u03b1) (H : a \u2208 s), \u2203 (t : set \u03b1), \u2203 (H : t \u2208 nhds_within a s), coe_fn \u03bc t = 0) \u2192\n        coe_fn \u03bc s = 0 :=\n  sorry\n\nend is_compact\n\n\ntheorem metric.bounded.finite_measure {\u03b1 : Type u_1} [metric_space \u03b1] [proper_space \u03b1]\n    [measurable_space \u03b1] {\u03bc : measure_theory.measure \u03b1} [measure_theory.locally_finite_measure \u03bc]\n    {s : set \u03b1} (hs : metric.bounded s) : coe_fn \u03bc s < \u22a4 :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/measure_theory/measure_space_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7140659778251396}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport data.nat.bitwise\nimport data.nat.parity\nimport data.nat.log\nimport ring_theory.int.basic\nimport algebra.big_operators.intervals\n\n/-!\n\n# Natural number multiplicity\n\nThis file contains lemmas about the multiplicity function\n(the maximum prime power divding a number).\n\n# Main results\n\nThere are natural number versions of some basic lemmas about multiplicity.\n\nThere are also lemmas about the multiplicity of primes in factorials and in binomial coefficients.\n-/\n\nopen finset nat multiplicity\nopen_locale big_operators nat\n\nnamespace nat\n\n/-- The multiplicity of a divisor `m` of `n`, is the cardinality of the set of\n  positive natural numbers `i` such that `p ^ i` divides `n`. The set is expressed\n  by filtering `Ico 1 b` where `b` is any bound greater than `log m n` -/\nlemma multiplicity_eq_card_pow_dvd {m n b : \u2115} (hm1 : m \u2260 1) (hn0 : 0 < n) (hb : log m n < b):\n  multiplicity m n = \u2191((finset.Ico 1 b).filter (\u03bb i, m ^ i \u2223 n)).card :=\ncalc multiplicity m n = \u2191(Ico 1 $ ((multiplicity m n).get (finite_nat_iff.2 \u27e8hm1, hn0\u27e9) + 1)).card :\n  by simp\n... = \u2191((finset.Ico 1 b).filter (\u03bb i, m ^ i \u2223 n)).card : congr_arg coe $ congr_arg card $\n  finset.ext $ \u03bb i,\n  have hmn : \u00ac m ^ (log m n).succ \u2223 n,\n    from if hm0 : m = 0\n    then \u03bb _, by cases n; simp [*, lt_irrefl, pow_succ'] at *\n    else mt (le_of_dvd hn0) (not_le_of_lt $ pow_succ_log_gt_self m n\n        (hm1.symm.le_iff_lt.mp (zero_lt_iff.mpr hm0.intro)) hn0),\n  \u27e8\u03bb hi, begin\n      simp only [Ico.mem, mem_filter, lt_succ_iff] at *,\n      exact \u27e8\u27e8hi.1, lt_of_le_of_lt hi.2 $\n        lt_of_lt_of_le (by rw [\u2190 enat.coe_lt_coe, enat.coe_get,\n            multiplicity_lt_iff_neg_dvd]; exact hmn)\n          hb\u27e9,\n        by rw [pow_dvd_iff_le_multiplicity];\n          rw [\u2190 @enat.coe_le_coe i, enat.coe_get] at hi; exact hi.2\u27e9\n    end,\n  begin\n    simp only [Ico.mem, mem_filter, lt_succ_iff, and_imp, true_and] { contextual := tt },\n    assume h1i hib hmin,\n    rwa [\u2190 enat.coe_le_coe, enat.coe_get, \u2190 pow_dvd_iff_le_multiplicity]\n  end\u27e9\n\nnamespace prime\n\n\n\nlemma multiplicity_mul {p m n : \u2115} (hp : p.prime) :\n  multiplicity p (m * n) = multiplicity p m + multiplicity p n :=\nmultiplicity.mul $ prime_iff_prime.mp hp\n\nlemma multiplicity_pow {p m n : \u2115} (hp : p.prime) :\n  multiplicity p (m ^ n) = n \u2022 (multiplicity p m) :=\nmultiplicity.pow $ prime_iff_prime.mp hp\n\nlemma multiplicity_self {p : \u2115} (hp : p.prime) : multiplicity p p = 1 :=\nmultiplicity_self (prime_iff_prime.mp hp).not_unit hp.ne_zero\n\nlemma multiplicity_pow_self {p n : \u2115} (hp : p.prime) : multiplicity p (p ^ n) = n :=\nmultiplicity_pow_self hp.ne_zero (prime_iff_prime.mp hp).not_unit n\n\n/-- The multiplicity of a prime in `n!` is the sum of the quotients `n / p ^ i`.\n  This sum is expressed over the set `Ico 1 b` where `b` is any bound greater than `log p n` -/\nlemma multiplicity_factorial {p : \u2115} (hp : p.prime) :\n  \u2200 {n b : \u2115}, log p n < b \u2192 multiplicity p n! = (\u2211 i in Ico 1 b, n / p ^ i : \u2115)\n| 0     b hb := by simp [Ico, hp.multiplicity_one]\n| (n+1) b hb :=\n  calc multiplicity p (n+1)! = multiplicity p n! + multiplicity p (n+1) :\n    by rw [factorial_succ, hp.multiplicity_mul, add_comm]\n  ... = (\u2211 i in Ico 1 b, n / p ^ i : \u2115) + ((finset.Ico 1 b).filter (\u03bb i, p ^ i \u2223 n+1)).card :\n    by rw [multiplicity_factorial (lt_of_le_of_lt log_le_log_succ hb),\n      \u2190 multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (succ_pos _) hb]\n  ... = (\u2211 i in Ico 1 b, (n / p ^ i + if p^i \u2223 n+1 then 1 else 0) : \u2115) :\n    by rw [sum_add_distrib, sum_boole]; simp\n  ... = (\u2211 i in Ico 1 b, (n + 1) / p ^ i : \u2115) :\n    congr_arg coe $ finset.sum_congr rfl (by intros; simp [nat.succ_div]; congr)\n\n/-- The multiplicity of `p` in `(p(n+1))!` is one more than the sum\n  of the multiplicities of `p` in `(p * n)!` and `n + 1`. -/\nlemma multiplicity_factorial_mul_succ {n p : \u2115} (hp : p.prime) :\n  multiplicity p (p * (n + 1))! = multiplicity p (p * n)! + multiplicity p (n + 1) + 1 :=\nbegin\n  have hp' := prime_iff_prime.mp hp,\n  have h0 : 2 \u2264 p := hp.two_le,\n  have h1 : 1 \u2264 p * n + 1 := le_add_left _ _,\n  have h2 : p * n + 1 \u2264 p * (n + 1), linarith,\n  have h3 : p * n + 1 \u2264 p * (n + 1) + 1, linarith,\n  have hm : multiplicity p (p * n)! \u2260 \u22a4,\n  { rw [ne.def, eq_top_iff_not_finite, not_not, finite_nat_iff],\n    exact \u27e8hp.ne_one, factorial_pos _\u27e9 },\n  revert hm,\n  have h4 : \u2200 m \u2208 Ico (p * n + 1) (p * (n + 1)), multiplicity p m = 0,\n  { intros m hm, apply multiplicity_eq_zero_of_not_dvd,\n    rw [\u2190 exists_lt_and_lt_iff_not_dvd _ (pos_iff_ne_zero.mpr hp.ne_zero)], rw [Ico.mem] at hm,\n    exact \u27e8n, lt_of_succ_le hm.1, hm.2\u27e9 },\n  simp_rw [\u2190 prod_Ico_id_eq_factorial, multiplicity.finset.prod hp', \u2190 sum_Ico_consecutive _ h1 h3,\n    add_assoc], intro h,\n  rw [enat.add_left_cancel_iff h, sum_Ico_succ_top h2, multiplicity.mul hp',\n    hp.multiplicity_self, sum_congr rfl h4, sum_const_zero, zero_add,\n    add_comm (1 : enat)]\nend\n\n/-- The multiplicity of `p` in `(pn)!` is `n` more than that of `n!`. -/\nlemma multiplicity_factorial_mul {n p : \u2115} (hp : p.prime) :\n  multiplicity p (p * n)! = multiplicity p n! + n :=\nbegin\n  induction n with n ih,\n  { simp },\n  { simp only [succ_eq_add_one, multiplicity.mul, hp, prime_iff_prime.mp hp, ih,\n      multiplicity_factorial_mul_succ, \u2190add_assoc, enat.coe_one, enat.coe_add, factorial_succ],\n    congr' 1,\n    rw [add_comm, add_assoc] }\nend\n\n/-- A prime power divides `n!` iff it is at most the sum of the quotients `n / p ^ i`.\n  This sum is expressed over the set `Ico 1 b` where `b` is any bound greater than `log p n` -/\nlemma pow_dvd_factorial_iff {p : \u2115} {n r b : \u2115} (hp : p.prime) (hbn : log p n < b) :\n   p ^ r \u2223 n! \u2194 r \u2264 \u2211 i in Ico 1 b, n / p ^ i :=\nby rw [\u2190 enat.coe_le_coe, \u2190 hp.multiplicity_factorial hbn, \u2190 pow_dvd_iff_le_multiplicity]\n\nlemma multiplicity_choose_aux {p n b k : \u2115} (hp : p.prime) (hkn : k \u2264 n) :\n  \u2211 i in finset.Ico 1 b, n / p ^ i =\n  \u2211 i in finset.Ico 1 b, k / p ^ i + \u2211 i in finset.Ico 1 b, (n - k) / p ^ i +\n  ((finset.Ico 1 b).filter (\u03bb i, p ^ i \u2264 k % p ^ i + (n - k) % p ^ i)).card :=\ncalc \u2211 i in finset.Ico 1 b, n / p ^ i\n    = \u2211 i in finset.Ico 1 b, (k + (n - k)) / p ^ i :\n    by simp only [nat.add_sub_cancel' hkn]\n... = \u2211 i in finset.Ico 1 b, (k / p ^ i + (n - k) / p ^ i +\n      if p ^ i \u2264 k % p ^ i + (n - k) % p ^ i then 1 else 0) :\n    by simp only [nat.add_div (pow_pos hp.pos _)]\n... = _ : by simp [sum_add_distrib, sum_boole]\n\n/-- The multiplity of `p` in `choose n k` is the number of carries when `k` and `n - k`\n  are added in base `p`. The set is expressed by filtering `Ico 1 b` where `b`\n  is any bound greater than `log p n`. -/\nlemma multiplicity_choose {p n k b : \u2115} (hp : p.prime) (hkn : k \u2264 n) (hnb : log p n < b) :\n  multiplicity p (choose n k) =\n  ((Ico 1 b).filter (\u03bb i, p ^ i \u2264 k % p ^ i + (n - k) % p ^ i)).card :=\nhave h\u2081 : multiplicity p (choose n k) + multiplicity p (k! * (n - k)!) =\n    ((finset.Ico 1 b).filter (\u03bb i, p ^ i \u2264 k % p ^ i + (n - k) % p ^ i)).card +\n    multiplicity p (k! * (n - k)!),\n  begin\n    rw [\u2190 hp.multiplicity_mul, \u2190 mul_assoc, choose_mul_factorial_mul_factorial hkn,\n        hp.multiplicity_factorial hnb, hp.multiplicity_mul,\n        hp.multiplicity_factorial ((log_le_log_of_le hkn).trans_lt hnb),\n        hp.multiplicity_factorial (lt_of_le_of_lt (log_le_log_of_le (nat.sub_le_self _ _)) hnb),\n        multiplicity_choose_aux hp hkn],\n    simp [add_comm],\n  end,\n(enat.add_right_cancel_iff\n  (enat.ne_top_iff_dom.2 $\n    by exact finite_nat_iff.2\n      \u27e8ne_of_gt hp.one_lt, mul_pos (factorial_pos k) (factorial_pos (n - k))\u27e9)).1\n  h\u2081\n\n/-- A lower bound on the multiplicity of `p` in `choose n k`. -/\nlemma multiplicity_le_multiplicity_choose_add {p : \u2115} (hp : p.prime) (n k : \u2115) :\n  multiplicity p n \u2264 multiplicity p (choose n k) + multiplicity p k :=\nif hkn : n < k then by simp [choose_eq_zero_of_lt hkn]\nelse if hk0 : k = 0 then by simp [hk0]\nelse if hn0 : n = 0 then by cases k; simp [hn0, *] at *\nelse begin\n  rw [multiplicity_choose hp (le_of_not_gt hkn) (lt_succ_self _),\n    multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (nat.pos_of_ne_zero hk0)\n      (lt_succ_of_le (log_le_log_of_le (le_of_not_gt hkn))),\n    multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (nat.pos_of_ne_zero hn0) (lt_succ_self _),\n    \u2190 enat.coe_add, enat.coe_le_coe],\n  calc ((Ico 1 (log p n).succ).filter (\u03bb i, p ^ i \u2223 n)).card\n      \u2264 ((Ico 1 (log p n).succ).filter (\u03bb i, p ^ i \u2264 k % p ^ i + (n - k) % p ^ i) \u222a\n        (Ico 1 (log p n).succ).filter (\u03bb i, p ^ i \u2223 k) ).card :\n    card_le_of_subset $ \u03bb i, begin\n      have := @le_mod_add_mod_of_dvd_add_of_not_dvd k (n - k) (p ^ i),\n      simp [nat.add_sub_cancel' (le_of_not_gt hkn)] at * {contextual := tt},\n      tauto\n    end\n  ... \u2264 ((Ico 1 (log p n).succ).filter (\u03bb i, p ^ i \u2264 k % p ^ i + (n - k) % p ^ i)).card +\n        ((Ico 1 (log p n).succ).filter (\u03bb i, p ^ i \u2223 k)).card :\n    card_union_le _ _\nend\n\nlemma multiplicity_choose_prime_pow {p n k : \u2115} (hp : p.prime)\n  (hkn : k \u2264 p ^ n) (hk0 : 0 < k) :\n  multiplicity p (choose (p ^ n) k) + multiplicity p k = n :=\nle_antisymm\n  (have hdisj : disjoint\n      ((Ico 1 n.succ).filter (\u03bb i, p ^ i \u2264 k % p ^ i + (p ^ n - k) % p ^ i))\n      ((Ico 1 n.succ).filter (\u03bb i, p ^ i \u2223 k)),\n    by simp [disjoint_right, *, dvd_iff_mod_eq_zero, nat.mod_lt _ (pow_pos hp.pos _)]\n        {contextual := tt},\n  begin\n    rw [multiplicity_choose hp hkn (lt_succ_self _),\n      multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) hk0\n        (lt_succ_of_le (log_le_log_of_le hkn)),\n      \u2190 enat.coe_add, enat.coe_le_coe, log_pow _ _ hp.one_lt,\n      \u2190 card_disjoint_union hdisj, filter_union_right],\n    have filter_le_Ico := (Ico 1 n.succ).card_filter_le _,\n    rwa Ico.card 1 n.succ at filter_le_Ico,\n  end)\n  (by rw [\u2190 hp.multiplicity_pow_self];\n    exact multiplicity_le_multiplicity_choose_add hp _ _)\n\nend prime\n\nlemma multiplicity_two_factorial_lt : \u2200 {n : \u2115} (h : n \u2260 0), multiplicity 2 n! < n :=\nbegin\n  have h2 := prime_iff_prime.mp prime_two,\n  refine binary_rec _ _,\n  { contradiction },\n  { intros b n ih h,\n    by_cases hn : n = 0,\n    { subst hn, simp at h, simp [h, one_right h2.not_unit, enat.zero_lt_one] },\n    have : multiplicity 2 (2 * n)! < (2 * n : \u2115),\n    { rw [prime_two.multiplicity_factorial_mul],\n      refine (enat.add_lt_add_right (ih hn) (enat.coe_ne_top _)).trans_le _,\n      rw [two_mul], norm_cast },\n    cases b,\n    { simpa [bit0_eq_two_mul n] },\n    { suffices : multiplicity 2 (2 * n + 1) + multiplicity 2 (2 * n)! < \u2191(2 * n) + 1,\n      { simpa [succ_eq_add_one, multiplicity.mul, h2, prime_two, nat.bit1_eq_succ_bit0,\n          bit0_eq_two_mul n] },\n      rw [multiplicity_eq_zero_of_not_dvd (two_not_dvd_two_mul_add_one n), zero_add],\n      refine this.trans _, exact_mod_cast lt_succ_self _ }}\nend\n\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/multiplicity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7140659757044204}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport data.fintype.basic\nimport group_theory.subgroup\n\n/-!\n# Free groups\n\nThis file defines free groups over a type. Furthermore, it is shown that the free group construction\nis an instance of a monad. For the result that `free_group` is the left adjoint to the forgetful\nfunctor from groups to types, see `algebra/category/Group/adjunctions`.\n\n## Main definitions\n\n* `free_group`: the free group associated to a type `\u03b1` defined as the words over `a : \u03b1 \u00d7 bool `\n  modulo the relation `a * x * x\u207b\u00b9 * b = a * b`.\n* `mk`: the canonical quotient map `list (\u03b1 \u00d7 bool) \u2192 free_group \u03b1`.\n* `of`: the canoical injection `\u03b1 \u2192 free_group \u03b1`.\n* `lift f`: the canonical group homomorphism `free_group \u03b1 \u2192* G` given a group `G` and a\n  function `f : \u03b1 \u2192 G`.\n\n## Main statements\n\n* `church_rosser`: The Church-Rosser theorem for word reduction (also known as Newman's diamond\n  lemma).\n* `free_group_unit_equiv_int`: The free group over the one-point type is isomorphic to the integers.\n* The free group construction is an instance of a monad.\n\n## Implementation details\n\nFirst we introduce the one step reduction relation `free_group.red.step`:\n`w * x * x\u207b\u00b9 * v   ~>   w * v`, its reflexive transitive closure `free_group.red.trans`\nand prove that its join is an equivalence relation. Then we introduce `free_group \u03b1` as a quotient\nover `free_group.red.step`.\n\n## Tags\n\nfree group, Newman's diamond lemma, Church-Rosser theorem\n-/\n\nopen relation\n\nuniverses u v w\n\nvariables {\u03b1 : Type u}\n\nlocal attribute [simp] list.append_eq_has_append\n\nnamespace free_group\nvariables {L L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)}\n\n/-- Reduction step: `w * x * x\u207b\u00b9 * v ~> w * v` -/\ninductive red.step : list (\u03b1 \u00d7 bool) \u2192 list (\u03b1 \u00d7 bool) \u2192 Prop\n| bnot {L\u2081 L\u2082 x b} : red.step (L\u2081 ++ (x, b) :: (x, bnot b) :: L\u2082) (L\u2081 ++ L\u2082)\nattribute [simp] red.step.bnot\n\n/-- Reflexive-transitive closure of red.step -/\ndef red : list (\u03b1 \u00d7 bool) \u2192 list (\u03b1 \u00d7 bool) \u2192 Prop := refl_trans_gen red.step\n\n@[refl] lemma red.refl : red L L := refl_trans_gen.refl\n@[trans] lemma red.trans : red L\u2081 L\u2082 \u2192 red L\u2082 L\u2083 \u2192 red L\u2081 L\u2083 := refl_trans_gen.trans\n\nnamespace red\n\n/-- Predicate asserting that word `w\u2081` can be reduced to `w\u2082` in one step, i.e. there are words\n`w\u2083 w\u2084` and letter `x` such that `w\u2081 = w\u2083xx\u207b\u00b9w\u2084` and `w\u2082 = w\u2083w\u2084`  -/\ntheorem step.length : \u2200 {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 L\u2082.length + 2 = L\u2081.length\n| _ _ (@red.step.bnot _ L1 L2 x b) := by rw [list.length_append, list.length_append]; refl\n\n@[simp] lemma step.bnot_rev {x b} : step (L\u2081 ++ (x, bnot b) :: (x, b) :: L\u2082) (L\u2081 ++ L\u2082) :=\nby cases b; from step.bnot\n\n@[simp] lemma step.cons_bnot {x b} : red.step ((x, b) :: (x, bnot b) :: L) L :=\n@step.bnot _ [] _ _ _\n\n@[simp] lemma step.cons_bnot_rev {x b} : red.step ((x, bnot b) :: (x, b) :: L) L :=\n@red.step.bnot_rev _ [] _ _ _\n\ntheorem step.append_left : \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)}, step L\u2082 L\u2083 \u2192 step (L\u2081 ++ L\u2082) (L\u2081 ++ L\u2083)\n| _ _ _ red.step.bnot := by rw [\u2190 list.append_assoc, \u2190 list.append_assoc]; constructor\n\ntheorem step.cons {x} (H : red.step L\u2081 L\u2082) : red.step (x :: L\u2081) (x :: L\u2082) :=\n@step.append_left _ [x] _ _ H\n\ntheorem step.append_right : \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 step (L\u2081 ++ L\u2083) (L\u2082 ++ L\u2083)\n| _ _ _ red.step.bnot := by simp\n\nlemma not_step_nil : \u00ac step [] L :=\nbegin\n  generalize h' : [] = L',\n  assume h,\n  cases h with L\u2081 L\u2082,\n  simp [list.nil_eq_append_iff] at h',\n  contradiction\nend\n\nlemma step.cons_left_iff {a : \u03b1} {b : bool} :\n  step ((a, b) :: L\u2081) L\u2082 \u2194 (\u2203L, step L\u2081 L \u2227 L\u2082 = (a, b) :: L) \u2228 (L\u2081 = (a, bnot b)::L\u2082) :=\nbegin\n  split,\n  { generalize hL : ((a, b) :: L\u2081 : list _) = L,\n    assume h,\n    rcases h with \u27e8_ | \u27e8p, s'\u27e9, e, a', b'\u27e9,\n    { simp at hL, simp [*] },\n    { simp at hL,\n      rcases hL with \u27e8rfl, rfl\u27e9,\n      refine or.inl \u27e8s' ++ e, step.bnot, _\u27e9,\n      simp } },\n  { assume h,\n    rcases h with \u27e8L, h, rfl\u27e9 | rfl,\n    { exact step.cons h },\n    { exact step.cons_bnot } }\nend\n\nlemma not_step_singleton : \u2200 {p : \u03b1 \u00d7 bool}, \u00ac step [p] L\n| (a, b) := by simp [step.cons_left_iff, not_step_nil]\n\nlemma step.cons_cons_iff : \u2200{p : \u03b1 \u00d7 bool}, step (p :: L\u2081) (p :: L\u2082) \u2194 step L\u2081 L\u2082 :=\nby simp [step.cons_left_iff, iff_def, or_imp_distrib] {contextual := tt}\n\nlemma step.append_left_iff : \u2200L, step (L ++ L\u2081) (L ++ L\u2082) \u2194 step L\u2081 L\u2082\n| [] := by simp\n| (p :: l) := by simp [step.append_left_iff l, step.cons_cons_iff]\n\nprivate theorem step.diamond_aux : \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)} {x1 b1 x2 b2},\n  L\u2081 ++ (x1, b1) :: (x1, bnot b1) :: L\u2082 = L\u2083 ++ (x2, b2) :: (x2, bnot b2) :: L\u2084 \u2192\n  L\u2081 ++ L\u2082 = L\u2083 ++ L\u2084 \u2228 \u2203 L\u2085, red.step (L\u2081 ++ L\u2082) L\u2085 \u2227 red.step (L\u2083 ++ L\u2084) L\u2085\n| []        _ []        _ _ _ _ _ H := by injections; subst_vars; simp\n| []        _ [(x3,b3)] _ _ _ _ _ H := by injections; subst_vars; simp\n| [(x3,b3)] _ []        _ _ _ _ _ H := by injections; subst_vars; simp\n| []                     _ ((x3,b3)::(x4,b4)::tl) _ _ _ _ _ H :=\n  by injections; subst_vars; simp; right; exact \u27e8_, red.step.bnot, red.step.cons_bnot\u27e9\n| ((x3,b3)::(x4,b4)::tl) _ []                     _ _ _ _ _ H :=\n  by injections; subst_vars; simp; right; exact \u27e8_, red.step.cons_bnot, red.step.bnot\u27e9\n| ((x3,b3)::tl) _ ((x4,b4)::tl2) _ _ _ _ _ H :=\n  let \u27e8H1, H2\u27e9 := list.cons.inj H in\n  match step.diamond_aux H2 with\n    | or.inl H3 := or.inl $ by simp [H1, H3]\n    | or.inr \u27e8L\u2085, H3, H4\u27e9 := or.inr\n      \u27e8_, step.cons H3, by simpa [H1] using step.cons H4\u27e9\n  end\n\ntheorem step.diamond : \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)},\n  red.step L\u2081 L\u2083 \u2192 red.step L\u2082 L\u2084 \u2192 L\u2081 = L\u2082 \u2192\n  L\u2083 = L\u2084 \u2228 \u2203 L\u2085, red.step L\u2083 L\u2085 \u2227 red.step L\u2084 L\u2085\n| _ _ _ _ red.step.bnot red.step.bnot H := step.diamond_aux H\n\nlemma step.to_red : step L\u2081 L\u2082 \u2192 red L\u2081 L\u2082 :=\nrefl_trans_gen.single\n\n/-- Church-Rosser theorem for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2`\nand `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`\nrespectively. This is also known as Newman's diamond lemma. -/\ntheorem church_rosser : red L\u2081 L\u2082 \u2192 red L\u2081 L\u2083 \u2192 join red L\u2082 L\u2083 :=\nrelation.church_rosser (assume a b c hab hac,\nmatch b, c, red.step.diamond hab hac rfl with\n| b, _, or.inl rfl           := \u27e8b, by refl, by refl\u27e9\n| b, c, or.inr \u27e8d, hbd, hcd\u27e9 := \u27e8d, refl_gen.single hbd, hcd.to_red\u27e9\nend)\n\nlemma cons_cons {p} : red L\u2081 L\u2082 \u2192 red (p :: L\u2081) (p :: L\u2082) :=\nrefl_trans_gen_lift (list.cons p) (assume a b, step.cons)\n\nlemma cons_cons_iff (p) : red (p :: L\u2081) (p :: L\u2082) \u2194 red L\u2081 L\u2082 :=\niff.intro\n  begin\n    generalize eq\u2081 : (p :: L\u2081 : list _) = LL\u2081,\n    generalize eq\u2082 : (p :: L\u2082 : list _) = LL\u2082,\n    assume h,\n    induction h using relation.refl_trans_gen.head_induction_on\n      with L\u2081 L\u2082 h\u2081\u2082 h ih\n      generalizing L\u2081 L\u2082,\n    { subst_vars, cases eq\u2082, constructor },\n    { subst_vars,\n      cases p with a b,\n      rw [step.cons_left_iff] at h\u2081\u2082,\n      rcases h\u2081\u2082 with \u27e8L, h\u2081\u2082, rfl\u27e9 | rfl,\n      { exact (ih rfl rfl).head h\u2081\u2082 },\n      { exact (cons_cons h).tail step.cons_bnot_rev } }\n  end\n  cons_cons\n\nlemma append_append_left_iff : \u2200L, red (L ++ L\u2081) (L ++ L\u2082) \u2194 red L\u2081 L\u2082\n| []       := iff.rfl\n| (p :: L) := by simp [append_append_left_iff L, cons_cons_iff]\n\nlemma append_append (h\u2081 : red L\u2081 L\u2083) (h\u2082 : red L\u2082 L\u2084) : red (L\u2081 ++ L\u2082) (L\u2083 ++ L\u2084) :=\n(refl_trans_gen_lift (\u03bbL, L ++ L\u2082) (assume a b, step.append_right) h\u2081).trans\n  ((append_append_left_iff _).2 h\u2082)\n\nlemma to_append_iff : red L (L\u2081 ++ L\u2082) \u2194 (\u2203L\u2083 L\u2084, L = L\u2083 ++ L\u2084 \u2227 red L\u2083 L\u2081 \u2227 red L\u2084 L\u2082) :=\niff.intro\n  begin\n    generalize eq : L\u2081 ++ L\u2082 = L\u2081\u2082,\n    assume h,\n    induction h with L' L\u2081\u2082 hLL' h ih generalizing L\u2081 L\u2082,\n    { exact \u27e8_, _, eq.symm, by refl, by refl\u27e9 },\n    { cases h with s e a b,\n      rcases list.append_eq_append_iff.1 eq with \u27e8s', rfl, rfl\u27e9 | \u27e8e', rfl, rfl\u27e9,\n      { have : L\u2081 ++ (s' ++ ((a, b) :: (a, bnot b) :: e)) =\n                 (L\u2081 ++ s') ++ ((a, b) :: (a, bnot b) :: e),\n        { simp },\n        rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9,\n        exact \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082.tail step.bnot\u27e9 },\n      { have : (s ++ ((a, b) :: (a, bnot b) :: e')) ++ L\u2082 =\n                 s ++ ((a, b) :: (a, bnot b) :: (e' ++ L\u2082)),\n        { simp },\n        rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9,\n        exact \u27e8w\u2081, w\u2082, rfl, h\u2081.tail step.bnot, h\u2082\u27e9 }, }\n  end\n  (assume \u27e8L\u2083, L\u2084, eq, h\u2083, h\u2084\u27e9, eq.symm \u25b8 append_append h\u2083 h\u2084)\n\n/-- The empty word `[]` only reduces to itself. -/\ntheorem nil_iff : red [] L \u2194 L = [] :=\nrefl_trans_gen_iff_eq (assume l, red.not_step_nil)\n\n/-- A letter only reduces to itself. -/\ntheorem singleton_iff {x} : red [x] L\u2081 \u2194 L\u2081 = [x] :=\nrefl_trans_gen_iff_eq (assume l, not_step_singleton)\n\n/-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces\nto `x\u207b\u00b9` -/\ntheorem cons_nil_iff_singleton {x b} : red ((x, b) :: L) [] \u2194 red L [(x, bnot b)] :=\niff.intro\n  (assume h,\n    have h\u2081 : red ((x, bnot b) :: (x, b) :: L) [(x, bnot b)], from cons_cons h,\n    have h\u2082 : red ((x, bnot b) :: (x, b) :: L) L, from refl_trans_gen.single step.cons_bnot_rev,\n    let \u27e8L', h\u2081, h\u2082\u27e9 := church_rosser h\u2081 h\u2082 in\n    by rw [singleton_iff] at h\u2081; subst L'; assumption)\n  (assume h, (cons_cons h).tail step.cons_bnot)\n\ntheorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) \u2260 (x2, b2)) :\n  red [(x1, bnot b1), (x2, b2)] L \u2194 L = [(x1, bnot b1), (x2, b2)] :=\nbegin\n  apply refl_trans_gen_iff_eq,\n  generalize eq : [(x1, bnot b1), (x2, b2)] = L',\n  assume L h',\n  cases h',\n  simp [list.cons_eq_append_iff, list.nil_eq_append_iff] at eq,\n  rcases eq with \u27e8rfl, \u27e8rfl, rfl\u27e9, \u27e8rfl, rfl\u27e9, rfl\u27e9, subst_vars,\n  simp at h,\n  contradiction\nend\n\n/-- If `x` and `y` are distinct letters and `w\u2081 w\u2082` are words such that `xw\u2081` reduces to `yw\u2082`, then\n`w\u2081` reduces to `x\u207b\u00b9yw\u2082`. -/\ntheorem inv_of_red_of_ne {x1 b1 x2 b2}\n  (H1 : (x1, b1) \u2260 (x2, b2))\n  (H2 : red ((x1, b1) :: L\u2081) ((x2, b2) :: L\u2082)) :\n  red L\u2081 ((x1, bnot b1) :: (x2, b2) :: L\u2082) :=\nbegin\n  have : red ((x1, b1) :: L\u2081) ([(x2, b2)] ++ L\u2082), from H2,\n  rcases to_append_iff.1 this with \u27e8_ | \u27e8p, L\u2083\u27e9, L\u2084, eq, h\u2081, h\u2082\u27e9,\n  { simp [nil_iff] at h\u2081, contradiction },\n  { cases eq,\n    show red (L\u2083 ++ L\u2084) ([(x1, bnot b1), (x2, b2)] ++ L\u2082),\n    apply append_append _ h\u2082,\n    have h\u2081 : red ((x1, bnot b1) :: (x1, b1) :: L\u2083) [(x1, bnot b1), (x2, b2)],\n    { exact cons_cons h\u2081 },\n    have h\u2082 : red ((x1, bnot b1) :: (x1, b1) :: L\u2083) L\u2083,\n    { exact step.cons_bnot_rev.to_red },\n    rcases church_rosser h\u2081 h\u2082 with \u27e8L', h\u2081, h\u2082\u27e9,\n    rw [red_iff_irreducible H1] at h\u2081,\n    rwa [h\u2081] at h\u2082 }\nend\n\ntheorem step.sublist (H : red.step L\u2081 L\u2082) : L\u2082 <+ L\u2081 :=\nby cases H; simp; constructor; constructor; refl\n\n/-- If `w\u2081 w\u2082` are words such that `w\u2081` reduces to `w\u2082`, then `w\u2082` is a sublist of `w\u2081`. -/\ntheorem sublist : red L\u2081 L\u2082 \u2192 L\u2082 <+ L\u2081 :=\nrefl_trans_gen_of_transitive_reflexive\n  (\u03bbl, list.sublist.refl l) (\u03bba b c hab hbc, list.sublist.trans hbc hab) (\u03bba b, red.step.sublist)\n\ntheorem sizeof_of_step : \u2200 {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 L\u2082.sizeof < L\u2081.sizeof\n| _ _ (@step.bnot _ L1 L2 x b) :=\n  begin\n    induction L1 with hd tl ih,\n    case list.nil\n    { dsimp [list.sizeof],\n      have H : 1 + sizeof (x, b) + (1 + sizeof (x, bnot b) + list.sizeof L2)\n        = (list.sizeof L2 + 1) + (sizeof (x, b) + sizeof (x, bnot b) + 1),\n      { ac_refl },\n      rw H,\n      exact nat.le_add_right _ _ },\n    case list.cons\n    { dsimp [list.sizeof],\n      exact nat.add_lt_add_left ih _ }\n  end\n\ntheorem length (h : red L\u2081 L\u2082) : \u2203 n, L\u2081.length = L\u2082.length + 2 * n :=\nbegin\n  induction h with L\u2082 L\u2083 h\u2081\u2082 h\u2082\u2083 ih,\n  { exact \u27e80, rfl\u27e9 },\n  { rcases ih with \u27e8n, eq\u27e9,\n    existsi (1 + n),\n    simp [mul_add, eq, (step.length h\u2082\u2083).symm, add_assoc] }\nend\n\ntheorem antisymm (h\u2081\u2082 : red L\u2081 L\u2082) : red L\u2082 L\u2081 \u2192 L\u2081 = L\u2082 :=\nmatch L\u2081, h\u2081\u2082.cases_head with\n| _,  or.inl rfl            := assume h, rfl\n| L\u2081, or.inr \u27e8L\u2083, h\u2081\u2083, h\u2083\u2082\u27e9 := assume h\u2082\u2081,\n  let \u27e8n, eq\u27e9 := length (h\u2083\u2082.trans h\u2082\u2081) in\n  have list.length L\u2083 + 0 = list.length L\u2083 + (2 * n + 2),\n    by simpa [(step.length h\u2081\u2083).symm, add_comm, add_assoc] using eq,\n  (nat.no_confusion $ nat.add_left_cancel this)\nend\n\nend red\n\ntheorem equivalence_join_red : equivalence (join (@red \u03b1)) :=\nequivalence_join_refl_trans_gen $ assume a b c hab hac,\n(match b, c, red.step.diamond hab hac rfl with\n| b, _, or.inl rfl           := \u27e8b, by refl, by refl\u27e9\n| b, c, or.inr \u27e8d, hbd, hcd\u27e9 := \u27e8d, refl_gen.single hbd, refl_trans_gen.single hcd\u27e9\nend)\n\ntheorem join_red_of_step (h : red.step L\u2081 L\u2082) : join red L\u2081 L\u2082 :=\njoin_of_single reflexive_refl_trans_gen h.to_red\n\ntheorem eqv_gen_step_iff_join_red : eqv_gen red.step L\u2081 L\u2082 \u2194 join red L\u2081 L\u2082 :=\niff.intro\n  (assume h,\n    have eqv_gen (join red) L\u2081 L\u2082 := eqv_gen_mono (assume a b, join_red_of_step) h,\n    (eqv_gen_iff_of_equivalence $ equivalence_join_red).1 this)\n  (join_of_equivalence (eqv_gen.is_equivalence _) $ assume a b,\n    refl_trans_gen_of_equivalence (eqv_gen.is_equivalence _) eqv_gen.rel)\n\nend free_group\n\n/-- The free group over a type, i.e. the words formed by the elements of the type and their formal\ninverses, quotient by one step reduction. -/\ndef free_group (\u03b1 : Type u) : Type u :=\nquot $ @free_group.red.step \u03b1\n\nnamespace free_group\n\nvariables {\u03b1} {L L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)}\n\n/-- The canonical map from `list (\u03b1 \u00d7 bool)` to the free group on `\u03b1`. -/\ndef mk (L) : free_group \u03b1 := quot.mk red.step L\n\n@[simp] lemma quot_mk_eq_mk : quot.mk red.step L = mk L := rfl\n\n@[simp] lemma quot_lift_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 \u03b2)\n  (H : \u2200 L\u2081 L\u2082, red.step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) :\nquot.lift f H (mk L) = f L := rfl\n\n@[simp] lemma quot_lift_on_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 \u03b2)\n  (H : \u2200 L\u2081 L\u2082, red.step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) :\nquot.lift_on (mk L) f H = f L := rfl\n\ninstance : has_one (free_group \u03b1) := \u27e8mk []\u27e9\nlemma one_eq_mk : (1 : free_group \u03b1) = mk [] := rfl\n\ninstance : inhabited (free_group \u03b1) := \u27e81\u27e9\n\ninstance : has_mul (free_group \u03b1) :=\n\u27e8\u03bb x y, quot.lift_on x\n    (\u03bb L\u2081, quot.lift_on y (\u03bb L\u2082, mk $ L\u2081 ++ L\u2082) (\u03bb L\u2082 L\u2083 H, quot.sound $ red.step.append_left H))\n    (\u03bb L\u2081 L\u2082 H, quot.induction_on y $ \u03bb L\u2083, quot.sound $ red.step.append_right H)\u27e9\n@[simp] lemma mul_mk : mk L\u2081 * mk L\u2082 = mk (L\u2081 ++ L\u2082) := rfl\n\ninstance : has_inv (free_group \u03b1) :=\n\u27e8\u03bbx, quot.lift_on x (\u03bb L, mk (L.map $ \u03bb x : \u03b1 \u00d7 bool, (x.1, bnot x.2)).reverse)\n  (assume a b h, quot.sound $ by cases h; simp)\u27e9\n@[simp] lemma inv_mk : (mk L)\u207b\u00b9 = mk (L.map $ \u03bb x : \u03b1 \u00d7 bool, (x.1, bnot x.2)).reverse := rfl\n\ninstance : group (free_group \u03b1) :=\n{ mul := (*),\n  one := 1,\n  inv := has_inv.inv,\n  mul_assoc := by rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9 \u27e8L\u2083\u27e9; simp,\n  one_mul := by rintros \u27e8L\u27e9; refl,\n  mul_one := by rintros \u27e8L\u27e9; simp [one_eq_mk],\n  mul_left_inv := by rintros \u27e8L\u27e9; exact (list.rec_on L rfl $\n    \u03bb \u27e8x, b\u27e9 tl ih, eq.trans (quot.sound $ by simp [one_eq_mk]) ih) }\n\n/-- `of` is the canonical injection from the type to the free group over that type by sending each\nelement to the equivalence class of the letter that is the element. -/\ndef of (x : \u03b1) : free_group \u03b1 :=\nmk [(x, tt)]\n\ntheorem red.exact : mk L\u2081 = mk L\u2082 \u2194 join red L\u2081 L\u2082 :=\ncalc (mk L\u2081 = mk L\u2082) \u2194 eqv_gen red.step L\u2081 L\u2082 : iff.intro (quot.exact _) quot.eqv_gen_sound\n  ... \u2194 join red L\u2081 L\u2082 : eqv_gen_step_iff_join_red\n\n/-- The canonical injection from the type to the free group is an injection. -/\ntheorem of_injective : function.injective (@of \u03b1) :=\n\u03bb _ _ H, let \u27e8L\u2081, hx, hy\u27e9 := red.exact.1 H in\n  by simp [red.singleton_iff] at hx hy; cc\n\nsection lift\n\nvariables {\u03b2 : Type v} [group \u03b2] (f : \u03b1 \u2192 \u03b2) {x y : free_group \u03b1}\n\n/-- Given `f : \u03b1 \u2192 \u03b2` with `\u03b2` a group, the canonical map `list (\u03b1 \u00d7 bool) \u2192 \u03b2` -/\ndef lift.aux : list (\u03b1 \u00d7 bool) \u2192 \u03b2 :=\n\u03bb L, list.prod $ L.map $ \u03bb x, cond x.2 (f x.1) (f x.1)\u207b\u00b9\n\ntheorem red.step.lift {f : \u03b1 \u2192 \u03b2} (H : red.step L\u2081 L\u2082) :\n  lift.aux f L\u2081 = lift.aux f L\u2082 :=\nby cases H with _ _ _ b; cases b; simp [lift.aux]\n\n\n/-- If `\u03b2` is a group, then any function from `\u03b1` to `\u03b2`\nextends uniquely to a group homomorphism from\nthe free group over `\u03b1` to `\u03b2` -/\n@[simps symm_apply]\ndef lift : (\u03b1 \u2192 \u03b2) \u2243 (free_group \u03b1 \u2192* \u03b2) :=\n{ to_fun := \u03bb f,\n    monoid_hom.mk' (quot.lift (lift.aux f) $ \u03bb L\u2081 L\u2082, red.step.lift) $ begin\n      rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9, simp [lift.aux],\n    end,\n  inv_fun := \u03bb g, g \u2218 of,\n  left_inv := \u03bb f, one_mul _,\n  right_inv := \u03bb g, monoid_hom.ext $ begin\n    rintros \u27e8L\u27e9,\n    apply list.rec_on L,\n    { exact g.map_one.symm, },\n    { rintros \u27e8x, _ | _\u27e9 t (ih : _ = g (mk t)),\n      { show _ = g ((of x)\u207b\u00b9 * mk t),\n        simpa [lift.aux] using ih },\n      { show _ = g (of x * mk t),\n        simpa [lift.aux] using ih }, },\n  end }\nvariable {f}\n\n@[simp] lemma lift.mk : lift f (mk L) =\n  list.prod (L.map $ \u03bb x, cond x.2 (f x.1) (f x.1)\u207b\u00b9) :=\nrfl\n\n@[simp] lemma lift.of {x} : lift f (of x) = f x :=\none_mul _\n\ntheorem lift.unique (g : free_group \u03b1 \u2192* \u03b2)\n  (hg : \u2200 x, g (of x) = f x) : \u2200{x}, g x = lift f x :=\nmonoid_hom.congr_fun $ (lift.symm_apply_eq).mp (funext hg : g \u2218 of = f)\n\n/-- Two homomorphisms out of a free group are equal if they are equal on generators.\n\nSee note [partially-applied ext lemmas]. -/\n@[ext]\nlemma ext_hom {G : Type*} [group G] (f g : free_group \u03b1 \u2192* G) (h : \u2200 a, f (of a) = g (of a)) :\n  f = g :=\nlift.symm.injective $ funext h\n\ntheorem lift.of_eq (x : free_group \u03b1) : lift of x = x :=\nmonoid_hom.congr_fun (lift.apply_symm_apply (monoid_hom.id _)) x\n\ntheorem lift.range_subset {s : subgroup \u03b2} (H : set.range f \u2286 s) :\n  set.range (lift f) \u2286 s :=\nby rintros _ \u27e8\u27e8L\u27e9, rfl\u27e9; exact list.rec_on L s.one_mem\n(\u03bb \u27e8x, b\u27e9 tl ih, bool.rec_on b\n    (by simp at ih \u22a2; from s.mul_mem\n      (s.inv_mem $ H \u27e8x, rfl\u27e9) ih)\n    (by simp at ih \u22a2; from s.mul_mem (H \u27e8x, rfl\u27e9) ih))\n\ntheorem closure_subset {G : Type*} [group G] {s : set G} {t : subgroup G}\n  (h : s \u2286 t) : subgroup.closure s \u2264 t :=\nbegin\n  simp only [h, subgroup.closure_le],\nend\n\ntheorem lift.range_eq_closure :\n  set.range (lift f) = subgroup.closure (set.range f) :=\nset.subset.antisymm\n  (lift.range_subset subgroup.subset_closure)\n  begin\n    suffices : (subgroup.closure (set.range f)) \u2264 monoid_hom.range (lift f),\n      simpa,\n    rw subgroup.closure_le,\n    rintros y \u27e8x, hx\u27e9,\n    exact \u27e8of x, by simpa\u27e9\n  end\n\nend lift\n\nsection map\n\nvariables {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) {x y : free_group \u03b1}\n\n/-- Given `f : \u03b1 \u2192 \u03b2`, the canonical map `list (\u03b1 \u00d7 bool) \u2192 list (\u03b2 \u00d7 bool)`. -/\ndef map.aux (L : list (\u03b1 \u00d7 bool)) : list (\u03b2 \u00d7 bool) :=\nL.map $ \u03bb x, (f x.1, x.2)\n\n/-- Any function from `\u03b1` to `\u03b2` extends uniquely\nto a group homomorphism from the free group\nover `\u03b1` to the free group over `\u03b2`. Note that this is the bare function;\nfor the group homomorphism use `map`. -/\ndef map.to_fun (x : free_group \u03b1) : free_group \u03b2 :=\nx.lift_on (\u03bb L, mk $ map.aux f L) $\n\u03bb L\u2081 L\u2082 H, quot.sound $ by cases H; simp [map.aux]\n\n/-- Any function from `\u03b1` to `\u03b2` extends uniquely\nto a group homomorphism from the free group\nver `\u03b1` to the free group over `\u03b2`. -/\ndef map : free_group \u03b1 \u2192* free_group \u03b2 := monoid_hom.mk' (map.to_fun f)\nbegin\n  rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9,\n  simp [map.to_fun, map.aux]\nend\n\n--by rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9; simp [map, map.aux]\n\nvariable {f}\n\n@[simp] lemma map.mk : map f (mk L) = mk (L.map (\u03bb x, (f x.1, x.2))) :=\nrfl\n\n@[simp] lemma map.id : map id x = x :=\nhave H1 : (\u03bb (x : \u03b1 \u00d7 bool), x) = id := rfl,\nby rcases x with \u27e8L\u27e9; simp [H1]\n\n@[simp] lemma map.id' : map (\u03bb z, z) x = x := map.id\n\ntheorem map.comp {\u03b3 : Type w} {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} {x} :\n  map g (map f x) = map (g \u2218 f) x :=\nby rcases x with \u27e8L\u27e9; simp\n\n@[simp] lemma map.of {x} : map f (of x) = of (f x) := rfl\n\ntheorem map.unique (g : free_group \u03b1 \u2192* free_group \u03b2)\n  (hg : \u2200 x, g (of x) = of (f x)) : \u2200{x}, g x = map f x :=\nby rintros \u27e8L\u27e9; exact list.rec_on L g.map_one\n(\u03bb \u27e8x, b\u27e9 t (ih : g (mk t) = map f (mk t)), bool.rec_on b\n  (show g ((of x)\u207b\u00b9 * mk t) = map f ((of x)\u207b\u00b9 * mk t),\n     by simp [g.map_mul, g.map_inv, hg, ih])\n  (show g (of x * mk t) = map f (of x * mk t),\n     by simp [g.map_mul, hg, ih]))\n\n/-- Equivalent types give rise to equivalent free groups. -/\ndef free_group_congr {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) : free_group \u03b1 \u2243 free_group \u03b2 :=\n\u27e8map e, map e.symm,\n \u03bb x, by simp [function.comp, map.comp],\n \u03bb x, by simp [function.comp, map.comp]\u27e9\n\ntheorem map_eq_lift : map f x = lift (of \u2218 f) x :=\neq.symm $ map.unique _ $ \u03bb x, by simp\n\nend map\n\nsection prod\n\nvariables [group \u03b1] (x y : free_group \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1`\nextends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the multiplicative\nversion of `sum`. -/\ndef prod : free_group \u03b1 \u2192* \u03b1 := lift id\n\nvariables {x y}\n\n@[simp] lemma prod_mk :\n  prod (mk L) = list.prod (L.map $ \u03bb x, cond x.2 x.1 x.1\u207b\u00b9) :=\nrfl\n\n@[simp] lemma prod.of {x : \u03b1} : prod (of x) = x :=\nlift.of\n\nlemma prod.unique (g : free_group \u03b1 \u2192* \u03b1)\n  (hg : \u2200 x, g (of x) = x) {x} :\n  g x = prod x :=\nlift.unique g hg\n\nend prod\n\ntheorem lift_eq_prod_map {\u03b2 : Type v} [group \u03b2] {f : \u03b1 \u2192 \u03b2} {x} :\n  lift f x = prod (map f x) :=\nbegin\n  rw \u2190lift.unique (prod.comp (map f)),\n  { refl },\n  { simp }\nend\n\nsection sum\n\nvariables [add_group \u03b1] (x y : free_group \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1`\nextends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the additive\nversion of `prod`. -/\ndef sum : \u03b1 :=\n@prod (multiplicative _) _ x\n\nvariables {x y}\n\n@[simp] lemma sum_mk :\n  sum (mk L) = list.sum (L.map $ \u03bb x, cond x.2 x.1 (-x.1)) :=\nrfl\n\n@[simp] lemma sum.of {x : \u03b1} : sum (of x) = x :=\nprod.of\n\n-- note: there are no bundled homs with different notation in the domain and codomain, so we copy\n-- these manually\n@[simp] lemma sum.map_mul : sum (x * y) = sum x + sum y :=\n(@prod (multiplicative _) _).map_mul _ _\n\n@[simp] lemma sum.map_one : sum (1:free_group \u03b1) = 0 :=\n(@prod (multiplicative _) _).map_one\n\n@[simp] lemma sum.map_inv : sum x\u207b\u00b9 = -sum x :=\n(@prod (multiplicative _) _).map_inv _\n\nend sum\n\n/-- The bijection between the free group on the empty type, and a type with one element. -/\ndef free_group_empty_equiv_unit : free_group empty \u2243 unit :=\n{ to_fun    := \u03bb _, (),\n  inv_fun   := \u03bb _, 1,\n  left_inv  := by rintros \u27e8_ | \u27e8\u27e8\u27e8\u27e9, _\u27e9, _\u27e9\u27e9; refl,\n  right_inv := \u03bb \u27e8\u27e9, rfl }\n\n/-- The bijection between the free group on a singleton, and the integers. -/\ndef free_group_unit_equiv_int : free_group unit \u2243 \u2124 :=\n{ to_fun    := \u03bb x,\n   sum begin revert x, apply monoid_hom.to_fun,\n    apply map (\u03bb _, (1 : \u2124)),\n  end,\n  inv_fun   := \u03bb x, of () ^ x,\n  left_inv  :=\n  begin\n    rintros \u27e8L\u27e9,\n    refine list.rec_on L rfl _,\n    exact (\u03bb \u27e8\u27e8\u27e9, b\u27e9 tl ih, by cases b; simp [gpow_add] at ih \u22a2; rw ih; refl),\n  end,\n  right_inv :=\n    \u03bb x, int.induction_on x (by simp)\n    (\u03bb i ih, by simp at ih; simp [gpow_add, ih])\n    (\u03bb i ih, by simp at ih; simp [gpow_add, ih, sub_eq_add_neg, -int.add_neg_one])\n}\n\nsection category\n\nvariables {\u03b2 : Type u}\n\ninstance : monad free_group.{u} :=\n{ pure := \u03bb \u03b1, of,\n  map := \u03bb \u03b1 \u03b2 f, (map f),\n  bind := \u03bb \u03b1 \u03b2 x f, lift f x }\n\n@[elab_as_eliminator]\nprotected theorem induction_on\n  {C : free_group \u03b1 \u2192 Prop}\n  (z : free_group \u03b1)\n  (C1 : C 1)\n  (Cp : \u2200 x, C $ pure x)\n  (Ci : \u2200 x, C (pure x) \u2192 C (pure x)\u207b\u00b9)\n  (Cm : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) : C z :=\nquot.induction_on z $ \u03bb L, list.rec_on L C1 $ \u03bb \u27e8x, b\u27e9 tl ih,\nbool.rec_on b (Cm _ _ (Ci _ $ Cp x) ih) (Cm _ _ (Cp x) ih)\n\n@[simp] lemma map_pure (f : \u03b1 \u2192 \u03b2) (x : \u03b1) : f <$> (pure x : free_group \u03b1) = pure (f x) :=\nmap.of\n\n@[simp] lemma map_one (f : \u03b1 \u2192 \u03b2) : f <$> (1 : free_group \u03b1) = 1 :=\n(map f).map_one\n\n@[simp] lemma map_mul (f : \u03b1 \u2192 \u03b2) (x y : free_group \u03b1) : f <$> (x * y) = f <$> x * f <$> y :=\n(map f).map_mul x y\n\n@[simp] lemma map_inv (f : \u03b1 \u2192 \u03b2) (x : free_group \u03b1) : f <$> (x\u207b\u00b9) = (f <$> x)\u207b\u00b9 :=\n(map f).map_inv x\n\n@[simp] lemma pure_bind (f : \u03b1 \u2192 free_group \u03b2) (x) : pure x >>= f = f x :=\nlift.of\n\n@[simp] lemma one_bind (f : \u03b1 \u2192 free_group \u03b2) : 1 >>= f = 1 :=\n(lift f).map_one\n\n@[simp] lemma mul_bind (f : \u03b1 \u2192 free_group \u03b2) (x y : free_group \u03b1) :\n  x * y >>= f = (x >>= f) * (y >>= f) :=\n(lift f).map_mul _ _\n\n@[simp] lemma inv_bind (f : \u03b1 \u2192 free_group \u03b2) (x : free_group \u03b1) : x\u207b\u00b9 >>= f = (x >>= f)\u207b\u00b9 :=\n(lift f).map_inv _\n\ninstance : is_lawful_monad free_group.{u} :=\n{ id_map := \u03bb \u03b1 x, free_group.induction_on x (map_one id) (\u03bb x, map_pure id x)\n    (\u03bb x ih, by rw [map_inv, ih]) (\u03bb x y ihx ihy, by rw [map_mul, ihx, ihy]),\n  pure_bind := \u03bb \u03b1 \u03b2 x f, pure_bind f x,\n  bind_assoc := \u03bb \u03b1 \u03b2 \u03b3 x f g, free_group.induction_on x\n    (by iterate 3 { rw one_bind }) (\u03bb x, by iterate 2 { rw pure_bind })\n    (\u03bb x ih, by iterate 3 { rw inv_bind }; rw ih)\n    (\u03bb x y ihx ihy, by iterate 3 { rw mul_bind }; rw [ihx, ihy]),\n  bind_pure_comp_eq_map := \u03bb \u03b1 \u03b2 f x, free_group.induction_on x\n    (by rw [one_bind, map_one]) (\u03bb x, by rw [pure_bind, map_pure])\n    (\u03bb x ih, by rw [inv_bind, map_inv, ih]) (\u03bb x y ihx ihy, by rw [mul_bind, map_mul, ihx, ihy]) }\n\nend category\n\nsection reduce\n\nvariable [decidable_eq \u03b1]\n\n/-- The maximal reduction of a word. It is computable\niff `\u03b1` has decidable equality. -/\ndef reduce (L : list (\u03b1 \u00d7 bool)) : list (\u03b1 \u00d7 bool) :=\nlist.rec_on L [] $ \u03bb hd1 tl1 ih,\nlist.cases_on ih [hd1] $ \u03bb hd2 tl2,\nif hd1.1 = hd2.1 \u2227 hd1.2 = bnot hd2.2 then tl2\nelse hd1 :: hd2 :: tl2\n\n@[simp] lemma reduce.cons (x) : reduce (x :: L) =\n  list.cases_on (reduce L) [x] (\u03bb hd tl,\n  if x.1 = hd.1 \u2227 x.2 = bnot hd.2 then tl\n  else x :: hd :: tl) := rfl\n\n/-- The first theorem that characterises the function\n`reduce`: a word reduces to its maximal reduction. -/\ntheorem reduce.red : red L (reduce L) :=\nbegin\n  induction L with hd1 tl1 ih,\n  case list.nil\n  { constructor },\n  case list.cons\n  { dsimp,\n    revert ih,\n    generalize htl : reduce tl1 = TL,\n    intro ih,\n    cases TL with hd2 tl2,\n    case list.nil\n    { exact red.cons_cons ih },\n    case list.cons\n    { dsimp,\n      by_cases h : hd1.fst = hd2.fst \u2227 hd1.snd = bnot (hd2.snd),\n      { rw [if_pos h],\n        transitivity,\n        { exact red.cons_cons ih },\n        { cases hd1, cases hd2, cases h,\n          dsimp at *, subst_vars,\n          exact red.step.cons_bnot_rev.to_red } },\n      { rw [if_neg h],\n        exact red.cons_cons ih } } }\nend\n\ntheorem reduce.not {p : Prop} :\n  \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)} {x b}, reduce L\u2081 = L\u2082 ++ (x, b) :: (x, bnot b) :: L\u2083 \u2192 p\n| [] L2 L3 _ _ := \u03bb h, by cases L2; injections\n| ((x,b)::L1) L2 L3 x' b' := begin\n  dsimp,\n  cases r : reduce L1,\n  { dsimp, intro h,\n    have := congr_arg list.length h,\n    simp [-add_comm] at this,\n    exact absurd this dec_trivial },\n  cases hd with y c,\n  by_cases x = y \u2227 b = bnot c; simp [h]; intro H,\n  { rw H at r,\n    exact @reduce.not L1 ((y,c)::L2) L3 x' b' r },\n  rcases L2 with _|\u27e8a, L2\u27e9,\n  { injections, subst_vars,\n    simp at h, cc },\n  { refine @reduce.not L1 L2 L3 x' b' _,\n    injection H with _ H,\n    rw [r, H], refl }\nend\n\n/-- The second theorem that characterises the\nfunction `reduce`: the maximal reduction of a word\nonly reduces to itself. -/\ntheorem reduce.min (H : red (reduce L\u2081) L\u2082) : reduce L\u2081 = L\u2082 :=\nbegin\n  induction H with L1 L' L2 H1 H2 ih,\n  { refl },\n  { cases H1 with L4 L5 x b,\n    exact reduce.not H2 }\nend\n\n/-- `reduce` is idempotent, i.e. the maximal reduction\nof the maximal reduction of a word is the maximal\nreduction of the word. -/\ntheorem reduce.idem : reduce (reduce L) = reduce L :=\neq.symm $ reduce.min reduce.red\n\ntheorem reduce.step.eq (H : red.step L\u2081 L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, HR13, HR23\u27e9 := red.church_rosser reduce.red (reduce.red.head H) in\n(reduce.min HR13).trans (reduce.min HR23).symm\n\n/-- If a word reduces to another word, then they have\na common maximal reduction. -/\ntheorem reduce.eq_of_red (H : red L\u2081 L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, HR13, HR23\u27e9 := red.church_rosser reduce.red (red.trans H reduce.red) in\n(reduce.min HR13).trans (reduce.min HR23).symm\n\n/-- If two words correspond to the same element in\nthe free group, then they have a common maximal\nreduction. This is the proof that the function that\nsends an element of the free group to its maximal\nreduction is well-defined. -/\ntheorem reduce.sound (H : mk L\u2081 = mk L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, H13, H23\u27e9 := red.exact.1 H in\n(reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm\n\n/-- If two words have a common maximal reduction,\nthen they correspond to the same element in the free group. -/\ntheorem reduce.exact (H : reduce L\u2081 = reduce L\u2082) : mk L\u2081 = mk L\u2082 :=\nred.exact.2 \u27e8reduce L\u2082, H \u25b8 reduce.red, reduce.red\u27e9\n\n/-- A word and its maximal reduction correspond to\nthe same element of the free group. -/\ntheorem reduce.self : mk (reduce L) = mk L :=\nreduce.exact reduce.idem\n\n/-- If words `w\u2081 w\u2082` are such that `w\u2081` reduces to `w\u2082`,\nthen `w\u2082` reduces to the maximal reduction of `w\u2081`. -/\ntheorem reduce.rev (H : red L\u2081 L\u2082) : red L\u2082 (reduce L\u2081) :=\n(reduce.eq_of_red H).symm \u25b8 reduce.red\n\n/-- The function that sends an element of the free\ngroup to its maximal reduction. -/\ndef to_word : free_group \u03b1 \u2192 list (\u03b1 \u00d7 bool) :=\nquot.lift reduce $ \u03bb L\u2081 L\u2082 H, reduce.step.eq H\n\nlemma to_word.mk : \u2200{x : free_group \u03b1}, mk (to_word x) = x :=\nby rintros \u27e8L\u27e9; exact reduce.self\n\nlemma to_word.inj : \u2200(x y : free_group \u03b1), to_word x = to_word y \u2192 x = y :=\nby rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9; exact reduce.exact\n\n/-- Constructive Church-Rosser theorem (compare `church_rosser`). -/\ndef reduce.church_rosser (H12 : red L\u2081 L\u2082) (H13 : red L\u2081 L\u2083) :\n  { L\u2084 // red L\u2082 L\u2084 \u2227 red L\u2083 L\u2084 } :=\n\u27e8reduce L\u2081, reduce.rev H12, reduce.rev H13\u27e9\n\ninstance : decidable_eq (free_group \u03b1) :=\nfunction.injective.decidable_eq to_word.inj\n\ninstance red.decidable_rel : decidable_rel (@red \u03b1)\n| [] []          := is_true red.refl\n| [] (hd2::tl2)  := is_false $ \u03bb H, list.no_confusion (red.nil_iff.1 H)\n| ((x,b)::tl) [] := match red.decidable_rel tl [(x, bnot b)] with\n  | is_true H  := is_true $ red.trans (red.cons_cons H) $\n    (@red.step.bnot _ [] [] _ _).to_red\n  | is_false H := is_false $ \u03bb H2, H $ red.cons_nil_iff_singleton.1 H2\n  end\n| ((x1,b1)::tl1) ((x2,b2)::tl2) := if h : (x1, b1) = (x2, b2)\n  then match red.decidable_rel tl1 tl2 with\n    | is_true H  := is_true $ h \u25b8 red.cons_cons H\n    | is_false H := is_false $ \u03bb H2, H $ h \u25b8 (red.cons_cons_iff _).1 $ H2\n    end\n  else match red.decidable_rel tl1 ((x1,bnot b1)::(x2,b2)::tl2) with\n    | is_true H  := is_true $ (red.cons_cons H).tail red.step.cons_bnot\n    | is_false H := is_false $ \u03bb H2, H $ red.inv_of_red_of_ne h H2\n    end\n\n/-- A list containing every word that `w\u2081` reduces to. -/\ndef red.enum (L\u2081 : list (\u03b1 \u00d7 bool)) : list (list (\u03b1 \u00d7 bool)) :=\nlist.filter (\u03bb L\u2082, red L\u2081 L\u2082) (list.sublists L\u2081)\n\ntheorem red.enum.sound (H : L\u2082 \u2208 red.enum L\u2081) : red L\u2081 L\u2082 :=\nlist.of_mem_filter H\n\ntheorem red.enum.complete (H : red L\u2081 L\u2082) : L\u2082 \u2208 red.enum L\u2081 :=\nlist.mem_filter_of_mem (list.mem_sublists.2 $ red.sublist H) H\n\ninstance : fintype { L\u2082 // red L\u2081 L\u2082 } :=\nfintype.subtype (list.to_finset $ red.enum L\u2081) $\n\u03bb L\u2082, \u27e8\u03bb H, red.enum.sound $ list.mem_to_finset.1 H,\n  \u03bb H, list.mem_to_finset.2 $ red.enum.complete H\u27e9\n\nend reduce\n\nend free_group\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/free_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642806, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.7140659720078744}}
{"text": "/-\nCopyright (c) 2021 Fran\u00e7ois Sunatori. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fran\u00e7ois Sunatori\n-/\nimport analysis.complex.circle\nimport linear_algebra.determinant\nimport linear_algebra.matrix.general_linear_group\n\n/-!\n# Isometries of the Complex Plane\n\nThe lemma `linear_isometry_complex` states the classification of isometries in the complex plane.\nSpecifically, isometries with rotations but without translation.\nThe proof involves:\n1. creating a linear isometry `g` with two fixed points, `g(0) = 0`, `g(1) = 1`\n2. applying `linear_isometry_complex_aux` to `g`\nThe proof of `linear_isometry_complex_aux` is separated in the following parts:\n1. show that the real parts match up: `linear_isometry.re_apply_eq_re`\n2. show that I maps to either I or -I\n3. every z is a linear combination of a + b * I\n\n## References\n\n* [Isometries of the Complex Plane](http://helmut.knaust.info/mediawiki/images/b/b5/Iso.pdf)\n-/\nnoncomputable theory\n\nopen complex\nopen_locale complex_conjugate\n\nlocal notation (name := complex.abs) `|` x `|` := complex.abs x\n\n/-- An element of the unit circle defines a `linear_isometry_equiv` from `\u2102` to itself, by\nrotation. -/\ndef rotation : circle \u2192* (\u2102 \u2243\u2097\u1d62[\u211d] \u2102) :=\n{ to_fun := \u03bb a,\n  { norm_map' := \u03bb x, show |a * x| = |x|, by rw [map_mul, abs_coe_circle, one_mul],\n    ..distrib_mul_action.to_linear_equiv \u211d \u2102 a },\n  map_one' := linear_isometry_equiv.ext $ one_smul _,\n  map_mul' := \u03bb _ _, linear_isometry_equiv.ext $ mul_smul _ _ }\n\n@[simp] lemma rotation_apply (a : circle) (z : \u2102) : rotation a z = a * z := rfl\n\n@[simp] lemma rotation_symm (a : circle) : (rotation a).symm = rotation a\u207b\u00b9 :=\nlinear_isometry_equiv.ext $ \u03bb x, rfl\n\n@[simp] lemma rotation_trans (a b : circle) :\n  (rotation a).trans (rotation b) = rotation (b * a) :=\nby { ext1, simp }\n\nlemma rotation_ne_conj_lie (a : circle) : rotation a \u2260 conj_lie :=\nbegin\n  intro h,\n  have h1 : rotation a 1 = conj 1 := linear_isometry_equiv.congr_fun h 1,\n  have hI : rotation a I = conj I := linear_isometry_equiv.congr_fun h I,\n  rw [rotation_apply, ring_hom.map_one, mul_one] at h1,\n  rw [rotation_apply, conj_I, \u2190 neg_one_mul, mul_left_inj' I_ne_zero, h1, eq_neg_self_iff] at hI,\n  exact one_ne_zero hI,\nend\n\n/-- Takes an element of `\u2102 \u2243\u2097\u1d62[\u211d] \u2102` and checks if it is a rotation, returns an element of the\nunit circle. -/\n@[simps]\ndef rotation_of (e : \u2102 \u2243\u2097\u1d62[\u211d] \u2102) : circle :=\n\u27e8(e 1) / complex.abs (e 1), by simp\u27e9\n\n@[simp]\nlemma rotation_of_rotation (a : circle) : rotation_of (rotation a) = a :=\nsubtype.ext $ by simp\n\nlemma rotation_injective : function.injective rotation :=\nfunction.left_inverse.injective rotation_of_rotation\n\nlemma linear_isometry.re_apply_eq_re_of_add_conj_eq (f : \u2102 \u2192\u2097\u1d62[\u211d] \u2102)\n  (h\u2083 : \u2200 z, z + conj z = f z + conj (f z)) (z : \u2102) : (f z).re = z.re :=\nby simpa [ext_iff, add_re, add_im, conj_re, conj_im, \u2190two_mul,\n         (show (2 : \u211d) \u2260 0, by simp [two_ne_zero])] using (h\u2083 z).symm\n\nlemma linear_isometry.im_apply_eq_im_or_neg_of_re_apply_eq_re {f : \u2102 \u2192\u2097\u1d62[\u211d] \u2102}\n  (h\u2082 : \u2200 z, (f z).re = z.re) (z : \u2102) :\n  (f z).im = z.im \u2228 (f z).im = -z.im :=\nbegin\n  have h\u2081 := f.norm_map z,\n  simp only [complex.abs_def, norm_eq_abs] at h\u2081,\n  rwa [real.sqrt_inj (norm_sq_nonneg _) (norm_sq_nonneg _), norm_sq_apply (f z), norm_sq_apply z,\n    h\u2082, add_left_cancel_iff, mul_self_eq_mul_self_iff] at h\u2081,\nend\n\nlemma linear_isometry.im_apply_eq_im {f : \u2102 \u2192\u2097\u1d62[\u211d] \u2102} (h : f 1 = 1) (z : \u2102) :\n  z + conj z = f z + conj (f z) :=\nbegin\n  have : \u2016f z - 1\u2016 = \u2016z - 1\u2016 := by rw [\u2190 f.norm_map (z - 1), f.map_sub, h],\n  apply_fun \u03bb x, x ^ 2 at this,\n  simp only [norm_eq_abs, \u2190norm_sq_eq_abs] at this,\n  rw [\u2190of_real_inj, \u2190mul_conj, \u2190mul_conj] at this,\n  rw [ring_hom.map_sub, ring_hom.map_sub] at this,\n  simp only [sub_mul, mul_sub, one_mul, mul_one] at this,\n  rw [mul_conj, norm_sq_eq_abs, \u2190norm_eq_abs, linear_isometry.norm_map] at this,\n  rw [mul_conj, norm_sq_eq_abs, \u2190norm_eq_abs] at this,\n  simp only [sub_sub, sub_right_inj, mul_one, of_real_pow, ring_hom.map_one, norm_eq_abs] at this,\n  simp only [add_sub, sub_left_inj] at this,\n  rw [add_comm, \u2190this, add_comm],\nend\n\nlemma linear_isometry.re_apply_eq_re {f : \u2102 \u2192\u2097\u1d62[\u211d] \u2102} (h : f 1 = 1) (z : \u2102) : (f z).re = z.re :=\nbegin\n  apply linear_isometry.re_apply_eq_re_of_add_conj_eq,\n  intro z,\n  apply linear_isometry.im_apply_eq_im h,\nend\n\nlemma linear_isometry_complex_aux {f : \u2102 \u2243\u2097\u1d62[\u211d] \u2102} (h : f 1 = 1) :\n  f = linear_isometry_equiv.refl \u211d \u2102 \u2228 f = conj_lie :=\nbegin\n  have h0 : f I = I \u2228 f I = -I,\n  { have : |f I| = 1 := by simpa using f.norm_map complex.I,\n    simp only [ext_iff, \u2190and_or_distrib_left, neg_re, I_re, neg_im, neg_zero],\n    split,\n    { rw \u2190I_re,\n      exact @linear_isometry.re_apply_eq_re f.to_linear_isometry h I, },\n    { apply @linear_isometry.im_apply_eq_im_or_neg_of_re_apply_eq_re f.to_linear_isometry,\n      intro z, rw @linear_isometry.re_apply_eq_re f.to_linear_isometry h } },\n  refine h0.imp (\u03bb h' : f I = I, _) (\u03bb h' : f I = -I, _);\n  { apply linear_isometry_equiv.to_linear_equiv_injective,\n    apply complex.basis_one_I.ext',\n    intros i,\n    fin_cases i; simp [h, h'] }\nend\n\nlemma linear_isometry_complex (f : \u2102 \u2243\u2097\u1d62[\u211d] \u2102) :\n  \u2203 a : circle, f = rotation a \u2228 f = conj_lie.trans (rotation a) :=\nbegin\n  let a : circle := \u27e8f 1, by simpa using f.norm_map 1\u27e9,\n  use a,\n  have : (f.trans (rotation a).symm) 1 = 1,\n  { simpa using rotation_apply a\u207b\u00b9 (f 1) },\n  refine (linear_isometry_complex_aux this).imp (\u03bb h\u2081, _) (\u03bb h\u2082, _),\n  { simpa using eq_mul_of_inv_mul_eq h\u2081 },\n  { exact eq_mul_of_inv_mul_eq h\u2082 }\nend\n\n/-- The matrix representation of `rotation a` is equal to the conformal matrix\n`!![re a, -im a; im a, re a]`. -/\nlemma to_matrix_rotation (a : circle) :\n  linear_map.to_matrix basis_one_I basis_one_I (rotation a).to_linear_equiv =\n    matrix.plane_conformal_matrix (re a) (im a) (by simp [pow_two, \u2190norm_sq_apply]) :=\nbegin\n  ext i j,\n  simp [linear_map.to_matrix_apply],\n  fin_cases i; fin_cases j; simp\nend\n\n/-- The determinant of `rotation` (as a linear map) is equal to `1`. -/\n@[simp] lemma det_rotation (a : circle) : ((rotation a).to_linear_equiv : \u2102 \u2192\u2097[\u211d] \u2102).det = 1 :=\nbegin\n  rw [\u2190linear_map.det_to_matrix basis_one_I, to_matrix_rotation, matrix.det_fin_two],\n  simp [\u2190norm_sq_apply]\nend\n\n/-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/\n@[simp] lemma linear_equiv_det_rotation (a : circle) : (rotation a).to_linear_equiv.det = 1 :=\nby rw [\u2190units.eq_iff, linear_equiv.coe_det, det_rotation, units.coe_one]\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/complex/isometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7140659695238936}}
{"text": "import topology.basic\nopen topological_space\nopen set filter classical\nvariables {X : Type} [topological_space X] {A E F U V : set X}\n\n-- Example 2.1.1.\nexample : is_closed F \u2192 A \u2286 F \u2192 closure A \u2286 F :=\nbegin\n  intros Fclosed AinF,\n  unfold closure,\n  /- \n  this is not how closure is defined in the module.\n  smallest closed set containing A? I guess it kinda makes sense. \n  -/\n  let T := {t : set X | is_closed t \u2227 A \u2286 t},\n  have : F \u2208 T,\n  apply and.intro,\n  exact Fclosed,\n  exact AinF,\n  /-\n  Since F is one of the closed set containing A,\n  intersections of sets in T (including F) is obviously a subset of F.\n  -/\n  apply sInter_subset_of_mem,\n  exact this,\nend\n\nexample : is_open U \u2192 U \u2286 A \u2192 U \u2286 interior A :=\nbegin\n  intros Uopen UinA,\n  unfold interior,\n  -- A\u00b0 = largest open set within A?\n  let T := {t : set X | is_open t \u2227 t \u2286 A},\n  have h1 : U \u2208 T,\n    exact and.intro Uopen UinA,\n  -- I would assume there is a equivalent thing but I don't seem to be able to find it so,\n  apply set.subset_sUnion_of_subset T U,\n  {by refl},\n  {exact h1},\nend\n", "meta": {"author": "Jun2M", "repo": "Lean_Topology", "sha": "74fa55946995ea139133ae5d5e67236570ba7e0d", "save_path": "github-repos/lean/Jun2M-Lean_Topology", "path": "github-repos/lean/Jun2M-Lean_Topology/Lean_Topology-74fa55946995ea139133ae5d5e67236570ba7e0d/src/Week 7 top.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379298, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7140659693422629}}
{"text": "import algebra.lattice.basic algebra.lattice.bounded_lattice algebra.lattice.complete_lattice\nimport data.set \n\nuniverses u v w\nopen lattice\nset_option old_structure_cmd true \nset_option eqn_compiler.zeta true\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v}{\u03b3 : Type w}\n\nprivate lemma exists_add_of_le : \u2200 {m n : \u2115}, m \u2264 n \u2192 \u2203 k, n = m + k := \n  begin\n   intros m n hle,\n   existsi n - m,\n   rw [nat.add_sub_of_le],\n   assumption\n  end\n\ndef is_directed [weak_order \u03b1] (s : set \u03b1) := \u2200 a b \u2208 s, \u2203 c, c \u2208 s \u2227 a \u2264 c \u2227 b \u2264 c \ndef is_chain [weak_order \u03b1] (s : set \u03b1)  := \u2200 a b \u2208 s, a \u2264 b \u2228 b \u2264 a \n\ndef chain [weak_order \u03b1] := {s : set \u03b1 // is_chain s}\n\ndef ascending_chain \u03b1 [weak_order \u03b1] := { f : \u2115 \u2192 \u03b1 //  \u2200 n, f n \u2264 f (n + 1) }\n\nnamespace ascending_chain\nvariables [weak_order \u03b1] \n\nprotected\ndef mem (a : \u03b1)(f : ascending_chain \u03b1) : Prop := \u2203 n : \u2115, a = f.1 n\ninstance : has_mem \u03b1 (ascending_chain \u03b1) := \u27e8 ascending_chain.mem \u27e9  \n\ndef monotone (f : ascending_chain \u03b1) {m n} : m \u2264 n \u2192 f.1 m \u2264 f.1 n :=     \nbegin \nintro hle,\ncases (exists_add_of_le hle) with k hk,\nrw hk,\nclear hk,\ninduction k with k iH,\nrefl,\ntransitivity f.1 (m + k),\nassumption,\nrw nat.add_succ,\napply f.property\nend\n\ndef is_stationary (f : ascending_chain \u03b1) : Prop := \u2203 n, \u2200 m, n \u2264 m \u2192 f.1 n = f.1 m \n\nend ascending_chain\n\ndef iter_n (f : \u03b1 \u2192 \u03b1) (z : \u03b1) : \u2115 \u2192 \u03b1 \n|  0 := z \n|  (n + 1) := f $ iter_n n\n\n\nnamespace iter_n \nvariables [weak_order \u03b1] {f : \u03b1 \u2192 \u03b1}\n\nlemma single_step {z : \u03b1} : monotone f \u2192 z \u2264 f z \u2192 \u2200 {{n : \u2115}}, iter_n f z n \u2264 iter_n f z (n+1) := \n  begin\n    intros hmono hini n,\n    induction n with n iH,\n     assumption,\n     apply hmono, assumption\n  end     \n\ndef to_ascending_chain {f} {z} : monotone f \u2192 z \u2264 f z \u2192 ascending_chain \u03b1 := \n  assume hmono hini, \u27e8iter_n f z, take n, begin apply single_step, repeat {assumption} end\u27e9 \n\nlemma upper_bound (a : \u03b1) {z} : monotone f \u2192 z \u2264 a \u2192 f a \u2264 a \u2192 \u2200 {{n}}, iter_n f z n \u2264 a := \nassume hmono hini hle, \n  take n,\n    nat.rec_on n hini (take n, assume iH, calc iter_n f z (n+1) = f (iter_n f z n) : by refl \n                                                            ... \u2264 f a              : hmono iH \n                                                            ... \u2264 a                : hle  \n                      )\n\nend iter_n\n\ndef iter_n\u2081 (f : \u03b1 \u2192 \u03b1) : \u2115 \u2192 \u03b1 \u2192 \u03b1 \n| 0 := id \n| (n+1) := \u03bb a, iter_n\u2081 n $ f a\n\nnamespace iter_n\u2081 \nvariables {f : \u03b1 \u2192 \u03b1}\n\n@[simp]\nlemma iter_eq : \u2200 {n}{z}, iter_n\u2081 f (n+1) z = f (iter_n\u2081 f n z) \n| 0 _ := rfl \n| (n+1) z := calc iter_n\u2081 f (n + 2) z = iter_n\u2081 f (n + 1) (f z) : by refl \n                                 ...  = f (iter_n\u2081 f n (f z))   : by rw iter_eq \n                                 ...  = f (iter_n\u2081 f (n+1) z)   : by refl \n\nlemma single_step [weak_order \u03b1] {z} (hmono : monotone f) (hini : z \u2264 f z) : \u2200 n, iter_n\u2081 f n z \u2264 iter_n\u2081 f (n+1) z \n| 0     := hini \n| (n+1) := calc iter_n\u2081 f (n+1) z = f (iter_n\u2081 f n z)     : iter_eq \n                            ...   \u2264 f (iter_n\u2081 f (n+1) z) : hmono (single_step n) \n                            ...   = iter_n\u2081 f (n+2) z     : iter_eq.symm \n\ndef to_ascending_chain [weak_order \u03b1] {z} : monotone f \u2192 z \u2264 f z \u2192 ascending_chain \u03b1 := \n  assume hmono hini, \u27e8_, single_step hmono hini\u27e9 \n   \nend iter_n\u2081\n\nnamespace is_directed \n\nlemma empty [weak_order \u03b1] : is_directed (\u2205 : set \u03b1) := take a b, false.elim\n\nlemma univ  [semilattice_sup \u03b1] : is_directed (set.univ : set \u03b1) := \n    take a b, assume ha hb, \u27e8a \u2294 b , true.intro ,le_sup_left  , le_sup_right\u27e9  \n\nlemma singleton [weak_order \u03b1] {a} : is_directed ({a} : set \u03b1) := \n   take x y, assume hx hy, \n      have eqx : x = a, from or.resolve_right hx false.elim,\n      have eqy : y = a, from or.resolve_right hy false.elim,\n      by rw [eqx, eqy]; exact \u27e8a, or.inl rfl, le_refl _ , le_refl _\u27e9 \n\nlemma of_is_chain [weak_order \u03b1] { s : set \u03b1 } : is_chain s \u2192 is_directed s := \n   assume h, take x y, assume hx hy, \n   or.elim  (h _ _ hx hy) \n      (assume hxy, \u27e8_, hy, hxy, by refl\u27e9) \n      (assume hyx, \u27e8_, hx, by refl, hyx\u27e9) \n\nlemma of_ascending_chain [weak_order \u03b1](f : ascending_chain \u03b1) : is_directed { a : \u03b1 | a \u2208 f } := \n  take x y, assume \u27e8m, hm\u27e9 \u27e8n, hn\u27e9,  \n    eq.rec_on hm.symm \n    (eq.rec_on hn.symm \n      (match le_total m n with \n       | or.inl hmn := \u27e8f.1 n, \u27e8_, rfl\u27e9, f.monotone hmn , by refl\u27e9  \n       | or.inr hnm := \u27e8f.1 m, \u27e8_, rfl\u27e9, by refl , f.monotone hnm\u27e9  \n       end\n      )\n    )\n lemma of_lower_set [weak_order \u03b1] (a : \u03b1) : is_directed ({ x | x \u2264 a}) := \n   take x y, assume hx hy, \u27e8a, le_refl _, hx, hy\u27e9   \n\nend is_directed\n\ndef directed \u03b1 [weak_order \u03b1] := { s : set \u03b1 // is_directed s }\n\ninstance [weak_order \u03b1] : has_mem \u03b1 (directed \u03b1) := \u27e8 \u03bb a s, a \u2208 s.1\u27e9  \ninstance [weak_order \u03b1] : has_emptyc (directed \u03b1) := \u27e8 \u27e8_, is_directed.empty\u27e9 \u27e9  \ninstance [weak_order \u03b1] : has_subset (directed \u03b1) := \u27e8 \u03bb s t, s.1 \u2286 t.1 \u27e9 \n\ndef directed.of_ascending_chain [weak_order \u03b1] : ascending_chain \u03b1 \u2192 directed \u03b1 := \u03bb seq, \u27e8_, is_directed.of_ascending_chain seq\u27e9  \ndef directed.of_lower_set [weak_order \u03b1] : \u03b1 \u2192 directed \u03b1 := \u03bb a, \u27e8_, is_directed.of_lower_set a\u27e9  \n\nclass directed_complete_partial_order \u03b1 extends weak_order \u03b1 := \n  (dSup : directed \u03b1 \u2192 \u03b1)\n  (le_dSup : \u2200 s, \u2200 a \u2208 s, a \u2264 dSup s)  \n  (dSup_le : \u2200 s a, (\u2200 b\u2208s, b \u2264 a) \u2192 dSup s \u2264 a)\n\ndef dSup [directed_complete_partial_order \u03b1] : directed \u03b1 \u2192 \u03b1 := directed_complete_partial_order.dSup \n\nsection \nvariables [directed_complete_partial_order \u03b1]{s t : directed \u03b1} {a b : \u03b1}\n\nlemma le_dSup : a \u2208 s \u2192 a \u2264 dSup s := directed_complete_partial_order.le_dSup s a \nlemma dSup_le : (\u2200 b \u2208 s, b \u2264 a) \u2192 dSup s \u2264 a := directed_complete_partial_order.dSup_le s a \nlemma le_dSup_of_le (hb : b \u2208 s) (h : a \u2264 b) : a \u2264 dSup s := le_trans h (le_dSup hb) \n\nlemma dSup_le_dSup (h : s \u2286 t) : dSup s \u2264 dSup t := \n  dSup_le ( take a, assume ha : a \u2208 s, le_dSup $ h ha)\nend \nnamespace directed_complete_partial_order \n\nvariables [directed_complete_partial_order \u03b1] {a b : \u03b1}\n\ndef bot : \u03b1 := dSup \u2205  \nlemma bot_le : bot \u2264 a := \n  dSup_le _ _ (take b, false.elim) \n\n  \nend directed_complete_partial_order\n\ninstance directed_complete_partial_order_bot [ ins : directed_complete_partial_order \u03b1] : order_bot \u03b1 := \n{\n  ins with \n  bot := directed_complete_partial_order.bot,\n  bot_le := @directed_complete_partial_order.bot_le _ _,\n}\n\nclass directed_complete_partial_order_sup \u03b1 extends semilattice_sup \u03b1 , directed_complete_partial_order \u03b1 \n\ninstance directed_complete_partial_order_sup_top [ ins : directed_complete_partial_order_sup \u03b1] : semilattice_sup_top \u03b1 := \n{\n  ins with \n  top := dSup \u27e8set.univ, take x y, assume hx hy, \u27e8_ , true.intro, le_sup_left, le_sup_right\u27e9\u27e9,  \n  le_top := take _, le_dSup true.intro\n}\n\ninstance complete_lattice_directed_complete_partial_order_sup [ins : complete_lattice \u03b1] : directed_complete_partial_order_sup \u03b1 := \n{\n    ins with \n    dSup := \u03bb s, Sup s.1,\n    le_dSup := \u03bb s a, assume ha, le_Sup ha,\n    dSup_le := \u03bb s a, assume h, Sup_le (take _ hb, h _ hb) \n} \n\nstructure is_scott_continuous [directed_complete_partial_order \u03b1] [directed_complete_partial_order \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop := \n  (preserve_directed : \u2200 s : directed \u03b1, is_directed (set.image f s.1))\n  (preserve_dSup     : \u2200 s : directed \u03b1, f (dSup s) = dSup \u27e8_, preserve_directed s\u27e9)\n\nnamespace is_scott_continuous \nvariables [directed_complete_partial_order \u03b1] [directed_complete_partial_order \u03b2][directed_complete_partial_order \u03b3] \n   {f : \u03b1 \u2192 \u03b2}{g : \u03b2 \u2192 \u03b3}\n\nprivate lemma set_image_id {\u03b1 : Type u} {s : set \u03b1} : set.image (@id \u03b1) s = s := \n  set.ext (take a, iff.intro (assume \u27e8_, hx, eqx\u27e9, eq.rec_on eqx hx) \n                             (assume ha, \u27e8_, ha, rfl\u27e9 ))\nprotected\nlemma id : is_scott_continuous (@id \u03b1) := \n  \u27e8 \u03bb s, begin rw set_image_id, apply s.2 end , take s, begin simp, apply congr_arg, symmetry, apply subtype.eq, apply set_image_id end \u27e9 \n\nprotected\nlemma comp : is_scott_continuous g \u2192 is_scott_continuous f \u2192 is_scott_continuous (g \u2218 f) := \n  assume hg hf, \n    have pr_dir : \u2200 s : directed \u03b1, is_directed (set.image (g \u2218 f) s.1), \n       from \n          take sa, take c\u2081 c\u2082, assume \u27e8a\u2081, ha\u2081, eqc\u2081\u27e9 \u27e8a\u2082, ha\u2082, eqc\u2082\u27e9, \n            let sb : directed \u03b2 := \u27e8_, hf.preserve_directed sa\u27e9 in\n            match (hg.preserve_directed sb _ _ \u27e8_, \u27e8_, ha\u2081, rfl\u27e9, eqc\u2081\u27e9 \u27e8_, \u27e8_, ha\u2082, rfl\u27e9, eqc\u2082\u27e9) with\n            | \u27e8c, \u27e8b, \u27e8a, ha, hab\u27e9 , hbc \u27e9, hfc\u2081c, hfc\u2082c\u27e9 := \n              \u27e8c, \u27e8a, ha, begin rw -hab at hbc, assumption end\u27e9  , hfc\u2081c , hfc\u2082c \u27e9  \n            end,\n    \u27e8pr_dir, \n      take sa, \n        let sb : directed \u03b2 := \u27e8_, hf.preserve_directed sa\u27e9 in\n        show g (f (dSup sa)) = dSup \u27e8_, pr_dir sa\u27e9, \n          from begin\n                 rw hf.preserve_dSup,\n                 rw hg.preserve_dSup,\n                 apply congr_arg, apply subtype.eq,\n                 apply set.ext, \n                 intro c, \n                 apply iff.intro,\n                  {\n                      intro h,\n                      cases h with b hb,\n                      cases hb with hb eqbc,\n                      cases hb with a ha,\n                      cases ha with ha eqab,\n                      rw -eqab at eqbc,\n                      exact \u27e8_, ha, eqbc\u27e9 \n                  },\n                  {\n                      intro h,\n                      cases h with a ha,\n                      cases ha with ha eqac,\n                      exact \u27e8_, \u27e8_, ha, rfl\u27e9, eqac\u27e9 \n                  }\n               end \n      \u27e9 \n            \n \nlemma monotone : is_scott_continuous f \u2192 monotone f := \n assume hcont, take a b, assume hab,\n    have ab_is_chain : is_chain ({a,b} : set \u03b1), \n       from begin \n             intros x y hx hy,\n             cases hx with xb hx,\n               rw xb, \n               cases hy with yb hy,\n               rw yb, simp,\n               cases hy with ya hy,\n               simph, \n               apply false.elim, assumption,\n            cases hx with xa hx,\n               rw xa,\n               cases hy with yb hy, \n               rw yb, left, assumption,\n               cases hy with ya hy,\n               simph,\n               apply false.elim, assumption,\n            apply false.elim, assumption\n            end,\n    let s : directed \u03b1 := \u27e8_, is_directed.of_is_chain ab_is_chain\u27e9 in\n    have H : dSup s = b, \n      from begin \n            apply le_antisymm,\n             { apply dSup_le, \n               intros x hx,\n               cases hx with xb hx,\n                 rw xb,\n               cases hx with xa hx,\n                 rw xa, assumption,\n               apply false.elim, assumption\n             },\n             {\n                 apply le_dSup,\n                 apply or.inl, refl\n             }\n           end,\n    let s_image : directed \u03b2 := \u27e8_, hcont.preserve_directed s\u27e9 in \n    have fH : dSup s_image = f b, \n      from begin \n            rw -hcont.preserve_dSup,\n            rw H\n           end,\n    show f a \u2264 f b, \n      from begin\n            rw -fH,\n            apply le_dSup,\n            exact \u27e8_, or.inr (or.inl rfl), rfl\u27e9 \n           end\n  private lemma set_image_empty {\u03b1}{\u03b2} {f : \u03b1 \u2192 \u03b2} : set.image f \u2205 = \u2205 := \n     set.ext (take x, \u27e8 assume \u27e8_, h, _\u27e9, h.elim, false.elim \u27e9 )\n\n  lemma is_strict : is_scott_continuous f \u2192 f \u22a5 = \u22a5 := \n    assume hcont, eq.trans (hcont.preserve_dSup \u2205) (congr_arg dSup (subtype.eq set_image_empty))\n\n\nend is_scott_continuous\n\ndef scott_continuous \u03b1 \u03b2 [directed_complete_partial_order \u03b1] [directed_complete_partial_order \u03b2] := { f : \u03b1 \u2192 \u03b2 // is_scott_continuous f }\n\nnamespace scott_continuous \n\nvariables [directed_complete_partial_order \u03b1] [directed_complete_partial_order \u03b2][directed_complete_partial_order \u03b3]\n {f : scott_continuous \u03b1 \u03b2} {g : scott_continuous \u03b2 \u03b3}\nprotected\ndef id : scott_continuous \u03b1 \u03b1 := \u27e8 _, is_scott_continuous.id\u27e9 \nprotected\ndef comp : scott_continuous \u03b2 \u03b3 \u2192 scott_continuous \u03b1 \u03b2 \u2192 scott_continuous \u03b1 \u03b3 := take g f, \u27e8_, is_scott_continuous.comp g.2 f.2\u27e9 \nprotected\ndef monotone (f : scott_continuous \u03b1 \u03b2) : monotone f.1 := f.2.monotone \n\n\nprotected \ndef le (f g : scott_continuous \u03b1 \u03b2) : Prop := \u2200 a , f.1 a \u2264 g.1 a  \n\ninstance : has_le (scott_continuous \u03b1 \u03b2) := \u27e8 scott_continuous.le \u27e9 \n\n@[refl]\nprotected \ndef le_refl (f : scott_continuous \u03b1 \u03b2) : f \u2264 f := take a : \u03b1, le_refl _\n\n@[trans]\nprotected \ndef le_trans  (f g h : scott_continuous \u03b1 \u03b2) : f \u2264 g \u2192 g \u2264 h \u2192 f \u2264 h := take hfg hgh, take a, le_trans (hfg a) (hgh a) \n\nprotected\ndef le_antisymm (f g : scott_continuous \u03b1 \u03b2) : f \u2264 g \u2192 g \u2264 f \u2192 f = g := \n  take hfg hgf, subtype.eq (funext (take a, le_antisymm (hfg a) (hgf a))) \n\ninstance scott_continuous_weak_order : weak_order (scott_continuous \u03b1 \u03b2) := \n{\n    le := scott_continuous.le,\n    le_refl := scott_continuous.le_refl,\n    le_trans := scott_continuous.le_trans,\n    le_antisymm := scott_continuous.le_antisymm\n}\n/-\nprotected\ndef sup (f g : scott_continuous \u03b1 \u03b2) : scott_continuous \u03b1 \u03b2 := \n  let h := \u03bb a, f.1 a \u2294 g.1 a in  \n  have h_monotone : monotone h, from \n    take a b, assume hab, sup_le_sup (f.monotone hab) (g.monotone hab),\n  have pr_dir : \u2200 s : directed \u03b1, is_directed (set.image h s.1), \n    from take s, take b\u2081 b\u2082, assume \u27e8a\u2081, ha\u2081, eqa\u2081\u27e9 \u27e8a\u2082, ha\u2082, eqa\u2082\u27e9,      \n         match s.property _ _ ha\u2081 ha\u2082 with \n         | \u27e8b, bmem, ha\u2081b, ha\u2082b\u27e9 := \n           \u27e8_, \u27e8_, bmem, rfl\u27e9, eq.rec_on eqa\u2081 (h_monotone ha\u2081b), eq.rec_on eqa\u2082 (h_monotone ha\u2082b)\u27e9  \n         end,\n   \u27e8 _, pr_dir, \n     take s, \n     le_antisymm \n       (begin \n        apply sup_le,\n        {\n            rw f.2.preserve_dSup,\n            apply dSup_le,\n            intros b hb,\n            cases hb with a ha,\n            cases ha with ha eqab,\n            rw -eqab,\n            apply le_dSup_of_le,\n              exact \u27e8_ , ha, rfl\u27e9,\n            apply le_sup_left              \n        },\n        {\n            rw g.2.preserve_dSup,\n            apply dSup_le,\n            intros b hb,\n            cases hb with a ha,\n            cases ha with ha eqab,\n            rw -eqab,\n            apply le_dSup_of_le,\n            exact \u27e8_ , ha, rfl\u27e9,\n            apply le_sup_right\n        }\n        end) \n       (dSup_le (take b, \n         assume \u27e8a, ha, eqa\u27e9,  \n         begin \n         rw -eqa,\n         apply h_monotone,\n         apply le_dSup,\n         assumption\n         end\n         )) \n   \u27e9     \n\ninstance : has_sup (scott_continuous \u03b1 \u03b2) := \u27e8scott_continuous.sup\u27e9   \nprotected \nlemma le_sup_left (f g : scott_continuous \u03b1 \u03b2) : f \u2264 f \u2294 g := \n  take a, le_sup_left\n\nprotected \nlemma le_sup_right (f g : scott_continuous \u03b1 \u03b2) : g \u2264 f \u2294 g := \n  take a, le_sup_right\n\nprotected    \nlemma sup_le (f g h : scott_continuous \u03b1 \u03b2) : f \u2264 h \u2192 g \u2264 h \u2192 f \u2294 g \u2264 h := \n  assume hfh hgh, take a, sup_le (hfh a) (hgh a) \n\ninstance scott_continuous_semilattice_sup : semilattice_sup (scott_continuous \u03b1 \u03b2) := \n{\n    le := scott_continuous.le,\n    le_refl := scott_continuous.le_refl,\n    le_trans := scott_continuous.le_trans,\n    le_antisymm := scott_continuous.le_antisymm,\n    sup := scott_continuous.sup,\n    le_sup_left := scott_continuous.le_sup_left,\n    le_sup_right := scott_continuous.le_sup_right,\n    sup_le := scott_continuous.sup_le\n} \n-/\ndef sapply (f : scott_continuous \u03b1 \u03b2) (s : directed \u03b1) : directed \u03b2 := \u27e8_, f.2.preserve_directed s\u27e9 \n\nprotected\ndef dSup (fs : directed (scott_continuous \u03b1 \u03b2)) : scott_continuous \u03b1 \u03b2 := \n  let s := \u03bb a : \u03b1, {b : \u03b2 | \u2203 f : scott_continuous \u03b1 \u03b2, f \u2208 fs \u2227 b = f.1 a} in   \n  have s_directed : \u2200 a, is_directed (s a), from \n    take a b\u2081 b\u2082, assume \u27e8f\u2081, hf\u2081, eqb\u2081\u27e9  \u27e8f\u2082, hf\u2082, eqb\u2082\u27e9,\n      match fs.property _ _ hf\u2081 hf\u2082 with \n      | \u27e8f, hf, hf\u2081f, hf\u2082f\u27e9 := \u27e8_, \u27e8_, hf, rfl\u27e9, \n          eq.rec_on eqb\u2081.symm (hf\u2081f _), eq.rec_on eqb\u2082.symm (hf\u2082f _)\u27e9 \n      end,\n  let sup_fs := \u03bb a : \u03b1, dSup \u27e8_, s_directed a\u27e9 in \n  have sup_fs_monotone : monotone sup_fs, from \n     take a\u2081 a\u2082, assume h, dSup_le (take b, assume \u27e8f, hf, eqf\u27e9, le_dSup_of_le \u27e8_, hf, rfl\u27e9 (eq.rec_on eqf.symm (f.monotone h))), \n  have pr_dir : \u2200 s : directed \u03b1, is_directed (set.image sup_fs s.1), \n    from take s, take b\u2081 b\u2082, assume \u27e8a\u2081, ha\u2081, eqb\u2081\u27e9 \u27e8a\u2082, ha\u2082, eqb\u2082\u27e9,    \n       match s.property _ _ ha\u2081 ha\u2082 with \n       | \u27e8a, ha, ha\u2081a, ha\u2082a\u27e9 := \u27e8_, \u27e8_, ha, rfl\u27e9, \n         eq.rec_on eqb\u2081 (sup_fs_monotone ha\u2081a), eq.rec_on eqb\u2082 (sup_fs_monotone ha\u2082a)\u27e9  \n       end,\n  \u27e8_, pr_dir, \n   take s, \n     le_antisymm \n       (dSup_le (take b, assume \u27e8f, hf, eqf\u27e9, \n        begin \n        rw eqf,\n        rw f.2.preserve_dSup,\n        apply dSup_le,\n        intros b hb,\n        cases hb with a ha,\n        cases ha with ha eqa,\n        rw -eqa,\n        apply le_dSup_of_le,\n        exact \u27e8_, ha, rfl\u27e9,\n        apply le_dSup,\n        exact \u27e8_, hf, rfl\u27e9  \n        end\n       ))\n       (dSup_le (take b, assume \u27e8a, ha, eqa\u27e9, eq.rec_on eqa (sup_fs_monotone (le_dSup ha) ) ))\u27e9\n\n \nprotected \nlemma le_dSup (fs : directed (scott_continuous \u03b1 \u03b2))(f : scott_continuous \u03b1 \u03b2) : f \u2208 fs \u2192 f \u2264 scott_continuous.dSup fs := \n assume hf, take a, le_dSup \u27e8_, hf, rfl\u27e9   \n\nprotected \nlemma dSup_le (fs : directed (scott_continuous \u03b1 \u03b2)) (f : scott_continuous \u03b1 \u03b2) : (\u2200 g \u2208 fs, g \u2264 f) \u2192 scott_continuous.dSup fs \u2264 f := \n  assume h, take a, dSup_le (take b, assume \u27e8g, hg, eqg\u27e9, eq.rec_on eqg.symm (h _ hg _)) \n\n@[simp]\nlemma is_strict (f : scott_continuous \u03b1 \u03b2) : f.1 \u22a5 = \u22a5 := f.property.is_strict\n\nend scott_continuous\n\ninstance scott_continuous_function [directed_complete_partial_order \u03b1][directed_complete_partial_order \u03b2] : \n         has_coe (scott_continuous \u03b1 \u03b2) (\u03b1 \u2192 \u03b2) := \u27e8 \u03bb f, f.1 \u27e9 \n\ninstance scott_continuous_dcpo [directed_complete_partial_order \u03b1][directed_complete_partial_order \u03b2] \n : directed_complete_partial_order (scott_continuous \u03b1 \u03b2) := \n {\n     scott_continuous.scott_continuous_weak_order with\n     dSup := scott_continuous.dSup,\n     le_dSup := scott_continuous.le_dSup,\n     dSup_le := scott_continuous.dSup_le\n }\n\n -- fixedpoints\nsection \nvariables [directed_complete_partial_order \u03b1] [directed_complete_partial_order \u03b2]\n\nlemma monotone_preserve_directed {f : \u03b1 \u2192 \u03b2} : monotone f \u2192 \u2200 s : directed \u03b1, is_directed (set.image f s.1) :=\nbegin \nintros hmono s b\u2081 b\u2082 hb\u2081 hb\u2082,  \ncases hb\u2081 with a\u2081 ha\u2081,\ncases ha\u2081 with ha\u2081 eqb\u2081,\ncases hb\u2082 with a\u2082  ha\u2082,\ncases ha\u2082 with ha\u2082 eqb\u2082,\nrw [-eqb\u2081, -eqb\u2082],\ncases s.property _ _ ha\u2081 ha\u2082 with a ha,\ncases ha with ha h,\ncases h with ha\u2081a ha\u2082a,\nexact \u27e8_, \u27e8_, ha, rfl\u27e9, hmono ha\u2081a, hmono ha\u2082a\u27e9   \nend   \n\ndef directed.map {f : \u03b1 \u2192 \u03b2} : monotone f \u2192 directed \u03b1 \u2192 directed \u03b2 := assume hmono, take s, \u27e8_, monotone_preserve_directed hmono s\u27e9   \n\nlemma monotone_dSup {f : \u03b1 \u2192 \u03b2} (hmono : monotone f) : \u2200 {{s : directed \u03b1}}, dSup (directed.map hmono s) \u2264 f (dSup s)\n:= \nbegin \nintro s,\napply dSup_le,\nintros b hb,\ncases hb with a ha,\ncases ha with ha eqa,\nrw -eqa,\napply hmono,\napply le_dSup,\nassumption\nend  \n\nlemma ascending_chain_dSup {seq : ascending_chain \u03b1} : \n  dSup (directed.of_ascending_chain seq) \u2208 seq \u2194 seq.is_stationary := \n  \u27e8 assume \u27e8n, eqn\u27e9 , \u27e8n, take m, assume hnm : n \u2264 m, le_antisymm (seq.monotone hnm) (eq.rec_on eqn (le_dSup \u27e8_, rfl\u27e9 ))\u27e9 ,\n    assume \u27e8n, hn \u27e9 , \u27e8n, le_antisymm \n                 (dSup_le (take b, assume \u27e8m, hm\u27e9, eq.rec_on hm.symm (or.elim (le_total n m) \n                     (assume h : n \u2264 m, eq.rec_on (hn _ h) (le_refl _)) \n                     (seq.monotone)))) \n                 (le_dSup \u27e8_, rfl\u27e9) \u27e9 \u27e9 \nend\nnamespace monotone\nvariables [directed_complete_partial_order \u03b1] [directed_complete_partial_order \u03b2]\n\ndef ascending_chain {\u03b1} [order_bot \u03b1] {f : \u03b1 \u2192 \u03b1} : monotone f \u2192 ascending_chain \u03b1 := assume hmono, iter_n.to_ascending_chain hmono bot_le\n\ndef lfp {f : \u03b1 \u2192 \u03b1} : monotone f \u2192 \u03b1 :=  assume hmono, dSup (directed.of_ascending_chain (ascending_chain hmono))\n\nlemma lfp_le {f : \u03b1 \u2192 \u03b1} (hmono : monotone f) : hmono.lfp \u2264 f hmono.lfp :=\n begin\n   apply dSup_le,\n   intros b hb,\n   cases hb with n hn,\n   rw hn,\n   cases n with n,\n   apply bot_le,\n   apply hmono,\n   apply le_dSup,\n   exact \u27e8_, rfl\u27e9  \n end\n\nlemma le_lfp {f : \u03b1 \u2192 \u03b1} (hmono : monotone f) : \n    hmono.ascending_chain.is_stationary \u2192 \n    f hmono.lfp \u2264  hmono.lfp :=\n begin\n  intro hst,\n  rw -ascending_chain_dSup at hst,\n  apply le_dSup,\n  cases hst with n hn,\n  assert H : hmono.lfp = iter_n f \u22a5 n, apply hn,\n  rw H,\n  exact \u27e8n+1, rfl\u27e9  \n end\n\nlemma lfp_eq {f : \u03b1 \u2192 \u03b1} (hmono : monotone f) : hmono.ascending_chain.is_stationary \u2192 hmono.lfp = f hmono.lfp \n:= assume hst, le_antisymm (lfp_le hmono) (le_lfp hmono hst)\n\nend monotone\n\ndef fixed_point (f : \u03b1 \u2192 \u03b1) : set \u03b1 := { x | x = f x }\n\nnamespace scott_continuous\nvariables [directed_complete_partial_order \u03b1] \n\ndef lfp (f : scott_continuous \u03b1 \u03b1) : \u03b1 := f.monotone.lfp\n\nvariable {f : scott_continuous \u03b1 \u03b1}\n\nlemma lfp_le : f.lfp \u2264 f.1 f.lfp := \n    begin\n    unfold lfp,\n    unfold monotone.lfp,\n    rw f.2.preserve_dSup,\n    apply dSup_le,\n    intros a ha,\n    cases ha with n hn,\n    rw hn,\n    cases n with n, \n    apply bot_le,\n    apply le_dSup,\n    exact \u27e8_, \u27e8n, rfl\u27e9, rfl\u27e9 \n    end\n\nlemma le_lfp : f.1 f.lfp \u2264 f.lfp := \n   begin \n   unfold lfp, unfold monotone.lfp,\n   rw f.2.preserve_dSup,   \n   apply dSup_le_dSup,\n   intros a ha,\n   cases ha with a\u2081 ha\u2081,\n   rw -ha\u2081.right,\n   cases ha\u2081.left with n hn,\n   rw hn,\n   exact \u27e8n+1, rfl\u27e9    \n   end\n\nlemma lfp_eq : f.lfp = f.1 f.lfp := le_antisymm lfp_le le_lfp \n\nlemma lfp_fixed_point : lfp f \u2208 fixed_point f.1 := lfp_eq \n\nlemma lfp_least : \u2200 x \u2208 fixed_point f.1, lfp f \u2264 x := \n  take x, assume xeq, dSup_le \n     (take a, assume \u27e8n, hn\u27e9, eq.rec_on hn.symm \n        (nat.rec_on n bot_le (\u03bb n iH, eq.rec_on xeq.symm (f.monotone iH)) )) \nend scott_continuous\n\n\n", "meta": {"author": "tizmd", "repo": "lean-abstract-interpretation", "sha": "ad69622adc082e7009f12b17568662a599779260", "save_path": "github-repos/lean/tizmd-lean-abstract-interpretation", "path": "github-repos/lean/tizmd-lean-abstract-interpretation/lean-abstract-interpretation-ad69622adc082e7009f12b17568662a599779260/algebra/lattice/dcpo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7140659693422627}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport data.finset.n_ary\nimport data.set.sups\n\n/-!\n# Set family operations\n\nThis file defines a few binary operations on `finset \u03b1` for use in set family combinatorics.\n\n## Main declarations\n\n* `s \u22bb t`: Finset of elements of the form `a \u2294 b` where `a \u2208 s`, `b \u2208 t`.\n* `s \u22bc t`: Finset of elements of the form `a \u2293 b` where `a \u2208 s`, `b \u2208 t`.\n* `finset.disj_sups s t`: Finset of elements of the form `a \u2294 b` where `a \u2208 s`, `b \u2208 t` and `a`\n  and `b` are disjoint.\n\n## Notation\n\nWe define the following notation in locale `finset_family`:\n* `s \u22bb t`\n* `s \u22bc t`\n* `s \u25cb t` for `finset.disj_sups s t`\n\n## References\n\n[B. Bollob\u00e1s, *Combinatorics*][bollobas1986]\n-/\n\nopen function\nopen_locale set_family\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1]\n\nnamespace finset\nsection sups\nvariables [semilattice_sup \u03b1] (s s\u2081 s\u2082 t t\u2081 t\u2082 u v : finset \u03b1)\n\n/-- `s \u22bb t` is the finset of elements of the form `a \u2294 b` where `a \u2208 s`, `b \u2208 t`. -/\nprotected def has_sups : has_sups (finset \u03b1) := \u27e8image\u2082 (\u2294)\u27e9\n\nlocalized \"attribute [instance] finset.has_sups\" in finset_family\n\nvariables {s t} {a b c : \u03b1}\n\n@[simp] lemma mem_sups : c \u2208 s \u22bb t \u2194 \u2203 (a \u2208 s) (b \u2208 t), a \u2294 b = c := by simp [(\u22bb)]\n\nvariables (s t)\n\n@[simp, norm_cast] lemma coe_sups : (\u2191(s \u22bb t) : set \u03b1) = s \u22bb t := coe_image\u2082 _ _ _\n\nlemma card_sups_le : (s \u22bb t).card \u2264 s.card * t.card := card_image\u2082_le _ _ _\n\nlemma card_sups_iff :\n  (s \u22bb t).card = s.card * t.card \u2194 (s \u00d7\u02e2 t : set (\u03b1 \u00d7 \u03b1)).inj_on (\u03bb x, x.1 \u2294 x.2) :=\ncard_image\u2082_iff\n\nvariables {s s\u2081 s\u2082 t t\u2081 t\u2082 u}\n\nlemma sup_mem_sups : a \u2208 s \u2192 b \u2208 t \u2192 a \u2294 b \u2208 s \u22bb t := mem_image\u2082_of_mem\nlemma sups_subset : s\u2081 \u2286 s\u2082 \u2192 t\u2081 \u2286 t\u2082 \u2192 s\u2081 \u22bb t\u2081 \u2286 s\u2082 \u22bb t\u2082 := image\u2082_subset\nlemma sups_subset_left : t\u2081 \u2286 t\u2082 \u2192 s \u22bb t\u2081 \u2286 s \u22bb t\u2082 := image\u2082_subset_left\nlemma sups_subset_right : s\u2081 \u2286 s\u2082 \u2192 s\u2081 \u22bb t \u2286 s\u2082 \u22bb t := image\u2082_subset_right\n\nlemma image_subset_sups_left : b \u2208 t \u2192 s.image (\u03bb a, a \u2294 b) \u2286 s \u22bb t := image_subset_image\u2082_left\nlemma image_subset_sups_right : a \u2208 s \u2192 t.image ((\u2294) a) \u2286 s \u22bb t := image_subset_image\u2082_right\n\nlemma forall_sups_iff {p : \u03b1 \u2192 Prop} : (\u2200 c \u2208 s \u22bb t, p c) \u2194 \u2200 (a \u2208 s) (b \u2208 t), p (a \u2294 b) :=\nforall_image\u2082_iff\n\n@[simp] lemma sups_subset_iff : s \u22bb t \u2286 u \u2194 \u2200 (a \u2208 s) (b \u2208 t), a \u2294 b \u2208 u := image\u2082_subset_iff\n\n@[simp] lemma sups_nonempty : (s \u22bb t).nonempty \u2194 s.nonempty \u2227 t.nonempty := image\u2082_nonempty_iff\n\nprotected lemma nonempty.sups : s.nonempty \u2192 t.nonempty \u2192 (s \u22bb t).nonempty := nonempty.image\u2082\nlemma nonempty.of_sups_left : (s \u22bb t).nonempty \u2192 s.nonempty := nonempty.of_image\u2082_left\nlemma nonempty.of_sups_right : (s \u22bb t).nonempty \u2192 t.nonempty := nonempty.of_image\u2082_right\n\n@[simp] lemma empty_sups : \u2205 \u22bb t = \u2205 := image\u2082_empty_left\n@[simp] lemma sups_empty : s \u22bb \u2205 = \u2205 := image\u2082_empty_right\n@[simp] lemma sups_eq_empty : s \u22bb t = \u2205 \u2194 s = \u2205 \u2228 t = \u2205 := image\u2082_eq_empty_iff\n\n@[simp] lemma singleton_sups : {a} \u22bb t = t.image (\u03bb b, a \u2294 b) := image\u2082_singleton_left\n@[simp] lemma sups_singleton : s \u22bb {b} = s.image (\u03bb a, a \u2294 b) := image\u2082_singleton_right\n\nlemma singleton_sups_singleton : ({a} \u22bb {b} : finset \u03b1) = {a \u2294 b} := image\u2082_singleton\n\nlemma sups_union_left : (s\u2081 \u222a s\u2082) \u22bb t = s\u2081 \u22bb t \u222a s\u2082 \u22bb t := image\u2082_union_left\nlemma sups_union_right : s \u22bb (t\u2081 \u222a t\u2082) = s \u22bb t\u2081 \u222a s \u22bb t\u2082 := image\u2082_union_right\n\nlemma sups_inter_subset_left : (s\u2081 \u2229 s\u2082) \u22bb t \u2286 s\u2081 \u22bb t \u2229 s\u2082 \u22bb t := image\u2082_inter_subset_left\nlemma sups_inter_subset_right : s \u22bb (t\u2081 \u2229 t\u2082) \u2286 s \u22bb t\u2081 \u2229 s \u22bb t\u2082 := image\u2082_inter_subset_right\n\nlemma subset_sups {s t : set \u03b1} :\n  \u2191u \u2286 s \u22bb t \u2192 \u2203 s' t' : finset \u03b1, \u2191s' \u2286 s \u2227 \u2191t' \u2286 t \u2227 u \u2286 s' \u22bb t' :=\nsubset_image\u2082\n\nvariables (s t u v)\n\nlemma bUnion_image_sup_left : s.bUnion (\u03bb a, t.image $ (\u2294) a) = s \u22bb t := bUnion_image_left\nlemma bUnion_image_sup_right : t.bUnion (\u03bb b, s.image $ \u03bb a, a \u2294 b) = s \u22bb t := bUnion_image_right\n\n@[simp] \n\nlemma sups_assoc : (s \u22bb t) \u22bb u = s \u22bb (t \u22bb u) := image\u2082_assoc $ \u03bb _ _ _, sup_assoc\nlemma sups_comm : s \u22bb t = t \u22bb s := image\u2082_comm $ \u03bb _ _, sup_comm\nlemma sups_left_comm : s \u22bb (t \u22bb u) = t \u22bb (s \u22bb u) := image\u2082_left_comm sup_left_comm\nlemma sups_right_comm : (s \u22bb t) \u22bb u = (s \u22bb u) \u22bb t := image\u2082_right_comm sup_right_comm\nlemma sups_sups_sups_comm : (s \u22bb t) \u22bb (u \u22bb v) = (s \u22bb u) \u22bb (t \u22bb v) :=\nimage\u2082_image\u2082_image\u2082_comm sup_sup_sup_comm\n\nend sups\n\nsection infs\nvariables [semilattice_inf \u03b1] (s s\u2081 s\u2082 t t\u2081 t\u2082 u v : finset \u03b1)\n\n/-- `s \u22bc t` is the finset of elements of the form `a \u2293 b` where `a \u2208 s`, `b \u2208 t`. -/\nprotected def has_infs : has_infs (finset \u03b1) := \u27e8image\u2082 (\u2293)\u27e9\n\nlocalized \"attribute [instance] finset.has_infs\" in finset_family\n\nvariables {s t} {a b c : \u03b1}\n\n@[simp] lemma mem_infs : c \u2208 s \u22bc t \u2194 \u2203 (a \u2208 s) (b \u2208 t), a \u2293 b = c := by simp [(\u22bc)]\n\nvariables (s t)\n\n@[simp, norm_cast] lemma coe_infs : (\u2191(s \u22bc t) : set \u03b1) = s \u22bc t := coe_image\u2082 _ _ _\n\nlemma card_infs_le : (s \u22bc t).card \u2264 s.card * t.card := card_image\u2082_le _ _ _\n\nlemma card_infs_iff :\n  (s \u22bc t).card = s.card * t.card \u2194 (s \u00d7\u02e2 t : set (\u03b1 \u00d7 \u03b1)).inj_on (\u03bb x, x.1 \u2293 x.2) :=\ncard_image\u2082_iff\n\nvariables {s s\u2081 s\u2082 t t\u2081 t\u2082 u}\n\nlemma inf_mem_infs : a \u2208 s \u2192 b \u2208 t \u2192 a \u2293 b \u2208 s \u22bc t := mem_image\u2082_of_mem\nlemma infs_subset : s\u2081 \u2286 s\u2082 \u2192 t\u2081 \u2286 t\u2082 \u2192 s\u2081 \u22bc t\u2081 \u2286 s\u2082 \u22bc t\u2082 := image\u2082_subset\nlemma infs_subset_left : t\u2081 \u2286 t\u2082 \u2192 s \u22bc t\u2081 \u2286 s \u22bc t\u2082 := image\u2082_subset_left\nlemma infs_subset_right : s\u2081 \u2286 s\u2082 \u2192 s\u2081 \u22bc t \u2286 s\u2082 \u22bc t := image\u2082_subset_right\n\nlemma image_subset_infs_left : b \u2208 t \u2192 s.image (\u03bb a, a \u2293 b) \u2286 s \u22bc t := image_subset_image\u2082_left\nlemma image_subset_infs_right : a \u2208 s \u2192 t.image ((\u2293) a) \u2286 s \u22bc t := image_subset_image\u2082_right\n\nlemma forall_infs_iff {p : \u03b1 \u2192 Prop} : (\u2200 c \u2208 s \u22bc t, p c) \u2194 \u2200 (a \u2208 s) (b \u2208 t), p (a \u2293 b) :=\nforall_image\u2082_iff\n\n@[simp] lemma infs_subset_iff : s \u22bc t \u2286 u \u2194 \u2200 (a \u2208 s) (b \u2208 t), a \u2293 b \u2208 u := image\u2082_subset_iff\n\n@[simp] lemma infs_nonempty : (s \u22bc t).nonempty \u2194 s.nonempty \u2227 t.nonempty := image\u2082_nonempty_iff\n\nprotected lemma nonempty.infs : s.nonempty \u2192 t.nonempty \u2192 (s \u22bc t).nonempty := nonempty.image\u2082\nlemma nonempty.of_infs_left : (s \u22bc t).nonempty \u2192 s.nonempty := nonempty.of_image\u2082_left\nlemma nonempty.of_infs_right : (s \u22bc t).nonempty \u2192 t.nonempty := nonempty.of_image\u2082_right\n\n@[simp] lemma empty_infs : \u2205 \u22bc t = \u2205 := image\u2082_empty_left\n@[simp] lemma infs_empty : s \u22bc \u2205 = \u2205 := image\u2082_empty_right\n@[simp] lemma infs_eq_empty : s \u22bc t = \u2205 \u2194 s = \u2205 \u2228 t = \u2205 := image\u2082_eq_empty_iff\n\n@[simp] lemma singleton_infs : {a} \u22bc t = t.image (\u03bb b, a \u2293 b) := image\u2082_singleton_left\n@[simp] lemma infs_singleton : s \u22bc {b} = s.image (\u03bb a, a \u2293 b) := image\u2082_singleton_right\n\nlemma singleton_infs_singleton : ({a} \u22bc {b} : finset \u03b1) = {a \u2293 b} := image\u2082_singleton\n\nlemma infs_union_left : (s\u2081 \u222a s\u2082) \u22bc t = s\u2081 \u22bc t \u222a s\u2082 \u22bc t := image\u2082_union_left\nlemma infs_union_right : s \u22bc (t\u2081 \u222a t\u2082) = s \u22bc t\u2081 \u222a s \u22bc t\u2082 := image\u2082_union_right\n\nlemma infs_inter_subset_left : (s\u2081 \u2229 s\u2082) \u22bc t \u2286 s\u2081 \u22bc t \u2229 s\u2082 \u22bc t := image\u2082_inter_subset_left\nlemma infs_inter_subset_right : s \u22bc (t\u2081 \u2229 t\u2082) \u2286 s \u22bc t\u2081 \u2229 s \u22bc t\u2082 := image\u2082_inter_subset_right\n\nlemma subset_infs {s t : set \u03b1} :\n  \u2191u \u2286 s \u22bc t \u2192 \u2203 s' t' : finset \u03b1, \u2191s' \u2286 s \u2227 \u2191t' \u2286 t \u2227 u \u2286 s' \u22bc t' :=\nsubset_image\u2082\n\nvariables (s t u v)\n\nlemma bUnion_image_inf_left : s.bUnion (\u03bb a, t.image $ (\u2293) a) = s \u22bc t := bUnion_image_left\nlemma bUnion_image_inf_right : t.bUnion (\u03bb b, s.image $ \u03bb a, a \u2293 b) = s \u22bc t := bUnion_image_right\n\n@[simp] lemma image_inf_product (s t : finset \u03b1) : (s \u00d7\u02e2 t).image (uncurry (\u2293)) = s \u22bc t :=\nimage_uncurry_product _ _ _\n\nlemma infs_assoc : (s \u22bc t) \u22bc u = s \u22bc (t \u22bc u) := image\u2082_assoc $ \u03bb _ _ _, inf_assoc\nlemma infs_comm : s \u22bc t = t \u22bc s := image\u2082_comm $ \u03bb _ _, inf_comm\nlemma infs_left_comm : s \u22bc (t \u22bc u) = t \u22bc (s \u22bc u) := image\u2082_left_comm inf_left_comm\nlemma infs_right_comm : (s \u22bc t) \u22bc u = (s \u22bc u) \u22bc t := image\u2082_right_comm inf_right_comm\nlemma infs_infs_infs_comm : (s \u22bc t) \u22bc (u \u22bc v) = (s \u22bc u) \u22bc (t \u22bc v) :=\nimage\u2082_image\u2082_image\u2082_comm inf_inf_inf_comm\n\nend infs\n\nopen_locale finset_family\n\nsection distrib_lattice\nvariables [distrib_lattice \u03b1] (s t u : finset \u03b1)\n\nlemma sups_infs_subset_left : s \u22bb (t \u22bc u) \u2286 (s \u22bb t) \u22bc (s \u22bb u) :=\nimage\u2082_distrib_subset_left $ \u03bb _ _ _, sup_inf_left\n\nlemma sups_infs_subset_right : (t \u22bc u) \u22bb s \u2286 (t \u22bb s) \u22bc (u \u22bb s) :=\nimage\u2082_distrib_subset_right $ \u03bb _ _ _, sup_inf_right\n\nlemma infs_sups_subset_left : s \u22bc (t \u22bb u) \u2286 (s \u22bc t) \u22bb (s \u22bc u) :=\nimage\u2082_distrib_subset_left $ \u03bb _ _ _, inf_sup_left\n\nlemma infs_sups_subset_right : (t \u22bb u) \u22bc s \u2286 (t \u22bc s) \u22bb (u \u22bc s) :=\nimage\u2082_distrib_subset_right $ \u03bb _ _ _, inf_sup_right\n\nend distrib_lattice\n\nsection disj_sups\nvariables [semilattice_sup \u03b1] [order_bot \u03b1] [@decidable_rel \u03b1 disjoint]\n  (s s\u2081 s\u2082 t t\u2081 t\u2082 u : finset \u03b1)\n\n/-- The finset of elements of the form `a \u2294 b` where `a \u2208 s`, `b \u2208 t` and `a` and `b` are disjoint.\n-/\ndef disj_sups : finset \u03b1 :=\n((s \u00d7\u02e2 t).filter $ \u03bb ab : \u03b1 \u00d7 \u03b1, disjoint ab.1 ab.2).image $ \u03bb ab, ab.1 \u2294 ab.2\n\nlocalized \"infix (name := finset.disj_sups) ` \u25cb `:74 := finset.disj_sups\" in finset_family\n\nvariables {s t u} {a b c : \u03b1}\n\n@[simp] lemma mem_disj_sups : c \u2208 s \u25cb t \u2194 \u2203 (a \u2208 s) (b \u2208 t), disjoint a b \u2227 a \u2294 b = c :=\nby simp [disj_sups, and_assoc]\n\nlemma disj_sups_subset_sups : s \u25cb t \u2286 s \u22bb t :=\nbegin\n  simp_rw [subset_iff, mem_sups, mem_disj_sups],\n  exact \u03bb c \u27e8a, b, ha, hb, h, hc\u27e9, \u27e8a, b, ha, hb, hc\u27e9,\nend\n\nvariables (s t)\n\nlemma card_disj_sups_le : (s \u25cb t).card \u2264 s.card * t.card :=\n(card_le_of_subset disj_sups_subset_sups).trans $ card_sups_le _ _\n\nvariables {s s\u2081 s\u2082 t t\u2081 t\u2082 u}\n\nlemma disj_sups_subset (hs : s\u2081 \u2286 s\u2082) (ht : t\u2081 \u2286 t\u2082) : s\u2081 \u25cb t\u2081 \u2286 s\u2082 \u25cb t\u2082 :=\nimage_subset_image $ filter_subset_filter _ $ product_subset_product hs ht\n\nlemma disj_sups_subset_left (ht : t\u2081 \u2286 t\u2082) : s \u25cb t\u2081 \u2286 s \u25cb t\u2082 := disj_sups_subset subset.rfl ht\nlemma disj_sups_subset_right (hs : s\u2081 \u2286 s\u2082) : s\u2081 \u25cb t \u2286 s\u2082 \u25cb t := disj_sups_subset hs subset.rfl\n\nlemma forall_disj_sups_iff {p : \u03b1 \u2192 Prop} :\n  (\u2200 c \u2208 s \u25cb t, p c) \u2194 \u2200 (a \u2208 s) (b \u2208 t), disjoint a b \u2192 p (a \u2294 b) :=\nbegin\n  simp_rw mem_disj_sups,\n  refine \u27e8\u03bb h a ha b hb hab, h _ \u27e8_, ha, _, hb, hab, rfl\u27e9, _\u27e9,\n  rintro h _ \u27e8a, ha, b, hb, hab, rfl\u27e9,\n  exact h _ ha _ hb hab,\nend\n\n@[simp] lemma disj_sups_subset_iff : s \u25cb t \u2286 u \u2194 \u2200 (a \u2208 s) (b \u2208 t), disjoint a b \u2192 a \u2294 b \u2208 u :=\nforall_disj_sups_iff\n\nlemma nonempty.of_disj_sups_left : (s \u25cb t).nonempty \u2192 s.nonempty :=\nby { simp_rw [finset.nonempty, mem_disj_sups], exact \u03bb \u27e8_, a, ha, _\u27e9, \u27e8a, ha\u27e9 }\n\nlemma nonempty.of_disj_sups_right : (s \u25cb t).nonempty \u2192 t.nonempty :=\nby { simp_rw [finset.nonempty, mem_disj_sups], exact \u03bb \u27e8_, _, _, b, hb, _\u27e9, \u27e8b, hb\u27e9 }\n\n@[simp] lemma disj_sups_empty_left : \u2205 \u25cb t = \u2205 := by simp [disj_sups]\n@[simp] lemma disj_sups_empty_right : s \u25cb \u2205 = \u2205 := by simp [disj_sups]\n\nlemma disj_sups_singleton : ({a} \u25cb {b} : finset \u03b1) = if disjoint a b then {a \u2294 b} else \u2205 :=\nby split_ifs; simp [disj_sups, filter_singleton, h]\n\nlemma disj_sups_union_left : (s\u2081 \u222a s\u2082) \u25cb t = s\u2081 \u25cb t \u222a s\u2082 \u25cb t :=\nby simp [disj_sups, filter_union, image_union]\nlemma disj_sups_union_right : s \u25cb (t\u2081 \u222a t\u2082) = s \u25cb t\u2081 \u222a s \u25cb t\u2082 :=\nby simp [disj_sups, filter_union, image_union]\n\nlemma disj_sups_inter_subset_left : (s\u2081 \u2229 s\u2082) \u25cb t \u2286 s\u2081 \u25cb t \u2229 s\u2082 \u25cb t :=\nby simpa only [disj_sups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _\nlemma disj_sups_inter_subset_right : s \u25cb (t\u2081 \u2229 t\u2082) \u2286 s \u25cb t\u2081 \u2229 s \u25cb t\u2082 :=\nby simpa only [disj_sups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _\n\nvariables (s t)\n\nlemma disj_sups_comm : s \u25cb t = t \u25cb s :=\nby { ext, rw [mem_disj_sups, exists\u2082_comm], simp [sup_comm, disjoint.comm] }\n\nend disj_sups\n\nopen_locale finset_family\n\nsection distrib_lattice\nvariables [distrib_lattice \u03b1] [order_bot \u03b1] [@decidable_rel \u03b1 disjoint] (s t u v : finset \u03b1)\n\nlemma disj_sups_assoc : \u2200 s t u : finset \u03b1, (s \u25cb t) \u25cb u = s \u25cb (t \u25cb u) :=\nbegin\n  refine associative_of_commutative_of_le disj_sups_comm _,\n  simp only [le_eq_subset, disj_sups_subset_iff, mem_disj_sups],\n  rintro s t u _ \u27e8a, ha, b, hb, hab, rfl\u27e9 c hc habc,\n  rw disjoint_sup_left at habc,\n  exact \u27e8a, ha, _, \u27e8b, hb, c, hc, habc.2, rfl\u27e9, hab.sup_right habc.1, sup_assoc.symm\u27e9,\nend\n\nlemma disj_sups_left_comm : s \u25cb (t \u25cb u) = t \u25cb (s \u25cb u) :=\nby simp_rw [\u2190disj_sups_assoc, disj_sups_comm s]\n\nlemma disj_sups_right_comm : (s \u25cb t) \u25cb u = (s \u25cb u) \u25cb t :=\nby simp_rw [disj_sups_assoc, disj_sups_comm]\n\nlemma disj_sups_disj_sups_disj_sups_comm : (s \u25cb t) \u25cb (u \u25cb v) = (s \u25cb u) \u25cb (t \u25cb v) :=\nby simp_rw [\u2190disj_sups_assoc, disj_sups_right_comm]\n\nend distrib_lattice\nend finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/finset/sups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7139700185607312}}
{"text": "/-\nCollection of nat.sqrt lemmas\nAuthor: Adri\u00e1n Do\u00f1a Mateo\n\nThese were contributed to mathlib in\n[#5155](https://github.com/leanprover-community/mathlib/pull/5155/).\n\nAn apostrophe was added at the end of the names to avoid clashes.\n-/\n\nimport data.nat.sqrt\n\n-- These lemmas were added to src/data/nat/sqrt.lean.\nnamespace nat\n\ntheorem sqrt_mul_sqrt_lt_succ' (n : \u2115) : sqrt n * sqrt n < n + 1 :=\nlt_succ_iff.mpr (sqrt_le _)\n\ntheorem succ_le_succ_sqrt' (n : \u2115) : n + 1 \u2264 (sqrt n + 1) * (sqrt n + 1) :=\nle_of_pred_lt (lt_succ_sqrt _)\n\n/-- There are no perfect squares strictly between m\u00b2 and (m+1)\u00b2 -/\ntheorem not_exists_sq' {n m : \u2115} (hl : m * m < n) (hr : n < (m + 1) * (m + 1)) :\n  \u00ac \u2203 t, t * t = n :=\nbegin\n  rintro \u27e8t, rfl\u27e9,\n  have h1 : m < t, from nat.mul_self_lt_mul_self_iff.mpr hl,\n  have h2 : t < m + 1, from nat.mul_self_lt_mul_self_iff.mpr hr,\n  exact (not_lt_of_ge $ le_of_lt_succ h2) h1\nend\n\nend nat", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/to_mathlib/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.7139700145632076}}
{"text": "import Mathlib.Data.Nat.Basic\nimport Mathlib.Data.Fin.Basic\nimport Mathlib.Data.Finset.Powerset\nimport Mathlib.Data.Fintype.CardEmbedding\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Tactic.Tauto\n\nopen Finset Nat Classical\n\n/- \n\nBasic Ramsey theory for graphs\n\n**Main results** \n\n1). Upper bound (Ramsey's Theorem) R(s+1,t+t) \u2264 (s+t).choose s (DONE)\n\nRamsey (s t : \u2115)  : Ramsey_of ((s + t).choose s) s.succ t.succ :=\n\n2). Lower bound (Erdos prob): if (n.choose s) < 2^((s.choose 2)-1) then n < R(s,s)\n(but written without division)\n\n Ramsey_lower_bound (s n : \u2115) (hn: 2 \u2264 s ) :\n(n.choose s) * 2 * (2^((n.choose 2) - (s.choose 2) )) < 2^(n.choose 2) \u2192 \u00ac Ramsey_of n s s \n\n3). Existence of k-colour 2-graph Ramsey numbers and Schur's theorem\nkcol_Ramsey (s: Fin k.succ \u2192 \u2115) : \u2203 n, kRamsey_of n s\n\n4).  Schur's theorem: for any k, there exists n such that in any k-coloring of \u2115 there is\na monochromatic solution to x + y = z with x,y,z < n\nSchur' (k:\u2115) : \u2203 (n:\u2115), Schur n k\n\n\n-/\nopen Finset Nat \n\nsection twocolour\n\n/-- Only two colours for now. We can think of 0 as red and 1 as blue -/\nlemma  fin_two_not (a : Fin 2) : \u00ac a = 0 \u2194 a = 1 :=by\n  apply Iff.intro\n  \u00b7 intro hn0\n    have h1: (a:\u2115).succ \u2264 2:=a.2\n    rw [succ_le_succ_iff] at h1\n    rw [\u2190 Fin.val_eq_val] at *\n    apply le_antisymm h1\n    rwa [one_le_iff_ne_zero]\n  \u00b7 intro h1 h0\n    rw [h0] at h1 \n    exact Fin.zero_ne_one h1\n\n\n\n/- flip a colour -/\ndef not_c (c : Fin 2) : Fin 2:= if (c = 0) then 1 else 0\n\n/-- not not  -/\nlemma not_not_c (c : Fin 2) : not_c (not_c c) = c:=\nby\n  rw [not_c,not_c]\n  split_ifs with h\n  contradiction\n  exact h.symm\n  rw [fin_two_not] at h\n  exact h.symm\n  contradiction\n\n/-- the flipped colouring given by swapping all colours -/\ndef col_flip (col : Finset \u2115 \u2192 Fin 2) (A: Finset \u2115) : Fin 2 :=  (not_c (col A))\n\n/-- A col is mono on a set A iff every pair in the set receives the same colour  -/\ndef mono_c_on (A : Finset \u2115) (col : Finset \u2115 \u2192 Fin 2) (c :Fin 2) :  Prop:= \n\u2200 (e : Finset \u2115), e \u2208 Finset.powersetLen 2 A \u2192 col e = c\n\n/-- Trivially if A is empty or a singleton any colouring is mono on it-/\nlemma mono_on_subsingleton {A : Finset \u2115} (h: A.card < 2) (col : Finset \u2115 \u2192 Fin 2) (c : Fin 2) : mono_c_on A col c:=\nby\n  intro e he\n  apply False.elim \n  rw [powersetLen_empty 2 h] at he  \n  contradiction\n\n\n/-- col is mono on A iff its flipped version is mono -/\nlemma mono_flip  {A : Finset \u2115} {col : Finset \u2115 \u2192 Fin 2} {c : Fin 2} : mono_c_on A col c \u2194\nmono_c_on A (col_flip col) (not_c c):=\nby\n  simp_rw [col_flip]\n  dsimp\n  apply Iff.intro\n  intros hm e he\n  dsimp\n  rw [hm e he] \n  intro hm e he\n  have t1:=hm e he\n  dsimp at t1\n  apply_fun not_c at t1\n  simp_rw [not_not_c] at t1\n  assumption\n\n\n\n/-- A colouring col is a Ramsey_col for N s t if every n-set contains a red s-set or a blue t-set under col -/\ndef Ramsey_col (col : Finset \u2115 \u2192 Fin 2) (N s t : \u2115) : Prop := \n\u2200 {V : Finset \u2115}, N \u2264 V.card \u2192 (\u2203 (A : Finset \u2115), A \u2286 V \u2227 ((mono_c_on A col 0 \u2227 s \u2264 A.card) \u2228 (mono_c_on A col 1 \u2227 t \u2264 A.card)))\n\n\n/-- N is Ramsey for s,t if every colouring is a Ramsey_col for n s t -/\ndef Ramsey_of (N s t : \u2115): Prop:= \u2200 (col : Finset \u2115 \u2192 Fin 2), Ramsey_col col N s t\n\n/-- if N is Ramsey for s,t and N \u2264 M then m is also Ramsey -/\nlemma mono_Ramsey_of {N M s t: \u2115} (h : Ramsey_of N s t) (hm: N \u2264 M) : Ramsey_of M s t :=\nby\n  intro col V h2\n  exact  h col (hm.trans h2)\n\n\n/-- given a Finset V and n \u2209 V the nbhd_col c is the set of w \u2208 V such that col {w, n} = c -/\ndef nbhd_col {n : \u2115}  (col : Finset \u2115 \u2192 Fin 2) (c : Fin 2) {V: Finset \u2115}(hV: n \u2209 V) : Finset \u2115:= V.filter ( \u03bb w => col (insert w {n}) = c)  \n\n/-- rw lemma for nbhd_col -/\nlemma col_nhbd_col {n w: \u2115} {col : Finset \u2115 \u2192 Fin 2} {c: Fin 2}{V : Finset \u2115}(hV: n \u2209 V)  (hw: w \u2208 nbhd_col col c hV) : col (insert w {n}) = c:=\nby\n  exact (mem_filter.1 hw).2\n\n\n/-- Any vertex in nbhd_col is in the original set V -/\nlemma mem_col_nbhd_range {v : \u2115} {n : \u2115} {col : Finset \u2115 \u2192 Fin 2} {c: Fin 2} {V : Finset \u2115}{hV: n \u2209 V} (hv :v \u2208 nbhd_col col c hV): v \u2208 V:=\nby\n  exact (mem_filter.1 hv).1\n\n\n/-- Any subset of nbhd_col is a subset of V -/\nlemma col_nbhd_sub_range {n : \u2115} {col : Finset \u2115 \u2192 Fin 2} {c: Fin 2} \n{A V : Finset \u2115}{hV: n \u2209 V} (hA: A \u2286 nbhd_col col c hV) : A \u2286 V:=\nby\n  intros v hv \n  exact mem_col_nbhd_range (hA hv)\n\n\n/-- the sets {b,a} and {a,b} are equal (note the proof is not refl)-/\nlemma insert_eq' (a b : \u2115)  : (insert a {b}: Finset \u2115)= insert b {a} :=by\next x\napply Iff.intro\n\u00b7 intro h\n  rw [mem_insert,  mem_singleton] at * \n  rwa [or_comm]\n\u00b7 intro h\n  rw [mem_insert,  mem_singleton] at * \n  rwa [or_comm]\n\n/-- Given an edge from n to the c-coloured nbhd of n it has colour c-/\nlemma mono_nbhr {n : \u2115}{A V e: Finset \u2115} {col: Finset \u2115 \u2192 Fin 2} {c : Fin 2} {hV: n \u2209 V} (hnb: A \u2286 nbhd_col col c hV) \n(he: e \u2208 image (insert n) (powersetLen 1 A)): col e = c:=by\n  simp_rw [mem_image, mem_powersetLen,card_eq_one] at he\n  obtain \u27e8B,\u27e8h1,\u27e8b,rfl\u27e9\u27e9,h3\u27e9:=he\n  rw [\u2190h3,insert_eq']\n  exact col_nhbd_col hV ((h1.trans hnb) (mem_singleton_self b))\n\n\n/-- If A is mono c and contained in the set of c-col nbhrs of n then A \u222a {n} is also mono c-/\nlemma mono_c_ext  {n : \u2115}{A V : Finset \u2115} {col: Finset \u2115 \u2192 Fin 2} {c : Fin 2} {hV: n \u2209 V}\n (hm : mono_c_on A col c) (hnb: A \u2286 nbhd_col col c hV) :\nmono_c_on (insert n A) col c:=by\n  intros e he\n  rw [powersetLen_succ_insert,mem_union] at he\n  cases' he with he he\n  exact hm e he\n  exact (mono_nbhr hnb he)\n  exact not_mem_mono (col_nbhd_sub_range hnb) hV\n\n/-- red and blue nbhds of n are disjoint-/\nlemma  nbhd_col_disj {n : \u2115} {V : Finset \u2115} (col : Finset \u2115 \u2192 Fin 2)   (hV: n \u2209 V): Disjoint (nbhd_col col 0 hV ) (nbhd_col col 1 hV):=by\n  unfold nbhd_col \n  intros w hw0 hw1 x hx\n  have hx0:=hw0 hx\n  have hx1:=hw1 hx\n  dsimp at *\n  simp_rw [mem_inter,mem_filter] at *\n  apply False.elim\n  rcases hx0 with \u27e8_,hx0\u27e9\n  rcases hx1 with \u27e8_,hx1\u27e9\n  rw [hx0] at hx1\n  apply Fin.zero_ne_one hx1\n\n\n/- union of red and blue nbhds of n \u2209 V is V-/\nlemma  nbhd_col_union_eq {n : \u2115} {V : Finset \u2115} (col : Finset \u2115 \u2192 Fin 2) (hV: n \u2209 V) : (nbhd_col col 0 hV) \u222a (nbhd_col col 1 hV) = V :=by\n  unfold nbhd_col\n  convert filter_union_filter_neg_eq (\u03bb w => col (insert w {n})  = 0) V\n  simp_rw [fin_two_not]\n\n\n/-- sum of red and blue nbhds is |V| -/\nlemma card_col_nbhd {n : \u2115} {V : Finset \u2115} (col : Finset \u2115 \u2192 Fin 2)   (hV: n \u2209 V) :\nV.card = (nbhd_col col 0 hV).card + (nbhd_col col 1 hV).card :=by\n  have :=card_union_eq (nbhd_col_disj col hV)\n  rwa [nbhd_col_union_eq] at this\n\n\n/-- The inequality we require for the inductive step in Ramsey's theorem -/\nlemma nbhd_cards_add_imp {a b c d: \u2115} :  a + b - 1 \u2264 c + d  \u2192 a \u2264 c \u2228 b \u2264 d:=by\n  intros h\n  contrapose h\n  push_neg at h\n  change c.succ \u2264 a \u2227 d.succ \u2264 b at h\n  have :=add_lt_add_of_le_of_lt h.1 h.2 \n  rw [succ_add] at this\n  exact (not_le_of_gt (le_pred_of_lt  this))\n\n\n/-- Key step  R (s+1,t+1) \u2264 R(s,t+1) + R(s+1,t) -/\nlemma Ramsey_step {a b s t : \u2115} (hab : 1 \u2264 a + b): Ramsey_of a s t.succ \u2192 Ramsey_of b s.succ t \n\u2192 Ramsey_of (a+b) s.succ t.succ:=by\n  intro ra rb col W hc\n  --- Need to show W contains a set of size s+1  that is red or t+1 that is blue\n  -- Since 0 < a+b , so W is non-empty and we can find a element n \u2208 W. \n  -- We work in the nbhd of n, which is V := W.erase n\n  obtain \u27e8n,hn\u27e9:=card_pos.1 (hab.trans hc)\n  set V:= W.erase n with hVr\n  -- n \u2209 V\n  have hV:=not_mem_erase n W \n  -- |V| = |W|-1\n  have hVc:=card_erase_of_mem hn\n  rw [\u2190 hVr] at hVc\n  have :=pred_le_pred hc \n  rw [\u2190 pred_eq_sub_one] at hVc; rw [\u2190 hVc] at this\n  rw [ card_col_nbhd col hV,pred_eq_sub_one] at  this\n  -- Have a + b - 1 \u2264 |V0| + |V1| (so we can apply previous lemma to say..)\n  cases' nbhd_cards_add_imp this with h h\n --- Case 1) a \u2264 |V0| so we use Ramsey_of a s t+1 to get set C \u2286 A such that either \n  rcases ra col h with \u27e8C,hC1,\u27e8hR2,hR3\u27e9| \u27e8hB2,hB3\u27e9\u27e9 \n  use (insert n C)\n  refine' \u27e8insert_subset.2 \u27e8hn,(col_nbhd_sub_range hC1).trans (erase_subset n W)\u27e9,_\u27e9\n  left\n  refine' \u27e8mono_c_ext hR2 hC1,_\u27e9\n  convert succ_le_succ hR3\n  apply card_insert_of_not_mem\n  intro hnR; exact  hV (mem_col_nbhd_range (hC1 hnR))\n  exact  \u27e8C,(col_nbhd_sub_range hC1).trans  (erase_subset n W),Or.inr \u27e8hB2,hB3\u27e9\u27e9\n  rcases rb col h with \u27e8C,hC1,\u27e8hR2,hR3\u27e9| \u27e8hB2,hB3\u27e9\u27e9\n  exact \u27e8C,(col_nbhd_sub_range hC1).trans  (erase_subset n W), Or.inl \u27e8hR2,hR3\u27e9\u27e9\n  use (insert n C)\n  refine' \u27e8insert_subset.2 \u27e8hn,(col_nbhd_sub_range hC1).trans (erase_subset n W)\u27e9,_\u27e9\n  right\n  refine' \u27e8mono_c_ext hB2 hC1,_\u27e9\n  convert succ_le_succ hB3\n  apply card_insert_of_not_mem\n  intro hnR;exact hV (mem_col_nbhd_range (hC1 hnR))\n  \n\n/-- Symmetry in (s,t) -/\nlemma Ramsey_symm (s t n : \u2115) : Ramsey_of n s t \u2192 Ramsey_of n t s:=by\n  intros h col V hV\n  rcases (h (col_flip col) hV) with \u27e8A,hA1,\u27e8hA2,hA3\u27e9 | \u27e8hA2,hA3\u27e9\u27e9\n  exact \u27e8A,hA1, Or.inr \u27e8mono_flip.2 hA2,hA3\u27e9\u27e9\n  exact \u27e8A,hA1,Or.inl \u27e8mono_flip.2 hA2,hA3\u27e9\u27e9 \n\n\n/-- R(0,t) \u2264 0 and R(1,t) \u2264 1 -/\nlemma Ramsey_lt_two {s t : \u2115} (h : s < 2): Ramsey_of s s t:=by\n  intro col V hV\n  obtain \u27e8B,hB1,rfl\u27e9:=exists_smaller_set V s hV\n  exact \u27e8B,hB1,Or.inl \u27e8mono_on_subsingleton h col 0,le_refl _\u27e9\u27e9\n\n\n/-- R(0,t) \u2264 0 -/\nlemma Ramsey_zero (t : \u2115): Ramsey_of 0 0 t:=\nby\n  exact Ramsey_lt_two zero_lt_two\n\n\n/-- R(1,t) \u2264 1 -/\nlemma Ramsey_one (t : \u2115): Ramsey_of 1 1 t:=\nby\n  exact Ramsey_lt_two one_lt_two\n\n\n/-- R(s,2) \u2264 s -/\nlemma Ramsey_theorem_two (s : \u2115) : Ramsey_of s s 2:=\nby\n  intro col V hV\n  by_cases h : \u2203(e: Finset \u2115), e \u2208 powersetLen 2 V \u2227 col e = 1\n  obtain \u27e8e,he\u27e9:=h\n  refine' \u27e8e,(mem_powersetLen.1 he.1).1,Or.inr \u27e8_, (mem_powersetLen.1 he.1).2.symm.le\u27e9\u27e9\n  intros x\n  have :=powersetLen_self e\n  intros hx \n  rw [(mem_powersetLen.1 he.1).2] at this\n  rw [this,mem_singleton] at hx\n  convert he.2\n  push_neg at h\n  refine' \u27e8V, le_refl V, _\u27e9\n  left\n  refine' \u27e8_ ,hV\u27e9\n  intros e he\n  have := h e he\n  dsimp at this\n  rwa [\u2190 fin_two_not,not_not] at this\n\n\n\n/-- Ramsey's theorem: R(s+1,t+1) \u2264 (s+t).choose s -/\ntheorem Ramsey (s t : \u2115)  : Ramsey_of ((s + t).choose s) s.succ t.succ :=\nby\n  induction' s with s hs generalizing t\n  rw [choose_zero_right] \n  exact Ramsey_one t.succ\n  induction' t  with t ht generalizing s\n  simp_rw [add_zero, choose_self]\n  apply Ramsey_symm\n  exact Ramsey_one _\n  rw [succ_add,add_succ,choose_succ_succ,\u2190 add_succ]\n  refine' Ramsey_step _ (hs t.succ) _ \n  change 0 < _ \n  apply add_pos\n  refine' choose_pos _\n  exact le_add_right (le_refl s)\n  refine' choose_pos _\n  rw [add_succ] \n  apply succ_le_succ (le_add_right (le_refl s))\n  rw [add_succ,\u2190 succ_add]\n  exact ht s hs\n\n\n/-- R(3,3) \u2264 6-/\nlemma R33 : Ramsey_of 6 3 3:=\nby\n  exact Ramsey 2 2\n\n\n/-- R(3,4) \u2264 10 -/\nlemma R34 : Ramsey_of 10 3 4:=\nby\n  exact Ramsey 2 3\n\n\n/-- R(4,4) \u2264 20 -/\nlemma R44 : Ramsey_of 20 4 4:=\nby\n  exact Ramsey 3 3\n\n\n/-- R(5,5) \u2264 70 -/\nlemma R55 : Ramsey_of 70 5 5:=\nby\n  exact Ramsey 4 4\n\n\n/-- R(6,6) \u2264 252 -/\nlemma R66 : Ramsey_of 252 6 6:=\nby\n  exact Ramsey 5 5\n\n\n\n\n-- section lower_bounds\n\n\n-- /-- If n is Ramsey for s then  for every coloring of range n by red/blue there is a subset\n--  A of size at least s and a color c such that all pairs coloured of A colored by c.  -/\n-- lemma Ramsey_of_range {n s: \u2115} (hr: Ramsey_of n s s) : \u2200 (col: Finset \u2115 \u2192 Fin 2),  \n-- \u2203 (A: Finset \u2115), \u2203 (c : Fin 2), A \u2286 range n \u2227 s \u2264 A.card \u2227 (\u2200 {e}, e \u2208 powersetLen 2 A \u2192 col e = c ) :=\n-- by \n--   intro col,\n--   obtain \u27e8A,hA1,\u27e8hA2,hA3\u27e9|\u27e8hA2,hA3\u27e9\u27e9:= hr col (card_range n).symm.le,\n--   exact \u27e8A,0,hA1,hA3, hA2\u27e9,\n--   exact \u27e8A,1,hA1,hA3,hA2\u27e9,\n-- \n\n\n-- /-- n is not Ramsey for s if there is a 2-coloring such that for any color c \u2208 {0,1}  and any s-subset S \u2286 range n \n-- there is a pair e \u2286 S that is not coloured c -/\n-- theorem Ramsey_lb (s n: \u2115) : \n-- (\u2203 (col : Finset \u2115 \u2192 Fin 2),\u2200 (c: Fin 2), \u2200 (S \u2208 powersetLen s (range n)), \u2203 e, e \u2208powersetLen 2 S \u2227 col e \u2260 c)  \u2192 \u00ac Ramsey_of n s s :=\n-- by\n--   intros h hr,\n--   obtain \u27e8col,hc\u27e9:=h,\n--   obtain \u27e8A,c,hA1,hA2,hA3\u27e9:=(Ramsey_of_range hr) col,\n--   obtain \u27e8B,hB\u27e9:= exists_smaller_set A s hA2,\n--   specialize hc c B, rw mem_powersetLen at hc,\n--   obtain \u27e8e,he1,he2\u27e9:=hc \u27e8hB.1.trans hA1,hB.2\u27e9,\n--   apply he2,\n--   apply hA3,\n--   exact powersetLen_mono hB.1 he1,\n-- \n\n-- lemma Finset_fin2 : (univ: Finset (Fin 2)) = ({0}:Finset (Fin 2)) \u222a ({1}:Finset (Fin 2))  \u2227 disjoint ({0}:Finset (Fin 2))  ({1}:Finset (Fin 2)):=\n-- by\n--   split,    \n--   ext, simp_rw [mem_union,mem_singleton,mem_univ],\n--   split,\n--   intro h, by_cases a = 0, left , exact h, right, exact (fin_two_not _).1 h,\n--   intro, triv,\n--   intros x hx, \n--   simp only [inf_eq_inter, inter_singleton_of_not_mem, mem_singleton, Fin.one_eq_zero_iff, nat.one_ne_zero, not_false_iff,not_mem_empty] at hx,\n--   exact hx,\n-- \n\n-- lemma map_fin_eq {n : \u2115} (A: Finset (Fin n)) :Finset.Fin n (A.map Fin.coe_embedding) = A :=\n-- by\n--   ext, \n--   simp_rw [mem_fin, mem_map,Fin.coe_embedding_apply,  exists_prop,\u2190 Fin.ext_iff,exists_eq_right],\n-- \n\n-- lemma map_fin_range {n : \u2115} (S: Finset (Fin n)) : S.map Fin.coe_embedding \u2286range n:=\n-- by\n--   intros x, \n--   rw [mem_map,mem_range],\n--   rintro \u27e8a,h1,h2\u27e9, rw Fin.coe_embedding_apply at h2,\n--   subst_vars,\n--   exact a.2,\n-- \n\n\n-- /-- Equiv to show existence of coloring of Fin n with no mono K_s to showing coloring of \u2115 -/\n-- lemma fin_lb' (s n : \u2115) : (\u2203 (col : Finset \u2115 \u2192 Fin 2), \u2200(c: Fin 2), \u2200 (S \u2208 powersetLen s (range n)), \u2203 e, e \u2208powersetLen 2 S \u2227 col e \u2260 c)  \u2194\n-- (\u2203 (colf : Finset (Fin n) \u2192 Fin 2),\u2200 (c: Fin 2), \u2200 (S:Finset (Fin n)), S.card = s \u2192  \u2203 e, e \u2208 powersetLen 2 S \u2227 colf e \u2260 c) :=\n-- by\n--   split,\n--   intro h, cases h with col hc,\n--   set colf: Finset (Fin n) \u2192 Fin 2 :=  (\u03bb s, col (s.map Fin.coe_embedding)),\n--   use colf,rintros c S hS,\n--   specialize hc c (S.map Fin.coe_embedding),\n--   rw mem_powersetLen at hc,\n--   rw card_map at hc, \n--   obtain \u27e8e,he,hec\u27e9:=hc \u27e8map_fin_range S,hS\u27e9,\n--   simp_rw mem_powersetLen at he \u22a2, \n--   rw subset_map_iff at he,\n--   obtain \u27e8hu,hf\u27e9:=he,\n--   obtain \u27e8u,H1,H2\u27e9:=hu,\n--   refine \u27e8u,\u27e8H1,_\u27e9,_\u27e9,\n--   rwa [H2,card_map] at hf,\n--   rw H2 at hec, exact hec, \n--   --\n--   intro h, cases h with colf hc,\n--   set col: Finset \u2115 \u2192 Fin 2:=(\u03bb s, if (s \u2286 range n) then (colf (s.Fin n)) else 0) with hcol,\n--   use col, rintros c S hS,  rw mem_powersetLen at hS,\n--   specialize hc c (S.Fin n),\n--   cases hS with hr hc2,\n--   have :=@fin_map n S, \n--   rw filter_true_of_mem at this,\n--   rw [\u2190 this, card_map] at hc2,\n--   obtain \u27e8e,he,hec\u27e9:= hc hc2,\n--   use (e.map Fin.coe_embedding),\n--   rw mem_powersetLen at *, \n--   clear hc, rw card_map,refine \u27e8\u27e8_,he.2\u27e9,_\u27e9,\n--   cases he with he1 he2,\n--   rw \u2190 this, rw subset_map_iff, exact \u27e8e,he1,rfl\u27e9,\n--   convert hec, rw hcol,dsimp,split_ifs,\n--   congr', exact map_fin_eq e,\n--   exfalso, apply h, exact map_fin_range e,\n--   intros x hx, exact mem_range.1 (hr hx),\n-- \n\n-- open_locale classical\n-- open fintype\n-- variables {\u03b1 \u03b2 :Type*} [fintype \u03b1] [fintype \u03b2]\n\n-- noncomputable\n-- def equiv_sub_fun {\u03b1 \u03b2 :Type*} [fintype \u03b1] [fintype \u03b2] (p : \u03b1 \u2192 Prop) (b : \u03b2): \n-- {f : \u03b1 \u2192 \u03b2 // \u2200x, \u00ac p x \u2192 f x = b} \u2243 \u03a0 x:\u03b1, p x \u2192 \u03b2:=\n-- { to_fun := \u03bb f x hx, f.val x,\n--   inv_fun := by\n--     intros h, \n--     set f: \u03b1 \u2192 \u03b2 :=\u03bb x, if hx: p x then (h x hx) else b with hf,\n--     refine \u27e8f,_\u27e9,\n--     intros x hx , rw hf,\n--     dsimp, simp only [dite_eq_right_iff],\n--     intros h1, contradiction,\n--   ,\n--   left_inv := by\n--     intros f,\n--     simp only [subtype.val_eq_coe, dite_eq_ite],\n--     ext,\n--     simp only [subtype.coe_mk, ite_eq_left_iff],\n--     intro hx, \n--     have :=f.property x hx, simp_rw \u2190 this,\n--     refl,\n--   ,\n--   right_inv := by\n--   intros h, simp only [dite_not] at *,\n--   ext, split_ifs, refl,\n--   ,  }\n\n\n\n\n-- def equiv_prop_true_fun (P: Prop) (h : P) [fintype \u03b2] : (P \u2192 \u03b2) \u2243 \u03b2:=\n-- { to_fun :=\u03bb f, f h,\n--   inv_fun := \u03bb b,\u03bb h1, b,\n--   left_inv := by\n--     intros h2,dsimp, simp only [eq_self_iff_true],\n--   ,\n--   right_inv := by\n--     intro b, dsimp,refl,\n--   , }\n\n-- def equiv_prop_false_fun (P: Prop) (h : \u00acP) [fintype \u03b2] : (P \u2192 \u03b2) \u2243 unit:=\n-- { to_fun :=\u03bb f, punit.star,\n--   inv_fun := by\n--   intros u h1,exfalso,apply h h1,\n--   ,\n--   left_inv := by\n--     intro f,dsimp, \n--     ext,contradiction, \n--   ,\n--   right_inv := by\n--   intro u,dsimp, simp only [eq_iff_true_of_subsingleton],\n--   , }\n\n\n\n-- lemma function_res_card  {\u03b1 \u03b2 :Type*} [fintype \u03b1] [fintype \u03b2] (p: \u03b1 \u2192Prop) (b : \u03b2):    \n-- fintype.card  (\u03a0 x:\u03b1,p x \u2192 \u03b2) = card \u03b2 ^(Finset.card (univ.filter (\u03bbx, p x))):=\n-- by\n--   simp only [fintype.card_pi],\n--   have : \u2200 a:\u03b1, (fintype.card (p a \u2192 \u03b2) = if (p a) then (card \u03b2) else 1),{\n--     intros a,\n--     by_cases p a, simp only [*, if_true] at *,\n--     rw card_eq, use equiv_prop_true_fun _ h,\n--     simp only [*, if_false] at *,\n--     rw \u2190 card_unit,\n--     rw card_eq,  use equiv_prop_false_fun  _ h,},\n--   simp_rw [this, prod_ite,  prod_const, one_pow, mul_one], \n-- \n\n\n\n-- lemma card_fun_res {\u03b1 \u03b2 :Type*} [fintype \u03b1] [fintype \u03b2] (p: \u03b1 \u2192Prop ) (b : \u03b2):\n-- fintype.card ({f:\u03b1 \u2192 \u03b2 // \u2200x, \u00ac p x \u2192 f x = b}) = card \u03b2 ^(Finset.card (univ.filter (\u03bbx,  p x))):=\n-- by\n--   rw \u2190 function_res_card p b,\n--   apply card_eq.2,  use equiv_sub_fun p b,\n-- \n\n-- --subtype of 2-edge colorings of K_n\n-- def twocol (n : \u2115) :Type*:= {A:Finset (Fin n) // A.card = 2} \u2192 Fin 2 \n\n-- def flipcol {n : \u2115}: twocol n \u2192 twocol n :=\n-- \u03bb col e, not_c (col e)\n\n\n\n-- def not_sub {n : \u2115} (S: Finset (Fin n)): {A:Finset (Fin n) // A.card = 2} \u2192 Prop:=\u03bb e, \u00ac \u2191e \u2286 S  \n\n-- def twocol_mono_c {n : \u2115} (c : Fin 2) (S: Finset (Fin n))  : twocol n \u2192 Prop :=\n-- \u03bb col, \u2200 e: {A:Finset (Fin n) // A.card = 2}, e.val \u2286 S \u2192  col e = c\n\n\n-- def twocol_mono {n : \u2115} (S: Finset (Fin n))  : twocol n \u2192 Prop :=\n-- \u03bb col,  (\u2200 e: {A:Finset (Fin n) // A.card = 2}, e.val \u2286 S \u2192  col e = 0) \u2228 (\u2200 e: {A:Finset (Fin n) // A.card = 2}, e.val \u2286 S \u2192  col e = 1) \n\n\n\n-- lemma flip_mono {n : \u2115} (c : Fin 2) (S: Finset (Fin n)) (col: twocol n) : twocol_mono_c c S col \u2194 twocol_mono_c (not_c c) S (flipcol col):=\n-- by\n--   unfold twocol_mono_c flipcol, \n--   split,\n--   intros h e he, rw h e he,\n--   intros h e he, rw \u2190 not_not_c c,\n--   rw \u2190  h e he, rw not_not_c,\n-- \n\n\n-- instance twocol_fintype (n : \u2115) : fintype (twocol n):=\n-- by \n--   unfold twocol,\n--   apply_instance,\n-- \n\n\n-- /-- The number of k-edge colourings of K_n^r is...-/\n-- lemma card_cols (n k r: \u2115) : fintype.card ({A:Finset (Fin n) // A.card = r} \u2192 Fin k )= k^(n.choose r):=\n-- by\n--   rw [fintype.card_fun, fintype.card_fin, fintype.card_Finset_len,fintype.card_fin],\n-- \n\n-- lemma card_twocols (n : \u2115): fintype.card (twocol n)= 2^(n.choose 2):=card_cols n 2 2\n\n-- lemma card_filter_powersetLen {n k: \u2115} (S: Finset (Fin n)): \n-- (filter (\u03bb (x : {A: Finset (Fin n) // A.card = k}), \u2191x \u2286 S) univ).card = S.card.choose k :=\n-- by\n--   dsimp, rw [\u2190 card_powersetLen k S, Finset.card_congr],\n--   intros a h1 , rw mem_filter at h1, rw mem_powersetLen,\n--   split, exact h1.2, exact a.property,\n--   intros a b ha hb heq, \n--   exact subtype.eq heq,\n--   intros b hb, rw mem_powersetLen at hb,\n--   refine \u27e8\u27e8b,hb.2\u27e9,_\u27e9,\n--   rw [mem_filter,exists_prop], \n--   exact \u27e8\u27e8mem_univ _, hb.1 \u27e9,rfl\u27e9,\n-- \n\n-- lemma card_filter_powersetLen_compl {n : \u2115} (k : \u2115) (S: Finset (Fin n)): \n-- (filter (\u03bb (x : {A: Finset (Fin n) // A.card = k}), \u00ac\u2191x \u2286 S) univ).card = n.choose k - S.card.choose k :=\n-- by\n--   have :=@card_Finset_len (Fin n) _ k, \n--   rw fintype.card_Fin at this,\n--   rw \u2190 Finset.card_univ at this,\n--   rw \u2190 filter_card_add_filter_neg_card_eq_card  (\u03bbx : {A:Finset (Fin n)// A.card = k}, \u2191x \u2286 S) at this,\n--   rw [\u2190 this, card_filter_powersetLen S, add_tsub_cancel_left], \n-- \n\n-- /-- The number of 2-edge colorings of K_n that are mono c on a set S of size s is\n--     2^(n.choose 2 - s.choose 2) -/\n-- lemma card_mono_cols {n : \u2115} {c : Fin 2} {S: Finset (Fin n)}:  \n-- fintype.card ({col: twocol n // twocol_mono_c c S col}) = 2^(n.choose 2 - S.card.choose 2):=\n-- by\n--   unfold twocol_mono_c,\n--   have := @card_fun_res ({A:Finset (Fin n) // A.card = 2}) (Fin 2) _ _ (not_sub S) c,\n--   unfold not_sub at this, simp_rw not_not at this,\n--   rwa [ fintype.card_fin, card_filter_powersetLen_compl 2 S] at this, \n-- \n\n\n-- lemma Ramsey_lb_twocol {s n: \u2115} : \n-- (\u2203 col: twocol n, \u2200 (c: Fin 2), \u2200 (S:Finset (Fin n)), S.card = s \u2192  \u00ac twocol_mono_c c S col) \u2192 \u00ac Ramsey_of n s s  :=\n-- by\n--   intro h, \n--   apply Ramsey_lb, rw (fin_lb' s n),\n--   obtain \u27e8col,hc\u27e9:=h,\n--   set colf: Finset (Fin n) \u2192 Fin 2:= \u03bb x, if hx: x.card = 2 then  col \u27e8x,hx\u27e9 else 0 with hcolf,\n--   use colf,intros c S hS,\n--   specialize hc c S hS,\n--   contrapose hc, rw not_not, push_neg at hc,\n--   unfold twocol_mono_c, intros e he,\n--   specialize hc \u2191e, rw mem_powersetLen at hc,\n--   rw hcolf at hc,\n--   simp only [eq_self_iff_true, subtype.val_eq_coe, subtype.coe_eta, dite_eq_ite, and_imp] at *,\n--   specialize hc he e.property, \n--   split_ifs at hc, exact hc,\n--   exfalso, apply h, exact e.property,\n-- \n\n-- open_locale big_operators\n\n\n-- lemma card_card (Q: \u03b1 \u2192 \u03b2 \u2192 Prop) {a : \u03b1}: fintype.card ({b:\u03b2//Q a b}) = Finset.card {b: \u03b2| Q a b}.to_Finset :=\n-- by\n--   simp only [set.to_Finset_card, set.coe_set_of],\n-- \n\n-- lemma subtype_pigeon_exist (F: Finset \u03b1) (p: \u03b1 \u2192 \u03b2  \u2192 Prop) :\n-- \u2211 a in F, fintype.card {b : \u03b2 // p a b} < fintype.card \u03b2 \u2192 \u2203 b, \u2200 a, a \u2208 F \u2192 \u00ac p a b:=\n-- by\n--   simp_rw card_card p,\n--   simp_rw Finset.card_eq_sum_ones, --simp,\n--   intros hf, by_contra, push_neg at h,\n--   rw sum_comm' _ at hf,\n--   rotate,\n--   exact (univ:Finset \u03b2),\n--   intro b, exact {a:\u03b1| a\u2208F \u2227 p a b}.to_Finset,\n--   intros x y, \n--   simp_rw set.mem_to_Finset at *,\n--   split,\n--   rintros \u27e8hx,hy\u27e9,  exact \u27e8\u27e8hx,hy\u27e9,mem_univ _\u27e9,\n--   intro h,  exact \u27e8h.1.1,h.1.2\u27e9,\n--   simp_rw sum_const at hf,\n--   simp only [set.to_Finset_card, set.coe_set_of, smul_one_eq_coe, cast_id] at hf,\n--   have c1:\u2200 b, 1 \u2264 card {x//x \u2208F \u2227 p x b},{\n--     intro b, change 0 < _, rw card_pos_iff,\n--     obtain \u27e8a,ha\u27e9:=h b, use \u27e8a,ha\u27e9,},\n--   rw fintype.card_eq_sum_ones at hf,\n--   apply lt_irrefl (\u2211 b: \u03b2,1),\n--   apply lt_of_le_of_lt _ hf,\n--   apply sum_le_sum, intros b hb, exact c1 b,\n-- \n\n\n-- /-- The mono two colorings that are red on S are disjoint from those that are blue-/\n-- lemma col_mono_disj {n : \u2115} {S: Finset (Fin n)} (hn : 2 \u2264 S.card ) :\n--  disjoint {col: twocol n | twocol_mono_c 0 S col}.to_Finset {col: twocol n | twocol_mono_c 1 S col}.to_Finset:=\n-- by\n--   simp only [set.to_Finset_disjoint_iff],\n--   have := hn.trans (card_le_univ S), rw fintype.card_Fin at this,\n--   intros col hc,\n--   obtain \u27e8e,he\u27e9:=exists_smaller_set _ _ hn,\n--   simp only [set.inf_eq_inter, set.mem_inter_iff, set.mem_set_of_eq] at hc,\n--   have c0:=hc.1 \u27e8e,he.2\u27e9 he.1, have c1:=hc.2 \u27e8e,he.2\u27e9 he.1,\n--   rw c0 at c1, rw \u2190 fin_two_not at c1, contradiction,\n-- \n\n-- /-- The mono two colorings on S are either red or blue -/\n-- lemma col_mono_union {n : \u2115} {S: Finset (Fin n)}  :  {col: twocol n | twocol_mono_c 0 S col}.to_Finset \u222a {col: twocol n | twocol_mono_c 1 S col}.to_Finset\n-- = {col : twocol n | twocol_mono S col}.to_Finset\n-- :=\n-- by\n--   ext, simp only [mem_union, set.mem_to_Finset, set.mem_set_of_eq],--simp only [set.mem_union, set.mem_set_of_eq],\n--   unfold twocol_mono_c twocol_mono,\n-- \n\n\n-- /-- Hence the number of mono colorings that of S is the sum over Fin 2 of mono 0 and mono 1 two-colourings -/\n-- lemma sum_cols_mono {n : \u2115} {S: Finset (Fin n)} (hn : 2 \u2264 S.card ) : \n-- \u2211  c, fintype.card ({col: twocol n // twocol_mono_c c S col})\n-- = fintype.card ({col: twocol n // twocol_mono S col}) :=\n-- by\n--   simp_rw card_card,\n--   rw [Finset_fin2.1,sum_union Finset_fin2.2, sum_singleton,sum_singleton],\n--   rw \u2190 card_disjoint_union, congr, exact col_mono_union, \n--   exact col_mono_disj hn,\n-- \n\n\n-- -- All quantities in this inequality are now known to us\n-- lemma union_card_mono_le_imp {s n : \u2115} (hn: 2 \u2264 s ): \n-- \u2211 S in powersetLen s univ, \u2211 c: Fin 2, fintype.card({col: twocol n // twocol_mono_c c S col} ) \n--                                     < fintype.card(twocol n) \u2192\u00acRamsey_of n s s:=\n-- by\n--   intro h,\n--   apply Ramsey_lb_twocol,\n--   have : \u2200 S:Finset (Fin n), S \u2208  powersetLen s univ \u2192  2 \u2264 S.card,{\n--     intros S hS, rw mem_powersetLen at hS,rw hS.2, exact hn, apply_instance,\n--   },\n--   rw Finset.sum_congr at h,\n--   rotate, refl,\n--   intros S hS, exact sum_cols_mono (this S hS),\n--   have :=subtype_pigeon_exist (powersetLen s (univ: Finset (Fin n))) twocol_mono h,\n--   obtain \u27e8col,h\u27e9:=this, use col, intros c S,\n--   intros hc hf,\n--   specialize h S,rw mem_powersetLen_univ_iff at h,\n--   specialize h hc, apply h, \n--   unfold twocol_mono,\n--   by_cases hc2: c= 0,\n--     left, rw hc2 at hf, exact hf,\n--     right, rw fin_two_not c at hc2, rw hc2 at hf, exact hf,\n-- \n\n\n-- -- The classical (easy) probabilistic lower bound for R(s,s)\n-- theorem Ramsey_lower_bound (s n : \u2115) (hn: 2 \u2264 s ) :\n-- (n.choose s) * 2 * (2^((n.choose 2) - (s.choose 2) )) < 2^(n.choose 2) \u2192 \u00ac Ramsey_of n s s:=\n-- by\n--   intros h,\n--   apply union_card_mono_le_imp hn,\n--   simp_rw card_mono_cols, unfold twocol, rw card_cols,\n--   simp_rw sum_const, rw card_univ, rw fintype.card_fin,\n--   simp_rw [nsmul_eq_mul, cast_id],\n--   convert h,  nth_rewrite_rhs 0 \u2190 fintype.card_Fin n,  rw \u2190 card_univ,\n--   rw \u2190 card_powersetLen, rw Finset.card_eq_sum_ones,simp_rw sum_mul, rw one_mul,\n--   apply Finset.sum_congr, refl,intros S hS,rw mem_powersetLen_univ_iff at hS,\n--   rw hS,\n-- \n\n--  lower_bounds\n\n  twocolour\n\n\n--  /-  k-colour 2-graph Ramsey numbers -/\n \n-- section kcolour\n-- variable {k : \u2115}\n\n\n-- /-- A col is mono on a particular set iff every pair in the set receives the same colour  -/\n-- def kmono_c_on (A : Finset \u2115) (col : Finset \u2115 \u2192 Fin k) (c : Fin k)  : Prop:=\n-- \u2200 (e : Finset \u2115), e \u2208 powersetLen 2 A \u2192 col e = c\n\n\n-- /-- A colouring col is Ramsey for n s t if every n-set contains a red s-set or a blue t-set under col -/\n-- def kRamsey_col (col : Finset \u2115 \u2192 Fin k) (n : \u2115) (s : Fin k \u2192 \u2115) : Prop:= \u2200 {V : Finset \u2115}, n \u2264 V.card \u2192 \n-- (\u2203 (A : Finset \u2115), \u2203 (i : Fin k), (A \u2286 V \u2227 kmono_c_on A col i \u2227 (s i) \u2264 A.card))\n\n-- /-- n is Ramsey if every colouring is Ramsey for n (with s and t) -/\n-- def kRamsey_of (n : \u2115) (s : Fin k \u2192 \u2115): Prop:= \u2200 (col : Finset \u2115 \u2192 Fin k), kRamsey_col col n s \n\n-- /-- if n is Ramsey for s,t and n \u2264 m then m is also Ramsey -/ \n-- lemma kmono_Ramsey_of {n m: \u2115} {s: Fin k \u2192 \u2115} (h : kRamsey_of n s) (hm: n \u2264 m) : kRamsey_of m s  :=\n-- by\n--   intros col V h2,\n--   exact  h col (hm.trans h2),\n-- \n\n-- def kres (s : Fin k.succ \u2192 \u2115) : Fin k \u2192 \u2115:=\u03bb i, s i \n\n-- def kto2 (col : Finset \u2115 \u2192 Fin k.succ) : Finset \u2115 \u2192 Fin 2:=\u03bb e, if (col e = k) then 1 else 0\n\n-- def rescol {col : Finset \u2115 \u2192 Fin k.succ} {A : Finset \u2115} (hm: mono_c_on A (kto2 col) 0) (hk : 0 < k): Finset \u2115 \u2192  (Fin k) :=\n-- by\n--   intros e, \n--   by_cases he: e \u2208 powersetLen 2 A,\n--   have hcol:=hm e he,\n--   unfold kto2 at hcol, simp only [ite_eq_right_iff, Fin.one_eq_zero_iff, nat.one_ne_zero] at hcol,\n--   refine \u27e8col e,_\u27e9,\n--   by_contra,\n--   have hk2:=Fin.eq_last_of_not_lt h, apply hcol, rw hk2,\n--   exact (Fin.coe_nat_eq_last k).symm,\n--   exact \u27e80,hk\u27e9,\n-- \n\n\n-- lemma resol_eq_col {col : Finset \u2115 \u2192 Fin k.succ} {A : Finset \u2115} (hm: mono_c_on A (kto2 col) 0)(hk : 0 < k): \n-- \u2200 e \u2208 powersetLen 2 A, (rescol hm hk e : \u2115) = (col e):=\n-- by\n--   intros e he, unfold rescol, split_ifs, refl,\n-- \n\n-- lemma mono_to_kmono_1 {col : Finset \u2115 \u2192 Fin k.succ} {A : Finset \u2115} (hm: mono_c_on A (kto2 col) 1) : kmono_c_on A col k:=\n-- by\n--   unfold mono_c_on kto2 at hm,\n--   simp only [ite_eq_left_iff, Fin.zero_eq_one_iff, nat.one_ne_zero] at hm,\n--   unfold kmono_c_on,\n--   intros e he, \n--   specialize hm e he,\n--   contrapose hm, push_neg, exact \u27e8hm,not_false\u27e9,\n-- \n\n-- lemma mono_to_kmono_0 {col : Finset \u2115 \u2192 Fin k.succ} {A : Finset \u2115} {a: \u2115}{s : Fin k.succ \u2192 \u2115} \n-- (hm: mono_c_on A (kto2 col) 0) (kra: kRamsey_of a (kres s)) (hA : a \u2264 A.card) (hk: 0 < k): \n--  \u2203 (i:Fin k), \u2203 (B:Finset \u2115), B\u2286 A \u2227 kmono_c_on B col i \u2227 (s i) \u2264 B.card:=\n-- by\n--   specialize kra (rescol hm hk) hA,  \n--   obtain \u27e8B,i, hB1,hB2,hB3\u27e9:=kra,\n--   refine \u27e8i,B,hB1,_, hB3\u27e9,\n--   intros e he, \n--   have h1:=resol_eq_col hm hk e (powersetLen_mono hB1 he),\n--   have h2:= hB2 e he, rw h2 at h1,\n--   rw Fin.eq_iff_veq,\n--   simp only [Fin.val_eq_coe, Fin.coe_eq_cast_succ, Fin.coe_cast_succ],  rw h1,\n-- \n\n\n\n-- lemma kRamsey_step {a b : \u2115} (s: Fin k.succ \u2192 \u2115) (hk : 0 < k): kRamsey_of a (kres s) \u2192 Ramsey_of b a (s k) \u2192 kRamsey_of b s:=\n-- by\n--   intros kra rb col V hcv,\n--   specialize rb (kto2 col) hcv,\n--   obtain \u27e8A,hA1,\u27e8hA2,hA3\u27e9|\u27e8hA2,hA3\u27e9\u27e9:=rb,\n--   obtain \u27e8i,B, hB1, hB2,hB3\u27e9:=mono_to_kmono_0 hA2 kra hA3 hk,\n--   exact \u27e8B,i,hB1.trans hA1,hB2,hB3\u27e9,\n--   exact \u27e8A,k,hA1,mono_to_kmono_1 hA2,hA3\u27e9,\n-- \n\n-- lemma kRamsey_one  (s : Fin 1 \u2192 \u2115) : kRamsey_of (s 0) s:=\n-- by\n--   intros col A hA,\n--   refine \u27e8A,0,subset_refl _,  _ ,hA\u27e9,\n--   intros e he, rw eq_iff_true_of_subsingleton, triv,\n-- \n\n\n-- lemma kRamsey_of_zero {n : \u2115} (s : Fin k.succ \u2192 \u2115) :(s k) = 0 \u2192   kRamsey_of n s:=\n-- by\n--   intros hk col A hA,\n--   refine \u27e8\u2205, k, empty_subset _,_, _\u27e9,\n--   intros e he,  exfalso, \n--   have hec1:=mem_powersetLen.1 he,\n--   have hec2:=card_le_of_subset hec1.1,\n--   rw [card_empty ,hec1.2]at hec2,\n--   exact (not_le_of_gt zero_lt_two) hec2,\n--   rw hk, exact zero_le',\n-- \n\n\n-- -- For any number of colours (k+1) and any clique sizes s0 ,s1,... sk there is an n that will work..\n-- theorem kcol_Ramsey (s: Fin k.succ \u2192 \u2115) : \u2203 n, kRamsey_of n s:=\n-- by\n--   induction k with k h generalizing s,\n--   exact \u27e8s 0, kRamsey_one s\u27e9,\n--   obtain \u27e8a,ha\u27e9:= h (kres s),\n--   have hk1:=kmono_Ramsey_of  ha (le_succ a),\n--   refine \u27e8(a + (s k.succ).pred).choose a,_\u27e9,\n--   refine kRamsey_step s (succ_pos k) hk1 _,\n--   cases (s k.succ),\n--   apply Ramsey_symm, \n--   apply mono_Ramsey_of (Ramsey_zero a.succ)  zero_le',\n--   rw pred_succ, exact Ramsey a n,\n-- \n\n\n--  kcolour\n\n\n-- section schur\n\n-- variable {k : \u2115}\n\n-- def schur3 (x y z : \u2115) : Prop:= x + y = z \u2227 0 < x \u2227 0 < y \u2227 0 < z\n\n-- lemma schur_of_ordered {a b c : \u2115} (h: a < b \u2227 b < c): schur3 (c-b) (b-a) (c-a):=\n-- by\n--   exact \u27e8tsub_add_tsub_cancel h.2.le h.1.le,nat.sub_pos_of_lt h.2, nat.sub_pos_of_lt h.1,nat.sub_pos_of_lt (h.1.trans h.2)\u27e9,\n-- \n\n-- def scol (ncol : \u2115 \u2192 Fin k.succ) : Finset \u2115 \u2192 Fin k.succ:=\n-- \u03bb A, if hne : A.nonempty then (ncol (max' A hne - min' A hne)) else 0\n\n\n\n-- lemma scol_pair {a b : \u2115} (h : a < b) (ncol : \u2115\u2192 Fin k.succ) :scol ncol {a,b} = ncol (b - a):=\n-- by\n--   unfold scol,\n--   set X:={a,b},\n--   have ha: a \u2208 X,\n--   { rw mem_insert,left,refl,},\n--   have hb: b \u2208 X,\n--   { rw mem_insert,right,exact mem_singleton_self b,},\n--   set c:= max' X \u27e8a,ha\u27e9 with hc,\n--   set d:= min' X \u27e8a,ha\u27e9 with hd,\n--   have : X = insert a {b}:=rfl,\n--   dsimp, split_ifs,   congr, \n--   refine le_antisymm _ (le_max' X b hb),\n--   apply max'_le, intros y hy, rw [mem_insert,mem_singleton] at hy,\n--   cases hy,\n--   rw hy, exact h.le, rwa hy, \n--   refine le_antisymm  (min'_le {a,b} a ha) _,\n--   apply le_min', intros y hy, rw [mem_insert,mem_singleton] at hy,\n--   cases hy,\n--   rwa hy, rw hy, exact h.le,  \n--   exfalso, apply h_1,\n--   exact \u27e8a,ha\u27e9,\n-- \n\n\n-- /-- Schur n k holds iff n is sufficiently large that in any k-colouring of \u2115, every subsert of size at \n-- least n contains a non-zero monochromatic solution of x + y = z -/\n-- def Schur (n k : \u2115):Prop:=\n--  \u2200 (col : \u2115 \u2192 Fin k.succ),\u2200 (V: Finset \u2115),\n--   n \u2264 V.card \u2192  \u2203 (x y z : \u2115), \u2203 (c : Fin k.succ), schur3 x y z \u2227 col x = c \u2227 col y = c \u2227 col z = c \n\n\n-- lemma card_pred_le_card_erase (S : Finset \u2115) (a : \u2115) : S.card.pred \u2264 (S.erase a).card:=\n-- by\n--   rw card_erase_eq_ite, split_ifs,refl,exact pred_le _,\n-- \n\n\n-- /-- Any set of 3 nats can be ordered and the pairs are edges of the triangle on B -/\n-- lemma card_three_nat {B : Finset \u2115} (h : B.card = 3) : \u2203 (a b c : \u2115), a < b \u2227 b < c \u2227\n--  {a,b} \u2208 powersetLen 2 B \u2227 {a,c} \u2208 powersetLen 2 B \u2227 {b,c} \u2208 powersetLen 2 B:=\n-- by\n--   obtain \u27e8x,y,z,hxy, hxz, hyz,hB\u27e9:=card_eq_three.1 h,\n--   have hbx: x\u2208 B,{rw [hB,mem_insert],left,refl},\n--   have hby: y\u2208 B,{rw [hB,mem_insert,mem_insert],right,left,refl},\n--   have hbz: z\u2208 B,{rw [hB,mem_insert,mem_insert,mem_singleton],right,right,refl},\n--   set a:= min' B \u27e8x,hbx\u27e9,\n--   set c:= max' B \u27e8x,hbx\u27e9,\n--   have haB: a \u2208 B :=min'_mem B \u27e8x,hbx\u27e9,\n--   have hcB: c \u2208 B :=max'_mem B \u27e8x,hbx\u27e9,\n--   have haltc:a < c, \n--     {refine min'_lt_max'_of_card B (_:1<B.card),\n--      rw h, exact succ_le_succ one_le_two}, \n--   have hBea:= card_erase_of_mem haB,\n--   have :=card_erase_of_mem (mem_erase_of_ne_of_mem (ne_of_gt haltc) hcB),\n--   rw [hBea,h] at this,\n--   rw (by refl:3-1-1=1) at this,\n--   obtain \u27e8b,hb\u27e9:=card_eq_one.1 this,\n--   have hbb: b \u2208 {b}:=mem_singleton_self b,\n--   rw \u2190 hb at hbb, \n--   have  hbB':=mem_of_mem_erase hbb,\n--   have  hbB:=mem_of_mem_erase hbB',\n--   refine \u27e8a,b,c,_,_,_,_,_\u27e9,\n--   have aleb:a\u2264 b:=min'_le B b hbB,\n--   have hnab:a \u2260 b := (ne_of_mem_erase hbB').symm,\n--   exact lt_of_le_of_ne aleb hnab,\n--   have blec:b\u2264 c:=le_max' B b hbB,\n--   have hnbc:b\u2260c := (ne_of_mem_erase hbb),\n--   exact lt_of_le_of_ne  blec hnbc,\n--   { \n--      refine mem_powersetLen.2 \u27e8_,card_eq_two.2 \u27e8a,b,\u27e8(ne_of_mem_erase hbB').symm,rfl\u27e9\u27e9\u27e9 ,\n--      intros x hx1, rw [mem_insert,mem_singleton] at hx1,\n--      cases hx1,  {rw hx1, exact haB}, {rw hx1, exact hbB},\n--   },\n--   { \n--      refine mem_powersetLen.2 \u27e8_,card_eq_two.2 \u27e8a,c,\u27e8ne_of_lt haltc,rfl\u27e9\u27e9\u27e9,\n--      intros x hx1, rw [mem_insert,mem_singleton] at hx1,\n--      cases hx1,  {rw hx1, exact haB}, {rw hx1, exact hcB},\n--   },\n--   { \n--     refine mem_powersetLen.2 \u27e8_,card_eq_two.2 \u27e8b,c,\u27e8(ne_of_mem_erase hbb), rfl\u27e9\u27e9\u27e9,\n--      intros x hx1, rw [mem_insert,mem_singleton] at hx1,\n--      cases hx1, {rw hx1, exact hbB},  {rw hx1, exact hcB},\n--   },\n-- \n\n\n-- /-- For any k the k-colour Ramsey number for triangles + 1 is sufficient to guarantee\n--  mono x + y = z in every n-subset -/\n-- theorem Schur' (k:\u2115) : \u2203 (n:\u2115), Schur n k:=\n-- by\n--   set s: Fin k.succ \u2192 \u2115:= \u03bb i , 3,\n--   obtain \u27e8n,hn\u27e9:=kcol_Ramsey s,\n--   use n.succ, intros col V hv,\n--   have:= (pred_le_pred hv).trans (card_pred_le_card_erase V 0),\n--   rw pred_succ at this,\n--   obtain \u27e8A,i,hA1,hA2,hA3\u27e9:=hn (scol col) this,\n--   obtain \u27e8B,hB\u27e9:=exists_smaller_set A 3 hA3,\n--   obtain \u27e8a,b,c,hab,hbc,h1,h2,h3\u27e9:=card_three_nat hB.2,\n--   refine \u27e8c-b,b-a,c-a,i,schur_of_ordered \u27e8hab,hbc\u27e9,_\u27e9,\n--   have cab:=hA2 {a,b} (powersetLen_mono hB.1 h1),\n--   rw scol_pair hab col at cab,\n--   have cac:=hA2 {a,c} (powersetLen_mono hB.1 h2),\n--   rw scol_pair (hab.trans hbc) col at cac,\n--   have cbc:=hA2 {b,c} (powersetLen_mono hB.1 h3),\n--   rw scol_pair hbc col at cbc,\n--   exact \u27e8cbc,cab,cac\u27e9,\n-- \n\n--  schur\n\n\n\n", "meta": {"author": "jt496", "repo": "Lean4_Test", "sha": "ec62c927827ab38b6aedadb59783a6d5066f3eb0", "save_path": "github-repos/lean/jt496-Lean4_Test", "path": "github-repos/lean/jt496-Lean4_Test/Lean4_Test-ec62c927827ab38b6aedadb59783a6d5066f3eb0/src/2graph_with_lb.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7139700047345164}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n\n! This file was ported from Lean 3 source module topology.algebra.uniform_filter_basis\n! leanprover-community/mathlib commit 531db2ef0fdddf8b3c8dcdcd87138fe969e1a81a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.Algebra.FilterBasis\nimport Mathbin.Topology.Algebra.UniformGroup\n\n/-!\n# Uniform properties of neighborhood bases in topological algebra\n\nThis files contains properties of filter bases on algebraic structures that also require the theory\nof uniform spaces.\n\nThe only result so far is a characterization of Cauchy filters in topological groups.\n\n-/\n\n\nopen uniformity Filter\n\nopen Filter\n\nnamespace AddGroupFilterBasis\n\nvariable {G : Type _} [AddCommGroup G] (B : AddGroupFilterBasis G)\n\n/-- The uniform space structure associated to an abelian group filter basis via the associated\ntopological abelian group structure. -/\nprotected def uniformSpace : UniformSpace G :=\n  @TopologicalAddGroup.toUniformSpace G _ B.topology B.is_topological_add_group\n#align add_group_filter_basis.uniform_space AddGroupFilterBasis.uniformSpace\n\n/-- The uniform space structure associated to an abelian group filter basis via the associated\ntopological abelian group structure is compatible with its group structure. -/\nprotected theorem uniformAddGroup : @UniformAddGroup G B.UniformSpace _ :=\n  @comm_topologicalAddGroup_is_uniform G _ B.topology B.is_topological_add_group\n#align add_group_filter_basis.uniform_add_group AddGroupFilterBasis.uniformAddGroup\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (x y \u00abexpr \u2208 \u00bb M) -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (x y \u00abexpr \u2208 \u00bb M) -/\ntheorem cauchy_iff {F : Filter G} :\n    @Cauchy G B.UniformSpace F \u2194\n      F.ne_bot \u2227 \u2200 U \u2208 B, \u2203 M \u2208 F, \u2200 (x) (_ : x \u2208 M) (y) (_ : y \u2208 M), y - x \u2208 U :=\n  by\n  letI := B.uniform_space\n  haveI := B.uniform_add_group\n  suffices F \u00d7\u1da0 F \u2264 \ud835\udce4 G \u2194 \u2200 U \u2208 B, \u2203 M \u2208 F, \u2200 (x) (_ : x \u2208 M) (y) (_ : y \u2208 M), y - x \u2208 U by\n    constructor <;> rintro \u27e8h', h\u27e9 <;> refine' \u27e8h', _\u27e9 <;> [rwa [\u2190 this], rwa [this]]\n  rw [uniformity_eq_comap_nhds_zero G, \u2190 map_le_iff_le_comap]\n  change tendsto _ _ _ \u2194 _\n  simp [(basis_sets F).prod_self.tendsto_iff\u2093 B.nhds_zero_has_basis, @forall_swap (_ \u2208 _) G]\n#align add_group_filter_basis.cauchy_iff AddGroupFilterBasis.cauchy_iff\n\nend AddGroupFilterBasis\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/Algebra/UniformFilterBasis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7139700008030399}}
{"text": "theorem mul_left_cancel (a b c : mynat) (ha : a \u2260 0) : a * b = a * c \u2192 b = c :=\nbegin\ninduction c with d hd generalizing b,\nrw mul_zero,\nrw mul_eq_zero_iff,\nintro h,\ncases h,\nexfalso,\nexact ha h,\nexact h,\nintro h,\ncases b,\nrw mul_zero at h,\nsymmetry at h,\nrw mul_eq_zero_iff at h,\ncases h,\nexfalso,\nexact ha h,\nsymmetry at h,\nexact h,\nrw succ_eq_succ_iff,\napply hd,\nrw mul_succ at h,\nrw mul_succ at h,\napply add_right_cancel _ a _,\nexact h,\nend\n", "meta": {"author": "chanha-park", "repo": "naturalNumberGame", "sha": "4e0d7100ce4575e1add92feefa38b1250431b879", "save_path": "github-repos/lean/chanha-park-naturalNumberGame", "path": "github-repos/lean/chanha-park-naturalNumberGame/naturalNumberGame-4e0d7100ce4575e1add92feefa38b1250431b879/Advanced_Multiplication/4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802529509909, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.71393456837213}}
{"text": "import data.nat.prime\n\nopen nat\n\nlemma larger_prime' : \u2200 n : \u2115, \u2203 p, (prime p) \u2227 (p > n) := \nbegin\n intro n,\n let m := fact n + 1,\n let p := min_fac m,\n have m_ne_1 : m \u2260 1 := ne_of_gt (nat.succ_lt_succ (fact_pos n)),\n have p_gt_0 : p > 0 := min_fac_pos m,\n have p_prime : prime p := min_fac_prime m_ne_1,\n have not_p_le_n : \u00ac p \u2264 n, {\n  intro p_le_n,\n  have d0 : p \u2223 fact n := dvd_fact p_gt_0 p_le_n,\n  have d1 : p \u2223 fact n + 1 := min_fac_dvd m,\n  have d  : p \u2223 1 := (nat.dvd_add_iff_right d0).mpr d1,\n  exact prime.not_dvd_one p_prime d\n },\n have p_gt_n : p > n := lt_of_not_ge not_p_le_n,\n exact \u27e8p,\u27e8p_prime,p_gt_n\u27e9\u27e9,\nend\n\nlemma larger_prime'' : \u2200 n : \u2115, \u2203 p, (prime p) \u2227 (p > n) := \n\u03bb n, \n let m := fact n + 1 in\n let p := min_fac m in \n let p_prime := min_fac_prime (ne_of_gt (nat.succ_lt_succ (fact_pos n))) in\n  \u27e8p,\u27e8p_prime,\n          (lt_of_not_ge (\u03bb p_le_n,\n                         prime.not_dvd_one\n                         p_prime ((nat.dvd_add_iff_right\n                                    (dvd_fact p_prime.pos p_le_n)).mpr (min_fac_dvd m))))\u27e9\u27e9\n\n\n", "meta": {"author": "NeilStrickland", "repo": "lean_primes", "sha": "26c89392d47018ec5bcaaec087cc06b82da3969d", "save_path": "github-repos/lean/NeilStrickland-lean_primes", "path": "github-repos/lean/NeilStrickland-lean_primes/lean_primes-26c89392d47018ec5bcaaec087cc06b82da3969d/src/primes_min.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802529509909, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7139345636337594}}
{"text": "import tactic\nimport data.set\nimport incidence_geometry\n\ndef Point := \u211d \u00d7 \u211d\n\n@[simp] lemma point_neq_by_coords (A B : Point) : (A \u2260 B) \u2194 (A.1 \u2260 B.1 \u2228 A.2 \u2260 B.2) :=\nbegin\n  rw \u2190 not_iff_not,\n  push_neg,\n  exact prod.ext_iff\nend\n\n@[ext] structure LineEq := (a b c : \u211d) (h : a \u2260 0 \u2228 b \u2260 0)\n\ndefinition line_eq (l m : LineEq) : Prop := \u2203 (x : \u211d), x\u2260 0 \u2227 l.a = x * m.a \u2227 l.b = x * m.b \u2227 l.c = x * m.c\n\nlemma line_eq_refl : reflexive line_eq :=\nbegin\n  intro l,\n  use 1,\n  refine \u27e8zero_ne_one.symm, _, _, _\u27e9,\n  { rw one_mul },\n  { rw one_mul }, \n  { rw one_mul }, \nend\n\nlemma line_eq_symm : symmetric line_eq :=\nbegin\n  intros l m hlm,\n  rcases hlm with \u27e8x, \u27e8hx, ha, hb, hc\u27e9\u27e9 ,\n  use x\u207b\u00b9,\n  have hxinv : x\u207b\u00b9*x = 1, { finish }, /- TODO: remove finish -/\n  refine \u27e8inv_ne_zero hx,_,_,_\u27e9,\n  { simp only [ha], rw [\u2190 mul_assoc, hxinv, one_mul] }, \n  { simp only [hb], rw [\u2190 mul_assoc, hxinv, one_mul] },\n  { simp only [hc], rw [\u2190 mul_assoc, hxinv, one_mul] },\nend\n\nlemma line_eq_trans : transitive line_eq :=\nbegin\n  intros l m n hlm hmn,\n  rcases hlm with \u27e8x, \u27e8hx, ha\u2081, hb\u2081, hc\u2081\u27e9\u27e9 ,\n  rcases hmn with \u27e8y, \u27e8hy, ha\u2082, hb\u2082, hc\u2082\u27e9\u27e9 ,\n  use x*y,\n  refine \u27e8mul_ne_zero hx hy,_,_,_\u27e9,\n  { rw [ha\u2081, ha\u2082, mul_assoc] },\n  { rw [hb\u2081, hb\u2082, mul_assoc] },\n  { rw [hc\u2081, hc\u2082, mul_assoc] },\nend\n\ntheorem line_equiv : equivalence line_eq := \u27e8line_eq_refl, line_eq_symm, line_eq_trans\u27e9\n\ndef Line.setoid : setoid LineEq := { r := line_eq, iseqv := line_equiv }\n\nlocal attribute [instance] Line.setoid\n\ndef Line := quotient Line.setoid\n\ndef Line.reduce : LineEq \u2192 Line := quot.mk line_eq\ninstance : has_lift LineEq Line := { lift := Line.reduce }\ninstance : has_coe LineEq Line := { coe := Line.reduce }\n\ndef Line.mk (a b c : \u211d) (h : a \u2260 0 \u2228 b \u2260 0) : Line := \u2191(LineEq.mk a b c h)\n\n\ndef has_point' (l : LineEq) (P : Point) : Prop := l.a*P.1 + l.b*P.2 + l.c = 0\n\ntheorem has_point_well_defined {l m : LineEq} (h : l \u2248 m) (P : Point): has_point' l P \u2194 has_point' m P :=\nbegin\n  cases h with x h,\n  rcases h with \u27e8hx, ha, hb, hc\u27e9,\n  rw [has_point', ha, hb, hc, mul_assoc, mul_assoc, \u2190 left_distrib, \u2190 left_distrib],\n  rw has_point',\n  finish, /- TODO: remove finish -/\nend\n\nlemma has_point_well_defined' {l m : LineEq} (h: l \u2248 m) : has_point' l = has_point' m := begin\n  rw function.funext_iff,\n  intro P,\n  rw has_point_well_defined,\n  exact h,\nend\n\ndef has_point := quotient.lift has_point' @has_point_well_defined'\n\nnoncomputable def line_from_points {A B : Point} (hAB : A \u2260 B) : Line :=\nbegin\n  rw point_neq_by_coords at hAB,\n  by_cases hx: A.1 = B.1,\n  {\n    let a : \u211d := 1,\n    let b : \u211d := 0,\n    let c : \u211d := -(A.1+B.1)/2,\n    have h : a \u2260 0 \u2228 b \u2260 0, { left, exact ne_zero.ne a },\n    exact Line.mk a b c h },\n  { \n    rw push_neg.not_eq at hx,\n    let a : \u211d := -(A.2-B.2)/(A.1-B.1),\n    let b : \u211d := 1,\n    let c : \u211d := -(a*(A.1+B.1)-(A.2+B.2))/2,\n    have h : a \u2260 0 \u2228 b \u2260 0, { right, exact ne_zero.ne b },\n    exact Line.mk a b c h }\nend\n\ndef line_from_points' : Point \u2192 Point \u2192 Prop\n  | (x, y) (a, b) := true\n\nlemma points_in_line_from_points {A B : Point} (hAB : A \u2260 B) :\n  has_point (line_from_points hAB) A \u2227 has_point (line_from_points hAB) B := \nbegin\n  -- rw line_from_points,\n  split,\n  { rw [has_point], /- TODO: \u00bfC\u00f3mo puedo escoger un representante can\u00f3nico? \u00bfo puedo evitar tener que escojerlo? -/\n    sorry },\n  { sorry },\nend\n\ninstance : incidence_geometry Point Line := { \n  lies_on := \u03bb P l, has_point l P,\n  I1 := begin\n    intros A B hAB,\n    use line_from_points hAB,\n    split,\n    { simp, exact points_in_line_from_points hAB },\n    { intro m, simp, intros hA hB,\n      sorry }\n  end,\n  I2 := begin\n    intro \u2113,\n\n    -- cases l.h,\n    -- { \n    --   use Point.mk (-l.c) 0, \n    --   use Point.mk (-l.c-l.b) 1,\n    --   split,\n    --   { rw [ \u2190 push_neg.not_eq, Point.ext_iff, push_neg.not_and_distrib_eq ], \n    --     right,\n    --     push_neg,\n    --     exact zero_ne_one },\n    --   { split, \n    --     { rw [h, one_mul, mul_zero, add_zero, add_left_neg] }, \n    --     { rw [h, one_mul, mul_one, sub_add_cancel, add_left_neg] }, }\n    -- },\n    -- {\n    --   use Point.mk 0 (-l.c), \n    --   use Point.mk 1 (-l.c-l.a),\n    --   split,\n    --   { rw [ \u2190 push_neg.not_eq, \n    --       Point.ext_iff, \n    --       push_neg.not_and_distrib_eq ], \n    --     left,\n    --     push_neg,\n    --     exact zero_ne_one },\n    --   { split, \n    --     { rw [h, mul_zero, one_mul, zero_add, add_left_neg] }, \n    --     { rw [h, mul_one, one_mul, add_sub_cancel'_right, add_left_neg] }},\n    -- },\n    sorry\n  end,\n  I3 := begin\n    let A : Point := (0, 1), use A, \n    let B : Point := (1, 0), use B, \n    let C : Point := (1, 1), use C, \n    split,\n    { rw [different3, point_neq_by_coords, point_neq_by_coords, point_neq_by_coords], \n      refine \u27e8_, _, _\u27e9,\n      { left, exact zero_ne_one },\n      { left, exact zero_ne_one },\n      { right, exact zero_ne_one },\n      },\n    { push_neg, \n      intros l hA hB,\n      -- rw [ne.def, mul_one, mul_one],\n      -- cases l.h with ha hb,\n      -- { \n      --   rw [ha, mul_zero, mul_one, add_zero, add_eq_zero_iff_neg_eq] at hB, \n      --   have hc : l.c = -1, { exact hB.symm }, \n      --   rw [ha, hc, mul_zero,  zero_add, mul_one, add_eq_zero_iff_eq_neg, neg_neg ] at hA, \n      --   rw [ha, hA, hc, add_neg_cancel_comm, push_neg.not_eq],\n      --   exact one_ne_zero },\n      -- { \n      --   rw [hb, mul_zero, mul_one, zero_add, add_eq_zero_iff_neg_eq] at hA,\n      --   have hc : l.c = -1, { exact hA.symm }, \n      --   rw [hc, mul_zero, mul_one, add_zero, add_eq_zero_iff_eq_neg, neg_neg] at hB,\n      --   rw [hB, hb, hc, add_neg_cancel_comm, push_neg.not_eq],\n      --   exact one_ne_zero }},\n    sorry }\n  end \n}", "meta": {"author": "haztecaso", "repo": "euclidean-geometry-lean", "sha": "ab3b82d64d2a931b63cf2ee34d1c736d2f1927e4", "save_path": "github-repos/lean/haztecaso-euclidean-geometry-lean", "path": "github-repos/lean/haztecaso-euclidean-geometry-lean/euclidean-geometry-lean-ab3b82d64d2a931b63cf2ee34d1c736d2f1927e4/src/examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7139345544962232}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport algebra.big_operators.ring\nimport number_theory.divisors\nimport algebra.squarefree\nimport algebra.invertible\n\n/-!\n# Arithmetic Functions and Dirichlet Convolution\n\nThis file defines arithmetic functions, which are functions from `\u2115` to a specified type that map 0\nto 0. In the literature, they are often instead defined as functions from `\u2115+`. These arithmetic\nfunctions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,\nto form the Dirichlet ring.\n\n## Main Definitions\n * `arithmetic_function R` consists of functions `f : \u2115 \u2192 R` such that `f 0 = 0`.\n * An arithmetic function `f` `is_multiplicative` when `x.coprime y \u2192 f (x * y) = f x * f y`.\n * The pointwise operations `pmul` and `ppow` differ from the multiplication\n  and power instances on `arithmetic_function R`, which use Dirichlet multiplication.\n * `\u03b6` is the arithmetic function such that `\u03b6 x = 1` for `0 < x`.\n * `\u03c3 k` is the arithmetic function such that `\u03c3 k x = \u2211 y in divisors x, y ^ k` for `0 < x`.\n * `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.\n * `id` is the identity arithmetic function on `\u2115`.\n * `\u03c9 n` is the number of distinct prime factors of `n`.\n * `\u03a9 n` is the number of prime factors of `n` counted with multiplicity.\n * `\u03bc` is the M\u00f6bius function.\n\n## Main Results\n * Several forms of M\u00f6bius inversion:\n * `sum_eq_iff_sum_mul_moebius_eq` for functions to a `comm_ring`\n * `sum_eq_iff_sum_smul_moebius_eq` for functions to an `add_comm_group`\n * `prod_eq_iff_prod_pow_moebius_eq` for functions to a `comm_group`\n * `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `comm_group_with_zero`\n\n## Notation\nThe arithmetic functions `\u03b6` and `\u03c3` have Greek letter names, which are localized notation in\nthe namespace `arithmetic_function`.\n\n## Tags\narithmetic functions, dirichlet convolution, divisors\n\n-/\n\nopen finset\nopen_locale big_operators\n\nnamespace nat\nvariable (R : Type*)\n\n/-- An arithmetic function is a function from `\u2115` that maps 0 to 0. In the literature, they are\n  often instead defined as functions from `\u2115+`. Multiplication on `arithmetic_functions` is by\n  Dirichlet convolution. -/\n@[derive [has_coe_to_fun, has_zero, inhabited]]\ndef arithmetic_function [has_zero R] := zero_hom \u2115 R\n\nvariable {R}\n\nnamespace arithmetic_function\n\nsection has_zero\nvariable [has_zero R]\n\n@[simp] lemma to_fun_eq (f : arithmetic_function R) : f.to_fun = f := rfl\n\n@[simp]\nlemma map_zero {f : arithmetic_function R} : f 0 = 0 :=\nzero_hom.map_zero' f\n\ntheorem coe_inj {f g : arithmetic_function R} : (f : \u2115 \u2192 R) = g \u2194 f = g :=\n\u27e8\u03bb h, zero_hom.coe_inj h, \u03bb h, h \u25b8 rfl\u27e9\n\n@[simp]\nlemma zero_apply {x : \u2115} : (0 : arithmetic_function R) x = 0 :=\nzero_hom.zero_apply x\n\n@[ext] theorem ext \u2983f g : arithmetic_function R\u2984 (h : \u2200 x, f x = g x) : f = g :=\nzero_hom.ext h\n\ntheorem ext_iff {f g : arithmetic_function R} : f = g \u2194 \u2200 x, f x = g x :=\nzero_hom.ext_iff\n\nsection has_one\nvariable [has_one R]\n\ninstance : has_one (arithmetic_function R) := \u27e8\u27e8\u03bb x, ite (x = 1) 1 0, rfl\u27e9\u27e9\n\n@[simp]\nlemma one_one : (1 : arithmetic_function R) 1 = 1 := rfl\n\n@[simp]\nlemma one_apply_ne {x : \u2115} (h : x \u2260 1) : (1 : arithmetic_function R) x = 0 := if_neg h\n\nend has_one\nend has_zero\n\ninstance nat_coe [has_zero R] [has_one R] [has_add R] :\n  has_coe (arithmetic_function \u2115) (arithmetic_function R) :=\n\u27e8\u03bb f, \u27e8\u2191(f : \u2115 \u2192 \u2115), by { transitivity \u2191(f 0), refl, simp }\u27e9\u27e9\n\n@[simp]\nlemma nat_coe_nat (f : arithmetic_function \u2115) :\n  (\u2191f : arithmetic_function \u2115) = f :=\next $ \u03bb _, cast_id _\n\n@[simp]\nlemma nat_coe_apply [has_zero R] [has_one R] [has_add R] {f : arithmetic_function \u2115} {x : \u2115} :\n  (f : arithmetic_function R) x = f x := rfl\n\ninstance int_coe [has_zero R] [has_one R] [has_add R] [has_neg R] :\n  has_coe (arithmetic_function \u2124) (arithmetic_function R) :=\n\u27e8\u03bb f, \u27e8\u2191(f : \u2115 \u2192 \u2124), by { transitivity \u2191(f 0), refl, simp }\u27e9\u27e9\n\n@[simp]\nlemma int_coe_int (f : arithmetic_function \u2124) :\n  (\u2191f : arithmetic_function \u2124) = f :=\next $ \u03bb _, int.cast_id _\n\n@[simp]\nlemma int_coe_apply [has_zero R] [has_one R] [has_add R] [has_neg R]\n  {f : arithmetic_function \u2124} {x : \u2115} :\n  (f : arithmetic_function R) x = f x := rfl\n\n@[simp]\nlemma coe_coe [has_zero R] [has_one R] [has_add R] [has_neg R] {f : arithmetic_function \u2115} :\n  ((f : arithmetic_function \u2124) : arithmetic_function R) = f :=\nby { ext, simp, }\n\nsection add_monoid\n\nvariable [add_monoid R]\n\ninstance : has_add (arithmetic_function R) := \u27e8\u03bb f g, \u27e8\u03bb n, f n + g n, by simp\u27e9\u27e9\n\n@[simp]\nlemma add_apply {f g : arithmetic_function R} {n : \u2115} : (f + g) n = f n + g n := rfl\n\ninstance : add_monoid (arithmetic_function R) :=\n{ add_assoc := \u03bb _ _ _, ext (\u03bb _, add_assoc _ _ _),\n  zero_add := \u03bb _, ext (\u03bb _, zero_add _),\n  add_zero := \u03bb _, ext (\u03bb _, add_zero _),\n  .. arithmetic_function.has_zero R,\n  .. arithmetic_function.has_add }\n\nend add_monoid\n\ninstance [add_comm_monoid R] : add_comm_monoid (arithmetic_function R) :=\n{ add_comm := \u03bb _ _, ext (\u03bb _, add_comm _ _),\n  .. arithmetic_function.add_monoid }\n\ninstance [add_group R] : add_group (arithmetic_function R) :=\n{ neg := \u03bb f, \u27e8\u03bb n, - f n, by simp\u27e9,\n  add_left_neg := \u03bb _, ext (\u03bb _, add_left_neg _),\n  .. arithmetic_function.add_monoid }\n\ninstance [add_comm_group R] : add_comm_group (arithmetic_function R) :=\n{ .. arithmetic_function.add_comm_monoid,\n  .. arithmetic_function.add_group }\n\nsection has_scalar\nvariables {M : Type*} [has_zero R] [add_comm_monoid M] [has_scalar R M]\n\n/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function\n  such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/\ninstance : has_scalar (arithmetic_function R) (arithmetic_function M) :=\n\u27e8\u03bb f g, \u27e8\u03bb n, \u2211 x in divisors_antidiagonal n, f x.fst \u2022 g x.snd, by simp\u27e9\u27e9\n\n@[simp]\nlemma smul_apply {f : arithmetic_function R} {g : arithmetic_function M} {n : \u2115} :\n  (f \u2022 g) n = \u2211 x in divisors_antidiagonal n, f x.fst \u2022 g x.snd := rfl\n\nend has_scalar\n\n/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function\n  such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/\ninstance [semiring R] : has_mul (arithmetic_function R) := \u27e8(\u2022)\u27e9\n\n@[simp]\nlemma mul_apply [semiring R] {f g : arithmetic_function R} {n : \u2115} :\n  (f * g) n = \u2211 x in divisors_antidiagonal n, f x.fst * g x.snd := rfl\n\nsection module\nvariables {M : Type*} [semiring R] [add_comm_monoid M] [module R M]\n\nlemma mul_smul' (f g : arithmetic_function R) (h : arithmetic_function M) :\n  (f * g) \u2022 h = f \u2022 g \u2022 h :=\nbegin\n  ext n,\n  simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, finset.sum_sigma'],\n  apply finset.sum_bij,\n  swap 5,\n  { rintros \u27e8\u27e8i,j\u27e9, \u27e8k,l\u27e9\u27e9 H, exact \u27e8(k, l*j), (l, j)\u27e9 },\n  { rintros \u27e8\u27e8i,j\u27e9, \u27e8k,l\u27e9\u27e9 H,\n    simp only [finset.mem_sigma, mem_divisors_antidiagonal] at H \u22a2,\n    rcases H with \u27e8\u27e8rfl, n0\u27e9, rfl, i0\u27e9,\n    refine \u27e8\u27e8(mul_assoc _ _ _).symm, n0\u27e9, rfl, _\u27e9,\n    rw mul_ne_zero_iff at *,\n    exact \u27e8i0.2, n0.2\u27e9, },\n  { rintros \u27e8\u27e8i,j\u27e9, \u27e8k,l\u27e9\u27e9 H, simp only [mul_assoc] },\n  { rintros \u27e8\u27e8a,b\u27e9, \u27e8c,d\u27e9\u27e9 \u27e8\u27e8i,j\u27e9, \u27e8k,l\u27e9\u27e9 H\u2081 H\u2082,\n    simp only [finset.mem_sigma, mem_divisors_antidiagonal,\n      and_imp, prod.mk.inj_iff, add_comm, heq_iff_eq] at H\u2081 H\u2082 \u22a2,\n    rintros rfl h2 rfl rfl,\n    exact \u27e8\u27e8eq.trans H\u2081.2.1.symm H\u2082.2.1, rfl\u27e9, rfl, rfl\u27e9 },\n  { rintros \u27e8\u27e8i,j\u27e9, \u27e8k,l\u27e9\u27e9 H, refine \u27e8\u27e8(i*k, l), (i, k)\u27e9, _, _\u27e9,\n  { simp only [finset.mem_sigma, mem_divisors_antidiagonal] at H \u22a2,\n    rcases H with \u27e8\u27e8rfl, n0\u27e9, rfl, j0\u27e9,\n    refine \u27e8\u27e8mul_assoc _ _ _, n0\u27e9, rfl, _\u27e9,\n    rw mul_ne_zero_iff at *,\n    exact \u27e8n0.1, j0.1\u27e9 },\n  { simp only [true_and, mem_divisors_antidiagonal, and_true, prod.mk.inj_iff, eq_self_iff_true,\n      ne.def, mem_sigma, heq_iff_eq] at H \u22a2,\n    rw H.2.1 } }\nend\n\nlemma one_smul' (b : arithmetic_function M) :\n  (1 : arithmetic_function R) \u2022 b = b :=\nbegin\n  ext,\n  rw smul_apply,\n  by_cases x0 : x = 0, {simp [x0]},\n  have h : {(1,x)} \u2286 divisors_antidiagonal x := by simp [x0],\n  rw \u2190 sum_subset h, {simp},\n  intros y ymem ynmem,\n  have y1ne : y.fst \u2260 1,\n  { intro con,\n    simp only [con, mem_divisors_antidiagonal, one_mul, ne.def] at ymem,\n    simp only [mem_singleton, prod.ext_iff] at ynmem,\n    tauto },\n  simp [y1ne],\nend\n\nend module\n\nsection semiring\nvariable [semiring R]\n\ninstance : monoid (arithmetic_function R) :=\n{ one_mul := one_smul',\n  mul_one := \u03bb f,\n  begin\n    ext,\n    rw mul_apply,\n    by_cases x0 : x = 0, {simp [x0]},\n    have h : {(x,1)} \u2286 divisors_antidiagonal x := by simp [x0],\n    rw \u2190 sum_subset h, {simp},\n    intros y ymem ynmem,\n    have y2ne : y.snd \u2260 1,\n    { intro con,\n      simp only [con, mem_divisors_antidiagonal, mul_one, ne.def] at ymem,\n      simp only [mem_singleton, prod.ext_iff] at ynmem,\n      tauto },\n    simp [y2ne],\n  end,\n  mul_assoc := mul_smul',\n  .. arithmetic_function.has_one,\n  .. arithmetic_function.has_mul }\n\ninstance : semiring (arithmetic_function R) :=\n{ zero_mul := \u03bb f, by { ext, simp only [mul_apply, zero_mul, sum_const_zero, zero_apply] },\n  mul_zero := \u03bb f, by { ext, simp only [mul_apply, sum_const_zero, mul_zero, zero_apply] },\n  left_distrib := \u03bb a b c, by { ext, simp only [\u2190sum_add_distrib, mul_add, mul_apply, add_apply] },\n  right_distrib := \u03bb a b c, by { ext, simp only [\u2190sum_add_distrib, add_mul, mul_apply, add_apply] },\n  .. arithmetic_function.has_zero R,\n  .. arithmetic_function.has_mul,\n  .. arithmetic_function.has_add,\n  .. arithmetic_function.add_comm_monoid,\n  .. arithmetic_function.monoid }\n\nend semiring\n\ninstance [comm_semiring R] : comm_semiring (arithmetic_function R) :=\n{ mul_comm := \u03bb f g, by { ext,\n    rw [mul_apply, \u2190 map_swap_divisors_antidiagonal, sum_map],\n    simp [mul_comm] },\n  .. arithmetic_function.semiring }\n\ninstance [comm_ring R] : comm_ring (arithmetic_function R) :=\n{ .. arithmetic_function.add_comm_group,\n  .. arithmetic_function.comm_semiring }\n\ninstance {M : Type*} [semiring R] [add_comm_monoid M] [module R M] :\n  module (arithmetic_function R) (arithmetic_function M) :=\n{ one_smul := one_smul',\n  mul_smul := mul_smul',\n  smul_add := \u03bb r x y, by { ext, simp only [sum_add_distrib, smul_add, smul_apply, add_apply] },\n  smul_zero := \u03bb r, by { ext, simp only [smul_apply, sum_const_zero, smul_zero, zero_apply] },\n  add_smul := \u03bb r s x, by { ext, simp only [add_smul, sum_add_distrib, smul_apply, add_apply] },\n  zero_smul := \u03bb r, by { ext, simp only [smul_apply, sum_const_zero, zero_smul, zero_apply] }, }\n\nsection zeta\n\n/-- `\u03b6 0 = 0`, otherwise `\u03b6 x = 1`. The Dirichlet Series is the Riemann \u03b6.  -/\ndef zeta : arithmetic_function \u2115 :=\n\u27e8\u03bb x, ite (x = 0) 0 1, rfl\u27e9\n\nlocalized \"notation `\u03b6` := zeta\" in arithmetic_function\n\n@[simp]\nlemma zeta_apply {x : \u2115} : \u03b6 x = if (x = 0) then 0 else 1 := rfl\n\nlemma zeta_apply_ne {x : \u2115} (h : x \u2260 0) : \u03b6 x = 1 := if_neg h\n\n@[simp]\ntheorem coe_zeta_mul_apply [semiring R] {f : arithmetic_function R} {x : \u2115} :\n  (\u2191\u03b6 * f) x = \u2211 i in divisors x, f i :=\nbegin\n  rw mul_apply,\n  transitivity \u2211 i in divisors_antidiagonal x, f i.snd,\n  { apply sum_congr rfl,\n    intros i hi,\n    rcases mem_divisors_antidiagonal.1 hi with \u27e8rfl, h\u27e9,\n    rw [nat_coe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_mul] },\n  { apply sum_bij (\u03bb i h, prod.snd i),\n    { rintros \u27e8a, b\u27e9 h, simp [snd_mem_divisors_of_mem_antidiagonal h] },\n    { rintros \u27e8a, b\u27e9 h, refl },\n    { rintros \u27e8a1, b1\u27e9 \u27e8a2, b2\u27e9 h1 h2 h,\n      dsimp at h,\n      rw h at *,\n      rw mem_divisors_antidiagonal at *,\n      ext, swap, {refl},\n      simp only [prod.fst, prod.snd] at *,\n      apply nat.eq_of_mul_eq_mul_right _ (eq.trans h1.1 h2.1.symm),\n      rcases h1 with \u27e8rfl, h\u27e9,\n      apply nat.pos_of_ne_zero (right_ne_zero_of_mul h) },\n    { intros a ha,\n      rcases mem_divisors.1 ha with \u27e8\u27e8b, rfl\u27e9, ne0\u27e9,\n      use (b, a),\n      simp [ne0, mul_comm] } }\nend\n\ntheorem coe_zeta_smul_apply {M : Type*} [comm_ring R] [add_comm_group M] [module R M]\n  {f : arithmetic_function M} {x : \u2115} :\n  ((\u2191\u03b6 : arithmetic_function R) \u2022 f) x = \u2211 i in divisors x, f i :=\nbegin\n  rw smul_apply,\n  transitivity \u2211 i in divisors_antidiagonal x, f i.snd,\n  { apply sum_congr rfl,\n    intros i hi,\n    rcases mem_divisors_antidiagonal.1 hi with \u27e8rfl, h\u27e9,\n    rw [nat_coe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul] },\n  { apply sum_bij (\u03bb i h, prod.snd i),\n    { rintros \u27e8a, b\u27e9 h, simp [snd_mem_divisors_of_mem_antidiagonal h] },\n    { rintros \u27e8a, b\u27e9 h, refl },\n    { rintros \u27e8a1, b1\u27e9 \u27e8a2, b2\u27e9 h1 h2 h,\n      dsimp at h,\n      rw h at *,\n      rw mem_divisors_antidiagonal at *,\n      ext, swap, {refl},\n      simp only [prod.fst, prod.snd] at *,\n      apply nat.eq_of_mul_eq_mul_right _ (eq.trans h1.1 h2.1.symm),\n      rcases h1 with \u27e8rfl, h\u27e9,\n      apply nat.pos_of_ne_zero (right_ne_zero_of_mul h) },\n    { intros a ha,\n      rcases mem_divisors.1 ha with \u27e8\u27e8b, rfl\u27e9, ne0\u27e9,\n      use (b, a),\n      simp [ne0, mul_comm] } }\nend\n\n@[simp]\ntheorem coe_mul_zeta_apply [semiring R] {f : arithmetic_function R} {x : \u2115} :\n  (f * \u03b6) x = \u2211 i in divisors x, f i :=\nbegin\n  apply opposite.op_injective,\n  rw [op_sum],\n  convert @coe_zeta_mul_apply R\u1d52\u1d56 _ { to_fun := opposite.op \u2218 f, map_zero' := by simp} x,\n  rw [mul_apply, mul_apply, op_sum],\n  conv_lhs { rw \u2190 map_swap_divisors_antidiagonal, },\n  rw sum_map,\n  apply sum_congr rfl,\n  intros y hy,\n  by_cases h1 : y.fst = 0,\n  { simp [function.comp_apply, h1] },\n  { simp only [h1, mul_one, one_mul, prod.fst_swap, function.embedding.coe_fn_mk, prod.snd_swap,\n      if_false, zeta_apply, zero_hom.coe_mk, nat_coe_apply, cast_one] }\nend\n\ntheorem zeta_mul_apply {f : arithmetic_function \u2115} {x : \u2115} :\n  (\u03b6 * f) x = \u2211 i in divisors x, f i :=\nby rw [\u2190 nat_coe_nat \u03b6, coe_zeta_mul_apply]\n\ntheorem mul_zeta_apply {f : arithmetic_function \u2115} {x : \u2115} :\n  (f * \u03b6) x = \u2211 i in divisors x, f i :=\nby rw [\u2190 nat_coe_nat \u03b6, coe_mul_zeta_apply]\n\nend zeta\n\nopen_locale arithmetic_function\n\nsection pmul\n\n/-- This is the pointwise product of `arithmetic_function`s. -/\ndef pmul [mul_zero_class R] (f g : arithmetic_function R) :\n  arithmetic_function R :=\n\u27e8\u03bb x, f x * g x, by simp\u27e9\n\n@[simp]\nlemma pmul_apply [mul_zero_class R] {f g : arithmetic_function R} {x : \u2115} :\n  f.pmul g x = f x * g x := rfl\n\nlemma pmul_comm [comm_monoid_with_zero R] (f g : arithmetic_function R) :\n  f.pmul g = g.pmul f :=\nby { ext, simp [mul_comm] }\n\nvariable [semiring R]\n\n@[simp]\nlemma pmul_zeta (f : arithmetic_function R) : f.pmul \u2191\u03b6 = f :=\nbegin\n  ext x,\n  cases x;\n  simp [nat.succ_ne_zero],\nend\n\n@[simp]\nlemma zeta_pmul (f : arithmetic_function R) : (\u03b6 : arithmetic_function R).pmul f = f :=\nbegin\n  ext x,\n  cases x;\n  simp [nat.succ_ne_zero],\nend\n\n/-- This is the pointwise power of `arithmetic_function`s. -/\ndef ppow (f : arithmetic_function R) (k : \u2115) :\n  arithmetic_function R :=\nif h0 : k = 0 then \u03b6 else \u27e8\u03bb x, (f x) ^ k,\n  by { rw [map_zero], exact zero_pow (nat.pos_of_ne_zero h0) }\u27e9\n\n@[simp]\nlemma ppow_zero {f : arithmetic_function R} : f.ppow 0 = \u03b6 :=\nby rw [ppow, dif_pos rfl]\n\n@[simp]\nlemma ppow_apply {f : arithmetic_function R} {k x : \u2115} (kpos : 0 < k) :\n  f.ppow k x = (f x) ^ k :=\nby { rw [ppow, dif_neg (ne_of_gt kpos)], refl }\n\nlemma ppow_succ {f : arithmetic_function R} {k : \u2115} :\n  f.ppow (k + 1) = f.pmul (f.ppow k) :=\nbegin\n  ext x,\n  rw [ppow_apply (nat.succ_pos k), pow_succ],\n  induction k; simp,\nend\n\nlemma ppow_succ' {f : arithmetic_function R} {k : \u2115} {kpos : 0 < k} :\n  f.ppow (k + 1) = (f.ppow k).pmul f :=\nbegin\n  ext x,\n  rw [ppow_apply (nat.succ_pos k), pow_succ'],\n  induction k; simp,\nend\n\nend pmul\n\n/-- Multiplicative functions -/\ndef is_multiplicative [monoid_with_zero R] (f : arithmetic_function R) : Prop :=\nf 1 = 1 \u2227 (\u2200 {m n : \u2115}, m.coprime n \u2192 f (m * n) = f m * f n)\n\nnamespace is_multiplicative\n\nsection monoid_with_zero\nvariable [monoid_with_zero R]\n\n@[simp]\nlemma map_one {f : arithmetic_function R} (h : f.is_multiplicative) : f 1 = 1 :=\nh.1\n\n@[simp]\nlemma map_mul_of_coprime {f : arithmetic_function R} (hf : f.is_multiplicative)\n  {m n : \u2115} (h : m.coprime n) : f (m * n) = f m * f n :=\nhf.2 h\n\nend monoid_with_zero\n\nlemma nat_cast {f : arithmetic_function \u2115} [semiring R] (h : f.is_multiplicative) :\n  is_multiplicative (f : arithmetic_function R) :=\n\u27e8by simp [h], \u03bb m n cop, by simp [cop, h]\u27e9\n\nlemma int_cast {f : arithmetic_function \u2124} [ring R] (h : f.is_multiplicative) :\n  is_multiplicative (f : arithmetic_function R) :=\n\u27e8by simp [h], \u03bb m n cop, by simp [cop, h]\u27e9\n\nlemma mul [comm_semiring R] {f g : arithmetic_function R}\n  (hf : f.is_multiplicative) (hg : g.is_multiplicative) :\n  is_multiplicative (f * g) :=\n\u27e8by { simp [hf, hg], }, begin\n  simp only [mul_apply],\n  intros m n cop,\n  rw sum_mul_sum,\n  symmetry,\n  apply sum_bij (\u03bb (x : (\u2115 \u00d7 \u2115) \u00d7 \u2115 \u00d7 \u2115) h, (x.1.1 * x.2.1, x.1.2 * x.2.2)),\n  { rintros \u27e8\u27e8a1, a2\u27e9, \u27e8b1, b2\u27e9\u27e9 h,\n    simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,\n    rcases h with \u27e8\u27e8rfl, ha\u27e9, \u27e8rfl, hb\u27e9\u27e9,\n    simp only [mem_divisors_antidiagonal, nat.mul_eq_zero, ne.def],\n    split, {ring},\n    rw nat.mul_eq_zero at *,\n    apply not_or ha hb },\n  { rintros \u27e8\u27e8a1, a2\u27e9, \u27e8b1, b2\u27e9\u27e9 h,\n    simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,\n    rcases h with \u27e8\u27e8rfl, ha\u27e9, \u27e8rfl, hb\u27e9\u27e9,\n    dsimp only,\n    rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,\n        hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right],\n    ring, },\n  { rintros \u27e8\u27e8a1, a2\u27e9, \u27e8b1, b2\u27e9\u27e9 \u27e8\u27e8c1, c2\u27e9, \u27e8d1, d2\u27e9\u27e9 hab hcd h,\n    simp only [mem_divisors_antidiagonal, ne.def, mem_product] at hab,\n    rcases hab with \u27e8\u27e8rfl, ha\u27e9, \u27e8rfl, hb\u27e9\u27e9,\n    simp only [mem_divisors_antidiagonal, ne.def, mem_product] at hcd,\n    simp only [prod.mk.inj_iff] at h,\n    ext; dsimp only,\n    { transitivity nat.gcd (a1 * a2) (a1 * b1),\n      { rw [nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] },\n      { rw [\u2190 hcd.1.1, \u2190 hcd.2.1] at cop,\n        rw [\u2190 hcd.1.1, h.1, nat.gcd_mul_left,\n            cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] } },\n    { transitivity nat.gcd (a1 * a2) (a2 * b2),\n      { rw [mul_comm, nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,\n            mul_one] },\n      { rw [\u2190 hcd.1.1, \u2190 hcd.2.1] at cop,\n        rw [\u2190 hcd.1.1, h.2, mul_comm, nat.gcd_mul_left,\n            cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] } },\n    { transitivity nat.gcd (b1 * b2) (a1 * b1),\n      { rw [mul_comm, nat.gcd_mul_right,\n           cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul] },\n      { rw [\u2190 hcd.1.1, \u2190 hcd.2.1] at cop,\n        rw [\u2190 hcd.2.1, h.1, mul_comm c1 d1, nat.gcd_mul_left,\n            cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one] } },\n    { transitivity nat.gcd (b1 * b2) (a2 * b2),\n      { rw [nat.gcd_mul_right,\n           cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] },\n      { rw [\u2190 hcd.1.1, \u2190 hcd.2.1] at cop,\n        rw [\u2190 hcd.2.1, h.2, nat.gcd_mul_right,\n            cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] } } },\n  { rintros \u27e8b1, b2\u27e9 h,\n    simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,\n    use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n)),\n    simp only [exists_prop, prod.mk.inj_iff, ne.def, mem_product, mem_divisors_antidiagonal],\n    rw [\u2190 cop.gcd_mul _, \u2190 cop.gcd_mul _, \u2190 h.1, nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,\n        nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _],\n    { rw [nat.mul_eq_zero, decidable.not_or_iff_and_not] at h, simp [h.2.1, h.2.2] },\n    rw [mul_comm n m, h.1] }\nend\u27e9\n\nlemma pmul [comm_semiring R] {f g : arithmetic_function R}\n  (hf : f.is_multiplicative) (hg : g.is_multiplicative) :\n  is_multiplicative (f.pmul g) :=\n\u27e8by { simp [hf, hg], }, \u03bb m n cop, begin\n  simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop],\n  ring,\nend\u27e9\n\nend is_multiplicative\n\nsection special_functions\n\n/-- The identity on `\u2115` as an `arithmetic_function`.  -/\ndef id : arithmetic_function \u2115 := \u27e8id, rfl\u27e9\n\n@[simp]\nlemma id_apply {x : \u2115} : id x = x := rfl\n\n/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/\ndef pow (k : \u2115) : arithmetic_function \u2115 := id.ppow k\n\n@[simp]\nlemma pow_apply {k n : \u2115} : pow k n = if (k = 0 \u2227 n = 0) then 0 else n ^ k :=\nbegin\n  cases k,\n  { simp [pow] },\n  simp [pow, (ne_of_lt (nat.succ_pos k)).symm],\nend\n\n/-- `\u03c3 k n` is the sum of the `k`th powers of the divisors of `n` -/\ndef sigma (k : \u2115) : arithmetic_function \u2115 :=\n\u27e8\u03bb n, \u2211 d in divisors n, d ^ k, by simp\u27e9\n\nlocalized \"notation `\u03c3` := sigma\" in arithmetic_function\n\n@[simp]\nlemma sigma_apply {k n : \u2115} : \u03c3 k n = \u2211 d in divisors n, d ^ k := rfl\n\nlemma sigma_one_apply {n : \u2115} : \u03c3 1 n = \u2211 d in divisors n, d := by simp\n\nlemma zeta_mul_pow_eq_sigma {k : \u2115} : \u03b6 * pow k = \u03c3 k :=\nbegin\n  ext,\n  rw [sigma, zeta_mul_apply],\n  apply sum_congr rfl,\n  intros x hx,\n  rw [pow_apply, if_neg (not_and_of_not_right _ _)],\n  contrapose! hx,\n  simp [hx],\nend\n\nlemma is_multiplicative_zeta : is_multiplicative \u03b6 :=\n\u27e8by simp, \u03bb m n cop, begin\n  cases m, {simp},\n  cases n, {simp},\n  simp [nat.succ_ne_zero]\nend\u27e9\n\nlemma is_multiplicative_id : is_multiplicative arithmetic_function.id :=\n\u27e8rfl, \u03bb _ _ _, rfl\u27e9\n\nlemma is_multiplicative.ppow [comm_semiring R] {f : arithmetic_function R}\n  (hf : f.is_multiplicative) {k : \u2115} :\n  is_multiplicative (f.ppow k) :=\nbegin\n  induction k with k hi,\n  { exact is_multiplicative_zeta.nat_cast },\n  { rw ppow_succ,\n    apply hf.pmul hi },\nend\n\nlemma is_multiplicative_pow {k : \u2115} : is_multiplicative (pow k) :=\nis_multiplicative_id.ppow\n\nlemma is_multiplicative_sigma {k : \u2115} :\n  is_multiplicative (sigma k) :=\nbegin\n  rw [\u2190 zeta_mul_pow_eq_sigma],\n  apply ((is_multiplicative_zeta).mul is_multiplicative_pow)\nend\n\n/-- `\u03a9 n` is the number of prime factors of `n`. -/\ndef card_factors : arithmetic_function \u2115 :=\n\u27e8\u03bb n, n.factors.length, by simp\u27e9\n\nlocalized \"notation `\u03a9` := card_factors\" in arithmetic_function\n\nlemma card_factors_apply {n : \u2115} :\n  \u03a9 n = n.factors.length := rfl\n\n@[simp]\nlemma card_factors_one : \u03a9 1 = 0 := by simp [card_factors]\n\nlemma card_factors_eq_one_iff_prime {n : \u2115} :\n  \u03a9 n = 1 \u2194 n.prime :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, list.length_eq_one.2 \u27e8n, factors_prime h\u27e9\u27e9,\n  cases n,\n  { contrapose! h,\n    simp },\n  rcases list.length_eq_one.1 h with \u27e8x, hx\u27e9,\n  rw [\u2190 prod_factors n.succ_pos, hx, list.prod_singleton],\n  apply prime_of_mem_factors,\n  rw [hx, list.mem_singleton]\nend\n\nlemma card_factors_mul {m n : \u2115} (m0 : m \u2260 0) (n0 : n \u2260 0) :\n  \u03a9 (m * n) = \u03a9 m + \u03a9 n :=\nby rw [card_factors_apply, card_factors_apply, card_factors_apply, \u2190 multiset.coe_card,\n  \u2190 factors_eq, unique_factorization_monoid.factors_mul m0 n0, factors_eq, factors_eq,\n  multiset.card_add, multiset.coe_card, multiset.coe_card]\n\nlemma card_factors_multiset_prod {s : multiset \u2115} (h0 : s.prod \u2260 0) :\n  \u03a9 s.prod = (multiset.map \u03a9 s).sum :=\nbegin\n  revert h0,\n  apply s.induction_on, by simp,\n  intros a t h h0,\n  rw [multiset.prod_cons, mul_ne_zero_iff] at h0,\n  simp [h0, card_factors_mul, h],\nend\n\n/-- `\u03c9 n` is the number of distinct prime factors of `n`. -/\ndef card_distinct_factors : arithmetic_function \u2115 :=\n\u27e8\u03bb n, n.factors.erase_dup.length, by simp\u27e9\n\nlocalized \"notation `\u03c9` := card_distinct_factors\" in arithmetic_function\n\nlemma card_distinct_factors_zero : \u03c9 0 = 0 := by simp\n\nlemma card_distinct_factors_apply {n : \u2115} :\n  \u03c9 n = n.factors.erase_dup.length := rfl\n\nlemma card_distinct_factors_eq_card_factors_iff_squarefree {n : \u2115} (h0 : n \u2260 0) :\n  \u03c9 n = \u03a9 n \u2194 squarefree n :=\nbegin\n  rw [squarefree_iff_nodup_factors h0, card_distinct_factors_apply],\n  split; intro h,\n  { rw \u2190 list.eq_of_sublist_of_length_eq n.factors.erase_dup_sublist h,\n    apply list.nodup_erase_dup },\n  { rw list.erase_dup_eq_self.2 h,\n    refl }\nend\n\n/-- `\u03bc` is the M\u00f6bius function. If `n` is squarefree with an even number of distinct prime factors,\n  `\u03bc n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `\u03bc n = -1`.\n  If `n` is not squarefree, `\u03bc n = 0`. -/\ndef moebius : arithmetic_function \u2124 :=\n\u27e8\u03bb n, if squarefree n then (-1) ^ (card_factors n) else 0, by simp\u27e9\n\nlocalized \"notation `\u03bc` := moebius\" in arithmetic_function\n\n@[simp]\nlemma moebius_apply_of_squarefree {n : \u2115} (h : squarefree n): \u03bc n = (-1) ^ (card_factors n) :=\nif_pos h\n\n@[simp]\nlemma moebius_eq_zero_of_not_squarefree {n : \u2115} (h : \u00ac squarefree n): \u03bc n = 0 := if_neg h\n\nlemma moebius_ne_zero_iff_squarefree {n : \u2115} : \u03bc n \u2260 0 \u2194 squarefree n :=\nbegin\n  split; intro h,\n  { contrapose! h,\n    simp [h] },\n  { simp [h, pow_ne_zero] }\nend\n\nlemma moebius_ne_zero_iff_eq_or {n : \u2115} : \u03bc n \u2260 0 \u2194 \u03bc n = 1 \u2228 \u03bc n = -1 :=\nbegin\n  split; intro h,\n  { rw moebius_ne_zero_iff_squarefree at h,\n    rw moebius_apply_of_squarefree h,\n    apply neg_one_pow_eq_or },\n  { rcases h with h | h; simp [h] }\nend\n\nopen unique_factorization_monoid\n\n@[simp] lemma coe_moebius_mul_coe_zeta [comm_ring R] : (\u03bc * \u03b6 : arithmetic_function R) = 1 :=\nbegin\n  ext x,\n  cases x,\n  { simp only [divisors_zero, sum_empty, ne.def, not_false_iff, coe_mul_zeta_apply,\n      zero_ne_one, one_apply_ne] },\n  cases x,\n  { simp only [moebius_apply_of_squarefree, card_factors_one, squarefree_one, divisors_one,\n      int.cast_one, sum_singleton, coe_mul_zeta_apply, one_one, int_coe_apply, pow_zero] },\n  rw [coe_mul_zeta_apply, one_apply_ne (ne_of_gt (succ_lt_succ (nat.succ_pos _)))],\n  simp_rw [int_coe_apply],\n  rw [\u2190 finset.sum_int_cast, \u2190 sum_filter_ne_zero],\n  convert int.cast_zero,\n  simp only [moebius_ne_zero_iff_squarefree],\n  suffices :\n    \u2211 (y : finset \u2115) in (unique_factorization_monoid.factors x.succ.succ).to_finset.powerset,\n    ite (squarefree y.val.prod) ((-1:\u2124) ^ \u03a9 y.val.prod) 0 = 0,\n  { have h : \u2211 i in _, ite (squarefree i) ((-1:\u2124) ^ \u03a9 i) 0 = _ :=\n      (sum_divisors_filter_squarefree (nat.succ_ne_zero _)),\n    exact (eq.trans (by congr') h).trans this },\n  apply eq.trans (sum_congr rfl _) (sum_powerset_neg_one_pow_card_of_nonempty _),\n  { intros y hy,\n    rw [finset.mem_powerset, \u2190 finset.val_le_iff, multiset.to_finset_val] at hy,\n    have h : unique_factorization_monoid.factors y.val.prod = y.val,\n    { apply factors_multiset_prod_of_irreducible,\n      intros z hz,\n      apply irreducible_of_factor _ (multiset.subset_of_le\n        (le_trans hy (multiset.erase_dup_le _)) hz) },\n    rw [if_pos],\n    { rw [card_factors_apply, \u2190 multiset.coe_card, \u2190 factors_eq, h, finset.card] },\n    rw [unique_factorization_monoid.squarefree_iff_nodup_factors, h],\n    { apply y.nodup },\n    rw [ne.def, multiset.prod_eq_zero_iff],\n    intro con,\n    rw \u2190 h at con,\n    exact not_irreducible_zero (irreducible_of_factor 0 con) },\n  { rw finset.nonempty,\n    rcases wf_dvd_monoid.exists_irreducible_factor _ (nat.succ_ne_zero _) with \u27e8i, hi\u27e9,\n    { rcases exists_mem_factors_of_dvd (nat.succ_ne_zero _) hi.1 hi.2 with \u27e8j, hj, hj2\u27e9,\n      use j,\n      apply multiset.mem_to_finset.2 hj },\n    rw nat.is_unit_iff,\n    omega },\nend\n\n@[simp] lemma coe_zeta_mul_coe_moebius [comm_ring R] : (\u03b6 * \u03bc : arithmetic_function R) = 1 :=\nby rw [mul_comm, coe_moebius_mul_coe_zeta]\n\n@[simp] \n\n@[simp] lemma coe_zeta_mul_moebius : (\u03b6 * \u03bc : arithmetic_function \u2124) = 1 :=\nby rw [\u2190 int_coe_int \u03bc, coe_zeta_mul_coe_moebius]\n\nsection comm_ring\nvariable [comm_ring R]\n\ninstance : invertible (\u03b6 : arithmetic_function R) :=\n{ inv_of := \u03bc,\n  inv_of_mul_self := coe_moebius_mul_coe_zeta,\n  mul_inv_of_self := coe_zeta_mul_coe_moebius}\n\n/-- A unit in `arithmetic_function R` that evaluates to `\u03b6`, with inverse `\u03bc`. -/\ndef zeta_unit : units (arithmetic_function R) :=\n\u27e8\u03b6, \u03bc, coe_zeta_mul_coe_moebius, coe_moebius_mul_coe_zeta\u27e9\n\n@[simp]\nlemma coe_zeta_unit :\n  ((zeta_unit : units (arithmetic_function R)) : arithmetic_function R) = \u03b6 := rfl\n\n@[simp]\nlemma inv_zeta_unit :\n  ((zeta_unit\u207b\u00b9 : units (arithmetic_function R)) : arithmetic_function R) = \u03bc := rfl\n\nend comm_ring\n\n/-- M\u00f6bius inversion for functions to an `add_comm_group`. -/\ntheorem sum_eq_iff_sum_smul_moebius_eq\n  [add_comm_group R] {f g : \u2115 \u2192 R} :\n  (\u2200 (n : \u2115), 0 < n \u2192 \u2211 i in (n.divisors), f i = g n) \u2194\n    \u2200 (n : \u2115), 0 < n \u2192 \u2211 (x : \u2115 \u00d7 \u2115) in n.divisors_antidiagonal, \u03bc x.fst \u2022 g x.snd = f n :=\nbegin\n  let f' : arithmetic_function R := \u27e8\u03bb x, if x = 0 then 0 else f x, if_pos rfl\u27e9,\n  let g' : arithmetic_function R := \u27e8\u03bb x, if x = 0 then 0 else g x, if_pos rfl\u27e9,\n  transitivity (\u03b6 : arithmetic_function \u2124) \u2022 f' = g',\n  { rw ext_iff,\n    apply forall_congr,\n    intro n,\n    cases n, { simp },\n    rw coe_zeta_smul_apply,\n    simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', if_false, zero_hom.coe_mk],\n    rw sum_congr rfl (\u03bb x hx, _),\n    rw (if_neg (ne_of_gt (nat.pos_of_mem_divisors hx))) },\n  transitivity \u03bc \u2022 g' = f',\n  { split; intro h,\n    { rw [\u2190 h, \u2190 mul_smul, moebius_mul_coe_zeta, one_smul] },\n    { rw [\u2190 h, \u2190 mul_smul, coe_zeta_mul_moebius, one_smul] } },\n  { rw ext_iff,\n    apply forall_congr,\n    intro n,\n    cases n, { simp },\n    simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', smul_apply,\n      if_false, zero_hom.coe_mk],\n    rw sum_congr rfl (\u03bb x hx, _),\n    rw (if_neg (ne_of_gt (nat.pos_of_mem_divisors (snd_mem_divisors_of_mem_antidiagonal hx)))) },\nend\n\n/-- M\u00f6bius inversion for functions to a `comm_ring`. -/\ntheorem sum_eq_iff_sum_mul_moebius_eq [comm_ring R] {f g : \u2115 \u2192 R} :\n  (\u2200 (n : \u2115), 0 < n \u2192 \u2211 i in (n.divisors), f i = g n) \u2194\n    \u2200 (n : \u2115), 0 < n \u2192 \u2211 (x : \u2115 \u00d7 \u2115) in n.divisors_antidiagonal, (\u03bc x.fst : R) * g x.snd = f n :=\nbegin\n  rw sum_eq_iff_sum_smul_moebius_eq,\n  apply forall_congr,\n  intro a,\n  apply imp_congr (iff.refl _) (eq.congr_left (sum_congr rfl (\u03bb x hx, _))),\n  rw [gsmul_eq_mul],\nend\n\n/-- M\u00f6bius inversion for functions to a `comm_group`. -/\ntheorem prod_eq_iff_prod_pow_moebius_eq [comm_group R] {f g : \u2115 \u2192 R} :\n  (\u2200 (n : \u2115), 0 < n \u2192 \u220f i in (n.divisors), f i = g n) \u2194\n    \u2200 (n : \u2115), 0 < n \u2192 \u220f (x : \u2115 \u00d7 \u2115) in n.divisors_antidiagonal, g x.snd ^ (\u03bc x.fst) = f n :=\n@sum_eq_iff_sum_smul_moebius_eq (additive R) _ _ _\n\n/-- M\u00f6bius inversion for functions to a `comm_group_with_zero`. -/\ntheorem prod_eq_iff_prod_pow_moebius_eq_of_nonzero [comm_group_with_zero R] {f g : \u2115 \u2192 R}\n  (hf : \u2200 (n : \u2115), 0 < n \u2192 f n \u2260 0) (hg : \u2200 (n : \u2115), 0 < n \u2192 g n \u2260 0) :\n  (\u2200 (n : \u2115), 0 < n \u2192 \u220f i in (n.divisors), f i = g n) \u2194\n    \u2200 (n : \u2115), 0 < n \u2192 \u220f (x : \u2115 \u00d7 \u2115) in n.divisors_antidiagonal, g x.snd ^ (\u03bc x.fst) = f n :=\nbegin\n  refine iff.trans (iff.trans (forall_congr (\u03bb n, _)) (@prod_eq_iff_prod_pow_moebius_eq (units R) _\n    (\u03bb n, if h : 0 < n then units.mk0 (f n) (hf n h) else 1)\n    (\u03bb n, if h : 0 < n then units.mk0 (g n) (hg n h) else 1))) (forall_congr (\u03bb n, _));\n  refine imp_congr_right (\u03bb hn, _),\n  { dsimp,\n    rw [dif_pos hn, \u2190 units.eq_iff, \u2190 units.coe_hom_apply, monoid_hom.map_prod, units.coe_mk0,\n      prod_congr rfl _],\n    intros x hx,\n    rw [dif_pos (nat.pos_of_mem_divisors hx), units.coe_hom_apply, units.coe_mk0] },\n  { dsimp,\n    rw [dif_pos hn, \u2190 units.eq_iff, \u2190 units.coe_hom_apply, monoid_hom.map_prod, units.coe_mk0,\n      prod_congr rfl _],\n    intros x hx,\n    rw [dif_pos (nat.pos_of_mem_divisors (nat.snd_mem_divisors_of_mem_antidiagonal hx)),\n      units.coe_hom_apply, units.coe_gpow', units.coe_mk0] }\nend\n\nend special_functions\nend arithmetic_function\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/number_theory/arithmetic_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7138866832524732}}
{"text": "/- Tactic : rw\n\n## Summary\n\nIf `h` is a proof of `X = Y`, then `rw h,` will change\nall `X`s in the goal to `Y`s. \n\n**Variants:** `rw \u2190 h` changes\n`Y` to `X` and\n`rw h at h2` changes `X` to `Y` in hypothesis `h2` instead\nof the goal.\n\n## Details\n\nThe `rw` tactic is a way to do \"substituting in\". There\nare two distinct situations where use this tactics.\n\n1) If `h : A = B` is a hypothesis (i.e., a proof of `A = B`)\nin your local context (the box in the top right)\nand if your goal contains one or more `A`s, then `rw h`\nwill change them all to `B`'s. \n\n2) The `rw` tactic will also work with proofs of theorems\nwhich are equalities (look for them in the drop down\nmenu on the left, within Theorem Statements).\n\n**Important note:** if `h` is not a proof of the form `A = B`\nor `A \u2194 B` (for example if `h` is a function, an implication,\nor perhaps even a proposition itself rather than its proof),\nthen `rw` is not the tactic you want to use. For example,\n`rw (P = Q)` is never correct: `P = Q` is the true-false\nstatement itself, not the proof.\nIf `h : P = Q` is its proof, then `rw h` will work.\n\n**Pro tip 1:** If `h : A = B` and you want to change\n`B`s to `A`s instead, try `rw \u2190h` (get the arrow with `\\l`,\nnote that this is a small letter L, not a number 1).\n\n### Example:\nIf it looks like this in the top right hand box:\n```\nA B C : Point\nh1 : A = B\nh2 : B = C\n\u22a2 A = C\n```\n\nthen\n\n`rw h1,`\n\nwill change the goal into `\u22a2 B = C`.\n\n### Example: \nYou can use `rw` to change a hypothesis as well. \nFor example, if your local context looks like this:\n```\nA B C : Point\nh1 : A = C\nh2 : A = B\n\u22a2 B = C\n```\nthen `rw h1 at h2` will turn `h2` into `h2 : C = B` (remember operator precedence).\n\n-/\n\n\n/-\n# Tutorial World\n\n## Level 2: the rewrite (`rw`) tactic.\n\nThe next tactic we will learn is `rw` (from rewrite). Rewriting is one of the most basic methods of proof, \nwhere we \"substitute\" one object that we know that is equal to another.\n\nFor example, if `h : A = B` is a hypothesis (i.e., a proof of `A = B`) in your local context (the box in the top right)\nand if your goal contains one or more `A`s, then `rw h` will change them all to `B`'s.\n\nNow, delete the sorry and take a look in the top right box at what we have. The variables `A`, `B` and `C` are \npoints that lie in the plane `\u03a9`. Here we have to prove that if the point $A$ is equal to the point $B$, \nand the point $B$ is equal to the point $C$, then the point $A$ is equal to the point $C$.\n\nTry to use a sequence of rewrite steps to prove the lemma below by typing them into the box underneath, \nbetween the begin and end lines that tell Lean you are starting and finishing a proof.\n\nRight below this explanation, you will find a grey box where a \"Hint\" is hidden in case you get stuck. Click on\nit to step through this level faster, but remember to use it wisely! From now on, you will find some \"Hints\" that might help you.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nDelete `sorry` and type `rw h1,` (don't forget the comma!). Then, note how the goal changes into \u22a2 B = C. Directly after,\ntry to think what would happen if you write `rw h2,`. Typing that line will finish the proof instead of wiritng \u22a2 C = C . This is\nbecause Lean tries to apply `refl` right after some tactics, and `rw`is one of them!\n-/\n\nvariables {\u03a9 : Type} -- hide\n\n/- Lemma : no-side-bar\nIf A, B and C are points with A = B and B = C, then A = C.\n-/\nlemma example_rw (A B C: \u03a9) (h1 : A = B) (h2 : B = C) : A = C :=\nbegin\n  rw h1,\n  rw h2,\n  \nend\n\n/-\n\n## Exploring your proof\n\nClick on `rw h1`, and then use the arrow keys to move your cursor around the proof. \nGo up and down and note that the goal changes -- indeed you can inspect Lean's \"state\" at \neach line of the proof (the hypotheses, and the goal). Try to figure out the exact place \nwhere the goal changes. The comma tells Lean \"I've finished writing this tactic now, please\nprocess it.\" Lean ignores new lines, but pays great attention to commas.\n\n-/\n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/tutorial_world/level02_rw.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7138866716718076}}
{"text": "-- La_equipotencia_es_una_relacion_transitiva.lean\n-- La equipotencia es una relaci\u00f3n transitiva\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 17 de agosto de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Dos conjuntos A y B son equipotentes (y se denota por A \u2243 B) si\n-- existe una aplicaci\u00f3n biyectiva entre ellos. La equipotencia se puede\n-- definir en Lean por\n--    def es_equipotente (A B : Type*) :=\n--      \u2203 g : A \u2192 B, bijective g\n--\n--    infix ` \u22cd `: 50 := es_equipotente\n--\n-- Demostrar que la relaci\u00f3n de equipotencia es transitiva.\n-- ---------------------------------------------------------------------\n\nimport tactic\nopen function\n\ndef es_equipotente (A B : Type*) :=\n  \u2203 g : A \u2192 B, bijective g\n\ninfix ` \u22cd `: 50 := es_equipotente\n\n-- 1\u00aa demostraci\u00f3n\nexample : transitive (\u22cd) :=\nbegin\n  intros X Y Z hXY hYZ,\n  unfold es_equipotente at *,\n  cases hXY with f hf,\n  cases hYZ with g hg,\n  use (g \u2218 f),\n  exact bijective.comp hg hf,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : transitive (\u22cd) :=\nbegin\n  rintros X Y Z \u27e8f, hf\u27e9 \u27e8g, hg\u27e9,\n  use [g \u2218 f, bijective.comp hg hf],\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : transitive (\u22cd) :=\n\u03bb X Y Z \u27e8f, hf\u27e9 \u27e8g, hg\u27e9, by use [g \u2218 f, bijective.comp hg hf]\n\n-- 4\u00aa demostraci\u00f3n\nexample : transitive (\u22cd) :=\n\u03bb X Y Z \u27e8f, hf\u27e9 \u27e8g, hg\u27e9, exists.intro (g \u2218 f) (bijective.comp hg hf)\n\n-- 4\u00aa demostraci\u00f3n\nexample : transitive (\u22cd) :=\n\u03bb X Y Z \u27e8f, hf\u27e9 \u27e8g, hg\u27e9, \u27e8g \u2218 f, bijective.comp hg hf\u27e9\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/La_equipotencia_es_una_relacion_transitiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7138866716282496}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Neil Strickland\n\n! This file was ported from Lean 3 source module data.pnat.basic\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Pnat.Defs\nimport Mathbin.Data.Nat.Bits\nimport Mathbin.Data.Nat.Order.Basic\nimport Mathbin.Data.Set.Basic\nimport Mathbin.Algebra.GroupWithZero.Divisibility\nimport Mathbin.Algebra.Order.Positive.Ring\n\n/-!\n# The positive natural numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file develops the type `\u2115+` or `pnat`, the subtype of natural numbers that are positive.\nIt is defined in `data.pnat.defs`, but most of the development is deferred to here so\nthat `data.pnat.defs` can have very few imports.\n-/\n\n\nderiving instance AddLeftCancelSemigroup, AddRightCancelSemigroup, AddCommSemigroup,\n  LinearOrderedCancelCommMonoid, Add, Mul, Distrib for PNat\n\nnamespace PNat\n\n#print PNat.one_add_natPred /-\n@[simp]\ntheorem one_add_natPred (n : \u2115+) : 1 + n.natPred = n := by\n  rw [nat_pred, add_tsub_cancel_iff_le.mpr <| show 1 \u2264 (n : \u2115) from n.2]\n#align pnat.one_add_nat_pred PNat.one_add_natPred\n-/\n\n#print PNat.natPred_add_one /-\n@[simp]\ntheorem natPred_add_one (n : \u2115+) : n.natPred + 1 = n :=\n  (add_comm _ _).trans n.one_add_natPred\n#align pnat.nat_pred_add_one PNat.natPred_add_one\n-/\n\n#print PNat.natPred_strictMono /-\n@[mono]\ntheorem natPred_strictMono : StrictMono natPred := fun m n h => Nat.pred_lt_pred m.2.ne' h\n#align pnat.nat_pred_strict_mono PNat.natPred_strictMono\n-/\n\n#print PNat.natPred_monotone /-\n@[mono]\ntheorem natPred_monotone : Monotone natPred :=\n  natPred_strictMono.Monotone\n#align pnat.nat_pred_monotone PNat.natPred_monotone\n-/\n\n#print PNat.natPred_injective /-\ntheorem natPred_injective : Function.Injective natPred :=\n  natPred_strictMono.Injective\n#align pnat.nat_pred_injective PNat.natPred_injective\n-/\n\n#print PNat.natPred_lt_natPred /-\n@[simp]\ntheorem natPred_lt_natPred {m n : \u2115+} : m.natPred < n.natPred \u2194 m < n :=\n  natPred_strictMono.lt_iff_lt\n#align pnat.nat_pred_lt_nat_pred PNat.natPred_lt_natPred\n-/\n\n#print PNat.natPred_le_natPred /-\n@[simp]\ntheorem natPred_le_natPred {m n : \u2115+} : m.natPred \u2264 n.natPred \u2194 m \u2264 n :=\n  natPred_strictMono.le_iff_le\n#align pnat.nat_pred_le_nat_pred PNat.natPred_le_natPred\n-/\n\n#print PNat.natPred_inj /-\n@[simp]\ntheorem natPred_inj {m n : \u2115+} : m.natPred = n.natPred \u2194 m = n :=\n  natPred_injective.eq_iff\n#align pnat.nat_pred_inj PNat.natPred_inj\n-/\n\nend PNat\n\nnamespace Nat\n\n#print Nat.succPNat_strictMono /-\n@[mono]\ntheorem succPNat_strictMono : StrictMono succPNat := fun m n => Nat.succ_lt_succ\n#align nat.succ_pnat_strict_mono Nat.succPNat_strictMono\n-/\n\n#print Nat.succPNat_mono /-\n@[mono]\ntheorem succPNat_mono : Monotone succPNat :=\n  succPNat_strictMono.Monotone\n#align nat.succ_pnat_mono Nat.succPNat_mono\n-/\n\n#print Nat.succPNat_lt_succPNat /-\n@[simp]\ntheorem succPNat_lt_succPNat {m n : \u2115} : m.succPNat < n.succPNat \u2194 m < n :=\n  succPNat_strictMono.lt_iff_lt\n#align nat.succ_pnat_lt_succ_pnat Nat.succPNat_lt_succPNat\n-/\n\n#print Nat.succPNat_le_succPNat /-\n@[simp]\ntheorem succPNat_le_succPNat {m n : \u2115} : m.succPNat \u2264 n.succPNat \u2194 m \u2264 n :=\n  succPNat_strictMono.le_iff_le\n#align nat.succ_pnat_le_succ_pnat Nat.succPNat_le_succPNat\n-/\n\n#print Nat.succPNat_injective /-\ntheorem succPNat_injective : Function.Injective succPNat :=\n  succPNat_strictMono.Injective\n#align nat.succ_pnat_injective Nat.succPNat_injective\n-/\n\n#print Nat.succPNat_inj /-\n@[simp]\ntheorem succPNat_inj {n m : \u2115} : succPNat n = succPNat m \u2194 n = m :=\n  succPNat_injective.eq_iff\n#align nat.succ_pnat_inj Nat.succPNat_inj\n-/\n\nend Nat\n\nnamespace PNat\n\nopen Nat\n\n#print PNat.coe_inj /-\n/-- We now define a long list of structures on \u2115+ induced by\n similar structures on \u2115. Most of these behave in a completely\n obvious way, but there are a few things to be said about\n subtraction, division and powers.\n-/\n@[simp, norm_cast]\ntheorem coe_inj {m n : \u2115+} : (m : \u2115) = n \u2194 m = n :=\n  SetCoe.ext_iff\n#align pnat.coe_inj PNat.coe_inj\n-/\n\n/- warning: pnat.add_coe -> PNat.add_coe is a dubious translation:\nlean 3 declaration is\n  forall (m : PNat) (n : PNat), Eq.{1} Nat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) m n)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) m) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) n))\nbut is expected to have type\n  forall (m : PNat) (n : PNat), Eq.{1} Nat (PNat.val (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) m n)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (PNat.val m) (PNat.val n))\nCase conversion may be inaccurate. Consider using '#align pnat.add_coe PNat.add_coe\u2093'. -/\n@[simp, norm_cast]\ntheorem add_coe (m n : \u2115+) : ((m + n : \u2115+) : \u2115) = m + n :=\n  rfl\n#align pnat.add_coe PNat.add_coe\n\n/- warning: pnat.coe_add_hom -> PNat.coeAddHom is a dubious translation:\nlean 3 declaration is\n  AddHom.{0, 0} PNat Nat PNat.hasAdd Nat.hasAdd\nbut is expected to have type\n  AddHom.{0, 0} PNat Nat instPNatAdd instAddNat\nCase conversion may be inaccurate. Consider using '#align pnat.coe_add_hom PNat.coeAddHom\u2093'. -/\n/-- `pnat.coe` promoted to an `add_hom`, that is, a morphism which preserves addition. -/\ndef coeAddHom : AddHom \u2115+ \u2115 where\n  toFun := coe\n  map_add' := add_coe\n#align pnat.coe_add_hom PNat.coeAddHom\n\ninstance : CovariantClass \u2115+ \u2115+ (\u00b7 + \u00b7) (\u00b7 \u2264 \u00b7) :=\n  Positive.covariantClass_add_le\n\ninstance : CovariantClass \u2115+ \u2115+ (\u00b7 + \u00b7) (\u00b7 < \u00b7) :=\n  Positive.covariantClass_add_lt\n\ninstance : ContravariantClass \u2115+ \u2115+ (\u00b7 + \u00b7) (\u00b7 \u2264 \u00b7) :=\n  Positive.contravariantClass_add_le\n\ninstance : ContravariantClass \u2115+ \u2115+ (\u00b7 + \u00b7) (\u00b7 < \u00b7) :=\n  Positive.contravariantClass_add_lt\n\n#print Equiv.pnatEquivNat /-\n/-- An equivalence between `\u2115+` and `\u2115` given by `pnat.nat_pred` and `nat.succ_pnat`. -/\n@[simps (config := { fullyApplied := false })]\ndef Equiv.pnatEquivNat : \u2115+ \u2243 \u2115 where\n  toFun := PNat.natPred\n  invFun := Nat.succPNat\n  left_inv := succPNat_natPred\n  right_inv := Nat.natPred_succPNat\n#align equiv.pnat_equiv_nat Equiv.pnatEquivNat\n-/\n\n#print OrderIso.pnatIsoNat /-\n/-- The order isomorphism between \u2115 and \u2115+ given by `succ`. -/\n@[simps (config := { fullyApplied := false }) apply]\ndef OrderIso.pnatIsoNat : \u2115+ \u2243o \u2115\n    where\n  toEquiv := Equiv.pnatEquivNat\n  map_rel_iff' _ _ := natPred_le_natPred\n#align order_iso.pnat_iso_nat OrderIso.pnatIsoNat\n-/\n\n/- warning: order_iso.pnat_iso_nat_symm_apply -> OrderIso.pnatIsoNat_symm_apply is a dubious translation:\nlean 3 declaration is\n  Eq.{1} (Nat -> PNat) (coeFn.{1, 1} (OrderIso.{0, 0} Nat PNat Nat.hasLe (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid))))) (fun (_x : RelIso.{0, 0} Nat PNat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))))) => Nat -> PNat) (RelIso.hasCoeToFun.{0, 0} Nat PNat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))))) (OrderIso.symm.{0, 0} PNat Nat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) Nat.hasLe OrderIso.pnatIsoNat)) Nat.succPNat\nbut is expected to have type\n  Eq.{1} (forall (\u1fb0 : Nat), (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => PNat) \u1fb0) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} Nat PNat) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => PNat) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} Nat PNat) Nat PNat (Function.instEmbeddingLikeEmbedding.{1, 1} Nat PNat)) (RelEmbedding.toEmbedding.{0, 0} Nat PNat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1281 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.1283 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.1281 x._@.Mathlib.Order.Hom.Basic._hyg.1283) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1296 : PNat) (x._@.Mathlib.Order.Hom.Basic._hyg.1298 : PNat) => LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) x._@.Mathlib.Order.Hom.Basic._hyg.1296 x._@.Mathlib.Order.Hom.Basic._hyg.1298) (RelIso.toRelEmbedding.{0, 0} Nat PNat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1281 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.1283 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.1281 x._@.Mathlib.Order.Hom.Basic._hyg.1283) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.1296 : PNat) (x._@.Mathlib.Order.Hom.Basic._hyg.1298 : PNat) => LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) x._@.Mathlib.Order.Hom.Basic._hyg.1296 x._@.Mathlib.Order.Hom.Basic._hyg.1298) (OrderIso.symm.{0, 0} PNat Nat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) instLENat OrderIso.pnatIsoNat)))) Nat.succPNat\nCase conversion may be inaccurate. Consider using '#align order_iso.pnat_iso_nat_symm_apply OrderIso.pnatIsoNat_symm_apply\u2093'. -/\n@[simp]\ntheorem OrderIso.pnatIsoNat_symm_apply : \u21d1OrderIso.pnatIsoNat.symm = Nat.succPNat :=\n  rfl\n#align order_iso.pnat_iso_nat_symm_apply OrderIso.pnatIsoNat_symm_apply\n\n/- warning: pnat.lt_add_one_iff -> PNat.lt_add_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {a : PNat} {b : PNat}, Iff (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) a (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) b (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne))))) (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) a b)\nbut is expected to have type\n  forall {a : PNat} {b : PNat}, Iff (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) a (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) b (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))) (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) a b)\nCase conversion may be inaccurate. Consider using '#align pnat.lt_add_one_iff PNat.lt_add_one_iff\u2093'. -/\ntheorem lt_add_one_iff : \u2200 {a b : \u2115+}, a < b + 1 \u2194 a \u2264 b := fun a b => Nat.lt_add_one_iff\n#align pnat.lt_add_one_iff PNat.lt_add_one_iff\n\n/- warning: pnat.add_one_le_iff -> PNat.add_one_le_iff is a dubious translation:\nlean 3 declaration is\n  forall {a : PNat} {b : PNat}, Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) a (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) b) (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) a b)\nbut is expected to have type\n  forall {a : PNat} {b : PNat}, Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) a (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) b) (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) a b)\nCase conversion may be inaccurate. Consider using '#align pnat.add_one_le_iff PNat.add_one_le_iff\u2093'. -/\ntheorem add_one_le_iff : \u2200 {a b : \u2115+}, a + 1 \u2264 b \u2194 a < b := fun a b => Nat.add_one_le_iff\n#align pnat.add_one_le_iff PNat.add_one_le_iff\n\ninstance : OrderBot \u2115+ where\n  bot := 1\n  bot_le a := a.property\n\n/- warning: pnat.bot_eq_one -> PNat.bot_eq_one is a dubious translation:\nlean 3 declaration is\n  Eq.{1} PNat (Bot.bot.{0} PNat (OrderBot.toHasBot.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) PNat.orderBot)) (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))\nbut is expected to have type\n  Eq.{1} PNat (Bot.bot.{0} PNat (OrderBot.toBot.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) PNat.instOrderBotPNatToLEToPreorderToPartialOrderToOrderedCancelCommMonoidInstPNatLinearOrderedCancelCommMonoid)) (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))\nCase conversion may be inaccurate. Consider using '#align pnat.bot_eq_one PNat.bot_eq_one\u2093'. -/\n@[simp]\ntheorem bot_eq_one : (\u22a5 : \u2115+) = 1 :=\n  rfl\n#align pnat.bot_eq_one PNat.bot_eq_one\n\n/- warning: pnat.mk_bit0 -> PNat.mk_bit0 is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) {h : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (bit0.{0} Nat Nat.hasAdd n)}, Eq.{1} (Subtype.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n)) (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) (bit0.{0} Nat Nat.hasAdd n) h) (bit0.{0} PNat PNat.hasAdd (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) n (Nat.pos_of_bit0_pos n h)))\nbut is expected to have type\n  forall (n : Nat) {h : LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (bit0.{0} Nat instAddNat n)}, Eq.{1} (Subtype.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n)) (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) (bit0.{0} Nat instAddNat n) h) (bit0.{0} PNat instPNatAdd (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) n (Nat.pos_of_bit0_pos n h)))\nCase conversion may be inaccurate. Consider using '#align pnat.mk_bit0 PNat.mk_bit0\u2093'. -/\n-- Some lemmas that rewrite `pnat.mk n h`, for `n` an explicit numeral, into explicit numerals.\n@[simp]\ntheorem mk_bit0 (n) {h} : (\u27e8bit0 n, h\u27e9 : \u2115+) = (bit0 \u27e8n, pos_of_bit0_pos h\u27e9 : \u2115+) :=\n  rfl\n#align pnat.mk_bit0 PNat.mk_bit0\n\n/- warning: pnat.mk_bit1 -> PNat.mk_bit1 is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) {h : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (bit1.{0} Nat Nat.hasOne Nat.hasAdd n)} {k : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n}, Eq.{1} (Subtype.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n)) (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) (bit1.{0} Nat Nat.hasOne Nat.hasAdd n) h) (bit1.{0} PNat PNat.hasOne PNat.hasAdd (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) n k))\nbut is expected to have type\n  forall (n : Nat) {h : LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (bit1.{0} Nat (CanonicallyOrderedCommSemiring.toOne.{0} Nat Nat.canonicallyOrderedCommSemiring) instAddNat n)} {k : LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n}, Eq.{1} (Subtype.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n)) (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) (bit1.{0} Nat (CanonicallyOrderedCommSemiring.toOne.{0} Nat Nat.canonicallyOrderedCommSemiring) instAddNat n) h) (bit1.{0} PNat instOnePNat instPNatAdd (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) n k))\nCase conversion may be inaccurate. Consider using '#align pnat.mk_bit1 PNat.mk_bit1\u2093'. -/\n@[simp]\ntheorem mk_bit1 (n) {h} {k} : (\u27e8bit1 n, h\u27e9 : \u2115+) = (bit1 \u27e8n, k\u27e9 : \u2115+) :=\n  rfl\n#align pnat.mk_bit1 PNat.mk_bit1\n\n/- warning: pnat.bit0_le_bit0 -> PNat.bit0_le_bit0 is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) (bit0.{0} PNat PNat.hasAdd n) (bit0.{0} PNat PNat.hasAdd m)) (LE.le.{0} Nat Nat.hasLe (bit0.{0} Nat Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) n)) (bit0.{0} Nat Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) m)))\nbut is expected to have type\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) (bit0.{0} PNat instPNatAdd n) (bit0.{0} PNat instPNatAdd m)) (LE.le.{0} Nat instLENat (bit0.{0} Nat instAddNat (PNat.val n)) (bit0.{0} Nat instAddNat (PNat.val m)))\nCase conversion may be inaccurate. Consider using '#align pnat.bit0_le_bit0 PNat.bit0_le_bit0\u2093'. -/\n-- Some lemmas that rewrite inequalities between explicit numerals in `\u2115+`\n-- into the corresponding inequalities in `\u2115`.\n-- TODO: perhaps this should not be attempted by `simp`,\n-- and instead we should expect `norm_num` to take care of these directly?\n-- TODO: these lemmas are perhaps incomplete:\n-- * 1 is not represented as a bit0 or bit1\n-- * strict inequalities?\n@[simp]\ntheorem bit0_le_bit0 (n m : \u2115+) : bit0 n \u2264 bit0 m \u2194 bit0 (n : \u2115) \u2264 bit0 (m : \u2115) :=\n  Iff.rfl\n#align pnat.bit0_le_bit0 PNat.bit0_le_bit0\n\n/- warning: pnat.bit0_le_bit1 -> PNat.bit0_le_bit1 is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) (bit0.{0} PNat PNat.hasAdd n) (bit1.{0} PNat PNat.hasOne PNat.hasAdd m)) (LE.le.{0} Nat Nat.hasLe (bit0.{0} Nat Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) n)) (bit1.{0} Nat Nat.hasOne Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) m)))\nbut is expected to have type\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) (bit0.{0} PNat instPNatAdd n) (bit1.{0} PNat instOnePNat instPNatAdd m)) (LE.le.{0} Nat instLENat (bit0.{0} Nat instAddNat (PNat.val n)) (bit1.{0} Nat (CanonicallyOrderedCommSemiring.toOne.{0} Nat Nat.canonicallyOrderedCommSemiring) instAddNat (PNat.val m)))\nCase conversion may be inaccurate. Consider using '#align pnat.bit0_le_bit1 PNat.bit0_le_bit1\u2093'. -/\n@[simp]\ntheorem bit0_le_bit1 (n m : \u2115+) : bit0 n \u2264 bit1 m \u2194 bit0 (n : \u2115) \u2264 bit1 (m : \u2115) :=\n  Iff.rfl\n#align pnat.bit0_le_bit1 PNat.bit0_le_bit1\n\n/- warning: pnat.bit1_le_bit0 -> PNat.bit1_le_bit0 is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) (bit1.{0} PNat PNat.hasOne PNat.hasAdd n) (bit0.{0} PNat PNat.hasAdd m)) (LE.le.{0} Nat Nat.hasLe (bit1.{0} Nat Nat.hasOne Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) n)) (bit0.{0} Nat Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) m)))\nbut is expected to have type\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) (bit1.{0} PNat instOnePNat instPNatAdd n) (bit0.{0} PNat instPNatAdd m)) (LE.le.{0} Nat instLENat (bit1.{0} Nat (CanonicallyOrderedCommSemiring.toOne.{0} Nat Nat.canonicallyOrderedCommSemiring) instAddNat (PNat.val n)) (bit0.{0} Nat instAddNat (PNat.val m)))\nCase conversion may be inaccurate. Consider using '#align pnat.bit1_le_bit0 PNat.bit1_le_bit0\u2093'. -/\n@[simp]\ntheorem bit1_le_bit0 (n m : \u2115+) : bit1 n \u2264 bit0 m \u2194 bit1 (n : \u2115) \u2264 bit0 (m : \u2115) :=\n  Iff.rfl\n#align pnat.bit1_le_bit0 PNat.bit1_le_bit0\n\n/- warning: pnat.bit1_le_bit1 -> PNat.bit1_le_bit1 is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) (bit1.{0} PNat PNat.hasOne PNat.hasAdd n) (bit1.{0} PNat PNat.hasOne PNat.hasAdd m)) (LE.le.{0} Nat Nat.hasLe (bit1.{0} Nat Nat.hasOne Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) n)) (bit1.{0} Nat Nat.hasOne Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) m)))\nbut is expected to have type\n  forall (n : PNat) (m : PNat), Iff (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) (bit1.{0} PNat instOnePNat instPNatAdd n) (bit1.{0} PNat instOnePNat instPNatAdd m)) (LE.le.{0} Nat instLENat (bit1.{0} Nat (CanonicallyOrderedCommSemiring.toOne.{0} Nat Nat.canonicallyOrderedCommSemiring) instAddNat (PNat.val n)) (bit1.{0} Nat (CanonicallyOrderedCommSemiring.toOne.{0} Nat Nat.canonicallyOrderedCommSemiring) instAddNat (PNat.val m)))\nCase conversion may be inaccurate. Consider using '#align pnat.bit1_le_bit1 PNat.bit1_le_bit1\u2093'. -/\n@[simp]\ntheorem bit1_le_bit1 (n m : \u2115+) : bit1 n \u2264 bit1 m \u2194 bit1 (n : \u2115) \u2264 bit1 (m : \u2115) :=\n  Iff.rfl\n#align pnat.bit1_le_bit1 PNat.bit1_le_bit1\n\n/- warning: pnat.mul_coe -> PNat.mul_coe is a dubious translation:\nlean 3 declaration is\n  forall (m : PNat) (n : PNat), Eq.{1} Nat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) (HMul.hMul.{0, 0, 0} PNat PNat PNat (instHMul.{0} PNat PNat.hasMul) m n)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) m) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) n))\nbut is expected to have type\n  forall (m : PNat) (n : PNat), Eq.{1} Nat (PNat.val (HMul.hMul.{0, 0, 0} PNat PNat PNat (instHMul.{0} PNat instPNatMul) m n)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (PNat.val m) (PNat.val n))\nCase conversion may be inaccurate. Consider using '#align pnat.mul_coe PNat.mul_coe\u2093'. -/\n@[simp, norm_cast]\ntheorem mul_coe (m n : \u2115+) : ((m * n : \u2115+) : \u2115) = m * n :=\n  rfl\n#align pnat.mul_coe PNat.mul_coe\n\n#print PNat.coeMonoidHom /-\n/-- `pnat.coe` promoted to a `monoid_hom`. -/\ndef coeMonoidHom : \u2115+ \u2192* \u2115 where\n  toFun := coe\n  map_one' := one_coe\n  map_mul' := mul_coe\n#align pnat.coe_monoid_hom PNat.coeMonoidHom\n-/\n\n/- warning: pnat.coe_coe_monoid_hom -> PNat.coe_coeMonoidHom is a dubious translation:\nlean 3 declaration is\n  Eq.{1} ((fun (_x : MonoidHom.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) => PNat -> Nat) PNat.coeMonoidHom) (coeFn.{1, 1} (MonoidHom.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) (fun (_x : MonoidHom.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) => PNat -> Nat) (MonoidHom.hasCoeToFun.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) PNat.coeMonoidHom) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))))\nbut is expected to have type\n  Eq.{1} (forall (a : PNat), (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : PNat) => Nat) a) (FunLike.coe.{1, 1, 1} (MonoidHom.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) PNat (fun (_x : PNat) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : PNat) => Nat) _x) (MulHomClass.toFunLike.{0, 0, 0} (MonoidHom.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) PNat Nat (MulOneClass.toMul.{0} PNat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid))))))) (MulOneClass.toMul.{0} Nat (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) (MonoidHomClass.toMulHomClass.{0, 0, 0} (MonoidHom.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))) PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring))) (MonoidHom.monoidHomClass.{0, 0} PNat Nat (Monoid.toMulOneClass.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))))) (MulZeroOneClass.toMulOneClass.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)))))) PNat.coeMonoidHom) (Coe.coe.{1, 1} PNat Nat coePNatNat)\nCase conversion may be inaccurate. Consider using '#align pnat.coe_coe_monoid_hom PNat.coe_coeMonoidHom\u2093'. -/\n@[simp]\ntheorem coe_coeMonoidHom : (coeMonoidHom : \u2115+ \u2192 \u2115) = coe :=\n  rfl\n#align pnat.coe_coe_monoid_hom PNat.coe_coeMonoidHom\n\n#print PNat.le_one_iff /-\n@[simp]\ntheorem le_one_iff {n : \u2115+} : n \u2264 1 \u2194 n = 1 :=\n  le_bot_iff\n#align pnat.le_one_iff PNat.le_one_iff\n-/\n\n/- warning: pnat.lt_add_left -> PNat.lt_add_left is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) (m : PNat), LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) n (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) m n)\nbut is expected to have type\n  forall (n : PNat) (m : PNat), LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) n (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) m n)\nCase conversion may be inaccurate. Consider using '#align pnat.lt_add_left PNat.lt_add_left\u2093'. -/\ntheorem lt_add_left (n m : \u2115+) : n < m + n :=\n  lt_add_of_pos_left _ m.2\n#align pnat.lt_add_left PNat.lt_add_left\n\n/- warning: pnat.lt_add_right -> PNat.lt_add_right is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) (m : PNat), LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) n (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n m)\nbut is expected to have type\n  forall (n : PNat) (m : PNat), LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) n (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n m)\nCase conversion may be inaccurate. Consider using '#align pnat.lt_add_right PNat.lt_add_right\u2093'. -/\ntheorem lt_add_right (n m : \u2115+) : n < n + m :=\n  (lt_add_left n m).trans_eq (add_comm _ _)\n#align pnat.lt_add_right PNat.lt_add_right\n\n/- warning: pnat.coe_bit0 -> PNat.coe_bit0 is a dubious translation:\nlean 3 declaration is\n  forall (a : PNat), Eq.{1} Nat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) (bit0.{0} PNat PNat.hasAdd a)) (bit0.{0} Nat Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) a))\nbut is expected to have type\n  forall (a : PNat), Eq.{1} Nat (PNat.val (bit0.{0} PNat instPNatAdd a)) (bit0.{0} Nat instAddNat (PNat.val a))\nCase conversion may be inaccurate. Consider using '#align pnat.coe_bit0 PNat.coe_bit0\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_bit0 (a : \u2115+) : ((bit0 a : \u2115+) : \u2115) = bit0 (a : \u2115) :=\n  rfl\n#align pnat.coe_bit0 PNat.coe_bit0\n\n/- warning: pnat.coe_bit1 -> PNat.coe_bit1 is a dubious translation:\nlean 3 declaration is\n  forall (a : PNat), Eq.{1} Nat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) (bit1.{0} PNat PNat.hasOne PNat.hasAdd a)) (bit1.{0} Nat Nat.hasOne Nat.hasAdd ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) a))\nbut is expected to have type\n  forall (a : PNat), Eq.{1} Nat (PNat.val (bit1.{0} PNat instOnePNat instPNatAdd a)) (bit1.{0} Nat (CanonicallyOrderedCommSemiring.toOne.{0} Nat Nat.canonicallyOrderedCommSemiring) instAddNat (PNat.val a))\nCase conversion may be inaccurate. Consider using '#align pnat.coe_bit1 PNat.coe_bit1\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_bit1 (a : \u2115+) : ((bit1 a : \u2115+) : \u2115) = bit1 (a : \u2115) :=\n  rfl\n#align pnat.coe_bit1 PNat.coe_bit1\n\n#print PNat.pow_coe /-\n@[simp, norm_cast]\ntheorem pow_coe (m : \u2115+) (n : \u2115) : ((m ^ n : \u2115+) : \u2115) = (m : \u2115) ^ n :=\n  rfl\n#align pnat.pow_coe PNat.pow_coe\n-/\n\n/-- Subtraction a - b is defined in the obvious way when\n  a > b, and by a - b = 1 if a \u2264 b.\n-/\ninstance : Sub \u2115+ :=\n  \u27e8fun a b => toPNat' (a - b : \u2115)\u27e9\n\n/- warning: pnat.sub_coe -> PNat.sub_coe is a dubious translation:\nlean 3 declaration is\n  forall (a : PNat) (b : PNat), Eq.{1} Nat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) (HSub.hSub.{0, 0, 0} PNat PNat PNat (instHSub.{0} PNat PNat.hasSub) a b)) (ite.{1} Nat (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) b a) (Subtype.decidableLT.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) (fun (a : Nat) (b : Nat) => Nat.decidableLt a b) (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) b a) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) a) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) PNat Nat (HasLiftT.mk.{1, 1} PNat Nat (CoeTC\u2093.coe.{1, 1} PNat Nat (coeBase.{1, 1} PNat Nat coePNatNat))) b)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))\nbut is expected to have type\n  forall (a : PNat) (b : PNat), Eq.{1} Nat (PNat.val (HSub.hSub.{0, 0, 0} PNat PNat PNat (instHSub.{0} PNat PNat.instSubPNat) a b)) (ite.{1} Nat (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) b a) (instDecidableLtToLTToPreorderToPartialOrder.{0} PNat instPNatLinearOrder b a) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) (PNat.val a) (PNat.val b)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))\nCase conversion may be inaccurate. Consider using '#align pnat.sub_coe PNat.sub_coe\u2093'. -/\ntheorem sub_coe (a b : \u2115+) : ((a - b : \u2115+) : \u2115) = ite (b < a) (a - b : \u2115) 1 :=\n  by\n  change (to_pnat' _ : \u2115) = ite _ _ _\n  split_ifs with h\n  \u00b7 exact to_pnat'_coe (tsub_pos_of_lt h)\n  \u00b7 rw [tsub_eq_zero_iff_le.mpr (le_of_not_gt h : (a : \u2115) \u2264 b)]\n    rfl\n#align pnat.sub_coe PNat.sub_coe\n\n/- warning: pnat.add_sub_of_lt -> PNat.add_sub_of_lt is a dubious translation:\nlean 3 declaration is\n  forall {a : PNat} {b : PNat}, (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) a b) -> (Eq.{1} PNat (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) a (HSub.hSub.{0, 0, 0} PNat PNat PNat (instHSub.{0} PNat PNat.hasSub) b a)) b)\nbut is expected to have type\n  forall {a : PNat} {b : PNat}, (LT.lt.{0} PNat (Preorder.toLT.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) a b) -> (Eq.{1} PNat (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) a (HSub.hSub.{0, 0, 0} PNat PNat PNat (instHSub.{0} PNat PNat.instSubPNat) b a)) b)\nCase conversion may be inaccurate. Consider using '#align pnat.add_sub_of_lt PNat.add_sub_of_lt\u2093'. -/\ntheorem add_sub_of_lt {a b : \u2115+} : a < b \u2192 a + (b - a) = b := fun h =>\n  eq <| by\n    rw [add_coe, sub_coe, if_pos h]\n    exact add_tsub_cancel_of_le h.le\n#align pnat.add_sub_of_lt PNat.add_sub_of_lt\n\n/- warning: pnat.exists_eq_succ_of_ne_one -> PNat.exists_eq_succ_of_ne_one is a dubious translation:\nlean 3 declaration is\n  forall {n : PNat}, (Ne.{1} PNat n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) -> (Exists.{1} PNat (fun (k : PNat) => Eq.{1} PNat n (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) k (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne))))))\nbut is expected to have type\n  forall {n : PNat}, (Ne.{1} PNat n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) -> (Exists.{1} PNat (fun (k : PNat) => Eq.{1} PNat n (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) k (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))))\nCase conversion may be inaccurate. Consider using '#align pnat.exists_eq_succ_of_ne_one PNat.exists_eq_succ_of_ne_one\u2093'. -/\n/-- If `n : \u2115+` is different from `1`, then it is the successor of some `k : \u2115+`. -/\ntheorem exists_eq_succ_of_ne_one : \u2200 {n : \u2115+} (h1 : n \u2260 1), \u2203 k : \u2115+, n = k + 1\n  | \u27e81, _\u27e9, h1 => False.elim <| h1 rfl\n  | \u27e8n + 2, _\u27e9, _ => \u27e8\u27e8n + 1, by simp\u27e9, rfl\u27e9\n#align pnat.exists_eq_succ_of_ne_one PNat.exists_eq_succ_of_ne_one\n\n/- warning: pnat.case_strong_induction_on -> PNat.caseStrongInductionOn is a dubious translation:\nlean 3 declaration is\n  forall {p : PNat -> Sort.{u1}} (a : PNat), (p (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) -> (forall (n : PNat), (forall (m : PNat), (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid)))) m n) -> (p m)) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))))) -> (p a)\nbut is expected to have type\n  forall {p : PNat -> Sort.{u1}} (a : PNat), (p (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) -> (forall (n : PNat), (forall (m : PNat), (LE.le.{0} PNat (Preorder.toLE.{0} PNat (PartialOrder.toPreorder.{0} PNat (OrderedCancelCommMonoid.toPartialOrder.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid)))) m n) -> (p m)) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) -> (p a)\nCase conversion may be inaccurate. Consider using '#align pnat.case_strong_induction_on PNat.caseStrongInductionOn\u2093'. -/\n/-- Strong induction on `\u2115+`, with `n = 1` treated separately. -/\ndef caseStrongInductionOn {p : \u2115+ \u2192 Sort _} (a : \u2115+) (hz : p 1)\n    (hi : \u2200 n, (\u2200 m, m \u2264 n \u2192 p m) \u2192 p (n + 1)) : p a :=\n  by\n  apply strong_induction_on a\n  rintro \u27e8k, kprop\u27e9 hk\n  cases' k with k\n  \u00b7 exact (lt_irrefl 0 kprop).elim\n  cases' k with k\n  \u00b7 exact hz\n  exact hi \u27e8k.succ, Nat.succ_pos _\u27e9 fun m hm => hk _ (lt_succ_iff.2 hm)\n#align pnat.case_strong_induction_on PNat.caseStrongInductionOn\n\n/- warning: pnat.rec_on -> PNat.recOn is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) {p : PNat -> Sort.{u1}}, (p (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) -> (forall (n : PNat), (p n) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))))) -> (p n)\nbut is expected to have type\n  forall (n : PNat) {p : PNat -> Sort.{u1}}, (p (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) -> (forall (n : PNat), (p n) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) -> (p n)\nCase conversion may be inaccurate. Consider using '#align pnat.rec_on PNat.recOn\u2093'. -/\n/-- An induction principle for `\u2115+`: it takes values in `Sort*`, so it applies also to Types,\nnot only to `Prop`. -/\n@[elab_as_elim]\ndef recOn (n : \u2115+) {p : \u2115+ \u2192 Sort _} (p1 : p 1) (hp : \u2200 n, p n \u2192 p (n + 1)) : p n :=\n  by\n  rcases n with \u27e8n, h\u27e9\n  induction' n with n IH\n  \u00b7 exact absurd h (by decide)\n  \u00b7 cases' n with n\n    \u00b7 exact p1\n    \u00b7 exact hp _ (IH n.succ_pos)\n#align pnat.rec_on PNat.recOn\n\n/- warning: pnat.rec_on_one -> PNat.recOn_one is a dubious translation:\nlean 3 declaration is\n  forall {p : PNat -> Sort.{u1}} (p1 : p (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) (hp : forall (n : PNat), (p n) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))))), Eq.{u1} (p (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) (PNat.recOn.{u1} (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne))) p p1 hp) p1\nbut is expected to have type\n  forall {p : PNat -> Sort.{u1}} (p1 : p (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) (hp : forall (n : PNat), (p n) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))), Eq.{u1} (p (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) (PNat.recOn.{u1} (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))) p p1 hp) p1\nCase conversion may be inaccurate. Consider using '#align pnat.rec_on_one PNat.recOn_one\u2093'. -/\n@[simp]\ntheorem recOn_one {p} (p1 hp) : @PNat.recOn 1 p p1 hp = p1 :=\n  rfl\n#align pnat.rec_on_one PNat.recOn_one\n\n/- warning: pnat.rec_on_succ -> PNat.recOn_succ is a dubious translation:\nlean 3 declaration is\n  forall (n : PNat) {p : PNat -> Sort.{u1}} (p1 : p (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) (hp : forall (n : PNat), (p n) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))))), Eq.{u1} (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne))))) (PNat.recOn.{u1} (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat PNat.hasAdd) n (OfNat.ofNat.{0} PNat 1 (OfNat.mk.{0} PNat 1 (One.one.{0} PNat PNat.hasOne)))) p p1 hp) (hp n (PNat.recOn.{u1} n p p1 hp))\nbut is expected to have type\n  forall (n : PNat) {p : PNat -> Sort.{u1}} (p1 : p (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) (hp : forall (n : PNat), (p n) -> (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))), Eq.{u1} (p (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))) (PNat.recOn.{u1} (HAdd.hAdd.{0, 0, 0} PNat PNat PNat (instHAdd.{0} PNat instPNatAdd) n (OfNat.ofNat.{0} PNat 1 (instOfNatPNatHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) p p1 hp) (hp n (PNat.recOn.{u1} n p p1 hp))\nCase conversion may be inaccurate. Consider using '#align pnat.rec_on_succ PNat.recOn_succ\u2093'. -/\n@[simp]\ntheorem recOn_succ (n : \u2115+) {p : \u2115+ \u2192 Sort _} (p1 hp) :\n    @PNat.recOn (n + 1) p p1 hp = hp n (@PNat.recOn n p p1 hp) :=\n  by\n  cases' n with n h\n  cases n <;> [exact absurd h (by decide), rfl]\n#align pnat.rec_on_succ PNat.recOn_succ\n\n#print PNat.modDivAux_spec /-\ntheorem modDivAux_spec :\n    \u2200 (k : \u2115+) (r q : \u2115) (h : \u00ac(r = 0 \u2227 q = 0)),\n      ((modDivAux k r q).1 : \u2115) + k * (modDivAux k r q).2 = r + k * q\n  | k, 0, 0, h => (h \u27e8rfl, rfl\u27e9).elim\n  | k, 0, q + 1, h =>\n    by\n    change (k : \u2115) + (k : \u2115) * (q + 1).pred = 0 + (k : \u2115) * (q + 1)\n    rw [Nat.pred_succ, Nat.mul_succ, zero_add, add_comm]\n  | k, r + 1, q, h => rfl\n#align pnat.mod_div_aux_spec PNat.modDivAux_spec\n-/\n\n#print PNat.mod_add_div /-\ntheorem mod_add_div (m k : \u2115+) : (mod m k + k * div m k : \u2115) = m :=\n  by\n  let h\u2080 := Nat.mod_add_div (m : \u2115) (k : \u2115)\n  have : \u00ac((m : \u2115) % (k : \u2115) = 0 \u2227 (m : \u2115) / (k : \u2115) = 0) :=\n    by\n    rintro \u27e8hr, hq\u27e9\n    rw [hr, hq, MulZeroClass.mul_zero, zero_add] at h\u2080\n    exact (m.ne_zero h\u2080.symm).elim\n  have := mod_div_aux_spec k ((m : \u2115) % (k : \u2115)) ((m : \u2115) / (k : \u2115)) this\n  exact this.trans h\u2080\n#align pnat.mod_add_div PNat.mod_add_div\n-/\n\n#print PNat.div_add_mod /-\ntheorem div_add_mod (m k : \u2115+) : (k * div m k + mod m k : \u2115) = m :=\n  (add_comm _ _).trans (mod_add_div _ _)\n#align pnat.div_add_mod PNat.div_add_mod\n-/\n\n#print PNat.mod_add_div' /-\ntheorem mod_add_div' (m k : \u2115+) : (mod m k + div m k * k : \u2115) = m :=\n  by\n  rw [mul_comm]\n  exact mod_add_div _ _\n#align pnat.mod_add_div' PNat.mod_add_div'\n-/\n\n#print PNat.div_add_mod' /-\ntheorem div_add_mod' (m k : \u2115+) : (div m k * k + mod m k : \u2115) = m :=\n  by\n  rw [mul_comm]\n  exact div_add_mod _ _\n#align pnat.div_add_mod' PNat.div_add_mod'\n-/\n\n#print PNat.mod_le /-\ntheorem mod_le (m k : \u2115+) : mod m k \u2264 m \u2227 mod m k \u2264 k :=\n  by\n  change (mod m k : \u2115) \u2264 (m : \u2115) \u2227 (mod m k : \u2115) \u2264 (k : \u2115)\n  rw [mod_coe]; split_ifs\n  \u00b7 have hm : (m : \u2115) > 0 := m.pos\n    rw [\u2190 Nat.mod_add_div (m : \u2115) (k : \u2115), h, zero_add] at hm\u22a2\n    by_cases h' : (m : \u2115) / (k : \u2115) = 0\n    \u00b7 rw [h', MulZeroClass.mul_zero] at hm\n      exact (lt_irrefl _ hm).elim\n    \u00b7 let h' := Nat.mul_le_mul_left (k : \u2115) (Nat.succ_le_of_lt (Nat.pos_of_ne_zero h'))\n      rw [mul_one] at h'\n      exact \u27e8h', le_refl (k : \u2115)\u27e9\n  \u00b7 exact \u27e8Nat.mod_le (m : \u2115) (k : \u2115), (Nat.mod_lt (m : \u2115) k.pos).le\u27e9\n#align pnat.mod_le PNat.mod_le\n-/\n\n#print PNat.dvd_iff /-\ntheorem dvd_iff {k m : \u2115+} : k \u2223 m \u2194 (k : \u2115) \u2223 (m : \u2115) :=\n  by\n  constructor <;> intro h; rcases h with \u27e8_, rfl\u27e9; apply dvd_mul_right\n  rcases h with \u27e8a, h\u27e9; cases a;\n  \u00b7 contrapose h\n    apply NeZero\n  use a.succ; apply Nat.succ_pos; rw [\u2190 coe_inj, h, mul_coe, mk_coe]\n#align pnat.dvd_iff PNat.dvd_iff\n-/\n\n#print PNat.dvd_iff' /-\ntheorem dvd_iff' {k m : \u2115+} : k \u2223 m \u2194 mod m k = k :=\n  by\n  rw [dvd_iff]\n  rw [Nat.dvd_iff_mod_eq_zero]; constructor\n  \u00b7 intro h\n    apply Eq\n    rw [mod_coe, if_pos h]\n  \u00b7 intro h\n    by_cases h' : (m : \u2115) % (k : \u2115) = 0\n    \u00b7 exact h'\n    \u00b7 replace h : (mod m k : \u2115) = (k : \u2115) := congr_arg _ h\n      rw [mod_coe, if_neg h'] at h\n      exact ((Nat.mod_lt (m : \u2115) k.pos).Ne h).elim\n#align pnat.dvd_iff' PNat.dvd_iff'\n-/\n\n#print PNat.le_of_dvd /-\ntheorem le_of_dvd {m n : \u2115+} : m \u2223 n \u2192 m \u2264 n :=\n  by\n  rw [dvd_iff']\n  intro h\n  rw [\u2190 h]\n  apply (mod_le n m).left\n#align pnat.le_of_dvd PNat.le_of_dvd\n-/\n\n/- warning: pnat.mul_div_exact -> PNat.mul_div_exact is a dubious translation:\nlean 3 declaration is\n  forall {m : PNat} {k : PNat}, (Dvd.Dvd.{0} PNat (semigroupDvd.{0} PNat (Monoid.toSemigroup.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat PNat.linearOrderedCancelCommMonoid))))))) k m) -> (Eq.{1} PNat (HMul.hMul.{0, 0, 0} PNat PNat PNat (instHMul.{0} PNat PNat.hasMul) k (PNat.divExact m k)) m)\nbut is expected to have type\n  forall {m : PNat} {k : PNat}, (Dvd.dvd.{0} PNat (semigroupDvd.{0} PNat (Monoid.toSemigroup.{0} PNat (RightCancelMonoid.toMonoid.{0} PNat (CancelMonoid.toRightCancelMonoid.{0} PNat (CancelCommMonoid.toCancelMonoid.{0} PNat (OrderedCancelCommMonoid.toCancelCommMonoid.{0} PNat (LinearOrderedCancelCommMonoid.toOrderedCancelCommMonoid.{0} PNat instPNatLinearOrderedCancelCommMonoid))))))) k m) -> (Eq.{1} PNat (HMul.hMul.{0, 0, 0} PNat PNat PNat (instHMul.{0} PNat instPNatMul) k (PNat.divExact m k)) m)\nCase conversion may be inaccurate. Consider using '#align pnat.mul_div_exact PNat.mul_div_exact\u2093'. -/\ntheorem mul_div_exact {m k : \u2115+} (h : k \u2223 m) : k * divExact m k = m :=\n  by\n  apply Eq; rw [mul_coe]\n  change (k : \u2115) * (div m k).succ = m\n  rw [\u2190 div_add_mod m k, dvd_iff'.mp h, Nat.mul_succ]\n#align pnat.mul_div_exact PNat.mul_div_exact\n\n#print PNat.dvd_antisymm /-\ntheorem dvd_antisymm {m n : \u2115+} : m \u2223 n \u2192 n \u2223 m \u2192 m = n := fun hmn hnm =>\n  (le_of_dvd hmn).antisymm (le_of_dvd hnm)\n#align pnat.dvd_antisymm PNat.dvd_antisymm\n-/\n\n#print PNat.dvd_one_iff /-\ntheorem dvd_one_iff (n : \u2115+) : n \u2223 1 \u2194 n = 1 :=\n  \u27e8fun h => dvd_antisymm h (one_dvd n), fun h => h.symm \u25b8 dvd_refl 1\u27e9\n#align pnat.dvd_one_iff PNat.dvd_one_iff\n-/\n\n#print PNat.pos_of_div_pos /-\ntheorem pos_of_div_pos {n : \u2115+} {a : \u2115} (h : a \u2223 n) : 0 < a :=\n  by\n  apply pos_iff_ne_zero.2\n  intro hzero\n  rw [hzero] at h\n  exact PNat.ne_zero n (eq_zero_of_zero_dvd h)\n#align pnat.pos_of_div_pos PNat.pos_of_div_pos\n-/\n\nend PNat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Pnat/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024556, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7138866699676462}}
{"text": "import algebra.order.field.basic algebra.big_operators.intervals\n\n/-! # IMO 2015 A1 -/\n\nnamespace IMOSL\nnamespace IMO2015A1\n\nopen finset\n\ntheorem final_solution {F : Type*} [linear_ordered_field F] {a : \u2115 \u2192 F}\n  (h : \u2200 k : \u2115, 0 < a k) (h0 : \u2200 k : \u2115, (k.succ : F) * a k / (a k ^ 2 + k) \u2264 a k.succ) :\n  \u2200 n : \u2115, 2 \u2264 n \u2192 (n : F) \u2264 (range n).sum a :=\nbegin\n  ---- First replace the inequality condition on `a`\n  replace h0 : \u2200 k : \u2115, (k.succ : F) / a k.succ \u2264 a k + k / a k :=\n  begin\n    intros k,\n    rw [add_div' _ _ _ (ne_of_gt (h k)), div_le_div_iff (h _) (h k), \u2190 sq],\n    exact (div_le_iff' (add_pos_of_pos_of_nonneg (pow_pos (h k) 2) k.cast_nonneg)).mp (h0 k)\n  end,\n\n  ---- Now induct on `n`, clearing the easy cases\n  apply nat.le_induction,\n  rw [nat.cast_bit0, nat.cast_one, sum_range_succ, sum_range_one],\n  replace h0 := h0 0,\n  rw [nat.cast_one, nat.cast_zero, zero_div, add_zero] at h0,\n  refine le_trans _ (add_le_add_right h0 _),\n  rw [div_add' _ _ _ (ne_of_gt (h 1)), le_div_iff (h 1), \u2190 sq],\n  convert two_mul_le_add_sq 1 (a 1); norm_num,\n\n  intros n h1 h2,\n  rw [sum_range_succ, nat.cast_succ],\n  cases le_total 1 (a n) with h3 h3,\n  exact add_le_add h2 h3,\n\n  ---- The hard cases\n  refine le_trans _ (add_le_add_right (_ : (n : F) / a n \u2264 _) _),\n  rw [div_add' _ _ _ (ne_of_gt (h n)), le_div_iff (h n), add_one_mul,\n      \u2190 sub_le_iff_le_add, add_sub_assoc, \u2190 mul_one_sub,\n      \u2190 le_sub_iff_add_le', \u2190 mul_one_sub, \u2190 sub_nonneg, \u2190 sub_mul],\n  refine mul_nonneg (sub_nonneg.mpr (le_trans h3 _)) (sub_nonneg.mpr h3),\n  rw nat.one_le_cast; exact le_trans one_le_two h1,\n\n  clear h1 h2 h3; induction n with n n_ih,\n  rw [nat.cast_zero, sum_range_zero, zero_div],\n  rw [sum_range_succ, add_comm],\n  exact le_trans (h0 n) (add_le_add_left n_ih (a n))\nend\n\nend IMO2015A1\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2015/A1/A1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7138674580315574}}
{"text": "/- Problem 1: Programming in Lean -/\n\n/-\nDefine the following list functions. Example uses are given via\nexample. Once you have defined the function (replaced the _ with\nan implementation), the examples will work (the red highlighting\nwill go away).\n-/\n\n-- part p1-a\ndef nonzeros : List Nat -> List Nat := \nfun list => match list with\n  | [] => []\n  | 0::rest => nonzeros rest\n  | first::rest => first::nonzeros rest\nexample : nonzeros [0,1,0,2,3,0,0] = [1,2,3] := by rfl\n\ndef oddmembers : List Nat -> List Nat := \nfun list => match list with\n  | [] => []\n  | first::rest => if (first % 2 == 1) \n             then first::oddmembers rest \n             else oddmembers rest\nexample : oddmembers [0,1,0,2,3,0,0] = [1,3] := by rfl\n\ndef countoddmembers : List Nat -> Nat := \nfun list => match list with\n  | [] => 0\n  | first::rest => if (first % 2 == 1)\n             then 1 + countoddmembers rest\n             else countoddmembers rest\nexample : countoddmembers [1,0,3,1,4,5] = 4 := by rfl\nexample : countoddmembers [0,2,4] = 0 := by rfl\nexample : countoddmembers [] = 0 := by rfl\n\n-- part p1-a\n\n\n/- A bag (or multiset) is like a set, except that each element\ncan appear multiple times rather than just once. One possible\nrepresentation for a bag of numbers is as a list.\n-/\n\n-- part p1-b\ndef Bag := List Nat\n-- part p1-b\n\n/- Complete the following definitions for the functions count,\nunion, add, and member for bags.\n-/\n\n-- part p1-c\ndef count : Nat -> Bag -> Nat := \nfun n b => match b with\n  | [] => 0\n  | first::rest => if (first == n)\n             then 1 + count n rest\n             else count n rest\nexample : count 1 [1,2,3,1,4,1] = 3 := by rfl\nexample : count 6 [1,2,3,1,4,1] = 0 := by rfl\n\ndef union : Bag -> Bag -> Bag := \nfun b0 b1 => match b1 with \n  | [] => b0\n  | first::rest => first::(union b0 rest)\nexample : count 1 (union [1,2,3] [1,4,1]) = 3 := by rfl\n\ndef add : Nat -> Bag -> Bag := \nfun n b => match b with \n  | [] => b \n  | _ => n::b \nexample : count 1 (add 1 [1,4,1]) = 3 := by rfl\nexample : count 5 (add 1 [1,4,1]) = 0 := by rfl\n\n\ndef member : Nat -> Bag -> Bool := \nfun n b => match b with \n  | [] => false\n  | first::rest => if (first != n)\n                   then member n rest\n                   else true \nexample : member 1 [1,4,1] = true := by rfl\nexample : member 2 [1,4,1] = false := by rfl\n\ndef remove_one : Nat -> Bag -> Bag := \nfun n b => match b with \n  | [] => []\n  | first::rest => if (first == n) \n                   then rest\n                   else first::(remove_one n rest)\nexample : count 5 (remove_one 5 [2,1,5,4,1]) = 0 := by rfl\nexample : count 5 (remove_one 5 [2,1,4,1]) = 0 := by rfl\nexample : count 4 (remove_one 5 [2,1,4,5,1,4]) = 2 := by rfl\nexample : count 5 (remove_one 5 [2,1,5,4,5,1,4]) = 1 := by rfl\n\ndef remove_all : Nat -> Bag -> Bag := \nfun n b => match b with \n  | [] => []\n  | first::rest => if (first == n) \n                   then remove_all n rest\n                   else first::(remove_all n rest)\nexample : count 5 (remove_all 5 [2,1,5,4,1]) = 0 := by rfl\nexample : count 5 (remove_all 5 [2,1,4,1]) = 0 := by rfl\nexample : count 4 (remove_all 5 [2,1,4,5,1,4]) = 2 := by rfl\nexample : count 5 (remove_all 5 [2,1,5,4,5,1,4,5,1,4]) = 0 := by rfl\n\ndef subset : Bag -> Bag -> Bool := \nfun b0 b1 => match b0 with \n  | [] => true \n  | first::rest => if (member first b1)\n                   then subset rest (remove_one first b1)\n                   else false \nexample : subset [1,2] [2,1,4,1] = true := by rfl\nexample : subset [1,2,2] [2,1,4,1] = false := by rfl\n\n-- part p1-c\n\n/- Proofs in minimal propositional logic -/\n\n-- part p1-d\n\nvariable (P Q R S : Prop)\n\ntheorem t1 : P -> P := fun P => P\n\ntheorem t2 : P -> Q -> P := fun p _ => p\n\ntheorem t3 : (P -> Q) -> (Q -> R) -> P -> R := fun PQ QR p => QR (PQ p)\n\ntheorem t4 : P -> Q -> (Q -> P -> R) -> R := fun p q PR => PR q p\n\ntheorem t5 : (P -> Q) -> (P -> R) -> (R -> Q -> S) -> P -> S := \n  fun PQ PR RQS p => RQS (PR p) (PQ p) \n\ntheorem t6 : (P -> Q -> R) -> (P -> Q) -> P -> R := \n  fun PQR PQ p => PQR p (PQ p)\n\n-- part p1-d\n\n/- Proofs in propositional logic -/\n\n-- part p1-e\n\ntheorem p1 : P \u2227 Q -> Q \u2227 P := \n  fun PQ => And.intro PQ.right PQ.left\n\ntheorem p2 : P \u2227 Q -> P := \n  fun PQ => PQ.left\n\ntheorem p3 : P \u2227 Q -> (Q -> R) -> R \u2227 P := \n  fun PQ QR => And.intro (QR PQ.right) PQ.left\n\ntheorem p4 : P \u2228 Q -> (P -> R) -> (Q -> R) -> R := \n  fun PQ PR QR => match PQ with\n                  | Or.inl p => PR p\n                  | Or.inr q => QR q\n\ntheorem p5 : P \u2228 Q -> (P -> R) -> R \u2228 Q := \n  fun PQ PR => match PQ with\n              | Or.inl p => Or.inl (PR p)\n              | Or.inr q => Or.inr q\n\ntheorem p6 : \u00ac Q -> (R -> Q) -> (R \u2228 \u00ac S) -> S -> False := \n  fun NQ RQ RNS S => match RNS with\n                    | Or.inl r => False.elim (NQ (RQ r))\n                    | Or.inr NS => False.elim (NS S)\n\n-- part p1-e\n", "meta": {"author": "zpulichino", "repo": "CS2800", "sha": "ad506aa6a4bf7c97b8e53e183b4bb9cad90bc64c", "save_path": "github-repos/lean/zpulichino-CS2800", "path": "github-repos/lean/zpulichino-CS2800/CS2800-ad506aa6a4bf7c97b8e53e183b4bb9cad90bc64c/HW5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7138674539995137}}
{"text": "set_option tactic.simp.trace true\nset_option trace.Meta.Tactic.simp.rewrite true\n\ndef f (x : \u03b1) := x\n\nexample (a : \u03b1) (b : List \u03b1) : f (a::b = []) = False :=\n  by simp [f]\n\ndef length : List \u03b1 \u2192 Nat\n  | []    => 0\n  | a::as => length as + 1\n\nexample (a b c : \u03b1) (as : List \u03b1) : length (a :: b :: as) > length as := by\n  simp [length]\n  apply Nat.lt.step\n  apply Nat.lt_succ_self\n\ndef fact : Nat \u2192 Nat\n  | 0 => 1\n  | x+1 => (x+1) * fact x\n\ntheorem ex3 : fact x > 0 := by\n  induction x with\n  | zero => decide\n  | succ x ih =>\n    simp [fact]\n    apply Nat.mul_pos\n    apply Nat.zero_lt_succ\n    apply ih\n\ndef head [Inhabited \u03b1] : List \u03b1 \u2192 \u03b1\n  | []   => default\n  | a::_ => a\n\nexample [Inhabited \u03b1] (a : \u03b1) (as : List \u03b1) : head (a::as) = a :=\n  by simp [head]\n\ndef foo := 10\n\nexample (x : Nat) : foo + x = 10 + x := by\n  simp [foo]\n  done\n\ndef g (x : Nat) : Nat := Id.run <| do\n  let x := x\n  return x\n\nexample : g x = x := by\n  simp [g, bind, pure]\n  rfl\n\ndef f1 : StateM Nat Unit := do\n  modify fun x => g x\n\ndef f2 : StateM Nat Unit := do\n  let s \u2190 get\n  set <| g s\n\nexample : f1 = f2 := by\n  simp [f1, f2, bind, StateT.bind, get, getThe, MonadStateOf.get, StateT.get, pure, set, StateT.set, modify, modifyGet, MonadStateOf.modifyGet, StateT.modifyGet]\n\ndef h (x : Nat) : Sum (Nat \u00d7 Nat) Nat := Sum.inl (x, x)\n\ndef bla (x : Nat) :=\n  match h x with\n  | Sum.inl (y, z) => y + z\n  | Sum.inr _ => 0\n\nexample (x : Nat) : bla x = x + x := by\n  simp [bla, h]\n\nexample (x : Nat) (h : 1 \u2264 x) : x - 1 + 1 + 2 = x + 2 := by\n  simp [h, Nat.sub_add_cancel]\n\nexample (x : Nat) : (if h : 1 \u2264 x then x - 1 + 1 else 0) = (if _h : 1 \u2264 x then x else 0) := by\n  simp (config := {contextual := true}) [h, Nat.sub_add_cancel]\n\ntheorem my_thm : a \u2227 a \u2194 a := \u27e8fun h => h.1, fun h => \u27e8h, h\u27e9\u27e9\n\nexample : a \u2227 (b \u2227 b) \u2194 a \u2227 b := by simp [my_thm]\nexample : (a \u2227 (b \u2227 b)) = (a \u2227 b) := by simp only [my_thm]\n\nexample : x - 1 + 1 = x := by simp (discharger := sorry) [Nat.sub_add_cancel]\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/simp_trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7138674454154167}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.vector_bundle\nimport geometry.manifold.smooth_manifold_with_corners\nimport data.set.prod\n\n/-!\n# Basic smooth bundles\n\nIn general, a smooth bundle is a bundle over a smooth manifold, whose fiber is a manifold, and\nfor which the coordinate changes are smooth. In this definition, there are charts involved at\nseveral places: in the manifold structure of the base, in the manifold structure of the fibers, and\nin the local trivializations. This makes it a complicated object in general. There is however a\nspecific situation where things are much simpler: when the fiber is a vector space (no need for\ncharts for the fibers), and when the local trivializations of the bundle and the charts of the base\ncoincide. Then everything is expressed in terms of the charts of the base, making for a much\nsimpler overall structure, which is easier to manipulate formally.\n\nMost vector bundles that naturally occur in differential geometry are of this form:\nthe tangent bundle, the cotangent bundle, differential forms (used to define de Rham cohomology)\nand the bundle of Riemannian metrics. Therefore, it is worth defining a specific constructor for\nthis kind of bundle, that we call basic smooth bundles.\n\nA basic smooth bundle is thus a smooth bundle over a smooth manifold whose fiber is a vector space,\nand which is trivial in the coordinate charts of the base. (We recall that in our notion of manifold\nthere is a distinguished atlas, which does not need to be maximal: we require the triviality above\nthis specific atlas). It can be constructed from a basic smooth bundled core, defined below,\nspecifying the changes in the fiber when one goes from one coordinate chart to another one.\n\n## Main definitions\n\n* `basic_smooth_vector_bundle_core I M F`: assuming that `M` is a smooth manifold over the model\n  with corners `I` on `(\ud835\udd5c, E, H)`, and `F` is a normed vector space over `\ud835\udd5c`, this structure\n  registers, for each pair of charts of `M`, a linear change of coordinates on `F` depending\n  smoothly on the base point. This is the core structure from which one will build a smooth vector\n  bundle with fiber `F` over `M`.\n\nLet `Z` be a basic smooth bundle core over `M` with fiber `F`. We define\n`Z.to_topological_vector_bundle_core`, the (topological) vector bundle core associated to `Z`. From\nit, we get a space `Z.to_topological_vector_bundle_core.total_space` (which as a Type is just\n`\u03a3 (x : M), F`), with the fiber bundle topology. It inherits a manifold structure (where the\ncharts are in bijection with the charts of the basis). We show that this manifold is smooth.\n\nThen we use this machinery to construct the tangent bundle of a smooth manifold.\n\n* `tangent_bundle_core I M`: the basic smooth bundle core associated to a smooth manifold `M` over\n  a model with corners `I`.\n* `tangent_bundle I M`     : the total space of `tangent_bundle_core I M`. It is itself a\n  smooth manifold over the model with corners `I.tangent`, the product of `I` and the trivial model\n  with corners on `E`.\n* `tangent_space I x`      : the tangent space to `M` at `x`\n* `tangent_bundle.proj I M`: the projection from the tangent bundle to the base manifold\n\n## Implementation notes\n\nWe register the vector space structure on the fibers of the tangent bundle, but we do not register\nthe normed space structure coming from that of `F` (as it is not canonical, and we also want to\nkeep the possibility to add a Riemannian structure on the manifold later on without having two\ncompeting normed space instances on the tangent spaces).\n\nWe require `F` to be a normed space, and not just a topological vector space, as we want to talk\nabout smooth functions on `F`. The notion of derivative requires a norm to be defined.\n\n## TODO\nconstruct the cotangent bundle, and the bundles of differential forms. They should follow\nfunctorially from the description of the tangent bundle as a basic smooth bundle.\n\n## Tags\nSmooth fiber bundle, vector bundle, tangent space, tangent bundle\n-/\nnoncomputable theory\n\nuniverse u\n\nopen topological_space set\nopen_locale manifold topological_space\n\n/-- Core structure used to create a smooth bundle above `M` (a manifold over the model with\ncorner `I`) with fiber the normed vector space `F` over `\ud835\udd5c`, which is trivial in the chart domains\nof `M`. This structure registers the changes in the fibers when one changes coordinate charts in the\nbase. We require the change of coordinates of the fibers to be linear, so that the resulting bundle\nis a vector bundle. -/\nstructure basic_smooth_vector_bundle_core {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n(F : Type*) [normed_group F] [normed_space \ud835\udd5c F] :=\n(coord_change      : atlas H M \u2192 atlas H M \u2192 H \u2192 (F \u2192L[\ud835\udd5c] F))\n(coord_change_self : \u2200 i : atlas H M, \u2200 x \u2208 i.1.target, \u2200 v, coord_change i i x v = v)\n(coord_change_comp : \u2200 i j k : atlas H M,\n  \u2200 x \u2208 ((i.1.symm.trans j.1).trans (j.1.symm.trans k.1)).source, \u2200 v,\n  (coord_change j k ((i.1.symm.trans j.1) x)) (coord_change i j x v) = coord_change i k x v)\n(coord_change_smooth_clm : \u2200 i j : atlas H M,\n  cont_diff_on \ud835\udd5c \u221e ((coord_change i j) \u2218 I.symm) (I '' (i.1.symm.trans j.1).source))\n\n/-- The trivial basic smooth bundle core, in which all the changes of coordinates are the\nidentity. -/\ndef trivial_basic_smooth_vector_bundle_core {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n(F : Type*) [normed_group F] [normed_space \ud835\udd5c F] : basic_smooth_vector_bundle_core I M F :=\n{ coord_change := \u03bb i j x, continuous_linear_map.id \ud835\udd5c F,\n  coord_change_self := \u03bb i x hx v, rfl,\n  coord_change_comp := \u03bb i j k x hx v, rfl,\n  coord_change_smooth_clm := \u03bb i j, by { dsimp, exact cont_diff_on_const } }\n\nnamespace basic_smooth_vector_bundle_core\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] {I : model_with_corners \ud835\udd5c E H}\n{M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n{F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\n(Z : basic_smooth_vector_bundle_core I M F)\n\ninstance : inhabited (basic_smooth_vector_bundle_core I M F) :=\n\u27e8trivial_basic_smooth_vector_bundle_core I M F\u27e9\n\nlemma coord_change_continuous (i j : atlas H M) :\n  continuous_on (Z.coord_change i j) (i.1.symm.trans j.1).source :=\nbegin\n  assume x hx,\n  apply (((Z.coord_change_smooth_clm i j).continuous_on.continuous_within_at\n    (mem_image_of_mem I hx)).comp I.continuous_within_at _).congr,\n  { assume y hy,\n    simp only with mfld_simps },\n  { simp only with mfld_simps },\n  { exact maps_to_image I _ },\nend\n\nlemma coord_change_smooth (i j : atlas H M) :\n  cont_diff_on \ud835\udd5c \u221e (\u03bb p : E \u00d7 F, Z.coord_change i j (I.symm p.1) p.2)\n    ((I '' (i.1.symm.trans j.1).source) \u00d7\u02e2 (univ : set F)) :=\nbegin\n  have A : cont_diff \ud835\udd5c \u221e (\u03bb p : (F \u2192L[\ud835\udd5c] F) \u00d7 F, p.1 p.2),\n  { apply is_bounded_bilinear_map.cont_diff,\n    exact is_bounded_bilinear_map_apply },\n  have B : cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F), (Z.coord_change i j (I.symm p.1), p.snd))\n    ((I '' (i.1.symm.trans j.1).source) \u00d7\u02e2 (univ : set F)),\n  { apply cont_diff_on.prod _ _,\n    { exact (Z.coord_change_smooth_clm i j).comp cont_diff_fst.cont_diff_on\n       (prod_subset_preimage_fst _ _) },\n    { exact is_bounded_linear_map.snd.cont_diff.cont_diff_on } },\n  exact A.comp_cont_diff_on B,\nend\n\n/-- Vector bundle core associated to a basic smooth bundle core -/\ndef to_topological_vector_bundle_core : topological_vector_bundle_core \ud835\udd5c M F (atlas H M) :=\n{ base_set := \u03bb i, i.1.source,\n  is_open_base_set := \u03bb i, i.1.open_source,\n  index_at := \u03bb x, \u27e8chart_at H x, chart_mem_atlas H x\u27e9,\n  mem_base_set_at := \u03bb x, mem_chart_source H x,\n  coord_change := \u03bb i j x, Z.coord_change i j (i.1 x),\n  coord_change_self := \u03bb i x hx v, Z.coord_change_self i (i.1 x) (i.1.map_source hx) v,\n  coord_change_comp := \u03bb i j k x \u27e8\u27e8hx1, hx2\u27e9, hx3\u27e9 v, begin\n    have := Z.coord_change_comp i j k (i.1 x) _ v,\n    convert this using 2,\n    { simp only [hx1] with mfld_simps },\n    { simp only [hx1, hx2, hx3] with mfld_simps }\n  end,\n  coord_change_continuous := \u03bb i j, begin\n    refine ((Z.coord_change_continuous i j).comp' i.1.continuous_on).mono _,\n    rintros p \u27e8hp\u2081, hp\u2082\u27e9,\n    refine \u27e8hp\u2081, i.1.maps_to hp\u2081, _\u27e9,\n    simp only [i.1.left_inv hp\u2081, hp\u2082] with mfld_simps\n  end }\n\n@[simp, mfld_simps] lemma base_set (i : atlas H M) :\n  (Z.to_topological_vector_bundle_core.local_triv i).base_set = i.1.source := rfl\n\n@[simp, mfld_simps] lemma target (i : atlas H M) :\n  (Z.to_topological_vector_bundle_core.local_triv i).target = i.1.source \u00d7\u02e2 (univ : set F) := rfl\n\n/-- Local chart for the total space of a basic smooth bundle -/\ndef chart {e : local_homeomorph M H} (he : e \u2208 atlas H M) :\n  local_homeomorph (Z.to_topological_vector_bundle_core.total_space) (model_prod H F) :=\n(Z.to_topological_vector_bundle_core.local_triv \u27e8e, he\u27e9).to_local_homeomorph.trans\n  (local_homeomorph.prod e (local_homeomorph.refl F))\n\n@[simp, mfld_simps] lemma chart_source (e : local_homeomorph M H) (he : e \u2208 atlas H M) :\n  (Z.chart he).source = Z.to_topological_vector_bundle_core.proj \u207b\u00b9' e.source :=\nby { simp only [chart, mem_prod], mfld_set_tac }\n\n@[simp, mfld_simps] lemma chart_target (e : local_homeomorph M H) (he : e \u2208 atlas H M) :\n  (Z.chart he).target = e.target \u00d7\u02e2 (univ : set F) :=\nby { simp only [chart], mfld_set_tac }\n\n/-- The total space of a basic smooth bundle is endowed with a charted space structure, where the\ncharts are in bijection with the charts of the basis. -/\ninstance to_charted_space :\n  charted_space (model_prod H F) Z.to_topological_vector_bundle_core.total_space :=\n{ atlas := \u22c3(e : local_homeomorph M H) (he : e \u2208 atlas H M), {Z.chart he},\n  chart_at := \u03bb p, Z.chart (chart_mem_atlas H p.1),\n  mem_chart_source := \u03bb p, by simp [mem_chart_source],\n  chart_mem_atlas := \u03bb p, begin\n    simp only [mem_Union, mem_singleton_iff, chart_mem_atlas],\n    exact \u27e8chart_at H p.1, chart_mem_atlas H p.1, rfl\u27e9\n  end }\n\nlemma mem_atlas_iff\n  (f : local_homeomorph Z.to_topological_vector_bundle_core.total_space (model_prod H F)) :\n  f \u2208 atlas (model_prod H F) Z.to_topological_vector_bundle_core.total_space \u2194\n  \u2203(e : local_homeomorph M H) (he : e \u2208 atlas H M), f = Z.chart he :=\nby simp only [atlas, mem_Union, mem_singleton_iff]\n\n@[simp, mfld_simps] lemma mem_chart_source_iff\n  (p q : Z.to_topological_vector_bundle_core.total_space) :\n  p \u2208 (chart_at (model_prod H F) q).source \u2194 p.1 \u2208 (chart_at H q.1).source :=\nby simp only [chart_at] with mfld_simps\n\n@[simp, mfld_simps] lemma mem_chart_target_iff\n  (p : H \u00d7 F) (q : Z.to_topological_vector_bundle_core.total_space) :\n  p \u2208 (chart_at (model_prod H F) q).target \u2194 p.1 \u2208 (chart_at H q.1).target :=\nby simp only [chart_at] with mfld_simps\n\n@[simp, mfld_simps] lemma coe_chart_at_fst (p q : Z.to_topological_vector_bundle_core.total_space) :\n  ((chart_at (model_prod H F) q) p).1 = chart_at H q.1 p.1 := rfl\n\n@[simp, mfld_simps] lemma coe_chart_at_symm_fst\n  (p : H \u00d7 F) (q : Z.to_topological_vector_bundle_core.total_space) :\n  ((chart_at (model_prod H F) q).symm p).1 = ((chart_at H q.1).symm : H \u2192 M) p.1 := rfl\n\n/-- Smooth manifold structure on the total space of a basic smooth bundle -/\ninstance to_smooth_manifold :\n  smooth_manifold_with_corners (I.prod (\ud835\udcd8(\ud835\udd5c, F))) Z.to_topological_vector_bundle_core.total_space :=\nbegin\n  /- We have to check that the charts belong to the smooth groupoid, i.e., they are smooth on their\n  source, and their inverses are smooth on the target. Since both objects are of the same kind, it\n  suffices to prove the first statement in A below, and then glue back the pieces at the end. -/\n  let J := model_with_corners.to_local_equiv (I.prod (\ud835\udcd8(\ud835\udd5c, F))),\n  have A : \u2200 (e e' : local_homeomorph M H) (he : e \u2208 atlas H M) (he' : e' \u2208 atlas H M),\n    cont_diff_on \ud835\udd5c \u221e\n    (J \u2218 ((Z.chart he).symm.trans (Z.chart he')) \u2218 J.symm)\n    (J.symm \u207b\u00b9' ((Z.chart he).symm.trans (Z.chart he')).source \u2229 range J),\n  { assume e e' he he',\n    have : J.symm \u207b\u00b9' ((chart Z he).symm.trans (chart Z he')).source \u2229 range J =\n      (I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F),\n      by { simp only [J, chart, model_with_corners.prod], mfld_set_tac },\n    rw this,\n    -- check separately that the two components of the coordinate change are smooth\n    apply cont_diff_on.prod,\n    show cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F), (I \u2218 e' \u2218 e.symm \u2218 I.symm) p.1)\n         ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F)),\n    { -- the coordinate change on the base is just a coordinate change for `M`, smooth since\n      -- `M` is smooth\n      have A : cont_diff_on \ud835\udd5c \u221e (I \u2218 (e.symm.trans e') \u2218 I.symm)\n        (I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) :=\n      (has_groupoid.compatible (cont_diff_groupoid \u221e I) he he').1,\n      have B : cont_diff_on \ud835\udd5c \u221e (\u03bb p : E \u00d7 F, p.1)\n        ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F)) :=\n      cont_diff_fst.cont_diff_on,\n      exact cont_diff_on.comp A B (prod_subset_preimage_fst _ _) },\n    show cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F),\n      Z.coord_change \u27e8chart_at H (e.symm (I.symm p.1)), _\u27e9 \u27e8e', he'\u27e9\n         ((chart_at H (e.symm (I.symm p.1)) : M \u2192 H) (e.symm (I.symm p.1)))\n      (Z.coord_change \u27e8e, he\u27e9 \u27e8chart_at H (e.symm (I.symm p.1)), _\u27e9\n        (e (e.symm (I.symm p.1))) p.2))\n      ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F)),\n    { /- The coordinate change in the fiber is more complicated as its definition involves the\n      reference chart chosen at each point. However, it appears with its inverse, so using the\n      cocycle property one can get rid of it, and then conclude using the smoothness of the\n      cocycle as given in the definition of basic smooth bundles. -/\n      have := Z.coord_change_smooth \u27e8e, he\u27e9 \u27e8e', he'\u27e9,\n      rw I.image_eq at this,\n      apply cont_diff_on.congr this,\n      rintros \u27e8x, v\u27e9 hx,\n      simp only with mfld_simps at hx,\n      let f := chart_at H (e.symm (I.symm x)),\n      have A : I.symm x \u2208 ((e.symm.trans f).trans (f.symm.trans e')).source,\n        by simp only [hx.1.1, hx.1.2] with mfld_simps,\n      rw e.right_inv hx.1.1,\n      have := Z.coord_change_comp \u27e8e, he\u27e9 \u27e8f, chart_mem_atlas _ _\u27e9 \u27e8e', he'\u27e9 (I.symm x) A v,\n      simpa only [] using this } },\n  refine @smooth_manifold_with_corners.mk _ _ _ _ _ _ _ _ _ _ _ \u27e8_\u27e9,\n  assume e\u2080 e\u2080' he\u2080 he\u2080',\n  rcases (Z.mem_atlas_iff _).1 he\u2080 with \u27e8e, he, rfl\u27e9,\n  rcases (Z.mem_atlas_iff _).1 he\u2080' with \u27e8e', he', rfl\u27e9,\n  rw [cont_diff_groupoid, mem_groupoid_of_pregroupoid],\n  exact \u27e8A e e' he he', A e' e he' he\u27e9\nend\n\nend basic_smooth_vector_bundle_core\n\nsection tangent_bundle\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n\n/-- Basic smooth bundle core version of the tangent bundle of a smooth manifold `M` modelled over a\nmodel with corners `I` on `(E, H)`. The fibers are equal to `E`, and the coordinate change in the\nfiber corresponds to the derivative of the coordinate change in `M`. -/\ndef tangent_bundle_core : basic_smooth_vector_bundle_core I M E :=\n{ coord_change := \u03bb i j x, (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x)),\n  coord_change_smooth_clm := \u03bb i j,\n  begin\n    rw I.image_eq,\n    have A : cont_diff_on \ud835\udd5c \u221e\n      (I \u2218 (i.1.symm.trans j.1) \u2218 I.symm)\n      (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n      (has_groupoid.compatible (cont_diff_groupoid \u221e I) i.2 j.2).1,\n    have B : unique_diff_on \ud835\udd5c (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n      I.unique_diff_preimage_source,\n    have C : cont_diff_on \ud835\udd5c \u221e\n      (\u03bb (p : E \u00d7 E), (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) p.1 : E \u2192 E) p.2)\n      ((I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) \u00d7\u02e2 (univ : set E)) :=\n      cont_diff_on_fderiv_within_apply A B le_top,\n    have D : \u2200 x \u2208 (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I),\n      fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (range I) x =\n      fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) x,\n    { assume x hx,\n      have N : I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2208 nhds x :=\n        I.continuous_symm.continuous_at.preimage_mem_nhds\n          (is_open.mem_nhds (local_homeomorph.open_source _) hx.1),\n      symmetry,\n      rw inter_comm,\n      exact fderiv_within_inter N (I.unique_diff _ hx.2) },\n    apply (A.fderiv_within B le_top).congr,\n    assume x hx,\n    simp only with mfld_simps at hx,\n    simp only [hx, D] with mfld_simps,\n  end,\n  coord_change_self := \u03bb i x hx v, begin\n    /- Locally, a self-change of coordinate is just the identity, thus its derivative is the\n    identity. One just needs to write this carefully, paying attention to the sets where the\n    functions are defined. -/\n    have A : I.symm \u207b\u00b9' (i.1.symm.trans i.1).source \u2229 range I \u2208 \ud835\udcdd[range I] (I x),\n    { rw inter_comm,\n      apply inter_mem_nhds_within,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simp only [hx, i.1.map_target] with mfld_simps },\n    have B : \u2200\u1da0 y in \ud835\udcdd[range I] (I x),\n      (I \u2218 i.1 \u2218 i.1.symm \u2218 I.symm) y = (id : E \u2192 E) y,\n    { filter_upwards [A] with _ hy,\n      rw \u2190 I.image_eq at hy,\n      rcases hy with \u27e8z, hz\u27e9,\n      simp only with mfld_simps at hz,\n      simp only [hz.2.symm, hz.1] with mfld_simps, },\n    have C : fderiv_within \ud835\udd5c (I \u2218 i.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x) =\n             fderiv_within \ud835\udd5c (id : E \u2192 E) (range I) (I x) :=\n      filter.eventually_eq.fderiv_within_eq I.unique_diff_at_image B\n      (by simp only [hx] with mfld_simps),\n    rw fderiv_within_id I.unique_diff_at_image at C,\n    rw C,\n    refl\n  end,\n  coord_change_comp := \u03bb i j u x hx, begin\n    /- The cocycle property is just the fact that the derivative of a composition is the product of\n    the derivatives. One needs however to check that all the functions one considers are smooth, and\n    to pay attention to the domains where these functions are defined, making this proof a little\n    bit cumbersome although there is nothing complicated here. -/\n    have M : I x \u2208\n      (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I) :=\n    \u27e8by simpa only [mem_preimage, model_with_corners.left_inv] using hx, mem_range_self _\u27e9,\n    have U : unique_diff_within_at \ud835\udd5c\n      (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I) (I x) :=\n      I.unique_diff_preimage_source _ M,\n    have A : fderiv_within \ud835\udd5c ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm))\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)\n      = (fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I)\n             ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x))).comp\n        (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)),\n    { apply fderiv_within.comp _ _ _ _ U,\n      show differentiable_within_at \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n        (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n        (I x),\n      { have A : cont_diff_on \ud835\udd5c \u221e\n          (I \u2218 (i.1.symm.trans j.1) \u2218 I.symm)\n          (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n        (has_groupoid.compatible (cont_diff_groupoid \u221e I) i.2 j.2).1,\n        have B : differentiable_on \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n          (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I),\n        { apply (A.differentiable_on le_top).mono,\n          have : ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2286\n            (i.1.symm.trans j.1).source := inter_subset_left _ _,\n          exact inter_subset_inter (preimage_mono this) (subset.refl (range I)) },\n        apply B,\n        simpa only [] with mfld_simps using hx },\n      show differentiable_within_at \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n        (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I)\n        ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)),\n      { have A : cont_diff_on \ud835\udd5c \u221e\n          (I \u2218 (j.1.symm.trans u.1) \u2218 I.symm)\n          (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I) :=\n        (has_groupoid.compatible (cont_diff_groupoid \u221e I) j.2 u.2).1,\n        apply A.differentiable_on le_top,\n        rw [local_homeomorph.trans_source] at hx,\n        simp only with mfld_simps,\n        exact hx.2 },\n      show (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n        \u2286 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) \u207b\u00b9' (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I),\n      { assume y hy,\n        simp only with mfld_simps at hy,\n        rw [local_homeomorph.left_inv] at hy,\n        { simp only [hy] with mfld_simps },\n        { exact hy.1.1.2 } } },\n    have B : fderiv_within \ud835\udd5c ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n                          \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm))\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)\n             = fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x),\n    { have E :\n        \u2200 y \u2208 (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I),\n          ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)) y =\n            (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm) y,\n      { assume y hy,\n        simp only [function.comp_app, model_with_corners.left_inv],\n        rw [j.1.left_inv],\n        exact hy.1.1.2 },\n      exact fderiv_within_congr U E (E _ M) },\n    have C : fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x) =\n             fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (range I) (I x),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simpa only [model_with_corners.left_inv] using hx },\n    have D : fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n      (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I) ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)) =\n      fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) (range I) ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      rw [local_homeomorph.trans_source] at hx,\n      simp only with mfld_simps,\n      exact hx.2 },\n    have E : fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n               (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n               (I x) =\n             fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simpa only [model_with_corners.left_inv] using hx },\n    rw [B, C, D, E] at A,\n    simp only [A, continuous_linear_map.coe_comp'] with mfld_simps,\n  end }\n\nvariable {M}\ninclude I\n\n/-- The tangent space at a point of the manifold `M`. It is just `E`. We could use instead\n`(tangent_bundle_core I M).to_topological_vector_bundle_core.fiber x`, but we use `E` to help the\nkernel.\n-/\n@[nolint unused_arguments]\ndef tangent_space (x : M) : Type* := E\n\nomit I\nvariable (M)\n\n/-- The tangent bundle to a smooth manifold, as a Sigma type. Defined in terms of\n`bundle.total_space` to be able to put a suitable topology on it. -/\n@[nolint has_inhabited_instance, reducible] -- is empty if the base manifold is empty\ndef tangent_bundle := bundle.total_space (tangent_space I : M \u2192 Type*)\n\nlocal notation `TM` := tangent_bundle I M\n\n/-- The projection from the tangent bundle of a smooth manifold to the manifold. As the tangent\nbundle is represented internally as a sigma type, the notation `p.1` also works for the projection\nof the point `p`. -/\ndef tangent_bundle.proj : TM \u2192 M :=\n\u03bb p, p.1\n\nvariable {M}\n\n@[simp, mfld_simps] lemma tangent_bundle.proj_apply (x : M) (v : tangent_space I x) :\n  tangent_bundle.proj I M \u27e8x, v\u27e9 = x :=\nrfl\n\nsection tangent_bundle_instances\n\n/- In general, the definition of tangent_bundle and tangent_space are not reducible, so that type\nclass inference does not pick wrong instances. In this section, we record the right instances for\nthem, noting in particular that the tangent bundle is a smooth manifold. -/\n\nsection\nlocal attribute [reducible] tangent_space\n\nvariables {M} (x : M)\n\ninstance : topological_space (tangent_space I x) := by apply_instance\ninstance : add_comm_group (tangent_space I x) := by apply_instance\ninstance : topological_add_group (tangent_space I x) := by apply_instance\ninstance : module \ud835\udd5c (tangent_space I x) := by apply_instance\ninstance : inhabited (tangent_space I x) := \u27e80\u27e9\n\nend\n\nvariable (M)\n\ninstance : topological_space TM :=\n(tangent_bundle_core I M).to_topological_vector_bundle_core.to_topological_space (atlas H M)\n\ninstance : charted_space (model_prod H E) TM :=\n(tangent_bundle_core I M).to_charted_space\n\ninstance : smooth_manifold_with_corners I.tangent TM :=\n(tangent_bundle_core I M).to_smooth_manifold\n\ninstance : topological_vector_bundle \ud835\udd5c E (tangent_space I : M \u2192 Type*) :=\ntopological_vector_bundle_core.fiber.topological_vector_bundle\n  (tangent_bundle_core I M).to_topological_vector_bundle_core\n\nend tangent_bundle_instances\n\nvariable (M)\n\n/-- The tangent bundle projection on the basis is a continuous map. -/\nlemma tangent_bundle_proj_continuous : continuous (tangent_bundle.proj I M) :=\n((tangent_bundle_core I M).to_topological_vector_bundle_core).continuous_proj\n\n/-- The tangent bundle projection on the basis is an open map. -/\nlemma tangent_bundle_proj_open : is_open_map (tangent_bundle.proj I M) :=\n((tangent_bundle_core I M).to_topological_vector_bundle_core).is_open_map_proj\n\n/-- In the tangent bundle to the model space, the charts are just the canonical identification\nbetween a product type and a sigma type, a.k.a. `equiv.sigma_equiv_prod`. -/\n@[simp, mfld_simps] lemma tangent_bundle_model_space_chart_at (p : tangent_bundle I H) :\n  (chart_at (model_prod H E) p).to_local_equiv = (equiv.sigma_equiv_prod H E).to_local_equiv :=\nbegin\n  have A : \u2200 x_fst, fderiv_within \ud835\udd5c (I \u2218 I.symm) (range I) (I x_fst) = continuous_linear_map.id \ud835\udd5c E,\n  { assume x_fst,\n    have : fderiv_within \ud835\udd5c (I \u2218 I.symm) (range I) (I x_fst)\n         = fderiv_within \ud835\udd5c id (range I) (I x_fst),\n    { refine fderiv_within_congr I.unique_diff_at_image (\u03bb y hy, _) (by simp),\n      exact model_with_corners.right_inv _ hy },\n    rwa fderiv_within_id I.unique_diff_at_image at this },\n  ext x : 1,\n  show (chart_at (model_prod H E) p : tangent_bundle I H \u2192 model_prod H E) x =\n    (equiv.sigma_equiv_prod H E) x,\n  { cases x,\n    simp only [chart_at, basic_smooth_vector_bundle_core.chart, tangent_bundle_core,\n      basic_smooth_vector_bundle_core.to_topological_vector_bundle_core, A, prod.mk.inj_iff,\n      continuous_linear_map.coe_id'] with mfld_simps,\n      exact (tangent_bundle_core I H).coord_change_self _ _ trivial x_snd, },\n  show \u2200 x, ((chart_at (model_prod H E) p).to_local_equiv).symm x =\n    (equiv.sigma_equiv_prod H E).symm x,\n  { rintros \u27e8x_fst, x_snd\u27e9,\n    simp only [basic_smooth_vector_bundle_core.to_topological_vector_bundle_core,\n      tangent_bundle_core, A, continuous_linear_map.coe_id', basic_smooth_vector_bundle_core.chart,\n      chart_at, continuous_linear_map.coe_coe, sigma.mk.inj_iff] with mfld_simps, },\n  show ((chart_at (model_prod H E) p).to_local_equiv).source = univ,\n    by simp only [chart_at] with mfld_simps,\nend\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at (p : tangent_bundle I H) :\n  \u21d1(chart_at (model_prod H E) p) = equiv.sigma_equiv_prod H E :=\nby { unfold_coes, simp only with mfld_simps }\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at_symm (p : tangent_bundle I H) :\n  ((chart_at (model_prod H E) p).symm : model_prod H E \u2192 tangent_bundle I H) =\n  (equiv.sigma_equiv_prod H E).symm :=\nby { unfold_coes, simp only with mfld_simps }\n\nvariable (H)\n/-- The canonical identification between the tangent bundle to the model space and the product,\nas a homeomorphism -/\ndef tangent_bundle_model_space_homeomorph : tangent_bundle I H \u2243\u209c model_prod H E :=\n{ continuous_to_fun :=\n  begin\n    let p : tangent_bundle I H := \u27e8I.symm (0 : E), (0 : E)\u27e9,\n    have : continuous (chart_at (model_prod H E) p),\n    { rw continuous_iff_continuous_on_univ,\n      convert local_homeomorph.continuous_on _,\n      simp only with mfld_simps },\n    simpa only with mfld_simps using this,\n  end,\n  continuous_inv_fun :=\n  begin\n    let p : tangent_bundle I H := \u27e8I.symm (0 : E), (0 : E)\u27e9,\n    have : continuous (chart_at (model_prod H E) p).symm,\n    { rw continuous_iff_continuous_on_univ,\n      convert local_homeomorph.continuous_on _,\n      simp only with mfld_simps },\n    simpa only with mfld_simps using this,\n  end,\n  .. equiv.sigma_equiv_prod H E }\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe :\n  (tangent_bundle_model_space_homeomorph H I : tangent_bundle I H \u2192 model_prod H E)\n  = equiv.sigma_equiv_prod H E :=\nrfl\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe_symm :\n  ((tangent_bundle_model_space_homeomorph H I).symm : model_prod H E \u2192 tangent_bundle I H)\n  = (equiv.sigma_equiv_prod H E).symm :=\nrfl\n\nend tangent_bundle\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/geometry/manifold/tangent_bundle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7138576431824374}}
{"text": "/-\nCopyright (c) 2022 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\nimport group_theory.abelianization\nimport group_theory.group_action.conj_act\nimport group_theory.index\n\n/-!\n# Commuting Probability\nThis file introduces the commuting probability of finite groups.\n\n## Main definitions\n* `comm_prob`: The commuting probability of a finite type with a multiplication operation.\n\n## Todo\n* Neumann's theorem.\n-/\n\nnoncomputable theory\nopen_locale classical\nopen_locale big_operators\n\nopen fintype\n\nvariables (M : Type*) [fintype M] [has_mul M]\n\n/-- The commuting probability of a finite type with a multiplication operation -/\ndef comm_prob : \u211a := card {p : M \u00d7 M // p.1 * p.2 = p.2 * p.1} / card M ^ 2\n\nlemma comm_prob_def : comm_prob M = card {p : M \u00d7 M // p.1 * p.2 = p.2 * p.1} / card M ^ 2 :=\nrfl\n\nlemma comm_prob_pos [h : nonempty M] : 0 < comm_prob M :=\nh.elim (\u03bb x, div_pos (nat.cast_pos.mpr (card_pos_iff.mpr \u27e8\u27e8(x, x), rfl\u27e9\u27e9))\n  (pow_pos (nat.cast_pos.mpr card_pos) 2))\n\nlemma comm_prob_le_one : comm_prob M \u2264 1 :=\nbegin\n  refine div_le_one_of_le _ (sq_nonneg (card M)),\n  rw [\u2190nat.cast_pow, nat.cast_le, sq, \u2190card_prod],\n  apply set_fintype_card_le_univ,\nend\n\nvariables {M}\n\nlemma comm_prob_eq_one_iff [h : nonempty M] : comm_prob M = 1 \u2194 commutative ((*) : M \u2192 M \u2192 M) :=\nbegin\n  change (card {p : M \u00d7 M | p.1 * p.2 = p.2 * p.1} : \u211a) / _ = 1 \u2194 _,\n  rw [div_eq_one_iff_eq, \u2190nat.cast_pow, nat.cast_inj, sq, \u2190card_prod,\n      set_fintype_card_eq_univ_iff, set.eq_univ_iff_forall],\n  { exact \u27e8\u03bb h x y, h (x, y), \u03bb h x, h x.1 x.2\u27e9 },\n  { exact pow_ne_zero 2 (nat.cast_ne_zero.mpr card_ne_zero) },\nend\n\nvariables (G : Type*) [group G] [fintype G]\n\nlemma card_comm_eq_card_conj_classes_mul_card :\n  card {p : G \u00d7 G // p.1 * p.2 = p.2 * p.1} = card (conj_classes G) * card G :=\ncalc card {p : G \u00d7 G // p.1 * p.2 = p.2 * p.1} = card (\u03a3 g, {h // g * h = h * g}) :\n  card_congr (equiv.subtype_prod_equiv_sigma_subtype (\u03bb g h : G, g * h = h * g))\n... = \u2211 g, card {h // g * h = h * g} : card_sigma _\n... = \u2211 g, card (mul_action.fixed_by (conj_act G) G g) : sum_equiv conj_act.to_conj_act.to_equiv\n  _ _ (\u03bb g, card_congr' $ congr_arg _ $ funext $ \u03bb h, mul_inv_eq_iff_eq_mul.symm.to_eq)\n... = card (quotient (mul_action.orbit_rel (conj_act G) G)) * card G :\n  mul_action.sum_card_fixed_by_eq_card_orbits_mul_card_group (conj_act G) G\n... = card (quotient (is_conj.setoid G)) * card G :\n  have this : mul_action.orbit_rel (conj_act G) G = is_conj.setoid G :=\n    setoid.ext (\u03bb g h, (setoid.comm' _).trans is_conj_iff.symm),\n  by cc\n\nlemma comm_prob_def' : comm_prob G = card (conj_classes G) / card G :=\nbegin\n  rw [comm_prob, card_comm_eq_card_conj_classes_mul_card, nat.cast_mul, sq],\n  exact mul_div_mul_right (card (conj_classes G)) (card G) (nat.cast_ne_zero.mpr card_ne_zero),\nend\n\nvariables {G} (H : subgroup G)\n\nlemma subgroup.comm_prob_subgroup_le : comm_prob H \u2264 comm_prob G * H.index ^ 2 :=\nbegin\n  /- After rewriting with `comm_prob_def`, we reduce to showing that `G` has at least as many\n    commuting pairs as `H`. -/\n  rw [comm_prob_def, comm_prob_def, div_le_iff, mul_assoc, \u2190mul_pow, \u2190nat.cast_mul,\n      H.index_mul_card, div_mul_cancel, nat.cast_le],\n  { apply card_le_of_injective _ _,\n    exact \u03bb p, \u27e8\u27e8p.1.1, p.1.2\u27e9, subtype.ext_iff.mp p.2\u27e9,\n    exact \u03bb p q h, by simpa only [subtype.ext_iff, prod.ext_iff] using h },\n  { exact pow_ne_zero 2 (nat.cast_ne_zero.mpr card_ne_zero) },\n  { exact pow_pos (nat.cast_pos.mpr card_pos) 2 },\nend\n\nlemma subgroup.comm_prob_quotient_le [H.normal] : comm_prob (G \u29f8 H) \u2264 comm_prob G * card H :=\nbegin\n  /- After rewriting with `comm_prob_def'`, we reduce to showing that `G` has at least as many\n    conjugacy classes as `G \u29f8 H`. -/\n  rw [comm_prob_def', comm_prob_def', div_le_iff, mul_assoc, \u2190nat.cast_mul, mul_comm (card H),\n      \u2190subgroup.card_eq_card_quotient_mul_card_subgroup, div_mul_cancel, nat.cast_le],\n  { exact card_le_of_surjective (conj_classes.map (quotient_group.mk' H))\n      (conj_classes.map_surjective quotient.surjective_quotient_mk') },\n  { exact nat.cast_ne_zero.mpr card_ne_zero },\n  { exact nat.cast_pos.mpr card_pos },\nend\n\nvariables (G)\n\nlemma inv_card_commutator_le_comm_prob : (\u2191(card (commutator G)))\u207b\u00b9 \u2264 comm_prob G :=\n(inv_pos_le_iff_one_le_mul (by exact nat.cast_pos.mpr card_pos)).mpr\n  (le_trans (ge_of_eq (comm_prob_eq_one_iff.mpr (abelianization.comm_group G).mul_comm))\n    (commutator G).comm_prob_quotient_le)\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/group_theory/commuting_probability.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7138410122884064}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland, Yury Kudryashov\n\n! This file was ported from Lean 3 source module algebra.group.commute\n! leanprover-community/mathlib commit 05101c3df9d9cfe9430edc205860c79b6d660102\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Group.Semiconj\n\n/-!\n# Commuting pairs of elements in monoids\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define the predicate `commute a b := a * b = b * a` and provide some operations on terms `(h :\ncommute a b)`. E.g., if `a`, `b`, and c are elements of a semiring, and that `hb : commute a b` and\n`hc : commute a c`.  Then `hb.pow_left 5` proves `commute (a ^ 5) b` and `(hb.pow_right 2).add_right\n(hb.mul_right hc)` proves `commute a (b ^ 2 + b * c)`.\n\nLean does not immediately recognise these terms as equations, so for rewriting we need syntax like\n`rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`.\n\nThis file defines only a few operations (`mul_left`, `inv_right`, etc).  Other operations\n(`pow_right`, field inverse etc) are in the files that define corresponding notions.\n\n## Implementation details\n\nMost of the proofs come from the properties of `semiconj_by`.\n-/\n\n\nvariable {G : Type _}\n\n#print Commute /-\n/-- Two elements commute if `a * b = b * a`. -/\n@[to_additive AddCommute \"Two elements additively commute if `a + b = b + a`\"]\ndef Commute {S : Type _} [Mul S] (a b : S) : Prop :=\n  SemiconjBy a b b\n#align commute Commute\n#align add_commute AddCommute\n-/\n\nnamespace Commute\n\nsection Mul\n\nvariable {S : Type _} [Mul S]\n\n#print Commute.eq /-\n/-- Equality behind `commute a b`; useful for rewriting. -/\n@[to_additive \"Equality behind `add_commute a b`; useful for rewriting.\"]\nprotected theorem eq {a b : S} (h : Commute a b) : a * b = b * a :=\n  h\n#align commute.eq Commute.eq\n#align add_commute.eq AddCommute.eq\n-/\n\n#print Commute.refl /-\n/-- Any element commutes with itself. -/\n@[refl, simp, to_additive \"Any element commutes with itself.\"]\nprotected theorem refl (a : S) : Commute a a :=\n  Eq.refl (a * a)\n#align commute.refl Commute.refl\n#align add_commute.refl AddCommute.refl\n-/\n\n#print Commute.symm /-\n/-- If `a` commutes with `b`, then `b` commutes with `a`. -/\n@[symm, to_additive \"If `a` commutes with `b`, then `b` commutes with `a`.\"]\nprotected theorem symm {a b : S} (h : Commute a b) : Commute b a :=\n  Eq.symm h\n#align commute.symm Commute.symm\n#align add_commute.symm AddCommute.symm\n-/\n\n#print Commute.semiconjBy /-\n@[to_additive]\nprotected theorem semiconjBy {a b : S} (h : Commute a b) : SemiconjBy a b b :=\n  h\n#align commute.semiconj_by Commute.semiconjBy\n#align add_commute.semiconj_by AddCommute.semiconjBy\n-/\n\n#print Commute.symm_iff /-\n@[to_additive]\nprotected theorem symm_iff {a b : S} : Commute a b \u2194 Commute b a :=\n  \u27e8Commute.symm, Commute.symm\u27e9\n#align commute.symm_iff Commute.symm_iff\n#align add_commute.symm_iff AddCommute.symm_iff\n-/\n\n@[to_additive]\ninstance : IsRefl S Commute :=\n  \u27e8Commute.refl\u27e9\n\n#print Commute.on_isRefl /-\n-- This instance is useful for `finset.noncomm_prod`\n@[to_additive]\ninstance on_isRefl {f : G \u2192 S} : IsRefl G fun a b => Commute (f a) (f b) :=\n  \u27e8fun _ => Commute.refl _\u27e9\n#align commute.on_is_refl Commute.on_isRefl\n#align add_commute.on_is_refl AddCommute.on_isRefl\n-/\n\nend Mul\n\nsection Semigroup\n\nvariable {S : Type _} [Semigroup S] {a b c : S}\n\n/-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/\n@[simp, to_additive \"If `a` commutes with both `b` and `c`, then it commutes with their sum.\"]\ntheorem mul_right (hab : Commute a b) (hac : Commute a c) : Commute a (b * c) :=\n  hab.mul_right hac\n#align commute.mul_right Commute.mul_right\u2093\n#align add_commute.add_right AddCommute.add_right\u2093\n\n/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/\n@[simp, to_additive \"If both `a` and `b` commute with `c`, then their product commutes with `c`.\"]\ntheorem mul_left (hac : Commute a c) (hbc : Commute b c) : Commute (a * b) c :=\n  hac.mul_left hbc\n#align commute.mul_left Commute.mul_left\u2093\n#align add_commute.add_left AddCommute.add_left\u2093\n\n@[to_additive]\nprotected theorem right_comm (h : Commute b c) (a : S) : a * b * c = a * c * b := by\n  simp only [mul_assoc, h.eq]\n#align commute.right_comm Commute.right_comm\u2093\n#align add_commute.right_comm AddCommute.right_comm\u2093\n\n@[to_additive]\nprotected theorem left_comm (h : Commute a b) (c) : a * (b * c) = b * (a * c) := by\n  simp only [\u2190 mul_assoc, h.eq]\n#align commute.left_comm Commute.left_comm\u2093\n#align add_commute.left_comm AddCommute.left_comm\u2093\n\n/- warning: commute.mul_mul_mul_comm -> Commute.mul_mul_mul_comm is a dubious translation:\nlean 3 declaration is\n  forall {S : Type.{u1}} [_inst_1 : Semigroup.{u1} S] {b : S} {c : S}, (Commute.{u1} S (Semigroup.toHasMul.{u1} S _inst_1) b c) -> (forall (a : S) (d : S), Eq.{succ u1} S (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toHasMul.{u1} S _inst_1)) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toHasMul.{u1} S _inst_1)) a b) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toHasMul.{u1} S _inst_1)) c d)) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toHasMul.{u1} S _inst_1)) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toHasMul.{u1} S _inst_1)) a c) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toHasMul.{u1} S _inst_1)) b d)))\nbut is expected to have type\n  forall {S : Type.{u1}} [_inst_1 : Semigroup.{u1} S] {b : S} {c : S}, (Commute.{u1} S (Semigroup.toMul.{u1} S _inst_1) b c) -> (forall (a : S) (d : S), Eq.{succ u1} S (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toMul.{u1} S _inst_1)) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toMul.{u1} S _inst_1)) a b) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toMul.{u1} S _inst_1)) c d)) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toMul.{u1} S _inst_1)) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toMul.{u1} S _inst_1)) a c) (HMul.hMul.{u1, u1, u1} S S S (instHMul.{u1} S (Semigroup.toMul.{u1} S _inst_1)) b d)))\nCase conversion may be inaccurate. Consider using '#align commute.mul_mul_mul_comm Commute.mul_mul_mul_comm\u2093'. -/\n@[to_additive]\nprotected theorem mul_mul_mul_comm (hbc : Commute b c) (a d : S) :\n    a * b * (c * d) = a * c * (b * d) := by simp only [hbc.left_comm, mul_assoc]\n#align commute.mul_mul_mul_comm Commute.mul_mul_mul_comm\n#align add_commute.add_add_add_comm AddCommute.add_add_add_comm\n\nend Semigroup\n\n@[to_additive]\nprotected theorem all {S : Type _} [CommSemigroup S] (a b : S) : Commute a b :=\n  mul_comm a b\n#align commute.all Commute.all\u2093\n#align add_commute.all AddCommute.all\u2093\n\nsection MulOneClass\n\nvariable {M : Type _} [MulOneClass M]\n\n@[simp, to_additive]\ntheorem one_right (a : M) : Commute a 1 :=\n  SemiconjBy.one_right a\n#align commute.one_right Commute.one_right\u2093\n#align add_commute.zero_right AddCommute.zero_right\u2093\n\n@[simp, to_additive]\ntheorem one_left (a : M) : Commute 1 a :=\n  SemiconjBy.one_left a\n#align commute.one_left Commute.one_left\u2093\n#align add_commute.zero_left AddCommute.zero_left\u2093\n\nend MulOneClass\n\nsection Monoid\n\nvariable {M : Type _} [Monoid M] {a b : M} {u u\u2081 u\u2082 : M\u02e3}\n\n@[simp, to_additive]\ntheorem pow_right (h : Commute a b) (n : \u2115) : Commute a (b ^ n) :=\n  h.pow_right n\n#align commute.pow_right Commute.pow_right\u2093\n#align add_commute.nsmul_right AddCommute.nsmul_right\u2093\n\n@[simp, to_additive]\ntheorem pow_left (h : Commute a b) (n : \u2115) : Commute (a ^ n) b :=\n  (h.symm.pow_right n).symm\n#align commute.pow_left Commute.pow_left\u2093\n#align add_commute.nsmul_left AddCommute.nsmul_left\u2093\n\n@[simp, to_additive]\ntheorem pow_pow (h : Commute a b) (m n : \u2115) : Commute (a ^ m) (b ^ n) :=\n  (h.pow_left\u2093 m).pow_right n\n#align commute.pow_pow Commute.pow_pow\u2093\n#align add_commute.nsmul_nsmul AddCommute.nsmul_nsmul\u2093\n\n@[simp, to_additive]\ntheorem self_pow (a : M) (n : \u2115) : Commute a (a ^ n) :=\n  (Commute.refl a).pow_right n\n#align commute.self_pow Commute.self_pow\u2093\n#align add_commute.self_nsmul AddCommute.self_nsmul\u2093\n\n/- warning: commute.pow_self -> Commute.pow_self is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (a : M) (n : Nat), Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M _inst_1)) a n) a\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (a : M) (n : Nat), Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M _inst_1)) a n) a\nCase conversion may be inaccurate. Consider using '#align commute.pow_self Commute.pow_self\u2093'. -/\n@[simp, to_additive]\ntheorem pow_self (a : M) (n : \u2115) : Commute (a ^ n) a :=\n  (Commute.refl a).pow_left\u2093 n\n#align commute.pow_self Commute.pow_self\n\n@[simp, to_additive]\ntheorem pow_pow_self (a : M) (m n : \u2115) : Commute (a ^ m) (a ^ n) :=\n  (Commute.refl a).pow_pow\u2093 m n\n#align commute.pow_pow_self Commute.pow_pow_self\u2093\n#align add_commute.nsmul_nsmul_self AddCommute.nsmul_nsmul_self\u2093\n\n/- warning: pow_succ' -> pow_succ' is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (a : M) (n : Nat), Eq.{succ u1} M (HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M _inst_1)) a (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) (HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M _inst_1)) a n) a)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (a : M) (n : Nat), Eq.{succ u1} M (HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M _inst_1)) a (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) (HPow.hPow.{u1, 0, u1} M Nat M (instHPow.{u1, 0} M Nat (Monoid.Pow.{u1} M _inst_1)) a n) a)\nCase conversion may be inaccurate. Consider using '#align pow_succ' pow_succ'\u2093'. -/\n@[to_additive succ_nsmul']\ntheorem pow_succ' (a : M) (n : \u2115) : a ^ (n + 1) = a ^ n * a :=\n  (pow_succ a n).trans (self_pow _ _)\n#align pow_succ' pow_succ'\n#align succ_nsmul' succ_nsmul'\n\n/- warning: commute.units_inv_right -> Commute.units_inv_right is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u)) -> (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.hasInv.{u1} M _inst_1) u)))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a (Units.val.{u1} M _inst_1 u)) -> (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a (Units.val.{u1} M _inst_1 (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.instInvUnits.{u1} M _inst_1) u)))\nCase conversion may be inaccurate. Consider using '#align commute.units_inv_right Commute.units_inv_right\u2093'. -/\n@[to_additive]\ntheorem units_inv_right : Commute a u \u2192 Commute a \u2191u\u207b\u00b9 :=\n  SemiconjBy.units_inv_right\n#align commute.units_inv_right Commute.units_inv_right\n#align add_commute.add_units_neg_right AddCommute.addUnits_neg_right\n\n/- warning: commute.units_inv_right_iff -> Commute.units_inv_right_iff is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, Iff (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.hasInv.{u1} M _inst_1) u))) (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, Iff (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a (Units.val.{u1} M _inst_1 (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.instInvUnits.{u1} M _inst_1) u))) (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a (Units.val.{u1} M _inst_1 u))\nCase conversion may be inaccurate. Consider using '#align commute.units_inv_right_iff Commute.units_inv_right_iff\u2093'. -/\n@[simp, to_additive]\ntheorem units_inv_right_iff : Commute a \u2191u\u207b\u00b9 \u2194 Commute a u :=\n  SemiconjBy.units_inv_right_iff\n#align commute.units_inv_right_iff Commute.units_inv_right_iff\n#align add_commute.add_units_neg_right_iff AddCommute.addUnits_neg_right_iff\n\n/- warning: commute.units_inv_left -> Commute.units_inv_left is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u) a) -> (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.hasInv.{u1} M _inst_1) u)) a)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (Units.val.{u1} M _inst_1 u) a) -> (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (Units.val.{u1} M _inst_1 (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.instInvUnits.{u1} M _inst_1) u)) a)\nCase conversion may be inaccurate. Consider using '#align commute.units_inv_left Commute.units_inv_left\u2093'. -/\n@[to_additive]\ntheorem units_inv_left : Commute (\u2191u) a \u2192 Commute (\u2191u\u207b\u00b9) a :=\n  SemiconjBy.units_inv_symm_left\n#align commute.units_inv_left Commute.units_inv_left\n#align add_commute.add_units_neg_left AddCommute.addUnits_neg_left\n\n/- warning: commute.units_inv_left_iff -> Commute.units_inv_left_iff is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, Iff (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.hasInv.{u1} M _inst_1) u)) a) (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u) a)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {u : Units.{u1} M _inst_1}, Iff (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (Units.val.{u1} M _inst_1 (Inv.inv.{u1} (Units.{u1} M _inst_1) (Units.instInvUnits.{u1} M _inst_1) u)) a) (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (Units.val.{u1} M _inst_1 u) a)\nCase conversion may be inaccurate. Consider using '#align commute.units_inv_left_iff Commute.units_inv_left_iff\u2093'. -/\n@[simp, to_additive]\ntheorem units_inv_left_iff : Commute (\u2191u\u207b\u00b9) a \u2194 Commute (\u2191u) a :=\n  SemiconjBy.units_inv_symm_left_iff\n#align commute.units_inv_left_iff Commute.units_inv_left_iff\n#align add_commute.add_units_neg_left_iff AddCommute.addUnits_neg_left_iff\n\n/- warning: commute.units_coe -> Commute.units_val is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {u\u2081 : Units.{u1} M _inst_1} {u\u2082 : Units.{u1} M _inst_1}, (Commute.{u1} (Units.{u1} M _inst_1) (MulOneClass.toHasMul.{u1} (Units.{u1} M _inst_1) (Units.mulOneClass.{u1} M _inst_1)) u\u2081 u\u2082) -> (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u\u2081) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u\u2082))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {u\u2081 : Units.{u1} M _inst_1} {u\u2082 : Units.{u1} M _inst_1}, (Commute.{u1} (Units.{u1} M _inst_1) (MulOneClass.toMul.{u1} (Units.{u1} M _inst_1) (Units.instMulOneClassUnits.{u1} M _inst_1)) u\u2081 u\u2082) -> (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (Units.val.{u1} M _inst_1 u\u2081) (Units.val.{u1} M _inst_1 u\u2082))\nCase conversion may be inaccurate. Consider using '#align commute.units_coe Commute.units_val\u2093'. -/\n@[to_additive]\ntheorem units_val : Commute u\u2081 u\u2082 \u2192 Commute (u\u2081 : M) u\u2082 :=\n  SemiconjBy.units_val\n#align commute.units_coe Commute.units_val\n#align add_commute.add_units_coe AddCommute.addUnits_val\n\n/- warning: commute.units_of_coe -> Commute.units_of_val is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {u\u2081 : Units.{u1} M _inst_1} {u\u2082 : Units.{u1} M _inst_1}, (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u\u2081) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u\u2082)) -> (Commute.{u1} (Units.{u1} M _inst_1) (MulOneClass.toHasMul.{u1} (Units.{u1} M _inst_1) (Units.mulOneClass.{u1} M _inst_1)) u\u2081 u\u2082)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {u\u2081 : Units.{u1} M _inst_1} {u\u2082 : Units.{u1} M _inst_1}, (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (Units.val.{u1} M _inst_1 u\u2081) (Units.val.{u1} M _inst_1 u\u2082)) -> (Commute.{u1} (Units.{u1} M _inst_1) (MulOneClass.toMul.{u1} (Units.{u1} M _inst_1) (Units.instMulOneClassUnits.{u1} M _inst_1)) u\u2081 u\u2082)\nCase conversion may be inaccurate. Consider using '#align commute.units_of_coe Commute.units_of_val\u2093'. -/\n@[to_additive]\ntheorem units_of_val : Commute (u\u2081 : M) u\u2082 \u2192 Commute u\u2081 u\u2082 :=\n  SemiconjBy.units_of_val\n#align commute.units_of_coe Commute.units_of_val\n#align add_commute.add_units_of_coe AddCommute.addUnits_of_val\n\n/- warning: commute.units_coe_iff -> Commute.units_val_iff is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {u\u2081 : Units.{u1} M _inst_1} {u\u2082 : Units.{u1} M _inst_1}, Iff (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u\u2081) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u\u2082)) (Commute.{u1} (Units.{u1} M _inst_1) (MulOneClass.toHasMul.{u1} (Units.{u1} M _inst_1) (Units.mulOneClass.{u1} M _inst_1)) u\u2081 u\u2082)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {u\u2081 : Units.{u1} M _inst_1} {u\u2082 : Units.{u1} M _inst_1}, Iff (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) (Units.val.{u1} M _inst_1 u\u2081) (Units.val.{u1} M _inst_1 u\u2082)) (Commute.{u1} (Units.{u1} M _inst_1) (MulOneClass.toMul.{u1} (Units.{u1} M _inst_1) (Units.instMulOneClassUnits.{u1} M _inst_1)) u\u2081 u\u2082)\nCase conversion may be inaccurate. Consider using '#align commute.units_coe_iff Commute.units_val_iff\u2093'. -/\n@[simp, to_additive]\ntheorem units_val_iff : Commute (u\u2081 : M) u\u2082 \u2194 Commute u\u2081 u\u2082 :=\n  SemiconjBy.units_val_iff\n#align commute.units_coe_iff Commute.units_val_iff\n#align add_commute.add_units_coe_iff AddCommute.addUnits_val_iff\n\n/- warning: units.left_of_mul -> Units.leftOfMul is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (u : Units.{u1} M _inst_1) (a : M) (b : M), (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a b) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u)) -> (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a b) -> (Units.{u1} M _inst_1)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (u : Units.{u1} M _inst_1) (a : M) (b : M), (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a b) (Units.val.{u1} M _inst_1 u)) -> (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a b) -> (Units.{u1} M _inst_1)\nCase conversion may be inaccurate. Consider using '#align units.left_of_mul Units.leftOfMul\u2093'. -/\n/-- If the product of two commuting elements is a unit, then the left multiplier is a unit. -/\n@[to_additive\n      \"If the sum of two commuting elements is an additive unit, then the left summand is an\\nadditive unit.\"]\ndef Units.leftOfMul (u : M\u02e3) (a b : M) (hu : a * b = u) (hc : Commute a b) : M\u02e3\n    where\n  val := a\n  inv := b * \u2191u\u207b\u00b9\n  val_inv := by rw [\u2190 mul_assoc, hu, u.mul_inv]\n  inv_val := by\n    have : Commute a u := hu \u25b8 (Commute.refl _).mul_right hc\n    rw [\u2190 this.units_inv_right.right_comm, \u2190 hc.eq, hu, u.mul_inv]\n#align units.left_of_mul Units.leftOfMul\n#align add_units.left_of_add AddUnits.leftOfAdd\n\n/- warning: units.right_of_mul -> Units.rightOfMul is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (u : Units.{u1} M _inst_1) (a : M) (b : M), (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a b) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} M _inst_1) M (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} M _inst_1) M (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} M _inst_1) M (coeBase.{succ u1, succ u1} (Units.{u1} M _inst_1) M (Units.hasCoe.{u1} M _inst_1)))) u)) -> (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a b) -> (Units.{u1} M _inst_1)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] (u : Units.{u1} M _inst_1) (a : M) (b : M), (Eq.{succ u1} M (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a b) (Units.val.{u1} M _inst_1 u)) -> (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a b) -> (Units.{u1} M _inst_1)\nCase conversion may be inaccurate. Consider using '#align units.right_of_mul Units.rightOfMul\u2093'. -/\n/-- If the product of two commuting elements is a unit, then the right multiplier is a unit. -/\n@[to_additive\n      \"If the sum of two commuting elements is an additive unit, then the right summand is\\nan additive unit.\"]\ndef Units.rightOfMul (u : M\u02e3) (a b : M) (hu : a * b = u) (hc : Commute a b) : M\u02e3 :=\n  u.leftOfMul b a (hc.Eq \u25b8 hu) hc.symm\n#align units.right_of_mul Units.rightOfMul\n#align add_units.right_of_add AddUnits.rightOfAdd\n\n/- warning: commute.is_unit_mul_iff -> Commute.isUnit_mul_iff is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {b : M}, (Commute.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a b) -> (Iff (IsUnit.{u1} M _inst_1 (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a b)) (And (IsUnit.{u1} M _inst_1 a) (IsUnit.{u1} M _inst_1 b)))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M} {b : M}, (Commute.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1)) a b) -> (Iff (IsUnit.{u1} M _inst_1 (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a b)) (And (IsUnit.{u1} M _inst_1 a) (IsUnit.{u1} M _inst_1 b)))\nCase conversion may be inaccurate. Consider using '#align commute.is_unit_mul_iff Commute.isUnit_mul_iff\u2093'. -/\n@[to_additive]\ntheorem isUnit_mul_iff (h : Commute a b) : IsUnit (a * b) \u2194 IsUnit a \u2227 IsUnit b :=\n  \u27e8fun \u27e8u, hu\u27e9 => \u27e8(u.leftOfMul a b hu.symm h).IsUnit, (u.rightOfMul a b hu.symm h).IsUnit\u27e9,\n    fun H => H.1.mul H.2\u27e9\n#align commute.is_unit_mul_iff Commute.isUnit_mul_iff\n#align add_commute.is_add_unit_add_iff AddCommute.isAddUnit_add_iff\n\n/- warning: is_unit_mul_self_iff -> isUnit_mul_self_iff is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M}, Iff (IsUnit.{u1} M _inst_1 (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toHasMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a a)) (IsUnit.{u1} M _inst_1 a)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Monoid.{u1} M] {a : M}, Iff (IsUnit.{u1} M _inst_1 (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (MulOneClass.toMul.{u1} M (Monoid.toMulOneClass.{u1} M _inst_1))) a a)) (IsUnit.{u1} M _inst_1 a)\nCase conversion may be inaccurate. Consider using '#align is_unit_mul_self_iff isUnit_mul_self_iff\u2093'. -/\n@[simp, to_additive]\ntheorem isUnit_mul_self_iff : IsUnit (a * a) \u2194 IsUnit a :=\n  (Commute.refl a).isUnit_mul_iff.trans (and_self_iff _)\n#align is_unit_mul_self_iff isUnit_mul_self_iff\n#align is_add_unit_add_self_iff isAddUnit_add_self_iff\n\nend Monoid\n\nsection DivisionMonoid\n\nvariable [DivisionMonoid G] {a b c d : G}\n\n/- warning: commute.inv_inv -> Commute.inv_inv is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) a) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) b))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) a) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) b))\nCase conversion may be inaccurate. Consider using '#align commute.inv_inv Commute.inv_inv\u2093'. -/\n@[to_additive]\nprotected theorem inv_inv : Commute a b \u2192 Commute a\u207b\u00b9 b\u207b\u00b9 :=\n  SemiconjBy.inv_inv_symm\n#align commute.inv_inv Commute.inv_inv\n#align add_commute.neg_neg AddCommute.neg_neg\n\n/- warning: commute.inv_inv_iff -> Commute.inv_inv_iff is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, Iff (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) a) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) b)) (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, Iff (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) a) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) b)) (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b)\nCase conversion may be inaccurate. Consider using '#align commute.inv_inv_iff Commute.inv_inv_iff\u2093'. -/\n@[simp, to_additive]\ntheorem inv_inv_iff : Commute a\u207b\u00b9 b\u207b\u00b9 \u2194 Commute a b :=\n  SemiconjBy.inv_inv_symm_iff\n#align commute.inv_inv_iff Commute.inv_inv_iff\n#align add_commute.neg_neg_iff AddCommute.neg_neg_iff\n\n/- warning: commute.mul_inv -> Commute.mul_inv is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a b)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) a) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) b)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a b)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) a) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) b)))\nCase conversion may be inaccurate. Consider using '#align commute.mul_inv Commute.mul_inv\u2093'. -/\n@[to_additive]\nprotected theorem mul_inv (hab : Commute a b) : (a * b)\u207b\u00b9 = a\u207b\u00b9 * b\u207b\u00b9 := by rw [hab.eq, mul_inv_rev]\n#align commute.mul_inv Commute.mul_inv\n#align add_commute.add_neg AddCommute.add_neg\n\n/- warning: commute.inv -> Commute.inv is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a b)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) a) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) b)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a b)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) a) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) b)))\nCase conversion may be inaccurate. Consider using '#align commute.inv Commute.inv\u2093'. -/\n@[to_additive]\nprotected theorem inv (hab : Commute a b) : (a * b)\u207b\u00b9 = a\u207b\u00b9 * b\u207b\u00b9 := by rw [hab.eq, mul_inv_rev]\n#align commute.inv Commute.inv\n#align add_commute.neg AddCommute.neg\n\n/- warning: commute.div_mul_div_comm -> Commute.div_mul_div_comm is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G} {c : G} {d : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) b d) -> (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) b) c) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a b) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) c d)) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a c) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) b d)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G} {c : G} {d : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) b d) -> (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) b) c) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a b) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) c d)) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a c) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) b d)))\nCase conversion may be inaccurate. Consider using '#align commute.div_mul_div_comm Commute.div_mul_div_comm\u2093'. -/\n@[to_additive]\nprotected theorem div_mul_div_comm (hbd : Commute b d) (hbc : Commute b\u207b\u00b9 c) :\n    a / b * (c / d) = a * c / (b * d) := by\n  simp_rw [div_eq_mul_inv, mul_inv_rev, hbd.inv_inv.symm.eq, hbc.mul_mul_mul_comm]\n#align commute.div_mul_div_comm Commute.div_mul_div_comm\n#align add_commute.sub_add_sub_comm AddCommute.sub_add_sub_comm\n\n/- warning: commute.mul_div_mul_comm -> Commute.mul_div_mul_comm is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G} {c : G} {d : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) c d) -> (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) b (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) c)) -> (Eq.{succ u1} G (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a b) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) c d)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a c) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) b d)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G} {c : G} {d : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) c d) -> (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) b (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) c)) -> (Eq.{succ u1} G (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) a b) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) c d)) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a c) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) b d)))\nCase conversion may be inaccurate. Consider using '#align commute.mul_div_mul_comm Commute.mul_div_mul_comm\u2093'. -/\n@[to_additive]\nprotected theorem mul_div_mul_comm (hcd : Commute c d) (hbc : Commute b c\u207b\u00b9) :\n    a * b / (c * d) = a / c * (b / d) :=\n  (hcd.div_mul_div_comm hbc.symm).symm\n#align commute.mul_div_mul_comm Commute.mul_div_mul_comm\n#align add_commute.add_sub_add_comm AddCommute.add_sub_add_comm\n\n/- warning: commute.div_div_div_comm -> Commute.div_div_div_comm is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G} {c : G} {d : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) b c) -> (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) b) d) -> (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)) c) d) -> (Eq.{succ u1} G (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a b) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) c d)) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a c) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toHasDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) b d)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} G] {a : G} {b : G} {c : G} {d : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) b c) -> (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) b) d) -> (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G _inst_1))) c) d) -> (Eq.{succ u1} G (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a b) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) c d)) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) a c) (HDiv.hDiv.{u1, u1, u1} G G G (instHDiv.{u1} G (DivInvMonoid.toDiv.{u1} G (DivisionMonoid.toDivInvMonoid.{u1} G _inst_1))) b d)))\nCase conversion may be inaccurate. Consider using '#align commute.div_div_div_comm Commute.div_div_div_comm\u2093'. -/\n@[to_additive]\nprotected theorem div_div_div_comm (hbc : Commute b c) (hbd : Commute b\u207b\u00b9 d) (hcd : Commute c\u207b\u00b9 d) :\n    a / b / (c / d) = a / c / (b / d) := by\n  simp_rw [div_eq_mul_inv, mul_inv_rev, inv_inv, hbd.symm.eq, hcd.symm.eq,\n    hbc.inv_inv.mul_mul_mul_comm]\n#align commute.div_div_div_comm Commute.div_div_div_comm\n#align add_commute.sub_sub_sub_comm AddCommute.sub_sub_sub_comm\n\nend DivisionMonoid\n\nsection Group\n\nvariable [Group G] {a b : G}\n\n/- warning: commute.inv_right -> Commute.inv_right is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) b))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) b))\nCase conversion may be inaccurate. Consider using '#align commute.inv_right Commute.inv_right\u2093'. -/\n@[to_additive]\ntheorem inv_right : Commute a b \u2192 Commute a b\u207b\u00b9 :=\n  SemiconjBy.inv_right\n#align commute.inv_right Commute.inv_right\n#align add_commute.neg_right AddCommute.neg_right\n\n/- warning: commute.inv_right_iff -> Commute.inv_right_iff is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, Iff (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) b)) (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, Iff (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) b)) (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b)\nCase conversion may be inaccurate. Consider using '#align commute.inv_right_iff Commute.inv_right_iff\u2093'. -/\n@[simp, to_additive]\ntheorem inv_right_iff : Commute a b\u207b\u00b9 \u2194 Commute a b :=\n  SemiconjBy.inv_right_iff\n#align commute.inv_right_iff Commute.inv_right_iff\n#align add_commute.neg_right_iff AddCommute.neg_right_iff\n\n/- warning: commute.inv_left -> Commute.inv_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) a) b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) a) b)\nCase conversion may be inaccurate. Consider using '#align commute.inv_left Commute.inv_left\u2093'. -/\n@[to_additive]\ntheorem inv_left : Commute a b \u2192 Commute a\u207b\u00b9 b :=\n  SemiconjBy.inv_symm_left\n#align commute.inv_left Commute.inv_left\n#align add_commute.neg_left AddCommute.neg_left\n\n/- warning: commute.inv_left_iff -> Commute.inv_left_iff is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, Iff (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) a) b) (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, Iff (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) a) b) (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b)\nCase conversion may be inaccurate. Consider using '#align commute.inv_left_iff Commute.inv_left_iff\u2093'. -/\n@[simp, to_additive]\ntheorem inv_left_iff : Commute a\u207b\u00b9 b \u2194 Commute a b :=\n  SemiconjBy.inv_symm_left_iff\n#align commute.inv_left_iff Commute.inv_left_iff\n#align add_commute.neg_left_iff AddCommute.neg_left_iff\n\n/- warning: commute.inv_mul_cancel -> Commute.inv_mul_cancel is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) a) b) a) b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) a) b) a) b)\nCase conversion may be inaccurate. Consider using '#align commute.inv_mul_cancel Commute.inv_mul_cancel\u2093'. -/\n@[to_additive]\nprotected theorem inv_mul_cancel (h : Commute a b) : a\u207b\u00b9 * b * a = b := by\n  rw [h.inv_left.eq, inv_mul_cancel_right]\n#align commute.inv_mul_cancel Commute.inv_mul_cancel\n#align add_commute.neg_add_cancel AddCommute.neg_add_cancel\n\n/- warning: commute.inv_mul_cancel_assoc -> Commute.inv_mul_cancel_assoc is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) a) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) b a)) b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) a) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) b a)) b)\nCase conversion may be inaccurate. Consider using '#align commute.inv_mul_cancel_assoc Commute.inv_mul_cancel_assoc\u2093'. -/\n@[to_additive]\ntheorem inv_mul_cancel_assoc (h : Commute a b) : a\u207b\u00b9 * (b * a) = b := by\n  rw [\u2190 mul_assoc, h.inv_mul_cancel]\n#align commute.inv_mul_cancel_assoc Commute.inv_mul_cancel_assoc\n#align add_commute.neg_add_cancel_assoc AddCommute.neg_add_cancel_assoc\n\n/- warning: commute.mul_inv_cancel -> Commute.mul_inv_cancel is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) a b) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) a)) b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) a b) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) a)) b)\nCase conversion may be inaccurate. Consider using '#align commute.mul_inv_cancel Commute.mul_inv_cancel\u2093'. -/\n@[to_additive]\nprotected theorem mul_inv_cancel (h : Commute a b) : a * b * a\u207b\u00b9 = b := by\n  rw [h.eq, mul_inv_cancel_right]\n#align commute.mul_inv_cancel Commute.mul_inv_cancel\n#align add_commute.add_neg_cancel AddCommute.add_neg_cancel\n\n/- warning: commute.mul_inv_cancel_assoc -> Commute.mul_inv_cancel_assoc is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) a (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) b (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)) a))) b)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {a : G} {b : G}, (Commute.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a b) -> (Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) a (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))))) b (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (Group.toDivisionMonoid.{u1} G _inst_1)))) a))) b)\nCase conversion may be inaccurate. Consider using '#align commute.mul_inv_cancel_assoc Commute.mul_inv_cancel_assoc\u2093'. -/\n@[to_additive]\ntheorem mul_inv_cancel_assoc (h : Commute a b) : a * (b * a\u207b\u00b9) = b := by\n  rw [\u2190 mul_assoc, h.mul_inv_cancel]\n#align commute.mul_inv_cancel_assoc Commute.mul_inv_cancel_assoc\n#align add_commute.add_neg_cancel_assoc AddCommute.add_neg_cancel_assoc\n\nend Group\n\nend Commute\n\nsection CommGroup\n\nvariable [CommGroup G] (a b : G)\n\n/- warning: mul_inv_cancel_comm -> mul_inv_cancel_comm is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) a b) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1))) a)) b\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) a b) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (DivisionCommMonoid.toDivisionMonoid.{u1} G (CommGroup.toDivisionCommMonoid.{u1} G _inst_1))))) a)) b\nCase conversion may be inaccurate. Consider using '#align mul_inv_cancel_comm mul_inv_cancel_comm\u2093'. -/\n@[simp, to_additive]\ntheorem mul_inv_cancel_comm : a * b * a\u207b\u00b9 = b :=\n  (Commute.all a b).mul_inv_cancel\n#align mul_inv_cancel_comm mul_inv_cancel_comm\n#align add_neg_cancel_comm add_neg_cancel_comm\n\n/- warning: mul_inv_cancel_comm_assoc -> mul_inv_cancel_comm_assoc is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) a (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) b (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1))) a))) b\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) a (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) b (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (DivisionCommMonoid.toDivisionMonoid.{u1} G (CommGroup.toDivisionCommMonoid.{u1} G _inst_1))))) a))) b\nCase conversion may be inaccurate. Consider using '#align mul_inv_cancel_comm_assoc mul_inv_cancel_comm_assoc\u2093'. -/\n@[simp, to_additive]\ntheorem mul_inv_cancel_comm_assoc : a * (b * a\u207b\u00b9) = b :=\n  (Commute.all a b).mul_inv_cancel_assoc\n#align mul_inv_cancel_comm_assoc mul_inv_cancel_comm_assoc\n#align add_neg_cancel_comm_assoc add_neg_cancel_comm_assoc\n\n/- warning: inv_mul_cancel_comm -> inv_mul_cancel_comm is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1))) a) b) a) b\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (DivisionCommMonoid.toDivisionMonoid.{u1} G (CommGroup.toDivisionCommMonoid.{u1} G _inst_1))))) a) b) a) b\nCase conversion may be inaccurate. Consider using '#align inv_mul_cancel_comm inv_mul_cancel_comm\u2093'. -/\n@[simp, to_additive]\ntheorem inv_mul_cancel_comm : a\u207b\u00b9 * b * a = b :=\n  (Commute.all a b).inv_mul_cancel\n#align inv_mul_cancel_comm inv_mul_cancel_comm\n#align neg_add_cancel_comm neg_add_cancel_comm\n\n/- warning: inv_mul_cancel_comm_assoc -> inv_mul_cancel_comm_assoc is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1))) a) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) b a)) b\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : CommGroup.{u1} G] (a : G) (b : G), Eq.{succ u1} G (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) (Inv.inv.{u1} G (InvOneClass.toInv.{u1} G (DivInvOneMonoid.toInvOneClass.{u1} G (DivisionMonoid.toDivInvOneMonoid.{u1} G (DivisionCommMonoid.toDivisionMonoid.{u1} G (CommGroup.toDivisionCommMonoid.{u1} G _inst_1))))) a) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G (CommGroup.toGroup.{u1} G _inst_1)))))) b a)) b\nCase conversion may be inaccurate. Consider using '#align inv_mul_cancel_comm_assoc inv_mul_cancel_comm_assoc\u2093'. -/\n@[simp, to_additive]\ntheorem inv_mul_cancel_comm_assoc : a\u207b\u00b9 * (b * a) = b :=\n  (Commute.all a b).inv_mul_cancel_assoc\n#align inv_mul_cancel_comm_assoc inv_mul_cancel_comm_assoc\n#align neg_add_cancel_comm_assoc neg_add_cancel_comm_assoc\n\nend CommGroup\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Group/Commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7138410021933463}}
{"text": "/-\nCopyright (c) 2018 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison, Bhavik Mehta\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.category_theory.opposites\nimport Mathlib.PostPort\n\nuniverses u\u2082 v\u2082 u\u2081 v\u2081 u\u2083 v\u2083 \n\nnamespace Mathlib\n\nnamespace category_theory.functor\n\n\n/--\nThe functor sending `X : C` to the constant functor `J \u2964 C` sending everything to `X`.\n-/\ndef const (J : Type u\u2081) [category J] {C : Type u\u2082} [category C] : C \u2964 J \u2964 C :=\n  mk (fun (X : C) => mk (fun (j : J) => X) fun (j j' : J) (f : j \u27f6 j') => \ud835\udfd9)\n    fun (X Y : C) (f : X \u27f6 Y) => nat_trans.mk fun (j : J) => f\n\nnamespace const\n\n\n@[simp] theorem obj_obj {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C) (j : J) :\n    obj (obj (const J) X) j = X :=\n  rfl\n\n@[simp] theorem obj_map {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C) {j : J}\n    {j' : J} (f : j \u27f6 j') : map (obj (const J) X) f = \ud835\udfd9 :=\n  rfl\n\n@[simp] theorem map_app {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] {X : C} {Y : C}\n    (f : X \u27f6 Y) (j : J) : nat_trans.app (map (const J) f) j = f :=\n  rfl\n\n/--\nThe contant functor `J\u1d52\u1d56 \u2964 C\u1d52\u1d56` sending everything to `op X`\nis (naturally isomorphic to) the opposite of the constant functor `J \u2964 C` sending everything to `X`.\n-/\ndef op_obj_op {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C) :\n    obj (const (J\u1d52\u1d56)) (opposite.op X) \u2245 functor.op (obj (const J) X) :=\n  iso.mk (nat_trans.mk fun (j : J\u1d52\u1d56) => \ud835\udfd9) (nat_trans.mk fun (j : J\u1d52\u1d56) => \ud835\udfd9)\n\n@[simp] theorem op_obj_op_hom_app {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C)\n    (j : J\u1d52\u1d56) : nat_trans.app (iso.hom (op_obj_op X)) j = \ud835\udfd9 :=\n  rfl\n\n@[simp] theorem op_obj_op_inv_app {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C)\n    (j : J\u1d52\u1d56) : nat_trans.app (iso.inv (op_obj_op X)) j = \ud835\udfd9 :=\n  rfl\n\n/--\nThe contant functor `J\u1d52\u1d56 \u2964 C` sending everything to `unop X`\nis (naturally isomorphic to) the opposite of\nthe constant functor `J \u2964 C\u1d52\u1d56` sending everything to `X`.\n-/\ndef op_obj_unop {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C\u1d52\u1d56) :\n    obj (const (J\u1d52\u1d56)) (opposite.unop X) \u2245 functor.left_op (obj (const J) X) :=\n  iso.mk (nat_trans.mk fun (j : J\u1d52\u1d56) => \ud835\udfd9) (nat_trans.mk fun (j : J\u1d52\u1d56) => \ud835\udfd9)\n\n-- Lean needs some help with universes here.\n\n@[simp] theorem op_obj_unop_hom_app {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C\u1d52\u1d56)\n    (j : J\u1d52\u1d56) : nat_trans.app (iso.hom (op_obj_unop X)) j = \ud835\udfd9 :=\n  rfl\n\n@[simp] theorem op_obj_unop_inv_app {J : Type u\u2081} [category J] {C : Type u\u2082} [category C] (X : C\u1d52\u1d56)\n    (j : J\u1d52\u1d56) : nat_trans.app (iso.inv (op_obj_unop X)) j = \ud835\udfd9 :=\n  rfl\n\n@[simp] theorem unop_functor_op_obj_map {J : Type u\u2081} [category J] {C : Type u\u2082} [category C]\n    (X : C\u1d52\u1d56) {j\u2081 : J} {j\u2082 : J} (f : j\u2081 \u27f6 j\u2082) :\n    map (opposite.unop (obj (functor.op (const J)) X)) f = \ud835\udfd9 :=\n  rfl\n\nend const\n\n\n/-- These are actually equal, of course, but not definitionally equal\n  (the equality requires F.map (\ud835\udfd9 _) = \ud835\udfd9 _). A natural isomorphism is\n  more convenient than an equality between functors (compare id_to_iso). -/\ndef const_comp (J : Type u\u2081) [category J] {C : Type u\u2082} [category C] {D : Type u\u2083} [category D]\n    (X : C) (F : C \u2964 D) : obj (const J) X \u22d9 F \u2245 obj (const J) (obj F X) :=\n  iso.mk (nat_trans.mk fun (_x : J) => \ud835\udfd9) (nat_trans.mk fun (_x : J) => \ud835\udfd9)\n\n/-- If `J` is nonempty, then the constant functor over `J` is faithful. -/\nprotected instance const.category_theory.faithful (J : Type u\u2081) [category J] {C : Type u\u2082}\n    [category C] [Nonempty J] : faithful (const J) :=\n  faithful.mk\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/category_theory/const_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516188, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.713840997341818}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport data.fin.basic\nimport data.fintype.basic\n/-!\n# The structure of `fintype (fin n)`\n\nThis file contains some basic results about the `fintype` instance for `fin`,\nespecially properties of `finset.univ : finset (fin n)`.\n-/\n\n\nopen finset\nopen fintype\n\nnamespace fin\n\n@[simp]\nlemma univ_filter_zero_lt {n : \u2115} :\n  (univ : finset (fin n.succ)).filter (\u03bb i, 0 < i) =\n    univ.map (fin.succ_embedding _).to_embedding :=\nbegin\n  ext i,\n  simp only [mem_filter, mem_map, mem_univ, true_and,\n  function.embedding.coe_fn_mk, exists_true_left],\n  split,\n  { refine cases _ _ i,\n    { rintro \u27e8\u27e8\u27e9\u27e9 },\n    { intros i _, exact \u27e8i, mem_univ _, rfl\u27e9 } },\n  { rintro \u27e8i, _, rfl\u27e9,\n    exact succ_pos _ },\nend\n\n@[simp]\nlemma univ_filter_succ_lt {n : \u2115} (j : fin n) :\n  (univ : finset (fin n.succ)).filter (\u03bb i, j.succ < i) =\n    (univ.filter (\u03bb i, j < i)).map (fin.succ_embedding _).to_embedding :=\nbegin\n  ext i,\n  simp only [mem_filter, mem_map, mem_univ, true_and,\n  function.embedding.coe_fn_mk, exists_true_left],\n  split,\n  { refine cases _ _ i,\n    { rintro \u27e8\u27e8\u27e9\u27e9 },\n    { intros i hi,\n      exact \u27e8i, mem_filter.mpr \u27e8mem_univ _, succ_lt_succ_iff.mp hi\u27e9, rfl\u27e9 } },\n  { rintro \u27e8i, hi, rfl\u27e9,\n    exact succ_lt_succ_iff.mpr (mem_filter.mp hi).2 },\nend\n\nend fin\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/fintype/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782277, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7138409919676175}}
{"text": "/-\n  Properties of Spec(R).\n\n  https://stacks.math.columbia.edu/tag/00E0\n-/\n\nimport algebra.module\nimport ring_theory.localization\nimport to_mathlib.ideals\nimport to_mathlib.localization.localization_alt\nimport spectrum_of_a_ring.spec\n\nopen lattice\n\nnoncomputable theory\n\nlocal attribute [instance] classical.prop_decidable\n\nuniverse u\n\nsection properties\n\nvariables {R : Type u} [comm_ring R]\n\nopen Spec\n\n-- Lemma 1.\n-- The spectrum of a ring R is empty if and only if R is the zero ring.\n\nlemma Spec.empty_iff_zero_ring : (Spec R \u2192 false) \u2194 subsingleton R :=\nbegin\n  split,\n  { intros H,\n    constructor,\n    intros a b,\n    have Hzo : (0 : R) = 1,\n    { by_contra Hzno,\n      replace Hzno : (0 : R) \u2260 1 := \u03bb H, (Hzno H),\n      have HTnB : (\u22a5 : ideal R) \u2260 \u22a4 := zero_ne_one_bot_ne_top Hzno,\n      rcases (ideal.exists_le_maximal \u22a5 HTnB) with \u27e8M, \u27e8HM, HBM\u27e9\u27e9,\n      have MP : ideal.is_prime _ := ideal.is_maximal.is_prime HM,\n      apply H,\n      exact \u27e8M, MP\u27e9, },\n    calc a = a * 0 : by rw [Hzo, mul_one]\n      ...  = b * 0 : by simp\n      ...  = b     : by rw [Hzo, mul_one], },\n  { intros Hsub X,\n    cases Hsub,\n    rcases X with \u27e8X, \u27e8HC, PX\u27e9\u27e9,\n    apply HC,\n    apply ideal.ext,\n    intros x,\n    split,\n    { intros Hx,\n      trivial, },\n    { intros Hx,\n      rw (Hsub x 0),\n      exact X.2, } }\nend\n\n-- Lemma 5.\n-- V(S) = V((S)).\n\nlemma Spec.V.set_eq_span (S : set R) : Spec.V S = Spec.V (ideal.span S) :=\nset.ext $ \u03bb \u27e8I, PI\u27e9,\n\u27e8\u03bb HI x Hx,\n  begin \n    have HxI := (ideal.span_mono HI) Hx, \n    rw ideal.span_eq at HxI,\n    exact HxI,\n  end,\n \u03bb HI x Hx, HI (ideal.subset_span Hx)\u27e9\n\n-- Lemma 8.\n-- V(I) = \u2205 iff I = R.\n\nlemma Spec.V.empty_iff_ideal_top (I : ideal R) : V(I.1) = \u2205 \u2194 I = \u22a4 :=\nbegin\n  split,\n  { intros HI,\n    by_contradiction HC,\n    suffices Hsuff : \u2203 x, x \u2208 Spec.V I.1,\n      cases Hsuff with x Hx,\n      rw set.eq_empty_iff_forall_not_mem at HI,\n      exact HI x Hx,\n    rcases (ideal.exists_le_maximal I HC) with \u27e8M, \u27e8HM, HBM\u27e9\u27e9,\n    have MP : ideal.is_prime M := ideal.is_maximal.is_prime HM,\n    use [\u27e8M, MP\u27e9],\n    exact HBM, },\n  { intros HI,\n    rw [HI, set.eq_empty_iff_forall_not_mem],\n    rintros \u27e8J, PJ\u27e9 HnJ,\n    have HJ : J = \u22a4 := le_antisymm (\u03bb x Hx, trivial) HnJ,\n    exact PJ.1 HJ, }\nend\n\n-- Lemma 15.\n-- If f,g \u2208 R, then D(fg) = D(f) \u2229 D(g).\n\nlemma Spec.V'.product_eq_union (f g : R) : V'(f * g) = V'(f) \u222a V'(g) :=\nbegin\n  unfold Spec.V',\n  apply set.ext,\n  rintros \u27e8x, Px\u27e9,\n  split,\n  { intros Hx,\n    have Hfg : f * g \u2208 x := Hx,\n    have Hforgx := Px.2 Hfg,\n    cases Hforgx,\n    { left,\n      apply Hforgx, },\n    { right,\n      apply Hforgx, } },\n  { intros Hx,\n    cases Hx,\n    { have Hf : f \u2208 x := Hx,\n      apply ideal.mul_mem_right x Hf, },\n    { have Hg : g \u2208 x := Hx,\n      apply ideal.mul_mem_left x Hg, } }\nend\n\nlemma Spec.D'.product_eq_inter (f g : R) : D'(f * g) = D'(f) \u2229 D'(g) :=\nbegin\n  unfold Spec.D',\n  rw Spec.V'.product_eq_union,\n  rw set.compl_union,\nend\n\n-- Lemma 16.\n-- \u22c3D(fi) is the complement of V({fi}).\n\nlemma Spec.D'.union (F : set R) : \u22c3\u2080 (D' '' F) = -V(F) :=\nbegin\n  apply set.ext,\n  intros x,\n  split,\n  { intros Hx HC,\n    rcases Hx with \u27e8Df, HDf, Hx\u27e9,\n    rcases HDf with \u27e8f, Hf, HDf\u27e9,\n    rw \u2190HDf at Hx,\n    apply Hx,\n    exact HC Hf, },\n  { intros Hx,\n    have Hf := not_forall.1 Hx,\n    rcases Hf with \u27e8f, Hf\u27e9,\n    rw not_imp at Hf,\n    rcases Hf with \u27e8HfF, Hfnx\u27e9,\n    use [Spec.D' f, \u27e8f, HfF, rfl\u27e9], }\nend\n\n\n-- D(g) \u2286 D(f) \u2192 f \u2208 R[1/g]*.\n\n--set_option trace.class_instances true\n\nlemma inverts.of_Dfs_subset {f g : R} (H : D'(g) \u2286 D'(f)) \n: localization_alt.inverts (powers f) (localization.of : R \u2192 localization R (powers g)) :=\nbegin\n  rintros \u27e8fn, Hfn\u27e9,\n  suffices Hsuff : \u2203 si, (localization.of : R \u2192 localization R (powers g)) f * si = 1,\n    rcases Hsuff with \u27e8si, Hsi\u27e9,\n    show \u2203 si, localization.of fn * si = 1,\n    rcases Hfn with \u27e8n, Hfn\u27e9,\n    rw \u2190Hfn,\n    clear Hfn,\n    induction n with n Hn,\n    { simp, },\n    { rw pow_succ,\n      rw (@is_ring_hom.map_mul _ _ _ _ localization.of localization.of.is_ring_hom),\n      rcases Hn with \u27e8sin, Hn\u27e9,\n      existsi (si * sin),\n      rw \u2190mul_assoc,\n      rw mul_assoc _ _ si,\n      rw mul_comm _ si,\n      rw \u2190mul_assoc,\n      rw Hsi,\n      rw one_mul,\n      exact Hn, },\n  unfold Spec.D' at H,\n  rw set.compl_subset_compl at H,\n  unfold Spec.V' at H,\n  by_contra Hne,\n  rw not_exists at Hne,\n  have Hnu : \u00acis_unit ((localization.of : R \u2192 localization R (powers g)) f),\n    intros HC,\n    simp [is_unit] at HC,\n    rcases HC with \u27e8u, HC\u27e9,\n    apply (Hne u.inv),\n    rw HC,\n    exact u.3,\n  letI Rgr : comm_ring (localization.away g) := by apply_instance, \n  let F : ideal (localization.away g) := ideal.span {(localization.of f)},\n  rcases (ideal.exists_le_maximal F (\u03bb HC, Hnu (ideal.span_singleton_eq_top.1 HC))) with \u27e8S, \u27e8HMS, HFS\u27e9\u27e9,\n  have HfF : (localization.of f : localization.away g) \u2208 F,\n    suffices Hsuff : localization.of f \u2208 {localization.of f},\n      refine ideal.subset_span Hsuff,\n    exact set.mem_singleton _,\n  have HfM : localization.of f \u2208 S := HFS HfF,\n  have PS := ideal.is_maximal.is_prime HMS,\n  have PS' : ideal.is_prime (ideal.comap localization.of S)\n    := @ideal.is_prime.comap _ _ _ _ localization.of _ _ PS,\n  let S' : Spec R := \u27e8ideal.comap localization.of S, PS'\u27e9,\n  have HfS' : f \u2208 S'.val,\n    erw ideal.mem_comap,\n    exact HfM,\n  replace HfS' : S' \u2208 {P : Spec R | f \u2208 P.val} := HfS',\n  have HgS' : g \u2208 ideal.comap localization.of S := H HfS',\n  rw ideal.mem_comap at HgS',\n  rcases (localization.coe_is_unit R (powers g) \u27e8g, \u27e81, pow_one g\u27e9\u27e9) with \u27e8w, Hw\u27e9,\n  rcases w with \u27e8w, winv, Hwwinv, Hwinvw\u27e9,\n  change localization.of g = w at Hw,\n  have HC : localization.of g * winv \u2208 S := ideal.mul_mem_right S HgS',\n  erw [Hw, Hwwinv] at HC,\n  exact ((ideal.ne_top_iff_one S).1 PS.1) HC,\nend\n\n-- D(g) \u2286 D(f) \u2192 \u2203 a e, g^e = a * f.\n\nlemma pow_eq.of_Dfs_subset {f g : R} (H : D'(g) \u2286 D'(f)) \n: \u2203 (a : R) (e : \u2115), g^e = a * f :=\nbegin \n  have Hinv := inverts.of_Dfs_subset H,\n  rcases (Hinv \u27e8f, \u27e81, pow_one f\u27e9\u27e9) with \u27e8w, Hw\u27e9,\n  dsimp only [subtype.coe_mk] at Hw,\n  rcases (quotient.exists_rep w) with \u27e8\u27e8a, \u27e8gn, \u27e8n, Hn\u27e9\u27e9\u27e9, Hagn\u27e9,\n  erw [\u2190Hagn, quotient.eq] at Hw,\n  rcases Hw with \u27e8gm, \u27e8\u27e8m, Hm\u27e9, Hw\u27e9\u27e9,\n  simp [-sub_eq_add_neg] at Hw,\n  rw [sub_mul, sub_eq_zero, mul_assoc, mul_comm f, \u2190Hn, \u2190Hm, \u2190pow_add] at Hw,\n  existsi [a * g ^ m, n + m],\n  exact Hw,\nend\n\nend properties\n", "meta": {"author": "ramonfmir", "repo": "lean-scheme", "sha": "6d3ec18fecfd174b79d0ce5c85a783f326dd50f6", "save_path": "github-repos/lean/ramonfmir-lean-scheme", "path": "github-repos/lean/ramonfmir-lean-scheme/lean-scheme-6d3ec18fecfd174b79d0ce5c85a783f326dd50f6/src/spectrum_of_a_ring/properties.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7138277813144605}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport order.hom.basic\nimport algebra.hom.equiv.basic\nimport algebra.ring.basic\nimport algebra.order.sub.defs\n\n/-!\n# Additional results about ordered Subtraction\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n-/\n\nvariables {\u03b1 \u03b2 : Type*}\n\nsection has_add\n\nvariables [preorder \u03b1] [has_add \u03b1] [has_sub \u03b1] [has_ordered_sub \u03b1] {a b c d : \u03b1}\n\nlemma add_hom.le_map_tsub [preorder \u03b2] [has_add \u03b2] [has_sub \u03b2] [has_ordered_sub \u03b2]\n  (f : add_hom \u03b1 \u03b2) (hf : monotone f) (a b : \u03b1) :\n  f a - f b \u2264 f (a - b) :=\nby { rw [tsub_le_iff_right, \u2190 f.map_add], exact hf le_tsub_add }\n\nlemma le_mul_tsub {R : Type*} [distrib R] [preorder R] [has_sub R] [has_ordered_sub R]\n  [covariant_class R R (*) (\u2264)] {a b c : R} :\n  a * b - a * c \u2264 a * (b - c) :=\n(add_hom.mul_left a).le_map_tsub (monotone_id.const_mul' a) _ _\n\nlemma le_tsub_mul {R : Type*} [comm_semiring R] [preorder R] [has_sub R] [has_ordered_sub R]\n  [covariant_class R R (*) (\u2264)] {a b c : R} :\n  a * c - b * c \u2264 (a - b) * c :=\nby simpa only [mul_comm _ c] using le_mul_tsub\n\nend has_add\n\n/-- An order isomorphism between types with ordered subtraction preserves subtraction provided that\nit preserves addition. -/\nlemma order_iso.map_tsub {M N : Type*} [preorder M] [has_add M] [has_sub M] [has_ordered_sub M]\n  [partial_order N] [has_add N] [has_sub N] [has_ordered_sub N] (e : M \u2243o N)\n  (h_add : \u2200 a b, e (a + b) = e a + e b) (a b : M) :\n  e (a - b) = e a - e b :=\nbegin\n  set e_add : M \u2243+ N := { map_add' := h_add, .. e },\n  refine le_antisymm _ (e_add.to_add_hom.le_map_tsub e.monotone a b),\n  suffices : e (e.symm (e a) - e.symm (e b)) \u2264 e (e.symm (e a - e b)), by simpa,\n  exact e.monotone (e_add.symm.to_add_hom.le_map_tsub e.symm.monotone _ _)\nend\n\n/-! ### Preorder -/\n\nsection preorder\nvariables [preorder \u03b1]\n\nvariables [add_comm_monoid \u03b1] [has_sub \u03b1] [has_ordered_sub \u03b1] {a b c d : \u03b1}\n\nlemma add_monoid_hom.le_map_tsub [preorder \u03b2] [add_comm_monoid \u03b2] [has_sub \u03b2]\n  [has_ordered_sub \u03b2] (f : \u03b1 \u2192+ \u03b2) (hf : monotone f) (a b : \u03b1) :\n  f a - f b \u2264 f (a - b) :=\nf.to_add_hom.le_map_tsub hf a b\n\nend preorder\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/sub/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.7138277768543323}}
{"text": "/- LoVe Demo 12: Basic Mathematical Structures -/\n\nimport .love05_inductive_predicates_demo\n\nnamespace LoVe\n\n\n/- Type Classes -/\n\n-- The `inhabited` typeclass for types that contain at least one element\n#check inhabited\n\n-- `nonempty` lives in `Prop`, whereas `inhabited` lives in `Type`\n#check nonempty\n\n-- Recall: `head` returns `option \u03b1`\n#check head\n\n-- Variant of `head` for inhabited types\ndef ihead {\u03b1 : Type} [inhabited \u03b1] (xs : list \u03b1) : \u03b1 :=\nmatch xs with\n| []     := inhabited.default \u03b1\n| x :: _ := x\nend\n\nlemma ihead_ihead {\u03b1 : Type} [inhabited \u03b1] (xs : list \u03b1) :\n  ihead [ihead xs] = ihead xs :=\nbegin\n  cases xs,\n  { refl },\n  { refl }\nend\n\n-- The natural numbers can be made an instance as follows:\ninstance : inhabited \u2115 :=\n{ default := 0 }\n\n#reduce inhabited.default \u2115\n#reduce ihead ([] : list \u2115)\n#check ihead_ihead ([1, 2, 3] : list \u2115)\n\n-- Syntactic type classes\n#check has_zero\n#check has_neg\n#check has_add\n#check has_one\n#check has_inv\n#check has_mul\n\n#check (1 : \u2115)\n#check (1 : \u2124)\n#check (1 : \u211d)\n#check (1 : linear_map _ _ _)\n\n\n/- Groups -/\n\n#print group\n\n#print add_group\n\ninductive \u2124\u2082 : Type\n| zero\n| one\n\ndef \u2124\u2082.add : \u2124\u2082 \u2192 \u2124\u2082 \u2192 \u2124\u2082\n| \u2124\u2082.zero x       := x\n| x       \u2124\u2082.zero := x\n| \u2124\u2082.one  \u2124\u2082.one  := \u2124\u2082.zero\n\ninstance \u2124\u2082.add_group : add_group \u2124\u2082 :=\n{ add          := \u2124\u2082.add,\n  add_assoc    :=\n    begin\n      intros a b c,\n      simp [(+)],\n      cases a;\n        cases b;\n        cases c;\n        refl\n    end,\n  zero         := \u2124\u2082.zero,\n  zero_add     :=\n    begin\n      intro a,\n      cases a;\n        refl\n    end,\n  add_zero     :=\n    begin\n      intro a,\n      cases a;\n        refl\n    end,\n  neg          := (\u03bb x, x),\n  add_left_neg :=\n    begin\n      intro a,\n      cases a;\n        refl\n    end }\n\n#reduce \u2124\u2082.one + 0 - 0 - \u2124\u2082.one\n\nexample :\n  \u2200a : \u2124\u2082, a + - a = 0 :=\nadd_right_neg\n\n-- Another example: lists as `add_monoid`:\ninstance {\u03b1 : Type} : add_monoid (list \u03b1) :=\n{ zero      := [],\n  add       := (++),\n  add_assoc := list.append_assoc,\n  zero_add  := list.nil_append,\n  add_zero  := list.append_nil }\n\n\n/- Fields -/\n\n#print field\n\ndef \u2124\u2082.mul : \u2124\u2082 \u2192 \u2124\u2082 \u2192 \u2124\u2082\n| \u2124\u2082.one  x       := x\n| x       \u2124\u2082.one  := x\n| \u2124\u2082.zero \u2124\u2082.zero := \u2124\u2082.zero\n\ninstance : field \u2124\u2082 :=\n{ one            := \u2124\u2082.one,\n  mul            := \u2124\u2082.mul,\n  inv            := \u03bbx, x,\n  add_comm       :=\n    begin\n      intros a b,\n      cases a;\n        cases b;\n        refl\n    end,\n  zero_ne_one    :=\n    begin\n      intro h,\n      cases h\n    end,\n  one_mul        :=\n    begin\n      intros a,\n      cases a;\n        refl\n    end,\n  mul_one        :=\n    begin\n      intros a,\n      cases a;\n        refl\n    end,\n  mul_inv_cancel :=\n    begin \n      intros a h,\n      cases a,\n      apply false.elim,\n      apply h,\n      refl,\n      refl \n    end,\n  inv_mul_cancel :=\n    begin \n      intros a h,\n      cases a,\n      apply false.elim,\n      apply h,\n      refl,\n      refl\n    end,\n  mul_assoc      :=\n    begin\n      intros a b c,\n      cases a;\n        cases b;\n        cases c;\n        refl\n    end,\n  mul_comm       :=\n    begin\n      intros a b,\n      cases a;\n        cases b;\n        refl\n    end,\n  left_distrib   :=\n    begin\n      intros a b c,\n      cases a;\n        cases b;\n        cases c;\n        refl\n    end,\n  right_distrib  :=\n    begin\n      intros a b c,\n      cases a;\n        cases b;\n        cases c;\n        refl\n    end,\n  ..\u2124\u2082.add_group }\n\n#reduce (1 : \u2124\u2082) * 0 / (0 - 1)  -- result: \u2124\u2082.zero\n\n#reduce (3 : \u2124\u2082)  -- result: \u2124\u2082.one\n\nexample (a b : \u2124\u2082) :\n  (a + b) ^ 3 = a ^ 3 + 3 * a^2 * b + 3 * a * b ^ 2 + b ^ 3 :=\nby ring -- normalizes terms of rings\n\nexample (a b : \u2124) :\n  (a + b + 0) - ((b + a) + a) = -a :=\nby abel -- normalizes terms of commutative monoids\n\n\n/- Coercions -/\n\nlemma neg_mul_neg_nat (n : \u2115) (z : \u2124) :\n  (- z) * (- n) = z * n :=\nneg_mul_neg z n\n-- This works, althogh negation `- n` is not defined on natural numbers.\n\n#print neg_mul_neg_nat\n-- Lean introduced a coercion `\u2191` automatically.\n\nlemma neg_mul_neg_nat\u2082 (n : \u2115) (z : \u2124) :\n  (- n : \u2124) * (- z) = n * z :=\nneg_mul_neg n z\n\n#print neg_mul_neg_nat\u2082\n\nexample (m n : \u2115) (h : (m : \u2124) = (n : \u2124)) :\n  m = n :=\nbegin\n  norm_cast at h,\n  exact h\nend\n\nexample (m n : \u2115) :\n  (m : \u2124) + (n : \u2124) = ((m + n : \u2115) : \u2124) :=\nbegin norm_cast end\n\n-- norm_cast internally uses lemmas such as:\n#check nat.cast_add\n#check int.cast_add\n#check rat.cast_add\n\n\n/- Lists, Multisets and Finite Sets -/\n\n-- lists: number of occurrences and order matter\n\nexample :\n  [1, 2, 2, 3] \u2260 [1, 2, 3] :=\ndec_trivial\n\nexample :\n  [3, 2, 1] \u2260 [1, 2, 3] :=\ndec_trivial\n\n-- multisets: number of occurrences matters, order doesn't\n\nexample :\n  ({1, 2, 2, 3} : multiset \u2115) \u2260 {1, 2, 3} :=\ndec_trivial\n\nexample :\n  ({1, 2, 3} : multiset \u2115) = {3, 2, 1} :=\ndec_trivial\n\n-- finsets: number of occurrences and order don't matter\n\nexample :\n  ({1, 2, 2, 3} : finset \u2115) = {1, 2, 3} :=\ndec_trivial\n\nexample :\n  ({1, 2, 3} : finset \u2115) = {3, 2, 1} :=\ndec_trivial\n\n-- `dec_trivial` can solve goals for which Lean can infer an algorithm \n-- to compute their truth value, i.e., trivially decidable goals\n\n-- list of nodes (depth first)\ndef nodes_list : btree \u2115 \u2192 list \u2115\n| empty          := []\n| (node a t\u2081 t\u2082) := a :: nodes_list t\u2081 ++ nodes_list t\u2082\n\n-- multiset of nodes\ndef nodes_multiset : btree \u2115 \u2192 multiset \u2115\n| empty          := \u2205\n| (node a t\u2081 t\u2082) :=\n  insert a (nodes_multiset t\u2081 \u222a nodes_multiset t\u2082)\n\n-- finset of nodes\ndef nodes_finset : btree \u2115 \u2192 finset \u2115\n| empty          := \u2205\n| (node a t\u2081 t\u2082) := insert a (nodes_finset t\u2081 \u222a nodes_finset t\u2082)\n\n#eval list.sum [1, 2, 3, 4]                          -- result: 10\n#eval multiset.sum ({1, 2, 3, 4} : multiset \u2115)       -- result: 10\n#eval finset.sum ({1, 2, 3, 4} : finset \u2115) (\u03bbx, x)   -- result: 10\n\n#eval list.prod [1, 2, 3, 4]                         -- result: 24\n#eval multiset.prod ({1, 2, 3, 4} : multiset \u2115)      -- result: 24\n#eval finset.prod ({1, 2, 3, 4} : finset \u2115) (\u03bbx, x)  -- result: 24\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love12_basic_mathematical_structures_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7138277744878176}}
{"text": "/-\nCopyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Kontorovich, Heather Macbeth, Marc Masdeu\n-/\n\nimport analysis.complex.upper_half_plane\nimport linear_algebra.general_linear_group\nimport analysis.matrix\n\n/-!\n# The action of the modular group SL(2, \u2124) on the upper half-plane\n\nWe define the action of `SL(2,\u2124)` on `\u210d` (via restriction of the `SL(2,\u211d)` action in\n`analysis.complex.upper_half_plane`). We then define the standard fundamental domain\n(`modular_group.fundamental_domain`, `\ud835\udc9f`) for this action and show\n(`modular_group.exists_smul_mem_fundamental_domain`) that any point in `\u210d` can be\nmoved inside `\ud835\udc9f`.\n\nStandard proofs make use of the identity\n\n`g \u2022 z = a / c - 1 / (c (cz + d))`\n\nfor `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`.\nInstead, our proof makes use of the following perhaps novel identity (see\n`modular_group.smul_eq_lc_row0_add`):\n\n`g \u2022 z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`\n\nwhere there is no issue of division by zero.\n\nAnother feature is that we delay until the very end the consideration of special matrices\n`T=[[1,1],[0,1]]` (see `modular_group.T`) and `S=[[0,-1],[1,0]]` (see `modular_group.S`), by\ninstead using abstract theory on the properness of certain maps (phrased in terms of the filters\n`filter.cocompact`, `filter.cofinite`, etc) to deduce existence theorems, first to prove the\nexistence of `g` maximizing `(g\u2022z).im` (see `modular_group.exists_max_im`), and then among\nthose, to minimize `|(g\u2022z).re|` (see `modular_group.exists_row_one_eq_and_min_re`).\n-/\n\n/- Disable these instances as they are not the simp-normal form, and having them disabled ensures\nwe state lemmas in this file without spurious `coe_fn` terms. -/\nlocal attribute [-instance] matrix.special_linear_group.has_coe_to_fun\nlocal attribute [-instance] matrix.general_linear_group.has_coe_to_fun\n\nopen complex matrix matrix.special_linear_group upper_half_plane\nnoncomputable theory\n\nlocal notation `SL(` n `, ` R `)`:= special_linear_group (fin n) R\nlocal prefix `\u2191\u2098`:1024 := @coe _ (matrix (fin 2) (fin 2) \u2124) _\n\n\nopen_locale upper_half_plane complex_conjugate\n\nlocal attribute [instance] fintype.card_fin_even\n\nnamespace modular_group\n\nsection upper_half_plane_action\n\n/-- For a subring `R` of `\u211d`, the action of `SL(2, R)` on the upper half-plane, as a restriction of\nthe `SL(2, \u211d)`-action defined by `upper_half_plane.mul_action`. -/\ninstance {R : Type*} [comm_ring R] [algebra R \u211d] : mul_action SL(2, R) \u210d :=\nmul_action.comp_hom \u210d (map (algebra_map R \u211d))\n\nlemma coe_smul (g : SL(2, \u2124)) (z : \u210d) : \u2191(g \u2022 z) = num g z / denom g z := rfl\nlemma re_smul (g : SL(2, \u2124)) (z : \u210d) : (g \u2022 z).re = (num g z / denom g z).re := rfl\n@[simp] lemma smul_coe (g : SL(2, \u2124)) (z : \u210d) : (g : SL(2,\u211d)) \u2022 z = g \u2022 z := rfl\n\n@[simp] lemma neg_smul (g : SL(2, \u2124)) (z : \u210d) : -g \u2022 z = g \u2022 z :=\nshow \u2191(-g) \u2022 _ = _, by simp [neg_smul g z]\n\nlemma im_smul (g : SL(2, \u2124)) (z : \u210d) : (g \u2022 z).im = (num g z / denom g z).im := rfl\n\nlemma im_smul_eq_div_norm_sq (g : SL(2, \u2124)) (z : \u210d) :\n  (g \u2022 z).im = z.im / (complex.norm_sq (denom g z)) :=\nim_smul_eq_div_norm_sq g z\n\n@[simp] lemma denom_apply (g : SL(2, \u2124)) (z : \u210d) : denom g z = \u2191\u2098g 1 0 * z + \u2191\u2098g 1 1 := by simp\n\nend upper_half_plane_action\n\nsection bottom_row\n\n/-- The two numbers `c`, `d` in the \"bottom_row\" of `g=[[*,*],[c,d]]` in `SL(2, \u2124)` are coprime. -/\nlemma bottom_row_coprime {R : Type*} [comm_ring R] (g : SL(2, R)) :\n  is_coprime ((\u2191g : matrix (fin 2) (fin 2) R) 1 0) ((\u2191g : matrix (fin 2) (fin 2) R) 1 1) :=\nbegin\n  use [- (\u2191g : matrix (fin 2) (fin 2) R) 0 1, (\u2191g : matrix (fin 2) (fin 2) R) 0 0],\n  rw [add_comm, neg_mul, \u2190sub_eq_add_neg, \u2190det_fin_two],\n  exact g.det_coe,\nend\n\n/-- Every pair `![c, d]` of coprime integers is the \"bottom_row\" of some element `g=[[*,*],[c,d]]`\nof `SL(2,\u2124)`. -/\nlemma bottom_row_surj {R : Type*} [comm_ring R] :\n  set.surj_on (\u03bb g : SL(2, R), @coe _ (matrix (fin 2) (fin 2) R) _ g 1) set.univ\n    {cd | is_coprime (cd 0) (cd 1)} :=\nbegin\n  rintros cd \u27e8b\u2080, a, gcd_eqn\u27e9,\n  let A := ![![a, -b\u2080], cd],\n  have det_A_1 : det A = 1,\n  { convert gcd_eqn,\n    simp [A, det_fin_two, (by ring : a * (cd 1) + b\u2080 * (cd 0) = b\u2080 * (cd 0) + a * (cd 1))] },\n  refine \u27e8\u27e8A, det_A_1\u27e9, set.mem_univ _, _\u27e9,\n  ext; simp [A]\nend\n\nend bottom_row\n\nsection tendsto_lemmas\n\nopen filter continuous_linear_map\nlocal attribute [instance] matrix.normed_group matrix.normed_space\nlocal attribute [simp] coe_smul\n\n/-- The function `(c,d) \u2192 |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite.\n-/\nlemma tendsto_norm_sq_coprime_pair (z : \u210d) :\n  filter.tendsto (\u03bb p : fin 2 \u2192 \u2124, ((p 0 : \u2102) * z + p 1).norm_sq)\n  cofinite at_top :=\nbegin\n  let \u03c0\u2080 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d := linear_map.proj 0,\n  let \u03c0\u2081 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d := linear_map.proj 1,\n  let f : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u2102 := \u03c0\u2080.smul_right (z:\u2102) + \u03c0\u2081.smul_right 1,\n  have f_def : \u21d1f = \u03bb (p : fin 2 \u2192 \u211d), (p 0 : \u2102) * \u2191z + p 1,\n  { ext1,\n    dsimp only [linear_map.coe_proj, real_smul,\n      linear_map.coe_smul_right, linear_map.add_apply],\n    rw mul_one, },\n  have : (\u03bb (p : fin 2 \u2192 \u2124), norm_sq ((p 0 : \u2102) * \u2191z + \u2191(p 1)))\n    = norm_sq \u2218 f \u2218 (\u03bb p : fin 2 \u2192 \u2124, (coe : \u2124 \u2192 \u211d) \u2218 p),\n  { ext1,\n    rw f_def,\n    dsimp only [function.comp],\n    rw [of_real_int_cast, of_real_int_cast], },\n  rw this,\n  have hf : f.ker = \u22a5,\n  { let g : \u2102 \u2192\u2097[\u211d] (fin 2 \u2192 \u211d) :=\n      linear_map.pi ![im_lm, im_lm.comp ((z:\u2102) \u2022 (conj_ae  : \u2102 \u2192\u2097[\u211d] \u2102))],\n    suffices : ((z:\u2102).im\u207b\u00b9 \u2022 g).comp f = linear_map.id,\n    { exact linear_map.ker_eq_bot_of_inverse this },\n    apply linear_map.ext,\n    intros c,\n    have hz : (z:\u2102).im \u2260 0 := z.2.ne',\n    rw [linear_map.comp_apply, linear_map.smul_apply, linear_map.id_apply],\n    ext i,\n    dsimp only [g, pi.smul_apply, linear_map.pi_apply, smul_eq_mul],\n    fin_cases i,\n    { show ((z : \u2102).im)\u207b\u00b9 * (f c).im = c 0,\n      rw [f_def, add_im, of_real_mul_im, of_real_im, add_zero, mul_left_comm,\n        inv_mul_cancel hz, mul_one], },\n    { show ((z : \u2102).im)\u207b\u00b9 * ((z : \u2102) * conj (f c)).im = c 1,\n      rw [f_def, ring_hom.map_add, ring_hom.map_mul, mul_add, mul_left_comm, mul_conj,\n        conj_of_real, conj_of_real, \u2190 of_real_mul, add_im, of_real_im, zero_add,\n        inv_mul_eq_iff_eq_mul\u2080 hz],\n      simp only [of_real_im, of_real_re, mul_im, zero_add, mul_zero] } },\n  have h\u2081 := (linear_equiv.closed_embedding_of_injective hf).tendsto_cocompact,\n  have h\u2082 : tendsto (\u03bb p : fin 2 \u2192 \u2124, (coe : \u2124 \u2192 \u211d) \u2218 p) cofinite (cocompact _),\n  { convert tendsto.pi_map_Coprod (\u03bb i, int.tendsto_coe_cofinite),\n    { rw Coprod_cofinite },\n    { rw Coprod_cocompact } },\n  exact tendsto_norm_sq_cocompact_at_top.comp (h\u2081.comp h\u2082)\nend\n\n\n/-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`.\n  This is the linear map version of this operation.\n-/\ndef lc_row0 (p : fin 2 \u2192 \u2124) : (matrix (fin 2) (fin 2) \u211d) \u2192\u2097[\u211d] \u211d :=\n((p 0:\u211d) \u2022 linear_map.proj 0 + (p 1:\u211d) \u2022 linear_map.proj 1 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d).comp\n  (linear_map.proj 0)\n\n@[simp] lemma lc_row0_apply (p : fin 2 \u2192 \u2124) (g : matrix (fin 2) (fin 2) \u211d) :\n  lc_row0 p g = p 0 * g 0 0 + p 1 * g 0 1 :=\nrfl\n\nlemma lc_row0_apply' (a b : \u211d) (c d : \u2124) (v : fin 2 \u2192 \u211d) :\n  lc_row0 ![c, d] ![![a, b], v] = c * a + d * b :=\nby simp\n\n/-- Linear map sending the matrix [a, b; c, d] to the matrix [ac\u2080 + bd\u2080, - ad\u2080 + bc\u2080; c, d], for\nsome fixed `(c\u2080, d\u2080)`. -/\n@[simps] def lc_row0_extend {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  (matrix (fin 2) (fin 2) \u211d) \u2243\u2097[\u211d] matrix (fin 2) (fin 2) \u211d :=\nlinear_equiv.Pi_congr_right\n![begin\n    refine linear_map.general_linear_group.general_linear_equiv \u211d (fin 2 \u2192 \u211d)\n      (general_linear_group.to_linear (plane_conformal_matrix (cd 0 : \u211d) (-(cd 1 : \u211d)) _)),\n    norm_cast,\n    rw neg_sq,\n    exact hcd.sq_add_sq_ne_zero\n  end,\n  linear_equiv.refl \u211d (fin 2 \u2192 \u211d)]\n\n/-- The map `lc_row0` is proper, that is, preimages of cocompact sets are finite in\n`[[* , *], [c, d]]`.-/\ntheorem tendsto_lc_row0 {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  tendsto (\u03bb g : {g : SL(2, \u2124) // \u2191\u2098g 1 = cd}, lc_row0 cd \u2191(\u2191g : SL(2, \u211d)))\n    cofinite (cocompact \u211d) :=\nbegin\n  let mB : \u211d \u2192 (matrix (fin 2) (fin 2)  \u211d) := \u03bb t, ![![t, (-(1:\u2124):\u211d)], coe \u2218 cd],\n  have hmB : continuous mB,\n  { simp only [continuous_pi_iff, fin.forall_fin_two],\n    have : \u2200 c : \u211d, continuous (\u03bb x : \u211d, c) := \u03bb c, continuous_const,\n    exact \u27e8\u27e8continuous_id, @this (-1 : \u2124)\u27e9, \u27e8this (cd 0), this (cd 1)\u27e9\u27e9 },\n  refine filter.tendsto.of_tendsto_comp _ (comap_cocompact hmB),\n  let f\u2081 : SL(2, \u2124) \u2192 matrix (fin 2) (fin 2) \u211d :=\n    \u03bb g, matrix.map (\u2191g : matrix _ _ \u2124) (coe : \u2124 \u2192 \u211d),\n  have cocompact_\u211d_to_cofinite_\u2124_matrix :\n    tendsto (\u03bb m : matrix (fin 2) (fin 2) \u2124, matrix.map m (coe : \u2124 \u2192 \u211d)) cofinite (cocompact _),\n  { simpa only [Coprod_cofinite, Coprod_cocompact]\n      using tendsto.pi_map_Coprod (\u03bb i : fin 2, tendsto.pi_map_Coprod\n        (\u03bb j : fin 2, int.tendsto_coe_cofinite)) },\n  have hf\u2081 : tendsto f\u2081 cofinite (cocompact _) :=\n    cocompact_\u211d_to_cofinite_\u2124_matrix.comp subtype.coe_injective.tendsto_cofinite,\n  have hf\u2082 : closed_embedding (lc_row0_extend hcd) :=\n    (lc_row0_extend hcd).to_continuous_linear_equiv.to_homeomorph.closed_embedding,\n  convert hf\u2082.tendsto_cocompact.comp (hf\u2081.comp subtype.coe_injective.tendsto_cofinite) using 1,\n  ext \u27e8g, rfl\u27e9 i j : 3,\n  fin_cases i; [fin_cases j, skip],\n  -- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts.\n  { simp only [mB, mul_vec, dot_product, fin.sum_univ_two, _root_.coe_coe, coe_matrix_coe,\n      int.coe_cast_ring_hom, lc_row0_apply, function.comp_app, cons_val_zero, lc_row0_extend_apply,\n      linear_map.general_linear_group.coe_fn_general_linear_equiv,\n      general_linear_group.to_linear_apply, coe_plane_conformal_matrix, neg_neg, mul_vec_lin_apply,\n      cons_val_one, head_cons] },\n  { convert congr_arg (\u03bb n : \u2124, (-n:\u211d)) g.det_coe.symm using 1,\n    simp only [f\u2081, mul_vec, dot_product, fin.sum_univ_two, matrix.det_fin_two, function.comp_app,\n      subtype.coe_mk, lc_row0_extend_apply, cons_val_zero,\n      linear_map.general_linear_group.coe_fn_general_linear_equiv,\n      general_linear_group.to_linear_apply, coe_plane_conformal_matrix, mul_vec_lin_apply,\n      cons_val_one, head_cons, map_apply, neg_mul, int.cast_sub, int.cast_mul, neg_sub],\n    ring },\n  { refl }\nend\n\n/-- This replaces `(g\u2022z).re = a/c + *` in the standard theory with the following novel identity:\n\n  `g \u2022 z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`\n\n  which does not need to be decomposed depending on whether `c = 0`. -/\nlemma smul_eq_lc_row0_add {p : fin 2 \u2192 \u2124} (hp : is_coprime (p 0) (p 1)) (z : \u210d) {g : SL(2,\u2124)}\n  (hg : \u2191\u2098g 1 = p) :\n  \u2191(g \u2022 z) = ((lc_row0 p \u2191(g : SL(2, \u211d))) : \u2102) / (p 0 ^ 2 + p 1 ^ 2)\n    + ((p 1 : \u2102) * z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1)) :=\nbegin\n  have nonZ1 : (p 0 : \u2102) ^ 2 + (p 1) ^ 2 \u2260 0 := by exact_mod_cast hp.sq_add_sq_ne_zero,\n  have : (coe : \u2124 \u2192 \u211d) \u2218 p \u2260 0 := \u03bb h, hp.ne_zero ((@int.cast_injective \u211d _ _ _).comp_left h),\n  have nonZ2 : (p 0 : \u2102) * z + p 1 \u2260 0 := by simpa using linear_ne_zero _ z this,\n  field_simp [nonZ1, nonZ2, denom_ne_zero, -upper_half_plane.denom, -denom_apply],\n  rw (by simp : (p 1 : \u2102) * z - p 0 = ((p 1) * z - p 0) * \u2191(det (\u2191g : matrix (fin 2) (fin 2) \u2124))),\n  rw [\u2190hg, det_fin_two],\n  simp only [int.coe_cast_ring_hom, coe_matrix_coe, coe_fn_eq_coe,\n    int.cast_mul, of_real_int_cast, map_apply, denom, int.cast_sub],\n  ring,\nend\n\nlemma tendsto_abs_re_smul (z:\u210d) {p : fin 2 \u2192 \u2124} (hp : is_coprime (p 0) (p 1)) :\n  tendsto (\u03bb g : {g : SL(2, \u2124) // \u2191\u2098g 1 = p}, |((g : SL(2, \u2124)) \u2022 z).re|)\n    cofinite at_top :=\nbegin\n  suffices : tendsto (\u03bb g : (\u03bb g : SL(2, \u2124), \u2191\u2098g 1) \u207b\u00b9' {p}, (((g : SL(2, \u2124)) \u2022 z).re))\n    cofinite (cocompact \u211d),\n  { exact tendsto_norm_cocompact_at_top.comp this },\n  have : ((p 0 : \u211d) ^ 2 + p 1 ^ 2)\u207b\u00b9 \u2260 0,\n  { apply inv_ne_zero,\n    exact_mod_cast hp.sq_add_sq_ne_zero },\n  let f := homeomorph.mul_right\u2080 _ this,\n  let ff := homeomorph.add_right (((p 1:\u2102)* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re,\n  convert ((f.trans ff).closed_embedding.tendsto_cocompact).comp (tendsto_lc_row0 hp),\n  ext g,\n  change ((g : SL(2, \u2124)) \u2022 z).re = (lc_row0 p \u2191(\u2191g : SL(2, \u211d))) / (p 0 ^ 2 + p 1 ^ 2)\n  + (((p 1:\u2102 )* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re,\n  exact_mod_cast (congr_arg complex.re (smul_eq_lc_row0_add hp z g.2))\nend\n\nend tendsto_lemmas\n\nsection fundamental_domain\n\nlocal attribute [simp] coe_smul re_smul\n\n/-- For `z : \u210d`, there is a `g : SL(2,\u2124)` maximizing `(g\u2022z).im` -/\nlemma exists_max_im (z : \u210d) :\n  \u2203 g : SL(2, \u2124), \u2200 g' : SL(2, \u2124), (g' \u2022 z).im \u2264 (g \u2022 z).im :=\nbegin\n  classical,\n  let s : set (fin 2 \u2192 \u2124) := {cd | is_coprime (cd 0) (cd 1)},\n  have hs : s.nonempty := \u27e8![1, 1], is_coprime_one_left\u27e9,\n  obtain \u27e8p, hp_coprime, hp\u27e9 :=\n    filter.tendsto.exists_within_forall_le hs (tendsto_norm_sq_coprime_pair z),\n  obtain \u27e8g, -, hg\u27e9 := bottom_row_surj hp_coprime,\n  refine \u27e8g, \u03bb g', _\u27e9,\n  rw [im_smul_eq_div_norm_sq, im_smul_eq_div_norm_sq, div_le_div_left],\n  { simpa [\u2190 hg] using hp (\u2191\u2098g' 1) (bottom_row_coprime g') },\n  { exact z.im_pos },\n  { exact norm_sq_denom_pos g' z },\n  { exact norm_sq_denom_pos g z },\nend\n\n/-- Given `z : \u210d` and a bottom row `(c,d)`, among the `g : SL(2,\u2124)` with this bottom row, minimize\n  `|(g\u2022z).re|`.  -/\nlemma exists_row_one_eq_and_min_re (z:\u210d) {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  \u2203 g : SL(2,\u2124), \u2191\u2098g 1 = cd \u2227 (\u2200 g' : SL(2,\u2124), \u2191\u2098g 1 = \u2191\u2098g' 1 \u2192\n  |(g \u2022 z).re| \u2264 |(g' \u2022 z).re|) :=\nbegin\n  haveI : nonempty {g : SL(2, \u2124) // \u2191\u2098g 1 = cd} :=\n    let \u27e8x, hx\u27e9 := bottom_row_surj hcd in \u27e8\u27e8x, hx.2\u27e9\u27e9,\n  obtain \u27e8g, hg\u27e9 := filter.tendsto.exists_forall_le (tendsto_abs_re_smul z hcd),\n  refine \u27e8g, g.2, _\u27e9,\n  { intros g1 hg1,\n    have : g1 \u2208 ((\u03bb g : SL(2, \u2124), \u2191\u2098g 1) \u207b\u00b9' {cd}),\n    { rw [set.mem_preimage, set.mem_singleton_iff],\n      exact eq.trans hg1.symm (set.mem_singleton_iff.mp (set.mem_preimage.mp g.2)) },\n    exact hg \u27e8g1, this\u27e9 },\nend\n\n/-- The matrix `T = [[1,1],[0,1]]` as an element of `SL(2,\u2124)` -/\ndef T : SL(2,\u2124) := \u27e8![![1, 1], ![0, 1]], by norm_num [matrix.det_fin_two]\u27e9\n\n/-- The matrix `T' (= T\u207b\u00b9) = [[1,-1],[0,1]]` as an element of `SL(2,\u2124)` -/\ndef T' : SL(2,\u2124) := \u27e8![![1, -1], ![0, 1]], by norm_num [matrix.det_fin_two]\u27e9\n\n/-- The matrix `S = [[0,-1],[1,0]]` as an element of `SL(2,\u2124)` -/\ndef S : SL(2,\u2124) := \u27e8![![0, -1], ![1, 0]], by norm_num [matrix.det_fin_two]\u27e9\n\n/-- The standard (closed) fundamental domain of the action of `SL(2,\u2124)` on `\u210d` -/\ndef fundamental_domain : set \u210d :=\n{z | 1 \u2264 (complex.norm_sq z) \u2227 |z.re| \u2264 (1 : \u211d) / 2}\n\nlocalized \"notation `\ud835\udc9f` := modular_group.fundamental_domain\" in modular\n\n/-- If `|z|<1`, then applying `S` strictly decreases `im` -/\nlemma im_lt_im_S_smul {z : \u210d} (h: norm_sq z < 1) : z.im < (S \u2022 z).im :=\nbegin\n  have : z.im < z.im / norm_sq (z:\u2102),\n  { have imz : 0 < z.im := im_pos z,\n    apply (lt_div_iff z.norm_sq_pos).mpr,\n    nlinarith },\n  convert this,\n  simp only [im_smul_eq_div_norm_sq],\n  field_simp [norm_sq_denom_ne_zero, norm_sq_ne_zero, S]\nend\n\n/-- Any `z : \u210d` can be moved to `\ud835\udc9f` by an element of `SL(2,\u2124)`  -/\nlemma exists_smul_mem_fundamental_domain (z : \u210d) : \u2203 g : SL(2,\u2124), g \u2022 z \u2208 \ud835\udc9f :=\nbegin\n  -- obtain a g\u2080 which maximizes im (g \u2022 z),\n  obtain \u27e8g\u2080, hg\u2080\u27e9 := exists_max_im z,\n  -- then among those, minimize re\n  obtain \u27e8g, hg, hg'\u27e9 := exists_row_one_eq_and_min_re z (bottom_row_coprime g\u2080),\n  refine \u27e8g, _\u27e9,\n  -- `g` has same max im property as `g\u2080`\n  have hg\u2080' : \u2200 (g' : SL(2,\u2124)), (g' \u2022 z).im \u2264 (g \u2022 z).im,\n  { have hg'' : (g \u2022 z).im = (g\u2080 \u2022 z).im,\n    { rw [im_smul_eq_div_norm_sq, im_smul_eq_div_norm_sq, denom_apply, denom_apply, hg] },\n    simpa only [hg''] using hg\u2080 },\n  split,\n  { -- Claim: `1 \u2264 \u21d1norm_sq \u2191(g \u2022 z)`. If not, then `S\u2022g\u2022z` has larger imaginary part\n    contrapose! hg\u2080',\n    refine \u27e8S * g, _\u27e9,\n    rw mul_action.mul_smul,\n    exact im_lt_im_S_smul hg\u2080' },\n  { show |(g \u2022 z).re| \u2264 1 / 2, -- if not, then either `T` or `T'` decrease |Re|.\n    rw abs_le,\n    split,\n    { contrapose! hg',\n      refine \u27e8T * g, by simp [T, matrix.mul, matrix.dot_product, fin.sum_univ_succ], _\u27e9,\n      rw mul_action.mul_smul,\n      have : |(g \u2022 z).re + 1| < |(g \u2022 z).re| :=\n        by cases abs_cases ((g \u2022 z).re + 1); cases abs_cases (g \u2022 z).re; linarith,\n      convert this,\n      simp [T] },\n    { contrapose! hg',\n      refine \u27e8T' * g, by simp [T', matrix.mul, matrix.dot_product, fin.sum_univ_succ], _\u27e9,\n      rw mul_action.mul_smul,\n      have : |(g \u2022 z).re - 1| < |(g \u2022 z).re| :=\n        by cases abs_cases ((g \u2022 z).re - 1); cases abs_cases (g \u2022 z).re; linarith,\n      convert this,\n      simp [T', sub_eq_add_neg] } }\nend\n\nend fundamental_domain\n\nend modular_group\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/number_theory/modular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7138277736691127}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n\n! This file was ported from Lean 3 source module linear_algebra.vandermonde\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.BigOperators.Fin\nimport Mathbin.Algebra.GeomSum\nimport Mathbin.LinearAlgebra.Matrix.Determinant\nimport Mathbin.LinearAlgebra.Matrix.Nondegenerate\n\n/-!\n# Vandermonde matrix\n\nThis file defines the `vandermonde` matrix and gives its determinant.\n\n## Main definitions\n\n - `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`.\n\n## Main results\n\n - `det_vandermonde`: `det (vandermonde v)` is the product of `v i - v j`, where\n   `(i, j)` ranges over the unordered pairs.\n-/\n\n\nvariable {R : Type _} [CommRing R]\n\nopen Equiv Finset\n\nopen BigOperators Matrix\n\nnamespace Matrix\n\n/-- `vandermonde v` is the square matrix with `i`th row equal to `1, v i, v i ^ 2, v i ^ 3, ...`.\n-/\ndef vandermonde {n : \u2115} (v : Fin n \u2192 R) : Matrix (Fin n) (Fin n) R := fun i j => v i ^ (j : \u2115)\n#align matrix.vandermonde Matrix.vandermonde\n\n@[simp]\ntheorem vandermonde_apply {n : \u2115} (v : Fin n \u2192 R) (i j) : vandermonde v i j = v i ^ (j : \u2115) :=\n  rfl\n#align matrix.vandermonde_apply Matrix.vandermonde_apply\n\n@[simp]\ntheorem vandermonde_cons {n : \u2115} (v0 : R) (v : Fin n \u2192 R) :\n    vandermonde (Fin.cons v0 v : Fin n.succ \u2192 R) =\n      Fin.cons (fun j => v0 ^ (j : \u2115)) fun i => Fin.cons 1 fun j => v i * vandermonde v i j :=\n  by\n  ext (i j)\n  refine' Fin.cases (by simp) (fun i => _) i\n  refine' Fin.cases (by simp) (fun j => _) j\n  simp [pow_succ]\n#align matrix.vandermonde_cons Matrix.vandermonde_cons\n\ntheorem vandermonde_succ {n : \u2115} (v : Fin n.succ \u2192 R) :\n    vandermonde v =\n      Fin.cons (fun j => v 0 ^ (j : \u2115)) fun i =>\n        Fin.cons 1 fun j => v i.succ * vandermonde (Fin.tail v) i j :=\n  by\n  conv_lhs => rw [\u2190 Fin.cons_self_tail v, vandermonde_cons]\n  simp only [Fin.tail]\n#align matrix.vandermonde_succ Matrix.vandermonde_succ\n\ntheorem vandermonde_mul_vandermonde_transpose {n : \u2115} (v w : Fin n \u2192 R) (i j) :\n    (vandermonde v \u2b1d (vandermonde w)\u1d40) i j = \u2211 k : Fin n, (v i * w j) ^ (k : \u2115) := by\n  simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, mul_pow]\n#align matrix.vandermonde_mul_vandermonde_transpose Matrix.vandermonde_mul_vandermonde_transpose\n\ntheorem vandermonde_transpose_mul_vandermonde {n : \u2115} (v : Fin n \u2192 R) (i j) :\n    ((vandermonde v)\u1d40 \u2b1d vandermonde v) i j = \u2211 k : Fin n, v k ^ (i + j : \u2115) := by\n  simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, pow_add]\n#align matrix.vandermonde_transpose_mul_vandermonde Matrix.vandermonde_transpose_mul_vandermonde\n\ntheorem det_vandermonde {n : \u2115} (v : Fin n \u2192 R) :\n    det (vandermonde v) = \u220f i : Fin n, \u220f j in Ioi i, v j - v i :=\n  by\n  unfold vandermonde\n  induction' n with n ih\n  \u00b7 exact det_eq_one_of_card_eq_zero (Fintype.card_fin 0)\n  calc\n    det (of fun i j : Fin n.succ => v i ^ (j : \u2115)) =\n        det\n          (of fun i j : Fin n.succ =>\n            Matrix.vecCons (v 0 ^ (j : \u2115)) (fun i => v (Fin.succ i) ^ (j : \u2115) - v 0 ^ (j : \u2115)) i) :=\n      det_eq_of_forall_row_eq_smul_add_const (Matrix.vecCons 0 1) 0 (Fin.cons_zero _ _) _\n    _ =\n        det\n          (of fun i j : Fin n =>\n            Matrix.vecCons (v 0 ^ (j.succ : \u2115))\n              (fun i : Fin n => v (Fin.succ i) ^ (j.succ : \u2115) - v 0 ^ (j.succ : \u2115))\n              (Fin.succAbove 0 i)) :=\n      by\n      simp_rw [det_succ_column_zero, Fin.sum_univ_succ, of_apply, Matrix.cons_val_zero, submatrix,\n        of_apply, Matrix.cons_val_succ, Fin.val_zero, pow_zero, one_mul, sub_self,\n        MulZeroClass.mul_zero, MulZeroClass.zero_mul, Finset.sum_const_zero, add_zero]\n    _ =\n        det\n          (of fun i j : Fin n =>\n              (v (Fin.succ i) - v 0) *\n                \u2211 k in Finset.range (j + 1 : \u2115), v i.succ ^ k * v 0 ^ (j - k : \u2115) :\n            Matrix _ _ R) :=\n      by\n      congr\n      ext (i j)\n      rw [Fin.succAbove_zero, Matrix.cons_val_succ, Fin.val_succ, mul_comm]\n      exact (geom_sum\u2082_mul (v i.succ) (v 0) (j + 1 : \u2115)).symm\n    _ =\n        (\u220f i : Fin n, v (Fin.succ i) - v 0) *\n          det fun i j : Fin n =>\n            \u2211 k in Finset.range (j + 1 : \u2115), v i.succ ^ k * v 0 ^ (j - k : \u2115) :=\n      (det_mul_column (fun i => v (Fin.succ i) - v 0) _)\n    _ = (\u220f i : Fin n, v (Fin.succ i) - v 0) * det fun i j : Fin n => v (Fin.succ i) ^ (j : \u2115) :=\n      (congr_arg ((\u00b7 * \u00b7) _) _)\n    _ = \u220f i : Fin n.succ, \u220f j in Ioi i, v j - v i := by\n      simp_rw [ih (v \u2218 Fin.succ), Fin.prod_univ_succ, Fin.prod_Ioi_zero, Fin.prod_Ioi_succ]\n    \n  \u00b7 intro i j\n    simp_rw [of_apply]\n    rw [Matrix.cons_val_zero]\n    refine' Fin.cases _ (fun i => _) i\n    \u00b7 simp\n    rw [Matrix.cons_val_succ, Matrix.cons_val_succ, Pi.one_apply]\n    ring\n  \u00b7 cases n\n    \u00b7 simp only [det_eq_one_of_card_eq_zero (Fintype.card_fin 0)]\n    apply det_eq_of_forall_col_eq_smul_add_pred fun i => v 0\n    \u00b7 intro j\n      simp\n    \u00b7 intro i j\n      simp only [smul_eq_mul, Pi.add_apply, Fin.val_succ, Fin.coe_castSucc, Pi.smul_apply]\n      rw [Finset.sum_range_succ, add_comm, tsub_self, pow_zero, mul_one, Finset.mul_sum]\n      congr 1\n      refine' Finset.sum_congr rfl fun i' hi' => _\n      rw [mul_left_comm (v 0), Nat.succ_sub, pow_succ]\n      exact nat.lt_succ_iff.mp (finset.mem_range.mp hi')\n#align matrix.det_vandermonde Matrix.det_vandermonde\n\ntheorem det_vandermonde_eq_zero_iff [IsDomain R] {n : \u2115} {v : Fin n \u2192 R} :\n    det (vandermonde v) = 0 \u2194 \u2203 i j : Fin n, v i = v j \u2227 i \u2260 j :=\n  by\n  constructor\n  \u00b7 simp only [det_vandermonde v, Finset.prod_eq_zero_iff, sub_eq_zero, forall_exists_index]\n    exact fun i _ j h\u2081 h\u2082 => \u27e8j, i, h\u2082, (mem_Ioi.mp h\u2081).ne'\u27e9\n  \u00b7 simp only [Ne.def, forall_exists_index, and_imp]\n    refine' fun i j h\u2081 h\u2082 => Matrix.det_zero_of_row_eq h\u2082 (funext fun k => _)\n    rw [vandermonde_apply, vandermonde_apply, h\u2081]\n#align matrix.det_vandermonde_eq_zero_iff Matrix.det_vandermonde_eq_zero_iff\n\ntheorem det_vandermonde_ne_zero_iff [IsDomain R] {n : \u2115} {v : Fin n \u2192 R} :\n    det (vandermonde v) \u2260 0 \u2194 Function.Injective v := by\n  simpa only [det_vandermonde_eq_zero_iff, Ne.def, not_exists, not_and, Classical.not_not]\n#align matrix.det_vandermonde_ne_zero_iff Matrix.det_vandermonde_ne_zero_iff\n\ntheorem eq_zero_of_forall_index_sum_pow_mul_eq_zero {R : Type _} [CommRing R] [IsDomain R] {n : \u2115}\n    {f v : Fin n \u2192 R} (hf : Function.Injective f)\n    (hfv : \u2200 j, (\u2211 i : Fin n, f j ^ (i : \u2115) * v i) = 0) : v = 0 :=\n  eq_zero_of_mulVec_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv)\n#align matrix.eq_zero_of_forall_index_sum_pow_mul_eq_zero Matrix.eq_zero_of_forall_index_sum_pow_mul_eq_zero\n\ntheorem eq_zero_of_forall_index_sum_mul_pow_eq_zero {R : Type _} [CommRing R] [IsDomain R] {n : \u2115}\n    {f v : Fin n \u2192 R} (hf : Function.Injective f) (hfv : \u2200 j, (\u2211 i, v i * f j ^ (i : \u2115)) = 0) :\n    v = 0 := by\n  apply eq_zero_of_forall_index_sum_pow_mul_eq_zero hf\n  simp_rw [mul_comm]\n  exact hfv\n#align matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero Matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero\n\ntheorem eq_zero_of_forall_pow_sum_mul_pow_eq_zero {R : Type _} [CommRing R] [IsDomain R] {n : \u2115}\n    {f v : Fin n \u2192 R} (hf : Function.Injective f)\n    (hfv : \u2200 i : Fin n, (\u2211 j : Fin n, v j * f j ^ (i : \u2115)) = 0) : v = 0 :=\n  eq_zero_of_vecMul_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv)\n#align matrix.eq_zero_of_forall_pow_sum_mul_pow_eq_zero Matrix.eq_zero_of_forall_pow_sum_mul_pow_eq_zero\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Vandermonde.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7138277736691127}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport data.enat.basic\nimport data.real.ennreal\n\n/-!\n# Coercion from `\u2115\u221e` to `\u211d\u22650\u221e`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define a coercion from `\u2115\u221e` to `\u211d\u22650\u221e` and prove some basic lemmas about this map.\n-/\n\nopen_locale classical nnreal ennreal\nnoncomputable theory\n\nnamespace enat\n\nvariables {m n : \u2115\u221e}\n\ninstance has_coe_ennreal : has_coe_t \u2115\u221e \u211d\u22650\u221e := \u27e8with_top.map coe\u27e9\n\n@[simp] lemma map_coe_nnreal : with_top.map (coe : \u2115 \u2192 \u211d\u22650) = (coe : \u2115\u221e \u2192 \u211d\u22650\u221e) := rfl\n\n/-- Coercion `\u2115\u221e \u2192 \u211d\u22650\u221e` as an `order_embedding`. -/\n@[simps { fully_applied := ff }] def to_ennreal_order_embedding : \u2115\u221e \u21aao \u211d\u22650\u221e :=\nnat.cast_order_embedding.with_top_map\n\n/-- Coercion `\u2115\u221e \u2192 \u211d\u22650\u221e` as a ring homomorphism. -/\n@[simps { fully_applied := ff }] def to_ennreal_ring_hom : \u2115\u221e \u2192+* \u211d\u22650\u221e :=\n(nat.cast_ring_hom \u211d\u22650).with_top_map nat.cast_injective\n\n@[simp, norm_cast] lemma coe_ennreal_top : ((\u22a4 : \u2115\u221e) : \u211d\u22650\u221e) = \u22a4 := rfl\n@[simp, norm_cast] lemma coe_ennreal_coe (n : \u2115) : ((n : \u2115\u221e) : \u211d\u22650\u221e) = n := rfl\n\n@[simp, norm_cast] lemma coe_ennreal_le : (m : \u211d\u22650\u221e) \u2264 n \u2194 m \u2264 n :=\nto_ennreal_order_embedding.le_iff_le\n\n@[simp, norm_cast] lemma coe_ennreal_lt : (m : \u211d\u22650\u221e) < n \u2194 m < n :=\nto_ennreal_order_embedding.lt_iff_lt\n\n@[mono] lemma coe_ennreal_mono : monotone (coe : \u2115\u221e \u2192 \u211d\u22650\u221e) := to_ennreal_order_embedding.monotone\n\n@[mono] lemma coe_ennreal_strict_mono : strict_mono (coe : \u2115\u221e \u2192 \u211d\u22650\u221e) :=\nto_ennreal_order_embedding.strict_mono\n\n@[simp, norm_cast] lemma coe_ennreal_zero : ((0 : \u2115\u221e) : \u211d\u22650\u221e) = 0 := map_zero to_ennreal_ring_hom\n\n@[simp] lemma coe_ennreal_add (m n : \u2115\u221e) : \u2191(m + n) = (m + n : \u211d\u22650\u221e) :=\nmap_add to_ennreal_ring_hom m n\n\n@[simp] lemma coe_ennreal_one : ((1 : \u2115\u221e) : \u211d\u22650\u221e) = 1 := map_one to_ennreal_ring_hom\n\n@[simp] lemma coe_ennreal_bit0 (n : \u2115\u221e) : \u2191(bit0 n) = bit0 (n : \u211d\u22650\u221e) := coe_ennreal_add n n\n\n@[simp] lemma coe_ennreal_bit1 (n : \u2115\u221e) : \u2191(bit1 n) = bit1 (n : \u211d\u22650\u221e) :=\nmap_bit1 to_ennreal_ring_hom n\n\n@[simp] lemma coe_ennreal_mul (m n : \u2115\u221e) : \u2191(m * n) = (m * n : \u211d\u22650\u221e) :=\nmap_mul to_ennreal_ring_hom m n\n\n@[simp] lemma coe_ennreal_min (m n : \u2115\u221e) : \u2191(min m n) = (min m n : \u211d\u22650\u221e) := coe_ennreal_mono.map_min\n@[simp] lemma coe_ennreal_max (m n : \u2115\u221e) : \u2191(max m n) = (max m n : \u211d\u22650\u221e) := coe_ennreal_mono.map_max\n\n@[simp] lemma coe_ennreal_sub (m n : \u2115\u221e) : \u2191(m - n) = (m - n : \u211d\u22650\u221e) :=\nwith_top.map_sub nat.cast_tsub nat.cast_zero m n\n\nend enat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/real/enat_ennreal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7138277726671056}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport order.complete_boolean_algebra\nimport order.cover\nimport order.modular_lattice\nimport data.fintype.basic\n\n/-!\n# Atoms, Coatoms, and Simple Lattices\n\nThis module defines atoms, which are minimal non-`\u22a5` elements in bounded lattices, simple lattices,\nwhich are lattices with only two elements, and related ideas.\n\n## Main definitions\n\n### Atoms and Coatoms\n  * `is_atom a` indicates that the only element below `a` is `\u22a5`.\n  * `is_coatom a` indicates that the only element above `a` is `\u22a4`.\n\n### Atomic and Atomistic Lattices\n  * `is_atomic` indicates that every element other than `\u22a5` is above an atom.\n  * `is_coatomic` indicates that every element other than `\u22a4` is below a coatom.\n  * `is_atomistic` indicates that every element is the `Sup` of a set of atoms.\n  * `is_coatomistic` indicates that every element is the `Inf` of a set of coatoms.\n\n### Simple Lattices\n  * `is_simple_order` indicates that an order has only two unique elements, `\u22a5` and `\u22a4`.\n  * `is_simple_order.bounded_order`\n  * `is_simple_order.distrib_lattice`\n  * Given an instance of `is_simple_order`, we provide the following definitions. These are not\n    made global instances as they contain data :\n    * `is_simple_order.boolean_algebra`\n    * `is_simple_order.complete_lattice`\n    * `is_simple_order.complete_boolean_algebra`\n\n## Main results\n  * `is_atom_dual_iff_is_coatom` and `is_coatom_dual_iff_is_atom` express the (definitional) duality\n   of `is_atom` and `is_coatom`.\n  * `is_simple_order_iff_is_atom_top` and `is_simple_order_iff_is_coatom_bot` express the\n  connection between atoms, coatoms, and simple lattices\n  * `is_compl.is_atom_iff_is_coatom` and `is_compl.is_coatom_if_is_atom`: In a modular\n  bounded lattice, a complement of an atom is a coatom and vice versa.\n  * `is_atomic_iff_is_coatomic`: A modular complemented lattice is atomic iff it is coatomic.\n  * `fintype.to_is_atomic`, `fintype.to_is_coatomic`: Finite partial orders with bottom resp. top\n    are atomic resp. coatomic.\n\n-/\n\nvariable {\u03b1 : Type*}\n\nsection atoms\n\nsection is_atom\n\n/-- An atom of an `order_bot` is an element with no other element between it and `\u22a5`,\n  which is not `\u22a5`. -/\ndef is_atom [preorder \u03b1] [order_bot \u03b1] (a : \u03b1) : Prop := a \u2260 \u22a5 \u2227 (\u2200 b, b < a \u2192 b = \u22a5)\n\nvariables [partial_order \u03b1] [order_bot \u03b1] {a b x : \u03b1}\n\nlemma eq_bot_or_eq_of_le_atom (ha : is_atom a) (hab : b \u2264 a) : b = \u22a5 \u2228 b = a :=\nhab.lt_or_eq.imp_left (ha.2 b)\n\nlemma is_atom.Iic (ha : is_atom a) (hax : a \u2264 x) : is_atom (\u27e8a, hax\u27e9 : set.Iic x) :=\n\u27e8\u03bb con, ha.1 (subtype.mk_eq_mk.1 con), \u03bb \u27e8b, hb\u27e9 hba, subtype.mk_eq_mk.2 (ha.2 b hba)\u27e9\n\nlemma is_atom.of_is_atom_coe_Iic {a : set.Iic x} (ha : is_atom a) : is_atom (a : \u03b1) :=\n\u27e8\u03bb con, ha.1 (subtype.ext con), \u03bb b hba, subtype.mk_eq_mk.1 (ha.2 \u27e8b, hba.le.trans a.prop\u27e9 hba)\u27e9\n\n@[simp] lemma bot_covby_iff : \u22a5 \u22d6 a \u2194 is_atom a :=\n\u27e8\u03bb h, \u27e8h.lt.ne', \u03bb b hba, not_not.1 $ \u03bb hb, h.2 (ne.bot_lt hb) hba\u27e9,\n  \u03bb h, \u27e8h.1.bot_lt, \u03bb b hb hba, hb.ne' $ h.2 _ hba\u27e9\u27e9\n\nalias bot_covby_iff \u2194 covby.is_atom is_atom.bot_covby\n\nend is_atom\n\nsection is_coatom\n\n/-- A coatom of an `order_top` is an element with no other element between it and `\u22a4`,\n  which is not `\u22a4`. -/\ndef is_coatom [preorder \u03b1] [order_top \u03b1] (a : \u03b1) : Prop := a \u2260 \u22a4 \u2227 (\u2200 b, a < b \u2192 b = \u22a4)\n\nvariables [partial_order \u03b1] [order_top \u03b1] {a b x : \u03b1}\n\nlemma eq_top_or_eq_of_coatom_le (ha : is_coatom a) (hab : a \u2264 b) : b = \u22a4 \u2228 b = a :=\nhab.lt_or_eq.imp (ha.2 b) eq_comm.2\n\nlemma is_coatom.Ici (ha : is_coatom a) (hax : x \u2264 a) : is_coatom (\u27e8a, hax\u27e9 : set.Ici x) :=\n\u27e8\u03bb con, ha.1 (subtype.mk_eq_mk.1 con), \u03bb \u27e8b, hb\u27e9 hba, subtype.mk_eq_mk.2 (ha.2 b hba)\u27e9\n\nlemma is_coatom.of_is_coatom_coe_Ici {a : set.Ici x} (ha : is_coatom a) :\n  is_coatom (a : \u03b1) :=\n\u27e8\u03bb con, ha.1 (subtype.ext con), \u03bb b hba, subtype.mk_eq_mk.1 (ha.2 \u27e8b, le_trans a.prop hba.le\u27e9 hba)\u27e9\n\n@[simp] lemma covby_top_iff : a \u22d6 \u22a4 \u2194 is_coatom a :=\n\u27e8\u03bb h, \u27e8h.ne, \u03bb b hab, not_not.1 $ \u03bb hb, h.2 hab $ ne.lt_top hb\u27e9,\n  \u03bb h, \u27e8h.1.lt_top, \u03bb b hab hb, hb.ne $ h.2 _ hab\u27e9\u27e9\n\nalias covby_top_iff \u2194 covby.is_coatom is_coatom.covby_top\n\nend is_coatom\n\nsection pairwise\n\nlemma is_atom.inf_eq_bot_of_ne [semilattice_inf \u03b1] [order_bot \u03b1] {a b : \u03b1}\n  (ha : is_atom a) (hb : is_atom b) (hab : a \u2260 b) : a \u2293 b = \u22a5 :=\nor.elim (eq_bot_or_eq_of_le_atom ha inf_le_left) id\n  (\u03bb h1, or.elim (eq_bot_or_eq_of_le_atom hb inf_le_right) id\n  (\u03bb h2, false.rec _ (hab (le_antisymm (inf_eq_left.mp h1) (inf_eq_right.mp h2)))))\n\nlemma is_atom.disjoint_of_ne [semilattice_inf \u03b1] [order_bot \u03b1] {a b : \u03b1}\n  (ha : is_atom a) (hb : is_atom b) (hab : a \u2260 b) : disjoint a b :=\ndisjoint_iff.mpr (is_atom.inf_eq_bot_of_ne ha hb hab)\n\nlemma is_coatom.sup_eq_top_of_ne [semilattice_sup \u03b1] [order_top \u03b1] {a b : \u03b1}\n  (ha : is_coatom a) (hb : is_coatom b) (hab : a \u2260 b) : a \u2294 b = \u22a4 :=\nor.elim (eq_top_or_eq_of_coatom_le ha le_sup_left) id\n  (\u03bb h1, or.elim (eq_top_or_eq_of_coatom_le hb le_sup_right) id\n  (\u03bb h2, false.rec _ (hab (le_antisymm (sup_eq_right.mp h2) (sup_eq_left.mp h1)))))\n\nend pairwise\n\nvariables [preorder \u03b1] {a : \u03b1}\n\n@[simp]\nlemma is_coatom_dual_iff_is_atom [order_bot \u03b1] :\n  is_coatom (order_dual.to_dual a) \u2194 is_atom a :=\niff.rfl\n\n@[simp]\nlemma is_atom_dual_iff_is_coatom [order_top \u03b1] :\n  is_atom (order_dual.to_dual a) \u2194 is_coatom a :=\niff.rfl\n\nend atoms\n\nsection atomic\n\nvariables [partial_order \u03b1] (\u03b1)\n\n/-- A lattice is atomic iff every element other than `\u22a5` has an atom below it. -/\nclass is_atomic [order_bot \u03b1] : Prop :=\n(eq_bot_or_exists_atom_le : \u2200 (b : \u03b1), b = \u22a5 \u2228 \u2203 (a : \u03b1), is_atom a \u2227 a \u2264 b)\n\n/-- A lattice is coatomic iff every element other than `\u22a4` has a coatom above it. -/\nclass is_coatomic [order_top \u03b1] : Prop :=\n(eq_top_or_exists_le_coatom : \u2200 (b : \u03b1), b = \u22a4 \u2228 \u2203 (a : \u03b1), is_coatom a \u2227 b \u2264 a)\n\nexport is_atomic (eq_bot_or_exists_atom_le) is_coatomic (eq_top_or_exists_le_coatom)\n\nvariable {\u03b1}\n\n@[simp] theorem is_coatomic_dual_iff_is_atomic [order_bot \u03b1] :\n  is_coatomic (order_dual \u03b1) \u2194 is_atomic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_top_or_exists_le_coatom\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_bot_or_exists_atom_le\u27e9\u27e9\n\n@[simp] theorem is_atomic_dual_iff_is_coatomic [order_top \u03b1] :\n  is_atomic (order_dual \u03b1) \u2194 is_coatomic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_bot_or_exists_atom_le\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_top_or_exists_le_coatom\u27e9\u27e9\n\nnamespace is_atomic\n\nvariables [order_bot \u03b1] [is_atomic \u03b1]\n\ninstance is_coatomic_dual : is_coatomic (order_dual \u03b1) :=\nis_coatomic_dual_iff_is_atomic.2 \u2039is_atomic \u03b1\u203a\n\ninstance {x : \u03b1} : is_atomic (set.Iic x) :=\n\u27e8\u03bb \u27e8y, hy\u27e9, (eq_bot_or_exists_atom_le y).imp subtype.mk_eq_mk.2\n  (\u03bb \u27e8a, ha, hay\u27e9, \u27e8\u27e8a, hay.trans hy\u27e9, ha.Iic (hay.trans hy), hay\u27e9)\u27e9\n\nend is_atomic\n\nnamespace is_coatomic\n\nvariables [order_top \u03b1] [is_coatomic \u03b1]\n\ninstance is_coatomic : is_atomic (order_dual \u03b1) :=\nis_atomic_dual_iff_is_coatomic.2 \u2039is_coatomic \u03b1\u203a\n\ninstance {x : \u03b1} : is_coatomic (set.Ici x) :=\n\u27e8\u03bb \u27e8y, hy\u27e9, (eq_top_or_exists_le_coatom y).imp subtype.mk_eq_mk.2\n  (\u03bb \u27e8a, ha, hay\u27e9, \u27e8\u27e8a, le_trans hy hay\u27e9, ha.Ici (le_trans hy hay), hay\u27e9)\u27e9\n\nend is_coatomic\n\ntheorem is_atomic_iff_forall_is_atomic_Iic [order_bot \u03b1] :\n  is_atomic \u03b1 \u2194 \u2200 (x : \u03b1), is_atomic (set.Iic x) :=\n\u27e8@is_atomic.set.Iic.is_atomic _ _ _, \u03bb h, \u27e8\u03bb x, ((@eq_bot_or_exists_atom_le _ _ _ (h x))\n  (\u22a4 : set.Iic x)).imp subtype.mk_eq_mk.1 (exists_imp_exists' coe\n  (\u03bb \u27e8a, ha\u27e9, and.imp_left (is_atom.of_is_atom_coe_Iic)))\u27e9\u27e9\n\ntheorem is_coatomic_iff_forall_is_coatomic_Ici [order_top \u03b1] :\n  is_coatomic \u03b1 \u2194 \u2200 (x : \u03b1), is_coatomic (set.Ici x) :=\nis_atomic_dual_iff_is_coatomic.symm.trans $ is_atomic_iff_forall_is_atomic_Iic.trans $ forall_congr\n  (\u03bb x, is_coatomic_dual_iff_is_atomic.symm.trans iff.rfl)\n\nend atomic\n\nsection atomistic\n\nvariables (\u03b1) [complete_lattice \u03b1]\n\n/-- A lattice is atomistic iff every element is a `Sup` of a set of atoms. -/\nclass is_atomistic : Prop :=\n(eq_Sup_atoms : \u2200 (b : \u03b1), \u2203 (s : set \u03b1), b = Sup s \u2227 \u2200 a, a \u2208 s \u2192 is_atom a)\n\n/-- A lattice is coatomistic iff every element is an `Inf` of a set of coatoms. -/\nclass is_coatomistic : Prop :=\n(eq_Inf_coatoms : \u2200 (b : \u03b1), \u2203 (s : set \u03b1), b = Inf s \u2227 \u2200 a, a \u2208 s \u2192 is_coatom a)\n\nexport is_atomistic (eq_Sup_atoms) is_coatomistic (eq_Inf_coatoms)\n\nvariable {\u03b1}\n\n@[simp]\ntheorem is_coatomistic_dual_iff_is_atomistic : is_coatomistic (order_dual \u03b1) \u2194 is_atomistic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_Inf_coatoms\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_Sup_atoms\u27e9\u27e9\n\n@[simp]\ntheorem is_atomistic_dual_iff_is_coatomistic : is_atomistic (order_dual \u03b1) \u2194 is_coatomistic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_Sup_atoms\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_Inf_coatoms\u27e9\u27e9\n\nnamespace is_atomistic\n\ninstance is_coatomistic_dual [h : is_atomistic \u03b1] : is_coatomistic (order_dual \u03b1) :=\nis_coatomistic_dual_iff_is_atomistic.2 h\n\nvariable [is_atomistic \u03b1]\n\n@[priority 100]\ninstance : is_atomic \u03b1 :=\n\u27e8\u03bb b, by { rcases eq_Sup_atoms b with \u27e8s, rfl, hs\u27e9,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ \u27e8h.some, hs _ h.some_spec, le_Sup h.some_spec\u27e9 } } \u27e9\n\nend is_atomistic\n\nsection is_atomistic\nvariables [is_atomistic \u03b1]\n\n@[simp]\ntheorem Sup_atoms_le_eq (b : \u03b1) : Sup {a : \u03b1 | is_atom a \u2227 a \u2264 b} = b :=\nbegin\n  rcases eq_Sup_atoms b with \u27e8s, rfl, hs\u27e9,\n  exact le_antisymm (Sup_le (\u03bb _, and.right)) (Sup_le_Sup (\u03bb a ha, \u27e8hs a ha, le_Sup ha\u27e9)),\nend\n\n@[simp]\ntheorem Sup_atoms_eq_top : Sup {a : \u03b1 | is_atom a} = \u22a4 :=\nbegin\n  refine eq.trans (congr rfl (set.ext (\u03bb x, _))) (Sup_atoms_le_eq \u22a4),\n  exact (and_iff_left le_top).symm,\nend\n\ntheorem le_iff_atom_le_imp {a b : \u03b1} :\n  a \u2264 b \u2194 \u2200 c : \u03b1, is_atom c \u2192 c \u2264 a \u2192 c \u2264 b :=\n\u27e8\u03bb ab c hc ca, le_trans ca ab, \u03bb h, begin\n  rw [\u2190 Sup_atoms_le_eq a, \u2190 Sup_atoms_le_eq b],\n  exact Sup_le_Sup (\u03bb c hc, \u27e8hc.1, h c hc.1 hc.2\u27e9),\nend\u27e9\n\nend is_atomistic\n\nnamespace is_coatomistic\n\ninstance is_atomistic_dual [h : is_coatomistic \u03b1] : is_atomistic (order_dual \u03b1) :=\nis_atomistic_dual_iff_is_coatomistic.2 h\n\nvariable [is_coatomistic \u03b1]\n\n@[priority 100]\ninstance : is_coatomic \u03b1 :=\n\u27e8\u03bb b, by { rcases eq_Inf_coatoms b with \u27e8s, rfl, hs\u27e9,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ \u27e8h.some, hs _ h.some_spec, Inf_le h.some_spec\u27e9 } } \u27e9\n\nend is_coatomistic\nend atomistic\n\n/-- An order is simple iff it has exactly two elements, `\u22a5` and `\u22a4`. -/\nclass is_simple_order (\u03b1 : Type*) [has_le \u03b1] [bounded_order \u03b1] extends nontrivial \u03b1 : Prop :=\n(eq_bot_or_eq_top : \u2200 (a : \u03b1), a = \u22a5 \u2228 a = \u22a4)\n\nexport is_simple_order (eq_bot_or_eq_top)\n\ntheorem is_simple_order_iff_is_simple_order_order_dual [has_le \u03b1] [bounded_order \u03b1] :\n  is_simple_order \u03b1 \u2194 is_simple_order (order_dual \u03b1) :=\nbegin\n  split; intro i; haveI := i,\n  { exact { exists_pair_ne := @exists_pair_ne \u03b1 _,\n      eq_bot_or_eq_top := \u03bb a, or.symm (eq_bot_or_eq_top ((order_dual.of_dual a)) : _ \u2228 _) } },\n  { exact { exists_pair_ne := @exists_pair_ne (order_dual \u03b1) _,\n      eq_bot_or_eq_top := \u03bb a, or.symm (eq_bot_or_eq_top (order_dual.to_dual a)) } }\nend\n\nlemma is_simple_order.bot_ne_top [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] :\n  (\u22a5 : \u03b1) \u2260 (\u22a4 : \u03b1) :=\nbegin\n  obtain \u27e8a, b, h\u27e9 := exists_pair_ne \u03b1,\n  rcases eq_bot_or_eq_top a with rfl|rfl;\n  rcases eq_bot_or_eq_top b with rfl|rfl;\n  simpa <|> simpa using h.symm\nend\n\nsection is_simple_order\n\nvariables [partial_order \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\n\ninstance {\u03b1} [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] : is_simple_order (order_dual \u03b1) :=\nis_simple_order_iff_is_simple_order_order_dual.1 (by apply_instance)\n\n/-- A simple `bounded_order` induces a preorder. This is not an instance to prevent loops. -/\nprotected def is_simple_order.preorder {\u03b1} [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] :\n  preorder \u03b1 :=\n{ le := (\u2264),\n  le_refl := \u03bb a, by rcases eq_bot_or_eq_top a with rfl|rfl; simp,\n  le_trans := \u03bb a b c, begin\n    rcases eq_bot_or_eq_top a with rfl|rfl,\n    { simp },\n    { rcases eq_bot_or_eq_top b with rfl|rfl,\n      { rcases eq_bot_or_eq_top c with rfl|rfl; simp },\n      { simp } }\n  end }\n\n/-- A simple partial ordered `bounded_order` induces a linear order.\nThis is not an instance to prevent loops. -/\nprotected def is_simple_order.linear_order [decidable_eq \u03b1] : linear_order \u03b1 :=\n{ le_total := \u03bb a b, by rcases eq_bot_or_eq_top a with rfl|rfl; simp,\n  decidable_le := \u03bb a b, if ha : a = \u22a5 then is_true (ha.le.trans bot_le) else\n    if hb : b = \u22a4 then is_true (le_top.trans hb.ge) else\n      is_false (\u03bb H, hb (top_unique\n        (le_trans (top_le_iff.mpr (or.resolve_left (eq_bot_or_eq_top a) ha)) H))),\n  decidable_eq := by assumption,\n  ..(infer_instance : partial_order \u03b1) }\n\n@[simp] lemma is_atom_top : is_atom (\u22a4 : \u03b1) :=\n\u27e8top_ne_bot, \u03bb a ha, or.resolve_right (eq_bot_or_eq_top a) (ne_of_lt ha)\u27e9\n\n@[simp] lemma is_coatom_bot : is_coatom (\u22a5 : \u03b1) := is_atom_dual_iff_is_coatom.1 is_atom_top\n\nlemma bot_covby_top : (\u22a5 : \u03b1) \u22d6 \u22a4 := is_atom_top.bot_covby\n\nend is_simple_order\n\nnamespace is_simple_order\nsection preorder\nvariables [preorder \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] {a b : \u03b1} (h : a < b)\n\nlemma eq_bot_of_lt : a = \u22a5 := (is_simple_order.eq_bot_or_eq_top _).resolve_right h.ne_top\nlemma eq_top_of_lt : b = \u22a4 := (is_simple_order.eq_bot_or_eq_top _).resolve_left h.ne_bot\n\nalias eq_bot_of_lt \u2190 has_lt.lt.eq_bot\nalias eq_top_of_lt \u2190 has_lt.lt.eq_top\n\nend preorder\n\nsection bounded_order\n\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\n\n/-- A simple partial ordered `bounded_order` induces a lattice.\nThis is not an instance to prevent loops -/\nprotected def lattice {\u03b1} [decidable_eq \u03b1] [partial_order \u03b1] [bounded_order \u03b1]\n  [is_simple_order \u03b1] : lattice \u03b1 :=\n@linear_order.to_lattice \u03b1 (is_simple_order.linear_order)\n\n/-- A lattice that is a `bounded_order` is a distributive lattice.\nThis is not an instance to prevent loops -/\nprotected def distrib_lattice : distrib_lattice \u03b1 :=\n{ le_sup_inf := \u03bb x y z, by { rcases eq_bot_or_eq_top x with rfl | rfl; simp },\n  .. (infer_instance : lattice \u03b1) }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : is_atomic \u03b1 :=\n\u27e8\u03bb b, (eq_bot_or_eq_top b).imp_right (\u03bb h, \u27e8\u22a4, \u27e8is_atom_top, ge_of_eq h\u27e9\u27e9)\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : is_coatomic \u03b1 := is_atomic_dual_iff_is_coatomic.1 is_simple_order.is_atomic\n\nend bounded_order\n\n/- It is important that in this section `is_simple_order` is the last type-class argument. -/\nsection decidable_eq\n\nvariables [decidable_eq \u03b1] [partial_order \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\n\n/-- Every simple lattice is isomorphic to `bool`, regardless of order. -/\n@[simps] def equiv_bool {\u03b1} [decidable_eq \u03b1] [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] :\n  \u03b1 \u2243 bool :=\n{ to_fun := \u03bb x, x = \u22a4,\n  inv_fun := \u03bb x, cond x \u22a4 \u22a5,\n  left_inv := \u03bb x, by { rcases (eq_bot_or_eq_top x) with rfl | rfl; simp [bot_ne_top] },\n  right_inv := \u03bb x, by { cases x; simp [bot_ne_top] } }\n\n/-- Every simple lattice over a partial order is order-isomorphic to `bool`. -/\ndef order_iso_bool : \u03b1 \u2243o bool :=\n{ map_rel_iff' := \u03bb a b, begin\n    rcases (eq_bot_or_eq_top a) with rfl | rfl,\n    { simp [bot_ne_top] },\n    { rcases (eq_bot_or_eq_top b) with rfl | rfl,\n      { simp [bot_ne_top.symm, bot_ne_top, bool.ff_lt_tt] },\n      { simp [bot_ne_top] } }\n  end,\n  ..equiv_bool }\n\n/- It is important that `is_simple_order` is the last type-class argument of this instance,\nso that type-class inference fails quickly if it doesn't apply. -/\n@[priority 200]\ninstance {\u03b1} [decidable_eq \u03b1] [has_le \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] : fintype \u03b1 :=\nfintype.of_equiv bool equiv_bool.symm\n\n/-- A simple `bounded_order` is also a `boolean_algebra`. -/\nprotected def boolean_algebra {\u03b1} [decidable_eq \u03b1] [lattice \u03b1] [bounded_order \u03b1]\n  [is_simple_order \u03b1] : boolean_algebra \u03b1 :=\n{ compl := \u03bb x, if x = \u22a5 then \u22a4 else \u22a5,\n  sdiff := \u03bb x y, if x = \u22a4 \u2227 y = \u22a5 then \u22a4 else \u22a5,\n  sdiff_eq := \u03bb x y, by rcases eq_bot_or_eq_top x with rfl | rfl;\n      simp [bot_ne_top, has_sdiff.sdiff, compl],\n  inf_compl_le_bot := \u03bb x, begin\n      rcases eq_bot_or_eq_top x with rfl | rfl,\n      { simp },\n      { simp only [top_inf_eq],\n        split_ifs with h h;\n        simp [h] }\n    end,\n  top_le_sup_compl := \u03bb x, by rcases eq_bot_or_eq_top x with rfl | rfl; simp,\n  sup_inf_sdiff := \u03bb x y, by rcases eq_bot_or_eq_top x with rfl | rfl;\n      rcases eq_bot_or_eq_top y with rfl | rfl; simp [bot_ne_top],\n  inf_inf_sdiff := \u03bb x y, begin\n      rcases eq_bot_or_eq_top x with rfl | rfl,\n      { simpa },\n      rcases eq_bot_or_eq_top y with rfl | rfl,\n      { simpa },\n      { simp only [true_and, top_inf_eq, eq_self_iff_true],\n        split_ifs with h h;\n        simpa [h] }\n    end,\n  .. (show bounded_order \u03b1, by apply_instance),\n  .. is_simple_order.distrib_lattice }\n\nend decidable_eq\n\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1]\nopen_locale classical\n\n/-- A simple `bounded_order` is also complete. -/\nprotected noncomputable def complete_lattice : complete_lattice \u03b1 :=\n{ Sup := \u03bb s, if \u22a4 \u2208 s then \u22a4 else \u22a5,\n  Inf := \u03bb s, if \u22a5 \u2208 s then \u22a5 else \u22a4,\n  le_Sup := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { exact bot_le },\n    { rw if_pos h } },\n  Sup_le := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { rw if_neg,\n      intro con,\n      exact bot_ne_top (eq_top_iff.2 (h \u22a4 con)) },\n    { exact le_top } },\n  Inf_le := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { rw if_pos h },\n    { exact le_top } },\n  le_Inf := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { exact bot_le },\n    { rw if_neg,\n      intro con,\n      exact top_ne_bot (eq_bot_iff.2 (h \u22a5 con)) } },\n  .. (infer_instance : lattice \u03b1),\n  .. (infer_instance : bounded_order \u03b1) }\n\n/-- A simple `bounded_order` is also a `complete_boolean_algebra`. -/\nprotected noncomputable def complete_boolean_algebra : complete_boolean_algebra \u03b1 :=\n{ infi_sup_le_sup_Inf := \u03bb x s, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { simp only [bot_sup_eq, \u2190 Inf_eq_infi], exact le_rfl },\n    { simp only [top_sup_eq, le_top] }, },\n  inf_Sup_le_supr_inf := \u03bb x s, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { simp only [bot_inf_eq, bot_le] },\n    { simp only [top_inf_eq, \u2190 Sup_eq_supr], exact le_rfl } },\n  .. is_simple_order.complete_lattice,\n  .. is_simple_order.boolean_algebra }\n\nend is_simple_order\n\nnamespace is_simple_order\nvariables [complete_lattice \u03b1] [is_simple_order \u03b1]\nset_option default_priority 100\n\ninstance : is_atomistic \u03b1 :=\n\u27e8\u03bb b, (eq_bot_or_eq_top b).elim\n  (\u03bb h, \u27e8\u2205, \u27e8h.trans Sup_empty.symm, \u03bb a ha, false.elim (set.not_mem_empty _ ha)\u27e9\u27e9)\n  (\u03bb h, \u27e8{\u22a4}, h.trans Sup_singleton.symm, \u03bb a ha, (set.mem_singleton_iff.1 ha).symm \u25b8 is_atom_top\u27e9)\u27e9\n\ninstance : is_coatomistic \u03b1 := is_atomistic_dual_iff_is_coatomistic.1 is_simple_order.is_atomistic\n\nend is_simple_order\nnamespace fintype\nnamespace is_simple_order\nvariables [partial_order \u03b1] [bounded_order \u03b1] [is_simple_order \u03b1] [decidable_eq \u03b1]\n\nlemma univ : (finset.univ : finset \u03b1) = {\u22a4, \u22a5} :=\nbegin\n  change finset.map _ (finset.univ : finset bool) = _,\n  rw fintype.univ_bool,\n  simp only [finset.map_insert, function.embedding.coe_fn_mk, finset.map_singleton],\n  refl,\nend\n\nlemma card : fintype.card \u03b1 = 2 :=\n(fintype.of_equiv_card _).trans fintype.card_bool\n\nend is_simple_order\nend fintype\n\nnamespace bool\n\ninstance : is_simple_order bool :=\n\u27e8\u03bb a, begin\n  rw [\u2190 finset.mem_singleton, or.comm, \u2190 finset.mem_insert,\n      top_eq_tt, bot_eq_ff, \u2190 fintype.univ_bool],\n  apply finset.mem_univ,\nend\u27e9\n\nend bool\n\ntheorem is_simple_order_iff_is_atom_top [partial_order \u03b1] [bounded_order \u03b1] :\n  is_simple_order \u03b1 \u2194 is_atom (\u22a4 : \u03b1) :=\n\u27e8\u03bb h, @is_atom_top _ _ _ h, \u03bb h,\n  { exists_pair_ne := \u27e8\u22a4, \u22a5, h.1\u27e9,\n    eq_bot_or_eq_top := \u03bb a, ((eq_or_lt_of_le le_top).imp_right (h.2 a)).symm }\u27e9\n\ntheorem is_simple_order_iff_is_coatom_bot [partial_order \u03b1] [bounded_order \u03b1] :\n  is_simple_order \u03b1 \u2194 is_coatom (\u22a5 : \u03b1) :=\nis_simple_order_iff_is_simple_order_order_dual.trans is_simple_order_iff_is_atom_top\n\nnamespace set\n\ntheorem is_simple_order_Iic_iff_is_atom [partial_order \u03b1] [order_bot \u03b1] {a : \u03b1} :\n  is_simple_order (Iic a) \u2194 is_atom a :=\nis_simple_order_iff_is_atom_top.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  \u27e8\u03bb h b ab, subtype.mk_eq_mk.1 (h \u27e8b, le_of_lt ab\u27e9 ab),\n    \u03bb h \u27e8b, hab\u27e9 hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))\u27e9\n\ntheorem is_simple_order_Ici_iff_is_coatom [partial_order \u03b1] [order_top \u03b1] {a : \u03b1} :\n  is_simple_order (Ici a) \u2194 is_coatom a :=\nis_simple_order_iff_is_coatom_bot.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  \u27e8\u03bb h b ab, subtype.mk_eq_mk.1 (h \u27e8b, le_of_lt ab\u27e9 ab),\n    \u03bb h \u27e8b, hab\u27e9 hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))\u27e9\n\nend set\n\nnamespace order_iso\n\nvariables {\u03b2 : Type*}\n\n@[simp] lemma is_atom_iff [partial_order \u03b1] [order_bot \u03b1] [partial_order \u03b2] [order_bot \u03b2]\n  (f : \u03b1 \u2243o \u03b2) (a : \u03b1) :\n  is_atom (f a) \u2194 is_atom a :=\nand_congr (not_congr \u27e8\u03bb h, f.injective (f.map_bot.symm \u25b8 h), \u03bb h, f.map_bot \u25b8 (congr rfl h)\u27e9)\n  \u27e8\u03bb h b hb, f.injective ((h (f b) ((f : \u03b1 \u21aao \u03b2).lt_iff_lt.2 hb)).trans f.map_bot.symm),\n  \u03bb h b hb, f.symm.injective begin\n    rw f.symm.map_bot,\n    apply h,\n    rw [\u2190 f.symm_apply_apply a],\n    exact (f.symm : \u03b2 \u21aao \u03b1).lt_iff_lt.2 hb,\n  end\u27e9\n\n@[simp] lemma is_coatom_iff [partial_order \u03b1] [order_top \u03b1] [partial_order \u03b2] [order_top \u03b2]\n  (f : \u03b1 \u2243o \u03b2) (a : \u03b1) :\n  is_coatom (f a) \u2194 is_coatom a :=\nf.dual.is_atom_iff a\n\nlemma is_simple_order_iff [partial_order \u03b1] [bounded_order \u03b1] [partial_order \u03b2] [bounded_order \u03b2]\n  (f : \u03b1 \u2243o \u03b2) :\n  is_simple_order \u03b1 \u2194 is_simple_order \u03b2 :=\nby rw [is_simple_order_iff_is_atom_top, is_simple_order_iff_is_atom_top,\n  \u2190 f.is_atom_iff \u22a4, f.map_top]\n\nlemma is_simple_order [partial_order \u03b1] [bounded_order \u03b1] [partial_order \u03b2] [bounded_order \u03b2]\n  [h : is_simple_order \u03b2] (f : \u03b1 \u2243o \u03b2) :\n  is_simple_order \u03b1 :=\nf.is_simple_order_iff.mpr h\n\nlemma is_atomic_iff [partial_order \u03b1] [order_bot \u03b1] [partial_order \u03b2] [order_bot \u03b2] (f : \u03b1 \u2243o \u03b2) :\n  is_atomic \u03b1 \u2194 is_atomic \u03b2 :=\nbegin\n  suffices : (\u2200 b : \u03b1, b = \u22a5 \u2228 \u2203 (a : \u03b1), is_atom a \u2227 a \u2264 b) \u2194\n    (\u2200 b : \u03b2, b = \u22a5 \u2228 \u2203 (a : \u03b2), is_atom a \u2227 a \u2264 b),\n  from \u27e8\u03bb \u27e8p\u27e9, \u27e8this.mp p\u27e9, \u03bb \u27e8p\u27e9, \u27e8this.mpr p\u27e9\u27e9,\n  apply f.to_equiv.forall_congr,\n  simp_rw [rel_iso.coe_fn_to_equiv],\n  intro b, apply or_congr,\n  { rw [f.apply_eq_iff_eq_symm_apply, map_bot], },\n  { split,\n    { exact \u03bb \u27e8a, ha\u27e9, \u27e8f a, \u27e8(f.is_atom_iff a).mpr ha.1, f.le_iff_le.mpr ha.2\u27e9\u27e9, },\n    { rintros \u27e8b, \u27e8hb1, hb2\u27e9\u27e9,\n      refine \u27e8f.symm b, \u27e8(f.symm.is_atom_iff b).mpr hb1, _\u27e9\u27e9,\n      rwa [\u2190f.le_iff_le, f.apply_symm_apply], }, },\nend\n\nlemma is_coatomic_iff [partial_order \u03b1] [order_top \u03b1] [partial_order \u03b2] [order_top \u03b2] (f : \u03b1 \u2243o \u03b2) :\n  is_coatomic \u03b1 \u2194 is_coatomic \u03b2 :=\nby { rw [\u2190is_atomic_dual_iff_is_coatomic, \u2190is_atomic_dual_iff_is_coatomic],\n  exact f.dual.is_atomic_iff }\n\nend order_iso\n\nsection is_modular_lattice\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_modular_lattice \u03b1]\n\nnamespace is_compl\nvariables {a b : \u03b1} (hc : is_compl a b)\ninclude hc\n\nlemma is_atom_iff_is_coatom : is_atom a \u2194 is_coatom b :=\nset.is_simple_order_Iic_iff_is_atom.symm.trans $ hc.Iic_order_iso_Ici.is_simple_order_iff.trans\n  set.is_simple_order_Ici_iff_is_coatom\n\nlemma is_coatom_iff_is_atom : is_coatom a \u2194 is_atom b := hc.symm.is_atom_iff_is_coatom.symm\n\nend is_compl\n\nvariables [is_complemented \u03b1]\n\nlemma is_coatomic_of_is_atomic_of_is_complemented_of_is_modular [is_atomic \u03b1] : is_coatomic \u03b1 :=\n\u27e8\u03bb x, begin\n  rcases exists_is_compl x with \u27e8y, xy\u27e9,\n  apply (eq_bot_or_exists_atom_le y).imp _ _,\n  { rintro rfl,\n    exact eq_top_of_is_compl_bot xy },\n  { rintro \u27e8a, ha, ay\u27e9,\n    rcases exists_is_compl (xy.symm.Iic_order_iso_Ici \u27e8a, ay\u27e9) with \u27e8\u27e8b, xb\u27e9, hb\u27e9,\n    refine \u27e8\u2191(\u27e8b, xb\u27e9 : set.Ici x), is_coatom.of_is_coatom_coe_Ici _, xb\u27e9,\n    rw [\u2190 hb.is_atom_iff_is_coatom, order_iso.is_atom_iff],\n    apply ha.Iic }\nend\u27e9\n\nlemma is_atomic_of_is_coatomic_of_is_complemented_of_is_modular [is_coatomic \u03b1] : is_atomic \u03b1 :=\nis_coatomic_dual_iff_is_atomic.1 is_coatomic_of_is_atomic_of_is_complemented_of_is_modular\n\ntheorem is_atomic_iff_is_coatomic : is_atomic \u03b1 \u2194 is_coatomic \u03b1 :=\n\u27e8\u03bb h, @is_coatomic_of_is_atomic_of_is_complemented_of_is_modular _ _ _ _ _ h,\n  \u03bb h, @is_atomic_of_is_coatomic_of_is_complemented_of_is_modular _ _ _ _ _ h\u27e9\n\nend is_modular_lattice\n\nsection fintype\n\nopen finset\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance fintype.to_is_coatomic [partial_order \u03b1] [order_top \u03b1] [fintype \u03b1] : is_coatomic \u03b1 :=\nbegin\n  refine is_coatomic.mk (\u03bb b, or_iff_not_imp_left.2 (\u03bb ht, _)),\n  obtain \u27e8c, hc, hmax\u27e9 := set.finite.exists_maximal_wrt id { x : \u03b1 | b \u2264 x \u2227 x \u2260 \u22a4 }\n    (set.finite.of_fintype _) \u27e8b, le_rfl, ht\u27e9,\n  refine \u27e8c, \u27e8hc.2, \u03bb y hcy, _\u27e9, hc.1\u27e9,\n  by_contra hyt,\n  obtain rfl : c = y := hmax y \u27e8hc.1.trans hcy.le, hyt\u27e9 hcy.le,\n  exact (lt_self_iff_false _).mp hcy\nend\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance fintype.to_is_atomic [partial_order \u03b1] [order_bot \u03b1] [fintype \u03b1] : is_atomic \u03b1 :=\nis_coatomic_dual_iff_is_atomic.mp fintype.to_is_coatomic\n\nend fintype\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/order/atoms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530937, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7138277713025977}}
{"text": "/-\nCopyright (c) 2018 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\nimport topology.algebra.ring.basic\nimport ring_theory.ideal.quotient\n/-!\n# Ideals and quotients of topological rings\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define `ideal.closure` to be the topological closure of an ideal in a topological\nring. We also define a `topological_space` structure on the quotient of a topological ring by an\nideal and prove that the quotient is a topological ring.\n-/\n\nsection ring\nvariables {R : Type*} [topological_space R] [ring R] [topological_ring R]\n\n/-- The closure of an ideal in a topological ring as an ideal. -/\nprotected def ideal.closure (I : ideal R) : ideal R :=\n{ carrier   := closure I,\n  smul_mem' := \u03bb c x hx, map_mem_closure (mul_left_continuous _) hx $ \u03bb a, I.mul_mem_left c,\n  ..(add_submonoid.topological_closure I.to_add_submonoid) }\n\n@[simp] lemma ideal.coe_closure (I : ideal R) : (I.closure : set R) = closure I := rfl\n\n@[simp] lemma ideal.closure_eq_of_is_closed (I : ideal R) [hI : is_closed (I : set R)] :\n  I.closure = I :=\nset_like.ext' hI.closure_eq\n\nend ring\n\nsection comm_ring\nvariables {R : Type*} [topological_space R] [comm_ring R] (N : ideal R)\nopen ideal.quotient\n\ninstance topological_ring_quotient_topology : topological_space (R \u29f8 N) :=\nquotient.topological_space\n\n-- note for the reader: in the following, `mk` is `ideal.quotient.mk`, the canonical map `R \u2192 R/I`.\n\nvariable [topological_ring R]\n\nlemma quotient_ring.is_open_map_coe : is_open_map (mk N) :=\nbegin\n  intros s s_op,\n  change is_open (mk N \u207b\u00b9' (mk N '' s)),\n  rw quotient_ring_saturate,\n  exact is_open_Union (\u03bb \u27e8n, _\u27e9, is_open_map_add_left n s s_op)\nend\n\nlemma quotient_ring.quotient_map_coe_coe : quotient_map (\u03bb p : R \u00d7 R, (mk N p.1, mk N p.2)) :=\nis_open_map.to_quotient_map\n((quotient_ring.is_open_map_coe N).prod (quotient_ring.is_open_map_coe N))\n((continuous_quot_mk.comp continuous_fst).prod_mk (continuous_quot_mk.comp continuous_snd))\n(by rintro \u27e8\u27e8x\u27e9, \u27e8y\u27e9\u27e9; exact \u27e8(x, y), rfl\u27e9)\n\ninstance topological_ring_quotient : topological_ring (R \u29f8 N) :=\ntopological_semiring.to_topological_ring\n{ continuous_add :=\n    have cont : continuous (mk N \u2218 (\u03bb (p : R \u00d7 R), p.fst + p.snd)) :=\n      continuous_quot_mk.comp continuous_add,\n    (quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).mpr cont,\n  continuous_mul :=\n    have cont : continuous (mk N \u2218 (\u03bb (p : R \u00d7 R), p.fst * p.snd)) :=\n      continuous_quot_mk.comp continuous_mul,\n    (quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).mpr cont }\n\nend comm_ring\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/ring/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7138277629281446}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Julian Kuelshammer\n-/\nimport data.nat.modeq\nimport algebra.iterate_hom\nimport algebra.pointwise\nimport dynamics.periodic_pts\nimport group_theory.coset\n\n/-!\n# Order of an element\n\nThis file defines the order of an element of a finite group. For a finite group `G` the order of\n`x \u2208 G` is the minimal `n \u2265 1` such that `x ^ n = 1`.\n\n## Main definitions\n\n* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite\n  order.\n* `is_of_fin_add_order` is the additive analogue of `is_of_find_order`.\n* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`\n  if `x` has infinite order.\n* `add_order_of` is the additive analogue of `order_of`.\n\n## Tags\norder of an element\n-/\n\nopen function nat\nopen_locale pointwise\n\nuniverses u v\n\nvariables {G : Type u} {A : Type v}\nvariables {x y : G} {a b : A} {n m : \u2115}\n\nsection monoid_add_monoid\n\nvariables [monoid G] [add_monoid A]\n\nsection is_of_fin_order\n\n@[to_additive is_periodic_pt_add_iff_nsmul_eq_zero]\nlemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 \u2194 x ^ n = 1 :=\nby rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]\n\n/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite\norder, i.e. there exists `n \u2265 1` such that `n \u2022 a = 0`.-/\ndef is_of_fin_add_order (a : A) : Prop :=\n(0 : A) \u2208 periodic_pts ((+) a)\n\n/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there\nexists `n \u2265 1` such that `x ^ n = 1`.-/\n@[to_additive is_of_fin_add_order]\ndef is_of_fin_order (x : G) : Prop :=\n(1 : G) \u2208 periodic_pts ((*) x)\n\nlemma is_of_fin_add_order_of_mul_iff :\n  is_of_fin_add_order (additive.of_mul x) \u2194 is_of_fin_order x := iff.rfl\n\nlemma is_of_fin_order_of_add_iff :\n  is_of_fin_order (multiplicative.of_add a) \u2194 is_of_fin_add_order a := iff.rfl\n\n@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]\nlemma is_of_fin_order_iff_pow_eq_one (x : G) :\n  is_of_fin_order x \u2194 \u2203 n, 0 < n \u2227 x ^ n = 1 :=\nby { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }\n\nend is_of_fin_order\n\n/-- `order_of x` is the order of the element `x`, i.e. the `n \u2265 1`, s.t. `x ^ n = 1` if it exists.\nOtherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/\n@[to_additive add_order_of\n\"`add_order_of a` is the order of the element `a`, i.e. the `n \u2265 1`, s.t. `n \u2022 a = 0` if it\nexists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention.\"]\nnoncomputable def order_of (x : G) : \u2115 :=\nminimal_period ((*) x) 1\n\n@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :\n  add_order_of (additive.of_mul x) = order_of x := rfl\n\n@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :\n  order_of (multiplicative.of_add a) = add_order_of a := rfl\n\n@[to_additive add_order_of_pos']\nlemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=\nminimal_period_pos_of_mem_periodic_pts h\n\n@[to_additive add_order_of_nsmul_eq_zero]\nlemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=\nbegin\n  convert is_periodic_pt_minimal_period ((*) x) _,\n  rw [order_of, mul_left_iterate, mul_one],\nend\n\n@[to_additive add_order_of_eq_zero]\nlemma order_of_eq_zero (h : \u00ac is_of_fin_order x) : order_of x = 0 :=\nby rwa [order_of, minimal_period, dif_neg]\n\n@[to_additive add_order_of_eq_zero_iff] lemma order_of_eq_zero_iff :\n  order_of x = 0 \u2194 \u00ac is_of_fin_order x :=\n\u27e8\u03bb h H, (order_of_pos' H).ne' h, order_of_eq_zero\u27e9\n\n@[to_additive add_order_of_eq_zero_iff'] lemma order_of_eq_zero_iff' :\n  order_of x = 0 \u2194 \u2200 n : \u2115, 0 < n \u2192 x ^ n \u2260 1 :=\nby simp_rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one, not_exists, not_and]\n\n@[to_additive nsmul_ne_zero_of_lt_add_order_of']\nlemma pow_ne_one_of_lt_order_of' (n0 : n \u2260 0) (h : n < order_of x) : x ^ n \u2260 1 :=\n\u03bb j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h\n  ((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)\n\n@[to_additive add_order_of_le_of_nsmul_eq_zero]\nlemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x \u2264 n :=\nis_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)\n\n@[simp, to_additive] lemma order_of_one : order_of (1 : G) = 1 :=\nby rw [order_of, one_mul_eq_id, minimal_period_id]\n\n@[simp, to_additive add_monoid.order_of_eq_one_iff] lemma order_of_eq_one_iff :\n  order_of x = 1 \u2194 x = 1 :=\nby rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]\n\n@[to_additive nsmul_eq_mod_add_order_of]\nlemma pow_eq_mod_order_of {n : \u2115} : x ^ n = x ^ (n % order_of x) :=\ncalc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]\n       ... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]\n\n@[to_additive add_order_of_dvd_of_nsmul_eq_zero]\nlemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x \u2223 n :=\nis_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)\n\n@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]\nlemma order_of_dvd_iff_pow_eq_one {n : \u2115} : order_of x \u2223 n \u2194 x ^ n = 1 :=\n\u27e8\u03bb h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one\u27e9\n\n@[to_additive exists_nsmul_eq_self_of_coprime]\nlemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :\n  \u2203 m : \u2115, (x ^ n) ^ m = x :=\nbegin\n  by_cases h0 : order_of x = 0,\n  { rw [h0, coprime_zero_right] at h,\n    exact \u27e81, by rw [h, pow_one, pow_one]\u27e9 },\n  by_cases h1 : order_of x = 1,\n  { exact \u27e80, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]\u27e9 },\n  obtain \u27e8m, hm\u27e9 :=\n    exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr \u27e8h0, h1\u27e9),\n  exact \u27e8m, by rw [\u2190pow_mul, pow_eq_mod_order_of, hm, pow_one]\u27e9,\nend\n\n/--\nIf `x^n = 1`, but `x^(n/p) \u2260 1` for all prime factors `p` of `r`,\nthen `x` has order `n` in `G`.\n-/\n@[to_additive add_order_of_eq_of_nsmul_and_div_prime_nsmul]\ntheorem order_of_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x^n = 1)\n  (hd : \u2200 p : \u2115, p.prime \u2192 p \u2223 n \u2192 x^(n/p) \u2260 1) :\n  order_of x = n :=\nbegin\n  -- Let `a` be `n/(order_of x)`, and show `a = 1`\n  cases exists_eq_mul_right_of_dvd (order_of_dvd_of_pow_eq_one hx) with a ha,\n  suffices : a = 1, by simp [this, ha],\n  -- Assume `a` is not one...\n  by_contra,\n  have a_min_fac_dvd_p_sub_one : a.min_fac \u2223 n,\n  { obtain \u27e8b, hb\u27e9 : \u2203 (b : \u2115), a = b * a.min_fac := exists_eq_mul_left_of_dvd a.min_fac_dvd,\n    rw [hb, \u2190mul_assoc] at ha,\n    exact dvd.intro_left (order_of x * b) ha.symm, },\n  -- Use the minimum prime factor of `a` as `p`.\n  refine hd a.min_fac (nat.min_fac_prime h) a_min_fac_dvd_p_sub_one _,\n  rw [\u2190order_of_dvd_iff_pow_eq_one, nat.dvd_div_iff (a_min_fac_dvd_p_sub_one),\n      ha, mul_comm, nat.mul_dvd_mul_iff_left (order_of_pos' _)],\n  { exact nat.min_fac_dvd a, },\n  { rw is_of_fin_order_iff_pow_eq_one,\n    exact Exists.intro n (id \u27e8hn, hx\u27e9) },\nend\n\n@[to_additive add_order_of_eq_add_order_of_iff]\nlemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :\n  order_of x = order_of y \u2194 \u2200 n : \u2115, x ^ n = 1 \u2194 y ^ n = 1 :=\nby simp_rw [\u2190 is_periodic_pt_mul_iff_pow_eq_one, \u2190 minimal_period_eq_minimal_period_iff, order_of]\n\n@[to_additive add_order_of_injective]\nlemma order_of_injective {H : Type*} [monoid H] (f : G \u2192* H)\n  (hf : function.injective f) (x : G) : order_of (f x) = order_of x :=\nby simp_rw [order_of_eq_order_of_iff, \u2190f.map_pow, \u2190f.map_one, hf.eq_iff, iff_self, forall_const]\n\n@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}\n  (y : H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive order_of_add_units]\nlemma order_of_units {y : G\u02e3} : order_of (y : G) = order_of y :=\norder_of_injective (units.coe_hom G) units.ext y\n\nvariables (x)\n\n@[to_additive add_order_of_nsmul']\nlemma order_of_pow' (h : n \u2260 0) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd h,\n  simp only [order_of, mul_left_iterate],\nend\n\nvariables (a) (n)\n\n@[to_additive add_order_of_nsmul'']\nlemma order_of_pow'' (h : is_of_fin_order x) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd' h,\n  simp only [order_of, mul_left_iterate],\nend\n\n@[to_additive]\nlemma commute.order_of_mul_dvd_lcm {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 nat.lcm (order_of x) (order_of y) :=\nbegin\n  convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,\n  rw [order_of, comp_mul_left],\nend\n\n@[to_additive add_order_of_add_dvd_mul_add_order_of]\nlemma commute.order_of_mul_dvd_mul_order_of {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 (order_of x) * (order_of y) :=\ndvd_trans h.order_of_mul_dvd_lcm (lcm_dvd_mul _ _)\n\n@[to_additive add_order_of_add_eq_mul_add_order_of_of_coprime]\nlemma commute.order_of_mul_eq_mul_order_of_of_coprime {x y : G} (h : commute x y)\n  (hco : nat.coprime (order_of x) (order_of y)) :\n  order_of (x * y) = (order_of x) * (order_of y) :=\nbegin\n  convert h.function_commute_mul_left.minimal_period_of_comp_eq_mul_of_coprime hco,\n  simp only [order_of, comp_mul_left],\nend\n\nsection p_prime\n\nvariables {a x n} {p : \u2115} [hp : fact p.prime]\ninclude hp\n\n@[to_additive add_order_of_eq_prime]\nlemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x \u2260 1) : order_of x = p :=\nminimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)\n  (by rwa [is_fixed_pt, mul_one])\n\n@[to_additive add_order_of_eq_prime_pow]\nlemma order_of_eq_prime_pow (hnot : \u00ac x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :\n  order_of x = p ^ (n + 1) :=\nbegin\n  apply minimal_period_eq_prime_pow;\n  rwa is_periodic_pt_mul_iff_pow_eq_one,\nend\n\nomit hp\n-- An example on how to determine the order of an element of a finite group.\nexample : order_of (-1 : \u2124\u02e3) = 2 :=\norder_of_eq_prime (int.units_sq _) dec_trivial\n\nend p_prime\n\nend monoid_add_monoid\n\nsection cancel_monoid\nvariables [left_cancel_monoid G] (x y)\n\n@[to_additive nsmul_injective_aux]\nlemma pow_injective_aux (h : n \u2264 m)\n  (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\nby_contradiction $ assume ne : n \u2260 m,\n  have h\u2081 : m - n > 0, from nat.pos_of_ne_zero (by simp [tsub_eq_iff_eq_add_of_le h, ne.symm]),\n  have h\u2082 : m = n + (m - n) := (add_tsub_cancel_of_le h).symm,\n  have h\u2083 : x ^ (m - n) = 1,\n    by { rw [h\u2082, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (x ^ n) },\n  have le : order_of x \u2264 m - n, from order_of_le_of_pow_eq_one h\u2081 h\u2083,\n  have lt : m - n < order_of x,\n    from (tsub_lt_iff_left h).mpr $ nat.lt_add_left _ _ _ hm,\n  lt_irrefl _ (le.trans_lt lt)\n\n@[to_additive nsmul_injective_of_lt_add_order_of]\nlemma pow_injective_of_lt_order_of\n  (hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\n(le_total n m).elim\n  (assume h, pow_injective_aux x h hm eq)\n  (assume h, (pow_injective_aux x h hn eq.symm).symm)\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of']\nlemma mem_powers_iff_mem_range_order_of' [decidable_eq G] (hx : 0 < order_of x) :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' hx (\u03bb i, pow_eq_mod_order_of.symm)\n\nlemma pow_eq_one_iff_modeq : x ^ n = 1 \u2194 n \u2261 0 [MOD (order_of x)] :=\nby rw [modeq_zero_iff_dvd, order_of_dvd_iff_pow_eq_one]\n\nlemma pow_eq_pow_iff_modeq : x ^ n = x ^ m \u2194 n \u2261 m [MOD (order_of x)] :=\nbegin\n  wlog hmn : m \u2264 n,\n  obtain \u27e8k, rfl\u27e9 := nat.exists_eq_add_of_le hmn,\n  rw [\u2190 mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modeq],\n  exact \u27e8\u03bb h, nat.modeq.add_left _ h, \u03bb h, nat.modeq.add_left_cancel' _ h\u27e9,\nend\n\nend cancel_monoid\n\nsection group\nvariables [group G] [add_group A] {x a} {i : \u2124}\n\n@[to_additive add_order_of_dvd_iff_zsmul_eq_zero]\nlemma order_of_dvd_iff_zpow_eq_one : (order_of x : \u2124) \u2223 i \u2194 x ^ i = 1 :=\nbegin\n  rcases int.eq_coe_or_neg i with \u27e8i, rfl|rfl\u27e9,\n  { rw [int.coe_nat_dvd, order_of_dvd_iff_pow_eq_one, zpow_coe_nat] },\n  { rw [dvd_neg, int.coe_nat_dvd, zpow_neg, inv_eq_one, zpow_coe_nat,\n      order_of_dvd_iff_pow_eq_one] }\nend\n\n@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}\n  (y: H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive zsmul_eq_mod_add_order_of]\nlemma zpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=\ncalc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :\n    by rw [int.mod_add_div]\n       ... = x ^ (i % order_of x) :\n    by simp [zpow_add, zpow_mul, pow_order_of_eq_one]\n    set_option pp.all true\n\n@[to_additive nsmul_inj_iff_of_add_order_of_eq_zero]\nlemma pow_inj_iff_of_order_of_eq_zero (h : order_of x = 0) {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n = m :=\nbegin\n  rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one] at h,\n  push_neg at h,\n  induction n with n IH generalizing m,\n  { cases m,\n    { simp },\n    { simpa [eq_comm] using h m.succ m.zero_lt_succ } },\n  { cases m,\n    { simpa using h n.succ n.zero_lt_succ },\n    { simp [pow_succ, IH] } }\nend\n\n@[to_additive nsmul_inj_mod]\nlemma pow_inj_mod {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n % order_of x = m % order_of x :=\nbegin\n  cases (order_of x).zero_le.eq_or_lt with hx hx,\n  { simp [pow_inj_iff_of_order_of_eq_zero, hx.symm] },\n  rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ m],\n  exact \u27e8pow_injective_of_lt_order_of _ (nat.mod_lt _ hx) (nat.mod_lt _ hx), \u03bb h, congr_arg _ h\u27e9\nend\n\n\nend group\n\nsection fintype\nvariables [fintype G] [fintype A]\n\nsection finite_monoid\nvariables [monoid G] [add_monoid A]\nopen_locale big_operators\n\n@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]\nlemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :\n  \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n  = (finset.univ.filter (\u03bb x : G, x ^ n = 1)).card :=\ncalc \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n    = _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm\n... = _ : congr_arg finset.card (finset.ext (begin\n  assume x,\n  suffices : order_of x \u2264 n \u2227 order_of x \u2223 n \u2194 x ^ n = 1,\n  { simpa [nat.lt_succ_iff], },\n  exact \u27e8\u03bb h, let \u27e8m, hm\u27e9 := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],\n    \u03bb h, \u27e8order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h\u27e9\u27e9\nend))\n\nend finite_monoid\n\nsection finite_cancel_monoid\n-- TODO: Of course everything also works for right_cancel_monoids.\nvariables [left_cancel_monoid G] [add_left_cancel_monoid A]\n\n-- TODO: Use this to show that a finite left cancellative monoid is a group.\n@[to_additive exists_nsmul_eq_zero]\nlemma exists_pow_eq_one (x : G) : is_of_fin_order x :=\nbegin\n  refine (is_of_fin_order_iff_pow_eq_one _).mpr _,\n  obtain \u27e8i, j, a_eq, ne\u27e9 : \u2203(i j : \u2115), x ^ i = x ^ j \u2227 i \u2260 j :=\n    by simpa only [not_forall, exists_prop, injective]\n      using (not_injective_infinite_fintype (\u03bbi:\u2115, x^i)),\n  wlog h'' : j \u2264 i,\n  refine \u27e8i - j, tsub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _\u27e9,\n  rw [mul_one, \u2190 pow_add, \u2190 a_eq, add_tsub_cancel_of_le h''],\nend\n\n@[to_additive add_order_of_le_card_univ]\nlemma order_of_le_card_univ : order_of x \u2264 fintype.card G :=\nfinset.le_card_of_inj_on_range ((^) x)\n  (assume n _, finset.mem_univ _)\n  (assume i hi j hj, pow_injective_of_lt_order_of x hi hj)\n\n/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative monoid.-/\n@[to_additive add_order_of_pos\n\"This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative additive monoid.\"]\nlemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)\n\nopen nat\n\n/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is\nautomatic in the case of a finite cancellative monoid.-/\n@[to_additive add_order_of_nsmul\n\"This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less\nwhich is automatic in the case of a finite cancellative additive monoid.\"]\nlemma order_of_pow (x : G) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of]\nlemma mem_powers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)\n  (assume i, pow_eq_mod_order_of.symm)\n\n@[to_additive decidable_multiples]\nnoncomputable instance decidable_powers [decidable_eq G] :\n  decidable_pred (\u2208 submonoid.powers x) :=\nbegin\n  assume y,\n  apply decidable_of_iff'\n    (y \u2208 (finset.range (order_of x)).image ((^) x)),\n  exact mem_powers_iff_mem_range_order_of\nend\n\n/--The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`.\"-/\n@[to_additive fin_equiv_multiples \"The equivalence between `fin (add_order_of a)` and\n`add_submonoid.multiples a`, sending `i` to `i \u2022 a`.\"]\nnoncomputable def fin_equiv_powers (x : G) :\n  fin (order_of x) \u2243 (submonoid.powers x : set G) :=\nequiv.of_bijective (\u03bb n, \u27e8x ^ \u2191n, \u27e8n, rfl\u27e9\u27e9) \u27e8\u03bb \u27e8i, hi\u27e9 \u27e8j, hj\u27e9 ij,\n  subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),\n  \u03bb \u27e8_, i, rfl\u27e9, \u27e8\u27e8i % order_of x, mod_lt i (order_of_pos x)\u27e9, subtype.eq pow_eq_mod_order_of.symm\u27e9\u27e9\n\n@[simp, to_additive fin_equiv_multiples_apply]\nlemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :\n  fin_equiv_powers x n = \u27e8x ^ \u2191n, n, rfl\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_multiples_symm_apply]\nlemma fin_equiv_powers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2115), x ^ m = x ^ n} :\n  ((fin_equiv_powers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,\n  pow_eq_mod_order_of, fin.coe_mk]\n\n/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive multiples_equiv_multiples\n\"The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def powers_equiv_powers (h : order_of x = order_of y) :\n  (submonoid.powers x : set G) \u2243 (submonoid.powers y : set G) :=\n(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))\n\n@[simp, to_additive multiples_equiv_multiples_apply]\nlemma powers_equiv_powers_apply (h : order_of x = order_of y)\n  (n : \u2115) : powers_equiv_powers h \u27e8x ^ n, n, rfl\u27e9 = \u27e8y ^ n, n, rfl\u27e9 :=\nbegin\n  rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_powers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_powers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_of_eq_card_multiples]\nlemma order_eq_card_powers [decidable_eq G] :\n  order_of x = fintype.card (submonoid.powers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_powers x\u27e9)\n\nend finite_cancel_monoid\n\nsection finite_group\nvariables [group G] [add_group A]\n\n@[to_additive]\nlemma exists_zpow_eq_one (x : G) : \u2203 (i : \u2124) (H : i \u2260 0), x ^ (i : \u2124) = 1 :=\nbegin\n  rcases exists_pow_eq_one x with \u27e8w, hw1, hw2\u27e9,\n  refine \u27e8w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _\u27e9,\n  rw zpow_coe_nat,\n  exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,\nend\n\nopen subgroup\n\n@[to_additive mem_multiples_iff_mem_zmultiples]\nlemma mem_powers_iff_mem_zpowers : y \u2208 submonoid.powers x \u2194 y \u2208 zpowers x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, \u27e8n, by simp * at *\u27e9,\n\u03bb \u27e8i, hi\u27e9, \u27e8(i % order_of x).nat_abs,\n  by rwa [\u2190 zpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _\n    (int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),\n    \u2190 zpow_eq_mod_order_of]\u27e9\u27e9\n\n@[to_additive multiples_eq_zmultiples]\nlemma powers_eq_zpowers (x : G) : (submonoid.powers x : set G) = zpowers x :=\nset.ext $ \u03bb x, mem_powers_iff_mem_zpowers\n\n@[to_additive mem_zmultiples_iff_mem_range_add_order_of]\nlemma mem_zpowers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 subgroup.zpowers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nby rw [\u2190 mem_powers_iff_mem_zpowers, mem_powers_iff_mem_range_order_of]\n\n@[to_additive decidable_zmultiples]\nnoncomputable instance decidable_zpowers [decidable_eq G] :\n  decidable_pred (\u2208 subgroup.zpowers x) :=\nbegin\n  simp_rw \u2190set_like.mem_coe,\n  rw \u2190 powers_eq_zpowers,\n  exact decidable_powers,\nend\n\n/-- The equivalence between `fin (order_of x)` and `subgroup.zpowers x`, sending `i` to `x ^ i`. -/\n@[to_additive fin_equiv_zmultiples\n\"The equivalence between `fin (add_order_of a)` and `subgroup.zmultiples a`, sending `i`\nto `i \u2022 a`.\"]\nnoncomputable def fin_equiv_zpowers (x : G) :\n  fin (order_of x) \u2243 (subgroup.zpowers x : set G) :=\n(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_zpowers x))\n\n@[simp, to_additive fin_equiv_zmultiples_apply]\nlemma fin_equiv_zpowers_apply {n : fin (order_of x)} :\n  fin_equiv_zpowers x n = \u27e8x ^ (n : \u2115), n, zpow_coe_nat x n\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_zmultiples_symm_apply]\nlemma fin_equiv_zpowers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2124), x ^ m = x ^ n} :\n  ((fin_equiv_zpowers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby { rw [fin_equiv_zpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],\n  exact fin_equiv_powers_symm_apply x n }\n\n/-- The equivalence between `subgroup.zpowers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive zmultiples_equiv_zmultiples\n\"The equivalence between `subgroup.zmultiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def zpowers_equiv_zpowers (h : order_of x = order_of y) :\n  (subgroup.zpowers x : set G) \u2243 (subgroup.zpowers y : set G) :=\n(fin_equiv_zpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_zpowers y))\n\n@[simp, to_additive zmultiples_equiv_zmultiples_apply]\nlemma zpowers_equiv_zpowers_apply (h : order_of x = order_of y)\n  (n : \u2115) : zpowers_equiv_zpowers h \u27e8x ^ n, n, zpow_coe_nat x n\u27e9 = \u27e8y ^ n, n, zpow_coe_nat y n\u27e9 :=\nbegin\n  rw [zpowers_equiv_zpowers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_zpowers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_zpowers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_eq_card_zmultiples]\nlemma order_eq_card_zpowers [decidable_eq G] :\n  order_of x = fintype.card (subgroup.zpowers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_zpowers x\u27e9)\n\nopen quotient_group\n\n/- TODO: use cardinal theory, introduce `card : set G \u2192 \u2115`, or setup decidability for cosets -/\n@[to_additive add_order_of_dvd_card_univ]\nlemma order_of_dvd_card_univ : order_of x \u2223 fintype.card G :=\nbegin\n  classical,\n  have ft_prod : fintype ((G \u29f8 zpowers x) \u00d7 zpowers x),\n    from fintype.of_equiv G group_equiv_quotient_times_subgroup,\n  have ft_s : fintype (zpowers x),\n    from @fintype.prod_right _ _ _ ft_prod _,\n  have ft_cosets : fintype (G \u29f8 zpowers x),\n    from @fintype.prod_left _ _ _ ft_prod \u27e8\u27e81, (zpowers x).one_mem\u27e9\u27e9,\n  have eq\u2081 : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,\n    from calc fintype.card G = @fintype.card _ ft_prod :\n        @fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup\n      ... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :\n        congr_arg (@fintype.card _) $ subsingleton.elim _ _\n      ... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :\n        @fintype.card_prod _ _ ft_cosets ft_s,\n  have eq\u2082 : order_of x = @fintype.card _ ft_s,\n    from calc order_of x = _ : order_eq_card_zpowers\n      ... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,\n  exact dvd.intro (@fintype.card (G \u29f8 subgroup.zpowers x) ft_cosets)\n          (by rw [eq\u2081, eq\u2082, mul_comm])\nend\n\n@[simp, to_additive card_nsmul_eq_zero] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=\nlet \u27e8m, hm\u27e9 := @order_of_dvd_card_univ _ x _ _ in\nby simp [hm, pow_mul, pow_order_of_eq_one]\n\n@[to_additive nsmul_eq_mod_card] lemma pow_eq_mod_card (n : \u2115) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [pow_eq_mod_order_of, \u2190nat.mod_mod_of_dvd n order_of_dvd_card_univ,\n  \u2190 pow_eq_mod_order_of]\n\n@[to_additive] lemma zpow_eq_mod_card (n : \u2124) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [zpow_eq_mod_order_of, \u2190 int.mod_mod_of_dvd n (int.coe_nat_dvd.2 order_of_dvd_card_univ),\n  \u2190 zpow_eq_mod_order_of]\n\n/-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/\n@[to_additive nsmul_coprime \"If `gcd(|G|,n)=1` then the smul by `n` is a bijection\", simps]\n  def pow_coprime (h : nat.coprime (fintype.card G) n) : G \u2243 G :=\n{ to_fun := \u03bb g, g ^ n,\n  inv_fun := \u03bb g, g ^ (nat.gcd_b (fintype.card G) n),\n  left_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul, zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key },\n  right_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul', zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key } }\n\n@[simp, to_additive] lemma pow_coprime_one (h : nat.coprime (fintype.card G) n) :\n  pow_coprime h 1 = 1 := one_pow n\n\n@[simp, to_additive] lemma pow_coprime_inv (h : nat.coprime (fintype.card G) n) {g : G} :\n  pow_coprime h g\u207b\u00b9 = (pow_coprime h g)\u207b\u00b9 := inv_pow g n\n\n@[to_additive add_inf_eq_bot_of_coprime]\nlemma inf_eq_bot_of_coprime {G : Type*} [group G] {H K : subgroup G} [fintype H] [fintype K]\n  (h : nat.coprime (fintype.card H) (fintype.card K)) : H \u2293 K = \u22a5 :=\nbegin\n  refine (H \u2293 K).eq_bot_iff_forall.mpr (\u03bb x hx, _),\n  rw [\u2190order_of_eq_one_iff, \u2190nat.dvd_one, \u2190h.gcd_eq_one, nat.dvd_gcd_iff],\n  exact \u27e8(congr_arg (\u2223 fintype.card H) (order_of_subgroup \u27e8x, hx.1\u27e9)).mpr order_of_dvd_card_univ,\n    (congr_arg (\u2223 fintype.card K) (order_of_subgroup \u27e8x, hx.2\u27e9)).mpr order_of_dvd_card_univ\u27e9,\nend\n\nvariable (a)\n\n/-- TODO: Generalise to `submonoid.powers`.-/\n@[to_additive image_range_add_order_of]\nlemma image_range_order_of [decidable_eq G] :\n  finset.image (\u03bb i, x ^ i) (finset.range (order_of x)) = (zpowers x : set G).to_finset :=\nby { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_zpowers_iff_mem_range_order_of] }\n\n/-- TODO: Generalise to `finite_cancel_monoid`. -/\n@[to_additive gcd_nsmul_card_eq_zero_iff]\nlemma pow_gcd_card_eq_one_iff : x ^ n = 1 \u2194 x ^ (gcd n (fintype.card G)) = 1 :=\n\u27e8\u03bb h, pow_gcd_eq_one _ h $ pow_card_eq_one,\n  \u03bb h, let \u27e8m, hm\u27e9 := gcd_dvd_left n (fintype.card G) in\n    by rw [hm, pow_mul, h, one_pow]\u27e9\n\nend finite_group\n\nend fintype\n\nsection pow_is_subgroup\n\n/-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/\n@[to_additive \"A nonempty idempotent subset of a finite cancellative add monoid is a submonoid\"]\ndef submonoid_of_idempotent {M : Type*} [left_cancel_monoid M] [fintype M] (S : set M)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : submonoid M :=\nhave pow_mem : \u2200 a : M, a \u2208 S \u2192 \u2200 n : \u2115, a ^ (n + 1) \u2208 S :=\n\u03bb a ha, nat.rec (by rwa [zero_add, pow_one])\n  (\u03bb n ih, (congr_arg2 (\u2208) (pow_succ a (n + 1)).symm hS2).mp (set.mul_mem_mul ha ih)),\n{ carrier := S,\n  one_mem' := by\n  { obtain \u27e8a, ha\u27e9 := hS1,\n    rw [\u2190pow_order_of_eq_one a, \u2190 tsub_add_cancel_of_le (succ_le_of_lt (order_of_pos a))],\n    exact pow_mem a ha (order_of a - 1) },\n  mul_mem' := \u03bb a b ha hb, (congr_arg2 (\u2208) rfl hS2).mp (set.mul_mem_mul ha hb) }\n\n/-- A nonempty idempotent subset of a finite group is a subgroup -/\n@[to_additive \"A nonempty idempotent subset of a finite add group is a subgroup\"]\ndef subgroup_of_idempotent {G : Type*} [group G] [fintype G] (S : set G)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : subgroup G :=\n{ carrier := S,\n  inv_mem' := \u03bb a ha, by\n  { rw [\u2190one_mul a\u207b\u00b9, \u2190pow_one a, \u2190pow_order_of_eq_one a, \u2190pow_sub a (order_of_pos a)],\n    exact (submonoid_of_idempotent S hS1 hS2).pow_mem ha (order_of a - 1) },\n  .. submonoid_of_idempotent S hS1 hS2 }\n\n/-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/\n@[to_additive smul_card_add_subgroup \"If `S` is a nonempty subset of a finite add group `G`,\n  then `|G| \u2022 S` is a subgroup\", simps]\ndef pow_card_subgroup {G : Type*} [group G] [fintype G] (S : set G) (hS : S.nonempty) :\n  subgroup G :=\nhave one_mem : (1 : G) \u2208 (S ^ fintype.card G) := by\n{ obtain \u27e8a, ha\u27e9 := hS,\n  rw \u2190 pow_card_eq_one,\n  exact set.pow_mem_pow ha (fintype.card G) },\nsubgroup_of_idempotent (S ^ (fintype.card G)) \u27e81, one_mem\u27e9 begin\n  classical,\n  refine (set.eq_of_subset_of_card_le\n    (\u03bb b hb, (congr_arg (\u2208 _) (one_mul b)).mp (set.mul_mem_mul one_mem hb)) (ge_of_eq _)).symm,\n  change _ = fintype.card (_ * _ : set G),\n  rw [\u2190pow_add, group.card_pow_eq_card_pow_card_univ S (fintype.card G) le_rfl,\n      group.card_pow_eq_card_pow_card_univ S (fintype.card G + fintype.card G) le_add_self],\nend\n\nend pow_is_subgroup\n\nsection linear_ordered_ring\n\nvariable [linear_ordered_ring G]\n\nlemma order_of_abs_ne_one (h : |x| \u2260 1) : order_of x = 0 :=\nbegin\n  rw order_of_eq_zero_iff',\n  intros n hn hx,\n  replace hx : |x| ^ n = 1 := by simpa only [abs_one, abs_pow] using congr_arg abs hx,\n  cases h.lt_or_lt with h h,\n  { exact ((pow_lt_one (abs_nonneg x) h hn.ne').ne hx).elim },\n  { exact ((one_lt_pow h hn.ne').ne' hx).elim }\nend\n\nlemma linear_ordered_ring.order_of_le_two : order_of x \u2264 2 :=\nbegin\n  cases ne_or_eq (|x|) 1 with h h,\n  { simp [order_of_abs_ne_one h] },\n  rcases eq_or_eq_neg_of_abs_eq h with rfl | rfl,\n  { simp },\n  apply order_of_le_of_pow_eq_one; norm_num\nend\n\nend linear_ordered_ring\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/group_theory/order_of_element.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7137969126378813}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.nat.basic\n/-!\n# Partial predecessor and partial subtraction on the natural numbers\n\nThe usual definition of natural number subtraction (`nat.sub`) returns 0 as a \"garbage value\" for\n`a - b` when `a < b`. Similarly, `nat.pred 0` is defined to be `0`. The functions in this file\nwrap the result in an `option` type instead:\n\n## Main definitions\n\n- `nat.ppred`: a partial predecessor operation\n- `nat.psub`: a partial subtraction operation\n\n-/\nnamespace nat\n\n/-- Partial predecessor operation. Returns `ppred n = some m`\n  if `n = m + 1`, otherwise `none`. -/\n@[simp] def ppred : \u2115 \u2192 option \u2115\n| 0     := none\n| (n+1) := some n\n\n/-- Partial subtraction operation. Returns `psub m n = some k`\n  if `m = n + k`, otherwise `none`. -/\n@[simp] def psub (m : \u2115) : \u2115 \u2192 option \u2115\n| 0     := some m\n| (n+1) := psub n >>= ppred\n\ntheorem pred_eq_ppred (n : \u2115) : pred n = (ppred n).get_or_else 0 :=\nby cases n; refl\n\ntheorem sub_eq_psub (m : \u2115) : \u2200 n, m - n = (psub m n).get_or_else 0\n| 0     := rfl\n| (n+1) := (pred_eq_ppred (m-n)).trans $\n  by rw [sub_eq_psub, psub]; cases psub m n; refl\n\n@[simp] theorem ppred_eq_some {m : \u2115} : \u2200 {n}, ppred n = some m \u2194 succ m = n\n| 0     := by split; intro h; contradiction\n| (n+1) := by dsimp; split; intro h; injection h; subst n\n\n@[simp] theorem ppred_eq_none : \u2200 {n : \u2115}, ppred n = none \u2194 n = 0\n| 0     := by simp\n| (n+1) := by dsimp; split; contradiction\n\ntheorem psub_eq_some {m : \u2115} : \u2200 {n k}, psub m n = some k \u2194 k + n = m\n| 0     k := by simp [eq_comm]\n| (n+1) k :=\n  begin\n    dsimp,\n    apply option.bind_eq_some.trans,\n    simp [psub_eq_some, add_comm, add_left_comm, nat.succ_eq_add_one]\n  end\n\ntheorem psub_eq_none {m n : \u2115} : psub m n = none \u2194 m < n :=\nbegin\n  cases s : psub m n; simp [eq_comm],\n  { show m < n, refine lt_of_not_ge (\u03bb h, _),\n    cases le.dest h with k e,\n    injection s.symm.trans (psub_eq_some.2 $ (add_comm _ _).trans e) },\n  { show n \u2264 m, rw \u2190 psub_eq_some.1 s, apply le_add_left }\nend\n\ntheorem ppred_eq_pred {n} (h : 0 < n) : ppred n = some (pred n) :=\nppred_eq_some.2 $ succ_pred_eq_of_pos h\n\ntheorem psub_eq_sub {m n} (h : n \u2264 m) : psub m n = some (m - n) :=\npsub_eq_some.2 $ nat.sub_add_cancel h\n\ntheorem psub_add (m n k) : psub m (n + k) = do x \u2190 psub m n, psub x k :=\nby induction k; simp [*, add_succ, bind_assoc]\n\n/-- Same as `psub`, but with a more efficient implementation. -/\n@[inline] def psub' (m n : \u2115) : option \u2115 := if n \u2264 m then some (m - n) else none\n\ntheorem psub'_eq_psub (m n) : psub' m n = psub m n :=\nby rw [psub']; split_ifs;\n  [exact (psub_eq_sub h).symm, exact (psub_eq_none.2 (not_le.1 h)).symm]\n\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/psub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7137760289926901}}
{"text": "import data.set\nimport data.int.basic\nimport data.nat.basic\nopen function int set nat\n\nsection\n  def f (x : \u2124) : \u2124 := x + 3\n  def g (x : \u2124) : \u2124 := -x\n  def h (x : \u2124) : \u2124 := 2 * x + 3\n\n  -- 1\n  example : injective h :=\n  begin\n  assume x1 x2, assume h2 : 2 * x1 + 3 = 2 * x2 + 3,\n  show x1=x2, from \n    have h1 : 2 \u2260 (0 : \u2124), from dec_trivial,  show x1 = x2, from mul_left_cancel\u2080 h1 (add_right_cancel h2)\n  end\n\n  -- 2\n  example : surjective g :=\n  assume y1, have h3 : g ( -y1 ) = y1, from calc \n        g ( -y1 ) = - (-y1) : rfl\n        ... = y1           : by rw neg_neg y1, show \u2203 x, g x = y1, from  exists.intro (-y1) h3\n\n  -- 3\n  example (A B : Type) (u : A \u2192 B) (v1 : B \u2192 A) (v2 : B \u2192 A)\n    (h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=\n  funext\n    (assume x,\n      calc\n        v1 x = v1 (u (v2 x)) : by rw h2\n         ... = v2 x          : by rw h1)\nend\n\n-- 4\nsection\n  variables {X Y : Type}\n  variable f : X \u2192 Y\n  variables A B : set X\n\n  example : f '' (A \u2229 B) \u2286 f '' A \u2229 f '' B :=\n  assume y,\n  assume h1 : y \u2208 f '' (A \u2229 B),\n  show y \u2208 f '' A \u2229 f '' B, from \n  exists.elim h1 $\n      assume x5 : X,\n      assume h4 : x5 \u2208 A \u2229 B \u2227 f x5 = y,\n      have ha: f x5 = y, from and.right h4,\n      have hb : x5 \u2208 A \u2229 B, from and.left h4,\n      have hc : x5 \u2208 A, from and.left hb,\n      have hd : y \u2208 f '' A, from exists.intro x5 $ \u27e8hc, ha\u27e9,\n      have he : x5 \u2208 B, from and.right hb,\n      have hf :y \u2208 f '' B, from exists.intro x5 $ \u27e8he, ha\u27e9,\n      \u27e8hd, hf\u27e9 \nend\n\n\n-- 5\nexample : \u2200 m n k : nat, m * (n + k) = m * n + m * k :=\nassume m n k, \nnat.rec_on k\n    (show m*(n + 0) = m*n + m*0, from calc\n    m*(n + 0) = m*n : by rw add_zero \n          ... = m*n + 0 : by rw add_zero\n          ... = m*n + m*0 : by rw mul_zero\n    )\n    (assume k, \n    assume ih: m*(n + k) = m*n + m*k, \n    show m*(n + succ k) = m*n + m*(succ k), from calc\n    m*(n + succ k) = m*(succ(n + k)) : by rw add_succ\n               ... = m*(n + k) + m : by rw mul_succ\n               ... = m*n + m*k + m : by rw ih \n               ... = m*n + (m*k + m) : by rw add_assoc\n               ... = m*n + m*(succ k) : by rw mul_succ         \n    )\n\n-- 6\nexample : \u2200 n : nat, 0 * n = 0 :=\nbegin\n  intro n,\n  induction n with i2 h2,\n  show 0 * 0 = 0, from mul_zero 0, \n  rw mul_succ,\n  rw h2,\nend\n\n-- 7\nexample : \u2200 n : nat, 1 * n = n :=\nbegin\nintro n,\n  induction n with i3 h3,\n  show 1 * 0 = 0, from mul_zero 1,\n  rw mul_succ,\n  rw h3,\nend\n\n-- 8\nexample : \u2200 m n k : nat, (m * n) * k = m * (n * k) :=\nbegin\n  intros m n k,\n  induction k with i4 h4,\n  show (m * n) * 0 = m * (n * 0), from calc\n        (m * n) * 0 = 0           : by rw mul_zero\n                ... = m * 0       : by rw mul_zero\n                ... = m * (n * 0) : by rw mul_zero n,\n  rw mul_succ,\n  rw mul_succ,\n  rw mul_add,\n  rw h4,\n\nend\n\n-- 9\nexample : \u2200 m n : nat, m * n = n * m :=\nbegin\n  intros m n,\n  induction n with i5 h5,\n  show m * 0 = 0 * m, from calc\n        m * 0 = 0     : by rw mul_zero\n          ... = 0 * m : by rw zero_mul,\n  rw mul_succ,\n  rw succ_mul,\n  rw h5,\n\nend\n", "meta": {"author": "Eemkayy", "repo": "discrete205", "sha": "73cd7e1973b054612363ca6cd149b183ad58a9fb", "save_path": "github-repos/lean/Eemkayy-discrete205", "path": "github-repos/lean/Eemkayy-discrete205/discrete205-73cd7e1973b054612363ca6cd149b183ad58a9fb/HW4/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.7137737928910685}}
{"text": "import data.real.basic\nimport topology.basic\n\nnamespace xena -- hide\n\nopen function\nopen real\nopen set\n\n/-\nClassic eps-delta definition of continuity equivalent to topological definition.\n\nWork in progress.\n-/\n\nnotation `|` x `|` := abs x\n\ndef continuous_at_x (f : \u211d \u2192 \u211d) (x : \u211d) := \n    \u2200 \u03b5 : \u211d, 0 < \u03b5 \u2192 \u2203 \u03b4 : \u211d, 0 < \u03b4 \u2227 \u2200 y : \u211d, |x - y| < \u03b4 \u2192 |f x - f y| < \u03b5\ndef continuous_on_set (f : \u211d \u2192 \u211d) (X : set \u211d) :=\n    \u2200 x \u2208 X, continuous_at_x f x\ndef open_in_R (Y : set \u211d) := \u2200 x \u2208 Y, \u2203 \u03b5 : \u211d, 0 < \u03b5 \u2227 { y | |x-y| < \u03b5 } \u2282 Y\ndef open_in_X (S : set \u211d) (X : set \u211d) (hS : S \u2282 X) := \u2203 Y : set \u211d, \n    S = Y \u2229 X \u2227 open_in_R Y \ndef preimage_in_X (f : \u211d \u2192 \u211d) (X : set \u211d) (T : set \u211d) :=\n    { x | x \u2208 X \u2227 \u2203 t \u2208 T, f x = t}\ndef continuous_on_topo_def (f : \u211d \u2192 \u211d) (X : set \u211d) :=\n    \u2200 T : set \u211d, open_in_R T \u2192 open_in_R (preimage_in_X f X T)\n\n\n/-\ntheorem continuous_on_topo_def2 (f : \u211d \u2192 \u211d) (X : set \u211d) :\n  \u2200 x \u2208 X, \u2200 t : set \u211d, is_open t \u2192 f x \u2208 t \u2192 \u2203 u, is_open u \u2227 x \u2208 u \u2227\n    u \u2229 X \u2286 f \u207b\u00b9' t :=\n-/\n\n\n/- Lemma\nEquivalent definitions of continuity.\n-/\nlemma continuity_topological (f : \u211d \u2192 \u211d) (X : set \u211d) :\n    continuous_on_set f X \u2194 continuous_on_topo_def f X :=\nbegin\n    sorry,\nend\n\nend xena\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/topology/continuity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539553, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7136162641177052}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.multiset.lattice\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Multiset.FinsetOps\nimport Mathlib.Data.Multiset.Fold\n\n/-!\n# Lattice operations on multisets\n-/\n\n\nnamespace Multiset\n\nvariable {\u03b1 : Type _}\n\n/-! ### sup -/\n\n\nsection Sup\n\n-- can be defined with just `[Bot \u03b1]` where some lemmas hold without requiring `[OrderBot \u03b1]`\nvariable [SemilatticeSup \u03b1] [OrderBot \u03b1]\n\n/-- Supremum of a multiset: `sup {a, b, c} = a \u2294 b \u2294 c` -/\ndef sup (s : Multiset \u03b1) : \u03b1 :=\n  s.fold (\u00b7 \u2294 \u00b7) \u22a5\n#align multiset.sup Multiset.sup\n\n@[simp]\ntheorem sup_coe (l : List \u03b1) : sup (l : Multiset \u03b1) = l.foldr (\u00b7 \u2294 \u00b7) \u22a5 :=\n  rfl\n#align multiset.sup_coe Multiset.sup_coe\n\n@[simp]\ntheorem sup_zero : (0 : Multiset \u03b1).sup = \u22a5 :=\n  fold_zero _ _\n#align multiset.sup_zero Multiset.sup_zero\n\n@[simp]\ntheorem sup_cons (a : \u03b1) (s : Multiset \u03b1) : (a ::\u2098 s).sup = a \u2294 s.sup :=\n  fold_cons_left _ _ _ _\n#align multiset.sup_cons Multiset.sup_cons\n\n@[simp]\ntheorem sup_singleton {a : \u03b1} : ({a} : Multiset \u03b1).sup = a :=\n  sup_bot_eq\n#align multiset.sup_singleton Multiset.sup_singleton\n\n@[simp]\ntheorem sup_add (s\u2081 s\u2082 : Multiset \u03b1) : (s\u2081 + s\u2082).sup = s\u2081.sup \u2294 s\u2082.sup :=\n  Eq.trans (by simp [sup]) (fold_add _ _ _ _ _)\n#align multiset.sup_add Multiset.sup_add\n\ntheorem sup_le {s : Multiset \u03b1} {a : \u03b1} : s.sup \u2264 a \u2194 \u2200 b \u2208 s, b \u2264 a :=\n  Multiset.induction_on s (by simp)\n    (by simp (config := { contextual := true }) [or_imp, forall_and])\n#align multiset.sup_le Multiset.sup_le\n\ntheorem le_sup {s : Multiset \u03b1} {a : \u03b1} (h : a \u2208 s) : a \u2264 s.sup :=\n  sup_le.1 le_rfl _ h\n#align multiset.le_sup Multiset.le_sup\n\ntheorem sup_mono {s\u2081 s\u2082 : Multiset \u03b1} (h : s\u2081 \u2286 s\u2082) : s\u2081.sup \u2264 s\u2082.sup :=\n  sup_le.2 fun _ hb => le_sup (h hb)\n#align multiset.sup_mono Multiset.sup_mono\n\nvariable [DecidableEq \u03b1]\n\n@[simp]\ntheorem sup_dedup (s : Multiset \u03b1) : (dedup s).sup = s.sup :=\n  fold_dedup_idem _ _ _\n#align multiset.sup_dedup Multiset.sup_dedup\n\n@[simp]\ntheorem sup_ndunion (s\u2081 s\u2082 : Multiset \u03b1) : (ndunion s\u2081 s\u2082).sup = s\u2081.sup \u2294 s\u2082.sup := by\n  rw [\u2190 sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp\n#align multiset.sup_ndunion Multiset.sup_ndunion\n\n@[simp]\ntheorem sup_union (s\u2081 s\u2082 : Multiset \u03b1) : (s\u2081 \u222a s\u2082).sup = s\u2081.sup \u2294 s\u2082.sup := by\n  rw [\u2190 sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp\n#align multiset.sup_union Multiset.sup_union\n\n@[simp]\ntheorem sup_ndinsert (a : \u03b1) (s : Multiset \u03b1) : (ndinsert a s).sup = a \u2294 s.sup := by\n  rw [\u2190 sup_dedup, dedup_ext.2, sup_dedup, sup_cons]; simp\n#align multiset.sup_ndinsert Multiset.sup_ndinsert\n\ntheorem nodup_sup_iff {\u03b1 : Type _} [DecidableEq \u03b1] {m : Multiset (Multiset \u03b1)} :\n    m.sup.Nodup \u2194 \u2200 a : Multiset \u03b1, a \u2208 m \u2192 a.Nodup := by\n  -- Porting note: this was originally `apply m.induction_on`, which failed due to\n  -- `failed to elaborate eliminator, expected type is not available`\n  induction' m using Multiset.induction_on with _ _ h\n  \u00b7 simp\n  \u00b7 simp [h]\n#align multiset.nodup_sup_iff Multiset.nodup_sup_iff\n\nend Sup\n\n/-! ### inf -/\n\n\nsection Inf\n\n-- can be defined with just `[Top \u03b1]` where some lemmas hold without requiring `[OrderTop \u03b1]`\nvariable [SemilatticeInf \u03b1] [OrderTop \u03b1]\n\n/-- Infimum of a multiset: `inf {a, b, c} = a \u2293 b \u2293 c` -/\ndef inf (s : Multiset \u03b1) : \u03b1 :=\n  s.fold (\u00b7 \u2293 \u00b7) \u22a4\n#align multiset.inf Multiset.inf\n\n@[simp]\ntheorem inf_coe (l : List \u03b1) : inf (l : Multiset \u03b1) = l.foldr (\u00b7 \u2293 \u00b7) \u22a4 :=\n  rfl\n#align multiset.inf_coe Multiset.inf_coe\n\n@[simp]\ntheorem inf_zero : (0 : Multiset \u03b1).inf = \u22a4 :=\n  fold_zero _ _\n#align multiset.inf_zero Multiset.inf_zero\n\n@[simp]\ntheorem inf_cons (a : \u03b1) (s : Multiset \u03b1) : (a ::\u2098 s).inf = a \u2293 s.inf :=\n  fold_cons_left _ _ _ _\n#align multiset.inf_cons Multiset.inf_cons\n\n@[simp]\ntheorem inf_singleton {a : \u03b1} : ({a} : Multiset \u03b1).inf = a :=\n  inf_top_eq\n#align multiset.inf_singleton Multiset.inf_singleton\n\n@[simp]\ntheorem inf_add (s\u2081 s\u2082 : Multiset \u03b1) : (s\u2081 + s\u2082).inf = s\u2081.inf \u2293 s\u2082.inf :=\n  Eq.trans (by simp [inf]) (fold_add _ _ _ _ _)\n#align multiset.inf_add Multiset.inf_add\n\ntheorem le_inf {s : Multiset \u03b1} {a : \u03b1} : a \u2264 s.inf \u2194 \u2200 b \u2208 s, a \u2264 b :=\n  Multiset.induction_on s (by simp)\n    (by simp (config := { contextual := true }) [or_imp, forall_and])\n#align multiset.le_inf Multiset.le_inf\n\ntheorem inf_le {s : Multiset \u03b1} {a : \u03b1} (h : a \u2208 s) : s.inf \u2264 a :=\n  le_inf.1 le_rfl _ h\n#align multiset.inf_le Multiset.inf_le\n\ntheorem inf_mono {s\u2081 s\u2082 : Multiset \u03b1} (h : s\u2081 \u2286 s\u2082) : s\u2082.inf \u2264 s\u2081.inf :=\n  le_inf.2 fun _ hb => inf_le (h hb)\n#align multiset.inf_mono Multiset.inf_mono\n\nvariable [DecidableEq \u03b1]\n\n@[simp]\ntheorem inf_dedup (s : Multiset \u03b1) : (dedup s).inf = s.inf :=\n  fold_dedup_idem _ _ _\n#align multiset.inf_dedup Multiset.inf_dedup\n\n@[simp]\ntheorem inf_ndunion (s\u2081 s\u2082 : Multiset \u03b1) : (ndunion s\u2081 s\u2082).inf = s\u2081.inf \u2293 s\u2082.inf := by\n  rw [\u2190 inf_dedup, dedup_ext.2, inf_dedup, inf_add]; simp\n#align multiset.inf_ndunion Multiset.inf_ndunion\n\n@[simp]\n\n\n@[simp]\ntheorem inf_ndinsert (a : \u03b1) (s : Multiset \u03b1) : (ndinsert a s).inf = a \u2293 s.inf := by\n  rw [\u2190 inf_dedup, dedup_ext.2, inf_dedup, inf_cons]; simp\n#align multiset.inf_ndinsert Multiset.inf_ndinsert\n\nend Inf\n\nend Multiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Multiset/Lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619979547273, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7136126932827878}}
{"text": "import tactic\nimport data.real.basic\n\n/-\nTwo functions f, g : \u211d \u2192 \u211d are such that for all x \u2208 \u211d,\ng(x) = x\u00b2 + x + 3, and (g \u2218 f)(x) = x\u00b2 \u2212 3x + 5.\nFind the possibilities for f .\n-/\n\ndef g : \u211d \u2192 \u211d := \u03bb x, x^2+x+3\n\n-- Edit the \"\u2200 x, f x = 37\" part of the claim below and replace it with your answer \nexample (f : \u211d \u2192 \u211d) : ((g \u2218 f) = \u03bb x, x^2-3*x+5) \u2194 \u2200 x, f x = x - 2 \u2228 f x = - x + 1 :=\nbegin\n  simp [function.funext_iff, g],\n  apply forall_congr,\n  intro x,\n  split,\n  {\n    intro h,\n    let y := f x,\n    have : y^2 + y + 3 = x^2 - 3 * x + 5 \u2192 y = x - 2 \u2228 y = -x + 1,\n    {\n      intro h,\n      have h' : y^2 + y + 3 = x^2 - 3 * x + 5 \u2194 (y - (x - 2)) * (y - (-x + 1)) = 0,\n      {split; intro h; nlinarith},\n      simpa [h', zero_eq_mul, sub_eq_zero] using h,\n    },\n    specialize this h,\n    exact this,\n  },\n  {\n    rintro (h | h);\n    simp [h] at *;\n    ring,\n  },\nend\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "m1fexplained_lean3", "sha": "570c9a3ff8cfc3805047f2796864516a49f51510", "save_path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3", "path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3/m1fexplained_lean3-570c9a3ff8cfc3805047f2796864516a49f51510/src/chapter19/exercises/exercise03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172673767973, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.7135977270729711}}
{"text": "import tactic --hide\n\n-- Level name : Super Boss\n\n\n/-Lemma\nTime for a super boss fight!\n-/\nlemma and_impl_equiv (P Q R : Prop) : (P  \u2192 Q) \u2227 (Q \u2192 R) \u2194 (P \u2192 R) \u2227 ((P \u2194 Q) \u2228 (R \u2194 Q)) :=\nbegin\n  tauto!,\n  \n\nend\n\n/-Hint : Cheat code\nCongratulations! If you are reading this you are about to unlock a cheat code!\nLean has more advanced tactics that can solve all of the levels very quickly. For example,\nusing the `tauto!` tactic should allow you to solve the whole game! (but what's the fun in that?)\n-/\n\n/-\nThat's all folks! If you enjoyed this then check out the\n<a href=\"https://www.ma.imperial.ac.uk/~buzzard/xena/natural_number_game/\" target=\"blank\">Natural Numbers Game</a>\nand Kevin Buzzard's <a href=\"https://www.ma.imperial.ac.uk/~buzzard/xena/formalising-mathematics-2022/\" target=\"blank\">Formalising mathematics</a> course.\n\n-/", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic2/logical_ands8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.7135846565635535}}
{"text": "import .cone .colvec\n\nsection dual_cone\n\nvariables {k m n : nat} (a : \u211d) (x y z : colvec (fin n) \u211d) (A : set (colvec (fin n) \u211d))\n\ndef second_order_cone (n : nat): set (colvec (fin (n + 1)) \u211d ) :=\n{ x | \u2225 x.tail \u2225 \u2264 x.head }\n\nlemma cone_second_order_cone : \ncone (second_order_cone n) :=\nbegin\n  intros x ha c hc,\n  unfold second_order_cone at *,\n  rw [set.mem_set_of_eq, colvec.tail_smul, colvec.head_smul, \n    norm_smul, real.norm_eq_abs, abs_of_nonneg hc],\n  exact mul_le_mul (le_refl c) ha (norm_nonneg _) hc\nend\n\npostfix `\u1d40` : 1500 := set.image matrix.transpose\n\nlemma second_order_cone_self_dual : \n  dual_cone (second_order_cone n) = second_order_cone n :=\nbegin\n  have h_ltr: dual_cone (second_order_cone n) \u2286 second_order_cone n,\n  { assume (y : colvec (fin (n + 1)) \u211d) (hy : y \u2208 dual_cone (second_order_cone n)),\n    by_cases h_cases : y.tail = 0,\n    { have h : (0:\u211d) \u2264 \u27ea colvec.cons 1 0, y \u27eb,\n      { apply hy (colvec.cons 1 0),\n        simp [second_order_cone,zero_le_one] },\n      have h : 0 \u2264 y.head,\n      { rw [\u2190@colvec.mul_head_add_mul_tail n \u211d _ (colvec.cons 1 0) y] at h,\n        simpa [matrix.mul_zero'] using h },\n      show y \u2208 second_order_cone n,\n      { unfold second_order_cone,\n        rwa [set.mem_set_of_eq, h_cases, norm_zero] }\n    },\n    { let y1 := y.head,\n      let y2 := y.tail,\n      have h : (0 : \u211d) \u2264 real.sqrt \u27ea y2, y2 \u27eb * y1 + \u27ea - y2, y2 \u27eb,\n      { convert hy (colvec.cons (real.sqrt \u27ea y2, y2 \u27eb) (- y2)) _,\n        unfold has_inner.inner,\n        convert @colvec.mul_head_add_mul_tail n \u211d _ _ _,\n        { simp },\n        { simp },\n        simp [second_order_cone],\n        refl\n      },\n      have h : \u27ea y2, y2 \u27eb \u2264 real.sqrt \u27ea y2, y2 \u27eb * y1,\n      { \n        apply le_of_sub_nonneg,\n        rw real_inner_product_space.inner_neg_left at h,\n        rwa sub_eq_add_neg,\n      },\n      have h : real.sqrt \u27ea y2, y2 \u27eb * \u27ea y2, y2 \u27eb \u2264 real.sqrt \u27ea y2, y2 \u27eb * (real.sqrt \u27ea y2, y2 \u27eb * y1),\n        from mul_le_mul (le_refl _) h (real_inner_product_space.inner_self_nonneg _) (real.sqrt_nonneg _),\n      have h : \u27ea y2, y2 \u27eb * real.sqrt \u27ea y2, y2 \u27eb \u2264 \u27ea y2, y2 \u27eb * y1,\n      {\n        rw [\u2190mul_assoc, mul_comm] at h,\n        convert h,\n        convert (@real.sqrt_mul \u27ea y2, y2 \u27eb (real_inner_product_space.inner_self_nonneg _) \u27ea y2, y2 \u27eb),\n        apply (real.sqrt_mul_self (real_inner_product_space.inner_self_nonneg _)).symm\n      },\n      show y \u2208 second_order_cone n,\n        from le_of_mul_le_mul_left h (real_inner_product_space.inner_self_pos h_cases),\n    }\n  },\n  have h_rtl: second_order_cone n \u2286 dual_cone (second_order_cone n),\n  begin\n    assume (y : colvec (fin (n + 1)) \u211d),\n    assume (hy : y \u2208 second_order_cone n),\n    assume (x : colvec (fin (n + 1)) \u211d) (hx : real.sqrt \u27ea x.tail, x.tail \u27eb \u2264 x.head),\n    have hx' : real.sqrt \u27ea - x.tail, - x.tail \u27eb \u2264 x.head,\n      by simpa,\n    have h : \u27ea -x.tail, y.tail \u27eb \u2264 x.head * y.head,\n      calc \u27ea -x.tail, y.tail \u27eb\n            \u2264 real.sqrt \u27ea -x.tail, -x.tail \u27eb * real.sqrt \u27ea y.tail, y.tail \u27eb \n              : real_inner_product_space.cauchy_schwartz' _ _\n        ... \u2264 x.head * y.head\n              : mul_le_mul hx' hy (real.sqrt_nonneg _) (le_trans (real.sqrt_nonneg _) hx'),\n    show 0 \u2264 \u27ea x, y \u27eb,\n    {\n      rw [\u2190@colvec.mul_head_add_mul_tail n \u211d _ x y],\n      rw [real_inner_product_space.inner_neg_left] at h,\n      convert sub_nonneg_of_le h,\n      simp\n    }\n  end,\n  show dual_cone (second_order_cone n) = second_order_cone n,\n    from set.subset.antisymm h_ltr h_rtl\nend\n\nend dual_cone", "meta": {"author": "skbaek", "repo": "cvx", "sha": "c50c790c9116f9fac8dfe742903a62bdd7292c15", "save_path": "github-repos/lean/skbaek-cvx", "path": "github-repos/lean/skbaek-cvx/cvx-c50c790c9116f9fac8dfe742903a62bdd7292c15/src/vec_cone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7135454350960765}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n\nDefine the p-adic numbers (rationals) \u211a_p as the completion of \u211a wrt the p-adic norm.\nShow that the p-adic norm extends to \u211a_p, that \u211a is embedded in \u211a_p, and that \u211a_p is complete\n-/\n\nimport data.real.cau_seq_completion topology.metric_space.cau_seq_filter\nimport data.padics.padic_norm algebra.archimedean analysis.normed_space.basic\nnoncomputable theory\nlocal attribute [instance, priority 1] classical.prop_decidable\n\nopen nat multiplicity padic_norm cau_seq cau_seq.completion metric\n\n@[reducible] def padic_seq (p : \u2115) [p.prime] := cau_seq _ (padic_norm p)\n\nnamespace padic_seq\n\nsection\nvariables {p : \u2115} [nat.prime p]\n\nlemma stationary {f : cau_seq \u211a (padic_norm p)} (hf : \u00ac f \u2248 0) :\n  \u2203 N, \u2200 m n, m \u2265 N \u2192 n \u2265 N \u2192 padic_norm p (f n) = padic_norm p (f m) :=\nhave \u2203 \u03b5 > 0, \u2203 N1, \u2200 j \u2265 N1, \u03b5 \u2264 padic_norm p (f j),\n  from cau_seq.abv_pos_of_not_lim_zero $ not_lim_zero_of_not_congr_zero hf,\nlet \u27e8\u03b5, h\u03b5, N1, hN1\u27e9 := this,\n    \u27e8N2, hN2\u27e9 := cau_seq.cauchy\u2082 f h\u03b5 in\n\u27e8 max N1 N2,\n  \u03bb n m hn hm,\n  have padic_norm p (f n - f m) < \u03b5, from hN2 _ _ (max_le_iff.1 hn).2 (max_le_iff.1 hm).2,\n  have padic_norm p (f n - f m) < padic_norm p (f n),\n    from lt_of_lt_of_le this $ hN1 _ (max_le_iff.1 hn).1,\n  have  padic_norm p (f n - f m) < max (padic_norm p (f n)) (padic_norm p (f m)),\n    from lt_max_iff.2 (or.inl this),\n  begin\n    by_contradiction hne,\n    rw \u2190padic_norm.neg p (f m) at hne,\n    have hnam := add_eq_max_of_ne p hne,\n    rw [padic_norm.neg, max_comm] at hnam,\n    rw \u2190hnam at this,\n    apply _root_.lt_irrefl _ (by simp at this; exact this)\n  end \u27e9\n\ndef stationary_point {f : padic_seq p} (hf : \u00ac f \u2248 0) : \u2115 :=\nclassical.some $ stationary hf\n\nlemma stationary_point_spec {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  \u2200 {m n}, m \u2265 stationary_point hf \u2192 n \u2265 stationary_point hf \u2192\n    padic_norm p (f n) = padic_norm p (f m) :=\nclassical.some_spec $ stationary hf\n\ndef norm (f : padic_seq p) : \u211a :=\nif hf : f \u2248 0 then 0 else padic_norm p (f (stationary_point hf))\n\nlemma norm_zero_iff (f : padic_seq p) : f.norm = 0 \u2194 f \u2248 0 :=\nbegin\n  constructor,\n  { intro h,\n    by_contradiction hf,\n    unfold norm at h, split_ifs at h,\n    apply hf,\n    intros \u03b5 h\u03b5,\n    existsi stationary_point hf,\n    intros j hj,\n    have heq := stationary_point_spec hf (le_refl _) hj,\n    simpa [h, heq] },\n  { intro h,\n    simp [norm, h] }\nend\n\nend\n\nsection embedding\nopen cau_seq\nvariables {p : \u2115} [nat.prime p]\n\nlemma equiv_zero_of_val_eq_of_equiv_zero {f g : padic_seq p}\n  (h : \u2200 k, padic_norm p (f k) = padic_norm p (g k)) (hf : f \u2248 0) : g \u2248 0 :=\n\u03bb \u03b5 h\u03b5, let \u27e8i, hi\u27e9 := hf _ h\u03b5 in\n\u27e8i, \u03bb j hj, by simpa [h] using hi _ hj\u27e9\n\nlemma norm_nonzero_of_not_equiv_zero {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  f.norm \u2260 0 :=\nhf \u2218 f.norm_zero_iff.1\n\nlemma norm_eq_norm_app_of_nonzero {f : padic_seq p} (hf : \u00ac f \u2248 0) :\n  \u2203 k, f.norm = padic_norm p k \u2227 k \u2260 0 :=\nhave heq : f.norm = padic_norm p (f $ stationary_point hf), by simp [norm, hf],\n\u27e8f $ stationary_point hf, heq,\n  \u03bb h, norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)\u27e9\n\nlemma not_lim_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac lim_zero (const (padic_norm p) q) :=\n\u03bb h', hq $ const_lim_zero.1 h'\n\nlemma not_equiv_zero_const_of_nonzero {q : \u211a} (hq : q \u2260 0) : \u00ac (const (padic_norm p) q) \u2248 0 :=\n\u03bb h : lim_zero (const (padic_norm p) q - 0), not_lim_zero_const_of_nonzero hq $ by simpa using h\n\nlemma norm_nonneg (f : padic_seq p) : f.norm \u2265 0 :=\nif hf : f \u2248 0 then by simp [hf, norm]\nelse by simp [norm, hf, padic_norm.nonneg]\n\nlemma lift_index_left_left {f : padic_seq p} (hf : \u00ac f \u2248 0) (v2 v3 : \u2115) :\n  padic_norm p (f (stationary_point hf)) = padic_norm p (f (max (stationary_point hf) (max v2 v3))) :=\nlet i := max (stationary_point hf) (max v2 v3) in\nbegin\n  apply stationary_point_spec hf,\n  { apply le_max_left },\n  { apply le_refl }\nend\n\nlemma lift_index_left {f : padic_seq p} (hf : \u00ac f \u2248 0) (v1 v3 : \u2115) :\n  padic_norm p (f (stationary_point hf)) = padic_norm p (f (max v1 (max (stationary_point hf) v3))) :=\nlet i := max v1 (max (stationary_point hf) v3) in\nbegin\n  apply stationary_point_spec hf,\n  { apply le_trans,\n    { apply le_max_left _ v3 },\n    { apply le_max_right } },\n  { apply le_refl }\nend\n\nlemma lift_index_right {f : padic_seq p} (hf : \u00ac f \u2248 0) (v1 v2 : \u2115) :\n  padic_norm p (f (stationary_point hf)) = padic_norm p (f (max v1 (max v2 (stationary_point hf)))) :=\nlet i := max v1 (max v2 (stationary_point hf)) in\nbegin\n  apply stationary_point_spec hf,\n  { apply le_trans,\n    { apply le_max_right v2 },\n    { apply le_max_right } },\n  { apply le_refl }\nend\n\nend embedding\n\nend padic_seq\n\nsection\nopen padic_seq\n\nmeta def index_simp_core (hh hf hg : expr) (at_ : interactive.loc := interactive.loc.ns [none]) : tactic unit :=\ndo [v1, v2, v3] \u2190 [hh, hf, hg].mmap\n     (\u03bb n, tactic.mk_app ``stationary_point [n] <|> return n),\n   e1 \u2190 tactic.mk_app ``lift_index_left_left [hh, v2, v3] <|> return `(true),\n   e2 \u2190 tactic.mk_app ``lift_index_left [hf, v1, v3] <|> return `(true),\n   e3 \u2190 tactic.mk_app ``lift_index_right [hg, v1, v2] <|> return `(true),\n   sl \u2190 [e1, e2, e3].mfoldl (\u03bb s e, simp_lemmas.add s e) simp_lemmas.mk,\n   when at_.include_goal (tactic.simp_target sl),\n   hs \u2190 at_.get_locals, hs.mmap' (tactic.simp_hyp sl [])\n\n/--\n  This is a special-purpose tactic that lifts padic_norm (f (stationary_point f)) to\n  padic_norm (f (max _ _ _)).\n-/\nmeta def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)\n  (at_ : interactive.parse interactive.types.location) : tactic unit :=\ndo [h, f, g] \u2190 l.mmap tactic.i_to_expr,\n   index_simp_core h f g at_\nend\n\nnamespace padic_seq\nsection embedding\n\nopen cau_seq\nvariables {p : \u2115} [hp : nat.prime p]\ninclude hp\n\nlemma norm_mul (f g : padic_seq p) : (f * g).norm = f.norm * g.norm :=\nif hf : f \u2248 0 then\n  have hg : f * g \u2248 0, from mul_equiv_zero' _ hf,\n  by simp [hf, hg, norm]\nelse if hg : g \u2248 0 then\n  have hf : f * g \u2248 0, from mul_equiv_zero _ hg,\n  by simp [hf, hg, norm]\nelse\n  have hfg : \u00ac f * g \u2248 0, by apply mul_not_equiv_zero; assumption,\n  begin\n    unfold norm,\n    split_ifs,\n    padic_index_simp [hfg, hf, hg],\n    apply padic_norm.mul\n  end\n\nlemma eq_zero_iff_equiv_zero (f : padic_seq p) : mk f = 0 \u2194 f \u2248 0 :=\nmk_eq\n\nlemma ne_zero_iff_nequiv_zero (f : padic_seq p) : mk f \u2260 0 \u2194 \u00ac f \u2248 0 :=\nnot_iff_not.2 (eq_zero_iff_equiv_zero _)\n\nlemma norm_const (q : \u211a) : norm (const (padic_norm p) q) = padic_norm p q :=\nif hq : q = 0 then\n  have (const (padic_norm p) q) \u2248 0,\n    by simp [hq]; apply setoid.refl (const (padic_norm p) 0),\n  by subst hq; simp [norm, this]\nelse\n  have \u00ac (const (padic_norm p) q) \u2248 0, from not_equiv_zero_const_of_nonzero hq,\n  by simp [norm, this]\n\nlemma norm_image (a : padic_seq p) (ha : \u00ac a \u2248 0) :\n  (\u2203 (n : \u2124), a.norm = \u2191p ^ (-n)) :=\nlet \u27e8k, hk, hk'\u27e9 := norm_eq_norm_app_of_nonzero ha in\nby simpa [hk] using padic_norm.image p hk'\n\nlemma norm_one : norm (1 : padic_seq p) = 1 :=\nhave h1 : \u00ac (1 : padic_seq p) \u2248 0, from one_not_equiv_zero _,\nby simp [h1, norm, hp.gt_one]\n\nprivate lemma norm_eq_of_equiv_aux {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g)\n  (h : padic_norm p (f (stationary_point hf)) \u2260 padic_norm p (g (stationary_point hg)))\n  (hgt : padic_norm p (f (stationary_point hf)) > padic_norm p (g (stationary_point hg))) :\n  false :=\nbegin\n  have hpn : padic_norm p (f (stationary_point hf)) - padic_norm p (g (stationary_point hg)) > 0,\n    from sub_pos_of_lt hgt,\n  cases hfg _ hpn with N hN,\n  let i := max N (max (stationary_point hf) (stationary_point hg)),\n  have hi : i \u2265 N, from le_max_left _ _,\n  have hN' := hN _ hi,\n  padic_index_simp [N, hf, hg] at hN' h hgt,\n  have hpne : padic_norm p (f i) \u2260 padic_norm p (-(g i)),\n    by rwa [ \u2190padic_norm.neg p (g i)] at h,\n  let hpnem := add_eq_max_of_ne p hpne,\n  have hpeq : padic_norm p ((f - g) i) = max (padic_norm p (f i)) (padic_norm p (g i)),\n  { rwa padic_norm.neg at hpnem },\n  rw [hpeq, max_eq_left_of_lt hgt] at hN',\n  have : padic_norm p (f i) < padic_norm p (f i),\n  { apply lt_of_lt_of_le hN', apply sub_le_self, apply padic_norm.nonneg },\n  exact lt_irrefl _ this\nend\n\nprivate lemma norm_eq_of_equiv {f g : padic_seq p} (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) (hfg : f \u2248 g) :\n  padic_norm p (f (stationary_point hf)) = padic_norm p (g (stationary_point hg)) :=\nbegin\n  by_contradiction h,\n  cases (decidable.em (padic_norm p (f (stationary_point hf)) >\n          padic_norm p (g (stationary_point hg))))\n      with hgt hngt,\n  { exact norm_eq_of_equiv_aux hf hg hfg h hgt },\n  { apply norm_eq_of_equiv_aux hg hf (setoid.symm hfg) (ne.symm h),\n    apply lt_of_le_of_ne,\n    apply le_of_not_gt hngt,\n    apply h }\nend\n\ntheorem norm_equiv {f g : padic_seq p} (hfg : f \u2248 g) : f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from setoid.trans (setoid.symm hfg) hf,\n  by simp [norm, hf, hg]\nelse have hg : \u00ac g \u2248 0, from hf \u2218 setoid.trans hfg,\nby unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg\n\nprivate lemma norm_nonarchimedean_aux {f g : padic_seq p}\n  (hfg : \u00ac f + g \u2248 0) (hf : \u00ac f \u2248 0) (hg : \u00ac g \u2248 0) : (f + g).norm \u2264 max (f.norm) (g.norm) :=\nbegin\n  unfold norm, split_ifs,\n  padic_index_simp [hfg, hf, hg],\n  apply padic_norm.nonarchimedean\nend\n\ntheorem norm_nonarchimedean (f g : padic_seq p) : (f + g).norm \u2264 max (f.norm) (g.norm) :=\nif hfg : f + g \u2248 0 then\n  have 0 \u2264 max (f.norm) (g.norm), from le_max_left_of_le (norm_nonneg _),\n  by simpa [hfg, norm]\nelse if hf : f \u2248 0 then\n  have hfg' : f + g \u2248 g,\n  { change lim_zero (f - 0) at hf,\n    show lim_zero (f + g - g), by simpa using hf },\n  have hcfg : (f + g).norm = g.norm, from norm_equiv hfg',\n  have hcl : f.norm = 0, from (norm_zero_iff f).2 hf,\n  have max (f.norm) (g.norm) = g.norm,\n    by rw hcl; exact max_eq_right (norm_nonneg _),\n  by rw [this, hcfg]\nelse if hg : g \u2248 0 then\n  have hfg' : f + g \u2248 f,\n  { change lim_zero (g - 0) at hg,\n    show lim_zero (f + g - f), by  simpa [add_sub_cancel'] using hg },\n  have hcfg : (f + g).norm = f.norm, from norm_equiv hfg',\n  have hcl : g.norm = 0, from (norm_zero_iff g).2 hg,\n  have max (f.norm) (g.norm) = f.norm,\n    by rw hcl; exact max_eq_left (norm_nonneg _),\n  by rw [this, hcfg]\nelse norm_nonarchimedean_aux hfg hf hg\n\nlemma norm_eq {f g : padic_seq p} (h : \u2200 k, padic_norm p (f k) = padic_norm p (g k)) :\n  f.norm = g.norm :=\nif hf : f \u2248 0 then\n  have hg : g \u2248 0, from equiv_zero_of_val_eq_of_equiv_zero h hf,\n  by simp [hf, hg, norm]\nelse\n  have hg : \u00ac g \u2248 0, from \u03bb hg, hf $ equiv_zero_of_val_eq_of_equiv_zero (by simp [h]) hg,\n  begin\n    simp [hg, hf, norm],\n    let i := max (stationary_point hf) (stationary_point hg),\n    have hpf : padic_norm p (f (stationary_point hf)) = padic_norm p (f i),\n    { apply stationary_point_spec, apply le_max_left, apply le_refl },\n    have hpg : padic_norm p (g (stationary_point hg)) = padic_norm p (g i),\n    { apply stationary_point_spec, apply le_max_right, apply le_refl },\n    rw [hpf, hpg, h]\n  end\n\nlemma norm_neg (a : padic_seq p) : (-a).norm = a.norm :=\nnorm_eq $ by simp\n\nlemma norm_eq_of_add_equiv_zero {f g : padic_seq p} (h : f + g \u2248 0) : f.norm = g.norm :=\nhave lim_zero (f + g - 0), from h,\nhave f \u2248 -g, from show lim_zero (f - (-g)), by simpa,\nhave f.norm = (-g).norm, from norm_equiv this,\nby simpa [norm_neg] using this\n\nlemma add_eq_max_of_ne {f g : padic_seq p} (hfgne : f.norm \u2260 g.norm) :\n  (f + g).norm = max f.norm g.norm :=\nhave hfg : \u00acf + g \u2248 0, from mt norm_eq_of_add_equiv_zero hfgne,\nif hf : f \u2248 0 then\n  have lim_zero (f - 0), from hf,\n  have f + g \u2248 g, from show lim_zero ((f + g) - g), by simpa,\n  have h1 : (f+g).norm = g.norm, from norm_equiv this,\n  have h2 : f.norm = 0, from (norm_zero_iff _).2 hf,\n  by rw [h1, h2]; rw max_eq_right (norm_nonneg _)\nelse if hg : g \u2248 0 then\n  have lim_zero (g - 0), from hg,\n  have f + g \u2248 f, from show lim_zero ((f + g) - f), by rw [add_sub_cancel']; simpa,\n  have h1 : (f+g).norm = f.norm, from norm_equiv this,\n  have h2 : g.norm = 0, from (norm_zero_iff _).2 hg,\n  by rw [h1, h2]; rw max_eq_left (norm_nonneg _)\nelse\nbegin\n  unfold norm at \u22a2 hfgne, split_ifs at \u22a2 hfgne,\n  padic_index_simp [hfg, hf, hg] at \u22a2 hfgne,\n  apply padic_norm.add_eq_max_of_ne,\n  simpa [hf, hg, norm] using hfgne\nend\n\nend embedding\nend padic_seq\n\ndef padic (p : \u2115) [nat.prime p] := @cau_seq.completion.Cauchy _ _ _ _ (padic_norm p) _\nnotation `\u211a_[` p `]` := padic p\n\nnamespace padic\n\nsection completion\nvariables {p : \u2115} [nat.prime p]\n\ninstance discrete_field : discrete_field (\u211a_[p]) :=\ncau_seq.completion.discrete_field\n\n-- short circuits\n\ninstance : has_zero \u211a_[p] := by apply_instance\ninstance : has_one \u211a_[p] := by apply_instance\ninstance : has_add \u211a_[p] := by apply_instance\ninstance : has_mul \u211a_[p] := by apply_instance\ninstance : has_sub \u211a_[p] := by apply_instance\ninstance : has_neg \u211a_[p] := by apply_instance\ninstance : has_div \u211a_[p] := by apply_instance\ninstance : add_comm_group \u211a_[p] := by apply_instance\ninstance : comm_ring \u211a_[p] := by apply_instance\n\ndef mk : padic_seq p \u2192 \u211a_[p] := quotient.mk\nend completion\n\nsection completion\nvariables (p : \u2115) [nat.prime p]\n\nlemma mk_eq {f g : padic_seq p} : mk f = mk g \u2194 f \u2248 g := quotient.eq\n\ndef of_rat : \u211a \u2192 \u211a_[p] := cau_seq.completion.of_rat\n\n@[simp] lemma of_rat_add : \u2200 (x y : \u211a), of_rat p (x + y) = of_rat p x + of_rat p y :=\ncau_seq.completion.of_rat_add\n\n@[simp] lemma of_rat_neg : \u2200 (x : \u211a), of_rat p (-x) = -of_rat p x :=\ncau_seq.completion.of_rat_neg\n\n@[simp] lemma of_rat_mul : \u2200 (x y : \u211a), of_rat p (x * y) = of_rat p x * of_rat p y :=\ncau_seq.completion.of_rat_mul\n\n@[simp] lemma of_rat_sub : \u2200 (x y : \u211a), of_rat p (x - y) = of_rat p x - of_rat p y :=\ncau_seq.completion.of_rat_sub\n\n@[simp] lemma of_rat_div : \u2200 (x y : \u211a), of_rat p (x / y) = of_rat p x / of_rat p y :=\ncau_seq.completion.of_rat_div\n\n@[simp] lemma of_rat_one : of_rat p 1 = 1 := rfl\n\n@[simp] lemma of_rat_zero : of_rat p 0 = 0 := rfl\n\n@[simp] lemma cast_eq_of_rat_of_nat (n : \u2115) : (\u2191n : \u211a_[p]) = of_rat p n :=\nbegin\n  induction n with n ih,\n  { refl },\n  { simpa using ih }\nend\n\nexample {\u03b1} [discrete_field \u03b1] (n : \u2124) : \u03b1 := n\n\n-- without short circuits, this needs an increase of class.instance_max_depth\n@[simp] lemma cast_eq_of_rat_of_int (n : \u2124) : \u2191n = of_rat p n :=\nby induction n; simp\n\nlemma cast_eq_of_rat : \u2200 (q : \u211a), (\u2191q : \u211a_[p]) = of_rat p q\n| \u27e8n, d, h1, h2\u27e9 :=\n  show \u2191n / \u2191d = _, from\n    have (\u27e8n, d, h1, h2\u27e9 : \u211a) = rat.mk n d, from rat.num_denom _,\n    by simp [this, rat.mk_eq_div, of_rat_div]\n\nlemma const_equiv {q r : \u211a} : const (padic_norm p) q \u2248 const (padic_norm p) r \u2194 q = r :=\n\u27e8 \u03bb heq : lim_zero (const (padic_norm p) (q - r)),\n    eq_of_sub_eq_zero $ const_lim_zero.1 heq,\n  \u03bb heq, by rw heq; apply setoid.refl _ \u27e9\n\nlemma of_rat_eq {q r : \u211a} : of_rat p q = of_rat p r \u2194 q = r :=\n\u27e8(const_equiv p).1 \u2218 quotient.eq.1, \u03bb h, by rw h\u27e9\n\ninstance : char_zero \u211a_[p] :=\n\u27e8 \u03bb m n, suffices of_rat p \u2191m = of_rat p \u2191n \u2194 m = n, by simpa using this,\n    by simp [of_rat_eq] \u27e9\n\nend completion\nend padic\n\ndef padic_norm_e {p : \u2115} [hp : nat.prime p] : \u211a_[p] \u2192 \u211a :=\nquotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _\n\nnamespace padic_norm_e\nsection embedding\nopen padic_seq\nvariables {p : \u2115} [nat.prime p]\n\nlemma defn (f : padic_seq p) {\u03b5 : \u211a} (h\u03b5 : \u03b5 > 0) : \u2203 N, \u2200 i \u2265 N, padic_norm_e (\u27e6f\u27e7 - f i) < \u03b5 :=\nbegin\n  simp only [padic.cast_eq_of_rat],\n  change \u2203 N, \u2200 i \u2265 N, (f - const _ (f i)).norm < \u03b5,\n  by_contradiction h,\n  cases cauchy\u2082 f h\u03b5 with N hN,\n  have : \u2200 N, \u2203 i \u2265 N, (f - const _ (f i)).norm \u2265 \u03b5,\n    by simpa [not_forall] using h,\n  rcases this N with \u27e8i, hi, hge\u27e9,\n  have hne : \u00ac (f - const (padic_norm p) (f i)) \u2248 0,\n  { intro h, unfold padic_seq.norm at hge; split_ifs at hge, exact not_lt_of_ge hge h\u03b5 },\n  unfold padic_seq.norm at hge; split_ifs at hge,\n  apply not_le_of_gt _ hge,\n  cases decidable.em ((stationary_point hne) \u2265 N) with hgen hngen,\n  { apply hN; assumption },\n  { have := stationary_point_spec hne (le_refl _) (le_of_not_le hngen),\n    rw \u2190this,\n    apply hN,\n    apply le_refl, assumption }\nend\n\nprotected lemma nonneg (q : \u211a_[p]) : padic_norm_e q \u2265 0 :=\nquotient.induction_on q $ norm_nonneg\n\nlemma zero_def : (0 : \u211a_[p]) = \u27e60\u27e7 := rfl\n\nlemma zero_iff (q : \u211a_[p]) : padic_norm_e q = 0 \u2194 q = 0 :=\nquotient.induction_on q $\n  by simpa only [zero_def, quotient.eq] using norm_zero_iff\n\n@[simp] protected lemma zero : padic_norm_e (0 : \u211a_[p]) = 0 :=\n(zero_iff _).2 rfl\n\n@[simp] protected lemma one' : padic_norm_e (1 : \u211a_[p]) = 1 :=\nnorm_one\n\n@[simp] protected lemma neg (q : \u211a_[p]) : padic_norm_e (-q) = padic_norm_e q :=\nquotient.induction_on q $ norm_neg\n\ntheorem nonarchimedean' (q r : \u211a_[p]) :\n  padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_nonarchimedean\n\ntheorem add_eq_max_of_ne' {q r : \u211a_[p]} :\n  padic_norm_e q \u2260 padic_norm_e r \u2192 padic_norm_e (q + r) = max (padic_norm_e q) (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ \u03bb _ _, padic_seq.add_eq_max_of_ne\n\nlemma triangle_ineq (x y z : \u211a_[p]) :\n  padic_norm_e (x - z) \u2264 padic_norm_e (x - y) + padic_norm_e (y - z) :=\ncalc padic_norm_e (x - z) = padic_norm_e ((x - y) + (y - z)) : by rw sub_add_sub_cancel\n  ... \u2264 max (padic_norm_e (x - y)) (padic_norm_e (y - z)) : padic_norm_e.nonarchimedean' _ _\n  ... \u2264 padic_norm_e (x - y) + padic_norm_e (y - z) :\n    max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)\n\nprotected lemma add (q r : \u211a_[p]) : padic_norm_e (q + r) \u2264 (padic_norm_e q) + (padic_norm_e r) :=\ncalc\n  padic_norm_e (q + r) \u2264 max (padic_norm_e q) (padic_norm_e r) : nonarchimedean' _ _\n                      ... \u2264 (padic_norm_e q) + (padic_norm_e r) :\n                              max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)\n\nprotected lemma mul' (q r : \u211a_[p]) : padic_norm_e (q * r) = (padic_norm_e q) * (padic_norm_e r) :=\nquotient.induction_on\u2082 q r $ norm_mul\n\ninstance : is_absolute_value (@padic_norm_e p _) :=\n{ abv_nonneg := padic_norm_e.nonneg,\n  abv_eq_zero := zero_iff,\n  abv_add := padic_norm_e.add,\n  abv_mul := padic_norm_e.mul' }\n\n@[simp] lemma eq_padic_norm' (q : \u211a) : padic_norm_e (padic.of_rat p q) = padic_norm p q :=\nnorm_const _\n\nprotected theorem image' {q : \u211a_[p]} : q \u2260 0 \u2192 \u2203 n : \u2124, padic_norm_e q = p ^ (-n) :=\nquotient.induction_on q $ \u03bb f hf,\n  have \u00ac f \u2248 0, from (ne_zero_iff_nequiv_zero f).1 hf,\n  norm_image f this\n\nlemma sub_rev (q r : \u211a_[p]) : padic_norm_e (q - r) = padic_norm_e (r - q) :=\nby rw \u2190(padic_norm_e.neg); simp\n\nend embedding\nend padic_norm_e\n\nnamespace padic\n\nsection complete\nopen padic_seq padic\n\ntheorem rat_dense' {p : \u2115} [nat.prime p] (q : \u211a_[p]) {\u03b5 : \u211a} (h\u03b5 : \u03b5 > 0) :\n  \u2203 r : \u211a, padic_norm_e (q - r) < \u03b5 :=\nquotient.induction_on q $ \u03bb q',\n  have \u2203 N, \u2200 m n \u2265 N, padic_norm p (q' m - q' n) < \u03b5, from cauchy\u2082 _ h\u03b5,\n  let \u27e8N, hN\u27e9 := this in\n  \u27e8q' N,\n    begin\n      simp only [padic.cast_eq_of_rat],\n      change padic_seq.norm (q' - const _ (q' N)) < \u03b5,\n      cases decidable.em ((q' - const (padic_norm p) (q' N)) \u2248 0) with heq hne',\n      { simpa only [heq, padic_seq.norm, dif_pos] },\n      { simp only [padic_seq.norm, dif_neg hne'],\n        change padic_norm p (q' _ - q' _) < \u03b5,\n        have := stationary_point_spec hne',\n        cases decidable.em (N \u2265 stationary_point hne') with hle hle,\n        { have := eq.symm (this (le_refl _) hle),\n          simp at this, simpa [this] },\n        { apply hN,\n          apply le_of_lt, apply lt_of_not_ge, apply hle, apply le_refl }}\n    end\u27e9\n\nvariables {p : \u2115} [nat.prime p] (f : cau_seq _ (@padic_norm_e p _))\nopen classical\n\nprivate lemma cast_succ_nat_pos (n : \u2115) : (\u2191(n + 1) : \u211a) > 0 :=\nnat.cast_pos.2 $ succ_pos _\n\nprivate lemma div_nat_pos (n : \u2115) : (1 / ((n + 1): \u211a)) > 0 :=\ndiv_pos zero_lt_one (cast_succ_nat_pos _)\n\ndef lim_seq : \u2115 \u2192 \u211a := \u03bb n, classical.some (rat_dense' (f n) (div_nat_pos n))\n\nlemma exi_rat_seq_conv {\u03b5 : \u211a} (h\u03b5 : 0 < \u03b5) :\n  \u2203 N, \u2200 i \u2265 N, padic_norm_e (f i - of_rat p ((lim_seq f) i)) < \u03b5 :=\nbegin\n  refine (exists_nat_gt (1/\u03b5)).imp (\u03bb N hN i hi, _),\n  have h := classical.some_spec (rat_dense' (f i) (div_nat_pos i)),\n  rw \u2190 cast_eq_of_rat,\n  refine lt_of_lt_of_le h (div_le_of_le_mul (cast_succ_nat_pos _) _),\n  rw right_distrib,\n  apply le_add_of_le_of_nonneg,\n  { exact le_mul_of_div_le h\u03b5 (le_trans (le_of_lt hN) (nat.cast_le.2 hi)) },\n  { apply le_of_lt, simpa }\nend\n\nlemma exi_rat_seq_conv_cauchy : is_cau_seq (padic_norm p) (lim_seq f) :=\nassume \u03b5 h\u03b5,\nhave h\u03b53 : \u03b5 / 3 > 0, from div_pos h\u03b5 (by norm_num),\nlet \u27e8N, hN\u27e9 := exi_rat_seq_conv f h\u03b53,\n    \u27e8N2, hN2\u27e9 := f.cauchy\u2082 h\u03b53 in\nbegin\n  existsi max N N2,\n  intros j hj,\n  rw [\u2190padic_norm_e.eq_padic_norm', padic.of_rat_sub],\n  suffices : padic_norm_e ((\u2191(lim_seq f j) - f (max N N2)) + (f (max N N2) - lim_seq f (max N N2))) < \u03b5,\n  { ring at this \u22a2, simpa only [cast_eq_of_rat] },\n  { apply lt_of_le_of_lt,\n    { apply padic_norm_e.add },\n    { have : (3 : \u211a) \u2260 0, by norm_num,\n      have : \u03b5 = \u03b5 / 3 + \u03b5 / 3 + \u03b5 / 3,\n      { apply eq_of_mul_eq_mul_left this, simp [left_distrib, mul_div_cancel' _ this ], ring },\n      rw this,\n      apply add_lt_add,\n      { suffices : padic_norm_e ((\u2191(lim_seq f j) - f j) + (f j - f (max N N2))) < \u03b5 / 3 + \u03b5 / 3,\n          by simpa,\n        apply lt_of_le_of_lt,\n        { apply padic_norm_e.add },\n        { apply add_lt_add,\n          { rw [padic_norm_e.sub_rev, cast_eq_of_rat], apply hN, apply le_of_max_le_left hj },\n          { apply hN2, apply le_of_max_le_right hj, apply le_max_right } } },\n      { rw cast_eq_of_rat, apply hN, apply le_max_left }}}\nend\n\nprivate def lim' : padic_seq p := \u27e8_, exi_rat_seq_conv_cauchy f\u27e9\n\nprivate def lim : \u211a_[p] := \u27e6lim' f\u27e7\n\ntheorem complete' : \u2203 q : \u211a_[p], \u2200 \u03b5 > 0, \u2203 N, \u2200 i \u2265 N, padic_norm_e (q - f i) < \u03b5 :=\n\u27e8 lim f,\n  \u03bb \u03b5 h\u03b5,\n  let \u27e8N, hN\u27e9 := exi_rat_seq_conv f (show \u03b5 / 2 > 0, from div_pos h\u03b5 (by norm_num)),\n      \u27e8N2, hN2\u27e9 := padic_norm_e.defn (lim' f) (show \u03b5 / 2 > 0, from div_pos h\u03b5 (by norm_num)) in\n  begin\n    existsi max N N2,\n    intros i hi,\n    suffices : padic_norm_e ((lim f - lim' f i) + (lim' f i - f i)) < \u03b5,\n    { ring at this; exact this },\n    { apply lt_of_le_of_lt,\n      { apply padic_norm_e.add },\n      { have : (2 : \u211a) \u2260 0, by norm_num,\n        have : \u03b5 = \u03b5 / 2 + \u03b5 / 2, by rw \u2190(add_self_div_two \u03b5); simp,\n        rw this,\n        apply add_lt_add,\n        { apply hN2, apply le_of_max_le_right hi },\n        { rw [padic_norm_e.sub_rev, cast_eq_of_rat], apply hN, apply le_of_max_le_left hi } } }\n  end \u27e9\n\nend complete\n\nsection normed_space\nvariables (p : \u2115) [nat.prime p]\n\ninstance : has_dist \u211a_[p] := \u27e8\u03bb x y, padic_norm_e (x - y)\u27e9\n\ninstance : metric_space \u211a_[p] :=\n{ dist_self := by simp [dist],\n  dist_comm := \u03bb x y, by unfold dist; rw \u2190padic_norm_e.neg (x - y); simp,\n  dist_triangle :=\n    begin\n      intros, unfold dist,\n      rw \u2190rat.cast_add,\n      apply rat.cast_le.2,\n      apply padic_norm_e.triangle_ineq\n    end,\n  eq_of_dist_eq_zero :=\n    begin\n      unfold dist, intros _ _ h,\n      apply eq_of_sub_eq_zero,\n      apply (padic_norm_e.zero_iff _).1,\n      simpa using h\n    end }\n\ninstance : has_norm \u211a_[p] := \u27e8\u03bb x, padic_norm_e x\u27e9\n\ninstance : normed_field \u211a_[p] :=\n{ dist_eq := \u03bb _ _, rfl,\n  norm_mul := by simp [has_norm.norm, padic_norm_e.mul'] }\n\ninstance : is_absolute_value (\u03bb a : \u211a_[p], \u2225a\u2225) :=\n{ abv_nonneg := norm_nonneg,\n  abv_eq_zero := norm_eq_zero,\n  abv_add := norm_triangle,\n  abv_mul := by simp [has_norm.norm, padic_norm_e.mul'] }\n\ntheorem rat_dense {p : \u2115} {hp : p.prime} (q : \u211a_[p]) {\u03b5 : \u211d} (h\u03b5 : \u03b5 > 0) :\n        \u2203 r : \u211a, \u2225q - r\u2225 < \u03b5 :=\nlet \u27e8\u03b5', h\u03b5'l, h\u03b5'r\u27e9 := exists_rat_btwn h\u03b5,\n    \u27e8r, hr\u27e9 := rat_dense' q (by simpa using h\u03b5'l)  in\n\u27e8r, lt.trans (by simpa [has_norm.norm] using hr) h\u03b5'r\u27e9\n\nend normed_space\nend padic\n\nnamespace padic_norm_e\nsection normed_space\nvariables {p : \u2115} [hp : p.prime]\ninclude hp\n\n@[simp] protected lemma mul (q r : \u211a_[p]) : \u2225q * r\u2225 = \u2225q\u2225 * \u2225r\u2225 :=\nby simp [has_norm.norm, padic_norm_e.mul']\n\nprotected lemma is_norm (q : \u211a_[p]) : \u2191(padic_norm_e q) = \u2225q\u2225 := rfl\n\ntheorem nonarchimedean (q r : \u211a_[p]) : \u2225q + r\u2225 \u2264 max (\u2225q\u2225) (\u2225r\u2225) :=\nbegin\n  unfold has_norm.norm, rw \u2190rat.cast_max, apply rat.cast_le.2, apply nonarchimedean'\nend\n\ntheorem add_eq_max_of_ne {q r : \u211a_[p]} (h : \u2225q\u2225 \u2260 \u2225r\u2225) : \u2225q+r\u2225 = max (\u2225q\u2225) (\u2225r\u2225) :=\nbegin\n  unfold has_norm.norm,\n  rw \u2190rat.cast_max,\n  congr,\n  apply add_eq_max_of_ne',\n  intro h',\n  apply h,\n  unfold has_norm.norm,\n  congr,\n  apply h'\nend\n\n@[simp] lemma eq_padic_norm (q : \u211a) : \u2225padic.of_rat p q\u2225 = padic_norm p q :=\nby unfold has_norm.norm; congr; apply padic_seq.norm_const\n\nprotected theorem image {q : \u211a_[p]} : q \u2260 0 \u2192 \u2203 n : \u2124, \u2225q\u2225 = \u2191((\u2191p : \u211a) ^ (-n)) :=\nquotient.induction_on q $ \u03bb f hf,\n  have \u00ac f \u2248 0, from (padic_seq.ne_zero_iff_nequiv_zero f).1 hf,\n  let \u27e8n, hn\u27e9 := padic_seq.norm_image f this in\n  \u27e8n, congr_arg rat.cast hn\u27e9\n\nprotected lemma is_rat (q : \u211a_[p]) : \u2203 q' : \u211a, \u2225q\u2225 = \u2191q' :=\nif h : q = 0 then \u27e80, by simp [h]\u27e9\nelse let \u27e8n, hn\u27e9 := padic_norm_e.image h in \u27e8_, hn\u27e9\n\ndef rat_norm (q : \u211a_[p]) : \u211a := classical.some (padic_norm_e.is_rat q)\n\nlemma eq_rat_norm (q : \u211a_[p]) : \u2225q\u2225 = rat_norm q := classical.some_spec (padic_norm_e.is_rat q)\n\ntheorem norm_rat_le_one : \u2200 {q : \u211a} (hq : \u00ac p \u2223 q.denom), \u2225(q : \u211a_[p])\u2225 \u2264 1\n| \u27e8n, d, hn, hd\u27e9 := \u03bb hq : \u00ac p \u2223 d,\n  if hnz : n = 0 then\n    have (\u27e8n, d, hn, hd\u27e9 : \u211a) = 0, from rat.zero_of_num_zero hnz,\n      by simp [this, padic.cast_eq_of_rat, zero_le_one]\n  else\n    have hnz' : {rat . num := n, denom := d, pos := hn, cop := hd} \u2260 0,\n      from mt rat.zero_iff_num_zero.1 hnz,\n    have (p : \u211a) ^ (-(multiplicity (p : \u2124) n).get\n      (finite_int_iff.2 \u27e8hp.ne_one, hnz\u27e9) : \u2124) \u2264 1,\n      from fpow_le_one_of_nonpos\n        (show (\u2191p : \u211a) \u2265 \u2191(1: \u2115), from le_of_lt (nat.cast_lt.2 hp.gt_one))\n        (neg_nonpos_of_nonneg (int.coe_nat_nonneg _)),\n    have (((p : \u211a) ^ (-(multiplicity (p : \u2124) n).get\n        (finite_int_iff.2 \u27e8hp.ne_one, hnz\u27e9) : \u2124) : \u211a) : \u211d) \u2264 (1 : \u211a),\n      from rat.cast_le.2 this,\n    by simpa [padic.cast_eq_of_rat, hnz', padic_norm, padic_val_rat_def p hnz',\n               multiplicity_eq_zero_of_not_dvd (mt int.coe_nat_dvd.1 hq)]\n\nlemma eq_of_norm_add_lt_right {p : \u2115} {hp : p.prime} {z1 z2 : \u211a_[p]}\n  (h : \u2225z1 + z2\u2225 < \u2225z2\u2225) : \u2225z1\u2225 = \u2225z2\u2225 :=\nby_contradiction $ \u03bb hne,\n  not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_right) h\n\nlemma eq_of_norm_add_lt_left {p : \u2115} {hp : p.prime} {z1 z2 : \u211a_[p]}\n  (h : \u2225z1 + z2\u2225 < \u2225z1\u2225) : \u2225z1\u2225 = \u2225z2\u2225 :=\nby_contradiction $ \u03bb hne,\n  not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_left) h\n\nend normed_space\nend padic_norm_e\n\nnamespace padic\nvariables {p : \u2115} [nat.prime p]\n\nset_option eqn_compiler.zeta true\ninstance complete : cau_seq.is_complete \u211a_[p] norm :=\n\u27e8\u03bb f,\n  let f' : cau_seq \u211a_[p] padic_norm_e :=\n    \u27e8\u03bb n, f n, \u03bb \u03b5 h\u03b5,\n      let \u27e8N, hN\u27e9 := is_cau f \u2191\u03b5 (rat.cast_pos.2 h\u03b5) in \u27e8N, \u03bb j hj, rat.cast_lt.1 (hN _ hj)\u27e9\u27e9 in\n  let \u27e8q, hq\u27e9 := padic.complete' f' in\n  \u27e8 q, setoid.symm $ \u03bb \u03b5 h\u03b5,\n    let \u27e8\u03b5', h\u03b5'l, h\u03b5'r\u27e9 := exists_rat_btwn h\u03b5,\n        \u27e8N, hN\u27e9 := hq _ (by simpa using h\u03b5'l) in\n    \u27e8N, \u03bb i hi, lt.trans (rat.cast_lt.2 (hN _ hi)) h\u03b5'r \u27e9\u27e9\u27e9\n\nlemma padic_norm_e_lim_le {f : cau_seq \u211a_[p] norm} {a : \u211d} (ha : a > 0)\n      (hf : \u2200 i, \u2225f i\u2225 \u2264 a) : \u2225f.lim\u2225 \u2264 a :=\nlet \u27e8N, hN\u27e9 := setoid.symm (cau_seq.equiv_lim f) _ ha in\ncalc \u2225f.lim\u2225 = \u2225f.lim - f N + f N\u2225 : by simp\n                ... \u2264 max (\u2225f.lim - f N\u2225) (\u2225f N\u2225) : padic_norm_e.nonarchimedean _ _\n                ... \u2264 a : max_le (le_of_lt (hN _ (le_refl _))) (hf _)\n\nend padic\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/data/padics/padic_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7135454318884809}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n\n! This file was ported from Lean 3 source module linear_algebra.charpoly.basic\n! leanprover-community/mathlib commit d3e8e0a0237c10c2627bf52c246b15ff8e7df4c0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.FreeModule.Finite.Basic\nimport Mathbin.LinearAlgebra.Matrix.Charpoly.Coeff\nimport Mathbin.FieldTheory.Minpoly.Field\n\n/-!\n\n# Characteristic polynomial\n\nWe define the characteristic polynomial of `f : M \u2192\u2097[R] M`, where `M` is a finite and\nfree `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f`\nin any basis is in `linear_algebra/charpoly/to_matrix`.\n\n## Main definition\n\n* `linear_map.charpoly f` : the characteristic polynomial of `f : M \u2192\u2097[R] M`.\n\n-/\n\n\nuniverse u v w\n\nvariable {R : Type u} {M : Type v} [CommRing R] [Nontrivial R]\n\nvariable [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] (f : M \u2192\u2097[R] M)\n\nopen Classical Matrix Polynomial\n\nnoncomputable section\n\nopen Module.Free Polynomial Matrix\n\nnamespace LinearMap\n\nsection Basic\n\n/-- The characteristic polynomial of `f : M \u2192\u2097[R] M`. -/\ndef charpoly : R[X] :=\n  (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly\n#align linear_map.charpoly LinearMap.charpoly\n\ntheorem charpoly_def : f.charpoly = (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly :=\n  rfl\n#align linear_map.charpoly_def LinearMap.charpoly_def\n\nend Basic\n\nsection Coeff\n\ntheorem charpoly_monic : f.charpoly.Monic :=\n  charpoly_monic _\n#align linear_map.charpoly_monic LinearMap.charpoly_monic\n\nend Coeff\n\nsection CayleyHamilton\n\n/-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied\nto the linear map itself, is zero.\n\nSee `matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/\ntheorem aeval_self_charpoly : aeval f f.charpoly = 0 :=\n  by\n  apply (LinearEquiv.map_eq_zero_iff (algEquivMatrix (choose_basis R M)).toLinearEquiv).1\n  rw [AlgEquiv.toLinearEquiv_apply, \u2190 AlgEquiv.coe_algHom, \u2190 Polynomial.aeval_algHom_apply _ _ _,\n    charpoly_def]\n  exact aeval_self_charpoly _\n#align linear_map.aeval_self_charpoly LinearMap.aeval_self_charpoly\n\ntheorem isIntegral : IsIntegral R f :=\n  \u27e8f.charpoly, \u27e8charpoly_monic f, aeval_self_charpoly f\u27e9\u27e9\n#align linear_map.is_integral LinearMap.isIntegral\n\ntheorem minpoly_dvd_charpoly {K : Type u} {M : Type v} [Field K] [AddCommGroup M] [Module K M]\n    [FiniteDimensional K M] (f : M \u2192\u2097[K] M) : minpoly K f \u2223 f.charpoly :=\n  minpoly.dvd _ _ (aeval_self_charpoly f)\n#align linear_map.minpoly_dvd_charpoly LinearMap.minpoly_dvd_charpoly\n\n/-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %\u2098 f.charpoly`; that is,\n`p` is equivalent to a polynomial with degree less than the dimension of the module. -/\ntheorem aeval_eq_aeval_mod_charpoly (p : R[X]) : aeval f p = aeval f (p %\u2098 f.charpoly) :=\n  (aeval_modByMonic_eq_self_of_root f.charpoly_monic f.aeval_self_charpoly).symm\n#align linear_map.aeval_eq_aeval_mod_charpoly LinearMap.aeval_eq_aeval_mod_charpoly\n\n/-- Any endomorphism power can be computed as the sum of endomorphism powers less than the\ndimension of the module. -/\ntheorem pow_eq_aeval_mod_charpoly (k : \u2115) : f ^ k = aeval f (X ^ k %\u2098 f.charpoly) := by\n  rw [\u2190 aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]\n#align linear_map.pow_eq_aeval_mod_charpoly LinearMap.pow_eq_aeval_mod_charpoly\n\nvariable {f}\n\ntheorem minpoly_coeff_zero_of_injective (hf : Function.Injective f) : (minpoly R f).coeff 0 \u2260 0 :=\n  by\n  intro h\n  obtain \u27e8P, hP\u27e9 := X_dvd_iff.2 h\n  have hdegP : P.degree < (minpoly R f).degree :=\n    by\n    rw [hP, mul_comm]\n    refine' degree_lt_degree_mul_X fun h => _\n    rw [h, MulZeroClass.mul_zero] at hP\n    exact minpoly.ne_zero (IsIntegral f) hP\n  have hPmonic : P.monic :=\n    by\n    suffices (minpoly R f).Monic by\n      rwa [monic.def, hP, mul_comm, leading_coeff_mul_X, \u2190 monic.def] at this\n    exact minpoly.monic (IsIntegral f)\n  have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _\n  simp only [hP, mul_eq_comp, ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp, AlgHom.map_mul,\n    zero_apply] at hzero\n  exact not_le.2 hdegP (minpoly.min _ _ hPmonic (ext hzero))\n#align linear_map.minpoly_coeff_zero_of_injective LinearMap.minpoly_coeff_zero_of_injective\n\nend CayleyHamilton\n\nend LinearMap\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Charpoly/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073575, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7135454285873277}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp, Yury Kudryashov\n-/\nimport analysis.convex.jensen\nimport analysis.normed.group.pointwise\nimport analysis.normed_space.finite_dimension\nimport analysis.normed_space.ray\nimport topology.path_connected\nimport topology.algebra.affine\n\n/-!\n# Topological and metric properties of convex sets\n\nWe prove the following facts:\n\n* `convex.interior` : interior of a convex set is convex;\n* `convex.closure` : closure of a convex set is convex;\n* `set.finite.compact_convex_hull` : convex hull of a finite set is compact;\n* `set.finite.is_closed_convex_hull` : convex hull of a finite set is closed;\n* `convex_on_norm`, `convex_on_dist` : norm and distance to a fixed point is convex on any convex\n  set;\n* `convex_on_univ_norm`, `convex_on_univ_dist` : norm and distance to a fixed point is convex on\n  the whole space;\n* `convex_hull_ediam`, `convex_hull_diam` : convex hull of a set has the same (e)metric diameter\n  as the original set;\n* `bounded_convex_hull` : convex hull of a set is bounded if and only if the original set\n  is bounded.\n* `bounded_std_simplex`, `is_closed_std_simplex`, `compact_std_simplex`: topological properties\n  of the standard simplex;\n-/\n\nvariables {\u03b9 : Type*} {E : Type*}\n\nopen metric set\nopen_locale pointwise convex\n\nlemma real.convex_iff_is_preconnected {s : set \u211d} : convex \u211d s \u2194 is_preconnected s :=\nconvex_iff_ord_connected.trans is_preconnected_iff_ord_connected.symm\n\nalias real.convex_iff_is_preconnected \u2194 convex.is_preconnected is_preconnected.convex\n\n/-! ### Standard simplex -/\n\nsection std_simplex\n\nvariables [fintype \u03b9]\n\n/-- Every vector in `std_simplex \ud835\udd5c \u03b9` has `max`-norm at most `1`. -/\nlemma std_simplex_subset_closed_ball :\n  std_simplex \u211d \u03b9 \u2286 metric.closed_ball 0 1 :=\nbegin\n  assume f hf,\n  rw [metric.mem_closed_ball, dist_zero_right],\n  refine (nnreal.coe_one \u25b8 nnreal.coe_le_coe.2 $ finset.sup_le $ \u03bb x hx, _),\n  change |f x| \u2264 1,\n  rw [abs_of_nonneg $ hf.1 x],\n  exact (mem_Icc_of_mem_std_simplex hf x).2\nend\n\nvariable (\u03b9)\n\n/-- `std_simplex \u211d \u03b9` is bounded. -/\nlemma bounded_std_simplex : metric.bounded (std_simplex \u211d \u03b9) :=\n(metric.bounded_iff_subset_ball 0).2 \u27e81, std_simplex_subset_closed_ball\u27e9\n\n/-- `std_simplex \u211d \u03b9` is closed. -/\nlemma is_closed_std_simplex : is_closed (std_simplex \u211d \u03b9) :=\n(std_simplex_eq_inter \u211d \u03b9).symm \u25b8 is_closed.inter\n  (is_closed_Inter $ \u03bb i, is_closed_le continuous_const (continuous_apply i))\n  (is_closed_eq (continuous_finset_sum _ $ \u03bb x _, continuous_apply x) continuous_const)\n\n/-- `std_simplex \u211d \u03b9` is compact. -/\nlemma compact_std_simplex : is_compact (std_simplex \u211d \u03b9) :=\nmetric.compact_iff_closed_bounded.2 \u27e8is_closed_std_simplex \u03b9, bounded_std_simplex \u03b9\u27e9\n\nend std_simplex\n\n/-! ### Topological vector space -/\n\nsection has_continuous_const_smul\n\nvariables {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c] [add_comm_group E] [module \ud835\udd5c E] [topological_space E]\n  [topological_add_group E] [has_continuous_const_smul \ud835\udd5c E]\n\n/-- If `s` is a convex set, then `a \u2022 interior s + b \u2022 closure s \u2286 interior s` for all `0 < a`,\n`0 \u2264 b`, `a + b = 1`. See also `convex.combo_interior_self_subset_interior` for a weaker version. -/\nlemma convex.combo_interior_closure_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {a b : \ud835\udd5c}\n  (ha : 0 < a) (hb : 0 \u2264 b) (hab : a + b = 1) :\n  a \u2022 interior s + b \u2022 closure s \u2286 interior s :=\ninterior_smul\u2080 ha.ne' s \u25b8\n  calc interior (a \u2022 s) + b \u2022 closure s \u2286 interior (a \u2022 s) + closure (b \u2022 s) :\n    add_subset_add subset.rfl (smul_closure_subset b s)\n  ... = interior (a \u2022 s) + b \u2022 s : by rw is_open_interior.add_closure (b \u2022 s)\n  ... \u2286 interior (a \u2022 s + b \u2022 s) : subset_interior_add_left\n  ... \u2286 interior s : interior_mono $ hs.set_combo_subset ha.le hb hab\n\n/-- If `s` is a convex set, then `a \u2022 interior s + b \u2022 s \u2286 interior s` for all `0 < a`, `0 \u2264 b`,\n`a + b = 1`. See also `convex.combo_interior_closure_subset_interior` for a stronger version. -/\nlemma convex.combo_interior_self_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {a b : \ud835\udd5c}\n  (ha : 0 < a) (hb : 0 \u2264 b) (hab : a + b = 1) :\n  a \u2022 interior s + b \u2022 s \u2286 interior s :=\ncalc a \u2022 interior s + b \u2022 s \u2286 a \u2022 interior s + b \u2022 closure s :\n  add_subset_add subset.rfl $ image_subset _ subset_closure\n... \u2286 interior s : hs.combo_interior_closure_subset_interior ha hb hab\n\n/-- If `s` is a convex set, then `a \u2022 closure s + b \u2022 interior s \u2286 interior s` for all `0 \u2264 a`,\n`0 < b`, `a + b = 1`. See also `convex.combo_self_interior_subset_interior` for a weaker version. -/\nlemma convex.combo_closure_interior_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {a b : \ud835\udd5c}\n  (ha : 0 \u2264 a) (hb : 0 < b) (hab : a + b = 1) :\n  a \u2022 closure s + b \u2022 interior s \u2286 interior s :=\nby { rw add_comm, exact hs.combo_interior_closure_subset_interior hb ha (add_comm a b \u25b8 hab) }\n\n/-- If `s` is a convex set, then `a \u2022 s + b \u2022 interior s \u2286 interior s` for all `0 \u2264 a`, `0 < b`,\n`a + b = 1`. See also `convex.combo_closure_interior_subset_interior` for a stronger version. -/\nlemma convex.combo_self_interior_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {a b : \ud835\udd5c}\n  (ha : 0 \u2264 a) (hb : 0 < b) (hab : a + b = 1) :\n  a \u2022 s + b \u2022 interior s \u2286 interior s :=\nby { rw add_comm, exact hs.combo_interior_self_subset_interior hb ha (add_comm a b \u25b8 hab) }\n\nlemma convex.combo_interior_closure_mem_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 interior s) (hy : y \u2208 closure s) {a b : \ud835\udd5c} (ha : 0 < a) (hb : 0 \u2264 b) (hab : a + b = 1) :\n  a \u2022 x + b \u2022 y \u2208 interior s :=\nhs.combo_interior_closure_subset_interior ha hb hab $\n  add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy)\n\nlemma convex.combo_interior_self_mem_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 interior s) (hy : y \u2208 s) {a b : \ud835\udd5c} (ha : 0 < a) (hb : 0 \u2264 b) (hab : a + b = 1) :\n  a \u2022 x + b \u2022 y \u2208 interior s :=\nhs.combo_interior_closure_mem_interior hx (subset_closure hy) ha hb hab\n\nlemma convex.combo_closure_interior_mem_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 closure s) (hy : y \u2208 interior s) {a b : \ud835\udd5c} (ha : 0 \u2264 a) (hb : 0 < b) (hab : a + b = 1) :\n  a \u2022 x + b \u2022 y \u2208 interior s :=\nhs.combo_closure_interior_subset_interior ha hb hab $\n  add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy)\n\nlemma convex.combo_self_interior_mem_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 s) (hy : y \u2208 interior s) {a b : \ud835\udd5c} (ha : 0 \u2264 a) (hb : 0 < b) (hab : a + b = 1) :\n  a \u2022 x + b \u2022 y \u2208 interior s :=\nhs.combo_closure_interior_mem_interior (subset_closure hx) hy ha hb hab\n\nlemma convex.open_segment_interior_closure_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 interior s) (hy : y \u2208 closure s) : open_segment \ud835\udd5c x y \u2286 interior s :=\nbegin\n  rintro _ \u27e8a, b, ha, hb, hab, rfl\u27e9,\n  exact hs.combo_interior_closure_mem_interior hx hy ha hb.le hab\nend\n\nlemma convex.open_segment_interior_self_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 interior s) (hy : y \u2208 s) : open_segment \ud835\udd5c x y \u2286 interior s :=\nhs.open_segment_interior_closure_subset_interior hx (subset_closure hy)\n\nlemma convex.open_segment_closure_interior_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 closure s) (hy : y \u2208 interior s) : open_segment \ud835\udd5c x y \u2286 interior s :=\nbegin\n  rintro _ \u27e8a, b, ha, hb, hab, rfl\u27e9,\n  exact hs.combo_closure_interior_mem_interior hx hy ha.le hb hab\nend\n\nlemma convex.open_segment_self_interior_subset_interior {s : set E} (hs : convex \ud835\udd5c s) {x y : E}\n  (hx : x \u2208 s) (hy : y \u2208 interior s) : open_segment \ud835\udd5c x y \u2286 interior s :=\nhs.open_segment_closure_interior_subset_interior (subset_closure hx) hy\n\n/-- If `x \u2208 closure s` and `y \u2208 interior s`, then the segment `(x, y]` is included in `interior s`.\n-/\nlemma convex.add_smul_sub_mem_interior' {s : set E} (hs : convex \ud835\udd5c s)\n  {x y : E} (hx : x \u2208 closure s) (hy : y \u2208 interior s) {t : \ud835\udd5c} (ht : t \u2208 Ioc (0 : \ud835\udd5c) 1) :\n  x + t \u2022 (y - x) \u2208 interior s :=\nby simpa only [sub_smul, smul_sub, one_smul, add_sub, add_comm]\n  using hs.combo_interior_closure_mem_interior hy hx ht.1 (sub_nonneg.mpr ht.2)\n    (add_sub_cancel'_right _ _)\n\n/-- If `x \u2208 s` and `y \u2208 interior s`, then the segment `(x, y]` is included in `interior s`. -/\nlemma convex.add_smul_sub_mem_interior {s : set E} (hs : convex \ud835\udd5c s)\n  {x y : E} (hx : x \u2208 s) (hy : y \u2208 interior s) {t : \ud835\udd5c} (ht : t \u2208 Ioc (0 : \ud835\udd5c) 1) :\n  x + t \u2022 (y - x) \u2208 interior s :=\nhs.add_smul_sub_mem_interior' (subset_closure hx) hy ht\n\n/-- If `x \u2208 closure s` and `x + y \u2208 interior s`, then `x + t y \u2208 interior s` for `t \u2208 (0, 1]`. -/\nlemma convex.add_smul_mem_interior' {s : set E} (hs : convex \ud835\udd5c s)\n  {x y : E} (hx : x \u2208 closure s) (hy : x + y \u2208 interior s) {t : \ud835\udd5c} (ht : t \u2208 Ioc (0 : \ud835\udd5c) 1) :\n  x + t \u2022 y \u2208 interior s :=\nby simpa only [add_sub_cancel'] using hs.add_smul_sub_mem_interior' hx hy ht\n\n/-- If `x \u2208 s` and `x + y \u2208 interior s`, then `x + t y \u2208 interior s` for `t \u2208 (0, 1]`. -/\nlemma convex.add_smul_mem_interior {s : set E} (hs : convex \ud835\udd5c s)\n  {x y : E} (hx : x \u2208 s) (hy : x + y \u2208 interior s) {t : \ud835\udd5c} (ht : t \u2208 Ioc (0 : \ud835\udd5c) 1) :\n  x + t \u2022 y \u2208 interior s :=\nhs.add_smul_mem_interior' (subset_closure hx) hy ht\n\n/-- In a topological vector space, the interior of a convex set is convex. -/\nprotected lemma convex.interior {s : set E} (hs : convex \ud835\udd5c s) : convex \ud835\udd5c (interior s) :=\nconvex_iff_open_segment_subset.mpr $ \u03bb x y hx hy,\n  hs.open_segment_closure_interior_subset_interior (interior_subset_closure hx) hy\n\n/-- In a topological vector space, the closure of a convex set is convex. -/\nprotected lemma convex.closure {s : set E} (hs : convex \ud835\udd5c s) : convex \ud835\udd5c (closure s) :=\n\u03bb x y hx hy a b ha hb hab,\nlet f : E \u2192 E \u2192 E := \u03bb x' y', a \u2022 x' + b \u2022 y' in\nhave hf : continuous (\u03bb p : E \u00d7 E, f p.1 p.2), from\n  (continuous_fst.const_smul _).add (continuous_snd.const_smul _),\nshow f x y \u2208 closure s, from\n  mem_closure_of_continuous2 hf hx hy (\u03bb x' hx' y' hy', subset_closure\n  (hs hx' hy' ha hb hab))\n\nend has_continuous_const_smul\n\nsection has_continuous_smul\n\nvariables [add_comm_group E] [module \u211d E] [topological_space E]\n  [topological_add_group E] [has_continuous_smul \u211d E]\n\n/-- Convex hull of a finite set is compact. -/\nlemma set.finite.compact_convex_hull {s : set E} (hs : s.finite) :\n  is_compact (convex_hull \u211d s) :=\nbegin\n  rw [hs.convex_hull_eq_image],\n  apply (compact_std_simplex _).image,\n  haveI := hs.fintype,\n  apply linear_map.continuous_on_pi\nend\n\n/-- Convex hull of a finite set is closed. -/\nlemma set.finite.is_closed_convex_hull [t2_space E] {s : set E} (hs : s.finite) :\n  is_closed (convex_hull \u211d s) :=\nhs.compact_convex_hull.is_closed\n\nopen affine_map\n\n/-- If we dilate the interior of a convex set about a point in its interior by a scale `t > 1`,\nthe result includes the closure of the original set.\n\nTODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/\nlemma convex.closure_subset_image_homothety_interior_of_one_lt {s : set E} (hs : convex \u211d s)\n  {x : E} (hx : x \u2208 interior s) (t : \u211d) (ht : 1 < t) :\n  closure s \u2286 homothety x t '' interior s :=\nbegin\n  intros y hy,\n  have hne : t \u2260 0, from (one_pos.trans ht).ne',\n  refine \u27e8homothety x t\u207b\u00b9 y, hs.open_segment_interior_closure_subset_interior hx hy _,\n    (affine_equiv.homothety_units_mul_hom x (units.mk0 t hne)).apply_symm_apply y\u27e9,\n  rw [open_segment_eq_image_line_map, \u2190 inv_one, \u2190 inv_Ioi (@one_pos \u211d _ _), \u2190 image_inv,\n    image_image, homothety_eq_line_map],\n  exact mem_image_of_mem _ ht\nend\n\n/-- If we dilate a convex set about a point in its interior by a scale `t > 1`, the interior of\nthe result includes the closure of the original set.\n\nTODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/\nlemma convex.closure_subset_interior_image_homothety_of_one_lt {s : set E} (hs : convex \u211d s)\n  {x : E} (hx : x \u2208 interior s) (t : \u211d) (ht : 1 < t) :\n  closure s \u2286 interior (homothety x t '' s) :=\n(hs.closure_subset_image_homothety_interior_of_one_lt hx t ht).trans $\n  (homothety_is_open_map x t (one_pos.trans ht).ne').image_interior_subset _\n\n/-- If we dilate a convex set about a point in its interior by a scale `t > 1`, the interior of\nthe result includes the closure of the original set.\n\nTODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/\nlemma convex.subset_interior_image_homothety_of_one_lt {s : set E} (hs : convex \u211d s)\n  {x : E} (hx : x \u2208 interior s) (t : \u211d) (ht : 1 < t) :\n  s \u2286 interior (homothety x t '' s) :=\nsubset_closure.trans $ hs.closure_subset_interior_image_homothety_of_one_lt hx t ht\n\nprotected lemma convex.is_path_connected {s : set E} (hconv : convex \u211d s) (hne : s.nonempty) :\n  is_path_connected s :=\nbegin\n  refine is_path_connected_iff.mpr \u27e8hne, _\u27e9,\n  intros x x_in y y_in,\n  have H := hconv.segment_subset x_in y_in,\n  rw segment_eq_image_line_map at H,\n  exact joined_in.of_line affine_map.line_map_continuous.continuous_on (line_map_apply_zero _ _)\n    (line_map_apply_one _ _) H\nend\n\n/--\nEvery topological vector space over \u211d is path connected.\n\nNot an instance, because it creates enormous TC subproblems (turn on `pp.all`).\n-/\nprotected lemma topological_add_group.path_connected : path_connected_space E :=\npath_connected_space_iff_univ.mpr $ convex_univ.is_path_connected \u27e8(0 : E), trivial\u27e9\n\nend has_continuous_smul\n\n/-! ### Normed vector space -/\n\nsection normed_space\nvariables [semi_normed_group E] [normed_space \u211d E] {s t : set E}\n\n/-- The norm on a real normed space is convex on any convex set. See also `seminorm.convex_on`\nand `convex_on_univ_norm`. -/\nlemma convex_on_norm (hs : convex \u211d s) : convex_on \u211d s norm :=\n\u27e8hs, \u03bb x y hx hy a b ha hb hab,\n  calc \u2225a \u2022 x + b \u2022 y\u2225 \u2264 \u2225a \u2022 x\u2225 + \u2225b \u2022 y\u2225 : norm_add_le _ _\n    ... = a * \u2225x\u2225 + b * \u2225y\u2225\n        : by rw [norm_smul, norm_smul, real.norm_of_nonneg ha, real.norm_of_nonneg hb]\u27e9\n\n/-- The norm on a real normed space is convex on the whole space. See also `seminorm.convex_on`\nand `convex_on_norm`. -/\nlemma convex_on_univ_norm : convex_on \u211d univ (norm : E \u2192 \u211d) := convex_on_norm convex_univ\n\nlemma convex_on_dist (z : E) (hs : convex \u211d s) : convex_on \u211d s (\u03bb z', dist z' z) :=\nby simpa [dist_eq_norm, preimage_preimage]\n  using (convex_on_norm (hs.translate (-z))).comp_affine_map\n    (affine_map.id \u211d E - affine_map.const \u211d E z)\n\nlemma convex_on_univ_dist (z : E) : convex_on \u211d univ (\u03bbz', dist z' z) :=\nconvex_on_dist z convex_univ\n\nlemma convex_ball (a : E) (r : \u211d) : convex \u211d (metric.ball a r) :=\nby simpa only [metric.ball, sep_univ] using (convex_on_univ_dist a).convex_lt r\n\nlemma convex_closed_ball (a : E) (r : \u211d) : convex \u211d (metric.closed_ball a r) :=\nby simpa only [metric.closed_ball, sep_univ] using (convex_on_univ_dist a).convex_le r\n\nlemma convex.thickening (hs : convex \u211d s) (\u03b4 : \u211d) : convex \u211d (thickening \u03b4 s) :=\nby { rw \u2190add_ball_zero, exact hs.add (convex_ball 0 _) }\n\nlemma convex.cthickening (hs : convex \u211d s) (\u03b4 : \u211d) : convex \u211d (cthickening \u03b4 s) :=\nbegin\n  obtain h\u03b4 | h\u03b4 := le_total 0 \u03b4,\n  { rw cthickening_eq_Inter_thickening h\u03b4,\n    exact convex_Inter\u2082 (\u03bb _ _, hs.thickening _) },\n  { rw cthickening_of_nonpos h\u03b4,\n    exact hs.closure }\nend\n\n/-- If `s`, `t` are disjoint convex sets, `s` is compact and `t` is closed then we can find open\ndisjoint convex sets containing them. -/\nlemma disjoint.exists_open_convexes (disj : disjoint s t) (hs\u2081 : convex \u211d s) (hs\u2082 : is_compact s)\n  (ht\u2081 : convex \u211d t) (ht\u2082 : is_closed t) :\n  \u2203 u v, is_open u \u2227 is_open v \u2227 convex \u211d u \u2227 convex \u211d v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 disjoint u v :=\nlet \u27e8\u03b4, h\u03b4, hst\u27e9 := disj.exists_thickenings hs\u2082 ht\u2082 in\n  \u27e8_, _, is_open_thickening, is_open_thickening, hs\u2081.thickening _, ht\u2081.thickening _,\n    self_subset_thickening h\u03b4 _, self_subset_thickening h\u03b4 _, hst\u27e9\n\n/-- Given a point `x` in the convex hull of `s` and a point `y`, there exists a point\nof `s` at distance at least `dist x y` from `y`. -/\nlemma convex_hull_exists_dist_ge {s : set E} {x : E} (hx : x \u2208 convex_hull \u211d s) (y : E) :\n  \u2203 x' \u2208 s, dist x y \u2264 dist x' y :=\n(convex_on_dist y (convex_convex_hull \u211d _)).exists_ge_of_mem_convex_hull hx\n\n/-- Given a point `x` in the convex hull of `s` and a point `y` in the convex hull of `t`,\nthere exist points `x' \u2208 s` and `y' \u2208 t` at distance at least `dist x y`. -/\nlemma convex_hull_exists_dist_ge2 {s t : set E} {x y : E}\n  (hx : x \u2208 convex_hull \u211d s) (hy : y \u2208 convex_hull \u211d t) :\n  \u2203 (x' \u2208 s) (y' \u2208 t), dist x y \u2264 dist x' y' :=\nbegin\n  rcases convex_hull_exists_dist_ge hx y with \u27e8x', hx', Hx'\u27e9,\n  rcases convex_hull_exists_dist_ge hy x' with \u27e8y', hy', Hy'\u27e9,\n  use [x', hx', y', hy'],\n  exact le_trans Hx' (dist_comm y x' \u25b8 dist_comm y' x' \u25b8 Hy')\nend\n\n/-- Emetric diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/\n@[simp] lemma convex_hull_ediam (s : set E) :\n  emetric.diam (convex_hull \u211d s) = emetric.diam s :=\nbegin\n  refine (emetric.diam_le $ \u03bb x hx y hy, _).antisymm (emetric.diam_mono $ subset_convex_hull \u211d s),\n  rcases convex_hull_exists_dist_ge2 hx hy with \u27e8x', hx', y', hy', H\u27e9,\n  rw edist_dist,\n  apply le_trans (ennreal.of_real_le_of_real H),\n  rw \u2190 edist_dist,\n  exact emetric.edist_le_diam_of_mem hx' hy'\nend\n\n/-- Diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/\n@[simp] lemma convex_hull_diam (s : set E) :\n  metric.diam (convex_hull \u211d s) = metric.diam s :=\nby simp only [metric.diam, convex_hull_ediam]\n\n/-- Convex hull of `s` is bounded if and only if `s` is bounded. -/\n@[simp] lemma bounded_convex_hull {s : set E} :\n  metric.bounded (convex_hull \u211d s) \u2194 metric.bounded s :=\nby simp only [metric.bounded_iff_ediam_ne_top, convex_hull_ediam]\n\n@[priority 100]\ninstance normed_space.path_connected : path_connected_space E :=\ntopological_add_group.path_connected\n\n@[priority 100]\ninstance normed_space.loc_path_connected : loc_path_connected_space E :=\nloc_path_connected_of_bases (\u03bb x, metric.nhds_basis_ball)\n  (\u03bb x r r_pos, (convex_ball x r).is_path_connected $ by simp [r_pos])\n\nlemma dist_add_dist_of_mem_segment {x y z : E} (h : y \u2208 [x -[\u211d] z]) :\n  dist x y + dist y z = dist x z :=\nbegin\n  simp only [dist_eq_norm, mem_segment_iff_same_ray] at *,\n  simpa only [sub_add_sub_cancel', norm_sub_rev] using h.norm_add.symm\nend\n\nend normed_space\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/convex/topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070839, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7134300406098067}}
{"text": "-- Exercise 1\n--\n-- Prove the following identities, replacing the \u201csorry\u201d placeholders with\n-- actual proofs.\nsection\n  variables p q r : Prop\n\n  -- commutativity of \u2227 and \u2228\n  example : p \u2227 q \u2194 q \u2227 p :=\n    iff.intro\n      (assume hp : p \u2227 q,\n        show q \u2227 p, from and.intro (and.right hp) (and.left hp))\n      (assume hq : q \u2227 p,\n        show p \u2227 q, from and.intro (and.right hq) (and.left hq))\n\n  example : p \u2228 q \u2194 q \u2228 p :=\n    iff.intro\n      (assume hp : p \u2228 q,\n        show q \u2228 p, from or.elim hp (or.intro_right q) (or.intro_left p))\n      (assume hq : q \u2228 p,\n        show p \u2228 q, from or.elim hq (or.intro_right p) (or.intro_left q))\n\n  -- associativity of \u2227 and \u2228\n  example : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n    iff.intro\n      (assume h : (p \u2227 q) \u2227 r,\n        show p \u2227 (q \u2227 r), from\n          and.intro\n            (and.left (and.left h))\n            (and.intro\n              (and.right (and.left h))\n              (and.right h)))\n      (assume h : p \u2227 (q \u2227 r),\n        show (p \u2227 q) \u2227 r, from\n          and.intro\n            (and.intro\n              (and.left h)\n              (and.left (and.right h)))\n            (and.right (and.right h)))\n\n  example : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n  begin\n    split,\n\n    -- (p \u2228 q) \u2228 r \u2192 p \u2228 (q \u2228 r)\n    {\n      assume h,\n\n      have f : (p \u2228 q) \u2192 p \u2228 q \u2228 r,\n      assume pq : (p \u2228 q),\n      exact\n        or.elim\n        pq\n        (\u03bb hp : p, or.intro_left (q \u2228 r) hp)\n        (\u03bb hq : q, or.intro_right p (or.intro_left r hq)),\n\n      have g : r \u2192 p \u2228 q \u2228 r,\n      assume hr : r,\n      exact or.intro_right p (or.intro_right q hr),\n\n      exact or.elim h f g,\n    },\n\n    -- p \u2228 (q \u2228 r) \u2192 (p \u2228 q) \u2228 r\n    {\n      assume h,\n\n      have f : p \u2192 (p \u2228 q) \u2228 r,\n      assume hp,\n      exact or.intro_left r (or.intro_left q hp),\n\n      have g : (q \u2228 r) \u2192 (p \u2228 q) \u2228 r,\n      assume qr,\n      exact\n        or.elim\n        qr\n        (\u03bb hq : q, or.intro_left r (or.intro_right p hq))\n        (\u03bb hr : r, or.intro_right (p \u2228 q) hr),\n\n      exact or.elim h f g,\n    },\n  end\n\n  -- distributivity\n  example : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    split,\n\n    {\n      assume h,\n      \n      have f : q \u2192 (p \u2227 q) \u2228 (p \u2227 r),\n      assume hq : q,\n      exact or.intro_left (p \u2227 r) (and.intro (and.left h) hq),\n\n      have g : r \u2192 (p \u2227 q) \u2228 (p \u2227 r),\n      assume hr,\n      exact or.intro_right (p \u2227 q) (and.intro (and.left h) hr),\n\n      exact or.elim (and.right h) f g,\n    },\n\n    {\n      assume h,\n\n      have f : p \u2227 q \u2192 p \u2227 (q \u2228 r),\n      assume pq : p \u2227 q,\n      exact and.intro (and.left pq) (or.intro_left r (and.right pq)),\n\n      have g : p \u2227 r \u2192 p \u2227 (q \u2228 r),\n      assume pr : p \u2227 r,\n      exact and.intro (and.left pr) (or.intro_right q (and.right pr)),\n\n      exact or.elim h f g,\n    },\n  end\n\n  section\n    variable hp : p\n\n    #check and.intro (or.intro_left q hp)\n  end\n  \n  example : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n  begin\n    split,\n\n    -- p \u2228 (q \u2227 r) \u2192 (p \u2228 q) \u2227 (p \u2228 r)\n    {\n      assume h,\n\n      have f : p \u2192 (p \u2228 q) \u2227 (p \u2228 r),\n      assume hp : p,\n      exact\n        and.intro\n          (or.intro_left q hp)\n          (or.intro_left r hp),\n\n      have g : q \u2227 r \u2192 (p \u2228 q) \u2227 (p \u2228 r),\n      assume qr,\n      exact\n        and.intro\n          (or.intro_right p (and.left qr))\n          (or.intro_right p (and.right qr)),\n\n      exact or.elim h f g,\n    },\n\n    -- (p \u2228 q) \u2227 (p \u2228 r) \u2192 p \u2228 (q \u2227 r)\n    {\n      assume h,\n      have hpq : p \u2228 q, from and.left h,\n      have hpr : p \u2228 r, from and.right h,\n\n      have f : p \u2192 p \u2228 (q \u2227 r),\n      assume hp,\n      exact or.intro_left (q \u2227 r) hp,\n\n      have g : q \u2192 p \u2228 (q \u2227 r),\n      assume hq,\n      exact or.elim hpr f (\u03bb hr : r, or.intro_right p (and.intro hq hr)),\n\n      exact or.elim hpq f g,\n    },\n  end\n\n  -- other properties\n  --\n  -- NOTE: Leaving these blank because I think I've got the hang of these kinds\n  --       of derivations.\n  example : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := sorry\n  example : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := sorry\n  example : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := sorry\n  example : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := sorry\n  example : \u00ac(p \u2227 \u00acp) := sorry\n  example : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := sorry\n  example : \u00acp \u2192 (p \u2192 q) := sorry\n  example : (\u00acp \u2228 q) \u2192 (p \u2192 q) := sorry\n  example : p \u2228 false \u2194 p := sorry\n  example : p \u2227 false \u2194 false := sorry\n  example : \u00ac(p \u2194 \u00acp) := sorry\n  example : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := sorry\nend\n\n-- Exercise 2\n--\n-- Prove the following identities, replacing the \u201csorry\u201d placeholders with\n-- actual proofs. These require classical reasoning.\nsection\n  open classical\n\n  section\n    #check by_cases\n    #check not.intro\n  end\n\n  variables p q r s : Prop\n\n  section\n    variable f : p \u2192 q\n    variable hnp : \u00acp\n\n    #check f hnp\n  end\n\n  example : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n  begin\n    assume h,\n    \n    have hi_pos : p \u2192 (p \u2192 r) \u2228 (p \u2192 s),\n    {\n      assume hp,\n      have hrs : r \u2228 s, from h hp,\n\n      exact\n        or.elim\n          hrs\n          (\u03bb hr : r, or.intro_left (p \u2192 s) (\u03bb hp' : p, hr))\n          (\u03bb hs : s, or.intro_right (p \u2192 r) (\u03bb hp' : p, hs)),\n    },\n\n    have hi_neg : \u00acp \u2192 (p \u2192 r) \u2228 (p \u2192 s),\n    {\n      assume hnp,\n      \n      suffices hpr : p \u2192 r,\n      exact or.intro_left (p \u2192 s) hpr,\n\n      assume hp,\n      exact absurd hp hnp,\n    }\n\n    by_cases hi_pos hi_neg,\n  end\n  \n  example : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n  begin\n    assume h,\n\n    have f : p \u2192 \u00acp \u2228 \u00acq,\n    {\n      assume hp,\n\n      have hq : \u00acq,\n      {\n        assume hq' : q,\n        exact h (and.intro hp hq'),\n      },\n\n      exact or.intro_right (\u00acp) hq,\n    },\n\n    have g : \u00acp \u2192 \u00acp \u2228 \u00acq,\n    assume hp,\n    exact or.intro_left (\u00acq) hp,\n\n    exact by_cases f g,\n  end\n  \n  example : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n  begin\n    assume h,\n\n    have pos : q \u2192 p \u2227 \u00acq,\n    {\n      assume hq,\n      exact false.elim (h (\u03bb hp : p, hq)),\n    },\n\n    have neg : \u00acq \u2192 p \u2227 \u00acq,\n    {\n      assume hnq,\n      exact\n        by_cases\n          (\u03bb hp : p, and.intro hp hnq)\n          (\u03bb hnp : \u00acp,\n            suffices hneg : p \u2192 q, from false.elim (h hneg),\n            assume hp,\n            absurd hp hnp),\n    },\n\n    exact by_cases pos neg,\n  end\n\n  example : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n  begin\n    assume h,\n\n    have f : p \u2192 \u00acp \u2228 q,\n    assume hp,\n    exact or.inr (h hp),\n\n    have g : \u00acp \u2192 \u00acp \u2228 q,\n    assume hnp,\n    exact or.inl hnp,\n\n    exact or.elim (em p) f g,\n  end\n\n  -- NOTE: Here I'm using `absurd` when we have \u00acq, because we find a\n  --       contradiction. Logically it's like saying that logical branch cannot\n  --       exist?\n  example : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n  begin\n    assume h,\n    assume hp,\n\n    exact by_cases\n      (\u03bb hq : q, hq)\n      (\u03bb hnq : \u00acq, absurd hp (h hnq)),\n  end\n  \n  example : p \u2228 \u00acp :=\n  begin\n    exact em p,\n  end\n\n  example : (((p \u2192 q) \u2192 p) \u2192 p) :=\n  begin\n    assume h,\n\n    have pos : p \u2192 p, from id,\n    \n    have neg : \u00acp \u2192 p,\n    {\n      assume hnp,\n\n      have qpos : q \u2192 p,\n      assume hq,\n      exact h (\u03bb hp : p, hq),\n\n      have qneg : \u00acq \u2192 p,\n      assume hnq,\n\n      suffices hneg : p \u2192 q, from h hneg,\n      assume hp,\n      exact absurd hp hnp,\n\n      exact by_cases qpos qneg,\n    },\n\n    exact by_cases pos neg,\n  end\nend\n\n-- Exercise 3\n--\n-- Prove \u00ac(p \u2194 \u00acp) without using classical logic.\nsection\n  variables p : Prop\n\n  example : \u00ac(p \u2194 \u00acp) :=\n  begin\n    assume hneg,\n\n    exact\n      classical.by_cases\n        (\u03bb hp : p, absurd hp (hneg.mp hp))\n        (\u03bb hnp : \u00acp, absurd (hneg.mpr hnp) hnp),\n  end\n\n  example : \u00ac(p \u2194 \u00acp) :=\n  begin\n    assume hneg : (p \u2194 \u00acp),\n\n    have hnp : \u00acp,\n    show p \u2192 false,\n    assume hp : p,\n    exact (hneg.mp hp) hp,\n\n    exact absurd (hneg.mpr hnp) hnp,\n  end\nend\n", "meta": {"author": "crockeo", "repo": "math-exercises", "sha": "cf9150ef9e025f1b7929ba070a783e7a71f24f31", "save_path": "github-repos/lean/crockeo-math-exercises", "path": "github-repos/lean/crockeo-math-exercises/math-exercises-cf9150ef9e025f1b7929ba070a783e7a71f24f31/tpil/chapter3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985636, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7134300343976296}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level6 -- add_right_comm\nimport AdvancedAdditionWorld.Level1 --  succ_inj\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 12: `le_of_succ_le_succ`\n\n## Lemma : le_of_succ_le_succ\nFor all naturals `a` and `b`, `succ a \u2264 succ b \u27f9 a \u2264 b.`\n-/\ntheorem le_of_succ_le_succ (a b : MyNat) : succ a \u2264 succ b \u2192 a \u2264 b := by\n  intro h\n  cases h with\n  | _ c hc =>\n    use c\n    apply succ_inj\n    rw [hc]\n    exact succ_add a c\n\n/-!\nNext up [Level 13](./Level13.lean.md)\n-/\n", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/InequalityWorld/Level12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.7634837689358858, "lm_q1q2_score": 0.7133955431618377}}
{"text": "import data.real.basic\nopen function\n\n/-\n# Chapter 6 : Functions\n\n## Level 6\n\nA classical result in composition of functions.\nNow going the other way around.\n-/\n\n/- Lemma\nIf composition of $f$ and $g$ is surjective, then $g$ is injective.\n-/\ntheorem composition_surjective \n    (X Y Z : set \u211d) (f : X \u2192 Y) (g : Y \u2192 Z) : surjective (g \u2218 f) \u2192 surjective g :=\nbegin\n    intros sgf z,\n    have hx := sgf z,\n    cases hx with x gfxz,\n    use f x,\n    exact gfxz, done\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/functions/composition_surjective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951588871156, "lm_q2_score": 0.7634837743174789, "lm_q1q2_score": 0.7133955426111154}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\n/--\nA group of $N$ students, where $N < 50$, is on a field trip.\nIf their teacher puts them in groups of 8, the last group has 5 students.\nIf their teacher instead puts them in groups of 6, the last group has 3 students.\nWhat is the sum of all possible values of $N$?\nAnswer: $66$.\n--/\ntheorem mathd_numbertheory_149 :\n  \u2211 k in (finset.filter (\u03bb x, x % 8 = 5 \u2227 x % 6 = 3) (finset.range 50)), k = 66 :=\nbegin\n  congr',\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/numbertheory/p149.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7133906755886039}}
{"text": "import data.rat\n\nopen function\n\nnamespace mth1001\n\nsection composite\n\ndef q\u2081 (x : \u2115) : \u2124 := x + 3\ndef q\u2082 (x : \u2124) : \u211a := 2 * x\n\n/-\nWhen a function `f` takes values from a type (or set) `\u03b1` and returns values in a type (or set) `\u03b2`,\nwe write that the *domain* of `f` is `\u03b1` and the *codomain* of `f` is `\u03b2`. This is denoted\n`f : \u03b1 \u2192 \u03b2`.\n-/\n\n/-\nGiven `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b3`, the *composite* of `g` and `f`, denoted `g \u2218 f` is the function\n`g \u2218 f : \u03b1 \u2192 \u03b3` with the property that `(g \u2218 f) x = g (f x)`, for every `x : \u03b1`.\n-/\n\n\n-- With `q\u2081` and `q\u2082` as above, `q\u2081 : \u2115 \u2192 \u2124` and `q\u2082 : Z \u2192 \u211a`. So `q\u2082 \u2218 q\u2081 : \u2115 \u2192 \u211a`.\n#check q\u2081\n#check q\u2082\n#check q\u2082 \u2218 q\u2081\n\n-- We verify, that `(q\u2082 \u2218 q\u2081) 5 = q\u2082 (q\u2081 5)`.\n#eval (q\u2082 \u2218 q\u2081) 5\n#eval q\u2082 (q\u2081 5)\n\n/-\nWith the above functions, `q\u2081 \u2218 q\u2082` is *not defined* as the codomain of `q\u2082` differs from the\ndomain of `q\u2081`.\n-/\n\n/-\nIf all the domains and codomains of two functions, say `p\u2081` and `p\u2082` are equal, then it makes sense\nto consider both composites. However, `p\u2082 \u2218 p\u2081` will not (in general) be equal to `p\u2081 \u2218 p\u2082`.\n-/\n\ndef p\u2081 (x : \u2124) : \u2124 := 3 * x\ndef p\u2082 (y : \u2124) : \u2124 := y + 4\n\n#eval (p\u2082 \u2218 p\u2081) 6  -- `(p\u2082 \u2218 p\u2081) 6 = p\u2082 (p\u2081 6) = p\u2082 (3*6) = p\u2082 18 = 18 + 4 = 22`, but\n#eval (p\u2081 \u2218 p\u2082) 6  -- `(p\u2081 \u2218 p\u2082) 6 = p\u2081 (p\u2082 6) = p\u2081 (6 + 4) = p\u2081 10 = 3 * 10 = 30`.\n\n\n/-\nWe'll prove that the composite of two injective functions is injective.\n-/\n\nvariable {\u03b1 : Type*}\nvariable {\u03b2 : Type*}\nvariable {\u03b3 : Type*}\n\ntheorem injective_comp {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (h\u2081 : injective f) (h\u2082 : injective g) :\n  injective (g \u2218 f) :=\nbegin\n  unfold injective at *, -- We use the definition of injective.\n  intros a\u2081 a\u2082 h, -- Assume `a\u2081 a\u2082 : \u03b1`. Assume `h : (g \u2218 f) a\u2081 = (g \u2218 f) a\u2082`.\n  have h\u2084 : f a\u2081 = f a\u2082,\n    from h\u2082 h, -- By injectivity of `g`, applied to `h`, we have `h\u2084 : f a\u2081 = f a\u2082`.\n  show a\u2081 = a\u2082, from h\u2081 h\u2084, -- We show `a\u2081 = a\u2082` by injectivity of `f`, applied to `h\u2084`.\nend\n\n\n/-\nWe'll prove that the composite of two surjective functions is surjective. The proof is\nmore involved that the corresponding injectivity result.\n-/\ntheorem surjective_comp {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (h\u2081 : surjective f) (h\u2082 : surjective g) :\n  surjective (g \u2218 f) :=\nbegin\n  unfold surjective at *, -- We use the definition of surjective.\n  intro c, -- Assume `c : \u03b3`. It suffices to show `\u2203 a : \u03b1, (g \u2218 f) a = c`.\n  sorry  \nend\n\n-- Exercise 145:\n-- From these two results, we have that the composite of two bijective functions is bijective.\ntheorem bijective_comp {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (h\u2081 : bijective f) (h\u2082 : bijective g) :\n  bijective (g \u2218 f) :=\nbegin\n  sorry  \nend\n\nend composite\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_32_composite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7133443214652677}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mitchell Rowett, Scott Morrison, Johan Commelin, Mario Carneiro\n-/\nimport group_theory.submonoid\nopen set function\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {a a\u2081 a\u2082 b c: \u03b1}\n\nsection group\nvariables [group \u03b1] [add_group \u03b2]\n\n@[to_additive injective_add]\nlemma injective_mul {a : \u03b1} : injective ((*) a) :=\nassume a\u2081 a\u2082 h,\nhave a\u207b\u00b9 * a * a\u2081 = a\u207b\u00b9 * a * a\u2082, by rw [mul_assoc, mul_assoc, h],\nby rwa [inv_mul_self, one_mul, one_mul] at this\n\n/-- `s` is a subgroup: a set containing 1 and closed under multiplication and inverse. -/\nclass is_subgroup (s : set \u03b1) extends is_submonoid s : Prop :=\n(inv_mem {a} : a \u2208 s \u2192 a\u207b\u00b9 \u2208 s)\n\n/-- `s` is an additive subgroup: a set containing 0 and closed under addition and negation. -/\nclass is_add_subgroup (s : set \u03b2) extends is_add_submonoid s : Prop :=\n(neg_mem {a} : a \u2208 s \u2192 -a \u2208 s)\nattribute [to_additive is_add_subgroup] is_subgroup\nattribute [to_additive is_add_subgroup.to_is_add_submonoid] is_subgroup.to_is_submonoid\nattribute [to_additive is_add_subgroup.neg_mem] is_subgroup.inv_mem\nattribute [to_additive is_add_subgroup.mk] is_subgroup.mk\n\ninstance additive.is_add_subgroup\n  (s : set \u03b1) [is_subgroup s] : @is_add_subgroup (additive \u03b1) _ s :=\n\u27e8@is_subgroup.inv_mem _ _ _ _\u27e9\n\ntheorem additive.is_add_subgroup_iff\n  {s : set \u03b1} : @is_add_subgroup (additive \u03b1) _ s \u2194 is_subgroup s :=\n\u27e8by rintro \u27e8\u27e8h\u2081, h\u2082\u27e9, h\u2083\u27e9; exact @is_subgroup.mk \u03b1 _ _ \u27e8h\u2081, @h\u2082\u27e9 @h\u2083,\n  \u03bb h, by resetI; apply_instance\u27e9\n\ninstance multiplicative.is_subgroup\n  (s : set \u03b2) [is_add_subgroup s] : @is_subgroup (multiplicative \u03b2) _ s :=\n\u27e8@is_add_subgroup.neg_mem _ _ _ _\u27e9\n\ntheorem multiplicative.is_subgroup_iff\n  {s : set \u03b2} : @is_subgroup (multiplicative \u03b2) _ s \u2194 is_add_subgroup s :=\n\u27e8by rintro \u27e8\u27e8h\u2081, h\u2082\u27e9, h\u2083\u27e9; exact @is_add_subgroup.mk \u03b2 _ _ \u27e8h\u2081, @h\u2082\u27e9 @h\u2083,\n  \u03bb h, by resetI; apply_instance\u27e9\n\ninstance subtype.group {s : set \u03b1} [is_subgroup s] : group s :=\nby subtype_instance\n\ninstance subtype.add_group {s : set \u03b2} [is_add_subgroup s] : add_group s :=\nby subtype_instance\nattribute [to_additive subtype.add_group] subtype.group\n\ntheorem is_subgroup.of_div (s : set \u03b1)\n  (one_mem : (1:\u03b1) \u2208 s) (div_mem : \u2200{a b:\u03b1}, a \u2208 s \u2192 b \u2208 s \u2192 a * b\u207b\u00b9 \u2208 s):\n  is_subgroup s :=\nhave inv_mem : \u2200a, a \u2208 s \u2192 a\u207b\u00b9 \u2208 s, from\n  assume a ha,\n  have 1 * a\u207b\u00b9 \u2208 s, from div_mem one_mem ha,\n  by simpa,\n{ inv_mem := inv_mem,\n  mul_mem := assume a b ha hb,\n    have a * b\u207b\u00b9\u207b\u00b9 \u2208 s, from div_mem ha (inv_mem b hb),\n    by simpa,\n  one_mem := one_mem }\n\ntheorem is_add_subgroup.of_sub (s : set \u03b2)\n  (zero_mem : (0:\u03b2) \u2208 s) (sub_mem : \u2200{a b:\u03b2}, a \u2208 s \u2192 b \u2208 s \u2192 a - b \u2208 s):\n  is_add_subgroup s :=\nmultiplicative.is_subgroup_iff.1 $\n@is_subgroup.of_div (multiplicative \u03b2) _ _ zero_mem @sub_mem\n\ndef gpowers (x : \u03b1) : set \u03b1 := {y | \u2203i:\u2124, x^i = y}\ndef gmultiples (x : \u03b2) : set \u03b2 := {y | \u2203i:\u2124, gsmul i x = y}\nattribute [to_additive gmultiples] gpowers\n\ninstance gpowers.is_subgroup (x : \u03b1) : is_subgroup (gpowers x) :=\n{ one_mem := \u27e8(0:\u2124), by simp\u27e9,\n  mul_mem := assume x\u2081 x\u2082 \u27e8i\u2081, h\u2081\u27e9 \u27e8i\u2082, h\u2082\u27e9, \u27e8i\u2081 + i\u2082, by simp [gpow_add, *]\u27e9,\n  inv_mem := assume x\u2080 \u27e8i, h\u27e9, \u27e8-i, by simp [h.symm]\u27e9 }\n\ninstance gmultiples.is_add_subgroup (x : \u03b2) : is_add_subgroup (gmultiples x) :=\nmultiplicative.is_subgroup_iff.1 $ gpowers.is_subgroup _\nattribute [to_additive gmultiples.is_add_subgroup] gpowers.is_subgroup\n\nlemma is_subgroup.gpow_mem {a : \u03b1} {s : set \u03b1} [is_subgroup s] (h : a \u2208 s) : \u2200{i:\u2124}, a ^ i \u2208 s\n| (n : \u2115) := is_submonoid.pow_mem h\n| -[1+ n] := is_subgroup.inv_mem (is_submonoid.pow_mem h)\n\nlemma is_add_subgroup.gsmul_mem {a : \u03b2} {s : set \u03b2} [is_add_subgroup s] : a \u2208 s \u2192 \u2200{i:\u2124}, gsmul i a \u2208 s :=\n@is_subgroup.gpow_mem (multiplicative \u03b2) _ _ _ _\n\nlemma mem_gpowers {a : \u03b1} : a \u2208 gpowers a := \u27e81, by simp\u27e9\nlemma mem_gmultiples {a : \u03b2} : a \u2208 gmultiples a := \u27e81, by simp\u27e9\nattribute [to_additive mem_gmultiples] mem_gpowers\n\nend group\n\nnamespace is_subgroup\nopen is_submonoid\nvariables [group \u03b1] (s : set \u03b1) [is_subgroup s]\n\n@[to_additive is_add_subgroup.neg_mem_iff]\nlemma inv_mem_iff : a\u207b\u00b9 \u2208 s \u2194 a \u2208 s :=\n\u27e8\u03bb h, by simpa using inv_mem h, inv_mem\u27e9\n\n@[to_additive is_add_subgroup.add_mem_cancel_left]\nlemma mul_mem_cancel_left (h : a \u2208 s) : b * a \u2208 s \u2194 b \u2208 s :=\n\u27e8\u03bb hba, by simpa using mul_mem hba (inv_mem h), \u03bb hb, mul_mem hb h\u27e9\n\n@[to_additive is_add_subgroup.add_mem_cancel_right]\nlemma mul_mem_cancel_right (h : a \u2208 s) : a * b \u2208 s \u2194 b \u2208 s :=\n\u27e8\u03bb hab, by simpa using mul_mem (inv_mem h) hab, mul_mem h\u27e9\n\nend is_subgroup\n\nnamespace group\nopen is_submonoid is_subgroup\n\nvariables [group \u03b1] {s : set \u03b1}\n\ninductive in_closure (s : set \u03b1) : \u03b1 \u2192 Prop\n| basic {a : \u03b1} : a \u2208 s \u2192 in_closure a\n| one : in_closure 1\n| inv {a : \u03b1} : in_closure a \u2192 in_closure a\u207b\u00b9\n| mul {a b : \u03b1} : in_closure a \u2192 in_closure b \u2192 in_closure (a * b)\n\n/-- `group.closure s` is the subgroup closed over `s`, i.e. the smallest subgroup containg s. -/\ndef closure (s : set \u03b1) : set \u03b1 := {a | in_closure s a }\n\nlemma mem_closure {a : \u03b1} : a \u2208 s \u2192 a \u2208 closure s := in_closure.basic\n\ninstance closure.is_subgroup (s : set \u03b1) : is_subgroup (closure s) :=\n{ one_mem := in_closure.one s, mul_mem := assume a b, in_closure.mul, inv_mem := assume a, in_closure.inv }\n\ntheorem subset_closure {s : set \u03b1} : s \u2286 closure s := \u03bb a, mem_closure\n\ntheorem closure_subset {s t : set \u03b1} [is_subgroup t] (h : s \u2286 t) : closure s \u2286 t :=\nassume a ha, by induction ha; simp [h _, *, one_mem, mul_mem, inv_mem_iff]\n\ntheorem gpowers_eq_closure {a : \u03b1} : gpowers a = closure {a} :=\nsubset.antisymm\n  (assume x h, match x, h with _, \u27e8i, rfl\u27e9 := gpow_mem (mem_closure $ by simp) end)\n  (closure_subset $ by  simp [mem_gpowers])\n\nend group\n\nnamespace add_group\nopen is_add_submonoid is_add_subgroup\n\nvariables [add_group \u03b1] {s : set \u03b1}\n\n/-- `add_group.closure s` is the additive subgroup closed over `s`, i.e. the smallest subgroup containg s. -/\ndef closure (s : set \u03b1) : set \u03b1 := @group.closure (multiplicative \u03b1) _ s\nattribute [to_additive add_group.closure] group.closure\n\nlemma mem_closure {a : \u03b1} : a \u2208 s \u2192 a \u2208 closure s := group.mem_closure\nattribute [to_additive add_group.mem_closure] group.mem_closure\n\ninstance closure.is_add_subgroup (s : set \u03b1) : is_add_subgroup (closure s) :=\nmultiplicative.is_subgroup_iff.1 $ group.closure.is_subgroup _\nattribute [to_additive add_group.closure.is_add_subgroup] group.closure.is_subgroup\n\nattribute [to_additive add_group.subset_closure] group.subset_closure\n\ntheorem closure_subset {s t : set \u03b1} [is_add_subgroup t] : s \u2286 t \u2192 closure s \u2286 t :=\ngroup.closure_subset\nattribute [to_additive add_group.closure_subset] group.closure_subset\n\ntheorem gmultiples_eq_closure {a : \u03b1} : gmultiples a = closure {a} :=\ngroup.gpowers_eq_closure\nattribute [to_additive add_group.gmultiples_eq_closure] group.gpowers_eq_closure\n\nend add_group\n\nclass normal_subgroup [group \u03b1] (s : set \u03b1) extends is_subgroup s : Prop :=\n(normal : \u2200 n \u2208 s, \u2200 g : \u03b1, g * n * g\u207b\u00b9 \u2208 s)\nclass normal_add_subgroup [add_group \u03b1] (s : set \u03b1) extends is_add_subgroup s : Prop :=\n(normal : \u2200 n \u2208 s, \u2200 g : \u03b1, g + n - g \u2208 s)\nattribute [to_additive normal_add_subgroup] normal_subgroup\nattribute [to_additive normal_add_subgroup.to_is_add_subgroup] normal_subgroup.to_is_subgroup\nattribute [to_additive normal_add_subgroup.normal] normal_subgroup.normal\nattribute [to_additive normal_add_subgroup.mk] normal_subgroup.mk\n\n@[to_additive normal_add_subgroup_of_add_comm_group]\nlemma normal_subgroup_of_comm_group [comm_group \u03b1] (s : set \u03b1) [hs : is_subgroup s] :\n  normal_subgroup s :=\n{ normal := \u03bb n hn g, by rwa [mul_right_comm, mul_right_inv, one_mul],\n  ..hs }\n\ninstance additive.normal_add_subgroup [group \u03b1]\n  (s : set \u03b1) [normal_subgroup s] : @normal_add_subgroup (additive \u03b1) _ s :=\n\u27e8@normal_subgroup.normal _ _ _ _\u27e9\n\ntheorem additive.normal_add_subgroup_iff [group \u03b1]\n  {s : set \u03b1} : @normal_add_subgroup (additive \u03b1) _ s \u2194 normal_subgroup s :=\n\u27e8by rintro \u27e8h\u2081, h\u2082\u27e9; exact\n    @normal_subgroup.mk \u03b1 _ _ (additive.is_add_subgroup_iff.1 h\u2081) @h\u2082,\n  \u03bb h, by resetI; apply_instance\u27e9\n\ninstance multiplicative.normal_subgroup [add_group \u03b1]\n  (s : set \u03b1) [normal_add_subgroup s] : @normal_subgroup (multiplicative \u03b1) _ s :=\n\u27e8@normal_add_subgroup.normal _ _ _ _\u27e9\n\ntheorem multiplicative.normal_subgroup_iff [add_group \u03b1]\n  {s : set \u03b1} : @normal_subgroup (multiplicative \u03b1) _ s \u2194 normal_add_subgroup s :=\n\u27e8by rintro \u27e8h\u2081, h\u2082\u27e9; exact\n    @normal_add_subgroup.mk \u03b1 _ _ (multiplicative.is_subgroup_iff.1 h\u2081) @h\u2082,\n  \u03bb h, by resetI; apply_instance\u27e9\n\nnamespace is_subgroup\nvariable [group \u03b1]\n\n-- Normal subgroup properties\nlemma mem_norm_comm {s : set \u03b1} [normal_subgroup s] {a b : \u03b1} (hab : a * b \u2208 s) : b * a \u2208 s :=\nhave h : a\u207b\u00b9 * (a * b) * a\u207b\u00b9\u207b\u00b9 \u2208 s, from normal_subgroup.normal (a * b) hab a\u207b\u00b9,\nby simp at h; exact h\n\nlemma mem_norm_comm_iff {s : set \u03b1} [normal_subgroup s] {a b : \u03b1} : a * b \u2208 s \u2194 b * a \u2208 s :=\n\u27e8mem_norm_comm, mem_norm_comm\u27e9\n\n/-- The trivial subgroup -/\ndef trivial (\u03b1 : Type*) [group \u03b1] : set \u03b1 := {1}\n\n@[simp] lemma mem_trivial [group \u03b1] {g : \u03b1} : g \u2208 trivial \u03b1 \u2194 g = 1 :=\nmem_singleton_iff\n\ninstance trivial_normal : normal_subgroup (trivial \u03b1) :=\nby refine {..}; simp [trivial] {contextual := tt}\n\nlemma trivial_eq_closure : trivial \u03b1 = group.closure \u2205 :=\nsubset.antisymm\n  (by simp [set.subset_def, is_submonoid.one_mem])\n  (group.closure_subset $ by simp)\n\ninstance univ_subgroup : normal_subgroup (@univ \u03b1) :=\nby refine {..}; simp\n\ndef center (\u03b1 : Type*) [group \u03b1] : set \u03b1 := {z | \u2200 g, g * z = z * g}\n\nlemma mem_center {a : \u03b1} : a \u2208 center \u03b1 \u2194 \u2200g, g * a = a * g := iff.rfl\n\ninstance center_normal : normal_subgroup (center \u03b1) :=\n{ one_mem := by simp [center],\n  mul_mem := assume a b ha hb g,\n    by rw [\u2190mul_assoc, mem_center.2 ha g, mul_assoc, mem_center.2 hb g, \u2190mul_assoc],\n  inv_mem := assume a ha g,\n    calc\n      g * a\u207b\u00b9 = a\u207b\u00b9 * (g * a) * a\u207b\u00b9 : by simp [ha g]\n      ...     = a\u207b\u00b9 * g             : by rw [\u2190mul_assoc, mul_assoc]; simp,\n  normal := assume n ha g h,\n    calc\n      h * (g * n * g\u207b\u00b9) = h * n           : by simp [ha g, mul_assoc]\n      ...               = g * g\u207b\u00b9 * n * h : by rw ha h; simp\n      ...               = g * n * g\u207b\u00b9 * h : by rw [mul_assoc g, ha g\u207b\u00b9, \u2190mul_assoc] }\n\nend is_subgroup\n\nnamespace is_add_subgroup\nvariable [add_group \u03b1]\n\nattribute [to_additive is_add_subgroup.mem_norm_comm] is_subgroup.mem_norm_comm\nattribute [to_additive is_add_subgroup.mem_norm_comm_iff] is_subgroup.mem_norm_comm_iff\n\n/-- The trivial subgroup -/\ndef trivial (\u03b1 : Type*) [add_group \u03b1] : set \u03b1 := {0}\nattribute [to_additive is_add_subgroup.trivial] is_subgroup.trivial\n\nattribute [to_additive is_add_subgroup.mem_trivial] is_subgroup.mem_trivial\n\ninstance trivial_normal : normal_add_subgroup (trivial \u03b1) :=\nmultiplicative.normal_subgroup_iff.1 is_subgroup.trivial_normal\nattribute [to_additive is_add_subgroup.trivial_normal] is_subgroup.trivial_normal\n\nattribute [to_additive is_add_subgroup.trivial_eq_closure] is_subgroup.trivial_eq_closure\n\ninstance univ_add_subgroup : normal_add_subgroup (@univ \u03b1) :=\nmultiplicative.normal_subgroup_iff.1 is_subgroup.univ_subgroup\nattribute [to_additive is_add_subgroup.univ_add_subgroup] is_subgroup.univ_subgroup\n\ndef center (\u03b1 : Type*) [add_group \u03b1] : set \u03b1 := {z | \u2200 g, g + z = z + g}\nattribute [to_additive is_add_subgroup.center] is_subgroup.center\n\nattribute [to_additive is_add_subgroup.mem_center] is_subgroup.mem_center\n\ninstance center_normal : normal_add_subgroup (center \u03b1) :=\nmultiplicative.normal_subgroup_iff.1 is_subgroup.center_normal\n\nend is_add_subgroup\n\n-- Homomorphism subgroups\nnamespace is_group_hom\nopen is_submonoid is_subgroup\nvariables [group \u03b1] [group \u03b2]\n\n@[to_additive is_add_group_hom.ker]\ndef ker (f : \u03b1 \u2192 \u03b2) [is_group_hom f] : set \u03b1 := preimage f (trivial \u03b2)\nattribute [to_additive is_add_group_hom.ker.equations._eqn_1] ker.equations._eqn_1\n\n@[to_additive is_add_group_hom.mem_ker]\nlemma mem_ker (f : \u03b1 \u2192 \u03b2) [is_group_hom f] {x : \u03b1} : x \u2208 ker f \u2194 f x = 1 :=\nmem_trivial\n\n@[to_additive is_add_group_hom.zero_ker_neg]\nlemma one_ker_inv (f : \u03b1 \u2192 \u03b2) [is_group_hom f] {a b : \u03b1} (h : f (a * b\u207b\u00b9) = 1) : f a = f b :=\nbegin\n  rw [mul f, inv f] at h,\n  rw [\u2190inv_inv (f b), eq_inv_of_mul_eq_one h]\nend\n\n@[to_additive is_add_group_hom.neg_ker_zero]\nlemma inv_ker_one (f : \u03b1 \u2192 \u03b2) [is_group_hom f] {a b : \u03b1} (h : f a = f b) : f (a * b\u207b\u00b9) = 1 :=\nhave f a * (f b)\u207b\u00b9 = 1, by rw [h, mul_right_inv],\nby rwa [\u2190inv f, \u2190mul f] at this\n\n@[to_additive is_add_group_hom.zero_iff_ker_neg]\nlemma one_iff_ker_inv (f : \u03b1 \u2192 \u03b2) [is_group_hom f] (a b : \u03b1) : f a = f b \u2194 f (a * b\u207b\u00b9) = 1 :=\n\u27e8inv_ker_one f, one_ker_inv f\u27e9\n\n@[to_additive is_add_group_hom.neg_iff_ker]\nlemma inv_iff_ker (f : \u03b1 \u2192 \u03b2) [w : is_group_hom f] (a b : \u03b1) : f a = f b \u2194 a * b\u207b\u00b9 \u2208 ker f :=\nby rw [mem_ker]; exact one_iff_ker_inv _ _ _\n\ninstance image_subgroup (f : \u03b1 \u2192 \u03b2) [is_group_hom f] (s : set \u03b1) [is_subgroup s] :\n  is_subgroup (f '' s) :=\n{ mul_mem := assume a\u2081 a\u2082 \u27e8b\u2081, hb\u2081, eq\u2081\u27e9 \u27e8b\u2082, hb\u2082, eq\u2082\u27e9,\n             \u27e8b\u2081 * b\u2082, mul_mem hb\u2081 hb\u2082, by simp [eq\u2081, eq\u2082, mul f]\u27e9,\n  one_mem := \u27e81, one_mem s, one f\u27e9,\n  inv_mem := assume a \u27e8b, hb, eq\u27e9, \u27e8b\u207b\u00b9, inv_mem hb, by rw inv f; simp *\u27e9 }\nattribute [to_additive is_add_group_hom.image_add_subgroup._match_1] is_group_hom.image_subgroup._match_1\nattribute [to_additive is_add_group_hom.image_add_subgroup._match_2] is_group_hom.image_subgroup._match_2\nattribute [to_additive is_add_group_hom.image_add_subgroup._match_3] is_group_hom.image_subgroup._match_3\nattribute [to_additive is_add_group_hom.image_add_subgroup] is_group_hom.image_subgroup\nattribute [to_additive is_add_group_hom.image_add_subgroup._match_1.equations._eqn_1] is_group_hom.image_subgroup._match_1.equations._eqn_1\nattribute [to_additive is_add_group_hom.image_add_subgroup._match_2.equations._eqn_1] is_group_hom.image_subgroup._match_2.equations._eqn_1\nattribute [to_additive is_add_group_hom.image_add_subgroup._match_3.equations._eqn_1] is_group_hom.image_subgroup._match_3.equations._eqn_1\nattribute [to_additive is_add_group_hom.image_add_subgroup.equations._eqn_1] is_group_hom.image_subgroup.equations._eqn_1\n\ninstance range_subgroup (f : \u03b1 \u2192 \u03b2) [is_group_hom f] : is_subgroup (set.range f) :=\n@set.image_univ _ _ f \u25b8 is_group_hom.image_subgroup f set.univ\nattribute [to_additive is_add_group_hom.range_add_subgroup] is_group_hom.range_subgroup\nattribute [to_additive is_add_group_hom.range_add_subgroup.equations._eqn_1] is_group_hom.range_subgroup.equations._eqn_1\n\nlocal attribute [simp] one_mem inv_mem mul_mem normal_subgroup.normal\n\ninstance preimage (f : \u03b1 \u2192 \u03b2) [is_group_hom f] (s : set \u03b2) [is_subgroup s] :\n  is_subgroup (f \u207b\u00b9' s) :=\nby refine {..}; simp [mul f, one f, inv f, @inv_mem \u03b2 _ s] {contextual:=tt}\nattribute [to_additive is_add_group_hom.preimage] is_group_hom.preimage\nattribute [to_additive is_add_group_hom.preimage.equations._eqn_1] is_group_hom.preimage.equations._eqn_1\n\ninstance preimage_normal (f : \u03b1 \u2192 \u03b2) [is_group_hom f] (s : set \u03b2) [normal_subgroup s] :\n  normal_subgroup (f \u207b\u00b9' s) :=\n\u27e8by simp [mul f, inv f] {contextual:=tt}\u27e9\nattribute [to_additive is_add_group_hom.preimage_normal] is_group_hom.preimage_normal\nattribute [to_additive is_add_group_hom.preimage_normal.equations._eqn_1] is_group_hom.preimage_normal.equations._eqn_1\n\ninstance normal_subgroup_ker (f : \u03b1 \u2192 \u03b2) [is_group_hom f] : normal_subgroup (ker f) :=\nis_group_hom.preimage_normal f (trivial \u03b2)\nattribute [to_additive is_add_group_hom.normal_subgroup_ker] is_group_hom.normal_subgroup_ker\nattribute [to_additive is_add_group_hom.normal_subgroup_ker.equations._eqn_1] is_group_hom.normal_subgroup_ker.equations._eqn_1\n\nlemma inj_of_trivial_ker (f : \u03b1 \u2192 \u03b2) [is_group_hom f] (h : ker f = trivial \u03b1) :\n  function.injective f :=\nbegin\n  intros a\u2081 a\u2082 hfa,\n  simp [ext_iff, ker, is_subgroup.trivial] at h,\n  have ha : a\u2081 * a\u2082\u207b\u00b9 = 1, by rw \u2190h; exact inv_ker_one f hfa,\n  rw [eq_inv_of_mul_eq_one ha, inv_inv a\u2082]\nend\n\nlemma trivial_ker_of_inj (f : \u03b1 \u2192 \u03b2) [is_group_hom f] (h : function.injective f) :\n  ker f = trivial \u03b1 :=\nset.ext $ assume x, iff.intro\n  (assume hx,\n    suffices f x = f 1, by simpa using h this,\n    by simp [one f]; rwa [mem_ker] at hx)\n  (by simp [mem_ker, is_group_hom.one f] {contextual := tt})\n\nlemma inj_iff_trivial_ker (f : \u03b1 \u2192 \u03b2) [is_group_hom f] :\n  function.injective f \u2194 ker f = trivial \u03b1 :=\n\u27e8trivial_ker_of_inj f, inj_of_trivial_ker f\u27e9\n\nend is_group_hom\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/group_theory/subgroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7133443025406526}}
{"text": "/-\nCopyright (c) 2022 Moritz Doll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Moritz Doll\n-/\n\nimport analysis.calculus.iterated_deriv\nimport analysis.calculus.mean_value\nimport data.polynomial.basic\nimport data.polynomial.module\n\n/-!\n# Taylor's theorem\n\nThis file defines the Taylor polynomial of a real function `f : \u211d \u2192 E`,\nwhere `E` is a normed vector space over `\u211d` and proves Taylor's theorem,\nwhich states that if `f` is sufficiently smooth, then\n`f` can be approximated by the Taylor polynomial up to an explicit error term.\n\n## Main definitions\n\n* `taylor_coeff_within`: the Taylor coefficient using `deriv_within`\n* `taylor_within`: the Taylor polynomial using `deriv_within`\n\n## Main statements\n\n* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term\n* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder\n* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder\n* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a\npolynomial bound on the remainder\n\n## TODO\n\n* the Peano form of the remainder\n* the integral form of the remainder\n* Generalization to higher dimensions\n\n## Tags\n\nTaylor polynomial, Taylor's theorem\n-/\n\n\nopen_locale big_operators interval topology nat\nopen set\n\nvariables {\ud835\udd5c E F : Type*}\nvariables [normed_add_comm_group E] [normed_space \u211d E]\n\n/-- The `k`th coefficient of the Taylor polynomial. -/\nnoncomputable\ndef taylor_coeff_within (f : \u211d \u2192 E) (k : \u2115) (s : set \u211d) (x\u2080 : \u211d) : E :=\n(k! : \u211d)\u207b\u00b9 \u2022 (iterated_deriv_within k f s x\u2080)\n\n/-- The Taylor polynomial with derivatives inside of a set `s`.\n\nThe Taylor polynomial is given by\n$$\u2211_{k=0}^n \\frac{(x - x\u2080)^k}{k!} f^{(k)}(x\u2080),$$\nwhere $f^{(k)}(x\u2080)$ denotes the iterated derivative in the set `s`. -/\nnoncomputable\ndef taylor_within (f : \u211d \u2192 E) (n : \u2115) (s : set \u211d) (x\u2080 : \u211d) : polynomial_module \u211d E :=\n(finset.range (n+1)).sum (\u03bb k,\n  polynomial_module.comp (polynomial.X - polynomial.C x\u2080)\n  (polynomial_module.single \u211d k (taylor_coeff_within f k s x\u2080)))\n\n/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `\u211d \u2192 E`-/\nnoncomputable\ndef taylor_within_eval (f : \u211d \u2192 E) (n : \u2115) (s : set \u211d) (x\u2080 x : \u211d) : E :=\npolynomial_module.eval x (taylor_within f n s x\u2080)\n\nlemma taylor_within_succ (f : \u211d \u2192 E) (n : \u2115) (s : set \u211d) (x\u2080 : \u211d) :\n  taylor_within f (n+1) s x\u2080 = taylor_within f n s x\u2080\n  + polynomial_module.comp (polynomial.X - polynomial.C x\u2080)\n  (polynomial_module.single \u211d (n+1) (taylor_coeff_within f (n+1) s x\u2080)) :=\nbegin\n  dunfold taylor_within,\n  rw finset.sum_range_succ,\nend\n\n@[simp] lemma taylor_within_eval_succ (f : \u211d \u2192 E) (n : \u2115) (s : set \u211d) (x\u2080 x : \u211d) :\n  taylor_within_eval f (n+1) s x\u2080 x = taylor_within_eval f n s x\u2080 x\n  + (((n + 1 : \u211d) * n!)\u207b\u00b9 * (x - x\u2080)^(n+1)) \u2022 iterated_deriv_within (n + 1) f s x\u2080 :=\nbegin\n  simp_rw [taylor_within_eval, taylor_within_succ, linear_map.map_add, polynomial_module.comp_eval],\n  congr,\n  simp only [polynomial.eval_sub, polynomial.eval_X, polynomial.eval_C,\n    polynomial_module.eval_single, mul_inv_rev],\n  dunfold taylor_coeff_within,\n  rw [\u2190mul_smul, mul_comm, nat.factorial_succ, nat.cast_mul, nat.cast_add, nat.cast_one,\n    mul_inv_rev],\nend\n\n/-- The Taylor polynomial of order zero evaluates to `f x`. -/\n@[simp] lemma taylor_within_zero_eval (f : \u211d \u2192 E) (s : set \u211d) (x\u2080 x : \u211d) :\n  taylor_within_eval f 0 s x\u2080 x = f x\u2080 :=\nbegin\n  dunfold taylor_within_eval,\n  dunfold taylor_within,\n  dunfold taylor_coeff_within,\n  simp,\nend\n\n/-- Evaluating the Taylor polynomial at `x = x\u2080` yields `f x`. -/\n@[simp] lemma taylor_within_eval_self (f : \u211d \u2192 E) (n : \u2115) (s : set \u211d) (x\u2080 : \u211d) :\n  taylor_within_eval f n s x\u2080 x\u2080 = f x\u2080 :=\nbegin\n  induction n with k hk,\n  { exact taylor_within_zero_eval _ _ _ _},\n  simp [hk]\nend\n\nlemma taylor_within_apply (f : \u211d \u2192 E) (n : \u2115) (s : set \u211d) (x\u2080 x : \u211d) :\n  taylor_within_eval f n s x\u2080 x = \u2211 k in finset.range (n+1),\n    ((k! : \u211d)\u207b\u00b9 * (x - x\u2080)^k) \u2022 iterated_deriv_within k f s x\u2080 :=\nbegin\n  induction n with k hk,\n  { simp },\n  rw [taylor_within_eval_succ, finset.sum_range_succ, hk],\n  simp,\nend\n\n/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial\n  `taylor_within_eval f n s x\u2080 x` is continuous in `x\u2080`. -/\nlemma continuous_on_taylor_within_eval {f : \u211d \u2192 E} {x : \u211d} {n : \u2115} {s : set \u211d}\n  (hs : unique_diff_on \u211d s) (hf : cont_diff_on \u211d n f s) :\n  continuous_on (\u03bb t, taylor_within_eval f n s t x) s :=\nbegin\n  simp_rw taylor_within_apply,\n  refine continuous_on_finset_sum (finset.range (n+1)) (\u03bb i hi, _),\n  refine (continuous_on_const.mul ((continuous_on_const.sub continuous_on_id).pow _)).smul _,\n  rw cont_diff_on_iff_continuous_on_differentiable_on_deriv hs at hf,\n  cases hf,\n  specialize hf_left i,\n  simp only [finset.mem_range] at hi,\n  refine (hf_left _),\n  simp only [with_top.coe_le_coe],\n  exact nat.lt_succ_iff.mp hi,\nend\n\n/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/\nlemma monomial_has_deriv_aux (t x : \u211d) (n : \u2115) :\n  has_deriv_at (\u03bb y, (x - y)^(n+1)) (-(n+1) * (x - t)^n) t :=\nbegin\n  simp_rw sub_eq_neg_add,\n  rw [\u2190neg_one_mul, mul_comm (-1 : \u211d), mul_assoc, mul_comm (-1 : \u211d), \u2190mul_assoc],\n  convert @has_deriv_at.pow _ _ _ _ _ (n+1) ((has_deriv_at_id t).neg.add_const x),\n  simp only [nat.cast_add, nat.cast_one],\nend\n\nlemma has_deriv_within_at_taylor_coeff_within {f : \u211d \u2192 E} {x y : \u211d} {k : \u2115} {s s' : set \u211d}\n  (hs'_unique : unique_diff_within_at \u211d s' y)\n  (hs' : s' \u2208 \ud835\udcdd[s] y) (hy : y \u2208 s') (h : s' \u2286 s)\n  (hf' : differentiable_on \u211d (iterated_deriv_within (k+1) f s) s') :\n  has_deriv_within_at (\u03bb t,\n    (((k+1 : \u211d) * k!)\u207b\u00b9 * (x - t)^(k+1)) \u2022 iterated_deriv_within (k+1) f s t)\n    ((((k+1 : \u211d) * k!)\u207b\u00b9 * (x - y)^(k+1)) \u2022 iterated_deriv_within (k+2) f s y -\n    ((k! : \u211d)\u207b\u00b9 * (x - y)^k) \u2022 iterated_deriv_within (k+1) f s y) s' y :=\nbegin\n  have hf'' : has_deriv_within_at (\u03bb t, iterated_deriv_within (k+1) f s t)\n    (iterated_deriv_within (k+2) f s y) s' y :=\n  begin\n    convert (hf' y hy).has_deriv_within_at,\n    rw iterated_deriv_within_succ (hs'_unique.mono h),\n    refine (deriv_within_subset h hs'_unique _).symm,\n    exact (hf' y hy).antimono h hs',\n  end,\n  have : has_deriv_within_at (\u03bb t, (((k+1 : \u211d) * k!)\u207b\u00b9 * (x - t)^(k+1)))\n    (-((k! : \u211d)\u207b\u00b9 * (x - y)^k)) s' y :=\n  begin\n    -- Commuting the factors:\n    have : (-((k! : \u211d)\u207b\u00b9 * (x - y)^k)) =\n      (((k+1 : \u211d) * k!)\u207b\u00b9 * (-(k+1) *(x - y)^k)) :=\n    by { field_simp [nat.cast_add_one_ne_zero k, nat.factorial_ne_zero k], ring_nf },\n    rw this,\n    exact (monomial_has_deriv_aux y x _).has_deriv_within_at.const_mul _,\n  end,\n  convert this.smul hf'',\n  field_simp [nat.cast_add_one_ne_zero k, nat.factorial_ne_zero k],\n  rw [neg_div, neg_smul, sub_eq_add_neg],\nend\n\n/-- Calculate the derivative of the Taylor polynomial with respect to `x\u2080`.\n\nVersion for arbitrary sets -/\nlemma has_deriv_within_at_taylor_within_eval {f : \u211d \u2192 E} {x y : \u211d} {n : \u2115} {s s' : set \u211d}\n  (hs'_unique : unique_diff_within_at \u211d s' y) (hs_unique : unique_diff_on \u211d s)\n  (hs' : s' \u2208 \ud835\udcdd[s] y) (hy : y \u2208 s') (h : s' \u2286 s)\n  (hf : cont_diff_on \u211d n f s)\n  (hf' : differentiable_on \u211d (iterated_deriv_within n f s) s') :\n  has_deriv_within_at (\u03bb t, taylor_within_eval f n s t x)\n    (((n! : \u211d)\u207b\u00b9 * (x - y)^n) \u2022 (iterated_deriv_within (n+1) f s y)) s' y :=\nbegin\n  induction n with k hk,\n  { simp only [taylor_within_zero_eval, nat.factorial_zero, nat.cast_one, inv_one, pow_zero,\n      mul_one, zero_add, one_smul],\n    simp only [iterated_deriv_within_zero] at hf',\n    rw iterated_deriv_within_one hs_unique (h hy),\n    refine has_deriv_within_at.mono _ h,\n    refine differentiable_within_at.has_deriv_within_at _,\n    exact (hf' y hy).antimono h hs' },\n  simp_rw [nat.add_succ, taylor_within_eval_succ],\n  simp only [add_zero, nat.factorial_succ, nat.cast_mul, nat.cast_add, nat.cast_one],\n  have hdiff : differentiable_on \u211d (iterated_deriv_within k f s) s' :=\n  begin\n    have coe_lt_succ : (k : with_top \u2115) < k.succ :=\n    by { rw [with_top.coe_lt_coe], exact lt_add_one k },\n    refine differentiable_on.mono _ h,\n    exact hf.differentiable_on_iterated_deriv_within coe_lt_succ hs_unique,\n  end,\n  specialize hk (cont_diff_on.of_succ hf) hdiff,\n  convert hk.add (has_deriv_within_at_taylor_coeff_within hs'_unique hs' hy h hf'),\n  exact (add_sub_cancel'_right _ _).symm,\nend\n\n/-- Calculate the derivative of the Taylor polynomial with respect to `x\u2080`.\n\nVersion for open intervals -/\nlemma taylor_within_eval_has_deriv_at_Ioo {f : \u211d \u2192 E} {a b t : \u211d} (x : \u211d) {n : \u2115}\n  (hx : a < b) (ht : t \u2208 Ioo a b)\n  (hf : cont_diff_on \u211d n f (Icc a b))\n  (hf' : differentiable_on \u211d (iterated_deriv_within n f (Icc a b)) (Ioo a b)) :\n  has_deriv_at (\u03bb y, taylor_within_eval f n (Icc a b) y x)\n    (((n! : \u211d)\u207b\u00b9 * (x - t)^n) \u2022 (iterated_deriv_within (n+1) f (Icc a b) t)) t :=\nbegin\n  have h_nhds := is_open.mem_nhds is_open_Ioo ht,\n  exact (has_deriv_within_at_taylor_within_eval (unique_diff_within_at_Ioo ht)\n    (unique_diff_on_Icc hx) (nhds_within_le_nhds h_nhds) ht Ioo_subset_Icc_self hf hf')\n    .has_deriv_at h_nhds,\nend\n\n/-- Calculate the derivative of the Taylor polynomial with respect to `x\u2080`.\n\nVersion for closed intervals -/\nlemma has_deriv_within_taylor_within_eval_at_Icc {f : \u211d \u2192 E} {a b t : \u211d} (x : \u211d) {n : \u2115}\n  (hx : a < b) (ht : t \u2208 Icc a b) (hf : cont_diff_on \u211d n f (Icc a b))\n  (hf' : differentiable_on \u211d (iterated_deriv_within n f (Icc a b)) (Icc a b)) :\n  has_deriv_within_at (\u03bb y, taylor_within_eval f n (Icc a b) y x)\n    (((n! : \u211d)\u207b\u00b9 * (x - t)^n) \u2022 (iterated_deriv_within (n+1) f (Icc a b) t)) (Icc a b) t :=\nhas_deriv_within_at_taylor_within_eval (unique_diff_on_Icc hx t ht) (unique_diff_on_Icc hx)\n  self_mem_nhds_within ht rfl.subset hf hf'\n\n/-! ### Taylor's theorem with mean value type remainder estimate -/\n\n/-- **Taylor's theorem** with the general mean value form of the remainder.\n\nWe assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x\u2080 x` and\n`n+1`-times differentiable on the open set `Ioo x\u2080 x`, and `g` is a differentiable function on\n`Ioo x\u2080 x` and continuous on `Icc x\u2080 x`. Then there exists a `x' \u2208 Ioo x\u2080 x` such that\n$$f(x) - (P_n f)(x\u2080, x) = \\frac{(x - x')^n}{n!} \\frac{g(x) - g(x\u2080)}{g' x'},$$\nwhere $P_n f$ denotes the Taylor polynomial of degree $n$. -/\nlemma taylor_mean_remainder {f : \u211d \u2192 \u211d} {g g' : \u211d \u2192 \u211d} {x x\u2080 : \u211d} {n : \u2115} (hx : x\u2080 < x)\n  (hf : cont_diff_on \u211d n f (Icc x\u2080 x))\n  (hf' : differentiable_on \u211d (iterated_deriv_within n f (Icc x\u2080 x)) (Ioo x\u2080 x))\n  (gcont : continuous_on g (Icc x\u2080 x))\n  (gdiff : \u2200 (x_1 : \u211d), x_1 \u2208 Ioo x\u2080 x \u2192 has_deriv_at g (g' x_1) x_1)\n  (g'_ne : \u2200 (x_1 : \u211d), x_1 \u2208 Ioo x\u2080 x \u2192 g' x_1 \u2260 0) :\n  \u2203 (x' : \u211d) (hx' : x' \u2208 Ioo x\u2080 x), f x - taylor_within_eval f n (Icc x\u2080 x) x\u2080 x =\n  ((x - x')^n /n! * (g x - g x\u2080) / g' x') \u2022\n    (iterated_deriv_within (n+1) f (Icc x\u2080 x) x')\n  :=\nbegin\n  -- We apply the mean value theorem\n  rcases exists_ratio_has_deriv_at_eq_ratio_slope (\u03bb t, taylor_within_eval f n (Icc x\u2080 x) t x)\n    (\u03bb t, ((n! : \u211d)\u207b\u00b9 * (x - t)^n) \u2022 (iterated_deriv_within (n+1) f (Icc x\u2080 x) t)) hx\n    (continuous_on_taylor_within_eval (unique_diff_on_Icc hx) hf)\n    (\u03bb _ hy, taylor_within_eval_has_deriv_at_Ioo x hx hy hf hf')\n    g g' gcont gdiff with \u27e8y, hy, h\u27e9,\n  use [y, hy],\n  -- The rest is simplifications and trivial calculations\n  simp only [taylor_within_eval_self] at h,\n  rw [mul_comm, \u2190div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h,\n  rw \u2190h,\n  field_simp [g'_ne y hy, n.factorial_ne_zero],\n  ring,\nend\n\n/-- **Taylor's theorem** with the Lagrange form of the remainder.\n\nWe assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x\u2080 x` and\n`n+1`-times differentiable on the open set `Ioo x\u2080 x`. Then there exists a `x' \u2208 Ioo x\u2080 x` such that\n$$f(x) - (P_n f)(x\u2080, x) = \\frac{f^{(n+1)}(x') (x - x\u2080)^{n+1}}{(n+1)!},$$\nwhere $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated\nderivative. -/\nlemma taylor_mean_remainder_lagrange {f : \u211d \u2192 \u211d} {x x\u2080 : \u211d} {n : \u2115} (hx : x\u2080 < x)\n  (hf : cont_diff_on \u211d n f (Icc x\u2080 x))\n  (hf' : differentiable_on \u211d (iterated_deriv_within n f (Icc x\u2080 x)) (Ioo x\u2080 x)) :\n  \u2203 (x' : \u211d) (hx' : x' \u2208 Ioo x\u2080 x), f x - taylor_within_eval f n (Icc x\u2080 x) x\u2080 x =\n  (iterated_deriv_within (n+1) f (Icc x\u2080 x) x') * (x - x\u2080)^(n+1) /(n+1)! :=\nbegin\n  have gcont : continuous_on (\u03bb (t : \u211d), (x - t) ^ (n + 1)) (Icc x\u2080 x) :=\n  by { refine continuous.continuous_on _, continuity },\n  have xy_ne : \u2200 (y : \u211d), y \u2208 Ioo x\u2080 x \u2192 (x - y)^n \u2260 0 :=\n  begin\n    intros y hy,\n    refine pow_ne_zero _ _,\n    rw [mem_Ioo] at hy,\n    rw sub_ne_zero,\n    exact hy.2.ne.symm,\n  end,\n  have hg' : \u2200 (y : \u211d), y \u2208 Ioo x\u2080 x \u2192 -(\u2191n + 1) * (x - y) ^ n \u2260 0 :=\n  \u03bb y hy, mul_ne_zero (neg_ne_zero.mpr (nat.cast_add_one_ne_zero n)) (xy_ne y hy),\n  -- We apply the general theorem with g(t) = (x - t)^(n+1)\n  rcases taylor_mean_remainder hx hf hf' gcont (\u03bb y _, monomial_has_deriv_aux y x _) hg'\n    with \u27e8y, hy, h\u27e9,\n  use [y, hy],\n  simp only [sub_self, zero_pow', ne.def, nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h,\n  rw [h, neg_div, \u2190div_neg, neg_mul, neg_neg],\n  field_simp [n.cast_add_one_ne_zero, n.factorial_ne_zero, xy_ne y hy],\n  ring,\nend\n\n/-- **Taylor's theorem** with the Cauchy form of the remainder.\n\nWe assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x\u2080 x` and\n`n+1`-times differentiable on the open set `Ioo x\u2080 x`. Then there exists a `x' \u2208 Ioo x\u2080 x` such that\n$$f(x) - (P_n f)(x\u2080, x) = \\frac{f^{(n+1)}(x') (x - x')^n (x-x\u2080)}{n!},$$\nwhere $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated\nderivative. -/\nlemma taylor_mean_remainder_cauchy {f : \u211d \u2192 \u211d} {x x\u2080 : \u211d} {n : \u2115} (hx : x\u2080 < x)\n  (hf : cont_diff_on \u211d n f (Icc x\u2080 x))\n  (hf' : differentiable_on \u211d (iterated_deriv_within n f (Icc x\u2080 x)) (Ioo x\u2080 x)) :\n  \u2203 (x' : \u211d) (hx' : x' \u2208 Ioo x\u2080 x), f x - taylor_within_eval f n (Icc x\u2080 x) x\u2080 x =\n  (iterated_deriv_within (n+1) f (Icc x\u2080 x) x') * (x - x')^n /n! * (x - x\u2080) :=\nbegin\n  have gcont : continuous_on id (Icc x\u2080 x) := continuous.continuous_on (by continuity),\n  have gdiff : (\u2200 (x_1 : \u211d), x_1 \u2208 Ioo x\u2080 x \u2192 has_deriv_at id\n    ((\u03bb (t : \u211d), (1 : \u211d)) x_1) x_1) := \u03bb _ _, has_deriv_at_id _,\n  -- We apply the general theorem with g = id\n  rcases taylor_mean_remainder hx hf hf' gcont gdiff (\u03bb _ _, by simp) with \u27e8y, hy, h\u27e9,\n  use [y, hy],\n  rw h,\n  field_simp [n.factorial_ne_zero],\n  ring,\nend\n\n/-- **Taylor's theorem** with a polynomial bound on the remainder\n\nWe assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.\nThe difference of `f` and its `n`-th Taylor polynomial can be estimated by\n`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/\nlemma taylor_mean_remainder_bound {f : \u211d \u2192 E} {a b C x : \u211d} {n : \u2115}\n  (hab : a \u2264 b) (hf : cont_diff_on \u211d (n+1) f (Icc a b)) (hx : x \u2208 Icc a b)\n  (hC : \u2200 y \u2208 Icc a b, \u2016iterated_deriv_within (n + 1) f (Icc a b) y\u2016 \u2264 C) :\n  \u2016f x - taylor_within_eval f n (Icc a b) a x\u2016 \u2264 C * (x - a)^(n+1) / n! :=\nbegin\n  rcases eq_or_lt_of_le hab with rfl|h,\n  { rw [Icc_self, mem_singleton_iff] at hx,\n    simp [hx] },\n  -- The nth iterated derivative is differentiable\n  have hf' : differentiable_on \u211d (iterated_deriv_within n f (Icc a b)) (Icc a b) :=\n  hf.differentiable_on_iterated_deriv_within (with_top.coe_lt_coe.mpr n.lt_succ_self)\n    (unique_diff_on_Icc h),\n  -- We can uniformly bound the derivative of the Taylor polynomial\n  have h' : \u2200 (y : \u211d) (hy : y \u2208 Ico a x),\n    \u2016((n! : \u211d)\u207b\u00b9 * (x - y) ^ n) \u2022 iterated_deriv_within (n + 1) f (Icc a b) y\u2016\n    \u2264 (n! : \u211d)\u207b\u00b9 * |(x - a)|^n * C,\n  { rintro y \u27e8hay, hyx\u27e9,\n    rw [norm_smul, real.norm_eq_abs],\n    -- Estimate the iterated derivative by `C`\n    refine mul_le_mul _ (hC y \u27e8hay, hyx.le.trans hx.2\u27e9) (by positivity) (by positivity),\n    -- The rest is a trivial calculation\n    rw [abs_mul, abs_pow, abs_inv, nat.abs_cast],\n    mono* with [0 \u2264 (n! : \u211d)\u207b\u00b9],\n    any_goals { positivity },\n    linarith [hx.1, hyx] },\n  -- Apply the mean value theorem for vector valued functions:\n  have A : \u2200 t \u2208 Icc a x, has_deriv_within_at (\u03bb y, taylor_within_eval f n (Icc a b) y x)\n    (((\u2191n!)\u207b\u00b9 * (x - t) ^ n) \u2022 iterated_deriv_within (n + 1) f (Icc a b) t) (Icc a x) t,\n  { assume t ht,\n    have I : Icc a x \u2286 Icc a b := Icc_subset_Icc_right hx.2,\n    exact (has_deriv_within_taylor_within_eval_at_Icc x h (I ht) hf.of_succ hf').mono I },\n  have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1),\n  simp only [taylor_within_eval_self] at this,\n  refine this.trans_eq _,\n  -- The rest is a trivial calculation\n  rw [abs_of_nonneg (sub_nonneg.mpr hx.1)],\n  ring_exp,\nend\n\n\n/-- **Taylor's theorem** with a polynomial bound on the remainder\n\nWe assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.\nThere exists a constant `C` such that for all `x \u2208 Icc a b` the difference of `f` and its `n`-th\nTaylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/\nlemma exists_taylor_mean_remainder_bound {f : \u211d \u2192 E} {a b : \u211d} {n : \u2115}\n  (hab : a \u2264 b) (hf : cont_diff_on \u211d (n+1) f (Icc a b)) :\n  \u2203 C, \u2200 x \u2208 Icc a b, \u2016f x - taylor_within_eval f n (Icc a b) a x\u2016 \u2264 C * (x - a)^(n+1) :=\nbegin\n  rcases eq_or_lt_of_le hab with rfl|h,\n  { refine \u27e80, \u03bb x hx, _\u27e9,\n    have : a = x, by simpa [\u2190 le_antisymm_iff] using hx,\n    simp [\u2190 this] },\n  -- We estimate by the supremum of the norm of the iterated derivative\n  let g : \u211d \u2192 \u211d := \u03bb y, \u2016iterated_deriv_within (n + 1) f (Icc a b) y\u2016,\n  use [has_Sup.Sup (g '' Icc a b) / n!],\n  intros x hx,\n  rw div_mul_eq_mul_div\u2080,\n  refine taylor_mean_remainder_bound hab hf hx (\u03bb y, _),\n  exact (hf.continuous_on_iterated_deriv_within rfl.le $ unique_diff_on_Icc h)\n    .norm.le_Sup_image_Icc,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/calculus/taylor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7132928580569253}}
{"text": "import combinatorics.simple_graph.connectivity\n\n#check simple_graph.walk.take_until\n\n/-!\n# Trees!\n\nA graph is a tree if for every pair of vertices there is a unique\npath between them\n\nThings to try:\n\n1) tree \u2194 \u2203! trails\n2) tree \u2194 connected + no cycles\n\n-/\n\n\nuniverse u\u2080\n\nnamespace simple_graph\n\ndef is_tree {V : Type u\u2080} (G : simple_graph V) : Prop :=\n\u2200 u v : V, \u2203! p : G.walk u v, p.is_path\n\ndef is_connected {V : Type u\u2080} (G : simple_graph V) : Prop :=\n\u2200 u v : V, \u2203 p : G.walk u v, p.is_path\n\nnamespace is_tree\nvariables {V: Type u\u2080} { G : simple_graph V} \n\nlemma is_tree.is_connceted {V : Type u\u2080} (G : simple_graph V)\n  (h: G.is_tree) : G.is_connected :=\nbegin\n  intros u v,\n  exact exists_unique.exists (h u v),\nend\n\nopen simple_graph.walk\n\nexample (X : Type) (P: X \u2192 Prop) (hP : \u2203! a : X, P a) (x y : X)\n  (hx : P x) (hy : P y) : x = y := exists_unique.unique hP hx hy\n\nlemma no_cycles [decidable_eq V] (hG: G.is_tree) (u : V) (p: G.walk u u) (hp : p.is_cycle)\n : false :=\nbegin\n  cases p with _ _ v _ huv q,\n  -- Nil walk is not a cycle\n  {\n    exact hp.ne_nil rfl,\n  }, {\n    set w1 := walk.cons huv nil with hw1,\n    set w2 := q.reverse with hw2,\n    have hw1path : w1.is_path,\n    {\n      simp,\n      intro h,\n      rewrite h at huv,\n      exact G.loopless v huv,\n    },\n    have hw2path : w2.is_path,\n    { sorry },\n\n    have hw := exists_unique.unique (hG u v) hw1path hw2path,\n    sorry,\n    -- stopping because no time\n  },\nend\n\nvariables {u v w : V} (p : G.walk u v)\n\n\nend is_tree\nend simple_graph\n", "meta": {"author": "Girgias", "repo": "icl-2022-formalising-mathematics-irl", "sha": "966bdfb8d544275b8b069d49c8dce885593a65e5", "save_path": "github-repos/lean/Girgias-icl-2022-formalising-mathematics-irl", "path": "github-repos/lean/Girgias-icl-2022-formalising-mathematics-irl/icl-2022-formalising-mathematics-irl-966bdfb8d544275b8b069d49c8dce885593a65e5/src/03-15session-tree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787563, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7132928499816702}}
{"text": "-- Welcome to Lean! As you can tell I'm working with Lean through VS Code. Unfortunately there aren't a ton of options available for Lean-compatible editors (the other option is emacs)\n\n\n\n\n\n-- I'll be using ``tactics'' to prove the results below, so I need to import the tactics module just as I would import a module in any other language. \nimport tactic\nimport data.nat.basic\n\n\n\n\n\n-- A little trick so Lean doesn't get confused between my definition of even and odd and the one already implemented in Lean.\nnamespace hidden\n\n\n\n\n\n\n-- The syntax of Lean is very human readable. It features UTF-8 encoding, and has all of our favorite characters like \u2190, \u2192, \u2194, \u27e8\u27e9, \u2115, \u2124, \u211d, \u2102   \n\ndef even (n : \u2115) := \u2203(k : \u2115), 2*k = n\ndef odd  (n : \u2115) := \u2203(k : \u2115), 2*k + 1 = n\n\n\n\n\n\ntheorem even_plus_even {n m : \u2115} (h\u2081 : even n) (h\u2082 : even m) : even (n + m) :=\n-- Begin and end are used to denote the beginning and end of a proof given in tactic mode. Sorry is a tactic that automatically proves any theorem! (unfortunately, it's cheating so Lean scolds us for using it)\nbegin\n  sorry\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n-- Lets prove an even harder theorem. This time we should think a little bit about how we would go about showing this result on pen and paper before we jump into its formalization. \ntheorem even_or_odd {n : \u2115} : even n \u2228 odd n :=\nbegin\n  sorry\nend\n\nend hidden\n", "meta": {"author": "mpenciak", "repo": "Lean-Seminar-Sp2022", "sha": "49437bb35643bf43e90afddb2e7702a749a725e4", "save_path": "github-repos/lean/mpenciak-Lean-Seminar-Sp2022", "path": "github-repos/lean/mpenciak-Lean-Seminar-Sp2022/Lean-Seminar-Sp2022-49437bb35643bf43e90afddb2e7702a749a725e4/src/week1/demo1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7132928499692985}}
{"text": "import data.set\nopen set\n\nnamespace logic\n\n    def reflexivity (R : set Prop \u2192 Prop \u2192 Prop) :=    \n        \u2200 \u03b1 : Prop, R {\u03b1} \u03b1\n\n    def monotonicity (R : set Prop \u2192 Prop \u2192 Prop) : Prop :=\n        \u2200 \u0393 \u0394 : set Prop, \u2200 \u03b1 : Prop, \u0393 \u2286 \u0394 \u2227 R \u0393 \u03b1 \u2192 R \u0394 \u03b1\n\n    def transitivity (R : set Prop \u2192 Prop \u2192 Prop) : Prop :=\n        \u2200 \u0393 \u0394 : set Prop, \u2200 \u03b1 : Prop, R (\u0393 \u222a \u0394) \u03b1 \u2227 (\u2200 \u03b2 \u2208 \u0394, R \u0393 \u03b2) \u2192 R \u0393 \u03b1\n    \n    theorem transitivity_single (R : set Prop \u2192 Prop \u2192 Prop) : Prop :=\n        \u2200 \u0393 : set Prop, \u2200 \u03b1 \u03b2 : Prop, R (\u0393 \u222a {\u03b1}) \u03b2 \u2227 R \u0393 \u03b1 \u2192 R \u0393 \u03b2\n\n    variables {\u03b1 \u03b2 : Prop}\n    variables {\u0393 \u0394 : set Prop}\n    variable R : set Prop \u2192 Prop \u2192 Prop\n    variable {reflCr : reflexivity R}\n    variable {monCr : monotonicity R}\n    variable {cutCr : transitivity R}\n\n    example (x : Prop) : R {x} x := reflCr x\n\nend logic\n", "meta": {"author": "greati", "repo": "hilbert-classical-fragments", "sha": "18a21ac6b2e890060eb4ae65752fc0245394d226", "save_path": "github-repos/lean/greati-hilbert-classical-fragments", "path": "github-repos/lean/greati-hilbert-classical-fragments/hilbert-classical-fragments-18a21ac6b2e890060eb4ae65752fc0245394d226/clfrags/src/core/consequence_relation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7132928483690935}}
{"text": "import homotopy.basic\nimport topology.path_connected\nimport path.defs\nimport intervals\n\n/-!\n# Homotopy of Paths\n\nIn this file, we define what it means for two paths to be homotopic. Furthermore, we show that this\nis an equivalence relation.\n-/\n\nnoncomputable theory\n\nvariables {X Y : Type _} [topological_space X] [topological_space Y] {x\u2080 x\u2081 x\u2082 x\u2083 : X}\n\nopen_locale unit_interval\n\n/--\nA `path_homotopy` between paths `f\u2080` and `f\u2081` is a homotopy between `f\u2080` and `f\u2081` which keep the end\npoints fixed.\n-/\nabbreviation path_homotopy (f\u2080 f\u2081 : path' x\u2080 x\u2081) := \n  homotopy_with (f\u2080 : C(\u211d, X)) f\u2081 (\u03bb r, r 0 = x\u2080 \u2227 r 1 = x\u2081)\n\nnamespace path_homotopy\n\nsection lemmas\n\nvariables {f\u2080 f\u2081 : path' x\u2080 x\u2081}\n\n@[simp] lemma to_fun_zero (h : path_homotopy f\u2080 f\u2081) {t : \u211d} : \n  h (0, t) = x\u2080 :=\nby simpa using (h.prop t).1\n\n@[simp] lemma to_fun_one (h : path_homotopy f\u2080 f\u2081) {t : \u211d} : \n  h (1, t) = x\u2081 :=\nby simpa using (h.prop t).2\n\n/--\nA path is homotopic to itself.\n-/\ndef refl (f\u2080 : path' x\u2080 x\u2081) : path_homotopy f\u2080 f\u2080 := homotopy_with.refl (by simp)\n\n/--\nGiven two paths `f\u2080` and `f\u2081` which agree for all inputs, we have a homotopy between them.\n-/\ndef of_refl {f\u2080 f\u2081 : path' x\u2080 x\u2081} (h : f\u2080 = f\u2081) : path_homotopy f\u2080 f\u2081 := \n{ to_fun := \n  { to_fun := \u03bb p : \u211d \u00d7 \u211d, f\u2080 (prod.fst p) },\n  to_fun_zero' := by simp [h],\n  to_fun_one' := by simp [h],\n  prop := by simp [h] }\n\n/--\nIf `f\u2080` and `f\u2081` are homotopic paths, and `F` is a continuous function, then the images of the paths\nare homotopic.\n-/\ndef map (h : path_homotopy f\u2080 f\u2081) (F : C(X, Y)) : path_homotopy (f\u2080.map F) (f\u2081.map F) :=\n{ to_fun := F.comp h,\n  to_fun_zero' := by simp,\n  to_fun_one' := by simp,\n  prop := \u03bb t, by simp } .\n\n/--\nA path `f\u2080` is homotopic to `f\u2080` joined to the constant path.\n-/\ndef trans_const (f\u2080 : path' x\u2080 x\u2081)  : path_homotopy f\u2080 (f\u2080.trans (path'.const x\u2081)) :=\n{ to_fun := \n  { to_fun := \u03bb p, f\u2080 (if p.1 \u2264 1/2 then (1 + p.2) * p.1 else (1 - p.2) * p.1 + p.2),\n    continuous_to_fun := begin\n      apply continuous.comp,\n      { continuity },\n      apply continuous.if; [skip, continuity, continuity],\n      { intros a ha,\n        rw mem_frontier_fst_le at ha,\n        rw ha,\n        linarith },\n    end },\n  to_fun_zero' := by norm_num,\n  to_fun_one' := \u03bb t, begin\n    simp only [path'.trans, one_div, path'.coe_apply, add_zero, mul_one, one_mul, path'.mk_apply, \n               path'.const_to_fun, continuous_map.coe_mk, zero_mul, zero_add, mul_zero, sub_self, \n               neg_zero],\n    split_ifs; norm_num,\n  end,\n  prop := \u03bb t, by norm_num } .\n\n/--\nA path `f\u2080` is homotopic to `f\u2080` joined to the constant path.\n-/\ndef const_trans (f\u2080 : path' x\u2080 x\u2081)  : path_homotopy f\u2080 ((path'.const x\u2080).trans f\u2080) :=\n{ to_fun := \n  { to_fun := \u03bb p, f\u2080 (if p.1 \u2264 1/2 then (1 - p.2) * p.1 else (1 + p.2) * p.1 - p.2),\n    continuous_to_fun := begin\n      apply continuous.comp,\n      { continuity },\n      apply continuous.if; [skip, continuity, continuity],\n      { intros a ha,\n        rw mem_frontier_fst_le at ha,\n        rw ha,\n        linarith }\n    end },\n  to_fun_zero' := by norm_num,\n  to_fun_one' := \u03bb t, begin\n    simp only [path'.trans, one_div, path'.coe_apply, add_zero, mul_one, one_mul, path'.mk_apply, \n               path'.const_to_fun, continuous_map.coe_mk, zero_mul, zero_add, neg_neg, mul_zero, \n               sub_self, neg_zero],\n    split_ifs; norm_num,\n  end,\n  prop := \u03bb t, by norm_num } .\n\n/--\nIf `f\u2080` and `g\u2080` are homotopic, and `f\u2081` and `g\u2081` are homotopic, then `f\u2080` joined with `f\u2081` is\nhomotopic to `g\u2080` joined to `g\u2081`.\n-/\ndef trans\u2082 {f\u2080 g\u2080 : path' x\u2080 x\u2081} {f\u2081 g\u2081 : path' x\u2081 x\u2082} (h\u2080 : path_homotopy f\u2080 g\u2080) (h\u2081 : path_homotopy f\u2081 g\u2081) :\n  path_homotopy (f\u2080.trans f\u2081) (g\u2080.trans g\u2081) :=\n{ to_fun := \n  { to_fun := \u03bb p, if p.1 \u2264 1/2 then h\u2080 (2 * p.1, p.2) else h\u2081 (2 * p.1 - 1, p.2),\n    continuous_to_fun := begin\n      apply continuous.if; [skip, continuity, continuity],\n      intros a ha,\n      rw mem_frontier_fst_le at ha,\n      norm_num [ha],\n    end },\n  to_fun_zero' := by simp [path'.trans],\n  to_fun_one' := by simp [path'.trans],\n  prop := \u03bb t, by norm_num } .\n\n/--\nIf `f` and `g` are homotopic paths, then their inverses are also homotopic.\n-/\ndef inv {f g : path' x\u2080 x\u2081} (h : path_homotopy f g) : path_homotopy f.inv g.inv :=\n{ to_fun := \n  { to_fun := \u03bb p, h (1 - p.1, p.2) },\n  to_fun_zero' := by norm_num [path'.inv],\n  to_fun_one' := by norm_num [path'.inv],\n  prop := by norm_num [path'.inv] }\n\nend lemmas\n\nsection assoc\n\nprivate def \u03b4 (\u03b3\u2080 : path' x\u2080 x\u2081) (\u03b3\u2081 : path' x\u2081 x\u2082) (\u03b3\u2082 : path' x\u2082 x\u2083) : C(\u211d, X) :=\n{ to_fun := \u03bb t, \n  if t \u2264 1/3 then\n    \u03b3\u2080 (3 * t)\n  else if t \u2264 2/3 then\n    \u03b3\u2081 (3 * t - 1)\n  else\n    \u03b3\u2082 (3 * t - 2),\n  continuous_to_fun := begin\n    apply continuous.if; [rintros a (ha : a \u2208 frontier (set.Iic (1/3 : \u211d))), continuity, skip],\n    { rw [frontier_Iic, set.mem_singleton_iff] at ha,\n      norm_num [ha] },\n    { apply continuous.if; [rintros b (hb : b \u2208 frontier (set.Iic (2/3 : \u211d))), continuity, continuity],\n      { rw [frontier_Iic, set.mem_singleton_iff] at hb,\n        norm_num [hb] } } \n  end } .\n\nprivate def f\u2080 : path' (0 : \u211d) 1 :=\n{ to_fun := \n  { to_fun := \u03bb t, if t \u2264 1/2 then 4/3 * t else 1/3 + 2/3 * t,\n    continuous_to_fun := begin\n      apply continuous.if; [rintros a (ha : a \u2208 frontier (set.Iic (1/2 : \u211d))), continuity, continuity],\n      rw [frontier_Iic, set.mem_singleton_iff] at ha,\n      norm_num [ha]\n    end },\n  to_fun_zero' := by norm_num,\n  to_fun_one' := by norm_num }\n\nprivate def f\u2081 : path' (0 : \u211d) 1 :=\n{ to_fun := \n  { to_fun := \u03bb t, if t \u2264 1/2 then 2/3 * t else -1/3 + 4/3 * t,\n    continuous_to_fun := begin\n      apply continuous.if; [rintros a (ha : a \u2208 frontier (set.Iic (1/2 : \u211d))), continuity, continuity],\n      rw [frontier_Iic, set.mem_singleton_iff] at ha,\n      norm_num [ha],\n    end },\n  to_fun_zero' := by norm_num,\n  to_fun_one' := by norm_num }\n\nprivate def path_homotopy_f\u2080_f\u2081 : path_homotopy f\u2080 f\u2081 :=\n{ to_fun := \n  { to_fun := \u03bb p, if p.1 \u2264 1/2 then 2/3 * p.1 * (2 - p.2) else 1/3 + 2/3 * p.1 - 2/3 * p.2 + 2/3 * p.1 * p.2,\n    continuous_to_fun := begin\n      apply continuous.if; [skip, continuity, continuity],\n      intros a ha,\n      rw mem_frontier_fst_le at ha,\n      rw ha,\n      linarith,\n    end },\n  to_fun_zero' := \u03bb x, begin\n    simp only [f\u2080, one_div, path'.coe_apply, add_zero, mul_one, one_mul, path'.mk_apply, \n               continuous_map.coe_mk, sub_zero, zero_add, neg_neg, mul_zero, neg_zero],\n    split_ifs; linarith\n  end,\n  to_fun_one' := \u03bb x, begin\n    simp only [f\u2081, path'.coe_apply, add_zero, mul_one, one_mul, path'.mk_apply, \n               continuous_map.coe_mk, zero_add, neg_neg, mul_zero, neg_zero],\n    split_ifs; linarith\n  end,\n  prop := \u03bb t, by norm_num }\n\nvariables {\u03b3\u2080 : path' x\u2080 x\u2081} {\u03b3\u2081 : path' x\u2081 x\u2082} {\u03b3\u2082 : path' x\u2082 x\u2083}\n\nprivate lemma f\u2080_map_\u03b4_eq : ((f\u2080.map (\u03b4 \u03b3\u2080 \u03b3\u2081 \u03b3\u2082)) : \u211d \u2192 X) = ((\u03b3\u2080.trans \u03b3\u2081).trans \u03b3\u2082) :=\nbegin\n  ext t,\n  unfold f\u2080 \u03b4 path'.trans,\n  simp only [\u03b4, path'.map, path'.coe_apply, path'.mk_apply, continuous_map.comp_coe, \n             continuous_map.coe_mk, function.comp_app, mul_ite],\n  split_ifs with h\u2081 h\u2082 h\u2083 h\u2084 h\u2085 h\u2086 h\u2087 h\u2088;\n    [apply congr_arg, exfalso, exfalso, apply congr_arg, exfalso, exfalso, exfalso, exfalso, \n     apply congr_arg]; linarith\nend .\n\nprivate lemma f\u2081_map_\u03b4_eq : (f\u2081.map (\u03b4 \u03b3\u2080 \u03b3\u2081 \u03b3\u2082) : \u211d \u2192 X) = (\u03b3\u2080.trans (\u03b3\u2081.trans \u03b3\u2082)) :=\nbegin\n  ext t,\n  unfold f\u2081 \u03b4 path'.trans,\n  simp only [\u03b4, path'.map, path'.coe_apply, path'.mk_apply, continuous_map.comp_coe, \n             continuous_map.coe_mk, function.comp_app, mul_ite],\n  split_ifs with h\u2081 h\u2082 h\u2083 h\u2084 h\u2085 h\u2086 h\u2087 h\u2088;\n    [apply congr_arg, exfalso, exfalso, exfalso, exfalso, apply congr_arg, exfalso, exfalso, \n     apply congr_arg]; linarith,\nend\n\n/--\nWhen dealing with `path_homotopy`s, sometimes we end up in a case where the end points have a\ndifferent type from what we expect.\n\nConsider for example if we had maps `f g : C(X, X)` such that `f x\u2080 = x\u2080` and `g x\u2081 = x\u2081`,\n(which can be proven, but is not true \"by definition\"). Then say if we had a homotopy between \n`p : path' x\u2080 x\u2081` and `q : path' x\u2080 x\u2081`, we can use this to define a homotopy between\n`p' : path' (f x\u2080) (g x\u2081)` and `q' : path' (f x\u2080) (g x\u2081)`, where `p'` as a function is the same\nas `p`, and `q'` as a function is the same as `q`.\n-/\ndef change_end_points {x\u2081 x\u2082 y\u2081 y\u2082 : X} {f\u2081 f\u2082 : path' x\u2081 x\u2082} {g\u2081 g\u2082 : path' y\u2081 y\u2082} \n  (h : path_homotopy f\u2081 f\u2082) (hfg\u2081 : (f\u2081 : \u211d \u2192 X) = g\u2081) (hfg\u2082 : (f\u2082 : \u211d \u2192 X) = g\u2082) : \n  path_homotopy g\u2081 g\u2082 :=\n{ to_fun := h,\n  to_fun_zero' := by simp [\u2190hfg\u2081],\n  to_fun_one' := by simp [\u2190hfg\u2082],\n  prop := \u03bb t, begin\n    simp only [to_fun_one, to_fun_zero, homotopy_with.coe_coe_apply_eq_coe],\n    split,\n    { simp [\u2190f\u2081.to_fun_zero, hfg\u2081, g\u2081.to_fun_zero] },\n    { simp [\u2190f\u2081.to_fun_one, hfg\u2081, g\u2081.to_fun_one] },\n  end }\n\n/--\nIf we have paths `\u03b3\u2080`, `\u03b3\u2081` and `\u03b3\u2082`, then the two paths formed by joined them in different ways\nare different, but there is a homotopy between them.\n-/\ndef assoc : path_homotopy ((\u03b3\u2080.trans \u03b3\u2081).trans \u03b3\u2082) (\u03b3\u2080.trans (\u03b3\u2081.trans \u03b3\u2082)) :=\n  (path_homotopy_f\u2080_f\u2081.map (\u03b4 \u03b3\u2080 \u03b3\u2081 \u03b3\u2082)).change_end_points f\u2080_map_\u03b4_eq f\u2081_map_\u03b4_eq\n\nend assoc\n\nsection inv\n\nvariable {f : path' x\u2080 x\u2081}\n\n/--\nA path joined to it's inverse is homotopic to the constant path.\n-/\ndef trans_right_inv : path_homotopy (f.trans f.inv) (path'.const x\u2080) :=\n{ to_fun := \n  { to_fun := \u03bb p, f (if p.1 \u2264 1/2 then 2 * p.1 * (1 - p.2) else (1 - p.2) * (2 - 2 * p.1)),\n    continuous_to_fun := begin\n      apply continuous.comp; [continuity, skip],\n      apply continuous.if; [skip, continuity, continuity],\n      intros a ha,\n      rw mem_frontier_fst_le at ha,\n      rw ha,\n      linarith,\n    end },\n  to_fun_zero' := \u03bb x, begin\n    unfold path'.trans path'.inv,\n    simp only [path'.coe_apply, add_zero, mul_one, one_mul, path'.mk_apply, continuous_map.coe_mk, \n               sub_zero, zero_add, neg_neg, neg_zero],\n    split_ifs; apply congr_arg; linarith\n  end,\n  to_fun_one' := by norm_num,\n  prop := \u03bb t, by norm_num }\n\n/--\nA path joined to it's inverse is homotopic to the constant path.\n-/\ndef trans_left_inv : path_homotopy (f.inv.trans f) (path'.const x\u2081) :=\n{ to_fun := \n  { to_fun := \u03bb p, f (if p.1 \u2264 1/2 then (1 - p.2) * (1 - 2 * p.1) + p.2 else (1 - p.2) * (2 * p.1 - 1) + p.2),\n    continuous_to_fun := begin\n      apply continuous.comp; [continuity, skip],\n      apply continuous.if; [skip, continuity, continuity],\n      intros a ha,\n      rw mem_frontier_fst_le at ha,\n      rw ha,\n      linarith,\n    end },\n  to_fun_zero' := \u03bb x, begin\n    unfold path'.trans path'.inv,\n    simp only [path'.coe_apply, add_zero, mul_one, one_mul, path'.mk_apply, continuous_map.coe_mk, \n               zero_mul, sub_zero, zero_add, mul_zero, neg_zero],\n    split_ifs; apply congr_arg; linarith\n  end,\n  to_fun_one' := by norm_num,\n  prop := \u03bb t, by norm_num }\n\nend inv\n\nend path_homotopy\n\n/--\nTwo paths are homotopic if there exists a homotopy between them.\n-/\ndef path_homotopic (f\u2080 f\u2081 : path' x\u2080 x\u2081) := nonempty (path_homotopy f\u2080 f\u2081)\n\nlemma path_homotopic.equiv : equivalence (@path_homotopic X _ x\u2080 x\u2081) :=\n\u27e8\u03bb p, \u27e8path_homotopy.refl p\u27e9, \u03bb f g \u27e8h\u27e9, \u27e8h.symm\u27e9, \u03bb f\u2080 f\u2081 f\u2082 \u27e8h\u2080\u27e9 \u27e8h\u2081\u27e9, \u27e8h\u2080.trans h\u2081\u27e9\u27e9\n", "meta": {"author": "shingtaklam1324", "repo": "alg-top", "sha": "4c88e28df6f0a329f26eab32bae023789193990e", "save_path": "github-repos/lean/shingtaklam1324-alg-top", "path": "github-repos/lean/shingtaklam1324-alg-top/alg-top-4c88e28df6f0a329f26eab32bae023789193990e/src/homotopy/path.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7132722112764571}}
{"text": "import tactic -- hide\n\n/-\n## Basic definition\n\nBelow we have one possible notion of being a subgroup. We will want to prove that\nthis definition matches the more natural one, and we will do so in this and the next levels.\n\nOn the left you will see a tab with theorems that you can use in your proofs. In this level\nyou will need to use `nonempty_of_subgroup` and `mul_inv_of_subgroup`, which follow\ndirectly from the definition of subgroup and are in fact the way that we will be able\nto access the definition.\n\nThroughout, you will find very useful the `group` tactic, which works like the powerful `ring`\ntactic but with equalities involving elements of a group.\n\nYou will need to type inverses, which are written using a superindex \"-1\". You type it as\n`\\-1`, and you will see how the `-1` appears as a superindex.\n-/\n\nvariables {G : Type} [group G] {H : set G} -- hide\n\n@[class] -- hide\ndef subgroup (X : set G) := X.nonempty \u2227 (\u2200 x y, x \u2208 X \u2192 y \u2208 X \u2192 x * y\u207b\u00b9 \u2208 X)\n\n/- Axiom: subgroup (X : set G)\nX.nonempty \u2227 (\u2200 x y, x \u2208 X \u2192 y \u2208 X \u2192 x * y\u207b\u00b9 \u2208 X)\n-/\n\nlemma nonempty_of_subgroup (X : set G) [h : subgroup X] : \u2203 x, x \u2208 X\n:= h.1 -- hide\n\n/- Axiom : nonempty_of_subgroup (X : set G) [subgroup X]\n\u2203 x, x \u2208 X\n-/\n\nlemma mul_inv_of_subgroup {X : set G} [h : subgroup X] {x y : G} (hx : x \u2208 X) (hy : y \u2208 X) : x * y\u207b\u00b9 \u2208 X\n:= h.2 x y hx hy -- hide\n\n/- Axiom : mul_inv_of_subgroup {X : set G} [h : subgroup X] {x y : G}\n(hx : x \u2208 X) (hy : y \u2208 X) :\nx * y\u207b\u00b9 \u2208 X\n-/\n\n/- Lemma:\nIf $H\\leq G$, then $1 \\in H$.\n-/\nlemma subgroup.one_mem [h : subgroup H]: (1 : G) \u2208 H :=\nbegin\n  cases h.1 with x hx,\n  have h2 :=  h.2 x x hx hx,\n  rw show (1 : G) = x * x\u207b\u00b9, by group,\n  assumption,\n\n\n\n\n\n\n\nend\n\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/subgroup_world/subgroup_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7132722079140873}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport algebra.polynomial.big_operators\nimport data.nat.choose.cast\nimport data.nat.choose.vandermonde\nimport data.polynomial.degree.lemmas\nimport data.polynomial.derivative\n\n/-!\n# Hasse derivative of polynomials\n\nThe `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt is a variant of the usual derivative, and satisfies `k! * (hasse_deriv k f) = derivative^[k] f`.\nThe main benefit is that is gives an atomic way of talking about expressions such as\n`(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example.\n\n## Main declarations\n\nIn the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`.\n\n* `polynomial.hasse_deriv`: the `k`-th Hasse derivative of a polynomial\n* `polynomial.hasse_deriv_zero`: the `0`th Hasse derivative is the identity\n* `polynomial.hasse_deriv_one`: the `1`st Hasse derivative is the usual derivative\n* `polynomial.factorial_smul_hasse_deriv`: the identity `k! \u2022 (D k f) = derivative^[k] f`\n* `polynomial.hasse_deriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k \u2022 D (k+l)`\n* `polynomial.hasse_deriv_mul`:\n  the \"Leibniz rule\" `D k (f * g) = \u2211 ij in antidiagonal k, D ij.1 f * D ij.2 g`\n\nFor the identity principle, see `polynomial.eq_zero_of_hasse_deriv_eq_zero`\nin `data/polynomial/taylor.lean`.\n\n## Reference\n\nhttps://math.fontein.de/2009/08/12/the-hasse-derivative/\n\n-/\n\nnoncomputable theory\n\nnamespace polynomial\n\nopen_locale nat big_operators\nopen function nat (hiding nsmul_eq_mul)\n\nvariables {R : Type*} [semiring R] (k : \u2115) (f : polynomial R)\n\n/-- The `k`th Hasse derivative of a polynomial `\u2211 a_i X^i` is `\u2211 (i.choose k) a_i X^(i-k)`.\nIt satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/\ndef hasse_deriv (k : \u2115) : polynomial R \u2192\u2097[R] polynomial R :=\nlsum (\u03bb i, (monomial (i-k)) \u2218\u2097 distrib_mul_action.to_linear_map R R (i.choose k))\n\nlemma hasse_deriv_apply :\n  hasse_deriv k f = f.sum (\u03bb i r, monomial (i - k) (\u2191(i.choose k) * r)) :=\nby simpa only [\u2190 nsmul_eq_mul]\n\nlemma hasse_deriv_coeff (n : \u2115) :\n  (hasse_deriv k f).coeff n = (n + k).choose k * f.coeff (n + k) :=\nbegin\n  rw [hasse_deriv_apply, coeff_sum, sum_def, finset.sum_eq_single (n + k), coeff_monomial],\n  { simp only [if_true, add_tsub_cancel_right, eq_self_iff_true], },\n  { intros i hi hink,\n    rw [coeff_monomial],\n    by_cases hik : i < k,\n    { simp only [nat.choose_eq_zero_of_lt hik, if_t_t, nat.cast_zero, zero_mul], },\n    { push_neg at hik, rw if_neg, contrapose! hink,\n      exact (tsub_eq_iff_eq_add_of_le hik).mp hink, } },\n  { intro h, simp only [not_mem_support_iff.mp h, monomial_zero_right, mul_zero, coeff_zero] }\nend\n\nlemma hasse_deriv_zero' : hasse_deriv 0 f = f :=\nby simp only [hasse_deriv_apply, tsub_zero, nat.choose_zero_right,\n  nat.cast_one, one_mul, sum_monomial_eq]\n\n@[simp] lemma hasse_deriv_zero : @hasse_deriv R _ 0 = linear_map.id :=\nlinear_map.ext $ hasse_deriv_zero'\n\nlemma hasse_deriv_eq_zero_of_lt_nat_degree (p : polynomial R) (n : \u2115)\n  (h : p.nat_degree < n) : hasse_deriv n p = 0 :=\nbegin\n  rw [hasse_deriv_apply, sum_def],\n  refine finset.sum_eq_zero (\u03bb x hx, _),\n  simp [nat.choose_eq_zero_of_lt ((le_nat_degree_of_mem_supp _ hx).trans_lt h)]\nend\n\nlemma hasse_deriv_one' : hasse_deriv 1 f = derivative f :=\nby simp only [hasse_deriv_apply, derivative_apply, monomial_eq_C_mul_X, nat.choose_one_right,\n    (nat.cast_commute _ _).eq]\n\n@[simp] lemma hasse_deriv_one : @hasse_deriv R _ 1 = derivative :=\nlinear_map.ext $ hasse_deriv_one'\n\n@[simp] lemma hasse_deriv_monomial (n : \u2115) (r : R) :\n  hasse_deriv k (monomial n r) = monomial (n - k) (\u2191(n.choose k) * r) :=\nbegin\n  ext i,\n  simp only [hasse_deriv_coeff, coeff_monomial],\n  by_cases hnik : n = i + k,\n  { rw [if_pos hnik, if_pos, \u2190 hnik], apply tsub_eq_of_eq_add_rev, rwa add_comm },\n  { rw [if_neg hnik, mul_zero],\n    by_cases hkn : k \u2264 n,\n    { rw [\u2190 tsub_eq_iff_eq_add_of_le hkn] at hnik, rw [if_neg hnik] },\n    { push_neg at hkn, rw [nat.choose_eq_zero_of_lt hkn, nat.cast_zero, zero_mul, if_t_t] } }\nend\n\nlemma hasse_deriv_C (r : R) (hk : 0 < k) : hasse_deriv k (C r) = 0 :=\nby rw [\u2190 monomial_zero_left, hasse_deriv_monomial, nat.choose_eq_zero_of_lt hk,\n    nat.cast_zero, zero_mul, monomial_zero_right]\n\nlemma hasse_deriv_apply_one (hk : 0 < k) : hasse_deriv k (1 : polynomial R) = 0 :=\nby rw [\u2190 C_1, hasse_deriv_C k _ hk]\n\nlemma hasse_deriv_X (hk : 1 < k) : hasse_deriv k (X : polynomial R) = 0 :=\nby rw [\u2190 monomial_one_one_eq_X, hasse_deriv_monomial, nat.choose_eq_zero_of_lt hk,\n    nat.cast_zero, zero_mul, monomial_zero_right]\n\nlemma factorial_smul_hasse_deriv :\n  \u21d1(k! \u2022 @hasse_deriv R _ k) = ((@derivative R _)^[k]) :=\nbegin\n  induction k with k ih,\n  { rw [hasse_deriv_zero, factorial_zero, iterate_zero, one_smul, linear_map.id_coe], },\n  ext f n : 2,\n  rw [iterate_succ_apply', \u2190 ih],\n  simp only [linear_map.smul_apply, coeff_smul, linear_map.map_smul_of_tower, coeff_derivative,\n    hasse_deriv_coeff, \u2190 @choose_symm_add _ k],\n  simp only [nsmul_eq_mul, factorial_succ, mul_assoc, succ_eq_add_one, \u2190 add_assoc,\n    add_right_comm n 1 k, \u2190 cast_succ],\n  rw \u2190 (cast_commute (n+1) (f.coeff (n + k + 1))).eq,\n  simp only [\u2190 mul_assoc], norm_cast, congr' 2,\n  apply @cast_injective \u211a,\n  have h1 : n + 1 \u2264 n + k + 1 := succ_le_succ le_self_add,\n  have h2 : k + 1 \u2264 n + k + 1 := succ_le_succ le_add_self,\n  have H : \u2200 (n : \u2115), (n! : \u211a) \u2260 0, { exact_mod_cast factorial_ne_zero },\n  -- why can't `field_simp` help me here?\n  simp only [cast_mul, cast_choose \u211a, h1, h2, -one_div, -mul_eq_zero,\n    succ_sub_succ_eq_sub, add_tsub_cancel_right, add_tsub_cancel_left] with field_simps,\n  rw [eq_div_iff_mul_eq (mul_ne_zero (H _) (H _)), eq_comm, div_mul_eq_mul_div,\n    eq_div_iff_mul_eq (mul_ne_zero (H _) (H _))],\n  norm_cast,\n  simp only [factorial_succ, succ_eq_add_one], ring,\nend\n\nlemma hasse_deriv_comp (k l : \u2115) :\n  (@hasse_deriv R _ k).comp (hasse_deriv l) = (k+l).choose k \u2022 hasse_deriv (k+l) :=\nbegin\n  ext i : 2,\n  simp only [linear_map.smul_apply, comp_app, linear_map.coe_comp, smul_monomial,\n    hasse_deriv_apply, mul_one, monomial_eq_zero_iff, sum_monomial_index, mul_zero,\n    \u2190 tsub_add_eq_tsub_tsub, add_comm l k],\n  rw_mod_cast nsmul_eq_mul,\n  congr' 2,\n  by_cases hikl : i < k + l,\n  { rw [choose_eq_zero_of_lt hikl, mul_zero],\n    by_cases hil : i < l,\n    { rw [choose_eq_zero_of_lt hil, mul_zero] },\n    { push_neg at hil, rw [\u2190 tsub_lt_iff_right hil] at hikl,\n      rw [choose_eq_zero_of_lt hikl , zero_mul], }, },\n  push_neg at hikl, apply @cast_injective \u211a,\n  have h1 : l \u2264 i     := nat.le_of_add_le_right hikl,\n  have h2 : k \u2264 i - l := le_tsub_of_add_le_right hikl,\n  have h3 : k \u2264 k + l := le_self_add,\n  have H : \u2200 (n : \u2115), (n! : \u211a) \u2260 0, { exact_mod_cast factorial_ne_zero },\n  -- why can't `field_simp` help me here?\n  simp only [cast_mul, cast_choose \u211a, h1, h2, h3, hikl, -one_div, -mul_eq_zero,\n    succ_sub_succ_eq_sub, add_tsub_cancel_right, add_tsub_cancel_left] with field_simps,\n  rw [eq_div_iff_mul_eq, eq_comm, div_mul_eq_mul_div, eq_div_iff_mul_eq, \u2190 tsub_add_eq_tsub_tsub,\n    add_comm l k],\n  { ring, },\n  all_goals { apply_rules [mul_ne_zero, H] }\nend\n\nlemma nat_degree_hasse_deriv_le (p : polynomial R) (n : \u2115) :\n  nat_degree (hasse_deriv n p) \u2264 nat_degree p - n :=\nbegin\n  classical,\n  rw [hasse_deriv_apply, sum_def],\n  refine (nat_degree_sum_le _ _).trans _,\n  simp_rw [function.comp, nat_degree_monomial],\n  rw [finset.fold_ite, finset.fold_const],\n  { simp only [if_t_t, max_eq_right, zero_le', finset.fold_max_le, true_and, and_imp,\n               tsub_le_iff_right, mem_support_iff, ne.def, finset.mem_filter],\n    intros x hx hx',\n    have hxp : x \u2264 p.nat_degree := le_nat_degree_of_ne_zero hx,\n    have hxn : n \u2264 x,\n    { contrapose! hx',\n      simp [nat.choose_eq_zero_of_lt hx'] },\n    rwa [tsub_add_cancel_of_le (hxn.trans hxp)] },\n  { simp }\nend\n\nlemma nat_degree_hasse_deriv [no_zero_smul_divisors \u2115 R] (p : polynomial R) (n : \u2115) :\n  nat_degree (hasse_deriv n p) = nat_degree p - n :=\nbegin\n  cases lt_or_le p.nat_degree n with hn hn,\n  { simpa [hasse_deriv_eq_zero_of_lt_nat_degree, hn] using (tsub_eq_zero_of_le hn.le).symm },\n  { refine map_nat_degree_eq_sub _ _,\n    { exact \u03bb h, hasse_deriv_eq_zero_of_lt_nat_degree _ _ },\n    { classical,\n      simp only [ite_eq_right_iff, ne.def, nat_degree_monomial, hasse_deriv_monomial],\n      intros k c c0 hh,\n      -- this is where we use the `smul_eq_zero` from `no_zero_smul_divisors`\n      rw [\u2190nsmul_eq_mul, smul_eq_zero, nat.choose_eq_zero_iff] at hh,\n      exact (tsub_eq_zero_of_le (or.resolve_right hh c0).le).symm } }\nend\n\nsection\nopen add_monoid_hom finset.nat\n\nlemma hasse_deriv_mul (f g : polynomial R) :\n  hasse_deriv k (f * g) = \u2211 ij in antidiagonal k, hasse_deriv ij.1 f * hasse_deriv ij.2 g :=\nbegin\n  let D := \u03bb k, (@hasse_deriv R _ k).to_add_monoid_hom,\n  let \u03a6 := @add_monoid_hom.mul (polynomial R) _,\n  show (comp_hom (D k)).comp \u03a6 f g =\n    \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, ((comp_hom.comp ((comp_hom \u03a6) (D ij.1))).flip (D ij.2) f) g,\n  simp only [\u2190 finset_sum_apply],\n  congr' 2, clear f g,\n  ext m r n s : 4,\n  simp only [finset_sum_apply, coe_mul_left, coe_comp, flip_apply, comp_app,\n    hasse_deriv_monomial, linear_map.to_add_monoid_hom_coe, comp_hom_apply_apply, coe_mul,\n    monomial_mul_monomial],\n  have aux : \u2200 (x : \u2115 \u00d7 \u2115), x \u2208 antidiagonal k \u2192\n    monomial (m - x.1 + (n - x.2)) (\u2191(m.choose x.1) * r * (\u2191(n.choose x.2) * s)) =\n    monomial (m + n - k) (\u2191(m.choose x.1) * \u2191(n.choose x.2) * (r * s)),\n  { intros x hx, rw [finset.nat.mem_antidiagonal] at hx, subst hx,\n    by_cases hm : m < x.1,\n    { simp only [nat.choose_eq_zero_of_lt hm, nat.cast_zero, zero_mul, monomial_zero_right], },\n    by_cases hn : n < x.2,\n    { simp only [nat.choose_eq_zero_of_lt hn, nat.cast_zero,\n        zero_mul, mul_zero, monomial_zero_right], },\n    push_neg at hm hn,\n    rw [tsub_add_eq_add_tsub hm, \u2190 add_tsub_assoc_of_le hn, \u2190 tsub_add_eq_tsub_tsub,\n      add_comm x.2 x.1, mul_assoc, \u2190 mul_assoc r, \u2190 (nat.cast_commute _ r).eq, mul_assoc,\n      mul_assoc], },\n  conv_rhs { apply_congr, skip, rw aux _ H, },\n  rw_mod_cast [\u2190 linear_map.map_sum, \u2190 finset.sum_mul, \u2190 nat.add_choose_eq],\nend\n\nend\n\nend polynomial\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/polynomial/hasse_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.7132283883068058}}
{"text": "import game.order.level06\nimport data.real.irrational\n\nopen real\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 7\n\nProve by example that there exist pairs of real numbers\n$a$ and $b$ such that $a \\in \\mathbb{R} \\setminus \\mathbb{Q}$, \n$b \\in \\mathbb{R} \\setminus \\mathbb{Q}$,\nbut their sum $a + b$ is a rational number, $(a+b) \\in \\mathbb{Q}$.\nYou may use this result in the Lean mathlib library:\n\n`irrational_sqrt_two : irrational (sqrt 2)`\n\n-/\n\n/- Axiom : irrational_sqrt_two : irrational (sqrt 2) \n\ntheorem irrational_neg_iff : irrational (-x) \u2194 irrational x \n\n.2 after irrational_neg_iff gives the left side of the biconditional\n\nexistsi in this case brings up 0 to the rational numbers.\n-/\n\n/- Lemma\nNot true that for any $a$, $b$, irrational numbers, the sum is \nalso an irrational number.\n-/\ntheorem not_sum_irrational : \n    \u00ac ( \u2200 (a b : \u211d), irrational a \u2192  irrational b \u2192 irrational (a+b) ) :=\nbegin\n  intro h,\n  have H := h (sqrt 2) (-sqrt 2),\n  have H3 := H irrational_sqrt_two (irrational_neg_iff.2 irrational_sqrt_two),\n  apply H3,\n  existsi (0 : \u211a),\n  simp,\nend\n\nend xena -- hide\n\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/order/level07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7132283851990647}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, S\u00e9bastien Gou\u00ebzel,\n  R\u00e9my Degenne, David Loeffler\n-/\nimport analysis.special_functions.complex.log\n\n/-!\n# Power function on `\u2102`, `\u211d`, `\u211d\u22650`, and `\u211d\u22650\u221e`\n\nWe construct the power functions `x ^ y` where\n* `x` and `y` are complex numbers,\n* or `x` and `y` are real numbers,\n* or `x` is a nonnegative real number and `y` is a real number;\n* or `x` is a number from `[0, +\u221e]` (a.k.a. `\u211d\u22650\u221e`) and `y` is a real number.\n\nWe also prove basic properties of these functions.\n-/\n\nnoncomputable theory\n\nopen_locale classical real topology nnreal ennreal filter big_operators complex_conjugate\nopen filter finset set\n\nnamespace complex\n\n/-- The complex power function `x^y`, given by `x^y = exp(y log x)` (where `log` is the principal\ndetermination of the logarithm), unless `x = 0` where one sets `0^0 = 1` and `0^y = 0` for\n`y \u2260 0`. -/\nnoncomputable def cpow (x y : \u2102) : \u2102 :=\nif x = 0\n  then if y = 0\n    then 1\n    else 0\n  else exp (log x * y)\n\nnoncomputable instance : has_pow \u2102 \u2102 := \u27e8cpow\u27e9\n\n@[simp] lemma cpow_eq_pow (x y : \u2102) : cpow x y = x ^ y := rfl\n\nlemma cpow_def (x y : \u2102) : x ^ y =\n  if x = 0\n    then if y = 0\n      then 1\n      else 0\n    else exp (log x * y) := rfl\n\nlemma cpow_def_of_ne_zero {x : \u2102} (hx : x \u2260 0) (y : \u2102) : x ^ y = exp (log x * y) := if_neg hx\n\n@[simp] lemma cpow_zero (x : \u2102) : x ^ (0 : \u2102) = 1 := by simp [cpow_def]\n\n@[simp] lemma cpow_eq_zero_iff (x y : \u2102) : x ^ y = 0 \u2194 x = 0 \u2227 y \u2260 0 :=\nby { simp only [cpow_def], split_ifs; simp [*, exp_ne_zero] }\n\n@[simp] lemma zero_cpow {x : \u2102} (h : x \u2260 0) : (0 : \u2102) ^ x = 0 :=\nby simp [cpow_def, *]\n\nlemma zero_cpow_eq_iff {x : \u2102} {a : \u2102} : 0 ^ x = a \u2194 (x \u2260 0 \u2227 a = 0) \u2228 (x = 0 \u2227 a = 1) :=\nbegin\n  split,\n  { intros hyp,\n    simp only [cpow_def, eq_self_iff_true, if_true] at hyp,\n    by_cases x = 0,\n    { subst h, simp only [if_true, eq_self_iff_true] at hyp, right, exact \u27e8rfl, hyp.symm\u27e9},\n    { rw if_neg h at hyp, left, exact \u27e8h, hyp.symm\u27e9, }, },\n  { rintro (\u27e8h, rfl\u27e9|\u27e8rfl,rfl\u27e9),\n    { exact zero_cpow h, },\n    { exact cpow_zero _, }, },\nend\n\nlemma eq_zero_cpow_iff {x : \u2102} {a : \u2102} : a = 0 ^ x \u2194 (x \u2260 0 \u2227 a = 0) \u2228 (x = 0 \u2227 a = 1) :=\nby rw [\u2190zero_cpow_eq_iff, eq_comm]\n\n@[simp] lemma cpow_one (x : \u2102) : x ^ (1 : \u2102) = x :=\nif hx : x = 0 then by simp [hx, cpow_def]\nelse by rw [cpow_def, if_neg (one_ne_zero : (1 : \u2102) \u2260 0), if_neg hx, mul_one, exp_log hx]\n\n@[simp] lemma one_cpow (x : \u2102) : (1 : \u2102) ^ x = 1 :=\nby rw cpow_def; split_ifs; simp [one_ne_zero, *] at *\n\nlemma cpow_add {x : \u2102} (y z : \u2102) (hx : x \u2260 0) : x ^ (y + z) = x ^ y * x ^ z :=\nby simp only [cpow_def, ite_mul, boole_mul, mul_ite, mul_boole]; simp [*, exp_add, mul_add] at *\n\nlemma cpow_mul {x y : \u2102} (z : \u2102) (h\u2081 : -\u03c0 < (log x * y).im) (h\u2082 : (log x * y).im \u2264 \u03c0) :\n  x ^ (y * z) = (x ^ y) ^ z :=\nbegin\n  simp only [cpow_def],\n  split_ifs;\n  simp [*, exp_ne_zero, log_exp h\u2081 h\u2082, mul_assoc] at *\nend\n\nlemma cpow_neg (x y : \u2102) : x ^ -y = (x ^ y)\u207b\u00b9 :=\nby simp only [cpow_def, neg_eq_zero, mul_neg]; split_ifs; simp [exp_neg]\n\nlemma cpow_sub {x : \u2102} (y z : \u2102) (hx : x \u2260 0) : x ^ (y - z) = x ^ y / x ^ z :=\nby rw [sub_eq_add_neg, cpow_add _ _ hx, cpow_neg, div_eq_mul_inv]\n\nlemma cpow_neg_one (x : \u2102) : x ^ (-1 : \u2102) = x\u207b\u00b9 :=\nby simpa using cpow_neg x 1\n\n@[simp, norm_cast] lemma cpow_nat_cast (x : \u2102) : \u2200 (n : \u2115), x ^ (n : \u2102) = x ^ n\n| 0       := by simp\n| (n + 1) := if hx : x = 0 then by simp only [hx, pow_succ,\n    complex.zero_cpow (nat.cast_ne_zero.2 (nat.succ_ne_zero _)), zero_mul]\n  else by simp [cpow_add, hx, pow_add, cpow_nat_cast n]\n\n@[simp] lemma cpow_two (x : \u2102) : x ^ (2 : \u2102) = x ^ 2 :=\nby { rw \u2190 cpow_nat_cast, simp only [nat.cast_bit0, nat.cast_one] }\n\n@[simp, norm_cast] lemma cpow_int_cast (x : \u2102) : \u2200 (n : \u2124), x ^ (n : \u2102) = x ^ n\n| (n : \u2115) := by simp\n| -[1+ n] := by rw zpow_neg_succ_of_nat;\n  simp only [int.neg_succ_of_nat_coe, int.cast_neg, complex.cpow_neg, inv_eq_one_div,\n    int.cast_coe_nat, cpow_nat_cast]\n\nlemma cpow_nat_inv_pow (x : \u2102) {n : \u2115} (hn : n \u2260 0) : (x ^ (n\u207b\u00b9 : \u2102)) ^ n = x :=\nbegin\n  suffices : im (log x * n\u207b\u00b9) \u2208 Ioc (-\u03c0) \u03c0,\n  { rw [\u2190 cpow_nat_cast, \u2190 cpow_mul _ this.1 this.2, inv_mul_cancel, cpow_one],\n    exact_mod_cast hn },\n  rw [mul_comm, \u2190 of_real_nat_cast, \u2190 of_real_inv, of_real_mul_im, \u2190 div_eq_inv_mul],\n  rw [\u2190 pos_iff_ne_zero] at hn,\n  have hn' : 0 < (n : \u211d), by assumption_mod_cast,\n  have hn1 : 1 \u2264 (n : \u211d), by exact_mod_cast (nat.succ_le_iff.2 hn),\n  split,\n  { rw lt_div_iff hn',\n    calc -\u03c0 * n \u2264 -\u03c0 * 1 : mul_le_mul_of_nonpos_left hn1 (neg_nonpos.2 real.pi_pos.le)\n    ... = -\u03c0 : mul_one _\n    ... < im (log x) : neg_pi_lt_log_im _ },\n  { rw div_le_iff hn',\n    calc im (log x) \u2264 \u03c0 : log_im_le_pi _\n    ... = \u03c0 * 1 : (mul_one \u03c0).symm\n    ... \u2264 \u03c0 * n : mul_le_mul_of_nonneg_left hn1 real.pi_pos.le }\nend\n\nlemma mul_cpow_of_real_nonneg {a b : \u211d} (ha : 0 \u2264 a) (hb : 0 \u2264 b) (r : \u2102) :\n  ((a : \u2102) * (b : \u2102)) ^ r = (a : \u2102) ^ r * (b : \u2102) ^ r :=\nbegin\n  rcases eq_or_ne r 0 with rfl | hr,\n  { simp only [cpow_zero, mul_one] },\n  rcases eq_or_lt_of_le ha with rfl | ha',\n  { rw [of_real_zero, zero_mul, zero_cpow hr, zero_mul] },\n  rcases eq_or_lt_of_le hb with rfl | hb',\n  { rw [of_real_zero, mul_zero, zero_cpow hr, mul_zero] },\n  have ha'' : (a : \u2102) \u2260 0 := of_real_ne_zero.mpr ha'.ne',\n  have hb'' : (b : \u2102) \u2260 0 := of_real_ne_zero.mpr hb'.ne',\n  rw [cpow_def_of_ne_zero (mul_ne_zero ha'' hb''), log_of_real_mul ha' hb'', of_real_log ha,\n    add_mul, exp_add, \u2190cpow_def_of_ne_zero ha'', \u2190cpow_def_of_ne_zero hb'']\nend\n\nend complex\n\nsection lim\n\nopen complex\n\nvariables {\u03b1 : Type*}\n\nlemma zero_cpow_eq_nhds {b : \u2102} (hb : b \u2260 0) :\n  (\u03bb (x : \u2102), (0 : \u2102) ^ x) =\u1da0[\ud835\udcdd b] 0 :=\nbegin\n  suffices : \u2200\u1da0 (x : \u2102) in (\ud835\udcdd b), x \u2260 0,\n  from this.mono (\u03bb x hx, by { dsimp only, rw [zero_cpow hx, pi.zero_apply]} ),\n  exact is_open.eventually_mem is_open_ne hb,\nend\n\nlemma cpow_eq_nhds {a b : \u2102} (ha : a \u2260 0) :\n  (\u03bb x, x ^ b) =\u1da0[\ud835\udcdd a] \u03bb x, exp (log x * b) :=\nbegin\n  suffices : \u2200\u1da0 (x : \u2102) in (\ud835\udcdd a), x \u2260 0,\n    from this.mono (\u03bb x hx, by { dsimp only, rw [cpow_def_of_ne_zero hx], }),\n  exact is_open.eventually_mem is_open_ne ha,\nend\n\nlemma cpow_eq_nhds' {p : \u2102 \u00d7 \u2102} (hp_fst : p.fst \u2260 0) :\n  (\u03bb x, x.1 ^ x.2) =\u1da0[\ud835\udcdd p] \u03bb x, exp (log x.1 * x.2) :=\nbegin\n  suffices : \u2200\u1da0 (x : \u2102 \u00d7 \u2102) in (\ud835\udcdd p), x.1 \u2260 0,\n    from this.mono (\u03bb x hx, by { dsimp only, rw cpow_def_of_ne_zero hx, }),\n  refine is_open.eventually_mem _ hp_fst,\n  change is_open {x : \u2102 \u00d7 \u2102 | x.1 = 0}\u1d9c,\n  rw is_open_compl_iff,\n  exact is_closed_eq continuous_fst continuous_const,\nend\n\n/- Continuity of `\u03bb x, a ^ x`: union of these two lemmas is optimal. -/\n\nlemma continuous_at_const_cpow {a b : \u2102} (ha : a \u2260 0) : continuous_at (\u03bb x, a ^ x) b :=\nbegin\n  have cpow_eq : (\u03bb x:\u2102, a ^ x) = \u03bb x, exp (log a * x),\n    by { ext1 b, rw [cpow_def_of_ne_zero ha], },\n  rw cpow_eq,\n  exact continuous_exp.continuous_at.comp (continuous_at.mul continuous_at_const continuous_at_id),\nend\n\nlemma continuous_at_const_cpow' {a b : \u2102} (h : b \u2260 0) : continuous_at (\u03bb x, a ^ x) b :=\nbegin\n  by_cases ha : a = 0,\n  { rw [ha, continuous_at_congr (zero_cpow_eq_nhds h)], exact continuous_at_const, },\n  { exact continuous_at_const_cpow ha, },\nend\n\n/-- The function `z ^ w` is continuous in `(z, w)` provided that `z` does not belong to the interval\n`(-\u221e, 0]` on the real line. See also `complex.continuous_at_cpow_zero_of_re_pos` for a version that\nworks for `z = 0` but assumes `0 < re w`. -/\nlemma continuous_at_cpow {p : \u2102 \u00d7 \u2102} (hp_fst : 0 < p.fst.re \u2228 p.fst.im \u2260 0) :\n  continuous_at (\u03bb x : \u2102 \u00d7 \u2102, x.1 ^ x.2) p :=\nbegin\n  have hp_fst_ne_zero : p.fst \u2260 0,\n    by { intro h, cases hp_fst; { rw h at hp_fst, simpa using hp_fst, }, },\n  rw continuous_at_congr (cpow_eq_nhds' hp_fst_ne_zero),\n  refine continuous_exp.continuous_at.comp _,\n  refine continuous_at.mul (continuous_at.comp _ continuous_fst.continuous_at)\n    continuous_snd.continuous_at,\n  exact continuous_at_clog hp_fst,\nend\n\nlemma continuous_at_cpow_const {a b : \u2102} (ha : 0 < a.re \u2228 a.im \u2260 0) :\n  continuous_at (\u03bb x, cpow x b) a :=\ntendsto.comp (@continuous_at_cpow (a, b) ha) (continuous_at_id.prod continuous_at_const)\n\nlemma filter.tendsto.cpow {l : filter \u03b1} {f g : \u03b1 \u2192 \u2102} {a b : \u2102} (hf : tendsto f l (\ud835\udcdd a))\n  (hg : tendsto g l (\ud835\udcdd b)) (ha : 0 < a.re \u2228 a.im \u2260 0) :\n  tendsto (\u03bb x, f x ^ g x) l (\ud835\udcdd (a ^ b)) :=\n(@continuous_at_cpow (a,b) ha).tendsto.comp (hf.prod_mk_nhds hg)\n\nlemma filter.tendsto.const_cpow {l : filter \u03b1} {f : \u03b1 \u2192 \u2102} {a b : \u2102} (hf : tendsto f l (\ud835\udcdd b))\n  (h : a \u2260 0 \u2228 b \u2260 0) :\n  tendsto (\u03bb x, a ^ f x) l (\ud835\udcdd (a ^ b)) :=\nbegin\n  cases h,\n  { exact (continuous_at_const_cpow h).tendsto.comp hf, },\n  { exact (continuous_at_const_cpow' h).tendsto.comp hf, },\nend\n\nvariables [topological_space \u03b1] {f g : \u03b1 \u2192 \u2102} {s : set \u03b1} {a : \u03b1}\n\nlemma continuous_within_at.cpow (hf : continuous_within_at f s a) (hg : continuous_within_at g s a)\n  (h0 : 0 < (f a).re \u2228 (f a).im \u2260 0) :\n  continuous_within_at (\u03bb x, f x ^ g x) s a :=\nhf.cpow hg h0\n\nlemma continuous_within_at.const_cpow {b : \u2102} (hf : continuous_within_at f s a)\n  (h : b \u2260 0 \u2228 f a \u2260 0) :\n  continuous_within_at (\u03bb x, b ^ f x) s a :=\nhf.const_cpow h\n\nlemma continuous_at.cpow (hf : continuous_at f a) (hg : continuous_at g a)\n  (h0 : 0 < (f a).re \u2228 (f a).im \u2260 0) :\n  continuous_at (\u03bb x, f x ^ g x) a :=\nhf.cpow hg h0\n\nlemma continuous_at.const_cpow {b : \u2102} (hf : continuous_at f a) (h : b \u2260 0 \u2228 f a \u2260 0) :\n  continuous_at (\u03bb x, b ^ f x) a :=\nhf.const_cpow h\n\nlemma continuous_on.cpow (hf : continuous_on f s) (hg : continuous_on g s)\n  (h0 : \u2200 a \u2208 s, 0 < (f a).re \u2228 (f a).im \u2260 0) :\n  continuous_on (\u03bb x, f x ^ g x) s :=\n\u03bb a ha, (hf a ha).cpow (hg a ha) (h0 a ha)\n\nlemma continuous_on.const_cpow {b : \u2102} (hf : continuous_on f s) (h : b \u2260 0 \u2228 \u2200 a \u2208 s, f a \u2260 0) :\n  continuous_on (\u03bb x, b ^ f x) s :=\n\u03bb a ha, (hf a ha).const_cpow (h.imp id $ \u03bb h, h a ha)\n\nlemma continuous.cpow (hf : continuous f) (hg : continuous g)\n  (h0 : \u2200 a, 0 < (f a).re \u2228 (f a).im \u2260 0) :\n  continuous (\u03bb x, f x ^ g x) :=\ncontinuous_iff_continuous_at.2 $ \u03bb a, (hf.continuous_at.cpow hg.continuous_at (h0 a))\n\nlemma continuous.const_cpow {b : \u2102} (hf : continuous f) (h : b \u2260 0 \u2228 \u2200 a, f a \u2260 0) :\n  continuous (\u03bb x, b ^ f x) :=\ncontinuous_iff_continuous_at.2 $ \u03bb a, (hf.continuous_at.const_cpow $ h.imp id $ \u03bb h, h a)\n\nlemma continuous_on.cpow_const {b : \u2102} (hf : continuous_on f s)\n  (h : \u2200 (a : \u03b1), a \u2208 s \u2192 0 < (f a).re \u2228 (f a).im \u2260 0) :\n  continuous_on (\u03bb x, (f x) ^ b) s :=\nhf.cpow continuous_on_const h\n\nend lim\n\nnamespace real\n\n/-- The real power function `x^y`, defined as the real part of the complex power function.\nFor `x > 0`, it is equal to `exp(y log x)`. For `x = 0`, one sets `0^0=1` and `0^y=0` for `y \u2260 0`.\nFor `x < 0`, the definition is somewhat arbitary as it depends on the choice of a complex\ndetermination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (\u03c0y)`. -/\nnoncomputable def rpow (x y : \u211d) := ((x : \u2102) ^ (y : \u2102)).re\n\nnoncomputable instance : has_pow \u211d \u211d := \u27e8rpow\u27e9\n\n@[simp] lemma rpow_eq_pow (x y : \u211d) : rpow x y = x ^ y := rfl\n\nlemma rpow_def (x y : \u211d) : x ^ y = ((x : \u2102) ^ (y : \u2102)).re := rfl\n\nlemma rpow_def_of_nonneg {x : \u211d} (hx : 0 \u2264 x) (y : \u211d) : x ^ y =\n  if x = 0\n    then if y = 0\n      then 1\n      else 0\n    else exp (log x * y) :=\nby simp only [rpow_def, complex.cpow_def];\n  split_ifs;\n  simp [*, (complex.of_real_log hx).symm, -complex.of_real_mul, -is_R_or_C.of_real_mul,\n    (complex.of_real_mul _ _).symm, complex.exp_of_real_re] at *\n\nlemma rpow_def_of_pos {x : \u211d} (hx : 0 < x) (y : \u211d) : x ^ y = exp (log x * y) :=\nby rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]\n\nlemma exp_mul (x y : \u211d) : exp (x * y) = (exp x) ^ y :=\nby rw [rpow_def_of_pos (exp_pos _), log_exp]\n\n@[simp] lemma exp_one_rpow (x : \u211d) : exp 1 ^ x = exp x := by rw [\u2190exp_mul, one_mul]\n\nlemma rpow_eq_zero_iff_of_nonneg {x y : \u211d} (hx : 0 \u2264 x) : x ^ y = 0 \u2194 x = 0 \u2227 y \u2260 0 :=\nby { simp only [rpow_def_of_nonneg hx], split_ifs; simp [*, exp_ne_zero] }\n\nopen_locale real\n\nlemma rpow_def_of_neg {x : \u211d} (hx : x < 0) (y : \u211d) : x ^ y = exp (log x * y) * cos (y * \u03c0) :=\nbegin\n  rw [rpow_def, complex.cpow_def, if_neg],\n  have : complex.log x * y = \u2191(log(-x) * y) + \u2191(y * \u03c0) * complex.I,\n  { simp only [complex.log, abs_of_neg hx, complex.arg_of_real_of_neg hx,\n      complex.abs_of_real, complex.of_real_mul], ring },\n  { rw [this, complex.exp_add_mul_I, \u2190 complex.of_real_exp, \u2190 complex.of_real_cos,\n      \u2190 complex.of_real_sin, mul_add, \u2190 complex.of_real_mul, \u2190 mul_assoc, \u2190 complex.of_real_mul,\n      complex.add_re, complex.of_real_re, complex.mul_re, complex.I_re, complex.of_real_im,\n      real.log_neg_eq_log],\n    ring },\n  { rw complex.of_real_eq_zero, exact ne_of_lt hx }\nend\n\nlemma rpow_def_of_nonpos {x : \u211d} (hx : x \u2264 0) (y : \u211d) : x ^ y =\n  if x = 0\n    then if y = 0\n      then 1\n      else 0\n    else exp (log x * y) * cos (y * \u03c0) :=\nby split_ifs; simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _\n\nlemma rpow_pos_of_pos {x : \u211d} (hx : 0 < x) (y : \u211d) : 0 < x ^ y :=\nby rw rpow_def_of_pos hx; apply exp_pos\n\n@[simp] lemma rpow_zero (x : \u211d) : x ^ (0 : \u211d) = 1 := by simp [rpow_def]\n\n@[simp] lemma zero_rpow {x : \u211d} (h : x \u2260 0) : (0 : \u211d) ^ x = 0 :=\nby simp [rpow_def, *]\n\nlemma zero_rpow_eq_iff {x : \u211d} {a : \u211d} : 0 ^ x = a \u2194 (x \u2260 0 \u2227 a = 0) \u2228 (x = 0 \u2227 a = 1) :=\nbegin\n  split,\n  { intros hyp,\n    simp only [rpow_def, complex.of_real_zero] at hyp,\n    by_cases x = 0,\n    { subst h,\n      simp only [complex.one_re, complex.of_real_zero, complex.cpow_zero] at hyp,\n      exact or.inr \u27e8rfl, hyp.symm\u27e9},\n    { rw complex.zero_cpow (complex.of_real_ne_zero.mpr h) at hyp,\n      exact or.inl \u27e8h, hyp.symm\u27e9, }, },\n  { rintro (\u27e8h,rfl\u27e9|\u27e8rfl,rfl\u27e9),\n    { exact zero_rpow h, },\n    { exact rpow_zero _, }, },\nend\n\nlemma eq_zero_rpow_iff {x : \u211d} {a : \u211d} : a = 0 ^ x \u2194 (x \u2260 0 \u2227 a = 0) \u2228 (x = 0 \u2227 a = 1) :=\nby rw [\u2190zero_rpow_eq_iff, eq_comm]\n\n@[simp] lemma rpow_one (x : \u211d) : x ^ (1 : \u211d) = x := by simp [rpow_def]\n\n@[simp] lemma one_rpow (x : \u211d) : (1 : \u211d) ^ x = 1 := by simp [rpow_def]\n\nlemma zero_rpow_le_one (x : \u211d) : (0 : \u211d) ^ x \u2264 1 :=\nby { by_cases h : x = 0; simp [h, zero_le_one] }\n\nlemma zero_rpow_nonneg (x : \u211d) : 0 \u2264 (0 : \u211d) ^ x :=\nby { by_cases h : x = 0; simp [h, zero_le_one] }\n\nlemma rpow_nonneg_of_nonneg {x : \u211d} (hx : 0 \u2264 x) (y : \u211d) : 0 \u2264 x ^ y :=\nby rw [rpow_def_of_nonneg hx];\n  split_ifs; simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)]\n\nlemma abs_rpow_of_nonneg {x y : \u211d} (hx_nonneg : 0 \u2264 x) : |x ^ y| = |x| ^ y :=\nbegin\n  have h_rpow_nonneg : 0 \u2264 x ^ y, from real.rpow_nonneg_of_nonneg hx_nonneg _,\n  rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg],\nend\n\nlemma abs_rpow_le_abs_rpow (x y : \u211d) : |x ^ y| \u2264 |x| ^ y :=\nbegin\n  cases le_or_lt 0 x with hx hx,\n  { rw [abs_rpow_of_nonneg hx] },\n  { rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log,\n      abs_mul, abs_of_pos (exp_pos _)],\n    exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) }\nend\n\nlemma abs_rpow_le_exp_log_mul (x y : \u211d) : |x ^ y| \u2264 exp (log x * y) :=\nbegin\n  refine (abs_rpow_le_abs_rpow x y).trans _,\n  by_cases hx : x = 0,\n  { by_cases hy : y = 0; simp [hx, hy, zero_le_one] },\n  { rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] }\nend\n\nlemma norm_rpow_of_nonneg {x y : \u211d} (hx_nonneg : 0 \u2264 x) : \u2016x ^ y\u2016 = \u2016x\u2016 ^ y :=\nby { simp_rw real.norm_eq_abs, exact abs_rpow_of_nonneg hx_nonneg, }\n\nend real\n\nnamespace complex\n\nlemma of_real_cpow {x : \u211d} (hx : 0 \u2264 x) (y : \u211d) : ((x ^ y : \u211d) : \u2102) = (x : \u2102) ^ (y : \u2102) :=\nby simp only [real.rpow_def_of_nonneg hx, complex.cpow_def, of_real_eq_zero]; split_ifs;\n  simp [complex.of_real_log hx]\n\nlemma of_real_cpow_of_nonpos {x : \u211d} (hx : x \u2264 0) (y : \u2102) :\n  (x : \u2102) ^ y = ((-x) : \u2102) ^ y * exp (\u03c0 * I * y) :=\nbegin\n  rcases hx.eq_or_lt with rfl|hlt,\n  { rcases eq_or_ne y 0 with rfl|hy; simp * },\n  have hne : (x : \u2102) \u2260 0, from of_real_ne_zero.mpr hlt.ne,\n  rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), \u2190 exp_add, \u2190 add_mul,\n      log, log, abs.map_neg, arg_of_real_of_neg hlt, \u2190 of_real_neg,\n      arg_of_real_of_nonneg (neg_nonneg.2 hx), of_real_zero, zero_mul, add_zero]\nend\n\nlemma abs_cpow_of_ne_zero {z : \u2102} (hz : z \u2260 0) (w : \u2102) :\n  abs (z ^ w) = abs z ^ w.re / real.exp (arg z * im w) :=\nby rw [cpow_def_of_ne_zero hz, abs_exp, mul_re, log_re, log_im, real.exp_sub,\n  real.rpow_def_of_pos (abs.pos hz)]\n\nlemma abs_cpow_of_imp {z w : \u2102} (h : z = 0 \u2192 w.re = 0 \u2192 w = 0) :\n  abs (z ^ w) = abs z ^ w.re / real.exp (arg z * im w) :=\nbegin\n  rcases ne_or_eq z 0 with hz|rfl; [exact (abs_cpow_of_ne_zero hz w), rw map_zero],\n  cases eq_or_ne w.re 0 with hw hw,\n  { simp [hw, h rfl hw] },\n  { rw [real.zero_rpow hw, zero_div, zero_cpow, map_zero],\n    exact ne_of_apply_ne re hw }\nend\n\nlemma abs_cpow_le (z w : \u2102) : abs (z ^ w) \u2264 abs z ^ w.re / real.exp (arg z * im w) :=\nbegin\n  rcases ne_or_eq z 0 with hz|rfl; [exact (abs_cpow_of_ne_zero hz w).le, rw map_zero],\n  rcases eq_or_ne w 0 with rfl|hw, { simp },\n  rw [zero_cpow hw, map_zero],\n  exact div_nonneg (real.rpow_nonneg_of_nonneg le_rfl _) (real.exp_pos _).le\nend\n\nsection\n\nvariables {\u03b1 : Type*} {l : filter \u03b1} {f g : \u03b1 \u2192 \u2102}\n\nopen asymptotics\n\nlemma is_Theta_exp_arg_mul_im (hl : is_bounded_under (\u2264) l (\u03bb x, |(g x).im|)) :\n  (\u03bb x, real.exp (arg (f x) * im (g x))) =\u0398[l] (\u03bb x, (1 : \u211d)) :=\nbegin\n  rcases hl with \u27e8b, hb\u27e9,\n  refine real.is_Theta_exp_comp_one.2 \u27e8\u03c0 * b, _\u27e9,\n  rw eventually_map at hb \u22a2,\n  refine hb.mono (\u03bb x hx, _),\n  erw [abs_mul],\n  exact mul_le_mul (abs_arg_le_pi _) hx (abs_nonneg _) real.pi_pos.le\nend\n\nlemma is_O_cpow_rpow (hl : is_bounded_under (\u2264) l (\u03bb x, |(g x).im|)) :\n  (\u03bb x, f x ^ g x) =O[l] (\u03bb x, abs (f x) ^ (g x).re) :=\ncalc (\u03bb x, f x ^ g x) =O[l] (\u03bb x, abs (f x) ^ (g x).re / real.exp (arg (f x) * im (g x))) :\n  is_O_of_le _ $ \u03bb x, (abs_cpow_le _ _).trans (le_abs_self _)\n... =\u0398[l] (\u03bb x, abs (f x) ^ (g x).re / (1 : \u211d)) :\n  (is_Theta_refl _ _).div (is_Theta_exp_arg_mul_im hl)\n... =\u1da0[l] (\u03bb x, abs (f x) ^ (g x).re) : by simp only [of_real_one, div_one]\n\nlemma is_Theta_cpow_rpow (hl_im : is_bounded_under (\u2264) l (\u03bb x, |(g x).im|))\n  (hl : \u2200\u1da0 x in l, f x = 0 \u2192 re (g x) = 0 \u2192 g x = 0):\n  (\u03bb x, f x ^ g x) =\u0398[l] (\u03bb x, abs (f x) ^ (g x).re) :=\ncalc (\u03bb x, f x ^ g x) =\u0398[l] (\u03bb x, abs (f x) ^ (g x).re / real.exp (arg (f x) * im (g x))) :\n  is_Theta_of_norm_eventually_eq' $ hl.mono $ \u03bb x, abs_cpow_of_imp\n... =\u0398[l] (\u03bb x, abs (f x) ^ (g x).re / (1 : \u211d)) :\n  (is_Theta_refl _ _).div (is_Theta_exp_arg_mul_im hl_im)\n... =\u1da0[l] (\u03bb x, abs (f x) ^ (g x).re) : by simp only [of_real_one, div_one]\n\nlemma is_Theta_cpow_const_rpow {b : \u2102} (hl : b.re = 0 \u2192 b \u2260 0 \u2192 \u2200\u1da0 x in l, f x \u2260 0) :\n  (\u03bb x, f x ^ b) =\u0398[l] (\u03bb x, abs (f x) ^ b.re) :=\nis_Theta_cpow_rpow is_bounded_under_const $ by simpa only [eventually_imp_distrib_right, ne.def,\n  \u2190 not_frequently, not_imp_not, imp.swap] using hl\n\nend\n\n@[simp] lemma abs_cpow_real (x : \u2102) (y : \u211d) : abs (x ^ (y : \u2102)) = x.abs ^ y :=\nby rcases eq_or_ne x 0 with rfl|hx; [rcases eq_or_ne y 0 with rfl|hy, skip];\n  simp [*, abs_cpow_of_ne_zero]\n\n@[simp] lemma abs_cpow_inv_nat (x : \u2102) (n : \u2115) : abs (x ^ (n\u207b\u00b9 : \u2102)) = x.abs ^ (n\u207b\u00b9 : \u211d) :=\nby rw \u2190 abs_cpow_real; simp [-abs_cpow_real]\n\nlemma abs_cpow_eq_rpow_re_of_pos {x : \u211d} (hx : 0 < x) (y : \u2102) : abs (x ^ y) = x ^ y.re :=\nby rw [abs_cpow_of_ne_zero (of_real_ne_zero.mpr hx.ne'), arg_of_real_of_nonneg hx.le, zero_mul,\n  real.exp_zero, div_one, abs_of_nonneg hx.le]\n\nlemma abs_cpow_eq_rpow_re_of_nonneg {x : \u211d} (hx : 0 \u2264 x) {y : \u2102} (hy : re y \u2260 0) :\n  abs (x ^ y) = x ^ re y :=\nbegin\n  rcases hx.eq_or_lt with rfl|hlt,\n  { rw [of_real_zero, zero_cpow, map_zero, real.zero_rpow hy],\n    exact ne_of_apply_ne re hy },\n  { exact abs_cpow_eq_rpow_re_of_pos hlt y }\nend\n\nlemma inv_cpow_eq_ite (x : \u2102) (n : \u2102) :\n  x\u207b\u00b9 ^ n = if x.arg = \u03c0 then conj (x ^ conj n)\u207b\u00b9 else (x ^ n)\u207b\u00b9 :=\nbegin\n  simp_rw [complex.cpow_def, log_inv_eq_ite, inv_eq_zero, map_eq_zero, ite_mul, neg_mul,\n    is_R_or_C.conj_inv, apply_ite conj, apply_ite exp, apply_ite has_inv.inv, map_zero, map_one,\n    exp_neg, inv_one, inv_zero, \u2190exp_conj, map_mul, conj_conj],\n  split_ifs with hx hn ha ha; refl,\nend\n\nlemma inv_cpow (x : \u2102) (n : \u2102) (hx : x.arg \u2260 \u03c0) : x\u207b\u00b9 ^ n = (x ^ n)\u207b\u00b9 :=\nby rw [inv_cpow_eq_ite, if_neg hx]\n\n/-- `complex.inv_cpow_eq_ite` with the `ite` on the other side. -/\nlemma inv_cpow_eq_ite' (x : \u2102) (n : \u2102) :\n  (x ^ n)\u207b\u00b9 = if x.arg = \u03c0 then conj (x\u207b\u00b9 ^ conj n) else x\u207b\u00b9 ^ n :=\nbegin\n  rw [inv_cpow_eq_ite, apply_ite conj, conj_conj, conj_conj],\n  split_ifs,\n  { refl },\n  { rw inv_cpow _ _ h }\nend\n\nlemma conj_cpow_eq_ite (x : \u2102) (n : \u2102) :\n  conj x ^ n = if x.arg = \u03c0 then x ^ n else conj (x ^ conj n) :=\nbegin\n  simp_rw [cpow_def, map_eq_zero, apply_ite conj, map_one, map_zero, \u2190exp_conj, map_mul,\n    conj_conj, log_conj_eq_ite],\n  split_ifs with hcx hn hx; refl\nend\n\nlemma conj_cpow (x : \u2102) (n : \u2102) (hx : x.arg \u2260 \u03c0) : conj x ^ n = conj (x ^ conj n) :=\nby rw [conj_cpow_eq_ite, if_neg hx]\n\nlemma cpow_conj (x : \u2102) (n : \u2102) (hx : x.arg \u2260 \u03c0) : x ^ conj n = conj (conj x ^ n) :=\nby rw [conj_cpow _ _ hx, conj_conj]\n\nend complex\n\nnamespace real\n\nvariables {x y z : \u211d}\n\nlemma rpow_add (hx : 0 < x) (y z : \u211d) : x ^ (y + z) = x ^ y * x ^ z :=\nby simp only [rpow_def_of_pos hx, mul_add, exp_add]\n\nlemma rpow_add' (hx : 0 \u2264 x) (h : y + z \u2260 0) : x ^ (y + z) = x ^ y * x ^ z :=\nbegin\n  rcases hx.eq_or_lt with rfl|pos,\n  { rw [zero_rpow h, zero_eq_mul],\n    have : y \u2260 0 \u2228 z \u2260 0, from not_and_distrib.1 (\u03bb \u27e8hy, hz\u27e9, h $ hy.symm \u25b8 hz.symm \u25b8 zero_add 0),\n    exact this.imp zero_rpow zero_rpow },\n  { exact rpow_add pos _ _ }\nend\n\nlemma rpow_add_of_nonneg (hx : 0 \u2264 x) (hy : 0 \u2264 y) (hz : 0 \u2264 z) :\n  x ^ (y + z) = x ^ y * x ^ z :=\nbegin\n  rcases hy.eq_or_lt with rfl|hy,\n  { rw [zero_add, rpow_zero, one_mul] },\n  exact rpow_add' hx (ne_of_gt $ add_pos_of_pos_of_nonneg hy hz)\nend\n\n/-- For `0 \u2264 x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for\n`x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish.\nThe inequality is always true, though, and given in this lemma. -/\nlemma le_rpow_add {x : \u211d} (hx : 0 \u2264 x) (y z : \u211d) : x ^ y * x ^ z \u2264 x ^ (y + z) :=\nbegin\n  rcases le_iff_eq_or_lt.1 hx with H|pos,\n  { by_cases h : y + z = 0,\n    { simp only [H.symm, h, rpow_zero],\n      calc (0 : \u211d) ^ y * 0 ^ z \u2264 1 * 1 :\n        mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one\n      ... = 1 : by simp },\n    { simp [rpow_add', \u2190 H, h] } },\n  { simp [rpow_add pos] }\nend\n\nlemma rpow_sum_of_pos {\u03b9 : Type*} {a : \u211d} (ha : 0 < a) (f : \u03b9 \u2192 \u211d) (s : finset \u03b9) :\n  a ^ (\u2211 x in s, f x) = \u220f x in s, a ^ f x :=\n@add_monoid_hom.map_sum \u211d \u03b9 (additive \u211d) _ _ \u27e8\u03bb x : \u211d, (a ^ x : \u211d), rpow_zero a, rpow_add ha\u27e9 f s\n\nlemma rpow_sum_of_nonneg {\u03b9 : Type*} {a : \u211d} (ha : 0 \u2264 a) {s : finset \u03b9} {f : \u03b9 \u2192 \u211d}\n  (h : \u2200 x \u2208 s, 0 \u2264 f x) :\n  a ^ (\u2211 x in s, f x) = \u220f x in s, a ^ f x :=\nbegin\n  induction s using finset.cons_induction with i s hi ihs,\n  { rw [sum_empty, finset.prod_empty, rpow_zero] },\n  { rw forall_mem_cons at h,\n    rw [sum_cons, prod_cons, \u2190 ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] }\nend\n\nlemma rpow_mul {x : \u211d} (hx : 0 \u2264 x) (y z : \u211d) : x ^ (y * z) = (x ^ y) ^ z :=\nby rw [\u2190 complex.of_real_inj, complex.of_real_cpow (rpow_nonneg_of_nonneg hx _),\n    complex.of_real_cpow hx, complex.of_real_mul, complex.cpow_mul, complex.of_real_cpow hx];\n  simp only [(complex.of_real_mul _ _).symm, (complex.of_real_log hx).symm,\n    complex.of_real_im, neg_lt_zero, pi_pos, le_of_lt pi_pos]\n\nlemma rpow_neg {x : \u211d} (hx : 0 \u2264 x) (y : \u211d) : x ^ -y = (x ^ y)\u207b\u00b9 :=\nby simp only [rpow_def_of_nonneg hx]; split_ifs; simp [*, exp_neg] at *\n\nlemma rpow_sub {x : \u211d} (hx : 0 < x) (y z : \u211d) : x ^ (y - z) = x ^ y / x ^ z :=\nby simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv]\n\nlemma rpow_sub' {x : \u211d} (hx : 0 \u2264 x) {y z : \u211d} (h : y - z \u2260 0) :\n  x ^ (y - z) = x ^ y / x ^ z :=\nby { simp only [sub_eq_add_neg] at h \u22a2, simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] }\n\nlemma rpow_add_int {x : \u211d} (hx : x \u2260 0) (y : \u211d) (n : \u2124) : x ^ (y + n) = x ^ y * x ^ n :=\nby rw [rpow_def, complex.of_real_add, complex.cpow_add _ _ (complex.of_real_ne_zero.mpr hx),\n  complex.of_real_int_cast, complex.cpow_int_cast, \u2190 complex.of_real_zpow, mul_comm,\n  complex.of_real_mul_re, \u2190 rpow_def, mul_comm]\n\nlemma rpow_add_nat {x : \u211d} (hx : x \u2260 0) (y : \u211d) (n : \u2115) : x ^ (y + n) = x ^ y * x ^ n :=\nby simpa using rpow_add_int hx y n\n\nlemma rpow_sub_int {x : \u211d} (hx : x \u2260 0) (y : \u211d) (n : \u2124) : x ^ (y - n) = x ^ y / x ^ n :=\nby simpa using rpow_add_int hx y (-n)\n\nlemma rpow_sub_nat {x : \u211d} (hx : x \u2260 0) (y : \u211d) (n : \u2115) : x ^ (y - n) = x ^ y / x ^ n :=\nby simpa using rpow_sub_int hx y n\n\nlemma rpow_add_one {x : \u211d} (hx : x \u2260 0) (y : \u211d) : x ^ (y + 1) = x ^ y * x :=\nby simpa using rpow_add_nat hx y 1\n\nlemma rpow_sub_one {x : \u211d} (hx : x \u2260 0) (y : \u211d) : x ^ (y - 1) = x ^ y / x :=\nby simpa using rpow_sub_nat hx y 1\n\n@[simp, norm_cast] lemma rpow_int_cast (x : \u211d) (n : \u2124) : x ^ (n : \u211d) = x ^ n :=\nby simp only [rpow_def, \u2190 complex.of_real_zpow, complex.cpow_int_cast,\n  complex.of_real_int_cast, complex.of_real_re]\n\n@[simp, norm_cast] lemma rpow_nat_cast (x : \u211d) (n : \u2115) : x ^ (n : \u211d) = x ^ n :=\nby simpa using rpow_int_cast x n\n\n@[simp] lemma rpow_two (x : \u211d) : x ^ (2 : \u211d) = x ^ 2 :=\nby { rw \u2190 rpow_nat_cast, simp only [nat.cast_bit0, nat.cast_one] }\n\nlemma rpow_neg_one (x : \u211d) : x ^ (-1 : \u211d) = x\u207b\u00b9 :=\nbegin\n  suffices H : x ^ ((-1 : \u2124) : \u211d) = x\u207b\u00b9, by rwa [int.cast_neg, int.cast_one] at H,\n  simp only [rpow_int_cast, zpow_one, zpow_neg],\nend\n\nlemma mul_rpow {x y z : \u211d} (h : 0 \u2264 x) (h\u2081 : 0 \u2264 y) : (x*y)^z = x^z * y^z :=\nbegin\n  iterate 3 { rw real.rpow_def_of_nonneg }, split_ifs; simp * at *,\n  { have hx : 0 < x,\n    { cases lt_or_eq_of_le h with h\u2082 h\u2082, { exact h\u2082 },\n      exfalso, apply h_2, exact eq.symm h\u2082 },\n    have hy : 0 < y,\n    { cases lt_or_eq_of_le h\u2081 with h\u2082 h\u2082, { exact h\u2082 },\n      exfalso, apply h_3, exact eq.symm h\u2082 },\n    rw [log_mul (ne_of_gt hx) (ne_of_gt hy), add_mul, exp_add]},\n  { exact h\u2081 },\n  { exact h },\n  { exact mul_nonneg h h\u2081 },\nend\n\nlemma inv_rpow (hx : 0 \u2264 x) (y : \u211d) : (x\u207b\u00b9)^y = (x^y)\u207b\u00b9 :=\nby simp only [\u2190 rpow_neg_one, \u2190 rpow_mul hx, mul_comm]\n\nlemma div_rpow (hx : 0 \u2264 x) (hy : 0 \u2264 y) (z : \u211d) : (x / y) ^ z = x^z / y^z :=\nby simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy]\n\nlemma log_rpow {x : \u211d} (hx : 0 < x) (y : \u211d) : log (x^y) = y * (log x) :=\nbegin\n  apply exp_injective,\n  rw [exp_log (rpow_pos_of_pos hx y), \u2190 exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y],\nend\n\nlemma rpow_lt_rpow (hx : 0 \u2264 x) (hxy : x < y) (hz : 0 < z) : x^z < y^z :=\nbegin\n  rw le_iff_eq_or_lt at hx, cases hx,\n  { rw [\u2190 hx, zero_rpow (ne_of_gt hz)], exact rpow_pos_of_pos (by rwa \u2190 hx at hxy) _ },\n  rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp],\n  exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz\nend\n\nlemma rpow_le_rpow {x y z: \u211d} (h : 0 \u2264 x) (h\u2081 : x \u2264 y) (h\u2082 : 0 \u2264 z) : x^z \u2264 y^z :=\nbegin\n  rcases eq_or_lt_of_le h\u2081 with rfl|h\u2081', { refl },\n  rcases eq_or_lt_of_le h\u2082 with rfl|h\u2082', { simp },\n  exact le_of_lt (rpow_lt_rpow h h\u2081' h\u2082')\nend\n\nlemma rpow_lt_rpow_iff (hx : 0 \u2264 x) (hy : 0 \u2264 y) (hz : 0 < z) : x ^ z < y ^ z \u2194 x < y :=\n\u27e8lt_imp_lt_of_le_imp_le $ \u03bb h, rpow_le_rpow hy h (le_of_lt hz), \u03bb h, rpow_lt_rpow hx h hz\u27e9\n\n\n\nlemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :\n  x \u2264 y ^ z\u207b\u00b9 \u2194 y \u2264 x ^ z :=\nbegin\n  have hz' : 0 < -z := by rwa [lt_neg, neg_zero],\n  have hxz : 0 < x ^ (-z) := real.rpow_pos_of_pos hx _,\n  have hyz : 0 < y ^ z\u207b\u00b9 := real.rpow_pos_of_pos hy _,\n  rw [\u2190real.rpow_le_rpow_iff hx.le hyz.le hz', \u2190real.rpow_mul hy.le],\n  simp only [ne_of_lt hz, real.rpow_neg_one, mul_neg, inv_mul_cancel, ne.def, not_false_iff],\n  rw [le_inv hxz hy, \u2190real.rpow_neg_one, \u2190real.rpow_mul hx.le],\n  simp,\nend\n\nlemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :\n  x < y ^ z\u207b\u00b9 \u2194 y < x ^ z :=\nbegin\n  have hz' : 0 < -z := by rwa [lt_neg, neg_zero],\n  have hxz : 0 < x ^ (-z) := real.rpow_pos_of_pos hx _,\n  have hyz : 0 < y ^ z\u207b\u00b9 := real.rpow_pos_of_pos hy _,\n  rw [\u2190real.rpow_lt_rpow_iff hx.le hyz.le hz', \u2190real.rpow_mul hy.le],\n  simp only [ne_of_lt hz, real.rpow_neg_one, mul_neg, inv_mul_cancel, ne.def, not_false_iff],\n  rw [lt_inv hxz hy, \u2190real.rpow_neg_one, \u2190real.rpow_mul hx.le],\n  simp,\nend\n\nlemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :\n  x ^ z\u207b\u00b9 < y \u2194 y ^ z < x :=\nbegin\n  convert lt_rpow_inv_iff_of_neg (real.rpow_pos_of_pos hx _) (real.rpow_pos_of_pos hy _) hz;\n  simp [\u2190real.rpow_mul hx.le, \u2190real.rpow_mul hy.le, ne_of_lt hz],\nend\n\nlemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :\n  x ^ z\u207b\u00b9 \u2264 y \u2194 y ^ z \u2264 x :=\nbegin\n  convert le_rpow_inv_iff_of_neg (real.rpow_pos_of_pos hx _) (real.rpow_pos_of_pos hy _) hz;\n  simp [\u2190real.rpow_mul hx.le, \u2190real.rpow_mul hy.le, ne_of_lt hz],\nend\n\nlemma rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x^y < x^z :=\nbegin\n  repeat {rw [rpow_def_of_pos (lt_trans zero_lt_one hx)]},\n  rw exp_lt_exp, exact mul_lt_mul_of_pos_left hyz (log_pos hx),\nend\n\nlemma rpow_le_rpow_of_exponent_le (hx : 1 \u2264 x) (hyz : y \u2264 z) : x^y \u2264 x^z :=\nbegin\n  repeat {rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)]},\n  rw exp_le_exp, exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx),\nend\n\n@[simp] lemma rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y \u2264 x ^ z \u2194 y \u2264 z :=\nbegin\n  have x_pos : 0 < x := lt_trans zero_lt_one hx,\n  rw [\u2190log_le_log (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z),\n      log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)],\nend\n\n@[simp] lemma rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z \u2194 y < z :=\nby rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le]\n\nlemma rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :\n  x^y < x^z :=\nbegin\n  repeat {rw [rpow_def_of_pos hx0]},\n  rw exp_lt_exp, exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1),\nend\n\nlemma rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x \u2264 1) (hyz : z \u2264 y) :\n  x^y \u2264 x^z :=\nbegin\n  repeat {rw [rpow_def_of_pos hx0]},\n  rw exp_le_exp, exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1),\nend\n\n@[simp] lemma rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :\n  x ^ y \u2264 x ^ z \u2194 z \u2264 y :=\nbegin\n  rw [\u2190log_le_log (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z),\n      log_rpow hx0, log_rpow hx0, mul_le_mul_right_of_neg (log_neg hx0 hx1)],\nend\n\n@[simp] lemma rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :\n  x ^ y < x ^ z \u2194 z < y :=\nby rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le]\n\nlemma rpow_lt_one {x z : \u211d} (hx1 : 0 \u2264 x) (hx2 : x < 1) (hz : 0 < z) : x^z < 1 :=\nby { rw \u2190 one_rpow z, exact rpow_lt_rpow hx1 hx2 hz }\n\nlemma rpow_le_one {x z : \u211d} (hx1 : 0 \u2264 x) (hx2 : x \u2264 1) (hz : 0 \u2264 z) : x^z \u2264 1 :=\nby { rw \u2190 one_rpow z, exact rpow_le_rpow hx1 hx2 hz }\n\nlemma rpow_lt_one_of_one_lt_of_neg {x z : \u211d} (hx : 1 < x) (hz : z < 0) : x^z < 1 :=\nby { convert rpow_lt_rpow_of_exponent_lt hx hz, exact (rpow_zero x).symm }\n\nlemma rpow_le_one_of_one_le_of_nonpos {x z : \u211d} (hx : 1 \u2264 x) (hz : z \u2264 0) : x^z \u2264 1 :=\nby { convert rpow_le_rpow_of_exponent_le hx hz, exact (rpow_zero x).symm }\n\nlemma one_lt_rpow {x z : \u211d} (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=\nby { rw \u2190 one_rpow z, exact rpow_lt_rpow zero_le_one hx hz }\n\nlemma one_le_rpow {x z : \u211d} (hx : 1 \u2264 x) (hz : 0 \u2264 z) : 1 \u2264 x^z :=\nby { rw \u2190 one_rpow z, exact rpow_le_rpow zero_le_one hx hz }\n\nlemma one_lt_rpow_of_pos_of_lt_one_of_neg (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) :\n  1 < x^z :=\nby { convert rpow_lt_rpow_of_exponent_gt hx1 hx2 hz, exact (rpow_zero x).symm }\n\nlemma one_le_rpow_of_pos_of_le_one_of_nonpos (hx1 : 0 < x) (hx2 : x \u2264 1) (hz : z \u2264 0) :\n  1 \u2264 x^z :=\nby { convert rpow_le_rpow_of_exponent_ge hx1 hx2 hz, exact (rpow_zero x).symm }\n\nlemma rpow_lt_one_iff_of_pos (hx : 0 < x) : x ^ y < 1 \u2194 1 < x \u2227 y < 0 \u2228 x < 1 \u2227 0 < y :=\nby rw [rpow_def_of_pos hx, exp_lt_one_iff, mul_neg_iff, log_pos_iff hx, log_neg_iff hx]\n\nlemma rpow_lt_one_iff (hx : 0 \u2264 x) : x ^ y < 1 \u2194 x = 0 \u2227 y \u2260 0 \u2228 1 < x \u2227 y < 0 \u2228 x < 1 \u2227 0 < y :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { rcases em (y = 0) with (rfl|hy); simp [*, lt_irrefl, zero_lt_one] },\n  { simp [rpow_lt_one_iff_of_pos hx, hx.ne.symm] }\nend\n\nlemma one_lt_rpow_iff_of_pos (hx : 0 < x) : 1 < x ^ y \u2194 1 < x \u2227 0 < y \u2228 x < 1 \u2227 y < 0 :=\nby rw [rpow_def_of_pos hx, one_lt_exp_iff, mul_pos_iff, log_pos_iff hx, log_neg_iff hx]\n\nlemma one_lt_rpow_iff (hx : 0 \u2264 x) : 1 < x ^ y \u2194 1 < x \u2227 0 < y \u2228 0 < x \u2227 x < 1 \u2227 y < 0 :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { rcases em (y = 0) with (rfl|hy); simp [*, lt_irrefl, (zero_lt_one' \u211d).not_lt] },\n  { simp [one_lt_rpow_iff_of_pos hx, hx] }\nend\n\nlemma rpow_le_rpow_of_exponent_ge' (hx0 : 0 \u2264 x) (hx1 : x \u2264 1) (hz : 0 \u2264 z) (hyz : z \u2264 y) :\n  x^y \u2264 x^z :=\nbegin\n  rcases eq_or_lt_of_le hx0 with rfl | hx0',\n  { rcases eq_or_lt_of_le hz with rfl | hz',\n    { exact (rpow_zero 0).symm \u25b8 (rpow_le_one hx0 hx1 hyz), },\n    rw [zero_rpow, zero_rpow]; linarith, },\n  { exact rpow_le_rpow_of_exponent_ge hx0' hx1 hyz, },\nend\n\nlemma rpow_left_inj_on {x : \u211d} (hx : x \u2260 0) :\n  inj_on (\u03bb y : \u211d, y^x) {y : \u211d | 0 \u2264 y} :=\nbegin\n  rintros y hy z hz (hyz : y ^ x = z ^ x),\n  rw [\u2190rpow_one y, \u2190rpow_one z, \u2190_root_.mul_inv_cancel hx, rpow_mul hy, rpow_mul hz, hyz]\nend\n\nlemma le_rpow_iff_log_le (hx : 0 < x) (hy : 0 < y) :\n  x \u2264 y^z \u2194 real.log x \u2264 z * real.log y :=\nby rw [\u2190real.log_le_log hx (real.rpow_pos_of_pos hy z), real.log_rpow hy]\n\nlemma le_rpow_of_log_le (hx : 0 \u2264 x) (hy : 0 < y) (h : real.log x \u2264 z * real.log y) :\n  x \u2264 y^z :=\nbegin\n  obtain hx | rfl := hx.lt_or_eq,\n  { exact (le_rpow_iff_log_le hx hy).2 h },\n  exact (real.rpow_pos_of_pos hy z).le,\nend\n\nlemma lt_rpow_iff_log_lt (hx : 0 < x) (hy : 0 < y) :\n  x < y^z \u2194 real.log x < z * real.log y :=\nby rw [\u2190real.log_lt_log_iff hx (real.rpow_pos_of_pos hy z), real.log_rpow hy]\n\nlemma lt_rpow_of_log_lt (hx : 0 \u2264 x) (hy : 0 < y) (h : real.log x < z * real.log y) :\n  x < y^z :=\nbegin\n  obtain hx | rfl := hx.lt_or_eq,\n  { exact (lt_rpow_iff_log_lt hx hy).2 h },\n  exact real.rpow_pos_of_pos hy z,\nend\n\nlemma rpow_le_one_iff_of_pos (hx : 0 < x) : x ^ y \u2264 1 \u2194 1 \u2264 x \u2227 y \u2264 0 \u2228 x \u2264 1 \u2227 0 \u2264 y :=\nby rw [rpow_def_of_pos hx, exp_le_one_iff, mul_nonpos_iff, log_nonneg_iff hx, log_nonpos_iff hx]\n\n/-- Bound for `|log x * x ^ t|` in the interval `(0, 1]`, for positive real `t`. -/\nlemma abs_log_mul_self_rpow_lt (x t : \u211d) (h1 : 0 < x) (h2 : x \u2264 1) (ht : 0 < t) :\n  |log x * x ^ t| < 1 / t :=\nbegin\n  rw lt_div_iff ht,\n  have := abs_log_mul_self_lt (x ^ t) (rpow_pos_of_pos h1 t) (rpow_le_one h1.le h2 ht.le),\n  rwa [log_rpow h1, mul_assoc, abs_mul, abs_of_pos ht, mul_comm] at this\nend\n\nlemma pow_nat_rpow_nat_inv {x : \u211d} (hx : 0 \u2264 x) {n : \u2115} (hn : n \u2260 0) :\n  (x ^ n) ^ (n\u207b\u00b9 : \u211d) = x :=\nhave hn0 : (n : \u211d) \u2260 0, from nat.cast_ne_zero.2 hn,\nby rw [\u2190 rpow_nat_cast, \u2190 rpow_mul hx, mul_inv_cancel hn0, rpow_one]\n\nlemma rpow_nat_inv_pow_nat {x : \u211d} (hx : 0 \u2264 x) {n : \u2115} (hn : n \u2260 0) :\n  (x ^ (n\u207b\u00b9 : \u211d)) ^ n = x :=\nhave hn0 : (n : \u211d) \u2260 0, from nat.cast_ne_zero.2 hn,\nby rw [\u2190 rpow_nat_cast, \u2190 rpow_mul hx, inv_mul_cancel hn0, rpow_one]\n\nlemma continuous_at_const_rpow {a b : \u211d} (h : a \u2260 0) : continuous_at (rpow a) b :=\nbegin\n  have : rpow a = \u03bb x : \u211d, ((a : \u2102) ^ (x : \u2102)).re, by { ext1 x, rw [rpow_eq_pow, rpow_def], },\n  rw this,\n  refine complex.continuous_re.continuous_at.comp _,\n  refine (continuous_at_const_cpow _).comp complex.continuous_of_real.continuous_at,\n  norm_cast,\n  exact h,\nend\n\nlemma continuous_at_const_rpow' {a b : \u211d} (h : b \u2260 0) : continuous_at (rpow a) b :=\nbegin\n  have : rpow a = \u03bb x : \u211d, ((a : \u2102) ^ (x : \u2102)).re, by { ext1 x, rw [rpow_eq_pow, rpow_def], },\n  rw this,\n  refine complex.continuous_re.continuous_at.comp _,\n  refine (continuous_at_const_cpow' _).comp complex.continuous_of_real.continuous_at,\n  norm_cast,\n  exact h,\nend\n\nlemma rpow_eq_nhds_of_neg {p : \u211d \u00d7 \u211d} (hp_fst : p.fst < 0) :\n  (\u03bb x : \u211d \u00d7 \u211d, x.1 ^ x.2) =\u1da0[\ud835\udcdd p] \u03bb x, exp (log x.1 * x.2) * cos (x.2 * \u03c0) :=\nbegin\n  suffices : \u2200\u1da0 (x : \u211d \u00d7 \u211d) in (\ud835\udcdd p), x.1 < 0,\n    from this.mono (\u03bb x hx, by { dsimp only, rw rpow_def_of_neg hx, }),\n  exact is_open.eventually_mem (is_open_lt continuous_fst continuous_const) hp_fst,\nend\n\nlemma rpow_eq_nhds_of_pos {p : \u211d \u00d7 \u211d} (hp_fst : 0 < p.fst) :\n  (\u03bb x : \u211d \u00d7 \u211d, x.1 ^ x.2) =\u1da0[\ud835\udcdd p] \u03bb x, exp (log x.1 * x.2) :=\nbegin\n  suffices : \u2200\u1da0 (x : \u211d \u00d7 \u211d) in (\ud835\udcdd p), 0 < x.1,\n    from this.mono (\u03bb x hx, by { dsimp only, rw rpow_def_of_pos hx, }),\n  exact is_open.eventually_mem (is_open_lt continuous_const continuous_fst) hp_fst,\nend\n\nlemma continuous_at_rpow_of_ne (p : \u211d \u00d7 \u211d) (hp : p.1 \u2260 0) :\n  continuous_at (\u03bb p : \u211d \u00d7 \u211d, p.1 ^ p.2) p :=\nbegin\n  rw ne_iff_lt_or_gt at hp,\n  cases hp,\n  { rw continuous_at_congr (rpow_eq_nhds_of_neg hp),\n    refine continuous_at.mul _ (continuous_cos.continuous_at.comp _),\n    { refine continuous_exp.continuous_at.comp (continuous_at.mul _ continuous_snd.continuous_at),\n      refine (continuous_at_log _).comp continuous_fst.continuous_at,\n      exact hp.ne, },\n    { exact continuous_snd.continuous_at.mul continuous_at_const, }, },\n  { rw continuous_at_congr (rpow_eq_nhds_of_pos hp),\n    refine continuous_exp.continuous_at.comp (continuous_at.mul _ continuous_snd.continuous_at),\n    refine (continuous_at_log _).comp continuous_fst.continuous_at,\n    exact hp.lt.ne.symm, },\nend\n\nlemma continuous_at_rpow_of_pos (p : \u211d \u00d7 \u211d) (hp : 0 < p.2) :\n  continuous_at (\u03bb p : \u211d \u00d7 \u211d, p.1 ^ p.2) p :=\nbegin\n  cases p with x y,\n  obtain hx|rfl := ne_or_eq x 0,\n  { exact continuous_at_rpow_of_ne (x, y) hx },\n  have A : tendsto (\u03bb p : \u211d \u00d7 \u211d, exp (log p.1 * p.2)) (\ud835\udcdd[\u2260] 0 \u00d7\u1da0 \ud835\udcdd y) (\ud835\udcdd 0) :=\n    tendsto_exp_at_bot.comp\n      ((tendsto_log_nhds_within_zero.comp tendsto_fst).at_bot_mul hp tendsto_snd),\n  have B : tendsto (\u03bb p : \u211d \u00d7 \u211d, p.1 ^ p.2) (\ud835\udcdd[\u2260] 0 \u00d7\u1da0 \ud835\udcdd y) (\ud835\udcdd 0) :=\n    squeeze_zero_norm (\u03bb p, abs_rpow_le_exp_log_mul p.1 p.2) A,\n  have C : tendsto (\u03bb p : \u211d \u00d7 \u211d, p.1 ^ p.2) (\ud835\udcdd[{0}] 0 \u00d7\u1da0 \ud835\udcdd y) (pure 0),\n  { rw [nhds_within_singleton, tendsto_pure, pure_prod, eventually_map],\n    exact (lt_mem_nhds hp).mono (\u03bb y hy, zero_rpow hy.ne') },\n  simpa only [\u2190 sup_prod, \u2190 nhds_within_union, compl_union_self, nhds_within_univ, nhds_prod_eq,\n    continuous_at, zero_rpow hp.ne'] using B.sup (C.mono_right (pure_le_nhds _))\nend\n\nlemma continuous_at_rpow (p : \u211d \u00d7 \u211d) (h : p.1 \u2260 0 \u2228 0 < p.2) :\n  continuous_at (\u03bb p : \u211d \u00d7 \u211d, p.1 ^ p.2) p :=\nh.elim (\u03bb h, continuous_at_rpow_of_ne p h) (\u03bb h, continuous_at_rpow_of_pos p h)\n\nlemma continuous_at_rpow_const (x : \u211d) (q : \u211d) (h : x \u2260 0 \u2228 0 < q) :\n  continuous_at (\u03bb (x : \u211d), x ^ q) x :=\nbegin\n  change continuous_at ((\u03bb p : \u211d \u00d7 \u211d, p.1 ^ p.2) \u2218 (\u03bb y : \u211d, (y, q))) x,\n  apply continuous_at.comp,\n  { exact continuous_at_rpow (x, q) h },\n  { exact (continuous_id'.prod_mk continuous_const).continuous_at }\nend\n\nend real\n\nsection\n\nvariable {\u03b1 : Type*}\n\nlemma filter.tendsto.rpow {l : filter \u03b1} {f g : \u03b1 \u2192 \u211d} {x y : \u211d}\n  (hf : tendsto f l (\ud835\udcdd x)) (hg : tendsto g l (\ud835\udcdd y)) (h : x \u2260 0 \u2228 0 < y) :\n  tendsto (\u03bb t, f t ^ g t) l (\ud835\udcdd (x ^ y)) :=\n(real.continuous_at_rpow (x, y) h).tendsto.comp (hf.prod_mk_nhds hg)\n\nlemma filter.tendsto.rpow_const {l : filter \u03b1} {f : \u03b1 \u2192 \u211d} {x p : \u211d}\n  (hf : tendsto f l (\ud835\udcdd x)) (h : x \u2260 0 \u2228 0 \u2264 p) :\n  tendsto (\u03bb a, f a ^ p) l (\ud835\udcdd (x ^ p)) :=\nif h0 : 0 = p then h0 \u25b8 by simp [tendsto_const_nhds]\nelse hf.rpow tendsto_const_nhds (h.imp id $ \u03bb h', h'.lt_of_ne h0)\n\nvariables [topological_space \u03b1] {f g : \u03b1 \u2192 \u211d} {s : set \u03b1} {x : \u03b1} {p : \u211d}\n\nlemma continuous_at.rpow (hf : continuous_at f x) (hg : continuous_at g x) (h : f x \u2260 0 \u2228 0 < g x) :\n  continuous_at (\u03bb t, f t ^ g t) x :=\nhf.rpow hg h\n\nlemma continuous_within_at.rpow (hf : continuous_within_at f s x) (hg : continuous_within_at g s x)\n  (h : f x \u2260 0 \u2228 0 < g x) :\n  continuous_within_at (\u03bb t, f t ^ g t) s x :=\nhf.rpow hg h\n\nlemma continuous_on.rpow (hf : continuous_on f s) (hg : continuous_on g s)\n  (h : \u2200 x \u2208 s, f x \u2260 0 \u2228 0 < g x) :\n  continuous_on (\u03bb t, f t ^ g t) s :=\n\u03bb t ht, (hf t ht).rpow (hg t ht) (h t ht)\n\nlemma continuous.rpow (hf : continuous f) (hg : continuous g) (h : \u2200 x, f x \u2260 0 \u2228 0 < g x) :\n  continuous (\u03bb x, f x ^ g x) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, (hf.continuous_at.rpow hg.continuous_at (h x))\n\nlemma continuous_within_at.rpow_const (hf : continuous_within_at f s x) (h : f x \u2260 0 \u2228 0 \u2264 p) :\n  continuous_within_at (\u03bb x, f x ^ p) s x :=\nhf.rpow_const h\n\nlemma continuous_at.rpow_const (hf : continuous_at f x) (h : f x \u2260 0 \u2228 0 \u2264 p) :\n  continuous_at (\u03bb x, f x ^ p) x :=\nhf.rpow_const h\n\nlemma continuous_on.rpow_const (hf : continuous_on f s) (h : \u2200 x \u2208 s, f x \u2260 0 \u2228 0 \u2264 p) :\n  continuous_on (\u03bb x, f x ^ p) s :=\n\u03bb x hx, (hf x hx).rpow_const (h x hx)\n\nlemma continuous.rpow_const (hf : continuous f) (h : \u2200 x, f x \u2260 0 \u2228 0 \u2264 p) :\n  continuous (\u03bb x, f x ^ p) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, hf.continuous_at.rpow_const (h x)\n\nend\n\nnamespace real\n\nvariables {z x y : \u211d}\n\nsection sqrt\n\nlemma sqrt_eq_rpow (x : \u211d) : sqrt x = x ^ (1/(2:\u211d)) :=\nbegin\n  obtain h | h := le_or_lt 0 x,\n  { rw [\u2190 mul_self_inj_of_nonneg (sqrt_nonneg _) (rpow_nonneg_of_nonneg h _), mul_self_sqrt h,\n      \u2190 sq, \u2190 rpow_nat_cast, \u2190 rpow_mul h],\n    norm_num },\n  { have : 1 / (2:\u211d) * \u03c0 = \u03c0 / (2:\u211d), ring,\n    rw [sqrt_eq_zero_of_nonpos h.le, rpow_def_of_neg h, this, cos_pi_div_two, mul_zero] }\nend\n\nlemma rpow_div_two_eq_sqrt {x : \u211d} (r : \u211d) (hx : 0 \u2264 x) : x ^ (r/2) = (sqrt x) ^ r :=\nbegin\n  rw [sqrt_eq_rpow, \u2190 rpow_mul hx],\n  congr,\n  ring,\nend\n\nend sqrt\n\nend real\n\nsection limits\nopen real filter\n\n/-- The function `x ^ y` tends to `+\u221e` at `+\u221e` for any positive real `y`. -/\nlemma tendsto_rpow_at_top {y : \u211d} (hy : 0 < y) : tendsto (\u03bb x : \u211d, x ^ y) at_top at_top :=\nbegin\n  rw tendsto_at_top_at_top,\n  intro b,\n  use (max b 0) ^ (1/y),\n  intros x hx,\n  exact le_of_max_le_left\n    (by { convert rpow_le_rpow (rpow_nonneg_of_nonneg (le_max_right b 0) (1/y)) hx (le_of_lt hy),\n      rw [\u2190 rpow_mul (le_max_right b 0), (eq_div_iff (ne_of_gt hy)).mp rfl, rpow_one] }),\nend\n\n/-- The function `x ^ (-y)` tends to `0` at `+\u221e` for any positive real `y`. -/\nlemma tendsto_rpow_neg_at_top {y : \u211d} (hy : 0 < y) : tendsto (\u03bb x : \u211d, x ^ (-y)) at_top (\ud835\udcdd 0) :=\ntendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top 0) (\u03bb x hx, (rpow_neg (le_of_lt hx) y).symm))\n  (tendsto_rpow_at_top hy).inv_tendsto_at_top\n\n/-- The function `x ^ (a / (b * x + c))` tends to `1` at `+\u221e`, for any real numbers `a`, `b`, and\n`c` such that `b` is nonzero. -/\nlemma tendsto_rpow_div_mul_add (a b c : \u211d) (hb : 0 \u2260 b) :\n  tendsto (\u03bb x, x ^ (a / (b*x+c))) at_top (\ud835\udcdd 1) :=\nbegin\n  refine tendsto.congr' _ ((tendsto_exp_nhds_0_nhds_1.comp\n    (by simpa only [mul_zero, pow_one] using ((@tendsto_const_nhds _ _ _ a _).mul\n      (tendsto_div_pow_mul_exp_add_at_top b c 1 hb)))).comp tendsto_log_at_top),\n  apply eventually_eq_of_mem (Ioi_mem_at_top (0:\u211d)),\n  intros x hx,\n  simp only [set.mem_Ioi, function.comp_app] at hx \u22a2,\n  rw [exp_log hx, \u2190 exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))],\n  field_simp,\nend\n\n/-- The function `x ^ (1 / x)` tends to `1` at `+\u221e`. -/\nlemma tendsto_rpow_div : tendsto (\u03bb x, x ^ ((1:\u211d) / x)) at_top (\ud835\udcdd 1) :=\nby { convert tendsto_rpow_div_mul_add (1:\u211d) _ (0:\u211d) zero_ne_one, funext, congr' 2, ring }\n\n/-- The function `x ^ (-1 / x)` tends to `1` at `+\u221e`. -/\nlemma tendsto_rpow_neg_div : tendsto (\u03bb x, x ^ (-(1:\u211d) / x)) at_top (\ud835\udcdd 1) :=\nby { convert tendsto_rpow_div_mul_add (-(1:\u211d)) _ (0:\u211d) zero_ne_one, funext, congr' 2, ring }\n\n/-- The function `exp(x) / x ^ s` tends to `+\u221e` at `+\u221e`, for any real number `s`. -/\nlemma tendsto_exp_div_rpow_at_top (s : \u211d) : tendsto (\u03bb x : \u211d, exp x / x ^ s) at_top at_top :=\nbegin\n  cases archimedean_iff_nat_lt.1 (real.archimedean) s with n hn,\n  refine tendsto_at_top_mono' _ _ (tendsto_exp_div_pow_at_top n),\n  filter_upwards [eventually_gt_at_top (0 : \u211d), eventually_ge_at_top (1 : \u211d)] with x hx\u2080 hx\u2081,\n  rw [div_le_div_left (exp_pos _) (pow_pos hx\u2080 _) (rpow_pos_of_pos hx\u2080 _), \u2190rpow_nat_cast],\n  exact rpow_le_rpow_of_exponent_le hx\u2081 hn.le,\nend\n\n/-- The function `exp (b * x) / x ^ s` tends to `+\u221e` at `+\u221e`, for any real `s` and `b > 0`. -/\nlemma tendsto_exp_mul_div_rpow_at_top (s : \u211d) (b : \u211d) (hb : 0 < b) :\n  tendsto (\u03bb x : \u211d, exp (b * x) / x ^ s) at_top at_top :=\nbegin\n  refine ((tendsto_rpow_at_top hb).comp (tendsto_exp_div_rpow_at_top (s / b))).congr' _,\n  filter_upwards [eventually_ge_at_top (0 : \u211d)] with x hx\u2080,\n  simp [div_rpow, (exp_pos x).le, rpow_nonneg_of_nonneg, \u2190rpow_mul, \u2190exp_mul, mul_comm x, hb.ne', *]\nend\n\n/-- The function `x ^ s * exp (-b * x)` tends to `0` at `+\u221e`, for any real `s` and `b > 0`. -/\nlemma tendsto_rpow_mul_exp_neg_mul_at_top_nhds_0 (s : \u211d) (b : \u211d) (hb : 0 < b):\n  tendsto (\u03bb x : \u211d, x ^ s * exp (-b * x)) at_top (\ud835\udcdd 0) :=\nbegin\n  refine (tendsto_exp_mul_div_rpow_at_top s b hb).inv_tendsto_at_top.congr' _,\n  filter_upwards with x using by simp [exp_neg, inv_div, div_eq_mul_inv _ (exp _)]\nend\n\nnamespace asymptotics\n\nvariables {\u03b1 : Type*} {r c : \u211d} {l : filter \u03b1} {f g : \u03b1 \u2192 \u211d}\n\nlemma is_O_with.rpow (h : is_O_with c l f g) (hc : 0 \u2264 c) (hr : 0 \u2264 r) (hg : 0 \u2264\u1da0[l] g) :\n  is_O_with (c ^ r) l (\u03bb x, f x ^ r) (\u03bb x, g x ^ r) :=\nbegin\n  apply is_O_with.of_bound,\n  filter_upwards [hg, h.bound] with x hgx hx,\n  calc |f x ^ r| \u2264 |f x| ^ r         : abs_rpow_le_abs_rpow _ _\n             ... \u2264 (c * |g x|) ^ r   : rpow_le_rpow (abs_nonneg _) hx hr\n             ... = c ^ r * |g x ^ r| : by rw [mul_rpow hc (abs_nonneg _), abs_rpow_of_nonneg hgx]\nend\n\nlemma is_O.rpow (hr : 0 \u2264 r) (hg : 0 \u2264\u1da0[l] g) (h : f =O[l] g) :\n  (\u03bb x, f x ^ r) =O[l] (\u03bb x, g x ^ r) :=\nlet \u27e8c, hc, h'\u27e9 := h.exists_nonneg in (h'.rpow hc hr hg).is_O\n\nlemma is_o.rpow (hr : 0 < r) (hg : 0 \u2264\u1da0[l] g) (h : f =o[l] g) :\n  (\u03bb x, f x ^ r) =o[l] (\u03bb x, g x ^ r) :=\nis_o.of_is_O_with $ \u03bb c hc, ((h.forall_is_O_with (rpow_pos_of_pos hc r\u207b\u00b9)).rpow\n  (rpow_nonneg_of_nonneg hc.le _) hr.le hg).congr_const\n    (by rw [\u2190rpow_mul hc.le, inv_mul_cancel hr.ne', rpow_one])\n\nend asymptotics\n\nopen asymptotics\n\n/-- `x ^ s = o(exp(b * x))` as `x \u2192 \u221e` for any real `s` and positive `b`. -/\nlemma is_o_rpow_exp_pos_mul_at_top (s : \u211d) {b : \u211d} (hb : 0 < b) :\n  (\u03bb x : \u211d, x ^ s) =o[at_top] (\u03bb x, exp (b * x)) :=\niff.mpr (is_o_iff_tendsto $ \u03bb x h, absurd h (exp_pos _).ne') $\n  by simpa only [div_eq_mul_inv, exp_neg, neg_mul]\n    using tendsto_rpow_mul_exp_neg_mul_at_top_nhds_0 s b hb\n\n/-- `x ^ k = o(exp(b * x))` as `x \u2192 \u221e` for any integer `k` and positive `b`. -/\nlemma is_o_zpow_exp_pos_mul_at_top (k : \u2124) {b : \u211d} (hb : 0 < b) :\n  (\u03bb x : \u211d, x ^ k) =o[at_top] (\u03bb x, exp (b * x)) :=\nby simpa only [rpow_int_cast] using is_o_rpow_exp_pos_mul_at_top k hb\n\n/-- `x ^ k = o(exp(b * x))` as `x \u2192 \u221e` for any natural `k` and positive `b`. -/\nlemma is_o_pow_exp_pos_mul_at_top (k : \u2115) {b : \u211d} (hb : 0 < b) :\n  (\u03bb x : \u211d, x ^ k) =o[at_top] (\u03bb x, exp (b * x)) :=\nby simpa using is_o_zpow_exp_pos_mul_at_top k hb\n\n/-- `x ^ s = o(exp x)` as `x \u2192 \u221e` for any real `s`. -/\nlemma is_o_rpow_exp_at_top (s : \u211d) : (\u03bb x : \u211d, x ^ s) =o[at_top] exp :=\nby simpa only [one_mul] using is_o_rpow_exp_pos_mul_at_top s one_pos\n\nlemma is_o_log_rpow_at_top {r : \u211d} (hr : 0 < r) : log =o[at_top] (\u03bb x, x ^ r) :=\ncalc log =O[at_top] (\u03bb x, r * log x)   : is_O_self_const_mul _ hr.ne' _ _\n     ... =\u1da0[at_top] (\u03bb x, log (x ^ r)) :\n  (eventually_gt_at_top 0).mono $ \u03bb x hx, (log_rpow hx _).symm\n     ... =o[at_top] (\u03bb x, x ^ r)       : is_o_log_id_at_top.comp_tendsto (tendsto_rpow_at_top hr)\n\nlemma is_o_log_rpow_rpow_at_top {s : \u211d} (r : \u211d) (hs : 0 < s) :\n  (\u03bb x, log x ^ r) =o[at_top] (\u03bb x, x ^ s) :=\nlet r' := max r 1 in\nhave hr : 0 < r', from lt_max_iff.2 $ or.inr one_pos,\nhave H : 0 < s / r', from div_pos hs hr,\ncalc (\u03bb x, log x ^ r) =O[at_top] (\u03bb x, log x ^ r') :\n  is_O.of_bound 1 $ (tendsto_log_at_top.eventually_ge_at_top 1).mono $ \u03bb x hx,\n    have hx\u2080 : 0 \u2264 log x, from zero_le_one.trans hx,\n    by simp [norm_eq_abs, abs_rpow_of_nonneg, abs_rpow_of_nonneg hx\u2080,\n      rpow_le_rpow_of_exponent_le (hx.trans (le_abs_self _))]\n                  ... =o[at_top] (\u03bb x, (x ^ (s / r')) ^ r') :\n  (is_o_log_rpow_at_top H).rpow hr $ (tendsto_rpow_at_top H).eventually $ eventually_ge_at_top 0\n                  ... =\u1da0[at_top] (\u03bb x, x ^ s) :\n  (eventually_ge_at_top 0).mono $ \u03bb x hx, by simp only [\u2190 rpow_mul hx, div_mul_cancel _ hr.ne']\n\nlemma is_o_abs_log_rpow_rpow_nhds_zero {s : \u211d} (r : \u211d) (hs : s < 0) :\n  (\u03bb x, |log x| ^ r) =o[\ud835\udcdd[>] 0] (\u03bb x, x ^ s) :=\n((is_o_log_rpow_rpow_at_top r (neg_pos.2 hs)).comp_tendsto tendsto_inv_zero_at_top).congr'\n  (mem_of_superset (Icc_mem_nhds_within_Ioi $ set.left_mem_Ico.2 one_pos) $\n    \u03bb x hx, by simp [abs_of_nonpos, log_nonpos hx.1 hx.2])\n  (eventually_mem_nhds_within.mono $ \u03bb x hx,\n    by rw [function.comp_app, inv_rpow hx.out.le, rpow_neg hx.out.le, inv_inv])\n\nlemma is_o_log_rpow_nhds_zero {r : \u211d} (hr : r < 0) : log =o[\ud835\udcdd[>] 0] (\u03bb x, x ^ r) :=\n(is_o_abs_log_rpow_rpow_nhds_zero 1 hr).neg_left.congr'\n  (mem_of_superset (Icc_mem_nhds_within_Ioi $ set.left_mem_Ico.2 one_pos) $\n    \u03bb x hx, by simp [abs_of_nonpos (log_nonpos hx.1 hx.2)])\n  eventually_eq.rfl\n\nlemma tendsto_log_div_rpow_nhds_zero {r : \u211d} (hr : r < 0) :\n  tendsto (\u03bb x, log x / x ^ r) (\ud835\udcdd[>] 0) (\ud835\udcdd 0) :=\n(is_o_log_rpow_nhds_zero hr).tendsto_div_nhds_zero\n\nlemma tendsto_log_mul_rpow_nhds_zero {r : \u211d} (hr : 0 < r) :\n  tendsto (\u03bb x, log x * x ^ r) (\ud835\udcdd[>] 0) (\ud835\udcdd 0) :=\n(tendsto_log_div_rpow_nhds_zero $ neg_lt_zero.2 hr).congr' $\n  eventually_mem_nhds_within.mono $ \u03bb x hx, by rw [rpow_neg hx.out.le, div_inv_eq_mul]\n\nend limits\n\nnamespace complex\n\n/-- See also `continuous_at_cpow` and `complex.continuous_at_cpow_of_re_pos`. -/\nlemma continuous_at_cpow_zero_of_re_pos {z : \u2102} (hz : 0 < z.re) :\n  continuous_at (\u03bb x : \u2102 \u00d7 \u2102, x.1 ^ x.2) (0, z) :=\nbegin\n  have hz\u2080 : z \u2260 0, from ne_of_apply_ne re hz.ne',\n  rw [continuous_at, zero_cpow hz\u2080, tendsto_zero_iff_norm_tendsto_zero],\n  refine squeeze_zero (\u03bb _, norm_nonneg _) (\u03bb _, abs_cpow_le _ _) _,\n  simp only [div_eq_mul_inv, \u2190 real.exp_neg],\n  refine tendsto.zero_mul_is_bounded_under_le _ _,\n  { convert (continuous_fst.norm.tendsto _).rpow ((continuous_re.comp continuous_snd).tendsto _) _;\n      simp [hz, real.zero_rpow hz.ne'] },\n  { simp only [(\u2218), real.norm_eq_abs, abs_of_pos (real.exp_pos _)],\n    rcases exists_gt (|im z|) with \u27e8C, hC\u27e9,\n    refine \u27e8real.exp (\u03c0 * C), eventually_map.2 _\u27e9,\n    refine (((continuous_im.comp continuous_snd).abs.tendsto (_, z)).eventually\n      (gt_mem_nhds hC)).mono (\u03bb z hz, real.exp_le_exp.2 $ (neg_le_abs_self _).trans _),\n    rw _root_.abs_mul,\n    exact mul_le_mul (abs_le.2 \u27e8(neg_pi_lt_arg _).le, arg_le_pi _\u27e9) hz.le\n      (_root_.abs_nonneg _) real.pi_pos.le }\nend\n\n/-- See also `continuous_at_cpow` for a version that assumes `p.1 \u2260 0` but makes no\nassumptions about `p.2`. -/\nlemma continuous_at_cpow_of_re_pos {p : \u2102 \u00d7 \u2102} (h\u2081 : 0 \u2264 p.1.re \u2228 p.1.im \u2260 0) (h\u2082 : 0 < p.2.re) :\n  continuous_at (\u03bb x : \u2102 \u00d7 \u2102, x.1 ^ x.2) p :=\nbegin\n  cases p with z w,\n  rw [\u2190 not_lt_zero_iff, lt_iff_le_and_ne, not_and_distrib, ne.def, not_not, not_le_zero_iff] at h\u2081,\n  rcases h\u2081 with h\u2081|(rfl : z = 0),\n  exacts [continuous_at_cpow h\u2081, continuous_at_cpow_zero_of_re_pos h\u2082]\nend\n\n/-- See also `continuous_at_cpow_const` for a version that assumes `z \u2260 0` but makes no\nassumptions about `w`. -/\nlemma continuous_at_cpow_const_of_re_pos {z w : \u2102} (hz : 0 \u2264 re z \u2228 im z \u2260 0) (hw : 0 < re w) :\n  continuous_at (\u03bb x, x ^ w) z :=\ntendsto.comp (@continuous_at_cpow_of_re_pos (z, w) hz hw)\n  (continuous_at_id.prod continuous_at_const)\n\n/-- Continuity of `(x, y) \u21a6 x ^ y` as a function on `\u211d \u00d7 \u2102`. -/\nlemma continuous_at_of_real_cpow (x : \u211d) (y : \u2102) (h : 0 < y.re \u2228 x \u2260 0) :\n  continuous_at (\u03bb p, \u2191p.1 ^ p.2 : \u211d \u00d7 \u2102 \u2192 \u2102) (x, y) :=\nbegin\n  rcases lt_trichotomy 0 x with hx | rfl | hx,\n  { -- x > 0 : easy case\n    have : continuous_at (\u03bb p, \u27e8\u2191p.1, p.2\u27e9 : \u211d \u00d7 \u2102 \u2192 \u2102 \u00d7 \u2102) (x, y),\n      from continuous_of_real.continuous_at.prod_map continuous_at_id,\n    refine (continuous_at_cpow (or.inl _)).comp this,\n    rwa of_real_re },\n  { -- x = 0 : reduce to continuous_at_cpow_zero_of_re_pos\n    have A : continuous_at (\u03bb p, p.1 ^ p.2 : \u2102 \u00d7 \u2102 \u2192 \u2102) \u27e8\u2191(0:\u211d), y\u27e9,\n    { rw of_real_zero,\n      apply continuous_at_cpow_zero_of_re_pos,\n      tauto },\n    have B : continuous_at (\u03bb p, \u27e8\u2191p.1, p.2\u27e9 : \u211d \u00d7 \u2102 \u2192 \u2102 \u00d7 \u2102) \u27e80, y\u27e9,\n      from continuous_of_real.continuous_at.prod_map continuous_at_id,\n    exact @continuous_at.comp (\u211d \u00d7 \u2102) (\u2102 \u00d7 \u2102) \u2102 _ _ _ _ (\u03bb p, \u27e8\u2191p.1, p.2\u27e9) \u27e80, y\u27e9 A B },\n  { -- x < 0 : difficult case\n    suffices : continuous_at (\u03bb p, (-\u2191p.1) ^ p.2 * exp (\u03c0 * I * p.2) : \u211d \u00d7 \u2102 \u2192 \u2102) (x, y),\n    { refine this.congr (eventually_of_mem (prod_mem_nhds (Iio_mem_nhds hx) univ_mem) _),\n      exact \u03bb p hp, (of_real_cpow_of_nonpos (le_of_lt hp.1) p.2).symm },\n    have A : continuous_at (\u03bb p, \u27e8-\u2191p.1, p.2\u27e9 : \u211d \u00d7 \u2102 \u2192 \u2102 \u00d7 \u2102) (x, y),\n      from continuous_at.prod_map (continuous_of_real.continuous_at.neg) continuous_at_id,\n    apply continuous_at.mul,\n    { refine (continuous_at_cpow (or.inl _)).comp A,\n      rwa [neg_re, of_real_re, neg_pos] },\n    { exact (continuous_exp.comp (continuous_const.mul continuous_snd)).continuous_at } },\nend\n\nlemma continuous_at_of_real_cpow_const (x : \u211d) (y : \u2102) (h : 0 < y.re \u2228 x \u2260 0) :\n  continuous_at (\u03bb a, a ^ y : \u211d \u2192 \u2102) x :=\n@continuous_at.comp _ _ _ _ _ _ _ _ x (continuous_at_of_real_cpow x y h)\n  (continuous_id.prod_mk continuous_const).continuous_at\n\nlemma continuous_of_real_cpow_const {y : \u2102} (hs : 0 < y.re) : continuous (\u03bb x, x ^ y : \u211d \u2192 \u2102) :=\ncontinuous_iff_continuous_at.mpr (\u03bb x, continuous_at_of_real_cpow_const x y (or.inl hs))\n\nend complex\n\nnamespace nnreal\n\n/-- The nonnegative real power function `x^y`, defined for `x : \u211d\u22650` and `y : \u211d ` as the\nrestriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`,\none sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y \u2260 0`. -/\nnoncomputable def rpow (x : \u211d\u22650) (y : \u211d) : \u211d\u22650 :=\n\u27e8(x : \u211d) ^ y, real.rpow_nonneg_of_nonneg x.2 y\u27e9\n\nnoncomputable instance : has_pow \u211d\u22650 \u211d := \u27e8rpow\u27e9\n\n@[simp] lemma rpow_eq_pow (x : \u211d\u22650) (y : \u211d) : rpow x y = x ^ y := rfl\n\n@[simp, norm_cast] lemma coe_rpow (x : \u211d\u22650) (y : \u211d) : ((x ^ y : \u211d\u22650) : \u211d) = (x : \u211d) ^ y := rfl\n\n@[simp] lemma rpow_zero (x : \u211d\u22650) : x ^ (0 : \u211d) = 1 :=\nnnreal.eq $ real.rpow_zero _\n\n@[simp] lemma rpow_eq_zero_iff {x : \u211d\u22650} {y : \u211d} : x ^ y = 0 \u2194 x = 0 \u2227 y \u2260 0 :=\nbegin\n  rw [\u2190 nnreal.coe_eq, coe_rpow, \u2190 nnreal.coe_eq_zero],\n  exact real.rpow_eq_zero_iff_of_nonneg x.2\nend\n\n@[simp] lemma zero_rpow {x : \u211d} (h : x \u2260 0) : (0 : \u211d\u22650) ^ x = 0 :=\nnnreal.eq $ real.zero_rpow h\n\n@[simp] lemma rpow_one (x : \u211d\u22650) : x ^ (1 : \u211d) = x :=\nnnreal.eq $ real.rpow_one _\n\n@[simp] lemma one_rpow (x : \u211d) : (1 : \u211d\u22650) ^ x = 1 :=\nnnreal.eq $ real.one_rpow _\n\nlemma rpow_add {x : \u211d\u22650} (hx : x \u2260 0) (y z : \u211d) : x ^ (y + z) = x ^ y * x ^ z :=\nnnreal.eq $ real.rpow_add (pos_iff_ne_zero.2 hx) _ _\n\nlemma rpow_add' (x : \u211d\u22650) {y z : \u211d} (h : y + z \u2260 0) : x ^ (y + z) = x ^ y * x ^ z :=\nnnreal.eq $ real.rpow_add' x.2 h\n\nlemma rpow_mul (x : \u211d\u22650) (y z : \u211d) : x ^ (y * z) = (x ^ y) ^ z :=\nnnreal.eq $ real.rpow_mul x.2 y z\n\nlemma rpow_neg (x : \u211d\u22650) (y : \u211d) : x ^ -y = (x ^ y)\u207b\u00b9 :=\nnnreal.eq $ real.rpow_neg x.2 _\n\nlemma rpow_neg_one (x : \u211d\u22650) : x ^ (-1 : \u211d) = x \u207b\u00b9 :=\nby simp [rpow_neg]\n\nlemma rpow_sub {x : \u211d\u22650} (hx : x \u2260 0) (y z : \u211d) : x ^ (y - z) = x ^ y / x ^ z :=\nnnreal.eq $ real.rpow_sub (pos_iff_ne_zero.2 hx) y z\n\nlemma rpow_sub' (x : \u211d\u22650) {y z : \u211d} (h : y - z \u2260 0) :\n  x ^ (y - z) = x ^ y / x ^ z :=\nnnreal.eq $ real.rpow_sub' x.2 h\n\nlemma rpow_inv_rpow_self {y : \u211d} (hy : y \u2260 0) (x : \u211d\u22650) : (x ^ y) ^ (1 / y) = x :=\nby field_simp [\u2190 rpow_mul]\n\nlemma rpow_self_rpow_inv {y : \u211d} (hy : y \u2260 0) (x : \u211d\u22650) : (x ^ (1 / y)) ^ y = x :=\nby field_simp [\u2190 rpow_mul]\n\nlemma inv_rpow (x : \u211d\u22650) (y : \u211d) : (x\u207b\u00b9) ^ y = (x ^ y)\u207b\u00b9 :=\nnnreal.eq $ real.inv_rpow x.2 y\n\nlemma div_rpow (x y : \u211d\u22650) (z : \u211d) : (x / y) ^ z = x ^ z / y ^ z :=\nnnreal.eq $ real.div_rpow x.2 y.2 z\n\nlemma sqrt_eq_rpow (x : \u211d\u22650) : sqrt x = x ^ (1/(2:\u211d)) :=\nbegin\n  refine nnreal.eq _,\n  push_cast,\n  exact real.sqrt_eq_rpow x.1,\nend\n\n@[simp, norm_cast] lemma rpow_nat_cast (x : \u211d\u22650) (n : \u2115) : x ^ (n : \u211d) = x ^ n :=\nnnreal.eq $ by simpa only [coe_rpow, coe_pow] using real.rpow_nat_cast x n\n\n@[simp] lemma rpow_two (x : \u211d\u22650) : x ^ (2 : \u211d) = x ^ 2 :=\nby { rw \u2190 rpow_nat_cast, simp only [nat.cast_bit0, nat.cast_one] }\n\nlemma mul_rpow {x y : \u211d\u22650} {z : \u211d}  : (x*y)^z = x^z * y^z :=\nnnreal.eq $ real.mul_rpow x.2 y.2\n\nlemma rpow_le_rpow {x y : \u211d\u22650} {z: \u211d} (h\u2081 : x \u2264 y) (h\u2082 : 0 \u2264 z) : x^z \u2264 y^z :=\nreal.rpow_le_rpow x.2 h\u2081 h\u2082\n\nlemma rpow_lt_rpow {x y : \u211d\u22650} {z: \u211d} (h\u2081 : x < y) (h\u2082 : 0 < z) : x^z < y^z :=\nreal.rpow_lt_rpow x.2 h\u2081 h\u2082\n\nlemma rpow_lt_rpow_iff {x y : \u211d\u22650} {z : \u211d} (hz : 0 < z) : x ^ z < y ^ z \u2194 x < y :=\nreal.rpow_lt_rpow_iff x.2 y.2 hz\n\nlemma rpow_le_rpow_iff {x y : \u211d\u22650} {z : \u211d} (hz : 0 < z) : x ^ z \u2264 y ^ z \u2194 x \u2264 y :=\nreal.rpow_le_rpow_iff x.2 y.2 hz\n\nlemma le_rpow_one_div_iff {x y : \u211d\u22650} {z : \u211d} (hz : 0 < z) :  x \u2264 y ^ (1 / z) \u2194 x ^ z \u2264 y :=\nby rw [\u2190 rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne']\n\nlemma rpow_one_div_le_iff {x y : \u211d\u22650} {z : \u211d} (hz : 0 < z) :  x ^ (1 / z) \u2264 y \u2194 x \u2264 y ^ z :=\nby rw [\u2190 rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne']\n\nlemma rpow_lt_rpow_of_exponent_lt {x : \u211d\u22650} {y z : \u211d} (hx : 1 < x) (hyz : y < z) : x^y < x^z :=\nreal.rpow_lt_rpow_of_exponent_lt hx hyz\n\nlemma rpow_le_rpow_of_exponent_le {x : \u211d\u22650} {y z : \u211d} (hx : 1 \u2264 x) (hyz : y \u2264 z) : x^y \u2264 x^z :=\nreal.rpow_le_rpow_of_exponent_le hx hyz\n\nlemma rpow_lt_rpow_of_exponent_gt {x : \u211d\u22650} {y z : \u211d} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :\n  x^y < x^z :=\nreal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz\n\nlemma rpow_le_rpow_of_exponent_ge {x : \u211d\u22650} {y z : \u211d} (hx0 : 0 < x) (hx1 : x \u2264 1) (hyz : z \u2264 y) :\n  x^y \u2264 x^z :=\nreal.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz\n\nlemma rpow_pos {p : \u211d} {x : \u211d\u22650} (hx_pos : 0 < x) : 0 < x^p :=\nbegin\n  have rpow_pos_of_nonneg : \u2200 {p : \u211d}, 0 < p \u2192 0 < x^p,\n  { intros p hp_pos,\n    rw \u2190zero_rpow hp_pos.ne',\n    exact rpow_lt_rpow hx_pos hp_pos },\n  rcases lt_trichotomy 0 p with hp_pos|rfl|hp_neg,\n  { exact rpow_pos_of_nonneg hp_pos },\n  { simp only [zero_lt_one, rpow_zero] },\n  { rw [\u2190neg_neg p, rpow_neg, inv_pos],\n    exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) },\nend\n\nlemma rpow_lt_one {x : \u211d\u22650} {z : \u211d} (hx1 : x < 1) (hz : 0 < z) : x^z < 1 :=\nreal.rpow_lt_one (coe_nonneg x) hx1 hz\n\nlemma rpow_le_one {x : \u211d\u22650} {z : \u211d} (hx2 : x \u2264 1) (hz : 0 \u2264 z) : x^z \u2264 1 :=\nreal.rpow_le_one x.2 hx2 hz\n\nlemma rpow_lt_one_of_one_lt_of_neg {x : \u211d\u22650} {z : \u211d} (hx : 1 < x) (hz : z < 0) : x^z < 1 :=\nreal.rpow_lt_one_of_one_lt_of_neg hx hz\n\nlemma rpow_le_one_of_one_le_of_nonpos {x : \u211d\u22650} {z : \u211d} (hx : 1 \u2264 x) (hz : z \u2264 0) : x^z \u2264 1 :=\nreal.rpow_le_one_of_one_le_of_nonpos hx hz\n\nlemma one_lt_rpow {x : \u211d\u22650} {z : \u211d} (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=\nreal.one_lt_rpow hx hz\n\nlemma one_le_rpow {x : \u211d\u22650} {z : \u211d} (h : 1 \u2264 x) (h\u2081 : 0 \u2264 z) : 1 \u2264 x^z :=\nreal.one_le_rpow h h\u2081\n\nlemma one_lt_rpow_of_pos_of_lt_one_of_neg {x : \u211d\u22650} {z : \u211d} (hx1 : 0 < x) (hx2 : x < 1)\n  (hz : z < 0) : 1 < x^z :=\nreal.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz\n\nlemma one_le_rpow_of_pos_of_le_one_of_nonpos {x : \u211d\u22650} {z : \u211d} (hx1 : 0 < x) (hx2 : x \u2264 1)\n  (hz : z \u2264 0) : 1 \u2264 x^z :=\nreal.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz\n\nlemma rpow_le_self_of_le_one {x : \u211d\u22650} {z : \u211d} (hx : x \u2264 1) (h_one_le : 1 \u2264 z) : x ^ z \u2264 x :=\nbegin\n  rcases eq_bot_or_bot_lt x with rfl | (h : 0 < x),\n  { have : z \u2260 0 := by linarith,\n    simp [this] },\n  nth_rewrite 1 \u2190nnreal.rpow_one x,\n  exact nnreal.rpow_le_rpow_of_exponent_ge h hx h_one_le,\nend\n\nlemma rpow_left_injective {x : \u211d} (hx : x \u2260 0) : function.injective (\u03bb y : \u211d\u22650, y^x) :=\n\u03bb y z hyz, by simpa only [rpow_inv_rpow_self hx] using congr_arg (\u03bb y, y ^ (1 / x)) hyz\n\nlemma rpow_eq_rpow_iff {x y : \u211d\u22650} {z : \u211d} (hz : z \u2260 0) : x ^ z = y ^ z \u2194 x = y :=\n(rpow_left_injective hz).eq_iff\n\nlemma rpow_left_surjective {x : \u211d} (hx : x \u2260 0) : function.surjective (\u03bb y : \u211d\u22650, y^x) :=\n\u03bb y, \u27e8y ^ x\u207b\u00b9, by simp_rw [\u2190rpow_mul, _root_.inv_mul_cancel hx, rpow_one]\u27e9\n\nlemma rpow_left_bijective {x : \u211d} (hx : x \u2260 0) : function.bijective (\u03bb y : \u211d\u22650, y^x) :=\n\u27e8rpow_left_injective hx, rpow_left_surjective hx\u27e9\n\nlemma eq_rpow_one_div_iff {x y : \u211d\u22650} {z : \u211d} (hz : z \u2260 0) :  x = y ^ (1 / z) \u2194 x ^ z = y :=\nby rw [\u2190 rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz]\n\nlemma rpow_one_div_eq_iff {x y : \u211d\u22650} {z : \u211d} (hz : z \u2260 0) :  x ^ (1 / z) = y \u2194 x = y ^ z :=\nby rw [\u2190 rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz]\n\nlemma pow_nat_rpow_nat_inv (x : \u211d\u22650) {n : \u2115} (hn : n \u2260 0) :\n  (x ^ n) ^ (n\u207b\u00b9 : \u211d) = x :=\nby { rw [\u2190 nnreal.coe_eq, coe_rpow, nnreal.coe_pow], exact real.pow_nat_rpow_nat_inv x.2 hn }\n\nlemma rpow_nat_inv_pow_nat (x : \u211d\u22650) {n : \u2115} (hn : n \u2260 0) :\n  (x ^ (n\u207b\u00b9 : \u211d)) ^ n = x :=\nby { rw [\u2190 nnreal.coe_eq, nnreal.coe_pow, coe_rpow], exact real.rpow_nat_inv_pow_nat x.2 hn }\n\nlemma continuous_at_rpow {x : \u211d\u22650} {y : \u211d} (h : x \u2260 0 \u2228 0 < y) :\n  continuous_at (\u03bbp:\u211d\u22650\u00d7\u211d, p.1^p.2) (x, y) :=\nbegin\n  have : (\u03bbp:\u211d\u22650\u00d7\u211d, p.1^p.2) = real.to_nnreal \u2218 (\u03bbp:\u211d\u00d7\u211d, p.1^p.2) \u2218 (\u03bbp:\u211d\u22650 \u00d7 \u211d, (p.1.1, p.2)),\n  { ext p,\n    rw [coe_rpow, real.coe_to_nnreal _ (real.rpow_nonneg_of_nonneg p.1.2 _)],\n    refl },\n  rw this,\n  refine continuous_real_to_nnreal.continuous_at.comp (continuous_at.comp _ _),\n  { apply real.continuous_at_rpow,\n    simp only [ne.def] at h,\n    rw \u2190 (nnreal.coe_eq_zero x) at h,\n    exact h },\n  { exact ((continuous_subtype_val.comp continuous_fst).prod_mk continuous_snd).continuous_at }\nend\n\nlemma _root_.real.to_nnreal_rpow_of_nonneg {x y : \u211d} (hx : 0 \u2264 x) :\n  real.to_nnreal (x ^ y) = (real.to_nnreal x) ^ y :=\nbegin\n  nth_rewrite 0 \u2190 real.coe_to_nnreal x hx,\n  rw [\u2190nnreal.coe_rpow, real.to_nnreal_coe],\nend\n\nlemma eventually_pow_one_div_le (x : \u211d\u22650) {y : \u211d\u22650} (hy : 1 < y) :\n  \u2200\u1da0 (n : \u2115) in at_top, x ^ (1 / n : \u211d) \u2264 y :=\nbegin\n  obtain \u27e8m, hm\u27e9 := add_one_pow_unbounded_of_pos x (tsub_pos_of_lt hy),\n  rw [tsub_add_cancel_of_le hy.le] at hm,\n  refine eventually_at_top.2 \u27e8m + 1, \u03bb n hn, _\u27e9,\n  simpa only [nnreal.rpow_one_div_le_iff (nat.cast_pos.2 $ m.succ_pos.trans_le hn),\n    nnreal.rpow_nat_cast] using hm.le.trans (pow_le_pow hy.le (m.le_succ.trans hn)),\nend\n\nend nnreal\n\nnamespace real\nvariables {n : \u2115}\n\nlemma exists_rat_pow_btwn_rat_aux (hn : n \u2260 0) (x y : \u211d) (h : x < y) (hy : 0 < y) :\n  \u2203 q : \u211a, 0 < q \u2227 x < q^n \u2227 \u2191q^n < y :=\nbegin\n  have hn' : 0 < (n : \u211d) := by exact_mod_cast hn.bot_lt,\n  obtain \u27e8q, hxq, hqy\u27e9 := exists_rat_btwn (rpow_lt_rpow (le_max_left 0 x) (max_lt hy h) $\n    inv_pos.mpr hn'),\n  have := rpow_nonneg_of_nonneg (le_max_left 0 x) n\u207b\u00b9,\n  have hq := this.trans_lt hxq,\n  replace hxq := rpow_lt_rpow this hxq hn',\n  replace hqy := rpow_lt_rpow hq.le hqy hn',\n  rw [rpow_nat_cast, rpow_nat_cast, rpow_nat_inv_pow_nat _ hn] at hxq hqy,\n  exact \u27e8q, by exact_mod_cast hq, (le_max_right _ _).trans_lt hxq, hqy\u27e9,\n  { exact le_max_left _ _ },\n  { exact hy.le }\nend\n\nlemma exists_rat_pow_btwn_rat (hn : n \u2260 0) {x y : \u211a} (h : x < y) (hy : 0 < y) :\n  \u2203 q : \u211a, 0 < q \u2227 x < q^n \u2227 q^n < y :=\nby apply_mod_cast exists_rat_pow_btwn_rat_aux hn x y; assumption\n\n/-- There is a rational power between any two positive elements of an archimedean ordered field. -/\nlemma exists_rat_pow_btwn {\u03b1 : Type*} [linear_ordered_field \u03b1] [archimedean \u03b1] (hn : n \u2260 0)\n  {x y : \u03b1} (h : x < y) (hy : 0 < y) : \u2203 q : \u211a, 0 < q \u2227 x < q^n \u2227 (q^n : \u03b1) < y :=\nbegin\n  obtain \u27e8q\u2082, hx\u2082, hy\u2082\u27e9 := exists_rat_btwn (max_lt h hy),\n  obtain \u27e8q\u2081, hx\u2081, hq\u2081\u2082\u27e9 := exists_rat_btwn hx\u2082,\n  have : (0 : \u03b1) < q\u2082 := (le_max_right _ _).trans_lt hx\u2082,\n  norm_cast at hq\u2081\u2082 this,\n  obtain \u27e8q, hq, hq\u2081, hq\u2082\u27e9 := exists_rat_pow_btwn_rat hn hq\u2081\u2082 this,\n  refine \u27e8q, hq, (le_max_left _ _).trans_lt $ hx\u2081.trans _, hy\u2082.trans' _\u27e9; assumption_mod_cast,\nend\n\nend real\n\nopen filter\n\nlemma filter.tendsto.nnrpow {\u03b1 : Type*} {f : filter \u03b1} {u : \u03b1 \u2192 \u211d\u22650} {v : \u03b1 \u2192 \u211d} {x : \u211d\u22650} {y : \u211d}\n  (hx : tendsto u f (\ud835\udcdd x)) (hy : tendsto v f (\ud835\udcdd y)) (h : x \u2260 0 \u2228 0 < y) :\n  tendsto (\u03bb a, (u a) ^ (v a)) f (\ud835\udcdd (x ^ y)) :=\ntendsto.comp (nnreal.continuous_at_rpow h) (hx.prod_mk_nhds hy)\n\nnamespace nnreal\n\nlemma continuous_at_rpow_const {x : \u211d\u22650} {y : \u211d} (h : x \u2260 0 \u2228 0 \u2264 y) :\n  continuous_at (\u03bb z, z^y) x :=\nh.elim (\u03bb h, tendsto_id.nnrpow tendsto_const_nhds (or.inl h)) $\n  \u03bb h, h.eq_or_lt.elim\n    (\u03bb h, h \u25b8 by simp only [rpow_zero, continuous_at_const])\n    (\u03bb h, tendsto_id.nnrpow tendsto_const_nhds (or.inr h))\n\nlemma continuous_rpow_const {y : \u211d} (h : 0 \u2264 y) :\n  continuous (\u03bb x : \u211d\u22650, x^y) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, continuous_at_rpow_const (or.inr h)\n\ntheorem tendsto_rpow_at_top {y : \u211d} (hy : 0 < y) :\n  tendsto (\u03bb (x : \u211d\u22650), x ^ y) at_top at_top :=\nbegin\n  rw filter.tendsto_at_top_at_top,\n  intros b,\n  obtain \u27e8c, hc\u27e9 := tendsto_at_top_at_top.mp (tendsto_rpow_at_top hy) b,\n  use c.to_nnreal,\n  intros a ha,\n  exact_mod_cast hc a (real.to_nnreal_le_iff_le_coe.mp ha),\nend\n\nend nnreal\n\nnamespace ennreal\n\n/-- The real power function `x^y` on extended nonnegative reals, defined for `x : \u211d\u22650\u221e` and\n`y : \u211d` as the restriction of the real power function if `0 < x < \u22a4`, and with the natural values\nfor `0` and `\u22a4` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `\u22a4` for `x < 0`, and\n`\u22a4 ^ x = 1 / 0 ^ x`). -/\nnoncomputable def rpow : \u211d\u22650\u221e \u2192 \u211d \u2192 \u211d\u22650\u221e\n| (some x) y := if x = 0 \u2227 y < 0 then \u22a4 else (x ^ y : \u211d\u22650)\n| none     y := if 0 < y then \u22a4 else if y = 0 then 1 else 0\n\nnoncomputable instance : has_pow \u211d\u22650\u221e \u211d := \u27e8rpow\u27e9\n\n@[simp] lemma rpow_eq_pow (x : \u211d\u22650\u221e) (y : \u211d) : rpow x y = x ^ y := rfl\n\n@[simp] lemma rpow_zero {x : \u211d\u22650\u221e} : x ^ (0 : \u211d) = 1 :=\nby cases x; { dsimp only [(^), rpow], simp [lt_irrefl] }\n\nlemma top_rpow_def (y : \u211d) : (\u22a4 : \u211d\u22650\u221e) ^ y = if 0 < y then \u22a4 else if y = 0 then 1 else 0 :=\nrfl\n\n@[simp] lemma top_rpow_of_pos {y : \u211d} (h : 0 < y) : (\u22a4 : \u211d\u22650\u221e) ^ y = \u22a4 :=\nby simp [top_rpow_def, h]\n\n@[simp] lemma top_rpow_of_neg {y : \u211d} (h : y < 0) : (\u22a4 : \u211d\u22650\u221e) ^ y = 0 :=\nby simp [top_rpow_def, asymm h, ne_of_lt h]\n\n@[simp] lemma zero_rpow_of_pos {y : \u211d} (h : 0 < y) : (0 : \u211d\u22650\u221e) ^ y = 0 :=\nbegin\n  rw [\u2190 ennreal.coe_zero, \u2190 ennreal.some_eq_coe],\n  dsimp only [(^), rpow],\n  simp [h, asymm h, ne_of_gt h],\nend\n\n@[simp] lemma zero_rpow_of_neg {y : \u211d} (h : y < 0) : (0 : \u211d\u22650\u221e) ^ y = \u22a4 :=\nbegin\n  rw [\u2190 ennreal.coe_zero, \u2190 ennreal.some_eq_coe],\n  dsimp only [(^), rpow],\n  simp [h, ne_of_gt h],\nend\n\nlemma zero_rpow_def (y : \u211d) : (0 : \u211d\u22650\u221e) ^ y = if 0 < y then 0 else if y = 0 then 1 else \u22a4 :=\nbegin\n  rcases lt_trichotomy 0 y with H|rfl|H,\n  { simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] },\n  { simp [lt_irrefl] },\n  { simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] }\nend\n\n@[simp] lemma zero_rpow_mul_self (y : \u211d) : (0 : \u211d\u22650\u221e) ^ y * 0 ^ y = 0 ^ y :=\nby { rw zero_rpow_def, split_ifs, exacts [zero_mul _, one_mul _, top_mul_top] }\n\n@[norm_cast] lemma coe_rpow_of_ne_zero {x : \u211d\u22650} (h : x \u2260 0) (y : \u211d) :\n  (x : \u211d\u22650\u221e) ^ y = (x ^ y : \u211d\u22650) :=\nbegin\n  rw [\u2190 ennreal.some_eq_coe],\n  dsimp only [(^), rpow],\n  simp [h]\nend\n\n@[norm_cast] lemma coe_rpow_of_nonneg (x : \u211d\u22650) {y : \u211d} (h : 0 \u2264 y) :\n  (x : \u211d\u22650\u221e) ^ y = (x ^ y : \u211d\u22650) :=\nbegin\n  by_cases hx : x = 0,\n  { rcases le_iff_eq_or_lt.1 h with H|H,\n    { simp [hx, H.symm] },\n    { simp [hx, zero_rpow_of_pos H, nnreal.zero_rpow (ne_of_gt H)] } },\n  { exact coe_rpow_of_ne_zero hx _ }\nend\n\nlemma coe_rpow_def (x : \u211d\u22650) (y : \u211d) :\n  (x : \u211d\u22650\u221e) ^ y = if x = 0 \u2227 y < 0 then \u22a4 else (x ^ y : \u211d\u22650) := rfl\n\n@[simp] lemma rpow_one (x : \u211d\u22650\u221e) : x ^ (1 : \u211d) = x :=\nbegin\n  cases x,\n  { exact dif_pos zero_lt_one },\n  { change ite _ _ _ = _,\n    simp only [nnreal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp],\n    exact \u03bb _, zero_le_one.not_lt }\nend\n\n@[simp] lemma one_rpow (x : \u211d) : (1 : \u211d\u22650\u221e) ^ x = 1 :=\nby { rw [\u2190 coe_one, coe_rpow_of_ne_zero one_ne_zero], simp }\n\n@[simp] lemma rpow_eq_zero_iff {x : \u211d\u22650\u221e} {y : \u211d} :\n  x ^ y = 0 \u2194 (x = 0 \u2227 0 < y) \u2228 (x = \u22a4 \u2227 y < 0) :=\nbegin\n  cases x,\n  { rcases lt_trichotomy y 0 with H|H|H;\n    simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] },\n  { by_cases h : x = 0,\n    { rcases lt_trichotomy y 0 with H|H|H;\n      simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] },\n    { simp [coe_rpow_of_ne_zero h, h] } }\nend\n\n@[simp] lemma rpow_eq_top_iff {x : \u211d\u22650\u221e} {y : \u211d} :\n  x ^ y = \u22a4 \u2194 (x = 0 \u2227 y < 0) \u2228 (x = \u22a4 \u2227 0 < y) :=\nbegin\n  cases x,\n  { rcases lt_trichotomy y 0 with H|H|H;\n    simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] },\n  { by_cases h : x = 0,\n    { rcases lt_trichotomy y 0 with H|H|H;\n      simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] },\n    { simp [coe_rpow_of_ne_zero h, h] } }\nend\n\nlemma rpow_eq_top_iff_of_pos {x : \u211d\u22650\u221e} {y : \u211d} (hy : 0 < y) : x ^ y = \u22a4 \u2194 x = \u22a4 :=\nby simp [rpow_eq_top_iff, hy, asymm hy]\n\nlemma rpow_eq_top_of_nonneg (x : \u211d\u22650\u221e) {y : \u211d} (hy0 : 0 \u2264 y) : x ^ y = \u22a4 \u2192 x = \u22a4 :=\nbegin\n  rw ennreal.rpow_eq_top_iff,\n  intro h,\n  cases h,\n  { exfalso, rw lt_iff_not_ge at h, exact h.right hy0, },\n  { exact h.left, },\nend\n\nlemma rpow_ne_top_of_nonneg {x : \u211d\u22650\u221e} {y : \u211d} (hy0 : 0 \u2264 y) (h : x \u2260 \u22a4) : x ^ y \u2260 \u22a4 :=\nmt (ennreal.rpow_eq_top_of_nonneg x hy0) h\n\nlemma rpow_lt_top_of_nonneg {x : \u211d\u22650\u221e} {y : \u211d} (hy0 : 0 \u2264 y) (h : x \u2260 \u22a4) : x ^ y < \u22a4 :=\nlt_top_iff_ne_top.mpr (ennreal.rpow_ne_top_of_nonneg hy0 h)\n\nlemma rpow_add {x : \u211d\u22650\u221e} (y z : \u211d) (hx : x \u2260 0) (h'x : x \u2260 \u22a4) : x ^ (y + z) = x ^ y * x ^ z :=\nbegin\n  cases x, { exact (h'x rfl).elim },\n  have : x \u2260 0 := \u03bb h, by simpa [h] using hx,\n  simp [coe_rpow_of_ne_zero this, nnreal.rpow_add this]\nend\n\nlemma rpow_neg (x : \u211d\u22650\u221e) (y : \u211d) : x ^ -y = (x ^ y)\u207b\u00b9 :=\nbegin\n  cases x,\n  { rcases lt_trichotomy y 0 with H|H|H;\n    simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr] },\n  { by_cases h : x = 0,\n    { rcases lt_trichotomy y 0 with H|H|H;\n      simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr] },\n    { have A : x ^ y \u2260 0, by simp [h],\n      simp [coe_rpow_of_ne_zero h, \u2190 coe_inv A, nnreal.rpow_neg] } }\nend\n\nlemma rpow_sub {x : \u211d\u22650\u221e} (y z : \u211d) (hx : x \u2260 0) (h'x : x \u2260 \u22a4) : x ^ (y - z) = x ^ y / x ^ z :=\nby rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv]\n\nlemma rpow_neg_one (x : \u211d\u22650\u221e) : x ^ (-1 : \u211d) = x \u207b\u00b9 :=\nby simp [rpow_neg]\n\nlemma rpow_mul (x : \u211d\u22650\u221e) (y z : \u211d) : x ^ (y * z) = (x ^ y) ^ z :=\nbegin\n  cases x,\n  { rcases lt_trichotomy y 0 with Hy|Hy|Hy;\n    rcases lt_trichotomy z 0 with Hz|Hz|Hz;\n    simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,\n          mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] },\n  { by_cases h : x = 0,\n    { rcases lt_trichotomy y 0 with Hy|Hy|Hy;\n      rcases lt_trichotomy z 0 with Hz|Hz|Hz;\n      simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,\n            mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] },\n    { have : x ^ y \u2260 0, by simp [h],\n      simp [coe_rpow_of_ne_zero h, coe_rpow_of_ne_zero this, nnreal.rpow_mul] } }\nend\n\n@[simp, norm_cast] lemma rpow_nat_cast (x : \u211d\u22650\u221e) (n : \u2115) : x ^ (n : \u211d) = x ^ n :=\nbegin\n  cases x,\n  { cases n;\n    simp [top_rpow_of_pos (nat.cast_add_one_pos _), top_pow (nat.succ_pos _)] },\n  { simp [coe_rpow_of_nonneg _ (nat.cast_nonneg n)] }\nend\n\n@[simp] lemma rpow_two (x : \u211d\u22650\u221e) : x ^ (2 : \u211d) = x ^ 2 :=\nby { rw \u2190 rpow_nat_cast, simp only [nat.cast_bit0, nat.cast_one] }\n\nlemma mul_rpow_eq_ite (x y : \u211d\u22650\u221e) (z : \u211d) :\n  (x * y) ^ z = if (x = 0 \u2227 y = \u22a4 \u2228 x = \u22a4 \u2227 y = 0) \u2227 z < 0 then \u22a4 else x ^ z * y ^ z :=\nbegin\n  rcases eq_or_ne z 0 with rfl|hz, { simp },\n  replace hz := hz.lt_or_lt,\n  wlog hxy : x \u2264 y,\n  { convert this y x z hz (le_of_not_le hxy) using 2; simp only [mul_comm, and_comm, or_comm], },\n  rcases eq_or_ne x 0 with rfl|hx0,\n  { induction y using with_top.rec_top_coe; cases hz with hz hz; simp [*, hz.not_lt] },\n  rcases eq_or_ne y 0 with rfl|hy0, { exact (hx0 (bot_unique hxy)).elim },\n  induction x using with_top.rec_top_coe, { cases hz with hz hz; simp [hz, top_unique hxy] },\n  induction y using with_top.rec_top_coe, { cases hz with hz hz; simp * },\n  simp only [*, false_and, and_false, false_or, if_false],\n  norm_cast at *,\n  rw [coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), nnreal.mul_rpow]\nend\n\nlemma mul_rpow_of_ne_top {x y : \u211d\u22650\u221e} (hx : x \u2260 \u22a4) (hy : y \u2260 \u22a4) (z : \u211d) :\n  (x * y) ^ z = x^z * y^z :=\nby simp [*, mul_rpow_eq_ite]\n\n@[norm_cast] lemma coe_mul_rpow (x y : \u211d\u22650) (z : \u211d) :\n  ((x : \u211d\u22650\u221e) * y) ^ z = x^z * y^z :=\nmul_rpow_of_ne_top coe_ne_top coe_ne_top z\n\nlemma mul_rpow_of_ne_zero {x y : \u211d\u22650\u221e} (hx : x \u2260 0) (hy : y \u2260 0) (z : \u211d) :\n  (x * y) ^ z = x ^ z * y ^ z :=\nby simp [*, mul_rpow_eq_ite]\n\nlemma mul_rpow_of_nonneg (x y : \u211d\u22650\u221e) {z : \u211d} (hz : 0 \u2264 z) :\n  (x * y) ^ z = x ^ z * y ^ z :=\nby simp [hz.not_lt, mul_rpow_eq_ite]\n\nlemma inv_rpow (x : \u211d\u22650\u221e) (y : \u211d) : (x\u207b\u00b9) ^ y = (x ^ y)\u207b\u00b9 :=\nbegin\n  rcases eq_or_ne y 0 with rfl|hy, { simp only [rpow_zero, inv_one] },\n  replace hy := hy.lt_or_lt,\n  rcases eq_or_ne x 0 with rfl|h0, { cases hy; simp * },\n  rcases eq_or_ne x \u22a4 with rfl|h_top, { cases hy; simp * },\n  apply ennreal.eq_inv_of_mul_eq_one_left,\n  rw [\u2190 mul_rpow_of_ne_zero (ennreal.inv_ne_zero.2 h_top) h0, ennreal.inv_mul_cancel h0 h_top,\n    one_rpow]\nend\n\nlemma div_rpow_of_nonneg (x y : \u211d\u22650\u221e) {z : \u211d} (hz : 0 \u2264 z) :\n  (x / y) ^ z = x ^ z / y ^ z :=\nby rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv]\n\nlemma strict_mono_rpow_of_pos {z : \u211d} (h : 0 < z) : strict_mono (\u03bb x : \u211d\u22650\u221e, x ^ z) :=\nbegin\n  intros x y hxy,\n  lift x to \u211d\u22650 using ne_top_of_lt hxy,\n  rcases eq_or_ne y \u221e with rfl|hy,\n  { simp only [top_rpow_of_pos h, coe_rpow_of_nonneg _ h.le, coe_lt_top] },\n  { lift y to \u211d\u22650 using hy,\n    simp only [coe_rpow_of_nonneg _ h.le, nnreal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe] }\nend\n\nlemma monotone_rpow_of_nonneg {z : \u211d} (h : 0 \u2264 z) : monotone (\u03bb x : \u211d\u22650\u221e, x ^ z) :=\nh.eq_or_lt.elim (\u03bb h0, h0 \u25b8 by simp only [rpow_zero, monotone_const])\n  (\u03bb h0, (strict_mono_rpow_of_pos h0).monotone)\n\n/-- Bundles `\u03bb x : \u211d\u22650\u221e, x ^ y` into an order isomorphism when `y : \u211d` is positive,\nwhere the inverse is `\u03bb x : \u211d\u22650\u221e, x ^ (1 / y)`. -/\n@[simps apply] def order_iso_rpow (y : \u211d) (hy : 0 < y) : \u211d\u22650\u221e \u2243o \u211d\u22650\u221e :=\n(strict_mono_rpow_of_pos hy).order_iso_of_right_inverse (\u03bb x, x ^ y) (\u03bb x, x ^ (1 / y))\n  (\u03bb x, by { dsimp, rw [\u2190rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] })\n\nlemma order_iso_rpow_symm_apply (y : \u211d) (hy : 0 < y) :\n  (order_iso_rpow y hy).symm = order_iso_rpow (1 / y) (one_div_pos.2 hy) :=\nby { simp only [order_iso_rpow, one_div_one_div], refl }\n\nlemma rpow_le_rpow {x y : \u211d\u22650\u221e} {z : \u211d} (h\u2081 : x \u2264 y) (h\u2082 : 0 \u2264 z) : x^z \u2264 y^z :=\nmonotone_rpow_of_nonneg h\u2082 h\u2081\n\nlemma rpow_lt_rpow {x y : \u211d\u22650\u221e} {z : \u211d} (h\u2081 : x < y) (h\u2082 : 0 < z) : x^z < y^z :=\nstrict_mono_rpow_of_pos h\u2082 h\u2081\n\nlemma rpow_le_rpow_iff {x y : \u211d\u22650\u221e} {z : \u211d} (hz : 0 < z) : x ^ z \u2264 y ^ z \u2194 x \u2264 y :=\n(strict_mono_rpow_of_pos hz).le_iff_le\n\nlemma rpow_lt_rpow_iff {x y : \u211d\u22650\u221e} {z : \u211d} (hz : 0 < z) :  x ^ z < y ^ z \u2194 x < y :=\n(strict_mono_rpow_of_pos hz).lt_iff_lt\n\nlemma le_rpow_one_div_iff {x y : \u211d\u22650\u221e} {z : \u211d} (hz : 0 < z) :  x \u2264 y ^ (1 / z) \u2194 x ^ z \u2264 y :=\nbegin\n  nth_rewrite 0 \u2190rpow_one x,\n  nth_rewrite 0 \u2190@_root_.mul_inv_cancel _ _ z  hz.ne',\n  rw [rpow_mul, \u2190one_div, @rpow_le_rpow_iff _ _ (1/z) (by simp [hz])],\nend\n\nlemma lt_rpow_one_div_iff {x y : \u211d\u22650\u221e} {z : \u211d} (hz : 0 < z) : x < y ^ (1 / z) \u2194 x ^ z < y :=\nbegin\n  nth_rewrite 0 \u2190rpow_one x,\n  nth_rewrite 0 \u2190@_root_.mul_inv_cancel _ _ z (ne_of_lt hz).symm,\n  rw [rpow_mul, \u2190one_div, @rpow_lt_rpow_iff _ _ (1/z) (by simp [hz])],\nend\n\nlemma rpow_one_div_le_iff {x y : \u211d\u22650\u221e} {z : \u211d} (hz : 0 < z) : x ^ (1 / z) \u2264 y \u2194 x \u2264 y ^ z :=\nbegin\n  nth_rewrite 0 \u2190 ennreal.rpow_one y,\n  nth_rewrite 1 \u2190 @_root_.mul_inv_cancel _ _ z hz.ne.symm,\n  rw [ennreal.rpow_mul, \u2190 one_div, ennreal.rpow_le_rpow_iff (one_div_pos.2 hz)],\nend\n\nlemma rpow_lt_rpow_of_exponent_lt {x : \u211d\u22650\u221e} {y z : \u211d} (hx : 1 < x) (hx' : x \u2260 \u22a4) (hyz : y < z) :\n  x^y < x^z :=\nbegin\n  lift x to \u211d\u22650 using hx',\n  rw [one_lt_coe_iff] at hx,\n  simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),\n        nnreal.rpow_lt_rpow_of_exponent_lt hx hyz]\nend\n\nlemma rpow_le_rpow_of_exponent_le {x : \u211d\u22650\u221e} {y z : \u211d} (hx : 1 \u2264 x) (hyz : y \u2264 z) : x^y \u2264 x^z :=\nbegin\n  cases x,\n  { rcases lt_trichotomy y 0 with Hy|Hy|Hy;\n    rcases lt_trichotomy z 0 with Hz|Hz|Hz;\n    simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl];\n    linarith },\n  { simp only [one_le_coe_iff, some_eq_coe] at hx,\n    simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),\n          nnreal.rpow_le_rpow_of_exponent_le hx hyz] }\nend\n\nlemma rpow_lt_rpow_of_exponent_gt {x : \u211d\u22650\u221e} {y z : \u211d} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :\n  x^y < x^z :=\nbegin\n  lift x to \u211d\u22650 using ne_of_lt (lt_of_lt_of_le hx1 le_top),\n  simp only [coe_lt_one_iff, coe_pos] at hx0 hx1,\n  simp [coe_rpow_of_ne_zero (ne_of_gt hx0), nnreal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz]\nend\n\nlemma rpow_le_rpow_of_exponent_ge {x : \u211d\u22650\u221e} {y z : \u211d} (hx1 : x \u2264 1) (hyz : z \u2264 y) :\n  x^y \u2264 x^z :=\nbegin\n  lift x to \u211d\u22650 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top),\n  by_cases h : x = 0,\n  { rcases lt_trichotomy y 0 with Hy|Hy|Hy;\n    rcases lt_trichotomy z 0 with Hz|Hz|Hz;\n    simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl];\n    linarith },\n  { rw [coe_le_one_iff] at hx1,\n    simp [coe_rpow_of_ne_zero h,\n          nnreal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz] }\nend\n\nlemma rpow_le_self_of_le_one {x : \u211d\u22650\u221e} {z : \u211d} (hx : x \u2264 1) (h_one_le : 1 \u2264 z) : x ^ z \u2264 x :=\nbegin\n  nth_rewrite 1 \u2190ennreal.rpow_one x,\n  exact ennreal.rpow_le_rpow_of_exponent_ge hx h_one_le,\nend\n\nlemma le_rpow_self_of_one_le {x : \u211d\u22650\u221e} {z : \u211d} (hx : 1 \u2264 x) (h_one_le : 1 \u2264 z) : x \u2264 x ^ z :=\nbegin\n  nth_rewrite 0 \u2190ennreal.rpow_one x,\n  exact ennreal.rpow_le_rpow_of_exponent_le hx h_one_le,\nend\n\nlemma rpow_pos_of_nonneg {p : \u211d} {x : \u211d\u22650\u221e} (hx_pos : 0 < x) (hp_nonneg : 0 \u2264 p) : 0 < x^p :=\nbegin\n  by_cases hp_zero : p = 0,\n  { simp [hp_zero, zero_lt_one], },\n  { rw \u2190ne.def at hp_zero,\n    have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm,\n    rw \u2190zero_rpow_of_pos hp_pos, exact rpow_lt_rpow hx_pos hp_pos, },\nend\n\nlemma rpow_pos {p : \u211d} {x : \u211d\u22650\u221e} (hx_pos : 0 < x) (hx_ne_top : x \u2260 \u22a4) : 0 < x^p :=\nbegin\n  cases lt_or_le 0 p with hp_pos hp_nonpos,\n  { exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos), },\n  { rw [\u2190neg_neg p, rpow_neg, ennreal.inv_pos],\n    exact rpow_ne_top_of_nonneg (right.nonneg_neg_iff.mpr hp_nonpos) hx_ne_top, },\nend\n\nlemma rpow_lt_one {x : \u211d\u22650\u221e} {z : \u211d} (hx : x < 1) (hz : 0 < z) : x^z < 1 :=\nbegin\n  lift x to \u211d\u22650 using ne_of_lt (lt_of_lt_of_le hx le_top),\n  simp only [coe_lt_one_iff] at hx,\n  simp [coe_rpow_of_nonneg _ (le_of_lt hz), nnreal.rpow_lt_one hx hz],\nend\n\nlemma rpow_le_one {x : \u211d\u22650\u221e} {z : \u211d} (hx : x \u2264 1) (hz : 0 \u2264 z) : x^z \u2264 1 :=\nbegin\n  lift x to \u211d\u22650 using ne_of_lt (lt_of_le_of_lt hx coe_lt_top),\n  simp only [coe_le_one_iff] at hx,\n  simp [coe_rpow_of_nonneg _ hz, nnreal.rpow_le_one hx hz],\nend\n\nlemma rpow_lt_one_of_one_lt_of_neg {x : \u211d\u22650\u221e} {z : \u211d} (hx : 1 < x) (hz : z < 0) : x^z < 1 :=\nbegin\n  cases x,\n  { simp [top_rpow_of_neg hz, zero_lt_one] },\n  { simp only [some_eq_coe, one_lt_coe_iff] at hx,\n    simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),\n          nnreal.rpow_lt_one_of_one_lt_of_neg hx hz] },\nend\n\nlemma rpow_le_one_of_one_le_of_neg {x : \u211d\u22650\u221e} {z : \u211d} (hx : 1 \u2264 x) (hz : z < 0) : x^z \u2264 1 :=\nbegin\n  cases x,\n  { simp [top_rpow_of_neg hz, zero_lt_one] },\n  { simp only [one_le_coe_iff, some_eq_coe] at hx,\n    simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),\n          nnreal.rpow_le_one_of_one_le_of_nonpos hx (le_of_lt hz)] },\nend\n\nlemma one_lt_rpow {x : \u211d\u22650\u221e} {z : \u211d} (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=\nbegin\n  cases x,\n  { simp [top_rpow_of_pos hz] },\n  { simp only [some_eq_coe, one_lt_coe_iff] at hx,\n    simp [coe_rpow_of_nonneg _ (le_of_lt hz), nnreal.one_lt_rpow hx hz] }\nend\n\nlemma one_le_rpow {x : \u211d\u22650\u221e} {z : \u211d} (hx : 1 \u2264 x) (hz : 0 < z) : 1 \u2264 x^z :=\nbegin\n  cases x,\n  { simp [top_rpow_of_pos hz] },\n  { simp only [one_le_coe_iff, some_eq_coe] at hx,\n    simp [coe_rpow_of_nonneg _ (le_of_lt hz), nnreal.one_le_rpow hx (le_of_lt hz)] },\nend\n\nlemma one_lt_rpow_of_pos_of_lt_one_of_neg {x : \u211d\u22650\u221e} {z : \u211d} (hx1 : 0 < x) (hx2 : x < 1)\n  (hz : z < 0) : 1 < x^z :=\nbegin\n  lift x to \u211d\u22650 using ne_of_lt (lt_of_lt_of_le hx2 le_top),\n  simp only [coe_lt_one_iff, coe_pos] at \u22a2 hx1 hx2,\n  simp [coe_rpow_of_ne_zero (ne_of_gt hx1), nnreal.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz],\nend\n\nlemma one_le_rpow_of_pos_of_le_one_of_neg {x : \u211d\u22650\u221e} {z : \u211d} (hx1 : 0 < x) (hx2 : x \u2264 1)\n  (hz : z < 0) : 1 \u2264 x^z :=\nbegin\n  lift x to \u211d\u22650 using ne_of_lt (lt_of_le_of_lt hx2 coe_lt_top),\n  simp only [coe_le_one_iff, coe_pos] at \u22a2 hx1 hx2,\n  simp [coe_rpow_of_ne_zero (ne_of_gt hx1),\n        nnreal.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 (le_of_lt hz)],\nend\n\nlemma to_nnreal_rpow (x : \u211d\u22650\u221e) (z : \u211d) : (x.to_nnreal) ^ z = (x ^ z).to_nnreal :=\nbegin\n  rcases lt_trichotomy z 0 with H|H|H,\n  { cases x, { simp [H, ne_of_lt] },\n    by_cases hx : x = 0,\n    { simp [hx, H, ne_of_lt] },\n    { simp [coe_rpow_of_ne_zero hx] } },\n  { simp [H] },\n  { cases x, { simp [H, ne_of_gt] },\n    simp [coe_rpow_of_nonneg _ (le_of_lt H)] }\nend\n\nlemma to_real_rpow (x : \u211d\u22650\u221e) (z : \u211d) : (x.to_real) ^ z = (x ^ z).to_real :=\nby rw [ennreal.to_real, ennreal.to_real, \u2190nnreal.coe_rpow, ennreal.to_nnreal_rpow]\n\nlemma of_real_rpow_of_pos {x p : \u211d} (hx_pos : 0 < x) :\n  ennreal.of_real x ^ p = ennreal.of_real (x ^ p) :=\nbegin\n  simp_rw ennreal.of_real,\n  rw [coe_rpow_of_ne_zero, coe_eq_coe, real.to_nnreal_rpow_of_nonneg hx_pos.le],\n  simp [hx_pos],\nend\n\nlemma of_real_rpow_of_nonneg {x p : \u211d} (hx_nonneg : 0 \u2264 x) (hp_nonneg : 0 \u2264 p) :\n  ennreal.of_real x ^ p = ennreal.of_real (x ^ p) :=\nbegin\n  by_cases hp0 : p = 0,\n  { simp [hp0], },\n  by_cases hx0 : x = 0,\n  { rw \u2190 ne.def at hp0,\n    have hp_pos : 0 < p := lt_of_le_of_ne hp_nonneg hp0.symm,\n    simp [hx0, hp_pos, hp_pos.ne.symm], },\n  rw \u2190 ne.def at hx0,\n  exact of_real_rpow_of_pos (hx_nonneg.lt_of_ne hx0.symm),\nend\n\nlemma rpow_left_injective {x : \u211d} (hx : x \u2260 0) :\n  function.injective (\u03bb y : \u211d\u22650\u221e, y^x) :=\nbegin\n  intros y z hyz,\n  dsimp only at hyz,\n  rw [\u2190rpow_one y, \u2190rpow_one z, \u2190_root_.mul_inv_cancel hx, rpow_mul, rpow_mul, hyz],\nend\n\nlemma rpow_left_surjective {x : \u211d} (hx : x \u2260 0) :\n  function.surjective (\u03bb y : \u211d\u22650\u221e, y^x) :=\n\u03bb y, \u27e8y ^ x\u207b\u00b9, by simp_rw [\u2190rpow_mul, _root_.inv_mul_cancel hx, rpow_one]\u27e9\n\nlemma rpow_left_bijective {x : \u211d} (hx : x \u2260 0) :\n  function.bijective (\u03bb y : \u211d\u22650\u221e, y^x) :=\n\u27e8rpow_left_injective hx, rpow_left_surjective hx\u27e9\n\ntheorem tendsto_rpow_at_top {y : \u211d} (hy : 0 < y) :\n  tendsto (\u03bb (x : \u211d\u22650\u221e), x ^ y) (\ud835\udcdd \u22a4) (\ud835\udcdd \u22a4) :=\nbegin\n  rw tendsto_nhds_top_iff_nnreal,\n  intros x,\n  obtain \u27e8c, _, hc\u27e9 :=\n    (at_top_basis_Ioi.tendsto_iff at_top_basis_Ioi).mp (nnreal.tendsto_rpow_at_top hy) x trivial,\n  have hc' : set.Ioi (\u2191c) \u2208 \ud835\udcdd (\u22a4 : \u211d\u22650\u221e) := Ioi_mem_nhds coe_lt_top,\n  refine eventually_of_mem hc' _,\n  intros a ha,\n  by_cases ha' : a = \u22a4,\n  { simp [ha', hy] },\n  lift a to \u211d\u22650 using ha',\n  change \u2191c < \u2191a at ha,\n  rw coe_rpow_of_nonneg _ hy.le,\n  exact_mod_cast hc a (by exact_mod_cast ha),\nend\n\nlemma eventually_pow_one_div_le {x : \u211d\u22650\u221e} (hx : x \u2260 \u221e) {y : \u211d\u22650\u221e} (hy : 1 < y) :\n  \u2200\u1da0 (n : \u2115) in at_top, x ^ (1 / n : \u211d) \u2264 y :=\nbegin\n  lift x to \u211d\u22650 using hx,\n  by_cases y = \u221e,\n  { exact eventually_of_forall (\u03bb n, h.symm \u25b8 le_top) },\n  { lift y to \u211d\u22650 using h,\n    have := nnreal.eventually_pow_one_div_le x (by exact_mod_cast hy : 1 < y),\n    refine this.congr (eventually_of_forall $ \u03bb n, _),\n    rw [coe_rpow_of_nonneg x (by positivity : 0 \u2264 (1 / n : \u211d)), coe_le_coe] },\nend\n\nprivate lemma continuous_at_rpow_const_of_pos {x : \u211d\u22650\u221e} {y : \u211d} (h : 0 < y) :\n  continuous_at (\u03bb a : \u211d\u22650\u221e, a ^ y) x :=\nbegin\n  by_cases hx : x = \u22a4,\n  { rw [hx, continuous_at],\n    convert tendsto_rpow_at_top h,\n    simp [h] },\n  lift x to \u211d\u22650 using hx,\n  rw continuous_at_coe_iff,\n  convert continuous_coe.continuous_at.comp\n    (nnreal.continuous_at_rpow_const (or.inr h.le)) using 1,\n  ext1 x,\n  simp [coe_rpow_of_nonneg _ h.le]\nend\n\n@[continuity]\nlemma continuous_rpow_const {y : \u211d} : continuous (\u03bb a : \u211d\u22650\u221e, a ^ y) :=\nbegin\n  apply continuous_iff_continuous_at.2 (\u03bb x, _),\n  rcases lt_trichotomy 0 y with hy|rfl|hy,\n  { exact continuous_at_rpow_const_of_pos hy },\n  { simp only [rpow_zero], exact continuous_at_const },\n  { obtain \u27e8z, hz\u27e9 : \u2203 z, y = -z := \u27e8-y, (neg_neg _).symm\u27e9,\n    have z_pos : 0 < z, by simpa [hz] using hy,\n    simp_rw [hz, rpow_neg],\n    exact continuous_inv.continuous_at.comp (continuous_at_rpow_const_of_pos z_pos) }\nend\n\nlemma tendsto_const_mul_rpow_nhds_zero_of_pos {c : \u211d\u22650\u221e} (hc : c \u2260 \u221e) {y : \u211d} (hy : 0 < y) :\n  tendsto (\u03bb x : \u211d\u22650\u221e, c * x ^ y) (\ud835\udcdd 0) (\ud835\udcdd 0) :=\nbegin\n  convert ennreal.tendsto.const_mul (ennreal.continuous_rpow_const.tendsto 0) _,\n  { simp [hy] },\n  { exact or.inr hc }\nend\n\nend ennreal\n\nlemma filter.tendsto.ennrpow_const {\u03b1 : Type*} {f : filter \u03b1} {m : \u03b1 \u2192 \u211d\u22650\u221e} {a : \u211d\u22650\u221e} (r : \u211d)\n  (hm : tendsto m f (\ud835\udcdd a)) :\n  tendsto (\u03bb x, (m x) ^ r) f (\ud835\udcdd (a ^ r)) :=\n(ennreal.continuous_rpow_const.tendsto a).comp hm\n\nnamespace norm_num\nopen tactic\n\ntheorem rpow_pos (a b : \u211d) (b' : \u2115) (c : \u211d) (hb : (b':\u211d) = b) (h : a ^ b' = c) : a ^ b = c :=\nby rw [\u2190 h, \u2190 hb, real.rpow_nat_cast]\ntheorem rpow_neg (a b : \u211d) (b' : \u2115) (c c' : \u211d)\n  (a0 : 0 \u2264 a) (hb : (b':\u211d) = b) (h : a ^ b' = c) (hc : c\u207b\u00b9 = c') : a ^ -b = c' :=\nby rw [\u2190 hc, \u2190 h, \u2190 hb, real.rpow_neg a0, real.rpow_nat_cast]\n\n/-- Evaluate `real.rpow a b` where `a` is a rational numeral and `b` is an integer.\n(This cannot go via the generalized version `prove_rpow'` because `rpow_pos` has a side condition;\nwe do not attempt to evaluate `a ^ b` where `a` and `b` are both negative because it comes\nout to some garbage.) -/\nmeta def prove_rpow (a b : expr) : tactic (expr \u00d7 expr) := do\n  na \u2190 a.to_rat,\n  ic \u2190 mk_instance_cache `(\u211d),\n  match match_sign b with\n  | sum.inl b := do\n    (ic, a0) \u2190 guard (na \u2265 0) >> prove_nonneg ic a,\n    nc \u2190 mk_instance_cache `(\u2115),\n    (ic, nc, b', hb) \u2190 prove_nat_uncast ic nc b,\n    (ic, c, h) \u2190 prove_pow a na ic b',\n    cr \u2190 c.to_rat,\n    (ic, c', hc) \u2190 prove_inv ic c cr,\n    pure (c', (expr.const ``rpow_neg []).mk_app [a, b, b', c, c', a0, hb, h, hc])\n  | sum.inr ff := pure (`(1:\u211d), expr.const ``real.rpow_zero [] a)\n  | sum.inr tt := do\n    nc \u2190 mk_instance_cache `(\u2115),\n    (ic, nc, b', hb) \u2190 prove_nat_uncast ic nc b,\n    (ic, c, h) \u2190 prove_pow a na ic b',\n    pure (c, (expr.const ``rpow_pos []).mk_app [a, b, b', c, hb, h])\n  end\n\n/-- Generalized version of `prove_cpow`, `prove_nnrpow`, `prove_ennrpow`. -/\nmeta def prove_rpow' (pos neg zero : name) (\u03b1 \u03b2 one a b : expr) : tactic (expr \u00d7 expr) := do\n  na \u2190 a.to_rat,\n  ic\u03b1 \u2190 mk_instance_cache \u03b1,\n  ic\u03b2 \u2190 mk_instance_cache \u03b2,\n  match match_sign b with\n  | sum.inl b := do\n    nc \u2190 mk_instance_cache `(\u2115),\n    (ic\u03b2, nc, b', hb) \u2190 prove_nat_uncast ic\u03b2 nc b,\n    (ic\u03b1, c, h) \u2190 prove_pow a na ic\u03b1 b',\n    cr \u2190 c.to_rat,\n    (ic\u03b1, c', hc) \u2190 prove_inv ic\u03b1 c cr,\n    pure (c', (expr.const neg []).mk_app [a, b, b', c, c', hb, h, hc])\n  | sum.inr ff := pure (one, expr.const zero [] a)\n  | sum.inr tt := do\n    nc \u2190 mk_instance_cache `(\u2115),\n    (ic\u03b2, nc, b', hb) \u2190 prove_nat_uncast ic\u03b2 nc b,\n    (ic\u03b1, c, h) \u2190 prove_pow a na ic\u03b1 b',\n    pure (c, (expr.const pos []).mk_app [a, b, b', c, hb, h])\n  end\n\nopen_locale nnreal ennreal\n\ntheorem cpow_pos (a b : \u2102) (b' : \u2115) (c : \u2102) (hb : b = b') (h : a ^ b' = c) : a ^ b = c :=\nby rw [\u2190 h, hb, complex.cpow_nat_cast]\ntheorem cpow_neg (a b : \u2102) (b' : \u2115) (c c' : \u2102)\n  (hb : b = b') (h : a ^ b' = c) (hc : c\u207b\u00b9 = c') : a ^ -b = c' :=\nby rw [\u2190 hc, \u2190 h, hb, complex.cpow_neg, complex.cpow_nat_cast]\n\ntheorem nnrpow_pos (a : \u211d\u22650) (b : \u211d) (b' : \u2115) (c : \u211d\u22650)\n  (hb : b = b') (h : a ^ b' = c) : a ^ b = c :=\nby rw [\u2190 h, hb, nnreal.rpow_nat_cast]\ntheorem nnrpow_neg (a : \u211d\u22650) (b : \u211d) (b' : \u2115) (c c' : \u211d\u22650)\n  (hb : b = b') (h : a ^ b' = c) (hc : c\u207b\u00b9 = c') : a ^ -b = c' :=\nby rw [\u2190 hc, \u2190 h, hb, nnreal.rpow_neg, nnreal.rpow_nat_cast]\n\ntheorem ennrpow_pos (a : \u211d\u22650\u221e) (b : \u211d) (b' : \u2115) (c : \u211d\u22650\u221e)\n  (hb : b = b') (h : a ^ b' = c) : a ^ b = c :=\nby rw [\u2190 h, hb, ennreal.rpow_nat_cast]\ntheorem ennrpow_neg (a : \u211d\u22650\u221e) (b : \u211d) (b' : \u2115) (c c' : \u211d\u22650\u221e)\n  (hb : b = b') (h : a ^ b' = c) (hc : c\u207b\u00b9 = c') : a ^ -b = c' :=\nby rw [\u2190 hc, \u2190 h, hb, ennreal.rpow_neg, ennreal.rpow_nat_cast]\n\n/-- Evaluate `complex.cpow a b` where `a` is a rational numeral and `b` is an integer. -/\nmeta def prove_cpow : expr \u2192 expr \u2192 tactic (expr \u00d7 expr) :=\nprove_rpow' ``cpow_pos ``cpow_neg ``complex.cpow_zero `(\u2102) `(\u2102) `(1:\u2102)\n\n/-- Evaluate `nnreal.rpow a b` where `a` is a rational numeral and `b` is an integer. -/\nmeta def prove_nnrpow : expr \u2192 expr \u2192 tactic (expr \u00d7 expr) :=\nprove_rpow' ``nnrpow_pos ``nnrpow_neg ``nnreal.rpow_zero `(\u211d\u22650) `(\u211d) `(1:\u211d\u22650)\n\n/-- Evaluate `ennreal.rpow a b` where `a` is a rational numeral and `b` is an integer. -/\nmeta def prove_ennrpow : expr \u2192 expr \u2192 tactic (expr \u00d7 expr) :=\nprove_rpow' ``ennrpow_pos ``ennrpow_neg ``ennreal.rpow_zero `(\u211d\u22650\u221e) `(\u211d) `(1:\u211d\u22650\u221e)\n\n/-- Evaluates expressions of the form `rpow a b`, `cpow a b` and `a ^ b` in the special case where\n`b` is an integer and `a` is a positive rational (so it's really just a rational power). -/\n@[norm_num] meta def eval_rpow_cpow : expr \u2192 tactic (expr \u00d7 expr)\n| `(@has_pow.pow _ _ real.has_pow %%a %%b) := b.to_int >> prove_rpow a b\n| `(real.rpow %%a %%b) := b.to_int >> prove_rpow a b\n| `(@has_pow.pow _ _ complex.has_pow %%a %%b) := b.to_int >> prove_cpow a b\n| `(complex.cpow %%a %%b) := b.to_int >> prove_cpow a b\n| `(@has_pow.pow _ _ nnreal.real.has_pow %%a %%b) := b.to_int >> prove_nnrpow a b\n| `(nnreal.rpow %%a %%b) := b.to_int >> prove_nnrpow a b\n| `(@has_pow.pow _ _ ennreal.real.has_pow %%a %%b) := b.to_int >> prove_ennrpow a b\n| `(ennreal.rpow %%a %%b) := b.to_int >> prove_ennrpow a b\n| _ := tactic.failed\n\nend norm_num\n\nnamespace tactic\nnamespace positivity\n\n/-- Auxiliary definition for the `positivity` tactic to handle real powers of reals. -/\nmeta def prove_rpow (a b : expr) : tactic strictness :=\ndo\n  strictness_a \u2190 core a,\n  match strictness_a with\n  | nonnegative p := nonnegative <$> mk_app ``real.rpow_nonneg_of_nonneg [p, b]\n  | positive p := positive <$> mk_app ``real.rpow_pos_of_pos [p, b]\n  | _ := failed\n  end\n\nprivate lemma nnrpow_pos {a : \u211d\u22650} (ha : 0 < a) (b : \u211d) : 0 < a ^ b := nnreal.rpow_pos ha\n\n/-- Auxiliary definition for the `positivity` tactic to handle real powers of nonnegative reals. -/\nmeta def prove_nnrpow (a b : expr) : tactic strictness :=\ndo\n  strictness_a \u2190 core a,\n  match strictness_a with\n  | positive p := positive <$> mk_app ``nnrpow_pos [p, b]\n  | _ := failed -- We already know `0 \u2264 x` for all `x : \u211d\u22650`\n  end\n\nprivate lemma ennrpow_pos {a : \u211d\u22650\u221e} {b : \u211d} (ha : 0 < a) (hb : 0 < b) : 0 < a ^ b :=\nennreal.rpow_pos_of_nonneg ha hb.le\n\n/-- Auxiliary definition for the `positivity` tactic to handle real powers of extended nonnegative\nreals. -/\nmeta def prove_ennrpow (a b : expr) : tactic strictness :=\ndo\n  strictness_a \u2190 core a,\n  strictness_b \u2190 core b,\n  match strictness_a, strictness_b with\n  | positive pa, positive pb := positive <$> mk_app ``ennrpow_pos [pa, pb]\n  | positive pa, nonnegative pb := positive <$> mk_app ``ennreal.rpow_pos_of_nonneg [pa, pb]\n  | _, _ := failed -- We already know `0 \u2264 x` for all `x : \u211d\u22650\u221e`\n  end\n\nend positivity\n\nopen positivity\n\n/-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the\nbase is nonnegative and positive when the base is positive. -/\n@[positivity]\nmeta def positivity_rpow : expr \u2192 tactic strictness\n| `(@has_pow.pow _ _ real.has_pow %%a %%b) := prove_rpow a b\n| `(real.rpow %%a %%b) := prove_rpow a b\n| `(@has_pow.pow _ _ nnreal.real.has_pow %%a %%b) := prove_nnrpow a b\n| `(nnreal.rpow %%a %%b) := prove_nnrpow a b\n| `(@has_pow.pow _ _ ennreal.real.has_pow %%a %%b) := prove_ennrpow a b\n| `(ennreal.rpow %%a %%b) := prove_ennrpow a b\n| _ := failed\n\nend tactic\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7132089525634829}}
{"text": "import data.fin\n\nnamespace fin\n\nlemma lt_or_eq_nat {n : \u2115} (i : fin n.succ) : (i : \u2115) < n \u2228 (i : \u2115) = n :=\nbegin\n  cases nat.decidable_lt i n with h,\n  {\n    right,\n    exact nat.eq_of_lt_succ_of_not_lt (fin.is_lt i) h,\n  },\n  {\n    left,\n    exact h,\n  }\nend\n\nlemma lt_coe_iff_val_lt {n m : \u2115} (i : fin n.succ) (hle : m < n.succ) :\n  (i : \u2115) < m \u2194 i < (m : fin n.succ) :=\nbegin\n  rw fin.lt_def,\n  repeat {rw fin.val_eq_coe},\n  rw fin.coe_coe_of_lt hle,\nend\n\nlemma lt_or_eq_fin {n : \u2115} (i : fin n.succ) : i < (n : fin n.succ) \u2228 i = (n : fin n.succ) :=\nbegin\n  cases fin.lt_or_eq_nat i with h,\n  {\n    left,\n    rw \u2190 fin.lt_coe_iff_val_lt i (nat.lt_succ_self _),\n    exact h,\n  },\n  {\n    right,\n    rw \u2190 fin.coe_coe_eq_self i,\n    have f := @congr_arg _ _ (i : \u2115) n fin.of_nat h,\n    simp only [fin.of_nat_eq_coe] at f,\n    exact f,\n  }\nend\n\n/-- converts an n-ary tuple to an n.succ-ary tuple -/\n@[simp] def x_val {A : Type*} {n} (x : A) (val : fin n \u2192 A) :\n  fin n.succ \u2192 A :=\n@fin.cases n (\u03bb _, A) x (\u03bb i, val i)\n\nend fin\n", "meta": {"author": "Jlh18", "repo": "ModelTheoryInLean8", "sha": "fbda7d869d4169b6e739bb74165e99ee03ca63d6", "save_path": "github-repos/lean/Jlh18-ModelTheoryInLean8", "path": "github-repos/lean/Jlh18-ModelTheoryInLean8/ModelTheoryInLean8-fbda7d869d4169b6e739bb74165e99ee03ca63d6/Trash/Rings/ToMathlib/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7132089498501902}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport data.fintype.basic\nimport data.list.sublists\nimport group_theory.subgroup.basic\n\n/-!\n# Free groups\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines free groups over a type. Furthermore, it is shown that the free group construction\nis an instance of a monad. For the result that `free_group` is the left adjoint to the forgetful\nfunctor from groups to types, see `algebra/category/Group/adjunctions`.\n\n## Main definitions\n\n* `free_group`/`free_add_group`: the free group (resp. free additive group) associated to a type\n  `\u03b1` defined as the words over `a : \u03b1 \u00d7 bool` modulo the relation `a * x * x\u207b\u00b9 * b = a * b`.\n* `free_group.mk`/`free_add_group.mk`: the canonical quotient map `list (\u03b1 \u00d7 bool) \u2192 free_group \u03b1`.\n* `free_group.of`/`free_add_group.of`: the canonical injection `\u03b1 \u2192 free_group \u03b1`.\n* `free_group.lift f`/`free_add_group.lift`: the canonical group homomorphism `free_group \u03b1 \u2192* G`\n  given a group `G` and a function `f : \u03b1 \u2192 G`.\n\n## Main statements\n\n* `free_group.church_rosser`/`free_add_group.church_rosser`: The Church-Rosser theorem for word\n  reduction (also known as Newman's diamond lemma).\n* `free_group.free_group_unit_equiv_int`: The free group over the one-point type\n  is isomorphic to the integers.\n* The free group construction is an instance of a monad.\n\n## Implementation details\n\nFirst we introduce the one step reduction relation `free_group.red.step`:\n`w * x * x\u207b\u00b9 * v   ~>   w * v`, its reflexive transitive closure `free_group.red.trans`\nand prove that its join is an equivalence relation. Then we introduce `free_group \u03b1` as a quotient\nover `free_group.red.step`.\n\nFor the additive version we introduce the same relation under a different name so that we can\ndistinguish the quotient types more easily.\n\n\n## Tags\n\nfree group, Newman's diamond lemma, Church-Rosser theorem\n-/\n\nopen relation\n\nuniverses u v w\n\nvariables {\u03b1 : Type u}\n\nlocal attribute [simp] list.append_eq_has_append\n\nrun_cmd to_additive.map_namespace `free_group `free_add_group\n\n/-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/\ninductive free_add_group.red.step : list (\u03b1 \u00d7 bool) \u2192 list (\u03b1 \u00d7 bool) \u2192 Prop\n| bnot {L\u2081 L\u2082 x b} : free_add_group.red.step (L\u2081 ++ (x, b) :: (x, bnot b) :: L\u2082) (L\u2081 ++ L\u2082)\nattribute [simp] free_add_group.red.step.bnot\n\n/-- Reduction step for the multiplicative free group relation: `w * x * x\u207b\u00b9 * v ~> w * v` -/\n@[to_additive]\ninductive free_group.red.step : list (\u03b1 \u00d7 bool) \u2192 list (\u03b1 \u00d7 bool) \u2192 Prop\n| bnot {L\u2081 L\u2082 x b} : free_group.red.step (L\u2081 ++ (x, b) :: (x, bnot b) :: L\u2082) (L\u2081 ++ L\u2082)\nattribute [simp] free_group.red.step.bnot\n\nnamespace free_group\n\nvariables {L L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)}\n\n/-- Reflexive-transitive closure of red.step -/\n@[to_additive \"Reflexive-transitive closure of red.step\"]\ndef red : list (\u03b1 \u00d7 bool) \u2192 list (\u03b1 \u00d7 bool) \u2192 Prop := refl_trans_gen red.step\n\n@[refl, to_additive] lemma red.refl : red L L := refl_trans_gen.refl\n@[trans, to_additive] lemma red.trans : red L\u2081 L\u2082 \u2192 red L\u2082 L\u2083 \u2192 red L\u2081 L\u2083 := refl_trans_gen.trans\n\nnamespace red\n\n/-- Predicate asserting that the word `w\u2081` can be reduced to `w\u2082` in one step, i.e. there are words\n`w\u2083 w\u2084` and letter `x` such that `w\u2081 = w\u2083xx\u207b\u00b9w\u2084` and `w\u2082 = w\u2083w\u2084`  -/\n@[to_additive\n\"Predicate asserting that the word `w\u2081` can be reduced to `w\u2082` in one step, i.e. there are words\n`w\u2083 w\u2084` and letter `x` such that `w\u2081 = w\u2083 + x + (-x) + w\u2084` and `w\u2082 = w\u2083w\u2084`\"]\ntheorem step.length : \u2200 {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 L\u2082.length + 2 = L\u2081.length\n| _ _ (@red.step.bnot _ L1 L2 x b) := by rw [list.length_append, list.length_append]; refl\n\n@[simp, to_additive]\nlemma step.bnot_rev {x b} : step (L\u2081 ++ (x, bnot b) :: (x, b) :: L\u2082) (L\u2081 ++ L\u2082) :=\nby cases b; from step.bnot\n\n@[simp, to_additive] lemma step.cons_bnot {x b} : red.step ((x, b) :: (x, bnot b) :: L) L :=\n@step.bnot _ [] _ _ _\n\n@[simp, to_additive] lemma step.cons_bnot_rev {x b} : red.step ((x, bnot b) :: (x, b) :: L) L :=\n@red.step.bnot_rev _ [] _ _ _\n\n@[to_additive]\ntheorem step.append_left : \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)}, step L\u2082 L\u2083 \u2192 step (L\u2081 ++ L\u2082) (L\u2081 ++ L\u2083)\n| _ _ _ red.step.bnot := by rw [\u2190 list.append_assoc, \u2190 list.append_assoc]; constructor\n\n@[to_additive]\ntheorem step.cons {x} (H : red.step L\u2081 L\u2082) : red.step (x :: L\u2081) (x :: L\u2082) :=\n@step.append_left _ [x] _ _ H\n\n@[to_additive]\ntheorem step.append_right : \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 step (L\u2081 ++ L\u2083) (L\u2082 ++ L\u2083)\n| _ _ _ red.step.bnot := by simp\n\n@[to_additive]\nlemma not_step_nil : \u00ac step [] L :=\nbegin\n  generalize h' : [] = L',\n  assume h,\n  cases h with L\u2081 L\u2082,\n  simp [list.nil_eq_append_iff] at h',\n  contradiction\nend\n\n@[to_additive]\nlemma step.cons_left_iff {a : \u03b1} {b : bool} :\n  step ((a, b) :: L\u2081) L\u2082 \u2194 (\u2203L, step L\u2081 L \u2227 L\u2082 = (a, b) :: L) \u2228 (L\u2081 = (a, bnot b)::L\u2082) :=\nbegin\n  split,\n  { generalize hL : ((a, b) :: L\u2081 : list _) = L,\n    rintro @\u27e8_ | \u27e8p, s'\u27e9, e, a', b'\u27e9,\n    { simp at hL, simp [*] },\n    { simp at hL,\n      rcases hL with \u27e8rfl, rfl\u27e9,\n      refine or.inl \u27e8s' ++ e, step.bnot, _\u27e9,\n      simp } },\n  { rintro (\u27e8L, h, rfl\u27e9 | rfl),\n    { exact step.cons h },\n    { exact step.cons_bnot } }\nend\n\n@[to_additive]\nlemma not_step_singleton : \u2200 {p : \u03b1 \u00d7 bool}, \u00ac step [p] L\n| (a, b) := by simp [step.cons_left_iff, not_step_nil]\n\n@[to_additive]\nlemma step.cons_cons_iff : \u2200{p : \u03b1 \u00d7 bool}, step (p :: L\u2081) (p :: L\u2082) \u2194 step L\u2081 L\u2082 :=\nby simp [step.cons_left_iff, iff_def, or_imp_distrib] {contextual := tt}\n\n@[to_additive]\nlemma step.append_left_iff : \u2200L, step (L ++ L\u2081) (L ++ L\u2082) \u2194 step L\u2081 L\u2082\n| [] := by simp\n| (p :: l) := by simp [step.append_left_iff l, step.cons_cons_iff]\n\n@[to_additive]\ntheorem step.diamond_aux : \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)} {x1 b1 x2 b2},\n  L\u2081 ++ (x1, b1) :: (x1, bnot b1) :: L\u2082 = L\u2083 ++ (x2, b2) :: (x2, bnot b2) :: L\u2084 \u2192\n  L\u2081 ++ L\u2082 = L\u2083 ++ L\u2084 \u2228 \u2203 L\u2085, red.step (L\u2081 ++ L\u2082) L\u2085 \u2227 red.step (L\u2083 ++ L\u2084) L\u2085\n| []        _ []        _ _ _ _ _ H := by injections; subst_vars; simp\n| []        _ [(x3,b3)] _ _ _ _ _ H := by injections; subst_vars; simp\n| [(x3,b3)] _ []        _ _ _ _ _ H := by injections; subst_vars; simp\n| []                     _ ((x3,b3)::(x4,b4)::tl) _ _ _ _ _ H :=\n  by injections; subst_vars; simp; right; exact \u27e8_, red.step.bnot, red.step.cons_bnot\u27e9\n| ((x3,b3)::(x4,b4)::tl) _ []                     _ _ _ _ _ H :=\n  by injections; subst_vars; simp; right; exact \u27e8_, red.step.cons_bnot, red.step.bnot\u27e9\n| ((x3,b3)::tl) _ ((x4,b4)::tl2) _ _ _ _ _ H :=\n  let \u27e8H1, H2\u27e9 := list.cons.inj H in\n  match step.diamond_aux H2 with\n    | or.inl H3 := or.inl $ by simp [H1, H3]\n    | or.inr \u27e8L\u2085, H3, H4\u27e9 := or.inr\n      \u27e8_, step.cons H3, by simpa [H1] using step.cons H4\u27e9\n  end\n\n@[to_additive]\ntheorem step.diamond : \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)},\n  red.step L\u2081 L\u2083 \u2192 red.step L\u2082 L\u2084 \u2192 L\u2081 = L\u2082 \u2192\n  L\u2083 = L\u2084 \u2228 \u2203 L\u2085, red.step L\u2083 L\u2085 \u2227 red.step L\u2084 L\u2085\n| _ _ _ _ red.step.bnot red.step.bnot H := step.diamond_aux H\n\n@[to_additive]\nlemma step.to_red : step L\u2081 L\u2082 \u2192 red L\u2081 L\u2082 :=\nrefl_trans_gen.single\n\n/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces\nto `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`\nrespectively. This is also known as Newman's diamond lemma. -/\n@[to_additive\n\"**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces\nto `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`\nrespectively. This is also known as Newman's diamond lemma.\"]\ntheorem church_rosser : red L\u2081 L\u2082 \u2192 red L\u2081 L\u2083 \u2192 join red L\u2082 L\u2083 :=\nrelation.church_rosser (assume a b c hab hac,\nmatch b, c, red.step.diamond hab hac rfl with\n| b, _, or.inl rfl           := \u27e8b, by refl, by refl\u27e9\n| b, c, or.inr \u27e8d, hbd, hcd\u27e9 := \u27e8d, refl_gen.single hbd, hcd.to_red\u27e9\nend)\n\n@[to_additive]\nlemma cons_cons {p} : red L\u2081 L\u2082 \u2192 red (p :: L\u2081) (p :: L\u2082) :=\nrefl_trans_gen.lift (list.cons p) (assume a b, step.cons)\n\n@[to_additive]\nlemma cons_cons_iff (p) : red (p :: L\u2081) (p :: L\u2082) \u2194 red L\u2081 L\u2082 :=\niff.intro\n  begin\n    generalize eq\u2081 : (p :: L\u2081 : list _) = LL\u2081,\n    generalize eq\u2082 : (p :: L\u2082 : list _) = LL\u2082,\n    assume h,\n    induction h using relation.refl_trans_gen.head_induction_on\n      with L\u2081 L\u2082 h\u2081\u2082 h ih\n      generalizing L\u2081 L\u2082,\n    { subst_vars, cases eq\u2082, constructor },\n    { subst_vars,\n      cases p with a b,\n      rw [step.cons_left_iff] at h\u2081\u2082,\n      rcases h\u2081\u2082 with \u27e8L, h\u2081\u2082, rfl\u27e9 | rfl,\n      { exact (ih rfl rfl).head h\u2081\u2082 },\n      { exact (cons_cons h).tail step.cons_bnot_rev } }\n  end\n  cons_cons\n\n@[to_additive]\nlemma append_append_left_iff : \u2200L, red (L ++ L\u2081) (L ++ L\u2082) \u2194 red L\u2081 L\u2082\n| []       := iff.rfl\n| (p :: L) := by simp [append_append_left_iff L, cons_cons_iff]\n\n@[to_additive]\nlemma append_append (h\u2081 : red L\u2081 L\u2083) (h\u2082 : red L\u2082 L\u2084) : red (L\u2081 ++ L\u2082) (L\u2083 ++ L\u2084) :=\n(h\u2081.lift (\u03bbL, L ++ L\u2082) (assume a b, step.append_right)).trans ((append_append_left_iff _).2 h\u2082)\n\n@[to_additive]\nlemma to_append_iff : red L (L\u2081 ++ L\u2082) \u2194 (\u2203L\u2083 L\u2084, L = L\u2083 ++ L\u2084 \u2227 red L\u2083 L\u2081 \u2227 red L\u2084 L\u2082) :=\niff.intro\n  begin\n    generalize eq : L\u2081 ++ L\u2082 = L\u2081\u2082,\n    assume h,\n    induction h with L' L\u2081\u2082 hLL' h ih generalizing L\u2081 L\u2082,\n    { exact \u27e8_, _, eq.symm, by refl, by refl\u27e9 },\n    { cases h with s e a b,\n      rcases list.append_eq_append_iff.1 eq with \u27e8s', rfl, rfl\u27e9 | \u27e8e', rfl, rfl\u27e9,\n      { have : L\u2081 ++ (s' ++ ((a, b) :: (a, bnot b) :: e)) =\n                 (L\u2081 ++ s') ++ ((a, b) :: (a, bnot b) :: e),\n        { simp },\n        rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9,\n        exact \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082.tail step.bnot\u27e9 },\n      { have : (s ++ ((a, b) :: (a, bnot b) :: e')) ++ L\u2082 =\n                 s ++ ((a, b) :: (a, bnot b) :: (e' ++ L\u2082)),\n        { simp },\n        rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9,\n        exact \u27e8w\u2081, w\u2082, rfl, h\u2081.tail step.bnot, h\u2082\u27e9 }, }\n  end\n  (assume \u27e8L\u2083, L\u2084, eq, h\u2083, h\u2084\u27e9, eq.symm \u25b8 append_append h\u2083 h\u2084)\n\n/-- The empty word `[]` only reduces to itself. -/\n@[to_additive \"The empty word `[]` only reduces to itself.\"]\ntheorem nil_iff : red [] L \u2194 L = [] :=\nrefl_trans_gen_iff_eq (assume l, red.not_step_nil)\n\n/-- A letter only reduces to itself. -/\n@[to_additive \"A letter only reduces to itself.\"]\ntheorem singleton_iff {x} : red [x] L\u2081 \u2194 L\u2081 = [x] :=\nrefl_trans_gen_iff_eq (assume l, not_step_singleton)\n\n/-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces\nto `x\u207b\u00b9` -/\n@[to_additive \"If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word,\nthen `w` reduces to `-x`.\"]\ntheorem cons_nil_iff_singleton {x b} : red ((x, b) :: L) [] \u2194 red L [(x, bnot b)] :=\niff.intro\n  (assume h,\n    have h\u2081 : red ((x, bnot b) :: (x, b) :: L) [(x, bnot b)], from cons_cons h,\n    have h\u2082 : red ((x, bnot b) :: (x, b) :: L) L, from refl_trans_gen.single step.cons_bnot_rev,\n    let \u27e8L', h\u2081, h\u2082\u27e9 := church_rosser h\u2081 h\u2082 in\n    by rw [singleton_iff] at h\u2081; subst L'; assumption)\n  (assume h, (cons_cons h).tail step.cons_bnot)\n\n@[to_additive]\ntheorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) \u2260 (x2, b2)) :\n  red [(x1, bnot b1), (x2, b2)] L \u2194 L = [(x1, bnot b1), (x2, b2)] :=\nbegin\n  apply refl_trans_gen_iff_eq,\n  generalize eq : [(x1, bnot b1), (x2, b2)] = L',\n  assume L h',\n  cases h',\n  simp [list.cons_eq_append_iff, list.nil_eq_append_iff] at eq,\n  rcases eq with \u27e8rfl, \u27e8rfl, rfl\u27e9, \u27e8rfl, rfl\u27e9, rfl\u27e9, subst_vars,\n  simp at h,\n  contradiction\nend\n\n/-- If `x` and `y` are distinct letters and `w\u2081 w\u2082` are words such that `xw\u2081` reduces to `yw\u2082`, then\n`w\u2081` reduces to `x\u207b\u00b9yw\u2082`. -/\n@[to_additive\n\"If `x` and `y` are distinct letters and `w\u2081 w\u2082` are words such that `x + w\u2081` reduces to `y + w\u2082`,\nthen `w\u2081` reduces to `-x + y + w\u2082`.\"]\ntheorem inv_of_red_of_ne {x1 b1 x2 b2}\n  (H1 : (x1, b1) \u2260 (x2, b2))\n  (H2 : red ((x1, b1) :: L\u2081) ((x2, b2) :: L\u2082)) :\n  red L\u2081 ((x1, bnot b1) :: (x2, b2) :: L\u2082) :=\nbegin\n  have : red ((x1, b1) :: L\u2081) ([(x2, b2)] ++ L\u2082), from H2,\n  rcases to_append_iff.1 this with \u27e8_ | \u27e8p, L\u2083\u27e9, L\u2084, eq, h\u2081, h\u2082\u27e9,\n  { simp [nil_iff] at h\u2081, contradiction },\n  { cases eq,\n    show red (L\u2083 ++ L\u2084) ([(x1, bnot b1), (x2, b2)] ++ L\u2082),\n    apply append_append _ h\u2082,\n    have h\u2081 : red ((x1, bnot b1) :: (x1, b1) :: L\u2083) [(x1, bnot b1), (x2, b2)],\n    { exact cons_cons h\u2081 },\n    have h\u2082 : red ((x1, bnot b1) :: (x1, b1) :: L\u2083) L\u2083,\n    { exact step.cons_bnot_rev.to_red },\n    rcases church_rosser h\u2081 h\u2082 with \u27e8L', h\u2081, h\u2082\u27e9,\n    rw [red_iff_irreducible H1] at h\u2081,\n    rwa [h\u2081] at h\u2082 }\nend\n\n@[to_additive]\ntheorem step.sublist (H : red.step L\u2081 L\u2082) : L\u2082 <+ L\u2081 :=\nby cases H; simp; constructor; constructor; refl\n\n/-- If `w\u2081 w\u2082` are words such that `w\u2081` reduces to `w\u2082`, then `w\u2082` is a sublist of `w\u2081`. -/\n@[to_additive \"If `w\u2081 w\u2082` are words such that `w\u2081` reduces to `w\u2082`,\nthen `w\u2082` is a sublist of `w\u2081`.\"]\nprotected theorem sublist : red L\u2081 L\u2082 \u2192 L\u2082 <+ L\u2081 :=\nrefl_trans_gen_of_transitive_reflexive\n  (\u03bbl, list.sublist.refl l) (\u03bba b c hab hbc, list.sublist.trans hbc hab) (\u03bba b, red.step.sublist)\n\n@[to_additive]\ntheorem length_le (h : red L\u2081 L\u2082) : L\u2082.length \u2264 L\u2081.length := h.sublist.length_le\n\n@[to_additive]\ntheorem sizeof_of_step : \u2200 {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)}, step L\u2081 L\u2082 \u2192 L\u2082.sizeof < L\u2081.sizeof\n| _ _ (@step.bnot _ L1 L2 x b) :=\n  begin\n    induction L1 with hd tl ih,\n    case list.nil\n    { dsimp [list.sizeof],\n      have H : 1 + sizeof (x, b) + (1 + sizeof (x, bnot b) + list.sizeof L2)\n        = (list.sizeof L2 + 1) + (sizeof (x, b) + sizeof (x, bnot b) + 1),\n      { ac_refl },\n      rw H,\n      exact nat.le_add_right _ _ },\n    case list.cons\n    { dsimp [list.sizeof],\n      exact nat.add_lt_add_left ih _ }\n  end\n\n@[to_additive]\ntheorem length (h : red L\u2081 L\u2082) : \u2203 n, L\u2081.length = L\u2082.length + 2 * n :=\nbegin\n  induction h with L\u2082 L\u2083 h\u2081\u2082 h\u2082\u2083 ih,\n  { exact \u27e80, rfl\u27e9 },\n  { rcases ih with \u27e8n, eq\u27e9,\n    existsi (1 + n),\n    simp [mul_add, eq, (step.length h\u2082\u2083).symm, add_assoc] }\nend\n\n@[to_additive]\ntheorem antisymm (h\u2081\u2082 : red L\u2081 L\u2082) (h\u2082\u2081 : red L\u2082 L\u2081) : L\u2081 = L\u2082 :=\nh\u2082\u2081.sublist.antisymm h\u2081\u2082.sublist\n\nend red\n\n@[to_additive]\ntheorem equivalence_join_red : equivalence (join (@red \u03b1)) :=\nequivalence_join_refl_trans_gen $ assume a b c hab hac,\n(match b, c, red.step.diamond hab hac rfl with\n| b, _, or.inl rfl           := \u27e8b, by refl, by refl\u27e9\n| b, c, or.inr \u27e8d, hbd, hcd\u27e9 := \u27e8d, refl_gen.single hbd, refl_trans_gen.single hcd\u27e9\nend)\n\n@[to_additive]\ntheorem join_red_of_step (h : red.step L\u2081 L\u2082) : join red L\u2081 L\u2082 :=\njoin_of_single reflexive_refl_trans_gen h.to_red\n\n@[to_additive]\ntheorem eqv_gen_step_iff_join_red : eqv_gen red.step L\u2081 L\u2082 \u2194 join red L\u2081 L\u2082 :=\niff.intro\n  (assume h,\n    have eqv_gen (join red) L\u2081 L\u2082 := h.mono (assume a b, join_red_of_step),\n    equivalence_join_red.eqv_gen_iff.1 this)\n  (join_of_equivalence (eqv_gen.is_equivalence _) $ assume a b,\n    refl_trans_gen_of_equivalence (eqv_gen.is_equivalence _) eqv_gen.rel)\n\nend free_group\n\n/-- The free group over a type, i.e. the words formed by the elements of the type and their formal\ninverses, quotient by one step reduction. -/\n@[to_additive \"The free additive group over a type, i.e. the words formed by the elements of the\ntype and their formal inverses, quotient by one step reduction.\"]\ndef free_group (\u03b1 : Type u) : Type u :=\nquot $ @free_group.red.step \u03b1\n\nnamespace free_group\n\nvariables {\u03b1} {L L\u2081 L\u2082 L\u2083 L\u2084 : list (\u03b1 \u00d7 bool)}\n\n/-- The canonical map from `list (\u03b1 \u00d7 bool)` to the free group on `\u03b1`. -/\n@[to_additive \"The canonical map from `list (\u03b1 \u00d7 bool)` to the free additive group on `\u03b1`.\"]\ndef mk (L) : free_group \u03b1 := quot.mk red.step L\n\n@[simp, to_additive] lemma quot_mk_eq_mk : quot.mk red.step L = mk L := rfl\n\n@[simp, to_additive] lemma quot_lift_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 \u03b2)\n  (H : \u2200 L\u2081 L\u2082, red.step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) :\nquot.lift f H (mk L) = f L := rfl\n\n@[simp, to_additive] lemma quot_lift_on_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 \u03b2)\n  (H : \u2200 L\u2081 L\u2082, red.step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) :\nquot.lift_on (mk L) f H = f L := rfl\n\n@[simp, to_additive] lemma quot_map_mk (\u03b2 : Type v) (f : list (\u03b1 \u00d7 bool) \u2192 list (\u03b2 \u00d7 bool))\n  (H : (red.step \u21d2 red.step) f f) :\nquot.map f H (mk L) = mk (f L) := rfl\n\n@[to_additive]\ninstance : has_one (free_group \u03b1) := \u27e8mk []\u27e9\n@[to_additive]\nlemma one_eq_mk : (1 : free_group \u03b1) = mk [] := rfl\n\n@[to_additive]\ninstance : inhabited (free_group \u03b1) := \u27e81\u27e9\n\n@[to_additive]\ninstance : has_mul (free_group \u03b1) :=\n\u27e8\u03bb x y, quot.lift_on x\n    (\u03bb L\u2081, quot.lift_on y (\u03bb L\u2082, mk $ L\u2081 ++ L\u2082) (\u03bb L\u2082 L\u2083 H, quot.sound $ red.step.append_left H))\n    (\u03bb L\u2081 L\u2082 H, quot.induction_on y $ \u03bb L\u2083, quot.sound $ red.step.append_right H)\u27e9\n@[simp, to_additive] lemma mul_mk : mk L\u2081 * mk L\u2082 = mk (L\u2081 ++ L\u2082) := rfl\n\n/-- Transform a word representing a free group element into a word representing its inverse. -/\n@[to_additive \"Transform a word representing a free group element into a word representing its\nnegative.\"]\ndef inv_rev (w : list (\u03b1 \u00d7 bool)) : list (\u03b1 \u00d7 bool) :=\n(list.map (\u03bb (g : \u03b1 \u00d7 bool), (g.1, bnot g.2)) w).reverse\n\n@[simp, to_additive] lemma inv_rev_length : (inv_rev L\u2081).length = L\u2081.length := by simp [inv_rev]\n@[simp, to_additive] lemma inv_rev_inv_rev : (inv_rev (inv_rev L\u2081) = L\u2081) := by simp [inv_rev, (\u2218)]\n@[simp, to_additive] lemma inv_rev_empty : inv_rev ([] : list (\u03b1 \u00d7 bool)) = [] := rfl\n\n@[to_additive]\nlemma inv_rev_involutive : function.involutive (@inv_rev \u03b1) := \u03bb _, inv_rev_inv_rev\n@[to_additive]\nlemma inv_rev_injective : function.injective (@inv_rev \u03b1) := inv_rev_involutive.injective\n@[to_additive]\nlemma inv_rev_surjective : function.surjective (@inv_rev \u03b1) := inv_rev_involutive.surjective\n@[to_additive]\nlemma inv_rev_bijective : function.bijective (@inv_rev \u03b1) := inv_rev_involutive.bijective\n\n@[to_additive]\ninstance : has_inv (free_group \u03b1) :=\n\u27e8quot.map inv_rev (by { intros a b h, cases h, simp [inv_rev], })\u27e9\n\n@[simp, to_additive] lemma inv_mk : (mk L)\u207b\u00b9 = mk (inv_rev L) := rfl\n\n@[to_additive]\nlemma red.step.inv_rev {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)} (h : red.step L\u2081 L\u2082) :\n  red.step (inv_rev L\u2081) (inv_rev L\u2082) :=\nbegin\n  cases h with a b x y,\n  simp [inv_rev],\nend\n\n@[to_additive]\nlemma red.inv_rev {L\u2081 L\u2082 : list (\u03b1 \u00d7 bool)} (h : red L\u2081 L\u2082) :\n  red (inv_rev L\u2081) (inv_rev L\u2082) :=\nrelation.refl_trans_gen.lift _ (\u03bb a b, red.step.inv_rev) h\n\n@[simp, to_additive]\nlemma red.step_inv_rev_iff : red.step (inv_rev L\u2081) (inv_rev L\u2082) \u2194 red.step L\u2081 L\u2082 :=\n\u27e8\u03bb h, by simpa only [inv_rev_inv_rev] using h.inv_rev, \u03bb h, h.inv_rev\u27e9\n\n@[simp, to_additive] lemma red_inv_rev_iff : red (inv_rev L\u2081) (inv_rev L\u2082) \u2194 red L\u2081 L\u2082 :=\n\u27e8\u03bb h, by simpa only [inv_rev_inv_rev] using h.inv_rev, \u03bb h, h.inv_rev\u27e9\n\n@[to_additive]\ninstance : group (free_group \u03b1) :=\n{ mul := (*),\n  one := 1,\n  inv := has_inv.inv,\n  mul_assoc := by rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9 \u27e8L\u2083\u27e9; simp,\n  one_mul := by rintros \u27e8L\u27e9; refl,\n  mul_one := by rintros \u27e8L\u27e9; simp [one_eq_mk],\n  mul_left_inv := by rintros \u27e8L\u27e9; exact (list.rec_on L rfl $\n    \u03bb \u27e8x, b\u27e9 tl ih, eq.trans (quot.sound $ by simp [inv_rev, one_eq_mk]) ih) }\n\n/-- `of` is the canonical injection from the type to the free group over that type by sending each\nelement to the equivalence class of the letter that is the element. -/\n@[to_additive \"`of` is the canonical injection from the type to the free group over that type\nby sending each element to the equivalence class of the letter that is the element.\"]\ndef of (x : \u03b1) : free_group \u03b1 :=\nmk [(x, tt)]\n\n@[to_additive]\ntheorem red.exact : mk L\u2081 = mk L\u2082 \u2194 join red L\u2081 L\u2082 :=\ncalc (mk L\u2081 = mk L\u2082) \u2194 eqv_gen red.step L\u2081 L\u2082 : iff.intro (quot.exact _) quot.eqv_gen_sound\n  ... \u2194 join red L\u2081 L\u2082 : eqv_gen_step_iff_join_red\n\n/-- The canonical map from the type to the free group is an injection. -/\n@[to_additive \"The canonical map from the type to the additive free group is an injection.\"]\ntheorem of_injective : function.injective (@of \u03b1) :=\n\u03bb _ _ H, let \u27e8L\u2081, hx, hy\u27e9 := red.exact.1 H in\n  by simp [red.singleton_iff] at hx hy; cc\n\nsection lift\n\nvariables {\u03b2 : Type v} [group \u03b2] (f : \u03b1 \u2192 \u03b2) {x y : free_group \u03b1}\n\n/-- Given `f : \u03b1 \u2192 \u03b2` with `\u03b2` a group, the canonical map `list (\u03b1 \u00d7 bool) \u2192 \u03b2` -/\n@[to_additive \"Given `f : \u03b1 \u2192 \u03b2` with `\u03b2` an additive group, the canonical map\n`list (\u03b1 \u00d7 bool) \u2192 \u03b2`\"]\ndef lift.aux : list (\u03b1 \u00d7 bool) \u2192 \u03b2 :=\n\u03bb L, list.prod $ L.map $ \u03bb x, cond x.2 (f x.1) (f x.1)\u207b\u00b9\n\n@[to_additive]\ntheorem red.step.lift {f : \u03b1 \u2192 \u03b2} (H : red.step L\u2081 L\u2082) :\n  lift.aux f L\u2081 = lift.aux f L\u2082 :=\nby cases H with _ _ _ b; cases b; simp [lift.aux]\n\n\n/-- If `\u03b2` is a group, then any function from `\u03b1` to `\u03b2`\nextends uniquely to a group homomorphism from\nthe free group over `\u03b1` to `\u03b2` -/\n@[to_additive \"If `\u03b2` is an additive group, then any function from `\u03b1` to `\u03b2`\nextends uniquely to an additive group homomorphism from\nthe free additive group over `\u03b1` to `\u03b2`\", simps symm_apply]\ndef lift : (\u03b1 \u2192 \u03b2) \u2243 (free_group \u03b1 \u2192* \u03b2) :=\n{ to_fun := \u03bb f,\n    monoid_hom.mk' (quot.lift (lift.aux f) $ \u03bb L\u2081 L\u2082, red.step.lift) $ begin\n      rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9, simp [lift.aux],\n    end,\n  inv_fun := \u03bb g, g \u2218 of,\n  left_inv := \u03bb f, one_mul _,\n  right_inv := \u03bb g, monoid_hom.ext $ begin\n    rintros \u27e8L\u27e9,\n    apply list.rec_on L,\n    { exact g.map_one.symm, },\n    { rintros \u27e8x, _ | _\u27e9 t (ih : _ = g (mk t)),\n      { show _ = g ((of x)\u207b\u00b9 * mk t),\n        simpa [lift.aux] using ih },\n      { show _ = g (of x * mk t),\n        simpa [lift.aux] using ih }, },\n  end }\nvariable {f}\n\n@[simp, to_additive] lemma lift.mk : lift f (mk L) =\n  list.prod (L.map $ \u03bb x, cond x.2 (f x.1) (f x.1)\u207b\u00b9) :=\nrfl\n\n@[simp, to_additive] lemma lift.of {x} : lift f (of x) = f x :=\none_mul _\n\n@[to_additive]\ntheorem lift.unique (g : free_group \u03b1 \u2192* \u03b2)\n  (hg : \u2200 x, g (of x) = f x) : \u2200{x}, g x = lift f x :=\nmonoid_hom.congr_fun $ (lift.symm_apply_eq).mp (funext hg : g \u2218 of = f)\n\n/-- Two homomorphisms out of a free group are equal if they are equal on generators.\n\nSee note [partially-applied ext lemmas]. -/\n@[ext, to_additive\n\"Two homomorphisms out of a free additive group are equal if they are equal on generators.\n\nSee note [partially-applied ext lemmas].\"]\nlemma ext_hom {G : Type*} [group G] (f g : free_group \u03b1 \u2192* G) (h : \u2200 a, f (of a) = g (of a)) :\n  f = g :=\nlift.symm.injective $ funext h\n\n@[to_additive]\ntheorem lift.of_eq (x : free_group \u03b1) : lift of x = x :=\nmonoid_hom.congr_fun (lift.apply_symm_apply (monoid_hom.id _)) x\n\n@[to_additive]\n\n\n@[to_additive]\ntheorem lift.range_eq_closure :\n  (lift f).range = subgroup.closure (set.range f) :=\nbegin\n  apply le_antisymm (lift.range_le subgroup.subset_closure),\n  rw subgroup.closure_le,\n  rintros _ \u27e8a, rfl\u27e9,\n  exact \u27e8of a, by simp only [lift.of]\u27e9,\nend\n\nend lift\n\nsection map\n\nvariables {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) {x y : free_group \u03b1}\n\n/-- Any function from `\u03b1` to `\u03b2` extends uniquely\nto a group homomorphism from the free group\nover `\u03b1` to the free group over `\u03b2`. -/\n@[to_additive \"Any function from `\u03b1` to `\u03b2` extends uniquely to an additive group homomorphism\nfrom the additive free group over `\u03b1` to the additive free group over `\u03b2`.\"]\ndef map : free_group \u03b1 \u2192* free_group \u03b2 :=\nmonoid_hom.mk'\n  (quot.map (list.map $ \u03bb x, (f x.1, x.2)) $ \u03bb L\u2081 L\u2082 H, by cases H; simp)\n  (by { rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9, simp })\n\nvariable {f}\n\n@[simp, to_additive] lemma map.mk : map f (mk L) = mk (L.map (\u03bb x, (f x.1, x.2))) :=\nrfl\n\n@[simp, to_additive] lemma map.id (x : free_group \u03b1) : map id x = x :=\nby rcases x with \u27e8L\u27e9; simp [list.map_id']\n\n@[simp, to_additive] lemma map.id' (x : free_group \u03b1) : map (\u03bb z, z) x = x := map.id x\n\n@[to_additive]\ntheorem map.comp {\u03b3 : Type w} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3) (x) :\n  map g (map f x) = map (g \u2218 f) x :=\nby rcases x with \u27e8L\u27e9; simp\n\n@[simp, to_additive] lemma map.of {x} : map f (of x) = of (f x) := rfl\n\n@[to_additive]\ntheorem map.unique (g : free_group \u03b1 \u2192* free_group \u03b2)\n  (hg : \u2200 x, g (of x) = of (f x)) : \u2200{x}, g x = map f x :=\nby rintros \u27e8L\u27e9; exact list.rec_on L g.map_one\n(\u03bb \u27e8x, b\u27e9 t (ih : g (mk t) = map f (mk t)), bool.rec_on b\n  (show g ((of x)\u207b\u00b9 * mk t) = map f ((of x)\u207b\u00b9 * mk t),\n     by simp [g.map_mul, g.map_inv, hg, ih])\n  (show g (of x * mk t) = map f (of x * mk t),\n     by simp [g.map_mul, hg, ih]))\n\n@[to_additive]\ntheorem map_eq_lift : map f x = lift (of \u2218 f) x :=\neq.symm $ map.unique _ $ \u03bb x, by simp\n\n/-- Equivalent types give rise to multiplicatively equivalent free groups.\n\nThe converse can be found in `group_theory.free_abelian_group_finsupp`,\nas `equiv.of_free_group_equiv`\n -/\n@[to_additive \"Equivalent types give rise to additively equivalent additive free groups.\",\nsimps apply]\ndef free_group_congr {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) : free_group \u03b1 \u2243* free_group \u03b2 :=\n{ to_fun := map e, inv_fun := map e.symm,\n  left_inv := \u03bb x, by simp [function.comp, map.comp],\n  right_inv := \u03bb x, by simp [function.comp, map.comp],\n  map_mul' := monoid_hom.map_mul _ }\n\n@[simp, to_additive]\nlemma free_group_congr_refl : free_group_congr (equiv.refl \u03b1) = mul_equiv.refl _ :=\nmul_equiv.ext map.id\n\n@[simp, to_additive] lemma free_group_congr_symm {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) :\n  (free_group_congr e).symm = free_group_congr e.symm :=\nrfl\n\n@[to_additive]\nlemma free_group_congr_trans {\u03b1 \u03b2 \u03b3} (e : \u03b1 \u2243 \u03b2) (f : \u03b2 \u2243 \u03b3) :\n  (free_group_congr e).trans (free_group_congr f) = free_group_congr (e.trans f) :=\nmul_equiv.ext $ map.comp _ _\n\nend map\n\nsection prod\n\nvariables [group \u03b1] (x y : free_group \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1`\nextends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the multiplicative\nversion of `free_group.sum`. -/\n@[to_additive\n\"If `\u03b1` is an additive group, then any function from `\u03b1` to `\u03b1`\nextends uniquely to an additive homomorphism from the\nadditive free group over `\u03b1` to `\u03b1`.\"]\ndef prod : free_group \u03b1 \u2192* \u03b1 := lift id\n\nvariables {x y}\n\n@[simp, to_additive] lemma prod_mk :\n  prod (mk L) = list.prod (L.map $ \u03bb x, cond x.2 x.1 x.1\u207b\u00b9) :=\nrfl\n\n@[simp, to_additive] lemma prod.of {x : \u03b1} : prod (of x) = x :=\nlift.of\n\n@[to_additive]\nlemma prod.unique (g : free_group \u03b1 \u2192* \u03b1)\n  (hg : \u2200 x, g (of x) = x) {x} :\n  g x = prod x :=\nlift.unique g hg\n\nend prod\n\n@[to_additive]\ntheorem lift_eq_prod_map {\u03b2 : Type v} [group \u03b2] {f : \u03b1 \u2192 \u03b2} {x} :\n  lift f x = prod (map f x) :=\nbegin\n  rw \u2190lift.unique (prod.comp (map f)),\n  { refl },\n  { simp }\nend\n\nsection sum\n\nvariables [add_group \u03b1] (x y : free_group \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1`\nextends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the additive\nversion of `prod`. -/\ndef sum : \u03b1 :=\n@prod (multiplicative _) _ x\n\nvariables {x y}\n\n@[simp] lemma sum_mk :\n  sum (mk L) = list.sum (L.map $ \u03bb x, cond x.2 x.1 (-x.1)) :=\nrfl\n\n@[simp] lemma sum.of {x : \u03b1} : sum (of x) = x :=\nprod.of\n\n-- note: there are no bundled homs with different notation in the domain and codomain, so we copy\n-- these manually\n@[simp] lemma sum.map_mul : sum (x * y) = sum x + sum y :=\n(@prod (multiplicative _) _).map_mul _ _\n\n@[simp] lemma sum.map_one : sum (1:free_group \u03b1) = 0 :=\n(@prod (multiplicative _) _).map_one\n\n@[simp] lemma sum.map_inv : sum x\u207b\u00b9 = -sum x :=\n(prod : free_group (multiplicative \u03b1) \u2192* multiplicative \u03b1).map_inv _\n\nend sum\n\n/-- The bijection between the free group on the empty type, and a type with one element. -/\n@[to_additive\n\"The bijection between the additive free group on the empty type, and a type with one element.\"]\ndef free_group_empty_equiv_unit : free_group empty \u2243 unit :=\n{ to_fun    := \u03bb _, (),\n  inv_fun   := \u03bb _, 1,\n  left_inv  := by rintros \u27e8_ | \u27e8\u27e8\u27e8\u27e9, _\u27e9, _\u27e9\u27e9; refl,\n  right_inv := \u03bb \u27e8\u27e9, rfl }\n\n/-- The bijection between the free group on a singleton, and the integers. -/\ndef free_group_unit_equiv_int : free_group unit \u2243 \u2124 :=\n{ to_fun    := \u03bb x,\n   sum begin revert x, apply monoid_hom.to_fun,\n    apply map (\u03bb _, (1 : \u2124)),\n  end,\n  inv_fun   := \u03bb x, of () ^ x,\n  left_inv  :=\n  begin\n    rintros \u27e8L\u27e9,\n    refine list.rec_on L rfl _,\n    exact (\u03bb \u27e8\u27e8\u27e9, b\u27e9 tl ih, by cases b; simp [zpow_add] at ih \u22a2; rw ih; refl),\n  end,\n  right_inv :=\n    \u03bb x, int.induction_on x (by simp)\n    (\u03bb i ih, by simp at ih; simp [zpow_add, ih])\n    (\u03bb i ih, by simp at ih; simp [zpow_add, ih, sub_eq_add_neg, -int.add_neg_one]) }\n\nsection category\n\nvariables {\u03b2 : Type u}\n\n@[to_additive]\ninstance : monad free_group.{u} :=\n{ pure := \u03bb \u03b1, of,\n  map := \u03bb \u03b1 \u03b2 f, (map f),\n  bind := \u03bb \u03b1 \u03b2 x f, lift f x }\n\n@[elab_as_eliminator, to_additive]\nprotected theorem induction_on\n  {C : free_group \u03b1 \u2192 Prop}\n  (z : free_group \u03b1)\n  (C1 : C 1)\n  (Cp : \u2200 x, C $ pure x)\n  (Ci : \u2200 x, C (pure x) \u2192 C (pure x)\u207b\u00b9)\n  (Cm : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) : C z :=\nquot.induction_on z $ \u03bb L, list.rec_on L C1 $ \u03bb \u27e8x, b\u27e9 tl ih,\nbool.rec_on b (Cm _ _ (Ci _ $ Cp x) ih) (Cm _ _ (Cp x) ih)\n\n@[simp, to_additive]\nlemma map_pure (f : \u03b1 \u2192 \u03b2) (x : \u03b1) : f <$> (pure x : free_group \u03b1) = pure (f x) := map.of\n\n@[simp, to_additive] lemma map_one (f : \u03b1 \u2192 \u03b2) : f <$> (1 : free_group \u03b1) = 1 :=\n(map f).map_one\n\n@[simp, to_additive]\nlemma map_mul (f : \u03b1 \u2192 \u03b2) (x y : free_group \u03b1) : f <$> (x * y) = f <$> x * f <$> y :=\n(map f).map_mul x y\n\n@[simp, to_additive] lemma map_inv (f : \u03b1 \u2192 \u03b2) (x : free_group \u03b1) : f <$> (x\u207b\u00b9) = (f <$> x)\u207b\u00b9 :=\n(map f).map_inv x\n\n@[simp, to_additive] lemma pure_bind (f : \u03b1 \u2192 free_group \u03b2) (x) : pure x >>= f = f x :=\nlift.of\n\n@[simp, to_additive] lemma one_bind (f : \u03b1 \u2192 free_group \u03b2) : 1 >>= f = 1 :=\n(lift f).map_one\n\n@[simp, to_additive] lemma mul_bind (f : \u03b1 \u2192 free_group \u03b2) (x y : free_group \u03b1) :\n  x * y >>= f = (x >>= f) * (y >>= f) :=\n(lift f).map_mul _ _\n\n@[simp, to_additive]\nlemma inv_bind (f : \u03b1 \u2192 free_group \u03b2) (x : free_group \u03b1) : x\u207b\u00b9 >>= f = (x >>= f)\u207b\u00b9 :=\n(lift f).map_inv _\n\n@[to_additive]\ninstance : is_lawful_monad free_group.{u} :=\n{ id_map := \u03bb \u03b1 x, free_group.induction_on x (map_one id) (\u03bb x, map_pure id x)\n    (\u03bb x ih, by rw [map_inv, ih]) (\u03bb x y ihx ihy, by rw [map_mul, ihx, ihy]),\n  pure_bind := \u03bb \u03b1 \u03b2 x f, pure_bind f x,\n  bind_assoc := \u03bb \u03b1 \u03b2 \u03b3 x f g, free_group.induction_on x\n    (by iterate 3 { rw one_bind }) (\u03bb x, by iterate 2 { rw pure_bind })\n    (\u03bb x ih, by iterate 3 { rw inv_bind }; rw ih)\n    (\u03bb x y ihx ihy, by iterate 3 { rw mul_bind }; rw [ihx, ihy]),\n  bind_pure_comp_eq_map := \u03bb \u03b1 \u03b2 f x, free_group.induction_on x\n    (by rw [one_bind, map_one]) (\u03bb x, by rw [pure_bind, map_pure])\n    (\u03bb x ih, by rw [inv_bind, map_inv, ih]) (\u03bb x y ihx ihy, by rw [mul_bind, map_mul, ihx, ihy]) }\n\nend category\n\nsection reduce\n\nvariable [decidable_eq \u03b1]\n\n/-- The maximal reduction of a word. It is computable\niff `\u03b1` has decidable equality. -/\n@[to_additive \"The maximal reduction of a word. It is computable\niff `\u03b1` has decidable equality.\"]\ndef reduce (L : list (\u03b1 \u00d7 bool)) : list (\u03b1 \u00d7 bool) :=\nlist.rec_on L [] $ \u03bb hd1 tl1 ih,\nlist.cases_on ih [hd1] $ \u03bb hd2 tl2,\nif hd1.1 = hd2.1 \u2227 hd1.2 = bnot hd2.2 then tl2\nelse hd1 :: hd2 :: tl2\n\n@[simp, to_additive] lemma reduce.cons (x) : reduce (x :: L) =\n  list.cases_on (reduce L) [x] (\u03bb hd tl,\n  if x.1 = hd.1 \u2227 x.2 = bnot hd.2 then tl\n  else x :: hd :: tl) := rfl\n\n/-- The first theorem that characterises the function\n`reduce`: a word reduces to its maximal reduction. -/\n@[to_additive\n\"The first theorem that characterises the function\n`reduce`: a word reduces to its maximal reduction.\"]\ntheorem reduce.red : red L (reduce L) :=\nbegin\n  induction L with hd1 tl1 ih,\n  case list.nil\n  { constructor },\n  case list.cons\n  { dsimp,\n    revert ih,\n    generalize htl : reduce tl1 = TL,\n    intro ih,\n    cases TL with hd2 tl2,\n    case list.nil\n    { exact red.cons_cons ih },\n    case list.cons\n    { dsimp only,\n      split_ifs with h,\n      { transitivity,\n        { exact red.cons_cons ih },\n        { cases hd1, cases hd2, cases h,\n          dsimp at *, subst_vars,\n          exact red.step.cons_bnot_rev.to_red } },\n      { exact red.cons_cons ih } } }\nend\n\n@[to_additive]\ntheorem reduce.not {p : Prop} :\n  \u2200 {L\u2081 L\u2082 L\u2083 : list (\u03b1 \u00d7 bool)} {x b}, reduce L\u2081 = L\u2082 ++ (x, b) :: (x, bnot b) :: L\u2083 \u2192 p\n| [] L2 L3 _ _ := \u03bb h, by cases L2; injections\n| ((x,b)::L1) L2 L3 x' b' := begin\n  dsimp,\n  cases r : reduce L1,\n  { dsimp, intro h,\n    have := congr_arg list.length h,\n    simp [-add_comm] at this,\n    exact absurd this dec_trivial },\n  cases hd with y c,\n  dsimp only,\n  split_ifs with h; intro H,\n  { rw H at r,\n    exact @reduce.not L1 ((y,c)::L2) L3 x' b' r },\n  rcases L2 with _|\u27e8a, L2\u27e9,\n  { injections, subst_vars,\n    simp at h, cc },\n  { refine @reduce.not L1 L2 L3 x' b' _,\n    injection H with _ H,\n    rw [r, H], refl }\nend\n\n/-- The second theorem that characterises the\nfunction `reduce`: the maximal reduction of a word\nonly reduces to itself. -/\n@[to_additive \"The second theorem that characterises the\nfunction `reduce`: the maximal reduction of a word\nonly reduces to itself.\"]\ntheorem reduce.min (H : red (reduce L\u2081) L\u2082) : reduce L\u2081 = L\u2082 :=\nbegin\n  induction H with L1 L' L2 H1 H2 ih,\n  { refl },\n  { cases H1 with L4 L5 x b,\n    exact reduce.not H2 }\nend\n\n/-- `reduce` is idempotent, i.e. the maximal reduction\nof the maximal reduction of a word is the maximal\nreduction of the word. -/\n@[simp, to_additive \"`reduce` is idempotent, i.e. the maximal reduction\nof the maximal reduction of a word is the maximal\nreduction of the word.\"] theorem reduce.idem : reduce (reduce L) = reduce L :=\neq.symm $ reduce.min reduce.red\n\n@[to_additive]\ntheorem reduce.step.eq (H : red.step L\u2081 L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, HR13, HR23\u27e9 := red.church_rosser reduce.red (reduce.red.head H) in\n(reduce.min HR13).trans (reduce.min HR23).symm\n\n/-- If a word reduces to another word, then they have\na common maximal reduction. -/\n@[to_additive \"If a word reduces to another word, then they have\na common maximal reduction.\"]\ntheorem reduce.eq_of_red (H : red L\u2081 L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, HR13, HR23\u27e9 := red.church_rosser reduce.red (red.trans H reduce.red) in\n(reduce.min HR13).trans (reduce.min HR23).symm\n\nalias reduce.eq_of_red \u2190 red.reduce_eq\nalias free_add_group.reduce.eq_of_red \u2190 free_add_group.red.reduce_eq\n\n@[to_additive]\nlemma red.reduce_right (h : red L\u2081 L\u2082) : red L\u2081 (reduce L\u2082) :=\nreduce.eq_of_red h \u25b8 reduce.red\n\n@[to_additive]\nlemma red.reduce_left (h : red L\u2081 L\u2082) : red L\u2082 (reduce L\u2081) :=\n(reduce.eq_of_red h).symm \u25b8 reduce.red\n\n/-- If two words correspond to the same element in\nthe free group, then they have a common maximal\nreduction. This is the proof that the function that\nsends an element of the free group to its maximal\nreduction is well-defined. -/\n@[to_additive\n\"If two words correspond to the same element in\nthe additive free group, then they have a common maximal\nreduction. This is the proof that the function that\nsends an element of the free group to its maximal\nreduction is well-defined.\"]\ntheorem reduce.sound (H : mk L\u2081 = mk L\u2082) : reduce L\u2081 = reduce L\u2082 :=\nlet \u27e8L\u2083, H13, H23\u27e9 := red.exact.1 H in\n(reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm\n\n/-- If two words have a common maximal reduction,\nthen they correspond to the same element in the free group. -/\n@[to_additive \"If two words have a common maximal reduction,\nthen they correspond to the same element in the additive free group.\"]\ntheorem reduce.exact (H : reduce L\u2081 = reduce L\u2082) : mk L\u2081 = mk L\u2082 :=\nred.exact.2 \u27e8reduce L\u2082, H \u25b8 reduce.red, reduce.red\u27e9\n\n/-- A word and its maximal reduction correspond to\nthe same element of the free group. -/\n@[to_additive \"A word and its maximal reduction correspond to\nthe same element of the additive free group.\"]\ntheorem reduce.self : mk (reduce L) = mk L :=\nreduce.exact reduce.idem\n\n/-- If words `w\u2081 w\u2082` are such that `w\u2081` reduces to `w\u2082`,\nthen `w\u2082` reduces to the maximal reduction of `w\u2081`. -/\n@[to_additive \"If words `w\u2081 w\u2082` are such that `w\u2081` reduces to `w\u2082`,\nthen `w\u2082` reduces to the maximal reduction of `w\u2081`.\"]\ntheorem reduce.rev (H : red L\u2081 L\u2082) : red L\u2082 (reduce L\u2081) :=\n(reduce.eq_of_red H).symm \u25b8 reduce.red\n\n/-- The function that sends an element of the free\ngroup to its maximal reduction. -/\n@[to_additive \"The function that sends an element of the additive free\ngroup to its maximal reduction.\"]\ndef to_word : free_group \u03b1 \u2192 list (\u03b1 \u00d7 bool) :=\nquot.lift reduce $ \u03bb L\u2081 L\u2082 H, reduce.step.eq H\n\n@[to_additive]\nlemma mk_to_word : \u2200{x : free_group \u03b1}, mk (to_word x) = x :=\nby rintros \u27e8L\u27e9; exact reduce.self\n\n@[to_additive]\nlemma to_word_injective : function.injective (to_word : free_group \u03b1 \u2192 list (\u03b1 \u00d7 bool)) :=\nby rintros \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9; exact reduce.exact\n\n@[simp, to_additive] lemma to_word_inj {x y : free_group \u03b1} : to_word x = to_word y \u2194 x = y :=\nto_word_injective.eq_iff\n\n@[simp, to_additive] lemma to_word_mk : (mk L\u2081).to_word = reduce L\u2081 := rfl\n\n@[simp, to_additive] lemma reduce_to_word : \u2200 (x : free_group \u03b1), reduce (to_word x) = to_word x :=\nby { rintro \u27e8L\u27e9, exact reduce.idem }\n\n@[simp, to_additive] lemma to_word_one : (1 : free_group \u03b1).to_word = [] := rfl\n\n@[simp, to_additive] lemma to_word_eq_nil_iff {x : free_group \u03b1} : (x.to_word = []) \u2194 (x = 1) :=\nto_word_injective.eq_iff' to_word_one\n\n@[to_additive]\nlemma reduce_inv_rev {w : list (\u03b1 \u00d7 bool)} : reduce (inv_rev w) = inv_rev (reduce w) :=\nbegin\n  apply reduce.min,\n  rw [\u2190 red_inv_rev_iff, inv_rev_inv_rev],\n  apply red.reduce_left,\n  have : red (inv_rev (inv_rev w)) (inv_rev (reduce (inv_rev w))) := reduce.red.inv_rev,\n  rwa inv_rev_inv_rev at this\nend\n\n@[to_additive]\nlemma to_word_inv {x : free_group \u03b1} : (x\u207b\u00b9).to_word = inv_rev x.to_word :=\nbegin\n  rcases x with \u27e8L\u27e9,\n  rw [quot_mk_eq_mk, inv_mk, to_word_mk, to_word_mk, reduce_inv_rev]\nend\n\n/-- Constructive Church-Rosser theorem (compare `church_rosser`). -/\n@[to_additive \"Constructive Church-Rosser theorem (compare `church_rosser`).\"]\ndef reduce.church_rosser (H12 : red L\u2081 L\u2082) (H13 : red L\u2081 L\u2083) :\n  { L\u2084 // red L\u2082 L\u2084 \u2227 red L\u2083 L\u2084 } :=\n\u27e8reduce L\u2081, reduce.rev H12, reduce.rev H13\u27e9\n\n@[to_additive]\ninstance : decidable_eq (free_group \u03b1) :=\nto_word_injective.decidable_eq\n\n-- TODO @[to_additive] doesn't succeed, possibly due to a bug\ninstance red.decidable_rel : decidable_rel (@red \u03b1)\n| [] []          := is_true red.refl\n| [] (hd2::tl2)  := is_false $ \u03bb H, list.no_confusion (red.nil_iff.1 H)\n| ((x,b)::tl) [] := match red.decidable_rel tl [(x, bnot b)] with\n  | is_true H  := is_true $ red.trans (red.cons_cons H) $\n    (@red.step.bnot _ [] [] _ _).to_red\n  | is_false H := is_false $ \u03bb H2, H $ red.cons_nil_iff_singleton.1 H2\n  end\n| ((x1,b1)::tl1) ((x2,b2)::tl2) := if h : (x1, b1) = (x2, b2)\n  then match red.decidable_rel tl1 tl2 with\n    | is_true H  := is_true $ h \u25b8 red.cons_cons H\n    | is_false H := is_false $ \u03bb H2, H $ h \u25b8 (red.cons_cons_iff _).1 $ H2\n    end\n  else match red.decidable_rel tl1 ((x1,bnot b1)::(x2,b2)::tl2) with\n    | is_true H  := is_true $ (red.cons_cons H).tail red.step.cons_bnot\n    | is_false H := is_false $ \u03bb H2, H $ red.inv_of_red_of_ne h H2\n    end\n\n/-- A list containing every word that `w\u2081` reduces to. -/\ndef red.enum (L\u2081 : list (\u03b1 \u00d7 bool)) : list (list (\u03b1 \u00d7 bool)) :=\nlist.filter (\u03bb L\u2082, red L\u2081 L\u2082) (list.sublists L\u2081)\n\ntheorem red.enum.sound (H : L\u2082 \u2208 red.enum L\u2081) : red L\u2081 L\u2082 :=\nlist.of_mem_filter H\n\ntheorem red.enum.complete (H : red L\u2081 L\u2082) : L\u2082 \u2208 red.enum L\u2081 :=\nlist.mem_filter_of_mem (list.mem_sublists.2 $ red.sublist H) H\n\ninstance : fintype { L\u2082 // red L\u2081 L\u2082 } :=\nfintype.subtype (list.to_finset $ red.enum L\u2081) $\n\u03bb L\u2082, \u27e8\u03bb H, red.enum.sound $ list.mem_to_finset.1 H,\n  \u03bb H, list.mem_to_finset.2 $ red.enum.complete H\u27e9\n\nend reduce\n\nsection metric\n\nvariable [decidable_eq \u03b1]\n\n/-- The length of reduced words provides a norm on a free group. -/\n@[to_additive \"The length of reduced words provides a norm on an additive free group.\"]\ndef norm (x : free_group \u03b1) : \u2115 := x.to_word.length\n\n@[simp, to_additive] lemma norm_inv_eq {x : free_group \u03b1} : norm x\u207b\u00b9 = norm x :=\nby simp only [norm, to_word_inv, inv_rev_length]\n\n@[simp, to_additive] lemma norm_eq_zero {x : free_group \u03b1} : norm x = 0 \u2194 x = 1 :=\nby simp only [norm, list.length_eq_zero, to_word_eq_nil_iff]\n\n@[simp, to_additive] lemma norm_one : norm (1 : free_group \u03b1) = 0 := rfl\n\n@[to_additive]\ntheorem norm_mk_le : norm (mk L\u2081) \u2264 L\u2081.length := reduce.red.length_le\n\n@[to_additive]\nlemma norm_mul_le (x y : free_group \u03b1) : norm (x * y) \u2264 norm x + norm y :=\ncalc norm (x * y) = norm (mk (x.to_word ++ y.to_word)) : by rw [\u2190 mul_mk, mk_to_word, mk_to_word]\n              ... \u2264 (x.to_word ++ y.to_word).length    : norm_mk_le\n              ... = norm x + norm y                    : list.length_append _ _\n\nend metric\n\nend free_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/free_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7132089463623578}}
{"text": "import kb_real_defs --hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 8\n-/\n\n\n/- \nThis is a very basic example of working with intervals of real numbers in Lean.\nAn interval `[a, b]` that is closed at both endpoints $a$ and $b$ can be \nconstructed using `set.Icc a b`. For an open-closed interval `(a, b]`,\nthe notation\nis `set.Ioc a b`, etc. The usual closed-interval notation, using square\nbrackets, is used here as a wrapper around these definitions. We have\nthe following lemma:\n\n\n\n```\nmem_Icc_iff : x \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b\n```\n-/\n\n/- Axiom : mem_Icc_iff :\nx \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b\n-/\n\n/-\nAfter rewriting it, the `split` tactic will isolate the two conditions for \nmembership. Each inequality goals can be solved with the `norm_num` tactic,\nwhich closes goals which are equalities or inequalities between explicit\nreal numbers.\n-/\n\n/- Pro tip : semicolons\nIf instead of a comma, you end a line with a semicolon, then\nLean will apply the next tactic to all the goals created by the\nprevious tactic, rather than just the top one.\n-/\n\n/- Pro tip : definitional equality\n`mem_Icc_iff` is true by definition, so you don't actually\nhave to even rewrite it.\n-/\n\nnotation `[` a `,` b `]`  := set.Icc a b\n\n/- Lemma : no-side-bar\n$2 \u2208 [0,5]$\n-/\nexample : (2 : \u211d) \u2208 [(0 : \u211d), 5] := \nbegin\n    rw mem_Icc_iff,\n    split;\n    norm_num,\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sets/sets_level08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782094, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7132089459726842}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sean x e y dos n\u00fameros tales que\n--    x \u2264 y \n--    \u00ac y \u2264 x\n-- entonces \n--    x \u2264 y \u2227 x \u2260 y\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {x y : \u211d}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\nexample  \n  (h\u2080 : x \u2264 y) \n  (h\u2081 : \u00ac y \u2264 x) \n  : x \u2264 y \u2227 x \u2260 y :=\nbegin\n  split,\n  { assumption },\n  intro h,\n  apply h\u2081,\n  rw h,\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : \u211d,\nh\u2080 : x \u2264 y,\nh\u2081 : \u00acy \u2264 x\n\u22a2 x \u2264 y \u2227 x \u2260 y\n  >> split,\n| \u22a2 x \u2264 y\n|   >> { assumption },\n| \u22a2 x \u2260 y\n|   >> intro h,\n| h : x = y\n| \u22a2 false\n|   >> apply h\u2081,\n| \u22a2 y \u2264 x\n|   >> rw h.\nno goals\n-/\n\n-- Comentario: La t\u00e1ctica split, cuando el objetivo es una conjunci\u00f3n \n-- (P \u2227 Q), aplica la regla de introducci\u00f3n de la conjunci\u00f3n; es decir,\n-- sustituye el objetivo por dos nuevos subobjetivos (P y Q).\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h\u2080 : x \u2264 y) \n  (h\u2081 : \u00ac y \u2264 x) \n  : x \u2264 y \u2227 x \u2260 y :=\n\u27e8h\u2080, \u03bb h, h\u2081 (by rw h)\u27e9\n\n-- Comentario: La notaci\u00f3n \u27e8h0, h1\u27e9, cuando el objetivo es una conjunci\u00f3n \n-- (P \u2227 Q), aplica la regla de introducci\u00f3n de la conjunci\u00f3n donde h0 es\n-- una prueba de P y h1 de Q.\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample \n  (h\u2080 : x \u2264 y) \n  (h\u2081 : \u00ac y \u2264 x) \n  : x \u2264 y \u2227 x \u2260 y :=\nbegin\n  have h : x \u2260 y,\n  { contrapose! h\u2081,\n    rw h\u2081 },\n  exact \u27e8h\u2080, h\u27e9,\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : \u211d,\nh\u2080 : x \u2264 y,\nh\u2081 : \u00acy \u2264 x\n\u22a2 x \u2264 y \u2227 x \u2260 y\n  >> have h : x \u2260 y,\n  >> { contrapose! h\u2081,\nh\u2081 : x = y\n\u22a2 y \u2264 x\n  >>   rw h\u2081 },\nh : x \u2260 y\n\u22a2 x \u2264 y \u2227 x \u2260 y\n  >> exact \u27e8h\u2080, h\u27e9,\nno goals\n-/\n\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Introduccion_de_la_conjuncion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7132089440339311}}
{"text": "/-\nCopyright (c) 2020 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module combinatorics.composition\n! leanprover-community/mathlib commit ac34df03f74e6f797efd6991df2e3b7f7d8d33e0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Finset.Sort\nimport Mathbin.Algebra.BigOperators.Order\nimport Mathbin.Algebra.BigOperators.Fin\n\n/-!\n# Compositions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA composition of a natural number `n` is a decomposition `n = i\u2080 + ... + i_{k-1}` of `n` into a sum\nof positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into\nnon-empty blocks of consecutive integers, where the `i\u2c7c` are the lengths of the blocks.\nThis notion is closely related to that of a partition of `n`, but in a composition of `n` the\norder of the `i\u2c7c`s matters.\n\nWe implement two different structures covering these two viewpoints on compositions. The first\none, made of a list of positive integers summing to `n`, is the main one and is called\n`composition n`. The second one is useful for combinatorial arguments (for instance to show that\nthe number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`\ncontaining `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost\npoints of each block. The main API is built on `composition n`, and we provide an equivalence\nbetween the two types.\n\n## Main functions\n\n* `c : composition n` is a structure, made of a list of integers which are all positive and\n  add up to `n`.\n* `composition_card` states that the cardinality of `composition n` is exactly\n  `2^(n-1)`, which is proved by constructing an equiv with `composition_as_set n` (see below), which\n  is itself in bijection with the subsets of `fin (n-1)` (this holds even for `n = 0`, where `-` is\n  nat subtraction).\n\nLet `c : composition n` be a composition of `n`. Then\n* `c.blocks` is the list of blocks in `c`.\n* `c.length` is the number of blocks in the composition.\n* `c.blocks_fun : fin c.length \u2192 \u2115` is the realization of `c.blocks` as a function on\n  `fin c.length`. This is the main object when using compositions to understand the composition of\n    analytic functions.\n* `c.size_up_to : \u2115 \u2192 \u2115` is the sum of the size of the blocks up to `i`.;\n* `c.embedding i : fin (c.blocks_fun i) \u2192 fin n` is the increasing embedding of the `i`-th block in\n  `fin n`;\n* `c.index j`, for `j : fin n`, is the index of the block containing `j`.\n\n* `composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.\n* `composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.\n\nCompositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition\nof `n`.\n* `l.split_wrt_composition c` is a list of lists, made of the slices of `l` corresponding to the\n  blocks of `c`.\n* `join_split_wrt_composition` states that splitting a list and then joining it gives back the\n  original list.\n* `split_wrt_composition_join` states that joining a list of lists, and then splitting it back\n  according to the right composition, gives back the original list of lists.\n\nWe turn to the second viewpoint on compositions, that we realize as a finset of `fin (n+1)`.\n`c : composition_as_set n` is a structure made of a finset of `fin (n+1)` called `c.boundaries`\nand proofs that it contains `0` and `n`. (Taking a finset of `fin n` containing `0` would not\nmake sense in the edge case `n = 0`, while the previous description works in all cases).\nThe elements of this set (other than `n`) correspond to leftmost points of blocks.\nThus, there is an equiv between `composition n` and `composition_as_set n`. We\nonly construct basic API on `composition_as_set` (notably `c.length` and `c.blocks`) to be able\nto construct this equiv, called `composition_equiv n`. Since there is a straightforward equiv\nbetween `composition_as_set n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`\nfrom a `composition_as_set` and called `composition_as_set_equiv n`), we deduce that\n`composition_as_set n` and `composition n` are both fintypes of cardinality `2^(n - 1)`\n(see `composition_as_set_card` and `composition_card`).\n\n## Implementation details\n\nThe main motivation for this structure and its API is in the construction of the composition of\nformal multilinear series, and the proof that the composition of analytic functions is analytic.\n\nThe representation of a composition as a list is very handy as lists are very flexible and already\nhave a well-developed API.\n\n## Tags\n\nComposition, partition\n\n## References\n\n<https://en.wikipedia.org/wiki/Composition_(combinatorics)>\n-/\n\n\nopen List\n\nopen BigOperators\n\nvariable {n : \u2115}\n\n#print Composition /-\n/-- A composition of `n` is a list of positive integers summing to `n`. -/\n@[ext]\nstructure Composition (n : \u2115) where\n  blocks : List \u2115\n  blocks_pos : \u2200 {i}, i \u2208 blocks \u2192 0 < i\n  blocks_sum : blocks.Sum = n\n#align composition Composition\n-/\n\n#print CompositionAsSet /-\n/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of\nconsecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding\na finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and\nget a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure\n`composition_as_set n`. -/\n@[ext]\nstructure CompositionAsSet (n : \u2115) where\n  boundaries : Finset (Fin n.succ)\n  zero_mem : (0 : Fin n.succ) \u2208 boundaries\n  getLast_mem : Fin.last n \u2208 boundaries\n#align composition_as_set CompositionAsSet\n-/\n\ninstance {n : \u2115} : Inhabited (CompositionAsSet n) :=\n  \u27e8\u27e8Finset.univ, Finset.mem_univ _, Finset.mem_univ _\u27e9\u27e9\n\n/-!\n### Compositions\n\nA composition of an integer `n` is a decomposition `n = i\u2080 + ... + i_{k-1}` of `n` into a sum of\npositive integers.\n-/\n\n\nnamespace Composition\n\nvariable (c : Composition n)\n\ninstance (n : \u2115) : ToString (Composition n) :=\n  \u27e8fun c => toString c.blocks\u27e9\n\n#print Composition.length /-\n/-- The length of a composition, i.e., the number of blocks in the composition. -/\n@[reducible]\ndef length : \u2115 :=\n  c.blocks.length\n#align composition.length Composition.length\n-/\n\n#print Composition.blocks_length /-\ntheorem blocks_length : c.blocks.length = c.length :=\n  rfl\n#align composition.blocks_length Composition.blocks_length\n-/\n\n#print Composition.blocksFun /-\n/-- The blocks of a composition, seen as a function on `fin c.length`. When composing analytic\nfunctions using compositions, this is the main player. -/\ndef blocksFun : Fin c.length \u2192 \u2115 := fun i => nthLe c.blocks i i.2\n#align composition.blocks_fun Composition.blocksFun\n-/\n\n#print Composition.ofFn_blocksFun /-\ntheorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=\n  ofFn_nthLe _\n#align composition.of_fn_blocks_fun Composition.ofFn_blocksFun\n-/\n\n#print Composition.sum_blocksFun /-\ntheorem sum_blocksFun : (\u2211 i, c.blocksFun i) = n := by\n  conv_rhs => rw [\u2190 c.blocks_sum, \u2190 of_fn_blocks_fun, sum_of_fn]\n#align composition.sum_blocks_fun Composition.sum_blocksFun\n-/\n\n#print Composition.blocksFun_mem_blocks /-\ntheorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i \u2208 c.blocks :=\n  nthLe_mem _ _ _\n#align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks\n-/\n\n#print Composition.one_le_blocks /-\n@[simp]\ntheorem one_le_blocks {i : \u2115} (h : i \u2208 c.blocks) : 1 \u2264 i :=\n  c.blocks_pos h\n#align composition.one_le_blocks Composition.one_le_blocks\n-/\n\n#print Composition.one_le_blocks' /-\n@[simp]\ntheorem one_le_blocks' {i : \u2115} (h : i < c.length) : 1 \u2264 nthLe c.blocks i h :=\n  c.one_le_blocks (nthLe_mem (blocks c) i h)\n#align composition.one_le_blocks' Composition.one_le_blocks'\n-/\n\n#print Composition.blocks_pos' /-\n@[simp]\ntheorem blocks_pos' (i : \u2115) (h : i < c.length) : 0 < nthLe c.blocks i h :=\n  c.one_le_blocks' h\n#align composition.blocks_pos' Composition.blocks_pos'\n-/\n\n#print Composition.one_le_blocksFun /-\ntheorem one_le_blocksFun (i : Fin c.length) : 1 \u2264 c.blocksFun i :=\n  c.one_le_blocks (c.blocksFun_mem_blocks i)\n#align composition.one_le_blocks_fun Composition.one_le_blocksFun\n-/\n\n#print Composition.length_le /-\ntheorem length_le : c.length \u2264 n :=\n  by\n  conv_rhs => rw [\u2190 c.blocks_sum]\n  exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi\n#align composition.length_le Composition.length_le\n-/\n\n#print Composition.length_pos_of_pos /-\ntheorem length_pos_of_pos (h : 0 < n) : 0 < c.length :=\n  by\n  apply length_pos_of_sum_pos\n  convert h\n  exact c.blocks_sum\n#align composition.length_pos_of_pos Composition.length_pos_of_pos\n-/\n\n#print Composition.sizeUpTo /-\n/-- The sum of the sizes of the blocks in a composition up to `i`. -/\ndef sizeUpTo (i : \u2115) : \u2115 :=\n  (c.blocks.take i).Sum\n#align composition.size_up_to Composition.sizeUpTo\n-/\n\n#print Composition.sizeUpTo_zero /-\n@[simp]\ntheorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [size_up_to]\n#align composition.size_up_to_zero Composition.sizeUpTo_zero\n-/\n\n#print Composition.sizeUpTo_ofLength_le /-\ntheorem sizeUpTo_ofLength_le (i : \u2115) (h : c.length \u2264 i) : c.sizeUpTo i = n :=\n  by\n  dsimp [size_up_to]\n  convert c.blocks_sum\n  exact take_all_of_le h\n#align composition.size_up_to_of_length_le Composition.sizeUpTo_ofLength_le\n-/\n\n#print Composition.sizeUpTo_length /-\n@[simp]\ntheorem sizeUpTo_length : c.sizeUpTo c.length = n :=\n  c.sizeUpTo_ofLength_le c.length le_rfl\n#align composition.size_up_to_length Composition.sizeUpTo_length\n-/\n\n#print Composition.sizeUpTo_le /-\ntheorem sizeUpTo_le (i : \u2115) : c.sizeUpTo i \u2264 n :=\n  by\n  conv_rhs => rw [\u2190 c.blocks_sum, \u2190 sum_take_add_sum_drop _ i]\n  exact Nat.le_add_right _ _\n#align composition.size_up_to_le Composition.sizeUpTo_le\n-/\n\n#print Composition.sizeUpTo_succ /-\ntheorem sizeUpTo_succ {i : \u2115} (h : i < c.length) :\n    c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks.nthLe i h :=\n  by\n  simp only [size_up_to]\n  rw [sum_take_succ _ _ h]\n#align composition.size_up_to_succ Composition.sizeUpTo_succ\n-/\n\n#print Composition.sizeUpTo_succ' /-\ntheorem sizeUpTo_succ' (i : Fin c.length) :\n    c.sizeUpTo ((i : \u2115) + 1) = c.sizeUpTo i + c.blocksFun i :=\n  c.sizeUpTo_succ i.2\n#align composition.size_up_to_succ' Composition.sizeUpTo_succ'\n-/\n\n#print Composition.sizeUpTo_strict_mono /-\ntheorem sizeUpTo_strict_mono {i : \u2115} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) :=\n  by\n  rw [c.size_up_to_succ h]\n  simp\n#align composition.size_up_to_strict_mono Composition.sizeUpTo_strict_mono\n-/\n\n#print Composition.monotone_sizeUpTo /-\ntheorem monotone_sizeUpTo : Monotone c.sizeUpTo :=\n  monotone_sum_take _\n#align composition.monotone_size_up_to Composition.monotone_sizeUpTo\n-/\n\n/- warning: composition.boundary -> Composition.boundary is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n), OrderEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.partialOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))\nbut is expected to have type\n  forall {n : Nat} (c : Composition n), OrderEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))\nCase conversion may be inaccurate. Consider using '#align composition.boundary Composition.boundary\u2093'. -/\n/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include\na virtual point at the right of the last block, to make for a nice equiv with\n`composition_as_set n`. -/\ndef boundary : Fin (c.length + 1) \u21aao Fin (n + 1) :=\n  (OrderEmbedding.ofStrictMono fun i => \u27e8c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)\u27e9) <|\n    Fin.strictMono_iff_lt_succ.2 fun \u27e8i, hi\u27e9 => c.sizeUpTo_strict_mono hi\n#align composition.boundary Composition.boundary\n\n/- warning: composition.boundary_zero -> Composition.boundary_zero is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n), Eq.{1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.partialOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))) (fun (_x : RelEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.partialOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))) => (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) -> (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.partialOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))) (Composition.boundary n c) (OfNat.ofNat.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (One.one.{0} Nat Nat.hasOne))) 0 (OfNat.mk.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (One.one.{0} Nat Nat.hasOne))) 0 (Zero.zero.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (One.one.{0} Nat Nat.hasOne))) (Fin.hasZeroOfNeZero (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (One.one.{0} Nat Nat.hasOne)) (NeZero.succ (Composition.length n c))))))) (OfNat.ofNat.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne))) 0 (OfNat.mk.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne))) 0 (Zero.zero.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne))) (Fin.hasZeroOfNeZero (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne)) (NeZero.succ n)))))\nbut is expected to have type\n  forall {n : Nat} (c : Composition n), Eq.{1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (OfNat.ofNat.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) 0 (Fin.instOfNatFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (NeZero.succ (Composition.length n c))))) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (fun (_x : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))))) (RelEmbedding.toEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.boundary n c)) (OfNat.ofNat.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) 0 (Fin.instOfNatFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (NeZero.succ (Composition.length n c))))) (OfNat.ofNat.{0} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (OfNat.ofNat.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) 0 (Fin.instOfNatFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (NeZero.succ (Composition.length n c))))) 0 (Fin.instOfNatFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (NeZero.succ n)))\nCase conversion may be inaccurate. Consider using '#align composition.boundary_zero Composition.boundary_zero\u2093'. -/\n@[simp]\ntheorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]\n#align composition.boundary_zero Composition.boundary_zero\n\n/- warning: composition.boundary_last -> Composition.boundary_last is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n), Eq.{1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.partialOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))) (fun (_x : RelEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.partialOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))) => (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) -> (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.partialOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))) (Composition.boundary n c) (Fin.last (Composition.length n c))) (Fin.last n)\nbut is expected to have type\n  forall {n : Nat} (c : Composition n), Eq.{1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin.last (Composition.length n c))) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (fun (_x : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))))) (RelEmbedding.toEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.boundary n c)) (Fin.last (Composition.length n c))) (Fin.last n)\nCase conversion may be inaccurate. Consider using '#align composition.boundary_last Composition.boundary_last\u2093'. -/\n@[simp]\ntheorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by\n  simp [boundary, Fin.ext_iff]\n#align composition.boundary_last Composition.boundary_last\n\n#print Composition.boundaries /-\n/-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include\na virtual point at the right of the last block, to make for a nice equiv with\n`composition_as_set n`. -/\ndef boundaries : Finset (Fin (n + 1)) :=\n  Finset.univ.map c.boundary.toEmbedding\n#align composition.boundaries Composition.boundaries\n-/\n\n#print Composition.card_boundaries_eq_succ_length /-\ntheorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]\n#align composition.card_boundaries_eq_succ_length Composition.card_boundaries_eq_succ_length\n-/\n\n#print Composition.toCompositionAsSet /-\n/-- To `c : composition n`, one can associate a `composition_as_set n` by registering the leftmost\npoint of each block, and adding a virtual point at the right of the last block. -/\ndef toCompositionAsSet : CompositionAsSet n\n    where\n  boundaries := c.boundaries\n  zero_mem :=\n    by\n    simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]\n    exact \u27e80, rfl\u27e9\n  getLast_mem :=\n    by\n    simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]\n    exact \u27e8Fin.last c.length, c.boundary_last\u27e9\n#align composition.to_composition_as_set Composition.toCompositionAsSet\n-/\n\n/- warning: composition.order_emb_of_fin_boundaries -> Composition.orderEmbOfFin_boundaries is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n), Eq.{1} (OrderEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.hasLe (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LinearOrder.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))))))))) (Finset.orderEmbOfFin.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.linearOrder (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Composition.boundaries n c) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Composition.card_boundaries_eq_succ_length n c)) (Composition.boundary n c)\nbut is expected to have type\n  forall {n : Nat} (c : Composition n), Eq.{1} (OrderEmbedding.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Preorder.toLE.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (PartialOrder.toPreorder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (SemilatticeInf.toPartialOrder.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Lattice.toSemilatticeInf.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (DistribLattice.toLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instDistribLattice.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin.instLinearOrderFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))))))))) (Finset.orderEmbOfFin.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin.instLinearOrderFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Composition.boundaries n c) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.length n c) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Composition.card_boundaries_eq_succ_length n c)) (Composition.boundary n c)\nCase conversion may be inaccurate. Consider using '#align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries\u2093'. -/\n/-- The canonical increasing bijection between `fin (c.length + 1)` and `c.boundaries` is\nexactly `c.boundary`. -/\ntheorem orderEmbOfFin_boundaries :\n    c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary :=\n  by\n  refine' (Finset.orderEmbOfFin_unique' _ _).symm\n  exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _)\n#align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries\n\n#print Composition.embedding /-\n/-- Embedding the `i`-th block of a composition (identified with `fin (c.blocks_fun i)`) into\n`fin n` at the relevant position. -/\ndef embedding (i : Fin c.length) : Fin (c.blocksFun i) \u21aao Fin n :=\n  (Fin.natAdd <| c.sizeUpTo i).trans <|\n    Fin.castLe <|\n      calc\n        c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ _).symm\n        _ \u2264 c.sizeUpTo c.length := (monotone_sum_take _ i.2)\n        _ = n := c.sizeUpTo_length\n        \n#align composition.embedding Composition.embedding\n-/\n\n/- warning: composition.coe_embedding -> Composition.coe_embedding is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) (i : Fin (Composition.length n c)) (j : Fin (Composition.blocksFun n c i)), Eq.{1} Nat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin n) Nat (HasLiftT.mk.{1, 1} (Fin n) Nat (CoeTC\u2093.coe.{1, 1} (Fin n) Nat (coeBase.{1, 1} (Fin n) Nat (Fin.coeToNat n)))) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Composition.sizeUpTo n c ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.length n c)) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.length n c)) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.length n c)) Nat (coeBase.{1, 1} (Fin (Composition.length n c)) Nat (Fin.coeToNat (Composition.length n c))))) i)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.blocksFun n c i)) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.blocksFun n c i)) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.blocksFun n c i)) Nat (coeBase.{1, 1} (Fin (Composition.blocksFun n c i)) Nat (Fin.coeToNat (Composition.blocksFun n c i))))) j))\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) (i : Fin (Composition.length n c)) (j : Fin (Composition.blocksFun n c i)), Eq.{1} Nat (Fin.val n (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (fun (_x : Fin (Composition.blocksFun n c i)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i)) => LE.le.{0} (Fin (Composition.blocksFun n c i)) (instLEFin (Composition.blocksFun n c i)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i)) j)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Composition.sizeUpTo n c (Fin.val (Composition.length n c) i)) (Fin.val (Composition.blocksFun n c i) j))\nCase conversion may be inaccurate. Consider using '#align composition.coe_embedding Composition.coe_embedding\u2093'. -/\n@[simp]\ntheorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :\n    (c.Embedding i j : \u2115) = c.sizeUpTo i + j :=\n  rfl\n#align composition.coe_embedding Composition.coe_embedding\n\n#print Composition.index_exists /-\n/-- `index_exists` asserts there is some `i` with `j < c.size_up_to (i+1)`.\nIn the next definition `index` we use `nat.find` to produce the minimal such index.\n-/\ntheorem index_exists {j : \u2115} (h : j < n) : \u2203 i : \u2115, j < c.sizeUpTo i.succ \u2227 i < c.length :=\n  by\n  have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h\n  have : 0 < c.blocks.sum := by rwa [\u2190 c.blocks_sum] at n_pos\n  have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this\n  refine' \u27e8c.length.pred, _, Nat.pred_lt (ne_of_gt length_pos)\u27e9\n  have : c.length.pred.succ = c.length := Nat.succ_pred_eq_of_pos length_pos\n  simp [this, h]\n#align composition.index_exists Composition.index_exists\n-/\n\n#print Composition.index /-\n/-- `c.index j` is the index of the block in the composition `c` containing `j`. -/\ndef index (j : Fin n) : Fin c.length :=\n  \u27e8Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2\u27e9\n#align composition.index Composition.index\n-/\n\n#print Composition.lt_sizeUpTo_index_succ /-\ntheorem lt_sizeUpTo_index_succ (j : Fin n) : (j : \u2115) < c.sizeUpTo (c.index j).succ :=\n  (Nat.find_spec (c.index_exists j.2)).1\n#align composition.lt_size_up_to_index_succ Composition.lt_sizeUpTo_index_succ\n-/\n\n#print Composition.sizeUpTo_index_le /-\ntheorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) \u2264 j :=\n  by\n  by_contra H\n  set i := c.index j with hi\n  push_neg  at H\n  have i_pos : (0 : \u2115) < i := by\n    by_contra' i_pos\n    revert H\n    simp [nonpos_iff_eq_zero.1 i_pos, c.size_up_to_zero]\n  let i\u2081 := (i : \u2115).pred\n  have i\u2081_lt_i : i\u2081 < i := Nat.pred_lt (ne_of_gt i_pos)\n  have i\u2081_succ : i\u2081.succ = i := Nat.succ_pred_eq_of_pos i_pos\n  have := Nat.find_min (c.index_exists j.2) i\u2081_lt_i\n  simp [lt_trans i\u2081_lt_i (c.index j).2, i\u2081_succ] at this\n  exact Nat.lt_le_antisymm H this\n#align composition.size_up_to_index_le Composition.sizeUpTo_index_le\n-/\n\n#print Composition.invEmbedding /-\n/-- Mapping an element `j` of `fin n` to the element in the block containing it, identified with\n`fin (c.blocks_fun (c.index j))` through the canonical increasing bijection. -/\ndef invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) :=\n  \u27e8j - c.sizeUpTo (c.index j),\n    by\n    rw [tsub_lt_iff_right, add_comm, \u2190 size_up_to_succ']\n    \u00b7 exact lt_size_up_to_index_succ _ _\n    \u00b7 exact size_up_to_index_le _ _\u27e9\n#align composition.inv_embedding Composition.invEmbedding\n-/\n\n#print Composition.coe_invEmbedding /-\n@[simp]\ntheorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : \u2115) = j - c.sizeUpTo (c.index j) :=\n  rfl\n#align composition.coe_inv_embedding Composition.coe_invEmbedding\n-/\n\n/- warning: composition.embedding_comp_inv -> Composition.embedding_comp_inv is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) (j : Fin n), Eq.{1} (Fin n) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (Fin.hasLe (Composition.blocksFun n c (Composition.index n c j))) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin.hasLe (Composition.blocksFun n c (Composition.index n c j)))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c (Composition.index n c j))) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin.hasLe (Composition.blocksFun n c (Composition.index n c j)))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c (Composition.index n c j)) (Composition.invEmbedding n c j)) j\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) (j : Fin n), Eq.{1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c (Composition.index n c j))) => Fin n) (Composition.invEmbedding n c j)) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n)) (Fin (Composition.blocksFun n c (Composition.index n c j))) (fun (_x : Fin (Composition.blocksFun n c (Composition.index n c j))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c (Composition.index n c j))) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n)) (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c (Composition.index n c j))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c (Composition.index n c j))) => LE.le.{0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (instLEFin (Composition.blocksFun n c (Composition.index n c j))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c (Composition.index n c j))) (Composition.invEmbedding n c j)) j\nCase conversion may be inaccurate. Consider using '#align composition.embedding_comp_inv Composition.embedding_comp_inv\u2093'. -/\ntheorem embedding_comp_inv (j : Fin n) : c.Embedding (c.index j) (c.invEmbedding j) = j :=\n  by\n  rw [Fin.ext_iff]\n  apply add_tsub_cancel_of_le (c.size_up_to_index_le j)\n#align composition.embedding_comp_inv Composition.embedding_comp_inv\n\n/- warning: composition.mem_range_embedding_iff -> Composition.mem_range_embedding_iff is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) {j : Fin n} {i : Fin (Composition.length n c)}, Iff (Membership.Mem.{0, 0} (Fin n) (Set.{0} (Fin n)) (Set.hasMem.{0} (Fin n)) j (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i)) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i)))) (And (LE.le.{0} Nat Nat.hasLe (Composition.sizeUpTo n c ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.length n c)) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.length n c)) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.length n c)) Nat (coeBase.{1, 1} (Fin (Composition.length n c)) Nat (Fin.coeToNat (Composition.length n c))))) i)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin n) Nat (HasLiftT.mk.{1, 1} (Fin n) Nat (CoeTC\u2093.coe.{1, 1} (Fin n) Nat (coeBase.{1, 1} (Fin n) Nat (Fin.coeToNat n)))) j)) (LT.lt.{0} Nat Nat.hasLt ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin n) Nat (HasLiftT.mk.{1, 1} (Fin n) Nat (CoeTC\u2093.coe.{1, 1} (Fin n) Nat (coeBase.{1, 1} (Fin n) Nat (Fin.coeToNat n)))) j) (Composition.sizeUpTo n c (Nat.succ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.length n c)) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.length n c)) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.length n c)) Nat (coeBase.{1, 1} (Fin (Composition.length n c)) Nat (Fin.coeToNat (Composition.length n c))))) i)))))\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) {j : Fin n} {i : Fin (Composition.length n c)}, Iff (Membership.mem.{0, 0} (Fin n) (Set.{0} (Fin n)) (Set.instMembershipSet.{0} (Fin n)) j (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i)) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (fun (_x : Fin (Composition.blocksFun n c i)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i)) => LE.le.{0} (Fin (Composition.blocksFun n c i)) (instLEFin (Composition.blocksFun n c i)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i))))) (And (LE.le.{0} Nat instLENat (Composition.sizeUpTo n c (Fin.val (Composition.length n c) i)) (Fin.val n j)) (LT.lt.{0} Nat instLTNat (Fin.val n j) (Composition.sizeUpTo n c (Nat.succ (Fin.val (Composition.length n c) i)))))\nCase conversion may be inaccurate. Consider using '#align composition.mem_range_embedding_iff Composition.mem_range_embedding_iff\u2093'. -/\ntheorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} :\n    j \u2208 Set.range (c.Embedding i) \u2194 c.sizeUpTo i \u2264 j \u2227 (j : \u2115) < c.sizeUpTo (i : \u2115).succ :=\n  by\n  constructor\n  \u00b7 intro h\n    rcases Set.mem_range.2 h with \u27e8k, hk\u27e9\n    rw [Fin.ext_iff] at hk\n    change c.size_up_to i + k = (j : \u2115) at hk\n    rw [\u2190 hk]\n    simp [size_up_to_succ', k.is_lt]\n  \u00b7 intro h\n    apply Set.mem_range.2\n    refine' \u27e8\u27e8j - c.size_up_to i, _\u27e9, _\u27e9\n    \u00b7 rw [tsub_lt_iff_left, \u2190 size_up_to_succ']\n      \u00b7 exact h.2\n      \u00b7 exact h.1\n    \u00b7 rw [Fin.ext_iff]\n      exact add_tsub_cancel_of_le h.1\n#align composition.mem_range_embedding_iff Composition.mem_range_embedding_iff\n\n/- warning: composition.disjoint_range -> Composition.disjoint_range is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) {i\u2081 : Fin (Composition.length n c)} {i\u2082 : Fin (Composition.length n c)}, (Ne.{1} (Fin (Composition.length n c)) i\u2081 i\u2082) -> (Disjoint.{0} (Set.{0} (Fin n)) (CompleteSemilatticeInf.toPartialOrder.{0} (Set.{0} (Fin n)) (CompleteLattice.toCompleteSemilatticeInf.{0} (Set.{0} (Fin n)) (Order.Coframe.toCompleteLattice.{0} (Set.{0} (Fin n)) (CompleteDistribLattice.toCoframe.{0} (Set.{0} (Fin n)) (CompleteBooleanAlgebra.toCompleteDistribLattice.{0} (Set.{0} (Fin n)) (Set.completeBooleanAlgebra.{0} (Fin n))))))) (GeneralizedBooleanAlgebra.toOrderBot.{0} (Set.{0} (Fin n)) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{0} (Set.{0} (Fin n)) (Set.booleanAlgebra.{0} (Fin n)))) (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i\u2081)) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i\u2081)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i\u2081)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i\u2081)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i\u2081)) (Fin.hasLe (Composition.blocksFun n c i\u2081))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i\u2081)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i\u2081)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i\u2081)) (Fin.hasLe (Composition.blocksFun n c i\u2081))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i\u2081))) (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i\u2082)) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i\u2082)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i\u2082)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i\u2082)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i\u2082)) (Fin.hasLe (Composition.blocksFun n c i\u2082))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i\u2082)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i\u2082)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i\u2082)) (Fin.hasLe (Composition.blocksFun n c i\u2082))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i\u2082))))\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) {i\u2081 : Fin (Composition.length n c)} {i\u2082 : Fin (Composition.length n c)}, (Ne.{1} (Fin (Composition.length n c)) i\u2081 i\u2082) -> (Disjoint.{0} (Set.{0} (Fin n)) (CompleteSemilatticeInf.toPartialOrder.{0} (Set.{0} (Fin n)) (CompleteLattice.toCompleteSemilatticeInf.{0} (Set.{0} (Fin n)) (Order.Coframe.toCompleteLattice.{0} (Set.{0} (Fin n)) (CompleteDistribLattice.toCoframe.{0} (Set.{0} (Fin n)) (CompleteBooleanAlgebra.toCompleteDistribLattice.{0} (Set.{0} (Fin n)) (Set.instCompleteBooleanAlgebraSet.{0} (Fin n))))))) (BoundedOrder.toOrderBot.{0} (Set.{0} (Fin n)) (Preorder.toLE.{0} (Set.{0} (Fin n)) (PartialOrder.toPreorder.{0} (Set.{0} (Fin n)) (CompleteSemilatticeInf.toPartialOrder.{0} (Set.{0} (Fin n)) (CompleteLattice.toCompleteSemilatticeInf.{0} (Set.{0} (Fin n)) (Order.Coframe.toCompleteLattice.{0} (Set.{0} (Fin n)) (CompleteDistribLattice.toCoframe.{0} (Set.{0} (Fin n)) (CompleteBooleanAlgebra.toCompleteDistribLattice.{0} (Set.{0} (Fin n)) (Set.instCompleteBooleanAlgebraSet.{0} (Fin n))))))))) (CompleteLattice.toBoundedOrder.{0} (Set.{0} (Fin n)) (Order.Coframe.toCompleteLattice.{0} (Set.{0} (Fin n)) (CompleteDistribLattice.toCoframe.{0} (Set.{0} (Fin n)) (CompleteBooleanAlgebra.toCompleteDistribLattice.{0} (Set.{0} (Fin n)) (Set.instCompleteBooleanAlgebraSet.{0} (Fin n))))))) (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i\u2081)) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i\u2081)) (Fin n)) (Fin (Composition.blocksFun n c i\u2081)) (fun (_x : Fin (Composition.blocksFun n c i\u2081)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i\u2081)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i\u2081)) (Fin n)) (Fin (Composition.blocksFun n c i\u2081)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i\u2081)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i\u2081)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i\u2081)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i\u2081)) => LE.le.{0} (Fin (Composition.blocksFun n c i\u2081)) (instLEFin (Composition.blocksFun n c i\u2081)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i\u2081)))) (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i\u2082)) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i\u2082)) (Fin n)) (Fin (Composition.blocksFun n c i\u2082)) (fun (_x : Fin (Composition.blocksFun n c i\u2082)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i\u2082)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i\u2082)) (Fin n)) (Fin (Composition.blocksFun n c i\u2082)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i\u2082)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i\u2082)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i\u2082)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i\u2082)) => LE.le.{0} (Fin (Composition.blocksFun n c i\u2082)) (instLEFin (Composition.blocksFun n c i\u2082)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i\u2082)))))\nCase conversion may be inaccurate. Consider using '#align composition.disjoint_range Composition.disjoint_range\u2093'. -/\n/-- The embeddings of different blocks of a composition are disjoint. -/\ntheorem disjoint_range {i\u2081 i\u2082 : Fin c.length} (h : i\u2081 \u2260 i\u2082) :\n    Disjoint (Set.range (c.Embedding i\u2081)) (Set.range (c.Embedding i\u2082)) := by\n  classical\n    wlog h' : i\u2081 < i\u2082\n    \u00b7 exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm\n    by_contra d\n    obtain \u27e8x, hx\u2081, hx\u2082\u27e9 :\n      \u2203 x : Fin n, x \u2208 Set.range (c.embedding i\u2081) \u2227 x \u2208 Set.range (c.embedding i\u2082) :=\n      Set.not_disjoint_iff.1 d\n    have A : (i\u2081 : \u2115).succ \u2264 i\u2082 := Nat.succ_le_of_lt h'\n    apply lt_irrefl (x : \u2115)\n    calc\n      (x : \u2115) < c.size_up_to (i\u2081 : \u2115).succ := (c.mem_range_embedding_iff.1 hx\u2081).2\n      _ \u2264 c.size_up_to (i\u2082 : \u2115) := (monotone_sum_take _ A)\n      _ \u2264 x := (c.mem_range_embedding_iff.1 hx\u2082).1\n      \n#align composition.disjoint_range Composition.disjoint_range\n\n/- warning: composition.mem_range_embedding -> Composition.mem_range_embedding is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) (j : Fin n), Membership.Mem.{0, 0} (Fin n) (Set.{0} (Fin n)) (Set.hasMem.{0} (Fin n)) j (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c (Composition.index n c j))) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (Fin.hasLe (Composition.blocksFun n c (Composition.index n c j))) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin.hasLe (Composition.blocksFun n c (Composition.index n c j)))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c (Composition.index n c j))) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin.hasLe (Composition.blocksFun n c (Composition.index n c j)))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c (Composition.index n c j))))\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) (j : Fin n), Membership.mem.{0, 0} (Fin n) (Set.{0} (Fin n)) (Set.instMembershipSet.{0} (Fin n)) j (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c (Composition.index n c j))) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n)) (Fin (Composition.blocksFun n c (Composition.index n c j))) (fun (_x : Fin (Composition.blocksFun n c (Composition.index n c j))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c (Composition.index n c j))) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n)) (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c (Composition.index n c j))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c (Composition.index n c j))) => LE.le.{0} (Fin (Composition.blocksFun n c (Composition.index n c j))) (instLEFin (Composition.blocksFun n c (Composition.index n c j))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c (Composition.index n c j)))))\nCase conversion may be inaccurate. Consider using '#align composition.mem_range_embedding Composition.mem_range_embedding\u2093'. -/\ntheorem mem_range_embedding (j : Fin n) : j \u2208 Set.range (c.Embedding (c.index j)) :=\n  by\n  have : c.embedding (c.index j) (c.inv_embedding j) \u2208 Set.range (c.embedding (c.index j)) :=\n    Set.mem_range_self _\n  rwa [c.embedding_comp_inv j] at this\n#align composition.mem_range_embedding Composition.mem_range_embedding\n\n/- warning: composition.mem_range_embedding_iff' -> Composition.mem_range_embedding_iff' is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) {j : Fin n} {i : Fin (Composition.length n c)}, Iff (Membership.Mem.{0, 0} (Fin n) (Set.{0} (Fin n)) (Set.hasMem.{0} (Fin n)) j (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i)) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i)))) (Eq.{1} (Fin (Composition.length n c)) i (Composition.index n c j))\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) {j : Fin n} {i : Fin (Composition.length n c)}, Iff (Membership.mem.{0, 0} (Fin n) (Set.{0} (Fin n)) (Set.instMembershipSet.{0} (Fin n)) j (Set.range.{0, 1} (Fin n) (Fin (Composition.blocksFun n c i)) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (fun (_x : Fin (Composition.blocksFun n c i)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i)) => LE.le.{0} (Fin (Composition.blocksFun n c i)) (instLEFin (Composition.blocksFun n c i)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i))))) (Eq.{1} (Fin (Composition.length n c)) i (Composition.index n c j))\nCase conversion may be inaccurate. Consider using '#align composition.mem_range_embedding_iff' Composition.mem_range_embedding_iff'\u2093'. -/\ntheorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} :\n    j \u2208 Set.range (c.Embedding i) \u2194 i = c.index j :=\n  by\n  constructor\n  \u00b7 rw [\u2190 not_imp_not]\n    intro h\n    exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j)\n  \u00b7 intro h\n    rw [h]\n    exact c.mem_range_embedding j\n#align composition.mem_range_embedding_iff' Composition.mem_range_embedding_iff'\n\n/- warning: composition.index_embedding -> Composition.index_embedding is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) (i : Fin (Composition.length n c)) (j : Fin (Composition.blocksFun n c i)), Eq.{1} (Fin (Composition.length n c)) (Composition.index n c (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j)) i\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) (i : Fin (Composition.length n c)) (j : Fin (Composition.blocksFun n c i)), Eq.{1} (Fin (Composition.length n c)) (Composition.index n c (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (fun (_x : Fin (Composition.blocksFun n c i)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i)) => LE.le.{0} (Fin (Composition.blocksFun n c i)) (instLEFin (Composition.blocksFun n c i)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i)) j)) i\nCase conversion may be inaccurate. Consider using '#align composition.index_embedding Composition.index_embedding\u2093'. -/\ntheorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :\n    c.index (c.Embedding i j) = i := by\n  symm\n  rw [\u2190 mem_range_embedding_iff']\n  apply Set.mem_range_self\n#align composition.index_embedding Composition.index_embedding\n\n/- warning: composition.inv_embedding_comp -> Composition.invEmbedding_comp is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : Composition n) (i : Fin (Composition.length n c)) (j : Fin (Composition.blocksFun n c i)), Eq.{1} Nat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.blocksFun n c (Composition.index n c (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j)))) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j)))) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j)))) Nat (coeBase.{1, 1} (Fin (Composition.blocksFun n c (Composition.index n c (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j)))) Nat (Fin.coeToNat (Composition.blocksFun n c (Composition.index n c (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j))))))) (Composition.invEmbedding n c (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (Fin.hasLe (Composition.blocksFun n c i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n c i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n c i)) (Fin.hasLe (Composition.blocksFun n c i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n c i) j))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.blocksFun n c i)) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.blocksFun n c i)) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.blocksFun n c i)) Nat (coeBase.{1, 1} (Fin (Composition.blocksFun n c i)) Nat (Fin.coeToNat (Composition.blocksFun n c i))))) j)\nbut is expected to have type\n  forall {n : Nat} (c : Composition n) (i : Fin (Composition.length n c)) (j : Fin (Composition.blocksFun n c i)), Eq.{1} Nat (Fin.val (Composition.blocksFun n c (Composition.index n c (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (fun (a : Fin (Composition.blocksFun n c i)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i)) => Fin n) a) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i)) => LE.le.{0} (Fin (Composition.blocksFun n c i)) (instLEFin (Composition.blocksFun n c i)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i)) j))) (Composition.invEmbedding n c (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (fun (_x : Fin (Composition.blocksFun n c i)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n c i)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n)) (Fin (Composition.blocksFun n c i)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n c i)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n c i)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n c i)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n c i)) => LE.le.{0} (Fin (Composition.blocksFun n c i)) (instLEFin (Composition.blocksFun n c i)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n c i)) j))) (Fin.val (Composition.blocksFun n c i) j)\nCase conversion may be inaccurate. Consider using '#align composition.inv_embedding_comp Composition.invEmbedding_comp\u2093'. -/\ntheorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) :\n    (c.invEmbedding (c.Embedding i j) : \u2115) = j := by\n  simp_rw [coe_inv_embedding, index_embedding, coe_embedding, add_tsub_cancel_left]\n#align composition.inv_embedding_comp Composition.invEmbedding_comp\n\n#print Composition.blocksFinEquiv /-\n/-- Equivalence between the disjoint union of the blocks (each of them seen as\n`fin (c.blocks_fun i)`) with `fin n`. -/\ndef blocksFinEquiv : (\u03a3i : Fin c.length, Fin (c.blocksFun i)) \u2243 Fin n\n    where\n  toFun x := c.Embedding x.1 x.2\n  invFun j := \u27e8c.index j, c.invEmbedding j\u27e9\n  left_inv x := by\n    rcases x with \u27e8i, y\u27e9\n    dsimp\n    congr ; \u00b7 exact c.index_embedding _ _\n    rw [Fin.heq_ext_iff]\n    \u00b7 exact c.inv_embedding_comp _ _\n    \u00b7 rw [c.index_embedding]\n  right_inv j := c.embedding_comp_inv j\n#align composition.blocks_fin_equiv Composition.blocksFinEquiv\n-/\n\n#print Composition.blocksFun_congr /-\ntheorem blocksFun_congr {n\u2081 n\u2082 : \u2115} (c\u2081 : Composition n\u2081) (c\u2082 : Composition n\u2082) (i\u2081 : Fin c\u2081.length)\n    (i\u2082 : Fin c\u2082.length) (hn : n\u2081 = n\u2082) (hc : c\u2081.blocks = c\u2082.blocks) (hi : (i\u2081 : \u2115) = i\u2082) :\n    c\u2081.blocksFun i\u2081 = c\u2082.blocksFun i\u2082 := by\n  cases hn\n  rw [\u2190 Composition.ext_iff] at hc\n  cases hc\n  congr\n  rwa [Fin.ext_iff]\n#align composition.blocks_fun_congr Composition.blocksFun_congr\n-/\n\n#print Composition.sigma_eq_iff_blocks_eq /-\n/-- Two compositions (possibly of different integers) coincide if and only if they have the\nsame sequence of blocks. -/\ntheorem sigma_eq_iff_blocks_eq {c : \u03a3n, Composition n} {c' : \u03a3n, Composition n} :\n    c = c' \u2194 c.2.blocks = c'.2.blocks :=\n  by\n  refine' \u27e8fun H => by rw [H], fun H => _\u27e9\n  rcases c with \u27e8n, c\u27e9\n  rcases c' with \u27e8n', c'\u27e9\n  have : n = n' := by rw [\u2190 c.blocks_sum, \u2190 c'.blocks_sum, H]\n  induction this\n  simp only [true_and_iff, eq_self_iff_true, heq_iff_eq]\n  ext1\n  exact H\n#align composition.sigma_eq_iff_blocks_eq Composition.sigma_eq_iff_blocks_eq\n-/\n\n/-! ### The composition `composition.ones` -/\n\n\n#print Composition.ones /-\n/-- The composition made of blocks all of size `1`. -/\ndef ones (n : \u2115) : Composition n :=\n  \u27e8replicate n (1 : \u2115), fun i hi => by simp [List.eq_of_mem_replicate hi], by simp\u27e9\n#align composition.ones Composition.ones\n-/\n\ninstance {n : \u2115} : Inhabited (Composition n) :=\n  \u27e8Composition.ones n\u27e9\n\n#print Composition.ones_length /-\n@[simp]\ntheorem ones_length (n : \u2115) : (ones n).length = n :=\n  List.length_replicate n 1\n#align composition.ones_length Composition.ones_length\n-/\n\n#print Composition.ones_blocks /-\n@[simp]\ntheorem ones_blocks (n : \u2115) : (ones n).blocks = replicate n (1 : \u2115) :=\n  rfl\n#align composition.ones_blocks Composition.ones_blocks\n-/\n\n#print Composition.ones_blocksFun /-\n@[simp]\ntheorem ones_blocksFun (n : \u2115) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by\n  simp [blocks_fun, ones, blocks, i.2]\n#align composition.ones_blocks_fun Composition.ones_blocksFun\n-/\n\n/- warning: composition.ones_size_up_to -> Composition.ones_sizeUpTo is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (i : Nat), Eq.{1} Nat (Composition.sizeUpTo n (Composition.ones n) i) (LinearOrder.min.{0} Nat Nat.linearOrder i n)\nbut is expected to have type\n  forall (n : Nat) (i : Nat), Eq.{1} Nat (Composition.sizeUpTo n (Composition.ones n) i) (Min.min.{0} Nat instMinNat i n)\nCase conversion may be inaccurate. Consider using '#align composition.ones_size_up_to Composition.ones_sizeUpTo\u2093'. -/\n@[simp]\ntheorem ones_sizeUpTo (n : \u2115) (i : \u2115) : (ones n).sizeUpTo i = min i n := by\n  simp [size_up_to, ones_blocks, take_replicate]\n#align composition.ones_size_up_to Composition.ones_sizeUpTo\n\n/- warning: composition.ones_embedding -> Composition.ones_embedding is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (i : Fin (Composition.length n (Composition.ones n))) (h : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.blocksFun n (Composition.ones n) i)), Eq.{1} (Fin n) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n) (Fin.hasLe (Composition.blocksFun n (Composition.ones n) i)) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin.hasLe (Composition.blocksFun n (Composition.ones n) i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n (Composition.ones n) i)) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin.hasLe (Composition.blocksFun n (Composition.ones n) i))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n (Composition.ones n) i) (Fin.mk (Composition.blocksFun n (Composition.ones n) i) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) h)) (Fin.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.length n (Composition.ones n))) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.length n (Composition.ones n))) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.length n (Composition.ones n))) Nat (coeBase.{1, 1} (Fin (Composition.length n (Composition.ones n))) Nat (Fin.coeToNat (Composition.length n (Composition.ones n)))))) i) (lt_of_lt_of_le.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (Composition.length n (Composition.ones n))) Nat (HasLiftT.mk.{1, 1} (Fin (Composition.length n (Composition.ones n))) Nat (CoeTC\u2093.coe.{1, 1} (Fin (Composition.length n (Composition.ones n))) Nat (coeBase.{1, 1} (Fin (Composition.length n (Composition.ones n))) Nat (Fin.coeToNat (Composition.length n (Composition.ones n)))))) i) (Composition.length n (Composition.ones n)) n (Fin.property (Composition.length n (Composition.ones n)) i) (Composition.length_le n (Composition.ones n))))\nbut is expected to have type\n  forall {n : Nat} (i : Fin (Composition.length n (Composition.ones n))) (h : LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Composition.blocksFun n (Composition.ones n) i)), Eq.{1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n (Composition.ones n) i)) => Fin n) (Fin.mk (Composition.blocksFun n (Composition.ones n) i) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) h)) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n)) (Fin (Composition.blocksFun n (Composition.ones n) i)) (fun (_x : Fin (Composition.blocksFun n (Composition.ones n) i)) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n (Composition.ones n) i)) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n)) (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n (Composition.ones n) i)) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n (Composition.ones n) i)) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n (Composition.ones n) i)) => LE.le.{0} (Fin (Composition.blocksFun n (Composition.ones n) i)) (instLEFin (Composition.blocksFun n (Composition.ones n) i)) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n (Composition.ones n) i)) (Fin.mk (Composition.blocksFun n (Composition.ones n) i) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) h)) (Fin.mk n (Fin.val (Composition.length n (Composition.ones n)) i) (lt_of_lt_of_le.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) (Fin.val (Composition.length n (Composition.ones n)) i) (Composition.length n (Composition.ones n)) n (Fin.isLt (Composition.length n (Composition.ones n)) i) (Composition.length_le n (Composition.ones n))))\nCase conversion may be inaccurate. Consider using '#align composition.ones_embedding Composition.ones_embedding\u2093'. -/\n@[simp]\ntheorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) :\n    (ones n).Embedding i \u27e80, h\u27e9 = \u27e8i, lt_of_lt_of_le i.2 (ones n).length_le\u27e9 :=\n  by\n  ext\n  simpa using i.2.le\n#align composition.ones_embedding Composition.ones_embedding\n\n#print Composition.eq_ones_iff /-\ntheorem eq_ones_iff {c : Composition n} : c = ones n \u2194 \u2200 i \u2208 c.blocks, i = 1 :=\n  by\n  constructor\n  \u00b7 rintro rfl\n    exact fun i => eq_of_mem_replicate\n  \u00b7 intro H\n    ext1\n    have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H\n    have : c.blocks.length = n := by\n      conv_rhs => rw [\u2190 c.blocks_sum, A]\n      simp\n    rw [A, this, ones_blocks]\n#align composition.eq_ones_iff Composition.eq_ones_iff\n-/\n\n/- warning: composition.ne_ones_iff -> Composition.ne_ones_iff is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} {c : Composition n}, Iff (Ne.{1} (Composition n) c (Composition.ones n)) (Exists.{1} Nat (fun (i : Nat) => Exists.{0} (Membership.Mem.{0, 0} Nat (List.{0} Nat) (List.hasMem.{0} Nat) i (Composition.blocks n c)) (fun (H : Membership.Mem.{0, 0} Nat (List.{0} Nat) (List.hasMem.{0} Nat) i (Composition.blocks n c)) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) i)))\nbut is expected to have type\n  forall {n : Nat} {c : Composition n}, Iff (Ne.{1} (Composition n) c (Composition.ones n)) (Exists.{1} Nat (fun (i : Nat) => And (Membership.mem.{0, 0} Nat (List.{0} Nat) (List.instMembershipList.{0} Nat) i (Composition.blocks n c)) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) i)))\nCase conversion may be inaccurate. Consider using '#align composition.ne_ones_iff Composition.ne_ones_iff\u2093'. -/\ntheorem ne_ones_iff {c : Composition n} : c \u2260 ones n \u2194 \u2203 i \u2208 c.blocks, 1 < i :=\n  by\n  refine' (not_congr eq_ones_iff).trans _\n  have : \u2200 j \u2208 c.blocks, j = 1 \u2194 j \u2264 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj]\n  simp (config := { contextual := true }) [this]\n#align composition.ne_ones_iff Composition.ne_ones_iff\n\n#print Composition.eq_ones_iff_length /-\ntheorem eq_ones_iff_length {c : Composition n} : c = ones n \u2194 c.length = n :=\n  by\n  constructor\n  \u00b7 rintro rfl\n    exact ones_length n\n  \u00b7 contrapose\n    intro H length_n\n    apply lt_irrefl n\n    calc\n      n = \u2211 i : Fin c.length, 1 := by simp [length_n]\n      _ < \u2211 i : Fin c.length, c.blocks_fun i :=\n        by\n        obtain \u27e8i, hi, i_blocks\u27e9 : \u2203 i \u2208 c.blocks, 1 < i := ne_ones_iff.1 H\n        rw [\u2190 of_fn_blocks_fun, mem_of_fn c.blocks_fun, Set.mem_range] at hi\n        obtain \u27e8j : Fin c.length, hj : c.blocks_fun j = i\u27e9 := hi\n        rw [\u2190 hj] at i_blocks\n        exact Finset.sum_lt_sum (fun i hi => by simp [blocks_fun]) \u27e8j, Finset.mem_univ _, i_blocks\u27e9\n      _ = n := c.sum_blocks_fun\n      \n#align composition.eq_ones_iff_length Composition.eq_ones_iff_length\n-/\n\n#print Composition.eq_ones_iff_le_length /-\ntheorem eq_ones_iff_le_length {c : Composition n} : c = ones n \u2194 n \u2264 c.length := by\n  simp [eq_ones_iff_length, le_antisymm_iff, c.length_le]\n#align composition.eq_ones_iff_le_length Composition.eq_ones_iff_le_length\n-/\n\n/-! ### The composition `composition.single` -/\n\n\n#print Composition.single /-\n/-- The composition made of a single block of size `n`. -/\ndef single (n : \u2115) (h : 0 < n) : Composition n :=\n  \u27e8[n], by simp [h], by simp\u27e9\n#align composition.single Composition.single\n-/\n\n#print Composition.single_length /-\n@[simp]\ntheorem single_length {n : \u2115} (h : 0 < n) : (single n h).length = 1 :=\n  rfl\n#align composition.single_length Composition.single_length\n-/\n\n#print Composition.single_blocks /-\n@[simp]\ntheorem single_blocks {n : \u2115} (h : 0 < n) : (single n h).blocks = [n] :=\n  rfl\n#align composition.single_blocks Composition.single_blocks\n-/\n\n#print Composition.single_blocksFun /-\n@[simp]\ntheorem single_blocksFun {n : \u2115} (h : 0 < n) (i : Fin (single n h).length) :\n    (single n h).blocksFun i = n := by simp [blocks_fun, single, blocks, i.2]\n#align composition.single_blocks_fun Composition.single_blocksFun\n-/\n\n/- warning: composition.single_embedding -> Composition.single_embedding is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (h : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) (i : Fin n), Eq.{1} (Fin n) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial)))))) (Fin n) (Fin.hasLe (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial)))))) (Fin.hasLe n)) (fun (_x : RelEmbedding.{0, 0} (Fin (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial)))))) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial)))))) (Fin.hasLe (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial))))))) (LE.le.{0} (Fin n) (Fin.hasLe n))) => (Fin (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial)))))) -> (Fin n)) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial)))))) (Fin n) (LE.le.{0} (Fin (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial)))))) (Fin.hasLe (Composition.blocksFun n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial))))))) (LE.le.{0} (Fin n) (Fin.hasLe n))) (Composition.embedding n (Composition.single n h) (Fin.mk (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Eq.subst.{1} Nat (fun (_x : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Composition.length n (Composition.single n h))) (Composition.length n (Composition.single n h)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Composition.single_length n h) (zero_lt_one.{0} Nat Nat.hasZero Nat.hasOne (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) (OrderedSemiring.zeroLEOneClass.{0} Nat Nat.orderedSemiring) (NeZero.one.{0} Nat (NonAssocSemiring.toMulZeroOneClass.{0} Nat (Semiring.toNonAssocSemiring.{0} Nat Nat.semiring)) Nat.nontrivial))))) i) i\nbut is expected to have type\n  forall {n : Nat} (h : LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) (i : Fin n), Eq.{1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) => Fin n) i) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (Fin n)) (Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (fun (_x : Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) => Fin n) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (Fin n)) (Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (Fin n) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (Fin n))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (Fin n) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) => LE.le.{0} (Fin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) (instLEFin (Composition.blocksFun n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin n) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin n) => LE.le.{0} (Fin n) (instLEFin n) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (Composition.embedding n (Composition.single n h) (OfNat.ofNat.{0} (Fin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (Fin.instOfNatFin (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) 0 (NeZero.succ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))) i) i\nCase conversion may be inaccurate. Consider using '#align composition.single_embedding Composition.single_embedding\u2093'. -/\n@[simp]\ntheorem single_embedding {n : \u2115} (h : 0 < n) (i : Fin n) :\n    (single n h).Embedding \u27e80, single_length h \u25b8 zero_lt_one\u27e9 i = i :=\n  by\n  ext\n  simp\n#align composition.single_embedding Composition.single_embedding\n\n#print Composition.eq_single_iff_length /-\ntheorem eq_single_iff_length {n : \u2115} (h : 0 < n) {c : Composition n} :\n    c = single n h \u2194 c.length = 1 := by\n  constructor\n  \u00b7 intro H\n    rw [H]\n    exact single_length h\n  \u00b7 intro H\n    ext1\n    have A : c.blocks.length = 1 := H \u25b8 c.blocks_length\n    have B : c.blocks.sum = n := c.blocks_sum\n    rw [eq_cons_of_length_one A] at B\u22a2\n    simpa [single_blocks] using B\n#align composition.eq_single_iff_length Composition.eq_single_iff_length\n-/\n\n#print Composition.ne_single_iff /-\ntheorem ne_single_iff {n : \u2115} (hn : 0 < n) {c : Composition n} :\n    c \u2260 single n hn \u2194 \u2200 i, c.blocksFun i < n :=\n  by\n  rw [\u2190 not_iff_not]\n  push_neg\n  constructor\n  \u00b7 rintro rfl\n    exact \u27e8\u27e80, by simp\u27e9, by simp\u27e9\n  \u00b7 rintro \u27e8i, hi\u27e9\n    rw [eq_single_iff_length]\n    have : \u2200 j : Fin c.length, j = i := by\n      intro j\n      by_contra ji\n      apply lt_irrefl (\u2211 k, c.blocks_fun k)\n      calc\n        (\u2211 k, c.blocks_fun k) \u2264 c.blocks_fun i := by simp only [c.sum_blocks_fun, hi]\n        _ < \u2211 k, c.blocks_fun k :=\n          Finset.single_lt_sum ji (Finset.mem_univ _) (Finset.mem_univ _) (c.one_le_blocks_fun j)\n            fun _ _ _ => zero_le _\n        \n    simpa using Fintype.card_eq_one_of_forall_eq this\n#align composition.ne_single_iff Composition.ne_single_iff\n-/\n\nend Composition\n\n/-!\n### Splitting a list\n\nGiven a list of length `n` and a composition `c` of `n`, one can split `l` into `c.length` sublists\nof respective lengths `c.blocks_fun 0`, ..., `c.blocks_fun (c.length-1)`. This is inverse to the\njoin operation.\n-/\n\n\nnamespace List\n\nvariable {\u03b1 : Type _}\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n#print List.splitWrtCompositionAux /-\n/-- Auxiliary for `list.split_wrt_composition`. -/\ndef splitWrtCompositionAux : List \u03b1 \u2192 List \u2115 \u2192 List (List \u03b1)\n  | l, [] => []\n  | l, n::ns =>\n    let (l\u2081, l\u2082) := l.splitAt n\n    l\u2081::split_wrt_composition_aux l\u2082 ns\n#align list.split_wrt_composition_aux List.splitWrtCompositionAux\n-/\n\n#print List.splitWrtComposition /-\n/-- Given a list of length `n` and a composition `[i\u2081, ..., i\u2096]` of `n`, split `l` into a list of\n`k` lists corresponding to the blocks of the composition, of respective lengths `i\u2081`, ..., `i\u2096`.\nThis makes sense mostly when `n = l.length`, but this is not necessary for the definition. -/\ndef splitWrtComposition (l : List \u03b1) (c : Composition n) : List (List \u03b1) :=\n  splitWrtCompositionAux l c.blocks\n#align list.split_wrt_composition List.splitWrtComposition\n-/\n\nattribute [local simp] split_wrt_composition_aux.equations._eqn_1\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n#print List.splitWrtCompositionAux_cons /-\n@[local simp]\ntheorem splitWrtCompositionAux_cons (l : List \u03b1) (n ns) :\n    l.splitWrtCompositionAux (n::ns) = take n l::(drop n l).splitWrtCompositionAux ns := by\n  simp [split_wrt_composition_aux]\n#align list.split_wrt_composition_aux_cons List.splitWrtCompositionAux_cons\n-/\n\n#print List.length_splitWrtCompositionAux /-\ntheorem length_splitWrtCompositionAux (l : List \u03b1) (ns) :\n    length (l.splitWrtCompositionAux ns) = ns.length := by induction ns generalizing l <;> simp [*]\n#align list.length_split_wrt_composition_aux List.length_splitWrtCompositionAux\n-/\n\n#print List.length_splitWrtComposition /-\n/-- When one splits a list along a composition `c`, the number of sublists thus created is\n`c.length`. -/\n@[simp]\ntheorem length_splitWrtComposition (l : List \u03b1) (c : Composition n) :\n    length (l.splitWrtComposition c) = c.length :=\n  length_splitWrtCompositionAux _ _\n#align list.length_split_wrt_composition List.length_splitWrtComposition\n-/\n\n#print List.map_length_splitWrtCompositionAux /-\ntheorem map_length_splitWrtCompositionAux {ns : List \u2115} :\n    \u2200 {l : List \u03b1}, ns.Sum \u2264 l.length \u2192 map length (l.splitWrtCompositionAux ns) = ns :=\n  by\n  induction' ns with n ns IH <;> intro l h <;> simp at h\u22a2\n  have := le_trans (Nat.le_add_right _ _) h\n  rw [IH]; \u00b7 simp [this]\n  rwa [length_drop, le_tsub_iff_left this]\n#align list.map_length_split_wrt_composition_aux List.map_length_splitWrtCompositionAux\n-/\n\n#print List.map_length_splitWrtComposition /-\n/-- When one splits a list along a composition `c`, the lengths of the sublists thus created are\ngiven by the block sizes in `c`. -/\ntheorem map_length_splitWrtComposition (l : List \u03b1) (c : Composition l.length) :\n    map length (l.splitWrtComposition c) = c.blocks :=\n  map_length_splitWrtCompositionAux (le_of_eq c.blocks_sum)\n#align list.map_length_split_wrt_composition List.map_length_splitWrtComposition\n-/\n\n#print List.length_pos_of_mem_splitWrtComposition /-\ntheorem length_pos_of_mem_splitWrtComposition {l l' : List \u03b1} {c : Composition l.length}\n    (h : l' \u2208 l.splitWrtComposition c) : 0 < length l' :=\n  by\n  have : l'.length \u2208 (l.split_wrt_composition c).map List.length :=\n    List.mem_map_of_mem List.length h\n  rw [map_length_split_wrt_composition] at this\n  exact c.blocks_pos this\n#align list.length_pos_of_mem_split_wrt_composition List.length_pos_of_mem_splitWrtComposition\n-/\n\n#print List.sum_take_map_length_splitWrtComposition /-\ntheorem sum_take_map_length_splitWrtComposition (l : List \u03b1) (c : Composition l.length) (i : \u2115) :\n    (((l.splitWrtComposition c).map length).take i).Sum = c.sizeUpTo i :=\n  by\n  congr\n  exact map_length_split_wrt_composition l c\n#align list.sum_take_map_length_split_wrt_composition List.sum_take_map_length_splitWrtComposition\n-/\n\n#print List.nthLe_splitWrtCompositionAux /-\ntheorem nthLe_splitWrtCompositionAux (l : List \u03b1) (ns : List \u2115) {i : \u2115} (hi) :\n    nthLe (l.splitWrtCompositionAux ns) i hi =\n      (l.take (ns.take (i + 1)).Sum).drop (ns.take i).Sum :=\n  by\n  induction' ns with n ns IH generalizing l i; \u00b7 cases hi\n  cases i <;> simp [IH]\n  rw [add_comm n, drop_add, drop_take]\n#align list.nth_le_split_wrt_composition_aux List.nthLe_splitWrtCompositionAux\n-/\n\n#print List.nthLe_splitWrtComposition /-\n/-- The `i`-th sublist in the splitting of a list `l` along a composition `c`, is the slice of `l`\nbetween the indices `c.size_up_to i` and `c.size_up_to (i+1)`, i.e., the indices in the `i`-th\nblock of the composition. -/\ntheorem nthLe_splitWrtComposition (l : List \u03b1) (c : Composition n) {i : \u2115}\n    (hi : i < (l.splitWrtComposition c).length) :\n    nthLe (l.splitWrtComposition c) i hi = (l.take (c.sizeUpTo (i + 1))).drop (c.sizeUpTo i) :=\n  nthLe_splitWrtCompositionAux _ _ _\n#align list.nth_le_split_wrt_composition List.nthLe_splitWrtComposition\n-/\n\n#print List.join_splitWrtCompositionAux /-\ntheorem join_splitWrtCompositionAux {ns : List \u2115} :\n    \u2200 {l : List \u03b1}, ns.Sum = l.length \u2192 (l.splitWrtCompositionAux ns).join = l :=\n  by\n  induction' ns with n ns IH <;> intro l h <;> simp at h\u22a2\n  \u00b7 exact (length_eq_zero.1 h.symm).symm\n  rw [IH]; \u00b7 simp\n  rwa [length_drop, \u2190 h, add_tsub_cancel_left]\n#align list.join_split_wrt_composition_aux List.join_splitWrtCompositionAux\n-/\n\n#print List.join_splitWrtComposition /-\n/-- If one splits a list along a composition, and then joins the sublists, one gets back the\noriginal list. -/\n@[simp]\ntheorem join_splitWrtComposition (l : List \u03b1) (c : Composition l.length) :\n    (l.splitWrtComposition c).join = l :=\n  join_splitWrtCompositionAux c.blocks_sum\n#align list.join_split_wrt_composition List.join_splitWrtComposition\n-/\n\n#print List.splitWrtComposition_join /-\n/-- If one joins a list of lists and then splits the join along the right composition, one gets\nback the original list of lists. -/\n@[simp]\ntheorem splitWrtComposition_join (L : List (List \u03b1)) (c : Composition L.join.length)\n    (h : map length L = c.blocks) : splitWrtComposition (join L) c = L := by\n  simp only [eq_self_iff_true, and_self_iff, eq_iff_join_eq, join_split_wrt_composition,\n    map_length_split_wrt_composition, h]\n#align list.split_wrt_composition_join List.splitWrtComposition_join\n-/\n\nend List\n\n/-!\n### Compositions as sets\n\nCombinatorial viewpoints on compositions, seen as finite subsets of `fin (n+1)` containing `0` and\n`n`, where the points of the set (other than `n`) correspond to the leftmost points of each block.\n-/\n\n\n#print compositionAsSetEquiv /-\n/-- Bijection between compositions of `n` and subsets of `{0, ..., n-2}`, defined by\nconsidering the restriction of the subset to `{1, ..., n-1}` and shifting to the left by one. -/\ndef compositionAsSetEquiv (n : \u2115) : CompositionAsSet n \u2243 Finset (Fin (n - 1))\n    where\n  toFun c :=\n    { i : Fin (n - 1) |\n        (\u27e81 + (i : \u2115), by\n              apply (add_lt_add_left i.is_lt 1).trans_le\n              rw [Nat.succ_eq_add_one, add_comm]\n              exact add_le_add (Nat.sub_le n 1) (le_refl 1)\u27e9 :\n            Fin n.succ) \u2208\n          c.boundaries }.toFinset\n  invFun s :=\n    { boundaries :=\n        { i : Fin n.succ |\n            i = 0 \u2228 i = Fin.last n \u2228 \u2203 (j : Fin (n - 1))(hj : j \u2208 s), (i : \u2115) = j + 1 }.toFinset\n      zero_mem := by simp\n      getLast_mem := by simp }\n  left_inv := by\n    intro c\n    ext i\n    simp only [exists_prop, add_comm, Set.mem_toFinset, true_or_iff, or_true_iff, Set.mem_setOf_eq]\n    constructor\n    \u00b7 rintro (rfl | rfl | \u27e8j, hj1, hj2\u27e9)\n      \u00b7 exact c.zero_mem\n      \u00b7 exact c.last_mem\n      \u00b7 convert hj1\n        rwa [Fin.ext_iff]\n    \u00b7 simp only [or_iff_not_imp_left]\n      intro i_mem i_ne_zero i_ne_last\n      simp [Fin.ext_iff] at i_ne_zero i_ne_last\n      have A : (1 + (i - 1) : \u2115) = (i : \u2115) := by\n        rw [add_comm]\n        exact Nat.succ_pred_eq_of_pos (pos_iff_ne_zero.mpr i_ne_zero)\n      refine' \u27e8\u27e8i - 1, _\u27e9, _, _\u27e9\n      \u00b7 have : (i : \u2115) < n + 1 := i.2\n        simp [Nat.lt_succ_iff_lt_or_eq, i_ne_last] at this\n        exact Nat.pred_lt_pred i_ne_zero this\n      \u00b7 convert i_mem\n        rw [Fin.ext_iff]\n        simp only [Fin.val_mk, A]\n      \u00b7 simp [A]\n  right_inv := by\n    intro s\n    ext i\n    have : 1 + (i : \u2115) \u2260 n := by\n      apply ne_of_lt\n      convert add_lt_add_left i.is_lt 1\n      rw [add_comm]\n      apply (Nat.succ_pred_eq_of_pos _).symm\n      exact (zero_le i.val).trans_lt (i.2.trans_le (Nat.sub_le n 1))\n    simp only [Fin.ext_iff, exists_prop, Fin.val_zero, add_comm, Set.mem_toFinset, Set.mem_setOf_eq,\n      Fin.val_last]\n    erw [Set.mem_setOf_eq]\n    simp only [this, false_or_iff, add_right_inj, add_eq_zero_iff, one_ne_zero, false_and_iff,\n      Fin.val_mk]\n    constructor\n    \u00b7 rintro \u27e8j, js, hj\u27e9\n      convert js\n      exact Fin.ext_iff.2 hj\n    \u00b7 intro h\n      exact \u27e8i, h, rfl\u27e9\n#align composition_as_set_equiv compositionAsSetEquiv\n-/\n\n#print compositionAsSetFintype /-\ninstance compositionAsSetFintype (n : \u2115) : Fintype (CompositionAsSet n) :=\n  Fintype.ofEquiv _ (compositionAsSetEquiv n).symm\n#align composition_as_set_fintype compositionAsSetFintype\n-/\n\n#print compositionAsSet_card /-\ntheorem compositionAsSet_card (n : \u2115) : Fintype.card (CompositionAsSet n) = 2 ^ (n - 1) :=\n  by\n  have : Fintype.card (Finset (Fin (n - 1))) = 2 ^ (n - 1) := by simp\n  rw [\u2190 this]\n  exact Fintype.card_congr (compositionAsSetEquiv n)\n#align composition_as_set_card compositionAsSet_card\n-/\n\nnamespace CompositionAsSet\n\nvariable (c : CompositionAsSet n)\n\n#print CompositionAsSet.boundaries_nonempty /-\ntheorem boundaries_nonempty : c.boundaries.Nonempty :=\n  \u27e80, c.zero_mem\u27e9\n#align composition_as_set.boundaries_nonempty CompositionAsSet.boundaries_nonempty\n-/\n\n#print CompositionAsSet.card_boundaries_pos /-\ntheorem card_boundaries_pos : 0 < Finset.card c.boundaries :=\n  Finset.card_pos.mpr c.boundaries_nonempty\n#align composition_as_set.card_boundaries_pos CompositionAsSet.card_boundaries_pos\n-/\n\n#print CompositionAsSet.length /-\n/-- Number of blocks in a `composition_as_set`. -/\ndef length : \u2115 :=\n  Finset.card c.boundaries - 1\n#align composition_as_set.length CompositionAsSet.length\n-/\n\n#print CompositionAsSet.card_boundaries_eq_succ_length /-\ntheorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 :=\n  (tsub_eq_iff_eq_add_of_le (Nat.succ_le_of_lt c.card_boundaries_pos)).mp rfl\n#align composition_as_set.card_boundaries_eq_succ_length CompositionAsSet.card_boundaries_eq_succ_length\n-/\n\n#print CompositionAsSet.length_lt_card_boundaries /-\ntheorem length_lt_card_boundaries : c.length < c.boundaries.card :=\n  by\n  rw [c.card_boundaries_eq_succ_length]\n  exact lt_add_one _\n#align composition_as_set.length_lt_card_boundaries CompositionAsSet.length_lt_card_boundaries\n-/\n\n#print CompositionAsSet.lt_length /-\ntheorem lt_length (i : Fin c.length) : (i : \u2115) + 1 < c.boundaries.card :=\n  lt_tsub_iff_right.mp i.2\n#align composition_as_set.lt_length CompositionAsSet.lt_length\n-/\n\n#print CompositionAsSet.lt_length' /-\ntheorem lt_length' (i : Fin c.length) : (i : \u2115) < c.boundaries.card :=\n  lt_of_le_of_lt (Nat.le_succ i) (c.lt_length i)\n#align composition_as_set.lt_length' CompositionAsSet.lt_length'\n-/\n\n/- warning: composition_as_set.boundary -> CompositionAsSet.boundary is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : CompositionAsSet n), OrderEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n)))))))\nbut is expected to have type\n  forall {n : Nat} (c : CompositionAsSet n), OrderEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))\nCase conversion may be inaccurate. Consider using '#align composition_as_set.boundary CompositionAsSet.boundary\u2093'. -/\n/-- Canonical increasing bijection from `fin c.boundaries.card` to `c.boundaries`. -/\ndef boundary : Fin c.boundaries.card \u21aao Fin (n + 1) :=\n  c.boundaries.orderEmbOfFin rfl\n#align composition_as_set.boundary CompositionAsSet.boundary\n\n/- warning: composition_as_set.boundary_zero -> CompositionAsSet.boundary_zero is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : CompositionAsSet n), Eq.{1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n)))))))) (fun (_x : RelEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n))))))))) => (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) -> (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n))))))))) (CompositionAsSet.boundary n c) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (CompositionAsSet.card_boundaries_pos n c))) (OfNat.ofNat.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne))) 0 (OfNat.mk.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne))) 0 (Zero.zero.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne))) (Fin.hasZeroOfNeZero (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (One.one.{0} Nat Nat.hasOne)) (NeZero.succ n)))))\nbut is expected to have type\n  forall {n : Nat} (c : CompositionAsSet n), Eq.{1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (CompositionAsSet.card_boundaries_pos n c))) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (fun (_x : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (instLEFin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (CompositionAsSet.boundary n c)) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (CompositionAsSet.card_boundaries_pos n c))) (OfNat.ofNat.{0} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (CompositionAsSet.card_boundaries_pos n c))) 0 (Fin.instOfNatFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) 0 (NeZero.succ n)))\nCase conversion may be inaccurate. Consider using '#align composition_as_set.boundary_zero CompositionAsSet.boundary_zero\u2093'. -/\n@[simp]\ntheorem boundary_zero : (c.boundary \u27e80, c.card_boundaries_pos\u27e9 : Fin (n + 1)) = 0 :=\n  by\n  rw [boundary, Finset.orderEmbOfFin_zero rfl c.card_boundaries_pos]\n  exact le_antisymm (Finset.min'_le _ _ c.zero_mem) (Fin.zero_le _)\n#align composition_as_set.boundary_zero CompositionAsSet.boundary_zero\n\n/- warning: composition_as_set.boundary_length -> CompositionAsSet.boundary_length is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : CompositionAsSet n), Eq.{1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n)))))))) (fun (_x : RelEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n))))))))) => (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) -> (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n))))))))) (CompositionAsSet.boundary n c) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) (CompositionAsSet.length n c) (CompositionAsSet.length_lt_card_boundaries n c))) (Fin.last n)\nbut is expected to have type\n  forall {n : Nat} (c : CompositionAsSet n), Eq.{1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) (CompositionAsSet.length n c) (CompositionAsSet.length_lt_card_boundaries n c))) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (fun (_x : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (instLEFin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (CompositionAsSet.boundary n c)) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) (CompositionAsSet.length n c) (CompositionAsSet.length_lt_card_boundaries n c))) (Fin.last n)\nCase conversion may be inaccurate. Consider using '#align composition_as_set.boundary_length CompositionAsSet.boundary_length\u2093'. -/\n@[simp]\ntheorem boundary_length : c.boundary \u27e8c.length, c.length_lt_card_boundaries\u27e9 = Fin.last n :=\n  by\n  convert Finset.orderEmbOfFin_last rfl c.card_boundaries_pos\n  exact le_antisymm (Finset.le_max' _ _ c.last_mem) (Fin.le_last _)\n#align composition_as_set.boundary_length CompositionAsSet.boundary_length\n\n#print CompositionAsSet.blocksFun /-\n/-- Size of the `i`-th block in a `composition_as_set`, seen as a function on `fin c.length`. -/\ndef blocksFun (i : Fin c.length) : \u2115 :=\n  c.boundary \u27e8(i : \u2115) + 1, c.lt_length i\u27e9 - c.boundary \u27e8i, c.lt_length' i\u27e9\n#align composition_as_set.blocks_fun CompositionAsSet.blocksFun\n-/\n\n#print CompositionAsSet.blocksFun_pos /-\ntheorem blocksFun_pos (i : Fin c.length) : 0 < c.blocksFun i :=\n  haveI : (\u27e8i, c.lt_length' i\u27e9 : Fin c.boundaries.card) < \u27e8i + 1, c.lt_length i\u27e9 :=\n    Nat.lt_succ_self _\n  lt_tsub_iff_left.mpr ((c.boundaries.order_emb_of_fin rfl).StrictMono this)\n#align composition_as_set.blocks_fun_pos CompositionAsSet.blocksFun_pos\n-/\n\n#print CompositionAsSet.blocks /-\n/-- List of the sizes of the blocks in a `composition_as_set`. -/\ndef blocks (c : CompositionAsSet n) : List \u2115 :=\n  ofFn c.blocksFun\n#align composition_as_set.blocks CompositionAsSet.blocks\n-/\n\n#print CompositionAsSet.blocks_length /-\n@[simp]\ntheorem blocks_length : c.blocks.length = c.length :=\n  length_ofFn _\n#align composition_as_set.blocks_length CompositionAsSet.blocks_length\n-/\n\n/- warning: composition_as_set.blocks_partial_sum -> CompositionAsSet.blocks_partial_sum is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : CompositionAsSet n) {i : Nat} (h : LT.lt.{0} Nat Nat.hasLt i (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))), Eq.{1} Nat (List.sum.{0} Nat Nat.hasAdd Nat.hasZero (List.take.{0} Nat i (CompositionAsSet.blocks n c))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (HasLiftT.mk.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (CoeTC\u2093.coe.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (coeBase.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (Fin.coeToNat (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))) (coeFn.{1, 1} (OrderEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n)))))))) (fun (_x : RelEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n))))))))) => (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) -> (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))) (RelEmbedding.hasCoeToFun.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin.hasLe (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)))) (LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Preorder.toLE.{0} (Fin (Nat.succ n)) (PartialOrder.toPreorder.{0} (Fin (Nat.succ n)) (SemilatticeInf.toPartialOrder.{0} (Fin (Nat.succ n)) (Lattice.toSemilatticeInf.{0} (Fin (Nat.succ n)) (LinearOrder.toLattice.{0} (Fin (Nat.succ n)) (Fin.linearOrder (Nat.succ n))))))))) (CompositionAsSet.boundary n c) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) i h)))\nbut is expected to have type\n  forall {n : Nat} (c : CompositionAsSet n) {i : Nat} (h : LT.lt.{0} Nat instLTNat i (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))), Eq.{1} Nat (List.sum.{0} Nat instAddNat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero) (List.take.{0} Nat i (CompositionAsSet.blocks n c))) (Fin.val (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (fun (_x : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Function.instEmbeddingLikeEmbedding.{1, 1} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))))) (RelEmbedding.toEmbedding.{0, 0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => LE.le.{0} (Fin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (instLEFin (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) => LE.le.{0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (instLEFin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) (CompositionAsSet.boundary n c)) (Fin.mk (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c)) i h)))\nCase conversion may be inaccurate. Consider using '#align composition_as_set.blocks_partial_sum CompositionAsSet.blocks_partial_sum\u2093'. -/\ntheorem blocks_partial_sum {i : \u2115} (h : i < c.boundaries.card) :\n    (c.blocks.take i).Sum = c.boundary \u27e8i, h\u27e9 :=\n  by\n  induction' i with i IH\n  \u00b7 simp\n  have A : i < c.blocks.length :=\n    by\n    rw [c.card_boundaries_eq_succ_length] at h\n    simp [blocks, Nat.lt_of_succ_lt_succ h]\n  have B : i < c.boundaries.card := lt_of_lt_of_le A (by simp [blocks, length, Nat.sub_le])\n  rw [sum_take_succ _ _ A, IH B]\n  simp only [blocks, blocks_fun, nth_le_of_fn']\n  apply add_tsub_cancel_of_le\n  simp\n#align composition_as_set.blocks_partial_sum CompositionAsSet.blocks_partial_sum\n\n/- warning: composition_as_set.mem_boundaries_iff_exists_blocks_sum_take_eq -> CompositionAsSet.mem_boundaries_iff_exists_blocks_sum_take_eq is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} (c : CompositionAsSet n) {j : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))}, Iff (Membership.Mem.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Finset.{0} (Fin (Nat.succ n))) (Finset.hasMem.{0} (Fin (Nat.succ n))) j (CompositionAsSet.boundaries n c)) (Exists.{1} Nat (fun (i : Nat) => Exists.{0} (LT.lt.{0} Nat Nat.hasLt i (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (fun (H : LT.lt.{0} Nat Nat.hasLt i (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) => Eq.{1} Nat (List.sum.{0} Nat Nat.hasAdd Nat.hasZero (List.take.{0} Nat i (CompositionAsSet.blocks n c))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (HasLiftT.mk.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (CoeTC\u2093.coe.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (coeBase.{1, 1} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) Nat (Fin.coeToNat (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))) j))))\nbut is expected to have type\n  forall {n : Nat} (c : CompositionAsSet n) {j : Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))}, Iff (Membership.mem.{0, 0} (Fin (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Finset.{0} (Fin (Nat.succ n))) (Finset.instMembershipFinset.{0} (Fin (Nat.succ n))) j (CompositionAsSet.boundaries n c)) (Exists.{1} Nat (fun (i : Nat) => And (LT.lt.{0} Nat instLTNat i (Finset.card.{0} (Fin (Nat.succ n)) (CompositionAsSet.boundaries n c))) (Eq.{1} Nat (List.sum.{0} Nat instAddNat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero) (List.take.{0} Nat i (CompositionAsSet.blocks n c))) (Fin.val (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) j))))\nCase conversion may be inaccurate. Consider using '#align composition_as_set.mem_boundaries_iff_exists_blocks_sum_take_eq CompositionAsSet.mem_boundaries_iff_exists_blocks_sum_take_eq\u2093'. -/\ntheorem mem_boundaries_iff_exists_blocks_sum_take_eq {j : Fin (n + 1)} :\n    j \u2208 c.boundaries \u2194 \u2203 i < c.boundaries.card, (c.blocks.take i).Sum = j :=\n  by\n  constructor\n  \u00b7 intro hj\n    rcases(c.boundaries.order_iso_of_fin rfl).Surjective \u27e8j, hj\u27e9 with \u27e8i, hi\u27e9\n    rw [Subtype.ext_iff, Subtype.coe_mk] at hi\n    refine' \u27e8i.1, i.2, _\u27e9\n    rw [\u2190 hi, c.blocks_partial_sum i.2]\n    rfl\n  \u00b7 rintro \u27e8i, hi, H\u27e9\n    convert(c.boundaries.order_iso_of_fin rfl \u27e8i, hi\u27e9).2\n    have : c.boundary \u27e8i, hi\u27e9 = j := by rwa [Fin.ext_iff, \u2190 c.blocks_partial_sum hi]\n    exact this.symm\n#align composition_as_set.mem_boundaries_iff_exists_blocks_sum_take_eq CompositionAsSet.mem_boundaries_iff_exists_blocks_sum_take_eq\n\n#print CompositionAsSet.blocks_sum /-\ntheorem blocks_sum : c.blocks.Sum = n :=\n  by\n  have : c.blocks.take c.length = c.blocks := take_all_of_le (by simp [blocks])\n  rw [\u2190 this, c.blocks_partial_sum c.length_lt_card_boundaries, c.boundary_length]\n  rfl\n#align composition_as_set.blocks_sum CompositionAsSet.blocks_sum\n-/\n\n#print CompositionAsSet.toComposition /-\n/-- Associating a `composition n` to a `composition_as_set n`, by registering the sizes of the\nblocks as a list of positive integers. -/\ndef toComposition : Composition n where\n  blocks := c.blocks\n  blocks_pos := by simp only [blocks, forall_mem_of_fn_iff, blocks_fun_pos c, forall_true_iff]\n  blocks_sum := c.blocks_sum\n#align composition_as_set.to_composition CompositionAsSet.toComposition\n-/\n\nend CompositionAsSet\n\n/-!\n### Equivalence between compositions and compositions as sets\n\nIn this section, we explain how to go back and forth between a `composition` and a\n`composition_as_set`, by showing that their `blocks` and `length` and `boundaries` correspond to\neach other, and construct an equivalence between them called `composition_equiv`.\n-/\n\n\n#print Composition.toCompositionAsSet_length /-\n@[simp]\ntheorem Composition.toCompositionAsSet_length (c : Composition n) :\n    c.toCompositionAsSet.length = c.length := by\n  simp [Composition.toCompositionAsSet, CompositionAsSet.length, c.card_boundaries_eq_succ_length]\n#align composition.to_composition_as_set_length Composition.toCompositionAsSet_length\n-/\n\n#print CompositionAsSet.toComposition_length /-\n@[simp]\ntheorem CompositionAsSet.toComposition_length (c : CompositionAsSet n) :\n    c.toComposition.length = c.length := by\n  simp [CompositionAsSet.toComposition, Composition.length, Composition.blocks]\n#align composition_as_set.to_composition_length CompositionAsSet.toComposition_length\n-/\n\n#print Composition.toCompositionAsSet_blocks /-\n@[simp]\ntheorem Composition.toCompositionAsSet_blocks (c : Composition n) :\n    c.toCompositionAsSet.blocks = c.blocks :=\n  by\n  let d := c.to_composition_as_set\n  change d.blocks = c.blocks\n  have length_eq : d.blocks.length = c.blocks.length :=\n    by\n    convert c.to_composition_as_set_length\n    simp [CompositionAsSet.blocks]\n  suffices H : \u2200 i \u2264 d.blocks.length, (d.blocks.take i).Sum = (c.blocks.take i).Sum\n  exact eq_of_sum_take_eq length_eq H\n  intro i hi\n  have i_lt : i < d.boundaries.card :=\n    by\n    convert Nat.lt_succ_iff.2 hi\n    convert d.card_boundaries_eq_succ_length\n    exact length_of_fn _\n  have i_lt' : i < c.boundaries.card := i_lt\n  have i_lt'' : i < c.length + 1 := by rwa [c.card_boundaries_eq_succ_length] at i_lt'\n  have A :\n    d.boundaries.order_emb_of_fin rfl \u27e8i, i_lt\u27e9 =\n      c.boundaries.order_emb_of_fin c.card_boundaries_eq_succ_length \u27e8i, i_lt''\u27e9 :=\n    rfl\n  have B : c.size_up_to i = c.boundary \u27e8i, i_lt''\u27e9 := rfl\n  rw [d.blocks_partial_sum i_lt, CompositionAsSet.boundary, \u2190 Composition.sizeUpTo, B, A,\n    c.order_emb_of_fin_boundaries]\n#align composition.to_composition_as_set_blocks Composition.toCompositionAsSet_blocks\n-/\n\n#print CompositionAsSet.toComposition_blocks /-\n@[simp]\ntheorem CompositionAsSet.toComposition_blocks (c : CompositionAsSet n) :\n    c.toComposition.blocks = c.blocks :=\n  rfl\n#align composition_as_set.to_composition_blocks CompositionAsSet.toComposition_blocks\n-/\n\n#print CompositionAsSet.toComposition_boundaries /-\n@[simp]\ntheorem CompositionAsSet.toComposition_boundaries (c : CompositionAsSet n) :\n    c.toComposition.boundaries = c.boundaries :=\n  by\n  ext j\n  simp only [c.mem_boundaries_iff_exists_blocks_sum_take_eq, Composition.boundaries, Finset.mem_map]\n  constructor\n  \u00b7 rintro \u27e8i, _, hi\u27e9\n    refine' \u27e8i.1, _, _\u27e9\n    simpa [c.card_boundaries_eq_succ_length] using i.2\n    simp [Composition.boundary, Composition.sizeUpTo, \u2190 hi]\n  \u00b7 rintro \u27e8i, i_lt, hi\u27e9\n    refine' \u27e8i, by simp, _\u27e9\n    rw [c.card_boundaries_eq_succ_length] at i_lt\n    simp [Composition.boundary, Nat.mod_eq_of_lt i_lt, Composition.sizeUpTo, hi]\n#align composition_as_set.to_composition_boundaries CompositionAsSet.toComposition_boundaries\n-/\n\n#print Composition.toCompositionAsSet_boundaries /-\n@[simp]\ntheorem Composition.toCompositionAsSet_boundaries (c : Composition n) :\n    c.toCompositionAsSet.boundaries = c.boundaries :=\n  rfl\n#align composition.to_composition_as_set_boundaries Composition.toCompositionAsSet_boundaries\n-/\n\n#print compositionEquiv /-\n/-- Equivalence between `composition n` and `composition_as_set n`. -/\ndef compositionEquiv (n : \u2115) : Composition n \u2243 CompositionAsSet n\n    where\n  toFun c := c.toCompositionAsSet\n  invFun c := c.toComposition\n  left_inv c := by\n    ext1\n    exact c.to_composition_as_set_blocks\n  right_inv c := by\n    ext1\n    exact c.to_composition_boundaries\n#align composition_equiv compositionEquiv\n-/\n\n#print compositionFintype /-\ninstance compositionFintype (n : \u2115) : Fintype (Composition n) :=\n  Fintype.ofEquiv _ (compositionEquiv n).symm\n#align composition_fintype compositionFintype\n-/\n\n#print composition_card /-\ntheorem composition_card (n : \u2115) : Fintype.card (Composition n) = 2 ^ (n - 1) :=\n  by\n  rw [\u2190 compositionAsSet_card n]\n  exact Fintype.card_congr (compositionEquiv n)\n#align composition_card composition_card\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/Composition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7132089432593914}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.set.sups\n! leanprover-community/mathlib commit 20715f4ac6819ef2453d9e5106ecd086a5dc2a5e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.NAry\nimport Mathlib.Order.UpperLower.Basic\n\n/-!\n# Set family operations\n\nThis file defines a few binary operations on `set \u03b1` for use in set family combinatorics.\n\n## Main declarations\n\n* `s \u22bb t`: Set of elements of the form `a \u2294 b` where `a \u2208 s`, `b \u2208 t`.\n* `s \u22bc t`: Set of elements of the form `a \u2293 b` where `a \u2208 s`, `b \u2208 t`.\n\n## Notation\n\nWe define the following notation in locale `set_family`:\n* `s \u22bb t`\n* `s \u22bc t`\n\n## References\n\n[B. Bollob\u00e1s, *Combinatorics*][bollobas1986]\n-/\n\n\nopen Function\n\nvariable {\u03b1 : Type _}\n\n/-- Notation typeclass for pointwise supremum `\u22bb`. -/\nclass HasSups (\u03b1 : Type _) where\n  sups : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n#align has_sups HasSups\n\n/-- Notation typeclass for pointwise infimum `\u22bc`. -/\nclass HasInfs (\u03b1 : Type _) where\n  infs : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n#align has_infs HasInfs\n\n-- mathport name: \u00abexpr \u22bb \u00bb\ninfixl:74\n  \" \u22bb \" => HasSups.sups\n  -- This notation is meant to have higher precedence than `\u2294` and `\u2293`, but still within the\n  -- realm of other binary notation\n\n-- mathport name: \u00abexpr \u22bc \u00bb\ninfixl:75 \" \u22bc \" => HasInfs.infs\n\nnamespace Set\n\nsection Sups\n\nvariable [SemilatticeSup \u03b1] (s s\u2081 s\u2082 t t\u2081 t\u2082 u v : Set \u03b1)\n\n/-- `s \u22bb t` is the set of elements of the form `a \u2294 b` where `a \u2208 s`, `b \u2208 t`. -/\nprotected def hasSups : HasSups (Set \u03b1) :=\n  \u27e8image2 (\u00b7 \u2294 \u00b7)\u27e9\n#align set.has_sups Set.hasSups\n\nscoped[SetFamily] attribute [instance] Set.hasSups\n-- porting note: opening SetFamily, because otherwise the Set.hasSups does not seem to be an\n-- instance\nopen SetFamily\n\nvariable {s s\u2081 s\u2082 t t\u2081 t\u2082 u} {a b c : \u03b1}\n\n@[simp]\ntheorem mem_sups : c \u2208 s \u22bb t \u2194 \u2203 a \u2208 s, \u2203 b \u2208 t, a \u2294 b = c := by simp [(\u00b7 \u22bb \u00b7)]\n#align set.mem_sups Set.mem_sups\n\ntheorem sup_mem_sups : a \u2208 s \u2192 b \u2208 t \u2192 a \u2294 b \u2208 s \u22bb t :=\n  mem_image2_of_mem\n#align set.sup_mem_sups Set.sup_mem_sups\n\ntheorem sups_subset : s\u2081 \u2286 s\u2082 \u2192 t\u2081 \u2286 t\u2082 \u2192 s\u2081 \u22bb t\u2081 \u2286 s\u2082 \u22bb t\u2082 :=\n  image2_subset\n#align set.sups_subset Set.sups_subset\n\ntheorem sups_subset_left : t\u2081 \u2286 t\u2082 \u2192 s \u22bb t\u2081 \u2286 s \u22bb t\u2082 :=\n  image2_subset_left\n#align set.sups_subset_left Set.sups_subset_left\n\ntheorem sups_subset_right : s\u2081 \u2286 s\u2082 \u2192 s\u2081 \u22bb t \u2286 s\u2082 \u22bb t :=\n  image2_subset_right\n#align set.sups_subset_right Set.sups_subset_right\n\ntheorem image_subset_sups_left : b \u2208 t \u2192 (fun a => a \u2294 b) '' s \u2286 s \u22bb t :=\n  image_subset_image2_left\n#align set.image_subset_sups_left Set.image_subset_sups_left\n\ntheorem image_subset_sups_right : a \u2208 s \u2192 (\u00b7 \u2294 \u00b7) a '' t \u2286 s \u22bb t :=\n  image_subset_image2_right\n#align set.image_subset_sups_right Set.image_subset_sups_right\n\ntheorem forall_sups_iff {p : \u03b1 \u2192 Prop} : (\u2200 c \u2208 s \u22bb t, p c) \u2194 \u2200 a \u2208 s, \u2200 b \u2208 t, p (a \u2294 b) :=\n  forall_image2_iff\n#align set.forall_sups_iff Set.forall_sups_iff\n\n@[simp]\ntheorem sups_subset_iff : s \u22bb t \u2286 u \u2194 \u2200 a \u2208 s, \u2200 b \u2208 t, a \u2294 b \u2208 u :=\n  image2_subset_iff\n#align set.sups_subset_iff Set.sups_subset_iff\n\n@[simp]\ntheorem sups_nonempty : (s \u22bb t).Nonempty \u2194 s.Nonempty \u2227 t.Nonempty :=\n  image2_nonempty_iff\n#align set.sups_nonempty Set.sups_nonempty\n\nprotected theorem Nonempty.sups : s.Nonempty \u2192 t.Nonempty \u2192 (s \u22bb t).Nonempty :=\n  Nonempty.image2\n#align set.nonempty.sups Set.Nonempty.sups\n\ntheorem Nonempty.of_sups_left : (s \u22bb t).Nonempty \u2192 s.Nonempty :=\n  Nonempty.of_image2_left\n#align set.nonempty.of_sups_left Set.Nonempty.of_sups_left\n\ntheorem Nonempty.of_sups_right : (s \u22bb t).Nonempty \u2192 t.Nonempty :=\n  Nonempty.of_image2_right\n#align set.nonempty.of_sups_right Set.Nonempty.of_sups_right\n\n@[simp]\ntheorem empty_sups : \u2205 \u22bb t = \u2205 :=\n  image2_empty_left\n#align set.empty_sups Set.empty_sups\n\n@[simp]\ntheorem sups_empty : s \u22bb \u2205 = \u2205 :=\n  image2_empty_right\n#align set.sups_empty Set.sups_empty\n\n@[simp]\ntheorem sups_eq_empty : s \u22bb t = \u2205 \u2194 s = \u2205 \u2228 t = \u2205 :=\n  image2_eq_empty_iff\n#align set.sups_eq_empty Set.sups_eq_empty\n\n@[simp]\ntheorem singleton_sups : {a} \u22bb t = t.image fun b => a \u2294 b :=\n  image2_singleton_left\n#align set.singleton_sups Set.singleton_sups\n\n@[simp]\ntheorem sups_singleton : s \u22bb {b} = s.image fun a => a \u2294 b :=\n  image2_singleton_right\n#align set.sups_singleton Set.sups_singleton\n\ntheorem singleton_sups_singleton : ({a} \u22bb {b} : Set \u03b1) = {a \u2294 b} :=\n  image2_singleton\n#align set.singleton_sups_singleton Set.singleton_sups_singleton\n\ntheorem sups_union_left : (s\u2081 \u222a s\u2082) \u22bb t = s\u2081 \u22bb t \u222a s\u2082 \u22bb t :=\n  image2_union_left\n#align set.sups_union_left Set.sups_union_left\n\ntheorem sups_union_right : s \u22bb (t\u2081 \u222a t\u2082) = s \u22bb t\u2081 \u222a s \u22bb t\u2082 :=\n  image2_union_right\n#align set.sups_union_right Set.sups_union_right\n\ntheorem sups_inter_subset_left : (s\u2081 \u2229 s\u2082) \u22bb t \u2286 s\u2081 \u22bb t \u2229 s\u2082 \u22bb t :=\n  image2_inter_subset_left\n#align set.sups_inter_subset_left Set.sups_inter_subset_left\n\ntheorem sups_inter_subset_right : s \u22bb (t\u2081 \u2229 t\u2082) \u2286 s \u22bb t\u2081 \u2229 s \u22bb t\u2082 :=\n  image2_inter_subset_right\n#align set.sups_inter_subset_right Set.sups_inter_subset_right\n\nvariable (s t u)\n\ntheorem union\u1d62_image_sup_left : (\u22c3 a \u2208 s, (\u00b7 \u2294 \u00b7) a '' t) = s \u22bb t :=\n  union\u1d62_image_left _\n#align set.Union_image_sup_left Set.union\u1d62_image_sup_left\n\ntheorem union\u1d62_image_sup_right : (\u22c3 b \u2208 t, (\u00b7 \u2294 b) '' s) = s \u22bb t :=\n  union\u1d62_image_right _\n#align set.Union_image_sup_right Set.union\u1d62_image_sup_right\n\n@[simp]\ntheorem image_sup_prod (s t : Set \u03b1) : Set.image2 (fun x x_1 => x \u2294 x_1) s t = s \u22bb t := by\n  have : (s \u00d7\u02e2 t).image (uncurry (\u00b7 \u2294 \u00b7)) = Set.image2 (fun x x_1 => x \u2294 x_1) s t := by\n    simp only [ge_iff_le, image_uncurry_prod]\n  rw [\u2190 this]\n  exact image_uncurry_prod _ _ _\n#align set.image_sup_prod Set.image_sup_prod\n\ntheorem sups_assoc : s \u22bb t \u22bb u = s \u22bb (t \u22bb u) :=\n  image2_assoc fun _ _ _ => sup_assoc\n#align set.sups_assoc Set.sups_assoc\n\ntheorem sups_comm : s \u22bb t = t \u22bb s :=\n  image2_comm fun _ _ => sup_comm\n#align set.sups_comm Set.sups_comm\n\ntheorem sups_left_comm : s \u22bb (t \u22bb u) = t \u22bb (s \u22bb u) :=\n  image2_left_comm sup_left_comm\n#align set.sups_left_comm Set.sups_left_comm\n\ntheorem sups_right_comm : s \u22bb t \u22bb u = s \u22bb u \u22bb t :=\n  image2_right_comm sup_right_comm\n#align set.sups_right_comm Set.sups_right_comm\n\ntheorem sups_sups_sups_comm : s \u22bb t \u22bb (u \u22bb v) = s \u22bb u \u22bb (t \u22bb v) :=\n  image2_image2_image2_comm sup_sup_sup_comm\n#align set.sups_sups_sups_comm Set.sups_sups_sups_comm\n\nend Sups\n\nsection Infs\n\nvariable [SemilatticeInf \u03b1] (s s\u2081 s\u2082 t t\u2081 t\u2082 u v : Set \u03b1)\n\n/-- `s \u22bc t` is the set of elements of the form `a \u2293 b` where `a \u2208 s`, `b \u2208 t`. -/\nprotected def hasInfs : HasInfs (Set \u03b1) :=\n  \u27e8image2 (\u00b7 \u2293 \u00b7)\u27e9\n#align set.has_infs Set.hasInfs\n\nscoped[SetFamily] attribute [instance] Set.hasInfs\n-- porting note: opening SetFamily, because otherwise the Set.hasSups does not seem to be an\n-- instance\nopen SetFamily\n\nvariable {s s\u2081 s\u2082 t t\u2081 t\u2082 u} {a b c : \u03b1}\n\n@[simp]\ntheorem mem_infs : c \u2208 s \u22bc t \u2194 \u2203 a \u2208 s, \u2203 b \u2208 t, a \u2293 b = c := by simp [(\u00b7 \u22bc \u00b7)]\n#align set.mem_infs Set.mem_infs\n\ntheorem inf_mem_infs : a \u2208 s \u2192 b \u2208 t \u2192 a \u2293 b \u2208 s \u22bc t :=\n  mem_image2_of_mem\n#align set.inf_mem_infs Set.inf_mem_infs\n\ntheorem infs_subset : s\u2081 \u2286 s\u2082 \u2192 t\u2081 \u2286 t\u2082 \u2192 s\u2081 \u22bc t\u2081 \u2286 s\u2082 \u22bc t\u2082 :=\n  image2_subset\n#align set.infs_subset Set.infs_subset\n\ntheorem infs_subset_left : t\u2081 \u2286 t\u2082 \u2192 s \u22bc t\u2081 \u2286 s \u22bc t\u2082 :=\n  image2_subset_left\n#align set.infs_subset_left Set.infs_subset_left\n\ntheorem infs_subset_right : s\u2081 \u2286 s\u2082 \u2192 s\u2081 \u22bc t \u2286 s\u2082 \u22bc t :=\n  image2_subset_right\n#align set.infs_subset_right Set.infs_subset_right\n\ntheorem image_subset_infs_left : b \u2208 t \u2192 (fun a => a \u2293 b) '' s \u2286 s \u22bc t :=\n  image_subset_image2_left\n#align set.image_subset_infs_left Set.image_subset_infs_left\n\ntheorem image_subset_infs_right : a \u2208 s \u2192 (\u00b7 \u2293 \u00b7) a '' t \u2286 s \u22bc t :=\n  image_subset_image2_right\n#align set.image_subset_infs_right Set.image_subset_infs_right\n\ntheorem forall_infs_iff {p : \u03b1 \u2192 Prop} : (\u2200 c \u2208 s \u22bc t, p c) \u2194 \u2200 a \u2208 s, \u2200 b \u2208 t, p (a \u2293 b) :=\n  forall_image2_iff\n#align set.forall_infs_iff Set.forall_infs_iff\n\n@[simp]\ntheorem infs_subset_iff : s \u22bc t \u2286 u \u2194 \u2200 a \u2208 s, \u2200 b \u2208 t, a \u2293 b \u2208 u :=\n  image2_subset_iff\n#align set.infs_subset_iff Set.infs_subset_iff\n\n@[simp]\ntheorem infs_nonempty : (s \u22bc t).Nonempty \u2194 s.Nonempty \u2227 t.Nonempty :=\n  image2_nonempty_iff\n#align set.infs_nonempty Set.infs_nonempty\n\nprotected theorem Nonempty.infs : s.Nonempty \u2192 t.Nonempty \u2192 (s \u22bc t).Nonempty :=\n  Nonempty.image2\n#align set.nonempty.infs Set.Nonempty.infs\n\ntheorem Nonempty.of_infs_left : (s \u22bc t).Nonempty \u2192 s.Nonempty :=\n  Nonempty.of_image2_left\n#align set.nonempty.of_infs_left Set.Nonempty.of_infs_left\n\ntheorem Nonempty.of_infs_right : (s \u22bc t).Nonempty \u2192 t.Nonempty :=\n  Nonempty.of_image2_right\n#align set.nonempty.of_infs_right Set.Nonempty.of_infs_right\n\n@[simp]\ntheorem empty_infs : \u2205 \u22bc t = \u2205 :=\n  image2_empty_left\n#align set.empty_infs Set.empty_infs\n\n@[simp]\ntheorem infs_empty : s \u22bc \u2205 = \u2205 :=\n  image2_empty_right\n#align set.infs_empty Set.infs_empty\n\n@[simp]\ntheorem infs_eq_empty : s \u22bc t = \u2205 \u2194 s = \u2205 \u2228 t = \u2205 :=\n  image2_eq_empty_iff\n#align set.infs_eq_empty Set.infs_eq_empty\n\n@[simp]\ntheorem singleton_infs : {a} \u22bc t = t.image fun b => a \u2293 b :=\n  image2_singleton_left\n#align set.singleton_infs Set.singleton_infs\n\n@[simp]\ntheorem infs_singleton : s \u22bc {b} = s.image fun a => a \u2293 b :=\n  image2_singleton_right\n#align set.infs_singleton Set.infs_singleton\n\ntheorem singleton_infs_singleton : ({a} \u22bc {b} : Set \u03b1) = {a \u2293 b} :=\n  image2_singleton\n#align set.singleton_infs_singleton Set.singleton_infs_singleton\n\ntheorem infs_union_left : (s\u2081 \u222a s\u2082) \u22bc t = s\u2081 \u22bc t \u222a s\u2082 \u22bc t :=\n  image2_union_left\n#align set.infs_union_left Set.infs_union_left\n\n\n\ntheorem infs_inter_subset_left : (s\u2081 \u2229 s\u2082) \u22bc t \u2286 s\u2081 \u22bc t \u2229 s\u2082 \u22bc t :=\n  image2_inter_subset_left\n#align set.infs_inter_subset_left Set.infs_inter_subset_left\n\ntheorem infs_inter_subset_right : s \u22bc (t\u2081 \u2229 t\u2082) \u2286 s \u22bc t\u2081 \u2229 s \u22bc t\u2082 :=\n  image2_inter_subset_right\n#align set.infs_inter_subset_right Set.infs_inter_subset_right\n\nvariable (s t u)\n\ntheorem union\u1d62_image_inf_left : (\u22c3 a \u2208 s, (\u00b7 \u2293 \u00b7) a '' t) = s \u22bc t :=\n  union\u1d62_image_left _\n#align set.Union_image_inf_left Set.union\u1d62_image_inf_left\n\ntheorem union\u1d62_image_inf_right : (\u22c3 b \u2208 t, (\u00b7 \u2293 b) '' s) = s \u22bc t :=\n  union\u1d62_image_right _\n#align set.Union_image_inf_right Set.union\u1d62_image_inf_right\n\n@[simp]\ntheorem image_inf_prod (s t : Set \u03b1) : Set.image2 (fun x x_1 => x \u2293 x_1) s t = s \u22bc t := by\n  have : (s \u00d7\u02e2 t).image (uncurry (\u00b7 \u2293 \u00b7)) = Set.image2 (fun x x_1 => x \u2293 x_1) s t := by\n    simp only [@ge_iff_le, @Set.image_uncurry_prod]\n  rw [\u2190 this]\n  exact image_uncurry_prod _ _ _\n#align set.image_inf_prod Set.image_inf_prod\n\ntheorem infs_assoc : s \u22bc t \u22bc u = s \u22bc (t \u22bc u) :=\n  image2_assoc fun _ _ _ => inf_assoc\n#align set.infs_assoc Set.infs_assoc\n\ntheorem infs_comm : s \u22bc t = t \u22bc s :=\n  image2_comm fun _ _ => inf_comm\n#align set.infs_comm Set.infs_comm\n\ntheorem infs_left_comm : s \u22bc (t \u22bc u) = t \u22bc (s \u22bc u) :=\n  image2_left_comm inf_left_comm\n#align set.infs_left_comm Set.infs_left_comm\n\ntheorem infs_right_comm : s \u22bc t \u22bc u = s \u22bc u \u22bc t :=\n  image2_right_comm inf_right_comm\n#align set.infs_right_comm Set.infs_right_comm\n\ntheorem infs_infs_infs_comm : s \u22bc t \u22bc (u \u22bc v) = s \u22bc u \u22bc (t \u22bc v) :=\n  image2_image2_image2_comm inf_inf_inf_comm\n#align set.infs_infs_infs_comm Set.infs_infs_infs_comm\n\nend Infs\n\nopen SetFamily\n\nsection DistribLattice\n\nvariable [DistribLattice \u03b1] (s t u : Set \u03b1)\n\ntheorem sups_infs_subset_left : s \u22bb t \u22bc u \u2286 (s \u22bb t) \u22bc (s \u22bb u) :=\n  image2_distrib_subset_left fun _ _ _ => sup_inf_left\n#align set.sups_infs_subset_left Set.sups_infs_subset_left\n\ntheorem sups_infs_subset_right : t \u22bc u \u22bb s \u2286 (t \u22bb s) \u22bc (u \u22bb s) :=\n  image2_distrib_subset_right fun _ _ _ => sup_inf_right\n#align set.sups_infs_subset_right Set.sups_infs_subset_right\n\ntheorem infs_sups_subset_left : s \u22bc (t \u22bb u) \u2286 s \u22bc t \u22bb s \u22bc u :=\n  image2_distrib_subset_left fun _ _ _ => inf_sup_left\n#align set.infs_sups_subset_left Set.infs_sups_subset_left\n\ntheorem infs_sups_subset_right : (t \u22bb u) \u22bc s \u2286 t \u22bc s \u22bb u \u22bc s :=\n  image2_distrib_subset_right fun _ _ _ => inf_sup_right\n#align set.infs_sups_subset_right Set.infs_sups_subset_right\n\nend DistribLattice\n\nend Set\n\nopen SetFamily\n\n@[simp]\ntheorem upperClosure_sups [SemilatticeSup \u03b1] (s t : Set \u03b1) :\n    upperClosure (s \u22bb t) = upperClosure s \u2294 upperClosure t := by\n  ext a\n  simp only [SetLike.mem_coe, mem_upperClosure, Set.mem_sups, exists_and_left, exists_prop,\n    UpperSet.coe_sup, Set.mem_inter_iff]\n  constructor\n  \u00b7 rintro \u27e8_, \u27e8b, hb, c, hc, rfl\u27e9, ha\u27e9\n    exact \u27e8\u27e8b, hb, le_sup_left.trans ha\u27e9, c, hc, le_sup_right.trans ha\u27e9\n  \u00b7 rintro \u27e8\u27e8b, hb, hab\u27e9, c, hc, hac\u27e9\n    exact \u27e8_, \u27e8b, hb, c, hc, rfl\u27e9, sup_le hab hac\u27e9\n#align upper_closure_sups upperClosure_sups\n\n@[simp]\ntheorem lowerClosure_infs [SemilatticeInf \u03b1] (s t : Set \u03b1) :\n    lowerClosure (s \u22bc t) = lowerClosure s \u2293 lowerClosure t := by\n  ext a\n  simp only [SetLike.mem_coe, mem_lowerClosure, Set.mem_infs, exists_and_left, exists_prop,\n    LowerSet.coe_sup, Set.mem_inter_iff]\n  constructor\n  \u00b7 rintro \u27e8_, \u27e8b, hb, c, hc, rfl\u27e9, ha\u27e9\n    exact \u27e8\u27e8b, hb, ha.trans inf_le_left\u27e9, c, hc, ha.trans inf_le_right\u27e9\n  \u00b7 rintro \u27e8\u27e8b, hb, hab\u27e9, c, hc, hac\u27e9\n    exact \u27e8_, \u27e8b, hb, c, hc, rfl\u27e9, le_inf hab hac\u27e9\n#align lower_closure_infs lowerClosure_infs\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Sups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7132089386073456}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module algebra.order.zero_le_one\n! leanprover-community/mathlib commit 07fee0ca54c320250c98bacf31ca5f288b2bcbe2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Basic\nimport Mathlib.Algebra.NeZero\n\n/-!\n# Typeclass expressing `0 \u2264 1`.\n-/\n\nvariable {\u03b1 : Type _}\n\nopen Function\n\n/-- Typeclass for expressing that the `0` of a type is less or equal to its `1`. -/\nclass ZeroLEOneClass (\u03b1 : Type _) [Zero \u03b1] [One \u03b1] [LE \u03b1] where\n  /-- Zero is less than or equal to one. -/\n  zero_le_one : (0 : \u03b1) \u2264 1\n#align zero_le_one_class ZeroLEOneClass\n\n/-- `zero_le_one` with the type argument implicit. -/\n@[simp] lemma zero_le_one [Zero \u03b1] [One \u03b1] [LE \u03b1] [ZeroLEOneClass \u03b1] : (0 : \u03b1) \u2264 1 :=\nZeroLEOneClass.zero_le_one\n#align zero_le_one zero_le_one\n\n/-- `zero_le_one` with the type argument explicit. -/\nlemma zero_le_one' (\u03b1) [Zero \u03b1] [One \u03b1] [LE \u03b1] [ZeroLEOneClass \u03b1] : (0 : \u03b1) \u2264 1 :=\nzero_le_one\n#align zero_le_one' zero_le_one'\n\nsection\nvariable [Zero \u03b1] [One \u03b1] [PartialOrder \u03b1] [ZeroLEOneClass \u03b1] [NeZero (1 : \u03b1)]\n\n/-- See `zero_lt_one'` for a version with the type explicit. -/\n@[simp] lemma zero_lt_one : (0 : \u03b1) < 1 := zero_le_one.lt_of_ne (NeZero.ne' 1)\n#align zero_lt_one zero_lt_one\n\nvariable (\u03b1)\n\n/-- See `zero_lt_one` for a version with the type implicit. -/\nlemma zero_lt_one' : (0 : \u03b1) < 1 := zero_lt_one\n#align zero_lt_one' zero_lt_one'\n\nend\n\nalias zero_lt_one \u2190 one_pos\n#align one_pos one_pos\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/ZeroLEOne.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7132018185929591}}
{"text": "/-\nCopyright (c) 2021 Henry Swanson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henry Swanson\n-/\nimport combinatorics.derangements.basic\nimport data.fintype.card\nimport tactic.delta_instance\nimport tactic.ring\n\n/-!\n# Derangements on fintypes\n\nThis file contains lemmas that describe the cardinality of `derangements \u03b1` when `\u03b1` is a fintype.\n\n# Main definitions\n\n* `card_derangements_invariant`: A lemma stating that the number of derangements on a type `\u03b1`\n    depends only on the cardinality of `\u03b1`.\n* `num_derangements n`: The number of derangements on an n-element set, defined in a computation-\n    friendly way.\n* `card_derangements_eq_num_derangements`: Proof that `num_derangements` really does compute the\n    number of derangements.\n* `num_derangements_sum`: A lemma giving an expression for `num_derangements n` in terms of\n    factorials.\n-/\n\nopen derangements equiv fintype\nopen_locale big_operators\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] [fintype \u03b1]\n\ninstance : decidable_pred (derangements \u03b1) := \u03bb _, fintype.decidable_forall_fintype\n\ninstance : fintype (derangements \u03b1) := by delta_instance derangements\n\nlemma card_derangements_invariant {\u03b1 \u03b2 : Type*} [fintype \u03b1] [decidable_eq \u03b1]\n  [fintype \u03b2] [decidable_eq \u03b2] (h : card \u03b1 = card \u03b2) :\n  card (derangements \u03b1) = card (derangements \u03b2) :=\nfintype.card_congr (equiv.derangements_congr $ equiv_of_card_eq h)\n\nlemma card_derangements_fin_add_two (n : \u2115) :\n  card (derangements (fin (n+2))) = (n+1) * card (derangements (fin n)) +\n  (n+1) * card (derangements (fin (n+1))) :=\nbegin\n  -- get some basic results about the size of fin (n+1) plus or minus an element\n  have h1 : \u2200 a : fin (n+1), card ({a}\u1d9c : set (fin (n+1))) = card (fin n),\n  { intro a,\n    simp only [fintype.card_fin, finset.card_fin, fintype.card_of_finset, finset.filter_ne' _ a,\n      set.mem_compl_singleton_iff, finset.card_erase_of_mem (finset.mem_univ a),\n      add_tsub_cancel_right] },\n  have h2 : card (fin (n+2)) = card (option (fin (n+1))),\n  { simp only [card_fin, card_option] },\n  -- rewrite the LHS and substitute in our fintype-level equivalence\n  simp only [card_derangements_invariant h2,\n    card_congr (@derangements_recursion_equiv (fin (n+1)) _),\n  -- push the cardinality through the \u03a3 and \u2295 so that we can use `card_n`\n    card_sigma, card_sum, card_derangements_invariant (h1 _), finset.sum_const, nsmul_eq_mul,\n    finset.card_fin, mul_add, nat.cast_id],\nend\n\n/-- The number of derangements of an `n`-element set. -/\ndef num_derangements : \u2115 \u2192 \u2115\n| 0 := 1\n| 1 := 0\n| (n + 2) := (n + 1) * (num_derangements n + num_derangements (n+1))\n\n@[simp] lemma num_derangements_zero : num_derangements 0 = 1 := rfl\n\n@[simp] lemma num_derangements_one : num_derangements 1 = 0 := rfl\n\nlemma num_derangements_add_two (n : \u2115) :\n  num_derangements (n+2) = (n+1) * (num_derangements n + num_derangements (n+1)) := rfl\n\nlemma num_derangements_succ (n : \u2115) :\n  (num_derangements (n+1) : \u2124) = (n + 1) * (num_derangements n : \u2124) - (-1)^n :=\nbegin\n  induction n with n hn,\n  { refl },\n  { simp only [num_derangements_add_two, hn, pow_succ,\n      int.coe_nat_mul, int.coe_nat_add, int.coe_nat_succ],\n    ring }\nend\n\nlemma card_derangements_fin_eq_num_derangements {n : \u2115} :\n  card (derangements (fin n)) = num_derangements n :=\nbegin\n  induction n using nat.strong_induction_on with n hyp,\n  obtain (_|_|n) := n, { refl }, { refl },  -- knock out cases 0 and 1\n  -- now we have n \u2265 2. rewrite everything in terms of card_derangements, so that we can use\n  -- `card_derangements_fin_add_two`\n  rw [num_derangements_add_two, card_derangements_fin_add_two, mul_add,\n    hyp _ (nat.lt_add_of_pos_right zero_lt_two), hyp _ (lt_add_one _)],\nend\n\nlemma card_derangements_eq_num_derangements (\u03b1 : Type*) [fintype \u03b1] [decidable_eq \u03b1] :\n  card (derangements \u03b1) = num_derangements (card \u03b1) :=\nbegin\n  rw \u2190card_derangements_invariant (card_fin _),\n  exact card_derangements_fin_eq_num_derangements,\nend\n\ntheorem num_derangements_sum (n : \u2115) :\n  (num_derangements n : \u2124) = \u2211 k in finset.range (n + 1), (-1:\u2124)^k * nat.asc_factorial k (n - k) :=\nbegin\n  induction n with n hn, { refl },\n  rw [finset.sum_range_succ, num_derangements_succ, hn, finset.mul_sum, tsub_self,\n    nat.asc_factorial_zero, int.coe_nat_one, mul_one, pow_succ, neg_one_mul, sub_eq_add_neg,\n    add_left_inj, finset.sum_congr rfl],\n  -- show that (n + 1) * (-1)^x * asc_fac x (n - x) = (-1)^x * asc_fac x (n.succ - x)\n  intros x hx,\n  have h_le : x \u2264 n := finset.mem_range_succ_iff.mp hx,\n  rw [nat.succ_sub h_le, nat.asc_factorial_succ, add_tsub_cancel_of_le h_le,\n    int.coe_nat_mul, int.coe_nat_succ, mul_left_comm],\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/combinatorics/derangements/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7132018132789127}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Kevin Kappelmann\n-/\nimport tactic.abel\nimport tactic.linarith\n\n/-!\n# Floor and ceil\n\n## Summary\n\nWe define the natural- and integer-valued floor and ceil functions on linearly ordered rings.\n\n## Main Definitions\n\n* `floor_semiring`: An ordered semiring with natural-valued floor and ceil.\n* `nat.floor a`: Greatest natural `n` such that `n \u2264 a`. Equal to `0` if `a < 0`.\n* `nat.ceil a`: Least natural `n` such that `a \u2264 n`.\n\n* `floor_ring`: A linearly ordered ring with integer-valued floor and ceil.\n* `int.floor a`: Greatest integer `z` such that `z \u2264 a`.\n* `int.ceil a`: Least integer `z` such that `a \u2264 z`.\n* `int.fract a`: Fractional part of `a`, defined as `a - floor a`.\n\n## Notations\n\n* `\u230aa\u230b\u208a` is `nat.floor a`.\n* `\u2308a\u2309\u208a` is `nat.ceil a`.\n* `\u230aa\u230b` is `int.floor a`.\n* `\u2308a\u2309` is `int.ceil a`.\n\nThe index `\u208a` in the notations for `nat.floor` and `nat.ceil` is used in analogy to the notation\nfor `nnnorm`.\n\n## TODO\n\nSome `nat.floor` and `nat.ceil` lemmas require `linear_ordered_ring \u03b1`. Is `has_ordered_sub` enough?\n\n`linear_ordered_ring`/`linear_ordered_semiring` can be relaxed to `order_ring`/`order_semiring` in\nmany lemmas.\n\n## Tags\n\nrounding, floor, ceil\n-/\n\nopen set\nvariables {\u03b1 : Type*}\n\n/-! ### Floor semiring -/\n\n/-- A `floor_semiring` is an ordered semiring over `\u03b1` with a function\n`floor : \u03b1 \u2192 \u2115` satisfying `\u2200 (n : \u2115) (x : \u03b1), n \u2264 \u230ax\u230b \u2194 (n : \u03b1) \u2264 x)`.\nNote that many lemmas require a `linear_order`. Please see the above `TODO`. -/\nclass floor_semiring (\u03b1) [ordered_semiring \u03b1] :=\n(floor : \u03b1 \u2192 \u2115)\n(ceil : \u03b1 \u2192 \u2115)\n(floor_of_neg {a : \u03b1} (ha : a < 0) : floor a = 0)\n(gc_floor {a : \u03b1} {n : \u2115} (ha : 0 \u2264 a) : n \u2264 floor a \u2194 (n : \u03b1) \u2264 a)\n(gc_ceil : galois_connection ceil coe)\n\ninstance : floor_semiring \u2115 :=\n{ floor := id,\n  ceil := id,\n  floor_of_neg := \u03bb a ha, (a.not_lt_zero ha).elim,\n  gc_floor := \u03bb n a ha, by { rw nat.cast_id, refl },\n  gc_ceil := \u03bb n a, by { rw nat.cast_id, refl } }\n\nnamespace nat\n\nsection ordered_semiring\nvariables [ordered_semiring \u03b1] [floor_semiring \u03b1] {a : \u03b1} {n : \u2115}\n\n/-- `\u230aa\u230b\u208a` is the greatest natural `n` such that `n \u2264 a`. If `a` is negative, then `\u230aa\u230b\u208a = 0`. -/\ndef floor : \u03b1 \u2192 \u2115 := floor_semiring.floor\n\n/-- `\u2308a\u2309\u208a` is the least natural `n` such that `a \u2264 n` -/\ndef ceil : \u03b1 \u2192 \u2115 := floor_semiring.ceil\n\nnotation `\u230a` a `\u230b\u208a` := nat.floor a\nnotation `\u2308` a `\u2309\u208a` := nat.ceil a\n\nend ordered_semiring\n\nsection linear_ordered_semiring\nvariables [linear_ordered_semiring \u03b1] [floor_semiring \u03b1] {a : \u03b1} {n : \u2115}\n\nlemma le_floor_iff (ha : 0 \u2264 a) : n \u2264 \u230aa\u230b\u208a \u2194 (n : \u03b1) \u2264 a := floor_semiring.gc_floor ha\n\nlemma le_floor (h : (n : \u03b1) \u2264 a) : n \u2264 \u230aa\u230b\u208a := (le_floor_iff $ n.cast_nonneg.trans h).2 h\n\nlemma floor_lt (ha : 0 \u2264 a) : \u230aa\u230b\u208a < n \u2194 a < n := lt_iff_lt_of_le_iff_le $ le_floor_iff ha\n\nlemma lt_of_floor_lt (h : \u230aa\u230b\u208a < n) : a < n := lt_of_not_ge' $ \u03bb h', (le_floor h').not_lt h\n\nlemma floor_le (ha : 0 \u2264 a) : (\u230aa\u230b\u208a : \u03b1) \u2264 a := (le_floor_iff ha).1 le_rfl\n\nlemma lt_succ_floor (a : \u03b1) : a < \u230aa\u230b\u208a.succ := lt_of_floor_lt $ nat.lt_succ_self _\n\nlemma lt_floor_add_one (a : \u03b1) : a < \u230aa\u230b\u208a + 1 := lt_succ_floor a\n\n@[simp] lemma floor_coe (n : \u2115) : \u230a(n : \u03b1)\u230b\u208a = n :=\neq_of_forall_le_iff $ \u03bb a, by { rw [le_floor_iff, nat.cast_le], exact n.cast_nonneg }\n\n@[simp] lemma floor_zero : \u230a(0 : \u03b1)\u230b\u208a = 0 := floor_coe 0\n\n@[simp] lemma floor_one : \u230a(1 : \u03b1)\u230b\u208a = 1 := by rw [\u2190nat.cast_one, floor_coe]\n\nlemma floor_of_nonpos (ha : a \u2264 0) : \u230aa\u230b\u208a = 0 :=\nha.lt_or_eq.elim floor_semiring.floor_of_neg $ by { rintro rfl, exact floor_zero }\n\nlemma floor_mono : monotone (floor : \u03b1 \u2192 \u2115) := \u03bb a b h, begin\n  obtain ha | ha := le_total a 0,\n  { rw floor_of_nonpos ha,\n    exact nat.zero_le _ },\n  { exact le_floor ((floor_le ha).trans h) }\nend\n\nlemma le_floor_iff' (hn : n \u2260 0) : n \u2264 \u230aa\u230b\u208a \u2194 (n : \u03b1) \u2264 a :=\nbegin\n  obtain ha | ha := le_total a 0,\n  { rw floor_of_nonpos ha,\n    exact iff_of_false (nat.pos_of_ne_zero hn).not_le\n      (not_le_of_lt $ ha.trans_lt $ cast_pos.2 $ nat.pos_of_ne_zero hn) },\n  { exact le_floor_iff ha }\nend\n\nlemma floor_lt' (hn : n \u2260 0) : \u230aa\u230b\u208a < n \u2194 a < n := lt_iff_lt_of_le_iff_le $ le_floor_iff' hn\n\nlemma floor_pos : 0 < \u230aa\u230b\u208a \u2194 1 \u2264 a :=\nby { convert le_floor_iff' nat.one_ne_zero, exact cast_one.symm }\n\nlemma pos_of_floor_pos (h : 0 < \u230aa\u230b\u208a) : 0 < a :=\n(le_or_lt a 0).resolve_left (\u03bb ha, lt_irrefl 0 $ by rwa floor_of_nonpos ha at h)\n\nlemma lt_of_lt_floor (h : n < \u230aa\u230b\u208a) : \u2191n < a :=\n(nat.cast_lt.2 h).trans_le $ floor_le (pos_of_floor_pos $ (nat.zero_le n).trans_lt h).le\n\nlemma floor_le_of_le (h : a \u2264 n) : \u230aa\u230b\u208a \u2264 n := le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h\n\n@[simp] lemma floor_eq_zero : \u230aa\u230b\u208a = 0 \u2194 a < 1 :=\nby { rw [\u2190lt_one_iff, \u2190@cast_one \u03b1], exact floor_lt' nat.one_ne_zero }\n\nlemma floor_eq_iff (ha : 0 \u2264 a) : \u230aa\u230b\u208a = n \u2194 \u2191n \u2264 a \u2227 a < \u2191n + 1 :=\nby rw [\u2190le_floor_iff ha, \u2190nat.cast_one, \u2190nat.cast_add, \u2190floor_lt ha, nat.lt_add_one_iff,\n  le_antisymm_iff, and.comm]\n\nlemma floor_eq_iff' (hn : n \u2260 0) : \u230aa\u230b\u208a = n \u2194 \u2191n \u2264 a \u2227 a < \u2191n + 1 :=\nby rw [\u2190 le_floor_iff' hn, \u2190 nat.cast_one, \u2190 nat.cast_add, \u2190 floor_lt' (nat.add_one_ne_zero n),\n  nat.lt_add_one_iff, le_antisymm_iff, and.comm]\n\nlemma floor_eq_on_Ico (n : \u2115) : \u2200 a \u2208 (set.Ico n (n+1) : set \u03b1), \u230aa\u230b\u208a = n :=\n\u03bb a \u27e8h\u2080, h\u2081\u27e9, (floor_eq_iff $ n.cast_nonneg.trans h\u2080).mpr \u27e8h\u2080, h\u2081\u27e9\n\n\n\n@[simp] lemma preimage_floor_zero : (floor : \u03b1 \u2192 \u2115) \u207b\u00b9' {0} = Iio 1 :=\next $ \u03bb a, floor_eq_zero\n\nlemma preimage_floor_of_ne_zero {n : \u2115} (hn : n \u2260 0) : (floor : \u03b1 \u2192 \u2115) \u207b\u00b9' {n} = Ico n (n + 1) :=\next $ \u03bb a, floor_eq_iff' hn\n\n/-! #### Ceil -/\n\nlemma gc_ceil_coe : galois_connection (ceil : \u03b1 \u2192 \u2115) coe := floor_semiring.gc_ceil\n\n@[simp] lemma ceil_le : \u2308a\u2309\u208a \u2264 n \u2194 a \u2264 n := gc_ceil_coe _ _\n\nlemma lt_ceil : n < \u2308a\u2309\u208a \u2194 (n : \u03b1) < a := lt_iff_lt_of_le_iff_le ceil_le\n\nlemma le_ceil (a : \u03b1) : a \u2264 \u2308a\u2309\u208a := ceil_le.1 le_rfl\n\nlemma ceil_mono : monotone (ceil : \u03b1 \u2192 \u2115) := gc_ceil_coe.monotone_l\n\n@[simp] lemma ceil_coe (n : \u2115) : \u2308(n : \u03b1)\u2309\u208a = n :=\neq_of_forall_ge_iff $ \u03bb a, ceil_le.trans nat.cast_le\n\n@[simp] lemma ceil_zero : \u2308(0 : \u03b1)\u2309\u208a = 0 := ceil_coe 0\n\n@[simp] lemma ceil_eq_zero : \u2308a\u2309\u208a = 0 \u2194 a \u2264 0 := le_zero_iff.symm.trans ceil_le\n\nlemma lt_of_ceil_lt (h : \u2308a\u2309\u208a < n) : a < n := (le_ceil a).trans_lt (nat.cast_lt.2 h)\n\nlemma le_of_ceil_le (h : \u2308a\u2309\u208a \u2264 n) : a \u2264 n := (le_ceil a).trans (nat.cast_le.2 h)\n\nlemma floor_le_ceil (a : \u03b1) : \u230aa\u230b\u208a \u2264 \u2308a\u2309\u208a :=\nbegin\n  obtain ha | ha := le_total a 0,\n  { rw floor_of_nonpos ha,\n    exact nat.zero_le _ },\n  { exact cast_le.1 ((floor_le ha).trans $ le_ceil _) }\nend\n\nlemma floor_lt_ceil_of_lt_of_pos {a b : \u03b1} (h : a < b) (h' : 0 < b) : \u230aa\u230b\u208a < \u2308b\u2309\u208a :=\nbegin\n  rcases le_or_lt 0 a with ha|ha,\n  { rw floor_lt ha, exact h.trans_le (le_ceil _) },\n  { rwa [floor_of_nonpos ha.le, lt_ceil] }\nend\n\nlemma ceil_eq_iff (hn : n \u2260 0) : \u2308a\u2309\u208a = n \u2194 \u2191(n - 1) < a \u2227 a \u2264 n :=\nby rw [\u2190 ceil_le, \u2190 not_le, \u2190 ceil_le, not_le,\n  tsub_lt_iff_right (nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), nat.lt_add_one_iff,\n  le_antisymm_iff, and.comm]\n\n@[simp] lemma preimage_ceil_zero : (nat.ceil : \u03b1 \u2192 \u2115) \u207b\u00b9' {0} = Iic 0 :=\next $ \u03bb x, ceil_eq_zero\n\nlemma preimage_ceil_of_ne_zero (hn : n \u2260 0) : (nat.ceil : \u03b1 \u2192 \u2115) \u207b\u00b9' {n} = Ioc \u2191(n - 1) n :=\next $ \u03bb x, ceil_eq_iff hn\n\n/-! #### Intervals -/\n\n@[simp] lemma preimage_Ioo {a b : \u03b1} (ha : 0 \u2264 a) :\n  ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Ioo a b)) = set.Ioo \u230aa\u230b\u208a \u2308b\u2309\u208a :=\nby { ext, simp [floor_lt, lt_ceil, ha] }\n\n@[simp] lemma preimage_Ico {a b : \u03b1} : ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Ico a b)) = set.Ico \u2308a\u2309\u208a \u2308b\u2309\u208a :=\nby { ext, simp [ceil_le, lt_ceil] }\n\n@[simp] lemma preimage_Ioc {a b : \u03b1} (ha : 0 \u2264 a) (hb : 0 \u2264 b) :\n  ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Ioc a b)) = set.Ioc \u230aa\u230b\u208a \u230ab\u230b\u208a :=\nby { ext, simp [floor_lt, le_floor_iff, hb, ha] }\n\n@[simp] lemma preimage_Icc {a b : \u03b1} (hb : 0 \u2264 b) :\n  ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Icc a b)) = set.Icc \u2308a\u2309\u208a \u230ab\u230b\u208a :=\nby { ext, simp [ceil_le, hb, le_floor_iff] }\n\n@[simp] lemma preimage_Ioi {a : \u03b1} (ha : 0 \u2264 a) : ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Ioi a)) = set.Ioi \u230aa\u230b\u208a :=\nby { ext, simp [floor_lt, ha] }\n\n@[simp] lemma preimage_Ici {a : \u03b1} : ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Ici a)) = set.Ici \u2308a\u2309\u208a :=\nby { ext, simp [ceil_le] }\n\n@[simp] lemma preimage_Iio {a : \u03b1} : ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Iio a)) = set.Iio \u2308a\u2309\u208a :=\nby { ext, simp [lt_ceil] }\n\n@[simp] lemma preimage_Iic {a : \u03b1} (ha : 0 \u2264 a) : ((coe : \u2115 \u2192 \u03b1) \u207b\u00b9' (set.Iic a)) = set.Iic \u230aa\u230b\u208a :=\nby { ext, simp [le_floor_iff, ha] }\n\nend linear_ordered_semiring\n\nsection linear_ordered_ring\nvariables [linear_ordered_ring \u03b1] [floor_semiring \u03b1] {a : \u03b1} {n : \u2115}\n\nlemma floor_add_nat (ha : 0 \u2264 a) (n : \u2115) : \u230aa + n\u230b\u208a = \u230aa\u230b\u208a + n :=\neq_of_forall_le_iff $ \u03bb b, begin\n  rw [le_floor_iff (add_nonneg ha n.cast_nonneg), \u2190sub_le_iff_le_add],\n  obtain hb | hb := le_total n b,\n  { rw [\u2190cast_sub hb, \u2190tsub_le_iff_right],\n    exact (le_floor_iff ha).symm },\n  { exact iff_of_true ((sub_nonpos_of_le $ cast_le.2 hb).trans ha) (le_add_left hb) }\nend\n\nlemma floor_add_one (ha : 0 \u2264 a) : \u230aa + 1\u230b\u208a = \u230aa\u230b\u208a + 1 :=\nby { convert floor_add_nat ha 1, exact cast_one.symm }\n\nlemma floor_sub_nat (a : \u03b1) (n : \u2115) : \u230aa - n\u230b\u208a = \u230aa\u230b\u208a - n :=\nbegin\n  obtain ha | ha := le_total a 0,\n  { rw [floor_of_nonpos ha, floor_of_nonpos (sub_nonpos_of_le (ha.trans n.cast_nonneg)),\n      zero_tsub] },\n  cases le_total a n,\n  { rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le],\n    exact nat.cast_le.1 ((nat.floor_le ha).trans h) },\n  { rw [eq_tsub_iff_add_eq_of_le (le_floor h), \u2190floor_add_nat (sub_nonneg_of_le h),\n      sub_add_cancel] }\nend\n\nlemma sub_one_lt_floor (a : \u03b1) : a - 1 < \u230aa\u230b\u208a := sub_lt_iff_lt_add.2 $ lt_floor_add_one a\n\nlemma ceil_add_nat (ha : 0 \u2264 a) (n : \u2115) : \u2308a + n\u2309\u208a = \u2308a\u2309\u208a + n :=\neq_of_forall_ge_iff $ \u03bb b, begin\n  rw [\u2190not_lt, \u2190not_lt, not_iff_not],\n  rw [lt_ceil],\n  obtain hb | hb := le_or_lt n b,\n  { rw [\u2190tsub_lt_iff_right hb, \u2190sub_lt_iff_lt_add, \u2190cast_sub hb],\n    exact lt_ceil.symm },\n  { exact iff_of_true (lt_add_of_nonneg_of_lt ha $ cast_lt.2 hb) (lt_add_left _ _ _ hb) }\nend\n\nlemma ceil_add_one (ha : 0 \u2264 a) : \u2308a + 1\u2309\u208a = \u2308a\u2309\u208a + 1 :=\nby { convert ceil_add_nat ha 1, exact cast_one.symm }\n\nlemma ceil_lt_add_one (ha : 0 \u2264 a) : (\u2308a\u2309\u208a : \u03b1) < a + 1 :=\nlt_ceil.1 $ (nat.lt_succ_self _).trans_le (ceil_add_one ha).ge\n\nend linear_ordered_ring\n\nsection linear_ordered_field\nvariables [linear_ordered_field \u03b1] [floor_semiring \u03b1]\n\nlemma floor_div_nat (a : \u03b1) (n : \u2115) : \u230aa / n\u230b\u208a = \u230aa\u230b\u208a / n :=\nbegin\n  cases le_total a 0 with ha ha,\n  { rw [floor_of_nonpos, floor_of_nonpos ha],\n    { simp },\n    apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg },\n  obtain rfl | hn := n.eq_zero_or_pos,\n  { rw [cast_zero, div_zero, nat.div_zero, floor_zero] },\n  refine (floor_eq_iff _).2 _,\n  { exact div_nonneg ha n.cast_nonneg },\n  split,\n  { exact cast_div_le.trans (div_le_div_of_le_of_nonneg (floor_le ha) n.cast_nonneg) },\n  rw [div_lt_iff, add_mul, one_mul, \u2190cast_mul, \u2190cast_add, \u2190floor_lt ha],\n  { exact lt_div_mul_add hn },\n  { exact (cast_pos.2 hn) }\nend\n\n/-- Natural division is the floor of field division. -/\nlemma floor_div_eq_div (m n : \u2115) : \u230a(m : \u03b1) / n\u230b\u208a = m / n :=\nby { convert floor_div_nat (m : \u03b1) n, rw m.floor_coe }\n\nend linear_ordered_field\n\nend nat\n\n/-- There exists at most one `floor_semiring` structure on a linear ordered semiring. -/\nlemma subsingleton_floor_semiring {\u03b1} [linear_ordered_semiring \u03b1] :\n  subsingleton (floor_semiring \u03b1) :=\nbegin\n  refine \u27e8\u03bb H\u2081 H\u2082, _\u27e9,\n  have : H\u2081.ceil = H\u2082.ceil,\n    from funext (\u03bb a, H\u2081.gc_ceil.l_unique H\u2082.gc_ceil $ \u03bb n, rfl),\n  have : H\u2081.floor = H\u2082.floor,\n  { ext a,\n    cases lt_or_le a 0,\n    { rw [H\u2081.floor_of_neg, H\u2082.floor_of_neg]; exact h },\n    { refine eq_of_forall_le_iff (\u03bb n, _),\n      rw [H\u2081.gc_floor, H\u2082.gc_floor]; exact h } },\n  cases H\u2081, cases H\u2082, congr; assumption\nend\n\n/-! ### Floor rings -/\n\n/--\nA `floor_ring` is a linear ordered ring over `\u03b1` with a function\n`floor : \u03b1 \u2192 \u2124` satisfying `\u2200 (z : \u2124) (a : \u03b1), z \u2264 floor a \u2194 (z : \u03b1) \u2264 a)`.\n-/\nclass floor_ring (\u03b1) [linear_ordered_ring \u03b1] :=\n(floor : \u03b1 \u2192 \u2124)\n(ceil : \u03b1 \u2192 \u2124)\n(gc_coe_floor : galois_connection coe floor)\n(gc_ceil_coe : galois_connection ceil coe)\n\ninstance : floor_ring \u2124 :=\n{ floor := id,\n  ceil := id,\n  gc_coe_floor := \u03bb a b, by { rw int.cast_id, refl },\n  gc_ceil_coe := \u03bb a b, by { rw int.cast_id, refl } }\n\n/-- A `floor_ring` constructor from the `floor` function alone. -/\ndef floor_ring.of_floor (\u03b1) [linear_ordered_ring \u03b1] (floor : \u03b1 \u2192 \u2124)\n  (gc_coe_floor : galois_connection coe floor) : floor_ring \u03b1 :=\n{ floor := floor,\n  ceil := \u03bb a, -floor (-a),\n  gc_coe_floor := gc_coe_floor,\n  gc_ceil_coe := \u03bb a z, by rw [neg_le, \u2190gc_coe_floor, int.cast_neg, neg_le_neg_iff] }\n\n/-- A `floor_ring` constructor from the `ceil` function alone. -/\ndef floor_ring.of_ceil (\u03b1) [linear_ordered_ring \u03b1] (ceil : \u03b1 \u2192 \u2124)\n  (gc_ceil_coe : galois_connection ceil coe) : floor_ring \u03b1 :=\n{ floor := \u03bb a, -ceil (-a),\n  ceil := ceil,\n  gc_coe_floor := \u03bb a z, by rw [le_neg, gc_ceil_coe, int.cast_neg, neg_le_neg_iff],\n  gc_ceil_coe := gc_ceil_coe }\n\nnamespace int\nvariables [linear_ordered_ring \u03b1] [floor_ring \u03b1] {z : \u2124} {a : \u03b1}\n\n/-- `int.floor a` is the greatest integer `z` such that `z \u2264 a`. It is denoted with `\u230aa\u230b`. -/\ndef floor : \u03b1 \u2192 \u2124 := floor_ring.floor\n\n/-- `int.ceil a` is the smallest integer `z` such that `a \u2264 z`. It is denoted with `\u2308a\u2309`. -/\ndef ceil : \u03b1 \u2192 \u2124 := floor_ring.ceil\n\n/-- `int.fract a`, the fractional part of `a`, is `a` minus its floor. -/\ndef fract (a : \u03b1) : \u03b1 := a - floor a\n\nnotation `\u230a` a `\u230b` := int.floor a\nnotation `\u2308` a `\u2309` := int.ceil a\n-- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there.\n\n@[simp] lemma floor_ring_floor_eq : @floor_ring.floor = @int.floor := rfl\n\n@[simp] lemma floor_ring_ceil_eq : @floor_ring.ceil = @int.ceil := rfl\n\n/-! #### Floor -/\n\nlemma gc_coe_floor : galois_connection (coe : \u2124 \u2192 \u03b1) floor := floor_ring.gc_coe_floor\n\nlemma le_floor : z \u2264 \u230aa\u230b \u2194 (z : \u03b1) \u2264 a := (gc_coe_floor z a).symm\n\nlemma floor_lt : \u230aa\u230b < z \u2194 a < z := lt_iff_lt_of_le_iff_le le_floor\n\nlemma floor_le (a : \u03b1) : (\u230aa\u230b : \u03b1) \u2264 a := gc_coe_floor.l_u_le a\n\nlemma floor_nonneg : 0 \u2264 \u230aa\u230b \u2194 0 \u2264 a := le_floor\n\nlemma floor_nonpos (ha : a \u2264 0) : \u230aa\u230b \u2264 0 :=\nbegin\n  rw \u2190@cast_le \u03b1,\n  exact (floor_le a).trans ha,\nend\n\nlemma lt_succ_floor (a : \u03b1) : a < \u230aa\u230b.succ := floor_lt.1 $ int.lt_succ_self _\n\nlemma lt_floor_add_one (a : \u03b1) : a < \u230aa\u230b + 1 :=\nby simpa only [int.succ, int.cast_add, int.cast_one] using lt_succ_floor a\n\nlemma sub_one_lt_floor (a : \u03b1) : a - 1 < \u230aa\u230b := sub_lt_iff_lt_add.2 (lt_floor_add_one a)\n\n@[simp] lemma floor_coe (z : \u2124) : \u230a(z : \u03b1)\u230b = z :=\neq_of_forall_le_iff $ \u03bb a, by rw [le_floor, int.cast_le]\n\n@[simp] lemma floor_zero : \u230a(0 : \u03b1)\u230b = 0 := floor_coe 0\n\n@[simp] lemma floor_one : \u230a(1 : \u03b1)\u230b = 1 := by rw [\u2190 int.cast_one, floor_coe]\n\n@[mono] lemma floor_mono : monotone (floor : \u03b1 \u2192 \u2124) := gc_coe_floor.monotone_u\n\nlemma floor_pos : 0 < \u230aa\u230b \u2194 1 \u2264 a :=\nby { convert le_floor, exact cast_one.symm }\n\n@[simp] lemma floor_add_int (a : \u03b1) (z : \u2124) : \u230aa + z\u230b = \u230aa\u230b + z :=\neq_of_forall_le_iff $ \u03bb a, by rw [le_floor,\n  \u2190 sub_le_iff_le_add, \u2190 sub_le_iff_le_add, le_floor, int.cast_sub]\n\nlemma floor_add_one (a : \u03b1) : \u230aa + 1\u230b = \u230aa\u230b + 1 :=\nby { convert floor_add_int a 1, exact cast_one.symm }\n\n@[simp] lemma floor_int_add (z : \u2124) (a : \u03b1) : \u230a\u2191z + a\u230b = z + \u230aa\u230b :=\nby simpa only [add_comm] using floor_add_int a z\n\n@[simp] lemma floor_add_nat (a : \u03b1) (n : \u2115) : \u230aa + n\u230b = \u230aa\u230b + n := floor_add_int a n\n\n@[simp] lemma floor_nat_add (n : \u2115) (a : \u03b1) : \u230a\u2191n + a\u230b = n + \u230aa\u230b := floor_int_add n a\n\n@[simp] lemma floor_sub_int (a : \u03b1) (z : \u2124) : \u230aa - z\u230b = \u230aa\u230b - z :=\neq.trans (by rw [int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _)\n\n@[simp] lemma floor_sub_nat (a : \u03b1) (n : \u2115) : \u230aa - n\u230b = \u230aa\u230b - n := floor_sub_int a n\n\nlemma abs_sub_lt_one_of_floor_eq_floor {\u03b1 : Type*} [linear_ordered_comm_ring \u03b1] [floor_ring \u03b1]\n  {a b : \u03b1} (h : \u230aa\u230b = \u230ab\u230b) : |a - b| < 1 :=\nbegin\n  have : a < \u230aa\u230b + 1     := lt_floor_add_one a,\n  have : b < \u230ab\u230b + 1     := lt_floor_add_one b,\n  have : (\u230aa\u230b : \u03b1) = \u230ab\u230b := int.cast_inj.2 h,\n  have : (\u230aa\u230b : \u03b1) \u2264 a   := floor_le a,\n  have : (\u230ab\u230b : \u03b1) \u2264 b   := floor_le b,\n  exact abs_sub_lt_iff.2 \u27e8by linarith, by linarith\u27e9\nend\n\nlemma floor_eq_iff : \u230aa\u230b = z \u2194 \u2191z \u2264 a \u2227 a < z + 1 :=\nby rw [le_antisymm_iff, le_floor, \u2190int.lt_add_one_iff, floor_lt, int.cast_add, int.cast_one,\n  and.comm]\n\nlemma floor_eq_on_Ico (n : \u2124) : \u2200 a \u2208 set.Ico (n : \u03b1) (n + 1), \u230aa\u230b = n :=\n\u03bb a \u27e8h\u2080, h\u2081\u27e9, floor_eq_iff.mpr \u27e8h\u2080, h\u2081\u27e9\n\nlemma floor_eq_on_Ico' (n : \u2124) : \u2200 a \u2208 set.Ico (n : \u03b1) (n + 1), (\u230aa\u230b : \u03b1) = n :=\n\u03bb a ha, congr_arg _ $ floor_eq_on_Ico n a ha\n\n@[simp] lemma preimage_floor_singleton (m : \u2124) : (floor : \u03b1 \u2192 \u2124) \u207b\u00b9' {m} = Ico m (m + 1) :=\next $ \u03bb x, floor_eq_iff\n\n/-! #### Fractional part -/\n\n@[simp] lemma self_sub_floor (a : \u03b1) : a - \u230aa\u230b = fract a := rfl\n\n@[simp] lemma floor_add_fract (a : \u03b1) : (\u230aa\u230b : \u03b1) + fract a = a := add_sub_cancel'_right _ _\n\n@[simp] lemma fract_add_floor (a : \u03b1) : fract a + \u230aa\u230b = a := sub_add_cancel _ _\n\n@[simp] lemma fract_add_int (a : \u03b1) (m : \u2124) : fract (a + m) = fract a :=\nby { rw fract, simp }\n\n@[simp] lemma fract_sub_int (a : \u03b1) (m : \u2124) : fract (a - m) = fract a :=\nby { rw fract, simp }\n\n@[simp] lemma fract_int_add (m : \u2124) (a : \u03b1) : fract (\u2191m + a) = fract a :=\nby rw [add_comm, fract_add_int]\n\n@[simp] lemma self_sub_fract (a : \u03b1) : a - fract a = \u230aa\u230b := sub_sub_cancel _ _\n\n@[simp] lemma fract_sub_self (a : \u03b1) : fract a - a = -\u230aa\u230b := sub_sub_cancel_left _ _\n\nlemma fract_nonneg (a : \u03b1) : 0 \u2264 fract a := sub_nonneg.2 $ floor_le _\n\nlemma fract_lt_one (a : \u03b1) : fract a < 1 := sub_lt.1 $ sub_one_lt_floor _\n\n@[simp] lemma fract_zero : fract (0 : \u03b1) = 0 := by rw [fract, floor_zero, cast_zero, sub_self]\n\n@[simp] lemma fract_coe (z : \u2124) : fract (z : \u03b1) = 0 :=\nby { unfold fract, rw floor_coe, exact sub_self _ }\n\n@[simp] lemma fract_floor (a : \u03b1) : fract (\u230aa\u230b : \u03b1) = 0 := fract_coe _\n\n@[simp] lemma floor_fract (a : \u03b1) : \u230afract a\u230b = 0 :=\nfloor_eq_iff.2 \u27e8fract_nonneg _, by { rw [int.cast_zero, zero_add], exact fract_lt_one a }\u27e9\n\nlemma fract_eq_iff {a b : \u03b1} : fract a = b \u2194 0 \u2264 b \u2227 b < 1 \u2227 \u2203 z : \u2124, a - b = z :=\n\u27e8\u03bb h, by { rw \u2190h, exact \u27e8fract_nonneg _, fract_lt_one _, \u27e8\u230aa\u230b, sub_sub_cancel _ _\u27e9\u27e9},\n  begin\n    rintro \u27e8h\u2080, h\u2081, z, hz\u27e9,\n    show a - \u230aa\u230b = b, apply eq.symm,\n    rw [eq_sub_iff_add_eq, add_comm, \u2190eq_sub_iff_add_eq],\n    rw [hz, int.cast_inj, floor_eq_iff, \u2190hz],\n    clear hz, split; simpa [sub_eq_add_neg, add_assoc]\n  end\u27e9\n\nlemma fract_eq_fract {a b : \u03b1} : fract a = fract b \u2194 \u2203 z : \u2124, a - b = z :=\n\u27e8\u03bb h, \u27e8\u230aa\u230b - \u230ab\u230b, begin\n  unfold fract at h, rw [int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h],\n end\u27e9, begin\n  rintro \u27e8z, hz\u27e9,\n  refine fract_eq_iff.2 \u27e8fract_nonneg _, fract_lt_one _, z + \u230ab\u230b, _\u27e9,\n  rw [eq_add_of_sub_eq hz, add_comm, int.cast_add],\n  exact add_sub_sub_cancel _ _ _,\nend\u27e9\n\n@[simp] lemma fract_eq_self {a : \u03b1} : fract a = a \u2194 0 \u2264 a \u2227 a < 1 :=\nfract_eq_iff.trans $ and.assoc.symm.trans $ and_iff_left \u27e80, sub_self a\u27e9\n\n@[simp] lemma fract_fract (a : \u03b1) : fract (fract a) = fract a :=\nfract_eq_self.2 \u27e8fract_nonneg _, fract_lt_one _\u27e9\n\nlemma fract_add (a b : \u03b1) : \u2203 z : \u2124, fract (a + b) - fract a - fract b = z :=\n\u27e8\u230aa\u230b + \u230ab\u230b - \u230aa + b\u230b, by { unfold fract, simp [sub_eq_add_neg], abel }\u27e9\n\nlemma fract_mul_nat (a : \u03b1) (b : \u2115) : \u2203 z : \u2124, fract a * b - fract (a * b) = z :=\nbegin\n  induction b with c hc,\n    use 0, simp,\n  rcases hc with \u27e8z, hz\u27e9,\n  rw [nat.succ_eq_add_one, nat.cast_add, mul_add, mul_add, nat.cast_one, mul_one, mul_one],\n  rcases fract_add (a * c) a with \u27e8y, hy\u27e9,\n  use z - y,\n  rw [int.cast_sub, \u2190hz, \u2190hy],\n  abel\nend\n\nlemma preimage_fract (s : set \u03b1) : fract \u207b\u00b9' s = \u22c3 m : \u2124, (\u03bb x, x - m) \u207b\u00b9' (s \u2229 Ico (0 : \u03b1) 1) :=\nbegin\n  ext x,\n  simp only [mem_preimage, mem_Union, mem_inter_eq],\n  refine \u27e8\u03bb h, \u27e8\u230ax\u230b, h, fract_nonneg x, fract_lt_one x\u27e9, _\u27e9,\n  rintro \u27e8m, hms, hm0, hm1\u27e9,\n  obtain rfl : \u230ax\u230b = m, from floor_eq_iff.2 \u27e8sub_nonneg.1 hm0, sub_lt_iff_lt_add'.1 hm1\u27e9,\n  exact hms\nend\n\nlemma image_fract (s : set \u03b1) : fract '' s = \u22c3 m : \u2124, (\u03bb x, x - m) '' s \u2229 Ico 0 1 :=\nbegin\n  ext x,\n  simp only [mem_image, mem_inter_eq, mem_Union], split,\n  { rintro \u27e8y, hy, rfl\u27e9,\n    exact \u27e8\u230ay\u230b, \u27e8y, hy, rfl\u27e9, fract_nonneg y, fract_lt_one y\u27e9 },\n  { rintro \u27e8m, \u27e8y, hys, rfl\u27e9, h0, h1\u27e9,\n    obtain rfl : \u230ay\u230b = m, from floor_eq_iff.2 \u27e8sub_nonneg.1 h0, sub_lt_iff_lt_add'.1 h1\u27e9,\n    exact \u27e8y, hys, rfl\u27e9 }\nend\n\nsection linear_ordered_field\n\nvariables {k : Type*} [linear_ordered_field k] [floor_ring k]\n\nlemma fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b/a) * a \u2208 Ico 0 a :=\n\u27e8(zero_le_mul_right ha).2 (fract_nonneg (b/a)), (mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b/a))\u27e9\n\nlemma fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a \u2260 0) :\n  fract (b/a) * a + \u230ab/a\u230b \u2022 a = b :=\nby rw [zsmul_eq_mul, \u2190 add_mul, fract_add_floor, div_mul_cancel b ha]\n\nend linear_ordered_field\n\n/-! #### Ceil -/\n\nlemma gc_ceil_coe : galois_connection ceil (coe : \u2124 \u2192 \u03b1) := floor_ring.gc_ceil_coe\n\nlemma ceil_le : \u2308a\u2309 \u2264 z \u2194 a \u2264 z := gc_ceil_coe a z\n\nlemma floor_neg : \u230a-a\u230b = -\u2308a\u2309 :=\neq_of_forall_le_iff (\u03bb z, by rw [le_neg, ceil_le, le_floor, int.cast_neg, le_neg])\n\nlemma ceil_neg : \u2308-a\u2309 = -\u230aa\u230b :=\neq_of_forall_ge_iff (\u03bb z, by rw [neg_le, ceil_le, le_floor, int.cast_neg, neg_le])\n\nlemma lt_ceil : z < \u2308a\u2309 \u2194 (z : \u03b1) < a := lt_iff_lt_of_le_iff_le ceil_le\n\nlemma ceil_le_floor_add_one (a : \u03b1) : \u2308a\u2309 \u2264 \u230aa\u230b + 1 :=\nby { rw [ceil_le, int.cast_add, int.cast_one], exact (lt_floor_add_one a).le }\n\nlemma le_ceil (a : \u03b1) : a \u2264 \u2308a\u2309 := gc_ceil_coe.le_u_l a\n\n@[simp] lemma ceil_coe (z : \u2124) : \u2308(z : \u03b1)\u2309 = z :=\neq_of_forall_ge_iff $ \u03bb a, by rw [ceil_le, int.cast_le]\n\nlemma ceil_mono : monotone (ceil : \u03b1 \u2192 \u2124) := gc_ceil_coe.monotone_l\n\n@[simp] lemma ceil_add_int (a : \u03b1) (z : \u2124) : \u2308a + z\u2309 = \u2308a\u2309 + z :=\nby rw [\u2190neg_inj, neg_add', \u2190floor_neg, \u2190floor_neg, neg_add', floor_sub_int]\n\n@[simp] lemma ceil_add_one (a : \u03b1) : \u2308a + 1\u2309 = \u2308a\u2309 + 1 :=\nby { convert ceil_add_int a (1 : \u2124), exact cast_one.symm }\n\n@[simp] lemma ceil_sub_int (a : \u03b1) (z : \u2124) : \u2308a - z\u2309 = \u2308a\u2309 - z :=\neq.trans (by rw [int.cast_neg, sub_eq_add_neg]) (ceil_add_int _ _)\n\n@[simp] lemma ceil_sub_one (a : \u03b1) : \u2308a - 1\u2309 = \u2308a\u2309 - 1 :=\nby rw [eq_sub_iff_add_eq, \u2190 ceil_add_one, sub_add_cancel]\n\nlemma ceil_lt_add_one (a : \u03b1) : (\u2308a\u2309 : \u03b1) < a + 1 :=\nby { rw [\u2190 lt_ceil, \u2190 int.cast_one, ceil_add_int], apply lt_add_one }\n\nlemma ceil_pos : 0 < \u2308a\u2309 \u2194 0 < a := lt_ceil\n\n@[simp] lemma ceil_zero : \u2308(0 : \u03b1)\u2309 = 0 := ceil_coe 0\n\nlemma ceil_nonneg (ha : 0 \u2264 a) : 0 \u2264 \u2308a\u2309 :=\nby exact_mod_cast ha.trans (le_ceil a)\n\nlemma ceil_eq_iff : \u2308a\u2309 = z \u2194 \u2191z - 1 < a \u2227 a \u2264 z :=\nby rw [\u2190ceil_le, \u2190int.cast_one, \u2190int.cast_sub, \u2190lt_ceil, int.sub_one_lt_iff, le_antisymm_iff,\n  and.comm]\n\nlemma ceil_eq_on_Ioc (z : \u2124) : \u2200 a \u2208 set.Ioc (z - 1 : \u03b1) z, \u2308a\u2309 = z :=\n\u03bb a \u27e8h\u2080, h\u2081\u27e9, ceil_eq_iff.mpr \u27e8h\u2080, h\u2081\u27e9\n\nlemma ceil_eq_on_Ioc' (z : \u2124) : \u2200 a \u2208 set.Ioc (z - 1 : \u03b1) z, (\u2308a\u2309 : \u03b1) = z :=\n\u03bb a ha, by exact_mod_cast ceil_eq_on_Ioc z a ha\n\nlemma floor_le_ceil (a : \u03b1) : \u230aa\u230b \u2264 \u2308a\u2309 := cast_le.1 $ (floor_le _).trans $ le_ceil _\n\nlemma floor_lt_ceil_of_lt {a b : \u03b1} (h : a < b) : \u230aa\u230b < \u2308b\u2309 :=\ncast_lt.1 $ (floor_le a).trans_lt $ h.trans_le $ le_ceil b\n\n@[simp] lemma preimage_ceil_singleton (m : \u2124) : (ceil : \u03b1 \u2192 \u2124) \u207b\u00b9' {m} = Ioc (m - 1) m :=\next $ \u03bb x, ceil_eq_iff\n\n/-! #### Intervals -/\n\n@[simp] lemma preimage_Ioo {a b : \u03b1} : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Ioo a b)) = set.Ioo \u230aa\u230b \u2308b\u2309 :=\nby { ext, simp [floor_lt, lt_ceil] }\n\n@[simp] lemma preimage_Ico {a b : \u03b1} : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Ico a b)) = set.Ico \u2308a\u2309 \u2308b\u2309 :=\nby { ext, simp [ceil_le, lt_ceil] }\n\n@[simp] lemma preimage_Ioc {a b : \u03b1} : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Ioc a b)) = set.Ioc \u230aa\u230b \u230ab\u230b :=\nby { ext, simp [floor_lt, le_floor] }\n\n@[simp] lemma preimage_Icc {a b : \u03b1} : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Icc a b)) = set.Icc \u2308a\u2309 \u230ab\u230b :=\nby { ext, simp [ceil_le, le_floor] }\n\n@[simp] lemma preimage_Ioi : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Ioi a)) = set.Ioi \u230aa\u230b :=\nby { ext, simp [floor_lt] }\n\n@[simp] lemma preimage_Ici : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Ici a)) = set.Ici \u2308a\u2309 :=\nby { ext, simp [ceil_le] }\n\n@[simp] lemma preimage_Iio : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Iio a)) = set.Iio \u2308a\u2309 :=\nby { ext, simp [lt_ceil] }\n\n@[simp] lemma preimage_Iic : ((coe : \u2124 \u2192 \u03b1) \u207b\u00b9' (set.Iic a)) = set.Iic \u230aa\u230b :=\nby { ext, simp [le_floor] }\n\nend int\n\nvariables {\u03b1} [linear_ordered_ring \u03b1] [floor_ring \u03b1]\n\n/-! #### A floor ring as a floor semiring -/\n\n@[priority 100] -- see Note [lower instance priority]\ninstance _root_.floor_ring.to_floor_semiring : floor_semiring \u03b1 :=\n{ floor := \u03bb a, \u230aa\u230b.to_nat,\n  ceil := \u03bb a, \u2308a\u2309.to_nat,\n  floor_of_neg := \u03bb a ha, int.to_nat_of_nonpos (int.floor_nonpos ha.le),\n  gc_floor := \u03bb a n ha, by { rw [int.le_to_nat_iff (int.floor_nonneg.2 ha), int.le_floor], refl },\n  gc_ceil := \u03bb a n, by { rw [int.to_nat_le, int.ceil_le], refl } }\n\nlemma int.floor_to_nat (a : \u03b1) : \u230aa\u230b.to_nat = \u230aa\u230b\u208a := rfl\n\nlemma int.ceil_to_nat  (a : \u03b1) : \u2308a\u2309.to_nat = \u2308a\u2309\u208a := rfl\n\nvariables {a : \u03b1}\n\nlemma nat.cast_floor_eq_int_floor (ha : 0 \u2264 a) : (\u230aa\u230b\u208a : \u2124) = \u230aa\u230b :=\nby rw [\u2190int.floor_to_nat, int.to_nat_of_nonneg (int.floor_nonneg.2 ha)]\n\nlemma nat.cast_floor_eq_cast_int_floor (ha : 0 \u2264 a) : (\u230aa\u230b\u208a : \u03b1) = \u230aa\u230b :=\nby rw [\u2190nat.cast_floor_eq_int_floor ha, int.cast_coe_nat]\n\nlemma nat.cast_ceil_eq_int_ceil (ha : 0 \u2264 a) : (\u2308a\u2309\u208a : \u2124) = \u2308a\u2309 :=\nby { rw [\u2190int.ceil_to_nat, int.to_nat_of_nonneg (int.ceil_nonneg ha)] }\n\nlemma nat.cast_ceil_eq_cast_int_ceil (ha : 0 \u2264 a) : (\u2308a\u2309\u208a : \u03b1) = \u2308a\u2309 :=\nby rw [\u2190nat.cast_ceil_eq_int_ceil ha, int.cast_coe_nat]\n\n/-- There exists at most one `floor_ring` structure on a given linear ordered ring. -/\nlemma subsingleton_floor_ring {\u03b1} [linear_ordered_ring \u03b1] :\n  subsingleton (floor_ring \u03b1) :=\nbegin\n  refine \u27e8\u03bb H\u2081 H\u2082, _\u27e9,\n  have : H\u2081.floor = H\u2082.floor := funext (\u03bb a, H\u2081.gc_coe_floor.u_unique H\u2082.gc_coe_floor $ \u03bb _, rfl),\n  have : H\u2081.ceil = H\u2082.ceil := funext (\u03bb a, H\u2081.gc_ceil_coe.l_unique H\u2082.gc_ceil_coe $ \u03bb _, rfl),\n  cases H\u2081, cases H\u2082, congr; assumption\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/order/floor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511359371249, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7132018032734888}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module data.finsupp.ne_locus\n! leanprover-community/mathlib commit f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finsupp.Defs\n\n/-!\n# Locus of unequal values of finitely supported functions\n\nLet `\u03b1 N` be two Types, assume that `N` has a `0` and let `f g : \u03b1 \u2192\u2080 N` be finitely supported\nfunctions.\n\n## Main definition\n\n* `Finsupp.neLocus f g : Finset \u03b1`, the finite subset of `\u03b1` where `f` and `g` differ.\n\nIn the case in which `N` is an additive group, `Finsupp.neLocus f g` coincides with\n`Finsupp.support (f - g)`.\n-/\n\n\nvariable {\u03b1 M N P : Type _}\n\nnamespace Finsupp\n\nvariable [DecidableEq \u03b1]\n\nsection NHasZero\n\nvariable [DecidableEq N] [Zero N] (f g : \u03b1 \u2192\u2080 N)\n\n/-- Given two finitely supported functions `f g : \u03b1 \u2192\u2080 N`, `Finsupp.neLocus f g` is the `Finset`\nwhere `f` and `g` differ. This generalizes `(f - g).support` to situations without subtraction. -/\ndef neLocus (f g : \u03b1 \u2192\u2080 N) : Finset \u03b1 :=\n  (f.support \u222a g.support).filter fun x => f x \u2260 g x\n#align finsupp.ne_locus Finsupp.neLocus\n\n@[simp]\ntheorem mem_neLocus {f g : \u03b1 \u2192\u2080 N} {a : \u03b1} : a \u2208 f.neLocus g \u2194 f a \u2260 g a := by\n  simpa only [neLocus, Finset.mem_filter, Finset.mem_union, mem_support_iff,\n    and_iff_right_iff_imp] using Ne.ne_or_ne _\n#align finsupp.mem_ne_locus Finsupp.mem_neLocus\n\ntheorem not_mem_neLocus {f g : \u03b1 \u2192\u2080 N} {a : \u03b1} : a \u2209 f.neLocus g \u2194 f a = g a :=\n  mem_neLocus.not.trans not_ne_iff\n#align finsupp.not_mem_ne_locus Finsupp.not_mem_neLocus\n\n@[simp]\ntheorem coe_neLocus : \u2191(f.neLocus g) = { x | f x \u2260 g x } := by\n  ext\n  exact mem_neLocus\n#align finsupp.coe_ne_locus Finsupp.coe_neLocus\n\n@[simp]\ntheorem neLocus_eq_empty {f g : \u03b1 \u2192\u2080 N} : f.neLocus g = \u2205 \u2194 f = g :=\n  \u27e8fun h =>\n    ext fun a => not_not.mp (mem_neLocus.not.mp (Finset.eq_empty_iff_forall_not_mem.mp h a)),\n    fun h => h \u25b8 by simp only [neLocus, Ne.def, eq_self_iff_true, not_true, Finset.filter_False]\u27e9\n#align finsupp.ne_locus_eq_empty Finsupp.neLocus_eq_empty\n\n@[simp]\ntheorem nonempty_neLocus_iff {f g : \u03b1 \u2192\u2080 N} : (f.neLocus g).Nonempty \u2194 f \u2260 g :=\n  Finset.nonempty_iff_ne_empty.trans neLocus_eq_empty.not\n#align finsupp.nonempty_ne_locus_iff Finsupp.nonempty_neLocus_iff\n\ntheorem neLocus_comm : f.neLocus g = g.neLocus f := by\n  simp_rw [neLocus, Finset.union_comm, ne_comm]\n#align finsupp.ne_locus_comm Finsupp.neLocus_comm\n\n@[simp]\ntheorem neLocus_zero_right : f.neLocus 0 = f.support := by\n  ext\n  rw [mem_neLocus, mem_support_iff, coe_zero, Pi.zero_apply]\n#align finsupp.ne_locus_zero_right Finsupp.neLocus_zero_right\n\n@[simp]\ntheorem neLocus_zero_left : (0 : \u03b1 \u2192\u2080 N).neLocus f = f.support :=\n  (neLocus_comm _ _).trans (neLocus_zero_right _)\n#align finsupp.ne_locus_zero_left Finsupp.neLocus_zero_left\n\nend NHasZero\n\nsection NeLocusAndMaps\n\ntheorem subset_mapRange_neLocus [DecidableEq N] [Zero N] [DecidableEq M] [Zero M] (f g : \u03b1 \u2192\u2080 N)\n    {F : N \u2192 M} (F0 : F 0 = 0) : (f.mapRange F F0).neLocus (g.mapRange F F0) \u2286 f.neLocus g :=\n  fun x => by simpa only [mem_neLocus, mapRange_apply, not_imp_not] using congr_arg F\n#align finsupp.subset_map_range_ne_locus Finsupp.subset_mapRange_neLocus\n\ntheorem zipWith_neLocus_eq_left [DecidableEq N] [Zero M] [DecidableEq P] [Zero P] [Zero N]\n    {F : M \u2192 N \u2192 P} (F0 : F 0 0 = 0) (f : \u03b1 \u2192\u2080 M) (g\u2081 g\u2082 : \u03b1 \u2192\u2080 N)\n    (hF : \u2200 f, Function.Injective fun g => F f g) :\n    (zipWith F F0 f g\u2081).neLocus (zipWith F F0 f g\u2082) = g\u2081.neLocus g\u2082 := by\n  ext\n  simpa only [mem_neLocus] using (hF _).ne_iff\n#align finsupp.zip_with_ne_locus_eq_left Finsupp.zipWith_neLocus_eq_left\n\ntheorem zipWith_neLocus_eq_right [DecidableEq M] [Zero M] [DecidableEq P] [Zero P] [Zero N]\n    {F : M \u2192 N \u2192 P} (F0 : F 0 0 = 0) (f\u2081 f\u2082 : \u03b1 \u2192\u2080 M) (g : \u03b1 \u2192\u2080 N)\n    (hF : \u2200 g, Function.Injective fun f => F f g) :\n    (zipWith F F0 f\u2081 g).neLocus (zipWith F F0 f\u2082 g) = f\u2081.neLocus f\u2082 := by\n  ext\n  simpa only [mem_neLocus] using (hF _).ne_iff\n#align finsupp.zip_with_ne_locus_eq_right Finsupp.zipWith_neLocus_eq_right\n\ntheorem mapRange_neLocus_eq [DecidableEq N] [DecidableEq M] [Zero M] [Zero N] (f g : \u03b1 \u2192\u2080 N)\n    {F : N \u2192 M} (F0 : F 0 = 0) (hF : Function.Injective F) :\n    (f.mapRange F F0).neLocus (g.mapRange F F0) = f.neLocus g := by\n  ext\n  simpa only [mem_neLocus] using hF.ne_iff\n#align finsupp.map_range_ne_locus_eq Finsupp.mapRange_neLocus_eq\n\nend NeLocusAndMaps\n\nvariable [DecidableEq N]\n\n@[simp]\ntheorem neLocus_add_left [AddLeftCancelMonoid N] (f g h : \u03b1 \u2192\u2080 N) :\n    (f + g).neLocus (f + h) = g.neLocus h :=\n  zipWith_neLocus_eq_left _ _ _ _ add_right_injective\n#align finsupp.ne_locus_add_left Finsupp.neLocus_add_left\n\n@[simp]\ntheorem neLocus_add_right [AddRightCancelMonoid N] (f g h : \u03b1 \u2192\u2080 N) :\n    (f + h).neLocus (g + h) = f.neLocus g :=\n  zipWith_neLocus_eq_right _ _ _ _ add_left_injective\n#align finsupp.ne_locus_add_right Finsupp.neLocus_add_right\n\nsection AddGroup\n\nvariable [AddGroup N] (f f\u2081 f\u2082 g g\u2081 g\u2082 : \u03b1 \u2192\u2080 N)\n\n@[simp]\ntheorem neLocus_neg_neg : neLocus (-f) (-g) = f.neLocus g :=\n  mapRange_neLocus_eq _ _ neg_zero neg_injective\n#align finsupp.ne_locus_neg_neg Finsupp.neLocus_neg_neg\n\ntheorem neLocus_neg : neLocus (-f) g = f.neLocus (-g) := by rw [\u2190 neLocus_neg_neg, neg_neg]\n#align finsupp.ne_locus_neg Finsupp.neLocus_neg\n\ntheorem neLocus_eq_support_sub : f.neLocus g = (f - g).support := by\n  rw [\u2190 neLocus_add_right _ _ (-g), add_right_neg, neLocus_zero_right, sub_eq_add_neg]\n#align finsupp.ne_locus_eq_support_sub Finsupp.neLocus_eq_support_sub\n\n@[simp]\ntheorem neLocus_sub_left : neLocus (f - g\u2081) (f - g\u2082) = neLocus g\u2081 g\u2082 := by\n  simp only [sub_eq_add_neg, neLocus_add_left, neLocus_neg_neg]\n#align finsupp.ne_locus_sub_left Finsupp.neLocus_sub_left\n\n@[simp]\ntheorem neLocus_sub_right : neLocus (f\u2081 - g) (f\u2082 - g) = neLocus f\u2081 f\u2082 := by\n  simpa only [sub_eq_add_neg] using neLocus_add_right _ _ _\n#align finsupp.ne_locus_sub_right Finsupp.neLocus_sub_right\n\n@[simp]\ntheorem neLocus_self_add_right : neLocus f (f + g) = g.support := by\n  rw [\u2190 neLocus_zero_left, \u2190 neLocus_add_left f 0 g, add_zero]\n#align finsupp.ne_locus_self_add_right Finsupp.neLocus_self_add_right\n\n@[simp]\ntheorem neLocus_self_add_left : neLocus (f + g) f = g.support := by\n  rw [neLocus_comm, neLocus_self_add_right]\n#align finsupp.ne_locus_self_add_left Finsupp.neLocus_self_add_left\n\n@[simp]\ntheorem neLocus_self_sub_right : neLocus f (f - g) = g.support := by\n  rw [sub_eq_add_neg, neLocus_self_add_right, support_neg]\n#align finsupp.ne_locus_self_sub_right Finsupp.neLocus_self_sub_right\n\n@[simp]\ntheorem neLocus_self_sub_left : neLocus (f - g) f = g.support := by\n  rw [neLocus_comm, neLocus_self_sub_right]\n#align finsupp.ne_locus_self_sub_left Finsupp.neLocus_self_sub_left\n\nend AddGroup\n\nend Finsupp\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Finsupp/NeLocus.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7132017992519881}}
{"text": "import Mathlib\n\n/-!\n# Random sampling for an element\n\nWe implement sampling to find an element with a given property, for instance being prime or being coprime to a given number. For this we need a hypothesis that such an element exists. \n\nWe use the `IO` monad to generate random numbers. This is because a random number is not a function, in the sense of having value determined by arguments.\n-/\n\n/-!\nThe basic way we sample is to choose an element at random from the list, and then check if it satisfies the property. If it does, we return it. If not, we remove it from the list and try again. To show termination we see (following a lab) that the length of the list decreases by at least one each time.\n-/\n\nuniverse u\n/-- Removing an element from a list does not increase length -/\ntheorem remove_length_le {\u03b1 :  Type u} [DecidableEq \u03b1](a : \u03b1) (l : List \u03b1) : (List.remove a l).length \u2264 l.length := by \n  induction l with\n  | nil => \n    simp [List.remove]\n  | cons h' t ih => \n      simp [List.remove]\n      split\n      \u00b7 apply Nat.le_step\n        assumption\n      \u00b7 rw [List.length_cons]\n        apply Nat.succ_le_succ\n        exact ih\n\n\n/-- Removing a member from a list shortens the list -/\ntheorem remove_mem_length  {\u03b1 :  Type u} [DecidableEq \u03b1]{a : \u03b1 } {l : List \u03b1} (hyp : a \u2208 l) : (List.remove a l).length < l.length  := by \n  induction l with\n  | nil => \n    contradiction\n  | cons h' t ih => \n      simp [List.remove]\n      split \n      \u00b7 apply Nat.lt_succ_of_le\n        apply remove_length_le\n      \u00b7 rw [List.length_cons]\n        apply Nat.succ_lt_succ\n        have in_tail: a \u2208 t := by \n          have : \u00ac a = h' := by assumption\n          simp [List.mem_cons, this] at hyp\n          assumption\n        exact ih in_tail\n\n\n/-!\nWe pick an index of the list `l`, which is of type `Fin l.length`. Rather than proving that the random number generator has this property we pass `mod n`.\n-/\n\n/-- A random number in `Fin n` -/\ndef IO.randFin (n : \u2115)(h : 0 < n ) : IO <| Fin n   := do\n  let r \u2190 IO.rand 0 (n - 1)\n  pure \u27e8r % n, Nat.mod_lt r h\u27e9\n\n#check List.mem_remove_iff -- \u2200 {\u03b1 : Type u_1} [inst : DecidableEq \u03b1] {a b : \u03b1} {as : List \u03b1}, b \u2208 List.remove a as \u2194 b \u2208 as \u2227 b \u2260 a\n#check List.length_pos_of_mem -- \u2200 {\u03b1 : Type u_1} {a : \u03b1} {l : List \u03b1}, a \u2208 l \u2192 0 < List.length l\n#check List.get_mem -- \u2200 {\u03b1 : Type u_1} (l : List \u03b1) (n : \u2115) (h : n < List.length l), List.get l { val := n, isLt := h } \u2208 l\n\n\n/-- A random element with a given property from a list, within `IO`  -/\ndef pickElemIO [DecidableEq \u03b1](l: List \u03b1)(p: \u03b1 \u2192 Bool)(h : \u2203t : \u03b1, t \u2208 l \u2227 p t = true) : IO {t : \u03b1 // t \u2208 l \u2227 p t = true} := do\n  have h' : 0 < l.length := by \n    have \u27e8t, h\u2080\u27e9 := h\n    apply List.length_pos_of_mem h\u2080.left\n  let index \u2190 IO.randFin l.length h' \n  let a := l.get index\n  if c:p a = true then\n    return \u27e8a, by \n      simp [c]\n      apply List.get_mem\n      \u27e9\n  else\n    let l' := l.remove a\n    have h' : \u2203t : \u03b1, t \u2208 l' \u2227 p t = true :=\n      by\n        have \u27e8t, h\u2081, h\u2082\u27e9 := h\n        use t\n        simp [List.mem_remove_iff, h\u2081, h\u2082]\n        simp at c\n        intro contra\n        simp [contra, c] at h\u2082\n    have : l'.length < l.length := by\n      apply remove_mem_length\n      apply List.get_mem\n    let \u27e8t, h\u2081, h\u2082\u27e9 \u2190  pickElemIO l' p h'\n    have m : t \u2208 l := \n      List.mem_of_mem_remove h\u2081\n    return \u27e8t, m, h\u2082\u27e9\ntermination_by _ _ _ l _ _ => l.length  \n    \n/-- A random element with a given property from a list. As IO may in principle give an error, we specify a default to fallback and the conditions that this is in the list and has the property `p` -/\ndef pickElemD [DecidableEq \u03b1](l: List \u03b1)(p: \u03b1 \u2192 Bool)(default : \u03b1)(h\u2081 : default \u2208 l)(h\u2082 : p default = true)\n  : \n    {t : \u03b1 // t \u2208 l \u2227 p t = true} := (pickElemIO l p \u27e8default, h\u2081, h\u2082\u27e9).run' () |>.getD \u27e8default, h\u2081, h\u2082\u27e9\n\n/-!\n## Random Monad\n\nWe used the IO Monad which has a lot of stuff besides randomness.\n-/", "meta": {"author": "siddhartha-gadgil", "repo": "proofs-and-programs-2023", "sha": "9d95a5396c018b9a26ed0d27c52cd446794cd1aa", "save_path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023", "path": "github-repos/lean/siddhartha-gadgil-proofs-and-programs-2023/proofs-and-programs-2023-9d95a5396c018b9a26ed0d27c52cd446794cd1aa/PnP2023/Lec_03_24/Sampling.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.713146172497205}}
{"text": "import data.set data.bool classical\nopen bool set eq.ops\n\n-- definition powertype [reducible] (T : Type) := T \u2192 bool\ndefinition injective [reducible] {T U : Type} (f : T \u2192 U) := \u2200 (x y : T), f x = f y \u2192 x = y\ndefinition surjective [reducible] {T U : Type} (f : T \u2192 U) := \u2200 (u : U), \u2203 (x : T), f x = u\n\n-- Misc lemmas\nlemma case_analysis (b : bool) {c : Prop} : (b = tt \u2192 c) \u2192 (b = ff \u2192 c) \u2192 c := \n  take tt_c ff_c, or.elim (dichotomy b) ff_c tt_c\n\nlemma bnot_of_false {b : bool} : b = bnot b \u2192 false := sorry\nlemma not_of_false {P : Prop} : P = \u00ac P \u2192 false := sorry\n-- Cantor's theorem : \n\nsection cantor\n\nvariables {T : Type} [T_dec : decidable_eq T]\ninclude T_dec\n\n-- On types\ntheorem cantor : \u00ac \u2203 (f : T \u2192 (T \u2192 bool)), surjective f :=\n  assume exists_surjection : \u2203 (f : T \u2192 (T \u2192 bool)), surjective f,\n  obtain (f : T \u2192 (T \u2192 bool)) (f_surjective : surjective f), from exists_surjection,\n  let D := \u03bb x, bnot (f x x) in\n  obtain (d : T) (fd_eq_D : f d = D), from f_surjective D,\n  have fdd_eq_nfdd : f d d = bnot (f d d), from \n    calc f d d = D d : congr fd_eq_D rfl\n         ... = bnot (f d d) : rfl,\n  show false, from bnot_of_false fdd_eq_nfdd\n\n-- On types with Prop\ntheorem cantor_prop : \u00ac \u2203 (f : T \u2192 (T \u2192 Prop)), surjective f :=\n  assume exists_surjection : \u2203 (f : T \u2192 (T \u2192 Prop)), surjective f,\n  obtain (f : T \u2192 (T \u2192 Prop)) (f_surjective : surjective f), from exists_surjection,\n  let D := \u03bb x, \u00ac f x x in\n  obtain (d : T) (fd_eq_D : f d = D), from f_surjective D,\n  have fdd_eq_nfdd : f d d = \u00ac f d d, from \n    calc f d d = D d : congr fd_eq_D rfl\n         ... = \u00ac f d d : rfl,\n  show false, from not_of_false fdd_eq_nfdd\n\n\n-- On sets\n\n/- TODO in progress\n\ndefinition powerset (xs : set T) : set (set T) := \u03bb ys, ys \u2286 xs\nvariables (S : set T)\n\nlemma dneg {P : Prop} : \u00ac \u00ac P \u2192 P := sorry \n\ntheorem cantor_set : \u00ac \u2203 (f : map S (powerset S)), surjective f :=\n  assume exists_surjection : \u2203 (f : map S (powerset S)), surjective f,\n  obtain (f : map S (powerset S)) (f_surjective : surjective f), from exists_surjection,\n  let D := { x \u2208 S | x \u2209 f x } in\n  obtain (d : T) (fd_eq_D : f d = D), from f_surjective D,\n  or.elim (em (d \u2208 f d))\n          (assume d_in_fd : d \u2208 f d, \n           have d_in_D : d \u2208 D, from fd_eq_D \u25b8 d_in_fd,\n           -- the ands are unfortunate\n           have d_nin_fd  : d \u2209 f d, from and.right d_in_D,\n           absurd d_in_fd d_nin_fd)\n          (assume d_nin_fd : d \u2209 f d, \n           have d_nin_D : d \u2209 D, from fd_eq_D \u25b8 d_nin_fd,\n           -- obnoxious, but we can make it cleaner\n           have d_nnin_fd  : \u00ac d \u2209 f d, from sorry,\n           have d_in_fd : d \u2208 f d, from dneg d_nnin_fd,\n           absurd d_in_fd d_nin_fd)\n\n            \n                 \n           \n                   \n\n\n\n-/\nend cantor\n", "meta": {"author": "dselsam", "repo": "cs103", "sha": "31ab9784a6f65f226efb702a0da52f907c616a71", "save_path": "github-repos/lean/dselsam-cs103", "path": "github-repos/lean/dselsam-cs103/cs103-31ab9784a6f65f226efb702a0da52f907c616a71/cantor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7826624890918021, "lm_q1q2_score": 0.7131461704091269}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport data.equiv.basic\nimport tactic.norm_fin\n\n/-!\n# `norm_swap`\n\nEvaluating `swap x y z` for numerals `x y z` that are `\u2115`, `\u2124`, or `\u211a`, via a `norm_num` plugin.\nTerms are passed to `eval`, quickly failing if not of the form `swap x y z`.\nThe expressions for numerals `x y z` are converted to `nat`, and then compared.\nBased on equality of these `nat`s, equality proofs are generated using either\n`equiv.swap_apply_left`, `equiv.swap_apply_right`, or `swap_apply_of_ne_of_ne`.\n-/\n\nopen equiv tactic expr\n\nopen norm_num\n\nnamespace norm_swap\n\n/--\nA `norm_num` plugin for normalizing `equiv.swap a b c`\nwhere `a b c` are numerals of `\u2115`, `\u2124`, `\u211a` or `fin n`.\n\n```\nexample : equiv.swap 1 2 1 = 2 := by norm_num\n```\n-/\n@[norm_num] meta def eval : expr \u2192 tactic (expr \u00d7 expr) := \u03bb e, do\n  (swapt, coe_fn_inst, fexpr, c) \u2190 e.match_app_coe_fn <|> fail \"did not get an app coe_fn expr\",\n  guard (fexpr.get_app_fn.const_name = ``equiv.swap) <|> fail \"coe_fn not of equiv.swap\",\n  [\u03b1, deceq_inst, a, b] \u2190 pure fexpr.get_app_args <|>\n    fail \"swap did not have exactly two args applied\",\n  na \u2190 a.to_rat <|> (do (fa, _) \u2190 norm_fin.eval_fin_num a, fa.to_rat),\n  nb \u2190 b.to_rat <|> (do (fb, _) \u2190 norm_fin.eval_fin_num b, fb.to_rat),\n  nc \u2190 c.to_rat <|> (do (fc, _) \u2190 norm_fin.eval_fin_num c, fc.to_rat),\n  if nc = na then do\n    p \u2190 mk_mapp `equiv.swap_apply_left [\u03b1, deceq_inst, a, b],\n    pure (b, p)\n  else if nc = nb then do\n    p \u2190 mk_mapp `equiv.swap_apply_right [\u03b1, deceq_inst, a, b],\n    pure (a, p)\n  else do\n    nic \u2190 mk_instance_cache \u03b1,\n    hca \u2190 (prod.snd <$> prove_ne nic c a nc na) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c a, pure p),\n    hcb \u2190 (prod.snd <$> prove_ne nic c b nc nb) <|>\n      (do (_, ff, p) \u2190 norm_fin.prove_eq_ne_fin c b, pure p),\n    p \u2190 mk_mapp `equiv.swap_apply_of_ne_of_ne [\u03b1, deceq_inst, a, b, c, hca, hcb],\n    pure (c, p)\n\nend norm_swap\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/tactic/norm_swap.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.713109660383749}}
{"text": "namespace HW7\n\n/-\nYour task in this HW is to replace all instances of `sorry` with proofs without errors. If you aren't able to complete a proof, get as much done as you can, and leave `sorry` in the cases you cannot finish. Partial work is better than nothing!\n\nFor this assignment, we redefine the inductive types we will use, and the operations on them, in order to not have standard library automation & already proved theorems get in the way of the assignment. Later on, we will _use_ this automation, but for now, it will get in the way of learning how to prove theorems.\n\nNOTE: For this HW, you cannot use the special List syntax: you must use List.nil & List.cons. You _can_ use number literals (0,1,2, etc) for Nat. \n-/\n\ninductive Nat where\n  | zero : Nat\n  | succ (n : Nat) : Nat\n\ndef natOfNat : _root_.Nat -> Nat\n| _root_.Nat.zero => Nat.zero\n| _root_.Nat.succ n => Nat.succ (natOfNat n)\n-- N.B.: this is the magic that allows us to write numerals\n-- instead of Nat.succ (Nat.succ ...). \ninstance (n : _root_.Nat) : OfNat Nat n where\n  ofNat := natOfNat n\n\ndef Nat.sub : Nat \u2192 Nat \u2192 Nat\n  | a, 0      => a\n  | 0, _      => 0 \n  | Nat.succ a, Nat.succ b => Nat.sub a b\n\ndef Nat.add : Nat \u2192 Nat \u2192 Nat\n  | Nat.zero, b   => b\n  | Nat.succ a, b => Nat.succ (Nat.add a b)\n\ndef Nat.mul : Nat \u2192 Nat \u2192 Nat\n  | _, 0          => 0\n  | a, Nat.succ b => Nat.add (Nat.mul a b) a\n\ninductive List (\u03b1 : Type u) where\n  | nil : List \u03b1\n  | cons (head : \u03b1) (tail : List \u03b1) : List \u03b1\n\ndef List.append : List \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n  | List.nil,       bs => bs\n  | List.cons a as, bs => List.cons a (List.append as bs)\n\ndef List.length : List \u03b1 \u2192 Nat\n  | List.nil       => 0\n  | List.cons _ as => Nat.add (List.length as) 1\n\ndef List.reverse : List Nat -> List Nat \n  | List.nil => List.nil\n  | List.cons a L => List.append (List.reverse L) (List.cons a List.nil) \n\ndef List.filter (p : \u03b1 \u2192 Bool) : List \u03b1 \u2192 List \u03b1\n  | List.nil => List.nil\n  | List.cons a as => match p a with\n    | true => List.cons a (filter p as)\n    | false => filter p as\n\n/- BEGIN PROOFS -/\n\n-- First, redo proofs that you did in HW5, but this time, using tactics. \n-- Note that `variable`s do not need to be introduced!\n\n-- part p1\nvariable (P Q R S : Prop)\n\ntheorem t1 : P -> P := \n by sorry\n\ntheorem t2 : P -> Q -> P := \n by sorry\n\ntheorem t3 : (P -> Q) -> (Q -> R) -> P -> R := \n by sorry\n\ntheorem t4 : P -> Q -> (Q -> P -> R) -> R := \n by sorry\n\ntheorem t5 : (P -> Q) -> (P -> R) -> (R -> Q -> S) -> P -> S := \n by sorry\n\ntheorem t6 : (P -> Q -> R) -> (P -> Q) -> P -> R := \n by sorry\n\n\ntheorem p3 : P \u2227 Q -> (Q -> R) -> R \u2227 P := \n by sorry\n\ntheorem p4 : P \u2228 Q -> (P -> R) -> (Q -> R) -> R := \n by sorry\n\ntheorem p5 : P \u2228 Q -> (P -> R) -> R \u2228 Q := \n by sorry\n\ntheorem p6 : \u00ac Q -> (R -> Q) -> (R \u2228 \u00ac S) -> S -> False := \n by sorry\n\n-- part p1\n\n-- Now, some new proofs\n\n-- part p2\ntheorem and_distrib_or: \u2200 A B C : Prop, \n  A \u2227 (B \u2228 C) \u2194 (A \u2227 B) \u2228 (A \u2227 C) := by sorry\n\ntheorem or_distrib_and: \u2200 A B C : Prop, \n  A \u2228 (B \u2227 C) \u2194 (A \u2228 B) \u2227 (A \u2228 C) := by sorry\n\n-- part p2\n\n-- Now, some proofs that will (likely) require induction, on \n-- either Nat(ural number)s or Lists.\n\n-- part p3\ndef addtail (n m : Nat) : Nat :=\n  match n, m with\n  | Nat.zero, m => m\n  | Nat.succ n', m => addtail n' (Nat.succ m)\n\n-- 8 lines\ntheorem addtail_succ : forall n m, \n  Nat.succ (addtail n m) = addtail (Nat.succ n) m :=\n by sorry\n\n-- 10 lines\ntheorem add_eq : forall n m, Nat.add n m = addtail n m := \n by sorry\n\n-- 9 lines\ntheorem app_associative: \u2200 L1 L2 L3 : List Nat, \n    List.append L1 (List.append L2 L3) = \n    List.append (List.append L1 L2) L3 := \n by sorry\n\n-- 7 lines\ntheorem minus_x_x: \u2200 x : Nat, Nat.sub x x = 0\n:= \n by sorry\n\n-- 5 lines\ntheorem add_n_1 : \u2200 x : Nat, Nat.add x 1 = Nat.succ x :=\n by sorry\n\n-- 9 lines\ntheorem mult_1_x: \u2200 x : Nat, Nat.mul 1 x = x := \n by sorry\n\n-- 7 lines\ntheorem add_assoc: \u2200 x y z : Nat, \n  Nat.add x (Nat.add y z) = Nat.add (Nat.add x y) z := \n by sorry\n\n-- 6 lines\ntheorem add_x_Sy : forall x y, \n  Nat.add x (Nat.succ y) = Nat.succ (Nat.add x y) :=\n by sorry\n\n-- 4 lines\ntheorem add_n_0 : forall n, Nat.add n Nat.zero = n :=\n by sorry\n\n-- 13 lines\ntheorem mult_2_x: \u2200 x : Nat, Nat.mul 2 x = Nat.add x x := \n by sorry\n\n-- 10 lines\ntheorem length_append : forall (T : Type) (L1 L2 : List T), \n  List.length (List.append L1 L2) = Nat.add (List.length L1) (List.length L2) :=\n by sorry\n\n-- 8 lines\ntheorem rev_length: \u2200 L : List Nat, \n  List.length (List.reverse L) = List.length L := \n by sorry\n\n\n-- Consider the following pair of definitions\ndef even : Nat -> Bool \n| 0 => true\n| 1 => false\n| Nat.succ (Nat.succ n) => even n\n\ndef double : Nat \u2192 Nat \n    | 0 => 0\n    | (Nat.succ x) => Nat.succ (Nat.succ (double x))\n\n-- 5 lines\ntheorem even_double: \u2200 x : Nat, even (double x) = true := \n by sorry\n\n-- part p3\nend HW7", "meta": {"author": "logiccomp", "repo": "s23-hw7", "sha": "9c0b3a67f398824a2c0281083e9d22478f1c164e", "save_path": "github-repos/lean/logiccomp-s23-hw7", "path": "github-repos/lean/logiccomp-s23-hw7/s23-hw7-9c0b3a67f398824a2c0281083e9d22478f1c164e/hw7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8962513675912913, "lm_q1q2_score": 0.7131096603166904}}
{"text": "import ..lectures.love13_rational_and_real_numbers_demo\nimport data.nat.parity\n\n/-! # LoVe Homework 9: Rationals, Reals, Quotients -/\n\nnamespace LoVe\n\n/-! \n\n## Question 1 (4 points): Cauchy sequences \n\n1,1 (4 points). In the demo, we sorry'ed the proof that the sum of two Cauchy sequences is Cauchy.\nProve this!\n\n\nHint: depending on how you approach this, you might want to do a long calc-mode proof.  \nIt can be nice to structure this as\n\n```\n    begin\n      <other tactics here>\n      calc \n        t1 = t2 : _ \n       ... \u2264 t3 : _ \n       ... < t4 : _ \n    end \n```\nleaving the placeholders _ in the calc block. \nAt the end of the calc block, you will be left with one goal for each step of the calculation. \n\nexample:\n-/\n\nlemma quarter_pos {x : \u211a} (hx : 0 < x) : 0 < x / 4 := \nbegin \n  have hx2 : 0 < x / 2 := half_pos hx,\n  calc 0 < (x / 2) / 2 : _ \n     ... = x / 4 : _,\n  { apply half_pos,\n    exact hx2 },\n  { ring }\nend \n\nlemma sum_is_cauchy (f g : \u2115 \u2192 \u211a) (hf : is_cau_seq f) (hg : is_cau_seq g) : \n  is_cau_seq (\u03bb n, f n + g n) :=\nsorry\n\n/-! \n## Question 2 (4 points): Operations on the reals \n\n2.1 (3 points). In the demo, we proved `add_comm` on the reals by first proving it for \nCauchy sequences and then lifting this proof. Follow this same procedure \nto prove `zero_add : \u2200 x : real, 0 + x = x`. \n-/\n\nopen LoVe.cau_seq \n\n\n/-! \n2.2 (1 point). Every rational number corresponds to a real number. \nDefine this coercion.\n-/\n\n\ninstance rat_real_coe : has_coe \u211a real :=\n{ coe := sorry }\n\n/-! \n\n## Question 3 (6 points): Quotients in general \n\nIn this problem we'll take a weird quotient of \u2115.\n\nThe following lemmas may be useful:\n-/\n\n#check nat.even_zero\n#check nat.not_even_one\n\n/-!  \n\n3.1 (2 points). Define a setoid structure on \u2115 using the equivalence relation \nwhere `x \u2248 y` if and only if `x` and `y` are both even or both odd.\nE.g. 0 \u2248 2, 1 \u2248 5, but \u00ac 4 \u2248 5. \n-/\ninstance eqv : setoid \u2115 :=\n{ r := sorry,\n  iseqv := sorry\n}\n\n\n/-! \nNow we'll define the quotient of \u2115 by this relation. \nThere are two elements of the quotient:\n-/\ndef eonat := quotient LoVe.eqv  \n\ndef e : eonat := \u27e60\u27e7\ndef o : eonat := \u27e61\u27e7\n\n/-!\n3.2 (2 points). Prove that these are the only two elements of `eonat`.\n-/\nlemma e_or_o (x : eonat) : x = e \u2228 x = o :=\nsorry\n\n/-!\n3.3 (2 points). Lift the addition function on \u2115 to `eonat`. \n\nWhat does the \"addition table\" for `eonat` look like? \nThat is, what are e+e, o+o, e+o, and o+e? \nProve two of these identities. \n-/\n\ndef add : eonat \u2192 eonat \u2192 eonat :=\nsorry \n\n\nend LoVe", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/homework/love09_rational_and_real_numbers_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.713109658245908}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Robert Y. Lewis\n-/\n\nimport ring_theory.witt_vector.structure_polynomial\n\n/-!\n# Witt vectors\n\nIn this file we define the type of `p`-typical Witt vectors and ring operations on it.\nThe ring axioms are verified in `ring_theory/witt_vector/basic.lean`.\n\nFor a fixed commutative ring `R` and prime `p`,\na Witt vector `x : \ud835\udd4e R` is an infinite sequence `\u2115 \u2192 R` of elements of `R`.\nHowever, the ring operations `+` and `*` are not defined in the obvious component-wise way.\nInstead, these operations are defined via certain polynomials\nusing the machinery in `structure_polynomial.lean`.\nThe `n`th value of the sum of two Witt vectors can depend on the `0`-th through `n`th values\nof the summands. This effectively simulates a \u201ccarrying\u201d operation.\n\n## Main definitions\n\n* `witt_vector p R`: the type of `p`-typical Witt vectors with coefficients in `R`.\n* `witt_vector.coeff x n`: projects the `n`th value of the Witt vector `x`.\n\n## Notation\n\nWe use notation `\ud835\udd4e R`, entered `\\bbW`, for the Witt vectors over `R`.\n\n## References\n\n* [Hazewinkel, *Witt Vectors*][Haze09]\n\n* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]\n-/\n\nnoncomputable theory\n\n/-- `witt_vector p R` is the ring of `p`-typical Witt vectors over the commutative ring `R`,\nwhere `p` is a prime number.\n\nIf `p` is invertible in `R`, this ring is isomorphic to `\u2115 \u2192 R` (the product of `\u2115` copies of `R`).\nIf `R` is a ring of characteristic `p`, then `witt_vector p R` is a ring of characteristic `0`.\nThe canonical example is `witt_vector p (zmod p)`,\nwhich is isomorphic to the `p`-adic integers `\u2124_[p]`. -/\nstructure witt_vector (p : \u2115) (R : Type*) :=\nmk [] :: (coeff : \u2115 \u2192 R)\n\nvariables {p : \u2115}\n\n/- We cannot make this `localized` notation, because the `p` on the RHS doesn't occur on the left\nHiding the `p` in the notation is very convenient, so we opt for repeating the `local notation`\nin other files that use Witt vectors. -/\nlocal notation `\ud835\udd4e` := witt_vector p -- type as `\\bbW`\n\nnamespace witt_vector\n\nvariables (p) {R : Type*}\n\n/-- Construct a Witt vector `mk p x : \ud835\udd4e R` from a sequence `x` of elements of `R`. -/\nadd_decl_doc witt_vector.mk\n\n/--\n`x.coeff n` is the `n`th coefficient of the Witt vector `x`.\n\nThis concept does not have a standard name in the literature.\n-/\nadd_decl_doc witt_vector.coeff\n\n@[ext] lemma ext {x y : \ud835\udd4e R} (h : \u2200 n, x.coeff n = y.coeff n) : x = y :=\nbegin\n  cases x,\n  cases y,\n  simp only at h,\n  simp [function.funext_iff, h]\nend\n\nlemma ext_iff {x y : \ud835\udd4e R} : x = y \u2194 \u2200 n, x.coeff n = y.coeff n :=\n\u27e8\u03bb h n, by rw h, ext\u27e9\n\nlemma coeff_mk (x : \u2115 \u2192 R) :\n  (mk p x).coeff = x := rfl\n\n/- These instances are not needed for the rest of the development,\nbut it is interesting to establish early on that `witt_vector p` is a lawful functor. -/\ninstance : functor (witt_vector p) :=\n{ map := \u03bb \u03b1 \u03b2 f v, mk p (f \u2218 v.coeff),\n  map_const := \u03bb \u03b1 \u03b2 a v, mk p (\u03bb _, a) }\n\ninstance : is_lawful_functor (witt_vector p) :=\n{ map_const_eq := \u03bb \u03b1 \u03b2, rfl,\n  id_map := \u03bb \u03b1 \u27e8v, _\u27e9, rfl,\n  comp_map := \u03bb \u03b1 \u03b2 \u03b3 f g v, rfl }\n\nvariables (p) [hp : fact p.prime] [comm_ring R]\ninclude hp\nopen mv_polynomial\n\nsection ring_operations\n\n/-- The polynomials used for defining the element `0` of the ring of Witt vectors. -/\ndef witt_zero : \u2115 \u2192 mv_polynomial (fin 0 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p 0\n\n/-- The polynomials used for defining the element `1` of the ring of Witt vectors. -/\ndef witt_one : \u2115 \u2192 mv_polynomial (fin 0 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p 1\n\n/-- The polynomials used for defining the addition of the ring of Witt vectors. -/\ndef witt_add : \u2115 \u2192 mv_polynomial (fin 2 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p (X 0 + X 1)\n\n/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/\ndef witt_nsmul (n : \u2115) : \u2115 \u2192 mv_polynomial (fin 1 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p (n \u2022 X 0)\n\n/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/\ndef witt_zsmul (n : \u2124) : \u2115 \u2192 mv_polynomial (fin 1 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p (n \u2022 X 0)\n\n/-- The polynomials used for describing the subtraction of the ring of Witt vectors. -/\ndef witt_sub : \u2115 \u2192 mv_polynomial (fin 2 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p (X 0 - X 1)\n\n/-- The polynomials used for defining the multiplication of the ring of Witt vectors. -/\ndef witt_mul : \u2115 \u2192 mv_polynomial (fin 2 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p (X 0 * X 1)\n\n/-- The polynomials used for defining the negation of the ring of Witt vectors. -/\ndef witt_neg : \u2115 \u2192 mv_polynomial (fin 1 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p (-X 0)\n\n/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/\ndef witt_pow (n : \u2115) : \u2115 \u2192 mv_polynomial (fin 1 \u00d7 \u2115) \u2124 :=\nwitt_structure_int p (X 0 ^ n)\n\nvariable {p}\nomit hp\n\n/-- An auxiliary definition used in `witt_vector.eval`.\nEvaluates a polynomial whose variables come from the disjoint union of `k` copies of `\u2115`,\nwith a curried evaluation `x`.\nThis can be defined more generally but we use only a specific instance here. -/\ndef peval {k : \u2115} (\u03c6 : mv_polynomial (fin k \u00d7 \u2115) \u2124) (x : fin k \u2192 \u2115 \u2192 R) : R :=\naeval (function.uncurry x) \u03c6\n\n/--\nLet `\u03c6` be a family of polynomials, indexed by natural numbers, whose variables come from the\ndisjoint union of `k` copies of `\u2115`, and let `x\u1d62` be a Witt vector for `0 \u2264 i < k`.\n\n`eval \u03c6 x` evaluates `\u03c6` mapping the variable `X_(i, n)` to the `n`th coefficient of `x\u1d62`.\n\nInstantiating `\u03c6` with certain polynomials defined in `structure_polynomial.lean` establishes the\nring operations on `\ud835\udd4e R`. For example, `witt_vector.witt_add` is such a `\u03c6` with `k = 2`;\nevaluating this at `(x\u2080, x\u2081)` gives us the sum of two Witt vectors `x\u2080 + x\u2081`.\n-/\ndef eval {k : \u2115} (\u03c6 : \u2115 \u2192 mv_polynomial (fin k \u00d7 \u2115) \u2124) (x : fin k \u2192 \ud835\udd4e R) : \ud835\udd4e R :=\nmk p $ \u03bb n, peval (\u03c6 n) $ \u03bb i, (x i).coeff\n\nvariables (R) [fact p.prime]\n\ninstance : has_zero (\ud835\udd4e R) :=\n\u27e8eval (witt_zero p) ![]\u27e9\n\ninstance : inhabited (\ud835\udd4e R) := \u27e80\u27e9\n\ninstance : has_one (\ud835\udd4e R) :=\n\u27e8eval (witt_one p) ![]\u27e9\n\ninstance : has_add (\ud835\udd4e R) :=\n\u27e8\u03bb x y, eval (witt_add p) ![x, y]\u27e9\n\ninstance : has_sub (\ud835\udd4e R) :=\n\u27e8\u03bb x y, eval (witt_sub p) ![x, y]\u27e9\n\ninstance has_nat_scalar : has_smul \u2115 (\ud835\udd4e R) :=\n\u27e8\u03bb n x, eval (witt_nsmul p n) ![x]\u27e9\n\ninstance has_int_scalar : has_smul \u2124 (\ud835\udd4e R) :=\n\u27e8\u03bb n x, eval (witt_zsmul p n) ![x]\u27e9\n\ninstance : has_mul (\ud835\udd4e R) :=\n\u27e8\u03bb x y, eval (witt_mul p) ![x, y]\u27e9\n\ninstance : has_neg (\ud835\udd4e R) :=\n\u27e8\u03bb x, eval (witt_neg p) ![x]\u27e9\n\ninstance has_nat_pow : has_pow (\ud835\udd4e R) \u2115 :=\n\u27e8\u03bb x n, eval (witt_pow p n) ![x]\u27e9\n\ninstance : has_nat_cast (\ud835\udd4e R) := \u27e8nat.unary_cast\u27e9\ninstance : has_int_cast (\ud835\udd4e R) := \u27e8int.cast_def\u27e9\n\nend ring_operations\n\nsection witt_structure_simplifications\n\n@[simp] lemma witt_zero_eq_zero (n : \u2115) : witt_zero p n = 0 :=\nbegin\n  apply mv_polynomial.map_injective (int.cast_ring_hom \u211a) int.cast_injective,\n  simp only [witt_zero, witt_structure_rat, bind\u2081, aeval_zero',\n    constant_coeff_X_in_terms_of_W, ring_hom.map_zero,\n    alg_hom.map_zero, map_witt_structure_int],\nend\n\n@[simp] lemma witt_one_zero_eq_one : witt_one p 0 = 1 :=\nbegin\n  apply mv_polynomial.map_injective (int.cast_ring_hom \u211a) int.cast_injective,\n  simp only [witt_one, witt_structure_rat, X_in_terms_of_W_zero, alg_hom.map_one,\n    ring_hom.map_one, bind\u2081_X_right, map_witt_structure_int]\nend\n\n@[simp] lemma witt_one_pos_eq_zero (n : \u2115) (hn : 0 < n) : witt_one p n = 0 :=\nbegin\n  apply mv_polynomial.map_injective (int.cast_ring_hom \u211a) int.cast_injective,\n  simp only [witt_one, witt_structure_rat, ring_hom.map_zero, alg_hom.map_one,\n    ring_hom.map_one, map_witt_structure_int],\n  revert hn, apply nat.strong_induction_on n, clear n,\n  intros n IH hn,\n  rw X_in_terms_of_W_eq,\n  simp only [alg_hom.map_mul, alg_hom.map_sub, alg_hom.map_sum, alg_hom.map_pow,\n    bind\u2081_X_right, bind\u2081_C_right],\n  rw [sub_mul, one_mul],\n  rw [finset.sum_eq_single 0],\n  { simp only [inv_of_eq_inv, one_mul, inv_pow, tsub_zero, ring_hom.map_one, pow_zero],\n    simp only [one_pow, one_mul, X_in_terms_of_W_zero, sub_self, bind\u2081_X_right] },\n  { intros i hin hi0,\n    rw [finset.mem_range] at hin,\n    rw [IH _ hin (nat.pos_of_ne_zero hi0), zero_pow (pow_pos hp.1.pos _), mul_zero], },\n  { rw finset.mem_range, intro, contradiction }\nend\n\n@[simp] lemma witt_add_zero : witt_add p 0 = X (0,0) + X (1,0) :=\nbegin\n  apply mv_polynomial.map_injective (int.cast_ring_hom \u211a) int.cast_injective,\n  simp only [witt_add, witt_structure_rat, alg_hom.map_add, ring_hom.map_add,\n    rename_X, X_in_terms_of_W_zero, map_X,\n     witt_polynomial_zero, bind\u2081_X_right, map_witt_structure_int],\nend\n\n@[simp] lemma witt_sub_zero : witt_sub p 0 = X (0,0) - X (1,0) :=\nbegin\n  apply mv_polynomial.map_injective (int.cast_ring_hom \u211a) int.cast_injective,\n  simp only [witt_sub, witt_structure_rat, alg_hom.map_sub, ring_hom.map_sub,\n    rename_X, X_in_terms_of_W_zero, map_X,\n     witt_polynomial_zero, bind\u2081_X_right, map_witt_structure_int],\nend\n\n@[simp] lemma witt_mul_zero : witt_mul p 0 = X (0,0) * X (1,0) :=\nbegin\n  apply mv_polynomial.map_injective (int.cast_ring_hom \u211a) int.cast_injective,\n  simp only [witt_mul, witt_structure_rat, rename_X, X_in_terms_of_W_zero, map_X,\n    witt_polynomial_zero, ring_hom.map_mul,\n    bind\u2081_X_right, alg_hom.map_mul, map_witt_structure_int]\nend\n\n@[simp] lemma witt_neg_zero : witt_neg p 0 = - X (0,0) :=\nbegin\n  apply mv_polynomial.map_injective (int.cast_ring_hom \u211a) int.cast_injective,\n  simp only [witt_neg, witt_structure_rat, rename_X, X_in_terms_of_W_zero, map_X,\n    witt_polynomial_zero, ring_hom.map_neg,\n   alg_hom.map_neg, bind\u2081_X_right, map_witt_structure_int]\nend\n\n@[simp] lemma constant_coeff_witt_add (n : \u2115) :\n  constant_coeff (witt_add p n) = 0 :=\nbegin\n  apply constant_coeff_witt_structure_int p _ _ n,\n  simp only [add_zero, ring_hom.map_add, constant_coeff_X],\nend\n\n@[simp] lemma constant_coeff_witt_sub (n : \u2115) :\n  constant_coeff (witt_sub p n) = 0 :=\nbegin\n  apply constant_coeff_witt_structure_int p _ _ n,\n  simp only [sub_zero, ring_hom.map_sub, constant_coeff_X],\nend\n\n@[simp] lemma constant_coeff_witt_mul (n : \u2115) :\n  constant_coeff (witt_mul p n) = 0 :=\nbegin\n  apply constant_coeff_witt_structure_int p _ _ n,\n  simp only [mul_zero, ring_hom.map_mul, constant_coeff_X],\nend\n\n@[simp] lemma constant_coeff_witt_neg (n : \u2115) :\n  constant_coeff (witt_neg p n) = 0 :=\nbegin\n  apply constant_coeff_witt_structure_int p _ _ n,\n  simp only [neg_zero, ring_hom.map_neg, constant_coeff_X],\nend\n\n@[simp] lemma constant_coeff_witt_nsmul (m : \u2115) (n : \u2115):\n  constant_coeff (witt_nsmul p m n) = 0 :=\nbegin\n  apply constant_coeff_witt_structure_int p _ _ n,\n  simp only [smul_zero, map_nsmul, constant_coeff_X],\nend\n\n@[simp] lemma constant_coeff_witt_zsmul (z : \u2124) (n : \u2115):\n  constant_coeff (witt_zsmul p z n) = 0 :=\nbegin\n  apply constant_coeff_witt_structure_int p _ _ n,\n  simp only [smul_zero, map_zsmul, constant_coeff_X],\nend\n\nend witt_structure_simplifications\n\nsection coeff\n\nvariables (p R)\n\n@[simp] lemma zero_coeff (n : \u2115) : (0 : \ud835\udd4e R).coeff n = 0 :=\nshow (aeval _ (witt_zero p n) : R) = 0,\nby simp only [witt_zero_eq_zero, alg_hom.map_zero]\n\n@[simp] lemma one_coeff_zero : (1 : \ud835\udd4e R).coeff 0 = 1 :=\nshow (aeval _ (witt_one p 0) : R) = 1,\nby simp only [witt_one_zero_eq_one, alg_hom.map_one]\n\n@[simp] lemma one_coeff_eq_of_pos (n : \u2115) (hn : 0 < n) : coeff (1 : \ud835\udd4e R) n = 0 :=\nshow (aeval _ (witt_one p n) : R) = 0,\nby simp only [hn, witt_one_pos_eq_zero, alg_hom.map_zero]\n\nvariables {p R}\n\nomit hp\n@[simp]\nlemma v2_coeff {p' R'} (x y : witt_vector p' R') (i : fin 2) :\n  (![x, y] i).coeff = ![x.coeff, y.coeff] i :=\nby fin_cases i; simp\ninclude hp\n\nlemma add_coeff (x y : \ud835\udd4e R) (n : \u2115) :\n  (x + y).coeff n = peval (witt_add p n) ![x.coeff, y.coeff] :=\nby simp [(+), eval]\n\nlemma sub_coeff (x y : \ud835\udd4e R) (n : \u2115) :\n  (x - y).coeff n = peval (witt_sub p n) ![x.coeff, y.coeff] :=\nby simp [has_sub.sub, eval]\n\nlemma mul_coeff (x y : \ud835\udd4e R) (n : \u2115) :\n  (x * y).coeff n = peval (witt_mul p n) ![x.coeff, y.coeff] :=\nby simp [(*), eval]\n\nlemma neg_coeff (x : \ud835\udd4e R) (n : \u2115) :\n  (-x).coeff n = peval (witt_neg p n) ![x.coeff] :=\nby simp [has_neg.neg, eval, matrix.cons_fin_one]\n\nlemma nsmul_coeff (m : \u2115) (x : \ud835\udd4e R) (n : \u2115) :\n  (m \u2022 x).coeff n = peval (witt_nsmul p m n) ![x.coeff] :=\nby simp [has_smul.smul, eval, matrix.cons_fin_one]\n\nlemma zsmul_coeff (m : \u2124) (x : \ud835\udd4e R) (n : \u2115) :\n  (m \u2022 x).coeff n = peval (witt_zsmul p m n) ![x.coeff] :=\nby simp [has_smul.smul, eval, matrix.cons_fin_one]\n\nlemma pow_coeff (m : \u2115) (x : \ud835\udd4e R) (n : \u2115) :\n  (x ^ m).coeff n = peval (witt_pow p m n) ![x.coeff] :=\nby simp [has_pow.pow, eval, matrix.cons_fin_one]\n\nlemma add_coeff_zero (x y : \ud835\udd4e R) : (x + y).coeff 0 = x.coeff 0 + y.coeff 0 :=\nby simp [add_coeff, peval]\n\nlemma mul_coeff_zero (x y : \ud835\udd4e R) : (x * y).coeff 0 = x.coeff 0 * y.coeff 0 :=\nby simp [mul_coeff, peval]\n\nend coeff\n\nlemma witt_add_vars (n : \u2115) : (witt_add p n).vars \u2286 finset.univ \u00d7\u02e2 finset.range (n + 1) :=\nwitt_structure_int_vars _ _ _\n\nlemma witt_sub_vars (n : \u2115) : (witt_sub p n).vars \u2286 finset.univ \u00d7\u02e2 finset.range (n + 1) :=\nwitt_structure_int_vars _ _ _\n\nlemma witt_mul_vars (n : \u2115) : (witt_mul p n).vars \u2286 finset.univ \u00d7\u02e2 finset.range (n + 1) :=\nwitt_structure_int_vars _ _ _\n\nlemma witt_neg_vars (n : \u2115) : (witt_neg p n).vars \u2286 finset.univ \u00d7\u02e2 finset.range (n + 1) :=\nwitt_structure_int_vars _ _ _\n\nlemma witt_nsmul_vars (m : \u2115) (n : \u2115) :\n  (witt_nsmul p m n).vars \u2286 finset.univ \u00d7\u02e2 finset.range (n + 1) :=\nwitt_structure_int_vars _ _ _\n\n\n\nlemma witt_pow_vars (m : \u2115) (n : \u2115) :\n  (witt_pow p m n).vars \u2286 finset.univ \u00d7\u02e2 finset.range (n + 1) :=\nwitt_structure_int_vars _ _ _\n\nend witt_vector\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/witt_vector/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7131096537690506}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.vector_bundle.basic\nimport geometry.manifold.smooth_manifold_with_corners\nimport data.set.prod\n\n/-!\n# Basic smooth bundles\n\nIn general, a smooth bundle is a bundle over a smooth manifold, whose fiber is a manifold, and\nfor which the coordinate changes are smooth. In this definition, there are charts involved at\nseveral places: in the manifold structure of the base, in the manifold structure of the fibers, and\nin the local trivializations. This makes it a complicated object in general. There is however a\nspecific situation where things are much simpler: when the fiber is a vector space (no need for\ncharts for the fibers), and when the local trivializations of the bundle and the charts of the base\ncoincide. Then everything is expressed in terms of the charts of the base, making for a much\nsimpler overall structure, which is easier to manipulate formally.\n\nMost vector bundles that naturally occur in differential geometry are of this form:\nthe tangent bundle, the cotangent bundle, differential forms (used to define de Rham cohomology)\nand the bundle of Riemannian metrics. Therefore, it is worth defining a specific constructor for\nthis kind of bundle, that we call basic smooth bundles.\n\nA basic smooth bundle is thus a smooth bundle over a smooth manifold whose fiber is a vector space,\nand which is trivial in the coordinate charts of the base. (We recall that in our notion of manifold\nthere is a distinguished atlas, which does not need to be maximal: we require the triviality above\nthis specific atlas). It can be constructed from a basic smooth bundled core, defined below,\nspecifying the changes in the fiber when one goes from one coordinate chart to another one.\n\n## Main definitions\n\n* `basic_smooth_vector_bundle_core I M F`: assuming that `M` is a smooth manifold over the model\n  with corners `I` on `(\ud835\udd5c, E, H)`, and `F` is a normed vector space over `\ud835\udd5c`, this structure\n  registers, for each pair of charts of `M`, a linear change of coordinates on `F` depending\n  smoothly on the base point. This is the core structure from which one will build a smooth vector\n  bundle with fiber `F` over `M`.\n\nLet `Z` be a basic smooth bundle core over `M` with fiber `F`. We define\n`Z.to_topological_vector_bundle_core`, the (topological) vector bundle core associated to `Z`. From\nit, we get a space `Z.to_topological_vector_bundle_core.total_space` (which as a Type is just\n`\u03a3 (x : M), F`), with the fiber bundle topology. It inherits a manifold structure (where the\ncharts are in bijection with the charts of the basis). We show that this manifold is smooth.\n\nThen we use this machinery to construct the tangent bundle of a smooth manifold.\n\n* `tangent_bundle_core I M`: the basic smooth bundle core associated to a smooth manifold `M` over\n  a model with corners `I`.\n* `tangent_bundle I M`     : the total space of `tangent_bundle_core I M`. It is itself a\n  smooth manifold over the model with corners `I.tangent`, the product of `I` and the trivial model\n  with corners on `E`.\n* `tangent_space I x`      : the tangent space to `M` at `x`\n* `tangent_bundle.proj I M`: the projection from the tangent bundle to the base manifold\n\n## Implementation notes\n\nWe register the vector space structure on the fibers of the tangent bundle, but we do not register\nthe normed space structure coming from that of `F` (as it is not canonical, and we also want to\nkeep the possibility to add a Riemannian structure on the manifold later on without having two\ncompeting normed space instances on the tangent spaces).\n\nWe require `F` to be a normed space, and not just a topological vector space, as we want to talk\nabout smooth functions on `F`. The notion of derivative requires a norm to be defined.\n\n## TODO\nconstruct the cotangent bundle, and the bundles of differential forms. They should follow\nfunctorially from the description of the tangent bundle as a basic smooth bundle.\n\n## Tags\nSmooth fiber bundle, vector bundle, tangent space, tangent bundle\n-/\nnoncomputable theory\n\nuniverse u\n\nopen topological_space set\nopen_locale manifold topological_space\n\n/-- Core structure used to create a smooth bundle above `M` (a manifold over the model with\ncorner `I`) with fiber the normed vector space `F` over `\ud835\udd5c`, which is trivial in the chart domains\nof `M`. This structure registers the changes in the fibers when one changes coordinate charts in the\nbase. We require the change of coordinates of the fibers to be linear, so that the resulting bundle\nis a vector bundle. -/\nstructure basic_smooth_vector_bundle_core {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n(F : Type*) [normed_group F] [normed_space \ud835\udd5c F] :=\n(coord_change      : atlas H M \u2192 atlas H M \u2192 H \u2192 (F \u2192L[\ud835\udd5c] F))\n(coord_change_self : \u2200 i : atlas H M, \u2200 x \u2208 i.1.target, \u2200 v, coord_change i i x v = v)\n(coord_change_comp : \u2200 i j k : atlas H M,\n  \u2200 x \u2208 ((i.1.symm.trans j.1).trans (j.1.symm.trans k.1)).source, \u2200 v,\n  (coord_change j k ((i.1.symm.trans j.1) x)) (coord_change i j x v) = coord_change i k x v)\n(coord_change_smooth_clm : \u2200 i j : atlas H M,\n  cont_diff_on \ud835\udd5c \u221e ((coord_change i j) \u2218 I.symm) (I '' (i.1.symm.trans j.1).source))\n\n/-- The trivial basic smooth bundle core, in which all the changes of coordinates are the\nidentity. -/\ndef trivial_basic_smooth_vector_bundle_core {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n(F : Type*) [normed_group F] [normed_space \ud835\udd5c F] : basic_smooth_vector_bundle_core I M F :=\n{ coord_change := \u03bb i j x, continuous_linear_map.id \ud835\udd5c F,\n  coord_change_self := \u03bb i x hx v, rfl,\n  coord_change_comp := \u03bb i j k x hx v, rfl,\n  coord_change_smooth_clm := \u03bb i j, by { dsimp, exact cont_diff_on_const } }\n\nnamespace basic_smooth_vector_bundle_core\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] {I : model_with_corners \ud835\udd5c E H}\n{M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n{F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\n(Z : basic_smooth_vector_bundle_core I M F)\n\ninstance : inhabited (basic_smooth_vector_bundle_core I M F) :=\n\u27e8trivial_basic_smooth_vector_bundle_core I M F\u27e9\n\nlemma coord_change_continuous (i j : atlas H M) :\n  continuous_on (Z.coord_change i j) (i.1.symm.trans j.1).source :=\nbegin\n  assume x hx,\n  apply (((Z.coord_change_smooth_clm i j).continuous_on.continuous_within_at\n    (mem_image_of_mem I hx)).comp I.continuous_within_at _).congr,\n  { assume y hy,\n    simp only with mfld_simps },\n  { simp only with mfld_simps },\n  { exact maps_to_image I _ },\nend\n\nlemma coord_change_smooth (i j : atlas H M) :\n  cont_diff_on \ud835\udd5c \u221e (\u03bb p : E \u00d7 F, Z.coord_change i j (I.symm p.1) p.2)\n    ((I '' (i.1.symm.trans j.1).source) \u00d7\u02e2 (univ : set F)) :=\nbegin\n  have A : cont_diff \ud835\udd5c \u221e (\u03bb p : (F \u2192L[\ud835\udd5c] F) \u00d7 F, p.1 p.2),\n  { apply is_bounded_bilinear_map.cont_diff,\n    exact is_bounded_bilinear_map_apply },\n  have B : cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F), (Z.coord_change i j (I.symm p.1), p.snd))\n    ((I '' (i.1.symm.trans j.1).source) \u00d7\u02e2 (univ : set F)),\n  { apply cont_diff_on.prod _ _,\n    { exact (Z.coord_change_smooth_clm i j).comp cont_diff_fst.cont_diff_on\n       (prod_subset_preimage_fst _ _) },\n    { exact is_bounded_linear_map.snd.cont_diff.cont_diff_on } },\n  exact A.comp_cont_diff_on B,\nend\n\n/-- Vector bundle core associated to a basic smooth bundle core -/\ndef to_topological_vector_bundle_core : topological_vector_bundle_core \ud835\udd5c M F (atlas H M) :=\n{ base_set := \u03bb i, i.1.source,\n  is_open_base_set := \u03bb i, i.1.open_source,\n  index_at := \u03bb x, \u27e8chart_at H x, chart_mem_atlas H x\u27e9,\n  mem_base_set_at := \u03bb x, mem_chart_source H x,\n  coord_change := \u03bb i j x, Z.coord_change i j (i.1 x),\n  coord_change_self := \u03bb i x hx v, Z.coord_change_self i (i.1 x) (i.1.map_source hx) v,\n  coord_change_comp := \u03bb i j k x \u27e8\u27e8hx1, hx2\u27e9, hx3\u27e9 v, begin\n    have := Z.coord_change_comp i j k (i.1 x) _ v,\n    convert this using 2,\n    { simp only [hx1] with mfld_simps },\n    { simp only [hx1, hx2, hx3] with mfld_simps }\n  end,\n  coord_change_continuous := \u03bb i j, begin\n    refine ((Z.coord_change_continuous i j).comp' i.1.continuous_on).mono _,\n    rintros p \u27e8hp\u2081, hp\u2082\u27e9,\n    refine \u27e8hp\u2081, i.1.maps_to hp\u2081, _\u27e9,\n    simp only [i.1.left_inv hp\u2081, hp\u2082] with mfld_simps\n  end }\n\n@[simp, mfld_simps] lemma base_set (i : atlas H M) :\n  (Z.to_topological_vector_bundle_core.local_triv i).base_set = i.1.source := rfl\n\n@[simp, mfld_simps] lemma target (i : atlas H M) :\n  (Z.to_topological_vector_bundle_core.local_triv i).target = i.1.source \u00d7\u02e2 (univ : set F) := rfl\n\n/-- Local chart for the total space of a basic smooth bundle -/\ndef chart {e : local_homeomorph M H} (he : e \u2208 atlas H M) :\n  local_homeomorph (Z.to_topological_vector_bundle_core.total_space) (model_prod H F) :=\n(Z.to_topological_vector_bundle_core.local_triv \u27e8e, he\u27e9).to_local_homeomorph.trans\n  (local_homeomorph.prod e (local_homeomorph.refl F))\n\n@[simp, mfld_simps] lemma chart_source (e : local_homeomorph M H) (he : e \u2208 atlas H M) :\n  (Z.chart he).source = Z.to_topological_vector_bundle_core.proj \u207b\u00b9' e.source :=\nby { simp only [chart, mem_prod], mfld_set_tac }\n\n@[simp, mfld_simps] lemma chart_target (e : local_homeomorph M H) (he : e \u2208 atlas H M) :\n  (Z.chart he).target = e.target \u00d7\u02e2 (univ : set F) :=\nby { simp only [chart], mfld_set_tac }\n\n/-- The total space of a basic smooth bundle is endowed with a charted space structure, where the\ncharts are in bijection with the charts of the basis. -/\ninstance to_charted_space :\n  charted_space (model_prod H F) Z.to_topological_vector_bundle_core.total_space :=\n{ atlas := \u22c3(e : local_homeomorph M H) (he : e \u2208 atlas H M), {Z.chart he},\n  chart_at := \u03bb p, Z.chart (chart_mem_atlas H p.1),\n  mem_chart_source := \u03bb p, by simp [mem_chart_source],\n  chart_mem_atlas := \u03bb p, begin\n    simp only [mem_Union, mem_singleton_iff, chart_mem_atlas],\n    exact \u27e8chart_at H p.1, chart_mem_atlas H p.1, rfl\u27e9\n  end }\n\nlemma mem_atlas_iff\n  (f : local_homeomorph Z.to_topological_vector_bundle_core.total_space (model_prod H F)) :\n  f \u2208 atlas (model_prod H F) Z.to_topological_vector_bundle_core.total_space \u2194\n  \u2203(e : local_homeomorph M H) (he : e \u2208 atlas H M), f = Z.chart he :=\nby simp only [atlas, mem_Union, mem_singleton_iff]\n\n@[simp, mfld_simps] lemma mem_chart_source_iff\n  (p q : Z.to_topological_vector_bundle_core.total_space) :\n  p \u2208 (chart_at (model_prod H F) q).source \u2194 p.1 \u2208 (chart_at H q.1).source :=\nby simp only [chart_at] with mfld_simps\n\n@[simp, mfld_simps] lemma mem_chart_target_iff\n  (p : H \u00d7 F) (q : Z.to_topological_vector_bundle_core.total_space) :\n  p \u2208 (chart_at (model_prod H F) q).target \u2194 p.1 \u2208 (chart_at H q.1).target :=\nby simp only [chart_at] with mfld_simps\n\n@[simp, mfld_simps] lemma coe_chart_at_fst (p q : Z.to_topological_vector_bundle_core.total_space) :\n  ((chart_at (model_prod H F) q) p).1 = chart_at H q.1 p.1 := rfl\n\n@[simp, mfld_simps] lemma coe_chart_at_symm_fst\n  (p : H \u00d7 F) (q : Z.to_topological_vector_bundle_core.total_space) :\n  ((chart_at (model_prod H F) q).symm p).1 = ((chart_at H q.1).symm : H \u2192 M) p.1 := rfl\n\n/-- Smooth manifold structure on the total space of a basic smooth bundle -/\ninstance to_smooth_manifold :\n  smooth_manifold_with_corners (I.prod (\ud835\udcd8(\ud835\udd5c, F))) Z.to_topological_vector_bundle_core.total_space :=\nbegin\n  /- We have to check that the charts belong to the smooth groupoid, i.e., they are smooth on their\n  source, and their inverses are smooth on the target. Since both objects are of the same kind, it\n  suffices to prove the first statement in A below, and then glue back the pieces at the end. -/\n  let J := model_with_corners.to_local_equiv (I.prod (\ud835\udcd8(\ud835\udd5c, F))),\n  have A : \u2200 (e e' : local_homeomorph M H) (he : e \u2208 atlas H M) (he' : e' \u2208 atlas H M),\n    cont_diff_on \ud835\udd5c \u221e\n    (J \u2218 ((Z.chart he).symm.trans (Z.chart he')) \u2218 J.symm)\n    (J.symm \u207b\u00b9' ((Z.chart he).symm.trans (Z.chart he')).source \u2229 range J),\n  { assume e e' he he',\n    have : J.symm \u207b\u00b9' ((chart Z he).symm.trans (chart Z he')).source \u2229 range J =\n      (I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F),\n      by { simp only [J, chart, model_with_corners.prod], mfld_set_tac },\n    rw this,\n    -- check separately that the two components of the coordinate change are smooth\n    apply cont_diff_on.prod,\n    show cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F), (I \u2218 e' \u2218 e.symm \u2218 I.symm) p.1)\n         ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F)),\n    { -- the coordinate change on the base is just a coordinate change for `M`, smooth since\n      -- `M` is smooth\n      have A : cont_diff_on \ud835\udd5c \u221e (I \u2218 (e.symm.trans e') \u2218 I.symm)\n        (I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) :=\n      (has_groupoid.compatible (cont_diff_groupoid \u221e I) he he').1,\n      have B : cont_diff_on \ud835\udd5c \u221e (\u03bb p : E \u00d7 F, p.1)\n        ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F)) :=\n      cont_diff_fst.cont_diff_on,\n      exact cont_diff_on.comp A B (prod_subset_preimage_fst _ _) },\n    show cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F),\n      Z.coord_change \u27e8chart_at H (e.symm (I.symm p.1)), _\u27e9 \u27e8e', he'\u27e9\n         ((chart_at H (e.symm (I.symm p.1)) : M \u2192 H) (e.symm (I.symm p.1)))\n      (Z.coord_change \u27e8e, he\u27e9 \u27e8chart_at H (e.symm (I.symm p.1)), _\u27e9\n        (e (e.symm (I.symm p.1))) p.2))\n      ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) \u00d7\u02e2 (univ : set F)),\n    { /- The coordinate change in the fiber is more complicated as its definition involves the\n      reference chart chosen at each point. However, it appears with its inverse, so using the\n      cocycle property one can get rid of it, and then conclude using the smoothness of the\n      cocycle as given in the definition of basic smooth bundles. -/\n      have := Z.coord_change_smooth \u27e8e, he\u27e9 \u27e8e', he'\u27e9,\n      rw I.image_eq at this,\n      apply cont_diff_on.congr this,\n      rintros \u27e8x, v\u27e9 hx,\n      simp only with mfld_simps at hx,\n      let f := chart_at H (e.symm (I.symm x)),\n      have A : I.symm x \u2208 ((e.symm.trans f).trans (f.symm.trans e')).source,\n        by simp only [hx.1.1, hx.1.2] with mfld_simps,\n      rw e.right_inv hx.1.1,\n      have := Z.coord_change_comp \u27e8e, he\u27e9 \u27e8f, chart_mem_atlas _ _\u27e9 \u27e8e', he'\u27e9 (I.symm x) A v,\n      simpa only [] using this } },\n  refine @smooth_manifold_with_corners.mk _ _ _ _ _ _ _ _ _ _ _ \u27e8_\u27e9,\n  assume e\u2080 e\u2080' he\u2080 he\u2080',\n  rcases (Z.mem_atlas_iff _).1 he\u2080 with \u27e8e, he, rfl\u27e9,\n  rcases (Z.mem_atlas_iff _).1 he\u2080' with \u27e8e', he', rfl\u27e9,\n  rw [cont_diff_groupoid, mem_groupoid_of_pregroupoid],\n  exact \u27e8A e e' he he', A e' e he' he\u27e9\nend\n\nend basic_smooth_vector_bundle_core\n\nsection tangent_bundle\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n\n/-- Basic smooth bundle core version of the tangent bundle of a smooth manifold `M` modelled over a\nmodel with corners `I` on `(E, H)`. The fibers are equal to `E`, and the coordinate change in the\nfiber corresponds to the derivative of the coordinate change in `M`. -/\ndef tangent_bundle_core : basic_smooth_vector_bundle_core I M E :=\n{ coord_change := \u03bb i j x, (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x)),\n  coord_change_smooth_clm := \u03bb i j,\n  begin\n    rw I.image_eq,\n    have A : cont_diff_on \ud835\udd5c \u221e\n      (I \u2218 (i.1.symm.trans j.1) \u2218 I.symm)\n      (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n      (has_groupoid.compatible (cont_diff_groupoid \u221e I) i.2 j.2).1,\n    have B : unique_diff_on \ud835\udd5c (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n      I.unique_diff_preimage_source,\n    have C : cont_diff_on \ud835\udd5c \u221e\n      (\u03bb (p : E \u00d7 E), (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) p.1 : E \u2192 E) p.2)\n      ((I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) \u00d7\u02e2 (univ : set E)) :=\n      cont_diff_on_fderiv_within_apply A B le_top,\n    have D : \u2200 x \u2208 (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I),\n      fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (range I) x =\n      fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) x,\n    { assume x hx,\n      have N : I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2208 nhds x :=\n        I.continuous_symm.continuous_at.preimage_mem_nhds\n          (is_open.mem_nhds (local_homeomorph.open_source _) hx.1),\n      symmetry,\n      rw inter_comm,\n      exact fderiv_within_inter N (I.unique_diff _ hx.2) },\n    apply (A.fderiv_within B le_top).congr,\n    assume x hx,\n    simp only with mfld_simps at hx,\n    simp only [hx, D] with mfld_simps,\n  end,\n  coord_change_self := \u03bb i x hx v, begin\n    /- Locally, a self-change of coordinate is just the identity, thus its derivative is the\n    identity. One just needs to write this carefully, paying attention to the sets where the\n    functions are defined. -/\n    have A : I.symm \u207b\u00b9' (i.1.symm.trans i.1).source \u2229 range I \u2208 \ud835\udcdd[range I] (I x),\n    { rw inter_comm,\n      apply inter_mem_nhds_within,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simp only [hx, i.1.map_target] with mfld_simps },\n    have B : \u2200\u1da0 y in \ud835\udcdd[range I] (I x),\n      (I \u2218 i.1 \u2218 i.1.symm \u2218 I.symm) y = (id : E \u2192 E) y,\n    { filter_upwards [A] with _ hy,\n      rw \u2190 I.image_eq at hy,\n      rcases hy with \u27e8z, hz\u27e9,\n      simp only with mfld_simps at hz,\n      simp only [hz.2.symm, hz.1] with mfld_simps, },\n    have C : fderiv_within \ud835\udd5c (I \u2218 i.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x) =\n             fderiv_within \ud835\udd5c (id : E \u2192 E) (range I) (I x) :=\n      filter.eventually_eq.fderiv_within_eq I.unique_diff_at_image B\n      (by simp only [hx] with mfld_simps),\n    rw fderiv_within_id I.unique_diff_at_image at C,\n    rw C,\n    refl\n  end,\n  coord_change_comp := \u03bb i j u x hx, begin\n    /- The cocycle property is just the fact that the derivative of a composition is the product of\n    the derivatives. One needs however to check that all the functions one considers are smooth, and\n    to pay attention to the domains where these functions are defined, making this proof a little\n    bit cumbersome although there is nothing complicated here. -/\n    have M : I x \u2208\n      (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I) :=\n    \u27e8by simpa only [mem_preimage, model_with_corners.left_inv] using hx, mem_range_self _\u27e9,\n    have U : unique_diff_within_at \ud835\udd5c\n      (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I) (I x) :=\n      I.unique_diff_preimage_source _ M,\n    have A : fderiv_within \ud835\udd5c ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm))\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)\n      = (fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I)\n             ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x))).comp\n        (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)),\n    { apply fderiv_within.comp _ _ _ _ U,\n      show differentiable_within_at \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n        (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n        (I x),\n      { have A : cont_diff_on \ud835\udd5c \u221e\n          (I \u2218 (i.1.symm.trans j.1) \u2218 I.symm)\n          (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n        (has_groupoid.compatible (cont_diff_groupoid \u221e I) i.2 j.2).1,\n        have B : differentiable_on \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n          (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I),\n        { apply (A.differentiable_on le_top).mono,\n          have : ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2286\n            (i.1.symm.trans j.1).source := inter_subset_left _ _,\n          exact inter_subset_inter (preimage_mono this) (subset.refl (range I)) },\n        apply B,\n        simpa only [] with mfld_simps using hx },\n      show differentiable_within_at \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n        (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I)\n        ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)),\n      { have A : cont_diff_on \ud835\udd5c \u221e\n          (I \u2218 (j.1.symm.trans u.1) \u2218 I.symm)\n          (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I) :=\n        (has_groupoid.compatible (cont_diff_groupoid \u221e I) j.2 u.2).1,\n        apply A.differentiable_on le_top,\n        rw [local_homeomorph.trans_source] at hx,\n        simp only with mfld_simps,\n        exact hx.2 },\n      show (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n        \u2286 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) \u207b\u00b9' (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I),\n      { assume y hy,\n        simp only with mfld_simps at hy,\n        rw [local_homeomorph.left_inv] at hy,\n        { simp only [hy] with mfld_simps },\n        { exact hy.1.1.2 } } },\n    have B : fderiv_within \ud835\udd5c ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n                          \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm))\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)\n             = fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x),\n    { have E :\n        \u2200 y \u2208 (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I),\n          ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)) y =\n            (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm) y,\n      { assume y hy,\n        simp only [function.comp_app, model_with_corners.left_inv],\n        rw [j.1.left_inv],\n        exact hy.1.1.2 },\n      exact fderiv_within_congr U E (E _ M) },\n    have C : fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x) =\n             fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (range I) (I x),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simpa only [model_with_corners.left_inv] using hx },\n    have D : fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n      (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I) ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)) =\n      fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) (range I) ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      rw [local_homeomorph.trans_source] at hx,\n      simp only with mfld_simps,\n      exact hx.2 },\n    have E : fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n               (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n               (I x) =\n             fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simpa only [model_with_corners.left_inv] using hx },\n    rw [B, C, D, E] at A,\n    simp only [A, continuous_linear_map.coe_comp'] with mfld_simps,\n  end }\n\nvariable {M}\ninclude I\n\n/-- The tangent space at a point of the manifold `M`. It is just `E`. We could use instead\n`(tangent_bundle_core I M).to_topological_vector_bundle_core.fiber x`, but we use `E` to help the\nkernel.\n-/\n@[nolint unused_arguments]\ndef tangent_space (x : M) : Type* := E\n\nomit I\nvariable (M)\n\n/-- The tangent bundle to a smooth manifold, as a Sigma type. Defined in terms of\n`bundle.total_space` to be able to put a suitable topology on it. -/\n@[nolint has_inhabited_instance, reducible] -- is empty if the base manifold is empty\ndef tangent_bundle := bundle.total_space (tangent_space I : M \u2192 Type*)\n\nlocal notation `TM` := tangent_bundle I M\n\n/-- The projection from the tangent bundle of a smooth manifold to the manifold. As the tangent\nbundle is represented internally as a sigma type, the notation `p.1` also works for the projection\nof the point `p`. -/\ndef tangent_bundle.proj : TM \u2192 M :=\n\u03bb p, p.1\n\nvariable {M}\n\n@[simp, mfld_simps] lemma tangent_bundle.proj_apply (x : M) (v : tangent_space I x) :\n  tangent_bundle.proj I M \u27e8x, v\u27e9 = x :=\nrfl\n\nsection tangent_bundle_instances\n\n/- In general, the definition of tangent_bundle and tangent_space are not reducible, so that type\nclass inference does not pick wrong instances. In this section, we record the right instances for\nthem, noting in particular that the tangent bundle is a smooth manifold. -/\n\nsection\nlocal attribute [reducible] tangent_space\n\nvariables {M} (x : M)\n\ninstance : topological_space (tangent_space I x) := by apply_instance\ninstance : add_comm_group (tangent_space I x) := by apply_instance\ninstance : topological_add_group (tangent_space I x) := by apply_instance\ninstance : module \ud835\udd5c (tangent_space I x) := by apply_instance\ninstance : inhabited (tangent_space I x) := \u27e80\u27e9\n\nend\n\nvariable (M)\n\ninstance : topological_space TM :=\n(tangent_bundle_core I M).to_topological_vector_bundle_core.to_topological_space (atlas H M)\n\ninstance : charted_space (model_prod H E) TM :=\n(tangent_bundle_core I M).to_charted_space\n\ninstance : smooth_manifold_with_corners I.tangent TM :=\n(tangent_bundle_core I M).to_smooth_manifold\n\ninstance : topological_vector_bundle \ud835\udd5c E (tangent_space I : M \u2192 Type*) :=\ntopological_vector_bundle_core.fiber.topological_vector_bundle\n  (tangent_bundle_core I M).to_topological_vector_bundle_core\n\nend tangent_bundle_instances\n\nvariable (M)\n\n/-- The tangent bundle projection on the basis is a continuous map. -/\nlemma tangent_bundle_proj_continuous : continuous (tangent_bundle.proj I M) :=\n((tangent_bundle_core I M).to_topological_vector_bundle_core).continuous_proj\n\n/-- The tangent bundle projection on the basis is an open map. -/\nlemma tangent_bundle_proj_open : is_open_map (tangent_bundle.proj I M) :=\n((tangent_bundle_core I M).to_topological_vector_bundle_core).is_open_map_proj\n\n/-- In the tangent bundle to the model space, the charts are just the canonical identification\nbetween a product type and a sigma type, a.k.a. `equiv.sigma_equiv_prod`. -/\n@[simp, mfld_simps] lemma tangent_bundle_model_space_chart_at (p : tangent_bundle I H) :\n  (chart_at (model_prod H E) p).to_local_equiv = (equiv.sigma_equiv_prod H E).to_local_equiv :=\nbegin\n  have A : \u2200 x_fst, fderiv_within \ud835\udd5c (I \u2218 I.symm) (range I) (I x_fst) = continuous_linear_map.id \ud835\udd5c E,\n  { assume x_fst,\n    have : fderiv_within \ud835\udd5c (I \u2218 I.symm) (range I) (I x_fst)\n         = fderiv_within \ud835\udd5c id (range I) (I x_fst),\n    { refine fderiv_within_congr I.unique_diff_at_image (\u03bb y hy, _) (by simp),\n      exact model_with_corners.right_inv _ hy },\n    rwa fderiv_within_id I.unique_diff_at_image at this },\n  ext x : 1,\n  show (chart_at (model_prod H E) p : tangent_bundle I H \u2192 model_prod H E) x =\n    (equiv.sigma_equiv_prod H E) x,\n  { cases x,\n    simp only [chart_at, basic_smooth_vector_bundle_core.chart, tangent_bundle_core,\n      basic_smooth_vector_bundle_core.to_topological_vector_bundle_core, A, prod.mk.inj_iff,\n      continuous_linear_map.coe_id'] with mfld_simps,\n      exact (tangent_bundle_core I H).coord_change_self _ _ trivial x_snd, },\n  show \u2200 x, ((chart_at (model_prod H E) p).to_local_equiv).symm x =\n    (equiv.sigma_equiv_prod H E).symm x,\n  { rintros \u27e8x_fst, x_snd\u27e9,\n    simp only [basic_smooth_vector_bundle_core.to_topological_vector_bundle_core,\n      tangent_bundle_core, A, continuous_linear_map.coe_id', basic_smooth_vector_bundle_core.chart,\n      chart_at, continuous_linear_map.coe_coe, sigma.mk.inj_iff] with mfld_simps, },\n  show ((chart_at (model_prod H E) p).to_local_equiv).source = univ,\n    by simp only [chart_at] with mfld_simps,\nend\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at (p : tangent_bundle I H) :\n  \u21d1(chart_at (model_prod H E) p) = equiv.sigma_equiv_prod H E :=\nby { unfold_coes, simp only with mfld_simps }\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at_symm (p : tangent_bundle I H) :\n  ((chart_at (model_prod H E) p).symm : model_prod H E \u2192 tangent_bundle I H) =\n  (equiv.sigma_equiv_prod H E).symm :=\nby { unfold_coes, simp only with mfld_simps }\n\nvariable (H)\n/-- The canonical identification between the tangent bundle to the model space and the product,\nas a homeomorphism -/\ndef tangent_bundle_model_space_homeomorph : tangent_bundle I H \u2243\u209c model_prod H E :=\n{ continuous_to_fun :=\n  begin\n    let p : tangent_bundle I H := \u27e8I.symm (0 : E), (0 : E)\u27e9,\n    have : continuous (chart_at (model_prod H E) p),\n    { rw continuous_iff_continuous_on_univ,\n      convert local_homeomorph.continuous_on _,\n      simp only with mfld_simps },\n    simpa only with mfld_simps using this,\n  end,\n  continuous_inv_fun :=\n  begin\n    let p : tangent_bundle I H := \u27e8I.symm (0 : E), (0 : E)\u27e9,\n    have : continuous (chart_at (model_prod H E) p).symm,\n    { rw continuous_iff_continuous_on_univ,\n      convert local_homeomorph.continuous_on _,\n      simp only with mfld_simps },\n    simpa only with mfld_simps using this,\n  end,\n  .. equiv.sigma_equiv_prod H E }\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe :\n  (tangent_bundle_model_space_homeomorph H I : tangent_bundle I H \u2192 model_prod H E)\n  = equiv.sigma_equiv_prod H E :=\nrfl\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe_symm :\n  ((tangent_bundle_model_space_homeomorph H I).symm : model_prod H E \u2192 tangent_bundle I H)\n  = (equiv.sigma_equiv_prod H E).symm :=\nrfl\n\nend tangent_bundle\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/geometry/manifold/tangent_bundle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7130985238343011}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.limits.constructions.zero_objects\n! leanprover-community/mathlib commit 52a270e2ea4e342c2587c106f8be904524214a4b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.Limits.Shapes.Pullbacks\nimport Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms\nimport Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts\n\n/-!\n# Limits involving zero objects\n\nBinary products and coproducts with a zero object always exist,\nand pullbacks/pushouts over a zero object are products/coproducts.\n-/\n\n\nnoncomputable section\n\nopen CategoryTheory\n\nvariable {C : Type _} [Category C]\n\nnamespace CategoryTheory.Limits\n\nvariable [HasZeroObject C] [HasZeroMorphisms C]\n\nopen ZeroObject\n\n/-- The limit cone for the product with a zero object. -/\ndef binaryFanZeroLeft (X : C) : BinaryFan (0 : C) X :=\n  BinaryFan.mk 0 (\ud835\udfd9 X)\n#align category_theory.limits.binary_fan_zero_left CategoryTheory.Limits.binaryFanZeroLeft\n\n/-- The limit cone for the product with a zero object is limiting. -/\ndef binaryFanZeroLeftIsLimit (X : C) : IsLimit (binaryFanZeroLeft X) :=\n  BinaryFan.isLimitMk (fun s => BinaryFan.snd s) (by aesop_cat) (by aesop_cat)\n    (fun s m _ h\u2082 => by simpa using h\u2082)\n#align category_theory.limits.binary_fan_zero_left_is_limit CategoryTheory.Limits.binaryFanZeroLeftIsLimit\n\ninstance hasBinaryProduct_zero_left (X : C) : HasBinaryProduct (0 : C) X :=\n  HasLimit.mk \u27e8_, binaryFanZeroLeftIsLimit X\u27e9\n#align category_theory.limits.has_binary_product_zero_left CategoryTheory.Limits.hasBinaryProduct_zero_left\n\n/-- A zero object is a left unit for categorical product. -/\ndef zeroProdIso (X : C) : (0 : C) \u2a2f X \u2245 X :=\n  limit.isoLimitCone \u27e8_, binaryFanZeroLeftIsLimit X\u27e9\n#align category_theory.limits.zero_prod_iso CategoryTheory.Limits.zeroProdIso\n\n@[simp]\n\n\n@[simp]\ntheorem zeroProdIso_inv_snd (X : C) : (zeroProdIso X).inv \u226b prod.snd = \ud835\udfd9 X := by\n  dsimp [zeroProdIso, binaryFanZeroLeft]\n  simp\n#align category_theory.limits.zero_prod_iso_inv_snd CategoryTheory.Limits.zeroProdIso_inv_snd\n\n/-- The limit cone for the product with a zero object. -/\ndef binaryFanZeroRight (X : C) : BinaryFan X (0 : C) :=\n  BinaryFan.mk (\ud835\udfd9 X) 0\n#align category_theory.limits.binary_fan_zero_right CategoryTheory.Limits.binaryFanZeroRight\n\n/-- The limit cone for the product with a zero object is limiting. -/\ndef binaryFanZeroRightIsLimit (X : C) : IsLimit (binaryFanZeroRight X) :=\n  BinaryFan.isLimitMk (fun s => BinaryFan.fst s) (by aesop_cat) (by aesop_cat)\n    (fun s m h\u2081 => by simpa using h\u2081)\n#align category_theory.limits.binary_fan_zero_right_is_limit CategoryTheory.Limits.binaryFanZeroRightIsLimit\n\ninstance hasBinaryProduct_zero_right (X : C) : HasBinaryProduct X (0 : C) :=\n  HasLimit.mk \u27e8_, binaryFanZeroRightIsLimit X\u27e9\n#align category_theory.limits.has_binary_product_zero_right CategoryTheory.Limits.hasBinaryProduct_zero_right\n\n/-- A zero object is a right unit for categorical product. -/\ndef prodZeroIso (X : C) : X \u2a2f (0 : C) \u2245 X :=\n  limit.isoLimitCone \u27e8_, binaryFanZeroRightIsLimit X\u27e9\n#align category_theory.limits.prod_zero_iso CategoryTheory.Limits.prodZeroIso\n\n@[simp]\ntheorem prodZeroIso_hom (X : C) : (prodZeroIso X).hom = prod.fst :=\n  rfl\n#align category_theory.limits.prod_zero_iso_hom CategoryTheory.Limits.prodZeroIso_hom\n\n@[simp]\ntheorem prodZeroIso_iso_inv_snd (X : C) : (prodZeroIso X).inv \u226b prod.fst = \ud835\udfd9 X := by\n  dsimp [prodZeroIso, binaryFanZeroRight]\n  simp\n#align category_theory.limits.prod_zero_iso_iso_inv_snd CategoryTheory.Limits.prodZeroIso_iso_inv_snd\n\n/-- The colimit cocone for the coproduct with a zero object. -/\ndef binaryCofanZeroLeft (X : C) : BinaryCofan (0 : C) X :=\n  BinaryCofan.mk 0 (\ud835\udfd9 X)\n#align category_theory.limits.binary_cofan_zero_left CategoryTheory.Limits.binaryCofanZeroLeft\n\n/-- The colimit cocone for the coproduct with a zero object is colimiting. -/\ndef binaryCofanZeroLeftIsColimit (X : C) : IsColimit (binaryCofanZeroLeft X) :=\n  BinaryCofan.isColimitMk (fun s => BinaryCofan.inr s) (by aesop_cat) (by aesop_cat)\n    (fun s m _ h\u2082 => by simpa using h\u2082)\n#align category_theory.limits.binary_cofan_zero_left_is_colimit CategoryTheory.Limits.binaryCofanZeroLeftIsColimit\n\ninstance hasBinaryCoproduct_zero_left (X : C) : HasBinaryCoproduct (0 : C) X :=\n  HasColimit.mk \u27e8_, binaryCofanZeroLeftIsColimit X\u27e9\n#align category_theory.limits.has_binary_coproduct_zero_left CategoryTheory.Limits.hasBinaryCoproduct_zero_left\n\n/-- A zero object is a left unit for categorical coproduct. -/\ndef zeroCoprodIso (X : C) : (0 : C) \u2a3f X \u2245 X :=\n  colimit.isoColimitCocone \u27e8_, binaryCofanZeroLeftIsColimit X\u27e9\n#align category_theory.limits.zero_coprod_iso CategoryTheory.Limits.zeroCoprodIso\n\n@[simp]\ntheorem inr_zeroCoprodIso_hom (X : C) : coprod.inr \u226b (zeroCoprodIso X).hom = \ud835\udfd9 X := by\n  dsimp [zeroCoprodIso, binaryCofanZeroLeft]\n  simp\n#align category_theory.limits.inr_zero_coprod_iso_hom CategoryTheory.Limits.inr_zeroCoprodIso_hom\n\n@[simp]\ntheorem zeroCoprodIso_inv (X : C) : (zeroCoprodIso X).inv = coprod.inr :=\n  rfl\n#align category_theory.limits.zero_coprod_iso_inv CategoryTheory.Limits.zeroCoprodIso_inv\n\n/-- The colimit cocone for the coproduct with a zero object. -/\ndef binaryCofanZeroRight (X : C) : BinaryCofan X (0 : C) :=\n  BinaryCofan.mk (\ud835\udfd9 X) 0\n#align category_theory.limits.binary_cofan_zero_right CategoryTheory.Limits.binaryCofanZeroRight\n\n/-- The colimit cocone for the coproduct with a zero object is colimiting. -/\ndef binaryCofanZeroRightIsColimit (X : C) : IsColimit (binaryCofanZeroRight X) :=\n  BinaryCofan.isColimitMk (fun s => BinaryCofan.inl s) (by aesop_cat) (by aesop_cat)\n    (fun s m h\u2081 _ => by simpa using h\u2081)\n#align category_theory.limits.binary_cofan_zero_right_is_colimit CategoryTheory.Limits.binaryCofanZeroRightIsColimit\n\ninstance hasBinaryCoproduct_zero_right (X : C) : HasBinaryCoproduct X (0 : C) :=\n  HasColimit.mk \u27e8_, binaryCofanZeroRightIsColimit X\u27e9\n#align category_theory.limits.has_binary_coproduct_zero_right CategoryTheory.Limits.hasBinaryCoproduct_zero_right\n\n/-- A zero object is a right unit for categorical coproduct. -/\ndef coprodZeroIso (X : C) : X \u2a3f (0 : C) \u2245 X :=\n  colimit.isoColimitCocone \u27e8_, binaryCofanZeroRightIsColimit X\u27e9\n#align category_theory.limits.coprod_zero_iso CategoryTheory.Limits.coprodZeroIso\n\n@[simp]\ntheorem inr_coprodZeroIso_hom (X : C) : coprod.inl \u226b (coprodZeroIso X).hom = \ud835\udfd9 X := by\n  dsimp [coprodZeroIso, binaryCofanZeroRight]\n  simp\n#align category_theory.limits.inr_coprod_zeroiso_hom CategoryTheory.Limits.inr_coprodZeroIso_hom\n\n@[simp]\ntheorem coprodZeroIso_inv (X : C) : (coprodZeroIso X).inv = coprod.inl :=\n  rfl\n#align category_theory.limits.coprod_zero_iso_inv CategoryTheory.Limits.coprodZeroIso_inv\n\ninstance hasPullback_over_zero (X Y : C) [HasBinaryProduct X Y] :\n    HasPullback (0 : X \u27f6 0) (0 : Y \u27f6 0) :=\n  HasLimit.mk\n    \u27e8_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)\u27e9\n#align category_theory.limits.has_pullback_over_zero CategoryTheory.Limits.hasPullback_over_zero\n\n/-- The pullback over the zeron object is the product. -/\ndef pullbackZeroZeroIso (X Y : C) [HasBinaryProduct X Y] :\n    pullback (0 : X \u27f6 0) (0 : Y \u27f6 0) \u2245 X \u2a2f Y :=\n  limit.isoLimitCone\n    \u27e8_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)\u27e9\n#align category_theory.limits.pullback_zero_zero_iso CategoryTheory.Limits.pullbackZeroZeroIso\n\n@[simp]\ntheorem pullbackZeroZeroIso_inv_fst (X Y : C) [HasBinaryProduct X Y] :\n    (pullbackZeroZeroIso X Y).inv \u226b pullback.fst = prod.fst := by\n  dsimp [pullbackZeroZeroIso]\n  simp\n#align category_theory.limits.pullback_zero_zero_iso_inv_fst CategoryTheory.Limits.pullbackZeroZeroIso_inv_fst\n\n@[simp]\ntheorem pullbackZeroZeroIso_inv_snd (X Y : C) [HasBinaryProduct X Y] :\n    (pullbackZeroZeroIso X Y).inv \u226b pullback.snd = prod.snd := by\n  dsimp [pullbackZeroZeroIso]\n  simp\n#align category_theory.limits.pullback_zero_zero_iso_inv_snd CategoryTheory.Limits.pullbackZeroZeroIso_inv_snd\n\n@[simp]\ntheorem pullbackZeroZeroIso_hom_fst (X Y : C) [HasBinaryProduct X Y] :\n    (pullbackZeroZeroIso X Y).hom \u226b prod.fst = pullback.fst := by simp [\u2190 Iso.eq_inv_comp]\n#align category_theory.limits.pullback_zero_zero_iso_hom_fst CategoryTheory.Limits.pullbackZeroZeroIso_hom_fst\n\n@[simp]\ntheorem pullbackZeroZeroIso_hom_snd (X Y : C) [HasBinaryProduct X Y] :\n    (pullbackZeroZeroIso X Y).hom \u226b prod.snd = pullback.snd := by simp [\u2190 Iso.eq_inv_comp]\n#align category_theory.limits.pullback_zero_zero_iso_hom_snd CategoryTheory.Limits.pullbackZeroZeroIso_hom_snd\n\ninstance hasPushout_over_zero (X Y : C) [HasBinaryCoproduct X Y] :\n    HasPushout (0 : 0 \u27f6 X) (0 : 0 \u27f6 Y) :=\n  HasColimit.mk\n    \u27e8_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)\u27e9\n#align category_theory.limits.has_pushout_over_zero CategoryTheory.Limits.hasPushout_over_zero\n\n/-- The pushout over the zero object is the coproduct. -/\ndef pushoutZeroZeroIso (X Y : C) [HasBinaryCoproduct X Y] :\n    pushout (0 : 0 \u27f6 X) (0 : 0 \u27f6 Y) \u2245 X \u2a3f Y :=\n  colimit.isoColimitCocone\n    \u27e8_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)\u27e9\n#align category_theory.limits.pushout_zero_zero_iso CategoryTheory.Limits.pushoutZeroZeroIso\n\n@[simp]\ntheorem inl_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] :\n    pushout.inl \u226b (pushoutZeroZeroIso X Y).hom = coprod.inl := by\n  dsimp [pushoutZeroZeroIso]\n  simp\n#align category_theory.limits.inl_pushout_zero_zero_iso_hom CategoryTheory.Limits.inl_pushoutZeroZeroIso_hom\n\n@[simp]\ntheorem inr_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] :\n    pushout.inr \u226b (pushoutZeroZeroIso X Y).hom = coprod.inr := by\n  dsimp [pushoutZeroZeroIso]\n  simp\n#align category_theory.limits.inr_pushout_zero_zero_iso_hom CategoryTheory.Limits.inr_pushoutZeroZeroIso_hom\n\n@[simp]\ntheorem inl_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] :\n    coprod.inl \u226b (pushoutZeroZeroIso X Y).inv = pushout.inl := by simp [Iso.comp_inv_eq]\n#align category_theory.limits.inl_pushout_zero_zero_iso_inv CategoryTheory.Limits.inl_pushoutZeroZeroIso_inv\n\n@[simp]\ntheorem inr_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] :\n    coprod.inr \u226b (pushoutZeroZeroIso X Y).inv = pushout.inr := by simp [Iso.comp_inv_eq]\n#align category_theory.limits.inr_pushout_zero_zero_iso_inv CategoryTheory.Limits.inr_pushoutZeroZeroIso_inv\n\nend CategoryTheory.Limits\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Limits/Constructions/ZeroObjects.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7130985216358459}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport algebra.algebra.operations\nimport algebra.algebra.tower\nimport data.equiv.ring\nimport data.nat.choose.sum\nimport ring_theory.ideal.basic\nimport ring_theory.non_zero_divisors\n/-!\n# More operations on modules and ideals\n-/\nuniverses u v w x\n\nopen_locale big_operators\n\nnamespace submodule\n\nvariables {R : Type u} {M : Type v}\nvariables [comm_ring R] [add_comm_group M] [module R M]\n\ninstance has_scalar' : has_scalar (ideal R) (submodule R M) :=\n\u27e8\u03bb I N, \u2a06 r : I, N.map (r.1 \u2022 linear_map.id)\u27e9\n\n/-- `N.annihilator` is the ideal of all elements `r : R` such that `r \u2022 N = 0`. -/\ndef annihilator (N : submodule R M) : ideal R :=\n(linear_map.lsmul R N).ker\n\n/-- `N.colon P` is the ideal of all elements `r : R` such that `r \u2022 P \u2286 N`. -/\ndef colon (N P : submodule R M) : ideal R :=\nannihilator (P.map N.mkq)\n\nvariables {I J : ideal R} {N N\u2081 N\u2082 P P\u2081 P\u2082 : submodule R M}\n\ntheorem mem_annihilator {r} : r \u2208 N.annihilator \u2194 \u2200 n \u2208 N, r \u2022 n = (0:M) :=\n\u27e8\u03bb hr n hn, congr_arg subtype.val (linear_map.ext_iff.1 (linear_map.mem_ker.1 hr) \u27e8n, hn\u27e9),\n\u03bb h, linear_map.mem_ker.2 $ linear_map.ext $ \u03bb n, subtype.eq $ h n.1 n.2\u27e9\n\ntheorem mem_annihilator' {r} : r \u2208 N.annihilator \u2194 N \u2264 comap (r \u2022 linear_map.id) \u22a5 :=\nmem_annihilator.trans \u27e8\u03bb H n hn, (mem_bot R).2 $ H n hn, \u03bb H n hn, (mem_bot R).1 $ H hn\u27e9\n\ntheorem annihilator_bot : (\u22a5 : submodule R M).annihilator = \u22a4 :=\n(ideal.eq_top_iff_one _).2 $ mem_annihilator'.2 bot_le\n\ntheorem annihilator_eq_top_iff : N.annihilator = \u22a4 \u2194 N = \u22a5 :=\n\u27e8\u03bb H, eq_bot_iff.2 $ \u03bb (n:M) hn, (mem_bot R).2 $\n  one_smul R n \u25b8 mem_annihilator.1 ((ideal.eq_top_iff_one _).1 H) n hn,\n  \u03bb H, H.symm \u25b8 annihilator_bot\u27e9\n\ntheorem annihilator_mono (h : N \u2264 P) : P.annihilator \u2264 N.annihilator :=\n\u03bb r hrp, mem_annihilator.2 $ \u03bb n hn, mem_annihilator.1 hrp n $ h hn\n\ntheorem annihilator_supr (\u03b9 : Sort w) (f : \u03b9 \u2192 submodule R M) :\n  (annihilator \u2a06 i, f i) = \u2a05 i, annihilator (f i) :=\nle_antisymm (le_infi $ \u03bb i, annihilator_mono $ le_supr _ _)\n(\u03bb r H, mem_annihilator'.2 $ supr_le $ \u03bb i,\n  have _ := (mem_infi _).1 H i, mem_annihilator'.1 this)\n\ntheorem mem_colon {r} : r \u2208 N.colon P \u2194 \u2200 p \u2208 P, r \u2022 p \u2208 N :=\nmem_annihilator.trans \u27e8\u03bb H p hp, (quotient.mk_eq_zero N).1 (H (quotient.mk p) (mem_map_of_mem hp)),\n\u03bb H m \u27e8p, hp, hpm\u27e9, hpm \u25b8 (N.mkq).map_smul r p \u25b8 (quotient.mk_eq_zero N).2 $ H p hp\u27e9\n\ntheorem mem_colon' {r} : r \u2208 N.colon P \u2194 P \u2264 comap (r \u2022 linear_map.id) N :=\nmem_colon\n\ntheorem colon_mono (hn : N\u2081 \u2264 N\u2082) (hp : P\u2081 \u2264 P\u2082) : N\u2081.colon P\u2082 \u2264 N\u2082.colon P\u2081 :=\n\u03bb r hrnp, mem_colon.2 $ \u03bb p\u2081 hp\u2081, hn $ mem_colon.1 hrnp p\u2081 $ hp hp\u2081\n\ntheorem infi_colon_supr (\u03b9\u2081 : Sort w) (f : \u03b9\u2081 \u2192 submodule R M)\n  (\u03b9\u2082 : Sort x) (g : \u03b9\u2082 \u2192 submodule R M) :\n  (\u2a05 i, f i).colon (\u2a06 j, g j) = \u2a05 i j, (f i).colon (g j) :=\nle_antisymm (le_infi $ \u03bb i, le_infi $ \u03bb j, colon_mono (infi_le _ _) (le_supr _ _))\n(\u03bb r H, mem_colon'.2 $ supr_le $ \u03bb j, map_le_iff_le_comap.1 $ le_infi $ \u03bb i,\n  map_le_iff_le_comap.2 $ mem_colon'.1 $ have _ := ((mem_infi _).1 H i),\n  have _ := ((mem_infi _).1 this j), this)\n\ntheorem smul_mem_smul {r} {n} (hr : r \u2208 I) (hn : n \u2208 N) : r \u2022 n \u2208 I \u2022 N :=\n(le_supr _ \u27e8r, hr\u27e9 : _ \u2264 I \u2022 N) \u27e8n, hn, rfl\u27e9\n\ntheorem smul_le {P : submodule R M} : I \u2022 N \u2264 P \u2194 \u2200 (r \u2208 I) (n \u2208 N), r \u2022 n \u2208 P :=\n\u27e8\u03bb H r hr n hn, H $ smul_mem_smul hr hn,\n\u03bb H, supr_le $ \u03bb r, map_le_iff_le_comap.2 $ \u03bb n hn, H r.1 r.2 n hn\u27e9\n\n@[elab_as_eliminator]\ntheorem smul_induction_on {p : M \u2192 Prop} {x} (H : x \u2208 I \u2022 N)\n  (Hb : \u2200 (r \u2208 I) (n \u2208 N), p (r \u2022 n)) (H0 : p 0)\n  (H1 : \u2200 x y, p x \u2192 p y \u2192 p (x + y))\n  (H2 : \u2200 (c:R) n, p n \u2192 p (c \u2022 n)) : p x :=\n(@smul_le _ _ _ _ _ _ _ \u27e8p, H0, H1, H2\u27e9).2 Hb H\n\ntheorem mem_smul_span_singleton {I : ideal R} {m : M} {x : M} :\n  x \u2208 I \u2022 span R ({m} : set M) \u2194 \u2203 y \u2208 I, y \u2022 m = x :=\n\u27e8\u03bb hx, smul_induction_on hx\n  (\u03bb r hri n hnm,\n    let \u27e8s, hs\u27e9 := mem_span_singleton.1 hnm in \u27e8r * s, I.mul_mem_right _ hri, hs \u25b8 mul_smul r s m\u27e9)\n  \u27e80, I.zero_mem, by rw [zero_smul]\u27e9\n  (\u03bb m1 m2 \u27e8y1, hyi1, hy1\u27e9 \u27e8y2, hyi2, hy2\u27e9,\n    \u27e8y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]\u27e9)\n  (\u03bb c r \u27e8y, hyi, hy\u27e9, \u27e8c * y, I.mul_mem_left _ hyi, by rw [mul_smul, hy]\u27e9),\n\u03bb \u27e8y, hyi, hy\u27e9, hy \u25b8 smul_mem_smul hyi (subset_span $ set.mem_singleton m)\u27e9\n\ntheorem smul_le_right : I \u2022 N \u2264 N :=\nsmul_le.2 $ \u03bb r hr n, N.smul_mem r\n\ntheorem smul_mono (hij : I \u2264 J) (hnp : N \u2264 P) : I \u2022 N \u2264 J \u2022 P :=\nsmul_le.2 $ \u03bb r hr n hn, smul_mem_smul (hij hr) (hnp hn)\n\ntheorem smul_mono_left (h : I \u2264 J) : I \u2022 N \u2264 J \u2022 N :=\nsmul_mono h (le_refl N)\n\ntheorem smul_mono_right (h : N \u2264 P) : I \u2022 N \u2264 I \u2022 P :=\nsmul_mono (le_refl I) h\n\nvariables (I J N P)\n@[simp] theorem smul_bot : I \u2022 (\u22a5 : submodule R M) = \u22a5 :=\neq_bot_iff.2 $ smul_le.2 $ \u03bb r hri s hsb,\n(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hsb).symm \u25b8 smul_zero r\n\n@[simp] theorem bot_smul : (\u22a5 : ideal R) \u2022 N = \u22a5 :=\neq_bot_iff.2 $ smul_le.2 $ \u03bb r hrb s hsi,\n(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hrb).symm \u25b8 zero_smul _ s\n\n@[simp] theorem top_smul : (\u22a4 : ideal R) \u2022 N = N :=\nle_antisymm smul_le_right $ \u03bb r hri, one_smul R r \u25b8 smul_mem_smul mem_top hri\n\ntheorem smul_sup : I \u2022 (N \u2294 P) = I \u2022 N \u2294 I \u2022 P :=\nle_antisymm (smul_le.2 $ \u03bb r hri m hmnp, let \u27e8n, hn, p, hp, hnpm\u27e9 := mem_sup.1 hmnp in\n  mem_sup.2 \u27e8_, smul_mem_smul hri hn, _, smul_mem_smul hri hp, hnpm \u25b8 (smul_add _ _ _).symm\u27e9)\n(sup_le (smul_mono_right le_sup_left)\n  (smul_mono_right le_sup_right))\n\ntheorem sup_smul : (I \u2294 J) \u2022 N = I \u2022 N \u2294 J \u2022 N :=\nle_antisymm (smul_le.2 $ \u03bb r hrij n hn, let \u27e8ri, hri, rj, hrj, hrijr\u27e9 := mem_sup.1 hrij in\n  mem_sup.2 \u27e8_, smul_mem_smul hri hn, _, smul_mem_smul hrj hn, hrijr \u25b8 (add_smul _ _ _).symm\u27e9)\n(sup_le (smul_mono_left le_sup_left)\n  (smul_mono_left le_sup_right))\n\nprotected theorem smul_assoc : (I \u2022 J) \u2022 N = I \u2022 (J \u2022 N) :=\nle_antisymm (smul_le.2 $ \u03bb rs hrsij t htn,\n  smul_induction_on hrsij\n  (\u03bb r hr s hs,\n    (@smul_eq_mul R _ r s).symm \u25b8 smul_smul r s t \u25b8 smul_mem_smul hr (smul_mem_smul hs htn))\n  ((zero_smul R t).symm \u25b8 submodule.zero_mem _)\n  (\u03bb x y, (add_smul x y t).symm \u25b8 submodule.add_mem _)\n  (\u03bb r s h, (@smul_eq_mul R _ r s).symm \u25b8 smul_smul r s t \u25b8 submodule.smul_mem _ _ h))\n(smul_le.2 $ \u03bb r hr sn hsn, suffices J \u2022 N \u2264 submodule.comap (r \u2022 linear_map.id) ((I \u2022 J) \u2022 N),\n  from this hsn,\nsmul_le.2 $ \u03bb s hs n hn, show r \u2022 (s \u2022 n) \u2208 (I \u2022 J) \u2022 N,\n  from mul_smul r s n \u25b8 smul_mem_smul (smul_mem_smul hr hs) hn)\n\nvariables (S : set R) (T : set M)\n\ntheorem span_smul_span : (ideal.span S) \u2022 (span R T) =\n  span R (\u22c3 (s \u2208 S) (t \u2208 T), {s \u2022 t}) :=\nle_antisymm (smul_le.2 $ \u03bb r hrS n hnT, span_induction hrS\n  (\u03bb r hrS, span_induction hnT\n    (\u03bb n hnT, subset_span $ set.mem_bUnion hrS $\n      set.mem_bUnion hnT $ set.mem_singleton _)\n    ((smul_zero r : r \u2022 0 = (0:M)).symm \u25b8 submodule.zero_mem _)\n    (\u03bb x y, (smul_add r x y).symm \u25b8 submodule.add_mem _)\n    (\u03bb c m, by rw [smul_smul, mul_comm, mul_smul]; exact submodule.smul_mem _ _))\n  ((zero_smul R n).symm \u25b8 submodule.zero_mem _)\n  (\u03bb r s, (add_smul r s n).symm \u25b8 submodule.add_mem _)\n  (\u03bb c r, by rw [smul_eq_mul, mul_smul]; exact submodule.smul_mem _ _)) $\nspan_le.2 $ set.bUnion_subset $ \u03bb r hrS, set.bUnion_subset $ \u03bb n hnT, set.singleton_subset_iff.2 $\nsmul_mem_smul (subset_span hrS) (subset_span hnT)\n\nvariables {M' : Type w} [add_comm_group M'] [module R M']\n\ntheorem map_smul'' (f : M \u2192\u2097[R] M') : (I \u2022 N).map f = I \u2022 N.map f :=\nle_antisymm (map_le_iff_le_comap.2 $ smul_le.2 $ \u03bb r hr n hn, show f (r \u2022 n) \u2208 I \u2022 N.map f,\n    from (f.map_smul r n).symm \u25b8 smul_mem_smul hr (mem_map_of_mem hn)) $\nsmul_le.2 $ \u03bb r hr n hn, let \u27e8p, hp, hfp\u27e9 := mem_map.1 hn in\nhfp \u25b8 f.map_smul r p \u25b8 mem_map_of_mem (smul_mem_smul hr hp)\n\nend submodule\n\nnamespace ideal\n\nsection chinese_remainder\nvariables {R : Type u} [comm_ring R] {\u03b9 : Type v}\n\ntheorem exists_sub_one_mem_and_mem (s : finset \u03b9) {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i \u2208 s, \u2200 j \u2208 s, i \u2260 j \u2192 f i \u2294 f j = \u22a4) (i : \u03b9) (his : i \u2208 s) :\n  \u2203 r : R, r - 1 \u2208 f i \u2227 \u2200 j \u2208 s, j \u2260 i \u2192 r \u2208 f j :=\nbegin\n  have : \u2200 j \u2208 s, j \u2260 i \u2192 \u2203 r : R, \u2203 H : r - 1 \u2208 f i, r \u2208 f j,\n  { intros j hjs hji, specialize hf i his j hjs hji.symm,\n    rw [eq_top_iff_one, submodule.mem_sup] at hf,\n    rcases hf with \u27e8r, hri, s, hsj, hrs\u27e9, refine \u27e81 - r, _, _\u27e9,\n    { rw [sub_right_comm, sub_self, zero_sub], exact (f i).neg_mem hri },\n    { rw [\u2190 hrs, add_sub_cancel'], exact hsj } },\n  classical,\n  have : \u2203 g : \u03b9 \u2192 R, (\u2200 j, g j - 1 \u2208 f i) \u2227 \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2208 f j,\n  { choose g hg1 hg2,\n    refine \u27e8\u03bb j, if H : j \u2208 s \u2227 j \u2260 i then g j H.1 H.2 else 1, \u03bb j, _, \u03bb j, _\u27e9,\n    { split_ifs with h, { apply hg1 }, rw sub_self, exact (f i).zero_mem },\n    { intros hjs hji, rw dif_pos, { apply hg2 }, exact \u27e8hjs, hji\u27e9 } },\n  rcases this with \u27e8g, hgi, hgj\u27e9, use (\u220f x in s.erase i, g x), split,\n  { rw [\u2190 quotient.eq, ring_hom.map_one, ring_hom.map_prod],\n    apply finset.prod_eq_one, intros, rw [\u2190 ring_hom.map_one, quotient.eq], apply hgi },\n  intros j hjs hji, rw [\u2190 quotient.eq_zero_iff_mem, ring_hom.map_prod],\n  refine finset.prod_eq_zero (finset.mem_erase_of_ne_of_mem hji hjs) _,\n  rw quotient.eq_zero_iff_mem, exact hgj j hjs hji\nend\n\ntheorem exists_sub_mem [fintype \u03b9] {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) (g : \u03b9 \u2192 R) :\n  \u2203 r : R, \u2200 i, r - g i \u2208 f i :=\nbegin\n  have : \u2203 \u03c6 : \u03b9 \u2192 R, (\u2200 i, \u03c6 i - 1 \u2208 f i) \u2227 (\u2200 i j, i \u2260 j \u2192 \u03c6 i \u2208 f j),\n  { have := exists_sub_one_mem_and_mem (finset.univ : finset \u03b9) (\u03bb i _ j _ hij, hf i j hij),\n    choose \u03c6 h\u03c6,\n    existsi \u03bb i, \u03c6 i (finset.mem_univ i),\n    exact \u27e8\u03bb i, (h\u03c6 i _).1, \u03bb i j hij, (h\u03c6 i _).2 j (finset.mem_univ j) hij.symm\u27e9 },\n  rcases this with \u27e8\u03c6, h\u03c61, h\u03c62\u27e9,\n  use \u2211 i, g i * \u03c6 i,\n  intros i,\n  rw [\u2190 quotient.eq, ring_hom.map_sum],\n  refine eq.trans (finset.sum_eq_single i _ _) _,\n  { intros j _ hji, rw quotient.eq_zero_iff_mem, exact (f i).mul_mem_left _ (h\u03c62 j i hji) },\n  { intros hi, exact (hi $ finset.mem_univ i).elim },\n  specialize h\u03c61 i, rw [\u2190 quotient.eq, ring_hom.map_one] at h\u03c61,\n  rw [ring_hom.map_mul, h\u03c61, mul_one]\nend\n\n/-- The homomorphism from `R/(\u22c2 i, f i)` to `\u220f i, (R / f i)` featured in the Chinese\n  Remainder Theorem. It is bijective if the ideals `f i` are comaximal. -/\ndef quotient_inf_to_pi_quotient (f : \u03b9 \u2192 ideal R) :\n  (\u2a05 i, f i).quotient \u2192+* \u03a0 i, (f i).quotient :=\nquotient.lift (\u2a05 i, f i)\n  (pi.ring_hom (\u03bb i : \u03b9, (quotient.mk (f i) : _))) $\n  \u03bb r hr, begin\n    rw submodule.mem_infi at hr,\n    ext i,\n    exact quotient.eq_zero_iff_mem.2 (hr i)\n  end\n\ntheorem quotient_inf_to_pi_quotient_bijective [fintype \u03b9] {f : \u03b9 \u2192 ideal R}\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) :\n  function.bijective (quotient_inf_to_pi_quotient f) :=\n\u27e8\u03bb x y, quotient.induction_on\u2082' x y $ \u03bb r s hrs, quotient.eq.2 $\n  (submodule.mem_infi _).2 $ \u03bb i, quotient.eq.1 $\n  show quotient_inf_to_pi_quotient f (quotient.mk' r) i = _, by rw hrs; refl,\n\u03bb g, let \u27e8r, hr\u27e9 := exists_sub_mem hf (\u03bb i, quotient.out' (g i)) in\n\u27e8quotient.mk _ r, funext $ \u03bb i, quotient.out_eq' (g i) \u25b8 quotient.eq.2 (hr i)\u27e9\u27e9\n\n/-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/\nnoncomputable def quotient_inf_ring_equiv_pi_quotient [fintype \u03b9] (f : \u03b9 \u2192 ideal R)\n  (hf : \u2200 i j, i \u2260 j \u2192 f i \u2294 f j = \u22a4) :\n  (\u2a05 i, f i).quotient \u2243+* \u03a0 i, (f i).quotient :=\n{ .. equiv.of_bijective _ (quotient_inf_to_pi_quotient_bijective hf),\n  .. quotient_inf_to_pi_quotient f }\n\nend chinese_remainder\n\nsection mul_and_radical\nvariables {R : Type u} {\u03b9 : Type*} [comm_ring R]\nvariables {I J K L: ideal R}\n\ninstance : has_mul (ideal R) := \u27e8(\u2022)\u27e9\n\n@[simp] lemma add_eq_sup : I + J = I \u2294 J := rfl\n@[simp] lemma zero_eq_bot : (0 : ideal R) = \u22a5 := rfl\n@[simp] lemma one_eq_top : (1 : ideal R) = \u22a4 :=\nby erw [submodule.one_eq_map_top, submodule.map_id]\n\ntheorem mul_mem_mul {r s} (hr : r \u2208 I) (hs : s \u2208 J) : r * s \u2208 I * J :=\nsubmodule.smul_mem_smul hr hs\n\ntheorem mul_mem_mul_rev {r s} (hr : r \u2208 I) (hs : s \u2208 J) : s * r \u2208 I * J :=\nmul_comm r s \u25b8 mul_mem_mul hr hs\n\ntheorem mul_le : I * J \u2264 K \u2194 \u2200 (r \u2208 I) (s \u2208 J), r * s \u2208 K :=\nsubmodule.smul_le\n\nlemma mul_le_left : I * J \u2264 J :=\nideal.mul_le.2 (\u03bb r hr s, J.mul_mem_left _)\n\nlemma mul_le_right : I * J \u2264 I :=\nideal.mul_le.2 (\u03bb r hr s hs, I.mul_mem_right _ hr)\n\n@[simp] lemma sup_mul_right_self : I \u2294 (I * J) = I :=\nsup_eq_left.2 ideal.mul_le_right\n\n@[simp] lemma sup_mul_left_self : I \u2294 (J * I) = I :=\nsup_eq_left.2 ideal.mul_le_left\n\n@[simp] lemma mul_right_self_sup : (I * J) \u2294 I = I :=\nsup_eq_right.2 ideal.mul_le_right\n\n@[simp] lemma mul_left_self_sup : (J * I) \u2294 I = I :=\nsup_eq_right.2 ideal.mul_le_left\n\nvariables (I J K)\nprotected theorem mul_comm : I * J = J * I :=\nle_antisymm (mul_le.2 $ \u03bb r hrI s hsJ, mul_mem_mul_rev hsJ hrI)\n(mul_le.2 $ \u03bb r hrJ s hsI, mul_mem_mul_rev hsI hrJ)\n\nprotected theorem mul_assoc : (I * J) * K = I * (J * K) :=\nsubmodule.smul_assoc I J K\n\ntheorem span_mul_span (S T : set R) : span S * span T =\n  span \u22c3 (s \u2208 S) (t \u2208 T), {s * t} :=\nsubmodule.span_smul_span S T\nvariables {I J K}\n\nlemma span_mul_span' (S T : set R) : span S * span T = span (S*T) :=\nby { unfold span, rw submodule.span_mul_span,}\n\nlemma span_singleton_mul_span_singleton (r s : R) :\n  span {r} * span {s} = (span {r * s} : ideal R) :=\nby { unfold span, rw [submodule.span_mul_span, set.singleton_mul_singleton],}\n\ntheorem mul_le_inf : I * J \u2264 I \u2293 J :=\nmul_le.2 $ \u03bb r hri s hsj, \u27e8I.mul_mem_right s hri, J.mul_mem_left r hsj\u27e9\n\ntheorem prod_le_inf {s : finset \u03b9} {f : \u03b9 \u2192 ideal R} : s.prod f \u2264 s.inf f :=\nbegin\n  classical, refine s.induction_on _ _,\n  { rw [finset.prod_empty, finset.inf_empty], exact le_top },\n  intros a s has ih,\n  rw [finset.prod_insert has, finset.inf_insert],\n  exact le_trans mul_le_inf (inf_le_inf (le_refl _) ih)\nend\n\ntheorem mul_eq_inf_of_coprime (h : I \u2294 J = \u22a4) : I * J = I \u2293 J :=\nle_antisymm mul_le_inf $ \u03bb r \u27e8hri, hrj\u27e9,\nlet \u27e8s, hsi, t, htj, hst\u27e9 := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in\nmul_one r \u25b8 hst \u25b8 (mul_add r s t).symm \u25b8 ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj)\n  (mul_mem_mul hri htj)\n\nvariables (I)\ntheorem mul_bot : I * \u22a5 = \u22a5 :=\nsubmodule.smul_bot I\n\ntheorem bot_mul : \u22a5 * I = \u22a5 :=\nsubmodule.bot_smul I\n\ntheorem mul_top : I * \u22a4 = I :=\nideal.mul_comm \u22a4 I \u25b8 submodule.top_smul I\n\ntheorem top_mul : \u22a4 * I = I :=\nsubmodule.top_smul I\nvariables {I}\n\ntheorem mul_mono (hik : I \u2264 K) (hjl : J \u2264 L) : I * J \u2264 K * L :=\nsubmodule.smul_mono hik hjl\n\ntheorem mul_mono_left (h : I \u2264 J) : I * K \u2264 J * K :=\nsubmodule.smul_mono_left h\n\ntheorem mul_mono_right (h : J \u2264 K) : I * J \u2264 I * K :=\nsubmodule.smul_mono_right h\n\nvariables (I J K)\ntheorem mul_sup : I * (J \u2294 K) = I * J \u2294 I * K :=\nsubmodule.smul_sup I J K\n\ntheorem sup_mul : (I \u2294 J) * K = I * K \u2294 J * K :=\nsubmodule.sup_smul I J K\nvariables {I J K}\n\nlemma pow_le_pow {m n : \u2115} (h : m \u2264 n) :\n  I^n \u2264 I^m :=\nbegin\n  cases nat.exists_eq_add_of_le h with k hk,\n  rw [hk, pow_add],\n  exact le_trans (mul_le_inf) (inf_le_left)\nend\n\nlemma mul_eq_bot {R : Type*} [integral_domain R] {I J : ideal R} :\n  I * J = \u22a5 \u2194 I = \u22a5 \u2228 J = \u22a5 :=\n\u27e8\u03bb hij, or_iff_not_imp_left.mpr (\u03bb I_ne_bot, J.eq_bot_iff.mpr (\u03bb j hj,\n  let \u27e8i, hi, ne0\u27e9 := I.ne_bot_iff.mp I_ne_bot in\n    or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0)),\n \u03bb h, by cases h; rw [\u2190 ideal.mul_bot, h, ideal.mul_comm]\u27e9\n\ninstance {R : Type*} [integral_domain R] : no_zero_divisors (ideal R) :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero := \u03bb I J, mul_eq_bot.1 }\n\n/-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/\nlemma prod_eq_bot {R : Type*} [integral_domain R]\n  {s : multiset (ideal R)} : s.prod = \u22a5 \u2194 \u2203 I \u2208 s, I = \u22a5 :=\nprod_zero_iff_exists_zero\n\n/-- The radical of an ideal `I` consists of the elements `r` such that `r^n \u2208 I` for some `n`. -/\ndef radical (I : ideal R) : ideal R :=\n{ carrier := { r | \u2203 n : \u2115, r ^ n \u2208 I },\n  zero_mem' := \u27e81, (pow_one (0:R)).symm \u25b8 I.zero_mem\u27e9,\n  add_mem' := \u03bb x y \u27e8m, hxmi\u27e9 \u27e8n, hyni\u27e9, \u27e8m + n,\n    (add_pow x y (m + n)).symm \u25b8 I.sum_mem $\n    show \u2200 c \u2208 finset.range (nat.succ (m + n)),\n      x ^ c * y ^ (m + n - c) * (nat.choose (m + n) c) \u2208 I,\n    from \u03bb c hc, or.cases_on (le_total c m)\n      (\u03bb hcm, I.mul_mem_right _ $ I.mul_mem_left _ $ nat.add_comm n m \u25b8\n        (nat.add_sub_assoc hcm n).symm \u25b8\n        (pow_add y n (m-c)).symm \u25b8 I.mul_mem_right _ hyni)\n      (\u03bb hmc, I.mul_mem_right _ $ I.mul_mem_right _ $ nat.add_sub_cancel' hmc \u25b8\n        (pow_add x m (c-m)).symm \u25b8 I.mul_mem_right _ hxmi)\u27e9,\n  smul_mem' := \u03bb r s \u27e8n, hsni\u27e9, \u27e8n, (mul_pow r s n).symm \u25b8 I.mul_mem_left (r^n) hsni\u27e9 }\n\ntheorem le_radical : I \u2264 radical I :=\n\u03bb r hri, \u27e81, (pow_one r).symm \u25b8 hri\u27e9\n\nvariables (R)\ntheorem radical_top : (radical \u22a4 : ideal R) = \u22a4 :=\n(eq_top_iff_one _).2 \u27e80, submodule.mem_top\u27e9\nvariables {R}\n\ntheorem radical_mono (H : I \u2264 J) : radical I \u2264 radical J :=\n\u03bb r \u27e8n, hrni\u27e9, \u27e8n, H hrni\u27e9\n\nvariables (I)\n@[simp] theorem radical_idem : radical (radical I) = radical I :=\nle_antisymm (\u03bb r \u27e8n, k, hrnki\u27e9, \u27e8n * k, (pow_mul r n k).symm \u25b8 hrnki\u27e9) le_radical\nvariables {I}\n\ntheorem radical_le_radical_iff : radical I \u2264 radical J \u2194 I \u2264 radical J :=\n\u27e8\u03bb h, le_trans le_radical h, \u03bb h, radical_idem J \u25b8 radical_mono h\u27e9\n\ntheorem radical_eq_top : radical I = \u22a4 \u2194 I = \u22a4 :=\n\u27e8\u03bb h, (eq_top_iff_one _).2 $ let \u27e8n, hn\u27e9 := (eq_top_iff_one _).1 h in\n  @one_pow R _ n \u25b8 hn, \u03bb h, h.symm \u25b8 radical_top R\u27e9\n\ntheorem is_prime.radical (H : is_prime I) : radical I = I :=\nle_antisymm (\u03bb r \u27e8n, hrni\u27e9, H.mem_of_pow_mem n hrni) le_radical\n\nvariables (I J)\ntheorem radical_sup : radical (I \u2294 J) = radical (radical I \u2294 radical J) :=\nle_antisymm (radical_mono $ sup_le_sup le_radical le_radical) $\n\u03bb r \u27e8n, hrnij\u27e9, let \u27e8s, hs, t, ht, hst\u27e9 := submodule.mem_sup.1 hrnij in\n@radical_idem _ _ (I \u2294 J) \u25b8 \u27e8n, hst \u25b8 ideal.add_mem _\n  (radical_mono le_sup_left hs) (radical_mono le_sup_right ht)\u27e9\n\ntheorem radical_inf : radical (I \u2293 J) = radical I \u2293 radical J :=\nle_antisymm (le_inf (radical_mono inf_le_left) (radical_mono inf_le_right))\n(\u03bb r \u27e8\u27e8m, hrm\u27e9, \u27e8n, hrn\u27e9\u27e9, \u27e8m + n, (pow_add r m n).symm \u25b8 I.mul_mem_right _ hrm,\n(pow_add r m n).symm \u25b8 J.mul_mem_left _ hrn\u27e9)\n\ntheorem radical_mul : radical (I * J) = radical I \u2293 radical J :=\nle_antisymm (radical_inf I J \u25b8 radical_mono $ @mul_le_inf _ _ I J)\n(\u03bb r \u27e8\u27e8m, hrm\u27e9, \u27e8n, hrn\u27e9\u27e9, \u27e8m + n, (pow_add r m n).symm \u25b8 mul_mem_mul hrm hrn\u27e9)\nvariables {I J}\n\ntheorem is_prime.radical_le_iff (hj : is_prime J) :\n  radical I \u2264 J \u2194 I \u2264 J :=\n\u27e8le_trans le_radical, \u03bb hij r \u27e8n, hrni\u27e9, hj.mem_of_pow_mem n $ hij hrni\u27e9\n\ntheorem radical_eq_Inf (I : ideal R) :\n  radical I = Inf { J : ideal R | I \u2264 J \u2227 is_prime J } :=\nle_antisymm (le_Inf $ \u03bb J hJ, hJ.2.radical_le_iff.2 hJ.1) $\n\u03bb r hr, classical.by_contradiction $ \u03bb hri,\nlet \u27e8m, (hrm : r \u2209 radical m), him, hm\u27e9 := zorn.zorn_nonempty_partial_order\u2080\n  {K : ideal R | r \u2209 radical K}\n  (\u03bb c hc hcc y hyc, \u27e8Sup c, \u03bb \u27e8n, hrnc\u27e9, let \u27e8y, hyc, hrny\u27e9 :=\n      (submodule.mem_Sup_of_directed \u27e8y, hyc\u27e9 hcc.directed_on).1 hrnc in hc hyc \u27e8n, hrny\u27e9,\n    \u03bb z, le_Sup\u27e9) I hri in\nhave \u2200 x \u2209 m, r \u2208 radical (m \u2294 span {x}) := \u03bb x hxm, classical.by_contradiction $ \u03bb hrmx, hxm $\n  hm (m \u2294 span {x}) hrmx le_sup_left \u25b8 (le_sup_right : _ \u2264 m \u2294 span {x})\n    (subset_span $ set.mem_singleton _),\nhave is_prime m, from \u27e8by rintro rfl; rw radical_top at hrm; exact hrm trivial,\n  \u03bb x y hxym, or_iff_not_imp_left.2 $ \u03bb hxm, classical.by_contradiction $ \u03bb hym,\n  let \u27e8n, hrn\u27e9 := this _ hxm,\n      \u27e8p, hpm, q, hq, hpqrn\u27e9 := submodule.mem_sup.1 hrn,\n      \u27e8c, hcxq\u27e9 := mem_span_singleton'.1 hq in\n  let \u27e8k, hrk\u27e9 := this _ hym,\n      \u27e8f, hfm, g, hg, hfgrk\u27e9 := submodule.mem_sup.1 hrk,\n      \u27e8d, hdyg\u27e9 := mem_span_singleton'.1 hg in\n  hrm \u27e8n + k, by rw [pow_add, \u2190 hpqrn, \u2190 hcxq, \u2190 hfgrk, \u2190 hdyg, add_mul, mul_add (c*x),\n                     mul_assoc c x (d*y), mul_left_comm x, \u2190 mul_assoc];\n    refine m.add_mem (m.mul_mem_right _ hpm) (m.add_mem (m.mul_mem_left _ hfm)\n      (m.mul_mem_left _ hxym))\u27e9\u27e9,\nhrm $ this.radical.symm \u25b8 (Inf_le \u27e8him, this\u27e9 : Inf {J : ideal R | I \u2264 J \u2227 is_prime J} \u2264 m) hr\n\n@[simp] lemma radical_bot_of_integral_domain {R : Type u} [integral_domain R] :\n  radical (\u22a5 : ideal R) = \u22a5 :=\neq_bot_iff.2 (\u03bb x hx, hx.rec_on (\u03bb n hn, pow_eq_zero hn))\n\ninstance : comm_semiring (ideal R) := submodule.comm_semiring\n\nvariables (R)\ntheorem top_pow (n : \u2115) : (\u22a4 ^ n : ideal R) = \u22a4 :=\nnat.rec_on n one_eq_top $ \u03bb n ih, by rw [pow_succ, ih, top_mul]\nvariables {R}\n\nvariables (I)\ntheorem radical_pow (n : \u2115) (H : n > 0) : radical (I^n) = radical I :=\nnat.rec_on n (not.elim dec_trivial) (\u03bb n ih H,\nor.cases_on (lt_or_eq_of_le $ nat.le_of_lt_succ H)\n  (\u03bb H, calc radical (I^(n+1))\n           = radical I \u2293 radical (I^n) : by { rw pow_succ, exact radical_mul _ _ }\n       ... = radical I \u2293 radical I : by rw ih H\n       ... = radical I : inf_idem)\n  (\u03bb H, H \u25b8 (pow_one I).symm \u25b8 rfl)) H\n\ntheorem is_prime.mul_le {I J P : ideal R} (hp : is_prime P) :\n  I * J \u2264 P \u2194 I \u2264 P \u2228 J \u2264 P :=\n\u27e8\u03bb h, or_iff_not_imp_left.2 $ \u03bb hip j hj, let \u27e8i, hi, hip\u27e9 := set.not_subset.1 hip in\n  (hp.mem_or_mem $ h $ mul_mem_mul hi hj).resolve_left hip,\n\u03bb h, or.cases_on h (le_trans $ le_trans mul_le_inf inf_le_left)\n  (le_trans $ le_trans mul_le_inf inf_le_right)\u27e9\n\ntheorem is_prime.inf_le {I J P : ideal R} (hp : is_prime P) :\n  I \u2293 J \u2264 P \u2194 I \u2264 P \u2228 J \u2264 P :=\n\u27e8\u03bb h, hp.mul_le.1 $ le_trans mul_le_inf h,\n\u03bb h, or.cases_on h (le_trans inf_le_left) (le_trans inf_le_right)\u27e9\n\ntheorem is_prime.prod_le {s : finset \u03b9} {f : \u03b9 \u2192 ideal R} {P : ideal R}\n  (hp : is_prime P) (hne: s.nonempty) :\n  s.prod f \u2264 P \u2194 \u2203 i \u2208 s, f i \u2264 P :=\nsuffices s.prod f \u2264 P \u2192 \u2203 i \u2208 s, f i \u2264 P,\n  from \u27e8this, \u03bb \u27e8i, his, hip\u27e9, le_trans prod_le_inf $ le_trans (finset.inf_le his) hip\u27e9,\nbegin\n  classical,\n  obtain \u27e8b, hb\u27e9 : \u2203 b, b \u2208 s := hne.bex,\n  obtain \u27e8t, hbt, rfl\u27e9 : \u2203 t, b \u2209 t \u2227 s = insert b t,\n  from \u27e8s.erase b, s.not_mem_erase b, (finset.insert_erase hb).symm\u27e9,\n  revert hbt,\n  refine t.induction_on _ _,\n  { simp only [finset.not_mem_empty, insert_emptyc_eq, exists_prop, finset.prod_singleton,\n      imp_self, exists_eq_left, not_false_iff, finset.mem_singleton] },\n  intros a s has ih hbs h,\n  have : a \u2209 insert b s,\n  { contrapose! has,\n    apply finset.mem_of_mem_insert_of_ne has,\n    rintro rfl,\n    contradiction },\n  rw [finset.insert.comm, finset.prod_insert this, hp.mul_le] at h,\n  rw finset.insert.comm,\n  cases h,\n  { exact \u27e8a, finset.mem_insert_self a _, h\u27e9 },\n  obtain \u27e8i, hi, ih\u27e9 : \u2203 i \u2208 insert b s, f i \u2264 P := ih (mt finset.mem_insert_of_mem hbs) h,\n  exact \u27e8i, finset.mem_insert_of_mem hi, ih\u27e9\nend\n\ntheorem is_prime.inf_le' {s : finset \u03b9} {f : \u03b9 \u2192 ideal R} {P : ideal R} (hp : is_prime P)\n  (hsne: s.nonempty) :\n  s.inf f \u2264 P \u2194 \u2203 i \u2208 s, f i \u2264 P :=\n\u27e8\u03bb h, (hp.prod_le hsne).1 $ le_trans prod_le_inf h,\n  \u03bb \u27e8i, his, hip\u27e9, le_trans (finset.inf_le his) hip\u27e9\n\ntheorem subset_union {I J K : ideal R} : (I : set R) \u2286 J \u222a K \u2194 I \u2264 J \u2228 I \u2264 K :=\n\u27e8\u03bb h, or_iff_not_imp_left.2 $ \u03bb hij s hsi,\n  let \u27e8r, hri, hrj\u27e9 := set.not_subset.1 hij in classical.by_contradiction $ \u03bb hsk,\n  or.cases_on (h $ I.add_mem hri hsi)\n    (\u03bb hj, hrj $ add_sub_cancel r s \u25b8 J.sub_mem hj ((h hsi).resolve_right hsk))\n    (\u03bb hk, hsk $ add_sub_cancel' r s \u25b8 K.sub_mem hk ((h hri).resolve_left hrj)),\n\u03bb h, or.cases_on h (\u03bb h, set.subset.trans h $ set.subset_union_left J K)\n  (\u03bb h, set.subset.trans h $ set.subset_union_right J K)\u27e9\n\ntheorem subset_union_prime' {s : finset \u03b9} {f : \u03b9 \u2192 ideal R} {a b : \u03b9}\n  (hp : \u2200 i \u2208 s, is_prime (f i)) {I : ideal R} :\n  (I : set R) \u2286 f a \u222a f b \u222a (\u22c3 i \u2208 (\u2191s : set \u03b9), f i) \u2194 I \u2264 f a \u2228 I \u2264 f b \u2228 \u2203 i \u2208 s, I \u2264 f i :=\nsuffices (I : set R) \u2286 f a \u222a f b \u222a (\u22c3 i \u2208 (\u2191s : set \u03b9), f i) \u2192\n  I \u2264 f a \u2228 I \u2264 f b \u2228 \u2203 i \u2208 s, I \u2264 f i,\n  from \u27e8this, \u03bb h, or.cases_on h (\u03bb h, set.subset.trans h $ set.subset.trans\n      (set.subset_union_left _ _) (set.subset_union_left _ _)) $\n    \u03bb h, or.cases_on h (\u03bb h, set.subset.trans h $ set.subset.trans\n      (set.subset_union_right _ _) (set.subset_union_left _ _)) $\n    \u03bb \u27e8i, his, hi\u27e9, by refine (set.subset.trans hi $ set.subset.trans _ $\n        set.subset_union_right _ _);\n      exact set.subset_bUnion_of_mem (finset.mem_coe.2 his)\u27e9,\nbegin\n  generalize hn : s.card = n, intros h,\n  unfreezingI { induction n with n ih generalizing a b s },\n  { clear hp,\n    rw finset.card_eq_zero at hn, subst hn,\n    rw [finset.coe_empty, set.bUnion_empty, set.union_empty, subset_union] at h,\n    simpa only [exists_prop, finset.not_mem_empty, false_and, exists_false, or_false] },\n  classical,\n  replace hn : \u2203 (i : \u03b9) (t : finset \u03b9), i \u2209 t \u2227 insert i t = s \u2227 t.card = n :=\n  finset.card_eq_succ.1 hn,\n  unfreezingI { rcases hn with \u27e8i, t, hit, rfl, hn\u27e9 },\n  replace hp : is_prime (f i) \u2227 \u2200 x \u2208 t, is_prime (f x) := (t.forall_mem_insert _ _).1 hp,\n  by_cases Ht : \u2203 j \u2208 t, f j \u2264 f i,\n  { obtain \u27e8j, hjt, hfji\u27e9 : \u2203 j \u2208 t, f j \u2264 f i := Ht,\n    obtain \u27e8u, hju, rfl\u27e9 : \u2203 u, j \u2209 u \u2227 insert j u = t,\n    { exact \u27e8t.erase j, t.not_mem_erase j, finset.insert_erase hjt\u27e9 },\n    have hp' : \u2200 k \u2208 insert i u, is_prime (f k),\n    { rw finset.forall_mem_insert at hp \u22a2, exact \u27e8hp.1, hp.2.2\u27e9 },\n    have hiu : i \u2209 u := mt finset.mem_insert_of_mem hit,\n    have hn' : (insert i u).card = n,\n    { rwa finset.card_insert_of_not_mem at hn \u22a2, exacts [hiu, hju] },\n    have h' : (I : set R) \u2286 f a \u222a f b \u222a (\u22c3 k \u2208 (\u2191(insert i u) : set \u03b9), f k),\n    { rw finset.coe_insert at h \u22a2, rw finset.coe_insert at h,\n      simp only [set.bUnion_insert] at h \u22a2,\n      rw [\u2190 set.union_assoc \u2191(f i)] at h,\n      erw [set.union_eq_self_of_subset_right hfji] at h,\n      exact h },\n    specialize @ih a b (insert i u) hp' hn' h',\n    refine ih.imp id (or.imp id (exists_imp_exists $ \u03bb k, _)), simp only [exists_prop],\n    exact and.imp (\u03bb hk, finset.insert_subset_insert i (finset.subset_insert j u) hk) id },\n  by_cases Ha : f a \u2264 f i,\n  { have h' : (I : set R) \u2286 f i \u222a f b \u222a (\u22c3 j \u2208 (\u2191t : set \u03b9), f j),\n    { rw [finset.coe_insert, set.bUnion_insert, \u2190 set.union_assoc,\n          set.union_right_comm \u2191(f a)] at h,\n      erw [set.union_eq_self_of_subset_left Ha] at h,\n      exact h },\n    specialize @ih i b t hp.2 hn h', right,\n    rcases ih with ih | ih | \u27e8k, hkt, ih\u27e9,\n    { exact or.inr \u27e8i, finset.mem_insert_self i t, ih\u27e9 },\n    { exact or.inl ih },\n    { exact or.inr \u27e8k, finset.mem_insert_of_mem hkt, ih\u27e9 } },\n  by_cases Hb : f b \u2264 f i,\n  { have h' : (I : set R) \u2286 f a \u222a f i \u222a (\u22c3 j \u2208 (\u2191t : set \u03b9), f j),\n    { rw [finset.coe_insert, set.bUnion_insert, \u2190 set.union_assoc, set.union_assoc \u2191(f a)] at h,\n      erw [set.union_eq_self_of_subset_left Hb] at h,\n      exact h },\n    specialize @ih a i t hp.2 hn h',\n    rcases ih with ih | ih | \u27e8k, hkt, ih\u27e9,\n    { exact or.inl ih },\n    { exact or.inr (or.inr \u27e8i, finset.mem_insert_self i t, ih\u27e9) },\n    { exact or.inr (or.inr \u27e8k, finset.mem_insert_of_mem hkt, ih\u27e9) } },\n  by_cases Hi : I \u2264 f i,\n  { exact or.inr (or.inr \u27e8i, finset.mem_insert_self i t, Hi\u27e9) },\n  have : \u00acI \u2293 f a \u2293 f b \u2293 t.inf f \u2264 f i,\n  { rcases t.eq_empty_or_nonempty with (rfl | hsne),\n    { rw [finset.inf_empty, inf_top_eq, hp.1.inf_le, hp.1.inf_le, not_or_distrib, not_or_distrib],\n      exact \u27e8\u27e8Hi, Ha\u27e9, Hb\u27e9 },\n    simp only [hp.1.inf_le, hp.1.inf_le' hsne, not_or_distrib],\n    exact \u27e8\u27e8\u27e8Hi, Ha\u27e9, Hb\u27e9, Ht\u27e9 },\n  rcases set.not_subset.1 this with \u27e8r, \u27e8\u27e8\u27e8hrI, hra\u27e9, hrb\u27e9, hr\u27e9, hri\u27e9,\n  by_cases HI : (I : set R) \u2286 f a \u222a f b \u222a \u22c3 j \u2208 (\u2191t : set \u03b9), f j,\n  { specialize ih hp.2 hn HI, rcases ih with ih | ih | \u27e8k, hkt, ih\u27e9,\n    { left, exact ih }, { right, left, exact ih },\n    { right, right, exact \u27e8k, finset.mem_insert_of_mem hkt, ih\u27e9 } },\n  exfalso, rcases set.not_subset.1 HI with \u27e8s, hsI, hs\u27e9,\n  rw [finset.coe_insert, set.bUnion_insert] at h,\n  have hsi : s \u2208 f i := ((h hsI).resolve_left (mt or.inl hs)).resolve_right (mt or.inr hs),\n  rcases h (I.add_mem hrI hsI) with \u27e8ha | hb\u27e9 | hi | ht,\n  { exact hs (or.inl $ or.inl $ add_sub_cancel' r s \u25b8 (f a).sub_mem ha hra) },\n  { exact hs (or.inl $ or.inr $ add_sub_cancel' r s \u25b8 (f b).sub_mem hb hrb) },\n  { exact hri (add_sub_cancel r s \u25b8 (f i).sub_mem hi hsi) },\n  { rw set.mem_bUnion_iff at ht, rcases ht with \u27e8j, hjt, hj\u27e9,\n    simp only [finset.inf_eq_infi, set_like.mem_coe, submodule.mem_infi] at hr,\n    exact hs (or.inr $ set.mem_bUnion hjt $ add_sub_cancel' r s \u25b8 (f j).sub_mem hj $ hr j hjt) }\nend\n\n/-- Prime avoidance. Atiyah-Macdonald 1.11, Eisenbud 3.3, Stacks 00DS, Matsumura Ex.1.6. -/\ntheorem subset_union_prime {s : finset \u03b9} {f : \u03b9 \u2192 ideal R} (a b : \u03b9)\n  (hp : \u2200 i \u2208 s, i \u2260 a \u2192 i \u2260 b \u2192 is_prime (f i)) {I : ideal R} :\n  (I : set R) \u2286 (\u22c3 i \u2208 (\u2191s : set \u03b9), f i) \u2194 \u2203 i \u2208 s, I \u2264 f i :=\nsuffices (I : set R) \u2286 (\u22c3 i \u2208 (\u2191s : set \u03b9), f i) \u2192 \u2203 i, i \u2208 s \u2227 I \u2264 f i,\n  from \u27e8\u03bb h, bex_def.2 $ this h, \u03bb \u27e8i, his, hi\u27e9, set.subset.trans hi $ set.subset_bUnion_of_mem $\n    show i \u2208 (\u2191s : set \u03b9), from his\u27e9,\nassume h : (I : set R) \u2286 (\u22c3 i \u2208 (\u2191s : set \u03b9), f i),\nbegin\n  classical, tactic.unfreeze_local_instances,\n  by_cases has : a \u2208 s,\n  { obtain \u27e8t, hat, rfl\u27e9 : \u2203 t, a \u2209 t \u2227 insert a t = s :=\n      \u27e8s.erase a, finset.not_mem_erase a s, finset.insert_erase has\u27e9,\n    by_cases hbt : b \u2208 t,\n    { obtain \u27e8u, hbu, rfl\u27e9 : \u2203 u, b \u2209 u \u2227 insert b u = t :=\n        \u27e8t.erase b, finset.not_mem_erase b t, finset.insert_erase hbt\u27e9,\n      have hp' : \u2200 i \u2208 u, is_prime (f i),\n      { intros i hiu, refine hp i (finset.mem_insert_of_mem (finset.mem_insert_of_mem hiu)) _ _;\n        rintro rfl; solve_by_elim only [finset.mem_insert_of_mem, *], },\n      rw [finset.coe_insert, finset.coe_insert, set.bUnion_insert, set.bUnion_insert,\n          \u2190 set.union_assoc, subset_union_prime' hp', bex_def] at h,\n      rwa [finset.exists_mem_insert, finset.exists_mem_insert] },\n    { have hp' : \u2200 j \u2208 t, is_prime (f j),\n      { intros j hj, refine hp j (finset.mem_insert_of_mem hj) _ _;\n        rintro rfl; solve_by_elim only [finset.mem_insert_of_mem, *], },\n      rw [finset.coe_insert, set.bUnion_insert, \u2190 set.union_self (f a : set R),\n          subset_union_prime' hp', \u2190 or_assoc, or_self, bex_def] at h,\n      rwa finset.exists_mem_insert } },\n  { by_cases hbs : b \u2208 s,\n    { obtain \u27e8t, hbt, rfl\u27e9 : \u2203 t, b \u2209 t \u2227 insert b t = s :=\n        \u27e8s.erase b, finset.not_mem_erase b s, finset.insert_erase hbs\u27e9,\n      have hp' : \u2200 j \u2208 t, is_prime (f j),\n      { intros j hj, refine hp j (finset.mem_insert_of_mem hj) _ _;\n        rintro rfl; solve_by_elim only [finset.mem_insert_of_mem, *], },\n      rw [finset.coe_insert, set.bUnion_insert, \u2190 set.union_self (f b : set R),\n          subset_union_prime' hp', \u2190 or_assoc, or_self, bex_def] at h,\n      rwa finset.exists_mem_insert },\n    cases s.eq_empty_or_nonempty with hse hsne,\n    { subst hse, rw [finset.coe_empty, set.bUnion_empty, set.subset_empty_iff] at h,\n      have : (I : set R) \u2260 \u2205 := set.nonempty.ne_empty (set.nonempty_of_mem I.zero_mem),\n      exact absurd h this },\n    { cases hsne.bex with i his,\n      obtain \u27e8t, hit, rfl\u27e9 : \u2203 t, i \u2209 t \u2227 insert i t = s :=\n        \u27e8s.erase i, finset.not_mem_erase i s, finset.insert_erase his\u27e9,\n      have hp' : \u2200 j \u2208 t, is_prime (f j),\n      { intros j hj, refine hp j (finset.mem_insert_of_mem hj) _ _;\n        rintro rfl; solve_by_elim only [finset.mem_insert_of_mem, *], },\n      rw [finset.coe_insert, set.bUnion_insert, \u2190 set.union_self (f i : set R),\n          subset_union_prime' hp', \u2190 or_assoc, or_self, bex_def] at h,\n      rwa finset.exists_mem_insert } }\nend\n\nend mul_and_radical\n\nsection map_and_comap\nvariables {R : Type u} {S : Type v} [comm_ring R] [comm_ring S]\nvariables (f : R \u2192+* S)\nvariables {I J : ideal R} {K L : ideal S}\n\n/-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than\n  the image itself. -/\ndef map (I : ideal R) : ideal S :=\nspan (f '' I)\n\n/-- `I.comap f` is the preimage of `I` under `f`. -/\ndef comap (I : ideal S) : ideal R :=\n{ carrier := f \u207b\u00b9' I,\n  smul_mem' := \u03bb c x hx, show f (c * x) \u2208 I, by { rw f.map_mul, exact I.mul_mem_left _ hx },\n  .. I.to_add_submonoid.comap (f : R \u2192+ S) }\n\nvariables {f}\ntheorem map_mono (h : I \u2264 J) : map f I \u2264 map f J :=\nspan_mono $ set.image_subset _ h\n\ntheorem mem_map_of_mem {x} (h : x \u2208 I) : f x \u2208 map f I :=\nsubset_span \u27e8x, h, rfl\u27e9\n\ntheorem map_le_iff_le_comap :\n  map f I \u2264 K \u2194 I \u2264 comap f K :=\nspan_le.trans set.image_subset_iff\n\n@[simp] theorem mem_comap {x} : x \u2208 comap f K \u2194 f x \u2208 K := iff.rfl\n\ntheorem comap_mono (h : K \u2264 L) : comap f K \u2264 comap f L :=\nset.preimage_mono (\u03bb x hx, h hx)\nvariables (f)\n\ntheorem comap_ne_top (hK : K \u2260 \u22a4) : comap f K \u2260 \u22a4 :=\n(ne_top_iff_one _).2 $ by rw [mem_comap, f.map_one];\n  exact (ne_top_iff_one _).1 hK\n\ntheorem is_prime.comap [hK : K.is_prime] : (comap f K).is_prime :=\n\u27e8comap_ne_top _ hK.1, \u03bb x y,\n  by simp only [mem_comap, f.map_mul]; apply hK.2\u27e9\n\nvariables (I J K L)\n\ntheorem map_top : map f \u22a4 = \u22a4 :=\n(eq_top_iff_one _).2 $ subset_span \u27e81, trivial, f.map_one\u27e9\n\ntheorem map_mul : map f (I * J) = map f I * map f J :=\nle_antisymm (map_le_iff_le_comap.2 $ mul_le.2 $ \u03bb r hri s hsj,\n  show f (r * s) \u2208 _, by rw f.map_mul;\n  exact mul_mem_mul (mem_map_of_mem hri) (mem_map_of_mem hsj))\n(trans_rel_right _ (span_mul_span _ _) $ span_le.2 $\n  set.bUnion_subset $ \u03bb i \u27e8r, hri, hfri\u27e9,\n  set.bUnion_subset $ \u03bb j \u27e8s, hsj, hfsj\u27e9,\n  set.singleton_subset_iff.2 $ hfri \u25b8 hfsj \u25b8\n  by rw [\u2190 f.map_mul];\n  exact mem_map_of_mem (mul_mem_mul hri hsj))\n\nvariable (f)\nlemma gc_map_comap : galois_connection (ideal.map f) (ideal.comap f) :=\n\u03bb I J, ideal.map_le_iff_le_comap\n\n@[simp] lemma comap_id : I.comap (ring_hom.id R) = I :=\nideal.ext $ \u03bb _, iff.rfl\n\n@[simp] lemma map_id : I.map (ring_hom.id R) = I :=\n(gc_map_comap (ring_hom.id R)).l_unique galois_connection.id comap_id\n\nlemma comap_comap {T : Type*} [comm_ring T] {I : ideal T} (f : R \u2192+* S)\n  (g : S \u2192+*T) : (I.comap g).comap f = I.comap (g.comp f) := rfl\n\nlemma map_map {T : Type*} [comm_ring T] {I : ideal R} (f : R \u2192+* S)\n  (g : S \u2192+*T) : (I.map f).map g = I.map (g.comp f) :=\n((gc_map_comap f).compose _ _ _ _ (gc_map_comap g)).l_unique\n  (gc_map_comap (g.comp f)) (\u03bb _, comap_comap _ _)\n\nvariables {f I J K L}\n\nlemma map_le_of_le_comap : I \u2264 K.comap f \u2192 I.map f \u2264 K :=\n(gc_map_comap f).l_le\n\nlemma le_comap_of_map_le : I.map f \u2264 K \u2192 I \u2264 K.comap f :=\n(gc_map_comap f).le_u\n\nlemma le_comap_map : I \u2264 (I.map f).comap f :=\n(gc_map_comap f).le_u_l _\n\nlemma map_comap_le : (K.comap f).map f \u2264 K :=\n(gc_map_comap f).l_u_le _\n\n@[simp] lemma comap_top : (\u22a4 : ideal S).comap f = \u22a4 :=\n(gc_map_comap f).u_top\n\n@[simp] lemma comap_eq_top_iff {I : ideal S} : I.comap f = \u22a4 \u2194 I = \u22a4 :=\n\u27e8 \u03bb h, I.eq_top_iff_one.mpr (f.map_one \u25b8 mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)),\n  \u03bb h, by rw [h, comap_top] \u27e9\n\n@[simp] lemma map_bot : (\u22a5 : ideal R).map f = \u22a5 :=\n(gc_map_comap f).l_bot\n\nvariables (f I J K L)\n\n@[simp] lemma map_comap_map : ((I.map f).comap f).map f = I.map f :=\ncongr_fun (gc_map_comap f).l_u_l_eq_l I\n\n@[simp] lemma comap_map_comap : ((K.comap f).map f).comap f = K.comap f :=\ncongr_fun (gc_map_comap f).u_l_u_eq_u K\n\nlemma map_sup : (I \u2294 J).map f = I.map f \u2294 J.map f :=\n(gc_map_comap f).l_sup\n\ntheorem comap_inf : comap f (K \u2293 L) = comap f K \u2293 comap f L := rfl\n\nvariables {\u03b9 : Sort*}\n\nlemma map_supr (K : \u03b9 \u2192 ideal R) : (supr K).map f = \u2a06 i, (K i).map f :=\n(gc_map_comap f).l_supr\n\nlemma comap_infi (K : \u03b9 \u2192 ideal S) : (infi K).comap f = \u2a05 i, (K i).comap f :=\n(gc_map_comap f).u_infi\n\nlemma map_Sup (s : set (ideal R)): (Sup s).map f = \u2a06 I \u2208 s, (I : ideal R).map f :=\n(gc_map_comap f).l_Sup\n\nlemma comap_Inf (s : set (ideal S)): (Inf s).comap f = \u2a05 I \u2208 s, (I : ideal S).comap f :=\n(gc_map_comap f).u_Inf\n\nlemma comap_Inf' (s : set (ideal S)) : (Inf s).comap f = \u2a05 I \u2208 (comap f '' s), I :=\ntrans (comap_Inf f s) (by rw infi_image)\n\ntheorem comap_radical : comap f (radical K) = radical (comap f K) :=\nle_antisymm (\u03bb r \u27e8n, hfrnk\u27e9, \u27e8n, show f (r ^ n) \u2208 K,\n  from (f.map_pow r n).symm \u25b8 hfrnk\u27e9)\n(\u03bb r \u27e8n, hfrnk\u27e9, \u27e8n, f.map_pow r n \u25b8 hfrnk\u27e9)\n\ntheorem comap_is_prime [H : is_prime K] : is_prime (comap f K) :=\n\u27e8comap_ne_top f H.ne_top,\n  \u03bb x y h, H.mem_or_mem $ by rwa [mem_comap, ring_hom.map_mul] at h\u27e9\n\n@[simp] lemma map_quotient_self :\n  map (quotient.mk I) I = \u22a5 :=\neq_bot_iff.2 $ ideal.map_le_iff_le_comap.2 $ \u03bb x hx,\n(submodule.mem_bot I.quotient).2 $ ideal.quotient.eq_zero_iff_mem.2 hx\n\nvariables {I J K L}\n\ntheorem map_inf_le : map f (I \u2293 J) \u2264 map f I \u2293 map f J :=\n(gc_map_comap f).monotone_l.map_inf_le _ _\n\ntheorem map_radical_le : map f (radical I) \u2264 radical (map f I) :=\nmap_le_iff_le_comap.2 $ \u03bb r \u27e8n, hrni\u27e9, \u27e8n, f.map_pow r n \u25b8 mem_map_of_mem hrni\u27e9\n\ntheorem le_comap_sup : comap f K \u2294 comap f L \u2264 comap f (K \u2294 L) :=\n(gc_map_comap f).monotone_u.le_map_sup _ _\n\ntheorem le_comap_mul : comap f K * comap f L \u2264 comap f (K * L) :=\nmap_le_iff_le_comap.1 $ (map_mul f (comap f K) (comap f L)).symm \u25b8\nmul_mono (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)\n\nsection surjective\nvariables (hf : function.surjective f)\ninclude hf\n\nopen function\n\ntheorem map_comap_of_surjective (I : ideal S) :\n  map f (comap f I) = I :=\nle_antisymm (map_le_iff_le_comap.2 (le_refl _))\n(\u03bb s hsi, let \u27e8r, hfrs\u27e9 := hf s in\n  hfrs \u25b8 (mem_map_of_mem $ show f r \u2208 I, from hfrs.symm \u25b8 hsi))\n\n/-- `map` and `comap` are adjoint, and the composition `map f \u2218 comap f` is the\n  identity -/\ndef gi_map_comap : galois_insertion (map f) (comap f) :=\ngalois_insertion.monotone_intro\n  ((gc_map_comap f).monotone_u)\n  ((gc_map_comap f).monotone_l)\n  (\u03bb _, le_comap_map)\n  (map_comap_of_surjective _ hf)\n\nlemma map_surjective_of_surjective : surjective (map f) :=\n(gi_map_comap f hf).l_surjective\n\nlemma comap_injective_of_surjective : injective (comap f) :=\n(gi_map_comap f hf).u_injective\n\nlemma map_sup_comap_of_surjective (I J : ideal S) : (I.comap f \u2294 J.comap f).map f = I \u2294 J :=\n(gi_map_comap f hf).l_sup_u _ _\n\nlemma map_supr_comap_of_surjective (K : \u03b9 \u2192 ideal S) : (\u2a06i, (K i).comap f).map f = supr K :=\n(gi_map_comap f hf).l_supr_u _\n\nlemma map_inf_comap_of_surjective (I J : ideal S) : (I.comap f \u2293 J.comap f).map f = I \u2293 J :=\n(gi_map_comap f hf).l_inf_u _ _\n\nlemma map_infi_comap_of_surjective (K : \u03b9 \u2192 ideal S) : (\u2a05i, (K i).comap f).map f = infi K :=\n(gi_map_comap f hf).l_infi_u _\n\ntheorem mem_image_of_mem_map_of_surjective {I : ideal R} {y}\n  (H : y \u2208 map f I) : y \u2208 f '' I :=\nsubmodule.span_induction H (\u03bb _, id) \u27e80, I.zero_mem, f.map_zero\u27e9\n(\u03bb y1 y2 \u27e8x1, hx1i, hxy1\u27e9 \u27e8x2, hx2i, hxy2\u27e9,\n  \u27e8x1 + x2, I.add_mem hx1i hx2i, hxy1 \u25b8 hxy2 \u25b8 f.map_add _ _\u27e9)\n(\u03bb c y \u27e8x, hxi, hxy\u27e9, let \u27e8d, hdc\u27e9 := hf c in \u27e8d \u2022 x, I.smul_mem _ hxi, hdc \u25b8 hxy \u25b8 f.map_mul _ _\u27e9)\n\nlemma mem_map_iff_of_surjective {I : ideal R} {y} :\n  y \u2208 map f I \u2194 \u2203 x, x \u2208 I \u2227 f x = y :=\n\u27e8\u03bb h, (set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h),\n  \u03bb \u27e8x, hx\u27e9, hx.right \u25b8 (mem_map_of_mem hx.left)\u27e9\n\ntheorem comap_map_of_surjective (I : ideal R) :\n  comap f (map f I) = I \u2294 comap f \u22a5 :=\nle_antisymm (assume r h, let \u27e8s, hsi, hfsr\u27e9 := mem_image_of_mem_map_of_surjective f hf h in\n  submodule.mem_sup.2 \u27e8s, hsi, r - s, (submodule.mem_bot S).2 $ by rw [f.map_sub, hfsr, sub_self],\n  add_sub_cancel'_right s r\u27e9)\n(sup_le (map_le_iff_le_comap.1 (le_refl _)) (comap_mono bot_le))\n\nlemma le_map_of_comap_le_of_surjective : comap f K \u2264 I \u2192 K \u2264 map f I :=\n\u03bb h, (map_comap_of_surjective f hf K) \u25b8 map_mono h\n\n/-- Correspondence theorem -/\ndef rel_iso_of_surjective :\n  ideal S \u2243o { p : ideal R // comap f \u22a5 \u2264 p } :=\n{ to_fun := \u03bb J, \u27e8comap f J, comap_mono bot_le\u27e9,\n  inv_fun := \u03bb I, map f I.1,\n  left_inv := \u03bb J, map_comap_of_surjective f hf J,\n  right_inv := \u03bb I, subtype.eq $ show comap f (map f I.1) = I.1,\n    from (comap_map_of_surjective f hf I).symm \u25b8 le_antisymm\n      (sup_le (le_refl _) I.2) le_sup_left,\n  map_rel_iff' := \u03bb I1 I2, \u27e8\u03bb H, map_comap_of_surjective f hf I1 \u25b8\n    map_comap_of_surjective f hf I2 \u25b8 map_mono H, comap_mono\u27e9 }\n\n/-- The map on ideals induced by a surjective map preserves inclusion. -/\ndef order_embedding_of_surjective : ideal S \u21aao ideal R :=\n(rel_iso_of_surjective f hf).to_rel_embedding.trans (subtype.rel_embedding _ _)\n\ntheorem map_eq_top_or_is_maximal_of_surjective (H : is_maximal I) :\n  (map f I) = \u22a4 \u2228 is_maximal (map f I) :=\nbegin\n  refine or_iff_not_imp_left.2 (\u03bb ne_top, \u27e8\u27e8\u03bb h, ne_top h, \u03bb J hJ, _\u27e9\u27e9),\n  { refine (rel_iso_of_surjective f hf).injective\n      (subtype.ext_iff.2 (eq.trans (H.1.2 (comap f J) (lt_of_le_of_ne _ _)) comap_top.symm)),\n    { exact (map_le_iff_le_comap).1 (le_of_lt hJ) },\n    { exact \u03bb h, hJ.right (le_map_of_comap_le_of_surjective f hf (le_of_eq h.symm)) } }\nend\n\ntheorem comap_is_maximal_of_surjective [H : is_maximal K] : is_maximal (comap f K) :=\nbegin\n  refine \u27e8\u27e8comap_ne_top _ H.1.1, \u03bb J hJ, _\u27e9\u27e9,\n  suffices : map f J = \u22a4,\n  { replace this := congr_arg (comap f) this,\n    rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this,\n    rw eq_top_iff,\n    exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono (bot_le)) (le_of_lt hJ))) },\n  refine H.1.2 (map f J) (lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ))\n    (\u03bb h, ne_of_lt hJ (trans (congr_arg (comap f) h) _))),\n  rw [comap_map_of_surjective _ hf, sup_eq_left],\n  exact le_trans (comap_mono bot_le) (le_of_lt hJ)\nend\n\nend surjective\n\nlemma mem_quotient_iff_mem (hIJ : I \u2264 J) {x : R} :\n  quotient.mk I x \u2208 J.map (quotient.mk I) \u2194 x \u2208 J :=\nbegin\n  refine iff.trans (mem_map_iff_of_surjective _ quotient.mk_surjective) _,\n  split,\n  { rintros \u27e8x, x_mem, x_eq\u27e9,\n    simpa using J.add_mem (hIJ (quotient.eq.mp x_eq.symm)) x_mem },\n  { intro x_mem,\n    exact \u27e8x, x_mem, rfl\u27e9 }\nend\n\nsection injective\nvariables (hf : function.injective f)\ninclude hf\n\nopen function\n\nlemma comap_bot_le_of_injective : comap f \u22a5 \u2264 I :=\nbegin\n  refine le_trans (\u03bb x hx, _) bot_le,\n  rw [mem_comap, submodule.mem_bot, \u2190 ring_hom.map_zero f] at hx,\n  exact eq.symm (hf hx) \u25b8 (submodule.zero_mem \u22a5)\nend\n\nend injective\n\nsection bijective\nvariables (hf : function.bijective f)\ninclude hf\n\nopen function\n\n/-- Special case of the correspondence theorem for isomorphic rings -/\ndef rel_iso_of_bijective : ideal S \u2243o ideal R :=\n{ to_fun := comap f,\n  inv_fun := map f,\n  left_inv := (rel_iso_of_surjective f hf.right).left_inv,\n  right_inv := \u03bb J, subtype.ext_iff.1\n    ((rel_iso_of_surjective f hf.right).right_inv \u27e8J, comap_bot_le_of_injective f hf.left\u27e9),\n  map_rel_iff' := (rel_iso_of_surjective f hf.right).map_rel_iff' }\n\nlemma comap_le_iff_le_map : comap f K \u2264 I \u2194 K \u2264 map f I :=\n\u27e8\u03bb h, le_map_of_comap_le_of_surjective f hf.right h,\n \u03bb h, ((rel_iso_of_bijective f hf).right_inv I) \u25b8 comap_mono h\u27e9\n\ntheorem map.is_maximal (H : is_maximal I) : is_maximal (map f I) :=\nby refine or_iff_not_imp_left.1\n  (map_eq_top_or_is_maximal_of_surjective f hf.right H) (\u03bb h, H.1.1 _);\ncalc I = comap f (map f I) : ((rel_iso_of_bijective f hf).right_inv I).symm\n   ... = comap f \u22a4 : by rw h\n   ... = \u22a4 : by rw comap_top\n\nend bijective\n\nlemma ring_equiv.bot_maximal_iff (e : R \u2243+* S) :\n  (\u22a5 : ideal R).is_maximal \u2194 (\u22a5 : ideal S).is_maximal :=\n\u27e8\u03bb h, (@map_bot _ _ _ _ e.to_ring_hom) \u25b8 map.is_maximal e.to_ring_hom e.bijective h,\n  \u03bb h, (@map_bot _ _ _ _ e.symm.to_ring_hom) \u25b8 map.is_maximal e.symm.to_ring_hom e.symm.bijective h\u27e9\n\nend map_and_comap\n\nsection is_primary\nvariables {R : Type u} [comm_ring R]\n\n/-- A proper ideal `I` is primary iff `xy \u2208 I` implies `x \u2208 I` or `y \u2208 radical I`. -/\ndef is_primary (I : ideal R) : Prop :=\nI \u2260 \u22a4 \u2227 \u2200 {x y : R}, x * y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 radical I\n\ntheorem is_primary.to_is_prime (I : ideal R) (hi : is_prime I) : is_primary I :=\n\u27e8hi.1, \u03bb x y hxy, (hi.mem_or_mem hxy).imp id $ \u03bb hyi, le_radical hyi\u27e9\n\ntheorem mem_radical_of_pow_mem {I : ideal R} {x : R} {m : \u2115} (hx : x ^ m \u2208 radical I) :\n  x \u2208 radical I :=\nradical_idem I \u25b8 \u27e8m, hx\u27e9\n\ntheorem is_prime_radical {I : ideal R} (hi : is_primary I) : is_prime (radical I) :=\n\u27e8mt radical_eq_top.1 hi.1, \u03bb x y \u27e8m, hxy\u27e9, begin\n  rw mul_pow at hxy, cases hi.2 hxy,\n  { exact or.inl \u27e8m, h\u27e9 },\n  { exact or.inr (mem_radical_of_pow_mem h) }\nend\u27e9\n\ntheorem is_primary_inf {I J : ideal R} (hi : is_primary I) (hj : is_primary J)\n  (hij : radical I = radical J) : is_primary (I \u2293 J) :=\n\u27e8ne_of_lt $ lt_of_le_of_lt inf_le_left (lt_top_iff_ne_top.2 hi.1), \u03bb x y \u27e8hxyi, hxyj\u27e9,\nbegin\n  rw [radical_inf, hij, inf_idem],\n  cases hi.2 hxyi with hxi hyi, cases hj.2 hxyj with hxj hyj,\n  { exact or.inl \u27e8hxi, hxj\u27e9 },\n  { exact or.inr hyj },\n  { rw hij at hyi, exact or.inr hyi }\nend\u27e9\n\nend is_primary\n\nend ideal\n\nnamespace ring_hom\n\nvariables {R : Type u} {S : Type v} [comm_ring R]\n\nsection comm_ring\nvariables [comm_ring S] (f : R \u2192+* S)\n\n/-- Kernel of a ring homomorphism as an ideal of the domain. -/\ndef ker : ideal R := ideal.comap f \u22a5\n\n/-- An element is in the kernel if and only if it maps to zero.-/\nlemma mem_ker {r} : r \u2208 ker f \u2194 f r = 0 :=\nby rw [ker, ideal.mem_comap, submodule.mem_bot]\n\nlemma ker_eq : ((ker f) : set R) = is_add_group_hom.ker f := rfl\n\nlemma ker_eq_comap_bot (f : R \u2192+* S) : f.ker = ideal.comap f \u22a5 := rfl\n\nlemma injective_iff_ker_eq_bot : function.injective f \u2194 ker f = \u22a5 :=\nby rw [set_like.ext'_iff, ker_eq]; exact is_add_group_hom.injective_iff_trivial_ker f\n\nlemma ker_eq_bot_iff_eq_zero : ker f = \u22a5 \u2194 \u2200 x, f x = 0 \u2192 x = 0 :=\nby rw [set_like.ext'_iff, ker_eq]; exact is_add_group_hom.trivial_ker_iff_eq_zero f\n\n/-- If the target is not the zero ring, then one is not in the kernel.-/\nlemma not_one_mem_ker [nontrivial S] (f : R \u2192+* S) : (1:R) \u2209 ker f :=\nby { rw [mem_ker, f.map_one], exact one_ne_zero }\n\n@[simp] lemma ker_coe_equiv (f : R \u2243+* S) : ker (f : R \u2192+* S) = \u22a5 :=\nby simpa only [\u2190injective_iff_ker_eq_bot] using f.injective\n\n/-- The induced map from the quotient by the kernel to the codomain.\n\nThis is an isomorphism if `f` has a right inverse (`quotient_ker_equiv_of_right_inverse`) /\nis surjective (`quotient_ker_equiv_of_surjective`).\n-/\ndef ker_lift (f : R \u2192+* S) : f.ker.quotient \u2192+* S :=\nideal.quotient.lift _ f $ \u03bb r, f.mem_ker.mp\n\n@[simp]\nlemma ker_lift_mk (f : R \u2192+* S) (r : R) : ker_lift f (ideal.quotient.mk f.ker r) = f r :=\nideal.quotient.lift_mk _ _ _\n\n/-- The induced map from the quotient by the kernel is injective. -/\nlemma ker_lift_injective (f : R \u2192+* S) : function.injective (ker_lift f) :=\nassume a b, quotient.induction_on\u2082' a b $\n  assume a b (h : f a = f b), quotient.sound' $\nshow a - b \u2208 ker f, by rw [mem_ker, map_sub, h, sub_self]\n\nvariable {f}\n\n/-- The first isomorphism theorem for commutative rings, computable version. -/\ndef quotient_ker_equiv_of_right_inverse\n  {g : S \u2192 R} (hf : function.right_inverse g f) :\n  f.ker.quotient \u2243+* S :=\n{ to_fun := ker_lift f,\n  inv_fun := (ideal.quotient.mk f.ker) \u2218 g,\n  left_inv := begin\n    rintro \u27e8x\u27e9,\n    apply ker_lift_injective,\n    simp [hf (f x)],\n  end,\n  right_inv := hf,\n  ..ker_lift f}\n\n@[simp]\nlemma quotient_ker_equiv_of_right_inverse.apply {g : S \u2192 R} (hf : function.right_inverse g f)\n  (x : f.ker.quotient) : quotient_ker_equiv_of_right_inverse hf x = ker_lift f x := rfl\n\n@[simp]\nlemma quotient_ker_equiv_of_right_inverse.symm.apply {g : S \u2192 R} (hf : function.right_inverse g f)\n  (x : S) : (quotient_ker_equiv_of_right_inverse hf).symm x = ideal.quotient.mk f.ker (g x) := rfl\n\n/-- The first isomorphism theorem for commutative rings. -/\nnoncomputable def quotient_ker_equiv_of_surjective (hf : function.surjective f) :\n  f.ker.quotient \u2243+* S :=\nquotient_ker_equiv_of_right_inverse (classical.some_spec hf.has_right_inverse)\n\nend comm_ring\n\n/-- The kernel of a homomorphism to an integral domain is a prime ideal.-/\nlemma ker_is_prime [integral_domain S] (f : R \u2192+* S) :\n  (ker f).is_prime :=\n\u27e8by { rw [ne.def, ideal.eq_top_iff_one], exact not_one_mem_ker f },\n\u03bb x y, by simpa only [mem_ker, f.map_mul] using @eq_zero_or_eq_zero_of_mul_eq_zero S _ _ _ _ _\u27e9\n\nend ring_hom\n\nnamespace ideal\n\nvariables {R : Type*} {S : Type*} [comm_ring R] [comm_ring S]\n\nlemma map_eq_bot_iff_le_ker {I : ideal R} (f : R \u2192+* S) : I.map f = \u22a5 \u2194 I \u2264 f.ker :=\nby rw [ring_hom.ker, eq_bot_iff, map_le_iff_le_comap]\n\n@[simp] lemma mk_ker {I : ideal R} : (quotient.mk I).ker = I :=\nby ext; rw [ring_hom.ker, mem_comap, submodule.mem_bot, quotient.eq_zero_iff_mem]\n\nlemma ker_le_comap {K : ideal S} (f : R \u2192+* S) : f.ker \u2264 comap f K :=\n\u03bb x hx, mem_comap.2 (((ring_hom.mem_ker f).1 hx).symm \u25b8 K.zero_mem)\n\nlemma map_Inf {A : set (ideal R)} {f : R \u2192+* S} (hf : function.surjective f) :\n  (\u2200 J \u2208 A, ring_hom.ker f \u2264 J) \u2192 map f (Inf A) = Inf (map f '' A) :=\nbegin\n  refine \u03bb h, le_antisymm (le_Inf _) _,\n  { intros j hj y hy,\n    cases (mem_map_iff_of_surjective f hf).1 hy with x hx,\n    cases (set.mem_image _ _ _).mp hj with J hJ,\n    rw [\u2190 hJ.right, \u2190 hx.right],\n    exact mem_map_of_mem (Inf_le_of_le hJ.left (le_of_eq rfl) hx.left) },\n  { intros y hy,\n    cases hf y with x hx,\n    refine hx \u25b8 (mem_map_of_mem _),\n    have : \u2200 I \u2208 A, y \u2208 map f I, by simpa using hy,\n    rw [submodule.mem_Inf],\n    intros J hJ,\n    rcases (mem_map_iff_of_surjective f hf).1 (this J hJ) with \u27e8x', hx', rfl\u27e9,\n    have : x - x' \u2208 J,\n    { apply h J hJ,\n      rw [ring_hom.mem_ker, ring_hom.map_sub, hx, sub_self] },\n    simpa only [sub_add_cancel] using J.add_mem this hx' }\nend\n\ntheorem map_is_prime_of_surjective {f : R \u2192+* S} (hf : function.surjective f) {I : ideal R}\n  [H : is_prime I] (hk : ring_hom.ker f \u2264 I) : is_prime (map f I) :=\nbegin\n  refine \u27e8\u03bb h, H.ne_top (eq_top_iff.2 _), \u03bb x y, _\u27e9,\n  { replace h := congr_arg (comap f) h,\n    rw [comap_map_of_surjective _ hf, comap_top] at h,\n    exact h \u25b8 sup_le (le_of_eq rfl) hk },\n  { refine \u03bb hxy, (hf x).rec_on (\u03bb a ha, (hf y).rec_on (\u03bb b hb, _)),\n    rw [\u2190 ha, \u2190 hb, \u2190 ring_hom.map_mul, mem_map_iff_of_surjective _ hf] at hxy,\n    rcases hxy with \u27e8c, hc, hc'\u27e9,\n    rw [\u2190 sub_eq_zero, \u2190 ring_hom.map_sub] at hc',\n    have : a * b \u2208 I,\n    { convert I.sub_mem hc (hk (hc' : c - a * b \u2208 f.ker)),\n      ring },\n    exact (H.mem_or_mem this).imp (\u03bb h, ha \u25b8 mem_map_of_mem h) (\u03bb h, hb \u25b8 mem_map_of_mem h) }\nend\n\ntheorem map_is_prime_of_equiv (f : R \u2243+* S) {I : ideal R} [is_prime I] :\n  is_prime (map (f : R \u2192+* S) I) :=\nmap_is_prime_of_surjective f.surjective $ by simp\n\ntheorem map_radical_of_surjective {f : R \u2192+* S} (hf : function.surjective f) {I : ideal R}\n  (h : ring_hom.ker f \u2264 I) : map f (I.radical) = (map f I).radical :=\nbegin\n  rw [radical_eq_Inf, radical_eq_Inf],\n  have : \u2200 J \u2208 {J : ideal R | I \u2264 J \u2227 J.is_prime}, f.ker \u2264 J := \u03bb J hJ, le_trans h hJ.left,\n  convert map_Inf hf this,\n  refine funext (\u03bb j, propext \u27e8_, _\u27e9),\n  { rintros \u27e8hj, hj'\u27e9,\n    haveI : j.is_prime := hj',\n    exact \u27e8comap f j, \u27e8\u27e8map_le_iff_le_comap.1 hj, comap_is_prime f j\u27e9,\n      map_comap_of_surjective f hf j\u27e9\u27e9 },\n  { rintro \u27e8J, \u27e8hJ, hJ'\u27e9\u27e9,\n    haveI : J.is_prime := hJ.right,\n    refine \u27e8hJ' \u25b8 map_mono hJ.left, hJ' \u25b8 map_is_prime_of_surjective hf (le_trans h hJ.left)\u27e9 },\nend\n\n@[simp] lemma bot_quotient_is_maximal_iff (I : ideal R) :\n  (\u22a5 : ideal I.quotient).is_maximal \u2194 I.is_maximal :=\n\u27e8\u03bb hI, (@mk_ker _ _ I) \u25b8\n  @comap_is_maximal_of_surjective _ _ _ _ (quotient.mk I) \u22a5 quotient.mk_surjective hI,\n \u03bb hI, @bot_is_maximal _ (@quotient.field _ _ I hI) \u27e9\n\nsection quotient_algebra\n\nvariables (R) {A : Type*} [comm_ring A] [algebra R A]\n\n/-- The `R`-algebra structure on `A/I` for an `R`-algebra `A` -/\ninstance {I : ideal A} : algebra R (ideal.quotient I) :=\n(ring_hom.comp (ideal.quotient.mk I) (algebra_map R A)).to_algebra\n\n/-- The canonical morphism `A \u2192\u2090[R] I.quotient` as morphism of `R`-algebras, for `I` an ideal of\n`A`, where `A` is an `R`-algebra. -/\ndef quotient.mk\u2090 (I : ideal A) : A \u2192\u2090[R] I.quotient :=\n\u27e8\u03bb a, submodule.quotient.mk a, rfl, \u03bb _ _, rfl, rfl, \u03bb _ _, rfl, \u03bb _, rfl\u27e9\n\nlemma quotient.alg_map_eq (I : ideal A) :\n  algebra_map R I.quotient = (algebra_map A I.quotient).comp (algebra_map R A) :=\nby simp only [ring_hom.algebra_map_to_algebra, ring_hom.comp_id]\n\ninstance [algebra S A] [algebra S R] [is_scalar_tower S R A]\n  {I : ideal A} : is_scalar_tower S R (ideal.quotient I) :=\nis_scalar_tower.of_algebra_map_eq' $ by\n  rw [quotient.alg_map_eq R, quotient.alg_map_eq S, ring_hom.comp_assoc,\n    is_scalar_tower.algebra_map_eq S R A]\n\nlemma quotient.mk\u2090_to_ring_hom (I : ideal A) :\n  (quotient.mk\u2090 R I).to_ring_hom = ideal.quotient.mk I := rfl\n\n@[simp] lemma quotient.mk\u2090_eq_mk (I : ideal A) :\n  \u21d1(quotient.mk\u2090 R I) = ideal.quotient.mk I := rfl\n\n/-- The canonical morphism `A \u2192\u2090[R] I.quotient` is surjective. -/\nlemma quotient.mk\u2090_surjective (I : ideal A) : function.surjective (quotient.mk\u2090 R I) :=\nsurjective_quot_mk _\n\n/-- The kernel of `A \u2192\u2090[R] I.quotient` is `I`. -/\n@[simp]\nlemma quotient.mk\u2090_ker (I : ideal A) : (quotient.mk\u2090 R I).to_ring_hom.ker = I :=\nideal.mk_ker\n\nvariables {R} {B : Type*} [comm_ring B] [algebra R B]\n\nlemma ker_lift.map_smul (f : A \u2192\u2090[R] B) (r : R) (x : f.to_ring_hom.ker.quotient) :\n  f.to_ring_hom.ker_lift (r \u2022 x) = r \u2022 f.to_ring_hom.ker_lift x :=\nbegin\n  obtain \u27e8a, rfl\u27e9 := quotient.mk\u2090_surjective R _ x,\n  rw [\u2190 alg_hom.map_smul, quotient.mk\u2090_eq_mk, ring_hom.ker_lift_mk],\n  exact f.map_smul _ _\nend\n\n/-- The induced algebras morphism from the quotient by the kernel to the codomain.\n\nThis is an isomorphism if `f` has a right inverse (`quotient_ker_alg_equiv_of_right_inverse`) /\nis surjective (`quotient_ker_alg_equiv_of_surjective`).\n-/\ndef ker_lift_alg (f : A \u2192\u2090[R] B) : f.to_ring_hom.ker.quotient \u2192\u2090[R] B :=\nalg_hom.mk' f.to_ring_hom.ker_lift (\u03bb _ _, ker_lift.map_smul f _ _)\n\n@[simp]\nlemma ker_lift_alg_mk (f : A \u2192\u2090[R] B) (a : A) :\n  ker_lift_alg f (quotient.mk f.to_ring_hom.ker a) = f a := rfl\n\n@[simp]\nlemma ker_lift_alg_to_ring_hom (f : A \u2192\u2090[R] B) :\n  (ker_lift_alg f).to_ring_hom = ring_hom.ker_lift f := rfl\n\n/-- The induced algebra morphism from the quotient by the kernel is injective. -/\nlemma ker_lift_alg_injective (f : A \u2192\u2090[R] B) : function.injective (ker_lift_alg f) :=\nring_hom.ker_lift_injective f\n\n/-- The first isomorphism theorem for agebras, computable version. -/\ndef quotient_ker_alg_equiv_of_right_inverse\n  {f : A \u2192\u2090[R] B} {g : B \u2192 A} (hf : function.right_inverse g f) :\n  f.to_ring_hom.ker.quotient \u2243\u2090[R] B :=\n{ ..ring_hom.quotient_ker_equiv_of_right_inverse (\u03bb x, show f.to_ring_hom (g x) = x, from hf x),\n  ..ker_lift_alg f}\n\n@[simp]\nlemma quotient_ker_alg_equiv_of_right_inverse.apply {f : A \u2192\u2090[R] B} {g : B \u2192 A}\n  (hf : function.right_inverse g f) (x : f.to_ring_hom.ker.quotient) :\n  quotient_ker_alg_equiv_of_right_inverse hf x = ker_lift_alg f x := rfl\n\n@[simp]\nlemma quotient_ker_alg_equiv_of_right_inverse_symm.apply {f : A \u2192\u2090[R] B} {g : B \u2192 A}\n  (hf : function.right_inverse g f) (x : B) :\n  (quotient_ker_alg_equiv_of_right_inverse hf).symm x = quotient.mk\u2090 R f.to_ring_hom.ker (g x) :=\n  rfl\n\n/-- The first isomorphism theorem for agebras. -/\nnoncomputable def quotient_ker_alg_equiv_of_surjective\n  {f : A \u2192\u2090[R] B} (hf : function.surjective f) : f.to_ring_hom.ker.quotient \u2243\u2090[R] B :=\nquotient_ker_alg_equiv_of_right_inverse (classical.some_spec hf.has_right_inverse)\n\n/-- The ring hom `R/I \u2192+* S/J` induced by a ring hom `f : R \u2192+* S` with `I \u2264 f\u207b\u00b9(J)` -/\ndef quotient_map {I : ideal R} (J : ideal S) (f : R \u2192+* S) (hIJ : I \u2264 J.comap f) :\n  I.quotient \u2192+* J.quotient :=\n(quotient.lift I ((quotient.mk J).comp f) (\u03bb _ ha,\n  by simpa [function.comp_app, ring_hom.coe_comp, quotient.eq_zero_iff_mem] using hIJ ha))\n\n@[simp]\nlemma quotient_map_mk {J : ideal R} {I : ideal S} {f : R \u2192+* S} {H : J \u2264 I.comap f}\n  {x : R} : quotient_map I f H (quotient.mk J x) = quotient.mk I (f x) :=\nquotient.lift_mk J _ _\n\nlemma quotient_map_comp_mk {J : ideal R} {I : ideal S} {f : R \u2192+* S} (H : J \u2264 I.comap f) :\n  (quotient_map I f H).comp (quotient.mk J) = (quotient.mk I).comp f :=\nring_hom.ext (\u03bb x, by simp only [function.comp_app, ring_hom.coe_comp, ideal.quotient_map_mk])\n\n/-- If `f : R \u2243+* S` is a ring isomorphism and `I : ideal R`, then `map f (map f.symm) = I`. -/\n@[simp]\nlemma map_of_equiv (I : ideal R) (f : R \u2243+* S) : (I.map (f : R \u2192+* S)).map (f.symm : S \u2192+* R) = I :=\nby simp [\u2190 ring_equiv.to_ring_hom_eq_coe, map_map]\n\n/-- If `f : R \u2243+* S` is a ring isomorphism and `I : ideal R`, then `comap f.symm (comap f) = I`. -/\n@[simp]\nlemma comap_of_equiv (I : ideal R) (f : R \u2243+* S) :\n  (I.comap (f.symm : S \u2192+* R)).comap (f : R \u2192+* S) = I :=\nby simp [\u2190 ring_equiv.to_ring_hom_eq_coe, comap_comap]\n\n/-- If `f : R \u2243+* S` is a ring isomorphism and `I : ideal R`, then `map f I = comap f.symm I`. -/\nlemma map_comap_of_equiv (I : ideal R) (f : R \u2243+* S) : I.map (f : R \u2192+* S) = I.comap f.symm :=\nle_antisymm (le_comap_of_map_le (map_of_equiv I f).le)\n  (le_map_of_comap_le_of_surjective _ f.surjective (comap_of_equiv I f).le)\n\n/-- The ring equiv `R/I \u2243+* S/J` induced by a ring equiv `f : R \u2243+** S`,  where `J = f(I)`. -/\n@[simps]\ndef quotient_equiv (I : ideal R) (J : ideal S) (f : R \u2243+* S) (hIJ : J = I.map (f : R \u2192+* S)) :\n  I.quotient \u2243+* J.quotient :=\n{ inv_fun := quotient_map I \u2191f.symm (by {rw hIJ, exact le_of_eq (map_comap_of_equiv I f)}),\n  left_inv := by {rintro \u27e8r\u27e9, simp },\n  right_inv := by {rintro \u27e8s\u27e9, simp },\n  ..quotient_map J \u2191f (by {rw hIJ, exact @le_comap_map _ S _ _ _ _}) }\n\n/-- `H` and `h` are kept as separate hypothesis since H is used in constructing the quotient map. -/\nlemma quotient_map_injective' {J : ideal R} {I : ideal S} {f : R \u2192+* S} {H : J \u2264 I.comap f}\n  (h : I.comap f \u2264 J) : function.injective (quotient_map I f H) :=\nbegin\n  refine (quotient_map I f H).injective_iff.2 (\u03bb a ha, _),\n  obtain \u27e8r, rfl\u27e9 := quotient.mk_surjective a,\n  rw [quotient_map_mk, quotient.eq_zero_iff_mem] at ha,\n  exact (quotient.eq_zero_iff_mem).mpr (h ha),\nend\n\n/-- If we take `J = I.comap f` then `quotient_map` is injective automatically. -/\nlemma quotient_map_injective {I : ideal S} {f : R \u2192+* S} :\n  function.injective (quotient_map I f le_rfl) :=\nquotient_map_injective' le_rfl\n\nlemma quotient_map_surjective {J : ideal R} {I : ideal S} {f : R \u2192+* S} {H : J \u2264 I.comap f}\n  (hf : function.surjective f) : function.surjective (quotient_map I f H) :=\n\u03bb x, let \u27e8x, hx\u27e9 := quotient.mk_surjective x in\n  let \u27e8y, hy\u27e9 := hf x in \u27e8(quotient.mk J) y, by simp [hx, hy]\u27e9\n\n/-- Commutativity of a square is preserved when taking quotients by an ideal. -/\nlemma comp_quotient_map_eq_of_comp_eq {R' S' : Type*} [comm_ring R'] [comm_ring S']\n  {f : R \u2192+* S} {f' : R' \u2192+* S'} {g : R \u2192+* R'} {g' : S \u2192+* S'} (hfg : f'.comp g = g'.comp f)\n  (I : ideal S') : (quotient_map I g' le_rfl).comp (quotient_map (I.comap g') f le_rfl) =\n    (quotient_map I f' le_rfl).comp (quotient_map (I.comap f') g\n      (le_of_eq (trans (comap_comap f g') (hfg \u25b8 (comap_comap g f'))))) :=\nbegin\n  refine ring_hom.ext (\u03bb a, _),\n  obtain \u27e8r, rfl\u27e9 := quotient.mk_surjective a,\n  simp only [ring_hom.comp_apply, quotient_map_mk],\n  exact congr_arg (quotient.mk I) (trans (g'.comp_apply f r).symm (hfg \u25b8 (f'.comp_apply g r))),\nend\n\nvariables {I : ideal R} {J: ideal S} [algebra R S]\n\n/-- The algebra hom `A/I \u2192+* S/J` induced by an algebra hom `f : A \u2192\u2090[R] S` with `I \u2264 f\u207b\u00b9(J)`. -/\ndef quotient_map\u2090 {I : ideal A} (J : ideal S) (f : A \u2192\u2090[R] S) (hIJ : I \u2264 J.comap f) :\n  I.quotient \u2192\u2090[R] J.quotient :=\n{ commutes' := \u03bb r,\n  begin\n    have h : (algebra_map R I.quotient) r = (quotient.mk I) (algebra_map R A r) := rfl,\n    simpa [h]\n  end\n  ..quotient_map J \u2191f hIJ }\n\n@[simp]\nlemma quotient_map_mk\u2090 {I : ideal A} (J : ideal S) (f : A \u2192\u2090[R] S) (H : I \u2264 J.comap f)\n  {x : A} : quotient_map\u2090 J f H (quotient.mk I x) = quotient.mk\u2090 R J (f x) := rfl\n\nlemma quotient_map_comp_mk\u2090 {I : ideal A} (J : ideal S) (f : A \u2192\u2090[R] S) (H : I \u2264 J.comap f) :\n  (quotient_map\u2090 J f H).comp (quotient.mk\u2090 R I) = (quotient.mk\u2090 R J).comp f :=\nalg_hom.ext (\u03bb x, by simp only [quotient_map_mk\u2090, quotient.mk\u2090_eq_mk, alg_hom.comp_apply])\n\n/-- The algebra equiv `A/I \u2243\u2090[R] S/J` induced by an algebra equiv `f : A \u2243\u2090[R] S`,\nwhere`J = f(I)`. -/\ndef quotient_equiv_alg (I : ideal A) (J : ideal S) (f : A \u2243\u2090[R] S) (hIJ : J = I.map (f : A \u2192+* S)) :\n  I.quotient \u2243\u2090[R] J.quotient :=\n{ commutes' := \u03bb r,\n  begin\n    have h : (algebra_map R I.quotient) r = (quotient.mk I) (algebra_map R A r) := rfl,\n    simpa [h]\n  end,\n  ..quotient_equiv I J (f : A \u2243+* S) hIJ }\n\n@[priority 100]\ninstance quotient_algebra : algebra (J.comap (algebra_map R S)).quotient J.quotient :=\n(quotient_map J (algebra_map R S) (le_of_eq rfl)).to_algebra\n\nlemma algebra_map_quotient_injective :\n  function.injective (algebra_map (J.comap (algebra_map R S)).quotient J.quotient) :=\nbegin\n  rintros \u27e8a\u27e9 \u27e8b\u27e9 hab,\n  replace hab := quotient.eq.mp hab,\n  rw \u2190 ring_hom.map_sub at hab,\n  exact quotient.eq.mpr hab\nend\n\nend quotient_algebra\n\nend ideal\n\nnamespace submodule\n\nvariables {R : Type u} {M : Type v}\nvariables [comm_ring R] [add_comm_group M] [module R M]\n\n-- It is even a semialgebra. But those aren't in mathlib yet.\n\ninstance module_submodule : module (ideal R) (submodule R M) :=\n{ smul_add := smul_sup,\n  add_smul := sup_smul,\n  mul_smul := submodule.smul_assoc,\n  one_smul := by simp,\n  zero_smul := bot_smul,\n  smul_zero := smul_bot }\n\nend submodule\n\nnamespace ring_hom\nvariables {A B C : Type*} [comm_ring A] [comm_ring B] [comm_ring C]\nvariables (f : A \u2192+* B) (f_inv : B \u2192 A)\n\n/-- Auxiliary definition used to define `lift_of_right_inverse` -/\ndef lift_of_right_inverse_aux\n  (hf : function.right_inverse f_inv f) (g : A \u2192+* C) (hg : f.ker \u2264 g.ker) :\n  B \u2192+* C :=\n{ to_fun := \u03bb b, g (f_inv b),\n  map_one' :=\n  begin\n    rw [\u2190 g.map_one, \u2190 sub_eq_zero, \u2190 g.map_sub, \u2190 g.mem_ker],\n    apply hg,\n    rw [f.mem_ker, f.map_sub, sub_eq_zero, f.map_one],\n    exact hf 1\n  end,\n  map_mul' :=\n  begin\n    intros x y,\n    rw [\u2190 g.map_mul, \u2190 sub_eq_zero, \u2190 g.map_sub, \u2190 g.mem_ker],\n    apply hg,\n    rw [f.mem_ker, f.map_sub, sub_eq_zero, f.map_mul],\n    simp only [hf _],\n  end,\n  .. add_monoid_hom.lift_of_right_inverse f.to_add_monoid_hom f_inv hf \u27e8g.to_add_monoid_hom, hg\u27e9 }\n\n@[simp] lemma lift_of_right_inverse_aux_comp_apply\n  (hf : function.right_inverse f_inv f) (g : A \u2192+* C) (hg : f.ker \u2264 g.ker) (a : A) :\n  (f.lift_of_right_inverse_aux f_inv hf g hg) (f a) = g a :=\nf.to_add_monoid_hom.lift_of_right_inverse_comp_apply f_inv hf \u27e8g.to_add_monoid_hom, hg\u27e9 a\n\n/-- `lift_of_right_inverse f hf g hg` is the unique ring homomorphism `\u03c6`\n\n* such that `\u03c6.comp f = g` (`ring_hom.lift_of_right_inverse_comp`),\n* where `f : A \u2192+* B` is has a right_inverse `f_inv` (`hf`),\n* and `g : B \u2192+* C` satisfies `hg : f.ker \u2264 g.ker`.\n\nSee `ring_hom.eq_lift_of_right_inverse` for the uniqueness lemma.\n\n```\n   A .\n   |  \\\n f |   \\ g\n   |    \\\n   v     \\\u231f\n   B ----> C\n      \u2203!\u03c6\n```\n-/\ndef lift_of_right_inverse\n  (hf : function.right_inverse f_inv f) : {g : A \u2192+* C // f.ker \u2264 g.ker} \u2243 (B \u2192+* C) :=\n{ to_fun := \u03bb g, f.lift_of_right_inverse_aux f_inv hf g.1 g.2,\n  inv_fun := \u03bb \u03c6, \u27e8\u03c6.comp f, \u03bb x hx, (mem_ker _).mpr $ by simp [(mem_ker _).mp hx]\u27e9,\n  left_inv := \u03bb g, by {\n    ext,\n    simp only [comp_apply, lift_of_right_inverse_aux_comp_apply, subtype.coe_mk,\n      subtype.val_eq_coe], },\n  right_inv := \u03bb \u03c6, by {\n    ext b,\n    simp [lift_of_right_inverse_aux, hf b], } }\n\n/-- A non-computable version of `ring_hom.lift_of_right_inverse` for when no computable right\ninverse is available, that uses `function.surj_inv`. -/\n@[simp]\nnoncomputable abbreviation lift_of_surjective\n  (hf : function.surjective f) : {g : A \u2192+* C // f.ker \u2264 g.ker} \u2243 (B \u2192+* C) :=\nf.lift_of_right_inverse (function.surj_inv hf) (function.right_inverse_surj_inv hf)\n\nlemma lift_of_right_inverse_comp_apply\n  (hf : function.right_inverse f_inv f) (g : {g : A \u2192+* C // f.ker \u2264 g.ker}) (x : A) :\n  (f.lift_of_right_inverse f_inv hf g) (f x) = g x :=\nf.lift_of_right_inverse_aux_comp_apply f_inv hf g.1 g.2 x\n\nlemma lift_of_right_inverse_comp (hf : function.right_inverse f_inv f)\n  (g : {g : A \u2192+* C // f.ker \u2264 g.ker}) :\n  (f.lift_of_right_inverse f_inv hf g).comp f = g :=\nring_hom.ext $ f.lift_of_right_inverse_comp_apply f_inv hf g\n\nlemma eq_lift_of_right_inverse (hf : function.right_inverse f_inv f) (g : A \u2192+* C)\n  (hg : f.ker \u2264 g.ker) (h : B \u2192+* C) (hh : h.comp f = g) :\n  h = (f.lift_of_right_inverse f_inv hf \u27e8g, hg\u27e9) :=\nbegin\n  simp_rw \u2190hh,\n  exact ((f.lift_of_right_inverse f_inv hf).apply_symm_apply _).symm,\nend\n\nend ring_hom\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/ideal/operations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.7130985215812621}}
{"text": "theorem ex1 (p q : Prop) : p \u2192 q \u2192 p \u2227 q := by\n  intros\n  apply And.intro\n  exact \u2039p\u203a\n  exact \u2039q\u203a\n\ntheorem ex2 (p q : Prop) : p \u2192 q \u2192 p \u2227 q :=\n  fun _ _ => And.intro \u2039p\u203a \u2039q\u203a\n\ntheorem ex3 (p q : Prop) : p \u2192 q \u2192 p \u2227 q :=\n  fun _ _ => \u27e8\u2039p\u203a, \u2039q\u203a\u27e9\n\ntheorem ex4 {a b c : Nat} : a = b \u2192 b = c \u2192 a = c :=\n  fun _ _ => Eq.trans \u2039a = _\u203a \u2039_ = c\u203a\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/french_quote.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.7130985194373906}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Yury Kudryashov\n-/\nimport data.set.pointwise.smul\n\n/-!\n# Torsors of additive group actions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines torsors of additive group actions.\n\n## Notations\n\nThe group elements are referred to as acting on points.  This file\ndefines the notation `+\u1d65` for adding a group element to a point and\n`-\u1d65` for subtracting two points to produce a group element.\n\n## Implementation notes\n\nAffine spaces are the motivating example of torsors of additive group actions. It may be appropriate\nto refactor in terms of the general definition of group actions, via `to_additive`, when there is a\nuse for multiplicative torsors (currently mathlib only develops the theory of group actions for\nmultiplicative group actions).\n\n## Notations\n\n* `v +\u1d65 p` is a notation for `has_vadd.vadd`, the left action of an additive monoid;\n\n* `p\u2081 -\u1d65 p\u2082` is a notation for `has_vsub.vsub`, difference between two points in an additive torsor\n  as an element of the corresponding additive group;\n\n## References\n\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n* https://en.wikipedia.org/wiki/Affine_space\n\n-/\n\n/-- An `add_torsor G P` gives a structure to the nonempty type `P`,\nacted on by an `add_group G` with a transitive and free action given\nby the `+\u1d65` operation and a corresponding subtraction given by the\n`-\u1d65` operation. In the case of a vector space, it is an affine\nspace. -/\nclass add_torsor (G : out_param Type*) (P : Type*) [out_param $ add_group G]\n  extends add_action G P, has_vsub G P :=\n[nonempty : nonempty P]\n(vsub_vadd' : \u2200 (p1 p2 : P), (p1 -\u1d65 p2 : G) +\u1d65 p2 = p1)\n(vadd_vsub' : \u2200 (g : G) (p : P), g +\u1d65 p -\u1d65 p = g)\n\nattribute [instance, priority 100, nolint dangerous_instance] add_torsor.nonempty\nattribute [nolint dangerous_instance] add_torsor.to_has_vsub\n\n/-- An `add_group G` is a torsor for itself. -/\n@[nolint instance_priority]\ninstance add_group_is_add_torsor (G : Type*) [add_group G] :\n  add_torsor G G :=\n{ vsub := has_sub.sub,\n  vsub_vadd' := sub_add_cancel,\n  vadd_vsub' := add_sub_cancel }\n\n/-- Simplify subtraction for a torsor for an `add_group G` over\nitself. -/\n@[simp] lemma vsub_eq_sub {G : Type*} [add_group G] (g1 g2 : G) : g1 -\u1d65 g2 = g1 - g2 :=\nrfl\n\nsection general\n\nvariables {G : Type*} {P : Type*} [add_group G] [T : add_torsor G P]\ninclude T\n\n/-- Adding the result of subtracting from another point produces that\npoint. -/\n@[simp] lemma vsub_vadd (p1 p2 : P) : p1 -\u1d65 p2 +\u1d65 p2 = p1 :=\nadd_torsor.vsub_vadd' p1 p2\n\n/-- Adding a group element then subtracting the original point\nproduces that group element. -/\n@[simp] lemma vadd_vsub (g : G) (p : P) : g +\u1d65 p -\u1d65 p = g :=\nadd_torsor.vadd_vsub' g p\n\n/-- If the same point added to two group elements produces equal\nresults, those group elements are equal. -/\nlemma vadd_right_cancel {g1 g2 : G} (p : P) (h : g1 +\u1d65 p = g2 +\u1d65 p) : g1 = g2 :=\nby rw [\u2190vadd_vsub g1, h, vadd_vsub]\n\n@[simp] lemma vadd_right_cancel_iff {g1 g2 : G} (p : P) :  g1 +\u1d65 p = g2 +\u1d65 p \u2194 g1 = g2 :=\n\u27e8vadd_right_cancel p, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Adding a group element to the point `p` is an injective\nfunction. -/\nlemma vadd_right_injective (p : P) : function.injective ((+\u1d65 p) : G \u2192 P) :=\n\u03bb g1 g2, vadd_right_cancel p\n\n/-- Adding a group element to a point, then subtracting another point,\nproduces the same result as subtracting the points then adding the\ngroup element. -/\nlemma vadd_vsub_assoc (g : G) (p1 p2 : P) : g +\u1d65 p1 -\u1d65 p2 = g + (p1 -\u1d65 p2) :=\nbegin\n  apply vadd_right_cancel p2,\n  rw [vsub_vadd, add_vadd, vsub_vadd]\nend\n\n/-- Subtracting a point from itself produces 0. -/\n@[simp] lemma vsub_self (p : P) : p -\u1d65 p = (0 : G) :=\nby rw [\u2190zero_add (p -\u1d65 p), \u2190vadd_vsub_assoc, vadd_vsub]\n\n/-- If subtracting two points produces 0, they are equal. -/\nlemma eq_of_vsub_eq_zero {p1 p2 : P} (h : p1 -\u1d65 p2 = (0 : G)) : p1 = p2 :=\nby rw [\u2190vsub_vadd p1 p2, h, zero_vadd]\n\n/-- Subtracting two points produces 0 if and only if they are\nequal. -/\n@[simp] lemma vsub_eq_zero_iff_eq {p1 p2 : P} : p1 -\u1d65 p2 = (0 : G) \u2194 p1 = p2 :=\niff.intro eq_of_vsub_eq_zero (\u03bb h, h \u25b8 vsub_self _)\n\nlemma vsub_ne_zero {p q : P} : p -\u1d65 q \u2260 (0 : G) \u2194 p \u2260 q :=\nnot_congr vsub_eq_zero_iff_eq\n\n/-- Cancellation adding the results of two subtractions. -/\n@[simp] lemma vsub_add_vsub_cancel (p1 p2 p3 : P) : p1 -\u1d65 p2 + (p2 -\u1d65 p3) = (p1 -\u1d65 p3) :=\nbegin\n  apply vadd_right_cancel p3,\n  rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd]\nend\n\n/-- Subtracting two points in the reverse order produces the negation\nof subtracting them. -/\n@[simp] lemma neg_vsub_eq_vsub_rev (p1 p2 : P) : -(p1 -\u1d65 p2) = (p2 -\u1d65 p1) :=\nbegin\n  refine neg_eq_of_add_eq_zero_right (vadd_right_cancel p1 _),\n  rw [vsub_add_vsub_cancel, vsub_self],\nend\n\nlemma vadd_vsub_eq_sub_vsub (g : G) (p q : P) : g +\u1d65 p -\u1d65 q = g - (q -\u1d65 p) :=\nby rw [vadd_vsub_assoc, sub_eq_add_neg, neg_vsub_eq_vsub_rev]\n\n/-- Subtracting the result of adding a group element produces the same result\nas subtracting the points and subtracting that group element. -/\nlemma vsub_vadd_eq_vsub_sub (p1 p2 : P) (g : G) : p1 -\u1d65 (g +\u1d65 p2) = (p1 -\u1d65 p2) - g :=\nby rw [\u2190add_right_inj (p2 -\u1d65 p1 : G), vsub_add_vsub_cancel, \u2190neg_vsub_eq_vsub_rev, vadd_vsub,\n       \u2190add_sub_assoc, \u2190neg_vsub_eq_vsub_rev, neg_add_self, zero_sub]\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_right (p1 p2 p3 : P) :\n  (p1 -\u1d65 p3) - (p2 -\u1d65 p3) = (p1 -\u1d65 p2) :=\nby rw [\u2190vsub_vadd_eq_vsub_sub, vsub_vadd]\n\n/-- Convert between an equality with adding a group element to a point\nand an equality of a subtraction of two points with a group\nelement. -/\nlemma eq_vadd_iff_vsub_eq (p1 : P) (g : G) (p2 : P) : p1 = g +\u1d65 p2 \u2194 p1 -\u1d65 p2 = g :=\n\u27e8\u03bb h, h.symm \u25b8 vadd_vsub _ _, \u03bb h, h \u25b8 (vsub_vadd _ _).symm\u27e9\n\nlemma vadd_eq_vadd_iff_neg_add_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 - v\u2081 + v\u2082 = p\u2081 -\u1d65 p\u2082 :=\nby rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, \u2190 add_right_inj (-v\u2081), neg_add_cancel_left, eq_comm]\n\nnamespace set\nopen_locale pointwise\n\n@[simp] lemma singleton_vsub_self (p : P) : ({p} : set P) -\u1d65 {p} = {(0:G)} :=\nby rw [set.singleton_vsub_singleton, vsub_self]\n\nend set\n\n@[simp] lemma vadd_vsub_vadd_cancel_right (v\u2081 v\u2082 : G) (p : P) :\n  (v\u2081 +\u1d65 p) -\u1d65 (v\u2082 +\u1d65 p) = v\u2081 - v\u2082 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero]\n\n/-- If the same point subtracted from two points produces equal\nresults, those points are equal. -/\nlemma vsub_left_cancel {p1 p2 p : P} (h : p1 -\u1d65 p = p2 -\u1d65 p) : p1 = p2 :=\nby rwa [\u2190sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h\n\n/-- The same point subtracted from two points produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_left_cancel_iff {p1 p2 p : P} : (p1 -\u1d65 p) = p2 -\u1d65 p \u2194 p1 = p2 :=\n\u27e8vsub_left_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting the point `p` is an injective function. -/\nlemma vsub_left_injective (p : P) : function.injective ((-\u1d65 p) : P \u2192 G) :=\n\u03bb p2 p3, vsub_left_cancel\n\n/-- If subtracting two points from the same point produces equal\nresults, those points are equal. -/\nlemma vsub_right_cancel {p1 p2 p : P} (h : p -\u1d65 p1 = p -\u1d65 p2) : p1 = p2 :=\nbegin\n  refine vadd_left_cancel (p -\u1d65 p2) _,\n  rw [vsub_vadd, \u2190 h, vsub_vadd]\nend\n\n/-- Subtracting two points from the same point produces equal results\nif and only if those points are equal. -/\n@[simp] lemma vsub_right_cancel_iff {p1 p2 p : P} : p -\u1d65 p1 = p -\u1d65 p2 \u2194 p1 = p2 :=\n\u27e8vsub_right_cancel, \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Subtracting a point from the point `p` is an injective\nfunction. -/\nlemma vsub_right_injective (p : P) : function.injective ((-\u1d65) p : P \u2192 G) :=\n\u03bb p2 p3, vsub_right_cancel\n\nend general\n\nsection comm\n\nvariables {G : Type*} {P : Type*} [add_comm_group G] [add_torsor G P]\n\ninclude G\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp] lemma vsub_sub_vsub_cancel_left (p1 p2 p3 : P) :\n  (p3 -\u1d65 p2) - (p3 -\u1d65 p1) = (p1 -\u1d65 p2) :=\nby rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]\n\n@[simp] lemma vadd_vsub_vadd_cancel_left (v : G) (p1 p2 : P) :\n  (v +\u1d65 p1) -\u1d65 (v +\u1d65 p2) = p1 -\u1d65 p2 :=\nby rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel']\n\nlemma vsub_vadd_comm (p1 p2 p3 : P) : (p1 -\u1d65 p2 : G) +\u1d65 p3 = p3 -\u1d65 p2 +\u1d65 p1 :=\nbegin\n  rw [\u2190@vsub_eq_zero_iff_eq G, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub],\n  simp\nend\n\nlemma vadd_eq_vadd_iff_sub_eq_vsub {v\u2081 v\u2082 : G} {p\u2081 p\u2082 : P} :\n  v\u2081 +\u1d65 p\u2081 = v\u2082 +\u1d65 p\u2082 \u2194 v\u2082 - v\u2081 = p\u2081 -\u1d65 p\u2082 :=\nby rw [vadd_eq_vadd_iff_neg_add_eq_vsub, neg_add_eq_sub]\n\nlemma vsub_sub_vsub_comm (p\u2081 p\u2082 p\u2083 p\u2084 : P) :\n  (p\u2081 -\u1d65 p\u2082) - (p\u2083 -\u1d65 p\u2084) = (p\u2081 -\u1d65 p\u2083) - (p\u2082 -\u1d65 p\u2084) :=\nby rw [\u2190 vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub]\n\nend comm\n\nnamespace prod\n\nvariables {G : Type*} {P : Type*} {G' : Type*} {P' : Type*} [add_group G] [add_group G']\n  [add_torsor G P] [add_torsor G' P']\n\ninstance : add_torsor (G \u00d7 G') (P \u00d7 P') :=\n{ vadd := \u03bb v p, (v.1 +\u1d65 p.1, v.2 +\u1d65 p.2),\n  zero_vadd := \u03bb p, by simp,\n  add_vadd := by simp [add_vadd],\n  vsub := \u03bb p\u2081 p\u2082, (p\u2081.1 -\u1d65 p\u2082.1, p\u2081.2 -\u1d65 p\u2082.2),\n  nonempty := prod.nonempty,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, show (p\u2081.1 -\u1d65 p\u2082.1 +\u1d65 p\u2082.1, _) = p\u2081, by simp,\n  vadd_vsub' := \u03bb v p, show (v.1 +\u1d65 p.1 -\u1d65 p.1, v.2 +\u1d65 p.2 -\u1d65 p.2)  =v, by simp }\n\n@[simp] lemma fst_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).1 = v.1 +\u1d65 p.1 := rfl\n@[simp] lemma snd_vadd (v : G \u00d7 G') (p : P \u00d7 P') : (v +\u1d65 p).2 = v.2 +\u1d65 p.2 := rfl\n@[simp] lemma mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') :\n  (v, v') +\u1d65 (p, p') = (v +\u1d65 p, v' +\u1d65 p') := rfl\n\n@[simp] lemma fst_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').1 = p\u2081.1 -\u1d65 p\u2082.1 := rfl\n@[simp] lemma snd_vsub (p\u2081 p\u2082 : P \u00d7 P') : (p\u2081 -\u1d65 p\u2082 : G \u00d7 G').2 = p\u2081.2 -\u1d65 p\u2082.2 := rfl\n@[simp] lemma mk_vsub_mk (p\u2081 p\u2082 : P) (p\u2081' p\u2082' : P') :\n  ((p\u2081, p\u2081') -\u1d65 (p\u2082, p\u2082') : G \u00d7 G') = (p\u2081 -\u1d65 p\u2082, p\u2081' -\u1d65 p\u2082') := rfl\n\nend prod\n\nnamespace pi\n\nuniverses u v w\nvariables {I : Type u} {fg : I \u2192 Type v} [\u2200 i, add_group (fg i)] {fp : I \u2192 Type w}\n\nopen add_action add_torsor\n\n/-- A product of `add_torsor`s is an `add_torsor`. -/\ninstance [T : \u2200 i, add_torsor (fg i) (fp i)] : add_torsor (\u03a0 i, fg i) (\u03a0 i, fp i) :=\n{ vadd := \u03bb g p, \u03bb i, g i +\u1d65 p i,\n  zero_vadd := \u03bb p, funext $ \u03bb i, zero_vadd (fg i) (p i),\n  add_vadd := \u03bb g\u2081 g\u2082 p, funext $ \u03bb i, add_vadd (g\u2081 i) (g\u2082 i) (p i),\n  vsub := \u03bb p\u2081 p\u2082, \u03bb i, p\u2081 i -\u1d65 p\u2082 i,\n  nonempty := \u27e8\u03bb i, classical.choice (T i).nonempty\u27e9,\n  vsub_vadd' := \u03bb p\u2081 p\u2082, funext $ \u03bb i, vsub_vadd (p\u2081 i) (p\u2082 i),\n  vadd_vsub' := \u03bb g p, funext $ \u03bb i, vadd_vsub (g i) (p i) }\n\nend pi\n\nnamespace equiv\n\nvariables {G : Type*} {P : Type*} [add_group G] [add_torsor G P]\n\ninclude G\n\n/-- `v \u21a6 v +\u1d65 p` as an equivalence. -/\ndef vadd_const (p : P) : G \u2243 P :=\n{ to_fun := \u03bb v, v +\u1d65 p,\n  inv_fun := \u03bb p', p' -\u1d65 p,\n  left_inv := \u03bb v, vadd_vsub _ _,\n  right_inv := \u03bb p', vsub_vadd _ _ }\n\n@[simp] lemma coe_vadd_const (p : P) : \u21d1(vadd_const p) = \u03bb v, v+\u1d65 p := rfl\n\n@[simp] lemma coe_vadd_const_symm (p : P) : \u21d1(vadd_const p).symm = \u03bb p', p' -\u1d65 p := rfl\n\n/-- `p' \u21a6 p -\u1d65 p'` as an equivalence. -/\ndef const_vsub (p : P) : P \u2243 G :=\n{ to_fun := (-\u1d65) p,\n  inv_fun := \u03bb v, -v +\u1d65 p,\n  left_inv := \u03bb p', by simp,\n  right_inv := \u03bb v, by simp [vsub_vadd_eq_vsub_sub] }\n\n@[simp] lemma coe_const_vsub (p : P) : \u21d1(const_vsub p) = (-\u1d65) p := rfl\n\n@[simp] lemma coe_const_vsub_symm (p : P) : \u21d1(const_vsub p).symm = \u03bb v, -v +\u1d65 p := rfl\n\nvariables (P)\n\n/-- The permutation given by `p \u21a6 v +\u1d65 p`. -/\ndef const_vadd (v : G) : equiv.perm P :=\n{ to_fun := (+\u1d65) v,\n  inv_fun := (+\u1d65) (-v),\n  left_inv := \u03bb p, by simp [vadd_vadd],\n  right_inv := \u03bb p, by simp [vadd_vadd] }\n\n@[simp] lemma coe_const_vadd (v : G) : \u21d1(const_vadd P v) = (+\u1d65) v := rfl\n\nvariable (G)\n\n@[simp] lemma const_vadd_zero : const_vadd P (0:G) = 1 := ext $ zero_vadd G\n\nvariable {G}\n\n@[simp] lemma const_vadd_add (v\u2081 v\u2082 : G) :\n  const_vadd P (v\u2081 + v\u2082) = const_vadd P v\u2081 * const_vadd P v\u2082 :=\next $ add_vadd v\u2081 v\u2082\n\n/-- `equiv.const_vadd` as a homomorphism from `multiplicative G` to `equiv.perm P` -/\ndef const_vadd_hom : multiplicative G \u2192* equiv.perm P :=\n{ to_fun := \u03bb v, const_vadd P v.to_add,\n  map_one' := const_vadd_zero G P,\n  map_mul' := const_vadd_add P }\n\nvariable {P}\n\nopen _root_.function\n\n/-- Point reflection in `x` as a permutation. -/\ndef point_reflection (x : P) : perm P := (const_vsub x).trans (vadd_const x)\n\nlemma point_reflection_apply (x y : P) : point_reflection x y = x -\u1d65 y +\u1d65 x := rfl\n\n@[simp] lemma point_reflection_symm (x : P) : (point_reflection x).symm = point_reflection x :=\next $ by simp [point_reflection]\n\n@[simp] lemma point_reflection_self (x : P) : point_reflection x x = x := vsub_vadd _ _\n\nlemma point_reflection_involutive (x : P) : involutive (point_reflection x : P \u2192 P) :=\n\u03bb y, (equiv.apply_eq_iff_eq_symm_apply _).2 $ by rw point_reflection_symm\n\n/-- `x` is the only fixed point of `point_reflection x`. This lemma requires\n`x + x = y + y \u2194 x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/\nlemma point_reflection_fixed_iff_of_injective_bit0 {x y : P} (h : injective (bit0 : G \u2192 G)) :\n  point_reflection x y = y \u2194 y = x :=\nby rw [point_reflection_apply, eq_comm, eq_vadd_iff_vsub_eq, \u2190 neg_vsub_eq_vsub_rev,\n  neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero, h.eq_iff, vsub_eq_zero_iff_eq, eq_comm]\n\nomit G\n\nlemma injective_point_reflection_left_of_injective_bit0 {G P : Type*} [add_comm_group G]\n  [add_torsor G P] (h : injective (bit0 : G \u2192 G)) (y : P) :\n  injective (\u03bb x : P, point_reflection x y) :=\n\u03bb x\u2081 x\u2082 (hy : point_reflection x\u2081 y = point_reflection x\u2082 y),\n  by rwa [point_reflection_apply, point_reflection_apply, vadd_eq_vadd_iff_sub_eq_vsub,\n    vsub_sub_vsub_cancel_right, \u2190 neg_vsub_eq_vsub_rev, neg_eq_iff_add_eq_zero, \u2190 bit0, \u2190 bit0_zero,\n    h.eq_iff, vsub_eq_zero_iff_eq] at hy\n\nend equiv\n\nlemma add_torsor.subsingleton_iff (G P : Type*) [add_group G] [add_torsor G P] :\n  subsingleton G \u2194 subsingleton P :=\nbegin\n  inhabit P,\n  exact (equiv.vadd_const default).subsingleton_congr,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/add_torsor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7130985150404798}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport topology.metric_space.lipschitz\nimport topology.uniform_space.complete_separated\n\n/-!\n# Antilipschitz functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe say that a map `f : \u03b1 \u2192 \u03b2` between two (extended) metric spaces is\n`antilipschitz_with K`, `K \u2265 0`, if for all `x, y` we have `edist x y \u2264 K * edist (f x) (f y)`.\nFor a metric space, the latter inequality is equivalent to `dist x y \u2264 K * dist (f x) (f y)`.\n\n## Implementation notes\n\nThe parameter `K` has type `\u211d\u22650`. This way we avoid conjuction in the definition and have\ncoercions both to `\u211d` and `\u211d\u22650\u221e`. We do not require `0 < K` in the definition, mostly because\nwe do not have a `posreal` type.\n-/\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\n\nopen_locale nnreal ennreal uniformity\nopen set filter bornology\n\n/-- We say that `f : \u03b1 \u2192 \u03b2` is `antilipschitz_with K` if for any two points `x`, `y` we have\n`edist x y \u2264 K * edist (f x) (f y)`. -/\ndef antilipschitz_with [pseudo_emetric_space \u03b1] [pseudo_emetric_space \u03b2] (K : \u211d\u22650) (f : \u03b1 \u2192 \u03b2) :=\n\u2200 x y, edist x y \u2264 K * edist (f x) (f y)\n\nlemma antilipschitz_with.edist_lt_top [pseudo_emetric_space \u03b1] [pseudo_metric_space \u03b2] {K : \u211d\u22650}\n  {f : \u03b1 \u2192 \u03b2} (h : antilipschitz_with K f) (x y : \u03b1) : edist x y < \u22a4 :=\n(h x y).trans_lt $ ennreal.mul_lt_top ennreal.coe_ne_top (edist_ne_top _ _)\n\nlemma antilipschitz_with.edist_ne_top [pseudo_emetric_space \u03b1] [pseudo_metric_space \u03b2] {K : \u211d\u22650}\n  {f : \u03b1 \u2192 \u03b2} (h : antilipschitz_with K f) (x y : \u03b1) : edist x y \u2260 \u22a4 :=\n(h.edist_lt_top x y).ne\n\nsection metric\n\nvariables [pseudo_metric_space \u03b1] [pseudo_metric_space \u03b2] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2}\n\nlemma antilipschitz_with_iff_le_mul_nndist :\n  antilipschitz_with K f \u2194 \u2200 x y, nndist x y \u2264 K * nndist (f x) (f y) :=\nby { simp only [antilipschitz_with, edist_nndist], norm_cast }\n\nalias antilipschitz_with_iff_le_mul_nndist \u2194 antilipschitz_with.le_mul_nndist\n  antilipschitz_with.of_le_mul_nndist\n\nlemma antilipschitz_with_iff_le_mul_dist :\n  antilipschitz_with K f \u2194 \u2200 x y, dist x y \u2264 K * dist (f x) (f y) :=\nby { simp only [antilipschitz_with_iff_le_mul_nndist, dist_nndist], norm_cast }\n\nalias antilipschitz_with_iff_le_mul_dist \u2194 antilipschitz_with.le_mul_dist\n  antilipschitz_with.of_le_mul_dist\n\nnamespace antilipschitz_with\n\nlemma mul_le_nndist (hf : antilipschitz_with K f) (x y : \u03b1) :\n  K\u207b\u00b9 * nndist x y \u2264 nndist (f x) (f y) :=\nby simpa only [div_eq_inv_mul] using nnreal.div_le_of_le_mul' (hf.le_mul_nndist x y)\n\nlemma mul_le_dist (hf : antilipschitz_with K f) (x y : \u03b1) :\n  (K\u207b\u00b9 * dist x y : \u211d) \u2264 dist (f x) (f y) :=\nby exact_mod_cast hf.mul_le_nndist x y\n\nend antilipschitz_with\n\nend metric\n\nnamespace antilipschitz_with\n\nvariables [pseudo_emetric_space \u03b1] [pseudo_emetric_space \u03b2] [pseudo_emetric_space \u03b3]\nvariables {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2}\n\nopen emetric\n\n/-- Extract the constant from `hf : antilipschitz_with K f`. This is useful, e.g.,\nif `K` is given by a long formula, and we want to reuse this value. -/\n@[nolint unused_arguments] -- uses neither `f` nor `hf`\nprotected def K (hf : antilipschitz_with K f) : \u211d\u22650 := K\n\nprotected lemma injective {\u03b1 : Type*} {\u03b2 : Type*} [emetric_space \u03b1] [pseudo_emetric_space \u03b2]\n  {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2} (hf : antilipschitz_with K f) : function.injective f :=\n\u03bb x y h, by simpa only [h, edist_self, mul_zero, edist_le_zero] using hf x y\n\nlemma mul_le_edist (hf : antilipschitz_with K f) (x y : \u03b1) :\n  (K\u207b\u00b9 * edist x y : \u211d\u22650\u221e) \u2264 edist (f x) (f y) :=\nbegin\n  rw [mul_comm, \u2190 div_eq_mul_inv],\n  exact ennreal.div_le_of_le_mul' (hf x y)\nend\n\nlemma ediam_preimage_le (hf : antilipschitz_with K f) (s : set \u03b2) : diam (f \u207b\u00b9' s) \u2264 K * diam s :=\ndiam_le $ \u03bb x hx y hy, (hf x y).trans $ mul_le_mul_left' (edist_le_diam_of_mem hx hy) K\n\nlemma le_mul_ediam_image (hf : antilipschitz_with K f) (s : set \u03b1) : diam s \u2264 K * diam (f '' s) :=\n(diam_mono (subset_preimage_image _ _)).trans (hf.ediam_preimage_le (f '' s))\n\nprotected lemma id : antilipschitz_with 1 (id : \u03b1 \u2192 \u03b1) :=\n\u03bb x y, by simp only [ennreal.coe_one, one_mul, id, le_refl]\n\nlemma comp {Kg : \u211d\u22650} {g : \u03b2 \u2192 \u03b3} (hg : antilipschitz_with Kg g)\n  {Kf : \u211d\u22650} {f : \u03b1 \u2192 \u03b2} (hf : antilipschitz_with Kf f) :\n  antilipschitz_with (Kf * Kg) (g \u2218 f) :=\n\u03bb x y,\ncalc edist x y \u2264 Kf * edist (f x) (f y) : hf x y\n... \u2264 Kf * (Kg * edist (g (f x)) (g (f y))) : ennreal.mul_left_mono (hg _ _)\n... = _ : by rw [ennreal.coe_mul, mul_assoc]\n\nlemma restrict (hf : antilipschitz_with K f) (s : set \u03b1) :\n  antilipschitz_with K (s.restrict f) :=\n\u03bb x y, hf x y\n\nlemma cod_restrict (hf : antilipschitz_with K f) {s : set \u03b2} (hs : \u2200 x, f x \u2208 s) :\n  antilipschitz_with K (s.cod_restrict f hs) :=\n\u03bb x y, hf x y\n\nlemma to_right_inv_on' {s : set \u03b1} (hf : antilipschitz_with K (s.restrict f))\n  {g : \u03b2 \u2192 \u03b1} {t : set \u03b2} (g_maps : maps_to g t s) (g_inv : right_inv_on g f t) :\n  lipschitz_with K (t.restrict g) :=\n\u03bb x y, by simpa only [restrict_apply, g_inv x.mem, g_inv y.mem, subtype.edist_eq, subtype.coe_mk]\n  using hf \u27e8g x, g_maps x.mem\u27e9 \u27e8g y, g_maps y.mem\u27e9\n\nlemma to_right_inv_on (hf : antilipschitz_with K f) {g : \u03b2 \u2192 \u03b1} {t : set \u03b2}\n  (h : right_inv_on g f t) :\n  lipschitz_with K (t.restrict g) :=\n(hf.restrict univ).to_right_inv_on' (maps_to_univ g t) h\n\nlemma to_right_inverse (hf : antilipschitz_with K f) {g : \u03b2 \u2192 \u03b1} (hg : function.right_inverse g f) :\n  lipschitz_with K g :=\nbegin\n  intros x y,\n  have := hf (g x) (g y),\n  rwa [hg x, hg y] at this\nend\n\nlemma comap_uniformity_le (hf : antilipschitz_with K f) :\n  (\ud835\udce4 \u03b2).comap (prod.map f f) \u2264 \ud835\udce4 \u03b1 :=\nbegin\n  refine ((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).2 (\u03bb \u03b5 h\u2080, _),\n  refine \u27e8K\u207b\u00b9 * \u03b5, ennreal.mul_pos (ennreal.inv_ne_zero.2 ennreal.coe_ne_top) h\u2080.ne', _\u27e9,\n  refine \u03bb x hx, (hf x.1 x.2).trans_lt _,\n  rw [mul_comm, \u2190 div_eq_mul_inv] at hx,\n  rw mul_comm,\n  exact ennreal.mul_lt_of_lt_div hx\nend\n\nprotected lemma uniform_inducing (hf : antilipschitz_with K f) (hfc : uniform_continuous f) :\n  uniform_inducing f :=\n\u27e8le_antisymm hf.comap_uniformity_le hfc.le_comap\u27e9\n\nprotected lemma uniform_embedding {\u03b1 : Type*} {\u03b2 : Type*} [emetric_space \u03b1] [pseudo_emetric_space \u03b2]\n  {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2} (hf : antilipschitz_with K f) (hfc : uniform_continuous f) :\n  uniform_embedding f :=\n\u27e8hf.uniform_inducing hfc, hf.injective\u27e9\n\nlemma is_complete_range [complete_space \u03b1] (hf : antilipschitz_with K f)\n  (hfc : uniform_continuous f) : is_complete (range f) :=\n(hf.uniform_inducing hfc).is_complete_range\n\nlemma is_closed_range {\u03b1 \u03b2 : Type*} [pseudo_emetric_space \u03b1] [emetric_space \u03b2] [complete_space \u03b1]\n  {f : \u03b1 \u2192 \u03b2} {K : \u211d\u22650} (hf : antilipschitz_with K f) (hfc : uniform_continuous f) :\n  is_closed (range f) :=\n(hf.is_complete_range hfc).is_closed\n\nlemma closed_embedding {\u03b1 : Type*} {\u03b2 : Type*} [emetric_space \u03b1] [emetric_space \u03b2] {K : \u211d\u22650}\n  {f : \u03b1 \u2192 \u03b2} [complete_space \u03b1] (hf : antilipschitz_with K f) (hfc : uniform_continuous f) :\n  closed_embedding f :=\n{ closed_range := hf.is_closed_range hfc,\n  .. (hf.uniform_embedding hfc).embedding }\n\nlemma subtype_coe (s : set \u03b1) : antilipschitz_with 1 (coe : s \u2192 \u03b1) :=\nantilipschitz_with.id.restrict s\n\nlemma of_subsingleton [subsingleton \u03b1] {K : \u211d\u22650} : antilipschitz_with K f :=\n\u03bb x y, by simp only [subsingleton.elim x y, edist_self, zero_le]\n\n/-- If `f : \u03b1 \u2192 \u03b2` is `0`-antilipschitz, then `\u03b1` is a `subsingleton`. -/\nprotected lemma subsingleton {\u03b1 \u03b2} [emetric_space \u03b1] [pseudo_emetric_space \u03b2] {f : \u03b1 \u2192 \u03b2}\n  (h : antilipschitz_with 0 f) : subsingleton \u03b1 :=\n\u27e8\u03bb x y, edist_le_zero.1 $ (h x y).trans_eq $ zero_mul _\u27e9\n\nend antilipschitz_with\n\nnamespace antilipschitz_with\n\nopen metric\n\nvariables [pseudo_metric_space \u03b1] [pseudo_metric_space \u03b2] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2}\n\nlemma bounded_preimage (hf : antilipschitz_with K f)\n  {s : set \u03b2} (hs : bounded s) :\n  bounded (f \u207b\u00b9' s) :=\nexists.intro (K * diam s) $ \u03bb x hx y hy,\ncalc dist x y \u2264 K * dist (f x) (f y) : hf.le_mul_dist x y\n... \u2264 K * diam s : mul_le_mul_of_nonneg_left (dist_le_diam_of_mem hs hx hy) K.2\n\nlemma tendsto_cobounded (hf : antilipschitz_with K f) : tendsto f (cobounded \u03b1) (cobounded \u03b2) :=\ncompl_surjective.forall.2 $ \u03bb s (hs : is_bounded s), metric.is_bounded_iff.2 $\n  hf.bounded_preimage $ metric.is_bounded_iff.1 hs\n\n/-- The image of a proper space under an expanding onto map is proper. -/\nprotected lemma proper_space {\u03b1 : Type*} [metric_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2} [proper_space \u03b1]\n  (hK : antilipschitz_with K f) (f_cont : continuous f) (hf : function.surjective f) :\n  proper_space \u03b2 :=\nbegin\n  apply proper_space_of_compact_closed_ball_of_le 0 (\u03bbx\u2080 r hr, _),\n  let K := f \u207b\u00b9' (closed_ball x\u2080 r),\n  have A : is_closed K := is_closed_ball.preimage f_cont,\n  have B : bounded K := hK.bounded_preimage bounded_closed_ball,\n  have : is_compact K := is_compact_iff_is_closed_bounded.2 \u27e8A, B\u27e9,\n  convert this.image f_cont,\n  exact (hf.image_preimage _).symm\nend\n\nend antilipschitz_with\n\nlemma lipschitz_with.to_right_inverse [pseudo_emetric_space \u03b1] [pseudo_emetric_space \u03b2] {K : \u211d\u22650}\n  {f : \u03b1 \u2192 \u03b2} (hf : lipschitz_with K f) {g : \u03b2 \u2192 \u03b1} (hg : function.right_inverse g f) :\n  antilipschitz_with K g :=\n\u03bb x y, by simpa only [hg _] using hf (g x) (g y)\n\n/-- The preimage of a proper space under a Lipschitz homeomorphism is proper. -/\n@[protected]\ntheorem lipschitz_with.proper_space [pseudo_metric_space \u03b1] [metric_space \u03b2] [proper_space \u03b2]\n  {K : \u211d\u22650} {f : \u03b1 \u2243\u209c \u03b2} (hK : lipschitz_with K f) :\n  proper_space \u03b1 :=\n(hK.to_right_inverse f.right_inv).proper_space f.symm.continuous f.symm.surjective\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/metric_space/antilipschitz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7130985128966083}}
{"text": "/-\nCopyright (c) 2021 Patrick Stevens. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Stevens, Thomas Browning\nPorted by: Fr\u00e9d\u00e9ric Dupuis\n\n! This file was ported from Lean 3 source module data.nat.choose.central\n! leanprover-community/mathlib commit 0a0ec35061ed9960bf0e7ffb0335f44447b58977\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Tactic.Linarith\n\n/-!\n# Central binomial coefficients\n\nThis file proves properties of the central binomial coefficients (that is, `nat.choose (2 * n) n`).\n\n## Main definition and results\n\n* `Nat.centralBinom`: the central binomial coefficient, `(2 * n).choose n`.\n* `Nat.succ_mul_centralBinom_succ`: the inductive relationship between successive central binomial\n  coefficients.\n* `Nat.four_pow_lt_mul_centralBinom`: an exponential lower bound on the central binomial\n  coefficient.\n* `succ_dvd_centralBinom`: The result that `n+1 \u2223 n.centralBinom`, ensuring that the explicit\n  definition of the Catalan numbers is integer-valued.\n-/\n\n\nnamespace Nat\n\n/-- The central binomial coefficient, `Nat.choose (2 * n) n`.\n-/\ndef centralBinom (n : \u2115) :=\n  (2 * n).choose n\n#align nat.central_binom Nat.centralBinom\n\ntheorem centralBinom_eq_two_mul_choose (n : \u2115) : centralBinom n = (2 * n).choose n :=\n  rfl\n#align nat.central_binom_eq_two_mul_choose Nat.centralBinom_eq_two_mul_choose\n\ntheorem centralBinom_pos (n : \u2115) : 0 < centralBinom n :=\n  choose_pos (Nat.le_mul_of_pos_left zero_lt_two)\n#align nat.central_binom_pos Nat.centralBinom_pos\n\ntheorem centralBinom_ne_zero (n : \u2115) : centralBinom n \u2260 0 :=\n  (centralBinom_pos n).ne'\n#align nat.central_binom_ne_zero Nat.centralBinom_ne_zero\n\n@[simp]\ntheorem centralBinom_zero : centralBinom 0 = 1 :=\n  choose_zero_right _\n#align nat.central_binom_zero Nat.centralBinom_zero\n\n/-- The central binomial coefficient is the largest binomial coefficient.\n-/\ntheorem choose_le_centralBinom (r n : \u2115) : choose (2 * n) r \u2264 centralBinom n :=\n  calc\n    (2 * n).choose r \u2264 (2 * n).choose (2 * n / 2) := choose_le_middle r (2 * n)\n    _ = (2 * n).choose n := by rw [Nat.mul_div_cancel_left n zero_lt_two]\n\n#align nat.choose_le_central_binom Nat.choose_le_centralBinom\n\ntheorem two_le_centralBinom (n : \u2115) (n_pos : 0 < n) : 2 \u2264 centralBinom n :=\n  calc\n    2 \u2264 2 * n := le_mul_of_pos_right n_pos\n    _ = (2 * n).choose 1 := (choose_one_right (2 * n)).symm\n    _ \u2264 centralBinom n := choose_le_centralBinom 1 n\n\n#align nat.two_le_central_binom Nat.two_le_centralBinom\n\n/-- An inductive property of the central binomial coefficient.\n-/\ntheorem succ_mul_centralBinom_succ (n : \u2115) :\n    (n + 1) * centralBinom (n + 1) = 2 * (2 * n + 1) * centralBinom n :=\n  calc\n    (n + 1) * (2 * (n + 1)).choose (n + 1) = (2 * n + 2).choose (n + 1) * (n + 1) := mul_comm _ _\n    _ = (2 * n + 1).choose n * (2 * n + 2) := by rw [choose_succ_right_eq, choose_mul_succ_eq]\n    _ = 2 * ((2 * n + 1).choose n * (n + 1)) := by ring\n    _ = 2 * ((2 * n + 1).choose n * (2 * n + 1 - n)) := by rw [two_mul n, add_assoc,\n                                                               Nat.add_sub_cancel_left]\n    _ = 2 * ((2 * n).choose n * (2 * n + 1)) := by rw [choose_mul_succ_eq]\n    _ = 2 * (2 * n + 1) * (2 * n).choose n := by rw [mul_assoc, mul_comm (2 * n + 1)]\n\n#align nat.succ_mul_central_binom_succ Nat.succ_mul_centralBinom_succ\n\n/-- An exponential lower bound on the central binomial coefficient.\nThis bound is of interest because it appears in\n[Tochiori's refinement of Erd\u0151s's proof of Bertrand's postulate](tochiori_bertrand).\n-/\ntheorem four_pow_lt_mul_centralBinom (n : \u2115) (n_big : 4 \u2264 n) : 4 ^ n < n * centralBinom n := by\n  induction' n using Nat.strong_induction_on with n IH\n  rcases lt_trichotomy n 4 with (hn | rfl | hn)\n  \u00b7 clear IH; exact False.elim ((not_lt.2 n_big) hn)\n  \u00b7 norm_num [centralBinom, choose]\n  obtain \u27e8n, rfl\u27e9 : \u2203 m, n = m + 1 := Nat.exists_eq_succ_of_ne_zero (Nat.not_eq_zero_of_lt hn)\n  calc\n    4 ^ (n + 1) < 4 * (n * centralBinom n) := lt_of_eq_of_lt (pow_succ'' n 4) $\n      (mul_lt_mul_left <| zero_lt_four' \u2115).mpr (IH n n.lt_succ_self (Nat.le_of_lt_succ hn))\n    _ \u2264 2 * (2 * n + 1) * centralBinom n := by rw [\u2190 mul_assoc]; linarith\n    _ = (n + 1) * centralBinom (n + 1) := (succ_mul_centralBinom_succ n).symm\n\n#align nat.four_pow_lt_mul_central_binom Nat.four_pow_lt_mul_centralBinom\n\n/-- An exponential lower bound on the central binomial coefficient.\nThis bound is weaker than `Nat.four_pow_lt_mul_centralBinom`, but it is of historical interest\nbecause it appears in Erd\u0151s's proof of Bertrand's postulate.\n-/\ntheorem four_pow_le_two_mul_self_mul_centralBinom :\n    \u2200 (n : \u2115) (_ : 0 < n), 4 ^ n \u2264 2 * n * centralBinom n\n  | 0, pr => (Nat.not_lt_zero _ pr).elim\n  | 1, _ => by norm_num [centralBinom, choose]\n  | 2, _ => by norm_num [centralBinom, choose]\n  | 3, _ => by norm_num [centralBinom, choose]\n  | n + 4, _ =>\n    calc\n      4 ^ (n+4) \u2264 (n+4) * centralBinom (n+4) := (four_pow_lt_mul_centralBinom _ le_add_self).le\n      _ \u2264 2 * (n+4) * centralBinom (n+4) := by rw [mul_assoc];\n                                               refine' le_mul_of_pos_left zero_lt_two\n#align nat.four_pow_le_two_mul_self_mul_central_binom Nat.four_pow_le_two_mul_self_mul_centralBinom\n\ntheorem two_dvd_centralBinom_succ (n : \u2115) : 2 \u2223 centralBinom (n + 1) := by\n  use (n + 1 + n).choose n\n  rw [centralBinom_eq_two_mul_choose, two_mul, \u2190 add_assoc,\n      choose_succ_succ' (n + 1 + n) n, choose_symm_add, \u2190 two_mul]\n#align nat.two_dvd_central_binom_succ Nat.two_dvd_centralBinom_succ\n\ntheorem two_dvd_centralBinom_of_one_le {n : \u2115} (h : 0 < n) : 2 \u2223 centralBinom n := by\n  rw [\u2190 Nat.succ_pred_eq_of_pos h]\n  exact two_dvd_centralBinom_succ n.pred\n#align nat.two_dvd_central_binom_of_one_le Nat.two_dvd_centralBinom_of_one_le\n\n/-- A crucial lemma to ensure that Catalan numbers can be defined via their explicit formula\n  `catalan n = n.centralBinom / (n + 1)`. -/\ntheorem succ_dvd_centralBinom (n : \u2115) : n + 1 \u2223 n.centralBinom := by\n  have h_s : (n + 1).coprime (2 * n + 1) := by\n    rw [two_mul, add_assoc, coprime_add_self_right, coprime_self_add_left]\n    exact coprime_one_left n\n  apply h_s.dvd_of_dvd_mul_left\n  apply Nat.dvd_of_mul_dvd_mul_left zero_lt_two\n  rw [\u2190 mul_assoc, \u2190 succ_mul_centralBinom_succ, mul_comm]\n  exact mul_dvd_mul_left _ (two_dvd_centralBinom_succ n)\n#align nat.succ_dvd_central_binom Nat.succ_dvd_centralBinom\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Choose/Central.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7130610408208315}}
{"text": "-- Program Verification #3: Tail-recursive sum\nimport data.nat.basic\n\ndef sum_simple (f : \u2115 \u2192 \u2115) : \u2115 \u2192 \u2115\n| 0       := f 0\n| n@(m+1) := f n + sum_simple m\n\ndef sum_aux : \u2115 \u2192 (\u2115 \u2192 \u2115) \u2192 \u2115 \u2192 \u2115\n| a f 0       := f 0 + a\n| a f n@(m+1) := sum_aux (f n + a) f m\n\ndef sum_tail := sum_aux 0\n\nlemma sum_eq_aux (f n k) : sum_aux k f n = (sum_simple f n) + k :=\nbegin \n    revert k, induction n with n hn,\n    { intros k, refl, },\n    { intros k, dsimp [sum_aux, sum_simple],\n      rw [hn (f (n + 1) + k), \u2190add_assoc, add_comm _ (f (n + 1))], },\nend\n\ntheorem sum_eq (f n) : sum_tail f n = sum_simple f n :=\nsum_eq_aux f n 0\n", "meta": {"author": "ramonfmir", "repo": "lean-experiments", "sha": "041c8727bb540fb8d1519c1ad84924d473885c27", "save_path": "github-repos/lean/ramonfmir-lean-experiments", "path": "github-repos/lean/ramonfmir-lean-experiments/lean-experiments-041c8727bb540fb8d1519c1ad84924d473885c27/src/codewars/tail_rec_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7130610331224931}}
{"text": "/-\nCopyright (c) 2018 . All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Thomas Browning\n-/\n\nimport data.zmod.basic\nimport group_theory.index\nimport group_theory.group_action.conj_act\nimport group_theory.perm.cycle.type\nimport group_theory.quotient_group\n\n/-!\n# p-groups\n\nThis file contains a proof that if `G` is a `p`-group acting on a finite set `\u03b1`,\nthen the number of fixed points of the action is congruent mod `p` to the cardinality of `\u03b1`.\nIt also contains proofs of some corollaries of this lemma about existence of fixed points.\n-/\n\nopen_locale big_operators\n\nopen fintype mul_action\n\nvariables (p : \u2115) (G : Type*) [group G]\n\n/-- A p-group is a group in which every element has prime power order -/\ndef is_p_group : Prop := \u2200 g : G, \u2203 k : \u2115, g ^ (p ^ k) = 1\n\nvariables {p} {G}\n\nnamespace is_p_group\n\nlemma iff_order_of [hp : fact p.prime] :\n  is_p_group p G \u2194 \u2200 g : G, \u2203 k : \u2115, order_of g = p ^ k :=\nforall_congr (\u03bb g, \u27e8\u03bb \u27e8k, hk\u27e9, exists_imp_exists (by exact \u03bb j, Exists.snd)\n  ((nat.dvd_prime_pow hp.out).mp (order_of_dvd_of_pow_eq_one hk)),\n  exists_imp_exists (\u03bb k hk, by rw [\u2190hk, pow_order_of_eq_one])\u27e9)\n\nlemma of_card [fintype G] {n : \u2115} (hG : card G = p ^ n) : is_p_group p G :=\n\u03bb g, \u27e8n, by rw [\u2190hG, pow_card_eq_one]\u27e9\n\nlemma of_bot : is_p_group p (\u22a5 : subgroup G) :=\nof_card (subgroup.card_bot.trans (pow_zero p).symm)\n\nlemma iff_card [fact p.prime] [fintype G] :\n  is_p_group p G \u2194 \u2203 n : \u2115, card G = p ^ n :=\nbegin\n  have hG : card G \u2260 0 := card_ne_zero,\n  refine \u27e8\u03bb h, _, \u03bb \u27e8n, hn\u27e9, of_card hn\u27e9,\n  suffices : \u2200 q \u2208 nat.factors (card G), q = p,\n  { use (card G).factors.length,\n    rw [\u2190list.prod_repeat, \u2190list.eq_repeat_of_mem this, nat.prod_factors hG] },\n  intros q hq,\n  obtain \u27e8hq1, hq2\u27e9 := (nat.mem_factors hG).mp hq,\n  haveI : fact q.prime := \u27e8hq1\u27e9,\n  obtain \u27e8g, hg\u27e9 := exists_prime_order_of_dvd_card q hq2,\n  obtain \u27e8k, hk\u27e9 := (iff_order_of.mp h) g,\n  exact (hq1.pow_eq_iff.mp (hg.symm.trans hk).symm).1.symm,\nend\n\nsection G_is_p_group\n\nvariables (hG : is_p_group p G)\n\ninclude hG\n\nlemma of_injective {H : Type*} [group H] (\u03d5 : H \u2192* G) (h\u03d5 : function.injective \u03d5) :\n  is_p_group p H :=\nbegin\n  simp_rw [is_p_group, \u2190h\u03d5.eq_iff, \u03d5.map_pow, \u03d5.map_one],\n  exact \u03bb h, hG (\u03d5 h),\nend\n\nlemma to_subgroup (H : subgroup G) : is_p_group p H :=\nhG.of_injective H.subtype subtype.coe_injective\n\nlemma of_surjective {H : Type*} [group H] (\u03d5 : G \u2192* H) (h\u03d5 : function.surjective \u03d5) :\n  is_p_group p H :=\nbegin\n  refine \u03bb h, exists.elim (h\u03d5 h) (\u03bb g hg, exists_imp_exists (\u03bb k hk, _) (hG g)),\n  rw [\u2190hg, \u2190\u03d5.map_pow, hk, \u03d5.map_one],\nend\n\nlemma to_quotient (H : subgroup G) [H.normal] :\n  is_p_group p (G \u29f8 H) :=\nhG.of_surjective (quotient_group.mk' H) quotient.surjective_quotient_mk'\n\nlemma of_equiv {H : Type*} [group H] (\u03d5 : G \u2243* H) : is_p_group p H :=\nhG.of_surjective \u03d5.to_monoid_hom \u03d5.surjective\n\nvariables [hp : fact p.prime]\n\ninclude hp\n\nlemma index (H : subgroup G) [fintype (G \u29f8 H)] :\n  \u2203 n : \u2115, H.index = p ^ n :=\nbegin\n  obtain \u27e8n, hn\u27e9 := iff_card.mp (hG.to_quotient H.normal_core),\n  obtain \u27e8k, hk1, hk2\u27e9 := (nat.dvd_prime_pow hp.out).mp ((congr_arg _\n    (H.normal_core.index_eq_card.trans hn)).mp (subgroup.index_dvd_of_le H.normal_core_le)),\n  exact \u27e8k, hk2\u27e9,\nend\n\nvariables {\u03b1 : Type*} [mul_action G \u03b1]\n\nlemma card_orbit (a : \u03b1) [fintype (orbit G a)] :\n  \u2203 n : \u2115, card (orbit G a) = p ^ n :=\nbegin\n  let \u03d5 := orbit_equiv_quotient_stabilizer G a,\n  haveI := fintype.of_equiv (orbit G a) \u03d5,\n  rw [card_congr \u03d5, \u2190subgroup.index_eq_card],\n  exact hG.index (stabilizer G a),\nend\n\nvariables (\u03b1) [fintype \u03b1] [fintype (fixed_points G \u03b1)]\n\n/-- If `G` is a `p`-group acting on a finite set `\u03b1`, then the number of fixed points\n  of the action is congruent mod `p` to the cardinality of `\u03b1` -/\nlemma card_modeq_card_fixed_points : card \u03b1 \u2261 card (fixed_points G \u03b1) [MOD p] :=\nbegin\n  classical,\n  calc card \u03b1 = card (\u03a3 y : quotient (orbit_rel G \u03b1), {x // quotient.mk' x = y}) :\n    card_congr (equiv.sigma_fiber_equiv (@quotient.mk' _ (orbit_rel G \u03b1))).symm\n  ... = \u2211 a : quotient (orbit_rel G \u03b1), card {x // quotient.mk' x = a} : card_sigma _\n  ... \u2261 \u2211 a : fixed_points G \u03b1, 1 [MOD p] : _\n  ... = _ : by simp; refl,\n  rw [\u2190zmod.eq_iff_modeq_nat p, nat.cast_sum, nat.cast_sum],\n  have key : \u2200 x, card {y // (quotient.mk' y : quotient (orbit_rel G \u03b1)) = quotient.mk' x} =\n    card (orbit G x) := \u03bb x, by simp only [quotient.eq']; congr,\n  refine eq.symm (finset.sum_bij_ne_zero (\u03bb a _ _, quotient.mk' a.1) (\u03bb _ _ _, finset.mem_univ _)\n    (\u03bb a\u2081 a\u2082 _ _ _ _ h, subtype.eq ((mem_fixed_points' \u03b1).mp a\u2082.2 a\u2081.1 (quotient.exact' h)))\n      (\u03bb b, quotient.induction_on' b (\u03bb b _ hb, _)) (\u03bb a ha _, by\n      { rw [key, mem_fixed_points_iff_card_orbit_eq_one.mp a.2] })),\n  obtain \u27e8k, hk\u27e9 := hG.card_orbit b,\n  have : k = 0 := nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge (mt (pow_dvd_pow p)\n    (by rwa [pow_one, \u2190hk, \u2190nat.modeq_zero_iff_dvd, \u2190zmod.eq_iff_modeq_nat, \u2190key,\n      nat.cast_zero])))),\n  exact \u27e8\u27e8b, mem_fixed_points_iff_card_orbit_eq_one.2 $ by rw [hk, this, pow_zero]\u27e9,\n    finset.mem_univ _, (ne_of_eq_of_ne nat.cast_one one_ne_zero), rfl\u27e9,\nend\n\n/-- If a p-group acts on `\u03b1` and the cardinality of `\u03b1` is not a multiple\n  of `p` then the action has a fixed point. -/\nlemma nonempty_fixed_point_of_prime_not_dvd_card (hp\u03b1 : \u00ac p \u2223 card \u03b1) :\n  (fixed_points G \u03b1).nonempty :=\n@set.nonempty_of_nonempty_subtype _ _ begin\nrw [\u2190card_pos_iff, pos_iff_ne_zero],\n  contrapose! hp\u03b1,\n  rw [\u2190nat.modeq_zero_iff_dvd, \u2190hp\u03b1],\n  exact hG.card_modeq_card_fixed_points \u03b1,\nend\n\n/-- If a p-group acts on `\u03b1` and the cardinality of `\u03b1` is a multiple\n  of `p`, and the action has one fixed point, then it has another fixed point. -/\nlemma exists_fixed_point_of_prime_dvd_card_of_fixed_point\n  (hp\u03b1 : p \u2223 card \u03b1) {a : \u03b1} (ha : a \u2208 fixed_points G \u03b1) :\n  \u2203 b, b \u2208 fixed_points G \u03b1 \u2227 a \u2260 b :=\nhave hpf : p \u2223 card (fixed_points G \u03b1) :=\n  nat.modeq_zero_iff_dvd.mp ((hG.card_modeq_card_fixed_points \u03b1).symm.trans hp\u03b1.modeq_zero_nat),\nhave h\u03b1 : 1 < card (fixed_points G \u03b1) :=\n  (fact.out p.prime).one_lt.trans_le (nat.le_of_dvd (card_pos_iff.2 \u27e8\u27e8a, ha\u27e9\u27e9) hpf),\nlet \u27e8\u27e8b, hb\u27e9, hba\u27e9 := exists_ne_of_one_lt_card h\u03b1 \u27e8a, ha\u27e9 in\n\u27e8b, hb, \u03bb hab, hba (by simp_rw [hab])\u27e9\n\nlemma center_nontrivial [nontrivial G] [fintype G] : nontrivial (subgroup.center G) :=\nbegin\n  classical,\n  have := (hG.of_equiv conj_act.to_conj_act).exists_fixed_point_of_prime_dvd_card_of_fixed_point G,\n  rw conj_act.fixed_points_eq_center at this,\n  obtain \u27e8g, hg\u27e9 := this _ (subgroup.center G).one_mem,\n  { exact \u27e8\u27e81, \u27e8g, hg.1\u27e9, mt subtype.ext_iff.mp hg.2\u27e9\u27e9 },\n  { obtain \u27e8n, hn\u27e9 := is_p_group.iff_card.mp hG,\n    rw hn,\n    apply dvd_pow_self,\n    rintro rfl,\n    exact (fintype.one_lt_card).ne' hn },\nend\n\nlemma bot_lt_center [nontrivial G] [fintype G] : \u22a5 < subgroup.center G :=\nbegin\n  haveI := center_nontrivial hG,\n  classical,\n  exact bot_lt_iff_ne_bot.mpr ((subgroup.center G).one_lt_card_iff_ne_bot.mp fintype.one_lt_card),\nend\n\nend G_is_p_group\n\nlemma to_le {H K : subgroup G} (hK : is_p_group p K) (hHK : H \u2264 K) : is_p_group p H :=\nhK.of_injective (subgroup.inclusion hHK) (\u03bb a b h, subtype.ext (show _, from subtype.ext_iff.mp h))\n\nlemma to_inf_left {H K : subgroup G} (hH : is_p_group p H) : is_p_group p (H \u2293 K : subgroup G) :=\nhH.to_le inf_le_left\n\nlemma to_inf_right {H K : subgroup G} (hK : is_p_group p K) : is_p_group p (H \u2293 K : subgroup G) :=\nhK.to_le inf_le_right\n\nlemma map {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]\n  (\u03d5 : G \u2192* K) : is_p_group p (H.map \u03d5) :=\nbegin\n  rw [\u2190H.subtype_range, monoid_hom.map_range],\n  exact hH.of_surjective (\u03d5.restrict H).range_restrict (\u03d5.restrict H).range_restrict_surjective,\nend\n\nlemma comap_of_ker_is_p_group {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]\n  (\u03d5 : K \u2192* G) (h\u03d5 : is_p_group p \u03d5.ker) : is_p_group p (H.comap \u03d5) :=\nbegin\n  intro g,\n  obtain \u27e8j, hj\u27e9 := hH \u27e8\u03d5 g.1, g.2\u27e9,\n  rw [subtype.ext_iff, H.coe_pow, subtype.coe_mk, \u2190\u03d5.map_pow] at hj,\n  obtain \u27e8k, hk\u27e9 := h\u03d5 \u27e8g.1 ^ p ^ j, hj\u27e9,\n  rwa [subtype.ext_iff, \u03d5.ker.coe_pow, subtype.coe_mk, \u2190pow_mul, \u2190pow_add] at hk,\n  exact \u27e8j + k, by rwa [subtype.ext_iff, (H.comap \u03d5).coe_pow]\u27e9,\nend\n\nlemma ker_is_p_group_of_injective {K : Type*} [group K] {\u03d5 : K \u2192* G} (h\u03d5 : function.injective \u03d5) :\n  is_p_group p \u03d5.ker :=\n(congr_arg (\u03bb Q : subgroup K, is_p_group p Q) (\u03d5.ker_eq_bot_iff.mpr h\u03d5)).mpr is_p_group.of_bot\n\nlemma comap_of_injective {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]\n  (\u03d5 : K \u2192* G) (h\u03d5 : function.injective \u03d5) : is_p_group p (H.comap \u03d5) :=\nhH.comap_of_ker_is_p_group \u03d5 (ker_is_p_group_of_injective h\u03d5)\n\nlemma comap_subtype {H : subgroup G} (hH : is_p_group p H) {K : subgroup G} :\n  is_p_group p (H.comap K.subtype) :=\nhH.comap_of_injective K.subtype subtype.coe_injective\n\nlemma to_sup_of_normal_right {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  [K.normal] : is_p_group p (H \u2294 K : subgroup G) :=\nbegin\n  rw [\u2190quotient_group.ker_mk K, \u2190subgroup.comap_map_eq],\n  apply (hH.map (quotient_group.mk' K)).comap_of_ker_is_p_group,\n  rwa quotient_group.ker_mk,\nend\n\nlemma to_sup_of_normal_left {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  [H.normal] : is_p_group p (H \u2294 K : subgroup G) :=\n(congr_arg (\u03bb H : subgroup G, is_p_group p H) sup_comm).mp (to_sup_of_normal_right hK hH)\n\nlemma to_sup_of_normal_right' {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  (hHK : H \u2264 K.normalizer) : is_p_group p (H \u2294 K : subgroup G) :=\nlet hHK' := to_sup_of_normal_right (hH.of_equiv (subgroup.comap_subtype_equiv_of_le hHK).symm)\n  (hK.of_equiv (subgroup.comap_subtype_equiv_of_le subgroup.le_normalizer).symm) in\n((congr_arg (\u03bb H : subgroup K.normalizer, is_p_group p H)\n  (subgroup.sup_subgroup_of_eq hHK subgroup.le_normalizer)).mp hHK').of_equiv\n  (subgroup.comap_subtype_equiv_of_le (sup_le hHK subgroup.le_normalizer))\n\nlemma to_sup_of_normal_left' {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)\n  (hHK : K \u2264 H.normalizer) : is_p_group p (H \u2294 K : subgroup G) :=\n(congr_arg (\u03bb H : subgroup G, is_p_group p H) sup_comm).mp (to_sup_of_normal_right' hK hH hHK)\n\n/-- finite p-groups with different p have coprime orders -/\nlemma coprime_card_of_ne {G\u2082 : Type*} [group G\u2082]\n  (p\u2081 p\u2082 : \u2115) [hp\u2081 : fact p\u2081.prime] [hp\u2082 : fact p\u2082.prime] (hne : p\u2081 \u2260 p\u2082)\n  (H\u2081 : subgroup G) (H\u2082 : subgroup G\u2082) [fintype H\u2081] [fintype H\u2082]\n  (hH\u2081 : is_p_group p\u2081 H\u2081) (hH\u2082 : is_p_group p\u2082 H\u2082) :\n  nat.coprime (fintype.card H\u2081) (fintype.card H\u2082) :=\nbegin\n  obtain \u27e8n\u2081, heq\u2081\u27e9 := iff_card.mp hH\u2081, rw heq\u2081, clear heq\u2081,\n  obtain \u27e8n\u2082, heq\u2082\u27e9 := iff_card.mp hH\u2082, rw heq\u2082, clear heq\u2082,\n  exact nat.coprime_pow_primes _ _ (hp\u2081.elim) (hp\u2082.elim) hne,\nend\n\n/-- p-groups with different p are disjoint -/\nlemma disjoint_of_ne (p\u2081 p\u2082 : \u2115) [hp\u2081 : fact p\u2081.prime] [hp\u2082 : fact p\u2082.prime] (hne : p\u2081 \u2260 p\u2082)\n  (H\u2081 H\u2082 : subgroup G) (hH\u2081 : is_p_group p\u2081 H\u2081) (hH\u2082 : is_p_group p\u2082 H\u2082) :\n  disjoint H\u2081 H\u2082 :=\nbegin\n  rintro x \u27e8hx\u2081, hx\u2082\u27e9,\n  rw subgroup.mem_bot,\n  obtain \u27e8n\u2081, hn\u2081\u27e9 := iff_order_of.mp hH\u2081 \u27e8x, hx\u2081\u27e9,\n  obtain \u27e8n\u2082, hn\u2082\u27e9 := iff_order_of.mp hH\u2082 \u27e8x, hx\u2082\u27e9,\n  rw [\u2190 order_of_subgroup, subgroup.coe_mk] at hn\u2081 hn\u2082,\n  have : p\u2081 ^ n\u2081 = p\u2082 ^ n\u2082, by rw [\u2190 hn\u2081, \u2190 hn\u2082],\n  have : n\u2081 = 0,\n  { contrapose! hne with h,\n    rw \u2190 associated_iff_eq at this \u22a2,\n    exact associated.of_pow_associated_of_prime\n      (nat.prime_iff.mp hp\u2081.elim) (nat.prime_iff.mp hp\u2082.elim) (ne.bot_lt h) this },\n  simpa [this] using hn\u2081,\nend\n\nend is_p_group\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/group_theory/p_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7130610306239826}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.group.defs\nimport Mathlib.logic.function.basic\nimport Mathlib.PostPort\n\nuniverses u u_1 \n\nnamespace Mathlib\n\n/--\nComposing two associative operations of `f : \u03b1 \u2192 \u03b1 \u2192 \u03b1` on the left\nis equal to an associative operation on the left.\n-/\ntheorem comp_assoc_left {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) [is_associative \u03b1 f] (x : \u03b1) (y : \u03b1) : f x \u2218 f y = f (f x y) := sorry\n\n/--\nComposing two associative operations of `f : \u03b1 \u2192 \u03b1 \u2192 \u03b1` on the right\nis equal to an associative operation on the right.\n-/\ntheorem comp_assoc_right {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1 \u2192 \u03b1) [is_associative \u03b1 f] (x : \u03b1) (y : \u03b1) : ((fun (z : \u03b1) => f z x) \u2218 fun (z : \u03b1) => f z y) = fun (z : \u03b1) => f z (f y x) := sorry\n\n/--\nComposing two multiplications on the left by `y` then `x`\nis equal to a multiplication on the left by `x * y`.\n-/\n@[simp] theorem comp_mul_left {\u03b1 : Type u_1} [semigroup \u03b1] (x : \u03b1) (y : \u03b1) : Mul.mul x \u2218 Mul.mul y = Mul.mul (x * y) :=\n  comp_assoc_left Mul.mul x y\n\n/--\nComposing two multiplications on the right by `y` and `x`\nis equal to a multiplication on the right by `y * x`.\n-/\n@[simp] theorem comp_add_right {\u03b1 : Type u_1} [add_semigroup \u03b1] (x : \u03b1) (y : \u03b1) : ((fun (_x : \u03b1) => _x + x) \u2218 fun (_x : \u03b1) => _x + y) = fun (_x : \u03b1) => _x + (y + x) :=\n  comp_assoc_right Add.add x y\n\ntheorem ite_add_zero {M : Type u} [add_monoid M] {P : Prop} [Decidable P] {a : M} {b : M} : ite P (a + b) 0 = ite P a 0 + ite P b 0 := sorry\n\ntheorem eq_one_iff_eq_one_of_mul_eq_one {M : Type u} [monoid M] {a : M} {b : M} (h : a * b = 1) : a = 1 \u2194 b = 1 := sorry\n\ntheorem add_left_comm {G : Type u} [add_comm_semigroup G] (a : G) (b : G) (c : G) : a + (b + c) = b + (a + c) :=\n  left_comm Add.add add_comm add_assoc\n\ntheorem mul_right_comm {G : Type u} [comm_semigroup G] (a : G) (b : G) (c : G) : a * b * c = a * c * b :=\n  right_comm Mul.mul mul_comm mul_assoc\n\ntheorem add_add_add_comm {G : Type u} [add_comm_semigroup G] (a : G) (b : G) (c : G) (d : G) : a + b + (c + d) = a + c + (b + d) := sorry\n\n@[simp] theorem bit0_zero {M : Type u} [add_monoid M] : bit0 0 = 0 :=\n  add_zero 0\n\n@[simp] theorem bit1_zero {M : Type u} [add_monoid M] [HasOne M] : bit1 0 = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (bit1 0 = 1)) (bit1.equations._eqn_1 0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 0 + 1 = 1)) bit0_zero))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 + 1 = 1)) (zero_add 1))) (Eq.refl 1)))\n\ntheorem neg_unique {M : Type u} [add_comm_monoid M] {x : M} {y : M} {z : M} (hy : x + y = 0) (hz : x + z = 0) : y = z :=\n  left_neg_eq_right_neg (trans (add_comm y x) hy) hz\n\n@[simp] theorem mul_eq_left_iff {M : Type u} [left_cancel_monoid M] {a : M} {b : M} : a * b = a \u2194 b = 1 :=\n  iff.trans (eq.mpr (id (Eq._oldrec (Eq.refl (a * b = a \u2194 a * b = a * 1)) (mul_one a))) (iff.refl (a * b = a)))\n    mul_left_cancel_iff\n\n@[simp] theorem left_eq_add_iff {M : Type u} [add_left_cancel_monoid M] {a : M} {b : M} : a = a + b \u2194 b = 0 :=\n  iff.trans eq_comm add_eq_left_iff\n\n@[simp] theorem mul_eq_right_iff {M : Type u} [right_cancel_monoid M] {a : M} {b : M} : a * b = b \u2194 a = 1 :=\n  iff.trans (eq.mpr (id (Eq._oldrec (Eq.refl (a * b = b \u2194 a * b = 1 * b)) (one_mul b))) (iff.refl (a * b = b)))\n    mul_right_cancel_iff\n\n@[simp] theorem right_eq_mul_iff {M : Type u} [right_cancel_monoid M] {a : M} {b : M} : b = a * b \u2194 a = 1 :=\n  iff.trans eq_comm mul_eq_right_iff\n\ntheorem neg_eq_zero_sub {G : Type u} [sub_neg_monoid G] (x : G) : -x = 0 - x :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-x = 0 - x)) (sub_eq_add_neg 0 x)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-x = 0 + -x)) (zero_add (-x)))) (Eq.refl (-x)))\n\ntheorem mul_one_div {G : Type u} [div_inv_monoid G] (x : G) (y : G) : x * (1 / y) = x / y :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (x * (1 / y) = x / y)) (div_eq_mul_inv 1 y)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (x * (1 * (y\u207b\u00b9)) = x / y)) (one_mul (y\u207b\u00b9))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (x * (y\u207b\u00b9) = x / y)) (div_eq_mul_inv x y))) (Eq.refl (x * (y\u207b\u00b9)))))\n\ntheorem mul_div_assoc {G : Type u} [div_inv_monoid G] {a : G} {b : G} {c : G} : a * b / c = a * (b / c) := sorry\n\ntheorem mul_div_assoc' {G : Type u} [div_inv_monoid G] (a : G) (b : G) (c : G) : a * (b / c) = a * b / c :=\n  Eq.symm mul_div_assoc\n\n@[simp] theorem one_div {G : Type u} [div_inv_monoid G] (a : G) : 1 / a = (a\u207b\u00b9) :=\n  Eq.symm (inv_eq_one_div a)\n\n@[simp] theorem neg_add_cancel_right {G : Type u} [add_group G] (a : G) (b : G) : a + -b + b = a := sorry\n\n@[simp] theorem neg_zero {G : Type u} [add_group G] : -0 = 0 :=\n  neg_eq_of_add_eq_zero (zero_add 0)\n\ntheorem left_inverse_inv (G : Type u_1) [group G] : function.left_inverse (fun (a : G) => a\u207b\u00b9) fun (a : G) => a\u207b\u00b9 :=\n  inv_inv\n\n@[simp] theorem inv_involutive {G : Type u} [group G] : function.involutive has_inv.inv :=\n  inv_inv\n\ntheorem neg_injective {G : Type u} [add_group G] : function.injective Neg.neg :=\n  function.involutive.injective neg_involutive\n\n@[simp] theorem neg_inj {G : Type u} [add_group G] {a : G} {b : G} : -a = -b \u2194 a = b :=\n  function.injective.eq_iff neg_injective\n\n@[simp] theorem add_neg_cancel_left {G : Type u} [add_group G] (a : G) (b : G) : a + (-a + b) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + (-a + b) = b)) (Eq.symm (add_assoc a (-a) b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -a + b = b)) (add_right_neg a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 + b = b)) (zero_add b))) (Eq.refl b)))\n\ntheorem add_left_surjective {G : Type u} [add_group G] (a : G) : function.surjective (Add.add a) :=\n  fun (x : G) => Exists.intro (-a + x) (add_neg_cancel_left a x)\n\ntheorem add_right_surjective {G : Type u} [add_group G] (a : G) : function.surjective fun (x : G) => x + a :=\n  fun (x : G) => Exists.intro (x + -a) (neg_add_cancel_right x a)\n\n@[simp] theorem mul_inv_rev {G : Type u} [group G] (a : G) (b : G) : a * b\u207b\u00b9 = b\u207b\u00b9 * (a\u207b\u00b9) := sorry\n\ntheorem eq_neg_of_eq_neg {G : Type u} [add_group G] {a : G} {b : G} (h : a = -b) : b = -a := sorry\n\ntheorem eq_neg_of_add_eq_zero {G : Type u} [add_group G] {a : G} {b : G} (h : a + b = 0) : a = -b := sorry\n\ntheorem eq_add_neg_of_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a + c = b) : a = b + -c := sorry\n\ntheorem eq_neg_add_of_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : b + a = c) : a = -b + c := sorry\n\ntheorem neg_add_eq_of_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : b = a + c) : -a + b = c := sorry\n\ntheorem mul_inv_eq_of_eq_mul {G : Type u} [group G] {a : G} {b : G} {c : G} (h : a = c * b) : a * (b\u207b\u00b9) = c := sorry\n\ntheorem eq_add_of_add_neg_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a + -c = b) : a = b + c := sorry\n\ntheorem eq_mul_of_inv_mul_eq {G : Type u} [group G] {a : G} {b : G} {c : G} (h : b\u207b\u00b9 * a = c) : a = b * c := sorry\n\ntheorem mul_eq_of_eq_inv_mul {G : Type u} [group G] {a : G} {b : G} {c : G} (h : b = a\u207b\u00b9 * c) : a * b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b = c)) h))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (a\u207b\u00b9 * c) = c)) (mul_inv_cancel_left a c))) (Eq.refl c))\n\ntheorem mul_eq_of_eq_mul_inv {G : Type u} [group G] {a : G} {b : G} {c : G} (h : a = c * (b\u207b\u00b9)) : a * b = c := sorry\n\ntheorem add_self_iff_eq_zero {G : Type u} [add_group G] {a : G} : a + a = a \u2194 a = 0 :=\n  eq.mp (Eq._oldrec (Eq.refl (a + a = a + 0 \u2194 a = 0)) (add_zero a)) (add_right_inj a)\n\n@[simp] theorem neg_eq_zero {G : Type u} [add_group G] {a : G} : -a = 0 \u2194 a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-a = 0 \u2194 a = 0)) (Eq.symm (propext neg_inj))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a = 0 \u2194 -a = -0)) neg_zero)) (iff.refl (-a = 0)))\n\n@[simp] theorem zero_eq_neg {G : Type u} [add_group G] {a : G} : 0 = -a \u2194 a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 = -a \u2194 a = 0)) (propext eq_comm)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a = 0 \u2194 a = 0)) (propext neg_eq_zero))) (iff.refl (a = 0)))\n\ntheorem neg_ne_zero {G : Type u} [add_group G] {a : G} : -a \u2260 0 \u2194 a \u2260 0 :=\n  not_congr neg_eq_zero\n\ntheorem eq_neg_iff_eq_neg {G : Type u} [add_group G] {a : G} {b : G} : a = -b \u2194 b = -a :=\n  { mp := eq_neg_of_eq_neg, mpr := eq_neg_of_eq_neg }\n\ntheorem neg_eq_iff_neg_eq {G : Type u} [add_group G] {a : G} {b : G} : -a = b \u2194 -b = a :=\n  iff.trans eq_comm (iff.trans eq_neg_iff_eq_neg eq_comm)\n\ntheorem mul_eq_one_iff_eq_inv {G : Type u} [group G] {a : G} {b : G} : a * b = 1 \u2194 a = (b\u207b\u00b9) := sorry\n\ntheorem mul_eq_one_iff_inv_eq {G : Type u} [group G] {a : G} {b : G} : a * b = 1 \u2194 a\u207b\u00b9 = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b = 1 \u2194 a\u207b\u00b9 = b)) (propext mul_eq_one_iff_eq_inv)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = (b\u207b\u00b9) \u2194 a\u207b\u00b9 = b)) (propext eq_inv_iff_eq_inv)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b = (a\u207b\u00b9) \u2194 a\u207b\u00b9 = b)) (propext eq_comm))) (iff.refl (a\u207b\u00b9 = b))))\n\ntheorem eq_neg_iff_add_eq_zero {G : Type u} [add_group G] {a : G} {b : G} : a = -b \u2194 a + b = 0 :=\n  iff.symm add_eq_zero_iff_eq_neg\n\ntheorem neg_eq_iff_add_eq_zero {G : Type u} [add_group G] {a : G} {b : G} : -a = b \u2194 a + b = 0 :=\n  iff.symm add_eq_zero_iff_neg_eq\n\ntheorem eq_mul_inv_iff_mul_eq {G : Type u} [group G] {a : G} {b : G} {c : G} : a = b * (c\u207b\u00b9) \u2194 a * c = b := sorry\n\ntheorem eq_inv_mul_iff_mul_eq {G : Type u} [group G] {a : G} {b : G} {c : G} : a = b\u207b\u00b9 * c \u2194 b * a = c := sorry\n\ntheorem inv_mul_eq_iff_eq_mul {G : Type u} [group G] {a : G} {b : G} {c : G} : a\u207b\u00b9 * b = c \u2194 b = a * c := sorry\n\ntheorem add_neg_eq_iff_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} : a + -b = c \u2194 a = c + b := sorry\n\ntheorem mul_inv_eq_one {G : Type u} [group G] {a : G} {b : G} : a * (b\u207b\u00b9) = 1 \u2194 a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b\u207b\u00b9) = 1 \u2194 a = b)) (propext mul_eq_one_iff_eq_inv)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = (b\u207b\u00b9\u207b\u00b9) \u2194 a = b)) (inv_inv b))) (iff.refl (a = b)))\n\ntheorem inv_mul_eq_one {G : Type u} [group G] {a : G} {b : G} : a\u207b\u00b9 * b = 1 \u2194 a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 * b = 1 \u2194 a = b)) (propext mul_eq_one_iff_eq_inv)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 = (b\u207b\u00b9) \u2194 a = b)) (propext inv_inj))) (iff.refl (a = b)))\n\n@[simp] theorem mul_left_eq_self {G : Type u} [group G] {a : G} {b : G} : a * b = b \u2194 a = 1 := sorry\n\n@[simp] theorem add_right_eq_self {G : Type u} [add_group G] {a : G} {b : G} : a + b = a \u2194 b = 0 := sorry\n\ntheorem sub_left_injective {G : Type u} [add_group G] {b : G} : function.injective fun (a : G) => a - b := sorry\n\ntheorem div_right_injective {G : Type u} [group G] {b : G} : function.injective fun (a : G) => b / a := sorry\n\n@[simp] theorem sub_self {G : Type u} [add_group G] (a : G) : a - a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - a = 0)) (sub_eq_add_neg a a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -a = 0)) (add_right_neg a))) (Eq.refl 0))\n\n@[simp] theorem sub_add_cancel {G : Type u} [add_group G] (a : G) (b : G) : a - b + b = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b + b = a)) (sub_eq_add_neg a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -b + b = a)) (neg_add_cancel_right a b))) (Eq.refl a))\n\n@[simp] theorem add_sub_cancel {G : Type u} [add_group G] (a : G) (b : G) : a + b - b = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + b - b = a)) (sub_eq_add_neg (a + b) b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + b + -b = a)) (add_neg_cancel_right a b))) (Eq.refl a))\n\ntheorem add_sub_assoc {G : Type u} [add_group G] (a : G) (b : G) (c : G) : a + b - c = a + (b - c) := sorry\n\ntheorem eq_of_sub_eq_zero {G : Type u} [add_group G] {a : G} {b : G} (h : a - b = 0) : a = b := sorry\n\ntheorem sub_eq_zero_of_eq {G : Type u} [add_group G] {a : G} {b : G} (h : a = b) : a - b = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = 0)) h))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b - b = 0)) (sub_self b))) (Eq.refl 0))\n\ntheorem sub_eq_zero_iff_eq {G : Type u} [add_group G] {a : G} {b : G} : a - b = 0 \u2194 a = b :=\n  { mp := eq_of_sub_eq_zero, mpr := sub_eq_zero_of_eq }\n\n@[simp] theorem sub_zero {G : Type u} [add_group G] (a : G) : a - 0 = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - 0 = a)) (sub_eq_add_neg a 0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -0 = a)) neg_zero))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 = a)) (add_zero a))) (Eq.refl a)))\n\ntheorem sub_ne_zero_of_ne {G : Type u} [add_group G] {a : G} {b : G} (h : a \u2260 b) : a - b \u2260 0 :=\n  id fun (hab : a - b = 0) => h (eq_of_sub_eq_zero hab)\n\n@[simp] theorem sub_neg_eq_add {G : Type u} [add_group G] (a : G) (b : G) : a - -b = a + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - -b = a + b)) (sub_eq_add_neg a (-b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + --b = a + b)) (neg_neg b))) (Eq.refl (a + b)))\n\n@[simp] theorem neg_sub {G : Type u} [add_group G] (a : G) (b : G) : -(a - b) = b - a := sorry\n\ntheorem add_sub {G : Type u} [add_group G] (a : G) (b : G) (c : G) : a + (b - c) = a + b - c := sorry\n\ntheorem sub_add_eq_sub_sub_swap {G : Type u} [add_group G] (a : G) (b : G) (c : G) : a - (b + c) = a - c - b := sorry\n\n@[simp] theorem add_sub_add_right_eq_sub {G : Type u} [add_group G] (a : G) (b : G) (c : G) : a + c - (b + c) = a - b := sorry\n\ntheorem eq_sub_of_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a + c = b) : a = b - c := sorry\n\ntheorem sub_eq_of_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a = c + b) : a - b = c := sorry\n\ntheorem eq_add_of_sub_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a - c = b) : a = b + c := sorry\n\ntheorem add_eq_of_eq_sub {G : Type u} [add_group G] {a : G} {b : G} {c : G} (h : a = c - b) : a + b = c := sorry\n\n@[simp] theorem sub_right_inj {G : Type u} [add_group G] {a : G} {b : G} {c : G} : a - b = a - c \u2194 b = c :=\n  function.injective.eq_iff sub_right_injective\n\n@[simp] theorem sub_left_inj {G : Type u} [add_group G] {a : G} {b : G} {c : G} : b - a = c - a \u2194 b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b - a = c - a \u2194 b = c)) (sub_eq_add_neg b a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b + -a = c - a \u2194 b = c)) (sub_eq_add_neg c a))) (add_left_inj (-a)))\n\ntheorem sub_add_sub_cancel {G : Type u} [add_group G] (a : G) (b : G) (c : G) : a - b + (b - c) = a - c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b + (b - c) = a - c)) (Eq.symm (add_sub_assoc (a - b) b c))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a - b + b - c = a - c)) (sub_add_cancel a b))) (Eq.refl (a - c)))\n\ntheorem sub_sub_sub_cancel_right {G : Type u} [add_group G] (a : G) (b : G) (c : G) : a - c - (b - c) = a - b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - c - (b - c) = a - b)) (Eq.symm (neg_sub c b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a - c - -(c - b) = a - b)) (sub_neg_eq_add (a - c) (c - b))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a - c + (c - b) = a - b)) (sub_add_sub_cancel a c b))) (Eq.refl (a - b))))\n\ntheorem sub_sub_assoc_swap {G : Type u} [add_group G] {a : G} {b : G} {c : G} : a - (b - c) = a + c - b := sorry\n\ntheorem sub_eq_zero {G : Type u} [add_group G] {a : G} {b : G} : a - b = 0 \u2194 a = b := sorry\n\ntheorem sub_ne_zero {G : Type u} [add_group G] {a : G} {b : G} : a - b \u2260 0 \u2194 a \u2260 b :=\n  not_congr sub_eq_zero\n\ntheorem eq_sub_iff_add_eq {G : Type u} [add_group G] {a : G} {b : G} {c : G} : a = b - c \u2194 a + c = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b - c \u2194 a + c = b)) (sub_eq_add_neg b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b + -c \u2194 a + c = b)) (propext eq_add_neg_iff_add_eq))) (iff.refl (a + c = b)))\n\ntheorem sub_eq_iff_eq_add {G : Type u} [add_group G] {a : G} {b : G} {c : G} : a - b = c \u2194 a = c + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = c \u2194 a = c + b)) (sub_eq_add_neg a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -b = c \u2194 a = c + b)) (propext add_neg_eq_iff_eq_add))) (iff.refl (a = c + b)))\n\ntheorem eq_iff_eq_of_sub_eq_sub {G : Type u} [add_group G] {a : G} {b : G} {c : G} {d : G} (H : a - b = c - d) : a = b \u2194 c = d :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b \u2194 c = d)) (Eq.symm (propext sub_eq_zero))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a - b = 0 \u2194 c = d)) H))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (c - d = 0 \u2194 c = d)) (propext sub_eq_zero))) (iff.refl (c = d))))\n\ntheorem left_inverse_sub_add_left {G : Type u} [add_group G] (c : G) : function.left_inverse (fun (x : G) => x - c) fun (x : G) => x + c :=\n  fun (x : G) => add_sub_cancel x c\n\ntheorem left_inverse_add_left_sub {G : Type u} [add_group G] (c : G) : function.left_inverse (fun (x : G) => x + c) fun (x : G) => x - c :=\n  fun (x : G) => sub_add_cancel x c\n\ntheorem left_inverse_add_right_neg_add {G : Type u} [add_group G] (c : G) : function.left_inverse (fun (x : G) => c + x) fun (x : G) => -c + x :=\n  fun (x : G) => add_neg_cancel_left c x\n\ntheorem left_inverse_neg_add_add_right {G : Type u} [add_group G] (c : G) : function.left_inverse (fun (x : G) => -c + x) fun (x : G) => c + x :=\n  fun (x : G) => neg_add_cancel_left c x\n\ntheorem neg_add {G : Type u} [add_comm_group G] (a : G) (b : G) : -(a + b) = -a + -b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-(a + b) = -a + -b)) (neg_add_rev a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-b + -a = -a + -b)) (add_comm (-b) (-a)))) (Eq.refl (-a + -b)))\n\ntheorem sub_add_eq_sub_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - (b + c) = a - b - c := sorry\n\ntheorem neg_add_eq_sub {G : Type u} [add_comm_group G] (a : G) (b : G) : -a + b = b - a := sorry\n\ntheorem sub_add_eq_add_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b + c = a + c - b := sorry\n\ntheorem sub_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b - c = a - (b + c) := sorry\n\ntheorem sub_add {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b + c = a - (b - c) := sorry\n\n@[simp] theorem add_sub_add_left_eq_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : c + a - (c + b) = a - b := sorry\n\ntheorem eq_sub_of_add_eq' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : c + a = b) : a = b - c := sorry\n\ntheorem sub_eq_of_eq_add' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : a = b + c) : a - b = c := sorry\n\ntheorem eq_add_of_sub_eq' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : a - b = c) : a = b + c := sorry\n\ntheorem add_eq_of_eq_sub' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} (h : b = c - a) : a + b = c := sorry\n\ntheorem sub_sub_self {G : Type u} [add_comm_group G] (a : G) (b : G) : a - (a - b) = b := sorry\n\ntheorem add_sub_comm {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) (d : G) : a + b - (c + d) = a - c + (b - d) := sorry\n\ntheorem sub_eq_sub_add_sub {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b = c - b + (a - c) := sorry\n\ntheorem neg_neg_sub_neg {G : Type u} [add_comm_group G] (a : G) (b : G) : -(-a - -b) = a - b := sorry\n\n@[simp] theorem sub_sub_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) : a - (a - b) = b :=\n  sub_sub_self a b\n\ntheorem sub_eq_neg_add {G : Type u} [add_comm_group G] (a : G) (b : G) : a - b = -b + a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = -b + a)) (sub_eq_add_neg a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + -b = -b + a)) (add_comm a (-b)))) (Eq.refl (-b + a)))\n\ntheorem neg_add' {G : Type u} [add_comm_group G] (a : G) (b : G) : -(a + b) = -a - b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-(a + b) = -a - b)) (sub_eq_add_neg (-a) b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-(a + b) = -a + -b)) (neg_add a b))) (Eq.refl (-a + -b)))\n\n@[simp] theorem neg_sub_neg {G : Type u} [add_comm_group G] (a : G) (b : G) : -a - -b = b - a := sorry\n\ntheorem eq_sub_iff_add_eq' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} : a = b - c \u2194 c + a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b - c \u2194 c + a = b)) (propext eq_sub_iff_add_eq)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + c = b \u2194 c + a = b)) (add_comm a c))) (iff.refl (c + a = b)))\n\ntheorem sub_eq_iff_eq_add' {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} : a - b = c \u2194 a = b + c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b = c \u2194 a = b + c)) (propext sub_eq_iff_eq_add)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = c + b \u2194 a = b + c)) (add_comm c b))) (iff.refl (a = b + c)))\n\n@[simp] theorem add_sub_cancel' {G : Type u} [add_comm_group G] (a : G) (b : G) : a + b - a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + b - a = b)) (sub_eq_neg_add (a + b) a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-a + (a + b) = b)) (neg_add_cancel_left a b))) (Eq.refl b))\n\n@[simp] theorem add_sub_cancel'_right {G : Type u} [add_comm_group G] (a : G) (b : G) : a + (b - a) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + (b - a) = b)) (Eq.symm (add_sub_assoc a b a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + b - a = b)) (add_sub_cancel' a b))) (Eq.refl b))\n\n-- This lemma is in the `simp` set under the name `add_neg_cancel_comm_assoc`,\n\n-- defined  in `algebra/group/commute`\n\ntheorem add_add_neg_cancel'_right {G : Type u} [add_comm_group G] (a : G) (b : G) : a + (b + -a) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + (b + -a) = b)) (Eq.symm (sub_eq_add_neg b a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + (b - a) = b)) (add_sub_cancel'_right a b))) (Eq.refl b))\n\ntheorem sub_right_comm {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b - c = a - c - b := sorry\n\n@[simp] theorem add_add_sub_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a + c + (b - c) = a + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + c + (b - c) = a + b)) (add_assoc a c (b - c))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + (c + (b - c)) = a + b)) (add_sub_cancel'_right c b))) (Eq.refl (a + b)))\n\n@[simp] theorem sub_add_add_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - c + (b + c) = a + b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - c + (b + c) = a + b)) (add_left_comm (a - c) b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b + (a - c + c) = a + b)) (sub_add_cancel a c)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b + a = a + b)) (add_comm b a))) (Eq.refl (a + b))))\n\n@[simp] theorem sub_add_sub_cancel' {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a - b + (c - a) = c - b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a - b + (c - a) = c - b)) (add_comm (a - b) (c - a)))) (sub_add_sub_cancel c a b)\n\n@[simp] theorem add_sub_sub_cancel {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : a + b - (a - c) = b + c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a + b - (a - c) = b + c)) (Eq.symm (sub_add (a + b) a c))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a + b - a + c = b + c)) (add_sub_cancel' a b))) (Eq.refl (b + c)))\n\n@[simp] theorem sub_sub_sub_cancel_left {G : Type u} [add_comm_group G] (a : G) (b : G) (c : G) : c - a - (c - b) = b - a := sorry\n\ntheorem sub_eq_sub_iff_add_eq_add {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} {d : G} : a - b = c - d \u2194 a + d = c + b := sorry\n\ntheorem sub_eq_sub_iff_sub_eq_sub {G : Type u} [add_comm_group G] {a : G} {b : G} {c : G} {d : G} : a - b = c - d \u2194 a - c = b - d := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/group/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7130610256269616}}
{"text": "import data.real.basic\nimport data.nat.prime\n\n/- Good work!\n62/62\n-/\n\n\n\n/-\n# Assignment 5\n\n- Homework 5 is due on Friday, February 24. \n- It is worth 62 points total.\n- Goal: get a working copy of the proof of the ivt\n\n# The intermediate value theorem\n-/\n\ndef approaches_at (f : \u211d \u2192 \u211d) (b : \u211d) (a : \u211d) :=\n\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, abs (x - a) < \u03b4 \u2192 abs (f x - b) < \u03b5\n\ndef continuous (f : \u211d \u2192 \u211d) := \u2200 a, approaches_at f (f a) a\n\nsection\nvariables (a b : \u211d) (f : \u211d \u2192 \u211d) (S : set \u211d)\n\n#check Sup S\n\n#check @Sup\n#check Sup { x : \u211d | a \u2264 x \u2227 x \u2264 b \u2227 f x < 0 }\n\n#check le_cSup\n#check @le_cSup \n\n#check cSup_le\n--#check @cSup_le\n\n--#print bdd_above.   \n--#print upper_bounds.\n\n#check exists_lt_of_lt_cSup\n--#check @exists_lt_of_lt_cSup\n\n#check tactic.linarith\n\n\n\ntheorem ivt {f : \u211d \u2192 \u211d} {a b : \u211d} (aleb : a \u2264 b)\n    (ctsf : continuous f) (hfa : f a < 0) (hfb : 0 < f b) :\n  \u2203 x, a \u2264 x \u2227 x \u2264 b \u2227 f x = 0 :=\nbegin\n  let S := {x : \u211d | a \u2264 x \u2227 x \u2264 b \u2227 f x < 0 },\n  have ainS : a \u2208 S, \n  { --dsimp,\n    exact \u27e8le_refl a, aleb, hfa\u27e9,  \n  },\n  \n  have bddS : bdd_above S,\n  { unfold bdd_above,\n  use b,\n  intros s sinS,\n  exact sinS.2.1,\n  },\n  have Sfull : S.nonempty,\n  { \n  use a, exact ainS,\n  },\n  \n  have e := Sup S,-- not the same\n  let d := Sup S,-- same, but no eqn\n  set c :=  Sup S with cdef,\n\n  have cleb: c \u2264 b,\n  { apply cSup_le Sfull,\n    intros s sinS,\n    exact sinS.2.1,\n  },\n\n  have alec: a \u2264 c,\n  { exact le_cSup bddS ainS,\n  },\n\n\n\n\n  rcases trichotomous_of (<) (f c) 0 with h | h | h,\n  {-- case where f c < 0, going for a contradiction  \n  exfalso,\n  specialize ctsf c,\n  set \u03b5 := - f c / 2 with \u03b5def,\n  have \u03b5pos : \u03b5 > 0 , linarith,\n  specialize ctsf \u03b5 \u03b5pos,\n  rcases ctsf with \u27e8\u03b4, \u03b4pos, h\u03b4\u27e9, \n  -- We need to check that c+\u03b4/2 is _in_ S\n  by_cases hcb: c+\u03b4/2 > b,\n  { have bnearc : | b - c | < \u03b4,\n    { rw abs_lt,\n      split; linarith,-- note the ; \n    },\n    specialize h\u03b4 b bnearc,\n    rw abs_lt at h\u03b4,\n    linarith, --deduces false from the inequalities\n  },\n  push_neg at hcb,\n  -- now in the case where c+\u03b4/2 \u2264 b.\n  have c2nearc: | c+ \u03b4/2 -c | < \u03b4,\n  { simp,\n    rw abs_lt,\n    split; --; says \"apply next command to all goals\"\n    linarith,\n  },\n  specialize h\u03b4 (c+\u03b4/2) c2nearc,\n  rw abs_lt at h\u03b4,\n  have fc2lt0 : f (c+\u03b4/2) <0,\n  { linarith,\n  },\n  have c2inS: c+\u03b4/2 \u2208 S,  --added after lecture\n  { exact \u27e8 by linarith,hcb, fc2lt0\u27e9, \n  },\n  have c2lec : c+\u03b4/2 \u2264c,  --added after lecture\n  { exact le_cSup bddS c2inS,\n  },\n  linarith   /-PROBLEM 1 [2pts]: replace `sorry` with\n             a single command on this line, using one \n             that will work with linear equaltions and/or\n             inequalities and derive a contradiction. \n             Hint: it has closed 5 subgoals above already!-/\n  },\n\n  {/- case where f c = 0\n      PROBLEM 2 [8pts]: complete the proof in this case.\n      We wrote `Done!` for this case on the board-/\n    exact \u27e8c, alec, cleb, h\u27e9 --can be done in one line using angle braces like these: \u27e8 , , \u27e9\n  },\n\n  --case where 0 < f c , also for a contradiction\n  /- PROBLEM 3 [52pts]: Fill in all the `sorry` commands below.\n     OR, if you are looking for a challenge, delete the rest of the\n     proof below and try to fill it in from scratch (or you \n     can try a middle ground, where you comment out the proof,\n     and only refer to it when you get stuck).  You get full credit\n     either way, so it is fine to use the outline.\n   -/\n\n\n\n  exfalso,\n  set \u03b5 := f c /2 with \u03b5def, -- define a new \u03b5 = (f c)/2\n  have \u03b5pos : 0 < \u03b5, -- \u03b5 is positive\n  { --[2pts]\n    linarith\n  },\n  specialize ctsf c,  -- we are inerested in continuity at c \n  specialize ctsf \u03b5 (\u03b5pos), -- use \u03b5 = (f c) / 2 in continuity at c\n  rcases ctsf with \u27e8 \u03b4, \u03b4pos, h\u03b4\u27e9, -- that produces a \u03b4 >0, which we study next\n  \n  have find_s : \u2203 s \u2208 S , c-\u03b4/2 < s,\n  { --[10pts] -- if you get stuck, look through the #check statements above.\n    apply exists_lt_of_lt_cSup,\n    apply Sfull,\n    linarith\n  },\n  \n  rcases find_s with \u27e8 s, sinS, hs \u27e9,-- pick a particular s \u2208 S with c-\u03b4/2 < s\n  \n  have slec : s \u2264 c,\n  { --[10pts]\n    apply le_cSup,\n    apply bddS,\n    apply sinS\n  },\n\n  have snearc : |s - c| < \u03b4,\n  { --[10pts]\n    have : |s - c| = c - s,\n    {\n      nth_rewrite 1 \u2190neg_sub,\n      apply abs_of_nonpos,\n      linarith\n    },\n    linarith\n  },\n\n  have fspos : 0 < f s,\n  { --[15pts]\n    by_contra fspos',\n    push_neg at fspos',\n    specialize (h\u03b4 s snearc),\n    rw \u2190not_le at h\u03b4,\n    apply h\u03b4,\n    have : f s - f c \u2264 0, { linarith },\n    rw abs_of_nonpos this,\n    linarith\n  },\n  --[5pts]\n  /- Verify that `linarith` alone does not work below.\n     What is missing?\n     It turns out the missing equation is f s < 0. \n     We essentially want to type:\n     linarith [f s < 0],\n     which tells linarith to run its usual plan, but also \n     use the inequality f s < 0.  However, we do not actually\n     write an inequality in the square brackets; we instead\n     write a _proof_ of the relevant inequality.  \n     So enter below the command \n     linarith [something], \n     where you replace the `something` with a proof term\n     for  f s < 0.  \n     (Hint: use the fact that s \u2208 S.)  \n  -/\n  linarith [sinS.right.right]\n\nend\n\n\nend", "meta": {"author": "PriyaMalhotra3", "repo": "har-ifvm-23-PriyaMalhotra3", "sha": "133a717f1d60680042ee0a514392106451853a71", "save_path": "github-repos/lean/PriyaMalhotra3-har-ifvm-23-PriyaMalhotra3", "path": "github-repos/lean/PriyaMalhotra3-har-ifvm-23-PriyaMalhotra3/har-ifvm-23-PriyaMalhotra3-133a717f1d60680042ee0a514392106451853a71/src/assignment5/assignment5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7130610197116583}}
{"text": "/-\nCopyright (c) 2021 Kalle Kyt\u00f6l\u00e4. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kyt\u00f6l\u00e4, Moritz Doll\n-/\nimport topology.algebra.module.basic\nimport linear_algebra.bilinear_map\n\n/-!\n# Weak dual topology\n\nThis file defines the weak topology given two vector spaces `E` and `F` over a commutative semiring\n`\ud835\udd5c` and a bilinear form `B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c`. The weak topology on `E` is the coarsest topology\nsuch that for all `y : F` every map `\u03bb x, B x y` is continuous.\n\nIn the case that `F = E \u2192L[\ud835\udd5c] \ud835\udd5c` and `B` being the canonical pairing, we obtain the weak-* topology,\n`weak_dual \ud835\udd5c E := (E \u2192L[\ud835\udd5c] \ud835\udd5c)`. Interchanging the arguments in the bilinear form yields the\nweak topology `weak_space \ud835\udd5c E := E`.\n\n## Main definitions\n\nThe main definitions are the types `weak_bilin B` for the general case and the two special cases\n`weak_dual \ud835\udd5c E` and `weak_space \ud835\udd5c E` with the respective topology instances on it.\n\n* Given `B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c`, the type `weak_bilin B` is a type synonym for `E`.\n* The instance `weak_bilin.topological_space` is the weak topology induced by the bilinear form `B`.\n* `weak_dual \ud835\udd5c E` is a type synonym for `dual \ud835\udd5c E` (when the latter is defined): both are equal to\n  the type `E \u2192L[\ud835\udd5c] \ud835\udd5c` of continuous linear maps from a module `E` over `\ud835\udd5c` to the ring `\ud835\udd5c`.\n* The instance `weak_dual.topological_space` is the weak-* topology on `weak_dual \ud835\udd5c E`, i.e., the\n  coarsest topology making the evaluation maps at all `z : E` continuous.\n* `weak_space \ud835\udd5c E` is a type synonym for `E` (when the latter is defined).\n* The instance `weak_dual.topological_space` is the weak topology on `E`, i.e., the\n  coarsest topology such that all `v : dual \ud835\udd5c E` remain continuous.\n\n## Main results\n\nWe establish that `weak_bilin B` has the following structure:\n* `weak_bilin.has_continuous_add`: The addition in `weak_bilin B` is continuous.\n* `weak_bilin.has_continuous_smul`: The scalar multiplication in `weak_bilin B` is continuous.\n\nWe prove the following results characterizing the weak topology:\n* `eval_continuous`: For any `y : F`, the evaluation mapping `\u03bb x, B x y` is continuous.\n* `continuous_of_continuous_eval`: For a mapping to `weak_bilin B` to be continuous,\n  it suffices that its compositions with pairing with `B` at all points `y : F` is continuous.\n* `tendsto_iff_forall_eval_tendsto`: Convergence in `weak_bilin B` can be characterized\n  in terms of convergence of the evaluations at all points `y : F`.\n\n## Notations\n\nNo new notation is introduced.\n\n## References\n\n* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]\n\n## Tags\n\nweak-star, weak dual, duality\n\n-/\n\nnoncomputable theory\nopen filter\nopen_locale topology\n\nvariables {\u03b1 \ud835\udd5c \ud835\udd5d R E F M : Type*}\n\nsection weak_topology\n\n/-- The space `E` equipped with the weak topology induced by the bilinear form `B`. -/\n@[derive [add_comm_monoid, module \ud835\udd5c],\nnolint has_nonempty_instance unused_arguments]\ndef weak_bilin [comm_semiring \ud835\udd5c] [add_comm_monoid E] [module \ud835\udd5c E] [add_comm_monoid F]\n  [module \ud835\udd5c F] (B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c) := E\n\nnamespace weak_bilin\n\ninstance [comm_semiring \ud835\udd5c] [a : add_comm_group E] [module \ud835\udd5c E] [add_comm_monoid F]\n  [module \ud835\udd5c F] (B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c) : add_comm_group (weak_bilin B) := a\n\n@[priority 100]\ninstance module' [comm_semiring \ud835\udd5c] [comm_semiring \ud835\udd5d] [add_comm_group E] [module \ud835\udd5c E]\n  [add_comm_group F] [module \ud835\udd5c F] [m : module \ud835\udd5d E] (B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c) :\n  module \ud835\udd5d (weak_bilin B) := m\n\ninstance [comm_semiring \ud835\udd5c] [comm_semiring \ud835\udd5d] [add_comm_group E] [module \ud835\udd5c E]\n  [add_comm_group F] [module \ud835\udd5c F] [has_smul \ud835\udd5d \ud835\udd5c] [module \ud835\udd5d E] [s : is_scalar_tower \ud835\udd5d \ud835\udd5c E]\n  (B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c) : is_scalar_tower \ud835\udd5d \ud835\udd5c (weak_bilin B) := s\n\nsection semiring\n\nvariables [topological_space \ud835\udd5c] [comm_semiring \ud835\udd5c]\nvariables [add_comm_monoid E] [module \ud835\udd5c E]\nvariables [add_comm_monoid F] [module \ud835\udd5c F]\nvariables (B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c)\n\ninstance : topological_space (weak_bilin B) :=\ntopological_space.induced (\u03bb x y, B x y) Pi.topological_space\n\n/-- The coercion `(\u03bb x y, B x y) : E \u2192 (F \u2192 \ud835\udd5c)` is continuous. -/\nlemma coe_fn_continuous : continuous (\u03bb (x : weak_bilin B) y, B x y) :=\ncontinuous_induced_dom\n\nlemma eval_continuous (y : F) : continuous (\u03bb x : weak_bilin B, B x y) :=\n( continuous_pi_iff.mp (coe_fn_continuous B)) y\n\nlemma continuous_of_continuous_eval [topological_space \u03b1] {g : \u03b1 \u2192 weak_bilin B}\n  (h : \u2200 y, continuous (\u03bb a, B (g a) y)) : continuous g :=\ncontinuous_induced_rng.2 (continuous_pi_iff.mpr h)\n\n/-- The coercion `(\u03bb x y, B x y) : E \u2192 (F \u2192 \ud835\udd5c)` is an embedding. -/\nlemma embedding {B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c} (hB : function.injective B) :\n  embedding (\u03bb (x : weak_bilin B)  y, B x y) :=\nfunction.injective.embedding_induced $ linear_map.coe_injective.comp hB\n\ntheorem tendsto_iff_forall_eval_tendsto {l : filter \u03b1} {f : \u03b1 \u2192 (weak_bilin B)} {x : weak_bilin B}\n  (hB : function.injective B) : tendsto f l (\ud835\udcdd x) \u2194 \u2200 y, tendsto (\u03bb i, B (f i) y) l (\ud835\udcdd (B x y)) :=\nby rw [\u2190 tendsto_pi_nhds, embedding.tendsto_nhds_iff (embedding hB)]\n\n/-- Addition in `weak_space B` is continuous. -/\ninstance [has_continuous_add \ud835\udd5c] : has_continuous_add (weak_bilin B) :=\nbegin\n  refine \u27e8continuous_induced_rng.2 _\u27e9,\n  refine cast (congr_arg _ _) (((coe_fn_continuous B).comp continuous_fst).add\n    ((coe_fn_continuous B).comp continuous_snd)),\n  ext,\n  simp only [function.comp_app, pi.add_apply, map_add, linear_map.add_apply],\nend\n\n/-- Scalar multiplication by `\ud835\udd5c` on `weak_bilin B` is continuous. -/\ninstance [has_continuous_smul \ud835\udd5c \ud835\udd5c] : has_continuous_smul \ud835\udd5c (weak_bilin B) :=\nbegin\n  refine \u27e8continuous_induced_rng.2 _\u27e9,\n  refine cast (congr_arg _ _) (continuous_fst.smul ((coe_fn_continuous B).comp continuous_snd)),\n  ext,\n  simp only [function.comp_app, pi.smul_apply, linear_map.map_smul\u209b\u2097, ring_hom.id_apply,\n    linear_map.smul_apply],\nend\n\nend semiring\n\nsection ring\n\nvariables [topological_space \ud835\udd5c] [comm_ring \ud835\udd5c]\nvariables [add_comm_group E] [module \ud835\udd5c E]\nvariables [add_comm_group F] [module \ud835\udd5c F]\nvariables (B : E \u2192\u2097[\ud835\udd5c] F \u2192\u2097[\ud835\udd5c] \ud835\udd5c)\n\n/-- `weak_space B` is a `topological_add_group`, meaning that addition and negation are\ncontinuous. -/\ninstance [has_continuous_add \ud835\udd5c] : topological_add_group (weak_bilin B) :=\n{ to_has_continuous_add := by apply_instance,\n  continuous_neg := begin\n    refine continuous_induced_rng.2 (continuous_pi_iff.mpr (\u03bb y, _)),\n    refine cast (congr_arg _ _) (eval_continuous B (-y)),\n    ext,\n    simp only [map_neg, function.comp_app, linear_map.neg_apply],\n  end }\n\nend ring\n\nend weak_bilin\n\nend weak_topology\n\nsection weak_star_topology\n\n/-- The canonical pairing of a vector space and its topological dual. -/\ndef top_dual_pairing (\ud835\udd5c E) [comm_semiring \ud835\udd5c] [topological_space \ud835\udd5c] [has_continuous_add \ud835\udd5c]\n  [add_comm_monoid E] [module \ud835\udd5c E] [topological_space E]\n  [has_continuous_const_smul \ud835\udd5c \ud835\udd5c] :\n  (E \u2192L[\ud835\udd5c] \ud835\udd5c) \u2192\u2097[\ud835\udd5c] E \u2192\u2097[\ud835\udd5c] \ud835\udd5c := continuous_linear_map.coe_lm \ud835\udd5c\n\nvariables [comm_semiring \ud835\udd5c] [topological_space \ud835\udd5c] [has_continuous_add \ud835\udd5c]\nvariables [has_continuous_const_smul \ud835\udd5c \ud835\udd5c]\nvariables [add_comm_monoid E] [module \ud835\udd5c E] [topological_space E]\n\nlemma dual_pairing_apply (v : (E \u2192L[\ud835\udd5c] \ud835\udd5c)) (x : E) : top_dual_pairing \ud835\udd5c E v x = v x := rfl\n\n/-- The weak star topology is the topology coarsest topology on `E \u2192L[\ud835\udd5c] \ud835\udd5c` such that all\nfunctionals `\u03bb v, top_dual_pairing \ud835\udd5c E v x` are continuous. -/\n@[derive [add_comm_monoid, module \ud835\udd5c, topological_space, has_continuous_add]]\ndef weak_dual (\ud835\udd5c E) [comm_semiring \ud835\udd5c] [topological_space \ud835\udd5c] [has_continuous_add \ud835\udd5c]\n  [has_continuous_const_smul \ud835\udd5c \ud835\udd5c] [add_comm_monoid E] [module \ud835\udd5c E] [topological_space E] :=\nweak_bilin (top_dual_pairing \ud835\udd5c E)\n\nnamespace weak_dual\n\ninstance : inhabited (weak_dual \ud835\udd5c E) := continuous_linear_map.inhabited\n\ninstance weak_dual.continuous_linear_map_class :\n  continuous_linear_map_class (weak_dual \ud835\udd5c E) \ud835\udd5c E \ud835\udd5c :=\ncontinuous_linear_map.continuous_semilinear_map_class\n\n/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`\ndirectly. -/\ninstance : has_coe_to_fun (weak_dual \ud835\udd5c E) (\u03bb _, E \u2192 \ud835\udd5c) := fun_like.has_coe_to_fun\n\n/-- If a monoid `M` distributively continuously acts on `\ud835\udd5c` and this action commutes with\nmultiplication on `\ud835\udd5c`, then it acts on `weak_dual \ud835\udd5c E`. -/\ninstance (M) [monoid M] [distrib_mul_action M \ud835\udd5c] [smul_comm_class \ud835\udd5c M \ud835\udd5c]\n  [has_continuous_const_smul M \ud835\udd5c] :\n  mul_action M (weak_dual \ud835\udd5c E) :=\ncontinuous_linear_map.mul_action\n\n/-- If a monoid `M` distributively continuously acts on `\ud835\udd5c` and this action commutes with\nmultiplication on `\ud835\udd5c`, then it acts distributively on `weak_dual \ud835\udd5c E`. -/\ninstance (M) [monoid M] [distrib_mul_action M \ud835\udd5c] [smul_comm_class \ud835\udd5c M \ud835\udd5c]\n  [has_continuous_const_smul M \ud835\udd5c] :\n  distrib_mul_action M (weak_dual \ud835\udd5c E) :=\ncontinuous_linear_map.distrib_mul_action\n\n/-- If `\ud835\udd5c` is a topological module over a semiring `R` and scalar multiplication commutes with the\nmultiplication on `\ud835\udd5c`, then `weak_dual \ud835\udd5c E` is a module over `R`. -/\ninstance module' (R) [semiring R] [module R \ud835\udd5c] [smul_comm_class \ud835\udd5c R \ud835\udd5c]\n  [has_continuous_const_smul R \ud835\udd5c] :\n  module R (weak_dual \ud835\udd5c E) :=\ncontinuous_linear_map.module\n\ninstance (M) [monoid M] [distrib_mul_action M \ud835\udd5c] [smul_comm_class \ud835\udd5c M \ud835\udd5c]\n  [has_continuous_const_smul M \ud835\udd5c] : has_continuous_const_smul M (weak_dual \ud835\udd5c E) :=\n\u27e8\u03bb m, continuous_induced_rng.2 $ (weak_bilin.coe_fn_continuous (top_dual_pairing \ud835\udd5c E)).const_smul m\u27e9\n\n/-- If a monoid `M` distributively continuously acts on `\ud835\udd5c` and this action commutes with\nmultiplication on `\ud835\udd5c`, then it continuously acts on `weak_dual \ud835\udd5c E`. -/\ninstance (M) [monoid M] [distrib_mul_action M \ud835\udd5c] [smul_comm_class \ud835\udd5c M \ud835\udd5c]\n  [topological_space M] [has_continuous_smul M \ud835\udd5c] :\n  has_continuous_smul M (weak_dual \ud835\udd5c E) :=\n\u27e8continuous_induced_rng.2 $ continuous_fst.smul ((weak_bilin.coe_fn_continuous\n                          (top_dual_pairing \ud835\udd5c E)).comp continuous_snd)\u27e9\n\nlemma coe_fn_continuous : continuous (\u03bb (x : weak_dual \ud835\udd5c E) y, x y) :=\ncontinuous_induced_dom\n\nlemma eval_continuous (y : E) : continuous (\u03bb x : weak_dual \ud835\udd5c E, x y) :=\ncontinuous_pi_iff.mp coe_fn_continuous y\n\nlemma continuous_of_continuous_eval [topological_space \u03b1] {g : \u03b1 \u2192 weak_dual \ud835\udd5c E}\n  (h : \u2200 y, continuous (\u03bb a, (g a) y)) : continuous g :=\ncontinuous_induced_rng.2 (continuous_pi_iff.mpr h)\n\ninstance [t2_space \ud835\udd5c] : t2_space (weak_dual \ud835\udd5c E) :=\nembedding.t2_space $ weak_bilin.embedding $\n  show function.injective (top_dual_pairing \ud835\udd5c E), from continuous_linear_map.coe_injective\n\nend weak_dual\n\n/-- The weak topology is the topology coarsest topology on `E` such that all\nfunctionals `\u03bb x, top_dual_pairing \ud835\udd5c E v x` are continuous. -/\n@[derive [add_comm_monoid, module \ud835\udd5c, topological_space, has_continuous_add],\nnolint has_nonempty_instance]\ndef weak_space (\ud835\udd5c E) [comm_semiring \ud835\udd5c] [topological_space \ud835\udd5c] [has_continuous_add \ud835\udd5c]\n  [has_continuous_const_smul \ud835\udd5c \ud835\udd5c] [add_comm_monoid E] [module \ud835\udd5c E] [topological_space E] :=\nweak_bilin (top_dual_pairing \ud835\udd5c E).flip\n\nnamespace weak_space\n\nvariables {\ud835\udd5c E F} [add_comm_monoid F] [module \ud835\udd5c F] [topological_space F]\n\n/-- A continuous linear map from `E` to `F` is still continuous when `E` and `F` are equipped with\ntheir weak topologies. -/\ndef map (f : E \u2192L[\ud835\udd5c] F) :\n  weak_space \ud835\udd5c E \u2192L[\ud835\udd5c] weak_space \ud835\udd5c F :=\n{ cont := weak_bilin.continuous_of_continuous_eval _ (\u03bb l, weak_bilin.eval_continuous _ (l \u2218L f)),\n  ..f }\n\nlemma map_apply (f : E \u2192L[\ud835\udd5c] F) (x : E) : weak_space.map f x = f x := rfl\n@[simp] lemma coe_map (f : E \u2192L[\ud835\udd5c] F) : (weak_space.map f : E \u2192 F) = f := rfl\n\nend weak_space\n\ntheorem tendsto_iff_forall_eval_tendsto_top_dual_pairing\n  {l : filter \u03b1} {f : \u03b1 \u2192 weak_dual \ud835\udd5c E} {x : weak_dual \ud835\udd5c E} :\n  tendsto f l (\ud835\udcdd x) \u2194\n    \u2200 y, tendsto (\u03bb i, top_dual_pairing \ud835\udd5c E (f i) y) l (\ud835\udcdd (top_dual_pairing \ud835\udd5c E x y)) :=\nweak_bilin.tendsto_iff_forall_eval_tendsto _ continuous_linear_map.coe_injective\n\nend weak_star_topology\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/module/weak_dual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7130277651658482}}
{"text": "/-\nCopyright (c) 2018 Guy Leroy. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes H\u00f6lzl, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.int.gcd\n! leanprover-community/mathlib commit d4f69d96f3532729da8ebb763f4bc26fcf640f06\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.GCD.Basic\nimport Mathlib.Algebra.Ring.Regular\nimport Mathlib.Data.Int.Dvd.Basic\nimport Mathlib.Order.Bounds.Basic\nimport Mathlib.Tactic.NormNum\n\n/-!\n# Extended GCD and divisibility over \u2124\n\n## Main definitions\n\n* Given `x y : \u2115`, `xgcd x y` computes the pair of integers `(a, b)` such that\n  `gcd x y = x * a + y * b`. `gcd_a x y` and `gcd_b x y` are defined to be `a` and `b`,\n  respectively.\n\n## Main statements\n\n* `gcd_eq_gcd_ab`: B\u00e9zout's lemma, given `x y : \u2115`, `gcd x y = x * gcd_a x y + y * gcd_b x y`.\n\n## Tags\n\nB\u00e9zout's lemma, Bezout's lemma\n-/\n\n\n/-! ### Extended Euclidean algorithm -/\n\n\nnamespace Nat\n\n/-- Helper function for the extended GCD algorithm (`Nat.xgcd`). -/\ndef xgcdAux : \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u2192 \u2124 \u2192 \u2124 \u2192 \u2115 \u00d7 \u2124 \u00d7 \u2124\n  | 0, _, _, r', s', t' => (r', s', t')\n  | succ k, s, t, r', s', t' =>\n    have : r' % succ k < succ k := mod_lt _ <| (succ_pos _).gt\n    let q := r' / succ k\n    xgcdAux (r' % succ k) (s' - q * s) (t' - q * t) (succ k) s t\n#align nat.xgcd_aux Nat.xgcdAux\n\n-- porting note: these are not in mathlib3; these equation lemmas are to fix\n-- complaints by the Lean 4 `unusedHavesSuffices` linter obtained when `simp [xgcdAux]` is used.\ntheorem xgcdAux_zero : xgcdAux 0 s t r' s' t' = (r', s', t') := rfl\n\ntheorem xgcdAux_succ : xgcdAux (succ k) s t r' s' t' =\n  xgcdAux (r' % succ k) (s' - (r' / succ k) * s) (t' - (r' / succ k) * t) (succ k) s t := rfl\n\n@[simp]\ntheorem xgcd_zero_left {s t r' s' t'} : xgcdAux 0 s t r' s' t' = (r', s', t') := by simp [xgcdAux]\n#align nat.xgcd_zero_left Nat.xgcd_zero_left\n\ntheorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) :\n    xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - r' / r * s) (t' - r' / r * t) r s t := by\n  obtain \u27e8r, rfl\u27e9 := Nat.exists_eq_succ_of_ne_zero h.ne'\n  rfl\n#align nat.xgcd_aux_rec Nat.xgcd_aux_rec\n\n/-- Use the extended GCD algorithm to generate the `a` and `b` values\n  satisfying `gcd x y = x * a + y * b`. -/\ndef xgcd (x y : \u2115) : \u2124 \u00d7 \u2124 :=\n  (xgcdAux x 1 0 y 0 1).2\n#align nat.xgcd Nat.xgcd\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcdA (x y : \u2115) : \u2124 :=\n  (xgcd x y).1\n#align nat.gcd_a Nat.gcdA\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcdB (x y : \u2115) : \u2124 :=\n  (xgcd x y).2\n#align nat.gcd_b Nat.gcdB\n\n@[simp]\ntheorem gcdA_zero_left {s : \u2115} : gcdA 0 s = 0 := by\n  unfold gcdA\n  rw [xgcd, xgcd_zero_left]\n#align nat.gcd_a_zero_left Nat.gcdA_zero_left\n\n@[simp]\ntheorem gcdB_zero_left {s : \u2115} : gcdB 0 s = 1 := by\n  unfold gcdB\n  rw [xgcd, xgcd_zero_left]\n#align nat.gcd_b_zero_left Nat.gcdB_zero_left\n\n@[simp]\ntheorem gcdA_zero_right {s : \u2115} (h : s \u2260 0) : gcdA s 0 = 1 := by\n  unfold gcdA xgcd\n  obtain \u27e8s, rfl\u27e9 := Nat.exists_eq_succ_of_ne_zero h\n  -- Porting note: `simp [xgcdAux_succ]` crashes Lean here\n  rw [xgcdAux_succ]\n  rfl\n#align nat.gcd_a_zero_right Nat.gcdA_zero_right\n\n@[simp]\ntheorem gcdB_zero_right {s : \u2115} (h : s \u2260 0) : gcdB s 0 = 0 := by\n  unfold gcdB xgcd\n  obtain \u27e8s, rfl\u27e9 := Nat.exists_eq_succ_of_ne_zero h\n  -- Porting note: `simp [xgcdAux_succ]` crashes Lean here\n  rw [xgcdAux_succ]\n  rfl\n#align nat.gcd_b_zero_right Nat.gcdB_zero_right\n\n@[simp]\ntheorem xgcd_aux_fst (x y) : \u2200 s t s' t', (xgcdAux x s t y s' t').1 = gcd x y :=\n  gcd.induction x y (by simp) fun x y h IH s t s' t' => by\n    simp [xgcd_aux_rec, h, IH]\n    rw [\u2190 gcd_rec]\n#align nat.xgcd_aux_fst Nat.xgcd_aux_fst\n\n\n\ntheorem xgcd_val (x y) : xgcd x y = (gcdA x y, gcdB x y) := by\n  unfold gcdA gcdB; cases xgcd x y; rfl\n#align nat.xgcd_val Nat.xgcd_val\n\nsection\n\nvariable (x y : \u2115)\n\nprivate def P : \u2115 \u00d7 \u2124 \u00d7 \u2124 \u2192 Prop\n  | (r, s, t) => (r : \u2124) = x * s + y * t\n\ntheorem xgcd_aux_P {r r'} :\n    \u2200 {s t s' t'}, P x y (r, s, t) \u2192 P x y (r', s', t') \u2192 P x y (xgcdAux r s t r' s' t') := by\n  induction r, r' using gcd.induction with\n  | H0 => simp\n  | H1 a b h IH =>\n    intro s t s' t' p p'\n    rw [xgcd_aux_rec h]; refine' IH _ p; dsimp [P] at *\n    rw [Int.emod_def]; generalize (b / a : \u2124) = k\n    rw [p, p', mul_sub, sub_add_eq_add_sub, mul_sub, add_mul, mul_comm k t, mul_comm k s,\n      \u2190 mul_assoc, \u2190 mul_assoc, add_comm (x * s * k), \u2190 add_sub_assoc, sub_sub]\nset_option linter.uppercaseLean3 false in\n#align nat.xgcd_aux_P Nat.xgcd_aux_P\n\n/-- **B\u00e9zout's lemma**: given `x y : \u2115`, `gcd x y = x * a + y * b`, where `a = gcd_a x y` and\n`b = gcd_b x y` are computed by the extended Euclidean algorithm.\n-/\ntheorem gcd_eq_gcd_ab : (gcd x y : \u2124) = x * gcdA x y + y * gcdB x y := by\n  have := @xgcd_aux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P])\n  rwa [xgcd_aux_val, xgcd_val] at this\n#align nat.gcd_eq_gcd_ab Nat.gcd_eq_gcd_ab\n\nend\n\ntheorem exists_mul_emod_eq_gcd {k n : \u2115} (hk : gcd n k < k) : \u2203 m, n * m % k = gcd n k := by\n  have hk' := Int.ofNat_ne_zero.2 (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk))\n  have key := congr_arg (fun (m : \u2124) => (m % k).toNat) (gcd_eq_gcd_ab n k)\n  simp only at key\n  rw [Int.add_mul_emod_self_left, \u2190 Int.coe_nat_mod, Int.toNat_coe_nat, mod_eq_of_lt hk] at key\n  refine' \u27e8(n.gcdA k % k).toNat, Eq.trans (Int.ofNat.inj _) key.symm\u27e9\n  rw [Int.ofNat_eq_coe, Int.coe_nat_mod, Int.ofNat_mul, Int.toNat_of_nonneg (Int.emod_nonneg _ hk'),\n    Int.ofNat_eq_coe, Int.toNat_of_nonneg (Int.emod_nonneg _ hk'), Int.mul_emod, Int.emod_emod,\n    \u2190 Int.mul_emod]\n#align nat.exists_mul_mod_eq_gcd Nat.exists_mul_emod_eq_gcd\n\ntheorem exists_mul_emod_eq_one_of_coprime {k n : \u2115} (hkn : coprime n k) (hk : 1 < k) :\n    \u2203 m, n * m % k = 1 :=\n  Exists.recOn (exists_mul_emod_eq_gcd (lt_of_le_of_lt (le_of_eq hkn) hk)) fun m hm \u21a6\n    \u27e8m, hm.trans hkn\u27e9\n#align nat.exists_mul_mod_eq_one_of_coprime Nat.exists_mul_emod_eq_one_of_coprime\n\nend Nat\n\n/-! ### Divisibility over \u2124 -/\n\n\nnamespace Int\n\nprotected theorem coe_nat_gcd (m n : \u2115) : Int.gcd \u2191m \u2191n = Nat.gcd m n :=\n  rfl\n#align int.coe_nat_gcd Int.coe_nat_gcd\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcdA : \u2124 \u2192 \u2124 \u2192 \u2124\n  | ofNat m, n => m.gcdA n.natAbs\n  | -[m+1], n => -m.succ.gcdA n.natAbs\n#align int.gcd_a Int.gcdA\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcdB : \u2124 \u2192 \u2124 \u2192 \u2124\n  | m, ofNat n => m.natAbs.gcdB n\n  | m, -[n+1] => -m.natAbs.gcdB n.succ\n#align int.gcd_b Int.gcdB\n\n/-- **B\u00e9zout's lemma** -/\ntheorem gcd_eq_gcd_ab : \u2200 x y : \u2124, (gcd x y : \u2124) = x * gcdA x y + y * gcdB x y\n  | (m : \u2115), (n : \u2115) => Nat.gcd_eq_gcd_ab _ _\n  | (m : \u2115), -[n+1] =>\n    show (_ : \u2124) = _ + -(n + 1) * -_ by rw [neg_mul_neg]; apply Nat.gcd_eq_gcd_ab\n  | -[m+1], (n : \u2115) =>\n    show (_ : \u2124) = -(m + 1) * -_ + _ by rw [neg_mul_neg]; apply Nat.gcd_eq_gcd_ab\n  | -[m+1], -[n+1] =>\n    show (_ : \u2124) = -(m + 1) * -_ + -(n + 1) * -_ by\n      rw [neg_mul_neg, neg_mul_neg]\n      apply Nat.gcd_eq_gcd_ab\n#align int.gcd_eq_gcd_ab Int.gcd_eq_gcd_ab\n\ntheorem natAbs_ediv (a b : \u2124) (H : b \u2223 a) : natAbs (a / b) = natAbs a / natAbs b := by\n  rcases Nat.eq_zero_or_pos (natAbs b) with (h | h)\n  rw [natAbs_eq_zero.1 h]\n  simp [Int.ediv_zero]\n  calc\n    natAbs (a / b) = natAbs (a / b) * 1 := by rw [mul_one]\n    _ = natAbs (a / b) * (natAbs b / natAbs b) := by rw [Nat.div_self h]\n    _ = natAbs (a / b) * natAbs b / natAbs b := by rw [Nat.mul_div_assoc _ dvd_rfl]\n    _ = natAbs (a / b * b) / natAbs b := by rw [natAbs_mul (a / b) b]\n    _ = natAbs a / natAbs b := by rw [Int.ediv_mul_cancel H]\n#align int.nat_abs_div Int.natAbs_ediv\n\ntheorem dvd_of_mul_dvd_mul_left {i j k : \u2124} (k_non_zero : k \u2260 0) (H : k * i \u2223 k * j) : i \u2223 j :=\n  Dvd.elim H fun l H1 => by rw [mul_assoc] at H1; exact \u27e8_, mul_left_cancel\u2080 k_non_zero H1\u27e9\n#align int.dvd_of_mul_dvd_mul_left Int.dvd_of_mul_dvd_mul_left\n\ntheorem dvd_of_mul_dvd_mul_right {i j k : \u2124} (k_non_zero : k \u2260 0) (H : i * k \u2223 j * k) : i \u2223 j := by\n  rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H\n#align int.dvd_of_mul_dvd_mul_right Int.dvd_of_mul_dvd_mul_right\n\n/-- \u2124 specific version of least common multiple. -/\ndef lcm (i j : \u2124) : \u2115 :=\n  Nat.lcm (natAbs i) (natAbs j)\n#align int.lcm Int.lcm\n\ntheorem lcm_def (i j : \u2124) : lcm i j = Nat.lcm (natAbs i) (natAbs j) :=\n  rfl\n#align int.lcm_def Int.lcm_def\n\nprotected theorem coe_nat_lcm (m n : \u2115) : Int.lcm \u2191m \u2191n = Nat.lcm m n :=\n  rfl\n#align int.coe_nat_lcm Int.coe_nat_lcm\n\ntheorem gcd_dvd_left (i j : \u2124) : (gcd i j : \u2124) \u2223 i :=\n  dvd_natAbs.mp <| coe_nat_dvd.mpr <| Nat.gcd_dvd_left _ _\n#align int.gcd_dvd_left Int.gcd_dvd_left\n\ntheorem gcd_dvd_right (i j : \u2124) : (gcd i j : \u2124) \u2223 j :=\n  dvd_natAbs.mp <| coe_nat_dvd.mpr <| Nat.gcd_dvd_right _ _\n#align int.gcd_dvd_right Int.gcd_dvd_right\n\ntheorem dvd_gcd {i j k : \u2124} (h1 : k \u2223 i) (h2 : k \u2223 j) : k \u2223 gcd i j :=\n  natAbs_dvd.1 <|\n    coe_nat_dvd.2 <| Nat.dvd_gcd (natAbs_dvd_natAbs.2 h1) (natAbs_dvd_natAbs.2 h2)\n#align int.dvd_gcd Int.dvd_gcd\n\ntheorem gcd_mul_lcm (i j : \u2124) : gcd i j * lcm i j = natAbs (i * j) := by\n  rw [Int.gcd, Int.lcm, Nat.gcd_mul_lcm, natAbs_mul]\n#align int.gcd_mul_lcm Int.gcd_mul_lcm\n\ntheorem gcd_comm (i j : \u2124) : gcd i j = gcd j i :=\n  Nat.gcd_comm _ _\n#align int.gcd_comm Int.gcd_comm\n\ntheorem gcd_assoc (i j k : \u2124) : gcd (gcd i j) k = gcd i (gcd j k) :=\n  Nat.gcd_assoc _ _ _\n#align int.gcd_assoc Int.gcd_assoc\n\n@[simp]\ntheorem gcd_self (i : \u2124) : gcd i i = natAbs i := by simp [gcd]\n#align int.gcd_self Int.gcd_self\n\n@[simp]\ntheorem gcd_zero_left (i : \u2124) : gcd 0 i = natAbs i := by simp [gcd]\n#align int.gcd_zero_left Int.gcd_zero_left\n\n@[simp]\ntheorem gcd_zero_right (i : \u2124) : gcd i 0 = natAbs i := by simp [gcd]\n#align int.gcd_zero_right Int.gcd_zero_right\n\n@[simp]\ntheorem gcd_one_left (i : \u2124) : gcd 1 i = 1 :=\n  Nat.gcd_one_left _\n#align int.gcd_one_left Int.gcd_one_left\n\n@[simp]\ntheorem gcd_one_right (i : \u2124) : gcd i 1 = 1 :=\n  Nat.gcd_one_right _\n#align int.gcd_one_right Int.gcd_one_right\n\n@[simp]\ntheorem gcd_neg_right {x y : \u2124} : gcd x (-y) = gcd x y := by rw [Int.gcd, Int.gcd, natAbs_neg]\n#align int.gcd_neg_right Int.gcd_neg_right\n\n@[simp]\ntheorem gcd_neg_left {x y : \u2124} : gcd (-x) y = gcd x y := by rw [Int.gcd, Int.gcd, natAbs_neg]\n#align int.gcd_neg_left Int.gcd_neg_left\n\ntheorem gcd_mul_left (i j k : \u2124) : gcd (i * j) (i * k) = natAbs i * gcd j k := by\n  rw [Int.gcd, Int.gcd, natAbs_mul, natAbs_mul]\n  apply Nat.gcd_mul_left\n#align int.gcd_mul_left Int.gcd_mul_left\n\ntheorem gcd_mul_right (i j k : \u2124) : gcd (i * j) (k * j) = gcd i k * natAbs j := by\n  rw [Int.gcd, Int.gcd, natAbs_mul, natAbs_mul]\n  apply Nat.gcd_mul_right\n#align int.gcd_mul_right Int.gcd_mul_right\n\ntheorem gcd_pos_of_non_zero_left {i : \u2124} (j : \u2124) (i_non_zero : i \u2260 0) : 0 < gcd i j :=\n  Nat.gcd_pos_of_pos_left (natAbs j) (natAbs_pos.2 i_non_zero)\n#align int.gcd_pos_of_non_zero_left Int.gcd_pos_of_non_zero_left\n\ntheorem gcd_pos_of_non_zero_right (i : \u2124) {j : \u2124} (j_non_zero : j \u2260 0) : 0 < gcd i j :=\n  Nat.gcd_pos_of_pos_right (natAbs i) (natAbs_pos.2 j_non_zero)\n#align int.gcd_pos_of_non_zero_right Int.gcd_pos_of_non_zero_right\n\ntheorem gcd_eq_zero_iff {i j : \u2124} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 := by\n  rw [gcd, Nat.gcd_eq_zero_iff, natAbs_eq_zero, natAbs_eq_zero]\n#align int.gcd_eq_zero_iff Int.gcd_eq_zero_iff\n\ntheorem gcd_pos_iff {i j : \u2124} : 0 < gcd i j \u2194 i \u2260 0 \u2228 j \u2260 0 :=\n  pos_iff_ne_zero.trans <| gcd_eq_zero_iff.not.trans not_and_or\n#align int.gcd_pos_iff Int.gcd_pos_iff\n\ntheorem gcd_div {i j k : \u2124} (H1 : k \u2223 i) (H2 : k \u2223 j) :\n    gcd (i / k) (j / k) = gcd i j / natAbs k := by\n  rw [gcd, natAbs_ediv i k H1, natAbs_ediv j k H2]\n  exact Nat.gcd_div (natAbs_dvd_natAbs.mpr H1) (natAbs_dvd_natAbs.mpr H2)\n#align int.gcd_div Int.gcd_div\n\ntheorem gcd_div_gcd_div_gcd {i j : \u2124} (H : 0 < gcd i j) : gcd (i / gcd i j) (j / gcd i j) = 1 := by\n  rw [gcd_div (gcd_dvd_left i j) (gcd_dvd_right i j), natAbs_ofNat, Nat.div_self H]\n#align int.gcd_div_gcd_div_gcd Int.gcd_div_gcd_div_gcd\n\ntheorem gcd_dvd_gcd_of_dvd_left {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd i j \u2223 gcd k j :=\n  Int.coe_nat_dvd.1 <| dvd_gcd ((gcd_dvd_left i j).trans H) (gcd_dvd_right i j)\n#align int.gcd_dvd_gcd_of_dvd_left Int.gcd_dvd_gcd_of_dvd_left\n\ntheorem gcd_dvd_gcd_of_dvd_right {i k : \u2124} (j : \u2124) (H : i \u2223 k) : gcd j i \u2223 gcd j k :=\n  Int.coe_nat_dvd.1 <| dvd_gcd (gcd_dvd_left j i) ((gcd_dvd_right j i).trans H)\n#align int.gcd_dvd_gcd_of_dvd_right Int.gcd_dvd_gcd_of_dvd_right\n\ntheorem gcd_dvd_gcd_mul_left (i j k : \u2124) : gcd i j \u2223 gcd (k * i) j :=\n  gcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n#align int.gcd_dvd_gcd_mul_left Int.gcd_dvd_gcd_mul_left\n\ntheorem gcd_dvd_gcd_mul_right (i j k : \u2124) : gcd i j \u2223 gcd (i * k) j :=\n  gcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n#align int.gcd_dvd_gcd_mul_right Int.gcd_dvd_gcd_mul_right\n\ntheorem gcd_dvd_gcd_mul_left_right (i j k : \u2124) : gcd i j \u2223 gcd i (k * j) :=\n  gcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n#align int.gcd_dvd_gcd_mul_left_right Int.gcd_dvd_gcd_mul_left_right\n\ntheorem gcd_dvd_gcd_mul_right_right (i j k : \u2124) : gcd i j \u2223 gcd i (j * k) :=\n  gcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n#align int.gcd_dvd_gcd_mul_right_right Int.gcd_dvd_gcd_mul_right_right\n\ntheorem gcd_eq_left {i j : \u2124} (H : i \u2223 j) : gcd i j = natAbs i :=\n  Nat.dvd_antisymm (Nat.gcd_dvd_left _ _) (Nat.dvd_gcd dvd_rfl (natAbs_dvd_natAbs.mpr H))\n#align int.gcd_eq_left Int.gcd_eq_left\n\ntheorem gcd_eq_right {i j : \u2124} (H : j \u2223 i) : gcd i j = natAbs j := by rw [gcd_comm, gcd_eq_left H]\n#align int.gcd_eq_right Int.gcd_eq_right\n\ntheorem ne_zero_of_gcd {x y : \u2124} (hc : gcd x y \u2260 0) : x \u2260 0 \u2228 y \u2260 0 := by\n  contrapose! hc\n  rw [hc.left, hc.right, gcd_zero_right, natAbs_zero]\n#align int.ne_zero_of_gcd Int.ne_zero_of_gcd\n\ntheorem exists_gcd_one {m n : \u2124} (H : 0 < gcd m n) :\n    \u2203 m' n' : \u2124, gcd m' n' = 1 \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\n  \u27e8_, _, gcd_div_gcd_div_gcd H, (Int.ediv_mul_cancel (gcd_dvd_left m n)).symm,\n    (Int.ediv_mul_cancel (gcd_dvd_right m n)).symm\u27e9\n#align int.exists_gcd_one Int.exists_gcd_one\n\ntheorem exists_gcd_one' {m n : \u2124} (H : 0 < gcd m n) :\n    \u2203 (g : \u2115)(m' n' : \u2124), 0 < g \u2227 gcd m' n' = 1 \u2227 m = m' * g \u2227 n = n' * g :=\n  let \u27e8m', n', h\u27e9 := exists_gcd_one H\n  \u27e8_, m', n', H, h\u27e9\n#align int.exists_gcd_one' Int.exists_gcd_one'\n\ntheorem pow_dvd_pow_iff {m n : \u2124} {k : \u2115} (k0 : 0 < k) : m ^ k \u2223 n ^ k \u2194 m \u2223 n := by\n  refine' \u27e8fun h => _, fun h => pow_dvd_pow_of_dvd h _\u27e9\n  rwa [\u2190 natAbs_dvd_natAbs, \u2190 Nat.pow_dvd_pow_iff k0, \u2190 Int.natAbs_pow, \u2190 Int.natAbs_pow,\n    natAbs_dvd_natAbs]\n#align int.pow_dvd_pow_iff Int.pow_dvd_pow_iff\n\ntheorem gcd_dvd_iff {a b : \u2124} {n : \u2115} : gcd a b \u2223 n \u2194 \u2203 x y : \u2124, \u2191n = a * x + b * y := by\n  constructor\n  \u00b7 intro h\n    rw [\u2190 Nat.mul_div_cancel' h, Int.ofNat_mul, gcd_eq_gcd_ab, add_mul, mul_assoc, mul_assoc]\n    exact \u27e8_, _, rfl\u27e9\n  \u00b7 rintro \u27e8x, y, h\u27e9\n    rw [\u2190 Int.coe_nat_dvd, h]\n    exact\n      dvd_add (dvd_mul_of_dvd_left (gcd_dvd_left a b) _) (dvd_mul_of_dvd_left (gcd_dvd_right a b) y)\n#align int.gcd_dvd_iff Int.gcd_dvd_iff\n\ntheorem gcd_greatest {a b d : \u2124} (hd_pos : 0 \u2264 d) (hda : d \u2223 a) (hdb : d \u2223 b)\n    (hd : \u2200 e : \u2124, e \u2223 a \u2192 e \u2223 b \u2192 e \u2223 d) : d = gcd a b :=\n  dvd_antisymm hd_pos (ofNat_zero_le (gcd a b)) (dvd_gcd hda hdb)\n    (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b))\n#align int.gcd_greatest Int.gcd_greatest\n\n/-- Euclid's lemma: if `a \u2223 b * c` and `gcd a c = 1` then `a \u2223 b`.\nCompare with `IsCoprime.dvd_of_dvd_mul_left` and\n`UniqueFactorizationMonoid.dvd_of_dvd_mul_left_of_no_prime_factors` -/\ntheorem dvd_of_dvd_mul_left_of_gcd_one {a b c : \u2124} (habc : a \u2223 b * c) (hab : gcd a c = 1) :\n    a \u2223 b := by\n  have := gcd_eq_gcd_ab a c\n  simp only [hab, Int.ofNat_zero, Int.ofNat_succ, zero_add] at this\n  have : b * a * gcdA a c + b * c * gcdB a c = b := by simp [mul_assoc, \u2190 mul_add, \u2190 this]\n  rw [\u2190 this]\n  exact dvd_add (dvd_mul_of_dvd_left (dvd_mul_left a b) _) (dvd_mul_of_dvd_left habc _)\n#align int.dvd_of_dvd_mul_left_of_gcd_one Int.dvd_of_dvd_mul_left_of_gcd_one\n\n/-- Euclid's lemma: if `a \u2223 b * c` and `gcd a b = 1` then `a \u2223 c`.\nCompare with `IsCoprime.dvd_of_dvd_mul_right` and\n`UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors` -/\ntheorem dvd_of_dvd_mul_right_of_gcd_one {a b c : \u2124} (habc : a \u2223 b * c) (hab : gcd a b = 1) :\n    a \u2223 c := by\n  rw [mul_comm] at habc\n  exact dvd_of_dvd_mul_left_of_gcd_one habc hab\n#align int.dvd_of_dvd_mul_right_of_gcd_one Int.dvd_of_dvd_mul_right_of_gcd_one\n\n/-- For nonzero integers `a` and `b`, `gcd a b` is the smallest positive natural number that can be\nwritten in the form `a * x + b * y` for some pair of integers `x` and `y` -/\ntheorem gcd_least_linear {a b : \u2124} (ha : a \u2260 0) :\n    IsLeast { n : \u2115 | 0 < n \u2227 \u2203 x y : \u2124, \u2191n = a * x + b * y } (a.gcd b) := by\n  simp_rw [\u2190 gcd_dvd_iff]\n  constructor\n  \u00b7 simpa [and_true_iff, dvd_refl, Set.mem_setOf_eq] using gcd_pos_of_non_zero_left b ha\n  \u00b7 simp only [lowerBounds, and_imp, Set.mem_setOf_eq]\n    exact fun n hn_pos hn => Nat.le_of_dvd hn_pos hn\n#align int.gcd_least_linear Int.gcd_least_linear\n\n/-! ### lcm -/\n\n\ntheorem lcm_comm (i j : \u2124) : lcm i j = lcm j i := by\n  rw [Int.lcm, Int.lcm]\n  exact Nat.lcm_comm _ _\n#align int.lcm_comm Int.lcm_comm\n\ntheorem lcm_assoc (i j k : \u2124) : lcm (lcm i j) k = lcm i (lcm j k) := by\n  rw [Int.lcm, Int.lcm, Int.lcm, Int.lcm, natAbs_ofNat, natAbs_ofNat]\n  apply Nat.lcm_assoc\n#align int.lcm_assoc Int.lcm_assoc\n\n@[simp]\ntheorem lcm_zero_left (i : \u2124) : lcm 0 i = 0 := by\n  rw [Int.lcm]\n  apply Nat.lcm_zero_left\n#align int.lcm_zero_left Int.lcm_zero_left\n\n@[simp]\ntheorem lcm_zero_right (i : \u2124) : lcm i 0 = 0 := by\n  rw [Int.lcm]\n  apply Nat.lcm_zero_right\n#align int.lcm_zero_right Int.lcm_zero_right\n\n@[simp]\ntheorem lcm_one_left (i : \u2124) : lcm 1 i = natAbs i := by\n  rw [Int.lcm]\n  apply Nat.lcm_one_left\n#align int.lcm_one_left Int.lcm_one_left\n\n@[simp]\ntheorem lcm_one_right (i : \u2124) : lcm i 1 = natAbs i := by\n  rw [Int.lcm]\n  apply Nat.lcm_one_right\n#align int.lcm_one_right Int.lcm_one_right\n\n@[simp]\ntheorem lcm_self (i : \u2124) : lcm i i = natAbs i := by\n  rw [Int.lcm]\n  apply Nat.lcm_self\n#align int.lcm_self Int.lcm_self\n\ntheorem dvd_lcm_left (i j : \u2124) : i \u2223 lcm i j := by\n  rw [Int.lcm]\n  apply coe_nat_dvd_right.mpr\n  apply Nat.dvd_lcm_left\n#align int.dvd_lcm_left Int.dvd_lcm_left\n\ntheorem dvd_lcm_right (i j : \u2124) : j \u2223 lcm i j := by\n  rw [Int.lcm]\n  apply coe_nat_dvd_right.mpr\n  apply Nat.dvd_lcm_right\n#align int.dvd_lcm_right Int.dvd_lcm_right\n\ntheorem lcm_dvd {i j k : \u2124} : i \u2223 k \u2192 j \u2223 k \u2192 (lcm i j : \u2124) \u2223 k := by\n  rw [Int.lcm]\n  intro hi hj\n  exact coe_nat_dvd_left.mpr (Nat.lcm_dvd (natAbs_dvd_natAbs.mpr hi) (natAbs_dvd_natAbs.mpr hj))\n#align int.lcm_dvd Int.lcm_dvd\n\nend Int\n\n@[to_additive gcd_nsmul_eq_zero]\ntheorem pow_gcd_eq_one {M : Type _} [Monoid M] (x : M) {m n : \u2115} (hm : x ^ m = 1) (hn : x ^ n = 1) :\n    x ^ m.gcd n = 1 := by\n  rcases m with (rfl | m); \u00b7 simp [hn]\n  obtain \u27e8y, rfl\u27e9 := isUnit_ofPowEqOne hm m.succ_ne_zero\n  simp only [\u2190 Units.val_pow_eq_pow_val] at *\n  rw [\u2190 Units.val_one, \u2190 zpow_coe_nat, \u2190 Units.ext_iff] at *\n  simp only [Nat.gcd_eq_gcd_ab, zpow_add, zpow_mul, hm, hn, one_zpow, one_mul]\n#align pow_gcd_eq_one pow_gcd_eq_one\n#align gcd_nsmul_eq_zero gcd_nsmul_eq_zero\n\n/-! ### GCD prover -/\n\n-- open NormNum\n\n-- namespace Tactic\n\n-- namespace NormNum\n\n-- theorem int_gcd_helper' {d : \u2115} {x y a b : \u2124} (h\u2081 : (d : \u2124) \u2223 x) (h\u2082 : (d : \u2124) \u2223 y)\n--     (h\u2083 : x * a + y * b = d) : Int.gcd x y = d := by\n--   refine' Nat.dvd_antisymm _ (Int.coe_nat_dvd.1 (Int.dvd_gcd h\u2081 h\u2082))\n--   rw [\u2190 Int.coe_nat_dvd, \u2190 h\u2083]\n--   apply dvd_add\n--   \u00b7 exact (Int.gcd_dvd_left _ _).mul_right _\n--   \u00b7 exact (Int.gcd_dvd_right _ _).mul_right _\n-- #align tactic.norm_num.int_gcd_helper' Tactic.NormNum.int_gcd_helper'\n\n-- theorem nat_gcd_helper_dvd_left (x y a : \u2115) (h : x * a = y) : Nat.gcd x y = x :=\n--   Nat.gcd_eq_left \u27e8a, h.symm\u27e9\n-- #align tactic.norm_num.nat_gcd_helper_dvd_left Tactic.NormNum.nat_gcd_helper_dvd_left\n\n-- theorem nat_gcd_helper_dvd_right (x y a : \u2115) (h : y * a = x) : Nat.gcd x y = y :=\n--   Nat.gcd_eq_right \u27e8a, h.symm\u27e9\n-- #align tactic.norm_num.nat_gcd_helper_dvd_right Tactic.NormNum.nat_gcd_helper_dvd_right\n\n-- theorem nat_gcd_helper_2 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n--     (hx : x * a = tx) (hy : y * b = ty) (h : ty + d = tx) : Nat.gcd x y = d := by\n--   rw [\u2190 Int.coe_nat_gcd];\n--   apply\n--     @int_gcd_helper' _ _ _ a (-b) (Int.coe_nat_dvd.2 \u27e8_, hu.symm\u27e9) (Int.coe_nat_dvd.2\n--      \u27e8_, hv.symm\u27e9)\n--   rw [mul_neg, \u2190 sub_eq_add_neg, sub_eq_iff_eq_add']\n--   norm_cast; rw [hx, hy, h]\n-- #align tactic.norm_num.nat_gcd_helper_2 Tactic.NormNum.nat_gcd_helper_2\n\n-- theorem nat_gcd_helper_1 (d x y a b u v tx ty : \u2115) (hu : d * u = x) (hv : d * v = y)\n--     (hx : x * a = tx) (hy : y * b = ty) (h : tx + d = ty) : Nat.gcd x y = d :=\n--   (Nat.gcd_comm _ _).trans <| nat_gcd_helper_2 _ _ _ _ _ _ _ _ _ hv hu hy hx h\n-- #align tactic.norm_num.nat_gcd_helper_1 Tactic.NormNum.nat_gcd_helper_1\n\n-- --Porting note: the `simp only` was not necessary in Lean3.\n-- theorem nat_lcm_helper (x y d m n : \u2115) (hd : Nat.gcd x y = d) (d0 : 0 < d) (xy : x * y = n)\n--     (dm : d * m = n) : Nat.lcm x y = m :=\n--   mul_right_injective\u2080 d0.ne' <| by simp only; rw [dm, \u2190 xy, \u2190 hd, Nat.gcd_mul_lcm]\n-- #align tactic.norm_num.nat_lcm_helper Tactic.NormNum.nat_lcm_helper\n\n-- theorem nat_coprime_helper_zero_left (x : \u2115) (h : 1 < x) : \u00acNat.coprime 0 x :=\n--   mt (Nat.coprime_zero_left _).1 <| ne_of_gt h\n-- #align tactic.norm_num.nat_coprime_helper_zero_left Tactic.NormNum.nat_coprime_helper_zero_left\n\n-- theorem nat_coprime_helper_zero_right (x : \u2115) (h : 1 < x) : \u00acNat.coprime x 0 :=\n--   mt (Nat.coprime_zero_right _).1 <| ne_of_gt h\n-- #align tactic.norm_num.nat_coprime_helper_zero_right Tactic.NormNum.nat_coprime_helper_zero_right\n\n-- theorem nat_coprime_helper_1 (x y a b tx ty : \u2115) (hx : x * a = tx) (hy : y * b = ty)\n--     (h : tx + 1 = ty) : Nat.coprime x y :=\n--   nat_gcd_helper_1 _ _ _ _ _ _ _ _ _ (one_mul _) (one_mul _) hx hy h\n-- #align tactic.norm_num.nat_coprime_helper_1 Tactic.NormNum.nat_coprime_helper_1\n\n-- theorem nat_coprime_helper_2 (x y a b tx ty : \u2115) (hx : x * a = tx) (hy : y * b = ty)\n--     (h : ty + 1 = tx) : Nat.coprime x y :=\n--   nat_gcd_helper_2 _ _ _ _ _ _ _ _ _ (one_mul _) (one_mul _) hx hy h\n-- #align tactic.norm_num.nat_coprime_helper_2 Tactic.NormNum.nat_coprime_helper_2\n\n-- theorem nat_not_coprime_helper (d x y u v : \u2115) (hu : d * u = x) (hv : d * v = y) (h : 1 < d) :\n--     \u00acNat.coprime x y :=\n--   Nat.not_coprime_of_dvd_of_dvd h \u27e8_, hu.symm\u27e9 \u27e8_, hv.symm\u27e9\n-- #align tactic.norm_num.nat_not_coprime_helper Tactic.NormNum.nat_not_coprime_helper\n\n-- theorem int_gcd_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx : \u2124) = x) (hy : (ny : \u2124) = y)\n--     (h : Nat.gcd nx ny = d) : Int.gcd x y = d := by rwa [\u2190 hx, \u2190 hy, Int.coe_nat_gcd]\n-- #align tactic.norm_num.int_gcd_helper Tactic.NormNum.int_gcd_helper\n\n-- theorem int_gcd_helper_neg_left (x y : \u2124) (d : \u2115) (h : Int.gcd x y = d) : Int.gcd (-x) y = d :=\n--  by rw [Int.gcd] at h\u22a2; rwa [Int.natAbs_neg]\n-- #align tactic.norm_num.int_gcd_helper_neg_left Tactic.NormNum.int_gcd_helper_neg_left\n\n-- theorem int_gcd_helper_neg_right (x y : \u2124) (d : \u2115) (h : Int.gcd x y = d) : Int.gcd x (-y) = d :=\n--  by rw [Int.gcd] at h\u22a2; rwa [Int.natAbs_neg]\n-- #align tactic.norm_num.int_gcd_helper_neg_right Tactic.NormNum.int_gcd_helper_neg_right\n\n-- theorem int_lcm_helper (x y : \u2124) (nx ny d : \u2115) (hx : (nx : \u2124) = x) (hy : (ny : \u2124) = y)\n--     (h : Nat.lcm nx ny = d) : Int.lcm x y = d := by rwa [\u2190 hx, \u2190 hy, Int.coe_nat_lcm]\n-- #align tactic.norm_num.int_lcm_helper Tactic.NormNum.int_lcm_helper\n\n-- theorem int_lcm_helper_neg_left (x y : \u2124) (d : \u2115) (h : Int.lcm x y = d) : Int.lcm (-x) y = d :=\n--  by rw [Int.lcm] at h\u22a2; rwa [Int.natAbs_neg]\n-- #align tactic.norm_num.int_lcm_helper_neg_left Tactic.NormNum.int_lcm_helper_neg_left\n\n-- theorem int_lcm_helper_neg_right (x y : \u2124) (d : \u2115) (h : Int.lcm x y = d) : Int.lcm x (-y) = d :=\n--  by rw [Int.lcm] at h\u22a2; rwa [Int.natAbs_neg]\n-- #align tactic.norm_num.int_lcm_helper_neg_right Tactic.NormNum.int_lcm_helper_neg_right\n\n-- /-- Evaluates the `nat.gcd` function. -/\n-- unsafe def prove_gcd_nat (c : instance_cache) (ex ey : expr) :\n--     tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n--   let x \u2190 ex.toNat\n--   let y \u2190 ey.toNat\n--   match x, y with\n--     | 0, _ => pure (c, ey, q(Nat.gcd_zero_left).mk_app [ey])\n--     | _, 0 => pure (c, ex, q(Nat.gcd_zero_right).mk_app [ex])\n--     | 1, _ => pure (c, q((1 : \u2115)), q(Nat.gcd_one_left).mk_app [ey])\n--     | _, 1 => pure (c, q((1 : \u2115)), q(Nat.gcd_one_right).mk_app [ex])\n--     | _, _ => do\n--       let (d, a, b) := Nat.xgcdAux x 1 0 y 0 1\n--       if d = x then do\n--           let (c, ea) \u2190 c (y / x)\n--           let (c, _, p) \u2190 prove_mul_nat c ex ea\n--           pure (c, ex, q(nat_gcd_helper_dvd_left).mk_app [ex, ey, ea, p])\n--         else\n--           if d = y then do\n--             let (c, ea) \u2190 c (x / y)\n--             let (c, _, p) \u2190 prove_mul_nat c ey ea\n--             pure (c, ey, q(nat_gcd_helper_dvd_right).mk_app [ex, ey, ea, p])\n--           else do\n--             let (c, ed) \u2190 c d\n--             let (c, ea) \u2190 c a\n--             let (c, eb) \u2190 c b\n--             let (c, eu) \u2190 c (x / d)\n--             let (c, ev) \u2190 c (y / d)\n--             let (c, _, pu) \u2190 prove_mul_nat c ed eu\n--             let (c, _, pv) \u2190 prove_mul_nat c ed ev\n--             let (c, etx, px) \u2190 prove_mul_nat c ex ea\n--             let (c, ety, py) \u2190 prove_mul_nat c ey eb\n--             let (c, p) \u2190 if a \u2265 0 then prove_add_nat c ety ed etx else prove_add_nat c etx ed ety\n--             let pf : expr := if a \u2265 0 then q(nat_gcd_helper_2) else q(nat_gcd_helper_1)\n--             pure (c, ed, pf [ed, ex, ey, ea, eb, eu, ev, etx, ety, pu, pv, px, py, p])\n-- #align tactic.norm_num.prove_gcd_nat tactic.norm_num.prove_gcd_nat\n\n-- /-- Evaluates the `nat.lcm` function. -/\n-- unsafe def prove_lcm_nat (c : instance_cache) (ex ey : expr) :\n--     tactic (instance_cache \u00d7 expr \u00d7 expr) := do\n--   let x \u2190 ex.toNat\n--   let y \u2190 ey.toNat\n--   match x, y with\n--     | 0, _ => pure (c, q((0 : \u2115)), q(Nat.lcm_zero_left).mk_app [ey])\n--     | _, 0 => pure (c, q((0 : \u2115)), q(Nat.lcm_zero_right).mk_app [ex])\n--     | 1, _ => pure (c, ey, q(Nat.lcm_one_left).mk_app [ey])\n--     | _, 1 => pure (c, ex, q(Nat.lcm_one_right).mk_app [ex])\n--     | _, _ => do\n--       let (c, ed, pd) \u2190 prove_gcd_nat c ex ey\n--       let (c, p0) \u2190 prove_pos c ed\n--       let (c, en, xy) \u2190 prove_mul_nat c ex ey\n--       let d \u2190 ed\n--       let (c, em) \u2190 c (x * y / d)\n--       let (c, _, dm) \u2190 prove_mul_nat c ed em\n--       pure (c, em, q(nat_lcm_helper).mk_app [ex, ey, ed, em, en, pd, p0, xy, dm])\n-- #align tactic.norm_num.prove_lcm_nat tactic.norm_num.prove_lcm_nat\n\n-- /-- Evaluates the `int.gcd` function. -/\n-- unsafe def prove_gcd_int (zc nc : instance_cache) :\n--     expr \u2192 expr \u2192 tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n--   | x, y =>\n--     match match_neg x with\n--     | some x => do\n--       let (zc, nc, d, p) \u2190 prove_gcd_int x y\n--       pure (zc, nc, d, q(int_gcd_helper_neg_left).mk_app [x, y, d, p])\n--     | none =>\n--       match match_neg y with\n--       | some y => do\n--         let (zc, nc, d, p) \u2190 prove_gcd_int x y\n--         pure (zc, nc, d, q(int_gcd_helper_neg_right).mk_app [x, y, d, p])\n--       | none => do\n--         let (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x\n--         let (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y\n--         let (nc, d, p) \u2190 prove_gcd_nat nc nx ny\n--         pure (zc, nc, d, q(int_gcd_helper).mk_app [x, y, nx, ny, d, px, py, p])\n-- #align tactic.norm_num.prove_gcd_int tactic.norm_num.prove_gcd_int\n\n-- /-- Evaluates the `int.lcm` function. -/\n-- unsafe def prove_lcm_int (zc nc : instance_cache) :\n--     expr \u2192 expr \u2192 tactic (instance_cache \u00d7 instance_cache \u00d7 expr \u00d7 expr)\n--   | x, y =>\n--     match match_neg x with\n--     | some x => do\n--       let (zc, nc, d, p) \u2190 prove_lcm_int x y\n--       pure (zc, nc, d, q(int_lcm_helper_neg_left).mk_app [x, y, d, p])\n--     | none =>\n--       match match_neg y with\n--       | some y => do\n--         let (zc, nc, d, p) \u2190 prove_lcm_int x y\n--         pure (zc, nc, d, q(int_lcm_helper_neg_right).mk_app [x, y, d, p])\n--       | none => do\n--         let (zc, nc, nx, px) \u2190 prove_nat_uncast zc nc x\n--         let (zc, nc, ny, py) \u2190 prove_nat_uncast zc nc y\n--         let (nc, d, p) \u2190 prove_lcm_nat nc nx ny\n--         pure (zc, nc, d, q(int_lcm_helper).mk_app [x, y, nx, ny, d, px, py, p])\n-- #align tactic.norm_num.prove_lcm_int tactic.norm_num.prove_lcm_int\n\n-- /-- Evaluates the `nat.coprime` function. -/\n-- unsafe def prove_coprime_nat (c : instance_cache) (ex ey : expr) :\n--     tactic (instance_cache \u00d7 Sum expr expr) := do\n--   let x \u2190 ex.toNat\n--   let y \u2190 ey.toNat\n--   match x, y with\n--     | 1, _ => pure (c, Sum.inl <| q(Nat.coprime_one_left).mk_app [ey])\n--     | _, 1 => pure (c, Sum.inl <| q(Nat.coprime_one_right).mk_app [ex])\n--     | 0, 0 => pure (c, Sum.inr q(Nat.not_coprime_zero_zero))\n--     | 0, _ => do\n--       let c \u2190 mk_instance_cache q(\u2115)\n--       let (c, p) \u2190 prove_lt_nat c q(1) ey\n--       pure (c, Sum.inr <| q(nat_coprime_helper_zero_left).mk_app [ey, p])\n--     | _, 0 => do\n--       let c \u2190 mk_instance_cache q(\u2115)\n--       let (c, p) \u2190 prove_lt_nat c q(1) ex\n--       pure (c, Sum.inr <| q(nat_coprime_helper_zero_right).mk_app [ex, p])\n--     | _, _ => do\n--       let c \u2190 mk_instance_cache q(\u2115)\n--       let (d, a, b) := Nat.xgcdAux x 1 0 y 0 1\n--       if d = 1 then do\n--           let (c, ea) \u2190 c a\n--           let (c, eb) \u2190 c b\n--           let (c, etx, px) \u2190 prove_mul_nat c ex ea\n--           let (c, ety, py) \u2190 prove_mul_nat c ey eb\n--           let (c, p) \u2190 if a \u2265 0 then\n--             prove_add_nat c ety q(1) etx else prove_add_nat c etx q(1) ety\n--           let pf : expr := if a \u2265 0 then q(nat_coprime_helper_2) else q(nat_coprime_helper_1)\n--           pure (c, Sum.inl <| pf [ex, ey, ea, eb, etx, ety, px, py, p])\n--         else do\n--           let (c, ed) \u2190 c d\n--           let (c, eu) \u2190 c (x / d)\n--           let (c, ev) \u2190 c (y / d)\n--           let (c, _, pu) \u2190 prove_mul_nat c ed eu\n--           let (c, _, pv) \u2190 prove_mul_nat c ed ev\n--           let (c, p) \u2190 prove_lt_nat c q(1) ed\n--           pure (c, Sum.inr <| q(nat_not_coprime_helper).mk_app [ed, ex, ey, eu, ev, pu, pv, p])\n-- #align tactic.norm_num.prove_coprime_nat tactic.norm_num.prove_coprime_nat\n\n-- /-- Evaluates the `gcd`, `lcm`, and `coprime` functions. -/\n-- @[norm_num]\n-- unsafe def eval_gcd : expr \u2192 tactic (expr \u00d7 expr)\n--   | q(Nat.gcd $(ex) $(ey)) => do\n--     let c \u2190 mk_instance_cache q(\u2115)\n--     Prod.snd <$> prove_gcd_nat c ex ey\n--   | q(Nat.lcm $(ex) $(ey)) => do\n--     let c \u2190 mk_instance_cache q(\u2115)\n--     Prod.snd <$> prove_lcm_nat c ex ey\n--   | q(Nat.Coprime $(ex) $(ey)) => do\n--     let c \u2190 mk_instance_cache q(\u2115)\n--     prove_coprime_nat c ex ey >>= Sum.elim true_intro false_intro \u2218 Prod.snd\n--   | q(Int.gcd $(ex) $(ey)) => do\n--     let zc \u2190 mk_instance_cache q(\u2124)\n--     let nc \u2190 mk_instance_cache q(\u2115)\n--     (Prod.snd \u2218 Prod.snd) <$> prove_gcd_int zc nc ex ey\n--   | q(Int.lcm $(ex) $(ey)) => do\n--     let zc \u2190 mk_instance_cache q(\u2124)\n--     let nc \u2190 mk_instance_cache q(\u2115)\n--     (Prod.snd \u2218 Prod.snd) <$> prove_lcm_int zc nc ex ey\n--   | _ => failed\n-- #align tactic.norm_num.eval_gcd tactic.norm_num.eval_gcd\n\n-- end NormNum\n\n-- end Tactic\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/GCD.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7130277586101781}}
{"text": "import linear_algebra.bilinear_form\nimport algebra.invertible\nimport annihilator\n-- import linear_algebra.direct_sum_module\n\nopen_locale classical\n\nuniverses u v w\n\nnamespace bilin_form\n\nvariables {M : Type u} {R : Type v} [add_comm_group M] [ring R] [module R M]\n\n/-- The perpendicular submodule of a submodule `N` is the set of elements all of \n  which are orthogonal to all elements of `N`. -/\ndef ortho (B : bilin_form R M) (N : submodule R M) : submodule R M := \n{ carrier := { m | \u2200 n \u2208 N, is_ortho B m n },\n  zero_mem' := \u03bb x _, ortho_zero x,\n  add_mem' := \u03bb x y hx hy n hn, \n    by rw [is_ortho, add_left, show B x n = 0, by exact hx n hn, \n        show B y n = 0, by exact hy n hn, zero_add],\n  smul_mem' := \u03bb c x hx n hn, \n    by rw [is_ortho, smul_left, show B x n = 0, by exact hx n hn, mul_zero] }\n\n/-- A set of vectors `v` is orthogonal with respect to some bilinear form `B` if \n  and only if for all `i \u2260 j`, `B (v i) (v j) = 0`. -/\ndef is_ortho' {n : Type w} (B : bilin_form R M) (v : n \u2192 M) : Prop :=\n  \u2200 i j : n, i \u2260 j \u2192 B (v j) (v i) = 0\n\n/-- The restriction of a bilinear form on a submodule. -/\ndef restrict (B : bilin_form R M) (W : submodule R M) : bilin_form R W := \n{ bilin := \u03bb a b, B a.1 b.1,\n  bilin_add_left := by simp,\n  bilin_smul_left := by simp,\n  bilin_add_right := by simp,\n  bilin_smul_right := by simp }.\n\n@[simp] lemma restrict_def (B : bilin_form R M) (W : submodule R M) (x y : W) : \n  B.restrict W x y = B x.1 y.1 := rfl\n\nlemma restrict_sym (B : bilin_form R M) (hB : sym_bilin_form.is_sym B) \n  (W : submodule R M) : sym_bilin_form.is_sym $ B.restrict W :=\n\u03bb x y, hB x.1 y.1\n\nend bilin_form\n\n/-- `std_basis` is the standard basis for vectors. -/\nnoncomputable def std_basis {R : Type v} [ring R] {n : Type w} \n  (i : n) : n \u2192 R := \u03bb j, if j = i then 1 else 0\n\nnamespace std_basis \n\nvariables {R : Type v} [ring R] {n : Type w} \n\nlemma eq_update (m : n) : std_basis m = function.update 0 m (1 : R) := \nby { ext, rw function.update_apply, refl }\n\nlemma linear_map.eq_std_basis (m : n) : \n  (std_basis m : n \u2192 R) = linear_map.std_basis R (\u03bb _, R) m 1 := \nby { rw linear_map.std_basis_apply, exact eq_update m }\n\n@[simp] lemma neq_eq_zero {i j : n} (h : i \u2260 j) : std_basis i j = (0 : R) := \n  if_neg h.symm\n\n@[simp] lemma eq_eq_one {i j : n} (h : i = j) : std_basis i j = (1 : R) := \n  if_pos h.symm\n\nlemma is_basis [fintype n] : @is_basis n R (n \u2192 R) std_basis _ _ _ := \nbegin\n  convert pi.is_basis_fun R n,\n  ext1 m, exact linear_map.eq_std_basis m, \nend\n\nlemma dot_product_eq_val (v : n \u2192 R) (i : n) [fintype n]:\n  v i = matrix.dot_product v (std_basis i) := \nbegin\n  rw [matrix.dot_product, finset.sum_eq_single i, eq_eq_one rfl, mul_one],\n  exact \u03bb _ _ hb, by rw [neq_eq_zero hb.symm, mul_zero],\n  exact \u03bb hi, false.elim (hi $ finset.mem_univ _)\nend\n\nend std_basis\n\nnamespace bilin_form \n\nvariables {M : Type u} {R : Type v} \n\n/-- A nondegenerate bilinear form is a bilinear form such that the only element \n  that is orthogonal to every other element is `0`. -/\ndef nondegenerate [add_comm_group M] [ring R] [module R M] (B : bilin_form R M) := \n  \u2200 m : M, (\u2200 n : M, B m n = 0) \u2192 m = 0\n\nvariables {n : Type w} [fintype n]\nvariables [add_comm_group M] [comm_ring R] [module R M]\n\nsection matrix\n\nlemma matrix.to_lin'_apply' (A : matrix n n R) (v w : n \u2192 R) : \n  (matrix.to_bilin' A) v w = matrix.dot_product v (A.mul_vec w) :=\nbegin\n  simp_rw [matrix.to_bilin'_apply, matrix.dot_product, \n           matrix.mul_vec, matrix.dot_product],\n  refine finset.sum_congr rfl (\u03bb _ _, _),\n  rw finset.mul_sum,\n  refine finset.sum_congr rfl (\u03bb _ _, _),\n  rw \u2190 mul_assoc,\nend\n\nlemma matrix.dot_product_eq_zero \n  (v : n \u2192 R) (h : \u2200 w, matrix.dot_product v w = 0) : v = 0 := \nbegin\n  refine funext (\u03bb x, _),\n  rw [std_basis.dot_product_eq_val v x, h _], refl,\nend\n\nlemma matrix.dot_product_vec_mul_eq_mul_vec {R : Type u} [ring R] \n  (A : matrix n n R) (v w : n \u2192 R) : \n  matrix.dot_product (A.vec_mul v) w = matrix.dot_product v (A.mul_vec w) := \nbegin\n  simp_rw [matrix.dot_product, matrix.vec_mul, matrix.mul_vec, \n    matrix.dot_product, finset.mul_sum, finset.sum_mul, \u2190 mul_assoc],\n  rw [finset.sum_comm]\nend\n\n/-- Let `A` be a symmetric matrix. Then `A` has trivial kernel, that is it is \n  invertible if and only if the induced bilinear form of `A` is nondegenerate. -/\ntheorem matrix.invertible_iff_nondegenerate (A : matrix n n R) \n  (temp : sym_bilin_form.is_sym A.to_bilin') : \n  A.to_bilin'.nondegenerate \u2194 A.to_lin'.ker = \u22a5 := \nbegin\n  rw linear_map.ker_eq_bot',\n  split; intro h,\n  { refine \u03bb m hm, h _ (\u03bb x, _),\n    rw [matrix.to_lin'_apply] at hm,\n    rw [temp, matrix.to_lin'_apply', hm], \n    exact matrix.dot_product_zero _ },\n  { intros m hm, apply h, \n    refine matrix.dot_product_eq_zero _ (\u03bb w, _),\n    have := hm w,\n    rwa [temp, matrix.to_lin'_apply', matrix.dot_product_comm] at this }\nend\n\n-- TODO:\n-- We would like a necessary and sufficent condition on which A.to_bilin' is \n-- symmetric so the condition is a prop on matrices not the induced bilinear \n-- product.\n\nend matrix\n\n/-- Let `B` be a symmetric, nondegenerate bilinear form on a nontrivial module \n  `M` over the ring `R` with invertible `2`. Then, there exists some `x : M` \n  such that `B x x \u2260 0`. -/\nlemma exists_bilin_form_self_neq_zero [htwo : invertible (2 : R)] \n  {B : bilin_form R M} (hB\u2081 : B.nondegenerate) (hB\u2082 : sym_bilin_form.is_sym B) \n  (hK : \u2203 x : M, x \u2260 0) : \u2203 x, B x x \u2260 0 :=\nbegin\n  by_contra, push_neg at h,\n  have : \u2200 u v : M, 2 * B u v = 0,\n  { intros u v,\n    rw [show 2 * B u v = B u u + B v u + B u v + B v v, \n          by rw [h u, h v, hB\u2082 v u]; ring, \n        show B u u + B v u + B u v + B v v = B (u + v) (u + v), \n          by simp [\u2190 add_assoc], h _] },\n  have hcon : \u2200 u v : M, B u v = 0,\n  { intros u v,\n    rw [show 0 = htwo.inv_of * (2 * B u v), by rw this; ring], simp [\u2190 mul_assoc] },\n  exact let \u27e8v, hv\u27e9 := hK in hv $ hB\u2081 v (hcon v),\nend\n\nvariables {V : Type u} {K : Type v} \nvariables [field K] [add_comm_group V] [vector_space K V] \n\n/-- A set of orthogonal vectors `v` with respect to some bilinear form `B` is \n  linearly independent if for all `i`, `B (v i) (v i) \u2260 0`. -/\nlemma is_ortho_linear_independent \n  {n : Type w} (B : bilin_form K V) {v : n \u2192 V} \n  (hv\u2081 : B.is_ortho' v) (hv\u2082 : \u2200 i, B (v i) (v i) \u2260 0) : linear_independent K v :=\nbegin\n  rw linear_independent_iff',\n  intros s w hs i hi,\n  have : B (s.sum $ \u03bb (i : n), w i \u2022 v i) (v i) = 0,\n  { rw [hs, zero_left] },\n  have hsum : s.sum (\u03bb (j : n), w j * B (v j) (v i)) = \n    s.sum (\u03bb (j : n), if i = j then w j * B (v j) (v i) else 0),\n  { refine finset.sum_congr rfl (\u03bb j hj, _),\n    by_cases (i = j),\n    { rw [if_pos h] },\n    { rw [if_neg h, hv\u2081 _ _ h, mul_zero] } },\n  simp_rw [map_sum_left, smul_left, hsum, finset.sum_ite_eq,\n           if_pos hi, mul_eq_zero] at this,\n  cases this, \n  { assumption },\n  { exact false.elim (hv\u2082 i $ this) }\nend\n\n-- \u2193 This lemma only applies in fields as we require `a * b = 0 \u2192 a = 0 \u2228 b = 0`\nlemma span_inf_ortho_eq_bot {B : bilin_form K V} (hB\u2081 : B.nondegenerate) \n  (hB\u2082 : sym_bilin_form.is_sym B) {x : V} (hx : B x x \u2260 0) : \n  submodule.span K ({x} : set V) \u2293 \n    B.ortho (submodule.span K ({x} : set V)) = \u22a5 := \nbegin\n  rw \u2190 finset.coe_singleton,\n  refine eq_bot_iff.2 (\u03bb y h, _),\n  rcases mem_span_finset.1 h.1 with \u27e8\u03bc, rfl\u27e9,\n  have := h.2 x _,\n  { rw finset.sum_singleton at this \u22a2,\n    suffices h\u03bczero : \u03bc x = 0,\n    { rw [h\u03bczero, zero_smul, submodule.mem_bot] },\n    change B (\u03bc x \u2022 x) x = 0 at this, rw [smul_left] at this,\n    exact or.elim (zero_eq_mul.mp this.symm) id (\u03bb hfalse, false.elim $ hx hfalse) },\n  { rw submodule.mem_span; exact \u03bb _ hp, hp $ finset.mem_singleton_self _ }\nend\n\n-- \u2193 This lemma only applies in field since we use the inverse\nlemma span_sup_ortho_eq_top {B : bilin_form K V} (hB\u2081 : B.nondegenerate) \n  (hB\u2082 : sym_bilin_form.is_sym B) {x : V} (hx : B x x \u2260 0) : \n  submodule.span K ({x} : set V) \u2294 \n    B.ortho (submodule.span K ({x} : set V)) = \u22a4 := \nbegin\n  refine eq_top_iff.2 (\u03bb y _, _), rw submodule.mem_sup,\n  refine \u27e8(B x y * (B x x)\u207b\u00b9) \u2022 x, _, y - (B x y * (B x x)\u207b\u00b9) \u2022 x, _, _\u27e9,\n  { exact submodule.mem_span_singleton.2 \u27e8(B x y * (B x x)\u207b\u00b9), rfl\u27e9 },\n  { intros z hz,\n    rcases submodule.mem_span_singleton.1 hz with \u27e8\u03bc, rfl\u27e9,\n    simp [is_ortho, mul_assoc, inv_mul_cancel hx, hB\u2082 x] },\n  { simp }\nend\n\nlemma is_compl_prop [hK : invertible (2 : K)] {B : bilin_form K V} -- temp\n  (hB\u2081 : B.nondegenerate) (hB\u2082 : sym_bilin_form.is_sym B) (hV : \u2203 x : V, x \u2260 0) : \n  \u2203 W : submodule K V, W \u2293 B.ortho W = \u22a5 \u2227 W \u2294 B.ortho W = \u22a4 :=\nbegin\n  rcases exists_bilin_form_self_neq_zero hB\u2081 hB\u2082 hV with \u27e8x, hx\u27e9,\n  refine \u27e8submodule.span K ({x} : set V), \n    span_inf_ortho_eq_bot hB\u2081 hB\u2082 hx, span_sup_ortho_eq_top hB\u2081 hB\u2082 hx\u27e9\nend\n\ndef is_compl_singleton [hK : invertible (2 : K)] {B : bilin_form K V} \n  (hB\u2081 : B.nondegenerate) (hB\u2082 : sym_bilin_form.is_sym B) {x : V} (hx : B x x \u2260 0) : \n  is_compl (submodule.span K ({x} : set V)) \n    (B.ortho (submodule.span K ({x} : set V))) := \n{ inf_le_bot := eq_bot_iff.1 $ span_inf_ortho_eq_bot hB\u2081 hB\u2082 hx,\n  top_le_sup := eq_top_iff.1 $ span_sup_ortho_eq_top hB\u2081 hB\u2082 hx }\n\n/-- The natural isomorphism between a singleton and the quotient by its \n  orthogonal complement. -/\nnoncomputable def quotient_equiv_of_ortho_singleton \n  [hK : invertible (2 : K)] {B : bilin_form K V} (hB\u2081 : B.nondegenerate) \n  (hB\u2082 : sym_bilin_form.is_sym B) {x : V} (hx : B x x \u2260 0) := \n  submodule.quotient_equiv_of_is_compl _ _ (is_compl_singleton hB\u2081 hB\u2082 hx)\n  \n/-- The natural isomorphism from the product between a singleton and its \n  orthogonal component and the whole space. -/\nnoncomputable def prod_equiv_of_ortho_singleton \n  [hK : invertible (2 : K)] {B : bilin_form K V} (hB\u2081 : B.nondegenerate) \n  (hB\u2082 : sym_bilin_form.is_sym B) {x : V} (hx : B x x \u2260 0) :=\n  submodule.prod_equiv_of_is_compl _ _ (is_compl_singleton hB\u2081 hB\u2082 hx)\n\nlemma restrict_ortho_singleton_nondegenerate (B : bilin_form K V) (hB\u2081 : nondegenerate B) \n  (hB\u2082 : sym_bilin_form.is_sym B) {x : V} (hx : B x x \u2260 0) : \n  nondegenerate $ B.restrict $ B.ortho (submodule.span K ({x} : set V)) :=\nbegin\n  refine \u03bb m hm, submodule.coe_eq_zero.1 (hB\u2081 m.1 (\u03bb n, _)),\n  have : n \u2208 submodule.span K ({x} : set V) \u2294 \n    B.ortho (submodule.span K ({x} : set V)) :=\n    (span_sup_ortho_eq_top hB\u2081 hB\u2082 hx).symm \u25b8 submodule.mem_top,\n  rcases submodule.mem_sup.1 this with \u27e8y, hy, z, hz, rfl\u27e9,\n  specialize hm \u27e8z, hz\u27e9, \n  rw [restrict_def, subtype.val_eq_coe] at hm,\n  erw [add_right, show B m.1 y = 0, by exact m.2 y hy, hm, add_zero]\nend\n\n/- Let V be a finite dimensional vector space over the field K with the \n  nondegenerate bilinear form B. Then for all m \u2208 M, f_m : M \u2192 R : n \u21a6 B m n is \n  a linear functional in the dual space.\n\n  Furthermore, the map, \u03c6 : M \u2192 M* : m \u21a6 f_m is an isomorphism.\n-/\n\n/-- Given a bilinear form `B`, `to_dual_aux` maps elements `m` of the module `M`\n  to the functional `\u03bb x, B m x` in the dual space. -/\ndef to_dual_aux (B : bilin_form R M) (m : M) : module.dual R M := \n{ to_fun := \u03bb n, B m n,\n  map_add' := add_right m,\n  map_smul' := \u03bb _ _, by simp only [algebra.id.smul_eq_mul, smul_right] }\n\n@[simp] lemma to_dual_aux_def {B : bilin_form R M} {m n : M} : \n  B.to_dual_aux m n = B m n := rfl\n\n/-- Given a bilinear form `B` on the modual `M`, `to_dual' B` is the linear map \n  from `M` to its dual such that `to_dual B m` is the functional `\u03bb x, B m x`. -/\ndef to_dual' (B : bilin_form R M) : M \u2192\u2097[R] module.dual R M := \n{ to_fun := \u03bb m, to_dual_aux B m,\n  map_add' := by { intros, ext, simp },\n  map_smul' := by { intros, ext, simp } }\n \nlemma to_dual'_injective (B : bilin_form R M) (hB : B.nondegenerate) : \n  function.injective (to_dual' B) :=\nB.to_dual'.to_add_monoid_hom.injective_iff.2 (\u03bb a ha, hB _ (linear_map.congr_fun ha))\n\nsection finite_dimensional\n\nopen finite_dimensional\n\nvariable [finite_dimensional K V] \n\n-- In order to show that `to_dual` is a surjective map we used the fact that \n-- the dimensions of a vector space equal to the dimensions of its dual.\n-- So rather than working with modules over rings, we work with vecotor spaces\nlemma to_dual'_bijective (B : bilin_form K V) (hB : B.nondegenerate) : \n  function.bijective (to_dual' B) :=\nbegin\n  refine \u27e8B.to_dual'_injective hB, _\u27e9,\n  change function.surjective B.to_dual',\n  refine (linear_map.injective_iff_surjective_of_findim_eq_findim \n    (linear_equiv.findim_eq _)).1 (B.to_dual'_injective hB),\n  have hB := classical.some_spec (exists_is_basis_finite K V),\n  haveI := classical.choice hB.2,\n  exact is_basis.to_dual_equiv _ hB.1\nend\n\n/-- To dual is the `linear_equiv` with the underlying linear map `to_dual'`. -/\nnoncomputable def to_dual (B : bilin_form K V) (hB : B.nondegenerate) : \n  V \u2243\u2097[K] module.dual K V := \n{ map_smul' := B.to_dual'.map_smul',\n  .. add_equiv.of_bijective B.to_dual'.to_add_monoid_hom (to_dual'_bijective B hB) }\n\n-- We start proving that bilinear forms are diagonalisable\n-- or equivilently there exists a orthogonal basis\n\n-- \u2193 Move\nlemma is_basis.trivial (hV : findim K V = 0) : is_basis K (\u03bb x : fin 0, (0 : V)) :=\nbegin\n  split,\n  rw linear_independent_iff', intros, exact fin.elim0 i,\n  rw \u2190 findim_top at hV,\n  rw [eq_top_iff, (@findim_eq_zero K V _ _ _ _ _).1 hV],\n  exact bot_le\nend\n\nlemma findim_ortho_span_singleton [hK : invertible (2 : K)] \n  {B : bilin_form K V} (hB\u2081 : B.nondegenerate) (hB\u2082 : sym_bilin_form.is_sym B) \n  {x : V} (hx : B x x \u2260 0) : findim K V = \n    findim K (B.ortho (submodule.span K ({x} : set V))) + 1 :=\nbegin\n  rw [\u2190 submodule.findim_quotient_add_findim (submodule.span K ({x} : set V)), \n      findim_span_singleton \n        (show x \u2260 0, by exact \u03bb hx', hx (hx'.symm \u25b8 zero_left _)), \n      (quotient_equiv_of_ortho_singleton hB\u2081 hB\u2082 hx).findim_eq]\nend\n\n/-- Given a nondegenerate symmetric basis `B` on some vector space `V` over the \n  field `K` with invertible `2`, there exists a orthogonal basis. -/\ntheorem exists_orthogonal_basis [hK : invertible (2 : K)] \n  {B : bilin_form K V} (hB\u2081 : B.nondegenerate) (hB\u2082 : sym_bilin_form.is_sym B) : \n  \u2203 v : fin (findim K V) \u2192 V, \n    B.is_ortho' v \u2227 is_basis K v \u2227 \u2200 i, B (v i) (v i) \u2260 0 :=\nbegin\n  tactic.unfreeze_local_instances,\n  induction hd : findim K V with d hi generalizing V,\n  { refine \u27e8\u03bb _, 0, \u03bb _ _ _, zero_left _, is_basis.trivial hd, fin.elim0\u27e9 },\n  { cases exists_bilin_form_self_neq_zero hB\u2081 hB\u2082 _ with x hx,\n    { have hd' := hd,\n      rw findim_ortho_span_singleton hB\u2081 hB\u2082 hx at hd,\n      rcases @hi (B.ortho (submodule.span K ({x} : set V))) _ _ _ \n        (B.restrict _) (B.restrict_ortho_singleton_nondegenerate hB\u2081 hB\u2082 hx)\n        (B.restrict_sym hB\u2082 _) (nat.succ.inj hd) with \u27e8v', hv\u2081, hv\u2082, hv\u2083\u27e9,\n      -- We now have a orthogonal basis on the orthogonal space \n      refine \u27e8\u03bb i, if h : i \u2260 0 then coe (v' (i.pred h)) else x, \u03bb i j hij, _, _, _\u27e9,\n      { by_cases hi : i = 0,\n        { subst i, \n          simp only [eq_self_iff_true, not_true, ne.def, dif_neg, \n            not_false_iff, dite_not], \n          rw dif_neg hij.symm,\n          exact (v' (j.pred hij.symm)).2 _ (submodule.mem_span_singleton_self x) },\n        by_cases hj : j = 0,\n        { subst j,\n          simp only [eq_self_iff_true, not_true, ne.def, dif_neg, \n            not_false_iff, dite_not], \n          rw [dif_neg hi, hB\u2082],\n          exact (v' (i.pred hi)).2 _ (submodule.mem_span_singleton_self x) },\n        { simp_rw [dif_pos hi, dif_pos hj],\n          { rw [hB\u2082, \u2190 hv\u2081 (j.pred hj) (i.pred hi) _], refl,\n            simpa using hij.symm } } }, \n      { refine is_basis_of_linear_independent_of_card_eq_findim \n          (B.is_ortho_linear_independent _ _)\n          (by rw [hd', fintype.card_fin]),\n        { intros i j hij,\n          by_cases hi : i = 0,\n          { subst hi,\n            simp only [eq_self_iff_true, not_true, ne.def, dif_neg, \n              not_false_iff, dite_not], \n            rw dif_neg hij.symm,\n            exact (v' (j.pred hij.symm)).2 _ (submodule.mem_span_singleton_self x) },\n          by_cases hj : j = 0,\n          { subst j,\n            simp only [eq_self_iff_true, not_true, ne.def, dif_neg, \n              not_false_iff, dite_not], \n            rw [dif_neg hi, hB\u2082],\n            exact (v' (i.pred hi)).2 _ (submodule.mem_span_singleton_self x) },\n          { simp_rw [dif_pos hi, dif_pos hj],\n            { rw [hB\u2082, \u2190 hv\u2081 (j.pred hj) (i.pred hi) _], refl,\n              simpa using hij.symm } } },\n        { intro i,\n          by_cases hi : i \u2260 0,\n          { rw dif_pos hi,\n            exact hv\u2083 (i.pred hi) },\n          { rw dif_neg hi, exact hx } } },\n      { intro i,\n          by_cases hi : i \u2260 0,\n          { rw dif_pos hi,\n            exact hv\u2083 (i.pred hi) },\n          { rw dif_neg hi, exact hx } } },\n    suffices : nontrivial V, \n    { rcases nontrivial_iff.1 this with \u27e8x, y, hxy\u27e9,\n      by_cases (x = 0),\n      { exact \u27e8y, h \u25b8 hxy.symm\u27e9 },\n      { exact \u27e8x, h\u27e9 } },\n    apply (@findim_pos_iff K _ _ _ _ _).1,\n    rw hd, exact nat.succ_pos _,\n    apply_instance }\nend .\n\nend finite_dimensional\n\nend bilin_form\n", "meta": {"author": "JasonKYi", "repo": "bilinear_sesquilinear_forms", "sha": "d54ff4537426e180473c8091375df2e3e528693d", "save_path": "github-repos/lean/JasonKYi-bilinear_sesquilinear_forms", "path": "github-repos/lean/JasonKYi-bilinear_sesquilinear_forms/bilinear_sesquilinear_forms-d54ff4537426e180473c8091375df2e3e528693d/src/main.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.713027758241451}}
{"text": "open classical\n\nvariables p q r s : Prop\n\ntheorem t1 : p \u2192 q \u2192 p :=\nbegin\n  intros hp hq,\n  exact hp\nend\n\ntheorem t2 (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q) : p \u2192 r :=\nbegin\n  intro hp,\n  apply h\u2081,\n  apply h\u2082,\n  exact hp\nend\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\nbegin\n  apply iff.intro,\n    intro h,\n    cases h with hp hq,\n    constructor, repeat { assumption },\n  intro h,\n  cases h with hq hp,\n  constructor, repeat { assumption }\nend\n\nexample : p \u2228 q \u2194 q \u2228 p :=\nbegin\n  apply iff.intro,\n    intro h,\n    cases h with hp hq,\n      right, exact hp,\n    left, exact hq,\n  intro h,\n  cases h with hq hp,\n    right, exact hq,\n  left, exact hp\nend\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\nbegin\n  apply iff.intro,\n  {\n    intro h,\n    cases h with hpq hr,\n    cases hpq with hp hq,\n    repeat { split; try { assumption } }\n  },\n  intro h,\n  cases h with hp hqr,\n  cases hqr with hq hr,\n  repeat { split; try { assumption } }\nend\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\nbegin\n  apply iff.intro,\n  {\n    intro h,\n    cases h with hpq hr,\n    {\n      cases hpq with hp hq,\n      { apply or.intro_left, assumption},\n      apply or.intro_right,\n      exact or.intro_left r hq\n    },\n    apply or.intro_right,\n    show q \u2228 r,\n      exact or.intro_right q hr\n  },\n  intro h,\n  cases h with hp hqr,\n  {\n    apply or.intro_left,\n    exact or.intro_left q hp\n  },\n  cases hqr with hq hr,\n  {\n    apply or.intro_left,\n    exact or.intro_right p hq\n  },\n  apply or.intro_right,\n  assumption\nend\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  apply iff.intro,\n    intro h,\n    cases h with hp hqr,\n    cases hqr with hq hr,\n      apply or.intro_left,\n      split,\n      repeat { assumption },\n    apply or.intro_right,\n    split,\n    repeat { assumption },\n  intro h,\n  cases h with hpq hpr,\n    split,\n      exact hpq.left,\n    exact or.intro_left r hpq.right,\n  split,\n    exact hpr.left,\n  exact or.intro_right q hpr.right\nend\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\nbegin\n  apply iff.intro,\n    intro h,\n    cases h with hp hqr,\n      { split; apply or.intro_left; assumption },\n    cases hqr with hq hr,\n    { split; apply or.intro_right; assumption },\n  intro h,\n  cases h with hpq hpr,\n  cases hpq with hp hq,\n    apply or.intro_left,\n    assumption,\n  cases hpr with hp hr,\n    apply or.intro_left,\n    assumption,\n  apply or.intro_right,\n  split; assumption\nend\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\nbegin\n  apply iff.intro,\n    intros h hpq,\n    exact h hpq.left hpq.right,\n  intros h hp hq,\n  exact h \u27e8hp, hq\u27e9\nend\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\nbegin\n  apply iff.intro,\n    intro h,\n    split,\n      intro,\n      exact h (or.intro_left q a),\n    intro,\n    exact h (or.intro_right p a),\n  intros h hpq,\n  cases h with hpr hqr,\n  cases hpq with hp hq,\n    exact hpr hp,\n  exact hqr hq\nend\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\nbegin\n  apply iff.intro,\n    intro h,\n    split,\n      intro,\n      exact absurd (or.intro_left q a) h,\n    intro,\n    exact absurd (or.intro_right p a) h,\n  intros h hpq,\n  cases hpq with hp hq,\n    exact h.left hp,\n  exact h.right hq\nend\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\nbegin\n  intros h hnpq,\n  cases h with hnp hnq,\n    exact hnp hnpq.left,\n  exact hnq hnpq.right\nend\nexample : \u00ac(p \u2227 \u00acp) :=\nbegin\n  intro h,\n  exact h.right h.left\nend\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\nbegin\n  intros h hpq,\n  exact h.right (hpq h.left)\nend\nexample : \u00acp \u2192 (p \u2192 q) :=\nbegin\n  intros,\n  contradiction\nend\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\nbegin\n  intros hpq hp,\n  cases hpq,\n    contradiction,\n  assumption\nend\nexample : p \u2228 false \u2194 p :=\nbegin\n  apply iff.intro,\n    intro,\n    cases a,\n      assumption,\n    contradiction,\n  intro,\n  left,\n  assumption\nend\nexample : p \u2227 false \u2194 false :=\nbegin\n  apply iff.intro,\n    intro,\n    exact a.right,\n  intro,\n  contradiction\nend\nexample : \u00ac(p \u2194 \u00acp) :=\nbegin\n  intro,\n  cases a,\n  have hnp: \u00ac p,\n    intros hp,\n    have : \u00ac p,\n      apply a_mp,\n      assumption,\n    contradiction,\n  have : p,\n    apply a_mpr,\n    assumption,\n  contradiction\nend\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\nbegin\n  intros hpq hnq hp,\n  have : q,\n    apply hpq,\n    assumption,\n  contradiction\nend\n\n-- these require classical reasoning\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\nbegin\n  intro h,\n  apply by_cases,\n    intro,\n    left,\n    assumption,\n  intro hnpr,\n  right,\n  intro hp,\n  cases h hp with hr hs,\n    have hpr : p \u2192 r,\n      intros,\n      assumption,\n    contradiction,\n  assumption\nend\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\nbegin\n  intro hnpq,\n  apply by_cases,\n    intro hp,\n    right,\n    intro hq,\n    have : p \u2227 q,\n      split; assumption,\n    contradiction,\n  intro hnp,\n  left,\n  assumption\nend\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nbegin\n  intro h,\n  split,\n    apply by_cases,\n      intro hp,\n      assumption,\n    intro hnp,\n    have : p \u2192 q,\n      intros,\n      contradiction,\n    contradiction,\n  apply not.intro,\n  intro hq,\n  have : p \u2192 q,\n    intros,\n    assumption,\n  contradiction\nend\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\nbegin\n  intro,\n  apply by_cases,\n    intro hp,\n    right,\n    exact a hp,\n  intro h,\n  left,\n  assumption\nend\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\nbegin\n  intros,\n  apply by_contradiction,\n  intro hnq,\n  have : \u00ac p,\n    apply a,\n    assumption,\n  contradiction\nend\nexample : p \u2228 \u00acp :=\nbegin\n  apply em\nend\nexample : p \u2228 \u00acp :=\nbegin\n  apply by_cases,\n    intro hp,\n    left,\n    assumption,\n  intro hnp,\n  right,\n  assumption\nend\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\nbegin\n  intros,\n  apply by_cases,\n    intro,\n    exact a a_1,\n  intro,\n  apply by_contradiction,\n  intro,\n  have h : p \u2192 q,\n    intros,\n    contradiction,\n  contradiction\nend\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/chap5_exercise3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7130277563430155}}
{"text": "variable(p q r : Prop)\n\nexample (h1 : P) : P := h1\n\nexample (h1 : P) (h2 : P \u2192 (P \u2192 Q)) : Q := ((h2 h1) h1)\n\n-- P, Q, (P \u2192 (Q \u2192 R)) \u22a2 R\n\nexample (h1 : p) (h2 : q) (h3 : p -> (q -> r)) : r := \n  (h3 h1) h2\n\nexample : p -> p :=\n  fun h1 => (h1 : p)\n\n-- Q \u22a2 (P \u2192 Q)\n\nexample (h1 : q) : p -> q :=\n  fun _ => h1\n\n-- (P \u2192 Q), (Q \u2192 R) \u22a2 (P \u2192 R)\n\nexample (h1 : p -> q) (h2 : q -> r) : p -> r := \n  fun h3 => h2 (h1 h3)\n\n-- The function goes on the left and the argument on the right\n\n-- P, (\u00acQ \u2192 \u00acP) \u22a2 Q\n\ndef DNI {p : Prop} : p -> \u00ac\u00acp :=\n  fun h1 : p => (fun h2 : \u00acp => h2 h1)\n\ndef MT {p : Prop} {q : Prop}: (((p -> q) \u2227 \u00acq) -> \u00acp) :=\n  fun h1 : ((p -> q) \u2227 \u00acq) => \n    (fun (h2 : p) => h1.right (h1.left h2))\n\nexample (h1 : p) (h2 : \u00acq -> \u00acp) : \u00ac\u00acq  :=\n  fun (h3 : \u00acq) => (h2 h3) h1\n\n\n\n-------------------------------------------------------------\n\naxiom DNE {p : Prop} : \u00ac\u00acp -> p \n\nexample (h1 : p) (h2 : \u00acq -> \u00acp) : q  :=\n  DNE (fun (h3 : \u00acq) => (h2 h3) h1)\n\n-- \u00acP, (\u00acQ \u2192 P) \u22a2 Q\nexample (h1 : \u00acp) (h2 : \u00acq -> p) : q :=\n  DNE $ MT $ And.intro h2 h1 ----------------------- Different syntax instead of ()\n\n\n-- (P \u2227 Q) \u22a2 (P \u2228 Q)\nexample (h1: p \u2227 q) : p \u2228 q :=\n  Or.inl $ h1.left\n\n-- \u00acP, \u00acQ \u22a2 \u00ac(P \u2228 Q)\nexample (h1 : \u00acp) (h2 : \u00acq) : \u00ac(p \u2228 q) :=\n  fun (h3 : p \u2228 q) => \n    have pthenr := fun (h4 : p) => h1 h4\n    have qthenr := fun (h5 : q) => h2 h5\n\n    (h3.elim pthenr) qthenr", "meta": {"author": "cmloura", "repo": "LeanPractice2023", "sha": "6819825e67228bfe5e69aa309f8d2bd37ef48ce3", "save_path": "github-repos/lean/cmloura-LeanPractice2023", "path": "github-repos/lean/cmloura-LeanPractice2023/LeanPractice2023-6819825e67228bfe5e69aa309f8d2bd37ef48ce3/test2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7130277560971975}}
{"text": "import .determinants\n\nuniverse u\n\ndef GL (n : \u2115) (R : Type u) [ring R] := units (matrix (fin n) (fin n) R)\n\nnamespace GL\n\nvariables {n : \u2115} {R : Type u} [comm_ring R]\n\ninstance : group (GL n R) := by unfold GL; apply_instance\n\ndef det : GL n R \u2192 units R := units.map matrix.det\n\ninstance : is_group_hom (det : GL n R \u2192 units R) := by unfold det; apply_instance\n\n@[simp] lemma det_one : det (1 : GL n R) = 1 := is_group_hom.one det\n\n@[simp] lemma det_mul (M : GL n R) (N : GL n R) : det (M * N) = det M * det N := is_group_hom.mul det M N\n\nend GL\n\ndef SL (n : \u2115) (R : Type u) [comm_ring R] := is_group_hom.ker (GL.det : GL n R \u2192 units R)\n", "meta": {"author": "semorrison", "repo": "kbb", "sha": "229bd06e840bc7a7438b8fee6802a4f8024419e3", "save_path": "github-repos/lean/semorrison-kbb", "path": "github-repos/lean/semorrison-kbb/kbb-229bd06e840bc7a7438b8fee6802a4f8024419e3/src/matrix_groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026641072387, "lm_q2_score": 0.7772998508568417, "lm_q1q2_score": 0.7130192240011403}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Scott Morrison, Simon Hudon\n\nDefinition and basic properties of endomorphisms and automorphisms of an object in a category.\n-/\nimport category_theory.groupoid\nimport data.equiv.mul_add\n\nuniverses v v' u u'\n\nnamespace category_theory\n\n/-- Endomorphisms of an object in a category. Arguments order in multiplication agrees with\n`function.comp`, not with `category.comp`. -/\ndef End {C : Type u} [category_struct.{v} C] (X : C) := X \u27f6 X\n\nnamespace End\n\nsection struct\n\nvariables {C : Type u} [category_struct.{v} C] (X : C)\n\ninstance has_one : has_one (End X) := \u27e8\ud835\udfd9 X\u27e9\ninstance inhabited : inhabited (End X) := \u27e8\ud835\udfd9 X\u27e9\n\n/-- Multiplication of endomorphisms agrees with `function.comp`, not `category_struct.comp`. -/\ninstance has_mul : has_mul (End X) := \u27e8\u03bb x y, y \u226b x\u27e9\n\nvariable {X}\n\n/-- Assist the typechecker by expressing a morphism `X \u27f6 X` as a term of `End X`. -/\ndef of (f : X \u27f6 X) : End X := f\n\n/-- Assist the typechecker by expressing an endomorphism `f : End X` as a term of `X \u27f6 X`. -/\ndef as_hom (f : End X) : X \u27f6 X := f\n\n@[simp] lemma one_def : (1 : End X) = \ud835\udfd9 X := rfl\n\n@[simp] lemma mul_def (xs ys : End X) : xs * ys = ys \u226b xs := rfl\n\nend struct\n\n/-- Endomorphisms of an object form a monoid -/\ninstance monoid {C : Type u} [category.{v} C] {X : C} : monoid (End X) :=\n{ mul_one := category.id_comp,\n  one_mul := category.comp_id,\n  mul_assoc := \u03bb x y z, (category.assoc z y x).symm,\n  ..End.has_mul X, ..End.has_one X }\n\n/-- In a groupoid, endomorphisms form a group -/\ninstance group {C : Type u} [groupoid.{v} C] (X : C) : group (End X) :=\n{ mul_left_inv := groupoid.comp_inv, inv := groupoid.inv, ..End.monoid }\n\nend End\n\nlemma is_unit_iff_is_iso {C : Type u} [category.{v} C] {X : C} (f : End X) :\n  is_unit (f : End X) \u2194 is_iso f :=\n\u27e8\u03bb h, { out := \u27e8h.unit.inv,\n  \u27e8by { convert h.unit.inv_val, exact h.unit_spec.symm, },\n    by { convert h.unit.val_inv, exact h.unit_spec.symm, }\u27e9\u27e9 },\n  \u03bb h, by exactI \u27e8\u27e8f, inv f, by simp, by simp\u27e9, rfl\u27e9\u27e9\n\nvariables {C : Type u} [category.{v} C] (X : C)\n\n/--\nAutomorphisms of an object in a category.\n\nThe order of arguments in multiplication agrees with\n`function.comp`, not with `category.comp`.\n-/\ndef Aut (X : C) := X \u2245 X\n\nattribute [ext Aut] iso.ext\n\nnamespace Aut\n\ninstance inhabited : inhabited (Aut X) := \u27e8iso.refl X\u27e9\n\ninstance : group (Aut X) :=\nby refine_struct\n{ one := iso.refl X,\n  inv := iso.symm,\n  mul := flip iso.trans,\n  div := _,\n  npow := @npow_rec (Aut X) \u27e8iso.refl X\u27e9 \u27e8flip iso.trans\u27e9,\n  gpow := @gpow_rec (Aut X) \u27e8iso.refl X\u27e9 \u27e8flip iso.trans\u27e9 \u27e8iso.symm\u27e9 };\nintros; try { refl }; ext;\nsimp [flip, (*), monoid.mul, mul_one_class.mul, mul_one_class.one, has_one.one, monoid.one,\n  has_inv.inv]\n\n/--\nUnits in the monoid of endomorphisms of an object\nare (multiplicatively) equivalent to automorphisms of that object.\n-/\ndef units_End_equiv_Aut : units (End X) \u2243* Aut X :=\n{ to_fun := \u03bb f, \u27e8f.1, f.2, f.4, f.3\u27e9,\n  inv_fun := \u03bb f, \u27e8f.1, f.2, f.4, f.3\u27e9,\n  left_inv := \u03bb \u27e8f\u2081, f\u2082, f\u2083, f\u2084\u27e9, rfl,\n  right_inv := \u03bb \u27e8f\u2081, f\u2082, f\u2083, f\u2084\u27e9, rfl,\n  map_mul' := \u03bb f g, by rcases f; rcases g; refl }\n\nend Aut\n\nnamespace functor\n\nvariables {D : Type u'} [category.{v'} D] (f : C \u2964 D) (X)\n\n/-- `f.map` as a monoid hom between endomorphism monoids. -/\n@[simps] def map_End : End X \u2192* End (f.obj X) :=\n{ to_fun := functor.map f,\n  map_mul' := \u03bb x y, f.map_comp y x,\n  map_one' := f.map_id X }\n\n/-- `f.map_iso` as a group hom between automorphism groups. -/\ndef map_Aut : Aut X \u2192* Aut (f.obj X) :=\n{ to_fun := f.map_iso,\n  map_mul' := \u03bb x y, f.map_iso_trans y x,\n  map_one' := f.map_iso_refl X }\n\nend functor\n\nend category_theory\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/category_theory/endomorphism.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7129956442826716}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Floris van Doorn\n-/\nimport algebra.big_operators.basic\nimport algebra.smul_with_zero\nimport data.set.finite\nimport group_theory.group_action.group\nimport group_theory.submonoid.basic\n\n/-!\n# Pointwise addition, multiplication, and scalar multiplication of sets.\n\nThis file defines pointwise algebraic operations on sets.\n* For a type `\u03b1` with multiplication, multiplication is defined on `set \u03b1` by taking\n  `s * t` to be the set of all `x * y` where `x \u2208 s` and `y \u2208 t`. Similarly for addition.\n* For `\u03b1` a semigroup, `set \u03b1` is a semigroup.\n* If `\u03b1` is a (commutative) monoid, we define an alias `set_semiring \u03b1` for `set \u03b1`, which then\n  becomes a (commutative) semiring with union as addition and pointwise multiplication as\n  multiplication.\n* For a type `\u03b2` with scalar multiplication by another type `\u03b1`, this\n  file defines a scalar multiplication of `set \u03b2` by `set \u03b1` and a separate scalar\n  multiplication of `set \u03b2` by `\u03b1`.\n* We also define pointwise multiplication on `finset`.\n\nAppropriate definitions and results are also transported to the additive theory via `to_additive`.\n\n## Implementation notes\n* The following expressions are considered in simp-normal form in a group:\n  `(\u03bb h, h * g) \u207b\u00b9' s`, `(\u03bb h, g * h) \u207b\u00b9' s`, `(\u03bb h, h * g\u207b\u00b9) \u207b\u00b9' s`, `(\u03bb h, g\u207b\u00b9 * h) \u207b\u00b9' s`,\n  `s * t`, `s\u207b\u00b9`, `(1 : set _)` (and similarly for additive variants).\n  Expressions equal to one of these will be simplified.\n* We put all instances in the locale `pointwise`, so that these instances are not available by\n  default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])\n  since we expect the locale to be open whenever the instances are actually used (and making the\n  instances reducible changes the behavior of `simp`).\n\n## Tags\n\nset multiplication, set addition, pointwise addition, pointwise multiplication\n\n-/\n\nnamespace set\nopen function\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {s s\u2081 s\u2082 t t\u2081 t\u2082 u : set \u03b1} {a b : \u03b1} {x y : \u03b2}\n\n/-! ### Properties about 1 -/\n\n/-- The set `(1 : set \u03b1)` is defined as `{1}` in locale `pointwise`. -/\n@[to_additive\n/-\"The set `(0 : set \u03b1)` is defined as `{0}` in locale `pointwise`. \"-/]\nprotected def has_one [has_one \u03b1] : has_one (set \u03b1) := \u27e8{1}\u27e9\n\nlocalized \"attribute [instance] set.has_one set.has_zero\" in pointwise\n\n@[to_additive]\nlemma singleton_one [has_one \u03b1] : ({1} : set \u03b1) = 1 := rfl\n\n@[simp, to_additive]\nlemma mem_one [has_one \u03b1] : a \u2208 (1 : set \u03b1) \u2194 a = 1 := iff.rfl\n\n@[to_additive]\nlemma one_mem_one [has_one \u03b1] : (1 : \u03b1) \u2208 (1 : set \u03b1) := eq.refl _\n\n@[simp, to_additive]\ntheorem one_subset [has_one \u03b1] : 1 \u2286 s \u2194 (1 : \u03b1) \u2208 s := singleton_subset_iff\n\n@[to_additive]\ntheorem one_nonempty [has_one \u03b1] : (1 : set \u03b1).nonempty := \u27e81, rfl\u27e9\n\n@[simp, to_additive]\ntheorem image_one [has_one \u03b1] {f : \u03b1 \u2192 \u03b2} : f '' 1 = {f 1} := image_singleton\n\n/-! ### Properties about multiplication -/\n\n/-- The set `(s * t : set \u03b1)` is defined as `{x * y | x \u2208 s, y \u2208 t}` in locale `pointwise`. -/\n@[to_additive\n/-\" The set `(s + t : set \u03b1)` is defined as `{x + y | x \u2208 s, y \u2208 t}` in locale `pointwise`.\"-/]\nprotected def has_mul [has_mul \u03b1] : has_mul (set \u03b1) := \u27e8image2 has_mul.mul\u27e9\n\nlocalized \"attribute [instance] set.has_mul set.has_add\" in pointwise\n\n@[simp, to_additive]\nlemma image2_mul [has_mul \u03b1] : image2 has_mul.mul s t = s * t := rfl\n\n@[to_additive]\nlemma mem_mul [has_mul \u03b1] : a \u2208 s * t \u2194 \u2203 x y, x \u2208 s \u2227 y \u2208 t \u2227 x * y = a := iff.rfl\n\n@[to_additive]\nlemma mul_mem_mul [has_mul \u03b1] (ha : a \u2208 s) (hb : b \u2208 t) : a * b \u2208 s * t := mem_image2_of_mem ha hb\n\n@[to_additive add_image_prod]\nlemma image_mul_prod [has_mul \u03b1] : (\u03bb x : \u03b1 \u00d7 \u03b1, x.fst * x.snd) '' s.prod t = s * t := image_prod _\n\n@[simp, to_additive]\nlemma image_mul_left [group \u03b1] : (\u03bb b, a * b) '' t = (\u03bb b, a\u207b\u00b9 * b) \u207b\u00b9' t :=\nby { rw image_eq_preimage_of_inverse; intro c; simp }\n\n@[simp, to_additive]\nlemma image_mul_right [group \u03b1] : (\u03bb a, a * b) '' t = (\u03bb a, a * b\u207b\u00b9) \u207b\u00b9' t :=\nby { rw image_eq_preimage_of_inverse; intro c; simp }\n\n@[to_additive]\nlemma image_mul_left' [group \u03b1] : (\u03bb b, a\u207b\u00b9 * b) '' t = (\u03bb b, a * b) \u207b\u00b9' t := by simp\n\n@[to_additive]\nlemma image_mul_right' [group \u03b1] : (\u03bb a, a * b\u207b\u00b9) '' t = (\u03bb a, a * b) \u207b\u00b9' t := by simp\n\n@[simp, to_additive]\nlemma preimage_mul_left_singleton [group \u03b1] : ((*) a) \u207b\u00b9' {b} = {a\u207b\u00b9 * b} :=\nby rw [\u2190 image_mul_left', image_singleton]\n\n@[simp, to_additive]\nlemma preimage_mul_right_singleton [group \u03b1] : (* a) \u207b\u00b9' {b} = {b * a\u207b\u00b9} :=\nby rw [\u2190 image_mul_right', image_singleton]\n\n@[simp, to_additive]\nlemma preimage_mul_left_one [group \u03b1] : (\u03bb b, a * b) \u207b\u00b9' 1 = {a\u207b\u00b9} :=\nby rw [\u2190 image_mul_left', image_one, mul_one]\n\n@[simp, to_additive]\nlemma preimage_mul_right_one [group \u03b1] : (\u03bb a, a * b) \u207b\u00b9' 1 = {b\u207b\u00b9} :=\nby rw [\u2190 image_mul_right', image_one, one_mul]\n\n@[to_additive]\nlemma preimage_mul_left_one' [group \u03b1] : (\u03bb b, a\u207b\u00b9 * b) \u207b\u00b9' 1 = {a} := by simp\n\n@[to_additive]\nlemma preimage_mul_right_one' [group \u03b1] : (\u03bb a, a * b\u207b\u00b9) \u207b\u00b9' 1 = {b} := by simp\n\n@[simp, to_additive]\nlemma mul_singleton [has_mul \u03b1] : s * {b} = (\u03bb a, a * b) '' s := image2_singleton_right\n\n@[simp, to_additive]\nlemma singleton_mul [has_mul \u03b1] : {a} * t = (\u03bb b, a * b) '' t := image2_singleton_left\n\n@[simp, to_additive]\nlemma singleton_mul_singleton [has_mul \u03b1] : ({a} : set \u03b1) * {b} = {a * b} := image2_singleton\n\n@[to_additive]\nprotected lemma mul_comm [comm_semigroup \u03b1] : s * t = t * s :=\nby simp only [\u2190 image2_mul, image2_swap _ s, mul_comm]\n\n/-- `set \u03b1` is a `mul_one_class` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_zero_class` under pointwise operations if `\u03b1` is.\"-/]\nprotected def mul_one_class [mul_one_class \u03b1] : mul_one_class (set \u03b1) :=\n{ mul_one := \u03bb s, by { simp only [\u2190 singleton_one, mul_singleton, mul_one, image_id'] },\n  one_mul := \u03bb s, by { simp only [\u2190 singleton_one, singleton_mul, one_mul, image_id'] },\n  ..set.has_one, ..set.has_mul }\n\n/-- `set \u03b1` is a `semigroup` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_semigroup` under pointwise operations if `\u03b1` is. \"-/]\nprotected def semigroup [semigroup \u03b1] : semigroup (set \u03b1) :=\n{ mul_assoc := \u03bb _ _ _, image2_assoc mul_assoc,\n  ..set.has_mul }\n\n/-- `set \u03b1` is a `monoid` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_monoid` under pointwise operations if `\u03b1` is. \"-/]\nprotected def monoid [monoid \u03b1] : monoid (set \u03b1) :=\n{ ..set.semigroup,\n  ..set.mul_one_class }\n\n/-- `set \u03b1` is a `comm_monoid` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_comm_monoid` under pointwise operations if `\u03b1` is. \"-/]\nprotected def comm_monoid [comm_monoid \u03b1] : comm_monoid (set \u03b1) :=\n{ mul_comm := \u03bb _ _, set.mul_comm, ..set.monoid }\n\nlocalized \"attribute [instance] set.mul_one_class set.add_zero_class set.semigroup set.add_semigroup\n  set.monoid set.add_monoid set.comm_monoid set.add_comm_monoid\" in pointwise\n\nlemma pow_mem_pow [monoid \u03b1] (ha : a \u2208 s) (n : \u2115) :\n  a ^ n \u2208 s ^ n :=\nbegin\n  induction n with n ih,\n  { rw pow_zero,\n    exact set.mem_singleton 1 },\n  { rw pow_succ,\n    exact set.mul_mem_mul ha ih },\nend\n\n/-- Under `[has_mul M]`, the `singleton` map from `M` to `set M` as a `mul_hom`, that is, a map\nwhich preserves multiplication. -/\n@[to_additive \"Under `[has_add A]`, the `singleton` map from `A` to `set A` as an `add_hom`,\nthat is, a map which preserves addition.\", simps]\ndef singleton_mul_hom [has_mul \u03b1] : mul_hom \u03b1 (set \u03b1) :=\n{ to_fun := singleton,\n  map_mul' := \u03bb a b, singleton_mul_singleton.symm }\n\n@[simp, to_additive]\nlemma empty_mul [has_mul \u03b1] : \u2205 * s = \u2205 := image2_empty_left\n\n@[simp, to_additive]\nlemma mul_empty [has_mul \u03b1] : s * \u2205 = \u2205 := image2_empty_right\n\nlemma empty_pow [monoid \u03b1] (n : \u2115) (hn : n \u2260 0) : (\u2205 : set \u03b1) ^ n = \u2205 :=\nby rw [\u2190 tsub_add_cancel_of_le (nat.succ_le_of_lt $ nat.pos_of_ne_zero hn), pow_succ, empty_mul]\n\ninstance decidable_mem_mul [monoid \u03b1] [fintype \u03b1] [decidable_eq \u03b1]\n  [decidable_pred (\u2208 s)] [decidable_pred (\u2208 t)] :\n  decidable_pred (\u2208 s * t) :=\n\u03bb _, decidable_of_iff _ mem_mul.symm\n\ninstance decidable_mem_pow [monoid \u03b1] [fintype \u03b1] [decidable_eq \u03b1]\n  [decidable_pred (\u2208 s)] (n : \u2115) :\n  decidable_pred (\u2208 (s ^ n)) :=\nbegin\n  induction n with n ih,\n  { simp_rw [pow_zero, mem_one], apply_instance },\n  { letI := ih, rw pow_succ, apply_instance }\nend\n\n@[to_additive]\nlemma mul_subset_mul [has_mul \u03b1] (h\u2081 : s\u2081 \u2286 t\u2081) (h\u2082 : s\u2082 \u2286 t\u2082) : s\u2081 * s\u2082 \u2286 t\u2081 * t\u2082 :=\nimage2_subset h\u2081 h\u2082\n\nlemma pow_subset_pow [monoid \u03b1] (hst : s \u2286 t) (n : \u2115) :\n  s ^ n \u2286 t ^ n :=\nbegin\n  induction n with n ih,\n  { rw pow_zero,\n    exact subset.rfl },\n  { rw [pow_succ, pow_succ],\n    exact mul_subset_mul hst ih },\nend\n\n@[to_additive]\nlemma union_mul [has_mul \u03b1] : (s \u222a t) * u = (s * u) \u222a (t * u) := image2_union_left\n\n@[to_additive]\nlemma mul_union [has_mul \u03b1] : s * (t \u222a u) = (s * t) \u222a (s * u) := image2_union_right\n\n@[to_additive]\nlemma Union_mul_left_image [has_mul \u03b1] : (\u22c3 a \u2208 s, (\u03bb x, a * x) '' t) = s * t :=\nUnion_image_left _\n\n@[to_additive]\nlemma Union_mul_right_image [has_mul \u03b1] : (\u22c3 a \u2208 t, (\u03bb x, x * a) '' s) = s * t :=\nUnion_image_right _\n\n@[to_additive]\nlemma Union_mul {\u03b9 : Sort*} [has_mul \u03b1] (s : \u03b9 \u2192 set \u03b1) (t : set \u03b1) :\n  (\u22c3 i, s i) * t = \u22c3 i, (s i * t) :=\nimage2_Union_left _ _ _\n\n@[to_additive]\nlemma mul_Union {\u03b9 : Sort*} [has_mul \u03b1] (t : set \u03b1) (s : \u03b9 \u2192 set \u03b1) :\n  t * (\u22c3 i, s i) = \u22c3 i, (t * s i) :=\nimage2_Union_right _ _ _\n\n@[simp, to_additive]\nlemma univ_mul_univ [monoid \u03b1] : (univ : set \u03b1) * univ = univ :=\nbegin\n  have : \u2200x, \u2203a b : \u03b1, a * b = x := \u03bbx, \u27e8x, \u27e81, mul_one x\u27e9\u27e9,\n  simpa only [mem_mul, eq_univ_iff_forall, mem_univ, true_and]\nend\n\n/-- `singleton` is a monoid hom. -/\n@[to_additive singleton_add_hom \"singleton is an add monoid hom\"]\ndef singleton_hom [monoid \u03b1] : \u03b1 \u2192* set \u03b1 :=\n{ to_fun := singleton, map_one' := rfl, map_mul' := \u03bb a b, singleton_mul_singleton.symm }\n\n@[to_additive]\nlemma nonempty.mul [has_mul \u03b1] : s.nonempty \u2192 t.nonempty \u2192 (s * t).nonempty := nonempty.image2\n\n@[to_additive]\nlemma finite.mul [has_mul \u03b1] (hs : finite s) (ht : finite t) : finite (s * t) :=\nhs.image2 _ ht\n\n/-- multiplication preserves finiteness -/\n@[to_additive \"addition preserves finiteness\"]\ndef fintype_mul [has_mul \u03b1] [decidable_eq \u03b1] (s t : set \u03b1) [hs : fintype s] [ht : fintype t] :\n  fintype (s * t : set \u03b1) :=\nset.fintype_image2 _ s t\n\n@[to_additive]\nlemma bdd_above_mul [ordered_comm_monoid \u03b1] {A B : set \u03b1} :\n  bdd_above A \u2192 bdd_above B \u2192 bdd_above (A * B) :=\nbegin\n  rintros \u27e8bA, hbA\u27e9 \u27e8bB, hbB\u27e9,\n  use bA * bB,\n  rintros x \u27e8xa, xb, hxa, hxb, rfl\u27e9,\n  exact mul_le_mul' (hbA hxa) (hbB hxb),\nend\n\nsection big_operators\nopen_locale big_operators\n\nvariables {\u03b9 : Type*} [comm_monoid \u03b1]\n\n/-- The n-ary version of `set.mem_mul`. -/\n@[to_additive /-\" The n-ary version of `set.mem_add`. \"-/]\nlemma mem_finset_prod (t : finset \u03b9) (f : \u03b9 \u2192 set \u03b1) (a : \u03b1) :\n  a \u2208 \u220f i in t, f i \u2194 \u2203 (g : \u03b9 \u2192 \u03b1) (hg : \u2200 {i}, i \u2208 t \u2192 g i \u2208 f i), \u220f i in t, g i = a :=\nbegin\n  classical,\n  induction t using finset.induction_on with i is hi ih generalizing a,\n  { simp_rw [finset.prod_empty, set.mem_one],\n    exact \u27e8\u03bb h, \u27e8\u03bb i, a, \u03bb i, false.elim, h.symm\u27e9, \u03bb \u27e8f, _, hf\u27e9, hf.symm\u27e9 },\n  rw [finset.prod_insert hi, set.mem_mul],\n  simp_rw [finset.prod_insert hi],\n  simp_rw ih,\n  split,\n  { rintros \u27e8x, y, hx, \u27e8g, hg, rfl\u27e9, rfl\u27e9,\n    refine \u27e8function.update g i x, \u03bb j hj, _, _\u27e9,\n    obtain rfl | hj := finset.mem_insert.mp hj,\n    { rw function.update_same, exact hx },\n    { rw update_noteq (ne_of_mem_of_not_mem hj hi), exact hg hj, },\n    rw [finset.prod_update_of_not_mem hi, function.update_same], },\n  { rintros \u27e8g, hg, rfl\u27e9,\n    exact \u27e8g i, is.prod g, hg (is.mem_insert_self _),\n      \u27e8g, \u03bb i hi, hg (finset.mem_insert_of_mem hi), rfl\u27e9, rfl\u27e9 },\nend\n\n/-- A version of `set.mem_finset_prod` with a simpler RHS for products over a fintype. -/\n@[to_additive /-\" A version of `set.mem_finset_sum` with a simpler RHS for sums over a fintype. \"-/]\nlemma mem_fintype_prod [fintype \u03b9] (f : \u03b9 \u2192 set \u03b1) (a : \u03b1) :\n  a \u2208 \u220f i, f i \u2194 \u2203 (g : \u03b9 \u2192 \u03b1) (hg : \u2200 i, g i \u2208 f i), \u220f i, g i = a :=\nby { rw mem_finset_prod, simp }\n\n/-- The n-ary version of `set.mul_mem_mul`. -/\n@[to_additive /-\" The n-ary version of `set.add_mem_add`. \"-/]\nlemma finset_prod_mem_finset_prod (t : finset \u03b9) (f : \u03b9 \u2192 set \u03b1)\n  (g : \u03b9 \u2192 \u03b1) (hg : \u2200 i \u2208 t, g i \u2208 f i) :\n  \u220f i in t, g i \u2208 \u220f i in t, f i :=\nby { rw mem_finset_prod, exact \u27e8g, hg, rfl\u27e9 }\n\n/-- The n-ary version of `set.mul_subset_mul`. -/\n@[to_additive /-\" The n-ary version of `set.add_subset_add`. \"-/]\nlemma finset_prod_subset_finset_prod (t : finset \u03b9) (f\u2081 f\u2082 : \u03b9 \u2192 set \u03b1)\n  (hf : \u2200 {i}, i \u2208 t \u2192 f\u2081 i \u2286 f\u2082 i) :\n  \u220f i in t, f\u2081 i \u2286 \u220f i in t, f\u2082 i :=\nbegin\n  intro a,\n  rw [mem_finset_prod, mem_finset_prod],\n  rintro \u27e8g, hg, rfl\u27e9,\n  exact \u27e8g, \u03bb i hi, hf hi $ hg hi, rfl\u27e9\nend\n\n@[to_additive]\nlemma finset_prod_singleton {M \u03b9 : Type*} [comm_monoid M] (s : finset \u03b9) (I : \u03b9 \u2192 M) :\n  \u220f (i : \u03b9) in s, ({I i} : set M) = {\u220f (i : \u03b9) in s, I i} :=\nbegin\n  letI := classical.dec_eq \u03b9,\n  refine finset.induction_on s _ _,\n  { simpa },\n  { intros _ _ H ih,\n    rw [finset.prod_insert H, finset.prod_insert H, ih],\n    simp }\nend\n\n/-! TODO: define `decidable_mem_finset_prod` and `decidable_mem_finset_sum`. -/\n\nend big_operators\n\n/-! ### Properties about inversion -/\n\n/-- The set `(s\u207b\u00b9 : set \u03b1)` is defined as `{x | x\u207b\u00b9 \u2208 s}` in locale `pointwise`.\nIt is equal to `{x\u207b\u00b9 | x \u2208 s}`, see `set.image_inv`. -/\n@[to_additive\n/-\" The set `(-s : set \u03b1)` is defined as `{x | -x \u2208 s}` in locale `pointwise`.\nIt is equal to `{-x | x \u2208 s}`, see `set.image_neg`. \"-/]\nprotected def has_inv [has_inv \u03b1] : has_inv (set \u03b1) :=\n\u27e8preimage has_inv.inv\u27e9\n\nlocalized \"attribute [instance] set.has_inv set.has_neg\" in pointwise\n\n@[simp, to_additive]\nlemma inv_empty [has_inv \u03b1] : (\u2205 : set \u03b1)\u207b\u00b9 = \u2205 := rfl\n\n@[simp, to_additive]\nlemma inv_univ [has_inv \u03b1] : (univ : set \u03b1)\u207b\u00b9 = univ := rfl\n\n@[simp, to_additive]\nlemma nonempty_inv [group \u03b1] {s : set \u03b1} : s\u207b\u00b9.nonempty \u2194 s.nonempty :=\ninv_involutive.surjective.nonempty_preimage\n\n@[to_additive] lemma nonempty.inv [group \u03b1] {s : set \u03b1} (h : s.nonempty) : s\u207b\u00b9.nonempty :=\nnonempty_inv.2 h\n\n@[simp, to_additive]\nlemma mem_inv [has_inv \u03b1] : a \u2208 s\u207b\u00b9 \u2194 a\u207b\u00b9 \u2208 s := iff.rfl\n\n@[to_additive]\nlemma inv_mem_inv [group \u03b1] : a\u207b\u00b9 \u2208 s\u207b\u00b9 \u2194 a \u2208 s :=\nby simp only [mem_inv, inv_inv]\n\n@[simp, to_additive]\nlemma inv_preimage [has_inv \u03b1] : has_inv.inv \u207b\u00b9' s = s\u207b\u00b9 := rfl\n\n@[simp, to_additive]\nlemma image_inv [group \u03b1] : has_inv.inv '' s = s\u207b\u00b9 :=\nby { simp only [\u2190 inv_preimage], rw [image_eq_preimage_of_inverse]; intro; simp only [inv_inv] }\n\n@[simp, to_additive]\nlemma inter_inv [has_inv \u03b1] : (s \u2229 t)\u207b\u00b9 = s\u207b\u00b9 \u2229 t\u207b\u00b9 := preimage_inter\n\n@[simp, to_additive]\nlemma union_inv [has_inv \u03b1] : (s \u222a t)\u207b\u00b9 = s\u207b\u00b9 \u222a t\u207b\u00b9 := preimage_union\n\n@[simp, to_additive]\nlemma Inter_inv {\u03b9 : Sort*} [has_inv \u03b1] (s : \u03b9 \u2192 set \u03b1) : (\u22c2 i, s i)\u207b\u00b9 = \u22c2 i, (s i)\u207b\u00b9 :=\npreimage_Inter\n\n@[simp, to_additive]\nlemma Union_inv {\u03b9 : Sort*} [has_inv \u03b1] (s : \u03b9 \u2192 set \u03b1) : (\u22c3 i, s i)\u207b\u00b9 = \u22c3 i, (s i)\u207b\u00b9 :=\npreimage_Union\n\n@[simp, to_additive]\nlemma compl_inv [has_inv \u03b1] : (s\u1d9c)\u207b\u00b9 = (s\u207b\u00b9)\u1d9c := preimage_compl\n\n@[simp, to_additive]\nprotected lemma inv_inv [group \u03b1] : s\u207b\u00b9\u207b\u00b9 = s :=\nby { simp only [\u2190 inv_preimage, preimage_preimage, inv_inv, preimage_id'] }\n\n@[simp, to_additive]\nprotected lemma univ_inv [group \u03b1] : (univ : set \u03b1)\u207b\u00b9 = univ := preimage_univ\n\n@[simp, to_additive]\nlemma inv_subset_inv [group \u03b1] {s t : set \u03b1} : s\u207b\u00b9 \u2286 t\u207b\u00b9 \u2194 s \u2286 t :=\n(equiv.inv \u03b1).surjective.preimage_subset_preimage_iff\n\n@[to_additive] lemma inv_subset [group \u03b1] {s t : set \u03b1} : s\u207b\u00b9 \u2286 t \u2194 s \u2286 t\u207b\u00b9 :=\nby { rw [\u2190 inv_subset_inv, set.inv_inv] }\n\n@[to_additive] lemma finite.inv [group \u03b1] {s : set \u03b1} (hs : finite s) : finite s\u207b\u00b9 :=\nhs.preimage $ inv_injective.inj_on _\n\n@[to_additive] lemma inv_singleton {\u03b2 : Type*} [group \u03b2] (x : \u03b2) : ({x} : set \u03b2)\u207b\u00b9 = {x\u207b\u00b9} :=\nby { ext1 y, rw [mem_inv, mem_singleton_iff, mem_singleton_iff, inv_eq_iff_inv_eq, eq_comm], }\n\n@[to_additive] protected lemma mul_inv_rev [group \u03b1] (s t : set \u03b1) : (s * t)\u207b\u00b9 = t\u207b\u00b9 * s\u207b\u00b9 :=\nby simp_rw [\u2190image_inv, \u2190image2_mul, image_image2, image2_image_left, image2_image_right,\n              mul_inv_rev, image2_swap _ s t]\n\n/-! ### Properties about scalar multiplication -/\n\n/-- The scaling of a set `(x \u2022 s : set \u03b2)` by a scalar `x \u2236 \u03b1` is defined as `{x \u2022 y | y \u2208 s}`\nin locale `pointwise`. -/\n@[to_additive has_vadd_set \"The translation of a set `(x +\u1d65 s : set \u03b2)` by a scalar `x \u2236 \u03b1` is\ndefined as `{x +\u1d65 y | y \u2208 s}` in locale `pointwise`.\"]\nprotected def has_scalar_set [has_scalar \u03b1 \u03b2] : has_scalar \u03b1 (set \u03b2) :=\n\u27e8\u03bb a, image (has_scalar.smul a)\u27e9\n\n/-- The pointwise scalar multiplication `(s \u2022 t : set \u03b2)` by a set of scalars `s \u2236 set \u03b1`\nis defined as `{x \u2022 y | x \u2208 s, y \u2208 t}` in locale `pointwise`. -/\n@[to_additive has_vadd \"The pointwise translation `(s +\u1d65 t : set \u03b2)` by a set of constants\n`s \u2236 set \u03b1` is defined as `{x +\u1d65 y | x \u2208 s, y \u2208 t}` in locale `pointwise`.\"]\nprotected def has_scalar [has_scalar \u03b1 \u03b2] : has_scalar (set \u03b1) (set \u03b2) :=\n\u27e8image2 has_scalar.smul\u27e9\n\nlocalized \"attribute [instance] set.has_scalar_set set.has_scalar\" in pointwise\nlocalized \"attribute [instance] set.has_vadd_set set.has_vadd\" in pointwise\n\n@[simp, to_additive]\nlemma image_smul [has_scalar \u03b1 \u03b2] {t : set \u03b2} : (\u03bb x, a \u2022 x) '' t = a \u2022 t := rfl\n\n@[to_additive]\nlemma mem_smul_set [has_scalar \u03b1 \u03b2] {t : set \u03b2} : x \u2208 a \u2022 t \u2194 \u2203 y, y \u2208 t \u2227 a \u2022 y = x := iff.rfl\n\n@[to_additive]\nlemma smul_mem_smul_set [has_scalar \u03b1 \u03b2] {t : set \u03b2} (hy : y \u2208 t) : a \u2022 y \u2208 a \u2022 t :=\n\u27e8y, hy, rfl\u27e9\n\n@[to_additive]\nlemma smul_set_union [has_scalar \u03b1 \u03b2] {s t : set \u03b2} : a \u2022 (s \u222a t) = a \u2022 s \u222a a \u2022 t :=\nby simp only [\u2190 image_smul, image_union]\n\n@[to_additive]\nlemma smul_set_inter [group \u03b1] [mul_action \u03b1 \u03b2] {s t : set \u03b2} :\n  a \u2022 (s \u2229 t) = a \u2022 s \u2229 a \u2022 t :=\n(image_inter $ mul_action.injective a).symm\n\nlemma smul_set_inter\u2080 [group_with_zero \u03b1] [mul_action \u03b1 \u03b2] {s t : set \u03b2} (ha : a \u2260 0) :\n  a \u2022 (s \u2229 t) = a \u2022 s \u2229 a \u2022 t :=\nshow units.mk0 a ha \u2022 _ = _, from smul_set_inter\n\n@[to_additive]\nlemma smul_set_inter_subset [has_scalar \u03b1 \u03b2] {s t : set \u03b2} :\n  a \u2022 (s \u2229 t) \u2286 a \u2022 s \u2229 a \u2022 t := image_inter_subset _ _ _\n\n@[simp, to_additive]\nlemma smul_set_empty [has_scalar \u03b1 \u03b2] (a : \u03b1) : a \u2022 (\u2205 : set \u03b2) = \u2205 :=\nby rw [\u2190 image_smul, image_empty]\n\n@[to_additive]\nlemma smul_set_mono [has_scalar \u03b1 \u03b2] {s t : set \u03b2} (h : s \u2286 t) : a \u2022 s \u2286 a \u2022 t :=\nby { simp only [\u2190 image_smul, image_subset, h] }\n\n@[simp, to_additive]\nlemma image2_smul [has_scalar \u03b1 \u03b2] {t : set \u03b2} : image2 has_scalar.smul s t = s \u2022 t := rfl\n\n@[to_additive]\nlemma mem_smul [has_scalar \u03b1 \u03b2] {t : set \u03b2} : x \u2208 s \u2022 t \u2194 \u2203 a y, a \u2208 s \u2227 y \u2208 t \u2227 a \u2022 y = x :=\niff.rfl\n\nlemma mem_smul_of_mem [has_scalar \u03b1 \u03b2] {t : set \u03b2} {a} {b} (ha : a \u2208 s) (hb : b \u2208 t) :\n  a \u2022 b \u2208 s \u2022 t :=\n\u27e8a, b, ha, hb, rfl\u27e9\n\n@[to_additive]\nlemma image_smul_prod [has_scalar \u03b1 \u03b2] {t : set \u03b2} :\n  (\u03bb x : \u03b1 \u00d7 \u03b2, x.fst \u2022 x.snd) '' s.prod t = s \u2022 t :=\nimage_prod _\n\n@[to_additive]\ntheorem range_smul_range [has_scalar \u03b1 \u03b2] {\u03b9 \u03ba : Type*} (b : \u03b9 \u2192 \u03b1) (c : \u03ba \u2192 \u03b2) :\n  range b \u2022 range c = range (\u03bb p : \u03b9 \u00d7 \u03ba, b p.1 \u2022 c p.2) :=\next $ \u03bb x, \u27e8\u03bb hx, let \u27e8p, q, \u27e8i, hi\u27e9, \u27e8j, hj\u27e9, hpq\u27e9 := set.mem_smul.1 hx in\n  \u27e8(i, j), hpq \u25b8 hi \u25b8 hj \u25b8 rfl\u27e9,\n\u03bb \u27e8\u27e8i, j\u27e9, h\u27e9, set.mem_smul.2 \u27e8b i, c j, \u27e8i, rfl\u27e9, \u27e8j, rfl\u27e9, h\u27e9\u27e9\n\n@[simp, to_additive]\nlemma smul_singleton [has_scalar \u03b1 \u03b2] (a : \u03b1) (b : \u03b2) : a \u2022 ({b} : set \u03b2) = {a \u2022 b} :=\nimage_singleton\n\n@[simp, to_additive]\nlemma singleton_smul [has_scalar \u03b1 \u03b2] {t : set \u03b2} : ({a} : set \u03b1) \u2022 t = a \u2022 t :=\nimage2_singleton_left\n\n@[to_additive]\ninstance smul_comm_class_set {\u03b3 : Type*}\n  [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [smul_comm_class \u03b1 \u03b2 \u03b3] :\n  smul_comm_class \u03b1 (set \u03b2) (set \u03b3) :=\n{ smul_comm := \u03bb a T T',\n    by simp only [\u2190image2_smul, \u2190image_smul, image2_image_right, image_image2, smul_comm] }\n\n@[to_additive]\ninstance smul_comm_class_set' {\u03b3 : Type*}\n  [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [smul_comm_class \u03b1 \u03b2 \u03b3] :\n  smul_comm_class (set \u03b1) \u03b2 (set \u03b3) :=\nby haveI := smul_comm_class.symm \u03b1 \u03b2 \u03b3; exact smul_comm_class.symm _ _ _\n\n@[to_additive]\ninstance smul_comm_class {\u03b3 : Type*}\n  [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [smul_comm_class \u03b1 \u03b2 \u03b3] :\n  smul_comm_class (set \u03b1) (set \u03b2) (set \u03b3) :=\n{ smul_comm := \u03bb T T' T'', begin\n    simp only [\u2190image2_smul, image2_swap _ T],\n    exact image2_assoc (\u03bb b c a, smul_comm a b c),\n  end }\n\ninstance is_scalar_tower {\u03b3 : Type*}\n  [has_scalar \u03b1 \u03b2] [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [is_scalar_tower \u03b1 \u03b2 \u03b3] :\n  is_scalar_tower \u03b1 \u03b2 (set \u03b3) :=\n{ smul_assoc := \u03bb a b T, by simp only [\u2190image_smul, image_image, smul_assoc] }\n\ninstance is_scalar_tower' {\u03b3 : Type*}\n  [has_scalar \u03b1 \u03b2] [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [is_scalar_tower \u03b1 \u03b2 \u03b3] :\n  is_scalar_tower \u03b1 (set \u03b2) (set \u03b3) :=\n{ smul_assoc := \u03bb a T T',\n    by simp only [\u2190image_smul, \u2190image2_smul, image_image2, image2_image_left, smul_assoc] }\n\ninstance is_scalar_tower'' {\u03b3 : Type*}\n  [has_scalar \u03b1 \u03b2] [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [is_scalar_tower \u03b1 \u03b2 \u03b3] :\n  is_scalar_tower (set \u03b1) (set \u03b2) (set \u03b3) :=\n{ smul_assoc := \u03bb T T' T'', image2_assoc smul_assoc }\n\nsection monoid\n\n/-! ### `set \u03b1` as a `(\u222a,*)`-semiring -/\n\n/-- An alias for `set \u03b1`, which has a semiring structure given by `\u222a` as \"addition\" and pointwise\n  multiplication `*` as \"multiplication\". -/\n@[derive inhabited] def set_semiring (\u03b1 : Type*) : Type* := set \u03b1\n\n/-- The identitiy function `set \u03b1 \u2192 set_semiring \u03b1`. -/\nprotected def up (s : set \u03b1) : set_semiring \u03b1 := s\n/-- The identitiy function `set_semiring \u03b1 \u2192 set \u03b1`. -/\nprotected def set_semiring.down (s : set_semiring \u03b1) : set \u03b1 := s\n@[simp] protected lemma down_up {s : set \u03b1} : s.up.down = s := rfl\n@[simp] protected lemma up_down {s : set_semiring \u03b1} : s.down.up = s := rfl\n\ninstance set_semiring.add_comm_monoid : add_comm_monoid (set_semiring \u03b1) :=\n{ add := \u03bb s t, (s \u222a t : set \u03b1),\n  zero := (\u2205 : set \u03b1),\n  add_assoc := union_assoc,\n  zero_add := empty_union,\n  add_zero := union_empty,\n  add_comm := union_comm, }\n\ninstance set_semiring.non_unital_non_assoc_semiring [has_mul \u03b1] :\n  non_unital_non_assoc_semiring (set_semiring \u03b1) :=\n{ zero_mul := \u03bb s, empty_mul,\n  mul_zero := \u03bb s, mul_empty,\n  left_distrib := \u03bb _ _ _, mul_union,\n  right_distrib := \u03bb _ _ _, union_mul,\n  ..set.has_mul, ..set_semiring.add_comm_monoid }\n\ninstance set_semiring.non_assoc_semiring [mul_one_class \u03b1] : non_assoc_semiring (set_semiring \u03b1) :=\n{ ..set_semiring.non_unital_non_assoc_semiring, ..set.mul_one_class }\n\ninstance set_semiring.non_unital_semiring [semigroup \u03b1] : non_unital_semiring (set_semiring \u03b1) :=\n{ ..set_semiring.non_unital_non_assoc_semiring, ..set.semigroup }\n\ninstance set_semiring.semiring [monoid \u03b1] : semiring (set_semiring \u03b1) :=\n{ ..set_semiring.non_assoc_semiring, ..set_semiring.non_unital_semiring }\n\ninstance set_semiring.comm_semiring [comm_monoid \u03b1] : comm_semiring (set_semiring \u03b1) :=\n{ ..set.comm_monoid, ..set_semiring.semiring }\n\n/-- A multiplicative action of a monoid on a type \u03b2 gives also a\n multiplicative action on the subsets of \u03b2. -/\n@[to_additive \"An additive action of an additive monoid on a type \u03b2 gives also an additive action\non the subsets of \u03b2.\"]\nprotected def mul_action_set [monoid \u03b1] [mul_action \u03b1 \u03b2] : mul_action \u03b1 (set \u03b2) :=\n{ mul_smul := by { intros, simp only [\u2190 image_smul, image_image, \u2190 mul_smul] },\n  one_smul := by { intros, simp only [\u2190 image_smul, image_eta, one_smul, image_id'] },\n  ..set.has_scalar_set }\n\nlocalized \"attribute [instance] set.mul_action_set set.add_action_set\" in pointwise\n\nsection mul_hom\n\nvariables [has_mul \u03b1] [has_mul \u03b2] (m : mul_hom \u03b1 \u03b2)\n\n@[to_additive]\nlemma image_mul : m '' (s * t) = m '' s * m '' t :=\nby { simp only [\u2190 image2_mul, image_image2, image2_image_left, image2_image_right, m.map_mul] }\n\n@[to_additive]\nlemma preimage_mul_preimage_subset {s t : set \u03b2} : m \u207b\u00b9' s * m \u207b\u00b9' t \u2286 m \u207b\u00b9' (s * t) :=\nby { rintros _ \u27e8_, _, _, _, rfl\u27e9, exact \u27e8_, _, \u2039_\u203a, \u2039_\u203a, (m.map_mul _ _).symm \u27e9 }\n\nend mul_hom\n\n/-- The image of a set under function is a ring homomorphism\nwith respect to the pointwise operations on sets. -/\ndef image_hom [monoid \u03b1] [monoid \u03b2] (f : \u03b1 \u2192* \u03b2) : set_semiring \u03b1 \u2192+* set_semiring \u03b2 :=\n{ to_fun := image f,\n  map_zero' := image_empty _,\n  map_one' := by simp only [\u2190 singleton_one, image_singleton, f.map_one],\n  map_add' := image_union _,\n  map_mul' := \u03bb _ _, image_mul f.to_mul_hom }\n\nend monoid\n\nend set\n\nopen set\nopen_locale pointwise\n\nsection\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n\n/-- A nonempty set is scaled by zero to the singleton set containing 0. -/\nlemma zero_smul_set [has_zero \u03b1] [has_zero \u03b2] [smul_with_zero \u03b1 \u03b2] {s : set \u03b2} (h : s.nonempty) :\n  (0 : \u03b1) \u2022 s = (0 : set \u03b2) :=\nby simp only [\u2190 image_smul, image_eta, zero_smul, h.image_const, singleton_zero]\n\nlemma zero_smul_subset [has_zero \u03b1] [has_zero \u03b2] [smul_with_zero \u03b1 \u03b2] (s : set \u03b2) :\n  (0 : \u03b1) \u2022 s \u2286 0 :=\nimage_subset_iff.2 $ \u03bb x _, zero_smul \u03b1 x\n\nlemma subsingleton_zero_smul_set [has_zero \u03b1] [has_zero \u03b2] [smul_with_zero \u03b1 \u03b2] (s : set \u03b2) :\n  ((0 : \u03b1) \u2022 s).subsingleton :=\nsubsingleton_singleton.mono (zero_smul_subset s)\n\nsection group\nvariables [group \u03b1] [mul_action \u03b1 \u03b2]\n\n@[simp, to_additive]\nlemma smul_mem_smul_set_iff {a : \u03b1} {A : set \u03b2} {x : \u03b2} : a \u2022 x \u2208 a \u2022 A \u2194 x \u2208 A :=\n\u27e8\u03bb h, begin\n  rw [\u2190inv_smul_smul a x, \u2190inv_smul_smul a A],\n  exact smul_mem_smul_set h,\nend, smul_mem_smul_set\u27e9\n\n@[to_additive]\nlemma mem_smul_set_iff_inv_smul_mem {a : \u03b1} {A : set \u03b2} {x : \u03b2} : x \u2208 a \u2022 A \u2194 a\u207b\u00b9 \u2022 x \u2208 A :=\nshow x \u2208 mul_action.to_perm a '' A \u2194 _, from mem_image_equiv\n\n@[to_additive]\nlemma mem_inv_smul_set_iff {a : \u03b1} {A : set \u03b2} {x : \u03b2} : x \u2208 a\u207b\u00b9 \u2022 A \u2194 a \u2022 x \u2208 A :=\nby simp only [\u2190 image_smul, mem_image, inv_smul_eq_iff, exists_eq_right]\n\n@[to_additive]\nlemma preimage_smul (a : \u03b1) (t : set \u03b2) : (\u03bb x, a \u2022 x) \u207b\u00b9' t = a\u207b\u00b9 \u2022 t :=\n((mul_action.to_perm a).symm.image_eq_preimage _).symm\n\n@[to_additive]\nlemma preimage_smul_inv (a : \u03b1) (t : set \u03b2) : (\u03bb x, a\u207b\u00b9 \u2022 x) \u207b\u00b9' t = a \u2022 t :=\npreimage_smul (to_units a)\u207b\u00b9 t\n\n@[simp, to_additive]\nlemma set_smul_subset_set_smul_iff {a : \u03b1} {A B : set \u03b2} : a \u2022 A \u2286 a \u2022 B \u2194 A \u2286 B :=\nimage_subset_image_iff $ mul_action.injective _\n\n@[to_additive]\nlemma set_smul_subset_iff {a : \u03b1} {A B : set \u03b2} : a \u2022 A \u2286 B \u2194 A \u2286 a\u207b\u00b9 \u2022 B :=\n(image_subset_iff).trans $ iff_of_eq $ congr_arg _ $\n  preimage_equiv_eq_image_symm _ $ mul_action.to_perm _\n\n@[to_additive]\nlemma subset_set_smul_iff {a : \u03b1} {A B : set \u03b2} : A \u2286 a \u2022 B \u2194 a\u207b\u00b9 \u2022 A \u2286 B :=\niff.symm $ (image_subset_iff).trans $ iff.symm $ iff_of_eq $ congr_arg _ $\n  image_equiv_eq_preimage_symm _ $ mul_action.to_perm _\n\nend group\n\nsection group_with_zero\nvariables [group_with_zero \u03b1] [mul_action \u03b1 \u03b2]\n\n@[simp] lemma smul_mem_smul_set_iff\u2080 {a : \u03b1} (ha : a \u2260 0) (A : set \u03b2)\n  (x : \u03b2) : a \u2022 x \u2208 a \u2022 A \u2194 x \u2208 A :=\nshow units.mk0 a ha \u2022 _ \u2208 _ \u2194 _, from smul_mem_smul_set_iff\n\nlemma mem_smul_set_iff_inv_smul_mem\u2080 {a : \u03b1} (ha : a \u2260 0) (A : set \u03b2) (x : \u03b2) :\n  x \u2208 a \u2022 A \u2194 a\u207b\u00b9 \u2022 x \u2208 A :=\nshow _ \u2208 units.mk0 a ha \u2022 _ \u2194 _, from mem_smul_set_iff_inv_smul_mem\n\nlemma mem_inv_smul_set_iff\u2080 {a : \u03b1} (ha : a \u2260 0) (A : set \u03b2) (x : \u03b2) : x \u2208 a\u207b\u00b9 \u2022 A \u2194 a \u2022 x \u2208 A :=\nshow _ \u2208 (units.mk0 a ha)\u207b\u00b9 \u2022 _ \u2194 _, from mem_inv_smul_set_iff\n\nlemma preimage_smul\u2080 {a : \u03b1} (ha : a \u2260 0) (t : set \u03b2) : (\u03bb x, a \u2022 x) \u207b\u00b9' t = a\u207b\u00b9 \u2022 t :=\npreimage_smul (units.mk0 a ha) t\n\nlemma preimage_smul_inv\u2080 {a : \u03b1} (ha : a \u2260 0) (t : set \u03b2) :\n  (\u03bb x, a\u207b\u00b9 \u2022 x) \u207b\u00b9' t = a \u2022 t :=\npreimage_smul ((units.mk0 a ha)\u207b\u00b9) t\n\n@[simp] lemma set_smul_subset_set_smul_iff\u2080 {a : \u03b1} (ha : a \u2260 0) {A B : set \u03b2} :\n  a \u2022 A \u2286 a \u2022 B \u2194 A \u2286 B :=\nshow units.mk0 a ha \u2022 _ \u2286 _ \u2194 _, from set_smul_subset_set_smul_iff\n\nlemma set_smul_subset_iff\u2080 {a : \u03b1} (ha : a \u2260 0) {A B : set \u03b2} : a \u2022 A \u2286 B \u2194 A \u2286 a\u207b\u00b9 \u2022 B :=\nshow units.mk0 a ha \u2022 _ \u2286 _ \u2194 _, from set_smul_subset_iff\n\nlemma subset_set_smul_iff\u2080 {a : \u03b1} (ha : a \u2260 0) {A B : set \u03b2} : A \u2286 a \u2022 B \u2194 a\u207b\u00b9 \u2022 A \u2286 B :=\nshow _ \u2286 units.mk0 a ha \u2022 _ \u2194 _, from subset_set_smul_iff\n\nend group_with_zero\n\nend\n\nnamespace finset\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] {s t : finset \u03b1}\n\n/-- The pointwise product of two finite sets `s` and `t`:\n`st = s \u2b1d t = s * t = { x * y | x \u2208 s, y \u2208 t }`. -/\n@[to_additive /-\"The pointwise sum of two finite sets `s` and `t`:\n`s + t = { x + y | x \u2208 s, y \u2208 t }`. \"-/]\nprotected def has_mul [has_mul \u03b1] : has_mul (finset \u03b1) :=\n\u27e8\u03bb s t, (s.product t).image (\u03bb p : \u03b1 \u00d7 \u03b1, p.1 * p.2)\u27e9\n\nlocalized \"attribute [instance] finset.has_mul finset.has_add\" in pointwise\n\n@[to_additive]\nlemma mul_def [has_mul \u03b1] :\n  s * t = (s.product t).image (\u03bb p : \u03b1 \u00d7 \u03b1, p.1 * p.2) := rfl\n\n@[to_additive]\nlemma mem_mul [has_mul \u03b1] {x : \u03b1} :\n  x \u2208 s * t \u2194 \u2203 y z, y \u2208 s \u2227 z \u2208 t \u2227 y * z = x :=\nby { simp only [finset.mul_def, and.assoc, mem_image, exists_prop, prod.exists, mem_product] }\n\n@[simp, norm_cast, to_additive]\nlemma coe_mul [has_mul \u03b1] : (\u2191(s * t) : set \u03b1) = \u2191s * \u2191t :=\nby { ext, simp only [mem_mul, set.mem_mul, mem_coe] }\n\n@[to_additive]\nlemma mul_mem_mul [has_mul \u03b1] {x y : \u03b1} (hx : x \u2208 s) (hy : y \u2208 t) :\n  x * y \u2208 s * t :=\nby { simp only [finset.mem_mul], exact \u27e8x, y, hx, hy, rfl\u27e9 }\n\n@[to_additive]\nlemma mul_card_le [has_mul \u03b1] : (s * t).card \u2264 s.card * t.card :=\nby { convert finset.card_image_le, rw [finset.card_product, mul_comm] }\n\n@[simp, to_additive] lemma empty_mul [has_mul \u03b1] (s : finset \u03b1) : \u2205 * s = \u2205 :=\neq_empty_of_forall_not_mem (by simp [mem_mul])\n\n@[simp, to_additive] lemma mul_empty [has_mul \u03b1] (s : finset \u03b1) : s * \u2205 = \u2205 :=\neq_empty_of_forall_not_mem (by simp [mem_mul])\n\n@[simp, to_additive] lemma mul_nonempty_iff [has_mul \u03b1] (s t : finset \u03b1):\n    (s * t).nonempty \u2194 s.nonempty \u2227 t.nonempty :=\nby simp [finset.mul_def]\n\n@[to_additive, mono] lemma mul_subset_mul [has_mul \u03b1] {s\u2081 s\u2082 t\u2081 t\u2082 : finset \u03b1}\n  (hs : s\u2081 \u2286 s\u2082) (ht : t\u2081 \u2286 t\u2082) : s\u2081 * t\u2081 \u2286 s\u2082 * t\u2082 :=\nimage_subset_image (product_subset_product hs ht)\n\nlemma mul_singleton_zero [mul_zero_class \u03b1] (s : finset \u03b1) :\n  s * {0} \u2286 {0} :=\nby simp [subset_iff, mem_mul]\n\nlemma singleton_zero_mul [mul_zero_class \u03b1] (s : finset \u03b1):\n  {(0 : \u03b1)} * s \u2286 {0} :=\nby simp [subset_iff, mem_mul]\n\nopen_locale classical\n\n/-- A finite set `U` contained in the product of two sets `S * S'` is also contained in the product\nof two finite sets `T * T' \u2286 S * S'`. -/\n@[to_additive]\nlemma subset_mul {M : Type*} [monoid M] {S : set M} {S' : set M} {U : finset M} (f : \u2191U \u2286 S * S') :\n  \u2203 (T T' : finset M), \u2191T \u2286 S \u2227 \u2191T' \u2286 S' \u2227 U \u2286 T * T' :=\nbegin\n  apply finset.induction_on' U,\n  { use [\u2205, \u2205], simp only [finset.empty_subset, finset.coe_empty, set.empty_subset, and_self], },\n  rintros a s haU hs has \u27e8T, T', hS, hS', h\u27e9,\n  obtain \u27e8x, y, hx, hy, ha\u27e9 := set.mem_mul.1 (f haU),\n  use [insert x T, insert y T'],\n  simp only [finset.coe_insert],\n  repeat { rw [set.insert_subset], },\n  use [hx, hS, hy, hS'],\n  refine finset.insert_subset.mpr \u27e8_, _\u27e9,\n  { rw finset.mem_mul,\n    use [x,y],\n    simpa only [true_and, true_or, eq_self_iff_true, finset.mem_insert], },\n  { suffices g : (s : set M) \u2286 insert x T * insert y T', { norm_cast at g, assumption, },\n    transitivity \u2191(T * T'),\n    apply h,\n    rw finset.coe_mul,\n    apply set.mul_subset_mul (set.subset_insert x T) (set.subset_insert y T'), },\nend\n\nend finset\n\n/-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in\n  `group_theory.submonoid.basic`, but currently we cannot because that file is imported by this. -/\nnamespace submonoid\n\nvariables {M : Type*} [monoid M]\n\n@[to_additive]\nlemma mul_subset {s t : set M} {S : submonoid M} (hs : s \u2286 S) (ht : t \u2286 S) : s * t \u2286 S :=\nby { rintro _ \u27e8p, q, hp, hq, rfl\u27e9, exact submonoid.mul_mem _ (hs hp) (ht hq) }\n\n@[to_additive]\nlemma mul_subset_closure {s t u : set M} (hs : s \u2286 u) (ht : t \u2286 u) :\n  s * t \u2286 submonoid.closure u :=\nmul_subset (subset.trans hs submonoid.subset_closure) (subset.trans ht submonoid.subset_closure)\n\n@[to_additive]\nlemma coe_mul_self_eq (s : submonoid M) : (s : set M) * s = s :=\nbegin\n  ext x,\n  refine \u27e8_, \u03bb h, \u27e8x, 1, h, s.one_mem, mul_one x\u27e9\u27e9,\n  rintros \u27e8a, b, ha, hb, rfl\u27e9,\n  exact s.mul_mem ha hb\nend\n\n@[to_additive]\nlemma closure_mul_le (S T : set M) : closure (S * T) \u2264 closure S \u2294 closure T :=\nInf_le $ \u03bb x \u27e8s, t, hs, ht, hx\u27e9, hx \u25b8 (closure S \u2294 closure T).mul_mem\n    (set_like.le_def.mp le_sup_left $ subset_closure hs)\n    (set_like.le_def.mp le_sup_right $ subset_closure ht)\n\n@[to_additive]\nlemma sup_eq_closure (H K : submonoid M) : H \u2294 K = closure (H * K) :=\nle_antisymm\n  (sup_le\n    (\u03bb h hh, subset_closure \u27e8h, 1, hh, K.one_mem, mul_one h\u27e9)\n    (\u03bb k hk, subset_closure \u27e81, k, H.one_mem, hk, one_mul k\u27e9))\n  (by conv_rhs { rw [\u2190 closure_eq H, \u2190 closure_eq K] }; apply closure_mul_le)\n\nend submonoid\n\nnamespace group\n\nlemma card_pow_eq_card_pow_card_univ_aux {f : \u2115 \u2192 \u2115} (h1 : monotone f)\n  {B : \u2115} (h2 : \u2200 n, f n \u2264 B) (h3 : \u2200 n, f n = f (n + 1) \u2192 f (n + 1) = f (n + 2)) :\n  \u2200 k, B \u2264 k \u2192 f k = f B :=\nbegin\n  have key : \u2203 n : \u2115, n \u2264 B \u2227 f n = f (n + 1),\n  { contrapose! h2,\n    suffices : \u2200 n : \u2115, n \u2264 B + 1 \u2192 n \u2264 f n,\n    { exact \u27e8B + 1, this (B + 1) (le_refl (B + 1))\u27e9 },\n    exact \u03bb n, nat.rec (\u03bb h, nat.zero_le (f 0)) (\u03bb n ih h, lt_of_le_of_lt (ih (n.le_succ.trans h))\n      (lt_of_le_of_ne (h1 n.le_succ) (h2 n (nat.succ_le_succ_iff.mp h)))) n },\n  { obtain \u27e8n, hn1, hn2\u27e9 := key,\n    replace key : \u2200 k : \u2115, f (n + k) = f (n + k + 1) \u2227 f (n + k) = f n :=\n    \u03bb k, nat.rec \u27e8hn2, rfl\u27e9 (\u03bb k ih, \u27e8h3 _ ih.1, ih.1.symm.trans ih.2\u27e9) k,\n    replace key : \u2200 k : \u2115, n \u2264 k \u2192 f k = f n :=\n    \u03bb k hk, (congr_arg f (add_tsub_cancel_of_le hk)).symm.trans (key (k - n)).2,\n    exact \u03bb k hk, (key k (hn1.trans hk)).trans (key B hn1).symm },\nend\n\nvariables {G : Type*} [group G] [fintype G] (S : set G)\n\nlemma card_pow_eq_card_pow_card_univ [\u2200 (k : \u2115), decidable_pred (\u2208 (S ^ k))] :\n  \u2200 k, fintype.card G \u2264 k \u2192 fintype.card \u21a5(S ^ k) = fintype.card \u21a5(S ^ (fintype.card G)) :=\nbegin\n  have hG : 0 < fintype.card G := fintype.card_pos_iff.mpr \u27e81\u27e9,\n  by_cases hS : S = \u2205,\n  { intros k hk,\n    congr' 2,\n    rw [hS, empty_pow _ (ne_of_gt (lt_of_lt_of_le hG hk)), empty_pow _ (ne_of_gt hG)] },\n  obtain \u27e8a, ha\u27e9 := set.ne_empty_iff_nonempty.mp hS,\n  classical,\n  have key : \u2200 a (s t : set G), (\u2200 b : G, b \u2208 s \u2192 a * b \u2208 t) \u2192 fintype.card s \u2264 fintype.card t,\n  { refine \u03bb a s t h, fintype.card_le_of_injective (\u03bb \u27e8b, hb\u27e9, \u27e8a * b, h b hb\u27e9) _,\n    rintros \u27e8b, hb\u27e9 \u27e8c, hc\u27e9 hbc,\n    exact subtype.ext (mul_left_cancel (subtype.ext_iff.mp hbc)) },\n  have mono : monotone (\u03bb n, fintype.card \u21a5(S ^ n) : \u2115 \u2192 \u2115) :=\n  monotone_nat_of_le_succ (\u03bb n, key a _ _ (\u03bb b hb, set.mul_mem_mul ha hb)),\n  convert card_pow_eq_card_pow_card_univ_aux mono (\u03bb n, set_fintype_card_le_univ (S ^ n))\n    (\u03bb n h, le_antisymm (mono (n + 1).le_succ) (key a\u207b\u00b9 _ _ _)),\n  { simp only [finset.filter_congr_decidable, fintype.card_of_finset] },\n  replace h : {a} * S ^ n = S ^ (n + 1),\n  { refine set.eq_of_subset_of_card_le _ (le_trans (ge_of_eq h) _),\n    { exact mul_subset_mul (set.singleton_subset_iff.mpr ha) set.subset.rfl },\n    { convert key a (S ^ n) ({a} * S ^ n) (\u03bb b hb, set.mul_mem_mul (set.mem_singleton a) hb) } },\n  rw [pow_succ', \u2190h, mul_assoc, \u2190pow_succ', h],\n  rintros _ \u27e8b, c, hb, hc, rfl\u27e9,\n  rwa [set.mem_singleton_iff.mp hb, inv_mul_cancel_left],\nend\n\nend group\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7129956398316659}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Fr\u00e9d\u00e9ric Dupuis\n-/\nimport analysis.convex.hull\nimport analysis.inner_product_space.basic\n\n/-!\n# Convex cones\n\nIn a `\ud835\udd5c`-module `E`, we define a convex cone as a set `s` such that `a \u2022 x + b \u2022 y \u2208 s` whenever\n`x, y \u2208 s` and `a, b > 0`. We prove that convex cones form a `complete_lattice`, and define their\nimages (`convex_cone.map`) and preimages (`convex_cone.comap`) under linear maps.\n\nWe define pointed, blunt, flat and salient cones, and prove the correspondence between\nconvex cones and ordered modules.\n\nWe also define `convex.to_cone` to be the minimal cone that includes a given convex set.\n\nWe define `set.inner_dual_cone` to be the cone consisting of all points `y` such that for\nall points `x` in a given set `0 \u2264 \u27ea x, y \u27eb`.\n\n## Main statements\n\nWe prove two extension theorems:\n* `riesz_extension`:\n  [M. Riesz extension theorem](https://en.wikipedia.org/wiki/M._Riesz_extension_theorem) says that\n  if `s` is a convex cone in a real vector space `E`, `p` is a submodule of `E`\n  such that `p + s = E`, and `f` is a linear function `p \u2192 \u211d` which is\n  nonnegative on `p \u2229 s`, then there exists a globally defined linear function\n  `g : E \u2192 \u211d` that agrees with `f` on `p`, and is nonnegative on `s`.\n* `exists_extension_of_le_sublinear`:\n  Hahn-Banach theorem: if `N : E \u2192 \u211d` is a sublinear map, `f` is a linear map\n  defined on a subspace of `E`, and `f x \u2264 N x` for all `x` in the domain of `f`,\n  then `f` can be extended to the whole space to a linear map `g` such that `g x \u2264 N x`\n  for all `x`\n\n## Implementation notes\n\nWhile `convex \ud835\udd5c` is a predicate on sets, `convex_cone \ud835\udd5c E` is a bundled convex cone.\n\n## References\n\n* https://en.wikipedia.org/wiki/Convex_cone\n-/\n\n\nopen set linear_map\nopen_locale classical pointwise\n\nvariables {\ud835\udd5c E F G : Type*}\n\n/-! ### Definition of `convex_cone` and basic properties -/\n\nsection definitions\nvariables (\ud835\udd5c E) [ordered_semiring \ud835\udd5c]\n\n/-- A convex cone is a subset `s` of a `\ud835\udd5c`-module such that `a \u2022 x + b \u2022 y \u2208 s` whenever `a, b > 0`\nand `x, y \u2208 s`. -/\nstructure convex_cone [add_comm_monoid E] [has_scalar \ud835\udd5c E] :=\n(carrier : set E)\n(smul_mem' : \u2200 \u2983c : \ud835\udd5c\u2984, 0 < c \u2192 \u2200 \u2983x : E\u2984, x \u2208 carrier \u2192 c \u2022 x \u2208 carrier)\n(add_mem' : \u2200 \u2983x\u2984 (hx : x \u2208 carrier) \u2983y\u2984 (hy : y \u2208 carrier), x + y \u2208 carrier)\n\nend definitions\n\nvariables {\ud835\udd5c E}\n\nnamespace convex_cone\nsection ordered_semiring\nvariables [ordered_semiring \ud835\udd5c] [add_comm_monoid E]\n\nsection has_scalar\nvariables [has_scalar \ud835\udd5c E] (S T : convex_cone \ud835\udd5c E)\n\ninstance : has_coe (convex_cone \ud835\udd5c E) (set E) := \u27e8convex_cone.carrier\u27e9\n\ninstance : has_mem E (convex_cone \ud835\udd5c E) := \u27e8\u03bb m S, m \u2208 S.carrier\u27e9\n\ninstance : has_le (convex_cone \ud835\udd5c E) := \u27e8\u03bb S T, S.carrier \u2286 T.carrier\u27e9\n\ninstance : has_lt (convex_cone \ud835\udd5c E) := \u27e8\u03bb S T, S.carrier \u2282 T.carrier\u27e9\n\n@[simp, norm_cast] lemma mem_coe {x : E} : x \u2208 (S : set E) \u2194 x \u2208 S := iff.rfl\n\n@[simp] lemma mem_mk {s : set E} {h\u2081 h\u2082 x} : x \u2208 @mk \ud835\udd5c _ _ _ _ s h\u2081 h\u2082 \u2194 x \u2208 s := iff.rfl\n\n/-- Two `convex_cone`s are equal if the underlying sets are equal. -/\ntheorem ext' {S T : convex_cone \ud835\udd5c E} (h : (S : set E) = T) : S = T :=\nby cases S; cases T; congr'\n\n/-- Two `convex_cone`s are equal if and only if the underlying sets are equal. -/\nprotected theorem ext'_iff {S T : convex_cone \ud835\udd5c E}  : (S : set E) = T \u2194 S = T :=\n\u27e8ext', \u03bb h, h \u25b8 rfl\u27e9\n\n/-- Two `convex_cone`s are equal if they have the same elements. -/\n@[ext] theorem ext {S T : convex_cone \ud835\udd5c E} (h : \u2200 x, x \u2208 S \u2194 x \u2208 T) : S = T := ext' $ set.ext h\n\nlemma smul_mem {c : \ud835\udd5c} {x : E} (hc : 0 < c) (hx : x \u2208 S) : c \u2022 x \u2208 S := S.smul_mem' hc hx\n\nlemma add_mem \u2983x\u2984 (hx : x \u2208 S) \u2983y\u2984 (hy : y \u2208 S) : x + y \u2208 S := S.add_mem' hx hy\n\ninstance : has_inf (convex_cone \ud835\udd5c E) :=\n\u27e8\u03bb S T, \u27e8S \u2229 T, \u03bb c hc x hx, \u27e8S.smul_mem hc hx.1, T.smul_mem hc hx.2\u27e9,\n  \u03bb x hx y hy, \u27e8S.add_mem hx.1 hy.1, T.add_mem hx.2 hy.2\u27e9\u27e9\u27e9\n\nlemma coe_inf : ((S \u2293 T : convex_cone \ud835\udd5c E) : set E) = \u2191S \u2229 \u2191T := rfl\n\nlemma mem_inf {x} : x \u2208 S \u2293 T \u2194 x \u2208 S \u2227 x \u2208 T := iff.rfl\n\ninstance : has_Inf (convex_cone \ud835\udd5c E) :=\n\u27e8\u03bb S, \u27e8\u22c2 s \u2208 S, \u2191s,\n  \u03bb c hc x hx, mem_bInter $ \u03bb s hs, s.smul_mem hc $ by apply mem_bInter_iff.1 hx s hs,\n  \u03bb x hx y hy, mem_bInter $ \u03bb s hs, s.add_mem (by apply mem_bInter_iff.1 hx s hs)\n    (by apply mem_bInter_iff.1 hy s hs)\u27e9\u27e9\n\nlemma mem_Inf {x : E} {S : set (convex_cone \ud835\udd5c E)} : x \u2208 Inf S \u2194 \u2200 s \u2208 S, x \u2208 s := mem_bInter_iff\n\nvariables (\ud835\udd5c)\n\ninstance : has_bot (convex_cone \ud835\udd5c E) := \u27e8\u27e8\u2205, \u03bb c hc x, false.elim, \u03bb x, false.elim\u27e9\u27e9\n\nlemma mem_bot (x : E) : x \u2208 (\u22a5 : convex_cone \ud835\udd5c E) = false := rfl\n\ninstance : has_top (convex_cone \ud835\udd5c E) := \u27e8\u27e8univ, \u03bb c hc x hx, mem_univ _, \u03bb x hx y hy, mem_univ _\u27e9\u27e9\n\nlemma mem_top (x : E) : x \u2208 (\u22a4 : convex_cone \ud835\udd5c E) := mem_univ x\n\ninstance : complete_lattice (convex_cone \ud835\udd5c E) :=\n{ le           := (\u2264),\n  lt           := (<),\n  bot          := (\u22a5),\n  bot_le       := \u03bb S x, false.elim,\n  top          := (\u22a4),\n  le_top       := \u03bb S x hx, mem_top \ud835\udd5c x,\n  inf          := (\u2293),\n  Inf          := has_Inf.Inf,\n  sup          := \u03bb a b, Inf {x | a \u2264 x \u2227 b \u2264 x},\n  Sup          := \u03bb s, Inf {T | \u2200 S \u2208 s, S \u2264 T},\n  le_sup_left  := \u03bb a b, \u03bb x hx, mem_Inf.2 $ \u03bb s hs, hs.1 hx,\n  le_sup_right := \u03bb a b, \u03bb x hx, mem_Inf.2 $ \u03bb s hs, hs.2 hx,\n  sup_le       := \u03bb a b c ha hb x hx, mem_Inf.1 hx c \u27e8ha, hb\u27e9,\n  le_inf       := \u03bb a b c ha hb x hx, \u27e8ha hx, hb hx\u27e9,\n  inf_le_left  := \u03bb a b x, and.left,\n  inf_le_right := \u03bb a b x, and.right,\n  le_Sup       := \u03bb s p hs x hx, mem_Inf.2 $ \u03bb t ht, ht p hs hx,\n  Sup_le       := \u03bb s p hs x hx, mem_Inf.1 hx p hs,\n  le_Inf       := \u03bb s a ha x hx, mem_Inf.2 $ \u03bb t ht, ha t ht hx,\n  Inf_le       := \u03bb s a ha x hx, mem_Inf.1 hx _ ha,\n  .. partial_order.lift (coe : convex_cone \ud835\udd5c E \u2192 set E) (\u03bb a b, ext') }\n\ninstance : inhabited (convex_cone \ud835\udd5c E) := \u27e8\u22a5\u27e9\n\nend has_scalar\n\nsection module\nvariables [module \ud835\udd5c E] (S : convex_cone \ud835\udd5c E)\n\nprotected lemma convex : convex \ud835\udd5c (S : set E) :=\nconvex_iff_forall_pos.2 $ \u03bb x y hx hy a b ha hb hab,\n  S.add_mem (S.smul_mem ha hx) (S.smul_mem hb hy)\n\nend module\nend ordered_semiring\n\nsection linear_ordered_field\nvariables [linear_ordered_field \ud835\udd5c]\n\nsection add_comm_monoid\nvariables [add_comm_monoid E] [add_comm_monoid F] [add_comm_monoid G]\n\nsection mul_action\nvariables [mul_action \ud835\udd5c E] (S : convex_cone \ud835\udd5c E)\n\nlemma smul_mem_iff {c : \ud835\udd5c} (hc : 0 < c) {x : E} :\n  c \u2022 x \u2208 S \u2194 x \u2208 S :=\n\u27e8\u03bb h, inv_smul_smul\u2080 hc.ne' x \u25b8 S.smul_mem (inv_pos.2 hc) h, S.smul_mem hc\u27e9\n\nend mul_action\n\nsection module\nvariables [module \ud835\udd5c E] [module \ud835\udd5c F] [module \ud835\udd5c G]\n\n/-- The image of a convex cone under a `\ud835\udd5c`-linear map is a convex cone. -/\ndef map (f : E \u2192\u2097[\ud835\udd5c] F) (S : convex_cone \ud835\udd5c E) : convex_cone \ud835\udd5c F :=\n{ carrier := f '' S,\n  smul_mem' := \u03bb c hc y \u27e8x, hx, hy\u27e9, hy \u25b8 f.map_smul c x \u25b8 mem_image_of_mem f (S.smul_mem hc hx),\n  add_mem' := \u03bb y\u2081 \u27e8x\u2081, hx\u2081, hy\u2081\u27e9 y\u2082 \u27e8x\u2082, hx\u2082, hy\u2082\u27e9, hy\u2081 \u25b8 hy\u2082 \u25b8 f.map_add x\u2081 x\u2082 \u25b8\n    mem_image_of_mem f (S.add_mem hx\u2081 hx\u2082) }\n\nlemma map_map (g : F \u2192\u2097[\ud835\udd5c] G) (f : E \u2192\u2097[\ud835\udd5c] F) (S : convex_cone \ud835\udd5c E) :\n  (S.map f).map g = S.map (g.comp f) :=\next' $ image_image g f S\n\n@[simp] lemma map_id (S : convex_cone \ud835\udd5c E) : S.map linear_map.id = S := ext' $ image_id _\n\n/-- The preimage of a convex cone under a `\ud835\udd5c`-linear map is a convex cone. -/\ndef comap (f : E \u2192\u2097[\ud835\udd5c] F) (S : convex_cone \ud835\udd5c F) : convex_cone \ud835\udd5c E :=\n{ carrier := f \u207b\u00b9' S,\n  smul_mem' := \u03bb c hc x hx, by { rw [mem_preimage, f.map_smul c], exact S.smul_mem hc hx },\n  add_mem' := \u03bb x hx y hy, by { rw [mem_preimage, f.map_add], exact S.add_mem hx hy } }\n\n@[simp] lemma comap_id (S : convex_cone \ud835\udd5c E) : S.comap linear_map.id = S := ext' preimage_id\n\nlemma comap_comap (g : F \u2192\u2097[\ud835\udd5c] G) (f : E \u2192\u2097[\ud835\udd5c] F) (S : convex_cone \ud835\udd5c G) :\n  (S.comap g).comap f = S.comap (g.comp f) :=\next' $ preimage_comp.symm\n\n@[simp] lemma mem_comap {f : E \u2192\u2097[\ud835\udd5c] F} {S : convex_cone \ud835\udd5c F} {x : E} : x \u2208 S.comap f \u2194 f x \u2208 S :=\niff.rfl\n\nend module\nend add_comm_monoid\n\nsection ordered_add_comm_group\nvariables [ordered_add_comm_group E] [module \ud835\udd5c E]\n\n/--\nConstructs an ordered module given an `ordered_add_comm_group`, a cone, and a proof that\nthe order relation is the one defined by the cone.\n-/\nlemma to_ordered_smul (S : convex_cone \ud835\udd5c E) (h : \u2200 x y : E, x \u2264 y \u2194 y - x \u2208 S) :\n  ordered_smul \ud835\udd5c E :=\nordered_smul.mk'\nbegin\n  intros x y z xy hz,\n  rw [h (z \u2022 x) (z \u2022 y), \u2190smul_sub z y x],\n  exact smul_mem S hz ((h x y).mp xy.le),\nend\n\nend ordered_add_comm_group\nend linear_ordered_field\n\n/-! ### Convex cones with extra properties -/\n\nsection ordered_semiring\nvariables [ordered_semiring \ud835\udd5c]\n\nsection add_comm_monoid\nvariables [add_comm_monoid E] [has_scalar \ud835\udd5c E] (S : convex_cone \ud835\udd5c E)\n\n/-- A convex cone is pointed if it includes `0`. -/\ndef pointed (S : convex_cone \ud835\udd5c E) : Prop := (0 : E) \u2208 S\n\n/-- A convex cone is blunt if it doesn't include `0`. -/\ndef blunt (S : convex_cone \ud835\udd5c E) : Prop := (0 : E) \u2209 S\n\nlemma pointed_iff_not_blunt (S : convex_cone \ud835\udd5c E) : S.pointed \u2194 \u00acS.blunt :=\n\u27e8\u03bb h\u2081 h\u2082, h\u2082 h\u2081, not_not.mp\u27e9\n\nlemma blunt_iff_not_pointed (S : convex_cone \ud835\udd5c E) : S.blunt \u2194 \u00acS.pointed :=\nby rw [pointed_iff_not_blunt, not_not]\n\nend add_comm_monoid\n\nsection add_comm_group\nvariables [add_comm_group E] [has_scalar \ud835\udd5c E] (S : convex_cone \ud835\udd5c E)\n\n/-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/\ndef flat : Prop := \u2203 x \u2208 S, x \u2260 (0 : E) \u2227 -x \u2208 S\n\n/-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/\ndef salient : Prop := \u2200 x \u2208 S, x \u2260 (0 : E) \u2192 -x \u2209 S\n\nlemma salient_iff_not_flat (S : convex_cone \ud835\udd5c E) : S.salient \u2194 \u00acS.flat :=\nbegin\n  split,\n  { rintros h\u2081 \u27e8x, xs, H\u2081, H\u2082\u27e9,\n    exact h\u2081 x xs H\u2081 H\u2082 },\n  { intro h,\n    unfold flat at h,\n    push_neg at h,\n    exact h }\nend\n\n/-- A flat cone is always pointed (contains `0`). -/\nlemma flat.pointed {S : convex_cone \ud835\udd5c E} (hS : S.flat) : S.pointed :=\nbegin\n  obtain \u27e8x, hx, _, hxneg\u27e9 := hS,\n  rw [pointed, \u2190add_neg_self x],\n  exact add_mem S hx hxneg,\nend\n\n/-- A blunt cone (one not containing `0`) is always salient. -/\nlemma blunt.salient {S : convex_cone \ud835\udd5c E} : S.blunt \u2192 S.salient :=\nbegin\n  rw [salient_iff_not_flat, blunt_iff_not_pointed],\n  exact mt flat.pointed,\nend\n\n/-- A pointed convex cone defines a preorder. -/\ndef to_preorder (h\u2081 : S.pointed) : preorder E :=\n{ le := \u03bb x y, y - x \u2208 S,\n  le_refl := \u03bb x, by change x - x \u2208 S; rw [sub_self x]; exact h\u2081,\n  le_trans := \u03bb x y z xy zy, by simpa using add_mem S zy xy }\n\n/-- A pointed and salient cone defines a partial order. -/\ndef to_partial_order (h\u2081 : S.pointed) (h\u2082 : S.salient) : partial_order E :=\n{ le_antisymm :=\n    begin\n      intros a b ab ba,\n      by_contradiction h,\n      have h' : b - a \u2260 0 := \u03bb h'', h (eq_of_sub_eq_zero h'').symm,\n      have H := h\u2082 (b-a) ab h',\n      rw neg_sub b a at H,\n      exact H ba,\n    end,\n  ..to_preorder S h\u2081 }\n\n/-- A pointed and salient cone defines an `ordered_add_comm_group`. -/\ndef to_ordered_add_comm_group (h\u2081 : S.pointed) (h\u2082 : S.salient) :\n  ordered_add_comm_group E :=\n{ add_le_add_left :=\n    begin\n      intros a b hab c,\n      change c + b - (c + a) \u2208 S,\n      rw add_sub_add_left_eq_sub,\n      exact hab,\n    end,\n  ..to_partial_order S h\u2081 h\u2082,\n  ..show add_comm_group E, by apply_instance }\n\nend add_comm_group\nend ordered_semiring\n\n/-! ### Positive cone of an ordered module -/\n\nsection positive_cone\nvariables (\ud835\udd5c E) [ordered_semiring \ud835\udd5c] [ordered_add_comm_group E] [module \ud835\udd5c E] [ordered_smul \ud835\udd5c E]\n\n/--\nThe positive cone is the convex cone formed by the set of nonnegative elements in an ordered\nmodule.\n-/\ndef positive_cone : convex_cone \ud835\udd5c E :=\n{ carrier := {x | 0 \u2264 x},\n  smul_mem' :=\n    begin\n      rintro c hc x (hx : _ \u2264 _),\n      rw \u2190smul_zero c,\n      exact smul_le_smul_of_nonneg hx hc.le,\n    end,\n  add_mem' := \u03bb x (hx : _ \u2264 _) y (hy : _ \u2264 _), add_nonneg hx hy }\n\n/-- The positive cone of an ordered module is always salient. -/\nlemma salient_positive_cone : salient (positive_cone \ud835\udd5c E) :=\n\u03bb x xs hx hx', lt_irrefl (0 : E)\n  (calc\n    0   < x         : lt_of_le_of_ne xs hx.symm\n    ... \u2264 x + (-x)  : le_add_of_nonneg_right hx'\n    ... = 0         : add_neg_self x)\n\n/-- The positive cone of an ordered module is always pointed. -/\nlemma pointed_positive_cone : pointed (positive_cone \ud835\udd5c E) := le_refl 0\n\nend positive_cone\nend convex_cone\n\n/-! ### Cone over a convex set -/\n\nsection cone_from_convex\nvariables [linear_ordered_field \ud835\udd5c] [ordered_add_comm_group E] [module \ud835\udd5c E]\n\nnamespace convex\n\n/-- The set of vectors proportional to those in a convex set forms a convex cone. -/\ndef to_cone (s : set E) (hs : convex \ud835\udd5c s) : convex_cone \ud835\udd5c E :=\nbegin\n  apply convex_cone.mk (\u22c3 (c : \ud835\udd5c) (H : 0 < c), c \u2022 s);\n    simp only [mem_Union, mem_smul_set],\n  { rintros c c_pos _ \u27e8c', c'_pos, x, hx, rfl\u27e9,\n    exact \u27e8c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm\u27e9 },\n  { rintros _ \u27e8cx, cx_pos, x, hx, rfl\u27e9 _ \u27e8cy, cy_pos, y, hy, rfl\u27e9,\n    have : 0 < cx + cy, from add_pos cx_pos cy_pos,\n    refine \u27e8_, this, _, convex_iff_div.1 hs hx hy cx_pos.le cy_pos.le this, _\u27e9,\n    simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left _ this.ne'] }\nend\n\nvariables {s : set E} (hs : convex \ud835\udd5c s) {x : E}\n\nlemma mem_to_cone : x \u2208 hs.to_cone s \u2194 \u2203 (c : \ud835\udd5c), 0 < c \u2227 \u2203 y \u2208 s, c \u2022 y = x :=\nby simp only [to_cone, convex_cone.mem_mk, mem_Union, mem_smul_set, eq_comm, exists_prop]\n\nlemma mem_to_cone' : x \u2208 hs.to_cone s \u2194 \u2203 (c : \ud835\udd5c), 0 < c \u2227 c \u2022 x \u2208 s :=\nbegin\n  refine hs.mem_to_cone.trans \u27e8_, _\u27e9,\n  { rintros \u27e8c, hc, y, hy, rfl\u27e9,\n    exact \u27e8c\u207b\u00b9, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel hc.ne', one_smul]\u27e9 },\n  { rintros \u27e8c, hc, hcx\u27e9,\n    exact \u27e8c\u207b\u00b9, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel hc.ne', one_smul]\u27e9 }\nend\n\nlemma subset_to_cone : s \u2286 hs.to_cone s :=\n\u03bb x hx, hs.mem_to_cone'.2 \u27e81, zero_lt_one, by rwa one_smul\u27e9\n\n/-- `hs.to_cone s` is the least cone that includes `s`. -/\nlemma to_cone_is_least : is_least { t : convex_cone \ud835\udd5c E | s \u2286 t } (hs.to_cone s) :=\nbegin\n  refine \u27e8hs.subset_to_cone, \u03bb t ht x hx, _\u27e9,\n  rcases hs.mem_to_cone.1 hx with \u27e8c, hc, y, hy, rfl\u27e9,\n  exact t.smul_mem hc (ht hy)\nend\n\nlemma to_cone_eq_Inf : hs.to_cone s = Inf { t : convex_cone \ud835\udd5c E | s \u2286 t } :=\nhs.to_cone_is_least.is_glb.Inf_eq.symm\n\nend convex\n\nlemma convex_hull_to_cone_is_least (s : set E) :\n  is_least {t : convex_cone \ud835\udd5c E | s \u2286 t} ((convex_convex_hull \ud835\udd5c s).to_cone _) :=\nbegin\n  convert (convex_convex_hull \ud835\udd5c s).to_cone_is_least,\n  ext t,\n  exact \u27e8\u03bb h, convex_hull_min h t.convex, (subset_convex_hull \ud835\udd5c s).trans\u27e9,\nend\n\nlemma convex_hull_to_cone_eq_Inf (s : set E) :\n  (convex_convex_hull \ud835\udd5c s).to_cone _ = Inf {t : convex_cone \ud835\udd5c E | s \u2286 t} :=\n(convex_hull_to_cone_is_least s).is_glb.Inf_eq.symm\n\nend cone_from_convex\n\n/-!\n### M. Riesz extension theorem\n\nGiven a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p \u2192 \u211d`, assume\nthat `f` is nonnegative on `p \u2229 s` and `p + s = E`. Then there exists a globally defined linear\nfunction `g : E \u2192 \u211d` that agrees with `f` on `p`, and is nonnegative on `s`.\n\nWe prove this theorem using Zorn's lemma. `riesz_extension.step` is the main part of the proof.\nIt says that if the domain `p` of `f` is not the whole space, then `f` can be extended to a larger\nsubspace `p \u2294 span \u211d {y}` without breaking the non-negativity condition.\n\nIn `riesz_extension.exists_top` we use Zorn's lemma to prove that we can extend `f`\nto a linear map `g` on `\u22a4 : submodule E`. Mathematically this is the same as a linear map on `E`\nbut in Lean `\u22a4 : submodule E` is isomorphic but is not equal to `E`. In `riesz_extension`\nwe use this isomorphism to prove the theorem.\n-/\n\nvariables [add_comm_group E] [module \u211d E]\n\nnamespace riesz_extension\nopen submodule\nvariables (s : convex_cone \u211d E) (f : linear_pmap \u211d E \u211d)\n\n/-- Induction step in M. Riesz extension theorem. Given a convex cone `s` in a vector space `E`,\na partially defined linear map `f : f.domain \u2192 \u211d`, assume that `f` is nonnegative on `f.domain \u2229 p`\nand `p + s = E`. If `f` is not defined on the whole `E`, then we can extend it to a larger\nsubmodule without breaking the non-negativity condition. -/\nlemma step (nonneg : \u2200 x : f.domain, (x : E) \u2208 s \u2192 0 \u2264 f x)\n  (dense : \u2200 y, \u2203 x : f.domain, (x : E) + y \u2208 s) (hdom : f.domain \u2260 \u22a4) :\n  \u2203 g, f < g \u2227 \u2200 x : g.domain, (x : E) \u2208 s \u2192 0 \u2264 g x :=\nbegin\n  obtain \u27e8y, -, hy\u27e9 : \u2203 (y : E) (h : y \u2208 \u22a4), y \u2209 f.domain,\n    { exact @set_like.exists_of_lt (submodule \u211d E) _ _ _ _ (lt_top_iff_ne_top.2 hdom) },\n  obtain \u27e8c, le_c, c_le\u27e9 :\n    \u2203 c, (\u2200 x : f.domain, -(x:E) - y \u2208 s \u2192 f x \u2264 c) \u2227 (\u2200 x : f.domain, (x:E) + y \u2208 s \u2192 c \u2264 f x),\n  { set Sp := f '' {x : f.domain | (x:E) + y \u2208 s},\n    set Sn := f '' {x : f.domain | -(x:E) - y \u2208 s},\n    suffices : (upper_bounds Sn \u2229 lower_bounds Sp).nonempty,\n      by simpa only [set.nonempty, upper_bounds, lower_bounds, ball_image_iff] using this,\n    refine exists_between_of_forall_le (nonempty.image f _) (nonempty.image f (dense y)) _,\n    { rcases (dense (-y)) with \u27e8x, hx\u27e9,\n      rw [\u2190 neg_neg x, coe_neg, \u2190 sub_eq_add_neg] at hx,\n      exact \u27e8_, hx\u27e9 },\n    rintros a \u27e8xn, hxn, rfl\u27e9 b \u27e8xp, hxp, rfl\u27e9,\n    have := s.add_mem hxp hxn,\n    rw [add_assoc, add_sub_cancel'_right, \u2190 sub_eq_add_neg, \u2190 coe_sub] at this,\n    replace := nonneg _ this,\n    rwa [f.map_sub, sub_nonneg] at this },\n  have hy' : y \u2260 0, from \u03bb hy\u2080, hy (hy\u2080.symm \u25b8 zero_mem _),\n  refine \u27e8f.sup_span_singleton y (-c) hy, _, _\u27e9,\n  { refine lt_iff_le_not_le.2 \u27e8f.left_le_sup _ _, \u03bb H, _\u27e9,\n    replace H := linear_pmap.domain_mono.monotone H,\n    rw [linear_pmap.domain_sup_span_singleton, sup_le_iff, span_le, singleton_subset_iff] at H,\n    exact hy H.2 },\n  { rintros \u27e8z, hz\u27e9 hzs,\n    rcases mem_sup.1 hz with \u27e8x, hx, y', hy', rfl\u27e9,\n    rcases mem_span_singleton.1 hy' with \u27e8r, rfl\u27e9,\n    simp only [subtype.coe_mk] at hzs,\n    erw [linear_pmap.sup_span_singleton_apply_mk _ _ _ _ _ hx, smul_neg,\n      \u2190 sub_eq_add_neg, sub_nonneg],\n    rcases lt_trichotomy r 0 with hr|hr|hr,\n    { have : -(r\u207b\u00b9 \u2022 x) - y \u2208 s,\n        by rwa [\u2190 s.smul_mem_iff (neg_pos.2 hr), smul_sub, smul_neg, neg_smul, neg_neg, smul_smul,\n          mul_inv_cancel hr.ne, one_smul, sub_eq_add_neg, neg_smul, neg_neg],\n      replace := le_c (r\u207b\u00b9 \u2022 \u27e8x, hx\u27e9) this,\n      rwa [\u2190 mul_le_mul_left (neg_pos.2 hr), \u2190 neg_mul_eq_neg_mul, \u2190 neg_mul_eq_neg_mul,\n        neg_le_neg_iff, f.map_smul, smul_eq_mul, \u2190 mul_assoc, mul_inv_cancel hr.ne,\n        one_mul] at this },\n    { subst r,\n      simp only [zero_smul, add_zero] at hzs \u22a2,\n      apply nonneg,\n      exact hzs },\n    { have : r\u207b\u00b9 \u2022 x + y \u2208 s,\n        by rwa [\u2190 s.smul_mem_iff hr, smul_add, smul_smul, mul_inv_cancel hr.ne', one_smul],\n      replace := c_le (r\u207b\u00b9 \u2022 \u27e8x, hx\u27e9) this,\n      rwa [\u2190 mul_le_mul_left hr, f.map_smul, smul_eq_mul, \u2190 mul_assoc,\n        mul_inv_cancel hr.ne', one_mul] at this } }\nend\n\ntheorem exists_top (p : linear_pmap \u211d E \u211d)\n  (hp_nonneg : \u2200 x : p.domain, (x : E) \u2208 s \u2192 0 \u2264 p x)\n  (hp_dense : \u2200 y, \u2203 x : p.domain, (x : E) + y \u2208 s) :\n  \u2203 q \u2265 p, q.domain = \u22a4 \u2227 \u2200 x : q.domain, (x : E) \u2208 s \u2192 0 \u2264 q x :=\nbegin\n  replace hp_nonneg : p \u2208 { p | _ }, by { rw mem_set_of_eq, exact hp_nonneg },\n  obtain \u27e8q, hqs, hpq, hq\u27e9 := zorn.zorn_nonempty_partial_order\u2080 _ _ _ hp_nonneg,\n  { refine \u27e8q, hpq, _, hqs\u27e9,\n    contrapose! hq,\n    rcases step s q hqs _ hq with \u27e8r, hqr, hr\u27e9,\n    { exact \u27e8r, hr, hqr.le, hqr.ne'\u27e9 },\n    { exact \u03bb y, let \u27e8x, hx\u27e9 := hp_dense y in \u27e8of_le hpq.left x, hx\u27e9 } },\n  { intros c hcs c_chain y hy,\n    clear hp_nonneg hp_dense p,\n    have cne : c.nonempty := \u27e8y, hy\u27e9,\n    refine \u27e8linear_pmap.Sup c c_chain.directed_on, _, \u03bb _, linear_pmap.le_Sup c_chain.directed_on\u27e9,\n    rintros \u27e8x, hx\u27e9 hxs,\n    have hdir : directed_on (\u2264) (linear_pmap.domain '' c),\n      from directed_on_image.2 (c_chain.directed_on.mono linear_pmap.domain_mono.monotone),\n    rcases (mem_Sup_of_directed (cne.image _) hdir).1 hx with \u27e8_, \u27e8f, hfc, rfl\u27e9, hfx\u27e9,\n    have : f \u2264 linear_pmap.Sup c c_chain.directed_on, from linear_pmap.le_Sup _ hfc,\n    convert \u2190 hcs hfc \u27e8x, hfx\u27e9 hxs,\n    apply this.2, refl }\nend\n\nend riesz_extension\n\n/-- M. **Riesz extension theorem**: given a convex cone `s` in a vector space `E`, a submodule `p`,\nand a linear `f : p \u2192 \u211d`, assume that `f` is nonnegative on `p \u2229 s` and `p + s = E`. Then\nthere exists a globally defined linear function `g : E \u2192 \u211d` that agrees with `f` on `p`,\nand is nonnegative on `s`. -/\ntheorem riesz_extension (s : convex_cone \u211d E) (f : linear_pmap \u211d E \u211d)\n  (nonneg : \u2200 x : f.domain, (x : E) \u2208 s \u2192 0 \u2264 f x) (dense : \u2200 y, \u2203 x : f.domain, (x : E) + y \u2208 s) :\n  \u2203 g : E \u2192\u2097[\u211d] \u211d, (\u2200 x : f.domain, g x = f x) \u2227 (\u2200 x \u2208 s, 0 \u2264 g x) :=\nbegin\n  rcases riesz_extension.exists_top s f nonneg dense with \u27e8\u27e8g_dom, g\u27e9, \u27e8hpg, hfg\u27e9, htop, hgs\u27e9,\n  clear hpg,\n  refine \u27e8g \u2218\u2097 \u2191(linear_equiv.of_top _ htop).symm, _, _\u27e9;\n    simp only [comp_apply, linear_equiv.coe_coe, linear_equiv.of_top_symm_apply],\n  { exact \u03bb x, (hfg (submodule.coe_mk _ _).symm).symm },\n  { exact \u03bb x hx, hgs \u27e8x, _\u27e9 hx }\nend\n\n/-- **Hahn-Banach theorem**: if `N : E \u2192 \u211d` is a sublinear map, `f` is a linear map\ndefined on a subspace of `E`, and `f x \u2264 N x` for all `x` in the domain of `f`,\nthen `f` can be extended to the whole space to a linear map `g` such that `g x \u2264 N x`\nfor all `x`. -/\ntheorem exists_extension_of_le_sublinear (f : linear_pmap \u211d E \u211d) (N : E \u2192 \u211d)\n  (N_hom : \u2200 (c : \u211d), 0 < c \u2192 \u2200 x, N (c \u2022 x) = c * N x)\n  (N_add : \u2200 x y, N (x + y) \u2264 N x + N y)\n  (hf : \u2200 x : f.domain, f x \u2264 N x) :\n  \u2203 g : E \u2192\u2097[\u211d] \u211d, (\u2200 x : f.domain, g x = f x) \u2227 (\u2200 x, g x \u2264 N x) :=\nbegin\n  let s : convex_cone \u211d (E \u00d7 \u211d) :=\n  { carrier := {p : E \u00d7 \u211d | N p.1 \u2264 p.2 },\n    smul_mem' := \u03bb c hc p hp,\n      calc N (c \u2022 p.1) = c * N p.1 : N_hom c hc p.1\n      ... \u2264 c * p.2 : mul_le_mul_of_nonneg_left hp hc.le,\n    add_mem' := \u03bb x hx y hy, (N_add _ _).trans (add_le_add hx hy) },\n  obtain \u27e8g, g_eq, g_nonneg\u27e9 :=\n    riesz_extension s ((-f).coprod (linear_map.id.to_pmap \u22a4)) _ _;\n    try { simp only [linear_pmap.coprod_apply, to_pmap_apply, id_apply,\n            linear_pmap.neg_apply, \u2190 sub_eq_neg_add, sub_nonneg, subtype.coe_mk] at * },\n  replace g_eq : \u2200 (x : f.domain) (y : \u211d), g (x, y) = y - f x,\n  { intros x y,\n    simpa only [subtype.coe_mk, subtype.coe_eta] using g_eq \u27e8(x, y), \u27e8x.2, trivial\u27e9\u27e9 },\n  { refine \u27e8-g.comp (inl \u211d E \u211d), _, _\u27e9; simp only [neg_apply, inl_apply, comp_apply],\n    { intro x, simp [g_eq x 0] },\n    { intro x,\n      have A : (x, N x) = (x, 0) + (0, N x), by simp,\n      have B := g_nonneg \u27e8x, N x\u27e9 (le_refl (N x)),\n      rw [A, map_add, \u2190 neg_le_iff_add_nonneg'] at B,\n      have C := g_eq 0 (N x),\n      simp only [submodule.coe_zero, f.map_zero, sub_zero] at C,\n      rwa \u2190 C } },\n  { exact \u03bb x hx, le_trans (hf _) hx },\n  { rintros \u27e8x, y\u27e9,\n    refine \u27e8\u27e8(0, N x - y), \u27e8f.domain.zero_mem, trivial\u27e9\u27e9, _\u27e9,\n    simp only [convex_cone.mem_mk, mem_set_of_eq, subtype.coe_mk, prod.fst_add, prod.snd_add,\n      zero_add, sub_add_cancel] }\nend\n\n/-! ### The dual cone -/\n\nsection dual\nvariables {H : Type*} [inner_product_space \u211d H] (s t : set H)\nopen_locale real_inner_product_space\n\n/-- The dual cone is the cone consisting of all points `y` such that for\nall points `x` in a given set `0 \u2264 \u27ea x, y \u27eb`. -/\nnoncomputable def set.inner_dual_cone (s : set H) : convex_cone \u211d H :=\n{ carrier := { y | \u2200 x \u2208 s, 0 \u2264 \u27ea x, y \u27eb },\n  smul_mem' := \u03bb c hc y hy x hx,\n  begin\n    rw real_inner_smul_right,\n    exact mul_nonneg hc.le (hy x hx)\n  end,\n  add_mem' := \u03bb u hu v hv x hx,\n  begin\n    rw inner_add_right,\n    exact add_nonneg (hu x hx) (hv x hx)\n  end }\n\nlemma mem_inner_dual_cone (y : H) (s : set H) :\n  y \u2208 s.inner_dual_cone \u2194 \u2200 x \u2208 s, 0 \u2264 \u27ea x, y \u27eb := by refl\n\n@[simp] lemma inner_dual_cone_empty : (\u2205 : set H).inner_dual_cone = \u22a4 :=\nconvex_cone.ext' (eq_univ_of_forall\n  (\u03bb x y hy, false.elim (set.not_mem_empty _ hy)))\n\nlemma inner_dual_cone_le_inner_dual_cone (h : t \u2286 s) :\n  s.inner_dual_cone \u2264 t.inner_dual_cone :=\n\u03bb y hy x hx, hy x (h hx)\n\nlemma pointed_inner_dual_cone : s.inner_dual_cone.pointed :=\n\u03bb x hx, by rw inner_zero_right\n\nend dual\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/convex/cone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7129956377475856}}
{"text": "/-\nCopyright (c) 2018 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n\n! This file was ported from Lean 3 source module topology.stone_cech\n! leanprover-community/mathlib commit 0a0ec35061ed9960bf0e7ffb0335f44447b58977\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.Bases\nimport Mathlib.Topology.DenseEmbedding\n\n/-! # Stone-\u010cech compactification\n\nConstruction of the Stone-\u010cech compactification using ultrafilters.\n\nParts of the formalization are based on \"Ultrafilters and Topology\"\nby Marius Stekelenburg, particularly section 5.\n-/\n\n\nnoncomputable section\n\nopen Filter Set\n\nopen Topology\n\nuniverse u v\n\nsection Ultrafilter\n\n/- The set of ultrafilters on \u03b1 carries a natural topology which makes\n  it the Stone-\u010cech compactification of \u03b1 (viewed as a discrete space). -/\n/-- Basis for the topology on `Ultrafilter \u03b1`. -/\ndef ultrafilterBasis (\u03b1 : Type u) : Set (Set (Ultrafilter \u03b1)) :=\n  range fun s : Set \u03b1 => { u | s \u2208 u }\n#align ultrafilter_basis ultrafilterBasis\n\nvariable {\u03b1 : Type u}\n\ninstance Ultrafilter.topologicalSpace : TopologicalSpace (Ultrafilter \u03b1) :=\n  TopologicalSpace.generateFrom (ultrafilterBasis \u03b1)\n#align ultrafilter.topological_space Ultrafilter.topologicalSpace\n\ntheorem ultrafilterBasis_is_basis : TopologicalSpace.IsTopologicalBasis (ultrafilterBasis \u03b1) :=\n  \u27e8by\n    rintro _ \u27e8a, rfl\u27e9 _ \u27e8b, rfl\u27e9 u \u27e8ua, ub\u27e9\n    refine' \u27e8_, \u27e8a \u2229 b, rfl\u27e9, inter_mem ua ub, fun v hv => \u27e8_, _\u27e9\u27e9 <;> apply mem_of_superset hv <;>\n      simp [inter_subset_right a b],\n    eq_univ_of_univ_subset <| subset_union\u209b_of_mem <| \u27e8univ, eq_univ_of_forall fun u => univ_mem\u27e9,\n    rfl\u27e9\n#align ultrafilter_basis_is_basis ultrafilterBasis_is_basis\n\n/-- The basic open sets for the topology on ultrafilters are open. -/\ntheorem ultrafilter_isOpen_basic (s : Set \u03b1) : IsOpen { u : Ultrafilter \u03b1 | s \u2208 u } :=\n  ultrafilterBasis_is_basis.isOpen \u27e8s, rfl\u27e9\n#align ultrafilter_is_open_basic ultrafilter_isOpen_basic\n\n/-- The basic open sets for the topology on ultrafilters are also closed. -/\ntheorem ultrafilter_isClosed_basic (s : Set \u03b1) : IsClosed { u : Ultrafilter \u03b1 | s \u2208 u } := by\n  rw [\u2190 isOpen_compl_iff]\n  convert ultrafilter_isOpen_basic (s\u1d9c) using 1\n  ext u\n  exact Ultrafilter.compl_mem_iff_not_mem.symm\n#align ultrafilter_is_closed_basic ultrafilter_isClosed_basic\n\n/-- Every ultrafilter `u` on `Ultrafilter \u03b1` converges to a unique\n  point of `Ultrafilter \u03b1`, namely `joinM u`. -/\ntheorem ultrafilter_converges_iff {u : Ultrafilter (Ultrafilter \u03b1)} {x : Ultrafilter \u03b1} :\n    \u2191u \u2264 \ud835\udcdd x \u2194 x = joinM u := by\n  rw [eq_comm, \u2190 Ultrafilter.coe_le_coe]\n  change \u2191u \u2264 \ud835\udcdd x \u2194 \u2200 s \u2208 x, { v : Ultrafilter \u03b1 | s \u2208 v } \u2208 u\n  simp only [TopologicalSpace.nhds_generateFrom, le_inf\u1d62_iff, ultrafilterBasis, le_principal_iff,\n    mem_setOf_eq]\n  constructor\n  \u00b7 intro h a ha\n    exact h _ \u27e8ha, a, rfl\u27e9\n  \u00b7 rintro h a \u27e8xi, a, rfl\u27e9\n    exact h _ xi\n#align ultrafilter_converges_iff ultrafilter_converges_iff\n\ninstance ultrafilter_compact : CompactSpace (Ultrafilter \u03b1) :=\n  \u27e8isCompact_iff_ultrafilter_le_nhds.mpr fun f _ =>\n      \u27e8joinM f, trivial, ultrafilter_converges_iff.mpr rfl\u27e9\u27e9\n#align ultrafilter_compact ultrafilter_compact\n\ninstance Ultrafilter.t2Space : T2Space (Ultrafilter \u03b1) :=\n  t2_iff_ultrafilter.mpr @fun x y f fx fy =>\n    have hx : x = joinM f := ultrafilter_converges_iff.mp fx\n    have hy : y = joinM f := ultrafilter_converges_iff.mp fy\n    hx.trans hy.symm\n#align ultrafilter.t2_space Ultrafilter.t2Space\n\ninstance : TotallyDisconnectedSpace (Ultrafilter \u03b1) := by\n  rw [totallyDisconnectedSpace_iff_connectedComponent_singleton]\n  intro A\n  simp only [Set.eq_singleton_iff_unique_mem, mem_connectedComponent, true_and_iff]\n  intro B hB\n  rw [\u2190 Ultrafilter.coe_le_coe]\n  intro s hs\n  rw [connectedComponent_eq_inter\u1d62_clopen, Set.mem_inter\u1d62] at hB\n  let Z := { F : Ultrafilter \u03b1 | s \u2208 F }\n  have hZ : IsClopen Z := \u27e8ultrafilter_isOpen_basic s, ultrafilter_isClosed_basic s\u27e9\n  exact hB \u27e8Z, hZ, hs\u27e9\n\ntheorem ultrafilter_comap_pure_nhds (b : Ultrafilter \u03b1) : comap pure (\ud835\udcdd b) \u2264 b := by\n  rw [TopologicalSpace.nhds_generateFrom]\n  simp only [comap_inf\u1d62, comap_principal]\n  intro s hs\n  rw [\u2190 le_principal_iff]\n  refine' inf\u1d62_le_of_le { u | s \u2208 u } _\n  refine' inf\u1d62_le_of_le \u27e8hs, \u27e8s, rfl\u27e9\u27e9 _\n  exact principal_mono.2 fun a => id\n#align ultrafilter_comap_pure_nhds ultrafilter_comap_pure_nhds\n\nsection Embedding\n\ntheorem ultrafilter_pure_injective : Function.Injective (pure : \u03b1 \u2192 Ultrafilter \u03b1) := by\n  intro x y h\n  have : {x} \u2208 (pure x : Ultrafilter \u03b1) := singleton_mem_pure\n  rw [h] at this\n  exact (mem_singleton_iff.mp (mem_pure.mp this)).symm\n#align ultrafilter_pure_injective ultrafilter_pure_injective\n\nopen TopologicalSpace\n\n/-- The range of `pure : \u03b1 \u2192 Ultrafilter \u03b1` is dense in `Ultrafilter \u03b1`. -/\ntheorem denseRange_pure : DenseRange (pure : \u03b1 \u2192 Ultrafilter \u03b1) := fun x =>\n  mem_closure_iff_ultrafilter.mpr\n    \u27e8x.map pure, range_mem_map, ultrafilter_converges_iff.mpr (bind_pure x).symm\u27e9\n#align dense_range_pure denseRange_pure\n\n/-- The map `pure : \u03b1 \u2192 Ultrafilter \u03b1` induces on `\u03b1` the discrete topology. -/\ntheorem induced_topology_pure :\n    TopologicalSpace.induced (pure : \u03b1 \u2192 Ultrafilter \u03b1) Ultrafilter.topologicalSpace = \u22a5 := by\n  apply eq_bot_of_singletons_open\n  intro x\n  use { u : Ultrafilter \u03b1 | {x} \u2208 u }, ultrafilter_isOpen_basic _\n  simp\n#align induced_topology_pure induced_topology_pure\n\n/-- `pure : \u03b1 \u2192 Ultrafilter \u03b1` defines a dense inducing of `\u03b1` in `Ultrafilter \u03b1`. -/\ntheorem denseInducing_pure : @DenseInducing _ _ \u22a5 _ (pure : \u03b1 \u2192 Ultrafilter \u03b1) :=\n  letI : TopologicalSpace \u03b1 := \u22a5\n  \u27e8\u27e8induced_topology_pure.symm\u27e9, denseRange_pure\u27e9\n#align dense_inducing_pure denseInducing_pure\n\n-- The following refined version will never be used\n/-- `pure : \u03b1 \u2192 Ultrafilter \u03b1` defines a dense embedding of `\u03b1` in `Ultrafilter \u03b1`. -/\ntheorem denseEmbedding_pure : @DenseEmbedding _ _ \u22a5 _ (pure : \u03b1 \u2192 Ultrafilter \u03b1) :=\n  letI : TopologicalSpace \u03b1 := \u22a5\n  { denseInducing_pure with inj := ultrafilter_pure_injective }\n#align dense_embedding_pure denseEmbedding_pure\n\nend Embedding\n\nsection Extension\n\n/- Goal: Any function `\u03b1 \u2192 \u03b3` to a compact Hausdorff space `\u03b3` has a\n  unique extension to a continuous function `Ultrafilter \u03b1 \u2192 \u03b3`. We\n  already know it must be unique because `\u03b1 \u2192 Ultrafilter \u03b1` is a\n  dense embedding and `\u03b3` is Hausdorff. For existence, we will invoke\n  `DenseInducing.continuous_extend`. -/\nvariable {\u03b3 : Type _} [TopologicalSpace \u03b3]\n\n/-- The extension of a function `\u03b1 \u2192 \u03b3` to a function `Ultrafilter \u03b1 \u2192 \u03b3`.\n  When `\u03b3` is a compact Hausdorff space it will be continuous. -/\ndef Ultrafilter.extend (f : \u03b1 \u2192 \u03b3) : Ultrafilter \u03b1 \u2192 \u03b3 :=\n  letI : TopologicalSpace \u03b1 := \u22a5\n  denseInducing_pure.extend f\n#align ultrafilter.extend Ultrafilter.extend\n\nvariable [T2Space \u03b3]\n\ntheorem ultrafilter_extend_extends (f : \u03b1 \u2192 \u03b3) : Ultrafilter.extend f \u2218 pure = f := by\n  letI : TopologicalSpace \u03b1 := \u22a5\n  haveI : DiscreteTopology \u03b1 := \u27e8rfl\u27e9\n  exact funext (denseInducing_pure.extend_eq continuous_of_discreteTopology)\n#align ultrafilter_extend_extends ultrafilter_extend_extends\n\nvariable [CompactSpace \u03b3]\n\ntheorem continuous_ultrafilter_extend (f : \u03b1 \u2192 \u03b3) : Continuous (Ultrafilter.extend f) := by\n  have h : \u2200 b : Ultrafilter \u03b1, \u2203 c, Tendsto f (comap pure (\ud835\udcdd b)) (\ud835\udcdd c) := fun b =>\n    -- b.map f is an ultrafilter on \u03b3, which is compact, so it converges to some c in \u03b3.\n    let \u27e8c, _, h'\u27e9 :=\n      isCompact_univ.ultrafilter_le_nhds (b.map f) (by rw [le_principal_iff]; exact univ_mem)\n    \u27e8c, le_trans (map_mono (ultrafilter_comap_pure_nhds _)) h'\u27e9\n  letI : TopologicalSpace \u03b1 := \u22a5\n  haveI : NormalSpace \u03b3 := normalOfCompactT2\n  exact denseInducing_pure.continuous_extend h\n#align continuous_ultrafilter_extend continuous_ultrafilter_extend\n\n/-- The value of `Ultrafilter.extend f` on an ultrafilter `b` is the\n  unique limit of the ultrafilter `b.map f` in `\u03b3`. -/\ntheorem ultrafilter_extend_eq_iff {f : \u03b1 \u2192 \u03b3} {b : Ultrafilter \u03b1} {c : \u03b3} :\n    Ultrafilter.extend f b = c \u2194 \u2191(b.map f) \u2264 \ud835\udcdd c :=\n  \u27e8fun h =>\n    by\n    -- Write b as an ultrafilter limit of pure ultrafilters, and use\n    -- the facts that ultrafilter.extend is a continuous extension of f.\n    let b' : Ultrafilter (Ultrafilter \u03b1) := b.map pure\n    have t : \u2191b' \u2264 \ud835\udcdd b := ultrafilter_converges_iff.mpr (bind_pure _).symm\n    rw [\u2190 h]\n    have := (continuous_ultrafilter_extend f).tendsto b\n    refine' le_trans _ (le_trans (map_mono t) this)\n    change _ \u2264 map (Ultrafilter.extend f \u2218 pure) \u2191b\n    rw [ultrafilter_extend_extends]\n    exact le_rfl, fun h =>\n    letI : TopologicalSpace \u03b1 := \u22a5\n    denseInducing_pure.extend_eq_of_tendsto\n      (le_trans (map_mono (ultrafilter_comap_pure_nhds _)) h)\u27e9\n#align ultrafilter_extend_eq_iff ultrafilter_extend_eq_iff\n\nend Extension\n\nend Ultrafilter\n\nsection StoneCech\n\n/- Now, we start with a (not necessarily discrete) topological space \u03b1\n  and we want to construct its Stone-\u010cech compactification. We can\n  build it as a quotient of `Ultrafilter \u03b1` by the relation which\n  identifies two points if the extension of every continuous function\n  \u03b1 \u2192 \u03b3 to a compact Hausdorff space sends the two points to the same\n  point of \u03b3. -/\nvariable (\u03b1 : Type u) [TopologicalSpace \u03b1]\n\ninstance stoneCechSetoid : Setoid (Ultrafilter \u03b1)\n    where\n  r x y :=\n    \u2200 (\u03b3 : Type u) [TopologicalSpace \u03b3],\n      \u2200 [T2Space \u03b3] [CompactSpace \u03b3] (f : \u03b1 \u2192 \u03b3) (_ : Continuous f),\n        Ultrafilter.extend f x = Ultrafilter.extend f y\n  iseqv :=\n    \u27e8fun _ _ _ _ _ _ _ => rfl, @fun _ _ xy \u03b3 _ _ _ f hf => (xy \u03b3 f hf).symm,\n      @fun _ _ _ xy yz \u03b3 _ _ _ f hf => (xy \u03b3 f hf).trans (yz \u03b3 f hf)\u27e9\n#align stone_cech_setoid stoneCechSetoid\n\n/-- The Stone-\u010cech compactification of a topological space. -/\ndef StoneCech : Type u :=\n  Quotient (stoneCechSetoid \u03b1)\n#align stone_cech StoneCech\n\nvariable {\u03b1}\n\ninstance : TopologicalSpace (StoneCech \u03b1) := by unfold StoneCech; infer_instance\n\ninstance [Inhabited \u03b1] : Inhabited (StoneCech \u03b1) := by unfold StoneCech; infer_instance\n\n/-- The natural map from \u03b1 to its Stone-\u010cech compactification. -/\ndef stoneCechUnit (x : \u03b1) : StoneCech \u03b1 :=\n  \u27e6pure x\u27e7\n#align stone_cech_unit stoneCechUnit\n\n/-- The image of stone_cech_unit is dense. (But stone_cech_unit need\n  not be an embedding, for example if \u03b1 is not Hausdorff.) -/\ntheorem denseRange_stoneCechUnit : DenseRange (stoneCechUnit : \u03b1 \u2192 StoneCech \u03b1) :=\n  denseRange_pure.quotient\n#align dense_range_stone_cech_unit denseRange_stoneCechUnit\n\nsection Extension\n\nvariable {\u03b3 : Type u} [TopologicalSpace \u03b3] [T2Space \u03b3] [CompactSpace \u03b3]\n\nvariable {\u03b3' : Type u} [TopologicalSpace \u03b3'] [T2Space \u03b3']\n\nvariable {f : \u03b1 \u2192 \u03b3} (hf : Continuous f)\n\n-- Porting note: missing attribute\n--attribute [local elab_with_expected_type] Quotient.lift\n\n/-- The extension of a continuous function from \u03b1 to a compact\n  Hausdorff space \u03b3 to the Stone-\u010cech compactification of \u03b1. -/\ndef stoneCechExtend : StoneCech \u03b1 \u2192 \u03b3 :=\n  Quotient.lift (Ultrafilter.extend f) fun _ _ xy => xy \u03b3 f hf\n#align stone_cech_extend stoneCechExtend\n\ntheorem stoneCechExtend_extends : stoneCechExtend hf \u2218 stoneCechUnit = f :=\n  ultrafilter_extend_extends f\n#align stone_cech_extend_extends stoneCechExtend_extends\n\ntheorem continuous_stoneCechExtend : Continuous (stoneCechExtend hf) :=\n  continuous_quot_lift _ (continuous_ultrafilter_extend f)\n#align continuous_stone_cech_extend continuous_stoneCechExtend\n\ntheorem stoneCech_hom_ext {g\u2081 g\u2082 : StoneCech \u03b1 \u2192 \u03b3'} (h\u2081 : Continuous g\u2081) (h\u2082 : Continuous g\u2082)\n    (h : g\u2081 \u2218 stoneCechUnit = g\u2082 \u2218 stoneCechUnit) : g\u2081 = g\u2082 := by\n  apply Continuous.ext_on denseRange_stoneCechUnit h\u2081 h\u2082\n  rintro x \u27e8x, rfl\u27e9\n  apply congr_fun h x\n#align stone_cech_hom_ext stoneCech_hom_ext\n\nend Extension\n\ntheorem convergent_eqv_pure {u : Ultrafilter \u03b1} {x : \u03b1} (ux : \u2191u \u2264 \ud835\udcdd x) : u \u2248 pure x :=\n  fun \u03b3 t\u03b3 h\u2081 h\u2082 f hf => by\n  skip\n  trans f x; swap; symm\n  all_goals refine' ultrafilter_extend_eq_iff.mpr (le_trans (map_mono _) (hf.tendsto _))\n  \u00b7 apply pure_le_nhds\n  \u00b7 exact ux\n#align convergent_eqv_pure convergent_eqv_pure\n\ntheorem continuous_stoneCechUnit : Continuous (stoneCechUnit : \u03b1 \u2192 StoneCech \u03b1) :=\n  continuous_iff_ultrafilter.mpr fun x g gx =>\n    by\n    have : (g.map pure).toFilter \u2264 \ud835\udcdd g := by\n      rw [ultrafilter_converges_iff]\n      exact (bind_pure _).symm\n    have : (g.map stoneCechUnit : Filter (StoneCech \u03b1)) \u2264 \ud835\udcdd \u27e6g\u27e7 :=\n      continuousAt_iff_ultrafilter.mp (continuous_quotient_mk'.tendsto g) _ this\n    rwa [show \u27e6g\u27e7 = \u27e6pure x\u27e7 from Quotient.sound <| convergent_eqv_pure gx] at this\n#align continuous_stone_cech_unit continuous_stoneCechUnit\n\ninstance StoneCech.t2Space : T2Space (StoneCech \u03b1) := by\n  rw [t2_iff_ultrafilter]\n  rintro \u27e8x\u27e9 \u27e8y\u27e9 g gx gy\n  apply Quotient.sound\n  intro \u03b3 t\u03b3 h\u2081 h\u2082 f hf\n  skip\n  let ff := stoneCechExtend hf\n  change ff \u27e6x\u27e7 = ff \u27e6y\u27e7\n  have lim := fun (z : Ultrafilter \u03b1) (gz : (g : Filter (StoneCech \u03b1)) \u2264 \ud835\udcdd \u27e6z\u27e7) =>\n    ((continuous_stoneCechExtend hf).tendsto _).mono_left gz\n  exact tendsto_nhds_unique (lim x gx) (lim y gy)\n#align stone_cech.t2_space StoneCech.t2Space\n\ninstance StoneCech.compactSpace : CompactSpace (StoneCech \u03b1) :=\n  Quotient.compactSpace\n#align stone_cech.compact_space StoneCech.compactSpace\n\nend StoneCech\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/StoneCech.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.7905303186696748, "lm_q1q2_score": 0.7129956314953445}}
{"text": "import tactic\n\nnamespace vilnius\n\n/- ### Introduction\nThe orange stuff on the right are **assumptions** or **hypothesis**; the stuff at the end before\nthe blue `\u22a2` sign is the **goal**. A **tactic** is some move that makes the goal change, hopefully\ntowards an easier one.\n\n ## intro(s), exact, apply\nThe main tools here are the tactics\n* `intro`, that introduces a *generic* object (and `intros` introducting several ones at once)\n* `exact`, telling Lean that the goal is already a hypothesis;\n* `apply`, which transforms a goal P into a goal Q when applying a hypothesis `H : Q \u2192 P`.\n-/\n\n-- **The implication \u2192**\n\ntheorem self_implication (P : Prop) : P \u2192 P :=\nbegin\n  sorry,\nend\n\ntheorem forall_imp (P Q R : Prop) : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  sorry,\nend\n\ntheorem modus_ponens (P Q : Prop) : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  sorry,\nend\n\n/- **not \u00ac**\n`not P`, with notation `\u00ac P`, is *defined* to mean `P \u2192 false`, so the fact that P implies false.\nYou can easily check with a truth table that P \u2192 false and \u00ac P are equivalent. -/\n\n\ntheorem modus_tollens (P Q : Prop) : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  sorry,\nend\n\n\n/- ## by_contradiction\nFor the following, we need to argue _by contradiction_, which can be done by the tactic \n* `by_contradiction`: it introduces the _negation_ of the goal and transforms the goal into `false`.\n-/\ntheorem double_negation_elimination (P : Prop) : \u00ac (\u00ac P) \u2192 P :=\nbegin\n  sorry,\nend\n\n/- **\u2227**\nGiven two propositions P and Q, P \u2227 Q is the proposition that is true precisely if both P and Q\nare true. Hence, in order to prove something like this, you can use \n\n## split\n* the tactic `split` splits the goal into two sub-goals.\n-/\n\ntheorem trivial (P Q : Prop) (hP : P) (hQ : Q) : P \u2227 Q :=\nbegin\n  sorry,\nend\n\n/-- ## cases \n If you want to _use_ an assumption of the form P \u2227 Q, you can use \n* the tactic `cases`: it destructures the **assumption** into two sub-assumptions, one being P and\n  the other being Q: it is the first tactic seen so far that does not act on the goal but on something\n  in orange -/\n\ntheorem and.elim_left (P Q : Prop) : P \u2227 Q \u2192 P :=\nbegin\n  sorry,\nend\n\n\n/- **\u2228**\nSimilarly, given propositions P and Q, the proposition P \u2228 Q is true whenever at least one of P or \nQ is true. Here, the tactic `cases` produces two sub-goals, one assuming that P is true, the other\nassuming that Q is true\n\n**Hint** When P and \u00ac P are both hypothesis, something is weird: the proposition to prove is\nfalse, so we can try to argue `by_contradiction`.-/\n\ntheorem or_not_left (P Q : Prop) : P \u2228 Q \u2192 \u00ac P \u2192 Q :=\nbegin\n  sorry,\nend\n\nend vilnius\n\n", "meta": {"author": "faenuccio", "repo": "May22_Vilnius", "sha": "2ff937dc7568e6118473b1e7f479ccb2a5fa9767", "save_path": "github-repos/lean/faenuccio-May22_Vilnius", "path": "github-repos/lean/faenuccio-May22_Vilnius/May22_Vilnius-2ff937dc7568e6118473b1e7f479ccb2a5fa9767/src/A_Logic/Course.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7129280085626365}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n\n! This file was ported from Lean 3 source module combinatorics.simple_graph.degree_sum\n! leanprover-community/mathlib commit 97eab48559068f3d6313da387714ef25768fb730\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Combinatorics.SimpleGraph.Basic\nimport Mathbin.Algebra.BigOperators.Basic\nimport Mathbin.Data.Nat.Parity\nimport Mathbin.Data.Zmod.Parity\n\n/-!\n# Degree-sum formula and handshaking lemma\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe degree-sum formula is that the sum of the degrees of the vertices in\na finite graph is equal to twice the number of edges.  The handshaking lemma,\na corollary, is that the number of odd-degree vertices is even.\n\n## Main definitions\n\n- `simple_graph.sum_degrees_eq_twice_card_edges` is the degree-sum formula.\n- `simple_graph.even_card_odd_degree_vertices` is the handshaking lemma.\n- `simple_graph.odd_card_odd_degree_vertices_ne` is that the number of odd-degree\n  vertices different from a given odd-degree vertex is odd.\n- `simple_graph.exists_ne_odd_degree_of_exists_odd_degree` is that the existence of an\n  odd-degree vertex implies the existence of another one.\n\n## Implementation notes\n\nWe give a combinatorial proof by using the facts that (1) the map from\ndarts to vertices is such that each fiber has cardinality the degree\nof the corresponding vertex and that (2) the map from darts to edges is 2-to-1.\n\n## Tags\n\nsimple graphs, sums, degree-sum formula, handshaking lemma\n-/\n\n\nopen Finset\n\nopen BigOperators\n\nnamespace SimpleGraph\n\nuniverse u\n\nvariable {V : Type u} (G : SimpleGraph V)\n\nsection DegreeSum\n\nvariable [Fintype V] [DecidableRel G.Adj]\n\n#print SimpleGraph.dart_fst_fiber /-\ntheorem dart_fst_fiber [DecidableEq V] (v : V) :\n    (univ.filter\u2093 fun d : G.Dart => d.fst = v) = univ.image (G.dartOfNeighborSet v) :=\n  by\n  ext d\n  simp only [mem_image, true_and_iff, mem_filter, SetCoe.exists, mem_univ, exists_prop_of_true]\n  constructor\n  \u00b7 rintro rfl\n    exact \u27e8_, d.is_adj, by ext <;> rfl\u27e9\n  \u00b7 rintro \u27e8e, he, rfl\u27e9\n    rfl\n#align simple_graph.dart_fst_fiber SimpleGraph.dart_fst_fiber\n-/\n\n#print SimpleGraph.dart_fst_fiber_card_eq_degree /-\ntheorem dart_fst_fiber_card_eq_degree [DecidableEq V] (v : V) :\n    (univ.filter\u2093 fun d : G.Dart => d.fst = v).card = G.degree v := by\n  simpa only [dart_fst_fiber, Finset.card_univ, card_neighbor_set_eq_degree] using\n    card_image_of_injective univ (G.dart_of_neighbor_set_injective v)\n#align simple_graph.dart_fst_fiber_card_eq_degree SimpleGraph.dart_fst_fiber_card_eq_degree\n-/\n\n#print SimpleGraph.dart_card_eq_sum_degrees /-\ntheorem dart_card_eq_sum_degrees : Fintype.card G.Dart = \u2211 v, G.degree v :=\n  by\n  haveI := Classical.decEq V\n  simp only [\u2190 card_univ, \u2190 dart_fst_fiber_card_eq_degree]\n  exact card_eq_sum_card_fiberwise (by simp)\n#align simple_graph.dart_card_eq_sum_degrees SimpleGraph.dart_card_eq_sum_degrees\n-/\n\nvariable {G} [DecidableEq V]\n\n#print SimpleGraph.Dart.edge_fiber /-\ntheorem Dart.edge_fiber (d : G.Dart) :\n    (univ.filter\u2093 fun d' : G.Dart => d'.edge = d.edge) = {d, d.symm} :=\n  Finset.ext fun d' => by simpa using dart_edge_eq_iff d' d\n#align simple_graph.dart.edge_fiber SimpleGraph.Dart.edge_fiber\n-/\n\nvariable (G)\n\n/- warning: simple_graph.dart_edge_fiber_card -> SimpleGraph.dart_edge_fiber_card is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] [_inst_3 : DecidableEq.{succ u1} V] (e : Sym2.{u1} V), (Membership.Mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.hasMem.{u1} (Sym2.{u1} V)) e (coeFn.{succ u1, succ u1} (OrderEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (SimpleGraph.hasLe.{u1} V) (Set.hasLe.{u1} (Sym2.{u1} V))) (fun (_x : RelEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) => (SimpleGraph.{u1} V) -> (Set.{u1} (Sym2.{u1} V))) (RelEmbedding.hasCoeToFun.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) (SimpleGraph.edgeSetEmbedding.{u1} V) G)) -> (Eq.{1} Nat (Finset.card.{u1} (SimpleGraph.Dart.{u1} V G) (Finset.filter.{u1} (SimpleGraph.Dart.{u1} V G) (fun (d : SimpleGraph.Dart.{u1} V G) => Eq.{succ u1} (Sym2.{u1} V) (SimpleGraph.Dart.edge.{u1} V G d) e) (fun (a : SimpleGraph.Dart.{u1} V G) => Quotient.decidableEq.{succ u1} (Prod.{u1, u1} V V) (Sym2.Rel.setoid.{u1} V) (fun (a : Prod.{u1, u1} V V) (b : Prod.{u1, u1} V V) => Sym2.Rel.decidableRel.{u1} V (fun (a : V) (b : V) => _inst_3 a b) a b) (SimpleGraph.Dart.edge.{u1} V G a) e) (Finset.univ.{u1} (SimpleGraph.Dart.{u1} V G) (SimpleGraph.Dart.fintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b))))) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne)))))\nbut is expected to have type\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] [_inst_3 : DecidableEq.{succ u1} V] (e : Sym2.{u1} V), (Membership.mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.instMembershipSet.{u1} (Sym2.{u1} V)) e (SimpleGraph.edgeSet.{u1} V G)) -> (Eq.{1} Nat (Finset.card.{u1} (SimpleGraph.Dart.{u1} V G) (Finset.filter.{u1} (SimpleGraph.Dart.{u1} V G) (fun (d : SimpleGraph.Dart.{u1} V G) => Eq.{succ u1} (Sym2.{u1} V) (SimpleGraph.Dart.edge.{u1} V G d) e) (fun (a : SimpleGraph.Dart.{u1} V G) => Quotient.decidableEq.{succ u1} (Prod.{u1, u1} V V) (Sym2.Rel.setoid.{u1} V) (fun (a : Prod.{u1, u1} V V) (b : Prod.{u1, u1} V V) => (fun (a : Prod.{u1, u1} V V) (b : Prod.{u1, u1} V V) => Sym2.instRelDecidable'.{u1} V (fun (a : V) (b : V) => _inst_3 a b) a b) a b) (SimpleGraph.Dart.edge.{u1} V G a) e) (Finset.univ.{u1} (SimpleGraph.Dart.{u1} V G) (SimpleGraph.Dart.fintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b))))) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)))\nCase conversion may be inaccurate. Consider using '#align simple_graph.dart_edge_fiber_card SimpleGraph.dart_edge_fiber_card\u2093'. -/\ntheorem dart_edge_fiber_card (e : Sym2 V) (h : e \u2208 G.edgeSetEmbedding) :\n    (univ.filter\u2093 fun d : G.Dart => d.edge = e).card = 2 :=\n  by\n  refine' Sym2.ind (fun v w h => _) e h\n  let d : G.dart := \u27e8(v, w), h\u27e9\n  convert congr_arg card d.edge_fiber\n  rw [card_insert_of_not_mem, card_singleton]\n  rw [mem_singleton]\n  exact d.symm_ne.symm\n#align simple_graph.dart_edge_fiber_card SimpleGraph.dart_edge_fiber_card\n\n/- warning: simple_graph.dart_card_eq_twice_card_edges -> SimpleGraph.dart_card_eq_twice_card_edges is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] [_inst_3 : DecidableEq.{succ u1} V], Eq.{1} Nat (Fintype.card.{u1} (SimpleGraph.Dart.{u1} V G) (SimpleGraph.Dart.fintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b))) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne)))) (Finset.card.{u1} (Sym2.{u1} V) (SimpleGraph.edgeFinset.{u1} V G (SimpleGraph.fintypeEdgeSet.{u1} V G (fun (a : V) (b : V) => _inst_3 a b) _inst_1 (fun (a : V) (b : V) => _inst_2 a b)))))\nbut is expected to have type\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] [_inst_3 : Fintype.{u1} (Sym2.{u1} V)] [inst._@.Mathlib.Combinatorics.SimpleGraph.DegreeSum._hyg.684 : DecidableEq.{succ u1} V], Eq.{1} Nat (Fintype.card.{u1} (SimpleGraph.Dart.{u1} V G) (SimpleGraph.Dart.fintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b))) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)) (Finset.card.{u1} (Sym2.{u1} V) (SimpleGraph.edgeFinset.{u1} V G (SimpleGraph.fintypeEdgeSet.{u1} V G _inst_3 (fun (a : V) (b : V) => _inst_2 a b)))))\nCase conversion may be inaccurate. Consider using '#align simple_graph.dart_card_eq_twice_card_edges SimpleGraph.dart_card_eq_twice_card_edges\u2093'. -/\ntheorem dart_card_eq_twice_card_edges : Fintype.card G.Dart = 2 * G.edgeFinset.card :=\n  by\n  rw [\u2190 card_univ]\n  rw [@card_eq_sum_card_fiberwise _ _ _ dart.edge _ G.edge_finset fun d h =>\n      by\n      rw [mem_edge_finset]\n      apply dart.edge_mem]\n  rw [\u2190 mul_comm, sum_const_nat]\n  intro e h\n  apply G.dart_edge_fiber_card e\n  rwa [\u2190 mem_edge_finset]\n#align simple_graph.dart_card_eq_twice_card_edges SimpleGraph.dart_card_eq_twice_card_edges\n\n/- warning: simple_graph.sum_degrees_eq_twice_card_edges -> SimpleGraph.sum_degrees_eq_twice_card_edges is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] [_inst_3 : DecidableEq.{succ u1} V], Eq.{1} Nat (Finset.sum.{0, u1} Nat V Nat.addCommMonoid (Finset.univ.{u1} V _inst_1) (fun (v : V) => SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b) v))) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne)))) (Finset.card.{u1} (Sym2.{u1} V) (SimpleGraph.edgeFinset.{u1} V G (SimpleGraph.fintypeEdgeSet.{u1} V G (fun (a : V) (b : V) => _inst_3 a b) _inst_1 (fun (a : V) (b : V) => _inst_2 a b)))))\nbut is expected to have type\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] [_inst_3 : Fintype.{u1} (Sym2.{u1} V)] [inst._@.Mathlib.Combinatorics.SimpleGraph.DegreeSum._hyg.883 : DecidableEq.{succ u1} V], Eq.{1} Nat (Finset.sum.{0, u1} Nat V Nat.addCommMonoid (Finset.univ.{u1} V _inst_1) (fun (v : V) => SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b) v))) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)) (Finset.card.{u1} (Sym2.{u1} V) (SimpleGraph.edgeFinset.{u1} V G (SimpleGraph.fintypeEdgeSet.{u1} V G _inst_3 (fun (a : V) (b : V) => _inst_2 a b)))))\nCase conversion may be inaccurate. Consider using '#align simple_graph.sum_degrees_eq_twice_card_edges SimpleGraph.sum_degrees_eq_twice_card_edges\u2093'. -/\n/-- The degree-sum formula.  This is also known as the handshaking lemma, which might\nmore specifically refer to `simple_graph.even_card_odd_degree_vertices`. -/\ntheorem sum_degrees_eq_twice_card_edges : (\u2211 v, G.degree v) = 2 * G.edgeFinset.card :=\n  G.dart_card_eq_sum_degrees.symm.trans G.dart_card_eq_twice_card_edges\n#align simple_graph.sum_degrees_eq_twice_card_edges SimpleGraph.sum_degrees_eq_twice_card_edges\n\nend DegreeSum\n\n/- warning: simple_graph.even_card_odd_degree_vertices -> SimpleGraph.even_card_odd_degree_vertices is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)], Even.{0} Nat Nat.hasAdd (Finset.card.{u1} V (Finset.filter.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b) v))) (fun (a : V) => Nat.Odd.decidablePred (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b) a))) (Finset.univ.{u1} V _inst_1)))\nbut is expected to have type\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)], Even.{0} Nat instAddNat (Finset.card.{u1} V (Finset.filter.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b) v))) (fun (a : V) => Nat.instDecidablePredNatOddSemiring (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_2 a b) a))) (Finset.univ.{u1} V _inst_1)))\nCase conversion may be inaccurate. Consider using '#align simple_graph.even_card_odd_degree_vertices SimpleGraph.even_card_odd_degree_vertices\u2093'. -/\n/-- The handshaking lemma.  See also `simple_graph.sum_degrees_eq_twice_card_edges`. -/\ntheorem even_card_odd_degree_vertices [Fintype V] [DecidableRel G.Adj] :\n    Even (univ.filter\u2093 fun v => Odd (G.degree v)).card := by\n  classical\n    have h := congr_arg (fun n => \u2191n : \u2115 \u2192 ZMod 2) G.sum_degrees_eq_twice_card_edges\n    simp only [ZMod.nat_cast_self, MulZeroClass.zero_mul, Nat.cast_mul] at h\n    rw [Nat.cast_sum, \u2190 sum_filter_ne_zero] at h\n    rw [@sum_congr _ _ _ _ (fun v => (G.degree v : ZMod 2)) (fun v => (1 : ZMod 2)) _ rfl] at h\n    \u00b7 simp only [filter_congr_decidable, mul_one, nsmul_eq_mul, sum_const, Ne.def] at h\n      rw [\u2190 ZMod.eq_zero_iff_even]\n      convert h\n      ext v\n      rw [\u2190 ZMod.ne_zero_iff_odd]\n    \u00b7 intro v\n      simp only [true_and_iff, mem_filter, mem_univ, Ne.def]\n      rw [ZMod.eq_zero_iff_even, ZMod.eq_one_iff_odd, Nat.odd_iff_not_even, imp_self]\n      trivial\n#align simple_graph.even_card_odd_degree_vertices SimpleGraph.even_card_odd_degree_vertices\n\n/- warning: simple_graph.odd_card_odd_degree_vertices_ne -> SimpleGraph.odd_card_odd_degree_vertices_ne is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableEq.{succ u1} V] [_inst_3 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] (v : V), (Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) v))) -> (Odd.{0} Nat Nat.semiring (Finset.card.{u1} V (Finset.filter.{u1} V (fun (w : V) => And (Ne.{succ u1} V w v) (Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G w (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) w)))) (fun (a : V) => And.decidable (Ne.{succ u1} V a v) (Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) a))) (Ne.decidable.{succ u1} V (fun (a : V) (b : V) => _inst_2 a b) a v) (Nat.Odd.decidablePred (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) a)))) (Finset.univ.{u1} V _inst_1))))\nbut is expected to have type\n  forall {V : Type.{u1}} (G : SimpleGraph.{u1} V) [_inst_1 : Fintype.{u1} V] [_inst_2 : DecidableEq.{succ u1} V] [_inst_3 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] (v : V), (Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) v))) -> (Odd.{0} Nat Nat.semiring (Finset.card.{u1} V (Finset.filter.{u1} V (fun (w : V) => And (Ne.{succ u1} V w v) (Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G w (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) w)))) (fun (a : V) => instDecidableAnd (Ne.{succ u1} V a v) (Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) a))) (instDecidableNot (Eq.{succ u1} V a v) (_inst_2 a v)) (Nat.instDecidablePredNatOddSemiring (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_1 (fun (a : V) (b : V) => _inst_3 a b) a)))) (Finset.univ.{u1} V _inst_1))))\nCase conversion may be inaccurate. Consider using '#align simple_graph.odd_card_odd_degree_vertices_ne SimpleGraph.odd_card_odd_degree_vertices_ne\u2093'. -/\ntheorem odd_card_odd_degree_vertices_ne [Fintype V] [DecidableEq V] [DecidableRel G.Adj] (v : V)\n    (h : Odd (G.degree v)) : Odd (univ.filter\u2093 fun w => w \u2260 v \u2227 Odd (G.degree w)).card :=\n  by\n  rcases G.even_card_odd_degree_vertices with \u27e8k, hg\u27e9\n  have hk : 0 < k :=\n    by\n    have hh : (Filter (fun v : V => Odd (G.degree v)) univ).Nonempty :=\n      by\n      use v\n      simp only [true_and_iff, mem_filter, mem_univ]\n      use h\n    rwa [\u2190 card_pos, hg, \u2190 two_mul, zero_lt_mul_left] at hh\n    exact zero_lt_two\n  have hc : (fun w : V => w \u2260 v \u2227 Odd (G.degree w)) = fun w : V => Odd (G.degree w) \u2227 w \u2260 v :=\n    by\n    ext w\n    rw [and_comm']\n  simp only [hc, filter_congr_decidable]\n  rw [\u2190 filter_filter, filter_ne', card_erase_of_mem]\n  \u00b7 refine' \u27e8k - 1, tsub_eq_of_eq_add <| hg.trans _\u27e9\n    rw [add_assoc, one_add_one_eq_two, \u2190 Nat.mul_succ, \u2190 two_mul]\n    congr\n    exact (tsub_add_cancel_of_le <| Nat.succ_le_iff.2 hk).symm\n  \u00b7 simpa only [true_and_iff, mem_filter, mem_univ]\n#align simple_graph.odd_card_odd_degree_vertices_ne SimpleGraph.odd_card_odd_degree_vertices_ne\n\n#print SimpleGraph.exists_ne_odd_degree_of_exists_odd_degree /-\ntheorem exists_ne_odd_degree_of_exists_odd_degree [Fintype V] [DecidableRel G.Adj] (v : V)\n    (h : Odd (G.degree v)) : \u2203 w : V, w \u2260 v \u2227 Odd (G.degree w) :=\n  by\n  haveI := Classical.decEq V\n  rcases G.odd_card_odd_degree_vertices_ne v h with \u27e8k, hg\u27e9\n  have hg' : (Filter (fun w : V => w \u2260 v \u2227 Odd (G.degree w)) univ).card > 0 :=\n    by\n    rw [hg]\n    apply Nat.succ_pos\n  rcases card_pos.mp hg' with \u27e8w, hw\u27e9\n  simp only [true_and_iff, mem_filter, mem_univ, Ne.def] at hw\n  exact \u27e8w, hw\u27e9\n#align simple_graph.exists_ne_odd_degree_of_exists_odd_degree SimpleGraph.exists_ne_odd_degree_of_exists_odd_degree\n-/\n\nend SimpleGraph\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/SimpleGraph/DegreeSum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7129280056373916}}
{"text": "/-\nCopyright (c) 2020 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Devon Tuma\n-/\nimport ring_theory.ideal.quotient\nimport ring_theory.polynomial.basic\n\n/-!\n# Jacobson radical\n\nThe Jacobson radical of a ring `R` is defined to be the intersection of all maximal ideals of `R`.\nThis is similar to how the nilradical is equal to the intersection of all prime ideals of `R`.\n\nWe can extend the idea of the nilradical to ideals of `R`,\nby letting the radical of an ideal `I` be the intersection of prime ideals containing `I`.\nUnder this extension, the original nilradical is the radical of the zero ideal `\u22a5`.\nHere we define the Jacobson radical of an ideal `I` in a similar way,\nas the intersection of maximal ideals containing `I`.\n\n## Main definitions\n\nLet `R` be a commutative ring, and `I` be an ideal of `R`\n\n* `jacobson I` is the jacobson radical, i.e. the infimum of all maximal ideals containing I.\n\n* `is_local I` is the proposition that the jacobson radical of `I` is itself a maximal ideal\n\n## Main statements\n\n* `mem_jacobson_iff` gives a characterization of members of the jacobson of I\n\n* `is_local_of_is_maximal_radical`: if the radical of I is maximal then so is the jacobson radical\n\n## Tags\n\nJacobson, Jacobson radical, Local Ideal\n\n-/\n\nuniverses u v\n\nnamespace ideal\nvariables {R : Type u} [comm_ring R] {I : ideal R}\nvariables {S : Type v} [comm_ring S]\nopen_locale polynomial\n\nsection jacobson\n\n/-- The Jacobson radical of `I` is the infimum of all maximal ideals containing `I`. -/\ndef jacobson (I : ideal R) : ideal R :=\nInf {J : ideal R | I \u2264 J \u2227 is_maximal J}\n\nlemma le_jacobson : I \u2264 jacobson I :=\n\u03bb x hx, mem_Inf.mpr (\u03bb J hJ, hJ.left hx)\n\n@[simp] lemma jacobson_idem : jacobson (jacobson I) = jacobson I :=\nle_antisymm (Inf_le_Inf (\u03bb J hJ, \u27e8Inf_le hJ, hJ.2\u27e9)) le_jacobson\n\nlemma radical_le_jacobson : radical I \u2264 jacobson I :=\nle_Inf (\u03bb J hJ, (radical_eq_Inf I).symm \u25b8 Inf_le \u27e8hJ.left, is_maximal.is_prime hJ.right\u27e9)\n\nlemma eq_radical_of_eq_jacobson : jacobson I = I \u2192 radical I = I :=\n\u03bb h, le_antisymm (le_trans radical_le_jacobson (le_of_eq h)) le_radical\n\n@[simp] lemma jacobson_top : jacobson (\u22a4 : ideal R) = \u22a4 :=\neq_top_iff.2 le_jacobson\n\n@[simp] theorem jacobson_eq_top_iff : jacobson I = \u22a4 \u2194 I = \u22a4 :=\n\u27e8\u03bb H, classical.by_contradiction $ \u03bb hi, let \u27e8M, hm, him\u27e9 := exists_le_maximal I hi in\n  lt_top_iff_ne_top.1\n    (lt_of_le_of_lt (show jacobson I \u2264 M, from Inf_le \u27e8him, hm\u27e9) $\n      lt_top_iff_ne_top.2 hm.ne_top) H,\n\u03bb H, eq_top_iff.2 $ le_Inf $ \u03bb J \u27e8hij, hj\u27e9, H \u25b8 hij\u27e9\n\nlemma jacobson_eq_bot : jacobson I = \u22a5 \u2192 I = \u22a5 :=\n\u03bb h, eq_bot_iff.mpr (h \u25b8 le_jacobson)\n\nlemma jacobson_eq_self_of_is_maximal [H : is_maximal I] : I.jacobson = I :=\nle_antisymm (Inf_le \u27e8le_of_eq rfl, H\u27e9) le_jacobson\n\n@[priority 100]\ninstance jacobson.is_maximal [H : is_maximal I] : is_maximal (jacobson I) :=\n\u27e8\u27e8\u03bb htop, H.1.1 (jacobson_eq_top_iff.1 htop),\n  \u03bb J hJ, H.1.2 _ (lt_of_le_of_lt le_jacobson hJ)\u27e9\u27e9\n\ntheorem mem_jacobson_iff {x : R} : x \u2208 jacobson I \u2194 \u2200 y, \u2203 z, x * y * z + z - 1 \u2208 I :=\n\u27e8\u03bb hx y, classical.by_cases\n  (assume hxy : I \u2294 span {x * y + 1} = \u22a4,\n    let \u27e8p, hpi, q, hq, hpq\u27e9 := submodule.mem_sup.1 ((eq_top_iff_one _).1 hxy) in\n    let \u27e8r, hr\u27e9 := mem_span_singleton.1 hq in\n    \u27e8r, by rw [\u2190 one_mul r, \u2190 mul_assoc, \u2190 add_mul, mul_one, \u2190 hr, \u2190 hpq, \u2190 neg_sub,\n               add_sub_cancel]; exact I.neg_mem hpi\u27e9)\n  (assume hxy : I \u2294 span {x * y + 1} \u2260 \u22a4,\n    let \u27e8M, hm1, hm2\u27e9 := exists_le_maximal _ hxy in\n    suffices x \u2209 M, from (this $ mem_Inf.1 hx \u27e8le_trans le_sup_left hm2, hm1\u27e9).elim,\n    \u03bb hxm, hm1.1.1 $ (eq_top_iff_one _).2 $ add_sub_cancel' (x * y) 1 \u25b8 M.sub_mem\n      (le_sup_right.trans hm2 $ mem_span_singleton.2 dvd_rfl)\n      (M.mul_mem_right _ hxm)),\n\u03bb hx, mem_Inf.2 $ \u03bb M \u27e8him, hm\u27e9, classical.by_contradiction $ \u03bb hxm,\n  let \u27e8y, hy\u27e9 := hm.exists_inv hxm, \u27e8z, hz\u27e9 := hx (-y) in\n  hm.1.1 $ (eq_top_iff_one _).2 $ sub_sub_cancel (x * -y * z + z) 1 \u25b8 M.sub_mem\n    (by { rw [\u2190 one_mul z, \u2190 mul_assoc, \u2190 add_mul, mul_one, mul_neg, neg_add_eq_sub,\n        \u2190 neg_sub, neg_mul, neg_mul_eq_mul_neg, mul_comm x y, mul_comm _ (- z)],\n      rcases hy with \u27e8i, hi, df\u27e9,\n      rw [\u2190 (sub_eq_iff_eq_add.mpr df.symm), sub_sub, add_comm, \u2190 sub_sub, sub_self, zero_sub],\n      refine M.mul_mem_left (-z) ((neg_mem_iff _).mpr hi) }) (him hz)\u27e9\n\nlemma exists_mul_sub_mem_of_sub_one_mem_jacobson {I : ideal R} (r : R)\n  (h : r - 1 \u2208 jacobson I) : \u2203 s, r * s - 1 \u2208 I :=\nbegin\n  cases mem_jacobson_iff.1 h 1 with s hs,\n  use s,\n  simpa [sub_mul] using hs\nend\n\nlemma is_unit_of_sub_one_mem_jacobson_bot (r : R)\n  (h : r - 1 \u2208 jacobson (\u22a5 : ideal R)) : is_unit r :=\nbegin\n  cases exists_mul_sub_mem_of_sub_one_mem_jacobson r h with s hs,\n  rw [mem_bot, sub_eq_zero] at hs,\n  exact is_unit_of_mul_eq_one _ _ hs\nend\n\n/-- An ideal equals its Jacobson radical iff it is the intersection of a set of maximal ideals.\nAllowing the set to include \u22a4 is equivalent, and is included only to simplify some proofs. -/\ntheorem eq_jacobson_iff_Inf_maximal :\n  I.jacobson = I \u2194 \u2203 M : set (ideal R), (\u2200 J \u2208 M, is_maximal J \u2228 J = \u22a4) \u2227 I = Inf M :=\nbegin\n  use \u03bb hI, \u27e8{J : ideal R | I \u2264 J \u2227 J.is_maximal}, \u27e8\u03bb _ hJ, or.inl hJ.right, hI.symm\u27e9\u27e9,\n  rintros \u27e8M, hM, hInf\u27e9,\n  refine le_antisymm (\u03bb x hx, _) le_jacobson,\n  rw [hInf, mem_Inf],\n  intros I hI,\n  cases hM I hI with is_max is_top,\n  { exact (mem_Inf.1 hx) \u27e8le_Inf_iff.1 (le_of_eq hInf) I hI, is_max\u27e9 },\n  { exact is_top.symm \u25b8 submodule.mem_top }\nend\n\ntheorem eq_jacobson_iff_Inf_maximal' :\n  I.jacobson = I \u2194 \u2203 M : set (ideal R), (\u2200 (J \u2208 M) (K : ideal R), J < K \u2192 K = \u22a4) \u2227 I = Inf M :=\neq_jacobson_iff_Inf_maximal.trans\n  \u27e8\u03bb h, let \u27e8M, hM\u27e9 := h in \u27e8M, \u27e8\u03bb J hJ K hK, or.rec_on (hM.1 J hJ) (\u03bb h, h.1.2 K hK)\n    (\u03bb h, eq_top_iff.2 (le_of_lt (h \u25b8 hK))), hM.2\u27e9\u27e9,\n  \u03bb h, let \u27e8M, hM\u27e9 := h in \u27e8M, \u27e8\u03bb J hJ, or.rec_on (classical.em (J = \u22a4)) (\u03bb h, or.inr h)\n    (\u03bb h, or.inl \u27e8\u27e8h, hM.1 J hJ\u27e9\u27e9), hM.2\u27e9\u27e9\u27e9\n\n/-- An ideal `I` equals its Jacobson radical if and only if every element outside `I`\nalso lies outside of a maximal ideal containing `I`. -/\nlemma eq_jacobson_iff_not_mem :\n  I.jacobson = I \u2194 \u2200 x \u2209 I, \u2203 M : ideal R, (I \u2264 M \u2227 M.is_maximal) \u2227 x \u2209 M :=\nbegin\n  split,\n  { intros h x hx,\n    erw [\u2190 h, mem_Inf] at hx,\n    push_neg at hx,\n    exact hx },\n  { refine \u03bb h, le_antisymm (\u03bb x hx, _) le_jacobson,\n    contrapose hx,\n    erw mem_Inf,\n    push_neg,\n    exact h x hx }\nend\n\ntheorem map_jacobson_of_surjective {f : R \u2192+* S} (hf : function.surjective f) :\n  ring_hom.ker f \u2264 I \u2192 map f (I.jacobson) = (map f I).jacobson :=\nbegin\n  intro h,\n  unfold ideal.jacobson,\n  have : \u2200 J \u2208 {J : ideal R | I \u2264 J \u2227 J.is_maximal}, f.ker \u2264 J := \u03bb J hJ, le_trans h hJ.left,\n  refine trans (map_Inf hf this) (le_antisymm _ _),\n  { refine Inf_le_Inf (\u03bb J hJ, \u27e8comap f J, \u27e8\u27e8le_comap_of_map_le hJ.1, _\u27e9,\n    map_comap_of_surjective f hf J\u27e9\u27e9),\n    haveI : J.is_maximal := hJ.right,\n    exact comap_is_maximal_of_surjective f hf },\n  { refine Inf_le_Inf_of_subset_insert_top (\u03bb j hj, hj.rec_on (\u03bb J hJ, _)),\n    rw \u2190 hJ.2,\n    cases map_eq_top_or_is_maximal_of_surjective f hf hJ.left.right with htop hmax,\n    { exact htop.symm \u25b8 set.mem_insert \u22a4 _ },\n    { exact set.mem_insert_of_mem \u22a4 \u27e8map_mono hJ.1.1, hmax\u27e9 } },\nend\n\nlemma map_jacobson_of_bijective {f : R \u2192+* S} (hf : function.bijective f) :\n  map f (I.jacobson) = (map f I).jacobson :=\nmap_jacobson_of_surjective hf.right\n  (le_trans (le_of_eq (f.injective_iff_ker_eq_bot.1 hf.left)) bot_le)\n\nlemma comap_jacobson {f : R \u2192+* S} {K : ideal S} :\n  comap f (K.jacobson) = Inf (comap f '' {J : ideal S | K \u2264 J \u2227 J.is_maximal}) :=\ntrans (comap_Inf' f _) (Inf_eq_infi).symm\n\ntheorem comap_jacobson_of_surjective {f : R \u2192+* S} (hf : function.surjective f) {K : ideal S} :\n  comap f (K.jacobson) = (comap f K).jacobson :=\nbegin\n  unfold ideal.jacobson,\n  refine le_antisymm _ _,\n  { refine le_trans (comap_mono (le_of_eq (trans top_inf_eq.symm Inf_insert.symm))) _,\n    rw [comap_Inf', Inf_eq_infi],\n    refine infi_le_infi_of_subset (\u03bb J hJ, _),\n    have : comap f (map f J) = J := trans (comap_map_of_surjective f hf J)\n      (le_antisymm (sup_le_iff.2 \u27e8le_of_eq rfl, le_trans (comap_mono bot_le) hJ.left\u27e9) le_sup_left),\n    cases map_eq_top_or_is_maximal_of_surjective _ hf hJ.right with htop hmax,\n    { refine \u27e8\u22a4, \u27e8set.mem_insert \u22a4 _, htop \u25b8 this\u27e9\u27e9 },\n    { refine \u27e8map f J, \u27e8set.mem_insert_of_mem _\n        \u27e8le_map_of_comap_le_of_surjective f hf hJ.1, hmax\u27e9, this\u27e9\u27e9 } },\n  { rw comap_Inf,\n    refine le_infi_iff.2 (\u03bb J, (le_infi_iff.2 (\u03bb hJ, _))),\n    haveI : J.is_maximal := hJ.right,\n    refine Inf_le \u27e8comap_mono hJ.left, comap_is_maximal_of_surjective _ hf\u27e9 }\nend\n\nlemma mem_jacobson_bot {x : R} : x \u2208 jacobson (\u22a5 : ideal R) \u2194 \u2200 y, is_unit (x * y + 1) :=\n\u27e8\u03bb hx y, let \u27e8z, hz\u27e9 := (mem_jacobson_iff.1 hx) y in\n  is_unit_iff_exists_inv.2 \u27e8z, by rwa [add_mul, one_mul, \u2190 sub_eq_zero]\u27e9,\n\u03bb h, mem_jacobson_iff.mpr (\u03bb y, (let \u27e8b, hb\u27e9 := is_unit_iff_exists_inv.1 (h y) in\n  \u27e8b, (submodule.mem_bot R).2 (hb \u25b8 (by ring))\u27e9))\u27e9\n\n/-- An ideal `I` of `R` is equal to its Jacobson radical if and only if\nthe Jacobson radical of the quotient ring `R/I` is the zero ideal -/\ntheorem jacobson_eq_iff_jacobson_quotient_eq_bot :\n  I.jacobson = I \u2194 jacobson (\u22a5 : ideal (R \u29f8 I)) = \u22a5 :=\nbegin\n  have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I,\n  split,\n  { intro h,\n    replace h := congr_arg (map (quotient.mk I)) h,\n    rw map_jacobson_of_surjective hf (le_of_eq mk_ker) at h,\n    simpa using h },\n  { intro h,\n    replace h := congr_arg (comap (quotient.mk I)) h,\n    rw [comap_jacobson_of_surjective hf, \u2190 (quotient.mk I).ker_eq_comap_bot] at h,\n    simpa using h }\nend\n\n/-- The standard radical and Jacobson radical of an ideal `I` of `R` are equal if and only if\nthe nilradical and Jacobson radical of the quotient ring `R/I` coincide -/\ntheorem radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot :\n  I.radical = I.jacobson \u2194 radical (\u22a5 : ideal (R \u29f8 I)) = jacobson \u22a5 :=\nbegin\n  have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I,\n  split,\n  { intro h,\n    have := congr_arg (map (quotient.mk I)) h,\n    rw [map_radical_of_surjective hf (le_of_eq mk_ker),\n      map_jacobson_of_surjective hf (le_of_eq mk_ker)] at this,\n    simpa using this },\n  { intro h,\n    have := congr_arg (comap (quotient.mk I)) h,\n    rw [comap_radical, comap_jacobson_of_surjective hf, \u2190 (quotient.mk I).ker_eq_comap_bot] at this,\n    simpa using this }\nend\n\n@[mono] lemma jacobson_mono {I J : ideal R} : I \u2264 J \u2192 I.jacobson \u2264 J.jacobson :=\nbegin\n  intros h x hx,\n  erw mem_Inf at \u22a2 hx,\n  exact \u03bb K \u27e8hK, hK_max\u27e9, hx \u27e8trans h hK, hK_max\u27e9\nend\n\nlemma jacobson_radical_eq_jacobson :\n  I.radical.jacobson = I.jacobson :=\nle_antisymm (le_trans (le_of_eq (congr_arg jacobson (radical_eq_Inf I)))\n  (Inf_le_Inf (\u03bb J hJ, \u27e8Inf_le \u27e8hJ.1, hJ.2.is_prime\u27e9, hJ.2\u27e9))) (jacobson_mono le_radical)\n\nend jacobson\n\nsection polynomial\nopen polynomial\n\nlemma jacobson_bot_polynomial_le_Inf_map_maximal :\n  jacobson (\u22a5 : ideal R[X]) \u2264 Inf (map C '' {J : ideal R | J.is_maximal}) :=\nbegin\n  refine le_Inf (\u03bb J, exists_imp_distrib.2 (\u03bb j hj, _)),\n  haveI : j.is_maximal := hj.1,\n  refine trans (jacobson_mono bot_le) (le_of_eq _ : J.jacobson \u2264 J),\n  suffices : (\u22a5 : ideal (polynomial (R \u29f8 j))).jacobson = \u22a5,\n  { rw [\u2190 hj.2, jacobson_eq_iff_jacobson_quotient_eq_bot],\n    replace this :=\n    congr_arg (map (polynomial_quotient_equiv_quotient_polynomial j).to_ring_hom) this,\n    rwa [map_jacobson_of_bijective _, map_bot] at this,\n    exact (ring_equiv.bijective (polynomial_quotient_equiv_quotient_polynomial j)) },\n  refine eq_bot_iff.2 (\u03bb f hf, _),\n  simpa [(\u03bb hX, by simpa using congr_arg (\u03bb f, coeff f 1) hX : (X : (R \u29f8 j)[X]) \u2260 0)]\n    using eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit ((mem_jacobson_bot.1 hf) X)),\nend\n\nlemma jacobson_bot_polynomial_of_jacobson_bot (h : jacobson (\u22a5 : ideal R) = \u22a5) :\n  jacobson (\u22a5 : ideal R[X]) = \u22a5 :=\nbegin\n  refine eq_bot_iff.2 (le_trans jacobson_bot_polynomial_le_Inf_map_maximal _),\n  refine (\u03bb f hf, ((submodule.mem_bot _).2 (polynomial.ext (\u03bb n, trans _ (coeff_zero n).symm)))),\n  suffices : f.coeff n \u2208 ideal.jacobson \u22a5, by rwa [h, submodule.mem_bot] at this,\n  exact mem_Inf.2 (\u03bb j hj, (mem_map_C_iff.1 ((mem_Inf.1 hf) \u27e8j, \u27e8hj.2, rfl\u27e9\u27e9)) n),\nend\n\nend polynomial\n\nsection is_local\n\n/-- An ideal `I` is local iff its Jacobson radical is maximal. -/\nclass is_local (I : ideal R) : Prop := (out : is_maximal (jacobson I))\n\ntheorem is_local_iff {I : ideal R} : is_local I \u2194 is_maximal (jacobson I) :=\n\u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\ntheorem is_local_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) : is_local I :=\n\u27e8have radical I = jacobson I,\nfrom le_antisymm (le_Inf $ \u03bb M \u27e8him, hm\u27e9, hm.is_prime.radical_le_iff.2 him)\n  (Inf_le \u27e8le_radical, hi\u27e9),\nshow is_maximal (jacobson I), from this \u25b8 hi\u27e9\n\ntheorem is_local.le_jacobson {I J : ideal R} (hi : is_local I) (hij : I \u2264 J) (hj : J \u2260 \u22a4) :\n  J \u2264 jacobson I :=\nlet \u27e8M, hm, hjm\u27e9 := exists_le_maximal J hj in\nle_trans hjm $ le_of_eq $ eq.symm $ hi.1.eq_of_le hm.1.1 $ Inf_le \u27e8le_trans hij hjm, hm\u27e9\n\ntheorem is_local.mem_jacobson_or_exists_inv {I : ideal R} (hi : is_local I) (x : R) :\n  x \u2208 jacobson I \u2228 \u2203 y, y * x - 1 \u2208 I :=\nclassical.by_cases\n  (assume h : I \u2294 span {x} = \u22a4,\n    let \u27e8p, hpi, q, hq, hpq\u27e9 := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in\n    let \u27e8r, hr\u27e9 := mem_span_singleton.1 hq in\n    or.inr \u27e8r, by rw [\u2190 hpq, mul_comm, \u2190 hr, \u2190 neg_sub, add_sub_cancel]; exact I.neg_mem hpi\u27e9)\n  (assume h : I \u2294 span {x} \u2260 \u22a4,\n    or.inl $ le_trans le_sup_right (hi.le_jacobson le_sup_left h) $ mem_span_singleton.2 $\n      dvd_refl x)\n\nend is_local\n\ntheorem is_primary_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) :\n  is_primary I :=\nhave radical I = jacobson I,\nfrom le_antisymm (le_Inf $ \u03bb M \u27e8him, hm\u27e9, hm.is_prime.radical_le_iff.2 him)\n  (Inf_le \u27e8le_radical, hi\u27e9),\n\u27e8ne_top_of_lt $ lt_of_le_of_lt le_radical (lt_top_iff_ne_top.2 hi.1.1),\n\u03bb x y hxy, ((is_local_of_is_maximal_radical hi).mem_jacobson_or_exists_inv y).symm.imp\n  (\u03bb \u27e8z, hz\u27e9, by rw [\u2190 mul_one x, \u2190 sub_sub_cancel (z * y) 1, mul_sub, mul_left_comm]; exact\n    I.sub_mem (I.mul_mem_left _ hxy) (I.mul_mem_left _ hz))\n  (this \u25b8 id)\u27e9\n\n\nend ideal\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/jacobson_ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768108626046, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.712927994777583}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin, Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Damiano Testa\n-/\nimport order.basic\nimport data.equiv.basic\n\n/-!\n# Initial lemmas to work with the `order_dual`\n\n## Definitions\n`to_dual` and `of_dual` the order reversing identity maps, bundled as equivalences.\n\n## Basic Lemmas to convert between an order and its dual\n\nThis file is similar to algebra/group/type_tags.lean\n-/\n\nopen function\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nnamespace order_dual\n\ninstance [nontrivial \u03b1] : nontrivial (order_dual \u03b1) := by delta order_dual; assumption\n\n/-- `to_dual` is the identity function to the `order_dual` of a linear order.  -/\ndef to_dual : \u03b1 \u2243 order_dual \u03b1 := \u27e8id, id, \u03bb h, rfl, \u03bb h, rfl\u27e9\n\n/-- `of_dual` is the identity function from the `order_dual` of a linear order.  -/\ndef of_dual : order_dual \u03b1 \u2243 \u03b1 := to_dual.symm\n\n@[simp] lemma to_dual_symm_eq : (@to_dual \u03b1).symm = of_dual := rfl\n\n@[simp] lemma of_dual_symm_eq : (@of_dual \u03b1).symm = to_dual := rfl\n\n@[simp] lemma to_dual_of_dual (a : order_dual \u03b1) : to_dual (of_dual a) = a := rfl\n@[simp] lemma of_dual_to_dual (a : \u03b1) : of_dual (to_dual a) = a := rfl\n\n@[simp] lemma to_dual_inj {a b : \u03b1} :\n  to_dual a = to_dual b \u2194 a = b := iff.rfl\n\n@[simp] lemma to_dual_le_to_dual [has_le \u03b1] {a b : \u03b1} :\n  to_dual a \u2264 to_dual b \u2194 b \u2264 a := iff.rfl\n\n@[simp] lemma to_dual_lt_to_dual [has_lt \u03b1] {a b : \u03b1} :\n  to_dual a < to_dual b \u2194 b < a := iff.rfl\n\n@[simp] lemma of_dual_inj {a b : order_dual \u03b1} :\n  of_dual a = of_dual b \u2194 a = b := iff.rfl\n\n@[simp] lemma of_dual_le_of_dual [has_le \u03b1] {a b : order_dual \u03b1} :\n  of_dual a \u2264 of_dual b \u2194 b \u2264 a := iff.rfl\n\n@[simp] lemma of_dual_lt_of_dual [has_lt \u03b1] {a b : order_dual \u03b1} :\n  of_dual a < of_dual b \u2194 b < a := iff.rfl\n\nlemma le_to_dual [has_le \u03b1] {a : order_dual \u03b1} {b : \u03b1} :\n  a \u2264 to_dual b \u2194 b \u2264 of_dual a := iff.rfl\n\nlemma lt_to_dual [has_lt \u03b1] {a : order_dual \u03b1} {b : \u03b1} :\n  a < to_dual b \u2194 b < of_dual a := iff.rfl\n\nlemma to_dual_le [has_le \u03b1] {a : \u03b1} {b : order_dual \u03b1} :\n  to_dual a \u2264 b \u2194 of_dual b \u2264 a := iff.rfl\n\nlemma to_dual_lt [has_lt \u03b1] {a : \u03b1} {b : order_dual \u03b1} :\n  to_dual a < b \u2194 of_dual b < a := iff.rfl\n\nend order_dual\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/order_dual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7129279922245505}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport tactic.ring_exp\nimport topology.metric_space.hausdorff_distance\n\n/-!\n# Topological study of spaces `\u03a0 (n : \u2115), E n`\n\nWhen `E n` are topological spaces, the space `\u03a0 (n : \u2115), E n` is naturally a topological space\n(with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure.\nHowever, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one\ncan put a noncanonical metric space structure (or rather, several of them). This is done in this\nfile.\n\n## Main definitions and results\n\nOne can define a combinatorial distance on `\u03a0 (n : \u2115), E n`, as follows:\n\n* `pi_nat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`.\n* `pi_nat.first_diff x y` is the first index at which `x i \u2260 y i`.\n* `pi_nat.dist x y` is equal to `(1/2) ^ (first_diff x y)`. It defines a distance\n  on `\u03a0 (n : \u2115), E n`, compatible with the topology when the `E n` have the discrete topology.\n* `pi_nat.metric_space`: the metric space structure, given by this distance. Not registered as an\n  instance. This space is a complete metric space.\n* `pi_nat.metric_space_of_discrete_uniformity`: the same metric space structure, but adjusting the\n  uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an\n  instance\n* `pi_nat.metric_space_nat_nat`: the particular case of `\u2115 \u2192 \u2115`, not registered as an instance.\n\nThese results are used to construct continuous functions on `\u03a0 n, E n`:\n\n* `pi_nat.exists_retraction_of_is_closed`: given a nonempty closed subset `s` of `\u03a0 (n : \u2115), E n`,\n  there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s`\n  restricting to the identity on `s`.\n* `exists_nat_nat_continuous_surjective_of_complete_space`: given any nonempty complete metric\n  space with second-countable topology, there exists a continuous surjection from `\u2115 \u2192 \u2115` onto\n  this space.\n\nOne can also put distances on `\u03a0 (i : \u03b9), E i` when the spaces `E i` are metric spaces (not discrete\nin general), and `\u03b9` is countable.\n\n* `pi_countable.dist` is the distance on `\u03a0 i, E i` given by\n    `dist x y = \u2211' i, min (1/2)^(encode i) (dist (x i) (y i))`.\n* `pi_countable.metric_space` is the corresponding metric space structure, adjusted so that\n  the uniformity is definitionally the product uniformity. Not registered as an instance.\n-/\n\nnoncomputable theory\nopen_locale classical topology filter\nopen topological_space set metric filter function\n\nlocal attribute [simp] pow_le_pow_iff one_lt_two inv_le_inv\n\nvariable {E : \u2115 \u2192 Type*}\n\nnamespace pi_nat\n\n/-! ### The first_diff function -/\n\n/-- In a product space `\u03a0 n, E n`, then `first_diff x y` is the first index at which `x` and `y`\ndiffer. If `x = y`, then by convention we set `first_diff x x = 0`. -/\n@[irreducible, pp_nodot] def first_diff (x y : \u03a0 n, E n) : \u2115 :=\nif h : x \u2260 y then nat.find (ne_iff.1 h) else 0\n\nlemma apply_first_diff_ne {x y : \u03a0 n, E n} (h : x \u2260 y) :\n  x (first_diff x y) \u2260 y (first_diff x y) :=\nbegin\n  rw [first_diff, dif_pos h],\n  exact nat.find_spec (ne_iff.1 h),\nend\n\nlemma apply_eq_of_lt_first_diff {x y : \u03a0 n, E n} {n : \u2115} (hn : n < first_diff x y) :\n  x n = y n :=\nbegin\n  rw first_diff at hn,\n  split_ifs at hn,\n  { convert nat.find_min (ne_iff.1 h) hn,\n    simp },\n  { exact (not_lt_zero' hn).elim }\nend\n\nlemma first_diff_comm (x y : \u03a0 n, E n) :\n  first_diff x y = first_diff y x :=\nbegin\n  rcases eq_or_ne x y with rfl|hxy, { refl },\n  rcases lt_trichotomy (first_diff x y) (first_diff y x) with h|h|h,\n  { exact (apply_first_diff_ne hxy (apply_eq_of_lt_first_diff h).symm).elim },\n  { exact h },\n  { exact (apply_first_diff_ne hxy.symm (apply_eq_of_lt_first_diff h).symm).elim }\nend\n\nlemma min_first_diff_le (x y z : \u03a0 n, E n) (h : x \u2260 z) :\n  min (first_diff x y) (first_diff y z) \u2264 first_diff x z :=\nbegin\n  by_contra' H,\n  have : x (first_diff x z) = z (first_diff x z), from calc\n    x (first_diff x z) = y (first_diff x z) :\n      apply_eq_of_lt_first_diff (H.trans_le (min_le_left _ _))\n    ... = z ((first_diff x z)) : apply_eq_of_lt_first_diff (H.trans_le (min_le_right _ _)),\n  exact (apply_first_diff_ne h this).elim,\nend\n\n/-! ### Cylinders -/\n\n/-- In a product space `\u03a0 n, E n`, the cylinder set of length `n` around `x`, denoted\n`cylinder x n`, is the set of sequences `y` that coincide with `x` on the first `n` symbols, i.e.,\nsuch that `y i = x i` for all `i < n`.\n-/\ndef cylinder (x : \u03a0 n, E n) (n : \u2115) : set (\u03a0 n, E n) :=\n{y | \u2200 i, i < n \u2192 y i = x i}\n\nlemma cylinder_eq_pi (x : \u03a0 n, E n) (n : \u2115) :\n  cylinder x n = set.pi (finset.range n : set \u2115) (\u03bb (i : \u2115), {x i}) :=\nby { ext y, simp [cylinder] }\n\n@[simp] lemma cylinder_zero (x : \u03a0 n, E n) : cylinder x 0 = univ :=\nby simp [cylinder_eq_pi]\n\nlemma cylinder_anti (x : \u03a0 n, E n) {m n : \u2115} (h : m \u2264 n) : cylinder x n \u2286 cylinder x m :=\n\u03bb y hy i hi, hy i (hi.trans_le h)\n\n@[simp] lemma mem_cylinder_iff {x y : \u03a0 n, E n} {n : \u2115} :\n  y \u2208 cylinder x n \u2194 \u2200 i, i < n \u2192 y i = x i :=\niff.rfl\n\nlemma self_mem_cylinder (x : \u03a0 n, E n) (n : \u2115) :\n  x \u2208 cylinder x n :=\nby simp\n\nlemma mem_cylinder_iff_eq {x y : \u03a0 n, E n} {n : \u2115} :\n  y \u2208 cylinder x n \u2194 cylinder y n = cylinder x n :=\nbegin\n  split,\n  { assume hy,\n    apply subset.antisymm,\n    { assume z hz i hi,\n      rw \u2190 hy i hi,\n      exact hz i hi },\n    { assume z hz i hi,\n      rw hy i hi,\n      exact hz i hi } },\n  { assume h,\n    rw \u2190 h,\n    exact self_mem_cylinder _ _ }\nend\n\nlemma mem_cylinder_comm (x y : \u03a0 n, E n) (n : \u2115) :\n  y \u2208 cylinder x n \u2194 x \u2208 cylinder y n :=\nby simp [mem_cylinder_iff_eq, eq_comm]\n\nlemma mem_cylinder_iff_le_first_diff {x y : \u03a0 n, E n} (hne : x \u2260 y) (i : \u2115) :\n  x \u2208 cylinder y i \u2194 i \u2264 first_diff x y :=\nbegin\n  split,\n  { assume h,\n    by_contra',\n    exact apply_first_diff_ne hne (h _ this) },\n  { assume hi j hj,\n    exact apply_eq_of_lt_first_diff (hj.trans_le hi) }\nend\n\nlemma mem_cylinder_first_diff (x y : \u03a0 n, E n) :\n  x \u2208 cylinder y (first_diff x y) :=\n\u03bb i hi, apply_eq_of_lt_first_diff hi\n\nlemma cylinder_eq_cylinder_of_le_first_diff (x y : \u03a0 n, E n) {n : \u2115} (hn : n \u2264 first_diff x y) :\n  cylinder x n = cylinder y n :=\nbegin\n  rw \u2190 mem_cylinder_iff_eq,\n  assume i hi,\n  exact apply_eq_of_lt_first_diff (hi.trans_le hn),\nend\n\nlemma Union_cylinder_update (x : \u03a0 n, E n) (n : \u2115) :\n  (\u22c3 k, cylinder (update x n k) (n+1)) = cylinder x n :=\nbegin\n  ext y,\n  simp only [mem_cylinder_iff, mem_Union],\n  split,\n  { rintros \u27e8k, hk\u27e9 i hi,\n    simpa [hi.ne] using hk i (nat.lt_succ_of_lt hi) },\n  { assume H,\n    refine \u27e8y n, \u03bb i hi, _\u27e9,\n    rcases nat.lt_succ_iff_lt_or_eq.1 hi with h'i|rfl,\n    { simp [H i h'i, h'i.ne] },\n    { simp } },\nend\n\n\n\n/-!\n### A distance function on `\u03a0 n, E n`\n\nWe define a distance function on `\u03a0 n, E n`, given by `dist x y = (1/2)^n` where `n` is the first\nindex at which `x` and `y` differ. When each `E n` has the discrete topology, this distance will\ndefine the right topology on the product space. We do not record a global `has_dist` instance nor\na `metric_space`instance, as other distances may be used on these spaces, but we register them as\nlocal instances in this section.\n-/\n\n/-- The distance function on a product space `\u03a0 n, E n`, given by `dist x y = (1/2)^n` where `n` is\nthe first index at which `x` and `y` differ. -/\nprotected def has_dist : has_dist (\u03a0 n, E n) :=\n\u27e8\u03bb x y, if h : x \u2260 y then (1/2 : \u211d) ^ (first_diff x y) else 0\u27e9\n\nlocal attribute [instance] pi_nat.has_dist\n\nlemma dist_eq_of_ne {x y : \u03a0 n, E n} (h : x \u2260 y) :\n  dist x y = (1/2 : \u211d) ^ (first_diff x y) :=\nby simp [dist, h]\n\nprotected lemma dist_self (x : \u03a0 n, E n) : dist x x = 0 :=\nby simp [dist]\n\nprotected lemma dist_comm (x y : \u03a0 n, E n) : dist x y = dist y x :=\nby simp [dist, @eq_comm _ x y, first_diff_comm]\n\nprotected lemma dist_nonneg (x y : \u03a0 n, E n) : 0 \u2264 dist x y :=\nbegin\n  rcases eq_or_ne x y with rfl|h,\n  { simp [dist] },\n  { simp [dist, h] }\nend\n\nlemma dist_triangle_nonarch (x y z : \u03a0 n, E n) :\n  dist x z \u2264 max (dist x y) (dist y z) :=\nbegin\n  rcases eq_or_ne x z with rfl|hxz,\n  { simp [pi_nat.dist_self x, pi_nat.dist_nonneg] },\n  rcases eq_or_ne x y with rfl|hxy,\n  { simp },\n  rcases eq_or_ne y z with rfl|hyz,\n  { simp },\n  simp only [dist_eq_of_ne, hxz, hxy, hyz, inv_le_inv, one_div, inv_pow, zero_lt_bit0,\n    ne.def, not_false_iff, le_max_iff, zero_lt_one, pow_le_pow_iff, one_lt_two, pow_pos,\n    min_le_iff.1 (min_first_diff_le x y z hxz)],\nend\n\nprotected lemma dist_triangle (x y z : \u03a0 n, E n) :\n  dist x z \u2264 dist x y + dist y z :=\ncalc dist x z \u2264 max (dist x y) (dist y z) :\n  dist_triangle_nonarch x y z\n... \u2264 dist x y + dist y z :\n  max_le_add_of_nonneg (pi_nat.dist_nonneg _ _) (pi_nat.dist_nonneg _ _)\n\nprotected lemma eq_of_dist_eq_zero (x y : \u03a0 n, E n) (hxy : dist x y = 0) : x = y :=\nbegin\n  rcases eq_or_ne x y with rfl|h, { refl },\n  simp [dist_eq_of_ne h] at hxy,\n  exact (two_ne_zero (pow_eq_zero hxy)).elim\nend\n\nlemma mem_cylinder_iff_dist_le {x y : \u03a0 n, E n} {n : \u2115} :\n  y \u2208 cylinder x n \u2194 dist y x \u2264 (1/2)^n :=\nbegin\n  rcases eq_or_ne y x with rfl|hne, { simp [pi_nat.dist_self] },\n  suffices : (\u2200 (i : \u2115), i < n \u2192 y i = x i) \u2194 n \u2264 first_diff y x,\n    by simpa [dist_eq_of_ne hne],\n  split,\n  { assume hy,\n    by_contra' H,\n    exact apply_first_diff_ne hne (hy _ H) },\n  { assume h i hi,\n    exact apply_eq_of_lt_first_diff (hi.trans_le h) }\nend\n\nlemma apply_eq_of_dist_lt {x y : \u03a0 n, E n} {n : \u2115} (h : dist x y < (1/2) ^ n) {i : \u2115}\n  (hi : i \u2264 n) :\n  x i = y i :=\nbegin\n  rcases eq_or_ne x y with rfl|hne, { refl },\n  have : n < first_diff x y,\n    by simpa [dist_eq_of_ne hne, inv_lt_inv, pow_lt_pow_iff, one_lt_two] using h,\n  exact apply_eq_of_lt_first_diff (hi.trans_lt this),\nend\n\n/-- A function to a pseudo-metric-space is `1`-Lipschitz if and only if points in the same cylinder\nof length `n` are sent to points within distance `(1/2)^n`.\nNot expressed using `lipschitz_with` as we don't have a metric space structure -/\nlemma lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder\n  {\u03b1 : Type*} [pseudo_metric_space \u03b1] {f : (\u03a0 n, E n) \u2192 \u03b1} :\n  (\u2200 (x y : \u03a0 n, E n), dist (f x) (f y) \u2264 dist x y) \u2194\n    (\u2200 x y n, y \u2208 cylinder x n \u2192 dist (f x) (f y) \u2264 (1/2)^n) :=\nbegin\n  split,\n  { assume H x y n hxy,\n    apply (H x y).trans,\n    rw pi_nat.dist_comm,\n    exact mem_cylinder_iff_dist_le.1 hxy },\n  { assume H x y,\n    rcases eq_or_ne x y with rfl|hne, { simp [pi_nat.dist_nonneg] },\n    rw dist_eq_of_ne hne,\n    apply H x y (first_diff x y),\n    rw first_diff_comm,\n    exact mem_cylinder_first_diff _ _ }\nend\n\nvariables (E) [\u2200 n, topological_space (E n)] [\u2200 n, discrete_topology (E n)]\n\nlemma is_topological_basis_cylinders  :\n  is_topological_basis {s : set (\u03a0 n, E n) | \u2203 (x : \u03a0 n, E n) (n : \u2115), s = cylinder x n} :=\nbegin\n  apply is_topological_basis_of_open_of_nhds,\n  { rintros u \u27e8x, n, rfl\u27e9,\n    rw cylinder_eq_pi,\n    exact is_open_set_pi (finset.range n).finite_to_set (\u03bb a ha, is_open_discrete _) },\n  { assume x u hx u_open,\n    obtain \u27e8v, \u27e8U, F, hUF, rfl\u27e9, xU, Uu\u27e9 : \u2203 (v : set (\u03a0 (i : \u2115), E i))\n      (H : v \u2208 {S : set (\u03a0 (i : \u2115), E i) | \u2203 (U : \u03a0 (i : \u2115), set (E i)) (F : finset \u2115),\n        (\u2200 (i : \u2115), i \u2208 F \u2192 U i \u2208 {s : set (E i) | is_open s}) \u2227 S = (F : set \u2115).pi U}),\n          x \u2208 v \u2227 v \u2286 u :=\n      (is_topological_basis_pi (\u03bb (n : \u2115), is_topological_basis_opens)).exists_subset_of_mem_open\n        hx u_open,\n    rcases finset.bdd_above F with \u27e8n, hn\u27e9,\n    refine \u27e8cylinder x (n+1), \u27e8x, n+1, rfl\u27e9, self_mem_cylinder _ _, subset.trans _ Uu\u27e9,\n    assume y hy,\n    suffices : \u2200 (i : \u2115), i \u2208 F \u2192 y i \u2208 U i, by simpa,\n    assume i hi,\n    have : y i = x i := mem_cylinder_iff.1 hy i ((hn hi).trans_lt (lt_add_one n)),\n    rw this,\n    simp only [set.mem_pi, finset.mem_coe] at xU,\n    exact xU i hi }\nend\n\nvariable {E}\n\nlemma is_open_iff_dist (s : set (\u03a0 n, E n)) :\n  is_open s \u2194 \u2200 x \u2208 s, \u2203 \u03b5 > 0, \u2200 y, dist x y < \u03b5 \u2192 y \u2208 s :=\nbegin\n  split,\n  { assume hs x hx,\n    obtain \u27e8v, \u27e8y, n, rfl\u27e9, h'x, h's\u27e9 : \u2203 (v : set (\u03a0 (n : \u2115), E n))\n      (H : v \u2208 {s | \u2203 (x : \u03a0 (n : \u2115), E n) (n : \u2115), s = cylinder x n}), x \u2208 v \u2227 v \u2286 s :=\n        (is_topological_basis_cylinders E).exists_subset_of_mem_open hx hs,\n    rw \u2190 mem_cylinder_iff_eq.1 h'x at h's,\n    exact \u27e8(1/2 : \u211d)^n, by simp,\n      \u03bb y hy, h's (\u03bb i hi, (apply_eq_of_dist_lt hy hi.le).symm)\u27e9 },\n  { assume h,\n    apply (is_topological_basis_cylinders E).is_open_iff.2 (\u03bb x hx, _),\n    rcases h x hx with \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9,\n    obtain \u27e8n, hn\u27e9 : \u2203 (n : \u2115), (1/2 : \u211d) ^ n < \u03b5 := exists_pow_lt_of_lt_one \u03b5pos one_half_lt_one,\n    refine \u27e8cylinder x n, \u27e8x, n, rfl\u27e9, self_mem_cylinder x n, \u03bb y hy, h\u03b5 y _\u27e9,\n    rw pi_nat.dist_comm,\n    exact (mem_cylinder_iff_dist_le.1 hy).trans_lt hn }\nend\n\n/-- Metric space structure on `\u03a0 (n : \u2115), E n` when the spaces `E n` have the discrete topology,\nwhere the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and\n`y` differ. Not registered as a global instance by default.\nWarning: this definition makes sure that the topology is defeq to the original product topology,\nbut it does not take care of a possible uniformity. If the `E n` have a uniform structure, then\nthere will be two non-defeq uniform structures on `\u03a0 n, E n`, the product one and the one coming\nfrom the metric structure. In this case, use `metric_space_of_discrete_uniformity` instead. -/\nprotected def metric_space : metric_space (\u03a0 n, E n) :=\nmetric_space.of_dist_topology dist pi_nat.dist_self pi_nat.dist_comm pi_nat.dist_triangle\n  is_open_iff_dist pi_nat.eq_of_dist_eq_zero\n\n/-- Metric space structure on `\u03a0 (n : \u2115), E n` when the spaces `E n` have the discrete uniformity,\nwhere the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and\n`y` differ. Not registered as a global instance by default. -/\nprotected def metric_space_of_discrete_uniformity {E : \u2115 \u2192 Type*} [\u2200 n, uniform_space (E n)]\n  (h : \u2200 n, uniformity (E n) = \ud835\udcdf id_rel) : metric_space (\u03a0 n, E n) :=\nbegin\n  haveI : \u2200 n, discrete_topology (E n) := \u03bb n, discrete_topology_of_discrete_uniformity (h n),\n  exact\n  { dist_triangle := pi_nat.dist_triangle,\n    dist_comm := pi_nat.dist_comm,\n    dist_self := pi_nat.dist_self,\n    eq_of_dist_eq_zero := pi_nat.eq_of_dist_eq_zero,\n    to_uniform_space := Pi.uniform_space _,\n    uniformity_dist :=\n    begin\n      simp [Pi.uniformity, comap_infi, gt_iff_lt, preimage_set_of_eq, comap_principal,\n        pseudo_metric_space.uniformity_dist, h, id_rel],\n      apply le_antisymm,\n      { simp only [le_infi_iff, le_principal_iff],\n        assume \u03b5 \u03b5pos,\n        obtain \u27e8n, hn\u27e9 : \u2203 n, (1/2 : \u211d)^n < \u03b5 := exists_pow_lt_of_lt_one \u03b5pos (by norm_num),\n        apply @mem_infi_of_Inter _ _ _ _ _ (finset.range n).finite_to_set\n          (\u03bb i, {p : (\u03a0 (n : \u2115), E n) \u00d7 \u03a0 (n : \u2115), E n | p.fst i = p.snd i}),\n        { simp only [mem_principal, set_of_subset_set_of, imp_self, implies_true_iff] },\n        { rintros \u27e8x, y\u27e9 hxy,\n          simp only [finset.mem_coe, finset.mem_range, Inter_coe_set, mem_Inter, mem_set_of_eq]\n            at hxy,\n          apply lt_of_le_of_lt _ hn,\n          rw [\u2190 mem_cylinder_iff_dist_le, mem_cylinder_iff],\n          exact hxy } },\n      { simp only [le_infi_iff, le_principal_iff],\n        assume n,\n        refine mem_infi_of_mem ((1/2)^n) _,\n        refine mem_infi_of_mem (by positivity) _,\n        simp only [mem_principal, set_of_subset_set_of, prod.forall],\n        assume x y hxy,\n        exact apply_eq_of_dist_lt hxy le_rfl }\n    end }\nend\n\n/-- Metric space structure on `\u2115 \u2192 \u2115` where the distance is given by `dist x y = (1/2)^n`,\nwhere `n` is the smallest index where `x` and `y` differ.\nNot registered as a global instance by default. -/\ndef metric_space_nat_nat : metric_space (\u2115 \u2192 \u2115) :=\npi_nat.metric_space_of_discrete_uniformity (\u03bb n, rfl)\n\nlocal attribute [instance] pi_nat.metric_space\n\nprotected lemma complete_space : complete_space (\u03a0 n, E n) :=\nbegin\n  refine metric.complete_of_convergent_controlled_sequences (\u03bb n, (1/2)^n) (by simp) _,\n  assume u hu,\n  refine \u27e8\u03bb n, u n n, tendsto_pi_nhds.2 (\u03bb i, _)\u27e9,\n  refine tendsto_const_nhds.congr' _,\n  filter_upwards [filter.Ici_mem_at_top i] with n hn,\n  exact apply_eq_of_dist_lt (hu i i n le_rfl hn) le_rfl,\nend\n\n/-!\n### Retractions inside product spaces\n\nWe show that, in a space `\u03a0 (n : \u2115), E n` where each `E n` is discrete, there is a retraction on\nany closed nonempty subset `s`, i.e., a continuous map `f` from the whole space to `s` restricting\nto the identity on `s`. The map `f` is defined as follows. For `x \u2208 s`, let `f x = x`. Otherwise,\nconsider the longest prefix `w` that `x` shares with an element of `s`, and let `f x = z_w`\nwhere `z_w` is an element of `s` starting with `w`.\n-/\n\nlemma exists_disjoint_cylinder {s : set (\u03a0 n, E n)} (hs : is_closed s) {x : \u03a0 n, E n} (hx : x \u2209 s) :\n  \u2203 n, disjoint s (cylinder x n) :=\nbegin\n  unfreezingI { rcases eq_empty_or_nonempty s with rfl|hne },\n  { exact \u27e80, by simp\u27e9 },\n  have A : 0 < inf_dist x s := (hs.not_mem_iff_inf_dist_pos hne).1 hx,\n  obtain \u27e8n, hn\u27e9 : \u2203 n, (1/2 : \u211d)^n < inf_dist x s := exists_pow_lt_of_lt_one A (one_half_lt_one),\n  refine \u27e8n, _\u27e9,\n  apply disjoint_left.2 (\u03bb y ys hy, _),\n  apply lt_irrefl (inf_dist x s),\n  calc inf_dist x s \u2264 dist x y : inf_dist_le_dist_of_mem ys\n  ... \u2264 (1/2)^n : by { rw mem_cylinder_comm at hy, exact mem_cylinder_iff_dist_le.1 hy }\n  ... < inf_dist x s : hn\nend\n\n/-- Given a point `x` in a product space `\u03a0 (n : \u2115), E n`, and `s` a subset of this space, then\n`shortest_prefix_diff x s` if the smallest `n` for which there is no element of `s` having the same\nprefix of length `n` as `x`. If there is no such `n`, then use `0` by convention. -/\ndef shortest_prefix_diff {E : \u2115 \u2192 Type*} (x : (\u03a0 n, E n)) (s : set (\u03a0 n, E n)) : \u2115 :=\nif h : \u2203 n, disjoint s (cylinder x n) then nat.find h else 0\n\nlemma first_diff_lt_shortest_prefix_diff {s : set (\u03a0 n, E n)} (hs : is_closed s)\n  {x y : (\u03a0 n, E n)} (hx : x \u2209 s) (hy : y \u2208 s) :\n  first_diff x y < shortest_prefix_diff x s :=\nbegin\n  have A := exists_disjoint_cylinder hs hx,\n  rw [shortest_prefix_diff, dif_pos A],\n  have B := nat.find_spec A,\n  contrapose! B,\n  rw not_disjoint_iff_nonempty_inter,\n  refine \u27e8y, hy, _\u27e9,\n  rw mem_cylinder_comm,\n  exact cylinder_anti y B (mem_cylinder_first_diff x y)\nend\n\nlemma shortest_prefix_diff_pos {s : set (\u03a0 n, E n)} (hs : is_closed s) (hne : s.nonempty)\n  {x : (\u03a0 n, E n)} (hx : x \u2209 s) :\n  0 < shortest_prefix_diff x s :=\nbegin\n  rcases hne with \u27e8y, hy\u27e9,\n  exact (zero_le _).trans_lt (first_diff_lt_shortest_prefix_diff hs hx hy)\nend\n\n/-- Given a point `x` in a product space `\u03a0 (n : \u2115), E n`, and `s` a subset of this space, then\n`longest_prefix x s` if the largest `n` for which there is an element of `s` having the same\nprefix of length `n` as `x`. If there is no such `n`, use `0` by convention. -/\ndef longest_prefix {E : \u2115 \u2192 Type*} (x : (\u03a0 n, E n)) (s : set (\u03a0 n, E n)) : \u2115 :=\nshortest_prefix_diff x s - 1\n\nlemma first_diff_le_longest_prefix {s : set (\u03a0 n, E n)} (hs : is_closed s)\n  {x y : (\u03a0 n, E n)} (hx : x \u2209 s) (hy : y \u2208 s) :\n  first_diff x y \u2264 longest_prefix x s :=\nbegin\n  rw [longest_prefix, le_tsub_iff_right],\n  { exact first_diff_lt_shortest_prefix_diff hs hx hy },\n  { exact shortest_prefix_diff_pos hs \u27e8y, hy\u27e9 hx }\nend\n\nlemma inter_cylinder_longest_prefix_nonempty\n  {s : set (\u03a0 n, E n)} (hs : is_closed s) (hne : s.nonempty) (x : (\u03a0 n, E n)) :\n  (s \u2229 cylinder x (longest_prefix x s)).nonempty :=\nbegin\n  by_cases hx : x \u2208 s, { exact \u27e8x, hx, self_mem_cylinder _ _\u27e9 },\n  have A := exists_disjoint_cylinder hs hx,\n  have B : longest_prefix x s < shortest_prefix_diff x s :=\n    nat.pred_lt (shortest_prefix_diff_pos hs hne hx).ne',\n  rw [longest_prefix, shortest_prefix_diff, dif_pos A] at B \u22a2,\n  obtain \u27e8y, ys, hy\u27e9 : \u2203 (y : \u03a0 (n : \u2115), E n), y \u2208 s \u2227 x \u2208 cylinder y (nat.find A - 1),\n  { have := nat.find_min A B,\n    push_neg at this,\n    simp_rw [not_disjoint_iff, mem_cylinder_comm] at this,\n    exact this },\n  refine \u27e8y, ys, _\u27e9,\n  rw mem_cylinder_iff_eq at hy \u22a2,\n  rw hy\nend\n\nlemma disjoint_cylinder_of_longest_prefix_lt\n  {s : set (\u03a0 n, E n)} (hs : is_closed s)\n  {x : (\u03a0 n, E n)} (hx : x \u2209 s) {n : \u2115} (hn : longest_prefix x s < n) :\n  disjoint s (cylinder x n) :=\nbegin\n  rcases eq_empty_or_nonempty s with h's|hne, { simp [h's] },\n  contrapose! hn,\n  rcases not_disjoint_iff_nonempty_inter.1 hn with \u27e8y, ys, hy\u27e9,\n  apply le_trans _ (first_diff_le_longest_prefix hs hx ys),\n  apply (mem_cylinder_iff_le_first_diff (ne_of_mem_of_not_mem ys hx).symm _).1,\n  rwa mem_cylinder_comm,\nend\n\n/-- If two points `x, y` coincide up to length `n`, and the longest common prefix of `x` with `s`\nis strictly shorter than `n`, then the longest common prefix of `y` with `s` is the same, and both\ncylinders of this length based at `x` and `y` coincide. -/\nlemma cylinder_longest_prefix_eq_of_longest_prefix_lt_first_diff\n  {x y : \u03a0 n, E n} {s : set (\u03a0 n, E n)} (hs : is_closed s) (hne : s.nonempty)\n  (H : longest_prefix x s < first_diff x y) (xs : x \u2209 s) (ys : y \u2209 s) :\n  cylinder x (longest_prefix x s) = cylinder y (longest_prefix y s) :=\nbegin\n  have l_eq : longest_prefix y s = longest_prefix x s,\n  { rcases lt_trichotomy (longest_prefix y s) (longest_prefix x s) with L|L|L,\n    { have Ax : (s \u2229 cylinder x (longest_prefix x s)).nonempty :=\n        inter_cylinder_longest_prefix_nonempty hs hne x,\n      have Z := disjoint_cylinder_of_longest_prefix_lt hs ys L,\n      rw first_diff_comm at H,\n      rw [cylinder_eq_cylinder_of_le_first_diff _ _ H.le] at Z,\n      exact (Ax.not_disjoint Z).elim },\n    { exact L },\n    { have Ay : (s \u2229 cylinder y (longest_prefix y s)).nonempty :=\n        inter_cylinder_longest_prefix_nonempty hs hne y,\n      have A'y : (s \u2229 cylinder y (longest_prefix x s).succ).nonempty :=\n        Ay.mono (inter_subset_inter_right s (cylinder_anti _ L)),\n      have Z := disjoint_cylinder_of_longest_prefix_lt hs xs (nat.lt_succ_self _),\n      rw cylinder_eq_cylinder_of_le_first_diff _ _ H at Z,\n      exact (A'y.not_disjoint Z).elim } },\n  rw [l_eq, \u2190 mem_cylinder_iff_eq],\n  exact cylinder_anti y H.le (mem_cylinder_first_diff x y)\nend\n\n/-- Given a closed nonempty subset `s` of `\u03a0 (n : \u2115), E n`, there exists a Lipschitz retraction\nonto this set, i.e., a Lipschitz map with range equal to `s`, equal to the identity on `s`. -/\ntheorem exists_lipschitz_retraction_of_is_closed\n  {s : set (\u03a0 n, E n)} (hs : is_closed s) (hne : s.nonempty) :\n  \u2203 f : (\u03a0 n, E n) \u2192 (\u03a0 n, E n), (\u2200 x \u2208 s, f x = x) \u2227 (range f = s) \u2227 lipschitz_with 1 f :=\nbegin\n  /- The map `f` is defined as follows. For `x \u2208 s`, let `f x = x`. Otherwise, consider the longest\n  prefix `w` that `x` shares with an element of `s`, and let `f x = z_w` where `z_w` is an element\n  of `s` starting with `w`. All the desired properties are clear, except the fact that `f`\n  is `1`-Lipschitz: if two points `x, y` belong to a common cylinder of length `n`, one should show\n  that their images also belong to a common cylinder of length `n`. This is a case analysis:\n  * if both `x, y \u2208 s`, then this is clear.\n  * if `x \u2208 s` but `y \u2209 s`, then the longest prefix `w` of `y` shared by an element of `s` is of\n  length at least `n` (because of `x`), and then `f y` starts with `w` and therefore stays in the\n  same length `n` cylinder.\n  * if `x \u2209 s`, `y \u2209 s`, let `w` be the longest prefix of `x` shared by an element of `s`. If its\n  length is `< n`, then it is also the longest prefix of `y`, and we get `f x = f y = z_w`.\n  Otherwise, `f x` remains in the same `n`-cylinder as `x`. Similarly for `y`. Finally, `f x` and\n  `f y` are again in the same `n`-cylinder, as desired. -/\n  set f := \u03bb x, if x \u2208 s then x else (inter_cylinder_longest_prefix_nonempty hs hne x).some with hf,\n  have fs : \u2200 x \u2208 s, f x = x := \u03bb x xs, by simp [xs],\n  refine \u27e8f, fs, _, _\u27e9,\n  -- check that the range of `f` is `s`.\n  { apply subset.antisymm,\n    { rintros x \u27e8y, rfl\u27e9,\n      by_cases hy : y \u2208 s, { rwa fs y hy },\n      simpa [hf, if_neg hy] using (inter_cylinder_longest_prefix_nonempty hs hne y).some_spec.1 },\n    { assume x hx,\n      rw \u2190 fs x hx,\n      exact mem_range_self _ } },\n  -- check that `f` is `1`-Lipschitz, by a case analysis.\n  { apply lipschitz_with.mk_one (\u03bb x y, _),\n    -- exclude the trivial cases where `x = y`, or `f x = f y`.\n    rcases eq_or_ne x y with rfl|hxy, { simp },\n    rcases eq_or_ne (f x) (f y) with h'|hfxfy, { simp [h', dist_nonneg] },\n    have I2 : cylinder x (first_diff x y) = cylinder y (first_diff x y),\n    { rw \u2190 mem_cylinder_iff_eq,\n      apply mem_cylinder_first_diff },\n    suffices : first_diff x y \u2264 first_diff (f x) (f y),\n      by simpa [dist_eq_of_ne hxy, dist_eq_of_ne hfxfy],\n    -- case where `x \u2208 s`\n    by_cases xs : x \u2208 s,\n    { rw [fs x xs] at \u22a2 hfxfy,\n      -- case where `y \u2208 s`, trivial\n      by_cases ys : y \u2208 s, { rw [fs y ys] },\n      -- case where `y \u2209 s`\n      have A : (s \u2229 cylinder y (longest_prefix y s)).nonempty :=\n        inter_cylinder_longest_prefix_nonempty hs hne y,\n      have fy : f y = A.some, by simp_rw [hf, if_neg ys],\n      have I : cylinder A.some (first_diff x y) = cylinder y (first_diff x y),\n        { rw [\u2190 mem_cylinder_iff_eq, first_diff_comm],\n          apply cylinder_anti y _ A.some_spec.2,\n          exact first_diff_le_longest_prefix hs ys xs },\n        rwa [\u2190 fy, \u2190 I2, \u2190 mem_cylinder_iff_eq, mem_cylinder_iff_le_first_diff hfxfy.symm,\n             first_diff_comm _ x] at I },\n    -- case where `x \u2209 s`\n    { by_cases ys : y \u2208 s,\n      -- case where `y \u2208 s` (similar to the above)\n      { have A : (s \u2229 cylinder x (longest_prefix x s)).nonempty :=\n          inter_cylinder_longest_prefix_nonempty hs hne x,\n        have fx : f x = A.some, by simp_rw [hf, if_neg xs],\n        have I : cylinder A.some (first_diff x y) = cylinder x (first_diff x y),\n        { rw \u2190 mem_cylinder_iff_eq,\n          apply cylinder_anti x _ A.some_spec.2,\n          apply first_diff_le_longest_prefix hs xs ys },\n        rw fs y ys at \u22a2 hfxfy,\n        rwa [\u2190 fx, I2, \u2190 mem_cylinder_iff_eq, mem_cylinder_iff_le_first_diff hfxfy] at I },\n      -- case where `y \u2209 s`\n      { have Ax : (s \u2229 cylinder x (longest_prefix x s)).nonempty :=\n          inter_cylinder_longest_prefix_nonempty hs hne x,\n        have fx : f x = Ax.some, by simp_rw [hf, if_neg xs],\n        have Ay : (s \u2229 cylinder y (longest_prefix y s)).nonempty :=\n          inter_cylinder_longest_prefix_nonempty hs hne y,\n        have fy : f y = Ay.some, by simp_rw [hf, if_neg ys],\n        -- case where the common prefix to `x` and `s`, or `y` and `s`, is shorter than the\n        -- common part to `x` and `y` -- then `f x = f y`.\n        by_cases H : longest_prefix x s < first_diff x y \u2228 longest_prefix y s < first_diff x y,\n        { have : cylinder x (longest_prefix x s) = cylinder y (longest_prefix y s),\n          { cases H,\n            { exact cylinder_longest_prefix_eq_of_longest_prefix_lt_first_diff hs hne H xs ys },\n            { symmetry,\n              rw first_diff_comm at H,\n              exact cylinder_longest_prefix_eq_of_longest_prefix_lt_first_diff hs hne H ys xs } },\n          rw [fx, fy] at hfxfy,\n          apply (hfxfy _).elim,\n          congr' },\n        -- case where the common prefix to `x` and `s` is long, as well as the common prefix to\n        -- `y` and `s`. Then all points remain in the same cylinders.\n        { push_neg at H,\n          have I1 : cylinder Ax.some (first_diff x y) = cylinder x (first_diff x y),\n          { rw \u2190 mem_cylinder_iff_eq,\n            exact cylinder_anti x H.1 Ax.some_spec.2 },\n          have I3 : cylinder y (first_diff x y) = cylinder Ay.some (first_diff x y),\n          { rw [eq_comm, \u2190 mem_cylinder_iff_eq],\n            exact cylinder_anti y H.2 Ay.some_spec.2 },\n          have : cylinder Ax.some (first_diff x y) = cylinder Ay.some (first_diff x y),\n            by rw [I1, I2, I3],\n          rw [\u2190 fx, \u2190 fy, \u2190 mem_cylinder_iff_eq, mem_cylinder_iff_le_first_diff hfxfy] at this,\n          exact this } } } }\nend\n\n/-- Given a closed nonempty subset `s` of `\u03a0 (n : \u2115), E n`, there exists a retraction onto this\nset, i.e., a continuous map with range equal to `s`, equal to the identity on `s`. -/\ntheorem exists_retraction_of_is_closed\n  {s : set (\u03a0 n, E n)} (hs : is_closed s) (hne : s.nonempty) :\n  \u2203 f : (\u03a0 n, E n) \u2192 (\u03a0 n, E n), (\u2200 x \u2208 s, f x = x) \u2227 (range f = s) \u2227 continuous f :=\nbegin\n  rcases exists_lipschitz_retraction_of_is_closed hs hne with \u27e8f, fs, frange, hf\u27e9,\n  exact \u27e8f, fs, frange, hf.continuous\u27e9\nend\n\ntheorem exists_retraction_subtype_of_is_closed\n  {s : set (\u03a0 n, E n)} (hs : is_closed s) (hne : s.nonempty) :\n  \u2203 f : (\u03a0 n, E n) \u2192 s, (\u2200 x : s, f x = x) \u2227 surjective f \u2227 continuous f :=\nbegin\n  obtain \u27e8f, fs, f_range, f_cont\u27e9 : \u2203 f : (\u03a0 n, E n) \u2192 (\u03a0 n, E n),\n    (\u2200 x \u2208 s, f x = x) \u2227 (range f = s) \u2227 continuous f :=\n      exists_retraction_of_is_closed hs hne,\n  have A : \u2200 x, f x \u2208 s, by simp [\u2190 f_range],\n  have B : \u2200 (x : s), cod_restrict f s A x = x,\n  { assume x,\n    apply subtype.coe_injective.eq_iff.1,\n    simpa only using fs x.val x.property },\n  exact \u27e8cod_restrict f s A, B, \u03bb x, \u27e8x, B x\u27e9, f_cont.subtype_mk _\u27e9,\nend\n\nend pi_nat\n\nopen pi_nat\n\n/-- Any nonempty complete second countable metric space is the continuous image of the\nfundamental space `\u2115 \u2192 \u2115`. For a version of this theorem in the context of Polish spaces, see\n`exists_nat_nat_continuous_surjective_of_polish_space`. -/\nlemma exists_nat_nat_continuous_surjective_of_complete_space\n  (\u03b1 : Type*) [metric_space \u03b1] [complete_space \u03b1] [second_countable_topology \u03b1] [nonempty \u03b1] :\n  \u2203 (f : (\u2115 \u2192 \u2115) \u2192 \u03b1), continuous f \u2227 surjective f :=\nbegin\n  /- First, we define a surjective map from a closed subset `s` of `\u2115 \u2192 \u2115`. Then, we compose\n  this map with a retraction of `\u2115 \u2192 \u2115` onto `s` to obtain the desired map.\n  Let us consider a dense sequence `u` in `\u03b1`. Then `s` is the set of sequences `x\u2099` such that the\n  balls `closed_ball (u x\u2099) (1/2^n)` have a nonempty intersection. This set is closed, and we define\n  `f x` there to be the unique point in the intersection. This function is continuous and surjective\n  by design. -/\n  letI : metric_space (\u2115 \u2192 \u2115) := pi_nat.metric_space_nat_nat,\n  have I0 : (0 : \u211d) < 1/2, by norm_num,\n  have I1 : (1/2 : \u211d) < 1, by norm_num,\n  rcases exists_dense_seq \u03b1 with \u27e8u, hu\u27e9,\n  let s : set (\u2115 \u2192 \u2115) := {x | (\u22c2 (n : \u2115), closed_ball (u (x n)) ((1/2)^n)).nonempty},\n  let g : s \u2192 \u03b1 := \u03bb x, x.2.some,\n  have A : \u2200 (x : s) (n : \u2115), dist (g x) (u ((x : \u2115 \u2192 \u2115) n)) \u2264 (1/2)^n :=\n    \u03bb x n, (mem_Inter.1 x.2.some_mem n : _),\n  have g_cont : continuous g,\n  { apply continuous_iff_continuous_at.2 (\u03bb y, _),\n    apply continuous_at_of_locally_lipschitz zero_lt_one 4 (\u03bb x hxy, _),\n    rcases eq_or_ne x y with rfl|hne, { simp },\n    have hne' : x.1 \u2260 y.1 := subtype.coe_injective.ne hne,\n    have dist' : dist x y = dist x.1 y.1 := rfl,\n    let n := first_diff x.1 y.1 - 1,\n    have diff_pos : 0 < first_diff x.1 y.1,\n    { by_contra' h,\n      apply apply_first_diff_ne hne',\n      rw [le_zero_iff.1 h],\n      apply apply_eq_of_dist_lt _ le_rfl,\n      rw pow_zero,\n      exact hxy },\n    have hn : first_diff x.1 y.1 = n + 1 := (nat.succ_pred_eq_of_pos diff_pos).symm,\n    rw [dist', dist_eq_of_ne hne', hn],\n    have B : x.1 n = y.1 n := mem_cylinder_first_diff x.1 y.1 n (nat.pred_lt diff_pos.ne'),\n    calc dist (g x) (g y) \u2264 dist (g x) (u (x.1 n)) + dist (g y) (u (x.1 n)) :\n      dist_triangle_right _ _ _\n    ... = dist (g x) (u (x.1 n)) + dist (g y) (u (y.1 n)) : by rw \u2190 B\n    ... \u2264 (1/2)^n + (1/2)^n : add_le_add (A x n) (A y n)\n    ... = 4 * (1 / 2) ^ (n + 1) : by ring_exp },\n  have g_surj : surjective g,\n  { assume y,\n    have : \u2200 (n : \u2115), \u2203 j, y \u2208 closed_ball (u j) ((1/2)^n),\n    { assume n,\n      rcases hu.exists_dist_lt y (by simp : (0 : \u211d) < (1/2)^n) with \u27e8j, hj\u27e9,\n      exact \u27e8j, hj.le\u27e9 },\n    choose x hx using this,\n    have I : (\u22c2 (n : \u2115), closed_ball (u (x n)) ((1 / 2) ^ n)).nonempty := \u27e8y, mem_Inter.2 hx\u27e9,\n    refine \u27e8\u27e8x, I\u27e9, _\u27e9,\n    refine dist_le_zero.1 _,\n    have J : \u2200 (n : \u2115), dist (g \u27e8x, I\u27e9) y \u2264 (1/2)^n + (1/2)^n := \u03bb n, calc\n      dist (g \u27e8x, I\u27e9) y \u2264 dist (g \u27e8x, I\u27e9) (u (x n)) + dist y (u (x n)) : dist_triangle_right _ _ _\n      ... \u2264 (1/2)^n + (1/2)^n : add_le_add (A \u27e8x, I\u27e9 n) (hx n),\n    have L : tendsto (\u03bb (n : \u2115), (1/2 : \u211d)^n + (1/2)^n) at_top (\ud835\udcdd (0 + 0)) :=\n      (tendsto_pow_at_top_nhds_0_of_lt_1 I0.le I1).add (tendsto_pow_at_top_nhds_0_of_lt_1 I0.le I1),\n    rw add_zero at L,\n    exact ge_of_tendsto' L J },\n  have s_closed : is_closed s,\n  { refine is_closed_iff_cluster_pt.mpr _,\n    assume x hx,\n    have L : tendsto (\u03bb (n : \u2115), diam (closed_ball (u (x n)) ((1 / 2) ^ n))) at_top (\ud835\udcdd 0),\n    { have : tendsto (\u03bb (n : \u2115), (2 : \u211d) * (1/2)^n) at_top (\ud835\udcdd (2 * 0)) :=\n        (tendsto_pow_at_top_nhds_0_of_lt_1 I0.le I1).const_mul _,\n      rw mul_zero at this,\n      exact squeeze_zero (\u03bb n, diam_nonneg) (\u03bb n, diam_closed_ball (pow_nonneg I0.le _)) this },\n    refine nonempty_Inter_of_nonempty_bInter (\u03bb n, is_closed_ball) (\u03bb n, bounded_closed_ball) _ L,\n    assume N,\n    obtain \u27e8y, hxy, ys\u27e9 : \u2203 y, y \u2208 ball x ((1 / 2) ^ N) \u2229 s :=\n      cluster_pt_principal_iff.1 hx _ (ball_mem_nhds x (pow_pos I0 N)),\n    have E : (\u22c2 (n : \u2115) (H : n \u2264 N), closed_ball (u (x n)) ((1 / 2) ^ n))\n            = \u22c2 (n : \u2115) (H : n \u2264 N), closed_ball (u (y n)) ((1 / 2) ^ n),\n    { congr,\n      ext1 n,\n      congr,\n      ext1 hn,\n      have : x n = y n := apply_eq_of_dist_lt (mem_ball'.1 hxy) hn,\n      rw this },\n    rw E,\n    apply nonempty.mono _ ys,\n    apply Inter_subset_Inter\u2082 },\n  obtain \u27e8f, -, f_surj, f_cont\u27e9 :\n    \u2203 f : (\u2115 \u2192 \u2115) \u2192 s, (\u2200 x : s, f x = x) \u2227 surjective f \u2227 continuous f,\n  { apply exists_retraction_subtype_of_is_closed s_closed,\n    simpa only [nonempty_coe_sort] using g_surj.nonempty },\n  exact \u27e8g \u2218 f, g_cont.comp f_cont, g_surj.comp f_surj\u27e9,\nend\n\nnamespace pi_countable\n\n/-!\n### Products of (possibly non-discrete) metric spaces\n-/\n\nvariables {\u03b9 : Type*} [encodable \u03b9] {F : \u03b9 \u2192 Type*} [\u2200 i, metric_space (F i)]\nopen encodable\n\n/-- Given a countable family of metric spaces, one may put a distance on their product `\u03a0 i, E i`.\nIt is highly non-canonical, though, and therefore not registered as a global instance.\nThe distance we use here is `dist x y = \u2211' i, min (1/2)^(encode i) (dist (x i) (y i))`. -/\nprotected def has_dist : has_dist (\u03a0 i, F i) :=\n\u27e8\u03bb x y, \u2211' (i : \u03b9), min ((1/2)^(encode i)) (dist (x i) (y i))\u27e9\n\nlocal attribute [instance] pi_countable.has_dist\n\nlemma dist_eq_tsum (x y : \u03a0 i, F i) :\n  dist x y = \u2211' (i : \u03b9), min ((1/2)^(encode i)) (dist (x i) (y i)) := rfl\n\nlemma dist_summable (x y : \u03a0 i, F i) :\n  summable (\u03bb (i : \u03b9), min ((1/2)^(encode i)) (dist (x i) (y i))) :=\nbegin\n  refine summable_of_nonneg_of_le (\u03bb i, _) (\u03bb i, min_le_left _ _) summable_geometric_two_encode,\n  exact le_min (pow_nonneg (by norm_num) _) (dist_nonneg)\nend\n\nlemma min_dist_le_dist_pi (x y : \u03a0 i, F i) (i : \u03b9) :\n  min ((1/2)^(encode i)) (dist (x i) (y i)) \u2264 dist x y :=\nle_tsum (dist_summable x y) i (\u03bb j hj, le_min (by simp) (dist_nonneg))\n\nlemma dist_le_dist_pi_of_dist_lt {x y : \u03a0 i, F i} {i : \u03b9} (h : dist x y < (1/2)^(encode i)) :\n  dist (x i) (y i) \u2264 dist x y :=\nby simpa only [not_le.2 h, false_or] using min_le_iff.1 (min_dist_le_dist_pi x y i)\n\nopen_locale big_operators topology\nopen filter\n\nopen_locale nnreal\n\nvariable (E)\n\n/-- Given a countable family of metric spaces, one may put a distance on their product `\u03a0 i, E i`,\ndefining the right topology and uniform structure. It is highly non-canonical, though, and therefore\nnot registered as a global instance.\nThe distance we use here is `dist x y = \u2211' n, min (1/2)^(encode i) (dist (x n) (y n))`. -/\nprotected def metric_space : metric_space (\u03a0 i, F i) :=\n{ dist_self := \u03bb x, by simp [dist_eq_tsum],\n  dist_comm := \u03bb x y, by simp [dist_eq_tsum, dist_comm],\n  dist_triangle := \u03bb x y z,\n  begin\n    have I : \u2200 i, min ((1/2)^(encode i)) (dist (x i) (z i)) \u2264\n      min ((1/2)^(encode i)) (dist (x i) (y i)) + min ((1/2)^(encode i)) (dist (y i) (z i)) :=\n    \u03bb i, calc\n      min ((1/2)^(encode i)) (dist (x i) (z i))\n        \u2264 min ((1/2)^(encode i)) (dist (x i) (y i) + dist (y i) (z i)) :\n          min_le_min le_rfl (dist_triangle _ _ _)\n      ... = min ((1/2)^(encode i)) (min ((1/2)^(encode i)) (dist (x i) (y i))\n            + min ((1/2)^(encode i)) (dist (y i) (z i))) :\n        begin\n          convert congr_arg (coe : \u211d\u22650 \u2192 \u211d)\n            (min_add_distrib ((1/2 : \u211d\u22650)^(encode i)) (nndist (x i) (y i)) (nndist (y i) (z i)));\n          simp\n        end\n      ... \u2264 min ((1/2)^(encode i)) (dist (x i) (y i)) + min ((1/2)^(encode i)) (dist (y i) (z i)) :\n          min_le_right _ _,\n    calc dist x z \u2264 \u2211' i, (min ((1/2)^(encode i)) (dist (x i) (y i))\n                          + min ((1/2)^(encode i)) (dist (y i) (z i))) :\n      tsum_le_tsum I (dist_summable x z) ((dist_summable x y).add (dist_summable y z))\n    ... = dist x y + dist y z : tsum_add (dist_summable x y) (dist_summable y z)\n  end,\n  eq_of_dist_eq_zero :=\n  begin\n    assume x y hxy,\n    ext1 n,\n    rw [\u2190 dist_le_zero, \u2190 hxy],\n    apply dist_le_dist_pi_of_dist_lt,\n    rw hxy,\n    simp\n  end,\n  to_uniform_space := Pi.uniform_space _,\n  uniformity_dist :=\n  begin\n    have I0 : (0 : \u211d) \u2264 1/2, by norm_num,\n    have I1 : (1/2 : \u211d) < 1, by norm_num,\n    simp only [Pi.uniformity, comap_infi, gt_iff_lt, preimage_set_of_eq, comap_principal,\n      pseudo_metric_space.uniformity_dist],\n    apply le_antisymm,\n    { simp only [le_infi_iff, le_principal_iff],\n      assume \u03b5 \u03b5pos,\n      obtain \u27e8K, hK\u27e9 : \u2203 (K : finset \u03b9), \u2211' (i : {j // j \u2209 K}), (1/2 : \u211d)^(encode (i : \u03b9)) < \u03b5/2 :=\n        ((tendsto_order.1 (tendsto_tsum_compl_at_top_zero (\u03bb (i : \u03b9), (1/2 : \u211d)^(encode i)))).2\n           _ (half_pos \u03b5pos)).exists,\n      obtain \u27e8\u03b4, \u03b4pos, h\u03b4\u27e9 : \u2203 (\u03b4 : \u211d) (\u03b4pos : 0 < \u03b4), (K.card : \u211d) * \u03b4 \u2264 \u03b5/2,\n      { rcases nat.eq_zero_or_pos K.card with hK|hK,\n        { exact \u27e81, zero_lt_one,\n                  by simpa only [hK, nat.cast_zero, zero_mul] using (half_pos \u03b5pos).le\u27e9 },\n        { have Kpos : 0 < (K.card : \u211d) := nat.cast_pos.2 hK,\n          refine \u27e8(\u03b5 / 2) / (K.card : \u211d), (div_pos (half_pos \u03b5pos) Kpos), le_of_eq _\u27e9,\n          field_simp [Kpos.ne'],\n          ring } },\n      apply @mem_infi_of_Inter _ _ _ _ _ K.finite_to_set\n        (\u03bb i, {p : (\u03a0 (i : \u03b9), F i) \u00d7 \u03a0 (i : \u03b9), F i | dist (p.fst i) (p.snd i) < \u03b4}),\n      { rintros \u27e8i, hi\u27e9,\n        refine mem_infi_of_mem \u03b4 (mem_infi_of_mem \u03b4pos _),\n        simp only [prod.forall, imp_self, mem_principal] },\n      { rintros \u27e8x, y\u27e9 hxy,\n        simp only [mem_Inter, mem_set_of_eq, set_coe.forall, finset.mem_range, finset.mem_coe]\n          at hxy,\n        calc dist x y = \u2211' (i : \u03b9), min ((1/2)^(encode i)) (dist (x i) (y i)) : rfl\n        ... = \u2211 i in K, min ((1/2)^(encode i)) (dist (x i) (y i))\n             + \u2211' (i : (\u2191K : set \u03b9)\u1d9c), min ((1/2)^(encode (i : \u03b9))) (dist (x i) (y i)) :\n          (sum_add_tsum_compl (dist_summable _ _)).symm\n        ... \u2264 \u2211 i in K, (dist (x i) (y i))\n             + \u2211' (i : (\u2191K : set \u03b9)\u1d9c), (1/2)^(encode (i : \u03b9)) :\n          begin\n            refine add_le_add (finset.sum_le_sum (\u03bb i hi, min_le_right _ _)) _,\n            refine tsum_le_tsum (\u03bb i, min_le_left _ _) _ _,\n            { apply summable.subtype (dist_summable x y) (\u2191K : set \u03b9)\u1d9c },\n            { apply summable.subtype summable_geometric_two_encode (\u2191K : set \u03b9)\u1d9c }\n          end\n        ... < (\u2211 i in K, \u03b4) + \u03b5 / 2 :\n          begin\n            apply add_lt_add_of_le_of_lt _ hK,\n            apply finset.sum_le_sum (\u03bb i hi, _),\n            apply (hxy i _).le,\n            simpa using hi\n          end\n        ... \u2264 \u03b5 / 2 + \u03b5 / 2 :\n          add_le_add_right (by simpa only [finset.sum_const, nsmul_eq_mul] using h\u03b4) _\n        ... = \u03b5 : add_halves _ } },\n    { simp only [le_infi_iff, le_principal_iff],\n      assume i \u03b5 \u03b5pos,\n      refine mem_infi_of_mem (min ((1/2)^(encode i)) \u03b5) _,\n      have : 0 < min ((1/2)^(encode i)) \u03b5 := lt_min (by simp) \u03b5pos,\n      refine mem_infi_of_mem this _,\n      simp only [and_imp, prod.forall, set_of_subset_set_of, lt_min_iff, mem_principal],\n      assume x y hn h\u03b5,\n      calc dist (x i) (y i) \u2264 dist x y : dist_le_dist_pi_of_dist_lt hn\n      ... < \u03b5 : h\u03b5 }\n  end }\n\nend pi_countable\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/metric_space/pi_nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7128673784024814}}
{"text": "namespace forall_conjunct_left\n  variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n  example : (\u2200 x : \u03b1, p x \u2227 q x) \u2192 \u2200 y : \u03b1, p y :=\n    assume h : \u2200 x : \u03b1 , p x \u2227 q x,\n    take k : \u03b1, \n    show p k, from (h k).left\nend forall_conjunct_left\n\nnamespace forall_rel_trans\n  variables (\u03b1 : Type) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n  variable trans_r : \u2200 x y z, r x y \u2192 r y z \u2192 r x z\n\n  variables a b c : \u03b1 \n  variables (hab : r a b) (hbc : r b c)\n\n  #check trans_r\n  #check trans_r a b c\n  #check trans_r a b c hab \n  #check trans_r a b c hab hbc\nend forall_rel_trans\n\nnamespace forall_rel_trans_impl\n  variables (\u03b1 : Type) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n  variable trans_r : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z\n\n  variables a b c : \u03b1 \n  variables (hab : r a b) (hbc : r b c)\n\n  #check trans_r\n  #check trans_r hab \n  #check trans_r hab hbc\nend forall_rel_trans_impl\n\nnamespace forall_equiv \n  variables (\u03b1 : Type) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n  variable reflex_r : \u2200 x, r x x\n  variable symm_r : \u2200 {x y}, r x y \u2192 r y x\n  variable trans_r : \u2200 {x y z}, r x y \u2192 r y z \u2192 r x z\n\n  example (a b c d : \u03b1) (hab : r a b) (hcb : r c b) (hcd : r c d) : r a d :=\n  trans_r (trans_r hab (symm_r hcb)) hcd\nend forall_equiv", "meta": {"author": "alexpatel", "repo": "lean-ex", "sha": "37419b8d014ba3ba416e2252809a89a1604a1330", "save_path": "github-repos/lean/alexpatel-lean-ex", "path": "github-repos/lean/alexpatel-lean-ex/lean-ex-37419b8d014ba3ba416e2252809a89a1604a1330/16-forall.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7128673774664478}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.combinatorics.composition\nimport Mathlib.data.nat.parity\nimport Mathlib.tactic.apply_fun\nimport Mathlib.PostPort\n\nuniverses l \n\nnamespace Mathlib\n\n/-!\n# Partitions\n\nA partition of a natural number `n` is a way of writing `n` as a sum of positive integers, where the\norder does not matter: two sums that differ only in the order of their summands are considered the\nsame partition. This notion is closely related to that of a composition of `n`, but in a composition\nof `n` the order does matter.\nA summand of the partition is called a part.\n\n## Main functions\n\n* `p : partition n` is a structure, made of a multiset of integers which are all positive and\n  add up to `n`.\n\n## Implementation details\n\nThe main motivation for this structure and its API is to show Euler's partition theorem, and\nrelated results.\n\nThe representation of a partition as a multiset is very handy as multisets are very flexible and\nalready have a well-developed API.\n\n## Tags\n\nPartition\n\n## References\n\n<https://en.wikipedia.org/wiki/Partition_(number_theory)>\n-/\n\n/-- A partition of `n` is a multiset of positive integers summing to `n`. -/\nstructure partition (n : \u2115) where\n  parts : multiset \u2115\n  parts_pos : \u2200 {i : \u2115}, i \u2208 parts \u2192 0 < i\n  parts_sum : multiset.sum parts = n\n\nnamespace partition\n\n\n/-- A composition induces a partition (just convert the list to a multiset). -/\ndef of_composition (n : \u2115) (c : composition n) : partition n :=\n  mk \u2191(composition.blocks c) sorry sorry\n\ntheorem of_composition_surj {n : \u2115} : function.surjective (of_composition n) := sorry\n\n/--\nGiven a multiset which sums to `n`, construct a partition of `n` with the same multiset, but\nwithout the zeros.\n-/\n-- The argument `n` is kept explicit here since it is useful in tactic mode proofs to generate the\n\n-- proof obligation `l.sum = n`.\n\ndef of_sums (n : \u2115) (l : multiset \u2115) (hl : multiset.sum l = n) : partition n :=\n  mk (multiset.filter (fun (_x : \u2115) => _x \u2260 0) l) sorry sorry\n\n/-- A `multiset \u2115` induces a partition on its sum. -/\ndef of_multiset (l : multiset \u2115) : partition (multiset.sum l) := of_sums (multiset.sum l) l sorry\n\n/-- The partition of exactly one part. -/\ndef indiscrete_partition (n : \u2115) : partition n := of_sums n (singleton n) sorry\n\nprotected instance inhabited {n : \u2115} : Inhabited (partition n) :=\n  { default := indiscrete_partition n }\n\n/--\nThe number of times a positive integer `i` appears in the partition `of_sums n l hl` is the same\nas the number of times it appears in the multiset `l`.\n(For `i = 0`, `partition.non_zero` combined with `multiset.count_eq_zero_of_not_mem` gives that\nthis is `0` instead.)\n-/\ntheorem count_of_sums_of_ne_zero {n : \u2115} {l : multiset \u2115} (hl : multiset.sum l = n) {i : \u2115}\n    (hi : i \u2260 0) : multiset.count i (parts (of_sums n l hl)) = multiset.count i l :=\n  multiset.count_filter_of_pos hi\n\ntheorem count_of_sums_zero {n : \u2115} {l : multiset \u2115} (hl : multiset.sum l = n) :\n    multiset.count 0 (parts (of_sums n l hl)) = 0 :=\n  multiset.count_filter_of_neg fun (h : 0 \u2260 0) => h rfl\n\n/--\nShow there are finitely many partitions by considering the surjection from compositions to\npartitions.\n-/\nprotected instance fintype (n : \u2115) : fintype (partition n) :=\n  fintype.of_surjective (of_composition n) of_composition_surj\n\n/-- The finset of those partitions in which every part is odd. -/\ndef odds (n : \u2115) : finset (partition n) :=\n  finset.filter (fun (c : partition n) => \u2200 (i : \u2115), i \u2208 parts c \u2192 \u00aceven i) finset.univ\n\n/-- The finset of those partitions in which each part is used at most once. -/\ndef distincts (n : \u2115) : finset (partition n) :=\n  finset.filter (fun (c : partition n) => multiset.nodup (parts c)) finset.univ\n\n/-- The finset of those partitions in which every part is odd and used at most once. -/\ndef odd_distincts (n : \u2115) : finset (partition n) := odds n \u2229 distincts n\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/combinatorics/partition_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7128673737055751}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.eval\n\n/-!\n# Theory of degrees of polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nSome of the main results include\n- `nat_degree_comp_le` : The degree of the composition is at most the product of degrees\n\n-/\n\nnoncomputable theory\nopen_locale classical polynomial\n\nopen finsupp finset\n\nnamespace polynomial\nuniverses u v w\nvariables {R : Type u} {S : Type v} { \u03b9 : Type w} {a b : R} {m n : \u2115}\n\nsection semiring\nvariables [semiring R] {p q r : R[X]}\n\nsection degree\n\nlemma nat_degree_comp_le : nat_degree (p.comp q) \u2264 nat_degree p * nat_degree q :=\nif h0 : p.comp q = 0 then by rw [h0, nat_degree_zero]; exact nat.zero_le _\nelse with_bot.coe_le_coe.1 $\n  calc \u2191(nat_degree (p.comp q)) = degree (p.comp q) : (degree_eq_nat_degree h0).symm\n  ... = _ : congr_arg degree comp_eq_sum_left\n  ... \u2264 _ : degree_sum_le _ _\n  ... \u2264 _ : finset.sup_le (\u03bb n hn,\n    calc degree (C (coeff p n) * q ^ n)\n        \u2264 degree (C (coeff p n)) + degree (q ^ n) : degree_mul_le _ _\n    ... \u2264 nat_degree (C (coeff p n)) + n \u2022 (degree q) :\n      add_le_add degree_le_nat_degree (degree_pow_le _ _)\n    ... \u2264 nat_degree (C (coeff p n)) + n \u2022 (nat_degree q) :\n      add_le_add_left (nsmul_le_nsmul_of_le_right (@degree_le_nat_degree _ _ q) n) _\n    ... = (n * nat_degree q : \u2115) :\n     by rw [nat_degree_C, with_bot.coe_zero, zero_add, \u2190 with_bot.coe_nsmul,\n       nsmul_eq_mul]; simp\n    ... \u2264 (nat_degree p * nat_degree q : \u2115) : with_bot.coe_le_coe.2 $\n      mul_le_mul_of_nonneg_right\n        (le_nat_degree_of_ne_zero (mem_support_iff.1 hn))\n        (nat.zero_le _))\n\nlemma degree_pos_of_root {p : R[X]} (hp : p \u2260 0) (h : is_root p a) : 0 < degree p :=\nlt_of_not_ge $ \u03bb hlt, begin\n  have := eq_C_of_degree_le_zero hlt,\n  rw [is_root, this, eval_C] at h,\n  simp only [h, ring_hom.map_zero] at this,\n  exact hp this,\nend\n\nlemma nat_degree_le_iff_coeff_eq_zero :\n  p.nat_degree \u2264 n \u2194 \u2200 N : \u2115, n < N \u2192 p.coeff N = 0 :=\nby simp_rw [nat_degree_le_iff_degree_le, degree_le_iff_coeff_zero, with_bot.coe_lt_coe]\n\nlemma nat_degree_add_le_iff_left {n : \u2115} (p q : R[X]) (qn : q.nat_degree \u2264 n) :\n  (p + q).nat_degree \u2264 n \u2194 p.nat_degree \u2264 n :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, nat_degree_add_le_of_degree_le h qn\u27e9,\n  refine nat_degree_le_iff_coeff_eq_zero.mpr (\u03bb m hm, _),\n  convert nat_degree_le_iff_coeff_eq_zero.mp h m hm using 1,\n  rw [coeff_add, nat_degree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero],\nend\n\nlemma nat_degree_add_le_iff_right {n : \u2115} (p q : R[X]) (pn : p.nat_degree \u2264 n) :\n  (p + q).nat_degree \u2264 n \u2194 q.nat_degree \u2264 n :=\nbegin\n  rw add_comm,\n  exact nat_degree_add_le_iff_left _ _ pn,\nend\n\nlemma nat_degree_C_mul_le (a : R) (f : R[X]) :\n  (C a * f).nat_degree \u2264 f.nat_degree :=\ncalc\n  (C a * f).nat_degree \u2264 (C a).nat_degree + f.nat_degree : nat_degree_mul_le\n  ... = 0 + f.nat_degree : by rw nat_degree_C a\n  ... = f.nat_degree : zero_add _\n\nlemma nat_degree_mul_C_le (f : R[X]) (a : R) :\n  (f * C a).nat_degree \u2264 f.nat_degree :=\ncalc\n  (f * C a).nat_degree \u2264 f.nat_degree + (C a).nat_degree : nat_degree_mul_le\n  ... = f.nat_degree + 0 : by rw nat_degree_C a\n  ... = f.nat_degree : add_zero _\n\nlemma eq_nat_degree_of_le_mem_support (pn : p.nat_degree \u2264 n) (ns : n \u2208 p.support) :\n  p.nat_degree = n :=\nle_antisymm pn (le_nat_degree_of_mem_supp _ ns)\n\nlemma nat_degree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) :\n  (C a * p).nat_degree = p.nat_degree :=\nle_antisymm (nat_degree_C_mul_le a p) (calc\n  p.nat_degree = (1 * p).nat_degree : by nth_rewrite 0 [\u2190 one_mul p]\n  ... = (C ai * (C a * p)).nat_degree : by rw [\u2190 C_1, \u2190 au, ring_hom.map_mul, \u2190 mul_assoc]\n  ... \u2264 (C a * p).nat_degree : nat_degree_C_mul_le ai (C a * p))\n\nlemma nat_degree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) :\n  (p * C a).nat_degree = p.nat_degree :=\nle_antisymm (nat_degree_mul_C_le p a) (calc\n  p.nat_degree = (p * 1).nat_degree : by nth_rewrite 0 [\u2190 mul_one p]\n  ... = ((p * C a) * C ai).nat_degree : by rw [\u2190 C_1, \u2190 au, ring_hom.map_mul, \u2190 mul_assoc]\n  ... \u2264 (p * C a).nat_degree : nat_degree_mul_C_le (p * C a) ai)\n\n/-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero`\nforce the polynomial `p` to be non-zero, via `p.leading_coeff \u2260 0`.\n-/\nlemma nat_degree_mul_C_eq_of_mul_ne_zero (h : p.leading_coeff * a \u2260 0) :\n  (p * C a).nat_degree = p.nat_degree :=\nbegin\n  refine eq_nat_degree_of_le_mem_support (nat_degree_mul_C_le p a) _,\n  refine mem_support_iff.mpr _,\n  rwa coeff_mul_C,\nend\n\n/-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero`\nforce the polynomial `p` to be non-zero, via `p.leading_coeff \u2260 0`.\n-/\nlemma nat_degree_C_mul_eq_of_mul_ne_zero (h : a * p.leading_coeff \u2260 0) :\n  (C a * p).nat_degree = p.nat_degree :=\nbegin\n  refine eq_nat_degree_of_le_mem_support (nat_degree_C_mul_le a p) _,\n  refine mem_support_iff.mpr _,\n  rwa coeff_C_mul,\nend\n\nlemma nat_degree_add_coeff_mul (f g : R[X]) :\n  (f * g).coeff (f.nat_degree + g.nat_degree) = f.coeff f.nat_degree * g.coeff g.nat_degree :=\nby simp only [coeff_nat_degree, coeff_mul_degree_add_degree]\n\nlemma nat_degree_lt_coeff_mul (h : p.nat_degree + q.nat_degree < m + n) :\n  (p * q).coeff (m + n) = 0 :=\ncoeff_eq_zero_of_nat_degree_lt (nat_degree_mul_le.trans_lt h)\n\nlemma coeff_mul_of_nat_degree_le (pm : p.nat_degree \u2264 m) (qn : q.nat_degree \u2264 n) :\n  (p * q).coeff (m + n) = p.coeff m * q.coeff n :=\nbegin\n  rcases eq_or_lt_of_le pm with rfl | hm;\n  rcases eq_or_lt_of_le qn with rfl | hn,\n  { exact nat_degree_add_coeff_mul _ _ },\n  { rw [coeff_eq_zero_of_nat_degree_lt hn, mul_zero],\n    exact nat_degree_lt_coeff_mul (add_lt_add_left hn _) },\n  { rw [coeff_eq_zero_of_nat_degree_lt hm, zero_mul],\n    exact nat_degree_lt_coeff_mul (add_lt_add_right hm _) },\n  { rw [coeff_eq_zero_of_nat_degree_lt hn, mul_zero],\n    exact nat_degree_lt_coeff_mul (add_lt_add hm hn) },\nend\n\nlemma coeff_pow_of_nat_degree_le (pn : p.nat_degree \u2264 n) :\n  (p ^ m).coeff (n * m) = (p.coeff n) ^ m :=\nbegin\n  induction m with m hm,\n  { simp },\n  { rw [pow_succ', pow_succ', \u2190 hm, nat.mul_succ, coeff_mul_of_nat_degree_le _ pn],\n    refine nat_degree_pow_le.trans (le_trans _ (mul_comm _ _).le),\n    exact mul_le_mul_of_nonneg_left pn m.zero_le }\nend\n\nlemma coeff_add_eq_left_of_lt (qn : q.nat_degree < n) :\n  (p + q).coeff n = p.coeff n :=\n(coeff_add _ _ _).trans $ (congr_arg _ $ coeff_eq_zero_of_nat_degree_lt $ qn).trans $ add_zero _\n\nlemma coeff_add_eq_right_of_lt (pn : p.nat_degree < n) :\n  (p + q).coeff n = q.coeff n :=\nby { rw add_comm, exact coeff_add_eq_left_of_lt pn }\n\n\n\nlemma nat_degree_sum_eq_of_disjoint (f : S \u2192 R[X]) (s : finset S)\n  (h : set.pairwise { i | i \u2208 s \u2227 f i \u2260 0 } (ne on (nat_degree \u2218 f))) :\n  nat_degree (s.sum f) = s.sup (\u03bb i, nat_degree (f i)) :=\nbegin\n  by_cases H : \u2203 x \u2208 s, f x \u2260 0,\n  { obtain \u27e8x, hx, hx'\u27e9 := H,\n    have hs : s.nonempty := \u27e8x, hx\u27e9,\n    refine nat_degree_eq_of_degree_eq_some _,\n    rw degree_sum_eq_of_disjoint,\n    { rw [\u2190finset.sup'_eq_sup hs, \u2190finset.sup'_eq_sup hs, finset.coe_sup', \u2190finset.sup'_eq_sup hs],\n      refine le_antisymm _ _,\n      { rw finset.sup'_le_iff,\n        intros b hb,\n        by_cases hb' : f b = 0,\n        { simpa [hb'] using hs },\n        rw degree_eq_nat_degree hb',\n        exact finset.le_sup' _ hb },\n      { rw finset.sup'_le_iff,\n        intros b hb,\n        simp only [finset.le_sup'_iff, exists_prop, function.comp_app],\n        by_cases hb' : f b = 0,\n        { refine \u27e8x, hx, _\u27e9,\n          contrapose! hx',\n          simpa [hb', degree_eq_bot] using hx' },\n        exact \u27e8b, hb, (degree_eq_nat_degree hb').ge\u27e9 } },\n    { exact h.imp (\u03bb x y hxy hxy', hxy (nat_degree_eq_of_degree_eq hxy')) } },\n  { push_neg at H,\n    rw [finset.sum_eq_zero H, nat_degree_zero, eq_comm, show 0 = \u22a5, from rfl,\n        finset.sup_eq_bot_iff],\n    intros x hx,\n    simp [H x hx] }\nend\n\nlemma nat_degree_bit0 (a : R[X]) : (bit0 a).nat_degree \u2264 a.nat_degree :=\n(nat_degree_add_le _ _).trans (max_self _).le\n\nlemma nat_degree_bit1 (a : R[X]) : (bit1 a).nat_degree \u2264 a.nat_degree :=\n(nat_degree_add_le _ _).trans (by simp [nat_degree_bit0])\n\nvariables [semiring S]\n\nlemma nat_degree_pos_of_eval\u2082_root {p : R[X]} (hp : p \u2260 0) (f : R \u2192+* S)\n  {z : S} (hz : eval\u2082 f z p = 0) (inj : \u2200 (x : R), f x = 0 \u2192 x = 0) :\n  0 < nat_degree p :=\nlt_of_not_ge $ \u03bb hlt, begin\n  have A : p = C (p.coeff 0) := eq_C_of_nat_degree_le_zero hlt,\n  rw [A, eval\u2082_C] at hz,\n  simp only [inj (p.coeff 0) hz, ring_hom.map_zero] at A,\n  exact hp A\nend\n\nlemma degree_pos_of_eval\u2082_root {p : R[X]} (hp : p \u2260 0) (f : R \u2192+* S)\n  {z : S} (hz : eval\u2082 f z p = 0) (inj : \u2200 (x : R), f x = 0 \u2192 x = 0) :\n  0 < degree p :=\nnat_degree_pos_iff_degree_pos.mp (nat_degree_pos_of_eval\u2082_root hp f hz inj)\n\n@[simp] lemma coe_lt_degree {p : R[X]} {n : \u2115} :\n  ((n : with_bot \u2115) < degree p) \u2194 n < nat_degree p :=\nbegin\n  by_cases h : p = 0,\n  { simp [h] },\n  rw [degree_eq_nat_degree h, with_bot.coe_lt_coe],\nend\n\nend degree\nend semiring\n\nsection ring\n\nvariables [ring R] {p q : R[X]}\n\nlemma nat_degree_sub : (p - q).nat_degree = (q - p).nat_degree :=\nby rw [\u2190 nat_degree_neg, neg_sub]\n\nlemma nat_degree_sub_le_iff_left (qn : q.nat_degree \u2264 n) :\n  (p - q).nat_degree \u2264 n \u2194 p.nat_degree \u2264 n :=\nbegin\n  rw \u2190 nat_degree_neg at qn,\n  rw [sub_eq_add_neg, nat_degree_add_le_iff_left _ _ qn],\nend\n\nlemma nat_degree_sub_le_iff_right (pn : p.nat_degree \u2264 n) :\n  (p - q).nat_degree \u2264 n \u2194 q.nat_degree \u2264 n :=\nby rwa [nat_degree_sub, nat_degree_sub_le_iff_left]\n\nlemma coeff_sub_eq_left_of_lt (dg : q.nat_degree < n) :\n  (p - q).coeff n = p.coeff n :=\nbegin\n  rw \u2190 nat_degree_neg at dg,\n  rw [sub_eq_add_neg, coeff_add_eq_left_of_lt dg],\nend\n\nlemma coeff_sub_eq_neg_right_of_lt (df : p.nat_degree < n) :\n  (p - q).coeff n = - q.coeff n :=\nby rwa [sub_eq_add_neg, coeff_add_eq_right_of_lt, coeff_neg]\n\nend ring\n\nsection no_zero_divisors\nvariables [semiring R] [no_zero_divisors R] {p q : R[X]}\n\nlemma degree_mul_C (a0 : a \u2260 0) :\n  (p * C a).degree = p.degree :=\nby rw [degree_mul, degree_C a0, add_zero]\n\nlemma degree_C_mul (a0 : a \u2260 0) :\n  (C a * p).degree = p.degree :=\nby rw [degree_mul, degree_C a0, zero_add]\n\nlemma nat_degree_mul_C (a0 : a \u2260 0) :\n  (p * C a).nat_degree = p.nat_degree :=\nby simp only [nat_degree, degree_mul_C a0]\n\nlemma nat_degree_C_mul (a0 : a \u2260 0) :\n  (C a * p).nat_degree = p.nat_degree :=\nby simp only [nat_degree, degree_C_mul a0]\n\nlemma nat_degree_comp : nat_degree (p.comp q) = nat_degree p * nat_degree q :=\nbegin\n  by_cases q0 : q.nat_degree = 0,\n  { rw [degree_le_zero_iff.mp (nat_degree_eq_zero_iff_degree_le_zero.mp q0), comp_C, nat_degree_C,\n      nat_degree_C, mul_zero] },\n  { by_cases p0 : p = 0, { simp only [p0, zero_comp, nat_degree_zero, zero_mul] },\n    refine le_antisymm nat_degree_comp_le (le_nat_degree_of_ne_zero _),\n    simp only [coeff_comp_degree_mul_degree q0, p0, mul_eq_zero, leading_coeff_eq_zero, or_self,\n      ne_zero_of_nat_degree_gt (nat.pos_of_ne_zero q0), pow_ne_zero, ne.def, not_false_iff] }\nend\n\n@[simp] theorem nat_degree_iterate_comp (k : \u2115) :\n  (p.comp^[k] q).nat_degree = p.nat_degree ^ k * q.nat_degree :=\nbegin\n  induction k with k IH,\n  { simp },\n  { rw [function.iterate_succ_apply', nat_degree_comp, IH, pow_succ, mul_assoc] }\nend\n\nlemma leading_coeff_comp (hq : nat_degree q \u2260 0) :\n  leading_coeff (p.comp q) = leading_coeff p * leading_coeff q ^ nat_degree p :=\nby rw [\u2190 coeff_comp_degree_mul_degree hq, \u2190 nat_degree_comp, coeff_nat_degree]\n\nend no_zero_divisors\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/degree/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7128514820420863}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport logic.encodable.basic\nimport order.atoms\nimport order.upper_lower.basic\n\n/-!\n# Order ideals, cofinal sets, and the Rasiowa\u2013Sikorski lemma\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections require more\nstructure, such as a bottom element, a top element, or a join-semilattice structure.\n- `order.ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.\n  Dual to the notion of a filter on a preorder.\n- `order.is_ideal P`: a predicate for when a `set P` is an ideal.\n- `order.ideal.principal p`: the principal ideal generated by `p : P`.\n- `order.ideal.is_proper P`: a predicate for proper ideals.\n  Dual to the notion of a proper filter.\n- `order.ideal.is_maximal`: a predicate for maximal ideals.\n  Dual to the notion of an ultrafilter.\n- `order.cofinal P`: the type of subsets of `P` containing arbitrarily large elements.\n  Dual to the notion of 'dense set' used in forcing.\n- `order.ideal_of_cofinals p \ud835\udc9f`, where `p : P`, and `\ud835\udc9f` is a countable family of cofinal\n  subsets of P: an ideal in `P` which contains `p` and intersects every set in `\ud835\udc9f`. (This a form\n  of the Rasiowa\u2013Sikorski lemma.)\n\n## References\n\n- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>\n- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>\n- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>\n\nNote that for the Rasiowa\u2013Sikorski lemma, Wikipedia uses the opposite ordering on `P`,\nin line with most presentations of forcing.\n\n## Tags\n\nideal, cofinal, dense, countable, generic\n\n-/\n\nopen function set\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- An ideal on an order `P` is a subset of `P` that is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\nstructure ideal (P) [has_le P] extends lower_set P :=\n(nonempty'  : carrier.nonempty)\n(directed'  : directed_on (\u2264) carrier)\n\n/-- A subset of a preorder `P` is an ideal if it is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\n@[mk_iff] structure is_ideal {P} [has_le P] (I : set P) : Prop :=\n(is_lower_set : is_lower_set I)\n(nonempty : I.nonempty)\n(directed : directed_on (\u2264) I)\n\n/-- Create an element of type `order.ideal` from a set satisfying the predicate\n`order.is_ideal`. -/\ndef is_ideal.to_ideal [has_le P] {I : set P} (h : is_ideal I) : ideal P :=\n\u27e8\u27e8I, h.is_lower_set\u27e9, h.nonempty, h.directed\u27e9\n\nnamespace ideal\nsection has_le\nvariables [has_le P]\n\nsection\nvariables {I J s t : ideal P} {x y : P}\n\nlemma to_lower_set_injective : injective (to_lower_set : ideal P \u2192 lower_set P) :=\n\u03bb s t h, by { cases s, cases t, congr' }\n\ninstance : set_like (ideal P) P :=\n{ coe := \u03bb s, s.carrier,\n  coe_injective' := \u03bb s t h, to_lower_set_injective $ set_like.coe_injective h }\n\n@[ext] lemma ext {s t : ideal P} : (s : set P) = t \u2192 s = t := set_like.ext'\n\n@[simp] lemma carrier_eq_coe (s : ideal P) : s.carrier = s := rfl\n@[simp] lemma coe_to_lower_set (s : ideal P) : (s.to_lower_set : set P) = s := rfl\n\nprotected lemma lower (s : ideal P) : is_lower_set (s : set P) := s.lower'\nprotected lemma nonempty (s : ideal P) : (s : set P).nonempty := s.nonempty'\nprotected lemma directed (s : ideal P) : directed_on (\u2264) (s : set P) := s.directed'\nprotected lemma is_ideal (s : ideal P) : is_ideal (s : set P) := \u27e8s.lower, s.nonempty, s.directed\u27e9\n\nlemma mem_compl_of_ge {x y : P} : x \u2264 y \u2192 x \u2208 (I : set P)\u1d9c \u2192 y \u2208 (I : set P)\u1d9c := \u03bb h, mt $ I.lower h\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (ideal P) := partial_order.lift coe set_like.coe_injective\n\n@[simp] lemma coe_subset_coe : (s : set P) \u2286 t \u2194 s \u2264 t := iff.rfl\n@[simp] lemma coe_ssubset_coe : (s : set P) \u2282 t \u2194 s < t := iff.rfl\n\n@[trans] lemma mem_of_mem_of_le {x : P} {I J : ideal P} : x \u2208 I \u2192 I \u2264 J \u2192 x \u2208 J :=\n@set.mem_of_mem_of_subset P x I J\n\n/-- A proper ideal is one that is not the whole set.\n    Note that the whole set might not be an ideal. -/\n@[mk_iff] class is_proper (I : ideal P) : Prop := (ne_univ : (I : set P) \u2260 univ)\n\nlemma is_proper_of_not_mem {I : ideal P} {p : P} (nmem : p \u2209 I) : is_proper I :=\n\u27e8\u03bb hp, begin\n  change p \u2209 \u2191I at nmem,\n  rw hp at nmem,\n  exact nmem (mem_univ p),\nend\u27e9\n\n/-- An ideal is maximal if it is maximal in the collection of proper ideals.\n\nNote that `is_coatom` is less general because ideals only have a top element when `P` is directed\nand nonempty. -/\n@[mk_iff] class is_maximal (I : ideal P) extends is_proper I : Prop :=\n(maximal_proper : \u2200 \u2983J : ideal P\u2984, I < J \u2192 (J : set P) = univ)\n\nlemma inter_nonempty [is_directed P (\u2265)] (I J : ideal P) : (I \u2229 J : set P).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 := I.nonempty,\n  obtain \u27e8b, hb\u27e9 := J.nonempty,\n  obtain \u27e8c, hac, hbc\u27e9 := exists_le_le a b,\n  exact \u27e8c, I.lower hac ha, J.lower hbc hb\u27e9,\nend\n\nend\n\nsection directed\nvariables [is_directed P (\u2264)] [nonempty P] {I : ideal P}\n\n/-- In a directed and nonempty order, the top ideal of a is `univ`. -/\ninstance : order_top (ideal P) :=\n{ top := \u27e8\u22a4, univ_nonempty, directed_on_univ\u27e9,\n  le_top := \u03bb I, le_top }\n\n@[simp] lemma top_to_lower_set : (\u22a4 : ideal P).to_lower_set = \u22a4 := rfl\n@[simp] lemma coe_top : ((\u22a4 : ideal P) : set P) = univ := rfl\n\nlemma is_proper_of_ne_top (ne_top : I \u2260 \u22a4) : is_proper I := \u27e8\u03bb h, ne_top $ ext h\u27e9\n\nlemma is_proper.ne_top (hI : is_proper I) : I \u2260 \u22a4 := \u03bb h, is_proper.ne_univ $ congr_arg coe h\n\nlemma _root_.is_coatom.is_proper (hI : is_coatom I) : is_proper I := is_proper_of_ne_top hI.1\n\nlemma is_proper_iff_ne_top : is_proper I \u2194 I \u2260 \u22a4 := \u27e8\u03bb h, h.ne_top, \u03bb h, is_proper_of_ne_top h\u27e9\n\nlemma is_maximal.is_coatom (h : is_maximal I) : is_coatom I :=\n\u27e8is_maximal.to_is_proper.ne_top, \u03bb J h, ext $ is_maximal.maximal_proper h\u27e9\n\nlemma is_maximal.is_coatom' [is_maximal I] : is_coatom I := is_maximal.is_coatom \u2039_\u203a\n\nlemma _root_.is_coatom.is_maximal (hI : is_coatom I) : is_maximal I :=\n{ maximal_proper := \u03bb _ _, by simp [hI.2 _ \u2039_\u203a],\n  ..is_coatom.is_proper \u2039_\u203a }\n\nlemma is_maximal_iff_is_coatom : is_maximal I \u2194 is_coatom I := \u27e8\u03bb h, h.is_coatom, \u03bb h, h.is_maximal\u27e9\n\nend directed\n\nsection order_bot\nvariables [order_bot P]\n\n@[simp] lemma bot_mem (s : ideal P) : \u22a5 \u2208 s := s.lower bot_le s.nonempty.some_mem\n\nend order_bot\n\nsection order_top\nvariables [order_top P] {I : ideal P}\n\nlemma top_of_top_mem (h : \u22a4 \u2208 I) : I = \u22a4 := by { ext, exact iff_of_true (I.lower le_top h) trivial }\n\nlemma is_proper.top_not_mem (hI : is_proper I) : \u22a4 \u2209 I := \u03bb h, hI.ne_top $ top_of_top_mem h\n\nend order_top\nend has_le\n\nsection preorder\nvariables [preorder P]\n\nsection\nvariables {I J : ideal P} {x y : P}\n\n/-- The smallest ideal containing a given element. -/\n@[simps] def principal (p : P) : ideal P :=\n{ to_lower_set := lower_set.Iic p,\n  nonempty' := nonempty_Iic,\n  directed' := \u03bb x hx y hy, \u27e8p, le_rfl, hx, hy\u27e9 }\n\ninstance [inhabited P] : inhabited (ideal P) := \u27e8ideal.principal default\u27e9\n\n@[simp] lemma principal_le_iff : principal x \u2264 I \u2194 x \u2208 I :=\n\u27e8\u03bb h, h le_rfl, \u03bb hx y hy, I.lower hy hx\u27e9\n\n@[simp] lemma mem_principal : x \u2208 principal y \u2194 x \u2264 y := iff.rfl\n\nend\n\nsection order_bot\nvariables [order_bot P]\n\n/-- There is a bottom ideal when `P` has a bottom element. -/\ninstance : order_bot (ideal P) :=\n{ bot := principal \u22a5,\n  bot_le := by simp }\n\n@[simp] lemma principal_bot : principal (\u22a5 : P) = \u22a5 := rfl\n\nend order_bot\n\nsection order_top\nvariables [order_top P]\n\n@[simp] lemma principal_top : principal (\u22a4 : P) = \u22a4 := to_lower_set_injective $ lower_set.Iic_top\n\nend order_top\nend preorder\n\nsection semilattice_sup\nvariables [semilattice_sup P] {x y : P} {I s : ideal P}\n\n/-- A specific witness of `I.directed` when `P` has joins. -/\nlemma sup_mem (hx : x \u2208 s) (hy : y \u2208 s) : x \u2294 y \u2208 s :=\nlet \u27e8z, hz, hx, hy\u27e9 := s.directed x hx y hy in s.lower (sup_le hx hy) hz\n\n@[simp] lemma sup_mem_iff : x \u2294 y \u2208 I \u2194 x \u2208 I \u2227 y \u2208 I :=\n\u27e8\u03bb h, \u27e8I.lower le_sup_left h, I.lower le_sup_right h\u27e9, \u03bb h, sup_mem h.1 h.2\u27e9\n\nend semilattice_sup\n\nsection semilattice_sup_directed\nvariables [semilattice_sup P] [is_directed P (\u2265)] {x : P} {I J K s t : ideal P}\n\n/-- The infimum of two ideals of a co-directed order is their intersection. -/\ninstance : has_inf (ideal P) :=\n\u27e8\u03bb I J, { to_lower_set := I.to_lower_set \u2293 J.to_lower_set,\n  nonempty' := inter_nonempty I J,\n  directed' := \u03bb x hx y hy, \u27e8x \u2294 y, \u27e8sup_mem hx.1 hy.1, sup_mem hx.2 hy.2\u27e9, by simp\u27e9 }\u27e9\n\n/-- The supremum of two ideals of a co-directed order is the union of the down sets of the pointwise\nsupremum of `I` and `J`. -/\ninstance : has_sup (ideal P) :=\n\u27e8\u03bb I J, { carrier   := {x | \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j},\n  nonempty' := by { cases inter_nonempty I J, exact \u27e8w, w, h.1, w, h.2, le_sup_left\u27e9 },\n  directed' := \u03bb x \u27e8xi, _, xj, _, _\u27e9 y \u27e8yi, _, yj, _, _\u27e9,\n    \u27e8x \u2294 y,\n     \u27e8xi \u2294 yi, sup_mem \u2039_\u203a \u2039_\u203a,\n      xj \u2294 yj, sup_mem \u2039_\u203a \u2039_\u203a,\n      sup_le\n        (calc x \u2264 xi \u2294 xj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_left le_sup_left)\n        (calc y \u2264 yi \u2294 yj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_right le_sup_right)\u27e9,\n     le_sup_left, le_sup_right\u27e9,\n  lower' := \u03bb x y h \u27e8yi, _, yj, _, _\u27e9, \u27e8yi, \u2039_\u203a, yj, \u2039_\u203a, h.trans \u2039_\u203a\u27e9 }\u27e9\n\ninstance : lattice (ideal P) :=\n{ sup          := (\u2294),\n  le_sup_left  := \u03bb I J (i \u2208 I), by { cases J.nonempty, exact \u27e8i, \u2039_\u203a, w, \u2039_\u203a, le_sup_left\u27e9 },\n  le_sup_right := \u03bb I J (j \u2208 J), by { cases I.nonempty, exact \u27e8w, \u2039_\u203a, j, \u2039_\u203a, le_sup_right\u27e9 },\n  sup_le       := \u03bb I J K hIK hJK a \u27e8i, hi, j, hj, ha\u27e9,\n    K.lower ha $ sup_mem (mem_of_mem_of_le hi hIK) (mem_of_mem_of_le hj hJK),\n  inf          := (\u2293),\n  inf_le_left  := \u03bb I J, inter_subset_left I J,\n  inf_le_right := \u03bb I J, inter_subset_right I J,\n  le_inf       := \u03bb I J K, subset_inter,\n  .. ideal.partial_order }\n\n@[simp] lemma coe_sup : \u2191(s \u2294 t) = {x | \u2203 (a \u2208 s) (b \u2208 t), x \u2264 a \u2294 b} := rfl\n@[simp] lemma coe_inf : (\u2191(s \u2293 t) : set P) = s \u2229 t := rfl\n@[simp] lemma mem_inf : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J := iff.rfl\n@[simp] lemma mem_sup : x \u2208 I \u2294 J \u2194 \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j := iff.rfl\n\nlemma lt_sup_principal_of_not_mem (hx : x \u2209 I) : I < I \u2294 principal x :=\nle_sup_left.lt_of_ne $ \u03bb h, hx $ by simpa only [left_eq_sup, principal_le_iff] using h\n\nend semilattice_sup_directed\n\nsection semilattice_sup_order_bot\nvariables [semilattice_sup P] [order_bot P] {x : P} {I J K : ideal P}\n\ninstance : has_Inf (ideal P) :=\n\u27e8\u03bb S, { to_lower_set := \u2a05 s \u2208 S, to_lower_set s,\n  nonempty' := \u27e8\u22a5, begin\n    rw [lower_set.carrier_eq_coe, lower_set.coe_infi\u2082, set.mem_Inter\u2082],\n    exact \u03bb s _, s.bot_mem,\n  end\u27e9,\n  directed' := \u03bb a ha b hb, \u27e8a \u2294 b, \u27e8\n    begin\n      rw [lower_set.carrier_eq_coe, lower_set.coe_infi\u2082, set.mem_Inter\u2082] at \u22a2 ha hb,\n      exact \u03bb s hs, sup_mem (ha _ hs) (hb _ hs),\n    end,\n    le_sup_left, le_sup_right\u27e9\u27e9 }\u27e9\n\nvariables {S : set (ideal P)}\n\n@[simp] lemma coe_Inf : (\u2191(Inf S) : set P) = \u22c2 s \u2208 S, \u2191s := lower_set.coe_infi\u2082 _\n\n@[simp] lemma mem_Inf : x \u2208 Inf S \u2194 \u2200 s \u2208 S, x \u2208 s :=\nby simp_rw [\u2190set_like.mem_coe, coe_Inf, mem_Inter\u2082]\n\ninstance : complete_lattice (ideal P) :=\n{ ..ideal.lattice,\n  ..complete_lattice_of_Inf (ideal P) (\u03bb S, begin\n    refine \u27e8\u03bb s hs, _, \u03bb s hs, by rwa [\u2190coe_subset_coe, coe_Inf, subset_Inter\u2082_iff]\u27e9,\n    rw [\u2190coe_subset_coe, coe_Inf],\n    exact bInter_subset_of_mem hs,\n  end) }\n\nend semilattice_sup_order_bot\n\nsection distrib_lattice\n\nvariables [distrib_lattice P]\nvariables {I J : ideal P}\n\nlemma eq_sup_of_le_sup {x i j: P} (hi : i \u2208 I) (hj : j \u2208 J) (hx : x \u2264 i \u2294 j) :\n  \u2203 (i' \u2208 I) (j' \u2208 J), x = i' \u2294 j' :=\nbegin\n  refine \u27e8x \u2293 i, I.lower inf_le_right hi, x \u2293 j, J.lower inf_le_right hj, _\u27e9,\n  calc\n  x    = x \u2293 (i \u2294 j)       : left_eq_inf.mpr hx\n  ...  = (x \u2293 i) \u2294 (x \u2293 j) : inf_sup_left,\nend\n\nlemma coe_sup_eq : \u2191(I \u2294 J) = {x | \u2203 i \u2208 I, \u2203 j \u2208 J, x = i \u2294 j} :=\nset.ext $ \u03bb _, \u27e8\u03bb \u27e8_, _, _, _, _\u27e9, eq_sup_of_le_sup \u2039_\u203a \u2039_\u203a \u2039_\u203a,\n  \u03bb \u27e8i, _, j, _, _\u27e9, \u27e8i, \u2039_\u203a, j, \u2039_\u203a, le_of_eq \u2039_\u203a\u27e9\u27e9\n\nend distrib_lattice\n\nsection boolean_algebra\n\nvariables [boolean_algebra P] {x : P} {I : ideal P}\n\nlemma is_proper.not_mem_of_compl_mem (hI : is_proper I) (hxc : x\u1d9c \u2208 I) : x \u2209 I :=\nbegin\n  intro hx,\n  apply hI.top_not_mem,\n  have ht : x \u2294 x\u1d9c \u2208 I := sup_mem \u2039_\u203a \u2039_\u203a,\n  rwa sup_compl_eq_top at ht,\nend\n\nlemma is_proper.not_mem_or_compl_not_mem (hI : is_proper I) : x \u2209 I \u2228 x\u1d9c \u2209 I :=\nhave h : x\u1d9c \u2208 I \u2192 x \u2209 I := hI.not_mem_of_compl_mem, by tauto\n\nend boolean_algebra\n\nend ideal\n\n/-- For a preorder `P`, `cofinal P` is the type of subsets of `P`\n  containing arbitrarily large elements. They are the dense sets in\n  the topology whose open sets are terminal segments. -/\nstructure cofinal (P) [preorder P] :=\n(carrier : set P)\n(mem_gt  : \u2200 x : P, \u2203 y \u2208 carrier, x \u2264 y)\n\nnamespace cofinal\n\nvariables [preorder P]\n\ninstance : inhabited (cofinal P) :=\n\u27e8{ carrier := univ, mem_gt := \u03bb x, \u27e8x, trivial, le_rfl\u27e9 }\u27e9\n\ninstance : has_mem P (cofinal P) := \u27e8\u03bb x D, x \u2208 D.carrier\u27e9\n\nvariables (D : cofinal P) (x : P)\n/-- A (noncomputable) element of a cofinal set lying above a given element. -/\nnoncomputable def above : P := classical.some $ D.mem_gt x\n\nlemma above_mem : D.above x \u2208 D :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb a _, a\n\nlemma le_above : x \u2264 D.above x :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb _ b, b\n\nend cofinal\n\nsection ideal_of_cofinals\n\nvariables [preorder P] (p : P) {\u03b9 : Type*} [encodable \u03b9] (\ud835\udc9f : \u03b9 \u2192 cofinal P)\n\n/-- Given a starting point, and a countable family of cofinal sets,\n  this is an increasing sequence that intersects each cofinal set. -/\nnoncomputable def sequence_of_cofinals : \u2115 \u2192 P\n| 0 := p\n| (n+1) := match encodable.decode \u03b9 n with\n           | none   := sequence_of_cofinals n\n           | some i := (\ud835\udc9f i).above (sequence_of_cofinals n)\n           end\n\nlemma sequence_of_cofinals.monotone : monotone (sequence_of_cofinals p \ud835\udc9f) :=\nby { apply monotone_nat_of_le_succ, intros n, dunfold sequence_of_cofinals,\n  cases encodable.decode \u03b9 n, { refl }, { apply cofinal.le_above }, }\n\nlemma sequence_of_cofinals.encode_mem (i : \u03b9) :\n  sequence_of_cofinals p \ud835\udc9f (encodable.encode i + 1) \u2208 \ud835\udc9f i :=\nby { dunfold sequence_of_cofinals, rw encodable.encodek, apply cofinal.above_mem, }\n\n/-- Given an element `p : P` and a family `\ud835\udc9f` of cofinal subsets of a preorder `P`,\n  indexed by a countable type, `ideal_of_cofinals p \ud835\udc9f` is an ideal in `P` which\n  - contains `p`, according to `mem_ideal_of_cofinals p \ud835\udc9f`, and\n  - intersects every set in `\ud835\udc9f`, according to `cofinal_meets_ideal_of_cofinals p \ud835\udc9f`.\n\n  This proves the Rasiowa\u2013Sikorski lemma. -/\ndef ideal_of_cofinals : ideal P :=\n{ carrier   := { x : P | \u2203 n, x \u2264 sequence_of_cofinals p \ud835\udc9f n },\n  lower'     := \u03bb x y hxy \u27e8n, hn\u27e9, \u27e8n, le_trans hxy hn\u27e9,\n  nonempty' := \u27e8p, 0, le_rfl\u27e9,\n  directed' := \u03bb x \u27e8n, hn\u27e9 y \u27e8m, hm\u27e9,\n               \u27e8_, \u27e8max n m, le_rfl\u27e9,\n               le_trans hn $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_left _ _),\n               le_trans hm $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_right _ _) \u27e9 }\n\nlemma mem_ideal_of_cofinals : p \u2208 ideal_of_cofinals p \ud835\udc9f := \u27e80, le_rfl\u27e9\n\n/-- `ideal_of_cofinals p \ud835\udc9f` is `\ud835\udc9f`-generic. -/\nlemma cofinal_meets_ideal_of_cofinals (i : \u03b9) : \u2203 x : P, x \u2208 \ud835\udc9f i \u2227 x \u2208 ideal_of_cofinals p \ud835\udc9f :=\n\u27e8_, sequence_of_cofinals.encode_mem p \ud835\udc9f i, _, le_rfl\u27e9\n\nend ideal_of_cofinals\n\nend order\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7128514775943157}}
{"text": "-- La funci\u00f3n identidad no est\u00e1 acotada superiormente\n-- ==================================================\n\nimport data.real.basic\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la funci\u00f3n\n--    acotada_superiormente : (\u211d \u2192 \u211d) \u2192 Prop\n-- tal que (acotada_superiormente f) expresa que la\n-- funci\u00f3n f est\u00e1 acotada superiormente.\n-- ----------------------------------------------------\n\ndef acotada_superiormente : (\u211d \u2192 \u211d) \u2192 Prop\n| f := \u2203 M, \u2200 x, f x \u2264 M\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que la funci\u00f3n identidad no\n-- est\u00e1 acotada superiormente.\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nbegin\n  unfold acotada_superiormente,\n  unfold id,\n  by_contradiction h,\n  cases h with M hM,\n  specialize hM (M+1),\n  contrapose hM,\n  simp only [not_le],\n  exact lt_add_one M,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nbegin\n  unfold acotada_superiormente id,\n  push_neg,\n  intro M,\n  use M + 1,\n  linarith,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nbegin\n  unfold acotada_superiormente id,\n  push_neg,\n  exact no_top,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nassume h1 : acotada_superiormente id,\nhave h2 : \u2203 M, \u2200 x, id x \u2264 M,\n  from h1,\nshow false, from\n  exists.elim h2\n    ( assume M,\n      assume hM : \u2200 x, id x \u2264 M,\n      have h3 : M + 1 \u2264 M,\n        from hM (M+1),\n      have h4 : \u00ac(M < M + 1),\n        from not_lt.mpr h3,\n      have h5 : M < M + 1,\n        from lt_add_one M,\n      show false,\n        from h4 h5)\n\n-- 5\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nassume h1 : acotada_superiormente id,\nhave h2 : \u2203 M, \u2200 x, id x \u2264 M,\n  from h1,\nshow false, from\n  exists.elim h2\n    ( assume M,\n      assume hM : \u2200 x, id x \u2264 M,\n      have h3 : M + 1 \u2264 M,\n        from hM (M+1),\n      have h4 : \u00ac(M < M + 1),\n        from not_lt.mpr h3,\n      have h5 : M < M + 1,\n        from lt_add_one M,\n      h4 h5)\n\n-- 6\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nassume h1 : acotada_superiormente id,\nhave h2 : \u2203 M, \u2200 x, id x \u2264 M,\n  from h1,\nshow false, from\n  exists.elim h2\n    ( assume M,\n      assume hM : \u2200 x, id x \u2264 M,\n      have h3 : M + 1 \u2264 M,\n        from hM (M+1),\n      (not_lt.mpr h3) (lt_add_one M))\n\n-- 7\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nassume h1 : acotada_superiormente id,\nhave h2 : \u2203 M, \u2200 x, id x \u2264 M,\n  from h1,\nshow false, from\n  exists.elim h2\n    ( assume M,\n      assume hM : \u2200 x, id x \u2264 M,\n      (not_lt.mpr (hM (M+1))) (lt_add_one M))\n\n-- 8\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nassume h1 : acotada_superiormente id,\nhave h2 : \u2203 M, \u2200 x, id x \u2264 M,\n  from h1,\nshow false, from\n  exists.elim h2\n    (\u03bb M hM, (not_lt.mpr (hM (M+1))) (lt_add_one M))\n\n-- 9\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nassume h1 : acotada_superiormente id,\nhave h2 : \u2203 M, \u2200 x, id x \u2264 M,\n  from h1,\nexists.elim h2\n  (\u03bb M hM, (not_lt.mpr (hM (M+1))) (lt_add_one M))\n\n-- 10\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\nassume h1 : acotada_superiormente id,\nexists.elim h1\n  (\u03bb M hM, (not_lt.mpr (hM (M+1))) (lt_add_one M))\n\n-- 11\u00aa demostraci\u00f3n\nexample : \u00acacotada_superiormente id :=\n\u03bb h1, exists.elim h1 (\u03bb M hM, (not_lt.mpr (hM (M+1))) (lt_add_one M))\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/4_Contradiccion_y_negacion/La_funcion_identidad_no_esta_acotada_superiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7128514689123205}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n\n! This file was ported from Lean 3 source module algebra.order.sub.basic\n! leanprover-community/mathlib commit 10b4e499f43088dd3bb7b5796184ad5216648ab1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Hom.Basic\nimport Mathlib.Algebra.Hom.Equiv.Basic\nimport Mathlib.Algebra.Ring.Basic\nimport Mathlib.Algebra.Order.Sub.Defs\n\n/-!\n# Additional results about ordered Subtraction\n\n-/\n\n\nvariable {\u03b1 \u03b2 : Type _}\n\nsection Add\n\nvariable [Preorder \u03b1] [Add \u03b1] [Sub \u03b1] [OrderedSub \u03b1] {a b c d : \u03b1}\n\ntheorem AddHom.le_map_tsub [Preorder \u03b2] [Add \u03b2] [Sub \u03b2] [OrderedSub \u03b2] (f : AddHom \u03b1 \u03b2)\n    (hf : Monotone f) (a b : \u03b1) : f a - f b \u2264 f (a - b) := by\n  rw [tsub_le_iff_right, \u2190 f.map_add]\n  exact hf le_tsub_add\n#align add_hom.le_map_tsub AddHom.le_map_tsub\n\ntheorem le_mul_tsub {R : Type _} [Distrib R] [Preorder R] [Sub R] [OrderedSub R]\n    [CovariantClass R R (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] {a b c : R} : a * b - a * c \u2264 a * (b - c) :=\n  (AddHom.mulLeft a).le_map_tsub (monotone_id.const_mul' a) _ _\n#align le_mul_tsub le_mul_tsub\n\ntheorem le_tsub_mul {R : Type _} [CommSemiring R] [Preorder R] [Sub R] [OrderedSub R]\n    [CovariantClass R R (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] {a b c : R} : a * c - b * c \u2264 (a - b) * c := by\n  simpa only [mul_comm _ c] using le_mul_tsub\n#align le_tsub_mul le_tsub_mul\n\nend Add\n\n/-- An order isomorphism between types with ordered subtraction preserves subtraction provided that\nit preserves addition. -/\ntheorem OrderIso.map_tsub {M N : Type _} [Preorder M] [Add M] [Sub M] [OrderedSub M]\n    [PartialOrder N] [Add N] [Sub N] [OrderedSub N] (e : M \u2243o N)\n    (h_add : \u2200 a b, e (a + b) = e a + e b) (a b : M) : e (a - b) = e a - e b := by\n  let e_add : M \u2243+ N := { e with map_add' := h_add }\n  refine' le_antisymm _ (e_add.toAddHom.le_map_tsub e.monotone a b)\n  suffices e (e.symm (e a) - e.symm (e b)) \u2264 e (e.symm (e a - e b)) by simpa\n  exact e.monotone (e_add.symm.toAddHom.le_map_tsub e.symm.monotone _ _)\n#align order_iso.map_tsub OrderIso.map_tsub\n\n/-! ### Preorder -/\n\n\nsection Preorder\n\nvariable [Preorder \u03b1]\n\nvariable [AddCommMonoid \u03b1] [Sub \u03b1] [OrderedSub \u03b1] {a b c d : \u03b1}\n\ntheorem AddMonoidHom.le_map_tsub [Preorder \u03b2] [AddCommMonoid \u03b2] [Sub \u03b2] [OrderedSub \u03b2] (f : \u03b1 \u2192+ \u03b2)\n    (hf : Monotone f) (a b : \u03b1) : f a - f b \u2264 f (a - b) :=\n  f.toAddHom.le_map_tsub hf a b\n#align add_monoid_hom.le_map_tsub AddMonoidHom.le_map_tsub\n\nend Preorder\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/Sub/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7128514689123204}}
{"text": "/-\n0. Read the class notes through Section \n3.7, Implication. It is important that \nyou do this before classes next week, as\nwe will move somewhat quickly through a\nfew of these chapters.\n\nTo complete the rest of this homework,\nsolve the problems given as specified,\nthen save and submit this file.\n-/\n\n\n/-\n1. \n\nShow that if you're given proofs\nof a = b and c = b you can construct\na proof of a = c. Do it by completing\nthe following function. \n-/\n\ndef eq_snart { T : Type}\n             { a b c: T }\n             (ab: a = b)\n             (cb: c = b) : \n             a = c :=\neq.trans\n    ab\n    (eq.symm cb)\n\n/-\nNow given the following assumptions, apply\nyour newly proved inference rule, eq.snart,\n(!) to show that Harry = Bob.\n-/\n\naxiom Person : Type\naxioms Harry Bob Jose: Person\naxioms (hj : Harry = Bob) (jb : Jose = Bob)\nexample : Harry = Jose := eq_snart hj jb\n\n/-\nNote: This problem featured the use of a \nlogically correct but humanly midleading\nidentifier, hj, for a proof of Harry=Bob.\nIt would have been better style to call it\nhb. That said, the proof goes through just\nfine. Ultimately the main rules that one\nmust follow when it comes to identifiers\nis to avoid using conflicting identifiers.\nThere is a more subtle rule when it comes\nto the elimination for for existentially\nquantified propositions. We'll get there. \nFor now, it's a good practice to avoid\nusing misleading idenifiers, even if they\nare logically ok.\n-/\n\n/-\n2. Use example to assert and then prove that\nif T is any type, and if a, b, c, and d, are\nvalues of that type, and if you have proofs of\na = b, b = c, and c = d, you can construct a \nproof of a = d. Put the proposition in the first\nplaceholder below, and the proof in the second.\n\nHint: Aquality propositions are types. Think of\nthe problem here as one of producing a function\nof the specific type. Use lambdas. We've gotten\nyou started. The first lambda \"assumes\" that a,\nb, c, and d are natural numbers. What's left to\ndo is to prove a function (yes, start with lambda)\nthat takes three arguments of the specified kinds \n(use lambda to give them names) and that finally\nproduces a result of the type at the end of the \nchain.\n-/\n\ntheorem transit : \n\u2200 a b c d : \u2115, \n    (a = b) \u2192 (b = c) \u2192 (c = d) \u2192 (a = d) \n:= \n    \u03bb a b c d,\n        \u03bb ab bc cd,\n            eq.trans (eq.trans ab bc) cd\n\n/-\n3. In the context of the axioms in the following\nnamespace, write an exact proof term to prove \nthat Yuanfang is friendly. Hint #1: Just apply \nthe relevant inference rule as a function to the\nright arguments. Hint #2: The direction in which\nan equality is written matters. If, for example,\nyou have a proof of x = y and you want to apply \nan inference rule that requires a proof of y = x,\nthen you need to find a way to get what you need\nfrom what you have to work with in your context.\n-/\n\naxioms Mary Yuanfang : Person\naxiom Friendly : Person \u2192 Prop\naxiom mf : Friendly Mary\naxiom yeqm : Yuanfang = Mary\nexample : Friendly Yuanfang :=\n    eq.subst (eq.symm yeqm) mf\n\n\n/-\n4. The subtitution rule for equality lets\nyou rewrite proof goals by substituting one \nterm for another, in a goal, as long as you \nalready have a proof that the two  terms \nare equal. The reasoning is that replacing \none term with another makes no difference to \nthe truth of a proposition if the two terms\nare equal. \n\nSuppose for example that you have a proof, \nh, of y = x (yes we can and do give names \nto proofs, as we consider them to be values), \nand a proof, y1, of y = 1, and that your \ngoal is to prove (x = 1). You can justify \nrewriting this goal as (y = 1), for which \nyou already have a proof, because you know \nthat y = x; so making this substitution \ndoesn't change the truth of the proposition. \n\nIn the tactic scripting libraries that Lean\nprovides, there is a tactic for rewriting a \ngoal in this way. If h is a proof of x = y,\nthen the tactic, \"rw h\" (\"rw\" is short for \n\"rewrite\") replaces all occurrences of x (the \nleft side of h) with y (it's right side).\n\nHere's an example.\n-/\n\ndef foo (x y : \u2115) (y1 : y = 1) (h: x = y) : (x = 1) :=\nbegin\nrewrite h,\nexact y1,\nend\n\n\n/-\nUse what you just learned to state and prove \nthe proposition that for any type, T, and for \nany objects, a, b, and c, of this type, if \n(a = b) and (b = c) then (c = a). Do this by\nfinishing off the tactic script that follows.  \nNote that to apply an inference rule within a\ntactic script you use the \"apply\" tactic. Read \nthe further explanation and hint that follow \nbefore attempting to solve this problem.\n-/\n\ndef ac (T : Type) (a b c : T) \n       (ab : a = b) (bc : b = c) \n    : (c = a) := \nbegin\napply eq.symm (eq.trans ab bc)\nend\n\n/-\nNote that the \"foralls\" in the natural language \nstatement are represented in this code *not* by \nusing  \u2200 but by declaring them to be arguments \nto our function. If you can write a function of \nthe specified type then you have in effect proven\nthat for *any* T and any a, b, c, of type T, if \nif you also have a proof of a=b and a proof of \nb=c, then a value of type c=a can be constructed \nand returned. The reason this is true is that in\nLean all functions are total, as you now recall!\n\nKey hint: The tactic application \"rw h\" changes\nall occurrences of the left side of the equality\nh, in the goal, into what's on its right side. \nIf you want the rewriting to go from right to \nleft, use \"rw<-h\". When you're just about done, \ndon't be surprised if the rewrite tactic applies \nrfl automatically.\n-/", "meta": {"author": "kevinsullivan", "repo": "uva-cs-dm-s19", "sha": "3e7177682acdb56a2d16914e0344c10335583dcf", "save_path": "github-repos/lean/kevinsullivan-uva-cs-dm-s19", "path": "github-repos/lean/kevinsullivan-uva-cs-dm-s19/uva-cs-dm-s19-3e7177682acdb56a2d16914e0344c10335583dcf/answers/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.7128023827200055}}
{"text": "import function.misc\nimport function.bijection\nimport data.list.misc\nimport data.list.map_partial\nimport data.list.index\nimport data.finord\n\n--- Exhaustive list of elements of given type; i.e. a list that contains all the terms of given type with no duplicate entries.\n@[reducible,inline]\ndefinition exhaustive_list (\u03b1 : Type _) := {l : list \u03b1 // l.nodup \u2227 \u2200 x, x \u2208 l}\n\n--- The standard exhaustive list of elements of type `finord n`.\nprotected\ndefinition finord.exhaustive_list (n : \u2115) : exhaustive_list (finord n) :=\n  nat.rec_on n\n    /- n=0 -/ \u27e8[],\u27e8list.nodup.nil, \u03bb x, by cases x\u27e9\u27e9\n    /- n=k+1 -/ (\n      \u03bb k l_ind, subtype.mk (finord.fz :: l_ind.val.map finord.fs) $\n        begin\n          split,\n          show list.nodup _, {\n            refine list.nodup.cons _ _,\n            exact list.not_mem_map_of_offimage finord.fz (@finord.fz_not_fs k),\n            exact list.nodup_map_of_nodup finord.fs_inj l_ind.property.left\n          },\n          show \u2200 x, x \u2208 _, {\n            intros x; cases x with _ _ j,\n            exact or.inl rfl,\n            exact or.inr (list.mem_map_of_mem j _ (l_ind.property.right j))\n          }\n        end\n    )\n\nnamespace exhaustive_list\n\nprotected\nlemma nodup {\u03b1 : Type _} (l : exhaustive_list \u03b1) : l.val.nodup := l.property.left\n\nprotected\nlemma exhaustive {\u03b1 : Type _} (l : exhaustive_list \u03b1) : \u2200 x, x \u2208 l.val := l.property.right\n\n--- `exhaustive_list \u03b1` is, if any, unique up to permutations.\nprotected\nlemma perm {\u03b1 : Type _} (l l': exhaustive_list \u03b1) : l.val.perm l'.val :=\n  list.nodup_perm_of_mem l.nodup l'.nodup $\n    \u03bb x, calc\n      x \u2208 l.val \u2194 true : iff_true_intro (l.exhaustive x)\n      ...       \u2194 x \u2208 l'.val : (iff_true_intro (l'.exhaustive x)).symm\n\n--- Translate `exhaustive_list` along bijections.\nprotected\ndefinition translate {\u03b1 \u03b2 : Type _} {f : \u03b1 \u2192 \u03b2} : function.bijective f \u2192 exhaustive_list \u03b1 \u2192 exhaustive_list \u03b2 :=\n  \u03bb hbij l, subtype.mk (l.val.map f) $\n    begin\n      split,\n      show list.nodup _, {\n        exact list.nodup_map_of_nodup hbij.left l.property.left\n      },\n      show \u2200 x, x \u2208 _, {\n        intros x,\n        cases hbij.right x with y hy; rw [\u2190hy],\n        apply list.mem_map_of_mem _ _ (l.property.right y),\n      }\n    end\n\n--- Convert an `exhaustive_list` into a bijection out of a finite set.\nprotected\ndefinition to_bijection {\u03b1 : Type _} [decidable_eq \u03b1] (l : exhaustive_list \u03b1) : bijection (finord l.val.length) \u03b1 :=\n  (bijection.subtype_true \u03b1).comp $\n    bijection.comp\n      (@bijection.subtype_equiv _ (\u03bb x, x \u2208 l.val) (\u03bb _, true) (\u03bb x, iff_true_intro (l.property.right x)))\n      (list.enum_bijection l.property.left)\n\nend exhaustive_list\n\n\n--- Class for types that are isomorphic to `finord n` for some `n`.\nclass is_finite (\u03b1 : Type _) : Prop :=\n  (enumerable : \u2203 (n : \u2115) (f : finord n \u2192 \u03b1), function.bijective f)\n\ninstance finord_is_finite {n : \u2115} : is_finite (finord n) :=\n  is_finite.mk \u27e8n, id, bijection.id.is_bijective\u27e9\n\n@[reducible,inline]\ndefinition enumerable (\u03b1 : Type _) [is_finite \u03b1] : \u2203 (n : \u2115) (f : finord n \u2192 \u03b1), function.bijective f :=\n  is_finite.enumerable\n\nnamespace is_finite\n\n--- Every finite type must be internally decidable.\nprotected\nlemma has_idecidable_eq {\u03b1 : Type _} [is_finite \u03b1] : idecidable_eq \u03b1 :=\n  begin\n    intros x y,\n    constructor,\n    cases _root_.enumerable \u03b1 with n ef; cases ef with f hf,\n    cases hf.right x with a ha,\n    cases hf.right y with b hb,\n    refine dite (a=b) _ _,\n    show a = b \u2192 _, {\n      intros hab,\n      apply or.inl,\n      calc\n        x   = f a : ha.symm\n        ... = f b : congr_arg f hab\n        ... = y : hb\n    },\n    show a \u2260 b \u2192 _, {\n      intros hab,\n      apply or.inr,\n      intros hxy,\n      refine hab (hf.left _),\n      calc\n        f a = x : ha\n        ... = y : hxy\n        ... = f b : hb.symm\n    }\n  end\n\n--- Every finite type admits a complete list of elements.\nlemma has_exhaustive_list (\u03b1 : Type _) [is_finite \u03b1] : nonempty (exhaustive_list \u03b1) :=\n  begin\n    cases _root_.enumerable \u03b1 with n ef; cases ef with f hf,\n    constructor,\n    apply exhaustive_list.translate hf,\n    exact finord.exhaustive_list n,\n  end\n\n--- Given `exhausitve_list \u03b1`, one can conclude `\u03b1` is a finite type.\nprotected\ntheorem of_exhaustive_list {\u03b1 : Type _} [decidable_eq \u03b1] (l : exhaustive_list \u03b1) : is_finite \u03b1 :=\n  is_finite.mk \u27e8l.val.length, l.to_bijection.to_fun, l.to_bijection.is_bijective\u27e9\n\nend is_finite\n", "meta": {"author": "Junology", "repo": "groth-lean", "sha": "5aa1ba624cd0f5145f63fa86130f99b85bbbcac2", "save_path": "github-repos/lean/Junology-groth-lean", "path": "github-repos/lean/Junology-groth-lean/groth-lean-5aa1ba624cd0f5145f63fa86130f99b85bbbcac2/src/logic/finite/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7128023773070652}}
{"text": "-- Math 52: Quiz 5\n-- Open this file in a folder that contains 'utils'.\n\nimport utils\nopen classical\n\ndefinition divides (a b : \u2124) : Prop := \u2203 (k : \u2124), b = a * k\nlocal infix \u2223 := divides\n\naxiom not_3_divides : \u2200 (m : \u2124), \u00ac (3 \u2223 m) \u2194 3 \u2223 m - 1 \u2228 3 \u2223 m + 1\n\nlemma not_3_divides_of_3_divides_minus_1 : \n\u2200 (m : \u2124), 3 \u2223 m - 1 \u2192 \u00ac (3 \u2223 m) :=\nbegin\nintros m H,\nrw not_3_divides,\nleft,\nassumption, \nend\n\nlemma not_3_divides_of_3_divides_plus_1 : \n\u2200 (m : \u2124), 3 \u2223 m + 1 \u2192 \u00ac (3 \u2223 m) :=\nbegin\nintros m H,\nrw not_3_divides,\nright,\nassumption, \nend\n\ntheorem main : \u2200 (n : \u2124), 3 \u2223 n * n - 1 \u2192 \u00ac (3 \u2223 n) :=\nbegin\nintro n,\nby_contrapositive,\n\n\n\n\n\nend\n", "meta": {"author": "UVM-M52", "repo": "quiz-5-maddiestrauss", "sha": "214529615e08bbcdd3d6600c89432ec985e6ba3a", "save_path": "github-repos/lean/UVM-M52-quiz-5-maddiestrauss", "path": "github-repos/lean/UVM-M52-quiz-5-maddiestrauss/quiz-5-maddiestrauss-214529615e08bbcdd3d6600c89432ec985e6ba3a/src/quiz05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.754914997895581, "lm_q1q2_score": 0.7127732726092306}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro\n-/\nimport data.prod.basic\nimport data.subtype\n\n/-!\n# Basic definitions about `\u2264` and `<`\n\nThis file proves basic results about orders, provides extensive dot notation, defines useful order\nclasses and allows to transfer order instances.\n\n## Type synonyms\n\n* `order_dual \u03b1` : A type synonym reversing the meaning of all inequalities, with notation `\u03b1\u1d52\u1d48`.\n* `as_linear_order \u03b1`: A type synonym to promote `partial_order \u03b1` to `linear_order \u03b1` using\n  `is_total \u03b1 (\u2264)`.\n\n### Transfering orders\n\n- `order.preimage`, `preorder.lift`: Transfers a (pre)order on `\u03b2` to an order on `\u03b1`\n  using a function `f : \u03b1 \u2192 \u03b2`.\n- `partial_order.lift`, `linear_order.lift`: Transfers a partial (resp., linear) order on `\u03b2` to a\n  partial (resp., linear) order on `\u03b1` using an injective function `f`.\n\n### Extra class\n\n- `densely_ordered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such\n  that `a < c < b`.\n\n## Notes\n\n`\u2264` and `<` are highly favored over `\u2265` and `>` in mathlib. The reason is that we can formulate all\nlemmas using `\u2264`/`<`, and `rw` has trouble unifying `\u2264` and `\u2265`. Hence choosing one direction spares\nus useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.\n\nDot notation is particularly useful on `\u2264` (`has_le.le`) and `<` (`has_lt.lt`). To that end, we\nprovide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with\n`has_le.le.trans` and can be used to construct `hab.trans hbc : a \u2264 c` when `hab : a \u2264 b`,\n`hbc : b \u2264 c`, `lt_of_le_of_lt` is aliased as `has_le.le.trans_lt` and can be used to construct\n`hab.trans hbc : a < c` when `hab : a \u2264 b`, `hbc : b < c`.\n\n## TODO\n\n- expand module docs\n- automatic construction of dual definitions / theorems\n\n## Tags\n\npreorder, order, partial order, poset, linear order, chain\n-/\n\nopen function\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nsection preorder\nvariables [preorder \u03b1] {a b c : \u03b1}\n\nlemma le_trans' : b \u2264 c \u2192 a \u2264 b \u2192 a \u2264 c := flip le_trans\nlemma lt_trans' : b < c \u2192 a < b \u2192 a < c := flip lt_trans\nlemma lt_of_le_of_lt' : b \u2264 c \u2192 a < b \u2192 a < c := flip lt_of_lt_of_le\nlemma lt_of_lt_of_le' : b < c \u2192 a \u2264 b \u2192 a < c := flip lt_of_le_of_lt\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] {a b : \u03b1}\n\nlemma ge_antisymm : a \u2264 b \u2192 b \u2264 a \u2192 b = a := flip le_antisymm\nlemma lt_of_le_of_ne' : a \u2264 b \u2192 b \u2260 a \u2192 a < b := \u03bb h\u2081 h\u2082, lt_of_le_of_ne h\u2081 h\u2082.symm\nlemma ne.lt_of_le : a \u2260 b \u2192 a \u2264 b \u2192 a < b := flip lt_of_le_of_ne\nlemma ne.lt_of_le' : b \u2260 a \u2192 a \u2264 b \u2192 a < b := flip lt_of_le_of_ne'\n\nend partial_order\n\nattribute [simp] le_refl\nattribute [ext] has_le\n\nalias le_trans        \u2190 has_le.le.trans\nalias le_trans'       \u2190 has_le.le.trans'\nalias lt_of_le_of_lt  \u2190 has_le.le.trans_lt\nalias lt_of_le_of_lt' \u2190 has_le.le.trans_lt'\nalias le_antisymm     \u2190 has_le.le.antisymm\nalias ge_antisymm     \u2190 has_le.le.antisymm'\nalias lt_of_le_of_ne  \u2190 has_le.le.lt_of_ne\nalias lt_of_le_of_ne' \u2190 has_le.le.lt_of_ne'\nalias lt_of_le_not_le \u2190 has_le.le.lt_of_not_le\nalias lt_or_eq_of_le  \u2190 has_le.le.lt_or_eq\nalias decidable.lt_or_eq_of_le \u2190 has_le.le.lt_or_eq_dec\n\nalias le_of_lt        \u2190 has_lt.lt.le\nalias lt_trans        \u2190 has_lt.lt.trans\nalias lt_trans'       \u2190 has_lt.lt.trans'\nalias lt_of_lt_of_le  \u2190 has_lt.lt.trans_le\nalias lt_of_lt_of_le' \u2190 has_lt.lt.trans_le'\nalias ne_of_lt        \u2190 has_lt.lt.ne\nalias lt_asymm        \u2190 has_lt.lt.asymm has_lt.lt.not_lt\n\nalias le_of_eq        \u2190 eq.le\n\nattribute [nolint decidable_classical] has_le.le.lt_or_eq_dec\n\nsection\nvariables [preorder \u03b1] {a b c : \u03b1}\n\n/-- A version of `le_refl` where the argument is implicit -/\nlemma le_rfl : a \u2264 a := le_refl a\n\n@[simp] lemma lt_self_iff_false (x : \u03b1) : x < x \u2194 false := \u27e8lt_irrefl x, false.elim\u27e9\n\nlemma le_of_le_of_eq (hab : a \u2264 b) (hbc : b = c) : a \u2264 c := hab.trans hbc.le\nlemma le_of_eq_of_le (hab : a = b) (hbc : b \u2264 c) : a \u2264 c := hab.le.trans hbc\nlemma lt_of_lt_of_eq (hab : a < b) (hbc : b = c) : a < c := hab.trans_le hbc.le\nlemma lt_of_eq_of_lt (hab : a = b) (hbc : b < c) : a < c := hab.le.trans_lt hbc\nlemma le_of_le_of_eq' : b \u2264 c \u2192 a = b \u2192 a \u2264 c := flip le_of_eq_of_le\nlemma le_of_eq_of_le' : b = c \u2192 a \u2264 b \u2192 a \u2264 c := flip le_of_le_of_eq\nlemma lt_of_lt_of_eq' : b < c \u2192 a = b \u2192 a < c := flip lt_of_eq_of_lt\nlemma lt_of_eq_of_lt' : b = c \u2192 a < b \u2192 a < c := flip lt_of_lt_of_eq\n\nalias le_of_le_of_eq  \u2190 has_le.le.trans_eq\nalias le_of_le_of_eq' \u2190 has_le.le.trans_eq'\nalias lt_of_lt_of_eq  \u2190 has_lt.lt.trans_eq\nalias lt_of_lt_of_eq' \u2190 has_lt.lt.trans_eq'\nalias le_of_eq_of_le  \u2190 eq.trans_le\nalias le_of_eq_of_le' \u2190 eq.trans_ge\nalias lt_of_eq_of_lt  \u2190 eq.trans_lt\nalias lt_of_eq_of_lt' \u2190 eq.trans_gt\n\nend\n\nnamespace eq\nvariables [preorder \u03b1] {x y z : \u03b1}\n\n/-- If `x = y` then `y \u2264 x`. Note: this lemma uses `y \u2264 x` instead of `x \u2265 y`, because `le` is used\nalmost exclusively in mathlib. -/\nprotected \n\nlemma not_lt (h : x = y) : \u00ac x < y := \u03bb h', h'.ne h\nlemma not_gt (h : x = y) : \u00ac y < x := h.symm.not_lt\n\nend eq\n\nnamespace has_le.le\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma ge [has_le \u03b1] {x y : \u03b1} (h : x \u2264 y) : y \u2265 x := h\n\nlemma lt_iff_ne [partial_order \u03b1] {x y : \u03b1} (h : x \u2264 y) : x < y \u2194 x \u2260 y := \u27e8\u03bb h, h.ne, h.lt_of_ne\u27e9\n\nlemma le_iff_eq [partial_order \u03b1] {x y : \u03b1} (h : x \u2264 y) : y \u2264 x \u2194 y = x :=\n\u27e8\u03bb h', h'.antisymm h, eq.le\u27e9\n\nlemma lt_or_le [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a < c \u2228 c \u2264 b :=\n(lt_or_ge a c).imp id $ \u03bb hc, le_trans hc h\n\nlemma le_or_lt [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a \u2264 c \u2228 c < b :=\n(le_or_gt a c).imp id $ \u03bb hc, lt_of_lt_of_le hc h\n\nlemma le_or_le [linear_order \u03b1] {a b : \u03b1} (h : a \u2264 b) (c : \u03b1) : a \u2264 c \u2228 c \u2264 b :=\n(h.le_or_lt c).elim or.inl (\u03bb h, or.inr $ le_of_lt h)\n\nend has_le.le\n\nnamespace has_lt.lt\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma gt [has_lt \u03b1] {x y : \u03b1} (h : x < y) : y > x := h\nprotected lemma false [preorder \u03b1] {x : \u03b1} : x < x \u2192 false := lt_irrefl x\n\nlemma ne' [preorder \u03b1] {x y : \u03b1} (h : x < y) : y \u2260 x := h.ne.symm\n\nlemma lt_or_lt [linear_order \u03b1] {x y : \u03b1} (h : x < y) (z : \u03b1) : x < z \u2228 z < y :=\n(lt_or_ge z y).elim or.inr (\u03bb hz, or.inl $ h.trans_le hz)\n\nend has_lt.lt\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma ge.le [has_le \u03b1] {x y : \u03b1} (h : x \u2265 y) : y \u2264 x := h\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nprotected lemma gt.lt [has_lt \u03b1] {x y : \u03b1} (h : x > y) : y < x := h\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\ntheorem ge_of_eq [preorder \u03b1] {a b : \u03b1} (h : a = b) : a \u2265 b := h.ge\n\n@[simp, nolint ge_or_gt] -- see Note [nolint_ge]\nlemma ge_iff_le [has_le \u03b1] {a b : \u03b1} : a \u2265 b \u2194 b \u2264 a := iff.rfl\n@[simp, nolint ge_or_gt] -- see Note [nolint_ge]\nlemma gt_iff_lt [has_lt \u03b1] {a b : \u03b1} : a > b \u2194 b < a := iff.rfl\n\nlemma not_le_of_lt [preorder \u03b1] {a b : \u03b1} (h : a < b) : \u00ac b \u2264 a := (le_not_le_of_lt h).right\n\nalias not_le_of_lt \u2190 has_lt.lt.not_le\n\nlemma not_lt_of_le [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) : \u00ac b < a := \u03bb hba, hba.not_le h\n\nalias not_lt_of_le \u2190 has_le.le.not_lt\n\nlemma ne_of_not_le [preorder \u03b1] {a b : \u03b1} (h : \u00ac a \u2264 b) : a \u2260 b :=\n\u03bb hab, h (le_of_eq hab)\n\n-- See Note [decidable namespace]\nprotected lemma decidable.le_iff_eq_or_lt [partial_order \u03b1] [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} : a \u2264 b \u2194 a = b \u2228 a < b := decidable.le_iff_lt_or_eq.trans or.comm\n\nlemma le_iff_eq_or_lt [partial_order \u03b1] {a b : \u03b1} : a \u2264 b \u2194 a = b \u2228 a < b :=\nle_iff_lt_or_eq.trans or.comm\n\nlemma lt_iff_le_and_ne [partial_order \u03b1] {a b : \u03b1} : a < b \u2194 a \u2264 b \u2227 a \u2260 b :=\n\u27e8\u03bb h, \u27e8le_of_lt h, ne_of_lt h\u27e9, \u03bb \u27e8h1, h2\u27e9, h1.lt_of_ne h2\u27e9\n\n-- See Note [decidable namespace]\nprotected lemma decidable.eq_iff_le_not_lt [partial_order \u03b1] [@decidable_rel \u03b1 (\u2264)]\n  {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 \u00ac a < b :=\n\u27e8\u03bb h, \u27e8h.le, h \u25b8 lt_irrefl _\u27e9, \u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.antisymm $\n  decidable.by_contradiction $ \u03bb h\u2083, h\u2082 (h\u2081.lt_of_not_le h\u2083)\u27e9\n\nlemma eq_iff_le_not_lt [partial_order \u03b1] {a b : \u03b1} : a = b \u2194 a \u2264 b \u2227 \u00ac a < b :=\nby haveI := classical.dec; exact decidable.eq_iff_le_not_lt\n\nlemma eq_or_lt_of_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2264 b) : a = b \u2228 a < b := h.lt_or_eq.symm\nlemma eq_or_gt_of_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2264 b) : b = a \u2228 a < b :=\nh.lt_or_eq.symm.imp eq.symm id\n\nalias decidable.eq_or_lt_of_le \u2190 has_le.le.eq_or_lt_dec\nalias eq_or_lt_of_le \u2190 has_le.le.eq_or_lt\nalias eq_or_gt_of_le \u2190 has_le.le.eq_or_gt\n\nattribute [nolint decidable_classical] has_le.le.eq_or_lt_dec\n\nlemma eq_of_le_of_not_lt [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) (hba : \u00ac a < b) : a = b :=\nhab.eq_or_lt.resolve_right hba\n\nlemma eq_of_ge_of_not_gt [partial_order \u03b1] {a b : \u03b1} (hab : a \u2264 b) (hba : \u00ac a < b) : b = a :=\n(hab.eq_or_lt.resolve_right hba).symm\n\nalias eq_of_le_of_not_lt \u2190 has_le.le.eq_of_not_lt\nalias eq_of_ge_of_not_gt \u2190 has_le.le.eq_of_not_gt\n\nlemma ne.le_iff_lt [partial_order \u03b1] {a b : \u03b1} (h : a \u2260 b) : a \u2264 b \u2194 a < b :=\n\u27e8\u03bb h', lt_of_le_of_ne h' h, \u03bb h, h.le\u27e9\n\nlemma ne.not_le_or_not_le [partial_order \u03b1] {a b : \u03b1} (h : a \u2260 b) : \u00ac a \u2264 b \u2228 \u00ac b \u2264 a :=\nnot_and_distrib.1 $ le_antisymm_iff.not.1 h\n\n-- See Note [decidable namespace]\nprotected lemma decidable.ne_iff_lt_iff_le [partial_order \u03b1] [decidable_eq \u03b1] {a b : \u03b1} :\n  (a \u2260 b \u2194 a < b) \u2194 a \u2264 b :=\n\u27e8\u03bb h, decidable.by_cases le_of_eq (le_of_lt \u2218 h.mp), \u03bb h, \u27e8lt_of_le_of_ne h, ne_of_lt\u27e9\u27e9\n\n@[simp] lemma ne_iff_lt_iff_le [partial_order \u03b1] {a b : \u03b1} : (a \u2260 b \u2194 a < b) \u2194 a \u2264 b :=\nby haveI := classical.dec; exact decidable.ne_iff_lt_iff_le\n\nlemma lt_of_not_le [linear_order \u03b1] {a b : \u03b1} (h : \u00ac b \u2264 a) : a < b :=\n((le_total _ _).resolve_right h).lt_of_not_le h\n\nlemma lt_iff_not_le [linear_order \u03b1] {x y : \u03b1} : x < y \u2194 \u00ac y \u2264 x := \u27e8not_le_of_lt, lt_of_not_le\u27e9\n\nlemma ne.lt_or_lt [linear_order \u03b1] {x y : \u03b1} (h : x \u2260 y) : x < y \u2228 y < x := lt_or_gt_of_ne h\n\n/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/\n@[simp] lemma lt_or_lt_iff_ne [linear_order \u03b1] {x y : \u03b1} : x < y \u2228 y < x \u2194 x \u2260 y :=\nne_iff_lt_or_gt.symm\n\nlemma not_lt_iff_eq_or_lt [linear_order \u03b1] {a b : \u03b1} : \u00ac a < b \u2194 a = b \u2228 b < a :=\nnot_lt.trans $ decidable.le_iff_eq_or_lt.trans $ or_congr eq_comm iff.rfl\n\nlemma exists_ge_of_linear [linear_order \u03b1] (a b : \u03b1) : \u2203 c, a \u2264 c \u2227 b \u2264 c :=\nmatch le_total a b with\n| or.inl h := \u27e8_, h, le_rfl\u27e9\n| or.inr h := \u27e8_, le_rfl, h\u27e9\nend\n\nlemma lt_imp_lt_of_le_imp_le {\u03b2} [linear_order \u03b1] [preorder \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2192 c \u2264 d) (h : d < c) : b < a :=\nlt_of_not_le $ \u03bb h', (H h').not_lt h\n\nlemma le_imp_le_iff_lt_imp_lt {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2} :\n  (a \u2264 b \u2192 c \u2264 d) \u2194 (d < c \u2192 b < a) :=\n\u27e8lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt\u27e9\n\nlemma lt_iff_lt_of_le_iff_le' {\u03b2} [preorder \u03b1] [preorder \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2194 c \u2264 d) (H' : b \u2264 a \u2194 d \u2264 c) : b < a \u2194 d < c :=\nlt_iff_le_not_le.trans $ (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm\n\nlemma lt_iff_lt_of_le_iff_le {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2}\n  (H : a \u2264 b \u2194 c \u2264 d) : b < a \u2194 d < c :=\nnot_le.symm.trans $ (not_congr H).trans $ not_le\n\nlemma le_iff_le_iff_lt_iff_lt {\u03b2} [linear_order \u03b1] [linear_order \u03b2] {a b : \u03b1} {c d : \u03b2} :\n  (a \u2264 b \u2194 c \u2264 d) \u2194 (b < a \u2194 d < c) :=\n\u27e8lt_iff_lt_of_le_iff_le, \u03bb H, not_lt.symm.trans $ (not_congr H).trans $ not_lt\u27e9\n\nlemma eq_of_forall_le_iff [partial_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c \u2264 a \u2194 c \u2264 b) : a = b :=\n((H _).1 le_rfl).antisymm ((H _).2 le_rfl)\n\nlemma le_of_forall_le [preorder \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c \u2264 a \u2192 c \u2264 b) : a \u2264 b :=\nH _ le_rfl\n\nlemma le_of_forall_le' [preorder \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a \u2264 c \u2192 b \u2264 c) : b \u2264 a :=\nH _ le_rfl\n\nlemma le_of_forall_lt [linear_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, c < a \u2192 c < b) : a \u2264 b :=\nle_of_not_lt $ \u03bb h, lt_irrefl _ (H _ h)\n\nlemma forall_lt_iff_le [linear_order \u03b1] {a b : \u03b1} :\n  (\u2200 \u2983c\u2984, c < a \u2192 c < b) \u2194 a \u2264 b :=\n\u27e8le_of_forall_lt, \u03bb h c hca, lt_of_lt_of_le hca h\u27e9\n\nlemma le_of_forall_lt' [linear_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a < c \u2192 b < c) : b \u2264 a :=\nle_of_not_lt $ \u03bb h, lt_irrefl _ (H _ h)\n\nlemma forall_lt_iff_le' [linear_order \u03b1] {a b : \u03b1} :\n  (\u2200 \u2983c\u2984, a < c \u2192 b < c) \u2194 b \u2264 a :=\n\u27e8le_of_forall_lt', \u03bb h c hac, lt_of_le_of_lt h hac\u27e9\n\nlemma eq_of_forall_ge_iff [partial_order \u03b1] {a b : \u03b1}\n  (H : \u2200 c, a \u2264 c \u2194 b \u2264 c) : a = b :=\n((H _).2 le_rfl).antisymm ((H _).1 le_rfl)\n\n/-- monotonicity of `\u2264` with respect to `\u2192` -/\nlemma le_implies_le_of_le_of_le {a b c d : \u03b1} [preorder \u03b1] (hca : c \u2264 a) (hbd : b \u2264 d) :\n  a \u2264 b \u2192 c \u2264 d :=\n\u03bb hab, (hca.trans hab).trans hbd\n\n@[ext]\nlemma preorder.to_has_le_injective {\u03b1 : Type*} :\n  function.injective (@preorder.to_has_le \u03b1) :=\n\u03bb A B h, begin\n  cases A, cases B,\n  injection h with h_le,\n  have : A_lt = B_lt,\n  { funext a b,\n    dsimp [(\u2264)] at A_lt_iff_le_not_le B_lt_iff_le_not_le h_le,\n    simp [A_lt_iff_le_not_le, B_lt_iff_le_not_le, h_le], },\n  congr',\nend\n\n@[ext]\nlemma partial_order.to_preorder_injective {\u03b1 : Type*} :\n  function.injective (@partial_order.to_preorder \u03b1) :=\n\u03bb A B h, by { cases A, cases B, injection h, congr' }\n\n@[ext]\nlemma linear_order.to_partial_order_injective {\u03b1 : Type*} :\n  function.injective (@linear_order.to_partial_order \u03b1) :=\nbegin\n  intros A B h,\n  cases A, cases B, injection h,\n  obtain rfl : A_le = B_le := \u2039_\u203a, obtain rfl : A_lt = B_lt := \u2039_\u203a,\n  obtain rfl : A_decidable_le = B_decidable_le := subsingleton.elim _ _,\n  obtain rfl : A_max = B_max := A_max_def.trans B_max_def.symm,\n  obtain rfl : A_min = B_min := A_min_def.trans B_min_def.symm,\n  congr\nend\n\ntheorem preorder.ext {\u03b1} {A B : preorder \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\ntheorem partial_order.ext {\u03b1} {A B : partial_order \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\ntheorem linear_order.ext {\u03b1} {A B : linear_order \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nby { ext x y, exact H x y }\n\n/-- Given a relation `R` on `\u03b2` and a function `f : \u03b1 \u2192 \u03b2`, the preimage relation on `\u03b1` is defined\nby `x \u2264 y \u2194 f x \u2264 f y`. It is the unique relation on `\u03b1` making `f` a `rel_embedding` (assuming `f`\nis injective). -/\n@[simp] def order.preimage {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) (x y : \u03b1) : Prop := s (f x) (f y)\n\ninfix ` \u207b\u00b9'o `:80 := order.preimage\n\n/-- The preimage of a decidable order is decidable. -/\ninstance order.preimage.decidable {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : \u03b2 \u2192 \u03b2 \u2192 Prop) [H : decidable_rel s] :\n  decidable_rel (f \u207b\u00b9'o s) :=\n\u03bb x y, H _ _\n\n/-! ### Order dual -/\n\n/-- Type synonym to equip a type with the dual order: `\u2264` means `\u2265` and `<` means `>`. `\u03b1\u1d52\u1d48` is\nnotation for `order_dual \u03b1`. -/\ndef order_dual (\u03b1 : Type*) : Type* := \u03b1\n\nnotation \u03b1 `\u1d52\u1d48`:std.prec.max_plus := order_dual \u03b1\n\nnamespace order_dual\n\ninstance (\u03b1 : Type*) [h : nonempty \u03b1] : nonempty \u03b1\u1d52\u1d48 := h\ninstance (\u03b1 : Type*) [h : subsingleton \u03b1] : subsingleton \u03b1\u1d52\u1d48 := h\ninstance (\u03b1 : Type*) [has_le \u03b1] : has_le \u03b1\u1d52\u1d48 := \u27e8\u03bb x y : \u03b1, y \u2264 x\u27e9\ninstance (\u03b1 : Type*) [has_lt \u03b1] : has_lt \u03b1\u1d52\u1d48 := \u27e8\u03bb x y : \u03b1, y < x\u27e9\ninstance (\u03b1 : Type*) [has_zero \u03b1] : has_zero \u03b1\u1d52\u1d48 := \u27e8(0 : \u03b1)\u27e9\n\n-- `dual_le` and `dual_lt` should not be simp lemmas:\n-- they cause a loop since `\u03b1` and `\u03b1\u1d52\u1d48` are definitionally equal\n\nlemma dual_le [has_le \u03b1] {a b : \u03b1} :\n  @has_le.le \u03b1\u1d52\u1d48 _ a b \u2194 @has_le.le \u03b1 _ b a := iff.rfl\n\nlemma dual_lt [has_lt \u03b1] {a b : \u03b1} :\n  @has_lt.lt \u03b1\u1d52\u1d48 _ a b \u2194 @has_lt.lt \u03b1 _ b a := iff.rfl\n\ninstance (\u03b1 : Type*) [preorder \u03b1] : preorder \u03b1\u1d52\u1d48 :=\n{ le_refl          := le_refl,\n  le_trans         := \u03bb a b c hab hbc, hbc.trans hab,\n  lt_iff_le_not_le := \u03bb _ _, lt_iff_le_not_le,\n  .. order_dual.has_le \u03b1,\n  .. order_dual.has_lt \u03b1 }\n\ninstance (\u03b1 : Type*) [partial_order \u03b1] : partial_order \u03b1\u1d52\u1d48 :=\n{ le_antisymm := \u03bb a b hab hba, @le_antisymm \u03b1 _ a b hba hab, .. order_dual.preorder \u03b1 }\n\ninstance (\u03b1 : Type*) [linear_order \u03b1] : linear_order \u03b1\u1d52\u1d48 :=\n{ le_total     := \u03bb a b : \u03b1, le_total b a,\n  decidable_le := (infer_instance : decidable_rel (\u03bb a b : \u03b1, b \u2264 a)),\n  decidable_lt := (infer_instance : decidable_rel (\u03bb a b : \u03b1, b < a)),\n  min := @max \u03b1 _,\n  max := @min \u03b1 _,\n  min_def := @linear_order.max_def \u03b1 _,\n  max_def := @linear_order.min_def \u03b1 _,\n  .. order_dual.partial_order \u03b1 }\n\ninstance : \u03a0 [inhabited \u03b1], inhabited \u03b1\u1d52\u1d48 := id\n\ntheorem preorder.dual_dual (\u03b1 : Type*) [H : preorder \u03b1] :\n  order_dual.preorder \u03b1\u1d52\u1d48 = H :=\npreorder.ext $ \u03bb _ _, iff.rfl\n\ntheorem partial_order.dual_dual (\u03b1 : Type*) [H : partial_order \u03b1] :\n  order_dual.partial_order \u03b1\u1d52\u1d48 = H :=\npartial_order.ext $ \u03bb _ _, iff.rfl\n\ntheorem linear_order.dual_dual (\u03b1 : Type*) [H : linear_order \u03b1] :\n  order_dual.linear_order \u03b1\u1d52\u1d48 = H :=\nlinear_order.ext $ \u03bb _ _, iff.rfl\n\nend order_dual\n\n/-! ### Order instances on the function space -/\n\ninstance pi.has_le {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_le (\u03b1 i)] : has_le (\u03a0 i, \u03b1 i) :=\n{ le       := \u03bb x y, \u2200 i, x i \u2264 y i }\n\nlemma pi.le_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, has_le (\u03b1 i)] {x y : \u03a0 i, \u03b1 i} :\n  x \u2264 y \u2194 \u2200 i, x i \u2264 y i :=\niff.rfl\n\ninstance pi.preorder {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] : preorder (\u03a0 i, \u03b1 i) :=\n{ le_refl  := \u03bb a i, le_refl (a i),\n  le_trans := \u03bb a b c h\u2081 h\u2082 i, le_trans (h\u2081 i) (h\u2082 i),\n  ..pi.has_le }\n\nlemma pi.lt_def {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] {x y : \u03a0 i, \u03b1 i} :\n  x < y \u2194 x \u2264 y \u2227 \u2203 i, x i < y i :=\nby simp [lt_iff_le_not_le, pi.le_def] {contextual := tt}\n\nlemma le_update_iff {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] [decidable_eq \u03b9]\n  {x y : \u03a0 i, \u03b1 i} {i : \u03b9} {a : \u03b1 i} :\n  x \u2264 function.update y i a \u2194 x i \u2264 a \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nfunction.forall_update_iff _ (\u03bb j z, x j \u2264 z)\n\nlemma update_le_iff {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] [decidable_eq \u03b9]\n  {x y : \u03a0 i, \u03b1 i} {i : \u03b9} {a : \u03b1 i} :\n  function.update x i a \u2264 y \u2194 a \u2264 y i \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nfunction.forall_update_iff _ (\u03bb j z, z \u2264 y j)\n\nlemma update_le_update_iff {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, preorder (\u03b1 i)] [decidable_eq \u03b9]\n  {x y : \u03a0 i, \u03b1 i} {i : \u03b9} {a b : \u03b1 i} :\n  function.update x i a \u2264 function.update y i b \u2194 a \u2264 b \u2227 \u2200 j \u2260 i, x j \u2264 y j :=\nby simp [update_le_iff] {contextual := tt}\n\ninstance pi.partial_order {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, partial_order (\u03b1 i)] :\n  partial_order (\u03a0 i, \u03b1 i) :=\n{ le_antisymm := \u03bb f g h1 h2, funext (\u03bb b, (h1 b).antisymm (h2 b)),\n  ..pi.preorder }\n\n/-! ### Lifts of order instances -/\n\n/-- Transfer a `preorder` on `\u03b2` to a `preorder` on `\u03b1` using a function `f : \u03b1 \u2192 \u03b2`.\nSee note [reducible non-instances]. -/\n@[reducible] def preorder.lift {\u03b1 \u03b2} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) : preorder \u03b1 :=\n{ le               := \u03bb x y, f x \u2264 f y,\n  le_refl          := \u03bb a, le_rfl,\n  le_trans         := \u03bb a b c, le_trans,\n  lt               := \u03bb x y, f x < f y,\n  lt_iff_le_not_le := \u03bb a b, lt_iff_le_not_le }\n\n/-- Transfer a `partial_order` on `\u03b2` to a `partial_order` on `\u03b1` using an injective\nfunction `f : \u03b1 \u2192 \u03b2`. See note [reducible non-instances]. -/\n@[reducible] def partial_order.lift {\u03b1 \u03b2} [partial_order \u03b2] (f : \u03b1 \u2192 \u03b2) (inj : injective f) :\n  partial_order \u03b1 :=\n{ le_antisymm := \u03bb a b h\u2081 h\u2082, inj (h\u2081.antisymm h\u2082), .. preorder.lift f }\n\n/-- Transfer a `linear_order` on `\u03b2` to a `linear_order` on `\u03b1` using an injective\nfunction `f : \u03b1 \u2192 \u03b2`. See note [reducible non-instances]. -/\n@[reducible] def linear_order.lift {\u03b1 \u03b2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (inj : injective f) :\n  linear_order \u03b1 :=\n{ le_total     := \u03bb x y, le_total (f x) (f y),\n  decidable_le := \u03bb x y, (infer_instance : decidable (f x \u2264 f y)),\n  decidable_lt := \u03bb x y, (infer_instance : decidable (f x < f y)),\n  decidable_eq := \u03bb x y, decidable_of_iff _ inj.eq_iff,\n  .. partial_order.lift f inj }\n\n/-! ### Subtype of an order -/\n\nnamespace subtype\n\ninstance [has_le \u03b1] {p : \u03b1 \u2192 Prop} : has_le (subtype p) := \u27e8\u03bb x y, (x : \u03b1) \u2264 y\u27e9\ninstance [has_lt \u03b1] {p : \u03b1 \u2192 Prop} : has_lt (subtype p) := \u27e8\u03bb x y, (x : \u03b1) < y\u27e9\n\n@[simp] lemma mk_le_mk [has_le \u03b1] {p : \u03b1 \u2192 Prop} {x y : \u03b1} {hx : p x} {hy : p y} :\n  (\u27e8x, hx\u27e9 : subtype p) \u2264 \u27e8y, hy\u27e9 \u2194 x \u2264 y :=\niff.rfl\n\n@[simp] lemma mk_lt_mk [has_lt \u03b1] {p : \u03b1 \u2192 Prop} {x y : \u03b1} {hx : p x} {hy : p y} :\n  (\u27e8x, hx\u27e9 : subtype p) < \u27e8y, hy\u27e9 \u2194 x < y :=\niff.rfl\n\n@[simp, norm_cast]\nlemma coe_le_coe [has_le \u03b1] {p : \u03b1 \u2192 Prop} {x y : subtype p} : (x : \u03b1) \u2264 y \u2194 x \u2264 y := iff.rfl\n\n@[simp, norm_cast]\nlemma coe_lt_coe [has_lt \u03b1] {p : \u03b1 \u2192 Prop} {x y : subtype p} : (x : \u03b1) < y \u2194 x < y := iff.rfl\n\ninstance [preorder \u03b1] (p : \u03b1 \u2192 Prop) : preorder (subtype p) := preorder.lift (coe : subtype p \u2192 \u03b1)\n\ninstance partial_order [partial_order \u03b1] (p : \u03b1 \u2192 Prop) :\n  partial_order (subtype p) :=\npartial_order.lift coe subtype.coe_injective\n\ninstance decidable_le [preorder \u03b1] [@decidable_rel \u03b1 (\u2264)] {p : \u03b1 \u2192 Prop} :\n  @decidable_rel (subtype p) (\u2264) :=\n\u03bb a b, decidable_of_iff _ subtype.coe_le_coe\n\ninstance decidable_lt [preorder \u03b1] [@decidable_rel \u03b1 (<)] {p : \u03b1 \u2192 Prop} :\n  @decidable_rel (subtype p) (<) :=\n\u03bb a b, decidable_of_iff _ subtype.coe_lt_coe\n\n/-- A subtype of a linear order is a linear order. We explicitly give the proofs of decidable\nequality and decidable order in order to ensure the decidability instances are all definitionally\nequal. -/\ninstance [linear_order \u03b1] (p : \u03b1 \u2192 Prop) : linear_order (subtype p) :=\n{ decidable_eq := subtype.decidable_eq,\n  decidable_le := subtype.decidable_le,\n  decidable_lt := subtype.decidable_lt,\n  max_def := by { ext a b, convert rfl },\n  min_def := by { ext a b, convert rfl },\n  .. linear_order.lift coe subtype.coe_injective }\n\nend subtype\n\n/-!\n### Pointwise order on `\u03b1 \u00d7 \u03b2`\n\nThe lexicographic order is defined in `data.prod.lex`, and the instances are available via the\ntype synonym `\u03b1 \u00d7\u2097 \u03b2 = \u03b1 \u00d7 \u03b2`.\n-/\n\nnamespace prod\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [has_le \u03b1] [has_le \u03b2] : has_le (\u03b1 \u00d7 \u03b2) :=\n\u27e8\u03bb p q, p.1 \u2264 q.1 \u2227 p.2 \u2264 q.2\u27e9\n\nlemma le_def [has_le \u03b1] [has_le \u03b2] {x y : \u03b1 \u00d7 \u03b2} : x \u2264 y \u2194 x.1 \u2264 y.1 \u2227 x.2 \u2264 y.2 := iff.rfl\n\n@[simp] lemma mk_le_mk [has_le \u03b1] [has_le \u03b2] {x\u2081 x\u2082 : \u03b1} {y\u2081 y\u2082 : \u03b2} :\n  (x\u2081, y\u2081) \u2264 (x\u2082, y\u2082) \u2194 x\u2081 \u2264 x\u2082 \u2227 y\u2081 \u2264 y\u2082 :=\niff.rfl\n\n@[simp] lemma swap_le_swap [has_le \u03b1] [has_le \u03b2] {x y : \u03b1 \u00d7 \u03b2} : x.swap \u2264 y.swap \u2194 x \u2264 y :=\nand_comm _ _\n\nsection preorder\nvariables [preorder \u03b1] [preorder \u03b2] {a a\u2081 a\u2082 : \u03b1} {b b\u2081 b\u2082 : \u03b2} {x y : \u03b1 \u00d7 \u03b2}\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [preorder \u03b1] [preorder \u03b2] : preorder (\u03b1 \u00d7 \u03b2) :=\n{ le_refl  := \u03bb \u27e8a, b\u27e9, \u27e8le_refl a, le_refl b\u27e9,\n  le_trans := \u03bb \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8e, f\u27e9 \u27e8hac, hbd\u27e9 \u27e8hce, hdf\u27e9,\n    \u27e8le_trans hac hce, le_trans hbd hdf\u27e9,\n  .. prod.has_le \u03b1 \u03b2 }\n\n@[simp] lemma swap_lt_swap : x.swap < y.swap \u2194 x < y :=\nand_congr swap_le_swap (not_congr swap_le_swap)\n\nlemma mk_le_mk_iff_left : (a\u2081, b) \u2264 (a\u2082, b) \u2194 a\u2081 \u2264 a\u2082 := and_iff_left le_rfl\nlemma mk_le_mk_iff_right : (a, b\u2081) \u2264 (a, b\u2082) \u2194 b\u2081 \u2264 b\u2082 := and_iff_right le_rfl\n\nlemma mk_lt_mk_iff_left : (a\u2081, b) < (a\u2082, b) \u2194 a\u2081 < a\u2082 :=\nlt_iff_lt_of_le_iff_le' mk_le_mk_iff_left mk_le_mk_iff_left\n\nlemma mk_lt_mk_iff_right : (a, b\u2081) < (a, b\u2082) \u2194 b\u2081 < b\u2082 :=\nlt_iff_lt_of_le_iff_le' mk_le_mk_iff_right mk_le_mk_iff_right\n\nlemma lt_iff : x < y \u2194 x.1 < y.1 \u2227 x.2 \u2264 y.2 \u2228 x.1 \u2264 y.1 \u2227 x.2 < y.2 :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { by_cases h\u2081 : y.1 \u2264 x.1,\n    { exact or.inr \u27e8h.1.1, h.1.2.lt_of_not_le $ \u03bb h\u2082, h.2 \u27e8h\u2081, h\u2082\u27e9\u27e9 },\n    { exact or.inl \u27e8h.1.1.lt_of_not_le h\u2081, h.1.2\u27e9 } },\n  { rintro (\u27e8h\u2081, h\u2082\u27e9 | \u27e8h\u2081, h\u2082\u27e9),\n    { exact \u27e8\u27e8h\u2081.le, h\u2082\u27e9, \u03bb h, h\u2081.not_le h.1\u27e9 },\n    { exact \u27e8\u27e8h\u2081, h\u2082.le\u27e9, \u03bb h, h\u2082.not_le h.2\u27e9 } }\nend\n\n@[simp] lemma mk_lt_mk : (a\u2081, b\u2081) < (a\u2082, b\u2082) \u2194 a\u2081 < a\u2082 \u2227 b\u2081 \u2264 b\u2082 \u2228 a\u2081 \u2264 a\u2082 \u2227 b\u2081 < b\u2082 := lt_iff\n\nend preorder\n\n/-- The pointwise partial order on a product.\n    (The lexicographic ordering is defined in order/lexicographic.lean, and the instances are\n    available via the type synonym `\u03b1 \u00d7\u2097 \u03b2 = \u03b1 \u00d7 \u03b2`.) -/\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [partial_order \u03b1] [partial_order \u03b2] :\n  partial_order (\u03b1 \u00d7 \u03b2) :=\n{ le_antisymm := \u03bb \u27e8a, b\u27e9 \u27e8c, d\u27e9 \u27e8hac, hbd\u27e9 \u27e8hca, hdb\u27e9,\n    prod.ext (hac.antisymm hca) (hbd.antisymm hdb),\n  .. prod.preorder \u03b1 \u03b2 }\n\nend prod\n\n/-! ### Additional order classes -/\n\n/-- An order is dense if there is an element between any pair of distinct elements. -/\nclass densely_ordered (\u03b1 : Type u) [has_lt \u03b1] : Prop :=\n(dense : \u2200 a\u2081 a\u2082 : \u03b1, a\u2081 < a\u2082 \u2192 \u2203 a, a\u2081 < a \u2227 a < a\u2082)\n\nlemma exists_between [has_lt \u03b1] [densely_ordered \u03b1] :\n  \u2200 {a\u2081 a\u2082 : \u03b1}, a\u2081 < a\u2082 \u2192 \u2203 a, a\u2081 < a \u2227 a < a\u2082 :=\ndensely_ordered.dense\n\ninstance order_dual.densely_ordered (\u03b1 : Type u) [has_lt \u03b1] [densely_ordered \u03b1] :\n  densely_ordered \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a\u2081 a\u2082 ha, (@exists_between \u03b1 _ _ _ _ ha).imp $ \u03bb a, and.symm\u27e9\n\nlemma le_of_forall_le_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h : \u2200 a, a\u2082 < a \u2192 a\u2081 \u2264 a) :\n  a\u2081 \u2264 a\u2082 :=\nle_of_not_gt $ \u03bb ha,\n  let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between ha in\n  lt_irrefl a $ lt_of_lt_of_le \u2039a < a\u2081\u203a (h _ \u2039a\u2082 < a\u203a)\n\nlemma eq_of_le_of_forall_le_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : \u2200 a, a\u2082 < a \u2192 a\u2081 \u2264 a) : a\u2081 = a\u2082 :=\nle_antisymm (le_of_forall_le_of_dense h\u2082) h\u2081\n\nlemma le_of_forall_ge_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h : \u2200 a\u2083 < a\u2081, a\u2083 \u2264 a\u2082) :\n  a\u2081 \u2264 a\u2082 :=\nle_of_not_gt $ \u03bb ha,\n  let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between ha in\n  lt_irrefl a $ lt_of_le_of_lt (h _ \u2039a < a\u2081\u203a) \u2039a\u2082 < a\u203a\n\nlemma eq_of_le_of_forall_ge_of_dense [linear_order \u03b1] [densely_ordered \u03b1] {a\u2081 a\u2082 : \u03b1}\n  (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : \u2200 a\u2083 < a\u2081, a\u2083 \u2264 a\u2082) : a\u2081 = a\u2082 :=\n(le_of_forall_ge_of_dense h\u2082).antisymm h\u2081\n\nlemma dense_or_discrete [linear_order \u03b1] (a\u2081 a\u2082 : \u03b1) :\n  (\u2203 a, a\u2081 < a \u2227 a < a\u2082) \u2228 ((\u2200 a, a\u2081 < a \u2192 a\u2082 \u2264 a) \u2227 (\u2200 a < a\u2082, a \u2264 a\u2081)) :=\nor_iff_not_imp_left.2 $ \u03bb h,\n  \u27e8\u03bb a ha\u2081, le_of_not_gt $ \u03bb ha\u2082, h \u27e8a, ha\u2081, ha\u2082\u27e9,\n    \u03bb a ha\u2082, le_of_not_gt $ \u03bb ha\u2081, h \u27e8a, ha\u2081, ha\u2082\u27e9\u27e9\n\nvariables {s : \u03b2 \u2192 \u03b2 \u2192 Prop} {t : \u03b3 \u2192 \u03b3 \u2192 Prop}\n\n/-! ### Linear order from a total partial order -/\n\n/-- Type synonym to create an instance of `linear_order` from a `partial_order` and\n`is_total \u03b1 (\u2264)` -/\ndef as_linear_order (\u03b1 : Type u) := \u03b1\n\ninstance {\u03b1} [inhabited \u03b1] : inhabited (as_linear_order \u03b1) :=\n\u27e8 (default : \u03b1) \u27e9\n\nnoncomputable instance as_linear_order.linear_order {\u03b1} [partial_order \u03b1] [is_total \u03b1 (\u2264)] :\n  linear_order (as_linear_order \u03b1) :=\n{ le_total     := @total_of \u03b1 (\u2264) _,\n  decidable_le := classical.dec_rel _,\n  .. (_ : partial_order \u03b1) }\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7126086503541497}}
{"text": "import tactic\n\n/-!\n\nBasic definitions in group theory.\n\nSource: \nhttps://xenaproject.wordpress.com/2018/04/30/group-theory-revision/\n\n-/\n\nset_option old_structure_cmd true -- it's better for this kind of stuff\n\n-- We're overwriting inbuilt group theory here so we always work in\n-- a namespace\n\nnamespace mygroup\n\n-- definitions of the group classes\n\nsection groupdefs \n\n-- Set up notation typeclass using `extends`.\nclass has_group_notation (G : Type) extends has_mul G, has_one G, has_inv G\n\n-- definition of the group structure\nclass group (G : Type) extends has_group_notation G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\nclass comm_group (G : Type) extends group G :=\n(mul_comm : \u2200 a b : G, a * b = b * a)\n\n-- an example\ninstance perm_group (\u03b1 : Type) : group (\u03b1 \u2243 \u03b1) :=\n{ mul := function.swap equiv.trans,\n  one := equiv.refl _,\n  inv := equiv.symm,\n  mul_assoc := by intros; ext; refl,\n  one_mul := by intros; ext; refl,\n  mul_left_inv := by intros; ext; simp }\n\nend groupdefs\n\n/- Our first task is to prove `mul_one` and `mul_right_inv`.\n   We prove some other things along the way too -- we make \n   what a computer scientist would call \"an interface for\n   the group class\".\n\n  Examples of what we prove:\n\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n\n-/\nnamespace group\n\nvariables {G : Type} [group G]  \n\n-- We prove left_mul_cancel for group using `calc`.\n\nlemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c := \n calc b = 1 * b         : by rw one_mul\n    ... = (a\u207b\u00b9 * a) * b : by rw mul_left_inv\n    ... = a\u207b\u00b9 * (a * b) : by rw mul_assoc\n    ... = a\u207b\u00b9 * (a * c) : by rw Habac\n    ... = (a\u207b\u00b9 * a) * c : by rw mul_assoc\n    ... = 1 * c         : by rw mul_left_inv\n    ... = c             : by rw one_mul\n\n-- We can do all this one go:\n\nlemma mul_left_cancel' (a b c : G) (Habac : a * b = a * c) : b = c := \nbegin \n  rw [\u2190one_mul b, \u2190mul_left_inv a, mul_assoc, Habac,\n      \u2190mul_assoc, mul_left_inv, one_mul],\nend\n\n-- Because the above proof just uses one tactic, we could use `by`\n-- instead of `begin ... end`:\n\nlemma mul_left_cancel'' (a b c : G) (Habac : a * b = a * c) : b = c := \nby rw [\u2190one_mul b, \u2190mul_left_inv a, mul_assoc, Habac,\n  \u2190mul_assoc, mul_left_inv, one_mul]\n\n-- The below is also a useful intermediate lemma\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  rw \u2190mul_assoc,\n  rw mul_left_inv,\n  rwa one_mul, -- rewrite then assumption\nend\n\n-- could prove it in `calc` mode:\n\nlemma mul_eq_of_eq_inv_mul' {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a\u207b\u00b9,\n  exact calc\n  a\u207b\u00b9 * (a * x) = a\u207b\u00b9 * a * x : by rw mul_assoc\n  ...           = 1 * x       : by rw mul_left_inv\n  ...           = x           : by rw one_mul\n  ...           = a\u207b\u00b9 * y     : by rw h  \nend\n\nattribute [simp] one_mul mul_left_inv\n\n-- Alternatively, get the simplifier to do some of the work for us\nlemma mul_eq_of_eq_inv_mul'' {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y :=\n\u03bb h, mul_left_cancel a\u207b\u00b9 _ _ $ by rw \u2190mul_assoc; simp [h]\n\n-- We can now prove `mul_one`:\n\n-- nice short proof\ntheorem mul_one (a : G) : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_left_inv,\n  -- note no refl\nend\n\n-- calc example (longer than previous one)\ntheorem mul_one' : \u2200 (a : G), a * 1 = a :=\nbegin\n  intro a, -- goal is a * 1 = a\n  apply mul_left_cancel a\u207b\u00b9, -- goal now a\u207b\u00b9 * (a * 1) = a\u207b\u00b9 * a\n  exact calc a\u207b\u00b9 * (a * 1) = (a\u207b\u00b9 * a) * 1 : by rw mul_assoc\n          ...               = 1 * 1         : by rw mul_left_inv\n          ...               = 1             : by rw one_mul\n          ...               = a\u207b\u00b9 * a       : by rw mul_left_inv\nend\n\n-- term mode proof\ntheorem mul_one'' (a : G) : a * 1 = a :=\nmul_eq_of_eq_inv_mul $ by simp\n\n-- it's also a good simp lemma\nattribute [simp] mul_one\n\n-- mul_left_inv is an axiom: here's mul_right_inv. \n\ntheorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\n-- another good simp lemma\nattribute [simp] mul_right_inv\n\n-- We already proved `mul_eq_of_eq_inv_mul` but there are several other\n-- similar-looking, but slightly different, versions of this. Here\n-- is one.\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nbegin\n  rw \u2190h,\n  rw mul_assoc,\n  rw mul_right_inv,\n  rw mul_one\nend\n\n-- one-liner proof\nlemma eq_mul_inv_of_mul_eq' {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nby rw [\u2190h, mul_assoc, mul_right_inv, mul_one]\n\n-- proof using automation\nlemma eq_mul_inv_of_mul_eq'' {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nby simp [h.symm, mul_assoc]\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b\u207b\u00b9 * c :=\nbegin\n  rw [\u2190h, \u2190mul_assoc, mul_left_inv b, one_mul]\nend\n\n-- Another useful lemma for the interface:\nlemma mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1 :=\nbegin\n  split,\n  { intro h,\n    replace h := eq_mul_inv_of_mul_eq h,\n    rw mul_right_inv at h,\n    assumption },\n  { intro h,\n    rw h,\n    rw one_mul }\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a \u2194 b = 1 :=\nbegin\n  split,\n    intro h,\n    from calc b = a\u207b\u00b9 * a : by apply eq_inv_mul_of_mul_eq h\n           ...  = 1 : by rw mul_left_inv,\n    intro h,\n    rw [h, mul_one]\nend\n\n-- Another useful lemma for the interface.\n-- Note use of the powerful `convert` tactic.\n-- `eq_mul_inv_of_mul_eq h` says ` a = 1 * b\u207b\u00b9` which is\n-- equal to our goal; convert creates the goals necessary\n-- to prove this\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9 :=\nbegin\n  convert eq_mul_inv_of_mul_eq h,\n  rw one_mul, -- `simp` would also work\nend\n\n-- Another useful lemma for the interface\nlemma inv_inv (a : G) : a \u207b\u00b9 \u207b\u00b9 = a :=\nbegin\n  symmetry,\n  apply eq_inv_of_mul_eq_one,\n  simp,\nend\n\n-- Another useful lemma for the interface\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b :=\nbegin\n  -- we can change hypotheses with the `replace` tactic.\n  -- h implies a = 1 * b\u207b\u00b9\n  replace h := eq_mul_inv_of_mul_eq h,\n  -- and so a = b\u207b\u00b9\n  rw one_mul at h,\n  -- By substituting in, we have to prove (b\u207b\u00b9)\u207b\u00b9 = b\n  rw h,\n  -- and we just did this, it's `inv_inv`\n  rw inv_inv,\nend\n\nlemma unique_id {e : G} (h : \u2200 x : G, e * x = x) : e = 1 :=\ncalc e = e * 1 : by rw mul_one\n  ...  = 1 : by rw h 1\n\n-- Maybe add unique_id but with x * e = x\n\nlemma unique_inv {a b : G} (h : a * b = 1) : b = a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel a,\n  rw [h, mul_right_inv]\nend\n\nlemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y := \ncalc x = x * 1 : by rw mul_one\n  ...  = x * (a * a\u207b\u00b9) : by rw mul_right_inv\n  ...  = x * a * a\u207b\u00b9 : by rw mul_assoc\n  ...  = y * a * a\u207b\u00b9 : by rw Habac\n  ...  = y * (a * a\u207b\u00b9) : by rw mul_assoc\n  ...  = y * 1 : by rw mul_right_inv\n  ...  = y : by rw mul_one\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y \u2194 x = y :=\nbegin\n  split,\n    from mul_left_cancel a x y,\n    intro hxy,\n    rwa hxy\nend\n\nlemma mul_right_cancel_iff (a x y : G) : x * a = y * a \u2194 x = y :=\nbegin\n  split,\n    from mul_right_cancel a x y,\n    intro hxy,\n    rwa hxy\nend\n\n@[simp] lemma inv_mul_cancel_left (a b : G) : a\u207b\u00b9 * (a * b) = b :=\nbegin\n  rw \u2190mul_assoc, simp\nend\n\n@[simp] lemma mul_inv_cancel_left (a b : G) : a * (a\u207b\u00b9 * b) = b :=\nbegin\n  rw \u2190mul_assoc,\n  simp\nend\n\nlemma inv_mul (a b : G) : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  apply mul_left_cancel (a * b),\n  rw mul_right_inv, simp [mul_assoc]\nend\n\nlemma one_inv : (1 : G)\u207b\u00b9 = 1 :=\nby conv_rhs { rw [\u2190(mul_left_inv (1 : G)), mul_one] }\n\nattribute [simp] mul_left_cancel_iff mul_right_cancel_iff inv_mul inv_inv  one_inv\n\n@[simp] theorem inv_inj_iff {a b : G}: a\u207b\u00b9 = b\u207b\u00b9 \u2194 a = b :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190 inv_inv a, h, inv_inv b] },\n  { rintro rfl,\n    refl }  \nend   \n\ntheorem inv_eq {a b : G}: a\u207b\u00b9 = b \u2194 b\u207b\u00b9 = a :=\nbegin\n  split;\n  { rintro rfl,\n    rw inv_inv }\nend  \n\ntheorem mul_comm {G : Type} [comm_group G] (g h : G) : \n  g * h = h * g := comm_group.mul_comm g h\n\n-- **TODO** open an issue about abel only working with `*`. We\n-- have `group` working but not `comm_group`. It\n-- would be an interesting exercise to get `abel` working.\n\nend group\n\nend mygroup", "meta": {"author": "ImperialCollegeLondon", "repo": "group-theory-game", "sha": "152ec4a92ad67b6174a3d240c63fa56a6df6017e", "save_path": "github-repos/lean/ImperialCollegeLondon-group-theory-game", "path": "github-repos/lean/ImperialCollegeLondon-group-theory-game/group-theory-game-152ec4a92ad67b6174a3d240c63fa56a6df6017e/src/group/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7126086455573267}}
{"text": "/-\nBelow we've listed 20 proposed \"inference rules\" for reasoning \nwith propositional logic. Remember that such a rule has a context, \nwhich is a list of propositions that you already know, or assume \n(hypothetically), to be true; then there is a turnstile symbol (\u22a2),\nwhich you can read as \"entails\" or \"makes it logically necessary\nthat\"; and finally to the right of the turnstile is a conclusion. \n\nSuch a rule can be read both left to right and right to left. Left\nto right, it says that if all of the propositions on the left (in \nthe context) are true, then by applying the rule you can conclude \nthat the conclusion, after the turnstile, is also true. Reading \nright to left, on the other hand, it says that if you want to show\nthat the conclusion is true, then it is sufficient (suffices) to\nshow that each of the propositions on the left is true; because if\nall those propositions are true, then you can apply the rule to\ndeduce that the conclusion must be, too.\n\nAn inference rule is meant to express a *valid* rule of reasoning\nin general. To be valid, such a proposition must be true no matter \nwhat specific values are assigned to the variables. Most of these \nproposed rules are valid, but to make things interesting, we have\nthrown in a few *fallacies*, which are seemingly sound but actually\ninvalid rules. \n\nYour goal is to understand both intuitively and formally which of \nthe rules below are valid, and which are not. To this end, for each \nproposed rule, do the following:\n\n- In the Python file you will turn in, translate each rule as given\nhere into a proposition in Z3 and assign that proposition to a \nPython variable called Cn, where n is 1-20 corresponding to the\nenumeration below. For example, C3 = (Implies(And(X, Y), X). Note: \ntranslate each context into a conjunction of its elements, and then\ntranslate \u22a2 into propositional logic as \u2192. For example, you can \ntranslate the \"and introduction\" rule below into X \u2227 Y \u2192 X \u2227 Y.  \n- Below each such assignment, in comment, translate the rule into \nEnglish. For example, for the first rule you could write, \"If X \u2227 Y \nis true, then it must be that X is true, as well.\" You might find it\nhelpful to express X \u2192 Y as \"whenever X is true, Y must be true.\"\nFor example, you might translate \"Raining \u2192 Wet\" as \"whenever it's\nraining, it's also wet,\" or \"IF it's raining, THEN it's wet.\"\n-  State whether you believe the rule to be valid or not valid.\n- Use Z3 to check each rule for validity. If Z3 confirms that your \nrule is valid, you're done. Your program should print \"Cn is valid\"\nfor that rule, where n is the rule number.\n- For any rule that's not valid, have Z3 return a counterexample, \nand translate the formal counter-example into a concrete example \nin English and explain why it doesn't make sense. Put each such\nEnglish language translation in a comment under the statement of\nthe rule in Python.\n-/\n\n/-\n1. X \u2228 Y, X \u22a2 \u00acY             -- affirming the disjunct *\n2. X, Y \u22a2 X \u2227 Y              -- and introduction\n3. X \u2227 Y \u22a2 X                 -- and elimination left\n4. X \u2227 Y \u22a2 Y                 -- and elimination right\n5. \u00ac\u00acX \u22a2 X                   -- negation elimination \n6. \u00ac(X \u2227 \u00acX)                 -- no contradiction\n7. X \u22a2 X \u2228 Y                 -- or introduction left\n8. Y \u22a2 X \u2228 Y                 -- or introduction right\n9. X \u2192 Y, \u00acX \u22a2 \u00ac Y           -- denying the antecedent *\n10. X \u2192 Y, Y \u2192 X \u22a2 X \u2194 Y      -- iff introduction\n11. X \u2194 Y \u22a2 X \u2192 Y            -- iff elimination left\n12. X \u2194 Y \u22a2 Y \u2192 X            -- iff elimination right\n13. X \u2228 Y, X \u2192 Z, Y \u2192 Z \u22a2 Z  -- or elimination\n14. X \u2192 Y, Y \u22a2 X             -- affirming the conclusion *\n15. X \u2192 Y, X \u22a2 Y             -- arrow elimination\n16. X \u2192 Y, Y \u2192 Z \u22a2 X \u2192 Z     -- transitivity of \u2192 \n17. X \u2192 Y \u22a2 Y \u2192 X            -- converse *\n18. X \u2192 Y \u22a2 \u00acY \u2192 \u00acX          -- contrapositive\n19. \u00ac(X \u2228 Y) \u2194 \u00acX \u2227 \u00acY       -- DeMorgan #1 (\u00ac distributes over \u2228)\n20. \u00ac(X \u2227 Y) \u2194 \u00acX \u2228 \u00acY       -- Demorgan #2 (\u00ac distributes over \u2227)\n-/\n\n/-\nHint: Recall that s.check() returns sat or unsat, and that\nthere's an easy \"trick\" to use Z3 to determine if a given\nproposition is *valid*. So DO write into your solution file \na procedure that takes a proposition, C, and returns true if \nit's valid and false otherwise. You will need to check each\nproposition above for validity, so you will find it helpful\nto have this helper function, so that you only have to write\nthe code once. \n-/\n\n/-\nWhat to turn in.\n\nTurn in ONE Python file that, when run, prints out one\nline of output for each of the 19 problems, either saying\nthat the inference rule is valid, or that it's not and giving\na model that serves as a counterexample. HINT: Once you've \nadded constraints to a Solver, s, and used s to try to\nsatisfy the constraints, you can then use the s.reset() \nmethod to clear the solver for the next constraints to be\nchecked/solved. Whenever you find a rule that's not valid,\ngiven an English language example of a situation in which\nit's not true. Add this explanation as a comment where your\ncode checks for validity.\n-/", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/homeworks/hw2/hw2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473629, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.7126086425769507}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland\n-/\nimport algebra.regular.basic\nimport algebra.ring.defs\n\n/-!\n# Lemmas about regular elements in rings.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {\u03b1 : Type*}\n\n/-- Left `mul` by a `k : \u03b1` over `[ring \u03b1]` is injective, if `k` is not a zero divisor.\nThe typeclass that restricts all terms of `\u03b1` to have this property is `no_zero_divisors`. -/\nlemma is_left_regular_of_non_zero_divisor [non_unital_non_assoc_ring \u03b1] (k : \u03b1)\n  (h : \u2200 (x : \u03b1), k * x = 0 \u2192 x = 0) : is_left_regular k :=\nbegin\n  refine \u03bb x y (h' : k * x = k * y), sub_eq_zero.mp (h _ _),\n  rw [mul_sub, sub_eq_zero, h']\nend\n\n/-- Right `mul` by a `k : \u03b1` over `[ring \u03b1]` is injective, if `k` is not a zero divisor.\nThe typeclass that restricts all terms of `\u03b1` to have this property is `no_zero_divisors`. -/\nlemma is_right_regular_of_non_zero_divisor [non_unital_non_assoc_ring \u03b1] (k : \u03b1)\n  (h : \u2200 (x : \u03b1), x * k = 0 \u2192 x = 0) : is_right_regular k :=\nbegin\n  refine \u03bb x y (h' : x * k = y * k), sub_eq_zero.mp (h _ _),\n  rw [sub_mul, sub_eq_zero, h']\nend\n\nlemma is_regular_of_ne_zero' [non_unital_non_assoc_ring \u03b1] [no_zero_divisors \u03b1] {k : \u03b1}\n  (hk : k \u2260 0) : is_regular k :=\n\u27e8is_left_regular_of_non_zero_divisor k\n  (\u03bb x h, (no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left hk),\n is_right_regular_of_non_zero_divisor k\n  (\u03bb x h, (no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hk)\u27e9\n\nlemma is_regular_iff_ne_zero' [nontrivial \u03b1] [non_unital_non_assoc_ring \u03b1] [no_zero_divisors \u03b1]\n  {k : \u03b1} : is_regular k \u2194 k \u2260 0 :=\n\u27e8\u03bb h, by { rintro rfl, exact not_not.mpr h.left not_is_left_regular_zero }, is_regular_of_ne_zero'\u27e9\n\n/-- A ring with no zero divisors is a `cancel_monoid_with_zero`.\n\nNote this is not an instance as it forms a typeclass loop. -/\n@[reducible]\ndef no_zero_divisors.to_cancel_monoid_with_zero [ring \u03b1] [no_zero_divisors \u03b1] :\n  cancel_monoid_with_zero \u03b1 :=\n{ mul_left_cancel_of_ne_zero := \u03bb a b c ha,\n    @is_regular.left _ _ _ (is_regular_of_ne_zero' ha) _ _,\n  mul_right_cancel_of_ne_zero := \u03bb a b c hb,\n    @is_regular.right _ _ _ (is_regular_of_ne_zero' hb) _ _,\n  .. (by apply_instance : monoid_with_zero \u03b1) }\n\n/-- A commutative ring with no zero divisors is a `cancel_comm_monoid_with_zero`.\n\nNote this is not an instance as it forms a typeclass loop. -/\n@[reducible]\ndef no_zero_divisors.to_cancel_comm_monoid_with_zero [comm_ring \u03b1] [no_zero_divisors \u03b1] :\n  cancel_comm_monoid_with_zero \u03b1 :=\n{ .. no_zero_divisors.to_cancel_monoid_with_zero,\n  .. (by apply_instance : comm_monoid_with_zero \u03b1) }\n\nsection is_domain\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_domain.to_cancel_monoid_with_zero [semiring \u03b1] [is_domain \u03b1] :\n  cancel_monoid_with_zero \u03b1 :=\n{ .. semiring.to_monoid_with_zero \u03b1, .. \u2039is_domain \u03b1\u203a }\n\nvariables [comm_semiring \u03b1] [is_domain \u03b1]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_domain.to_cancel_comm_monoid_with_zero : cancel_comm_monoid_with_zero \u03b1 :=\n{ .. \u2039comm_semiring \u03b1\u203a, .. \u2039is_domain \u03b1\u203a }\n\nend is_domain\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/ring/regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7126086346586455}}
{"text": "/-\nCopyright (c) 2021 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport analysis.normed_space.finite_dimension\nimport analysis.p_series\nimport number_theory.arithmetic_function\nimport topology.algebra.infinite_sum.basic\n\n/-!\n# L-series\n\nGiven an arithmetic function, we define the corresponding L-series.\n\n## Main Definitions\n * `nat.arithmetic_function.l_series` is the `l_series` with a given arithmetic function as its\n  coefficients. This is not the analytic continuation, just the infinite series.\n * `nat.arithmetic_function.l_series_summable` indicates that the `l_series`\n  converges at a given point.\n\n## Main Results\n * `nat.arithmetic_function.l_series_summable_of_bounded_of_one_lt_re`: the `l_series` of a bounded\n  arithmetic function converges when `1 < z.re`.\n * `nat.arithmetic_function.zeta_l_series_summable_iff_one_lt_re`: the `l_series` of `\u03b6`\n  (whose analytic continuation is the Riemann \u03b6) converges iff `1 < z.re`.\n\n-/\n\nnoncomputable theory\nopen_locale big_operators\n\nnamespace nat\nnamespace arithmetic_function\n\n/-- The L-series of an `arithmetic_function`. -/\ndef l_series (f : arithmetic_function \u2102) (z : \u2102) : \u2102 := \u2211'n, (f n) / (n ^ z)\n\n/-- `f.l_series_summable z` indicates that the L-series of `f` converges at `z`. -/\ndef l_series_summable (f : arithmetic_function \u2102) (z : \u2102) : Prop := summable (\u03bb n, (f n) / (n ^ z))\n\nlemma l_series_eq_zero_of_not_l_series_summable (f : arithmetic_function \u2102) (z : \u2102) :\n  \u00ac f.l_series_summable z \u2192 f.l_series z = 0 :=\ntsum_eq_zero_of_not_summable\n\n@[simp]\nlemma l_series_summable_zero {z : \u2102} : l_series_summable 0 z :=\nby simp [l_series_summable, summable_zero]\n\ntheorem l_series_summable_of_bounded_of_one_lt_real {f : arithmetic_function \u2102} {m : \u211d}\n  (h : \u2200 (n : \u2115), complex.abs (f n) \u2264 m) {z : \u211d} (hz : 1 < z) :\n  f.l_series_summable z :=\nbegin\n  by_cases h0 : m = 0,\n  { subst h0,\n    have hf : f = 0 := arithmetic_function.ext (\u03bb n, complex.abs.eq_zero.1\n        (le_antisymm (h n) (complex.abs.nonneg _))),\n    simp [hf] },\n  refine summable_of_norm_bounded (\u03bb (n : \u2115), m / (n ^ z)) _ _,\n  { simp_rw [div_eq_mul_inv],\n    exact (summable_mul_left_iff h0).2 (real.summable_nat_rpow_inv.2 hz) },\n  { intro n,\n    have hm : 0 \u2264 m := le_trans (complex.abs.nonneg _) (h 0),\n    cases n,\n    { simp [hm, real.zero_rpow (ne_of_gt (lt_trans real.zero_lt_one hz))] },\n    simp only [map_div\u2080, complex.norm_eq_abs],\n    apply div_le_div hm (h _) (real.rpow_pos_of_pos (nat.cast_pos.2 n.succ_pos) _) (le_of_eq _),\n    rw [complex.abs_cpow_real, complex.abs_cast_nat] }\nend\n\n\n\ntheorem l_series_summable_of_bounded_of_one_lt_re {f : arithmetic_function \u2102} {m : \u211d}\n  (h : \u2200 (n : \u2115), complex.abs (f n) \u2264 m) {z : \u2102} (hz : 1 < z.re) :\n  f.l_series_summable z :=\nbegin\n  rw \u2190 l_series_summable_iff_of_re_eq_re (complex.of_real_re z.re),\n  apply l_series_summable_of_bounded_of_one_lt_real h,\n  exact hz,\nend\n\nopen_locale arithmetic_function\n\ntheorem zeta_l_series_summable_iff_one_lt_re {z : \u2102} :\n  l_series_summable \u03b6 z \u2194 1 < z.re :=\nbegin\n  rw [\u2190 l_series_summable_iff_of_re_eq_re (complex.of_real_re z.re), l_series_summable,\n    \u2190 summable_norm_iff, \u2190 real.summable_one_div_nat_rpow, iff_iff_eq],\n  by_cases h0 : z.re = 0,\n  { rw [h0, \u2190 summable_nat_add_iff 1],\n    swap, { apply_instance },\n    apply congr rfl,\n    ext n,\n    simp [n.succ_ne_zero] },\n  { apply congr rfl,\n    ext \u27e8-|n\u27e9,\n    { simp [h0] },\n    simp only [cast_zero, nat_coe_apply, zeta_apply, succ_ne_zero, if_false, cast_succ, one_div,\n               complex.norm_eq_abs, map_inv\u2080, complex.abs_cpow_real, inv_inj, zero_add],\n    rw [\u2190cast_one, \u2190cast_add, complex.abs_of_nat, cast_add, cast_one] }\nend\n\n@[simp] theorem l_series_add {f g : arithmetic_function \u2102} {z : \u2102}\n  (hf : f.l_series_summable z) (hg : g.l_series_summable z) :\n  (f + g).l_series z = f.l_series z + g.l_series z :=\nbegin\n  simp only [l_series, add_apply],\n  rw \u2190 tsum_add hf hg,\n  apply congr rfl (funext (\u03bb n, _)),\n  apply _root_.add_div,\nend\n\nend arithmetic_function\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/l_series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7125794843818634}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport data.set.basic\n\n/-!\n# Circular order hierarchy\n\nThis file defines circular preorders, circular partial orders and circular orders.\n\n## Hierarchy\n\n* A ternary \"betweenness\" relation `btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` forms a `circular_order` if it is\n  - reflexive: `btw a a a`\n  - cyclic: `btw a b c \u2192 btw b c a`\n  - antisymmetric: `btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a`\n  - total: `btw a b c \u2228 btw c b a`\n  along with a strict betweenness relation `sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop` which respects\n  `sbtw a b c \u2194 btw a b c \u2227 \u00ac btw c b a`, analogously to how `<` and `\u2264` are related, and is\n  - transitive: `sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c`.\n* A `circular_partial_order` drops totality.\n* A `circular_preorder` further drops antisymmetry.\n\nThe intuition is that a circular order is a circle and `btw a b c` means that going around\nclockwise from `a` you reach `b` before `c` (`b` is between `a` and `c` is meaningless on an\nunoriented circle). A circular partial order is several, potentially intersecting, circles. A\ncircular preorder is like a circular partial order, but several points can coexist.\n\nNote that the relations between `circular_preorder`, `circular_partial_order` and `circular_order`\nare subtler than between `preorder`, `partial_order`, `linear_order`. In particular, one cannot\nsimply extend the `btw` of a `circular_partial_order` to make it a `circular_order`.\n\nOne can translate from usual orders to circular ones by \"closing the necklace at infinity\". See\n`has_le.to_has_btw` and `has_lt.to_has_sbtw`. Going the other way involves \"cutting the necklace\" or\n\"rolling the necklace open\".\n\n## Examples\n\nSome concrete circular orders one encounters in the wild are `zmod n` for `0 < n`, `circle`,\n`real.angle`...\n\n## Main definitions\n\n* `set.cIcc`: Closed-closed circular interval.\n* `set.cIoo`: Open-open circular interval.\n\n## Notes\n\nThere's an unsolved diamond here. The instances `has_le \u03b1 \u2192 has_btw (order_dual \u03b1)` and\n`has_lt \u03b1 \u2192 has_sbtw (order_dual \u03b1)` can each be inferred in two ways:\n* `has_le \u03b1` \u2192 `has_btw \u03b1` \u2192 `has_btw (order_dual \u03b1)` vs\n  `has_le \u03b1` \u2192 `has_le (order_dual \u03b1)` \u2192 `has_btw (order_dual \u03b1)`\n* `has_lt \u03b1` \u2192 `has_sbtw \u03b1` \u2192 `has_sbtw (order_dual \u03b1)` vs\n  `has_lt \u03b1` \u2192 `has_lt (order_dual \u03b1)` \u2192 `has_sbtw (order_dual \u03b1)`\nThe fields are propeq, but not defeq. It is temporarily fixed by turning the circularizing instances\ninto definitions.\n\n## TODO\n\nAntisymmetry is quite weak in the sense that there's no way to discriminate which two points are\nequal. This prevents defining closed-open intervals `cIco` and `cIoc` in the neat `=`-less way. We\ncurrently haven't defined them at all.\n\nWhat is the correct generality of \"rolling the necklace\" open? At least, this works for `\u03b1 \u00d7 \u03b2` and\n`\u03b2 \u00d7 \u03b1` where `\u03b1` is a circular order and `\u03b2` is a linear order.\n\nWhat's next is to define circular groups and provide instances for `zmod n`, the usual circle group\n`circle`, `real.angle`, and `roots_of_unity M`. What conditions do we need on `M` for this last one\nto work?\n\nWe should have circular order homomorphisms. The typical example is\n`days_to_month : days_of_the_year \u2192c months_of_the_year` which relates the circular order of days\nand the circular order of months. Is `\u03b1 \u2192c \u03b2` a good notation?\n\n## References\n\n* https://en.wikipedia.org/wiki/Cyclic_order\n* https://en.wikipedia.org/wiki/Partial_cyclic_order\n\n## Tags\n\ncircular order, cyclic order, circularly ordered set, cyclically ordered set\n-/\n\n/-- Syntax typeclass for a betweenness relation. -/\nclass has_btw (\u03b1 : Type*) :=\n(btw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop)\n\nexport has_btw (btw)\n\n/-- Syntax typeclass for a strict betweenness relation. -/\nclass has_sbtw (\u03b1 : Type*) :=\n(sbtw : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \u2192 Prop)\n\nexport has_sbtw (sbtw)\n\n/-- A circular preorder is the analogue of a preorder where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive and cyclic. `sbtw` is transitive.\n-/\nclass circular_preorder (\u03b1 : Type*) extends has_btw \u03b1, has_sbtw \u03b1 :=\n(btw_refl (a : \u03b1) : btw a a a)\n(btw_cyclic_left {a b c : \u03b1} : btw a b c \u2192 btw b c a)\n(sbtw := \u03bb a b c, btw a b c \u2227 \u00acbtw c b a)\n(sbtw_iff_btw_not_btw {a b c : \u03b1} : sbtw a b c \u2194 (btw a b c \u2227 \u00acbtw c b a) . order_laws_tac)\n(sbtw_trans_left {a b c d : \u03b1} : sbtw a b c \u2192 sbtw b d c \u2192 sbtw a d c)\n\nexport circular_preorder (btw_refl) (btw_cyclic_left) (sbtw_trans_left)\n\n/-- A circular partial order is the analogue of a partial order where you can loop around. `\u2264` and\n`<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic and\nantisymmetric. `sbtw` is transitive. -/\nclass circular_partial_order (\u03b1 : Type*) extends circular_preorder \u03b1 :=\n(btw_antisymm {a b c : \u03b1} : btw a b c \u2192 btw c b a \u2192 a = b \u2228 b = c \u2228 c = a)\n\nexport circular_partial_order (btw_antisymm)\n\n/-- A circular order is the analogue of a linear order where you can loop around. `\u2264` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic, antisymmetric and total.\n`sbtw` is transitive. -/\nclass circular_order (\u03b1 : Type*) extends circular_partial_order \u03b1 :=\n(btw_total : \u2200 a b c : \u03b1, btw a b c \u2228 btw c b a)\n\nexport circular_order (btw_total)\n\n/-! ### Circular preorders -/\n\nsection circular_preorder\nvariables {\u03b1 : Type*} [circular_preorder \u03b1]\n\nlemma btw_rfl {a : \u03b1} : btw a a a :=\nbtw_refl _\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_cyclic_left        \u2190 has_btw.btw.cyclic_left\nlemma has_btw.btw.cyclic_left {a b c : \u03b1} (h : btw a b c) : btw b c a :=\nbtw_cyclic_left h\n\nlemma btw_cyclic_right {a b c : \u03b1} (h : btw a b c) : btw c a b :=\nh.cyclic_left.cyclic_left\n\nalias btw_cyclic_right \u2190 has_btw.btw.cyclic_right\n\n/-- The order of the `\u2194` has been chosen so that `rw btw_cyclic` cycles to the right while\n`rw \u2190btw_cyclic` cycles to the left (thus following the prepended arrow). -/\nlemma btw_cyclic {a b c : \u03b1} : btw a b c \u2194 btw c a b :=\n\u27e8btw_cyclic_right, btw_cyclic_left\u27e9\n\nlemma sbtw_iff_btw_not_btw {a b c : \u03b1} : sbtw a b c \u2194 btw a b c \u2227 \u00acbtw c b a :=\ncircular_preorder.sbtw_iff_btw_not_btw\n\nlemma btw_of_sbtw {a b c : \u03b1} (h : sbtw a b c) : btw a b c :=\n(sbtw_iff_btw_not_btw.1 h).1\n\nalias btw_of_sbtw \u2190 has_sbtw.sbtw.btw\n\nlemma not_btw_of_sbtw {a b c : \u03b1} (h : sbtw a b c) : \u00acbtw c b a :=\n(sbtw_iff_btw_not_btw.1 h).2\n\nalias not_btw_of_sbtw \u2190 has_sbtw.sbtw.not_btw\n\nlemma not_sbtw_of_btw {a b c : \u03b1} (h : btw a b c) : \u00acsbtw c b a :=\n\u03bb h', h'.not_btw h\n\nalias not_sbtw_of_btw \u2190 has_btw.btw.not_sbtw\n\nlemma sbtw_of_btw_not_btw {a b c : \u03b1} (habc : btw a b c) (hcba : \u00acbtw c b a) : sbtw a b c :=\nsbtw_iff_btw_not_btw.2 \u27e8habc, hcba\u27e9\n\nalias sbtw_of_btw_not_btw \u2190 has_btw.btw.sbtw_of_not_btw\n\nlemma sbtw_cyclic_left {a b c : \u03b1} (h : sbtw a b c) : sbtw b c a :=\nh.btw.cyclic_left.sbtw_of_not_btw (\u03bb h', h.not_btw h'.cyclic_left)\n\nalias sbtw_cyclic_left \u2190 has_sbtw.sbtw.cyclic_left\n\nlemma sbtw_cyclic_right {a b c : \u03b1} (h : sbtw a b c) : sbtw c a b :=\nh.cyclic_left.cyclic_left\n\nalias sbtw_cyclic_right \u2190 has_sbtw.sbtw.cyclic_right\n\n/-- The order of the `\u2194` has been chosen so that `rw sbtw_cyclic` cycles to the right while\n`rw \u2190sbtw_cyclic` cycles to the left (thus following the prepended arrow). -/\nlemma sbtw_cyclic {a b c : \u03b1} : sbtw a b c \u2194 sbtw c a b :=\n\u27e8sbtw_cyclic_right, sbtw_cyclic_left\u27e9\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_trans_left        \u2190 has_btw.btw.trans_left\nlemma has_sbtw.sbtw.trans_left {a b c d : \u03b1} (h : sbtw a b c) : sbtw b d c \u2192 sbtw a d c :=\nsbtw_trans_left h\n\nlemma sbtw_trans_right {a b c d : \u03b1} (hbc : sbtw a b c) (hcd : sbtw a c d) : sbtw a b d :=\n(hbc.cyclic_left.trans_left hcd.cyclic_left).cyclic_right\n\nalias sbtw_trans_right \u2190 has_sbtw.sbtw.trans_right\n\nlemma sbtw_asymm {a b c : \u03b1} (h : sbtw a b c) : \u00ac sbtw c b a :=\nh.btw.not_sbtw\n\nalias sbtw_asymm \u2190 has_sbtw.sbtw.not_sbtw\n\nlemma sbtw_irrefl_left_right {a b : \u03b1} : \u00ac sbtw a b a := \u03bb h, h.not_btw h.btw\nlemma sbtw_irrefl_left {a b : \u03b1} : \u00ac sbtw a a b := \u03bb h, sbtw_irrefl_left_right h.cyclic_left\nlemma sbtw_irrefl_right {a b : \u03b1} : \u00ac sbtw a b b := \u03bb h, sbtw_irrefl_left_right h.cyclic_right\nlemma sbtw_irrefl (a : \u03b1) : \u00ac sbtw a a a := sbtw_irrefl_left_right\n\nend circular_preorder\n\n/-! ### Circular partial orders -/\n\nsection circular_partial_order\nvariables {\u03b1 : Type*} [circular_partial_order \u03b1]\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_antisymm        \u2190 has_btw.btw.antisymm\nlemma has_btw.btw.antisymm {a b c : \u03b1} (h : btw a b c) : btw c b a \u2192 a = b \u2228 b = c \u2228 c = a :=\nbtw_antisymm h\n\nend circular_partial_order\n\n/-! ### Circular orders -/\n\nsection circular_order\nvariables {\u03b1 : Type*} [circular_order \u03b1]\n\nlemma btw_refl_left_right (a b : \u03b1) : btw a b a :=\n(or_self _).1 (btw_total a b a)\n\nlemma btw_rfl_left_right {a b : \u03b1} : btw a b a :=\nbtw_refl_left_right _ _\n\nlemma btw_refl_left (a b : \u03b1) : btw a a b :=\nbtw_rfl_left_right.cyclic_right\n\nlemma btw_rfl_left {a b : \u03b1} : btw a a b :=\nbtw_refl_left _ _\n\nlemma btw_refl_right (a b : \u03b1) : btw a b b :=\nbtw_rfl_left_right.cyclic_left\n\nlemma btw_rfl_right {a b : \u03b1} : btw a b b :=\nbtw_refl_right _ _\n\nlemma sbtw_iff_not_btw {a b c : \u03b1} : sbtw a b c \u2194 \u00ac btw c b a :=\nbegin\n  rw sbtw_iff_btw_not_btw,\n  exact and_iff_right_of_imp (btw_total _ _ _).resolve_left,\nend\n\nlemma btw_iff_not_sbtw {a b c : \u03b1} : btw a b c \u2194 \u00ac sbtw c b a :=\niff_not_comm.1 sbtw_iff_not_btw\n\nend circular_order\n\n/-! ### Circular intervals -/\n\nnamespace set\n\nsection circular_preorder\nvariables {\u03b1 : Type*} [circular_preorder \u03b1]\n\n/-- Closed-closed circular interval -/\ndef cIcc (a b : \u03b1) : set \u03b1 := {x | btw a x b}\n\n/-- Open-open circular interval -/\ndef cIoo (a b : \u03b1) : set \u03b1 := {x | sbtw a x b}\n\n@[simp] lemma mem_cIcc {a b x : \u03b1} : x \u2208 cIcc a b \u2194 btw a x b := iff.rfl\n@[simp] lemma mem_cIoo {a b x : \u03b1} : x \u2208 cIoo a b \u2194 sbtw a x b := iff.rfl\n\nend circular_preorder\n\nsection circular_order\nvariables {\u03b1 : Type*} [circular_order \u03b1]\n\nlemma left_mem_cIcc (a b : \u03b1) : a \u2208 cIcc a b := btw_rfl_left\nlemma right_mem_cIcc (a b : \u03b1) : b \u2208 cIcc a b := btw_rfl_right\n\nlemma compl_cIcc {a b : \u03b1} : (cIcc a b)\u1d9c = cIoo b a :=\nbegin\n  ext,\n  rw [set.mem_cIoo, sbtw_iff_not_btw],\n  refl,\nend\n\nlemma compl_cIoo {a b : \u03b1} : (cIoo a b)\u1d9c = cIcc b a :=\nbegin\n  ext,\n  rw [set.mem_cIcc, btw_iff_not_sbtw],\n  refl,\nend\n\nend circular_order\nend set\n\n/-! ### Circularizing instances -/\n\n/-- The betweenness relation obtained from \"looping around\" `\u2264`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef has_le.to_has_btw (\u03b1 : Type*) [has_le \u03b1] : has_btw \u03b1 :=\n{ btw := \u03bb a b c, (a \u2264 b \u2227 b \u2264 c) \u2228 (b \u2264 c \u2227 c \u2264 a) \u2228 (c \u2264 a \u2227 a \u2264 b) }\n\n/-- The strict betweenness relation obtained from \"looping around\" `<`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef has_lt.to_has_sbtw (\u03b1 : Type*) [has_lt \u03b1] : has_sbtw \u03b1 :=\n{ sbtw := \u03bb a b c, (a < b \u2227 b < c) \u2228 (b < c \u2227 c < a) \u2228 (c < a \u2227 a < b) }\n\n/-- The circular preorder obtained from \"looping around\" a preorder.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef preorder.to_circular_preorder (\u03b1 : Type*) [preorder \u03b1] : circular_preorder \u03b1 :=\n{ btw := \u03bb a b c, (a \u2264 b \u2227 b \u2264 c) \u2228 (b \u2264 c \u2227 c \u2264 a) \u2228 (c \u2264 a \u2227 a \u2264 b),\n  sbtw := \u03bb a b c, (a < b \u2227 b < c) \u2228 (b < c \u2227 c < a) \u2228 (c < a \u2227 a < b),\n  btw_refl := \u03bb a, or.inl \u27e8le_rfl, le_rfl\u27e9,\n  btw_cyclic_left := \u03bb a b c h, begin\n    unfold btw at \u22a2 h,\n    rwa [\u2190or.assoc, or_comm],\n  end,\n  sbtw_trans_left := \u03bb a b c d, begin\n    rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hbd, hdc\u27e9 | \u27e8hdc, hcb\u27e9 | \u27e8hcb, hbd\u27e9),\n    { exact or.inl \u27e8hab.trans hbd, hdc\u27e9 },\n    { exact (hbc.not_lt hcb).elim },\n    { exact (hbc.not_lt hcb).elim },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact (hbc.not_lt hcb).elim },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact or.inr (or.inl \u27e8hdc, hca\u27e9) },\n    { exact or.inr (or.inr \u27e8hca, hab.trans hbd\u27e9) }\n  end,\n  sbtw_iff_btw_not_btw := \u03bb a b c, begin\n    simp_rw lt_iff_le_not_le,\n    set x\u2080 := a \u2264 b,\n    set x\u2081 := b \u2264 c,\n    set x\u2082 := c \u2264 a,\n    have : x\u2080 \u2192 x\u2081 \u2192 a \u2264 c := le_trans,\n    have : x\u2081 \u2192 x\u2082 \u2192 b \u2264 a := le_trans,\n    have : x\u2082 \u2192 x\u2080 \u2192 c \u2264 b := le_trans,\n    clear_value x\u2080 x\u2081 x\u2082,\n    tauto!,\n  end }\n\n/-- The circular partial order obtained from \"looping around\" a partial order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef partial_order.to_circular_partial_order (\u03b1 : Type*) [partial_order \u03b1] :\n  circular_partial_order \u03b1 :=\n{ btw_antisymm := \u03bb a b c, begin\n    rintro (\u27e8hab, hbc\u27e9 | \u27e8hbc, hca\u27e9 | \u27e8hca, hab\u27e9) (\u27e8hcb, hba\u27e9 | \u27e8hba, hac\u27e9 | \u27e8hac, hcb\u27e9),\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inr (or.inl $ hbc.antisymm hcb) },\n    { exact or.inr (or.inl $ hbc.antisymm hcb) },\n    { exact or.inr (or.inr $ hca.antisymm hac) },\n    { exact or.inr (or.inl $ hbc.antisymm hcb) },\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inl (hab.antisymm hba) },\n    { exact or.inr (or.inr $ hca.antisymm hac) }\n  end,\n  .. preorder.to_circular_preorder \u03b1 }\n\n/-- The circular order obtained from \"looping around\" a linear order.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef linear_order.to_circular_order (\u03b1 : Type*) [linear_order \u03b1] :\n  circular_order \u03b1 :=\n{ btw_total := \u03bb a b c, begin\n    cases le_total a b with hab hba; cases le_total b c with hbc hcb;\n      cases le_total c a with hca hac,\n    { exact or.inl (or.inl \u27e8hab, hbc\u27e9) },\n    { exact or.inl (or.inl \u27e8hab, hbc\u27e9) },\n    { exact or.inl (or.inr $ or.inr \u27e8hca, hab\u27e9) },\n    { exact or.inr (or.inr $ or.inr \u27e8hac, hcb\u27e9) },\n    { exact or.inl (or.inr $ or.inl \u27e8hbc, hca\u27e9) },\n    { exact or.inr (or.inr $ or.inl \u27e8hba, hac\u27e9) },\n    { exact or.inr (or.inl \u27e8hcb, hba\u27e9) },\n    { exact or.inr (or.inr $ or.inl \u27e8hba, hac\u27e9) }\n  end,\n  .. partial_order.to_circular_partial_order \u03b1 }\n\n/-! ### Dual constructions -/\n\nsection order_dual\n\ninstance (\u03b1 : Type*) [has_btw \u03b1] : has_btw (order_dual \u03b1) := \u27e8\u03bb a b c : \u03b1, btw c b a\u27e9\ninstance (\u03b1 : Type*) [has_sbtw \u03b1] : has_sbtw (order_dual \u03b1) := \u27e8\u03bb a b c : \u03b1, sbtw c b a\u27e9\n\ninstance (\u03b1 : Type*) [h : circular_preorder \u03b1] : circular_preorder (order_dual \u03b1) :=\n{ btw_refl := btw_refl,\n  btw_cyclic_left := \u03bb a b c, btw_cyclic_right,\n  sbtw_trans_left := \u03bb a b c d habc hbdc, hbdc.trans_right habc,\n  sbtw_iff_btw_not_btw := \u03bb a b c, @sbtw_iff_btw_not_btw \u03b1 _ c b a,\n  .. order_dual.has_btw \u03b1,\n  .. order_dual.has_sbtw \u03b1 }\n\ninstance (\u03b1 : Type*) [circular_partial_order \u03b1] : circular_partial_order (order_dual \u03b1) :=\n{ btw_antisymm := \u03bb a b c habc hcba, @btw_antisymm \u03b1 _ _ _ _ hcba habc,\n  .. order_dual.circular_preorder \u03b1 }\n\ninstance (\u03b1 : Type*) [circular_order \u03b1] : circular_order (order_dual \u03b1) :=\n{ btw_total := \u03bb a b c, btw_total c b a, .. order_dual.circular_partial_order \u03b1 }\n\nend order_dual\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/order/circular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.712579481681051}}
{"text": "import tactic.interactive tactic.squeeze data.nat.modeq\n\nvariables n m : nat \n\n@[simp]\ndef is_odd_a : \u2115 \u2192 bool\n| 0 := ff\n| (nat.succ n) := bnot (is_odd_a n)\n\n#reduce is_odd_a (n + 2)\n\nlemma odd_ss_a : is_odd_a (n + 2) = is_odd_a n := \nbegin\n dsimp[is_odd_a],\n cases is_odd_a n; refl,\nend\n\nlemma odd_add_a : \u2200 n m : \u2115 , \n is_odd_a (n + m) = bxor (is_odd_a n) (is_odd_a m)\n| n 0 := by rw[is_odd_a,nat.add_zero,bxor_ff]\n| n (m + 1) := begin\n   rw[nat.add_succ,is_odd_a,is_odd_a,(odd_add_a n m)],\n   cases (is_odd_a n); cases (is_odd_a m); refl,\n  end\n\n/- ------------------------------------------------------------ -/\n\n@[simp]\ndef s : \u2115 \u00d7 bool \u2192 \u2115 \u00d7 bool\n| \u27e8n,ff\u27e9 := \u27e8n,tt\u27e9\n| \u27e8n,tt\u27e9 := \u27e8n.succ,ff\u27e9 \n\n@[simp]\ndef ss : \u2115 \u2192 \u2115 \u00d7 bool\n| 0 := \u27e80,ff\u27e9 \n| (nat.succ n) := s (ss n) \n\ndef is_odd_b (n : \u2115) : bool := (ss n).2\n\n#reduce ss (n + 2)\n\nlemma odd_ss_b : is_odd_b (n + 2) = is_odd_b n :=\nbegin\n dsimp[is_odd_b,ss,s],\n rcases (ss n) with \u27e8k,tt|ff\u27e9;refl,\nend\n\ndef Nb_add : \u2115 \u00d7 bool \u2192 \u2115 \u00d7 bool \u2192 \u2115 \u00d7 bool \n| \u27e8n,ff\u27e9 \u27e8m,b\u27e9 := \u27e8n+m,b\u27e9 \n| \u27e8n,tt\u27e9 \u27e8m,ff\u27e9 := \u27e8n+m,tt\u27e9 \n| \u27e8n,tt\u27e9 \u27e8m,tt\u27e9 := \u27e8n+m+1,ff\u27e9\n\nlemma Nb_add_s (u v) : Nb_add u (s v) = s (Nb_add u v) := \nbegin\n rcases u with \u27e8i,ff|tt\u27e9; rcases v with \u27e8j,ff|tt\u27e9; refl,\nend\n\nlemma ss_add (n m : \u2115) : ss (n + m) = Nb_add (ss n) (ss m) := \nbegin\n induction m with m ih_m,\n {rw[add_zero,ss],cases (ss n) with k b; cases b; refl},\n {rw[nat.add_succ,ss,ss,ih_m,Nb_add_s],}\nend\n\nlemma odd_add_b : \u2200 n m : \u2115, \n is_odd_b (n + m) = bxor (is_odd_b n) (is_odd_b m) := \nbegin\n intros n m,\n rw[is_odd_b,is_odd_b,is_odd_b,ss_add],\n rcases (ss n) with \u27e8i,ff|tt\u27e9; rcases (ss m) with \u27e8j,ff|tt\u27e9; refl,\nend\n\n/- ------------------------------------------------------------ -/\n\n@[simp]\ndef is_odd_c (n : \u2115) : bool := if n % 2 = 0 then ff else tt\n\nlemma odd_ss_c : is_odd_c (n + 2) = is_odd_c n :=\nbegin\n dsimp[is_odd_c],\n rw [nat.add_mod_right n 2]\nend\n\n/- ------------------------------------------------------------ -/\n\nmutual def is_odd_d, is_even_d\nwith is_odd_d : nat \u2192 bool\n| 0     := ff\n| (n + 1) := is_even_d n\nwith is_even_d : nat \u2192 bool\n| 0     := tt\n| (n + 1) := is_odd_d n\n\n#check n\n#reduce is_odd_d (n + 2)\n\nlemma odd_ss_d : is_odd_d (n + 2) = is_odd_d n :=\nbegin\n rw[is_odd_d,is_even_d], \nend\n\nlemma odd_even_d : \u2200 (n : \u2115), is_odd_d n = bnot (is_even_d n) \n| 0 := by {rw[is_odd_d,is_even_d],refl}\n| (n + 1) := by {rw[is_odd_d,is_even_d,odd_even_d n,bnot_bnot],}\n\n@[inline] def beq : bool \u2192 bool \u2192 bool\n| tt tt  := tt\n| ff ff  := tt\n| _  _   := ff\n\nlemma even_add_d : \u2200 n m : \u2115, \n is_even_d (n + m) = beq (is_even_d n) (is_even_d m) := \nbegin\n intros n m,\n induction m with m ih_m,\n {rw[add_zero,is_even_d],cases is_even_d n;refl},\n {rw[nat.add_succ,is_even_d,is_even_d,odd_even_d,odd_even_d,ih_m],\n  cases is_even_d n;cases is_even_d m; refl,\n }\nend\n\nlemma odd_add_d : \u2200 n m : \u2115, \n is_odd_d (n + m) = bxor (is_odd_d n) (is_odd_d m) := \nbegin\n intros n m,\n rw[odd_even_d,odd_even_d,odd_even_d,even_add_d],\n cases is_even_d n;cases is_even_d m; refl,\nend\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/exercises/mathcomp_book/odd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7125794805073888}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport data.list.prime\nimport data.polynomial.field_division\nimport data.polynomial.lifts\n\n/-!\n# Split polynomials\n\nA polynomial `f : K[X]` splits over a field extension `L` of `K` if it is zero or all of its\nirreducible factors over `L` have degree `1`.\n\n## Main definitions\n\n* `polynomial.splits i f`: A predicate on a homomorphism `i : K \u2192+* L` from a commutative ring to a\n  field and a polynomial `f` saying that `f.map i` is zero or all of its irreducible factors over\n  `L` have degree `1`.\n\n## Main statements\n\n* `lift_of_splits`: If `K` and `L` are field extensions of a field `F` and for some finite subset\n  `S` of `K`, the minimal polynomial of every `x \u2208 K` splits as a polynomial with coefficients in\n  `L`, then `algebra.adjoin F S` embeds into `L`.\n\n-/\n\nnoncomputable theory\nopen_locale classical big_operators polynomial\n\nuniverses u v w\n\nvariables {F : Type u} {K : Type v} {L : Type w}\n\nnamespace polynomial\n\nopen polynomial\n\nsection splits\n\nsection comm_ring\nvariables [comm_ring K] [field L] [field F]\nvariables (i : K \u2192+* L)\n\n/-- A polynomial `splits` iff it is zero or all of its irreducible factors have `degree` 1. -/\ndef splits (f : K[X]) : Prop :=\nf.map i = 0 \u2228 \u2200 {g : L[X]}, irreducible g \u2192 g \u2223 f.map i \u2192 degree g = 1\n\n@[simp] \n\nlemma splits_of_map_eq_C {f : K[X]} {a : L} (h : f.map i = C a) : splits i f :=\nif ha : a = 0 then or.inl (h.trans (ha.symm \u25b8 C_0))\nelse or.inr $ \u03bb g hg \u27e8p, hp\u27e9, absurd hg.1 $ not_not.2 $ is_unit_iff_degree_eq_zero.2 $\nbegin\n  have := congr_arg degree hp,\n  rw [h, degree_C ha, degree_mul, @eq_comm (with_bot \u2115) 0, nat.with_bot.add_eq_zero_iff] at this,\n  exact this.1,\nend\n\n@[simp] lemma splits_C (a : K) : splits i (C a) := splits_of_map_eq_C i (map_C i)\n\nlemma splits_of_map_degree_eq_one {f : K[X]} (hf : degree (f.map i) = 1) : splits i f :=\nor.inr $ \u03bb g hg \u27e8p, hp\u27e9,\n  by have := congr_arg degree hp;\n  simp [nat.with_bot.add_eq_one_iff, hf, @eq_comm (with_bot \u2115) 1,\n    mt is_unit_iff_degree_eq_zero.2 hg.1] at this;\n  clear _fun_match; tauto\n\nlemma splits_of_degree_le_one {f : K[X]} (hf : degree f \u2264 1) : splits i f :=\nif hif : degree (f.map i) \u2264 0 then splits_of_map_eq_C i (degree_le_zero_iff.mp hif)\nelse begin\n  push_neg at hif,\n  rw [\u2190 order.succ_le_iff, \u2190 with_bot.coe_zero, with_bot.succ_coe, nat.succ_eq_succ] at hif,\n  exact splits_of_map_degree_eq_one i (le_antisymm ((degree_map_le i _).trans hf) hif),\nend\n\nlemma splits_of_degree_eq_one {f : K[X]} (hf : degree f = 1) : splits i f :=\nsplits_of_degree_le_one i hf.le\n\nlemma splits_of_nat_degree_le_one {f : K[X]} (hf : nat_degree f \u2264 1) : splits i f :=\nsplits_of_degree_le_one i (degree_le_of_nat_degree_le hf)\n\nlemma splits_of_nat_degree_eq_one {f : K[X]} (hf : nat_degree f = 1) : splits i f :=\nsplits_of_nat_degree_le_one i (le_of_eq hf)\n\nlemma splits_mul {f g : K[X]} (hf : splits i f) (hg : splits i g) : splits i (f * g) :=\nif h : (f * g).map i = 0 then or.inl h\nelse or.inr $ \u03bb p hp hpf, ((principal_ideal_ring.irreducible_iff_prime.1 hp).2.2 _ _\n    (show p \u2223 map i f * map i g, by convert hpf; rw polynomial.map_mul)).elim\n  (hf.resolve_left (\u03bb hf, by simpa [hf] using h) hp)\n  (hg.resolve_left (\u03bb hg, by simpa [hg] using h) hp)\n\nlemma splits_of_splits_mul' {f g : K[X]} (hfg : (f * g).map i \u2260 0) (h : splits i (f * g)) :\n  splits i f \u2227 splits i g :=\n\u27e8or.inr $ \u03bb g hgi hg, or.resolve_left h hfg hgi\n   (by rw polynomial.map_mul; exact hg.trans (dvd_mul_right _ _)),\n or.inr $ \u03bb g hgi hg, or.resolve_left h hfg hgi\n   (by rw polynomial.map_mul; exact hg.trans (dvd_mul_left _ _))\u27e9\n\nlemma splits_map_iff (j : L \u2192+* F) {f : K[X]} :\n  splits j (f.map i) \u2194 splits (j.comp i) f :=\nby simp [splits, polynomial.map_map]\n\ntheorem splits_one : splits i 1 :=\nsplits_C i 1\n\ntheorem splits_of_is_unit [is_domain K] {u : K[X]} (hu : is_unit u) : u.splits i :=\n(is_unit_iff.mp hu).some_spec.2 \u25b8 splits_C _ _\n\ntheorem splits_X_sub_C {x : K} : (X - C x).splits i :=\nsplits_of_degree_le_one _ $ degree_X_sub_C_le _\n\ntheorem splits_X : X.splits i :=\nsplits_of_degree_le_one _ degree_X_le\n\ntheorem splits_prod {\u03b9 : Type u} {s : \u03b9 \u2192 K[X]} {t : finset \u03b9} :\n  (\u2200 j \u2208 t, (s j).splits i) \u2192 (\u220f x in t, s x).splits i :=\nbegin\n  refine finset.induction_on t (\u03bb _, splits_one i) (\u03bb a t hat ih ht, _),\n  rw finset.forall_mem_insert at ht, rw finset.prod_insert hat,\n  exact splits_mul i ht.1 (ih ht.2)\nend\n\nlemma splits_pow {f : K[X]} (hf : f.splits i) (n : \u2115) : (f ^ n).splits i :=\nbegin\n  rw [\u2190finset.card_range n, \u2190finset.prod_const],\n  exact splits_prod i (\u03bb j hj, hf),\nend\n\nlemma splits_X_pow (n : \u2115) : (X ^ n).splits i := splits_pow i (splits_X i) n\n\ntheorem splits_id_iff_splits {f : K[X]} :\n  (f.map i).splits (ring_hom.id L) \u2194 f.splits i :=\nby rw [splits_map_iff, ring_hom.id_comp]\n\nlemma exists_root_of_splits' {f : K[X]} (hs : splits i f) (hf0 : degree (f.map i) \u2260 0) :\n  \u2203 x, eval\u2082 i x f = 0 :=\nif hf0' : f.map i = 0 then by simp [eval\u2082_eq_eval_map, hf0']\nelse\n  let \u27e8g, hg\u27e9 := wf_dvd_monoid.exists_irreducible_factor\n    (show \u00ac is_unit (f.map i), from mt is_unit_iff_degree_eq_zero.1 hf0) hf0' in\n  let \u27e8x, hx\u27e9 := exists_root_of_degree_eq_one (hs.resolve_left hf0' hg.1 hg.2) in\n  let \u27e8i, hi\u27e9 := hg.2 in\n  \u27e8x, by rw [\u2190 eval_map, hi, eval_mul, show _ = _, from hx, zero_mul]\u27e9\n\nlemma roots_ne_zero_of_splits' {f : K[X]} (hs : splits i f) (hf0 : nat_degree (f.map i) \u2260 0) :\n  (f.map i).roots \u2260 0 :=\nlet \u27e8x, hx\u27e9 := exists_root_of_splits' i hs (\u03bb h, hf0 $ nat_degree_eq_of_degree_eq_some h) in\n\u03bb h, by { rw \u2190 eval_map at hx,\n  cases h.subst ((mem_roots _).2 hx), exact ne_zero_of_nat_degree_gt (nat.pos_of_ne_zero hf0) }\n\n/-- Pick a root of a polynomial that splits. See `root_of_splits` for polynomials over a field\nwhich has simpler assumptions. -/\ndef root_of_splits' {f : K[X]} (hf : f.splits i) (hfd : (f.map i).degree \u2260 0) : L :=\nclassical.some $ exists_root_of_splits' i hf hfd\n\ntheorem map_root_of_splits' {f : K[X]} (hf : f.splits i) (hfd) :\n  f.eval\u2082 i (root_of_splits' i hf hfd) = 0 :=\nclassical.some_spec $ exists_root_of_splits' i hf hfd\n\nlemma nat_degree_eq_card_roots' {p : K[X]} {i : K \u2192+* L}\n  (hsplit : splits i p) : (p.map i).nat_degree = (p.map i).roots.card :=\nbegin\n  by_cases hp : p.map i = 0,\n  { rw [hp, nat_degree_zero, roots_zero, multiset.card_zero] },\n  obtain \u27e8q, he, hd, hr\u27e9 := exists_prod_multiset_X_sub_C_mul (p.map i),\n  rw [\u2190 splits_id_iff_splits, \u2190 he] at hsplit,\n  rw \u2190 he at hp,\n  have hq : q \u2260 0 := \u03bb h, hp (by rw [h, mul_zero]),\n  rw [\u2190 hd, add_right_eq_self],\n  by_contra,\n  have h' : (map (ring_hom.id L) q).nat_degree \u2260 0, { simp [h], },\n  have := roots_ne_zero_of_splits' (ring_hom.id L) (splits_of_splits_mul' _ _ hsplit).2 h',\n  { rw map_id at this, exact this hr },\n  { rw [map_id], exact mul_ne_zero monic_prod_multiset_X_sub_C.ne_zero hq },\nend\n\nlemma degree_eq_card_roots' {p : K[X]} {i : K \u2192+* L} (p_ne_zero : p.map i \u2260 0)\n  (hsplit : splits i p) : (p.map i).degree = (p.map i).roots.card :=\nby rw [degree_eq_nat_degree p_ne_zero, nat_degree_eq_card_roots' hsplit]\n\nend comm_ring\n\nvariables [field K] [field L] [field F]\nvariables (i : K \u2192+* L)\n\n/-- This lemma is for polynomials over a field. -/\nlemma splits_iff (f : K[X]) :\n  splits i f \u2194 f = 0 \u2228 \u2200 {g : L[X]}, irreducible g \u2192 g \u2223 f.map i \u2192 degree g = 1 :=\nby rw [splits, map_eq_zero]\n\n/-- This lemma is for polynomials over a field. -/\nlemma splits.def {i : K \u2192+* L} {f : K[X]} (h : splits i f) :\n  f = 0 \u2228 \u2200 {g : L[X]}, irreducible g \u2192 g \u2223 f.map i \u2192 degree g = 1 :=\n(splits_iff i f).mp h\n\nlemma splits_of_splits_mul {f g : K[X]} (hfg : f * g \u2260 0) (h : splits i (f * g)) :\n  splits i f \u2227 splits i g :=\nsplits_of_splits_mul' i (map_ne_zero hfg) h\n\nlemma splits_of_splits_of_dvd {f g : K[X]} (hf0 : f \u2260 0) (hf : splits i f) (hgf : g \u2223 f) :\n  splits i g :=\nby { obtain \u27e8f, rfl\u27e9 := hgf, exact (splits_of_splits_mul i hf0 hf).1 }\n\nlemma splits_of_splits_gcd_left {f g : K[X]} (hf0 : f \u2260 0) (hf : splits i f) :\n  splits i (euclidean_domain.gcd f g) :=\npolynomial.splits_of_splits_of_dvd i hf0 hf (euclidean_domain.gcd_dvd_left f g)\n\nlemma splits_of_splits_gcd_right {f g : K[X]} (hg0 : g \u2260 0) (hg : splits i g) :\n  splits i (euclidean_domain.gcd f g) :=\npolynomial.splits_of_splits_of_dvd i hg0 hg (euclidean_domain.gcd_dvd_right f g)\n\ntheorem splits_mul_iff {f g : K[X]} (hf : f \u2260 0) (hg : g \u2260 0) :\n  (f * g).splits i \u2194 f.splits i \u2227 g.splits i :=\n\u27e8splits_of_splits_mul i (mul_ne_zero hf hg), \u03bb \u27e8hfs, hgs\u27e9, splits_mul i hfs hgs\u27e9\n\ntheorem splits_prod_iff {\u03b9 : Type u} {s : \u03b9 \u2192 K[X]} {t : finset \u03b9} :\n  (\u2200 j \u2208 t, s j \u2260 0) \u2192 ((\u220f x in t, s x).splits i \u2194 \u2200 j \u2208 t, (s j).splits i) :=\nbegin\n  refine finset.induction_on t (\u03bb _, \u27e8\u03bb _ _ h, h.elim, \u03bb _, splits_one i\u27e9) (\u03bb a t hat ih ht, _),\n  rw finset.forall_mem_insert at ht \u22a2,\n  rw [finset.prod_insert hat, splits_mul_iff i ht.1 (finset.prod_ne_zero_iff.2 ht.2), ih ht.2]\nend\n\nlemma degree_eq_one_of_irreducible_of_splits {p : K[X]}\n  (hp : irreducible p) (hp_splits : splits (ring_hom.id K) p) :\n  p.degree = 1 :=\nbegin\n  rcases hp_splits,\n  { exfalso, simp * at *, },\n  { apply hp_splits hp, simp }\nend\n\nlemma exists_root_of_splits {f : K[X]} (hs : splits i f) (hf0 : degree f \u2260 0) :\n  \u2203 x, eval\u2082 i x f = 0 :=\nexists_root_of_splits' i hs ((f.degree_map i).symm \u25b8 hf0)\n\nlemma roots_ne_zero_of_splits {f : K[X]} (hs : splits i f) (hf0 : nat_degree f \u2260 0) :\n  (f.map i).roots \u2260 0 :=\nroots_ne_zero_of_splits' i hs (ne_of_eq_of_ne (nat_degree_map i) hf0)\n\n/-- Pick a root of a polynomial that splits. This version is for polynomials over a field and has\nsimpler assumptions. -/\ndef root_of_splits {f : K[X]} (hf : f.splits i) (hfd : f.degree \u2260 0) : L :=\nroot_of_splits' i hf ((f.degree_map i).symm \u25b8 hfd)\n\n/-- `root_of_splits'` is definitionally equal to `root_of_splits`. -/\nlemma root_of_splits'_eq_root_of_splits {f : K[X]} (hf : f.splits i) (hfd) :\n  root_of_splits' i hf hfd = root_of_splits i hf (f.degree_map i \u25b8 hfd) := rfl\n\ntheorem map_root_of_splits {f : K[X]} (hf : f.splits i) (hfd) :\n  f.eval\u2082 i (root_of_splits i hf hfd) = 0 :=\nmap_root_of_splits' i hf (ne_of_eq_of_ne (degree_map f i) hfd)\n\nlemma nat_degree_eq_card_roots {p : K[X]} {i : K \u2192+* L}\n  (hsplit : splits i p) : p.nat_degree = (p.map i).roots.card :=\n(nat_degree_map i).symm.trans $ nat_degree_eq_card_roots' hsplit\n\nlemma degree_eq_card_roots {p : K[X]} {i : K \u2192+* L} (p_ne_zero : p \u2260 0)\n  (hsplit : splits i p) : p.degree = (p.map i).roots.card :=\nby rw [degree_eq_nat_degree p_ne_zero, nat_degree_eq_card_roots hsplit]\n\ntheorem roots_map {f : K[X]} (hf : f.splits $ ring_hom.id K) :\n  (f.map i).roots = f.roots.map i :=\n(roots_map_of_injective_of_card_eq_nat_degree i.injective $\n  by { convert (nat_degree_eq_card_roots hf).symm, rw map_id }).symm\n\nlemma image_root_set [algebra F K] [algebra F L] {p : F[X]} (h : p.splits (algebra_map F K))\n  (f : K \u2192\u2090[F] L) : f '' p.root_set K = p.root_set L :=\nbegin\n  classical,\n  rw [root_set, \u2190finset.coe_image, \u2190multiset.to_finset_map, \u2190f.coe_to_ring_hom, \u2190roots_map \u2191f\n      ((splits_id_iff_splits (algebra_map F K)).mpr h), map_map, f.comp_algebra_map, \u2190root_set],\nend\n\nlemma adjoin_root_set_eq_range [algebra F K] [algebra F L] {p : F[X]}\n  (h : p.splits (algebra_map F K)) (f : K \u2192\u2090[F] L) :\n  algebra.adjoin F (p.root_set L) = f.range \u2194 algebra.adjoin F (p.root_set K) = \u22a4 :=\nbegin\n  rw [\u2190image_root_set h f, algebra.adjoin_image, \u2190algebra.map_top],\n  exact (subalgebra.map_injective f.to_ring_hom.injective).eq_iff,\nend\n\nlemma eq_prod_roots_of_splits {p : K[X]} {i : K \u2192+* L} (hsplit : splits i p) :\n  p.map i = C (i p.leading_coeff) * ((p.map i).roots.map (\u03bb a, X - C a)).prod :=\nbegin\n  rw \u2190 leading_coeff_map, symmetry,\n  apply C_leading_coeff_mul_prod_multiset_X_sub_C,\n  rw nat_degree_map, exact (nat_degree_eq_card_roots hsplit).symm,\nend\n\nlemma eq_prod_roots_of_splits_id {p : K[X]}\n  (hsplit : splits (ring_hom.id K) p) :\n  p = C p.leading_coeff * (p.roots.map (\u03bb a, X - C a)).prod :=\nby simpa using eq_prod_roots_of_splits hsplit\n\nlemma eq_prod_roots_of_monic_of_splits_id {p : K[X]}\n  (m : monic p) (hsplit : splits (ring_hom.id K) p) :\n  p = (p.roots.map (\u03bb a, X - C a)).prod :=\nbegin\n  convert eq_prod_roots_of_splits_id hsplit,\n  simp [m],\nend\n\nlemma eq_X_sub_C_of_splits_of_single_root {x : K} {h : K[X]} (h_splits : splits i h)\n  (h_roots : (h.map i).roots = {i x}) : h = C h.leading_coeff * (X - C x) :=\nbegin\n  apply polynomial.map_injective _ i.injective,\n  rw [eq_prod_roots_of_splits h_splits, h_roots],\n  simp,\nend\n\ntheorem mem_lift_of_splits_of_roots_mem_range (R : Type*) [comm_ring R] [algebra R K] {f : K[X]}\n  (hs : f.splits (ring_hom.id K)) (hm : f.monic)\n  (hr : \u2200 a \u2208 f.roots, a \u2208 (algebra_map R K).range) : f \u2208 polynomial.lifts (algebra_map R K) :=\nbegin\n  rw [eq_prod_roots_of_monic_of_splits_id hm hs, lifts_iff_lifts_ring],\n  refine subring.multiset_prod_mem _ _ (\u03bb P hP, _),\n  obtain \u27e8b, hb, rfl\u27e9 := multiset.mem_map.1 hP,\n  exact subring.sub_mem _ (X_mem_lifts _) (C'_mem_lifts (hr _ hb))\nend\n\nsection UFD\n\nlocal attribute [instance, priority 10] principal_ideal_ring.to_unique_factorization_monoid\nlocal infix ` ~\u1d64 ` : 50 := associated\n\nopen unique_factorization_monoid associates\n\nlemma splits_of_exists_multiset {f : K[X]} {s : multiset L}\n  (hs : f.map i = C (i f.leading_coeff) * (s.map (\u03bb a : L, X - C a)).prod) :\n  splits i f :=\nif hf0 : f = 0 then hf0.symm \u25b8 splits_zero i\nelse or.inr $ \u03bb p hp hdp, begin\n  rw irreducible_iff_prime at hp,\n  rw [hs, \u2190 multiset.prod_to_list] at hdp,\n  obtain (hd|hd) := hp.2.2 _ _ hdp,\n  { refine (hp.2.1 $ is_unit_of_dvd_unit hd _).elim,\n    exact is_unit_C.2 ((leading_coeff_ne_zero.2 hf0).is_unit.map i) },\n  { obtain \u27e8q, hq, hd\u27e9 := hp.dvd_prod_iff.1 hd,\n    obtain \u27e8a, ha, rfl\u27e9 := multiset.mem_map.1 (multiset.mem_to_list.1 hq),\n    rw degree_eq_degree_of_associated ((hp.dvd_prime_iff_associated $ prime_X_sub_C a).1 hd),\n    exact degree_X_sub_C a },\nend\n\nlemma splits_of_splits_id {f : K[X]} : splits (ring_hom.id K) f \u2192 splits i f :=\nunique_factorization_monoid.induction_on_prime f (\u03bb _, splits_zero _)\n  (\u03bb _ hu _, splits_of_degree_le_one _\n    ((is_unit_iff_degree_eq_zero.1 hu).symm \u25b8 dec_trivial))\n  (\u03bb a p ha0 hp ih hfi, splits_mul _\n    (splits_of_degree_eq_one _\n      ((splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).1.def.resolve_left\n        hp.1 hp.irreducible (by rw map_id)))\n    (ih (splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).2))\n\nend UFD\n\nlemma splits_iff_exists_multiset {f : K[X]} : splits i f \u2194\n  \u2203 (s : multiset L), f.map i = C (i f.leading_coeff) * (s.map (\u03bb a : L, X - C a)).prod :=\n\u27e8\u03bb hf, \u27e8(f.map i).roots, eq_prod_roots_of_splits hf\u27e9, \u03bb \u27e8s, hs\u27e9, splits_of_exists_multiset i hs\u27e9\n\nlemma splits_comp_of_splits (j : L \u2192+* F) {f : K[X]}\n  (h : splits i f) : splits (j.comp i) f :=\nbegin\n  change i with ((ring_hom.id _).comp i) at h,\n  rw [\u2190 splits_map_iff],\n  rw [\u2190 splits_map_iff i] at h,\n  exact splits_of_splits_id _ h\nend\n\n/-- A polynomial splits if and only if it has as many roots as its degree. -/\nlemma splits_iff_card_roots {p : K[X]} :\n  splits (ring_hom.id K) p \u2194 p.roots.card = p.nat_degree :=\nbegin\n  split,\n  { intro H, rw [nat_degree_eq_card_roots H, map_id] },\n  { intro hroots,\n    rw splits_iff_exists_multiset (ring_hom.id K),\n    use p.roots,\n    simp only [ring_hom.id_apply, map_id],\n    exact (C_leading_coeff_mul_prod_multiset_X_sub_C hroots).symm },\nend\n\nlemma aeval_root_derivative_of_splits [algebra K L] {P : K[X]} (hmo : P.monic)\n  (hP : P.splits (algebra_map K L)) {r : L} (hr : r \u2208 (P.map (algebra_map K L)).roots) :\n  aeval r P.derivative = (((P.map $ algebra_map K L).roots.erase r).map (\u03bb a, r - a)).prod :=\nbegin\n  replace hmo := hmo.map (algebra_map K L),\n  replace hP := (splits_id_iff_splits (algebra_map K L)).2 hP,\n  rw [aeval_def, \u2190 eval_map, \u2190 derivative_map],\n  nth_rewrite 0 [eq_prod_roots_of_monic_of_splits_id hmo hP],\n  rw [eval_multiset_prod_X_sub_C_derivative hr]\nend\n\n/-- If `P` is a monic polynomial that splits, then `coeff P 0` equals the product of the roots. -/\nlemma prod_roots_eq_coeff_zero_of_monic_of_split {P : K[X]} (hmo : P.monic)\n  (hP : P.splits (ring_hom.id K)) : coeff P 0 = (-1) ^ P.nat_degree * P.roots.prod :=\nbegin\n  nth_rewrite 0 [eq_prod_roots_of_monic_of_splits_id hmo hP],\n  rw [coeff_zero_eq_eval_zero, eval_multiset_prod, multiset.map_map],\n  simp_rw [function.comp_app, eval_sub, eval_X, zero_sub, eval_C],\n  conv_lhs { congr, congr, funext,\n    rw [neg_eq_neg_one_mul] },\n  rw [multiset.prod_map_mul, multiset.map_const, multiset.prod_replicate, multiset.map_id',\n    splits_iff_card_roots.1 hP]\nend\n\n/-- If `P` is a monic polynomial that splits, then `P.next_coeff` equals the sum of the roots. -/\nlemma sum_roots_eq_next_coeff_of_monic_of_split {P : K[X]} (hmo : P.monic)\n  (hP : P.splits (ring_hom.id K)) : P.next_coeff = - P.roots.sum :=\nbegin\n  nth_rewrite 0 [eq_prod_roots_of_monic_of_splits_id hmo hP],\n  rw [monic.next_coeff_multiset_prod _ _ (\u03bb a ha, _)],\n  { simp_rw [next_coeff_X_sub_C, multiset.sum_map_neg'] },\n  { exact monic_X_sub_C a }\nend\n\nend splits\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/polynomial/splits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7125794775011468}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\n\nimport algebra.group_ring_action.invariant\nimport algebra.polynomial.group_ring_action\nimport field_theory.normal\nimport field_theory.separable\nimport field_theory.tower\n\n/-!\n# Fixed field under a group action.\n\nThis is the basis of the Fundamental Theorem of Galois Theory.\nGiven a (finite) group `G` that acts on a field `F`, we define `fixed_points G F`,\nthe subfield consisting of elements of `F` fixed_points by every element of `G`.\n\nThis subfield is then normal and separable, and in addition (TODO) if `G` acts faithfully on `F`\nthen `finrank (fixed_points G F) F = fintype.card G`.\n\n## Main Definitions\n\n- `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of\n`G`, where `G` is a group that acts on `F`.\n\n-/\n\nnoncomputable theory\nopen_locale classical big_operators\nopen mul_action finset finite_dimensional\n\nuniverses u v w\n\nvariables {M : Type u} [monoid M]\nvariables (G : Type u) [group G]\nvariables (F : Type v) [field F] [mul_semiring_action M F] [mul_semiring_action G F] (m : M)\n\n/-- The subfield of F fixed by the field endomorphism `m`. -/\ndef fixed_by.subfield : subfield F :=\n{ carrier := fixed_by M F m,\n  zero_mem' := smul_zero m,\n  add_mem' := \u03bb x y hx hy, (smul_add m x y).trans $ congr_arg2 _ hx hy,\n  neg_mem' := \u03bb x hx, (smul_neg m x).trans $ congr_arg _ hx,\n  one_mem' := smul_one m,\n  mul_mem' := \u03bb x y hx hy, (smul_mul' m x y).trans $ congr_arg2 _ hx hy,\n  inv_mem' := \u03bb x hx, (smul_inv'' m x).trans $ congr_arg _ hx }\n\nsection invariant_subfields\n\nvariables (M) {F}\n/-- A typeclass for subrings invariant under a `mul_semiring_action`. -/\nclass is_invariant_subfield (S : subfield F) : Prop :=\n(smul_mem : \u2200 (m : M) {x : F}, x \u2208 S \u2192 m \u2022 x \u2208 S)\n\nvariable (S : subfield F)\n\ninstance is_invariant_subfield.to_mul_semiring_action [is_invariant_subfield M S] :\n  mul_semiring_action M S :=\n{ smul := \u03bb m x, \u27e8m \u2022 x, is_invariant_subfield.smul_mem m x.2\u27e9,\n  one_smul := \u03bb s, subtype.eq $ one_smul M s,\n  mul_smul := \u03bb m\u2081 m\u2082 s, subtype.eq $ mul_smul m\u2081 m\u2082 s,\n  smul_add := \u03bb m s\u2081 s\u2082, subtype.eq $ smul_add m s\u2081 s\u2082,\n  smul_zero := \u03bb m, subtype.eq $ smul_zero m,\n  smul_one := \u03bb m, subtype.eq $ smul_one m,\n  smul_mul := \u03bb m s\u2081 s\u2082, subtype.eq $ smul_mul' m s\u2081 s\u2082 }\n\ninstance [is_invariant_subfield M S] : is_invariant_subring M (S.to_subring) :=\n{ smul_mem := is_invariant_subfield.smul_mem }\n\nend invariant_subfields\n\nnamespace fixed_points\n\nvariable (M)\n\n-- we use `subfield.copy` so that the underlying set is `fixed_points M F`\n/-- The subfield of fixed points by a monoid action. -/\ndef subfield : subfield F :=\nsubfield.copy (\u2a05 (m : M), fixed_by.subfield F m) (fixed_points M F)\n(by { ext z, simp [fixed_points, fixed_by.subfield, infi, subfield.mem_Inf] })\n\ninstance : is_invariant_subfield M (fixed_points.subfield M F) :=\n{ smul_mem := \u03bb g x hx g', by rw [hx, hx] }\n\ninstance : smul_comm_class M (fixed_points.subfield M F) F :=\n{ smul_comm := \u03bb m f f', show m \u2022 (\u2191f * f') = f * (m \u2022 f'), by rw [smul_mul', f.prop m] }\n\ninstance smul_comm_class' : smul_comm_class (fixed_points.subfield M F) M F :=\nsmul_comm_class.symm _ _ _\n\n@[simp] theorem smul (m : M) (x : fixed_points.subfield M F) : m \u2022 x = x :=\nsubtype.eq $ x.2 m\n\n-- Why is this so slow?\n@[simp] theorem smul_polynomial (m : M) (p : polynomial (fixed_points.subfield M F)) : m \u2022 p = p :=\npolynomial.induction_on p\n  (\u03bb x, by rw [polynomial.smul_C, smul])\n  (\u03bb p q ihp ihq, by rw [smul_add, ihp, ihq])\n  (\u03bb n x ih, by rw [smul_mul', polynomial.smul_C, smul, smul_pow', polynomial.smul_X])\n\ninstance : algebra (fixed_points.subfield M F) F :=\nby apply_instance\n\ntheorem coe_algebra_map :\n  algebra_map (fixed_points.subfield M F) F = subfield.subtype (fixed_points.subfield M F) :=\nrfl\n\nlemma linear_independent_smul_of_linear_independent {s : finset F} :\n  linear_independent (fixed_points.subfield G F) (\u03bb i : (s : set F), (i : F)) \u2192\n  linear_independent F (\u03bb i : (s : set F), mul_action.to_fun G F i) :=\nbegin\n  haveI : is_empty ((\u2205 : finset F) : set F) := \u27e8subtype.prop\u27e9,\n  refine finset.induction_on s (\u03bb _, linear_independent_empty_type)\n    (\u03bb a s has ih hs, _),\n  rw coe_insert at hs \u22a2,\n  rw linear_independent_insert (mt mem_coe.1 has) at hs,\n  rw linear_independent_insert' (mt mem_coe.1 has), refine \u27e8ih hs.1, \u03bb ha, _\u27e9,\n  rw finsupp.mem_span_image_iff_total at ha, rcases ha with \u27e8l, hl, hla\u27e9,\n  rw [finsupp.total_apply_of_mem_supported F hl] at hla,\n  suffices : \u2200 i \u2208 s, l i \u2208 fixed_points.subfield G F,\n  { replace hla := (sum_apply _ _ (\u03bb i, l i \u2022 to_fun G F i)).symm.trans (congr_fun hla 1),\n    simp_rw [pi.smul_apply, to_fun_apply, one_smul] at hla,\n    refine hs.2 (hla \u25b8 submodule.sum_mem _ (\u03bb c hcs, _)),\n    change (\u27e8l c, this c hcs\u27e9 : fixed_points.subfield G F) \u2022 c \u2208 _,\n    exact submodule.smul_mem _ _ (submodule.subset_span $ mem_coe.2 hcs) },\n  intros i his g,\n  refine eq_of_sub_eq_zero (linear_independent_iff'.1 (ih hs.1) s.attach (\u03bb i, g \u2022 l i - l i) _\n    \u27e8i, his\u27e9 (mem_attach _ _) : _),\n  refine (@sum_attach _ _ s _ (\u03bb i, (g \u2022 l i - l i) \u2022 mul_action.to_fun G F i)).trans _,\n  ext g', dsimp only,\n  conv_lhs { rw sum_apply, congr, skip, funext, rw [pi.smul_apply, sub_smul, smul_eq_mul] },\n  rw [sum_sub_distrib, pi.zero_apply, sub_eq_zero],\n  conv_lhs { congr, skip, funext,\n    rw [to_fun_apply, \u2190 mul_inv_cancel_left g g', mul_smul, \u2190 smul_mul', \u2190 to_fun_apply _ x] },\n  show \u2211 x in s, g \u2022 (\u03bb y, l y \u2022 mul_action.to_fun G F y) x (g\u207b\u00b9 * g') =\n    \u2211 x in s, (\u03bb y, l y \u2022 mul_action.to_fun G F y) x g',\n  rw [\u2190 smul_sum, \u2190 sum_apply _ _ (\u03bb y, l y \u2022 to_fun G F y),\n      \u2190 sum_apply _ _ (\u03bb y, l y \u2022 to_fun G F y)], dsimp only,\n  rw [hla, to_fun_apply, to_fun_apply, smul_smul, mul_inv_cancel_left]\nend\n\nsection fintype\nvariables [fintype G] (x : F)\n\n/-- `minpoly G F x` is the minimal polynomial of `(x : F)` over `fixed_points G F`. -/\ndef minpoly : polynomial (fixed_points.subfield G F) :=\n(prod_X_sub_smul G F x).to_subring (fixed_points.subfield G F).to_subring $ \u03bb c hc g,\nlet \u27e8n, hc0, hn\u27e9 := polynomial.mem_frange_iff.1 hc in hn.symm \u25b8 prod_X_sub_smul.coeff G F x g n\n\nnamespace minpoly\n\n\n\ntheorem eval\u2082 : polynomial.eval\u2082 (subring.subtype $ (fixed_points.subfield G F).to_subring) x\n  (minpoly G F x) = 0 :=\nbegin\n  rw [\u2190 prod_X_sub_smul.eval G F x, polynomial.eval\u2082_eq_eval_map],\n  simp only [minpoly, polynomial.map_to_subring],\nend\n\ntheorem eval\u2082' :\n  polynomial.eval\u2082 (subfield.subtype $ (fixed_points.subfield G F)) x (minpoly G F x) = 0 :=\neval\u2082 G F x\n\ntheorem ne_one :\n  minpoly G F x \u2260 (1 : polynomial (fixed_points.subfield G F)) :=\n\u03bb H, have _ := eval\u2082 G F x,\n(one_ne_zero : (1 : F) \u2260 0) $ by rwa [H, polynomial.eval\u2082_one] at this\n\ntheorem of_eval\u2082 (f : polynomial (fixed_points.subfield G F))\n  (hf : polynomial.eval\u2082 (subfield.subtype $ fixed_points.subfield G F) x f = 0) :\n  minpoly G F x \u2223 f :=\nbegin\n  erw [\u2190 polynomial.map_dvd_map' (subfield.subtype $ fixed_points.subfield G F),\n      minpoly, polynomial.map_to_subring _ (subfield G F).to_subring, prod_X_sub_smul],\n  refine fintype.prod_dvd_of_coprime\n    (polynomial.pairwise_coprime_X_sub_C $ mul_action.injective_of_quotient_stabilizer G x)\n    (\u03bb y, quotient_group.induction_on y $ \u03bb g, _),\n  rw [polynomial.dvd_iff_is_root, polynomial.is_root.def, mul_action.of_quotient_stabilizer_mk,\n      polynomial.eval_smul',\n      \u2190 subfield.to_subring.subtype_eq_subtype,\n      \u2190 is_invariant_subring.coe_subtype_hom' G (fixed_points.subfield G F).to_subring,\n      \u2190 mul_semiring_action_hom.coe_polynomial, \u2190 mul_semiring_action_hom.map_smul,\n      smul_polynomial, mul_semiring_action_hom.coe_polynomial,\n      is_invariant_subring.coe_subtype_hom', polynomial.eval_map,\n      subfield.to_subring.subtype_eq_subtype, hf, smul_zero]\nend\n\n/- Why is this so slow? -/\ntheorem irreducible_aux (f g : polynomial (fixed_points.subfield G F))\n  (hf : f.monic) (hg : g.monic) (hfg : f * g = minpoly G F x) :\n  f = 1 \u2228 g = 1 :=\nbegin\n  have hf2 : f \u2223 minpoly G F x,\n  { rw \u2190 hfg, exact dvd_mul_right _ _ },\n  have hg2 : g \u2223 minpoly G F x,\n  { rw \u2190 hfg, exact dvd_mul_left _ _ },\n  have := eval\u2082 G F x,\n  rw [\u2190 hfg, polynomial.eval\u2082_mul, mul_eq_zero] at this,\n  cases this,\n  { right,\n    have hf3 : f = minpoly G F x,\n    { exact polynomial.eq_of_monic_of_associated hf (monic G F x)\n        (associated_of_dvd_dvd hf2 $ @of_eval\u2082 G _ F _ _ _  x f this) },\n    rwa [\u2190 mul_one (minpoly G F x), hf3,\n        mul_right_inj' (monic G F x).ne_zero] at hfg },\n  { left,\n    have hg3 : g = minpoly G F x,\n    { exact polynomial.eq_of_monic_of_associated hg (monic G F x)\n        (associated_of_dvd_dvd hg2 $ @of_eval\u2082 G _ F _ _ _  x g this) },\n    rwa [\u2190 one_mul (minpoly G F x), hg3,\n        mul_left_inj' (monic G F x).ne_zero] at hfg }\nend\n\ntheorem irreducible : irreducible (minpoly G F x) :=\n(polynomial.irreducible_of_monic (monic G F x) (ne_one G F x)).2 (irreducible_aux G F x)\n\nend minpoly\nend fintype\n\ntheorem is_integral [finite G] (x : F) : is_integral (fixed_points.subfield G F) x :=\nby { casesI nonempty_fintype G, exact \u27e8minpoly G F x, minpoly.monic G F x, minpoly.eval\u2082 G F x\u27e9 }\n\nsection fintype\nvariables [fintype G] (x : F)\n\ntheorem minpoly_eq_minpoly :\n  minpoly G F x = _root_.minpoly (fixed_points.subfield G F) x :=\nminpoly.eq_of_irreducible_of_monic (minpoly.irreducible G F x)\n  (minpoly.eval\u2082 G F x) (minpoly.monic G F x)\n\nlemma dim_le_card : module.rank (fixed_points.subfield G F) F \u2264 fintype.card G :=\ndim_le $ \u03bb s hs, by simpa only [dim_fun', cardinal.mk_coe_finset, finset.coe_sort_coe,\n  cardinal.lift_nat_cast, cardinal.nat_cast_le]\n  using cardinal_lift_le_dim_of_linear_independent'\n    (linear_independent_smul_of_linear_independent G F hs)\n\nend fintype\n\nsection finite\nvariables [finite G]\n\ninstance normal : normal (fixed_points.subfield G F) F :=\n\u27e8\u03bb x, (is_integral G F x).is_algebraic _, \u03bb x, (polynomial.splits_id_iff_splits _).1 $\nbegin\n  casesI nonempty_fintype G,\n  rw [\u2190minpoly_eq_minpoly, minpoly, coe_algebra_map, \u2190subfield.to_subring.subtype_eq_subtype,\n    polynomial.map_to_subring _ (subfield G F).to_subring, prod_X_sub_smul],\n  exact polynomial.splits_prod _ (\u03bb _ _, polynomial.splits_X_sub_C _),\nend\u27e9\n\ninstance separable : is_separable (fixed_points.subfield G F) F :=\n\u27e8is_integral G F, \u03bb x, by\n{ casesI nonempty_fintype G,\n  -- this was a plain rw when we were using unbundled subrings\n  erw [\u2190 minpoly_eq_minpoly,\n    \u2190 polynomial.separable_map (fixed_points.subfield G F).subtype,\n    minpoly, polynomial.map_to_subring _ ((subfield G F).to_subring) ],\n  exact polynomial.separable_prod_X_sub_C_iff.2 (injective_of_quotient_stabilizer G x) }\u27e9\n\ninstance : finite_dimensional (subfield G F) F :=\nby { casesI nonempty_fintype G, exact is_noetherian.iff_fg.1 (is_noetherian.iff_dim_lt_aleph_0.2 $\n  (dim_le_card G F).trans_lt $ cardinal.nat_lt_aleph_0 _) }\n\nend finite\n\nlemma finrank_le_card [fintype G] : finrank (subfield G F) F \u2264 fintype.card G :=\nbegin\n  rw [\u2190 cardinal.nat_cast_le, finrank_eq_dim],\n  apply dim_le_card,\nend\n\nend fixed_points\n\nlemma linear_independent_to_linear_map (R : Type u) (A : Type v) (B : Type w)\n  [comm_semiring R] [ring A] [algebra R A]\n  [comm_ring B] [is_domain B] [algebra R B] :\n  linear_independent B (alg_hom.to_linear_map : (A \u2192\u2090[R] B) \u2192 (A \u2192\u2097[R] B)) :=\nhave linear_independent B (linear_map.lto_fun R A B \u2218 alg_hom.to_linear_map),\nfrom ((linear_independent_monoid_hom A B).comp\n  (coe : (A \u2192\u2090[R] B) \u2192 (A \u2192* B))\n  (\u03bb f g hfg, alg_hom.ext $ monoid_hom.ext_iff.1 hfg) : _),\nthis.of_comp _\n\nlemma cardinal_mk_alg_hom (K : Type u) (V : Type v) (W : Type w)\n  [field K] [field V] [algebra K V] [finite_dimensional K V]\n            [field W] [algebra K W] [finite_dimensional K W] :\n  cardinal.mk (V \u2192\u2090[K] W) \u2264 finrank W (V \u2192\u2097[K] W) :=\ncardinal_mk_le_finrank_of_linear_independent $ linear_independent_to_linear_map K V W\n\nnoncomputable instance alg_equiv.fintype (K : Type u) (V : Type v)\n  [field K] [field V] [algebra K V] [finite_dimensional K V] :\n  fintype (V \u2243\u2090[K] V) :=\nfintype.of_equiv (V \u2192\u2090[K] V) (alg_equiv_equiv_alg_hom K V).symm\n\nlemma finrank_alg_hom (K : Type u) (V : Type v)\n  [field K] [field V] [algebra K V] [finite_dimensional K V] :\n  fintype.card (V \u2192\u2090[K] V) \u2264 finrank V (V \u2192\u2097[K] V) :=\nfintype_card_le_finrank_of_linear_independent $ linear_independent_to_linear_map K V V\n\nnamespace fixed_points\n\ntheorem finrank_eq_card (G : Type u) (F : Type v) [group G] [field F]\n  [fintype G] [mul_semiring_action G F] [has_faithful_smul G F] :\n  finrank (fixed_points.subfield G F) F = fintype.card G :=\nle_antisymm (fixed_points.finrank_le_card G F) $\ncalc  fintype.card G\n    \u2264 fintype.card (F \u2192\u2090[fixed_points.subfield G F] F) :\n        fintype.card_le_of_injective _ (mul_semiring_action.to_alg_hom_injective _ F)\n... \u2264 finrank F (F \u2192\u2097[fixed_points.subfield G F] F) : finrank_alg_hom (fixed_points G F) F\n... = finrank (fixed_points.subfield G F) F : finrank_linear_map' _ _ _\n\n/-- `mul_semiring_action.to_alg_hom` is bijective. -/\ntheorem to_alg_hom_bijective (G : Type u) (F : Type v) [group G] [field F]\n  [finite G] [mul_semiring_action G F] [has_faithful_smul G F] :\n  function.bijective (mul_semiring_action.to_alg_hom _ _ : G \u2192 F \u2192\u2090[subfield G F] F) :=\nbegin\n  casesI nonempty_fintype G,\n  rw fintype.bijective_iff_injective_and_card,\n  split,\n  { exact mul_semiring_action.to_alg_hom_injective _ F },\n  { apply le_antisymm,\n    { exact fintype.card_le_of_injective _ (mul_semiring_action.to_alg_hom_injective _ F) },\n    { rw \u2190 finrank_eq_card G F,\n      exact has_le.le.trans_eq (finrank_alg_hom _ F) (finrank_linear_map' _ _ _) } },\nend\n\n/-- Bijection between G and algebra homomorphisms that fix the fixed points -/\ndef to_alg_hom_equiv (G : Type u) (F : Type v) [group G] [field F]\n  [fintype G] [mul_semiring_action G F] [has_faithful_smul G F] :\n    G \u2243 (F \u2192\u2090[fixed_points.subfield G F] F) :=\nequiv.of_bijective _ (to_alg_hom_bijective G F)\n\nend fixed_points\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/field_theory/fixed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699185, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.7125794703149995}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.nat.log\n! leanprover-community/mathlib commit 55d224c38461be1e8e4363247dd110137c24a4ff\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Pow\nimport Mathbin.Tactic.ByContra\n\n/-!\n# Natural number logarithms\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines two `\u2115`-valued analogs of the logarithm of `n` with base `b`:\n* `log b n`: Lower logarithm, or floor **log**. Greatest `k` such that `b^k \u2264 n`.\n* `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n \u2264 b^k`.\n\nThese are interesting because, for `1 < b`, `nat.log b` and `nat.clog b` are respectively right and\nleft adjoints of `nat.pow b`. See `pow_le_iff_le_log` and `le_pow_iff_clog_le`.\n-/\n\n\nnamespace Nat\n\n/-! ### Floor logarithm -/\n\n\n#print Nat.log /-\n/-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : \u2115`\nsuch that `b^k \u2264 n`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot]\ndef log (b : \u2115) : \u2115 \u2192 \u2115\n  | n =>\n    if h : b \u2264 n \u2227 1 < b then\n      have : n / b < n := div_lt_self ((zero_lt_one.trans h.2).trans_le h.1) h.2\n      log (n / b) + 1\n    else 0\n#align nat.log Nat.log\n-/\n\n#print Nat.log_eq_zero_iff /-\n@[simp]\ntheorem log_eq_zero_iff {b n : \u2115} : log b n = 0 \u2194 n < b \u2228 b \u2264 1 :=\n  by\n  rw [log, ite_eq_right_iff]\n  simp only [Nat.succ_ne_zero, imp_false, Decidable.not_and, not_le, not_lt]\n#align nat.log_eq_zero_iff Nat.log_eq_zero_iff\n-/\n\n#print Nat.log_of_lt /-\ntheorem log_of_lt {b n : \u2115} (hb : n < b) : log b n = 0 :=\n  log_eq_zero_iff.2 (Or.inl hb)\n#align nat.log_of_lt Nat.log_of_lt\n-/\n\n#print Nat.log_of_left_le_one /-\ntheorem log_of_left_le_one {b : \u2115} (hb : b \u2264 1) (n) : log b n = 0 :=\n  log_eq_zero_iff.2 (Or.inr hb)\n#align nat.log_of_left_le_one Nat.log_of_left_le_one\n-/\n\n#print Nat.log_pos_iff /-\n@[simp]\ntheorem log_pos_iff {b n : \u2115} : 0 < log b n \u2194 b \u2264 n \u2227 1 < b := by\n  rw [pos_iff_ne_zero, Ne.def, log_eq_zero_iff, not_or, not_lt, not_le]\n#align nat.log_pos_iff Nat.log_pos_iff\n-/\n\n#print Nat.log_pos /-\ntheorem log_pos {b n : \u2115} (hb : 1 < b) (hbn : b \u2264 n) : 0 < log b n :=\n  log_pos_iff.2 \u27e8hbn, hb\u27e9\n#align nat.log_pos Nat.log_pos\n-/\n\n#print Nat.log_of_one_lt_of_le /-\ntheorem log_of_one_lt_of_le {b n : \u2115} (h : 1 < b) (hn : b \u2264 n) : log b n = log b (n / b) + 1 :=\n  by\n  rw [log]\n  exact if_pos \u27e8hn, h\u27e9\n#align nat.log_of_one_lt_of_le Nat.log_of_one_lt_of_le\n-/\n\n#print Nat.log_zero_left /-\n@[simp]\ntheorem log_zero_left : \u2200 n, log 0 n = 0 :=\n  log_of_left_le_one zero_le_one\n#align nat.log_zero_left Nat.log_zero_left\n-/\n\n#print Nat.log_zero_right /-\n@[simp]\ntheorem log_zero_right (b : \u2115) : log b 0 = 0 :=\n  log_eq_zero_iff.2 (le_total 1 b)\n#align nat.log_zero_right Nat.log_zero_right\n-/\n\n#print Nat.log_one_left /-\n@[simp]\ntheorem log_one_left : \u2200 n, log 1 n = 0 :=\n  log_of_left_le_one le_rfl\n#align nat.log_one_left Nat.log_one_left\n-/\n\n#print Nat.log_one_right /-\n@[simp]\ntheorem log_one_right (b : \u2115) : log b 1 = 0 :=\n  log_eq_zero_iff.2 (lt_or_le _ _)\n#align nat.log_one_right Nat.log_one_right\n-/\n\n#print Nat.pow_le_iff_le_log /-\n/-- `pow b` and `log b` (almost) form a Galois connection. See also `nat.pow_le_of_le_log` and\n`nat.le_log_of_pow_le` for individual implications under weaker assumptions. -/\ntheorem pow_le_iff_le_log {b : \u2115} (hb : 1 < b) {x y : \u2115} (hy : y \u2260 0) : b ^ x \u2264 y \u2194 x \u2264 log b y :=\n  by\n  induction' y using Nat.strong_induction_on with y ih generalizing x\n  cases x\n  \u00b7 exact iff_of_true hy.bot_lt (zero_le _)\n  rw [log]; split_ifs\n  \u00b7 have b_pos : 0 < b := zero_le_one.trans_lt hb\n    rw [succ_eq_add_one, add_le_add_iff_right, \u2190\n      ih (y / b) (div_lt_self hy.bot_lt hb) (Nat.div_pos h.1 b_pos).ne', le_div_iff_mul_le b_pos,\n      pow_succ']\n  \u00b7\n    exact\n      iff_of_false (fun hby => h \u27e8(le_self_pow x.succ_ne_zero _).trans hby, hb\u27e9)\n        (not_succ_le_zero _)\n#align nat.pow_le_iff_le_log Nat.pow_le_iff_le_log\n-/\n\n#print Nat.lt_pow_iff_log_lt /-\ntheorem lt_pow_iff_log_lt {b : \u2115} (hb : 1 < b) {x y : \u2115} (hy : y \u2260 0) : y < b ^ x \u2194 log b y < x :=\n  lt_iff_lt_of_le_iff_le (pow_le_iff_le_log hb hy)\n#align nat.lt_pow_iff_log_lt Nat.lt_pow_iff_log_lt\n-/\n\n#print Nat.pow_le_of_le_log /-\ntheorem pow_le_of_le_log {b x y : \u2115} (hy : y \u2260 0) (h : x \u2264 log b y) : b ^ x \u2264 y :=\n  by\n  refine' (le_or_lt b 1).elim (fun hb => _) fun hb => (pow_le_iff_le_log hb hy).2 h\n  rw [log_of_left_le_one hb, nonpos_iff_eq_zero] at h\n  rwa [h, pow_zero, one_le_iff_ne_zero]\n#align nat.pow_le_of_le_log Nat.pow_le_of_le_log\n-/\n\n#print Nat.le_log_of_pow_le /-\ntheorem le_log_of_pow_le {b x y : \u2115} (hb : 1 < b) (h : b ^ x \u2264 y) : x \u2264 log b y :=\n  by\n  rcases ne_or_eq y 0 with (hy | rfl)\n  exacts[(pow_le_iff_le_log hb hy).1 h, (h.not_lt (pow_pos (zero_lt_one.trans hb) _)).elim]\n#align nat.le_log_of_pow_le Nat.le_log_of_pow_le\n-/\n\n#print Nat.pow_log_le_self /-\ntheorem pow_log_le_self (b : \u2115) {x : \u2115} (hx : x \u2260 0) : b ^ log b x \u2264 x :=\n  pow_le_of_le_log hx le_rfl\n#align nat.pow_log_le_self Nat.pow_log_le_self\n-/\n\n#print Nat.log_lt_of_lt_pow /-\ntheorem log_lt_of_lt_pow {b x y : \u2115} (hy : y \u2260 0) : y < b ^ x \u2192 log b y < x :=\n  lt_imp_lt_of_le_imp_le (pow_le_of_le_log hy)\n#align nat.log_lt_of_lt_pow Nat.log_lt_of_lt_pow\n-/\n\n#print Nat.lt_pow_of_log_lt /-\ntheorem lt_pow_of_log_lt {b x y : \u2115} (hb : 1 < b) : log b y < x \u2192 y < b ^ x :=\n  lt_imp_lt_of_le_imp_le (le_log_of_pow_le hb)\n#align nat.lt_pow_of_log_lt Nat.lt_pow_of_log_lt\n-/\n\n#print Nat.lt_pow_succ_log_self /-\ntheorem lt_pow_succ_log_self {b : \u2115} (hb : 1 < b) (x : \u2115) : x < b ^ (log b x).succ :=\n  lt_pow_of_log_lt hb (lt_succ_self _)\n#align nat.lt_pow_succ_log_self Nat.lt_pow_succ_log_self\n-/\n\n#print Nat.log_eq_iff /-\ntheorem log_eq_iff {b m n : \u2115} (h : m \u2260 0 \u2228 1 < b \u2227 n \u2260 0) :\n    log b n = m \u2194 b ^ m \u2264 n \u2227 n < b ^ (m + 1) :=\n  by\n  rcases em (1 < b \u2227 n \u2260 0) with (\u27e8hb, hn\u27e9 | hbn)\n  \u00b7\n    rw [le_antisymm_iff, \u2190 lt_succ_iff, \u2190 pow_le_iff_le_log, \u2190 lt_pow_iff_log_lt, and_comm] <;>\n      assumption\n  \u00b7 have hm : m \u2260 0 := h.resolve_right hbn\n    rw [not_and_or, not_lt, Ne.def, Classical.not_not] at hbn\n    rcases hbn with (hb | rfl)\n    \u00b7\n      simpa only [log_of_left_le_one hb, hm.symm, false_iff_iff, not_and, not_lt] using\n        le_trans (pow_le_pow_of_le_one' hb m.le_succ)\n    \u00b7\n      simpa only [log_zero_right, hm.symm, false_iff_iff, not_and, not_lt, le_zero_iff,\n        pow_succ] using mul_eq_zero_of_right _\n#align nat.log_eq_iff Nat.log_eq_iff\n-/\n\n#print Nat.log_eq_of_pow_le_of_lt_pow /-\ntheorem log_eq_of_pow_le_of_lt_pow {b m n : \u2115} (h\u2081 : b ^ m \u2264 n) (h\u2082 : n < b ^ (m + 1)) :\n    log b n = m := by\n  rcases eq_or_ne m 0 with (rfl | hm)\n  \u00b7 rw [pow_one] at h\u2082\n    exact log_of_lt h\u2082\n  \u00b7 exact (log_eq_iff (Or.inl hm)).2 \u27e8h\u2081, h\u2082\u27e9\n#align nat.log_eq_of_pow_le_of_lt_pow Nat.log_eq_of_pow_le_of_lt_pow\n-/\n\n#print Nat.log_pow /-\ntheorem log_pow {b : \u2115} (hb : 1 < b) (x : \u2115) : log b (b ^ x) = x :=\n  log_eq_of_pow_le_of_lt_pow le_rfl (pow_lt_pow hb x.lt_succ_self)\n#align nat.log_pow Nat.log_pow\n-/\n\n#print Nat.log_eq_one_iff' /-\ntheorem log_eq_one_iff' {b n : \u2115} : log b n = 1 \u2194 b \u2264 n \u2227 n < b * b := by\n  rw [log_eq_iff (Or.inl one_ne_zero), pow_add, pow_one]\n#align nat.log_eq_one_iff' Nat.log_eq_one_iff'\n-/\n\n#print Nat.log_eq_one_iff /-\ntheorem log_eq_one_iff {b n : \u2115} : log b n = 1 \u2194 n < b * b \u2227 1 < b \u2227 b \u2264 n :=\n  log_eq_one_iff'.trans\n    \u27e8fun h => \u27e8h.2, lt_mul_self_iff.1 (h.1.trans_lt h.2), h.1\u27e9, fun h => \u27e8h.2.2, h.1\u27e9\u27e9\n#align nat.log_eq_one_iff Nat.log_eq_one_iff\n-/\n\n#print Nat.log_mul_base /-\ntheorem log_mul_base {b n : \u2115} (hb : 1 < b) (hn : n \u2260 0) : log b (n * b) = log b n + 1 :=\n  by\n  apply log_eq_of_pow_le_of_lt_pow <;> rw [pow_succ']\n  exacts[mul_le_mul_right' (pow_log_le_self _ hn) _,\n    (mul_lt_mul_right (zero_lt_one.trans hb)).2 (lt_pow_succ_log_self hb _)]\n#align nat.log_mul_base Nat.log_mul_base\n-/\n\n#print Nat.pow_log_le_add_one /-\ntheorem pow_log_le_add_one (b : \u2115) : \u2200 x, b ^ log b x \u2264 x + 1\n  | 0 => by rw [log_zero_right, pow_zero]\n  | x + 1 => (pow_log_le_self b x.succ_ne_zero).trans (x + 1).le_succ\n#align nat.pow_log_le_add_one Nat.pow_log_le_add_one\n-/\n\n#print Nat.log_monotone /-\ntheorem log_monotone {b : \u2115} : Monotone (log b) :=\n  by\n  refine' monotone_nat_of_le_succ fun n => _\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [log_of_left_le_one hb]\n    exact zero_le _\n  \u00b7 exact le_log_of_pow_le hb (pow_log_le_add_one _ _)\n#align nat.log_monotone Nat.log_monotone\n-/\n\n#print Nat.log_mono_right /-\n@[mono]\ntheorem log_mono_right {b n m : \u2115} (h : n \u2264 m) : log b n \u2264 log b m :=\n  log_monotone h\n#align nat.log_mono_right Nat.log_mono_right\n-/\n\n#print Nat.log_anti_left /-\n@[mono]\ntheorem log_anti_left {b c n : \u2115} (hc : 1 < c) (hb : c \u2264 b) : log b n \u2264 log c n :=\n  by\n  rcases eq_or_ne n 0 with (rfl | hn); \u00b7 rw [log_zero_right, log_zero_right]\n  apply le_log_of_pow_le hc\n  calc\n    c ^ log b n \u2264 b ^ log b n := pow_le_pow_of_le_left' hb _\n    _ \u2264 n := pow_log_le_self _ hn\n    \n#align nat.log_anti_left Nat.log_anti_left\n-/\n\n#print Nat.log_antitone_left /-\ntheorem log_antitone_left {n : \u2115} : AntitoneOn (fun b => log b n) (Set.Ioi 1) := fun _ hc _ _ hb =>\n  log_anti_left (Set.mem_Iio.1 hc) hb\n#align nat.log_antitone_left Nat.log_antitone_left\n-/\n\n#print Nat.log_div_base /-\n@[simp]\ntheorem log_div_base (b n : \u2115) : log b (n / b) = log b n - 1 :=\n  by\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [log_of_left_le_one hb, log_of_left_le_one hb, Nat.zero_sub]\n  cases' lt_or_le n b with h h\n  \u00b7 rw [div_eq_of_lt h, log_of_lt h, log_zero_right]\n  rw [log_of_one_lt_of_le hb h, add_tsub_cancel_right]\n#align nat.log_div_base Nat.log_div_base\n-/\n\n#print Nat.log_div_mul_self /-\n@[simp]\ntheorem log_div_mul_self (b n : \u2115) : log b (n / b * b) = log b n :=\n  by\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [log_of_left_le_one hb, log_of_left_le_one hb]\n  cases' lt_or_le n b with h h\n  \u00b7 rw [div_eq_of_lt h, MulZeroClass.zero_mul, log_zero_right, log_of_lt h]\n  rw [log_mul_base hb (Nat.div_pos h (zero_le_one.trans_lt hb)).ne', log_div_base,\n    tsub_add_cancel_of_le (succ_le_iff.2 <| log_pos hb h)]\n#align nat.log_div_mul_self Nat.log_div_mul_self\n-/\n\nprivate theorem add_pred_div_lt {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) : (n + b - 1) / b < n :=\n  by\n  rw [div_lt_iff_lt_mul (zero_lt_one.trans hb), \u2190 succ_le_iff, \u2190 pred_eq_sub_one,\n    succ_pred_eq_of_pos (add_pos (zero_lt_one.trans hn) (zero_lt_one.trans hb))]\n  exact add_le_mul hn hb\n#align nat.add_pred_div_lt nat.add_pred_div_lt\n\n/-! ### Ceil logarithm -/\n\n\n#print Nat.clog /-\n/-- `clog b n`, is the upper logarithm of natural number `n` in base `b`. It returns the smallest\n`k : \u2115` such that `n \u2264 b^k`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot]\ndef clog (b : \u2115) : \u2115 \u2192 \u2115\n  | n =>\n    if h : 1 < b \u2227 1 < n then\n      have : (n + b - 1) / b < n := add_pred_div_lt h.1 h.2\n      clog ((n + b - 1) / b) + 1\n    else 0\n#align nat.clog Nat.clog\n-/\n\n#print Nat.clog_of_left_le_one /-\ntheorem clog_of_left_le_one {b : \u2115} (hb : b \u2264 1) (n : \u2115) : clog b n = 0 := by\n  rw [clog, if_neg fun h : 1 < b \u2227 1 < n => h.1.not_le hb]\n#align nat.clog_of_left_le_one Nat.clog_of_left_le_one\n-/\n\n#print Nat.clog_of_right_le_one /-\ntheorem clog_of_right_le_one {n : \u2115} (hn : n \u2264 1) (b : \u2115) : clog b n = 0 := by\n  rw [clog, if_neg fun h : 1 < b \u2227 1 < n => h.2.not_le hn]\n#align nat.clog_of_right_le_one Nat.clog_of_right_le_one\n-/\n\n#print Nat.clog_zero_left /-\n@[simp]\ntheorem clog_zero_left (n : \u2115) : clog 0 n = 0 :=\n  clog_of_left_le_one zero_le_one _\n#align nat.clog_zero_left Nat.clog_zero_left\n-/\n\n#print Nat.clog_zero_right /-\n@[simp]\ntheorem clog_zero_right (b : \u2115) : clog b 0 = 0 :=\n  clog_of_right_le_one zero_le_one _\n#align nat.clog_zero_right Nat.clog_zero_right\n-/\n\n#print Nat.clog_one_left /-\n@[simp]\ntheorem clog_one_left (n : \u2115) : clog 1 n = 0 :=\n  clog_of_left_le_one le_rfl _\n#align nat.clog_one_left Nat.clog_one_left\n-/\n\n#print Nat.clog_one_right /-\n@[simp]\ntheorem clog_one_right (b : \u2115) : clog b 1 = 0 :=\n  clog_of_right_le_one le_rfl _\n#align nat.clog_one_right Nat.clog_one_right\n-/\n\n#print Nat.clog_of_two_le /-\ntheorem clog_of_two_le {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) :\n    clog b n = clog b ((n + b - 1) / b) + 1 := by rw [clog, if_pos (\u27e8hb, hn\u27e9 : 1 < b \u2227 1 < n)]\n#align nat.clog_of_two_le Nat.clog_of_two_le\n-/\n\n#print Nat.clog_pos /-\ntheorem clog_pos {b n : \u2115} (hb : 1 < b) (hn : 2 \u2264 n) : 0 < clog b n :=\n  by\n  rw [clog_of_two_le hb hn]\n  exact zero_lt_succ _\n#align nat.clog_pos Nat.clog_pos\n-/\n\n#print Nat.clog_eq_one /-\ntheorem clog_eq_one {b n : \u2115} (hn : 2 \u2264 n) (h : n \u2264 b) : clog b n = 1 :=\n  by\n  rw [clog_of_two_le (hn.trans h) hn, clog_of_right_le_one]\n  have n_pos : 0 < n := zero_lt_two.trans_le hn\n  rw [\u2190 lt_succ_iff, Nat.div_lt_iff_lt_mul (n_pos.trans_le h), \u2190 succ_le_iff, \u2190 pred_eq_sub_one,\n    succ_pred_eq_of_pos (add_pos n_pos (n_pos.trans_le h)), succ_mul, one_mul]\n  exact add_le_add_right h _\n#align nat.clog_eq_one Nat.clog_eq_one\n-/\n\n#print Nat.le_pow_iff_clog_le /-\n/-- `clog b` and `pow b` form a Galois connection. -/\ntheorem le_pow_iff_clog_le {b : \u2115} (hb : 1 < b) {x y : \u2115} : x \u2264 b ^ y \u2194 clog b x \u2264 y :=\n  by\n  induction' x using Nat.strong_induction_on with x ih generalizing y\n  cases y\n  \u00b7 rw [pow_zero]\n    refine' \u27e8fun h => (clog_of_right_le_one h b).le, _\u27e9\n    simp_rw [\u2190 not_lt]\n    contrapose!\n    exact clog_pos hb\n  have b_pos : 0 < b := zero_lt_two.trans_le hb\n  rw [clog]; split_ifs\n  \u00b7\n    rw [succ_eq_add_one, add_le_add_iff_right, \u2190 ih ((x + b - 1) / b) (add_pred_div_lt hb h.2),\n      Nat.div_le_iff_le_mul_add_pred b_pos, \u2190 pow_succ,\n      add_tsub_assoc_of_le (Nat.succ_le_of_lt b_pos), add_le_add_iff_right]\n  \u00b7\n    exact\n      iff_of_true ((not_lt.1 (not_and.1 h hb)).trans <| succ_le_of_lt <| pow_pos b_pos _)\n        (zero_le _)\n#align nat.le_pow_iff_clog_le Nat.le_pow_iff_clog_le\n-/\n\n#print Nat.pow_lt_iff_lt_clog /-\ntheorem pow_lt_iff_lt_clog {b : \u2115} (hb : 1 < b) {x y : \u2115} : b ^ y < x \u2194 y < clog b x :=\n  lt_iff_lt_of_le_iff_le (le_pow_iff_clog_le hb)\n#align nat.pow_lt_iff_lt_clog Nat.pow_lt_iff_lt_clog\n-/\n\n#print Nat.clog_pow /-\ntheorem clog_pow (b x : \u2115) (hb : 1 < b) : clog b (b ^ x) = x :=\n  eq_of_forall_ge_iff fun z => by\n    rw [\u2190 le_pow_iff_clog_le hb]\n    exact (pow_right_strict_mono hb).le_iff_le\n#align nat.clog_pow Nat.clog_pow\n-/\n\n#print Nat.pow_pred_clog_lt_self /-\ntheorem pow_pred_clog_lt_self {b : \u2115} (hb : 1 < b) {x : \u2115} (hx : 1 < x) : b ^ (clog b x).pred < x :=\n  by\n  rw [\u2190 not_le, le_pow_iff_clog_le hb, not_le]\n  exact pred_lt (clog_pos hb hx).ne'\n#align nat.pow_pred_clog_lt_self Nat.pow_pred_clog_lt_self\n-/\n\n#print Nat.le_pow_clog /-\ntheorem le_pow_clog {b : \u2115} (hb : 1 < b) (x : \u2115) : x \u2264 b ^ clog b x :=\n  (le_pow_iff_clog_le hb).2 le_rfl\n#align nat.le_pow_clog Nat.le_pow_clog\n-/\n\n#print Nat.clog_mono_right /-\n@[mono]\ntheorem clog_mono_right (b : \u2115) {n m : \u2115} (h : n \u2264 m) : clog b n \u2264 clog b m :=\n  by\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rw [clog_of_left_le_one hb]\n    exact zero_le _\n  \u00b7 rw [\u2190 le_pow_iff_clog_le hb]\n    exact h.trans (le_pow_clog hb _)\n#align nat.clog_mono_right Nat.clog_mono_right\n-/\n\n#print Nat.clog_anti_left /-\n@[mono]\ntheorem clog_anti_left {b c n : \u2115} (hc : 1 < c) (hb : c \u2264 b) : clog b n \u2264 clog c n :=\n  by\n  rw [\u2190 le_pow_iff_clog_le (lt_of_lt_of_le hc hb)]\n  calc\n    n \u2264 c ^ clog c n := le_pow_clog hc _\n    _ \u2264 b ^ clog c n := pow_le_pow_of_le_left (zero_lt_one.trans hc).le hb _\n    \n#align nat.clog_anti_left Nat.clog_anti_left\n-/\n\n#print Nat.clog_monotone /-\ntheorem clog_monotone (b : \u2115) : Monotone (clog b) := fun x y => clog_mono_right _\n#align nat.clog_monotone Nat.clog_monotone\n-/\n\n#print Nat.clog_antitone_left /-\ntheorem clog_antitone_left {n : \u2115} : AntitoneOn (fun b : \u2115 => clog b n) (Set.Ioi 1) :=\n  fun _ hc _ _ hb => clog_anti_left (Set.mem_Iio.1 hc) hb\n#align nat.clog_antitone_left Nat.clog_antitone_left\n-/\n\n#print Nat.log_le_clog /-\ntheorem log_le_clog (b n : \u2115) : log b n \u2264 clog b n :=\n  by\n  obtain hb | hb := le_or_lt b 1\n  \u00b7 rw [log_of_left_le_one hb]\n    exact zero_le _\n  cases n\n  \u00b7 rw [log_zero_right]\n    exact zero_le _\n  exact\n    (pow_right_strict_mono hb).le_iff_le.1\n      ((pow_log_le_self b n.succ_ne_zero).trans <| le_pow_clog hb _)\n#align nat.log_le_clog Nat.log_le_clog\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7125761503250199}}
{"text": "-- Propiedad_semidistributiva_de_la_interseccion_sobre_la_union_2.lean\n-- 2\u00aa propiedad semidistributiva de la intersecci\u00f3n sobre la uni\u00f3n\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 20 de mayo de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t u : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u):=\nbegin\n  intros x hx,\n  cases hx with xst xsu,\n  { split,\n    { exact xst.1 },\n    { left,\n      exact xst.2 }},\n  { split,\n    { exact xsu.1 },\n    { right,\n      exact xsu.2 }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u):=\nbegin\n  rintros x (\u27e8xs, xt\u27e9 | \u27e8xs, xu\u27e9),\n  { use xs,\n    left,\n    exact xt },\n  { use xs,\n    right,\n    exact xu },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u):=\nby rw inter_distrib_left s t u\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u):=\nbegin\n  intros x hx,\n  finish\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Propiedad_semidistributiva_de_la_interseccion_sobre_la_union_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7125761490753679}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n\n! This file was ported from Lean 3 source module analysis.special_functions.log.basic\n! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.SpecialFunctions.Exp\nimport Mathbin.Data.Nat.Factorization.Basic\n\n/-!\n# Real logarithm\n\nIn this file we define `real.log` to be the logarithm of a real number. As usual, we extend it from\nits domain `(0, +\u221e)` to a globally defined function. We choose to do it so that `log 0 = 0` and\n`log (-x) = log x`.\n\nWe prove some basic properties of this function and show that it is continuous.\n\n## Tags\n\nlogarithm, continuity\n-/\n\n\nopen Set Filter Function\n\nopen Topology\n\nnoncomputable section\n\nnamespace Real\n\nvariable {x y : \u211d}\n\n/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,\nto `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to\n`(-\u221e, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and\nthe derivative of `log` is `1/x` away from `0`. -/\n@[pp_nodot]\nnoncomputable def log (x : \u211d) : \u211d :=\n  if hx : x = 0 then 0 else expOrderIso.symm \u27e8|x|, abs_pos.2 hx\u27e9\n#align real.log Real.log\n\ntheorem log_of_ne_zero (hx : x \u2260 0) : log x = expOrderIso.symm \u27e8|x|, abs_pos.2 hx\u27e9 :=\n  dif_neg hx\n#align real.log_of_ne_zero Real.log_of_ne_zero\n\ntheorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm \u27e8x, hx\u27e9 :=\n  by\n  rw [log_of_ne_zero hx.ne']\n  congr\n  exact abs_of_pos hx\n#align real.log_of_pos Real.log_of_pos\n\ntheorem exp_log_eq_abs (hx : x \u2260 0) : exp (log x) = |x| := by\n  rw [log_of_ne_zero hx, \u2190 coe_exp_order_iso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk]\n#align real.exp_log_eq_abs Real.exp_log_eq_abs\n\ntheorem exp_log (hx : 0 < x) : exp (log x) = x :=\n  by\n  rw [exp_log_eq_abs hx.ne']\n  exact abs_of_pos hx\n#align real.exp_log Real.exp_log\n\ntheorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x :=\n  by\n  rw [exp_log_eq_abs (ne_of_lt hx)]\n  exact abs_of_neg hx\n#align real.exp_log_of_neg Real.exp_log_of_neg\n\ntheorem le_exp_log (x : \u211d) : x \u2264 exp (log x) :=\n  by\n  by_cases h_zero : x = 0\n  \u00b7 rw [h_zero, log, dif_pos rfl, exp_zero]\n    exact zero_le_one\n  \u00b7 rw [exp_log_eq_abs h_zero]\n    exact le_abs_self _\n#align real.le_exp_log Real.le_exp_log\n\n@[simp]\ntheorem log_exp (x : \u211d) : log (exp x) = x :=\n  exp_injective <| exp_log (exp_pos x)\n#align real.log_exp Real.log_exp\n\ntheorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => \u27e8exp x, exp_pos x, log_exp x\u27e9\n#align real.surj_on_log Real.surjOn_log\n\ntheorem log_surjective : Surjective log := fun x => \u27e8exp x, log_exp x\u27e9\n#align real.log_surjective Real.log_surjective\n\n@[simp]\ntheorem range_log : range log = univ :=\n  log_surjective.range_eq\n#align real.range_log Real.range_log\n\n@[simp]\ntheorem log_zero : log 0 = 0 :=\n  dif_pos rfl\n#align real.log_zero Real.log_zero\n\n@[simp]\ntheorem log_one : log 1 = 0 :=\n  exp_injective <| by rw [exp_log zero_lt_one, exp_zero]\n#align real.log_one Real.log_one\n\n@[simp]\ntheorem log_abs (x : \u211d) : log (|x|) = log x :=\n  by\n  by_cases h : x = 0\n  \u00b7 simp [h]\n  \u00b7 rw [\u2190 exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs]\n#align real.log_abs Real.log_abs\n\n@[simp]\ntheorem log_neg_eq_log (x : \u211d) : log (-x) = log x := by rw [\u2190 log_abs x, \u2190 log_abs (-x), abs_neg]\n#align real.log_neg_eq_log Real.log_neg_eq_log\n\ntheorem sinh_log {x : \u211d} (hx : 0 < x) : sinh (log x) = (x - x\u207b\u00b9) / 2 := by\n  rw [sinh_eq, exp_neg, exp_log hx]\n#align real.sinh_log Real.sinh_log\n\ntheorem cosh_log {x : \u211d} (hx : 0 < x) : cosh (log x) = (x + x\u207b\u00b9) / 2 := by\n  rw [cosh_eq, exp_neg, exp_log hx]\n#align real.cosh_log Real.cosh_log\n\ntheorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ =>\n  \u27e8-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]\u27e9\n#align real.surj_on_log' Real.surjOn_log'\n\ntheorem log_mul (hx : x \u2260 0) (hy : y \u2260 0) : log (x * y) = log x + log y :=\n  exp_injective <| by\n    rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]\n#align real.log_mul Real.log_mul\n\ntheorem log_div (hx : x \u2260 0) (hy : y \u2260 0) : log (x / y) = log x - log y :=\n  exp_injective <| by\n    rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]\n#align real.log_div Real.log_div\n\n@[simp]\ntheorem log_inv (x : \u211d) : log x\u207b\u00b9 = -log x :=\n  by\n  by_cases hx : x = 0; \u00b7 simp [hx]\n  rw [\u2190 exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]\n#align real.log_inv Real.log_inv\n\ntheorem log_le_log (h : 0 < x) (h\u2081 : 0 < y) : log x \u2264 log y \u2194 x \u2264 y := by\n  rw [\u2190 exp_le_exp, exp_log h, exp_log h\u2081]\n#align real.log_le_log Real.log_le_log\n\ntheorem log_lt_log (hx : 0 < x) : x < y \u2192 log x < log y :=\n  by\n  intro h\n  rwa [\u2190 exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)]\n#align real.log_lt_log Real.log_lt_log\n\ntheorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y \u2194 x < y := by\n  rw [\u2190 exp_lt_exp, exp_log hx, exp_log hy]\n#align real.log_lt_log_iff Real.log_lt_log_iff\n\ntheorem log_le_iff_le_exp (hx : 0 < x) : log x \u2264 y \u2194 x \u2264 exp y := by rw [\u2190 exp_le_exp, exp_log hx]\n#align real.log_le_iff_le_exp Real.log_le_iff_le_exp\n\ntheorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y \u2194 x < exp y := by rw [\u2190 exp_lt_exp, exp_log hx]\n#align real.log_lt_iff_lt_exp Real.log_lt_iff_lt_exp\n\ntheorem le_log_iff_exp_le (hy : 0 < y) : x \u2264 log y \u2194 exp x \u2264 y := by rw [\u2190 exp_le_exp, exp_log hy]\n#align real.le_log_iff_exp_le Real.le_log_iff_exp_le\n\ntheorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y \u2194 exp x < y := by rw [\u2190 exp_lt_exp, exp_log hy]\n#align real.lt_log_iff_exp_lt Real.lt_log_iff_exp_lt\n\ntheorem log_pos_iff (hx : 0 < x) : 0 < log x \u2194 1 < x :=\n  by\n  rw [\u2190 log_one]\n  exact log_lt_log_iff zero_lt_one hx\n#align real.log_pos_iff Real.log_pos_iff\n\ntheorem log_pos (hx : 1 < x) : 0 < log x :=\n  (log_pos_iff (lt_trans zero_lt_one hx)).2 hx\n#align real.log_pos Real.log_pos\n\ntheorem log_neg_iff (h : 0 < x) : log x < 0 \u2194 x < 1 :=\n  by\n  rw [\u2190 log_one]\n  exact log_lt_log_iff h zero_lt_one\n#align real.log_neg_iff Real.log_neg_iff\n\ntheorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 :=\n  (log_neg_iff h0).2 h1\n#align real.log_neg Real.log_neg\n\ntheorem log_nonneg_iff (hx : 0 < x) : 0 \u2264 log x \u2194 1 \u2264 x := by rw [\u2190 not_lt, log_neg_iff hx, not_lt]\n#align real.log_nonneg_iff Real.log_nonneg_iff\n\ntheorem log_nonneg (hx : 1 \u2264 x) : 0 \u2264 log x :=\n  (log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx\n#align real.log_nonneg Real.log_nonneg\n\ntheorem log_nonpos_iff (hx : 0 < x) : log x \u2264 0 \u2194 x \u2264 1 := by rw [\u2190 not_lt, log_pos_iff hx, not_lt]\n#align real.log_nonpos_iff Real.log_nonpos_iff\n\ntheorem log_nonpos_iff' (hx : 0 \u2264 x) : log x \u2264 0 \u2194 x \u2264 1 :=\n  by\n  rcases hx.eq_or_lt with (rfl | hx)\n  \u00b7 simp [le_refl, zero_le_one]\n  exact log_nonpos_iff hx\n#align real.log_nonpos_iff' Real.log_nonpos_iff'\n\ntheorem log_nonpos (hx : 0 \u2264 x) (h'x : x \u2264 1) : log x \u2264 0 :=\n  (log_nonpos_iff' hx).2 h'x\n#align real.log_nonpos Real.log_nonpos\n\ntheorem strictMonoOn_log : StrictMonoOn log (Set.Ioi 0) := fun x hx y hy hxy => log_lt_log hx hxy\n#align real.strict_mono_on_log Real.strictMonoOn_log\n\ntheorem strictAntiOn_log : StrictAntiOn log (Set.Iio 0) :=\n  by\n  rintro x (hx : x < 0) y (hy : y < 0) hxy\n  rw [\u2190 log_abs y, \u2190 log_abs x]\n  refine' log_lt_log (abs_pos.2 hy.ne) _\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]\n#align real.strict_anti_on_log Real.strictAntiOn_log\n\ntheorem log_injOn_pos : Set.InjOn log (Set.Ioi 0) :=\n  strictMonoOn_log.InjOn\n#align real.log_inj_on_pos Real.log_injOn_pos\n\ntheorem eq_one_of_pos_of_log_eq_zero {x : \u211d} (h\u2081 : 0 < x) (h\u2082 : log x = 0) : x = 1 :=\n  log_injOn_pos (Set.mem_Ioi.2 h\u2081) (Set.mem_Ioi.2 zero_lt_one) (h\u2082.trans Real.log_one.symm)\n#align real.eq_one_of_pos_of_log_eq_zero Real.eq_one_of_pos_of_log_eq_zero\n\ntheorem log_ne_zero_of_pos_of_ne_one {x : \u211d} (hx_pos : 0 < x) (hx : x \u2260 1) : log x \u2260 0 :=\n  mt (eq_one_of_pos_of_log_eq_zero hx_pos) hx\n#align real.log_ne_zero_of_pos_of_ne_one Real.log_ne_zero_of_pos_of_ne_one\n\n@[simp]\ntheorem log_eq_zero {x : \u211d} : log x = 0 \u2194 x = 0 \u2228 x = 1 \u2228 x = -1 :=\n  by\n  constructor\n  \u00b7 intro h\n    rcases lt_trichotomy x 0 with (x_lt_zero | rfl | x_gt_zero)\n    \u00b7 refine' Or.inr (Or.inr (neg_eq_iff_eq_neg.mp _))\n      rw [\u2190 log_neg_eq_log x] at h\n      exact eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h\n    \u00b7 exact Or.inl rfl\n    \u00b7 exact Or.inr (Or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h))\n  \u00b7 rintro (rfl | rfl | rfl) <;> simp only [log_one, log_zero, log_neg_eq_log]\n#align real.log_eq_zero Real.log_eq_zero\n\n@[simp]\ntheorem log_pow (x : \u211d) (n : \u2115) : log (x ^ n) = n * log x :=\n  by\n  induction' n with n ih\n  \u00b7 simp\n  rcases eq_or_ne x 0 with (rfl | hx)\n  \u00b7 simp\n  rw [pow_succ', log_mul (pow_ne_zero _ hx) hx, ih, Nat.cast_succ, add_mul, one_mul]\n#align real.log_pow Real.log_pow\n\n@[simp]\ntheorem log_zpow (x : \u211d) (n : \u2124) : log (x ^ n) = n * log x :=\n  by\n  induction n\n  \u00b7 rw [Int.ofNat_eq_coe, zpow_ofNat, log_pow, Int.cast_ofNat]\n  rw [zpow_negSucc, log_inv, log_pow, Int.cast_negSucc, Nat.cast_add_one, neg_mul_eq_neg_mul]\n#align real.log_zpow Real.log_zpow\n\ntheorem log_sqrt {x : \u211d} (hx : 0 \u2264 x) : log (sqrt x) = log x / 2 :=\n  by\n  rw [eq_div_iff, mul_comm, \u2190 Nat.cast_two, \u2190 log_pow, sq_sqrt hx]\n  exact two_ne_zero\n#align real.log_sqrt Real.log_sqrt\n\ntheorem log_le_sub_one_of_pos {x : \u211d} (hx : 0 < x) : log x \u2264 x - 1 :=\n  by\n  rw [le_sub_iff_add_le]\n  convert add_one_le_exp (log x)\n  rw [exp_log hx]\n#align real.log_le_sub_one_of_pos Real.log_le_sub_one_of_pos\n\n/-- Bound for `|log x * x|` in the interval `(0, 1]`. -/\ntheorem abs_log_mul_self_lt (x : \u211d) (h1 : 0 < x) (h2 : x \u2264 1) : |log x * x| < 1 :=\n  by\n  have : 0 < 1 / x := by simpa only [one_div, inv_pos] using h1\n  replace := log_le_sub_one_of_pos this\n  replace : log (1 / x) < 1 / x := by linarith\n  rw [log_div one_ne_zero h1.ne', log_one, zero_sub, lt_div_iff h1] at this\n  have aux : 0 \u2264 -log x * x := by\n    refine' mul_nonneg _ h1.le\n    rw [\u2190 log_inv]\n    apply log_nonneg\n    rw [\u2190 le_inv h1 zero_lt_one, inv_one]\n    exact h2\n  rw [\u2190 abs_of_nonneg aux, neg_mul, abs_neg] at this\n  exact this\n#align real.abs_log_mul_self_lt Real.abs_log_mul_self_lt\n\n/-- The real logarithm function tends to `+\u221e` at `+\u221e`. -/\ntheorem tendsto_log_atTop : Tendsto log atTop atTop :=\n  tendsto_comp_exp_atTop.1 <| by simpa only [log_exp] using tendsto_id\n#align real.tendsto_log_at_top Real.tendsto_log_atTop\n\ntheorem tendsto_log_nhdsWithin_zero : Tendsto log (\ud835\udcdd[\u2260] 0) atBot :=\n  by\n  rw [\u2190 show _ = log from funext log_abs]\n  refine' tendsto.comp _ tendsto_abs_nhdsWithin_zero\n  simpa [\u2190 tendsto_comp_exp_at_bot] using tendsto_id\n#align real.tendsto_log_nhds_within_zero Real.tendsto_log_nhdsWithin_zero\n\ntheorem continuousOn_log : ContinuousOn log ({0}\u1d9c) :=\n  by\n  rw [continuousOn_iff_continuous_restrict, restrict]\n  conv in log _ => rw [log_of_ne_zero (show (x : \u211d) \u2260 0 from x.2)]\n  exact exp_order_iso.symm.continuous.comp (continuous_subtype_coe.norm.subtype_mk _)\n#align real.continuous_on_log Real.continuousOn_log\n\n@[continuity]\ntheorem continuous_log : Continuous fun x : { x : \u211d // x \u2260 0 } => log x :=\n  continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun x hx => hx\n#align real.continuous_log Real.continuous_log\n\n@[continuity]\ntheorem continuous_log' : Continuous fun x : { x : \u211d // 0 < x } => log x :=\n  continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun x hx => ne_of_gt hx\n#align real.continuous_log' Real.continuous_log'\n\ntheorem continuousAt_log (hx : x \u2260 0) : ContinuousAt log x :=\n  (continuousOn_log x hx).ContinuousAt <| IsOpen.mem_nhds isOpen_compl_singleton hx\n#align real.continuous_at_log Real.continuousAt_log\n\n@[simp]\ntheorem continuousAt_log_iff : ContinuousAt log x \u2194 x \u2260 0 :=\n  by\n  refine' \u27e8_, continuous_at_log\u27e9\n  rintro h rfl\n  exact\n    not_tendsto_nhds_of_tendsto_atBot tendsto_log_nhds_within_zero _\n      (h.tendsto.mono_left inf_le_left)\n#align real.continuous_at_log_iff Real.continuousAt_log_iff\n\nopen BigOperators\n\ntheorem log_prod {\u03b1 : Type _} (s : Finset \u03b1) (f : \u03b1 \u2192 \u211d) (hf : \u2200 x \u2208 s, f x \u2260 0) :\n    log (\u220f i in s, f i) = \u2211 i in s, log (f i) :=\n  by\n  induction' s using Finset.cons_induction_on with a s ha ih\n  \u00b7 simp\n  \u00b7 rw [Finset.forall_mem_cons] at hf\n    simp [ih hf.2, log_mul hf.1 (Finset.prod_ne_zero_iff.2 hf.2)]\n#align real.log_prod Real.log_prod\n\ntheorem log_nat_eq_sum_factorization (n : \u2115) : log n = n.factorization.Sum fun p t => t * log p :=\n  by\n  rcases eq_or_ne n 0 with (rfl | hn)\n  \u00b7 simp\n  nth_rw 1 [\u2190 Nat.factorization_prod_pow_eq_self hn]\n  rw [Finsupp.prod, Nat.cast_prod, log_prod _ _ fun p hp => _, Finsupp.sum]\n  \u00b7 simp_rw [Nat.cast_pow, log_pow]\n  \u00b7 norm_cast\n    exact pow_ne_zero _ (Nat.prime_of_mem_factorization hp).NeZero\n#align real.log_nat_eq_sum_factorization Real.log_nat_eq_sum_factorization\n\ntheorem tendsto_pow_log_div_mul_add_atTop (a b : \u211d) (n : \u2115) (ha : a \u2260 0) :\n    Tendsto (fun x => log x ^ n / (a * x + b)) atTop (\ud835\udcdd 0) :=\n  ((tendsto_div_pow_mul_exp_add_atTop a b n ha.symm).comp tendsto_log_atTop).congr'\n    (by filter_upwards [eventually_gt_at_top (0 : \u211d)]with x hx using by simp [exp_log hx])\n#align real.tendsto_pow_log_div_mul_add_at_top Real.tendsto_pow_log_div_mul_add_atTop\n\ntheorem isOCat_pow_log_id_atTop {n : \u2115} : (fun x => log x ^ n) =o[atTop] id :=\n  by\n  rw [Asymptotics.isOCat_iff_tendsto']\n  \u00b7 simpa using tendsto_pow_log_div_mul_add_at_top 1 0 n one_ne_zero\n  filter_upwards [eventually_ne_at_top (0 : \u211d)]with x h\u2081 h\u2082 using(h\u2081 h\u2082).elim\n#align real.is_o_pow_log_id_at_top Real.isOCat_pow_log_id_atTop\n\ntheorem isOCat_log_id_atTop : log =o[atTop] id :=\n  isOCat_pow_log_id_atTop.congr_left fun x => pow_one _\n#align real.is_o_log_id_at_top Real.isOCat_log_id_atTop\n\nend Real\n\nsection Continuity\n\nopen Real\n\nvariable {\u03b1 : Type _}\n\ntheorem Filter.Tendsto.log {f : \u03b1 \u2192 \u211d} {l : Filter \u03b1} {x : \u211d} (h : Tendsto f l (\ud835\udcdd x)) (hx : x \u2260 0) :\n    Tendsto (fun x => log (f x)) l (\ud835\udcdd (log x)) :=\n  (continuousAt_log hx).Tendsto.comp h\n#align filter.tendsto.log Filter.Tendsto.log\n\nvariable [TopologicalSpace \u03b1] {f : \u03b1 \u2192 \u211d} {s : Set \u03b1} {a : \u03b1}\n\ntheorem Continuous.log (hf : Continuous f) (h\u2080 : \u2200 x, f x \u2260 0) : Continuous fun x => log (f x) :=\n  continuousOn_log.comp_continuous hf h\u2080\n#align continuous.log Continuous.log\n\ntheorem ContinuousAt.log (hf : ContinuousAt f a) (h\u2080 : f a \u2260 0) :\n    ContinuousAt (fun x => log (f x)) a :=\n  hf.log h\u2080\n#align continuous_at.log ContinuousAt.log\n\ntheorem ContinuousWithinAt.log (hf : ContinuousWithinAt f s a) (h\u2080 : f a \u2260 0) :\n    ContinuousWithinAt (fun x => log (f x)) s a :=\n  hf.log h\u2080\n#align continuous_within_at.log ContinuousWithinAt.log\n\ntheorem ContinuousOn.log (hf : ContinuousOn f s) (h\u2080 : \u2200 x \u2208 s, f x \u2260 0) :\n    ContinuousOn (fun x => log (f x)) s := fun x hx => (hf x hx).log (h\u2080 x hx)\n#align continuous_on.log ContinuousOn.log\n\nend Continuity\n\nsection TendstoCompAddSub\n\nopen Filter\n\nnamespace Real\n\ntheorem tendsto_log_comp_add_sub_log (y : \u211d) :\n    Tendsto (fun x : \u211d => log (x + y) - log x) atTop (\ud835\udcdd 0) :=\n  by\n  refine' tendsto.congr' (_ : \u2200\u1da0 x : \u211d in at_top, log (1 + y / x) = _) _\n  \u00b7 refine'\n      eventually.mp ((eventually_ne_at_top 0).And (eventually_gt_at_top (-y)))\n        (eventually_of_forall fun x hx => _)\n    rw [\u2190 log_div _ hx.1]\n    \u00b7 congr 1\n      field_simp [hx.1]\n    \u00b7 linarith [hx.2]\n  \u00b7 suffices tendsto (fun x : \u211d => log (1 + y / x)) at_top (\ud835\udcdd (log (1 + 0))) by simpa\n    refine' tendsto.log _ (by simp)\n    exact tendsto_const_nhds.add (tendsto_const_nhds.div_at_top tendsto_id)\n#align real.tendsto_log_comp_add_sub_log Real.tendsto_log_comp_add_sub_log\n\ntheorem tendsto_log_nat_add_one_sub_log : Tendsto (fun k : \u2115 => log (k + 1) - log k) atTop (\ud835\udcdd 0) :=\n  (tendsto_log_comp_add_sub_log 1).comp tendsto_nat_cast_atTop_atTop\n#align real.tendsto_log_nat_add_one_sub_log Real.tendsto_log_nat_add_one_sub_log\n\nend Real\n\nend TendstoCompAddSub\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/SpecialFunctions/Log/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.712529924969705}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Johannes H\u00f6lzl, Mario Carneiro\n\nCardinal arithmetic.\n\nCardinals are represented as quotient over equinumerous types.\n-/\n\nimport data.set.finite data.quot logic.schroeder_bernstein logic.function\n\nopen function lattice set\nlocal attribute [instance] classical.prop_decidable\n\nuniverses u v w x\n\ninstance cardinal.is_equivalent : setoid (Type u) :=\n{ r := \u03bb\u03b1 \u03b2, nonempty (\u03b1 \u2243 \u03b2),\n  iseqv := \u27e8\u03bb\u03b1,\n    \u27e8equiv.refl \u03b1\u27e9,\n    \u03bb\u03b1 \u03b2 \u27e8e\u27e9, \u27e8e.symm\u27e9,\n    \u03bb\u03b1 \u03b2 \u03b3 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9, \u27e8e\u2081.trans e\u2082\u27e9\u27e9 }\n\n/-- `cardinal.{u}` is the type of cardinal numbers in `Type u`,\n  defined as the quotient of `Type u` by existence of an equivalence\n  (a bijection with explicit inverse). -/\ndef cardinal : Type (u + 1) := quotient cardinal.is_equivalent\n\nnamespace cardinal\n\n/-- The cardinal of a type -/\ndef mk : Type u \u2192 cardinal := quotient.mk\n\n@[simp] theorem mk_def (\u03b1 : Type u) : @eq cardinal \u27e6\u03b1\u27e7 (mk \u03b1) := rfl\n\n@[simp] theorem mk_out (c : cardinal) : mk (c.out) = c := quotient.out_eq _\n\ninstance : has_le cardinal.{u} :=\n\u27e8\u03bbq\u2081 q\u2082, quotient.lift_on\u2082 q\u2081 q\u2082 (\u03bb\u03b1 \u03b2, nonempty $ \u03b1 \u21aa \u03b2) $\n  assume \u03b1 \u03b2 \u03b3 \u03b4 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9,\n    propext \u27e8assume \u27e8e\u27e9, \u27e8e.congr e\u2081 e\u2082\u27e9, assume \u27e8e\u27e9, \u27e8e.congr e\u2081.symm e\u2082.symm\u27e9\u27e9\u27e9\n\ntheorem le_mk_iff_exists_set {c : cardinal} {\u03b1 : Type u} :\n  c \u2264 mk \u03b1 \u2194 \u2203 p : set \u03b1, mk p = c :=\n\u27e8quotient.induction_on c $ \u03bb \u03b2 \u27e8\u27e8f, hf\u27e9\u27e9,\n  \u27e8set.range f, eq.symm $ quot.sound \u27e8equiv.set.range f hf\u27e9\u27e9,\n\u03bb \u27e8p, e\u27e9, e \u25b8 \u27e8\u27e8subtype.val, \u03bb a b, subtype.eq\u27e9\u27e9\u27e9\n\ninstance : linear_order cardinal.{u} :=\n{ le          := (\u2264),\n  le_refl     := by rintros \u27e8\u03b1\u27e9; exact \u27e8embedding.refl _\u27e9,\n  le_trans    := by rintros \u27e8\u03b1\u27e9 \u27e8\u03b2\u27e9 \u27e8\u03b3\u27e9 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9; exact \u27e8e\u2081.trans e\u2082\u27e9,\n  le_antisymm := by rintros \u27e8\u03b1\u27e9 \u27e8\u03b2\u27e9 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9; exact quotient.sound (e\u2081.antisymm e\u2082),\n  le_total    := by rintros \u27e8\u03b1\u27e9 \u27e8\u03b2\u27e9; exact embedding.total }\n\nnoncomputable instance : decidable_linear_order cardinal.{u} := classical.DLO _\n\nnoncomputable instance : distrib_lattice cardinal.{u} := by apply_instance\n\ninstance : has_zero cardinal.{u} := \u27e8\u27e6pempty\u27e7\u27e9\n\ninstance : inhabited cardinal.{u} := \u27e80\u27e9\n\ntheorem ne_zero_iff_nonempty {\u03b1 : Type u} : mk \u03b1 \u2260 0 \u2194 nonempty \u03b1 :=\nnot_iff_comm.1\n  \u27e8\u03bb h, quotient.sound \u27e8(equiv.empty_of_not_nonempty h).trans equiv.empty_equiv_pempty\u27e9,\n   \u03bb e, let \u27e8h\u27e9 := quotient.exact e in \u03bb \u27e8a\u27e9, (h a).elim\u27e9\n\ninstance : has_one cardinal.{u} := \u27e8\u27e6punit\u27e7\u27e9\n\ninstance : zero_ne_one_class cardinal.{u} :=\n{ zero := 0, one := 1, zero_ne_one :=\n  ne.symm $ ne_zero_iff_nonempty.2 \u27e8punit.star\u27e9 }\n\ntheorem le_one_iff_subsingleton {\u03b1 : Type u} : mk \u03b1 \u2264 1 \u2194 subsingleton \u03b1 :=\n\u27e8\u03bb \u27e8f\u27e9, \u27e8\u03bb a b, f.inj (subsingleton.elim _ _)\u27e9,\n \u03bb \u27e8h\u27e9, \u27e8\u27e8\u03bb a, punit.star, \u03bb a b _, h _ _\u27e9\u27e9\u27e9\n\ninstance : has_add cardinal.{u} :=\n\u27e8\u03bbq\u2081 q\u2082, quotient.lift_on\u2082 q\u2081 q\u2082 (\u03bb\u03b1 \u03b2, mk (\u03b1 \u2295 \u03b2)) $ assume \u03b1 \u03b2 \u03b3 \u03b4 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9,\n  quotient.sound \u27e8equiv.sum_congr e\u2081 e\u2082\u27e9\u27e9\n\n@[simp] theorem add_def (\u03b1 \u03b2) : mk \u03b1 + mk \u03b2 = mk (\u03b1 \u2295 \u03b2) := rfl\n\ninstance : has_mul cardinal.{u} :=\n\u27e8\u03bbq\u2081 q\u2082, quotient.lift_on\u2082 q\u2081 q\u2082 (\u03bb\u03b1 \u03b2, mk (\u03b1 \u00d7 \u03b2)) $ assume \u03b1 \u03b2 \u03b3 \u03b4 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9,\n  quotient.sound \u27e8equiv.prod_congr e\u2081 e\u2082\u27e9\u27e9\n\n@[simp] theorem mul_def (\u03b1 \u03b2) : mk \u03b1 * mk \u03b2 = mk (\u03b1 \u00d7 \u03b2) := rfl\n\nprivate theorem add_comm (a b : cardinal.{u}) : a + b = b + a :=\nquotient.induction_on\u2082 a b $ assume \u03b1 \u03b2, quotient.sound \u27e8equiv.sum_comm \u03b1 \u03b2\u27e9\n\nprivate theorem mul_comm (a b : cardinal.{u}) : a * b = b * a :=\nquotient.induction_on\u2082 a b $ assume \u03b1 \u03b2, quotient.sound \u27e8equiv.prod_comm \u03b1 \u03b2\u27e9\n\nprivate theorem zero_add (a : cardinal.{u}) : 0 + a = a :=\nquotient.induction_on a $ assume \u03b1, quotient.sound \u27e8equiv.pempty_sum \u03b1\u27e9\n\nprivate theorem zero_mul (a : cardinal.{u}) : 0 * a = 0 :=\nquotient.induction_on a $ assume \u03b1, quotient.sound \u27e8equiv.pempty_prod \u03b1\u27e9\n\nprivate theorem one_mul (a : cardinal.{u}) : 1 * a = a :=\nquotient.induction_on a $ assume \u03b1, quotient.sound \u27e8equiv.punit_prod \u03b1\u27e9\n\nprivate theorem left_distrib (a b c : cardinal.{u}) : a * (b + c) = a * b + a * c :=\nquotient.induction_on\u2083 a b c $ assume \u03b1 \u03b2 \u03b3, quotient.sound \u27e8equiv.prod_sum_distrib \u03b1 \u03b2 \u03b3\u27e9\n\ninstance : comm_semiring cardinal.{u} :=\n{ zero          := 0,\n  one           := 1,\n  add           := (+),\n  mul           := (*),\n  zero_add      := zero_add,\n  add_zero      := assume a, by rw [add_comm a 0, zero_add a],\n  add_assoc     := \u03bba b c, quotient.induction_on\u2083 a b c $ assume \u03b1 \u03b2 \u03b3,\n    quotient.sound \u27e8equiv.sum_assoc \u03b1 \u03b2 \u03b3\u27e9,\n  add_comm      := add_comm,\n  zero_mul      := zero_mul,\n  mul_zero      := assume a, by rw [mul_comm a 0, zero_mul a],\n  one_mul       := one_mul,\n  mul_one       := assume a, by rw [mul_comm a 1, one_mul a],\n  mul_assoc     := \u03bba b c, quotient.induction_on\u2083 a b c $ assume \u03b1 \u03b2 \u03b3,\n    quotient.sound \u27e8equiv.prod_assoc \u03b1 \u03b2 \u03b3\u27e9,\n  mul_comm      := mul_comm,\n  left_distrib  := left_distrib,\n  right_distrib := assume a b c,\n    by rw [mul_comm (a + b) c, left_distrib c a b, mul_comm c a, mul_comm c b] }\n\n/-- The cardinal exponential. `mk \u03b1 ^ mk \u03b2` is the cardinal of `\u03b2 \u2192 \u03b1`. -/\nprotected def power (a b : cardinal.{u}) : cardinal.{u} :=\nquotient.lift_on\u2082 a b (\u03bb\u03b1 \u03b2, mk (\u03b2 \u2192 \u03b1)) $ assume \u03b1\u2081 \u03b1\u2082 \u03b2\u2081 \u03b2\u2082 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9,\n  quotient.sound \u27e8equiv.arrow_congr e\u2082 e\u2081\u27e9\n\ninstance : has_pow cardinal cardinal := \u27e8cardinal.power\u27e9\nlocal infixr ^ := @has_pow.pow cardinal cardinal cardinal.has_pow\n\n@[simp] theorem power_def (\u03b1 \u03b2) : mk \u03b1 ^ mk \u03b2 = mk (\u03b2 \u2192 \u03b1) := rfl\n\n@[simp] theorem power_zero {a : cardinal} : a ^ 0 = 1 :=\nquotient.induction_on a $ assume \u03b1, quotient.sound\n\u27e8equiv.pempty_arrow_equiv_punit \u03b1\u27e9\n\n@[simp] theorem power_one {a : cardinal} : a ^ 1 = a :=\nquotient.induction_on a $ assume \u03b1, quotient.sound\n\u27e8equiv.punit_arrow_equiv \u03b1\u27e9\n\n@[simp] theorem one_power {a : cardinal} : 1 ^ a = 1 :=\nquotient.induction_on a $ assume \u03b1, quotient.sound\n\u27e8equiv.arrow_punit_equiv_punit \u03b1\u27e9\n\n@[simp] theorem prop_eq_two : mk (ulift Prop) = 2 :=\nquot.sound \u27e8equiv.ulift.trans $ equiv.Prop_equiv_bool.trans equiv.bool_equiv_punit_sum_punit\u27e9\n\n@[simp] theorem zero_power {a : cardinal} : a \u2260 0 \u2192 0 ^ a = 0 :=\nquotient.induction_on a $ assume \u03b1 heq,\nnonempty.rec_on (ne_zero_iff_nonempty.1 heq) $ assume a,\nquotient.sound \u27e8equiv.equiv_pempty $ assume f, pempty.rec (\u03bb _, false) (f a)\u27e9\n\ntheorem power_ne_zero {a : cardinal} (b) : a \u2260 0 \u2192 a ^ b \u2260 0 :=\nquotient.induction_on\u2082 a b $ \u03bb \u03b1 \u03b2 h,\nlet \u27e8a\u27e9 := ne_zero_iff_nonempty.1 h in\nne_zero_iff_nonempty.2 \u27e8\u03bb _, a\u27e9\n\ntheorem mul_power {a b c : cardinal} : (a * b) ^ c = a ^ c * b ^ c :=\nquotient.induction_on\u2083 a b c $ assume \u03b1 \u03b2 \u03b3,\n  quotient.sound \u27e8equiv.arrow_prod_equiv_prod_arrow \u03b1 \u03b2 \u03b3\u27e9\n\ntheorem power_add {a b c : cardinal} : a ^ (b + c) = a ^ b * a ^ c :=\nquotient.induction_on\u2083 a b c $ assume \u03b1 \u03b2 \u03b3,\n  quotient.sound \u27e8equiv.sum_arrow_equiv_prod_arrow \u03b2 \u03b3 \u03b1\u27e9\n\ntheorem power_mul {a b c : cardinal} : (a ^ b) ^ c = a ^ (b * c) :=\nby rw [_root_.mul_comm b c];\nfrom (quotient.induction_on\u2083 a b c $ assume \u03b1 \u03b2 \u03b3,\n  quotient.sound \u27e8equiv.arrow_arrow_equiv_prod_arrow \u03b3 \u03b2 \u03b1\u27e9)\n\nsection order_properties\nopen sum\n\ntheorem zero_le : \u2200(a : cardinal), 0 \u2264 a :=\nby rintro \u27e8\u03b1\u27e9; exact \u27e8embedding.of_not_nonempty $ \u03bb \u27e8a\u27e9, a.elim\u27e9\n\ntheorem le_zero (a : cardinal) : a \u2264 0 \u2194 a = 0 :=\nby simp [le_antisymm_iff, zero_le]\n\ntheorem pos_iff_ne_zero {o : cardinal} : 0 < o \u2194 o \u2260 0 :=\nby simp [lt_iff_le_and_ne, eq_comm, zero_le]\n\ntheorem zero_lt_one : (0 : cardinal) < 1 :=\nlt_of_le_of_ne (zero_le _) zero_ne_one\n\ntheorem add_le_add : \u2200{a b c d : cardinal}, a \u2264 b \u2192 c \u2264 d \u2192 a + c \u2264 b + d :=\nby rintros \u27e8\u03b1\u27e9 \u27e8\u03b2\u27e9 \u27e8\u03b3\u27e9 \u27e8\u03b4\u27e9 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9; exact \u27e8embedding.sum_congr e\u2081 e\u2082\u27e9\n\ntheorem add_le_add_left (a) {b c : cardinal} : b \u2264 c \u2192 a + b \u2264 a + c :=\nadd_le_add (le_refl _)\n\ntheorem add_le_add_right {a b : cardinal} (c) (h : a \u2264 b) : a + c \u2264 b + c :=\nadd_le_add h (le_refl _)\n\ntheorem le_add_right (a b : cardinal) : a \u2264 a + b :=\nby simpa using add_le_add_left a (zero_le b)\n\ntheorem le_add_left (a b : cardinal) : a \u2264 b + a :=\nby simpa using add_le_add_right a (zero_le b)\n\ntheorem mul_le_mul : \u2200{a b c d : cardinal}, a \u2264 b \u2192 c \u2264 d \u2192 a * c \u2264 b * d :=\nby rintros \u27e8\u03b1\u27e9 \u27e8\u03b2\u27e9 \u27e8\u03b3\u27e9 \u27e8\u03b4\u27e9 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9; exact \u27e8embedding.prod_congr e\u2081 e\u2082\u27e9\n\ntheorem mul_le_mul_left (a) {b c : cardinal} : b \u2264 c \u2192 a * b \u2264 a * c :=\nmul_le_mul (le_refl _)\n\ntheorem mul_le_mul_right {a b : cardinal} (c) (h : a \u2264 b) : a * c \u2264 b * c :=\nmul_le_mul h (le_refl _)\n\ntheorem power_le_power_left : \u2200{a b c : cardinal}, a \u2260 0 \u2192 b \u2264 c \u2192 a ^ b \u2264 a ^ c :=\nby rintros \u27e8\u03b1\u27e9 \u27e8\u03b2\u27e9 \u27e8\u03b3\u27e9 h\u03b1 \u27e8e\u27e9; exact\n  let \u27e8a\u27e9 := ne_zero_iff_nonempty.1 h\u03b1 in\n  \u27e8@embedding.arrow_congr_right _ _ _ \u27e8a\u27e9 e\u27e9\n\ntheorem power_le_power_right {a b c : cardinal} : a \u2264 b \u2192 a ^ c \u2264 b ^ c :=\nquotient.induction_on\u2083 a b c $ assume \u03b1 \u03b2 \u03b3 \u27e8e\u27e9, \u27e8embedding.arrow_congr_left e\u27e9\n\ntheorem le_iff_exists_add {a b : cardinal} : a \u2264 b \u2194 \u2203 c, b = a + c :=\n\u27e8quotient.induction_on\u2082 a b $ \u03bb \u03b1 \u03b2 \u27e8\u27e8f, hf\u27e9\u27e9,\n  have (\u03b1 \u2295 \u21a5-range f) \u2243 \u03b2, from\n    (equiv.sum_congr (equiv.set.range f hf) (equiv.refl _)).trans $\n    (equiv.set.sum_compl (range f)),\n  \u27e8\u27e6(-range f : set \u03b2)\u27e7, quotient.sound \u27e8this.symm\u27e9\u27e9,\n \u03bb \u27e8c, e\u27e9, add_zero a \u25b8 e.symm \u25b8 add_le_add_left _ (zero_le _)\u27e9\n\nend order_properties\n\ninstance : canonically_ordered_monoid cardinal.{u} :=\n{ add_le_add_left       := \u03bb a b h c, add_le_add_left _ h,\n  lt_of_add_lt_add_left := \u03bb a b c, le_imp_le_iff_lt_imp_lt.1 (add_le_add_left _),\n  le_iff_exists_add     := @le_iff_exists_add,\n  ..cardinal.comm_semiring, ..cardinal.linear_order }\n\ninstance : order_bot cardinal.{u} :=\n{ bot := 0, bot_le := zero_le, ..cardinal.linear_order }\n\ntheorem cantor : \u2200(a : cardinal.{u}), a < 2 ^ a :=\nby rw \u2190 prop_eq_two; rintros \u27e8a\u27e9; exact \u27e8\n  \u27e8\u27e8\u03bb a b, \u27e8a = b\u27e9, \u03bb a b h, cast (ulift.up.inj (@congr_fun _ _ _ _ h b)).symm rfl\u27e9\u27e9,\n  \u03bb \u27e8\u27e8f, hf\u27e9\u27e9, cantor_injective (\u03bb s, f (\u03bb a, \u27e8s a\u27e9)) $\n    \u03bb s t h, by funext a; injection congr_fun (hf h) a\u27e9\n\ninstance : no_top_order cardinal.{u} :=\n{ no_top := \u03bb a, \u27e8_, cantor a\u27e9, ..cardinal.linear_order }\n\n/-- The minimum cardinal in a family of cardinals (the existence\n  of which is provided by `injective_min`). -/\nnoncomputable def min {\u03b9} (I : nonempty \u03b9) (f : \u03b9 \u2192 cardinal) : cardinal :=\nf $ classical.some $\n@embedding.injective_min _ (\u03bb i, (f i).out) I\n\ntheorem min_eq {\u03b9} (I) (f : \u03b9 \u2192 cardinal) : \u2203 i, min I f = f i :=\n\u27e8_, rfl\u27e9\n\ntheorem min_le {\u03b9 I} (f : \u03b9 \u2192 cardinal) (i) : min I f \u2264 f i :=\nby rw [\u2190 mk_out (min I f), \u2190 mk_out (f i)]; exact\nlet \u27e8g\u27e9 := classical.some_spec\n  (@embedding.injective_min _ (\u03bb i, (f i).out) I) in\n\u27e8g i\u27e9\n\ntheorem le_min {\u03b9 I} {f : \u03b9 \u2192 cardinal} {a} : a \u2264 min I f \u2194 \u2200 i, a \u2264 f i :=\n\u27e8\u03bb h i, le_trans h (min_le _ _),\n \u03bb h, let \u27e8i, e\u27e9 := min_eq I f in e.symm \u25b8 h i\u27e9\n\nprotected theorem wf : @well_founded cardinal.{u} (<) :=\n\u27e8\u03bb a, classical.by_contradiction $ \u03bb h,\n  let \u03b9 := {c :cardinal // \u00ac acc (<) c},\n      f : \u03b9 \u2192 cardinal := subtype.val,\n      \u27e8\u27e8c, hc\u27e9, hi\u27e9 := @min_eq \u03b9 \u27e8\u27e8_, h\u27e9\u27e9 f in\n    hc (acc.intro _ (\u03bb j \u27e8_, h'\u27e9,\n      classical.by_contradiction $ \u03bb hj, h' $\n      by have := min_le f \u27e8j, hj\u27e9; rwa hi at this))\u27e9\n\ninstance has_wf : @has_well_founded cardinal.{u} := \u27e8(<), cardinal.wf\u27e9\n\ninstance wo : @is_well_order cardinal.{u} (<) := \u27e8cardinal.wf\u27e9\n\n/-- The successor cardinal - the smallest cardinal greater than\n  `c`. This is not the same as `c + 1` except in the case of finite `c`. -/\nnoncomputable def succ (c : cardinal) : cardinal :=\n@min {c' // c < c'} \u27e8\u27e8_, cantor _\u27e9\u27e9 subtype.val\n\ntheorem lt_succ_self (c : cardinal) : c < succ c :=\nby cases min_eq _ _ with s e; rw [succ, e]; exact s.2\n\ntheorem succ_le {a b : cardinal} : succ a \u2264 b \u2194 a < b :=\n\u27e8lt_of_lt_of_le (lt_succ_self _), \u03bb h,\n  by exact min_le _ (subtype.mk b h)\u27e9\n\ntheorem lt_succ {a b : cardinal} : a < succ b \u2194 a \u2264 b :=\nby rw [\u2190 not_le, succ_le, not_lt]\n\ntheorem add_one_le_succ (c : cardinal) : c + 1 \u2264 succ c :=\nbegin\n  refine quot.induction_on c (\u03bb \u03b1, _) (lt_succ_self c),\n  refine quot.induction_on (succ (quot.mk setoid.r \u03b1)) (\u03bb \u03b2 h, _),\n  cases h.left with f,\n  have : \u00ac surjective f := \u03bb hn,\n    ne_of_lt h (quotient.sound \u27e8equiv.of_bijective \u27e8f.inj, hn\u27e9\u27e9),\n  cases classical.not_forall.1 this with b nex,\n  refine \u27e8\u27e8sum.rec (by exact f) _, _\u27e9\u27e9,\n  { exact \u03bb _, b },\n  { intros a b h, rcases a with a|\u27e8\u27e8\u27e8\u27e9\u27e9\u27e9; rcases b with b|\u27e8\u27e8\u27e8\u27e9\u27e9\u27e9,\n    { rw f.inj h },\n    { exact nex.elim \u27e8_, h\u27e9 },\n    { exact nex.elim \u27e8_, h.symm\u27e9 },\n    { refl } }\nend\n\n/-- The indexed sum of cardinals is the cardinality of the\n  indexed disjoint union, i.e. sigma type. -/\ndef sum {\u03b9} (f : \u03b9 \u2192 cardinal) : cardinal := mk \u03a3 i, (f i).out\n\ntheorem le_sum {\u03b9} (f : \u03b9 \u2192 cardinal) (i) : f i \u2264 sum f :=\nby rw \u2190 quotient.out_eq (f i); exact\n\u27e8\u27e8\u03bb a, \u27e8i, a\u27e9, \u03bb a b h, eq_of_heq $ by injection h\u27e9\u27e9\n\n@[simp] theorem sum_mk {\u03b9} (f : \u03b9 \u2192 Type*) : sum (\u03bb i, mk (f i)) = mk (\u03a3 i, f i) :=\nquot.sound \u27e8equiv.sigma_congr_right $ \u03bb i,\n  classical.choice $ quotient.exact $ quot.out_eq $ mk (f i)\u27e9\n\ntheorem sum_const (\u03b9 : Type u) (a : cardinal.{u}) : sum (\u03bb _:\u03b9, a) = mk \u03b9 * a :=\nquotient.induction_on a $ \u03bb \u03b1, by simp; exact\n  quotient.sound \u27e8equiv.sigma_equiv_prod _ _\u27e9\n\ntheorem sum_le_sum {\u03b9} (f g : \u03b9 \u2192 cardinal) (H : \u2200 i, f i \u2264 g i) : sum f \u2264 sum g :=\n\u27e8embedding.sigma_congr_right $ \u03bb i, classical.choice $\n  by have := H i; rwa [\u2190 quot.out_eq (f i), \u2190 quot.out_eq (g i)] at this\u27e9\n\n/-- The indexed supremum of cardinals is the smallest cardinal above\n  everything in the family. -/\nnoncomputable def sup {\u03b9} (f : \u03b9 \u2192 cardinal) : cardinal :=\n@min {c // \u2200 i, f i \u2264 c} \u27e8\u27e8sum f, le_sum f\u27e9\u27e9 (\u03bb a, a.1)\n\ntheorem le_sup {\u03b9} (f : \u03b9 \u2192 cardinal) (i) : f i \u2264 sup f :=\nby dsimp [sup]; cases min_eq _ _ with c hc; rw hc; exact c.2 i\n\ntheorem sup_le {\u03b9} {f : \u03b9 \u2192 cardinal} {a} : sup f \u2264 a \u2194 \u2200 i, f i \u2264 a :=\n\u27e8\u03bb h i, le_trans (le_sup _ _) h,\n \u03bb h, by dsimp [sup]; change a with (\u27e8a, h\u27e9:subtype _).1; apply min_le\u27e9\n\ntheorem sup_le_sup {\u03b9} (f g : \u03b9 \u2192 cardinal) (H : \u2200 i, f i \u2264 g i) : sup f \u2264 sup g :=\nsup_le.2 $ \u03bb i, le_trans (H i) (le_sup _ _)\n\ntheorem sup_le_sum {\u03b9} (f : \u03b9 \u2192 cardinal) : sup f \u2264 sum f :=\nsup_le.2 $ le_sum _\n\ntheorem sum_le_sup {\u03b9 : Type u} (f : \u03b9 \u2192 cardinal.{u}) : sum f \u2264 mk \u03b9 * sup.{u u} f :=\nby rw \u2190 sum_const; exact sum_le_sum _ _ (le_sup _)\n\n/-- The indexed product of cardinals is the cardinality of the Pi type\n  (dependent product). -/\ndef prod {\u03b9 : Type u} (f : \u03b9 \u2192 cardinal) : cardinal := mk (\u03a0 i, (f i).out)\n\n@[simp] theorem prod_mk {\u03b9} (f : \u03b9 \u2192 Type*) : prod (\u03bb i, mk (f i)) = mk (\u03a0 i, f i) :=\nquot.sound \u27e8equiv.Pi_congr_right $ \u03bb i,\n  classical.choice $ quotient.exact $ mk_out $ mk (f i)\u27e9\n\ntheorem prod_const (\u03b9 : Type u) (a : cardinal.{u}) : prod (\u03bb _:\u03b9, a) = a ^ mk \u03b9 :=\nquotient.induction_on a $ by simp\n\ntheorem prod_le_prod {\u03b9} (f g : \u03b9 \u2192 cardinal) (H : \u2200 i, f i \u2264 g i) : prod f \u2264 prod g :=\n\u27e8embedding.Pi_congr_right $ \u03bb i, classical.choice $\n  by have := H i; rwa [\u2190 mk_out (f i), \u2190 mk_out (g i)] at this\u27e9\n\ntheorem prod_ne_zero {\u03b9} (f : \u03b9 \u2192 cardinal) : prod f \u2260 0 \u2194 \u2200 i, f i \u2260 0 :=\nbegin\n  conv in (f _) {rw \u2190 mk_out (f i)},\n  simp [prod, ne_zero_iff_nonempty, -mk_out, -ne.def],\n  exact \u27e8\u03bb \u27e8F\u27e9 i, \u27e8F i\u27e9, \u03bb h, \u27e8\u03bb i, classical.choice (h i)\u27e9\u27e9,\nend\n\ntheorem prod_eq_zero {\u03b9} (f : \u03b9 \u2192 cardinal) : prod f = 0 \u2194 \u2203 i, f i = 0 :=\nnot_iff_not.1 $ by simpa using prod_ne_zero f\n\n/-- The universe lift operation on cardinals -/\ndef lift (c : cardinal.{u}) : cardinal.{max u v} :=\nquotient.lift_on c (\u03bb \u03b1, \u27e6ulift \u03b1\u27e7) $ \u03bb \u03b1 \u03b2 \u27e8e\u27e9,\nquotient.sound \u27e8equiv.ulift.trans $ e.trans equiv.ulift.symm\u27e9\n\ntheorem lift_mk (\u03b1) : lift.{u v} (mk \u03b1) = mk (ulift.{v u} \u03b1) := rfl\n\ntheorem lift_umax : lift.{u (max u v)} = lift.{u v} :=\nfunext $ \u03bb a, quot.induction_on a $ \u03bb \u03b1,\nquotient.sound \u27e8equiv.ulift.trans equiv.ulift.symm\u27e9\n\ntheorem lift_id' (a : cardinal) : lift a = a :=\nquot.induction_on a $ \u03bb \u03b1, quot.sound \u27e8equiv.ulift\u27e9\n\n@[simp] theorem lift_id : \u2200 a, lift.{u u} a = a := lift_id'.{u u}\n\n@[simp] theorem lift_lift (a : cardinal) : lift.{(max u v) w} (lift.{u v} a) = lift.{u (max v w)} a :=\nquot.induction_on a $ \u03bb \u03b1,\nquotient.sound \u27e8equiv.ulift.trans $ equiv.ulift.trans equiv.ulift.symm\u27e9\n\ntheorem lift_mk_le {\u03b1 : Type u} {\u03b2 : Type v} :\n  lift.{u (max v w)} (mk \u03b1) \u2264 lift.{v (max u w)} (mk \u03b2) \u2194 nonempty (\u03b1 \u21aa \u03b2) :=\n\u27e8\u03bb \u27e8f\u27e9, \u27e8embedding.congr equiv.ulift equiv.ulift f\u27e9,\n \u03bb \u27e8f\u27e9, \u27e8embedding.congr equiv.ulift.symm equiv.ulift.symm f\u27e9\u27e9\n\ntheorem lift_mk_eq {\u03b1 : Type u} {\u03b2 : Type v} :\n  lift.{u (max v w)} (mk \u03b1) = lift.{v (max u w)} (mk \u03b2) \u2194 nonempty (\u03b1 \u2243 \u03b2) :=\nquotient.eq.trans\n\u27e8\u03bb \u27e8f\u27e9, \u27e8equiv.ulift.symm.trans $ f.trans equiv.ulift\u27e9,\n \u03bb \u27e8f\u27e9, \u27e8equiv.ulift.trans $ f.trans equiv.ulift.symm\u27e9\u27e9\n\n@[simp] theorem lift_le {a b : cardinal} : lift a \u2264 lift b \u2194 a \u2264 b :=\nquotient.induction_on\u2082 a b $ \u03bb \u03b1 \u03b2,\nby rw \u2190 lift_umax; exact lift_mk_le\n\n@[simp] theorem lift_inj {a b : cardinal} : lift a = lift b \u2194 a = b :=\nby simp [le_antisymm_iff]\n\n@[simp] theorem lift_lt {a b : cardinal} : lift a < lift b \u2194 a < b :=\nby simp [lt_iff_le_not_le, -not_le]\n\n@[simp] theorem lift_zero : lift 0 = 0 :=\nquotient.sound \u27e8equiv.ulift.trans equiv.pempty_equiv_pempty\u27e9\n\n@[simp] theorem lift_one : lift 1 = 1 :=\nquotient.sound \u27e8equiv.ulift.trans equiv.punit_equiv_punit\u27e9\n\n@[simp] theorem lift_add (a b) : lift (a + b) = lift a + lift b :=\nquotient.induction_on\u2082 a b $ \u03bb \u03b1 \u03b2,\nquotient.sound \u27e8equiv.ulift.trans (equiv.sum_congr equiv.ulift equiv.ulift).symm\u27e9\n\n@[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b :=\nquotient.induction_on\u2082 a b $ \u03bb \u03b1 \u03b2,\nquotient.sound \u27e8equiv.ulift.trans (equiv.prod_congr equiv.ulift equiv.ulift).symm\u27e9\n\n@[simp] theorem lift_power (a b) : lift (a ^ b) = lift a ^ lift b :=\nquotient.induction_on\u2082 a b $ \u03bb \u03b1 \u03b2,\nquotient.sound \u27e8equiv.ulift.trans (equiv.arrow_congr equiv.ulift equiv.ulift).symm\u27e9\n\n@[simp] theorem lift_two_power (a) : lift (2 ^ a) = 2 ^ lift a :=\nby simp [bit0]\n\n@[simp] theorem lift_min {\u03b9 I} (f : \u03b9 \u2192 cardinal) : lift (min I f) = min I (lift \u2218 f) :=\nle_antisymm (le_min.2 $ \u03bb a, lift_le.2 $ min_le _ a) $\nlet \u27e8i, e\u27e9 := min_eq I (lift \u2218 f) in\nby rw e; exact lift_le.2 (le_min.2 $ \u03bb j, lift_le.1 $\nby have := min_le (lift \u2218 f) j; rwa e at this)\n\ntheorem lift_down {a : cardinal.{u}} {b : cardinal.{max u v}} :\n  b \u2264 lift a \u2192 \u2203 a', lift a' = b :=\nquotient.induction_on\u2082 a b $ \u03bb \u03b1 \u03b2,\nby dsimp; rw [\u2190 lift_id (mk \u03b2), \u2190 lift_umax, \u2190 lift_umax.{u v}, lift_mk_le]; exact\n\u03bb \u27e8f\u27e9, \u27e8mk (set.range f), eq.symm $ lift_mk_eq.2\n  \u27e8embedding.equiv_of_surjective\n    (embedding.cod_restrict _ f set.mem_range_self)\n    $ \u03bb \u27e8a, \u27e8b, e\u27e9\u27e9, \u27e8b, subtype.eq e\u27e9\u27e9\u27e9\n\ntheorem le_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :\n  b \u2264 lift a \u2194 \u2203 a', lift a' = b \u2227 a' \u2264 a :=\n\u27e8\u03bb h, let \u27e8a', e\u27e9 := lift_down h in \u27e8a', e, lift_le.1 $ e.symm \u25b8 h\u27e9,\n \u03bb \u27e8a', e, h\u27e9, e \u25b8 lift_le.2 h\u27e9\n\ntheorem lt_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :\n  b < lift a \u2194 \u2203 a', lift a' = b \u2227 a' < a :=\n\u27e8\u03bb h, let \u27e8a', e\u27e9 := lift_down (le_of_lt h) in\n      \u27e8a', e, lift_lt.1 $ e.symm \u25b8 h\u27e9,\n \u03bb \u27e8a', e, h\u27e9, e \u25b8 lift_lt.2 h\u27e9\n\n@[simp] theorem lift_succ (a) : lift (succ a) = succ (lift a) :=\nle_antisymm\n  (le_of_not_gt $ \u03bb h, begin\n    rcases lt_lift_iff.1 h with \u27e8b, e, h\u27e9,\n    rw [lt_succ, \u2190 lift_le, e] at h,\n    exact not_lt_of_le h (lt_succ_self _)\n  end)\n  (succ_le.2 $ lift_lt.2 $ lt_succ_self _)\n\n/-- `\u03c9` is the smallest infinite cardinal, also known as \u2135\u2080. -/\ndef omega : cardinal.{u} := lift (mk \u2115)\n\ntheorem omega_ne_zero : omega \u2260 0 :=\nne_zero_iff_nonempty.2 \u27e8\u27e80\u27e9\u27e9\n\ntheorem omega_pos : 0 < omega :=\npos_iff_ne_zero.2 omega_ne_zero\n\n@[simp] theorem lift_omega : lift omega = omega := lift_lift _\n\n@[simp] theorem mk_fin : \u2200 (n : \u2115), mk (fin n) = n\n| 0     := quotient.sound \u27e8(equiv.pempty_of_not_nonempty $ \u03bb \u27e8h\u27e9, h.elim0)\u27e9\n| (n+1) := by rw [nat.cast_succ, \u2190 mk_fin]; exact\n  quotient.sound (fintype.card_eq.1 $ by simp)\n\n@[simp] theorem lift_nat_cast (n : \u2115) : lift n = n :=\nby induction n; simp *\n\ntheorem lift_mk_fin (n : \u2115) : lift (mk (fin n)) = n := by simp\n\ntheorem fintype_card (\u03b1 : Type u) [fintype \u03b1] : mk \u03b1 = fintype.card \u03b1 :=\nby rw [\u2190 lift_mk_fin.{u}, \u2190 lift_id (mk \u03b1), lift_mk_eq.{u 0 u}];\n   exact fintype.card_eq.1 (by simp)\n\ntheorem card_le_of_finset {\u03b1} (s : finset \u03b1) :\n  (s.card : cardinal) \u2264 cardinal.mk \u03b1 :=\nbegin\n  rw (_ : (s.card : cardinal) = cardinal.mk (\u2191s : set \u03b1)),\n  { exact \u27e8function.embedding.subtype _\u27e9 },\n  rw [cardinal.fintype_card, fintype.card_coe]\nend\n\n@[simp] theorem nat_cast_pow {m n : \u2115} : (\u2191(pow m n) : cardinal) = m ^ n :=\nby induction n; simp [nat.pow_succ, -_root_.add_comm, power_add, *]\n\n@[simp] theorem nat_cast_le {m n : \u2115} : (m : cardinal) \u2264 n \u2194 m \u2264 n :=\nby rw [\u2190 lift_mk_fin, \u2190 lift_mk_fin, lift_le]; exact\n\u27e8\u03bb \u27e8\u27e8f, hf\u27e9\u27e9, begin\n  have : _ = fintype.card _ := finset.card_image_of_injective finset.univ hf,\n  simp at this,\n  rw [\u2190 fintype.card_fin n, \u2190 this],\n  exact finset.card_le_of_subset (finset.subset_univ _)\nend,\n\u03bb h, \u27e8\u27e8\u03bb i, \u27e8i.1, lt_of_lt_of_le i.2 h\u27e9, \u03bb a b h,\n  have _, from fin.veq_of_eq h, fin.eq_of_veq this\u27e9\u27e9\u27e9\n\n@[simp] theorem nat_cast_lt {m n : \u2115} : (m : cardinal) < n \u2194 m < n :=\nby simp [lt_iff_le_not_le, -not_le]\n\n@[simp] theorem nat_cast_inj {m n : \u2115} : (m : cardinal) = n \u2194 m = n :=\nby simp [le_antisymm_iff]\n\n@[simp] theorem nat_succ (n : \u2115) : succ n = n.succ :=\nle_antisymm (succ_le.2 $ nat_cast_lt.2 $ nat.lt_succ_self _) (add_one_le_succ _)\n\n@[simp] theorem succ_zero : succ 0 = 1 :=\nby simpa using nat_succ 0\n\ntheorem cantor' (a) {b : cardinal} (hb : 1 < b) : a < b ^ a :=\nby rw [\u2190 succ_le, (by simpa using nat_succ 1 : succ 1 = 2)] at hb;\n   exact lt_of_lt_of_le (cantor _) (power_le_power_right hb)\n\ntheorem one_le_iff_pos {c : cardinal} : 1 \u2264 c \u2194 0 < c :=\nby rw [\u2190 succ_zero, succ_le]\n\ntheorem one_le_iff_ne_zero {c : cardinal} : 1 \u2264 c \u2194 c \u2260 0 :=\nby rw [one_le_iff_pos, pos_iff_ne_zero]\n\ntheorem nat_lt_omega (n : \u2115) : (n : cardinal.{u}) < omega :=\nsucc_le.1 $ by rw [nat_succ, \u2190 lift_mk_fin, omega, lift_mk_le.{0 0 u}]; exact\n\u27e8\u27e8fin.val, \u03bb a b, fin.eq_of_veq\u27e9\u27e9\n\ntheorem one_lt_omega : 1 < omega :=\nby simpa using nat_lt_omega 1\n\ntheorem lt_omega {c : cardinal.{u}} : c < omega \u2194 \u2203 n : \u2115, c = n :=\n\u27e8\u03bb h, begin\n  rcases lt_lift_iff.1 h with \u27e8c, rfl, h'\u27e9,\n  rcases le_mk_iff_exists_set.1 h'.1 with \u27e8S, rfl\u27e9,\n  suffices : finite S,\n  { cases this, resetI,\n    existsi fintype.card S,\n    rw [\u2190 lift_nat_cast.{0 u}, lift_inj, fintype_card S] },\n  by_contra nf,\n  have P : \u2200 (n : \u2115) (IH : \u2200 i<n, S), \u2203 a : S, \u00ac \u2203 y h, IH y h = a :=\n    \u03bb n IH,\n    let g : {i | i < n} \u2192 S := \u03bb \u27e8i, h\u27e9, IH i h in\n    classical.not_forall.1 (\u03bb h, nf\n      \u27e8fintype.of_surjective g (\u03bb a, subtype.exists.2 (h a))\u27e9),\n  let F : \u2115 \u2192 S := nat.lt_wf.fix (\u03bb n IH, classical.some (P n IH)),\n  refine not_le_of_lt h' \u27e8\u27e8F, _\u27e9\u27e9,\n  suffices : \u2200 (n : \u2115) (m < n), F m \u2260 F n,\n  { refine \u03bb m n, not_imp_not.1 (\u03bb ne, _),\n    rcases lt_trichotomy m n with h|h|h,\n    { exact this n m h },\n    { contradiction },\n    { exact (this m n h).symm } },\n  intros n m h,\n  have := classical.some_spec (P n (\u03bb y _, F y)),\n  rw [\u2190 show F n = classical.some (P n (\u03bb y _, F y)),\n      from nat.lt_wf.fix_eq (\u03bb n IH, classical.some (P n IH)) n] at this,\n  exact \u03bb e, this \u27e8m, h, e\u27e9,\nend, \u03bb \u27e8n, e\u27e9, e.symm \u25b8 nat_lt_omega _\u27e9\n\ntheorem omega_le {c : cardinal.{u}} : omega \u2264 c \u2194 \u2200 n : \u2115, (n:cardinal) \u2264 c :=\n\u27e8\u03bb h n, le_trans (le_of_lt (nat_lt_omega _)) h,\n \u03bb h, le_of_not_lt $ \u03bb hn, begin\n  rcases lt_omega.1 hn with \u27e8n, rfl\u27e9,\n  exact not_le_of_lt (nat.lt_succ_self _) (nat_cast_le.1 (h (n+1)))\nend\u27e9\n\ntheorem lt_omega_iff_fintype {\u03b1 : Type u} : mk \u03b1 < omega \u2194 nonempty (fintype \u03b1) :=\nlt_omega.trans \u27e8\u03bb \u27e8n, e\u27e9, begin\n  rw [\u2190 lift_mk_fin n] at e,\n  cases quotient.exact e with f,\n  exact \u27e8fintype.of_equiv _ f.symm\u27e9\nend, \u03bb \u27e8_\u27e9, by exactI \u27e8_, fintype_card _\u27e9\u27e9\n\ntheorem lt_omega_iff_finite {\u03b1} {S : set \u03b1} : mk S < omega \u2194 finite S :=\nlt_omega_iff_fintype\n\ntheorem add_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a + b < omega :=\nmatch a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by rw [\u2190 nat.cast_add]; apply nat_lt_omega\nend\n\ntheorem mul_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a * b < omega :=\nmatch a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by rw [\u2190 nat.cast_mul]; apply nat_lt_omega\nend\n\ntheorem power_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a ^ b < omega :=\nmatch a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 := by rw [\u2190 nat_cast_pow]; apply nat_lt_omega\nend\n\n/-- K\u00f6nig's theorem -/\ntheorem sum_lt_prod {\u03b9} (f g : \u03b9 \u2192 cardinal) (H : \u2200 i, f i < g i) : sum f < prod g :=\nlt_of_not_ge $ \u03bb \u27e8F\u27e9, begin\n  have : inhabited (\u03a0 (i : \u03b9), (g i).out),\n  { refine \u27e8\u03bb i, classical.choice $ ne_zero_iff_nonempty.1 _\u27e9,\n    rw mk_out,\n    exact ne_of_gt (lt_of_le_of_lt (zero_le _) (H i)) }, resetI,\n  let G := inv_fun F,\n  have sG : surjective G := inv_fun_surjective F.2,\n  have : \u2200 i, \u00ac \u2200 b, \u2203 a, G \u27e8i, a\u27e9 i = b,\n  { refine \u03bb i h, not_le_of_lt (H i) _,\n    rw [\u2190 mk_out (f i), \u2190 mk_out (g i)],\n    exact \u27e8embedding.of_surjective h\u27e9 },\n  simp [classical.not_forall] at this,\n  exact let \u27e8C, hc\u27e9 := classical.axiom_of_choice this, \u27e8\u27e8i, a\u27e9, h\u27e9 := sG C in\n  hc i a (congr_fun h _),\nend\n\n@[simp] theorem mk_empty : mk empty = 0 :=\nfintype_card empty\n\n@[simp] theorem mk_pempty : mk pempty = 0 :=\nfintype_card pempty\n\n@[simp] theorem mk_empty' (\u03b1 : Type u) : mk (\u2205 : set \u03b1) = 0 :=\nquotient.sound \u27e8equiv.set.pempty \u03b1\u27e9\n\n@[simp] theorem mk_plift_false : mk (plift false) = 0 :=\nquotient.sound \u27e8equiv.plift.trans $ equiv.false_equiv_pempty\u27e9\n\n@[simp] theorem mk_unit : mk unit = 1 :=\n(fintype_card unit).trans nat.cast_one\n\n@[simp] theorem mk_punit : mk punit = 1 :=\n(fintype_card punit).trans nat.cast_one\n\n@[simp] theorem mk_singleton {\u03b1 : Type u} (x : \u03b1) : mk ({x} : set \u03b1) = 1 :=\nquotient.sound \u27e8equiv.set.singleton x\u27e9\n\n@[simp] theorem mk_plift_true : mk (plift true) = 1 :=\nquotient.sound \u27e8equiv.plift.trans equiv.true_equiv_punit\u27e9\n\n@[simp] theorem mk_bool : mk bool = 2 :=\nquotient.sound \u27e8equiv.bool_equiv_punit_sum_punit\u27e9\n\n@[simp] theorem mk_Prop : mk Prop = 2 :=\n(quotient.sound \u27e8equiv.Prop_equiv_bool\u27e9 : mk Prop = mk bool).trans mk_bool\n\n@[simp] theorem mk_option {\u03b1 : Type u} : mk (option \u03b1) = mk \u03b1 + 1 :=\nquotient.sound \u27e8equiv.option_equiv_sum_punit \u03b1\u27e9\n\ntheorem mk_eq_of_injective {\u03b1 \u03b2 : Type u} {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (hf : injective f) : mk (f '' s) = mk s :=\nquotient.sound \u27e8(equiv.set.image f s hf).symm\u27e9\n\ntheorem mk_list_eq_sum_pow (\u03b1 : Type u) : mk (list \u03b1) = sum (\u03bb n : \u2115, (mk \u03b1)^(n:cardinal.{u})) :=\ncalc  mk (list \u03b1)\n    = mk (\u03a3 n, vector \u03b1 n) : quotient.sound \u27e8equiv.equiv_sigma_subtype list.length\u27e9\n... = mk (\u03a3 n, fin n \u2192 \u03b1) : quotient.sound \u27e8equiv.sigma_congr_right $ \u03bb n,\n  \u27e8vector.nth, vector.of_fn, vector.of_fn_nth, \u03bb f, funext $ vector.nth_of_fn f\u27e9\u27e9\n... = mk (\u03a3 n : \u2115, ulift.{u} (fin n) \u2192 \u03b1) : quotient.sound \u27e8equiv.sigma_congr_right $ \u03bb n,\n  equiv.arrow_congr equiv.ulift.symm (equiv.refl \u03b1)\u27e9\n... = sum (\u03bb n : \u2115, (mk \u03b1)^(n:cardinal.{u})) : by simp only [(lift_mk_fin _).symm, lift_mk, power_def, sum_mk]\n\ntheorem mk_Union_le_sum_mk {\u03b1 \u03b9 : Type u} {f : \u03b9 \u2192 set \u03b1} : mk (\u22c3 i, f i) \u2264 sum (\u03bb i, mk (f i)) :=\ncalc  mk (\u22c3 i, f i)\n    \u2264 mk (\u03a3 i, f i) : show nonempty ((\u22c3 i, f i) \u21aa (\u03a3 i, f i)),\n  from \u27e8\u27e8\u03bb x, \u27e8classical.some (mem_Union.1 x.2), x.1, classical.some_spec (mem_Union.1 x.2)\u27e9,\n  \u03bb x y H, subtype.eq $ begin\n    cases sigma.mk.inj H with H1 H2, clear H,\n    generalize_hyp : classical.some_spec _ = H4 at H1 H2,\n    generalize_hyp : classical.some _ = i\u2080 at H1 H2 H4,\n    subst H1,\n    exact subtype.mk.inj (eq_of_heq H2)\n  end\u27e9\u27e9\n... = sum (\u03bb i, mk (f i)) : (sum_mk _).symm\n\n@[simp] lemma finset_card {\u03b1 : Type u} {s : finset \u03b1} : \u2191(finset.card s) = mk (\u2191s : set \u03b1) :=\nby rw [fintype_card, nat_cast_inj, fintype.card_coe]\n\ntheorem mk_union_add_mk_inter {\u03b1 : Type u} {S T : set \u03b1} : mk (S \u222a T : set \u03b1) + mk (S \u2229 T : set \u03b1) = mk S + mk T :=\nquotient.sound $ nonempty.intro $\n{ to_fun := \u03bb x, sum.rec_on x\n    (\u03bb x, if h : x.1 \u2208 S then sum.inl \u27e8x.1, h\u27e9 else sum.inr \u27e8x.1, x.2.resolve_left h\u27e9)\n    (\u03bb x, sum.inr \u27e8x.1, x.2.2\u27e9),\n  inv_fun := \u03bb x, sum.rec_on x\n    (\u03bb x, sum.inl \u27e8x.1, or.inl x.2\u27e9)\n    (\u03bb x, if h : x.1 \u2208 S then sum.inr \u27e8x.1, h, x.2\u27e9 else sum.inl \u27e8x.1, or.inr x.2\u27e9),\n  left_inv := \u03bb x, sum.rec_on x\n    (\u03bb \u27e8x, hx\u27e9, if h : x \u2208 S\n      then by dsimp only; rw [dif_pos h]; refl\n      else by dsimp only; rw [dif_neg h]; dsimp only; rw [dif_neg h]; refl)\n    (\u03bb \u27e8x, hx1, hx2\u27e9, by dsimp only; rw [dif_pos hx1]),\n  right_inv := \u03bb x, sum.rec_on x\n    (\u03bb \u27e8x, hx\u27e9, by dsimp only; rw [dif_pos hx])\n    (\u03bb \u27e8x, hx\u27e9, if h : x \u2208 S\n      then by dsimp only; rw [dif_pos h]\n      else by dsimp only; rw [dif_neg h]; dsimp only; rw [dif_neg h]) } \n\ntheorem mk_union_of_disjiont {\u03b1 : Type u} {S T : set \u03b1} (H : disjoint S T) : mk (S \u222a T : set \u03b1) = mk S + mk T :=\neq.trans (by simp only [(eq_empty_of_subset_empty H : S \u2229 T = \u2205), mk_empty', add_zero]) mk_union_add_mk_inter\n\nend cardinal\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/set_theory/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431001, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.71252991415033}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport data.list.cycle\nimport group_theory.perm.cycle.type\nimport group_theory.perm.list\n\n/-!\n\n# Properties of cyclic permutations constructed from lists/cycles\n\nIn the following, `{\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1]`.\n\n## Main definitions\n\n* `cycle.form_perm`: the cyclic permutation created by looping over a `cycle \u03b1`\n* `equiv.perm.to_list`: the list formed by iterating application of a permutation\n* `equiv.perm.to_cycle`: the cycle formed by iterating application of a permutation\n* `equiv.perm.iso_cycle`: the equivalence between cyclic permutations `f : perm \u03b1`\n  and the terms of `cycle \u03b1` that correspond to them\n* `equiv.perm.iso_cycle'`: the same equivalence as `equiv.perm.iso_cycle`\n  but with evaluation via choosing over fintypes\n* The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)`\n* A `has_repr` instance for any `perm \u03b1`, by representing the `finset` of\n  `cycle \u03b1` that correspond to the cycle factors.\n\n## Main results\n\n* `list.is_cycle_form_perm`: a nontrivial list without duplicates, when interpreted as\n  a permutation, is cyclic\n* `equiv.perm.is_cycle.exists_unique_cycle`: there is only one nontrivial `cycle \u03b1`\n  corresponding to each cyclic `f : perm \u03b1`\n\n## Implementation details\n\nThe forward direction of `equiv.perm.iso_cycle'` uses `fintype.choose` of the uniqueness\nresult, relying on the `fintype` instance of a `cycle.nodup` subtype.\nIt is unclear if this works faster than the `equiv.perm.to_cycle`, which relies\non recursion over `finset.univ`.\nRunning `#eval` on even a simple noncyclic permutation `c[(1 : fin 7), 2, 3] * c[0, 5]`\nto show it takes a long time. TODO: is this because computing the cycle factors is slow?\n\n-/\n\nopen equiv equiv.perm list\n\nvariables {\u03b1 : Type*}\n\nnamespace list\n\nvariables [decidable_eq \u03b1] {l l' : list \u03b1}\n\nlemma form_perm_disjoint_iff (hl : nodup l) (hl' : nodup l')\n  (hn : 2 \u2264 l.length) (hn' : 2 \u2264 l'.length) :\n  perm.disjoint (form_perm l) (form_perm l') \u2194 l.disjoint l' :=\nbegin\n  rw [disjoint_iff_eq_or_eq, list.disjoint],\n  split,\n  { rintro h x hx hx',\n    specialize h x,\n    rw [form_perm_apply_mem_eq_self_iff _ hl _ hx,\n        form_perm_apply_mem_eq_self_iff _ hl' _ hx'] at h,\n    rcases h with hl | hl'; linarith },\n  { intros h x,\n    by_cases hx : x \u2208 l, by_cases hx' : x \u2208 l',\n    { exact (h hx hx').elim },\n    all_goals { have := form_perm_eq_self_of_not_mem _ _ \u2039_\u203a, tauto } }\nend\n\nlemma is_cycle_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) :\n  is_cycle (form_perm l) :=\nbegin\n  cases l with x l,\n  { norm_num at hn },\n  induction l with y l IH generalizing x,\n  { norm_num at hn },\n  { use x,\n    split,\n    { rwa form_perm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _) },\n    { intros w hw,\n      have : w \u2208 (x :: y :: l) := mem_of_form_perm_ne_self _ _ hw,\n      obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem this,\n      use k,\n      simp only [zpow_coe_nat, form_perm_pow_apply_head _ _ hl k, nat.mod_eq_of_lt hk] } }\nend\n\nlemma pairwise_same_cycle_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) :\n  pairwise (l.form_perm.same_cycle) l :=\npairwise.imp_mem.mpr (pairwise_of_forall (\u03bb x y hx hy, (is_cycle_form_perm hl hn).same_cycle\n  ((form_perm_apply_mem_ne_self_iff _ hl _ hx).mpr hn)\n  ((form_perm_apply_mem_ne_self_iff _ hl _ hy).mpr hn)))\n\nlemma cycle_of_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) (x) :\n  cycle_of l.attach.form_perm x = l.attach.form_perm :=\nhave hn : 2 \u2264 l.attach.length := by rwa \u2190 length_attach at hn,\nhave hl : l.attach.nodup := by rwa \u2190 nodup_attach at hl,\n(is_cycle_form_perm hl hn).cycle_of_eq\n  ((form_perm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn)\n\nlemma cycle_type_form_perm (hl : nodup l) (hn : 2 \u2264 l.length) :\n  cycle_type l.attach.form_perm = {l.length} :=\nbegin\n  rw \u2190length_attach at hn,\n  rw \u2190nodup_attach at hl,\n  rw cycle_type_eq [l.attach.form_perm],\n  { simp only [map, function.comp_app],\n    rw [support_form_perm_of_nodup _ hl, card_to_finset, dedup_eq_self.mpr hl],\n    { simp },\n    { intros x h,\n      simpa [h, nat.succ_le_succ_iff] using hn } },\n  { simp },\n  { simpa using is_cycle_form_perm hl hn },\n  { simp }\nend\n\nlemma form_perm_apply_mem_eq_next (hl : nodup l) (x : \u03b1) (hx : x \u2208 l) :\n  form_perm l x = next l x hx :=\nbegin\n  obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx,\n  rw [next_nth_le _ hl, form_perm_apply_nth_le _ hl]\nend\n\nend list\n\nnamespace cycle\n\nvariables [decidable_eq \u03b1] (s s' : cycle \u03b1)\n\n/--\nA cycle `s : cycle \u03b1` , given `nodup s` can be interpreted as a `equiv.perm \u03b1`\nwhere each element in the list is permuted to the next one, defined as `form_perm`.\n-/\ndef form_perm : \u03a0 (s : cycle \u03b1) (h : nodup s), equiv.perm \u03b1 :=\n\u03bb s, quot.hrec_on s (\u03bb l h, form_perm l)\n  (\u03bb l\u2081 l\u2082 (h : l\u2081 ~r l\u2082),\n    begin\n      ext,\n      { exact h.nodup_iff },\n      { intros h\u2081 h\u2082 _,\n        exact heq_of_eq (form_perm_eq_of_is_rotated h\u2081 h) }\n    end)\n\n@[simp] lemma form_perm_coe (l : list \u03b1) (hl : l.nodup) :\n  form_perm (l : cycle \u03b1) hl = l.form_perm := rfl\n\nlemma form_perm_subsingleton (s : cycle \u03b1) (h : subsingleton s) :\n  form_perm s h.nodup = 1 :=\nbegin\n  induction s using quot.induction_on,\n  simp only [form_perm_coe, mk_eq_coe],\n  simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h,\n  cases s with hd tl,\n  { simp },\n  { simp only [length_eq_zero, add_le_iff_nonpos_left, list.length, nonpos_iff_eq_zero] at h,\n    simp [h] }\nend\n\nlemma is_cycle_form_perm (s : cycle \u03b1) (h : nodup s) (hn : nontrivial s) :\n  is_cycle (form_perm s h) :=\nbegin\n  induction s using quot.induction_on,\n  exact list.is_cycle_form_perm h (length_nontrivial hn)\nend\n\nlemma support_form_perm [fintype \u03b1] (s : cycle \u03b1) (h : nodup s) (hn : nontrivial s) :\n  support (form_perm s h) = s.to_finset :=\nbegin\n  induction s using quot.induction_on,\n  refine support_form_perm_of_nodup s h _,\n  rintro _ rfl,\n  simpa [nat.succ_le_succ_iff] using length_nontrivial hn\nend\n\nlemma form_perm_eq_self_of_not_mem (s : cycle \u03b1) (h : nodup s) (x : \u03b1) (hx : x \u2209 s) :\n  form_perm s h x = x :=\nbegin\n  induction s using quot.induction_on,\n  simpa using list.form_perm_eq_self_of_not_mem _ _ hx\nend\n\nlemma form_perm_apply_mem_eq_next (s : cycle \u03b1) (h : nodup s) (x : \u03b1) (hx : x \u2208 s) :\n  form_perm s h x = next s h x hx :=\nbegin\n  induction s using quot.induction_on,\n  simpa using list.form_perm_apply_mem_eq_next h _ _\nend\n\nlemma form_perm_reverse (s : cycle \u03b1) (h : nodup s) :\n  form_perm s.reverse (nodup_reverse_iff.mpr h) = (form_perm s h)\u207b\u00b9 :=\nbegin\n  induction s using quot.induction_on,\n  simpa using form_perm_reverse _ h\nend\n\nlemma form_perm_eq_form_perm_iff {\u03b1 : Type*} [decidable_eq \u03b1]\n  {s s' : cycle \u03b1} {hs : s.nodup} {hs' : s'.nodup} :\n  s.form_perm hs = s'.form_perm hs' \u2194 s = s' \u2228 s.subsingleton \u2227 s'.subsingleton :=\nbegin\n  rw [cycle.length_subsingleton_iff, cycle.length_subsingleton_iff],\n  revert s s',\n  intros s s',\n  apply quotient.induction_on\u2082' s s',\n  intros l l',\n  simpa using form_perm_eq_form_perm_iff\nend\n\nend cycle\n\nnamespace equiv.perm\nsection fintype\nvariables [fintype \u03b1] [decidable_eq \u03b1] (p : equiv.perm \u03b1) (x : \u03b1)\n\n/--\n`equiv.perm.to_list (f : perm \u03b1) (x : \u03b1)` generates the list `[x, f x, f (f x), ...]`\nuntil looping. That means when `f x = x`, `to_list f x = []`.\n-/\ndef to_list : list \u03b1 :=\n(list.range (cycle_of p x).support.card).map (\u03bb k, (p ^ k) x)\n\n@[simp] lemma to_list_one : to_list (1 : perm \u03b1) x = [] :=\nby simp [to_list, cycle_of_one]\n\n@[simp] lemma to_list_eq_nil_iff {p : perm \u03b1} {x} : to_list p x = [] \u2194 x \u2209 p.support :=\nby simp [to_list]\n\n@[simp] lemma length_to_list : length (to_list p x) = (cycle_of p x).support.card :=\nby simp [to_list]\n\nlemma to_list_ne_singleton (y : \u03b1) : to_list p x \u2260 [y] :=\nbegin\n  intro H,\n  simpa [card_support_ne_one] using congr_arg length H\nend\n\nlemma two_le_length_to_list_iff_mem_support {p : perm \u03b1} {x : \u03b1} :\n  2 \u2264 length (to_list p x) \u2194 x \u2208 p.support :=\nby simp\n\nlemma length_to_list_pos_of_mem_support (h : x \u2208 p.support) : 0 < length (to_list p x) :=\nzero_lt_two.trans_le (two_le_length_to_list_iff_mem_support.mpr h)\n\nlemma nth_le_to_list (n : \u2115) (hn : n < length (to_list p x)) :\n  nth_le (to_list p x) n hn = (p ^ n) x :=\nby simp [to_list]\n\nlemma to_list_nth_le_zero (h : x \u2208 p.support) :\n  (to_list p x).nth_le 0 (length_to_list_pos_of_mem_support _ _ h) = x :=\nby simp [to_list]\n\nvariables {p} {x}\n\nlemma mem_to_list_iff {y : \u03b1} :\n  y \u2208 to_list p x \u2194 same_cycle p x y \u2227 x \u2208 p.support :=\nbegin\n  simp only [to_list, mem_range, mem_map],\n  split,\n  { rintro \u27e8n, hx, rfl\u27e9,\n    refine \u27e8\u27e8n, rfl\u27e9, _\u27e9,\n    contrapose! hx,\n    rw \u2190support_cycle_of_eq_nil_iff at hx,\n    simp [hx] },\n  { rintro \u27e8h, hx\u27e9,\n    simpa using h.exists_pow_eq_of_mem_support hx }\nend\n\nlemma nodup_to_list (p : perm \u03b1) (x : \u03b1) :\n  nodup (to_list p x) :=\nbegin\n  by_cases hx : p x = x,\n  { rw [\u2190not_mem_support, \u2190to_list_eq_nil_iff] at hx,\n    simp [hx] },\n  have hc : is_cycle (cycle_of p x) := is_cycle_cycle_of p hx,\n  rw nodup_iff_nth_le_inj,\n  rintros n m hn hm,\n  rw [length_to_list, \u2190hc.order_of] at hm hn,\n  rw [\u2190cycle_of_apply_self, \u2190ne.def, \u2190mem_support] at hx,\n  rw [nth_le_to_list, nth_le_to_list,\n      \u2190cycle_of_pow_apply_self p x n, \u2190cycle_of_pow_apply_self p x m],\n  cases n; cases m,\n  { simp },\n  { rw [\u2190hc.support_pow_of_pos_of_lt_order_of m.zero_lt_succ hm,\n        mem_support, cycle_of_pow_apply_self] at hx,\n    simp [hx.symm] },\n  { rw [\u2190hc.support_pow_of_pos_of_lt_order_of n.zero_lt_succ hn,\n        mem_support, cycle_of_pow_apply_self] at hx,\n    simp [hx] },\n  intro h,\n  have hn' : \u00ac order_of (p.cycle_of x) \u2223 n.succ := nat.not_dvd_of_pos_of_lt n.zero_lt_succ hn,\n  have hm' : \u00ac order_of (p.cycle_of x) \u2223 m.succ := nat.not_dvd_of_pos_of_lt m.zero_lt_succ hm,\n  rw \u2190hc.support_pow_eq_iff at hn' hm',\n  rw [\u2190nat.mod_eq_of_lt hn, \u2190nat.mod_eq_of_lt hm, \u2190pow_inj_mod],\n  refine support_congr _ _,\n  { rw [hm', hn'],\n    exact finset.subset.refl _ },\n  { rw hm',\n    intros y hy,\n    obtain \u27e8k, rfl\u27e9 := hc.exists_pow_eq (mem_support.mp hx) (mem_support.mp hy),\n    rw [\u2190mul_apply, (commute.pow_pow_self _ _ _).eq, mul_apply, h, \u2190mul_apply, \u2190mul_apply,\n        (commute.pow_pow_self _ _ _).eq] }\nend\n\nlemma next_to_list_eq_apply (p : perm \u03b1) (x y : \u03b1) (hy : y \u2208 to_list p x) :\n  next (to_list p x) y hy = p y :=\nbegin\n  rw mem_to_list_iff at hy,\n  obtain \u27e8k, hk, hk'\u27e9 := hy.left.exists_pow_eq_of_mem_support hy.right,\n  rw \u2190nth_le_to_list p x k (by simpa using hk) at hk',\n  simp_rw \u2190hk',\n  rw [next_nth_le _ (nodup_to_list _ _), nth_le_to_list, nth_le_to_list, \u2190mul_apply, \u2190pow_succ,\n      length_to_list, pow_apply_eq_pow_mod_order_of_cycle_of_apply p (k + 1), is_cycle.order_of],\n  exact is_cycle_cycle_of _ (mem_support.mp hy.right)\nend\n\nlemma to_list_pow_apply_eq_rotate (p : perm \u03b1) (x : \u03b1) (k : \u2115) :\n  p.to_list ((p ^ k) x) = (p.to_list x).rotate k :=\nbegin\n  apply ext_le,\n  { simp only [length_to_list, cycle_of_self_apply_pow, length_rotate]},\n  { intros n hn hn',\n    rw [nth_le_to_list, nth_le_rotate, nth_le_to_list, length_to_list,\n        pow_mod_card_support_cycle_of_self_apply, pow_add, mul_apply] }\nend\n\nlemma same_cycle.to_list_is_rotated {f : perm \u03b1} {x y : \u03b1} (h : same_cycle f x y) :\n  to_list f x ~r to_list f y :=\nbegin\n  by_cases hx : x \u2208 f.support,\n  { obtain \u27e8_ | k, hk, hy\u27e9 := h.exists_pow_eq_of_mem_support hx,\n    { simp only [coe_one, id.def, pow_zero] at hy,\n      simp [hy] },\n    use k.succ,\n    rw [\u2190to_list_pow_apply_eq_rotate, hy] },\n  { rw [to_list_eq_nil_iff.mpr hx, is_rotated_nil_iff', eq_comm, to_list_eq_nil_iff],\n    rwa \u2190h.mem_support_iff }\nend\n\nlemma pow_apply_mem_to_list_iff_mem_support {n : \u2115} :\n  (p ^ n) x \u2208 p.to_list x \u2194 x \u2208 p.support :=\nbegin\n  rw [mem_to_list_iff, and_iff_right_iff_imp],\n  refine \u03bb _, same_cycle.symm _,\n  rw same_cycle_pow_left\nend\n\nlemma to_list_form_perm_nil (x : \u03b1) :\n  to_list (form_perm ([] : list \u03b1)) x = [] :=\nby simp\n\nlemma to_list_form_perm_singleton (x y : \u03b1) :\n  to_list (form_perm [x]) y = [] :=\nby simp\n\nlemma to_list_form_perm_nontrivial (l : list \u03b1) (hl : 2 \u2264 l.length) (hn : nodup l) :\n  to_list (form_perm l) (l.nth_le 0 (zero_lt_two.trans_le hl)) = l :=\nbegin\n  have hc : l.form_perm.is_cycle := list.is_cycle_form_perm hn hl,\n  have hs : l.form_perm.support = l.to_finset,\n  { refine support_form_perm_of_nodup _ hn _,\n    rintro _ rfl,\n    simpa [nat.succ_le_succ_iff] using hl },\n  rw [to_list, hc.cycle_of_eq (mem_support.mp _), hs, card_to_finset, dedup_eq_self.mpr hn],\n  { refine list.ext_le (by simp) (\u03bb k hk hk', _),\n    simp [form_perm_pow_apply_nth_le _ hn, nat.mod_eq_of_lt hk'] },\n  { simpa [hs] using nth_le_mem _ _ _ }\nend\n\nlemma to_list_form_perm_is_rotated_self (l : list \u03b1) (hl : 2 \u2264 l.length) (hn : nodup l)\n  (x : \u03b1) (hx : x \u2208 l):\n  to_list (form_perm l) x ~r l :=\nbegin\n  obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx,\n  have hr : l ~r l.rotate k := \u27e8k, rfl\u27e9,\n  rw form_perm_eq_of_is_rotated hn hr,\n  rw \u2190nth_le_rotate' l k k,\n  simp only [nat.mod_eq_of_lt hk, tsub_add_cancel_of_le hk.le, nat.mod_self],\n  rw [to_list_form_perm_nontrivial],\n  { simp },\n  { simpa using hl },\n  { simpa using hn }\nend\n\nlemma form_perm_to_list (f : perm \u03b1) (x : \u03b1) :\n  form_perm (to_list f x) = f.cycle_of x :=\nbegin\n  by_cases hx : f x = x,\n  { rw [(cycle_of_eq_one_iff f).mpr hx, to_list_eq_nil_iff.mpr (not_mem_support.mpr hx),\n        form_perm_nil] },\n  ext y,\n  by_cases hy : same_cycle f x y,\n  { obtain \u27e8k, hk, rfl\u27e9 := hy.exists_pow_eq_of_mem_support (mem_support.mpr hx),\n    rw [cycle_of_apply_apply_pow_self, list.form_perm_apply_mem_eq_next (nodup_to_list f x),\n        next_to_list_eq_apply, pow_succ, mul_apply],\n    rw mem_to_list_iff,\n    exact \u27e8\u27e8k, rfl\u27e9, mem_support.mpr hx\u27e9 },\n  { rw [cycle_of_apply_of_not_same_cycle hy, form_perm_apply_of_not_mem],\n    simp [mem_to_list_iff, hy] }\nend\n\n/--\nGiven a cyclic `f : perm \u03b1`, generate the `cycle \u03b1` in the order\nof application of `f`. Implemented by finding an element `x : \u03b1`\nin the support of `f` in `finset.univ`, and iterating on using\n`equiv.perm.to_list f x`.\n-/\ndef to_cycle (f : perm \u03b1) (hf : is_cycle f) : cycle \u03b1 :=\nmultiset.rec_on (finset.univ : finset \u03b1).val\n  (quot.mk _ [])\n  (\u03bb x s l, if f x = x then l else to_list f x)\n  (by { intros x y m s,\n    refine heq_of_eq _,\n    split_ifs with hx hy hy; try { refl },\n    { have hc : same_cycle f x y := is_cycle.same_cycle hf hx hy,\n      exact quotient.sound' hc.to_list_is_rotated }})\n\nlemma to_cycle_eq_to_list (f : perm \u03b1) (hf : is_cycle f) (x : \u03b1) (hx : f x \u2260 x) :\n  to_cycle f hf = to_list f x :=\nbegin\n  have key : (finset.univ : finset \u03b1).val = x ::\u2098 finset.univ.val.erase x,\n  { simp },\n  rw [to_cycle, key],\n  simp [hx]\nend\n\nlemma nodup_to_cycle (f : perm \u03b1) (hf : is_cycle f) : (to_cycle f hf).nodup :=\nbegin\n  obtain \u27e8x, hx, -\u27e9 := id hf,\n  simpa [to_cycle_eq_to_list f hf x hx] using nodup_to_list _ _\nend\n\nlemma nontrivial_to_cycle (f : perm \u03b1) (hf : is_cycle f) : (to_cycle f hf).nontrivial :=\nbegin\n  obtain \u27e8x, hx, -\u27e9 := id hf,\n  simp [to_cycle_eq_to_list f hf x hx, hx, cycle.nontrivial_coe_nodup_iff (nodup_to_list _ _)]\nend\n\n/--\nAny cyclic `f : perm \u03b1` is isomorphic to the nontrivial `cycle \u03b1`\nthat corresponds to repeated application of `f`.\nThe forward direction is implemented by `equiv.perm.to_cycle`.\n-/\ndef iso_cycle : {f : perm \u03b1 // is_cycle f} \u2243 {s : cycle \u03b1 // s.nodup \u2227 s.nontrivial} :=\n{ to_fun := \u03bb f, \u27e8to_cycle (f : perm \u03b1) f.prop, nodup_to_cycle f f.prop,\n    nontrivial_to_cycle _ f.prop\u27e9,\n  inv_fun := \u03bb s, \u27e8(s : cycle \u03b1).form_perm s.prop.left,\n    (s : cycle \u03b1).is_cycle_form_perm _ s.prop.right\u27e9,\n  left_inv := \u03bb f, by\n  { obtain \u27e8x, hx, -\u27e9 := id f.prop,\n    simpa [to_cycle_eq_to_list (f : perm \u03b1) f.prop x hx, form_perm_to_list, subtype.ext_iff]\n      using f.prop.cycle_of_eq hx },\n  right_inv := \u03bb s, by\n  { rcases s with \u27e8\u27e8s\u27e9, hn, ht\u27e9,\n    obtain \u27e8x, -, -, hx, -\u27e9 := id ht,\n    have hl : 2 \u2264 s.length := by simpa using cycle.length_nontrivial ht,\n    simp only [cycle.mk_eq_coe, cycle.nodup_coe_iff, cycle.mem_coe_iff, subtype.coe_mk,\n               cycle.form_perm_coe] at hn hx \u22a2,\n    rw to_cycle_eq_to_list _ _ x,\n    { refine quotient.sound' _,\n      exact to_list_form_perm_is_rotated_self _ hl hn _ hx },\n    { rw [\u2190mem_support, support_form_perm_of_nodup _ hn],\n      { simpa using hx },\n      { rintro _ rfl,\n        simpa [nat.succ_le_succ_iff] using hl } } } }\n\nend fintype\n\nsection finite\nvariables [finite \u03b1] [decidable_eq \u03b1]\n\nlemma is_cycle.exists_unique_cycle {f : perm \u03b1} (hf : is_cycle f) :\n  \u2203! (s : cycle \u03b1), \u2203 (h : s.nodup), s.form_perm h = f :=\nbegin\n  casesI nonempty_fintype \u03b1,\n  obtain \u27e8x, hx, hy\u27e9 := id hf,\n  refine \u27e8f.to_list x, \u27e8nodup_to_list f x, _\u27e9, _\u27e9,\n  { simp [form_perm_to_list, hf.cycle_of_eq hx] },\n  { rintro \u27e8l\u27e9 \u27e8hn, rfl\u27e9,\n    simp only [cycle.mk_eq_coe, cycle.coe_eq_coe, subtype.coe_mk, cycle.form_perm_coe],\n    refine (to_list_form_perm_is_rotated_self _ _ hn _ _).symm,\n    { contrapose! hx,\n      suffices : form_perm l = 1,\n      { simp [this] },\n      rw form_perm_eq_one_iff _ hn,\n      exact nat.le_of_lt_succ hx },\n    { rw \u2190mem_to_finset,\n      refine support_form_perm_le l _,\n      simpa using hx } }\nend\n\nlemma is_cycle.exists_unique_cycle_subtype {f : perm \u03b1} (hf : is_cycle f) :\n  \u2203! (s : {s : cycle \u03b1 // s.nodup}), (s : cycle \u03b1).form_perm s.prop = f :=\nbegin\n  obtain \u27e8s, \u27e8hs, rfl\u27e9, hs'\u27e9 := hf.exists_unique_cycle,\n  refine \u27e8\u27e8s, hs\u27e9, rfl, _\u27e9,\n  rintro \u27e8t, ht\u27e9 ht',\n  simpa using hs' _ \u27e8ht, ht'\u27e9\nend\n\nlemma is_cycle.exists_unique_cycle_nontrivial_subtype {f : perm \u03b1} (hf : is_cycle f) :\n  \u2203! (s : {s : cycle \u03b1 // s.nodup \u2227 s.nontrivial}), (s : cycle \u03b1).form_perm s.prop.left = f :=\nbegin\n  obtain \u27e8\u27e8s, hn\u27e9, hs, hs'\u27e9 := hf.exists_unique_cycle_subtype,\n  refine \u27e8\u27e8s, hn, _\u27e9, _, _\u27e9,\n  { rw hn.nontrivial_iff,\n    subst f,\n    intro H,\n    refine hf.ne_one _,\n    simpa using cycle.form_perm_subsingleton _ H },\n  { simpa using hs },\n  { rintro \u27e8t, ht, ht'\u27e9 ht'',\n    simpa using hs' \u27e8t, ht\u27e9 ht'' }\nend\n\nend finite\n\nvariables [fintype \u03b1] [decidable_eq \u03b1]\n\n/--\nAny cyclic `f : perm \u03b1` is isomorphic to the nontrivial `cycle \u03b1`\nthat corresponds to repeated application of `f`.\nThe forward direction is implemented by finding this `cycle \u03b1` using `fintype.choose`.\n-/\ndef iso_cycle' : {f : perm \u03b1 // is_cycle f} \u2243 {s : cycle \u03b1 // s.nodup \u2227 s.nontrivial} :=\n{ to_fun := \u03bb f, fintype.choose _ f.prop.exists_unique_cycle_nontrivial_subtype,\n  inv_fun := \u03bb s, \u27e8(s : cycle \u03b1).form_perm s.prop.left,\n    (s : cycle \u03b1).is_cycle_form_perm _ s.prop.right\u27e9,\n  left_inv := \u03bb f, by simpa [subtype.ext_iff]\n    using fintype.choose_spec _ f.prop.exists_unique_cycle_nontrivial_subtype,\n  right_inv := \u03bb \u27e8s, hs, ht\u27e9, by\n  { simp [subtype.coe_mk],\n    convert fintype.choose_subtype_eq (\u03bb (s' : cycle \u03b1), s'.nodup \u2227 s'.nontrivial) _,\n    ext \u27e8s', hs', ht'\u27e9,\n    simp [cycle.form_perm_eq_form_perm_iff, (iff_not_comm.mp hs.nontrivial_iff),\n          (iff_not_comm.mp hs'.nontrivial_iff), ht] } }\n\nnotation `c[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) :=\n  cycle.form_perm \u2191l (cycle.nodup_coe_iff.mpr dec_trivial)\n\nmeta instance repr_perm [has_repr \u03b1] : has_repr (perm \u03b1) :=\n\u27e8\u03bb f, repr (multiset.pmap (\u03bb (g : perm \u03b1) (hg : g.is_cycle),\n  iso_cycle \u27e8g, hg\u27e9) -- to_cycle is faster?\n  (perm.cycle_factors_finset f).val\n  (\u03bb g hg, (mem_cycle_factors_finset_iff.mp (finset.mem_def.mpr hg)).left))\u27e9\n\nend equiv.perm\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/perm/cycle/concrete.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7125299110299264}}
{"text": "import tactic\nimport data.real.basic data.int.basic init.data.int.basic\nimport data.complex.exponential\nimport analysis.special_functions.trigonometric\n\n\n-- sinm imports\n import wonky_sq.basic wonky_sq.addition_formulae \n\n/-!\nHere we are going to prove periodicity lemma's like sinm(2\u03c0) = 0 or even \nsinm(x\u2213\u03c0) = -sin(x) and so on. Makng sure we know the periodicity of the \nfunctions we defined in the previous section.\n-/\n\nopen real\n\n/- 012\nFirst let us prove that sinm \u03c0 = 0 \n-/\nlemma sinm_pi (m : \u211d) : sinm pi m = 0 :=\nbegin\n  unfold sinm,\n  rw [sin_pi, zero_mul],\nend\n -- We need some half pi lemmas to prove the zero for cosm\n\n/- 013 -/\nlemma cos_half_pi : cos (pi/2) = 0 := by simp\n\n/- 014 -/\nlemma sin_half_pi : sin (pi/2) = 1 := by simp\n\n/- 015\nNow let's prove the cosm_halfpi lemma, it is much the same as the sim_pi above\n-/\nlemma cosm_halfpi (m : \u211d) (H: m \u2260 0): cosm (pi/2) m = 0 :=\nbegin\n  unfold cosm,\n  rw cos_half_pi,\n  simp only [zero_mul],\nend\n\n/- 016\nmathlib doen't seem to have a sin_2pi function so I created it for the next \n lemma  CORRECTION: I DIDN'T HAVE THE RIGHT IMPORTS\n -/\nlemma sin_2pi : sin (2*pi) = 0 :=\nbegin \n  simp,\nend\n\n/- 017\nNow for the second case of the cosm, but first let us prove it for cos\n-/\nlemma cos_3on2pi : cos (3 *pi / 2) = 0 :=\nbegin\n  have H : pi + pi/2 = 3 * pi/2,\n  {ring},\n  {   rw \u2190H,\n      rw cos_add,\n      simp}\nend\n\n/- 018\n Now we can prove the above result for our general sine\n -/\nlemma sinm_2pi (m : \u211d) : sinm (2 * pi) m = 0 :=\nbegin\n  unfold sinm,\n  -- I could at this point use simp, but I thought this was nicer and neater\n  rw [sin_2pi, zero_mul],\nend\n\n/- 019\n Proving that cos\u2098 function is zero at 3\u03c0/2\n-/\nlemma cosm_3on2pi (m : \u211d) : cosm (3 * pi / 2) m = 0 :=\nbegin \n  unfold cosm,\n  rw [cos_3on2pi, zero_mul]\nend\n\n/- 020\n We are now going to prove that for the naturals that sin(n*\u03c0)=0. I am aware this in mathlib\n-/\nlemma sin_npi_nat (n : \u2115) : sin (n * pi) = 0 :=\nbegin \n  induction n with d hd,\n  { simp },\n  { simp only [nat.cast_succ],\n    rw [add_mul,sin_add],\n    simp [hd] },\nend\n\n/- 021\n Now for sin\u2098 where n is an integer\n-/\nlemma sinm_npi (m : \u211d) (n : \u2124) : sinm (n * pi) m = 0 :=\nbegin\n  unfold sinm,\n  rw [sin_int_mul_pi, zero_mul]\nend\n\n/- 022\n I got annoyed that you couldn't just say that (a + b) / c = a/c + b/c so I proved it. \n-/\nlemma div_distrib (a b c : \u211d) (c \u2260 0) : (a + b) / c = a/c + b/c :=\nbegin\n  ring,\nend\n\n/- 034\n Just something I forgot I needed\n-/\n\nlemma sinm_halfpi (x m : \u211d) (H : m \u2260 0): sinm (pi/2) m = 1 :=\nbegin\n  unfold sinm,\n  unfold radius,\n  rw [sin_half_pi,cos_half_pi],\n  norm_num,\n  rw zero_rpow H,\n  norm_num,\nend\n\n/- 023\n Now to prove that that cos ((2n + 1)\u03c0/2) = 0 \u2200 n \u2208 \u2115\n-/\nlemma cos_nat_pi_half (n : \u2115) (H : n \u2260 0) : cos ((2 * n + 1) * pi / 2) = 0 :=\nbegin\n  induction n with d hd,\n  { simp },\n  -- It goes downhill from here!\n  { simp only [nat.cast_succ],\n    rw [add_mul],\n    have H : (2 * (\u2191d + 1) * pi + 1 * pi) / 2 = (\u2191d + 1) * pi + pi/2,\n    {ring,},\n    rw [H, cos_add, cos_half_pi, sin_half_pi, mul_zero],\n    norm_num,\n    rw add_mul, norm_num,\n    rw sin_add, simp only [add_zero, mul_one, sin_pi, cos_pi, mul_neg_eq_neg_mul_symm, neg_eq_zero, mul_zero], -- this is messy and I dislike it\n    rw \u2190sin_nat_mul_pi,\n   }\nend\n\n/- 024\n Now to prove the above for the integers. It is a lot cleaner.\n-/\nlemma cos_npi_half (n : \u2124) (H : n \u2260 0) : cos (((2 * n + 1) * pi )/ 2) = 0 :=\nbegin\n  rw add_mul,\n  have H : (2 * \u2191n * pi + 1 * pi) / 2 = \u2191n * pi + pi/2,\n    {ring,},\n  rw [H, cos_add, cos_half_pi, sin_half_pi, mul_zero, mul_one],\n  simp [sin_int_mul_pi],\nend\n\n/- 025 \nThe generalised for, so \u2200 n \u2260 0, cos\u2098 (2n+1)\u03c0/2 = 0\n-/\nlemma cosm_npi_half (n : \u2124) (H : n \u2260 0) (m : \u211d) : cosm ((2 *n + 1) * pi / 2) m = 0 :=\nbegin\n  unfold cosm,\n  rw [cos_npi_half n, zero_mul],\n  exact H,\nend\n\n/- We are now going to prove some things relating to taking a result \u00b1\u03c0 -/\n\n/- 026 \nFirst up is normal sin! (Again this is probably in mathlib somewhere but I couldn't find it)\n-/\nlemma sin_selfsim (x : \u211d) : sin(pi - x) = sin(x) :=\nbegin\n  rw sin_sub,\n  simp,\nend\n\n/- 027\n Now for general cosine (\")\n-/\nlemma cos_selfsim (x : \u211d) : cos (pi - x) = -cos x :=\nbegin\n  rw cos_sub,\n  simp,\nend\n\n/- 028\n Finally to something interesting! We get to do the generalised sine version of 026\n-/\n\nlemma sinm_selfsim (x m : \u211d) : sinm (pi - x) m = sinm x m :=\nbegin\n  unfold sinm,\n  rw sin_selfsim,\n  unfold radius,\n  rw [sin_selfsim, cos_selfsim],\n  simp,\nend\n/- 029\n and the same as 028 but for cos\u2098\n-/\nlemma cosm_selfsim (x m : \u211d) : cosm(pi - x) m = -cosm x m :=\nbegin \n  unfold cosm,\n  rw cos_selfsim,\n  unfold radius, \n  rw [sin_selfsim, cos_selfsim],\n  simp,\nend\n\n-- I may rearrange these wrt whether they are sin, cos, sin\u2098, cos\u2098 etc.\n\n/- 030\nLets now prove that sin\u2098 (x + \u03c0/2) = cos\u2098 x \n-/\nlemma sinm_plus_half_pi_eq_cosm ( x m : \u211d) (h : m \u2260 0): sinm (x + pi/2) m = cosm x m :=\nbegin\n  -- want addition formula first\n  rw sinm_add x (pi/2) m;\n  rw [cos_half_pi, mul_zero, sin_half_pi],\n  norm_num,\n  rw add_comm,\nend\n\n/- 034\n\n-/\n\n\nlemma sinm_plus_half_pi_eq_negsinm ( x m : \u211d) (h : m \u2260 0) : cosm (x + pi/2) m = - sinm x m :=\nbegin\n  rw [cosm_add, cos_half_pi, sin_half_pi, mul_zero, mul_zero, mul_one, zero_sub, zero_add, mul_one],\n  rw abs_neg,\n  unfold sinm,\n  unfold radius,\n  ring,\nend\n\n/- 035.0\n\n-/\n\nlemma sinm_self_sim_pos (x m : \u211d) : sinm (x + pi) m = - sinm x m :=\nbegin\n  rw sinm_add,\n  rw [cos_pi, sin_pi, mul_comm, neg_one_mul, mul_zero, add_zero, mul_zero, sub_zero, mul_comm, neg_one_mul],\n  repeat {rw[abs_neg]},\n  apply neg_inj,\n  rw [neg_neg, neg_div, neg_neg, sinm_unfolded],\nend\n\n/- 35.5\n\n-/\n\nlemma sinm_self_sim_neg (x m : \u211d) : sinm (x - pi) m = - sinm x m :=\nbegin\n  rw sinm_sub,\n  rw [sin_pi, cos_pi, mul_neg_eq_neg_mul_symm, mul_zero, mul_one],\n  norm_num,\n  apply neg_inj,\n  rw [neg_neg, neg_div, neg_neg,inv_eq_one_div],\nend\n\n/- 040\n\n-/\n\nlemma cosm_self_sim_neg (x m : \u211d) : cosm (x - pi) m = - cosm x m :=\nbegin\n  rw cosm_sub,\n  rw [sin_pi, cos_pi, mul_neg_eq_neg_mul_symm, mul_zero, mul_one],\n  norm_num,\n  apply neg_inj,\n  rw [neg_neg, neg_div, neg_neg,inv_eq_one_div],\nend\n\n/- 041\n\n-/\n\nlemma cosm_self_sim_pos (x m : \u211d) : cosm (x + pi) m = - cosm x m :=\nbegin\n  rw cosm_add,\n  rw [sin_pi, cos_pi, mul_neg_eq_neg_mul_symm, mul_zero, mul_one],\n  norm_num,\n  apply neg_inj,\n  rw [neg_neg, neg_div, neg_neg,inv_eq_one_div],\nend\n", "meta": {"author": "jamesa9283", "repo": "Generalised-Trigonometric-Functions-for-Lean", "sha": "33775fb8286eacfc17397fe41af9d446cbdd78f3", "save_path": "github-repos/lean/jamesa9283-Generalised-Trigonometric-Functions-for-Lean", "path": "github-repos/lean/jamesa9283-Generalised-Trigonometric-Functions-for-Lean/Generalised-Trigonometric-Functions-for-Lean-33775fb8286eacfc17397fe41af9d446cbdd78f3/src/wonky_sq/periodicity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7125299072095105}}
{"text": "/-\nCopyright (c) 2018 Andreas Swerdlow. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Andreas Swerdlow, Kexing Ying\n-/\n\nimport linear_algebra.matrix\nimport linear_algebra.tensor_product\nimport linear_algebra.nonsingular_inverse\n\n/-!\n# Bilinear form\n\nThis file defines a bilinear form over a module. Basic ideas\nsuch as orthogonality are also introduced, as well as reflexivive,\nsymmetric, non-degenerate and alternating bilinear forms. Adjoints of\nlinear maps with respect to a bilinear form are also introduced.\n\nA bilinear form on an R-(semi)module M, is a function from M x M to R,\nthat is linear in both arguments. Comments will typically abbreviate\n\"(semi)module\" as just \"module\", but the definitions should be as general as\npossible.\n\nThe result that there exists an orthogonal basis with respect to a symmetric,\nnondegenerate bilinear form can be found in `quadratic_form.lean` with\n`exists_orthogonal_basis`.\n\n## Notations\n\nGiven any term B of type bilin_form, due to a coercion, can use\nthe notation B x y to refer to the function field, ie. B x y = B.bilin x y.\n\nIn this file we use the following type variables:\n - `M`, `M'`, ... are modules over the semiring `R`,\n - `M\u2081`, `M\u2081'`, ... are modules over the ring `R\u2081`,\n - `M\u2082`, `M\u2082'`, ... are modules over the commutative semiring `R\u2082`,\n - `M\u2083`, `M\u2083'`, ... are modules over the commutative ring `R\u2083`,\n - `V`, ... is a vector space over the field `K`.\n\n## References\n\n* <https://en.wikipedia.org/wiki/Bilinear_form>\n\n## Tags\n\nBilinear form,\n-/\n\nopen_locale big_operators\n\nuniverses u v w\n\n/-- `bilin_form R M` is the type of `R`-bilinear functions `M \u2192 M \u2192 R`. -/\nstructure bilin_form (R : Type*) (M : Type*) [semiring R] [add_comm_monoid M] [module R M] :=\n(bilin : M \u2192 M \u2192 R)\n(bilin_add_left : \u2200 (x y z : M), bilin (x + y) z = bilin x z + bilin y z)\n(bilin_smul_left : \u2200 (a : R) (x y : M), bilin (a \u2022 x) y = a * (bilin x y))\n(bilin_add_right : \u2200 (x y z : M), bilin x (y + z) = bilin x y + bilin x z)\n(bilin_smul_right : \u2200 (a : R) (x y : M), bilin x (a \u2022 y) = a * (bilin x y))\n\nvariables {R : Type*} {M : Type*} [semiring R] [add_comm_monoid M] [module R M]\nvariables {R\u2081 : Type*} {M\u2081 : Type*} [ring R\u2081] [add_comm_group M\u2081] [module R\u2081 M\u2081]\nvariables {R\u2082 : Type*} {M\u2082 : Type*} [comm_semiring R\u2082] [add_comm_monoid M\u2082] [module R\u2082 M\u2082]\nvariables {R\u2083 : Type*} {M\u2083 : Type*} [comm_ring R\u2083] [add_comm_group M\u2083] [module R\u2083 M\u2083]\nvariables {V : Type*} {K : Type*} [field K] [add_comm_group V] [module K V]\nvariables {B : bilin_form R M} {B\u2081 : bilin_form R\u2081 M\u2081} {B\u2082 : bilin_form R\u2082 M\u2082}\n\nnamespace bilin_form\n\ninstance : has_coe_to_fun (bilin_form R M) :=\n\u27e8_, \u03bb B, B.bilin\u27e9\n\ninitialize_simps_projections bilin_form (bilin -> apply)\n\n@[simp] lemma coe_fn_mk (f : M \u2192 M \u2192 R) (h\u2081 h\u2082 h\u2083 h\u2084) :\n  (bilin_form.mk f h\u2081 h\u2082 h\u2083 h\u2084 : M \u2192 M \u2192 R) = f :=\nrfl\n\nlemma coe_fn_congr : \u03a0 {x x' y y' : M}, x = x' \u2192 y = y' \u2192 B x y = B x' y'\n| _ _ _ _ rfl rfl := rfl\n\n@[simp]\nlemma add_left (x y z : M) : B (x + y) z = B x z + B y z := bilin_add_left B x y z\n\n@[simp]\nlemma smul_left (a : R) (x y : M) : B (a \u2022 x) y = a * (B x y) := bilin_smul_left B a x y\n\n@[simp]\nlemma add_right (x y z : M) : B x (y + z) = B x y + B x z := bilin_add_right B x y z\n\n@[simp]\nlemma smul_right (a : R) (x y : M) : B x (a \u2022 y) = a * (B x y) := bilin_smul_right B a x y\n\n@[simp]\nlemma zero_left (x : M) : B 0 x = 0 :=\nby { rw [\u2190@zero_smul R _ _ _ _ (0 : M), smul_left, zero_mul] }\n\n@[simp]\nlemma zero_right (x : M) : B x 0 = 0 :=\nby rw [\u2190@zero_smul _ _ _ _ _ (0 : M), smul_right, zero_mul]\n\n@[simp]\nlemma neg_left (x y : M\u2081) : B\u2081 (-x) y = -(B\u2081 x y) :=\nby rw [\u2190@neg_one_smul R\u2081 _ _, smul_left, neg_one_mul]\n\n@[simp]\nlemma neg_right (x y : M\u2081) : B\u2081 x (-y) = -(B\u2081 x y) :=\nby rw [\u2190@neg_one_smul R\u2081 _ _, smul_right, neg_one_mul]\n\n@[simp]\nlemma sub_left (x y z : M\u2081) : B\u2081 (x - y) z = B\u2081 x z - B\u2081 y z :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, add_left, neg_left]\n\n@[simp]\nlemma sub_right (x y z : M\u2081) : B\u2081 x (y - z) = B\u2081 x y - B\u2081 x z :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, add_right, neg_right]\n\nvariable {D : bilin_form R M}\n@[ext] lemma ext (H : \u2200 (x y : M), B x y = D x y) : B = D :=\nby { cases B, cases D, congr, funext, exact H _ _ }\n\ninstance : add_comm_monoid (bilin_form R M) :=\n{ add := \u03bb B D, { bilin := \u03bb x y, B x y + D x y,\n                  bilin_add_left := \u03bb x y z, by { rw add_left, rw add_left, ac_refl },\n                  bilin_smul_left := \u03bb a x y, by { rw [smul_left, smul_left, mul_add] },\n                  bilin_add_right := \u03bb x y z, by { rw add_right, rw add_right, ac_refl },\n                  bilin_smul_right := \u03bb a x y, by { rw [smul_right, smul_right, mul_add] } },\n  add_assoc := by { intros, ext, unfold bilin coe_fn has_coe_to_fun.coe bilin, rw add_assoc },\n  zero := { bilin := \u03bb x y, 0,\n            bilin_add_left := \u03bb x y z, (add_zero 0).symm,\n            bilin_smul_left := \u03bb a x y, (mul_zero a).symm,\n            bilin_add_right := \u03bb x y z, (zero_add 0).symm,\n            bilin_smul_right := \u03bb a x y, (mul_zero a).symm },\n  zero_add := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_add },\n  add_zero := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_zero },\n  add_comm := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_comm } }\n\ninstance : add_comm_group (bilin_form R\u2081 M\u2081) :=\n{ neg := \u03bb B, { bilin := \u03bb x y, - (B.1 x y),\n                bilin_add_left := \u03bb x y z, by rw [bilin_add_left, neg_add],\n                bilin_smul_left := \u03bb a x y, by rw [bilin_smul_left, mul_neg_eq_neg_mul_symm],\n                bilin_add_right := \u03bb x y z, by rw [bilin_add_right, neg_add],\n                bilin_smul_right := \u03bb a x y, by rw [bilin_smul_right, mul_neg_eq_neg_mul_symm] },\n  add_left_neg := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw neg_add_self },\n  .. bilin_form.add_comm_monoid }\n\n@[simp]\nlemma add_apply (x y : M) : (B + D) x y = B x y + D x y := rfl\n\n@[simp]\nlemma zero_apply (x y : M) : (0 : bilin_form R M) x y = 0 := rfl\n\n@[simp]\nlemma neg_apply (x y : M\u2081) : (-B\u2081) x y = -(B\u2081 x y) := rfl\n\ninstance : inhabited (bilin_form R M) := \u27e80\u27e9\n\nsection\n\n/-- `bilin_form R M` inherits the scalar action from any commutative subalgebra `R\u2082` of `R`.\n\nWhen `R` itself is commutative, this provides an `R`-action via `algebra.id`. -/\ninstance [algebra R\u2082 R] : module R\u2082 (bilin_form R M) :=\n{ smul := \u03bb c B,\n  { bilin := \u03bb x y, c \u2022 B x y,\n    bilin_add_left := \u03bb x y z,\n      by { unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_left, smul_add] },\n    bilin_smul_left := \u03bb a x y, by { unfold coe_fn has_coe_to_fun.coe bilin,\n      rw [bilin_smul_left, \u2190algebra.mul_smul_comm] },\n    bilin_add_right := \u03bb x y z, by { unfold coe_fn has_coe_to_fun.coe bilin,\n      rw [bilin_add_right, smul_add] },\n    bilin_smul_right := \u03bb a x y, by { unfold coe_fn has_coe_to_fun.coe bilin,\n      rw [bilin_smul_right, \u2190algebra.mul_smul_comm] } },\n  smul_add := \u03bb c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw smul_add },\n  add_smul := \u03bb c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_smul },\n  mul_smul := \u03bb a c D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw \u2190smul_assoc, refl },\n  one_smul := \u03bb B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw one_smul },\n  zero_smul := \u03bb B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_smul },\n  smul_zero := \u03bb B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw smul_zero } }\n\n@[simp] lemma smul_apply [algebra R\u2082 R] (B : bilin_form R M) (a : R\u2082) (x y : M) :\n  (a \u2022 B) x y = a \u2022 (B x y) :=\nrfl\n\nend\n\nsection flip\n\nvariables (R\u2082)\n\n/-- Auxiliary construction for the flip of a bilinear form, obtained by exchanging the left and\nright arguments. This version is a `linear_map`; it is later upgraded to a `linear_equiv`\nin `flip_hom`. -/\ndef flip_hom_aux [algebra R\u2082 R] : bilin_form R M \u2192\u2097[R\u2082] bilin_form R M :=\n{ to_fun := \u03bb A,\n  { bilin := \u03bb i j, A j i,\n    bilin_add_left := \u03bb x y z, A.bilin_add_right z x y,\n    bilin_smul_left := \u03bb a x y, A.bilin_smul_right a y x,\n    bilin_add_right := \u03bb x y z, A.bilin_add_left y z x,\n    bilin_smul_right := \u03bb a x y, A.bilin_smul_left a y x },\n  map_add' := \u03bb A\u2081 A\u2082, by { ext, simp } ,\n  map_smul' := \u03bb c A, by { ext, simp } }\n\nvariables {R\u2082}\n\nlemma flip_flip_aux [algebra R\u2082 R] (A : bilin_form R M) :\n  (flip_hom_aux R\u2082) (flip_hom_aux R\u2082 A) = A :=\nby { ext A x y, simp [flip_hom_aux] }\n\nvariables (R\u2082)\n\n/-- The flip of a bilinear form, obtained by exchanging the left and right arguments. This is a\nless structured version of the equiv which applies to general (noncommutative) rings `R` with a\ndistinguished commutative subring `R\u2082`; over a commutative ring use `flip`. -/\ndef flip_hom [algebra R\u2082 R] : bilin_form R M \u2243\u2097[R\u2082] bilin_form R M :=\n{ inv_fun := flip_hom_aux R\u2082,\n  left_inv := flip_flip_aux,\n  right_inv := flip_flip_aux,\n  .. flip_hom_aux R\u2082 }\n\nvariables {R\u2082}\n\n@[simp] lemma flip_apply [algebra R\u2082 R] (A : bilin_form R M) (x y : M) :\n  flip_hom R\u2082 A x y = A y x :=\nrfl\n\nlemma flip_flip [algebra R\u2082 R] :\n  (flip_hom R\u2082).trans (flip_hom R\u2082) = linear_equiv.refl R\u2082 (bilin_form R M) :=\nby { ext A x y, simp }\n\n/-- The flip of a bilinear form over a ring, obtained by exchanging the left and right arguments,\nhere considered as an `\u2115`-linear equivalence, i.e. an additive equivalence. -/\nabbreviation flip' : bilin_form R M \u2243\u2097[\u2115] bilin_form R M := flip_hom \u2115\n\n/-- The `flip` of a bilinear form over a commutative ring, obtained by exchanging the left and\nright arguments. -/\nabbreviation flip : bilin_form R\u2082 M\u2082 \u2243\u2097[R\u2082] bilin_form R\u2082 M\u2082 := flip_hom R\u2082\n\nend flip\n\nsection to_lin'\n\nvariables (R\u2082) [algebra R\u2082 R] [module R\u2082 M] [is_scalar_tower R\u2082 R M]\n\n/-- The linear map obtained from a `bilin_form` by fixing the left co-ordinate and evaluating in\nthe right.\nThis is the most general version of the construction; it is `R\u2082`-linear for some distinguished\ncommutative subsemiring `R\u2082` of the scalar ring.  Over a semiring with no particular distinguished\nsuch subsemiring, use `to_lin'`, which is `\u2115`-linear.  Over a commutative semiring, use `to_lin`,\nwhich is linear. -/\ndef to_lin_hom : bilin_form R M \u2192\u2097[R\u2082] M \u2192\u2097[R\u2082] M \u2192\u2097[R] R :=\n{ to_fun := \u03bb A,\n  { to_fun := \u03bb x,\n    { to_fun := \u03bb y, A x y,\n      map_add' := A.bilin_add_right x,\n      map_smul' := \u03bb c, A.bilin_smul_right c x },\n    map_add' := \u03bb x\u2081 x\u2082, by { ext, simp only [linear_map.coe_mk, linear_map.add_apply, add_left] },\n    map_smul' := \u03bb c x, by { ext, simp only [\u2190 algebra_map_smul R c x, algebra.smul_def,\n                                      linear_map.coe_mk, linear_map.smul_apply, smul_left] } },\n  map_add' := \u03bb A\u2081 A\u2082, by { ext, simp only [linear_map.coe_mk, linear_map.add_apply, add_apply] },\n  map_smul' := \u03bb c A, by { ext, simp only [linear_map.coe_mk, linear_map.smul_apply, smul_apply] } }\n\nvariables {R\u2082}\n\n@[simp] lemma to_lin'_apply (A : bilin_form R M) (x : M) :\n  \u21d1(to_lin_hom R\u2082 A x) = A x :=\nrfl\n\n/-- The linear map obtained from a `bilin_form` by fixing the left co-ordinate and evaluating in\nthe right.\nOver a commutative semiring, use `to_lin`, which is linear rather than `\u2115`-linear. -/\nabbreviation to_lin' : bilin_form R M \u2192\u2097[\u2115] M \u2192\u2097[\u2115] M \u2192\u2097[R] R := to_lin_hom \u2115\n\n@[simp]\nlemma sum_left {\u03b1} (t : finset \u03b1) (g : \u03b1 \u2192 M) (w : M) :\n  B (\u2211 i in t, g i) w = \u2211 i in t, B (g i) w :=\n(bilin_form.to_lin' B).map_sum\u2082 t g w\n\n@[simp]\nlemma sum_right {\u03b1} (t : finset \u03b1) (w : M) (g : \u03b1 \u2192 M) :\n  B w (\u2211 i in t, g i) = \u2211 i in t, B w (g i) :=\n(bilin_form.to_lin' B w).map_sum\n\nvariables (R\u2082)\n\n/-- The linear map obtained from a `bilin_form` by fixing the right co-ordinate and evaluating in\nthe left.\nThis is the most general version of the construction; it is `R\u2082`-linear for some distinguished\ncommutative subsemiring `R\u2082` of the scalar ring.  Over semiring with no particular distinguished\nsuch subsemiring, use `to_lin'_flip`, which is `\u2115`-linear.  Over a commutative semiring, use\n`to_lin_flip`, which is linear. -/\ndef to_lin_hom_flip : bilin_form R M \u2192\u2097[R\u2082] M \u2192\u2097[R\u2082] M \u2192\u2097[R] R :=\n(to_lin_hom R\u2082).comp (flip_hom R\u2082).to_linear_map\n\nvariables {R\u2082}\n\n@[simp] lemma to_lin'_flip_apply (A : bilin_form R M) (x : M) :\n  \u21d1(to_lin_hom_flip R\u2082 A x) = \u03bb y, A y x :=\nrfl\n\n/-- The linear map obtained from a `bilin_form` by fixing the right co-ordinate and evaluating in\nthe left.\nOver a commutative semiring, use `to_lin_flip`, which is linear rather than `\u2115`-linear. -/\nabbreviation to_lin'_flip : bilin_form R M \u2192\u2097[\u2115] M \u2192\u2097[\u2115] M \u2192\u2097[R] R := to_lin_hom_flip \u2115\n\nend to_lin'\n\nend bilin_form\n\nsection equiv_lin\n\n/-- A map with two arguments that is linear in both is a bilinear form.\n\nThis is an auxiliary definition for the full linear equivalence `linear_map.to_bilin`.\n-/\ndef linear_map.to_bilin_aux (f : M\u2082 \u2192\u2097[R\u2082] M\u2082 \u2192\u2097[R\u2082] R\u2082) : bilin_form R\u2082 M\u2082 :=\n{ bilin := \u03bb x y, f x y,\n  bilin_add_left := \u03bb x y z, (linear_map.map_add f x y).symm \u25b8 linear_map.add_apply (f x) (f y) z,\n  bilin_smul_left := \u03bb a x y, by rw [linear_map.map_smul, linear_map.smul_apply, smul_eq_mul],\n  bilin_add_right := \u03bb x y z, linear_map.map_add (f x) y z,\n  bilin_smul_right := \u03bb a x y, linear_map.map_smul (f x) a y }\n\n/-- Bilinear forms are linearly equivalent to maps with two arguments that are linear in both. -/\ndef bilin_form.to_lin : bilin_form R\u2082 M\u2082 \u2243\u2097[R\u2082] (M\u2082 \u2192\u2097[R\u2082] M\u2082 \u2192\u2097[R\u2082] R\u2082) :=\n{ inv_fun := linear_map.to_bilin_aux,\n  left_inv := \u03bb B, by { ext, simp [linear_map.to_bilin_aux] },\n  right_inv := \u03bb B, by { ext, simp [linear_map.to_bilin_aux] },\n  .. bilin_form.to_lin_hom R\u2082 }\n\n/-- A map with two arguments that is linear in both is linearly equivalent to bilinear form. -/\ndef linear_map.to_bilin : (M\u2082 \u2192\u2097[R\u2082] M\u2082 \u2192\u2097[R\u2082] R\u2082) \u2243\u2097[R\u2082] bilin_form R\u2082 M\u2082 :=\nbilin_form.to_lin.symm\n\n@[simp] lemma linear_map.to_bilin_aux_eq (f : M\u2082 \u2192\u2097[R\u2082] M\u2082 \u2192\u2097[R\u2082] R\u2082) :\n  linear_map.to_bilin_aux f = linear_map.to_bilin f :=\nrfl\n\n@[simp] lemma linear_map.to_bilin_symm :\n  (linear_map.to_bilin.symm : bilin_form R\u2082 M\u2082 \u2243\u2097 _) = bilin_form.to_lin := rfl\n\n@[simp] lemma bilin_form.to_lin_symm :\n  (bilin_form.to_lin.symm : _ \u2243\u2097 bilin_form R\u2082 M\u2082) = linear_map.to_bilin :=\nlinear_map.to_bilin.symm_symm\n\n@[simp, norm_cast]\nlemma bilin_form.to_lin_apply (x : M\u2082) : \u21d1(bilin_form.to_lin B\u2082 x) = B\u2082 x := rfl\n\nend equiv_lin\n\nnamespace bilin_form\n\nsection comp\n\nvariables {M' : Type w} [add_comm_monoid M'] [module R M']\n\n/-- Apply a linear map on the left and right argument of a bilinear form. -/\ndef comp (B : bilin_form R M') (l r : M \u2192\u2097[R] M') : bilin_form R M :=\n{ bilin := \u03bb x y, B (l x) (r y),\n  bilin_add_left := \u03bb x y z, by rw [linear_map.map_add, add_left],\n  bilin_smul_left := \u03bb x y z, by rw [linear_map.map_smul, smul_left],\n  bilin_add_right := \u03bb x y z, by rw [linear_map.map_add, add_right],\n  bilin_smul_right := \u03bb x y z, by rw [linear_map.map_smul, smul_right] }\n\n/-- Apply a linear map to the left argument of a bilinear form. -/\ndef comp_left (B : bilin_form R M) (f : M \u2192\u2097[R] M) : bilin_form R M :=\nB.comp f linear_map.id\n\n/-- Apply a linear map to the right argument of a bilinear form. -/\ndef comp_right (B : bilin_form R M) (f : M \u2192\u2097[R] M) : bilin_form R M :=\nB.comp linear_map.id f\n\nlemma comp_comp {M'' : Type*} [add_comm_monoid M''] [module R M'']\n  (B : bilin_form R M'') (l r : M \u2192\u2097[R] M') (l' r' : M' \u2192\u2097[R] M'') :\n  (B.comp l' r').comp l r = B.comp (l'.comp l) (r'.comp r) := rfl\n\n@[simp] lemma comp_left_comp_right (B : bilin_form R M) (l r : M \u2192\u2097[R] M) :\n  (B.comp_left l).comp_right r = B.comp l r := rfl\n\n@[simp] lemma comp_right_comp_left (B : bilin_form R M) (l r : M \u2192\u2097[R] M) :\n  (B.comp_right r).comp_left l = B.comp l r := rfl\n\n@[simp] lemma comp_apply (B : bilin_form R M') (l r : M \u2192\u2097[R] M') (v w) :\n  B.comp l r v w = B (l v) (r w) := rfl\n\n@[simp] lemma comp_left_apply (B : bilin_form R M) (f : M \u2192\u2097[R] M) (v w) :\n  B.comp_left f v w = B (f v) w := rfl\n\n@[simp] lemma comp_right_apply (B : bilin_form R M) (f : M \u2192\u2097[R] M) (v w) :\n  B.comp_right f v w = B v (f w) := rfl\n\nlemma comp_injective (B\u2081 B\u2082 : bilin_form R M') {l r : M \u2192\u2097[R] M'}\n  (h\u2097 : function.surjective l) (h\u1d63 : function.surjective r) :\n  B\u2081.comp l r = B\u2082.comp l r \u2194 B\u2081 = B\u2082 :=\nbegin\n  split; intros h,\n  { -- B\u2081.comp l r = B\u2082.comp l r \u2192 B\u2081 = B\u2082\n    ext,\n    cases h\u2097 x with x' hx, subst hx,\n    cases h\u1d63 y with y' hy, subst hy,\n    rw [\u2190comp_apply, \u2190comp_apply, h], },\n  { -- B\u2081 = B\u2082 \u2192 B\u2081.comp l r = B\u2082.comp l r\n    subst h, },\nend\n\nend comp\n\nvariables {M\u2082' : Type*} [add_comm_monoid M\u2082'] [module R\u2082 M\u2082']\n\nsection congr\n\n/-- Apply a linear equivalence on the arguments of a bilinear form. -/\ndef congr (e : M\u2082 \u2243\u2097[R\u2082] M\u2082') : bilin_form R\u2082 M\u2082 \u2243\u2097[R\u2082] bilin_form R\u2082 M\u2082' :=\n{ to_fun := \u03bb B, B.comp e.symm e.symm,\n  inv_fun := \u03bb B, B.comp e e,\n  left_inv :=\n    \u03bb B, ext (\u03bb x y, by simp only [comp_apply, linear_equiv.coe_coe, e.symm_apply_apply]),\n  right_inv :=\n    \u03bb B, ext (\u03bb x y, by simp only [comp_apply, linear_equiv.coe_coe, e.apply_symm_apply]),\n  map_add' := \u03bb B B', ext (\u03bb x y, by simp only [comp_apply, add_apply]),\n  map_smul' := \u03bb B B', ext (\u03bb x y, by simp only [comp_apply, smul_apply]) }\n\n@[simp] lemma congr_apply (e : M\u2082 \u2243\u2097[R\u2082] M\u2082') (B : bilin_form R\u2082 M\u2082) (x y : M\u2082') :\n  congr e B x y = B (e.symm x) (e.symm y) := rfl\n\n@[simp] lemma congr_symm (e : M\u2082 \u2243\u2097[R\u2082] M\u2082') :\n  (congr e).symm = congr e.symm :=\nby { ext B x y, simp only [congr_apply, linear_equiv.symm_symm], refl }\n\nlemma congr_comp {M\u2082'' : Type*} [add_comm_monoid M\u2082''] [module R\u2082 M\u2082'']\n  (e : M\u2082 \u2243\u2097[R\u2082] M\u2082') (B : bilin_form R\u2082 M\u2082) (l r : M\u2082'' \u2192\u2097[R\u2082] M\u2082') :\n  (congr e B).comp l r = B.comp\n    (linear_map.comp (e.symm : M\u2082' \u2192\u2097[R\u2082] M\u2082) l)\n    (linear_map.comp (e.symm : M\u2082' \u2192\u2097[R\u2082] M\u2082) r) :=\nrfl\n\nlemma comp_congr {M\u2082'' : Type*} [add_comm_monoid M\u2082''] [module R\u2082 M\u2082'']\n  (e : M\u2082' \u2243\u2097[R\u2082] M\u2082'') (B : bilin_form R\u2082 M\u2082) (l r : M\u2082' \u2192\u2097[R\u2082] M\u2082) :\n  congr e (B.comp l r) = B.comp\n    (l.comp (e.symm : M\u2082'' \u2192\u2097[R\u2082] M\u2082'))\n    (r.comp (e.symm : M\u2082'' \u2192\u2097[R\u2082] M\u2082')) :=\nrfl\n\nend congr\n\nsection lin_mul_lin\n\n/-- `lin_mul_lin f g` is the bilinear form mapping `x` and `y` to `f x * g y` -/\ndef lin_mul_lin (f g : M\u2082 \u2192\u2097[R\u2082] R\u2082) : bilin_form R\u2082 M\u2082 :=\n{ bilin := \u03bb x y, f x * g y,\n  bilin_add_left := \u03bb x y z, by rw [linear_map.map_add, add_mul],\n  bilin_smul_left := \u03bb x y z, by rw [linear_map.map_smul, smul_eq_mul, mul_assoc],\n  bilin_add_right := \u03bb x y z, by rw [linear_map.map_add, mul_add],\n  bilin_smul_right := \u03bb x y z, by rw [linear_map.map_smul, smul_eq_mul, mul_left_comm] }\n\nvariables {f g : M\u2082 \u2192\u2097[R\u2082] R\u2082}\n\n@[simp] lemma lin_mul_lin_apply (x y) : lin_mul_lin f g x y = f x * g y := rfl\n\n@[simp] lemma lin_mul_lin_comp (l r : M\u2082' \u2192\u2097[R\u2082] M\u2082) :\n  (lin_mul_lin f g).comp l r = lin_mul_lin (f.comp l) (g.comp r) :=\nrfl\n\n@[simp] lemma lin_mul_lin_comp_left (l : M\u2082 \u2192\u2097[R\u2082] M\u2082) :\n  (lin_mul_lin f g).comp_left l = lin_mul_lin (f.comp l) g :=\nrfl\n\n@[simp] lemma lin_mul_lin_comp_right (r : M\u2082 \u2192\u2097[R\u2082] M\u2082) :\n  (lin_mul_lin f g).comp_right r = lin_mul_lin f (g.comp r) :=\nrfl\n\nend lin_mul_lin\n\n/-- The proposition that two elements of a bilinear form space are orthogonal. For orthogonality\nof an indexed set of elements, use `bilin_form.is_Ortho`. -/\ndef is_ortho (B : bilin_form R M) (x y : M) : Prop :=\nB x y = 0\n\nlemma is_ortho_def {B : bilin_form R M} {x y : M} :\n  B.is_ortho x y \u2194 B x y = 0 := iff.rfl\n\n\n\nlemma is_ortho_zero_right (x : M) : is_ortho B x (0 : M) :=\nzero_right x\n\nlemma ne_zero_of_not_is_ortho_self {B : bilin_form K V}\n  (x : V) (hx\u2081 : \u00ac B.is_ortho x x) : x \u2260 0 :=\n\u03bb hx\u2082, hx\u2081 (hx\u2082.symm \u25b8 is_ortho_zero_left _)\n\n/-- A set of vectors `v` is orthogonal with respect to some bilinear form `B` if and only\nif for all `i \u2260 j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use\n`bilin_form.is_ortho` -/\ndef is_Ortho {n : Type w} (B : bilin_form R M) (v : n \u2192 M) : Prop :=\n\u2200 i j : n, i \u2260 j \u2192 B.is_ortho (v j) (v i)\n\nlemma is_Ortho_def {n : Type w} {B : bilin_form R M} {v : n \u2192 M} :\n  B.is_Ortho v \u2194 \u2200 i j : n, i \u2260 j \u2192 B (v j) (v i) = 0 := iff.rfl\n\nsection\n\nvariables {R\u2084 M\u2084 : Type*} [domain R\u2084] [add_comm_group M\u2084] [module R\u2084 M\u2084] {G : bilin_form R\u2084 M\u2084}\n\n@[simp]\ntheorem is_ortho_smul_left {x y : M\u2084} {a : R\u2084} (ha : a \u2260 0) :\n  is_ortho G (a \u2022 x) y \u2194 is_ortho G x y :=\nbegin\n  dunfold is_ortho,\n  split; intro H,\n  { rw [smul_left, mul_eq_zero] at H,\n    cases H,\n    { trivial },\n    { exact H }},\n  { rw [smul_left, H, mul_zero] },\nend\n\n@[simp]\ntheorem is_ortho_smul_right {x y : M\u2084} {a : R\u2084} (ha : a \u2260 0) :\n  is_ortho G x (a \u2022 y) \u2194 is_ortho G x y :=\nbegin\n  dunfold is_ortho,\n  split; intro H,\n  { rw [smul_right, mul_eq_zero] at H,\n    cases H,\n    { trivial },\n    { exact H }},\n  { rw [smul_right, H, mul_zero] },\nend\n\n/-- A set of orthogonal vectors `v` with respect to some bilinear form `B` is linearly independent\n  if for all `i`, `B (v i) (v i) \u2260 0`. -/\nlemma linear_independent_of_is_Ortho\n  {n : Type w} {B : bilin_form K V} {v : n \u2192 V}\n  (hv\u2081 : B.is_Ortho v) (hv\u2082 : \u2200 i, \u00ac B.is_ortho (v i) (v i)) :\n  linear_independent K v :=\nbegin\n  classical,\n  rw linear_independent_iff',\n  intros s w hs i hi,\n  have : B (s.sum $ \u03bb (i : n), w i \u2022 v i) (v i) = 0,\n  { rw [hs, zero_left] },\n  have hsum : s.sum (\u03bb (j : n), w j * B (v j) (v i)) =\n    s.sum (\u03bb (j : n), if i = j then w j * B (v j) (v i) else 0),\n  { refine finset.sum_congr rfl (\u03bb j hj, _),\n    by_cases (i = j),\n    { rw [if_pos h] },\n    { rw [if_neg h, is_Ortho_def.1 hv\u2081 _ _ h, mul_zero] } },\n  simp_rw [sum_left, smul_left, hsum, finset.sum_ite_eq] at this,\n  rw [if_pos, mul_eq_zero] at this,\n  cases this,\n  { assumption },\n  { exact false.elim (hv\u2082 i $ this) },\n  { assumption }\nend\n\nend\n\nsection is_basis\n\nvariables {B\u2083 F\u2083 : bilin_form R\u2083 M\u2083}\nvariables {\u03b9 : Type*} {b : \u03b9 \u2192 M\u2083} (hb : is_basis R\u2083 b)\n\n/-- Two bilinear forms are equal when they are equal on all basis vectors. -/\nlemma ext_basis (h : \u2200 i j, B\u2083 (b i) (b j) = F\u2083 (b i) (b j)) : B\u2083 = F\u2083 :=\nto_lin.injective $ hb.ext $ \u03bb i, hb.ext $ \u03bb j, h i j\n\n/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis. -/\nlemma sum_repr_mul_repr_mul (x y : M\u2083) :\n  (hb.repr x).sum (\u03bb i xi, (hb.repr y).sum (\u03bb j yj, xi \u2022 yj \u2022 B\u2083 (b i) (b j))) = B\u2083 x y :=\nbegin\n  conv_rhs { rw [\u2190 hb.total_repr x, \u2190 hb.total_repr y] },\n  simp_rw [finsupp.total_apply, finsupp.sum, sum_left, sum_right,\n    smul_left, smul_right, smul_eq_mul]\nend\n\nend is_basis\n\nend bilin_form\n\nsection matrix\nvariables {n o : Type*} [fintype n] [fintype o]\n\nopen bilin_form finset linear_map matrix\nopen_locale matrix\n\n/-- The map from `matrix n n R` to bilinear forms on `n \u2192 R`.\n\nThis is an auxiliary definition for the equivalence `matrix.to_bilin_form'`. -/\ndef matrix.to_bilin'_aux (M : matrix n n R\u2082) : bilin_form R\u2082 (n \u2192 R\u2082) :=\n{ bilin := \u03bb v w, \u2211 i j, v i * M i j * w j,\n  bilin_add_left := \u03bb x y z, by simp only [pi.add_apply, add_mul, sum_add_distrib],\n  bilin_smul_left := \u03bb a x y, by simp only [pi.smul_apply, smul_eq_mul, mul_assoc, mul_sum],\n  bilin_add_right := \u03bb x y z, by simp only [pi.add_apply, mul_add, sum_add_distrib],\n  bilin_smul_right := \u03bb a x y,\n    by simp only [pi.smul_apply, smul_eq_mul, mul_assoc, mul_left_comm, mul_sum] }\n\nlemma matrix.to_bilin'_aux_std_basis [decidable_eq n] (M : matrix n n R\u2082) (i j : n) :\n  M.to_bilin'_aux (std_basis R\u2082 (\u03bb _, R\u2082) i 1) (std_basis R\u2082 (\u03bb _, R\u2082) j 1) =\n    M i j :=\nbegin\n  rw [matrix.to_bilin'_aux, coe_fn_mk, sum_eq_single i, sum_eq_single j],\n  { simp only [std_basis_same, std_basis_same, one_mul, mul_one] },\n  { rintros j' - hj',\n    apply mul_eq_zero_of_right,\n    exact std_basis_ne R\u2082 (\u03bb _, R\u2082) _ _ hj' 1 },\n  { intros,\n    have := finset.mem_univ j,\n    contradiction },\n  { rintros i' - hi',\n    refine finset.sum_eq_zero (\u03bb j _, _),\n    apply mul_eq_zero_of_left,\n    apply mul_eq_zero_of_left,\n    exact std_basis_ne R\u2082 (\u03bb _, R\u2082) _ _ hi' 1 },\n  { intros,\n    have := finset.mem_univ i,\n    contradiction }\nend\n\n/-- The linear map from bilinear forms to `matrix n n R` given an `n`-indexed basis.\n\nThis is an auxiliary definition for the equivalence `matrix.to_bilin_form'`. -/\ndef bilin_form.to_matrix_aux (b : n \u2192 M\u2082) : bilin_form R\u2082 M\u2082 \u2192\u2097[R\u2082] matrix n n R\u2082 :=\n{ to_fun := \u03bb B i j, B (b i) (b j),\n  map_add' := \u03bb f g, rfl,\n  map_smul' := \u03bb f g, rfl }\n\nlemma to_bilin'_aux_to_matrix_aux [decidable_eq n] (B\u2083 : bilin_form R\u2083 (n \u2192 R\u2083)) :\n  matrix.to_bilin'_aux (bilin_form.to_matrix_aux (\u03bb j, std_basis R\u2083 (\u03bb _, R\u2083) j 1) B\u2083) =\n    B\u2083 :=\nbegin\n  refine ext_basis (pi.is_basis_fun R\u2083 n) (\u03bb i j, _),\n  rw [bilin_form.to_matrix_aux, linear_map.coe_mk, matrix.to_bilin'_aux_std_basis]\nend\n\nsection to_matrix'\n\n/-! ### `to_matrix'` section\n\nThis section deals with the conversion between matrices and bilinear forms on `n \u2192 R\u2083`.\n-/\n\nvariables [decidable_eq n] [decidable_eq o]\n\n/-- The linear equivalence between bilinear forms on `n \u2192 R` and `n \u00d7 n` matrices -/\ndef bilin_form.to_matrix' : bilin_form R\u2083 (n \u2192 R\u2083) \u2243\u2097[R\u2083] matrix n n R\u2083 :=\n{ inv_fun := matrix.to_bilin'_aux,\n  left_inv := by convert to_bilin'_aux_to_matrix_aux,\n  right_inv := \u03bb M,\n    by { ext i j, simp only [bilin_form.to_matrix_aux, matrix.to_bilin'_aux_std_basis] },\n  ..bilin_form.to_matrix_aux (\u03bb j, std_basis R\u2083 (\u03bb _, R\u2083) j 1) }\n\n@[simp] lemma bilin_form.to_matrix_aux_std_basis (B : bilin_form R\u2083 (n \u2192 R\u2083)) :\n  bilin_form.to_matrix_aux (\u03bb j, std_basis R\u2083 (\u03bb _, R\u2083) j 1) B =\n    bilin_form.to_matrix' B :=\nrfl\n\n/-- The linear equivalence between `n \u00d7 n` matrices and bilinear forms on `n \u2192 R` -/\ndef matrix.to_bilin' : matrix n n R\u2083 \u2243\u2097[R\u2083] bilin_form R\u2083 (n \u2192 R\u2083) :=\nbilin_form.to_matrix'.symm\n\n@[simp] lemma matrix.to_bilin'_aux_eq (M : matrix n n R\u2083) :\n  matrix.to_bilin'_aux M = matrix.to_bilin' M :=\nrfl\n\nlemma matrix.to_bilin'_apply (M : matrix n n R\u2083) (x y : n \u2192 R\u2083) :\n  matrix.to_bilin' M x y = \u2211 i j, x i * M i j * y j := rfl\n\nlemma matrix.to_bilin'_apply' (M : matrix n n R\u2083) (v w : n \u2192 R\u2083) :\n  matrix.to_bilin' M v w = matrix.dot_product v (M.mul_vec w) :=\nbegin\n  simp_rw [matrix.to_bilin'_apply, matrix.dot_product,\n           matrix.mul_vec, matrix.dot_product],\n  refine finset.sum_congr rfl (\u03bb _ _, _),\n  rw finset.mul_sum,\n  refine finset.sum_congr rfl (\u03bb _ _, _),\n  rw \u2190 mul_assoc,\nend\n\n@[simp] lemma matrix.to_bilin'_std_basis (M : matrix n n R\u2083) (i j : n) :\n  matrix.to_bilin' M (std_basis R\u2083 (\u03bb _, R\u2083) i 1) (std_basis R\u2083 (\u03bb _, R\u2083) j 1) =\n    M i j :=\nmatrix.to_bilin'_aux_std_basis M i j\n\n@[simp] lemma bilin_form.to_matrix'_symm :\n  (bilin_form.to_matrix'.symm : matrix n n R\u2083 \u2243\u2097 _) = matrix.to_bilin' :=\nrfl\n\n@[simp] lemma matrix.to_bilin'_symm :\n  (matrix.to_bilin'.symm : _ \u2243\u2097 matrix n n R\u2083) = bilin_form.to_matrix' :=\nbilin_form.to_matrix'.symm_symm\n\n@[simp] lemma matrix.to_bilin'_to_matrix' (B : bilin_form R\u2083 (n \u2192 R\u2083)) :\n  matrix.to_bilin' (bilin_form.to_matrix' B) = B :=\nmatrix.to_bilin'.apply_symm_apply B\n\n@[simp] lemma bilin_form.to_matrix'_to_bilin' (M : matrix n n R\u2083) :\n  bilin_form.to_matrix' (matrix.to_bilin' M) = M :=\nbilin_form.to_matrix'.apply_symm_apply M\n\n@[simp] lemma bilin_form.to_matrix'_apply (B : bilin_form R\u2083 (n \u2192 R\u2083)) (i j : n) :\n  bilin_form.to_matrix' B i j =\n    B (std_basis R\u2083 (\u03bb _, R\u2083) i 1) (std_basis R\u2083 (\u03bb _, R\u2083) j 1) :=\nrfl\n\n@[simp] lemma bilin_form.to_matrix'_comp (B : bilin_form R\u2083 (n \u2192 R\u2083))\n  (l r : (o \u2192 R\u2083) \u2192\u2097[R\u2083] (n \u2192 R\u2083)) :\n  (B.comp l r).to_matrix' = l.to_matrix'\u1d40 \u2b1d B.to_matrix' \u2b1d r.to_matrix' :=\nbegin\n  ext i j,\n  simp only [bilin_form.to_matrix'_apply, bilin_form.comp_apply, transpose_apply, matrix.mul_apply,\n    linear_map.to_matrix', linear_equiv.coe_mk, sum_mul],\n  rw sum_comm,\n  conv_lhs { rw \u2190 sum_repr_mul_repr_mul (pi.is_basis_fun R\u2083 n) (l _) (r _) },\n  rw finsupp.sum_fintype,\n  { apply sum_congr rfl,\n    rintros i' -,\n    rw finsupp.sum_fintype,\n    { apply sum_congr rfl,\n      rintros j' -,\n      simp only [smul_eq_mul, pi.is_basis_fun_repr, mul_assoc, mul_comm, mul_left_comm] },\n    { intros, simp only [zero_smul, smul_zero] } },\n  { intros, simp only [zero_smul, finsupp.sum_zero] }\nend\n\nlemma bilin_form.to_matrix'_comp_left (B : bilin_form R\u2083 (n \u2192 R\u2083)) (f : (n \u2192 R\u2083) \u2192\u2097[R\u2083] (n \u2192 R\u2083)) :\n  (B.comp_left f).to_matrix' = f.to_matrix'\u1d40 \u2b1d B.to_matrix' :=\nby simp only [comp_left, bilin_form.to_matrix'_comp, to_matrix'_id, matrix.mul_one]\n\nlemma bilin_form.to_matrix'_comp_right (B : bilin_form R\u2083 (n \u2192 R\u2083)) (f : (n \u2192 R\u2083) \u2192\u2097[R\u2083] (n \u2192 R\u2083)) :\n  (B.comp_right f).to_matrix' = B.to_matrix' \u2b1d f.to_matrix' :=\nby simp only [bilin_form.comp_right, bilin_form.to_matrix'_comp, to_matrix'_id,\n              transpose_one, matrix.one_mul]\n\nlemma bilin_form.mul_to_matrix'_mul (B : bilin_form R\u2083 (n \u2192 R\u2083))\n  (M : matrix o n R\u2083) (N : matrix n o R\u2083) :\n  M \u2b1d B.to_matrix' \u2b1d N = (B.comp M\u1d40.to_lin' N.to_lin').to_matrix' :=\nby simp only [B.to_matrix'_comp, transpose_transpose, to_matrix'_to_lin']\n\nlemma bilin_form.mul_to_matrix' (B : bilin_form R\u2083 (n \u2192 R\u2083)) (M : matrix n n R\u2083) :\n  M \u2b1d B.to_matrix' = (B.comp_left M\u1d40.to_lin').to_matrix' :=\nby simp only [B.to_matrix'_comp_left, transpose_transpose, to_matrix'_to_lin']\n\nlemma bilin_form.to_matrix'_mul (B : bilin_form R\u2083 (n \u2192 R\u2083)) (M : matrix n n R\u2083) :\n  B.to_matrix' \u2b1d M = (B.comp_right M.to_lin').to_matrix' :=\nby simp only [B.to_matrix'_comp_right, to_matrix'_to_lin']\n\nlemma matrix.to_bilin'_comp (M : matrix n n R\u2083) (P Q : matrix n o R\u2083) :\n  M.to_bilin'.comp P.to_lin' Q.to_lin' = (P\u1d40 \u2b1d M \u2b1d Q).to_bilin' :=\nbilin_form.to_matrix'.injective\n  (by simp only [bilin_form.to_matrix'_comp, bilin_form.to_matrix'_to_bilin', to_matrix'_to_lin'])\n\nend to_matrix'\n\nsection to_matrix\n\n/-! ### `to_matrix` section\n\nThis section deals with the conversion between matrices and bilinear forms on\na module with a fixed basis.\n-/\n\nvariables [decidable_eq n] {b : n \u2192 M\u2083} (hb : is_basis R\u2083 b)\n\n/-- `bilin_form.to_matrix hb` is the equivalence between `R`-bilinear forms on `M` and\n`n`-by-`n` matrices with entries in `R`, if `hb` is an `R`-basis for `M`. -/\nnoncomputable def bilin_form.to_matrix : bilin_form R\u2083 M\u2083 \u2243\u2097[R\u2083] matrix n n R\u2083 :=\n(bilin_form.congr hb.equiv_fun).trans bilin_form.to_matrix'\n\n/-- `bilin_form.to_matrix hb` is the equivalence between `R`-bilinear forms on `M` and\n`n`-by-`n` matrices with entries in `R`, if `hb` is an `R`-basis for `M`. -/\nnoncomputable def matrix.to_bilin : matrix n n R\u2083 \u2243\u2097[R\u2083] bilin_form R\u2083 M\u2083 :=\n(bilin_form.to_matrix hb).symm\n\n@[simp] lemma is_basis.equiv_fun_symm_std_basis (i : n) :\n  hb.equiv_fun.symm (std_basis R\u2083 (\u03bb _, R\u2083) i 1) = b i :=\nbegin\n  rw [hb.equiv_fun_symm_apply, finset.sum_eq_single i],\n  { rw [std_basis_same, one_smul] },\n  { rintros j - hj,\n    rw [std_basis_ne _ _ _ _ hj, zero_smul] },\n  { intro,\n    have := mem_univ i,\n    contradiction }\nend\n\n@[simp] lemma bilin_form.to_matrix_apply (B : bilin_form R\u2083 M\u2083) (i j : n) :\n  bilin_form.to_matrix hb B i j = B (b i) (b j) :=\nby rw [bilin_form.to_matrix, linear_equiv.trans_apply, bilin_form.to_matrix'_apply, congr_apply,\n       hb.equiv_fun_symm_std_basis, hb.equiv_fun_symm_std_basis]\n\n@[simp] lemma matrix.to_bilin_apply (M : matrix n n R\u2083) (x y : M\u2083) :\n  matrix.to_bilin hb M x y = \u2211 i j, hb.repr x i * M i j * hb.repr y j :=\nshow ((congr hb.equiv_fun).symm (matrix.to_bilin' M)) x y =\n    \u2211 (i j : n), hb.repr x i * M i j * hb.repr y j,\nby simp only [congr_symm, congr_apply, linear_equiv.symm_symm, matrix.to_bilin'_apply,\n  is_basis.equiv_fun_apply]\n\n-- Not a `simp` lemma since `bilin_form.to_matrix` needs an extra argument\nlemma bilinear_form.to_matrix_aux_eq (B : bilin_form R\u2083 M\u2083) :\n  bilin_form.to_matrix_aux b B = bilin_form.to_matrix hb B :=\next (\u03bb i j, by rw [bilin_form.to_matrix_apply, bilin_form.to_matrix_aux, linear_map.coe_mk])\n\n@[simp] lemma bilin_form.to_matrix_symm :\n  (bilin_form.to_matrix hb).symm = matrix.to_bilin hb :=\nrfl\n\n@[simp] lemma matrix.to_bilin_symm :\n  (matrix.to_bilin hb).symm = bilin_form.to_matrix hb :=\n(bilin_form.to_matrix hb).symm_symm\n\nlemma matrix.to_bilin_is_basis_fun :\n  matrix.to_bilin (pi.is_basis_fun R\u2083 n) = matrix.to_bilin' :=\nby { ext M, simp only [matrix.to_bilin_apply, matrix.to_bilin'_apply, pi.is_basis_fun_repr] }\n\nlemma bilin_form.to_matrix_is_basis_fun :\n  bilin_form.to_matrix (pi.is_basis_fun R\u2083 n) = bilin_form.to_matrix' :=\nby { ext B, rw [bilin_form.to_matrix_apply, bilin_form.to_matrix'_apply] }\n\n@[simp] lemma matrix.to_bilin_to_matrix (B : bilin_form R\u2083 M\u2083) :\n  matrix.to_bilin hb (bilin_form.to_matrix hb B) = B :=\n(matrix.to_bilin hb).apply_symm_apply B\n\n@[simp] lemma bilin_form.to_matrix_to_bilin (M : matrix n n R\u2083) :\n  bilin_form.to_matrix hb (matrix.to_bilin hb M) = M :=\n(bilin_form.to_matrix hb).apply_symm_apply M\n\nvariables {M\u2083' : Type*} [add_comm_group M\u2083'] [module R\u2083 M\u2083']\nvariables {c : o \u2192 M\u2083'} (hc : is_basis R\u2083 c)\nvariables [decidable_eq o]\n\n-- Cannot be a `simp` lemma because `hb` must be inferred.\nlemma bilin_form.to_matrix_comp\n  (B : bilin_form R\u2083 M\u2083) (l r : M\u2083' \u2192\u2097[R\u2083] M\u2083) :\n  bilin_form.to_matrix hc (B.comp l r) =\n    (to_matrix hc hb l)\u1d40 \u2b1d bilin_form.to_matrix hb B \u2b1d to_matrix hc hb r :=\nbegin\n  ext i j,\n  simp only [bilin_form.to_matrix_apply, bilin_form.comp_apply, transpose_apply, matrix.mul_apply,\n    linear_map.to_matrix', linear_equiv.coe_mk, sum_mul],\n  rw sum_comm,\n  conv_lhs { rw \u2190 sum_repr_mul_repr_mul hb },\n  rw finsupp.sum_fintype,\n  { apply sum_congr rfl,\n    rintros i' -,\n    rw finsupp.sum_fintype,\n    { apply sum_congr rfl,\n      rintros j' -,\n      simp only [smul_eq_mul, linear_map.to_matrix_apply,\n        is_basis.equiv_fun_apply, mul_assoc, mul_comm, mul_left_comm] },\n    { intros, simp only [zero_smul, smul_zero] } },\n  { intros, simp only [zero_smul, finsupp.sum_zero] }\nend\n\nlemma bilin_form.to_matrix_comp_left (B : bilin_form R\u2083 M\u2083) (f : M\u2083 \u2192\u2097[R\u2083] M\u2083) :\n  bilin_form.to_matrix hb (B.comp_left f) = (to_matrix hb hb f)\u1d40 \u2b1d bilin_form.to_matrix hb B :=\nby simp only [comp_left, bilin_form.to_matrix_comp hb hb, to_matrix_id, matrix.mul_one]\n\nlemma bilin_form.to_matrix_comp_right (B : bilin_form R\u2083 M\u2083) (f : M\u2083 \u2192\u2097[R\u2083] M\u2083) :\n  bilin_form.to_matrix hb (B.comp_right f) = bilin_form.to_matrix hb B \u2b1d (to_matrix hb hb f) :=\nby simp only [bilin_form.comp_right, bilin_form.to_matrix_comp hb hb, to_matrix_id,\n              transpose_one, matrix.one_mul]\n\nlemma bilin_form.mul_to_matrix_mul (B : bilin_form R\u2083 M\u2083)\n  (M : matrix o n R\u2083) (N : matrix n o R\u2083) :\n  M \u2b1d bilin_form.to_matrix hb B \u2b1d N =\n    bilin_form.to_matrix hc (B.comp (to_lin hc hb M\u1d40) (to_lin hc hb N)) :=\nby simp only [B.to_matrix_comp hb hc, to_matrix_to_lin, transpose_transpose]\n\nlemma bilin_form.mul_to_matrix (B : bilin_form R\u2083 M\u2083) (M : matrix n n R\u2083) :\n  M \u2b1d bilin_form.to_matrix hb B =\n    bilin_form.to_matrix hb (B.comp_left (to_lin hb hb M\u1d40)) :=\nby rw [B.to_matrix_comp_left hb, to_matrix_to_lin, transpose_transpose]\n\nlemma bilin_form.to_matrix_mul (B : bilin_form R\u2083 M\u2083) (M : matrix n n R\u2083) :\n  bilin_form.to_matrix hb B \u2b1d M =\n    bilin_form.to_matrix hb (B.comp_right (to_lin hb hb M)) :=\nby rw [B.to_matrix_comp_right hb, to_matrix_to_lin]\n\nlemma matrix.to_bilin_comp (M : matrix n n R\u2083) (P Q : matrix n o R\u2083) :\n  (matrix.to_bilin hb M).comp (to_lin hc hb P) (to_lin hc hb Q) = matrix.to_bilin hc (P\u1d40 \u2b1d M \u2b1d Q) :=\n(bilin_form.to_matrix hc).injective\n  (by simp only [bilin_form.to_matrix_comp hb hc, bilin_form.to_matrix_to_bilin, to_matrix_to_lin])\n\nend to_matrix\n\nend matrix\n\nnamespace refl_bilin_form\n\nopen refl_bilin_form bilin_form\n\n/-- The proposition that a bilinear form is reflexive -/\ndef is_refl (B : bilin_form R M) : Prop := \u2200 (x y : M), B x y = 0 \u2192 B y x = 0\n\nvariable (H : is_refl B)\n\nlemma eq_zero : \u2200 {x y : M}, B x y = 0 \u2192 B y x = 0 := \u03bb x y, H x y\n\nlemma ortho_sym {x y : M} :\n  is_ortho B x y \u2194 is_ortho B y x := \u27e8eq_zero H, eq_zero H\u27e9\n\nend refl_bilin_form\n\nnamespace sym_bilin_form\n\nopen sym_bilin_form bilin_form\n\n/-- The proposition that a bilinear form is symmetric -/\ndef is_sym (B : bilin_form R M) : Prop := \u2200 (x y : M), B x y = B y x\n\nvariable (H : is_sym B)\n\nlemma sym (x y : M) : B x y = B y x := H x y\n\nlemma is_refl : refl_bilin_form.is_refl B := \u03bb x y H1, H x y \u25b8 H1\n\nlemma ortho_sym {x y : M} :\n  is_ortho B x y \u2194 is_ortho B y x := refl_bilin_form.ortho_sym (is_refl H)\n\nlemma is_sym_iff_flip' [algebra R\u2082 R] : is_sym B \u2194 flip_hom R\u2082 B = B :=\nbegin\n  split,\n  { intros h,\n    ext x y,\n    exact h y x },\n  { intros h x y,\n    conv_lhs { rw \u2190 h },\n    simp }\nend\n\nend sym_bilin_form\n\nnamespace alt_bilin_form\n\nopen alt_bilin_form bilin_form\n\n/-- The proposition that a bilinear form is alternating -/\ndef is_alt (B : bilin_form R M) : Prop := \u2200 (x : M), B x x = 0\n\nvariable (H : is_alt B)\ninclude H\n\nlemma self_eq_zero (x : M) : B x x = 0 := H x\n\nlemma neg (H : is_alt B\u2081) (x y : M\u2081) :\n  - B\u2081 x y = B\u2081 y x :=\nbegin\n  have H1 : B\u2081 (x + y) (x + y) = 0,\n  { exact self_eq_zero H (x + y) },\n  rw [add_left, add_right, add_right,\n    self_eq_zero H, self_eq_zero H, ring.zero_add,\n    ring.add_zero, add_eq_zero_iff_neg_eq] at H1,\n  exact H1,\nend\n\nend alt_bilin_form\n\nnamespace bilin_form\n\nsection linear_adjoints\n\nvariables (B) (F : bilin_form R M)\nvariables {M' : Type*} [add_comm_monoid M'] [module R M']\nvariables (B' : bilin_form R M') (f f' : M \u2192\u2097[R] M') (g g' : M' \u2192\u2097[R] M)\n\n/-- Given a pair of modules equipped with bilinear forms, this is the condition for a pair of\nmaps between them to be mutually adjoint. -/\ndef is_adjoint_pair := \u2200 \u2983x y\u2984, B' (f x) y = B x (g y)\n\nvariables {B B' B\u2082 f f' g g'}\n\nlemma is_adjoint_pair.eq (h : is_adjoint_pair B B' f g) :\n  \u2200 {x y}, B' (f x) y = B x (g y) := h\n\nlemma is_adjoint_pair_iff_comp_left_eq_comp_right (f g : module.End R M) :\n  is_adjoint_pair B F f g \u2194 F.comp_left f = B.comp_right g :=\nbegin\n  split; intros h,\n  { ext x y, rw [comp_left_apply, comp_right_apply], apply h, },\n  { intros x y, rw [\u2190comp_left_apply, \u2190comp_right_apply], rw h, },\nend\n\nlemma is_adjoint_pair_zero : is_adjoint_pair B B' 0 0 :=\n\u03bb x y, by simp only [bilin_form.zero_left, bilin_form.zero_right, linear_map.zero_apply]\n\nlemma is_adjoint_pair_id : is_adjoint_pair B B 1 1 := \u03bb x y, rfl\n\nlemma is_adjoint_pair.add (h : is_adjoint_pair B B' f g) (h' : is_adjoint_pair B B' f' g') :\n  is_adjoint_pair B B' (f + f') (g + g') :=\n\u03bb x y, by rw [linear_map.add_apply, linear_map.add_apply, add_left, add_right, h, h']\n\nvariables {M\u2081' : Type*} [add_comm_group M\u2081'] [module R\u2081 M\u2081']\nvariables {B\u2081' : bilin_form R\u2081 M\u2081'} {f\u2081 f\u2081' : M\u2081 \u2192\u2097[R\u2081] M\u2081'} {g\u2081 g\u2081' : M\u2081' \u2192\u2097[R\u2081] M\u2081}\n\nlemma is_adjoint_pair.sub (h : is_adjoint_pair B\u2081 B\u2081' f\u2081 g\u2081) (h' : is_adjoint_pair B\u2081 B\u2081' f\u2081' g\u2081') :\n  is_adjoint_pair B\u2081 B\u2081' (f\u2081 - f\u2081') (g\u2081 - g\u2081') :=\n\u03bb x y, by rw [linear_map.sub_apply, linear_map.sub_apply, sub_left, sub_right, h, h']\n\nvariables {M\u2082' : Type*} [add_comm_monoid M\u2082'] [module R\u2082 M\u2082']\nvariables {B\u2082' : bilin_form R\u2082 M\u2082'} {f\u2082 f\u2082' : M\u2082 \u2192\u2097[R\u2082] M\u2082'} {g\u2082 g\u2082' : M\u2082' \u2192\u2097[R\u2082] M\u2082}\n\nlemma is_adjoint_pair.smul (c : R\u2082) (h : is_adjoint_pair B\u2082 B\u2082' f\u2082 g\u2082) :\n  is_adjoint_pair B\u2082 B\u2082' (c \u2022 f\u2082) (c \u2022 g\u2082) :=\n\u03bb x y, by rw [linear_map.smul_apply, linear_map.smul_apply, smul_left, smul_right, h]\n\nvariables {M'' : Type*} [add_comm_monoid M''] [module R M'']\nvariables (B'' : bilin_form R M'')\n\nlemma is_adjoint_pair.comp {f' : M' \u2192\u2097[R] M''} {g' : M'' \u2192\u2097[R] M'}\n  (h : is_adjoint_pair B B' f g) (h' : is_adjoint_pair B' B'' f' g') :\n  is_adjoint_pair B B'' (f'.comp f) (g.comp g') :=\n\u03bb x y, by rw [linear_map.comp_apply, linear_map.comp_apply, h', h]\n\nlemma is_adjoint_pair.mul\n  {f g f' g' : module.End R M} (h : is_adjoint_pair B B f g) (h' : is_adjoint_pair B B f' g') :\n  is_adjoint_pair B B (f * f') (g' * g) :=\n\u03bb x y, by rw [linear_map.mul_apply, linear_map.mul_apply, h, h']\n\nvariables (B B' B\u2081 B\u2082) (F\u2082 : bilin_form R\u2082 M\u2082)\n\n/-- The condition for an endomorphism to be \"self-adjoint\" with respect to a pair of bilinear forms\non the underlying module. In the case that these two forms are identical, this is the usual concept\nof self adjointness. In the case that one of the forms is the negation of the other, this is the\nusual concept of skew adjointness. -/\ndef is_pair_self_adjoint (f : module.End R M) := is_adjoint_pair B F f f\n\n/-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/\ndef is_pair_self_adjoint_submodule : submodule R\u2082 (module.End R\u2082 M\u2082) :=\n{ carrier   := { f | is_pair_self_adjoint B\u2082 F\u2082 f },\n  zero_mem' := is_adjoint_pair_zero,\n  add_mem'  := \u03bb f g hf hg, hf.add hg,\n  smul_mem' := \u03bb c f h, h.smul c, }\n\n@[simp] lemma mem_is_pair_self_adjoint_submodule (f : module.End R\u2082 M\u2082) :\n  f \u2208 is_pair_self_adjoint_submodule B\u2082 F\u2082 \u2194 is_pair_self_adjoint B\u2082 F\u2082 f :=\nby refl\n\nvariables {M\u2083' : Type*} [add_comm_group M\u2083'] [module R\u2083 M\u2083']\nvariables (B\u2083 F\u2083 : bilin_form R\u2083 M\u2083)\n\nlemma is_pair_self_adjoint_equiv (e : M\u2083' \u2243\u2097[R\u2083] M\u2083) (f : module.End R\u2083 M\u2083) :\n  is_pair_self_adjoint B\u2083 F\u2083 f \u2194\n    is_pair_self_adjoint (B\u2083.comp \u2191e \u2191e) (F\u2083.comp \u2191e \u2191e) (e.symm.conj f) :=\nbegin\n  have h\u2097 : (F\u2083.comp \u2191e \u2191e).comp_left (e.symm.conj f) = (F\u2083.comp_left f).comp \u2191e \u2191e :=\n    by { ext, simp [linear_equiv.symm_conj_apply], },\n  have h\u1d63 : (B\u2083.comp \u2191e \u2191e).comp_right (e.symm.conj f) = (B\u2083.comp_right f).comp \u2191e \u2191e :=\n    by { ext, simp [linear_equiv.conj_apply], },\n  have he : function.surjective (\u21d1(\u2191e : M\u2083' \u2192\u2097[R\u2083] M\u2083) : M\u2083' \u2192 M\u2083) := e.surjective,\n  show bilin_form.is_adjoint_pair _ _ _ _  \u2194 bilin_form.is_adjoint_pair _ _ _ _,\n  rw [is_adjoint_pair_iff_comp_left_eq_comp_right, is_adjoint_pair_iff_comp_left_eq_comp_right,\n      h\u1d63, h\u2097, comp_injective _ _ he he],\nend\n\n/-- An endomorphism of a module is self-adjoint with respect to a bilinear form if it serves as an\nadjoint for itself. -/\ndef is_self_adjoint (f : module.End R M) := is_adjoint_pair B B f f\n\n/-- An endomorphism of a module is skew-adjoint with respect to a bilinear form if its negation\nserves as an adjoint. -/\ndef is_skew_adjoint (f : module.End R\u2081 M\u2081) := is_adjoint_pair B\u2081 B\u2081 f (-f)\n\nlemma is_skew_adjoint_iff_neg_self_adjoint (f : module.End R\u2081 M\u2081) :\n  B\u2081.is_skew_adjoint f \u2194 is_adjoint_pair (-B\u2081) B\u2081 f f :=\nshow (\u2200 x y, B\u2081 (f x) y = B\u2081 x ((-f) y)) \u2194 \u2200 x y, B\u2081 (f x) y = (-B\u2081) x (f y),\nby simp only [linear_map.neg_apply, bilin_form.neg_apply, bilin_form.neg_right]\n\n/-- The set of self-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact\nit is a Jordan subalgebra.) -/\ndef self_adjoint_submodule := is_pair_self_adjoint_submodule B\u2082 B\u2082\n\n@[simp] lemma mem_self_adjoint_submodule (f : module.End R\u2082 M\u2082) :\n  f \u2208 B\u2082.self_adjoint_submodule \u2194 B\u2082.is_self_adjoint f := iff.rfl\n\n/-- The set of skew-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact\nit is a Lie subalgebra.) -/\ndef skew_adjoint_submodule := is_pair_self_adjoint_submodule (-B\u2083) B\u2083\n\n@[simp] lemma mem_skew_adjoint_submodule (f : module.End R\u2083 M\u2083) :\n  f \u2208 B\u2083.skew_adjoint_submodule \u2194 B\u2083.is_skew_adjoint f :=\nby { rw is_skew_adjoint_iff_neg_self_adjoint, exact iff.rfl, }\n\nend linear_adjoints\n\nend bilin_form\n\nsection matrix_adjoints\nopen_locale matrix\n\nvariables {n : Type w} [fintype n]\nvariables {b : n \u2192 M\u2083} (hb : is_basis R\u2083 b)\nvariables (J J\u2083 A A' : matrix n n R\u2083)\n\n/-- The condition for the square matrices `A`, `A'` to be an adjoint pair with respect to the square\nmatrices `J`, `J\u2083`. -/\ndef matrix.is_adjoint_pair := A\u1d40 \u2b1d J\u2083 = J \u2b1d A'\n\n/-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix\n`J`. -/\ndef matrix.is_self_adjoint := matrix.is_adjoint_pair J J A A\n\n/-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix\n`J`. -/\ndef matrix.is_skew_adjoint := matrix.is_adjoint_pair J J A (-A)\n\n@[simp] lemma is_adjoint_pair_to_bilin' [decidable_eq n] :\n  bilin_form.is_adjoint_pair (matrix.to_bilin' J) (matrix.to_bilin' J\u2083)\n      (matrix.to_lin' A) (matrix.to_lin' A') \u2194\n    matrix.is_adjoint_pair J J\u2083 A A' :=\nbegin\n  rw bilin_form.is_adjoint_pair_iff_comp_left_eq_comp_right,\n  have h : \u2200 (B B' : bilin_form R\u2083 (n \u2192 R\u2083)), B = B' \u2194\n    (bilin_form.to_matrix' B) = (bilin_form.to_matrix' B'),\n  { intros B B',\n    split; intros h,\n    { rw h },\n    { exact bilin_form.to_matrix'.injective h } },\n  rw [h, bilin_form.to_matrix'_comp_left, bilin_form.to_matrix'_comp_right,\n      linear_map.to_matrix'_to_lin', linear_map.to_matrix'_to_lin',\n      bilin_form.to_matrix'_to_bilin', bilin_form.to_matrix'_to_bilin'],\n  refl,\nend\n\n@[simp] lemma is_adjoint_pair_to_bilin [decidable_eq n] :\n  bilin_form.is_adjoint_pair (matrix.to_bilin hb J) (matrix.to_bilin hb J\u2083)\n      (matrix.to_lin hb hb A) (matrix.to_lin hb hb A') \u2194\n    matrix.is_adjoint_pair J J\u2083 A A' :=\nbegin\n  rw bilin_form.is_adjoint_pair_iff_comp_left_eq_comp_right,\n  have h : \u2200 (B B' : bilin_form R\u2083 M\u2083), B = B' \u2194\n    (bilin_form.to_matrix hb B) = (bilin_form.to_matrix hb B'),\n  { intros B B',\n    split; intros h,\n    { rw h },\n    { exact (bilin_form.to_matrix hb).injective h } },\n  rw [h, bilin_form.to_matrix_comp_left, bilin_form.to_matrix_comp_right,\n      linear_map.to_matrix_to_lin, linear_map.to_matrix_to_lin,\n      bilin_form.to_matrix_to_bilin, bilin_form.to_matrix_to_bilin],\n  refl,\nend\n\nlemma matrix.is_adjoint_pair_equiv [decidable_eq n] (P : matrix n n R\u2083) (h : is_unit P) :\n  (P\u1d40 \u2b1d J \u2b1d P).is_adjoint_pair (P\u1d40 \u2b1d J \u2b1d P) A A' \u2194\n    J.is_adjoint_pair J (P \u2b1d A \u2b1d P\u207b\u00b9) (P \u2b1d A' \u2b1d P\u207b\u00b9) :=\nhave h' : is_unit P.det := P.is_unit_iff_is_unit_det.mp h,\nbegin\n  let u := P.nonsing_inv_unit h',\n  let v := P\u1d40.nonsing_inv_unit (P.is_unit_det_transpose h'),\n  let x := A\u1d40 * P\u1d40 * J,\n  let y := J * P * A',\n  suffices : x * \u2191u = \u2191v * y \u2194 \u2191v\u207b\u00b9 * x = y * \u2191u\u207b\u00b9,\n  { dunfold matrix.is_adjoint_pair,\n    repeat { rw matrix.transpose_mul, },\n    simp only [\u2190matrix.mul_eq_mul, \u2190mul_assoc, P.transpose_nonsing_inv h'],\n    conv_lhs { to_rhs, rw [mul_assoc, mul_assoc], congr, skip, rw \u2190mul_assoc, },\n    conv_rhs { rw [mul_assoc, mul_assoc], conv { to_lhs, congr, skip, rw \u2190mul_assoc }, },\n    exact this, },\n  rw units.eq_mul_inv_iff_mul_eq, conv_rhs { rw mul_assoc, }, rw v.inv_mul_eq_iff_eq_mul,\nend\n\nvariables [decidable_eq n]\n\n/-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to\ngiven matrices `J`, `J\u2082`. -/\ndef pair_self_adjoint_matrices_submodule : submodule R\u2083 (matrix n n R\u2083) :=\n(bilin_form.is_pair_self_adjoint_submodule (matrix.to_bilin' J) (matrix.to_bilin' J\u2083)).map\n  (linear_map.to_matrix' : ((n \u2192 R\u2083) \u2192\u2097[R\u2083] (n \u2192 R\u2083)) \u2243\u2097[R\u2083] matrix n n R\u2083)\n\n@[simp] lemma mem_pair_self_adjoint_matrices_submodule :\n  A \u2208 (pair_self_adjoint_matrices_submodule J J\u2083) \u2194 matrix.is_adjoint_pair J J\u2083 A A :=\nbegin\n  simp only [pair_self_adjoint_matrices_submodule, linear_equiv.coe_coe,\n    linear_map.to_matrix'_apply, submodule.mem_map, bilin_form.mem_is_pair_self_adjoint_submodule],\n  split,\n  { rintros \u27e8f, hf, hA\u27e9,\n    have hf' : f = A.to_lin' := by rw [\u2190hA, matrix.to_lin'_to_matrix'], rw hf' at hf,\n    rw \u2190 is_adjoint_pair_to_bilin',\n    exact hf, },\n  { intros h, refine \u27e8A.to_lin', _, linear_map.to_matrix'_to_lin' _\u27e9,\n    exact (is_adjoint_pair_to_bilin' _ _ _ _).mpr h, },\nend\n\n/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to\nthe matrix `J`. -/\ndef self_adjoint_matrices_submodule : submodule R\u2083 (matrix n n R\u2083) :=\n  pair_self_adjoint_matrices_submodule J J\n\n@[simp] lemma mem_self_adjoint_matrices_submodule :\n  A \u2208 self_adjoint_matrices_submodule J \u2194 J.is_self_adjoint A :=\nby { erw mem_pair_self_adjoint_matrices_submodule, refl, }\n\n/-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to\nthe matrix `J`. -/\ndef skew_adjoint_matrices_submodule : submodule R\u2083 (matrix n n R\u2083) :=\n  pair_self_adjoint_matrices_submodule (-J) J\n\n@[simp] lemma mem_skew_adjoint_matrices_submodule :\n  A \u2208 skew_adjoint_matrices_submodule J \u2194 J.is_skew_adjoint A :=\nbegin\n  erw mem_pair_self_adjoint_matrices_submodule,\n  simp [matrix.is_skew_adjoint, matrix.is_adjoint_pair],\nend\n\nend matrix_adjoints\n\nnamespace bilin_form\n\nsection orthogonal\n\n/-- The orthogonal complement of a submodule `N` with respect to some bilinear form is the set of\nelements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B x y = 0`.\n\nNote that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a\nchirality; in addition to this \"left\" orthogonal complement one could define a \"right\" orthogonal\ncomplement for which, for all `y` in `N`, `B y x = 0`.  This variant definition is not currently\nprovided in mathlib. -/\ndef orthogonal (B : bilin_form R M) (N : submodule R M) : submodule R M :=\n{ carrier := { m | \u2200 n \u2208 N, is_ortho B n m },\n  zero_mem' := \u03bb x _, is_ortho_zero_right x,\n  add_mem' := \u03bb x y hx hy n hn,\n    by rw [is_ortho, add_right, show B n x = 0, by exact hx n hn,\n        show B n y = 0, by exact hy n hn, zero_add],\n  smul_mem' := \u03bb c x hx n hn,\n    by rw [is_ortho, smul_right, show B n x = 0, by exact hx n hn, mul_zero] }\n\nvariables {N L : submodule R M}\n\n@[simp] lemma mem_orthogonal_iff {N : submodule R M} {m : M} :\n  m \u2208 B.orthogonal N \u2194 \u2200 n \u2208 N, is_ortho B n m := iff.rfl\n\nlemma orthogonal_le (h : N \u2264 L) : B.orthogonal L \u2264 B.orthogonal N :=\n\u03bb _ hn l hl, hn l (h hl)\n\nlemma le_orthogonal_orthogonal (hB : refl_bilin_form.is_refl B) :\n  N \u2264 B.orthogonal (B.orthogonal N) :=\n\u03bb n hn m hm, hB _ _ (hm n hn)\n\n-- \u2193 This lemma only applies in fields as we require `a * b = 0 \u2192 a = 0 \u2228 b = 0`\nlemma span_singleton_inf_orthogonal_eq_bot\n  {B : bilin_form K V} {x : V} (hx : \u00ac B.is_ortho x x) :\n  (K \u2219 x) \u2293 B.orthogonal (K \u2219 x) = \u22a5 :=\nbegin\n  rw \u2190 finset.coe_singleton,\n  refine eq_bot_iff.2 (\u03bb y h, _),\n  rcases mem_span_finset.1 h.1 with \u27e8\u03bc, rfl\u27e9,\n  have := h.2 x _,\n  { rw finset.sum_singleton at this \u22a2,\n    suffices h\u03bczero : \u03bc x = 0,\n    { rw [h\u03bczero, zero_smul, submodule.mem_bot] },\n    change B x (\u03bc x \u2022 x) = 0 at this, rw [smul_right] at this,\n    exact or.elim (zero_eq_mul.mp this.symm) id (\u03bb hfalse, false.elim $ hx hfalse) },\n  { rw submodule.mem_span; exact \u03bb _ hp, hp $ finset.mem_singleton_self _ }\nend\n\n-- \u2193 This lemma only applies in fields since we use the `mul_eq_zero`\nlemma orthogonal_span_singleton_eq_to_lin_ker {B : bilin_form K V} (x : V) :\n  B.orthogonal (K \u2219 x) = (bilin_form.to_lin B x).ker :=\nbegin\n  ext y,\n  simp_rw [mem_orthogonal_iff, linear_map.mem_ker,\n           submodule.mem_span_singleton ],\n  split,\n  { exact \u03bb h, h x \u27e81, one_smul _ _\u27e9 },\n  { rintro h _ \u27e8z, rfl\u27e9,\n    rw [is_ortho, smul_left, mul_eq_zero],\n    exact or.intro_right _ h }\nend\n\nlemma span_singleton_sup_orthogonal_eq_top {B : bilin_form K V}\n  {x : V} (hx : \u00ac B.is_ortho x x) :\n  (K \u2219 x) \u2294 B.orthogonal (K \u2219 x) = \u22a4 :=\nbegin\n  rw orthogonal_span_singleton_eq_to_lin_ker,\n  exact linear_map.span_singleton_sup_ker_eq_top _ hx,\nend\n\n/-- Given a bilinear form `B` and some `x` such that `B x x \u2260 0`, the span of the singleton of `x`\n  is complement to its orthogonal complement. -/\nlemma is_compl_span_singleton_orthogonal {B : bilin_form K V}\n  {x : V} (hx : \u00ac B.is_ortho x x) : is_compl (K \u2219 x) (B.orthogonal $ K \u2219 x) :=\n{ inf_le_bot := eq_bot_iff.1 $ span_singleton_inf_orthogonal_eq_bot hx,\n  top_le_sup := eq_top_iff.1 $ span_singleton_sup_orthogonal_eq_top hx }\n\nend orthogonal\n\n/-- The restriction of a bilinear form on a submodule. -/\n@[simps apply]\ndef restrict (B : bilin_form R M) (W : submodule R M) : bilin_form R W :=\n{ bilin := \u03bb a b, B a b,\n  bilin_add_left := \u03bb _ _ _, add_left _ _ _,\n  bilin_smul_left := \u03bb _ _ _, smul_left _ _ _,\n  bilin_add_right := \u03bb _ _ _, add_right _ _ _,\n  bilin_smul_right := \u03bb _ _ _, smul_right _ _ _}\n\n/-- The restriction of a symmetric bilinear form on a submodule is also symmetric. -/\nlemma restrict_sym (B : bilin_form R M) (hB : sym_bilin_form.is_sym B)\n  (W : submodule R M) : sym_bilin_form.is_sym $ B.restrict W :=\n\u03bb x y, hB x y\n\n/-- A nondegenerate bilinear form is a bilinear form such that the only element that is orthogonal\nto every other element is `0`; i.e., for all nonzero `m` in `M`, there exists `n` in `M` with\n`B m n \u2260 0`.\n\nNote that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a\nchirality; in addition to this \"left\" nondegeneracy condition one could define a \"right\"\nnondegeneracy condition that in the situation described, `B n m \u2260 0`.  This variant definition is\nnot currently provided in mathlib. In finite dimension either definition implies the other. -/\ndef nondegenerate (B : bilin_form R M) : Prop :=\n\u2200 m : M, (\u2200 n : M, B m n = 0) \u2192 m = 0\n\n/-- A bilinear form is nondegenerate if and only if it has a trivial kernel. -/\ntheorem nondegenerate_iff_ker_eq_bot {B : bilin_form R\u2082 M\u2082} :\n  B.nondegenerate \u2194 B.to_lin.ker = \u22a5 :=\nbegin\n  rw linear_map.ker_eq_bot',\n  split; intro h,\n  { refine \u03bb m hm, h _ (\u03bb x, _),\n    rw [\u2190 to_lin_apply, hm], refl },\n  { intros m hm, apply h,\n    ext, exact hm x }\nend\n\n/-- The restriction of a nondegenerate bilinear form `B` onto a submodule `W` is\nnondegenerate if `disjoint W (B.orthogonal W)`. -/\nlemma nondegenerate_restrict_of_disjoint_orthogonal\n  (B : bilin_form R\u2081 M\u2081) (hB : sym_bilin_form.is_sym B)\n  {W : submodule R\u2081 M\u2081} (hW : disjoint W (B.orthogonal W)) :\n  (B.restrict W).nondegenerate :=\nbegin\n  rintro \u27e8x, hx\u27e9 hB\u2081,\n  rw [submodule.mk_eq_zero, \u2190 submodule.mem_bot R\u2081],\n  refine hW \u27e8hx, \u03bb y hy, _\u27e9,\n  specialize hB\u2081 \u27e8y, hy\u27e9,\n  rwa [restrict_apply, submodule.coe_mk, submodule.coe_mk, hB] at hB\u2081\nend\n\nsection\n\nlemma to_lin_restrict_ker_eq_inf_orthogonal\n  (B : bilin_form K V) (W : subspace K V) (hB : sym_bilin_form.is_sym B) :\n  (B.to_lin.dom_restrict W).ker.map W.subtype = (W \u2293 B.orthogonal \u22a4 : subspace K V) :=\nbegin\n  ext x, split; intro hx,\n  { rcases hx with \u27e8\u27e8x, hx\u27e9, hker, rfl\u27e9,\n    erw linear_map.mem_ker at hker,\n    split,\n    { simp [hx] },\n    { intros y _,\n      rw [is_ortho, hB],\n      change (B.to_lin.dom_restrict W) \u27e8x, hx\u27e9 y = 0,\n      rw hker, refl } },\n  { simp_rw [submodule.mem_map, linear_map.mem_ker],\n    refine \u27e8\u27e8x, hx.1\u27e9, _, rfl\u27e9,\n    ext y, change B x y = 0,\n    rw hB,\n    exact hx.2 _ submodule.mem_top }\nend\n\nlemma to_lin_restrict_range_dual_annihilator_comap_eq_orthogonal\n  (B : bilin_form K V) (W : subspace K V) :\n  (B.to_lin.dom_restrict W).range.dual_annihilator_comap = B.orthogonal W :=\nbegin\n  ext x, split; rw [mem_orthogonal_iff]; intro hx,\n  { intros y hy,\n    rw submodule.mem_dual_annihilator_comap_iff at hx,\n    refine hx (B.to_lin.dom_restrict W \u27e8y, hy\u27e9) \u27e8\u27e8y, hy\u27e9, rfl\u27e9 },\n  { rw submodule.mem_dual_annihilator_comap_iff,\n    rintro _ \u27e8\u27e8w, hw\u27e9, rfl\u27e9,\n    exact hx w hw }\nend\n\nvariable [finite_dimensional K V]\n\nopen finite_dimensional\n\nlemma finrank_add_finrank_orthogonal\n  {B : bilin_form K V} {W : subspace K V} (hB\u2081 : sym_bilin_form.is_sym B) :\n  finrank K W + finrank K (B.orthogonal W) =\n  finrank K V + finrank K (W \u2293 B.orthogonal \u22a4 : subspace K V) :=\nbegin\n  rw [\u2190 to_lin_restrict_ker_eq_inf_orthogonal _ _ hB\u2081,\n      \u2190 to_lin_restrict_range_dual_annihilator_comap_eq_orthogonal _ _,\n      finrank_map_subtype_eq],\n  conv_rhs { rw [\u2190 @subspace.finrank_add_finrank_dual_annihilator_comap_eq K V _ _ _ _\n                  (B.to_lin.dom_restrict W).range,\n                 add_comm, \u2190 add_assoc, add_comm (finrank K \u21a5((B.to_lin.dom_restrict W).ker)),\n                 linear_map.finrank_range_add_finrank_ker] },\nend\n\n/-- A subspace is complement to its orthogonal complement with respect to some\nbilinear form if that bilinear form restricted on to the subspace is nondegenerate. -/\nlemma restrict_nondegenerate_of_is_compl_orthogonal\n  {B : bilin_form K V} {W : subspace K V}\n  (hB\u2081 : sym_bilin_form.is_sym B) (hB\u2082 : (B.restrict W).nondegenerate) :\n  is_compl W (B.orthogonal W) :=\nbegin\n  have : W \u2293 B.orthogonal W = \u22a5,\n  { rw eq_bot_iff,\n    intros x hx,\n    obtain \u27e8hx\u2081, hx\u2082\u27e9 := submodule.mem_inf.1 hx,\n    refine subtype.mk_eq_mk.1 (hB\u2082 \u27e8x, hx\u2081\u27e9 _),\n    rintro \u27e8n, hn\u27e9,\n    rw [restrict_apply, submodule.coe_mk, submodule.coe_mk, hB\u2081],\n    exact hx\u2082 n hn },\n  refine \u27e8this \u25b8 le_refl _, _\u27e9,\n  { rw top_le_iff,\n    refine eq_top_of_finrank_eq _,\n    refine le_antisymm (submodule.finrank_le _) _,\n    conv_rhs { rw \u2190 add_zero (finrank K _) },\n    rw [\u2190 finrank_bot K V, \u2190 this, submodule.dim_sup_add_dim_inf_eq,\n        finrank_add_finrank_orthogonal hB\u2081],\n    exact nat.le.intro rfl }\nend\n\n/-- A subspace is complement to its orthogonal complement with respect to some bilinear form\nif and only if that bilinear form restricted on to the subspace is nondegenerate. -/\ntheorem restrict_nondegenerate_iff_is_compl_orthogonal\n  {B : bilin_form K V} {W : subspace K V} (hB\u2081 : sym_bilin_form.is_sym B) :\n  (B.restrict W).nondegenerate \u2194 is_compl W (B.orthogonal W) :=\n\u27e8\u03bb hB\u2082, restrict_nondegenerate_of_is_compl_orthogonal hB\u2081 hB\u2082,\n \u03bb h, B.nondegenerate_restrict_of_disjoint_orthogonal hB\u2081 h.1\u27e9\n\n/-- Given a nondegenerate bilinear form `B` on a finite-dimensional vector space, `B.to_dual` is\nthe linear equivalence between a vector space and its dual with the underlying linear map\n`B.to_lin`. -/\nnoncomputable def to_dual (B : bilin_form K V) (hB : B.nondegenerate) :\n  V \u2243\u2097[K] module.dual K V :=\nB.to_lin.linear_equiv_of_ker_eq_bot\n  (nondegenerate_iff_ker_eq_bot.mp hB) subspace.dual_finrank_eq.symm\n\nlemma to_dual_def {B : bilin_form K V} (hB : B.nondegenerate) {m n : V} :\n  B.to_dual hB m n = B m n := rfl\n\nend\n\n/-! We note that we cannot use `bilin_form.restrict_nondegenerate_iff_is_compl_orthogonal` for the\nlemma below since the below lemma does not require `V` to be finite dimensional. However,\n`bilin_form.restrict_nondegenerate_iff_is_compl_orthogonal` does not require `B` to be nondegenerate\non the whole space. -/\n\n/-- The restriction of a symmetric, non-degenerate bilinear form on the orthogonal complement of\nthe span of a singleton is also non-degenerate. -/\nlemma restrict_orthogonal_span_singleton_nondegenerate (B : bilin_form K V)\n  (hB\u2081 : nondegenerate B) (hB\u2082 : sym_bilin_form.is_sym B) {x : V} (hx : \u00ac B.is_ortho x x) :\n  nondegenerate $ B.restrict $ B.orthogonal (K \u2219 x) :=\nbegin\n  refine \u03bb m hm, submodule.coe_eq_zero.1 (hB\u2081 m.1 (\u03bb n, _)),\n  have : n \u2208 (K \u2219 x) \u2294 B.orthogonal (K \u2219 x) :=\n    (span_singleton_sup_orthogonal_eq_top hx).symm \u25b8 submodule.mem_top,\n  rcases submodule.mem_sup.1 this with \u27e8y, hy, z, hz, rfl\u27e9,\n  specialize hm \u27e8z, hz\u27e9,\n  rw restrict at hm,\n  erw [add_right, show B m.1 y = 0, by rw hB\u2082; exact m.2 y hy, hm, add_zero]\nend\n\nsection linear_adjoints\n\nlemma comp_left_injective (B : bilin_form R\u2081 M\u2081) (hB : B.nondegenerate) :\n  function.injective B.comp_left :=\n\u03bb \u03c6 \u03c8 h, begin\n  ext w,\n  refine eq_of_sub_eq_zero (hB _ _),\n  intro v,\n  rw [sub_left, \u2190 comp_left_apply, \u2190 comp_left_apply, \u2190 h, sub_self]\nend\n\nlemma is_adjoint_pair_unique_of_nondegenerate (B : bilin_form R\u2081 M\u2081) (hB : B.nondegenerate)\n  (\u03c6 \u03c8\u2081 \u03c8\u2082 : M\u2081 \u2192\u2097[R\u2081] M\u2081) (h\u03c8\u2081 : is_adjoint_pair B B \u03c8\u2081 \u03c6) (h\u03c8\u2082 : is_adjoint_pair B B \u03c8\u2082 \u03c6) :\n  \u03c8\u2081 = \u03c8\u2082 :=\nB.comp_left_injective hB $ ext $ \u03bb v w, by rw [comp_left_apply, comp_left_apply, h\u03c8\u2081, h\u03c8\u2082]\n\nvariable [finite_dimensional K V]\n\n/-- Given bilinear forms `B\u2081, B\u2082` where `B\u2082` is nondegenerate, `symm_comp_of_nondegenerate`\nis the linear map `B\u2082.to_lin\u207b\u00b9 \u2218 B\u2081.to_lin`. -/\nnoncomputable def symm_comp_of_nondegenerate\n  (B\u2081 B\u2082 : bilin_form K V) (hB\u2082 : B\u2082.nondegenerate) : V \u2192\u2097[K] V :=\n(B\u2082.to_dual hB\u2082).symm.to_linear_map.comp B\u2081.to_lin\n\nlemma comp_symm_comp_of_nondegenerate_apply (B\u2081 : bilin_form K V)\n  {B\u2082 : bilin_form K V} (hB\u2082 : B\u2082.nondegenerate) (v : V) :\n  to_lin B\u2082 (B\u2081.symm_comp_of_nondegenerate B\u2082 hB\u2082 v) = to_lin B\u2081 v :=\nby erw [symm_comp_of_nondegenerate, linear_equiv.apply_symm_apply (B\u2082.to_dual hB\u2082) _]\n\n@[simp]\nlemma symm_comp_of_nondegenerate_left_apply (B\u2081 : bilin_form K V)\n  {B\u2082 : bilin_form K V} (hB\u2082 : B\u2082.nondegenerate) (v w : V) :\n  B\u2082 (symm_comp_of_nondegenerate B\u2081 B\u2082 hB\u2082 w) v = B\u2081 w v :=\nbegin\n  conv_lhs { rw [\u2190 bilin_form.to_lin_apply, comp_symm_comp_of_nondegenerate_apply] },\n  refl,\nend\n\n/-- Given the nondegenerate bilinear form `B` and the linear map `\u03c6`,\n`left_adjoint_of_nondegenerate` provides the left adjoint of `\u03c6` with respect to `B`.\nThe lemma proving this property is `bilin_form.is_adjoint_pair_left_adjoint_of_nondegenerate`. -/\nnoncomputable def left_adjoint_of_nondegenerate\n  (B : bilin_form K V) (hB : B.nondegenerate) (\u03c6 : V \u2192\u2097[K] V) : V \u2192\u2097[K] V :=\nsymm_comp_of_nondegenerate (B.comp_right \u03c6) B hB\n\nlemma is_adjoint_pair_left_adjoint_of_nondegenerate\n  (B : bilin_form K V) (hB : B.nondegenerate) (\u03c6 : V \u2192\u2097[K] V) :\n  is_adjoint_pair B B (B.left_adjoint_of_nondegenerate hB \u03c6) \u03c6 :=\n\u03bb x y, (B.comp_right \u03c6).symm_comp_of_nondegenerate_left_apply hB y x\n\n/-- Given the nondegenerate bilinear form `B`, the linear map `\u03c6` has a unique left adjoint given by\n`bilin_form.left_adjoint_of_nondegenerate`. -/\ntheorem is_adjoint_pair_iff_eq_of_nondegenerate\n  (B : bilin_form K V) (hB : B.nondegenerate) (\u03c8 \u03c6 : V \u2192\u2097[K] V) :\n  is_adjoint_pair B B \u03c8 \u03c6 \u2194 \u03c8 = B.left_adjoint_of_nondegenerate hB \u03c6 :=\n\u27e8\u03bb h, B.is_adjoint_pair_unique_of_nondegenerate hB \u03c6 \u03c8 _ h\n   (is_adjoint_pair_left_adjoint_of_nondegenerate _ _ _),\n \u03bb h, h.symm \u25b8 is_adjoint_pair_left_adjoint_of_nondegenerate _ _ _\u27e9\n\nend linear_adjoints\n\nend bilin_form\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/linear_algebra/bilinear_form.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.712520071010629}}
{"text": "/-\nCopyright \u00a9 2018 Fran\u00e7ois G. Dorais. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n-/\n\ntheorem fin.choice : \u03a0 {n : \u2115} {C : fin n \u2192 Sort*}, \n(\u2200 i, nonempty (C i)) \u2192 nonempty (\u03a0 i, C i)\n| 0 _ _ := nonempty.intro (\u03bb i, fin.elim0 i)\n| (n+1) C h := \n  have h0 : nonempty (C 0), from h 0,\n  have hs : nonempty (\u03a0 i, C (fin.succ i)), from fin.choice (\u03bb i, h (fin.succ i)),\n  nonempty.elim hs $ nonempty.elim h0 $ \u03bb c0 cs, \n  nonempty.intro $ \u03bb i, \n  match i with\n  | \u27e80, _\u27e9 := c0\n  | \u27e8i+1, h\u27e9 := cs \u27e8i, nat.lt_of_succ_lt_succ h\u27e9 \n  end\n", "meta": {"author": "fgdorais", "repo": "tup", "sha": "ac4a2f8ca2ccc8aea091498439a0a47d43ac4700", "save_path": "github-repos/lean/fgdorais-tup", "path": "github-repos/lean/fgdorais-tup/tup-ac4a2f8ca2ccc8aea091498439a0a47d43ac4700/src/fin/choice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7125200644835076}}
{"text": "open classical\n\n--  Proving double negation implies excluded middle\n\nvariables p q : Prop\n\ntheorem dne {p : Prop} (H : \u00ac\u00acp) : p :=\n    or.elim (em p)\n    (assume Hp : p, Hp)\n    (assume Hnp : \u00acp, absurd Hnp H)\n\ntheorem help3 (negated : \u00ac(p \u2228 \u00acp)) : \u00acp \u2227 \u00ac\u00acp :=\n    and.intro\n        (assume Hp : p, \n            show false, from negated (or.intro_left (\u00acp) Hp))\n        (assume Hp : \u00acp,\n            show false, from negated (or.intro_right p Hp))\n\ntheorem help2 (single_negated : \u00ac(p \u2228 \u00acp)) : false :=\n    have Hp : \u00acp \u2227 \u00ac\u00acp, from help3 p single_negated,\n    show false, from (and.elim_right Hp (and.elim_left Hp))\n\ntheorem emm_ : p \u2228 \u00acp := dne (help2 p)\n\ncheck emm_ \n", "meta": {"author": "0xpr", "repo": "lean_tutorial", "sha": "56ef609d8df9e392916012db5354bf182cbbb8d8", "save_path": "github-repos/lean/0xpr-lean_tutorial", "path": "github-repos/lean/0xpr-lean_tutorial/lean_tutorial-56ef609d8df9e392916012db5354bf182cbbb8d8/em_dne.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552536, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7124417869653441}}
{"text": "structure Graph' where\n  V : Type\n  E : Type\n  init : E \u2192 V\n  bar : E \u2192 E\n  barInv : bar \u2218 bar = id\n  barNoFP : \u2200 e: E, bar e \u2260 e\n\nstructure Graph(V: Type) (E: Type) where\n  init : E \u2192 V\n  bar : E \u2192 E\n  barInv : bar \u2218 bar = id\n  barNoFP : \u2200 e: E, bar e \u2260 e\n\n@[inline] def term{V: Type}{E: Type}(graph: Graph V E): E \u2192 V :=\n  fun e => graph.init (graph.bar e)\n\nexample : Graph Unit Bool:= \n  let init : Bool \u2192 Unit := fun e => ()\n  let bar : Bool \u2192 Bool := fun e => \u00ac e\n  let barInv : bar \u2218 bar = id := by \n    apply funext ; intro x ; cases x <;> rfl  \n  let barNoFP : \u2200 e: Bool, bar e \u2260 e := by\n    intro e; cases e <;> simp\n  \u27e8init, bar, barInv, barNoFP\u27e9\n\nexample : Graph Unit Bool:= by\n  apply Graph.mk\n  case init => \n    intro x; exact ()\n  case bar =>\n    intro x\n    exact not x\n  case barInv =>\n    apply funext ; intro x ; cases x <;> rfl  \n  case barNoFP =>\n    intro e; cases e <;> simp\n\ninductive EdgePath{V: Type}{E: Type}(graph: Graph V E): V \u2192 V \u2192 Type where\n  | single : (x: V) \u2192 EdgePath graph v v\n  | cons : {x y z : V} \u2192 (e : E) \u2192 graph.init e = x \u2192 term graph e = y \u2192  \n        EdgePath graph y z \u2192 EdgePath graph x z\n\ndef length{V: Type}{E: Type}{graph: Graph V E}{x y: V}: EdgePath graph x y \u2192 Nat\n  | EdgePath.single x => 0\n  | EdgePath.cons  _ _ _ path => length path + 1 \n", "meta": {"author": "siddhartha-gadgil", "repo": "Polylean", "sha": "3b411dc1dca8c84ab221cc544d1ae3bd4f83de5a", "save_path": "github-repos/lean/siddhartha-gadgil-Polylean", "path": "github-repos/lean/siddhartha-gadgil-Polylean/Polylean-3b411dc1dca8c84ab221cc544d1ae3bd4f83de5a/Experiments/Graph.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7124417706825762}}
{"text": "import Mathlib.Data.Rat.Order\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Existsi\nimport BrownCs22.Demos.Readme\n\n/- 4 points -/\ntheorem problem1 {a b : \u211a} (h1 : a - b = 4) (h2 : a * b = 1) :\n    (a + b) ^ 2 = 20 :=\n  calc (a + b) ^ 2 = (a - b) ^ 2 + 4 * (a * b) := by ring\n  _ = 4 ^ 2 + 4 * 1 := by rw [h1, h2]\n  _ = 20 := by ring\n\n/- 2 points -/\ntheorem problem2 {a : \u211a} (h : \u2203 b : \u211a, a = b ^ 2) : a \u2265 0 := by\n  cases' h with b hb\n  calc a = b ^ 2 := hb\n  _ \u2265 0 := by apply sq_nonneg\n\ntheorem you_might_use_this_theorem_in_your_answer :\n    1 + 1 = 2 := by\n  norm_num\n\n/- 4 points -/\ntheorem problem3 : \u2203 n : \u2124, 12 * n = 84 := by\n  existsi 7\n  norm_num", "meta": {"author": "robertylewis", "repo": "leanclass", "sha": "f609276675431388632d46619581bdb7c557be50", "save_path": "github-repos/lean/robertylewis-leanclass", "path": "github-repos/lean/robertylewis-leanclass/leanclass-f609276675431388632d46619581bdb7c557be50/BrownCs22/Exercises/submission.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7124018942673578}}
{"text": "import game.world_01_tutorial\nnamespace mynat\n\nlemma zero_add (n : mynat) : 0 + n = n := begin[nat_num_game]\n  induction n,\n  rwa add_zero,\n  rwa [add_succ, n_ih],\nend\n\nlemma add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) := begin[nat_num_game]\n  induction c,\n  rwa [add_zero, add_zero],\n  rwa [add_succ, add_succ, add_succ, c_ih],\nend\n\nlemma succ_add (a b : mynat) : succ a + b = succ (a + b) := begin[nat_num_game]\n  induction b,\n  rwa [add_zero, add_zero],\n  rwa [add_succ, add_succ, b_ih],\nend\n\nlemma add_comm (a b : mynat) : a + b = b + a := begin[nat_num_game]\n  induction b,\n  rwa [add_zero, zero_add],\n  rwa [add_succ, succ_add, b_ih],\nend\n\ntheorem succ_eq_add_one (n : mynat) : succ n = n + 1 := begin[nat_num_game]\n  induction n,\n  rwa [one_eq_succ_zero, add_succ, add_zero],\n  rwa [succ_add, n_ih],\nend\n\nlemma add_right_comm (a b c : mynat) : a + b + c = a + c + b := begin[nat_num_game]\n  rwa [add_assoc, add_assoc, add_comm(b)],\nend\n\nend mynat\n", "meta": {"author": "lacrosse", "repo": "natural_number_game", "sha": "400179cde1d3fcc9744901dabff98813ba2b544f", "save_path": "github-repos/lean/lacrosse-natural_number_game", "path": "github-repos/lean/lacrosse-natural_number_game/natural_number_game-400179cde1d3fcc9744901dabff98813ba2b544f/src/game/world_02_addition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.712401892493972}}
{"text": "import tactic\n\nstructure graph := (V : \u2115)\n  (E : \u2115 \u2192 \u2115 \u2192 bool)\n  (E_irreflexive : \u2200 x : \u2115, x < V \u2192 \u00ac E x x)\n  (E_symmetric : \u2200 x y : \u2115, x < V \u2192 y < V \u2192 E x y \u2192 E y x)\n\ndef K (n: \u2115): graph := begin\n  refine_struct ({\n    V := n, \n    E := (\u03bb x, \u03bb y, x \u2260 y),\n  }),\n  simp,\n  intros,\n  cc,\nend\n\ndef Path (n: \u2115): graph := begin\n  refine_struct ({\n    V := n, \n    E := (\u03bb x, \u03bb y, nat.succ x = y \u2228 x = nat.succ y),\n  }),\n  simp,\n  intros,\n  omega,\n  simp,\n  tauto,\nend\n\ndef Empty (n: \u2115): graph := begin\n  refine_struct ({\n    V := n, \n    E := (\u03bb x, \u03bb y, false),\n  }),\n  tauto,\n  tauto,\nend\n\ndef sum_fun : (\u2115 \u2192 \u2115) -> \u2115 \u2192 \u2115\n| m 0 := 0\n| m (n + 1) := m n + sum_fun m n\n\nnotation `\u2211` binders ` to ` n `, ` r:(scoped:67 f, sum_fun f n) := r\n-- this means `\u2211 x to n, foo` denotes `sum_fun (\u03bb x, foo) n`\n-- the `\u2211` is entered using \\sum\n\ndef edges (G : graph) : \u2115 :=\n\u2211 x to G.V, \u2211 y to x, if G.E x y then 1 else 0\n\ndef degree (G : graph) (x : \u2115) : \u2115 :=\n\u2211 y to G.V, if G.E x y then 1 else 0\n\ndef darts (G : graph) : \u2115 :=\n\u2211 x to G.V, \u2211 y to G.V, if G.E x y then 1 else 0\n\n@[simp]\nlemma sum_to_zero_eq (f : \u2115 \u2192 \u2115) : \u2211 x to 0, f x = 0 := rfl\n\n@[simp]\nlemma sum_zero_eq (n : \u2115) : \u2211 x to n, 0 = 0 :=\nbegin\n  induction n,\n  rw sum_to_zero_eq,\n  dunfold sum_fun,\n  rw n_ih,\nend\n\nlemma sum_add_eq_add_sum (f g : \u2115 \u2192 \u2115) (n : \u2115) :\n  \u2211 x to n, (f x + g x) = \u2211 x to n, f x + \u2211 x to n, g x :=\nbegin\n  induction n,\n  { simp, },\n  { dunfold sum_fun,\n    rw n_ih,\n    ring, }\nend\n\nlemma sum_if_true (f g : \u2115 \u2192 \u2115) (p : \u2115 \u2192 Prop) [decidable_pred p] (n : \u2115) (h : \u2200 x, x < n \u2192 p x) :\n  \u2211 x to n, (if p x then f x else g x) = \u2211 x to n, f x :=\nbegin\n  induction n,\n  { simp },\n  { dunfold sum_fun,\n    have k := h n_n (lt_add_one _),\n    simp [k],\n    rw n_ih,\n    intros x hlt, apply h, exact nat.lt.step hlt, }\nend\n\nlemma sum_if_false (f g : \u2115 \u2192 \u2115) (p : \u2115 \u2192 Prop) [decidable_pred p] (n : \u2115) (h : \u2200 x, x < n \u2192 \u00ac p x) :\n  \u2211 x to n, (if p x then f x else g x) = \u2211 x to n, g x :=\nbegin\n  induction n,\n  { simp },\n  { dunfold sum_fun,\n    have k := h n_n (lt_add_one _),\n    simp [k],\n    rw n_ih,\n    intros x hlt, apply h, exact nat.lt.step hlt, }\nend\n\nlemma sum_fun_restrict' (f : \u2115 \u2192 \u2115) (n m : \u2115) :\n  \u2211 x to n, f x = \u2211 x to n + m, if x < n then f x else 0 :=\nbegin\n  induction m,\n  { rw sum_if_true,\n    simp, simp, },\n  { rw nat.add_succ,\n    dunfold sum_fun,\n    rw \u2190m_ih,\n    split_ifs,\n    exfalso, linarith,\n    simp, },\nend\n\nlemma sum_fun_restrict (f : \u2115 \u2192 \u2115) (n m : \u2115) (h : n \u2264 m) :\n  \u2211 x to n, f x = \u2211 x to m, if x < n then f x else 0 :=\nbegin\n  rw sum_fun_restrict' f n (m - n),\n  rw nat.add_sub_of_le h,\nend\n\nlemma sum_congr (f g : \u2115 \u2192 \u2115) (n : \u2115) (h : \u2200 x < n, f x = g x) :\n  \u2211 x to n, f x = \u2211 x to n, g x :=\nbegin\n  induction n,\n  { simp },\n  { dunfold sum_fun,\n    rw [h, n_ih],\n    intros x h', apply h, apply nat.lt.step h',\n    apply lt_add_one, },\nend\n\nlemma swap_sum (f : \u2115 \u2192 \u2115 \u2192 \u2115) (n m : \u2115) : \u2211 x to n, \u2211 y to m, f x y = \u2211 y to m, \u2211 x to n, f x y :=\nbegin\n  induction n generalizing m,\n  { simp, },\n  { dunfold sum_fun,\n    rw sum_add_eq_add_sum,\n    rw n_ih, }\nend\n\n@[simp]\nlemma indic_indic_eq_and (a b : Prop) [decidable a] [decidable b]:\n  (if a then (if b then 1 else 0) else 0) = (if a \u2227 b then 1 else 0) :=\nbegin\n  split_ifs; try { refl <|> { exfalso, cc } },\nend\n\nlemma darts_eq_twice_edges (G : graph) : darts G = 2 * edges G :=\nbegin\n  dsimp only [darts, edges],\n  have key := \u03bb x (h : x < G.V), sum_fun_restrict (\u03bb y, if G.E x y then 1 else 0) x G.V (by linarith),\n  rw sum_congr _ _ _ key, clear key,\n  simp,\n  rw two_mul,\n  conv_rhs { congr, rw swap_sum, },\n  rw \u2190sum_add_eq_add_sum,\n  apply sum_congr,\n  intros x xel,\n  rw \u2190sum_add_eq_add_sum,\n  apply sum_congr,\n  intros y yel,\n  by_cases h : (G.E x y : Prop),\n  simp [h, G.E_symmetric x y xel yel h],\n  split_ifs; try { refl <|> cc },\n  exfalso, exact nat.lt_asymm h_1 h_2,\n  exfalso,\n  have h' : x = y := by linarith,\n  subst x, exact G.E_irreflexive _ yel h,\n  have h' : \u00ac G.E y x,\n  { revert h, contrapose, push_neg, exact G.E_symmetric y x yel xel },\n  simp [h, h'],\nend\n\nlemma darts_eq_sum_degrees (G : graph) : darts G = \u2211 x to G.V, degree G x := rfl\n\ntheorem sum_degrees (G : graph) : \u2211 x to G.V, degree G x = 2 * edges G :=\nbegin\n  rw \u2190darts_eq_sum_degrees,\n  rw \u2190darts_eq_twice_edges,\nend\n", "meta": {"author": "modderme123", "repo": "lean-graph", "sha": "d47ea22cc0ec82f2ae073393c029be67ca8a82ad", "save_path": "github-repos/lean/modderme123-lean-graph", "path": "github-repos/lean/modderme123-lean-graph/lean-graph-d47ea22cc0ec82f2ae073393c029be67ca8a82ad/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7123452913822147}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n\n! This file was ported from Lean 3 source module group_theory.perm.cycle.concrete\n! leanprover-community/mathlib commit 00638177efd1b2534fc5269363ebf42a7871df9a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.List.Cycle\nimport Mathbin.GroupTheory.Perm.Cycle.Type\nimport Mathbin.GroupTheory.Perm.List\n\n/-!\n\n# Properties of cyclic permutations constructed from lists/cycles\n\nIn the following, `{\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1]`.\n\n## Main definitions\n\n* `cycle.form_perm`: the cyclic permutation created by looping over a `cycle \u03b1`\n* `equiv.perm.to_list`: the list formed by iterating application of a permutation\n* `equiv.perm.to_cycle`: the cycle formed by iterating application of a permutation\n* `equiv.perm.iso_cycle`: the equivalence between cyclic permutations `f : perm \u03b1`\n  and the terms of `cycle \u03b1` that correspond to them\n* `equiv.perm.iso_cycle'`: the same equivalence as `equiv.perm.iso_cycle`\n  but with evaluation via choosing over fintypes\n* The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)`\n* A `has_repr` instance for any `perm \u03b1`, by representing the `finset` of\n  `cycle \u03b1` that correspond to the cycle factors.\n\n## Main results\n\n* `list.is_cycle_form_perm`: a nontrivial list without duplicates, when interpreted as\n  a permutation, is cyclic\n* `equiv.perm.is_cycle.exists_unique_cycle`: there is only one nontrivial `cycle \u03b1`\n  corresponding to each cyclic `f : perm \u03b1`\n\n## Implementation details\n\nThe forward direction of `equiv.perm.iso_cycle'` uses `fintype.choose` of the uniqueness\nresult, relying on the `fintype` instance of a `cycle.nodup` subtype.\nIt is unclear if this works faster than the `equiv.perm.to_cycle`, which relies\non recursion over `finset.univ`.\nRunning `#eval` on even a simple noncyclic permutation `c[(1 : fin 7), 2, 3] * c[0, 5]`\nto show it takes a long time. TODO: is this because computing the cycle factors is slow?\n\n-/\n\n\nopen Equiv Equiv.Perm List\n\nvariable {\u03b1 : Type _}\n\nnamespace List\n\nvariable [DecidableEq \u03b1] {l l' : List \u03b1}\n\ntheorem formPerm_disjoint_iff (hl : Nodup l) (hl' : Nodup l') (hn : 2 \u2264 l.length)\n    (hn' : 2 \u2264 l'.length) : Perm.Disjoint (formPerm l) (formPerm l') \u2194 l.Disjoint l' :=\n  by\n  rw [disjoint_iff_eq_or_eq, List.Disjoint]\n  constructor\n  \u00b7 rintro h x hx hx'\n    specialize h x\n    rw [form_perm_apply_mem_eq_self_iff _ hl _ hx, form_perm_apply_mem_eq_self_iff _ hl' _ hx'] at h\n    rcases h with (hl | hl') <;> linarith\n  \u00b7 intro h x\n    by_cases hx : x \u2208 l\n    by_cases hx' : x \u2208 l'\n    \u00b7 exact (h hx hx').elim\n    all_goals have := form_perm_eq_self_of_not_mem _ _ \u2039_\u203a; tauto\n#align list.form_perm_disjoint_iff List.formPerm_disjoint_iff\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem isCycle_formPerm (hl : Nodup l) (hn : 2 \u2264 l.length) : IsCycle (formPerm l) :=\n  by\n  cases' l with x l\n  \u00b7 norm_num at hn\n  induction' l with y l IH generalizing x\n  \u00b7 norm_num at hn\n  \u00b7 use x\n    constructor\n    \u00b7 rwa [form_perm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _)]\n    \u00b7 intro w hw\n      have : w \u2208 x::y::l := mem_of_form_perm_ne_self _ _ hw\n      obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem this\n      use k\n      simp only [zpow_ofNat, form_perm_pow_apply_head _ _ hl k, Nat.mod_eq_of_lt hk]\n#align list.is_cycle_form_perm List.isCycle_formPerm\n\ntheorem pairwise_sameCycle_formPerm (hl : Nodup l) (hn : 2 \u2264 l.length) :\n    Pairwise l.formPerm.SameCycle l :=\n  Pairwise.imp_mem.mpr\n    (pairwise_of_forall fun x y hx hy =>\n      (isCycle_formPerm hl hn).SameCycle ((formPerm_apply_mem_ne_self_iff _ hl _ hx).mpr hn)\n        ((formPerm_apply_mem_ne_self_iff _ hl _ hy).mpr hn))\n#align list.pairwise_same_cycle_form_perm List.pairwise_sameCycle_formPerm\n\ntheorem cycleOf_formPerm (hl : Nodup l) (hn : 2 \u2264 l.length) (x) :\n    cycleOf l.attach.formPerm x = l.attach.formPerm :=\n  have hn : 2 \u2264 l.attach.length := by rwa [\u2190 length_attach] at hn\n  have hl : l.attach.Nodup := by rwa [\u2190 nodup_attach] at hl\n  (isCycle_formPerm hl hn).cycleOf_eq\n    ((formPerm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn)\n#align list.cycle_of_form_perm List.cycleOf_formPerm\n\ntheorem cycleType_formPerm (hl : Nodup l) (hn : 2 \u2264 l.length) :\n    cycleType l.attach.formPerm = {l.length} :=\n  by\n  rw [\u2190 length_attach] at hn\n  rw [\u2190 nodup_attach] at hl\n  rw [cycle_type_eq [l.attach.form_perm]]\n  \u00b7 simp only [map, Function.comp_apply]\n    rw [support_form_perm_of_nodup _ hl, card_to_finset, dedup_eq_self.mpr hl]\n    \u00b7 simp\n    \u00b7 intro x h\n      simpa [h, Nat.succ_le_succ_iff] using hn\n  \u00b7 simp\n  \u00b7 simpa using is_cycle_form_perm hl hn\n  \u00b7 simp\n#align list.cycle_type_form_perm List.cycleType_formPerm\n\ntheorem formPerm_apply_mem_eq_next (hl : Nodup l) (x : \u03b1) (hx : x \u2208 l) :\n    formPerm l x = next l x hx :=\n  by\n  obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx\n  rw [next_nth_le _ hl, form_perm_apply_nth_le _ hl]\n#align list.form_perm_apply_mem_eq_next List.formPerm_apply_mem_eq_next\n\nend List\n\nnamespace Cycle\n\nvariable [DecidableEq \u03b1] (s s' : Cycle \u03b1)\n\n/-- A cycle `s : cycle \u03b1` , given `nodup s` can be interpreted as a `equiv.perm \u03b1`\nwhere each element in the list is permuted to the next one, defined as `form_perm`.\n-/\ndef formPerm : \u2200 (s : Cycle \u03b1) (h : Nodup s), Equiv.Perm \u03b1 := fun s =>\n  Quot.hrecOn s (fun l h => formPerm l) fun l\u2081 l\u2082 (h : l\u2081 ~r l\u2082) =>\n    by\n    ext\n    \u00b7 exact h.nodup_iff\n    \u00b7 intro h\u2081 h\u2082 _\n      exact hEq_of_eq (form_perm_eq_of_is_rotated h\u2081 h)\n#align cycle.form_perm Cycle.formPerm\n\n@[simp]\ntheorem formPerm_coe (l : List \u03b1) (hl : l.Nodup) : formPerm (l : Cycle \u03b1) hl = l.formPerm :=\n  rfl\n#align cycle.form_perm_coe Cycle.formPerm_coe\n\ntheorem formPerm_subsingleton (s : Cycle \u03b1) (h : Subsingleton s) : formPerm s h.Nodup = 1 :=\n  by\n  induction s using Quot.inductionOn\n  simp only [form_perm_coe, mk_eq_coe]\n  simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h\n  cases' s with hd tl\n  \u00b7 simp\n  \u00b7 simp only [length_eq_zero, add_le_iff_nonpos_left, List.length, nonpos_iff_eq_zero] at h\n    simp [h]\n#align cycle.form_perm_subsingleton Cycle.formPerm_subsingleton\n\ntheorem isCycle_formPerm (s : Cycle \u03b1) (h : Nodup s) (hn : Nontrivial s) : IsCycle (formPerm s h) :=\n  by\n  induction s using Quot.inductionOn\n  exact List.isCycle_formPerm h (length_nontrivial hn)\n#align cycle.is_cycle_form_perm Cycle.isCycle_formPerm\n\ntheorem support_formPerm [Fintype \u03b1] (s : Cycle \u03b1) (h : Nodup s) (hn : Nontrivial s) :\n    support (formPerm s h) = s.toFinset :=\n  by\n  induction s using Quot.inductionOn\n  refine' support_form_perm_of_nodup s h _\n  rintro _ rfl\n  simpa [Nat.succ_le_succ_iff] using length_nontrivial hn\n#align cycle.support_form_perm Cycle.support_formPerm\n\ntheorem formPerm_eq_self_of_not_mem (s : Cycle \u03b1) (h : Nodup s) (x : \u03b1) (hx : x \u2209 s) :\n    formPerm s h x = x := by\n  induction s using Quot.inductionOn\n  simpa using List.formPerm_eq_self_of_not_mem _ _ hx\n#align cycle.form_perm_eq_self_of_not_mem Cycle.formPerm_eq_self_of_not_mem\n\ntheorem formPerm_apply_mem_eq_next (s : Cycle \u03b1) (h : Nodup s) (x : \u03b1) (hx : x \u2208 s) :\n    formPerm s h x = next s h x hx :=\n  by\n  induction s using Quot.inductionOn\n  simpa using List.formPerm_apply_mem_eq_next h _ _\n#align cycle.form_perm_apply_mem_eq_next Cycle.formPerm_apply_mem_eq_next\n\ntheorem formPerm_reverse (s : Cycle \u03b1) (h : Nodup s) :\n    formPerm s.reverse (nodup_reverse_iff.mpr h) = (formPerm s h)\u207b\u00b9 :=\n  by\n  induction s using Quot.inductionOn\n  simpa using form_perm_reverse _ h\n#align cycle.form_perm_reverse Cycle.formPerm_reverse\n\ntheorem formPerm_eq_formPerm_iff {\u03b1 : Type _} [DecidableEq \u03b1] {s s' : Cycle \u03b1} {hs : s.Nodup}\n    {hs' : s'.Nodup} :\n    s.formPerm hs = s'.formPerm hs' \u2194 s = s' \u2228 s.Subsingleton \u2227 s'.Subsingleton :=\n  by\n  rw [Cycle.length_subsingleton_iff, Cycle.length_subsingleton_iff]\n  revert s s'\n  intro s s'\n  apply Quotient.inductionOn\u2082' s s'\n  intro l l'\n  simpa using form_perm_eq_form_perm_iff\n#align cycle.form_perm_eq_form_perm_iff Cycle.formPerm_eq_formPerm_iff\n\nend Cycle\n\nnamespace Equiv.Perm\n\nsection Fintype\n\nvariable [Fintype \u03b1] [DecidableEq \u03b1] (p : Equiv.Perm \u03b1) (x : \u03b1)\n\n/-- `equiv.perm.to_list (f : perm \u03b1) (x : \u03b1)` generates the list `[x, f x, f (f x), ...]`\nuntil looping. That means when `f x = x`, `to_list f x = []`.\n-/\ndef toList : List \u03b1 :=\n  (List.range (cycleOf p x).support.card).map fun k => (p ^ k) x\n#align equiv.perm.to_list Equiv.Perm.toList\n\n@[simp]\ntheorem toList_one : toList (1 : Perm \u03b1) x = [] := by simp [to_list, cycle_of_one]\n#align equiv.perm.to_list_one Equiv.Perm.toList_one\n\n@[simp]\ntheorem toList_eq_nil_iff {p : Perm \u03b1} {x} : toList p x = [] \u2194 x \u2209 p.support := by simp [to_list]\n#align equiv.perm.to_list_eq_nil_iff Equiv.Perm.toList_eq_nil_iff\n\n@[simp]\ntheorem length_toList : length (toList p x) = (cycleOf p x).support.card := by simp [to_list]\n#align equiv.perm.length_to_list Equiv.Perm.length_toList\n\ntheorem toList_ne_singleton (y : \u03b1) : toList p x \u2260 [y] :=\n  by\n  intro H\n  simpa [card_support_ne_one] using congr_arg length H\n#align equiv.perm.to_list_ne_singleton Equiv.Perm.toList_ne_singleton\n\ntheorem two_le_length_toList_iff_mem_support {p : Perm \u03b1} {x : \u03b1} :\n    2 \u2264 length (toList p x) \u2194 x \u2208 p.support := by simp\n#align equiv.perm.two_le_length_to_list_iff_mem_support Equiv.Perm.two_le_length_toList_iff_mem_support\n\ntheorem length_toList_pos_of_mem_support (h : x \u2208 p.support) : 0 < length (toList p x) :=\n  zero_lt_two.trans_le (two_le_length_toList_iff_mem_support.mpr h)\n#align equiv.perm.length_to_list_pos_of_mem_support Equiv.Perm.length_toList_pos_of_mem_support\n\ntheorem nthLe_toList (n : \u2115) (hn : n < length (toList p x)) : nthLe (toList p x) n hn = (p ^ n) x :=\n  by simp [to_list]\n#align equiv.perm.nth_le_to_list Equiv.Perm.nthLe_toList\n\ntheorem toList_nthLe_zero (h : x \u2208 p.support) :\n    (toList p x).nthLe 0 (length_toList_pos_of_mem_support _ _ h) = x := by simp [to_list]\n#align equiv.perm.to_list_nth_le_zero Equiv.Perm.toList_nthLe_zero\n\nvariable {p} {x}\n\ntheorem mem_toList_iff {y : \u03b1} : y \u2208 toList p x \u2194 SameCycle p x y \u2227 x \u2208 p.support :=\n  by\n  simp only [to_list, mem_range, mem_map]\n  constructor\n  \u00b7 rintro \u27e8n, hx, rfl\u27e9\n    refine' \u27e8\u27e8n, rfl\u27e9, _\u27e9\n    contrapose! hx\n    rw [\u2190 support_cycle_of_eq_nil_iff] at hx\n    simp [hx]\n  \u00b7 rintro \u27e8h, hx\u27e9\n    simpa using h.exists_pow_eq_of_mem_support hx\n#align equiv.perm.mem_to_list_iff Equiv.Perm.mem_toList_iff\n\ntheorem nodup_toList (p : Perm \u03b1) (x : \u03b1) : Nodup (toList p x) :=\n  by\n  by_cases hx : p x = x\n  \u00b7 rw [\u2190 not_mem_support, \u2190 to_list_eq_nil_iff] at hx\n    simp [hx]\n  have hc : is_cycle (cycle_of p x) := is_cycle_cycle_of p hx\n  rw [nodup_iff_nth_le_inj]\n  rintro n m hn hm\n  rw [length_to_list, \u2190 hc.order_of] at hm hn\n  rw [\u2190 cycle_of_apply_self, \u2190 Ne.def, \u2190 mem_support] at hx\n  rw [nth_le_to_list, nth_le_to_list, \u2190 cycle_of_pow_apply_self p x n, \u2190\n    cycle_of_pow_apply_self p x m]\n  cases n <;> cases m\n  \u00b7 simp\n  \u00b7 rw [\u2190 hc.support_pow_of_pos_of_lt_order_of m.zero_lt_succ hm, mem_support,\n      cycle_of_pow_apply_self] at hx\n    simp [hx.symm]\n  \u00b7 rw [\u2190 hc.support_pow_of_pos_of_lt_order_of n.zero_lt_succ hn, mem_support,\n      cycle_of_pow_apply_self] at hx\n    simp [hx]\n  intro h\n  have hn' : \u00acorderOf (p.cycle_of x) \u2223 n.succ := Nat.not_dvd_of_pos_of_lt n.zero_lt_succ hn\n  have hm' : \u00acorderOf (p.cycle_of x) \u2223 m.succ := Nat.not_dvd_of_pos_of_lt m.zero_lt_succ hm\n  rw [\u2190 hc.support_pow_eq_iff] at hn' hm'\n  rw [\u2190 Nat.mod_eq_of_lt hn, \u2190 Nat.mod_eq_of_lt hm, \u2190 pow_inj_mod]\n  refine' support_congr _ _\n  \u00b7 rw [hm', hn']\n    exact Finset.Subset.refl _\n  \u00b7 rw [hm']\n    intro y hy\n    obtain \u27e8k, rfl\u27e9 := hc.exists_pow_eq (mem_support.mp hx) (mem_support.mp hy)\n    rw [\u2190 mul_apply, (Commute.pow_pow_self _ _ _).Eq, mul_apply, h, \u2190 mul_apply, \u2190 mul_apply,\n      (Commute.pow_pow_self _ _ _).Eq]\n#align equiv.perm.nodup_to_list Equiv.Perm.nodup_toList\n\ntheorem next_toList_eq_apply (p : Perm \u03b1) (x y : \u03b1) (hy : y \u2208 toList p x) :\n    next (toList p x) y hy = p y := by\n  rw [mem_to_list_iff] at hy\n  obtain \u27e8k, hk, hk'\u27e9 := hy.left.exists_pow_eq_of_mem_support hy.right\n  rw [\u2190 nth_le_to_list p x k (by simpa using hk)] at hk'\n  simp_rw [\u2190 hk']\n  rw [next_nth_le _ (nodup_to_list _ _), nth_le_to_list, nth_le_to_list, \u2190 mul_apply, \u2190 pow_succ,\n    length_to_list, pow_apply_eq_pow_mod_order_of_cycle_of_apply p (k + 1), is_cycle.order_of]\n  exact is_cycle_cycle_of _ (mem_support.mp hy.right)\n#align equiv.perm.next_to_list_eq_apply Equiv.Perm.next_toList_eq_apply\n\ntheorem toList_pow_apply_eq_rotate (p : Perm \u03b1) (x : \u03b1) (k : \u2115) :\n    p.toList ((p ^ k) x) = (p.toList x).rotate k :=\n  by\n  apply ext_le\n  \u00b7 simp only [length_to_list, cycle_of_self_apply_pow, length_rotate]\n  \u00b7 intro n hn hn'\n    rw [nth_le_to_list, nth_le_rotate, nth_le_to_list, length_to_list,\n      pow_mod_card_support_cycle_of_self_apply, pow_add, mul_apply]\n#align equiv.perm.to_list_pow_apply_eq_rotate Equiv.Perm.toList_pow_apply_eq_rotate\n\ntheorem SameCycle.toList_isRotated {f : Perm \u03b1} {x y : \u03b1} (h : SameCycle f x y) :\n    toList f x ~r toList f y := by\n  by_cases hx : x \u2208 f.support\n  \u00b7 obtain \u27e8_ | k, hk, hy\u27e9 := h.exists_pow_eq_of_mem_support hx\n    \u00b7 simp only [coe_one, id.def, pow_zero] at hy\n      simp [hy]\n    use k.succ\n    rw [\u2190 to_list_pow_apply_eq_rotate, hy]\n  \u00b7 rw [to_list_eq_nil_iff.mpr hx, is_rotated_nil_iff', eq_comm, to_list_eq_nil_iff]\n    rwa [\u2190 h.mem_support_iff]\n#align equiv.perm.same_cycle.to_list_is_rotated Equiv.Perm.SameCycle.toList_isRotated\n\ntheorem pow_apply_mem_toList_iff_mem_support {n : \u2115} : (p ^ n) x \u2208 p.toList x \u2194 x \u2208 p.support :=\n  by\n  rw [mem_to_list_iff, and_iff_right_iff_imp]\n  refine' fun _ => same_cycle.symm _\n  rw [same_cycle_pow_left]\n#align equiv.perm.pow_apply_mem_to_list_iff_mem_support Equiv.Perm.pow_apply_mem_toList_iff_mem_support\n\ntheorem toList_formPerm_nil (x : \u03b1) : toList (formPerm ([] : List \u03b1)) x = [] := by simp\n#align equiv.perm.to_list_form_perm_nil Equiv.Perm.toList_formPerm_nil\n\ntheorem toList_formPerm_singleton (x y : \u03b1) : toList (formPerm [x]) y = [] := by simp\n#align equiv.perm.to_list_form_perm_singleton Equiv.Perm.toList_formPerm_singleton\n\ntheorem toList_formPerm_nontrivial (l : List \u03b1) (hl : 2 \u2264 l.length) (hn : Nodup l) :\n    toList (formPerm l) (l.nthLe 0 (zero_lt_two.trans_le hl)) = l :=\n  by\n  have hc : l.form_perm.is_cycle := List.isCycle_formPerm hn hl\n  have hs : l.form_perm.support = l.to_finset :=\n    by\n    refine' support_form_perm_of_nodup _ hn _\n    rintro _ rfl\n    simpa [Nat.succ_le_succ_iff] using hl\n  rw [to_list, hc.cycle_of_eq (mem_support.mp _), hs, card_to_finset, dedup_eq_self.mpr hn]\n  \u00b7 refine' List.ext_nthLe (by simp) fun k hk hk' => _\n    simp [form_perm_pow_apply_nth_le _ hn, Nat.mod_eq_of_lt hk']\n  \u00b7 simpa [hs] using nth_le_mem _ _ _\n#align equiv.perm.to_list_form_perm_nontrivial Equiv.Perm.toList_formPerm_nontrivial\n\ntheorem toList_formPerm_isRotated_self (l : List \u03b1) (hl : 2 \u2264 l.length) (hn : Nodup l) (x : \u03b1)\n    (hx : x \u2208 l) : toList (formPerm l) x ~r l :=\n  by\n  obtain \u27e8k, hk, rfl\u27e9 := nth_le_of_mem hx\n  have hr : l ~r l.rotate k := \u27e8k, rfl\u27e9\n  rw [form_perm_eq_of_is_rotated hn hr]\n  rw [\u2190 nth_le_rotate' l k k]\n  simp only [Nat.mod_eq_of_lt hk, tsub_add_cancel_of_le hk.le, Nat.mod_self]\n  rw [to_list_form_perm_nontrivial]\n  \u00b7 simp\n  \u00b7 simpa using hl\n  \u00b7 simpa using hn\n#align equiv.perm.to_list_form_perm_is_rotated_self Equiv.Perm.toList_formPerm_isRotated_self\n\ntheorem formPerm_toList (f : Perm \u03b1) (x : \u03b1) : formPerm (toList f x) = f.cycleOf x :=\n  by\n  by_cases hx : f x = x\n  \u00b7\n    rw [(cycle_of_eq_one_iff f).mpr hx, to_list_eq_nil_iff.mpr (not_mem_support.mpr hx),\n      form_perm_nil]\n  ext y\n  by_cases hy : same_cycle f x y\n  \u00b7 obtain \u27e8k, hk, rfl\u27e9 := hy.exists_pow_eq_of_mem_support (mem_support.mpr hx)\n    rw [cycle_of_apply_apply_pow_self, List.formPerm_apply_mem_eq_next (nodup_to_list f x),\n      next_to_list_eq_apply, pow_succ, mul_apply]\n    rw [mem_to_list_iff]\n    exact \u27e8\u27e8k, rfl\u27e9, mem_support.mpr hx\u27e9\n  \u00b7 rw [cycle_of_apply_of_not_same_cycle hy, form_perm_apply_of_not_mem]\n    simp [mem_to_list_iff, hy]\n#align equiv.perm.form_perm_to_list Equiv.Perm.formPerm_toList\n\n/-- Given a cyclic `f : perm \u03b1`, generate the `cycle \u03b1` in the order\nof application of `f`. Implemented by finding an element `x : \u03b1`\nin the support of `f` in `finset.univ`, and iterating on using\n`equiv.perm.to_list f x`.\n-/\ndef toCycle (f : Perm \u03b1) (hf : IsCycle f) : Cycle \u03b1 :=\n  Multiset.recOn (Finset.univ : Finset \u03b1).val (Quot.mk _ [])\n    (fun x s l => if f x = x then l else toList f x)\n    (by\n      intro x y m s\n      refine' hEq_of_eq _\n      split_ifs with hx hy hy <;> try rfl\n      \u00b7 have hc : same_cycle f x y := is_cycle.same_cycle hf hx hy\n        exact Quotient.sound' hc.to_list_is_rotated)\n#align equiv.perm.to_cycle Equiv.Perm.toCycle\n\ntheorem toCycle_eq_toList (f : Perm \u03b1) (hf : IsCycle f) (x : \u03b1) (hx : f x \u2260 x) :\n    toCycle f hf = toList f x :=\n  by\n  have key : (Finset.univ : Finset \u03b1).val = x ::\u2098 finset.univ.val.erase x := by simp\n  rw [to_cycle, key]\n  simp [hx]\n#align equiv.perm.to_cycle_eq_to_list Equiv.Perm.toCycle_eq_toList\n\ntheorem nodup_toCycle (f : Perm \u03b1) (hf : IsCycle f) : (toCycle f hf).Nodup :=\n  by\n  obtain \u27e8x, hx, -\u27e9 := id hf\n  simpa [to_cycle_eq_to_list f hf x hx] using nodup_to_list _ _\n#align equiv.perm.nodup_to_cycle Equiv.Perm.nodup_toCycle\n\ntheorem nontrivial_toCycle (f : Perm \u03b1) (hf : IsCycle f) : (toCycle f hf).Nontrivial :=\n  by\n  obtain \u27e8x, hx, -\u27e9 := id hf\n  simp [to_cycle_eq_to_list f hf x hx, hx, Cycle.nontrivial_coe_nodup_iff (nodup_to_list _ _)]\n#align equiv.perm.nontrivial_to_cycle Equiv.Perm.nontrivial_toCycle\n\n/-- Any cyclic `f : perm \u03b1` is isomorphic to the nontrivial `cycle \u03b1`\nthat corresponds to repeated application of `f`.\nThe forward direction is implemented by `equiv.perm.to_cycle`.\n-/\ndef isoCycle : { f : Perm \u03b1 // IsCycle f } \u2243 { s : Cycle \u03b1 // s.Nodup \u2227 s.Nontrivial }\n    where\n  toFun f := \u27e8toCycle (f : Perm \u03b1) f.Prop, nodup_toCycle f f.Prop, nontrivial_toCycle _ f.Prop\u27e9\n  invFun s := \u27e8(s : Cycle \u03b1).formPerm s.Prop.left, (s : Cycle \u03b1).isCycle_formPerm _ s.Prop.right\u27e9\n  left_inv f := by\n    obtain \u27e8x, hx, -\u27e9 := id f.prop\n    simpa [to_cycle_eq_to_list (f : perm \u03b1) f.prop x hx, form_perm_to_list, Subtype.ext_iff] using\n      f.prop.cycle_of_eq hx\n  right_inv s := by\n    rcases s with \u27e8\u27e8s\u27e9, hn, ht\u27e9\n    obtain \u27e8x, -, -, hx, -\u27e9 := id ht\n    have hl : 2 \u2264 s.length := by simpa using Cycle.length_nontrivial ht\n    simp only [Cycle.mk_eq_coe, Cycle.nodup_coe_iff, Cycle.mem_coe_iff, Subtype.coe_mk,\n      Cycle.formPerm_coe] at hn hx\u22a2\n    rw [to_cycle_eq_to_list _ _ x]\n    \u00b7 refine' Quotient.sound' _\n      exact to_list_form_perm_is_rotated_self _ hl hn _ hx\n    \u00b7 rw [\u2190 mem_support, support_form_perm_of_nodup _ hn]\n      \u00b7 simpa using hx\n      \u00b7 rintro _ rfl\n        simpa [Nat.succ_le_succ_iff] using hl\n#align equiv.perm.iso_cycle Equiv.Perm.isoCycle\n\nend Fintype\n\nsection Finite\n\nvariable [Finite \u03b1] [DecidableEq \u03b1]\n\ntheorem IsCycle.existsUnique_cycle {f : Perm \u03b1} (hf : IsCycle f) :\n    \u2203! s : Cycle \u03b1, \u2203 h : s.Nodup, s.formPerm h = f :=\n  by\n  cases nonempty_fintype \u03b1\n  obtain \u27e8x, hx, hy\u27e9 := id hf\n  refine' \u27e8f.to_list x, \u27e8nodup_to_list f x, _\u27e9, _\u27e9\n  \u00b7 simp [form_perm_to_list, hf.cycle_of_eq hx]\n  \u00b7 rintro \u27e8l\u27e9 \u27e8hn, rfl\u27e9\n    simp only [Cycle.mk_eq_coe, Cycle.coe_eq_coe, Subtype.coe_mk, Cycle.formPerm_coe]\n    refine' (to_list_form_perm_is_rotated_self _ _ hn _ _).symm\n    \u00b7 contrapose! hx\n      suffices form_perm l = 1 by simp [this]\n      rw [form_perm_eq_one_iff _ hn]\n      exact Nat.le_of_lt_succ hx\n    \u00b7 rw [\u2190 mem_to_finset]\n      refine' support_form_perm_le l _\n      simpa using hx\n#align equiv.perm.is_cycle.exists_unique_cycle Equiv.Perm.IsCycle.existsUnique_cycle\n\ntheorem IsCycle.existsUnique_cycle_subtype {f : Perm \u03b1} (hf : IsCycle f) :\n    \u2203! s : { s : Cycle \u03b1 // s.Nodup }, (s : Cycle \u03b1).formPerm s.Prop = f :=\n  by\n  obtain \u27e8s, \u27e8hs, rfl\u27e9, hs'\u27e9 := hf.exists_unique_cycle\n  refine' \u27e8\u27e8s, hs\u27e9, rfl, _\u27e9\n  rintro \u27e8t, ht\u27e9 ht'\n  simpa using hs' _ \u27e8ht, ht'\u27e9\n#align equiv.perm.is_cycle.exists_unique_cycle_subtype Equiv.Perm.IsCycle.existsUnique_cycle_subtype\n\ntheorem IsCycle.existsUnique_cycle_nontrivial_subtype {f : Perm \u03b1} (hf : IsCycle f) :\n    \u2203! s : { s : Cycle \u03b1 // s.Nodup \u2227 s.Nontrivial }, (s : Cycle \u03b1).formPerm s.Prop.left = f :=\n  by\n  obtain \u27e8\u27e8s, hn\u27e9, hs, hs'\u27e9 := hf.exists_unique_cycle_subtype\n  refine' \u27e8\u27e8s, hn, _\u27e9, _, _\u27e9\n  \u00b7 rw [hn.nontrivial_iff]\n    subst f\n    intro H\n    refine' hf.ne_one _\n    simpa using Cycle.formPerm_subsingleton _ H\n  \u00b7 simpa using hs\n  \u00b7 rintro \u27e8t, ht, ht'\u27e9 ht''\n    simpa using hs' \u27e8t, ht\u27e9 ht''\n#align equiv.perm.is_cycle.exists_unique_cycle_nontrivial_subtype Equiv.Perm.IsCycle.existsUnique_cycle_nontrivial_subtype\n\nend Finite\n\nvariable [Fintype \u03b1] [DecidableEq \u03b1]\n\n/-- Any cyclic `f : perm \u03b1` is isomorphic to the nontrivial `cycle \u03b1`\nthat corresponds to repeated application of `f`.\nThe forward direction is implemented by finding this `cycle \u03b1` using `fintype.choose`.\n-/\ndef isoCycle' : { f : Perm \u03b1 // IsCycle f } \u2243 { s : Cycle \u03b1 // s.Nodup \u2227 s.Nontrivial }\n    where\n  toFun f := Fintype.choose _ f.Prop.existsUnique_cycle_nontrivial_subtype\n  invFun s := \u27e8(s : Cycle \u03b1).formPerm s.Prop.left, (s : Cycle \u03b1).isCycle_formPerm _ s.Prop.right\u27e9\n  left_inv f := by\n    simpa [Subtype.ext_iff] using\n      Fintype.choose_spec _ f.prop.exists_unique_cycle_nontrivial_subtype\n  right_inv := fun \u27e8s, hs, ht\u27e9 => by\n    simp [Subtype.coe_mk]\n    convert Fintype.choose_subtype_eq (fun s' : Cycle \u03b1 => s'.Nodup \u2227 s'.Nontrivial) _\n    ext \u27e8s', hs', ht'\u27e9\n    simp [Cycle.formPerm_eq_formPerm_iff, iff_not_comm.mp hs.nontrivial_iff,\n      iff_not_comm.mp hs'.nontrivial_iff, ht]\n#align equiv.perm.iso_cycle' Equiv.Perm.isoCycle'\n\n-- mathport name: \u00abexprc[ ,]\u00bb\nnotation3\"c[\"(l\", \"* => foldr (h t => List.cons h t) List.nil)\"]\" =>\n  Cycle.formPerm (\u2191l) (Cycle.nodup_coe_iff.mpr (by decide))\n\nunsafe instance repr_perm [Repr \u03b1] : Repr (Perm \u03b1) :=\n  \u27e8fun f =>\n    repr\n      (Multiset.pmap (fun (g : Perm \u03b1) (hg : g.IsCycle) => isoCycle \u27e8g, hg\u27e9)\n        (-- to_cycle is faster?\n            Perm.cycleFactorsFinset\n            f).val\n        fun g hg => (mem_cycleFactorsFinset_iff.mp (Finset.mem_def.mpr hg)).left)\u27e9\n#align equiv.perm.repr_perm equiv.perm.repr_perm\n\nend Equiv.Perm\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/GroupTheory/Perm/Cycle/Concrete.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7123452896363017}}
{"text": "/-\nThis is a d\u2203\u2200duction file providing first exercises about quantifiers and numbers.\nFrench version.\n-/\n\nimport data.set\nimport data.real.basic\nimport tactic\n\n-- dEAduction tactics\nimport structures2      -- hypo_analysis, targets_analysis\nimport utils            -- no_meta_vars\nimport user_notations   -- notations that can be used in deaduction UI for a new object\nimport compute          -- tactics for computation, used by the Goal! button\nimport push_neg_once\n\n\n-- dEAduction definitions\n-- import set_definitions\n\n\n-- General principles :\n-- Type should be defined as parameters, in order to be implicit everywhere\n-- other parameters are implicit in definitions, i.e. defined using '{}' (e.g. {A : set X} )\n-- but explicit everywhere else, i.e. defined using '()' (e.g. (A : set X) )\n-- each definition must be an iff statement (since it will be called with 'rw' or 'symp_rw')\n\n\n\n---------------------\n-- Course metadata --\n---------------------\n-- logic names ['and', 'or', 'negate', 'implicate', 'iff', 'forall', 'exists']\n-- proofs names ['use_proof_methods', 'new_object', 'apply', 'assumption']\n-- magic names ['compute']\n-- proof methods names ['cbr', 'contrapose', 'absurdum', 'sorry']\n-- Note for Python devs:\n--      Any supplementary metadata will be put in the 'info' dict of each exo\n\n/- dEAduction\nAuthor\n    Fr\u00e9d\u00e9ric Le Roux\nInstitution\n    Universit\u00e9 de France\nTitle\n    Logique et in\u00e9galit\u00e9s\nDescription\n    Ce fichier contient quelques exercices de base\n    impliquant des quantificateurs et des in\u00e9galit\u00e9s.\n    Certains buts sont vrais et d'autres faux :\n    avant de commencer l'exercice,\n    vous choisirez ce que vous voulez prouver,\n    le but ou sa n\u00e9gation.\nOpenQuestion\n    True\nAvailableExercises\n    NONE\nAvailableLogic\n    ALL -not\n-/\n\n-- If OpenQuestion is True, DEAduction will ask the user if she wants to\n-- prove the statement or its negation, and set the variable\n-- NegateStatement accordingly\n-- If NegateStatement is True, then the statement will be replaced by its\n-- negation\n-- AvailableExercises is set to None so that no exercise statement can be applied\n-- by the user. Recommended with OpenQuestions set to True!\n\n\nlocal attribute [instance] classical.prop_decidable\n\n---------------------------------------------\n-- global parameters = implicit variables --\n---------------------------------------------\nsection course\n\nnamespace Logique_et_nombres_reels\n/- dEAduction\nPrettyName\n    Logique et nombres r\u00e9els\n-/\n\nnamespace negation\n/- dEAduction\nPrettyName\n    Enonc\u00e9s de n\u00e9gation\n-/\n\nlemma theorem.negation_et {P Q : Prop} :\n( not (P and Q) ) \u2194 ( (not P) or (not Q) )\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation du 'et'\n-/\nbegin\n    exact not_and_distrib\nend\n\nlemma theorem.negation_ou {P Q : Prop} :\n( not (P or Q) ) \u2194 ( (not P) and (not Q) )\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation du 'ou'\n-/\nbegin\n    exact not_or_distrib\nend\n\nlemma theorem.negation_non {P : Prop} :\n( not not P ) \u2194  P\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation du 'non'\n-/\nbegin\n    exact not_not\nend\n\n\nlemma theorem.negation_implique {P Q : Prop} :\n( not (P \u2192 Q) ) \u2194  ( P and (not Q) )\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation d'une implication\n-/\nbegin\n    exact not_imp,\nend\n\n\nlemma theorem.negation_existe  {X : Type} {P : X \u2192 Prop} :\n( ( not \u2203 (x:X), P x  ) \u2194 \u2200 x:X, not P x )\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation de '\u2203X, P(x)'\n-/\nbegin\n    exact not_exists,\nend\n\n\n\nlemma theorem.negation_pour_tout {X : Type} {P : X \u2192 Prop} :\n( not (\u2200x, P x ) ) \u2194 \u2203x, not P x\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation de '\u2200x, P(x)'\n-/\nbegin\n    exact not_forall\nend\n\n\nlemma theorem.negation_inegalite_stricte {X : Type} (x y : X) [linear_order X]:\n( not (x < y) ) \u2194 y \u2264 x\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation de 'x < y'\n-/\nbegin\n    exact not_lt\nend\n\n\nlemma theorem.negation_inegalite_large {X : Type} (x y : X) [linear_order X]:\n( not (x \u2264 y) ) \u2194 y < x\n:=\n/- dEAduction\nPrettyName\n    N\u00e9gation de 'x \u2264 y'\n-/\nbegin\n    exact not_le\nend\n\nlemma theorem.double_negation (P: Prop) :\n(non non P) \u2194 P :=\n/- dEAduction\nPrettyName\n    Double n\u00e9gation\n-/\nbegin\n    todo\nend\n\n\nend negation\n\nnamespace exercices\n/- dEAduction\nPrettyName\n    Exercices\n-/\n\n\n\nlemma exercise.zero_ou_un : \u2200 n:\u2115, (n \u2260 0 or n \u2260 1)\n:=\n/- dEAduction\nPrettyName\n    Pas z\u00e9ro ou pas un\n-/\nbegin\n    todo\nend\n\nlemma exercise.zero_ou_un_2 : \u2200 n:\u2115, (n = 0 or n = 1)\n:=\n/- dEAduction\nPrettyName\n    Z\u00e9ro ou un ou ?...\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.plus_petit : \u2203 m:\u2115, \u2200 n:\u2115, m \u2264 n\n:=\n/- dEAduction\nPrettyName\n    Plus petit que tous\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.vraiment_plus_petit : \u2203 m:\u2124, \u2200 n:\u2124, m \u2264 n\n:=\n/- dEAduction\nPrettyName\n    Plus petit que tous...\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.egalite : \u2200 n:\u2115, \u2203 m:\u2115, m=n\n:=\n/- dEAduction\nPrettyName\n    Tous \u00e9gaux\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.egalite_2 :\n\u2203 m:\u2115, \u2200 n:\u2115, m=n\n:=\n/- dEAduction\nPrettyName\n    Egaux \u00e0 tous !\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.tres_petit :\n\u2200 a \u2265 (0:\u211d), \u2200 \u03b5 \u2265 (0:\u211d), (a \u2264 \u03b5 \u2192 a = 0)\n:=\n/- dEAduction\nPrettyName\n    Tr\u00e8s petit\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.tres_petit_2 :\n\u2200 a \u2265 (0:\u211d), ((\u2200 \u03b5 \u2265 (0:\u211d), a \u2264 \u03b5) \u2192 a = 0)\n:=\n/- dEAduction\nPrettyName\n    Ca se complique\nSimplificationCompute\n    $ALL\n-/\nbegin\n    todo\nend\n\n\n\nlemma exercise.tres_petit_3 :\n\u2200 a \u2265 (0:\u211d), ((\u2200 \u03b5 > (0:\u211d), a \u2264 \u03b5) \u2192 a = 0)\n:=\n/- dEAduction\nPrettyName\n    Trop compliqu\u00e9 !\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.entre_deux_entiers :\n\u2200x:\u2124, \u2200y:\u2124, (x<y \u2192 (\u2203z:\u2124, x < z and z < y))\n:=\n/- dEAduction\nPrettyName\n    Entre deux entiers\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.entre_deux_reels :\n\u2200x:\u211d, \u2200y:\u211d, (x<y \u2192 (\u2203z:\u211d, x < z and z < y))\n:=\n/- dEAduction\nPrettyName\n    Entre deux r\u00e9els\n-/\nbegin\n    todo\nend\n\nend exercices\n\nend Logique_et_nombres_reels\n\nend course", "meta": {"author": "dEAduction", "repo": "dEAduction-lean", "sha": "4fe1d642078fc94f9081ccbed08e047e86a741fd", "save_path": "github-repos/lean/dEAduction-dEAduction-lean", "path": "github-repos/lean/dEAduction-dEAduction-lean/dEAduction-lean-4fe1d642078fc94f9081ccbed08e047e86a741fd/src/exercises_deaduction_synchro/Logique_et_inegalites.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7123452802432239}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.degree.lemmas\n! leanprover-community/mathlib commit 728baa2f54e6062c5879a3e397ac6bac323e506f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Polynomial.Eval\n\n/-!\n# Theory of degrees of polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nSome of the main results include\n- `nat_degree_comp_le` : The degree of the composition is at most the product of degrees\n\n-/\n\n\nnoncomputable section\n\nopen Classical Polynomial\n\nopen Finsupp Finset\n\nnamespace Polynomial\n\nuniverse u v w\n\nvariable {R : Type u} {S : Type v} {\u03b9 : Type w} {a b : R} {m n : \u2115}\n\nsection Semiring\n\nvariable [Semiring R] {p q r : R[X]}\n\nsection Degree\n\n#print Polynomial.natDegree_comp_le /-\ntheorem natDegree_comp_le : natDegree (p.comp q) \u2264 natDegree p * natDegree q :=\n  if h0 : p.comp q = 0 then by rw [h0, nat_degree_zero] <;> exact Nat.zero_le _\n  else\n    WithBot.coe_le_coe.1 <|\n      calc\n        \u2191(natDegree (p.comp q)) = degree (p.comp q) := (degree_eq_natDegree h0).symm\n        _ = _ := (congr_arg degree comp_eq_sum_left)\n        _ \u2264 _ := (degree_sum_le _ _)\n        _ \u2264 _ :=\n          Finset.sup_le fun n hn =>\n            calc\n              degree (C (coeff p n) * q ^ n) \u2264 degree (C (coeff p n)) + degree (q ^ n) :=\n                degree_mul_le _ _\n              _ \u2264 natDegree (C (coeff p n)) + n \u2022 degree q :=\n                (add_le_add degree_le_natDegree (degree_pow_le _ _))\n              _ \u2264 natDegree (C (coeff p n)) + n \u2022 natDegree q :=\n                (add_le_add_left (nsmul_le_nsmul_of_le_right (@degree_le_natDegree _ _ q) n) _)\n              _ = (n * natDegree q : \u2115) := by\n                rw [nat_degree_C, WithBot.coe_zero, zero_add, \u2190 WithBot.coe_nsmul, nsmul_eq_mul] <;>\n                  simp\n              _ \u2264 (natDegree p * natDegree q : \u2115) :=\n                WithBot.coe_le_coe.2 <|\n                  mul_le_mul_of_nonneg_right (le_natDegree_of_ne_zero (mem_support_iff.1 hn))\n                    (Nat.zero_le _)\n              \n        \n#align polynomial.nat_degree_comp_le Polynomial.natDegree_comp_le\n-/\n\n#print Polynomial.degree_pos_of_root /-\ntheorem degree_pos_of_root {p : R[X]} (hp : p \u2260 0) (h : IsRoot p a) : 0 < degree p :=\n  lt_of_not_ge fun hlt => by\n    have := eq_C_of_degree_le_zero hlt\n    rw [is_root, this, eval_C] at h\n    simp only [h, RingHom.map_zero] at this\n    exact hp this\n#align polynomial.degree_pos_of_root Polynomial.degree_pos_of_root\n-/\n\n/- warning: polynomial.nat_degree_le_iff_coeff_eq_zero -> Polynomial.natDegree_le_iff_coeff_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, Iff (LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 p) n) (forall (N : Nat), (LT.lt.{0} Nat Nat.hasLt n N) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p N) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, Iff (LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 p) n) (forall (N : Nat), (LT.lt.{0} Nat instLTNat n N) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 p N) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_le_iff_coeff_eq_zero Polynomial.natDegree_le_iff_coeff_eq_zero\u2093'. -/\ntheorem natDegree_le_iff_coeff_eq_zero : p.natDegree \u2264 n \u2194 \u2200 N : \u2115, n < N \u2192 p.coeff N = 0 := by\n  simp_rw [nat_degree_le_iff_degree_le, degree_le_iff_coeff_zero, WithBot.coe_lt_coe]\n#align polynomial.nat_degree_le_iff_coeff_eq_zero Polynomial.natDegree_le_iff_coeff_eq_zero\n\n#print Polynomial.natDegree_add_le_iff_left /-\ntheorem natDegree_add_le_iff_left {n : \u2115} (p q : R[X]) (qn : q.natDegree \u2264 n) :\n    (p + q).natDegree \u2264 n \u2194 p.natDegree \u2264 n :=\n  by\n  refine' \u27e8fun h => _, fun h => nat_degree_add_le_of_degree_le h qn\u27e9\n  refine' nat_degree_le_iff_coeff_eq_zero.mpr fun m hm => _\n  convert nat_degree_le_iff_coeff_eq_zero.mp h m hm using 1\n  rw [coeff_add, nat_degree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero]\n#align polynomial.nat_degree_add_le_iff_left Polynomial.natDegree_add_le_iff_left\n-/\n\n#print Polynomial.natDegree_add_le_iff_right /-\ntheorem natDegree_add_le_iff_right {n : \u2115} (p q : R[X]) (pn : p.natDegree \u2264 n) :\n    (p + q).natDegree \u2264 n \u2194 q.natDegree \u2264 n :=\n  by\n  rw [add_comm]\n  exact nat_degree_add_le_iff_left _ _ pn\n#align polynomial.nat_degree_add_le_iff_right Polynomial.natDegree_add_le_iff_right\n-/\n\n/- warning: polynomial.nat_degree_C_mul_le -> Polynomial.natDegree_C_mul_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (a : R) (f : Polynomial.{u1} R _inst_1), LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a) f)) (Polynomial.natDegree.{u1} R _inst_1 f)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (a : R) (f : Polynomial.{u1} R _inst_1), LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a) f)) (Polynomial.natDegree.{u1} R _inst_1 f)\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_C_mul_le Polynomial.natDegree_C_mul_le\u2093'. -/\ntheorem natDegree_C_mul_le (a : R) (f : R[X]) : (C a * f).natDegree \u2264 f.natDegree :=\n  calc\n    (C a * f).natDegree \u2264 (C a).natDegree + f.natDegree := natDegree_mul_le\n    _ = 0 + f.natDegree := by rw [nat_degree_C a]\n    _ = f.natDegree := zero_add _\n    \n#align polynomial.nat_degree_C_mul_le Polynomial.natDegree_C_mul_le\n\n/- warning: polynomial.nat_degree_mul_C_le -> Polynomial.natDegree_mul_C_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1) (a : R), LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) f (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.natDegree.{u1} R _inst_1 f)\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1) (a : R), LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) f (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.natDegree.{u1} R _inst_1 f)\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_mul_C_le Polynomial.natDegree_mul_C_le\u2093'. -/\ntheorem natDegree_mul_C_le (f : R[X]) (a : R) : (f * C a).natDegree \u2264 f.natDegree :=\n  calc\n    (f * C a).natDegree \u2264 f.natDegree + (C a).natDegree := natDegree_mul_le\n    _ = f.natDegree + 0 := by rw [nat_degree_C a]\n    _ = f.natDegree := add_zero _\n    \n#align polynomial.nat_degree_mul_C_le Polynomial.natDegree_mul_C_le\n\n#print Polynomial.eq_natDegree_of_le_mem_support /-\ntheorem eq_natDegree_of_le_mem_support (pn : p.natDegree \u2264 n) (ns : n \u2208 p.support) :\n    p.natDegree = n :=\n  le_antisymm pn (le_natDegree_of_mem_supp _ ns)\n#align polynomial.eq_nat_degree_of_le_mem_support Polynomial.eq_natDegree_of_le_mem_support\n-/\n\n/- warning: polynomial.nat_degree_C_mul_eq_of_mul_eq_one -> Polynomial.natDegree_C_mul_eq_of_mul_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {ai : R}, (Eq.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) ai a) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {ai : R}, (Eq.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) ai a) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (Semiring.toOne.{u1} R _inst_1)))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_C_mul_eq_of_mul_eq_one Polynomial.natDegree_C_mul_eq_of_mul_eq_one\u2093'. -/\ntheorem natDegree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) :\n    (C a * p).natDegree = p.natDegree :=\n  le_antisymm (natDegree_C_mul_le a p)\n    (calc\n      p.natDegree = (1 * p).natDegree := by nth_rw 1 [\u2190 one_mul p]\n      _ = (C ai * (C a * p)).natDegree := by rw [\u2190 C_1, \u2190 au, RingHom.map_mul, \u2190 mul_assoc]\n      _ \u2264 (C a * p).natDegree := natDegree_C_mul_le ai (C a * p)\n      )\n#align polynomial.nat_degree_C_mul_eq_of_mul_eq_one Polynomial.natDegree_C_mul_eq_of_mul_eq_one\n\n/- warning: polynomial.nat_degree_mul_C_eq_of_mul_eq_one -> Polynomial.natDegree_mul_C_eq_of_mul_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {ai : R}, (Eq.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) a ai) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} R (NonAssocSemiring.toAddCommMonoidWithOne.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.natDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {ai : R}, (Eq.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) a ai) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (Semiring.toOne.{u1} R _inst_1)))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.natDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_mul_C_eq_of_mul_eq_one Polynomial.natDegree_mul_C_eq_of_mul_eq_one\u2093'. -/\ntheorem natDegree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) :\n    (p * C a).natDegree = p.natDegree :=\n  le_antisymm (natDegree_mul_C_le p a)\n    (calc\n      p.natDegree = (p * 1).natDegree := by nth_rw 1 [\u2190 mul_one p]\n      _ = (p * C a * C ai).natDegree := by rw [\u2190 C_1, \u2190 au, RingHom.map_mul, \u2190 mul_assoc]\n      _ \u2264 (p * C a).natDegree := natDegree_mul_C_le (p * C a) ai\n      )\n#align polynomial.nat_degree_mul_C_eq_of_mul_eq_one Polynomial.natDegree_mul_C_eq_of_mul_eq_one\n\n/- warning: polynomial.nat_degree_mul_C_eq_of_mul_ne_zero -> Polynomial.natDegree_mul_c_eq_of_mul_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (Polynomial.leadingCoeff.{u1} R _inst_1 p) a) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.natDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Polynomial.leadingCoeff.{u1} R _inst_1 p) a) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.natDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_mul_C_eq_of_mul_ne_zero Polynomial.natDegree_mul_c_eq_of_mul_ne_zero\u2093'. -/\n/-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero`\nforce the polynomial `p` to be non-zero, via `p.leading_coeff \u2260 0`.\n-/\ntheorem natDegree_mul_c_eq_of_mul_ne_zero (h : p.leadingCoeff * a \u2260 0) :\n    (p * C a).natDegree = p.natDegree :=\n  by\n  refine' eq_nat_degree_of_le_mem_support (nat_degree_mul_C_le p a) _\n  refine' mem_support_iff.mpr _\n  rwa [coeff_mul_C]\n#align polynomial.nat_degree_mul_C_eq_of_mul_ne_zero Polynomial.natDegree_mul_c_eq_of_mul_ne_zero\n\n/- warning: polynomial.nat_degree_C_mul_eq_of_mul_ne_zero -> Polynomial.natDegree_c_mul_eq_of_mul_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) a (Polynomial.leadingCoeff.{u1} R _inst_1 p)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) a (Polynomial.leadingCoeff.{u1} R _inst_1 p)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_C_mul_eq_of_mul_ne_zero Polynomial.natDegree_c_mul_eq_of_mul_ne_zero\u2093'. -/\n/-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero`\nforce the polynomial `p` to be non-zero, via `p.leading_coeff \u2260 0`.\n-/\ntheorem natDegree_c_mul_eq_of_mul_ne_zero (h : a * p.leadingCoeff \u2260 0) :\n    (C a * p).natDegree = p.natDegree :=\n  by\n  refine' eq_nat_degree_of_le_mem_support (nat_degree_C_mul_le a p) _\n  refine' mem_support_iff.mpr _\n  rwa [coeff_C_mul]\n#align polynomial.nat_degree_C_mul_eq_of_mul_ne_zero Polynomial.natDegree_c_mul_eq_of_mul_ne_zero\n\n/- warning: polynomial.nat_degree_add_coeff_mul -> Polynomial.natDegree_add_coeff_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1) (g : Polynomial.{u1} R _inst_1), Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) f g) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Polynomial.natDegree.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 g))) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (Polynomial.coeff.{u1} R _inst_1 f (Polynomial.natDegree.{u1} R _inst_1 f)) (Polynomial.coeff.{u1} R _inst_1 g (Polynomial.natDegree.{u1} R _inst_1 g)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] (f : Polynomial.{u1} R _inst_1) (g : Polynomial.{u1} R _inst_1), Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) f g) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Polynomial.natDegree.{u1} R _inst_1 f) (Polynomial.natDegree.{u1} R _inst_1 g))) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Polynomial.coeff.{u1} R _inst_1 f (Polynomial.natDegree.{u1} R _inst_1 f)) (Polynomial.coeff.{u1} R _inst_1 g (Polynomial.natDegree.{u1} R _inst_1 g)))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_add_coeff_mul Polynomial.natDegree_add_coeff_mul\u2093'. -/\ntheorem natDegree_add_coeff_mul (f g : R[X]) :\n    (f * g).coeff (f.natDegree + g.natDegree) = f.coeff f.natDegree * g.coeff g.natDegree := by\n  simp only [coeff_nat_degree, coeff_mul_degree_add_degree]\n#align polynomial.nat_degree_add_coeff_mul Polynomial.natDegree_add_coeff_mul\n\n/- warning: polynomial.nat_degree_lt_coeff_mul -> Polynomial.natDegree_lt_coeff_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {m : Nat} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (LT.lt.{0} Nat Nat.hasLt (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Polynomial.natDegree.{u1} R _inst_1 p) (Polynomial.natDegree.{u1} R _inst_1 q)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) m n)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) m n)) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} {m : Nat} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (LT.lt.{0} Nat instLTNat (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Polynomial.natDegree.{u1} R _inst_1 p) (Polynomial.natDegree.{u1} R _inst_1 q)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) m n)) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) m n)) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_lt_coeff_mul Polynomial.natDegree_lt_coeff_mul\u2093'. -/\ntheorem natDegree_lt_coeff_mul (h : p.natDegree + q.natDegree < m + n) :\n    (p * q).coeff (m + n) = 0 :=\n  coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt h)\n#align polynomial.nat_degree_lt_coeff_mul Polynomial.natDegree_lt_coeff_mul\n\n/- warning: polynomial.coeff_mul_of_nat_degree_le -> Polynomial.coeff_mul_of_natDegree_le is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {m : Nat} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 p) m) -> (LE.le.{0} Nat Nat.hasLe (Polynomial.natDegree.{u1} R _inst_1 q) n) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) m n)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (Polynomial.coeff.{u1} R _inst_1 p m) (Polynomial.coeff.{u1} R _inst_1 q n)))\nbut is expected to have type\n  forall {R : Type.{u1}} {m : Nat} {n : Nat} [_inst_1 : Semiring.{u1} R] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 p) m) -> (LE.le.{0} Nat instLENat (Polynomial.natDegree.{u1} R _inst_1 q) n) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p q) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) m n)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Polynomial.coeff.{u1} R _inst_1 p m) (Polynomial.coeff.{u1} R _inst_1 q n)))\nCase conversion may be inaccurate. Consider using '#align polynomial.coeff_mul_of_nat_degree_le Polynomial.coeff_mul_of_natDegree_le\u2093'. -/\ntheorem coeff_mul_of_natDegree_le (pm : p.natDegree \u2264 m) (qn : q.natDegree \u2264 n) :\n    (p * q).coeff (m + n) = p.coeff m * q.coeff n :=\n  by\n  rcases eq_or_lt_of_le pm with (rfl | hm) <;> rcases eq_or_lt_of_le qn with (rfl | hn)\n  \u00b7 exact nat_degree_add_coeff_mul _ _\n  \u00b7 rw [coeff_eq_zero_of_nat_degree_lt hn, MulZeroClass.mul_zero]\n    exact nat_degree_lt_coeff_mul (add_lt_add_left hn _)\n  \u00b7 rw [coeff_eq_zero_of_nat_degree_lt hm, MulZeroClass.zero_mul]\n    exact nat_degree_lt_coeff_mul (add_lt_add_right hm _)\n  \u00b7 rw [coeff_eq_zero_of_nat_degree_lt hn, MulZeroClass.mul_zero]\n    exact nat_degree_lt_coeff_mul (add_lt_add hm hn)\n#align polynomial.coeff_mul_of_nat_degree_le Polynomial.coeff_mul_of_natDegree_le\n\n#print Polynomial.coeff_pow_of_natDegree_le /-\ntheorem coeff_pow_of_natDegree_le (pn : p.natDegree \u2264 n) : (p ^ m).coeff (n * m) = p.coeff n ^ m :=\n  by\n  induction' m with m hm\n  \u00b7 simp\n  \u00b7 rw [pow_succ', pow_succ', \u2190 hm, Nat.mul_succ, coeff_mul_of_nat_degree_le _ pn]\n    refine' nat_degree_pow_le.trans (le_trans _ (mul_comm _ _).le)\n    exact mul_le_mul_of_nonneg_left pn m.zero_le\n#align polynomial.coeff_pow_of_nat_degree_le Polynomial.coeff_pow_of_natDegree_le\n-/\n\n#print Polynomial.coeff_add_eq_left_of_lt /-\ntheorem coeff_add_eq_left_of_lt (qn : q.natDegree < n) : (p + q).coeff n = p.coeff n :=\n  (coeff_add _ _ _).trans <|\n    (congr_arg _ <| coeff_eq_zero_of_natDegree_lt <| qn).trans <| add_zero _\n#align polynomial.coeff_add_eq_left_of_lt Polynomial.coeff_add_eq_left_of_lt\n-/\n\n#print Polynomial.coeff_add_eq_right_of_lt /-\ntheorem coeff_add_eq_right_of_lt (pn : p.natDegree < n) : (p + q).coeff n = q.coeff n :=\n  by\n  rw [add_comm]\n  exact coeff_add_eq_left_of_lt pn\n#align polynomial.coeff_add_eq_right_of_lt Polynomial.coeff_add_eq_right_of_lt\n-/\n\n#print Polynomial.degree_sum_eq_of_disjoint /-\ntheorem degree_sum_eq_of_disjoint (f : S \u2192 R[X]) (s : Finset S)\n    (h : Set.Pairwise { i | i \u2208 s \u2227 f i \u2260 0 } (Ne on degree \u2218 f)) :\n    degree (s.Sum f) = s.sup fun i => degree (f i) :=\n  by\n  induction' s using Finset.induction_on with x s hx IH\n  \u00b7 simp\n  \u00b7 simp only [hx, Finset.sum_insert, not_false_iff, Finset.sup_insert]\n    specialize IH (h.mono fun _ => by simp (config := { contextual := true }))\n    rcases lt_trichotomy (degree (f x)) (degree (s.sum f)) with (H | H | H)\n    \u00b7 rw [\u2190 IH, sup_eq_right.mpr H.le, degree_add_eq_right_of_degree_lt H]\n    \u00b7 rcases s.eq_empty_or_nonempty with (rfl | hs)\n      \u00b7 simp\n      obtain \u27e8y, hy, hy'\u27e9 := Finset.exists_mem_eq_sup s hs fun i => degree (f i)\n      rw [IH, hy'] at H\n      by_cases hx0 : f x = 0\n      \u00b7 simp [hx0, IH]\n      have hy0 : f y \u2260 0 := by\n        contrapose! H\n        simpa [H, degree_eq_bot] using hx0\n      refine' absurd H (h _ _ fun H => hx _)\n      \u00b7 simp [hx0]\n      \u00b7 simp [hy, hy0]\n      \u00b7 exact H.symm \u25b8 hy\n    \u00b7 rw [\u2190 IH, sup_eq_left.mpr H.le, degree_add_eq_left_of_degree_lt H]\n#align polynomial.degree_sum_eq_of_disjoint Polynomial.degree_sum_eq_of_disjoint\n-/\n\n#print Polynomial.natDegree_sum_eq_of_disjoint /-\ntheorem natDegree_sum_eq_of_disjoint (f : S \u2192 R[X]) (s : Finset S)\n    (h : Set.Pairwise { i | i \u2208 s \u2227 f i \u2260 0 } (Ne on natDegree \u2218 f)) :\n    natDegree (s.Sum f) = s.sup fun i => natDegree (f i) :=\n  by\n  by_cases H : \u2203 x \u2208 s, f x \u2260 0\n  \u00b7 obtain \u27e8x, hx, hx'\u27e9 := H\n    have hs : s.nonempty := \u27e8x, hx\u27e9\n    refine' nat_degree_eq_of_degree_eq_some _\n    rw [degree_sum_eq_of_disjoint]\n    \u00b7 rw [\u2190 Finset.sup'_eq_sup hs, \u2190 Finset.sup'_eq_sup hs, Finset.coe_sup', \u2190\n        Finset.sup'_eq_sup hs]\n      refine' le_antisymm _ _\n      \u00b7 rw [Finset.sup'_le_iff]\n        intro b hb\n        by_cases hb' : f b = 0\n        \u00b7 simpa [hb'] using hs\n        rw [degree_eq_nat_degree hb']\n        exact Finset.le_sup' _ hb\n      \u00b7 rw [Finset.sup'_le_iff]\n        intro b hb\n        simp only [Finset.le_sup'_iff, exists_prop, Function.comp_apply]\n        by_cases hb' : f b = 0\n        \u00b7 refine' \u27e8x, hx, _\u27e9\n          contrapose! hx'\n          simpa [hb', degree_eq_bot] using hx'\n        exact \u27e8b, hb, (degree_eq_nat_degree hb').ge\u27e9\n    \u00b7 exact h.imp fun x y hxy hxy' => hxy (nat_degree_eq_of_degree_eq hxy')\n  \u00b7 push_neg  at H\n    rw [Finset.sum_eq_zero H, nat_degree_zero, eq_comm, show 0 = \u22a5 from rfl, Finset.sup_eq_bot_iff]\n    intro x hx\n    simp [H x hx]\n#align polynomial.nat_degree_sum_eq_of_disjoint Polynomial.natDegree_sum_eq_of_disjoint\n-/\n\n#print Polynomial.natDegree_bit0 /-\ntheorem natDegree_bit0 (a : R[X]) : (bit0 a).natDegree \u2264 a.natDegree :=\n  (natDegree_add_le _ _).trans (max_self _).le\n#align polynomial.nat_degree_bit0 Polynomial.natDegree_bit0\n-/\n\n#print Polynomial.natDegree_bit1 /-\ntheorem natDegree_bit1 (a : R[X]) : (bit1 a).natDegree \u2264 a.natDegree :=\n  (natDegree_add_le _ _).trans (by simp [nat_degree_bit0])\n#align polynomial.nat_degree_bit1 Polynomial.natDegree_bit1\n-/\n\nvariable [Semiring S]\n\n/- warning: polynomial.nat_degree_pos_of_eval\u2082_root -> Polynomial.natDegree_pos_of_eval\u2082_root is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {S : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : Semiring.{u2} S] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))) -> (forall (f : RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) {z : S}, (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S _inst_1 _inst_2 f z p) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2)))))))) -> (forall (x : R), (Eq.{succ u2} S (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) (fun (_x : RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) => R -> S) (RingHom.hasCoeToFun.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) f x) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2)))))))) -> (Eq.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))))) -> (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Polynomial.natDegree.{u1} R _inst_1 p)))\nbut is expected to have type\n  forall {R : Type.{u1}} {S : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : Semiring.{u2} S] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))) -> (forall (f : RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) {z : S}, (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S _inst_1 _inst_2 f z p) (OfNat.ofNat.{u2} S 0 (Zero.toOfNat0.{u2} S (MonoidWithZero.toZero.{u2} S (Semiring.toMonoidWithZero.{u2} S _inst_2))))) -> (forall (x : R), (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) _x) (MulHomClass.toFunLike.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R S (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2))) (NonUnitalRingHomClass.toMulHomClass.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2)) (RingHomClass.toNonUnitalRingHomClass.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2) (RingHom.instRingHomClassRingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2))))) f x) (OfNat.ofNat.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) 0 (Zero.toOfNat0.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) (MonoidWithZero.toZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) (Semiring.toMonoidWithZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) _inst_2))))) -> (Eq.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))))) -> (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Polynomial.natDegree.{u1} R _inst_1 p)))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_pos_of_eval\u2082_root Polynomial.natDegree_pos_of_eval\u2082_root\u2093'. -/\ntheorem natDegree_pos_of_eval\u2082_root {p : R[X]} (hp : p \u2260 0) (f : R \u2192+* S) {z : S}\n    (hz : eval\u2082 f z p = 0) (inj : \u2200 x : R, f x = 0 \u2192 x = 0) : 0 < natDegree p :=\n  lt_of_not_ge fun hlt =>\n    by\n    have A : p = C (p.coeff 0) := eq_C_of_nat_degree_le_zero hlt\n    rw [A, eval\u2082_C] at hz\n    simp only [inj (p.coeff 0) hz, RingHom.map_zero] at A\n    exact hp A\n#align polynomial.nat_degree_pos_of_eval\u2082_root Polynomial.natDegree_pos_of_eval\u2082_root\n\n/- warning: polynomial.degree_pos_of_eval\u2082_root -> Polynomial.degree_pos_of_eval\u2082_root is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {S : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : Semiring.{u2} S] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (OfNat.mk.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.zero.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1))))) -> (forall (f : RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) {z : S}, (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S _inst_1 _inst_2 f z p) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2)))))))) -> (forall (x : R), (Eq.{succ u2} S (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) (fun (_x : RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) => R -> S) (RingHom.hasCoeToFun.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) f x) (OfNat.ofNat.{u2} S 0 (OfNat.mk.{u2} S 0 (Zero.zero.{u2} S (MulZeroClass.toHasZero.{u2} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2)))))))) -> (Eq.{succ u1} R x (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))))))) -> (LT.lt.{0} (WithBot.{0} Nat) (Preorder.toLT.{0} (WithBot.{0} Nat) (WithBot.preorder.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))))) (OfNat.ofNat.{0} (WithBot.{0} Nat) 0 (OfNat.mk.{0} (WithBot.{0} Nat) 0 (Zero.zero.{0} (WithBot.{0} Nat) (WithBot.hasZero.{0} Nat Nat.hasZero)))) (Polynomial.degree.{u1} R _inst_1 p)))\nbut is expected to have type\n  forall {R : Type.{u1}} {S : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : Semiring.{u2} S] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} (Polynomial.{u1} R _inst_1) p (OfNat.ofNat.{u1} (Polynomial.{u1} R _inst_1) 0 (Zero.toOfNat0.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.zero.{u1} R _inst_1)))) -> (forall (f : RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) {z : S}, (Eq.{succ u2} S (Polynomial.eval\u2082.{u1, u2} R S _inst_1 _inst_2 f z p) (OfNat.ofNat.{u2} S 0 (Zero.toOfNat0.{u2} S (MonoidWithZero.toZero.{u2} S (Semiring.toMonoidWithZero.{u2} S _inst_2))))) -> (forall (x : R), (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) _x) (MulHomClass.toFunLike.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R S (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u2} S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2))) (NonUnitalRingHomClass.toMulHomClass.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R S (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} S (Semiring.toNonAssocSemiring.{u2} S _inst_2)) (RingHomClass.toNonUnitalRingHomClass.{max u1 u2, u1, u2} (RingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2)) R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2) (RingHom.instRingHomClassRingHom.{u1, u2} R S (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u2} S _inst_2))))) f x) (OfNat.ofNat.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) 0 (Zero.toOfNat0.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) (MonoidWithZero.toZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) (Semiring.toMonoidWithZero.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => S) x) _inst_2))))) -> (Eq.{succ u1} R x (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))))) -> (LT.lt.{0} (WithBot.{0} Nat) (Preorder.toLT.{0} (WithBot.{0} Nat) (WithBot.preorder.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)))) (OfNat.ofNat.{0} (WithBot.{0} Nat) 0 (Zero.toOfNat0.{0} (WithBot.{0} Nat) (WithBot.zero.{0} Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)))) (Polynomial.degree.{u1} R _inst_1 p)))\nCase conversion may be inaccurate. Consider using '#align polynomial.degree_pos_of_eval\u2082_root Polynomial.degree_pos_of_eval\u2082_root\u2093'. -/\ntheorem degree_pos_of_eval\u2082_root {p : R[X]} (hp : p \u2260 0) (f : R \u2192+* S) {z : S}\n    (hz : eval\u2082 f z p = 0) (inj : \u2200 x : R, f x = 0 \u2192 x = 0) : 0 < degree p :=\n  natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_eval\u2082_root hp f hz inj)\n#align polynomial.degree_pos_of_eval\u2082_root Polynomial.degree_pos_of_eval\u2082_root\n\n#print Polynomial.coe_lt_degree /-\n@[simp]\ntheorem coe_lt_degree {p : R[X]} {n : \u2115} : (n : WithBot \u2115) < degree p \u2194 n < natDegree p :=\n  by\n  by_cases h : p = 0\n  \u00b7 simp [h]\n  rw [degree_eq_nat_degree h, WithBot.coe_lt_coe]\n#align polynomial.coe_lt_degree Polynomial.coe_lt_degree\n-/\n\nend Degree\n\nend Semiring\n\nsection Ring\n\nvariable [Ring R] {p q : R[X]}\n\n#print Polynomial.natDegree_sub /-\ntheorem natDegree_sub : (p - q).natDegree = (q - p).natDegree := by rw [\u2190 nat_degree_neg, neg_sub]\n#align polynomial.nat_degree_sub Polynomial.natDegree_sub\n-/\n\n#print Polynomial.natDegree_sub_le_iff_left /-\ntheorem natDegree_sub_le_iff_left (qn : q.natDegree \u2264 n) :\n    (p - q).natDegree \u2264 n \u2194 p.natDegree \u2264 n :=\n  by\n  rw [\u2190 nat_degree_neg] at qn\n  rw [sub_eq_add_neg, nat_degree_add_le_iff_left _ _ qn]\n#align polynomial.nat_degree_sub_le_iff_left Polynomial.natDegree_sub_le_iff_left\n-/\n\n#print Polynomial.natDegree_sub_le_iff_right /-\ntheorem natDegree_sub_le_iff_right (pn : p.natDegree \u2264 n) :\n    (p - q).natDegree \u2264 n \u2194 q.natDegree \u2264 n := by rwa [nat_degree_sub, nat_degree_sub_le_iff_left]\n#align polynomial.nat_degree_sub_le_iff_right Polynomial.natDegree_sub_le_iff_right\n-/\n\n#print Polynomial.coeff_sub_eq_left_of_lt /-\ntheorem coeff_sub_eq_left_of_lt (dg : q.natDegree < n) : (p - q).coeff n = p.coeff n :=\n  by\n  rw [\u2190 nat_degree_neg] at dg\n  rw [sub_eq_add_neg, coeff_add_eq_left_of_lt dg]\n#align polynomial.coeff_sub_eq_left_of_lt Polynomial.coeff_sub_eq_left_of_lt\n-/\n\n/- warning: polynomial.coeff_sub_eq_neg_right_of_lt -> Polynomial.coeff_sub_eq_neg_right_of_lt is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Ring.{u1} R] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)} {q : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)}, (LT.lt.{0} Nat Nat.hasLt (Polynomial.natDegree.{u1} R (Ring.toSemiring.{u1} R _inst_1) p) n) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R (Ring.toSemiring.{u1} R _inst_1) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (Polynomial.sub.{u1} R _inst_1)) p q) n) (Neg.neg.{u1} R (SubNegMonoid.toHasNeg.{u1} R (AddGroup.toSubNegMonoid.{u1} R (AddGroupWithOne.toAddGroup.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R _inst_1))))) (Polynomial.coeff.{u1} R (Ring.toSemiring.{u1} R _inst_1) q n)))\nbut is expected to have type\n  forall {R : Type.{u1}} {n : Nat} [_inst_1 : Ring.{u1} R] {p : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)} {q : Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)}, (LT.lt.{0} Nat instLTNat (Polynomial.natDegree.{u1} R (Ring.toSemiring.{u1} R _inst_1) p) n) -> (Eq.{succ u1} R (Polynomial.coeff.{u1} R (Ring.toSemiring.{u1} R _inst_1) (HSub.hSub.{u1, u1, u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (instHSub.{u1} (Polynomial.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (Polynomial.sub.{u1} R _inst_1)) p q) n) (Neg.neg.{u1} R (Ring.toNeg.{u1} R _inst_1) (Polynomial.coeff.{u1} R (Ring.toSemiring.{u1} R _inst_1) q n)))\nCase conversion may be inaccurate. Consider using '#align polynomial.coeff_sub_eq_neg_right_of_lt Polynomial.coeff_sub_eq_neg_right_of_lt\u2093'. -/\ntheorem coeff_sub_eq_neg_right_of_lt (df : p.natDegree < n) : (p - q).coeff n = -q.coeff n := by\n  rwa [sub_eq_add_neg, coeff_add_eq_right_of_lt, coeff_neg]\n#align polynomial.coeff_sub_eq_neg_right_of_lt Polynomial.coeff_sub_eq_neg_right_of_lt\n\nend Ring\n\nsection NoZeroDivisors\n\nvariable [Semiring R] [NoZeroDivisors R] {p q : R[X]}\n\n/- warning: polynomial.degree_mul_C -> Polynomial.degree_mul_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} (WithBot.{0} Nat) (Polynomial.degree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.degree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} (WithBot.{0} Nat) (Polynomial.degree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) p (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a))) (Polynomial.degree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.degree_mul_C Polynomial.degree_mul_C\u2093'. -/\ntheorem degree_mul_C (a0 : a \u2260 0) : (p * C a).degree = p.degree := by\n  rw [degree_mul, degree_C a0, add_zero]\n#align polynomial.degree_mul_C Polynomial.degree_mul_C\n\n/- warning: polynomial.degree_C_mul -> Polynomial.degree_C_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} (WithBot.{0} Nat) (Polynomial.degree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.degree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} (WithBot.{0} Nat) (Polynomial.degree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.degree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.degree_C_mul Polynomial.degree_C_mul\u2093'. -/\ntheorem degree_C_mul (a0 : a \u2260 0) : (C a * p).degree = p.degree := by\n  rw [degree_mul, degree_C a0, zero_add]\n#align polynomial.degree_C_mul Polynomial.degree_C_mul\n\ntheorem natDegree_mul_c (a0 : a \u2260 0) : (p * C a).natDegree = p.natDegree := by\n  simp only [nat_degree, degree_mul_C a0]\n#align polynomial.nat_degree_mul_C Polynomial.natDegree_mul_c\n\n/- warning: polynomial.nat_degree_C_mul -> Polynomial.natDegree_C_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (Polynomial.{u1} R _inst_1) (instHMul.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.mul'.{u1} R _inst_1)) (coeFn.{succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (fun (_x : RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) => R -> (Polynomial.{u1} R _inst_1)) (RingHom.hasCoeToFun.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nbut is expected to have type\n  forall {R : Type.{u1}} {a : R} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))] {p : Polynomial.{u1} R _inst_1}, (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) -> (Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (HMul.hMul.{u1, u1, u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.{u1} R _inst_1) ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (instHMul.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) a) (Polynomial.mul'.{u1} R _inst_1)) (FunLike.coe.{succ u1, succ u1, succ u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => Polynomial.{u1} R _inst_1) _x) (MulHomClass.toFunLike.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) (RingHomClass.toNonUnitalRingHomClass.{u1, u1, u1} (RingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1))) R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)) (RingHom.instRingHomClassRingHom.{u1, u1} R (Polynomial.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} R _inst_1) (Semiring.toNonAssocSemiring.{u1} (Polynomial.{u1} R _inst_1) (Polynomial.semiring.{u1} R _inst_1)))))) (Polynomial.C.{u1} R _inst_1) a) p)) (Polynomial.natDegree.{u1} R _inst_1 p))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_C_mul Polynomial.natDegree_C_mul\u2093'. -/\ntheorem natDegree_C_mul (a0 : a \u2260 0) : (C a * p).natDegree = p.natDegree := by\n  simp only [nat_degree, degree_C_mul a0]\n#align polynomial.nat_degree_C_mul Polynomial.natDegree_C_mul\n\n/- warning: polynomial.nat_degree_comp -> Polynomial.natDegree_comp is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (Polynomial.comp.{u1} R _inst_1 p q)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Polynomial.natDegree.{u1} R _inst_1 p) (Polynomial.natDegree.{u1} R _inst_1 q))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (Polynomial.comp.{u1} R _inst_1 p q)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Polynomial.natDegree.{u1} R _inst_1 p) (Polynomial.natDegree.{u1} R _inst_1 q))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_comp Polynomial.natDegree_comp\u2093'. -/\ntheorem natDegree_comp : natDegree (p.comp q) = natDegree p * natDegree q :=\n  by\n  by_cases q0 : q.nat_degree = 0\n  \u00b7\n    rw [degree_le_zero_iff.mp (nat_degree_eq_zero_iff_degree_le_zero.mp q0), comp_C, nat_degree_C,\n      nat_degree_C, MulZeroClass.mul_zero]\n  \u00b7 by_cases p0 : p = 0\n    \u00b7 simp only [p0, zero_comp, nat_degree_zero, MulZeroClass.zero_mul]\n    refine' le_antisymm nat_degree_comp_le (le_nat_degree_of_ne_zero _)\n    simp only [coeff_comp_degree_mul_degree q0, p0, mul_eq_zero, leading_coeff_eq_zero, or_self_iff,\n      ne_zero_of_nat_degree_gt (Nat.pos_of_ne_zero q0), pow_ne_zero, Ne.def, not_false_iff]\n#align polynomial.nat_degree_comp Polynomial.natDegree_comp\n\n/- warning: polynomial.nat_degree_iterate_comp -> Polynomial.natDegree_iterate_comp is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1} (k : Nat), Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (Nat.iterate.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.comp.{u1} R _inst_1 p) k q)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) (Polynomial.natDegree.{u1} R _inst_1 p) k) (Polynomial.natDegree.{u1} R _inst_1 q))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1} (k : Nat), Eq.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 (Nat.iterate.{succ u1} (Polynomial.{u1} R _inst_1) (Polynomial.comp.{u1} R _inst_1 p) k q)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) (Polynomial.natDegree.{u1} R _inst_1 p) k) (Polynomial.natDegree.{u1} R _inst_1 q))\nCase conversion may be inaccurate. Consider using '#align polynomial.nat_degree_iterate_comp Polynomial.natDegree_iterate_comp\u2093'. -/\n@[simp]\ntheorem natDegree_iterate_comp (k : \u2115) :\n    ((p.comp^[k]) q).natDegree = p.natDegree ^ k * q.natDegree :=\n  by\n  induction' k with k IH\n  \u00b7 simp\n  \u00b7 rw [Function.iterate_succ_apply', nat_degree_comp, IH, pow_succ, mul_assoc]\n#align polynomial.nat_degree_iterate_comp Polynomial.natDegree_iterate_comp\n\n/- warning: polynomial.leading_coeff_comp -> Polynomial.leadingCoeff_comp is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 q) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{succ u1} R (Polynomial.leadingCoeff.{u1} R _inst_1 (Polynomial.comp.{u1} R _inst_1 p q)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (Distrib.toHasMul.{u1} R (NonUnitalNonAssocSemiring.toDistrib.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))))) (Polynomial.leadingCoeff.{u1} R _inst_1 p) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (Polynomial.leadingCoeff.{u1} R _inst_1 q) (Polynomial.natDegree.{u1} R _inst_1 p))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Semiring.{u1} R] [_inst_2 : NoZeroDivisors.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))] {p : Polynomial.{u1} R _inst_1} {q : Polynomial.{u1} R _inst_1}, (Ne.{1} Nat (Polynomial.natDegree.{u1} R _inst_1 q) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{succ u1} R (Polynomial.leadingCoeff.{u1} R _inst_1 (Polynomial.comp.{u1} R _inst_1 p q)) (HMul.hMul.{u1, u1, u1} R R R (instHMul.{u1} R (NonUnitalNonAssocSemiring.toMul.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Polynomial.leadingCoeff.{u1} R _inst_1 p) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (Polynomial.leadingCoeff.{u1} R _inst_1 q) (Polynomial.natDegree.{u1} R _inst_1 p))))\nCase conversion may be inaccurate. Consider using '#align polynomial.leading_coeff_comp Polynomial.leadingCoeff_comp\u2093'. -/\ntheorem leadingCoeff_comp (hq : natDegree q \u2260 0) :\n    leadingCoeff (p.comp q) = leadingCoeff p * leadingCoeff q ^ natDegree p := by\n  rw [\u2190 coeff_comp_degree_mul_degree hq, \u2190 nat_degree_comp, coeff_nat_degree]\n#align polynomial.leading_coeff_comp Polynomial.leadingCoeff_comp\n\nend NoZeroDivisors\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Polynomial/Degree/Lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7123398243540534}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Violeta Hern\u00e1ndez Palacios\n-/\nimport measure_theory.measurable_space_def\nimport set_theory.cardinal.cofinality\nimport set_theory.cardinal.continuum\n\n/-!\n# Cardinal of sigma-algebras\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIf a sigma-algebra is generated by a set of sets `s`, then the cardinality of the sigma-algebra is\nbounded by `(max (#s) 2) ^ \u2135\u2080`. This is stated in `measurable_space.cardinal_generate_measurable_le`\nand `measurable_space.cardinal_measurable_set_le`.\n\nIn particular, if `#s \u2264 \ud835\udd20`, then the generated sigma-algebra has cardinality at most `\ud835\udd20`, see\n`measurable_space.cardinal_measurable_set_le_continuum`.\n\nFor the proof, we rely on an explicit inductive construction of the sigma-algebra generated by\n`s` (instead of the inductive predicate `generate_measurable`). This transfinite inductive\nconstruction is parameterized by an ordinal `< \u03c9\u2081`, and the cardinality bound is preserved along\neach step of the construction. We show in `measurable_space.generate_measurable_eq_rec` that this\nindeed generates this sigma-algebra.\n-/\n\nuniverse u\nvariables {\u03b1 : Type u}\n\nopen_locale cardinal\nopen cardinal set\n\nlocal notation `\u03c9\u2081` := (aleph 1 : cardinal.{u}).ord.out.\u03b1\n\nnamespace measurable_space\n\n/-- Transfinite induction construction of the sigma-algebra generated by a set of sets `s`. At each\nstep, we add all elements of `s`, the empty set, the complements of already constructed sets, and\ncountable unions of already constructed sets. We index this construction by an ordinal `< \u03c9\u2081`, as\nthis will be enough to generate all sets in the sigma-algebra.\n\nThis construction is very similar to that of the Borel hierarchy. -/\ndef generate_measurable_rec (s : set (set \u03b1)) : \u03c9\u2081 \u2192 set (set \u03b1)\n| i := let S := \u22c3 j : Iio i, generate_measurable_rec j.1 in\n    s \u222a {\u2205} \u222a compl '' S \u222a set.range (\u03bb (f : \u2115 \u2192 S), \u22c3 n, (f n).1)\nusing_well_founded {dec_tac := `[exact j.2]}\n\ntheorem self_subset_generate_measurable_rec (s : set (set \u03b1)) (i : \u03c9\u2081) :\n  s \u2286 generate_measurable_rec s i :=\nbegin\n  unfold generate_measurable_rec,\n  apply_rules [subset_union_of_subset_left],\n  exact subset_rfl\nend\n\ntheorem empty_mem_generate_measurable_rec (s : set (set \u03b1)) (i : \u03c9\u2081) :\n  \u2205 \u2208 generate_measurable_rec s i :=\nbegin\n  unfold generate_measurable_rec,\n  exact mem_union_left _ (mem_union_left _ (mem_union_right _ (mem_singleton \u2205)))\nend\n\ntheorem compl_mem_generate_measurable_rec {s : set (set \u03b1)} {i j : \u03c9\u2081} (h : j < i) {t : set \u03b1}\n  (ht : t \u2208 generate_measurable_rec s j) : t\u1d9c \u2208 generate_measurable_rec s i :=\nbegin\n  unfold generate_measurable_rec,\n  exact mem_union_left _ (mem_union_right _ \u27e8t, mem_Union.2 \u27e8\u27e8j, h\u27e9, ht\u27e9, rfl\u27e9)\nend\n\ntheorem Union_mem_generate_measurable_rec {s : set (set \u03b1)} {i : \u03c9\u2081}\n  {f : \u2115 \u2192 set \u03b1} (hf : \u2200 n, \u2203 j < i, f n \u2208 generate_measurable_rec s j) :\n  (\u22c3 n, f n) \u2208 generate_measurable_rec s i :=\nbegin\n  unfold generate_measurable_rec,\n  exact mem_union_right _ \u27e8\u03bb n, \u27e8f n, let \u27e8j, hj, hf\u27e9 := hf n in mem_Union.2 \u27e8\u27e8j, hj\u27e9, hf\u27e9\u27e9, rfl\u27e9\nend\n\ntheorem generate_measurable_rec_subset (s : set (set \u03b1)) {i j : \u03c9\u2081} (h : i \u2264 j) :\n  generate_measurable_rec s i \u2286 generate_measurable_rec s j :=\n\u03bb x hx, begin\n  rcases eq_or_lt_of_le h with rfl | h,\n  { exact hx },\n  { convert Union_mem_generate_measurable_rec (\u03bb n, \u27e8i, h, hx\u27e9),\n    exact (Union_const x).symm }\nend\n\n/-- At each step of the inductive construction, the cardinality bound `\u2264 (max (#s) 2) ^ \u2135\u2080` holds.\n-/\nlemma cardinal_generate_measurable_rec_le (s : set (set \u03b1)) (i : \u03c9\u2081) :\n  #(generate_measurable_rec s i) \u2264 (max (#s) 2) ^ aleph_0.{u} :=\nbegin\n  apply (aleph 1).ord.out.wo.wf.induction i,\n  assume i IH,\n  have A := aleph_0_le_aleph 1,\n  have B : aleph 1 \u2264 (max (#s) 2) ^ aleph_0.{u} :=\n    aleph_one_le_continuum.trans (power_le_power_right (le_max_right _ _)),\n  have C : \u2135\u2080 \u2264 (max (#s) 2) ^ aleph_0.{u} := A.trans B,\n  have J : #(\u22c3 j : Iio i, generate_measurable_rec s j.1) \u2264 (max (#s) 2) ^ aleph_0.{u},\n  { apply (mk_Union_le _).trans,\n    have D : (\u2a06 j : Iio i, #(generate_measurable_rec s j)) \u2264 _ := csupr_le' (\u03bb \u27e8j, hj\u27e9, IH j hj),\n    apply (mul_le_mul' ((mk_subtype_le _).trans (aleph 1).mk_ord_out.le) D).trans,\n    rw mul_eq_max A C,\n    exact max_le B le_rfl },\n  rw [generate_measurable_rec],\n  apply_rules [(mk_union_le _ _).trans, add_le_of_le C, mk_image_le.trans],\n  { exact (le_max_left _ _).trans (self_le_power _ one_lt_aleph_0.le) },\n  { rw [mk_singleton],\n    exact one_lt_aleph_0.le.trans C },\n  { apply mk_range_le.trans,\n    simp only [mk_pi, subtype.val_eq_coe, prod_const, lift_uzero, mk_denumerable, lift_aleph_0],\n    have := @power_le_power_right _ _ \u2135\u2080 J,\n    rwa [\u2190 power_mul, aleph_0_mul_aleph_0] at this }\nend\n\n/-- `generate_measurable_rec s` generates precisely the smallest sigma-algebra containing `s`. -/\ntheorem generate_measurable_eq_rec (s : set (set \u03b1)) :\n  {t | generate_measurable s t} = \u22c3 i, generate_measurable_rec s i :=\nbegin\n  ext t, refine \u27e8\u03bb ht, _, \u03bb ht, _\u27e9,\n  { inhabit \u03c9\u2081,\n    induction ht with u hu u hu IH f hf IH,\n    { exact mem_Union.2 \u27e8default, self_subset_generate_measurable_rec s _ hu\u27e9 },\n    { exact mem_Union.2 \u27e8default, empty_mem_generate_measurable_rec s _\u27e9 },\n    { rcases mem_Union.1 IH with \u27e8i, hi\u27e9,\n      obtain \u27e8j, hj\u27e9 := exists_gt i,\n      exact mem_Union.2 \u27e8j, compl_mem_generate_measurable_rec hj hi\u27e9 },\n    { have : \u2200 n, \u2203 i, f n \u2208 generate_measurable_rec s i := \u03bb n, by simpa using IH n,\n      choose I hI using this,\n      refine mem_Union.2 \u27e8ordinal.enum (<) (ordinal.lsub (\u03bb n, ordinal.typein.{u} (<) (I n))) _,\n        Union_mem_generate_measurable_rec (\u03bb n, \u27e8I n, _, hI n\u27e9)\u27e9,\n      { rw ordinal.type_lt,\n        refine ordinal.lsub_lt_ord_lift _ (\u03bb i, ordinal.typein_lt_self _),\n        rw [mk_denumerable, lift_aleph_0, is_regular_aleph_one.cof_eq],\n        exact aleph_0_lt_aleph_one },\n      { rw [\u2190ordinal.typein_lt_typein (<), ordinal.typein_enum],\n        apply ordinal.lt_lsub (\u03bb n : \u2115, _) } } },\n  { rcases ht with \u27e8t, \u27e8i, rfl\u27e9, hx\u27e9,\n    revert t,\n    apply (aleph 1).ord.out.wo.wf.induction i,\n    intros j H t ht,\n    unfold generate_measurable_rec at ht,\n    rcases ht with (((h | h) | \u27e8u, \u27e8-, \u27e8\u27e8k, hk\u27e9, rfl\u27e9, hu\u27e9, rfl\u27e9) | \u27e8f, rfl\u27e9),\n    { exact generate_measurable.basic t h },\n    { convert generate_measurable.empty },\n    { exact generate_measurable.compl u (H k hk u hu) },\n    { apply generate_measurable.union _ (\u03bb n, _),\n      obtain \u27e8-, \u27e8\u27e8k, hk\u27e9, rfl\u27e9, hf\u27e9 := (f n).prop,\n      exact H k hk _ hf } }\nend\n\n/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma-algebra has cardinality at\nmost `(max (#s) 2) ^ \u2135\u2080`. -/\ntheorem cardinal_generate_measurable_le (s : set (set \u03b1)) :\n  #{t | generate_measurable s t} \u2264 (max (#s) 2) ^ aleph_0.{u} :=\nbegin\n  rw generate_measurable_eq_rec,\n  apply (mk_Union_le _).trans,\n  rw (aleph 1).mk_ord_out,\n  refine le_trans (mul_le_mul' aleph_one_le_continuum\n    (csupr_le' (\u03bb i, cardinal_generate_measurable_rec_le s i))) _,\n  have := power_le_power_right (le_max_right (#s) 2),\n  rw mul_eq_max aleph_0_le_continuum (aleph_0_le_continuum.trans this),\n  exact max_le this le_rfl\nend\n\n/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma\nalgebra has cardinality at most `(max (#s) 2) ^ \u2135\u2080`. -/\ntheorem cardinal_measurable_set_le (s : set (set \u03b1)) :\n  #{t | @measurable_set \u03b1 (generate_from s) t} \u2264 (max (#s) 2) ^ aleph_0.{u} :=\ncardinal_generate_measurable_le s\n\n/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,\nthen the sigma algebra has the same cardinality bound. -/\ntheorem cardinal_generate_measurable_le_continuum {s : set (set \u03b1)} (hs : #s \u2264 \ud835\udd20) :\n  #{t | generate_measurable s t} \u2264 \ud835\udd20 :=\n(cardinal_generate_measurable_le s).trans begin\n  rw \u2190continuum_power_aleph_0,\n  exact_mod_cast power_le_power_right (max_le hs (nat_lt_continuum 2).le)\nend\n\n/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,\nthen the sigma algebra has the same cardinality bound. -/\ntheorem cardinal_measurable_set_le_continuum {s : set (set \u03b1)} :\n  #s \u2264 \ud835\udd20 \u2192 #{t | @measurable_set \u03b1 (generate_from s) t} \u2264 \ud835\udd20 :=\ncardinal_generate_measurable_le_continuum\n\nend measurable_space\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/card_measurable_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7122438046572906}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro\n-/\nimport data.int.basic\n/-! # Least upper bound and greatest lower bound properties for integers\n\nIn this file we prove that a bounded above nonempty set of integers has the greatest element, and a\ncounterpart of this statement for the least element.\n\n## Main definitions\n\n* `int.least_of_bdd`: if `P : \u2124 \u2192 Prop` is a decidable predicate, `b` is a lower bound of the set\n  `{m | P m}`, and there exists `m : \u2124` such that `P m` (this time, no witness is required), then\n  `int.least_of_bdd` returns the least number `m` such that `P m`, together with proofs of `P m` and\n  of the minimality. This definition is computable and does not rely on the axiom of choice.\n* `int.greatest_of_bdd`: a similar definition with all inequalities reversed.\n\n## Main statements\n\n* `int.exists_least_of_bdd`: if `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is\n  bounded below and nonempty, then this set has the least element. This lemma uses classical logic\n  to avoid assumption `[decidable_pred P]`. See `int.least_of_bdd` for a constructive counterpart.\n\n* `int.coe_least_of_bdd_eq`: `(int.least_of_bdd b Hb Hinh : \u2124)` does not depend on `b`.\n\n* `int.exists_greatest_of_bdd`, `int.coe_greatest_of_bdd_eq`: versions of the above lemmas with all\n  inequalities reversed.\n\n## Tags\n\ninteger numbers, least element, greatest element\n-/\n\nnamespace int\n\n/-- A computable version of `exists_least_of_bdd`: given a decidable predicate on the\nintegers, with an explicit lower bound and a proof that it is somewhere true, return\nthe least value for which the predicate is true. -/\ndef least_of_bdd {P : \u2124 \u2192 Prop} [decidable_pred P]\n  (b : \u2124) (Hb : \u2200 z : \u2124, P z \u2192 b \u2264 z) (Hinh : \u2203 z : \u2124, P z) :\n  {lb : \u2124 // P lb \u2227 (\u2200 z : \u2124, P z \u2192 lb \u2264 z)} :=\nhave EX : \u2203 n : \u2115, P (b + n), from\n  let \u27e8elt, Helt\u27e9 := Hinh in\n  match elt, le.dest (Hb _ Helt), Helt with\n  | ._, \u27e8n, rfl\u27e9, Hn := \u27e8n, Hn\u27e9\n  end,\n\u27e8b + (nat.find EX : \u2124), nat.find_spec EX, \u03bb z h,\n  match z, le.dest (Hb _ h), h with\n  | ._, \u27e8n, rfl\u27e9, h := add_le_add_left\n    (int.coe_nat_le.2 $ nat.find_min' _ h) _\n  end\u27e9\n\n/-- If `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is bounded below and nonempty,\nthen this set has the least element. This lemma uses classical logic to avoid assumption\n`[decidable_pred P]`. See `int.least_of_bdd` for a constructive counterpart. -/\ntheorem exists_least_of_bdd {P : \u2124 \u2192 Prop}\n  (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 b \u2264 z) (Hinh : \u2203 z : \u2124, P z) :\n  \u2203 lb : \u2124, P lb \u2227 (\u2200 z : \u2124, P z \u2192 lb \u2264 z) :=\nby classical; exact let \u27e8b, Hb\u27e9 := Hbdd, \u27e8lb, H\u27e9 := least_of_bdd b Hb Hinh in \u27e8lb, H\u27e9\n\nlemma coe_least_of_bdd_eq {P : \u2124 \u2192 Prop} [decidable_pred P]\n  {b b' : \u2124} (Hb : \u2200 z : \u2124, P z \u2192 b \u2264 z) (Hb' : \u2200 z : \u2124, P z \u2192 b' \u2264 z) (Hinh : \u2203 z : \u2124, P z) :\n  (least_of_bdd b Hb Hinh : \u2124) = least_of_bdd b' Hb' Hinh :=\nbegin\n  rcases least_of_bdd b Hb Hinh with \u27e8n, hn, h2n\u27e9,\n  rcases least_of_bdd b' Hb' Hinh with \u27e8n', hn', h2n'\u27e9,\n  exact le_antisymm (h2n _ hn') (h2n' _ hn),\nend\n\n/-- A computable version of `exists_greatest_of_bdd`: given a decidable predicate on the\nintegers, with an explicit upper bound and a proof that it is somewhere true, return\nthe greatest value for which the predicate is true. -/\ndef greatest_of_bdd {P : \u2124 \u2192 Prop} [decidable_pred P]\n  (b : \u2124) (Hb : \u2200 z : \u2124, P z \u2192 z \u2264 b) (Hinh : \u2203 z : \u2124, P z) :\n  {ub : \u2124 // P ub \u2227 (\u2200 z : \u2124, P z \u2192 z \u2264 ub)} :=\nhave Hbdd' : \u2200 (z : \u2124), P (-z) \u2192 -b \u2264 z, from \u03bb z h, neg_le.1 (Hb _ h),\nhave Hinh' : \u2203 z : \u2124, P (-z), from\nlet \u27e8elt, Helt\u27e9 := Hinh in \u27e8-elt, by rw [neg_neg]; exact Helt\u27e9,\nlet \u27e8lb, Plb, al\u27e9 := least_of_bdd (-b) Hbdd' Hinh' in\n\u27e8-lb, Plb, \u03bb z h, le_neg.1 $ al _ $ by rwa neg_neg\u27e9\n\n/-- If `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is bounded above and nonempty,\nthen this set has the greatest element. This lemma uses classical logic to avoid assumption\n`[decidable_pred P]`. See `int.greatest_of_bdd` for a constructive counterpart. -/\ntheorem exists_greatest_of_bdd {P : \u2124 \u2192 Prop}\n  (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 z \u2264 b) (Hinh : \u2203 z : \u2124, P z) :\n  \u2203 ub : \u2124, P ub \u2227 (\u2200 z : \u2124, P z \u2192 z \u2264 ub) :=\nby classical; exact let \u27e8b, Hb\u27e9 := Hbdd, \u27e8lb, H\u27e9 := greatest_of_bdd b Hb Hinh in \u27e8lb, H\u27e9\n\nlemma coe_greatest_of_bdd_eq {P : \u2124 \u2192 Prop} [decidable_pred P]\n  {b b' : \u2124} (Hb : \u2200 z : \u2124, P z \u2192 z \u2264 b) (Hb' : \u2200 z : \u2124, P z \u2192 z \u2264 b') (Hinh : \u2203 z : \u2124, P z) :\n  (greatest_of_bdd b Hb Hinh : \u2124) = greatest_of_bdd b' Hb' Hinh :=\nbegin\n  rcases greatest_of_bdd b Hb Hinh with \u27e8n, hn, h2n\u27e9,\n  rcases greatest_of_bdd b' Hb' Hinh with \u27e8n', hn', h2n'\u27e9,\n  exact le_antisymm (h2n' _ hn) (h2n _ hn'),\nend\n\nend int\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/int/least_greatest.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.7122438046572905}}
{"text": "/-\nCopyright (c) 2018 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon, Patrick Massot\n\n! This file was ported from Lean 3 source module algebra.big_operators.pi\n! leanprover-community/mathlib commit 509de852e1de55e1efa8eacfa11df0823f26f226\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Algebra.Group.Prod\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Ring.Pi\n\n/-!\n# Big operators for Pi Types\n\nThis file contains theorems relevant to big operators in binary and arbitrary product\nof monoids and groups\n-/\n\n\nopen BigOperators\n\nnamespace Pi\n\n@[to_additive]\ntheorem list_prod_apply {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _} [\u2200 a, Monoid (\u03b2 a)] (a : \u03b1)\n    (l : List (\u2200 a, \u03b2 a)) : l.prod a = (l.map fun f : \u2200 a, \u03b2 a \u21a6 f a).prod :=\n  (evalMonoidHom \u03b2 a).map_list_prod _\n#align pi.list_prod_apply Pi.list_prod_apply\n#align pi.list_sum_apply Pi.list_sum_apply\n\n@[to_additive]\ntheorem multiset_prod_apply {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _} [\u2200 a, CommMonoid (\u03b2 a)] (a : \u03b1)\n    (s : Multiset (\u2200 a, \u03b2 a)) : s.prod a = (s.map fun f : \u2200 a, \u03b2 a \u21a6 f a).prod :=\n  (evalMonoidHom \u03b2 a).map_multiset_prod _\n#align pi.multiset_prod_apply Pi.multiset_prod_apply\n#align pi.multiset_sum_apply Pi.multiset_sum_apply\n\nend Pi\n\n@[to_additive (attr:=simp)]\ntheorem Finset.prod_apply {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _} {\u03b3} [\u2200 a, CommMonoid (\u03b2 a)] (a : \u03b1)\n    (s : Finset \u03b3) (g : \u03b3 \u2192 \u2200 a, \u03b2 a) : (\u220f c in s, g c) a = \u220f c in s, g c a :=\n  (Pi.evalMonoidHom \u03b2 a).map_prod _ _\n#align finset.prod_apply Finset.prod_apply\n#align finset.sum_apply Finset.sum_apply\n\n/-- An 'unapplied' analogue of `Finset.prod_apply`. -/\n@[to_additive \"An 'unapplied' analogue of `Finset.sum_apply`.\"]\ntheorem Finset.prod_fn {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _} {\u03b3} [\u2200 a, CommMonoid (\u03b2 a)] (s : Finset \u03b3)\n    (g : \u03b3 \u2192 \u2200 a, \u03b2 a) : (\u220f c in s, g c) = fun a \u21a6 \u220f c in s, g c a :=\n  funext fun _ \u21a6 Finset.prod_apply _ _ _\n#align finset.prod_fn Finset.prod_fn\n#align finset.sum_fn Finset.sum_fn\n\n@[to_additive]\ntheorem Fintype.prod_apply {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _} {\u03b3 : Type _} [Fintype \u03b3]\n    [\u2200 a, CommMonoid (\u03b2 a)] (a : \u03b1) (g : \u03b3 \u2192 \u2200 a, \u03b2 a) : (\u220f c, g c) a = \u220f c, g c a :=\n  Finset.prod_apply a Finset.univ g\n#align fintype.prod_apply Fintype.prod_apply\n#align fintype.sum_apply Fintype.sum_apply\n\n@[to_additive prod_mk_sum]\ntheorem prod_mk_prod {\u03b1 \u03b2 \u03b3 : Type _} [CommMonoid \u03b1] [CommMonoid \u03b2] (s : Finset \u03b3) (f : \u03b3 \u2192 \u03b1)\n    (g : \u03b3 \u2192 \u03b2) : (\u220f x in s, f x, \u220f x in s, g x) = \u220f x in s, (f x, g x) :=\n  haveI := Classical.decEq \u03b3\n  Finset.induction_on s rfl (by simp (config := { contextual := true }) [Prod.ext_iff])\n#align prod_mk_prod prod_mk_prod\n#align prod_mk_sum prod_mk_sum\n\nsection Single\n\nvariable {I : Type _} [DecidableEq I] {Z : I \u2192 Type _}\n\nvariable [\u2200 i, AddCommMonoid (Z i)]\n\n-- As we only defined `single` into `add_monoid`, we only prove the `finset.sum` version here.\ntheorem Finset.univ_sum_single [Fintype I] (f : \u2200 i, Z i) : (\u2211 i, Pi.single i (f i)) = f := by\n  ext a\n  simp\n#align finset.univ_sum_single Finset.univ_sum_single\n\ntheorem AddMonoidHom.functions_ext [Finite I] (G : Type _) [AddCommMonoid G] (g h : (\u2200 i, Z i) \u2192+ G)\n    (H : \u2200 i x, g (Pi.single i x) = h (Pi.single i x)) : g = h := by\n  cases nonempty_fintype I\n  ext k\n  rw [\u2190 Finset.univ_sum_single k, g.map_sum, h.map_sum]\n  simp only [H]\n#align add_monoid_hom.functions_ext AddMonoidHom.functions_ext\n\n/-- This is used as the ext lemma instead of `AddMonoidHom.functions_ext` for reasons explained in\nnote [partially-applied ext lemmas]. -/\n@[ext]\ntheorem AddMonoidHom.functions_ext' [Finite I] (M : Type _) [AddCommMonoid M]\n    (g h : (\u2200 i, Z i) \u2192+ M)\n    (H : \u2200 i, g.comp (AddMonoidHom.single Z i) = h.comp (AddMonoidHom.single Z i)) : g = h :=\n  have := fun i \u21a6 FunLike.congr_fun (H i)\n  g.functions_ext M h this\n#align add_monoid_hom.functions_ext' AddMonoidHom.functions_ext'\n\nend Single\n\nsection RingHom\n\nopen Pi\n\nvariable {I : Type _} [DecidableEq I] {f : I \u2192 Type _}\n\nvariable [\u2200 i, NonAssocSemiring (f i)]\n\n@[ext]\ntheorem RingHom.functions_ext [Finite I] (G : Type _) [NonAssocSemiring G] (g h : (\u2200 i, f i) \u2192+* G)\n    (H : \u2200 (i : I) (x : f i), g (single i x) = h (single i x)) : g = h :=\n  RingHom.coe_addMonoidHom_injective <|\n    @AddMonoidHom.functions_ext I _ f _ _ G _ (g : (\u2200 i, f i) \u2192+ G) h H\n#align ring_hom.functions_ext RingHom.functions_ext\n\nend RingHom\n\nnamespace Prod\n\nvariable {\u03b1 \u03b2 \u03b3 : Type _} [CommMonoid \u03b1] [CommMonoid \u03b2] {s : Finset \u03b3} {f : \u03b3 \u2192 \u03b1 \u00d7 \u03b2}\n\n@[to_additive]\ntheorem fst_prod : (\u220f c in s, f c).1 = \u220f c in s, (f c).1 :=\n  (MonoidHom.fst \u03b1 \u03b2).map_prod f s\n#align prod.fst_prod Prod.fst_prod\n#align prod.fst_sum Prod.fst_sum\n\n@[to_additive]\ntheorem snd_prod : (\u220f c in s, f c).2 = \u220f c in s, (f c).2 :=\n  (MonoidHom.snd \u03b1 \u03b2).map_prod f s\n#align prod.snd_prod Prod.snd_prod\n#align prod.snd_sum Prod.snd_sum\n\nend Prod\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/BigOperators/Pi.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7122437954794392}}
{"text": "/-\nCopyright (c) 2020 Simon Hudon. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Simon Hudon\n-/\nimport data.stream.init\nimport tactic.apply\nimport control.fix\nimport order.omega_complete_partial_order\n\n/-!\n# Lawful fixed point operators\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis module defines the laws required of a `has_fix` instance, using the theory of\nomega complete partial orders (\u03c9CPO). Proofs of the lawfulness of all `has_fix` instances in\n`control.fix` are provided.\n\n## Main definition\n\n * class `lawful_fix`\n-/\n\nuniverses u v\n\nopen_locale classical\nvariables {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type*}\n\nopen omega_complete_partial_order\n\n/-- Intuitively, a fixed point operator `fix` is lawful if it satisfies `fix f = f (fix f)` for all\n`f`, but this is inconsistent / uninteresting in most cases due to the existence of \"exotic\"\nfunctions `f`, such as the function that is defined iff its argument is not, familiar from the\nhalting problem. Instead, this requirement is limited to only functions that are `continuous` in the\nsense of `\u03c9`-complete partial orders, which excludes the example because it is not monotone\n(making the input argument less defined can make `f` more defined). -/\nclass lawful_fix (\u03b1 : Type*) [omega_complete_partial_order \u03b1] extends has_fix \u03b1 :=\n(fix_eq : \u2200 {f : \u03b1 \u2192o \u03b1}, continuous f \u2192 has_fix.fix f = f (has_fix.fix f))\n\nlemma lawful_fix.fix_eq' {\u03b1} [omega_complete_partial_order \u03b1] [lawful_fix \u03b1]\n  {f : \u03b1 \u2192 \u03b1} (hf : continuous' f) :\n  has_fix.fix f = f (has_fix.fix f) :=\nlawful_fix.fix_eq (hf.to_bundled _)\n\nnamespace part\n\nopen part nat nat.upto\n\nnamespace fix\n\nvariables (f : (\u03a0 a, part $ \u03b2 a) \u2192o (\u03a0 a, part $ \u03b2 a))\n\nlemma approx_mono' {i : \u2115} : fix.approx f i \u2264 fix.approx f (succ i) :=\nbegin\n  induction i, dsimp [approx], apply @bot_le _ _ _ (f \u22a5),\n  intro, apply f.monotone, apply i_ih\nend\n\nlemma approx_mono \u2983i j : \u2115\u2984 (hij : i \u2264 j) : approx f i \u2264 approx f j :=\nbegin\n  induction j with j ih, { cases hij, exact le_rfl },\n  cases hij, { exact le_rfl },\n  exact le_trans (ih \u2039_\u203a) (approx_mono' f)\nend\n\nlemma mem_iff (a : \u03b1) (b : \u03b2 a) : b \u2208 part.fix f a \u2194 \u2203 i, b \u2208 approx f i a :=\nbegin\n  by_cases h\u2080 : \u2203 (i : \u2115), (approx f i a).dom,\n  { simp only [part.fix_def f h\u2080],\n    split; intro hh, exact \u27e8_,hh\u27e9,\n    have h\u2081 := nat.find_spec h\u2080,\n    rw [dom_iff_mem] at h\u2081,\n    cases h\u2081 with y h\u2081,\n    replace h\u2081 := approx_mono' f _ _ h\u2081,\n    suffices : y = b, subst this, exact h\u2081,\n    cases hh with i hh,\n    revert h\u2081, generalize : (succ (nat.find h\u2080)) = j, intro,\n    wlog case : i \u2264 j,\n    { cases le_total i j with H H; [skip, symmetry]; apply_assumption; assumption },\n    replace hh := approx_mono f case _ _ hh,\n    apply part.mem_unique h\u2081 hh },\n  { simp only [fix_def' \u21d1f h\u2080, not_exists, false_iff, not_mem_none],\n    simp only [dom_iff_mem, not_exists] at h\u2080,\n    intro, apply h\u2080 }\nend\n\nlemma approx_le_fix (i : \u2115) : approx f i \u2264 part.fix f :=\nassume a b hh,\nby { rw [mem_iff f], exact \u27e8_,hh\u27e9 }\n\nlemma exists_fix_le_approx (x : \u03b1) : \u2203 i, part.fix f x \u2264 approx f i x :=\nbegin\n  by_cases hh : \u2203 i b, b \u2208 approx f i x,\n  { rcases hh with \u27e8i,b,hb\u27e9, existsi i,\n    intros b' h',\n    have hb' := approx_le_fix f i _ _ hb,\n    obtain rfl := part.mem_unique h' hb',\n    exact hb },\n  { simp only [not_exists] at hh, existsi 0,\n    intros b' h',\n    simp only [mem_iff f] at h',\n    cases h' with i h',\n    cases hh _ _ h' }\nend\n\ninclude f\n\n/-- The series of approximations of `fix f` (see `approx`) as a `chain` -/\ndef approx_chain : chain (\u03a0 a, part $ \u03b2 a) := \u27e8approx f, approx_mono f\u27e9\n\nlemma le_f_of_mem_approx {x} : x \u2208 approx_chain f \u2192 x \u2264 f x :=\nbegin\n  simp only [(\u2208), forall_exists_index],\n  rintro i rfl,\n  apply approx_mono'\nend\n\nlemma approx_mem_approx_chain {i} : approx f i \u2208 approx_chain f :=\nstream.mem_of_nth_eq rfl\n\nend fix\n\nopen fix\n\nvariables {\u03b1}\nvariables (f : (\u03a0 a, part $ \u03b2 a) \u2192o (\u03a0 a, part $ \u03b2 a))\n\nopen omega_complete_partial_order\n\nopen part (hiding \u03c9Sup) nat\nopen nat.upto omega_complete_partial_order\n\nlemma fix_eq_\u03c9Sup : part.fix f = \u03c9Sup (approx_chain f) :=\nbegin\n  apply le_antisymm,\n  { intro x, cases exists_fix_le_approx f x with i hx,\n    transitivity' approx f i.succ x,\n    { transitivity', apply hx, apply approx_mono' f },\n    apply' le_\u03c9Sup_of_le i.succ,\n    dsimp [approx], refl', },\n  { apply \u03c9Sup_le _ _ _,\n    simp only [fix.approx_chain, order_hom.coe_fun_mk],\n    intros y x, apply approx_le_fix f },\nend\n\nlemma fix_le {X : \u03a0 a, part $ \u03b2 a} (hX : f X \u2264 X) : part.fix f \u2264 X :=\nbegin\n  rw fix_eq_\u03c9Sup f,\n  apply \u03c9Sup_le _ _ _,\n  simp only [fix.approx_chain, order_hom.coe_fun_mk],\n  intros i,\n  induction i, dsimp [fix.approx], apply' bot_le,\n  transitivity' f X, apply f.monotone i_ih,\n  apply hX\nend\n\nvariables {f} (hc : continuous f)\ninclude hc\n\nlemma fix_eq : part.fix f = f (part.fix f) :=\nbegin\n  rw [fix_eq_\u03c9Sup f,hc],\n  apply le_antisymm,\n  { apply \u03c9Sup_le_\u03c9Sup_of_le _,\n    intros i, existsi [i], intro x, -- intros x y hx,\n    apply le_f_of_mem_approx _ \u27e8i, rfl\u27e9, },\n  { apply \u03c9Sup_le_\u03c9Sup_of_le _,\n    intros i, existsi i.succ, refl', }\nend\n\nend part\n\nnamespace part\n\n/-- `to_unit` as a monotone function -/\n@[simps]\ndef to_unit_mono (f : part \u03b1 \u2192o part \u03b1) : (unit \u2192 part \u03b1) \u2192o (unit \u2192 part \u03b1) :=\n{ to_fun := \u03bb x u, f (x u),\n  monotone' := \u03bb x y (h : x \u2264 y) u, f.monotone $ h u }\n\nlemma to_unit_cont (f : part \u03b1 \u2192o part \u03b1) (hc : continuous f) : continuous (to_unit_mono f)\n| c := begin\n  ext \u27e8\u27e9 : 1,\n  dsimp [omega_complete_partial_order.\u03c9Sup],\n  erw [hc, chain.map_comp], refl\nend\n\ninstance : lawful_fix (part \u03b1) :=\n\u27e8\u03bb f hc, show part.fix (to_unit_mono f) () = _, by rw part.fix_eq (to_unit_cont f hc); refl\u27e9\n\nend part\n\nopen sigma\n\nnamespace pi\n\ninstance {\u03b2} : lawful_fix (\u03b1 \u2192 part \u03b2) := \u27e8\u03bb f, part.fix_eq\u27e9\n\nvariables {\u03b3 : \u03a0 a : \u03b1, \u03b2 a \u2192 Type*}\n\nsection monotone\n\nvariables (\u03b1 \u03b2 \u03b3)\n\n/-- `sigma.curry` as a monotone function. -/\n@[simps]\ndef monotone_curry [\u2200 x y, preorder $ \u03b3 x y] :\n  (\u03a0 x : \u03a3 a, \u03b2 a, \u03b3 x.1 x.2) \u2192o (\u03a0 a (b : \u03b2 a), \u03b3 a b) :=\n{ to_fun := curry,\n  monotone' := \u03bb x y h a b, h \u27e8a,b\u27e9 }\n\n/-- `sigma.uncurry` as a monotone function. -/\n@[simps]\ndef monotone_uncurry [\u2200 x y, preorder $ \u03b3 x y] :\n  (\u03a0 a (b : \u03b2 a), \u03b3 a b) \u2192o (\u03a0 x : \u03a3 a, \u03b2 a, \u03b3 x.1 x.2) :=\n{ to_fun := uncurry,\n  monotone' := \u03bb x y h a, h a.1 a.2 }\n\nvariables [\u2200 x y, omega_complete_partial_order $ \u03b3 x y]\n\nopen omega_complete_partial_order.chain\n\nlemma continuous_curry : continuous $ monotone_curry \u03b1 \u03b2 \u03b3 :=\n\u03bb c, by { ext x y, dsimp [curry,\u03c9Sup], rw [map_comp,map_comp], refl }\n\nlemma continuous_uncurry : continuous $ monotone_uncurry \u03b1 \u03b2 \u03b3 :=\n\u03bb c, by { ext x y, dsimp [uncurry,\u03c9Sup], rw [map_comp,map_comp], refl }\n\nend monotone\n\nopen has_fix\n\ninstance [has_fix $ \u03a0 x : sigma \u03b2, \u03b3 x.1 x.2] : has_fix (\u03a0 x (y : \u03b2 x), \u03b3 x y) :=\n\u27e8 \u03bb f, curry (fix $ uncurry \u2218 f \u2218 curry) \u27e9\n\nvariables [\u2200 x y, omega_complete_partial_order $ \u03b3 x y]\n\nsection curry\n\nvariables {f : (\u03a0 x (y : \u03b2 x), \u03b3 x y) \u2192o (\u03a0 x (y : \u03b2 x), \u03b3 x y)}\nvariables (hc : continuous f)\n\nlemma uncurry_curry_continuous :\n  continuous $ (monotone_uncurry \u03b1 \u03b2 \u03b3).comp $ f.comp $ monotone_curry \u03b1 \u03b2 \u03b3 :=\ncontinuous_comp _ _\n  (continuous_comp _ _ (continuous_curry _ _ _) hc)\n  (continuous_uncurry _ _ _)\n\nend curry\n\ninstance pi.lawful_fix' [lawful_fix $ \u03a0 x : sigma \u03b2, \u03b3 x.1 x.2] : lawful_fix (\u03a0 x y, \u03b3 x y) :=\n{ fix_eq := \u03bb f hc,\n    begin\n      dsimp [fix],\n      conv { to_lhs, erw [lawful_fix.fix_eq (uncurry_curry_continuous hc)] },\n      refl,\n    end, }\n\nend pi\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/control/lawful_fix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.712243784444523}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport analysis.convex.between\nimport analysis.convex.strict_convex_space\n\n/-!\n# Betweenness in affine spaces for strictly convex spaces\n\nThis file proves results about betweenness for points in an affine space for a strictly convex\nspace.\n\n-/\n\nvariables {V P : Type*} [normed_add_comm_group V] [normed_space \u211d V] [pseudo_metric_space P]\nvariables [normed_add_torsor V P] [strict_convex_space \u211d V]\n\ninclude V\n\nlemma sbtw.dist_lt_max_dist (p : P) {p\u2081 p\u2082 p\u2083 : P} (h : sbtw \u211d p\u2081 p\u2082 p\u2083) :\n  dist p\u2082 p < max (dist p\u2081 p) (dist p\u2083 p) :=\nbegin\n  have hp\u2081p\u2083 : p\u2081 -\u1d65 p \u2260 p\u2083 -\u1d65 p, { by simpa using h.left_ne_right },\n  rw [sbtw, \u2190wbtw_vsub_const_iff p, wbtw, affine_segment_eq_segment,\n      \u2190insert_endpoints_open_segment, set.mem_insert_iff, set.mem_insert_iff] at h,\n  rcases h with \u27e8h | h | h, hp\u2082p\u2081, hp\u2082p\u2083\u27e9,\n  { rw vsub_left_cancel_iff at h, exact false.elim (hp\u2082p\u2081 h) },\n  { rw vsub_left_cancel_iff at h, exact false.elim (hp\u2082p\u2083 h) },\n  { rw [open_segment_eq_image, set.mem_image] at h,\n    rcases h with \u27e8r, \u27e8hr0, hr1\u27e9, hr\u27e9,\n    simp_rw [@dist_eq_norm_vsub V, \u2190hr],\n    exact norm_combo_lt_of_ne (le_max_left _ _) (le_max_right _ _) hp\u2081p\u2083 (sub_pos.2 hr1) hr0\n      (by abel) }\nend\n\nlemma wbtw.dist_le_max_dist (p : P) {p\u2081 p\u2082 p\u2083 : P} (h : wbtw \u211d p\u2081 p\u2082 p\u2083) :\n  dist p\u2082 p \u2264 max (dist p\u2081 p) (dist p\u2083 p) :=\nbegin\n  by_cases hp\u2081 : p\u2082 = p\u2081, { simp [hp\u2081] },\n  by_cases hp\u2083 : p\u2082 = p\u2083, { simp [hp\u2083] },\n  have hs : sbtw \u211d p\u2081 p\u2082 p\u2083 := \u27e8h, hp\u2081, hp\u2083\u27e9,\n  exact (hs.dist_lt_max_dist _).le\nend\n\n/-- Given three collinear points, two (not equal) with distance `r` from `p` and one with\ndistance at most `r` from `p`, the third point is weakly between the other two points. -/\nlemma collinear.wbtw_of_dist_eq_of_dist_le {p p\u2081 p\u2082 p\u2083 : P} {r : \u211d}\n  (h : collinear \u211d ({p\u2081, p\u2082, p\u2083} : set P)) (hp\u2081 : dist p\u2081 p = r) (hp\u2082 : dist p\u2082 p \u2264 r)\n  (hp\u2083 : dist p\u2083 p = r) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) : wbtw \u211d p\u2081 p\u2082 p\u2083 :=\nbegin\n  rcases h.wbtw_or_wbtw_or_wbtw with hw | hw | hw,\n  { exact hw },\n  { by_cases hp\u2083p\u2082 : p\u2083 = p\u2082, { simp [hp\u2083p\u2082] },\n    have hs : sbtw \u211d p\u2082 p\u2083 p\u2081 := \u27e8hw, hp\u2083p\u2082, hp\u2081p\u2083.symm\u27e9,\n    have hs' := hs.dist_lt_max_dist p,\n    rw [hp\u2081, hp\u2083, lt_max_iff, lt_self_iff_false, or_false] at hs',\n    exact false.elim (hp\u2082.not_lt hs') },\n  { by_cases hp\u2081p\u2082 : p\u2081 = p\u2082, { simp [hp\u2081p\u2082] },\n    have hs : sbtw \u211d p\u2083 p\u2081 p\u2082 := \u27e8hw, hp\u2081p\u2083, hp\u2081p\u2082\u27e9,\n    have hs' := hs.dist_lt_max_dist p,\n    rw [hp\u2081, hp\u2083, lt_max_iff, lt_self_iff_false, false_or] at hs',\n    exact false.elim (hp\u2082.not_lt hs') }\nend\n\n/-- Given three collinear points, two (not equal) with distance `r` from `p` and one with\ndistance less than `r` from `p`, the third point is strictly between the other two points. -/\nlemma collinear.sbtw_of_dist_eq_of_dist_lt {p p\u2081 p\u2082 p\u2083 : P} {r : \u211d}\n  (h : collinear \u211d ({p\u2081, p\u2082, p\u2083} : set P)) (hp\u2081 : dist p\u2081 p = r) (hp\u2082 : dist p\u2082 p < r)\n  (hp\u2083 : dist p\u2083 p = r) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) : sbtw \u211d p\u2081 p\u2082 p\u2083 :=\nbegin\n  refine \u27e8h.wbtw_of_dist_eq_of_dist_le hp\u2081 hp\u2082.le hp\u2083 hp\u2081p\u2083, _, _\u27e9,\n  { rintro rfl, exact hp\u2082.ne hp\u2081 },\n  { rintro rfl, exact hp\u2082.ne hp\u2083 }\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/convex/strict_convex_between.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114835, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7122105132080144}}
{"text": "/-\nCopyright (c) 2014 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Gabriel Ebner\n\n! This file was ported from Lean 3 source module data.nat.cast.defs\n! leanprover-community/mathlib commit a148d797a1094ab554ad4183a4ad6f130358ef64\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Defs\nimport Mathlib.Algebra.NeZero\nimport Mathlib.Tactic.SplitIfs\n\n/-!\n# Cast of natural numbers\n\nThis file defines the *canonical* homomorphism from the natural numbers into an\n`AddMonoid` with a one.  In additive monoids with one, there exists a unique\nsuch homomorphism and we store it in the `natCast : \u2115 \u2192 R` field.\n\nPreferentially, the homomorphism is written as the coercion `Nat.cast`.\n\n## Main declarations\n\n* `NatCast`: Type class for `Nat.cast`.\n* `AddMonoidWithOne`: Type class for which `Nat.cast` is a canonical monoid homomorphism from `\u2115`.\n* `Nat.cast`: Canonical homomorphism `\u2115 \u2192 R`.\n-/\n\n/-- The numeral `((0+1)+\u22ef)+1`. -/\nprotected def Nat.unaryCast {R : Type u} [One R] [Zero R] [Add R] : \u2115 \u2192 R\n  | 0 => 0\n  | n + 1 => Nat.unaryCast n + 1\n#align nat.unary_cast Nat.unaryCast\n\n#align has_nat_cast NatCast\n#align has_nat_cast.nat_cast NatCast.natCast\n\n#align nat.cast Nat.cast\n\n-- the following four declarations are not in mathlib3 and are relevant to the way numeric\n-- literals are handled in Lean 4.\n\n/-- A type class for natural numbers which are greater than or equal to `2`. -/\nclass Nat.AtLeastTwo (n : \u2115) : Prop where\n  prop : n \u2265 2\n\ninstance : Nat.AtLeastTwo (n + 2) where\n  prop := Nat.succ_le_succ $ Nat.succ_le_succ $ Nat.zero_le _\n\n/-- Recognize numeric literals which are at least `2` as terms of `R` via `Nat.cast`. This\ninstance is what makes things like `37 : R` type check.  Note that `0` and `1` are not needed\nbecause they are recognized as terms of `R` (at least when `R` is an `AddMonoidWithOne`) through\n`Zero` and `One`, respectively. -/\n@[nolint unusedArguments]\ninstance [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where\n  ofNat := n.cast\n\n@[simp, norm_cast] theorem Nat.cast_ofNat [NatCast R] [Nat.AtLeastTwo n] :\n  (Nat.cast (OfNat.ofNat n) : R) = OfNat.ofNat n := rfl\n\ntheorem Nat.cast_eq_ofNat [NatCast R] [Nat.AtLeastTwo n] : (Nat.cast n : R) = OfNat.ofNat n := rfl\n\n/-! ### Additive monoids with one -/\n\n/-- An `AddMonoidWithOne` is an `AddMonoid` with a `1`.\nIt also contains data for the unique homomorphism `\u2115 \u2192 R`. -/\nclass AddMonoidWithOne (R : Type u) extends NatCast R, AddMonoid R, One R where\n  natCast := Nat.unaryCast\n  /-- The canonical map `\u2115 \u2192 R` sends `0 : \u2115` to `0 : R`. -/\n  natCast_zero : natCast 0 = 0 := by intros; rfl\n  /-- The canonical map `\u2115 \u2192 R` is a homomorphism. -/\n  natCast_succ : \u2200 n, natCast (n + 1) = natCast n + 1 := by intros; rfl\n#align add_monoid_with_one AddMonoidWithOne\n#align add_monoid_with_one.to_has_nat_cast AddMonoidWithOne.toNatCast\n#align add_monoid_with_one.to_add_monoid AddMonoidWithOne.toAddMonoid\n#align add_monoid_with_one.to_has_one AddMonoidWithOne.toOne\n#align add_monoid_with_one.nat_cast_zero AddMonoidWithOne.natCast_zero\n#align add_monoid_with_one.nat_cast_succ AddMonoidWithOne.natCast_succ\n\n/-- An `AddCommMonoidWithOne` is an `AddMonoidWithOne` satisfying `a + b = b + a`.  -/\nclass AddCommMonoidWithOne (R : Type _) extends AddMonoidWithOne R, AddCommMonoid R\n#align add_comm_monoid_with_one AddCommMonoidWithOne\n#align add_comm_monoid_with_one.to_add_monoid_with_one AddCommMonoidWithOne.toAddMonoidWithOne\n#align add_comm_monoid_with_one.to_add_comm_monoid AddCommMonoidWithOne.toAddCommMonoid\n\nlibrary_note \"coercion into rings\"\n/--\nCoercions such as `Nat.castCoe` that go from a concrete structure such as\n`\u2115` to an arbitrary ring `R` should be set up as follows:\n```lean\ninstance : CoeTail \u2115 R where coe := ...\ninstance : CoeHTCT \u2115 R where coe := ...\n```\n\nIt needs to be `CoeTail` instead of `Coe` because otherwise type-class\ninference would loop when constructing the transitive coercion `\u2115 \u2192 \u2115 \u2192 \u2115 \u2192 ...`.\nSometimes we also need to declare the `CoeHTCT` instance\nif we need to shadow another coercion\n(e.g. `Nat.cast` should be used over `Int.ofNat`).\n-/\n\nnamespace Nat\nvariable [AddMonoidWithOne R]\n\n@[simp, norm_cast]\ntheorem cast_zero : ((0 : \u2115) : R) = 0 :=\n  AddMonoidWithOne.natCast_zero\n#align nat.cast_zero Nat.cast_zero\n\n-- Lemmas about nat.succ need to get a low priority, so that they are tried last.\n-- This is because `nat.succ _` matches `1`, `3`, `x+1`, etc.\n-- Rewriting would then produce really wrong terms.\n@[simp 500, norm_cast 500]\ntheorem cast_succ (n : \u2115) : ((succ n : \u2115) : R) = n + 1 :=\n  AddMonoidWithOne.natCast_succ _\n#align nat.cast_succ Nat.cast_succ\n\ntheorem cast_add_one (n : \u2115) : ((n + 1 : \u2115) : R) = n + 1 :=\n  cast_succ _\n#align nat.cast_add_one Nat.cast_add_one\n\n@[simp, norm_cast]\ntheorem cast_ite (P : Prop) [Decidable P] (m n : \u2115) :\n    ((ite P m n : \u2115) : R) = ite P (m : R) (n : R) := by\n  split_ifs <;> rfl\n#align nat.cast_ite Nat.cast_ite\n\nend Nat\n\nnamespace Nat\n\n@[simp, norm_cast]\ntheorem cast_one [AddMonoidWithOne R] : ((1 : \u2115) : R) = 1 := by\n  rw [cast_succ, Nat.cast_zero, zero_add]\n#align nat.cast_one Nat.cast_one\u2093\n\n@[simp, norm_cast]\n\n\n/-- Computationally friendlier cast than `Nat.unaryCast`, using binary representation. -/\nprotected def binCast [Zero R] [One R] [Add R] : \u2115 \u2192 R\n  | 0 => 0\n  | n + 1 => if (n + 1) % 2 = 0\n    then (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2))\n    else (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2)) + 1\ndecreasing_by (exact Nat.div_lt_self (Nat.succ_pos n) (Nat.le_refl 2))\n#align nat.bin_cast Nat.binCast\n\n@[simp]\ntheorem binCast_eq [AddMonoidWithOne R] (n : \u2115) : (Nat.binCast n : R) = ((n : \u2115) : R) := by\n  apply Nat.strongInductionOn n\n  intros k hk\n  cases k with\n  | zero => rw [Nat.binCast, Nat.cast_zero]\n  | succ k =>\n      rw [Nat.binCast]\n      by_cases h : (k + 1) % 2 = 0\n      \u00b7 rw [\u2190Nat.mod_add_div (succ k) 2]\n        rw [if_pos h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), \u2190Nat.cast_add]\n        rw [Nat.succ_eq_add_one, h, Nat.zero_add, Nat.succ_mul, Nat.one_mul]\n      \u00b7 rw [\u2190Nat.mod_add_div (succ k) 2]\n        rw [if_neg h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), \u2190Nat.cast_add]\n        have h1 := Or.resolve_left (Nat.mod_two_eq_zero_or_one (succ k)) h\n        rw [h1, Nat.add_comm 1, Nat.succ_mul, Nat.one_mul]\n        simp only [Nat.cast_add, Nat.cast_one]\n#align nat.bin_cast_eq Nat.binCast_eq\n\nsection deprecated\nset_option linter.deprecated false\n\n@[norm_cast, deprecated]\ntheorem cast_bit0 [AddMonoidWithOne R] (n : \u2115) : ((bit0 n : \u2115) : R) = bit0 (n : R) :=\n  Nat.cast_add _ _\n#align nat.cast_bit0 Nat.cast_bit0\n\n@[norm_cast, deprecated]\ntheorem cast_bit1 [AddMonoidWithOne R] (n : \u2115) : ((bit1 n : \u2115) : R) = bit1 (n : R) := by\n  rw [bit1, cast_add_one, cast_bit0]; rfl\n#align nat.cast_bit1 Nat.cast_bit1\n\nend deprecated\n\ntheorem cast_two [AddMonoidWithOne R] : ((2 : \u2115) : R) = (2 : R) := rfl\n#align nat.cast_two Nat.cast_two\n\nattribute [simp, norm_cast] Int.natAbs_ofNat\n\nend Nat\n\n/-- `AddMonoidWithOne` implementation using unary recursion. -/\n@[reducible]\nprotected def AddMonoidWithOne.unary {R : Type _} [AddMonoid R] [One R] : AddMonoidWithOne R :=\n  { \u2039One R\u203a, \u2039AddMonoid R\u203a with }\n#align add_monoid_with_one.unary AddMonoidWithOne.unary\n\n/-- `AddMonoidWithOne` implementation using binary recursion. -/\n@[reducible]\nprotected def AddMonoidWithOne.binary {R : Type _} [AddMonoid R] [One R] : AddMonoidWithOne R :=\n  { \u2039One R\u203a, \u2039AddMonoid R\u203a with\n    natCast := Nat.binCast,\n    natCast_zero := by simp only [Nat.binCast, Nat.cast],\n    natCast_succ := fun n => by\n      dsimp only [NatCast.natCast]\n      letI : AddMonoidWithOne R := AddMonoidWithOne.unary\n      rw [Nat.binCast_eq, Nat.binCast_eq, Nat.cast_succ] }\n#align add_monoid_with_one.binary AddMonoidWithOne.binary\n\nnamespace NeZero\n\nlemma natCast_ne (n : \u2115) (R) [AddMonoidWithOne R] [h : NeZero (n : R)] :\n  (n : R) \u2260 0 := h.out\n#align ne_zero.nat_cast_ne NeZero.natCast_ne\n\nlemma of_neZero_natCast (R) [AddMonoidWithOne R] {n : \u2115} [h : NeZero (n : R)] : NeZero n :=\n  \u27e8by rintro rfl; exact h.out Nat.cast_zero\u27e9\n#align ne_zero.of_ne_zero_coe NeZero.of_neZero_natCast\n\nlemma pos_of_neZero_natCast (R) [AddMonoidWithOne R] {n : \u2115} [NeZero (n : R)] : 0 < n :=\n  Nat.pos_of_ne_zero (of_neZero_natCast R).out\n#align ne_zero.pos_of_ne_zero_coe NeZero.pos_of_neZero_natCast\n\nend NeZero\n\ntheorem one_add_one_eq_two [AddMonoidWithOne \u03b1] : 1 + 1 = (2 : \u03b1) := by\n  rw [\u2190Nat.cast_one, \u2190Nat.cast_add]\n  apply congrArg\n  decide\n#align one_add_one_eq_two one_add_one_eq_two\n\ntheorem two_add_one_eq_three [AddMonoidWithOne \u03b1] : 2 + 1 = (3 : \u03b1) := by\n  rw [\u2190one_add_one_eq_two, \u2190Nat.cast_one, \u2190Nat.cast_add, \u2190Nat.cast_add]\n  apply congrArg\n  decide\n\ntheorem three_add_one_eq_four [AddMonoidWithOne \u03b1] : 3 + 1 = (4 : \u03b1) := by\n  rw [\u2190two_add_one_eq_three, \u2190one_add_one_eq_two, \u2190Nat.cast_one,\n    \u2190Nat.cast_add, \u2190Nat.cast_add, \u2190Nat.cast_add]\n  apply congrArg\n  decide\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Cast/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7122105012999257}}
{"text": "/-\nCopyright (c) 2021 David Renshaw. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Renshaw\n-/\n\nimport algebra.geom_sum\nimport data.rat.basic\nimport data.real.basic\n\n/-!\n# IMO 2013 Q5\n\nLet `\u211a>\u2080` be the positive rational numbers. Let `f : \u211a>\u2080 \u2192 \u211d` be a function satisfying\nthe conditions\n\n1. `f(x) * f(y) \u2265 f(x * y)`\n2. `f(x + y) \u2265 f(x) + f(y)`\n\nfor all `x, y \u2208 \u211a>\u2080`. Given that `f(a) = a` for some rational `a > 1`, prove that `f(x) = x` for\nall `x \u2208 \u211a>\u2080`.\n\n# Solution\n\nWe provide a direct translation of the solution found in\nhttps://www.imo-official.org/problems/IMO2013SL.pdf\n-/\n\nopen_locale big_operators\n\nlemma le_of_all_pow_lt_succ {x y : \u211d} (hx : 1 < x) (hy : 1 < y)\n  (h : \u2200 n : \u2115, 0 < n \u2192 x^n - 1 < y^n) :\n  x \u2264 y :=\nbegin\n  by_contra hxy,\n  push_neg at hxy,\n  have hxmy : 0 < x - y := sub_pos.mpr hxy,\n  have hn : \u2200 n : \u2115, 0 < n \u2192 (x - y) * (n : \u211d) \u2264 x^n - y^n,\n  { intros n hn,\n    have hterm : \u2200 i : \u2115, i \u2208 finset.range n \u2192 1 \u2264 x^i * y^(n - 1 - i),\n    { intros i hi,\n      have hx' : 1 \u2264 x ^ i := one_le_pow_of_one_le hx.le i,\n      have hy' : 1 \u2264 y ^ (n - 1 - i) := one_le_pow_of_one_le hy.le (n - 1 - i),\n      calc 1 \u2264 x^i             : hx'\n         ... = x^i * 1         : (mul_one _).symm\n         ... \u2264 x^i * y^(n-1-i) : mul_le_mul_of_nonneg_left hy' (zero_le_one.trans hx') },\n\n    calc (x - y) * (n : \u211d)\n            = (n : \u211d) * (x - y) : mul_comm _ _\n        ... = (\u2211 (i : \u2115) in finset.range n, (1 : \u211d)) * (x - y) :\n                                  by simp only [mul_one, finset.sum_const, nsmul_eq_mul,\n                                    finset.card_range]\n        ... \u2264 (\u2211 (i : \u2115) in finset.range n, x ^ i * y ^ (n - 1 - i)) * (x-y) :\n                                  (mul_le_mul_right hxmy).mpr (finset.sum_le_sum hterm)\n        ... = x^n - y^n         : geom_sum\u2082_mul x y n, },\n\n  -- Choose n larger than 1 / (x - y).\n  obtain \u27e8N, hN\u27e9 := exists_nat_gt (1 / (x - y)),\n  have hNp : 0 < N, { exact_mod_cast (one_div_pos.mpr hxmy).trans hN },\n\n  have := calc 1 = (x - y) * (1 / (x - y)) : by field_simp [ne_of_gt hxmy]\n             ... < (x - y) * N             : (mul_lt_mul_left hxmy).mpr hN\n             ... \u2264 x^N - y^N               : hn N hNp,\n  linarith [h N hNp]\nend\n\n/--\n Like le_of_all_pow_lt_succ, but with a weaker assumption for y.\n-/\nlemma le_of_all_pow_lt_succ' {x y : \u211d} (hx : 1 < x) (hy : 0 < y)\n  (h : \u2200 n : \u2115, 0 < n \u2192 x^n - 1 < y^n) :\n  x \u2264 y :=\nbegin\n  refine le_of_all_pow_lt_succ hx _ h,\n  by_contra hy'',\n  push_neg at hy'', -- hy'' : y \u2264 1.\n\n  -- Then there exists y' such that 0 < y \u2264 1 < y' < x.\n  let y' := (x + 1) / 2,\n  have h_y'_lt_x : y' < x,\n  { have hh : (x + 1)/2 < (x * 2) / 2, { linarith },\n    calc y' < (x * 2) / 2 : hh\n        ... = x           : by field_simp },\n  have h1_lt_y' : 1 < y',\n  { have hh' : 1 * 2 / 2 < (x + 1) / 2, { linarith },\n    calc 1 = 1 * 2 / 2 : by field_simp\n       ... < y'        : hh' },\n  have h_y_lt_y' : y < y' := hy''.trans_lt h1_lt_y',\n  have hh : \u2200 n, 0 < n \u2192 x^n - 1 < y'^n,\n  { intros n hn,\n    calc x^n - 1 < y^n  : h n hn\n            ...  \u2264 y'^n : pow_le_pow_of_le_left hy.le h_y_lt_y'.le n },\n  exact h_y'_lt_x.not_le (le_of_all_pow_lt_succ hx h1_lt_y' hh)\nend\n\nlemma f_pos_of_pos {f : \u211a \u2192 \u211d} {q : \u211a} (hq : 0 < q)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n  0 < f q :=\nbegin\n  have num_pos : 0 < q.num := rat.num_pos_iff_pos.mpr hq,\n  have hmul_pos :=\n    calc (0 : \u211d) < q.num   : int.cast_pos.mpr num_pos\n      ... = ((q.num.nat_abs : \u2124) : \u211d) : congr_arg coe (int.nat_abs_of_nonneg num_pos.le).symm\n      ... \u2264 f q.num.nat_abs           : H4 q.num.nat_abs\n                                          (int.nat_abs_pos_of_ne_zero num_pos.ne')\n      ... = f q.num : by { rw \u2190int.nat_abs_of_nonneg num_pos.le, norm_cast }\n      ... = f (q * q.denom) : by rw \u2190rat.mul_denom_eq_num\n      ... \u2264 f q * f q.denom : H1 q q.denom hq (nat.cast_pos.mpr q.pos),\n  have h_f_denom_pos :=\n    calc (0 : \u211d) < q.denom : nat.cast_pos.mpr q.pos\n      ... \u2264 f q.denom : H4 q.denom q.pos,\n  exact pos_of_mul_pos_right hmul_pos h_f_denom_pos.le,\nend\n\nlemma fx_gt_xm1 {f : \u211a \u2192 \u211d} {x : \u211a} (hx : 1 \u2264 x)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n  (x - 1 : \u211d) < f x :=\nbegin\n  have hx0 :=\n    calc (x - 1 : \u211d)\n          < \u230ax\u230b\u208a   : by exact_mod_cast nat.sub_one_lt_floor x\n      ... \u2264 f \u230ax\u230b\u208a : H4 _ (nat.floor_pos.2 hx),\n\n  obtain h_eq | h_lt := (nat.floor_le $ zero_le_one.trans hx).eq_or_lt,\n  { rwa h_eq at hx0 },\n\n  calc (x - 1 : \u211d) < f \u230ax\u230b\u208a : hx0\n    ... < f (x - \u230ax\u230b\u208a) + f \u230ax\u230b\u208a : lt_add_of_pos_left _ (f_pos_of_pos (sub_pos.mpr h_lt) H1 H4)\n    ... \u2264 f (x - \u230ax\u230b\u208a + \u230ax\u230b\u208a)   : H2 _ _ (sub_pos.mpr h_lt) (nat.cast_pos.2 (nat.floor_pos.2 hx))\n    ... = f x                   : by rw sub_add_cancel\nend\n\nlemma pow_f_le_f_pow {f : \u211a \u2192 \u211d} {n : \u2115} (hn : 0 < n) {x : \u211a} (hx : 1 < x)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n  f (x^n) \u2264 (f x)^n :=\nbegin\n  induction n with pn hpn,\n  { exfalso, exact nat.lt_asymm hn hn },\n  cases pn,\n  { simp only [pow_one] },\n  have hpn' := hpn pn.succ_pos,\n  rw [pow_succ' x (pn + 1), pow_succ' (f x) (pn + 1)],\n  have hxp : 0 < x := zero_lt_one.trans hx,\n  calc f ((x ^ (pn+1)) * x)\n          \u2264 f (x ^ (pn+1)) * f x : H1 (x ^ (pn+1)) x (pow_pos hxp (pn+1)) hxp\n      ... \u2264 (f x) ^ (pn+1) * f x : (mul_le_mul_right (f_pos_of_pos hxp H1 H4)).mpr hpn'\nend\n\nlemma fixed_point_of_pos_nat_pow {f : \u211a \u2192 \u211d} {n : \u2115} (hn : 0 < n)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n)\n  (H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x)\n  {a : \u211a} (ha1 : 1 < a) (hae : f a = a) :\n  f (a^n) = a^n :=\nbegin\n  have hh0 : (a : \u211d) ^ n \u2264 f (a ^ n),\n  { exact_mod_cast H5 (a ^ n) (one_lt_pow ha1 hn.ne') },\n\n  have hh1 := calc f (a^n) \u2264 (f a)^n   : pow_f_le_f_pow hn ha1 H1 H4\n                       ... = (a : \u211d)^n : by rw \u2190 hae,\n\n  exact hh1.antisymm hh0\nend\n\nlemma fixed_point_of_gt_1 {f : \u211a \u2192 \u211d} {x : \u211a} (hx : 1 < x)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n)\n  (H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x)\n  {a : \u211a} (ha1 : 1 < a) (hae : f a = a) :\n  f x = x :=\nbegin\n  -- Choose n such that 1 + x < a^n.\n  obtain \u27e8N, hN\u27e9 := pow_unbounded_of_one_lt (1 + x) ha1,\n  have h_big_enough : (1:\u211a) < a^N - x := lt_sub_iff_add_lt.mpr hN,\n\n  have h1 := calc (x : \u211d) + ((a^N - x) : \u211a)\n                        \u2264 f x + ((a^N - x) : \u211a) : add_le_add_right (H5 x hx) _\n                    ... \u2264 f x + f (a^N - x)     : add_le_add_left (H5 _ h_big_enough) _,\n\n  have hxp : 0 < x := zero_lt_one.trans hx,\n\n  have hNp : 0 < N,\n  { by_contra H, push_neg at H, rw [nat.le_zero_iff.mp H] at hN, linarith },\n\n  have h2 := calc f x + f (a^N - x)\n                        \u2264 f (x + (a^N - x)) : H2 x (a^N - x) hxp (zero_lt_one.trans h_big_enough)\n                    ... = f (a^N)           : by ring_nf\n                    ... = a^N               : fixed_point_of_pos_nat_pow hNp H1 H4 H5 ha1 hae\n                    ... = x + (a^N - x)     : by ring,\n\n  have heq := h1.antisymm (by exact_mod_cast h2),\n  linarith [H5 x hx, H5 _ h_big_enough]\nend\n\ntheorem imo2013_q5\n  (f : \u211a \u2192 \u211d)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n  (H_fixed_point : \u2203 a, 1 < a \u2227 f a = a) :\n  \u2200 x, 0 < x \u2192 f x = x :=\nbegin\n  obtain \u27e8a, ha1, hae\u27e9 := H_fixed_point,\n  have H3 : \u2200 x : \u211a, 0 < x \u2192 \u2200 n : \u2115, 0 < n \u2192 \u2191n * f x \u2264 f (n * x),\n  { intros x hx n hn,\n    cases n,\n    { exact (lt_irrefl 0 hn).elim },\n    induction n with pn hpn,\n    { simp only [one_mul, nat.cast_one] },\n    calc (\u2191pn + 1 + 1) * f x\n          = ((pn : \u211d) + 1) * f x + 1 * f x : add_mul (\u2191pn + 1) 1 (f x)\n      ... = (\u2191pn + 1) * f x + f x          : by rw one_mul\n      ... \u2264 f ((\u2191pn.succ) * x) + f x       : by exact_mod_cast add_le_add_right\n                                                  (hpn pn.succ_pos) (f x)\n      ... \u2264 f ((\u2191pn + 1) * x + x)          : by exact_mod_cast H2 _ _\n                                                  (mul_pos pn.cast_add_one_pos hx) hx\n      ... = f ((\u2191pn + 1) * x + 1 * x)      : by rw one_mul\n      ... = f ((\u2191pn + 1 + 1) * x)          : congr_arg f (add_mul (\u2191pn + 1) 1 x).symm },\n  have H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n,\n  { intros n hn,\n    have hf1 : 1 \u2264 f 1,\n    { have a_pos : (0 : \u211d) < a := rat.cast_pos.mpr (zero_lt_one.trans ha1),\n      suffices : \u2191a * 1 \u2264 \u2191a * f 1, from (mul_le_mul_left a_pos).mp this,\n      calc \u2191a * 1 = \u2191a        : mul_one \u2191a\n              ... = f a       : hae.symm\n              ... = f (a * 1) : by rw mul_one\n              ... \u2264 f a * f 1 : (H1 a 1) (zero_lt_one.trans ha1) zero_lt_one\n              ... = \u2191a * f 1  : by rw hae },\n\n    calc (n : \u211d) = (n : \u211d) * 1   : (mul_one _).symm\n             ... \u2264 (n : \u211d) * f 1 : mul_le_mul_of_nonneg_left hf1 (nat.cast_nonneg _)\n             ... \u2264 f (n * 1)     : H3 1 zero_lt_one n hn\n             ... = f n           : by rw mul_one },\n\n  have H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x,\n  { intros x hx,\n    have hxnm1 : \u2200 n : \u2115, 0 < n \u2192 (x : \u211d)^n - 1 < (f x)^n,\n    { intros n hn,\n      calc (x : \u211d)^n - 1 < f (x^n) : by exact_mod_cast fx_gt_xm1 (one_le_pow_of_one_le hx.le n)\n                                          H1 H2 H4\n                     ... \u2264 (f x)^n : pow_f_le_f_pow hn hx H1 H4 },\n    have hx' : 1 < (x : \u211d) := by exact_mod_cast hx,\n    have hxp : 0 < x := zero_lt_one.trans hx,\n    exact le_of_all_pow_lt_succ' hx' (f_pos_of_pos hxp H1 H4) hxnm1 },\n\n  have h_f_commutes_with_pos_nat_mul : \u2200 n : \u2115, 0 < n \u2192 \u2200 x : \u211a, 0 < x \u2192 f (n * x) = n * f x,\n  { intros n hn x hx,\n    have h2 : f (n * x) \u2264 n * f x,\n    { cases n,\n      { exfalso, exact nat.lt_asymm hn hn },\n      cases n,\n      { simp only [one_mul, nat.cast_one] },\n      have hfneq : f (n.succ.succ) = n.succ.succ,\n      { have := fixed_point_of_gt_1\n                  (nat.one_lt_cast.mpr (nat.succ_lt_succ n.succ_pos)) H1 H2 H4 H5 ha1 hae,\n        rwa (rat.cast_coe_nat n.succ.succ) at this },\n      rw \u2190 hfneq,\n      exact H1 (n.succ.succ : \u211a) x (nat.cast_pos.mpr hn) hx },\n    exact h2.antisymm (H3 x hx n hn) },\n\n  -- For the final calculation, we expand x as (2*x.num) / (2*x.denom), because\n  -- we need the top of the fraction to be strictly greater than 1 in order\n  -- to apply fixed_point_of_gt_1.\n  intros x hx,\n  let x2denom := 2 * x.denom,\n  let x2num := 2 * x.num,\n\n  have hx2pos := calc 0 < x.denom           : x.pos\n                    ... < x.denom + x.denom : lt_add_of_pos_left x.denom x.pos\n                    ... = 2 * x.denom       : by ring,\n\n  have hxcnez   : (x.denom : \u211a) \u2260 (0 : \u211a) := ne_of_gt (nat.cast_pos.mpr x.pos),\n  have hx2cnezr : (x2denom : \u211d) \u2260 (0 : \u211d) := nat.cast_ne_zero.mpr (ne_of_gt hx2pos),\n\n  have hrat_expand2 := calc x = x.num / x.denom : by exact_mod_cast rat.num_denom.symm\n                          ... = x2num / x2denom : by { field_simp [-rat.num_div_denom], linarith },\n\n  have h_denom_times_fx :=\n    calc (x2denom : \u211d) * f x = f (x2denom * x)                 : (h_f_commutes_with_pos_nat_mul\n                                                                    x2denom hx2pos x hx).symm\n                         ... = f (x2denom * (x2num / x2denom)) : by rw hrat_expand2\n                         ... = f x2num                         : by { congr, field_simp, ring },\n\n  have h_fx2num_fixed : f x2num = x2num,\n  { have hx2num_gt_one : (1 : \u211a) < (2 * x.num : \u2124),\n    { norm_cast, linarith [rat.num_pos_iff_pos.mpr hx] },\n    have hh := fixed_point_of_gt_1 hx2num_gt_one H1 H2 H4 H5 ha1 hae,\n    rwa (rat.cast_coe_int x2num) at hh },\n\n  calc f x = f x * 1                                 : (mul_one (f x)).symm\n       ... = f x * (x2denom / x2denom)               : by rw \u2190(div_self hx2cnezr)\n       ... = (f x * x2denom) / x2denom               : mul_div_assoc' (f x) _ _\n       ... = (x2denom * f x) / x2denom               : by rw mul_comm\n       ... = f x2num / x2denom                       : by rw h_denom_times_fx\n       ... = x2num / x2denom                         : by rw h_fx2num_fixed\n       ... = (((x2num : \u211a) / (x2denom : \u211a) : \u211a) : \u211d) : by norm_cast\n       ... = x                                       : by rw \u2190hrat_expand2\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/archive/imo/imo2013_q5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7122104930488072}}
{"text": "\ndef even : nat \u2192 Prop :=\n\u03bb n, \u2203 m, m * 2 = n\n\ndef odd : nat \u2192 Prop :=\n\u03bb n, \u2203 m, nat.succ (m * 2) = n\n\nlemma ", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/even_odd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.7121858068174682}}
{"text": "import data.real.basic\nimport .lin2k\n\n\n-- Let's work with rational number field\nabbreviation K := \u211a  \n\n-- Here are nice abbreviations for types\nabbreviation scalr := K\nabbreviation vectr := K \u00d7 K\n\n/-\n1A. [10 points]\n\nDeclare v1, v2, and v3 to be of type\nvectr with values (4,6), (-6,2), and\n(3, -7), respectively.\n-/\n\n-- HERE\n\n/-\n1B. [10 points]\n\nNow define v4, *using the vector \nspace operators, + and \u2022, to be \nthe following \"linear combination\"\nof vectors: twice v1 plus negative \nv2 plus v3. The negative of a vector\nis just -1 (in the field K) times\nthe vector. Write -1 as (-1:K), as \notherwise Lean will treat it as the \ninteger -1. (Note that subtraction\nof vectors, v2 - v1 is defined as\nv2 + (-1:K) \u2022 v1.)\n-/\n\n-- HERE \n\n/-\nCompute the correct answer by hand\nhere, showing your work, and check\nthat eval is producing the correct\nanswer. \n\n-- HERE\n\n-/\n\n/-\n1C. [10 points]\n\nOn a piece of paper, draw a picture\nof the preceding computation. Make a\nCartesian plane with x and y axes. \nDraw each vector, v1, v2, v3, as an\narrow from the origin to the point\ndesignated by the coordinates of the\nvector.\n\nScalar multiplication stretches or\nshrinks a vector by a given factor.\nShow each of the scaled vectors in \nyour picture: 2 \u2022 v1 and (-1:K) \u2022 v2. \n\nFinally vector addition in graphical\nterms works by putting the tail (non\narrow) end of one vector at the head\nof the other then drawing the vector\nfrom the tail of the first to the head\nof the second. Draw the vectors that\nillustrate the sum, 2 \u2022 v1 + (-1:K) \u2022 v2,\nand then the sum of that with v3. You\nshould come out with the same answer\nas before. Take a picture of your\ndrawing and upload it with your test.\n-/\n\n-- HERE\n\n/-\n2. [15 points]\n\nMany sets can be viewed as fields. For \nexample, the integers mod p, where p is\nany prime, has the structure of a field\nunder the usual operations of addition\nand multiplication mod p.\n\nIn case you forget about the integers \nmod n, it can be understood as the set\nof natural numbers from 0 to n-1, where\naddition and multiplication wrap around.\n\nFor example, the integers mod 5 is the\nset {0, 1, 2, 3, 4}. Now 2 + 2 = 4 but\n2 + 3 = 5 = 0. It's \"clock arithmetic,\" \nas they say. Similarly 2 * 2 = 4 but \n2 * 3 = 6 = 5 + 1 = 0 + 1 = 1. \n\nTo show informally that the integers \nmod 5 is a field you have to show that\nevery element of the set has an additive\ninverse and that every element of the \nset but 0 has a multiplicative inverse.\n\nDraw two tables below with the values\nof the integers mod 5 in each of the \nleft column. In the second column of\nthe first table, write in the additive\ninverses of each element. In the second\ntable, write the multiplicative inverses.\n-/\n\n-- HERE\n\n/-\n4. [15 points]\nIs the integers mod 4 a field? If so,\nprove it informally by writing tables\ngiving the inverses. If not, show that\nnot every value in the integers mod 4\n(except 0) has a multiplicative inverse,\nidentify a value that doesn't have an\ninverse, and briefly explain why.\n-/\n\n-- HERE\n\n/-\n5. [20 points]\nWrite a function, sum_vectrs, that \ntakes a list of our vectr objects as \nan argument and that reduces it to a \nsingle vector sum. To implement your\nfunction use a version of foldr as we\ndeveloped it: one that takes an additive\nmonoid implicit instance as an argument, \nensuring consistency of the operator we\nare using to reduce the list (add) and \nthe corresponding identity element. \nCopy and if needed modify the foldr\ndefinition here. It should use Lean's \nmonoid class, as we've done throughout\nthis exercise. You do not need to and\nshould not try to use our algebra.lean \nfile. Test your function by creating a\nlist of vectrs, [v1, v2, v3, v4], from\nabove, compute the expected sum, and\nshow that your function returns the \nexpected/correct result.\n-/\n\n-- HERE\n\n/-\n6. Required for graduate students,\noptional extra credit for undergrads.\n\nThe set of integers mod p can be viewed\nas a field with the usual addition and\nmultiplication operations mod p. These \nfinite fields (with only a finite number \nof elements) play a crucial role in many \nareas of number theory (in mathematics), \nand in cryptography in computer science.\n\n\nA. [20 points]\n\nInstantiate the field typeclass for\nfs (a prime). You \nmay and should stub out the proofs \nall along the way using \"sorry\", but\nbefore you do that, convince yourself\nthat you are *justified* in doing so.\n\nUse a \"fake\" representation of the\nintegers mod 5 for this exercise: as\nan enumerated type with five values. \nCall them zero, one, two, three, and\nfour. Then define two functions, \nz5add and z5mul, to add and multiply\nvalues of this type. You can figure\nout the addition and multiplication\ntables and just write the functions\nby cases to return the right result\nin each case. Start with Lean's field\ntypeclass, see what you need to \ninstantiate it, and work backwards, \nrecursively applying the same method \nuntil your reach clases that you can\nimplement directly. Put your code for\nthis problem below this comment.\n\nReplace the following \"assumptions\" \nwith your actual definitions (commenting\nout the axioms as you replace them). You\ncan right away right click on \"field\" and\n\"go to definition\" to see what you need\nto do. Solving this problem will require\nsome digging through Lean library code.\n-/\naxioms \n  (Z5 : Type) \n  (z5add : Z5 \u2192 Z5 \u2192 Z5)\n  (z5mul : Z5 \u2192 Z5 \u2192 Z5)\n  #check field Z5\n\n-- HERE\n\n/-\nB. [15 points]\n\nGiven that you've now presumably\nestablished that Z5 is a field,\nlet z5scalr be an abbreviation for\nZ5, and z5vectr for Z5 \u2a2f Z5. Then\nuse #eval to evaluate an expression\n(that you make up) involving vector \naddition and scalar multiplication\nusing our new z5vectr objects, i.e., \nvectors over Z5. These vectors will\nlook like, e.g., (one, three). Work \nout the right answer by hand and\ntest your code to gain confidence \nthat it's working correctly.\n-/\n\ninductive foo : Type\n| bar\n\nopen foo \n\ndef add_foo : foo \u2192 foo \u2192 foo\n| foo.bar foo.bar := foo.bar\n\ninstance has_add_foo : has_add foo := \u27e8 add_foo \u27e9 \n\n#reduce (bar, bar) + (bar, bar)\n\n-- HERE\n\n/-\nTake away: Instantiating a typeclass\nfor a given type can provide a whole\nset of operations and notations that\nyou can use to \"do algebra\" with that\ntype. The underlying types themselves\ncan be very diverse. That is, we can\nimpose the same abstract interface on\nsets of objects of different kinds, \njust as we previously imposed a group\nAPI on the elements of the symmetry \ngroup, D4, of a square. Here we've now\nseen that we can write vector space\nalgebra computations involving 2-D\nvectors over both the rational and\nthe integers mod 5. It's in this \nsense that instantiating a typeclass\nfor a type provides a new \"API\" for\nmanipulating values of that type.\n\nAnd while languages such as Haskell\ndo provide typeclasses, they don't\nprovide a language in which you can\ndeclaratively express and give proofs\nof the \"rules\" that structures have \nto follow to be valid instances. So,\nwelcome to Lean, a language in which\nyou can write mathematics and code,\nwith strong automated type checking\nof both code and proofs. If it has to\nbe right (which is the case for much\ncrypto code), maybe write it like so!\n-/\n\ninductive three : Type\n| O\n| I\n| II\n\n\ndef mult : three \u2192 three \u2192 three :=\nbegin\nassume t1 t2, \ncases t1,\ncases t2,\nexact three.O,\nexact three.O,\nexact three.O,\ncases t2,\nexact three.O,\nexact three.I,\nexact three.II,\ncases t2,\nexact three.O,\nexact three.O,\nexact three.I,\nend\n\nopen three \n\n#reduce mult II II\n\nlemma one_mult : \u2200 (t : three), mult I t = t := \n\u03bb (t : three), \n  match t with\n  | O   := eq.refl O\n  | I   := rfl\n  | II  := rfl\n  end ", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/exam1/lin2k_test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7121360496336424}}
{"text": "-- Diferencia_de_union_e_interseccion.lean\n-- Diferencia de uni\u00f3n e intersecci\u00f3n\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 28 de mayo de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext x,\n  split,\n  { rintros (\u27e8xs, xnt\u27e9 | \u27e8xt, xns\u27e9),\n    { split,\n      { left,\n        exact xs },\n      { rintros \u27e8_, xt\u27e9,\n        contradiction }},\n    { split ,\n      { right,\n        exact xt },\n      { rintros \u27e8xs, _\u27e9,\n        contradiction }}},\n  { rintros \u27e8xs | xt, nxst\u27e9,\n    { left,\n      use xs,\n      intro xt,\n      apply nxst,\n      split; assumption },\n    { right,\n      use xt,\n      intro xs,\n      apply nxst,\n      split; assumption }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext x,\n  split,\n  { rintros (\u27e8xs, xnt\u27e9 | \u27e8xt, xns\u27e9),\n    { finish, },\n    { finish, }},\n  { rintros \u27e8xs | xt, nxst\u27e9,\n    { finish, },\n    { finish, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext x,\n  split,\n  { rintros (\u27e8xs, xnt\u27e9 | \u27e8xt, xns\u27e9) ; finish, },\n  { rintros \u27e8xs | xt, nxst\u27e9 ; finish, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext,\n  split,\n  { finish, },\n  { finish, },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  rw ext_iff,\n  intro,\n  rw iff_def,\n  finish,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nby finish [ext_iff, iff_def]\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Diferencia_de_union_e_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7121360316070957}}
{"text": "-- BOTH:\nimport data.set.lattice\nimport data.set.function\nimport analysis.special_functions.log.basic\n\n/- TEXT:\n.. _functions:\n\nFunctions\n---------\n\nIf ``f : \u03b1 \u2192 \u03b2`` is a function and  ``p`` is a set of\nelements of type ``\u03b2``,\nthe library defines ``preimage f p``, written ``f \u207b\u00b9' p``,\nto be ``{x | f x \u2208 p}``.\nThe expression ``x \u2208 f \u207b\u00b9' p`` reduces to ``f x \u2208 p``.\nThis is often convenient, as in the following example:\nTEXT. -/\n-- BOTH:\nsection\n\n-- QUOTE:\nvariables {\u03b1 \u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables s t : set \u03b1\nvariables u v : set \u03b2\nopen function\nopen set\n\n-- EXAMPLES:\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nby { ext, refl }\n-- QUOTE.\n\n/- TEXT:\nIf ``s`` is a set of elements of type ``\u03b1``,\nthe library also defines ``image f s``,\nwritten ``f '' s``,\nto be ``{y | \u2203 x, x \u2208 s \u2227 f x = y}``.\nSo a hypothesis  ``y \u2208 f '' s`` decomposes to a triple\n``\u27e8x, xs, xeq\u27e9`` with ``x : \u03b1`` satisfying the hypotheses ``xs : x \u2208 s``\nand ``xeq : f x = y``.\nThe ``rfl`` tag in the ``rintros`` tactic (see :numref:`the_existential_quantifier`) was made precisely\nfor this sort of situation.\nTEXT. -/\n-- QUOTE:\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y, split,\n  { rintros \u27e8x, xs | xt, rfl\u27e9,\n    { left, use [x, xs] },\n    right, use [x, xt] },\n  rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9),\n  { use [x, or.inl xs] },\n  use [x, or.inr xt]\nend\n-- QUOTE.\n\n/- TEXT:\nNotice also that the ``use`` tactic applies ``refl``\nto close goals when it can.\n\nHere is another example:\nTEXT. -/\n-- QUOTE:\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nbegin\n  intros x xs,\n  show f x \u2208 f '' s,\n  use [x, xs]\nend\n-- QUOTE.\n\n/- TEXT:\nWe can replace the line ``use [x, xs]`` by\n``apply mem_image_of_mem f xs`` if we want to\nuse a theorem specifically designed for that purpose.\nBut knowing that the image is defined in terms\nof an existential quantifier is often convenient.\n\nThe following equivalence is a good exercise:\nTEXT. -/\n-- QUOTE:\nexample : f '' s \u2286 v \u2194 s \u2286 f \u207b\u00b9' v :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : f '' s \u2286 v \u2194 s \u2286 f \u207b\u00b9' v :=\nbegin\n  split,\n  { intros h x xs,\n    have : f x \u2208 f '' s,\n    from mem_image_of_mem _ xs,\n    exact h this },\n  intros h y ymem,\n  rcases ymem with \u27e8x, xs, fxeq\u27e9,\n  rw \u2190 fxeq,\n  apply h xs\nend\n\n/- TEXT:\nIt shows that ``image f`` and ``preimage f`` are\nan instance of what is known as a *Galois connection*\nbetween ``set \u03b1`` and ``set \u03b2``,\neach partially ordered by the subset relation.\nIn the library, this equivalence is named\n``image_subset_iff``.\nIn practice, the right-hand side is often the\nmore useful representation,\nbecause ``y \u2208 f \u207b\u00b9' t`` unfolds to ``f y \u2208 t``\nwhereas working with ``x \u2208 f '' s`` requires\ndecomposing an existential quantifier.\n\nHere is a long list of set-theoretic identities for\nyou to enjoy.\nYou don't have to do all of them at once;\ndo a few of them,\nand set the rest aside for a rainy day.\nTEXT. -/\n-- QUOTE:\nexample (h : injective f) : f \u207b\u00b9' (f '' s) \u2286 s :=\nsorry\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nsorry\n\nexample (h : surjective f) : u \u2286 f '' (f\u207b\u00b9' u) :=\nsorry\n\nexample (h : s \u2286 t) : f '' s \u2286 f '' t :=\nsorry\n\nexample (h : u \u2286 v) : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nsorry\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nsorry\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nsorry\n\nexample (h : injective f) : f '' s \u2229 f '' t \u2286 f '' (s \u2229 t) :=\nsorry\n\nexample : f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nsorry\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nsorry\n\nexample : f '' s \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nsorry\n\nexample : f '' (s \u2229 f \u207b\u00b9' u) \u2286 f '' s \u222a u :=\nsorry\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\nsorry\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : injective f) : f \u207b\u00b9' (f '' s) \u2286 s :=\nbegin\n  rintros x \u27e8y, ys, fxeq\u27e9,\n  rw \u2190 h fxeq,\n  exact ys\nend\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  rintros y \u27e8x, xmem, rfl\u27e9,\n  exact xmem\nend\n\nexample (h : surjective f) : u \u2286 f '' (f\u207b\u00b9' u) :=\nbegin\n  intros y yu,\n  rcases h y with \u27e8x, fxeq\u27e9,\n  use x,\n  split,\n  { show f x \u2208 u,\n    rw fxeq, exact yu },\n  exact fxeq\nend\n\nexample (h : s \u2286 t) : f '' s \u2286 f '' t :=\nbegin\n  rintros y \u27e8x, xs, fxeq\u27e9,\n  use [x, h xs, fxeq]\nend\n\nexample (h : u \u2286 v) : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nby intro x; apply h\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nby ext x; refl\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nbegin\n  rintros y \u27e8x, \u27e8xs, xt\u27e9, rfl\u27e9,\n  use [x, xs, rfl, x, xt, rfl]\nend\n\nexample (h : injective f) : f '' s \u2229 f '' t \u2286 f '' (s \u2229 t) :=\nbegin\n  rintros y \u27e8\u27e8x\u2081, x\u2081s, rfl\u27e9, \u27e8x\u2082, x\u2082t, fx\u2082eq\u27e9\u27e9,\n  use [x\u2081, x\u2081s],\n  rw \u2190 h fx\u2082eq,\n  exact x\u2082t\nend\n\nexample : f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nbegin\n  rintros y \u27e8\u27e8x\u2081, x\u2081s, rfl\u27e9, h\u27e9,\n  use [x\u2081, x\u2081s],\n  intro h',\n  apply h,\n  use [x\u2081, h', rfl]\nend\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\n\u03bb x, id\n\nexample : f '' s \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin\n  ext y, split,\n  { rintros \u27e8\u27e8x, xs, rfl\u27e9, fxv\u27e9,\n    use [x, xs, fxv] },\n  rintros \u27e8x, \u27e8\u27e8xs, fxv\u27e9, rfl\u27e9\u27e9,\n  use [x, xs, rfl, fxv],\nend\n\nexample : f '' (s \u2229 f \u207b\u00b9' u) \u2286 f '' s \u2229 u :=\nbegin\n  rintros y \u27e8x, \u27e8xs, fxu\u27e9, rfl\u27e9,\n  use [x, xs, rfl, fxu],\nend\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\nbegin\n  rintros x \u27e8xs, fxu\u27e9,\n  use [x, xs, rfl, fxu],\nend\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin\n  rintros x (xs | fxu),\n  { left, use [x, xs, rfl] },\n  right, use fxu\nend\n\n/- TEXT:\nYou can also try your hand at the next group of exercises,\nwhich characterize the behavior of images and preimages\nwith respect to indexed unions and intersections.\nIn the third exercise, the argument ``i : I`` is needed\nto guarantee that the index set is nonempty.\nTo prove any of these, we recommend using ``ext`` or ``intro``\nto unfold the meaning of an equation or inclusion between sets,\nand then calling ``simp`` to unpack the conditions for membership.\nBOTH: -/\n-- QUOTE:\nvariables {I : Type*} (A : I \u2192 set \u03b1) (B : I \u2192 set \u03b2)\n\n-- EXAMPLES:\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y, simp,\n  split,\n  { rintros \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9,\n    use [i, x, xAi, fxeq] },\n  rintros \u27e8i, x, xAi, fxeq\u27e9,\n  exact \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9\nend\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nbegin\n  intro y, simp,\n  intros x h fxeq i,\n  use [x, h i, fxeq],\nend\n\nexample (i : I) (injf : injective f) :\n  (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i) :=\nbegin\n  intro y, simp,\n  intro h,\n  rcases h i with \u27e8x, xAi, fxeq\u27e9,\n  use x, split,\n  { intro i',\n    rcases h i' with \u27e8x', x'Ai, fx'eq\u27e9,\n    have : f x = f x', by rw [fxeq, fx'eq],\n    have : x = x', from injf this,\n    rw this,\n    exact x'Ai },\n  exact fxeq\nend\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\nby { ext x, simp }\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nby { ext x, simp }\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y, simp,\n  split,\n  { rintros \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9,\n    use [i, x, xAi, fxeq] },\n  rintros \u27e8i, x, xAi, fxeq\u27e9,\n  exact \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9\nend\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nbegin\n  intro y, simp,\n  intros x h fxeq i,\n  use [x, h i, fxeq],\nend\n\nexample (i : I) (injf : injective f) : (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i) :=\nbegin\n  intro y, simp,\n  intro h,\n  rcases h i with \u27e8x, xAi, fxeq\u27e9,\n  use x, split,\n  { intro i',\n    rcases h i' with \u27e8x', x'Ai, fx'eq\u27e9,\n    have : f x = f x', by rw [fxeq, fx'eq],\n    have : x = x', from injf this,\n    rw this,\n    exact x'Ai },\n  exact fxeq\nend\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\nby { ext x, simp }\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nby { ext x, simp }\n\n-- OMIT:\n/-\nIn type theory, a function ``f : \u03b1 \u2192 \u03b2`` can be applied to any\nelement of the domain ``\u03b1``,\nbut we sometimes want to represent functions that are\nmeaningfully defined on only some of those elements.\nFor example, as a function of type ``\u211d \u2192 \u211d \u2192 \u211d``,\ndivision is only meaningful when the second argument is nonzero.\nIn mathematics, when we write an expression of the form ``s / t``,\nwe should have implicitly or explicitly ruled out\nthe case that ``t`` is zero.\n\nBut since division has type ``\u211d \u2192 \u211d \u2192 \u211d`` in Lean,\nit also has to return a value when the second argument is zero.\nThe strategy generally followed by the library is to assign such\nfunctions convenient values outside their natural domain.\nFor example, defining ``x / 0`` to be ``0`` means that the\nidentity ``(x + y) / z = x / z + y / z`` holds for every\n``x``, ``y``, and ``z``.\n\nAs a result, when we read an expression ``s / t`` in Lean,\nwe should not assume that ``t`` is a meaningful input value.\nWhen we need to, we can restrict the statement of a theorem to\nguarantee that it is.\nFor example, theorem ``div_mul_cancel`` asserts ``x \u2260 0 \u2192 x / y * y = x`` for\n``x`` and ``y`` in suitable algebraic structures.\n\n.. TODO: previous text (delete eventually)\n\n.. The fact that in type theory a function is always totally\n.. defined on its domain type\n.. sometimes forces some difficult choices.\n.. For example, if we want to define ``x / y`` and ``log x``\n.. as functions on the reals,\n.. we have to assign a value to the first when ``y`` is ``0``,\n.. and a value to the second for ``x \u2264 0``.\n.. The strategy generally followed by the Lean library\n.. in these situations is to assign such functions somewhat arbitrary\n.. but convenient values outside their natural domain.\n.. For example, defining ``x / 0`` to be ``0`` means that the\n.. identity ``(x + y) / z = x / z + y / z`` holds\n.. for every ``x``, ``y``, and ``z``.\n.. When you see a theorem in the library that uses the\n.. division symbol,\n.. you should be mindful that theorem depends on this\n.. nonstandard definition,\n.. but this generally does not cause problems in practice.\n.. When we need to,\n.. we can restrict the statement of a theorem so that\n.. it does not rely on such values.\n.. For example, if a theorem begins ``\u2200 x > 0, ...``,\n.. dividing by ``x`` in the body of the statement is not problematic.\n.. Limiting the scope of a quantifier in this way is known\n.. as *relativization*.\n\n.. TODO: comments from Patrick\n.. This discussion is very important and we should really get it right. The natural tendency of mathematicians here is to think Lean does bullshit and will let them prove false things. So we should focus on why there is no issue, not on apologies or difficulties.\n\n.. I think we could include a discussion of the fact that the meaning of f : \u03b1 \u2192 \u03b2 is actually more subtle that it seems. Saying f is a function from \u03b1 to \u03b2 is actually a slight oversimplification. The more nuanced meaning is that f is a function whose possible meaningful input values all have type \u03b1 and whose output values have type \u03b2, but we should not assume that every term with type \u03b1 is a meaningful input value.\n\n.. Then we of course need to point out that defining terms of type \u03b1 \u2192 \u03b2 required to assign a value to every term of type \u03b1, and this can be irritating but this is balanced by the convenience of having a couple of unconditional lemma like the (x+y)/z thing.\n\n.. Also, I feel it is very important to point out that real world math doesn't force you to (x+y)/\u27e8z, proof that z doesn't vanish\u27e9. So type theory is not different here.\n\n.. TODO: deleted because we haven't discussed subtypes yet.\n.. Be sure to do that eventually.\n.. There are ways around this, but they are generally unpleasant.\n.. For example, we can take ``log`` to be defined on\n.. the subtype ``{ x // x > 0 }``,\n.. but then we have to mediate between two different types,\n.. the reals and that subtype.\n\nThe library defines a predicate ``inj_on f s`` to say that\n``f`` is injective on ``s``.\nIt is defined as follows:\n-/\n\n-- QUOTE:\nexample : inj_on f s \u2194\n  \u2200 x\u2081 \u2208 s, \u2200 x\u2082 \u2208 s, f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082 :=\niff.refl _\n-- QUOTE.\n\n-- BOTH:\nend\n\n/- TEXT:\nThe statement ``injective f`` is provably equivalent\nto ``inj_on f univ``.\nSimilarly, the library defines ``range f`` to be\n``{x | \u2203y, f y = x}``,\nso ``range f`` is provably equal to ``f '' univ``.\nThis is a common theme in mathlib:\nalthough many properties of functions are defined relative\nto their full domain,\nthere are often relativized versions that restrict\nthe statements to a subset of the domain type.\n\nHere is are some examples of ``inj_on`` and ``range`` in use:\nBOTH: -/\nsection\n-- QUOTE:\nopen set real\n\n-- EXAMPLES:\nexample : inj_on log { x | x > 0 } :=\nbegin\n  intros x xpos y ypos,\n  intro e,   -- log x = log y\n  calc\n    x   = exp (log x) : by rw exp_log xpos\n    ... = exp (log y) : by rw e\n    ... = y           : by rw exp_log ypos\nend\n\nexample : range exp = { y | y > 0 } :=\nbegin\n  ext y, split,\n  { rintros \u27e8x, rfl\u27e9,\n    apply exp_pos },\n  intro ypos,\n  use log y,\n  rw exp_log ypos\nend\n-- QUOTE.\n\n/- TEXT:\nTry proving these:\nEXAMPLES: -/\n-- QUOTE:\nexample : inj_on sqrt { x | x \u2265 0 } :=\nsorry\n\nexample : inj_on (\u03bb x, x^2) { x : \u211d | x \u2265 0 } :=\nsorry\n\nexample : sqrt '' { x | x \u2265 0 } = {y | y \u2265 0} :=\nsorry\n\nexample : range (\u03bb x, x^2) = {y : \u211d  | y \u2265 0} :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : inj_on sqrt { x | x \u2265 0 } :=\nbegin\n  intros x xnonneg y ynonneg,\n  intro e,\n  calc\n    x   = (sqrt x)^2 : by rw sq_sqrt xnonneg\n    ... = (sqrt y)^2 : by rw e\n    ... = y          : by rw sq_sqrt ynonneg\nend\n\nexample : inj_on (\u03bb x, x^2) { x : \u211d | x \u2265 0 } :=\nbegin\n    intros x xnonneg y ynonneg,\n    intro e,\n    dsimp at *,\n    calc\n      x   = sqrt (x^2) : by rw sqrt_sq xnonneg\n      ... = sqrt (y^2) : by rw e\n      ... = y          : by rw sqrt_sq ynonneg,\nend\n\nexample : sqrt '' { x | x \u2265 0 } = {y | y \u2265 0} :=\nbegin\n    ext y, split,\n    { rintros \u27e8x, \u27e8xnonneg, rfl\u27e9\u27e9,\n      apply sqrt_nonneg },\n    intro ynonneg,\n    use y^2,\n    dsimp at *,\n    split,\n    apply pow_nonneg ynonneg,\n    apply sqrt_sq,\n    assumption,\nend\n\nexample : range (\u03bb x, x^2) = {y : \u211d | y \u2265 0} :=\nbegin\n    ext y,\n    split,\n    { rintros \u27e8x, rfl\u27e9,\n       dsimp at *,\n       apply pow_two_nonneg },\n    intro ynonneg,\n    use sqrt y,\n    exact sq_sqrt ynonneg,\nend\n\n-- BOTH:\nend\n\n/- TEXT:\nTo define the inverse of a function ``f : \u03b1 \u2192 \u03b2``,\nwe will use two new ingredients.\nFirst, we need to deal with the fact that\nan arbitrary type in Lean may be empty.\nTo define the inverse to ``f`` at ``y`` when there is\nno ``x`` satisfying ``f x = y``,\nwe want to assign a default value in ``\u03b1``.\nAdding the annotation ``[inhabited \u03b1]`` as a variable\nis tantamount to assuming that ``\u03b1`` has a\npreferred element, which is denoted ``default``.\nSecond, in the case where there is more than one ``x``\nsuch that ``f x = y``,\nthe inverse function needs to *choose* one of them.\nThis requires an appeal to the *axiom of choice*.\nLean allows various ways of accessing it;\none convenient method is to use the classical ``some``\noperator, illustrated below.\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {\u03b1 \u03b2 : Type*} [inhabited \u03b1]\n\n-- EXAMPLES:\n#check (default : \u03b1)\n\nvariables (P : \u03b1 \u2192 Prop) (h : \u2203 x, P x)\n\n#check classical.some h\n\nexample : P (classical.some h) := classical.some_spec h\n-- QUOTE.\n\n/- TEXT:\nGiven ``h : \u2203 x, P x``, the value of ``classical.some h``\nis some ``x`` satisfying ``P x``.\nThe theorem ``classical.some_spec h`` says that ``classical.some h``\nmeets this specification.\n\nWith these in hand, we can define the inverse function\nas follows:\nBOTH: -/\n-- QUOTE:\nnoncomputable theory\nopen_locale classical\n\ndef inverse (f : \u03b1 \u2192 \u03b2) : \u03b2 \u2192 \u03b1 :=\n\u03bb y : \u03b2, if h : \u2203 x, f x = y then classical.some h else default\n\ntheorem inverse_spec {f : \u03b1 \u2192 \u03b2} (y : \u03b2) (h : \u2203 x, f x = y) :\n  f (inverse f y) = y :=\nbegin\n  rw inverse, dsimp, rw dif_pos h,\n  exact classical.some_spec h\nend\n-- QUOTE.\n\n/- TEXT:\nThe lines ``noncomputable theory`` and ``open_locale classical``\nare needed because we are using classical logic in an essential way.\nOn input ``y``, the function ``inverse f``\nreturns some value of ``x`` satisfying ``f x = y`` if there is one,\nand a default element of ``\u03b1`` otherwise.\nThis is an instance of a *dependent if* construction,\nsince in the positive case, the value returned,\n``classical.some h``, depends on the assumption ``h``.\nThe identity ``dif_pos h`` rewrites ``if h : e then a else b``\nto ``a`` given ``h : e``,\nand, similarly, ``dif_neg h`` rewrites it to ``b`` given ``h : \u00ac e``.\nThe theorem ``inverse_spec`` says that ``inverse f``\nmeets the first part of this specification.\n\nDon't worry if you do not fully understand how these work.\nThe theorem ``inverse_spec`` alone should be enough to show\nthat ``inverse f`` is a left inverse if and only if ``f`` is injective\nand a right inverse if and only if ``f`` is surjective.\nLook up the definition of ``left_inverse`` and ``right_inverse``\nby double-clicking or right-clicking on them in VS Code,\nor using the commands ``#print left_inverse`` and ``#print right_inverse``.\nThen try to prove the two theorems.\nThey are tricky!\nIt helps to do the proofs on paper before\nyou start hacking through the details.\nYou should be able to prove each of them with about a half-dozen\nshort lines.\nIf you are looking for an extra challenge,\ntry to condense each proof to a single-line proof term.\nBOTH: -/\n-- QUOTE:\nvariable  f : \u03b1 \u2192 \u03b2\nopen function\n\n-- EXAMPLES:\nexample : injective f \u2194 left_inverse (inverse f) f  :=\nsorry\n\nexample : surjective f \u2194 right_inverse (inverse f) f :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : injective f \u2194 left_inverse (inverse f) f  :=\nbegin\n  split,\n  { intros h y,\n    apply h,\n    apply inverse_spec,\n    use y },\n  intros h x1 x2 e,\n  rw [\u2190h x1, \u2190h x2, e]\nend\n\nexample : injective f \u2194 left_inverse (inverse f) f  :=\n\u27e8\u03bb h y, h (inverse_spec _ \u27e8y, rfl\u27e9), \u03bb h x1 x2 e, by rw [\u2190h x1, \u2190h x2, e]\u27e9\n\nexample : surjective f \u2194 right_inverse (inverse f) f :=\nbegin\n  split,\n  { intros h y,\n    apply inverse_spec,\n    apply h },\n  intros h y,\n  use (inverse f y),\n  apply h\nend\n\nexample : surjective f \u2194 right_inverse (inverse f) f :=\n\u27e8\u03bb h y, inverse_spec _ (h _), \u03bb h y, \u27e8inverse f y, h _\u27e9\u27e9\n\n-- BOTH:\nend\n\n-- OMIT:\n/-\n.. TODO: These comments after this paragraph are from Patrick.\n.. We should decide whether we want to do this here.\n.. Another possibility is to wait until later.\n.. There may be good examples for the topology chapter,\n.. at which point, the reader will be more of an expert.\n\n.. This may be a good place to also introduce a discussion of the choose tactic, and explain why you choose (!) not to use it here.\n\n.. Typically, you can include:\n\n.. example {\u03b1 \u03b2 : Type*} {f : \u03b1 \u2192 \u03b2} : surjective f \u2194 \u2203 g : \u03b2 \u2192 \u03b1, \u2200 b, f (g b) = b :=\n.. begin\n..   split,\n..   { intro h,\n..     dsimp [surjective] at h, -- this line is optional\n..     choose g hg using h,\n..     use g,\n..     exact hg },\n..   { rintro \u27e8g, hg\u27e9,\n..     intros b,\n..     use g b,\n..     exact hg b },\n.. end\n.. Then contrast this to a situation where we really want a def outputting an element or a function, maybe with a less artificial example than your inverse.\n\n.. We should also tie this to the \"function are global\" discussion, and the whole thread of deferring proofs to lemmas instead of definitions. There is a lot going on here, and all of it is crucial for formalization.\n-/\n\n/- TEXT:\nWe close this section with a type-theoretic statement of Cantor's\nfamous theorem that there is no surjective function from a set\nto its power set.\nSee if you can understand the proof,\nand then fill in the two lines that are missing.\nTEXT. -/\n-- BOTH:\nsection\nvariable {\u03b1 : Type*}\nopen function\n\n-- EXAMPLES:\n-- QUOTE:\ntheorem Cantor : \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f :=\nbegin\n  intros f surjf,\n  let S := { i | i \u2209 f i},\n  rcases surjf S with \u27e8j, h\u27e9,\n  have h\u2081 : j \u2209 f j,\n  { intro h',\n    have : j \u2209 f j,\n      { by rwa h at h' },\n    contradiction },\n  have h\u2082 : j \u2208 S,\n    sorry,\n  have h\u2083 : j \u2209 S,\n    sorry,\n  contradiction\nend\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem Cantor\u03b1\u03b1 : \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f :=\nbegin\n  intros f surjf,\n  let S := { i | i \u2209 f i},\n  rcases surjf S with \u27e8j, h\u27e9,\n  have h\u2081 : j \u2209 f j,\n  { intro h',\n    have : j \u2209 f j,\n      by rwa h at h',\n    contradiction },\n  have h\u2082 : j \u2208 S,\n    from h\u2081,\n  have h\u2083 : j \u2209 S,\n    by rwa h at h\u2081,\n  contradiction\nend\n\n-- BOTH:\nend\n", "meta": {"author": "avigad", "repo": "mathematics_in_lean_source", "sha": "4eeb8c43762522c1acaa7f799599609d6a48f59e", "save_path": "github-repos/lean/avigad-mathematics_in_lean_source", "path": "github-repos/lean/avigad-mathematics_in_lean_source/mathematics_in_lean_source-4eeb8c43762522c1acaa7f799599609d6a48f59e/lean_source/04_Sets_and_Functions/source_02_Functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7121360314760379}}
{"text": "import data.real.basic\nimport game.order.level01\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 2\n\nThis level invites you to work out a property of the absolute value.\nIn Lean the absolute value of $x$ is denoted by `abs x`. \n-/\n\n/- Hint : The definition of the absolute value in mathlib:\ndefinition abs {\u03b1 : Type u} [decidable_linear_ordered_add_comm_group \u03b1] (a : \u03b1) : \u03b1 := max a (-a)\n-/\n\n/-\nFor ease of use, a notation can be wrapped around that definition as below.\n-/\n\nnotation `|` x `|` := abs x\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$|ab| = |a||b|$$.\n-/\ntheorem abs_prod (a b : \u211d) : |a * b| = |a| * |b| :=\nbegin\n    rcases lt_trichotomy a 0 with haNeg | haZero | haPos,\n    swap,\n    { -- case a = 0\n        have h1 : a * b = 0, norm_num, left, exact haZero,\n        have h2 : | a * b | = 0, exact (is_absolute_value.abv_eq_zero abs).mpr h1,\n        have h3 : | a | = 0, exact (is_absolute_value.abv_eq_zero abs).mpr haZero,\n        rw [h2,h3], norm_num,\n    },\n    { -- case a < 0\n        rcases lt_trichotomy b 0 with hbNeg | hbZero | hbPos,\n        swap,\n        { -- case b = 0\n            have h1 : a * b = 0, norm_num, right, exact hbZero,\n            have h2 : | a * b | = 0, exact (is_absolute_value.abv_eq_zero abs).mpr h1,\n            have h3 : | b | = 0, exact (is_absolute_value.abv_eq_zero abs).mpr hbZero,\n            rw [h2,h3], norm_num,\n        },\n        { -- case b < 0\n            have h1 : 0 < a * b,  exact mul_pos_of_neg_of_neg haNeg hbNeg,\n            have h2 : | a * b | = a * b, exact abs_of_pos h1,\n            have h3 : | a | = - a, exact abs_of_neg haNeg,\n            have h4 : | b | = - b, exact abs_of_neg hbNeg,\n            rw [h2, h3, h4], norm_num,\n        },\n        { -- case 0 < b\n            have h1 : a * b < 0,  exact mul_neg_of_neg_of_pos haNeg hbPos,\n            have h2 : | a * b | = - (a * b), exact abs_of_neg h1,\n            have h3 : | a | = - a, exact abs_of_neg haNeg,\n            have h4 : | b | = b, exact abs_of_pos hbPos,\n            rw [h2, h3, h4], norm_num,\n        }\n\n    },\n    { -- case 0 < a\n        rcases lt_trichotomy b 0 with hbNeg | hbZero | hbPos,\n        swap,\n        { -- case b = 0\n            have h1 : a * b = 0, norm_num, right, exact hbZero,\n            have h2 : | a * b | = 0, exact (is_absolute_value.abv_eq_zero abs).mpr h1,\n            have h3 : | b | = 0, exact (is_absolute_value.abv_eq_zero abs).mpr hbZero,\n            rw [h2,h3], norm_num,\n        },\n        { -- case b < 0\n            have h1 : a * b < 0,  exact mul_neg_of_pos_of_neg haPos hbNeg,\n            have h2 : | a * b | = -( a * b), exact abs_of_neg h1,\n            have h3 : | a | = a, exact abs_of_pos haPos,\n            have h4 : | b | = - b, exact abs_of_neg hbNeg,\n            rw [h2, h3, h4], norm_num,\n        },\n        { -- case 0 < b\n            have h1 : 0 < a * b,  exact mul_pos haPos hbPos,\n            have h2 : | a * b | = a * b, exact abs_of_pos h1,\n            have h3 : | a | = a, exact abs_of_pos haPos,\n            have h4 : | b | = b, exact abs_of_pos hbPos,\n            rw [h2, h3, h4],  -- this is enough, rw closes the refl goal \n        }\n\n    },\n    done\n\nend\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7120918784096756}}
{"text": "import data.set.basic\nimport data.set.lattice\nimport data.nat.parity\nimport tactic.linarith\nimport tactic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1. Habilitar las teor\u00edas set, nat y function.\n-- ----------------------------------------------------------------------\n\nopen set nat function\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Activar la l\u00f3gica cl\u00e1sica.\n-- ----------------------------------------------------------------------\n\nopen_locale classical\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Declarar los tipos \u03b1, \u03b2, \u03b3 e I.\n-- ----------------------------------------------------------------------\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*} {I : Type*}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Empezar la secci\u00f3n set_variables.\n-- ----------------------------------------------------------------------\n\n\nsection set_variables\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Declarar\n-- 1. x como una variable sobre objetos de tipo \u03b1\n-- 2. s, t y u como variables sobre conjuntos de elementos de tipo \u03b1.\n-- ----------------------------------------------------------------------\n\nvariable  x : \u03b1\nvariables s t u : set \u03b1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Calcular el tipo de las siguientes expresiones (el\n-- s\u00edmbolo se puede escribir como se indica a su lado).\n--    s \u2286 t           -- \\sub\n--    x \u2208 s           -- \\in o \\mem\n--    x \u2209 s           -- \\notin\n--    s \u2229 t           -- \\i o \\cap\n--    s \u222a t           -- \\un o \\cup\n--    (\u2205 : set \u03b1)     -- \\empty\n--    (univ: set \u03b1)\n-- ----------------------------------------------------------------------\n\n#check s \u2286 t\n#check x \u2208 s\n#check x \u2209 s\n#check s \u2229 t\n#check s \u222a t\n#check (\u2205 : set \u03b1)\n#check (univ: set \u03b1)\n\n-- Comentario; Al colocar el cursor sobre check se obtiene\n-- + s \u2286 t : Prop\n-- + x \u2208 s : Prop\n-- + x \u2209 s : Prop\n-- + s \u2229 t : set \u03b1\n-- + s \u222a t : set \u03b1\n-- + \u2205 : set \u03b1\n-- univ : set \u03b1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Demostrar que si\n--    s \u2286 t\n-- entonces\n--    s \u2229 u \u2286 t \u2229 u\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  rw subset_def,\n  rw inter_def,\n  rw inter_def,\n  dsimp,\n  intros x h,\n  cases h with xs xu,\n  split,\n  { rw subset_def at h,\n    apply h,\n    assumption },\n  { assumption },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u\n  >> rw subset_def,\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2229 u \u2192 x \u2208 t \u2229 u\n  >> rw inter_def,\n\u22a2 \u2200 (x : \u03b1), x \u2208 {a : \u03b1 | a \u2208 s \u2227 a \u2208 u} \u2192 x \u2208 t \u2229 u\n  >> rw inter_def,\n\u22a2 \u2200 (x : \u03b1), x \u2208 {a : \u03b1 | a \u2208 s \u2227 a \u2208 u} \u2192 x \u2208 {a : \u03b1 | a \u2208 t \u2227 a \u2208 u}\n  >> dsimp,\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> intros x h,\nx : \u03b1,\nh : x \u2208 s \u2227 x \u2208 u\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> cases hx with xs xu,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> split,\n| 2 goals\n| \u03b1 : Type u_1,\n| s t u : set \u03b1,\n| h : s \u2286 t,\n| x : \u03b1,\n| xs : x \u2208 s,\n| xu : x \u2208 u\n| \u22a2 x \u2208 t\n|   >>  { rw subset_def at h,\n| h : \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2208 t\n| \u22a2 x \u2208 t\n|   >>    apply h,\n| \u22a2 x \u2208 s\n|   >>    assumption },\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t,\nx : \u03b1,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 u\n  >>  { assumption },\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  rw [subset_def, inter_def, inter_def],\n  dsimp,\n  rintros x \u27e8xs, xu\u27e9,\n  rw subset_def at h,\n  exact \u27e8h _ xs, xu\u27e9,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u\n  >> rw [subset_def, inter_def, inter_def],\n\u22a2 \u2200 (x : \u03b1), x \u2208 {a : \u03b1 | a \u2208 s \u2227 a \u2208 u} \u2192 x \u2208 {a : \u03b1 | a \u2208 t \u2227 a \u2208 u}\n  >> dsimp,\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> rintros x \u27e8xs, xu\u27e9,\nx : \u03b1,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> rw subset_def at h,\nh : \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2208 t\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> exact \u27e8h _ xs, xu\u27e9,\nno goals\n-/\n\n-- Comentarios:\n-- 1. La t\u00e1ctica (rintros x \u27e8h1, h2\u27e9) cuando la conclusi\u00f3n es\n--    de la forma (\u2200 x : \u03b1, P \u2227 Q \u2192 S) a\u00f1ade las hip\u00f3tesis (x : \u03b1),\n--    (h1 : P), (h2 : Q) y cambia la conclusi\u00f3n a S.\n-- 2. La t\u00e1ctica (exact \u27e8h1, h2\u27e9) si la conclusi\u00f3n es de la\n--    forma (P \u2227 Q), h1 es una prueba de P y h2 es una prueba de, entonces\n--    es una prueba de la conclusi\u00f3n.\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  simp only [subset_def, mem_inter_eq] at *,\n  rintros x \u27e8xs, xu\u27e9,\n  exact \u27e8h _ xs, xu\u27e9,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u\n  >> simp only [subset_def, mem_inter_eq] at *,\nh : \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2208 t\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> rintros x \u27e8xs, xu\u27e9,\nx : \u03b1,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> exact \u27e8h _ xs, xu\u27e9,\nno goals\n-/\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  intros x xsu,\n  exact \u27e8h xsu.1, xsu.2\u27e9,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u\n  >> intros x xsu,\nx : \u03b1,\nxsu : x \u2208 s \u2229 u\n\u22a2 x \u2208 t \u2229 u\n  >> exact \u27e8h xsu.1, xsu.2\u27e9,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 8. Demostrar que\n--    s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n  intros x hx,\n  have xs : x \u2208 s := hx.1,\n  have xtu : x \u2208 t \u222a u := hx.2,\n  clear hx,\n  cases xtu with xt xu,\n  { left,\n    show x \u2208 s \u2229 t,\n    exact \u27e8xs, xt\u27e9 },\n  { right,\n    show x \u2208 s \u2229 u,\n    exact \u27e8xs, xu\u27e9 },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n  rintros x \u27e8xs, xt | xu\u27e9,\n  { left,\n    exact \u27e8xs, xt\u27e9 },\n  { right,\n    exact \u27e8xs, xu\u27e9 },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 9. Demostrar que\n--    (s \\ t) \\ u \u2286 s \\ (t \u222a u)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x xstu,\n  have xs : x \u2208 s := xstu.1.1,\n  have xnt : x \u2209 t := xstu.1.2,\n  have xnu : x \u2209 u := xstu.2,\n  split,\n  { exact xs },\n  { dsimp,\n    intro xtu,\n    cases xtu with xt xu,\n    { show false, from xnt xt },\n    { show false, from xnu xu }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8xs, xnt\u27e9, xnu\u27e9,\n  use xs,\n  rintros (xt | xu); contradiction\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x xstu,\n  simp at *,\n  finish,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x xstu,\n  finish,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nby rw diff_diff\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 10. Demostrar que\n--    (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n  intros x hx,\n  have xs : x \u2208 s := hx.1,\n  have xtu : x \u2208 t \u222a u := hx.2,\n  clear hx,\n  cases xtu with xt xu,\n  { left,\n    show x \u2208 s \u2229 t,\n    exact \u27e8xs, xt\u27e9 },\n  { right,\n    show x \u2208 s \u2229 u,\n    exact \u27e8xs, xu\u27e9 },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n  rintros x \u27e8xs, xt | xu\u27e9,\n  { left,\n    exact \u27e8xs, xt\u27e9 },\n  { right,\n    exact \u27e8xs, xu\u27e9 },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n  intros x hx,\n  by finish\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nby rw inter_union_distrib_left\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 11. Demostrar que\n--    s \\ (t \u222a u) \u2286 (s \\ t) \\ u\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  intros x hx,\n  split,\n  { split,\n    { exact hx.1, },\n    { dsimp,\n      intro xt,\n      apply hx.2,\n      left,\n      exact xt, }},\n  { dsimp,\n    intro xu,\n    apply hx.2,\n    right,\n    exact xu, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  rintros x \u27e8xs, xntu\u27e9,\n  split,\n  { split,\n    { exact xs, },\n    { intro xt,\n      exact xntu (or.inl xt), }},\n  { intro xu,\n    exact xntu (or.inr xu), },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  rintros x \u27e8xs, xntu\u27e9,\n  use xs,\n  { intro xt,\n    exact xntu (or.inl xt) },\n  { intro xu,\n    exact xntu (or.inr xu) },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  rintros x \u27e8xs, xntu\u27e9;\n  finish,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nby intro ; finish\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nby rw diff_diff\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 12. Demostrar que\n--    s \u2229 t = t \u2229 s\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\nbegin\n  ext x,\n  simp only [mem_inter_eq],\n  split,\n  { intro h,\n    split,\n    { exact h.2, },\n    { exact h.1, }},\n  { intro h,\n    split,\n    { exact h.2, },\n    { exact h.1, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\nbegin\n  ext,\n  simp only [mem_inter_eq],\n  exact \u27e8\u03bb h, \u27e8h.2, h.1\u27e9,\n         \u03bb h, \u27e8h.2, h.1\u27e9\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\nbegin\n  ext,\n  exact \u27e8\u03bb h, \u27e8h.2, h.1\u27e9,\n         \u03bb h, \u27e8h.2, h.1\u27e9\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\nbegin\n  ext x,\n  simp only [mem_inter_eq],\n  split,\n  { rintros \u27e8xs, xt\u27e9,\n    exact \u27e8xt, xs\u27e9 },\n  { rintros \u27e8xt, xs\u27e9,\n    exact \u27e8xs, xt\u27e9 },\nend\n\n-- Comentarios:\n-- 1. La t\u00e1ctica ext si la conclusi\u00f3n es un igualdad de conjunto (A = B)\n--    la sustituye por (x \u2208 A \u2194 x \u2208 B).\n-- 2. Se ha usado el lema\n--    + mem_inter_eq x s t : x \u2208 s \u2229 t = (x \u2208 s \u2227 x \u2208 t)\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\nbegin\n  ext x,\n  exact and.comm,\nend\n\n-- Comentario: Se ha usado el lema\n-- + and.comm : a \u2227 b \u2194 b \u2227 a\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\next (\u03bb x, and.comm)\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\nby ext x; simp [and.comm]\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\ninter_comm s t\n\n-- Comentario: Se ha usado el lema\n-- + inter_comm: a \u2229 b = b \u2229 a\n\n-- 9\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 t = t \u2229 s :=\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 13. Demostrar que\n--    s \u2229 (s \u222a t) = s\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    dsimp at h,\n    exact h.1, },\n  { intro xs,\n    dsimp,\n    split,\n    { exact xs, },\n    { left,\n      exact xs, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    exact h.1, },\n  { intro xs,\n    split,\n    { exact xs, },\n    { left,\n      exact xs, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    exact h.1, },\n  { intro xs,\n    split,\n    { exact xs, },\n    { exact (or.inl xs), }},\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext,\n  exact \u27e8\u03bb h, h.1,\n         \u03bb xs, \u27e8xs, or.inl xs\u27e9\u27e9,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext,\n  exact \u27e8and.left,\n         \u03bb xs, \u27e8xs, or.inl xs\u27e9\u27e9,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\nbegin\n  ext x,\n  split,\n  { rintros \u27e8xs, _\u27e9,\n    exact xs },\n  { intro xs,\n    use xs,\n    left,\n    exact xs },\nend\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (s \u222a t) = s :=\ninf_sup_self\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 14. Demostrar que\n--    s \u222a (s \u2229 t) = s\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    cases hx with xs xst,\n    { exact xs, },\n    { exact xst.1, }},\n  { intro xs,\n    left,\n    exact xs, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nbegin\n  ext x,\n  exact \u27e8\u03bb hx, or.dcases_on hx id and.left,\n         \u03bb xs, or.inl xs\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nbegin\n  ext x,\n  split,\n  { rintros (xs | \u27e8xs, xt\u27e9);\n    exact xs },\n  { intro xs,\n    left,\n    exact xs },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nsup_inf_self\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 15. Demostrar que\n--    (s \\ t) \u222a t = s \u222a t\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa definici\u00f3n\n-- =============\n\nexample : (s \\ t) \u222a t = s \u222a t :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    cases hx with xst xt,\n    { left,\n      exact xst.1, },\n    { right,\n      exact xt }},\n  { by_cases h : x \u2208 t,\n    { intro _,\n      right,\n      exact h },\n    { intro hx,\n      cases hx with xs xt,\n      { left,\n        split,\n        { exact xs, },\n        { dsimp,\n          exact h, }},\n      { right,\n        exact xt, }}},\nend\n\n-- 2\u00aa definici\u00f3n\n-- =============\n\nexample : (s \\ t) \u222a t = s \u222a t :=\nbegin\n  ext x,\n  split,\n  { rintros (\u27e8xs, nxt\u27e9 | xt),\n    { left,\n      exact xs},\n    { right,\n      exact xt }},\n  { by_cases h : x \u2208 t,\n    { intro _,\n      right,\n      exact h },\n    { rintros (xs | xt),\n      { left,\n        use [xs, h] },\n      { right,\n        use xt }}},\nend\n\n-- 3\u00aa definici\u00f3n\n-- =============\n\nexample : (s \\ t) \u222a t = s \u222a t :=\nbegin\n  ext,\n  simp,\n  tauto,\nend\n\n-- 4\u00aa definici\u00f3n\n-- =============\n\nexample : (s \\ t) \u222a t = s \u222a t :=\nbegin\n  rw ext_iff,\n  intro,\n  rw iff_def,\n  finish,\nend\n\n-- 5\u00aa definici\u00f3n\n-- =============\n\nexample : (s \\ t) \u222a t = s \u222a t :=\nby finish [ext_iff, iff_def]\n\n-- 6\u00aa definici\u00f3n\n-- =============\n\nexample : (s \\ t) \u222a t = s \u222a t :=\ndiff_union_self\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 16. Demostrar que\n--    (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext x,\n  split,\n  { rintros (\u27e8xs, xnt\u27e9 | \u27e8xt, xns\u27e9),\n    { split,\n      { left,\n        exact xs },\n      { rintros \u27e8_, xt\u27e9,\n        contradiction }},\n    { split ,\n      { right,\n        exact xt },\n      { rintros \u27e8xs, _\u27e9,\n        contradiction }}},\n  { rintros \u27e8xs | xt, nxst\u27e9,\n    { left,\n      use xs,\n      intro xt,\n      apply nxst,\n      split; assumption },\n    { right,\n      use xt,\n      intro xs,\n      apply nxst,\n      split; assumption }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext x,\n  split,\n  { rintros (\u27e8xs, xnt\u27e9 | \u27e8xt, xns\u27e9),\n    { finish, },\n    { finish, }},\n  { rintros \u27e8xs | xt, nxst\u27e9,\n    { finish, },\n    { finish, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext x,\n  split,\n  { rintros (\u27e8xs, xnt\u27e9 | \u27e8xt, xns\u27e9) ; finish, },\n  { rintros \u27e8xs | xt, nxst\u27e9 ; finish, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  ext,\n  split,\n  { finish, },\n  { finish, },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nbegin\n  rw ext_iff,\n  intro,\n  rw iff_def,\n  finish,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \u222a (t \\ s) = (s \u222a t) \\ (s \u2229 t) :=\nby finish [ext_iff, iff_def]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 17. Definir\n-- + naturales como el conjunto de los n\u00fameros naturales,\n-- + pares como el conjunto de los n\u00fameros naturales pares y\n-- + impares como el conjunto de los n\u00fameros naturales impares.\n-- ----------------------------------------------------------------------\n\ndef naturales : set \u2115 := {n | true}\ndef pares     : set \u2115 := {n | even n}\ndef impares   : set \u2115 := {n | \u00ac even n}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 18. Demostrar que la uni\u00f3n de pares e impares es el\n-- conjunto de los n\u00fameros naturales.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : pares \u222a impares = naturales :=\nbegin\n  unfold pares impares naturales,\n  ext n,\n  simp,\n  apply classical.em,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : pares \u222a impares = naturales :=\nbegin\n  unfold pares impares naturales,\n  ext n,\n  finish,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : pares \u222a impares = naturales :=\nby finish [pares, impares, naturales, ext_iff]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 19. Demostrar que\n-- + s \u2229 t = {x | x \u2208 s \u2227 x \u2208 t}\n-- + s \u222a t = {x | x \u2208 s \u2228 x \u2208 t}\n-- + (\u2205 : set \u03b1) = {x | false}\n-- + (univ : set \u03b1) = {x | true}\n-- ----------------------------------------------------------------------\n\nexample : s \u2229 t = {x | x \u2208 s \u2227 x \u2208 t} := rfl\nexample : s \u222a t = {x | x \u2208 s \u2228 x \u2208 t} := rfl\nexample : (\u2205 : set \u03b1) = {x | false} := rfl\nexample : (univ : set \u03b1) = {x | true} := rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 20. Demostrar que el vac\u00edo no tiene elementos.\n-- ----------------------------------------------------------------------\n\nexample\n  (x : \u2115)\n  (h : x \u2208 (\u2205 : set \u2115))\n  : false :=\nh\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 21. Demostrar que todos los elementos pertenecen al\n-- universal.\n-- ----------------------------------------------------------------------\n\nexample\n  (x : \u2115)\n  : x \u2208 (univ : set \u2115) :=\ntrivial\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 22. Los n\u00fameros primos y los mayores que 2 se definen por\n--    def primos      : set \u2115 := {n | prime n}\n--    def mayoresQue2 : set \u2115 := {n | n > 2}\n--\n-- Demostrar que\n--    primos \u2229 mayoresQue2 \u2286 impares\n-- ----------------------------------------------------------------------\n\ndef primos      : set \u2115 := {n | prime n}\ndef mayoresQue2 : set \u2115 := {n | n > 2}\n\nexample : primos \u2229 mayoresQue2 \u2286 impares :=\nbegin\n  unfold primos mayoresQue2 impares,\n  intro n,\n  simp,\n  intro hn,\n  cases prime.eq_two_or_odd hn with h h,\n  { rw h,\n    intro,\n    linarith, },\n  { rw even_iff,\n    rw h,\n    norm_num },\nend\n\n-- Comentario: Se han usado los siguientes lemas\n-- + prime.eq_two_or_odd : prime p \u2192 p = 2 \u2228 p % 2 = 1\n-- + even_iff : n.even \u2194 n % 2 = 0\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 23. Crear una secci\u00f3n.\n-- ----------------------------------------------------------------------\n\nsection\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 24. Declarar A y B como familias de conjuntos de elementos\n-- de tipo \u03b1 indexadas por \u2115.\n-- ----------------------------------------------------------------------\n\nvariables A B : \u2115 \u2192 set \u03b1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 25. Demostrar que\n--    s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    rw mem_Union,\n    cases h with xs xUAi,\n    rw mem_Union at xUAi,\n    cases xUAi with i xAi,\n    use i,\n    split,\n    { exact xAi, },\n    { exact xs, }},\n  { intro h,\n    rw mem_Union at h,\n    cases h with i hi,\n    cases hi with xAi xs,\n    split,\n    { exact xs, },\n    { rw mem_Union,\n      use i,\n      exact xAi, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Union],\n  split,\n  { rintros \u27e8xs, \u27e8i, xAi\u27e9\u27e9,\n    exact \u27e8i, xAi, xs\u27e9, },\n  { rintros \u27e8i, xAi, xs\u27e9,\n    exact \u27e8xs, \u27e8i, xAi\u27e9\u27e9 },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  finish [mem_inter_eq, mem_Union],\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nby finish [mem_inter_eq, mem_Union, ext_iff]\n\n-- Comentario: Se han usado los lemas\n-- + mem_inter_eq x s t : x \u2208 s \u2229 t = (x \u2208 s \u2227 x \u2208 t)\n-- + mem_Union : x \u2208 Union A \u2194 \u2203 (i : \u2115), x \u2208 A i\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 26. Demostrar que\n--    (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Inter],\n  split,\n  { intro h,\n    split,\n    { intro i,\n      exact (h i).1 },\n    { intro i,\n      exact (h i).2 }},\n  { intros h i,\n    cases h with h1 h2,\n    split,\n    { exact h1 i },\n    { exact h2 i }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Inter],\n  exact \u27e8\u03bb h, \u27e8\u03bb i, (h i).1, \u03bb i, (h i).2\u27e9,\n         \u03bb \u27e8h1, h2\u27e9 i, \u27e8h1 i, h2 i\u27e9\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext,\n  simp only [mem_inter_eq, mem_Inter],\n  finish,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext,\n  finish [mem_inter_eq, mem_Inter],\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nby finish [mem_inter_eq, mem_Inter, ext_iff]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 27. Cerrar la secci\u00f3n\n-- ----------------------------------------------------------------------\n\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 28. Abrir una secci\u00f3n\n-- ----------------------------------------------------------------------\n\nsection\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 29. Declarar A y B como familias de conjuntos de elementos\n-- de tipo \u03b1 indexadas por \u2115.\n-- ----------------------------------------------------------------------\n\nvariables A B : \u2115 \u2192 set \u03b1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 30. Demostrar que\n--    s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s) :=\nbegin\n  ext x,\n  simp only [mem_union, mem_Inter],\n  split,\n  { intros h i,\n    cases h with xs xAi,\n    { right,\n      exact xs },\n    { left,\n      exact xAi i, }},\n  { intro h,\n    by_cases xs : x \u2208 s,\n    { left,\n      exact xs },\n    { right,\n      intro i,\n      cases h i with xAi xs,\n      { exact xAi, },\n      { contradiction, }}},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s) :=\nbegin\n  ext x,\n  simp only [mem_union, mem_Inter],\n  split,\n  { rintros (xs | xI) i,\n    { right,\n      exact xs },\n    { left,\n      exact xI i }},\n  { intro h,\n    by_cases xs : x \u2208 s,\n    { left,\n      exact xs },\n    { right,\n      intro i,\n      cases h i,\n      { assumption },\n      { contradiction }}},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s) :=\nbegin\n  ext x,\n  simp only [mem_union, mem_Inter],\n  split,\n  { finish, },\n  { finish, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s) :=\nbegin\n  ext,\n  simp only [mem_union, mem_Inter],\n  split ; finish,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s) :=\nbegin\n  ext,\n  simp only [mem_union, mem_Inter],\n  finish [iff_def],\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (\u22c2 i, A i) = \u22c2 i, (A i \u222a s) :=\nby finish [ext_iff, mem_union, mem_Inter, iff_def]\n\n-- Comentario. Se han usado los lemas\n-- + mem_union x s t : x \u2208 s \u222a t \u2194 x \u2208 s \u2228 x \u2208 t\n-- + mem_Inter : x \u2208 Inter A \u2194 \u2200 (i : \u2115), x \u2208 A i\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 31. Cerrar la secci\u00f3n.\n-- ----------------------------------------------------------------------\n\nend\n\n-- Comentario: Mathlib tambi\u00e9n tiene, como se explica en *Mathematics in\n-- Lean*,\n-- + uniones acotadas: \u22c3 x \u2208 s, f x\n-- + intersecciones acotadas: \u22c2 x \u2208 s, f x\n-- + uniones de conjuntos: \u22c3\u2080 s\n-- + intersecciones de conjuntos: \u22c2\u2080 s\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 32. Cerrar la secci\u00f3n set_variables.\n-- ---------------------------------------------------------------------\n\nend set_variables\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 33. Iniciar la secci\u00f3n function_variables.\n-- ----------------------------------------------------------------------\n\nsection function_variables\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 34. Declarar las siguientes variables:\n-- + f como variable de funciones de \u03b1 en \u03b2\n-- + s y t como variables sobre conjuntos de elementos de tipo \u03b1.\n-- + u y v como variables sobre conjuntos de elementos de tipo \u03b2.\n-- + A como variable de familias de conjuntos de \u03b1 con \u00edndice en I.\n-- + B como variable de familias de conjuntos de \u03b2 con \u00edndice en I.\n-- ----------------------------------------------------------------------\n\nvariable  f : \u03b1 \u2192 \u03b2\nvariables s t : set \u03b1\nvariables u v : set \u03b2\nvariable  A : I \u2192 set \u03b1\nvariable  B : I \u2192 set \u03b2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 35. Calcular los tipos de\n-- 1. La imagen de s por f.\n-- 2. La imagen inversa de u por f,\n-- ----------------------------------------------------------------------\n\n#check f '' s\n#check image f s\n#check f \u207b\u00b9' u       -- se escribe con \\inv\n#check preimage f u\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 36. Demostrar que\n--    f '' s = {y | \u2203 x, x \u2208 s \u2227 f x = y}\n-- ----------------------------------------------------------------------\n\nexample : f '' s = {y | \u2203 x, x \u2208 s \u2227 f x = y} := rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 37. Demostrar que\n--    f \u207b\u00b9' u = {x | f x \u2208 u}\n-- ----------------------------------------------------------------------\n\nexample : f \u207b\u00b9' u = {x | f x \u2208 u} := rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 38. Demostrar que\n--    f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { intro h,\n    split,\n    { apply mem_preimage.mpr,\n      rw mem_preimage at h,\n      exact mem_of_mem_inter_left h, },\n    { apply mem_preimage.mpr,\n      rw mem_preimage at h,\n      exact mem_of_mem_inter_right h, }},\n  { intro h,\n    apply mem_preimage.mpr,\n    split,\n    { apply mem_preimage.mp,\n      exact mem_of_mem_inter_left h,},\n    { apply mem_preimage.mp,\n      exact mem_of_mem_inter_right h, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nbegin\n  ext x,\n  exact \u27e8\u03bb h, \u27e8mem_preimage.mpr (mem_of_mem_inter_left h),\n               mem_preimage.mpr (mem_of_mem_inter_right h)\u27e9,\n         \u03bb h, \u27e8mem_preimage.mp (mem_of_mem_inter_left h),\n               mem_preimage.mp (mem_of_mem_inter_right h)\u27e9\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nbegin\n  ext,\n  refl,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nby {ext, refl}\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\nrfl\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u2229 v) = f \u207b\u00b9' u \u2229 f \u207b\u00b9' v :=\npreimage_inter\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 39. Demostrar que\n--    f '' (s \u222a t) = f '' s \u222a f '' t\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { intro h1,\n    cases h1 with x hx,\n    cases hx with xst fxy,\n    rw \u2190 fxy,\n    cases xst with xs xt,\n    { left,\n      apply mem_image_of_mem,\n      exact xs, },\n    { right,\n      apply mem_image_of_mem,\n      exact xt, }},\n  { intro h2,\n    cases h2 with yfs yft,\n    { cases yfs with x hx,\n      cases hx with xs fxy,\n      rw \u2190 fxy,\n      apply mem_image_of_mem,\n      left,\n      exact xs, },\n    { cases yft with x hx,\n      cases hx with xt fxy,\n      rw \u2190 fxy,\n      apply mem_image_of_mem,\n      right,\n      exact xt, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8x, xst, fxy\u27e9,\n    rw \u2190 fxy,\n    cases xst with xs xt,\n    { left,\n      exact mem_image_of_mem f xs, },\n    { right,\n      exact mem_image_of_mem f xt, }},\n  { rintros (yfs | yft),\n    { rcases yfs with \u27e8x, xs, fxy\u27e9,\n      rw \u2190 fxy,\n      apply mem_image_of_mem,\n      left,\n      exact xs, },\n    { rcases yft with \u27e8x, xt, fxy\u27e9,\n      rw \u2190 fxy,\n      apply mem_image_of_mem,\n      right,\n      exact xt, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8x, xst, rfl\u27e9,\n    cases xst with xs xt,\n    { left,\n      exact mem_image_of_mem f xs, },\n    { right,\n      exact mem_image_of_mem f xt, }},\n  { rintros (yfs | yft),\n    { rcases yfs with \u27e8x, xs, rfl\u27e9,\n      apply mem_image_of_mem,\n      left,\n      exact xs, },\n    { rcases yft with \u27e8x, xt, rfl\u27e9,\n      apply mem_image_of_mem,\n      right,\n      exact xt, }},\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8x, xst, rfl\u27e9,\n    cases xst with xs xt,\n    { left,\n      use [x, xs], },\n    { right,\n      use [x, xt], }},\n  { rintros (yfs | yft),\n    { rcases yfs with \u27e8x, xs, rfl\u27e9,\n      use [x, or.inl xs], },\n    { rcases yft with \u27e8x, xt, rfl\u27e9,\n      use [x, or.inr xt], }},\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8x, xs | xt, rfl\u27e9,\n    { left,\n      use [x, xs] },\n    { right,\n      use [x, xt] }},\n  { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9),\n    { use [x, or.inl xs] },\n    { use [x, or.inr xt] }},\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8x, xs | xt, rfl\u27e9,\n    { finish, },\n    { finish, }},\n  { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9),\n    { finish, },\n    { finish, }},\nend\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8x, xs | xt, rfl\u27e9 ; finish, },\n  { rintros (\u27e8x, xs, rfl\u27e9 | \u27e8x, xt, rfl\u27e9) ; finish, },\nend\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  split,\n  { finish, },\n  { finish, },\nend\n\n-- 9\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nbegin\n  ext y,\n  rw iff_def,\n  finish,\nend\n\n-- 10\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nby finish [ext_iff, iff_def, mem_image_eq]\n\n-- 11\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a t) = f '' s \u222a f '' t :=\nimage_union f s t\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 40. Demostrar que\n--    s \u2286 f \u207b\u00b9' (f '' s)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nbegin\n  intros x xs,\n  apply mem_preimage.mpr,\n  apply mem_image_of_mem,\n  exact xs,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nbegin\n  intros x xs,\n  apply mem_image_of_mem,\n  exact xs,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\n\u03bb x, mem_image_of_mem f\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nbegin\n  intros x xs,\n  show f x \u2208 f '' s,\n  use [x, xs],\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nbegin\n  intros x xs,\n  use [x, xs],\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nsubset_preimage_image f s\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 41. Demostrar que\n--    f '' s \u2286 u \u2194 s \u2286 f \u207b\u00b9' u\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \u2286 u \u2194 s \u2286 f \u207b\u00b9' u :=\nbegin\n  split,\n  { intros h x xs,\n    apply mem_preimage.mpr,\n    apply h,\n    apply mem_image_of_mem,\n    exact xs, },\n  { intros h y hy,\n    rcases hy with \u27e8x, xs, fxy\u27e9,\n    rw \u2190 fxy,\n    exact h xs, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \u2286 u \u2194 s \u2286 f \u207b\u00b9' u :=\nbegin\n  split,\n  { intros h x xs,\n    apply h,\n    apply mem_image_of_mem,\n    exact xs, },\n  { rintros h y \u27e8x, xs, rfl\u27e9,\n    exact h xs, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \u2286 u \u2194 s \u2286 f \u207b\u00b9' u :=\nimage_subset_iff\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \u2286 u \u2194 s \u2286 f \u207b\u00b9' u :=\nby simp\n\n-- Comentario: Se ha usado el lema\n-- + mem_image_of_mem f : x \u2208 s \u2192 f x \u2208 f '' s\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 42. Demostrar que si f es inyectiva, entonces\n--    f \u207b\u00b9' (f '' s) \u2286 s\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : injective f)\n  : f \u207b\u00b9' (f '' s) \u2286 s :=\nbegin\n  intros x hx,\n  rw mem_preimage at hx,\n  rw mem_image_eq at hx,\n  cases hx with y hy,\n  cases hy with ys fyx,\n  unfold injective at h,\n  have h1 : y = x := h fyx,\n  rw \u2190 h1,\n  exact ys,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : injective f)\n  : f \u207b\u00b9' (f '' s) \u2286 s :=\nbegin\n  intros x hx,\n  rw mem_preimage at hx,\n  rcases hx with \u27e8y, ys, fyx\u27e9,\n  rw \u2190 h fyx,\n  exact ys,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : injective f)\n  : f \u207b\u00b9' (f '' s) \u2286 s :=\nbegin\n  rintros x \u27e8y, ys, hy\u27e9,\n  rw \u2190 h hy,\n  exact ys,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 43. Demostrar que\n--    f '' (f\u207b\u00b9' u) \u2286 u\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  intros y h,\n  cases h with x h2,\n  cases h2 with hx fxy,\n  rw \u2190 fxy,\n  exact hx,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  intros y h,\n  rcases h with \u27e8x, hx, fxy\u27e9,\n  rw \u2190 fxy,\n  exact hx,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  rintros y \u27e8x, hx, fxy\u27e9,\n  rw \u2190 fxy,\n  exact hx,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nbegin\n  rintros y \u27e8x, hx, rfl\u27e9,\n  exact hx,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nimage_preimage_subset f u\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (f\u207b\u00b9' u) \u2286 u :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 44. Demostrar que si f es suprayectiva, entonces\n--    u \u2286 f '' (f\u207b\u00b9' u)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : surjective f)\n  : u \u2286 f '' (f\u207b\u00b9' u) :=\nbegin\n  intros y yu,\n  cases h y with x fxy,\n  use x,\n  split,\n  { apply mem_preimage.mpr,\n    rw fxy,\n    exact yu },\n  { exact fxy },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : surjective f)\n  : u \u2286 f '' (f\u207b\u00b9' u) :=\nbegin\n  intros y yu,\n  cases h y with x fxy,\n  use x,\n  split,\n  { show f x \u2208 u,\n    rw fxy,\n    exact yu },\n  { exact fxy },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : surjective f)\n  : u \u2286 f '' (f\u207b\u00b9' u) :=\nbegin\n  intros y yu,\n  cases h y with x fxy,\n  by finish,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 45. Demostrar que si s \u2286 t, entonces\n--    f '' s \u2286 f '' t\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : f '' s \u2286 f '' t :=\nbegin\n  intros y hy,\n  rw mem_image at hy,\n  cases hy with x hx,\n  cases hx with xs fxy,\n  use x,\n  split,\n  { exact h xs, },\n  { exact fxy, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : f '' s \u2286 f '' t :=\nbegin\n  intros y hy,\n  rcases hy with \u27e8x, xs, fxy\u27e9,\n  use x,\n  exact \u27e8h xs, fxy\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : f '' s \u2286 f '' t :=\nbegin\n  rintros y \u27e8x, xs, fxy \u27e9,\n  use [x, h xs, fxy],\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : f '' s \u2286 f '' t :=\nby finish [subset_def, mem_image_eq]\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : f '' s \u2286 f '' t :=\nimage_subset f h\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 46. Demostrar que si u \u2286 v, entonces\n--    f \u207b\u00b9' u \u2286 f \u207b\u00b9' v\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : u \u2286 v)\n  : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nbegin\n  intros x hx,\n  apply mem_preimage.mpr,\n  apply h,\n  apply mem_preimage.mp,\n  exact hx,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : u \u2286 v)\n  : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nbegin\n  intros x hx,\n  apply h,\n  exact hx,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : u \u2286 v)\n  : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nbegin\n  intros x hx,\n  exact h hx,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : u \u2286 v)\n  : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\n\u03bb x hx, h hx\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : u \u2286 v)\n  : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nby intro x; apply h\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : u \u2286 v)\n  : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\npreimage_mono h\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : u \u2286 v)\n  : f \u207b\u00b9' u \u2286 f \u207b\u00b9' v :=\nby tauto\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 47. Demostrar que\n--    f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    rw mem_preimage at h,\n    cases h with fxu fxv,\n    { left,\n      apply mem_preimage.mpr,\n      exact fxu, },\n    { right,\n      apply mem_preimage.mpr,\n      exact fxv, }},\n  { intro h,\n    rw mem_preimage,\n    cases h with xfu xfv,\n    { rw mem_preimage at xfu,\n      left,\n      exact xfu, },\n    { rw mem_preimage at xfv,\n      right,\n      exact xfv, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    cases h with fxu fxv,\n    { left,\n      exact fxu, },\n    { right,\n      exact fxv, }},\n  { intro h,\n    cases h with xfu xfv,\n    { left,\n      exact xfu, },\n    { right,\n      exact xfv, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { rintro (fxu | fxv),\n    { exact or.inl fxu, },\n    { exact or.inr fxv, }},\n  { rintro (xfu | xfv),\n    { exact or.inl xfu, },\n    { exact or.inr xfv, }},\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { finish, },\n  { finish, } ,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  finish,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nby ext; finish\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nby ext; refl\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nrfl\n\n-- 9\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\npreimage_union\n\n-- 10\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 48. Demostrar que\n--    f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nbegin\n  intros y hy,\n  cases hy with x hx,\n  cases hx with xst fxy,\n  split,\n  { use x,\n    split,\n    { exact xst.1, },\n    { exact fxy, }},\n  { use x,\n    split,\n    { exact xst.2, },\n    { exact fxy, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nbegin\n  intros y hy,\n  rcases hy with \u27e8x, \u27e8xs, xt\u27e9, fxy\u27e9,\n  split,\n  { use x,\n    exact \u27e8xs, fxy\u27e9, },\n  { use x,\n    exact \u27e8xt, fxy\u27e9, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nbegin\n  rintros y \u27e8x, \u27e8xs, xt\u27e9, fxy\u27e9,\n  split,\n  { use [x, xs, fxy], },\n  { use [x, xt, fxy], },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nimage_inter_subset f s t\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nby intro ; finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 49. Demostrar que si f es inyectiva, entonces\n--    f '' s \u2229 f '' t \u2286 f '' (s \u2229 t)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : injective f)\n  : f '' s \u2229 f '' t \u2286 f '' (s \u2229 t) :=\nbegin\n  intros y hy,\n  cases hy  with hy1 hy2,\n  cases hy1 with x1 hx1,\n  cases hx1 with x1s fx1y,\n  cases hy2 with x2 hx2,\n  cases hx2 with x2t fx2y,\n  use x1,\n  split,\n  { split,\n    { exact x1s, },\n    { convert x2t,\n      apply h,\n      rw \u2190 fx2y at fx1y,\n      exact fx1y, }},\n  { exact fx1y, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : injective f)\n  : f '' s \u2229 f '' t \u2286 f '' (s \u2229 t) :=\nbegin\n  rintros y \u27e8\u27e8x1, x1s, fx1y\u27e9, \u27e8x2, x2t, fx2y\u27e9\u27e9,\n  use x1,\n  split,\n  { split,\n    { exact x1s, },\n    { convert x2t,\n      apply h,\n      rw \u2190 fx2y at fx1y,\n      exact fx1y, }},\n  { exact fx1y, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : injective f)\n  : f '' s \u2229 f '' t \u2286 f '' (s \u2229 t) :=\nbegin\n  rintros y \u27e8\u27e8x1, x1s, fx1y\u27e9, \u27e8x2, x2t, fx2y\u27e9\u27e9,\n  unfold injective at h,\n  finish,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : injective f)\n  : f '' s \u2229 f '' t \u2286 f '' (s \u2229 t) :=\nby intro ; unfold injective at *  ; finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 50. Demostrar que\n--    f '' s \\ f '' t \u2286 f '' (s \\ t)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nbegin\n  intros y hy,\n  cases hy with yfs ynft,\n  cases yfs with x hx,\n  cases hx with xs fxy,\n  use x,\n  split,\n  { split,\n    { exact xs, },\n    { dsimp,\n      intro xt,\n      apply ynft,\n      rw \u2190 fxy,\n      apply mem_image_of_mem,\n      exact xt, }},\n  { exact fxy, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nbegin\n  rintros y \u27e8\u27e8x, xs, fxy\u27e9, ynft\u27e9,\n  use x,\n  split,\n  { split,\n    { exact xs, },\n    { intro xt,\n      apply ynft,\n      use [x, xt, fxy], }},\n  { exact fxy, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nbegin\n  rintros y \u27e8\u27e8x, xs, fxy\u27e9, ynft\u27e9,\n  use x,\n  finish,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nsubset_image_diff f s t\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 51. Demostrar que\n--    f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nbegin\n  intros x hx,\n  rw mem_preimage,\n  split,\n  { rw \u2190 mem_preimage,\n    exact hx.1, },\n  { dsimp,\n    rw \u2190 mem_preimage,\n    exact hx.2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nbegin\n  intros x hx,\n  split,\n  { exact hx.1, },\n  { exact hx.2, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nbegin\n  intros x hx,\n  exact \u27e8hx.1, hx.2\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nbegin\n  rintros x \u27e8h1, h2\u27e9,\n  exact \u27e8h1, h2\u27e9,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nsubset.rfl\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' u \\ f \u207b\u00b9' v \u2286 f \u207b\u00b9' (u \\ v) :=\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 52. Demostrar que\n--    (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin\n  ext y,\n  split,\n  { intro hy,\n    cases hy with hyfs yv,\n    cases hyfs with x hx,\n    cases hx with xs fxy,\n    use x,\n    split,\n    { split,\n      { exact xs, },\n      { rw mem_preimage,\n        rw fxy,\n        exact yv, }},\n    { exact fxy, }},\n  { intro hy,\n    cases hy with x hx,\n    split,\n    { use x,\n      split,\n      { exact hx.1.1, },\n      { exact hx.2, }},\n    { cases hx with hx1 fxy,\n      rw \u2190 fxy,\n      rw \u2190 mem_preimage,\n      exact hx1.2, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8\u27e8x, xs, fxy\u27e9, yv\u27e9,\n    use x,\n    split,\n    { split,\n      { exact xs, },\n      { rw mem_preimage,\n        rw fxy,\n        exact yv, }},\n    { exact fxy, }},\n  { rintros \u27e8x, \u27e8xs, xv\u27e9, fxy\u27e9,\n    split,\n    { use [x, xs, fxy], },\n    { rw \u2190 fxy,\n      rw \u2190 mem_preimage,\n      exact xv, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nbegin\n  ext y,\n  split,\n  { rintros \u27e8\u27e8x, xs, fxy\u27e9, yv\u27e9,\n    finish, },\n  { rintros \u27e8x, \u27e8xs, xv\u27e9, fxy\u27e9,\n    finish, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nby ext ; split ; finish\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\nby finish [ext_iff, iff_def]\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (f '' s) \u2229 v = f '' (s \u2229 f \u207b\u00b9' v) :=\n(set.push_pull f s v).symm\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 53. Demostrar que\n--    f '' (s \u222a f \u207b\u00b9' v) \u2286 f '' s \u222a v\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a f \u207b\u00b9' v) \u2286 f '' s \u222a v :=\nbegin\n  intros y hy,\n  cases hy with x hx,\n  cases hx with hx1 fxy,\n  cases hx1 with xs xv,\n  { left,\n    use x,\n    split,\n    { exact xs, },\n    { exact fxy, }},\n  { right,\n    rw \u2190 fxy,\n    exact xv, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a f \u207b\u00b9' v) \u2286 f '' s \u222a v :=\nbegin\n  rintros y \u27e8x, xs | xv, fxy\u27e9,\n  { left,\n    use [x, xs, fxy], },\n  { right,\n    rw \u2190 fxy,\n    exact xv, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (s \u222a f \u207b\u00b9' v) \u2286 f '' s \u222a v :=\nbegin\n  rintros y \u27e8x, xs | xv, fxy\u27e9;\n  finish,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 54. Demostrar que\n--    s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\nbegin\n  intros x hx,\n  rw mem_preimage,\n  split,\n  { apply mem_image_of_mem,\n    exact hx.1, },\n  { rw \u2190 mem_preimage,\n    exact hx.2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\nbegin\n  rintros x \u27e8xs, xu\u27e9,\n  split,\n  { exact mem_image_of_mem f xs, },\n  { exact xu, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\nbegin\n  rintros x \u27e8xs, xu\u27e9,\n  exact \u27e8mem_image_of_mem f xs, xu\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\nbegin\n  rintros x \u27e8xs, xu\u27e9,\n  show f x \u2208 f '' s \u2229 u,\n  split,\n  { use [x, xs, rfl] },\n  { exact xu },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u2229 u) :=\ninter_preimage_subset s u f\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 55. Demostrar que\n--    s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin\n  intros x hx,\n  rw mem_preimage,\n  cases hx with xs xu,\n  { apply mem_union_left,\n    apply mem_image_of_mem,\n    exact xs, },\n  { apply mem_union_right,\n    rw \u2190 mem_preimage,\n    exact xu, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin\n  intros x hx,\n  cases hx with xs xu,\n  { apply mem_union_left,\n    apply mem_image_of_mem,\n    exact xs, },\n  { apply mem_union_right,\n    exact xu, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin\n  rintros x (xs | xu),\n  { left,\n    exact mem_image_of_mem f xs, },\n  { right,\n    exact xu, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin\n  rintros x (xs | xu),\n  { exact or.inl (mem_image_of_mem f xs), },\n  { exact or.inr xu, },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin\n  intros x h,\n  exact or.elim h (\u03bb xs, or.inl (mem_image_of_mem f xs)) or.inr,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\n\u03bb x h, or.elim h (\u03bb xs, or.inl (mem_image_of_mem f xs)) or.inr\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nbegin\n  rintros x (xs | xu),\n  { show f x \u2208 f '' s \u222a u,\n    use [x, xs, rfl] },\n  { show f x \u2208 f '' s \u222a u,\n    right,\n    apply xu },\nend\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a f \u207b\u00b9' u \u2286 f \u207b\u00b9' (f '' s \u222a u) :=\nunion_preimage_subset s u f\n\n-- Comentario: Se ha usado el lema\n-- + mem_union_right : x \u2208 t \u2192 x \u2208 s \u222a t\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 56. Demostrar que\n--    f '' (\u22c3 i, A i) = \u22c3 i, f '' A i\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y,\n  split,\n  { intro hy,\n    rw mem_image at hy,\n    cases hy with x hx,\n    cases hx with xUA fxy,\n    rw mem_Union at xUA,\n    cases xUA with i xAi,\n    rw mem_Union,\n    use i,\n    rw \u2190 fxy,\n    apply mem_image_of_mem,\n    exact xAi, },\n  { intro hy,\n    rw mem_Union at hy,\n    cases hy with i yAi,\n    cases yAi with x hx,\n    cases hx with xAi fxy,\n    rw \u2190 fxy,\n    apply mem_image_of_mem,\n    rw mem_Union,\n    use i,\n    exact xAi, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y,\n  simp,\n  split,\n  { rintros \u27e8x, \u27e8i, xAi\u27e9, fxy\u27e9,\n    use [i, x, xAi, fxy] },\n  { rintros \u27e8i, x, xAi, fxy\u27e9,\n    exact \u27e8x, \u27e8i, xAi\u27e9, fxy\u27e9 },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nby tidy\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nimage_Union\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 57. Demostrar que\n--    f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nbegin\n  intros y h,\n  apply mem_Inter_of_mem,\n  intro i,\n  cases h with x hx,\n  cases hx with xIA fxy,\n  rw \u2190 fxy,\n  apply mem_image_of_mem,\n  exact mem_Inter.mp xIA i,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nbegin\n  intros y h,\n  apply mem_Inter_of_mem,\n  intro i,\n  rcases h with \u27e8x, xIA, rfl\u27e9,\n  exact mem_image_of_mem f (mem_Inter.mp xIA i),\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nbegin\n  intro y,\n  simp,\n  intros x xIA fxy i,\n  use [x, xIA i, fxy],\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nby tidy\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 58. Demostrar que si f es inyectiva, entonces\n--    (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (i : I)\n  (injf : injective f)\n  : (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i) :=\nbegin\n  intros y hy,\n  rw mem_Inter at hy,\n  rcases hy i with \u27e8x, xAi, fxy\u27e9,\n  use x,\n  split,\n  { apply mem_Inter_of_mem,\n    intro j,\n    rcases hy j with \u27e8z, zAj, fzy\u27e9,\n    convert zAj,\n    apply injf,\n    rw fxy,\n    rw \u2190 fzy, },\n  { exact fxy, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (i : I)\n  (injf : injective f)\n  : (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i) :=\nbegin\n  intro y,\n  simp,\n  intro h,\n  rcases h i with \u27e8x, xAi, fxy\u27e9,\n  use x,\n  split,\n  { intro j,\n    rcases h j with \u27e8z, zAi, fzy\u27e9,\n    have : f x = f z, by rw [fxy, fzy],\n    have : x = z, from injf this,\n    rw this,\n    exact zAi },\n  { exact fxy },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 59. Demostrar que\n--    f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    rw mem_preimage at hx,\n    rw mem_Union at hx,\n    cases hx with i fxBi,\n    rw mem_Union,\n    use i,\n    apply mem_preimage.mpr,\n    exact fxBi, },\n  { intro hx,\n    rw mem_preimage,\n    rw mem_Union,\n    rw mem_Union at hx,\n    cases hx with i xBi,\n    use i,\n    rw mem_preimage at xBi,\n    exact xBi, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\npreimage_Union\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 60. Demostrar que\n--    f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    apply mem_Inter_of_mem,\n    intro i,\n    rw mem_preimage,\n    rw mem_preimage at hx,\n    rw mem_Inter at hx,\n    exact hx i, },\n  { intro hx,\n    rw mem_preimage,\n    rw mem_Inter,\n    intro i,\n    rw \u2190 mem_preimage,\n    rw mem_Inter at hx,\n    exact hx i, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  calc  (x \u2208 f \u207b\u00b9' \u22c2 (i : I), B i)\n      \u2194 f x \u2208 \u22c2 (i : I), B i       : mem_preimage\n  ... \u2194 (\u2200 i : I, f x \u2208 B i)       : mem_Inter\n  ... \u2194 (\u2200 i : I, x \u2208 f \u207b\u00b9' B i)   : iff_of_eq rfl\n  ... \u2194 x \u2208 \u22c2 (i : I), f \u207b\u00b9' B i   : mem_Inter.symm,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  simp,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nby { ext, simp }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 61. Demostrar el teorema de Cantor:\n--    \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f :=\nbegin\n  intros f surjf,\n  let S := {i | i \u2209 f i},\n  unfold surjective at surjf,\n  cases surjf S with j fjS,\n  by_cases j \u2208 S,\n  { apply absurd _ h,\n    rw fjS,\n    exact h, },\n  { apply h,\n    rw \u2190 fjS at h,\n    exact h, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f :=\nbegin\n  intros f surjf,\n  let S := {i | i \u2209 f i},\n  cases surjf S with j fjS,\n  by_cases j \u2208 S,\n  { apply absurd _ h,\n    rwa fjS, },\n  { apply h,\n    rwa \u2190 fjS at h, },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : \u2200 f : \u03b1 \u2192 set \u03b1, \u00ac surjective f :=\ncantor_surjective\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 62. Cerrar la sesi\u00f3n function_variables\n-- ----------------------------------------------------------------------\n\nend function_variables\n\n------------------------------------------------------------------------\n-- \u00a7 Referencia                                                       --\n------------------------------------------------------------------------\n\n-- Basado en la teor\u00eda sets.lean de Jeremy Avigad que se\n-- encuentra en https://bit.ly/2ZW0ldf y se comenta en el v\u00eddeo\n-- \"Sets in Lean\" que se encuentra en https://youtu.be/qlJrCtYiEkI\n", "meta": {"author": "jaalonso", "repo": "Lean_para_matematicos", "sha": "924c77b7f010604b84f82d2f79967ad8b9cddc6e", "save_path": "github-repos/lean/jaalonso-Lean_para_matematicos", "path": "github-repos/lean/jaalonso-Lean_para_matematicos/Lean_para_matematicos-924c77b7f010604b84f82d2f79967ad8b9cddc6e/src/Conjuntos/Conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339716830606, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.7120673271491619}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.fintype.big_operators\n! leanprover-community/mathlib commit 2445c98ae4b87eabebdde552593519b9b6dc350c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fintype.Option\nimport Mathlib.Data.Fintype.Powerset\nimport Mathlib.Data.Fintype.Sigma\nimport Mathlib.Data.Fintype.Sum\nimport Mathlib.Data.Fintype.Vector\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Option\n\n/-!\nResults about \"big operations\" over a `Fintype`, and consequent\nresults about cardinalities of certain types.\n\n## Implementation note\nThis content had previously been in `Data.Fintype.Basic`, but was moved here to avoid\nrequiring `Algebra.BigOperators` (and hence many other imports) as a\ndependency of `Fintype`.\n\nHowever many of the results here really belong in `Algebra.BigOperators.Basic`\nand should be moved at some point.\n-/\n\n\nuniverse u v\n\nvariable {\u03b1 : Type _} {\u03b2 : Type _} {\u03b3 : Type _}\n\nopen BigOperators\n\nnamespace Fintype\n\n@[to_additive]\ntheorem prod_bool [CommMonoid \u03b1] (f : Bool \u2192 \u03b1) : (\u220f b, f b) = f true * f false := by simp\n#align fintype.prod_bool Fintype.prod_bool\n#align fintype.sum_bool Fintype.sum_bool\n\ntheorem card_eq_sum_ones {\u03b1} [Fintype \u03b1] : Fintype.card \u03b1 = \u2211 _a : \u03b1, 1 :=\n  Finset.card_eq_sum_ones _\n#align fintype.card_eq_sum_ones Fintype.card_eq_sum_ones\n\nsection\n\nopen Finset\n\nvariable {\u03b9 : Type _} [DecidableEq \u03b9] [Fintype \u03b9]\n\n@[to_additive]\ntheorem prod_extend_by_one [CommMonoid \u03b1] (s : Finset \u03b9) (f : \u03b9 \u2192 \u03b1) :\n    (\u220f i, if i \u2208 s then f i else 1) = \u220f i in s, f i := by\n  rw [\u2190 prod_filter, filter_mem_eq_inter, univ_inter]\n#align fintype.prod_extend_by_one Fintype.prod_extend_by_one\n#align fintype.sum_extend_by_zero Fintype.sum_extend_by_zero\n\nend\n\nsection\n\nvariable {M : Type _} [Fintype \u03b1] [CommMonoid M]\n\n@[to_additive]\ntheorem prod_eq_one (f : \u03b1 \u2192 M) (h : \u2200 a, f a = 1) : (\u220f a, f a) = 1 :=\n  Finset.prod_eq_one fun a _ha => h a\n#align fintype.prod_eq_one Fintype.prod_eq_one\n#align fintype.sum_eq_zero Fintype.sum_eq_zero\n\n@[to_additive]\ntheorem prod_congr (f g : \u03b1 \u2192 M) (h : \u2200 a, f a = g a) : (\u220f a, f a) = \u220f a, g a :=\n  Finset.prod_congr rfl fun a _ha => h a\n#align fintype.prod_congr Fintype.prod_congr\n#align fintype.sum_congr Fintype.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : \u03b1 \u2192 M} (a : \u03b1) (h : \u2200 (x) (_ : x \u2260 a), f x = 1) : (\u220f x, f x) = f a :=\n  Finset.prod_eq_single a (fun x _ hx => h x hx) fun ha => (ha (Finset.mem_univ a)).elim\n#align fintype.prod_eq_single Fintype.prod_eq_single\n#align fintype.sum_eq_single Fintype.sum_eq_single\n\n@[to_additive]\ntheorem prod_eq_mul {f : \u03b1 \u2192 M} (a b : \u03b1) (h\u2081 : a \u2260 b) (h\u2082 : \u2200 x, x \u2260 a \u2227 x \u2260 b \u2192 f x = 1) :\n    (\u220f x, f x) = f a * f b := by\n  apply Finset.prod_eq_mul a b h\u2081 fun x _ hx => h\u2082 x hx <;>\n    exact fun hc => (hc (Finset.mem_univ _)).elim\n#align fintype.prod_eq_mul Fintype.prod_eq_mul\n#align fintype.sum_eq_add Fintype.sum_eq_add\n\n/-- If a product of a `Finset` of a subsingleton type has a given\nvalue, so do the terms in that product. -/\n@[to_additive \"If a sum of a `Finset` of a subsingleton type has a given\n  value, so do the terms in that sum.\"]\ntheorem eq_of_subsingleton_of_prod_eq {\u03b9 : Type _} [Subsingleton \u03b9] {s : Finset \u03b9} {f : \u03b9 \u2192 M}\n    {b : M} (h : (\u220f i in s, f i) = b) : \u2200 i \u2208 s, f i = b :=\n  Finset.eq_of_card_le_one_of_prod_eq (Finset.card_le_one_of_subsingleton s) h\n#align fintype.eq_of_subsingleton_of_prod_eq Fintype.eq_of_subsingleton_of_prod_eq\n#align fintype.eq_of_subsingleton_of_sum_eq Fintype.eq_of_subsingleton_of_sum_eq\n\nend\n\nend Fintype\n\nopen Finset\n\nsection\n\nvariable {M : Type _} [Fintype \u03b1] [CommMonoid M]\n\n@[to_additive (attr := simp)]\ntheorem Fintype.prod_option (f : Option \u03b1 \u2192 M) : (\u220f i, f i) = f none * \u220f i, f (some i) :=\n  Finset.prod_insertNone f univ\n#align fintype.prod_option Fintype.prod_option\n#align fintype.sum_option Fintype.sum_option\n\nend\n\nopen Finset\n\n@[simp]\nnonrec theorem Fintype.card_sigma {\u03b1 : Type _} (\u03b2 : \u03b1 \u2192 Type _) [Fintype \u03b1] [\u2200 a, Fintype (\u03b2 a)] :\n    Fintype.card (Sigma \u03b2) = \u2211 a, Fintype.card (\u03b2 a) :=\n  card_sigma _ _\n#align fintype.card_sigma Fintype.card_sigma\n\n@[simp]\ntheorem Finset.card_pi [DecidableEq \u03b1] {\u03b4 : \u03b1 \u2192 Type _} (s : Finset \u03b1) (t : \u2200 a, Finset (\u03b4 a)) :\n    (s.pi t).card = \u220f a in s, card (t a) :=\n  Multiset.card_pi _ _\n#align finset.card_pi Finset.card_pi\n\n@[simp]\ntheorem Fintype.card_piFinset [DecidableEq \u03b1] [Fintype \u03b1] {\u03b4 : \u03b1 \u2192 Type _} (t : \u2200 a, Finset (\u03b4 a)) :\n    (Fintype.piFinset t).card = \u220f a, Finset.card (t a) := by simp [Fintype.piFinset, card_map]\n#align fintype.card_pi_finset Fintype.card_piFinset\n\n@[simp]\ntheorem Fintype.card_pi {\u03b2 : \u03b1 \u2192 Type _} [DecidableEq \u03b1] [Fintype \u03b1] [\u2200 a, Fintype (\u03b2 a)] :\n    Fintype.card (\u2200 a, \u03b2 a) = \u220f a, Fintype.card (\u03b2 a) :=\n  Fintype.card_piFinset _\n#align fintype.card_pi Fintype.card_pi\n\n-- FIXME ouch, this should be in the main file.\n@[simp]\ntheorem Fintype.card_fun [DecidableEq \u03b1] [Fintype \u03b1] [Fintype \u03b2] :\n    Fintype.card (\u03b1 \u2192 \u03b2) = Fintype.card \u03b2 ^ Fintype.card \u03b1 := by\n  rw [Fintype.card_pi, Finset.prod_const]; rfl\n#align fintype.card_fun Fintype.card_fun\n\n@[simp]\ntheorem card_vector [Fintype \u03b1] (n : \u2115) : Fintype.card (Vector \u03b1 n) = Fintype.card \u03b1 ^ n := by\n  rw [Fintype.ofEquiv_card]; simp\n#align card_vector card_vector\n\n@[to_additive (attr := simp)]\ntheorem Finset.prod_attach_univ [Fintype \u03b1] [CommMonoid \u03b2] (f : { a : \u03b1 // a \u2208 @univ \u03b1 _ } \u2192 \u03b2) :\n    (\u220f x in univ.attach, f x) = \u220f x, f \u27e8x, mem_univ _\u27e9 :=\n  Fintype.prod_equiv (Equiv.subtypeUnivEquiv fun x => mem_univ _) _ _ fun x => by simp\n#align finset.prod_attach_univ Finset.prod_attach_univ\n#align finset.sum_attach_univ Finset.sum_attach_univ\n\n/-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`.\n  `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ\n  in the type of their element, `univ.pi t` is a `Finset (\u03a0 a \u2208 univ, t a)` and\n  `Fintype.piFinset t` is a `Finset (\u03a0 a, t a)`. -/\n@[to_additive \"Taking a sum over `univ.pi t` is the same as taking the sum over\n  `Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`,\n  but differ in the type of their element, `univ.pi t` is a `Finset (\u03a0 a \u2208 univ, t a)` and\n  `Fintype.piFinset t` is a `Finset (\u03a0 a, t a)`.\"]\ntheorem Finset.prod_univ_pi [DecidableEq \u03b1] [Fintype \u03b1] [CommMonoid \u03b2] {\u03b4 : \u03b1 \u2192 Type _}\n    {t : \u2200 a : \u03b1, Finset (\u03b4 a)} (f : (\u2200 a : \u03b1, a \u2208 (univ : Finset \u03b1) \u2192 \u03b4 a) \u2192 \u03b2) :\n    (\u220f x in univ.pi t, f x) = \u220f x in Fintype.piFinset t, f fun a _ => x a := by\n  refine prod_bij (fun x _ a => x a (mem_univ _)) ?_ (by simp)\n    (by simp (config := { contextual := true }) [Function.funext_iff]) fun x hx =>\n    \u27e8fun a _ => x a, by simp_all\u27e9\n  -- Porting note: old proof was `by simp`\n  intro a ha\n  simp only [Fintype.piFinset, mem_map, mem_pi, Function.Embedding.coeFn_mk]\n  exact \u27e8a, by simpa using ha, by simp\u27e9\n#align finset.prod_univ_pi Finset.prod_univ_pi\n#align finset.sum_univ_pi Finset.sum_univ_pi\n\n/-- The product over `univ` of a sum can be written as a sum over the product of sets,\n  `Fintype.piFinset`. `Finset.prod_sum` is an alternative statement when the product is not\n  over `univ` -/\ntheorem Finset.prod_univ_sum [DecidableEq \u03b1] [Fintype \u03b1] [CommSemiring \u03b2] {\u03b4 : \u03b1 \u2192 Type u_1}\n    [\u2200 a : \u03b1, DecidableEq (\u03b4 a)] {t : \u2200 a : \u03b1, Finset (\u03b4 a)} {f : \u2200 a : \u03b1, \u03b4 a \u2192 \u03b2} :\n    (\u220f a, \u2211 b in t a, f a b) = \u2211 p in Fintype.piFinset t, \u220f x, f x (p x) := by\n  simp only [Finset.prod_attach_univ, prod_sum, Finset.sum_univ_pi]\n#align finset.prod_univ_sum Finset.prod_univ_sum\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a fintype of cardinality `n`\ngives `(a + b)^n`. The \"good\" proof involves expanding along all coordinates using the fact that\n`x^n` is multilinear, but multilinear maps are only available now over rings, so we give instead\na proof reducing to the usual binomial theorem to have a result over semirings. -/\ntheorem Fintype.sum_pow_mul_eq_add_pow (\u03b1 : Type _) [Fintype \u03b1] {R : Type _} [CommSemiring R]\n    (a b : R) :\n    (\u2211 s : Finset \u03b1, a ^ s.card * b ^ (Fintype.card \u03b1 - s.card)) = (a + b) ^ Fintype.card \u03b1 :=\n  Finset.sum_pow_mul_eq_add_pow _ _ _\n#align fintype.sum_pow_mul_eq_add_pow Fintype.sum_pow_mul_eq_add_pow\n\n@[to_additive]\ntheorem Function.Bijective.prod_comp [Fintype \u03b1] [Fintype \u03b2] [CommMonoid \u03b3] {f : \u03b1 \u2192 \u03b2}\n    (hf : Function.Bijective f) (g : \u03b2 \u2192 \u03b3) : (\u220f i, g (f i)) = \u220f i, g i :=\n  Fintype.prod_bijective f hf _ _ fun _x => rfl\n#align function.bijective.prod_comp Function.Bijective.prod_comp\n#align function.bijective.sum_comp Function.Bijective.sum_comp\n\n@[to_additive]\ntheorem Equiv.prod_comp [Fintype \u03b1] [Fintype \u03b2] [CommMonoid \u03b3] (e : \u03b1 \u2243 \u03b2) (f : \u03b2 \u2192 \u03b3) :\n    (\u220f i, f (e i)) = \u220f i, f i :=\n  e.bijective.prod_comp f\n#align equiv.prod_comp Equiv.prod_comp\n#align equiv.sum_comp Equiv.sum_comp\n\n@[to_additive]\ntheorem Equiv.prod_comp' [Fintype \u03b1] [Fintype \u03b2] [CommMonoid \u03b3] (e : \u03b1 \u2243 \u03b2) (f : \u03b1 \u2192 \u03b3) (g : \u03b2 \u2192 \u03b3)\n    (h : \u2200 i, f i = g (e i)) : (\u220f i, f i) = \u220f i, g i :=\n  (show f = g \u2218 e from funext h).symm \u25b8 e.prod_comp _\n#align equiv.prod_comp' Equiv.prod_comp'\n#align equiv.sum_comp' Equiv.sum_comp'\n\n/-- It is equivalent to compute the product of a function over `Fin n` or `Finset.range n`. -/\n@[to_additive \"It is equivalent to sum a function over `fin n` or `finset.range n`.\"]\ntheorem Fin.prod_univ_eq_prod_range [CommMonoid \u03b1] (f : \u2115 \u2192 \u03b1) (n : \u2115) :\n    (\u220f i : Fin n, f i) = \u220f i in range n, f i :=\n  calc\n    (\u220f i : Fin n, f i) = \u220f i : { x // x \u2208 range n }, f i :=\n      (Fin.equivSubtype.trans (Equiv.subtypeEquivRight (by simp))).prod_comp' _ _ (by simp)\n    _ = \u220f i in range n, f i := by rw [\u2190 attach_eq_univ, prod_attach]\n\n#align fin.prod_univ_eq_prod_range Fin.prod_univ_eq_prod_range\n#align fin.sum_univ_eq_sum_range Fin.sum_univ_eq_sum_range\n\n@[to_additive]\ntheorem Finset.prod_fin_eq_prod_range [CommMonoid \u03b2] {n : \u2115} (c : Fin n \u2192 \u03b2) :\n    (\u220f i, c i) = \u220f i in Finset.range n, if h : i < n then c \u27e8i, h\u27e9 else 1 := by\n  rw [\u2190 Fin.prod_univ_eq_prod_range, Finset.prod_congr rfl]\n  rintro \u27e8i, hi\u27e9 _\n  simp only [hi, dif_pos]\n#align finset.prod_fin_eq_prod_range Finset.prod_fin_eq_prod_range\n#align finset.sum_fin_eq_sum_range Finset.sum_fin_eq_sum_range\n\n@[to_additive]\ntheorem Finset.prod_toFinset_eq_subtype {M : Type _} [CommMonoid M] [Fintype \u03b1] (p : \u03b1 \u2192 Prop)\n    [DecidablePred p] (f : \u03b1 \u2192 M) : (\u220f a in { x | p x }.toFinset, f a) = \u220f a : Subtype p, f a := by\n  rw [\u2190 Finset.prod_subtype]\n  simp_rw [Set.mem_toFinset]; intro; rfl\n#align finset.prod_to_finset_eq_subtype Finset.prod_toFinset_eq_subtype\n#align finset.sum_to_finset_eq_subtype Finset.sum_toFinset_eq_subtype\n\n@[to_additive]\ntheorem Finset.prod_fiberwise [DecidableEq \u03b2] [Fintype \u03b2] [CommMonoid \u03b3] (s : Finset \u03b1) (f : \u03b1 \u2192 \u03b2)\n    (g : \u03b1 \u2192 \u03b3) : (\u220f b : \u03b2, \u220f a in s.filter fun a => f a = b, g a) = \u220f a in s, g a :=\n  Finset.prod_fiberwise_of_maps_to (fun _x _ => mem_univ _) _\n#align finset.prod_fiberwise Finset.prod_fiberwise\n#align finset.sum_fiberwise Finset.sum_fiberwise\n\n@[to_additive]\ntheorem Fintype.prod_fiberwise [Fintype \u03b1] [DecidableEq \u03b2] [Fintype \u03b2] [CommMonoid \u03b3] (f : \u03b1 \u2192 \u03b2)\n    (g : \u03b1 \u2192 \u03b3) : (\u220f b : \u03b2, \u220f a : { a // f a = b }, g (a : \u03b1)) = \u220f a, g a := by\n  rw [\u2190 (Equiv.sigmaFiberEquiv f).prod_comp, \u2190 univ_sigma_univ, prod_sigma]\n  rfl\n#align fintype.prod_fiberwise Fintype.prod_fiberwise\n#align fintype.sum_fiberwise Fintype.sum_fiberwise\n\nnonrec theorem Fintype.prod_dite [Fintype \u03b1] {p : \u03b1 \u2192 Prop} [DecidablePred p] [CommMonoid \u03b2]\n    (f : \u2200 (a : \u03b1) (_ha : p a), \u03b2) (g : \u2200 (a : \u03b1) (_ha : \u00acp a), \u03b2) :\n    (\u220f a, dite (p a) (f a) (g a)) = (\u220f a : { a // p a }, f a a.2) * \u220f a : { a // \u00acp a }, g a a.2 :=\n  by\n  simp only [prod_dite, attach_eq_univ]\n  congr 1\n  \u00b7 exact (Equiv.subtypeEquivRight $ by simp).prod_comp fun x : { x // p x } => f x x.2\n  \u00b7 exact (Equiv.subtypeEquivRight $ by simp).prod_comp fun x : { x // \u00acp x } => g x x.2\n#align fintype.prod_dite Fintype.prod_dite\n\nsection\n\nopen Finset\n\nvariable {\u03b1\u2081 : Type _} {\u03b1\u2082 : Type _} {M : Type _} [Fintype \u03b1\u2081] [Fintype \u03b1\u2082] [CommMonoid M]\n\n@[to_additive]\ntheorem Fintype.prod_sum_elim (f : \u03b1\u2081 \u2192 M) (g : \u03b1\u2082 \u2192 M) :\n    (\u220f x, Sum.elim f g x) = (\u220f a\u2081, f a\u2081) * \u220f a\u2082, g a\u2082 :=\n  prod_disj_sum _ _ _\n#align fintype.prod_sum_elim Fintype.prod_sum_elim\n#align fintype.sum_sum_elim Fintype.sum_sum_elim\n\n@[to_additive (attr := simp)]\ntheorem Fintype.prod_sum_type (f : Sum \u03b1\u2081 \u03b1\u2082 \u2192 M) :\n    (\u220f x, f x) = (\u220f a\u2081, f (Sum.inl a\u2081)) * \u220f a\u2082, f (Sum.inr a\u2082) :=\n  prod_disj_sum _ _ _\n#align fintype.prod_sum_type Fintype.prod_sum_type\n#align fintype.sum_sum_type Fintype.sum_sum_type\n\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Fintype/BigOperators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357569, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7120673269744306}}
{"text": "-- Pertenencia_a_su_propia_clase_de_equivalencia.lean\n-- Pertenencia a su propia clase de equivalencia\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 2 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Este ejercicio es el 3\u00ba de una serie, cuyo objetivo es demostrar que\n-- el tipo de las particiones de un conjunto `X` es isomorfo al tipo de\n-- las relaciones de equivalencia sobre `X`.\n--\n-- Los anteriores son\n-- 1. [Igualdad de bloques de una partici\u00f3n cuando tienen elementos comunes](https://bit.ly/2YfsvBZ).\n-- 2. [Pertenencia a bloques de una partici\u00f3n con elementos comunes](https://bit.ly/3l2onxZ).\n--\n-- Los anteriores fueron sobre particiones y con este empezamos con las\n-- relaciones de equivalencia que est\u00e1n definidas en Lean por:\n--    reflexive R := \u2200 (x : A), R x x\n--    symmetric R := \u2200 \u2983x y : A\u2984, R x y \u2192 R y x\n--    transitive R := \u2200 \u2983x y z : A\u2984, R x y \u2192 R y z \u2192 R x z\n--    equivalence R := reflexive R \u2227 symmetric R \u2227 transitive R\n-- donde `A` un tipo y `R: A \u2192 A \u2192 Prop` es una relaci\u00f3n binaria en `A`.\n--\n-- Adem\u00e1s, en Lean se puede definir la clase de equivalencia de un\n-- elemento `a` respecto de una relaci\u00f3n de equivalencia `R` por\n--    def clase (a : A) :=\n--      {b : A | R b a}\n--\n-- Demostrar que cada elemento pertenece a su clase de equivalencia.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\nvariable {A : Type}\nvariable (R : A \u2192 A \u2192 Prop)\n\ndef clase (a : A) :=\n  {b : A | R b a}\n\n-- Se usar\u00e1 el siguiente lema auxiliar\nlemma pertenece_clase_syss\n  {a b : A}\n  : b \u2208 clase R a \u2194 R b a :=\nby refl\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  {hR : equivalence R}\n  (a : A)\n  : a \u2208 clase R a :=\nbegin\n  rw pertenece_clase_syss,\n  suffices h : reflexive R,\n  { exact h a, },\n  { rcases hR with \u27e8h2, -, -\u27e9,\n    exact h2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  {hR : equivalence R}\n  (a : A)\n  : a \u2208 clase R a :=\nbegin\n  rw pertenece_clase_syss,\n  suffices h : reflexive R,\n  { exact h a, },\n  { exact hR.1, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  {hR : equivalence R}\n  (a : A)\n  : a \u2208 clase R a :=\nbegin\n  rw pertenece_clase_syss,\n  rcases hR with \u27e8hrefl, -, -\u27e9,\n  exact hrefl a,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  {hR : equivalence R}\n  (a : A)\n  : a \u2208 clase R a :=\nbegin\n  obtain \u27e8hrefl, -, -\u27e9 := hR,\n  rw pertenece_clase_syss,\n  apply hrefl,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  {hR : equivalence R}\n  (a : A)\n  : a \u2208 clase R a :=\nbegin\n  rw pertenece_clase_syss,\n  apply hR.1,\nend\n\n-- 6\u00aa demostraci\u00f3n\nlemma pertenece_clase_propia\n  {hR : equivalence R}\n  (a : A)\n  : a \u2208 clase R a :=\n(pertenece_clase_syss R).mpr (hR.1 a)\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Pertenencia_a_su_propia_clase_de_equivalencia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.7120673135449731}}
{"text": "import Duper.Tactic\n\nclass Group (G : Type) where \n(one : G)\n(inv : G \u2192 G)\n(mul : G \u2192 G \u2192 G)\n(mul_assoc : \u2200 (x y z : G), mul (mul x y) z = mul x (mul y z))\n(mul_one : \u2200 (x : G), mul x one = x)\n(mul_inv : \u2200 (x : G), mul x (inv x) = one)\n\nnamespace Group\n\nvariable {G : Type} [hG : Group G] (x y : G)\n\ninfix:80 (priority := high) \" \u2b1d \" => Group.mul\n\nnoncomputable instance : Inhabited G := \u27e8one\u27e9\n\ntheorem test : x \u2b1d one = x :=\nby duper [Group.mul_one]\n\ntheorem exists_right_inv (x : G) : inv x \u2b1d x = one :=\nby duper [Group.mul_assoc, Group.mul_one, Group.mul_inv]\n\nset_option trace.Prover.saturate true in\ntheorem left_neutral_unique (x : G) : (\u2200 y, x \u2b1d y = y) \u2192 x = one :=\nby duper [Group.mul_assoc, Group.mul_one, Group.mul_inv]\n\ntheorem right_neutral_unique (x : G) : (\u2200 y, y \u2b1d x = y) \u2192 x = one :=\nby duper [Group.mul_assoc, Group.mul_one, Group.mul_inv]\n\ntheorem right_inv_unique (x y z : G) (h : x \u2b1d y = one) (h : x \u2b1d z = one) : y = z :=\nby duper [Group.mul_assoc, Group.mul_one, Group.mul_inv]\n\ntheorem left_inv_unique (x y z : G) (h : y \u2b1d x = one) (h : z \u2b1d x = one) : y = z :=\nby duper [Group.mul_assoc, Group.mul_one, Group.mul_inv]\n\nnoncomputable def sq := x \u2b1d x\n\ntheorem sq_mul_sq_eq_e (h_comm : \u2200 (a b : G), a \u2b1d b = b \u2b1d a) (h : x \u2b1d y = one) :\n  sq x \u2b1d sq y = one :=\nby duper [sq, Group.mul_assoc, Group.mul_one, Group.mul_inv]\n\nend Group", "meta": {"author": "leanprover-community", "repo": "duper", "sha": "96b8f8383363e800976b0fa99830c1b5e8c19b09", "save_path": "github-repos/lean/leanprover-community-duper", "path": "github-repos/lean/leanprover-community-duper/duper-96b8f8383363e800976b0fa99830c1b5e8c19b09/Duper/Tests/group2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7119674916416306}}
{"text": "import Mynat.Base\n\nnamespace mynat\n\ndef myadd (m n : mynat) : mynat :=\n  match n with\n  | 0   => m\n  | succ n' => succ (myadd m n')\n\ninstance : Add mynat where\n  add := myadd\n\ntheorem add_zero (m : mynat) : m + 0 = m := rfl\ntheorem add_succ (m n : mynat) : m + succ n = succ (m + n) := rfl\n\ntheorem zero_add (n : mynat) : 0 + n = n := by\n  cases n\n  . rfl\n  case succ m =>\n    have h := congrArg succ (zero_add m)\n    rw [\u2190add_succ] at h\n    exact h\n\ntheorem add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) := by\n  cases c\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    repeat {rw [add_zero]}\n    rfl\n  case succ m =>\n    rw [add_succ]\n    rw [add_succ]\n    rw [add_succ]\n    rw [add_assoc a b m]\n\ntheorem succ_add (a b : mynat) : succ a + b = succ (a + b) := by\n  cases b\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    repeat {rw [add_zero]}\n    rfl\n  case succ m =>\n    rw [add_succ]\n    rw [add_succ]\n    rw [succ_add a m]\n\ntheorem add_comm (a b : mynat) : a + b = b + a := by\n  cases b\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [add_zero]\n    rw [zero_add]\n  case succ m =>\n    rw [add_succ]\n    rw [succ_add]\n    rw [add_comm a m]\n\ntheorem succ_eq_add_one (n : mynat) : succ n = n + 1 := by\n  rw [one_eq_succ_zero]\n  rw [add_succ n 0]\n  rw [add_zero]\n\ntheorem add_right_comm (a b c : mynat) : a + b + c = a + c + b := by\n  rw [add_assoc]\n  rw [add_assoc]\n  rw [add_comm b c]\n\nattribute [simp] add_assoc add_comm add_right_comm\n\nend mynat", "meta": {"author": "plumsirawit", "repo": "mynat", "sha": "0a6529078322c76f7460ef6dafba8367608a5163", "save_path": "github-repos/lean/plumsirawit-mynat", "path": "github-repos/lean/plumsirawit-mynat/mynat-0a6529078322c76f7460ef6dafba8367608a5163/Mynat/Add.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.711967480715265}}
{"text": "/-\nCopyright (c) 2015 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jeremy Avigad\n\nThe power operation on monoids and groups. We separate this from group, because it depends on\nnat, which in turn depends on other parts of algebra.\n\nWe have \"pow a n\" for natural number powers, and \"gpow a i\" for integer powers. The notation\na^n is used for the first, but users can locally redefine it to gpow when needed.\n\nNote: power adopts the convention that 0^0=1.\n-/\nimport data.nat.basic data.int.basic\n\nvariables {A : Type}\n\nstructure has_pow_nat [class] (A : Type) :=\n(pow_nat : A \u2192 nat \u2192 A)\n\ndefinition pow_nat {A : Type} [s : has_pow_nat A] : A \u2192 nat \u2192 A :=\nhas_pow_nat.pow_nat\n\ninfix ` ^ ` := pow_nat\n\nstructure has_pow_int [class] (A : Type) :=\n(pow_int : A \u2192 int \u2192 A)\n\ndefinition pow_int {A : Type} [s : has_pow_int A] : A \u2192 int \u2192 A :=\nhas_pow_int.pow_int\n\n /- monoid -/\nsection monoid\nopen nat\n\nvariable [s : monoid A]\ninclude s\n\ndefinition monoid.pow (a : A) : \u2115 \u2192 A\n| 0     := 1\n| (n+1) := a * monoid.pow n\n\ndefinition monoid_has_pow_nat [instance] : has_pow_nat A :=\nhas_pow_nat.mk monoid.pow\n\ntheorem pow_zero (a : A) : a^0 = 1 := rfl\ntheorem pow_succ (a : A) (n : \u2115) : a^(succ n) = a * a^n := rfl\n\ntheorem pow_one (a : A) : a^1 = a := !mul_one\ntheorem pow_two (a : A) : a^2 = a * a :=\ncalc\n  a^2 = a * (a * 1) : rfl\n  ... = a * a       : mul_one\ntheorem pow_three (a : A) : a^3 = a * (a * a) :=\ncalc\n  a^3 = a * (a * (a * 1)) : rfl\n  ... = a * (a * a)       : mul_one\ntheorem pow_four (a : A) : a^4 = a * (a * (a * a))  :=\ncalc\n  a^4 = a * a^3           : rfl\n  ... = a * (a * (a * a)) : pow_three\n\ntheorem pow_succ' (a : A) : \u2200n, a^(succ n) = a^n * a\n| 0        := by rewrite [pow_succ, *pow_zero, one_mul, mul_one]\n| (succ n) := by rewrite [pow_succ, pow_succ' at {1}, pow_succ, mul.assoc]\n\ntheorem one_pow : \u2200 n : \u2115, 1^n = (1:A)\n| 0        := rfl\n| (succ n) := by rewrite [pow_succ, one_mul, one_pow]\n\ntheorem pow_add (a : A) (m n : \u2115) : a^(m + n) = a^m * a^n :=\nbegin\n  induction n with n ih,\n    {krewrite [nat.add_zero, pow_zero, mul_one]},\n  rewrite [add_succ, *pow_succ', ih, mul.assoc]\nend\n\ntheorem pow_mul (a : A) (m : \u2115) : \u2200 n, a^(m * n) = (a^m)^n\n| 0        := by rewrite [nat.mul_zero, pow_zero]\n| (succ n) := by rewrite [nat.mul_succ, pow_add, pow_succ', pow_mul]\n\ntheorem pow_comm (a : A) (m n : \u2115)  : a^m * a^n = a^n * a^m :=\nby rewrite [-*pow_add, add.comm]\n\nend monoid\n\n/- commutative monoid -/\n\nsection comm_monoid\nopen nat\nvariable [s : comm_monoid A]\ninclude s\n\ntheorem mul_pow (a b : A) : \u2200 n, (a * b)^n = a^n * b^n\n| 0        := by rewrite [*pow_zero, mul_one]\n| (succ n) := by rewrite [*pow_succ', mul_pow, *mul.assoc, mul.left_comm a]\n\nend comm_monoid\n\nsection group\nvariable [s : group A]\ninclude s\n\nsection nat\nopen nat\ntheorem inv_pow (a : A) : \u2200n, (a\u207b\u00b9)^n = (a^n)\u207b\u00b9\n| 0        := by rewrite [*pow_zero, one_inv]\n| (succ n) := by rewrite [pow_succ, pow_succ', inv_pow, mul_inv]\n\ntheorem pow_sub (a : A) {m n : \u2115} (H : m \u2265 n) : a^(m - n) = a^m * (a^n)\u207b\u00b9 :=\nhave H1 : m - n + n = m, from nat.sub_add_cancel H,\nhave H2 : a^(m - n) * a^n = a^m, by rewrite [-pow_add, H1],\neq_mul_inv_of_mul_eq H2\n\ntheorem pow_inv_comm (a : A) : \u2200m n, (a\u207b\u00b9)^m * a^n = a^n * (a\u207b\u00b9)^m\n| 0 n               := by rewrite [*pow_zero, one_mul, mul_one]\n| m 0               := by rewrite [*pow_zero, one_mul, mul_one]\n| (succ m) (succ n) := by rewrite [pow_succ' at {1}, pow_succ at {1}, pow_succ', pow_succ,\n                            *mul.assoc, inv_mul_cancel_left, mul_inv_cancel_left, pow_inv_comm]\n\nend nat\n\nopen int\n\ndefinition gpow (a : A) : \u2124 \u2192 A\n| (of_nat n) := a^n\n| -[1+n]     := (a^(nat.succ n))\u207b\u00b9\n\nopen nat\n\nprivate lemma gpow_add_aux (a : A) (m n : nat) :\n  gpow a ((of_nat m) + -[1+n]) = gpow a (of_nat m) * gpow a (-[1+n]) :=\nor.elim (nat.lt_or_ge m (nat.succ n))\n  (assume H : (m < nat.succ n),\n    have H1 : (#nat nat.succ n - m > nat.zero), from nat.sub_pos_of_lt H,\n    calc\n      gpow a ((of_nat m) + -[1+n]) = gpow a (sub_nat_nat m (nat.succ n))  : rfl\n        ... = gpow a (-[1+ nat.pred (nat.sub (nat.succ n) m)])            : {sub_nat_nat_of_lt H}\n        ... = (a ^ (nat.succ (nat.pred (nat.sub (nat.succ n) m))))\u207b\u00b9    : rfl\n        ... = (a ^ (nat.succ n) * (a ^ m)\u207b\u00b9)\u207b\u00b9                        :\n                by krewrite [succ_pred_of_pos H1, pow_sub a (nat.le_of_lt H)]\n        ... = a ^ m * (a ^ (nat.succ n))\u207b\u00b9                            :\n                by rewrite [mul_inv, inv_inv]\n        ... = gpow a (of_nat m) * gpow a (-[1+n])                         : rfl)\n  (assume H : (m \u2265 nat.succ n),\n    calc\n      gpow a ((of_nat m) + -[1+n]) = gpow a (sub_nat_nat m (nat.succ n))  : rfl\n        ... = gpow a (#nat m - nat.succ n)                                : {sub_nat_nat_of_ge H}\n        ... = a ^ m * (a ^ (nat.succ n))\u207b\u00b9                                : pow_sub a H\n        ... = gpow a (of_nat m) * gpow a (-[1+n])                         : rfl)\n\ntheorem gpow_add (a : A) : \u2200i j : int, gpow a (i + j) = gpow a i * gpow a j\n| (of_nat m) (of_nat n) := !pow_add\n| (of_nat m) -[1+n]     := !gpow_add_aux\n| -[1+m]     (of_nat n) := by rewrite [add.comm, gpow_add_aux, \u2191gpow, -*inv_pow, pow_inv_comm]\n| -[1+m]     -[1+n]     :=\n  calc\n    gpow a (-[1+m] + -[1+n]) = (a^(#nat nat.succ m + nat.succ n))\u207b\u00b9 : rfl\n      ... = (a^(nat.succ m))\u207b\u00b9 * (a^(nat.succ n))\u207b\u00b9 : by rewrite [pow_add, pow_comm, mul_inv]\n      ... = gpow a (-[1+m]) * gpow a (-[1+n])       : rfl\n\ntheorem gpow_comm (a : A) (i j : \u2124) : gpow a i * gpow a j = gpow a j * gpow a i :=\nby rewrite [-*gpow_add, add.comm]\nend group\n\nsection ordered_ring\nopen nat\nvariable [s : linear_ordered_ring A]\ninclude s\n\ntheorem pow_pos {a : A} (H : a > 0) (n : \u2115) : a ^ n > 0 :=\n  begin\n    induction n,\n    krewrite pow_zero,\n    apply zero_lt_one,\n    rewrite pow_succ',\n    apply mul_pos,\n    apply v_0, apply H\n  end\n\ntheorem pow_ge_one_of_ge_one {a : A} (H : a \u2265 1) (n : \u2115) : a ^ n \u2265 1 :=\n  begin\n    induction n,\n    krewrite pow_zero,\n    apply le.refl,\n    rewrite [pow_succ', -mul_one 1],\n    apply mul_le_mul v_0 H zero_le_one,\n    apply le_of_lt,\n    apply pow_pos,\n    apply gt_of_ge_of_gt H zero_lt_one\n  end\n\ntheorem pow_two_add (n : \u2115) : (2:A)^n + 2^n = 2^(succ n) :=\n  by rewrite [pow_succ', -one_add_one_eq_two, left_distrib, *mul_one]\n\nend ordered_ring\n\n/- additive monoid -/\n\nsection add_monoid\nvariable [s : add_monoid A]\ninclude s\nlocal attribute add_monoid.to_monoid [trans_instance]\nopen nat\n\ndefinition nmul : \u2115 \u2192 A \u2192 A := \u03bb n a, a^n\n\ninfix [priority algebra.prio] `\u2b1d` := nmul\n\ntheorem zero_nmul (a : A) : (0:\u2115) \u2b1d a = 0 := pow_zero a\ntheorem succ_nmul (n : \u2115) (a : A) : nmul (succ n) a = a + (nmul n a) := pow_succ a n\n\ntheorem succ_nmul' (n : \u2115) (a : A) : succ n \u2b1d a = nmul n a + a := pow_succ' a n\n\ntheorem nmul_zero (n : \u2115) : n \u2b1d 0 = (0:A) := one_pow n\n\ntheorem one_nmul (a : A) : 1 \u2b1d a = a := pow_one a\n\ntheorem add_nmul (m n : \u2115) (a : A) : (m + n) \u2b1d a = (m \u2b1d a) + (n \u2b1d a) := pow_add a m n\n\ntheorem mul_nmul (m n : \u2115) (a : A) : (m * n) \u2b1d a = m \u2b1d (n \u2b1d a) := eq.subst (mul.comm n m) (pow_mul a n m)\n\ntheorem nmul_comm (m n : \u2115) (a : A) : (m \u2b1d a) + (n \u2b1d a) = (n \u2b1d a) + (m \u2b1d a) := pow_comm a m n\n\nend add_monoid\n\n/- additive commutative monoid -/\n\nsection add_comm_monoid\nopen nat\nvariable [s : add_comm_monoid A]\ninclude s\nlocal attribute add_comm_monoid.to_comm_monoid [trans_instance]\n\ntheorem nmul_add (n : \u2115) (a b : A) : n \u2b1d (a + b) = (n \u2b1d a) + (n \u2b1d b) := mul_pow a b n\n\nend add_comm_monoid\n\nsection add_group\nvariable [s : add_group A]\ninclude s\nlocal attribute add_group.to_group [trans_instance]\n\nsection nat\nopen nat\ntheorem nmul_neg (n : \u2115) (a : A) : n \u2b1d (-a) = -(n \u2b1d a) := inv_pow a n\n\ntheorem sub_nmul {m n : \u2115} (a : A) (H : m \u2265 n) : (m - n) \u2b1d a = (m \u2b1d a) + -(n \u2b1d a) := pow_sub a H\n\ntheorem nmul_neg_comm (m n : \u2115) (a : A) : (m \u2b1d (-a)) + (n \u2b1d a) = (n \u2b1d a) + (m \u2b1d (-a)) := pow_inv_comm a m n\n\nend nat\n\nopen int\n\ndefinition imul : \u2124 \u2192 A \u2192 A := \u03bb i a, gpow a i\n\ntheorem add_imul (i j : \u2124) (a : A) : imul (i + j) a = imul i a + imul j a :=\n  gpow_add a i j\n\ntheorem imul_comm (i j : \u2124) (a : A) : imul i a + imul j a = imul j a + imul i a := gpow_comm a i j\n\nend add_group\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/algebra/group_power.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7119674763495661}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov\n-/\nimport linear_algebra.quotient\n\n/-!\n# Isomorphism theorems for modules.\n\n* The Noether's first, second, and third isomorphism theorems for modules are proved as\n  `linear_map.quot_ker_equiv_range`, `linear_map.quotient_inf_equiv_sup_quotient` and\n  `submodule.quotient_quotient_equiv_quotient`.\n\n-/\n\nuniverses u v\n\nvariables {R M M\u2082 M\u2083 : Type*}\nvariables [ring R] [add_comm_group M] [add_comm_group M\u2082] [add_comm_group M\u2083]\nvariables [module R M] [module R M\u2082] [module R M\u2083]\nvariables (f : M \u2192\u2097[R] M\u2082)\n\n/-! The first and second isomorphism theorems for modules. -/\nnamespace linear_map\n\nopen submodule\n\nsection isomorphism_laws\n\n/-- The first isomorphism law for modules. The quotient of `M` by the kernel of `f` is linearly\nequivalent to the range of `f`. -/\nnoncomputable def quot_ker_equiv_range : (M \u29f8 f.ker) \u2243\u2097[R] f.range :=\n(linear_equiv.of_injective (f.ker.liftq f $ le_refl _) $\n  ker_eq_bot.mp $ submodule.ker_liftq_eq_bot _ _ _ (le_refl f.ker)).trans\n  (linear_equiv.of_eq _ _ $ submodule.range_liftq _ _ _)\n\n/-- The first isomorphism theorem for surjective linear maps. -/\nnoncomputable def quot_ker_equiv_of_surjective\n  (f : M \u2192\u2097[R] M\u2082) (hf : function.surjective f) : (M \u29f8 f.ker) \u2243\u2097[R] M\u2082 :=\nf.quot_ker_equiv_range.trans\n  (linear_equiv.of_top f.range (linear_map.range_eq_top.2 hf))\n\n@[simp] lemma quot_ker_equiv_range_apply_mk (x : M) :\n  (f.quot_ker_equiv_range (submodule.quotient.mk x) : M\u2082) = f x :=\nrfl\n\n@[simp] lemma quot_ker_equiv_range_symm_apply_image (x : M) (h : f x \u2208 f.range) :\n  f.quot_ker_equiv_range.symm \u27e8f x, h\u27e9 = f.ker.mkq x :=\nf.quot_ker_equiv_range.symm_apply_apply (f.ker.mkq x)\n\n/--\nCanonical linear map from the quotient `p/(p \u2229 p')` to `(p+p')/p'`, mapping `x + (p \u2229 p')`\nto `x + p'`, where `p` and `p'` are submodules of an ambient module.\n-/\ndef quotient_inf_to_sup_quotient (p p' : submodule R M) :\n  p \u29f8 (comap p.subtype (p \u2293 p')) \u2192\u2097[R] _ \u29f8 (comap (p \u2294 p').subtype p') :=\n(comap p.subtype (p \u2293 p')).liftq\n  ((comap (p \u2294 p').subtype p').mkq.comp (of_le le_sup_left)) begin\nrw [ker_comp, of_le, comap_cod_restrict, ker_mkq, map_comap_subtype],\nexact comap_mono (inf_le_inf_right _ le_sup_left) end\n\n/--\nSecond Isomorphism Law : the canonical map from `p/(p \u2229 p')` to `(p+p')/p'` as a linear isomorphism.\n-/\nnoncomputable def quotient_inf_equiv_sup_quotient (p p' : submodule R M) :\n  (p \u29f8 (comap p.subtype (p \u2293 p'))) \u2243\u2097[R] _ \u29f8 (comap (p \u2294 p').subtype p') :=\nlinear_equiv.of_bijective (quotient_inf_to_sup_quotient p p')\n  begin\n    rw [\u2190 ker_eq_bot, quotient_inf_to_sup_quotient, ker_liftq_eq_bot],\n    rw [ker_comp, ker_mkq],\n    exact \u03bb \u27e8x, hx1\u27e9 hx2, \u27e8hx1, hx2\u27e9\n  end\n  begin\n    rw [\u2190 range_eq_top, quotient_inf_to_sup_quotient, range_liftq, eq_top_iff'],\n    rintros \u27e8x, hx\u27e9, rcases mem_sup.1 hx with \u27e8y, hy, z, hz, rfl\u27e9,\n    use [\u27e8y, hy\u27e9], apply (submodule.quotient.eq _).2,\n    change y - (y + z) \u2208 p',\n    rwa [sub_add_eq_sub_sub, sub_self, zero_sub, neg_mem_iff]\n  end\n\n@[simp] lemma coe_quotient_inf_to_sup_quotient (p p' : submodule R M) :\n  \u21d1(quotient_inf_to_sup_quotient p p') = quotient_inf_equiv_sup_quotient p p' := rfl\n\n@[simp] lemma quotient_inf_equiv_sup_quotient_apply_mk (p p' : submodule R M) (x : p) :\n  quotient_inf_equiv_sup_quotient p p' (submodule.quotient.mk x) =\n    submodule.quotient.mk (of_le (le_sup_left : p \u2264 p \u2294 p') x) :=\nrfl\n\nlemma quotient_inf_equiv_sup_quotient_symm_apply_left (p p' : submodule R M)\n  (x : p \u2294 p') (hx : (x:M) \u2208 p) :\n  (quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) =\n    submodule.quotient.mk \u27e8x, hx\u27e9 :=\n(linear_equiv.symm_apply_eq _).2 $ by simp [of_le_apply]\n\n@[simp] lemma quotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff {p p' : submodule R M}\n  {x : p \u2294 p'} :\n  (quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 \u2194 (x:M) \u2208 p' :=\n(linear_equiv.symm_apply_eq _).trans $ by simp [of_le_apply]\n\nlemma quotient_inf_equiv_sup_quotient_symm_apply_right (p p' : submodule R M) {x : p \u2294 p'}\n  (hx : (x:M) \u2208 p') :\n  (quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 :=\nquotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff.2 hx\n\nend isomorphism_laws\n\nend linear_map\n\n/-! The third isomorphism theorem for modules. -/\nnamespace submodule\n\nvariables (S T : submodule R M) (h : S \u2264 T)\n\n/-- The map from the third isomorphism theorem for modules: `(M / S) / (T / S) \u2192 M / T`. -/\ndef quotient_quotient_equiv_quotient_aux :\n  (M \u29f8 S) \u29f8 (T.map S.mkq) \u2192\u2097[R] M \u29f8 T :=\nliftq _ (mapq S T linear_map.id h)\n  (by { rintro _ \u27e8x, hx, rfl\u27e9, rw [linear_map.mem_ker, mkq_apply, mapq_apply],\n        exact (quotient.mk_eq_zero _).mpr hx })\n\n@[simp] lemma quotient_quotient_equiv_quotient_aux_mk (x : M \u29f8 S) :\n  quotient_quotient_equiv_quotient_aux S T h (quotient.mk x) = mapq S T linear_map.id h x :=\nliftq_apply _ _ _\n\n@[simp] lemma quotient_quotient_equiv_quotient_aux_mk_mk (x : M) :\n  quotient_quotient_equiv_quotient_aux S T h (quotient.mk (quotient.mk x)) = quotient.mk x :=\nby rw [quotient_quotient_equiv_quotient_aux_mk, mapq_apply, linear_map.id_apply]\n\n/-- **Noether's third isomorphism theorem** for modules: `(M / S) / (T / S) \u2243 M / T`. -/\ndef quotient_quotient_equiv_quotient :\n  ((M \u29f8 S) \u29f8 (T.map S.mkq)) \u2243\u2097[R] M \u29f8 T :=\n{ to_fun := quotient_quotient_equiv_quotient_aux S T h,\n  inv_fun := mapq _ _ (mkq S) (le_comap_map _ _),\n  left_inv := \u03bb x, quotient.induction_on' x $ \u03bb x, quotient.induction_on' x $ \u03bb x, by simp,\n  right_inv := \u03bb x, quotient.induction_on' x $ \u03bb x, by simp,\n  .. quotient_quotient_equiv_quotient_aux S T h }\n\nend submodule\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/isomorphisms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.7119674741545978}}
{"text": "import analysis.normed_space.hahn_banach\nimport data.real.basic\nimport analysis.normed_space.extend\nimport tactic\nimport topology.basic\n\nopen function metric filter is_R_or_C\nopen_locale classical topological_space big_operators nnreal\nnamespace vilnius\n\nvariables {\ud835\udd5c : Type} [is_R_or_C \ud835\udd5c]\nvariables {V : Type*} [normed_group V] [normed_space \ud835\udd5c V] \n\n-- ## Example 1\n\n/- \nThe Hahn-Banach theorem about extending linear functionals to a field `\ud835\udd5c = \u211d` or `\ud835\udd5c = \u2102`: -/\n\ntheorem Hahn_Banach [complete_space V] (p : subspace \ud835\udd5c V)\n(f : p \u2192L[\ud835\udd5c] \ud835\udd5c) : \u2203 g : V \u2192L[\ud835\udd5c] \ud835\udd5c, (\u2200 x : p, g x = f x) \u2227 \u2225g\u2225 = \u2225f\u2225 :=\nbegin\n  letI : module \u211d V := restrict_scalars.module \u211d \ud835\udd5c V,\n  letI : is_scalar_tower \u211d \ud835\udd5c V := restrict_scalars.is_scalar_tower _ _ _,\n  letI : normed_space \u211d V := normed_space.restrict_scalars _ \ud835\udd5c _,\n  -- Let `fr: p \u2192L[\u211d] \u211d` be the real part of `f`.\n  let fr := re_clm.comp (f.restrict_scalars \u211d),\n  have fr_apply : \u2200 x, fr x = re (f x), by { assume x, refl },\n  -- Use the real version to get a norm-preserving extension of `fr`, which\n  -- we'll call `g : V \u2192L[\u211d] \u211d`.\n  rcases real.exists_extension_norm_eq (p.restrict_scalars \u211d) fr with \u27e8g, \u27e8hextends, hnormeq\u27e9\u27e9,\n  -- **Now `g` can be extended to the `V \u2192L[\ud835\udd5c] \ud835\udd5c` we need.**\n  refine \u27e8g.extend_to_\ud835\udd5c, _\u27e9,\n  -- It is an extension of `f`.\n  have h : \u2200 x : p, g.extend_to_\ud835\udd5c x = f x,\n  { assume x,\n    rw [continuous_linear_map.extend_to_\ud835\udd5c_apply, \u2190submodule.coe_smul, hextends, hextends],\n    have : (fr x : \ud835\udd5c) - I * \u2191(fr (I \u2022 x)) = (re (f x) : \ud835\udd5c) - (I : \ud835\udd5c) * (re (f ((I : \ud835\udd5c) \u2022 x))),\n      by refl,\n    rw this,\n    apply ext,\n    { simp only [add_zero, algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add,\n        zero_sub, I_im', zero_mul, of_real_re, eq_self_iff_true, sub_zero, of_real_neg, mul_re,\n          mul_zero, sub_neg_eq_add, continuous_linear_map.map_smul, mul_neg, sub_neg_eq_add,\n          map_add, of_real_re, I_mul_re, of_real_im, neg_zero', add_zero] },\n    { simp only [algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add, zero_sub, I_im',\n        zero_mul, of_real_re, mul_im, zero_add, of_real_neg, mul_re,\n        sub_neg_eq_add, continuous_linear_map.map_smul, mul_neg, sub_neg_eq_add, map_add, \n        of_real_im, mul_im, mul_zero, of_real_re, I_im', zero_add] } },\n  -- And we derive the equality of the norms by bounding on both sides.\n  refine \u27e8h, le_antisymm _ _\u27e9,\n  { calc \u2225g.extend_to_\ud835\udd5c\u2225\n        \u2264 \u2225g\u2225 : g.extend_to_\ud835\udd5c.op_norm_le_bound g.op_norm_nonneg (norm_bound _)\n    ... = \u2225fr\u2225 : hnormeq\n    ... \u2264 \u2225re_clm\u2225 * \u2225f\u2225 : continuous_linear_map.op_norm_comp_le _ _\n    ... = \u2225f\u2225 : by rw [re_clm_norm, one_mul] },\n  -- We're **almost** there...\n  { exact f.op_norm_le_bound g.extend_to_\ud835\udd5c.op_norm_nonneg (\u03bb x, h x \u25b8 g.extend_to_\ud835\udd5c.le_op_norm x) },\nend\n\n-- #lint\n\n/-- ## Example 2\n\nWe are going to show the trivial result asserting that the sum of two odd numbers is even: first, the definitions:-/\n\ndefinition even (n : \u2115) := \u2203 (k : \u2115), n = 2 * k\ndefinition odd (n : \u2115) := \u2203 (k : \u2115), n = 2 * k + 1\n\n/--Then, some results that are already in the library:\n* theorem `add_add_add_comm` (a b c d : G) : (a + b) + (c + d) = (a + c) + (b + d)\n* theorem `one_add_one_eq_two` : 1 + 1 = 2\n* theorem `mul_add` (a b c : G) : a * (b + c) = a * b + a * c\n* theorem `mul_add_one` (a b : G) : a * (b + 1) = a * b + a\n\n-/\n\nexample (n m : \u2115) (hyp_n : odd n) (hyp_m : odd m) : even (n + m) :=\nbegin\n  obtain \u27e8k, relation_k_n\u27e9 := hyp_n,\n  obtain \u27e8\u2113, relation_\u2113_m\u27e9 := hyp_m,\n  rw relation_k_n,\n  rw relation_\u2113_m,\n  rw add_add_add_comm,\n  rw one_add_one_eq_two,\n  rw \u2190 mul_add,\n  rw \u2190 mul_add_one,\n  use (k + \u2113 + 1),\nend\n\n\n\n\n\n\n\n\n\n\n-- **Example 3** --\n\n/-- To play with some topology, observe that the library contains the following\n* `definition` continuous_def {f : \u03b1 \u2192 \u03b2} : continuous f \u2194\n  (\u2200s, is_open s \u2192 is_open (f \u207b\u00b9' s))\n\nfrom which we deduce (= the system automatically constructs) the \n***Modus Ponens*** variant\n* `lemma` continuous_def.mp {f : \u03b1 \u2192 \u03b2} : continuous f \u2192\n  (\u2200s, is_open s \u2192 is_open (f \u207b\u00b9' s))\n-/\n\nvariables {X Y Z : Type}\n\nexample [topological_space X] [topological_space Y] [topological_space Z]\n(f : X \u2192 Y) (g : Y \u2192 Z) (hyp_f : continuous f) (hyp_g : continuous g) :\ncontinuous (g \u2218 f : X \u2192 Z) :=\nbegin\n  -- continuity,\n  -- exact continuous.comp hyp_g hyp_f,\n  rewrite continuous_def,\n  intros W hW,\n  let V := g\u207b\u00b9' W,\n  have hV : is_open V,\n  exact continuous_def.mp hyp_g W hW,\n  let U := f\u207b\u00b9' V,\n  have hU : is_open U,\n  exact continuous_def.mp hyp_f V hV,\n  exact hU,\nend\n\n\n\n\n\n\n\n\n\nend vilnius", "meta": {"author": "faenuccio", "repo": "May22_Vilnius", "sha": "2ff937dc7568e6118473b1e7f479ccb2a5fa9767", "save_path": "github-repos/lean/faenuccio-May22_Vilnius", "path": "github-repos/lean/faenuccio-May22_Vilnius/May22_Vilnius-2ff937dc7568e6118473b1e7f479ccb2a5fa9767/src/Z_Introduction/fae_solutions/colloquium.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7119674675939305}}
{"text": "import \u00ab05_lib\u00bb\n\n/-\nCe fichier concerne la d\u00e9finition de limite d'une suite (de nombres r\u00e9els).\nUne suite u est une fonction de \u2115 dans \u211d, Lean \u00e9crit donc u : \u2115 \u2192 \u211d\n-/\n\n\n-- D\u00e9finition de \u00ab u tend vers l \u00bb\ndef limite_suite (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\n/-\nOn notera dans la d\u00e9finition ci-dessus l'utilisation de \u00ab \u2200 \u03b5 > 0, ... \u00bb\nqui est une abbr\u00e9viation de \u00ab \u2200 \u03b5, \u03b5 > 0 \u2192 ... \u00bb.\n\nEn particulier un \u00e9nonc\u00e9 de la forme \u00ab h : \u2200 \u03b5 > 0, ... \u00bb se sp\u00e9cialise \u00e0\nun \u03b5\u2080 fix\u00e9 par la commande \u00ab specialize h \u03b5\u2080 h\u03b5\u2080 \u00bb o\u00f9 h\u03b5\u2080 est une d\u00e9monstration\nde \u03b5\u2080 > 0.\n\nAstuce : partout o\u00f9 Lean attend une hypoth\u00e8se, on peut commencer une\nd\u00e9monstration \u00e0 l'aide du mot clef \u00ab by\u00a0\u00bb, suivie de la d\u00e9monstration (entour\u00e9e\nd'accolades si elle comporte plusieurs commandes).\nPar exemple, si le contexte contient\n\n\u03b4 : \u211d\n\u03b4_pos : \u03b4 > 0\nh : \u2200 \u03b5 > 0, ...\n\non peut sp\u00e9cialiser l'\u00e9nonc\u00e9 quantifi\u00e9 h au r\u00e9el \u03b4/2 en tapant\nspecialize h (\u03b4/2) (by linarith)\no\u00f9 \u00ab by linarith \u00bb fournit la d\u00e9monstration de \u03b4/2 > 0 attendue par Lean.\n-/\n\n-- Dans toute la suite, u, v et w sont des suites tandis que l et l' sont des\n-- nombres r\u00e9els\nvariables (u v w : \u2115 \u2192 \u211d) (l l' : \u211d)\n\n-- Si u est constante de valeur l, alors u tend vers l\nexample : (\u2200 n, u n = l) \u2192 limite_suite u l :=\nbegin\n  sorry\nend\n\n/- Concernant les valeurs absolues, on pourra utiliser les lemmes\n\nabs_inferieur_ssi (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nineg_triangle (x y : \u211d) : |x + y| \u2264 |x| + |y|\n\nabs_diff (x y : \u211d) : |x - y| = |y - x|\n\nIl est conseill\u00e9 de noter ces lemmes sur une feuille car ils\npeuvent \u00eatre utiles dans chaque exercice.\n-/\n\n-- Si u tend vers l strictement positif, alors u n \u2265 l/2 pour n assez grand.\nexample (hl : l > 0) : limite_suite u l \u2192 \u2203 N, \u2200 n \u2265 N, u n \u2265 l/2 :=\nbegin\n  sorry\nend\n\n/- Concernant le maximum de deux nombres, on pourra utiliser les lemmes\n\nsuperieur_max_ssi (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\ninferieur_max_gauche p q : p \u2264 max p q\n\ninferieur_max_droite p q : q \u2264 max p q\n\nIl est conseill\u00e9 de noter ces lemmes sur une feuille car ils\npeuvent \u00eatre utiles dans chaque exercice.\n-/\n\n-- Si u tend vers l et v tend vers l' alors u+v tend vers l+l'\nexample (hu : limite_suite u l) (hv : limite_suite v l') :\nlimite_suite (u + v) (l + l') :=\nbegin\n  -- Soit \u03b5 un r\u00e9el strictement positif\n  intros \u03b5 \u03b5_pos,\n  -- L'hypoth\u00e8se de limite sur u, appliqu\u00e9e au r\u00e9el strictement positif \u03b5/2,\n  -- fournit un entier N\u2081 tel \u2200 n \u2265 N\u2081, |u n - l| \u2264 \u03b5 / 2\n  cases hu (\u03b5/2) (by linarith) with N\u2081 hN\u2081,\n  -- L'hypoth\u00e8se de limite sur v, appliqu\u00e9e au r\u00e9el strictement positif \u03b5/2,\n  -- fournit un entier N\u2082 tel \u2200 n \u2265 N\u2082, |v n - l| \u2264 \u03b5 / 2\n  cases hv (\u03b5/2) (by linarith) with N\u2082 hN\u2082,\n  -- On veut un entier N tel que \u2200 n \u2265 N, |(u+v) n - (l+l')| \u2264 \u03b5\n  -- Montrons que max N\u2081 N\u2082 convient.\n  use max N\u2081 N\u2082,\n  -- Soit n \u2265 max N\u2081 N\u2082\n  intros n hn,\n  -- Par d\u00e9finition du max, n \u2265 N\u2081 et n \u2265 N\u2082\n  rw superieur_max_ssi at hn,\n  cases hn with hn\u2081 hn\u2082,\n  -- Donc |u n - l| \u2264 \u03b5/2\n  have fait\u2081 : |u n - l| \u2264 \u03b5/2,\n    apply hN\u2081,\n    linarith,\n  -- et |v n - l| \u2264 \u03b5/2\n  have fait\u2082 : |v n - l'| \u2264 \u03b5/2,\n    exact hN\u2082 n (by linarith),  -- Notez la variante Lean par rapport \u00e0 fait\u2081\n  -- On peut alors calculer.\n  calc\n  |(u + v) n - (l + l')| = |(u n -l) + (v n -l')| : by compute\n                     ... \u2264 |u n - l| + |v n - l'| : by apply ineg_triangle\n                     ... \u2264  \u03b5/2 + \u03b5/2             : by linarith\n                     ... =  \u03b5                     : by compute,\nend\n\nexample (hu : limite_suite u l) (hw : limite_suite w l)\n(h : \u2200 n, u n \u2264 v n)\n(h' : \u2200 n, v n \u2264 w n) : limite_suite v l :=\nbegin\n  sorry\n\nend\n\n-- La derni\u00e8re in\u00e9galit\u00e9 dans la d\u00e9finition de limite peut \u00eatre remplac\u00e9e par\n-- une in\u00e9galit\u00e9 stricte.\nexample (u l) : limite_suite u l \u2194\n \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| < \u03b5 :=\nbegin\n  sorry\nend\n\n/- Dans l'exercice suivant, on pourra utiliser le lemme\n\negal_si_abs_eps (x y : \u211d) : (\u2200 \u03b5 > 0, |x - y| \u2264 \u03b5) \u2192 x = y\n-/\n\n-- Une suite u admet au plus une limite\nexample : limite_suite u l \u2192 limite_suite u l' \u2192 l = l' :=\nbegin\n  sorry\nend\n\n-- D\u00e9finition de \u00ab la suite u est croissante \u00bb\ndef croissante (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- D\u00e9finition de \u00ab M est borne sup\u00e9rieure des termes de la suite u  \u00bb\ndef est_borne_sup (M : \u211d) (u : \u2115 \u2192 \u211d) :=\n(\u2200 n, u n \u2264 M) \u2227 \u2200 \u03b5 > 0, \u2203 n\u2080, u n\u2080 \u2265 M - \u03b5\n\n-- Toute suite croissante ayant une borne sup\u00e9rieure tend vers cette borne\nexample (M : \u211d) (h : est_borne_sup M u) (h' : croissante u) :\nlimite_suite u M :=\nbegin\n  sorry\nend\n\n\n", "meta": {"author": "dEAduction", "repo": "dEAduction-lean", "sha": "4fe1d642078fc94f9081ccbed08e047e86a741fd", "save_path": "github-repos/lean/dEAduction-dEAduction-lean", "path": "github-repos/lean/dEAduction-dEAduction-lean/dEAduction-lean-4fe1d642078fc94f9081ccbed08e047e86a741fd/PM/05/exos/05_limite_suite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7119528297635837}}
{"text": "/-\nCopyright (c) 2021 Alex J. Best. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex J. Best\n-/\nimport data.set.pointwise\nimport group_theory.group_action.pi\n\n/-!\n# Pointwise actions on sets in Pi types\n\nThis file contains lemmas about pointwise actions on sets in Pi types.\n\n## Tags\n\nset multiplication, set addition, pointwise addition, pointwise multiplication, pi\n\n-/\n\nopen_locale pointwise\nopen set\n\nvariables {K \u03b9 : Type*} {R : \u03b9 \u2192 Type*}\n\n@[to_additive]\nlemma smul_pi_subset [\u2200 i, has_smul K (R i)] (r : K) (s : set \u03b9) (t : \u03a0 i, set (R i)) :\n  r \u2022 pi s t \u2286 pi s (r \u2022 t) :=\nbegin\n  rintros x \u27e8y, h, rfl\u27e9 i hi,\n  exact smul_mem_smul_set (h i hi),\nend\n\n@[to_additive]\nlemma smul_univ_pi [\u2200 i, has_smul K (R i)] (r : K) (t : \u03a0 i, set (R i)) :\n  r \u2022 pi (univ : set \u03b9) t = pi (univ : set \u03b9) (r \u2022 t) :=\nsubset.antisymm (smul_pi_subset _ _ _) $ \u03bb x h, begin\n  refine \u27e8\u03bb i, classical.some (h i $ set.mem_univ _), \u03bb i hi, _, funext $ \u03bb i, _\u27e9,\n  { exact (classical.some_spec (h i _)).left, },\n  { exact (classical.some_spec (h i _)).right, },\nend\n\n@[to_additive]\nlemma smul_pi [group K] [\u2200 i, mul_action K (R i)] (r : K) (S : set \u03b9) (t : \u03a0 i, set (R i)) :\n  r \u2022 S.pi t = S.pi (r \u2022 t) :=\nsubset.antisymm (smul_pi_subset _ _ _) $ \u03bb x h,\n  \u27e8r\u207b\u00b9 \u2022 x, \u03bb i hiS, mem_smul_set_iff_inv_smul_mem.mp (h i hiS), smul_inv_smul _ _\u27e9\n\nlemma smul_pi\u2080 [group_with_zero K] [\u2200 i, mul_action K (R i)] {r : K} (S : set \u03b9)\n  (t : \u03a0 i, set (R i)) (hr : r \u2260 0) : r \u2022 S.pi t = S.pi (r \u2022 t) :=\nsmul_pi (units.mk0 r hr) S t\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/algebra/module/pointwise_pi.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7119528281719393}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    s \u2286 f \u207b\u00b9' (f '' s)\n-- ----------------------------------------------------------------------\n\nimport data.set.function\n\nuniverses u v\nvariable  \u03b1 : Type u\nvariable  \u03b2 : Type v\nvariable  f : \u03b1 \u2192 \u03b2\nvariables s t : set \u03b1\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nbegin\n  intros x xs,\n  show f x \u2208 f '' s,\n  use [x, xs],\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u,\n\u03b2 : Type v,\nf : \u03b1 \u2192 \u03b2,\ns : set \u03b1\n\u22a2 s \u2286 f \u207b\u00b9' (f '' s)\n  >> intros x xs,\nx : \u03b1,\nxs : x \u2208 s\n\u22a2 x \u2208 f \u207b\u00b9' (f '' s)\n  >> show f x \u2208 f '' s,\n\u22a2 f x \u2208 f '' s\n  >> use [x, xs],\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2286 f \u207b\u00b9' (f '' s) :=\nbegin\n  intros x xs,\n  show f x \u2208 f '' s,\n  apply set.mem_image_of_mem f xs,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u,\n\u03b2 : Type v,\nf : \u03b1 \u2192 \u03b2,\ns : set \u03b1\n\u22a2 s \u2286 f \u207b\u00b9' (f '' s)\n  >> intros x xs,\nx : \u03b1,\nxs : x \u2208 s\n\u22a2 x \u2208 f \u207b\u00b9' (f '' s)\n  >> show f x \u2208 f '' s,\n\u22a2 f x \u2208 f '' s\n  >> apply set.mem_image_of_mem f xs,\nno goals\n-/\n\n-- Comentario: Se ha usado el lema\n-- + set.mem_image_of_mem : x \u2208 a \u2192 f x \u2208 f '' a\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Primagen_de_imagen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7119528198206182}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\nThe order relation on the integers.\n-/\nimport Mathlib.Init.Data.Int.Basic\nimport Mathlib.Algebra.Ring.Basic\n\nnamespace Int\n\ntheorem nonneg_def {a : \u2124} : NonNeg a \u2194 \u2203 n : \u2115, a = n :=\n  \u27e8fun \u27e8n\u27e9 => \u27e8n, rfl\u27e9, fun h => match a, h with | _, \u27e8n, rfl\u27e9 => \u27e8n\u27e9\u27e9\n\nlemma NonNeg.elim {a : \u2124} : NonNeg a \u2192 \u2203 n : \u2115, a = n := nonneg_def.1\n\nlemma nonneg_or_nonneg_neg (a : \u2124) : NonNeg a \u2228 NonNeg (-a) :=\nmatch a with | ofNat n => Or.inl \u27e8_\u27e9 | negSucc n => Or.inr \u27e8_\u27e9\n\ntheorem le_def (a b : \u2124) : a \u2264 b \u2194 NonNeg (b - a) := Iff.refl _\n\ntheorem lt_iff_add_one_le (a b : \u2124) : a < b \u2194 (a+1) \u2264 b := Iff.refl _\n\ntheorem le.intro_sub {a b : \u2124} (n : \u2115) (h : b - a = n) : a \u2264 b := by\n  simp [le_def, h]; constructor\n\nattribute [local simp] Int.sub_eq_add_neg Int.add_assoc Int.add_right_neg\n  Int.add_left_neg Int.zero_add Int.add_zero Int.neg_add Int.neg_neg Int.neg_zero\n\ntheorem le.intro {a b : \u2124} (n : \u2115) (h : a + n = b) : a \u2264 b :=\n  le.intro_sub n $ by rw [\u2190 h, Int.add_comm]; simp\n\ntheorem le.dest_sub {a b : \u2124} (h : a \u2264 b) : \u2203 n : \u2115, b - a = n := nonneg_def.1 h\n\ntheorem le.dest {a b : \u2124} (h : a \u2264 b) : \u2203 n : \u2115, a + n = b :=\n  let \u27e8n, h\u2081\u27e9 := le.dest_sub h\n  \u27e8n, by rw [\u2190 h\u2081, Int.add_comm]; simp\u27e9\n\nprotected theorem le_total (a b : \u2124) : a \u2264 b \u2228 b \u2264 a :=\n  (nonneg_or_nonneg_neg (b - a)).imp_right fun H => by\n    rwa [(by simp [Int.add_comm] : -(b - a) = a - b)] at H\n\n@[simp, norm_cast] theorem ofNat_le {m n : \u2115} : (\u2191m : \u2124) \u2264 \u2191n \u2194 m \u2264 n :=\n  \u27e8fun h =>\n    let \u27e8k, hk\u27e9 := le.dest h\n    Nat.le.intro $ Int.ofNat.inj $ (Int.ofNat_add m k).trans hk,\n  fun h =>\n    let \u27e8k, (hk : m + k = n)\u27e9 := Nat.le.dest h\n    le.intro k (by rw [\u2190 hk]; rfl)\u27e9\n\ntheorem ofNat_zero_le (n : \u2115) : 0 \u2264 (\u2191n : \u2124) := ofNat_le.2 n.zero_le\n\ntheorem eq_ofNat_of_zero_le {a : \u2124} (h : 0 \u2264 a) : \u2203 n : \u2115, a = n := by\n  have t := le.dest_sub h; simp at t; exact t\n\ntheorem eq_succ_of_zero_lt {a : \u2124} (h : 0 < a) : \u2203 n : \u2115, a = n.succ :=\n  let \u27e8n, (h : 1 + n = a)\u27e9 := le.dest h\n  \u27e8n, by rw [Nat.add_comm] at h <;> exact h.symm\u27e9\n\ntheorem lt_add_succ (a : \u2124) (n : \u2115) : a < a + Nat.succ n :=\n  le.intro n $ by rw [Int.add_comm, Int.add_left_comm]; rfl\n\ntheorem lt.intro {a b : \u2124} {n : \u2115} (h : a + Nat.succ n = b) : a < b :=\n  h \u25b8 lt_add_succ a n\n\ntheorem lt.dest {a b : \u2124} (h : a < b) : \u2203 n : \u2115, a + Nat.succ n = b :=\n  (le.dest h).imp fun n h => by\n    rwa [Int.add_comm, Int.add_left_comm] at h\n\n@[simp, norm_cast] theorem ofNat_lt {n m : \u2115} : (\u2191n : \u2124) < \u2191m \u2194 n < m := by\n  rw [lt_iff_add_one_le, \u2190 Nat.cast_succ, ofNat_le]; rfl\n\ntheorem ofNat_nonneg (n : \u2115) : 0 \u2264 ofNat n := \u27e8_\u27e9\n\ntheorem ofNat_succ_pos (n : Nat) : 0 < (Nat.succ n : \u2124) := ofNat_lt.2 $ Nat.succ_pos _\n\nprotected theorem le_refl (a : \u2124) : a \u2264 a :=\n  le.intro _ (Int.add_zero a)\n\nprotected theorem le_trans {a b c : \u2124} (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : a \u2264 c :=\n  let \u27e8n, hn\u27e9 := le.dest h\u2081; let \u27e8m, hm\u27e9 := le.dest h\u2082\n  le.intro (n + m) $ by rw [\u2190 hm, \u2190 hn, Int.add_assoc, Nat.cast_add]\n\nprotected theorem le_antisymm {a b : \u2124} (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 a) : a = b := by\n  let \u27e8n, hn\u27e9 := le.dest h\u2081; let \u27e8m, hm\u27e9 := le.dest h\u2082\n  have := hn; rw [\u2190 hm, Int.add_assoc, \u2190 Nat.cast_add] at this\n  have := Int.ofNat.inj $ Int.add_left_cancel $ this.trans (Int.add_zero _).symm\n  rw [\u2190 hn, Nat.eq_zero_of_add_eq_zero_left this, Nat.cast_zero, Int.add_zero a]\n\nprotected theorem lt_irrefl (a : \u2124) : \u00aca < a := fun H =>\n  let \u27e8n, hn\u27e9 := lt.dest H\n  have : (a+Nat.succ n) = a+0 := by\n    rw [hn, Int.add_zero]\n  have : Nat.succ n = 0 := Int.coe_nat_inj (Int.add_left_cancel this)\n  show False from Nat.succ_ne_zero _ this\n\nprotected theorem ne_of_lt {a b : \u2124} (h : a < b) : a \u2260 b := fun e => by\n  cases e; exact Int.lt_irrefl _ h\n\ntheorem le_of_lt {a b : \u2124} (h : a < b) : a \u2264 b :=\n  let \u27e8n, hn\u27e9 := lt.dest h; le.intro _ hn\n\nprotected theorem lt_iff_le_and_ne {a b : \u2124} : a < b \u2194 a \u2264 b \u2227 a \u2260 b := by\n  refine \u27e8fun h => \u27e8le_of_lt h, Int.ne_of_lt h\u27e9, fun \u27e8aleb, aneb\u27e9 => ?_\u27e9\n  let \u27e8n, hn\u27e9 := le.dest aleb\n  have : n \u2260 0 := aneb.imp fun this' => by\n    rw [\u2190 hn, this', Nat.cast_zero, Int.add_zero]\n  exact lt.intro $ by rwa [\u2190 Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero this)] at hn\n\ntheorem lt_succ (a : \u2124) : a < a + 1 := Int.le_refl (a + 1)\n\nprotected theorem add_le_add_left {a b : \u2124} (h : a \u2264 b) (c : \u2124) : c + a \u2264 c + b :=\n  let \u27e8n, hn\u27e9 := le.dest h; le.intro n $ by rw [Int.add_assoc, hn]\n\nprotected theorem add_lt_add_left {a b : \u2124} (h : a < b) (c : \u2124) : c + a < c + b := by\n  refine Int.lt_iff_le_and_ne.2 \u27e8Int.add_le_add_left (le_of_lt h) _, fun heq => ?_\u27e9\n  exact Int.lt_irrefl b $ by rwa [Int.add_left_cancel heq] at h\n\nprotected theorem mul_nonneg {a b : \u2124} (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a * b := by\n  let \u27e8n, hn\u27e9 := eq_ofNat_of_zero_le ha\n  let \u27e8m, hm\u27e9 := eq_ofNat_of_zero_le hb\n  rw [hn, hm, \u2190 Nat.cast_mul]; exact ofNat_nonneg _\n\nprotected theorem mul_pos {a b : \u2124} (ha : 0 < a) (hb : 0 < b) : 0 < a * b := by\n  let \u27e8n, hn\u27e9 := eq_succ_of_zero_lt ha\n  let \u27e8m, hm\u27e9 := eq_succ_of_zero_lt hb\n  rw [hn, hm, \u2190 Nat.cast_mul]; exact ofNat_succ_pos _\n\nprotected theorem zero_lt_one : (0 : \u2124) < 1 := \u27e8_\u27e9\n\nprotected theorem lt_iff_le_not_le {a b : \u2124} : a < b \u2194 a \u2264 b \u2227 \u00acb \u2264 a := by\n  rw [Int.lt_iff_le_and_ne]\n  constructor <;> refine fun \u27e8h, h'\u27e9 => \u27e8h, h'.imp fun h' => ?_\u27e9\n  \u00b7 exact Int.le_antisymm h h'\n  \u00b7 subst h'; apply Int.le_refl\n\ninstance : LinearOrder Int where\n  le := (\u00b7\u2264\u00b7)\n  le_refl := Int.le_refl\n  le_trans := @Int.le_trans\n  le_antisymm := @Int.le_antisymm\n  lt := (\u00b7<\u00b7)\n  lt_iff_le_not_le := @Int.lt_iff_le_not_le\n  le_total := Int.le_total\n  decidable_eq := by infer_instance\n  decidable_le := by infer_instance\n  decidable_lt := by infer_instance\n\ntheorem eq_natAbs_of_zero_le {a : \u2124} (h : 0 \u2264 a) : a = natAbs a := by\n  let \u27e8n, e\u27e9 := eq_ofNat_of_zero_le h\n  rw [e]; rfl\n\ntheorem le_natAbs {a : \u2124} : a \u2264 natAbs a :=\n  Or.elim (le_total 0 a)\n    (fun h => by rw [eq_natAbs_of_zero_le h]; apply Int.le_refl)\n    fun h => le_trans h (ofNat_zero_le _)\n\ntheorem neg_succ_lt_zero (n : \u2115) : -[1+ n] < 0 :=\n  lt_of_not_ge $ fun h => by\n    let \u27e8m, h\u27e9 := eq_ofNat_of_zero_le h\n    contradiction\n\ntheorem eq_neg_succ_of_lt_zero : \u2200 {a : \u2124}, a < 0 \u2192 \u2203 n : \u2115, a = -[1+ n]\n  | (n : \u2115), h => absurd h (not_lt_of_ge (ofNat_zero_le _))\n  | -[1+ n], h => \u27e8n, rfl\u27e9\n\nprotected theorem eq_neg_of_eq_neg {a b : \u2124} (h : a = -b) : b = -a := by\n  rw [h, Int.neg_neg]\n\nprotected theorem neg_add_cancel_left (a b : \u2124) : -a + (a + b) = b := by\n  rw [\u2190 Int.add_assoc, Int.add_left_neg, Int.zero_add]\n\nprotected theorem add_neg_cancel_left (a b : \u2124) : a + (-a + b) = b := by\n  rw [\u2190 Int.add_assoc, Int.add_right_neg, Int.zero_add]\n\nprotected theorem add_neg_cancel_right (a b : \u2124) : a + b + -b = a := by\n  rw [Int.add_assoc, Int.add_right_neg, Int.add_zero]\n\nprotected theorem neg_add_cancel_right (a b : \u2124) : a + -b + b = a := by\n  rw [Int.add_assoc, Int.add_left_neg, Int.add_zero]\n\nprotected theorem sub_self (a : \u2124) : a - a = 0 := by\n  rw [Int.sub_eq_add_neg, Int.add_right_neg]\n\nprotected theorem sub_eq_zero_of_eq {a b : \u2124} (h : a = b) : a - b = 0 := by\n  rw [h, Int.sub_self]\n\nprotected theorem eq_of_sub_eq_zero {a b : \u2124} (h : a - b = 0) : a = b := by\n  have : 0 + b = b := by rw [Int.zero_add]\n  have : a - b + b = b := by rwa [h]\n  rwa [Int.sub_eq_add_neg, Int.neg_add_cancel_right] at this\n\nprotected theorem sub_eq_zero_iff_eq {a b : \u2124} : a - b = 0 \u2194 a = b :=\n  \u27e8Int.eq_of_sub_eq_zero, Int.sub_eq_zero_of_eq\u27e9\n\n@[simp] protected theorem neg_eq_of_add_eq_zero {a b : \u2124} (h : a + b = 0) : -a = b := by\n  rw [\u2190 Int.add_zero (-a), \u2190 h, \u2190 Int.add_assoc, Int.add_left_neg, Int.zero_add]\n\nprotected theorem neg_mul_eq_neg_mul (a b : \u2124) : -(a * b) = -a * b :=\n  Int.neg_eq_of_add_eq_zero $ by\n    rw [\u2190 Int.distrib_right, Int.add_right_neg, Int.zero_mul]\n\nprotected theorem neg_mul_eq_mul_neg (a b : \u2124) : -(a * b) = a * -b :=\n  Int.neg_eq_of_add_eq_zero $ by\n    rw [\u2190 Int.distrib_left, Int.add_right_neg, Int.mul_zero]\n\ntheorem neg_mul_eq_neg_mul_symm (a b : \u2124) : -a * b = -(a * b) :=\n  (Int.neg_mul_eq_neg_mul a b).symm\n\ntheorem mul_neg_eq_neg_mul_symm (a b : \u2124) : a * -b = -(a * b) :=\n  (Int.neg_mul_eq_mul_neg a b).symm\n\nattribute [local simp] neg_mul_eq_neg_mul_symm mul_neg_eq_neg_mul_symm\n\nprotected theorem neg_mul_neg (a b : \u2124) : -a * -b = a * b := by simp\n\nprotected theorem neg_mul_comm (a b : \u2124) : -a * b = a * -b := by simp\n\nprotected theorem mul_sub (a b c : \u2124) : a * (b - c) = a * b - a * c :=\n  calc\n    a * (b - c) = a * b + a * -c := Int.distrib_left a b (-c)\n    _ = a * b - a * c := by simp\n\nprotected theorem sub_mul (a b c : \u2124) : (a - b) * c = a * c - b * c :=\n  calc\n    (a - b) * c = a * c + -b * c := Int.distrib_right a (-b) c\n    _ = a * c - b * c := by simp\n\nprotected theorem le_of_add_le_add_left {a b c : \u2124} (h : a + b \u2264 a + c) : b \u2264 c := by\n  have : -a + (a + b) \u2264 -a + (a + c) := Int.add_le_add_left h _\n  simp [Int.neg_add_cancel_left] at this\n  assumption\n\nprotected theorem lt_of_add_lt_add_left {a b c : \u2124} (h : a + b < a + c) : b < c := by\n  have : -a + (a + b) < -a + (a + c) := Int.add_lt_add_left h _\n  simp [Int.neg_add_cancel_left] at this\n  assumption\n\nprotected theorem add_le_add_right {a b : \u2124} (h : a \u2264 b) (c : \u2124) : a + c \u2264 b + c :=\n  Int.add_comm c a \u25b8 Int.add_comm c b \u25b8 Int.add_le_add_left h c\n\nprotected theorem add_lt_add_right {a b : \u2124} (h : a < b) (c : \u2124) : a + c < b + c := by\n  rw [Int.add_comm a c, Int.add_comm b c]\n  exact Int.add_lt_add_left h c\n\nprotected theorem add_le_add {a b c d : \u2124} (h\u2081 : a \u2264 b) (h\u2082 : c \u2264 d) : a + c \u2264 b + d :=\n  le_trans (Int.add_le_add_right h\u2081 c) (Int.add_le_add_left h\u2082 b)\n\nprotected theorem le_add_of_nonneg_right {a b : \u2124} (h : 0 \u2264 b) : a \u2264 a + b := by\n  have : a + b \u2265 a + 0 := Int.add_le_add_left h a\n  rwa [Int.add_zero] at this\n\nprotected theorem le_add_of_nonneg_left {a b : \u2124} (h : 0 \u2264 b) : a \u2264 b + a := by\n  have : 0 + a \u2264 b + a := Int.add_le_add_right h a\n  rwa [Int.zero_add] at this\n\nprotected theorem add_lt_add {a b c d : \u2124} (h\u2081 : a < b) (h\u2082 : c < d) : a + c < b + d :=\n  lt_trans (Int.add_lt_add_right h\u2081 c) (Int.add_lt_add_left h\u2082 b)\n\nprotected theorem add_lt_add_of_le_of_lt {a b c d : \u2124} (h\u2081 : a \u2264 b) (h\u2082 : c < d) : a + c < b + d :=\n  lt_of_le_of_lt (Int.add_le_add_right h\u2081 c) (Int.add_lt_add_left h\u2082 b)\n\nprotected theorem add_lt_add_of_lt_of_le {a b c d : \u2124} (h\u2081 : a < b) (h\u2082 : c \u2264 d) : a + c < b + d :=\n  lt_of_lt_of_le (Int.add_lt_add_right h\u2081 c) (Int.add_le_add_left h\u2082 b)\n\nprotected theorem lt_add_of_pos_right (a : \u2124) {b : \u2124} (h : 0 < b) : a < a + b := by\n  have : a + 0 < a + b := Int.add_lt_add_left h a\n  rwa [Int.add_zero] at this\n\nprotected theorem lt_add_of_pos_left (a : \u2124) {b : \u2124} (h : 0 < b) : a < b + a := by\n  have : 0 + a < b + a := Int.add_lt_add_right h a\n  rwa [Int.zero_add] at this\n\nprotected theorem le_of_add_le_add_right {a b c : \u2124} (h : a + b \u2264 c + b) : a \u2264 c :=\n  Int.le_of_add_le_add_left (a := b) $ by rwa [Int.add_comm b a, Int.add_comm b c]\n\nprotected theorem lt_of_add_lt_add_right {a b c : \u2124} (h : a + b < c + b) : a < c :=\n  Int.lt_of_add_lt_add_left (a := b) $ by rwa [Int.add_comm b a, Int.add_comm b c]\n\nprotected theorem add_nonneg {a b : \u2124} (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a + b :=\n  Int.zero_add 0 \u25b8 Int.add_le_add ha hb\n\nprotected theorem add_pos {a b : \u2124} (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=\n  Int.zero_add 0 \u25b8 Int.add_lt_add ha hb\n\nprotected theorem add_pos_of_pos_of_nonneg {a b : \u2124} (ha : 0 < a) (hb : 0 \u2264 b) : 0 < a + b :=\n  Int.zero_add 0 \u25b8 Int.add_lt_add_of_lt_of_le ha hb\n\nprotected theorem add_pos_of_nonneg_of_pos {a b : \u2124} (ha : 0 \u2264 a) (hb : 0 < b) : 0 < a + b :=\n  Int.zero_add 0 \u25b8 Int.add_lt_add_of_le_of_lt ha hb\n\nprotected theorem add_nonpos {a b : \u2124} (ha : a \u2264 0) (hb : b \u2264 0) : a + b \u2264 0 :=\n  Int.zero_add 0 \u25b8 Int.add_le_add ha hb\n\nprotected theorem add_neg {a b : \u2124} (ha : a < 0) (hb : b < 0) : a + b < 0 :=\n  Int.zero_add 0 \u25b8 Int.add_lt_add ha hb\n\nprotected theorem add_neg_of_neg_of_nonpos {a b : \u2124} (ha : a < 0) (hb : b \u2264 0) : a + b < 0 :=\n  Int.zero_add 0 \u25b8 Int.add_lt_add_of_lt_of_le ha hb\n\nprotected theorem add_neg_of_nonpos_of_neg {a b : \u2124} (ha : a \u2264 0) (hb : b < 0) : a + b < 0 :=\n  Int.zero_add 0 \u25b8 Int.add_lt_add_of_le_of_lt ha hb\n\nprotected theorem lt_add_of_le_of_pos {a b c : \u2124} (hbc : b \u2264 c) (ha : 0 < a) : b < c + a :=\n  Int.add_zero b \u25b8 Int.add_lt_add_of_le_of_lt hbc ha\n\nprotected theorem sub_add_cancel (a b : \u2124) : a - b + b = a :=\n  Int.neg_add_cancel_right a b\n\nprotected theorem add_sub_cancel (a b : \u2124) : a + b - b = a :=\n  Int.add_neg_cancel_right a b\n\nprotected theorem add_sub_assoc (a b c : \u2124) : a + b - c = a + (b - c) := by\n  rw [Int.sub_eq_add_neg, Int.add_assoc, \u2190 Int.sub_eq_add_neg]\n\nprotected theorem neg_le_neg {a b : \u2124} (h : a \u2264 b) : -b \u2264 -a := by\n  have : 0 \u2264 -a + b := Int.add_left_neg a \u25b8 Int.add_le_add_left h (-a)\n  have : 0 + -b \u2264 -a + b + -b := Int.add_le_add_right this (-b)\n  rwa [Int.add_neg_cancel_right, Int.zero_add] at this\n\nprotected theorem le_of_neg_le_neg {a b : \u2124} (h : -b \u2264 -a) : a \u2264 b :=\n  suffices - -a \u2264 - -b by simp [Int.neg_neg] at this; assumption\n  Int.neg_le_neg h\n\nprotected theorem nonneg_of_neg_nonpos {a : \u2124} (h : -a \u2264 0) : 0 \u2264 a :=\n  Int.le_of_neg_le_neg $ by rwa [Int.neg_zero]\n\nprotected theorem neg_nonpos_of_nonneg {a : \u2124} (h : 0 \u2264 a) : -a \u2264 0 := by\n  have : -a \u2264 -0 := Int.neg_le_neg h\n  rwa [Int.neg_zero] at this\n\nprotected theorem nonpos_of_neg_nonneg {a : \u2124} (h : 0 \u2264 -a) : a \u2264 0 :=\n  Int.le_of_neg_le_neg $ by rwa [Int.neg_zero]\n\nprotected theorem neg_nonneg_of_nonpos {a : \u2124} (h : a \u2264 0) : 0 \u2264 -a := by\n  have : -0 \u2264 -a := Int.neg_le_neg h\n  rwa [Int.neg_zero] at this\n\nprotected theorem neg_lt_neg {a b : \u2124} (h : a < b) : -b < -a := by\n  have : 0 < -a + b := Int.add_left_neg a \u25b8 Int.add_lt_add_left h (-a)\n  have : 0 + -b < -a + b + -b := Int.add_lt_add_right this (-b)\n  rwa [Int.add_neg_cancel_right, Int.zero_add] at this\n\nprotected theorem lt_of_neg_lt_neg {a b : \u2124} (h : -b < -a) : a < b :=\n  Int.neg_neg a \u25b8 Int.neg_neg b \u25b8 Int.neg_lt_neg h\n\nprotected theorem pos_of_neg_neg {a : \u2124} (h : -a < 0) : 0 < a :=\n  Int.lt_of_neg_lt_neg $ by rwa [Int.neg_zero]\n\nprotected theorem neg_neg_of_pos {a : \u2124} (h : 0 < a) : -a < 0 := by\n  have : -a < -0 := Int.neg_lt_neg h\n  rwa [Int.neg_zero] at this\n\nprotected theorem neg_of_neg_pos {a : \u2124} (h : 0 < -a) : a < 0 :=\n  have : -0 < -a := by rwa [Int.neg_zero]\n  Int.lt_of_neg_lt_neg this\n\nprotected theorem neg_pos_of_neg {a : \u2124} (h : a < 0) : 0 < -a := by\n  have : -0 < -a := Int.neg_lt_neg h\n  rwa [Int.neg_zero] at this\n\nprotected theorem le_neg_of_le_neg {a b : \u2124} (h : a \u2264 -b) : b \u2264 -a := by\n  have h := Int.neg_le_neg h\n  rwa [Int.neg_neg] at h\n\nprotected theorem neg_le_of_neg_le {a b : \u2124} (h : -a \u2264 b) : -b \u2264 a := by\n  have h := Int.neg_le_neg h\n  rwa [Int.neg_neg] at h\n\nprotected theorem lt_neg_of_lt_neg {a b : \u2124} (h : a < -b) : b < -a := by\n  have h := Int.neg_lt_neg h\n  rwa [Int.neg_neg] at h\n\nprotected theorem neg_lt_of_neg_lt {a b : \u2124} (h : -a < b) : -b < a := by\n  have h := Int.neg_lt_neg h\n  rwa [Int.neg_neg] at h\n\nprotected theorem sub_nonneg_of_le {a b : \u2124} (h : b \u2264 a) : 0 \u2264 a - b := by\n  have h := Int.add_le_add_right h (-b)\n  rwa [Int.add_right_neg] at h\n\nprotected theorem le_of_sub_nonneg {a b : \u2124} (h : 0 \u2264 a - b) : b \u2264 a := by\n  have h := Int.add_le_add_right h b\n  rwa [Int.sub_add_cancel, Int.zero_add] at h\n\nprotected theorem sub_nonpos_of_le {a b : \u2124} (h : a \u2264 b) : a - b \u2264 0 := by\n  have h := Int.add_le_add_right h (-b)\n  rwa [Int.add_right_neg] at h\n\nprotected theorem le_of_sub_nonpos {a b : \u2124} (h : a - b \u2264 0) : a \u2264 b := by\n  have h := Int.add_le_add_right h b\n  rwa [Int.sub_add_cancel, Int.zero_add] at h\n\nprotected theorem sub_pos_of_lt {a b : \u2124} (h : b < a) : 0 < a - b := by\n  have h := Int.add_lt_add_right h (-b)\n  rwa [Int.add_right_neg] at h\n\nprotected theorem lt_of_sub_pos {a b : \u2124} (h : 0 < a - b) : b < a := by\n  have h := Int.add_lt_add_right h b\n  rwa [Int.sub_add_cancel, Int.zero_add] at h\n\nprotected theorem sub_neg_of_lt {a b : \u2124} (h : a < b) : a - b < 0 := by\n  have h := Int.add_lt_add_right h (-b)\n  rwa [Int.add_right_neg] at h\n\nprotected theorem lt_of_sub_neg {a b : \u2124} (h : a - b < 0) : a < b := by\n  have h := Int.add_lt_add_right h b\n  rwa [Int.sub_add_cancel, Int.zero_add] at h\n\nprotected theorem add_le_of_le_neg_add {a b c : \u2124} (h : b \u2264 -a + c) : a + b \u2264 c := by\n  have h := Int.add_le_add_left h a\n  rwa [Int.add_neg_cancel_left] at h\n\nprotected theorem le_neg_add_of_add_le {a b c : \u2124} (h : a + b \u2264 c) : b \u2264 -a + c := by\n  have h := Int.add_le_add_left h (-a)\n  rwa [Int.neg_add_cancel_left] at h\n\nprotected theorem add_le_of_le_sub_left {a b c : \u2124} (h : b \u2264 c - a) : a + b \u2264 c := by\n  have h := Int.add_le_add_left h a\n  rwa [\u2190 Int.add_sub_assoc, Int.add_comm a c, Int.add_sub_cancel] at h\n\nprotected theorem le_sub_left_of_add_le {a b c : \u2124} (h : a + b \u2264 c) : b \u2264 c - a := by\n  have h := Int.add_le_add_right h (-a)\n  rwa [Int.add_comm a b, Int.add_neg_cancel_right] at h\n\nprotected theorem add_le_of_le_sub_right {a b c : \u2124} (h : a \u2264 c - b) : a + b \u2264 c := by\n  have h := Int.add_le_add_right h b\n  rwa [Int.sub_add_cancel] at h\n\nprotected theorem le_sub_right_of_add_le {a b c : \u2124} (h : a + b \u2264 c) : a \u2264 c - b := by\n  have h := Int.add_le_add_right h (-b)\n  rwa [Int.add_neg_cancel_right] at h\n\nprotected theorem le_add_of_neg_add_le {a b c : \u2124} (h : -b + a \u2264 c) : a \u2264 b + c := by\n  have h := Int.add_le_add_left h b\n  rwa [Int.add_neg_cancel_left] at h\n\nprotected theorem neg_add_le_of_le_add {a b c : \u2124} (h : a \u2264 b + c) : -b + a \u2264 c := by\n  have h := Int.add_le_add_left h (-b)\n  rwa [Int.neg_add_cancel_left] at h\n\nprotected theorem le_add_of_sub_left_le {a b c : \u2124} (h : a - b \u2264 c) : a \u2264 b + c := by\n  have h := Int.add_le_add_right h b\n  rwa [Int.sub_add_cancel, Int.add_comm] at h\n\nprotected theorem sub_left_le_of_le_add {a b c : \u2124} (h : a \u2264 b + c) : a - b \u2264 c := by\n  have h := Int.add_le_add_right h (-b)\n  rwa [Int.add_comm b c, Int.add_neg_cancel_right] at h\n\nprotected theorem le_add_of_sub_right_le {a b c : \u2124} (h : a - c \u2264 b) : a \u2264 b + c := by\n  have h := Int.add_le_add_right h c\n  rwa [Int.sub_add_cancel] at h\n\nprotected theorem sub_right_le_of_le_add {a b c : \u2124} (h : a \u2264 b + c) : a - c \u2264 b := by\n  have h := Int.add_le_add_right h (-c)\n  rwa [Int.add_neg_cancel_right] at h\n\nprotected theorem le_add_of_neg_add_le_left {a b c : \u2124} (h : -b + a \u2264 c) : a \u2264 b + c := by\n  rw [Int.add_comm] at h\n  exact Int.le_add_of_sub_left_le h\n\nprotected theorem neg_add_le_left_of_le_add {a b c : \u2124} (h : a \u2264 b + c) : -b + a \u2264 c := by\n  rw [Int.add_comm]\n  exact Int.sub_left_le_of_le_add h\n\nprotected theorem le_add_of_neg_add_le_right {a b c : \u2124} (h : -c + a \u2264 b) : a \u2264 b + c := by\n  rw [Int.add_comm] at h\n  exact Int.le_add_of_sub_right_le h\n\nprotected theorem neg_add_le_right_of_le_add {a b c : \u2124} (h : a \u2264 b + c) : -c + a \u2264 b := by\n  rw [Int.add_comm] at h\n  exact Int.neg_add_le_left_of_le_add h\n\nprotected theorem le_add_of_neg_le_sub_left {a b c : \u2124} (h : -a \u2264 b - c) : c \u2264 a + b :=\n  Int.le_add_of_neg_add_le_left (Int.add_le_of_le_sub_right h)\n\nprotected theorem neg_le_sub_left_of_le_add {a b c : \u2124} (h : c \u2264 a + b) : -a \u2264 b - c := by\n  have h := Int.le_neg_add_of_add_le (Int.sub_left_le_of_le_add h)\n  rwa [Int.add_comm] at h\n\nprotected theorem le_add_of_neg_le_sub_right {a b c : \u2124} (h : -b \u2264 a - c) : c \u2264 a + b :=\n  Int.le_add_of_sub_right_le (Int.add_le_of_le_sub_left h)\n\nprotected theorem neg_le_sub_right_of_le_add {a b c : \u2124} (h : c \u2264 a + b) : -b \u2264 a - c :=\n  Int.le_sub_left_of_add_le (Int.sub_right_le_of_le_add h)\n\nprotected theorem sub_le_of_sub_le {a b c : \u2124} (h : a - b \u2264 c) : a - c \u2264 b :=\n  Int.sub_left_le_of_le_add (Int.le_add_of_sub_right_le h)\n\nprotected theorem sub_le_sub_left {a b : \u2124} (h : a \u2264 b) (c : \u2124) : c - b \u2264 c - a :=\n  Int.add_le_add_left (Int.neg_le_neg h) c\n\nprotected theorem sub_le_sub_right {a b : \u2124} (h : a \u2264 b) (c : \u2124) : a - c \u2264 b - c :=\n  Int.add_le_add_right h (-c)\n\nprotected theorem sub_le_sub {a b c d : \u2124} (hab : a \u2264 b) (hcd : c \u2264 d) : a - d \u2264 b - c :=\n  Int.add_le_add hab (Int.neg_le_neg hcd)\n\nprotected theorem add_lt_of_lt_neg_add {a b c : \u2124} (h : b < -a + c) : a + b < c := by\n  have h := Int.add_lt_add_left h a\n  rwa [Int.add_neg_cancel_left] at h\n\nprotected theorem lt_neg_add_of_add_lt {a b c : \u2124} (h : a + b < c) : b < -a + c := by\n  have h := Int.add_lt_add_left h (-a)\n  rwa [Int.neg_add_cancel_left] at h\n\nprotected theorem add_lt_of_lt_sub_left {a b c : \u2124} (h : b < c - a) : a + b < c := by\n  have h := Int.add_lt_add_left h a\n  rwa [\u2190 Int.add_sub_assoc, Int.add_comm a c, Int.add_sub_cancel] at h\n\nprotected theorem lt_sub_left_of_add_lt {a b c : \u2124} (h : a + b < c) : b < c - a := by\n  have h := Int.add_lt_add_right h (-a)\n  rwa [Int.add_comm a b, Int.add_neg_cancel_right] at h\n\nprotected theorem add_lt_of_lt_sub_right {a b c : \u2124} (h : a < c - b) : a + b < c := by\n  have h := Int.add_lt_add_right h b\n  rwa [Int.sub_add_cancel] at h\n\nprotected theorem lt_sub_right_of_add_lt {a b c : \u2124} (h : a + b < c) : a < c - b := by\n  have h := Int.add_lt_add_right h (-b)\n  rwa [Int.add_neg_cancel_right] at h\n\nprotected theorem lt_add_of_neg_add_lt {a b c : \u2124} (h : -b + a < c) : a < b + c := by\n  have h := Int.add_lt_add_left h b\n  rwa [Int.add_neg_cancel_left] at h\n\nprotected theorem neg_add_lt_of_lt_add {a b c : \u2124} (h : a < b + c) : -b + a < c := by\n  have h := Int.add_lt_add_left h (-b)\n  rwa [Int.neg_add_cancel_left] at h\n\nprotected theorem lt_add_of_sub_left_lt {a b c : \u2124} (h : a - b < c) : a < b + c := by\n  have h := Int.add_lt_add_right h b\n  rwa [Int.sub_add_cancel, Int.add_comm] at h\n\nprotected theorem sub_left_lt_of_lt_add {a b c : \u2124} (h : a < b + c) : a - b < c := by\n  have h := Int.add_lt_add_right h (-b)\n  rwa [Int.add_comm b c, Int.add_neg_cancel_right] at h\n\nprotected theorem lt_add_of_sub_right_lt {a b c : \u2124} (h : a - c < b) : a < b + c := by\n  have h := Int.add_lt_add_right h c\n  rwa [Int.sub_add_cancel] at h\n\nprotected theorem sub_right_lt_of_lt_add {a b c : \u2124} (h : a < b + c) : a - c < b := by\n  have h := Int.add_lt_add_right h (-c)\n  rwa [Int.add_neg_cancel_right] at h\n\nprotected theorem lt_add_of_neg_add_lt_left {a b c : \u2124} (h : -b + a < c) : a < b + c := by\n  rw [Int.add_comm] at h\n  exact Int.lt_add_of_sub_left_lt h\n\nprotected theorem neg_add_lt_left_of_lt_add {a b c : \u2124} (h : a < b + c) : -b + a < c := by\n  rw [Int.add_comm]\n  exact Int.sub_left_lt_of_lt_add h\n\nprotected theorem lt_add_of_neg_add_lt_right {a b c : \u2124} (h : -c + a < b) : a < b + c := by\n  rw [Int.add_comm] at h\n  exact Int.lt_add_of_sub_right_lt h\n\nprotected theorem neg_add_lt_right_of_lt_add {a b c : \u2124} (h : a < b + c) : -c + a < b := by\n  rw [Int.add_comm] at h\n  exact Int.neg_add_lt_left_of_lt_add h\n\nprotected theorem lt_add_of_neg_lt_sub_left {a b c : \u2124} (h : -a < b - c) : c < a + b :=\n  Int.lt_add_of_neg_add_lt_left (Int.add_lt_of_lt_sub_right h)\n\nprotected theorem neg_lt_sub_left_of_lt_add {a b c : \u2124} (h : c < a + b) : -a < b - c := by\n  have h := Int.lt_neg_add_of_add_lt (Int.sub_left_lt_of_lt_add h)\n  rwa [Int.add_comm] at h\n\nprotected theorem lt_add_of_neg_lt_sub_right {a b c : \u2124} (h : -b < a - c) : c < a + b :=\n  Int.lt_add_of_sub_right_lt (Int.add_lt_of_lt_sub_left h)\n\nprotected theorem neg_lt_sub_right_of_lt_add {a b c : \u2124} (h : c < a + b) : -b < a - c :=\n  Int.lt_sub_left_of_add_lt (Int.sub_right_lt_of_lt_add h)\n\nprotected theorem sub_lt_of_sub_lt {a b c : \u2124} (h : a - b < c) : a - c < b :=\n  Int.sub_left_lt_of_lt_add (Int.lt_add_of_sub_right_lt h)\n\nprotected theorem sub_lt_sub_left {a b : \u2124} (h : a < b) (c : \u2124) : c - b < c - a :=\n  Int.add_lt_add_left (Int.neg_lt_neg h) c\n\nprotected theorem sub_lt_sub_right {a b : \u2124} (h : a < b) (c : \u2124) : a - c < b - c :=\n  Int.add_lt_add_right h (-c)\n\nprotected theorem sub_lt_sub {a b c d : \u2124} (hab : a < b) (hcd : c < d) : a - d < b - c :=\n  Int.add_lt_add hab (Int.neg_lt_neg hcd)\n\nprotected theorem sub_lt_sub_of_le_of_lt {a b c d : \u2124}\n  (hab : a \u2264 b) (hcd : c < d) : a - d < b - c :=\n  Int.add_lt_add_of_le_of_lt hab (Int.neg_lt_neg hcd)\n\nprotected theorem sub_lt_sub_of_lt_of_le {a b c d : \u2124}\n  (hab : a < b) (hcd : c \u2264 d) : a - d < b - c :=\n  Int.add_lt_add_of_lt_of_le hab (Int.neg_le_neg hcd)\n\nprotected theorem sub_le_self (a : \u2124) {b : \u2124} (h : 0 \u2264 b) : a - b \u2264 a :=\n  calc\n    a + -b \u2264 a + 0 := Int.add_le_add_left (Int.neg_nonpos_of_nonneg h) _\n    _ = a := by rw [Int.add_zero]\n\nprotected theorem sub_lt_self (a : \u2124) {b : \u2124} (h : 0 < b) : a - b < a :=\n  calc\n    a + -b < a + 0 := Int.add_lt_add_left (Int.neg_neg_of_pos h) _\n    _ = a := by rw [Int.add_zero]\n\nprotected theorem add_le_add_three {a b c d e f : \u2124}\n  (h\u2081 : a \u2264 d) (h\u2082 : b \u2264 e) (h\u2083 : c \u2264 f) : a + b + c \u2264 d + e + f := by\n  apply le_trans\n  apply Int.add_le_add\n  apply Int.add_le_add\n  assumption'\n  apply le_refl\n\nprotected theorem mul_lt_mul_of_pos_left {a b c : \u2124}\n  (h\u2081 : a < b) (h\u2082 : 0 < c) : c * a < c * b := by\n  have : 0 < c * (b - a) := Int.mul_pos h\u2082 (Int.sub_pos_of_lt h\u2081)\n  rw [Int.mul_sub] at this\n  exact Int.lt_of_sub_pos this\n\nprotected theorem mul_lt_mul_of_pos_right {a b c : \u2124}\n  (h\u2081 : a < b) (h\u2082 : 0 < c) : a * c < b * c := by\n  have : 0 < b - a := Int.sub_pos_of_lt h\u2081\n  have : 0 < (b - a) * c := Int.mul_pos this h\u2082\n  rw [Int.sub_mul] at this\n  exact Int.lt_of_sub_pos this\n\nprotected theorem mul_le_mul_of_nonneg_left {a b c : \u2124}\n  (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c * a \u2264 c * b := by\n  by_cases hba : b \u2264 a; { simp [le_antisymm hba h\u2081] }\n  by_cases hc0 : c \u2264 0; { simp [le_antisymm hc0 h\u2082, Int.zero_mul] }\n  exact (le_not_le_of_lt (Int.mul_lt_mul_of_pos_left\n    (lt_of_le_not_le h\u2081 hba) (lt_of_le_not_le h\u2082 hc0))).left\n\nprotected theorem mul_le_mul_of_nonneg_right {a b c : \u2124}\n  (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : a * c \u2264 b * c := by\n  by_cases hba : b \u2264 a; { simp [le_antisymm hba h\u2081] }\n  by_cases hc0 : c \u2264 0; { simp [le_antisymm hc0 h\u2082, Int.mul_zero] }\n  exact (le_not_le_of_lt (Int.mul_lt_mul_of_pos_right\n    (lt_of_le_not_le h\u2081 hba) (lt_of_le_not_le h\u2082 hc0))).left\n\nprotected theorem mul_le_mul {a b c d : \u2124}\n  (hac : a \u2264 c) (hbd : b \u2264 d) (nn_b : 0 \u2264 b) (nn_c : 0 \u2264 c) : a * b \u2264 c * d :=\n  calc\n    a * b \u2264 c * b := Int.mul_le_mul_of_nonneg_right hac nn_b\n    _ \u2264 c * d := Int.mul_le_mul_of_nonneg_left hbd nn_c\n\nprotected theorem mul_nonpos_of_nonneg_of_nonpos {a b : \u2124}\n  (ha : 0 \u2264 a) (hb : b \u2264 0) : a * b \u2264 0 := by\n  have h : a * b \u2264 a * 0 := Int.mul_le_mul_of_nonneg_left hb ha\n  rwa [Int.mul_zero] at h\n\nprotected theorem mul_nonpos_of_nonpos_of_nonneg {a b : \u2124}\n  (ha : a \u2264 0) (hb : 0 \u2264 b) : a * b \u2264 0 := by\n  have h : a * b \u2264 0 * b := Int.mul_le_mul_of_nonneg_right ha hb\n  rwa [Int.zero_mul] at h\n\nprotected theorem mul_lt_mul {a b c d : \u2124}\n  (hac : a < c) (hbd : b \u2264 d) (pos_b : 0 < b) (nn_c : 0 \u2264 c) : a * b < c * d :=\n  calc\n    a * b < c * b := Int.mul_lt_mul_of_pos_right hac pos_b\n    _ \u2264 c * d := Int.mul_le_mul_of_nonneg_left hbd nn_c\n\n\nprotected theorem mul_lt_mul' {a b c d : \u2124}\n  (h1 : a \u2264 c) (h2 : b < d) (h3 : 0 \u2264 b) (h4 : 0 < c) : a * b < c * d :=\n  calc\n    a * b \u2264 c * b := Int.mul_le_mul_of_nonneg_right h1 h3\n    _ < c * d := Int.mul_lt_mul_of_pos_left h2 h4\n\nprotected theorem mul_neg_of_pos_of_neg {a b : \u2124} (ha : 0 < a) (hb : b < 0) : a * b < 0 := by\n  have h : a * b < a * 0 := Int.mul_lt_mul_of_pos_left hb ha\n  rwa [Int.mul_zero] at h\n\nprotected theorem mul_neg_of_neg_of_pos {a b : \u2124} (ha : a < 0) (hb : 0 < b) : a * b < 0 := by\n  have h : a * b < 0 * b := Int.mul_lt_mul_of_pos_right ha hb\n  rwa [Int.zero_mul] at h\n\nprotected theorem mul_le_mul_of_nonpos_right {a b c : \u2124}\n  (h : b \u2264 a) (hc : c \u2264 0) : a * c \u2264 b * c :=\n  have : -c \u2265 0 := Int.neg_nonneg_of_nonpos hc\n  have : b * -c \u2264 a * -c := Int.mul_le_mul_of_nonneg_right h this\n  have : -(b * c) \u2264 -(a * c) := by\n    rwa [\u2190 Int.neg_mul_eq_mul_neg, \u2190 Int.neg_mul_eq_mul_neg] at this\n  Int.le_of_neg_le_neg this\n\nprotected theorem mul_nonneg_of_nonpos_of_nonpos {a b : \u2124}\n  (ha : a \u2264 0) (hb : b \u2264 0) : 0 \u2264 a * b := by\n  have : 0 * b \u2264 a * b := Int.mul_le_mul_of_nonpos_right ha hb\n  rwa [Int.zero_mul] at this\n\nprotected theorem mul_lt_mul_of_neg_left {a b c : \u2124} (h : b < a) (hc : c < 0) : c * a < c * b :=\n  have : -c > 0 := Int.neg_pos_of_neg hc\n  have : -c * b < -c * a := Int.mul_lt_mul_of_pos_left h this\n  have : -(c * b) < -(c * a) := by\n    rwa [\u2190 Int.neg_mul_eq_neg_mul, \u2190 Int.neg_mul_eq_neg_mul] at this\n  Int.lt_of_neg_lt_neg this\n\nprotected theorem mul_lt_mul_of_neg_right {a b c : \u2124} (h : b < a) (hc : c < 0) : a * c < b * c :=\n  have : -c > 0 := Int.neg_pos_of_neg hc\n  have : b * -c < a * -c := Int.mul_lt_mul_of_pos_right h this\n  have : -(b * c) < -(a * c) := by\n    rwa [\u2190 Int.neg_mul_eq_mul_neg, \u2190 Int.neg_mul_eq_mul_neg] at this\n  Int.lt_of_neg_lt_neg this\n\nprotected theorem mul_pos_of_neg_of_neg {a b : \u2124} (ha : a < 0) (hb : b < 0) : 0 < a * b := by\n  have : 0 * b < a * b := Int.mul_lt_mul_of_neg_right ha hb\n  rwa [Int.zero_mul] at this\n\nprotected theorem mul_self_le_mul_self {a b : \u2124} (h1 : 0 \u2264 a) (h2 : a \u2264 b) : a * a \u2264 b * b :=\n  Int.mul_le_mul h2 h2 h1 (le_trans h1 h2)\n\nprotected theorem mul_self_lt_mul_self {a b : \u2124} (h1 : 0 \u2264 a) (h2 : a < b) : a * a < b * b :=\n  Int.mul_lt_mul' (le_of_lt h2) h2 h1 (lt_of_le_of_lt h1 h2)\n\ntheorem exists_eq_neg_ofNat {a : \u2124} (H : a \u2264 0) : \u2203 n : \u2115, a = -(n : \u2124) :=\n  let \u27e8n, h\u27e9 := eq_ofNat_of_zero_le (Int.neg_nonneg_of_nonpos H)\n  \u27e8n, Int.eq_neg_of_eq_neg h.symm\u27e9\n\ntheorem natAbs_of_nonneg {a : \u2124} (H : 0 \u2264 a) : (natAbs a : \u2124) = a :=\n  match a, eq_ofNat_of_zero_le H with\n  | _, \u27e8n, rfl\u27e9 => rfl\n\ntheorem ofNat_natAbs_of_nonpos {a : \u2124} (H : a \u2264 0) : (natAbs a : \u2124) = -a := by\n  rw [\u2190 natAbs_neg, natAbs_of_nonneg (Int.neg_nonneg_of_nonpos H)]\n\ntheorem lt_of_add_one_le {a b : \u2124} (H : a + 1 \u2264 b) : a < b := H\n\ntheorem add_one_le_of_lt {a b : \u2124} (H : a < b) : a + 1 \u2264 b := H\n\ntheorem lt_add_one_of_le {a b : \u2124} (H : a \u2264 b) : a < b + 1 := Int.add_le_add_right H 1\n\ntheorem le_of_lt_add_one {a b : \u2124} (H : a < b + 1) : a \u2264 b := Int.le_of_add_le_add_right H\n\ntheorem sub_one_lt_of_le {a b : \u2124} (H : a \u2264 b) : a - 1 < b :=\n  Int.sub_right_lt_of_lt_add $ lt_add_one_of_le H\n\ntheorem le_of_sub_one_lt {a b : \u2124} (H : a - 1 < b) : a \u2264 b :=\n  le_of_lt_add_one $ Int.lt_add_of_sub_right_lt H\n\ntheorem le_sub_one_of_lt {a b : \u2124} (H : a < b) : a \u2264 b - 1 := Int.le_sub_right_of_add_le H\n\ntheorem lt_of_le_sub_one {a b : \u2124} (H : a \u2264 b - 1) : a < b := Int.add_le_of_le_sub_right H\n\ntheorem sign_of_succ (n : Nat) : sign (Nat.succ n) = 1 := rfl\n\ntheorem sign_eq_one_of_pos {a : \u2124} (h : 0 < a) : sign a = 1 :=\n  match a, eq_succ_of_zero_lt h with\n  | _, \u27e8n, rfl\u27e9 => rfl\n\ntheorem sign_eq_neg_one_of_neg {a : \u2124} (h : a < 0) : sign a = -1 :=\n  match a, eq_neg_succ_of_lt_zero h with\n  | _, \u27e8n, rfl\u27e9 => rfl\n\ntheorem eq_zero_of_sign_eq_zero : \u2200 {a : \u2124}, sign a = 0 \u2192 a = 0\n  | 0, _ => rfl\n\ntheorem pos_of_sign_eq_one : \u2200 {a : \u2124}, sign a = 1 \u2192 0 < a\n  | (n + 1 : \u2115), _ => ofNat_lt.2 (Nat.succ_pos _)\n\ntheorem neg_of_sign_eq_neg_one : \u2200 {a : \u2124}, sign a = -1 \u2192 a < 0\n  | (n + 1 : \u2115), h => nomatch h\n  | 0, h => nomatch h\n  | -[1+ n], _ => neg_succ_lt_zero _\n\ntheorem sign_eq_one_iff_pos (a : \u2124) : sign a = 1 \u2194 0 < a :=\n  \u27e8pos_of_sign_eq_one, sign_eq_one_of_pos\u27e9\n\ntheorem sign_eq_neg_one_iff_neg (a : \u2124) : sign a = -1 \u2194 a < 0 :=\n  \u27e8neg_of_sign_eq_neg_one, sign_eq_neg_one_of_neg\u27e9\n\ntheorem sign_eq_zero_iff_zero (a : \u2124) : sign a = 0 \u2194 a = 0 :=\n  \u27e8eq_zero_of_sign_eq_zero, fun h => by rw [h, sign_zero]\u27e9\n\nprotected \n\nprotected theorem eq_of_mul_eq_mul_right {a b c : \u2124} (ha : a \u2260 0) (h : b * a = c * a) : b = c :=\n  have : b * a - c * a = 0 := Int.sub_eq_zero_of_eq h\n  have : (b - c) * a = 0 := by rw [Int.sub_mul, this]\n  have : b - c = 0 := (Int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right ha\n  Int.eq_of_sub_eq_zero this\n\nprotected theorem eq_of_mul_eq_mul_left {a b c : \u2124} (ha : a \u2260 0) (h : a * b = a * c) : b = c :=\n  have : a * b - a * c = 0 := Int.sub_eq_zero_of_eq h\n  have : a * (b - c) = 0 := by rw [Int.mul_sub, this]\n  have : b - c = 0 := (Int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_left ha\n  Int.eq_of_sub_eq_zero this\n\ntheorem eq_one_of_mul_eq_self_left {a b : \u2124} (Hpos : a \u2260 0) (H : b * a = a) : b = 1 :=\n  Int.eq_of_mul_eq_mul_right Hpos $ by rw [Int.one_mul, H]\n\ntheorem eq_one_of_mul_eq_self_right {a b : \u2124} (Hpos : b \u2260 0) (H : b * a = b) : a = 1 :=\n  Int.eq_of_mul_eq_mul_left Hpos $ by rw [Int.mul_one, H]\n\nlemma ofNat_natAbs_eq_of_nonneg : \u2200 a : \u2124, 0 \u2264 a \u2192 Int.ofNat (Int.natAbs a) = a\n| (ofNat n), h => rfl\n| -[1+ n],   h => absurd (neg_succ_lt_zero n) (not_lt_of_ge h)\n\nend Int\n", "meta": {"author": "JOSHCLUNE", "repo": "Keller_reduction", "sha": "dc392b3da352fc1ffcfbecb1d4717d05f5faed4a", "save_path": "github-repos/lean/JOSHCLUNE-Keller_reduction", "path": "github-repos/lean/JOSHCLUNE-Keller_reduction/Keller_reduction-dc392b3da352fc1ffcfbecb1d4717d05f5faed4a/Lean4_Clique/Mathlib/Mathlib/Init/Data/Int/Order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7119464954204647}}
{"text": "import group_theory.group_action\nimport ..affine.add_group_action\n\n-- g-spaces\n\n/-!\n# G-spaces, Homogeneous spaces, and torsors\n\nA `G-space` is a nonempty set `X` on which a group `G` acts.\nA `Homogeneous Space` is a G-space where the group action is transitive.\nA `Torsor` is a homogeneous space where the group action is also free.\n\nAll of these things are implemented w.r.t. both additive and multiplicative groups. The theory\nis equivalent for both.\n-/\n\n\n/-- g-space w.r.t. multiplicative action. -/\nclass mul_space (G X : Type*) [group G] extends mul_action G X\n\n/-- g-space w.r.t. additive action. -/\nclass add_space (G X : Type*) [add_group G] extends add_action G X\n\n\n/-- homogeneous spaces w.r.t. multiplicative action. -/\nclass mul_homogeneous_space (G X : Type*) [group G] extends mul_space G X :=\n(mul_trans : \u2200 x y : X, \u2203 g : G, g \u2022 x = y)\n\n/-- homogeneous spaces w.r.t. additive action. -/\nclass add_homogeneous_space (G X : Type*) [add_group G] extends add_space G X :=\n(add_trans : \u2200 x y : X, \u2203 g : G, g \u22b9 x = y)\n\n\n/-- torsors w.r.t. multiplicative action. -/\nclass mul_torsor (G X : Type*) [group G] extends mul_homogeneous_space G X :=\n(mul_free : \u2200 x : X, \u2200 g h : G, g \u2022 x = h \u2022 x \u2192 g = h)\n\n/-- torsors w.r.t. additive action. -/\nclass add_torsor (G X : Type*) [add_group G] extends add_space G X :=\n(add_free : \u2200 x : X, \u2200 g h : G, g \u22b9 x = h \u22b9 x \u2192 g = h)\n\n-- TODO: mul_ and add_torsor with diff function\n\nuniverses u v\nvariables (X : Type u) (G : Type v) [add_group G] [add_torsor G X]\n\n#check exists_unique\n\nlemma add_trans_free_unique : \u2200 x y : X, \u2203! g : G, g \u22b9 x = y := sorry\n", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/old/old_affine/g_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7119464841298726}}
{"text": "/-\nCopyright (c) 2020 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module topology.uniform_space.uniform_convergence\n! leanprover-community/mathlib commit 2705404e701abc6b3127da906f40bae062a169c9\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.Separation\nimport Mathlib.Topology.UniformSpace.Basic\nimport Mathlib.Topology.UniformSpace.Cauchy\n\n/-!\n# Uniform convergence\n\nA sequence of functions `F\u2099` (with values in a metric space) converges uniformly on a set `s` to a\nfunction `f` if, for all `\u03b5 > 0`, for all large enough `n`, one has for all `y \u2208 s` the inequality\n`dist (f y, F\u2099 y) < \u03b5`. Under uniform convergence, many properties of the `F\u2099` pass to the limit,\nmost notably continuity. We prove this in the file, defining the notion of uniform convergence\nin the more general setting of uniform spaces, and with respect to an arbitrary indexing set\nendowed with a filter (instead of just `\u2115` with `atTop`).\n\n## Main results\n\nLet `\u03b1` be a topological space, `\u03b2` a uniform space, `F\u2099` and `f` be functions from `\u03b1` to `\u03b2`\n(where the index `n` belongs to an indexing type `\u03b9` endowed with a filter `p`).\n\n* `TendstoUniformlyOn F f p s`: the fact that `F\u2099` converges uniformly to `f` on `s`. This means\n  that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has\n  `(f y, F\u2099 y) \u2208 u` for all `y \u2208 s`.\n* `TendstoUniformly F f p`: same notion with `s = univ`.\n* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous\n  on this set is itself continuous on this set.\n* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.\n* `TendstoUniformlyOn.tendsto_comp`: If `F\u2099` tends uniformly to `f` on a set `s`, and `g\u2099` tends\n  to `x` within `s`, then `F\u2099 g\u2099` tends to `f x` if `f` is continuous at `x` within `s`.\n* `TendstoUniformly.tendsto_comp`: If `F\u2099` tends uniformly to `f`, and `g\u2099` tends to `x`, then\n  `F\u2099 g\u2099` tends to `f x`.\n\nWe also define notions where the convergence is locally uniform, called\n`TendstoLocallyUniformlyOn F f p s` and `TendstoLocallyUniformly F f p`. The previous theorems\nall have corresponding versions under locally uniform convergence.\n\nFinally, we introduce the notion of a uniform Cauchy sequence, which is to uniform\nconvergence what a Cauchy sequence is to the usual notion of convergence.\n\n## Implementation notes\n\nWe derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.\nThis definition in and of itself can sometimes be useful, e.g., when studying the local behavior\nof the `F\u2099` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (\ud835\udcdd x)`.\nStill, while this may be the \"correct\" definition (see\n`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in\npractice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.\n\nMost results hold under weaker assumptions of locally uniform approximation. In a first section,\nwe prove the results under these weaker assumptions. Then, we derive the results on uniform\nconvergence from them.\n\n## Tags\n\nUniform limit, uniform convergence, tends uniformly to\n -/\n\n\nnoncomputable section\n\nopen Topology Uniformity Filter Set\n\nuniverse u v w x\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Type x} [UniformSpace \u03b2]\n\nvariable {F : \u03b9 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2} {s s' : Set \u03b1} {x : \u03b1} {p : Filter \u03b9} {p' : Filter \u03b1}\n  {g : \u03b9 \u2192 \u03b1}\n\n/-!\n### Different notions of uniform convergence\n\nWe define uniform convergence and locally uniform convergence, on a set or in the whole space.\n-/\n\n\n/-- A sequence of functions `F\u2099` converges uniformly on a filter `p'` to a limiting function `f`\nwith respect to the filter `p` if, for any entourage of the diagonal `u`, one has\n`p \u00d7\u1da0 p'`-eventually `(f x, F\u2099 x) \u2208 u`. -/\ndef TendstoUniformlyOnFilter (F : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) (p : Filter \u03b9) (p' : Filter \u03b1) :=\n  \u2200 u \u2208 \ud835\udce4 \u03b2, \u2200\u1da0 n : \u03b9 \u00d7 \u03b1 in p \u00d7\u1da0 p', (f n.snd, F n.fst n.snd) \u2208 u\n#align tendsto_uniformly_on_filter TendstoUniformlyOnFilter\n\n/--\nA sequence of functions `F\u2099` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.\nfilter `p` iff the function `(n, x) \u21a6 (f x, F\u2099 x)` converges along `p \u00d7\u1da0 p'` to the uniformity.\nIn other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.\n-/\ntheorem tendstoUniformlyOnFilter_iff_tendsto :\n    TendstoUniformlyOnFilter F f p p' \u2194\n      Tendsto (fun q : \u03b9 \u00d7 \u03b1 => (f q.2, F q.1 q.2)) (p \u00d7\u1da0 p') (\ud835\udce4 \u03b2) :=\n  Iff.rfl\n#align tendsto_uniformly_on_filter_iff_tendsto tendstoUniformlyOnFilter_iff_tendsto\n\n/-- A sequence of functions `F\u2099` converges uniformly on a set `s` to a limiting function `f` with\nrespect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually\n`(f x, F\u2099 x) \u2208 u` for all `x \u2208 s`. -/\ndef TendstoUniformlyOn (F : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) (p : Filter \u03b9) (s : Set \u03b1) :=\n  \u2200 u \u2208 \ud835\udce4 \u03b2, \u2200\u1da0 n in p, \u2200 x : \u03b1, x \u2208 s \u2192 (f x, F n x) \u2208 u\n#align tendsto_uniformly_on TendstoUniformlyOn\n\ntheorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :\n    TendstoUniformlyOn F f p s \u2194 TendstoUniformlyOnFilter F f p (\ud835\udcdf s) := by\n  simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]\n  apply forall\u2082_congr\n  simp_rw [eventually_prod_principal_iff]\n  simp\n#align tendsto_uniformly_on_iff_tendsto_uniformly_on_filter tendstoUniformlyOn_iff_tendstoUniformlyOnFilter\n\nalias tendstoUniformlyOn_iff_tendstoUniformlyOnFilter \u2194\n  TendstoUniformlyOn.tendstoUniformlyOnFilter TendstoUniformlyOnFilter.tendstoUniformlyOn\n#align tendsto_uniformly_on.tendsto_uniformly_on_filter TendstoUniformlyOn.tendstoUniformlyOnFilter\n#align tendsto_uniformly_on_filter.tendsto_uniformly_on TendstoUniformlyOnFilter.tendstoUniformlyOn\n\n/-- A sequence of functions `F\u2099` converges uniformly on a set `s` to a limiting function `f` w.r.t.\nfilter `p` iff the function `(n, x) \u21a6 (f x, F\u2099 x)` converges along `p \u00d7\u1da0 \ud835\udcdf s` to the uniformity.\nIn other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.\n-/\ntheorem tendstoUniformlyOn_iff_tendsto {F : \u03b9 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2} {p : Filter \u03b9} {s : Set \u03b1} :\n    TendstoUniformlyOn F f p s \u2194 Tendsto (fun q : \u03b9 \u00d7 \u03b1 => (f q.2, F q.1 q.2)) (p \u00d7\u1da0 \ud835\udcdf s) (\ud835\udce4 \u03b2) :=\n  by simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]\n#align tendsto_uniformly_on_iff_tendsto tendstoUniformlyOn_iff_tendsto\n\n/-- A sequence of functions `F\u2099` converges uniformly to a limiting function `f` with respect to a\nfilter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually\n`(f x, F\u2099 x) \u2208 u` for all `x`. -/\ndef TendstoUniformly (F : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) (p : Filter \u03b9) :=\n  \u2200 u \u2208 \ud835\udce4 \u03b2, \u2200\u1da0 n in p, \u2200 x : \u03b1, (f x, F n x) \u2208 u\n#align tendsto_uniformly TendstoUniformly\n\n-- porting note: moved from below\ntheorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ \u2194 TendstoUniformly F f p := by\n  simp [TendstoUniformlyOn, TendstoUniformly]\n#align tendsto_uniformly_on_univ tendstoUniformlyOn_univ\n\ntheorem tendstoUniformly_iff_tendstoUniformlyOnFilter :\n    TendstoUniformly F f p \u2194 TendstoUniformlyOnFilter F f p \u22a4 := by\n  rw [\u2190 tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]\n#align tendsto_uniformly_iff_tendsto_uniformly_on_filter tendstoUniformly_iff_tendstoUniformlyOnFilter\n\ntheorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :\n    TendstoUniformlyOnFilter F f p \u22a4 := by rwa [\u2190 tendstoUniformly_iff_tendstoUniformlyOnFilter]\n#align tendsto_uniformly.tendsto_uniformly_on_filter TendstoUniformly.tendstoUniformlyOnFilter\n\ntheorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :\n    TendstoUniformlyOn F f p s \u2194 TendstoUniformly (fun i (x : s) => F i x) (f \u2218 (\u2191)) p :=\n  forall\u2082_congr <| fun u _ => by simp\n#align tendsto_uniformly_on_iff_tendsto_uniformly_comp_coe tendstoUniformlyOn_iff_tendstoUniformly_comp_coe\n\n/-- A sequence of functions `F\u2099` converges uniformly to a limiting function `f` w.r.t.\nfilter `p` iff the function `(n, x) \u21a6 (f x, F\u2099 x)` converges along `p \u00d7\u1da0 \u22a4` to the uniformity.\nIn other words: one knows nothing about the behavior of `x` in this limit.\n-/\ntheorem tendstoUniformly_iff_tendsto {F : \u03b9 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2} {p : Filter \u03b9} :\n    TendstoUniformly F f p \u2194 Tendsto (fun q : \u03b9 \u00d7 \u03b1 => (f q.2, F q.1 q.2)) (p \u00d7\u1da0 \u22a4) (\ud835\udce4 \u03b2) := by\n  simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]\n#align tendsto_uniformly_iff_tendsto tendstoUniformly_iff_tendsto\n\n/-- Uniform converence implies pointwise convergence. -/\ntheorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p')\n    (hx : \ud835\udcdf {x} \u2264 p') : Tendsto (fun n => F n x) p <| \ud835\udcdd (f x) := by\n  refine' Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr _\n  filter_upwards [(h u hu).curry]\n  intro i h\n  simpa using h.filter_mono hx\n#align tendsto_uniformly_on_filter.tendsto_at TendstoUniformlyOnFilter.tendsto_at\n\n/-- Uniform converence implies pointwise convergence. -/\ntheorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) {x : \u03b1} (hx : x \u2208 s) :\n    Tendsto (fun n => F n x) p <| \ud835\udcdd (f x) :=\n  h.tendstoUniformlyOnFilter.tendsto_at\n    (le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx)\n#align tendsto_uniformly_on.tendsto_at TendstoUniformlyOn.tendsto_at\n\n/-- Uniform converence implies pointwise convergence. -/\ntheorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : \u03b1) :\n    Tendsto (fun n => F n x) p <| \ud835\udcdd (f x) :=\n  h.tendstoUniformlyOnFilter.tendsto_at le_top\n#align tendsto_uniformly.tendsto_at TendstoUniformly.tendsto_at\n\n-- porting note: tendstoUniformlyOn_univ moved up\n\ntheorem TendstoUniformlyOnFilter.mono_left {p'' : Filter \u03b9} (h : TendstoUniformlyOnFilter F f p p')\n    (hp : p'' \u2264 p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu =>\n  (h u hu).filter_mono (p'.prod_mono_left hp)\n#align tendsto_uniformly_on_filter.mono_left TendstoUniformlyOnFilter.mono_left\n\ntheorem TendstoUniformlyOnFilter.mono_right {p'' : Filter \u03b1} (h : TendstoUniformlyOnFilter F f p p')\n    (hp : p'' \u2264 p') : TendstoUniformlyOnFilter F f p p'' := fun u hu =>\n  (h u hu).filter_mono (p.prod_mono_right hp)\n#align tendsto_uniformly_on_filter.mono_right TendstoUniformlyOnFilter.mono_right\n\ntheorem TendstoUniformlyOn.mono {s' : Set \u03b1} (h : TendstoUniformlyOn F f p s) (h' : s' \u2286 s) :\n    TendstoUniformlyOn F f p s' :=\n  tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr\n    (h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h'))\n#align tendsto_uniformly_on.mono TendstoUniformlyOn.mono\n\ntheorem TendstoUniformlyOnFilter.congr {F' : \u03b9 \u2192 \u03b1 \u2192 \u03b2} (hf : TendstoUniformlyOnFilter F f p p')\n    (hff' : \u2200\u1da0 n : \u03b9 \u00d7 \u03b1 in p \u00d7\u1da0 p', F n.fst n.snd = F' n.fst n.snd) :\n    TendstoUniformlyOnFilter F' f p p' := by\n  refine' fun u hu => ((hf u hu).and hff').mono fun n h => _\n  rw [\u2190 h.right]\n  exact h.left\n#align tendsto_uniformly_on_filter.congr TendstoUniformlyOnFilter.congr\n\ntheorem TendstoUniformlyOn.congr {F' : \u03b9 \u2192 \u03b1 \u2192 \u03b2} (hf : TendstoUniformlyOn F f p s)\n    (hff' : \u2200\u1da0 n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by\n  rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf\u22a2\n  refine' hf.congr _\n  rw [eventually_iff] at hff'\u22a2\n  simp only [Set.EqOn] at hff'\n  simp only [mem_prod_principal, hff', mem_setOf_eq]\n#align tendsto_uniformly_on.congr TendstoUniformlyOn.congr\n\ntheorem TendstoUniformlyOn.congr_right {g : \u03b1 \u2192 \u03b2} (hf : TendstoUniformlyOn F f p s)\n    (hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by\n  filter_upwards [hf u hu]with i hi a ha using hfg ha \u25b8 hi a ha\n#align tendsto_uniformly_on.congr_right TendstoUniformlyOn.congr_right\n\nprotected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) :\n    TendstoUniformlyOn F f p s :=\n  (tendstoUniformlyOn_univ.2 h).mono (subset_univ s)\n#align tendsto_uniformly.tendsto_uniformly_on TendstoUniformly.tendstoUniformlyOn\n\n/-- Composing on the right by a function preserves uniform convergence on a filter -/\ntheorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : \u03b3 \u2192 \u03b1) :\n    TendstoUniformlyOnFilter (fun n => F n \u2218 g) (f \u2218 g) p (p'.comap g) := by\n  rw [tendstoUniformlyOnFilter_iff_tendsto] at h \u22a2\n  exact h.comp (tendsto_id.prod_map tendsto_comap)\n#align tendsto_uniformly_on_filter.comp TendstoUniformlyOnFilter.comp\n\n/-- Composing on the right by a function preserves uniform convergence on a set -/\ntheorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : \u03b3 \u2192 \u03b1) :\n    TendstoUniformlyOn (fun n => F n \u2218 g) (f \u2218 g) p (g \u207b\u00b9' s) := by\n  rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h\u22a2\n  simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g\n#align tendsto_uniformly_on.comp TendstoUniformlyOn.comp\n\n/-- Composing on the right by a function preserves uniform convergence -/\ntheorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : \u03b3 \u2192 \u03b1) :\n    TendstoUniformly (fun n => F n \u2218 g) (f \u2218 g) p := by\n  rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h\u22a2\n  simpa [principal_univ, comap_principal] using h.comp g\n#align tendsto_uniformly.comp TendstoUniformly.comp\n\n/-- Composing on the left by a uniformly continuous function preserves\n  uniform convergence on a filter -/\ntheorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace \u03b3] {g : \u03b2 \u2192 \u03b3}\n    (hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') :\n    TendstoUniformlyOnFilter (fun i => g \u2218 F i) (g \u2218 f) p p' := fun _u hu => h _ (hg hu)\n#align uniform_continuous.comp_tendsto_uniformly_on_filter UniformContinuous.comp_tendstoUniformlyOnFilter\n\n/-- Composing on the left by a uniformly continuous function preserves\n  uniform convergence on a set -/\ntheorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace \u03b3] {g : \u03b2 \u2192 \u03b3}\n    (hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) :\n    TendstoUniformlyOn (fun i => g \u2218 F i) (g \u2218 f) p s := fun _u hu => h _ (hg hu)\n#align uniform_continuous.comp_tendsto_uniformly_on UniformContinuous.comp_tendstoUniformlyOn\n\n/-- Composing on the left by a uniformly continuous function preserves uniform convergence -/\ntheorem UniformContinuous.comp_tendstoUniformly [UniformSpace \u03b3] {g : \u03b2 \u2192 \u03b3}\n    (hg : UniformContinuous g) (h : TendstoUniformly F f p) :\n    TendstoUniformly (fun i => g \u2218 F i) (g \u2218 f) p := fun _u hu => h _ (hg hu)\n#align uniform_continuous.comp_tendsto_uniformly UniformContinuous.comp_tendstoUniformly\n\ntheorem TendstoUniformlyOnFilter.prod_map {\u03b9' \u03b1' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1' \u2192 \u03b2'}\n    {f' : \u03b1' \u2192 \u03b2'} {q : Filter \u03b9'} {q' : Filter \u03b1'} (h : TendstoUniformlyOnFilter F f p p')\n    (h' : TendstoUniformlyOnFilter F' f' q q') :\n    TendstoUniformlyOnFilter (fun i : \u03b9 \u00d7 \u03b9' => Prod.map (F i.1) (F' i.2)) (Prod.map f f')\n      (p \u00d7\u1da0 q) (p' \u00d7\u1da0 q') := by\n  rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' \u22a2\n  rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, \u2190 map_swap4_prod, tendsto_map'_iff]\n  convert h.prod_map h' -- seems to be faster than `exact` here\n#align tendsto_uniformly_on_filter.prod_map TendstoUniformlyOnFilter.prod_map\n\ntheorem TendstoUniformlyOn.prod_map {\u03b9' \u03b1' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1' \u2192 \u03b2'}\n    {f' : \u03b1' \u2192 \u03b2'} {p' : Filter \u03b9'} {s' : Set \u03b1'} (h : TendstoUniformlyOn F f p s)\n    (h' : TendstoUniformlyOn F' f' p' s') :\n    TendstoUniformlyOn (fun i : \u03b9 \u00d7 \u03b9' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p \u00d7\u1da0 p')\n      (s \u00d7\u02e2 s') := by\n  rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h'\u22a2\n  simpa only [prod_principal_principal] using h.prod_map h'\n#align tendsto_uniformly_on.prod_map TendstoUniformlyOn.prod_map\n\ntheorem TendstoUniformly.prod_map {\u03b9' \u03b1' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1' \u2192 \u03b2'}\n    {f' : \u03b1' \u2192 \u03b2'} {p' : Filter \u03b9'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :\n    TendstoUniformly (fun i : \u03b9 \u00d7 \u03b9' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p \u00d7\u1da0 p') := by\n  rw [\u2190 tendstoUniformlyOn_univ, \u2190 univ_prod_univ] at *\n  exact h.prod_map h'\n#align tendsto_uniformly.prod_map TendstoUniformly.prod_map\n\ntheorem TendstoUniformlyOnFilter.prod {\u03b9' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1 \u2192 \u03b2'}\n    {f' : \u03b1 \u2192 \u03b2'} {q : Filter \u03b9'} (h : TendstoUniformlyOnFilter F f p p')\n    (h' : TendstoUniformlyOnFilter F' f' q p') :\n    TendstoUniformlyOnFilter (fun (i : \u03b9 \u00d7 \u03b9') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))\n      (p \u00d7\u1da0 q) p' :=\n  fun u hu => ((h.prod_map h') u hu).diag_of_prod_right\n#align tendsto_uniformly_on_filter.prod TendstoUniformlyOnFilter.prod\n\ntheorem TendstoUniformlyOn.prod {\u03b9' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1 \u2192 \u03b2'} {f' : \u03b1 \u2192 \u03b2'}\n    {p' : Filter \u03b9'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s) :\n    TendstoUniformlyOn (fun (i : \u03b9 \u00d7 \u03b9') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))\n      (p.prod p') s :=\n  (congr_arg _ s.inter_self).mp ((h.prod_map h').comp fun a => (a, a))\n#align tendsto_uniformly_on.prod TendstoUniformlyOn.prod\n\ntheorem TendstoUniformly.prod {\u03b9' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1 \u2192 \u03b2'} {f' : \u03b1 \u2192 \u03b2'}\n    {p' : Filter \u03b9'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :\n    TendstoUniformly (fun (i : \u03b9 \u00d7 \u03b9') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))\n      (p \u00d7\u1da0 p') :=\n  (h.prod_map h').comp fun a => (a, a)\n#align tendsto_uniformly.prod TendstoUniformly.prod\n\n/-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in\n`p \u00d7\u1da0 p'`. -/\ntheorem tendsto_prod_filter_iff {c : \u03b2} :\n    Tendsto (\u21bfF) (p \u00d7\u1da0 p') (\ud835\udcdd c) \u2194 TendstoUniformlyOnFilter F (fun _ => c) p p' := by\n  simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff, map_map, le_def, mem_map]\n  rfl\n#align tendsto_prod_filter_iff tendsto_prod_filter_iff\n\n/-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in\n`p \u00d7\u1da0 \ud835\udcdf s`. -/\ntheorem tendsto_prod_principal_iff {c : \u03b2} :\n    Tendsto (\u21bfF) (p \u00d7\u1da0 \ud835\udcdf s) (\ud835\udcdd c) \u2194 TendstoUniformlyOn F (fun _ => c) p s := by\n  rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter]\n  exact tendsto_prod_filter_iff\n#align tendsto_prod_principal_iff tendsto_prod_principal_iff\n\n/-- Uniform convergence to a constant function is equivalent to convergence in `p \u00d7\u1da0 \u22a4`. -/\ntheorem tendsto_prod_top_iff {c : \u03b2} :\n    Tendsto (\u21bfF) (p \u00d7\u1da0 \u22a4) (\ud835\udcdd c) \u2194 TendstoUniformly F (fun _ => c) p := by\n  rw [tendstoUniformly_iff_tendstoUniformlyOnFilter]\n  exact tendsto_prod_filter_iff\n#align tendsto_prod_top_iff tendsto_prod_top_iff\n\n/-- Uniform convergence on the empty set is vacuously true -/\ntheorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p \u2205 := fun u _ => by simp\n#align tendsto_uniformly_on_empty tendstoUniformlyOn_empty\n\n/-- Uniform convergence on a singleton is equivalent to regular convergence -/\ntheorem tendstoUniformlyOn_singleton_iff_tendsto :\n    TendstoUniformlyOn F f p {x} \u2194 Tendsto (fun n : \u03b9 => F n x) p (\ud835\udcdd (f x)) := by\n  simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def]\n  exact forall\u2082_congr fun u _ => by simp [mem_prod_principal, preimage]\n#align tendsto_uniformly_on_singleton_iff_tendsto tendstoUniformlyOn_singleton_iff_tendsto\n\n/-- If a sequence `g` converges to some `b`, then the sequence of constant functions\n`\u03bb n, \u03bb a, g n` converges to the constant function `\u03bb a, b` on any set `s` -/\ntheorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : \u03b9 \u2192 \u03b2} {b : \u03b2} (hg : Tendsto g p (\ud835\udcdd b))\n    (p' : Filter \u03b1) :\n    TendstoUniformlyOnFilter (fun n : \u03b9 => fun _ : \u03b1 => g n) (fun _ : \u03b1 => b) p p' := by\n  simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p'))\n#align filter.tendsto.tendsto_uniformly_on_filter_const Filter.Tendsto.tendstoUniformlyOnFilter_const\n\n/-- If a sequence `g` converges to some `b`, then the sequence of constant functions\n`\u03bb n, \u03bb a, g n` converges to the constant function `\u03bb a, b` on any set `s` -/\ntheorem Filter.Tendsto.tendstoUniformlyOn_const {g : \u03b9 \u2192 \u03b2} {b : \u03b2} (hg : Tendsto g p (\ud835\udcdd b))\n    (s : Set \u03b1) : TendstoUniformlyOn (fun n : \u03b9 => fun _ : \u03b1 => g n) (fun _ : \u03b1 => b) p s :=\n  tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (\ud835\udcdf s))\n#align filter.tendsto.tendsto_uniformly_on_const Filter.Tendsto.tendstoUniformlyOn_const\n\n-- porting note: new lemma\ntheorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace \u03b1] [UniformSpace \u03b3] {x : \u03b1} {U : Set \u03b1}\n    {V : Set \u03b2} {F : \u03b1 \u2192 \u03b2 \u2192 \u03b3} (hF : UniformContinuousOn (\u21bfF) (U \u00d7\u02e2 V)) (hU : x \u2208 U) :\n    TendstoUniformlyOn F (F x) (\ud835\udcdd[U] x) V := by\n  set \u03c6 := fun q : \u03b1 \u00d7 \u03b2 => ((x, q.2), q)\n  rw [tendstoUniformlyOn_iff_tendsto]\n  change Tendsto (Prod.map (\u21bfF) \u21bfF \u2218 \u03c6) (\ud835\udcdd[U] x \u00d7\u1da0 \ud835\udcdf V) (\ud835\udce4 \u03b3)\n  simp only [nhdsWithin, Filter.prod, comap_inf, inf_assoc, comap_principal, inf_principal]\n  refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 <| fun x hx => \u27e8\u27e8hU, hx.2\u27e9, hx\u27e9)\n  simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, (\u00b7 \u2218 \u00b7),\n    nhds_eq_comap_uniformity, comap_comap]\n  exact tendsto_comap.prod_mk (tendsto_diag_uniformity _ _)\n\ntheorem UniformContinuousOn.tendstoUniformly [UniformSpace \u03b1] [UniformSpace \u03b3] {x : \u03b1} {U : Set \u03b1}\n    (hU : U \u2208 \ud835\udcdd x) {F : \u03b1 \u2192 \u03b2 \u2192 \u03b3} (hF : UniformContinuousOn (\u21bfF) (U \u00d7\u02e2 (univ : Set \u03b2))) :\n    TendstoUniformly F (F x) (\ud835\udcdd x) := by\n  simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU]\n    using hF.tendstoUniformlyOn (mem_of_mem_nhds hU)\n#align uniform_continuous_on.tendsto_uniformly UniformContinuousOn.tendstoUniformly\n\ntheorem UniformContinuous\u2082.tendstoUniformly [UniformSpace \u03b1] [UniformSpace \u03b3] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3}\n    (h : UniformContinuous\u2082 f) {x : \u03b1} : TendstoUniformly f (f x) (\ud835\udcdd x) :=\n  UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ]\n#align uniform_continuous\u2082.tendsto_uniformly UniformContinuous\u2082.tendstoUniformly\n\n/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are\nuniformly bounded -/\ndef UniformCauchySeqOnFilter (F : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (p : Filter \u03b9) (p' : Filter \u03b1) : Prop :=\n  \u2200 u \u2208 \ud835\udce4 \u03b2, \u2200\u1da0 m : (\u03b9 \u00d7 \u03b9) \u00d7 \u03b1 in (p \u00d7\u1da0 p) \u00d7\u1da0 p', (F m.fst.fst m.snd, F m.fst.snd m.snd) \u2208 u\n#align uniform_cauchy_seq_on_filter UniformCauchySeqOnFilter\n\n/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are\nuniformly bounded -/\ndef UniformCauchySeqOn (F : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (p : Filter \u03b9) (s : Set \u03b1) : Prop :=\n  \u2200 u \u2208 \ud835\udce4 \u03b2, \u2200\u1da0 m : \u03b9 \u00d7 \u03b9 in p \u00d7\u1da0 p, \u2200 x : \u03b1, x \u2208 s \u2192 (F m.fst x, F m.snd x) \u2208 u\n#align uniform_cauchy_seq_on UniformCauchySeqOn\n\ntheorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter :\n    UniformCauchySeqOn F p s \u2194 UniformCauchySeqOnFilter F p (\ud835\udcdf s) := by\n  simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter]\n  refine' forall\u2082_congr fun u hu => _\n  rw [eventually_prod_principal_iff]\n#align uniform_cauchy_seq_on_iff_uniform_cauchy_seq_on_filter uniformCauchySeqOn_iff_uniformCauchySeqOnFilter\n\ntheorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) :\n    UniformCauchySeqOnFilter F p (\ud835\udcdf s) := by rwa [\u2190 uniformCauchySeqOn_iff_uniformCauchySeqOnFilter]\n#align uniform_cauchy_seq_on.uniform_cauchy_seq_on_filter UniformCauchySeqOn.uniformCauchySeqOnFilter\n\n/-- A sequence that converges uniformly is also uniformly Cauchy -/\ntheorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') :\n    UniformCauchySeqOnFilter F p p' := by\n  intro u hu\n  rcases comp_symm_of_uniformity hu with \u27e8t, ht, htsymm, htmem\u27e9\n  have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht))\n  apply this.diag_of_prod_right.mono\n  simp only [and_imp, Prod.forall]\n  intro n1 n2 x hl hr\n  exact Set.mem_of_mem_of_subset (prod_mk_mem_compRel (htsymm hl) hr) htmem\n#align tendsto_uniformly_on_filter.uniform_cauchy_seq_on_filter TendstoUniformlyOnFilter.uniformCauchySeqOnFilter\n\n/-- A sequence that converges uniformly is also uniformly Cauchy -/\ntheorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) :\n    UniformCauchySeqOn F p s :=\n  uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr\n    hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter\n#align tendsto_uniformly_on.uniform_cauchy_seq_on TendstoUniformlyOn.uniformCauchySeqOn\n\n/-- A uniformly Cauchy sequence converges uniformly to its limit -/\ntheorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto [NeBot p]\n    (hF : UniformCauchySeqOnFilter F p p')\n    (hF' : \u2200\u1da0 x : \u03b1 in p', Tendsto (fun n => F n x) p (\ud835\udcdd (f x))) :\n    TendstoUniformlyOnFilter F f p p' := by\n  -- Proof idea: |f_n(x) - f(x)| \u2264 |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n`\n  -- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m \u2265 n`. Then for\n  -- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small.\n  intro u hu\n  rcases comp_symm_of_uniformity hu with \u27e8t, ht, htsymm, htmem\u27e9\n  -- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF'\n  -- But we need to promote hF' to the full product filter to use it\n  have hmc : \u2200\u1da0 x in (p \u00d7\u1da0 p) \u00d7\u1da0 p', Tendsto (fun n : \u03b9 => F n x.snd) p (\ud835\udcdd (f x.snd)) := by\n    rw [eventually_prod_iff]\n    refine' \u27e8fun _ => True, by simp, _, hF', by simp\u27e9\n  -- To apply filter operations we'll need to do some order manipulation\n  rw [Filter.eventually_swap_iff]\n  have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc))\n  apply this.curry.mono\n  simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap,\n    and_imp, Prod.forall]\n  -- Complete the proof\n  intro x n hx hm'\n  refine' Set.mem_of_mem_of_subset (mem_compRel.mpr _) htmem\n  rw [Uniform.tendsto_nhds_right] at hm'\n  have := hx.and (hm' ht)\n  obtain \u27e8m, hm\u27e9 := this.exists\n  exact \u27e8F m x, \u27e8hm.2, htsymm hm.1\u27e9\u27e9\n#align uniform_cauchy_seq_on_filter.tendsto_uniformly_on_filter_of_tendsto UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto\n\n/-- A uniformly Cauchy sequence converges uniformly to its limit -/\ntheorem UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto [NeBot p] (hF : UniformCauchySeqOn F p s)\n    (hF' : \u2200 x : \u03b1, x \u2208 s \u2192 Tendsto (fun n => F n x) p (\ud835\udcdd (f x))) : TendstoUniformlyOn F f p s :=\n  tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr\n    (hF.uniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto hF')\n#align uniform_cauchy_seq_on.tendsto_uniformly_on_of_tendsto UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto\n\ntheorem UniformCauchySeqOnFilter.mono_left {p'' : Filter \u03b9} (hf : UniformCauchySeqOnFilter F p p')\n    (hp : p'' \u2264 p) : UniformCauchySeqOnFilter F p'' p' := by\n  intro u hu\n  have := (hf u hu).filter_mono (p'.prod_mono_left (Filter.prod_mono hp hp))\n  exact this.mono (by simp)\n#align uniform_cauchy_seq_on_filter.mono_left UniformCauchySeqOnFilter.mono_left\n\ntheorem UniformCauchySeqOnFilter.mono_right {p'' : Filter \u03b1} (hf : UniformCauchySeqOnFilter F p p')\n    (hp : p'' \u2264 p') : UniformCauchySeqOnFilter F p p'' := fun u hu =>\n  have := (hf u hu).filter_mono ((p \u00d7\u1da0 p).prod_mono_right hp)\n  this.mono (by simp)\n#align uniform_cauchy_seq_on_filter.mono_right UniformCauchySeqOnFilter.mono_right\n\ntheorem UniformCauchySeqOn.mono {s' : Set \u03b1} (hf : UniformCauchySeqOn F p s) (hss' : s' \u2286 s) :\n    UniformCauchySeqOn F p s' := by\n  rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf\u22a2\n  exact hf.mono_right (le_principal_iff.mpr <| mem_principal.mpr hss')\n#align uniform_cauchy_seq_on.mono UniformCauchySeqOn.mono\n\n/-- Composing on the right by a function preserves uniform Cauchy sequences -/\ntheorem UniformCauchySeqOnFilter.comp {\u03b3 : Type _} (hf : UniformCauchySeqOnFilter F p p')\n    (g : \u03b3 \u2192 \u03b1) : UniformCauchySeqOnFilter (fun n => F n \u2218 g) p (p'.comap g) := fun u hu => by\n  obtain \u27e8pa, hpa, pb, hpb, hpapb\u27e9 := eventually_prod_iff.mp (hf u hu)\n  rw [eventually_prod_iff]\n  refine \u27e8pa, hpa, pb \u2218 g, ?_, fun hx _ hy => hpapb hx hy\u27e9\n  exact eventually_comap.mpr (hpb.mono fun x hx y hy => by simp only [hx, hy, Function.comp_apply])\n#align uniform_cauchy_seq_on_filter.comp UniformCauchySeqOnFilter.comp\n\n/-- Composing on the right by a function preserves uniform Cauchy sequences -/\ntheorem UniformCauchySeqOn.comp {\u03b3 : Type _} (hf : UniformCauchySeqOn F p s) (g : \u03b3 \u2192 \u03b1) :\n    UniformCauchySeqOn (fun n => F n \u2218 g) p (g \u207b\u00b9' s) := by\n  rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf\u22a2\n  simpa only [UniformCauchySeqOn, comap_principal] using hf.comp g\n#align uniform_cauchy_seq_on.comp UniformCauchySeqOn.comp\n\n/-- Composing on the left by a uniformly continuous function preserves\nuniform Cauchy sequences -/\ntheorem UniformContinuous.comp_uniformCauchySeqOn [UniformSpace \u03b3] {g : \u03b2 \u2192 \u03b3}\n    (hg : UniformContinuous g) (hf : UniformCauchySeqOn F p s) :\n    UniformCauchySeqOn (fun n => g \u2218 F n) p s := fun _u hu => hf _ (hg hu)\n#align uniform_continuous.comp_uniform_cauchy_seq_on UniformContinuous.comp_uniformCauchySeqOn\n\ntheorem UniformCauchySeqOn.prod_map {\u03b9' \u03b1' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1' \u2192 \u03b2'}\n    {p' : Filter \u03b9'} {s' : Set \u03b1'} (h : UniformCauchySeqOn F p s)\n    (h' : UniformCauchySeqOn F' p' s') :\n    UniformCauchySeqOn (fun i : \u03b9 \u00d7 \u03b9' => Prod.map (F i.1) (F' i.2)) (p \u00d7\u1da0 p') (s \u00d7\u02e2 s') := by\n  intro u hu\n  rw [uniformity_prod_eq_prod, mem_map, mem_prod_iff] at hu\n  obtain \u27e8v, hv, w, hw, hvw\u27e9 := hu\n  simp_rw [mem_prod, Prod_map, and_imp, Prod.forall]\n  rw [\u2190 Set.image_subset_iff] at hvw\n  apply (tendsto_swap4_prod.eventually ((h v hv).prod_mk (h' w hw))).mono\n  intro x hx a b ha hb\n  refine' hvw \u27e8_, mk_mem_prod (hx.1 a ha) (hx.2 b hb), rfl\u27e9\n#align uniform_cauchy_seq_on.prod_map UniformCauchySeqOn.prod_map\n\ntheorem UniformCauchySeqOn.prod {\u03b9' \u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9' \u2192 \u03b1 \u2192 \u03b2'}\n    {p' : Filter \u03b9'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s) :\n    UniformCauchySeqOn (fun (i : \u03b9 \u00d7 \u03b9') a => (F i.fst a, F' i.snd a)) (p \u00d7\u1da0 p') s :=\n  (congr_arg _ s.inter_self).mp ((h.prod_map h').comp fun a => (a, a))\n#align uniform_cauchy_seq_on.prod UniformCauchySeqOn.prod\n\ntheorem UniformCauchySeqOn.prod' {\u03b2' : Type _} [UniformSpace \u03b2'] {F' : \u03b9 \u2192 \u03b1 \u2192 \u03b2'}\n    (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p s) :\n    UniformCauchySeqOn (fun (i : \u03b9) a => (F i a, F' i a)) p s := fun u hu =>\n  have hh : Tendsto (fun x : \u03b9 => (x, x)) p (p \u00d7\u1da0 p) := tendsto_diag\n  (hh.prod_map hh).eventually ((h.prod h') u hu)\n#align uniform_cauchy_seq_on.prod' UniformCauchySeqOn.prod'\n\n/-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form\na Cauchy sequence. -/\ntheorem UniformCauchySeqOn.cauchy_map [hp : NeBot p] (hf : UniformCauchySeqOn F p s) (hx : x \u2208 s) :\n    Cauchy (map (fun i => F i x) p) := by\n  simp only [cauchy_map_iff, hp, true_and_iff]\n  intro u hu\n  rw [mem_map]\n  filter_upwards [hf u hu]with p hp using hp x hx\n#align uniform_cauchy_seq_on.cauchy_map UniformCauchySeqOn.cauchy_map\n\nsection SeqTendsto\n\ntheorem tendstoUniformlyOn_of_seq_tendstoUniformlyOn {l : Filter \u03b9} [l.IsCountablyGenerated]\n    (h : \u2200 u : \u2115 \u2192 \u03b9, Tendsto u atTop l \u2192 TendstoUniformlyOn (fun n => F (u n)) f atTop s) :\n    TendstoUniformlyOn F f l s := by\n  rw [tendstoUniformlyOn_iff_tendsto, tendsto_iff_seq_tendsto]\n  intro u hu\n  rw [tendsto_prod_iff'] at hu\n  specialize h (fun n => (u n).fst) hu.1\n  rw [tendstoUniformlyOn_iff_tendsto] at h\n  exact h.comp (tendsto_id.prod_mk hu.2)\n#align tendsto_uniformly_on_of_seq_tendsto_uniformly_on tendstoUniformlyOn_of_seq_tendstoUniformlyOn\n\ntheorem TendstoUniformlyOn.seq_tendstoUniformlyOn {l : Filter \u03b9} (h : TendstoUniformlyOn F f l s)\n    (u : \u2115 \u2192 \u03b9) (hu : Tendsto u atTop l) : TendstoUniformlyOn (fun n => F (u n)) f atTop s := by\n  rw [tendstoUniformlyOn_iff_tendsto] at h\u22a2\n  exact h.comp ((hu.comp tendsto_fst).prod_mk tendsto_snd)\n#align tendsto_uniformly_on.seq_tendsto_uniformly_on TendstoUniformlyOn.seq_tendstoUniformlyOn\n\ntheorem tendstoUniformlyOn_iff_seq_tendstoUniformlyOn {l : Filter \u03b9} [l.IsCountablyGenerated] :\n    TendstoUniformlyOn F f l s \u2194\n      \u2200 u : \u2115 \u2192 \u03b9, Tendsto u atTop l \u2192 TendstoUniformlyOn (fun n => F (u n)) f atTop s :=\n  \u27e8TendstoUniformlyOn.seq_tendstoUniformlyOn, tendstoUniformlyOn_of_seq_tendstoUniformlyOn\u27e9\n#align tendsto_uniformly_on_iff_seq_tendsto_uniformly_on tendstoUniformlyOn_iff_seq_tendstoUniformlyOn\n\ntheorem tendstoUniformly_iff_seq_tendstoUniformly {l : Filter \u03b9} [l.IsCountablyGenerated] :\n    TendstoUniformly F f l \u2194\n      \u2200 u : \u2115 \u2192 \u03b9, Tendsto u atTop l \u2192 TendstoUniformly (fun n => F (u n)) f atTop := by\n  simp_rw [\u2190 tendstoUniformlyOn_univ]\n  exact tendstoUniformlyOn_iff_seq_tendstoUniformlyOn\n#align tendsto_uniformly_iff_seq_tendsto_uniformly tendstoUniformly_iff_seq_tendstoUniformly\n\nend SeqTendsto\n\nvariable [TopologicalSpace \u03b1]\n\n/-- A sequence of functions `F\u2099` converges locally uniformly on a set `s` to a limiting function\n`f` with respect to a filter `p` if, for any entourage of the diagonal `u`, for any `x \u2208 s`, one\nhas `p`-eventually `(f y, F\u2099 y) \u2208 u` for all `y` in a neighborhood of `x` in `s`. -/\ndef TendstoLocallyUniformlyOn (F : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) (p : Filter \u03b9) (s : Set \u03b1) :=\n  \u2200 u \u2208 \ud835\udce4 \u03b2, \u2200 x \u2208 s, \u2203 t \u2208 \ud835\udcdd[s] x, \u2200\u1da0 n in p, \u2200 y \u2208 t, (f y, F n y) \u2208 u\n#align tendsto_locally_uniformly_on TendstoLocallyUniformlyOn\n\n/-- A sequence of functions `F\u2099` converges locally uniformly to a limiting function `f` with respect\nto a filter `p` if, for any entourage of the diagonal `u`, for any `x`, one has `p`-eventually\n`(f y, F\u2099 y) \u2208 u` for all `y` in a neighborhood of `x`. -/\ndef TendstoLocallyUniformly (F : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) (p : Filter \u03b9) :=\n  \u2200 u \u2208 \ud835\udce4 \u03b2, \u2200 x : \u03b1, \u2203 t \u2208 \ud835\udcdd x, \u2200\u1da0 n in p, \u2200 y \u2208 t, (f y, F n y) \u2208 u\n#align tendsto_locally_uniformly TendstoLocallyUniformly\n\ntheorem tendstoLocallyUniformlyOn_univ :\n    TendstoLocallyUniformlyOn F f p univ \u2194 TendstoLocallyUniformly F f p := by\n  simp [TendstoLocallyUniformlyOn, TendstoLocallyUniformly, nhdsWithin_univ]\n#align tendsto_locally_uniformly_on_univ tendstoLocallyUniformlyOn_univ\n\n-- porting note: new lemma\ntheorem tendstoLocallyUniformlyOn_iff_forall_tendsto :\n    TendstoLocallyUniformlyOn F f p s \u2194\n      \u2200 x \u2208 s, Tendsto (fun y : \u03b9 \u00d7 \u03b1 => (f y.2, F y.1 y.2)) (p \u00d7\u1da0 \ud835\udcdd[s] x) (\ud835\udce4 \u03b2) :=\n  forall\u2082_swap.trans <| forall\u2084_congr fun _ _ _ _ => by\n    rw [mem_map, mem_prod_iff_right]; rfl\n\nnonrec theorem IsOpen.tendstoLocallyUniformlyOn_iff_forall_tendsto (hs : IsOpen s) :\n    TendstoLocallyUniformlyOn F f p s \u2194\n      \u2200 x \u2208 s, Tendsto (fun y : \u03b9 \u00d7 \u03b1 => (f y.2, F y.1 y.2)) (p \u00d7\u1da0 \ud835\udcdd x) (\ud835\udce4 \u03b2) :=\n  tendstoLocallyUniformlyOn_iff_forall_tendsto.trans <| forall\u2082_congr fun x hx => by\n    rw [hs.nhdsWithin_eq hx]\n\ntheorem tendstoLocallyUniformly_iff_forall_tendsto :\n    TendstoLocallyUniformly F f p \u2194\n      \u2200 x, Tendsto (fun y : \u03b9 \u00d7 \u03b1 => (f y.2, F y.1 y.2)) (p \u00d7\u1da0 \ud835\udcdd x) (\ud835\udce4 \u03b2) := by\n  simp [\u2190 tendstoLocallyUniformlyOn_univ, isOpen_univ.tendstoLocallyUniformlyOn_iff_forall_tendsto]\n#align tendsto_locally_uniformly_iff_forall_tendsto tendstoLocallyUniformly_iff_forall_tendsto\n\ntheorem tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe :\n    TendstoLocallyUniformlyOn F f p s \u2194\n      TendstoLocallyUniformly (fun i (x : s) => F i x) (f \u2218 (\u2191)) p := by\n  simp only [tendstoLocallyUniformly_iff_forall_tendsto, Subtype.forall', tendsto_map'_iff,\n    tendstoLocallyUniformlyOn_iff_forall_tendsto, \u2190 map_nhds_subtype_val, prod_map_right]; rfl\n#align tendsto_locally_uniformly_on_iff_tendsto_locally_uniformly_comp_coe tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe\n\nprotected theorem TendstoUniformlyOn.tendstoLocallyUniformlyOn (h : TendstoUniformlyOn F f p s) :\n    TendstoLocallyUniformlyOn F f p s := fun u hu x _ =>\n  \u27e8s, self_mem_nhdsWithin, by simpa using h u hu\u27e9\n#align tendsto_uniformly_on.tendsto_locally_uniformly_on TendstoUniformlyOn.tendstoLocallyUniformlyOn\n\nprotected theorem TendstoUniformly.tendstoLocallyUniformly (h : TendstoUniformly F f p) :\n    TendstoLocallyUniformly F f p := fun u hu x => \u27e8univ, univ_mem, by simpa using h u hu\u27e9\n#align tendsto_uniformly.tendsto_locally_uniformly TendstoUniformly.tendstoLocallyUniformly\n\ntheorem TendstoLocallyUniformlyOn.mono (h : TendstoLocallyUniformlyOn F f p s) (h' : s' \u2286 s) :\n    TendstoLocallyUniformlyOn F f p s' := by\n  intro u hu x hx\n  rcases h u hu x (h' hx) with \u27e8t, ht, H\u27e9\n  exact \u27e8t, nhdsWithin_mono x h' ht, H.mono fun n => id\u27e9\n#align tendsto_locally_uniformly_on.mono TendstoLocallyUniformlyOn.mono\n\n-- porting note: generalized from `Type` to `Sort`\ntheorem tendstoLocallyUniformlyOn_union\u1d62 {\u03b9' : Sort _} {S : \u03b9' \u2192 Set \u03b1} (hS : \u2200 i, IsOpen (S i))\n    (h : \u2200 i, TendstoLocallyUniformlyOn F f p (S i)) :\n    TendstoLocallyUniformlyOn F f p (\u22c3 i, S i) :=\n  (isOpen_union\u1d62 hS).tendstoLocallyUniformlyOn_iff_forall_tendsto.2 $ fun _x hx =>\n    let \u27e8i, hi\u27e9 := mem_union\u1d62.1 hx\n    (hS i).tendstoLocallyUniformlyOn_iff_forall_tendsto.1 (h i) _ hi\n#align tendsto_locally_uniformly_on_Union tendstoLocallyUniformlyOn_union\u1d62\n\ntheorem tendstoLocallyUniformlyOn_bunion\u1d62 {s : Set \u03b3} {S : \u03b3 \u2192 Set \u03b1} (hS : \u2200 i \u2208 s, IsOpen (S i))\n    (h : \u2200 i \u2208 s, TendstoLocallyUniformlyOn F f p (S i)) :\n    TendstoLocallyUniformlyOn F f p (\u22c3 i \u2208 s, S i) :=\n  tendstoLocallyUniformlyOn_union\u1d62 (fun i => isOpen_union\u1d62 (hS i)) fun i =>\n   tendstoLocallyUniformlyOn_union\u1d62 (hS i) (h i)\n#align tendsto_locally_uniformly_on_bUnion tendstoLocallyUniformlyOn_bunion\u1d62\n\ntheorem tendstoLocallyUniformlyOn_union\u209b (S : Set (Set \u03b1)) (hS : \u2200 s \u2208 S, IsOpen s)\n    (h : \u2200 s \u2208 S, TendstoLocallyUniformlyOn F f p s) : TendstoLocallyUniformlyOn F f p (\u22c3\u2080 S) := by\n  rw [union\u209b_eq_bunion\u1d62]\n  exact tendstoLocallyUniformlyOn_bunion\u1d62 hS h\n#align tendsto_locally_uniformly_on_sUnion tendstoLocallyUniformlyOn_union\u209b\n\ntheorem TendstoLocallyUniformlyOn.union {s\u2081 s\u2082 : Set \u03b1} (hs\u2081 : IsOpen s\u2081) (hs\u2082 : IsOpen s\u2082)\n    (h\u2081 : TendstoLocallyUniformlyOn F f p s\u2081) (h\u2082 : TendstoLocallyUniformlyOn F f p s\u2082) :\n    TendstoLocallyUniformlyOn F f p (s\u2081 \u222a s\u2082) := by\n  rw [\u2190 union\u209b_pair]\n  refine' tendstoLocallyUniformlyOn_union\u209b _ _ _ <;> simp [*]\n#align tendsto_locally_uniformly_on.union TendstoLocallyUniformlyOn.union\n\n-- porting note: tendstoLocallyUniformlyOn_univ moved up\n\nprotected theorem TendstoLocallyUniformly.tendstoLocallyUniformlyOn\n    (h : TendstoLocallyUniformly F f p) : TendstoLocallyUniformlyOn F f p s :=\n  (tendstoLocallyUniformlyOn_univ.mpr h).mono (subset_univ _)\n#align tendsto_locally_uniformly.tendsto_locally_uniformly_on TendstoLocallyUniformly.tendstoLocallyUniformlyOn\n\n/-- On a compact space, locally uniform convergence is just uniform convergence. -/\ntheorem tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace [CompactSpace \u03b1] :\n    TendstoLocallyUniformly F f p \u2194 TendstoUniformly F f p := by\n  refine' \u27e8fun h V hV => _, TendstoUniformly.tendstoLocallyUniformly\u27e9\n  choose U hU using h V hV\n  obtain \u27e8t, ht\u27e9 := isCompact_univ.elim_nhds_subcover' (fun k _ => U k) fun k _ => (hU k).1\n  replace hU := fun x : t => (hU x).2\n  rw [\u2190 eventually_all] at hU\n  refine' hU.mono fun i hi x => _\n  specialize ht (mem_univ x)\n  simp only [exists_prop, mem_union\u1d62, SetCoe.exists, exists_and_right, Subtype.coe_mk] at ht\n  obtain \u27e8y, \u27e8hy\u2081, hy\u2082\u27e9, hy\u2083\u27e9 := ht\n  exact hi \u27e8\u27e8y, hy\u2081\u27e9, hy\u2082\u27e9 x hy\u2083\n#align tendsto_locally_uniformly_iff_tendsto_uniformly_of_compact_space tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace\n\n/-- For a compact set `s`, locally uniform convergence on `s` is just uniform convergence on `s`. -/\ntheorem tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact (hs : IsCompact s) :\n    TendstoLocallyUniformlyOn F f p s \u2194 TendstoUniformlyOn F f p s := by\n  haveI : CompactSpace s := isCompact_iff_compactSpace.mp hs\n  refine' \u27e8fun h => _, TendstoUniformlyOn.tendstoLocallyUniformlyOn\u27e9\n  rwa [tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe,\n    tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace, \u2190\n    tendstoUniformlyOn_iff_tendstoUniformly_comp_coe] at h\n#align tendsto_locally_uniformly_on_iff_tendsto_uniformly_on_of_compact tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact\n\ntheorem TendstoLocallyUniformlyOn.comp [TopologicalSpace \u03b3] {t : Set \u03b3}\n    (h : TendstoLocallyUniformlyOn F f p s) (g : \u03b3 \u2192 \u03b1) (hg : MapsTo g t s)\n    (cg : ContinuousOn g t) : TendstoLocallyUniformlyOn (fun n => F n \u2218 g) (f \u2218 g) p t := by\n  intro u hu x hx\n  rcases h u hu (g x) (hg hx) with \u27e8a, ha, H\u27e9\n  have : g \u207b\u00b9' a \u2208 \ud835\udcdd[t] x :=\n    (cg x hx).preimage_mem_nhds_within' (nhdsWithin_mono (g x) hg.image_subset ha)\n  exact \u27e8g \u207b\u00b9' a, this, H.mono fun n hn y hy => hn _ hy\u27e9\n#align tendsto_locally_uniformly_on.comp TendstoLocallyUniformlyOn.comp\n\ntheorem TendstoLocallyUniformly.comp [TopologicalSpace \u03b3] (h : TendstoLocallyUniformly F f p)\n    (g : \u03b3 \u2192 \u03b1) (cg : Continuous g) : TendstoLocallyUniformly (fun n => F n \u2218 g) (f \u2218 g) p := by\n  rw [\u2190 tendstoLocallyUniformlyOn_univ] at h\u22a2\n  rw [continuous_iff_continuousOn_univ] at cg\n  exact h.comp _ (mapsTo_univ _ _) cg\n#align tendsto_locally_uniformly.comp TendstoLocallyUniformly.comp\n\nopen List in\ntheorem tendstoLocallyUniformlyOn_TFAE [LocallyCompactSpace \u03b1] (G : \u03b9 \u2192 \u03b1 \u2192 \u03b2) (g : \u03b1 \u2192 \u03b2)\n    (p : Filter \u03b9) (hs : IsOpen s) :\n    TFAE [TendstoLocallyUniformlyOn G g p s,\n          \u2200 K, K \u2286 s \u2192 IsCompact K \u2192 TendstoUniformlyOn G g p K,\n          \u2200 x \u2208 s, \u2203 v \u2208 \ud835\udcdd[s] x, TendstoUniformlyOn G g p v] := by\n  apply_rules [tfae_of_cycle, Chain.cons, Chain.nil] -- porting note: todo: use `tfae_have` or not?\n  \u00b7 exact fun h K hKs hKc =>\n      (tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hKc).mp (h.mono hKs)\n  \u00b7 rintro h x hx\n    obtain \u27e8K, \u27e8hK1, hK2\u27e9 ,hK3\u27e9 := (compact_basis_nhds x).mem_iff.mp (hs.mem_nhds hx)\n    refine' \u27e8K, nhdsWithin_le_nhds hK1 , h K hK3 hK2 \u27e9\n  \u00b7 rintro h u hu x hx\n    obtain \u27e8v, hv1, hv2\u27e9 := h x hx\n    exact \u27e8v, hv1, hv2 u hu\u27e9\n#align tendsto_locally_uniformly_on_tfae tendstoLocallyUniformlyOn_TFAE\n\ntheorem tendstoLocallyUniformlyOn_iff_forall_isCompact [LocallyCompactSpace \u03b1] (hs : IsOpen s) :\n    TendstoLocallyUniformlyOn F f p s \u2194 \u2200 K, K \u2286 s \u2192 IsCompact K \u2192 TendstoUniformlyOn F f p K :=\n  (tendstoLocallyUniformlyOn_TFAE F f p hs).out 0 1\n#align tendsto_locally_uniformly_on_iff_forall_is_compact tendstoLocallyUniformlyOn_iff_forall_isCompact\n\ntheorem tendstoLocallyUniformlyOn_iff_filter :\n    TendstoLocallyUniformlyOn F f p s \u2194 \u2200 x \u2208 s, TendstoUniformlyOnFilter F f p (\ud835\udcdd[s] x) := by\n  simp only [TendstoUniformlyOnFilter, eventually_prod_iff]\n  constructor\n  \u00b7 rintro h x hx u hu\n    obtain \u27e8s, hs1, hs2\u27e9 := h u hu x hx\n    exact \u27e8_, hs2, _, eventually_of_mem hs1 fun x => id, fun hi y hy => hi y hy\u27e9\n  \u00b7 rintro h u hu x hx\n    obtain \u27e8pa, hpa, pb, hpb, h\u27e9 := h x hx u hu\n    refine' \u27e8pb, hpb, eventually_of_mem hpa fun i hi y hy => h hi hy\u27e9\n#align tendsto_locally_uniformly_on_iff_filter tendstoLocallyUniformlyOn_iff_filter\n\ntheorem tendstoLocallyUniformly_iff_filter :\n    TendstoLocallyUniformly F f p \u2194 \u2200 x, TendstoUniformlyOnFilter F f p (\ud835\udcdd x) := by\n  simpa [\u2190 tendstoLocallyUniformlyOn_univ, \u2190 nhdsWithin_univ] using\n    @tendstoLocallyUniformlyOn_iff_filter _ _ _ _ F f univ p _\n#align tendsto_locally_uniformly_iff_filter tendstoLocallyUniformly_iff_filter\n\ntheorem TendstoLocallyUniformlyOn.tendsto_at (hf : TendstoLocallyUniformlyOn F f p s) {a : \u03b1}\n    (ha : a \u2208 s) : Tendsto (fun i => F i a) p (\ud835\udcdd (f a)) := by\n  refine' ((tendstoLocallyUniformlyOn_iff_filter.mp hf) a ha).tendsto_at _\n  simpa only [Filter.principal_singleton] using pure_le_nhdsWithin ha\n#align tendsto_locally_uniformly_on.tendsto_at TendstoLocallyUniformlyOn.tendsto_at\n\ntheorem TendstoLocallyUniformlyOn.unique [p.NeBot] [T2Space \u03b2] {g : \u03b1 \u2192 \u03b2}\n    (hf : TendstoLocallyUniformlyOn F f p s) (hg : TendstoLocallyUniformlyOn F g p s) :\n    s.EqOn f g := fun _a ha => tendsto_nhds_unique (hf.tendsto_at ha) (hg.tendsto_at ha)\n#align tendsto_locally_uniformly_on.unique TendstoLocallyUniformlyOn.unique\n\ntheorem TendstoLocallyUniformlyOn.congr {G : \u03b9 \u2192 \u03b1 \u2192 \u03b2} (hf : TendstoLocallyUniformlyOn F f p s)\n    (hg : \u2200 n, s.EqOn (F n) (G n)) : TendstoLocallyUniformlyOn G f p s := by\n  rintro u hu x hx\n  obtain \u27e8t, ht, h\u27e9 := hf u hu x hx\n  refine' \u27e8s \u2229 t, inter_mem self_mem_nhdsWithin ht, _\u27e9\n  filter_upwards [h]with i hi y hy using hg i hy.1 \u25b8 hi y hy.2\n#align tendsto_locally_uniformly_on.congr TendstoLocallyUniformlyOn.congr\n\ntheorem TendstoLocallyUniformlyOn.congr_right {g : \u03b1 \u2192 \u03b2} (hf : TendstoLocallyUniformlyOn F f p s)\n    (hg : s.EqOn f g) : TendstoLocallyUniformlyOn F g p s := by\n  rintro u hu x hx\n  obtain \u27e8t, ht, h\u27e9 := hf u hu x hx\n  refine' \u27e8s \u2229 t, inter_mem self_mem_nhdsWithin ht, _\u27e9\n  filter_upwards [h]with i hi y hy using hg hy.1 \u25b8 hi y hy.2\n#align tendsto_locally_uniformly_on.congr_right TendstoLocallyUniformlyOn.congr_right\n\n/-!\n### Uniform approximation\n\nIn this section, we give lemmas ensuring that a function is continuous if it can be approximated\nuniformly by continuous functions. We give various versions, within a set or the whole space, at\na single point or at all points, with locally uniform approximation or uniform approximation. All\nthe statements are derived from a statement about locally uniform approximation within a set at\na point, called `continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt`. -/\n\n\n/-- A function which can be locally uniformly approximated by functions which are continuous\nwithin a set at a point is continuous within this set at this point. -/\ntheorem continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt (hx : x \u2208 s)\n    (L : \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 t \u2208 \ud835\udcdd[s] x, \u2203 F : \u03b1 \u2192 \u03b2, ContinuousWithinAt F s x \u2227 \u2200 y \u2208 t, (f y, F y) \u2208 u) :\n    ContinuousWithinAt f s x := by\n  refine Uniform.continuousWithinAt_iff'_left.2 fun u\u2080 hu\u2080 => ?_\n  obtain \u27e8u\u2081, h\u2081, u\u2081\u2080\u27e9 : \u2203 u \u2208 \ud835\udce4 \u03b2, u \u25cb u \u2286 u\u2080 := comp_mem_uniformity_sets hu\u2080\n  obtain \u27e8u\u2082, h\u2082, hsymm, u\u2082\u2081\u27e9 : \u2203 u \u2208 \ud835\udce4 \u03b2, (\u2200 {a b}, (a, b) \u2208 u \u2192 (b, a) \u2208 u) \u2227 u \u25cb u \u2286 u\u2081 :=\n    comp_symm_of_uniformity h\u2081\n  rcases L u\u2082 h\u2082 with \u27e8t, tx, F, hFc, hF\u27e9\n  have A : \u2200\u1da0 y in \ud835\udcdd[s] x, (f y, F y) \u2208 u\u2082 := Eventually.mono tx hF\n  have B : \u2200\u1da0 y in \ud835\udcdd[s] x, (F y, F x) \u2208 u\u2082 := Uniform.continuousWithinAt_iff'_left.1 hFc h\u2082\n  have C : \u2200\u1da0 y in \ud835\udcdd[s] x, (f y, F x) \u2208 u\u2081 :=\n    (A.and B).mono fun y hy => u\u2082\u2081 (prod_mk_mem_compRel hy.1 hy.2)\n  have : (F x, f x) \u2208 u\u2081 :=\n    u\u2082\u2081 (prod_mk_mem_compRel (refl_mem_uniformity h\u2082) (hsymm (A.self_of_nhdsWithin hx)))\n  exact C.mono fun y hy => u\u2081\u2080 (prod_mk_mem_compRel hy this)\n#align continuous_within_at_of_locally_uniform_approx_of_continuous_within_at continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt\n\n/-- A function which can be locally uniformly approximated by functions which are continuous at\na point is continuous at this point. -/\ntheorem continuousAt_of_locally_uniform_approx_of_continuousAt\n    (L : \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 t \u2208 \ud835\udcdd x, \u2203 F, ContinuousAt F x \u2227 \u2200 y \u2208 t, (f y, F y) \u2208 u) :\n    ContinuousAt f x := by\n  rw [\u2190 continuousWithinAt_univ]\n  apply continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt (mem_univ _) _\n  simpa only [exists_prop, nhdsWithin_univ, continuousWithinAt_univ] using L\n#align continuous_at_of_locally_uniform_approx_of_continuous_at continuousAt_of_locally_uniform_approx_of_continuousAt\n\n/-- A function which can be locally uniformly approximated by functions which are continuous\non a set is continuous on this set. -/\ntheorem continuousOn_of_locally_uniform_approx_of_continuousWithinAt\n    (L : \u2200 x \u2208 s, \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 t \u2208 \ud835\udcdd[s] x, \u2203 F,\n      ContinuousWithinAt F s x \u2227 \u2200 y \u2208 t, (f y, F y) \u2208 u) :\n    ContinuousOn f s := fun x hx =>\n  continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt hx (L x hx)\n#align continuous_on_of_locally_uniform_approx_of_continuous_within_at continuousOn_of_locally_uniform_approx_of_continuousWithinAt\n\n/-- A function which can be uniformly approximated by functions which are continuous on a set\nis continuous on this set. -/\ntheorem continuousOn_of_uniform_approx_of_continuousOn\n    (L : \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 F, ContinuousOn F s \u2227 \u2200 y \u2208 s, (f y, F y) \u2208 u) : ContinuousOn f s :=\n  continuousOn_of_locally_uniform_approx_of_continuousWithinAt fun _x hx u hu =>\n    \u27e8s, self_mem_nhdsWithin, (L u hu).imp fun _F hF => \u27e8hF.1.continuousWithinAt hx, hF.2\u27e9\u27e9\n#align continuous_on_of_uniform_approx_of_continuous_on continuousOn_of_uniform_approx_of_continuousOn\n\n/-- A function which can be locally uniformly approximated by continuous functions is continuous. -/\ntheorem continuous_of_locally_uniform_approx_of_continuousAt\n    (L : \u2200 x : \u03b1, \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 t \u2208 \ud835\udcdd x, \u2203 F, ContinuousAt F x \u2227 \u2200 y \u2208 t, (f y, F y) \u2208 u) :\n    Continuous f :=\n  continuous_iff_continuousAt.2 fun x =>\n    continuousAt_of_locally_uniform_approx_of_continuousAt (L x)\n#align continuous_of_locally_uniform_approx_of_continuous_at continuous_of_locally_uniform_approx_of_continuousAt\n\n/-- A function which can be uniformly approximated by continuous functions is continuous. -/\ntheorem continuous_of_uniform_approx_of_continuous\n    (L : \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 F, Continuous F \u2227 \u2200 y, (f y, F y) \u2208 u) : Continuous f :=\n  continuous_iff_continuousOn_univ.mpr <|\n    continuousOn_of_uniform_approx_of_continuousOn <| by\n      simpa [continuous_iff_continuousOn_univ] using L\n#align continuous_of_uniform_approx_of_continuous continuous_of_uniform_approx_of_continuous\n\n/-!\n### Uniform limits\n\nFrom the previous statements on uniform approximation, we deduce continuity results for uniform\nlimits.\n-/\n\n\n/-- A locally uniform limit on a set of functions which are continuous on this set is itself\ncontinuous on this set. -/\nprotected theorem TendstoLocallyUniformlyOn.continuousOn (h : TendstoLocallyUniformlyOn F f p s)\n    (hc : \u2200\u1da0 n in p, ContinuousOn (F n) s) [NeBot p] : ContinuousOn f s := by\n  refine continuousOn_of_locally_uniform_approx_of_continuousWithinAt fun x hx u hu => ?_\n  rcases h u hu x hx with \u27e8t, ht, H\u27e9\n  rcases (hc.and H).exists with \u27e8n, hFc, hF\u27e9\n  exact \u27e8t, ht, \u27e8F n, hFc.continuousWithinAt hx, hF\u27e9\u27e9\n#align tendsto_locally_uniformly_on.continuous_on TendstoLocallyUniformlyOn.continuousOn\n\n/-- A uniform limit on a set of functions which are continuous on this set is itself continuous\non this set. -/\nprotected theorem TendstoUniformlyOn.continuousOn (h : TendstoUniformlyOn F f p s)\n    (hc : \u2200\u1da0 n in p, ContinuousOn (F n) s) [NeBot p] : ContinuousOn f s :=\n  h.tendstoLocallyUniformlyOn.continuousOn hc\n#align tendsto_uniformly_on.continuous_on TendstoUniformlyOn.continuousOn\n\n/-- A locally uniform limit of continuous functions is continuous. -/\nprotected theorem TendstoLocallyUniformly.continuous (h : TendstoLocallyUniformly F f p)\n    (hc : \u2200\u1da0 n in p, Continuous (F n)) [NeBot p] : Continuous f :=\n  continuous_iff_continuousOn_univ.mpr <|\n    h.tendstoLocallyUniformlyOn.continuousOn <| hc.mono fun _n hn => hn.continuousOn\n#align tendsto_locally_uniformly.continuous TendstoLocallyUniformly.continuous\n\n/-- A uniform limit of continuous functions is continuous. -/\nprotected theorem TendstoUniformly.continuous (h : TendstoUniformly F f p)\n    (hc : \u2200\u1da0 n in p, Continuous (F n)) [NeBot p] : Continuous f :=\n  h.tendstoLocallyUniformly.continuous hc\n#align tendsto_uniformly.continuous TendstoUniformly.continuous\n\n/-!\n### Composing limits under uniform convergence\n\nIn general, if `F\u2099` converges pointwise to a function `f`, and `g\u2099` tends to `x`, it is not true\nthat `F\u2099 g\u2099` tends to `f x`. It is true however if the convergence of `F\u2099` to `f` is uniform. In\nthis paragraph, we prove variations around this statement.\n-/\n\n\n/-- If `F\u2099` converges locally uniformly on a neighborhood of `x` within a set `s` to a function `f`\nwhich is continuous at `x` within `s `, and `g\u2099` tends to `x` within `s`, then `F\u2099 (g\u2099)` tends\nto `f x`. -/\ntheorem tendsto_comp_of_locally_uniform_limit_within (h : ContinuousWithinAt f s x)\n    (hg : Tendsto g p (\ud835\udcdd[s] x))\n    (hunif : \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 t \u2208 \ud835\udcdd[s] x, \u2200\u1da0 n in p, \u2200 y \u2208 t, (f y, F n y) \u2208 u) :\n    Tendsto (fun n => F n (g n)) p (\ud835\udcdd (f x)) := by\n  refine Uniform.tendsto_nhds_right.2 fun u\u2080 hu\u2080 => ?_\n  obtain \u27e8u\u2081, h\u2081, u\u2081\u2080\u27e9 : \u2203 u \u2208 \ud835\udce4 \u03b2, u \u25cb u \u2286 u\u2080 := comp_mem_uniformity_sets hu\u2080\n  rcases hunif u\u2081 h\u2081 with \u27e8s, sx, hs\u27e9\n  have A : \u2200\u1da0 n in p, g n \u2208 s := hg sx\n  have B : \u2200\u1da0 n in p, (f x, f (g n)) \u2208 u\u2081 := hg (Uniform.continuousWithinAt_iff'_right.1 h h\u2081)\n  exact B.mp <| A.mp <| hs.mono fun y H1 H2 H3 => u\u2081\u2080 (prod_mk_mem_compRel H3 (H1 _ H2))\n#align tendsto_comp_of_locally_uniform_limit_within tendsto_comp_of_locally_uniform_limit_within\n\n/-- If `F\u2099` converges locally uniformly on a neighborhood of `x` to a function `f` which is\ncontinuous at `x`, and `g\u2099` tends to `x`, then `F\u2099 (g\u2099)` tends to `f x`. -/\ntheorem tendsto_comp_of_locally_uniform_limit (h : ContinuousAt f x) (hg : Tendsto g p (\ud835\udcdd x))\n    (hunif : \u2200 u \u2208 \ud835\udce4 \u03b2, \u2203 t \u2208 \ud835\udcdd x, \u2200\u1da0 n in p, \u2200 y \u2208 t, (f y, F n y) \u2208 u) :\n    Tendsto (fun n => F n (g n)) p (\ud835\udcdd (f x)) := by\n  rw [\u2190 continuousWithinAt_univ] at h\n  rw [\u2190 nhdsWithin_univ] at hunif hg\n  exact tendsto_comp_of_locally_uniform_limit_within h hg hunif\n#align tendsto_comp_of_locally_uniform_limit tendsto_comp_of_locally_uniform_limit\n\n/-- If `F\u2099` tends locally uniformly to `f` on a set `s`, and `g\u2099` tends to `x` within `s`, then\n`F\u2099 g\u2099` tends to `f x` if `f` is continuous at `x` within `s` and `x \u2208 s`. -/\ntheorem TendstoLocallyUniformlyOn.tendsto_comp (h : TendstoLocallyUniformlyOn F f p s)\n    (hf : ContinuousWithinAt f s x) (hx : x \u2208 s) (hg : Tendsto g p (\ud835\udcdd[s] x)) :\n    Tendsto (fun n => F n (g n)) p (\ud835\udcdd (f x)) :=\n  tendsto_comp_of_locally_uniform_limit_within hf hg fun u hu => h u hu x hx\n#align tendsto_locally_uniformly_on.tendsto_comp TendstoLocallyUniformlyOn.tendsto_comp\n\n/-- If `F\u2099` tends uniformly to `f` on a set `s`, and `g\u2099` tends to `x` within `s`, then `F\u2099 g\u2099`\ntends to `f x` if `f` is continuous at `x` within `s`. -/\ntheorem TendstoUniformlyOn.tendsto_comp (h : TendstoUniformlyOn F f p s)\n    (hf : ContinuousWithinAt f s x) (hg : Tendsto g p (\ud835\udcdd[s] x)) :\n    Tendsto (fun n => F n (g n)) p (\ud835\udcdd (f x)) :=\n  tendsto_comp_of_locally_uniform_limit_within hf hg fun u hu => \u27e8s, self_mem_nhdsWithin, h u hu\u27e9\n#align tendsto_uniformly_on.tendsto_comp TendstoUniformlyOn.tendsto_comp\n\n/-- If `F\u2099` tends locally uniformly to `f`, and `g\u2099` tends to `x`, then `F\u2099 g\u2099` tends to `f x`. -/\ntheorem TendstoLocallyUniformly.tendsto_comp (h : TendstoLocallyUniformly F f p)\n    (hf : ContinuousAt f x) (hg : Tendsto g p (\ud835\udcdd x)) : Tendsto (fun n => F n (g n)) p (\ud835\udcdd (f x)) :=\n  tendsto_comp_of_locally_uniform_limit hf hg fun u hu => h u hu x\n#align tendsto_locally_uniformly.tendsto_comp TendstoLocallyUniformly.tendsto_comp\n\n/-- If `F\u2099` tends uniformly to `f`, and `g\u2099` tends to `x`, then `F\u2099 g\u2099` tends to `f x`. -/\ntheorem TendstoUniformly.tendsto_comp (h : TendstoUniformly F f p) (hf : ContinuousAt f x)\n    (hg : Tendsto g p (\ud835\udcdd x)) : Tendsto (fun n => F n (g n)) p (\ud835\udcdd (f x)) :=\n  h.tendstoLocallyUniformly.tendsto_comp hf hg\n#align tendsto_uniformly.tendsto_comp TendstoUniformly.tendsto_comp\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/UniformSpace/UniformConvergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7119464798587092}}
{"text": "import integer.definition natural.addition tactic.nth_rewrite natural.equality\n\nnamespace Z\n\ndef sub_helper : N -> N -> Z\n| 0 0                   := 0\n| 0 (N.succ a)          := neg_succ a\n| a 0                   := pos a\n| (N.succ a) (N.succ b) := sub_helper a b\n\ndef add : Z -> Z -> Z\n| (pos a) (pos b)           := pos (a + b)\n| (pos a) (neg_succ b)      := sub_helper a (b + 1)\n| (neg_succ a) (pos b)      := sub_helper b (a + 1)\n| (neg_succ a) (neg_succ b) := neg_succ (a + b + 1)\n\ndef sub : Z -> Z -> Z\n| (pos a) (pos b)           := sub_helper a b\n| (pos a) (neg_succ b)      := pos (a + b + 1)\n| (neg_succ a) (pos b)      := neg_succ (a + b)\n| (neg_succ a) (neg_succ b) := sub_helper b a\n\ndef neg : Z -> Z\n| (pos 0)          := pos 0\n| (pos (N.succ a)) := neg_succ a\n| (neg_succ a)     := pos (a + 1)\n\ninstance : has_add Z := \u27e8 Z.add \u27e9 \ninstance : has_sub Z := \u27e8 Z.sub \u27e9 \ninstance : has_neg Z := \u27e8 Z.neg \u27e9\n\ndef two := pos (N.succ 1)\ntheorem two_eq_two : two = 2 := rfl\n\nlemma pos_add_pos (a b : N) : (pos a) + (pos b) = pos (a + b) := rfl\nlemma pos_add_neg (a b : N) : (pos a) + (neg_succ b) = sub_helper a (b + 1) := rfl\nlemma neg_add_pos (a b : N) : (neg_succ a) + (pos b) = sub_helper b (a + 1) := rfl\nlemma neg_add_neg (a b : N) : (neg_succ a) + (neg_succ b) = neg_succ (a + b + 1) := rfl\n\nlemma zero_sub_helper_zero : sub_helper 0 0 = 0 := rfl\nlemma zero_sub_helper_succ (a : N) : sub_helper 0 (N.succ a) = neg_succ a := rfl\nlemma succ_sub_helper_zero (a : N) : sub_helper (N.succ a) 0 = pos (N.succ a) := rfl\nlemma succ_sub_helper_succ (a b : N) : sub_helper (N.succ a) (N.succ b) = sub_helper a b := rfl\n\nlemma pos_sub_pos (a b : N) : (pos a) - (pos b) = sub_helper a b := rfl\nlemma pos_sub_neg (a b : N) : (pos a) - (neg_succ b) = pos (a + b + 1) := rfl\nlemma neg_sub_pos (a b : N) : (neg_succ a) - (pos b) = neg_succ (a + b) := rfl\nlemma neg_sub_neg (a b : N) : (neg_succ a) - (neg_succ b) = sub_helper b a := rfl\n\nlemma neg_zero : neg 0 = 0 := rfl\nlemma neg_pos_succ (a : N) : neg (pos (N.succ a)) = neg_succ a := rfl\nlemma neg_neg_succ (a : N) : neg (neg_succ a) = pos (a + 1) := rfl\n\nlemma zero_sub (a : Z) : 0 - a = neg a :=\nbegin\n  rw \u2190 zero_eq_zero,\n  cases a,\n  rw pos_sub_pos,\n  rw N.zero_eq_zero,\n  cases a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw \u2190 N.zero_eq_zero,\n  rw zero_eq_zero,\n  rw neg_zero,\n  rw zero_sub_helper_succ,\n  rw neg_pos_succ,\n  rw pos_sub_neg,\n  rw neg_neg_succ,\n  rw N.zero_eq_zero,\n  rw N.zero_add,\nend\n\nlemma sub_helper_eq (a : N) : sub_helper a a = 0 := \nbegin\n  induction a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw succ_sub_helper_succ,\n  exact a_ih,\nend\n\nlemma sub_eq (a : Z) : a - a = 0 :=\nbegin\n  cases a,\n  rw pos_sub_pos,\n  rw sub_helper_eq,\n  rw neg_sub_neg,\n  rw sub_helper_eq,\nend\n\nlemma sub_helper_zero (a : N) : sub_helper a 0 = pos a := \nbegin\n  cases a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw \u2190 zero_eq_zero,\n  rw N.zero_eq_zero,\n  rw succ_sub_helper_zero,\nend\n\nlemma zero_sub_helper_eq_r (a : N) : (sub_helper 0 a = 0) -> (a = 0) := \nbegin\n  intro h,\n  cases a,\n  rw N.zero_eq_zero,\n  exfalso,\n  rw zero_sub_helper_succ at h,\n  cases h,\nend\n\nlemma zero_sub_helper_eq_l (a : N) : (sub_helper a 0 = 0) -> (a = 0) := \nbegin\n  intro h,\n  cases a,\n  rw N.zero_eq_zero,\n  exfalso,\n  rw succ_sub_helper_zero at h,\n  cases h,\nend\n\nlemma zero_sub_helper_eq : \u2200 a b : N, (sub_helper a b = 0) -> (a = b)\n| 0 0 := \nbegin\n  intro h,\n  refl,\nend\n| 0 (N.succ a) := \nbegin\n  intro h,\n  exfalso,\n  have s := zero_sub_helper_eq_r (N.succ a) h,\n  cases h,\nend\n| (N.succ a) 0 := \nbegin\n  intro h,\n  exfalso,\n  have s := zero_sub_helper_eq_l (N.succ a) h,\n  cases h,\nend\n| (N.succ a) (N.succ b) := \nbegin\n  intro h,\n  rw succ_sub_helper_succ at h,\n  have q := zero_sub_helper_eq a b h,\n  exact (N.eq_succ a b q),\nend\n\nlemma pos_eq_pos (a b : N) : (pos a = pos b) -> a = b :=\nbegin\n  intro h,\n  have s := sub_eq (pos a),\n  nth_rewrite 1 h at s,\n  rw pos_sub_pos at s,\n  exact (zero_sub_helper_eq a b s),\nend\n\nlemma neg_eq_neg (a b : N) : (neg_succ a = neg_succ b) -> (a = b) :=\nbegin\n  intro h,\n  have s := sub_eq (neg_succ a),\n  nth_rewrite 1 h at s,\n  rw neg_sub_neg at s,\n  have t := zero_sub_helper_eq b a s,\n  rw t,\nend\n\nlemma neg_succ_sub (a b : N) : (neg_succ a) - (pos b) = neg_succ (a + b) :=\nbegin\n  rw neg_sub_pos,\nend\n\nlemma neg_succ_eq_neg_succ (a : N) : neg_succ a = neg (pos a)-1 := \nbegin\n  cases a,\n  rw zero_eq_zero,\n  rw neg_zero,\n  rw zero_sub,\n  rw \u2190 one_eq_one,\n  rw one,\n  rw neg_pos_succ,\n  rw N.zero_eq_zero,\n  rw neg_pos_succ,\n  rw \u2190 one_eq_one,\n  rw one,\n  rw neg_succ_sub,\n  rw N.add_succ,\n  rw N.add_zero,\nend\n\nlemma zero_add (a : Z) : 0 + a = a :=\nbegin\n  rw \u2190 zero_eq_zero,\n  cases a,\n  rw pos_add_pos,\n  rw N.zero_eq_zero,\n  rw N.zero_add,\n  rw pos_add_neg,\n  rw \u2190 N.one_eq_one,\n  rw N.one,\n  rw N.add_succ,\n  rw N.add_zero,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_succ,\nend\n\nlemma add_zero (a : Z) : a + 0 = a :=\nbegin\n  rw \u2190 zero_eq_zero,\n  cases a,\n  rw pos_add_pos,\n  rw N.zero_eq_zero,\n  rw N.add_zero,\n  rw neg_add_pos,\n  rw \u2190 N.one_eq_one, rw N.one,\n  rw N.add_succ,\n  rw N.add_zero,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_succ,\nend\n\nlemma sub_zero (a : Z) : a - 0 = a :=\nbegin\n  rw \u2190 zero_eq_zero,\n  cases a,\n  rw pos_sub_pos,\n  rw N.zero_eq_zero,\n  rw sub_helper_zero,\n  rw neg_sub_pos,\n  rw N.zero_eq_zero,\n  rw N.add_zero,\nend\n\ntheorem sub_eq_neg_add (a b : Z) : a - b = a + (neg b) := \nbegin\n  cases b,\n  cases b,\n  rw zero_eq_zero,\n  rw neg_zero,\n  rw add_zero,\n  rw sub_zero,\n  rw neg_pos_succ,\n  cases a,\n  rw pos_sub_pos,\n  rw pos_add_neg,\n  rw N.succ_eq_inc,\n  rw neg_sub_pos,\n  rw neg_add_neg,\n  rw N.succ_eq_inc,\n  rw N.add_assoc,\n  rw neg_neg_succ,\n  cases a,\n  rw pos_sub_neg,\n  rw pos_add_pos,\n  rw N.add_assoc,\n  rw neg_sub_neg,\n  rw neg_add_pos,\n  repeat {rw \u2190 N.succ_eq_inc},\n  rw succ_sub_helper_succ,\nend\n\ndef neg_succ_Z (a : Z) := -a-1\n\nlemma neg_succ_Z_eq_neg_succ (a : Z) : neg_succ_Z a = (neg a) - 1 := rfl\n\ntheorem double_neg_succ_is_eq (a : Z) : neg_succ_Z (neg_succ_Z a) = a :=\nbegin\n  rw neg_succ_Z_eq_neg_succ,\n  rw neg_succ_Z_eq_neg_succ,\n  cases a,\n  cases a,\n  rw zero_eq_zero,\n  rw neg_zero,\n  rw zero_sub,\n  rw \u2190 one_eq_one,\n  rw one,\n  rw neg_pos_succ,\n  rw neg_neg_succ,\n  rw N.zero_add,\n  rw \u2190 N.one_eq_one,\n  rw N.one,\n  rw sub_eq,\n  rw neg_pos_succ,\n  rw \u2190 one_eq_one,\n  rw one,\n  rw neg_succ_sub,\n  rw neg_neg_succ,\n  rw pos_sub_pos,\n  rw N.add_succ,\n  rw N.succ_add,\n  rw succ_sub_helper_succ,\n  rw N.add_zero,\n  rw \u2190 N.one_eq_one,\n  rw N.one,\n  rw N.add_succ,\n  rw succ_sub_helper_zero,\n  rw N.add_zero,\n  rw neg_neg_succ,\n  rw \u2190 one_eq_one,\n  rw one,\n  rw pos_sub_pos,\n  rw \u2190 N.one_eq_one,\n  rw N.one,\n  rw N.add_succ,\n  rw succ_sub_helper_succ,\n  rw N.add_zero,\n  cases a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw neg_zero,\n  rw zero_sub,\n  rw neg_pos_succ,\n  rw succ_sub_helper_zero,\n  rw neg_pos_succ,\n  rw neg_sub_pos,\n  rw N.add_succ,\n  rw N.add_zero,\nend\n\nlemma succ_eq_inc (a : N) : pos (N.succ a) = pos a + 1 := begin\n  rw \u2190 one_eq_one,\n  rw one,\n  rw pos_add_pos,\n  rw N.add_succ,\n  rw N.add_zero,\nend\n\nlemma succ_eq_inc_l (a : N) : pos (N.succ a) = 1 + pos a :=\nbegin\n  rw \u2190 one_eq_one,\n  rw one,\n  rw pos_add_pos,\n  rw N.succ_add,\n  rw N.zero_add,\nend\n\nlemma left_add_one_eq (a b : Z) : (1 + a = 1 + b) -> (a = b) :=\nbegin\n  intro h,\n  cases a,\n  cases b,\n  rw \u2190 one_eq_one at h,\n  rw one at h,\n  repeat {rw pos_add_pos at h},\n  have q := pos_eq_pos (N.succ 0 + a) (N.succ 0 + b) h,\n  have t := N.add_eq a b (N.succ 0) q,\n  exact (eq_pos_eq a b t),\n  rw \u2190 one_eq_one at h, rw one at h,\n  rw pos_add_pos at h,\n  rw N.succ_add at h,\n  rw N.zero_add at h,\n  rw pos_add_neg at h,\n  rw \u2190 N.one_eq_one at h, rw N.one at h,\n  rw N.add_succ at h,\n  rw N.add_zero at h,\n  rw succ_sub_helper_succ at h,\n  cases b,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  rw \u2190 zero_eq_zero at h,\n  have q := pos_eq_pos (N.succ a) (N.zero) h,\n  exfalso,\n  rw N.zero_eq_zero at q,\n  have t := N.eq_comm (N.succ a) 0 q,\n  exact (N.zero_neq_succ a t),\n  rw zero_sub_helper_succ at h,\n  exfalso,\n  exact (pos_neq_neg (N.succ a) b h),\n  cases b,\n  rw \u2190 one_eq_one at h, rw one at h,\n  rw pos_add_pos at h,\n  rw N.succ_add at h,\n  rw N.zero_add at h,\n  rw pos_add_neg at h,\n  rw \u2190 N.one_eq_one at h, rw N.one at h,\n  rw N.add_succ at h,\n  rw N.add_zero at h,\n  rw succ_sub_helper_succ at h,\n  cases a,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  rw \u2190 zero_eq_zero at h,\n  rw N.zero_eq_zero at h,\n  have q := pos_eq_pos 0 (N.succ b) h,\n  exfalso,\n  exact (N.zero_neq_succ b q),\n  rw zero_sub_helper_succ at h,\n  exfalso,\n  exact (neg_neq_pos a (N.succ b) h),\n  rw \u2190 one_eq_one at h, rw one at h,\n  repeat {rw pos_add_neg at h},\n  rw \u2190 N.one_eq_one at h, rw N.one at h,\n  repeat {rw N.add_succ at h,rw N.add_zero at h},\n  repeat {rw succ_sub_helper_succ at h},\n  cases a,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  cases b,\n  refl,\n  rw zero_sub_helper_succ at h,\n  exfalso,\n  exact (pos_neq_neg 0 b h),\n  rw zero_sub_helper_succ at h,\n  cases b,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  exfalso,\n  exact (neg_neq_pos a 0 h),\n  rw zero_sub_helper_succ at h,\n  have t := neg_eq_neg a b h,\n  exact (eq_neg_eq (N.succ a) (N.succ b) (N.eq_succ a b t)),\nend\n\nlemma one_add_comm (a : Z) : 1 + a = a + 1 :=\nbegin\n  rw \u2190 one_eq_one, rw one,\n  cases a,\n  repeat {rw pos_add_pos},\n  rw N.succ_add,\n  rw N.zero_add,\n  rw N.add_succ,\n  rw N.add_zero,\n  rw pos_add_neg,\n  rw neg_add_pos,\nend\n\nlemma one_sub_comm (a : Z) : neg 1 + a = a - 1 :=\nbegin\n  rw \u2190 one_eq_one, rw one,\n  rw neg_pos_succ,\n  cases a,\n  rw neg_add_pos,\n  rw pos_sub_pos,\n  rw N.succ_eq_inc,\n  rw neg_add_neg,\n  rw neg_sub_pos,\n  rw \u2190 N.one, rw N.one_eq_one,\n  rw N.zero_add,\nend\n\nlemma right_add_one_eq (a b : Z) : (a + 1 = b + 1) -> (a = b) :=\nbegin\n  intro h,\n  repeat {rw \u2190 one_add_comm at h},\n  exact (left_add_one_eq a b h),\nend\n\nlemma add_one_assoc (a b : Z) : (a + 1) + b = a + (1 + b) :=\nbegin\n  cases a,\n  cases b,\n  rw \u2190 one_eq_one, rw one,\n  repeat {rw pos_add_pos},\n  rw N.add_assoc,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_add_pos,\n  rw pos_add_neg,\n  rw pos_add_neg,\n  rw \u2190 N.one_eq_one, rw N.one,\n  repeat {rw N.add_succ, rw N.add_zero},\n  repeat {rw succ_sub_helper_succ},\n  cases b,\n  cases a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw \u2190 zero_eq_zero,\n  rw pos_add_pos,\n  rw N.zero_add,\n  rw N.zero_eq_zero,\n  rw succ_sub_helper_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  cases a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_succ,\n  rw pos_add_neg,\n  have t := zero_sub (pos (b + 1)),\n  rw \u2190 zero_eq_zero at t,\n  rw pos_sub_pos at t,\n  rw N.zero_eq_zero at t,\n  rw t,\n  rw \u2190 N.one_eq_one, rw N.one,\n  rw N.add_succ,\n  rw N.add_zero,\n  rw neg_pos_succ,\n  rw zero_sub_helper_succ,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  cases b,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_add_pos,\n  repeat {rw neg_add_pos},\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  rw N.succ_add,\n  rw N.zero_add,\n  rw succ_sub_helper_succ,\n  cases a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw sub_helper_zero,\n  rw zero_add,\n  rw zero_sub_helper_succ,\n  rw neg_add_pos,\n  rw N.succ_eq_inc,\n  rw \u2190 one_eq_one, rw one,\n  rw neg_add_pos,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  cases a,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw zero_add,\n  cases b,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw zero_sub_helper_succ,\n  rw neg_add_neg,\n  rw N.zero_add,\n  rw \u2190 N.succ_eq_inc,\n  rw zero_sub_helper_succ,\n  rw neg_add_neg,\n  cases b,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw N.add_zero,\n  rw \u2190 N.succ_eq_inc,\n  rw zero_sub_helper_succ,\n  rw neg_add_neg,\n  repeat {rw N.succ_eq_inc},\n  rw N.add_comm b 1,\n  repeat {rw N.add_assoc},\nend\n\nlemma fir_arg_sub_helper_inc : \u2200 (a b : N), sub_helper (a + 1) b = (sub_helper a b) + 1\n| 0 0 :=\nbegin\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_zero,\n  rw zero_sub_helper_zero,\n  rw \u2190 zero_eq_zero,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_add_pos,\n  rw N.zero_eq_zero,\n  rw N.zero_add,\nend\n| 0 (N.succ b) :=\nbegin\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  cases b,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw zero_sub_helper_succ,\n  rw \u2190 one_eq_one, rw one,\n  rw neg_add_pos,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  rw zero_sub_helper_zero,\n  repeat {rw zero_sub_helper_succ},\n  rw \u2190 one_eq_one, rw one,\n  rw neg_add_pos,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  rw zero_sub_helper_succ,\nend\n| (N.succ a) 0 :=\nbegin\n  repeat {rw sub_helper_zero},\n  rw \u2190 one_eq_one, rw one,\n  rw pos_add_pos,\n  rw \u2190 N.one_eq_one, rw N.one,\nend\n| (N.succ a) (N.succ b) :=\nbegin\n  rw \u2190 N.succ_eq_inc,\n  repeat {rw succ_sub_helper_succ},\n  exact (fir_arg_sub_helper_inc a b),\nend\n\nlemma sec_arg_sub_helper_inc : \u2200 (a b : N), sub_helper a (b + 1) = (sub_helper a b) - 1\n| 0 0 := \nbegin\n  rw \u2190 N.succ_eq_inc,\n  rw zero_sub_helper_succ,\n  rw zero_sub_helper_zero,\n  rw \u2190 zero_eq_zero,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_sub_pos,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_succ,\nend\n| 0 (N.succ b) :=\nbegin\n  rw \u2190 N.succ_eq_inc,\n  repeat {rw zero_sub_helper_succ},\n  rw \u2190 one_eq_one, rw one,\n  rw neg_sub_pos,\n  rw N.add_succ,\n  rw N.add_zero,\nend\n| (N.succ a) 0 := \nbegin\n  rw \u2190 N.succ_eq_inc, \n  rw succ_sub_helper_succ,\n  rw succ_sub_helper_zero,\n  rw sub_helper_zero,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_sub_pos,\n  rw succ_sub_helper_succ,\n  rw sub_helper_zero,\nend\n| (N.succ a) (N.succ b) :=\nbegin\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  rw succ_sub_helper_succ,\n  exact (sec_arg_sub_helper_inc a b),\nend\n\nlemma infix_inc_eq (a b c d : Z) : (a + 1 + b = c + 1 + d) -> (a + b = c + d) :=\nbegin\n  intro h,\n  cases a,\n  cases b,\n  cases c,\n  cases d,\n  rw \u2190 one_eq_one at h, rw one at h,\n  repeat {rw pos_add_pos},\n  repeat {rw pos_add_pos at h},\n  have s := pos_eq_pos _ _ h,\n  rw N.add_comm a _ at s,\n  rw N.add_comm c _ at s,\n  repeat {rw N.add_assoc at s},\n  have t := N.add_eq _ _ _ s,\n  rw t,\n  rw \u2190 one_eq_one at h, rw one at h,\n  repeat {rw pos_add_pos at h},\n  rw pos_add_neg at h,\n  rw \u2190 N.one at h, rw N.one_eq_one at h,\n  repeat {rw \u2190 N.succ_eq_inc at h},\n  rw succ_sub_helper_succ at h,\n  rw pos_add_neg,\n  have s := sub_helper c d,\n  rw sec_arg_sub_helper_inc,\n  cases (sub_helper c d),\n  rw \u2190 h,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_sub_pos,\n  rw N.succ_add,\n  rw succ_sub_helper_succ,\n  rw sub_helper_zero,\n  rw \u2190 h,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_sub_pos,\n  rw N.succ_add,\n  rw succ_sub_helper_succ,\n  rw sub_helper_zero,\n  cases d,\n  repeat {rw add_one_assoc at h},\n  rw \u2190 one_eq_one at h, rw one at h,\n  repeat {rw pos_add_pos at h},\n  rw neg_add_pos at h,\n  rw neg_add_pos,\n  rw \u2190 N.one at h, rw N.one_eq_one at h,\n  rw N.add_comm 1 d at h,\n  rw fir_arg_sub_helper_inc _ _ at h,\n  rw N.add_comm 1 b at h,\n  rw \u2190 N.add_assoc at h,\n  rw \u2190 pos_add_pos at h,\n  rw \u2190 N.one_eq_one at h, rw N.one at h,\n  rw \u2190 one at h, rw one_eq_one at h,\n  exact (right_add_one_eq _ _ h),\n  rw \u2190 one_eq_one at h, rw one at h,\n  repeat {rw pos_add_pos at h},\n  rw pos_add_neg at h,\n  exfalso,\n  rw \u2190 N.succ_eq_inc at h,\n  rw succ_sub_helper_succ at h,\n  cases d,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  rw add_zero at h,\n  cases h,\n  rw zero_sub_helper_succ at h,\n  rw neg_add_neg at h,\n  cases h,\n  rw \u2190 one_eq_one at h, rw one at h,\n  rw pos_add_neg at h,\n  rw \u2190 N.succ_eq_inc at h,\n  rw succ_sub_helper_succ at h,\n  cases d,\n  rw pos_add_pos at h,\n  cases c,\n  rw pos_add_pos,\n  rw pos_add_pos at h,\n  cases b,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  rw add_zero at h,\n  rw h,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw N.succ_add,\n  rw N.add_succ,\n  rw succ_sub_helper_succ,\n  rw N.zero_eq_zero,\n  rw sub_helper_zero,\n  rw N.zero_add,\n  rw zero_sub_helper_succ at h,\n  rw pos_add_neg,\n  rw sec_arg_sub_helper_inc,\n  rw pos_add_neg at h,\n  rw N.succ_eq_inc,\n  rw h,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_sub_pos,\n  rw N.succ_add,\n  rw N.add_succ,\n  rw succ_sub_helper_succ,\n  rw sub_helper_zero,\n  rw N.zero_add,\n  cases b,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  rw add_zero at h,\n  rw h,\n  rw neg_add_pos,\n  rw N.succ_add,\n  rw N.zero_add,\n  rw neg_add_pos,\n  rw N.succ_eq_inc,\n  rw fir_arg_sub_helper_inc,\n  rw add_one_assoc,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc N.zero,\n  rw succ_sub_helper_succ,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw zero_sub_helper_succ at h,\n  rw pos_add_neg,\n  rw sec_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\n  rw \u2190 pos_add_neg,\n  rw h,\n  rw N.add_comm,\n  rw neg_add_pos,\n  rw \u2190 N.one, rw N.one_eq_one,\n  rw fir_arg_sub_helper_inc,\n  rw sub_eq_neg_add,\n  rw add_one_assoc,\n  rw \u2190 sub_eq_neg_add,\n  rw sub_eq,\n  rw add_zero,rw neg_add_pos,\n  cases b,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  rw add_zero at h,\n  rw h,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  cases d,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw zero_sub_helper_succ,\n  cases c,\n  repeat {rw pos_add_neg},\n  nth_rewrite 1 sec_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\n  rw sub_eq_neg_add,\n  rw \u2190 one_eq_one, rw one,\n  rw neg_pos_succ,\n  rw N.zero_eq_zero,\n  repeat {rw neg_add_neg},\n  rw N.succ_eq_inc,\n  rw N.zero_eq_zero,\n  rw N.add_zero,\n  repeat {rw N.add_assoc},\n  rw zero_sub_helper_succ at h,\n  rw pos_add_neg at h,\n  rw sec_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\n  rw h,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  cases d,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw sub_eq_neg_add,\n  rw \u2190 one_eq_one, rw one,\n  rw neg_pos_succ,\n  rw zero_sub_helper_succ,\n  cases c,\n  repeat {rw pos_add_neg},\n  nth_rewrite 1 sec_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\n  repeat {rw neg_add_neg},\n  rw \u2190 one_eq_one, rw one,\n  rw neg_sub_pos,\n  rw N.succ_eq_inc d,\n  repeat {rw N.add_assoc},\n  rw \u2190 N.one, rw N.one_eq_one,\n  cases b,\n  rw \u2190 one_eq_one at h, rw one at h,\n  rw pos_add_pos at h,\n  rw neg_add_pos at h,\n  rw \u2190 N.succ_eq_inc at h,\n  rw N.succ_add at h,\n  rw N.zero_add at h,\n  rw succ_sub_helper_succ at h,\n  rw neg_add_pos,\n  rw sec_arg_sub_helper_inc,\n  rw h,\n  cases d,\n  rw pos_add_pos,\n  cases c,\n  rw pos_add_pos,\n  rw \u2190 one_eq_one, rw one,\n  rw pos_sub_pos,\n  rw N.succ_add,\n  rw N.zero_add,\n  rw N.add_succ,\n  rw succ_sub_helper_succ,\n  rw sub_helper_zero,\n  rw pos_add_pos,\n  rw neg_add_pos,\n  rw \u2190 sec_arg_sub_helper_inc,\n  rw \u2190 N.one_eq_one, rw N.one,\n  rw N.succ_add,\n  rw N.zero_add,\n  repeat {rw N.add_succ, rw N.add_zero},\n  rw succ_sub_helper_succ,\n  rw neg_add_pos,\n  rw N.succ_eq_inc,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  cases d,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw \u2190 one_eq_one, rw one,\n  rw sub_eq_neg_add,\n  rw neg_pos_succ,\n  rw zero_sub_helper_succ,\n  cases c,\n  rw pos_add_neg,\n  rw \u2190 sec_arg_sub_helper_inc,\n  rw \u2190 pos_add_neg,\n  rw N.succ_eq_inc,\n  repeat {rw neg_add_neg},\n  rw \u2190 one_eq_one, rw one,\n  rw neg_sub_pos,\n  rw \u2190 N.one, rw N.one_eq_one,\n  rw N.succ_eq_inc,\n  repeat {rw N.add_assoc},\n  rw \u2190 one_eq_one at h, rw one at h,\n  rw pos_add_neg at h,\n  rw \u2190 N.succ_eq_inc at h,\n  rw succ_sub_helper_succ at h,\n  cases b,\n  rw N.zero_eq_zero at h,\n  rw zero_sub_helper_zero at h,\n  rw add_zero at h,\n  rw N.zero_eq_zero,\n  rw \u2190 N.add_assoc,\n  rw \u2190 neg_add_neg,\n  rw h,\n  cases d,\n  rw pos_add_pos,\n  cases c,\n  rw pos_add_pos,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw N.succ_add,\n  rw N.zero_add,\n  rw N.add_succ,\n  rw succ_sub_helper_succ,\n  rw sub_helper_zero,\n  rw pos_add_pos,\n  rw neg_add_pos,\n  rw \u2190 neg_pos_succ,\n  rw \u2190 sub_eq_neg_add,\n  rw \u2190 one, rw one_eq_one,\n  rw \u2190 sec_arg_sub_helper_inc,\n  nth_rewrite 0 \u2190 N.one_eq_one, rw N.one,\n  rw N.add_succ,\n  repeat {rw N.succ_add},\n  rw succ_sub_helper_succ,\n  rw N.add_zero,\n  rw neg_add_pos,\n  rw N.zero_add,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  cases d,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw zero_sub_helper_succ,\n  cases c,\n  rw pos_add_neg,\n  rw \u2190 neg_pos_succ,\n  rw \u2190 sub_eq_neg_add,\n  rw \u2190 one, rw one_eq_one,\n  rw \u2190 sec_arg_sub_helper_inc,\n  rw \u2190 pos_add_neg,\n  rw N.succ_eq_inc,\n  repeat {rw neg_add_neg},\n  rw N.add_zero,\n  rw N.succ_eq_inc,\n  repeat {rw N.add_assoc},\n  rw zero_sub_helper_succ at h,\n  rw neg_add_neg at h,\n  rw N.succ_eq_inc,\n  rw \u2190 N.add_assoc,\n  nth_rewrite 1 \u2190 N.one_eq_one, rw N.one,\n  rw N.succ_eq_inc,\n  repeat {rw \u2190 N.add_assoc},\n  rw \u2190 neg_add_neg,\n  rw h,\n  cases d,\n  rw pos_add_pos,\n  rw N.succ_add,\n  rw N.zero_add,\n  cases c,\n  repeat {rw pos_add_pos},\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw N.add_succ,\n  rw succ_sub_helper_succ,\n  rw sub_helper_zero,\n  rw neg_add_pos,\n  rw \u2190 neg_pos_succ,\n  rw \u2190 sub_eq_neg_add,\n  rw \u2190 one, rw one_eq_one,\n  rw \u2190 N.succ_eq_inc,\n  rw \u2190 sec_arg_sub_helper_inc,\n  rw N.succ_add,\n  rw succ_sub_helper_succ,\n  rw \u2190 neg_add_pos,\n  rw pos_add_neg,\n  rw \u2190 N.succ_eq_inc,\n  rw succ_sub_helper_succ,\n  cases d,\n  rw N.zero_eq_zero,\n  rw zero_sub_helper_zero,\n  rw add_zero,\n  rw zero_sub_helper_succ,\n  cases c,\n  rw pos_add_neg,\n  rw \u2190 N.one_eq_one, rw N.one,\n  rw \u2190 neg_pos_succ,\n  rw \u2190 sub_eq_neg_add,\n  rw \u2190 one, rw one_eq_one,\n  rw \u2190 sec_arg_sub_helper_inc,\n  rw \u2190 pos_add_neg,\n  rw N.add_succ,\n  rw N.add_zero,\n  repeat {rw neg_add_neg},\n  rw N.add_zero,\n  rw N.succ_eq_inc,\n  repeat {rw N.add_assoc},\nend\n\nlemma neg_eq (a b : Z) : (a = b) -> (neg a = neg b) :=\nbegin\n  intro h,\n  rw h,\nend\n\nlemma neg_sub_helper : \u2200 (a b : N), neg (sub_helper a b) = sub_helper b a\n| 0 0 :=\nbegin\n  rw zero_sub_helper_zero,\n  rw neg_zero,\nend\n| 0 (N.succ b) :=\nbegin\n  rw succ_sub_helper_zero,\n  rw zero_sub_helper_succ,\n  rw neg_neg_succ,\n  rw N.succ_eq_inc,\nend\n| (N.succ a) 0 :=\nbegin\n  rw succ_sub_helper_zero,\n  rw zero_sub_helper_succ,\n  rw neg_pos_succ,\nend\n| (N.succ a) (N.succ b) :=\nbegin\n  repeat {rw succ_sub_helper_succ},\n  exact (neg_sub_helper a b),\nend\n\nlemma neg_add (a b : Z) : neg (a + b) = neg a + neg b :=\nbegin\n  cases a,\n  cases a,\n  rw zero_eq_zero,\n  rw neg_zero,\n  repeat {rw zero_add},\n  rw neg_pos_succ,\n  cases b,\n  cases b,\n  rw zero_eq_zero,\n  rw neg_zero,\n  repeat {rw add_zero},\n  rw neg_pos_succ,\n  rw pos_add_pos,\n  rw N.add_succ,\n  rw neg_pos_succ,\n  rw neg_pos_succ,\n  rw neg_add_neg,\n  rw N.succ_add,\n  rw \u2190 N.succ_eq_inc,\n  rw neg_neg_succ,\n  rw pos_add_neg,\n  rw neg_sub_helper,\n  rw neg_add_pos,\n  rw N.succ_eq_inc,\n  rw neg_neg_succ,\n  cases b,\n  rw neg_add_pos,\n  rw neg_sub_helper,\n  cases b,\n  rw N.zero_eq_zero,\n  rw \u2190 N.zero_eq_zero,\n  rw zero_eq_zero,\n  rw neg_zero,\n  rw add_zero,\n  rw N.zero_eq_zero,\n  rw sub_helper_zero,\n  rw neg_pos_succ,\n  rw pos_add_neg,\n  rw N.succ_eq_inc,\n  rw neg_add_neg,\n  repeat {rw neg_neg_succ},\n  rw pos_add_pos,\n  rw \u2190 N.add_assoc,\n  rw N.add_assoc a 1 b,\n  rw N.add_comm 1 b,\n  rw \u2190 N.add_assoc,\nend\n\nlemma neg_Z_eq_neg_Z (a b : Z) : (neg a = neg b) -> (a = b) :=\nbegin\n  intro h,\n  cases a,\n  cases a,\n  rw zero_eq_zero at h,\n  rw neg_zero at h,\n  rw zero_eq_zero,\n  cases b,\n  cases b,\n  rw zero_eq_zero,\n  exfalso,\n  rw neg_pos_succ at h,\n  cases h,\n  exfalso,\n  rw neg_neg_succ at h,\n  rw \u2190 zero_eq_zero at h,\n  have t := pos_eq_pos _ _ h,\n  exact N.zero_neq_succ _ t,\n  rw neg_pos_succ at h,\n  cases b,\n  cases b,\n  exfalso,\n  rw zero_eq_zero at h,\n  rw neg_zero at h,\n  cases h,\n  rw neg_pos_succ at h,\n  have t := neg_eq_neg _ _ h,\n  rw t,\n  rw neg_neg_succ at h,\n  exfalso,\n  cases h,\n  rw neg_neg_succ at h,\n  cases b,\n  cases b,\n  rw zero_eq_zero at h,\n  rw neg_zero at h,\n  exfalso,\n  rw \u2190 N.succ_eq_inc at h,\n  rw \u2190 zero_eq_zero at h,\n  have t := pos_eq_pos _ _ h,\n  exact (N.succ_neq_zero _ t),\n  rw neg_pos_succ at h,\n  exfalso,\n  cases h,\n  rw neg_neg_succ at h,\n  have t := pos_eq_pos _ _ h,\n  repeat {rw \u2190 N.succ_eq_inc at t},\n  have q := N.succ_eq _ _ t,\n  rw q,\nend\n\nlemma add_eq_pos (a b: Z) (d: N): ((pos d) + a = (pos d) + b) -> (a = b) :=\nbegin\n  intro h,\n  induction d,\n  rw zero_eq_zero at h,\n  rw zero_add at h,\n  rw zero_add at h,\n  exact h,\n  rw succ_eq_inc at h,\n  have t := infix_inc_eq _ _ _ _ h,\n  exact (d_ih t),\nend\n\nlemma add_eq_neg (a b: Z) (d: N): ((neg_succ d) + a = (neg_succ d) + b) -> (a = b) :=\nbegin\n  intro h,\n  have t := neg_eq _ _ h,\n  repeat {rw neg_add at t},\n  repeat {rw neg_neg_succ at t},\n  have q := add_eq_pos _ _ _ t,\n  exact (neg_Z_eq_neg_Z _ _ q),\nend\n\ntheorem add_eq (a b d : Z): (d + a = d + b) -> (a = b) :=\nbegin\n  intro h,\n  cases d,\n  exact add_eq_pos _ _ _ h,\n  exact add_eq_neg _ _ _ h,\nend\n\nlemma sub_helper_add_pos (a b c : N) : sub_helper a b + pos c = sub_helper (a + c) b :=\nbegin\n  induction c,\n  rw zero_eq_zero,\n  rw add_zero,\n  rw N.zero_eq_zero,\n  rw N.add_zero,\n  rw N.succ_eq_inc,\n  rw \u2190 N.add_assoc,\n  rw fir_arg_sub_helper_inc,\n  rw \u2190 c_ih,\n  cases sub_helper a b,\n  rw \u2190 one_eq_one, rw one,\n  repeat {rw pos_add_pos},\n  rw \u2190 N.one, rw N.one_eq_one,\n  rw N.add_assoc,\n  repeat {rw neg_add_pos},\n  rw \u2190 fir_arg_sub_helper_inc,\nend\n\nlemma pos_add_sub_helper (a b c : N) : pos a + sub_helper b c = sub_helper (a + b) c :=\nbegin\n  induction a,\n  rw zero_eq_zero,\n  rw zero_add,\n  rw N.zero_eq_zero,\n  rw N.zero_add,\n  rw N.succ_add,\n  rw N.succ_eq_inc (a_n + b),\n  rw fir_arg_sub_helper_inc,\n  rw \u2190 a_ih,\n  cases sub_helper b c,\n  rw \u2190 one_eq_one, rw one,\n  repeat {rw pos_add_pos},\n  rw N.succ_add,\n  rw N.add_succ,\n  rw N.add_zero,\n  repeat {rw pos_add_neg},\n  rw \u2190 fir_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\nend\n\nlemma sub_helper_add_neg (a b c : N) : sub_helper a b + neg_succ c = sub_helper a (b + c + 1) :=\nbegin\n  induction c,\n  rw N.zero_eq_zero,\n  rw N.add_zero,\n  rw \u2190 neg_pos_succ,\n  rw \u2190 sub_eq_neg_add,\n  rw \u2190 one, rw one_eq_one,\n  rw sec_arg_sub_helper_inc,\n  rw N.add_succ,\n  rw N.succ_add,\n  rw N.succ_eq_inc (b + c_n + 1),\n  rw sec_arg_sub_helper_inc,\n  rw \u2190 c_ih,\n  cases sub_helper a b,\n  repeat {rw pos_add_neg},\n  rw \u2190 sec_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\n  rw sub_eq_neg_add,\n  rw \u2190 one_eq_one, rw one,\n  rw neg_pos_succ,\n  repeat {rw neg_add_neg},\n  rw N.succ_eq_inc,\n  rw N.add_zero,\n  repeat {rw N.add_assoc},\nend\n\nlemma neg_add_sub_helper (a b c : N) : neg_succ a + sub_helper b c = sub_helper b (a + c + 1) :=\nbegin\n  induction a,\n  rw N.zero_eq_zero,\n  rw N.zero_add,\n  rw \u2190 neg_pos_succ,\n  rw \u2190 one, rw one_eq_one,\n  rw one_sub_comm,\n  rw sec_arg_sub_helper_inc,\n  repeat {rw N.succ_add},\n  rw N.succ_eq_inc (a_n + c + 1),\n  rw sec_arg_sub_helper_inc,\n  rw \u2190 a_ih,\n  cases sub_helper b c,\n  repeat {rw neg_add_pos},\n  rw \u2190 sec_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\n  repeat {rw neg_add_neg},\n  rw \u2190 one_eq_one, rw one,\n  rw neg_sub_pos,\n  repeat {rw N.succ_add},\n  rw N.add_succ,\n  rw N.add_zero,\nend\n\ntheorem add_assoc (a b c : Z) : a + b + c = a + (b + c) :=\nbegin\n  cases a,\n  induction a,\n  rw zero_eq_zero,\n  rw zero_add,\n  rw zero_add,\n  cases b,\n  rw pos_add_pos,\n  rw pos_add_pos at a_ih,\n  cases c,\n  repeat {rw pos_add_pos},\n  repeat {rw N.add_assoc},\n  repeat {rw pos_add_neg},\n  repeat {rw pos_add_neg at a_ih},\n  rw N.succ_add,\n  rw N.succ_eq_inc,\n  rw fir_arg_sub_helper_inc,\n  rw a_ih,\n  cases sub_helper b (c + 1),\n  rw \u2190 one_eq_one, rw one,\n  repeat {rw pos_add_pos},\n  rw N.succ_add,\n  rw N.add_succ,\n  rw N.add_zero,\n  repeat {rw pos_add_neg},\n  rw \u2190 fir_arg_sub_helper_inc,\n  rw N.succ_eq_inc,\n  cases c,\n  rw sub_helper_add_pos,\n  rw neg_add_pos,\n  rw pos_add_sub_helper,\n  rw neg_add_neg,\n  rw pos_add_neg,\n  rw sub_helper_add_neg,\n  rw N.add_assoc b 1 c,\n  rw N.add_comm 1 c,\n  rw \u2190 N.add_assoc,\n  cases b,\n  rw neg_add_pos,\n  cases c,\n  rw pos_add_pos,\n  rw neg_add_pos,\n  rw sub_helper_add_pos,\n  rw sub_helper_add_neg,\n  rw pos_add_neg,\n  rw neg_add_sub_helper,\n  rw N.add_comm c 1,\n  repeat {rw N.add_assoc},\n  rw neg_add_neg,\n  cases c,\n  repeat {rw neg_add_pos},\n  rw neg_add_sub_helper,\n  repeat {rw N.add_assoc},\n  repeat {rw neg_add_neg},\n  rw \u2190 N.one_eq_one, rw N.one,\n  repeat {rw N.add_succ},\n  repeat {rw N.add_zero},\n  rw N.succ_add,\n  rw N.add_assoc,\nend\n\ntheorem add_comm (a b : Z): a + b = b + a :=\nbegin\n  cases a,\n  cases b,\n  repeat {rw pos_add_pos},\n  rw N.add_comm,\n  rw pos_add_neg,\n  rw neg_add_pos,\n  cases b,\n  rw neg_add_pos,\n  rw pos_add_neg,\n  repeat {rw neg_add_neg},\n  rw N.add_comm a b,\nend\n\nend Z", "meta": {"author": "Jijasan", "repo": "UselessArithProofs", "sha": "c2e48e9a83b327246ba86debb1ef2fe87919c00d", "save_path": "github-repos/lean/Jijasan-UselessArithProofs", "path": "github-repos/lean/Jijasan-UselessArithProofs/UselessArithProofs-c2e48e9a83b327246ba86debb1ef2fe87919c00d/src/integer/addition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7119464688905812}}
{"text": "import prelim.embed prelim.minmax set_tactic.solver\nimport matroid.rankfun matroid.dual \n\nopen_locale classical \nnoncomputable theory\n\nuniverses u v w \n\nopen matroid set list \n\nvariables {\u03b1 : Type*} [fintype \u03b1] {N M : matroid \u03b1}\n\nsection weak_image \n/- M is a weak image N if the rank in N is upper-bounded by the rank in M -/\ndef is_weak_image (N M : matroid \u03b1) := \n  \u2200 X, N.r X \u2264 M.r X \n\ninstance weak_image_le : has_le (matroid \u03b1) := \n\u27e8\u03bb N M, is_weak_image N M\u27e9\n\nlemma weak_image_r_set (h : N \u2264 M) (X : set \u03b1) :\n  N.r X \u2264 M.r X :=\nh X\n\nlemma weak_image_iff_indep:\n  N \u2264 M \u2194 \u2200 X, N.is_indep X \u2192 M.is_indep X := \nbegin\n  simp_rw indep_iff_r, \n  refine \u27e8\u03bb h, \u03bb X hX, le_antisymm (M.rank_le_size _) _, \u03bb h, \u03bb Y, _\u27e9,  \n  {  rw \u2190hX, apply h}, \n  rcases exists_basis_of N Y with \u27e8BN,\u27e8hN1, \u27e8hN2, hN3\u27e9\u27e9\u27e9, \n  exact le_trans (by rw [h _ hN2, \u2190hN3, hN2]) (M.rank_mono hN1),  \nend\n\nlemma indep_of_weak_image_indep (h : N \u2264 M){I : set \u03b1} (hI : N.is_indep I) :\n  M.is_indep I := \nweak_image_iff_indep.mp h I hI\n\nlemma weak_image_iff_dep:\n  N \u2264 M \u2194 \u2200 X, M.is_dep X \u2192 N.is_dep X := \nby simp_rw [weak_image_iff_indep, indep_iff_not_dep, not_imp_not]\n\nlemma weak_image_iff_cct:\n  N \u2264 M \u2194 \u2200 C, M.is_circuit C \u2192 \u2203 C', N.is_circuit C' \u2227 C' \u2286 C := \nbegin\n  simp_rw [weak_image_iff_dep, dep_iff_contains_circuit],  \n  refine \u27e8\u03bb h, \u03bb C hC, _, \u03bb h, \u03bb X hX, _\u27e9, \n  {  apply h, exact \u27e8C,hC,subset_refl _\u27e9,},\n  rcases hX with \u27e8C, \u27e8h', h''\u27e9\u27e9, \n  rcases h C h' with \u27e8C',h1,h2\u27e9, \n  exact \u27e8C', h1, subset.trans h2 h''\u27e9, \nend\n\nlemma weak_image_tfae: \n  tfae\n[ N \u2264 M, \n  \u2200 X, N.r X \u2264 M.r X, \n  \u2200 X, N.is_indep X \u2192 M.is_indep X, \n  \u2200 X, M.is_dep X \u2192 N.is_dep X,\n  \u2200 C, M.is_circuit C \u2192 \u2203 C', N.is_circuit C' \u2227 C' \u2286 C] :=\nbegin\n  tfae_have : 1 \u2194 2, unfold has_le.le is_weak_image, \n  tfae_have : 1 \u2194 3, apply weak_image_iff_indep, \n  tfae_have : 1 \u2194 4, apply weak_image_iff_dep,  \n  tfae_have : 1 \u2194 5, apply weak_image_iff_cct, \n  tfae_finish, \nend\n/- that was fun! -/\n\nlemma weak_image_rank_zero_of_rank_zero (h : N \u2264 M){X : set \u03b1} (hX : M.r X = 0) :\n  N.r X = 0 :=\nby {apply rank_eq_zero_of_le_zero, rw \u2190hX, apply h}\n\nlemma weak_image_loop_of_loop (h : N \u2264 M){e : \u03b1} (he : M.is_loop e) :\n  N.is_loop e :=\nweak_image_rank_zero_of_rank_zero h he \n\nlemma nonloop_of_weak_image_nonloop (h : N \u2264 M){e : \u03b1} (he : N.is_nonloop e) :\n  M.is_nonloop e :=\nby {rw is_nonloop at *, linarith [rank_single_ub M e, h {e}], }\n\nlemma loops_weak_image (h : N \u2264 M) : \n  loops M \u2286 loops N := \nby {intro e, simp only [\u2190loop_iff_mem_loops], apply weak_image_loop_of_loop h }\n\nend weak_image\n\nsection quotient \n/-- a quotient of M is a matroid N for which rank differences of nested pairs in N are at most\nthe corresponding rank differences in M. This is equivalent to the existence of a matroid P for \nwhich M is a deletion of P and N is a contraction of P, but we do not show this equivalence here.-/\ndef is_quotient (N M : matroid \u03b1) := \n  \u2200 X Y, X \u2286 Y \u2192 N.r Y - N.r X \u2264 M.r Y - M.r X\n\nreserve infixl ` \u227c `:75\ninfix ` \u227c ` :=  is_quotient \n\nlemma quotient_iff_r : \n  N \u227c M \u2194 \u2200 X Y, X \u2286 Y \u2192 N.r Y - N.r X \u2264 M.r Y - M.r X := \nby rw is_quotient\n\nlemma rank_diff_of_quotient (hNM : N \u227c M) {X Y : set \u03b1} (h : X \u2286 Y) :\n  N.r Y - N.r X \u2264 M.r Y - M.r X :=\nhNM _ _ h \n\nlemma weak_image_of_quotient (h : N \u227c M) :\n   N \u2264 M :=\n\u03bb X, by {convert h \u2205 X (empty_subset _); simp, }\n\nlemma quotient_of_cl (h : \u2200 X, M.cl X \u2286 N.cl X) : \n   N \u227c M := \nbegin\n  set P : set \u03b1 \u00d7 set \u03b1 \u2192 Prop :=  \n  (\u03bb p, p.1 \u2286 p.2 \u2192 N.r p.2 - N.r p.1 \u2264 M.r p.2 - M.r p.1 ) with hP, \n  suffices : \u2200 p, P p, exact \u03bb X Y, this \u27e8X,Y\u27e9, \n  apply nonneg_int_strong_induction_param P (\u03bb p, size (p.2 \\ p.1)), \n  { rintros \u27e8X,Y\u27e9, apply size_nonneg}, \n  { rintros \u27e8X,Y\u27e9 hs hXY, dsimp only at *, \n    rw [size_zero_iff_empty, diff_empty_iff_subset] at hs, \n    rw [subset.antisymm hXY hs, sub_self, sub_self],  }, \n  rintros \u27e8X,Y\u27e9 h_size h' hXY, dsimp only at *,   \n  cases exists_mem_of_size_pos h_size with e he,\n  specialize h' \u27e8X, Y \\ {e}\u27e9 _ _, \n  { dsimp only, rw [diff_right_comm, size_remove_mem he], linarith}, \n  { dsimp only, apply subset_of_remove_mem_diff; assumption,},\n  dsimp only at h', \n  suffices : N.r Y - N.r (Y \\ {e}) \u2264 M.r Y - M.r (Y \\ {e}), by linarith, \n  by_cases hY : M.r Y = M.r (Y \\ {e}), swap, \n  { rw [rank_eq_sub_one_of_ne_remove _ _ _ hY], linarith [rank_remove_single_lb N Y e]  },\n  rw [hY, sub_self], \n  rw [eq_comm, rank_removal_iff_closure _ _ he.1]  at hY, \n  have hN := mem_of_subset (h _) hY, rw [\u2190rank_removal_iff_closure _ _ he.1] at hN, \n  linarith, \nend\n\nlemma quotient_iff_dual_quotient : \n  N \u227c M \u2194 M.dual \u227c N.dual :=\nbegin\n  suffices h' : \u2200 (N M : matroid \u03b1), N \u227c M \u2192 M.dual \u227c N.dual, \n  exact \u27e8\u03bb h, h' _ _ h, \u03bb h, by {convert h' _ _ h; rw dual_dual, }\u27e9, \n  intros N M h X Y hXY, \n  simp_rw [dual_r], \n  rw compl_subset_compl.symm at hXY, \n  linarith [h _ _ hXY],\nend\n\nlemma quotient_tfae : \n  tfae \n[N \u227c M,\n \u2200 F, N.is_flat F \u2192 M.is_flat F, \n \u2200 X Y, X \u2286 Y \u2192 N.r Y - N.r X \u2264 M.r Y - M.r X,\n \u2200 X, M.cl X \u2286 N.cl X,\n M.dual \u227c N.dual] :=\nbegin\n  tfae_have : 1 \u2194 3, unfold is_quotient,\n  tfae_have : 3 \u2192 2, \n  {exact \u03bb h, \u03bb F hF Y hFY, by linarith [hF _ hFY, h _ _ hFY.1],}, \n  tfae_have : 2 \u2192 4, \n  {exact \u03bb h X, subset_flat X _ (subset_cl N X) (h _ (N.cl_is_flat X))}, \n  tfae_have: 4 \u2192 1, apply quotient_of_cl, \n  tfae_have : 1 \u2194 5, apply quotient_iff_dual_quotient, \n  tfae_finish, \nend\n\nlemma quotient_iff_flat :\n  N \u227c M \u2194 \u2200 F, N.is_flat F \u2192 M.is_flat F :=\nby apply @tfae.out _ quotient_tfae 0 1 \n\nlemma flat_of_quotient_flat (h : N \u227c M){F : set \u03b1} (hF : N.is_flat F) :\n  M.is_flat F :=\n(quotient_iff_flat.mp h) F hF \n\nlemma indep_of_quotient_indep (h : N \u227c M){I : set \u03b1} (hI : N.is_indep I) :\n  M.is_indep I := \nindep_of_weak_image_indep (weak_image_of_quotient h) hI \n\nlemma quotient_iff_cl :\n  N \u227c M \u2194 \u2200 X, M.cl X \u2286 N.cl X :=\nby apply @tfae.out _ quotient_tfae 0 3 \n\nlemma quotient_rank_zero_of_rank_zero (h : N \u227c M){X : set \u03b1} (hX : M.r X = 0) :\n  N.r X = 0 :=\nweak_image_rank_zero_of_rank_zero (weak_image_of_quotient h) hX \n\nlemma quotient_loop_of_loop (h : N \u227c M){e : \u03b1} (he : M.is_loop e) :\n  N.is_loop e :=\nweak_image_loop_of_loop (weak_image_of_quotient h) he\n\nlemma nonloop_of_quotient_nonloop (h : N \u227c M){e : \u03b1} (he : N.is_nonloop e) :\n  M.is_nonloop e :=\nnonloop_of_weak_image_nonloop (weak_image_of_quotient h) he\n\nlemma loops_quotient (h : N \u227c M) : \n  loops M \u2286 loops N := \nloops_weak_image (weak_image_of_quotient h)\n\nlemma eq_of_eq_rank_quotient (h : N \u227c M) (hr : N.r univ = M.r univ) :\n  N = M :=\nbegin\n  ext X, by_contra hn,\n  /- take a maximal set on which the ranks of N and M differ. -/\n  rcases maximal_example_aug (\u03bb X, \u00acN.r X = M.r X) hn with \u27e8Y, hXY, h',h''\u27e9, \n  dsimp only at h'', simp_rw [not_not] at h'', clear hXY hn X, \n  have hY : Y \u2260 univ := \u03bb hY, by {rw \u2190hY at hr, exact h' hr },\n  cases ne_univ_iff_has_nonmem.mp hY with e heY,  \n  specialize h'' e heY, \n  have hle := weak_image_of_quotient h, \n  rw quotient_iff_cl at h, \n  by_cases hM : e \u2208 M.cl Y, \n  { rw [(mem_cl_iff_r.mp hM)] at h'',\n    rw [\u2190h'', eq_comm, \u2190mem_cl_iff_r] at h', \n    exact h' (mem_of_mem_of_subset hM (h _))}, \n  rw nonmem_cl_iff_r at hM,  \n  linarith [int.le_sub_one_of_le_of_ne (hle _) h', rank_augment_single_ub N Y e], \nend\n\nend quotient \n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/submatroid/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7118986301536928}}
{"text": "/-\nCopyright (c) 2020 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Yury Kudryashov\n-/\nimport analysis.calculus.deriv\nimport measure_theory.constructions.borel_space\nimport measure_theory.function.strongly_measurable\nimport tactic.ring_exp\n\n/-!\n# Derivative is measurable\n\nIn this file we prove that the derivative of any function with complete codomain is a measurable\nfunction. Namely, we prove:\n\n* `measurable_set_of_differentiable_at`: the set `{x | differentiable_at \ud835\udd5c f x}` is measurable;\n* `measurable_fderiv`: the function `fderiv \ud835\udd5c f` is measurable;\n* `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `\u03bb x, fderiv \ud835\udd5c f x y`\n  is measurable;\n* `measurable_deriv`: the function `deriv f` is measurable (for `f : \ud835\udd5c \u2192 F`).\n\nWe also show the same results for the right derivative on the real line\n(see `measurable_deriv_within_Ici` and ``measurable_deriv_within_Ioi`), following the same\nproof strategy.\n\n## Implementation\n\nWe give a proof that avoids second-countability issues, by expressing the differentiability set\nas a function of open sets in the following way. Define `A (L, r, \u03b5)` to be the set of points\nwhere, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the\nlinear map `L`, up to `\u03b5 r`. It is an open set.\nLet also `B (L, r, s, \u03b5) = A (L, r, \u03b5) \u2229 A (L, s, \u03b5)`: we require that at two possibly different\nscales `r` and `s`, the function is well approximated by the linear map `L`. It is also open.\n\nWe claim that the differentiability set of `f` is exactly\n`D = \u22c2 \u03b5 > 0, \u22c3 \u03b4 > 0, \u22c2 r, s < \u03b4, \u22c3 L, B (L, r, s, \u03b5)`.\nIn other words, for any `\u03b5 > 0`, we require that there is a size `\u03b4` such that, for any two scales\nbelow this size, the function is well approximated by a linear map, common to the two scales.\n\nThe set `\u22c3 L, B (L, r, s, \u03b5)` is open, as a union of open sets. Converting the intersections and\nunions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the\ndifferentiability set is measurable.\n\nTo prove the claim, there are two inclusions. One is trivial: if the function is differentiable\nat `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the\ndifferentiability exactly says that the map is well approximated by `L`). This is proved in\n`mem_A_of_differentiable` and `differentiable_set_subset_D`.\n\nFor the other direction, the difficulty is that `L` in the union may depend on `\u03b5, r, s`. The key\npoint is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to\n`A (L, r, \u03b5)` and `A (L', r, \u03b5)`, then `L` and `L'` have to be close on a shell, and thus\n`\u2225L - L'\u2225` is bounded by `\u03b5` (see `norm_sub_le_of_mem_A`). Assume now `x \u2208 D`. If one has two maps\n`L` and `L'` such that `x` belongs to `A (L, r, \u03b5)` and to `A (L', r', \u03b5')`, one deduces that `L` is\nclose to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a\nlinear map `L\u2081` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `\u03b5` (it exists as\n`x` belongs to `D`). Take also `L\u2082` that approximates `f` around `x` both at scales `r'` and `s`\nw.r.t. `\u03b5'`. Then `L\u2081` is close to `L` (as they are close on a shell of radius `r`), and `L\u2082` is\nclose to `L\u2081` (as they are close on a shell of radius `s`), and `L'` is close to `L\u2082` (as they are\nclose on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed.\n\nIt follows that the different approximating linear maps that show up form a Cauchy sequence when\n`\u03b5` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`.\nWith the same kind of arguments, one checks that `f` is differentiable with derivative `f'`.\n\nTo show that the derivative itself is measurable, add in the definition of `B` and `D` a set\n`K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K`\nis exactly the set of points where `f` is differentiable with a derivative in `K`.\n\n## Tags\n\nderivative, measurable function, Borel \u03c3-algebra\n-/\n\nnoncomputable theory\n\nopen set metric asymptotics filter continuous_linear_map\nopen topological_space (second_countable_topology) measure_theory\nopen_locale topological_space\n\nnamespace continuous_linear_map\n\nvariables {\ud835\udd5c E F : Type*} [nondiscrete_normed_field \ud835\udd5c]\n  [normed_group E] [normed_space \ud835\udd5c E] [normed_group F] [normed_space \ud835\udd5c F]\n\nlemma measurable_apply\u2082 [measurable_space E] [opens_measurable_space E]\n  [second_countable_topology E] [second_countable_topology (E \u2192L[\ud835\udd5c] F)]\n  [measurable_space F] [borel_space F] :\n  measurable (\u03bb p : (E \u2192L[\ud835\udd5c] F) \u00d7 E, p.1 p.2) :=\nis_bounded_bilinear_map_apply.continuous.measurable\n\nend continuous_linear_map\n\nsection fderiv\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\nvariables {E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\nvariables {F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\nvariables {f : E \u2192 F} (K : set (E \u2192L[\ud835\udd5c] F))\n\nnamespace fderiv_measurable_aux\n\n/-- The set `A f L r \u03b5` is the set of points `x` around which the function `f` is well approximated\nat scale `r` by the linear map `L`, up to an error `\u03b5`. We tweak the definition to make sure that\nthis is an open set.-/\ndef A (f : E \u2192 F) (L : E \u2192L[\ud835\udd5c] F) (r \u03b5 : \u211d) : set E :=\n{x | \u2203 r' \u2208 Ioc (r/2) r, \u2200 y z \u2208 ball x r', \u2225f z - f y - L (z-y)\u2225 \u2264 \u03b5 * r}\n\n/-- The set `B f K r s \u03b5` is the set of points `x` around which there exists a continuous linear map\n`L` belonging to `K` (a given set of continuous linear maps) that approximates well the\nfunction `f` (up to an error `\u03b5`), simultaneously at scales `r` and `s`. -/\ndef B (f : E \u2192 F) (K : set (E \u2192L[\ud835\udd5c] F)) (r s \u03b5 : \u211d) : set E :=\n\u22c3 (L \u2208 K), (A f L r \u03b5) \u2229 (A f L s \u03b5)\n\n/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its\nmain use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,\nwith a derivative in `K`. -/\ndef D (f : E \u2192 F) (K : set (E \u2192L[\ud835\udd5c] F)) : set E :=\n\u22c2 (e : \u2115), \u22c3 (n : \u2115), \u22c2 (p \u2265 n) (q \u2265 n), B f K ((1/2) ^ p) ((1/2) ^ q) ((1/2) ^ e)\n\nlemma is_open_A (L : E \u2192L[\ud835\udd5c] F) (r \u03b5 : \u211d) : is_open (A f L r \u03b5) :=\nbegin\n  rw metric.is_open_iff,\n  rintros x \u27e8r', r'_mem, hr'\u27e9,\n  obtain \u27e8s, s_gt, s_lt\u27e9 : \u2203 (s : \u211d), r / 2 < s \u2227 s < r' := exists_between r'_mem.1,\n  have : s \u2208 Ioc (r/2) r := \u27e8s_gt, le_of_lt (s_lt.trans_le r'_mem.2)\u27e9,\n  refine \u27e8r' - s, by linarith, \u03bb x' hx', \u27e8s, this, _\u27e9\u27e9,\n  have B : ball x' s \u2286 ball x r' := ball_subset (le_of_lt hx'),\n  assume y hy z hz,\n  exact hr' y (B hy) z (B hz)\nend\n\nlemma is_open_B {K : set (E \u2192L[\ud835\udd5c] F)} {r s \u03b5 : \u211d} : is_open (B f K r s \u03b5) :=\nby simp [B, is_open_Union, is_open.inter, is_open_A]\n\nlemma A_mono (L : E \u2192L[\ud835\udd5c] F) (r : \u211d) {\u03b5 \u03b4 : \u211d} (h : \u03b5 \u2264 \u03b4) :\n  A f L r \u03b5 \u2286 A f L r \u03b4 :=\nbegin\n  rintros x \u27e8r', r'r, hr'\u27e9,\n  refine \u27e8r', r'r, \u03bb y hy z hz, (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h _)\u27e9,\n  linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x],\nend\n\n\n\nlemma mem_A_of_differentiable {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {x : E} (hx : differentiable_at \ud835\udd5c f x) :\n  \u2203 R > 0, \u2200 r \u2208 Ioo (0 : \u211d) R, x \u2208 A f (fderiv \ud835\udd5c f x) r \u03b5 :=\nbegin\n  have := hx.has_fderiv_at,\n  simp only [has_fderiv_at, has_fderiv_at_filter, is_o_iff] at this,\n  rcases eventually_nhds_iff_ball.1 (this (half_pos h\u03b5)) with \u27e8R, R_pos, hR\u27e9,\n  refine \u27e8R, R_pos, \u03bb r hr, _\u27e9,\n  have : r \u2208 Ioc (r/2) r := \u27e8half_lt_self hr.1, le_rfl\u27e9,\n  refine \u27e8r, this, \u03bb y hy z hz, _\u27e9,\n  calc  \u2225f z - f y - (fderiv \ud835\udd5c f x) (z - y)\u2225\n      = \u2225(f z - f x - (fderiv \ud835\udd5c f x) (z - x)) - (f y - f x - (fderiv \ud835\udd5c f x) (y - x))\u2225 :\n    by { congr' 1, simp only [continuous_linear_map.map_sub], abel }\n  ... \u2264 \u2225(f z - f x - (fderiv \ud835\udd5c f x) (z - x))\u2225 + \u2225f y - f x - (fderiv \ud835\udd5c f x) (y - x)\u2225 :\n    norm_sub_le _ _\n  ... \u2264 \u03b5 / 2 * \u2225z - x\u2225 + \u03b5 / 2 * \u2225y - x\u2225 :\n    add_le_add (hR _ (lt_trans (mem_ball.1 hz) hr.2)) (hR _ (lt_trans (mem_ball.1 hy) hr.2))\n  ... \u2264 \u03b5 / 2 * r + \u03b5 / 2 * r :\n    add_le_add\n      (mul_le_mul_of_nonneg_left (le_of_lt (mem_ball_iff_norm.1 hz)) (le_of_lt (half_pos h\u03b5)))\n      (mul_le_mul_of_nonneg_left (le_of_lt (mem_ball_iff_norm.1 hy)) (le_of_lt (half_pos h\u03b5)))\n  ... = \u03b5 * r : by ring\nend\n\nlemma norm_sub_le_of_mem_A {c : \ud835\udd5c} (hc : 1 < \u2225c\u2225)\n  {r \u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) (hr : 0 < r) {x : E} {L\u2081 L\u2082 : E \u2192L[\ud835\udd5c] F}\n  (h\u2081 : x \u2208 A f L\u2081 r \u03b5) (h\u2082 : x \u2208 A f L\u2082 r \u03b5) : \u2225L\u2081 - L\u2082\u2225 \u2264 4 * \u2225c\u2225 * \u03b5 :=\nbegin\n  have : 0 \u2264 4 * \u2225c\u2225 * \u03b5 :=\n    mul_nonneg (mul_nonneg (by norm_num : (0 : \u211d) \u2264 4) (norm_nonneg _)) h\u03b5.le,\n  refine op_norm_le_of_shell (half_pos hr) this hc _,\n  assume y ley ylt,\n  rw [div_div,\n      div_le_iff' (mul_pos (by norm_num : (0 : \u211d) < 2) (zero_lt_one.trans hc))] at ley,\n  calc \u2225(L\u2081 - L\u2082) y\u2225\n        = \u2225(f (x + y) - f x - L\u2082 ((x + y) - x)) - (f (x + y) - f x - L\u2081 ((x + y) - x))\u2225 : by simp\n    ... \u2264 \u2225(f (x + y) - f x - L\u2082 ((x + y) - x))\u2225 + \u2225(f (x + y) - f x - L\u2081 ((x + y) - x))\u2225 :\n      norm_sub_le _ _\n    ... \u2264 \u03b5 * r + \u03b5 * r :\n      begin\n        apply add_le_add,\n        { apply le_of_mem_A h\u2082,\n          { simp only [le_of_lt (half_pos hr), mem_closed_ball, dist_self] },\n          { simp only [dist_eq_norm, add_sub_cancel', mem_closed_ball, ylt.le], } },\n        { apply le_of_mem_A h\u2081,\n          { simp only [le_of_lt (half_pos hr), mem_closed_ball, dist_self] },\n          { simp only [dist_eq_norm, add_sub_cancel', mem_closed_ball, ylt.le] } },\n      end\n    ... = 2 * \u03b5 * r : by ring\n    ... \u2264 2 * \u03b5 * (2 * \u2225c\u2225 * \u2225y\u2225) : mul_le_mul_of_nonneg_left ley (mul_nonneg (by norm_num) h\u03b5.le)\n    ... = 4 * \u2225c\u2225 * \u03b5 * \u2225y\u2225 : by ring\nend\n\n/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/\nlemma differentiable_set_subset_D : {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} \u2286 D f K :=\nbegin\n  assume x hx,\n  rw [D, mem_Inter],\n  assume e,\n  have : (0 : \u211d) < (1/2) ^ e := pow_pos (by norm_num) _,\n  rcases mem_A_of_differentiable this hx.1 with \u27e8R, R_pos, hR\u27e9,\n  obtain \u27e8n, hn\u27e9 : \u2203 (n : \u2115), (1/2) ^ n < R :=\n    exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : \u211d)/2 < 1),\n  simp only [mem_Union, mem_Inter, B, mem_inter_eq],\n  refine \u27e8n, \u03bb p hp q hq, \u27e8fderiv \ud835\udd5c f x, hx.2, \u27e8_, _\u27e9\u27e9\u27e9;\n  { refine hR _ \u27e8pow_pos (by norm_num) _, lt_of_le_of_lt _ hn\u27e9,\n    exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) }\nend\n\n/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/\nlemma D_subset_differentiable_set {K : set (E \u2192L[\ud835\udd5c] F)} (hK : is_complete K) :\n  D f K \u2286 {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} :=\nbegin\n  have P : \u2200 {n : \u2115}, (0 : \u211d) < (1/2) ^ n := pow_pos (by norm_num),\n  rcases normed_field.exists_one_lt_norm \ud835\udd5c with \u27e8c, hc\u27e9,\n  have cpos : 0 < \u2225c\u2225 := lt_trans zero_lt_one hc,\n  assume x hx,\n  have : \u2200 (e : \u2115), \u2203 (n : \u2115), \u2200 p q, n \u2264 p \u2192 n \u2264 q \u2192 \u2203 L \u2208 K,\n    x \u2208 A f L ((1/2) ^ p) ((1/2) ^ e) \u2229 A f L ((1/2) ^ q) ((1/2) ^ e),\n  { assume e,\n    have := mem_Inter.1 hx e,\n    rcases mem_Union.1 this with \u27e8n, hn\u27e9,\n    refine \u27e8n, \u03bb p q hp hq, _\u27e9,\n    simp only [mem_Inter, ge_iff_le] at hn,\n    rcases mem_Union.1 (hn p hp q hq) with \u27e8L, hL\u27e9,\n    exact \u27e8L, mem_Union.1 hL\u27e9, },\n  /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`\n  such that, for `p, q \u2265 n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and\n  `2 ^ (-q)`, with an error `2 ^ (-e)`. -/\n  choose! n L hn using this,\n  /- All the operators `L e p q` that show up are close to each other. To prove this, we argue\n    that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at\n    scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale\n    `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale\n    `2 ^ (- p')`. -/\n  have M : \u2200 e p q e' p' q', n e \u2264 p \u2192 n e \u2264 q \u2192 n e' \u2264 p' \u2192 n e' \u2264 q' \u2192 e \u2264 e' \u2192\n    \u2225L e p q - L e' p' q'\u2225 \u2264 12 * \u2225c\u2225 * (1/2) ^ e,\n  { assume e p q e' p' q' hp hq hp' hq' he',\n    let r := max (n e) (n e'),\n    have I : ((1:\u211d)/2)^e' \u2264 (1/2)^e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he',\n    have J1 : \u2225L e p q - L e p r\u2225 \u2264 4 * \u2225c\u2225 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p q) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p q hp hq).2.1,\n      have I2 : x \u2208 A f (L e p r) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.1,\n      exact norm_sub_le_of_mem_A hc P P I1 I2 },\n    have J2 : \u2225L e p r - L e' p' r\u2225 \u2264 4 * \u2225c\u2225 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p r) ((1 / 2) ^ r) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.2,\n      have I2 : x \u2208 A f (L e' p' r) ((1 / 2) ^ r) ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.2,\n      exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2) },\n    have J3 : \u2225L e' p' r - L e' p' q'\u2225 \u2264 4 * \u2225c\u2225 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e' p' r) ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.1,\n      have I2 : x \u2208 A f (L e' p' q') ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' q' hp' hq').2.1,\n      exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2) },\n    calc \u2225L e p q - L e' p' q'\u2225\n          = \u2225(L e p q - L e p r) + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')\u2225 :\n        by { congr' 1, abel }\n      ... \u2264 \u2225L e p q - L e p r\u2225 + \u2225L e p r - L e' p' r\u2225 + \u2225L e' p' r - L e' p' q'\u2225 :\n        le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)\n      ... \u2264 4 * \u2225c\u2225 * (1/2)^e + 4 * \u2225c\u2225 * (1/2)^e + 4 * \u2225c\u2225 * (1/2)^e :\n        by apply_rules [add_le_add]\n      ... = 12 * \u2225c\u2225 * (1/2)^e : by ring },\n  /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this\n  is a Cauchy sequence. -/\n  let L0 : \u2115 \u2192 (E \u2192L[\ud835\udd5c] F) := \u03bb e, L e (n e) (n e),\n  have : cauchy_seq L0,\n  { rw metric.cauchy_seq_iff',\n    assume \u03b5 \u03b5pos,\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1/2) ^ e < \u03b5 / (12 * \u2225c\u2225) :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos (mul_pos (by norm_num) cpos)) (by norm_num),\n    refine \u27e8e, \u03bb e' he', _\u27e9,\n    rw [dist_comm, dist_eq_norm],\n    calc \u2225L0 e - L0 e'\u2225\n          \u2264 12 * \u2225c\u2225 * (1/2)^e : M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'\n      ... < 12 * \u2225c\u2225 * (\u03b5 / (12 * \u2225c\u2225)) :\n        mul_lt_mul' le_rfl he (le_of_lt P) (mul_pos (by norm_num) cpos)\n      ... = \u03b5 : by { field_simp [(by norm_num : (12 : \u211d) \u2260 0), ne_of_gt cpos], ring } },\n  /- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.-/\n  obtain \u27e8f', f'K, hf'\u27e9 : \u2203 f' \u2208 K, tendsto L0 at_top (\ud835\udcdd f') :=\n    cauchy_seq_tendsto_of_is_complete hK (\u03bb e, (hn e (n e) (n e) le_rfl le_rfl).1) this,\n  have Lf' : \u2200 e p, n e \u2264 p \u2192 \u2225L e (n e) p - f'\u2225 \u2264 12 * \u2225c\u2225 * (1/2)^e,\n  { assume e p hp,\n    apply le_of_tendsto (tendsto_const_nhds.sub hf').norm,\n    rw eventually_at_top,\n    exact \u27e8e, \u03bb e' he', M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'\u27e9 },\n  /- Let us show that `f` has derivative `f'` at `x`. -/\n  have : has_fderiv_at f f' x,\n  { simp only [has_fderiv_at_iff_is_o_nhds_zero, is_o_iff],\n    /- to get an approximation with a precision `\u03b5`, we will replace `f` with `L e (n e) m` for\n    some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,\n    this makes it possible to cover all scales, and thus to obtain a good linear approximation in\n    the whole ball of radius `(1/2)^(n e)`. -/\n    assume \u03b5 \u03b5pos,\n    have pos : 0 < 4 + 12 * \u2225c\u2225 :=\n      add_pos_of_pos_of_nonneg (by norm_num) (mul_nonneg (by norm_num) (norm_nonneg _)),\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1 / 2) ^ e < \u03b5 / (4 + 12 * \u2225c\u2225) :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos pos) (by norm_num),\n    rw eventually_nhds_iff_ball,\n    refine \u27e8(1/2) ^ (n e + 1), P, \u03bb y hy, _\u27e9,\n    -- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale\n    -- `k` where `k` is chosen with `\u2225y\u2225 \u223c 2 ^ (-k)`.\n    by_cases y_pos : y = 0, {simp [y_pos] },\n    have yzero : 0 < \u2225y\u2225 := norm_pos_iff.mpr y_pos,\n    have y_lt : \u2225y\u2225 < (1/2) ^ (n e + 1), by simpa using mem_ball_iff_norm.1 hy,\n    have yone : \u2225y\u2225 \u2264 1 :=\n      le_trans (y_lt.le) (pow_le_one _ (by norm_num) (by norm_num)),\n    -- define the scale `k`.\n    obtain \u27e8k, hk, h'k\u27e9 : \u2203 (k : \u2115), (1/2) ^ (k + 1) < \u2225y\u2225 \u2227 \u2225y\u2225 \u2264 (1/2) ^ k :=\n      exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : \u211d) < 1/2)\n      (by norm_num : (1 : \u211d)/2 < 1),\n    -- the scale is large enough (as `y` is small enough)\n    have k_gt : n e < k,\n    { have : ((1:\u211d)/2) ^ (k + 1) < (1/2) ^ (n e + 1) := lt_trans hk y_lt,\n      rw pow_lt_pow_iff_of_lt_one (by norm_num : (0 : \u211d) < 1/2) (by norm_num) at this,\n      linarith },\n    set m := k - 1 with hl,\n    have m_ge : n e \u2264 m := nat.le_pred_of_lt k_gt,\n    have km : k = m + 1 := (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm,\n    rw km at hk h'k,\n    -- `f` is well approximated by `L e (n e) k` at the relevant scale\n    -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).\n    have J1 : \u2225f (x + y) - f x - L e (n e) m ((x + y) - x)\u2225 \u2264 (1/2) ^ e * (1/2) ^ m,\n    { apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2,\n      { simp only [mem_closed_ball, dist_self],\n        exact div_nonneg (le_of_lt P) (zero_le_two) },\n      { simpa only [dist_eq_norm, add_sub_cancel', mem_closed_ball, pow_succ', mul_one_div]\n          using h'k } },\n    have J2 : \u2225f (x + y) - f x - L e (n e) m y\u2225 \u2264 4 * (1/2) ^ e * \u2225y\u2225 := calc\n      \u2225f (x + y) - f x - L e (n e) m y\u2225 \u2264 (1/2) ^ e * (1/2) ^ m :\n        by simpa only [add_sub_cancel'] using J1\n      ... = 4 * (1/2) ^ e * (1/2) ^ (m + 2) : by { field_simp, ring_exp }\n      ... \u2264 4 * (1/2) ^ e * \u2225y\u2225 :\n        mul_le_mul_of_nonneg_left (le_of_lt hk) (mul_nonneg (by norm_num) (le_of_lt P)),\n    -- use the previous estimates to see that `f (x + y) - f x - f' y` is small.\n    calc \u2225f (x + y) - f x - f' y\u2225\n        = \u2225(f (x + y) - f x - L e (n e) m y) + (L e (n e) m - f') y\u2225 :\n      congr_arg _ (by simp)\n    ... \u2264 4 * (1/2) ^ e * \u2225y\u2225 + 12 * \u2225c\u2225 * (1/2) ^ e * \u2225y\u2225 :\n      norm_add_le_of_le J2\n        ((le_op_norm _ _).trans (mul_le_mul_of_nonneg_right (Lf' _ _ m_ge) (norm_nonneg _)))\n    ... = (4 + 12 * \u2225c\u2225) * \u2225y\u2225 * (1/2) ^ e : by ring\n    ... \u2264 (4 + 12 * \u2225c\u2225) * \u2225y\u2225 * (\u03b5 / (4 + 12 * \u2225c\u2225)) :\n      mul_le_mul_of_nonneg_left he.le\n        (mul_nonneg (add_nonneg (by norm_num) (mul_nonneg (by norm_num) (norm_nonneg _)))\n          (norm_nonneg _))\n    ... = \u03b5 * \u2225y\u2225 : by { field_simp [ne_of_gt pos], ring } },\n  rw \u2190 this.fderiv at f'K,\n  exact \u27e8this.differentiable_at, f'K\u27e9\nend\n\ntheorem differentiable_set_eq_D (hK : is_complete K) :\n  {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} = D f K :=\nsubset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)\n\nend fderiv_measurable_aux\n\nopen fderiv_measurable_aux\n\nvariables [measurable_space E] [opens_measurable_space E]\nvariables (\ud835\udd5c f)\n\n/-- The set of differentiability points of a function, with derivative in a given complete set,\nis Borel-measurable. -/\ntheorem measurable_set_of_differentiable_at_of_is_complete\n  {K : set (E \u2192L[\ud835\udd5c] F)} (hK : is_complete K) :\n  measurable_set {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} :=\nby simp [differentiable_set_eq_D K hK, D, is_open_B.measurable_set, measurable_set.Inter_Prop,\n         measurable_set.Inter, measurable_set.Union]\n\nvariable [complete_space F]\n\n/-- The set of differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurable_set_of_differentiable_at :\n  measurable_set {x | differentiable_at \ud835\udd5c f x} :=\nbegin\n  have : is_complete (univ : set (E \u2192L[\ud835\udd5c] F)) := complete_univ,\n  convert measurable_set_of_differentiable_at_of_is_complete \ud835\udd5c f this,\n  simp\nend\n\n@[measurability] lemma measurable_fderiv : measurable (fderiv \ud835\udd5c f) :=\nbegin\n  refine measurable_of_is_closed (\u03bb s hs, _),\n  have : fderiv \ud835\udd5c f \u207b\u00b9' s = {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 s} \u222a\n    ({x | \u00acdifferentiable_at \ud835\udd5c f x} \u2229 {x | (0 : E \u2192L[\ud835\udd5c] F) \u2208 s}) :=\n    set.ext (\u03bb x, mem_preimage.trans fderiv_mem_iff),\n  rw this,\n  exact (measurable_set_of_differentiable_at_of_is_complete _ _ hs.is_complete).union\n    ((measurable_set_of_differentiable_at _ _).compl.inter (measurable_set.const _))\nend\n\n@[measurability] lemma measurable_fderiv_apply_const [measurable_space F] [borel_space F] (y : E) :\n  measurable (\u03bb x, fderiv \ud835\udd5c f x y) :=\n(continuous_linear_map.measurable_apply y).comp (measurable_fderiv \ud835\udd5c f)\n\nvariable {\ud835\udd5c}\n\n@[measurability] lemma measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [measurable_space F] [borel_space F] (f : \ud835\udd5c \u2192 F) : measurable (deriv f) :=\nby simpa only [fderiv_deriv] using measurable_fderiv_apply_const \ud835\udd5c f 1\n\nlemma strongly_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [second_countable_topology F] (f : \ud835\udd5c \u2192 F) :\n  strongly_measurable (deriv f) :=\nby { borelize F, exact (measurable_deriv f).strongly_measurable }\n\nlemma ae_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c] [measurable_space F]\n  [borel_space F] (f : \ud835\udd5c \u2192 F) (\u03bc : measure \ud835\udd5c) : ae_measurable (deriv f) \u03bc :=\n(measurable_deriv f).ae_measurable\n\nlemma ae_strongly_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [second_countable_topology F] (f : \ud835\udd5c \u2192 F) (\u03bc : measure \ud835\udd5c) :\n  ae_strongly_measurable (deriv f) \u03bc :=\n(strongly_measurable_deriv f).ae_strongly_measurable\n\nend fderiv\n\nsection right_deriv\n\nvariables {F : Type*} [normed_group F] [normed_space \u211d F]\nvariables {f : \u211d \u2192 F} (K : set F)\n\nnamespace right_deriv_measurable_aux\n\n/-- The set `A f L r \u03b5` is the set of points `x` around which the function `f` is well approximated\nat scale `r` by the linear map `h \u21a6 h \u2022 L`, up to an error `\u03b5`. We tweak the definition to\nmake sure that this is open on the right. -/\ndef A (f : \u211d \u2192 F) (L : F) (r \u03b5 : \u211d) : set \u211d :=\n{x | \u2203 r' \u2208 Ioc (r/2) r, \u2200 y z \u2208 Icc x (x + r'), \u2225f z - f y - (z-y) \u2022 L\u2225 \u2264 \u03b5 * r}\n\n/-- The set `B f K r s \u03b5` is the set of points `x` around which there exists a vector\n`L` belonging to `K` (a given set of vectors) such that `h \u2022 L` approximates well `f (x + h)`\n(up to an error `\u03b5`), simultaneously at scales `r` and `s`. -/\ndef B (f : \u211d \u2192 F) (K : set F) (r s \u03b5 : \u211d) : set \u211d :=\n\u22c3 (L \u2208 K), (A f L r \u03b5) \u2229 (A f L s \u03b5)\n\n/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its\nmain use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,\nwith a derivative in `K`. -/\ndef D (f : \u211d \u2192 F) (K : set F) : set \u211d :=\n\u22c2 (e : \u2115), \u22c3 (n : \u2115), \u22c2 (p \u2265 n) (q \u2265 n), B f K ((1/2) ^ p) ((1/2) ^ q) ((1/2) ^ e)\n\nlemma A_mem_nhds_within_Ioi {L : F} {r \u03b5 x : \u211d} (hx : x \u2208 A f L r \u03b5) :\n  A f L r \u03b5 \u2208 \ud835\udcdd[>] x :=\nbegin\n  rcases hx with \u27e8r', rr', hr'\u27e9,\n  rw mem_nhds_within_Ioi_iff_exists_Ioo_subset,\n  obtain \u27e8s, s_gt, s_lt\u27e9 : \u2203 (s : \u211d), r / 2 < s \u2227 s < r' := exists_between rr'.1,\n  have : s \u2208 Ioc (r/2) r := \u27e8s_gt, le_of_lt (s_lt.trans_le rr'.2)\u27e9,\n  refine \u27e8x + r' - s, by { simp only [mem_Ioi], linarith }, \u03bb x' hx', \u27e8s, this, _\u27e9\u27e9,\n  have A : Icc x' (x' + s) \u2286 Icc x (x + r'),\n  { apply Icc_subset_Icc hx'.1.le,\n    linarith [hx'.2] },\n  assume y hy z hz,\n  exact hr' y (A hy) z (A hz)\nend\n\nlemma B_mem_nhds_within_Ioi {K : set F} {r s \u03b5 x : \u211d} (hx : x \u2208 B f K r s \u03b5) :\n  B f K r s \u03b5 \u2208 \ud835\udcdd[>] x :=\nbegin\n  obtain \u27e8L, LK, hL\u2081, hL\u2082\u27e9 : \u2203 (L : F), L \u2208 K \u2227 x \u2208 A f L r \u03b5 \u2227 x \u2208 A f L s \u03b5,\n    by simpa only [B, mem_Union, mem_inter_eq, exists_prop] using hx,\n  filter_upwards [A_mem_nhds_within_Ioi hL\u2081, A_mem_nhds_within_Ioi hL\u2082] with y hy\u2081 hy\u2082,\n  simp only [B, mem_Union, mem_inter_eq, exists_prop],\n  exact \u27e8L, LK, hy\u2081, hy\u2082\u27e9\nend\n\nlemma measurable_set_B {K : set F} {r s \u03b5 : \u211d} : measurable_set (B f K r s \u03b5) :=\nmeasurable_set_of_mem_nhds_within_Ioi (\u03bb x hx, B_mem_nhds_within_Ioi hx)\n\nlemma A_mono (L : F) (r : \u211d) {\u03b5 \u03b4 : \u211d} (h : \u03b5 \u2264 \u03b4) :\n  A f L r \u03b5 \u2286 A f L r \u03b4 :=\nbegin\n  rintros x \u27e8r', r'r, hr'\u27e9,\n  refine \u27e8r', r'r, \u03bb y hy z hz, (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h _)\u27e9,\n  linarith [hy.1, hy.2, r'r.2],\nend\n\nlemma le_of_mem_A {r \u03b5 : \u211d} {L : F} {x : \u211d} (hx : x \u2208 A f L r \u03b5)\n  {y z : \u211d} (hy : y \u2208 Icc x (x + r/2)) (hz : z \u2208 Icc x (x + r/2)) :\n  \u2225f z - f y - (z-y) \u2022 L\u2225 \u2264 \u03b5 * r :=\nbegin\n  rcases hx with \u27e8r', r'mem, hr'\u27e9,\n  have A : x + r / 2 \u2264 x + r', by linarith [r'mem.1],\n  exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz),\nend\n\nlemma mem_A_of_differentiable {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {x : \u211d}\n  (hx : differentiable_within_at \u211d f (Ici x) x) :\n  \u2203 R > 0, \u2200 r \u2208 Ioo (0 : \u211d) R, x \u2208 A f (deriv_within f (Ici x) x) r \u03b5 :=\nbegin\n  have := hx.has_deriv_within_at,\n  simp_rw [has_deriv_within_at_iff_is_o, is_o_iff] at this,\n  rcases mem_nhds_within_Ici_iff_exists_Ico_subset.1 (this (half_pos h\u03b5)) with \u27e8m, xm, hm\u27e9,\n  refine \u27e8m - x, by linarith [show x < m, from xm], \u03bb r hr, _\u27e9,\n  have : r \u2208 Ioc (r/2) r := \u27e8half_lt_self hr.1, le_rfl\u27e9,\n  refine \u27e8r, this, \u03bb y hy z hz, _\u27e9,\n  calc  \u2225f z - f y - (z - y) \u2022 deriv_within f (Ici x) x\u2225\n      = \u2225(f z - f x - (z - x) \u2022 deriv_within f (Ici x) x)\n           - (f y - f x - (y - x) \u2022 deriv_within f (Ici x) x)\u2225 :\n    by { congr' 1, simp only [sub_smul], abel }\n  ... \u2264 \u2225f z - f x - (z - x) \u2022 deriv_within f (Ici x) x\u2225\n         + \u2225f y - f x - (y - x) \u2022 deriv_within f (Ici x) x\u2225 :\n    norm_sub_le _ _\n  ... \u2264 \u03b5 / 2 * \u2225z - x\u2225 + \u03b5 / 2 * \u2225y - x\u2225 :\n    add_le_add (hm \u27e8hz.1, hz.2.trans_lt (by linarith [hr.2])\u27e9)\n               (hm \u27e8hy.1, hy.2.trans_lt (by linarith [hr.2])\u27e9)\n  ... \u2264 \u03b5 / 2 * r + \u03b5 / 2 * r :\n  begin\n    apply add_le_add,\n    { apply mul_le_mul_of_nonneg_left _ (le_of_lt (half_pos h\u03b5)),\n      rw [real.norm_of_nonneg];\n      linarith [hz.1, hz.2] },\n    { apply mul_le_mul_of_nonneg_left _ (le_of_lt (half_pos h\u03b5)),\n      rw [real.norm_of_nonneg];\n      linarith [hy.1, hy.2] },\n   end\n  ... = \u03b5 * r : by ring\nend\n\nlemma norm_sub_le_of_mem_A\n  {r x : \u211d} (hr : 0 < r) (\u03b5 : \u211d) {L\u2081 L\u2082 : F}\n  (h\u2081 : x \u2208 A f L\u2081 r \u03b5) (h\u2082 : x \u2208 A f L\u2082 r \u03b5) : \u2225L\u2081 - L\u2082\u2225 \u2264 4 * \u03b5 :=\nbegin\n  suffices H : \u2225(r/2) \u2022 (L\u2081 - L\u2082)\u2225 \u2264 (r / 2) * (4 * \u03b5),\n    by rwa [norm_smul, real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H,\n  calc\n  \u2225(r/2) \u2022 (L\u2081 - L\u2082)\u2225\n      = \u2225(f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2082) - (f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2081)\u2225 :\n    by simp [smul_sub]\n  ... \u2264 \u2225f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2082\u2225 + \u2225f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2081\u2225 :\n    norm_sub_le _ _\n  ... \u2264 \u03b5 * r + \u03b5 * r :\n    begin\n      apply add_le_add,\n      { apply le_of_mem_A h\u2082;\n        simp [(half_pos hr).le] },\n      { apply le_of_mem_A h\u2081;\n        simp [(half_pos hr).le] },\n    end\n  ... = (r / 2) * (4 * \u03b5) : by ring\nend\n\n/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/\nlemma differentiable_set_subset_D :\n  {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} \u2286 D f K :=\nbegin\n  assume x hx,\n  rw [D, mem_Inter],\n  assume e,\n  have : (0 : \u211d) < (1/2) ^ e := pow_pos (by norm_num) _,\n  rcases mem_A_of_differentiable this hx.1 with \u27e8R, R_pos, hR\u27e9,\n  obtain \u27e8n, hn\u27e9 : \u2203 (n : \u2115), (1/2) ^ n < R :=\n    exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : \u211d)/2 < 1),\n  simp only [mem_Union, mem_Inter, B, mem_inter_eq],\n  refine \u27e8n, \u03bb p hp q hq, \u27e8deriv_within f (Ici x) x, hx.2, \u27e8_, _\u27e9\u27e9\u27e9;\n  { refine hR _ \u27e8pow_pos (by norm_num) _, lt_of_le_of_lt _ hn\u27e9,\n    exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) }\nend\n\n/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/\nlemma D_subset_differentiable_set {K : set F} (hK : is_complete K) :\n  D f K \u2286 {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} :=\nbegin\n  have P : \u2200 {n : \u2115}, (0 : \u211d) < (1/2) ^ n := pow_pos (by norm_num),\n  assume x hx,\n  have : \u2200 (e : \u2115), \u2203 (n : \u2115), \u2200 p q, n \u2264 p \u2192 n \u2264 q \u2192 \u2203 L \u2208 K,\n    x \u2208 A f L ((1/2) ^ p) ((1/2) ^ e) \u2229 A f L ((1/2) ^ q) ((1/2) ^ e),\n  { assume e,\n    have := mem_Inter.1 hx e,\n    rcases mem_Union.1 this with \u27e8n, hn\u27e9,\n    refine \u27e8n, \u03bb p q hp hq, _\u27e9,\n    simp only [mem_Inter, ge_iff_le] at hn,\n    rcases mem_Union.1 (hn p hp q hq) with \u27e8L, hL\u27e9,\n    exact \u27e8L, mem_Union.1 hL\u27e9, },\n  /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`\n  such that, for `p, q \u2265 n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and\n  `2 ^ (-q)`, with an error `2 ^ (-e)`. -/\n  choose! n L hn using this,\n  /- All the operators `L e p q` that show up are close to each other. To prove this, we argue\n    that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at\n    scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale\n    `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale\n    `2 ^ (- p')`. -/\n  have M : \u2200 e p q e' p' q', n e \u2264 p \u2192 n e \u2264 q \u2192 n e' \u2264 p' \u2192 n e' \u2264 q' \u2192 e \u2264 e' \u2192\n    \u2225L e p q - L e' p' q'\u2225 \u2264 12 * (1/2) ^ e,\n  { assume e p q e' p' q' hp hq hp' hq' he',\n    let r := max (n e) (n e'),\n    have I : ((1:\u211d)/2)^e' \u2264 (1/2)^e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he',\n    have J1 : \u2225L e p q - L e p r\u2225 \u2264 4 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p q) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p q hp hq).2.1,\n      have I2 : x \u2208 A f (L e p r) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.1,\n      exact norm_sub_le_of_mem_A P _ I1 I2 },\n    have J2 : \u2225L e p r - L e' p' r\u2225 \u2264 4 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p r) ((1 / 2) ^ r) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.2,\n      have I2 : x \u2208 A f (L e' p' r) ((1 / 2) ^ r) ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.2,\n      exact norm_sub_le_of_mem_A P _ I1 (A_mono _ _ I I2) },\n    have J3 : \u2225L e' p' r - L e' p' q'\u2225 \u2264 4 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e' p' r) ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.1,\n      have I2 : x \u2208 A f (L e' p' q') ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' q' hp' hq').2.1,\n      exact norm_sub_le_of_mem_A P _ (A_mono _ _ I I1) (A_mono _ _ I I2) },\n    calc \u2225L e p q - L e' p' q'\u2225\n          = \u2225(L e p q - L e p r) + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')\u2225 :\n        by { congr' 1, abel }\n      ... \u2264 \u2225L e p q - L e p r\u2225 + \u2225L e p r - L e' p' r\u2225 + \u2225L e' p' r - L e' p' q'\u2225 :\n        le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)\n      ... \u2264 4 * (1/2)^e + 4 * (1/2)^e + 4 * (1/2)^e :\n        by apply_rules [add_le_add]\n      ... = 12 * (1/2)^e : by ring },\n  /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this\n  is a Cauchy sequence. -/\n  let L0 : \u2115 \u2192 F := \u03bb e, L e (n e) (n e),\n  have : cauchy_seq L0,\n  { rw metric.cauchy_seq_iff',\n    assume \u03b5 \u03b5pos,\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1/2) ^ e < \u03b5 / 12 :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos (by norm_num)) (by norm_num),\n    refine \u27e8e, \u03bb e' he', _\u27e9,\n    rw [dist_comm, dist_eq_norm],\n    calc \u2225L0 e - L0 e'\u2225\n          \u2264 12 * (1/2)^e : M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'\n      ... < 12 * (\u03b5 / 12) :\n        mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num)\n      ... = \u03b5 : by { field_simp [(by norm_num : (12 : \u211d) \u2260 0)], ring } },\n  /- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.-/\n  obtain \u27e8f', f'K, hf'\u27e9 : \u2203 f' \u2208 K, tendsto L0 at_top (\ud835\udcdd f') :=\n    cauchy_seq_tendsto_of_is_complete hK (\u03bb e, (hn e (n e) (n e) le_rfl le_rfl).1) this,\n  have Lf' : \u2200 e p, n e \u2264 p \u2192 \u2225L e (n e) p - f'\u2225 \u2264 12 * (1/2)^e,\n  { assume e p hp,\n    apply le_of_tendsto (tendsto_const_nhds.sub hf').norm,\n    rw eventually_at_top,\n    exact \u27e8e, \u03bb e' he', M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'\u27e9 },\n  /- Let us show that `f` has right derivative `f'` at `x`. -/\n  have : has_deriv_within_at f f' (Ici x) x,\n  { simp only [has_deriv_within_at_iff_is_o, is_o_iff],\n    /- to get an approximation with a precision `\u03b5`, we will replace `f` with `L e (n e) m` for\n    some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,\n    this makes it possible to cover all scales, and thus to obtain a good linear approximation in\n    the whole interval of length `(1/2)^(n e)`. -/\n    assume \u03b5 \u03b5pos,\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1 / 2) ^ e < \u03b5 / 16 :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos (by norm_num)) (by norm_num),\n    have xmem : x \u2208 Ico x (x + (1/2)^(n e + 1)),\n      by simp only [one_div, left_mem_Ico, lt_add_iff_pos_right, inv_pos, pow_pos, zero_lt_bit0,\n        zero_lt_one],\n    filter_upwards [Icc_mem_nhds_within_Ici xmem] with y hy,\n    -- We need to show that `f y - f x - f' (y - x)` is small. For this, we will work at scale\n    -- `k` where `k` is chosen with `\u2225y - x\u2225 \u223c 2 ^ (-k)`.\n    rcases eq_or_lt_of_le hy.1 with rfl|xy,\n    { simp only [sub_self, zero_smul, norm_zero, mul_zero]},\n    have yzero : 0 < y - x := sub_pos.2 xy,\n    have y_le : y - x \u2264 (1/2) ^ (n e + 1), by linarith [hy.2],\n    have yone : y - x \u2264 1 := le_trans y_le (pow_le_one _ (by norm_num) (by norm_num)),\n    -- define the scale `k`.\n    obtain \u27e8k, hk, h'k\u27e9 : \u2203 (k : \u2115), (1/2) ^ (k + 1) < y - x \u2227 y - x \u2264 (1/2) ^ k :=\n      exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : \u211d) < 1/2)\n      (by norm_num : (1 : \u211d)/2 < 1),\n    -- the scale is large enough (as `y - x` is small enough)\n    have k_gt : n e < k,\n    { have : ((1:\u211d)/2) ^ (k + 1) < (1/2) ^ (n e + 1) := lt_of_lt_of_le hk y_le,\n      rw pow_lt_pow_iff_of_lt_one (by norm_num : (0 : \u211d) < 1/2) (by norm_num) at this,\n      linarith },\n    set m := k - 1 with hl,\n    have m_ge : n e \u2264 m := nat.le_pred_of_lt k_gt,\n    have km : k = m + 1 := (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm,\n    rw km at hk h'k,\n    -- `f` is well approximated by `L e (n e) k` at the relevant scale\n    -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).\n    have J : \u2225f y - f x - (y - x) \u2022 L e (n e) m\u2225 \u2264 4 * (1/2) ^ e * \u2225y - x\u2225 := calc\n      \u2225f y - f x - (y - x) \u2022 L e (n e) m\u2225 \u2264 (1/2) ^ e * (1/2) ^ m :\n        begin\n          apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2,\n          { simp only [one_div, inv_pow, left_mem_Icc, le_add_iff_nonneg_right],\n            exact div_nonneg (inv_nonneg.2 (pow_nonneg zero_le_two _)) zero_le_two },\n          { simp only [pow_add, tsub_le_iff_left] at h'k,\n            simpa only [hy.1, mem_Icc, true_and, one_div, pow_one] using h'k }\n        end\n      ... = 4 * (1/2) ^ e * (1/2) ^ (m + 2) : by { field_simp, ring_exp }\n      ... \u2264 4 * (1/2) ^ e * (y - x) :\n        mul_le_mul_of_nonneg_left (le_of_lt hk) (mul_nonneg (by norm_num) (le_of_lt P))\n      ... = 4 * (1/2) ^ e * \u2225y - x\u2225 : by rw [real.norm_of_nonneg yzero.le],\n    calc \u2225f y - f x - (y - x) \u2022 f'\u2225\n        = \u2225(f y - f x - (y - x) \u2022 L e (n e) m) + (y - x) \u2022 (L e (n e) m - f')\u2225 :\n      by simp only [smul_sub, sub_add_sub_cancel]\n    ... \u2264 4 * (1/2) ^ e * \u2225y - x\u2225 + \u2225y - x\u2225 * (12 * (1/2) ^ e) : norm_add_le_of_le J\n      (by { rw [norm_smul], exact mul_le_mul_of_nonneg_left (Lf' _ _ m_ge) (norm_nonneg _) })\n    ... = 16 * \u2225y - x\u2225 * (1/2) ^ e : by ring\n    ... \u2264 16 * \u2225y - x\u2225 * (\u03b5 / 16) :\n      mul_le_mul_of_nonneg_left he.le (mul_nonneg (by norm_num) (norm_nonneg _))\n    ... = \u03b5 * \u2225y - x\u2225 : by ring },\n  rw \u2190 this.deriv_within (unique_diff_on_Ici x x le_rfl) at f'K,\n  exact \u27e8this.differentiable_within_at, f'K\u27e9,\nend\n\ntheorem differentiable_set_eq_D (hK : is_complete K) :\n  {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} = D f K :=\nsubset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)\n\nend right_deriv_measurable_aux\n\nopen right_deriv_measurable_aux\n\nvariables (f)\n\n/-- The set of right differentiability points of a function, with derivative in a given complete\nset, is Borel-measurable. -/\ntheorem measurable_set_of_differentiable_within_at_Ici_of_is_complete\n  {K : set F} (hK : is_complete K) :\n  measurable_set {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} :=\nby simp [differentiable_set_eq_D K hK, D, measurable_set_B, measurable_set.Inter_Prop,\n         measurable_set.Inter, measurable_set.Union]\n\nvariable [complete_space F]\n\n/-- The set of right differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurable_set_of_differentiable_within_at_Ici :\n  measurable_set {x | differentiable_within_at \u211d f (Ici x) x} :=\nbegin\n  have : is_complete (univ : set F) := complete_univ,\n  convert measurable_set_of_differentiable_within_at_Ici_of_is_complete f this,\n  simp\nend\n\n@[measurability] lemma measurable_deriv_within_Ici [measurable_space F] [borel_space F] :\n  measurable (\u03bb x, deriv_within f (Ici x) x) :=\nbegin\n  refine measurable_of_is_closed (\u03bb s hs, _),\n  have : (\u03bb x, deriv_within f (Ici x) x) \u207b\u00b9' s =\n    {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 s} \u222a\n    ({x | \u00acdifferentiable_within_at \u211d f (Ici x) x} \u2229 {x | (0 : F) \u2208 s}) :=\n    set.ext (\u03bb x, mem_preimage.trans deriv_within_mem_iff),\n  rw this,\n  exact (measurable_set_of_differentiable_within_at_Ici_of_is_complete _ hs.is_complete).union\n    ((measurable_set_of_differentiable_within_at_Ici _).compl.inter (measurable_set.const _))\nend\n\nlemma strongly_measurable_deriv_within_Ici [second_countable_topology F] :\n  strongly_measurable (\u03bb x, deriv_within f (Ici x) x) :=\nby { borelize F, exact (measurable_deriv_within_Ici f).strongly_measurable }\n\nlemma ae_measurable_deriv_within_Ici [measurable_space F] [borel_space F]\n  (\u03bc : measure \u211d) : ae_measurable (\u03bb x, deriv_within f (Ici x) x) \u03bc :=\n(measurable_deriv_within_Ici f).ae_measurable\n\nlemma ae_strongly_measurable_deriv_within_Ici [second_countable_topology F] (\u03bc : measure \u211d) :\n  ae_strongly_measurable (\u03bb x, deriv_within f (Ici x) x) \u03bc :=\n(strongly_measurable_deriv_within_Ici f).ae_strongly_measurable\n\n/-- The set of right differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurable_set_of_differentiable_within_at_Ioi :\n  measurable_set {x | differentiable_within_at \u211d f (Ioi x) x} :=\nby simpa [differentiable_within_at_Ioi_iff_Ici]\n  using measurable_set_of_differentiable_within_at_Ici f\n\n@[measurability] lemma measurable_deriv_within_Ioi [measurable_space F] [borel_space F] :\n  measurable (\u03bb x, deriv_within f (Ioi x) x) :=\nby simpa [deriv_within_Ioi_eq_Ici] using measurable_deriv_within_Ici f\n\nlemma strongly_measurable_deriv_within_Ioi [second_countable_topology F] :\n  strongly_measurable (\u03bb x, deriv_within f (Ioi x) x) :=\nby { borelize F, exact (measurable_deriv_within_Ioi f).strongly_measurable }\n\nlemma ae_measurable_deriv_within_Ioi [measurable_space F] [borel_space F]\n  (\u03bc : measure \u211d) : ae_measurable (\u03bb x, deriv_within f (Ioi x) x) \u03bc :=\n(measurable_deriv_within_Ioi f).ae_measurable\n\nlemma ae_strongly_measurable_deriv_within_Ioi [second_countable_topology F] (\u03bc : measure \u211d) :\n  ae_strongly_measurable (\u03bb x, deriv_within f (Ioi x) x) \u03bc :=\n(strongly_measurable_deriv_within_Ioi f).ae_strongly_measurable\n\nend right_deriv\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/calculus/fderiv_measurable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7118986248830289}}
{"text": "-- Integers mod 37\n\n-- a demonstration of how to use equivalence relations and equivalence classes in Lean.\n\n-- We define the \"congruent mod 37\" relation on integers,\n-- prove it is an equivalence relation, define Zmod37 to be the equivalence classes,\n-- and put a ring structure on the quotient.\n\nimport tactic\n\n\ndefinition cong_mod37 (a b : \u2124) := \u2203 (k : \u2124), k * 37 = b - a\n\n-- Now check it's an equivalence reln!\n\ntheorem cong_mod_refl : reflexive (cong_mod37) :=\nbegin\n  intro x,\n  -- to prove cong_mod37 x x we just observe that k=0 will do.\n  use 0, -- this is k\n  simp,\nend\n\ntheorem cong_mod_symm : symmetric (cong_mod37) :=\nbegin\n  intros a b H,\n  -- H : cond_mod37 a b\n  cases H with k Hk,\n  -- Hk : k * 37 = (b - a)\n  -- Goal is to find an integer k' with k' * 37 = a - b  \n  use -k,\n  simp [Hk],\nend\n\ntheorem cong_mod_trans : transitive (cong_mod37) :=\nbegin\n  intros a b c Hab Hbc,\n  cases Hab with k Hk,\n  cases Hbc with l Hl,\n  -- k*37 = b - a, l*37 = c - b\n  -- need to solve m*37 = c - a\n  sorry -- can you finish it?\nend\n\n-- so we've now seen a general technique for proving a \u2248 b -- existsi (the k that works)\n\ntheorem cong_mod_equiv : equivalence (cong_mod37) :=\n\u27e8cong_mod_refl, cong_mod_symm, cong_mod_trans\u27e9\n\ninstance Z_setoid : setoid \u2124 := { r := cong_mod37, iseqv := cong_mod_equiv }\n\ndefinition Zmod37 := quotient (Z_setoid)\n\nnamespace Zmod37\n\ndefinition reduce_mod37 : \u2124 \u2192 Zmod37 := quot.mk (cong_mod37)\n\n-- now a little bit of basic interface\n\ninstance coe_int_Zmod37 : has_coe \u2124 (Zmod37) := \u27e8reduce_mod37\u27e9\n\ninstance : has_zero (Zmod37) := \u27e8reduce_mod37 0\u27e9\ninstance : has_one (Zmod37) := \u27e8reduce_mod37 1\u27e9\ninstance : inhabited (Zmod37) := \u27e80\u27e9\n\n@[simp] theorem of_int_zero : (0 : (Zmod37))  = reduce_mod37 0 := rfl \n@[simp] theorem of_int_one : (1 : (Zmod37))  = reduce_mod37 1 := rfl \n\n-- now back to the maths\n\n-- here's a useful lemma -- it's needed to prove addition is well-defined on the quotient.\n-- Note the use of quotient.sound to get from Zmod37 back to Z\n\nlemma congr_add (a\u2081 a\u2082 b\u2081 b\u2082 : \u2124) : a\u2081 \u2248 b\u2081 \u2192 a\u2082 \u2248 b\u2082 \u2192 \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7 :=\nbegin\n  intros H1 H2,\n  cases H1 with m Hm, -- Hm : m * 37 = b\u2081 - a\u2081\n  cases H2 with n Hn, -- Hn : n * 37 = b\u2082 - a\u2082\n  -- goal is \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7\n  apply quotient.sound,\n  -- goal now a\u2081 + a\u2082 \u2248 b\u2081 + b\u2082, and we know how to do these.\n  use (m + n),\n  rw [add_mul, Hm, Hn],\n  ring,\nend \n\n-- That lemma above is *exactly* what we need to make sure addition is\n-- well-defined on Zmod37, so let's do this now, using quotient.lift \n\n-- note: stuff like \"add\" is used everywhere so it's best to protect.\nprotected definition add : Zmod37 \u2192 Zmod37 \u2192 Zmod37 :=\nquotient.lift\u2082 (\u03bb a b : \u2124, \u27e6a + b\u27e7) (begin\n  show \u2200 (a\u2081 a\u2082 b\u2081 b\u2082 : \u2124), a\u2081 \u2248 b\u2081 \u2192 a\u2082 \u2248 b\u2082 \u2192 \u27e6a\u2081 + a\u2082\u27e7 = \u27e6b\u2081 + b\u2082\u27e7,\n  -- that's what quotient.lift\u2082 reduces us to doing. But we did it already!\n  exact congr_add,\nend)\n\n-- Now here's the lemma we need for the definition of neg\n\n-- I spelt out the proof for add, here's a quick term proof for neg.\n\nlemma congr_neg (a b : \u2124) : a \u2248 b \u2192 \u27e6-a\u27e7 = \u27e6-b\u27e7 :=\n\u03bb \u27e8m, Hm\u27e9, quotient.sound \u27e8-m, by simp [Hm]\u27e9\n\nprotected def neg : Zmod37 \u2192 Zmod37 := quotient.lift (\u03bb a : \u2124, \u27e6-a\u27e7) congr_neg\n\n-- For multiplication I won't even bother proving the lemma, I'll just let ring do it\n\nprotected def mul : Zmod37 \u2192 Zmod37 \u2192 Zmod37 :=\nquotient.lift\u2082 (\u03bb a b : \u2124, \u27e6a*b\u27e7) (\u03bb a\u2081 a\u2082 b\u2081 b\u2082 \u27e8m\u2081,H\u2081\u27e9 \u27e8m\u2082,H\u2082\u27e9,quotient.sound \u27e8b\u2081 * m\u2082 + a\u2082 * m\u2081,\n  by {rw [add_mul, mul_assoc, mul_assoc, H\u2081, H\u2082], ring}\u27e9)\n\n-- this adds notation to the quotient\n\ninstance : has_add (Zmod37) := \u27e8Zmod37.add\u27e9\ninstance : has_neg (Zmod37) := \u27e8Zmod37.neg\u27e9\ninstance : has_mul (Zmod37) := \u27e8Zmod37.mul\u27e9\n\n-- these are now very cool proofs:\n@[simp] lemma coe_add {a b : \u2124} : (\u2191(a + b) : Zmod37) = \u2191a + \u2191b := rfl\n@[simp] lemma coe_neg {a : \u2124} : (\u2191(-a) : Zmod37) = -\u2191a := rfl\n@[simp] lemma coe_mul {a b : \u2124} : (\u2191(a * b) : Zmod37) = \u2191a * \u2191b := rfl\n\n-- The proof of coe_add would not be rfl at all if you defined addition on the quotient\n-- by choosing representatives and then adding them. Note that choosing reps\n-- and adding them is exactly what mathematicians do; they shoot first and\n-- ask questions later.\n\n-- Now here's how to use quotient.induction_on and quotient.sound\n\ninstance : add_comm_group (Zmod37)  :=\n{ add_comm_group .\n  zero         := 0, -- because we already defined has_zero\n  add          := (+), -- could also have written has_add.add\n  neg          := has_neg.neg,\n  zero_add     := \n    \u03bb abar, quotient.induction_on abar (begin\n      -- goal is \u2200 (a : \u2124), 0 + \u27e6a\u27e7 = \u27e6a\u27e7 -- that's what quotient.induction_on does for us\n      intro a,\n      apply quotient.sound, -- works because 0 + \u27e6a\u27e7 is by definition \u27e60\u27e7 + \u27e6a\u27e7 which is by definition \u27e60 + a\u27e7\n      -- goal is now 0 + a \u2248 a\n      -- here's the way we used to do it.\n      existsi (0 : \u2124),\n      simp,\n      -- but there are tricks now, which I'll show you with add_zero and add_assoc.\n    end),\n  add_assoc    := \u03bb abar bbar cbar,quotient.induction_on\u2083 abar bbar cbar (\u03bb a b c,\n    begin\n      -- goal now \u27e6a\u27e7 + \u27e6b\u27e7 + \u27e6c\u27e7 = \u27e6a\u27e7 + (\u27e6b\u27e7 + \u27e6c\u27e7)\n      apply quotient.sound,\n      -- goal now a + b + c \u2248 a + (b + c)\n      rw add_assoc, -- done :-) because after a rw a goal is closed if it's of the form x \u2248 x, as \u2248 is\n                    -- known to be reflexive.\n    end),\n  add_zero     := -- I will introduce some more sneaky stuff now now\n                  -- add_zero for Zmod37 follows from add_zero on Z.\n                  -- Note use of $ instead of the brackets\n    \u03bb abar, quotient.induction_on abar $ \u03bb a, quotient.sound $ by rw add_zero,\n                  -- that's it! Term mode proof.\n  add_left_neg := -- super-slow method not even using quotient.induction_on \n    begin\n      intro abar,\n      cases (quot.exists_rep abar) with a Ha,\n      rw [\u2190Ha],\n      apply quot.sound,\n      existsi (0:\u2124),\n      simp,\n    end,\n  -- but really all proofs should just look something like this\n  add_comm     := \u03bb abar bbar, quotient.induction_on\u2082 abar bbar $ \u03bb _ _,quotient.sound $ by rw add_comm,\n  -- the noise at the beginning is just the machine; all the work is done by the rewrite\n}\n\n-- Now let's just nail this using all the tricks in the book. All ring axioms on the quotient\n-- follow from the corresponding axioms for Z.\ninstance : comm_ring (Zmod37) :=\n{ \n  mul := (*), \n  -- Now look how the proof of mul_assoc is just the same structure as add_comm above\n  -- but with three variables not two\n  mul_assoc := \u03bb a b c, quotient.induction_on\u2083 a b c $ \u03bb _ _ _, quotient.sound $ by rw mul_assoc,\n  one := 1,\n  one_mul := \u03bb a, quotient.induction_on a $ \u03bb _, quotient.sound $ by rw one_mul,\n  -- can you finish the job?\n  mul_one := sorry,\n  left_distrib := sorry,\n  right_distrib := sorry,\n  mul_comm := sorry,\n  ..Zmod37.add_comm_group\n}\n\nend Zmod37\n", "meta": {"author": "ImperialCollegeLondon", "repo": "Example-Lean-Projects", "sha": "87b27ba616eaf03f3642000829a481a1932dd08e", "save_path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects", "path": "github-repos/lean/ImperialCollegeLondon-Example-Lean-Projects/Example-Lean-Projects-87b27ba616eaf03f3642000829a481a1932dd08e/src/int/ZmodN.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7118986202625717}}
{"text": "/-\nCopyright (c) 2014 Robert Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Lewis, Leonardo de Moura, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport algebra.ring.basic\nimport algebra.group_with_zero\n\n/-!\n# Fields and division rings\n\nThis file introduces fields and division rings (also known as skewfields) and proves some basic\nstatements about them. For a more extensive theory of fields, see the `field_theory` folder.\n\n## Main definitions\n\n* `division_ring`: introduces the notion of a division ring as a `ring` such that `0 \u2260 1` and\n  `a * a\u207b\u00b9 = 1` for `a \u2260 0`\n* `field`: a division ring which is also a commutative ring.\n* `is_field`: a predicate on a ring that it is a field, i.e. that the multiplication is commutative,\n  that it has more than one element and that all non-zero elements have a multiplicative inverse.\n  In contrast to `field`, which contains the data of a function associating to an element of the\n  field its multiplicative inverse, this predicate only assumes the existence and can therefore more\n  easily be used to e.g. transfer along ring isomorphisms.\n\n## Implementation details\n\nBy convention `0\u207b\u00b9 = 0` in a field or division ring. This is due to the fact that working with total\nfunctions has the advantage of not constantly having to check that `x \u2260 0` when writing `x\u207b\u00b9`. With\nthis convention in place, some statements like `(a + b) * c\u207b\u00b9 = a * c\u207b\u00b9 + b * c\u207b\u00b9` still remain\ntrue, while others like the defining property `a * a\u207b\u00b9 = 1` need the assumption `a \u2260 0`. If you are\na beginner in using Lean and are confused by that, you can read more about why this convention is\ntaken in Kevin Buzzard's\n[blogpost](https://xenaproject.wordpress.com/2020/07/05/division-by-zero-in-type-theory-a-faq/)\n\nA division ring or field is an example of a `group_with_zero`. If you cannot find\na division ring / field lemma that does not involve `+`, you can try looking for\na `group_with_zero` lemma instead.\n\n## Tags\n\nfield, division ring, skew field, skew-field, skewfield\n-/\n\nopen set\n\nset_option old_structure_cmd true\n\nuniverse u\nvariables {K : Type u}\n\n/-- A `division_ring` is a `ring` with multiplicative inverses for nonzero elements -/\n@[protect_proj, ancestor ring div_inv_monoid nontrivial]\nclass division_ring (K : Type u) extends ring K, div_inv_monoid K, nontrivial K :=\n(mul_inv_cancel : \u2200 {a : K}, a \u2260 0 \u2192 a * a\u207b\u00b9 = 1)\n(inv_zero : (0 : K)\u207b\u00b9 = 0)\n\nsection division_ring\nvariables [division_ring K] {a b : K}\n\n/-- Every division ring is a `group_with_zero`. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance division_ring.to_group_with_zero :\n  group_with_zero K :=\n{ .. \u2039division_ring K\u203a,\n  .. (infer_instance : semiring K) }\n\nlemma inverse_eq_has_inv : (ring.inverse : K \u2192 K) = has_inv.inv :=\nbegin\n  ext x,\n  by_cases hx : x = 0,\n  { simp [hx] },\n  { exact ring.inverse_unit (units.mk0 x hx) }\nend\n\nattribute [field_simps] inv_eq_one_div\n\nlocal attribute [simp]\n  division_def mul_comm mul_assoc\n  mul_left_comm mul_inv_cancel inv_mul_cancel\n\nlemma one_div_neg_one_eq_neg_one : (1:K) / (-1) = -1 :=\nhave (-1) * (-1) = (1:K), by rw [neg_mul_neg, one_mul],\neq.symm (eq_one_div_of_mul_eq_one this)\n\nlemma one_div_neg_eq_neg_one_div (a : K) : 1 / (- a) = - (1 / a) :=\ncalc\n  1 / (- a) = 1 / ((-1) * a)        : by rw neg_eq_neg_one_mul\n        ... = (1 / a) * (1 / (- 1)) : by rw one_div_mul_one_div_rev\n        ... = (1 / a) * (-1)        : by rw one_div_neg_one_eq_neg_one\n        ... = - (1 / a)             : by rw [mul_neg_eq_neg_mul_symm, mul_one]\n\nlemma div_neg_eq_neg_div (a b : K) : b / (- a) = - (b / a) :=\ncalc\n  b / (- a) = b * (1 / (- a)) : by rw [\u2190 inv_eq_one_div, division_def]\n        ... = b * -(1 / a)    : by rw one_div_neg_eq_neg_one_div\n        ... = -(b * (1 / a))  : by rw neg_mul_eq_mul_neg\n        ... = - (b / a)       : by rw mul_one_div\n\nlemma neg_div (a b : K) : (-b) / a = - (b / a) :=\nby rw [neg_eq_neg_one_mul, mul_div_assoc, \u2190 neg_eq_neg_one_mul]\n\n@[field_simps] lemma neg_div' {K : Type*} [division_ring K] (a b : K) : - (b / a) = (-b) / a :=\nby simp [neg_div]\n\nlemma neg_div_neg_eq (a b : K) : (-a) / (-b) = a / b :=\nby rw [div_neg_eq_neg_div, neg_div, neg_neg]\n\n@[field_simps] lemma div_add_div_same (a b c : K) : a / c + b / c = (a + b) / c :=\nby simpa only [div_eq_mul_inv] using (right_distrib a b (c\u207b\u00b9)).symm\n\nlemma same_add_div {a b : K} (h : b \u2260 0) : (b + a) / b = 1 + a / b :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_add_div_same b a b).symm\n\nlemma one_add_div {a b : K} (h : b \u2260 0 ) : 1 + a / b = (b + a) / b := (same_add_div h).symm\n\nlemma div_add_same {a b : K} (h : b \u2260 0) : (a + b) / b = a / b + 1 :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_add_div_same a b b).symm\n\nlemma div_add_one {a b : K} (h : b \u2260 0) : a / b + 1 = (a + b) / b := (div_add_same h).symm\n\nlemma div_sub_div_same (a b c : K) : (a / c) - (b / c) = (a - b) / c :=\nby rw [sub_eq_add_neg, \u2190 neg_div, div_add_div_same, sub_eq_add_neg]\n\nlemma same_sub_div {a b : K} (h : b \u2260 0) : (b - a) / b = 1 - a / b :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_sub_div_same b a b).symm\n\nlemma one_sub_div {a b : K} (h : b \u2260 0) : 1 - a / b = (b - a) / b := (same_sub_div h).symm\n\nlemma div_sub_same {a b : K} (h : b \u2260 0) : (a - b) / b = a / b - 1 :=\nby simpa only [\u2190 @div_self _ _ b h] using (div_sub_div_same a b b).symm\n\nlemma div_sub_one {a b : K} (h : b \u2260 0) : a / b - 1 = (a - b) / b := (div_sub_same h).symm\n\nlemma neg_inv : - a\u207b\u00b9 = (- a)\u207b\u00b9 :=\nby rw [inv_eq_one_div, inv_eq_one_div, div_neg_eq_neg_div]\n\nlemma add_div (a b c : K) : (a + b) / c = a / c + b / c :=\n(div_add_div_same _ _ _).symm\n\nlemma sub_div (a b c : K) : (a - b) / c = a / c - b / c :=\n(div_sub_div_same _ _ _).symm\n\nlemma div_neg (a : K) : a / -b = -(a / b) :=\nby rw [\u2190 div_neg_eq_neg_div]\n\nlemma inv_neg : (-a)\u207b\u00b9 = -(a\u207b\u00b9) :=\nby rw neg_inv\n\nlemma one_div_mul_add_mul_one_div_eq_one_div_add_one_div (ha : a \u2260 0) (hb : b \u2260 0) :\n          (1 / a) * (a + b) * (1 / b) = 1 / a + 1 / b :=\nby rw [(left_distrib (1 / a)), (one_div_mul_cancel ha), right_distrib, one_mul,\n       mul_assoc, (mul_one_div_cancel hb), mul_one, add_comm]\n\nlemma one_div_mul_sub_mul_one_div_eq_one_div_add_one_div (ha : a \u2260 0) (hb : b \u2260 0) :\n          (1 / a) * (b - a) * (1 / b) = 1 / a - 1 / b :=\nby rw [(mul_sub_left_distrib (1 / a)), (one_div_mul_cancel ha), mul_sub_right_distrib,\n       one_mul, mul_assoc, (mul_one_div_cancel hb), mul_one]\n\nlemma add_div_eq_mul_add_div (a b : K) {c : K} (hc : c \u2260 0) : a + b / c = (a * c + b) / c :=\n(eq_div_iff_mul_eq hc).2 $ by rw [right_distrib, (div_mul_cancel _ hc)]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance division_ring.to_domain : domain K :=\n{ ..\u2039division_ring K\u203a, ..(by apply_instance : semiring K),\n  ..(by apply_instance : no_zero_divisors K) }\n\nend division_ring\n\n/-- A `field` is a `comm_ring` with multiplicative inverses for nonzero elements -/\n@[protect_proj, ancestor comm_ring div_inv_monoid nontrivial]\nclass field (K : Type u) extends comm_ring K, div_inv_monoid K, nontrivial K :=\n(mul_inv_cancel : \u2200 {a : K}, a \u2260 0 \u2192 a * a\u207b\u00b9 = 1)\n(inv_zero : (0 : K)\u207b\u00b9 = 0)\n\nsection field\n\nvariable [field K]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance field.to_division_ring : division_ring K :=\n{ ..show field K, by apply_instance }\n\n/-- Every field is a `comm_group_with_zero`. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance field.to_comm_group_with_zero :\n  comm_group_with_zero K :=\n{ .. (_ : group_with_zero K), .. \u2039field K\u203a }\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\nlemma div_add_div (a : K) {b : K} (c : K) {d : K} (hb : b \u2260 0) (hd : d \u2260 0) :\n      (a / b) + (c / d) = ((a * d) + (b * c)) / (b * d) :=\nby rw [\u2190 mul_div_mul_right _ b hd, \u2190 mul_div_mul_left c d hb, div_add_div_same]\n\nlemma one_div_add_one_div {a b : K} (ha : a \u2260 0) (hb : b \u2260 0) : 1 / a + 1 / b = (a + b) / (a * b) :=\nby rw [div_add_div _ _ ha hb, one_mul, mul_one, add_comm]\n\n@[field_simps] lemma div_sub_div (a : K) {b : K} (c : K) {d : K} (hb : b \u2260 0) (hd : d \u2260 0) :\n  (a / b) - (c / d) = ((a * d) - (b * c)) / (b * d) :=\nbegin\n  simp only [sub_eq_add_neg],\n  rw [neg_eq_neg_one_mul, \u2190 mul_div_assoc, div_add_div _ _ hb hd,\n      \u2190 mul_assoc, mul_comm b, mul_assoc, \u2190 neg_eq_neg_one_mul]\nend\n\nlemma inv_add_inv {a b : K} (ha : a \u2260 0) (hb : b \u2260 0) : a\u207b\u00b9 + b\u207b\u00b9 = (a + b) / (a * b) :=\nby rw [inv_eq_one_div, inv_eq_one_div, one_div_add_one_div ha hb]\n\nlemma inv_sub_inv {a b : K} (ha : a \u2260 0) (hb : b \u2260 0) : a\u207b\u00b9 - b\u207b\u00b9 = (b - a) / (a * b) :=\nby rw [inv_eq_one_div, inv_eq_one_div, div_sub_div _ _ ha hb, one_mul, mul_one]\n\n@[field_simps] lemma add_div' (a b c : K) (hc : c \u2260 0) : b + a / c = (b * c + a) / c :=\nby simpa using div_add_div b a one_ne_zero hc\n\n@[field_simps] lemma sub_div' (a b c : K) (hc : c \u2260 0) : b - a / c = (b * c - a) / c :=\nby simpa using div_sub_div b a one_ne_zero hc\n\n@[field_simps] lemma div_add' (a b c : K) (hc : c \u2260 0) : a / c + b = (a + b * c) / c :=\nby rwa [add_comm, add_div', add_comm]\n\n@[field_simps] lemma div_sub' (a b c : K) (hc : c \u2260 0) : a / c - b = (a - c * b) / c :=\nby simpa using div_sub_div a b hc one_ne_zero\n\n@[priority 100] -- see Note [lower instance priority]\ninstance field.to_integral_domain : integral_domain K :=\n{ ..\u2039field K\u203a, ..division_ring.to_domain }\n\nend field\n\nsection is_field\n\n/-- A predicate to express that a ring is a field.\n\nThis is mainly useful because such a predicate does not contain data,\nand can therefore be easily transported along ring isomorphisms.\nAdditionaly, this is useful when trying to prove that\na particular ring structure extends to a field. -/\nstructure is_field (R : Type u) [ring R] : Prop :=\n(exists_pair_ne : \u2203 (x y : R), x \u2260 y)\n(mul_comm : \u2200 (x y : R), x * y = y * x)\n(mul_inv_cancel : \u2200 {a : R}, a \u2260 0 \u2192 \u2203 b, a * b = 1)\n\n/-- Transferring from field to is_field -/\nlemma field.to_is_field (R : Type u) [field R] : is_field R :=\n{ mul_inv_cancel := \u03bb a ha, \u27e8a\u207b\u00b9, field.mul_inv_cancel ha\u27e9,\n  ..\u2039field R\u203a }\n\nopen_locale classical\n\n/-- Transferring from is_field to field -/\nnoncomputable def is_field.to_field (R : Type u) [ring R] (h : is_field R) : field R :=\n{ inv := \u03bb a, if ha : a = 0 then 0 else classical.some (is_field.mul_inv_cancel h ha),\n  inv_zero := dif_pos rfl,\n  mul_inv_cancel := \u03bb a ha,\n    begin\n      convert classical.some_spec (is_field.mul_inv_cancel h ha),\n      exact dif_neg ha\n    end,\n  .. \u2039ring R\u203a, ..h }\n\n/-- For each field, and for each nonzero element of said field, there is a unique inverse.\nSince `is_field` doesn't remember the data of an `inv` function and as such,\na lemma that there is a unique inverse could be useful.\n-/\nlemma uniq_inv_of_is_field (R : Type u) [ring R] (hf : is_field R) :\n  \u2200 (x : R), x \u2260 0 \u2192 \u2203! (y : R), x * y = 1 :=\nbegin\n  intros x hx,\n  apply exists_unique_of_exists_of_unique,\n  { exact hf.mul_inv_cancel hx },\n  { intros y z hxy hxz,\n    calc y = y * (x * z) : by rw [hxz, mul_one]\n       ... = (x * y) * z : by rw [\u2190 mul_assoc, hf.mul_comm y x]\n       ... = z           : by rw [hxy, one_mul] }\nend\n\nend is_field\n\nnamespace ring_hom\n\nsection\n\nvariables {R : Type*} [semiring R] [division_ring K] (f : R \u2192+* K)\n\n@[simp] lemma map_units_inv (u : units R) :\n  f \u2191u\u207b\u00b9 = (f \u2191u)\u207b\u00b9 :=\n(f : R \u2192* K).map_units_inv u\n\nend\n\nsection\n\nvariables {R K' : Type*} [division_ring K] [semiring R] [nontrivial R] [division_ring K']\n  (f : K \u2192+* R) (g : K \u2192+* K') {x y : K}\n\nlemma map_ne_zero : f x \u2260 0 \u2194 x \u2260 0 := f.to_monoid_with_zero_hom.map_ne_zero\n\n@[simp] lemma map_eq_zero : f x = 0 \u2194 x = 0 := f.to_monoid_with_zero_hom.map_eq_zero\n\nvariables (x y)\n\nlemma map_inv : g x\u207b\u00b9 = (g x)\u207b\u00b9 := g.to_monoid_with_zero_hom.map_inv' x\n\nlemma map_div : g (x / y) = g x / g y := g.to_monoid_with_zero_hom.map_div x y\n\nprotected lemma injective : function.injective f := f.injective_iff.2 $ \u03bb x, f.map_eq_zero.1\n\nend\n\nend ring_hom\n\nsection noncomputable_defs\n\nvariables {R : Type*} [nontrivial R]\n\n/-- Constructs a `division_ring` structure on a `ring` consisting only of units and 0. -/\nnoncomputable def division_ring_of_is_unit_or_eq_zero [hR : ring R]\n  (h : \u2200 (a : R), is_unit a \u2228 a = 0) : division_ring R :=\n{ .. (group_with_zero_of_is_unit_or_eq_zero h), .. hR }\n\n/-- Constructs a `field` structure on a `comm_ring` consisting only of units and 0. -/\nnoncomputable def field_of_is_unit_or_eq_zero [hR : comm_ring R]\n  (h : \u2200 (a : R), is_unit a \u2228 a = 0) : field R :=\n{ .. (group_with_zero_of_is_unit_or_eq_zero h), .. hR }\n\nend noncomputable_defs\n\n/-- Pullback a `division_ring` along an injective function. -/\nprotected def function.injective.division_ring [division_ring K] {K'}\n  [has_zero K'] [has_mul K'] [has_add K'] [has_neg K'] [has_sub K'] [has_one K'] [has_inv K']\n  [has_div K']\n  (f : K' \u2192 K) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9) (div : \u2200 x y, f (x / y) = f x / f y) :\n  division_ring K' :=\n{ .. hf.group_with_zero f zero one mul inv div,\n  .. hf.ring f zero one add mul neg sub }\n\n/-- Pullback a `field` along an injective function. -/\nprotected def function.injective.field [field K] {K'}\n  [has_zero K'] [has_mul K'] [has_add K'] [has_neg K'] [has_sub K'] [has_one K'] [has_inv K']\n  [has_div K']\n  (f : K' \u2192 K) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9) (div : \u2200 x y, f (x / y) = f x / f y) :\n  field K' :=\n{ .. hf.comm_group_with_zero f zero one mul inv div,\n  .. hf.comm_ring f zero one add mul neg sub }\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7118986202280665}}
{"text": "import probability.martingale.basic\n\nopen filter\nopen_locale nnreal ennreal measure_theory probability_theory big_operators topological_space\n\nnamespace measure_theory\n\n/-!\n\n# Probability theory \n\nNow that we know the basics of measure theory in Lean, let us talk about \nmeasure theoretic probability theory. While probability theory is a large area \nin mathematics, mathlib itself does not contain much of it at the moment. In \nthis section I will introduce some notions fundamental to probability theory. \n\n-/\n\n/-!\n## The set-up\n\nIf you have read any literature on probability, you've probably seen the phrase: \n\"let `(\u03a9, \u2131, \u2119)` be a probability space\". A probability space is simply a \nmeasure space with the additional assumption that `\u2119(\u03a9) = 1`. In Lean, one can \ndeclare this by simply declaring a measure space, i.e. \n-/\nvariables {\u03a9 : Type*} {m0 : measurable_space \u03a9} {\u03bc : measure \u03a9}\n\n/-\nand require that `\u03bc` is a probability measure with the instance \n```\n  [is_probability_measure \u03bc]\n```\nWhile, this is the setting most literature in probability will go with, this is \nin fact unnecessarily restrictive. Indeed, most theorems in probability theory \nremains to hold provided that `\u03bc` is a finite measure (although sometimes that \nis not even necessary). As a result, we will add the required assumptions on the \nmeasure when needed. \n-/\n\n/-!\n## Random variables & Lp functions\n\nRandom variables are measurable functions and in most cases, are real valued.\nNamely, to declare a (real valued)-random variable in Lean, simply declare a \nfunction `X : \u03a9 \u2192 \u211d` and the hypothesis `measurable X`. From this point onwards \nI will use functions and random variables interchangably.\n\n*Remark* Since a random variable is simply a function, I will denote random \nvariables with the same notations as I use for functions, i.e. `f, g, h...`.\nThis notation is (mostly) consistent with what is used in mathlib and so I would \nprefer if you use it as well.\n\nMathematically, this is as simple as it gets however, as usual, its more \ncomplicated in practice. \n\nIn probability theory, you commonly have hypothesis such as: \"let `X` be a \nrandom variable with finite `p`-th moment\". Mathematically, this is saying \n`\ud835\udd3c[|X|^p] = \u222b \u03c9, |X \u03c9|^p d\u2119 < \u221e`. In measure theory, this notion is known \nas `\u2112p` (see section 6.2 of https://www.xuemei.org/Measure-Integration.pdf). \n\n`\u2112p` functions form a Banch space with the norm `\u2225\u2b1d\u2225\u209a` where we define \n`\u2225f\u2225\u209a = (\u222b x, |f x|^p \u2202\u03bc)^(1 / p)`. In the case that `p = 2`, the space is \nactually a Hilbert space with the inner product `\u27e8f, g\u27e9 := \u222b x, (f x) (g x) \u2202\u03bc`.\nWe say a sequence of functions converges in `Lp` if it converges with respect \nto the above norm.\n\nI've told a small lie in the above explaination. Actually, by noting that a \nfunction which is a.e. zero will have norm 0 contradicting the definition of a \nnorm. So, to actually get the Banach space we need to quotient by the equivalence \nrelation `~` where `f ~ g` if and only if `f =\u1d50[\u03bc] g`. This quotient space is \nis known as `Lp`. However, by axiom of choice, we can always chose a \nrepresentation for each class so we can imagine them as functions and commonly \nto interchange the two notions.\n\nIn Lean however, we will stick to the function intepretation and only falling \nback to the quotient when absolutely necessary. Nonetheless, due to the above \nconstruction, when mathematically defining properties for the `Lp` space \n(the quotient `\u2112p / ~`), we should make definitions which transfers over a.e. \nequality. Namely, if we want to define a predicate `P : \u2112p \u2192 Prop`, we should \nmake sure the following diagram holds:\n\n```\n\u2112p -{P}-> Prop \n |       /\n{q}    / \n |   /\nLp\n```\nwhere `q` is the quotient map.\n\n**Here's the conclusion**: As `measurable` does not satisfy the above diagram, \nit is not a good requirment to assume due to the reasons outlined above. \nInstead, we shall work with `ae_measurable` functions in whenever possible.\n\nI will now interchangably use `Lp` and `\u2112p`\n\nLean vocabulary:\n- A function `f` is Lp: `mem_\u2112p f p \u03bc`\n- the Lp norm of `f`: `snorm f p \u03bc`\n-/\n\nvariables {f : \u03a9 \u2192 \u211d}\n\n-- See Markov inequality\nexample (hf : ae_measurable f \u03bc) (\u03b5 : \u211d\u22650\u221e) :\n  \u03b5 * \u03bc {x | \u03b5 \u2264 \u2225f x\u2225\u208a} \u2264 snorm f 1 \u03bc :=\nbegin\n  sorry\nend\n\n-- If `(f\u2099)` converges in L\u221e then it converges almost everywhere. \n-- The L\u221e norm of a function `f` is defined as the essential supremum of `|f|`, i.e.\n-- `\u2225f\u2225\u221e = inf {R : \u211d | \u03bc {f \u2264 R}\u1d9c = 0}`, i.e. \n-- the least element for which bounds `f` a.e.\nexample (f : \u2115 \u2192 \u03a9 \u2192 \u211d) (f' : \u03a9 \u2192 \u211d) \n  (hf : \u2200 n, ae_measurable (f n) \u03bc) (hf' : ae_measurable f' \u03bc)\n  (hf : tendsto (\u03bb n, snorm (f n - f') \u221e \u03bc) at_top (\ud835\udcdd 0)) :\n  \u2200\u1d50 \u03c9 \u2202\u03bc, tendsto (\u03bb n, f n \u03c9) at_top (\ud835\udcdd (f' \u03c9)) :=\nbegin\n  sorry\nend\n\n/-!\n## Convergence in measure/probability\n\nSo far we have seen two types of convergence: convergence a.e. and convergence \nin Lp. There is one more type of convergence which we care about in probability \ntheory (actually there is one more but we shall not touch on it) known as \nconvergence in measure. (or convergence in probability though we will stick \nwith the first nomenclature). \n\nThe sequence of function `(f\u2099)` is said to converge in measure to some function \n`g` if for all `\u03b5 > 0`, `lim_{n \u2192 \u221e} \u03bc {|f\u2099 - f| > \u03b5} = 0`. In Lean, this notion \nis defined as `tendsto_in_measure` although there is an extra parameter of type \n`filter`. To recover the mathematical defintion simply take this parameter to be \nthe `at_top` filter.\n\nConvergence in measure is the notion of convergence described by the weak law of \nlarge numbers. \n\nConvergence in measure is strictly weaker than convergence a.e. and in Lp. This \nis formalized in Lean with `tendsto_in_measure_of_tendsto_ae` and \n`tendsto_in_measure_of_tendsto_snorm`. On the other and, convergence in measure \npartially implies convergence a.e. In particular, a sequence of function \nconverges in measure implies it has a subsequence which conveges a.e. This is \nformalized as `tendsto_in_measure.exists_seq_tendsto_ae`.\n-/\n\nexample (f : \u2115 \u2192 \u03a9 \u2192 \u211d) (f' : \u03a9 \u2192 \u211d) \n  (hf : \u2200 n, ae_measurable (f n) \u03bc) (hf' : ae_measurable f' \u03bc)\n  (hft : tendsto (\u03bb n, snorm (f n - f') 1 \u03bc) at_top (\ud835\udcdd 0)) : \n  \u2203 ns : \u2115 \u2192 \u2115, strict_mono ns \u2227 \n  \u2200\u1d50 \u03c9 \u2202\u03bc, tendsto (\u03bb n, f (ns n) \u03c9) at_top (\ud835\udcdd (f' \u03c9)) :=\nbegin\n  sorry\nend\n\n-- In the above exercise, if `hf'` necessary? I suspect not. Try to prove the \n-- following lemma (I don't this this is in mathlib!)\n\n-- *Hint*: try proving it on paper first\n-- *Maths hint*: Fatou's lemma\nexample (f : \u2115 \u2192 \u03a9 \u2192 \u211d) (f' : \u03a9 \u2192 \u211d) (hf : \u2200 n, measurable (f n)) \n  (hft : tendsto (\u03bb n, snorm (f n - f') 1 \u03bc) at_top (\ud835\udcdd 0)) : \n  ae_measurable f' \u03bc :=\nbegin\n  sorry\nend\n\n-- Now, give the above example a name and use it to prove the following\nexample (f : \u2115 \u2192 \u03a9 \u2192 \u211d) (f' : \u03a9 \u2192 \u211d) (hf : \u2200 n, ae_measurable (f n) \u03bc) \n  (hft : tendsto (\u03bb n, snorm (f n - f') 1 \u03bc) at_top (\ud835\udcdd 0)) : \n  ae_measurable f' \u03bc :=\nbegin\n  sorry\nend\n\n-- Bonus: try to generalize the above for convergence in Lp rather than just \n-- convergence in L1.\n\n/-!\n## Conditional expectation\n\nConditional expectation is an important definition in probability theory. While \nyou might have seen a version of conditional expecation in elementary probability \ntheory where one conditions on an event, we shall work with a much more general \ndefinition in which we condition on a \u03c3-algebra. \n\nThe formal definition of the condition expectation is the following: \nLet `(\u03a9, \u2131, \u03bc)` be a measure space and suppose `f` is a measurable function \nand `\ud835\udca2` is a sub-\u03c3-algebra (i.e. `\ud835\udca2` is also a \u03c3-algebra and all `\ud835\udca2`-measurable \nsets are also `\u2131`-measurable), then a `\ud835\udca2`-measurable function `g` is said to \nbe a conditional expectation of `f` if for all `\ud835\udca2`-measurable sets `s : set \u03a9`, \n`\u222b \u03c9 in s, f \u03c9 \u2202\u03bc = \u222b \u03c9 in s, g \u03c9 \u2202\u03bc`. \n\nOne can prove that there always exists a conditional expectation and it is \nunique up to almost everywhere equality however this is not trivial to prove. \n\nPersonally, I think about the conditional expectation in two ways. \n- Geometrically: recall that the space `L\u00b2(\u2131, \u03bc)` forms a Hilbert space, \n  and furthermore, should we restrict the space onto the sub-\u03c3-algebra, the \n  resulting space `L\u00b2(\ud835\udca2, \u03bc)` is a closed vector-subspace of `L\u00b2(\u2131, \u03bc)`. Thus, \n  the orthogonal projection `P : L\u00b2(\u2131, \u03bc) \u2192 L\u00b2(\ud835\udca2, \u03bc)` is a well defined \n  operator. This orthogonal projection `P` is precisely the conditional \n  expecation. \n  \n  Not only does this method provides a mental image for what the conditiona \n  expecation is doing, we also obtain the existence and uniqueness for free \n  for `L\u00b2` functions. However, the conditional expecations is also defined for \n  `L\u00b9` functions. To obtain the general definition, one exploit the density of \n  `L\u00b2` functions in `L\u00b9` to define the conditional expecation in `L\u00b9` as a\n  limit of the conditional expecation in `L\u00b2`. \n\n- Probabilistically: the \u03c3-algebra in probability theory is often interpreted \n  as information as we shall see in the defintion of filtrations. Thus, \n  conditioning on \u03c3-algebras is a natural thing to do probabilitically where \n  we would like to update our random variable providing some information.\n  (Recall the \u03c3-algebra is often refereed as the event space as it is suppose \n  to contain all possible events. One way to think about sub-\u03c3-algebras as \n  additional information is that we have restricted the number of possible \n  events, i.e. ruling them out given the information.)\n  \n  The updated random variable should certainly be measurably with respect to \n  the new sub-\u03c3-algebra `\ud835\udca2` while it should behave as before on `\ud835\udca2`. \n  To demonstrate the second point we test it on all possible `\ud835\udca2`-measurable sets \n  resulting in the definition of the conditional expecation. This is sensible \n  since, if `\ud835\udc9c` is a \u03c3-algebra and `f` and `g` are `\ud835\udc9c`-measurable, \n  `f = g` a.e. if `\u222b \u03c9 in s, f \u03c9 \u2202\u03bc = \u222b \u03c9 in s, g \u03c9 \u2202\u03bc` for all `\ud835\udc9c`-measurable \n  sets `s` (try proving this in Lean).\n\nIn Lean, the conditional expecation is known as `condexp` and is defined via. \nthe projection process outlined above and we introduce the notation `\u03bc[f | \ud835\udca2]` \nfor the conditional expecation of the function `f` with respect to the \u03c3-algebra \n`\ud835\udca2` (in literature you might see `\ud835\udd3c[f | \ud835\udca2]`). It will be useful if you can \nfamiliarize yourself with the basic properties of conditional expectation \n(Thm. 33 of https://github.com/JasonKYi/y3_notes/blob/main/Probability_Theory/Probability_Theory.pdf\nis what you need in most cases though section 9 of https://www.xuemei.org/Measure-Integration.pdf\ncontains a lot more about conditional expectation).\n\nPS. should you read about the martingale convergence theorems, you will see that \na lot of the conditional limit theorems are corollaries of the martingale \nconvergence theorems.\n-/\n\nexample (f : \u03a9 \u2192 \u211d) {\u2131 \ud835\udca2 : measurable_space \u03a9} \n  (h\ud835\udca2 : \ud835\udca2 \u2264 m0) (h\u2131 : \u2131 \u2264 \ud835\udca2) [sigma_finite (\u03bc.trim h\ud835\udca2)] : \n  \u03bc[\u03bc[f | \u2131] | \ud835\udca2] = \u03bc[f | \u2131] :=\nbegin\n  sorry\nend\n\n/-\nLet's now try to do a hard problem. The following question is part 3 of the second \nquestion from the 2014 Part III advanced probability exam. Do assume basic \nproperties about the conditional expectation and add sorry-ed lemmas when needed \nif they don't exists in mathlib (e.g. (not that you necessarily need it) \nthe conditional Jensen's inequality).\n\nHere's a couple of *Lean hints* (there is maths hints below the question if you \nare stuck on the maths):\n- as ususal, do it on paper first \n- after you've done it on paper, think about what steps probably already exists \n  as lemmas in mathlib (and find them)\n- instead of working directly with functions, would it be easier to work with \n  elements with the `Lp` type instead \n-/\nexample {\ud835\udca2 : measurable_space \u03a9} (h\ud835\udca2 : \ud835\udca2 \u2264 m0) (f g : \u03a9 \u2192 \u211d) \n  (hf : mem_\u2112p f 2 \u03bc) (hg : mem_\u2112p g 2 \u03bc) \n  (hfg\u2081 : \u03bc[g | \ud835\udca2] =\u1d50[\u03bc] f) (hfg\u2082 : snorm f 2 \u03bc = snorm g 2 \u03bc) :\n  f =\u1d50[\u03bc] g :=\nbegin\n  sorry\nend\n\n/-\n*Maths hints*: \n- an orthogonal projection is self-adjoint\n- when does the Cauchy-Schwartz inequality achieves equality\n-/\n\n-- Give the above lemma a name and use it to prove the following\nexample {\ud835\udca2 : measurable_space \u03a9} (h\ud835\udca2 : \ud835\udca2 \u2264 m0) (f : \u03a9 \u2192 \u211d) \n  (hf : mem_\u2112p f 2 \u03bc) (hf' : snorm f 2 \u03bc = snorm (\u03bc [f | \ud835\udca2]) 2 \u03bc) :\n  ae_strongly_measurable f (\u03bc.trim h\ud835\udca2) :=\nbegin \n  sorry\nend\n\nend measure_theory", "meta": {"author": "JasonKYi", "repo": "prob-workshop-sept", "sha": "0a18510d89fb56fbf652f253a052ac27befe9dfa", "save_path": "github-repos/lean/JasonKYi-prob-workshop-sept", "path": "github-repos/lean/JasonKYi-prob-workshop-sept/prob-workshop-sept-0a18510d89fb56fbf652f253a052ac27befe9dfa/src/prob_thy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7118961053458293}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Damiano Testa, Jens Wagemaker\n-/\nimport data.nat.interval\nimport data.polynomial.degree.definitions\n\n/-!\n# Induction on polynomials\n\nThis file contains lemmas dealing with different flavours of induction on polynomials.\n-/\n\nnoncomputable theory\nopen_locale classical big_operators polynomial\n\nopen finset\n\nnamespace polynomial\nuniverses u v w z\nvariables {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : \u2115}\n\nsection semiring\nvariables [semiring R] {p q : R[X]}\n\n/-- `div_X p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`.\n  It can be used in a semiring where the usual division algorithm is not possible -/\ndef div_X (p : R[X]) : R[X] :=\n\u2211 n in Ico 0 p.nat_degree, monomial n (p.coeff (n + 1))\n\n@[simp] lemma coeff_div_X : (div_X p).coeff n = p.coeff (n+1) :=\nbegin\n  simp only [div_X, coeff_monomial, true_and, finset_sum_coeff, not_lt,\n    mem_Ico, zero_le, finset.sum_ite_eq', ite_eq_left_iff],\n  intro h,\n  rw coeff_eq_zero_of_nat_degree_lt (nat.lt_succ_of_le h)\nend\n\nlemma div_X_mul_X_add (p : R[X]) : div_X p * X + C (p.coeff 0) = p :=\next $ by rintro \u27e8_|_\u27e9; simp [coeff_C, nat.succ_ne_zero, coeff_mul_X]\n\n@[simp] lemma div_X_C (a : R) : div_X (C a) = 0 :=\next $ \u03bb n, by cases n; simp [div_X, coeff_C]; simp [coeff]\n\nlemma div_X_eq_zero_iff : div_X p = 0 \u2194 p = C (p.coeff 0) :=\n\u27e8\u03bb h, by simpa [eq_comm, h] using div_X_mul_X_add p,\n  \u03bb h, by rw [h, div_X_C]\u27e9\n\nlemma div_X_add : div_X (p + q) = div_X p + div_X q :=\next $ by simp\n\nlemma degree_div_X_lt (hp0 : p \u2260 0) : (div_X p).degree < p.degree :=\nby haveI := nontrivial.of_polynomial_ne hp0;\ncalc (div_X p).degree < (div_X p * X + C (p.coeff 0)).degree :\n  if h : degree p \u2264 0\n  then begin\n      have h' : C (p.coeff 0) \u2260 0, by rwa [\u2190 eq_C_of_degree_le_zero h],\n      rw [eq_C_of_degree_le_zero h, div_X_C, degree_zero, zero_mul, zero_add],\n      exact lt_of_le_of_ne bot_le (ne.symm (mt degree_eq_bot.1 $\n        by simp [h'])),\n    end\n  else\n    have hXp0 : div_X p \u2260 0,\n      by simpa [div_X_eq_zero_iff, -not_le, degree_le_zero_iff] using h,\n    have leading_coeff (div_X p) * leading_coeff X \u2260 0, by simpa,\n    have degree (C (p.coeff 0)) < degree (div_X p * X),\n      from calc degree (C (p.coeff 0)) \u2264 0 : degree_C_le\n         ... < 1 : dec_trivial\n         ... = degree (X : R[X]) : degree_X.symm\n         ... \u2264 degree (div_X p * X) :\n          by rw [\u2190 zero_add (degree X), degree_mul' this];\n            exact add_le_add\n              (by rw [zero_le_degree_iff, ne.def, div_X_eq_zero_iff];\n                exact \u03bb h0, h (h0.symm \u25b8 degree_C_le))\n              le_rfl,\n    by rw [degree_add_eq_left_of_degree_lt this];\n      exact degree_lt_degree_mul_X hXp0\n... = p.degree : congr_arg _ (div_X_mul_X_add _)\n\n/-- An induction principle for polynomials, valued in Sort* instead of Prop. -/\n@[elab_as_eliminator] noncomputable def rec_on_horner\n  {M : R[X] \u2192 Sort*} : \u03a0 (p : R[X]),\n  M 0 \u2192\n  (\u03a0 p a, coeff p 0 = 0 \u2192 a \u2260 0 \u2192 M p \u2192 M (p + C a)) \u2192\n  (\u03a0 p, p \u2260 0 \u2192 M p \u2192 M (p * X)) \u2192\n  M p\n| p := \u03bb M0 MC MX,\nif hp : p = 0 then eq.rec_on hp.symm M0\nelse\nhave wf : degree (div_X p) < degree p,\n  from degree_div_X_lt hp,\nby rw [\u2190 div_X_mul_X_add p] at *;\n  exact\n  if hcp0 : coeff p 0 = 0\n  then by rw [hcp0, C_0, add_zero];\n    exact MX _ (\u03bb h : div_X p = 0, by simpa [h, hcp0] using hp)\n      (rec_on_horner _ M0 MC MX)\n  else MC _ _ (coeff_mul_X_zero _) hcp0 (if hpX0 : div_X p = 0\n    then show M (div_X p * X), by rw [hpX0, zero_mul]; exact M0\n    else MX (div_X p) hpX0 (rec_on_horner _ M0 MC MX))\nusing_well_founded {dec_tac := tactic.assumption}\n\n/--  A property holds for all polynomials of positive `degree` with coefficients in a semiring `R`\nif it holds for\n* `a * X`, with `a \u2208 R`,\n* `p * X`, with `p \u2208 R[X]`,\n* `p + a`, with `a \u2208 R`, `p \u2208 R[X]`,\nwith appropriate restrictions on each term.\n\nSee `nat_degree_ne_zero_induction_on` for a similar statement involving no explicit multiplication.\n -/\n@[elab_as_eliminator] lemma degree_pos_induction_on\n  {P : R[X] \u2192 Prop} (p : R[X]) (h0 : 0 < degree p)\n  (hC : \u2200 {a}, a \u2260 0 \u2192 P (C a * X))\n  (hX : \u2200 {p}, 0 < degree p \u2192 P p \u2192 P (p * X))\n  (hadd : \u2200 {p} {a}, 0 < degree p \u2192 P p \u2192 P (p + C a)) : P p :=\nrec_on_horner p\n  (\u03bb h, by rw degree_zero at h; exact absurd h dec_trivial)\n  (\u03bb p a _ _ ih h0,\n    have 0 < degree p,\n      from lt_of_not_ge (\u03bb h, (not_lt_of_ge degree_C_le) $\n        by rwa [eq_C_of_degree_le_zero h, \u2190 C_add] at h0),\n    hadd this (ih this))\n  (\u03bb p _ ih h0',\n    if h0 : 0 < degree p\n    then hX h0 (ih h0)\n    else by rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at *;\n      exact hC (\u03bb h : coeff p 0 = 0,\n        by simpa [h, nat.not_lt_zero] using h0'))\n  h0\n\n/--  A property holds for all polynomials of non-zero `nat_degree` with coefficients in a\nsemiring `R` if it holds for\n* `p + a`, with `a \u2208 R`, `p \u2208 R[X]`,\n* `p + q`, with `p, q \u2208 R[X]`,\n* monomials with nonzero coefficient and non-zero exponent,\nwith appropriate restrictions on each term.\nNote that multiplication is \"hidden\" in the assumption on monomials, so there is no explicit\nmultiplication in the statement.\nSee `degree_pos_induction_on` for a similar statement involving more explicit multiplications.\n -/\n@[elab_as_eliminator] lemma nat_degree_ne_zero_induction_on {M : R[X] \u2192 Prop}\n  {f : R[X]} (f0 : f.nat_degree \u2260 0) (h_C_add : \u2200 {a p}, M p \u2192 M (C a + p))\n  (h_add : \u2200 {p q}, M p \u2192 M q \u2192 M (p + q))\n  (h_monomial : \u2200 {n : \u2115} {a : R}, a \u2260 0 \u2192 n \u2260 0 \u2192 M (monomial n a)) :\n  M f :=\nsuffices f.nat_degree = 0 \u2228 M f, from or.dcases_on this (\u03bb h, (f0 h).elim) id,\nbegin\n  apply f.induction_on,\n  { exact \u03bb a, or.inl (nat_degree_C _) },\n  { rintros p q (hp | hp) (hq | hq),\n    { refine or.inl _,\n      rw [eq_C_of_nat_degree_eq_zero hp, eq_C_of_nat_degree_eq_zero hq, \u2190 C_add, nat_degree_C] },\n    { refine or.inr _,\n      rw [eq_C_of_nat_degree_eq_zero hp],\n      exact h_C_add hq },\n    { refine or.inr _,\n      rw [eq_C_of_nat_degree_eq_zero hq, add_comm],\n      exact h_C_add hp },\n    { exact or.inr (h_add hp hq) } },\n  { intros n a hi,\n    by_cases a0 : a = 0,\n    { exact or.inl (by rw [a0, C_0, zero_mul, nat_degree_zero]) },\n    { refine or.inr _,\n      rw C_mul_X_pow_eq_monomial,\n      exact h_monomial a0 n.succ_ne_zero } }\nend\n\nend semiring\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/polynomial/inductions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7118961009016875}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.calculus.local_extr\nimport analysis.calculus.implicit\n\n/-!\n# Lagrange multipliers\n\nIn this file we formalize the\n[Lagrange multipliers](https://en.wikipedia.org/wiki/Lagrange_multiplier) method of solving\nconditional extremum problems: if a function `\u03c6` has a local extremum at `x\u2080` on the set\n`f \u207b\u00b9' {f x\u2080}`, `f x = (f\u2080 x, ..., f\u2099\u208b\u2081 x)`, then the differentials of `f\u2096` and `\u03c6` are linearly\ndependent. First we formulate a geometric version of this theorem which does not rely on the\ntarget space being `\u211d\u207f`, then restate it in terms of coordinates.\n\n## TODO\n\nFormalize Karush-Kuhn-Tucker theorem\n\n## Tags\n\nlagrange multiplier, local extremum\n\n-/\n\nopen filter set\nopen_locale topological_space filter big_operators\nvariables {E F : Type*} [normed_group E] [normed_space \u211d E] [complete_space E]\n  [normed_group F] [normed_space \u211d F] [complete_space F]\n  {f : E \u2192 F} {\u03c6 : E \u2192 \u211d} {x\u2080 : E} {f' : E \u2192L[\u211d] F} {\u03c6' : E \u2192L[\u211d] \u211d}\n\n/-- Lagrange multipliers theorem: if `\u03c6 : E \u2192 \u211d` has a local extremum on the set `{x | f x = f x\u2080}`\nat `x\u2080`, both `f : E \u2192 F` and `\u03c6` are strictly differentiable at `x\u2080`, and the codomain of `f` is\na complete space, then the linear map `x \u21a6 (f' x, \u03c6' x)` is not surjective. -/\nlemma is_local_extr_on.range_ne_top_of_has_strict_fderiv_at\n  (hextr : is_local_extr_on \u03c6 {x | f x = f x\u2080} x\u2080) (hf' : has_strict_fderiv_at f f' x\u2080)\n  (h\u03c6' : has_strict_fderiv_at \u03c6 \u03c6' x\u2080) :\n  (f'.prod \u03c6').range \u2260 \u22a4 :=\nbegin\n  intro htop,\n  set f\u03c6 := \u03bb x, (f x, \u03c6 x),\n  have A : map \u03c6 (\ud835\udcdd[f \u207b\u00b9' {f x\u2080}] x\u2080) = \ud835\udcdd (\u03c6 x\u2080),\n  { change map (prod.snd \u2218 f\u03c6) (\ud835\udcdd[f\u03c6 \u207b\u00b9' {p | p.1 = f x\u2080}] x\u2080) = \ud835\udcdd (\u03c6 x\u2080),\n    rw [\u2190 map_map, nhds_within, map_inf_principal_preimage,\n      (hf'.prod h\u03c6').map_nhds_eq_of_surj htop],\n    exact map_snd_nhds_within _ },\n  exact hextr.not_nhds_le_map A.ge\nend\n\n/-- Lagrange multipliers theorem: if `\u03c6 : E \u2192 \u211d` has a local extremum on the set `{x | f x = f x\u2080}`\nat `x\u2080`, both `f : E \u2192 F` and `\u03c6` are strictly differentiable at `x\u2080`, and the codomain of `f` is\na complete space, then there exist `\u039b : dual \u211d F` and `\u039b\u2080 : \u211d` such that `(\u039b, \u039b\u2080) \u2260 0` and\n`\u039b (f' x) + \u039b\u2080 \u2022 \u03c6' x = 0` for all `x`. -/\nlemma is_local_extr_on.exists_linear_map_of_has_strict_fderiv_at\n  (hextr : is_local_extr_on \u03c6 {x | f x = f x\u2080} x\u2080) (hf' : has_strict_fderiv_at f f' x\u2080)\n  (h\u03c6' : has_strict_fderiv_at \u03c6 \u03c6' x\u2080) :\n  \u2203 (\u039b : module.dual \u211d F) (\u039b\u2080 : \u211d), (\u039b, \u039b\u2080) \u2260 0 \u2227 \u2200 x, \u039b (f' x) + \u039b\u2080 \u2022 \u03c6' x = 0 :=\nbegin\n  rcases submodule.exists_le_ker_of_lt_top _\n    (lt_top_iff_ne_top.2 $ hextr.range_ne_top_of_has_strict_fderiv_at hf' h\u03c6') with \u27e8\u039b', h0, h\u039b'\u27e9,\n  set e : ((F \u2192\u2097[\u211d] \u211d) \u00d7 \u211d) \u2243\u2097[\u211d] (F \u00d7 \u211d \u2192\u2097[\u211d] \u211d) :=\n    ((linear_equiv.refl \u211d (F \u2192\u2097[\u211d] \u211d)).prod (linear_map.ring_lmap_equiv_self \u211d \u211d \u211d).symm).trans\n      (linear_map.coprod_equiv \u211d),\n  rcases e.surjective \u039b' with \u27e8\u27e8\u039b, \u039b\u2080\u27e9, rfl\u27e9,\n  refine \u27e8\u039b, \u039b\u2080, e.map_ne_zero_iff.1 h0, \u03bb x, _\u27e9,\n  convert linear_map.congr_fun (linear_map.range_le_ker_iff.1 h\u039b') x using 1,\n  -- squeezed `simp [mul_comm]` to speed up elaboration\n  simp only [linear_map.coprod_equiv_apply, linear_equiv.refl_apply,\n    linear_map.ring_lmap_equiv_self_symm_apply, linear_map.comp_apply,\n    continuous_linear_map.coe_coe, continuous_linear_map.prod_apply,\n    linear_equiv.trans_apply, linear_equiv.prod_apply, linear_map.coprod_apply,\n    linear_map.smul_right_apply, linear_map.one_apply, smul_eq_mul, mul_comm]\nend\n\n/-- Lagrange multipliers theorem. Let `f : \u03b9 \u2192 E \u2192 \u211d` be a finite family of functions.\nSuppose that `\u03c6 : E \u2192 \u211d` has a local extremum on the set `{x | \u2200 i, f i x = f i x\u2080}` at `x\u2080`.\nSuppose that all functions `f i` as well as `\u03c6` are strictly differentiable at `x\u2080`.\nThen the derivatives `f' i : E \u2192 L[\u211d] \u211d` and `\u03c6' : E \u2192L[\u211d] \u211d` are linearly dependent:\nthere exist `\u039b : \u03b9 \u2192 \u211d` and `\u039b\u2080 : \u211d`, `(\u039b, \u039b\u2080) \u2260 0`, such that `\u2211 i, \u039b i \u2022 f' i + \u039b\u2080 \u2022 \u03c6' = 0`.\n\nSee also `is_local_extr_on.linear_dependent_of_has_strict_fderiv_at` for a version that\nstates `\u00aclinear_independent \u211d _` instead of existence of `\u039b` and `\u039b\u2080`. -/\nlemma is_local_extr_on.exists_multipliers_of_has_strict_fderiv_at {\u03b9 : Type*} [fintype \u03b9]\n  {f : \u03b9 \u2192 E \u2192 \u211d} {f' : \u03b9 \u2192 E \u2192L[\u211d] \u211d}\n  (hextr : is_local_extr_on \u03c6 {x | \u2200 i, f i x = f i x\u2080} x\u2080)\n  (hf' : \u2200 i, has_strict_fderiv_at (f i) (f' i) x\u2080)\n  (h\u03c6' : has_strict_fderiv_at \u03c6 \u03c6' x\u2080) :\n  \u2203 (\u039b : \u03b9 \u2192 \u211d) (\u039b\u2080 : \u211d), (\u039b, \u039b\u2080) \u2260 0 \u2227 \u2211 i, \u039b i \u2022 f' i + \u039b\u2080 \u2022 \u03c6' = 0 :=\nbegin\n  letI := classical.dec_eq \u03b9,\n  replace hextr : is_local_extr_on \u03c6 {x | (\u03bb i, f i x) = (\u03bb i, f i x\u2080)} x\u2080,\n    by simpa only [function.funext_iff] using hextr,\n  rcases hextr.exists_linear_map_of_has_strict_fderiv_at\n    (has_strict_fderiv_at_pi.2 (\u03bb i, hf' i)) h\u03c6'\n    with \u27e8\u039b, \u039b\u2080, h0, hsum\u27e9,\n  rcases (linear_equiv.pi_ring \u211d \u211d \u03b9 \u211d).symm.surjective \u039b with \u27e8\u039b, rfl\u27e9,\n  refine \u27e8\u039b, \u039b\u2080, _, _\u27e9,\n  { simpa only [ne.def, prod.ext_iff, linear_equiv.map_eq_zero_iff, prod.fst_zero] using h0 },\n  { ext x, simpa [mul_comm] using hsum x }\nend\n\n/-- Lagrange multipliers theorem. Let `f : \u03b9 \u2192 E \u2192 \u211d` be a finite family of functions.\nSuppose that `\u03c6 : E \u2192 \u211d` has a local extremum on the set `{x | \u2200 i, f i x = f i x\u2080}` at `x\u2080`.\nSuppose that all functions `f i` as well as `\u03c6` are strictly differentiable at `x\u2080`.\nThen the derivatives `f' i : E \u2192 L[\u211d] \u211d` and `\u03c6' : E \u2192L[\u211d] \u211d` are linearly dependent.\n\nSee also `is_local_extr_on.exists_multipliers_of_has_strict_fderiv_at` for a version that\nthat states existence of Lagrange multipliers `\u039b` and `\u039b\u2080` instead of using\n`\u00aclinear_independent \u211d _` -/\nlemma is_local_extr_on.linear_dependent_of_has_strict_fderiv_at {\u03b9 : Type*} [fintype \u03b9]\n  {f : \u03b9 \u2192 E \u2192 \u211d} {f' : \u03b9 \u2192 E \u2192L[\u211d] \u211d}\n  (hextr : is_local_extr_on \u03c6 {x | \u2200 i, f i x = f i x\u2080} x\u2080)\n  (hf' : \u2200 i, has_strict_fderiv_at (f i) (f' i) x\u2080)\n  (h\u03c6' : has_strict_fderiv_at \u03c6 \u03c6' x\u2080) :\n  \u00aclinear_independent \u211d (\u03bb i, option.elim i \u03c6' f' : option \u03b9 \u2192 E \u2192L[\u211d] \u211d) :=\nbegin\n  rw [fintype.linear_independent_iff], push_neg,\n  rcases hextr.exists_multipliers_of_has_strict_fderiv_at hf' h\u03c6' with \u27e8\u039b, \u039b\u2080, h\u039b, h\u039bf\u27e9,\n  refine \u27e8\u03bb i, option.elim i \u039b\u2080 \u039b, _, _\u27e9,\n  { simpa [add_comm] using h\u039bf },\n  { simpa [function.funext_iff, not_and_distrib, or_comm, option.exists] using h\u039b }\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/calculus/lagrange_multipliers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7118335215685524}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\nimport data.option.basic\nimport logic.nontrivial\nimport order.lattice\nimport order.max\nimport tactic.pi_instances\n\n/-!\n# \u22a4 and \u22a5, bounded lattices and variants\n\nThis file defines top and bottom elements (greatest and least elements) of a type, the bounded\nvariants of different kinds of lattices, sets up the typeclass hierarchy between them and provides\ninstances for `Prop` and `fun`.\n\n## Main declarations\n\n* `has_<top/bot> \u03b1`: Typeclasses to declare the `\u22a4`/`\u22a5` notation.\n* `order_<top/bot> \u03b1`: Order with a top/bottom element.\n* `bounded_order \u03b1`: Order with a top and bottom element.\n* `with_<top/bot> \u03b1`: Equips `option \u03b1` with the order on `\u03b1` plus `none` as the top/bottom element.\n* `is_compl x y`: In a bounded lattice, predicate for \"`x` is a complement of `y`\". Note that in a\n  non distributive lattice, an element can have several complements.\n* `is_complemented \u03b1`: Typeclass stating that any element of a lattice has a complement.\n\n## Common lattices\n\n* Distributive lattices with a bottom element. Notated by `[distrib_lattice \u03b1] [order_bot \u03b1]`\n  It captures the properties of `disjoint` that are common to `generalized_boolean_algebra` and\n  `distrib_lattice` when `order_bot`.\n* Bounded and distributive lattice. Notated by `[distrib_lattice \u03b1] [bounded_order \u03b1]`.\n  Typical examples include `Prop` and `set \u03b1`.\n\n## Implementation notes\n\nWe didn't prove things about `[distrib_lattice \u03b1] [order_top \u03b1]` because the dual notion of\n`disjoint` isn't really used anywhere.\n-/\n\nopen order_dual\n\nset_option old_structure_cmd true\n\nuniverses u v\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\n\n/-! ### Top, bottom element -/\n\n/-- Typeclass for the `\u22a4` (`\\top`) notation -/\n@[notation_class] class has_top (\u03b1 : Type u) := (top : \u03b1)\n/-- Typeclass for the `\u22a5` (`\\bot`) notation -/\n@[notation_class] class has_bot (\u03b1 : Type u) := (bot : \u03b1)\n\nnotation `\u22a4` := has_top.top\nnotation `\u22a5` := has_bot.bot\n\n@[priority 100] instance has_top_nonempty (\u03b1 : Type u) [has_top \u03b1] : nonempty \u03b1 := \u27e8\u22a4\u27e9\n@[priority 100] instance has_bot_nonempty (\u03b1 : Type u) [has_bot \u03b1] : nonempty \u03b1 := \u27e8\u22a5\u27e9\n\nattribute [pattern] has_bot.bot has_top.top\n\n/-- An order is an `order_top` if it has a greatest element.\nWe state this using a data mixin, holding the value of `\u22a4` and the greatest element constraint. -/\n@[ancestor has_top]\nclass order_top (\u03b1 : Type u) [has_le \u03b1] extends has_top \u03b1 :=\n(le_top : \u2200 a : \u03b1, a \u2264 \u22a4)\n\nsection order_top\nsection has_le\nvariables [has_le \u03b1] [order_top \u03b1] {a : \u03b1}\n\n@[simp] lemma le_top : a \u2264 \u22a4 := order_top.le_top a\n@[simp] lemma is_top_top : is_top (\u22a4 : \u03b1) := \u03bb _, le_top\n\nend has_le\n\nsection preorder\nvariables [preorder \u03b1] [order_top \u03b1] {a b : \u03b1}\n\n@[simp] lemma is_max_top : is_max (\u22a4 : \u03b1) := is_top_top.is_max\n@[simp] lemma not_top_lt : \u00ac \u22a4 < a := is_max_top.not_lt\n\nlemma ne_top_of_lt (h : a < b) : a \u2260 \u22a4 := (h.trans_le le_top).ne\n\nalias ne_top_of_lt \u2190 has_lt.lt.ne_top\n\nend preorder\n\nvariables [partial_order \u03b1] [order_top \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a b : \u03b1}\n\n@[simp] lemma is_max_iff_eq_top : is_max a \u2194 a = \u22a4 :=\n\u27e8\u03bb h, h.eq_of_le le_top, \u03bb h b _, h.symm \u25b8 le_top\u27e9\n\n@[simp] lemma is_top_iff_eq_top : is_top a \u2194 a = \u22a4 :=\n\u27e8\u03bb h, h.is_max.eq_of_le le_top, \u03bb h b, h.symm \u25b8 le_top\u27e9\n\nlemma not_is_max_iff_ne_top : \u00ac is_max a \u2194 a \u2260 \u22a4 := is_max_iff_eq_top.not\nlemma not_is_top_iff_ne_top : \u00ac is_top a \u2194 a \u2260 \u22a4 := is_top_iff_eq_top.not\n\nalias is_max_iff_eq_top \u2194 is_max.eq_top _\nalias is_top_iff_eq_top \u2194 is_top.eq_top _\n\n@[simp] lemma top_le_iff : \u22a4 \u2264 a \u2194 a = \u22a4 := le_top.le_iff_eq.trans eq_comm\nlemma top_unique (h : \u22a4 \u2264 a) : a = \u22a4 := le_top.antisymm h\nlemma eq_top_iff : a = \u22a4 \u2194 \u22a4 \u2264 a := top_le_iff.symm\nlemma eq_top_mono (h : a \u2264 b) (h\u2082 : a = \u22a4) : b = \u22a4 := top_unique $ h\u2082 \u25b8 h\nlemma lt_top_iff_ne_top : a < \u22a4 \u2194 a \u2260 \u22a4 := le_top.lt_iff_ne\n@[simp] lemma not_lt_top_iff : \u00ac a < \u22a4 \u2194 a = \u22a4 := lt_top_iff_ne_top.not_left\nlemma eq_top_or_lt_top (a : \u03b1) : a = \u22a4 \u2228 a < \u22a4 := le_top.eq_or_lt\nlemma ne.lt_top (h : a \u2260 \u22a4) : a < \u22a4 := lt_top_iff_ne_top.mpr h\nlemma ne.lt_top' (h : \u22a4 \u2260 a) : a < \u22a4 := h.symm.lt_top\nlemma ne_top_of_le_ne_top (hb : b \u2260 \u22a4) (hab : a \u2264 b) : a \u2260 \u22a4 := (hab.trans_lt hb.lt_top).ne\n\nlemma strict_mono.apply_eq_top_iff (hf : strict_mono f) : f a = f \u22a4 \u2194 a = \u22a4 :=\n\u27e8\u03bb h, not_lt_top_iff.1 $ \u03bb ha, (hf ha).ne h, congr_arg _\u27e9\n\nlemma strict_anti.apply_eq_top_iff (hf : strict_anti f) : f a = f \u22a4 \u2194 a = \u22a4 :=\n\u27e8\u03bb h, not_lt_top_iff.1 $ \u03bb ha, (hf ha).ne' h, congr_arg _\u27e9\n\nvariables [nontrivial \u03b1]\n\nlemma not_is_min_top : \u00ac is_min (\u22a4 : \u03b1) :=\n\u03bb h, let \u27e8a, ha\u27e9 := exists_ne (\u22a4 : \u03b1) in ha $ top_le_iff.1 $ h le_top\n\nend order_top\n\nlemma strict_mono.maximal_preimage_top [linear_order \u03b1] [preorder \u03b2] [order_top \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (H : strict_mono f) {a} (h_top : f a = \u22a4) (x : \u03b1) :\n  x \u2264 a :=\nH.maximal_of_maximal_image (\u03bb p, by { rw h_top, exact le_top }) x\n\ntheorem order_top.ext_top {\u03b1} {hA : partial_order \u03b1} (A : order_top \u03b1)\n  {hB : partial_order \u03b1} (B : order_top \u03b1)\n  (H : \u2200 x y : \u03b1, (by haveI := hA; exact x \u2264 y) \u2194 x \u2264 y) :\n  (by haveI := A; exact \u22a4 : \u03b1) = \u22a4 :=\ntop_unique $ by rw \u2190 H; apply le_top\n\ntheorem order_top.ext {\u03b1} [partial_order \u03b1] {A B : order_top \u03b1} : A = B :=\nbegin\n  have tt := order_top.ext_top A B (\u03bb _ _, iff.rfl),\n  casesI A with _ ha, casesI B with _ hb,\n  congr,\n  exact le_antisymm (hb _) (ha _)\nend\n\n/-- An order is an `order_bot` if it has a least element.\nWe state this using a data mixin, holding the value of `\u22a5` and the least element constraint. -/\n@[ancestor has_bot]\nclass order_bot (\u03b1 : Type u) [has_le \u03b1] extends has_bot \u03b1 :=\n(bot_le : \u2200 a : \u03b1, \u22a5 \u2264 a)\n\nsection order_bot\n\nsection has_le\nvariables [has_le \u03b1] [order_bot \u03b1] {a : \u03b1}\n\n@[simp] lemma bot_le : \u22a5 \u2264 a := order_bot.bot_le a\n@[simp] lemma is_bot_bot : is_bot (\u22a5 : \u03b1) := \u03bb _, bot_le\n\nend has_le\n\nnamespace order_dual\nvariable (\u03b1)\n\ninstance [has_bot \u03b1] : has_top \u03b1\u1d52\u1d48 := \u27e8(\u22a5 : \u03b1)\u27e9\ninstance [has_top \u03b1] : has_bot \u03b1\u1d52\u1d48 := \u27e8(\u22a4 : \u03b1)\u27e9\n\ninstance [has_le \u03b1] [order_bot \u03b1] : order_top \u03b1\u1d52\u1d48 :=\n{ le_top := @bot_le \u03b1 _ _,\n  .. order_dual.has_top \u03b1 }\n\ninstance [has_le \u03b1] [order_top \u03b1] : order_bot \u03b1\u1d52\u1d48 :=\n{ bot_le := @le_top \u03b1 _ _,\n  .. order_dual.has_bot \u03b1 }\n\n@[simp] lemma of_dual_bot [has_top \u03b1] : of_dual \u22a5 = (\u22a4 : \u03b1) := rfl\n@[simp] lemma of_dual_top [has_bot \u03b1] : of_dual \u22a4 = (\u22a5 : \u03b1) := rfl\n@[simp] lemma to_dual_bot [has_bot \u03b1] : to_dual (\u22a5 : \u03b1) = \u22a4 := rfl\n@[simp] lemma to_dual_top [has_top \u03b1] : to_dual (\u22a4 : \u03b1) = \u22a5 := rfl\n\nend order_dual\n\nsection preorder\nvariables [preorder \u03b1] [order_bot \u03b1] {a b : \u03b1}\n\n@[simp] lemma is_min_bot : is_min (\u22a5 : \u03b1) := is_bot_bot.is_min\n@[simp] lemma not_lt_bot : \u00ac a < \u22a5 := is_min_bot.not_lt\n\nlemma ne_bot_of_gt (h : a < b) : b \u2260 \u22a5 := (bot_le.trans_lt h).ne'\n\nalias ne_bot_of_gt \u2190 has_lt.lt.ne_bot\n\nend preorder\n\nvariables [partial_order \u03b1] [order_bot \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a b : \u03b1}\n\n@[simp] lemma is_min_iff_eq_bot : is_min a \u2194 a = \u22a5 :=\n\u27e8\u03bb h, h.eq_of_ge bot_le, \u03bb h b _, h.symm \u25b8 bot_le\u27e9\n\n@[simp] lemma is_bot_iff_eq_bot : is_bot a \u2194 a = \u22a5 :=\n\u27e8\u03bb h, h.is_min.eq_of_ge bot_le, \u03bb h b, h.symm \u25b8 bot_le\u27e9\n\nlemma not_is_min_iff_ne_bot : \u00ac is_min a \u2194 a \u2260 \u22a5 := is_min_iff_eq_bot.not\nlemma not_is_bot_iff_ne_bot : \u00ac is_bot a \u2194 a \u2260 \u22a5 := is_bot_iff_eq_bot.not\n\nalias is_min_iff_eq_bot \u2194 is_min.eq_bot _\nalias is_bot_iff_eq_bot \u2194 is_bot.eq_bot _\n\n@[simp] lemma le_bot_iff : a \u2264 \u22a5 \u2194 a = \u22a5 := bot_le.le_iff_eq\nlemma bot_unique (h : a \u2264 \u22a5) : a = \u22a5 := h.antisymm bot_le\nlemma eq_bot_iff : a = \u22a5 \u2194 a \u2264 \u22a5 := le_bot_iff.symm\nlemma eq_bot_mono (h : a \u2264 b) (h\u2082 : b = \u22a5) : a = \u22a5 := bot_unique $ h\u2082 \u25b8 h\nlemma bot_lt_iff_ne_bot : \u22a5 < a \u2194 a \u2260 \u22a5 := bot_le.lt_iff_ne.trans ne_comm\n@[simp] lemma not_bot_lt_iff : \u00ac \u22a5 < a \u2194 a = \u22a5 := bot_lt_iff_ne_bot.not_left\nlemma eq_bot_or_bot_lt (a : \u03b1) : a = \u22a5 \u2228 \u22a5 < a := bot_le.eq_or_gt\nlemma eq_bot_of_minimal (h : \u2200 b, \u00ac b < a) : a = \u22a5 := (eq_bot_or_bot_lt a).resolve_right (h \u22a5)\nlemma ne.bot_lt (h : a \u2260 \u22a5) : \u22a5 < a := bot_lt_iff_ne_bot.mpr h\nlemma ne.bot_lt' (h : \u22a5 \u2260 a) : \u22a5 < a := h.symm.bot_lt\nlemma ne_bot_of_le_ne_bot (hb : b \u2260 \u22a5) (hab : b \u2264 a) : a \u2260 \u22a5 := (hb.bot_lt.trans_le hab).ne'\n\nlemma strict_mono.apply_eq_bot_iff (hf : strict_mono f) : f a = f \u22a5 \u2194 a = \u22a5 :=\nhf.dual.apply_eq_top_iff\n\nlemma strict_anti.apply_eq_bot_iff (hf : strict_anti f) : f a = f \u22a5 \u2194 a = \u22a5 :=\nhf.dual.apply_eq_top_iff\n\nvariables [nontrivial \u03b1]\n\nlemma not_is_max_bot : \u00ac is_max (\u22a5 : \u03b1) := @not_is_min_top \u03b1\u1d52\u1d48 _ _ _\n\nend order_bot\n\nlemma strict_mono.minimal_preimage_bot [linear_order \u03b1] [partial_order \u03b2] [order_bot \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (H : strict_mono f) {a} (h_bot : f a = \u22a5) (x : \u03b1) :\n  a \u2264 x :=\nH.minimal_of_minimal_image (\u03bb p, by { rw h_bot, exact bot_le }) x\n\ntheorem order_bot.ext_bot {\u03b1} {hA : partial_order \u03b1} (A : order_bot \u03b1)\n  {hB : partial_order \u03b1} (B : order_bot \u03b1)\n  (H : \u2200 x y : \u03b1, (by haveI := hA; exact x \u2264 y) \u2194 x \u2264 y) :\n  (by haveI := A; exact \u22a5 : \u03b1) = \u22a5 :=\nbot_unique $ by rw \u2190 H; apply bot_le\n\ntheorem order_bot.ext {\u03b1} [partial_order \u03b1] {A B : order_bot \u03b1} : A = B :=\nbegin\n  have tt := order_bot.ext_bot A B (\u03bb _ _, iff.rfl),\n  casesI A with a ha, casesI B with b hb,\n  congr,\n  exact le_antisymm (ha _) (hb _)\nend\n\nsection semilattice_sup_top\nvariables [semilattice_sup \u03b1] [order_top \u03b1] {a : \u03b1}\n\n@[simp] theorem top_sup_eq : \u22a4 \u2294 a = \u22a4 :=\nsup_of_le_left le_top\n\n@[simp] theorem sup_top_eq : a \u2294 \u22a4 = \u22a4 :=\nsup_of_le_right le_top\n\nend semilattice_sup_top\n\nsection semilattice_sup_bot\nvariables [semilattice_sup \u03b1] [order_bot \u03b1] {a b : \u03b1}\n\n@[simp] theorem bot_sup_eq : \u22a5 \u2294 a = a :=\nsup_of_le_right bot_le\n\n@[simp] theorem sup_bot_eq : a \u2294 \u22a5 = a :=\nsup_of_le_left bot_le\n\n@[simp] theorem sup_eq_bot_iff : a \u2294 b = \u22a5 \u2194 (a = \u22a5 \u2227 b = \u22a5) :=\nby rw [eq_bot_iff, sup_le_iff]; simp\n\nend semilattice_sup_bot\n\nsection semilattice_inf_top\nvariables [semilattice_inf \u03b1] [order_top \u03b1] {a b : \u03b1}\n\n@[simp] theorem top_inf_eq : \u22a4 \u2293 a = a :=\ninf_of_le_right le_top\n\n@[simp] theorem inf_top_eq : a \u2293 \u22a4 = a :=\ninf_of_le_left le_top\n\n@[simp] theorem inf_eq_top_iff : a \u2293 b = \u22a4 \u2194 (a = \u22a4 \u2227 b = \u22a4) :=\n@sup_eq_bot_iff \u03b1\u1d52\u1d48 _ _ _ _\n\nend semilattice_inf_top\n\nsection semilattice_inf_bot\nvariables [semilattice_inf \u03b1] [order_bot \u03b1] {a : \u03b1}\n\n@[simp] theorem bot_inf_eq : \u22a5 \u2293 a = \u22a5 :=\ninf_of_le_left bot_le\n\n@[simp] theorem inf_bot_eq : a \u2293 \u22a5 = \u22a5 :=\ninf_of_le_right bot_le\n\nend semilattice_inf_bot\n\n/-! ### Bounded order -/\n\n/-- A bounded order describes an order `(\u2264)` with a top and bottom element,\n  denoted `\u22a4` and `\u22a5` respectively. -/\n@[ancestor order_top order_bot]\nclass bounded_order (\u03b1 : Type u) [has_le \u03b1] extends order_top \u03b1, order_bot \u03b1.\n\ninstance (\u03b1 : Type u) [has_le \u03b1] [bounded_order \u03b1] : bounded_order \u03b1\u1d52\u1d48 :=\n{ .. order_dual.order_top \u03b1, .. order_dual.order_bot \u03b1 }\n\ntheorem bounded_order.ext {\u03b1} [partial_order \u03b1] {A B : bounded_order \u03b1} : A = B :=\nbegin\n  have ht : @bounded_order.to_order_top \u03b1 _ A = @bounded_order.to_order_top \u03b1 _ B := order_top.ext,\n  have hb : @bounded_order.to_order_bot \u03b1 _ A = @bounded_order.to_order_bot \u03b1 _ B := order_bot.ext,\n  casesI A,\n  casesI B,\n  injection ht with h,\n  injection hb with h',\n  convert rfl,\n  { exact h.symm },\n  { exact h'.symm }\nend\n\n/-- Propositions form a distributive lattice. -/\ninstance Prop.distrib_lattice : distrib_lattice Prop :=\n{ le           := \u03bb a b, a \u2192 b,\n  le_refl      := \u03bb _, id,\n  le_trans     := \u03bb a b c f g, g \u2218 f,\n  le_antisymm  := \u03bb a b Hab Hba, propext \u27e8Hab, Hba\u27e9,\n\n  sup          := or,\n  le_sup_left  := @or.inl,\n  le_sup_right := @or.inr,\n  sup_le       := \u03bb a b c, or.rec,\n\n  inf          := and,\n  inf_le_left  := @and.left,\n  inf_le_right := @and.right,\n  le_inf       := \u03bb a b c Hab Hac Ha, and.intro (Hab Ha) (Hac Ha),\n  le_sup_inf   := \u03bb a b c H, or_iff_not_imp_left.2 $\n    \u03bb Ha, \u27e8H.1.resolve_left Ha, H.2.resolve_left Ha\u27e9 }\n\n/-- Propositions form a bounded order. -/\ninstance Prop.bounded_order : bounded_order Prop :=\n{ top          := true,\n  le_top       := \u03bb a Ha, true.intro,\n  bot          := false,\n  bot_le       := @false.elim }\n\ninstance Prop.le_is_total : is_total Prop (\u2264) :=\n\u27e8\u03bb p q, by { change (p \u2192 q) \u2228 (q \u2192 p), tauto! }\u27e9\n\nnoncomputable instance Prop.linear_order : linear_order Prop :=\nby classical; exact lattice.to_linear_order Prop\n\n@[simp] lemma le_Prop_eq : ((\u2264) : Prop \u2192 Prop \u2192 Prop) = (\u2192) := rfl\n@[simp] lemma sup_Prop_eq : (\u2294) = (\u2228) := rfl\n@[simp] lemma inf_Prop_eq : (\u2293) = (\u2227) := rfl\n\nsection logic\n/-!\n#### In this section we prove some properties about monotone and antitone operations on `Prop`\n-/\nsection preorder\n\nvariable [preorder \u03b1]\n\ntheorem monotone_and {p q : \u03b1 \u2192 Prop} (m_p : monotone p) (m_q : monotone q) :\n  monotone (\u03bb x, p x \u2227 q x) :=\n\u03bb a b h, and.imp (m_p h) (m_q h)\n-- Note: by finish [monotone] doesn't work\n\ntheorem monotone_or {p q : \u03b1 \u2192 Prop} (m_p : monotone p) (m_q : monotone q) :\n  monotone (\u03bb x, p x \u2228 q x) :=\n\u03bb a b h, or.imp (m_p h) (m_q h)\n\nlemma monotone_le {x : \u03b1}: monotone ((\u2264) x) :=\n\u03bb y z h' h, h.trans h'\n\nlemma monotone_lt {x : \u03b1}: monotone ((<) x) :=\n\u03bb y z h' h, h.trans_le h'\n\nlemma antitone_le {x : \u03b1}: antitone (\u2264 x) :=\n\u03bb y z h' h, h'.trans h\n\nlemma antitone_lt {x : \u03b1}: antitone (< x) :=\n\u03bb y z h' h, h'.trans_lt h\n\nlemma monotone.forall {P : \u03b2 \u2192 \u03b1 \u2192 Prop} (hP : \u2200 x, monotone (P x)) :\n  monotone (\u03bb y, \u2200 x, P x y) :=\n\u03bb y y' hy h x, hP x hy $ h x\n\nlemma antitone.forall {P : \u03b2 \u2192 \u03b1 \u2192 Prop} (hP : \u2200 x, antitone (P x)) :\n  antitone (\u03bb y, \u2200 x, P x y) :=\n\u03bb y y' hy h x, hP x hy (h x)\n\nlemma monotone.ball {P : \u03b2 \u2192 \u03b1 \u2192 Prop} {s : set \u03b2} (hP : \u2200 x \u2208 s, monotone (P x)) :\n  monotone (\u03bb y, \u2200 x \u2208 s, P x y) :=\n\u03bb y y' hy h x hx, hP x hx hy (h x hx)\n\nlemma antitone.ball {P : \u03b2 \u2192 \u03b1 \u2192 Prop} {s : set \u03b2} (hP : \u2200 x \u2208 s, antitone (P x)) :\n  antitone (\u03bb y, \u2200 x \u2208 s, P x y) :=\n\u03bb y y' hy h x hx, hP x hx hy (h x hx)\n\nend preorder\n\nsection semilattice_sup\nvariables [semilattice_sup \u03b1]\n\nlemma exists_ge_and_iff_exists {P : \u03b1 \u2192 Prop} {x\u2080 : \u03b1} (hP : monotone P) :\n  (\u2203 x, x\u2080 \u2264 x \u2227 P x) \u2194 \u2203 x, P x :=\n\u27e8\u03bb h, h.imp $ \u03bb x h, h.2, \u03bb \u27e8x, hx\u27e9, \u27e8x \u2294 x\u2080, le_sup_right, hP le_sup_left hx\u27e9\u27e9\n\nend semilattice_sup\n\nsection semilattice_inf\nvariables [semilattice_inf \u03b1]\n\nlemma exists_le_and_iff_exists {P : \u03b1 \u2192 Prop} {x\u2080 : \u03b1} (hP : antitone P) :\n  (\u2203 x, x \u2264 x\u2080 \u2227 P x) \u2194 \u2203 x, P x :=\nexists_ge_and_iff_exists hP.dual_left\n\nend semilattice_inf\nend logic\n\n/-! ### Function lattices -/\n\nnamespace pi\nvariables {\u03b9 : Type*} {\u03b1' : \u03b9 \u2192 Type*}\n\ninstance [\u03a0 i, has_bot (\u03b1' i)] : has_bot (\u03a0 i, \u03b1' i) := \u27e8\u03bb i, \u22a5\u27e9\n\n@[simp] lemma bot_apply [\u03a0 i, has_bot (\u03b1' i)] (i : \u03b9) : (\u22a5 : \u03a0 i, \u03b1' i) i = \u22a5 := rfl\n\nlemma bot_def [\u03a0 i, has_bot (\u03b1' i)] : (\u22a5 : \u03a0 i, \u03b1' i) = \u03bb i, \u22a5 := rfl\n\ninstance [\u03a0 i, has_top (\u03b1' i)] : has_top (\u03a0 i, \u03b1' i) := \u27e8\u03bb i, \u22a4\u27e9\n\n@[simp] lemma top_apply [\u03a0 i, has_top (\u03b1' i)] (i : \u03b9) : (\u22a4 : \u03a0 i, \u03b1' i) i = \u22a4 := rfl\n\nlemma top_def [\u03a0 i, has_top (\u03b1' i)] : (\u22a4 : \u03a0 i, \u03b1' i) = \u03bb i, \u22a4 := rfl\n\ninstance [\u03a0 i, has_le (\u03b1' i)] [\u03a0 i, order_top (\u03b1' i)] : order_top (\u03a0 i, \u03b1' i) :=\n{ le_top := \u03bb _ _, le_top, ..pi.has_top }\n\ninstance [\u03a0 i, has_le (\u03b1' i)] [\u03a0 i, order_bot (\u03b1' i)] : order_bot (\u03a0 i, \u03b1' i) :=\n{ bot_le := \u03bb _ _, bot_le, ..pi.has_bot }\n\ninstance [\u03a0 i, has_le (\u03b1' i)] [\u03a0 i, bounded_order (\u03b1' i)] :\n  bounded_order (\u03a0 i, \u03b1' i) :=\n{ ..pi.order_top, ..pi.order_bot }\n\nend pi\n\nsection subsingleton\n\nvariables [partial_order \u03b1] [bounded_order \u03b1]\n\nlemma eq_bot_of_bot_eq_top (h\u03b1 : (\u22a5 : \u03b1) = \u22a4) (x : \u03b1) :\n  x = (\u22a5 : \u03b1) :=\neq_bot_mono le_top (eq.symm h\u03b1)\n\nlemma eq_top_of_bot_eq_top (h\u03b1 : (\u22a5 : \u03b1) = \u22a4) (x : \u03b1) :\n  x = (\u22a4 : \u03b1) :=\neq_top_mono bot_le h\u03b1\n\nlemma subsingleton_of_top_le_bot (h : (\u22a4 : \u03b1) \u2264 (\u22a5 : \u03b1)) :\n  subsingleton \u03b1 :=\n\u27e8\u03bb a b, le_antisymm (le_trans le_top $ le_trans h bot_le) (le_trans le_top $ le_trans h bot_le)\u27e9\n\nlemma subsingleton_of_bot_eq_top (h\u03b1 : (\u22a5 : \u03b1) = (\u22a4 : \u03b1)) :\n  subsingleton \u03b1 :=\nsubsingleton_of_top_le_bot (ge_of_eq h\u03b1)\n\nlemma subsingleton_iff_bot_eq_top :\n  (\u22a5 : \u03b1) = (\u22a4 : \u03b1) \u2194 subsingleton \u03b1 :=\n\u27e8subsingleton_of_bot_eq_top, \u03bb h, by exactI subsingleton.elim \u22a5 \u22a4\u27e9\n\nend subsingleton\n\nsection lift\n\n/-- Pullback an `order_top`. -/\n@[reducible] -- See note [reducible non-instances]\ndef order_top.lift [has_le \u03b1] [has_top \u03b1] [has_le \u03b2] [order_top \u03b2] (f : \u03b1 \u2192 \u03b2)\n  (map_le : \u2200 a b, f a \u2264 f b \u2192 a \u2264 b) (map_top : f \u22a4 = \u22a4) :\n  order_top \u03b1 :=\n\u27e8\u22a4, \u03bb a, map_le _ _ $ by { rw map_top, exact le_top }\u27e9\n\n/-- Pullback an `order_bot`. -/\n@[reducible] -- See note [reducible non-instances]\ndef order_bot.lift [has_le \u03b1] [has_bot \u03b1] [has_le \u03b2] [order_bot \u03b2] (f : \u03b1 \u2192 \u03b2)\n  (map_le : \u2200 a b, f a \u2264 f b \u2192 a \u2264 b) (map_bot : f \u22a5 = \u22a5) :\n  order_bot \u03b1 :=\n\u27e8\u22a5, \u03bb a, map_le _ _ $ by { rw map_bot, exact bot_le }\u27e9\n\n/-- Pullback a `bounded_order`. -/\n@[reducible] -- See note [reducible non-instances]\ndef bounded_order.lift [has_le \u03b1] [has_top \u03b1] [has_bot \u03b1] [has_le \u03b2] [bounded_order \u03b2] (f : \u03b1 \u2192 \u03b2)\n  (map_le : \u2200 a b, f a \u2264 f b \u2192 a \u2264 b) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5) :\n  bounded_order \u03b1 :=\n{ ..order_top.lift f map_le map_top, ..order_bot.lift f map_le map_bot }\n\nend lift\n\n/-! ### `with_bot`, `with_top` -/\n\n/-- Attach `\u22a5` to a type. -/\ndef with_bot (\u03b1 : Type*) := option \u03b1\n\nnamespace with_bot\nvariables {a b : \u03b1}\n\nmeta instance [has_to_format \u03b1] : has_to_format (with_bot \u03b1) :=\n{ to_format := \u03bb x,\n  match x with\n  | none := \"\u22a5\"\n  | (some x) := to_fmt x\n  end }\n\ninstance [has_repr \u03b1] : has_repr (with_bot \u03b1) :=\n\u27e8\u03bb o, match o with | none := \"\u22a5\" | (some a) := \"\u2191\" ++ repr a end\u27e9\n\ninstance : has_coe_t \u03b1 (with_bot \u03b1) := \u27e8some\u27e9\ninstance : has_bot (with_bot \u03b1) := \u27e8none\u27e9\n\nmeta instance {\u03b1 : Type} [reflected _ \u03b1] [has_reflect \u03b1] : has_reflect (with_bot \u03b1)\n| \u22a5 := `(\u22a5)\n| (a : \u03b1) := `(coe : \u03b1 \u2192 with_bot \u03b1).subst `(a)\n\ninstance : inhabited (with_bot \u03b1) := \u27e8\u22a5\u27e9\n\nlemma none_eq_bot : (none : with_bot \u03b1) = (\u22a5 : with_bot \u03b1) := rfl\nlemma some_eq_coe (a : \u03b1) : (some a : with_bot \u03b1) = (\u2191a : with_bot \u03b1) := rfl\n\n@[simp] lemma bot_ne_coe : \u22a5 \u2260 (a : with_bot \u03b1) .\n@[simp] lemma coe_ne_bot : (a : with_bot \u03b1) \u2260 \u22a5 .\n\n/-- Recursor for `with_bot` using the preferred forms `\u22a5` and `\u2191a`. -/\n@[elab_as_eliminator]\ndef rec_bot_coe {C : with_bot \u03b1 \u2192 Sort*} (h\u2081 : C \u22a5) (h\u2082 : \u03a0 (a : \u03b1), C a) :\n  \u03a0 (n : with_bot \u03b1), C n :=\noption.rec h\u2081 h\u2082\n\n@[norm_cast] lemma coe_eq_coe : (a : with_bot \u03b1) = b \u2194 a = b := option.some_inj\n\n/-- Lift a map `f : \u03b1 \u2192 \u03b2` to `with_bot \u03b1 \u2192 with_bot \u03b2`. Implemented using `option.map`. -/\ndef map (f : \u03b1 \u2192 \u03b2) : with_bot \u03b1 \u2192 with_bot \u03b2 := option.map f\n\n@[simp] lemma map_bot (f : \u03b1 \u2192 \u03b2) : map f \u22a5 = \u22a5 := rfl\n@[simp] lemma map_coe (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : map f a = f a := rfl\n\nlemma ne_bot_iff_exists {x : with_bot \u03b1} : x \u2260 \u22a5 \u2194 \u2203 (a : \u03b1), \u2191a = x := option.ne_none_iff_exists\n\n/-- Deconstruct a `x : with_bot \u03b1` to the underlying value in `\u03b1`, given a proof that `x \u2260 \u22a5`. -/\ndef unbot : \u03a0 (x : with_bot \u03b1), x \u2260 \u22a5 \u2192 \u03b1\n| \u22a5        h := absurd rfl h\n| (some x) h := x\n\n@[simp] lemma coe_unbot (x : with_bot \u03b1) (h : x \u2260 \u22a5) : (x.unbot h : with_bot \u03b1) = x :=\nby { cases x, simpa using h, refl, }\n\n@[simp] lemma unbot_coe (x : \u03b1) (h : (x : with_bot \u03b1) \u2260 \u22a5 := coe_ne_bot) :\n  (x : with_bot \u03b1).unbot h = x := rfl\n\ninstance : can_lift (with_bot \u03b1) \u03b1 :=\n{ coe := coe,\n  cond := \u03bb r, r \u2260 \u22a5,\n  prf := \u03bb x h, \u27e8x.unbot h, coe_unbot _ _\u27e9 }\n\nsection has_le\nvariables [has_le \u03b1]\n\n@[priority 10]\ninstance : has_le (with_bot \u03b1) := \u27e8\u03bb o\u2081 o\u2082 : option \u03b1, \u2200 a \u2208 o\u2081, \u2203 b \u2208 o\u2082, a \u2264 b\u27e9\n\n@[simp] lemma some_le_some : @has_le.le (with_bot \u03b1) _ (some a) (some b) \u2194 a \u2264 b := by simp [(\u2264)]\n@[simp, norm_cast] lemma coe_le_coe : (a : with_bot \u03b1) \u2264 b \u2194 a \u2264 b := some_le_some\n\n@[simp] lemma none_le {a : with_bot \u03b1} : @has_le.le (with_bot \u03b1) _ none a :=\n\u03bb b h, option.no_confusion h\n\ninstance : order_bot (with_bot \u03b1) := { bot_le := \u03bb a, none_le, ..with_bot.has_bot }\n\ninstance [order_top \u03b1] : order_top (with_bot \u03b1) :=\n{ top := some \u22a4,\n  le_top := \u03bb o a ha, by cases ha; exact \u27e8_, rfl, le_top\u27e9 }\n\ninstance [order_top \u03b1] : bounded_order (with_bot \u03b1) :=\n{ ..with_bot.order_top, ..with_bot.order_bot }\n\nlemma not_coe_le_bot (a : \u03b1) : \u00ac (a : with_bot \u03b1) \u2264 \u22a5 :=\n\u03bb h, let \u27e8b, hb, _\u27e9 := h _ rfl in option.not_mem_none _ hb\n\nlemma coe_le : \u2200 {o : option \u03b1}, b \u2208 o \u2192 ((a : with_bot \u03b1) \u2264 o \u2194 a \u2264 b) | _ rfl := coe_le_coe\n\nlemma coe_le_iff : \u2200 {x : with_bot \u03b1}, \u2191a \u2264 x \u2194 \u2203 b : \u03b1, x = b \u2227 a \u2264 b\n| (some a) := by simp [some_eq_coe, coe_eq_coe]\n| none     := iff_of_false (not_coe_le_bot _) $ by simp [none_eq_bot]\n\nlemma le_coe_iff : \u2200 {x : with_bot \u03b1}, x \u2264 b \u2194 \u2200 a, x = \u2191a \u2192 a \u2264 b\n| (some b) := by simp [some_eq_coe, coe_eq_coe]\n| none     := by simp [none_eq_bot]\n\nprotected lemma _root_.is_max.with_bot (h : is_max a) : is_max (a : with_bot \u03b1)\n| none _ := bot_le\n| (some b) hb := some_le_some.2 $ h $ some_le_some.1 hb\n\nend has_le\n\nsection has_lt\nvariables [has_lt \u03b1]\n\n@[priority 10]\ninstance : has_lt (with_bot \u03b1) := \u27e8\u03bb o\u2081 o\u2082 : option \u03b1, \u2203 b \u2208 o\u2082, \u2200 a \u2208 o\u2081, a < b\u27e9\n\n@[simp] lemma some_lt_some : @has_lt.lt (with_bot \u03b1) _ (some a) (some b) \u2194 a < b := by simp [(<)]\n@[simp, norm_cast] lemma coe_lt_coe : (a : with_bot \u03b1) < b \u2194 a < b := some_lt_some\n\n@[simp] lemma none_lt_some (a : \u03b1) : @has_lt.lt (with_bot \u03b1) _ none (some a) :=\n\u27e8a, rfl, \u03bb b hb, (option.not_mem_none _ hb).elim\u27e9\nlemma bot_lt_coe (a : \u03b1) : (\u22a5 : with_bot \u03b1) < a := none_lt_some a\n\n@[simp] lemma not_lt_none (a : with_bot \u03b1) : \u00ac @has_lt.lt (with_bot \u03b1) _ a none :=\n\u03bb \u27e8_, h, _\u27e9, option.not_mem_none _ h\n\nlemma lt_iff_exists_coe : \u2200 {a b : with_bot \u03b1}, a < b \u2194 \u2203 p : \u03b1, b = p \u2227 a < p\n| a (some b) := by simp [some_eq_coe, coe_eq_coe]\n| a none     := iff_of_false (not_lt_none _) $ by simp [none_eq_bot]\n\nlemma lt_coe_iff : \u2200 {x : with_bot \u03b1}, x < b \u2194 \u2200 a, x = \u2191a \u2192 a < b\n| (some b) := by simp [some_eq_coe, coe_eq_coe, coe_lt_coe]\n| none     := by simp [none_eq_bot, bot_lt_coe]\n\nend has_lt\n\ninstance [preorder \u03b1] : preorder (with_bot \u03b1) :=\n{ le          := (\u2264),\n  lt          := (<),\n  lt_iff_le_not_le := by { intros, cases a; cases b; simp [lt_iff_le_not_le]; simp [(<), (\u2264)] },\n  le_refl     := \u03bb o a ha, \u27e8a, ha, le_rfl\u27e9,\n  le_trans    := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha,\n    let \u27e8b, hb, ab\u27e9 := h\u2081 a ha, \u27e8c, hc, bc\u27e9 := h\u2082 b hb in\n    \u27e8c, hc, le_trans ab bc\u27e9 }\n\ninstance [partial_order \u03b1] : partial_order (with_bot \u03b1) :=\n{ le_antisymm := \u03bb o\u2081 o\u2082 h\u2081 h\u2082, begin\n    cases o\u2081 with a,\n    { cases o\u2082 with b, {refl},\n      rcases h\u2082 b rfl with \u27e8_, \u27e8\u27e9, _\u27e9 },\n    { rcases h\u2081 a rfl with \u27e8b, \u27e8\u27e9, h\u2081'\u27e9,\n      rcases h\u2082 b rfl with \u27e8_, \u27e8\u27e9, h\u2082'\u27e9,\n      rw le_antisymm h\u2081' h\u2082' }\n  end,\n  .. with_bot.preorder }\n\nlemma le_coe_get_or_else [preorder \u03b1] : \u2200 (a : with_bot \u03b1) (b : \u03b1), a \u2264 a.get_or_else b\n| (some a) b := le_refl a\n| none     b := \u03bb _ h, option.no_confusion h\n\n@[simp] lemma get_or_else_bot (a : \u03b1) : option.get_or_else (\u22a5 : with_bot \u03b1) a = a := rfl\n\nlemma get_or_else_bot_le_iff [has_le \u03b1] [order_bot \u03b1] {a : with_bot \u03b1} {b : \u03b1} :\n  a.get_or_else \u22a5 \u2264 b \u2194 a \u2264 b :=\nby cases a; simp [none_eq_bot, some_eq_coe]\n\nlemma get_or_else_bot_lt_iff [partial_order \u03b1] [order_bot \u03b1] {a : with_bot \u03b1} {b : \u03b1}\n  (ha : a \u2260 \u22a5) :\n  a.get_or_else \u22a5 < b \u2194 a < b :=\nbegin\n  obtain \u27e8a, rfl\u27e9 := ne_bot_iff_exists.mp ha,\n  simp only [lt_iff_le_and_ne, get_or_else_bot_le_iff, and.congr_right_iff],\n  intro h,\n  apply iff.not,\n  simp only [with_bot.coe_eq_coe, option.get_or_else_coe, iff_self],\nend\n\ninstance [semilattice_sup \u03b1] : semilattice_sup (with_bot \u03b1) :=\n{ sup          := option.lift_or_get (\u2294),\n  le_sup_left  := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2082; simp [option.lift_or_get],\n  le_sup_right := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2081; simp [option.lift_or_get],\n  sup_le       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases o\u2081 with b; cases o\u2082 with c; cases ha,\n    { exact h\u2082 a rfl },\n    { exact h\u2081 a rfl },\n    { rcases h\u2081 b rfl with \u27e8d, \u27e8\u27e9, h\u2081'\u27e9,\n      simp at h\u2082,\n      exact \u27e8d, rfl, sup_le h\u2081' h\u2082\u27e9 }\n  end,\n  ..with_bot.order_bot,\n  ..with_bot.partial_order }\n\nlemma coe_sup [semilattice_sup \u03b1] (a b : \u03b1) : ((a \u2294 b : \u03b1) : with_bot \u03b1) = a \u2294 b := rfl\n\ninstance [semilattice_inf \u03b1] : semilattice_inf (with_bot \u03b1) :=\n{ inf          := \u03bb o\u2081 o\u2082, o\u2081.bind (\u03bb a, o\u2082.map (\u03bb b, a \u2293 b)),\n  inf_le_left  := \u03bb o\u2081 o\u2082 a ha, begin\n    simp [map] at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, inf_le_left\u27e9\n  end,\n  inf_le_right := \u03bb o\u2081 o\u2082 a ha, begin\n    simp [map] at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, inf_le_right\u27e9\n  end,\n  le_inf       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases ha,\n    rcases h\u2081 a rfl with \u27e8b, \u27e8\u27e9, ab\u27e9,\n    rcases h\u2082 a rfl with \u27e8c, \u27e8\u27e9, ac\u27e9,\n    exact \u27e8_, rfl, le_inf ab ac\u27e9\n  end,\n  ..with_bot.order_bot,\n  ..with_bot.partial_order }\n\nlemma coe_inf [semilattice_inf \u03b1] (a b : \u03b1) : ((a \u2293 b : \u03b1) : with_bot \u03b1) = a \u2293 b := rfl\n\ninstance [lattice \u03b1] : lattice (with_bot \u03b1) :=\n{ ..with_bot.semilattice_sup, ..with_bot.semilattice_inf }\n\ninstance decidable_le [has_le \u03b1] [@decidable_rel \u03b1 (\u2264)] : @decidable_rel (with_bot \u03b1) (\u2264)\n| none x := is_true $ \u03bb a h, option.no_confusion h\n| (some x) (some y) :=\n  if h : x \u2264 y\n  then is_true (some_le_some.2 h)\n  else is_false $ by simp *\n| (some x) none := is_false $ \u03bb h, by rcases h x rfl with \u27e8y, \u27e8_\u27e9, _\u27e9\n\ninstance decidable_lt [has_lt \u03b1] [@decidable_rel \u03b1 (<)] : @decidable_rel (with_bot \u03b1) (<)\n| none (some x) := is_true $ by existsi [x,rfl]; rintros _ \u27e8\u27e9\n| (some x) (some y) :=\n  if h : x < y\n  then is_true $ by simp *\n  else is_false $ by simp *\n| x none := is_false $ by rintro \u27e8a,\u27e8\u27e8\u27e9\u27e9\u27e9\n\ninstance is_total_le [has_le \u03b1] [is_total \u03b1 (\u2264)] : is_total (with_bot \u03b1) (\u2264) :=\n\u27e8\u03bb a b, match a, b with\n  | none  , _      := or.inl bot_le\n  | _     , none   := or.inr bot_le\n  | some x, some y := (total_of (\u2264) x y).imp some_le_some.2 some_le_some.2\n  end\u27e9\n\ninstance [linear_order \u03b1] : linear_order (with_bot \u03b1) := lattice.to_linear_order _\n\n@[norm_cast] -- this is not marked simp because the corresponding with_top lemmas are used\nlemma coe_min [linear_order \u03b1] (x y : \u03b1) : ((min x y : \u03b1) : with_bot \u03b1) = min x y := rfl\n\n@[norm_cast] -- this is not marked simp because the corresponding with_top lemmas are used\nlemma coe_max [linear_order \u03b1] (x y : \u03b1) : ((max x y : \u03b1) : with_bot \u03b1) = max x y := rfl\n\nlemma well_founded_lt [preorder \u03b1] (h : @well_founded \u03b1 (<)) : @well_founded (with_bot \u03b1) (<) :=\nhave acc_bot : acc ((<) : with_bot \u03b1 \u2192 with_bot \u03b1 \u2192 Prop) \u22a5 :=\n  acc.intro _ (\u03bb a ha, (not_le_of_gt ha bot_le).elim),\n\u27e8\u03bb a, option.rec_on a acc_bot (\u03bb a, acc.intro _ (\u03bb b, option.rec_on b (\u03bb _, acc_bot)\n(\u03bb b, well_founded.induction h b\n  (show \u2200 b : \u03b1, (\u2200 c, c < b \u2192 (c : with_bot \u03b1) < a \u2192\n      acc ((<) : with_bot \u03b1 \u2192 with_bot \u03b1 \u2192 Prop) c) \u2192 (b : with_bot \u03b1) < a \u2192\n        acc ((<) : with_bot \u03b1 \u2192 with_bot \u03b1 \u2192 Prop) b,\n  from \u03bb b ih hba, acc.intro _ (\u03bb c, option.rec_on c (\u03bb _, acc_bot)\n    (\u03bb c hc, ih _ (some_lt_some.1 hc) (lt_trans hc hba)))))))\u27e9\n\ninstance [has_lt \u03b1] [densely_ordered \u03b1] [no_min_order \u03b1] : densely_ordered (with_bot \u03b1) :=\n\u27e8 \u03bb a b,\n  match a, b with\n  | a,      none   := \u03bb h : a < \u22a5, (not_lt_none _ h).elim\n  | none,   some b := \u03bb h, let \u27e8a, ha\u27e9 := exists_lt b in \u27e8a, bot_lt_coe a, coe_lt_coe.2 ha\u27e9\n  | some a, some b := \u03bb h, let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between (coe_lt_coe.1 h) in\n    \u27e8a, coe_lt_coe.2 ha\u2081, coe_lt_coe.2 ha\u2082\u27e9\n  end\u27e9\n\nlemma lt_iff_exists_coe_btwn [preorder \u03b1] [densely_ordered \u03b1] [no_min_order \u03b1] {a b : with_bot \u03b1} :\n  a < b \u2194 \u2203 x : \u03b1, a < \u2191x \u2227 \u2191x < b :=\n\u27e8\u03bb h, let \u27e8y, hy\u27e9 := exists_between h, \u27e8x, hx\u27e9 := lt_iff_exists_coe.1 hy.1 in \u27e8x, hx.1 \u25b8 hy\u27e9,\n \u03bb \u27e8x, hx\u27e9, lt_trans hx.1 hx.2\u27e9\n\ninstance [has_le \u03b1] [no_top_order \u03b1] [nonempty \u03b1] : no_top_order (with_bot \u03b1) :=\n\u27e8begin\n  apply rec_bot_coe,\n  { exact \u2039nonempty \u03b1\u203a.elim (\u03bb a, \u27e8a, not_coe_le_bot a\u27e9) },\n  { intro a,\n    obtain \u27e8b, h\u27e9 := exists_not_le a,\n    exact \u27e8b, by rwa coe_le_coe\u27e9 }\nend\u27e9\n\ninstance [has_lt \u03b1] [no_max_order \u03b1] [nonempty \u03b1] : no_max_order (with_bot \u03b1) :=\n\u27e8begin\n  apply with_bot.rec_bot_coe,\n  { apply \u2039nonempty \u03b1\u203a.elim,\n    exact \u03bb a, \u27e8a, with_bot.bot_lt_coe a\u27e9, },\n  { intro a,\n    obtain \u27e8b, ha\u27e9 := exists_gt a,\n    exact \u27e8b, with_bot.coe_lt_coe.mpr ha\u27e9, }\nend\u27e9\n\nend with_bot\n\n--TODO(Mario): Construct using order dual on with_bot\n/-- Attach `\u22a4` to a type. -/\ndef with_top (\u03b1 : Type*) := option \u03b1\n\nnamespace with_top\nvariables {a b : \u03b1}\n\nmeta instance [has_to_format \u03b1] : has_to_format (with_top \u03b1) :=\n{ to_format := \u03bb x,\n  match x with\n  | none := \"\u22a4\"\n  | (some x) := to_fmt x\n  end }\n\ninstance [has_repr \u03b1] : has_repr (with_top \u03b1) :=\n\u27e8\u03bb o, match o with | none := \"\u22a4\" | (some a) := \"\u2191\" ++ repr a end\u27e9\n\ninstance : has_coe_t \u03b1 (with_top \u03b1) := \u27e8some\u27e9\ninstance : has_top (with_top \u03b1) := \u27e8none\u27e9\n\nmeta instance {\u03b1 : Type} [reflected _ \u03b1] [has_reflect \u03b1] : has_reflect (with_top \u03b1)\n| \u22a4 := `(\u22a4)\n| (a : \u03b1) := `(coe : \u03b1 \u2192 with_top \u03b1).subst `(a)\n\ninstance : inhabited (with_top \u03b1) := \u27e8\u22a4\u27e9\n\nlemma none_eq_top : (none : with_top \u03b1) = (\u22a4 : with_top \u03b1) := rfl\nlemma some_eq_coe (a : \u03b1) : (some a : with_top \u03b1) = (\u2191a : with_top \u03b1) := rfl\n\n@[simp] lemma top_ne_coe : \u22a4 \u2260 (a : with_top \u03b1) .\n@[simp] lemma coe_ne_top : (a : with_top \u03b1) \u2260 \u22a4 .\n\n/-- Recursor for `with_top` using the preferred forms `\u22a4` and `\u2191a`. -/\n@[elab_as_eliminator]\ndef rec_top_coe {C : with_top \u03b1 \u2192 Sort*} (h\u2081 : C \u22a4) (h\u2082 : \u03a0 (a : \u03b1), C a) :\n  \u03a0 (n : with_top \u03b1), C n :=\noption.rec h\u2081 h\u2082\n\n@[norm_cast] lemma coe_eq_coe : (a : with_top \u03b1) = b \u2194 a = b := option.some_inj\n\n/-- Lift a map `f : \u03b1 \u2192 \u03b2` to `with_top \u03b1 \u2192 with_top \u03b2`. Implemented using `option.map`. -/\ndef map (f : \u03b1 \u2192 \u03b2) : with_top \u03b1 \u2192 with_top \u03b2 := option.map f\n\n@[simp] lemma map_top (f : \u03b1 \u2192 \u03b2) : map f \u22a4 = \u22a4 := rfl\n@[simp] lemma map_coe (f : \u03b1 \u2192 \u03b2) (a : \u03b1) : map f a = f a := rfl\n\nlemma ne_top_iff_exists {x : with_top \u03b1} : x \u2260 \u22a4 \u2194 \u2203 (a : \u03b1), \u2191a = x := option.ne_none_iff_exists\n\n/-- Deconstruct a `x : with_top \u03b1` to the underlying value in `\u03b1`, given a proof that `x \u2260 \u22a4`. -/\ndef untop : \u03a0 (x : with_top \u03b1), x \u2260 \u22a4 \u2192 \u03b1 :=\nwith_bot.unbot\n\n@[simp] lemma coe_untop (x : with_top \u03b1) (h : x \u2260 \u22a4) : (x.untop h : with_top \u03b1) = x :=\nwith_bot.coe_unbot x h\n\n@[simp] lemma untop_coe (x : \u03b1) (h : (x : with_top \u03b1) \u2260 \u22a4 := coe_ne_top) :\n  (x : with_top \u03b1).untop h = x := rfl\n\ninstance : can_lift (with_top \u03b1) \u03b1 :=\n{ coe := coe,\n  cond := \u03bb r, r \u2260 \u22a4,\n  prf := \u03bb x h, \u27e8x.untop h, coe_untop _ _\u27e9 }\n\nsection has_le\nvariables [has_le \u03b1]\n\n@[priority 10]\ninstance : has_le (with_top \u03b1) := \u27e8\u03bb o\u2081 o\u2082 : option \u03b1, \u2200 a \u2208 o\u2082, \u2203 b \u2208 o\u2081, b \u2264 a\u27e9\n\n@[simp] lemma some_le_some : @has_le.le (with_top \u03b1) _ (some a) (some b) \u2194 a \u2264 b := by simp [(\u2264)]\n@[simp, norm_cast] lemma coe_le_coe : (a : with_top \u03b1) \u2264 b \u2194 a \u2264 b := some_le_some\n\n@[simp] lemma le_none {a : with_top \u03b1} : @has_le.le (with_top \u03b1) _ a none :=\n\u03bb b h, option.no_confusion h\n\ninstance : order_top (with_top \u03b1) := { le_top := \u03bb a, le_none, .. with_top.has_top }\n\ninstance [order_bot \u03b1] : order_bot (with_top \u03b1) :=\n{ bot := some \u22a5,\n  bot_le := \u03bb o a ha, by cases ha; exact \u27e8_, rfl, bot_le\u27e9 }\n\ninstance [order_bot \u03b1] : bounded_order (with_top \u03b1) :=\n{ ..with_top.order_top, ..with_top.order_bot }\n\nlemma not_top_le_coe (a : \u03b1) : \u00ac (\u22a4 : with_top \u03b1) \u2264 \u2191a := with_bot.not_coe_le_bot (to_dual a)\n\nlemma le_coe : \u2200 {o : option \u03b1}, a \u2208 o \u2192 (@has_le.le (with_top \u03b1) _ o b \u2194 a \u2264 b) | _ rfl :=\ncoe_le_coe\n\nlemma le_coe_iff : \u2200 {x : with_top \u03b1}, x \u2264 b \u2194 \u2203 a : \u03b1, x = a \u2227 a \u2264 b\n| (some a) := by simp [some_eq_coe, coe_eq_coe]\n| none     := iff_of_false (not_top_le_coe _) $ by simp [none_eq_top]\n\nlemma coe_le_iff : \u2200 {x : with_top \u03b1}, \u2191a \u2264 x \u2194 \u2200 b, x = \u2191b \u2192 a \u2264 b\n| (some b) := by simp [some_eq_coe, coe_eq_coe]\n| none     := by simp [none_eq_top]\n\nprotected lemma _root_.is_min.with_top (h : is_min a) : is_min (a : with_top \u03b1)\n| none _ := le_top\n| (some b) hb := some_le_some.2 $ h $ some_le_some.1 hb\n\nend has_le\n\nsection has_lt\nvariables [has_lt \u03b1]\n\n@[priority 10]\ninstance : has_lt (with_top \u03b1) := \u27e8\u03bb o\u2081 o\u2082 : option \u03b1, \u2203 b \u2208 o\u2081, \u2200 a \u2208 o\u2082, b < a\u27e9\n\n@[simp] lemma some_lt_some : @has_lt.lt (with_top \u03b1) _ (some a) (some b) \u2194 a < b := by simp [(<)]\n@[simp, norm_cast] lemma coe_lt_coe : (a : with_top \u03b1) < b \u2194 a < b := some_lt_some\n\n@[simp] lemma some_lt_none (a : \u03b1) : @has_lt.lt (with_top \u03b1) _ (some a) none :=\n\u27e8a, rfl, \u03bb b hb, (option.not_mem_none _ hb).elim\u27e9\nlemma coe_lt_top (a : \u03b1) : (a : with_top \u03b1) < \u22a4 := some_lt_none a\n\n@[simp] lemma not_none_lt (a : with_top \u03b1) : \u00ac @has_lt.lt (with_top \u03b1) _ none a :=\n\u03bb \u27e8_, h, _\u27e9, option.not_mem_none _ h\n\nlemma lt_iff_exists_coe : \u2200 {a b : with_top \u03b1}, a < b \u2194 \u2203 p : \u03b1, a = p \u2227 \u2191p < b\n| (some a) b := by simp [some_eq_coe, coe_eq_coe]\n| none     b := iff_of_false (not_none_lt _) $ by simp [none_eq_top]\n\nlemma coe_lt_iff : \u2200 {x : with_top \u03b1}, \u2191a < x \u2194 \u2200 b, x = \u2191b \u2192 a < b\n| (some b) := by simp [some_eq_coe, coe_eq_coe, coe_lt_coe]\n| none     := by simp [none_eq_top, coe_lt_top]\n\nend has_lt\n\ninstance [preorder \u03b1] : preorder (with_top \u03b1) :=\n{ le          := (\u2264),\n  lt          := (<),\n  lt_iff_le_not_le := by { intros, cases a; cases b; simp [lt_iff_le_not_le]; simp [(<), (\u2264)] },\n  le_refl     := \u03bb o a ha, \u27e8a, ha, le_rfl\u27e9,\n  le_trans    := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 c hc,\n    let \u27e8b, hb, bc\u27e9 := h\u2082 c hc, \u27e8a, ha, ab\u27e9 := h\u2081 b hb in\n    \u27e8a, ha, le_trans ab bc\u27e9 }\n\ninstance [partial_order \u03b1] : partial_order (with_top \u03b1) :=\n{ le_antisymm := \u03bb o\u2081 o\u2082 h\u2081 h\u2082, begin\n    cases o\u2082 with b,\n    { cases o\u2081 with a, {refl},\n      rcases h\u2082 a rfl with \u27e8_, \u27e8\u27e9, _\u27e9 },\n    { rcases h\u2081 b rfl with \u27e8a, \u27e8\u27e9, h\u2081'\u27e9,\n      rcases h\u2082 a rfl with \u27e8_, \u27e8\u27e9, h\u2082'\u27e9,\n      rw le_antisymm h\u2081' h\u2082' }\n  end,\n  .. with_top.preorder }\n\ninstance [semilattice_inf \u03b1] : semilattice_inf (with_top \u03b1) :=\n{ inf          := option.lift_or_get (\u2293),\n  inf_le_left  := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2082; simp [option.lift_or_get],\n  inf_le_right := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2081; simp [option.lift_or_get],\n  le_inf       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases o\u2082 with b; cases o\u2083 with c; cases ha,\n    { exact h\u2082 a rfl },\n    { exact h\u2081 a rfl },\n    { rcases h\u2081 b rfl with \u27e8d, \u27e8\u27e9, h\u2081'\u27e9,\n      simp at h\u2082,\n      exact \u27e8d, rfl, le_inf h\u2081' h\u2082\u27e9 }\n  end,\n  ..with_top.partial_order }\n\nlemma coe_inf [semilattice_inf \u03b1] (a b : \u03b1) : ((a \u2293 b : \u03b1) : with_top \u03b1) = a \u2293 b := rfl\n\ninstance [semilattice_sup \u03b1] : semilattice_sup (with_top \u03b1) :=\n{ sup          := \u03bb o\u2081 o\u2082, o\u2081.bind (\u03bb a, o\u2082.map (\u03bb b, a \u2294 b)),\n  le_sup_left  := \u03bb o\u2081 o\u2082 a ha, begin\n    simp [map] at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, le_sup_left\u27e9\n  end,\n  le_sup_right := \u03bb o\u2081 o\u2082 a ha, begin\n    simp [map] at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, le_sup_right\u27e9\n  end,\n  sup_le       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases ha,\n    rcases h\u2081 a rfl with \u27e8b, \u27e8\u27e9, ab\u27e9,\n    rcases h\u2082 a rfl with \u27e8c, \u27e8\u27e9, ac\u27e9,\n    exact \u27e8_, rfl, sup_le ab ac\u27e9\n  end,\n  ..with_top.partial_order }\n\nlemma coe_sup [semilattice_sup \u03b1] (a b : \u03b1) : ((a \u2294 b : \u03b1) : with_top \u03b1) = a \u2294 b := rfl\n\ninstance [lattice \u03b1] : lattice (with_top \u03b1) :=\n{ ..with_top.semilattice_sup, ..with_top.semilattice_inf }\n\ninstance decidable_le [has_le \u03b1] [@decidable_rel \u03b1 (\u2264)] : @decidable_rel (with_top \u03b1) (\u2264) :=\n\u03bb x y, @with_bot.decidable_le \u03b1\u1d52\u1d48 _ _ y x\n\ninstance decidable_lt [has_lt \u03b1] [@decidable_rel \u03b1 (<)] : @decidable_rel (with_top \u03b1) (<) :=\n\u03bb x y, @with_bot.decidable_lt \u03b1\u1d52\u1d48 _ _ y x\n\ninstance is_total_le [has_le \u03b1] [is_total \u03b1 (\u2264)] : is_total (with_top \u03b1) (\u2264) :=\n@order_dual.is_total_le (with_bot \u03b1\u1d52\u1d48) _ _\n\ninstance [linear_order \u03b1] : linear_order (with_top \u03b1) := lattice.to_linear_order _\n\n@[simp, norm_cast]\nlemma coe_min [linear_order \u03b1] (x y : \u03b1) : (\u2191(min x y) : with_top \u03b1) = min x y := rfl\n\n@[simp, norm_cast]\nlemma coe_max [linear_order \u03b1] (x y : \u03b1) : (\u2191(max x y) : with_top \u03b1) = max x y := rfl\n\nlemma well_founded_lt [preorder \u03b1] (h : @well_founded \u03b1 (<)) : @well_founded (with_top \u03b1) (<) :=\nhave acc_some : \u2200 a : \u03b1, acc ((<) : with_top \u03b1 \u2192 with_top \u03b1 \u2192 Prop) (some a) :=\n\u03bb a, acc.intro _ (well_founded.induction h a\n  (show \u2200 b, (\u2200 c, c < b \u2192 \u2200 d : with_top \u03b1, d < some c \u2192 acc (<) d) \u2192\n    \u2200 y : with_top \u03b1, y < some b \u2192 acc (<) y,\n  from \u03bb b ih c, option.rec_on c (\u03bb hc, (not_lt_of_ge le_top hc).elim)\n    (\u03bb c hc, acc.intro _ (ih _ (some_lt_some.1 hc))))),\n\u27e8\u03bb a, option.rec_on a (acc.intro _ (\u03bb y, option.rec_on y (\u03bb h, (lt_irrefl _ h).elim)\n  (\u03bb _ _, acc_some _))) acc_some\u27e9\n\nlemma well_founded_gt [preorder \u03b1] (h : @well_founded \u03b1 (>)) : @well_founded (with_top \u03b1) (>) :=\n@with_bot.well_founded_lt \u03b1\u1d52\u1d48 _ h\n\nlemma _root_.with_bot.well_founded_gt [preorder \u03b1] (h : @well_founded \u03b1 (>)) :\n  @well_founded (with_bot \u03b1) (>) :=\n@with_top.well_founded_lt \u03b1\u1d52\u1d48 _ h\n\ninstance [has_lt \u03b1] [densely_ordered \u03b1] [no_max_order \u03b1] : densely_ordered (with_top \u03b1) :=\norder_dual.densely_ordered (with_bot \u03b1\u1d52\u1d48)\n\nlemma lt_iff_exists_coe_btwn [preorder \u03b1] [densely_ordered \u03b1] [no_max_order \u03b1] {a b : with_top \u03b1} :\n  a < b \u2194 \u2203 x : \u03b1, a < \u2191x \u2227 \u2191x < b :=\n\u27e8\u03bb h, let \u27e8y, hy\u27e9 := exists_between h, \u27e8x, hx\u27e9 := lt_iff_exists_coe.1 hy.2 in \u27e8x, hx.1 \u25b8 hy\u27e9,\n \u03bb \u27e8x, hx\u27e9, lt_trans hx.1 hx.2\u27e9\n\ninstance [has_le \u03b1] [no_bot_order \u03b1] [nonempty \u03b1] : no_bot_order (with_top \u03b1) :=\norder_dual.no_bot_order (with_bot \u03b1\u1d52\u1d48)\n\ninstance [has_lt \u03b1] [no_min_order \u03b1] [nonempty \u03b1] : no_min_order (with_top \u03b1) :=\norder_dual.no_min_order (with_bot \u03b1\u1d52\u1d48)\n\nend with_top\n\nsection mono\n\nvariables [preorder \u03b1] [preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n\nprotected lemma monotone.with_bot_map (hf : monotone f) : monotone (with_bot.map f)\n| \u22a5       _       h := bot_le\n| (a : \u03b1) \u22a5       h := (with_bot.not_coe_le_bot _ h).elim\n| (a : \u03b1) (b : \u03b1) h := with_bot.coe_le_coe.2 (hf (with_bot.coe_le_coe.1 h))\n\nprotected lemma monotone.with_top_map (hf : monotone f) : monotone (with_top.map f) :=\nhf.dual.with_bot_map.dual\n\nprotected lemma strict_mono.with_bot_map (hf : strict_mono f) : strict_mono (with_bot.map f)\n| \u22a5       (a : \u03b1) h := with_bot.bot_lt_coe _\n| (a : \u03b1) (b : \u03b1) h := with_bot.coe_lt_coe.mpr (hf $ with_bot.coe_lt_coe.mp h)\n\nprotected lemma strict_mono.with_top_map (hf : strict_mono f) : strict_mono (with_top.map f) :=\nhf.dual.with_bot_map.dual\n\nend mono\n\n/-! ### Subtype, order dual, product lattices -/\n\nnamespace subtype\nvariables {p : \u03b1 \u2192 Prop}\n\n/-- A subtype remains a `\u22a5`-order if the property holds at `\u22a5`. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def order_bot [has_le \u03b1] [order_bot \u03b1] (hbot : p \u22a5) : order_bot {x : \u03b1 // p x} :=\n{ bot := \u27e8\u22a5, hbot\u27e9,\n  bot_le := \u03bb _, bot_le }\n\n/-- A subtype remains a `\u22a4`-order if the property holds at `\u22a4`. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def order_top [has_le \u03b1] [order_top \u03b1] (htop : p \u22a4) : order_top {x : \u03b1 // p x} :=\n{ top := \u27e8\u22a4, htop\u27e9,\n  le_top := \u03bb _, le_top }\n\n/-- A subtype remains a bounded order if the property holds at `\u22a5` and `\u22a4`. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def bounded_order [has_le \u03b1] [bounded_order \u03b1] (hbot : p \u22a5) (htop : p \u22a4) :\n  bounded_order (subtype p) :=\n{ ..subtype.order_top htop, ..subtype.order_bot hbot }\n\nvariables [partial_order \u03b1]\n\n@[simp] lemma mk_bot [order_bot \u03b1] [order_bot (subtype p)] (hbot : p \u22a5) : mk \u22a5 hbot = \u22a5 :=\nle_bot_iff.1 $ coe_le_coe.1 bot_le\n\n@[simp] lemma mk_top [order_top \u03b1] [order_top (subtype p)] (htop : p \u22a4) : mk \u22a4 htop = \u22a4 :=\ntop_le_iff.1 $ coe_le_coe.1 le_top\n\nlemma coe_bot [order_bot \u03b1] [order_bot (subtype p)] (hbot : p \u22a5) : ((\u22a5 : subtype p) : \u03b1) = \u22a5 :=\ncongr_arg coe (mk_bot hbot).symm\n\nlemma coe_top [order_top \u03b1] [order_top (subtype p)] (htop : p \u22a4) : ((\u22a4 : subtype p) : \u03b1) = \u22a4 :=\ncongr_arg coe (mk_top htop).symm\n\n@[simp] lemma coe_eq_bot_iff [order_bot \u03b1] [order_bot (subtype p)] (hbot : p \u22a5) {x : {x // p x}} :\n  (x : \u03b1) = \u22a5 \u2194 x = \u22a5 :=\nby rw [\u2190coe_bot hbot, ext_iff]\n\n@[simp] lemma coe_eq_top_iff [order_top \u03b1] [order_top (subtype p)] (htop : p \u22a4) {x : {x // p x}} :\n  (x : \u03b1) = \u22a4 \u2194 x = \u22a4 :=\nby rw [\u2190coe_top htop, ext_iff]\n\n@[simp] lemma mk_eq_bot_iff [order_bot \u03b1] [order_bot (subtype p)] (hbot : p \u22a5) {x : \u03b1} (hx : p x) :\n  (\u27e8x, hx\u27e9 : subtype p) = \u22a5 \u2194 x = \u22a5 :=\n(coe_eq_bot_iff hbot).symm\n\n@[simp] lemma mk_eq_top_iff [order_top \u03b1] [order_top (subtype p)] (htop : p \u22a4) {x : \u03b1} (hx : p x) :\n  (\u27e8x, hx\u27e9 : subtype p) = \u22a4 \u2194 x = \u22a4 :=\n(coe_eq_top_iff htop).symm\n\nend subtype\n\nnamespace prod\nvariables (\u03b1 \u03b2)\n\ninstance [has_top \u03b1] [has_top \u03b2] : has_top (\u03b1 \u00d7 \u03b2) := \u27e8\u27e8\u22a4, \u22a4\u27e9\u27e9\ninstance [has_bot \u03b1] [has_bot \u03b2] : has_bot (\u03b1 \u00d7 \u03b2) := \u27e8\u27e8\u22a5, \u22a5\u27e9\u27e9\n\ninstance [has_le \u03b1] [has_le \u03b2] [order_top \u03b1] [order_top \u03b2] : order_top (\u03b1 \u00d7 \u03b2) :=\n{ le_top := \u03bb a, \u27e8le_top, le_top\u27e9,\n  .. prod.has_top \u03b1 \u03b2 }\n\ninstance [has_le \u03b1] [has_le \u03b2] [order_bot \u03b1] [order_bot \u03b2] : order_bot (\u03b1 \u00d7 \u03b2) :=\n{ bot_le := \u03bb a, \u27e8bot_le, bot_le\u27e9,\n  .. prod.has_bot \u03b1 \u03b2 }\n\ninstance [has_le \u03b1] [has_le \u03b2] [bounded_order \u03b1] [bounded_order \u03b2] : bounded_order (\u03b1 \u00d7 \u03b2) :=\n{ .. prod.order_top \u03b1 \u03b2, .. prod.order_bot \u03b1 \u03b2 }\n\n\nend prod\n\nsection linear_order\nvariables [linear_order \u03b1]\n\n-- `simp` can prove these, so they shouldn't be simp-lemmas.\nlemma min_bot_left [order_bot \u03b1] (a : \u03b1) : min \u22a5 a = \u22a5 := bot_inf_eq\nlemma max_top_left [order_top \u03b1] (a : \u03b1) : max \u22a4 a = \u22a4 := top_sup_eq\nlemma min_top_left [order_top \u03b1] (a : \u03b1) : min \u22a4 a = a := top_inf_eq\nlemma max_bot_left [order_bot \u03b1] (a : \u03b1) : max \u22a5 a = a := bot_sup_eq\nlemma min_top_right [order_top \u03b1] (a : \u03b1) : min a \u22a4 = a := inf_top_eq\nlemma max_bot_right [order_bot \u03b1] (a : \u03b1) : max a \u22a5 = a := sup_bot_eq\nlemma min_bot_right [order_bot \u03b1] (a : \u03b1) : min a \u22a5 = \u22a5 := inf_bot_eq\nlemma max_top_right [order_top \u03b1] (a : \u03b1) : max a \u22a4 = \u22a4 := sup_top_eq\n\n@[simp] lemma min_eq_bot [order_bot \u03b1] {a b : \u03b1} : min a b = \u22a5 \u2194 a = \u22a5 \u2228 b = \u22a5 :=\nby simp only [\u2190inf_eq_min, \u2190le_bot_iff, inf_le_iff]\n\n@[simp] lemma max_eq_top [order_top \u03b1] {a b : \u03b1} : max a b = \u22a4 \u2194 a = \u22a4 \u2228 b = \u22a4 :=\n@min_eq_bot \u03b1\u1d52\u1d48 _ _ a b\n\n@[simp] lemma max_eq_bot [order_bot \u03b1] {a b : \u03b1} : max a b = \u22a5 \u2194 a = \u22a5 \u2227 b = \u22a5 := sup_eq_bot_iff\n@[simp] lemma min_eq_top [order_top \u03b1] {a b : \u03b1} : min a b = \u22a4 \u2194 a = \u22a4 \u2227 b = \u22a4 := inf_eq_top_iff\n\nend linear_order\n\n/-! ### Disjointness and complements -/\n\nsection disjoint\nsection semilattice_inf_bot\nvariables [semilattice_inf \u03b1] [order_bot \u03b1] {a b c d : \u03b1}\n\n/-- Two elements of a lattice are disjoint if their inf is the bottom element.\n  (This generalizes disjoint sets, viewed as members of the subset lattice.) -/\ndef disjoint (a b : \u03b1) : Prop := a \u2293 b \u2264 \u22a5\n\nlemma disjoint_iff : disjoint a b \u2194 a \u2293 b = \u22a5 := le_bot_iff\nlemma disjoint.eq_bot : disjoint a b \u2192 a \u2293 b = \u22a5 := bot_unique\nlemma disjoint.comm : disjoint a b \u2194 disjoint b a := by rw [disjoint, disjoint, inf_comm]\n@[symm] lemma disjoint.symm \u2983a b : \u03b1\u2984 : disjoint a b \u2192 disjoint b a := disjoint.comm.1\nlemma symmetric_disjoint : symmetric (disjoint : \u03b1 \u2192 \u03b1 \u2192 Prop) := disjoint.symm\nlemma disjoint_assoc : disjoint (a \u2293 b) c \u2194 disjoint a (b \u2293 c) :=\nby rw [disjoint, disjoint, inf_assoc]\n\n@[simp] lemma disjoint_bot_left : disjoint \u22a5 a := inf_le_left\n@[simp] lemma disjoint_bot_right : disjoint a \u22a5 := inf_le_right\n\nlemma disjoint.mono (h\u2081 : a \u2264 b) (h\u2082 : c \u2264 d) : disjoint b d \u2192 disjoint a c :=\nle_trans $ inf_le_inf h\u2081 h\u2082\n\nlemma disjoint.mono_left (h : a \u2264 b) : disjoint b c \u2192 disjoint a c := disjoint.mono h le_rfl\nlemma disjoint.mono_right : b \u2264 c \u2192 disjoint a c \u2192 disjoint a b := disjoint.mono le_rfl\n\nvariables (c)\n\nlemma disjoint.inf_left (h : disjoint a b) : disjoint (a \u2293 c) b := h.mono_left inf_le_left\nlemma disjoint.inf_left' (h : disjoint a b) : disjoint (c \u2293 a) b := h.mono_left inf_le_right\nlemma disjoint.inf_right (h : disjoint a b) : disjoint a (b \u2293 c) := h.mono_right inf_le_left\nlemma disjoint.inf_right' (h : disjoint a b) : disjoint a (c \u2293 b) := h.mono_right inf_le_right\n\nvariables {c}\n\n@[simp] lemma disjoint_self : disjoint a a \u2194 a = \u22a5 := by simp [disjoint]\n\n/- TODO: Rename `disjoint.eq_bot` to `disjoint.inf_eq` and `disjoint.eq_bot_of_self` to\n`disjoint.eq_bot` -/\nalias disjoint_self \u2194 disjoint.eq_bot_of_self _\n\nlemma disjoint.ne (ha : a \u2260 \u22a5) (hab : disjoint a b) : a \u2260 b :=\n\u03bb h, ha $ disjoint_self.1 $ by rwa \u2190h at hab\n\nlemma disjoint.eq_bot_of_le (hab : disjoint a b) (h : a \u2264 b) : a = \u22a5 :=\neq_bot_iff.2 (by rwa \u2190inf_eq_left.2 h)\n\nlemma disjoint.eq_bot_of_ge (hab : disjoint a b) : b \u2264 a \u2192 b = \u22a5 := hab.symm.eq_bot_of_le\n\nlemma disjoint.of_disjoint_inf_of_le (h : disjoint (a \u2293 b) c) (hle : a \u2264 c) : disjoint a b :=\ndisjoint_iff.2 $ h.eq_bot_of_le $ inf_le_of_left_le hle\n\nlemma disjoint.of_disjoint_inf_of_le' (h : disjoint (a \u2293 b) c) (hle : b \u2264 c) : disjoint a b :=\ndisjoint_iff.2 $ h.eq_bot_of_le $ inf_le_of_right_le hle\n\nend semilattice_inf_bot\n\nsection lattice\nvariables [lattice \u03b1] [bounded_order \u03b1] {a : \u03b1}\n\n@[simp] theorem disjoint_top : disjoint a \u22a4 \u2194 a = \u22a5 := by simp [disjoint_iff]\n@[simp] theorem top_disjoint : disjoint \u22a4 a \u2194 a = \u22a5 := by simp [disjoint_iff]\n\nend lattice\n\nsection distrib_lattice_bot\nvariables [distrib_lattice \u03b1] [order_bot \u03b1] {a b c : \u03b1}\n\n@[simp] lemma disjoint_sup_left : disjoint (a \u2294 b) c \u2194 disjoint a c \u2227 disjoint b c :=\nby simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff]\n\n@[simp] lemma disjoint_sup_right : disjoint a (b \u2294 c) \u2194 disjoint a b \u2227 disjoint a c :=\nby simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff]\n\nlemma disjoint.sup_left (ha : disjoint a c) (hb : disjoint b c) : disjoint (a \u2294 b) c :=\ndisjoint_sup_left.2 \u27e8ha, hb\u27e9\n\nlemma disjoint.sup_right (hb : disjoint a b) (hc : disjoint a c) : disjoint a (b \u2294 c) :=\ndisjoint_sup_right.2 \u27e8hb, hc\u27e9\n\nlemma disjoint.left_le_of_le_sup_right (h : a \u2264 b \u2294 c) (hd : disjoint a c) : a \u2264 b :=\nle_of_inf_le_sup_le (le_trans hd bot_le) $ sup_le h le_sup_right\n\nlemma disjoint.left_le_of_le_sup_left (h : a \u2264 c \u2294 b) (hd : disjoint a c) : a \u2264 b :=\nhd.left_le_of_le_sup_right $ by rwa sup_comm\n\nend distrib_lattice_bot\nend disjoint\n\nsection is_compl\n\n/-- Two elements `x` and `y` are complements of each other if `x \u2294 y = \u22a4` and `x \u2293 y = \u22a5`. -/\nstructure is_compl [lattice \u03b1] [bounded_order \u03b1] (x y : \u03b1) : Prop :=\n(inf_le_bot : x \u2293 y \u2264 \u22a5)\n(top_le_sup : \u22a4 \u2264 x \u2294 y)\n\nnamespace is_compl\n\nsection bounded_order\n\nvariables [lattice \u03b1] [bounded_order \u03b1] {x y z : \u03b1}\n\nprotected lemma disjoint (h : is_compl x y) : disjoint x y := h.1\n\n@[symm] protected lemma symm (h : is_compl x y) : is_compl y x :=\n\u27e8by { rw inf_comm, exact h.1 }, by { rw sup_comm, exact h.2 }\u27e9\n\nlemma of_eq (h\u2081 : x \u2293 y = \u22a5) (h\u2082 : x \u2294 y = \u22a4) : is_compl x y := \u27e8h\u2081.le, h\u2082.ge\u27e9\n\nlemma inf_eq_bot (h : is_compl x y) : x \u2293 y = \u22a5 := h.disjoint.eq_bot\n\nlemma sup_eq_top (h : is_compl x y) : x \u2294 y = \u22a4 := top_unique h.top_le_sup\n\nlemma dual (h : is_compl x y) : is_compl (to_dual x) (to_dual y) := \u27e8h.2, h.1\u27e9\nlemma of_dual {a b : \u03b1\u1d52\u1d48} (h : is_compl a b) : is_compl (of_dual a) (of_dual b) := \u27e8h.2, h.1\u27e9\n\nend bounded_order\n\nvariables [distrib_lattice \u03b1] [bounded_order \u03b1] {a b x y z : \u03b1}\n\nlemma inf_left_le_of_le_sup_right (h : is_compl x y) (hle : a \u2264 b \u2294 y) : a \u2293 x \u2264 b :=\ncalc a \u2293 x \u2264 (b \u2294 y) \u2293 x : inf_le_inf hle le_rfl\n... = (b \u2293 x) \u2294 (y \u2293 x) : inf_sup_right\n... = b \u2293 x : by rw [h.symm.inf_eq_bot, sup_bot_eq]\n... \u2264 b : inf_le_left\n\nlemma le_sup_right_iff_inf_left_le {a b} (h : is_compl x y) : a \u2264 b \u2294 y \u2194 a \u2293 x \u2264 b :=\n\u27e8h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right\u27e9\n\nlemma inf_left_eq_bot_iff (h : is_compl y z) : x \u2293 y = \u22a5 \u2194 x \u2264 z :=\nby rw [\u2190 le_bot_iff, \u2190 h.le_sup_right_iff_inf_left_le, bot_sup_eq]\n\nlemma inf_right_eq_bot_iff (h : is_compl y z) : x \u2293 z = \u22a5 \u2194 x \u2264 y :=\nh.symm.inf_left_eq_bot_iff\n\nlemma disjoint_left_iff (h : is_compl y z) : disjoint x y \u2194 x \u2264 z :=\nby { rw disjoint_iff, exact h.inf_left_eq_bot_iff }\n\nlemma disjoint_right_iff (h : is_compl y z) : disjoint x z \u2194 x \u2264 y :=\nh.symm.disjoint_left_iff\n\nlemma le_left_iff (h : is_compl x y) : z \u2264 x \u2194 disjoint z y :=\nh.disjoint_right_iff.symm\n\nlemma le_right_iff (h : is_compl x y) : z \u2264 y \u2194 disjoint z x :=\nh.symm.le_left_iff\n\nlemma left_le_iff (h : is_compl x y) : x \u2264 z \u2194 \u22a4 \u2264 z \u2294 y := h.dual.le_left_iff\n\nlemma right_le_iff (h : is_compl x y) : y \u2264 z \u2194 \u22a4 \u2264 z \u2294 x :=\nh.symm.left_le_iff\n\nprotected lemma antitone {x' y'} (h : is_compl x y) (h' : is_compl x' y') (hx : x \u2264 x') :\n  y' \u2264 y :=\nh'.right_le_iff.2 $ le_trans h.symm.top_le_sup (sup_le_sup_left hx _)\n\nlemma right_unique (hxy : is_compl x y) (hxz : is_compl x z) :\n  y = z :=\nle_antisymm (hxz.antitone hxy $ le_refl x) (hxy.antitone hxz $ le_refl x)\n\nlemma left_unique (hxz : is_compl x z) (hyz : is_compl y z) :\n  x = y :=\nhxz.symm.right_unique hyz.symm\n\nlemma sup_inf {x' y'} (h : is_compl x y) (h' : is_compl x' y') :\n  is_compl (x \u2294 x') (y \u2293 y') :=\nof_eq\n  (by rw [inf_sup_right, \u2190 inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm,\n    h'.inf_eq_bot, inf_bot_eq])\n  (by rw [sup_inf_left, @sup_comm _ _ x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq,\n    sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq])\n\nlemma inf_sup {x' y'} (h : is_compl x y) (h' : is_compl x' y') :\n  is_compl (x \u2293 x') (y \u2294 y') :=\n(h.symm.sup_inf h'.symm).symm\n\nend is_compl\n\nsection\nvariables [lattice \u03b1] [bounded_order \u03b1] {a b x : \u03b1}\n\n@[simp] lemma is_compl_to_dual_iff : is_compl (to_dual a) (to_dual b) \u2194 is_compl a b :=\n\u27e8is_compl.of_dual, is_compl.dual\u27e9\n\n@[simp] lemma is_compl_of_dual_iff {a b : \u03b1\u1d52\u1d48} : is_compl (of_dual a) (of_dual b) \u2194 is_compl a b :=\n\u27e8is_compl.dual, is_compl.of_dual\u27e9\n\nlemma is_compl_bot_top : is_compl (\u22a5 : \u03b1) \u22a4 := is_compl.of_eq bot_inf_eq sup_top_eq\nlemma is_compl_top_bot : is_compl (\u22a4 : \u03b1) \u22a5 := is_compl.of_eq inf_bot_eq top_sup_eq\n\nlemma eq_top_of_is_compl_bot (h : is_compl x \u22a5) : x = \u22a4 := sup_bot_eq.symm.trans h.sup_eq_top\nlemma eq_top_of_bot_is_compl (h : is_compl \u22a5 x) : x = \u22a4 := eq_top_of_is_compl_bot h.symm\nlemma eq_bot_of_is_compl_top (h : is_compl x \u22a4) : x = \u22a5 := eq_top_of_is_compl_bot h.dual\nlemma eq_bot_of_top_is_compl (h : is_compl \u22a4 x) : x = \u22a5 := eq_top_of_bot_is_compl h.dual\n\nend\n\n/-- A complemented bounded lattice is one where every element has a (not necessarily unique)\ncomplement. -/\nclass is_complemented (\u03b1) [lattice \u03b1] [bounded_order \u03b1] : Prop :=\n(exists_is_compl : \u2200 (a : \u03b1), \u2203 (b : \u03b1), is_compl a b)\n\nexport is_complemented (exists_is_compl)\n\nnamespace is_complemented\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_complemented \u03b1]\n\ninstance : is_complemented \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a, let \u27e8b, hb\u27e9 := exists_is_compl (show \u03b1, from a) in \u27e8b, hb.dual\u27e9\u27e9\n\nend is_complemented\n\nend is_compl\n\nsection nontrivial\n\nvariables [partial_order \u03b1] [bounded_order \u03b1] [nontrivial \u03b1]\n\nlemma bot_ne_top : (\u22a5 : \u03b1) \u2260 \u22a4 :=\n\u03bb H, not_nontrivial_iff_subsingleton.mpr (subsingleton_of_bot_eq_top H) \u2039_\u203a\n\nlemma top_ne_bot : (\u22a4 : \u03b1) \u2260 \u22a5 := bot_ne_top.symm\nlemma bot_lt_top : (\u22a5 : \u03b1) < \u22a4 := lt_top_iff_ne_top.2 bot_ne_top\n\nend nontrivial\n\nsection bool\nopen bool\n\ninstance : bounded_order bool :=\n{ top := tt,\n  le_top := \u03bb x, le_tt,\n  bot := ff,\n  bot_le := \u03bb x, ff_le }\n\n@[simp] lemma top_eq_tt : \u22a4 = tt := rfl\n@[simp] lemma bot_eq_ff : \u22a5 = ff := rfl\n\nend bool\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/bounded_order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7118335159826783}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n\n! This file was ported from Lean 3 source module algebra.algebraic_card\n! leanprover-community/mathlib commit 40494fe75ecbd6d2ec61711baa630cf0a7b7d064\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Polynomial.Cardinal\nimport Mathbin.RingTheory.Algebraic\n\n/-!\n### Cardinality of algebraic numbers\n\nIn this file, we prove variants of the following result: the cardinality of algebraic numbers under\nan R-algebra is at most `# R[X] * \u2135\u2080`.\n\nAlthough this can be used to prove that real or complex transcendental numbers exist, a more direct\nproof is given by `liouville.is_transcendental`.\n-/\n\n\nuniverse u v\n\nopen Cardinal Polynomial Set\n\nopen Cardinal Polynomial\n\nnamespace Algebraic\n\ntheorem infinite_of_charZero (R A : Type _) [CommRing R] [IsDomain R] [Ring A] [Algebra R A]\n    [CharZero A] : { x : A | IsAlgebraic R x }.Infinite :=\n  infinite_of_injective_forall_mem Nat.cast_injective isAlgebraic_nat\n#align algebraic.infinite_of_char_zero Algebraic.infinite_of_charZero\n\ntheorem aleph0_le_cardinal_mk_of_charZero (R A : Type _) [CommRing R] [IsDomain R] [Ring A]\n    [Algebra R A] [CharZero A] : \u2135\u2080 \u2264 (#{ x : A // IsAlgebraic R x }) :=\n  infinite_iff.1 (Set.infinite_coe_iff.2 <| infinite_of_charZero R A)\n#align algebraic.aleph_0_le_cardinal_mk_of_char_zero Algebraic.aleph0_le_cardinal_mk_of_charZero\n\nsection lift\n\nvariable (R : Type u) (A : Type v) [CommRing R] [CommRing A] [IsDomain A] [Algebra R A]\n  [NoZeroSMulDivisors R A]\n\ntheorem cardinal_mk_lift_le_mul :\n    Cardinal.lift.{u} (#{ x : A // IsAlgebraic R x }) \u2264 Cardinal.lift.{v} (#R[X]) * \u2135\u2080 :=\n  by\n  rw [\u2190 mk_ulift, \u2190 mk_ulift]\n  choose g hg\u2081 hg\u2082 using fun x : { x : A | IsAlgebraic R x } => x.coe_prop\n  refine' lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le g fun f => _\n  rw [lift_le_aleph_0, le_aleph_0_iff_set_countable]\n  suffices : maps_to coe (g \u207b\u00b9' {f}) (f.root_set A)\n  exact this.countable_of_inj_on (subtype.coe_injective.inj_on _) (f.root_set_finite A).Countable\n  rintro x (rfl : g x = f)\n  exact mem_root_set.2 \u27e8hg\u2081 x, hg\u2082 x\u27e9\n#align algebraic.cardinal_mk_lift_le_mul Algebraic.cardinal_mk_lift_le_mul\n\ntheorem cardinal_mk_lift_le_max :\n    Cardinal.lift.{u} (#{ x : A // IsAlgebraic R x }) \u2264 max (Cardinal.lift.{v} (#R)) \u2135\u2080 :=\n  (cardinal_mk_lift_le_mul R A).trans <|\n    (mul_le_mul_right' (lift_le.2 cardinal_mk_le_max) _).trans <| by simp\n#align algebraic.cardinal_mk_lift_le_max Algebraic.cardinal_mk_lift_le_max\n\n@[simp]\ntheorem cardinal_mk_lift_of_infinite [Infinite R] :\n    Cardinal.lift.{u} (#{ x : A // IsAlgebraic R x }) = Cardinal.lift.{v} (#R) :=\n  ((cardinal_mk_lift_le_max R A).trans_eq (max_eq_left <| aleph0_le_mk _)).antisymm <|\n    lift_mk_le'.2\n      \u27e8\u27e8fun x => \u27e8algebraMap R A x, isAlgebraic_algebraMap _\u27e9, fun x y h =>\n          NoZeroSMulDivisors.algebraMap_injective R A (Subtype.ext_iff.1 h)\u27e9\u27e9\n#align algebraic.cardinal_mk_lift_of_infinite Algebraic.cardinal_mk_lift_of_infinite\n\nvariable [Countable R]\n\n@[simp]\nprotected theorem countable : Set.Countable { x : A | IsAlgebraic R x } :=\n  by\n  rw [\u2190 le_aleph_0_iff_set_countable, \u2190 lift_le]\n  apply (cardinal_mk_lift_le_max R A).trans\n  simp\n#align algebraic.countable Algebraic.countable\n\n@[simp]\ntheorem cardinal_mk_of_countble_of_charZero [CharZero A] [IsDomain R] :\n    (#{ x : A // IsAlgebraic R x }) = \u2135\u2080 :=\n  (Algebraic.countable R A).le_aleph0.antisymm (aleph0_le_cardinal_mk_of_charZero R A)\n#align algebraic.cardinal_mk_of_countble_of_char_zero Algebraic.cardinal_mk_of_countble_of_charZero\n\nend lift\n\nsection NonLift\n\nvariable (R A : Type u) [CommRing R] [CommRing A] [IsDomain A] [Algebra R A]\n  [NoZeroSMulDivisors R A]\n\ntheorem cardinal_mk_le_mul : (#{ x : A // IsAlgebraic R x }) \u2264 (#R[X]) * \u2135\u2080 :=\n  by\n  rw [\u2190 lift_id (#_), \u2190 lift_id (#R[X])]\n  exact cardinal_mk_lift_le_mul R A\n#align algebraic.cardinal_mk_le_mul Algebraic.cardinal_mk_le_mul\n\ntheorem cardinal_mk_le_max : (#{ x : A // IsAlgebraic R x }) \u2264 max (#R) \u2135\u2080 :=\n  by\n  rw [\u2190 lift_id (#_), \u2190 lift_id (#R)]\n  exact cardinal_mk_lift_le_max R A\n#align algebraic.cardinal_mk_le_max Algebraic.cardinal_mk_le_max\n\n@[simp]\ntheorem cardinal_mk_of_infinite [Infinite R] : (#{ x : A // IsAlgebraic R x }) = (#R) :=\n  lift_inj.1 <| cardinal_mk_lift_of_infinite R A\n#align algebraic.cardinal_mk_of_infinite Algebraic.cardinal_mk_of_infinite\n\nend NonLift\n\nend Algebraic\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/AlgebraicCard.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190226, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7118335130846285}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport order.filter.cofinite\n\n/-!\n# Basic theory of bornology\n\nWe develop the basic theory of bornologies. Instead of axiomatizing bounded sets and defining\nbornologies in terms of those, we recognize that the cobounded sets form a filter and define a\nbornology as a filter of cobounded sets which contains the cofinite filter.  This allows us to make\nuse of the extensive library for filters, but we also provide the relevant connecting results for\nbounded sets.\n\nThe specification of a bornology in terms of the cobounded filter is equivalent to the standard\none (e.g., see [Bourbaki, *Topological Vector Spaces*][bourbaki1987], **covering bornology**, now\noften called simply **bornology**) in terms of bounded sets (see `bornology.of_bounded`,\n`is_bounded.union`, `is_bounded.subset`), except that we do not allow the empty bornology (that is,\nwe require that *some* set must be bounded; equivalently, `\u2205` is bounded). In the literature the\ncobounded filter is generally referred to as the *filter at infinity*.\n\n## Main definitions\n\n- `bornology \u03b1`: a class consisting of `cobounded : filter \u03b1` and a proof that this filter\n  contains the `cofinite` filter.\n- `bornology.is_cobounded`: the predicate that a set is a member of the `cobounded \u03b1` filter. For\n  `s : set \u03b1`, one should prefer `bornology.is_cobounded s` over `s \u2208 cobounded \u03b1`.\n- `bornology.is_bounded`: the predicate that states a set is bounded (i.e., the complement of a\n  cobounded set). One should prefer `bornology.is_bounded s` over `s\u1d9c \u2208 cobounded \u03b1`.\n- `bounded_space \u03b1`: a class extending `bornology \u03b1` with the condition\n  `bornology.is_bounded (set.univ : set \u03b1)`\n\nAlthough use of `cobounded \u03b1` is discouraged for indicating the (co)boundedness of individual sets,\nit is intended for regular use as a filter on `\u03b1`.\n-/\n\nopen set filter\n\nvariables {\u03b9 \u03b1 \u03b2 : Type*}\n\n/-- A **bornology** on a type `\u03b1` is a filter of cobounded sets which contains the cofinite filter.\nSuch spaces are equivalently specified by their bounded sets, see `bornology.of_bounded`\nand `bornology.ext_iff_is_bounded`-/\n@[ext]\nclass bornology (\u03b1 : Type*) :=\n(cobounded [] : filter \u03b1)\n(le_cofinite [] : cobounded \u2264 cofinite)\n\n/-- A constructor for bornologies by specifying the bounded sets,\nand showing that they satisfy the appropriate conditions. -/\n@[simps]\ndef bornology.of_bounded {\u03b1 : Type*} (B : set (set \u03b1))\n  (empty_mem : \u2205 \u2208 B) (subset_mem : \u2200 s\u2081 \u2208 B, \u2200 s\u2082 : set \u03b1, s\u2082 \u2286 s\u2081 \u2192 s\u2082 \u2208 B)\n  (union_mem : \u2200 s\u2081 s\u2082 \u2208 B, s\u2081 \u222a s\u2082 \u2208 B) (singleton_mem : \u2200 x, {x} \u2208 B) :\n  bornology \u03b1 :=\n{ cobounded :=\n  { sets := {s : set \u03b1 | s\u1d9c \u2208 B},\n    univ_sets := by rwa \u2190compl_univ at empty_mem,\n    sets_of_superset := \u03bb x y hx hy, subset_mem x\u1d9c hx y\u1d9c (compl_subset_compl.mpr hy),\n    inter_sets := \u03bb x y hx hy, by simpa [compl_inter] using union_mem x\u1d9c hx y\u1d9c hy, },\n  le_cofinite :=\n  begin\n    rw le_cofinite_iff_compl_singleton_mem,\n    intros x,\n    change {x}\u1d9c\u1d9c \u2208 B,\n    rw compl_compl,\n    exact singleton_mem x\n  end }\n\n/-- A constructor for bornologies by specifying the bounded sets,\nand showing that they satisfy the appropriate conditions. -/\n@[simps]\ndef bornology.of_bounded' {\u03b1 : Type*} (B : set (set \u03b1))\n  (empty_mem : \u2205 \u2208 B) (subset_mem : \u2200 s\u2081 \u2208 B, \u2200 s\u2082 : set \u03b1, s\u2082 \u2286 s\u2081 \u2192 s\u2082 \u2208 B)\n  (union_mem : \u2200 s\u2081 s\u2082 \u2208 B, s\u2081 \u222a s\u2082 \u2208 B) (sUnion_univ : \u22c3\u2080 B = univ) :\n  bornology \u03b1 :=\nbornology.of_bounded B empty_mem subset_mem union_mem $ \u03bb x,\n  begin\n    rw sUnion_eq_univ_iff at sUnion_univ,\n    rcases sUnion_univ x with \u27e8s, hs, hxs\u27e9,\n    exact subset_mem s hs {x} (singleton_subset_iff.mpr hxs)\n  end\n\nnamespace bornology\n\nsection\nvariables [bornology \u03b1] {s t : set \u03b1} {x : \u03b1}\n\n/-- `is_cobounded` is the predicate that `s` is in the filter of cobounded sets in the ambient\nbornology on `\u03b1` -/\ndef is_cobounded (s : set \u03b1) : Prop := s \u2208 cobounded \u03b1\n\n/-- `is_bounded` is the predicate that `s` is bounded relative to the ambient bornology on `\u03b1`. -/\ndef is_bounded (s : set \u03b1) : Prop := is_cobounded s\u1d9c\n\nlemma is_cobounded_def {s : set \u03b1} : is_cobounded s \u2194 s \u2208 cobounded \u03b1 := iff.rfl\n\nlemma is_bounded_def {s : set \u03b1} : is_bounded s \u2194 s\u1d9c \u2208 cobounded \u03b1 := iff.rfl\n\n@[simp] lemma is_bounded_compl_iff : is_bounded s\u1d9c \u2194 is_cobounded s :=\nby rw [is_bounded_def, is_cobounded_def, compl_compl]\n\n@[simp] lemma is_cobounded_compl_iff : is_cobounded s\u1d9c \u2194 is_bounded s := iff.rfl\n\nalias is_bounded_compl_iff \u2194 bornology.is_bounded.of_compl bornology.is_cobounded.compl\nalias is_cobounded_compl_iff \u2194 bornology.is_cobounded.of_compl bornology.is_bounded.compl\n\n@[simp] lemma is_bounded_empty : is_bounded (\u2205 : set \u03b1) :=\nby { rw [is_bounded_def, compl_empty], exact univ_mem}\n\n@[simp] lemma is_bounded_singleton : is_bounded ({x} : set \u03b1) :=\nby {rw [is_bounded_def], exact le_cofinite _ (finite_singleton x).compl_mem_cofinite}\n\n@[simp] \n\n@[simp] lemma is_cobounded_inter : is_cobounded (s \u2229 t) \u2194 is_cobounded s \u2227 is_cobounded t :=\ninter_mem_iff\n\nlemma is_cobounded.inter (hs : is_cobounded s) (ht : is_cobounded t) : is_cobounded (s \u2229 t) :=\nis_cobounded_inter.2 \u27e8hs, ht\u27e9\n\n@[simp] lemma is_bounded_union : is_bounded (s \u222a t) \u2194 is_bounded s \u2227 is_bounded t :=\nby simp only [\u2190 is_cobounded_compl_iff, compl_union, is_cobounded_inter]\n\nlemma is_bounded.union (hs : is_bounded s) (ht : is_bounded t) : is_bounded (s \u222a t) :=\nis_bounded_union.2 \u27e8hs, ht\u27e9\n\nlemma is_cobounded.superset (hs : is_cobounded s) (ht : s \u2286 t) : is_cobounded t :=\nmem_of_superset hs ht\n\nlemma is_bounded.subset (ht : is_bounded t) (hs : s \u2286 t) : is_bounded s :=\nht.superset (compl_subset_compl.mpr hs)\n\n@[simp]\nlemma sUnion_bounded_univ : (\u22c3\u2080 {s : set \u03b1 | is_bounded s}) = univ :=\nsUnion_eq_univ_iff.2 $ \u03bb a, \u27e8{a}, is_bounded_singleton, mem_singleton a\u27e9\n\nlemma comap_cobounded_le_iff [bornology \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  (cobounded \u03b2).comap f \u2264 cobounded \u03b1 \u2194 \u2200 \u2983s\u2984, is_bounded s \u2192 is_bounded (f '' s) :=\nbegin\n  refine \u27e8\u03bb h s hs, _, \u03bb h t ht,\n    \u27e8(f '' t\u1d9c)\u1d9c, h $ is_cobounded.compl ht, compl_subset_comm.1 $ subset_preimage_image _ _\u27e9\u27e9,\n  obtain \u27e8t, ht, hts\u27e9 := h hs.compl,\n  rw [subset_compl_comm, \u2190preimage_compl] at hts,\n  exact (is_cobounded.compl ht).subset ((image_subset f hts).trans $ image_preimage_subset _ _),\nend\n\nend\n\nlemma ext_iff' {t t' : bornology \u03b1} :\n  t = t' \u2194 \u2200 s, (@cobounded \u03b1 t).sets s \u2194 (@cobounded \u03b1 t').sets s :=\n(ext_iff _ _).trans filter.ext_iff\n\nlemma ext_iff_is_bounded {t t' : bornology \u03b1} :\n  t = t' \u2194 \u2200 s, @is_bounded \u03b1 t s \u2194 @is_bounded \u03b1 t' s :=\n\u27e8\u03bb h s, h \u25b8 iff.rfl, \u03bb h, by { ext, simpa only [is_bounded_def, compl_compl] using h s\u1d9c, }\u27e9\n\nvariables {s : set \u03b1}\n\nlemma is_cobounded_of_bounded_iff (B : set (set \u03b1)) {empty_mem subset_mem union_mem sUnion_univ} :\n  @is_cobounded _ (of_bounded B empty_mem subset_mem union_mem sUnion_univ) s \u2194 s\u1d9c \u2208 B := iff.rfl\n\nlemma is_bounded_of_bounded_iff (B : set (set \u03b1)) {empty_mem subset_mem union_mem sUnion_univ} :\n  @is_bounded _ (of_bounded B empty_mem subset_mem union_mem sUnion_univ) s \u2194 s \u2208 B :=\nby rw [is_bounded_def, \u2190filter.mem_sets, of_bounded_cobounded_sets, set.mem_set_of_eq, compl_compl]\n\nvariables [bornology \u03b1]\n\nlemma is_cobounded_bInter {s : set \u03b9} {f : \u03b9 \u2192 set \u03b1} (hs : s.finite) :\n  is_cobounded (\u22c2 i \u2208 s, f i) \u2194 \u2200 i \u2208 s, is_cobounded (f i) :=\nbInter_mem hs\n\n@[simp] lemma is_cobounded_bInter_finset (s : finset \u03b9) {f : \u03b9 \u2192 set \u03b1} :\n  is_cobounded (\u22c2 i \u2208 s, f i) \u2194 \u2200 i \u2208 s, is_cobounded (f i) :=\nbInter_finset_mem s\n\n@[simp] lemma is_cobounded_Inter [fintype \u03b9] {f : \u03b9 \u2192 set \u03b1} :\n  is_cobounded (\u22c2 i, f i) \u2194 \u2200 i, is_cobounded (f i) :=\nInter_mem\n\nlemma is_cobounded_sInter {S : set (set \u03b1)} (hs : S.finite) :\n  is_cobounded (\u22c2\u2080 S) \u2194 \u2200 s \u2208 S, is_cobounded s :=\nsInter_mem hs\n\nlemma is_bounded_bUnion {s : set \u03b9} {f : \u03b9 \u2192 set \u03b1} (hs : s.finite) :\n  is_bounded (\u22c3 i \u2208 s, f i) \u2194 \u2200 i \u2208 s, is_bounded (f i) :=\nby simp only [\u2190 is_cobounded_compl_iff, compl_Union, is_cobounded_bInter hs]\n\nlemma is_bounded_bUnion_finset (s : finset \u03b9) {f : \u03b9 \u2192 set \u03b1} :\n  is_bounded (\u22c3 i \u2208 s, f i) \u2194 \u2200 i \u2208 s, is_bounded (f i) :=\nis_bounded_bUnion s.finite_to_set\n\nlemma is_bounded_sUnion {S : set (set \u03b1)} (hs : S.finite) :\n  is_bounded (\u22c3\u2080 S) \u2194 (\u2200 s \u2208 S, is_bounded s) :=\nby rw [sUnion_eq_bUnion, is_bounded_bUnion hs]\n\n@[simp] lemma is_bounded_Union [fintype \u03b9] {s : \u03b9 \u2192 set \u03b1} :\n  is_bounded (\u22c3 i, s i) \u2194 \u2200 i, is_bounded (s i) :=\nby rw [\u2190 sUnion_range, is_bounded_sUnion (finite_range s), forall_range_iff]\n\nend bornology\n\nopen bornology\n\nlemma set.finite.is_bounded [bornology \u03b1] {s : set \u03b1} (hs : s.finite) : is_bounded s :=\nbornology.le_cofinite \u03b1 hs.compl_mem_cofinite\n\ninstance : bornology punit := \u27e8\u22a5, bot_le\u27e9\n\n/-- The cofinite filter as a bornology -/\n@[reducible] def bornology.cofinite : bornology \u03b1 :=\n{ cobounded := cofinite,\n  le_cofinite := le_rfl }\n\n/-- A space with a `bornology` is a **bounded space** if `set.univ : set \u03b1` is bounded. -/\nclass bounded_space (\u03b1 : Type*) [bornology \u03b1] : Prop :=\n(bounded_univ : bornology.is_bounded (univ : set \u03b1))\n\nnamespace bornology\n\nvariables [bornology \u03b1]\n\nlemma is_bounded_univ : is_bounded (univ : set \u03b1) \u2194 bounded_space \u03b1 :=\n\u27e8\u03bb h, \u27e8h\u27e9, \u03bb h, h.1\u27e9\n\nlemma cobounded_eq_bot_iff : cobounded \u03b1 = \u22a5 \u2194 bounded_space \u03b1 :=\nby rw [\u2190 is_bounded_univ, is_bounded_def, compl_univ, empty_mem_iff_bot]\n\nvariables [bounded_space \u03b1]\n\nlemma is_bounded.all (s : set \u03b1) : is_bounded s := bounded_space.bounded_univ.subset s.subset_univ\nlemma is_cobounded.all (s : set \u03b1) : is_cobounded s := compl_compl s \u25b8 is_bounded.all s\u1d9c\n\nvariable (\u03b1)\n\n@[simp] lemma cobounded_eq_bot : cobounded \u03b1 = \u22a5 := cobounded_eq_bot_iff.2 \u2039_\u203a\n\nend bornology\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/topology/bornology/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064586998, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7118335108022175}}
{"text": "import tactic\n\nnamespace mbl\n\n/-\n# Groups\n\n## Definition of a group\n\nThe `group` class will extend `has_mul`, `has_one` and `has_inv`. \n\n`has_mul G` means that `G` has a multiplication `* : G \u2192 G \u2192 G`\n`has_one G` means that `G` has a `1 : G`\n`has_inv G` means that `G` has an `\u207b\u00b9 : G \u2192 G`\n\nAll of `*`, `1` and `\u207b\u00b9` are notation for functions -- no axioms yet.\n\nA `group` has all of this notation, and the group axioms too. \nLet's now define the group class.\n\nA `group` structure on a type `G` is multiplication, identity and inverse,\nplus the usual axioms \n\n-/\n\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n(mul_assoc : \u2200 (a b c : G), a * b * c = a * (b * c))\n(one_mul : \u2200 (a : G), 1 * a = a)\n(mul_left_inv : \u2200 (a : G), a\u207b\u00b9 * a = 1)\n\n/-\n\nFormally, a term of type `group G` is now the following data:\na multiplication, 1, and inverse function,\nand proofs that the group axioms are satisfied.\n\nThe way to say \"let G be a group\" is now `(G : Type) [group G]`\n\nThe square bracket notation is the notation used for classes.\nFormally, it means \"put a term of type `group G` into the type class\ninference system\". In practice this just means \"you can use group\nnotation and axioms in proofs, and Lean will figure out why they're true\"\n\nWe have been extremely mean with our axioms. Some authors also add\nthe axioms `mul_one : \u2200 (a : G), a * 1 = a`\nand `mul_right_inv : \u2200 (a : G), a * a\u207b\u00b9 = 1`.\n\nBut these follow from the three axioms we used. Our first job is\nto prove them. As you might imagine, mathematically this is pretty\nmuch the trickiest part, because we have to be careful not to\naccidentally assume these axioms when we're proving them.\n\nHere are the four lemmas we will prove next.\n\n`mul_left_cancel : \u2200 (a b c : G), a * b = a * c \u2192 b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a\u207b\u00b9 * y \u2192 a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n-/\n\nnamespace group\n\n-- let `G` be a group.\nvariables {G : Type} [group G]\n\n/-\nThis proof could be done using rewrites, but I will take this opportunity\nto introduce the `calc` tactic.\nThe math is already done. All you need to do is apply correct axioms/assumptions\n-/\n\nlemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c := \nbegin\n calc b = 1 * b         : by sorry\n    ... = (a\u207b\u00b9 * a) * b : by sorry\n    ... = a\u207b\u00b9 * (a * b) : by sorry\n    ... = a\u207b\u00b9 * (a * c) : by sorry\n    ... = (a\u207b\u00b9 * a) * c : by sorry\n    ... = 1 * c         : by sorry\n    ... = c             : by sorry\nend\n/-!\nNext we prove that if `x = a\u207b\u00b9 * y` then `a * x = y`. Remember we are still\nmissing `mul_one` and `mul_right_inv`. A proof that avoids them is\nthe following: we want `a * x = y`. Now `apply`ing the previous lemma, it\nsuffices to prove that `a\u207b\u00b9 * (a * x) = a\u207b\u00b9 * y.`\nNow use associativity and left cancellation on on the left, to reduce\nto `h`.\nNote that `mul_left_cancel` is a function, and its first input is \ncalled `a`, but you had better give it `a\u207b\u00b9` instead.\n-/\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a\u207b\u00b9 * y) : a * x = y :=\nbegin\n  sorry,\nend\n\n-- Let `a,b,c,x,y` be elements of `G`.\nvariables (a b c x y : G)\n--From now on we don't need to redefine all the variables in our theorems\n\n/-\nWe can use `mul_eq_of_eq_inv_mul` to prove the two \"missing\" axioms `mul_one`\nand `mul_right_inv`, and then our lives will be much easier. Try `apply`ing it\nin the theorems below.\n-/\n\n@[simp] theorem mul_one : a * 1 = a :=\nbegin\n  sorry,\nend\n\n@[simp] theorem mul_right_inv : a * a\u207b\u00b9 = 1 :=\nbegin\n  sorry,\nend\n\n/-\n## Lean's simplifier\n\nA human sees `a * a\u207b\u00b9` in group theory, and instantly replaces it with `1`.\nWe are going to train a simple AI called `simp` to do the same thing.\n\nLean's simplifier `simp` is a \"term rewriting system\". This means\nthat if you teach it a bunch of theorems of the form `A = B` or\n`P \u2194 Q` (by tagging them with the `@[simp]` attribute) and then give\nit a complicated goal, like\n\n`example : (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1`\n\nthen it will try to use the `rw` tactic as much as it can, using the lemmas\nit has been taught, in an attempt to simplify the goal. If it manages\nto solve it completely, then great! If it does not, but you feel like\nit should have done, you might want to tag more lemmas with `@[simp]`.\n`simp` should only be used to completely close goals. We are now\ngoing to train the simplifier to solve the example above (indeed, we are\ngoing to train it to reduce an arbitrary element of a free group into\na unique normal form, so it will solve any equalities which are true\nfor all groups, like the example above).\n\n## Important note\n\nLean's simplifier does a series of rewrites, each one replacing something\nwith something else. But the simplifier will always rewrite from left to right!\nIf you tell it that `A = B` is a `simp` lemma then it will replace `A`s with\n`B`s, but it will never replace `B`s with `A`s. If you tag a proof\nof `A = B` with `@[simp]` and you also tag a proof of `B = A` with\n`@[simp]`, then the simplifier will get stuck in an infinite loop when\nit runs into an `A`! Equality should not be thought of as symmetric here.\n\nBecause the simplifier works from left to right, an important\nrule of thumb is that if `A = B` is a `simp` lemma, then `B` should\nprobably be simpler than `A`! In particular, equality should not be\nthought of as symmetric here. It is not a coincidence that in\nthe theorems below\n\n`@[simp] theorem mul_one (a : G) : a * 1 = a`\n`@[simp] theorem mul_right_inv (a : G) : a * a\u207b\u00b9 = 1`\n\nthe right hand side is simpler than the left hand side. It would be a\n> disaster to tag `a = a * 1` with the `@[simp]` tag -- can you see why?\n\n\nLet's train Lean's simplifier! Let's teach it the axioms of a `group` next.\nWe have already done the axioms, so we have to retrospectively tag\nthem with the `@[simp]` attribute.\n-/\n\nattribute [simp] one_mul mul_left_inv mul_assoc\n\n/-\nNow let's teach the simplifier the following five lemmas:\n\n`inv_mul_cancel_left : a\u207b\u00b9 * (a * b) = b`\n`mul_inv_cancel_left : a * (a\u207b\u00b9 * b) = b`\n`inv_mul : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9`\n`one_inv : (1 : G)\u207b\u00b9 = 1`\n`inv_inv : (a\u207b\u00b9)\u207b\u00b9 = a`\n\nNote that in each case, the right hand side is simpler\nthan the left hand side.\n\nTry using the simplifier in your proofs! I will do the\nfirst one for you.\n\n-/\n\n@[simp] lemma inv_mul_cancel_left : a\u207b\u00b9 * (a * b) = b :=\nbegin\n  rw \u2190 mul_assoc, -- the simplifier wouldn't do it that way\n                  -- so we have to do it manually\n  simp, -- simplifier takes it from here, \n        -- rewriting a\u207b\u00b9 * a to 1 and then 1 * b to b\nend\n\n@[simp] lemma mul_inv_cancel_left : a * (a\u207b\u00b9 * b) = b :=\nbegin\n  sorry,\nend\n\n@[simp] lemma inv_mul : (a * b)\u207b\u00b9 = b\u207b\u00b9 * a\u207b\u00b9 :=\nbegin\n  sorry,\nend\n\n@[simp] lemma one_inv : (1 : G)\u207b\u00b9 = 1 :=\nbegin\n  sorry,\nend\n\n@[simp] lemma inv_inv : a \u207b\u00b9 \u207b\u00b9 = a :=\nbegin\n  sorry,\nend\n\n--Once we prove those, simp can solve things such as this\nexample : (a * b) * 1\u207b\u00b9\u207b\u00b9 * b\u207b\u00b9 * (a\u207b\u00b9 * a\u207b\u00b9\u207b\u00b9\u207b\u00b9) * a = 1 := by simp -- short for begin simp end\n\n--Even more exercises. We probably won't look at them but you are welcome to try them in your own time\n\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c\u207b\u00b9 :=\nbegin\n  sorry,\nend\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b\u207b\u00b9 * c :=\nbegin\n  sorry\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b \u2194 a = 1 :=\nbegin\n  sorry\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a \u2194 b = 1 :=\nbegin\n  sorry\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b\u207b\u00b9 :=\nbegin\n  sorry\nend\n\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a\u207b\u00b9 = b :=\nbegin\n  sorry,\nend\n\nlemma unique_left_id {e : G} (h : \u2200 x : G, e * x = x) : e = 1 :=\nbegin\n  sorry\nend\n\nlemma unique_right_inv {a b : G} (h : a * b = 1) : b = a\u207b\u00b9 :=\nbegin\n  sorry\nend\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y \u2194 x = y :=\nbegin\n  sorry,\nend\n\n-- You don't even need to go into tactic mode (begin/end) to use `calc`:\nlemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y := \ncalc x = x * 1 : by rw mul_one\n  -- missing arguments here\n  ... = y : by sorry\n\n-- `\u2194` lemmas are good simp lemmas too.\n@[simp] theorem inv_inj_iff {a b : G}: a\u207b\u00b9 = b\u207b\u00b9 \u2194 a = b :=\nbegin\n  sorry\nend   \n\ntheorem inv_eq {a b : G}: a\u207b\u00b9 = b \u2194 b\u207b\u00b9 = a :=\nbegin\n  sorry\nend\n\n\n\nend group\nend mbl", "meta": {"author": "Wornbard", "repo": "mbl_lean_workshop", "sha": "6b68ce25fdc49043fd5ab409de8e4a2987def22e", "save_path": "github-repos/lean/Wornbard-mbl_lean_workshop", "path": "github-repos/lean/Wornbard-mbl_lean_workshop/mbl_lean_workshop-6b68ce25fdc49043fd5ab409de8e4a2987def22e/src/day_3/groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.711833509766125}}
{"text": "/-\nThe functor typeclass enables us to change the behavior\nof (what amounts to) function *application* In particular,\nthe functor.map operation (<$>) lifts any pure function, \nh : \u03b1 \u2192 \u03b2, to a \"structure-preserving\" function on data \nvalues containing \u03b1 and \u03b2 values: e.g., mapping options, \nlists, or trees of \u03b1 values into structurally identical \ntrees of \u03b2 values. Preservation of structure is assured\nby the functor laws. \n-/\n\n/-\nThe applicative functor typeclass enables us to change \nthe behavior of *multi-argument* function application.\nThe pure function takes a function and lifts it into\none that can then serve as a first argument to the seq\nfunction, which then \"applies\" that function to a data\nstructure containing first arguments to that function. \nThe result is then a data structure holding partially\nevaluated functions that is then \"applied\" to the next\ndata structure containing argument values. Overriding\nthe definitions of pure and seq in particular ways for\ndifferent data structures, such as option and list,\nhas given us nice ways to implement \"non-deterministic\"\nfunction application as well as \"exceptions\" over\napplications of functions to multiple arguments. Note:\nan applicative functor *is a kind of functor,* so we\ncan assume that the map function is available when we\ndefine pure and seq.\n-/\n\n/-\nWe can now state the purpose of the monad typeclass.\nIn short, it provides a way to override the behavior \nof function *composition* so that additional data and\nbehavior can be overlaid on top of ordinary function\ncomposition, just as the applicative functor let us\noverlay extra data and behavior on ordinary function\n*application*.\n\nComposition is a super-power because because it lets \nus decompose complex computations into compositions\nof simple computations.\n\nAs an example, suppose we want to get a dog but not\none that will make our house all furry. So we go to\nthe animal shelter. There are two dogs there, polly\nand fido. Polly is a poodle and fido is a husky.\n\nWe don't want a dog that will mess up our house by\nleaving lots of fur around. What we need then is a \nfunction that given a particular dog as input tells\nus whether that dog is messy. For each dog we'll want \na yes/no answer: is is this dog *messy* or not?\n\nmessy : dogs \u2192 yesno\n\nHow should we implement messy? The trick is to see \nthat we can break it into a composition of simpler\nfunctions. (1) We note that whether a dog is messy\nif and only if it sheds. Whether it sheds depends \non its coat: if it has hair it doesn't shed, but if \nit has fur, it does shed.  Whether a dog has fur or \nhair depends, in turn, on its breed. Poodles have \nhair. Husky's have fur. \n\nSo we can now see how to solve the problem. Given\none of the dogs as input, compute its breed (husky\nor poodle); then use that \"output\" as the input to\na second function that takes a breed as input and\noutputs its coat type (fur or hair); next use that\noutput as the input to a function that indicates\nwhether that kind of coat sheds or not (yes/no).\nWe will take the answer to the last question as \nthe answer to the overall question of whether a\ngiven dog is *messy*.\n\nSuppose we have functions to solve each of these\nsmaller problems.\n\nbreed : dogs \u2192 breeds\ncoat : breeds \u2192 coats\nsheds : coats \u2192 yesno\n\nHaving broken our problem up into these parts, we\nnow need a way to compose them into the function \nwe seek, messy : dogs \u2192 yesno.\n-/\n\nnamespace hidden\n\n-- Data types\ninductive dogs | fido | polly\ninductive breeds | poodle | husky\ninductive coats | fur | hair\ninductive yesno | yes | no\n  \nopen dogs breeds coats yesno\n\n-- Component functions\ndef breed : dogs \u2192 breeds\n| polly := poodle\n| fido := husky\n\ndef coat : breeds \u2192 coats\n| poodle := hair\n| husky := fur\n\ndef sheds : coats \u2192 yesno \n| fur := yes\n| hair := no\n\n/-\nComposition is the operation of \"connecting\" \nthe output of one function to the input of a\nnext one to produce a new function from initial\ninput to final output. We can thus chain together\nour three functions to get our desired overall\nsolution.\n-/\n\ndef messy := sheds \u2218 coat \u2218 breed\n\n/-\nWe pronounce (sheds \u2218 coat \u2218 breed) as \n\"sheds after coat after breed.\" When applied\nto a dog, d, this function first applies breed,\nthen feeds the result to coat, then feeds that\nresult to sheds and finally returns the desired\nyes/no result. Note that the argument on the \nright sort of flows right to left through this\nfunction composition.\n-/\n\n#check messy  -- isMessy : dogs \u2192 messy\n#reduce messy -- \u03bb (x : dogs), sheds (breed x)\n\nexample : messy polly = no := rfl   \nexample : messy fido = yes := rfl\n\n/-\nFunction composition is associative.\n-/\n\ntheorem comp_assoc : \n  \u2200 {\u03b1 \u03b2 \u03b3 \u03b4 : Type } \n    (k : \u03b3 \u2192 \u03b4) \n    (g : \u03b2 \u2192 \u03b3) \n    (f : \u03b1 \u2192 \u03b2),\n  (k \u2218 g) \u2218 f = k \u2218 (g \u2218 f) :=\nsorry\n\n-- hint\n#check @funext\n\n/-\nLet's unpack one of these examples. We know now that \n(messy polly) reduces to no. We also know that it\napplies (\u03bb d, (sheds (coat (breed d)))) to (polly).\nIt binds d to polly, then applies breed then coat\nand then sheds. \n\nWhat we see is that ordinary function composition \nnotation gives us a sort of \"backwards\" or inside out\nsequential notation: the last operation to be applied \nis the leftmost one in the expression. On the other\nhand, we can think of this sequence in a more usual\n(for English speakers) left to right or top to bottom\nsequence. \n\nWith a simple notational change we can express the \nsame composition of functions in a more natural manner.  \nThe secret is to use binding operations. First we bind\nb to the result of applying breed to polly, then we\nbind c to the result of applying coat to b then we\nbind m to the result of apply sheds to c, and finally\nwe \"return\" (reduce to) m. What we end up with looks\na lot more like typical \"sequential\" code of the kind\nwe find in imperative languages.\n-/\n\ndef isPollyMessy :=\n  (let \n    b := (breed polly) in let\n    c := (coat b) in let\n    m := (sheds c) in\n    m\n  )\n\n\n/-\nIf we generalize the choice of polly as the dog in\nthis case (replacing it with a parameter) then we\nget our messy function back.\n-/\ndef messy' (d : dogs) :=\n(let \n  b := (breed d) in let   -- bind b, call rest\n  c := (coat b)  in let   -- bind c, call rest\n  m := (sheds c) in       -- bind m, call rest\n        m                 -- \"return\" m\n)\n\n-- It's exactly the same as sheds \u2218 coat \u2218 breed\nexample : messy' = messy := rfl\n\n/-\nOne of the things that a \"monad\" does is to allow\nus to write compositions of a richer kind in this\nsort of sequential style. But we don't need monad\nto understand this idea. We can easily define a \nnew notation that allows us to write the program\nwe've written here in a left-to-right sequential\nstyle.\n-/\n\n/-\nThe easy trick is to define a notation for function\napplication where the argument is on the left and \nthe function is on the right. We can then think of\n\"feeding\" each argument into the function on the \nright. Let's use >> as an infix notation of this\nstyle of function application.\n-/\n\nlocal notation v ` >> ` f :120 := f v\n\n#reduce \n  polly >>  -- a pure argument bound as argument of rest\n  breed >>  -- apply bread to incoing, pass result to rest\n  coat >>   -- apply coat to incoming, pass result to rest\n  sheds     -- apply sheds to incoming, return final result\n\n/-\nFunction application is *left* associative, so what we\nhave here is polly being fed to breed reducing to some\nbreed, which is fed to coat, reducing to some coat, which\nis fed to sheds, reducing to a yes/no value. It's still\njust ordinary everyday function composition/application.\n-/\n\n#reduce (((polly >> breed) >> coat) >> sheds)     \n\n  \n/-\nSo now we have an abstraction of a sequential pipeline\nthat works by taking an argument (in general the result\nof a preceding computation), and passes that value as \nthe argument to \"the rest of the pipeline.\"\n-/\n\n/-\nLet's look at another way we can write this code,\nstarting with just (polly >> breed). \n-/\n\n#reduce  \n    (\u03bb d, breed d)  -- bind d and compute (breed d)\n    polly           -- argument bound to d\n\n\n#reduce \n  (\u03bb b, coat b)     -- bind b to result of the rest then compute (coat b)\n    ((\u03bb d, breed d) -- argument (\"the rest\")\n      polly\n    )\n\n#reduce polly >> breed >> coat >> sheds\n#reduce \n  (\u03bb c, sheds c)  -- bind c to result of rest then compute (sheds c)\n    ((\u03bb b, coat b) -- argument (rest)\n      ((\u03bb d, breed d)\n          polly\n      )\n  )\n\n/-\nYet another way to write the same code, then, is as\na sequence of binding operation. Here we bind c to\nthe result of \"running the rest of the computation\"\nthen we process c. And the rest of the computation\nis structured in the same way. We present this style\nagain to demystify some of the syntactic constructs\nwe'll see next, when we turn to monads, which simply\nprovide a way to compose functions, let's call them\n\"monadic functions\" that return not pure results, of\nsome type \u03b2, but \"enriched\" results, of type (m \u03b2),\nwhere m is a type constructor such as list, option,\neither, pair, etc.\n-/\n\n/-\nWith this discussion of composition in mind, and now\nunderstanding that a monad is a typeclass that enables\ncomposition of monadic functions, please continue to\nthe monad.lean file. \n-/\n\nend hidden\n", "meta": {"author": "kevinsullivan", "repo": "cs6501s22", "sha": "c55d342145b127e7b7bf396c660966034e80a944", "save_path": "github-repos/lean/kevinsullivan-cs6501s22", "path": "github-repos/lean/kevinsullivan-cs6501s22/cs6501s22-c55d342145b127e7b7bf396c660966034e80a944/src/content/lectures/S_07_monads/composition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7118334965221925}}
{"text": "/-\nCopyright (c) 2020 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.finset.mul_antidiagonal\n! leanprover-community/mathlib commit 0a0ec35061ed9960bf0e7ffb0335f44447b58977\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Pointwise.Basic\nimport Mathlib.Data.Set.MulAntidiagonal\n\n/-! # Multiplication antidiagonal as a `Finset`.\n\nWe construct the `Finset` of all pairs\nof an element in `s` and an element in `t` that multiply to `a`,\ngiven that `s` and `t` are well-ordered.-/\n\n\nnamespace Set\n\nopen Pointwise\n\nvariable {\u03b1 : Type _} {s t : Set \u03b1}\n\n@[to_additive]\ntheorem IsPwo.mul [OrderedCancelCommMonoid \u03b1] (hs : s.IsPwo) (ht : t.IsPwo) : IsPwo (s * t) := by\n  rw [\u2190 image_mul_prod]\n  exact (hs.prod ht).image_of_monotone (monotone_fst.mul' monotone_snd)\n#align set.is_pwo.mul Set.IsPwo.mul\n#align set.is_pwo.add Set.IsPwo.add\n\nvariable [LinearOrderedCancelCommMonoid \u03b1]\n\n@[to_additive]\ntheorem IsWf.mul (hs : s.IsWf) (ht : t.IsWf) : IsWf (s * t) :=\n  (hs.isPwo.mul ht.isPwo).isWf\n#align set.is_wf.mul Set.IsWf.mul\n#align set.is_wf.add Set.IsWf.add\n\n@[to_additive]\ntheorem IsWf.min_mul (hs : s.IsWf) (ht : t.IsWf) (hsn : s.Nonempty) (htn : t.Nonempty) :\n    (hs.mul ht).min (hsn.mul htn) = hs.min hsn * ht.min htn := by\n  refine' le_antisymm (IsWf.min_le _ _ (mem_mul.2 \u27e8_, _, hs.min_mem _, ht.min_mem _, rfl\u27e9)) _\n  rw [IsWf.le_min_iff]\n  rintro _ \u27e8x, y, hx, hy, rfl\u27e9\n  exact mul_le_mul' (hs.min_le _ hx) (ht.min_le _ hy)\n#align set.is_wf.min_mul Set.IsWf.min_mul\n#align set.is_wf.min_add Set.IsWf.min_add\n\nend Set\n\nnamespace Finset\n\nopen Pointwise\n\nvariable {\u03b1 : Type _}\n\nvariable [OrderedCancelCommMonoid \u03b1] {s t : Set \u03b1} (hs : s.IsPwo) (ht : t.IsPwo) (a : \u03b1)\n\n/-- `Finset.mulAntidiagonal hs ht a` is the set of all pairs of an element in `s` and an\nelement in `t` that multiply to `a`, but its construction requires proofs that `s` and `t` are\nwell-ordered. -/\n@[to_additive \"`Finset.addAntidiagonal hs ht a` is the set of all pairs of an element in\n`s` and an element in `t` that add to `a`, but its construction requires proofs that `s` and `t` are\nwell-ordered.\"]\nnoncomputable def mulAntidiagonal : Finset (\u03b1 \u00d7 \u03b1) :=\n  (Set.MulAntidiagonal.finite_of_isPwo hs ht a).toFinset\n#align finset.mul_antidiagonal Finset.mulAntidiagonal\n#align finset.add_antidiagonal Finset.addAntidiagonal\n\nvariable {hs ht a} {u : Set \u03b1} {hu : u.IsPwo} {x : \u03b1 \u00d7 \u03b1}\n\n@[to_additive (attr := simp)]\ntheorem mem_mulAntidiagonal : x \u2208 mulAntidiagonal hs ht a \u2194 x.1 \u2208 s \u2227 x.2 \u2208 t \u2227 x.1 * x.2 = a := by\n  simp only [mulAntidiagonal, Set.Finite.mem_toFinset, Set.mem_mulAntidiagonal]\n#align finset.mem_mul_antidiagonal Finset.mem_mulAntidiagonal\n#align finset.mem_add_antidiagonal Finset.mem_addAntidiagonal\n\n@[to_additive]\ntheorem mulAntidiagonal_mono_left (h : u \u2286 s) : mulAntidiagonal hu ht a \u2286 mulAntidiagonal hs ht a :=\n  Set.Finite.toFinset_mono <| Set.mulAntidiagonal_mono_left h\n#align finset.mul_antidiagonal_mono_left Finset.mulAntidiagonal_mono_left\n#align finset.add_antidiagonal_mono_left Finset.addAntidiagonal_mono_left\n\n@[to_additive]\ntheorem mulAntidiagonal_mono_right (h : u \u2286 t) :\n    mulAntidiagonal hs hu a \u2286 mulAntidiagonal hs ht a :=\n  Set.Finite.toFinset_mono <| Set.mulAntidiagonal_mono_right h\n#align finset.mul_antidiagonal_mono_right Finset.mulAntidiagonal_mono_right\n#align finset.add_antidiagonal_mono_right Finset.addAntidiagonal_mono_right\n\n-- Porting note: removed `(attr := simp)`. simp can prove this.\n@[to_additive]\ntheorem swap_mem_mulAntidiagonal :\n    x.swap \u2208 Finset.mulAntidiagonal hs ht a \u2194 x \u2208 Finset.mulAntidiagonal ht hs a := by\n  simp only [mem_mulAntidiagonal, Prod.fst_swap, Prod.snd_swap, Set.swap_mem_mulAntidiagonal_aux,\n             Set.mem_mulAntidiagonal]\n#align finset.swap_mem_mul_antidiagonal Finset.swap_mem_mulAntidiagonal\n#align finset.swap_mem_add_antidiagonal Finset.swap_mem_addAntidiagonal\n\n@[to_additive]\ntheorem support_mulAntidiagonal_subset_mul : { a | (mulAntidiagonal hs ht a).Nonempty } \u2286 s * t :=\n  fun a \u27e8b, hb\u27e9 => by\n  rw [mem_mulAntidiagonal] at hb\n  exact \u27e8b.1, b.2, hb\u27e9\n#align finset.support_mul_antidiagonal_subset_mul Finset.support_mulAntidiagonal_subset_mul\n#align finset.support_add_antidiagonal_subset_add Finset.support_addAntidiagonal_subset_add\n\n@[to_additive]\ntheorem isPwo_support_mulAntidiagonal : { a | (mulAntidiagonal hs ht a).Nonempty }.IsPwo :=\n  (hs.mul ht).mono support_mulAntidiagonal_subset_mul\n#align finset.is_pwo_support_mul_antidiagonal Finset.isPwo_support_mulAntidiagonal\n#align finset.is_pwo_support_add_antidiagonal Finset.isPwo_support_addAntidiagonal\n\n@[to_additive]\ntheorem mulAntidiagonal_min_mul_min {\u03b1} [LinearOrderedCancelCommMonoid \u03b1] {s t : Set \u03b1}\n    (hs : s.IsWf) (ht : t.IsWf) (hns : s.Nonempty) (hnt : t.Nonempty) :\n    mulAntidiagonal hs.isPwo ht.isPwo (hs.min hns * ht.min hnt) = {(hs.min hns, ht.min hnt)} := by\n  ext \u27e8a, b\u27e9\n  simp only [mem_mulAntidiagonal, mem_singleton, Prod.ext_iff]\n  constructor\n  \u00b7 rintro \u27e8has, hat, hst\u27e9\n    obtain rfl :=\n      (hs.min_le hns has).eq_of_not_lt fun hlt =>\n        (mul_lt_mul_of_lt_of_le hlt <| ht.min_le hnt hat).ne' hst\n    exact \u27e8rfl, mul_left_cancel hst\u27e9\n  \u00b7 rintro \u27e8rfl, rfl\u27e9\n    exact \u27e8hs.min_mem _, ht.min_mem _, rfl\u27e9\n#align finset.mul_antidiagonal_min_mul_min Finset.mulAntidiagonal_min_mul_min\n#align finset.add_antidiagonal_min_add_min Finset.addAntidiagonal_min_add_min\n\nend Finset\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Finset/MulAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7118317866968716}}
{"text": "/-\nEq\n-/\n\n#check @eq  -- binary relation : \u03b1 \u2192 \u03b1 \u2192 \u03b1 \n\n\n#print eq\n/-\ninductive eq : \u03a0 {\u03b1 : Sort u}, \u03b1 \u2192 \u03b1 \u2192 Prop\nconstructors:\neq.refl : \u2200 {\u03b1 : Sort u} (a : \u03b1), a = a\n-/\n\n/- \nProperties \n-/\n#print eq\n\n/-\n-- reflexive    -- constructor\n-- symmetric    <- reflexive\n-- transitive   <- reflexive\n-- equivalence  <- resymtr\n-/\n\n\n/-\nAXIOMS\n-/\n\n/-\nrefl: Every thing equals itself\n-/\n#check @eq.refl \n/-\neq.refl: from any a, proof of a = a\n-/\n-- the only eq constructor\n-- the one introduction rule\n\n-- the one elimination rule\n-- substitution of equals\n/-\n      subst \n\n        C : \u03b1 \u2192 Prop\n      /   \\\n    /       \\\nC a   >a=b>   C b\n\n-/\n\n#check @eq.rec\n\n-- What does this type say?\n\n/-\neq.rec : \n  \u03a0 {\u03b1 : Sort u_2} \n    {a : \u03b1} \n    {C : \u03b1 \u2192 Sort u_1}, \n    C a \u2192 \n    \u03a0 {\u1fb0 : \u03b1}, \n    a = \u1fb0 \u2192 \n    C \u1fb0\n-/\n\n/-\nFor any type of object, \u03b1, \nfor any a of this type,\nand for any property, C \u03b1, of objects of type \u03b1, \nIf you know or assume that a has property C\nthen for any other object, \u1fb0, of type \u03b1 \nif you know or assume that a and \u1fb0 are equal\nthen you may conclude that \u1fb0 also has that proeprty, C. \nSo, if you need to prove C b it suffices to show C a and a = b.\nSubst uses an equality a = b in order to rewrite a term C a to C b.\n-/\n\n/-\nProve that symmetry and transitivty are now theorems\n-/\n\n#check @eq.symm \n\nexample : \u2200 {\u03b1 : Type } {a b : \u03b1}, a = b \u2194 b = a :=  \nbegin\n  assume \u03b1 a b, \n  split,\n  assume h,\n  rw h,\n  assume h,\n  rw h,\nend\n\nexample : \u2200 {\u03b1 : Type } {a b : \u03b1}, a = b \u2194 b = a :=  \n\u03bb \u03b1 a b, \n  (iff.intro \n    (\u03bb aeqb, \n      (\n        let s := eq.symm aeqb \n        in eq.subst aeqb (eq.refl a) \n      )\n    )  \n    (_)                 -- exercise!\n  )\n\n\n#check @eq.trans        -- exercise\n\n\n-- tactic script\nexample : \u2200 {\u03b1 : Type } {a b c : \u03b1}, a = b \u2192 b = c \u2192 a = c := \n_\n\n\n-- Lean term\nexample : \u2200 {\u03b1 : Type } {a b c : \u03b1}, a = b \u2192 b = c \u2192 a = c := \n_", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/inClassNotes/propositions/eq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7118317865423821}}
{"text": "import group_theory.group_action.basic\nimport tactic\nimport data.setoid.partition\n\nvariables {G : Type*} [group G] {S : Type} {s t u : S} [mul_action G S]\n\nopen mul_action\n\ntheorem mem_orbit_refl (s : S) : s \u2208 orbit G s :=\nbegin\n  -- we could use `1 : G` but this is already in the library under another name\n  exact mem_orbit_self s,\nend\n\ntheorem mem_orbit_symm (h : s \u2208 orbit G t) : t \u2208 orbit G s :=\nbegin\n  rw mem_orbit_iff at *,\n  -- h says \u2203 x, x \u2022 t = s so let's let `a` be that `x` and \n  -- then replace `s` by `a \u2022 t` everywhere (that's the `rfl`)\n  rcases h with \u27e8a, rfl\u27e9,\n  -- By the maths proof, we use a\u207b\u00b9\n  use a\u207b\u00b9,\n  -- now the simplifier can solve this equality\n  simp,\nend\n\ntheorem mem_orbit_trans (hst : s \u2208 orbit G t) (htu : t \u2208 orbit G u) :\n  s \u2208 orbit G u :=\nbegin\n  rw mem_orbit_iff at *,\n  -- we know a \u2022 t = s and b \u2022 u = t\n  rcases hst with \u27e8a, rfl\u27e9,\n  rcases htu with \u27e8b, rfl\u27e9,\n  -- so we have to solve `\u2203 x, x \u2022 u = a \u2022 b \u2022 u` \n  use a * b,\n  exact mul_smul a b u, -- I know the axiom name\nend\n\nopen set\n\nvariable (G)\n\ntheorem orbit_nonempty (s : S) : set.nonempty (orbit G s) :=\nbegin\n  rw nonempty_def,\n  -- the orbit is nonempty because it contains s\n  use s,\n  -- and here's the proof that s is in its own orbit\n  exact mem_orbit_refl s,\nend\n\nvariable {G}\ntheorem mem_orbit (s : S) : \u2203 (t : S), s \u2208 orbit G t :=\nbegin\n  -- we can use t = s\n  use s,\n  -- and here's the proof that s is in its own orbit\n  exact mem_orbit_refl s,\nend\n\nvariable {a : S}\n\ntheorem boring_lemma (has : a \u2208 orbit G s) (hat : a \u2208 orbit G t) : s \u2208 orbit G t :=\nbegin\n  -- this is a little logic puzzle. Note that my proof is backwards\n  refine mem_orbit_trans _ hat,\n  exact mem_orbit_symm has,\nend\n\ntheorem orbit_subset_of_mem_orbit (hst : s \u2208 orbit G t) : orbit G s \u2286 orbit G t :=\nbegin\n  rintros u hu,\n  exact mem_orbit_trans hu hst,\nend\n\ntheorem orbit_eq_orbit_of_mem_inter (has : a \u2208 orbit G s) (hat : a \u2208 orbit G t) :\n  orbit G s = orbit G t :=\nbegin\n  -- \u2286 is antisymmetric\n  apply subset.antisymm,\n  { -- both cases follow from the boring lemma and `orbit_subset_of_mem_orbit`\n    apply orbit_subset_of_mem_orbit,\n    exact boring_lemma has hat, },\n  { apply orbit_subset_of_mem_orbit,\n    exact boring_lemma hat has, }\nend\n\nvariable {g : G}\n\nopen setoid\n\n-- this is harder and can probably be golfed.\nexample : is_partition {\ud835\udcaa : set S | \u2203 s, orbit G s = \ud835\udcaa} :=\nbegin\n  refine \u27e8_, _\u27e9,\n  { rintro \u27e8s, hs\u27e9,\n    exact not_nonempty_iff_eq_empty.mpr hs (orbit_nonempty G s), },\n  intro s,\n  refine exists_unique_of_exists_of_unique _ _,\n  { use orbit G s,\n    simp },\n  { rintro A B \u27e8\u27e8t, rfl\u27e9, hst, -\u27e9 \u27e8\u27e8u, rfl\u27e9, hsu, -\u27e9,\n    exact orbit_eq_orbit_of_mem_inter hst hsu, },\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "group-action-exercises", "sha": "197b1a0e53ec8d84bf3903c9ab5cddf615a44816", "save_path": "github-repos/lean/ImperialCollegeLondon-group-action-exercises", "path": "github-repos/lean/ImperialCollegeLondon-group-action-exercises/group-action-exercises-197b1a0e53ec8d84bf3903c9ab5cddf615a44816/src/solutions/level_2_group_actions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110483133799, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7118317784432218}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n\n! This file was ported from Lean 3 source module category_theory.skeletal\n! leanprover-community/mathlib commit 28aa996fc6fb4317f0083c4e6daf79878d81be33\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.Adjunction.Basic\nimport Mathlib.CategoryTheory.Category.Preorder\nimport Mathlib.CategoryTheory.IsomorphismClasses\nimport Mathlib.CategoryTheory.Thin\n\n/-!\n# Skeleton of a category\n\nDefine skeletal categories as categories in which any two isomorphic objects are equal.\n\nConstruct the skeleton of an arbitrary category by taking isomorphism classes, and show it is a\nskeleton of the original category.\n\nIn addition, construct the skeleton of a thin category as a partial ordering, and (noncomputably)\nshow it is a skeleton of the original category. The advantage of this special case being handled\nseparately is that lemmas and definitions about orderings can be used directly, for example for the\nsubobject lattice. In addition, some of the commutative diagrams about the functors commute\ndefinitionally on the nose which is convenient in practice.\n-/\n\n\nuniverse v\u2081 v\u2082 v\u2083 u\u2081 u\u2082 u\u2083\n\nnamespace CategoryTheory\n\nopen Category\n\nvariable (C : Type u\u2081) [Category.{v\u2081} C]\n\nvariable (D : Type u\u2082) [Category.{v\u2082} D]\n\nvariable {E : Type u\u2083} [Category.{v\u2083} E]\n\n/-- A category is skeletal if isomorphic objects are equal. -/\ndef Skeletal : Prop :=\n  \u2200 \u2983X Y : C\u2984, IsIsomorphic X Y \u2192 X = Y\n#align category_theory.skeletal CategoryTheory.Skeletal\n\n/-- `IsSkeletonOf C D F` says that `F : D \u2964 C` exhibits `D` as a skeletal full subcategory of `C`,\nin particular `F` is a (strong) equivalence and `D` is skeletal.\n-/\nstructure IsSkeletonOf (F : D \u2964 C) where\n  /-- The category `D` has isomorphic objects equal -/\n  skel : Skeletal D\n  /-- The functor `F` is an equivalence -/\n  eqv : IsEquivalence F\n#align category_theory.is_skeleton_of CategoryTheory.IsSkeletonOf\n\nattribute [local instance] isIsomorphicSetoid\n\nvariable {C D}\n\n/-- If `C` is thin and skeletal, then any naturally isomorphic functors to `C` are equal. -/\ntheorem Functor.eq_of_iso {F\u2081 F\u2082 : D \u2964 C} [Quiver.IsThin C] (hC : Skeletal C) (hF : F\u2081 \u2245 F\u2082) :\n    F\u2081 = F\u2082 :=\n  Functor.ext (fun X => hC \u27e8hF.app X\u27e9) fun _ _ _ => Subsingleton.elim _ _\n#align category_theory.functor.eq_of_iso CategoryTheory.Functor.eq_of_iso\n\n/-- If `C` is thin and skeletal, `D \u2964 C` is skeletal.\n`CategoryTheory.functor_thin` shows it is thin also.\n-/\ntheorem functor_skeletal [Quiver.IsThin C] (hC : Skeletal C) : Skeletal (D \u2964 C) := fun _ _ h =>\n  h.elim (Functor.eq_of_iso hC)\n#align category_theory.functor_skeletal CategoryTheory.functor_skeletal\n\nvariable (C D)\n\n/-- Construct the skeleton category as the induced category on the isomorphism classes, and derive\nits category structure.\n-/\ndef Skeleton : Type u\u2081 := InducedCategory C Quotient.out\n#align category_theory.skeleton CategoryTheory.Skeleton\n\ninstance [Inhabited C] : Inhabited (Skeleton C) :=\n  \u27e8\u27e6default\u27e7\u27e9\n\n-- Porting note: previously `Skeleton` used `deriving Category`\nnoncomputable instance : Category (Skeleton C) := by\n  apply InducedCategory.category\n\n/-- The functor from the skeleton of `C` to `C`. -/\n@[simps!]\nnoncomputable def fromSkeleton : Skeleton C \u2964 C :=\n  inducedFunctor _\n#align category_theory.from_skeleton CategoryTheory.fromSkeleton\n\n-- Porting note: previously `fromSkeleton` used `deriving Faithful, Full`\nnoncomputable instance : Full <| fromSkeleton C := by\n  apply InducedCategory.full\nnoncomputable instance : Faithful <| fromSkeleton C := by\n  apply InducedCategory.faithful\n\ninstance : EssSurj (fromSkeleton C) where mem_essImage X := \u27e8Quotient.mk' X, Quotient.mk_out X\u27e9\n\n-- Porting note: named this instance\nnoncomputable instance fromSkeleton.isEquivalence : IsEquivalence (fromSkeleton C) :=\n  Equivalence.ofFullyFaithfullyEssSurj (fromSkeleton C)\n\n/-- The equivalence between the skeleton and the category itself. -/\nnoncomputable def skeletonEquivalence : Skeleton C \u224c C :=\n  (fromSkeleton C).asEquivalence\n#align category_theory.skeleton_equivalence CategoryTheory.skeletonEquivalence\n\ntheorem skeleton_skeletal : Skeletal (Skeleton C) := by\n  rintro X Y \u27e8h\u27e9\n  have : X.out \u2248 Y.out := \u27e8(fromSkeleton C).mapIso h\u27e9\n  simpa using Quotient.sound this\n#align category_theory.skeleton_skeletal CategoryTheory.skeleton_skeletal\n\n/-- The `skeleton` of `C` given by choice is a skeleton of `C`. -/\nnoncomputable def skeletonIsSkeleton : IsSkeletonOf C (Skeleton C) (fromSkeleton C) where\n  skel := skeleton_skeletal C\n  eqv := fromSkeleton.isEquivalence C\n#align category_theory.skeleton_is_skeleton CategoryTheory.skeletonIsSkeleton\n\nsection\n\nvariable {C D}\n\n/-- Two categories which are categorically equivalent have skeletons with equivalent objects.\n-/\nnoncomputable def Equivalence.skeletonEquiv (e : C \u224c D) : Skeleton C \u2243 Skeleton D :=\n  let f := ((skeletonEquivalence C).trans e).trans (skeletonEquivalence D).symm\n  { toFun := f.functor.obj\n    invFun := f.inverse.obj\n    left_inv := fun X => skeleton_skeletal C \u27e8(f.unitIso.app X).symm\u27e9\n    right_inv := fun Y => skeleton_skeletal D \u27e8f.counitIso.app Y\u27e9 }\n#align category_theory.equivalence.skeleton_equiv CategoryTheory.Equivalence.skeletonEquiv\n\nend\n\n/-- Construct the skeleton category by taking the quotient of objects. This construction gives a\npreorder with nice definitional properties, but is only really appropriate for thin categories.\nIf your original category is not thin, you probably want to be using `skeleton` instead of this.\n-/\ndef ThinSkeleton : Type u\u2081 :=\n  Quotient (isIsomorphicSetoid C)\n#align category_theory.thin_skeleton CategoryTheory.ThinSkeleton\n\ninstance inhabitedThinSkeleton [Inhabited C] : Inhabited (ThinSkeleton C) :=\n  \u27e8@Quotient.mk' C (isIsomorphicSetoid C) default\u27e9\n#align category_theory.inhabited_thin_skeleton CategoryTheory.inhabitedThinSkeleton\n\ninstance ThinSkeleton.preorder : Preorder (ThinSkeleton C)\n    where\n  le :=\n    @Quotient.lift\u2082 C C _ (isIsomorphicSetoid C) (isIsomorphicSetoid C)\n      (fun X Y => Nonempty (X \u27f6 Y))\n        (by\n          rintro _ _ _ _ \u27e8i\u2081\u27e9 \u27e8i\u2082\u27e9\n          exact\n            propext\n              \u27e8Nonempty.map fun f => i\u2081.inv \u226b f \u226b i\u2082.hom,\n                Nonempty.map fun f => i\u2081.hom \u226b f \u226b i\u2082.inv\u27e9)\n  le_refl := by\n    refine' Quotient.ind fun a => _\n    exact \u27e8\ud835\udfd9 _\u27e9\n  le_trans a b c := Quotient.inductionOn\u2083 a b c fun A B C => Nonempty.map2 (\u00b7 \u226b \u00b7)\n#align category_theory.thin_skeleton.preorder CategoryTheory.ThinSkeleton.preorder\n\n/-- The functor from a category to its thin skeleton. -/\n@[simps]\ndef toThinSkeleton : C \u2964 ThinSkeleton C where\n  obj := @Quotient.mk' C _\n  map f := homOfLE (Nonempty.intro f)\n#align category_theory.to_thin_skeleton CategoryTheory.toThinSkeleton\n\n/-!\nThe constructions here are intended to be used when the category `C` is thin, even though\nsome of the statements can be shown without this assumption.\n-/\n\n\nnamespace ThinSkeleton\n\n/-- The thin skeleton is thin. -/\ninstance thin : Quiver.IsThin (ThinSkeleton C) := fun _ _ =>\n  \u27e8by\n    rintro \u27e8\u27e8f\u2081\u27e9\u27e9 \u27e8\u27e8_\u27e9\u27e9\n    rfl\u27e9\n#align category_theory.thin_skeleton.thin CategoryTheory.ThinSkeleton.thin\n\nvariable {C} {D}\n\n/-- A functor `C \u2964 D` computably lowers to a functor `ThinSkeleton C \u2964 ThinSkeleton D`. -/\n@[simps]\ndef map (F : C \u2964 D) : ThinSkeleton C \u2964 ThinSkeleton D where\n  obj := Quotient.map F.obj fun X\u2081 X\u2082 \u27e8hX\u27e9 => \u27e8F.mapIso hX\u27e9\n  map {X} {Y} := Quotient.recOnSubsingleton\u2082 X Y fun x y k => homOfLE (k.le.elim fun t => \u27e8F.map t\u27e9)\n#align category_theory.thin_skeleton.map CategoryTheory.ThinSkeleton.map\n\ntheorem comp_toThinSkeleton (F : C \u2964 D) : F \u22d9 toThinSkeleton D = toThinSkeleton C \u22d9 map F :=\n  rfl\n#align category_theory.thin_skeleton.comp_to_thin_skeleton CategoryTheory.ThinSkeleton.comp_toThinSkeleton\n\n/-- Given a natural transformation `F\u2081 \u27f6 F\u2082`, induce a natural transformation `map F\u2081 \u27f6 map F\u2082`.-/\ndef mapNatTrans {F\u2081 F\u2082 : C \u2964 D} (k : F\u2081 \u27f6 F\u2082) : map F\u2081 \u27f6 map F\u2082\n    where app X := Quotient.recOnSubsingleton X fun x => \u27e8\u27e8\u27e8k.app x\u27e9\u27e9\u27e9\n#align category_theory.thin_skeleton.map_nat_trans CategoryTheory.ThinSkeleton.mapNatTrans\n\n/- Porting note: `map\u2082ObjMap`, `map\u2082Functor`, and `map\u2082NatTrans` were all extracted\nfrom the original `map\u2082` proof. Lean needed an extensive amount explicit type\nannotations to figure things out. This also translated into repeated deterministic\ntimeouts. The extracted defs allow for explicit motives for the multiple\ndescents to the quotients.\n\nIt would be better to prove that\n`ThinSkeleton (C \u00d7 D) \u224c ThinSkeleton C \u00d7 ThinSkeleton D`\nwhich is more immediate from comparing the preorders. Then one could get\n`map\u2082` by currying.\n-/\n/-- Given a bifunctor, we descend to a function on objects of `ThinSkeleton` -/\ndef map\u2082ObjMap (F : C \u2964 D \u2964 E) : ThinSkeleton C \u2192 ThinSkeleton D \u2192 ThinSkeleton E :=\n  fun x y =>\n    @Quotient.map\u2082 C D (isIsomorphicSetoid C) (isIsomorphicSetoid D) E (isIsomorphicSetoid E)\n      (fun X Y => (F.obj X).obj Y)\n          (fun X\u2081 _ \u27e8hX\u27e9 _ Y\u2082 \u27e8hY\u27e9 => \u27e8(F.obj X\u2081).mapIso hY \u226a\u226b (F.mapIso hX).app Y\u2082\u27e9) x y\n\n/-- For each `x : ThinSkeleton C`, we promote `map\u2082ObjMap F x` to a functor -/\ndef map\u2082Functor (F : C \u2964 D \u2964 E) : ThinSkeleton C \u2192 ThinSkeleton D \u2964 ThinSkeleton E :=\n  fun x =>\n    { obj := fun y => map\u2082ObjMap F x y\n      map := fun {y\u2081} {y\u2082} => @Quotient.recOnSubsingleton C (isIsomorphicSetoid C)\n        (fun x => (y\u2081 \u27f6  y\u2082) \u2192 (map\u2082ObjMap F x y\u2081 \u27f6  map\u2082ObjMap F x y\u2082)) _ x fun X\n          => Quotient.recOnSubsingleton\u2082 y\u2081 y\u2082 fun Y\u2081 Y\u2082 hY =>\n            homOfLE (hY.le.elim fun g => \u27e8(F.obj X).map g\u27e9) }\n\n/-- This provides natural transformations `map\u2082Functor F x\u2081 \u27f6  map\u2082Functor F x\u2082` given\n`x\u2081 \u27f6  x\u2082` -/\ndef map\u2082NatTrans (F : C \u2964 D \u2964 E) : {x\u2081 x\u2082 : ThinSkeleton C} \u2192 (x\u2081 \u27f6  x\u2082) \u2192\n    (map\u2082Functor F x\u2081 \u27f6  map\u2082Functor F x\u2082) := fun {x\u2081} {x\u2082} =>\n  @Quotient.recOnSubsingleton\u2082 C C (isIsomorphicSetoid C) (isIsomorphicSetoid C)\n    (fun x x' : ThinSkeleton C => (x \u27f6  x') \u2192 (map\u2082Functor F x \u27f6  map\u2082Functor F x')) _ x\u2081 x\u2082\n    (fun X\u2081 X\u2082 f => { app := fun y =>\n      Quotient.recOnSubsingleton y fun Y => homOfLE (f.le.elim fun f' => \u27e8(F.map f').app Y\u27e9) })\n\n-- TODO: state the lemmas about what happens when you compose with `toThinSkeleton`\n/-- A functor `C \u2964 D \u2964 E` computably lowers to a functor\n`ThinSkeleton C \u2964 ThinSkeleton D \u2964 ThinSkeleton E` -/\n@[simps]\ndef map\u2082 (F : C \u2964 D \u2964 E) : ThinSkeleton C \u2964 ThinSkeleton D \u2964 ThinSkeleton E where\n  obj := map\u2082Functor F\n  map := map\u2082NatTrans F\n#align category_theory.thin_skeleton.map\u2082 CategoryTheory.ThinSkeleton.map\u2082\n\nvariable (C)\n\nsection\n\nvariable [Quiver.IsThin C]\n\ninstance toThinSkeleton_faithful : Faithful (toThinSkeleton C) where\n#align category_theory.thin_skeleton.to_thin_skeleton_faithful CategoryTheory.ThinSkeleton.toThinSkeleton_faithful\n\n/-- Use `Quotient.out` to create a functor out of the thin skeleton. -/\n@[simps]\nnoncomputable def fromThinSkeleton : ThinSkeleton C \u2964 C where\n  obj := Quotient.out\n  map {x} {y} :=\n    Quotient.recOnSubsingleton\u2082 x y fun X Y f =>\n      (Nonempty.some (Quotient.mk_out X)).hom \u226b f.le.some \u226b (Nonempty.some (Quotient.mk_out Y)).inv\n#align category_theory.thin_skeleton.from_thin_skeleton CategoryTheory.ThinSkeleton.fromThinSkeleton\n\nnoncomputable instance fromThinSkeletonEquivalence : IsEquivalence (fromThinSkeleton C) where\n  inverse := toThinSkeleton C\n  counitIso := NatIso.ofComponents (fun X => Nonempty.some (Quotient.mk_out X)) (by aesop_cat)\n  unitIso := NatIso.ofComponents (fun x => Quotient.recOnSubsingleton x fun X =>\n          eqToIso (Quotient.sound \u27e8(Nonempty.some (Quotient.mk_out X)).symm\u27e9)) (fun _ => rfl)\n#align category_theory.thin_skeleton.from_thin_skeleton_equivalence CategoryTheory.ThinSkeleton.fromThinSkeletonEquivalence\n\n/-- The equivalence between the thin skeleton and the category itself. -/\nnoncomputable def equivalence : ThinSkeleton C \u224c C :=\n  (fromThinSkeleton C).asEquivalence\n#align category_theory.thin_skeleton.equivalence CategoryTheory.ThinSkeleton.equivalence\n\nvariable {C}\n\ntheorem equiv_of_both_ways {X Y : C} (f : X \u27f6 Y) (g : Y \u27f6 X) : X \u2248 Y :=\n  \u27e8iso_of_both_ways f g\u27e9\n#align category_theory.thin_skeleton.equiv_of_both_ways CategoryTheory.ThinSkeleton.equiv_of_both_ways\n\ninstance thinSkeletonPartialOrder : PartialOrder (ThinSkeleton C) :=\n  { CategoryTheory.ThinSkeleton.preorder C with\n    le_antisymm :=\n      Quotient.ind\u2082\n        (by\n          rintro _ _ \u27e8f\u27e9 \u27e8g\u27e9\n          apply Quotient.sound (equiv_of_both_ways f g)) }\n#align category_theory.thin_skeleton.thin_skeleton_partial_order CategoryTheory.ThinSkeleton.thinSkeletonPartialOrder\n\ntheorem skeletal : Skeletal (ThinSkeleton C) := fun X Y =>\n  Quotient.inductionOn\u2082 X Y fun _ _ h => h.elim fun i => i.1.le.antisymm i.2.le\n#align category_theory.thin_skeleton.skeletal CategoryTheory.ThinSkeleton.skeletal\n\n\n\ntheorem map_id_eq : map (\ud835\udfed C) = \ud835\udfed (ThinSkeleton C) :=\n  Functor.eq_of_iso skeletal <|\n    NatIso.ofComponents (fun X => Quotient.recOnSubsingleton X fun x => Iso.refl _) (by aesop_cat)\n#align category_theory.thin_skeleton.map_id_eq CategoryTheory.ThinSkeleton.map_id_eq\n\ntheorem map_iso_eq {F\u2081 F\u2082 : D \u2964 C} (h : F\u2081 \u2245 F\u2082) : map F\u2081 = map F\u2082 :=\n  Functor.eq_of_iso skeletal\n    { hom := mapNatTrans h.hom\n      inv := mapNatTrans h.inv }\n#align category_theory.thin_skeleton.map_iso_eq CategoryTheory.ThinSkeleton.map_iso_eq\n\n/-- `fromThinSkeleton C` exhibits the thin skeleton as a skeleton. -/\nnoncomputable def thinSkeletonIsSkeleton : IsSkeletonOf C (ThinSkeleton C) (fromThinSkeleton C)\n    where\n  skel := skeletal\n  eqv := ThinSkeleton.fromThinSkeletonEquivalence C\n#align category_theory.thin_skeleton.thin_skeleton_is_skeleton CategoryTheory.ThinSkeleton.thinSkeletonIsSkeleton\n\nnoncomputable instance isSkeletonOfInhabited :\n    Inhabited (IsSkeletonOf C (ThinSkeleton C) (fromThinSkeleton C)) :=\n  \u27e8thinSkeletonIsSkeleton\u27e9\n#align category_theory.thin_skeleton.is_skeleton_of_inhabited CategoryTheory.ThinSkeleton.isSkeletonOfInhabited\n\nend\n\nvariable {C}\n\n/-- An adjunction between thin categories gives an adjunction between their thin skeletons. -/\ndef lowerAdjunction (R : D \u2964 C) (L : C \u2964 D) (h : L \u22a3 R) : ThinSkeleton.map L \u22a3 ThinSkeleton.map R :=\n  Adjunction.mkOfUnitCounit\n    { unit :=\n        {\n          app := fun X => by\n            letI := isIsomorphicSetoid C\n            refine' Quotient.recOnSubsingleton X fun x => homOfLE \u27e8h.unit.app x\u27e9 }\n      -- TODO: make quotient.rec_on_subsingleton' so the letI isn't needed\n      counit :=\n        {\n          app := fun X => by\n            letI := isIsomorphicSetoid D\n            refine' Quotient.recOnSubsingleton X fun x => homOfLE \u27e8h.counit.app x\u27e9 } }\n#align category_theory.thin_skeleton.lower_adjunction CategoryTheory.ThinSkeleton.lowerAdjunction\n\nend ThinSkeleton\n\nopen ThinSkeleton\n\nsection\n\nvariable {C} {\u03b1 : Type _} [PartialOrder \u03b1]\n\n/--\nWhen `e : C \u224c \u03b1` is a categorical equivalence from a thin category `C` to some partial order `\u03b1`,\nthe `ThinSkeleton C` is order isomorphic to `\u03b1`.\n-/\nnoncomputable def Equivalence.thinSkeletonOrderIso [Quiver.IsThin C] (e : C \u224c \u03b1) :\n    ThinSkeleton C \u2243o \u03b1 :=\n  ((ThinSkeleton.equivalence C).trans e).toOrderIso\n#align category_theory.equivalence.thin_skeleton_order_iso CategoryTheory.Equivalence.thinSkeletonOrderIso\n\nend\n\nend CategoryTheory\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Skeletal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7118317781342433}}
{"text": "import .love10_denotational_semantics_demo\n\n\n/-! # LoVe Homework 10: Denotational Semantics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n/-! The following command enables noncomputable decidability on every `Prop`.\nThe `priority 0` attribute ensures this is used only when necessary; otherwise,\nit would make some computable definitions noncomputable for Lean. Depending on\nhow you solve question 2.2, this command might help you. -/\n\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n/-! Denotational semantics are well suited to functional programming. In this\nexercise, we will study some representations of functional programs in Lean and\ntheir denotational semantics.\n\nThe `nondet` type represents functional programs that can perform\nnondeterministic computations: A program can choose between many different\ncomputation paths / return values. Returning no results at all is represented\nby `fail`, and nondeterministic choice between two options (identified by the\n`bool` values `tt` and `ff`) is represented by `choice`. -/\n\ninductive nondet (\u03b1 : Type) : Type\n| pure    : \u03b1 \u2192 nondet\n| fail {} : nondet\n| choice  : (bool \u2192 nondet) \u2192 nondet\n\nnamespace nondet\n\n\n/-! ## Question 1 (4 points): The `nondet` Monad\n\nThe `nondet` inductive type forms a monad. The `pure` operator is `nondet.pure`.\n`bind` is as follows: -/\n\ndef bind {\u03b1 \u03b2 : Type} : nondet \u03b1 \u2192 (\u03b1 \u2192 nondet \u03b2) \u2192 nondet \u03b2\n| (pure x)   f := f x\n| fail       f := fail\n| (choice k) f := choice (\u03bbb, bind (k b) f)\n\ninstance : has_pure nondet :=\n{ pure := @pure }\n\ninstance : has_bind nondet :=\n{ bind := @bind }\n\n/-! 1.1 (3 points). Prove the three monad laws for `nondet`.\n\nHints:\n\n* To unfold the definition of `>>=`, invoke `simp [(>>=)]`.\n\n* To prove `f = g` from `\u2200x, f x = g x`, use the theorem `funext`. -/\n\nlemma pure_bind {\u03b1 \u03b2 : Type} (x : \u03b1) (f : \u03b1 \u2192 nondet \u03b2) :\n  pure x >>= f = f x :=\nsorry\n\nlemma bind_pure {\u03b1 : Type} :\n  \u2200mx : nondet \u03b1, mx >>= pure = mx :=\nsorry\n\nlemma bind_assoc {\u03b1 \u03b2 \u03b3 : Type} :\n  \u2200(mx : nondet \u03b1) (f : \u03b1 \u2192 nondet \u03b2) (g : \u03b2 \u2192 nondet \u03b3),\n    ((mx >>= f) >>= g) = (mx >>= (\u03bba, f a >>= g)) :=\nsorry\n\n/-! The function `portmanteau` computes a portmanteau of two lists: A\nportmanteau of `xs` and `ys` has `xs` as a prefix and `ys` as a suffix, and they\noverlap. We use `starts_with xs ys` to test that `ys` has `xs` as a prefix. -/\n\ndef starts_with : list \u2115 \u2192 list \u2115 \u2192 bool\n| (x :: xs) []        := ff\n| []        ys        := tt\n| (x :: xs) (y :: ys) := (x = y) && starts_with xs ys\n\n#eval starts_with [1, 2] [1, 2, 3]\n#eval starts_with [1, 2, 3] [1, 2]\n\ndef portmanteau : list \u2115 \u2192 list \u2115 \u2192 list (list \u2115)\n| []        ys := []\n| (x :: xs) ys :=\n  list.map (list.cons x) (portmanteau xs ys) ++\n  (if starts_with (x :: xs) ys then [ys] else [])\n\n/-! Here are some examples of portmanteaux: -/\n\n#reduce portmanteau [0, 1, 2, 3] [2, 3, 4]\n#reduce portmanteau [0, 1] [2, 3, 4]\n#reduce portmanteau [0, 1, 2, 1, 2] [1, 2, 1, 2, 3, 4]\n\n/-! 1.2 (1 point). Translate the `portmanteau` program from the `list` monad to\nthe `nondet` monad. -/\n\ndef nondet_portmanteau : list \u2115 \u2192 list \u2115 \u2192 nondet (list \u2115) :=\nsorry\n\n\n/-! ## Question 2 (5 points): Nondeterminism, Denotationally\n\n2.1 (2 points). Give a denotational semantics for `nondet`, mapping it into a\n`list` of all results. `pure` returns one result, `fail` returns zero, and\n`choice` combines the results of either option. -/\n\ndef list_sem {\u03b1 : Type} : nondet \u03b1 \u2192 list \u03b1 :=\nsorry\n\n/-! Check that the following lines give the same output as for `portmanteau` (if\nyou have answered question 1.2): -/\n\n#reduce list_sem (nondet_portmanteau [0, 1, 2, 3] [2, 3, 4])\n#reduce list_sem (nondet_portmanteau [0, 1] [2, 3, 4])\n#reduce list_sem (nondet_portmanteau [0, 1, 2, 1, 2] [1, 2, 1, 2, 3, 4])\n\n/-! 2.2 (2 points). Often, we are not interested in getting all outcomes, just\nthe first successful one. Give a semantics for `nondet` that produces the first\nsuccessful result, if any. Your solution should *not* use `list_sem`. -/\n\nnoncomputable def option_sem {\u03b1 : Type} : nondet \u03b1 \u2192 option \u03b1 :=\nsorry\n\n/-! 2.3 (1 point). Prove the theorem `list_option_compat` below, showing that\nthe two semantics you defined are compatible. -/\n\nlemma head'_orelse_eq_head'_append {\u03b1 : Type} (xs ys : list \u03b1) :\n  (list.head' xs <|> list.head' ys) = list.head' (xs ++ ys) :=\nby induction' xs; simp\n\ntheorem list_option_compat {\u03b1 : Type} :\n  \u2200mx : nondet \u03b1, option_sem mx = list.head' (list_sem mx) :=\nsorry\n\nend nondet\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2021", "sha": "23b469c79afd482fa66da82e4726a317e3a7b5d5", "save_path": "github-repos/lean/blanchette-logical_verification_2021", "path": "github-repos/lean/blanchette-logical_verification_2021/logical_verification_2021-23b469c79afd482fa66da82e4726a317e3a7b5d5/lean/love10_denotational_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7118317758390966}}
{"text": "open classical\n\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable a : \u03b1\nvariable r : Prop\n\n--\n\n-- using exists.elim\nexample : (\u2203 x : \u03b1, r) \u2192 r :=\nassume h : \u2203 x : \u03b1, r,\nshow r, from\nexists.elim h\n    (assume w,\n    assume hw : r,\n    hw)\n\n-- using match\nexample : (\u2203 x : \u03b1, r) \u2192 r :=\nassume h : \u2203 x : \u03b1, r,\nmatch h with \u27e8w, (hw : r)\u27e9 :=\n    hw\nend\n\nexample : r \u2192 (\u2203 x : \u03b1, r) :=\nassume hr : r,\n\u27e8a, hr\u27e9\n\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r :=\niff.intro\n    (assume h : \u2203 x, p x \u2227 r,\n        show (\u2203 x, p x) \u2227 r, from\n        match h with \u27e8w, (hw : p w \u2227 r)\u27e9 :=\n            \u27e8\u27e8w, hw.left\u27e9, hw.right\u27e9\n        end)\n    (assume h : (\u2203 x, p x) \u2227 r,\n        show \u2203 x, p x \u2227 r, from\n        match h.left with \u27e8w, (hw : p w)\u27e9 :=\n            \u27e8w, \u27e8hw, h.right\u27e9\u27e9\n        end)\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\niff.intro\n    (assume h : (\u2203 x, p x \u2228 q x),\n        show (\u2203 x, p x) \u2228 (\u2203 x, q x), from\n        match h with \u27e8w, (hw : p w \u2228 q w)\u27e9 :=\n            or.elim hw\n                (assume hpw : p w,\n                    or.inl \u27e8w, hpw\u27e9)\n                (assume hqw : q w,\n                    or.inr \u27e8w, hqw\u27e9)\n        end)\n    (assume h : (\u2203 x, p x) \u2228 (\u2203 x, q x),\n        show (\u2203 x, p x \u2228 q x), from\n        or.elim h\n            (assume hleft : \u2203 x, p x,\n                match hleft with \u27e8w, hw\u27e9 :=\n                    \u27e8w, or.inl hw\u27e9\n                end)\n            (assume hright : \u2203 x, q x,\n                match hright with \u27e8w, hw\u27e9 :=\n                    \u27e8w, or.inr hw\u27e9\n                end))\n\n--\n\n-- refactor some lemmas for reuse {\n\nlemma not_exists_then_forall_not\n    {\u03b1 : Type} {p : \u03b1 \u2192 Prop} : (\u00ac \u2203 x, p x) \u2192 (\u2200 x, \u00ac p x) :=\nassume h : \u00ac \u2203 x, p x,\n    show \u2200 x, \u00ac p x, from\n    assume z : \u03b1,\n    show \u00ac p z, from\n    (assume hpz : p z,\n        show false, from\n        h \u27e8z, hpz\u27e9)\n\nlemma not_not_exists_then_forall\n    {\u03b1 : Type} {p : \u03b1 \u2192 Prop} : \u00ac (\u2203 x, \u00ac p x) \u2192 (\u2200 x, p x) :=\nassume h : \u00ac (\u2203 x, \u00ac p x),\n    show (\u2200 x, p x), from\n    assume z : \u03b1,\n    show p z, from\n    by_contradiction\n        (assume hnpz : \u00ac p z,\n            show false, from\n            h \u27e8z, hnpz\u27e9)\n\n-- }\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) :=\niff.intro\n    (assume h : (\u2200 x, p x),\n        show \u00ac (\u2203 x, \u00ac p x), from\n        assume hneg : \u2203 x, \u00ac p x,\n        show false, from\n        match hneg with \u27e8w, (hw : \u00ac p w)\u27e9 :=\n            absurd (h w) hw\n        end)\n    (assume h : \u00ac (\u2203 x, \u00ac p x),\n        show (\u2200 x, p x), from\n        not_not_exists_then_forall h)\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) :=\niff.intro\n    (assume h : \u2203 x, p x,\n        show \u00ac (\u2200 x, \u00ac p x), from\n        match h with \u27e8w, hw\u27e9 :=\n            assume hneg : \u2200 x, \u00ac p x,\n            show false, from\n            absurd hw (hneg w)\n        end)\n    (assume h : \u00ac (\u2200 x, \u00ac p x), -- \u2200 x, \u00ac p x \u2192 false\n        show \u2203 x, p x, from\n        by_contradiction\n            (assume h_tofalsify : \u00ac (\u2203 x, p x),\n                have h2 : \u2200 x, \u00ac p x, from not_exists_then_forall_not h_tofalsify,\n                absurd h2 h))\n\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) :=\niff.intro\n    (assume h : \u00ac \u2203 x, p x,\n        show \u2200 x, \u00ac p x, from\n        not_exists_then_forall_not h)\n    (assume h : \u2200 x, \u00ac p x,\n        show \u00ac \u2203 x, p x, from\n        (assume h2 : \u2203 x, p x,\n            show false, from\n            match h2 with \u27e8w, hw\u27e9 :=\n                absurd hw (h w)\n            end))\n\ntheorem not_forall_iff_not_exists\n    {\u03b1 : Type} {p : \u03b1 \u2192 Prop} : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) :=\niff.intro\n    (assume h : \u00ac \u2200 x, p x,\n        show \u2203 x, \u00ac p x, from\n        by_contradiction\n            (assume h_tofalsify : \u00ac (\u2203 x, \u00ac p x),\n                have h2 : \u2200 x, p x, from not_not_exists_then_forall h_tofalsify,\n                absurd h2 h))\n    (assume h : \u2203 x, \u00ac p x,\n        show \u00ac \u2200 x, p x, from\n        match h with \u27e8w, hw\u27e9 :=\n            assume hallp : \u2200 x, p x,\n            show false, from\n            absurd (hallp w) hw\n        end)\n\n--\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r :=\niff.intro\n    (assume h : (\u2200 x, p x \u2192 r),\n        show (\u2203 x, p x) \u2192 r, from\n        (assume h2 : \u2203 x, p x,\n            show r, from\n            match h2 with \u27e8w, (hw : p w)\u27e9 :=\n                (h w) hw\n            end))\n    (assume h : (\u2203 x, p x) \u2192 r,\n        show \u2200 x, p x \u2192 r, from\n        assume z : \u03b1,\n        show p z \u2192 r, from\n            (assume hpz : p z,\n                show r, from\n                h \u27e8z, hpz\u27e9))\n\nexample : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r :=\niff.intro\n    (assume h : \u2203 x, p x \u2192 r,\n        show (\u2200 x, p x) \u2192 r, from\n        match h with \u27e8w, (hw : p w \u2192 r)\u27e9 :=\n            assume h2 : \u2200 x, p x,\n            show r, from\n            hw (h2 w)\n        end)\n    (assume h : (\u2200 x, p x) \u2192 r,\n        show \u2203 x, p x \u2192 r, from\n        by_cases\n            (assume h_all : \u2200 x, p x,\n                \u27e8a, (\u03bb hpa, h h_all)\u27e9)\n            (assume h_nall : \u00ac \u2200 x, p x,\n                have h2 : \u2203 x, \u00ac p x, from not_forall_iff_not_exists.mp h_nall,\n                match h2 with \u27e8w, hw\u27e9 :=\n                    \u27e8w, (\n                        show p w \u2192 r, from\n                        (assume hpw : p w, absurd hpw hw)\n                    )\u27e9\n                end))\n\nexample : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) :=\niff.intro\n    (assume h : (\u2203 x, r \u2192 p x),\n        show (r \u2192 \u2203 x, p x), from\n        match h with \u27e8w, (hw : r \u2192 p w)\u27e9 :=\n            assume hr : r,\n            show \u2203 x, p x, from\n            \u27e8w, hw hr\u27e9\n        end)\n    (assume h : (r \u2192 \u2203 x, p x),\n        show (\u2203 x, r \u2192 p x), from\n        by_cases\n            (assume hr : r,\n                have h2 : \u2203 x, p x, from h hr,\n                match h2 with \u27e8w, (hw : p w)\u27e9 :=\n                    \u27e8w, (\u03bb _, hw)\u27e9\n                end)\n            (assume hnr : \u00acr,\n                \u27e8a, (\u03bb hr, absurd hr hnr)\u27e9))\n\n--\n\n", "meta": {"author": "hyponymous", "repo": "theorem-proving-in-lean-solutions", "sha": "a95320ae81c90c1b15da04574602cd378794400d", "save_path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions", "path": "github-repos/lean/hyponymous-theorem-proving-in-lean-solutions/theorem-proving-in-lean-solutions-a95320ae81c90c1b15da04574602cd378794400d/4.6.5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7117925521242701}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n-/\nimport order.boolean_algebra\n\n/-!\n# Basic properties of sets\n\nSets in Lean are homogeneous; all their elements have the same type. Sets whose elements\nhave type `X` are thus defined as `set X := X \u2192 Prop`. Note that this function need not\nbe decidable. The definition is in the core library.\n\nThis file provides some basic definitions related to sets and functions not present in the core\nlibrary, as well as extra lemmas for functions in the core library (empty set, univ, union,\nintersection, insert, singleton, set-theoretic difference, complement, and powerset).\n\nNote that a set is a term, not a type. There is a coercion from `set \u03b1` to `Type*` sending\n`s` to the corresponding subtype `\u21a5s`.\n\nSee also the file `set_theory/zfc.lean`, which contains an encoding of ZFC set theory in Lean.\n\n## Main definitions\n\nNotation used here:\n\n-  `f : \u03b1 \u2192 \u03b2` is a function,\n\n-  `s : set \u03b1` and `s\u2081 s\u2082 : set \u03b1` are subsets of `\u03b1`\n\n-  `t : set \u03b2` is a subset of `\u03b2`.\n\nDefinitions in the file:\n\n* `nonempty s : Prop` : the predicate `s \u2260 \u2205`. Note that this is the preferred way to express the\n  fact that `s` has an element (see the Implementation Notes).\n\n* `preimage f t : set \u03b1` : the preimage f\u207b\u00b9(t) (written `f \u207b\u00b9' t` in Lean) of a subset of \u03b2.\n\n* `subsingleton s : Prop` : the predicate saying that `s` has at most one element.\n\n* `range f : set \u03b2` : the image of `univ` under `f`.\n  Also works for `{p : Prop} (f : p \u2192 \u03b1)` (unlike `image`)\n\n* `inclusion s\u2081 s\u2082 : \u21a5s\u2081 \u2192 \u21a5s\u2082` : the map `\u21a5s\u2081 \u2192 \u21a5s\u2082` induced by an inclusion `s\u2081 \u2286 s\u2082`.\n\n## Notation\n\n* `f \u207b\u00b9' t` for `preimage f t`\n\n* `f '' s` for `image f s`\n\n* `s\u1d9c` for the complement of `s`\n\n## Implementation notes\n\n* `s.nonempty` is to be preferred to `s \u2260 \u2205` or `\u2203 x, x \u2208 s`. It has the advantage that\nthe `s.nonempty` dot notation can be used.\n\n* For `s : set \u03b1`, do not use `subtype s`. Instead use `\u21a5s` or `(s : Type*)` or `s`.\n\n## Tags\n\nset, sets, subset, subsets, image, preimage, pre-image, range, union, intersection, insert,\nsingleton, complement, powerset\n\n-/\n\n/-! ### Set coercion to a type -/\n\nopen function\n\nuniverses u v w x\n\nrun_cmd do e \u2190 tactic.get_env,\n  tactic.set_env $ e.mk_protected `set.compl\n\nnamespace set\n\nvariable {\u03b1 : Type*}\n\ninstance : has_le (set \u03b1) := \u27e8(\u2286)\u27e9\ninstance : has_lt (set \u03b1) := \u27e8\u03bb s t, s \u2264 t \u2227 \u00act \u2264 s\u27e9  -- `\u2282` is not defined until further down\n\ninstance {\u03b1 : Type*} : boolean_algebra (set \u03b1) :=\n{ sup := (\u222a),\n  le  := (\u2264),\n  lt  := (<),\n  inf := (\u2229),\n  bot := \u2205,\n  compl := set.compl,\n  top := univ,\n  sdiff := (\\),\n  .. (infer_instance : boolean_algebra (\u03b1 \u2192 Prop)) }\n\n@[simp] lemma top_eq_univ : (\u22a4 : set \u03b1) = univ := rfl\n@[simp] lemma bot_eq_empty : (\u22a5 : set \u03b1) = \u2205 := rfl\n@[simp] lemma sup_eq_union : ((\u2294) : set \u03b1 \u2192 set \u03b1 \u2192 set \u03b1) = (\u222a) := rfl\n@[simp] lemma inf_eq_inter : ((\u2293) : set \u03b1 \u2192 set \u03b1 \u2192 set \u03b1) = (\u2229) := rfl\n@[simp] lemma le_eq_subset : ((\u2264) : set \u03b1 \u2192 set \u03b1 \u2192 Prop) = (\u2286) := rfl\n/-! `set.lt_eq_ssubset` is defined further down -/\n@[simp] lemma compl_eq_compl : set.compl = (has_compl.compl : set \u03b1 \u2192 set \u03b1) := rfl\n\n/-- Coercion from a set to the corresponding subtype. -/\ninstance {\u03b1 : Type u} : has_coe_to_sort (set \u03b1) (Type u) := \u27e8\u03bb s, {x // x \u2208 s}\u27e9\n\ninstance pi_set_coe.can_lift (\u03b9 : Type u) (\u03b1 : \u03a0 i : \u03b9, Type v) [ne : \u03a0 i, nonempty (\u03b1 i)]\n  (s : set \u03b9) :\n  can_lift (\u03a0 i : s, \u03b1 i) (\u03a0 i, \u03b1 i) :=\n{ coe := \u03bb f i, f i,\n  .. pi_subtype.can_lift \u03b9 \u03b1 s }\n\ninstance pi_set_coe.can_lift' (\u03b9 : Type u) (\u03b1 : Type v) [ne : nonempty \u03b1] (s : set \u03b9) :\n  can_lift (s \u2192 \u03b1) (\u03b9 \u2192 \u03b1) :=\npi_set_coe.can_lift \u03b9 (\u03bb _, \u03b1) s\n\ninstance set_coe.can_lift (s : set \u03b1) : can_lift \u03b1 s :=\n{ coe := coe,\n  cond := \u03bb a, a \u2208 s,\n  prf := \u03bb a ha, \u27e8\u27e8a, ha\u27e9, rfl\u27e9 }\n\nend set\n\nsection set_coe\n\nvariables {\u03b1 : Type u}\n\ntheorem set.set_coe_eq_subtype (s : set \u03b1) :\n  coe_sort.{(u+1) (u+2)} s = {x // x \u2208 s} := rfl\n\n@[simp] theorem set_coe.forall {s : set \u03b1} {p : s \u2192 Prop} :\n  (\u2200 x : s, p x) \u2194 (\u2200 x (h : x \u2208 s), p \u27e8x, h\u27e9) :=\nsubtype.forall\n\n@[simp] theorem set_coe.exists {s : set \u03b1} {p : s \u2192 Prop} :\n  (\u2203 x : s, p x) \u2194 (\u2203 x (h : x \u2208 s), p \u27e8x, h\u27e9) :=\nsubtype.exists\n\ntheorem set_coe.exists' {s : set \u03b1} {p : \u03a0 x, x \u2208 s \u2192 Prop} :\n  (\u2203 x (h : x \u2208 s), p x h) \u2194 (\u2203 x : s, p x x.2)  :=\n(@set_coe.exists _ _ $ \u03bb x, p x.1 x.2).symm\n\ntheorem set_coe.forall' {s : set \u03b1} {p : \u03a0 x, x \u2208 s \u2192 Prop} :\n  (\u2200 x (h : x \u2208 s), p x h) \u2194 (\u2200 x : s, p x x.2)  :=\n(@set_coe.forall _ _ $ \u03bb x, p x.1 x.2).symm\n\n@[simp] theorem set_coe_cast : \u2200 {s t : set \u03b1} (H' : s = t) (H : @eq (Type u) s t) (x : s),\n  cast H x = \u27e8x.1, H' \u25b8 x.2\u27e9\n| s _ rfl _ \u27e8x, h\u27e9 := rfl\n\ntheorem set_coe.ext {s : set \u03b1} {a b : s} : (\u2191a : \u03b1) = \u2191b \u2192 a = b :=\nsubtype.eq\n\ntheorem set_coe.ext_iff {s : set \u03b1} {a b : s} : (\u2191a : \u03b1) = \u2191b \u2194 a = b :=\niff.intro set_coe.ext (assume h, h \u25b8 rfl)\n\nend set_coe\n\n/-- See also `subtype.prop` -/\nlemma subtype.mem {\u03b1 : Type*} {s : set \u03b1} (p : s) : (p : \u03b1) \u2208 s := p.prop\n\n/-- Duplicate of `eq.subset'`, which currently has elaboration problems. -/\nlemma eq.subset {\u03b1} {s t : set \u03b1} : s = t \u2192 s \u2286 t :=\nby { rintro rfl x hx, exact hx }\n\nnamespace set\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x} {a : \u03b1} {s t : set \u03b1}\n\ninstance : inhabited (set \u03b1) := \u27e8\u2205\u27e9\n\n@[ext]\ntheorem ext {a b : set \u03b1} (h : \u2200 x, x \u2208 a \u2194 x \u2208 b) : a = b :=\nfunext (assume x, propext (h x))\n\ntheorem ext_iff {s t : set \u03b1} : s = t \u2194 \u2200 x, x \u2208 s \u2194 x \u2208 t :=\n\u27e8\u03bb h x, by rw h, ext\u27e9\n\n@[trans] theorem mem_of_mem_of_subset {x : \u03b1} {s t : set \u03b1}\n  (hx : x \u2208 s) (h : s \u2286 t) : x \u2208 t := h hx\n\n/-! ### Lemmas about `mem` and `set_of` -/\n\n@[simp] theorem mem_set_of_eq {a : \u03b1} {p : \u03b1 \u2192 Prop} : a \u2208 {a | p a} = p a := rfl\n\ntheorem nmem_set_of_eq {a : \u03b1} {P : \u03b1 \u2192 Prop} : a \u2209 {a : \u03b1 | P a} = \u00ac P a := rfl\n\n@[simp] theorem set_of_mem_eq {s : set \u03b1} : {x | x \u2208 s} = s := rfl\n\ntheorem set_of_set {s : set \u03b1} : set_of s = s := rfl\n\nlemma set_of_app_iff {p : \u03b1 \u2192 Prop} {x : \u03b1} : { x | p x } x \u2194 p x := iff.rfl\n\ntheorem mem_def {a : \u03b1} {s : set \u03b1} : a \u2208 s \u2194 s a := iff.rfl\n\nlemma set_of_bijective : bijective (set_of : (\u03b1 \u2192 Prop) \u2192 set \u03b1) := bijective_id\n\n@[simp] theorem set_of_subset_set_of {p q : \u03b1 \u2192 Prop} :\n  {a | p a} \u2286 {a | q a} \u2194 (\u2200a, p a \u2192 q a) := iff.rfl\n\n@[simp] lemma sep_set_of {p q : \u03b1 \u2192 Prop} : {a \u2208 {a | p a } | q a} = {a | p a \u2227 q a} := rfl\n\nlemma set_of_and {p q : \u03b1 \u2192 Prop} : {a | p a \u2227 q a} = {a | p a} \u2229 {a | q a} := rfl\n\nlemma set_of_or {p q : \u03b1 \u2192 Prop} : {a | p a \u2228 q a} = {a | p a} \u222a {a | q a} := rfl\n\n/-! ### Subset and strict subset relations -/\n\ninstance : has_ssubset (set \u03b1) := \u27e8(<)\u27e9\n\ninstance : is_refl (set \u03b1) (\u2286) := has_le.le.is_refl\ninstance : is_trans (set \u03b1) (\u2286) := has_le.le.is_trans\ninstance : is_antisymm (set \u03b1) (\u2286) := has_le.le.is_antisymm\ninstance : is_irrefl (set \u03b1) (\u2282) := has_lt.lt.is_irrefl\ninstance : is_trans (set \u03b1) (\u2282) := has_lt.lt.is_trans\ninstance : is_asymm (set \u03b1) (\u2282) := has_lt.lt.is_asymm\ninstance : is_nonstrict_strict_order (set \u03b1) (\u2286) (\u2282) := \u27e8\u03bb _ _, iff.rfl\u27e9\n\n-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?\nlemma subset_def : (s \u2286 t) = \u2200 x, x \u2208 s \u2192 x \u2208 t := rfl\nlemma ssubset_def : s \u2282 t = (s \u2286 t \u2227 \u00ac t \u2286 s) := rfl\n\n@[refl] theorem subset.refl (a : set \u03b1) : a \u2286 a := assume x, id\ntheorem subset.rfl {s : set \u03b1} : s \u2286 s := subset.refl s\n\n@[trans] theorem subset.trans {a b c : set \u03b1} (ab : a \u2286 b) (bc : b \u2286 c) : a \u2286 c :=\nassume x h, bc (ab h)\n\n@[trans] theorem mem_of_eq_of_mem {x y : \u03b1} {s : set \u03b1} (hx : x = y) (h : y \u2208 s) : x \u2208 s :=\nhx.symm \u25b8 h\n\ntheorem subset.antisymm {a b : set \u03b1} (h\u2081 : a \u2286 b) (h\u2082 : b \u2286 a) : a = b :=\nset.ext $ \u03bb x, \u27e8@h\u2081 _, @h\u2082 _\u27e9\n\ntheorem subset.antisymm_iff {a b : set \u03b1} : a = b \u2194 a \u2286 b \u2227 b \u2286 a :=\n\u27e8\u03bb e, \u27e8e.subset, e.symm.subset\u27e9, \u03bb \u27e8h\u2081, h\u2082\u27e9, subset.antisymm h\u2081 h\u2082\u27e9\n\n-- an alternative name\ntheorem eq_of_subset_of_subset {a b : set \u03b1} : a \u2286 b \u2192 b \u2286 a \u2192 a = b := subset.antisymm\n\ntheorem mem_of_subset_of_mem {s\u2081 s\u2082 : set \u03b1} {a : \u03b1} (h : s\u2081 \u2286 s\u2082) : a \u2208 s\u2081 \u2192 a \u2208 s\u2082 := @h _\n\ntheorem not_mem_subset (h : s \u2286 t) : a \u2209 t \u2192 a \u2209 s :=\nmt $ mem_of_subset_of_mem h\n\ntheorem not_subset : (\u00ac s \u2286 t) \u2194 \u2203a \u2208 s, a \u2209 t := by simp only [subset_def, not_forall]\n\ntheorem nontrivial_mono {\u03b1 : Type*} {s t : set \u03b1} (h\u2081 : s \u2286 t) (h\u2082 : nontrivial s) :\n  nontrivial t :=\nbegin\n  rw nontrivial_iff at h\u2082 \u22a2,\n  obtain \u27e8\u27e8x, hx\u27e9, \u27e8y, hy\u27e9, hxy\u27e9 := h\u2082,\n  exact \u27e8\u27e8x, h\u2081 hx\u27e9, \u27e8y, h\u2081 hy\u27e9, by simpa using hxy\u27e9,\nend\n\n/-! ### Definition of strict subsets `s \u2282 t` and basic properties. -/\n\n@[simp] lemma lt_eq_ssubset : ((<) : set \u03b1 \u2192 set \u03b1 \u2192 Prop) = (\u2282) := rfl\n\nprotected theorem eq_or_ssubset_of_subset (h : s \u2286 t) : s = t \u2228 s \u2282 t :=\neq_or_lt_of_le h\n\nlemma exists_of_ssubset {s t : set \u03b1} (h : s \u2282 t) : (\u2203x\u2208t, x \u2209 s) :=\nnot_subset.1 h.2\n\nprotected lemma ssubset_iff_subset_ne {s t : set \u03b1} : s \u2282 t \u2194 s \u2286 t \u2227 s \u2260 t :=\n@lt_iff_le_and_ne (set \u03b1) _ s t\n\nlemma ssubset_iff_of_subset {s t : set \u03b1} (h : s \u2286 t) : s \u2282 t \u2194 \u2203 x \u2208 t, x \u2209 s :=\n\u27e8exists_of_ssubset, \u03bb \u27e8x, hxt, hxs\u27e9, \u27e8h, \u03bb h, hxs $ h hxt\u27e9\u27e9\n\nprotected lemma ssubset_of_ssubset_of_subset {s\u2081 s\u2082 s\u2083 : set \u03b1} (hs\u2081s\u2082 : s\u2081 \u2282 s\u2082)\n  (hs\u2082s\u2083 : s\u2082 \u2286 s\u2083) :\n  s\u2081 \u2282 s\u2083 :=\n\u27e8subset.trans hs\u2081s\u2082.1 hs\u2082s\u2083, \u03bb hs\u2083s\u2081, hs\u2081s\u2082.2 (subset.trans hs\u2082s\u2083 hs\u2083s\u2081)\u27e9\n\nprotected lemma ssubset_of_subset_of_ssubset {s\u2081 s\u2082 s\u2083 : set \u03b1} (hs\u2081s\u2082 : s\u2081 \u2286 s\u2082)\n  (hs\u2082s\u2083 : s\u2082 \u2282 s\u2083) :\n  s\u2081 \u2282 s\u2083 :=\n\u27e8subset.trans hs\u2081s\u2082 hs\u2082s\u2083.1, \u03bb hs\u2083s\u2081, hs\u2082s\u2083.2 (subset.trans hs\u2083s\u2081 hs\u2081s\u2082)\u27e9\n\ntheorem not_mem_empty (x : \u03b1) : \u00ac (x \u2208 (\u2205 : set \u03b1)) := id\n\n@[simp] theorem not_not_mem : \u00ac (a \u2209 s) \u2194 a \u2208 s := not_not\n\n/-! ### Non-empty sets -/\n\n/-- The property `s.nonempty` expresses the fact that the set `s` is not empty. It should be used\nin theorem assumptions instead of `\u2203 x, x \u2208 s` or `s \u2260 \u2205` as it gives access to a nice API thanks\nto the dot notation. -/\nprotected def nonempty (s : set \u03b1) : Prop := \u2203 x, x \u2208 s\n\n@[simp] lemma nonempty_coe_sort (s : set \u03b1) : nonempty \u21a5s \u2194 s.nonempty := nonempty_subtype\n\nlemma nonempty_def : s.nonempty \u2194 \u2203 x, x \u2208 s := iff.rfl\n\nlemma nonempty_of_mem {x} (h : x \u2208 s) : s.nonempty := \u27e8x, h\u27e9\n\ntheorem nonempty.not_subset_empty : s.nonempty \u2192 \u00ac(s \u2286 \u2205)\n| \u27e8x, hx\u27e9 hs := hs hx\n\ntheorem nonempty.ne_empty : \u2200 {s : set \u03b1}, s.nonempty \u2192 s \u2260 \u2205\n| _ \u27e8x, hx\u27e9 rfl := hx\n\n@[simp] theorem not_nonempty_empty : \u00ac(\u2205 : set \u03b1).nonempty :=\n\u03bb h, h.ne_empty rfl\n\n/-- Extract a witness from `s.nonempty`. This function might be used instead of case analysis\non the argument. Note that it makes a proof depend on the `classical.choice` axiom. -/\nprotected noncomputable def nonempty.some (h : s.nonempty) : \u03b1 := classical.some h\n\nprotected lemma nonempty.some_mem (h : s.nonempty) : h.some \u2208 s := classical.some_spec h\n\nlemma nonempty.mono (ht : s \u2286 t) (hs : s.nonempty) : t.nonempty := hs.imp ht\n\nlemma nonempty_of_not_subset (h : \u00acs \u2286 t) : (s \\ t).nonempty :=\nlet \u27e8x, xs, xt\u27e9 := not_subset.1 h in \u27e8x, xs, xt\u27e9\n\nlemma nonempty_of_ssubset (ht : s \u2282 t) : (t \\ s).nonempty :=\nnonempty_of_not_subset ht.2\n\nlemma nonempty.of_diff (h : (s \\ t).nonempty) : s.nonempty := h.imp $ \u03bb _, and.left\n\nlemma nonempty_of_ssubset' (ht : s \u2282 t) : t.nonempty := (nonempty_of_ssubset ht).of_diff\n\nlemma nonempty.inl (hs : s.nonempty) : (s \u222a t).nonempty := hs.imp $ \u03bb _, or.inl\n\nlemma nonempty.inr (ht : t.nonempty) : (s \u222a t).nonempty := ht.imp $ \u03bb _, or.inr\n\n@[simp] lemma union_nonempty : (s \u222a t).nonempty \u2194 s.nonempty \u2228 t.nonempty := exists_or_distrib\n\nlemma nonempty.left (h : (s \u2229 t).nonempty) : s.nonempty := h.imp $ \u03bb _, and.left\n\nlemma nonempty.right (h : (s \u2229 t).nonempty) : t.nonempty := h.imp $ \u03bb _, and.right\n\nlemma nonempty_inter_iff_exists_right : (s \u2229 t).nonempty \u2194 \u2203 x : t, \u2191x \u2208 s :=\n\u27e8\u03bb \u27e8x, xs, xt\u27e9, \u27e8\u27e8x, xt\u27e9, xs\u27e9, \u03bb \u27e8\u27e8x, xt\u27e9, xs\u27e9, \u27e8x, xs, xt\u27e9\u27e9\n\nlemma nonempty_inter_iff_exists_left : (s \u2229 t).nonempty \u2194 \u2203 x : s, \u2191x \u2208 t :=\n\u27e8\u03bb \u27e8x, xs, xt\u27e9, \u27e8\u27e8x, xs\u27e9, xt\u27e9, \u03bb \u27e8\u27e8x, xt\u27e9, xs\u27e9, \u27e8x, xt, xs\u27e9\u27e9\n\nlemma nonempty_iff_univ_nonempty : nonempty \u03b1 \u2194 (univ : set \u03b1).nonempty :=\n\u27e8\u03bb \u27e8x\u27e9, \u27e8x, trivial\u27e9, \u03bb \u27e8x, _\u27e9, \u27e8x\u27e9\u27e9\n\n@[simp] lemma univ_nonempty : \u2200 [h : nonempty \u03b1], (univ : set \u03b1).nonempty\n| \u27e8x\u27e9 := \u27e8x, trivial\u27e9\n\nlemma nonempty.to_subtype (h : s.nonempty) : nonempty s :=\nnonempty_subtype.2 h\n\ninstance [nonempty \u03b1] : nonempty (set.univ : set \u03b1) := set.univ_nonempty.to_subtype\n\n@[simp] lemma nonempty_insert (a : \u03b1) (s : set \u03b1) : (insert a s).nonempty := \u27e8a, or.inl rfl\u27e9\n\nlemma nonempty_of_nonempty_subtype [nonempty s] : s.nonempty :=\nnonempty_subtype.mp \u2039_\u203a\n\n/-! ### Lemmas about the empty set -/\n\ntheorem empty_def : (\u2205 : set \u03b1) = {x | false} := rfl\n\n@[simp] theorem mem_empty_eq (x : \u03b1) : x \u2208 (\u2205 : set \u03b1) = false := rfl\n\n@[simp] theorem set_of_false : {a : \u03b1 | false} = \u2205 := rfl\n\n@[simp] theorem empty_subset (s : set \u03b1) : \u2205 \u2286 s.\n\ntheorem subset_empty_iff {s : set \u03b1} : s \u2286 \u2205 \u2194 s = \u2205 :=\n(subset.antisymm_iff.trans $ and_iff_left (empty_subset _)).symm\n\ntheorem eq_empty_iff_forall_not_mem {s : set \u03b1} : s = \u2205 \u2194 \u2200 x, x \u2209 s := subset_empty_iff.symm\n\ntheorem eq_empty_of_subset_empty {s : set \u03b1} : s \u2286 \u2205 \u2192 s = \u2205 := subset_empty_iff.1\n\ntheorem eq_empty_of_is_empty [is_empty \u03b1] (s : set \u03b1) : s = \u2205 :=\neq_empty_of_subset_empty $ \u03bb x hx, is_empty_elim x\n\n/-- There is exactly one set of a type that is empty. -/\n-- TODO[gh-6025]: make this an instance once safe to do so\ndef unique_empty [is_empty \u03b1] : unique (set \u03b1) :=\n{ default := \u2205, uniq := eq_empty_of_is_empty }\n\nlemma not_nonempty_iff_eq_empty {s : set \u03b1} : \u00acs.nonempty \u2194 s = \u2205 :=\nby simp only [set.nonempty, eq_empty_iff_forall_not_mem, not_exists]\n\nlemma empty_not_nonempty : \u00ac(\u2205 : set \u03b1).nonempty := \u03bb h, h.ne_empty rfl\n\ntheorem ne_empty_iff_nonempty : s \u2260 \u2205 \u2194 s.nonempty := not_iff_comm.1 not_nonempty_iff_eq_empty\n\nlemma eq_empty_or_nonempty (s : set \u03b1) : s = \u2205 \u2228 s.nonempty :=\nor_iff_not_imp_left.2 ne_empty_iff_nonempty.1\n\ntheorem subset_eq_empty {s t : set \u03b1} (h : t \u2286 s) (e : s = \u2205) : t = \u2205 :=\nsubset_empty_iff.1 $ e \u25b8 h\n\ntheorem ball_empty_iff {p : \u03b1 \u2192 Prop} : (\u2200 x \u2208 (\u2205 : set \u03b1), p x) \u2194 true :=\niff_true_intro $ \u03bb x, false.elim\n\ninstance (\u03b1 : Type u) : is_empty.{u+1} (\u2205 : set \u03b1) :=\n\u27e8\u03bb x, x.2\u27e9\n\n@[simp] lemma empty_ssubset : \u2205 \u2282 s \u2194 s.nonempty :=\n(@bot_lt_iff_ne_bot (set \u03b1) _ _ _).trans ne_empty_iff_nonempty\n\n/-!\n\n### Universal set.\n\nIn Lean `@univ \u03b1` (or `univ : set \u03b1`) is the set that contains all elements of type `\u03b1`.\nMathematically it is the same as `\u03b1` but it has a different type.\n\n-/\n\n@[simp] theorem set_of_true : {x : \u03b1 | true} = univ := rfl\n\n@[simp] theorem mem_univ (x : \u03b1) : x \u2208 @univ \u03b1 := trivial\n\n@[simp] lemma univ_eq_empty_iff : (univ : set \u03b1) = \u2205 \u2194 is_empty \u03b1 :=\neq_empty_iff_forall_not_mem.trans \u27e8\u03bb H, \u27e8\u03bb x, H x trivial\u27e9, \u03bb H x _, @is_empty.false \u03b1 H x\u27e9\n\ntheorem empty_ne_univ [nonempty \u03b1] : (\u2205 : set \u03b1) \u2260 univ :=\n\u03bb e, not_is_empty_of_nonempty \u03b1 $ univ_eq_empty_iff.1 e.symm\n\n@[simp] theorem subset_univ (s : set \u03b1) : s \u2286 univ := \u03bb x H, trivial\n\ntheorem univ_subset_iff {s : set \u03b1} : univ \u2286 s \u2194 s = univ :=\n(subset.antisymm_iff.trans $ and_iff_right (subset_univ _)).symm\n\ntheorem eq_univ_of_univ_subset {s : set \u03b1} : univ \u2286 s \u2192 s = univ := univ_subset_iff.1\n\ntheorem eq_univ_iff_forall {s : set \u03b1} : s = univ \u2194 \u2200 x, x \u2208 s :=\nuniv_subset_iff.symm.trans $ forall_congr $ \u03bb x, imp_iff_right \u27e8\u27e9\n\ntheorem eq_univ_of_forall {s : set \u03b1} : (\u2200 x, x \u2208 s) \u2192 s = univ := eq_univ_iff_forall.2\n\nlemma eq_univ_of_subset {s t : set \u03b1} (h : s \u2286 t) (hs : s = univ) : t = univ :=\neq_univ_of_univ_subset $ hs \u25b8 h\n\nlemma exists_mem_of_nonempty (\u03b1) : \u2200 [nonempty \u03b1], \u2203x:\u03b1, x \u2208 (univ : set \u03b1)\n| \u27e8x\u27e9 := \u27e8x, trivial\u27e9\n\nlemma ne_univ_iff_exists_not_mem {\u03b1 : Type*} (s : set \u03b1) : s \u2260 univ \u2194 \u2203 a, a \u2209 s :=\nby rw [\u2190not_forall, \u2190eq_univ_iff_forall]\n\nlemma not_subset_iff_exists_mem_not_mem {\u03b1 : Type*} {s t : set \u03b1} :\n  \u00ac s \u2286 t \u2194 \u2203 x, x \u2208 s \u2227 x \u2209 t :=\nby simp [subset_def]\n\nlemma univ_unique [unique \u03b1] : @set.univ \u03b1 = {default} :=\nset.ext $ \u03bb x, iff_of_true trivial $ subsingleton.elim x default\n\n/-! ### Lemmas about union -/\n\ntheorem union_def {s\u2081 s\u2082 : set \u03b1} : s\u2081 \u222a s\u2082 = {a | a \u2208 s\u2081 \u2228 a \u2208 s\u2082} := rfl\n\ntheorem mem_union_left {x : \u03b1} {a : set \u03b1} (b : set \u03b1) : x \u2208 a \u2192 x \u2208 a \u222a b := or.inl\n\ntheorem mem_union_right {x : \u03b1} {b : set \u03b1} (a : set \u03b1) : x \u2208 b \u2192 x \u2208 a \u222a b := or.inr\n\ntheorem mem_or_mem_of_mem_union {x : \u03b1} {a b : set \u03b1} (H : x \u2208 a \u222a b) : x \u2208 a \u2228 x \u2208 b := H\n\ntheorem mem_union.elim {x : \u03b1} {a b : set \u03b1} {P : Prop}\n    (H\u2081 : x \u2208 a \u222a b) (H\u2082 : x \u2208 a \u2192 P) (H\u2083 : x \u2208 b \u2192 P) : P :=\nor.elim H\u2081 H\u2082 H\u2083\n\ntheorem mem_union (x : \u03b1) (a b : set \u03b1) : x \u2208 a \u222a b \u2194 x \u2208 a \u2228 x \u2208 b := iff.rfl\n\n@[simp] theorem mem_union_eq (x : \u03b1) (a b : set \u03b1) : x \u2208 a \u222a b = (x \u2208 a \u2228 x \u2208 b) := rfl\n\n@[simp] theorem union_self (a : set \u03b1) : a \u222a a = a := ext $ \u03bb x, or_self _\n\n@[simp] theorem union_empty (a : set \u03b1) : a \u222a \u2205 = a := ext $ \u03bb x, or_false _\n\n@[simp] theorem empty_union (a : set \u03b1) : \u2205 \u222a a = a := ext $ \u03bb x, false_or _\n\ntheorem union_comm (a b : set \u03b1) : a \u222a b = b \u222a a := ext $ \u03bb x, or.comm\n\ntheorem union_assoc (a b c : set \u03b1) : (a \u222a b) \u222a c = a \u222a (b \u222a c) := ext $ \u03bb x, or.assoc\n\ninstance union_is_assoc : is_associative (set \u03b1) (\u222a) := \u27e8union_assoc\u27e9\n\ninstance union_is_comm : is_commutative (set \u03b1) (\u222a) := \u27e8union_comm\u27e9\n\ntheorem union_left_comm (s\u2081 s\u2082 s\u2083 : set \u03b1) : s\u2081 \u222a (s\u2082 \u222a s\u2083) = s\u2082 \u222a (s\u2081 \u222a s\u2083) :=\next $ \u03bb x, or.left_comm\n\ntheorem union_right_comm (s\u2081 s\u2082 s\u2083 : set \u03b1) : (s\u2081 \u222a s\u2082) \u222a s\u2083 = (s\u2081 \u222a s\u2083) \u222a s\u2082 :=\next $ \u03bb x, or.right_comm\n\n@[simp] theorem union_eq_left_iff_subset {s t : set \u03b1} : s \u222a t = s \u2194 t \u2286 s :=\nsup_eq_left\n\n@[simp] theorem union_eq_right_iff_subset {s t : set \u03b1} : s \u222a t = t \u2194 s \u2286 t :=\nsup_eq_right\n\ntheorem union_eq_self_of_subset_left {s t : set \u03b1} (h : s \u2286 t) : s \u222a t = t :=\nunion_eq_right_iff_subset.mpr h\n\ntheorem union_eq_self_of_subset_right {s t : set \u03b1} (h : t \u2286 s) : s \u222a t = s :=\nunion_eq_left_iff_subset.mpr h\n\n@[simp] theorem subset_union_left (s t : set \u03b1) : s \u2286 s \u222a t := \u03bb x, or.inl\n\n@[simp] theorem subset_union_right (s t : set \u03b1) : t \u2286 s \u222a t := \u03bb x, or.inr\n\ntheorem union_subset {s t r : set \u03b1} (sr : s \u2286 r) (tr : t \u2286 r) : s \u222a t \u2286 r :=\n\u03bb x, or.rec (@sr _) (@tr _)\n\n@[simp] theorem union_subset_iff {s t u : set \u03b1} : s \u222a t \u2286 u \u2194 s \u2286 u \u2227 t \u2286 u :=\n(forall_congr (by exact \u03bb x, or_imp_distrib)).trans forall_and_distrib\n\ntheorem union_subset_union {s\u2081 s\u2082 t\u2081 t\u2082 : set \u03b1}\n  (h\u2081 : s\u2081 \u2286 s\u2082) (h\u2082 : t\u2081 \u2286 t\u2082) : s\u2081 \u222a t\u2081 \u2286 s\u2082 \u222a t\u2082 := \u03bb x, or.imp (@h\u2081 _) (@h\u2082 _)\n\ntheorem union_subset_union_left {s\u2081 s\u2082 : set \u03b1} (t) (h : s\u2081 \u2286 s\u2082) : s\u2081 \u222a t \u2286 s\u2082 \u222a t :=\nunion_subset_union h subset.rfl\n\ntheorem union_subset_union_right (s) {t\u2081 t\u2082 : set \u03b1} (h : t\u2081 \u2286 t\u2082) : s \u222a t\u2081 \u2286 s \u222a t\u2082 :=\nunion_subset_union subset.rfl h\n\nlemma subset_union_of_subset_left {s t : set \u03b1} (h : s \u2286 t) (u : set \u03b1) : s \u2286 t \u222a u :=\nsubset.trans h (subset_union_left t u)\n\nlemma subset_union_of_subset_right {s u : set \u03b1} (h : s \u2286 u) (t : set \u03b1) : s \u2286 t \u222a u :=\nsubset.trans h (subset_union_right t u)\n\n@[simp] theorem union_empty_iff {s t : set \u03b1} : s \u222a t = \u2205 \u2194 s = \u2205 \u2227 t = \u2205 :=\nby simp only [\u2190 subset_empty_iff]; exact union_subset_iff\n\n@[simp] lemma union_univ {s : set \u03b1} : s \u222a univ = univ := sup_top_eq\n\n@[simp] lemma univ_union {s : set \u03b1} : univ \u222a s = univ := top_sup_eq\n\n/-! ### Lemmas about intersection -/\n\ntheorem inter_def {s\u2081 s\u2082 : set \u03b1} : s\u2081 \u2229 s\u2082 = {a | a \u2208 s\u2081 \u2227 a \u2208 s\u2082} := rfl\n\ntheorem mem_inter_iff (x : \u03b1) (a b : set \u03b1) : x \u2208 a \u2229 b \u2194 x \u2208 a \u2227 x \u2208 b := iff.rfl\n\n@[simp] theorem mem_inter_eq (x : \u03b1) (a b : set \u03b1) : x \u2208 a \u2229 b = (x \u2208 a \u2227 x \u2208 b) := rfl\n\ntheorem mem_inter {x : \u03b1} {a b : set \u03b1} (ha : x \u2208 a) (hb : x \u2208 b) : x \u2208 a \u2229 b := \u27e8ha, hb\u27e9\n\ntheorem mem_of_mem_inter_left {x : \u03b1} {a b : set \u03b1} (h : x \u2208 a \u2229 b) : x \u2208 a := h.left\n\ntheorem mem_of_mem_inter_right {x : \u03b1} {a b : set \u03b1} (h : x \u2208 a \u2229 b) : x \u2208 b := h.right\n\n@[simp] theorem inter_self (a : set \u03b1) : a \u2229 a = a := ext $ \u03bb x, and_self _\n\n@[simp] theorem inter_empty (a : set \u03b1) : a \u2229 \u2205 = \u2205 := ext $ \u03bb x, and_false _\n\n@[simp] theorem empty_inter (a : set \u03b1) : \u2205 \u2229 a = \u2205 := ext $ \u03bb x, false_and _\n\ntheorem inter_comm (a b : set \u03b1) : a \u2229 b = b \u2229 a := ext $ \u03bb x, and.comm\n\ntheorem inter_assoc (a b c : set \u03b1) : (a \u2229 b) \u2229 c = a \u2229 (b \u2229 c) := ext $ \u03bb x, and.assoc\n\ninstance inter_is_assoc : is_associative (set \u03b1) (\u2229) := \u27e8inter_assoc\u27e9\n\ninstance inter_is_comm : is_commutative (set \u03b1) (\u2229) := \u27e8inter_comm\u27e9\n\ntheorem inter_left_comm (s\u2081 s\u2082 s\u2083 : set \u03b1) : s\u2081 \u2229 (s\u2082 \u2229 s\u2083) = s\u2082 \u2229 (s\u2081 \u2229 s\u2083) :=\next $ \u03bb x, and.left_comm\n\ntheorem inter_right_comm (s\u2081 s\u2082 s\u2083 : set \u03b1) : (s\u2081 \u2229 s\u2082) \u2229 s\u2083 = (s\u2081 \u2229 s\u2083) \u2229 s\u2082 :=\next $ \u03bb x, and.right_comm\n\n@[simp] theorem inter_subset_left (s t : set \u03b1) : s \u2229 t \u2286 s := \u03bb x, and.left\n\n@[simp] theorem inter_subset_right (s t : set \u03b1) : s \u2229 t \u2286 t := \u03bb x, and.right\n\ntheorem subset_inter {s t r : set \u03b1} (rs : r \u2286 s) (rt : r \u2286 t) : r \u2286 s \u2229 t := \u03bb x h, \u27e8rs h, rt h\u27e9\n\n@[simp] theorem subset_inter_iff {s t r : set \u03b1} : r \u2286 s \u2229 t \u2194 r \u2286 s \u2227 r \u2286 t :=\n(forall_congr (by exact \u03bb x, imp_and_distrib)).trans forall_and_distrib\n\n@[simp] theorem inter_eq_left_iff_subset {s t : set \u03b1} : s \u2229 t = s \u2194 s \u2286 t :=\ninf_eq_left\n\n@[simp] theorem inter_eq_right_iff_subset {s t : set \u03b1} : s \u2229 t = t \u2194 t \u2286 s :=\ninf_eq_right\n\ntheorem inter_eq_self_of_subset_left {s t : set \u03b1} : s \u2286 t \u2192 s \u2229 t = s :=\ninter_eq_left_iff_subset.mpr\n\ntheorem inter_eq_self_of_subset_right {s t : set \u03b1} : t \u2286 s \u2192 s \u2229 t = t :=\ninter_eq_right_iff_subset.mpr\n\n@[simp] theorem inter_univ (a : set \u03b1) : a \u2229 univ = a := inf_top_eq\n\n@[simp] theorem univ_inter (a : set \u03b1) : univ \u2229 a = a := top_inf_eq\n\ntheorem inter_subset_inter {s\u2081 s\u2082 t\u2081 t\u2082 : set \u03b1}\n  (h\u2081 : s\u2081 \u2286 t\u2081) (h\u2082 : s\u2082 \u2286 t\u2082) : s\u2081 \u2229 s\u2082 \u2286 t\u2081 \u2229 t\u2082 := \u03bb x, and.imp (@h\u2081 _) (@h\u2082 _)\n\ntheorem inter_subset_inter_left {s t : set \u03b1} (u : set \u03b1) (H : s \u2286 t) : s \u2229 u \u2286 t \u2229 u :=\ninter_subset_inter H subset.rfl\n\ntheorem inter_subset_inter_right {s t : set \u03b1} (u : set \u03b1) (H : s \u2286 t) : u \u2229 s \u2286 u \u2229 t :=\ninter_subset_inter subset.rfl H\n\ntheorem union_inter_cancel_left {s t : set \u03b1} : (s \u222a t) \u2229 s = s :=\ninter_eq_self_of_subset_right $ subset_union_left _ _\n\ntheorem union_inter_cancel_right {s t : set \u03b1} : (s \u222a t) \u2229 t = t :=\ninter_eq_self_of_subset_right $ subset_union_right _ _\n\n/-! ### Distributivity laws -/\n\ntheorem inter_distrib_left (s t u : set \u03b1) : s \u2229 (t \u222a u) = (s \u2229 t) \u222a (s \u2229 u) :=\ninf_sup_left\ntheorem inter_union_distrib_left {s t u : set \u03b1} : s \u2229 (t \u222a u) = (s \u2229 t) \u222a (s \u2229 u) :=\ninf_sup_left\n\ntheorem inter_distrib_right (s t u : set \u03b1) : (s \u222a t) \u2229 u = (s \u2229 u) \u222a (t \u2229 u) :=\ninf_sup_right\ntheorem union_inter_distrib_right {s t u : set \u03b1} : (s \u222a t) \u2229 u = (s \u2229 u) \u222a (t \u2229 u) :=\ninf_sup_right\n\ntheorem union_distrib_left (s t u : set \u03b1) : s \u222a (t \u2229 u) = (s \u222a t) \u2229 (s \u222a u) :=\nsup_inf_left\ntheorem union_inter_distrib_left {s t u : set \u03b1} : s \u222a (t \u2229 u) = (s \u222a t) \u2229 (s \u222a u) :=\nsup_inf_left\n\ntheorem union_distrib_right (s t u : set \u03b1) : (s \u2229 t) \u222a u = (s \u222a u) \u2229 (t \u222a u) :=\nsup_inf_right\ntheorem inter_union_distrib_right {s t u : set \u03b1} : (s \u2229 t) \u222a u = (s \u222a u) \u2229 (t \u222a u) :=\nsup_inf_right\n\n/-!\n### Lemmas about `insert`\n\n`insert \u03b1 s` is the set `{\u03b1} \u222a s`.\n-/\n\ntheorem insert_def (x : \u03b1) (s : set \u03b1) : insert x s = { y | y = x \u2228 y \u2208 s } := rfl\n\n@[simp] theorem subset_insert (x : \u03b1) (s : set \u03b1) : s \u2286 insert x s := \u03bb y, or.inr\n\ntheorem mem_insert (x : \u03b1) (s : set \u03b1) : x \u2208 insert x s := or.inl rfl\n\ntheorem mem_insert_of_mem {x : \u03b1} {s : set \u03b1} (y : \u03b1) : x \u2208 s \u2192 x \u2208 insert y s := or.inr\n\ntheorem eq_or_mem_of_mem_insert {x a : \u03b1} {s : set \u03b1} : x \u2208 insert a s \u2192 x = a \u2228 x \u2208 s := id\n\ntheorem mem_of_mem_insert_of_ne {x a : \u03b1} {s : set \u03b1} : x \u2208 insert a s \u2192 x \u2260 a \u2192 x \u2208 s :=\nor.resolve_left\n\n@[simp] theorem mem_insert_iff {x a : \u03b1} {s : set \u03b1} : x \u2208 insert a s \u2194 x = a \u2228 x \u2208 s := iff.rfl\n\n@[simp] theorem insert_eq_of_mem {a : \u03b1} {s : set \u03b1} (h : a \u2208 s) : insert a s = s :=\next $ \u03bb x, or_iff_right_of_imp $ \u03bb e, e.symm \u25b8 h\n\nlemma ne_insert_of_not_mem {s : set \u03b1} (t : set \u03b1) {a : \u03b1} : a \u2209 s \u2192 s \u2260 insert a t :=\nmt $ \u03bb e, e.symm \u25b8 mem_insert _ _\n\ntheorem insert_subset : insert a s \u2286 t \u2194 (a \u2208 t \u2227 s \u2286 t) :=\nby simp only [subset_def, or_imp_distrib, forall_and_distrib, forall_eq, mem_insert_iff]\n\ntheorem insert_subset_insert (h : s \u2286 t) : insert a s \u2286 insert a t := \u03bb x, or.imp_right (@h _)\n\ntheorem insert_subset_insert_iff (ha : a \u2209 s) : insert a s \u2286 insert a t \u2194 s \u2286 t :=\nbegin\n  refine \u27e8\u03bb h x hx, _, insert_subset_insert\u27e9,\n  rcases h (subset_insert _ _ hx) with (rfl|hxt),\n  exacts [(ha hx).elim, hxt]\nend\n\ntheorem ssubset_iff_insert {s t : set \u03b1} : s \u2282 t \u2194 \u2203 a \u2209 s, insert a s \u2286 t :=\nbegin\n  simp only [insert_subset, exists_and_distrib_right, ssubset_def, not_subset],\n  simp only [exists_prop, and_comm]\nend\n\ntheorem ssubset_insert {s : set \u03b1} {a : \u03b1} (h : a \u2209 s) : s \u2282 insert a s :=\nssubset_iff_insert.2 \u27e8a, h, subset.rfl\u27e9\n\ntheorem insert_comm (a b : \u03b1) (s : set \u03b1) : insert a (insert b s) = insert b (insert a s) :=\next $ \u03bb x, or.left_comm\n\ntheorem insert_union : insert a s \u222a t = insert a (s \u222a t) := ext $ \u03bb x, or.assoc\n\n@[simp] theorem union_insert : s \u222a insert a t = insert a (s \u222a t) := ext $ \u03bb x, or.left_comm\n\ntheorem insert_nonempty (a : \u03b1) (s : set \u03b1) : (insert a s).nonempty := \u27e8a, mem_insert a s\u27e9\n\ninstance (a : \u03b1) (s : set \u03b1) : nonempty (insert a s : set \u03b1) := (insert_nonempty a s).to_subtype\n\nlemma insert_inter (x : \u03b1) (s t : set \u03b1) : insert x (s \u2229 t) = insert x s \u2229 insert x t :=\next $ \u03bb y, or_and_distrib_left\n\n-- useful in proofs by induction\ntheorem forall_of_forall_insert {P : \u03b1 \u2192 Prop} {a : \u03b1} {s : set \u03b1}\n  (H : \u2200 x, x \u2208 insert a s \u2192 P x) (x) (h : x \u2208 s) : P x := H _ (or.inr h)\n\ntheorem forall_insert_of_forall {P : \u03b1 \u2192 Prop} {a : \u03b1} {s : set \u03b1}\n  (H : \u2200 x, x \u2208 s \u2192 P x) (ha : P a) (x) (h : x \u2208 insert a s) : P x :=\nh.elim (\u03bb e, e.symm \u25b8 ha) (H _)\n\ntheorem bex_insert_iff {P : \u03b1 \u2192 Prop} {a : \u03b1} {s : set \u03b1} :\n  (\u2203 x \u2208 insert a s, P x) \u2194 P a \u2228 (\u2203 x \u2208 s, P x) :=\nbex_or_left_distrib.trans $ or_congr_left bex_eq_left\n\ntheorem ball_insert_iff {P : \u03b1 \u2192 Prop} {a : \u03b1} {s : set \u03b1} :\n  (\u2200 x \u2208 insert a s, P x) \u2194 P a \u2227 (\u2200x \u2208 s, P x) :=\nball_or_left_distrib.trans $ and_congr_left' forall_eq\n\n/-! ### Lemmas about singletons -/\n\ntheorem singleton_def (a : \u03b1) : ({a} : set \u03b1) = insert a \u2205 := (insert_emptyc_eq _).symm\n\n@[simp] theorem mem_singleton_iff {a b : \u03b1} : a \u2208 ({b} : set \u03b1) \u2194 a = b := iff.rfl\n\n@[simp] lemma set_of_eq_eq_singleton {a : \u03b1} : {n | n = a} = {a} := rfl\n\n@[simp] lemma set_of_eq_eq_singleton' {a : \u03b1} : {x | a = x} = {a} := ext $ \u03bb x, eq_comm\n\n-- TODO: again, annotation needed\n@[simp] theorem mem_singleton (a : \u03b1) : a \u2208 ({a} : set \u03b1) := @rfl _ _\n\ntheorem eq_of_mem_singleton {x y : \u03b1} (h : x \u2208 ({y} : set \u03b1)) : x = y := h\n\n@[simp] theorem singleton_eq_singleton_iff {x y : \u03b1} : {x} = ({y} : set \u03b1) \u2194 x = y :=\next_iff.trans eq_iff_eq_cancel_left\n\nlemma singleton_injective : injective (singleton : \u03b1 \u2192 set \u03b1) :=\n\u03bb _ _, singleton_eq_singleton_iff.mp\n\ntheorem mem_singleton_of_eq {x y : \u03b1} (H : x = y) : x \u2208 ({y} : set \u03b1) := H\n\ntheorem insert_eq (x : \u03b1) (s : set \u03b1) : insert x s = ({x} : set \u03b1) \u222a s := rfl\n\n@[simp] theorem pair_eq_singleton (a : \u03b1) : ({a, a} : set \u03b1) = {a} := union_self _\n\ntheorem pair_comm (a b : \u03b1) : ({a, b} : set \u03b1) = {b, a} := union_comm _ _\n\n@[simp] theorem singleton_nonempty (a : \u03b1) : ({a} : set \u03b1).nonempty :=\n\u27e8a, rfl\u27e9\n\n@[simp] theorem singleton_subset_iff {a : \u03b1} {s : set \u03b1} : {a} \u2286 s \u2194 a \u2208 s := forall_eq\n\ntheorem set_compr_eq_eq_singleton {a : \u03b1} : {b | b = a} = {a} := rfl\n\n@[simp] theorem singleton_union : {a} \u222a s = insert a s := rfl\n\n@[simp] theorem union_singleton : s \u222a {a} = insert a s := union_comm _ _\n\n@[simp] theorem singleton_inter_nonempty : ({a} \u2229 s).nonempty \u2194 a \u2208 s :=\nby simp only [set.nonempty, mem_inter_eq, mem_singleton_iff, exists_eq_left]\n\n@[simp] theorem inter_singleton_nonempty : (s \u2229 {a}).nonempty \u2194 a \u2208 s :=\nby rw [inter_comm, singleton_inter_nonempty]\n\n@[simp] theorem singleton_inter_eq_empty : {a} \u2229 s = \u2205 \u2194 a \u2209 s :=\nnot_nonempty_iff_eq_empty.symm.trans singleton_inter_nonempty.not\n\n@[simp] theorem inter_singleton_eq_empty : s \u2229 {a} = \u2205 \u2194 a \u2209 s :=\nby rw [inter_comm, singleton_inter_eq_empty]\n\nlemma nmem_singleton_empty {s : set \u03b1} : s \u2209 ({\u2205} : set (set \u03b1)) \u2194 s.nonempty :=\nne_empty_iff_nonempty\n\ninstance unique_singleton (a : \u03b1) : unique \u21a5({a} : set \u03b1) :=\n\u27e8\u27e8\u27e8a, mem_singleton a\u27e9\u27e9, \u03bb \u27e8x, h\u27e9, subtype.eq h\u27e9\n\nlemma eq_singleton_iff_unique_mem : s = {a} \u2194 a \u2208 s \u2227 \u2200 x \u2208 s, x = a :=\nsubset.antisymm_iff.trans $ and.comm.trans $ and_congr_left' singleton_subset_iff\n\nlemma eq_singleton_iff_nonempty_unique_mem : s = {a} \u2194 s.nonempty \u2227 \u2200 x \u2208 s, x = a :=\neq_singleton_iff_unique_mem.trans $ and_congr_left $ \u03bb H, \u27e8\u03bb h', \u27e8_, h'\u27e9, \u03bb \u27e8x, h\u27e9, H x h \u25b8 h\u27e9\n\nlemma exists_eq_singleton_iff_nonempty_unique_mem :\n  (\u2203 a : \u03b1, s = {a}) \u2194 (s.nonempty \u2227 \u2200 a b \u2208 s, a = b) :=\nbegin\n  refine \u27e8_, \u03bb h, _\u27e9,\n  { rintros \u27e8a, rfl\u27e9,\n    refine \u27e8set.singleton_nonempty a, \u03bb b hb c hc, hb.trans hc.symm\u27e9 },\n  { obtain \u27e8a, ha\u27e9 := h.1,\n    refine \u27e8a, set.eq_singleton_iff_unique_mem.mpr \u27e8ha, \u03bb b hb, (h.2 b hb a ha)\u27e9\u27e9 },\nend\n\n-- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS.\n@[simp] lemma default_coe_singleton (x : \u03b1) : (default : ({x} : set \u03b1)) = \u27e8x, rfl\u27e9 := rfl\n\n/-! ### Lemmas about sets defined as `{x \u2208 s | p x}`. -/\n\ntheorem mem_sep {s : set \u03b1} {p : \u03b1 \u2192 Prop} {x : \u03b1} (xs : x \u2208 s) (px : p x) : x \u2208 {x \u2208 s | p x} :=\n\u27e8xs, px\u27e9\n\n@[simp] theorem sep_mem_eq {s t : set \u03b1} : {x \u2208 s | x \u2208 t} = s \u2229 t := rfl\n\n@[simp] theorem mem_sep_eq {s : set \u03b1} {p : \u03b1 \u2192 Prop} {x : \u03b1} :\n  x \u2208 {x \u2208 s | p x} = (x \u2208 s \u2227 p x) := rfl\n\ntheorem mem_sep_iff {s : set \u03b1} {p : \u03b1 \u2192 Prop} {x : \u03b1} : x \u2208 {x \u2208 s | p x} \u2194 x \u2208 s \u2227 p x :=\niff.rfl\n\ntheorem eq_sep_of_subset {s t : set \u03b1} (h : s \u2286 t) : s = {x \u2208 t | x \u2208 s} :=\n(inter_eq_self_of_subset_right h).symm\n\n@[simp] theorem sep_subset (s : set \u03b1) (p : \u03b1 \u2192 Prop) : {x \u2208 s | p x} \u2286 s := \u03bb x, and.left\n\n@[simp] lemma sep_empty (p : \u03b1 \u2192 Prop) : {x \u2208 (\u2205 : set \u03b1) | p x} = \u2205 :=\nby { ext, exact false_and _ }\n\ntheorem forall_not_of_sep_empty {s : set \u03b1} {p : \u03b1 \u2192 Prop} (H : {x \u2208 s | p x} = \u2205)\n  (x) : x \u2208 s \u2192 \u00ac p x := not_and.1 (eq_empty_iff_forall_not_mem.1 H x : _)\n\n@[simp] lemma sep_univ {\u03b1} {p : \u03b1 \u2192 Prop} : {a \u2208 (univ : set \u03b1) | p a} = {a | p a} := univ_inter _\n\n@[simp] lemma sep_true : {a \u2208 s | true} = s :=\nby { ext, simp }\n\n@[simp] lemma sep_false : {a \u2208 s | false} = \u2205 :=\nby { ext, simp }\n\nlemma sep_inter_sep {p q : \u03b1 \u2192 Prop} :\n  {x \u2208 s | p x} \u2229 {x \u2208 s | q x} = {x \u2208 s | p x \u2227 q x} :=\nbegin\n  ext,\n  simp_rw [mem_inter_iff, mem_sep_iff],\n  rw [and_and_and_comm, and_self],\nend\n\n@[simp] lemma subset_singleton_iff {\u03b1 : Type*} {s : set \u03b1} {x : \u03b1} : s \u2286 {x} \u2194 \u2200 y \u2208 s, y = x :=\niff.rfl\n\nlemma subset_singleton_iff_eq {s : set \u03b1} {x : \u03b1} : s \u2286 {x} \u2194 s = \u2205 \u2228 s = {x} :=\nbegin\n  obtain (rfl | hs) := s.eq_empty_or_nonempty,\n  use \u27e8\u03bb _, or.inl rfl, \u03bb _, empty_subset _\u27e9,\n  simp [eq_singleton_iff_nonempty_unique_mem, hs, ne_empty_iff_nonempty.2 hs],\nend\n\nlemma ssubset_singleton_iff {s : set \u03b1} {x : \u03b1} : s \u2282 {x} \u2194 s = \u2205 :=\nbegin\n  rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_distrib_right, and_not_self, or_false,\n    and_iff_left_iff_imp],\n  rintro rfl,\n  refine ne_comm.1 (ne_empty_iff_nonempty.2 (singleton_nonempty _)),\nend\n\nlemma eq_empty_of_ssubset_singleton {s : set \u03b1} {x : \u03b1} (hs : s \u2282 {x}) : s = \u2205 :=\nssubset_singleton_iff.1 hs\n\n/-! ### Lemmas about complement -/\n\ntheorem mem_compl {s : set \u03b1} {x : \u03b1} (h : x \u2209 s) : x \u2208 s\u1d9c := h\n\nlemma compl_set_of {\u03b1} (p : \u03b1 \u2192 Prop) : {a | p a}\u1d9c = { a | \u00ac p a } := rfl\n\ntheorem not_mem_of_mem_compl {s : set \u03b1} {x : \u03b1} (h : x \u2208 s\u1d9c) : x \u2209 s := h\n\n@[simp] theorem mem_compl_eq (s : set \u03b1) (x : \u03b1) : x \u2208 s\u1d9c = (x \u2209 s) := rfl\n\ntheorem mem_compl_iff (s : set \u03b1) (x : \u03b1) : x \u2208 s\u1d9c \u2194 x \u2209 s := iff.rfl\n\n@[simp] theorem inter_compl_self (s : set \u03b1) : s \u2229 s\u1d9c = \u2205 := inf_compl_eq_bot\n\n@[simp] theorem compl_inter_self (s : set \u03b1) : s\u1d9c \u2229 s = \u2205 := compl_inf_eq_bot\n\n@[simp] theorem compl_empty : (\u2205 : set \u03b1)\u1d9c = univ := compl_bot\n\n@[simp] theorem compl_union (s t : set \u03b1) : (s \u222a t)\u1d9c = s\u1d9c \u2229 t\u1d9c := compl_sup\n\ntheorem compl_inter (s t : set \u03b1) : (s \u2229 t)\u1d9c = s\u1d9c \u222a t\u1d9c := compl_inf\n\n@[simp] theorem compl_univ : (univ : set \u03b1)\u1d9c = \u2205 := compl_top\n\n@[simp] lemma compl_empty_iff {s : set \u03b1} : s\u1d9c = \u2205 \u2194 s = univ := compl_eq_bot\n\n@[simp] lemma compl_univ_iff {s : set \u03b1} : s\u1d9c = univ \u2194 s = \u2205 := compl_eq_top\n\nlemma nonempty_compl {s : set \u03b1} : s\u1d9c.nonempty \u2194 s \u2260 univ :=\nne_empty_iff_nonempty.symm.trans compl_empty_iff.not\n\nlemma mem_compl_singleton_iff {a x : \u03b1} : x \u2208 ({a} : set \u03b1)\u1d9c \u2194 x \u2260 a :=\nmem_singleton_iff.not\n\nlemma compl_singleton_eq (a : \u03b1) : ({a} : set \u03b1)\u1d9c = {x | x \u2260 a} :=\next $ \u03bb x, mem_compl_singleton_iff\n\n@[simp]\nlemma compl_ne_eq_singleton (a : \u03b1) : ({x | x \u2260 a} : set \u03b1)\u1d9c = {a} :=\nby { ext, simp, }\n\ntheorem union_eq_compl_compl_inter_compl (s t : set \u03b1) : s \u222a t = (s\u1d9c \u2229 t\u1d9c)\u1d9c :=\next $ \u03bb x, or_iff_not_and_not\n\ntheorem inter_eq_compl_compl_union_compl (s t : set \u03b1) : s \u2229 t = (s\u1d9c \u222a t\u1d9c)\u1d9c :=\next $ \u03bb x, and_iff_not_or_not\n\n@[simp] theorem union_compl_self (s : set \u03b1) : s \u222a s\u1d9c = univ := eq_univ_iff_forall.2 $ \u03bb x, em _\n\n@[simp] theorem compl_union_self (s : set \u03b1) : s\u1d9c \u222a s = univ := by rw [union_comm, union_compl_self]\n\ntheorem compl_comp_compl : compl \u2218 compl = @id (set \u03b1) := funext compl_compl\n\ntheorem compl_subset_comm {s t : set \u03b1} : s\u1d9c \u2286 t \u2194 t\u1d9c \u2286 s := @compl_le_iff_compl_le _ s t _\n\n@[simp] lemma compl_subset_compl {s t : set \u03b1} : s\u1d9c \u2286 t\u1d9c \u2194 t \u2286 s := @compl_le_compl_iff_le _ t s _\n\ntheorem subset_union_compl_iff_inter_subset {s t u : set \u03b1} : s \u2286 t \u222a u\u1d9c \u2194 s \u2229 u \u2286 t :=\n(@is_compl_compl _ u _).le_sup_right_iff_inf_left_le\n\ntheorem compl_subset_iff_union {s t : set \u03b1} : s\u1d9c \u2286 t \u2194 s \u222a t = univ :=\niff.symm $ eq_univ_iff_forall.trans $ forall_congr $ \u03bb a, or_iff_not_imp_left\n\ntheorem subset_compl_comm {s t : set \u03b1} : s \u2286 t\u1d9c \u2194 t \u2286 s\u1d9c :=\nforall_congr $ \u03bb a, imp_not_comm\n\ntheorem subset_compl_iff_disjoint {s t : set \u03b1} : s \u2286 t\u1d9c \u2194 s \u2229 t = \u2205 :=\niff.trans (forall_congr $ \u03bb a, and_imp.symm) subset_empty_iff\n\nlemma subset_compl_singleton_iff {a : \u03b1} {s : set \u03b1} : s \u2286 {a}\u1d9c \u2194 a \u2209 s :=\nsubset_compl_comm.trans singleton_subset_iff\n\ntheorem inter_subset (a b c : set \u03b1) : a \u2229 b \u2286 c \u2194 a \u2286 b\u1d9c \u222a c :=\nforall_congr $ \u03bb x, and_imp.trans $ imp_congr_right $ \u03bb _, imp_iff_not_or\n\nlemma inter_compl_nonempty_iff {s t : set \u03b1} : (s \u2229 t\u1d9c).nonempty \u2194 \u00ac s \u2286 t :=\n(not_subset.trans $ exists_congr $ by exact \u03bb x, by simp [mem_compl]).symm\n\n/-! ### Lemmas about set difference -/\n\ntheorem diff_eq (s t : set \u03b1) : s \\ t = s \u2229 t\u1d9c := rfl\n\n@[simp] theorem mem_diff {s t : set \u03b1} (x : \u03b1) : x \u2208 s \\ t \u2194 x \u2208 s \u2227 x \u2209 t := iff.rfl\n\ntheorem mem_diff_of_mem {s t : set \u03b1} {x : \u03b1} (h1 : x \u2208 s) (h2 : x \u2209 t) : x \u2208 s \\ t :=\n\u27e8h1, h2\u27e9\n\ntheorem mem_of_mem_diff {s t : set \u03b1} {x : \u03b1} (h : x \u2208 s \\ t) : x \u2208 s :=\nh.left\n\ntheorem not_mem_of_mem_diff {s t : set \u03b1} {x : \u03b1} (h : x \u2208 s \\ t) : x \u2209 t :=\nh.right\n\ntheorem diff_eq_compl_inter {s t : set \u03b1} : s \\ t = t\u1d9c \u2229 s :=\nby rw [diff_eq, inter_comm]\n\n\n\ntheorem diff_subset (s t : set \u03b1) : s \\ t \u2286 s := show s \\ t \u2264 s, from sdiff_le\n\ntheorem union_diff_cancel' {s t u : set \u03b1} (h\u2081 : s \u2286 t) (h\u2082 : t \u2286 u) : t \u222a (u \\ s) = u :=\nsup_sdiff_cancel' h\u2081 h\u2082\n\ntheorem union_diff_cancel {s t : set \u03b1} (h : s \u2286 t) : s \u222a (t \\ s) = t :=\nsup_sdiff_cancel_right h\n\ntheorem union_diff_cancel_left {s t : set \u03b1} (h : s \u2229 t \u2286 \u2205) : (s \u222a t) \\ s = t :=\ndisjoint.sup_sdiff_cancel_left h\n\ntheorem union_diff_cancel_right {s t : set \u03b1} (h : s \u2229 t \u2286 \u2205) : (s \u222a t) \\ t = s :=\ndisjoint.sup_sdiff_cancel_right h\n\n@[simp] theorem union_diff_left {s t : set \u03b1} : (s \u222a t) \\ s = t \\ s :=\nsup_sdiff_left_self\n\n@[simp] theorem union_diff_right {s t : set \u03b1} : (s \u222a t) \\ t = s \\ t :=\nsup_sdiff_right_self\n\ntheorem union_diff_distrib {s t u : set \u03b1} : (s \u222a t) \\ u = s \\ u \u222a t \\ u :=\nsup_sdiff\n\ntheorem inter_diff_assoc (a b c : set \u03b1) : (a \u2229 b) \\ c = a \u2229 (b \\ c) :=\ninf_sdiff_assoc\n\n@[simp] theorem inter_diff_self (a b : set \u03b1) : a \u2229 (b \\ a) = \u2205 :=\ninf_sdiff_self_right\n\n@[simp] theorem inter_union_diff (s t : set \u03b1) : (s \u2229 t) \u222a (s \\ t) = s :=\nsup_inf_sdiff s t\n\n@[simp] lemma diff_union_inter (s t : set \u03b1) : (s \\ t) \u222a (s \u2229 t) = s :=\nby { rw union_comm, exact sup_inf_sdiff _ _ }\n\n@[simp] theorem inter_union_compl (s t : set \u03b1) : (s \u2229 t) \u222a (s \u2229 t\u1d9c) = s := inter_union_diff _ _\n\ntheorem diff_subset_diff {s\u2081 s\u2082 t\u2081 t\u2082 : set \u03b1} : s\u2081 \u2286 s\u2082 \u2192 t\u2082 \u2286 t\u2081 \u2192 s\u2081 \\ t\u2081 \u2286 s\u2082 \\ t\u2082 :=\nshow s\u2081 \u2264 s\u2082 \u2192 t\u2082 \u2264 t\u2081 \u2192 s\u2081 \\ t\u2081 \u2264 s\u2082 \\ t\u2082, from sdiff_le_sdiff\n\ntheorem diff_subset_diff_left {s\u2081 s\u2082 t : set \u03b1} (h : s\u2081 \u2286 s\u2082) : s\u2081 \\ t \u2286 s\u2082 \\ t :=\nsdiff_le_sdiff_right \u2039s\u2081 \u2264 s\u2082\u203a\n\ntheorem diff_subset_diff_right {s t u : set \u03b1} (h : t \u2286 u) : s \\ u \u2286 s \\ t :=\nsdiff_le_sdiff_left \u2039t \u2264 u\u203a\n\ntheorem compl_eq_univ_diff (s : set \u03b1) : s\u1d9c = univ \\ s :=\ntop_sdiff.symm\n\n@[simp] lemma empty_diff (s : set \u03b1) : (\u2205 \\ s : set \u03b1) = \u2205 :=\nbot_sdiff\n\ntheorem diff_eq_empty {s t : set \u03b1} : s \\ t = \u2205 \u2194 s \u2286 t :=\nsdiff_eq_bot_iff\n\n@[simp] theorem diff_empty {s : set \u03b1} : s \\ \u2205 = s :=\nsdiff_bot\n\n@[simp] lemma diff_univ (s : set \u03b1) : s \\ univ = \u2205 := diff_eq_empty.2 (subset_univ s)\n\ntheorem diff_diff {u : set \u03b1} : s \\ t \\ u = s \\ (t \u222a u) :=\nsdiff_sdiff_left\n\n-- the following statement contains parentheses to help the reader\nlemma diff_diff_comm {s t u : set \u03b1} : (s \\ t) \\ u = (s \\ u) \\ t :=\nsdiff_sdiff_comm\n\nlemma diff_subset_iff {s t u : set \u03b1} : s \\ t \u2286 u \u2194 s \u2286 t \u222a u :=\nshow s \\ t \u2264 u \u2194 s \u2264 t \u222a u, from sdiff_le_iff\n\nlemma subset_diff_union (s t : set \u03b1) : s \u2286 (s \\ t) \u222a t :=\nshow s \u2264 (s \\ t) \u222a t, from le_sdiff_sup\n\nlemma diff_union_of_subset {s t : set \u03b1} (h : t \u2286 s) :\n  (s \\ t) \u222a t = s :=\nsubset.antisymm (union_subset (diff_subset _ _) h) (subset_diff_union _ _)\n\n@[simp] lemma diff_singleton_subset_iff {x : \u03b1} {s t : set \u03b1} : s \\ {x} \u2286 t \u2194 s \u2286 insert x t :=\nby { rw [\u2190union_singleton, union_comm], apply diff_subset_iff }\n\nlemma subset_diff_singleton {x : \u03b1} {s t : set \u03b1} (h : s \u2286 t) (hx : x \u2209 s) : s \u2286 t \\ {x} :=\nsubset_inter h $ subset_compl_comm.1 $ singleton_subset_iff.2 hx\n\nlemma subset_insert_diff_singleton (x : \u03b1) (s : set \u03b1) : s \u2286 insert x (s \\ {x}) :=\nby rw [\u2190diff_singleton_subset_iff]\n\nlemma diff_subset_comm {s t u : set \u03b1} : s \\ t \u2286 u \u2194 s \\ u \u2286 t :=\nshow s \\ t \u2264 u \u2194 s \\ u \u2264 t, from sdiff_le_comm\n\nlemma diff_inter {s t u : set \u03b1} : s \\ (t \u2229 u) = (s \\ t) \u222a (s \\ u) :=\nsdiff_inf\n\nlemma diff_inter_diff {s t u : set \u03b1} : s \\ t \u2229 (s \\ u) = s \\ (t \u222a u) :=\nsdiff_sup.symm\n\nlemma diff_compl : s \\ t\u1d9c = s \u2229 t := sdiff_compl\n\nlemma diff_diff_right {s t u : set \u03b1} : s \\ (t \\ u) = (s \\ t) \u222a (s \u2229 u) :=\nsdiff_sdiff_right'\n\n@[simp] theorem insert_diff_of_mem (s) (h : a \u2208 t) : insert a s \\ t = s \\ t :=\nby { ext, split; simp [or_imp_distrib, h] {contextual := tt} }\n\ntheorem insert_diff_of_not_mem (s) (h : a \u2209 t) : insert a s \\ t = insert a (s \\ t) :=\nbegin\n  classical,\n  ext x,\n  by_cases h' : x \u2208 t,\n  { have : x \u2260 a,\n    { assume H,\n      rw H at h',\n      exact h h' },\n    simp [h, h', this] },\n  { simp [h, h'] }\nend\n\nlemma insert_diff_self_of_not_mem {a : \u03b1} {s : set \u03b1} (h : a \u2209 s) :\n  insert a s \\ {a} = s :=\nby { ext, simp [and_iff_left_of_imp (\u03bb hx : x \u2208 s, show x \u2260 a, from \u03bb hxa, h $ hxa \u25b8 hx)] }\n\nlemma insert_inter_of_mem {s\u2081 s\u2082 : set \u03b1} {a : \u03b1} (h : a \u2208 s\u2082) :\n  insert a s\u2081 \u2229 s\u2082 = insert a (s\u2081 \u2229 s\u2082) :=\nby simp [set.insert_inter, h]\n\nlemma insert_inter_of_not_mem {s\u2081 s\u2082 : set \u03b1} {a : \u03b1} (h : a \u2209 s\u2082) :\n  insert a s\u2081 \u2229 s\u2082 = s\u2081 \u2229 s\u2082 :=\nbegin\n  ext x,\n  simp only [mem_inter_iff, mem_insert_iff, mem_inter_eq, and.congr_left_iff, or_iff_right_iff_imp],\n  cc,\nend\n\n@[simp] theorem union_diff_self {s t : set \u03b1} : s \u222a (t \\ s) = s \u222a t :=\nsup_sdiff_self_right\n\n@[simp] theorem diff_union_self {s t : set \u03b1} : (s \\ t) \u222a t = s \u222a t :=\nsup_sdiff_self_left\n\n@[simp] theorem diff_inter_self {a b : set \u03b1} : (b \\ a) \u2229 a = \u2205 :=\ninf_sdiff_self_left\n\n@[simp] theorem diff_inter_self_eq_diff {s t : set \u03b1} : s \\ (t \u2229 s) = s \\ t :=\nsdiff_inf_self_right\n\n@[simp] theorem diff_self_inter {s t : set \u03b1} : s \\ (s \u2229 t) = s \\ t :=\nsdiff_inf_self_left\n\n@[simp] theorem diff_eq_self {s t : set \u03b1} : s \\ t = s \u2194 t \u2229 s \u2286 \u2205 :=\nshow s \\ t = s \u2194 t \u2293 s \u2264 \u22a5, from sdiff_eq_self_iff_disjoint\n\n@[simp] theorem diff_singleton_eq_self {a : \u03b1} {s : set \u03b1} (h : a \u2209 s) : s \\ {a} = s :=\ndiff_eq_self.2 $ by simp [singleton_inter_eq_empty.2 h]\n\n@[simp] theorem insert_diff_singleton {a : \u03b1} {s : set \u03b1} :\n  insert a (s \\ {a}) = insert a s :=\nby simp [insert_eq, union_diff_self, -union_singleton, -singleton_union]\n\n@[simp] lemma diff_self {s : set \u03b1} : s \\ s = \u2205 := sdiff_self\n\nlemma diff_diff_cancel_left {s t : set \u03b1} (h : s \u2286 t) : t \\ (t \\ s) = s :=\nsdiff_sdiff_eq_self h\n\nlemma mem_diff_singleton {x y : \u03b1} {s : set \u03b1} : x \u2208 s \\ {y} \u2194 (x \u2208 s \u2227 x \u2260 y) :=\niff.rfl\n\nlemma mem_diff_singleton_empty {s : set \u03b1} {t : set (set \u03b1)} :\n  s \u2208 t \\ {\u2205} \u2194 (s \u2208 t \u2227 s.nonempty) :=\nmem_diff_singleton.trans $ iff.rfl.and ne_empty_iff_nonempty\n\nlemma union_eq_diff_union_diff_union_inter (s t : set \u03b1) :\n  s \u222a t = (s \\ t) \u222a (t \\ s) \u222a (s \u2229 t) :=\nsup_eq_sdiff_sup_sdiff_sup_inf\n\n/-! ### Powerset -/\n\ntheorem mem_powerset {x s : set \u03b1} (h : x \u2286 s) : x \u2208 powerset s := h\n\ntheorem subset_of_mem_powerset {x s : set \u03b1} (h : x \u2208 powerset s) : x \u2286 s := h\n\n@[simp] theorem mem_powerset_iff (x s : set \u03b1) : x \u2208 powerset s \u2194 x \u2286 s := iff.rfl\n\ntheorem powerset_inter (s t : set \u03b1) : \ud835\udcab (s \u2229 t) = \ud835\udcab s \u2229 \ud835\udcab t :=\next $ \u03bb u, subset_inter_iff\n\n@[simp] theorem powerset_mono : \ud835\udcab s \u2286 \ud835\udcab t \u2194 s \u2286 t :=\n\u27e8\u03bb h, h (subset.refl s), \u03bb h u hu, subset.trans hu h\u27e9\n\ntheorem monotone_powerset : monotone (powerset : set \u03b1 \u2192 set (set \u03b1)) :=\n\u03bb s t, powerset_mono.2\n\n@[simp] theorem powerset_nonempty : (\ud835\udcab s).nonempty :=\n\u27e8\u2205, empty_subset s\u27e9\n\n@[simp] theorem powerset_empty : \ud835\udcab (\u2205 : set \u03b1) = {\u2205} :=\next $ \u03bb s, subset_empty_iff\n\n@[simp] theorem powerset_univ : \ud835\udcab (univ : set \u03b1) = univ :=\neq_univ_of_forall subset_univ\n\n/-! ### If-then-else for sets -/\n\n/-- `ite` for sets: `set.ite t s s' \u2229 t = s \u2229 t`, `set.ite t s s' \u2229 t\u1d9c = s' \u2229 t\u1d9c`.\nDefined as `s \u2229 t \u222a s' \\ t`. -/\nprotected def ite (t s s' : set \u03b1) : set \u03b1 := s \u2229 t \u222a s' \\ t\n\n@[simp] lemma ite_inter_self (t s s' : set \u03b1) : t.ite s s' \u2229 t = s \u2229 t :=\nby rw [set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty]\n\n@[simp] lemma ite_compl (t s s' : set \u03b1) : t\u1d9c.ite s s' = t.ite s' s :=\nby rw [set.ite, set.ite, diff_compl, union_comm, diff_eq]\n\n@[simp] lemma ite_inter_compl_self (t s s' : set \u03b1) : t.ite s s' \u2229 t\u1d9c = s' \u2229 t\u1d9c :=\nby rw [\u2190 ite_compl, ite_inter_self]\n\n@[simp] lemma ite_diff_self (t s s' : set \u03b1) : t.ite s s' \\ t = s' \\ t :=\nite_inter_compl_self t s s'\n\n@[simp] lemma ite_same (t s : set \u03b1) : t.ite s s = s := inter_union_diff _ _\n\n@[simp] lemma ite_left (s t : set \u03b1) : s.ite s t = s \u222a t := by simp [set.ite]\n\n@[simp] lemma ite_right (s t : set \u03b1) : s.ite t s = t \u2229 s := by simp [set.ite]\n\n@[simp] lemma ite_empty (s s' : set \u03b1) : set.ite \u2205 s s' = s' :=\nby simp [set.ite]\n\n@[simp] lemma ite_univ (s s' : set \u03b1) : set.ite univ s s' = s :=\nby simp [set.ite]\n\n@[simp] lemma ite_empty_left (t s : set \u03b1) : t.ite \u2205 s = s \\ t :=\nby simp [set.ite]\n\n@[simp] lemma ite_empty_right (t s : set \u03b1) : t.ite s \u2205 = s \u2229 t :=\nby simp [set.ite]\n\nlemma ite_mono (t : set \u03b1) {s\u2081 s\u2081' s\u2082 s\u2082' : set \u03b1} (h : s\u2081 \u2286 s\u2082) (h' : s\u2081' \u2286 s\u2082') :\n  t.ite s\u2081 s\u2081' \u2286 t.ite s\u2082 s\u2082' :=\nunion_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')\n\nlemma ite_subset_union (t s s' : set \u03b1) : t.ite s s' \u2286 s \u222a s' :=\nunion_subset_union (inter_subset_left _ _) (diff_subset _ _)\n\nlemma inter_subset_ite (t s s' : set \u03b1) : s \u2229 s' \u2286 t.ite s s' :=\nite_same t (s \u2229 s') \u25b8 ite_mono _ (inter_subset_left _ _) (inter_subset_right _ _)\n\nlemma ite_inter_inter (t s\u2081 s\u2082 s\u2081' s\u2082' : set \u03b1) :\n  t.ite (s\u2081 \u2229 s\u2082) (s\u2081' \u2229 s\u2082') = t.ite s\u2081 s\u2081' \u2229 t.ite s\u2082 s\u2082' :=\nby { ext x, simp only [set.ite, set.mem_inter_eq, set.mem_diff, set.mem_union_eq], itauto }\n\nlemma ite_inter (t s\u2081 s\u2082 s : set \u03b1) :\n  t.ite (s\u2081 \u2229 s) (s\u2082 \u2229 s) = t.ite s\u2081 s\u2082 \u2229 s :=\nby rw [ite_inter_inter, ite_same]\n\nlemma ite_inter_of_inter_eq (t : set \u03b1) {s\u2081 s\u2082 s : set \u03b1} (h : s\u2081 \u2229 s = s\u2082 \u2229 s) :\n  t.ite s\u2081 s\u2082 \u2229 s = s\u2081 \u2229 s :=\nby rw [\u2190 ite_inter, \u2190 h, ite_same]\n\nlemma subset_ite {t s s' u : set \u03b1} : u \u2286 t.ite s s' \u2194 u \u2229 t \u2286 s \u2227 u \\ t \u2286 s' :=\nbegin\n  simp only [subset_def, \u2190 forall_and_distrib],\n  refine forall_congr (\u03bb x, _),\n  by_cases hx : x \u2208 t; simp [*, set.ite]\nend\n\n/-! ### Inverse image -/\n\n/-- The preimage of `s : set \u03b2` by `f : \u03b1 \u2192 \u03b2`, written `f \u207b\u00b9' s`,\n  is the set of `x : \u03b1` such that `f x \u2208 s`. -/\ndef preimage {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (s : set \u03b2) : set \u03b1 := {x | f x \u2208 s}\n\ninfix ` \u207b\u00b9' `:80 := preimage\n\nsection preimage\nvariables {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3}\n\n@[simp] theorem preimage_empty : f \u207b\u00b9' \u2205 = \u2205 := rfl\n\n@[simp] theorem mem_preimage {s : set \u03b2} {a : \u03b1} : (a \u2208 f \u207b\u00b9' s) \u2194 (f a \u2208 s) := iff.rfl\n\nlemma preimage_congr {f g : \u03b1 \u2192 \u03b2} {s : set \u03b2} (h : \u2200 (x : \u03b1), f x = g x) : f \u207b\u00b9' s = g \u207b\u00b9' s :=\nby { congr' with x, apply_assumption }\n\ntheorem preimage_mono {s t : set \u03b2} (h : s \u2286 t) : f \u207b\u00b9' s \u2286 f \u207b\u00b9' t :=\nassume x hx, h hx\n\n@[simp] theorem preimage_univ : f \u207b\u00b9' univ = univ := rfl\n\ntheorem subset_preimage_univ {s : set \u03b1} : s \u2286 f \u207b\u00b9' univ := subset_univ _\n\n@[simp] theorem preimage_inter {s t : set \u03b2} : f \u207b\u00b9' (s \u2229 t) = f \u207b\u00b9' s \u2229 f \u207b\u00b9' t := rfl\n\n@[simp] theorem preimage_union {s t : set \u03b2} : f \u207b\u00b9' (s \u222a t) = f \u207b\u00b9' s \u222a f \u207b\u00b9' t := rfl\n\n@[simp] theorem preimage_compl {s : set \u03b2} : f \u207b\u00b9' s\u1d9c = (f \u207b\u00b9' s)\u1d9c := rfl\n\n@[simp] theorem preimage_diff (f : \u03b1 \u2192 \u03b2) (s t : set \u03b2) :\n  f \u207b\u00b9' (s \\ t) = f \u207b\u00b9' s \\ f \u207b\u00b9' t := rfl\n\n@[simp] theorem preimage_ite (f : \u03b1 \u2192 \u03b2) (s t\u2081 t\u2082 : set \u03b2) :\n  f \u207b\u00b9' (s.ite t\u2081 t\u2082) = (f \u207b\u00b9' s).ite (f \u207b\u00b9' t\u2081) (f \u207b\u00b9' t\u2082) :=\nrfl\n\n@[simp] theorem preimage_set_of_eq {p : \u03b1 \u2192 Prop} {f : \u03b2 \u2192 \u03b1} : f \u207b\u00b9' {a | p a} = {a | p (f a)} :=\nrfl\n\n@[simp] theorem preimage_id {s : set \u03b1} : id \u207b\u00b9' s = s := rfl\n\n@[simp] theorem preimage_id' {s : set \u03b1} : (\u03bb x, x) \u207b\u00b9' s = s := rfl\n\n@[simp] theorem preimage_const_of_mem {b : \u03b2} {s : set \u03b2} (h : b \u2208 s) :\n  (\u03bb (x : \u03b1), b) \u207b\u00b9' s = univ :=\neq_univ_of_forall $ \u03bb x, h\n\n@[simp] theorem preimage_const_of_not_mem {b : \u03b2} {s : set \u03b2} (h : b \u2209 s) :\n  (\u03bb (x : \u03b1), b) \u207b\u00b9' s = \u2205 :=\neq_empty_of_subset_empty $ \u03bb x hx, h hx\n\ntheorem preimage_const (b : \u03b2) (s : set \u03b2) [decidable (b \u2208 s)] :\n  (\u03bb (x : \u03b1), b) \u207b\u00b9' s = if b \u2208 s then univ else \u2205 :=\nby { split_ifs with hb hb, exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] }\n\ntheorem preimage_comp {s : set \u03b3} : (g \u2218 f) \u207b\u00b9' s = f \u207b\u00b9' (g \u207b\u00b9' s) := rfl\n\nlemma preimage_preimage {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} {s : set \u03b3} :\n  f \u207b\u00b9' (g \u207b\u00b9' s) = (\u03bb x, g (f x)) \u207b\u00b9' s :=\npreimage_comp.symm\n\ntheorem eq_preimage_subtype_val_iff {p : \u03b1 \u2192 Prop} {s : set (subtype p)} {t : set \u03b1} :\n  s = subtype.val \u207b\u00b9' t \u2194 (\u2200x (h : p x), (\u27e8x, h\u27e9 : subtype p) \u2208 s \u2194 x \u2208 t) :=\n\u27e8assume s_eq x h, by { rw [s_eq], simp },\n assume h, ext $ \u03bb \u27e8x, hx\u27e9, by simp [h]\u27e9\n\nlemma nonempty_of_nonempty_preimage {s : set \u03b2} {f : \u03b1 \u2192 \u03b2} (hf : (f \u207b\u00b9' s).nonempty) :\n  s.nonempty :=\nlet \u27e8x, hx\u27e9 := hf in \u27e8f x, hx\u27e9\n\nend preimage\n\n/-! ### Image of a set under a function -/\n\nsection image\n\ninfix ` '' `:80 := image\n\ntheorem mem_image_iff_bex {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {y : \u03b2} :\n  y \u2208 f '' s \u2194 \u2203 x (_ : x \u2208 s), f x = y := bex_def.symm\n\ntheorem mem_image_eq (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (y: \u03b2) : y \u2208 f '' s = \u2203 x, x \u2208 s \u2227 f x = y := rfl\n\n@[simp] theorem mem_image (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (y : \u03b2) :\n  y \u2208 f '' s \u2194 \u2203 x, x \u2208 s \u2227 f x = y := iff.rfl\n\nlemma image_eta (f : \u03b1 \u2192 \u03b2) : f '' s = (\u03bb x, f x) '' s := rfl\n\ntheorem mem_image_of_mem (f : \u03b1 \u2192 \u03b2) {x : \u03b1} {a : set \u03b1} (h : x \u2208 a) : f x \u2208 f '' a :=\n\u27e8_, h, rfl\u27e9\n\ntheorem _root_.function.injective.mem_set_image {f : \u03b1 \u2192 \u03b2} (hf : injective f) {s : set \u03b1} {a : \u03b1} :\n  f a \u2208 f '' s \u2194 a \u2208 s :=\n\u27e8\u03bb \u27e8b, hb, eq\u27e9, (hf eq) \u25b8 hb, mem_image_of_mem f\u27e9\n\ntheorem ball_image_iff {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {p : \u03b2 \u2192 Prop} :\n  (\u2200 y \u2208 f '' s, p y) \u2194 (\u2200 x \u2208 s, p (f x)) :=\nby simp\n\ntheorem ball_image_of_ball {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {p : \u03b2 \u2192 Prop}\n  (h : \u2200 x \u2208 s, p (f x)) : \u2200 y \u2208 f '' s, p y :=\nball_image_iff.2 h\n\ntheorem bex_image_iff {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {p : \u03b2 \u2192 Prop} :\n  (\u2203 y \u2208 f '' s, p y) \u2194 (\u2203 x \u2208 s, p (f x)) :=\nby simp\n\ntheorem mem_image_elim {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {C : \u03b2 \u2192 Prop} (h : \u2200 (x : \u03b1), x \u2208 s \u2192 C (f x)) :\n \u2200{y : \u03b2}, y \u2208 f '' s \u2192 C y\n| ._ \u27e8a, a_in, rfl\u27e9 := h a a_in\n\ntheorem mem_image_elim_on {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {C : \u03b2 \u2192 Prop} {y : \u03b2} (h_y : y \u2208 f '' s)\n  (h : \u2200 (x : \u03b1), x \u2208 s \u2192 C (f x)) : C y :=\nmem_image_elim h h_y\n\n@[congr] lemma image_congr {f g : \u03b1 \u2192 \u03b2} {s : set \u03b1}\n  (h : \u2200a\u2208s, f a = g a) : f '' s = g '' s :=\nby safe [ext_iff, iff_def]\n\n/-- A common special case of `image_congr` -/\nlemma image_congr' {f g : \u03b1 \u2192 \u03b2} {s : set \u03b1} (h : \u2200 (x : \u03b1), f x = g x) : f '' s = g '' s :=\nimage_congr (\u03bbx _, h x)\n\ntheorem image_comp (f : \u03b2 \u2192 \u03b3) (g : \u03b1 \u2192 \u03b2) (a : set \u03b1) : (f \u2218 g) '' a = f '' (g '' a) :=\nsubset.antisymm\n  (ball_image_of_ball $ assume a ha, mem_image_of_mem _ $ mem_image_of_mem _ ha)\n  (ball_image_of_ball $ ball_image_of_ball $ assume a ha, mem_image_of_mem _ ha)\n\n/-- A variant of `image_comp`, useful for rewriting -/\nlemma image_image (g : \u03b2 \u2192 \u03b3) (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) : g '' (f '' s) = (\u03bb x, g (f x)) '' s :=\n(image_comp g f s).symm\n\n/-- Image is monotone with respect to `\u2286`. See `set.monotone_image` for the statement in\nterms of `\u2264`. -/\ntheorem image_subset {a b : set \u03b1} (f : \u03b1 \u2192 \u03b2) (h : a \u2286 b) : f '' a \u2286 f '' b :=\nby { simp only [subset_def, mem_image_eq], exact \u03bb x, \u03bb \u27e8w, h1, h2\u27e9, \u27e8w, h h1, h2\u27e9 }\n\ntheorem image_union (f : \u03b1 \u2192 \u03b2) (s t : set \u03b1) :\n  f '' (s \u222a t) = f '' s \u222a f '' t :=\next $ \u03bb x, \u27e8by rintro \u27e8a, h|h, rfl\u27e9; [left, right]; exact \u27e8_, h, rfl\u27e9,\n  by rintro (\u27e8a, h, rfl\u27e9 | \u27e8a, h, rfl\u27e9); refine \u27e8_, _, rfl\u27e9; [left, right]; exact h\u27e9\n\n@[simp] theorem image_empty (f : \u03b1 \u2192 \u03b2) : f '' \u2205 = \u2205 := by { ext, simp }\n\nlemma image_inter_subset (f : \u03b1 \u2192 \u03b2) (s t : set \u03b1) :\n  f '' (s \u2229 t) \u2286 f '' s \u2229 f '' t :=\nsubset_inter (image_subset _ $ inter_subset_left _ _) (image_subset _ $ inter_subset_right _ _)\n\ntheorem image_inter_on {f : \u03b1 \u2192 \u03b2} {s t : set \u03b1} (h : \u2200x\u2208t, \u2200y\u2208s, f x = f y \u2192 x = y) :\n  f '' s \u2229 f '' t = f '' (s \u2229 t) :=\nsubset.antisymm\n  (assume b \u27e8\u27e8a\u2081, ha\u2081, h\u2081\u27e9, \u27e8a\u2082, ha\u2082, h\u2082\u27e9\u27e9,\n    have a\u2082 = a\u2081, from h _ ha\u2082 _ ha\u2081 (by simp *),\n    \u27e8a\u2081, \u27e8ha\u2081, this \u25b8 ha\u2082\u27e9, h\u2081\u27e9)\n  (image_inter_subset _ _ _)\n\ntheorem image_inter {f : \u03b1 \u2192 \u03b2} {s t : set \u03b1} (H : injective f) :\n  f '' s \u2229 f '' t = f '' (s \u2229 t) :=\nimage_inter_on (assume x _ y _ h, H h)\n\ntheorem image_univ_of_surjective {\u03b9 : Type*} {f : \u03b9 \u2192 \u03b2} (H : surjective f) : f '' univ = univ :=\neq_univ_of_forall $ by { simpa [image] }\n\n@[simp] theorem image_singleton {f : \u03b1 \u2192 \u03b2} {a : \u03b1} : f '' {a} = {f a} :=\nby { ext, simp [image, eq_comm] }\n\n@[simp] theorem nonempty.image_const {s : set \u03b1} (hs : s.nonempty) (a : \u03b2) : (\u03bb _, a) '' s = {a} :=\next $ \u03bb x, \u27e8\u03bb \u27e8y, _, h\u27e9, h \u25b8 mem_singleton _,\n  \u03bb h, (eq_of_mem_singleton h).symm \u25b8 hs.imp (\u03bb y hy, \u27e8hy, rfl\u27e9)\u27e9\n\n@[simp] lemma image_eq_empty {\u03b1 \u03b2} {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} : f '' s = \u2205 \u2194 s = \u2205 :=\nby { simp only [eq_empty_iff_forall_not_mem],\n     exact \u27e8\u03bb H a ha, H _ \u27e8_, ha, rfl\u27e9, \u03bb H b \u27e8_, ha, _\u27e9, H _ ha\u27e9 }\n\n-- TODO(Jeremy): there is an issue with - t unfolding to compl t\ntheorem mem_compl_image (t : set \u03b1) (S : set (set \u03b1)) :\n  t \u2208 compl '' S \u2194 t\u1d9c \u2208 S :=\nbegin\n  suffices : \u2200 x, x\u1d9c = t \u2194 t\u1d9c = x, { simp [this] },\n  intro x, split; { intro e, subst e, simp }\nend\n\n/-- A variant of `image_id` -/\n@[simp] lemma image_id' (s : set \u03b1) : (\u03bbx, x) '' s = s := by { ext, simp }\n\ntheorem image_id (s : set \u03b1) : id '' s = s := by simp\n\ntheorem compl_compl_image (S : set (set \u03b1)) :\n  compl '' (compl '' S) = S :=\nby rw [\u2190 image_comp, compl_comp_compl, image_id]\n\ntheorem image_insert_eq {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} :\n  f '' (insert a s) = insert (f a) (f '' s) :=\nby { ext, simp [and_or_distrib_left, exists_or_distrib, eq_comm, or_comm, and_comm] }\n\ntheorem image_pair (f : \u03b1 \u2192 \u03b2) (a b : \u03b1) : f '' {a, b} = {f a, f b} :=\nby simp only [image_insert_eq, image_singleton]\n\ntheorem image_subset_preimage_of_inverse {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (I : left_inverse g f) (s : set \u03b1) : f '' s \u2286 g \u207b\u00b9' s :=\n\u03bb b \u27e8a, h, e\u27e9, e \u25b8 ((I a).symm \u25b8 h : g (f a) \u2208 s)\n\ntheorem preimage_subset_image_of_inverse {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (I : left_inverse g f) (s : set \u03b2) : f \u207b\u00b9' s \u2286 g '' s :=\n\u03bb b h, \u27e8f b, h, I b\u27e9\n\ntheorem image_eq_preimage_of_inverse {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (h\u2081 : left_inverse g f) (h\u2082 : right_inverse g f) :\n  image f = preimage g :=\nfunext $ \u03bb s, subset.antisymm\n  (image_subset_preimage_of_inverse h\u2081 s)\n  (preimage_subset_image_of_inverse h\u2082 s)\n\ntheorem mem_image_iff_of_inverse {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1} {b : \u03b2} {s : set \u03b1}\n  (h\u2081 : left_inverse g f) (h\u2082 : right_inverse g f) :\n  b \u2208 f '' s \u2194 g b \u2208 s :=\nby rw image_eq_preimage_of_inverse h\u2081 h\u2082; refl\n\ntheorem image_compl_subset {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (H : injective f) : f '' s\u1d9c \u2286 (f '' s)\u1d9c :=\nsubset_compl_iff_disjoint.2 $ by simp [image_inter H]\n\ntheorem subset_image_compl {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (H : surjective f) : (f '' s)\u1d9c \u2286 f '' s\u1d9c :=\ncompl_subset_iff_union.2 $\nby { rw \u2190 image_union, simp [image_univ_of_surjective H] }\n\ntheorem image_compl_eq {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (H : bijective f) : f '' s\u1d9c = (f '' s)\u1d9c :=\nsubset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)\n\ntheorem subset_image_diff (f : \u03b1 \u2192 \u03b2) (s t : set \u03b1) :\n  f '' s \\ f '' t \u2286 f '' (s \\ t) :=\nbegin\n  rw [diff_subset_iff, \u2190 image_union, union_diff_self],\n  exact image_subset f (subset_union_right t s)\nend\n\ntheorem image_diff {f : \u03b1 \u2192 \u03b2} (hf : injective f) (s t : set \u03b1) :\n  f '' (s \\ t) = f '' s \\ f '' t :=\nsubset.antisymm\n  (subset.trans (image_inter_subset _ _ _) $ inter_subset_inter_right _ $ image_compl_subset hf)\n  (subset_image_diff f s t)\n\nlemma nonempty.image (f : \u03b1 \u2192 \u03b2) {s : set \u03b1} : s.nonempty \u2192 (f '' s).nonempty\n| \u27e8x, hx\u27e9 := \u27e8f x, mem_image_of_mem f hx\u27e9\n\nlemma nonempty.of_image {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} : (f '' s).nonempty \u2192 s.nonempty\n| \u27e8y, x, hx, _\u27e9 := \u27e8x, hx\u27e9\n\n@[simp] lemma nonempty_image_iff {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} :\n  (f '' s).nonempty \u2194 s.nonempty :=\n\u27e8nonempty.of_image, \u03bb h, h.image f\u27e9\n\nlemma nonempty.preimage {s : set \u03b2} (hs : s.nonempty) {f : \u03b1 \u2192 \u03b2} (hf : surjective f) :\n  (f \u207b\u00b9' s).nonempty :=\nlet \u27e8y, hy\u27e9 := hs, \u27e8x, hx\u27e9 := hf y in \u27e8x, mem_preimage.2 $ hx.symm \u25b8 hy\u27e9\n\ninstance (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) [nonempty s] : nonempty (f '' s) :=\n(set.nonempty.image f nonempty_of_nonempty_subtype).to_subtype\n\n/-- image and preimage are a Galois connection -/\n@[simp] theorem image_subset_iff {s : set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2} :\n  f '' s \u2286 t \u2194 s \u2286 f \u207b\u00b9' t :=\nball_image_iff\n\ntheorem image_preimage_subset (f : \u03b1 \u2192 \u03b2) (s : set \u03b2) : f '' (f \u207b\u00b9' s) \u2286 s :=\nimage_subset_iff.2 subset.rfl\n\ntheorem subset_preimage_image (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) :\n  s \u2286 f \u207b\u00b9' (f '' s) :=\n\u03bb x, mem_image_of_mem f\n\ntheorem preimage_image_eq {f : \u03b1 \u2192 \u03b2} (s : set \u03b1) (h : injective f) : f \u207b\u00b9' (f '' s) = s :=\nsubset.antisymm\n  (\u03bb x \u27e8y, hy, e\u27e9, h e \u25b8 hy)\n  (subset_preimage_image f s)\n\ntheorem image_preimage_eq {f : \u03b1 \u2192 \u03b2} (s : set \u03b2) (h : surjective f) : f '' (f \u207b\u00b9' s) = s :=\nsubset.antisymm\n  (image_preimage_subset f s)\n  (\u03bb x hx, let \u27e8y, e\u27e9 := h x in \u27e8y, (e.symm \u25b8 hx : f y \u2208 s), e\u27e9)\n\nlemma preimage_eq_preimage {f : \u03b2 \u2192 \u03b1} (hf : surjective f) : f \u207b\u00b9' s = f \u207b\u00b9' t \u2194 s = t :=\niff.intro\n  (assume eq, by rw [\u2190 image_preimage_eq s hf, \u2190 image_preimage_eq t hf, eq])\n  (assume eq, eq \u25b8 rfl)\n\nlemma image_inter_preimage (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (t : set \u03b2) :\n  f '' (s \u2229 f \u207b\u00b9' t) = f '' s \u2229 t :=\nbegin\n  apply subset.antisymm,\n  { calc f '' (s \u2229 f \u207b\u00b9' t) \u2286 f '' s \u2229 (f '' (f\u207b\u00b9' t)) : image_inter_subset _ _ _\n  ... \u2286 f '' s \u2229 t : inter_subset_inter_right _ (image_preimage_subset f t) },\n  { rintros _ \u27e8\u27e8x, h', rfl\u27e9, h\u27e9,\n    exact \u27e8x, \u27e8h', h\u27e9, rfl\u27e9 }\nend\n\nlemma image_preimage_inter (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (t : set \u03b2) :\n  f '' (f \u207b\u00b9' t \u2229 s) = t \u2229 f '' s :=\nby simp only [inter_comm, image_inter_preimage]\n\n@[simp] lemma image_inter_nonempty_iff {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {t : set \u03b2} :\n  (f '' s \u2229 t).nonempty \u2194 (s \u2229 f \u207b\u00b9' t).nonempty :=\nby rw [\u2190image_inter_preimage, nonempty_image_iff]\n\nlemma image_diff_preimage {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {t : set \u03b2} : f '' (s \\ f \u207b\u00b9' t) = f '' s \\ t :=\nby simp_rw [diff_eq, \u2190 preimage_compl, image_inter_preimage]\n\ntheorem compl_image : image (compl : set \u03b1 \u2192 set \u03b1) = preimage compl :=\nimage_eq_preimage_of_inverse compl_compl compl_compl\n\ntheorem compl_image_set_of {p : set \u03b1 \u2192 Prop} :\n  compl '' {s | p s} = {s | p s\u1d9c} :=\ncongr_fun compl_image p\n\ntheorem inter_preimage_subset (s : set \u03b1) (t : set \u03b2) (f : \u03b1 \u2192 \u03b2) :\n  s \u2229 f \u207b\u00b9' t \u2286 f \u207b\u00b9' (f '' s \u2229 t) :=\n\u03bb x h, \u27e8mem_image_of_mem _ h.left, h.right\u27e9\n\ntheorem union_preimage_subset (s : set \u03b1) (t : set \u03b2) (f : \u03b1 \u2192 \u03b2) :\n  s \u222a f \u207b\u00b9' t \u2286 f \u207b\u00b9' (f '' s \u222a t) :=\n\u03bb x h, or.elim h (\u03bb l, or.inl $ mem_image_of_mem _ l) (\u03bb r, or.inr r)\n\ntheorem subset_image_union (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (t : set \u03b2) :\n  f '' (s \u222a f \u207b\u00b9' t) \u2286 f '' s \u222a t :=\nimage_subset_iff.2 (union_preimage_subset _ _ _)\n\nlemma preimage_subset_iff {A : set \u03b1} {B : set \u03b2} {f : \u03b1 \u2192 \u03b2} :\n  f\u207b\u00b9' B \u2286 A \u2194 (\u2200 a : \u03b1, f a \u2208 B \u2192 a \u2208 A) := iff.rfl\n\nlemma image_eq_image {f : \u03b1 \u2192 \u03b2} (hf : injective f) : f '' s = f '' t \u2194 s = t :=\niff.symm $ iff.intro (assume eq, eq \u25b8 rfl) $ assume eq,\n  by rw [\u2190 preimage_image_eq s hf, \u2190 preimage_image_eq t hf, eq]\n\nlemma image_subset_image_iff {f : \u03b1 \u2192 \u03b2} (hf : injective f) : f '' s \u2286 f '' t \u2194 s \u2286 t :=\nbegin\n  refine (iff.symm $ iff.intro (image_subset f) $ assume h, _),\n  rw [\u2190 preimage_image_eq s hf, \u2190 preimage_image_eq t hf],\n  exact preimage_mono h\nend\n\nlemma prod_quotient_preimage_eq_image [s : setoid \u03b1] (g : quotient s \u2192 \u03b2) {h : \u03b1 \u2192 \u03b2}\n  (Hh : h = g \u2218 quotient.mk) (r : set (\u03b2 \u00d7 \u03b2)) :\n  {x : quotient s \u00d7 quotient s | (g x.1, g x.2) \u2208 r} =\n  (\u03bb a : \u03b1 \u00d7 \u03b1, (\u27e6a.1\u27e7, \u27e6a.2\u27e7)) '' ((\u03bb a : \u03b1 \u00d7 \u03b1, (h a.1, h a.2)) \u207b\u00b9' r) :=\nHh.symm \u25b8 set.ext (\u03bb \u27e8a\u2081, a\u2082\u27e9, \u27e8quotient.induction_on\u2082 a\u2081 a\u2082\n  (\u03bb a\u2081 a\u2082 h, \u27e8(a\u2081, a\u2082), h, rfl\u27e9),\n  \u03bb \u27e8\u27e8b\u2081, b\u2082\u27e9, h\u2081, h\u2082\u27e9, show (g a\u2081, g a\u2082) \u2208 r, from\n  have h\u2083 : \u27e6b\u2081\u27e7 = a\u2081 \u2227 \u27e6b\u2082\u27e7 = a\u2082 := prod.ext_iff.1 h\u2082,\n    h\u2083.1 \u25b8 h\u2083.2 \u25b8 h\u2081\u27e9)\n\nlemma exists_image_iff (f : \u03b1 \u2192 \u03b2) (x : set \u03b1) (P : \u03b2 \u2192 Prop) :\n  (\u2203 (a : f '' x), P a) \u2194 \u2203 (a : x), P (f a) :=\n\u27e8\u03bb \u27e8a, h\u27e9, \u27e8\u27e8_, a.prop.some_spec.1\u27e9, a.prop.some_spec.2.symm \u25b8 h\u27e9,\n  \u03bb \u27e8a, h\u27e9, \u27e8\u27e8_, _, a.prop, rfl\u27e9, h\u27e9\u27e9\n\n/-- Restriction of `f` to `s` factors through `s.image_factorization f : s \u2192 f '' s`. -/\ndef image_factorization (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) : s \u2192 f '' s :=\n\u03bb p, \u27e8f p.1, mem_image_of_mem f p.2\u27e9\n\nlemma image_factorization_eq {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} :\n  subtype.val \u2218 image_factorization f s = f \u2218 subtype.val :=\nfunext $ \u03bb p, rfl\n\nlemma surjective_onto_image {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} :\n  surjective (image_factorization f s) :=\n\u03bb \u27e8_, \u27e8a, ha, rfl\u27e9\u27e9, \u27e8\u27e8a, ha\u27e9, rfl\u27e9\n\nend image\n\n/-! ### Subsingleton -/\n\n/-- A set `s` is a `subsingleton`, if it has at most one element. -/\nprotected def subsingleton (s : set \u03b1) : Prop :=\n\u2200 \u2983x\u2984 (hx : x \u2208 s) \u2983y\u2984 (hy : y \u2208 s), x = y\n\nlemma subsingleton.mono (ht : t.subsingleton) (hst : s \u2286 t) : s.subsingleton :=\n\u03bb x hx y hy, ht (hst hx) (hst hy)\n\nlemma subsingleton.image (hs : s.subsingleton) (f : \u03b1 \u2192 \u03b2) : (f '' s).subsingleton :=\n\u03bb _ \u27e8x, hx, Hx\u27e9 _ \u27e8y, hy, Hy\u27e9, Hx \u25b8 Hy \u25b8 congr_arg f (hs hx hy)\n\nlemma subsingleton.eq_singleton_of_mem (hs : s.subsingleton) {x:\u03b1} (hx : x \u2208 s) :\n  s = {x} :=\next $ \u03bb y, \u27e8\u03bb hy, (hs hx hy) \u25b8 mem_singleton _, \u03bb hy, (eq_of_mem_singleton hy).symm \u25b8 hx\u27e9\n\n@[simp] lemma subsingleton_empty : (\u2205 : set \u03b1).subsingleton := \u03bb x, false.elim\n\n@[simp] lemma subsingleton_singleton {a} : ({a} : set \u03b1).subsingleton :=\n\u03bb x hx y hy, (eq_of_mem_singleton hx).symm \u25b8 (eq_of_mem_singleton hy).symm \u25b8 rfl\n\nlemma subsingleton_of_forall_eq (a : \u03b1) (h : \u2200 b \u2208 s, b = a) : s.subsingleton :=\n\u03bb b hb c hc, (h _ hb).trans (h _ hc).symm\n\nlemma subsingleton_iff_singleton {x} (hx : x \u2208 s) : s.subsingleton \u2194 s = {x} :=\n\u27e8\u03bb h, h.eq_singleton_of_mem hx, \u03bb h,h.symm \u25b8 subsingleton_singleton\u27e9\n\nlemma subsingleton.eq_empty_or_singleton (hs : s.subsingleton) :\n  s = \u2205 \u2228 \u2203 x, s = {x} :=\ns.eq_empty_or_nonempty.elim or.inl (\u03bb \u27e8x, hx\u27e9, or.inr \u27e8x, hs.eq_singleton_of_mem hx\u27e9)\n\nlemma subsingleton.induction_on {p : set \u03b1 \u2192 Prop} (hs : s.subsingleton) (he : p \u2205)\n  (h\u2081 : \u2200 x, p {x}) : p s :=\nby { rcases hs.eq_empty_or_singleton with rfl|\u27e8x, rfl\u27e9, exacts [he, h\u2081 _] }\n\nlemma subsingleton_univ [subsingleton \u03b1] : (univ : set \u03b1).subsingleton :=\n\u03bb x hx y hy, subsingleton.elim x y\n\nlemma subsingleton_of_univ_subsingleton (h : (univ : set \u03b1).subsingleton) : subsingleton \u03b1 :=\n\u27e8\u03bb a b, h (mem_univ a) (mem_univ b)\u27e9\n\n@[simp] lemma subsingleton_univ_iff : (univ : set \u03b1).subsingleton \u2194 subsingleton \u03b1 :=\n\u27e8subsingleton_of_univ_subsingleton, \u03bb h, @subsingleton_univ _ h\u27e9\n\nlemma subsingleton_of_subsingleton [subsingleton \u03b1] {s : set \u03b1} : set.subsingleton s :=\nsubsingleton.mono subsingleton_univ (subset_univ s)\n\nlemma subsingleton_is_top (\u03b1 : Type*) [partial_order \u03b1] : set.subsingleton {x : \u03b1 | is_top x} :=\n\u03bb x hx y hy, hx.is_max.eq_of_le (hy x)\n\nlemma subsingleton_is_bot (\u03b1 : Type*) [partial_order \u03b1] : set.subsingleton {x : \u03b1 | is_bot x} :=\n\u03bb x hx y hy, hx.is_min.eq_of_ge (hy x)\n\n/-- `s`, coerced to a type, is a subsingleton type if and only if `s`\nis a subsingleton set. -/\n@[simp, norm_cast] lemma subsingleton_coe (s : set \u03b1) : subsingleton s \u2194 s.subsingleton :=\nbegin\n  split,\n  { refine \u03bb h, (\u03bb a ha b hb, _),\n    exact set_coe.ext_iff.2 (@subsingleton.elim s h \u27e8a, ha\u27e9 \u27e8b, hb\u27e9) },\n  { exact \u03bb h, subsingleton.intro (\u03bb a b, set_coe.ext (h a.property b.property)) }\nend\n\n/-- The `coe_sort` of a set `s` in a subsingleton type is a subsingleton.\nFor the corresponding result for `subtype`, see `subtype.subsingleton`. -/\ninstance subsingleton_coe_of_subsingleton [subsingleton \u03b1] {s : set \u03b1} : subsingleton s :=\nby { rw [s.subsingleton_coe], exact subsingleton_of_subsingleton }\n\n/-- The preimage of a subsingleton under an injective map is a subsingleton. -/\ntheorem subsingleton.preimage {s : set \u03b2} (hs : s.subsingleton) {f : \u03b1 \u2192 \u03b2}\n  (hf : function.injective f) :\n  (f \u207b\u00b9' s).subsingleton :=\n\u03bb a ha b hb, hf $ hs ha hb\n\n/-- `s` is a subsingleton, if its image of an injective function is. -/\ntheorem subsingleton_of_image {\u03b1 \u03b2 : Type*} {f : \u03b1 \u2192 \u03b2} (hf : function.injective f)\n  (s : set \u03b1) (hs : (f '' s).subsingleton) : s.subsingleton :=\n(hs.preimage hf).mono $ subset_preimage_image _ _\n\ntheorem univ_eq_true_false : univ = ({true, false} : set Prop) :=\neq.symm $ eq_univ_of_forall $ classical.cases (by simp) (by simp)\n\n/-! ### Lemmas about range of a function. -/\nsection range\nvariables {f : \u03b9 \u2192 \u03b1}\nopen function\n\n/-- Range of a function.\n\nThis function is more flexible than `f '' univ`, as the image requires that the domain is in Type\nand not an arbitrary Sort. -/\ndef range (f : \u03b9 \u2192 \u03b1) : set \u03b1 := {x | \u2203y, f y = x}\n\n@[simp] theorem mem_range {x : \u03b1} : x \u2208 range f \u2194 \u2203 y, f y = x := iff.rfl\n\n@[simp] theorem mem_range_self (i : \u03b9) : f i \u2208 range f := \u27e8i, rfl\u27e9\n\ntheorem forall_range_iff {p : \u03b1 \u2192 Prop} : (\u2200 a \u2208 range f, p a) \u2194 (\u2200 i, p (f i)) :=\nby simp\n\ntheorem forall_subtype_range_iff {p : range f \u2192 Prop} :\n  (\u2200 a : range f, p a) \u2194 \u2200 i, p \u27e8f i, mem_range_self _\u27e9 :=\n\u27e8\u03bb H i, H _, \u03bb H \u27e8y, i, hi\u27e9, by { subst hi, apply H }\u27e9\n\ntheorem exists_range_iff {p : \u03b1 \u2192 Prop} : (\u2203 a \u2208 range f, p a) \u2194 (\u2203 i, p (f i)) :=\nby simp\n\nlemma exists_range_iff' {p : \u03b1 \u2192 Prop} :\n  (\u2203 a, a \u2208 range f \u2227 p a) \u2194 \u2203 i, p (f i) :=\nby simpa only [exists_prop] using exists_range_iff\n\nlemma exists_subtype_range_iff {p : range f \u2192 Prop} :\n  (\u2203 a : range f, p a) \u2194 \u2203 i, p \u27e8f i, mem_range_self _\u27e9 :=\n\u27e8\u03bb \u27e8\u27e8a, i, hi\u27e9, ha\u27e9, by { subst a, exact \u27e8i, ha\u27e9}, \u03bb \u27e8i, hi\u27e9, \u27e8_, hi\u27e9\u27e9\n\ntheorem range_iff_surjective : range f = univ \u2194 surjective f :=\neq_univ_iff_forall\n\nalias range_iff_surjective \u2194 _ function.surjective.range_eq\n\n@[simp] theorem range_id : range (@id \u03b1) = univ := range_iff_surjective.2 surjective_id\n\n@[simp] theorem range_id' : range (\u03bb (x : \u03b1), x) = univ := range_id\n\n@[simp] theorem _root_.prod.range_fst [nonempty \u03b2] : range (prod.fst : \u03b1 \u00d7 \u03b2 \u2192 \u03b1) = univ :=\nprod.fst_surjective.range_eq\n\n@[simp] theorem _root_.prod.range_snd [nonempty \u03b1] : range (prod.snd : \u03b1 \u00d7 \u03b2 \u2192 \u03b2) = univ :=\nprod.snd_surjective.range_eq\n\n@[simp] theorem range_eval {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Sort*} [\u03a0 i, nonempty (\u03b1 i)] (i : \u03b9) :\n  range (eval i : (\u03a0 i, \u03b1 i) \u2192 \u03b1 i) = univ :=\n(surjective_eval i).range_eq\n\ntheorem is_compl_range_inl_range_inr : is_compl (range $ @sum.inl \u03b1 \u03b2) (range sum.inr) :=\n\u27e8by { rintro y \u27e8\u27e8x\u2081, rfl\u27e9, \u27e8x\u2082, _\u27e9\u27e9, cc },\n  by { rintro (x|y) -; [left, right]; exact mem_range_self _ }\u27e9\n\n@[simp] theorem range_inl_union_range_inr : range (sum.inl : \u03b1 \u2192 \u03b1 \u2295 \u03b2) \u222a range sum.inr = univ :=\nis_compl_range_inl_range_inr.sup_eq_top\n\n@[simp] theorem range_inl_inter_range_inr : range (sum.inl : \u03b1 \u2192 \u03b1 \u2295 \u03b2) \u2229 range sum.inr = \u2205 :=\nis_compl_range_inl_range_inr.inf_eq_bot\n\n@[simp] theorem range_inr_union_range_inl : range (sum.inr : \u03b2 \u2192 \u03b1 \u2295 \u03b2) \u222a range sum.inl = univ :=\nis_compl_range_inl_range_inr.symm.sup_eq_top\n\n@[simp] theorem range_inr_inter_range_inl : range (sum.inr : \u03b2 \u2192 \u03b1 \u2295 \u03b2) \u2229 range sum.inl = \u2205 :=\nis_compl_range_inl_range_inr.symm.inf_eq_bot\n\n@[simp] theorem preimage_inl_range_inr : sum.inl \u207b\u00b9' range (sum.inr : \u03b2 \u2192 \u03b1 \u2295 \u03b2) = \u2205 :=\nby { ext, simp }\n\n@[simp] theorem preimage_inr_range_inl : sum.inr \u207b\u00b9' range (sum.inl : \u03b1 \u2192 \u03b1 \u2295 \u03b2) = \u2205 :=\nby { ext, simp }\n\n@[simp] theorem range_quot_mk (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : range (quot.mk r) = univ :=\n(surjective_quot_mk r).range_eq\n\n@[simp] theorem image_univ {f : \u03b1 \u2192 \u03b2} : f '' univ = range f :=\nby { ext, simp [image, range] }\n\ntheorem image_subset_range (f : \u03b1 \u2192 \u03b2) (s) : f '' s \u2286 range f :=\nby rw \u2190 image_univ; exact image_subset _ (subset_univ _)\n\ntheorem mem_range_of_mem_image (f : \u03b1 \u2192 \u03b2) (s) {x : \u03b2} (h : x \u2208 f '' s) : x \u2208 range f :=\nimage_subset_range f s h\n\nlemma nonempty.preimage' {s : set \u03b2} (hs : s.nonempty) {f : \u03b1 \u2192 \u03b2} (hf : s \u2286 set.range f) :\n  (f \u207b\u00b9' s).nonempty :=\nlet \u27e8y, hy\u27e9 := hs, \u27e8x, hx\u27e9 := hf hy in \u27e8x, set.mem_preimage.2 $ hx.symm \u25b8 hy\u27e9\n\ntheorem range_comp (g : \u03b1 \u2192 \u03b2) (f : \u03b9 \u2192 \u03b1) : range (g \u2218 f) = g '' range f :=\nsubset.antisymm\n  (forall_range_iff.mpr $ assume i, mem_image_of_mem g (mem_range_self _))\n  (ball_image_iff.mpr $ forall_range_iff.mpr mem_range_self)\n\ntheorem range_subset_iff : range f \u2286 s \u2194 \u2200 y, f y \u2208 s :=\nforall_range_iff\n\ntheorem range_eq_iff (f : \u03b1 \u2192 \u03b2) (s : set \u03b2) :\n  range f = s \u2194 (\u2200 a, f a \u2208 s) \u2227 \u2200 b \u2208 s, \u2203 a, f a = b :=\nby { rw \u2190range_subset_iff, exact le_antisymm_iff }\n\nlemma range_comp_subset_range (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3) : range (g \u2218 f) \u2286 range g :=\nby rw range_comp; apply image_subset_range\n\nlemma range_nonempty_iff_nonempty : (range f).nonempty \u2194 nonempty \u03b9 :=\n\u27e8\u03bb \u27e8y, x, hxy\u27e9, \u27e8x\u27e9, \u03bb \u27e8x\u27e9, \u27e8f x, mem_range_self x\u27e9\u27e9\n\nlemma range_nonempty [h : nonempty \u03b9] (f : \u03b9 \u2192 \u03b1) : (range f).nonempty :=\nrange_nonempty_iff_nonempty.2 h\n\n@[simp] lemma range_eq_empty_iff {f : \u03b9 \u2192 \u03b1} : range f = \u2205 \u2194 is_empty \u03b9 :=\nby rw [\u2190 not_nonempty_iff, \u2190 range_nonempty_iff_nonempty, not_nonempty_iff_eq_empty]\n\nlemma range_eq_empty [is_empty \u03b9] (f : \u03b9 \u2192 \u03b1) : range f = \u2205 := range_eq_empty_iff.2 \u2039_\u203a\n\ninstance [nonempty \u03b9] (f : \u03b9 \u2192 \u03b1) : nonempty (range f) := (range_nonempty f).to_subtype\n\n@[simp] lemma image_union_image_compl_eq_range (f : \u03b1 \u2192 \u03b2) :\n  (f '' s) \u222a (f '' s\u1d9c) = range f :=\nby rw [\u2190 image_union, \u2190 image_univ, \u2190 union_compl_self]\n\ntheorem image_preimage_eq_inter_range {f : \u03b1 \u2192 \u03b2} {t : set \u03b2} :\n  f '' (f \u207b\u00b9' t) = t \u2229 range f :=\next $ assume x, \u27e8assume \u27e8x, hx, heq\u27e9, heq \u25b8 \u27e8hx, mem_range_self _\u27e9,\n  assume \u27e8hx, \u27e8y, h_eq\u27e9\u27e9, h_eq \u25b8 mem_image_of_mem f $\n    show y \u2208 f \u207b\u00b9' t, by simp [preimage, h_eq, hx]\u27e9\n\nlemma image_preimage_eq_of_subset {f : \u03b1 \u2192 \u03b2} {s : set \u03b2} (hs : s \u2286 range f) :\n  f '' (f \u207b\u00b9' s) = s :=\nby rw [image_preimage_eq_inter_range, inter_eq_self_of_subset_left hs]\n\ninstance set.can_lift [can_lift \u03b1 \u03b2] : can_lift (set \u03b1) (set \u03b2) :=\n{ coe := \u03bb s, can_lift.coe '' s,\n  cond := \u03bb s, \u2200 x \u2208 s, can_lift.cond \u03b2 x,\n  prf := \u03bb s hs, \u27e8can_lift.coe \u207b\u00b9' s, image_preimage_eq_of_subset $\n    \u03bb x hx, can_lift.prf _ (hs x hx)\u27e9 }\n\nlemma image_preimage_eq_iff {f : \u03b1 \u2192 \u03b2} {s : set \u03b2} : f '' (f \u207b\u00b9' s) = s \u2194 s \u2286 range f :=\n\u27e8by { intro h, rw [\u2190 h], apply image_subset_range }, image_preimage_eq_of_subset\u27e9\n\nlemma preimage_subset_preimage_iff {s t : set \u03b1} {f : \u03b2 \u2192 \u03b1} (hs : s \u2286 range f) :\n  f \u207b\u00b9' s \u2286 f \u207b\u00b9' t \u2194 s \u2286 t :=\nbegin\n  split,\n  { intros h x hx, rcases hs hx with \u27e8y, rfl\u27e9, exact h hx },\n  intros h x, apply h\nend\n\nlemma preimage_eq_preimage' {s t : set \u03b1} {f : \u03b2 \u2192 \u03b1} (hs : s \u2286 range f) (ht : t \u2286 range f) :\n  f \u207b\u00b9' s = f \u207b\u00b9' t \u2194 s = t :=\nbegin\n  split,\n  { intro h, apply subset.antisymm, rw [\u2190preimage_subset_preimage_iff hs, h],\n    rw [\u2190preimage_subset_preimage_iff ht, h] },\n  rintro rfl, refl\nend\n\n@[simp] theorem preimage_inter_range {f : \u03b1 \u2192 \u03b2} {s : set \u03b2} : f \u207b\u00b9' (s \u2229 range f) = f \u207b\u00b9' s :=\nset.ext $ \u03bb x, and_iff_left \u27e8x, rfl\u27e9\n\n@[simp] theorem preimage_range_inter {f : \u03b1 \u2192 \u03b2} {s : set \u03b2} : f \u207b\u00b9' (range f \u2229 s) = f \u207b\u00b9' s :=\nby rw [inter_comm, preimage_inter_range]\n\ntheorem preimage_image_preimage {f : \u03b1 \u2192 \u03b2} {s : set \u03b2} :\n  f \u207b\u00b9' (f '' (f \u207b\u00b9' s)) = f \u207b\u00b9' s :=\nby rw [image_preimage_eq_inter_range, preimage_inter_range]\n\n@[simp] theorem quot_mk_range_eq [setoid \u03b1] : range (\u03bbx : \u03b1, \u27e6x\u27e7) = univ :=\nrange_iff_surjective.2 quot.exists_rep\n\nlemma range_const_subset {c : \u03b1} : range (\u03bbx:\u03b9, c) \u2286 {c} :=\nrange_subset_iff.2 $ \u03bb x, rfl\n\n@[simp] lemma range_const : \u2200 [nonempty \u03b9] {c : \u03b1}, range (\u03bbx:\u03b9, c) = {c}\n| \u27e8x\u27e9 c := subset.antisymm range_const_subset $\n  assume y hy, (mem_singleton_iff.1 hy).symm \u25b8 mem_range_self x\n\nlemma image_swap_eq_preimage_swap : image (@prod.swap \u03b1 \u03b2) = preimage prod.swap :=\nimage_eq_preimage_of_inverse prod.swap_left_inverse prod.swap_right_inverse\n\ntheorem preimage_singleton_nonempty {f : \u03b1 \u2192 \u03b2} {y : \u03b2} :\n  (f \u207b\u00b9' {y}).nonempty \u2194 y \u2208 range f :=\niff.rfl\n\ntheorem preimage_singleton_eq_empty {f : \u03b1 \u2192 \u03b2} {y : \u03b2} :\n  f \u207b\u00b9' {y} = \u2205 \u2194 y \u2209 range f :=\nnot_nonempty_iff_eq_empty.symm.trans preimage_singleton_nonempty.not\n\nlemma range_subset_singleton {f : \u03b9 \u2192 \u03b1} {x : \u03b1} : range f \u2286 {x} \u2194 f = const \u03b9 x :=\nby simp [range_subset_iff, funext_iff, mem_singleton]\n\nlemma image_compl_preimage {f : \u03b1 \u2192 \u03b2} {s : set \u03b2} : f '' ((f \u207b\u00b9' s)\u1d9c) = range f \\ s :=\nby rw [compl_eq_univ_diff, image_diff_preimage, image_univ]\n\n@[simp] theorem range_sigma_mk {\u03b2 : \u03b1 \u2192 Type*} (a : \u03b1) :\n  range (sigma.mk a : \u03b2 a \u2192 \u03a3 a, \u03b2 a) = sigma.fst \u207b\u00b9' {a} :=\nbegin\n  apply subset.antisymm,\n  { rintros _ \u27e8b, rfl\u27e9, simp },\n  { rintros \u27e8x, y\u27e9 (rfl|_),\n    exact mem_range_self y }\nend\n\n/-- Any map `f : \u03b9 \u2192 \u03b2` factors through a map `range_factorization f : \u03b9 \u2192 range f`. -/\ndef range_factorization (f : \u03b9 \u2192 \u03b2) : \u03b9 \u2192 range f :=\n\u03bb i, \u27e8f i, mem_range_self i\u27e9\n\nlemma range_factorization_eq {f : \u03b9 \u2192 \u03b2} :\n  subtype.val \u2218 range_factorization f = f :=\nfunext $ \u03bb i, rfl\n\n@[simp] lemma range_factorization_coe (f : \u03b9 \u2192 \u03b2) (a : \u03b9) :\n  (range_factorization f a : \u03b2) = f a := rfl\n\n@[simp] lemma coe_comp_range_factorization (f : \u03b9 \u2192 \u03b2) : coe \u2218 range_factorization f = f := rfl\n\nlemma surjective_onto_range : surjective (range_factorization f) :=\n\u03bb \u27e8_, \u27e8i, rfl\u27e9\u27e9, \u27e8i, rfl\u27e9\n\nlemma image_eq_range (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) : f '' s = range (\u03bb(x : s), f x) :=\nby { ext, split, rintro \u27e8x, h1, h2\u27e9, exact \u27e8\u27e8x, h1\u27e9, h2\u27e9, rintro \u27e8\u27e8x, h1\u27e9, h2\u27e9, exact \u27e8x, h1, h2\u27e9 }\n\n@[simp] lemma sum.elim_range {\u03b1 \u03b2 \u03b3 : Type*} (f : \u03b1 \u2192 \u03b3) (g : \u03b2 \u2192 \u03b3) :\n  range (sum.elim f g) = range f \u222a range g :=\nby simp [set.ext_iff, mem_range]\n\nlemma range_ite_subset' {p : Prop} [decidable p] {f g : \u03b1 \u2192 \u03b2} :\n  range (if p then f else g) \u2286 range f \u222a range g :=\nbegin\n  by_cases h : p, {rw if_pos h, exact subset_union_left _ _},\n  {rw if_neg h, exact subset_union_right _ _}\nend\n\nlemma range_ite_subset {p : \u03b1 \u2192 Prop} [decidable_pred p] {f g : \u03b1 \u2192 \u03b2} :\n  range (\u03bb x, if p x then f x else g x) \u2286 range f \u222a range g :=\nbegin\n  rw range_subset_iff, intro x, by_cases h : p x,\n  simp [if_pos h, mem_union, mem_range_self],\n  simp [if_neg h, mem_union, mem_range_self]\nend\n\n@[simp] lemma preimage_range (f : \u03b1 \u2192 \u03b2) : f \u207b\u00b9' (range f) = univ :=\neq_univ_of_forall mem_range_self\n\n/-- The range of a function from a `unique` type contains just the\nfunction applied to its single value. -/\nlemma range_unique [h : unique \u03b9] : range f = {f default} :=\nbegin\n  ext x,\n  rw mem_range,\n  split,\n  { rintros \u27e8i, hi\u27e9,\n    rw h.uniq i at hi,\n    exact hi \u25b8 mem_singleton _ },\n  { exact \u03bb h, \u27e8default, h.symm\u27e9 }\nend\n\nlemma range_diff_image_subset (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) :\n  range f \\ f '' s \u2286 f '' s\u1d9c :=\n\u03bb y \u27e8\u27e8x, h\u2081\u27e9, h\u2082\u27e9, \u27e8x, \u03bb h, h\u2082 \u27e8x, h, h\u2081\u27e9, h\u2081\u27e9\n\nlemma range_diff_image {f : \u03b1 \u2192 \u03b2} (H : injective f) (s : set \u03b1) :\n  range f \\ f '' s = f '' s\u1d9c :=\nsubset.antisymm (range_diff_image_subset f s) $ \u03bb y \u27e8x, hx, hy\u27e9, hy \u25b8\n  \u27e8mem_range_self _, \u03bb \u27e8x', hx', eq\u27e9, hx $ H eq \u25b8 hx'\u27e9\n\n/-- We can use the axiom of choice to pick a preimage for every element of `range f`. -/\nnoncomputable def range_splitting (f : \u03b1 \u2192 \u03b2) : range f \u2192 \u03b1 := \u03bb x, x.2.some\n\n-- This can not be a `@[simp]` lemma because the head of the left hand side is a variable.\nlemma apply_range_splitting (f : \u03b1 \u2192 \u03b2) (x : range f) : f (range_splitting f x) = x :=\nx.2.some_spec\n\nattribute [irreducible] range_splitting\n\n@[simp] lemma comp_range_splitting (f : \u03b1 \u2192 \u03b2) : f \u2218 range_splitting f = coe :=\nby { ext, simp only [function.comp_app], apply apply_range_splitting, }\n\n-- When `f` is injective, see also `equiv.of_injective`.\nlemma left_inverse_range_splitting (f : \u03b1 \u2192 \u03b2) :\n  left_inverse (range_factorization f) (range_splitting f) :=\n\u03bb x, by { ext, simp only [range_factorization_coe], apply apply_range_splitting, }\n\nlemma range_splitting_injective (f : \u03b1 \u2192 \u03b2) : injective (range_splitting f) :=\n(left_inverse_range_splitting f).injective\n\nlemma right_inverse_range_splitting {f : \u03b1 \u2192 \u03b2} (h : injective f) :\n  right_inverse (range_factorization f) (range_splitting f) :=\n(left_inverse_range_splitting f).right_inverse_of_injective $\n  \u03bb x y hxy, h $ subtype.ext_iff.1 hxy\n\nlemma preimage_range_splitting {f : \u03b1 \u2192 \u03b2} (hf : injective f) :\n  preimage (range_splitting f) = image (range_factorization f) :=\n(image_eq_preimage_of_inverse (right_inverse_range_splitting hf)\n  (left_inverse_range_splitting f)).symm\n\nlemma is_compl_range_some_none (\u03b1 : Type*) :\n  is_compl (range (some : \u03b1 \u2192 option \u03b1)) {none} :=\n\u27e8\u03bb x \u27e8\u27e8a, ha\u27e9, (hn : x = none)\u27e9, option.some_ne_none _ (ha.trans hn),\n  \u03bb x hx, option.cases_on x (or.inr rfl) (\u03bb x, or.inl $ mem_range_self _)\u27e9\n\n@[simp] lemma compl_range_some (\u03b1 : Type*) :\n  (range (some : \u03b1 \u2192 option \u03b1))\u1d9c = {none} :=\n(is_compl_range_some_none \u03b1).compl_eq\n\n@[simp] lemma range_some_inter_none (\u03b1 : Type*) : range (some : \u03b1 \u2192 option \u03b1) \u2229 {none} = \u2205 :=\n(is_compl_range_some_none \u03b1).inf_eq_bot\n\n@[simp] lemma range_some_union_none (\u03b1 : Type*) : range (some : \u03b1 \u2192 option \u03b1) \u222a {none} = univ :=\n(is_compl_range_some_none \u03b1).sup_eq_top\n\nend range\nend set\n\nopen set\n\nnamespace function\n\nvariables {\u03b9 : Sort*} {\u03b1 : Type*} {\u03b2 : Type*} {f : \u03b1 \u2192 \u03b2}\n\nlemma surjective.preimage_injective (hf : surjective f) : injective (preimage f) :=\nassume s t, (preimage_eq_preimage hf).1\n\nlemma injective.preimage_image (hf : injective f) (s : set \u03b1) : f \u207b\u00b9' (f '' s) = s :=\npreimage_image_eq s hf\n\nlemma injective.preimage_surjective (hf : injective f) : surjective (preimage f) :=\nby { intro s, use f '' s, rw hf.preimage_image }\n\nlemma injective.subsingleton_image_iff (hf : injective f) {s : set \u03b1} :\n  (f '' s).subsingleton \u2194 s.subsingleton :=\n\u27e8subsingleton_of_image hf s, \u03bb h, h.image f\u27e9\n\nlemma surjective.image_preimage (hf : surjective f) (s : set \u03b2) : f '' (f \u207b\u00b9' s) = s :=\nimage_preimage_eq s hf\n\nlemma surjective.image_surjective (hf : surjective f) : surjective (image f) :=\nby { intro s, use f \u207b\u00b9' s, rw hf.image_preimage }\n\nlemma surjective.nonempty_preimage (hf : surjective f) {s : set \u03b2} :\n  (f \u207b\u00b9' s).nonempty \u2194 s.nonempty :=\nby rw [\u2190 nonempty_image_iff, hf.image_preimage]\n\nlemma injective.image_injective (hf : injective f) : injective (image f) :=\nby { intros s t h, rw [\u2190preimage_image_eq s hf, \u2190preimage_image_eq t hf, h] }\n\nlemma surjective.preimage_subset_preimage_iff {s t : set \u03b2} (hf : surjective f) :\n  f \u207b\u00b9' s \u2286 f \u207b\u00b9' t \u2194 s \u2286 t :=\nby { apply preimage_subset_preimage_iff, rw [hf.range_eq], apply subset_univ }\n\nlemma surjective.range_comp {\u03b9' : Sort*} {f : \u03b9 \u2192 \u03b9'} (hf : surjective f) (g : \u03b9' \u2192 \u03b1) :\n  range (g \u2218 f) = range g :=\next $ \u03bb y, (@surjective.exists _ _ _ hf (\u03bb x, g x = y)).symm\n\nlemma injective.nonempty_apply_iff {f : set \u03b1 \u2192 set \u03b2} (hf : injective f)\n  (h2 : f \u2205 = \u2205) {s : set \u03b1} : (f s).nonempty \u2194 s.nonempty :=\nby rw [\u2190 ne_empty_iff_nonempty, \u2190 h2, \u2190 ne_empty_iff_nonempty, hf.ne_iff]\n\nlemma injective.mem_range_iff_exists_unique (hf : injective f) {b : \u03b2} :\n  b \u2208 range f \u2194 \u2203! a, f a = b :=\n\u27e8\u03bb \u27e8a, h\u27e9, \u27e8a, h, \u03bb a' ha, hf (ha.trans h.symm)\u27e9, exists_unique.exists\u27e9\n\nlemma injective.exists_unique_of_mem_range (hf : injective f) {b : \u03b2} (hb : b \u2208 range f) :\n  \u2203! a, f a = b :=\nhf.mem_range_iff_exists_unique.mp hb\n\ntheorem injective.compl_image_eq (hf : injective f) (s : set \u03b1) :\n  (f '' s)\u1d9c = f '' s\u1d9c \u222a (range f)\u1d9c :=\nbegin\n  ext y,\n  rcases em (y \u2208 range f) with \u27e8x, rfl\u27e9|hx,\n  { simp [hf.eq_iff] },\n  { rw [mem_range, not_exists] at hx,\n    simp [hx] }\nend\n\nlemma left_inverse.image_image {g : \u03b2 \u2192 \u03b1} (h : left_inverse g f) (s : set \u03b1) :\n  g '' (f '' s) = s :=\nby rw [\u2190 image_comp, h.comp_eq_id, image_id]\n\nlemma left_inverse.preimage_preimage {g : \u03b2 \u2192 \u03b1} (h : left_inverse g f) (s : set \u03b1) :\n  f \u207b\u00b9' (g \u207b\u00b9' s) = s :=\nby rw [\u2190 preimage_comp, h.comp_eq_id, preimage_id]\n\nend function\nopen function\n\nlemma option.injective_iff {\u03b1 \u03b2} {f : option \u03b1 \u2192 \u03b2} :\n  injective f \u2194 injective (f \u2218 some) \u2227 f none \u2209 range (f \u2218 some) :=\nbegin\n  simp only [mem_range, not_exists, (\u2218)],\n  refine \u27e8\u03bb hf, \u27e8hf.comp (option.some_injective _), \u03bb x, hf.ne $ option.some_ne_none _\u27e9, _\u27e9,\n  rintro \u27e8h_some, h_none\u27e9 (_|a) (_|b) hab,\n  exacts [rfl, (h_none _ hab.symm).elim, (h_none _ hab).elim, congr_arg some (h_some hab)]\nend\n\n/-! ### Image and preimage on subtypes -/\n\nnamespace subtype\n\nvariable {\u03b1 : Type*}\n\nlemma coe_image {p : \u03b1 \u2192 Prop} {s : set (subtype p)} :\n  coe '' s = {x | \u2203h : p x, (\u27e8x, h\u27e9 : subtype p) \u2208 s} :=\nset.ext $ assume a,\n\u27e8assume \u27e8\u27e8a', ha'\u27e9, in_s, h_eq\u27e9, h_eq \u25b8 \u27e8ha', in_s\u27e9,\n  assume \u27e8ha, in_s\u27e9, \u27e8\u27e8a, ha\u27e9, in_s, rfl\u27e9\u27e9\n\n@[simp] lemma coe_image_of_subset {s t : set \u03b1} (h : t \u2286 s) : coe '' {x : \u21a5s | \u2191x \u2208 t} = t :=\nbegin\n  ext x,\n  rw set.mem_image,\n  exact \u27e8\u03bb \u27e8x', hx', hx\u27e9, hx \u25b8 hx', \u03bb hx, \u27e8\u27e8x, h hx\u27e9, hx, rfl\u27e9\u27e9,\nend\n\nlemma range_coe {s : set \u03b1} :\n  range (coe : s \u2192 \u03b1) = s :=\nby { rw \u2190 set.image_univ, simp [-set.image_univ, coe_image] }\n\n/-- A variant of `range_coe`. Try to use `range_coe` if possible.\n  This version is useful when defining a new type that is defined as the subtype of something.\n  In that case, the coercion doesn't fire anymore. -/\nlemma range_val {s : set \u03b1} :\n  range (subtype.val : s \u2192 \u03b1) = s :=\nrange_coe\n\n/-- We make this the simp lemma instead of `range_coe`. The reason is that if we write\n  for `s : set \u03b1` the function `coe : s \u2192 \u03b1`, then the inferred implicit arguments of `coe` are\n  `coe \u03b1 (\u03bb x, x \u2208 s)`. -/\n@[simp] lemma range_coe_subtype {p : \u03b1 \u2192 Prop} :\n  range (coe : subtype p \u2192 \u03b1) = {x | p x} :=\nrange_coe\n\n@[simp] lemma coe_preimage_self (s : set \u03b1) : (coe : s \u2192 \u03b1) \u207b\u00b9' s = univ :=\nby rw [\u2190 preimage_range (coe : s \u2192 \u03b1), range_coe]\n\nlemma range_val_subtype {p : \u03b1 \u2192 Prop} :\n  range (subtype.val : subtype p \u2192 \u03b1) = {x | p x} :=\nrange_coe\n\ntheorem coe_image_subset (s : set \u03b1) (t : set s) : coe '' t \u2286 s :=\n\u03bb x \u27e8y, yt, yvaleq\u27e9, by rw \u2190yvaleq; exact y.property\n\ntheorem coe_image_univ (s : set \u03b1) : (coe : s \u2192 \u03b1) '' set.univ = s :=\nimage_univ.trans range_coe\n\n@[simp] theorem image_preimage_coe (s t : set \u03b1) :\n  (coe : s \u2192 \u03b1) '' (coe \u207b\u00b9' t) = t \u2229 s :=\nimage_preimage_eq_inter_range.trans $ congr_arg _ range_coe\n\ntheorem image_preimage_val (s t : set \u03b1) :\n  (subtype.val : s \u2192 \u03b1) '' (subtype.val \u207b\u00b9' t) = t \u2229 s :=\nimage_preimage_coe s t\n\ntheorem preimage_coe_eq_preimage_coe_iff {s t u : set \u03b1} :\n  ((coe : s \u2192 \u03b1) \u207b\u00b9' t = coe \u207b\u00b9' u) \u2194 t \u2229 s = u \u2229 s :=\nbegin\n  rw [\u2190image_preimage_coe, \u2190image_preimage_coe],\n  split, { intro h, rw h },\n  intro h, exact coe_injective.image_injective h\nend\n\ntheorem preimage_val_eq_preimage_val_iff (s t u : set \u03b1) :\n  ((subtype.val : s \u2192 \u03b1) \u207b\u00b9' t = subtype.val \u207b\u00b9' u) \u2194 (t \u2229 s = u \u2229 s) :=\npreimage_coe_eq_preimage_coe_iff\n\nlemma exists_set_subtype {t : set \u03b1} (p : set \u03b1 \u2192 Prop) :\n  (\u2203(s : set t), p (coe '' s)) \u2194 \u2203(s : set \u03b1), s \u2286 t \u2227 p s :=\nbegin\n  split,\n  { rintro \u27e8s, hs\u27e9, refine \u27e8coe '' s, _, hs\u27e9,\n    convert image_subset_range _ _, rw [range_coe] },\n  rintro \u27e8s, hs\u2081, hs\u2082\u27e9, refine \u27e8coe \u207b\u00b9' s, _\u27e9,\n  rw [image_preimage_eq_of_subset], exact hs\u2082, rw [range_coe], exact hs\u2081\nend\n\nlemma preimage_coe_nonempty {s t : set \u03b1} : ((coe : s \u2192 \u03b1) \u207b\u00b9' t).nonempty \u2194 (s \u2229 t).nonempty :=\nby rw [inter_comm, \u2190 image_preimage_coe, nonempty_image_iff]\n\nlemma preimage_coe_eq_empty {s t : set \u03b1} : (coe : s \u2192 \u03b1) \u207b\u00b9' t = \u2205 \u2194 s \u2229 t = \u2205 :=\nby simp only [\u2190 not_nonempty_iff_eq_empty, preimage_coe_nonempty]\n\n@[simp] lemma preimage_coe_compl (s : set \u03b1) : (coe : s \u2192 \u03b1) \u207b\u00b9' s\u1d9c = \u2205 :=\npreimage_coe_eq_empty.2 (inter_compl_self s)\n\n@[simp] lemma preimage_coe_compl' (s : set \u03b1) : (coe : s\u1d9c \u2192 \u03b1) \u207b\u00b9' s = \u2205 :=\npreimage_coe_eq_empty.2 (compl_inter_self s)\n\nend subtype\n\nnamespace set\n\n/-! ### Lemmas about `inclusion`, the injection of subtypes induced by `\u2286` -/\n\nsection inclusion\nvariable {\u03b1 : Type*}\n\n/-- `inclusion` is the \"identity\" function between two subsets `s` and `t`, where `s \u2286 t` -/\ndef inclusion {s t : set \u03b1} (h : s \u2286 t) : s \u2192 t :=\n\u03bb x : s, (\u27e8x, h x.2\u27e9 : t)\n\n@[simp] lemma inclusion_self {s : set \u03b1} (x : s) : inclusion subset.rfl x = x :=\nby { cases x, refl }\n\n@[simp] lemma inclusion_right {s t : set \u03b1} (h : s \u2286 t) (x : t) (m : (x : \u03b1) \u2208 s) :\n  inclusion h \u27e8x, m\u27e9 = x :=\nby { cases x, refl }\n\n@[simp] lemma inclusion_inclusion {s t u : set \u03b1} (hst : s \u2286 t) (htu : t \u2286 u)\n  (x : s) : inclusion htu (inclusion hst x) = inclusion (set.subset.trans hst htu) x :=\nby { cases x, refl }\n\n@[simp] lemma coe_inclusion {s t : set \u03b1} (h : s \u2286 t) (x : s) :\n  (inclusion h x : \u03b1) = (x : \u03b1) := rfl\n\nlemma inclusion_injective {s t : set \u03b1} (h : s \u2286 t) :\n  function.injective (inclusion h)\n| \u27e8_, _\u27e9 \u27e8_, _\u27e9 := subtype.ext_iff_val.2 \u2218 subtype.ext_iff_val.1\n\n@[simp] lemma range_inclusion {s t : set \u03b1} (h : s \u2286 t) :\n  range (inclusion h) = {x : t | (x:\u03b1) \u2208 s} :=\nby { ext \u27e8x, hx\u27e9, simp [inclusion] }\n\nlemma eq_of_inclusion_surjective {s t : set \u03b1} {h : s \u2286 t}\n  (h_surj : function.surjective (inclusion h)) : s = t :=\nbegin\n  rw [\u2190 range_iff_surjective, range_inclusion, eq_univ_iff_forall] at h_surj,\n  exact set.subset.antisymm h (\u03bb x hx, h_surj \u27e8x, hx\u27e9)\nend\n\nend inclusion\n\n/-! ### Injectivity and surjectivity lemmas for image and preimage -/\nsection image_preimage\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {f : \u03b1 \u2192 \u03b2}\n@[simp]\nlemma preimage_injective : injective (preimage f) \u2194 surjective f :=\nbegin\n  refine \u27e8\u03bb h y, _, surjective.preimage_injective\u27e9,\n  obtain \u27e8x, hx\u27e9 : (f \u207b\u00b9' {y}).nonempty,\n  { rw [h.nonempty_apply_iff preimage_empty], apply singleton_nonempty },\n  exact \u27e8x, hx\u27e9\nend\n\n@[simp]\nlemma preimage_surjective : surjective (preimage f) \u2194 injective f :=\nbegin\n  refine \u27e8\u03bb h x x' hx, _, injective.preimage_surjective\u27e9,\n  cases h {x} with s hs, have := mem_singleton x,\n  rwa [\u2190 hs, mem_preimage, hx, \u2190 mem_preimage, hs, mem_singleton_iff, eq_comm] at this\nend\n\n@[simp] lemma image_surjective : surjective (image f) \u2194 surjective f :=\nbegin\n  refine \u27e8\u03bb h y, _, surjective.image_surjective\u27e9,\n  cases h {y} with s hs,\n  have := mem_singleton y, rw [\u2190 hs] at this, rcases this with \u27e8x, h1x, h2x\u27e9,\n  exact \u27e8x, h2x\u27e9\nend\n\n@[simp] lemma image_injective : injective (image f) \u2194 injective f :=\nbegin\n  refine \u27e8\u03bb h x x' hx, _, injective.image_injective\u27e9,\n  rw [\u2190 singleton_eq_singleton_iff], apply h,\n  rw [image_singleton, image_singleton, hx]\nend\n\nlemma preimage_eq_iff_eq_image {f : \u03b1 \u2192 \u03b2} (hf : bijective f) {s t} :\n  f \u207b\u00b9' s = t \u2194 s = f '' t :=\nby rw [\u2190 image_eq_image hf.1, hf.2.image_preimage]\n\nlemma eq_preimage_iff_image_eq {f : \u03b1 \u2192 \u03b2} (hf : bijective f) {s t} :\n  s = f \u207b\u00b9' t \u2194 f '' s = t :=\nby rw [\u2190 image_eq_image hf.1, hf.2.image_preimage]\n\nend image_preimage\n\n/-! ### Lemmas about images of binary and ternary functions -/\n\nsection n_ary_image\n\nvariables {\u03b1 \u03b2 \u03b3 \u03b4 \u03b5 : Type*} {f f' : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {g g' : \u03b1 \u2192 \u03b2 \u2192 \u03b3 \u2192 \u03b4}\nvariables {s s' : set \u03b1} {t t' : set \u03b2} {u u' : set \u03b3} {a a' : \u03b1} {b b' : \u03b2} {c c' : \u03b3} {d d' : \u03b4}\n\n\n/-- The image of a binary function `f : \u03b1 \u2192 \u03b2 \u2192 \u03b3` as a function `set \u03b1 \u2192 set \u03b2 \u2192 set \u03b3`.\n  Mathematically this should be thought of as the image of the corresponding function `\u03b1 \u00d7 \u03b2 \u2192 \u03b3`.\n-/\ndef image2 (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (s : set \u03b1) (t : set \u03b2) : set \u03b3 :=\n{c | \u2203 a b, a \u2208 s \u2227 b \u2208 t \u2227 f a b = c }\n\nlemma mem_image2_eq : c \u2208 image2 f s t = \u2203 a b, a \u2208 s \u2227 b \u2208 t \u2227 f a b = c := rfl\n\n@[simp] lemma mem_image2 : c \u2208 image2 f s t \u2194 \u2203 a b, a \u2208 s \u2227 b \u2208 t \u2227 f a b = c := iff.rfl\n\nlemma mem_image2_of_mem (h1 : a \u2208 s) (h2 : b \u2208 t) : f a b \u2208 image2 f s t :=\n\u27e8a, b, h1, h2, rfl\u27e9\n\nlemma mem_image2_iff (hf : injective2 f) : f a b \u2208 image2 f s t \u2194 a \u2208 s \u2227 b \u2208 t :=\n\u27e8 by { rintro \u27e8a', b', ha', hb', h\u27e9, rcases hf h with \u27e8rfl, rfl\u27e9, exact \u27e8ha', hb'\u27e9 },\n  \u03bb \u27e8ha, hb\u27e9, mem_image2_of_mem ha hb\u27e9\n\n/-- image2 is monotone with respect to `\u2286`. -/\nlemma image2_subset (hs : s \u2286 s') (ht : t \u2286 t') : image2 f s t \u2286 image2 f s' t' :=\nby { rintro _ \u27e8a, b, ha, hb, rfl\u27e9, exact mem_image2_of_mem (hs ha) (ht hb) }\n\nlemma image2_subset_left (ht : t \u2286 t') : image2 f s t \u2286 image2 f s t' := image2_subset subset.rfl ht\n\nlemma image2_subset_right (hs : s \u2286 s') : image2 f s t \u2286 image2 f s' t :=\nimage2_subset hs subset.rfl\n\nlemma forall_image2_iff {p : \u03b3 \u2192 Prop} :\n  (\u2200 z \u2208 image2 f s t, p z) \u2194 \u2200 (x \u2208 s) (y \u2208 t), p (f x y) :=\n\u27e8\u03bb h x hx y hy, h _ \u27e8x, y, hx, hy, rfl\u27e9, \u03bb h z \u27e8x, y, hx, hy, hz\u27e9, hz \u25b8 h x hx y hy\u27e9\n\n@[simp] lemma image2_subset_iff {u : set \u03b3} :\n  image2 f s t \u2286 u \u2194 \u2200 (x \u2208 s) (y \u2208 t), f x y \u2208 u :=\nforall_image2_iff\n\nlemma image2_union_left : image2 f (s \u222a s') t = image2 f s t \u222a image2 f s' t :=\nbegin\n  ext c, split,\n  { rintros \u27e8a, b, h1a|h2a, hb, rfl\u27e9;[left, right]; exact \u27e8_, _, \u2039_\u203a, \u2039_\u203a, rfl\u27e9 },\n  { rintro (\u27e8_, _, _, _, rfl\u27e9|\u27e8_, _, _, _, rfl\u27e9); refine \u27e8_, _, _, \u2039_\u203a, rfl\u27e9; simp [mem_union, *] }\nend\n\nlemma image2_union_right : image2 f s (t \u222a t') = image2 f s t \u222a image2 f s t' :=\nbegin\n  ext c, split,\n  { rintros \u27e8a, b, ha, h1b|h2b, rfl\u27e9;[left, right]; exact \u27e8_, _, \u2039_\u203a, \u2039_\u203a, rfl\u27e9 },\n  { rintro (\u27e8_, _, _, _, rfl\u27e9|\u27e8_, _, _, _, rfl\u27e9); refine \u27e8_, _, \u2039_\u203a, _, rfl\u27e9; simp [mem_union, *] }\nend\n\n@[simp] lemma image2_empty_left : image2 f \u2205 t = \u2205 := ext $ by simp\n@[simp] lemma image2_empty_right : image2 f s \u2205 = \u2205 := ext $ by simp\n\nlemma image2_inter_subset_left : image2 f (s \u2229 s') t \u2286 image2 f s t \u2229 image2 f s' t :=\nby { rintro _ \u27e8a, b, \u27e8h1a, h2a\u27e9, hb, rfl\u27e9, split; exact \u27e8_, _, \u2039_\u203a, \u2039_\u203a, rfl\u27e9 }\n\nlemma image2_inter_subset_right : image2 f s (t \u2229 t') \u2286 image2 f s t \u2229 image2 f s t' :=\nby { rintro _ \u27e8a, b, ha, \u27e8h1b, h2b\u27e9, rfl\u27e9, split; exact \u27e8_, _, \u2039_\u203a, \u2039_\u203a, rfl\u27e9 }\n\n@[simp] lemma image2_singleton_left : image2 f {a} t = f a '' t :=\next $ \u03bb x, by simp\n\n@[simp] lemma image2_singleton_right : image2 f s {b} = (\u03bb a, f a b) '' s :=\next $ \u03bb x, by simp\n\nlemma image2_singleton : image2 f {a} {b} = {f a b} := by simp\n\n@[congr] lemma image2_congr (h : \u2200 (a \u2208 s) (b \u2208 t), f a b = f' a b) :\n  image2 f s t = image2 f' s t :=\nby { ext, split; rintro \u27e8a, b, ha, hb, rfl\u27e9; refine \u27e8a, b, ha, hb, by rw h a ha b hb\u27e9 }\n\n/-- A common special case of `image2_congr` -/\nlemma image2_congr' (h : \u2200 a b, f a b = f' a b) : image2 f s t = image2 f' s t :=\nimage2_congr (\u03bb a _ b _, h a b)\n\n/-- The image of a ternary function `f : \u03b1 \u2192 \u03b2 \u2192 \u03b3 \u2192 \u03b4` as a function\n  `set \u03b1 \u2192 set \u03b2 \u2192 set \u03b3 \u2192 set \u03b4`. Mathematically this should be thought of as the image of the\n  corresponding function `\u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 \u03b4`.\n-/\ndef image3 (g : \u03b1 \u2192 \u03b2 \u2192 \u03b3 \u2192 \u03b4) (s : set \u03b1) (t : set \u03b2) (u : set \u03b3) : set \u03b4 :=\n{d | \u2203 a b c, a \u2208 s \u2227 b \u2208 t \u2227 c \u2208 u \u2227 g a b c = d }\n\n@[simp] lemma mem_image3 : d \u2208 image3 g s t u \u2194 \u2203 a b c, a \u2208 s \u2227 b \u2208 t \u2227 c \u2208 u \u2227 g a b c = d :=\niff.rfl\n\n@[congr] lemma image3_congr (h : \u2200 (a \u2208 s) (b \u2208 t) (c \u2208 u), g a b c = g' a b c) :\n  image3 g s t u = image3 g' s t u :=\nby { ext x,\n     split; rintro \u27e8a, b, c, ha, hb, hc, rfl\u27e9; exact \u27e8a, b, c, ha, hb, hc, by rw h a ha b hb c hc\u27e9 }\n\n/-- A common special case of `image3_congr` -/\nlemma image3_congr' (h : \u2200 a b c, g a b c = g' a b c) : image3 g s t u = image3 g' s t u :=\nimage3_congr (\u03bb a _ b _ c _, h a b c)\n\nlemma image2_image2_left (f : \u03b4 \u2192 \u03b3 \u2192 \u03b5) (g : \u03b1 \u2192 \u03b2 \u2192 \u03b4) :\n  image2 f (image2 g s t) u = image3 (\u03bb a b c, f (g a b) c) s t u :=\nbegin\n  ext, split,\n  { rintro \u27e8_, c, \u27e8a, b, ha, hb, rfl\u27e9, hc, rfl\u27e9, refine \u27e8a, b, c, ha, hb, hc, rfl\u27e9 },\n  { rintro \u27e8a, b, c, ha, hb, hc, rfl\u27e9, refine \u27e8_, c, \u27e8a, b, ha, hb, rfl\u27e9, hc, rfl\u27e9 }\nend\n\nlemma image2_image2_right (f : \u03b1 \u2192 \u03b4 \u2192 \u03b5) (g : \u03b2 \u2192 \u03b3 \u2192 \u03b4) :\n  image2 f s (image2 g t u) = image3 (\u03bb a b c, f a (g b c)) s t u :=\nbegin\n  ext, split,\n  { rintro \u27e8a, _, ha, \u27e8b, c, hb, hc, rfl\u27e9, rfl\u27e9, refine \u27e8a, b, c, ha, hb, hc, rfl\u27e9 },\n  { rintro \u27e8a, b, c, ha, hb, hc, rfl\u27e9, refine \u27e8a, _, ha, \u27e8b, c, hb, hc, rfl\u27e9, rfl\u27e9 }\nend\n\nlemma image2_assoc {\u03b5'} {f : \u03b4 \u2192 \u03b3 \u2192 \u03b5} {g : \u03b1 \u2192 \u03b2 \u2192 \u03b4} {f' : \u03b1 \u2192 \u03b5' \u2192 \u03b5} {g' : \u03b2 \u2192 \u03b3 \u2192 \u03b5'}\n  (h_assoc : \u2200 a b c, f (g a b) c = f' a (g' b c)) :\n  image2 f (image2 g s t) u = image2 f' s (image2 g' t u) :=\nby simp only [image2_image2_left, image2_image2_right, h_assoc]\n\nlemma image_image2 (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (g : \u03b3 \u2192 \u03b4) :\n  g '' image2 f s t = image2 (\u03bb a b, g (f a b)) s t :=\nbegin\n  ext, split,\n  { rintro \u27e8_, \u27e8a, b, ha, hb, rfl\u27e9, rfl\u27e9, refine \u27e8a, b, ha, hb, rfl\u27e9 },\n  { rintro \u27e8a, b, ha, hb, rfl\u27e9, refine \u27e8_, \u27e8a, b, ha, hb, rfl\u27e9, rfl\u27e9 }\nend\n\nlemma image2_image_left (f : \u03b3 \u2192 \u03b2 \u2192 \u03b4) (g : \u03b1 \u2192 \u03b3) :\n  image2 f (g '' s) t = image2 (\u03bb a b, f (g a) b) s t :=\nbegin\n  ext, split,\n  { rintro \u27e8_, b, \u27e8a, ha, rfl\u27e9, hb, rfl\u27e9, refine \u27e8a, b, ha, hb, rfl\u27e9 },\n  { rintro \u27e8a, b, ha, hb, rfl\u27e9, refine \u27e8_, b, \u27e8a, ha, rfl\u27e9, hb, rfl\u27e9 }\nend\n\nlemma image2_image_right (f : \u03b1 \u2192 \u03b3 \u2192 \u03b4) (g : \u03b2 \u2192 \u03b3) :\n  image2 f s (g '' t) = image2 (\u03bb a b, f a (g b)) s t :=\nbegin\n  ext, split,\n  { rintro \u27e8a, _, ha, \u27e8b, hb, rfl\u27e9, rfl\u27e9, refine \u27e8a, b, ha, hb, rfl\u27e9 },\n  { rintro \u27e8a, b, ha, hb, rfl\u27e9, refine \u27e8a, _, ha, \u27e8b, hb, rfl\u27e9, rfl\u27e9 }\nend\n\nlemma image2_swap (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (s : set \u03b1) (t : set \u03b2) :\n  image2 f s t = image2 (\u03bb a b, f b a) t s :=\nby { ext, split; rintro \u27e8a, b, ha, hb, rfl\u27e9; refine \u27e8b, a, hb, ha, rfl\u27e9 }\n\n@[simp] lemma image2_left (h : t.nonempty) : image2 (\u03bb x y, x) s t = s :=\nby simp [nonempty_def.mp h, ext_iff]\n\n@[simp] lemma image2_right (h : s.nonempty) : image2 (\u03bb x y, y) s t = t :=\nby simp [nonempty_def.mp h, ext_iff]\n\nlemma nonempty.image2 (hs : s.nonempty) (ht : t.nonempty) : (image2 f s t).nonempty :=\nby { cases hs with a ha, cases ht with b hb, exact \u27e8f a b, \u27e8a, b, ha, hb, rfl\u27e9\u27e9 }\n\nend n_ary_image\n\nend set\n\nnamespace subsingleton\n\nvariables {\u03b1 : Type*} [subsingleton \u03b1]\n\nlemma eq_univ_of_nonempty {s : set \u03b1} : s.nonempty \u2192 s = univ :=\n\u03bb \u27e8x, hx\u27e9, eq_univ_of_forall $ \u03bb y, subsingleton.elim x y \u25b8 hx\n\n@[elab_as_eliminator]\nlemma set_cases {p : set \u03b1 \u2192 Prop} (h0 : p \u2205) (h1 : p univ) (s) : p s :=\ns.eq_empty_or_nonempty.elim (\u03bb h, h.symm \u25b8 h0) $ \u03bb h, (eq_univ_of_nonempty h).symm \u25b8 h1\n\nlemma mem_iff_nonempty {\u03b1 : Type*} [subsingleton \u03b1] {s : set \u03b1} {x : \u03b1} :\n  x \u2208 s \u2194 s.nonempty :=\n\u27e8\u03bb hx, \u27e8x, hx\u27e9, \u03bb \u27e8y, hy\u27e9, subsingleton.elim y x \u25b8 hy\u27e9\n\nend subsingleton\n\n/-! ### Decidability instances for sets -/\n\nnamespace set\nvariables {\u03b1 : Type u} (s t : set \u03b1) (a : \u03b1)\n\ninstance decidable_sdiff [decidable (a \u2208 s)] [decidable (a \u2208 t)] : decidable (a \u2208 s \\ t) :=\n(by apply_instance : decidable (a \u2208 s \u2227 a \u2209 t))\n\ninstance decidable_inter [decidable (a \u2208 s)] [decidable (a \u2208 t)] : decidable (a \u2208 s \u2229 t) :=\n(by apply_instance : decidable (a \u2208 s \u2227 a \u2208 t))\n\ninstance decidable_union [decidable (a \u2208 s)] [decidable (a \u2208 t)] : decidable (a \u2208 s \u222a t) :=\n(by apply_instance : decidable (a \u2208 s \u2228 a \u2208 t))\n\ninstance decidable_compl [decidable (a \u2208 s)] : decidable (a \u2208 s\u1d9c) :=\n(by apply_instance : decidable (a \u2209 s))\n\ninstance decidable_emptyset : decidable_pred (\u2208 (\u2205 : set \u03b1)) :=\n\u03bb _, decidable.is_false (by simp)\n\ninstance decidable_univ : decidable_pred (\u2208 (set.univ : set \u03b1)) :=\n\u03bb _, decidable.is_true (by simp)\n\ninstance decidable_set_of (p : \u03b1 \u2192 Prop) [decidable (p a)] : decidable (a \u2208 {a | p a}) :=\nby assumption\n\nend set\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/set/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7117925516002245}}
{"text": "/-\nCopyright (c) 2022 Michael Stoll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Gei\u00dfer, Michael Stoll\n-/\nimport tactic.basic\nimport data.real.irrational\nimport combinatorics.pigeonhole\n\n/-!\n# Diophantine Approximation\n\nThis file gives proofs of various versions of **Dirichlet's approximation theorem**\nand its important consequence that when `\u03be` is an irrational real number, then there are\ninfinitely many rationals `x/y` (in lowest terms) such that `|\u03be - x/y| < 1/y^2`.\n\nThe proof is based on the pigeonhole principle.\n\n## Main statements\n\nThe main results are three variants of Dirichlet's approximation theorem:\n* `real.exists_int_int_abs_mul_sub_le`, which states that for all real `\u03be` and natural `0 < n`,\n  there are integers `j` and `k` with `0 < k \u2264 n` and `|k*\u03be - j| \u2264 1/(n+1)`,\n* `real.exists_nat_abs_mul_sub_round_le`, which replaces `j` by `round(k*\u03be)` and uses\n  a natural number `k`,\n* `real.exists_rat_abs_sub_le_and_denom_le`, which says that there is a rational number `q`\n  satisfying `|\u03be - q| \u2264 1/((n+1)*q.denom)` and `q.denom \u2264 n`,\n\nand\n* `real.infinite_rat_abs_sub_lt_one_div_denom_sq_of_irrational`, which states that\n  for irrational `\u03be`, the set `{q : \u211a | |\u03be - q| < 1/q.denom^2}` is infinite.\n\nWe also show a converse,\n* `rat.finite_rat_abs_sub_lt_one_div_denom_sq`, which states that the set above is finite\n  when `\u03be` is a rational number.\n\nBoth statements are combined to give an equivalence,\n`real.infinite_rat_abs_sub_lt_one_div_denom_sq_iff_irrational`.\n\n## Implementation notes\n\nWe use the namespace `real` for the results on real numbers and `rat` for the results\non rational numbers.\n\n## References\n\n<https://en.wikipedia.org/wiki/Dirichlet%27s_approximation_theorem>\n\n## Tags\n\nDiophantine approximation, Dirichlet's approximation theorem\n-/\n\nnamespace real\n\nsection dirichlet\n\n/-!\n### Dirichlet's approximation theorem\n\nWe show that for any real number `\u03be` and positive natural `n`, there is a fraction `q`\nsuch that `q.denom \u2264 n` and `|\u03be - q| \u2264 1/((n+1)*q.denom)`.\n-/\n\nopen finset int\n\n/-- *Dirichlet's approximation theorem:*\nFor any real number `\u03be` and positive natural `n`, there are integers `j` and `k`,\nwith `0 < k \u2264 n` and `|k*\u03be - j| \u2264 1/(n+1)`.\n\nSee also `real.exists_nat_abs_mul_sub_round_le`. -/\nlemma exists_int_int_abs_mul_sub_le (\u03be : \u211d) {n : \u2115} (n_pos : 0 < n) :\n  \u2203 j k : \u2124, 0 < k \u2227 k \u2264 n \u2227 |\u2191k * \u03be - j| \u2264 1 / (n + 1) :=\nbegin\n  let f : \u2124 \u2192 \u2124 := \u03bb m, \u230afract (\u03be * m) * (n + 1)\u230b,\n  have hn : 0 < (n : \u211d) + 1 := by exact_mod_cast nat.succ_pos _,\n  have hfu := \u03bb m : \u2124, mul_lt_of_lt_one_left hn $ fract_lt_one (\u03be * \u2191m),\n  conv in (|_| \u2264 _) { rw [mul_comm, le_div_iff hn, \u2190 abs_of_pos hn, \u2190 abs_mul], },\n  let D := Icc (0 : \u2124) n,\n  by_cases H : \u2203 m \u2208 D, f m = n,\n  { obtain \u27e8m, hm, hf\u27e9 := H,\n    have hf' : ((n : \u2124) : \u211d) \u2264 fract (\u03be * m) * (n + 1) := hf \u25b8 floor_le (fract (\u03be * m) * (n + 1)),\n    have hm\u2080 : 0 < m,\n    { have hf\u2080 : f 0 = 0,\n      { simp only [floor_eq_zero_iff, algebra_map.coe_zero, mul_zero, fract_zero, zero_mul,\n                   set.left_mem_Ico, zero_lt_one], },\n      refine ne.lt_of_le (\u03bb h, n_pos.ne _) (mem_Icc.mp hm).1,\n      exact_mod_cast hf\u2080.symm.trans (h.symm \u25b8 hf : f 0 = n), },\n    refine \u27e8\u230a\u03be * m\u230b + 1, m, hm\u2080, (mem_Icc.mp hm).2, _\u27e9,\n    rw [cast_add, \u2190 sub_sub, sub_mul, cast_one, one_mul, abs_le],\n    refine \u27e8le_sub_iff_add_le.mpr _,\n            sub_le_iff_le_add.mpr $ le_of_lt $ (hfu m).trans $ lt_one_add _\u27e9,\n    simpa only [neg_add_cancel_comm_assoc] using hf', },\n  { simp_rw [not_exists] at H,\n    have hD : (Ico (0 : \u2124) n).card < D.card,\n    { rw [card_Icc, card_Ico], exact lt_add_one n, },\n    have hfu' : \u2200 m, f m \u2264 n := \u03bb m, lt_add_one_iff.mp (floor_lt.mpr (by exact_mod_cast hfu m)),\n    have hwd : \u2200 m : \u2124, m \u2208 D \u2192 f m \u2208 Ico (0 : \u2124) n :=\n      \u03bb x hx, mem_Ico.mpr \u27e8floor_nonneg.mpr (mul_nonneg (fract_nonneg (\u03be * x)) hn.le),\n                           ne.lt_of_le (H x hx) (hfu' x)\u27e9,\n    have : \u2203 (x : \u2124) (hx : x \u2208 D) (y : \u2124) (hy : y \u2208 D), x < y \u2227 f x = f y,\n    { obtain \u27e8x, hx, y, hy, x_ne_y, hxy\u27e9 := exists_ne_map_eq_of_card_lt_of_maps_to hD hwd,\n      rcases lt_trichotomy x y with h | h | h,\n      exacts [\u27e8x, hx, y, hy, h, hxy\u27e9, false.elim (x_ne_y h), \u27e8y, hy, x, hx, h, hxy.symm\u27e9], },\n    obtain \u27e8x, hx, y, hy, x_lt_y, hxy\u27e9 := this,\n    refine \u27e8\u230a\u03be * y\u230b - \u230a\u03be * x\u230b, y - x, sub_pos_of_lt x_lt_y,\n            sub_le_iff_le_add.mpr $ le_add_of_le_of_nonneg (mem_Icc.mp hy).2 (mem_Icc.mp hx).1, _\u27e9,\n    convert_to |fract (\u03be * y) * (n + 1) - fract (\u03be * x) * (n + 1)| \u2264 1,\n    { congr, push_cast, simp only [fract], ring, },\n    exact (abs_sub_lt_one_of_floor_eq_floor hxy.symm).le, }\nend\n\n/-- *Dirichlet's approximation theorem:*\nFor any real number `\u03be` and positive natural `n`, there is a natural number `k`,\nwith `0 < k \u2264 n` such that `|k*\u03be - round(k*\u03be)| \u2264 1/(n+1)`.\n-/\nlemma exists_nat_abs_mul_sub_round_le (\u03be : \u211d) {n : \u2115} (n_pos : 0 < n) :\n  \u2203 k : \u2115, 0 < k \u2227 k \u2264 n \u2227 |\u2191k * \u03be - round (\u2191k * \u03be)| \u2264 1 / (n + 1) :=\nbegin\n  obtain \u27e8j, k, hk\u2080, hk\u2081, h\u27e9 := exists_int_int_abs_mul_sub_le \u03be n_pos,\n  have hk := to_nat_of_nonneg hk\u2080.le,\n  rw [\u2190 hk] at hk\u2080 hk\u2081 h,\n  exact \u27e8k.to_nat, coe_nat_pos.mp hk\u2080, nat.cast_le.mp hk\u2081, (round_le (\u2191k.to_nat * \u03be) j).trans h\u27e9,\nend\n\n/-- *Dirichlet's approximation theorem:*\nFor any real number `\u03be` and positive natural `n`, there is a fraction `q`\nsuch that `q.denom \u2264 n` and `|\u03be - q| \u2264 1/((n+1)*q.denom)`. -/\nlemma exists_rat_abs_sub_le_and_denom_le (\u03be : \u211d) {n : \u2115} (n_pos : 0 < n) :\n  \u2203 q : \u211a, |\u03be - q| \u2264 1 / ((n + 1) * q.denom) \u2227 q.denom \u2264 n :=\nbegin\n  obtain \u27e8j, k, hk\u2080, hk\u2081, h\u27e9 := exists_int_int_abs_mul_sub_le \u03be n_pos,\n  have hk\u2080' : (0 : \u211d) < k := int.cast_pos.mpr hk\u2080,\n  have hden : ((j / k : \u211a).denom : \u2124) \u2264 k,\n  { convert le_of_dvd hk\u2080 (rat.denom_dvd j k), exact rat.coe_int_div_eq_mk, },\n  refine \u27e8j / k, _, nat.cast_le.mp (hden.trans hk\u2081)\u27e9,\n  rw [\u2190 div_div, le_div_iff (nat.cast_pos.mpr $ rat.pos _ : (0 : \u211d) < _)],\n  refine (mul_le_mul_of_nonneg_left (int.cast_le.mpr hden : _ \u2264 (k : \u211d)) (abs_nonneg _)).trans _,\n  rwa [\u2190 abs_of_pos hk\u2080', rat.cast_div, rat.cast_coe_int, rat.cast_coe_int,\n       \u2190 abs_mul, sub_mul, div_mul_cancel _ hk\u2080'.ne', mul_comm],\nend\n\nend dirichlet\n\nsection rat_approx\n\n/-!\n### Infinitely many good approximations to irrational numbers\n\nWe show that an irrational real number `\u03be` has infinitely many \"good rational approximations\",\ni.e., fractions `x/y` in lowest terms such that `|\u03be - x/y| < 1/y^2`.\n-/\n\nopen set\n\n/-- Given any rational approximation `q` to the irrational real number `\u03be`, there is\na good rational approximation `q'` such that `|\u03be - q'| < |\u03be - q|`. -/\nlemma exists_rat_abs_sub_lt_and_lt_of_irrational {\u03be : \u211d} (h\u03be : irrational \u03be) (q : \u211a) :\n  \u2203 q' : \u211a, |\u03be - q'| < 1 / q'.denom ^ 2 \u2227 |\u03be - q'| < |\u03be - q| :=\nbegin\n  have h := abs_pos.mpr (sub_ne_zero.mpr $ irrational.ne_rat h\u03be q),\n  obtain \u27e8m, hm\u27e9 := exists_nat_gt (1 / |\u03be - q|),\n  have m_pos : (0 : \u211d) < m := (one_div_pos.mpr h).trans hm,\n  obtain \u27e8q', hbd, hden\u27e9 := exists_rat_abs_sub_le_and_denom_le \u03be (nat.cast_pos.mp m_pos),\n  have den_pos : (0 : \u211d) < q'.denom := nat.cast_pos.mpr q'.pos,\n  have md_pos := mul_pos (add_pos m_pos zero_lt_one) den_pos,\n  refine \u27e8q', lt_of_le_of_lt hbd _,\n          lt_of_le_of_lt hbd $ (one_div_lt md_pos h).mpr $ hm.trans $\n            lt_of_lt_of_le (lt_add_one _) $ (le_mul_iff_one_le_right $\n            add_pos m_pos zero_lt_one).mpr $ by exact_mod_cast (q'.pos : 1 \u2264 q'.denom)\u27e9,\n  rw [sq, one_div_lt_one_div md_pos (mul_pos den_pos den_pos), mul_lt_mul_right den_pos],\n  exact lt_add_of_le_of_pos (nat.cast_le.mpr hden) zero_lt_one,\nend\n\n/-- If `\u03be` is an irrational real number, then there are infinitely many good\nrational approximations to `\u03be`. -/\nlemma infinite_rat_abs_sub_lt_one_div_denom_sq_of_irrational {\u03be : \u211d} (h\u03be : irrational \u03be) :\n  {q : \u211a | |\u03be - q| < 1 / q.denom ^ 2}.infinite :=\nbegin\n  refine or.resolve_left (set.finite_or_infinite _) (\u03bb h, _),\n  obtain \u27e8q, _, hq\u27e9 := exists_min_image {q : \u211a | |\u03be - q| < 1 / q.denom ^ 2} (\u03bb q, |\u03be - q|) h\n                                        \u27e8\u230a\u03be\u230b, by simp [abs_of_nonneg, int.fract_lt_one]\u27e9,\n  obtain \u27e8q', hmem, hbetter\u27e9 := exists_rat_abs_sub_lt_and_lt_of_irrational h\u03be q,\n  exact lt_irrefl _ (lt_of_le_of_lt (hq q' hmem) hbetter),\nend\n\nend rat_approx\n\nend real\n\nnamespace rat\n\n/-!\n### Finitely many good approximations to rational numbers\n\nWe now show that a rational number `\u03be` has only finitely many good rational\napproximations.\n-/\n\nopen set\n\n/-- If `\u03be` is rational, then the good rational approximations to `\u03be` have bounded\nnumerator and denominator. -/\n\n\n/-- A rational number has only finitely many good rational approximations. -/\nlemma finite_rat_abs_sub_lt_one_div_denom_sq (\u03be : \u211a) :\n  {q : \u211a | |\u03be - q| < 1 / q.denom ^ 2}.finite :=\nbegin\n  let f : \u211a \u2192 \u2124 \u00d7 \u2115 := \u03bb q, (q.num, q.denom),\n  set s := {q : \u211a | |\u03be - q| < 1 / q.denom ^ 2},\n  have hinj : function.injective f,\n  { intros a b hab,\n    simp only [prod.mk.inj_iff] at hab,\n    rw [\u2190 rat.num_div_denom a, \u2190 rat.num_div_denom b, hab.1, hab.2], },\n  have H : f '' s \u2286 \u22c3 (y : \u2115) (hy : y \u2208 Ioc 0 \u03be.denom), Icc (\u2308\u03be * y\u2309 - 1) (\u230a\u03be * y\u230b + 1) \u00d7\u02e2 {y},\n  { intros xy hxy,\n    simp only [mem_image, mem_set_of_eq] at hxy,\n    obtain \u27e8q, hq\u2081, hq\u2082\u27e9 := hxy,\n    obtain \u27e8hd, hn\u27e9 := denom_le_and_le_num_le_of_sub_lt_one_div_denom_sq hq\u2081,\n    simp_rw [mem_Union],\n    refine \u27e8q.denom, set.mem_Ioc.mpr \u27e8q.pos, hd\u27e9, _\u27e9,\n    simp only [prod_singleton, mem_image, mem_Icc, (congr_arg prod.snd (eq.symm hq\u2082)).trans rfl],\n    exact \u27e8q.num, hn, hq\u2082\u27e9, },\n  refine finite.of_finite_image (finite.subset _ H) (inj_on_of_injective hinj s),\n  exact finite.bUnion (finite_Ioc _ _) (\u03bb x hx, finite.prod (finite_Icc _ _) (finite_singleton _)),\nend\n\nend rat\n\n/-- The set of good rational approximations to a real number `\u03be` is infinite if and only if\n`\u03be` is irrational. -/\nlemma real.infinite_rat_abs_sub_lt_one_div_denom_sq_iff_irrational (\u03be : \u211d) :\n  {q : \u211a | |\u03be - q| < 1 / q.denom ^ 2}.infinite \u2194 irrational \u03be :=\nbegin\n  refine \u27e8\u03bb h, (irrational_iff_ne_rational \u03be).mpr (\u03bb a b H, set.not_infinite.mpr _ h),\n          real.infinite_rat_abs_sub_lt_one_div_denom_sq_of_irrational\u27e9,\n  convert rat.finite_rat_abs_sub_lt_one_div_denom_sq ((a : \u211a) / b),\n  ext q,\n  rw [H, (by push_cast : (1 : \u211d) / q.denom ^ 2 = (1 / q.denom ^ 2 : \u211a))],\n  norm_cast,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/diophantine_approximation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7117925489837345}}
{"text": "/-\nCopyright (c) 2019 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard\n\n! This file was ported from Lean 3 source module data.real.ereal\n! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Real.Basic\nimport Mathbin.Data.Real.Ennreal\nimport Mathbin.Data.Sign\n\n/-!\n# The extended reals [-\u221e, \u221e].\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines `ereal`, the real numbers together with a top and bottom element,\nreferred to as \u22a4 and \u22a5. It is implemented as `with_bot (with_top \u211d)`\n\nAddition and multiplication are problematic in the presence of \u00b1\u221e, but\nnegation has a natural definition and satisfies the usual properties.\n\nAn ad hoc addition is defined, for which `ereal` is an `add_comm_monoid`, and even an ordered one\n(if `a \u2264 a'` and `b \u2264 b'` then `a + b \u2264 a' + b'`).\nNote however that addition is badly behaved at `(\u22a5, \u22a4)` and `(\u22a4, \u22a5)` so this can not be upgraded\nto a group structure. Our choice is that `\u22a5 + \u22a4 = \u22a4 + \u22a5 = \u22a5`, to make sure that the exponential\nand the logarithm between `ereal` and `\u211d\u22650\u221e` respect the operations (notice that the\nconvention `0 * \u221e = 0` on `\u211d\u22650\u221e` is enforced by measure theory).\n\nAn ad hoc subtraction is then defined by `x - y = x + (-y)`. It does not have nice properties,\nbut it is sometimes convenient to have.\n\nAn ad hoc multiplication is defined, for which `ereal` is a `comm_monoid_with_zero`. We make the\nchoice that `0 * x = x * 0 = 0` for any `x` (while the other cases are defined non-ambiguously).\nThis does not distribute with addition, as `\u22a5 = \u22a5 + \u22a4 = 1*\u22a5 + (-1)*\u22a5 \u2260 (1 - 1) * \u22a5 = 0 * \u22a5 = 0`.\n\n`ereal` is a `complete_linear_order`; this is deduced by type class inference from\nthe fact that `with_bot (with_top L)` is a complete linear order if `L` is\na conditionally complete linear order.\n\nCoercions from `\u211d` and from `\u211d\u22650\u221e` are registered, and their basic properties are proved. The main\none is the real coercion, and is usually referred to just as `coe` (lemmas such as\n`ereal.coe_add` deal with this coercion). The one from `ennreal` is usually called `coe_ennreal`\nin the `ereal` namespace.\n\nWe define an absolute value `ereal.abs` from `ereal` to `\u211d\u22650\u221e`. Two elements of `ereal` coincide\nif and only if they have the same absolute value and the same sign.\n\n## Tags\n\nreal, ereal, complete lattice\n-/\n\n\nopen Function\n\nopen ENNReal NNReal\n\nnoncomputable section\n\n#print EReal /-\n/-- ereal : The type `[-\u221e, \u221e]` -/\ndef EReal :=\n  WithBot (WithTop \u211d)deriving Bot, Zero, One, Nontrivial, AddMonoid, SupSet, InfSet,\n  CompleteLinearOrder, LinearOrderedAddCommMonoid, ZeroLEOneClass\n#align ereal EReal\n-/\n\n#print Real.toEReal /-\n/-- The canonical inclusion froms reals to ereals. Do not use directly: as this is registered as\na coercion, use the coercion instead. -/\ndef Real.toEReal : \u211d \u2192 EReal :=\n  some \u2218 some\n#align real.to_ereal Real.toEReal\n-/\n\nnamespace EReal\n\n/- warning: ereal.decidable_lt -> EReal.decidableLt is a dubious translation:\nlean 3 declaration is\n  DecidableRel.{1} EReal (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))))\nbut is expected to have type\n  DecidableRel.{1} EReal (fun (x._@.Mathlib.Data.Real.EReal._hyg.238 : EReal) (x._@.Mathlib.Data.Real.EReal._hyg.240 : EReal) => LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x._@.Mathlib.Data.Real.EReal._hyg.238 x._@.Mathlib.Data.Real.EReal._hyg.240)\nCase conversion may be inaccurate. Consider using '#align ereal.decidable_lt EReal.decidableLt\u2093'. -/\n-- things unify with `with_bot.decidable_lt` later if we we don't provide this explicitly.\ninstance decidableLt : DecidableRel ((\u00b7 < \u00b7) : EReal \u2192 EReal \u2192 Prop) :=\n  WithBot.decidableLT\n#align ereal.decidable_lt EReal.decidableLt\n\n-- TODO: Provide explicitly, otherwise it is inferred noncomputably from `complete_linear_order`\ninstance : Top EReal :=\n  \u27e8some \u22a4\u27e9\n\ninstance : Coe \u211d EReal :=\n  \u27e8Real.toEReal\u27e9\n\n/- warning: ereal.coe_strict_mono -> EReal.coe_strictMono is a dubious translation:\nlean 3 declaration is\n  StrictMono.{0, 0} Real EReal Real.preorder (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))))\nbut is expected to have type\n  StrictMono.{0, 0} Real EReal Real.instPreorderReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) Real.toEReal\nCase conversion may be inaccurate. Consider using '#align ereal.coe_strict_mono EReal.coe_strictMono\u2093'. -/\ntheorem coe_strictMono : StrictMono (coe : \u211d \u2192 EReal) :=\n  WithBot.coe_strictMono.comp WithTop.coe_strictMono\n#align ereal.coe_strict_mono EReal.coe_strictMono\n\n#print EReal.coe_injective /-\ntheorem coe_injective : Injective (coe : \u211d \u2192 EReal) :=\n  coe_strictMono.Injective\n#align ereal.coe_injective EReal.coe_injective\n-/\n\n/- warning: ereal.coe_le_coe_iff -> EReal.coe_le_coe_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : Real} {y : Real}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y)) (LE.le.{0} Real Real.hasLe x y)\nbut is expected to have type\n  forall {x : Real} {y : Real}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal x) (Real.toEReal y)) (LE.le.{0} Real Real.instLEReal x y)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_le_coe_iff EReal.coe_le_coe_iff\u2093'. -/\n@[simp, norm_cast]\nprotected theorem coe_le_coe_iff {x y : \u211d} : (x : EReal) \u2264 (y : EReal) \u2194 x \u2264 y :=\n  coe_strictMono.le_iff_le\n#align ereal.coe_le_coe_iff EReal.coe_le_coe_iff\n\n/- warning: ereal.coe_lt_coe_iff -> EReal.coe_lt_coe_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : Real} {y : Real}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y)) (LT.lt.{0} Real Real.hasLt x y)\nbut is expected to have type\n  forall {x : Real} {y : Real}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal x) (Real.toEReal y)) (LT.lt.{0} Real Real.instLTReal x y)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_lt_coe_iff EReal.coe_lt_coe_iff\u2093'. -/\n@[simp, norm_cast]\nprotected theorem coe_lt_coe_iff {x y : \u211d} : (x : EReal) < (y : EReal) \u2194 x < y :=\n  coe_strictMono.lt_iff_lt\n#align ereal.coe_lt_coe_iff EReal.coe_lt_coe_iff\n\n#print EReal.coe_eq_coe_iff /-\n@[simp, norm_cast]\nprotected theorem coe_eq_coe_iff {x y : \u211d} : (x : EReal) = (y : EReal) \u2194 x = y :=\n  coe_injective.eq_iff\n#align ereal.coe_eq_coe_iff EReal.coe_eq_coe_iff\n-/\n\n#print EReal.coe_ne_coe_iff /-\nprotected theorem coe_ne_coe_iff {x y : \u211d} : (x : EReal) \u2260 (y : EReal) \u2194 x \u2260 y :=\n  coe_injective.ne_iff\n#align ereal.coe_ne_coe_iff EReal.coe_ne_coe_iff\n-/\n\n#print ENNReal.toEReal /-\n/-- The canonical map from nonnegative extended reals to extended reals -/\ndef ENNReal.toEReal : \u211d\u22650\u221e \u2192 EReal\n  | \u22a4 => \u22a4\n  | some x => x.1\n#align ennreal.to_ereal ENNReal.toEReal\n-/\n\n#print EReal.hasCoeENNReal /-\ninstance hasCoeENNReal : Coe \u211d\u22650\u221e EReal :=\n  \u27e8ENNReal.toEReal\u27e9\n#align ereal.has_coe_ennreal EReal.hasCoeENNReal\n-/\n\ninstance : Inhabited EReal :=\n  \u27e80\u27e9\n\n/- warning: ereal.coe_zero -> EReal.coe_zero is a dubious translation:\nlean 3 declaration is\n  Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))\nbut is expected to have type\n  Eq.{1} EReal (Real.toEReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_zero EReal.coe_zero\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_zero : ((0 : \u211d) : EReal) = 0 :=\n  rfl\n#align ereal.coe_zero EReal.coe_zero\n\n/- warning: ereal.coe_one -> EReal.coe_one is a dubious translation:\nlean 3 declaration is\n  Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (OfNat.ofNat.{0} Real 1 (OfNat.mk.{0} Real 1 (One.one.{0} Real Real.hasOne)))) (OfNat.ofNat.{0} EReal 1 (OfNat.mk.{0} EReal 1 (One.one.{0} EReal EReal.hasOne)))\nbut is expected to have type\n  Eq.{1} EReal (Real.toEReal (OfNat.ofNat.{0} Real 1 (One.toOfNat1.{0} Real Real.instOneReal))) (OfNat.ofNat.{0} EReal 1 (One.toOfNat1.{0} EReal instERealOne))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_one EReal.coe_one\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_one : ((1 : \u211d) : EReal) = 1 :=\n  rfl\n#align ereal.coe_one EReal.coe_one\n\n#print EReal.rec /-\n/-- A recursor for `ereal` in terms of the coercion.\n\nA typical invocation looks like `induction x using ereal.rec`. Note that using `induction`\ndirectly will unfold `ereal` to `option` which is undesirable.\n\nWhen working in term mode, note that pattern matching can be used directly. -/\n@[elab_as_elim]\nprotected def rec {C : EReal \u2192 Sort _} (h_bot : C \u22a5) (h_real : \u2200 a : \u211d, C a) (h_top : C \u22a4) :\n    \u2200 a : EReal, C a\n  | \u22a5 => h_bot\n  | (a : \u211d) => h_real a\n  | \u22a4 => h_top\n#align ereal.rec EReal.rec\n-/\n\n#print EReal.mul /-\n/-- The multiplication on `ereal`. Our definition satisfies `0 * x = x * 0 = 0` for any `x`, and\npicks the only sensible value elsewhere. -/\nprotected def mul : EReal \u2192 EReal \u2192 EReal\n  | \u22a5, \u22a5 => \u22a4\n  | \u22a5, \u22a4 => \u22a5\n  | \u22a5, (y : \u211d) => if 0 < y then \u22a5 else if y = 0 then 0 else \u22a4\n  | \u22a4, \u22a5 => \u22a5\n  | \u22a4, \u22a4 => \u22a4\n  | \u22a4, (y : \u211d) => if 0 < y then \u22a4 else if y = 0 then 0 else \u22a5\n  | (x : \u211d), \u22a4 => if 0 < x then \u22a4 else if x = 0 then 0 else \u22a5\n  | (x : \u211d), \u22a5 => if 0 < x then \u22a5 else if x = 0 then 0 else \u22a4\n  | (x : \u211d), (y : \u211d) => (x * y : \u211d)\n#align ereal.mul EReal.mul\n-/\n\ninstance : Mul EReal :=\n  \u27e8EReal.mul\u27e9\n\n/- warning: ereal.induction\u2082 -> EReal.induction\u2082 is a dubious translation:\nlean 3 declaration is\n  forall {P : EReal -> EReal -> Prop}, (P (Top.top.{0} EReal EReal.hasTop) (Top.top.{0} EReal EReal.hasTop)) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (P (Top.top.{0} EReal EReal.hasTop) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))) -> (P (Top.top.{0} EReal EReal.hasTop) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (P (Top.top.{0} EReal EReal.hasTop) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))) -> (P (Top.top.{0} EReal EReal.hasTop) (Bot.bot.{0} EReal EReal.hasBot)) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (P ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Top.top.{0} EReal EReal.hasTop))) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (P ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Bot.bot.{0} EReal EReal.hasBot))) -> (P (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) (Top.top.{0} EReal EReal.hasTop)) -> (forall (x : Real) (y : Real), P ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y)) -> (P (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) (Bot.bot.{0} EReal EReal.hasBot)) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (P ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Top.top.{0} EReal EReal.hasTop))) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (P ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Bot.bot.{0} EReal EReal.hasBot))) -> (P (Bot.bot.{0} EReal EReal.hasBot) (Top.top.{0} EReal EReal.hasTop)) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (P (Bot.bot.{0} EReal EReal.hasBot) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))) -> (P (Bot.bot.{0} EReal EReal.hasBot) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) -> (forall (x : Real), (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (P (Bot.bot.{0} EReal EReal.hasBot) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))) -> (P (Bot.bot.{0} EReal EReal.hasBot) (Bot.bot.{0} EReal EReal.hasBot)) -> (forall (x : EReal) (y : EReal), P x y)\nbut is expected to have type\n  forall {P : EReal -> EReal -> Prop}, (P (Top.top.{0} EReal EReal.instTopEReal) (Top.top.{0} EReal EReal.instTopEReal)) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (P (Top.top.{0} EReal EReal.instTopEReal) (Real.toEReal x))) -> (P (Top.top.{0} EReal EReal.instTopEReal) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (P (Top.top.{0} EReal EReal.instTopEReal) (Real.toEReal x))) -> (P (Top.top.{0} EReal EReal.instTopEReal) (Bot.bot.{0} EReal instERealBot)) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (P (Real.toEReal x) (Top.top.{0} EReal EReal.instTopEReal))) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (P (Real.toEReal x) (Bot.bot.{0} EReal instERealBot))) -> (P (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (Top.top.{0} EReal EReal.instTopEReal)) -> (forall (x : Real) (y : Real), P (Real.toEReal x) (Real.toEReal y)) -> (P (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (Bot.bot.{0} EReal instERealBot)) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (P (Real.toEReal x) (Top.top.{0} EReal EReal.instTopEReal))) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (P (Real.toEReal x) (Bot.bot.{0} EReal instERealBot))) -> (P (Bot.bot.{0} EReal instERealBot) (Top.top.{0} EReal EReal.instTopEReal)) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (P (Bot.bot.{0} EReal instERealBot) (Real.toEReal x))) -> (P (Bot.bot.{0} EReal instERealBot) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) -> (forall (x : Real), (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (P (Bot.bot.{0} EReal instERealBot) (Real.toEReal x))) -> (P (Bot.bot.{0} EReal instERealBot) (Bot.bot.{0} EReal instERealBot)) -> (forall (x : EReal) (y : EReal), P x y)\nCase conversion may be inaccurate. Consider using '#align ereal.induction\u2082 EReal.induction\u2082\u2093'. -/\n/-- Induct on two ereals by performing case splits on the sign of one whenever the other is\ninfinite. -/\n@[elab_as_elim]\ntheorem induction\u2082 {P : EReal \u2192 EReal \u2192 Prop} (top_top : P \u22a4 \u22a4) (top_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a4 x)\n    (top_zero : P \u22a4 0) (top_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a4 x) (top_bot : P \u22a4 \u22a5)\n    (pos_top : \u2200 x : \u211d, 0 < x \u2192 P x \u22a4) (pos_bot : \u2200 x : \u211d, 0 < x \u2192 P x \u22a5) (zero_top : P 0 \u22a4)\n    (coe_coe : \u2200 x y : \u211d, P x y) (zero_bot : P 0 \u22a5) (neg_top : \u2200 x : \u211d, x < 0 \u2192 P x \u22a4)\n    (neg_bot : \u2200 x : \u211d, x < 0 \u2192 P x \u22a5) (bot_top : P \u22a5 \u22a4) (bot_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a5 x)\n    (bot_zero : P \u22a5 0) (bot_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a5 x) (bot_bot : P \u22a5 \u22a5) : \u2200 x y, P x y\n  | \u22a5, \u22a5 => bot_bot\n  | \u22a5, (y : \u211d) => by\n    rcases lt_trichotomy 0 y with (hy | rfl | hy)\n    exacts[bot_pos y hy, bot_zero, bot_neg y hy]\n  | \u22a5, \u22a4 => bot_top\n  | (x : \u211d), \u22a5 => by\n    rcases lt_trichotomy 0 x with (hx | rfl | hx)\n    exacts[pos_bot x hx, zero_bot, neg_bot x hx]\n  | (x : \u211d), (y : \u211d) => coe_coe _ _\n  | (x : \u211d), \u22a4 => by\n    rcases lt_trichotomy 0 x with (hx | rfl | hx)\n    exacts[pos_top x hx, zero_top, neg_top x hx]\n  | \u22a4, \u22a5 => top_bot\n  | \u22a4, (y : \u211d) => by\n    rcases lt_trichotomy 0 y with (hy | rfl | hy)\n    exacts[top_pos y hy, top_zero, top_neg y hy]\n  | \u22a4, \u22a4 => top_top\n#align ereal.induction\u2082 EReal.induction\u2082\n\n/-! `ereal` with its multiplication is a `comm_monoid_with_zero`. However, the proof of\nassociativity by hand is extremely painful (with 125 cases...). Instead, we will deduce it later\non from the facts that the absolute value and the sign are multiplicative functions taking value\nin associative objects, and that they characterize an extended real number. For now, we only\nrecord more basic properties of multiplication.\n-/\n\n\ninstance : MulZeroOneClass EReal :=\n  { EReal.hasMul, EReal.hasOne,\n    EReal.hasZero with\n    one_mul := fun x => by\n      induction x using EReal.rec <;>\n        \u00b7 dsimp only [(\u00b7 * \u00b7)]\n          simp only [EReal.mul, \u2190 EReal.coe_one, zero_lt_one, if_true, one_mul]\n    mul_one := fun x => by\n      induction x using EReal.rec <;>\n        \u00b7 dsimp only [(\u00b7 * \u00b7)]\n          simp only [EReal.mul, \u2190 EReal.coe_one, zero_lt_one, if_true, mul_one]\n    zero_mul := fun x => by\n      induction x using EReal.rec <;>\n        \u00b7 simp only [(\u00b7 * \u00b7)]\n          simp only [EReal.mul, \u2190 EReal.coe_zero, zero_lt_one, if_true, if_false, lt_irrefl (0 : \u211d),\n            eq_self_iff_true, MulZeroClass.zero_mul]\n    mul_zero := fun x => by\n      induction x using EReal.rec <;>\n        \u00b7 simp only [(\u00b7 * \u00b7)]\n          simp only [EReal.mul, \u2190 EReal.coe_zero, zero_lt_one, if_true, if_false, lt_irrefl (0 : \u211d),\n            eq_self_iff_true, MulZeroClass.mul_zero] }\n\n/-! ### Real coercion -/\n\n\n#print EReal.canLift /-\ninstance canLift : CanLift EReal \u211d coe fun r => r \u2260 \u22a4 \u2227 r \u2260 \u22a5\n    where prf x hx := by\n    induction x using EReal.rec\n    \u00b7 simpa using hx\n    \u00b7 simp\n    \u00b7 simpa using hx\n#align ereal.can_lift EReal.canLift\n-/\n\n#print EReal.toReal /-\n/-- The map from extended reals to reals sending infinities to zero. -/\ndef toReal : EReal \u2192 \u211d\n  | \u22a5 => 0\n  | \u22a4 => 0\n  | (x : \u211d) => x\n#align ereal.to_real EReal.toReal\n-/\n\n/- warning: ereal.to_real_top -> EReal.toReal_top is a dubious translation:\nlean 3 declaration is\n  Eq.{1} Real (EReal.toReal (Top.top.{0} EReal EReal.hasTop)) (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))\nbut is expected to have type\n  Eq.{1} Real (EReal.toReal (Top.top.{0} EReal EReal.instTopEReal)) (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_top EReal.toReal_top\u2093'. -/\n@[simp]\ntheorem toReal_top : toReal \u22a4 = 0 :=\n  rfl\n#align ereal.to_real_top EReal.toReal_top\n\n/- warning: ereal.to_real_bot -> EReal.toReal_bot is a dubious translation:\nlean 3 declaration is\n  Eq.{1} Real (EReal.toReal (Bot.bot.{0} EReal EReal.hasBot)) (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))\nbut is expected to have type\n  Eq.{1} Real (EReal.toReal (Bot.bot.{0} EReal instERealBot)) (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_bot EReal.toReal_bot\u2093'. -/\n@[simp]\ntheorem toReal_bot : toReal \u22a5 = 0 :=\n  rfl\n#align ereal.to_real_bot EReal.toReal_bot\n\n/- warning: ereal.to_real_zero -> EReal.toReal_zero is a dubious translation:\nlean 3 declaration is\n  Eq.{1} Real (EReal.toReal (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))\nbut is expected to have type\n  Eq.{1} Real (EReal.toReal (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_zero EReal.toReal_zero\u2093'. -/\n@[simp]\ntheorem toReal_zero : toReal 0 = 0 :=\n  rfl\n#align ereal.to_real_zero EReal.toReal_zero\n\n/- warning: ereal.to_real_one -> EReal.toReal_one is a dubious translation:\nlean 3 declaration is\n  Eq.{1} Real (EReal.toReal (OfNat.ofNat.{0} EReal 1 (OfNat.mk.{0} EReal 1 (One.one.{0} EReal EReal.hasOne)))) (OfNat.ofNat.{0} Real 1 (OfNat.mk.{0} Real 1 (One.one.{0} Real Real.hasOne)))\nbut is expected to have type\n  Eq.{1} Real (EReal.toReal (OfNat.ofNat.{0} EReal 1 (One.toOfNat1.{0} EReal instERealOne))) (OfNat.ofNat.{0} Real 1 (One.toOfNat1.{0} Real Real.instOneReal))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_one EReal.toReal_one\u2093'. -/\n@[simp]\ntheorem toReal_one : toReal 1 = 1 :=\n  rfl\n#align ereal.to_real_one EReal.toReal_one\n\n#print EReal.toReal_coe /-\n@[simp]\ntheorem toReal_coe (x : \u211d) : toReal (x : EReal) = x :=\n  rfl\n#align ereal.to_real_coe EReal.toReal_coe\n-/\n\n/- warning: ereal.bot_lt_coe -> EReal.bot_lt_coe is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Bot.bot.{0} EReal EReal.hasBot) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)\nbut is expected to have type\n  forall (x : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Bot.bot.{0} EReal instERealBot) (Real.toEReal x)\nCase conversion may be inaccurate. Consider using '#align ereal.bot_lt_coe EReal.bot_lt_coe\u2093'. -/\n@[simp]\ntheorem bot_lt_coe (x : \u211d) : (\u22a5 : EReal) < x :=\n  WithBot.bot_lt_coe _\n#align ereal.bot_lt_coe EReal.bot_lt_coe\n\n#print EReal.coe_ne_bot /-\n@[simp]\ntheorem coe_ne_bot (x : \u211d) : (x : EReal) \u2260 \u22a5 :=\n  (bot_lt_coe x).ne'\n#align ereal.coe_ne_bot EReal.coe_ne_bot\n-/\n\n#print EReal.bot_ne_coe /-\n@[simp]\ntheorem bot_ne_coe (x : \u211d) : (\u22a5 : EReal) \u2260 x :=\n  (bot_lt_coe x).Ne\n#align ereal.bot_ne_coe EReal.bot_ne_coe\n-/\n\n/- warning: ereal.coe_lt_top -> EReal.coe_lt_top is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  forall (x : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal x) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_lt_top EReal.coe_lt_top\u2093'. -/\n@[simp]\ntheorem coe_lt_top (x : \u211d) : (x : EReal) < \u22a4 :=\n  by\n  apply WithBot.coe_lt_coe.2\n  exact WithTop.coe_lt_top _\n#align ereal.coe_lt_top EReal.coe_lt_top\n\n#print EReal.coe_ne_top /-\n@[simp]\ntheorem coe_ne_top (x : \u211d) : (x : EReal) \u2260 \u22a4 :=\n  (coe_lt_top x).Ne\n#align ereal.coe_ne_top EReal.coe_ne_top\n-/\n\n#print EReal.top_ne_coe /-\n@[simp]\ntheorem top_ne_coe (x : \u211d) : (\u22a4 : EReal) \u2260 x :=\n  (coe_lt_top x).ne'\n#align ereal.top_ne_coe EReal.top_ne_coe\n-/\n\n/- warning: ereal.bot_lt_zero -> EReal.bot_lt_zero is a dubious translation:\nlean 3 declaration is\n  LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Bot.bot.{0} EReal EReal.hasBot) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))\nbut is expected to have type\n  LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Bot.bot.{0} EReal instERealBot) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))\nCase conversion may be inaccurate. Consider using '#align ereal.bot_lt_zero EReal.bot_lt_zero\u2093'. -/\n@[simp]\ntheorem bot_lt_zero : (\u22a5 : EReal) < 0 :=\n  bot_lt_coe 0\n#align ereal.bot_lt_zero EReal.bot_lt_zero\n\n/- warning: ereal.bot_ne_zero -> EReal.bot_ne_zero is a dubious translation:\nlean 3 declaration is\n  Ne.{1} EReal (Bot.bot.{0} EReal EReal.hasBot) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))\nbut is expected to have type\n  Ne.{1} EReal (Bot.bot.{0} EReal instERealBot) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))\nCase conversion may be inaccurate. Consider using '#align ereal.bot_ne_zero EReal.bot_ne_zero\u2093'. -/\n@[simp]\ntheorem bot_ne_zero : (\u22a5 : EReal) \u2260 0 :=\n  (coe_ne_bot 0).symm\n#align ereal.bot_ne_zero EReal.bot_ne_zero\n\n/- warning: ereal.zero_ne_bot -> EReal.zero_ne_bot is a dubious translation:\nlean 3 declaration is\n  Ne.{1} EReal (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) (Bot.bot.{0} EReal EReal.hasBot)\nbut is expected to have type\n  Ne.{1} EReal (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (Bot.bot.{0} EReal instERealBot)\nCase conversion may be inaccurate. Consider using '#align ereal.zero_ne_bot EReal.zero_ne_bot\u2093'. -/\n@[simp]\ntheorem zero_ne_bot : (0 : EReal) \u2260 \u22a5 :=\n  coe_ne_bot 0\n#align ereal.zero_ne_bot EReal.zero_ne_bot\n\n/- warning: ereal.zero_lt_top -> EReal.zero_lt_top is a dubious translation:\nlean 3 declaration is\n  LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.zero_lt_top EReal.zero_lt_top\u2093'. -/\n@[simp]\ntheorem zero_lt_top : (0 : EReal) < \u22a4 :=\n  coe_lt_top 0\n#align ereal.zero_lt_top EReal.zero_lt_top\n\n/- warning: ereal.zero_ne_top -> EReal.zero_ne_top is a dubious translation:\nlean 3 declaration is\n  Ne.{1} EReal (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  Ne.{1} EReal (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.zero_ne_top EReal.zero_ne_top\u2093'. -/\n@[simp]\ntheorem zero_ne_top : (0 : EReal) \u2260 \u22a4 :=\n  coe_ne_top 0\n#align ereal.zero_ne_top EReal.zero_ne_top\n\n/- warning: ereal.top_ne_zero -> EReal.top_ne_zero is a dubious translation:\nlean 3 declaration is\n  Ne.{1} EReal (Top.top.{0} EReal EReal.hasTop) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))\nbut is expected to have type\n  Ne.{1} EReal (Top.top.{0} EReal EReal.instTopEReal) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))\nCase conversion may be inaccurate. Consider using '#align ereal.top_ne_zero EReal.top_ne_zero\u2093'. -/\n@[simp]\ntheorem top_ne_zero : (\u22a4 : EReal) \u2260 0 :=\n  (coe_ne_top 0).symm\n#align ereal.top_ne_zero EReal.top_ne_zero\n\n/- warning: ereal.coe_add -> EReal.coe_add is a dubious translation:\nlean 3 declaration is\n  forall (x : Real) (y : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (HAdd.hAdd.{0, 0, 0} Real Real Real (instHAdd.{0} Real Real.hasAdd) x y)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y))\nbut is expected to have type\n  forall (x : Real) (y : Real), Eq.{1} EReal (Real.toEReal (HAdd.hAdd.{0, 0, 0} Real Real Real (instHAdd.{0} Real Real.instAddReal) x y)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (Real.toEReal x) (Real.toEReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_add EReal.coe_add\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_add (x y : \u211d) : (\u2191(x + y) : EReal) = x + y :=\n  rfl\n#align ereal.coe_add EReal.coe_add\n\n/- warning: ereal.coe_mul -> EReal.coe_mul is a dubious translation:\nlean 3 declaration is\n  forall (x : Real) (y : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.hasMul) x y)) (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y))\nbut is expected to have type\n  forall (x : Real) (y : Real), Eq.{1} EReal (Real.toEReal (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.instMulReal) x y)) (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Real.toEReal x) (Real.toEReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_mul EReal.coe_mul\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_mul (x y : \u211d) : (\u2191(x * y) : EReal) = x * y :=\n  rfl\n#align ereal.coe_mul EReal.coe_mul\n\n/- warning: ereal.coe_nsmul -> EReal.coe_nsmul is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (SMul.smul.{0, 0} Nat Real (AddMonoid.SMul.{0} Real Real.addMonoid) n x)) (SMul.smul.{0, 0} Nat EReal (AddMonoid.SMul.{0} EReal EReal.addMonoid) n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))\nbut is expected to have type\n  forall (n : Nat) (x : Real), Eq.{1} EReal (Real.toEReal (HSMul.hSMul.{0, 0, 0} Nat Real Real (instHSMul.{0, 0} Nat Real (AddMonoid.SMul.{0} Real Real.instAddMonoidReal)) n x)) (HSMul.hSMul.{0, 0, 0} Nat EReal EReal (instHSMul.{0, 0} Nat EReal (AddMonoid.SMul.{0} EReal instERealAddMonoid)) n (Real.toEReal x))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_nsmul EReal.coe_nsmul\u2093'. -/\n@[norm_cast]\ntheorem coe_nsmul (n : \u2115) (x : \u211d) : (\u2191(n \u2022 x) : EReal) = n \u2022 x :=\n  map_nsmul (\u27e8coe, coe_zero, coe_add\u27e9 : \u211d \u2192+ EReal) _ _\n#align ereal.coe_nsmul EReal.coe_nsmul\n\n/- warning: ereal.coe_bit0 clashes with [anonymous] -> [anonymous]\nwarning: ereal.coe_bit0 -> [anonymous] is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (bit0.{0} Real Real.hasAdd x)) (bit0.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))\nbut is expected to have type\n  forall {x : Type.{u}} {\u03b2 : Type.{v}}, (Nat -> x -> \u03b2) -> Nat -> (List.{u} x) -> (List.{v} \u03b2)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_bit0 [anonymous]\u2093'. -/\n@[simp, norm_cast]\ntheorem [anonymous] (x : \u211d) : (\u2191(bit0 x) : EReal) = bit0 x :=\n  rfl\n#align ereal.coe_bit0 [anonymous]\n\n/- warning: ereal.coe_bit1 clashes with [anonymous] -> [anonymous]\nwarning: ereal.coe_bit1 -> [anonymous] is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (bit1.{0} Real Real.hasOne Real.hasAdd x)) (bit1.{0} EReal EReal.hasOne (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))\nbut is expected to have type\n  forall {x : Type.{u}} {\u03b2 : Type.{v}}, (Nat -> x -> \u03b2) -> Nat -> (List.{u} x) -> (List.{v} \u03b2)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_bit1 [anonymous]\u2093'. -/\n@[simp, norm_cast]\ntheorem [anonymous] (x : \u211d) : (\u2191(bit1 x) : EReal) = bit1 x :=\n  rfl\n#align ereal.coe_bit1 [anonymous]\n\n/- warning: ereal.coe_eq_zero -> EReal.coe_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (Eq.{1} Real x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))))\nbut is expected to have type\n  forall {x : Real}, Iff (Eq.{1} EReal (Real.toEReal x) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (Eq.{1} Real x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_eq_zero EReal.coe_eq_zero\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_eq_zero {x : \u211d} : (x : EReal) = 0 \u2194 x = 0 :=\n  EReal.coe_eq_coe_iff\n#align ereal.coe_eq_zero EReal.coe_eq_zero\n\n/- warning: ereal.coe_eq_one -> EReal.coe_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (OfNat.ofNat.{0} EReal 1 (OfNat.mk.{0} EReal 1 (One.one.{0} EReal EReal.hasOne)))) (Eq.{1} Real x (OfNat.ofNat.{0} Real 1 (OfNat.mk.{0} Real 1 (One.one.{0} Real Real.hasOne))))\nbut is expected to have type\n  forall {x : Real}, Iff (Eq.{1} EReal (Real.toEReal x) (OfNat.ofNat.{0} EReal 1 (One.toOfNat1.{0} EReal instERealOne))) (Eq.{1} Real x (OfNat.ofNat.{0} Real 1 (One.toOfNat1.{0} Real Real.instOneReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_eq_one EReal.coe_eq_one\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_eq_one {x : \u211d} : (x : EReal) = 1 \u2194 x = 1 :=\n  EReal.coe_eq_coe_iff\n#align ereal.coe_eq_one EReal.coe_eq_one\n\n/- warning: ereal.coe_ne_zero -> EReal.coe_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (Ne.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (Ne.{1} Real x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))))\nbut is expected to have type\n  forall {x : Real}, Iff (Ne.{1} EReal (Real.toEReal x) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (Ne.{1} Real x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ne_zero EReal.coe_ne_zero\u2093'. -/\ntheorem coe_ne_zero {x : \u211d} : (x : EReal) \u2260 0 \u2194 x \u2260 0 :=\n  EReal.coe_ne_coe_iff\n#align ereal.coe_ne_zero EReal.coe_ne_zero\n\n/- warning: ereal.coe_ne_one -> EReal.coe_ne_one is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (Ne.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (OfNat.ofNat.{0} EReal 1 (OfNat.mk.{0} EReal 1 (One.one.{0} EReal EReal.hasOne)))) (Ne.{1} Real x (OfNat.ofNat.{0} Real 1 (OfNat.mk.{0} Real 1 (One.one.{0} Real Real.hasOne))))\nbut is expected to have type\n  forall {x : Real}, Iff (Ne.{1} EReal (Real.toEReal x) (OfNat.ofNat.{0} EReal 1 (One.toOfNat1.{0} EReal instERealOne))) (Ne.{1} Real x (OfNat.ofNat.{0} Real 1 (One.toOfNat1.{0} Real Real.instOneReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ne_one EReal.coe_ne_one\u2093'. -/\ntheorem coe_ne_one {x : \u211d} : (x : EReal) \u2260 1 \u2194 x \u2260 1 :=\n  EReal.coe_ne_coe_iff\n#align ereal.coe_ne_one EReal.coe_ne_one\n\n/- warning: ereal.coe_nonneg -> EReal.coe_nonneg is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (LE.le.{0} Real Real.hasLe (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x)\nbut is expected to have type\n  forall {x : Real}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (Real.toEReal x)) (LE.le.{0} Real Real.instLEReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_nonneg EReal.coe_nonneg\u2093'. -/\n@[simp, norm_cast]\nprotected theorem coe_nonneg {x : \u211d} : (0 : EReal) \u2264 x \u2194 0 \u2264 x :=\n  EReal.coe_le_coe_iff\n#align ereal.coe_nonneg EReal.coe_nonneg\n\n/- warning: ereal.coe_nonpos -> EReal.coe_nonpos is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (LE.le.{0} Real Real.hasLe x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))))\nbut is expected to have type\n  forall {x : Real}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal x) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (LE.le.{0} Real Real.instLEReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_nonpos EReal.coe_nonpos\u2093'. -/\n@[simp, norm_cast]\nprotected theorem coe_nonpos {x : \u211d} : (x : EReal) \u2264 0 \u2194 x \u2264 0 :=\n  EReal.coe_le_coe_iff\n#align ereal.coe_nonpos EReal.coe_nonpos\n\n/- warning: ereal.coe_pos -> EReal.coe_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x)\nbut is expected to have type\n  forall {x : Real}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (Real.toEReal x)) (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_pos EReal.coe_pos\u2093'. -/\n@[simp, norm_cast]\nprotected theorem coe_pos {x : \u211d} : (0 : EReal) < x \u2194 0 < x :=\n  EReal.coe_lt_coe_iff\n#align ereal.coe_pos EReal.coe_pos\n\n/- warning: ereal.coe_neg' -> EReal.coe_neg' is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))))\nbut is expected to have type\n  forall {x : Real}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal x) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_neg' EReal.coe_neg'\u2093'. -/\n@[simp, norm_cast]\nprotected theorem coe_neg' {x : \u211d} : (x : EReal) < 0 \u2194 x < 0 :=\n  EReal.coe_lt_coe_iff\n#align ereal.coe_neg' EReal.coe_neg'\n\n/- warning: ereal.to_real_le_to_real -> EReal.toReal_le_toReal is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) -> (Ne.{1} EReal x (Bot.bot.{0} EReal EReal.hasBot)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.hasTop)) -> (LE.le.{0} Real Real.hasLe (EReal.toReal x) (EReal.toReal y))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) -> (Ne.{1} EReal x (Bot.bot.{0} EReal instERealBot)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.instTopEReal)) -> (LE.le.{0} Real Real.instLEReal (EReal.toReal x) (EReal.toReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_le_to_real EReal.toReal_le_toReal\u2093'. -/\ntheorem toReal_le_toReal {x y : EReal} (h : x \u2264 y) (hx : x \u2260 \u22a5) (hy : y \u2260 \u22a4) :\n    x.toReal \u2264 y.toReal := by\n  lift x to \u211d\n  \u00b7 simp [hx, (h.trans_lt (lt_top_iff_ne_top.2 hy)).Ne]\n  lift y to \u211d\n  \u00b7 simp [hy, ((bot_lt_iff_ne_bot.2 hx).trans_le h).ne']\n  simpa using h\n#align ereal.to_real_le_to_real EReal.toReal_le_toReal\n\n#print EReal.coe_toReal /-\ntheorem coe_toReal {x : EReal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) : (x.toReal : EReal) = x :=\n  by\n  induction x using EReal.rec\n  \u00b7 simpa using h'x\n  \u00b7 rfl\n  \u00b7 simpa using hx\n#align ereal.coe_to_real EReal.coe_toReal\n-/\n\n/- warning: ereal.le_coe_to_real -> EReal.le_coe_toReal is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.hasTop)) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (EReal.toReal x)))\nbut is expected to have type\n  forall {x : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.instTopEReal)) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x (Real.toEReal (EReal.toReal x)))\nCase conversion may be inaccurate. Consider using '#align ereal.le_coe_to_real EReal.le_coe_toReal\u2093'. -/\ntheorem le_coe_toReal {x : EReal} (h : x \u2260 \u22a4) : x \u2264 x.toReal :=\n  by\n  by_cases h' : x = \u22a5\n  \u00b7 simp only [h', bot_le]\n  \u00b7 simp only [le_refl, coe_to_real h h']\n#align ereal.le_coe_to_real EReal.le_coe_toReal\n\n/- warning: ereal.coe_to_real_le -> EReal.coe_toReal_le is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (Ne.{1} EReal x (Bot.bot.{0} EReal EReal.hasBot)) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (EReal.toReal x)) x)\nbut is expected to have type\n  forall {x : EReal}, (Ne.{1} EReal x (Bot.bot.{0} EReal instERealBot)) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal (EReal.toReal x)) x)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_to_real_le EReal.coe_toReal_le\u2093'. -/\ntheorem coe_toReal_le {x : EReal} (h : x \u2260 \u22a5) : \u2191x.toReal \u2264 x :=\n  by\n  by_cases h' : x = \u22a4\n  \u00b7 simp only [h', le_top]\n  \u00b7 simp only [le_refl, coe_to_real h' h]\n#align ereal.coe_to_real_le EReal.coe_toReal_le\n\n/- warning: ereal.eq_top_iff_forall_lt -> EReal.eq_top_iff_forall_lt is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal), Iff (Eq.{1} EReal x (Top.top.{0} EReal EReal.hasTop)) (forall (y : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y) x)\nbut is expected to have type\n  forall (x : EReal), Iff (Eq.{1} EReal x (Top.top.{0} EReal EReal.instTopEReal)) (forall (y : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal y) x)\nCase conversion may be inaccurate. Consider using '#align ereal.eq_top_iff_forall_lt EReal.eq_top_iff_forall_lt\u2093'. -/\ntheorem eq_top_iff_forall_lt (x : EReal) : x = \u22a4 \u2194 \u2200 y : \u211d, (y : EReal) < x :=\n  by\n  constructor\n  \u00b7 rintro rfl\n    exact EReal.coe_lt_top\n  \u00b7 contrapose!\n    intro h\n    exact \u27e8x.to_real, le_coe_to_real h\u27e9\n#align ereal.eq_top_iff_forall_lt EReal.eq_top_iff_forall_lt\n\n/- warning: ereal.eq_bot_iff_forall_lt -> EReal.eq_bot_iff_forall_lt is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal), Iff (Eq.{1} EReal x (Bot.bot.{0} EReal EReal.hasBot)) (forall (y : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y))\nbut is expected to have type\n  forall (x : EReal), Iff (Eq.{1} EReal x (Bot.bot.{0} EReal instERealBot)) (forall (y : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x (Real.toEReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.eq_bot_iff_forall_lt EReal.eq_bot_iff_forall_lt\u2093'. -/\ntheorem eq_bot_iff_forall_lt (x : EReal) : x = \u22a5 \u2194 \u2200 y : \u211d, x < (y : EReal) :=\n  by\n  constructor\n  \u00b7 rintro rfl\n    exact bot_lt_coe\n  \u00b7 contrapose!\n    intro h\n    exact \u27e8x.to_real, coe_to_real_le h\u27e9\n#align ereal.eq_bot_iff_forall_lt EReal.eq_bot_iff_forall_lt\n\n/-! ### ennreal coercion -/\n\n\n#print EReal.toReal_coe_ennreal /-\n@[simp]\ntheorem toReal_coe_ennreal : \u2200 {x : \u211d\u22650\u221e}, toReal (x : EReal) = ENNReal.toReal x\n  | \u22a4 => rfl\n  | some x => rfl\n#align ereal.to_real_coe_ennreal EReal.toReal_coe_ennreal\n-/\n\n/- warning: ereal.coe_ennreal_of_real -> EReal.coe_ennreal_ofReal is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (ENNReal.ofReal x)) (LinearOrder.max.{0} EReal (ConditionallyCompleteLinearOrder.toLinearOrder.{0} EReal (ConditionallyCompleteLinearOrderBot.toConditionallyCompleteLinearOrder.{0} EReal (CompleteLinearOrder.toConditionallyCompleteLinearOrderBot.{0} EReal EReal.completeLinearOrder))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))))\nbut is expected to have type\n  forall {x : Real}, Eq.{1} EReal (ENNReal.toEReal (ENNReal.ofReal x)) (Real.toEReal (Max.max.{0} Real (LinearOrderedRing.toMax.{0} Real Real.instLinearOrderedRingReal) x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_of_real EReal.coe_ennreal_ofReal\u2093'. -/\n@[simp]\ntheorem coe_ennreal_ofReal {x : \u211d} : (ENNReal.ofReal x : EReal) = max x 0 :=\n  rfl\n#align ereal.coe_ennreal_of_real EReal.coe_ennreal_ofReal\n\n/- warning: ereal.coe_nnreal_eq_coe_real -> EReal.coe_nnreal_eq_coe_real is a dubious translation:\nlean 3 declaration is\n  forall (x : NNReal), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal ENNReal (HasLiftT.mk.{1, 1} NNReal ENNReal (CoeTC\u2093.coe.{1, 1} NNReal ENNReal (coeBase.{1, 1} NNReal ENNReal ENNReal.hasCoe))) x)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal Real (HasLiftT.mk.{1, 1} NNReal Real (CoeTC\u2093.coe.{1, 1} NNReal Real (coeBase.{1, 1} NNReal Real NNReal.Real.hasCoe))) x))\nbut is expected to have type\n  forall (x : NNReal), Eq.{1} EReal (ENNReal.toEReal (ENNReal.some x)) (Real.toEReal (NNReal.toReal x))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_nnreal_eq_coe_real EReal.coe_nnreal_eq_coe_real\u2093'. -/\ntheorem coe_nnreal_eq_coe_real (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : EReal) = (x : \u211d) :=\n  rfl\n#align ereal.coe_nnreal_eq_coe_real EReal.coe_nnreal_eq_coe_real\n\n/- warning: ereal.coe_ennreal_zero -> EReal.coe_ennreal_zero is a dubious translation:\nlean 3 declaration is\n  Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (OfNat.ofNat.{0} ENNReal 0 (OfNat.mk.{0} ENNReal 0 (Zero.zero.{0} ENNReal ENNReal.hasZero)))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))\nbut is expected to have type\n  Eq.{1} EReal (ENNReal.toEReal (OfNat.ofNat.{0} ENNReal 0 (Zero.toOfNat0.{0} ENNReal instENNRealZero))) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_zero EReal.coe_ennreal_zero\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_zero : ((0 : \u211d\u22650\u221e) : EReal) = 0 :=\n  rfl\n#align ereal.coe_ennreal_zero EReal.coe_ennreal_zero\n\n/- warning: ereal.coe_ennreal_one -> EReal.coe_ennreal_one is a dubious translation:\nlean 3 declaration is\n  Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (OfNat.ofNat.{0} ENNReal 1 (OfNat.mk.{0} ENNReal 1 (One.one.{0} ENNReal (AddMonoidWithOne.toOne.{0} ENNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} ENNReal ENNReal.addCommMonoidWithOne)))))) (OfNat.ofNat.{0} EReal 1 (OfNat.mk.{0} EReal 1 (One.one.{0} EReal EReal.hasOne)))\nbut is expected to have type\n  Eq.{1} EReal (ENNReal.toEReal (OfNat.ofNat.{0} ENNReal 1 (One.toOfNat1.{0} ENNReal (CanonicallyOrderedCommSemiring.toOne.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)))) (OfNat.ofNat.{0} EReal 1 (One.toOfNat1.{0} EReal instERealOne))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_one EReal.coe_ennreal_one\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_one : ((1 : \u211d\u22650\u221e) : EReal) = 1 :=\n  rfl\n#align ereal.coe_ennreal_one EReal.coe_ennreal_one\n\n/- warning: ereal.coe_ennreal_top -> EReal.coe_ennreal_top is a dubious translation:\nlean 3 declaration is\n  Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (Top.top.{0} ENNReal (CompleteLattice.toHasTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder)))) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  Eq.{1} EReal (ENNReal.toEReal (Top.top.{0} ENNReal (CompleteLattice.toTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal)))) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_top EReal.coe_ennreal_top\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_top : ((\u22a4 : \u211d\u22650\u221e) : EReal) = \u22a4 :=\n  rfl\n#align ereal.coe_ennreal_top EReal.coe_ennreal_top\n\n/- warning: ereal.coe_ennreal_eq_top_iff -> EReal.coe_ennreal_eq_top_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal}, Iff (Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) (Top.top.{0} EReal EReal.hasTop)) (Eq.{1} ENNReal x (Top.top.{0} ENNReal (CompleteLattice.toHasTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))\nbut is expected to have type\n  forall {x : ENNReal}, Iff (Eq.{1} EReal (ENNReal.toEReal x) (Top.top.{0} EReal EReal.instTopEReal)) (Eq.{1} ENNReal x (Top.top.{0} ENNReal (CompleteLattice.toTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal))))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_eq_top_iff EReal.coe_ennreal_eq_top_iff\u2093'. -/\n@[simp]\ntheorem coe_ennreal_eq_top_iff : \u2200 {x : \u211d\u22650\u221e}, (x : EReal) = \u22a4 \u2194 x = \u22a4\n  | \u22a4 => by simp\n  | some x => by\n    simp only [ENNReal.coe_ne_top, iff_false_iff, ENNReal.some_eq_coe]\n    decide\n#align ereal.coe_ennreal_eq_top_iff EReal.coe_ennreal_eq_top_iff\n\n#print EReal.coe_nnreal_ne_top /-\ntheorem coe_nnreal_ne_top (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : EReal) \u2260 \u22a4 := by decide\n#align ereal.coe_nnreal_ne_top EReal.coe_nnreal_ne_top\n-/\n\n/- warning: ereal.coe_nnreal_lt_top -> EReal.coe_nnreal_lt_top is a dubious translation:\nlean 3 declaration is\n  forall (x : NNReal), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal ENNReal (HasLiftT.mk.{1, 1} NNReal ENNReal (CoeTC\u2093.coe.{1, 1} NNReal ENNReal (coeBase.{1, 1} NNReal ENNReal ENNReal.hasCoe))) x)) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  forall (x : NNReal), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (ENNReal.toEReal (ENNReal.some x)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_nnreal_lt_top EReal.coe_nnreal_lt_top\u2093'. -/\n@[simp]\ntheorem coe_nnreal_lt_top (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : EReal) < \u22a4 := by decide\n#align ereal.coe_nnreal_lt_top EReal.coe_nnreal_lt_top\n\n/- warning: ereal.coe_ennreal_strict_mono -> EReal.coe_ennreal_strictMono is a dubious translation:\nlean 3 declaration is\n  StrictMono.{0, 0} ENNReal EReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))))\nbut is expected to have type\n  StrictMono.{0, 0} ENNReal EReal (PartialOrder.toPreorder.{0} ENNReal (OrderedSemiring.toPartialOrder.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)))) (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) ENNReal.toEReal\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_strict_mono EReal.coe_ennreal_strictMono\u2093'. -/\ntheorem coe_ennreal_strictMono : StrictMono (coe : \u211d\u22650\u221e \u2192 EReal)\n  | \u22a4, \u22a4 => by simp\n  | some x, \u22a4 => by simp\n  | \u22a4, some y => by simp\n  | some x, some y => by simp [coe_nnreal_eq_coe_real]\n#align ereal.coe_ennreal_strict_mono EReal.coe_ennreal_strictMono\n\n#print EReal.coe_ennreal_injective /-\ntheorem coe_ennreal_injective : Injective (coe : \u211d\u22650\u221e \u2192 EReal) :=\n  coe_ennreal_strictMono.Injective\n#align ereal.coe_ennreal_injective EReal.coe_ennreal_injective\n-/\n\n/- warning: ereal.coe_ennreal_le_coe_ennreal_iff -> EReal.coe_ennreal_le_coe_ennreal_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal} {y : ENNReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) y)) (LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) x y)\nbut is expected to have type\n  forall {x : ENNReal} {y : ENNReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (ENNReal.toEReal x) (ENNReal.toEReal y)) (LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (OrderedSemiring.toPartialOrder.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))) x y)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_le_coe_ennreal_iff EReal.coe_ennreal_le_coe_ennreal_iff\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_le_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) \u2264 (y : EReal) \u2194 x \u2264 y :=\n  coe_ennreal_strictMono.le_iff_le\n#align ereal.coe_ennreal_le_coe_ennreal_iff EReal.coe_ennreal_le_coe_ennreal_iff\n\n/- warning: ereal.coe_ennreal_lt_coe_ennreal_iff -> EReal.coe_ennreal_lt_coe_ennreal_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal} {y : ENNReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) y)) (LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) x y)\nbut is expected to have type\n  forall {x : ENNReal} {y : ENNReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (ENNReal.toEReal x) (ENNReal.toEReal y)) (LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (OrderedSemiring.toPartialOrder.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))) x y)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_lt_coe_ennreal_iff EReal.coe_ennreal_lt_coe_ennreal_iff\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_lt_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) < (y : EReal) \u2194 x < y :=\n  coe_ennreal_strictMono.lt_iff_lt\n#align ereal.coe_ennreal_lt_coe_ennreal_iff EReal.coe_ennreal_lt_coe_ennreal_iff\n\n#print EReal.coe_ennreal_eq_coe_ennreal_iff /-\n@[simp, norm_cast]\ntheorem coe_ennreal_eq_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) = (y : EReal) \u2194 x = y :=\n  coe_ennreal_injective.eq_iff\n#align ereal.coe_ennreal_eq_coe_ennreal_iff EReal.coe_ennreal_eq_coe_ennreal_iff\n-/\n\n#print EReal.coe_ennreal_ne_coe_ennreal_iff /-\ntheorem coe_ennreal_ne_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : EReal) \u2260 (y : EReal) \u2194 x \u2260 y :=\n  coe_ennreal_injective.ne_iff\n#align ereal.coe_ennreal_ne_coe_ennreal_iff EReal.coe_ennreal_ne_coe_ennreal_iff\n-/\n\n/- warning: ereal.coe_ennreal_eq_zero -> EReal.coe_ennreal_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal}, Iff (Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (Eq.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 0 (OfNat.mk.{0} ENNReal 0 (Zero.zero.{0} ENNReal ENNReal.hasZero))))\nbut is expected to have type\n  forall {x : ENNReal}, Iff (Eq.{1} EReal (ENNReal.toEReal x) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (Eq.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 0 (Zero.toOfNat0.{0} ENNReal instENNRealZero)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_eq_zero EReal.coe_ennreal_eq_zero\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_eq_zero {x : \u211d\u22650\u221e} : (x : EReal) = 0 \u2194 x = 0 := by\n  rw [\u2190 coe_ennreal_eq_coe_ennreal_iff, coe_ennreal_zero]\n#align ereal.coe_ennreal_eq_zero EReal.coe_ennreal_eq_zero\n\n/- warning: ereal.coe_ennreal_eq_one -> EReal.coe_ennreal_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal}, Iff (Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) (OfNat.ofNat.{0} EReal 1 (OfNat.mk.{0} EReal 1 (One.one.{0} EReal EReal.hasOne)))) (Eq.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 1 (OfNat.mk.{0} ENNReal 1 (One.one.{0} ENNReal (AddMonoidWithOne.toOne.{0} ENNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} ENNReal ENNReal.addCommMonoidWithOne))))))\nbut is expected to have type\n  forall {x : ENNReal}, Iff (Eq.{1} EReal (ENNReal.toEReal x) (OfNat.ofNat.{0} EReal 1 (One.toOfNat1.{0} EReal instERealOne))) (Eq.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 1 (One.toOfNat1.{0} ENNReal (CanonicallyOrderedCommSemiring.toOne.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_eq_one EReal.coe_ennreal_eq_one\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_eq_one {x : \u211d\u22650\u221e} : (x : EReal) = 1 \u2194 x = 1 := by\n  rw [\u2190 coe_ennreal_eq_coe_ennreal_iff, coe_ennreal_one]\n#align ereal.coe_ennreal_eq_one EReal.coe_ennreal_eq_one\n\n/- warning: ereal.coe_ennreal_ne_zero -> EReal.coe_ennreal_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal}, Iff (Ne.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (Ne.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 0 (OfNat.mk.{0} ENNReal 0 (Zero.zero.{0} ENNReal ENNReal.hasZero))))\nbut is expected to have type\n  forall {x : ENNReal}, Iff (Ne.{1} EReal (ENNReal.toEReal x) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (Ne.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 0 (Zero.toOfNat0.{0} ENNReal instENNRealZero)))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_ne_zero EReal.coe_ennreal_ne_zero\u2093'. -/\n@[norm_cast]\ntheorem coe_ennreal_ne_zero {x : \u211d\u22650\u221e} : (x : EReal) \u2260 0 \u2194 x \u2260 0 :=\n  coe_ennreal_eq_zero.Not\n#align ereal.coe_ennreal_ne_zero EReal.coe_ennreal_ne_zero\n\n/- warning: ereal.coe_ennreal_ne_one -> EReal.coe_ennreal_ne_one is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal}, Iff (Ne.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) (OfNat.ofNat.{0} EReal 1 (OfNat.mk.{0} EReal 1 (One.one.{0} EReal EReal.hasOne)))) (Ne.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 1 (OfNat.mk.{0} ENNReal 1 (One.one.{0} ENNReal (AddMonoidWithOne.toOne.{0} ENNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} ENNReal ENNReal.addCommMonoidWithOne))))))\nbut is expected to have type\n  forall {x : ENNReal}, Iff (Ne.{1} EReal (ENNReal.toEReal x) (OfNat.ofNat.{0} EReal 1 (One.toOfNat1.{0} EReal instERealOne))) (Ne.{1} ENNReal x (OfNat.ofNat.{0} ENNReal 1 (One.toOfNat1.{0} ENNReal (CanonicallyOrderedCommSemiring.toOne.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_ne_one EReal.coe_ennreal_ne_one\u2093'. -/\n@[norm_cast]\ntheorem coe_ennreal_ne_one {x : \u211d\u22650\u221e} : (x : EReal) \u2260 1 \u2194 x \u2260 1 :=\n  coe_ennreal_eq_one.Not\n#align ereal.coe_ennreal_ne_one EReal.coe_ennreal_ne_one\n\n/- warning: ereal.coe_ennreal_nonneg -> EReal.coe_ennreal_nonneg is a dubious translation:\nlean 3 declaration is\n  forall (x : ENNReal), LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x)\nbut is expected to have type\n  forall (x : ENNReal), LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (ENNReal.toEReal x)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_nonneg EReal.coe_ennreal_nonneg\u2093'. -/\ntheorem coe_ennreal_nonneg (x : \u211d\u22650\u221e) : (0 : EReal) \u2264 x :=\n  coe_ennreal_le_coe_ennreal_iff.2 (zero_le x)\n#align ereal.coe_ennreal_nonneg EReal.coe_ennreal_nonneg\n\n/- warning: ereal.coe_ennreal_pos -> EReal.coe_ennreal_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : ENNReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x)) (LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (OfNat.ofNat.{0} ENNReal 0 (OfNat.mk.{0} ENNReal 0 (Zero.zero.{0} ENNReal ENNReal.hasZero))) x)\nbut is expected to have type\n  forall {x : ENNReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) (ENNReal.toEReal x)) (LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (OrderedSemiring.toPartialOrder.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))) (OfNat.ofNat.{0} ENNReal 0 (Zero.toOfNat0.{0} ENNReal instENNRealZero)) x)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_pos EReal.coe_ennreal_pos\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_pos {x : \u211d\u22650\u221e} : (0 : EReal) < x \u2194 0 < x := by\n  rw [\u2190 coe_ennreal_zero, coe_ennreal_lt_coe_ennreal_iff]\n#align ereal.coe_ennreal_pos EReal.coe_ennreal_pos\n\n/- warning: ereal.bot_lt_coe_ennreal -> EReal.bot_lt_coe_ennreal is a dubious translation:\nlean 3 declaration is\n  forall (x : ENNReal), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Bot.bot.{0} EReal EReal.hasBot) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x)\nbut is expected to have type\n  forall (x : ENNReal), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Bot.bot.{0} EReal instERealBot) (ENNReal.toEReal x)\nCase conversion may be inaccurate. Consider using '#align ereal.bot_lt_coe_ennreal EReal.bot_lt_coe_ennreal\u2093'. -/\n@[simp]\ntheorem bot_lt_coe_ennreal (x : \u211d\u22650\u221e) : (\u22a5 : EReal) < x :=\n  (bot_lt_coe 0).trans_le (coe_ennreal_nonneg _)\n#align ereal.bot_lt_coe_ennreal EReal.bot_lt_coe_ennreal\n\n#print EReal.coe_ennreal_ne_bot /-\n@[simp]\ntheorem coe_ennreal_ne_bot (x : \u211d\u22650\u221e) : (x : EReal) \u2260 \u22a5 :=\n  (bot_lt_coe_ennreal x).ne'\n#align ereal.coe_ennreal_ne_bot EReal.coe_ennreal_ne_bot\n-/\n\n/- warning: ereal.coe_ennreal_add -> EReal.coe_ennreal_add is a dubious translation:\nlean 3 declaration is\n  forall (x : ENNReal) (y : ENNReal), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (HAdd.hAdd.{0, 0, 0} ENNReal ENNReal ENNReal (instHAdd.{0} ENNReal (Distrib.toHasAdd.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring)))))))) x y)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) y))\nbut is expected to have type\n  forall (x : ENNReal) (y : ENNReal), Eq.{1} EReal (ENNReal.toEReal (HAdd.hAdd.{0, 0, 0} ENNReal ENNReal ENNReal (instHAdd.{0} ENNReal (Distrib.toAdd.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)))))))) x y)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (ENNReal.toEReal x) (ENNReal.toEReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_add EReal.coe_ennreal_add\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_add (x y : ENNReal) : ((x + y : \u211d\u22650\u221e) : EReal) = x + y := by\n  cases x <;> cases y <;> rfl\n#align ereal.coe_ennreal_add EReal.coe_ennreal_add\n\n/- warning: ereal.coe_ennreal_mul -> EReal.coe_ennreal_mul is a dubious translation:\nlean 3 declaration is\n  forall (x : ENNReal) (y : ENNReal), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (Distrib.toHasMul.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring)))))))) x y)) (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) y))\nbut is expected to have type\n  forall (x : ENNReal) (y : ENNReal), Eq.{1} EReal (ENNReal.toEReal (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (CanonicallyOrderedCommSemiring.toMul.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)) x y)) (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (ENNReal.toEReal x) (ENNReal.toEReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_mul EReal.coe_ennreal_mul\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_mul : \u2200 x y : \u211d\u22650\u221e, ((x * y : \u211d\u22650\u221e) : EReal) = x * y\n  | \u22a4, \u22a4 => rfl\n  | \u22a4, (y : \u211d\u22650) => by\n    rw [ENNReal.top_mul']; split_ifs\n    \u00b7 simp only [h, coe_ennreal_zero, MulZeroClass.mul_zero]\n    \u00b7 have A : (0 : \u211d) < y := by\n        simp only [ENNReal.coe_eq_zero] at h\n        exact NNReal.coe_pos.2 (bot_lt_iff_ne_bot.2 h)\n      simp only [coe_nnreal_eq_coe_real, coe_ennreal_top, (\u00b7 * \u00b7), EReal.mul, A, if_true]\n  | (x : \u211d\u22650), \u22a4 => by\n    rw [ENNReal.mul_top']; split_ifs\n    \u00b7 simp only [h, coe_ennreal_zero, MulZeroClass.zero_mul]\n    \u00b7 have A : (0 : \u211d) < x := by\n        simp only [ENNReal.coe_eq_zero] at h\n        exact NNReal.coe_pos.2 (bot_lt_iff_ne_bot.2 h)\n      simp only [coe_nnreal_eq_coe_real, coe_ennreal_top, (\u00b7 * \u00b7), EReal.mul, A, if_true]\n  | (x : \u211d\u22650), (y : \u211d\u22650) => by\n    simp only [\u2190 ENNReal.coe_mul, coe_nnreal_eq_coe_real, NNReal.coe_mul, EReal.coe_mul]\n#align ereal.coe_ennreal_mul EReal.coe_ennreal_mul\n\n/- warning: ereal.coe_ennreal_nsmul -> EReal.coe_ennreal_nsmul is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (x : ENNReal), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (SMul.smul.{0, 0} Nat ENNReal (AddMonoid.SMul.{0} ENNReal (AddMonoidWithOne.toAddMonoid.{0} ENNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} ENNReal ENNReal.addCommMonoidWithOne))) n x)) (SMul.smul.{0, 0} Nat EReal (AddMonoid.SMul.{0} EReal EReal.addMonoid) n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x))\nbut is expected to have type\n  forall (n : Nat) (x : ENNReal), Eq.{1} EReal (ENNReal.toEReal (HSMul.hSMul.{0, 0, 0} Nat ENNReal ENNReal (instHSMul.{0, 0} Nat ENNReal (AddMonoid.SMul.{0} ENNReal (AddMonoidWithOne.toAddMonoid.{0} ENNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} ENNReal instENNRealAddCommMonoidWithOne)))) n x)) (HSMul.hSMul.{0, 0, 0} Nat EReal EReal (instHSMul.{0, 0} Nat EReal (AddMonoid.SMul.{0} EReal instERealAddMonoid)) n (ENNReal.toEReal x))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_nsmul EReal.coe_ennreal_nsmul\u2093'. -/\n@[norm_cast]\ntheorem coe_ennreal_nsmul (n : \u2115) (x : \u211d\u22650\u221e) : (\u2191(n \u2022 x) : EReal) = n \u2022 x :=\n  map_nsmul (\u27e8coe, coe_ennreal_zero, coe_ennreal_add\u27e9 : \u211d\u22650\u221e \u2192+ EReal) _ _\n#align ereal.coe_ennreal_nsmul EReal.coe_ennreal_nsmul\n\n/- warning: ereal.coe_ennreal_bit0 clashes with [anonymous] -> [anonymous]\nwarning: ereal.coe_ennreal_bit0 -> [anonymous] is a dubious translation:\nlean 3 declaration is\n  forall (x : ENNReal), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (bit0.{0} ENNReal (Distrib.toHasAdd.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring))))))) x)) (bit0.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x))\nbut is expected to have type\n  forall {x : Type.{u}} {\u03b2 : Type.{v}}, (Nat -> x -> \u03b2) -> Nat -> (List.{u} x) -> (List.{v} \u03b2)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_bit0 [anonymous]\u2093'. -/\n@[simp, norm_cast]\ntheorem [anonymous] (x : \u211d\u22650\u221e) : (\u2191(bit0 x) : EReal) = bit0 x :=\n  coe_ennreal_add _ _\n#align ereal.coe_ennreal_bit0 [anonymous]\n\n/- warning: ereal.coe_ennreal_bit1 clashes with [anonymous] -> [anonymous]\nwarning: ereal.coe_ennreal_bit1 -> [anonymous] is a dubious translation:\nlean 3 declaration is\n  forall (x : ENNReal), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (bit1.{0} ENNReal (AddMonoidWithOne.toOne.{0} ENNReal (AddCommMonoidWithOne.toAddMonoidWithOne.{0} ENNReal ENNReal.addCommMonoidWithOne)) (Distrib.toHasAdd.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring))))))) x)) (bit1.{0} EReal EReal.hasOne (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x))\nbut is expected to have type\n  forall {x : Type.{u}} {\u03b2 : Type.{v}}, (Nat -> x -> \u03b2) -> Nat -> (List.{u} x) -> (List.{v} \u03b2)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_bit1 [anonymous]\u2093'. -/\n@[simp, norm_cast]\ntheorem [anonymous] (x : \u211d\u22650\u221e) : (\u2191(bit1 x) : EReal) = bit1 x := by\n  simp_rw [bit1, coe_ennreal_add, coe_ennreal_bit0, coe_ennreal_one]\n#align ereal.coe_ennreal_bit1 [anonymous]\n\n/-! ### Order -/\n\n\n/- warning: ereal.exists_rat_btwn_of_lt -> EReal.exists_rat_btwn_of_lt is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) a b) -> (Exists.{1} Rat (fun (x : Rat) => And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) a ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Rat Real (HasLiftT.mk.{1, 1} Rat Real (CoeTC\u2093.coe.{1, 1} Rat Real (Rat.castCoe.{0} Real Real.hasRatCast))) x))) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Rat Real (HasLiftT.mk.{1, 1} Rat Real (CoeTC\u2093.coe.{1, 1} Rat Real (Rat.castCoe.{0} Real Real.hasRatCast))) x)) b)))\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) a b) -> (Exists.{1} Rat (fun (x : Rat) => And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) a (Real.toEReal (Rat.cast.{0} Real Real.ratCast x))) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal (Rat.cast.{0} Real Real.ratCast x)) b)))\nCase conversion may be inaccurate. Consider using '#align ereal.exists_rat_btwn_of_lt EReal.exists_rat_btwn_of_lt\u2093'. -/\ntheorem exists_rat_btwn_of_lt :\n    \u2200 {a b : EReal} (hab : a < b), \u2203 x : \u211a, a < (x : \u211d) \u2227 ((x : \u211d) : EReal) < b\n  | \u22a4, b, h => (not_top_lt h).elim\n  | (a : \u211d), \u22a5, h => (lt_irrefl _ ((bot_lt_coe a).trans h)).elim\n  | (a : \u211d), (b : \u211d), h => by simp [exists_rat_btwn (EReal.coe_lt_coe_iff.1 h)]\n  | (a : \u211d), \u22a4, h =>\n    let \u27e8b, hab\u27e9 := exists_rat_gt a\n    \u27e8b, by simpa using hab, coe_lt_top _\u27e9\n  | \u22a5, \u22a5, h => (lt_irrefl _ h).elim\n  | \u22a5, (a : \u211d), h =>\n    let \u27e8b, hab\u27e9 := exists_rat_lt a\n    \u27e8b, bot_lt_coe _, by simpa using hab\u27e9\n  | \u22a5, \u22a4, h => \u27e80, bot_lt_coe _, coe_lt_top _\u27e9\n#align ereal.exists_rat_btwn_of_lt EReal.exists_rat_btwn_of_lt\n\n/- warning: ereal.lt_iff_exists_rat_btwn -> EReal.lt_iff_exists_rat_btwn is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) a b) (Exists.{1} Rat (fun (x : Rat) => And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) a ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Rat Real (HasLiftT.mk.{1, 1} Rat Real (CoeTC\u2093.coe.{1, 1} Rat Real (Rat.castCoe.{0} Real Real.hasRatCast))) x))) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Rat Real (HasLiftT.mk.{1, 1} Rat Real (CoeTC\u2093.coe.{1, 1} Rat Real (Rat.castCoe.{0} Real Real.hasRatCast))) x)) b)))\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) a b) (Exists.{1} Rat (fun (x : Rat) => And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) a (Real.toEReal (Rat.cast.{0} Real Real.ratCast x))) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal (Rat.cast.{0} Real Real.ratCast x)) b)))\nCase conversion may be inaccurate. Consider using '#align ereal.lt_iff_exists_rat_btwn EReal.lt_iff_exists_rat_btwn\u2093'. -/\ntheorem lt_iff_exists_rat_btwn {a b : EReal} :\n    a < b \u2194 \u2203 x : \u211a, a < (x : \u211d) \u2227 ((x : \u211d) : EReal) < b :=\n  \u27e8fun hab => exists_rat_btwn_of_lt hab, fun \u27e8x, ax, xb\u27e9 => ax.trans xb\u27e9\n#align ereal.lt_iff_exists_rat_btwn EReal.lt_iff_exists_rat_btwn\n\n/- warning: ereal.lt_iff_exists_real_btwn -> EReal.lt_iff_exists_real_btwn is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) a b) (Exists.{1} Real (fun (x : Real) => And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) a ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) b)))\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) a b) (Exists.{1} Real (fun (x : Real) => And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) a (Real.toEReal x)) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Real.toEReal x) b)))\nCase conversion may be inaccurate. Consider using '#align ereal.lt_iff_exists_real_btwn EReal.lt_iff_exists_real_btwn\u2093'. -/\ntheorem lt_iff_exists_real_btwn {a b : EReal} : a < b \u2194 \u2203 x : \u211d, a < x \u2227 (x : EReal) < b :=\n  \u27e8fun hab =>\n    let \u27e8x, ax, xb\u27e9 := exists_rat_btwn_of_lt hab\n    \u27e8(x : \u211d), ax, xb\u27e9,\n    fun \u27e8x, ax, xb\u27e9 => ax.trans xb\u27e9\n#align ereal.lt_iff_exists_real_btwn EReal.lt_iff_exists_real_btwn\n\n/- warning: ereal.ne_top_bot_equiv_real -> EReal.neTopBotEquivReal is a dubious translation:\nlean 3 declaration is\n  Equiv.{1, 1} (coeSort.{1, 2} (Set.{0} EReal) Type (Set.hasCoeToSort.{0} EReal) (HasCompl.compl.{0} (Set.{0} EReal) (BooleanAlgebra.toHasCompl.{0} (Set.{0} EReal) (Set.booleanAlgebra.{0} EReal)) (Insert.insert.{0, 0} EReal (Set.{0} EReal) (Set.hasInsert.{0} EReal) (Bot.bot.{0} EReal EReal.hasBot) (Singleton.singleton.{0, 0} EReal (Set.{0} EReal) (Set.hasSingleton.{0} EReal) (Top.top.{0} EReal EReal.hasTop))))) Real\nbut is expected to have type\n  Equiv.{1, 1} (Set.Elem.{0} EReal (HasCompl.compl.{0} (Set.{0} EReal) (BooleanAlgebra.toHasCompl.{0} (Set.{0} EReal) (Set.instBooleanAlgebraSet.{0} EReal)) (Insert.insert.{0, 0} EReal (Set.{0} EReal) (Set.instInsertSet.{0} EReal) (Bot.bot.{0} EReal instERealBot) (Singleton.singleton.{0, 0} EReal (Set.{0} EReal) (Set.instSingletonSet.{0} EReal) (Top.top.{0} EReal EReal.instTopEReal))))) Real\nCase conversion may be inaccurate. Consider using '#align ereal.ne_top_bot_equiv_real EReal.neTopBotEquivReal\u2093'. -/\n/-- The set of numbers in `ereal` that are not equal to `\u00b1\u221e` is equivalent to `\u211d`. -/\ndef neTopBotEquivReal : ({\u22a5, \u22a4}\u1d9c : Set EReal) \u2243 \u211d\n    where\n  toFun x := EReal.toReal x\n  invFun x := \u27e8x, by simp\u27e9\n  left_inv := fun \u27e8x, hx\u27e9 =>\n    Subtype.eq <| by\n      lift x to \u211d\n      \u00b7 simpa [not_or, and_comm'] using hx\n      \u00b7 simp\n  right_inv x := by simp\n#align ereal.ne_top_bot_equiv_real EReal.neTopBotEquivReal\n\n/-! ### Addition -/\n\n\n/- warning: ereal.add_bot -> EReal.add_bot is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x (Bot.bot.{0} EReal EReal.hasBot)) (Bot.bot.{0} EReal EReal.hasBot)\nbut is expected to have type\n  forall (x : EReal), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x (Bot.bot.{0} EReal instERealBot)) (Bot.bot.{0} EReal instERealBot)\nCase conversion may be inaccurate. Consider using '#align ereal.add_bot EReal.add_bot\u2093'. -/\n@[simp]\ntheorem add_bot (x : EReal) : x + \u22a5 = \u22a5 :=\n  WithBot.add_bot _\n#align ereal.add_bot EReal.add_bot\n\n/- warning: ereal.bot_add -> EReal.bot_add is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) (Bot.bot.{0} EReal EReal.hasBot) x) (Bot.bot.{0} EReal EReal.hasBot)\nbut is expected to have type\n  forall (x : EReal), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (Bot.bot.{0} EReal instERealBot) x) (Bot.bot.{0} EReal instERealBot)\nCase conversion may be inaccurate. Consider using '#align ereal.bot_add EReal.bot_add\u2093'. -/\n@[simp]\ntheorem bot_add (x : EReal) : \u22a5 + x = \u22a5 :=\n  WithBot.bot_add _\n#align ereal.bot_add EReal.bot_add\n\n/- warning: ereal.top_add_top -> EReal.top_add_top is a dubious translation:\nlean 3 declaration is\n  Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) (Top.top.{0} EReal EReal.hasTop) (Top.top.{0} EReal EReal.hasTop)) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (Top.top.{0} EReal EReal.instTopEReal) (Top.top.{0} EReal EReal.instTopEReal)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.top_add_top EReal.top_add_top\u2093'. -/\n@[simp]\ntheorem top_add_top : (\u22a4 : EReal) + \u22a4 = \u22a4 :=\n  rfl\n#align ereal.top_add_top EReal.top_add_top\n\n/- warning: ereal.top_add_coe -> EReal.top_add_coe is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) (Top.top.{0} EReal EReal.hasTop) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (Top.top.{0} EReal EReal.instTopEReal) (Real.toEReal x)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.top_add_coe EReal.top_add_coe\u2093'. -/\n@[simp]\ntheorem top_add_coe (x : \u211d) : (\u22a4 : EReal) + x = \u22a4 :=\n  rfl\n#align ereal.top_add_coe EReal.top_add_coe\n\n/- warning: ereal.coe_add_top -> EReal.coe_add_top is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Top.top.{0} EReal EReal.hasTop)) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (Real.toEReal x) (Top.top.{0} EReal EReal.instTopEReal)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_add_top EReal.coe_add_top\u2093'. -/\n@[simp]\ntheorem coe_add_top (x : \u211d) : (x : EReal) + \u22a4 = \u22a4 :=\n  rfl\n#align ereal.coe_add_top EReal.coe_add_top\n\n/- warning: ereal.to_real_add -> EReal.toReal_add is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.hasTop)) -> (Ne.{1} EReal x (Bot.bot.{0} EReal EReal.hasBot)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.hasTop)) -> (Ne.{1} EReal y (Bot.bot.{0} EReal EReal.hasBot)) -> (Eq.{1} Real (EReal.toReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x y)) (HAdd.hAdd.{0, 0, 0} Real Real Real (instHAdd.{0} Real Real.hasAdd) (EReal.toReal x) (EReal.toReal y)))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.instTopEReal)) -> (Ne.{1} EReal x (Bot.bot.{0} EReal instERealBot)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.instTopEReal)) -> (Ne.{1} EReal y (Bot.bot.{0} EReal instERealBot)) -> (Eq.{1} Real (EReal.toReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x y)) (HAdd.hAdd.{0, 0, 0} Real Real Real (instHAdd.{0} Real Real.instAddReal) (EReal.toReal x) (EReal.toReal y)))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_add EReal.toReal_add\u2093'. -/\ntheorem toReal_add :\n    \u2200 {x y : EReal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) (hy : y \u2260 \u22a4) (h'y : y \u2260 \u22a5),\n      toReal (x + y) = toReal x + toReal y\n  | \u22a5, y, hx, h'x, hy, h'y => (h'x rfl).elim\n  | \u22a4, y, hx, h'x, hy, h'y => (hx rfl).elim\n  | x, \u22a4, hx, h'x, hy, h'y => (hy rfl).elim\n  | x, \u22a5, hx, h'x, hy, h'y => (h'y rfl).elim\n  | (x : \u211d), (y : \u211d), hx, h'x, hy, h'y => by simp [\u2190 EReal.coe_add]\n#align ereal.to_real_add EReal.toReal_add\n\n/- warning: ereal.add_lt_add_right_coe -> EReal.add_lt_add_right_coe is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) -> (forall (z : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) z)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) y ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) z)))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) -> (forall (z : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x (Real.toEReal z)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) y (Real.toEReal z)))\nCase conversion may be inaccurate. Consider using '#align ereal.add_lt_add_right_coe EReal.add_lt_add_right_coe\u2093'. -/\ntheorem add_lt_add_right_coe {x y : EReal} (h : x < y) (z : \u211d) : x + z < y + z :=\n  by\n  induction x using EReal.rec <;> induction y using EReal.rec\n  \u00b7 exact (lt_irrefl _ h).elim\n  \u00b7 simp only [\u2190 coe_add, bot_add, bot_lt_coe]\n  \u00b7 simp\n  \u00b7 exact (lt_irrefl _ (h.trans (bot_lt_coe x))).elim\n  \u00b7 norm_cast  at h\u22a2\n    exact add_lt_add_right h _\n  \u00b7 simp only [\u2190 coe_add, top_add_coe, coe_lt_top]\n  \u00b7 exact (lt_irrefl _ (h.trans_le le_top)).elim\n  \u00b7 exact (lt_irrefl _ (h.trans_le le_top)).elim\n  \u00b7 exact (lt_irrefl _ (h.trans_le le_top)).elim\n#align ereal.add_lt_add_right_coe EReal.add_lt_add_right_coe\n\n/- warning: ereal.add_lt_add_of_lt_of_le -> EReal.add_lt_add_of_lt_of_le is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) z t) -> (Ne.{1} EReal z (Bot.bot.{0} EReal EReal.hasBot)) -> (Ne.{1} EReal t (Top.top.{0} EReal EReal.hasTop)) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x z) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) y t))\nbut is expected to have type\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) z t) -> (Ne.{1} EReal z (Bot.bot.{0} EReal instERealBot)) -> (Ne.{1} EReal t (Top.top.{0} EReal EReal.instTopEReal)) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x z) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) y t))\nCase conversion may be inaccurate. Consider using '#align ereal.add_lt_add_of_lt_of_le EReal.add_lt_add_of_lt_of_le\u2093'. -/\ntheorem add_lt_add_of_lt_of_le {x y z t : EReal} (h : x < y) (h' : z \u2264 t) (hz : z \u2260 \u22a5)\n    (ht : t \u2260 \u22a4) : x + z < y + t := by\n  induction z using EReal.rec\n  \u00b7 simpa only using hz\n  \u00b7\n    calc\n      x + z < y + z := add_lt_add_right_coe h _\n      _ \u2264 y + t := add_le_add le_rfl h'\n      \n  \u00b7 exact (ht (top_le_iff.1 h')).elim\n#align ereal.add_lt_add_of_lt_of_le EReal.add_lt_add_of_lt_of_le\n\n/- warning: ereal.add_lt_add_left_coe -> EReal.add_lt_add_left_coe is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) -> (forall (z : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) z) x) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) z) y))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) -> (forall (z : Real), LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (Real.toEReal z) x) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) (Real.toEReal z) y))\nCase conversion may be inaccurate. Consider using '#align ereal.add_lt_add_left_coe EReal.add_lt_add_left_coe\u2093'. -/\ntheorem add_lt_add_left_coe {x y : EReal} (h : x < y) (z : \u211d) : (z : EReal) + x < z + y := by\n  simpa [add_comm] using add_lt_add_right_coe h z\n#align ereal.add_lt_add_left_coe EReal.add_lt_add_left_coe\n\n/- warning: ereal.add_lt_add -> EReal.add_lt_add is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) z t) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x z) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) y t))\nbut is expected to have type\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) z t) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x z) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) y t))\nCase conversion may be inaccurate. Consider using '#align ereal.add_lt_add EReal.add_lt_add\u2093'. -/\ntheorem add_lt_add {x y z t : EReal} (h1 : x < y) (h2 : z < t) : x + z < y + t :=\n  by\n  induction x using EReal.rec\n  \u00b7 simp [bot_lt_iff_ne_bot, h1.ne', (bot_le.trans_lt h2).ne']\n  \u00b7\n    calc\n      (x : EReal) + z < x + t := add_lt_add_left_coe h2 _\n      _ \u2264 y + t := add_le_add h1.le le_rfl\n      \n  \u00b7 exact (lt_irrefl _ (h1.trans_le le_top)).elim\n#align ereal.add_lt_add EReal.add_lt_add\n\n/- warning: ereal.add_eq_bot_iff -> EReal.add_eq_bot_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, Iff (Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x y) (Bot.bot.{0} EReal EReal.hasBot)) (Or (Eq.{1} EReal x (Bot.bot.{0} EReal EReal.hasBot)) (Eq.{1} EReal y (Bot.bot.{0} EReal EReal.hasBot)))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, Iff (Eq.{1} EReal (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x y) (Bot.bot.{0} EReal instERealBot)) (Or (Eq.{1} EReal x (Bot.bot.{0} EReal instERealBot)) (Eq.{1} EReal y (Bot.bot.{0} EReal instERealBot)))\nCase conversion may be inaccurate. Consider using '#align ereal.add_eq_bot_iff EReal.add_eq_bot_iff\u2093'. -/\n@[simp]\ntheorem add_eq_bot_iff {x y : EReal} : x + y = \u22a5 \u2194 x = \u22a5 \u2228 y = \u22a5 := by\n  induction x using EReal.rec <;> induction y using EReal.rec <;> simp [\u2190 EReal.coe_add]\n#align ereal.add_eq_bot_iff EReal.add_eq_bot_iff\n\n/- warning: ereal.bot_lt_add_iff -> EReal.bot_lt_add_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Bot.bot.{0} EReal EReal.hasBot) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x y)) (And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Bot.bot.{0} EReal EReal.hasBot) x) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Bot.bot.{0} EReal EReal.hasBot) y))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Bot.bot.{0} EReal instERealBot) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x y)) (And (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Bot.bot.{0} EReal instERealBot) x) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Bot.bot.{0} EReal instERealBot) y))\nCase conversion may be inaccurate. Consider using '#align ereal.bot_lt_add_iff EReal.bot_lt_add_iff\u2093'. -/\n@[simp]\ntheorem bot_lt_add_iff {x y : EReal} : \u22a5 < x + y \u2194 \u22a5 < x \u2227 \u22a5 < y := by\n  simp [bot_lt_iff_ne_bot, not_or]\n#align ereal.bot_lt_add_iff EReal.bot_lt_add_iff\n\n/- warning: ereal.add_lt_top -> EReal.add_lt_top is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.hasTop)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.hasTop)) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toHasAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal EReal.addMonoid))) x y) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.instTopEReal)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.instTopEReal)) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (HAdd.hAdd.{0, 0, 0} EReal EReal EReal (instHAdd.{0} EReal (AddZeroClass.toAdd.{0} EReal (AddMonoid.toAddZeroClass.{0} EReal instERealAddMonoid))) x y) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.add_lt_top EReal.add_lt_top\u2093'. -/\ntheorem add_lt_top {x y : EReal} (hx : x \u2260 \u22a4) (hy : y \u2260 \u22a4) : x + y < \u22a4 :=\n  by\n  rw [\u2190 EReal.top_add_top]\n  exact EReal.add_lt_add hx.lt_top hy.lt_top\n#align ereal.add_lt_top EReal.add_lt_top\n\n/-! ### Negation -/\n\n\n#print EReal.neg /-\n/-- negation on `ereal` -/\nprotected def neg : EReal \u2192 EReal\n  | \u22a5 => \u22a4\n  | \u22a4 => \u22a5\n  | (x : \u211d) => (-x : \u211d)\n#align ereal.neg EReal.neg\n-/\n\ninstance : Neg EReal :=\n  \u27e8EReal.neg\u27e9\n\ninstance : SubNegZeroMonoid EReal :=\n  { EReal.addMonoid, EReal.hasNeg with\n    neg_zero := by\n      change ((-0 : \u211d) : EReal) = 0\n      simp }\n\n/- warning: ereal.neg_def clashes with ereal.coe_neg -> EReal.coe_neg\nwarning: ereal.neg_def -> EReal.coe_neg is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (Neg.neg.{0} Real Real.hasNeg x)) (Neg.neg.{0} EReal EReal.hasNeg ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (Real.toEReal (Neg.neg.{0} Real Real.instNegReal x)) (Neg.neg.{0} EReal EReal.instNegEReal (Real.toEReal x))\nCase conversion may be inaccurate. Consider using '#align ereal.neg_def EReal.coe_neg\u2093'. -/\n@[norm_cast]\nprotected theorem coe_neg (x : \u211d) : ((-x : \u211d) : EReal) = -x :=\n  rfl\n#align ereal.neg_def EReal.coe_neg\n\n#print EReal.neg_top /-\n@[simp]\ntheorem neg_top : -(\u22a4 : EReal) = \u22a5 :=\n  rfl\n#align ereal.neg_top EReal.neg_top\n-/\n\n#print EReal.neg_bot /-\n@[simp]\ntheorem neg_bot : -(\u22a5 : EReal) = \u22a4 :=\n  rfl\n#align ereal.neg_bot EReal.neg_bot\n-/\n\n/- warning: ereal.coe_neg -> EReal.coe_neg is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (Neg.neg.{0} Real Real.hasNeg x)) (Neg.neg.{0} EReal EReal.hasNeg ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (Real.toEReal (Neg.neg.{0} Real Real.instNegReal x)) (Neg.neg.{0} EReal EReal.instNegEReal (Real.toEReal x))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_neg EReal.coe_neg\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_neg (x : \u211d) : (\u2191(-x) : EReal) = -x :=\n  rfl\n#align ereal.coe_neg EReal.coe_neg\n\n/- warning: ereal.coe_sub -> EReal.coe_sub is a dubious translation:\nlean 3 declaration is\n  forall (x : Real) (y : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (HSub.hSub.{0, 0, 0} Real Real Real (instHSub.{0} Real Real.hasSub) x y)) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) y))\nbut is expected to have type\n  forall (x : Real) (y : Real), Eq.{1} EReal (Real.toEReal (HSub.hSub.{0, 0, 0} Real Real Real (instHSub.{0} Real Real.instSubReal) x y)) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) (Real.toEReal x) (Real.toEReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_sub EReal.coe_sub\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_sub (x y : \u211d) : (\u2191(x - y) : EReal) = x - y :=\n  rfl\n#align ereal.coe_sub EReal.coe_sub\n\n/- warning: ereal.coe_zsmul -> EReal.coe_zsmul is a dubious translation:\nlean 3 declaration is\n  forall (n : Int) (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (SMul.smul.{0, 0} Int Real (SubNegMonoid.SMulInt.{0} Real (AddGroup.toSubNegMonoid.{0} Real Real.addGroup)) n x)) (SMul.smul.{0, 0} Int EReal (SubNegMonoid.SMulInt.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid)) n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))\nbut is expected to have type\n  forall (n : Int) (x : Real), Eq.{1} EReal (Real.toEReal (HSMul.hSMul.{0, 0, 0} Int Real Real (instHSMul.{0, 0} Int Real (SubNegMonoid.SMulInt.{0} Real (AddGroup.toSubNegMonoid.{0} Real Real.instAddGroupReal))) n x)) (HSMul.hSMul.{0, 0, 0} Int EReal EReal (instHSMul.{0, 0} Int EReal (SubNegMonoid.SMulInt.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) n (Real.toEReal x))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_zsmul EReal.coe_zsmul\u2093'. -/\n@[norm_cast]\ntheorem coe_zsmul (n : \u2124) (x : \u211d) : (\u2191(n \u2022 x) : EReal) = n \u2022 x :=\n  map_zsmul' (\u27e8coe, coe_zero, coe_add\u27e9 : \u211d \u2192+ EReal) coe_neg _ _\n#align ereal.coe_zsmul EReal.coe_zsmul\n\ninstance : InvolutiveNeg EReal where\n  neg := Neg.neg\n  neg_neg a :=\n    match a with\n    | \u22a5 => rfl\n    | \u22a4 => rfl\n    | (a : \u211d) => by\n      norm_cast\n      simp [neg_neg a]\n\n/- warning: ereal.to_real_neg -> EReal.toReal_neg is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal}, Eq.{1} Real (EReal.toReal (Neg.neg.{0} EReal EReal.hasNeg a)) (Neg.neg.{0} Real Real.hasNeg (EReal.toReal a))\nbut is expected to have type\n  forall {a : EReal}, Eq.{1} Real (EReal.toReal (Neg.neg.{0} EReal EReal.instNegEReal a)) (Neg.neg.{0} Real Real.instNegReal (EReal.toReal a))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_neg EReal.toReal_neg\u2093'. -/\n@[simp]\ntheorem toReal_neg : \u2200 {a : EReal}, toReal (-a) = -toReal a\n  | \u22a4 => by simp\n  | \u22a5 => by simp\n  | (x : \u211d) => rfl\n#align ereal.to_real_neg EReal.toReal_neg\n\n#print EReal.neg_eq_top_iff /-\n@[simp]\ntheorem neg_eq_top_iff {x : EReal} : -x = \u22a4 \u2194 x = \u22a5 :=\n  neg_eq_iff_eq_neg\n#align ereal.neg_eq_top_iff EReal.neg_eq_top_iff\n-/\n\n#print EReal.neg_eq_bot_iff /-\n@[simp]\ntheorem neg_eq_bot_iff {x : EReal} : -x = \u22a5 \u2194 x = \u22a4 :=\n  neg_eq_iff_eq_neg\n#align ereal.neg_eq_bot_iff EReal.neg_eq_bot_iff\n-/\n\n/- warning: ereal.neg_eq_zero_iff -> EReal.neg_eq_zero_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, Iff (Eq.{1} EReal (Neg.neg.{0} EReal EReal.hasNeg x) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (Eq.{1} EReal x (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))))\nbut is expected to have type\n  forall {x : EReal}, Iff (Eq.{1} EReal (Neg.neg.{0} EReal EReal.instNegEReal x) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (Eq.{1} EReal x (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)))\nCase conversion may be inaccurate. Consider using '#align ereal.neg_eq_zero_iff EReal.neg_eq_zero_iff\u2093'. -/\n@[simp]\ntheorem neg_eq_zero_iff {x : EReal} : -x = 0 \u2194 x = 0 := by rw [neg_eq_iff_eq_neg, neg_zero]\n#align ereal.neg_eq_zero_iff EReal.neg_eq_zero_iff\n\n/- warning: ereal.neg_le_of_neg_le -> EReal.neg_le_of_neg_le is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg a) b) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg b) a)\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal a) b) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal b) a)\nCase conversion may be inaccurate. Consider using '#align ereal.neg_le_of_neg_le EReal.neg_le_of_neg_le\u2093'. -/\n/-- if `-a \u2264 b` then `-b \u2264 a` on `ereal`. -/\nprotected theorem neg_le_of_neg_le {a b : EReal} (h : -a \u2264 b) : -b \u2264 a :=\n  by\n  induction a using EReal.rec <;> induction b using EReal.rec\n  \u00b7 exact h\n  \u00b7 simpa only [coe_ne_top, neg_bot, top_le_iff] using h\n  \u00b7 exact bot_le\n  \u00b7 simpa only [coe_ne_top, le_bot_iff] using h\n  \u00b7 norm_cast  at h\u22a2\n    exact neg_le.1 h\n  \u00b7 exact bot_le\n  \u00b7 exact le_top\n  \u00b7 exact le_top\n  \u00b7 exact le_top\n#align ereal.neg_le_of_neg_le EReal.neg_le_of_neg_le\n\n/- warning: ereal.neg_le -> EReal.neg_le is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg a) b) (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg b) a)\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal a) b) (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal b) a)\nCase conversion may be inaccurate. Consider using '#align ereal.neg_le EReal.neg_le\u2093'. -/\n/-- `-a \u2264 b \u2194 -b \u2264 a` on `ereal`. -/\nprotected theorem neg_le {a b : EReal} : -a \u2264 b \u2194 -b \u2264 a :=\n  \u27e8EReal.neg_le_of_neg_le, EReal.neg_le_of_neg_le\u27e9\n#align ereal.neg_le EReal.neg_le\n\n/- warning: ereal.le_neg_of_le_neg -> EReal.le_neg_of_le_neg is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) a (Neg.neg.{0} EReal EReal.hasNeg b)) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) b (Neg.neg.{0} EReal EReal.hasNeg a))\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) a (Neg.neg.{0} EReal EReal.instNegEReal b)) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) b (Neg.neg.{0} EReal EReal.instNegEReal a))\nCase conversion may be inaccurate. Consider using '#align ereal.le_neg_of_le_neg EReal.le_neg_of_le_neg\u2093'. -/\n/-- `a \u2264 -b \u2192 b \u2264 -a` on ereal -/\ntheorem le_neg_of_le_neg {a b : EReal} (h : a \u2264 -b) : b \u2264 -a := by\n  rwa [\u2190 neg_neg b, EReal.neg_le, neg_neg]\n#align ereal.le_neg_of_le_neg EReal.le_neg_of_le_neg\n\n/- warning: ereal.neg_le_neg_iff -> EReal.neg_le_neg_iff is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg a) (Neg.neg.{0} EReal EReal.hasNeg b)) (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) b a)\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal a) (Neg.neg.{0} EReal EReal.instNegEReal b)) (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) b a)\nCase conversion may be inaccurate. Consider using '#align ereal.neg_le_neg_iff EReal.neg_le_neg_iff\u2093'. -/\n@[simp]\ntheorem neg_le_neg_iff {a b : EReal} : -a \u2264 -b \u2194 b \u2264 a := by conv_lhs => rw [EReal.neg_le, neg_neg]\n#align ereal.neg_le_neg_iff EReal.neg_le_neg_iff\n\n/- warning: ereal.neg_order_iso -> EReal.negOrderIso is a dubious translation:\nlean 3 declaration is\n  OrderIso.{0, 0} EReal (OrderDual.{0} EReal) (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OrderDual.hasLe.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))))\nbut is expected to have type\n  OrderIso.{0, 0} EReal (OrderDual.{0} EReal) (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OrderDual.instLEOrderDual.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)))\nCase conversion may be inaccurate. Consider using '#align ereal.neg_order_iso EReal.negOrderIso\u2093'. -/\n/-- Negation as an order reversing isomorphism on `ereal`. -/\ndef negOrderIso : EReal \u2243o EReal\u1d52\u1d48 :=\n  { Equiv.neg EReal with\n    toFun := fun x => OrderDual.toDual (-x)\n    invFun := fun x => -x.ofDual\n    map_rel_iff' := fun x y => neg_le_neg_iff }\n#align ereal.neg_order_iso EReal.negOrderIso\n\n/- warning: ereal.neg_lt_of_neg_lt -> EReal.neg_lt_of_neg_lt is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg a) b) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg b) a)\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal a) b) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal b) a)\nCase conversion may be inaccurate. Consider using '#align ereal.neg_lt_of_neg_lt EReal.neg_lt_of_neg_lt\u2093'. -/\ntheorem neg_lt_of_neg_lt {a b : EReal} (h : -a < b) : -b < a :=\n  by\n  apply lt_of_le_of_ne (EReal.neg_le_of_neg_le h.le)\n  intro H\n  rw [\u2190 H, neg_neg] at h\n  exact lt_irrefl _ h\n#align ereal.neg_lt_of_neg_lt EReal.neg_lt_of_neg_lt\n\n/- warning: ereal.neg_lt_iff_neg_lt -> EReal.neg_lt_iff_neg_lt is a dubious translation:\nlean 3 declaration is\n  forall {a : EReal} {b : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg a) b) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (Neg.neg.{0} EReal EReal.hasNeg b) a)\nbut is expected to have type\n  forall {a : EReal} {b : EReal}, Iff (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal a) b) (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (Neg.neg.{0} EReal EReal.instNegEReal b) a)\nCase conversion may be inaccurate. Consider using '#align ereal.neg_lt_iff_neg_lt EReal.neg_lt_iff_neg_lt\u2093'. -/\ntheorem neg_lt_iff_neg_lt {a b : EReal} : -a < b \u2194 -b < a :=\n  \u27e8fun h => EReal.neg_lt_of_neg_lt h, fun h => EReal.neg_lt_of_neg_lt h\u27e9\n#align ereal.neg_lt_iff_neg_lt EReal.neg_lt_iff_neg_lt\n\n/-!\n### Subtraction\n\nSubtraction on `ereal` is defined by `x - y = x + (-y)`. Since addition is badly behaved at some\npoints, so is subtraction. There is no standard algebraic typeclass involving subtraction that is\nregistered on `ereal`, beyond `sub_neg_zero_monoid`, because of this bad behavior.\n-/\n\n\n/- warning: ereal.bot_sub -> EReal.bot_sub is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) (Bot.bot.{0} EReal EReal.hasBot) x) (Bot.bot.{0} EReal EReal.hasBot)\nbut is expected to have type\n  forall (x : EReal), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) (Bot.bot.{0} EReal instERealBot) x) (Bot.bot.{0} EReal instERealBot)\nCase conversion may be inaccurate. Consider using '#align ereal.bot_sub EReal.bot_sub\u2093'. -/\n@[simp]\ntheorem bot_sub (x : EReal) : \u22a5 - x = \u22a5 :=\n  bot_add x\n#align ereal.bot_sub EReal.bot_sub\n\n/- warning: ereal.sub_top -> EReal.sub_top is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) x (Top.top.{0} EReal EReal.hasTop)) (Bot.bot.{0} EReal EReal.hasBot)\nbut is expected to have type\n  forall (x : EReal), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) x (Top.top.{0} EReal EReal.instTopEReal)) (Bot.bot.{0} EReal instERealBot)\nCase conversion may be inaccurate. Consider using '#align ereal.sub_top EReal.sub_top\u2093'. -/\n@[simp]\ntheorem sub_top (x : EReal) : x - \u22a4 = \u22a5 :=\n  add_bot x\n#align ereal.sub_top EReal.sub_top\n\n/- warning: ereal.top_sub_bot -> EReal.top_sub_bot is a dubious translation:\nlean 3 declaration is\n  Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) (Top.top.{0} EReal EReal.hasTop) (Bot.bot.{0} EReal EReal.hasBot)) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) (Top.top.{0} EReal EReal.instTopEReal) (Bot.bot.{0} EReal instERealBot)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.top_sub_bot EReal.top_sub_bot\u2093'. -/\n@[simp]\ntheorem top_sub_bot : (\u22a4 : EReal) - \u22a5 = \u22a4 :=\n  rfl\n#align ereal.top_sub_bot EReal.top_sub_bot\n\n/- warning: ereal.top_sub_coe -> EReal.top_sub_coe is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) (Top.top.{0} EReal EReal.hasTop) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) (Top.top.{0} EReal EReal.instTopEReal) (Real.toEReal x)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.top_sub_coe EReal.top_sub_coe\u2093'. -/\n@[simp]\ntheorem top_sub_coe (x : \u211d) : (\u22a4 : EReal) - x = \u22a4 :=\n  rfl\n#align ereal.top_sub_coe EReal.top_sub_coe\n\n/- warning: ereal.coe_sub_bot -> EReal.coe_sub_bot is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Bot.bot.{0} EReal EReal.hasBot)) (Top.top.{0} EReal EReal.hasTop)\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) (Real.toEReal x) (Bot.bot.{0} EReal instERealBot)) (Top.top.{0} EReal EReal.instTopEReal)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_sub_bot EReal.coe_sub_bot\u2093'. -/\n@[simp]\ntheorem coe_sub_bot (x : \u211d) : (x : EReal) - \u22a5 = \u22a4 :=\n  rfl\n#align ereal.coe_sub_bot EReal.coe_sub_bot\n\n/- warning: ereal.sub_le_sub -> EReal.sub_le_sub is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) t z) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) x z) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) y t))\nbut is expected to have type\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) t z) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) x z) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) y t))\nCase conversion may be inaccurate. Consider using '#align ereal.sub_le_sub EReal.sub_le_sub\u2093'. -/\ntheorem sub_le_sub {x y z t : EReal} (h : x \u2264 y) (h' : t \u2264 z) : x - z \u2264 y - t :=\n  add_le_add h (neg_le_neg_iff.2 h')\n#align ereal.sub_le_sub EReal.sub_le_sub\n\n/- warning: ereal.sub_lt_sub_of_lt_of_le -> EReal.sub_lt_sub_of_lt_of_le is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) z t) -> (Ne.{1} EReal z (Bot.bot.{0} EReal EReal.hasBot)) -> (Ne.{1} EReal t (Top.top.{0} EReal EReal.hasTop)) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) x t) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) y z))\nbut is expected to have type\n  forall {x : EReal} {y : EReal} {z : EReal} {t : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) -> (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) z t) -> (Ne.{1} EReal z (Bot.bot.{0} EReal instERealBot)) -> (Ne.{1} EReal t (Top.top.{0} EReal EReal.instTopEReal)) -> (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) x t) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) y z))\nCase conversion may be inaccurate. Consider using '#align ereal.sub_lt_sub_of_lt_of_le EReal.sub_lt_sub_of_lt_of_le\u2093'. -/\ntheorem sub_lt_sub_of_lt_of_le {x y z t : EReal} (h : x < y) (h' : z \u2264 t) (hz : z \u2260 \u22a5)\n    (ht : t \u2260 \u22a4) : x - t < y - z :=\n  add_lt_add_of_lt_of_le h (neg_le_neg_iff.2 h') (by simp [ht]) (by simp [hz])\n#align ereal.sub_lt_sub_of_lt_of_le EReal.sub_lt_sub_of_lt_of_le\n\n/- warning: ereal.coe_real_ereal_eq_coe_to_nnreal_sub_coe_to_nnreal -> EReal.coe_real_ereal_eq_coe_toNNReal_sub_coe_toNNReal is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal EReal (HasLiftT.mk.{1, 1} NNReal EReal (CoeTC\u2093.coe.{1, 1} NNReal EReal (coeTrans.{1, 1, 1} NNReal ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal) ENNReal.hasCoe))) (Real.toNNReal x)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal EReal (HasLiftT.mk.{1, 1} NNReal EReal (CoeTC\u2093.coe.{1, 1} NNReal EReal (coeTrans.{1, 1, 1} NNReal ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal) ENNReal.hasCoe))) (Real.toNNReal (Neg.neg.{0} Real Real.hasNeg x))))\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (Real.toEReal x) (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) (ENNReal.toEReal (ENNReal.some (Real.toNNReal x))) (ENNReal.toEReal (ENNReal.some (Real.toNNReal (Neg.neg.{0} Real Real.instNegReal x)))))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_real_ereal_eq_coe_to_nnreal_sub_coe_to_nnreal EReal.coe_real_ereal_eq_coe_toNNReal_sub_coe_toNNReal\u2093'. -/\ntheorem coe_real_ereal_eq_coe_toNNReal_sub_coe_toNNReal (x : \u211d) :\n    (x : EReal) = Real.toNNReal x - Real.toNNReal (-x) :=\n  by\n  rcases le_or_lt 0 x with (h | h)\n  \u00b7 have : Real.toNNReal x = \u27e8x, h\u27e9 := by\n      ext\n      simp [h]\n    simp only [Real.toNNReal_of_nonpos (neg_nonpos.mpr h), this, sub_zero, ENNReal.coe_zero,\n      coe_ennreal_zero, coe_coe]\n    rfl\n  \u00b7 have : (x : EReal) = -(-x : \u211d) := by simp\n    conv_lhs => rw [this]\n    have : Real.toNNReal (-x) = \u27e8-x, neg_nonneg.mpr h.le\u27e9 :=\n      by\n      ext\n      simp [neg_nonneg.mpr h.le]\n    simp only [Real.toNNReal_of_nonpos h.le, this, zero_sub, neg_inj, coe_neg, ENNReal.coe_zero,\n      coe_ennreal_zero, coe_coe]\n    rfl\n#align ereal.coe_real_ereal_eq_coe_to_nnreal_sub_coe_to_nnreal EReal.coe_real_ereal_eq_coe_toNNReal_sub_coe_toNNReal\n\n/- warning: ereal.to_real_sub -> EReal.toReal_sub is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.hasTop)) -> (Ne.{1} EReal x (Bot.bot.{0} EReal EReal.hasBot)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.hasTop)) -> (Ne.{1} EReal y (Bot.bot.{0} EReal EReal.hasBot)) -> (Eq.{1} Real (EReal.toReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toHasSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.subNegZeroMonoid))) x y)) (HSub.hSub.{0, 0, 0} Real Real Real (instHSub.{0} Real Real.hasSub) (EReal.toReal x) (EReal.toReal y)))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, (Ne.{1} EReal x (Top.top.{0} EReal EReal.instTopEReal)) -> (Ne.{1} EReal x (Bot.bot.{0} EReal instERealBot)) -> (Ne.{1} EReal y (Top.top.{0} EReal EReal.instTopEReal)) -> (Ne.{1} EReal y (Bot.bot.{0} EReal instERealBot)) -> (Eq.{1} Real (EReal.toReal (HSub.hSub.{0, 0, 0} EReal EReal EReal (instHSub.{0} EReal (SubNegMonoid.toSub.{0} EReal (SubNegZeroMonoid.toSubNegMonoid.{0} EReal EReal.instSubNegZeroMonoidEReal))) x y)) (HSub.hSub.{0, 0, 0} Real Real Real (instHSub.{0} Real Real.instSubReal) (EReal.toReal x) (EReal.toReal y)))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_sub EReal.toReal_sub\u2093'. -/\ntheorem toReal_sub {x y : EReal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) (hy : y \u2260 \u22a4) (h'y : y \u2260 \u22a5) :\n    toReal (x - y) = toReal x - toReal y :=\n  by\n  rw [sub_eq_add_neg, to_real_add hx h'x, to_real_neg]\n  \u00b7 rfl\n  \u00b7 simpa using hy\n  \u00b7 simpa using h'y\n#align ereal.to_real_sub EReal.toReal_sub\n\n/-! ### Multiplication -/\n\n\n#print EReal.mul_comm /-\nprotected theorem mul_comm (x y : EReal) : x * y = y * x :=\n  by\n  induction x using EReal.rec <;> induction y using EReal.rec <;> try rfl\n  dsimp only [(\u00b7 * \u00b7)]\n  simp only [EReal.mul, mul_comm]\n#align ereal.mul_comm EReal.mul_comm\n-/\n\n#print EReal.top_mul_top /-\n@[simp]\ntheorem top_mul_top : (\u22a4 : EReal) * \u22a4 = \u22a4 :=\n  rfl\n#align ereal.top_mul_top EReal.top_mul_top\n-/\n\n#print EReal.top_mul_bot /-\n@[simp]\ntheorem top_mul_bot : (\u22a4 : EReal) * \u22a5 = \u22a5 :=\n  rfl\n#align ereal.top_mul_bot EReal.top_mul_bot\n-/\n\n#print EReal.bot_mul_top /-\n@[simp]\ntheorem bot_mul_top : (\u22a5 : EReal) * \u22a4 = \u22a5 :=\n  rfl\n#align ereal.bot_mul_top EReal.bot_mul_top\n-/\n\n#print EReal.bot_mul_bot /-\n@[simp]\ntheorem bot_mul_bot : (\u22a5 : EReal) * \u22a5 = \u22a4 :=\n  rfl\n#align ereal.bot_mul_bot EReal.bot_mul_bot\n-/\n\n/- warning: ereal.mul_top_of_pos -> EReal.mul_top_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) x (Top.top.{0} EReal EReal.hasTop)) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) x (Top.top.{0} EReal EReal.instTopEReal)) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.mul_top_of_pos EReal.mul_top_of_pos\u2093'. -/\ntheorem mul_top_of_pos {x : EReal} (h : 0 < x) : x * \u22a4 = \u22a4 :=\n  by\n  induction x using EReal.rec\n  \u00b7 simpa only [not_lt_bot] using h\n  \u00b7 simp only [Mul.mul, EReal.mul, EReal.coe_pos.1 h, if_true]\n  \u00b7 rfl\n#align ereal.mul_top_of_pos EReal.mul_top_of_pos\n\n/- warning: ereal.mul_top_of_neg -> EReal.mul_top_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) x (Top.top.{0} EReal EReal.hasTop)) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) x (Top.top.{0} EReal EReal.instTopEReal)) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.mul_top_of_neg EReal.mul_top_of_neg\u2093'. -/\ntheorem mul_top_of_neg {x : EReal} (h : x < 0) : x * \u22a4 = \u22a5 :=\n  by\n  induction x using EReal.rec\n  \u00b7 rfl\n  \u00b7 simp only [EReal.coe_neg'] at h\n    simp only [Mul.mul, EReal.mul, not_lt.2 h.le, h.ne, if_false]\n  \u00b7 simpa only [not_top_lt] using h\n#align ereal.mul_top_of_neg EReal.mul_top_of_neg\n\n/- warning: ereal.top_mul_of_pos -> EReal.top_mul_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Top.top.{0} EReal EReal.hasTop) x) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Top.top.{0} EReal EReal.instTopEReal) x) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.top_mul_of_pos EReal.top_mul_of_pos\u2093'. -/\ntheorem top_mul_of_pos {x : EReal} (h : 0 < x) : \u22a4 * x = \u22a4 :=\n  by\n  rw [EReal.mul_comm]\n  exact mul_top_of_pos h\n#align ereal.top_mul_of_pos EReal.top_mul_of_pos\n\n/- warning: ereal.top_mul_of_neg -> EReal.top_mul_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Top.top.{0} EReal EReal.hasTop) x) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Top.top.{0} EReal EReal.instTopEReal) x) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.top_mul_of_neg EReal.top_mul_of_neg\u2093'. -/\ntheorem top_mul_of_neg {x : EReal} (h : x < 0) : \u22a4 * x = \u22a5 :=\n  by\n  rw [EReal.mul_comm]\n  exact mul_top_of_neg h\n#align ereal.top_mul_of_neg EReal.top_mul_of_neg\n\n/- warning: ereal.coe_mul_top_of_pos -> EReal.coe_mul_top_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Top.top.{0} EReal EReal.hasTop)) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Real.toEReal x) (Top.top.{0} EReal EReal.instTopEReal)) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_mul_top_of_pos EReal.coe_mul_top_of_pos\u2093'. -/\ntheorem coe_mul_top_of_pos {x : \u211d} (h : 0 < x) : (x : EReal) * \u22a4 = \u22a4 :=\n  mul_top_of_pos (EReal.coe_pos.2 h)\n#align ereal.coe_mul_top_of_pos EReal.coe_mul_top_of_pos\n\n/- warning: ereal.coe_mul_top_of_neg -> EReal.coe_mul_top_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Top.top.{0} EReal EReal.hasTop)) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Real.toEReal x) (Top.top.{0} EReal EReal.instTopEReal)) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_mul_top_of_neg EReal.coe_mul_top_of_neg\u2093'. -/\ntheorem coe_mul_top_of_neg {x : \u211d} (h : x < 0) : (x : EReal) * \u22a4 = \u22a5 :=\n  mul_top_of_neg (EReal.coe_neg'.2 h)\n#align ereal.coe_mul_top_of_neg EReal.coe_mul_top_of_neg\n\n/- warning: ereal.top_mul_coe_of_pos -> EReal.top_mul_coe_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Top.top.{0} EReal EReal.hasTop) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Top.top.{0} EReal EReal.instTopEReal) (Real.toEReal x)) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.top_mul_coe_of_pos EReal.top_mul_coe_of_pos\u2093'. -/\ntheorem top_mul_coe_of_pos {x : \u211d} (h : 0 < x) : (\u22a4 : EReal) * x = \u22a4 :=\n  top_mul_of_pos (EReal.coe_pos.2 h)\n#align ereal.top_mul_coe_of_pos EReal.top_mul_coe_of_pos\n\n/- warning: ereal.top_mul_coe_of_neg -> EReal.top_mul_coe_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Top.top.{0} EReal EReal.hasTop) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Top.top.{0} EReal EReal.instTopEReal) (Real.toEReal x)) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.top_mul_coe_of_neg EReal.top_mul_coe_of_neg\u2093'. -/\ntheorem top_mul_coe_of_neg {x : \u211d} (h : x < 0) : (\u22a4 : EReal) * x = \u22a5 :=\n  top_mul_of_neg (EReal.coe_neg'.2 h)\n#align ereal.top_mul_coe_of_neg EReal.top_mul_coe_of_neg\n\n/- warning: ereal.mul_bot_of_pos -> EReal.mul_bot_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) x (Bot.bot.{0} EReal EReal.hasBot)) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) x (Bot.bot.{0} EReal instERealBot)) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.mul_bot_of_pos EReal.mul_bot_of_pos\u2093'. -/\ntheorem mul_bot_of_pos {x : EReal} (h : 0 < x) : x * \u22a5 = \u22a5 :=\n  by\n  induction x using EReal.rec\n  \u00b7 simpa only [not_lt_bot] using h\n  \u00b7 simp only [Mul.mul, EReal.mul, EReal.coe_pos.1 h, if_true]\n  \u00b7 rfl\n#align ereal.mul_bot_of_pos EReal.mul_bot_of_pos\n\n/- warning: ereal.mul_bot_of_neg -> EReal.mul_bot_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) x (Bot.bot.{0} EReal EReal.hasBot)) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) x (Bot.bot.{0} EReal instERealBot)) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.mul_bot_of_neg EReal.mul_bot_of_neg\u2093'. -/\ntheorem mul_bot_of_neg {x : EReal} (h : x < 0) : x * \u22a5 = \u22a4 :=\n  by\n  induction x using EReal.rec\n  \u00b7 rfl\n  \u00b7 simp only [EReal.coe_neg'] at h\n    simp only [Mul.mul, EReal.mul, not_lt.2 h.le, h.ne, if_false]\n  \u00b7 simpa only [not_top_lt] using h\n#align ereal.mul_bot_of_neg EReal.mul_bot_of_neg\n\n/- warning: ereal.bot_mul_of_pos -> EReal.bot_mul_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Bot.bot.{0} EReal EReal.hasBot) x) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Bot.bot.{0} EReal instERealBot) x) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.bot_mul_of_pos EReal.bot_mul_of_pos\u2093'. -/\ntheorem bot_mul_of_pos {x : EReal} (h : 0 < x) : \u22a5 * x = \u22a5 :=\n  by\n  rw [EReal.mul_comm]\n  exact mul_bot_of_pos h\n#align ereal.bot_mul_of_pos EReal.bot_mul_of_pos\n\n/- warning: ereal.bot_mul_of_neg -> EReal.bot_mul_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Bot.bot.{0} EReal EReal.hasBot) x) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : EReal}, (LT.lt.{0} EReal (Preorder.toLT.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Bot.bot.{0} EReal instERealBot) x) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.bot_mul_of_neg EReal.bot_mul_of_neg\u2093'. -/\ntheorem bot_mul_of_neg {x : EReal} (h : x < 0) : \u22a5 * x = \u22a4 :=\n  by\n  rw [EReal.mul_comm]\n  exact mul_bot_of_neg h\n#align ereal.bot_mul_of_neg EReal.bot_mul_of_neg\n\n/- warning: ereal.coe_mul_bot_of_pos -> EReal.coe_mul_bot_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Bot.bot.{0} EReal EReal.hasBot)) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Real.toEReal x) (Bot.bot.{0} EReal instERealBot)) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_mul_bot_of_pos EReal.coe_mul_bot_of_pos\u2093'. -/\ntheorem coe_mul_bot_of_pos {x : \u211d} (h : 0 < x) : (x : EReal) * \u22a5 = \u22a5 :=\n  mul_bot_of_pos (EReal.coe_pos.2 h)\n#align ereal.coe_mul_bot_of_pos EReal.coe_mul_bot_of_pos\n\n/- warning: ereal.coe_mul_bot_of_neg -> EReal.coe_mul_bot_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) (Bot.bot.{0} EReal EReal.hasBot)) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Real.toEReal x) (Bot.bot.{0} EReal instERealBot)) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_mul_bot_of_neg EReal.coe_mul_bot_of_neg\u2093'. -/\ntheorem coe_mul_bot_of_neg {x : \u211d} (h : x < 0) : (x : EReal) * \u22a5 = \u22a4 :=\n  mul_bot_of_neg (EReal.coe_neg'.2 h)\n#align ereal.coe_mul_bot_of_neg EReal.coe_mul_bot_of_neg\n\n/- warning: ereal.bot_mul_coe_of_pos -> EReal.bot_mul_coe_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero))) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Bot.bot.{0} EReal EReal.hasBot) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (Bot.bot.{0} EReal EReal.hasBot))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal)) x) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Bot.bot.{0} EReal instERealBot) (Real.toEReal x)) (Bot.bot.{0} EReal instERealBot))\nCase conversion may be inaccurate. Consider using '#align ereal.bot_mul_coe_of_pos EReal.bot_mul_coe_of_pos\u2093'. -/\ntheorem bot_mul_coe_of_pos {x : \u211d} (h : 0 < x) : (\u22a5 : EReal) * x = \u22a5 :=\n  bot_mul_of_pos (EReal.coe_pos.2 h)\n#align ereal.bot_mul_coe_of_pos EReal.bot_mul_coe_of_pos\n\n/- warning: ereal.bot_mul_coe_of_neg -> EReal.bot_mul_coe_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {x : Real}, (LT.lt.{0} Real Real.hasLt x (OfNat.ofNat.{0} Real 0 (OfNat.mk.{0} Real 0 (Zero.zero.{0} Real Real.hasZero)))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) (Bot.bot.{0} EReal EReal.hasBot) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (Top.top.{0} EReal EReal.hasTop))\nbut is expected to have type\n  forall {x : Real}, (LT.lt.{0} Real Real.instLTReal x (OfNat.ofNat.{0} Real 0 (Zero.toOfNat0.{0} Real Real.instZeroReal))) -> (Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (Bot.bot.{0} EReal instERealBot) (Real.toEReal x)) (Top.top.{0} EReal EReal.instTopEReal))\nCase conversion may be inaccurate. Consider using '#align ereal.bot_mul_coe_of_neg EReal.bot_mul_coe_of_neg\u2093'. -/\ntheorem bot_mul_coe_of_neg {x : \u211d} (h : x < 0) : (\u22a5 : EReal) * x = \u22a4 :=\n  bot_mul_of_neg (EReal.coe_neg'.2 h)\n#align ereal.bot_mul_coe_of_neg EReal.bot_mul_coe_of_neg\n\n/- warning: ereal.to_real_mul -> EReal.toReal_mul is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, Eq.{1} Real (EReal.toReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) x y)) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.hasMul) (EReal.toReal x) (EReal.toReal y))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, Eq.{1} Real (EReal.toReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) x y)) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.instMulReal) (EReal.toReal x) (EReal.toReal y))\nCase conversion may be inaccurate. Consider using '#align ereal.to_real_mul EReal.toReal_mul\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Tactic/Lean3.lean:145:2: warning: unsupported: with_cases -/\ntheorem toReal_mul {x y : EReal} : toReal (x * y) = toReal x * toReal y :=\n  by\n  -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n    apply @induction\u2082 fun x y => to_real (x * y) = to_real x * to_real y <;>\n    propagate_tags try dsimp only\n  case top_zero | bot_zero | zero_top | zero_bot =>\n    all_goals simp only [MulZeroClass.zero_mul, MulZeroClass.mul_zero, to_real_zero]\n  case coe_coe x y => norm_cast\n  case top_top => rw [top_mul_top, to_real_top, MulZeroClass.mul_zero]\n  case top_bot => rw [top_mul_bot, to_real_top, to_real_bot, MulZeroClass.zero_mul]\n  case bot_top => rw [bot_mul_top, to_real_bot, MulZeroClass.zero_mul]\n  case bot_bot => rw [bot_mul_bot, to_real_top, to_real_bot, MulZeroClass.zero_mul]\n  case pos_bot x hx =>\n    rw [to_real_bot, to_real_coe, coe_mul_bot_of_pos hx, to_real_bot, MulZeroClass.mul_zero]\n  case neg_bot x hx =>\n    rw [to_real_bot, to_real_coe, coe_mul_bot_of_neg hx, to_real_top, MulZeroClass.mul_zero]\n  case pos_top x hx =>\n    rw [to_real_top, to_real_coe, coe_mul_top_of_pos hx, to_real_top, MulZeroClass.mul_zero]\n  case neg_top x hx =>\n    rw [to_real_top, to_real_coe, coe_mul_top_of_neg hx, to_real_bot, MulZeroClass.mul_zero]\n  case top_pos y hy =>\n    rw [to_real_top, to_real_coe, top_mul_coe_of_pos hy, to_real_top, MulZeroClass.zero_mul]\n  case top_neg y hy =>\n    rw [to_real_top, to_real_coe, top_mul_coe_of_neg hy, to_real_bot, MulZeroClass.zero_mul]\n  case bot_pos y hy =>\n    rw [to_real_bot, to_real_coe, bot_mul_coe_of_pos hy, to_real_bot, MulZeroClass.zero_mul]\n  case bot_neg y hy =>\n    rw [to_real_bot, to_real_coe, bot_mul_coe_of_neg hy, to_real_top, MulZeroClass.zero_mul]\n#align ereal.to_real_mul EReal.toReal_mul\n\n/- ./././Mathport/Syntax/Translate/Tactic/Lean3.lean:145:2: warning: unsupported: with_cases -/\n#print EReal.neg_mul /-\nprotected theorem neg_mul (x y : EReal) : -x * y = -(x * y) :=\n  by\n  -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n    apply @induction\u2082 fun x y => -x * y = -(x * y) <;>\n    propagate_tags try dsimp only\n  case top_top | bot_top | top_bot | bot_bot => all_goals rfl\n  case top_zero | bot_zero | zero_top | zero_bot =>\n    all_goals simp only [MulZeroClass.zero_mul, MulZeroClass.mul_zero, neg_zero]\n  case coe_coe x y => norm_cast; exact neg_mul _ _\n  case pos_bot x hx =>\n    rw [coe_mul_bot_of_pos hx, neg_bot, \u2190 coe_neg, coe_mul_bot_of_neg (neg_neg_of_pos hx)]\n  case neg_bot x hx =>\n    rw [coe_mul_bot_of_neg hx, neg_top, \u2190 coe_neg, coe_mul_bot_of_pos (neg_pos_of_neg hx)]\n  case pos_top x hx =>\n    rw [coe_mul_top_of_pos hx, neg_top, \u2190 coe_neg, coe_mul_top_of_neg (neg_neg_of_pos hx)]\n  case neg_top x hx =>\n    rw [coe_mul_top_of_neg hx, neg_bot, \u2190 coe_neg, coe_mul_top_of_pos (neg_pos_of_neg hx)]\n  case top_pos y hy => rw [top_mul_coe_of_pos hy, neg_top, bot_mul_coe_of_pos hy]\n  case top_neg y hy => rw [top_mul_coe_of_neg hy, neg_top, neg_bot, bot_mul_coe_of_neg hy]\n  case bot_pos y hy => rw [bot_mul_coe_of_pos hy, neg_bot, top_mul_coe_of_pos hy]\n  case bot_neg y hy => rw [bot_mul_coe_of_neg hy, neg_bot, neg_top, top_mul_coe_of_neg hy]\n#align ereal.neg_mul EReal.neg_mul\n-/\n\ninstance : HasDistribNeg EReal :=\n  { EReal.hasInvolutiveNeg with\n    neg_mul := EReal.neg_mul\n    mul_neg := fun x y => by\n      rw [x.mul_comm, x.mul_comm]\n      exact y.neg_mul x }\n\n/-! ### Absolute value -/\n\n\n#print EReal.abs /-\n/-- The absolute value from `ereal` to `\u211d\u22650\u221e`, mapping `\u22a5` and `\u22a4` to `\u22a4` and\na real `x` to `|x|`. -/\nprotected def abs : EReal \u2192 \u211d\u22650\u221e\n  | \u22a5 => \u22a4\n  | \u22a4 => \u22a4\n  | (x : \u211d) => ENNReal.ofReal (|x|)\n#align ereal.abs EReal.abs\n-/\n\n/- warning: ereal.abs_top -> EReal.abs_top is a dubious translation:\nlean 3 declaration is\n  Eq.{1} ENNReal (EReal.abs (Top.top.{0} EReal EReal.hasTop)) (Top.top.{0} ENNReal (CompleteLattice.toHasTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder)))\nbut is expected to have type\n  Eq.{1} ENNReal (EReal.abs (Top.top.{0} EReal EReal.instTopEReal)) (Top.top.{0} ENNReal (CompleteLattice.toTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.abs_top EReal.abs_top\u2093'. -/\n@[simp]\ntheorem abs_top : (\u22a4 : EReal).abs = \u22a4 :=\n  rfl\n#align ereal.abs_top EReal.abs_top\n\n/- warning: ereal.abs_bot -> EReal.abs_bot is a dubious translation:\nlean 3 declaration is\n  Eq.{1} ENNReal (EReal.abs (Bot.bot.{0} EReal EReal.hasBot)) (Top.top.{0} ENNReal (CompleteLattice.toHasTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder)))\nbut is expected to have type\n  Eq.{1} ENNReal (EReal.abs (Bot.bot.{0} EReal instERealBot)) (Top.top.{0} ENNReal (CompleteLattice.toTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.abs_bot EReal.abs_bot\u2093'. -/\n@[simp]\ntheorem abs_bot : (\u22a5 : EReal).abs = \u22a4 :=\n  rfl\n#align ereal.abs_bot EReal.abs_bot\n\n/- warning: ereal.abs_def -> EReal.abs_def is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} ENNReal (EReal.abs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (ENNReal.ofReal (Abs.abs.{0} Real (Neg.toHasAbs.{0} Real Real.hasNeg Real.hasSup) x))\nbut is expected to have type\n  forall (x : Real), Eq.{1} ENNReal (EReal.abs (Real.toEReal x)) (ENNReal.ofReal (Abs.abs.{0} Real (Neg.toHasAbs.{0} Real Real.instNegReal Real.instSupReal) x))\nCase conversion may be inaccurate. Consider using '#align ereal.abs_def EReal.abs_def\u2093'. -/\ntheorem abs_def (x : \u211d) : (x : EReal).abs = ENNReal.ofReal (|x|) :=\n  rfl\n#align ereal.abs_def EReal.abs_def\n\n/- warning: ereal.abs_coe_lt_top -> EReal.abs_coe_lt_top is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (EReal.abs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (Top.top.{0} ENNReal (CompleteLattice.toHasTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder)))\nbut is expected to have type\n  forall (x : Real), LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (OrderedSemiring.toPartialOrder.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))) (EReal.abs (Real.toEReal x)) (Top.top.{0} ENNReal (CompleteLattice.toTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal)))\nCase conversion may be inaccurate. Consider using '#align ereal.abs_coe_lt_top EReal.abs_coe_lt_top\u2093'. -/\ntheorem abs_coe_lt_top (x : \u211d) : (x : EReal).abs < \u22a4 :=\n  ENNReal.ofReal_lt_top\n#align ereal.abs_coe_lt_top EReal.abs_coe_lt_top\n\n/- warning: ereal.abs_eq_zero_iff -> EReal.abs_eq_zero_iff is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal}, Iff (Eq.{1} ENNReal (EReal.abs x) (OfNat.ofNat.{0} ENNReal 0 (OfNat.mk.{0} ENNReal 0 (Zero.zero.{0} ENNReal ENNReal.hasZero)))) (Eq.{1} EReal x (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero))))\nbut is expected to have type\n  forall {x : EReal}, Iff (Eq.{1} ENNReal (EReal.abs x) (OfNat.ofNat.{0} ENNReal 0 (Zero.toOfNat0.{0} ENNReal instENNRealZero))) (Eq.{1} EReal x (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero)))\nCase conversion may be inaccurate. Consider using '#align ereal.abs_eq_zero_iff EReal.abs_eq_zero_iff\u2093'. -/\n@[simp]\ntheorem abs_eq_zero_iff {x : EReal} : x.abs = 0 \u2194 x = 0 :=\n  by\n  induction x using EReal.rec\n  \u00b7 simp only [abs_bot, ENNReal.top_ne_zero, bot_ne_zero]\n  \u00b7 simp only [EReal.abs, coe_eq_zero, ENNReal.ofReal_eq_zero, abs_nonpos_iff]\n  \u00b7 simp only [abs_top, ENNReal.top_ne_zero, top_ne_zero]\n#align ereal.abs_eq_zero_iff EReal.abs_eq_zero_iff\n\n/- warning: ereal.abs_zero -> EReal.abs_zero is a dubious translation:\nlean 3 declaration is\n  Eq.{1} ENNReal (EReal.abs (OfNat.ofNat.{0} EReal 0 (OfNat.mk.{0} EReal 0 (Zero.zero.{0} EReal EReal.hasZero)))) (OfNat.ofNat.{0} ENNReal 0 (OfNat.mk.{0} ENNReal 0 (Zero.zero.{0} ENNReal ENNReal.hasZero)))\nbut is expected to have type\n  Eq.{1} ENNReal (EReal.abs (OfNat.ofNat.{0} EReal 0 (Zero.toOfNat0.{0} EReal instERealZero))) (OfNat.ofNat.{0} ENNReal 0 (Zero.toOfNat0.{0} ENNReal instENNRealZero))\nCase conversion may be inaccurate. Consider using '#align ereal.abs_zero EReal.abs_zero\u2093'. -/\n@[simp]\ntheorem abs_zero : (0 : EReal).abs = 0 := by rw [abs_eq_zero_iff]\n#align ereal.abs_zero EReal.abs_zero\n\n/- warning: ereal.coe_abs -> EReal.coe_abs is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (EReal.abs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (Abs.abs.{0} Real (Neg.toHasAbs.{0} Real Real.hasNeg Real.hasSup) x))\nbut is expected to have type\n  forall (x : Real), Eq.{1} EReal (ENNReal.toEReal (EReal.abs (Real.toEReal x))) (Real.toEReal (Abs.abs.{0} Real (Neg.toHasAbs.{0} Real Real.instNegReal Real.instSupReal) x))\nCase conversion may be inaccurate. Consider using '#align ereal.coe_abs EReal.coe_abs\u2093'. -/\n@[simp]\ntheorem coe_abs (x : \u211d) : ((x : EReal).abs : EReal) = (|x| : \u211d) := by\n  rcases lt_trichotomy 0 x with (hx | rfl | hx) <;> simp [abs_def]\n#align ereal.coe_abs EReal.coe_abs\n\n/- warning: ereal.abs_mul -> EReal.abs_mul is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal) (y : EReal), Eq.{1} ENNReal (EReal.abs (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) x y)) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (Distrib.toHasMul.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring)))))))) (EReal.abs x) (EReal.abs y))\nbut is expected to have type\n  forall (x : EReal) (y : EReal), Eq.{1} ENNReal (EReal.abs (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) x y)) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (CanonicallyOrderedCommSemiring.toMul.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)) (EReal.abs x) (EReal.abs y))\nCase conversion may be inaccurate. Consider using '#align ereal.abs_mul EReal.abs_mul\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Tactic/Lean3.lean:145:2: warning: unsupported: with_cases -/\n@[simp]\ntheorem abs_mul (x y : EReal) : (x * y).abs = x.abs * y.abs :=\n  by\n  -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n    apply @induction\u2082 fun x y => (x * y).abs = x.abs * y.abs <;>\n    propagate_tags try dsimp only\n  case top_top | bot_top | top_bot | bot_bot => all_goals rfl\n  case top_zero | bot_zero | zero_top | zero_bot =>\n    all_goals simp only [MulZeroClass.zero_mul, MulZeroClass.mul_zero, abs_zero]\n  case coe_coe x y => simp only [\u2190 coe_mul, EReal.abs, abs_mul, ENNReal.ofReal_mul (abs_nonneg _)]\n  case pos_bot x hx =>\n    simp only [coe_mul_bot_of_pos hx, hx.ne', abs_bot, WithTop.mul_top, Ne.def, abs_eq_zero_iff,\n      coe_eq_zero, not_false_iff]\n  case neg_bot x hx =>\n    simp only [coe_mul_bot_of_neg hx, hx.ne, abs_bot, WithTop.mul_top, Ne.def, abs_eq_zero_iff,\n      coe_eq_zero, not_false_iff, abs_top]\n  case pos_top x hx =>\n    simp only [coe_mul_top_of_pos hx, hx.ne', WithTop.mul_top, Ne.def, abs_eq_zero_iff, coe_eq_zero,\n      not_false_iff, abs_top]\n  case neg_top x hx =>\n    simp only [coe_mul_top_of_neg hx, hx.ne, abs_bot, WithTop.mul_top, Ne.def, abs_eq_zero_iff,\n      coe_eq_zero, not_false_iff, abs_top]\n  case top_pos y hy =>\n    simp only [top_mul_coe_of_pos hy, hy.ne', WithTop.top_mul, Ne.def, abs_eq_zero_iff, coe_eq_zero,\n      not_false_iff, abs_top]\n  case top_neg y hy =>\n    simp only [top_mul_coe_of_neg hy, hy.ne, abs_bot, WithTop.top_mul, Ne.def, abs_eq_zero_iff,\n      coe_eq_zero, not_false_iff, abs_top]\n  case bot_pos y hy =>\n    simp only [bot_mul_coe_of_pos hy, hy.ne', abs_bot, WithTop.top_mul, Ne.def, abs_eq_zero_iff,\n      coe_eq_zero, not_false_iff]\n  case bot_neg y hy =>\n    simp only [bot_mul_coe_of_neg hy, hy.ne, abs_bot, WithTop.top_mul, Ne.def, abs_eq_zero_iff,\n      coe_eq_zero, not_false_iff, abs_top]\n#align ereal.abs_mul EReal.abs_mul\n\n/-! ### Sign -/\n\n\n#print EReal.sign_top /-\n@[simp]\ntheorem sign_top : SignType.sign (\u22a4 : EReal) = 1 :=\n  rfl\n#align ereal.sign_top EReal.sign_top\n-/\n\n#print EReal.sign_bot /-\n@[simp]\ntheorem sign_bot : SignType.sign (\u22a5 : EReal) = -1 :=\n  rfl\n#align ereal.sign_bot EReal.sign_bot\n-/\n\n/- warning: ereal.sign_coe -> EReal.sign_coe is a dubious translation:\nlean 3 declaration is\n  forall (x : Real), Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x)) (coeFn.{1, 1} (OrderHom.{0, 0} Real SignType Real.preorder (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} Real SignType Real.preorder (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => Real -> SignType) (OrderHom.hasCoeToFun.{0, 0} Real SignType Real.preorder (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} Real Real.hasZero Real.preorder (fun (a : Real) (b : Real) => Real.decidableLT a b)) x)\nbut is expected to have type\n  forall (x : Real), Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) (Real.toEReal x)) (OrderHom.toFun.{0, 0} Real SignType Real.instPreorderReal (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} Real Real.instZeroReal Real.instPreorderReal (fun (a : Real) (b : Real) => Real.decidableLT a b)) x)\nCase conversion may be inaccurate. Consider using '#align ereal.sign_coe EReal.sign_coe\u2093'. -/\n@[simp]\ntheorem sign_coe (x : \u211d) : SignType.sign (x : EReal) = SignType.sign x := by\n  simp only [SignType.sign, OrderHom.coe_fun_mk, EReal.coe_pos, EReal.coe_neg']\n#align ereal.sign_coe EReal.sign_coe\n\n/- warning: ereal.sign_mul -> EReal.sign_mul is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal) (y : EReal), Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) x y)) (HMul.hMul.{0, 0, 0} SignType SignType SignType (instHMul.{0} SignType SignType.hasMul) (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y))\nbut is expected to have type\n  forall (x : EReal) (y : EReal), Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) x y)) (HMul.hMul.{0, 0, 0} SignType SignType SignType (instHMul.{0} SignType SignType.instMulSignType) (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y))\nCase conversion may be inaccurate. Consider using '#align ereal.sign_mul EReal.sign_mul\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Tactic/Lean3.lean:145:2: warning: unsupported: with_cases -/\n@[simp]\ntheorem sign_mul (x y : EReal) : SignType.sign (x * y) = SignType.sign x * SignType.sign y :=\n  by\n  -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n    apply @induction\u2082 fun x y => SignType.sign (x * y) = SignType.sign x * SignType.sign y <;>\n    propagate_tags try dsimp only\n  case top_top | bot_top | top_bot | bot_bot => all_goals rfl\n  case top_zero | bot_zero | zero_top | zero_bot =>\n    all_goals simp only [MulZeroClass.zero_mul, MulZeroClass.mul_zero, sign_zero]\n  case coe_coe x y => simp only [\u2190 coe_mul, sign_coe, sign_mul]\n  case pos_bot x hx => simp_rw [coe_mul_bot_of_pos hx, sign_coe, sign_pos hx, one_mul]\n  case neg_bot x hx =>\n    simp_rw [coe_mul_bot_of_neg hx, sign_coe, sign_neg hx, sign_top, sign_bot, neg_one_mul, neg_neg]\n  case pos_top x hx => simp_rw [coe_mul_top_of_pos hx, sign_coe, sign_pos hx, one_mul]\n  case neg_top x hx =>\n    simp_rw [coe_mul_top_of_neg hx, sign_coe, sign_neg hx, sign_top, sign_bot, mul_one]\n  case top_pos y hy => simp_rw [top_mul_coe_of_pos hy, sign_coe, sign_pos hy, mul_one]\n  case top_neg y hy =>\n    simp_rw [top_mul_coe_of_neg hy, sign_coe, sign_neg hy, sign_top, sign_bot, one_mul]\n  case bot_pos y hy => simp_rw [bot_mul_coe_of_pos hy, sign_coe, sign_pos hy, mul_one]\n  case bot_neg y hy =>\n    simp_rw [bot_mul_coe_of_neg hy, sign_coe, sign_neg hy, sign_top, sign_bot, neg_one_mul, neg_neg]\n#align ereal.sign_mul EReal.sign_mul\n\n/- warning: ereal.sign_mul_abs -> EReal.sign_mul_abs is a dubious translation:\nlean 3 declaration is\n  forall (x : EReal), Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) SignType EReal (HasLiftT.mk.{1, 1} SignType EReal (CoeTC\u2093.coe.{1, 1} SignType EReal (SignType.hasCoeT.{0} EReal EReal.hasZero EReal.hasOne EReal.hasNeg))) (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (EReal.abs x))) x\nbut is expected to have type\n  forall (x : EReal), Eq.{1} EReal (HMul.hMul.{0, 0, 0} EReal EReal EReal (instHMul.{0} EReal EReal.instMulEReal) (SignType.cast.{0} EReal instERealZero instERealOne EReal.instNegEReal (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x)) (ENNReal.toEReal (EReal.abs x))) x\nCase conversion may be inaccurate. Consider using '#align ereal.sign_mul_abs EReal.sign_mul_abs\u2093'. -/\ntheorem sign_mul_abs (x : EReal) : (SignType.sign x * x.abs : EReal) = x :=\n  by\n  induction x using EReal.rec\n  \u00b7 simp\n  \u00b7 rcases lt_trichotomy 0 x with (hx | rfl | hx)\n    \u00b7 simp [sign_pos hx, abs_of_pos hx]\n    \u00b7 simp\n    \u00b7 simp [sign_neg hx, abs_of_neg hx]\n  \u00b7 simp\n#align ereal.sign_mul_abs EReal.sign_mul_abs\n\n/- warning: ereal.sign_eq_and_abs_eq_iff_eq -> EReal.sign_eq_and_abs_eq_iff_eq is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, Iff (And (Eq.{1} ENNReal (EReal.abs x) (EReal.abs y)) (Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y))) (Eq.{1} EReal x y)\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, Iff (And (Eq.{1} ENNReal (EReal.abs x) (EReal.abs y)) (Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y))) (Eq.{1} EReal x y)\nCase conversion may be inaccurate. Consider using '#align ereal.sign_eq_and_abs_eq_iff_eq EReal.sign_eq_and_abs_eq_iff_eq\u2093'. -/\ntheorem sign_eq_and_abs_eq_iff_eq {x y : EReal} :\n    x.abs = y.abs \u2227 SignType.sign x = SignType.sign y \u2194 x = y :=\n  by\n  constructor\n  \u00b7 rintro \u27e8habs, hsign\u27e9\n    rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs, habs, hsign]\n  \u00b7 rintro rfl\n    simp only [eq_self_iff_true, and_self_iff]\n#align ereal.sign_eq_and_abs_eq_iff_eq EReal.sign_eq_and_abs_eq_iff_eq\n\n/- warning: ereal.le_iff_sign -> EReal.le_iff_sign is a dubious translation:\nlean 3 declaration is\n  forall {x : EReal} {y : EReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder))))) x y) (Or (LT.lt.{0} SignType (Preorder.toLT.{0} SignType (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y)) (Or (And (Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) SignType.neg) (And (Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y) SignType.neg) (LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (EReal.abs y) (EReal.abs x)))) (Or (And (Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) SignType.zero) (Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y) SignType.zero)) (And (Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) SignType.pos) (And (Eq.{1} SignType (coeFn.{1, 1} (OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (fun (_x : OrderHom.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) => EReal -> SignType) (OrderHom.hasCoeToFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (LinearOrder.toLattice.{0} SignType SignType.linearOrder))))) (SignType.sign.{0} EReal EReal.hasZero (PartialOrder.toPreorder.{0} EReal (CompleteSemilatticeInf.toPartialOrder.{0} EReal (CompleteLattice.toCompleteSemilatticeInf.{0} EReal (CompleteLinearOrder.toCompleteLattice.{0} EReal EReal.completeLinearOrder)))) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y) SignType.pos) (LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (EReal.abs x) (EReal.abs y)))))))\nbut is expected to have type\n  forall {x : EReal} {y : EReal}, Iff (LE.le.{0} EReal (Preorder.toLE.{0} EReal (PartialOrder.toPreorder.{0} EReal instERealPartialOrder)) x y) (Or (LT.lt.{0} SignType (Preorder.toLT.{0} SignType (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType)))))) (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y)) (Or (And (Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) SignType.neg) (And (Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y) SignType.neg) (LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (OrderedSemiring.toPartialOrder.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))) (EReal.abs y) (EReal.abs x)))) (Or (And (Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) SignType.zero) (Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y) SignType.zero)) (And (Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) x) SignType.pos) (And (Eq.{1} SignType (OrderHom.toFun.{0, 0} EReal SignType (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (PartialOrder.toPreorder.{0} SignType (SemilatticeInf.toPartialOrder.{0} SignType (Lattice.toSemilatticeInf.{0} SignType (DistribLattice.toLattice.{0} SignType (instDistribLattice.{0} SignType SignType.instLinearOrderSignType))))) (SignType.sign.{0} EReal instERealZero (PartialOrder.toPreorder.{0} EReal instERealPartialOrder) (fun (a : EReal) (b : EReal) => EReal.decidableLt a b)) y) SignType.pos) (LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (OrderedSemiring.toPartialOrder.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))) (EReal.abs x) (EReal.abs y)))))))\nCase conversion may be inaccurate. Consider using '#align ereal.le_iff_sign EReal.le_iff_sign\u2093'. -/\ntheorem le_iff_sign {x y : EReal} :\n    x \u2264 y \u2194\n      SignType.sign x < SignType.sign y \u2228\n        SignType.sign x = SignType.neg \u2227 SignType.sign y = SignType.neg \u2227 y.abs \u2264 x.abs \u2228\n          SignType.sign x = SignType.zero \u2227 SignType.sign y = SignType.zero \u2228\n            SignType.sign x = SignType.pos \u2227 SignType.sign y = SignType.pos \u2227 x.abs \u2264 y.abs :=\n  by\n  constructor\n  \u00b7 intro h\n    rcases(sign.monotone h).lt_or_eq with (hs | hs)\n    \u00b7 exact Or.inl hs\n    \u00b7 rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs] at h\n      cases SignType.sign y <;> rw [hs] at *\n      \u00b7 simp\n      \u00b7 simp at h\u22a2\n        exact Or.inl h\n      \u00b7 simpa using h\n  \u00b7 rintro (h | h | h | h)\n    \u00b7 exact (sign.monotone.reflect_lt h).le\n    all_goals rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs]; simp [h]\n#align ereal.le_iff_sign EReal.le_iff_sign\n\ninstance : CommMonoidWithZero EReal :=\n  { EReal.hasMul, EReal.hasOne, EReal.hasZero,\n    EReal.mulZeroOneClass with\n    mul_assoc := fun x y z => by\n      rw [\u2190 sign_eq_and_abs_eq_iff_eq]\n      simp only [mul_assoc, abs_mul, eq_self_iff_true, sign_mul, and_self_iff]\n    mul_comm := EReal.mul_comm }\n\ninstance : PosMulMono EReal :=\n  posMulMono_iff_covariant_pos.2\n    \u27e8by\n      rintro \u27e8x, x0\u27e9 a b h; dsimp\n      rcases le_iff_sign.mp h with (h | h | h | h)\n      \u00b7 rw [le_iff_sign]\n        left\n        simp [sign_pos x0, h]\n      all_goals\n        rw [\u2190 x.sign_mul_abs, \u2190 a.sign_mul_abs, \u2190 b.sign_mul_abs, sign_pos x0]\n        simp only [h]; dsimp\n        simp only [neg_mul, mul_neg, EReal.neg_le_neg_iff, one_mul, le_refl, MulZeroClass.zero_mul,\n          MulZeroClass.mul_zero]\n      all_goals norm_cast; exact mul_le_mul_left' h.2.2 _\u27e9\n\ninstance : MulPosMono EReal :=\n  posMulMono_iff_mulPosMono.1 EReal.posMulMono\n\ninstance : PosMulReflectLT EReal :=\n  PosMulMono.toPosMulReflectLT\n\ninstance : MulPosReflectLT EReal :=\n  MulPosMono.toMulPosReflectLT\n\n/- warning: ereal.coe_pow -> EReal.coe_pow is a dubious translation:\nlean 3 declaration is\n  forall (x : Real) (n : Nat), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) (HPow.hPow.{0, 0, 0} Real Nat Real (instHPow.{0, 0} Real Nat (Monoid.Pow.{0} Real Real.monoid)) x n)) (HPow.hPow.{0, 0, 0} EReal Nat EReal (instHPow.{0, 0} EReal Nat (Monoid.Pow.{0} EReal (MonoidWithZero.toMonoid.{0} EReal (CommMonoidWithZero.toMonoidWithZero.{0} EReal EReal.commMonoidWithZero)))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Real EReal (HasLiftT.mk.{1, 1} Real EReal (CoeTC\u2093.coe.{1, 1} Real EReal (coeBase.{1, 1} Real EReal EReal.hasCoe))) x) n)\nbut is expected to have type\n  forall (x : Real) (n : Nat), Eq.{1} EReal (Real.toEReal (HPow.hPow.{0, 0, 0} Real Nat Real (instHPow.{0, 0} Real Nat (Monoid.Pow.{0} Real Real.instMonoidReal)) x n)) (HPow.hPow.{0, 0, 0} EReal Nat EReal (instHPow.{0, 0} EReal Nat (Monoid.Pow.{0} EReal (MonoidWithZero.toMonoid.{0} EReal (CommMonoidWithZero.toMonoidWithZero.{0} EReal EReal.instCommMonoidWithZeroEReal)))) (Real.toEReal x) n)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_pow EReal.coe_pow\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_pow (x : \u211d) (n : \u2115) : (\u2191(x ^ n) : EReal) = x ^ n :=\n  map_pow (\u27e8coe, coe_one, coe_mul\u27e9 : \u211d \u2192* EReal) _ _\n#align ereal.coe_pow EReal.coe_pow\n\n/- warning: ereal.coe_ennreal_pow -> EReal.coe_ennreal_pow is a dubious translation:\nlean 3 declaration is\n  forall (x : ENNReal) (n : Nat), Eq.{1} EReal ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) (HPow.hPow.{0, 0, 0} ENNReal Nat ENNReal (instHPow.{0, 0} ENNReal Nat (Monoid.Pow.{0} ENNReal (MonoidWithZero.toMonoid.{0} ENNReal (Semiring.toMonoidWithZero.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring))))))) x n)) (HPow.hPow.{0, 0, 0} EReal Nat EReal (instHPow.{0, 0} EReal Nat (Monoid.Pow.{0} EReal (MonoidWithZero.toMonoid.{0} EReal (CommMonoidWithZero.toMonoidWithZero.{0} EReal EReal.commMonoidWithZero)))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) ENNReal EReal (HasLiftT.mk.{1, 1} ENNReal EReal (CoeTC\u2093.coe.{1, 1} ENNReal EReal (coeBase.{1, 1} ENNReal EReal EReal.hasCoeENNReal))) x) n)\nbut is expected to have type\n  forall (x : ENNReal) (n : Nat), Eq.{1} EReal (ENNReal.toEReal (HPow.hPow.{0, 0, 0} ENNReal Nat ENNReal (instHPow.{0, 0} ENNReal Nat (Monoid.Pow.{0} ENNReal (MonoidWithZero.toMonoid.{0} ENNReal (Semiring.toMonoidWithZero.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal))))))) x n)) (HPow.hPow.{0, 0, 0} EReal Nat EReal (instHPow.{0, 0} EReal Nat (Monoid.Pow.{0} EReal (MonoidWithZero.toMonoid.{0} EReal (CommMonoidWithZero.toMonoidWithZero.{0} EReal EReal.instCommMonoidWithZeroEReal)))) (ENNReal.toEReal x) n)\nCase conversion may be inaccurate. Consider using '#align ereal.coe_ennreal_pow EReal.coe_ennreal_pow\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_ennreal_pow (x : \u211d\u22650\u221e) (n : \u2115) : (\u2191(x ^ n) : EReal) = x ^ n :=\n  map_pow (\u27e8coe, coe_ennreal_one, coe_ennreal_mul\u27e9 : \u211d\u22650\u221e \u2192* EReal) _ _\n#align ereal.coe_ennreal_pow EReal.coe_ennreal_pow\n\nend EReal\n\nnamespace Tactic\n\nopen Positivity\n\nprivate theorem ereal_coe_ne_zero {r : \u211d} : r \u2260 0 \u2192 (r : EReal) \u2260 0 :=\n  EReal.coe_ne_zero.2\n#align tactic.ereal_coe_ne_zero tactic.ereal_coe_ne_zero\n\nprivate theorem ereal_coe_nonneg {r : \u211d} : 0 \u2264 r \u2192 0 \u2264 (r : EReal) :=\n  EReal.coe_nonneg.2\n#align tactic.ereal_coe_nonneg tactic.ereal_coe_nonneg\n\nprivate theorem ereal_coe_pos {r : \u211d} : 0 < r \u2192 0 < (r : EReal) :=\n  EReal.coe_pos.2\n#align tactic.ereal_coe_pos tactic.ereal_coe_pos\n\nprivate theorem ereal_coe_ennreal_pos {r : \u211d\u22650\u221e} : 0 < r \u2192 0 < (r : EReal) :=\n  EReal.coe_ennreal_pos.2\n#align tactic.ereal_coe_ennreal_pos tactic.ereal_coe_ennreal_pos\n\n/-- Extension for the `positivity` tactic: cast from `\u211d` to `ereal`. -/\n@[positivity]\nunsafe def positivity_coe_real_ereal : expr \u2192 tactic strictness\n  | q(@coe _ _ $(inst) $(a)) => do\n    unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoe)\n    let strictness_a \u2190 core a\n    match strictness_a with\n      | positive p => positive <$> mk_app `` ereal_coe_pos [p]\n      | nonnegative p => nonnegative <$> mk_mapp `` ereal_coe_nonneg [a, p]\n      | nonzero p => nonzero <$> mk_mapp `` ereal_coe_ne_zero [a, p]\n  | e =>\n    pp e >>= fail \u2218 format.bracket \"The expression \" \" is not of the form `(r : ereal)` for `r : \u211d`\"\n#align tactic.positivity_coe_real_ereal tactic.positivity_coe_real_ereal\n\n/-- Extension for the `positivity` tactic: cast from `\u211d\u22650\u221e` to `ereal`. -/\n@[positivity]\nunsafe def positivity_coe_ennreal_ereal : expr \u2192 tactic strictness\n  | q(@coe _ _ $(inst) $(a)) => do\n    unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoeENNReal)\n    let strictness_a \u2190 core a\n    match strictness_a with\n      | positive p => positive <$> mk_app `` ereal_coe_ennreal_pos [p]\n      | _ => nonnegative <$> mk_mapp `ereal.coe_ennreal_nonneg [a]\n  | e =>\n    pp e >>=\n      fail \u2218 format.bracket \"The expression \" \" is not of the form `(r : ereal)` for `r : \u211d\u22650\u221e`\"\n#align tactic.positivity_coe_ennreal_ereal tactic.positivity_coe_ennreal_ereal\n\nend Tactic\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Real/Ereal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7117925362469094}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport analysis.convex.topology\nimport topology.basic\nimport order.directed\n\n\nvariables {E : Type*} [add_comm_group E] [module \u211d E] {s X Y : set E}\n\nopen set\n\n--will be proven from the stuff about closure operators\nlemma convex_hull_convex_hull_union :\n  convex_hull (convex_hull X \u222a Y) = convex_hull (X \u222a Y) :=\nsubset.antisymm (convex_hull_min (union_subset (convex_hull_mono (subset_union_left X Y))\n  (subset.trans (subset_convex_hull Y) (convex_hull_mono (subset_union_right X Y))))\n  (convex_convex_hull _)) (convex_hull_mono (union_subset_union_left _ (subset_convex_hull _)))\n\n--will be proven from the stuff about closure operators\nlemma convex_hull_self_union_convex_hull :\n  convex_hull (X \u222a convex_hull Y) = convex_hull (X \u222a Y) :=\nbegin\n  rw [union_comm, union_comm X Y],\n  exact convex_hull_convex_hull_union,\nend\n\nlemma eq_left_or_right_or_mem_open_segment_of_mem_segment {x y z : E} (hz : z \u2208 segment x y) :\n  z = x \u2228 z = y \u2228 z \u2208 open_segment x y :=\nbegin\n   obtain \u27e8a, b, ha, hb, hab, hz\u27e9 := hz,\n  by_cases ha' : a = 0,\n  swap,\n  by_cases hb' : b = 0,\n  swap,\n  { right, right, exact \u27e8a, b, ha.lt_of_ne (ne.symm ha'), hb.lt_of_ne (ne.symm hb'), hab, hz\u27e9 },\n  all_goals { simp only [*, add_zero, not_not, one_smul, zero_smul, zero_add, rfl] at *},\n  { left,\n    refl },\n  right,\n  left,\n  refl,\nend\n\nlemma convex_hull_pair {a b : E} :\n  convex_hull {a, b} = (segment a b) := sorry\n\n--TODO: Generalise to LCTVS\nvariables [normed_group E] [normed_space \u211d E] {x : E} {A B : set E}\n", "meta": {"author": "mmasdeu", "repo": "brouwerfixedpoint", "sha": "548270f79ecf12d7e20a256806ccb9fcf57b87e2", "save_path": "github-repos/lean/mmasdeu-brouwerfixedpoint", "path": "github-repos/lean/mmasdeu-brouwerfixedpoint/brouwerfixedpoint-548270f79ecf12d7e20a256806ccb9fcf57b87e2/src/combinatorics/simplicial_complex/to_move/convex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7117925341525965}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n\nDefines bounded lattice type class hierarchy.\n\nIncludes the Prop and fun instances.\n-/\nimport order.lattice\nimport data.option.basic\nimport tactic.pi_instances\nimport logic.nontrivial\n\nset_option old_structure_cmd true\n\nuniverses u v\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\n\n/-- Typeclass for the `\u22a4` (`\\top`) notation -/\nclass has_top (\u03b1 : Type u) := (top : \u03b1)\n/-- Typeclass for the `\u22a5` (`\\bot`) notation -/\nclass has_bot (\u03b1 : Type u) := (bot : \u03b1)\n\nnotation `\u22a4` := has_top.top\nnotation `\u22a5` := has_bot.bot\n\nattribute [pattern] has_bot.bot has_top.top\n\n/-- An `order_top` is a partial order with a greatest element.\n  (We could state this on preorders, but then it wouldn't be unique\n  so distinguishing one would seem odd.) -/\nclass order_top (\u03b1 : Type u) extends has_top \u03b1, partial_order \u03b1 :=\n(le_top : \u2200 a : \u03b1, a \u2264 \u22a4)\n\nsection order_top\nvariables [order_top \u03b1] {a b : \u03b1}\n\n@[simp] theorem le_top : a \u2264 \u22a4 :=\norder_top.le_top a\n\ntheorem top_unique (h : \u22a4 \u2264 a) : a = \u22a4 :=\nle_antisymm le_top h\n\n-- TODO: delete in favor of the next?\ntheorem eq_top_iff : a = \u22a4 \u2194 \u22a4 \u2264 a :=\n\u27e8assume eq, eq.symm \u25b8 le_refl \u22a4, top_unique\u27e9\n\n@[simp] theorem top_le_iff : \u22a4 \u2264 a \u2194 a = \u22a4 :=\n\u27e8top_unique, \u03bb h, h.symm \u25b8 le_refl \u22a4\u27e9\n\n@[simp] theorem not_top_lt : \u00ac \u22a4 < a :=\nassume h, lt_irrefl a (lt_of_le_of_lt le_top h)\n\ntheorem eq_top_mono (h : a \u2264 b) (h\u2082 : a = \u22a4) : b = \u22a4 :=\ntop_le_iff.1 $ h\u2082 \u25b8 h\n\nlemma lt_top_iff_ne_top : a < \u22a4 \u2194 a \u2260 \u22a4 :=\nbegin\n  haveI := classical.dec_eq \u03b1,\n  haveI : decidable (\u22a4 \u2264 a) := decidable_of_iff' _ top_le_iff,\n  by simp [-top_le_iff, lt_iff_le_not_le, not_iff_not.2 (@top_le_iff _ _ a)]\nend\n\nlemma ne_top_of_lt (h : a < b) : a \u2260 \u22a4 :=\nlt_top_iff_ne_top.1 $ lt_of_lt_of_le h le_top\n\ntheorem ne_top_of_le_ne_top {a b : \u03b1} (hb : b \u2260 \u22a4) (hab : a \u2264 b) : a \u2260 \u22a4 :=\nassume ha, hb $ top_unique $ ha \u25b8 hab\n\nlemma eq_top_of_maximal (h : \u2200 b, \u00ac a < b) : a = \u22a4 :=\nor.elim (lt_or_eq_of_le le_top) (\u03bb hlt, absurd hlt (h \u22a4)) (\u03bb he, he)\n\nend order_top\n\nlemma strict_mono.top_preimage_top' [linear_order \u03b1] [order_top \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (H : strict_mono f) {a} (h_top : f a = \u22a4) (x : \u03b1) :\n  x \u2264 a :=\nH.top_preimage_top (\u03bb p, by { rw h_top, exact le_top }) x\n\ntheorem order_top.ext_top {\u03b1} {A B : order_top \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) :\n  (by haveI := A; exact \u22a4 : \u03b1) = \u22a4 :=\ntop_unique $ by rw \u2190 H; apply le_top\n\ntheorem order_top.ext {\u03b1} {A B : order_top \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nbegin\n  have := partial_order.ext H,\n  have tt := order_top.ext_top H,\n  casesI A, casesI B,\n  injection this; congr'\nend\n\n/-- An `order_bot` is a partial order with a least element.\n  (We could state this on preorders, but then it wouldn't be unique\n  so distinguishing one would seem odd.) -/\nclass order_bot (\u03b1 : Type u) extends has_bot \u03b1, partial_order \u03b1 :=\n(bot_le : \u2200 a : \u03b1, \u22a5 \u2264 a)\n\nsection order_bot\nvariables [order_bot \u03b1] {a b : \u03b1}\n\n@[simp] theorem bot_le : \u22a5 \u2264 a := order_bot.bot_le a\n\ntheorem bot_unique (h : a \u2264 \u22a5) : a = \u22a5 :=\nle_antisymm h bot_le\n\n-- TODO: delete?\ntheorem eq_bot_iff : a = \u22a5 \u2194 a \u2264 \u22a5 :=\n\u27e8assume eq, eq.symm \u25b8 le_refl \u22a5, bot_unique\u27e9\n\n@[simp] theorem le_bot_iff : a \u2264 \u22a5 \u2194 a = \u22a5 :=\n\u27e8bot_unique, assume h, h.symm \u25b8 le_refl \u22a5\u27e9\n\n@[simp] theorem not_lt_bot : \u00ac a < \u22a5 :=\nassume h, lt_irrefl a (lt_of_lt_of_le h bot_le)\n\ntheorem ne_bot_of_le_ne_bot {a b : \u03b1} (hb : b \u2260 \u22a5) (hab : b \u2264 a) : a \u2260 \u22a5 :=\nassume ha, hb $ bot_unique $ ha \u25b8 hab\n\ntheorem eq_bot_mono (h : a \u2264 b) (h\u2082 : b = \u22a5) : a = \u22a5 :=\nle_bot_iff.1 $ h\u2082 \u25b8 h\n\nlemma bot_lt_iff_ne_bot : \u22a5 < a \u2194 a \u2260 \u22a5 :=\nbegin\n  haveI := classical.dec_eq \u03b1,\n  haveI : decidable (a \u2264 \u22a5) := decidable_of_iff' _ le_bot_iff,\n  simp [-le_bot_iff, lt_iff_le_not_le, not_iff_not.2 (@le_bot_iff _ _ a)]\nend\n\nlemma ne_bot_of_gt (h : a < b) : b \u2260 \u22a5 :=\nbot_lt_iff_ne_bot.1 $ lt_of_le_of_lt bot_le h\n\nlemma eq_bot_of_minimal (h : \u2200 b, \u00ac b < a) : a = \u22a5 :=\nor.elim (lt_or_eq_of_le bot_le) (\u03bb hlt, absurd hlt (h \u22a5)) (\u03bb he, he.symm)\n\nend order_bot\n\nlemma strict_mono.bot_preimage_bot' [linear_order \u03b1] [order_bot \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (H : strict_mono f) {a} (h_bot : f a = \u22a5) (x : \u03b1) :\n  a \u2264 x :=\nH.bot_preimage_bot (\u03bb p, by { rw h_bot, exact bot_le }) x\n\ntheorem order_bot.ext_bot {\u03b1} {A B : order_bot \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) :\n  (by haveI := A; exact \u22a5 : \u03b1) = \u22a5 :=\nbot_unique $ by rw \u2190 H; apply bot_le\n\ntheorem order_bot.ext {\u03b1} {A B : order_bot \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nbegin\n  have := partial_order.ext H,\n  have tt := order_bot.ext_bot H,\n  casesI A, casesI B,\n  injection this; congr'\nend\n\n/-- A `semilattice_sup_top` is a semilattice with top and join. -/\nclass semilattice_sup_top (\u03b1 : Type u) extends order_top \u03b1, semilattice_sup \u03b1\n\nsection semilattice_sup_top\nvariables [semilattice_sup_top \u03b1] {a : \u03b1}\n\n@[simp] theorem top_sup_eq : \u22a4 \u2294 a = \u22a4 :=\nsup_of_le_left le_top\n\n@[simp] theorem sup_top_eq : a \u2294 \u22a4 = \u22a4 :=\nsup_of_le_right le_top\n\nend semilattice_sup_top\n\n/-- A `semilattice_sup_bot` is a semilattice with bottom and join. -/\nclass semilattice_sup_bot (\u03b1 : Type u) extends order_bot \u03b1, semilattice_sup \u03b1\n\nsection semilattice_sup_bot\nvariables [semilattice_sup_bot \u03b1] {a b : \u03b1}\n\n@[simp] theorem bot_sup_eq : \u22a5 \u2294 a = a :=\nsup_of_le_right bot_le\n\n@[simp] theorem sup_bot_eq : a \u2294 \u22a5 = a :=\nsup_of_le_left bot_le\n\n@[simp] theorem sup_eq_bot_iff : a \u2294 b = \u22a5 \u2194 (a = \u22a5 \u2227 b = \u22a5) :=\nby rw [eq_bot_iff, sup_le_iff]; simp\n\nend semilattice_sup_bot\n\ninstance nat.semilattice_sup_bot : semilattice_sup_bot \u2115 :=\n{ bot := 0, bot_le := nat.zero_le, .. nat.distrib_lattice }\n\n/-- A `semilattice_inf_top` is a semilattice with top and meet. -/\nclass semilattice_inf_top (\u03b1 : Type u) extends order_top \u03b1, semilattice_inf \u03b1\n\nsection semilattice_inf_top\nvariables [semilattice_inf_top \u03b1] {a b : \u03b1}\n\n@[simp] theorem top_inf_eq : \u22a4 \u2293 a = a :=\ninf_of_le_right le_top\n\n@[simp] theorem inf_top_eq : a \u2293 \u22a4 = a :=\ninf_of_le_left le_top\n\n@[simp] theorem inf_eq_top_iff : a \u2293 b = \u22a4 \u2194 (a = \u22a4 \u2227 b = \u22a4) :=\nby rw [eq_top_iff, le_inf_iff]; simp\n\nend semilattice_inf_top\n\n/-- A `semilattice_inf_bot` is a semilattice with bottom and meet. -/\nclass semilattice_inf_bot (\u03b1 : Type u) extends order_bot \u03b1, semilattice_inf \u03b1\n\nsection semilattice_inf_bot\nvariables [semilattice_inf_bot \u03b1] {a : \u03b1}\n\n@[simp] theorem bot_inf_eq : \u22a5 \u2293 a = \u22a5 :=\ninf_of_le_left bot_le\n\n@[simp] theorem inf_bot_eq : a \u2293 \u22a5 = \u22a5 :=\ninf_of_le_right bot_le\n\nend semilattice_inf_bot\n\n/- Bounded lattices -/\n\n/-- A bounded lattice is a lattice with a top and bottom element,\n  denoted `\u22a4` and `\u22a5` respectively. This allows for the interpretation\n  of all finite suprema and infima, taking `inf \u2205 = \u22a4` and `sup \u2205 = \u22a5`. -/\nclass bounded_lattice (\u03b1 : Type u) extends lattice \u03b1, order_top \u03b1, order_bot \u03b1\n\n@[priority 100] -- see Note [lower instance priority]\ninstance semilattice_inf_top_of_bounded_lattice (\u03b1 : Type u) [bl : bounded_lattice \u03b1] :\n  semilattice_inf_top \u03b1 :=\n{ le_top := assume x, @le_top \u03b1 _ x, ..bl }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance semilattice_inf_bot_of_bounded_lattice (\u03b1 : Type u) [bl : bounded_lattice \u03b1] :\n  semilattice_inf_bot \u03b1 :=\n{ bot_le := assume x, @bot_le \u03b1 _ x, ..bl }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance semilattice_sup_top_of_bounded_lattice (\u03b1 : Type u) [bl : bounded_lattice \u03b1] :\n  semilattice_sup_top \u03b1 :=\n{ le_top := assume x, @le_top \u03b1 _ x, ..bl }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance semilattice_sup_bot_of_bounded_lattice (\u03b1 : Type u) [bl : bounded_lattice \u03b1] :\n  semilattice_sup_bot \u03b1 :=\n{ bot_le := assume x, @bot_le \u03b1 _ x, ..bl }\n\ntheorem bounded_lattice.ext {\u03b1} {A B : bounded_lattice \u03b1}\n  (H : \u2200 x y : \u03b1, (by haveI := A; exact x \u2264 y) \u2194 x \u2264 y) : A = B :=\nbegin\n  have H1 : @bounded_lattice.to_lattice \u03b1 A =\n             @bounded_lattice.to_lattice \u03b1 B := lattice.ext H,\n  have H2 := order_bot.ext H,\n  have H3 : @bounded_lattice.to_order_top \u03b1 A =\n             @bounded_lattice.to_order_top \u03b1 B := order_top.ext H,\n  have tt := order_bot.ext_bot H,\n  casesI A, casesI B,\n  injection H1; injection H2; injection H3; congr'\nend\n\n/-- A bounded distributive lattice is exactly what it sounds like. -/\nclass bounded_distrib_lattice \u03b1 extends distrib_lattice \u03b1, bounded_lattice \u03b1\n\nlemma inf_eq_bot_iff_le_compl {\u03b1 : Type u} [bounded_distrib_lattice \u03b1] {a b c : \u03b1}\n  (h\u2081 : b \u2294 c = \u22a4) (h\u2082 : b \u2293 c = \u22a5) : a \u2293 b = \u22a5 \u2194 a \u2264 c :=\n\u27e8assume : a \u2293 b = \u22a5,\n  calc a \u2264 a \u2293 (b \u2294 c) : by simp [h\u2081]\n    ... = (a \u2293 b) \u2294 (a \u2293 c) : by simp [inf_sup_left]\n    ... \u2264 c : by simp [this, inf_le_right],\n  assume : a \u2264 c,\n  bot_unique $\n    calc a \u2293 b \u2264 b \u2293 c : by { rw [inf_comm], exact inf_le_inf_left _ this }\n      ... = \u22a5 : h\u2082\u27e9\n\n/- Prop instance -/\ninstance bounded_distrib_lattice_Prop : bounded_distrib_lattice Prop :=\n{ le           := \u03bba b, a \u2192 b,\n  le_refl      := assume _, id,\n  le_trans     := assume a b c f g, g \u2218 f,\n  le_antisymm  := assume a b Hab Hba, propext \u27e8Hab, Hba\u27e9,\n\n  sup          := or,\n  le_sup_left  := @or.inl,\n  le_sup_right := @or.inr,\n  sup_le       := assume a b c, or.rec,\n\n  inf          := and,\n  inf_le_left  := @and.left,\n  inf_le_right := @and.right,\n  le_inf       := assume a b c Hab Hac Ha, and.intro (Hab Ha) (Hac Ha),\n  le_sup_inf   := assume a b c H, or_iff_not_imp_left.2 $\n    \u03bb Ha, \u27e8H.1.resolve_left Ha, H.2.resolve_left Ha\u27e9,\n\n  top          := true,\n  le_top       := assume a Ha, true.intro,\n\n  bot          := false,\n  bot_le       := @false.elim }\n\nnoncomputable instance Prop.linear_order : linear_order Prop :=\n{ le_total := by intros p q; change (p \u2192 q) \u2228 (q \u2192 p); tauto!,\n  decidable_le := classical.dec_rel _,\n  .. (_ : partial_order Prop) }\n\n@[simp]\nlemma le_iff_imp {p q : Prop} : p \u2264 q \u2194 (p \u2192 q) := iff.rfl\n\nsection logic\nvariable [preorder \u03b1]\n\ntheorem monotone_and {p q : \u03b1 \u2192 Prop} (m_p : monotone p) (m_q : monotone q) :\n  monotone (\u03bbx, p x \u2227 q x) :=\nassume a b h, and.imp (m_p h) (m_q h)\n-- Note: by finish [monotone] doesn't work\n\ntheorem monotone_or {p q : \u03b1 \u2192 Prop} (m_p : monotone p) (m_q : monotone q) :\n  monotone (\u03bbx, p x \u2228 q x) :=\nassume a b h, or.imp (m_p h) (m_q h)\nend logic\n\ninstance pi.order_bot {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type*} [\u2200 a, order_bot $ \u03b2 a]  : order_bot (\u03a0 a, \u03b2 a) :=\n{ bot := \u03bb _, \u22a5,\n  bot_le := \u03bb x a, bot_le,\n  .. pi.partial_order }\n\n/- Function lattices -/\n\ninstance pi.has_sup {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_sup (\u03b1 i)] : has_sup (\u03a0 i, \u03b1 i) :=\n\u27e8\u03bb f g i, f i \u2294 g i\u27e9\n\n@[simp] lemma sup_apply {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_sup (\u03b1 i)] (f g : \u03a0 i, \u03b1 i) (i : \u03b9) :\n  (f \u2294 g) i = f i \u2294 g i :=\nrfl\n\ninstance pi.has_inf {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_inf (\u03b1 i)] : has_inf (\u03a0 i, \u03b1 i) :=\n\u27e8\u03bb f g i, f i \u2293 g i\u27e9\n\n@[simp] lemma inf_apply {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_inf (\u03b1 i)] (f g : \u03a0 i, \u03b1 i) (i : \u03b9) :\n  (f \u2293 g) i = f i \u2293 g i :=\nrfl\n\ninstance pi.has_bot {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_bot (\u03b1 i)] : has_bot (\u03a0 i, \u03b1 i) :=\n\u27e8\u03bb i, \u22a5\u27e9\n\n@[simp] lemma bot_apply {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_bot (\u03b1 i)] (i : \u03b9) :\n  (\u22a5 : \u03a0 i, \u03b1 i) i = \u22a5 :=\nrfl\n\ninstance pi.has_top {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_top (\u03b1 i)] : has_top (\u03a0 i, \u03b1 i) :=\n\u27e8\u03bb i, \u22a4\u27e9\n\n@[simp] lemma top_apply {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, has_top (\u03b1 i)] (i : \u03b9) :\n  (\u22a4 : \u03a0 i, \u03b1 i) i = \u22a4 :=\nrfl\n\ninstance pi.semilattice_sup {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, semilattice_sup (\u03b1 i)] :\n  semilattice_sup (\u03a0 i, \u03b1 i) :=\nby refine_struct { sup := (\u2294), .. pi.partial_order }; tactic.pi_instance_derive_field\n\ninstance pi.semilattice_inf {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, semilattice_inf (\u03b1 i)] :\n  semilattice_inf (\u03a0 i, \u03b1 i) :=\nby refine_struct { inf := (\u2293), .. pi.partial_order }; tactic.pi_instance_derive_field\n\ninstance pi.semilattice_inf_bot {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, semilattice_inf_bot (\u03b1 i)] :\n  semilattice_inf_bot (\u03a0 i, \u03b1 i) :=\nby refine_struct { inf := (\u2293), bot := \u22a5, .. pi.partial_order }; tactic.pi_instance_derive_field\n\ninstance pi.semilattice_inf_top {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, semilattice_inf_top (\u03b1 i)] :\n  semilattice_inf_top (\u03a0 i, \u03b1 i) :=\nby refine_struct { inf := (\u2293), top := \u22a4, .. pi.partial_order }; tactic.pi_instance_derive_field\n\ninstance pi.semilattice_sup_bot {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, semilattice_sup_bot (\u03b1 i)] :\n  semilattice_sup_bot (\u03a0 i, \u03b1 i) :=\nby refine_struct { sup := (\u2294), bot := \u22a5, .. pi.partial_order }; tactic.pi_instance_derive_field\n\ninstance pi.semilattice_sup_top {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, semilattice_sup_top (\u03b1 i)] :\n  semilattice_sup_top (\u03a0 i, \u03b1 i) :=\nby refine_struct { sup := (\u2294), top := \u22a4, .. pi.partial_order }; tactic.pi_instance_derive_field\n\ninstance pi.lattice {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, lattice (\u03b1 i)] : lattice (\u03a0 i, \u03b1 i) :=\n{ .. pi.semilattice_sup, .. pi.semilattice_inf }\n\ninstance pi.bounded_lattice {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0 i, bounded_lattice (\u03b1 i)] :\n  bounded_lattice (\u03a0 i, \u03b1 i) :=\n{ .. pi.semilattice_sup_top, .. pi.semilattice_inf_bot }\n\nlemma eq_bot_of_bot_eq_top {\u03b1 : Type*} [bounded_lattice \u03b1] (h\u03b1 : (\u22a5 : \u03b1) = \u22a4) (x : \u03b1) :\n  x = (\u22a5 : \u03b1) :=\neq_bot_mono le_top (eq.symm h\u03b1)\n\nlemma eq_top_of_bot_eq_top {\u03b1 : Type*} [bounded_lattice \u03b1] (h\u03b1 : (\u22a5 : \u03b1) = \u22a4) (x : \u03b1) :\n  x = (\u22a4 : \u03b1) :=\neq_top_mono bot_le h\u03b1\n\nlemma subsingleton_of_top_le_bot {\u03b1 : Type*} [bounded_lattice \u03b1] (h : (\u22a4 : \u03b1) \u2264 (\u22a5 : \u03b1)) :\n  subsingleton \u03b1 :=\n\u27e8\u03bb a b, le_antisymm (le_trans le_top $ le_trans h bot_le) (le_trans le_top $ le_trans h bot_le)\u27e9\n\nlemma subsingleton_of_bot_eq_top {\u03b1 : Type*} [bounded_lattice \u03b1] (h\u03b1 : (\u22a5 : \u03b1) = (\u22a4 : \u03b1)) :\n  subsingleton \u03b1 :=\nsubsingleton_of_top_le_bot (ge_of_eq h\u03b1)\n\nlemma subsingleton_iff_bot_eq_top {\u03b1 : Type*} [bounded_lattice \u03b1] :\n  (\u22a5 : \u03b1) = (\u22a4 : \u03b1) \u2194 subsingleton \u03b1 :=\n\u27e8subsingleton_of_bot_eq_top, \u03bb h, by exactI subsingleton.elim \u22a5 \u22a4\u27e9\n\n/-- Attach `\u22a5` to a type. -/\ndef with_bot (\u03b1 : Type*) := option \u03b1\n\nnamespace with_bot\n\nmeta instance {\u03b1} [has_to_format \u03b1] : has_to_format (with_bot \u03b1) :=\n{ to_format := \u03bb x,\n  match x with\n  | none := \"\u22a5\"\n  | (some x) := to_fmt x\n  end }\n\ninstance : has_coe_t \u03b1 (with_bot \u03b1) := \u27e8some\u27e9\ninstance has_bot : has_bot (with_bot \u03b1) := \u27e8none\u27e9\n\ninstance : inhabited (with_bot \u03b1) := \u27e8\u22a5\u27e9\n\nlemma none_eq_bot : (none : with_bot \u03b1) = (\u22a5 : with_bot \u03b1) := rfl\nlemma some_eq_coe (a : \u03b1) : (some a : with_bot \u03b1) = (\u2191a : with_bot \u03b1) := rfl\n\n/-- Recursor for `with_bot` using the preferred forms `\u22a5` and `\u2191a`. -/\n@[elab_as_eliminator]\ndef rec_bot_coe {C : with_bot \u03b1 \u2192 Sort*} (h\u2081 : C \u22a5) (h\u2082 : \u03a0 (a : \u03b1), C a) :\n  \u03a0 (n : with_bot \u03b1), C n :=\noption.rec h\u2081 h\u2082\n\n@[norm_cast]\ntheorem coe_eq_coe {a b : \u03b1} : (a : with_bot \u03b1) = b \u2194 a = b :=\nby rw [\u2190 option.some.inj_eq a b]; refl\n\n@[priority 10]\ninstance has_lt [has_lt \u03b1] : has_lt (with_bot \u03b1) :=\n{ lt := \u03bb o\u2081 o\u2082 : option \u03b1, \u2203 b \u2208 o\u2082, \u2200 a \u2208 o\u2081, a < b }\n\n@[simp] theorem some_lt_some [has_lt \u03b1] {a b : \u03b1} :\n  @has_lt.lt (with_bot \u03b1) _ (some a) (some b) \u2194 a < b :=\nby simp [(<)]\n\nlemma bot_lt_some [has_lt \u03b1] (a : \u03b1) : (\u22a5 : with_bot \u03b1) < some a :=\n\u27e8a, rfl, \u03bb b hb, (option.not_mem_none _ hb).elim\u27e9\n\nlemma bot_lt_coe [has_lt \u03b1] (a : \u03b1) : (\u22a5 : with_bot \u03b1) < a := bot_lt_some a\n\ninstance [preorder \u03b1] : preorder (with_bot \u03b1) :=\n{ le          := \u03bb o\u2081 o\u2082 : option \u03b1, \u2200 a \u2208 o\u2081, \u2203 b \u2208 o\u2082, a \u2264 b,\n  lt          := (<),\n  lt_iff_le_not_le := by intros; cases a; cases b;\n                         simp [lt_iff_le_not_le]; simp [(<)];\n                         split; refl,\n  le_refl     := \u03bb o a ha, \u27e8a, ha, le_refl _\u27e9,\n  le_trans    := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha,\n    let \u27e8b, hb, ab\u27e9 := h\u2081 a ha, \u27e8c, hc, bc\u27e9 := h\u2082 b hb in\n    \u27e8c, hc, le_trans ab bc\u27e9 }\n\ninstance partial_order [partial_order \u03b1] : partial_order (with_bot \u03b1) :=\n{ le_antisymm := \u03bb o\u2081 o\u2082 h\u2081 h\u2082, begin\n    cases o\u2081 with a,\n    { cases o\u2082 with b, {refl},\n      rcases h\u2082 b rfl with \u27e8_, \u27e8\u27e9, _\u27e9 },\n    { rcases h\u2081 a rfl with \u27e8b, \u27e8\u27e9, h\u2081'\u27e9,\n      rcases h\u2082 b rfl with \u27e8_, \u27e8\u27e9, h\u2082'\u27e9,\n      rw le_antisymm h\u2081' h\u2082' }\n  end,\n  .. with_bot.preorder }\n\ninstance order_bot [partial_order \u03b1] : order_bot (with_bot \u03b1) :=\n{ bot_le := \u03bb a a' h, option.no_confusion h,\n  ..with_bot.partial_order, ..with_bot.has_bot }\n\n@[simp, norm_cast] theorem coe_le_coe [preorder \u03b1] {a b : \u03b1} :\n  (a : with_bot \u03b1) \u2264 b \u2194 a \u2264 b :=\n\u27e8\u03bb h, by rcases h a rfl with \u27e8_, \u27e8\u27e9, h\u27e9; exact h,\n \u03bb h a' e, option.some_inj.1 e \u25b8 \u27e8b, rfl, h\u27e9\u27e9\n\n@[simp] theorem some_le_some [preorder \u03b1] {a b : \u03b1} :\n  @has_le.le (with_bot \u03b1) _ (some a) (some b) \u2194 a \u2264 b := coe_le_coe\n\ntheorem coe_le [partial_order \u03b1] {a b : \u03b1} :\n  \u2200 {o : option \u03b1}, b \u2208 o \u2192 ((a : with_bot \u03b1) \u2264 o \u2194 a \u2264 b)\n| _ rfl := coe_le_coe\n\n@[norm_cast]\nlemma coe_lt_coe [partial_order \u03b1] {a b : \u03b1} : (a : with_bot \u03b1) < b \u2194 a < b := some_lt_some\n\nlemma le_coe_get_or_else [preorder \u03b1] : \u2200 (a : with_bot \u03b1) (b : \u03b1), a \u2264 a.get_or_else b\n| (some a) b := le_refl a\n| none     b := \u03bb _ h, option.no_confusion h\n\n@[simp] lemma get_or_else_bot (a : \u03b1) : option.get_or_else (\u22a5 : with_bot \u03b1) a = a := rfl\n\nlemma get_or_else_bot_le_iff [order_bot \u03b1] {a : with_bot \u03b1} {b : \u03b1} :\n  a.get_or_else \u22a5 \u2264 b \u2194 a \u2264 b :=\nby cases a; simp [none_eq_bot, some_eq_coe]\n\ninstance decidable_le [preorder \u03b1] [@decidable_rel \u03b1 (\u2264)] : @decidable_rel (with_bot \u03b1) (\u2264)\n| none x := is_true $ \u03bb a h, option.no_confusion h\n| (some x) (some y) :=\n  if h : x \u2264 y\n  then is_true (some_le_some.2 h)\n  else is_false $ by simp *\n| (some x) none := is_false $ \u03bb h, by rcases h x rfl with \u27e8y, \u27e8_\u27e9, _\u27e9\n\ninstance decidable_lt [has_lt \u03b1] [@decidable_rel \u03b1 (<)] : @decidable_rel (with_bot \u03b1) (<)\n| none (some x) := is_true $ by existsi [x,rfl]; rintros _ \u27e8\u27e9\n| (some x) (some y) :=\n  if h : x < y\n  then is_true $ by simp *\n  else is_false $ by simp *\n| x none := is_false $ by rintro \u27e8a,\u27e8\u27e8\u27e9\u27e9\u27e9\n\ninstance [partial_order \u03b1] [is_total \u03b1 (\u2264)] : is_total (with_bot \u03b1) (\u2264) :=\n{ total := \u03bb a b, match a, b with\n  | none  , _      := or.inl bot_le\n  | _     , none   := or.inr bot_le\n  | some x, some y := by simp only [some_le_some, total_of]\n  end }\n\ninstance linear_order [linear_order \u03b1] : linear_order (with_bot \u03b1) :=\n{ le_total := \u03bb o\u2081 o\u2082, begin\n    cases o\u2081 with a, {exact or.inl bot_le},\n    cases o\u2082 with b, {exact or.inr bot_le},\n    simp [le_total]\n  end,\n  decidable_le := with_bot.decidable_le,\n  decidable_lt := with_bot.decidable_lt,\n  ..with_bot.partial_order }\n\ninstance semilattice_sup [semilattice_sup \u03b1] : semilattice_sup_bot (with_bot \u03b1) :=\n{ sup          := option.lift_or_get (\u2294),\n  le_sup_left  := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2082; simp [option.lift_or_get],\n  le_sup_right := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2081; simp [option.lift_or_get],\n  sup_le       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases o\u2081 with b; cases o\u2082 with c; cases ha,\n    { exact h\u2082 a rfl },\n    { exact h\u2081 a rfl },\n    { rcases h\u2081 b rfl with \u27e8d, \u27e8\u27e9, h\u2081'\u27e9,\n      simp at h\u2082,\n      exact \u27e8d, rfl, sup_le h\u2081' h\u2082\u27e9 }\n  end,\n  ..with_bot.order_bot }\n\nlemma coe_sup [semilattice_sup \u03b1] (a b : \u03b1) : ((a \u2294 b : \u03b1) : with_bot \u03b1) = a \u2294 b := rfl\n\ninstance semilattice_inf [semilattice_inf \u03b1] : semilattice_inf_bot (with_bot \u03b1) :=\n{ inf          := \u03bb o\u2081 o\u2082, o\u2081.bind (\u03bb a, o\u2082.map (\u03bb b, a \u2293 b)),\n  inf_le_left  := \u03bb o\u2081 o\u2082 a ha, begin\n    simp at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, inf_le_left\u27e9\n  end,\n  inf_le_right := \u03bb o\u2081 o\u2082 a ha, begin\n    simp at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, inf_le_right\u27e9\n  end,\n  le_inf       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases ha,\n    rcases h\u2081 a rfl with \u27e8b, \u27e8\u27e9, ab\u27e9,\n    rcases h\u2082 a rfl with \u27e8c, \u27e8\u27e9, ac\u27e9,\n    exact \u27e8_, rfl, le_inf ab ac\u27e9\n  end,\n  ..with_bot.order_bot }\n\nlemma coe_inf [semilattice_inf \u03b1] (a b : \u03b1) : ((a \u2293 b : \u03b1) : with_bot \u03b1) = a \u2293 b := rfl\n\ninstance lattice [lattice \u03b1] : lattice (with_bot \u03b1) :=\n{ ..with_bot.semilattice_sup, ..with_bot.semilattice_inf }\n\ntheorem lattice_eq_DLO [linear_order \u03b1] :\n  lattice_of_linear_order = @with_bot.lattice \u03b1 _ :=\nlattice.ext $ \u03bb x y, iff.rfl\n\ntheorem sup_eq_max [linear_order \u03b1] (x y : with_bot \u03b1) : x \u2294 y = max x y :=\nby rw [\u2190 sup_eq_max, lattice_eq_DLO]\n\ntheorem inf_eq_min [linear_order \u03b1] (x y : with_bot \u03b1) : x \u2293 y = min x y :=\nby rw [\u2190 inf_eq_min, lattice_eq_DLO]\n\n@[norm_cast] -- this is not marked simp because the corresponding with_top lemmas are used\nlemma coe_min [linear_order \u03b1] (x y : \u03b1) : ((min x y : \u03b1) : with_bot \u03b1) = min x y :=\nby simp [min, ite_cast]\n\n@[norm_cast] -- this is not marked simp because the corresponding with_top lemmas are used\nlemma coe_max [linear_order \u03b1] (x y : \u03b1) : ((max x y : \u03b1) : with_bot \u03b1) = max x y :=\nby simp [max, ite_cast]\n\ninstance order_top [order_top \u03b1] : order_top (with_bot \u03b1) :=\n{ top := some \u22a4,\n  le_top := \u03bb o a ha, by cases ha; exact \u27e8_, rfl, le_top\u27e9,\n  ..with_bot.partial_order }\n\ninstance bounded_lattice [bounded_lattice \u03b1] : bounded_lattice (with_bot \u03b1) :=\n{ ..with_bot.lattice, ..with_bot.order_top, ..with_bot.order_bot }\n\nlemma well_founded_lt [partial_order \u03b1] (h : well_founded ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop)) :\n  well_founded ((<) : with_bot \u03b1 \u2192 with_bot \u03b1 \u2192 Prop) :=\nhave acc_bot : acc ((<) : with_bot \u03b1 \u2192 with_bot \u03b1 \u2192 Prop) \u22a5 :=\n  acc.intro _ (\u03bb a ha, (not_le_of_gt ha bot_le).elim),\n\u27e8\u03bb a, option.rec_on a acc_bot (\u03bb a, acc.intro _ (\u03bb b, option.rec_on b (\u03bb _, acc_bot)\n(\u03bb b, well_founded.induction h b\n  (show \u2200 b : \u03b1, (\u2200 c, c < b \u2192 (c : with_bot \u03b1) < a \u2192\n      acc ((<) : with_bot \u03b1 \u2192 with_bot \u03b1 \u2192 Prop) c) \u2192 (b : with_bot \u03b1) < a \u2192\n        acc ((<) : with_bot \u03b1 \u2192 with_bot \u03b1 \u2192 Prop) b,\n  from \u03bb b ih hba, acc.intro _ (\u03bb c, option.rec_on c (\u03bb _, acc_bot)\n    (\u03bb c hc, ih _ (some_lt_some.1 hc) (lt_trans hc hba)))))))\u27e9\n\ninstance densely_ordered [partial_order \u03b1] [densely_ordered \u03b1] [no_bot_order \u03b1] :\n  densely_ordered (with_bot \u03b1) :=\n\u27e8 assume a b,\n  match a, b with\n  | a,      none   := assume h : a < \u22a5, (not_lt_bot h).elim\n  | none,   some b := assume h, let \u27e8a, ha\u27e9 := no_bot b in \u27e8a, bot_lt_coe a, coe_lt_coe.2 ha\u27e9\n  | some a, some b := assume h, let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between (coe_lt_coe.1 h) in\n    \u27e8a, coe_lt_coe.2 ha\u2081, coe_lt_coe.2 ha\u2082\u27e9\n  end\u27e9\n\nend with_bot\n\n--TODO(Mario): Construct using order dual on with_bot\n/-- Attach `\u22a4` to a type. -/\ndef with_top (\u03b1 : Type*) := option \u03b1\n\nnamespace with_top\n\nmeta instance {\u03b1} [has_to_format \u03b1] : has_to_format (with_top \u03b1) :=\n{ to_format := \u03bb x,\n  match x with\n  | none := \"\u22a4\"\n  | (some x) := to_fmt x\n  end }\n\ninstance : has_coe_t \u03b1 (with_top \u03b1) := \u27e8some\u27e9\ninstance has_top : has_top (with_top \u03b1) := \u27e8none\u27e9\n\ninstance : inhabited (with_top \u03b1) := \u27e8\u22a4\u27e9\n\nlemma none_eq_top : (none : with_top \u03b1) = (\u22a4 : with_top \u03b1) := rfl\nlemma some_eq_coe (a : \u03b1) : (some a : with_top \u03b1) = (\u2191a : with_top \u03b1) := rfl\n\n/-- Recursor for `with_top` using the preferred forms `\u22a4` and `\u2191a`. -/\n@[elab_as_eliminator]\ndef rec_top_coe {C : with_top \u03b1 \u2192 Sort*} (h\u2081 : C \u22a4) (h\u2082 : \u03a0 (a : \u03b1), C a) :\n  \u03a0 (n : with_top \u03b1), C n :=\noption.rec h\u2081 h\u2082\n\n@[norm_cast]\ntheorem coe_eq_coe {a b : \u03b1} : (a : with_top \u03b1) = b \u2194 a = b :=\nby rw [\u2190 option.some.inj_eq a b]; refl\n\n@[simp] theorem top_ne_coe {a : \u03b1} : \u22a4 \u2260 (a : with_top \u03b1) .\n@[simp] theorem coe_ne_top {a : \u03b1} : (a : with_top \u03b1) \u2260 \u22a4 .\n\n@[priority 10]\ninstance has_lt [has_lt \u03b1] : has_lt (with_top \u03b1) :=\n{ lt := \u03bb o\u2081 o\u2082 : option \u03b1, \u2203 b \u2208 o\u2081, \u2200 a \u2208 o\u2082, b < a }\n\n@[priority 10]\ninstance has_le [has_le \u03b1] : has_le (with_top \u03b1) :=\n{ le          := \u03bb o\u2081 o\u2082 : option \u03b1, \u2200 a \u2208 o\u2082, \u2203 b \u2208 o\u2081, b \u2264 a }\n\n@[simp] theorem some_lt_some [has_lt \u03b1] {a b : \u03b1} :\n  @has_lt.lt (with_top \u03b1) _ (some a) (some b) \u2194 a < b :=\nby simp [(<)]\n\n@[simp] theorem some_le_some [has_le \u03b1] {a b : \u03b1} :\n  @has_le.le (with_top \u03b1) _ (some a) (some b) \u2194 a \u2264 b :=\nby simp [(\u2264)]\n\n@[simp] theorem le_none [has_le \u03b1] {a : with_top \u03b1} :\n  @has_le.le (with_top \u03b1) _ a none :=\nby simp [(\u2264)]\n\n@[simp] theorem some_lt_none [has_lt \u03b1] {a : \u03b1} :\n  @has_lt.lt (with_top \u03b1) _ (some a) none :=\nby simp [(<)]; existsi a; refl\n\ninstance : can_lift (with_top \u03b1) \u03b1 :=\n{ coe := coe,\n  cond := \u03bb r, r \u2260 \u22a4,\n  prf := \u03bb x hx, \u27e8option.get $ option.ne_none_iff_is_some.1 hx, option.some_get _\u27e9 }\n\ninstance [preorder \u03b1] : preorder (with_top \u03b1) :=\n{ le          := \u03bb o\u2081 o\u2082 : option \u03b1, \u2200 a \u2208 o\u2082, \u2203 b \u2208 o\u2081, b \u2264 a,\n  lt          := (<),\n  lt_iff_le_not_le := by { intros; cases a; cases b;\n                           simp [lt_iff_le_not_le]; simp [(<),(\u2264)] },\n  le_refl     := \u03bb o a ha, \u27e8a, ha, le_refl _\u27e9,\n  le_trans    := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 c hc,\n    let \u27e8b, hb, bc\u27e9 := h\u2082 c hc, \u27e8a, ha, ab\u27e9 := h\u2081 b hb in\n    \u27e8a, ha, le_trans ab bc\u27e9,\n }\n\ninstance partial_order [partial_order \u03b1] : partial_order (with_top \u03b1) :=\n{ le_antisymm := \u03bb o\u2081 o\u2082 h\u2081 h\u2082, begin\n    cases o\u2082 with b,\n    { cases o\u2081 with a, {refl},\n      rcases h\u2082 a rfl with \u27e8_, \u27e8\u27e9, _\u27e9 },\n    { rcases h\u2081 b rfl with \u27e8a, \u27e8\u27e9, h\u2081'\u27e9,\n      rcases h\u2082 a rfl with \u27e8_, \u27e8\u27e9, h\u2082'\u27e9,\n      rw le_antisymm h\u2081' h\u2082' }\n  end,\n  .. with_top.preorder }\n\ninstance order_top [partial_order \u03b1] : order_top (with_top \u03b1) :=\n{ le_top := \u03bb a a' h, option.no_confusion h,\n  ..with_top.partial_order, .. with_top.has_top }\n\n@[simp, norm_cast] theorem coe_le_coe [partial_order \u03b1] {a b : \u03b1} :\n  (a : with_top \u03b1) \u2264 b \u2194 a \u2264 b :=\n\u27e8\u03bb h, by rcases h b rfl with \u27e8_, \u27e8\u27e9, h\u27e9; exact h,\n \u03bb h a' e, option.some_inj.1 e \u25b8 \u27e8a, rfl, h\u27e9\u27e9\n\ntheorem le_coe [partial_order \u03b1] {a b : \u03b1} :\n  \u2200 {o : option \u03b1}, a \u2208 o \u2192\n  (@has_le.le (with_top \u03b1) _ o b \u2194 a \u2264 b)\n| _ rfl := coe_le_coe\n\ntheorem le_coe_iff [partial_order \u03b1] {b : \u03b1} : \u2200{x : with_top \u03b1}, x \u2264 b \u2194 (\u2203a:\u03b1, x = a \u2227 a \u2264 b)\n| (some a) := by simp [some_eq_coe, coe_eq_coe]\n| none     := by simp [none_eq_top]\n\ntheorem coe_le_iff [partial_order \u03b1] {a : \u03b1} : \u2200{x : with_top \u03b1}, \u2191a \u2264 x \u2194 (\u2200b:\u03b1, x = \u2191b \u2192 a \u2264 b)\n| (some b) := by simp [some_eq_coe, coe_eq_coe]\n| none     := by simp [none_eq_top]\n\ntheorem lt_iff_exists_coe [partial_order \u03b1] : \u2200{a b : with_top \u03b1}, a < b \u2194 (\u2203p:\u03b1, a = p \u2227 \u2191p < b)\n| (some a) b := by simp [some_eq_coe, coe_eq_coe]\n| none     b := by simp [none_eq_top]\n\n@[norm_cast]\nlemma coe_lt_coe [partial_order \u03b1] {a b : \u03b1} : (a : with_top \u03b1) < b \u2194 a < b := some_lt_some\n\nlemma coe_lt_top [partial_order \u03b1] (a : \u03b1) : (a : with_top \u03b1) < \u22a4 := some_lt_none\n\ntheorem coe_lt_iff [partial_order \u03b1] {a : \u03b1} : \u2200{x : with_top \u03b1}, \u2191a < x \u2194 (\u2200b:\u03b1, x = \u2191b \u2192 a < b)\n| (some b) := by simp [some_eq_coe, coe_eq_coe, coe_lt_coe]\n| none     := by simp [none_eq_top, coe_lt_top]\n\nlemma not_top_le_coe [partial_order \u03b1] (a : \u03b1) : \u00ac (\u22a4:with_top \u03b1) \u2264 \u2191a :=\nassume h, (lt_irrefl \u22a4 (lt_of_le_of_lt h (coe_lt_top a))).elim\n\ninstance decidable_le [preorder \u03b1] [@decidable_rel \u03b1 (\u2264)] : @decidable_rel (with_top \u03b1) (\u2264) :=\n\u03bb x y, @with_bot.decidable_le (order_dual \u03b1) _ _ y x\n\ninstance decidable_lt [has_lt \u03b1] [@decidable_rel \u03b1 (<)] : @decidable_rel (with_top \u03b1) (<) :=\n\u03bb x y, @with_bot.decidable_lt (order_dual \u03b1) _ _ y x\n\ninstance [partial_order \u03b1] [is_total \u03b1 (\u2264)] : is_total (with_top \u03b1) (\u2264) :=\n{ total := \u03bb a b, match a, b with\n  | none  , _      := or.inr le_top\n  | _     , none   := or.inl le_top\n  | some x, some y := by simp only [some_le_some, total_of]\n  end }\n\ninstance linear_order [linear_order \u03b1] : linear_order (with_top \u03b1) :=\n{ le_total := \u03bb o\u2081 o\u2082, begin\n    cases o\u2081 with a, {exact or.inr le_top},\n    cases o\u2082 with b, {exact or.inl le_top},\n    simp [le_total]\n  end,\n  decidable_le := with_top.decidable_le,\n  decidable_lt := with_top.decidable_lt,\n  ..with_top.partial_order }\n\ninstance semilattice_inf [semilattice_inf \u03b1] : semilattice_inf_top (with_top \u03b1) :=\n{ inf          := option.lift_or_get (\u2293),\n  inf_le_left  := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2082; simp [option.lift_or_get],\n  inf_le_right := \u03bb o\u2081 o\u2082 a ha,\n    by cases ha; cases o\u2081; simp [option.lift_or_get],\n  le_inf       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases o\u2082 with b; cases o\u2083 with c; cases ha,\n    { exact h\u2082 a rfl },\n    { exact h\u2081 a rfl },\n    { rcases h\u2081 b rfl with \u27e8d, \u27e8\u27e9, h\u2081'\u27e9,\n      simp at h\u2082,\n      exact \u27e8d, rfl, le_inf h\u2081' h\u2082\u27e9 }\n  end,\n  ..with_top.order_top }\n\nlemma coe_inf [semilattice_inf \u03b1] (a b : \u03b1) : ((a \u2293 b : \u03b1) : with_top \u03b1) = a \u2293 b := rfl\n\ninstance semilattice_sup [semilattice_sup \u03b1] : semilattice_sup_top (with_top \u03b1) :=\n{ sup          := \u03bb o\u2081 o\u2082, o\u2081.bind (\u03bb a, o\u2082.map (\u03bb b, a \u2294 b)),\n  le_sup_left  := \u03bb o\u2081 o\u2082 a ha, begin\n    simp at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, le_sup_left\u27e9\n  end,\n  le_sup_right := \u03bb o\u2081 o\u2082 a ha, begin\n    simp at ha, rcases ha with \u27e8b, rfl, c, rfl, rfl\u27e9,\n    exact \u27e8_, rfl, le_sup_right\u27e9\n  end,\n  sup_le       := \u03bb o\u2081 o\u2082 o\u2083 h\u2081 h\u2082 a ha, begin\n    cases ha,\n    rcases h\u2081 a rfl with \u27e8b, \u27e8\u27e9, ab\u27e9,\n    rcases h\u2082 a rfl with \u27e8c, \u27e8\u27e9, ac\u27e9,\n    exact \u27e8_, rfl, sup_le ab ac\u27e9\n  end,\n  ..with_top.order_top }\n\nlemma coe_sup [semilattice_sup \u03b1] (a b : \u03b1) : ((a \u2294 b : \u03b1) : with_top \u03b1) = a \u2294 b := rfl\n\ninstance lattice [lattice \u03b1] : lattice (with_top \u03b1) :=\n{ ..with_top.semilattice_sup, ..with_top.semilattice_inf }\n\ntheorem lattice_eq_DLO [linear_order \u03b1] :\n  lattice_of_linear_order = @with_top.lattice \u03b1 _ :=\nlattice.ext $ \u03bb x y, iff.rfl\n\ntheorem sup_eq_max [linear_order \u03b1] (x y : with_top \u03b1) : x \u2294 y = max x y :=\nby rw [\u2190 sup_eq_max, lattice_eq_DLO]\n\ntheorem inf_eq_min [linear_order \u03b1] (x y : with_top \u03b1) : x \u2293 y = min x y :=\nby rw [\u2190 inf_eq_min, lattice_eq_DLO]\n\n@[simp, norm_cast]\nlemma coe_min [linear_order \u03b1] (x y : \u03b1) : ((min x y : \u03b1) : with_top \u03b1) = min x y :=\nby simp [min, ite_cast]\n\n@[simp, norm_cast]\nlemma coe_max [linear_order \u03b1] (x y : \u03b1) : ((max x y : \u03b1) : with_top \u03b1) = max x y :=\nby simp [max, ite_cast]\n\ninstance order_bot [order_bot \u03b1] : order_bot (with_top \u03b1) :=\n{ bot := some \u22a5,\n  bot_le := \u03bb o a ha, by cases ha; exact \u27e8_, rfl, bot_le\u27e9,\n  ..with_top.partial_order }\n\ninstance bounded_lattice [bounded_lattice \u03b1] : bounded_lattice (with_top \u03b1) :=\n{ ..with_top.lattice, ..with_top.order_top, ..with_top.order_bot }\n\nlemma well_founded_lt {\u03b1 : Type*} [partial_order \u03b1] (h : well_founded ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop)) :\n  well_founded ((<) : with_top \u03b1 \u2192 with_top \u03b1 \u2192 Prop) :=\nhave acc_some : \u2200 a : \u03b1, acc ((<) : with_top \u03b1 \u2192 with_top \u03b1 \u2192 Prop) (some a) :=\n\u03bb a, acc.intro _ (well_founded.induction h a\n  (show \u2200 b, (\u2200 c, c < b \u2192 \u2200 d : with_top \u03b1, d < some c \u2192 acc (<) d) \u2192\n    \u2200 y : with_top \u03b1, y < some b \u2192 acc (<) y,\n  from \u03bb b ih c, option.rec_on c (\u03bb hc, (not_lt_of_ge le_top hc).elim)\n    (\u03bb c hc, acc.intro _ (ih _ (some_lt_some.1 hc))))),\n\u27e8\u03bb a, option.rec_on a (acc.intro _ (\u03bb y, option.rec_on y (\u03bb h, (lt_irrefl _ h).elim)\n  (\u03bb _ _, acc_some _))) acc_some\u27e9\n\ninstance densely_ordered [partial_order \u03b1] [densely_ordered \u03b1] [no_top_order \u03b1] :\n  densely_ordered (with_top \u03b1) :=\n\u27e8 assume a b,\n  match a, b with\n  | none,   a   := assume h : \u22a4 < a, (not_top_lt h).elim\n  | some a, none := assume h, let \u27e8b, hb\u27e9 := no_top a in \u27e8b, coe_lt_coe.2 hb, coe_lt_top b\u27e9\n  | some a, some b := assume h, let \u27e8a, ha\u2081, ha\u2082\u27e9 := exists_between (coe_lt_coe.1 h) in\n    \u27e8a, coe_lt_coe.2 ha\u2081, coe_lt_coe.2 ha\u2082\u27e9\n  end\u27e9\n\nlemma lt_iff_exists_coe_btwn [partial_order \u03b1] [densely_ordered \u03b1] [no_top_order \u03b1]\n  {a b : with_top \u03b1} :\n  (a < b) \u2194 (\u2203 x : \u03b1, a < \u2191x \u2227 \u2191x < b) :=\n\u27e8\u03bb h, let \u27e8y, hy\u27e9 := exists_between h, \u27e8x, hx\u27e9 := lt_iff_exists_coe.1 hy.2 in \u27e8x, hx.1 \u25b8 hy\u27e9,\n \u03bb \u27e8x, hx\u27e9, lt_trans hx.1 hx.2\u27e9\n\nend with_top\n\nnamespace subtype\n\n/-- A subtype forms a `\u2294`-`\u22a5`-semilattice if `\u22a5` and `\u2294` preserve the property. -/\nprotected def semilattice_sup_bot [semilattice_sup_bot \u03b1] {P : \u03b1 \u2192 Prop}\n  (Pbot : P \u22a5) (Psup : \u2200\u2983x y\u2984, P x \u2192 P y \u2192 P (x \u2294 y)) : semilattice_sup_bot {x : \u03b1 // P x} :=\n{ bot := \u27e8\u22a5, Pbot\u27e9,\n  bot_le := \u03bb x, @bot_le \u03b1 _ x,\n  ..subtype.semilattice_sup Psup }\n\n/-- A subtype forms a `\u2293`-`\u22a5`-semilattice if `\u22a5` and `\u2293` preserve the property. -/\nprotected def semilattice_inf_bot [semilattice_inf_bot \u03b1] {P : \u03b1 \u2192 Prop}\n  (Pbot : P \u22a5) (Pinf : \u2200\u2983x y\u2984, P x \u2192 P y \u2192 P (x \u2293 y)) : semilattice_inf_bot {x : \u03b1 // P x} :=\n{ bot := \u27e8\u22a5, Pbot\u27e9,\n  bot_le := \u03bb x, @bot_le \u03b1 _ x,\n  ..subtype.semilattice_inf Pinf }\n\n/-- A subtype forms a `\u2293`-`\u22a4`-semilattice if `\u22a4` and `\u2293` preserve the property. -/\nprotected def semilattice_inf_top [semilattice_inf_top \u03b1] {P : \u03b1 \u2192 Prop}\n  (Ptop : P \u22a4) (Pinf : \u2200{{x y}}, P x \u2192 P y \u2192 P (x \u2293 y)) : semilattice_inf_top {x : \u03b1 // P x} :=\n{ top := \u27e8\u22a4, Ptop\u27e9,\n  le_top := \u03bb x, @le_top \u03b1 _ x,\n  ..subtype.semilattice_inf Pinf }\n\nend subtype\n\nnamespace order_dual\nvariable (\u03b1)\n\ninstance [has_bot \u03b1] : has_top (order_dual \u03b1) := \u27e8(\u22a5 : \u03b1)\u27e9\ninstance [has_top \u03b1] : has_bot (order_dual \u03b1) := \u27e8(\u22a4 : \u03b1)\u27e9\n\ninstance [order_bot \u03b1] : order_top (order_dual \u03b1) :=\n{ le_top := @bot_le \u03b1 _,\n  .. order_dual.partial_order \u03b1, .. order_dual.has_top \u03b1 }\n\ninstance [order_top \u03b1] : order_bot (order_dual \u03b1) :=\n{ bot_le := @le_top \u03b1 _,\n  .. order_dual.partial_order \u03b1, .. order_dual.has_bot \u03b1 }\n\ninstance [semilattice_inf_bot \u03b1] : semilattice_sup_top (order_dual \u03b1) :=\n{ .. order_dual.semilattice_sup \u03b1, .. order_dual.order_top \u03b1 }\n\ninstance [semilattice_inf_top \u03b1] : semilattice_sup_bot (order_dual \u03b1) :=\n{ .. order_dual.semilattice_sup \u03b1, .. order_dual.order_bot \u03b1 }\n\ninstance [semilattice_sup_bot \u03b1] : semilattice_inf_top (order_dual \u03b1) :=\n{ .. order_dual.semilattice_inf \u03b1, .. order_dual.order_top \u03b1 }\n\ninstance [semilattice_sup_top \u03b1] : semilattice_inf_bot (order_dual \u03b1) :=\n{ .. order_dual.semilattice_inf \u03b1, .. order_dual.order_bot \u03b1 }\n\ninstance [bounded_lattice \u03b1] : bounded_lattice (order_dual \u03b1) :=\n{ .. order_dual.lattice \u03b1, .. order_dual.order_top \u03b1, .. order_dual.order_bot \u03b1 }\n\ninstance [bounded_distrib_lattice \u03b1] : bounded_distrib_lattice (order_dual \u03b1) :=\n{ .. order_dual.bounded_lattice \u03b1, .. order_dual.distrib_lattice \u03b1 }\n\nend order_dual\n\nnamespace prod\nvariables (\u03b1 \u03b2)\n\ninstance [has_top \u03b1] [has_top \u03b2] : has_top (\u03b1 \u00d7 \u03b2) := \u27e8\u27e8\u22a4, \u22a4\u27e9\u27e9\ninstance [has_bot \u03b1] [has_bot \u03b2] : has_bot (\u03b1 \u00d7 \u03b2) := \u27e8\u27e8\u22a5, \u22a5\u27e9\u27e9\n\ninstance [order_top \u03b1] [order_top \u03b2] : order_top (\u03b1 \u00d7 \u03b2) :=\n{ le_top := assume a, \u27e8le_top, le_top\u27e9,\n  .. prod.partial_order \u03b1 \u03b2, .. prod.has_top \u03b1 \u03b2 }\n\ninstance [order_bot \u03b1] [order_bot \u03b2] : order_bot (\u03b1 \u00d7 \u03b2) :=\n{ bot_le := assume a, \u27e8bot_le, bot_le\u27e9,\n  .. prod.partial_order \u03b1 \u03b2, .. prod.has_bot \u03b1 \u03b2 }\n\ninstance [semilattice_sup_top \u03b1] [semilattice_sup_top \u03b2] : semilattice_sup_top (\u03b1 \u00d7 \u03b2) :=\n{ .. prod.semilattice_sup \u03b1 \u03b2, .. prod.order_top \u03b1 \u03b2 }\n\ninstance [semilattice_inf_top \u03b1] [semilattice_inf_top \u03b2] : semilattice_inf_top (\u03b1 \u00d7 \u03b2) :=\n{ .. prod.semilattice_inf \u03b1 \u03b2, .. prod.order_top \u03b1 \u03b2 }\n\ninstance [semilattice_sup_bot \u03b1] [semilattice_sup_bot \u03b2] : semilattice_sup_bot (\u03b1 \u00d7 \u03b2) :=\n{ .. prod.semilattice_sup \u03b1 \u03b2, .. prod.order_bot \u03b1 \u03b2 }\n\ninstance [semilattice_inf_bot \u03b1] [semilattice_inf_bot \u03b2] : semilattice_inf_bot (\u03b1 \u00d7 \u03b2) :=\n{ .. prod.semilattice_inf \u03b1 \u03b2, .. prod.order_bot \u03b1 \u03b2 }\n\ninstance [bounded_lattice \u03b1] [bounded_lattice \u03b2] : bounded_lattice (\u03b1 \u00d7 \u03b2) :=\n{ .. prod.lattice \u03b1 \u03b2, .. prod.order_top \u03b1 \u03b2, .. prod.order_bot \u03b1 \u03b2 }\n\ninstance [bounded_distrib_lattice \u03b1] [bounded_distrib_lattice \u03b2] :\n  bounded_distrib_lattice (\u03b1 \u00d7 \u03b2) :=\n{ .. prod.bounded_lattice \u03b1 \u03b2, .. prod.distrib_lattice \u03b1 \u03b2 }\n\nend prod\n\nsection disjoint\n\nsection semilattice_inf_bot\n\nvariable [semilattice_inf_bot \u03b1]\n\n/-- Two elements of a lattice are disjoint if their inf is the bottom element.\n  (This generalizes disjoint sets, viewed as members of the subset lattice.) -/\ndef disjoint (a b : \u03b1) : Prop := a \u2293 b \u2264 \u22a5\n\ntheorem disjoint.eq_bot {a b : \u03b1} (h : disjoint a b) : a \u2293 b = \u22a5 :=\neq_bot_iff.2 h\n\ntheorem disjoint_iff {a b : \u03b1} : disjoint a b \u2194 a \u2293 b = \u22a5 :=\neq_bot_iff.symm\n\ntheorem disjoint.comm {a b : \u03b1} : disjoint a b \u2194 disjoint b a :=\nby rw [disjoint, disjoint, inf_comm]\n\n@[symm] theorem disjoint.symm \u2983a b : \u03b1\u2984 : disjoint a b \u2192 disjoint b a :=\ndisjoint.comm.1\n\n@[simp] theorem disjoint_bot_left {a : \u03b1} : disjoint \u22a5 a := inf_le_left\n@[simp] theorem disjoint_bot_right {a : \u03b1} : disjoint a \u22a5 := inf_le_right\n\ntheorem disjoint.mono {a b c d : \u03b1} (h\u2081 : a \u2264 b) (h\u2082 : c \u2264 d) :\n  disjoint b d \u2192 disjoint a c := le_trans (inf_le_inf h\u2081 h\u2082)\n\ntheorem disjoint.mono_left {a b c : \u03b1} (h : a \u2264 b) : disjoint b c \u2192 disjoint a c :=\ndisjoint.mono h (le_refl _)\n\ntheorem disjoint.mono_right {a b c : \u03b1} (h : b \u2264 c) : disjoint a c \u2192 disjoint a b :=\ndisjoint.mono (le_refl _) h\n\n@[simp] lemma disjoint_self {a : \u03b1} : disjoint a a \u2194 a = \u22a5 :=\nby simp [disjoint]\n\nlemma disjoint.ne {a b : \u03b1} (ha : a \u2260 \u22a5) (hab : disjoint a b) : a \u2260 b :=\nby { intro h, rw [\u2190h, disjoint_self] at hab, exact ha hab }\n\nend semilattice_inf_bot\n\nsection bounded_lattice\n\nvariables [bounded_lattice \u03b1] {a : \u03b1}\n\n@[simp] theorem disjoint_top : disjoint a \u22a4 \u2194 a = \u22a5 := by simp [disjoint_iff]\n@[simp] theorem top_disjoint : disjoint \u22a4 a \u2194 a = \u22a5 := by simp [disjoint_iff]\n\nend bounded_lattice\n\nsection bounded_distrib_lattice\n\nvariables [bounded_distrib_lattice \u03b1] {a b c : \u03b1}\n\n@[simp] lemma disjoint_sup_left : disjoint (a \u2294 b) c \u2194 disjoint a c \u2227 disjoint b c :=\nby simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff]\n\n@[simp] lemma disjoint_sup_right : disjoint a (b \u2294 c) \u2194 disjoint a b \u2227 disjoint a c :=\nby simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff]\n\nlemma disjoint.sup_left (ha : disjoint a c) (hb : disjoint b c) : disjoint (a \u2294 b) c :=\ndisjoint_sup_left.2 \u27e8ha, hb\u27e9\n\nlemma disjoint.sup_right (hb : disjoint a b) (hc : disjoint a c) : disjoint a (b \u2294 c) :=\ndisjoint_sup_right.2 \u27e8hb, hc\u27e9\n\nlemma disjoint.left_le_of_le_sup_right {a b c : \u03b1} (h : a \u2264 b \u2294 c) (hd : disjoint a c) : a \u2264 b :=\n(\u03bb x, le_of_inf_le_sup_le x (sup_le h le_sup_right)) ((disjoint_iff.mp hd).symm \u25b8 bot_le)\n\nlemma disjoint.left_le_of_le_sup_left {a b c : \u03b1} (h : a \u2264 c \u2294 b) (hd : disjoint a c) : a \u2264 b :=\n@le_of_inf_le_sup_le _ _ a b c ((disjoint_iff.mp hd).symm \u25b8 bot_le)\n  ((@sup_comm _ _ c b) \u25b8 (sup_le h le_sup_left))\n\nend bounded_distrib_lattice\n\nend disjoint\n\nsection is_compl\n\n/-!\n### `is_compl` predicate\n-/\n\n/-- Two elements `x` and `y` are complements of each other if\n`x \u2294 y = \u22a4` and `x \u2293 y = \u22a5`. -/\nstructure is_compl [bounded_lattice \u03b1] (x y : \u03b1) : Prop :=\n(inf_le_bot : x \u2293 y \u2264 \u22a5)\n(top_le_sup : \u22a4 \u2264 x \u2294 y)\n\nnamespace is_compl\n\nsection bounded_lattice\n\nvariables [bounded_lattice \u03b1] {x y z : \u03b1}\n\nprotected lemma disjoint (h : is_compl x y) : disjoint x y := h.1\n\n@[symm] protected lemma symm (h : is_compl x y) : is_compl y x :=\n\u27e8by { rw inf_comm, exact h.1 }, by { rw sup_comm, exact h.2 }\u27e9\n\nlemma of_eq (h\u2081 : x \u2293 y = \u22a5) (h\u2082 : x \u2294 y = \u22a4) : is_compl x y :=\n\u27e8le_of_eq h\u2081, le_of_eq h\u2082.symm\u27e9\n\nlemma inf_eq_bot (h : is_compl x y) : x \u2293 y = \u22a5 := h.disjoint.eq_bot\n\nlemma sup_eq_top (h : is_compl x y) : x \u2294 y = \u22a4 := top_unique h.top_le_sup\n\nlemma to_order_dual (h : is_compl x y) : @is_compl (order_dual \u03b1) _ x y := \u27e8h.2, h.1\u27e9\n\nend bounded_lattice\n\nvariables [bounded_distrib_lattice \u03b1] {x y z : \u03b1}\n\nlemma inf_left_eq_bot_iff (h : is_compl y z) : x \u2293 y = \u22a5 \u2194 x \u2264 z :=\ninf_eq_bot_iff_le_compl h.sup_eq_top h.inf_eq_bot\n\nlemma inf_right_eq_bot_iff (h : is_compl y z) : x \u2293 z = \u22a5 \u2194 x \u2264 y :=\nh.symm.inf_left_eq_bot_iff\n\nlemma disjoint_left_iff (h : is_compl y z) : disjoint x y \u2194 x \u2264 z :=\nby { rw [disjoint_iff], exact h.inf_left_eq_bot_iff }\n\nlemma disjoint_right_iff (h : is_compl y z) : disjoint x z \u2194 x \u2264 y :=\nh.symm.disjoint_left_iff\n\nlemma le_left_iff (h : is_compl x y) : z \u2264 x \u2194 disjoint z y :=\nh.disjoint_right_iff.symm\n\nlemma le_right_iff (h : is_compl x y) : z \u2264 y \u2194 disjoint z x :=\nh.symm.le_left_iff\n\nlemma left_le_iff (h : is_compl x y) : x \u2264 z \u2194 \u22a4 \u2264 z \u2294 y :=\nh.to_order_dual.le_left_iff\n\nlemma right_le_iff (h : is_compl x y) : y \u2264 z \u2194 \u22a4 \u2264 z \u2294 x :=\nh.symm.left_le_iff\n\nlemma antimono {x' y'} (h : is_compl x y) (h' : is_compl x' y') (hx : x \u2264 x') :\n  y' \u2264 y :=\nh'.right_le_iff.2 $ le_trans h.symm.top_le_sup (sup_le_sup_left hx _)\n\nlemma right_unique (hxy : is_compl x y) (hxz : is_compl x z) :\n  y = z :=\nle_antisymm (hxz.antimono hxy $ le_refl x) (hxy.antimono hxz $ le_refl x)\n\nlemma left_unique (hxz : is_compl x z) (hyz : is_compl y z) :\n  x = y :=\nhxz.symm.right_unique hyz.symm\n\nlemma sup_inf {x' y'} (h : is_compl x y) (h' : is_compl x' y') :\n  is_compl (x \u2294 x') (y \u2293 y') :=\nof_eq\n  (by rw [inf_sup_right, \u2190 inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm,\n    h'.inf_eq_bot, inf_bot_eq])\n  (by rw [sup_inf_left, @sup_comm _ _ x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq,\n    sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq])\n\nlemma inf_sup {x' y'} (h : is_compl x y) (h' : is_compl x' y') :\n  is_compl (x \u2293 x') (y \u2294 y') :=\n(h.symm.sup_inf h'.symm).symm\n\nend is_compl\n\nlemma is_compl_bot_top [bounded_lattice \u03b1] : is_compl (\u22a5 : \u03b1) \u22a4 :=\nis_compl.of_eq bot_inf_eq sup_top_eq\n\nlemma is_compl_top_bot [bounded_lattice \u03b1] : is_compl (\u22a4 : \u03b1) \u22a5 :=\nis_compl.of_eq inf_bot_eq top_sup_eq\n\nsection\nvariables [bounded_lattice \u03b1] {x : \u03b1}\n\nlemma eq_top_of_is_compl_bot (h : is_compl x \u22a5) : x = \u22a4 :=\nsup_bot_eq.symm.trans h.sup_eq_top\n\nlemma eq_top_of_bot_is_compl (h : is_compl \u22a5 x) : x = \u22a4 :=\neq_top_of_is_compl_bot h.symm\n\nlemma eq_bot_of_is_compl_top (h : is_compl x \u22a4) : x = \u22a5 :=\neq_top_of_is_compl_bot h.to_order_dual\n\nlemma eq_bot_of_top_is_compl (h : is_compl \u22a4 x) : x = \u22a5 :=\neq_top_of_bot_is_compl h.to_order_dual\n\nend\n\n/-- A complemented bounded lattice is one where every element has a\n  (not necessarily unique) complement. -/\nclass is_complemented (\u03b1) [bounded_lattice \u03b1] : Prop :=\n(exists_is_compl : \u2200 (a : \u03b1), \u2203 (b : \u03b1), is_compl a b)\n\nexport is_complemented (exists_is_compl)\n\nnamespace is_complemented\nvariables [bounded_lattice \u03b1] [is_complemented \u03b1]\n\ninstance : is_complemented (order_dual \u03b1) :=\n\u27e8\u03bb a, \u27e8classical.some (@exists_is_compl \u03b1 _ _ a),\n  (classical.some_spec (@exists_is_compl \u03b1 _ _ a)).to_order_dual\u27e9\u27e9\n\nend is_complemented\n\nend is_compl\n\nsection nontrivial\n\nvariables [bounded_lattice \u03b1] [nontrivial \u03b1]\n\nlemma bot_ne_top : (\u22a5 : \u03b1) \u2260 \u22a4 :=\n\u03bb H, not_nontrivial_iff_subsingleton.mpr (subsingleton_of_bot_eq_top H) \u2039_\u203a\n\nlemma top_ne_bot : (\u22a4 : \u03b1) \u2260 \u22a5 := ne.symm bot_ne_top\n\nend nontrivial\n\nnamespace bool\n\ninstance : bounded_lattice bool :=\n{ top := tt,\n  le_top := \u03bb x, le_tt,\n  bot := ff,\n  bot_le := \u03bb x, ff_le,\n  .. (infer_instance : lattice bool)}\n\nend bool\n\nsection bool\n\n@[simp] lemma top_eq_tt : \u22a4 = tt := rfl\n\n@[simp] lemma bot_eq_ff : \u22a5 = ff := rfl\n\nend bool\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/bounded_lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914788, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7117925275221614}}
{"text": "import data.nat.basic\nimport data.int.basic\nimport data.real.basic\nopen classical\n\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) (r : Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\niff.intro\n  (assume h : \u2200 x, p x \u2227 q x,\n    and.intro\n      (\u03bb x, show p x, from (h x).left)\n      (\u03bb x, show q x, from (h x).right))\n  (assume h : (\u2200 x, p x) \u2227 (\u2200 x, q x),\n    \u03bb x, show p x \u2227 q x, from \u27e8h.left x, h.right x\u27e9)\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\nassume h1 : \u2200 x, p x \u2192 q x,\nassume h2 : \u2200 x, p x,\n\u03bb x, show q x, from (h1 x) (h2 x)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\nassume h : (\u2200 x, p x) \u2228 (\u2200 x, q x),\n\u03bb x, show p x \u2228 q x, from or.elim h\n  (assume h1 : \u2200 x, p x, or.inl (h1 x))\n  (assume h2 : \u2200 x, q x, or.inr (h2 x))\n\nexample : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) :=\n\u03bb x, iff.intro\n  (assume h : \u2200 y : \u03b1, r, show r, from h x)\n  (assume r1 : r, \u03bb y, show r, from r1)\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r :=\niff.intro\n  (assume h : \u2200 x, p x \u2228 r,\n    by_cases\n      (assume h1 : r, or.inr h1)\n      (assume h1 : \u00acr, or.inl\n        (\u03bb x, show p x, from or.elim (h x)\n          (assume h2 : p x, h2)\n          (assume h2 : r, false.elim (h1 h2)))))\n  (assume h : (\u2200 x, p x) \u2228 r,\n    assume x : \u03b1,\n    show p x \u2228 r, from or.elim h\n      (assume h1 : \u2200 x, p x, or.inl (h1 x))\n      (\u03bb r1, or.inr r1))\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\niff.intro\n  (assume h : \u2200 x, r \u2192 p x,\n    \u03bb r x, show p x, from h x r)\n  (assume h : r \u2192 \u2200 x, p x,\n    \u03bb x r, show p x, from h r x)\n\n-- Barber paradox\nvariables (men : Type) (barber : men) (shaves : men \u2192 men \u2192 Prop)\n\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : false :=\nor.elim (classical.em (shaves barber barber))\n  (assume h1 : shaves barber barber, (h barber).mp h1 h1)\n  (assume h1 : \u00ac shaves barber barber, h1 ((h barber).mpr h1))\n\n-- Some number theory\ndef prime (n : \u2115) : Prop := \u2200 (k : \u2115), k \u2223 n \u2192 k = 1 \u2228 k = n\n\ndef infinitely_many_primes : Prop := \u2200 n, \u2203 N, n < N \u2227 prime N\n\ndef Fermat_prime (n : \u2115) : Prop := prime n \u2227 \u2203 (k : \u2115), n = 2 ^ k + 1\n\ndef infinitely_many_Fermat_primes : Prop := \u2200 n, \u2203 N, n < N \u2227 Fermat_prime N\n\ndef goldbach_conjecture : Prop :=\n  \u2200 (n : \u2115), even n \u2192 (\u2203 x y, prime x \u2227 prime y \u2227 n = x + y)\n\ndef Goldbach's_weak_conjecture : Prop :=\n  \u2200 (n : \u2115), \u00ac even n \u2227 n > 5 \u2192 (\u2203 x y z, prime x \u2227 prime y \u2227 prime z \u2227 n = x + y + z)\n\ndef Fermat's_last_theorem : Prop :=\n  \u2200 (n : \u2115), n > 2 \u2192 \u00ac(\u2203 (a b c : \u2115), a ^ n + b ^ n = c ^ n)\n\n-- Very fun\nexample : (\u2203 x : \u03b1, r) \u2192 r :=\nassume h : \u2203 x, r,\nlet \u27e8x, r\u27e9 := h in r\n\nexample (a : \u03b1) : r \u2192 (\u2203 x : \u03b1, r) :=\n\u03bb r0, exists.intro a r0\n\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r :=\niff.intro\n  (assume h : \u2203 x, p x \u2227 r,\n    let \u27e8x, hx\u27e9 := h in \u27e8\u27e8x, hx.left\u27e9, hx.right\u27e9)\n  (assume h : (\u2203 x, p x) \u2227 r,\n    let \u27e8x, hx\u27e9 := h.left in \u27e8x, hx, h.right\u27e9)\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\niff.intro\n  (assume h : \u2203 x, p x \u2228 q x,\n    let \u27e8x, hx\u27e9 := h in or.elim hx\n      (assume h1 : p x, or.inl \u27e8x, h1\u27e9)\n      (assume h1 : q x, or.inr \u27e8x, h1\u27e9))\n  (assume h : (\u2203 x, p x) \u2228 (\u2203 x, q x),\n    or.elim h\n      (assume h1 : \u2203 x, p x, let \u27e8x, hx\u27e9 := h1 in \u27e8x, or.inl hx\u27e9)\n      (assume h1 : \u2203 x, q x, let \u27e8x, hx\u27e9 := h1 in \u27e8x, or.inr hx\u27e9))\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) :=\niff.intro\n  (assume h1 : \u2200 x, p x,\n    assume h2 : \u2203 x, \u00ac p x,\n    let \u27e8x, hnpx\u27e9 := h2 in hnpx (h1 x))\n  (assume h1 : \u00ac (\u2203 x, \u00ac p x),\n    \u03bb x, by_cases\n      (assume h2 : p x, h2)\n      (assume h2 : \u00ac p x, false.elim (h1 \u27e8x, h2\u27e9)))\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) :=\niff.intro\n  (assume h1 : \u2203 x, p x,\n    assume h2 : \u2200 x, \u00ac p x,\n    let \u27e8x, hpx\u27e9 := h1 in h2 x hpx)\n  (assume h1 : \u00ac (\u2200 x, \u00ac p x),\n    classical.by_contradiction\n      (assume h2 : \u00ac (\u2203 x, p x),\n        suffices h3 : \u2200 x, \u00ac p x, from h1 h3,\n        \u03bb x, assume h4 : p x, h2 \u27e8x, h4\u27e9))\n\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) :=\niff.intro\n  (assume h1 : \u00ac \u2203 x, p x,\n    \u03bb x, by_cases\n      (assume h2 : p x, false.elim (h1 \u27e8x, h2\u27e9))\n      (assume h2 : \u00ac p x, h2))\n  (assume h1 : \u2200 x, \u00ac p x,\n    assume h2 : \u2203 x, p x,\n    let \u27e8x, hpx\u27e9 := h2 in h1 x hpx)\n\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) :=\niff.intro\n  (assume h1 : \u00ac \u2200 x, p x,\n    classical.by_contradiction\n      (assume h2 : \u00ac (\u2203 x, \u00ac p x),\n        suffices h3 : \u2200 x, p x, from h1 h3,\n        \u03bb x, by_cases\n          (assume h4 : p x, h4)\n          (assume h4 : \u00ac p x, false.elim (h2 \u27e8x, h4\u27e9))))\n  (assume h1 : \u2203 x, \u00ac p x,\n    assume h2 : \u2200 x, p x,\n    let \u27e8x, hnpx\u27e9 := h1 in hnpx (h2 x))\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r :=\niff.intro\n  (assume h1 : \u2200 x, p x \u2192 r,\n    assume h2 : \u2203 x, p x,\n    let \u27e8x, hpx\u27e9 := h2 in h1 x hpx)\n  (assume h1 : (\u2203 x, p x) \u2192 r,\n    \u03bb x, assume h2 : p x, h1 \u27e8x, h2\u27e9)\n\nexample (a : \u03b1) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r :=\niff.intro\n  (assume h1 : \u2203 x, p x \u2192 r,\n    assume h2 : \u2200 x, p x,\n    let \u27e8x, hpxr\u27e9 := h1 in hpxr (h2 x))\n  -- This solution is very cursed\n  (assume h1 : (\u2200 x, p x) \u2192 r,\n    show \u2203 x, p x \u2192 r, from\n      by_cases\n        (assume hap : \u2200 x, p x, \u27e8a, \u03bb h', h1 hap\u27e9)\n        (assume hnap : \u00ac \u2200 x, p x,\n          classical.by_contradiction\n            (assume hnex : \u00ac \u2203 x, p x \u2192 r,\n              have hap : \u2200 x, p x, from\n                assume x,\n                classical.by_contradiction\n                  (assume hnp : \u00ac p x,\n                    have hex : \u2203 x, p x \u2192 r,\n                      from \u27e8x, (assume hp, absurd hp hnp)\u27e9,\n                    show false, from hnex hex),\n              show false, from hnap hap)))\n\nexample (a : \u03b1) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) :=\niff.intro\n  (assume h1 : \u2203 x, r \u2192 p x,\n    assume r1 : r,\n    let \u27e8x, hrpx\u27e9 := h1 in \u27e8x, hrpx r1\u27e9)\n  (assume h1 : r \u2192 \u2203 x, p x,\n    by_cases\n      (assume h2 : r,\n        let \u27e8x, hpx\u27e9 := h1 h2 in \u27e8x, \u03bb r, hpx\u27e9)\n      (assume h2 : \u00ac r,\n        exists.intro a\n          (assume r1 : r, false.elim (h2 r1))))\n\n-- Some calculation\nvariables log exp : real \u2192 real\nvariable log_exp_eq : \u2200 x, log (exp x) = x\nvariable exp_log_eq : \u2200 x, x > 0 \u2192 exp (log x) = x\nvariable exp_pos : \u2200 x, exp x > 0\nvariable exp_add : \u2200 x y, exp (x + y) = exp x * exp y\ninclude log_exp_eq exp_log_eq exp_pos exp_add\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\ncalc log (x * y) = log (x * exp (log y)) : by rw exp_log_eq y hy\n... = log (exp (log x) * exp (log y)) : by rw exp_log_eq x hx\n... = log (exp (log x + log y)) : by rw exp_add\n... = log x + log y : log_exp_eq _\n\nexample (x : \u2124) : x * 0 = 0 :=\ncalc x * 0 = x * (x - x) : by rw \u2190sub_self\n... = x * x - x * x : by rw mul_sub\n... = 0 : by rw sub_self", "meta": {"author": "greysome", "repo": "lean-practice", "sha": "00729df4b18a2538cd3f63f68ab9c59308e3a6c2", "save_path": "github-repos/lean/greysome-lean-practice", "path": "github-repos/lean/greysome-lean-practice/lean-practice-00729df4b18a2538cd3f63f68ab9c59308e3a6c2/src/old/thm-proving-ch4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382004, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7117781186093403}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport data.set.intervals.unordered_interval\nimport linear_algebra.affine_space.affine_equiv\n\n/-!\n# Affine spaces\n\nThis file defines affine subspaces (over modules) and the affine span of a set of points.\n\n## Main definitions\n\n* `affine_subspace k P` is the type of affine subspaces.  Unlike\n  affine spaces, affine subspaces are allowed to be empty, and lemmas\n  that do not apply to empty affine subspaces have `nonempty`\n  hypotheses.  There is a `complete_lattice` structure on affine\n  subspaces.\n* `affine_subspace.direction` gives the `submodule` spanned by the\n  pairwise differences of points in an `affine_subspace`.  There are\n  various lemmas relating to the set of vectors in the `direction`,\n  and relating the lattice structure on affine subspaces to that on\n  their directions.\n* `affine_span` gives the affine subspace spanned by a set of points,\n  with `vector_span` giving its direction.  `affine_span` is defined\n  in terms of `span_points`, which gives an explicit description of\n  the points contained in the affine span; `span_points` itself should\n  generally only be used when that description is required, with\n  `affine_span` being the main definition for other purposes.  Two\n  other descriptions of the affine span are proved equivalent: it is\n  the `Inf` of affine subspaces containing the points, and (if\n  `[nontrivial k]`) it contains exactly those points that are affine\n  combinations of points in the given set.\n\n## Implementation notes\n\n`out_param` is used in the definiton of `add_torsor V P` to make `V` an implicit argument (deduced\nfrom `P`) in most cases; `include V` is needed in many cases for `V`, and type classes using it, to\nbe added as implicit arguments to individual lemmas.  As for modules, `k` is an explicit argument\nrather than implied by `P` or `V`.\n\nThis file only provides purely algebraic definitions and results.\nThose depending on analysis or topology are defined elsewhere; see\n`analysis.normed_space.add_torsor` and `topology.algebra.affine`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Affine_space\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n-/\n\nnoncomputable theory\nopen_locale big_operators classical affine\n\nopen set\n\nsection\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\nvariables [affine_space V P]\ninclude V\n\n/-- The submodule spanning the differences of a (possibly empty) set\nof points. -/\ndef vector_span (s : set P) : submodule k V := submodule.span k (s -\u1d65 s)\n\n/-- The definition of `vector_span`, for rewriting. -/\nlemma vector_span_def (s : set P) : vector_span k s = submodule.span k (s -\u1d65 s) :=\nrfl\n\n/-- `vector_span` is monotone. -/\nlemma vector_span_mono {s\u2081 s\u2082 : set P} (h : s\u2081 \u2286 s\u2082) : vector_span k s\u2081 \u2264 vector_span k s\u2082 :=\nsubmodule.span_mono (vsub_self_mono h)\n\nvariables (P)\n\n/-- The `vector_span` of the empty set is `\u22a5`. -/\n@[simp] lemma vector_span_empty : vector_span k (\u2205 : set P) = (\u22a5 : submodule k V) :=\nby rw [vector_span_def, vsub_empty, submodule.span_empty]\n\nvariables {P}\n\n/-- The `vector_span` of a single point is `\u22a5`. -/\n@[simp] lemma vector_span_singleton (p : P) : vector_span k ({p} : set P) = \u22a5 :=\nby simp [vector_span_def]\n\n/-- The `s -\u1d65 s` lies within the `vector_span k s`. -/\nlemma vsub_set_subset_vector_span (s : set P) : s -\u1d65 s \u2286 \u2191(vector_span k s) :=\nsubmodule.subset_span\n\n/-- Each pairwise difference is in the `vector_span`. -/\nlemma vsub_mem_vector_span {s : set P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n  p1 -\u1d65 p2 \u2208 vector_span k s :=\nvsub_set_subset_vector_span k s (vsub_mem_vsub hp1 hp2)\n\n/-- The points in the affine span of a (possibly empty) set of\npoints. Use `affine_span` instead to get an `affine_subspace k P`. -/\ndef span_points (s : set P) : set P :=\n{p | \u2203 p1 \u2208 s, \u2203 v \u2208 (vector_span k s), p = v +\u1d65 p1}\n\n/-- A point in a set is in its affine span. -/\nlemma mem_span_points (p : P) (s : set P) : p \u2208 s \u2192 p \u2208 span_points k s\n| hp := \u27e8p, hp, 0, submodule.zero_mem _, (zero_vadd V p).symm\u27e9\n\n/-- A set is contained in its `span_points`. -/\nlemma subset_span_points (s : set P) : s \u2286 span_points k s :=\n\u03bb p, mem_span_points k p s\n\n/-- The `span_points` of a set is nonempty if and only if that set\nis. -/\n@[simp] lemma span_points_nonempty (s : set P) :\n  (span_points k s).nonempty \u2194 s.nonempty :=\nbegin\n  split,\n  { contrapose,\n    rw [set.not_nonempty_iff_eq_empty, set.not_nonempty_iff_eq_empty],\n    intro h,\n    simp [h, span_points] },\n  { exact \u03bb h, h.mono (subset_span_points _ _) }\nend\n\n/-- Adding a point in the affine span and a vector in the spanning\nsubmodule produces a point in the affine span. -/\nlemma vadd_mem_span_points_of_mem_span_points_of_mem_vector_span {s : set P} {p : P} {v : V}\n    (hp : p \u2208 span_points k s) (hv : v \u2208 vector_span k s) : v +\u1d65 p \u2208 span_points k s :=\nbegin\n  rcases hp with \u27e8p2, \u27e8hp2, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9,\n  rw [hv2p, vadd_vadd],\n  use [p2, hp2, v + v2, (vector_span k s).add_mem hv hv2, rfl]\nend\n\n/-- Subtracting two points in the affine span produces a vector in the\nspanning submodule. -/\nlemma vsub_mem_vector_span_of_mem_span_points_of_mem_span_points {s : set P} {p1 p2 : P}\n    (hp1 : p1 \u2208 span_points k s) (hp2 : p2 \u2208 span_points k s) :\n  p1 -\u1d65 p2 \u2208 vector_span k s :=\nbegin\n  rcases hp1 with \u27e8p1a, \u27e8hp1a, \u27e8v1, \u27e8hv1, hv1p\u27e9\u27e9\u27e9\u27e9,\n  rcases hp2 with \u27e8p2a, \u27e8hp2a, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9,\n  rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +\u1d65 p1a), vadd_vsub_assoc, add_comm, add_sub_assoc],\n  have hv1v2 : v1 - v2 \u2208 vector_span k s,\n  { rw sub_eq_add_neg,\n    apply (vector_span k s).add_mem hv1,\n    rw \u2190neg_one_smul k v2,\n    exact (vector_span k s).smul_mem (-1 : k) hv2 },\n  refine (vector_span k s).add_mem _ hv1v2,\n  exact vsub_mem_vector_span k hp1a hp2a\nend\n\nend\n\n/-- An `affine_subspace k P` is a subset of an `affine_space V P`\nthat, if not empty, has an affine space structure induced by a\ncorresponding subspace of the `module k V`. -/\nstructure affine_subspace (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V]\n    [module k V] [affine_space V P] :=\n(carrier : set P)\n(smul_vsub_vadd_mem : \u2200 (c : k) {p1 p2 p3 : P}, p1 \u2208 carrier \u2192 p2 \u2208 carrier \u2192 p3 \u2208 carrier \u2192\n  c \u2022 (p1 -\u1d65 p2 : V) +\u1d65 p3 \u2208 carrier)\n\nnamespace submodule\n\nvariables {k V : Type*} [ring k] [add_comm_group V] [module k V]\n\n/-- Reinterpret `p : submodule k V` as an `affine_subspace k V`. -/\ndef to_affine_subspace (p : submodule k V) : affine_subspace k V :=\n{ carrier := p,\n  smul_vsub_vadd_mem := \u03bb c p\u2081 p\u2082 p\u2083 h\u2081 h\u2082 h\u2083, p.add_mem (p.smul_mem _ (p.sub_mem h\u2081 h\u2082)) h\u2083 }\n\nend submodule\n\nnamespace affine_subspace\n\nvariables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\n-- TODO Refactor to use `instance : set_like (affine_subspace k P) P :=` instead\ninstance : has_coe (affine_subspace k P) (set P) := \u27e8carrier\u27e9\ninstance : has_mem P (affine_subspace k P) := \u27e8\u03bb p s, p \u2208 (s : set P)\u27e9\n\n/-- A point is in an affine subspace coerced to a set if and only if\nit is in that affine subspace. -/\n@[simp] lemma mem_coe (p : P) (s : affine_subspace k P) :\n  p \u2208 (s : set P) \u2194 p \u2208 s :=\niff.rfl\n\nvariables {k P}\n\n/-- The direction of an affine subspace is the submodule spanned by\nthe pairwise differences of points.  (Except in the case of an empty\naffine subspace, where the direction is the zero submodule, every\nvector in the direction is the difference of two points in the affine\nsubspace.) -/\ndef direction (s : affine_subspace k P) : submodule k V := vector_span k (s : set P)\n\n/-- The direction equals the `vector_span`. -/\nlemma direction_eq_vector_span (s : affine_subspace k P) :\n  s.direction = vector_span k (s : set P) :=\nrfl\n\n/-- Alternative definition of the direction when the affine subspace\nis nonempty.  This is defined so that the order on submodules (as used\nin the definition of `submodule.span`) can be used in the proof of\n`coe_direction_eq_vsub_set`, and is not intended to be used beyond\nthat proof. -/\ndef direction_of_nonempty {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  submodule k V :=\n{ carrier := (s : set P) -\u1d65 s,\n  zero_mem' := begin\n    cases h with p hp,\n    exact (vsub_self p) \u25b8 vsub_mem_vsub hp hp\n  end,\n  add_mem' := begin\n    intros a b ha hb,\n    rcases ha with \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    rcases hb with \u27e8p3, p4, hp3, hp4, rfl\u27e9,\n    rw [\u2190vadd_vsub_assoc],\n    refine vsub_mem_vsub _ hp4,\n    convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3,\n    rw one_smul\n  end,\n  smul_mem' := begin\n    intros c v hv,\n    rcases hv with \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    rw [\u2190vadd_vsub (c \u2022 (p1 -\u1d65 p2)) p2],\n    refine vsub_mem_vsub _ hp2,\n    exact s.smul_vsub_vadd_mem c hp1 hp2 hp2\n  end }\n\n/-- `direction_of_nonempty` gives the same submodule as\n`direction`. -/\nlemma direction_of_nonempty_eq_direction {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  direction_of_nonempty h = s.direction :=\nle_antisymm (vsub_set_subset_vector_span k s) (submodule.span_le.2 set.subset.rfl)\n\n/-- The set of vectors in the direction of a nonempty affine subspace\nis given by `vsub_set`. -/\nlemma coe_direction_eq_vsub_set {s : affine_subspace k P} (h : (s : set P).nonempty) :\n  (s.direction : set V) = (s : set P) -\u1d65 s :=\ndirection_of_nonempty_eq_direction h \u25b8 rfl\n\n/-- A vector is in the direction of a nonempty affine subspace if and\nonly if it is the subtraction of two vectors in the subspace. -/\nlemma mem_direction_iff_eq_vsub {s : affine_subspace k P} (h : (s : set P).nonempty) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p1 \u2208 s, \u2203 p2 \u2208 s, v = p1 -\u1d65 p2 :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set h],\n  exact \u27e8\u03bb \u27e8p1, p2, hp1, hp2, hv\u27e9, \u27e8p1, hp1, p2, hp2, hv.symm\u27e9,\n         \u03bb \u27e8p1, hp1, p2, hp2, hv\u27e9, \u27e8p1, p2, hp1, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Adding a vector in the direction to a point in the subspace\nproduces a point in the subspace. -/\nlemma vadd_mem_of_mem_direction {s : affine_subspace k P} {v : V} (hv : v \u2208 s.direction) {p : P}\n    (hp : p \u2208 s) : v +\u1d65 p \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub \u27e8p, hp\u27e9 at hv,\n  rcases hv with \u27e8p1, hp1, p2, hp2, hv\u27e9,\n  rw hv,\n  convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp,\n  rw one_smul\nend\n\n/-- Subtracting two points in the subspace produces a vector in the\ndirection. -/\nlemma vsub_mem_direction {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n  (p1 -\u1d65 p2) \u2208 s.direction :=\nvsub_mem_vector_span k hp1 hp2\n\n/-- Adding a vector to a point in a subspace produces a point in the\nsubspace if and only if the vector is in the direction. -/\nlemma vadd_mem_iff_mem_direction {s : affine_subspace k P} (v : V) {p : P} (hp : p \u2208 s) :\n  v +\u1d65 p \u2208 s \u2194 v \u2208 s.direction :=\n\u27e8\u03bb h, by simpa using vsub_mem_direction h hp, \u03bb h, vadd_mem_of_mem_direction h hp\u27e9\n\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nright. -/\nlemma coe_direction_eq_vsub_set_right {s : affine_subspace k P} {p : P} (hp : p \u2208 s) :\n  (s.direction : set V) = (-\u1d65 p) '' s :=\nbegin\n  rw coe_direction_eq_vsub_set \u27e8p, hp\u27e9,\n  refine le_antisymm _ _,\n  { rintros v \u27e8p1, p2, hp1, hp2, rfl\u27e9,\n    exact \u27e8p1 -\u1d65 p2 +\u1d65 p,\n           vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp,\n           (vadd_vsub _ _)\u27e9 },\n  { rintros v \u27e8p2, hp2, rfl\u27e9,\n    exact \u27e8p2, p, hp2, hp, rfl\u27e9 }\nend\n\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nleft. -/\nlemma coe_direction_eq_vsub_set_left {s : affine_subspace k P} {p : P} (hp : p \u2208 s) :\n  (s.direction : set V) = (-\u1d65) p '' s :=\nbegin\n  ext v,\n  rw [set_like.mem_coe, \u2190submodule.neg_mem_iff, \u2190set_like.mem_coe,\n      coe_direction_eq_vsub_set_right hp, set.mem_image_iff_bex, set.mem_image_iff_bex],\n  conv_lhs { congr, funext, rw [\u2190neg_vsub_eq_vsub_rev, neg_inj] }\nend\n\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the right. -/\nlemma mem_direction_iff_eq_vsub_right {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p2 -\u1d65 p :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set_right hp],\n  exact \u27e8\u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9, \u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the left. -/\nlemma mem_direction_iff_eq_vsub_left {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n  v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p -\u1d65 p2 :=\nbegin\n  rw [\u2190set_like.mem_coe, coe_direction_eq_vsub_set_left hp],\n  exact \u27e8\u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9, \u03bb \u27e8p2, hp2, hv\u27e9, \u27e8p2, hp2, hv.symm\u27e9\u27e9\nend\n\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the right is in the direction if and only if the other point\nis in the subspace. -/\nlemma vsub_right_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n  p2 -\u1d65 p \u2208 s.direction \u2194 p2 \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub_right hp,\n  simp\nend\n\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the left is in the direction if and only if the other point\nis in the subspace. -/\nlemma vsub_left_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n  p -\u1d65 p2 \u2208 s.direction \u2194 p2 \u2208 s :=\nbegin\n  rw mem_direction_iff_eq_vsub_left hp,\n  simp\nend\n\n/-- Two affine subspaces are equal if they have the same points. -/\n@[ext] lemma ext {s1 s2 : affine_subspace k P} (h : (s1 : set P) = s2) : s1 = s2 :=\nbegin\n  cases s1,\n  cases s2,\n  congr,\n  exact h\nend\n\n@[simp] lemma ext_iff (s\u2081 s\u2082 : affine_subspace k P) :\n  (s\u2081 : set P) = s\u2082 \u2194 s\u2081 = s\u2082 :=\n\u27e8ext, by tidy\u27e9\n\n/-- Two affine subspaces with the same direction and nonempty\nintersection are equal. -/\nlemma ext_of_direction_eq {s1 s2 : affine_subspace k P} (hd : s1.direction = s2.direction)\n    (hn : ((s1 : set P) \u2229 s2).nonempty) : s1 = s2 :=\nbegin\n  ext p,\n  have hq1 := set.mem_of_mem_inter_left hn.some_mem,\n  have hq2 := set.mem_of_mem_inter_right hn.some_mem,\n  split,\n  { intro hp,\n    rw \u2190vsub_vadd p hn.some,\n    refine vadd_mem_of_mem_direction _ hq2,\n    rw \u2190hd,\n    exact vsub_mem_direction hp hq1 },\n  { intro hp,\n    rw \u2190vsub_vadd p hn.some,\n    refine vadd_mem_of_mem_direction _ hq1,\n    rw hd,\n    exact vsub_mem_direction hp hq2 }\nend\n\ninstance to_add_torsor (s : affine_subspace k P) [nonempty s] : add_torsor s.direction s :=\n{ vadd := \u03bb a b, \u27e8(a:V) +\u1d65 (b:P), vadd_mem_of_mem_direction a.2 b.2\u27e9,\n  zero_vadd := by simp,\n  add_vadd := \u03bb a b c, by { ext, apply add_vadd },\n  vsub := \u03bb a b, \u27e8(a:P) -\u1d65 (b:P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2 \u27e9,\n  nonempty := by apply_instance,\n  vsub_vadd' := \u03bb a b, by { ext, apply add_torsor.vsub_vadd' },\n  vadd_vsub' := \u03bb a b, by { ext, apply add_torsor.vadd_vsub' } }\n\n@[simp, norm_cast] lemma coe_vsub (s : affine_subspace k P) [nonempty s] (a b : s) :\n  \u2191(a -\u1d65 b) = (a:P) -\u1d65 (b:P) :=\nrfl\n\n@[simp, norm_cast] lemma coe_vadd (s : affine_subspace k P) [nonempty s] (a : s.direction) (b : s) :\n  \u2191(a +\u1d65 b) = (a:V) +\u1d65 (b:P) :=\nrfl\n\n/-- Two affine subspaces with nonempty intersection are equal if and\nonly if their directions are equal. -/\nlemma eq_iff_direction_eq_of_mem {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h\u2081 : p \u2208 s\u2081)\n  (h\u2082 : p \u2208 s\u2082) : s\u2081 = s\u2082 \u2194 s\u2081.direction = s\u2082.direction :=\n\u27e8\u03bb h, h \u25b8 rfl, \u03bb h, ext_of_direction_eq h \u27e8p, h\u2081, h\u2082\u27e9\u27e9\n\n/-- Construct an affine subspace from a point and a direction. -/\ndef mk' (p : P) (direction : submodule k V) : affine_subspace k P :=\n{ carrier := {q | \u2203 v \u2208 direction, q = v +\u1d65 p},\n  smul_vsub_vadd_mem := \u03bb c p1 p2 p3 hp1 hp2 hp3, begin\n    rcases hp1 with \u27e8v1, hv1, hp1\u27e9,\n    rcases hp2 with \u27e8v2, hv2, hp2\u27e9,\n    rcases hp3 with \u27e8v3, hv3, hp3\u27e9,\n    use [c \u2022 (v1 - v2) + v3,\n         direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3],\n    simp [hp1, hp2, hp3, vadd_vadd]\n  end }\n\n/-- An affine subspace constructed from a point and a direction contains\nthat point. -/\nlemma self_mem_mk' (p : P) (direction : submodule k V) :\n  p \u2208 mk' p direction :=\n\u27e80, \u27e8direction.zero_mem, (zero_vadd _ _).symm\u27e9\u27e9\n\n/-- An affine subspace constructed from a point and a direction contains\nthe result of adding a vector in that direction to that point. -/\nlemma vadd_mem_mk' {v : V} (p : P) {direction : submodule k V} (hv : v \u2208 direction) :\n  v +\u1d65 p \u2208 mk' p direction :=\n\u27e8v, hv, rfl\u27e9\n\n/-- An affine subspace constructed from a point and a direction is\nnonempty. -/\nlemma mk'_nonempty (p : P) (direction : submodule k V) : (mk' p direction : set P).nonempty :=\n\u27e8p, self_mem_mk' p direction\u27e9\n\n/-- The direction of an affine subspace constructed from a point and a\ndirection. -/\n@[simp] lemma direction_mk' (p : P) (direction : submodule k V) :\n  (mk' p direction).direction = direction :=\nbegin\n  ext v,\n  rw mem_direction_iff_eq_vsub (mk'_nonempty _ _),\n  split,\n  { rintros \u27e8p1, \u27e8v1, hv1, hp1\u27e9, p2, \u27e8v2, hv2, hp2\u27e9, hv\u27e9,\n    rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right],\n    exact direction.sub_mem  hv1 hv2 },\n  { exact \u03bb hv, \u27e8v +\u1d65 p, vadd_mem_mk' _ hv, p,\n                 self_mem_mk' _ _, (vadd_vsub _ _).symm\u27e9 }\nend\n\n/-- Constructing an affine subspace from a point in a subspace and\nthat subspace's direction yields the original subspace. -/\n@[simp] lemma mk'_eq {s : affine_subspace k P} {p : P} (hp : p \u2208 s) : mk' p s.direction = s :=\next_of_direction_eq (direction_mk' p s.direction)\n                    \u27e8p, set.mem_inter (self_mem_mk' _ _) hp\u27e9\n\n/-- If an affine subspace contains a set of points, it contains the\n`span_points` of that set. -/\nlemma span_points_subset_coe_of_subset_coe {s : set P} {s1 : affine_subspace k P} (h : s \u2286 s1) :\n  span_points k s \u2286 s1 :=\nbegin\n  rintros p \u27e8p1, hp1, v, hv, hp\u27e9,\n  rw hp,\n  have hp1s1 : p1 \u2208 (s1 : set P) := set.mem_of_mem_of_subset hp1 h,\n  refine vadd_mem_of_mem_direction _ hp1s1,\n  have hs : vector_span k s \u2264 s1.direction := vector_span_mono k h,\n  rw set_like.le_def at hs,\n  rw \u2190set_like.mem_coe,\n  exact set.mem_of_mem_of_subset hv hs\nend\n\nend affine_subspace\n\nlemma affine_map.line_map_mem\n  {k V P : Type*} [ring k] [add_comm_group V] [module k V] [add_torsor V P]\n  {Q : affine_subspace k P} {p\u2080 p\u2081 : P} (c : k) (h\u2080 : p\u2080 \u2208 Q) (h\u2081 : p\u2081 \u2208 Q) :\n  affine_map.line_map p\u2080 p\u2081 c \u2208 Q :=\nbegin\n  rw affine_map.line_map_apply,\n  exact Q.smul_vsub_vadd_mem c h\u2081 h\u2080 h\u2080,\nend\n\nsection affine_span\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\n/-- The affine span of a set of points is the smallest affine subspace\ncontaining those points. (Actually defined here in terms of spans in\nmodules.) -/\ndef affine_span (s : set P) : affine_subspace k P :=\n{ carrier := span_points k s,\n  smul_vsub_vadd_mem := \u03bb c p1 p2 p3 hp1 hp2 hp3,\n    vadd_mem_span_points_of_mem_span_points_of_mem_vector_span k hp3\n      ((vector_span k s).smul_mem c\n        (vsub_mem_vector_span_of_mem_span_points_of_mem_span_points k hp1 hp2)) }\n\n/-- The affine span, converted to a set, is `span_points`. -/\n@[simp] lemma coe_affine_span (s : set P) :\n  (affine_span k s : set P) = span_points k s :=\nrfl\n\n/-- A set is contained in its affine span. -/\nlemma subset_affine_span (s : set P) : s \u2286 affine_span k s :=\nsubset_span_points k s\n\n/-- The direction of the affine span is the `vector_span`. -/\nlemma direction_affine_span (s : set P) : (affine_span k s).direction = vector_span k s :=\nbegin\n  apply le_antisymm,\n  { refine submodule.span_le.2 _,\n    rintros v \u27e8p1, p3, \u27e8p2, hp2, v1, hv1, hp1\u27e9, \u27e8p4, hp4, v2, hv2, hp3\u27e9, rfl\u27e9,\n    rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, set_like.mem_coe],\n    exact (vector_span k s).sub_mem ((vector_span k s).add_mem hv1\n      (vsub_mem_vector_span k hp2 hp4)) hv2 },\n  { exact vector_span_mono k (subset_span_points k s) }\nend\n\n/-- A point in a set is in its affine span. -/\nlemma mem_affine_span {p : P} {s : set P} (hp : p \u2208 s) : p \u2208 affine_span k s :=\nmem_span_points k p s hp\n\nend affine_span\n\nnamespace affine_subspace\n\nvariables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [S : affine_space V P]\ninclude S\n\ninstance : complete_lattice (affine_subspace k P) :=\n{ sup := \u03bb s1 s2, affine_span k (s1 \u222a s2),\n  le_sup_left := \u03bb s1 s2, set.subset.trans (set.subset_union_left s1 s2)\n                                           (subset_span_points k _),\n  le_sup_right :=  \u03bb s1 s2, set.subset.trans (set.subset_union_right s1 s2)\n                                             (subset_span_points k _),\n  sup_le := \u03bb s1 s2 s3 hs1 hs2, span_points_subset_coe_of_subset_coe (set.union_subset hs1 hs2),\n  inf := \u03bb s1 s2, mk (s1 \u2229 s2)\n                     (\u03bb c p1 p2 p3 hp1 hp2 hp3,\n                       \u27e8s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1,\n                       s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2\u27e9),\n  inf_le_left := \u03bb _ _, set.inter_subset_left _ _,\n  inf_le_right := \u03bb _ _, set.inter_subset_right _ _,\n  le_inf := \u03bb _ _ _, set.subset_inter,\n  top := { carrier := set.univ,\n    smul_vsub_vadd_mem := \u03bb _ _ _ _ _ _ _, set.mem_univ _ },\n  le_top := \u03bb _ _ _, set.mem_univ _,\n  bot := { carrier := \u2205,\n    smul_vsub_vadd_mem := \u03bb _ _ _ _, false.elim },\n  bot_le := \u03bb _ _, false.elim,\n  Sup := \u03bb s, affine_span k (\u22c3 s' \u2208 s, (s' : set P)),\n  Inf := \u03bb s, mk (\u22c2 s' \u2208 s, (s' : set P))\n                 (\u03bb c p1 p2 p3 hp1 hp2 hp3, set.mem_bInter_iff.2 $ \u03bb s2 hs2,\n                   s2.smul_vsub_vadd_mem c (set.mem_bInter_iff.1 hp1 s2 hs2)\n                                           (set.mem_bInter_iff.1 hp2 s2 hs2)\n                                           (set.mem_bInter_iff.1 hp3 s2 hs2)),\n  le_Sup := \u03bb _ _ h, set.subset.trans (set.subset_bUnion_of_mem h) (subset_span_points k _),\n  Sup_le := \u03bb _ _ h, span_points_subset_coe_of_subset_coe (set.bUnion_subset h),\n  Inf_le := \u03bb _ _, set.bInter_subset_of_mem,\n  le_Inf := \u03bb _ _, set.subset_bInter,\n  .. partial_order.lift (coe : affine_subspace k P \u2192 set P) (\u03bb _ _, ext) }\n\ninstance : inhabited (affine_subspace k P) := \u27e8\u22a4\u27e9\n\n/-- The `\u2264` order on subspaces is the same as that on the corresponding\nsets. -/\nlemma le_def (s1 s2 : affine_subspace k P) : s1 \u2264 s2 \u2194 (s1 : set P) \u2286 s2 :=\niff.rfl\n\n/-- One subspace is less than or equal to another if and only if all\nits points are in the second subspace. -/\nlemma le_def' (s1 s2 : affine_subspace k P) : s1 \u2264 s2 \u2194 \u2200 p \u2208 s1, p \u2208 s2 :=\niff.rfl\n\n/-- The `<` order on subspaces is the same as that on the corresponding\nsets. -/\nlemma lt_def (s1 s2 : affine_subspace k P) : s1 < s2 \u2194 (s1 : set P) \u2282 s2 :=\niff.rfl\n\n/-- One subspace is not less than or equal to another if and only if\nit has a point not in the second subspace. -/\nlemma not_le_iff_exists (s1 s2 : affine_subspace k P) : \u00ac s1 \u2264 s2 \u2194 \u2203 p \u2208 s1, p \u2209 s2 :=\nset.not_subset\n\n/-- If a subspace is less than another, there is a point only in the\nsecond. -/\nlemma exists_of_lt {s1 s2 : affine_subspace k P} (h : s1 < s2) : \u2203 p \u2208 s2, p \u2209 s1 :=\nset.exists_of_ssubset h\n\n/-- A subspace is less than another if and only if it is less than or\nequal to the second subspace and there is a point only in the\nsecond. -/\nlemma lt_iff_le_and_exists (s1 s2 : affine_subspace k P) : s1 < s2 \u2194 s1 \u2264 s2 \u2227 \u2203 p \u2208 s2, p \u2209 s1 :=\nby rw [lt_iff_le_not_le, not_le_iff_exists]\n\n/-- If an affine subspace is nonempty and contained in another with\nthe same direction, they are equal. -/\nlemma eq_of_direction_eq_of_nonempty_of_le {s\u2081 s\u2082 : affine_subspace k P}\n  (hd : s\u2081.direction = s\u2082.direction) (hn : (s\u2081 : set P).nonempty) (hle : s\u2081 \u2264 s\u2082) :\n  s\u2081 = s\u2082 :=\nlet \u27e8p, hp\u27e9 := hn in ext_of_direction_eq hd \u27e8p, hp, hle hp\u27e9\n\nvariables (k V)\n\n/-- The affine span is the `Inf` of subspaces containing the given\npoints. -/\nlemma affine_span_eq_Inf (s : set P) : affine_span k s = Inf {s' | s \u2286 s'} :=\nle_antisymm (span_points_subset_coe_of_subset_coe (set.subset_bInter (\u03bb _ h, h)))\n            (Inf_le (subset_span_points k _))\n\nvariables (P)\n\n/-- The Galois insertion formed by `affine_span` and coercion back to\na set. -/\nprotected def gi : galois_insertion (affine_span k) (coe : affine_subspace k P \u2192 set P) :=\n{ choice := \u03bb s _, affine_span k s,\n  gc := \u03bb s1 s2, \u27e8\u03bb h, set.subset.trans (subset_span_points k s1) h,\n                       span_points_subset_coe_of_subset_coe\u27e9,\n  le_l_u := \u03bb _, subset_span_points k _,\n  choice_eq := \u03bb _ _, rfl }\n\n/-- The span of the empty set is `\u22a5`. -/\n@[simp] lemma span_empty : affine_span k (\u2205 : set P) = \u22a5 :=\n(affine_subspace.gi k V P).gc.l_bot\n\n/-- The span of `univ` is `\u22a4`. -/\n@[simp] lemma span_univ : affine_span k (set.univ : set P) = \u22a4 :=\neq_top_iff.2 $ subset_span_points k _\n\nvariables {k V P}\n\nlemma _root_.affine_span_le {s : set P} {Q : affine_subspace k P} :\n  affine_span k s \u2264 Q \u2194 s \u2286 (Q : set P) :=\n(affine_subspace.gi k V P).gc _ _\n\nvariables (k V) {P}\n\n/-- The affine span of a single point, coerced to a set, contains just\nthat point. -/\n@[simp] lemma coe_affine_span_singleton (p : P) : (affine_span k ({p} : set P) : set P) = {p} :=\nbegin\n  ext x,\n  rw [mem_coe, \u2190vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_singleton p)) _,\n      direction_affine_span],\n  simp\nend\n\n/-- A point is in the affine span of a single point if and only if\nthey are equal. -/\n@[simp] lemma mem_affine_span_singleton (p1 p2 : P) :\n  p1 \u2208 affine_span k ({p2} : set P) \u2194 p1 = p2 :=\nby simp [\u2190mem_coe]\n\n/-- The span of a union of sets is the sup of their spans. -/\nlemma span_union (s t : set P) : affine_span k (s \u222a t) = affine_span k s \u2294 affine_span k t :=\n(affine_subspace.gi k V P).gc.l_sup\n\n/-- The span of a union of an indexed family of sets is the sup of\ntheir spans. -/\nlemma span_Union {\u03b9 : Type*} (s : \u03b9 \u2192 set P) :\n  affine_span k (\u22c3 i, s i) = \u2a06 i, affine_span k (s i) :=\n(affine_subspace.gi k V P).gc.l_supr\n\nvariables (P)\n\n/-- `\u22a4`, coerced to a set, is the whole set of points. -/\n@[simp] lemma top_coe : ((\u22a4 : affine_subspace k P) : set P) = set.univ :=\nrfl\n\nvariables {P}\n\n/-- All points are in `\u22a4`. -/\nlemma mem_top (p : P) : p \u2208 (\u22a4 : affine_subspace k P) :=\nset.mem_univ p\n\nvariables (P)\n\n/-- The direction of `\u22a4` is the whole module as a submodule. -/\n@[simp] lemma direction_top : (\u22a4 : affine_subspace k P).direction = \u22a4 :=\nbegin\n  cases S.nonempty with p,\n  ext v,\n  refine \u27e8imp_intro submodule.mem_top, \u03bb hv, _\u27e9,\n  have hpv : (v +\u1d65 p -\u1d65 p : V) \u2208 (\u22a4 : affine_subspace k P).direction :=\n    vsub_mem_direction (mem_top k V _) (mem_top k V _),\n  rwa vadd_vsub at hpv\nend\n\n/-- `\u22a5`, coerced to a set, is the empty set. -/\n@[simp] lemma bot_coe : ((\u22a5 : affine_subspace k P) : set P) = \u2205 :=\nrfl\n\nlemma bot_ne_top : (\u22a5 : affine_subspace k P) \u2260 \u22a4 :=\nbegin\n  intros contra,\n  rw [\u2190 ext_iff, bot_coe, top_coe] at contra,\n  exact set.empty_ne_univ contra,\nend\n\ninstance : nontrivial (affine_subspace k P) := \u27e8\u27e8\u22a5, \u22a4, bot_ne_top k V P\u27e9\u27e9\n\nlemma nonempty_of_affine_span_eq_top {s : set P} (h : affine_span k s = \u22a4) : s.nonempty :=\nbegin\n  rw \u2190 set.ne_empty_iff_nonempty,\n  rintros rfl,\n  rw affine_subspace.span_empty at h,\n  exact bot_ne_top k V P h,\nend\n\n/-- If the affine span of a set is `\u22a4`, then the vector span of the same set is the `\u22a4`. -/\nlemma vector_span_eq_top_of_affine_span_eq_top {s : set P} (h : affine_span k s = \u22a4) :\n  vector_span k s = \u22a4 :=\nby rw [\u2190 direction_affine_span, h, direction_top]\n\n/-- For a nonempty set, the affine span is `\u22a4` iff its vector span is `\u22a4`. -/\nlemma affine_span_eq_top_iff_vector_span_eq_top_of_nonempty {s : set P} (hs : s.nonempty) :\n  affine_span k s = \u22a4 \u2194 vector_span k s = \u22a4 :=\nbegin\n  refine \u27e8vector_span_eq_top_of_affine_span_eq_top k V P, _\u27e9,\n  intros h,\n  suffices : nonempty (affine_span k s),\n  { obtain \u27e8p, hp : p \u2208 affine_span k s\u27e9 := this,\n    rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affine_span, h, direction_top] },\n  obtain \u27e8x, hx\u27e9 := hs,\n  exact \u27e8\u27e8x, mem_affine_span k hx\u27e9\u27e9,\nend\n\n/-- For a non-trivial space, the affine span of a set is `\u22a4` iff its vector span is `\u22a4`. -/\nlemma affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial {s : set P} [nontrivial P] :\n  affine_span k s = \u22a4 \u2194 vector_span k s = \u22a4 :=\nbegin\n  cases s.eq_empty_or_nonempty with hs hs,\n  { simp [hs, subsingleton_iff_bot_eq_top, add_torsor.subsingleton_iff V P, not_subsingleton], },\n  { rw affine_span_eq_top_iff_vector_span_eq_top_of_nonempty k V P hs, },\nend\n\nlemma card_pos_of_affine_span_eq_top {\u03b9 : Type*} [fintype \u03b9] {p : \u03b9 \u2192 P}\n  (h : affine_span k (range p) = \u22a4) :\n  0 < fintype.card \u03b9 :=\nbegin\n  obtain \u27e8-, \u27e8i, -\u27e9\u27e9 := nonempty_of_affine_span_eq_top k V P h,\n  exact fintype.card_pos_iff.mpr \u27e8i\u27e9,\nend\n\nvariables {P}\n\n/-- No points are in `\u22a5`. -/\nlemma not_mem_bot (p : P) : p \u2209 (\u22a5 : affine_subspace k P) :=\nset.not_mem_empty p\n\nvariables (P)\n\n/-- The direction of `\u22a5` is the submodule `\u22a5`. -/\n@[simp] lemma direction_bot : (\u22a5 : affine_subspace k P).direction = \u22a5 :=\nby rw [direction_eq_vector_span, bot_coe, vector_span_def, vsub_empty, submodule.span_empty]\n\nvariables {k V P}\n\nlemma subsingleton_of_subsingleton_span_eq_top {s : set P} (h\u2081 : s.subsingleton)\n  (h\u2082 : affine_span k s = \u22a4) : subsingleton P :=\nbegin\n  obtain \u27e8p, hp\u27e9 := affine_subspace.nonempty_of_affine_span_eq_top k V P h\u2082,\n  have : s = {p}, { exact subset.antisymm (\u03bb q hq, h\u2081 hq hp) (by simp [hp]), },\n  rw [this, \u2190 affine_subspace.ext_iff, affine_subspace.coe_affine_span_singleton,\n    affine_subspace.top_coe, eq_comm, \u2190 subsingleton_iff_singleton (mem_univ _)] at h\u2082,\n  exact subsingleton_of_univ_subsingleton h\u2082,\nend\n\nlemma eq_univ_of_subsingleton_span_eq_top {s : set P} (h\u2081 : s.subsingleton)\n  (h\u2082 : affine_span k s = \u22a4) : s = (univ : set P) :=\nbegin\n  obtain \u27e8p, hp\u27e9 := affine_subspace.nonempty_of_affine_span_eq_top k V P h\u2082,\n  have : s = {p}, { exact subset.antisymm (\u03bb q hq, h\u2081 hq hp) (by simp [hp]), },\n  rw [this, eq_comm, \u2190 subsingleton_iff_singleton (mem_univ p), subsingleton_univ_iff],\n  exact subsingleton_of_subsingleton_span_eq_top h\u2081 h\u2082,\nend\n\n/-- A nonempty affine subspace is `\u22a4` if and only if its direction is\n`\u22a4`. -/\n@[simp] lemma direction_eq_top_iff_of_nonempty {s : affine_subspace k P}\n  (h : (s : set P).nonempty) : s.direction = \u22a4 \u2194 s = \u22a4 :=\nbegin\n  split,\n  { intro hd,\n    rw \u2190direction_top k V P at hd,\n    refine ext_of_direction_eq hd _,\n    simp [h] },\n  { rintro rfl,\n    simp }\nend\n\n/-- The inf of two affine subspaces, coerced to a set, is the\nintersection of the two sets of points. -/\n@[simp] lemma inf_coe (s1 s2 : affine_subspace k P) : ((s1 \u2293 s2) : set P) = s1 \u2229 s2 :=\nrfl\n\n/-- A point is in the inf of two affine subspaces if and only if it is\nin both of them. -/\nlemma mem_inf_iff (p : P) (s1 s2 : affine_subspace k P) : p \u2208 s1 \u2293 s2 \u2194 p \u2208 s1 \u2227 p \u2208 s2 :=\niff.rfl\n\n/-- The direction of the inf of two affine subspaces is less than or\nequal to the inf of their directions. -/\nlemma direction_inf (s1 s2 : affine_subspace k P) :\n  (s1 \u2293 s2).direction \u2264 s1.direction \u2293 s2.direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact le_inf\n    (Inf_le_Inf (\u03bb p hp, trans (vsub_self_mono (inter_subset_left _ _)) hp))\n    (Inf_le_Inf (\u03bb p hp, trans (vsub_self_mono (inter_subset_right _ _)) hp))\nend\n\n/-- If two affine subspaces have a point in common, the direction of\ntheir inf equals the inf of their directions. -/\nlemma direction_inf_of_mem {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h\u2081 : p \u2208 s\u2081) (h\u2082 : p \u2208 s\u2082) :\n  (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\nbegin\n  ext v,\n  rw [submodule.mem_inf, \u2190vadd_mem_iff_mem_direction v h\u2081, \u2190vadd_mem_iff_mem_direction v h\u2082,\n      \u2190vadd_mem_iff_mem_direction v ((mem_inf_iff p s\u2081 s\u2082).2 \u27e8h\u2081, h\u2082\u27e9), mem_inf_iff]\nend\n\n/-- If two affine subspaces have a point in their inf, the direction\nof their inf equals the inf of their directions. -/\nlemma direction_inf_of_mem_inf {s\u2081 s\u2082 : affine_subspace k P} {p : P} (h : p \u2208 s\u2081 \u2293 s\u2082) :\n  (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\ndirection_inf_of_mem ((mem_inf_iff p s\u2081 s\u2082).1 h).1 ((mem_inf_iff p s\u2081 s\u2082).1 h).2\n\n/-- If one affine subspace is less than or equal to another, the same\napplies to their directions. -/\nlemma direction_le {s1 s2 : affine_subspace k P} (h : s1 \u2264 s2) : s1.direction \u2264 s2.direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact vector_span_mono k h\nend\n\n/-- If one nonempty affine subspace is less than another, the same\napplies to their directions -/\nlemma direction_lt_of_nonempty {s1 s2 : affine_subspace k P} (h : s1 < s2)\n    (hn : (s1 : set P).nonempty) : s1.direction < s2.direction :=\nbegin\n  cases hn with p hp,\n  rw lt_iff_le_and_exists at h,\n  rcases h with \u27e8hle, p2, hp2, hp2s1\u27e9,\n  rw set_like.lt_iff_le_and_exists,\n  use [direction_le hle, p2 -\u1d65 p, vsub_mem_direction hp2 (hle hp)],\n  intro hm,\n  rw vsub_right_mem_direction_iff_mem hp p2 at hm,\n  exact hp2s1 hm\nend\n\n/-- The sup of the directions of two affine subspaces is less than or\nequal to the direction of their sup. -/\nlemma sup_direction_le (s1 s2 : affine_subspace k P) :\n  s1.direction \u2294 s2.direction \u2264 (s1 \u2294 s2).direction :=\nbegin\n  repeat { rw [direction_eq_vector_span, vector_span_def] },\n  exact sup_le\n    (Inf_le_Inf (\u03bb p hp, set.subset.trans (vsub_self_mono (le_sup_left : s1 \u2264 s1 \u2294 s2)) hp))\n    (Inf_le_Inf (\u03bb p hp, set.subset.trans (vsub_self_mono (le_sup_right : s2 \u2264 s1 \u2294 s2)) hp))\nend\n\n/-- The sup of the directions of two nonempty affine subspaces with\nempty intersection is less than the direction of their sup. -/\nlemma sup_direction_lt_of_nonempty_of_inter_empty {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty) (he : (s1 \u2229 s2 : set P) = \u2205) :\n  s1.direction \u2294 s2.direction < (s1 \u2294 s2).direction :=\nbegin\n  cases h1 with p1 hp1,\n  cases h2 with p2 hp2,\n  rw set_like.lt_iff_le_and_exists,\n  use [sup_direction_le s1 s2, p2 -\u1d65 p1,\n       vsub_mem_direction ((le_sup_right : s2 \u2264 s1 \u2294 s2) hp2) ((le_sup_left : s1 \u2264 s1 \u2294 s2) hp1)],\n  intro h,\n  rw submodule.mem_sup at h,\n  rcases h with \u27e8v1, hv1, v2, hv2, hv1v2\u27e9,\n  rw [\u2190sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc,\n      \u2190vadd_vsub_assoc, \u2190neg_neg v2, add_comm, \u2190sub_eq_add_neg, \u2190vsub_vadd_eq_vsub_sub,\n      vsub_eq_zero_iff_eq] at hv1v2,\n  refine set.nonempty.ne_empty _ he,\n  use [v1 +\u1d65 p1, vadd_mem_of_mem_direction hv1 hp1],\n  rw hv1v2,\n  exact vadd_mem_of_mem_direction (submodule.neg_mem _ hv2) hp2\nend\n\n/-- If the directions of two nonempty affine subspaces span the whole\nmodule, they have nonempty intersection. -/\nlemma inter_nonempty_of_nonempty_of_sup_direction_eq_top {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)\n    (hd : s1.direction \u2294 s2.direction = \u22a4) : ((s1 : set P) \u2229 s2).nonempty :=\nbegin\n  by_contradiction h,\n  rw set.not_nonempty_iff_eq_empty at h,\n  have hlt := sup_direction_lt_of_nonempty_of_inter_empty h1 h2 h,\n  rw hd at hlt,\n  exact not_top_lt hlt\nend\n\n/-- If the directions of two nonempty affine subspaces are complements\nof each other, they intersect in exactly one point. -/\nlemma inter_eq_singleton_of_nonempty_of_is_compl {s1 s2 : affine_subspace k P}\n    (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)\n    (hd : is_compl s1.direction s2.direction) : \u2203 p, (s1 : set P) \u2229 s2 = {p} :=\nbegin\n  cases inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top with p hp,\n  use p,\n  ext q,\n  rw set.mem_singleton_iff,\n  split,\n  { rintros \u27e8hq1, hq2\u27e9,\n    have hqp : q -\u1d65 p \u2208 s1.direction \u2293 s2.direction :=\n      \u27e8vsub_mem_direction hq1 hp.1, vsub_mem_direction hq2 hp.2\u27e9,\n    rwa [hd.inf_eq_bot, submodule.mem_bot, vsub_eq_zero_iff_eq] at hqp },\n  { exact \u03bb h, h.symm \u25b8 hp }\nend\n\n/-- Coercing a subspace to a set then taking the affine span produces\nthe original subspace. -/\n@[simp] lemma affine_span_coe (s : affine_subspace k P) : affine_span k (s : set P) = s :=\nbegin\n  refine le_antisymm _ (subset_span_points _ _),\n  rintros p \u27e8p1, hp1, v, hv, rfl\u27e9,\n  exact vadd_mem_of_mem_direction hv hp1\nend\n\nend affine_subspace\n\nsection affine_space'\n\nvariables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\nvariables {\u03b9 : Type*}\ninclude V\n\nopen affine_subspace set\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left. -/\nlemma vector_span_eq_span_vsub_set_left {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65) p '' s) :=\nbegin\n  rw vector_span_def,\n  refine le_antisymm _ (submodule.span_mono _),\n  { rw submodule.span_le,\n    rintros v \u27e8p1, p2, hp1, hp2, hv\u27e9,\n    rw \u2190vsub_sub_vsub_cancel_left p1 p2 p at hv,\n    rw [\u2190hv, set_like.mem_coe, submodule.mem_span],\n    exact \u03bb m hm, submodule.sub_mem _ (hm \u27e8p2, hp2, rfl\u27e9) (hm \u27e8p1, hp1, rfl\u27e9) },\n  { rintros v \u27e8p2, hp2, hv\u27e9,\n    exact \u27e8p, p2, hp, hp2, hv\u27e9 }\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right. -/\nlemma vector_span_eq_span_vsub_set_right {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65 p) '' s) :=\nbegin\n  rw vector_span_def,\n  refine le_antisymm _ (submodule.span_mono _),\n  { rw submodule.span_le,\n    rintros v \u27e8p1, p2, hp1, hp2, hv\u27e9,\n    rw \u2190vsub_sub_vsub_cancel_right p1 p2 p at hv,\n    rw [\u2190hv, set_like.mem_coe, submodule.mem_span],\n    exact \u03bb m hm, submodule.sub_mem _ (hm \u27e8p1, hp1, rfl\u27e9) (hm \u27e8p2, hp2, rfl\u27e9) },\n  { rintros v \u27e8p2, hp2, hv\u27e9,\n    exact \u27e8p2, p, hp2, hp, hv\u27e9 }\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_set_left_ne {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65) p '' (s \\ {p})) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_left k hp, \u2190set.insert_eq_of_mem hp,\n                 \u2190set.insert_diff_singleton, set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_set_right_ne {s : set P} {p : P} (hp : p \u2208 s) :\n  vector_span k s = submodule.span k ((-\u1d65 p) '' (s \\ {p})) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_right k hp, \u2190set.insert_eq_of_mem hp,\n                 \u2190set.insert_diff_singleton, set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right, excluding the subtraction of that point from\nitself. -/\nlemma vector_span_eq_span_vsub_finset_right_ne {s : finset P} {p : P} (hp : p \u2208 s) :\n  vector_span k (s : set P) = submodule.span k ((s.erase p).image (-\u1d65 p)) :=\nby simp [vector_span_eq_span_vsub_set_right_ne _ (finset.mem_coe.mpr hp)]\n\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the left, excluding the\nsubtraction of that point from itself. -/\nlemma vector_span_image_eq_span_vsub_set_left_ne (p : \u03b9 \u2192 P) {s : set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  vector_span k (p '' s) = submodule.span k ((-\u1d65) (p i) '' (p '' (s \\ {i}))) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_left k (set.mem_image_of_mem p hi),\n                 \u2190set.insert_eq_of_mem hi, \u2190set.insert_diff_singleton, set.image_insert_eq,\n                 set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the right, excluding the\nsubtraction of that point from itself. -/\nlemma vector_span_image_eq_span_vsub_set_right_ne (p : \u03b9 \u2192 P) {s : set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n  vector_span k (p '' s) = submodule.span k ((-\u1d65 (p i)) '' (p '' (s \\ {i}))) :=\nbegin\n  conv_lhs { rw [vector_span_eq_span_vsub_set_right k (set.mem_image_of_mem p hi),\n                 \u2190set.insert_eq_of_mem hi, \u2190set.insert_diff_singleton, set.image_insert_eq,\n                 set.image_insert_eq] },\n  simp [submodule.span_insert_eq_span]\nend\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left. -/\nlemma vector_span_range_eq_span_range_vsub_left (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : \u03b9), p i0 -\u1d65 p i)) :=\nby rw [vector_span_eq_span_vsub_set_left k (set.mem_range_self i0), \u2190set.range_comp]\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right. -/\nlemma vector_span_range_eq_span_range_vsub_right (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : \u03b9), p i -\u1d65 p i0)) :=\nby rw [vector_span_eq_span_vsub_set_right k (set.mem_range_self i0), \u2190set.range_comp]\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left, excluding the subtraction\nof that point from itself. -/\nlemma vector_span_range_eq_span_range_vsub_left_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : {x // x \u2260 i\u2080}), p i\u2080 -\u1d65 p i)) :=\nbegin\n  rw [\u2190set.image_univ, vector_span_image_eq_span_vsub_set_left_ne k _ (set.mem_univ i\u2080)],\n  congr' with v,\n  simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,\n             subtype.coe_mk],\n  split,\n  { rintros \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9,\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9 },\n  { exact \u03bb \u27e8i\u2081, hi\u2081, hv\u27e9, \u27e8p i\u2081, \u27e8i\u2081, \u27e8set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9 }\nend\n\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right, excluding the subtraction\nof that point from itself. -/\nlemma vector_span_range_eq_span_range_vsub_right_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n  vector_span k (set.range p) = submodule.span k (set.range (\u03bb (i : {x // x \u2260 i\u2080}), p i -\u1d65 p i\u2080)) :=\nbegin\n  rw [\u2190set.image_univ, vector_span_image_eq_span_vsub_set_right_ne k _ (set.mem_univ i\u2080)],\n  congr' with v,\n  simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,\n             subtype.coe_mk],\n  split,\n  { rintros \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9,\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9 },\n  { exact \u03bb \u27e8i\u2081, hi\u2081, hv\u27e9, \u27e8p i\u2081, \u27e8i\u2081, \u27e8set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9 }\nend\n\n/-- The affine span of a set is nonempty if and only if that set\nis. -/\nlemma affine_span_nonempty (s : set P) :\n  (affine_span k s : set P).nonempty \u2194 s.nonempty :=\nspan_points_nonempty k s\n\n/-- The affine span of a nonempty set is nonempty. -/\ninstance {s : set P} [nonempty s] : nonempty (affine_span k s) :=\n((affine_span_nonempty k s).mpr (nonempty_subtype.mp \u2039_\u203a)).to_subtype\n\nvariables {k}\n\n/-- Suppose a set of vectors spans `V`.  Then a point `p`, together\nwith those vectors added to `p`, spans `P`. -/\nlemma affine_span_singleton_union_vadd_eq_top_of_span_eq_top {s : set V} (p : P)\n    (h : submodule.span k (set.range (coe : s \u2192 V)) = \u22a4) :\n  affine_span k ({p} \u222a (\u03bb v, v +\u1d65 p) '' s) = \u22a4 :=\nbegin\n  convert ext_of_direction_eq _\n    \u27e8p,\n     mem_affine_span k (set.mem_union_left _ (set.mem_singleton _)),\n     mem_top k V p\u27e9,\n  rw [direction_affine_span, direction_top,\n      vector_span_eq_span_vsub_set_right k\n        ((set.mem_union_left _ (set.mem_singleton _)) : p \u2208 _), eq_top_iff, \u2190h],\n  apply submodule.span_mono,\n  rintros v \u27e8v', rfl\u27e9,\n  use (v' : V) +\u1d65 p,\n  simp\nend\n\nvariables (k)\n\n/-- `affine_span` is monotone. -/\n@[mono]\nlemma affine_span_mono {s\u2081 s\u2082 : set P} (h : s\u2081 \u2286 s\u2082) : affine_span k s\u2081 \u2264 affine_span k s\u2082 :=\nspan_points_subset_coe_of_subset_coe (set.subset.trans h (subset_affine_span k _))\n\n/-- Taking the affine span of a set, adding a point and taking the\nspan again produces the same results as adding the point to the set\nand taking the span. -/\nlemma affine_span_insert_affine_span (p : P) (ps : set P) :\n  affine_span k (insert p (affine_span k ps : set P)) = affine_span k (insert p ps) :=\nby rw [set.insert_eq, set.insert_eq, span_union, span_union, affine_span_coe]\n\n/-- If a point is in the affine span of a set, adding it to that set\ndoes not change the affine span. -/\nlemma affine_span_insert_eq_affine_span {p : P} {ps : set P} (h : p \u2208 affine_span k ps) :\n  affine_span k (insert p ps) = affine_span k ps :=\nbegin\n  rw \u2190mem_coe at h,\n  rw [\u2190affine_span_insert_affine_span, set.insert_eq_of_mem h, affine_span_coe]\nend\n\nend affine_space'\n\nnamespace affine_subspace\n\nvariables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]\n          [affine_space V P]\ninclude V\n\n/-- The direction of the sup of two nonempty affine subspaces is the\nsup of the two directions and of any one difference between points in\nthe two subspaces. -/\nlemma direction_sup {s1 s2 : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s1) (hp2 : p2 \u2208 s2) :\n  (s1 \u2294 s2).direction = s1.direction \u2294 s2.direction \u2294 k \u2219 (p2 -\u1d65 p1) :=\nbegin\n  refine le_antisymm _ _,\n  { change (affine_span k ((s1 : set P) \u222a s2)).direction \u2264 _,\n    rw \u2190mem_coe at hp1,\n    rw [direction_affine_span, vector_span_eq_span_vsub_set_right k (set.mem_union_left _ hp1),\n        submodule.span_le],\n    rintros v \u27e8p3, hp3, rfl\u27e9,\n    cases hp3,\n    { rw [sup_assoc, sup_comm, set_like.mem_coe, submodule.mem_sup],\n      use [0, submodule.zero_mem _, p3 -\u1d65 p1, vsub_mem_direction hp3 hp1],\n      rw zero_add },\n    { rw [sup_assoc, set_like.mem_coe, submodule.mem_sup],\n      use [0, submodule.zero_mem _, p3 -\u1d65 p1],\n      rw [and_comm, zero_add],\n      use rfl,\n      rw [\u2190vsub_add_vsub_cancel p3 p2 p1, submodule.mem_sup],\n      use [p3 -\u1d65 p2, vsub_mem_direction hp3 hp2, p2 -\u1d65 p1,\n           submodule.mem_span_singleton_self _] } },\n  { refine sup_le (sup_direction_le _ _) _,\n    rw [direction_eq_vector_span, vector_span_def],\n    exact Inf_le_Inf (\u03bb p hp, set.subset.trans\n      (set.singleton_subset_iff.2\n        (vsub_mem_vsub (mem_span_points k p2 _ (set.mem_union_right _ hp2))\n                       (mem_span_points k p1 _ (set.mem_union_left _ hp1))))\n      hp) }\nend\n\n/-- The direction of the span of the result of adding a point to a\nnonempty affine subspace is the sup of the direction of that subspace\nand of any one difference between that point and a point in the\nsubspace. -/\nlemma direction_affine_span_insert {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) :\n  (affine_span k (insert p2 (s : set P))).direction = submodule.span k {p2 -\u1d65 p1} \u2294 s.direction :=\nbegin\n  rw [sup_comm, \u2190set.union_singleton, \u2190coe_affine_span_singleton k V p2],\n  change (s \u2294 affine_span k {p2}).direction = _,\n  rw [direction_sup hp1 (mem_affine_span k (set.mem_singleton _)), direction_affine_span],\n  simp\nend\n\n/-- Given a point `p1` in an affine subspace `s`, and a point `p2`, a\npoint `p` is in the span of `s` with `p2` added if and only if it is a\nmultiple of `p2 -\u1d65 p1` added to a point in `s`. -/\nlemma mem_affine_span_insert_iff {s : affine_subspace k P} {p1 : P} (hp1 : p1 \u2208 s) (p2 p : P) :\n  p \u2208 affine_span k (insert p2 (s : set P)) \u2194\n    \u2203 (r : k) (p0 : P) (hp0 : p0 \u2208 s), p = r \u2022 (p2 -\u1d65 p1 : V) +\u1d65 p0 :=\nbegin\n  rw \u2190mem_coe at hp1,\n  rw [\u2190vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_insert_of_mem _ hp1)),\n      direction_affine_span_insert hp1, submodule.mem_sup],\n  split,\n  { rintros \u27e8v1, hv1, v2, hv2, hp\u27e9,\n    rw submodule.mem_span_singleton at hv1,\n    rcases hv1 with \u27e8r, rfl\u27e9,\n    use [r, v2 +\u1d65 p1, vadd_mem_of_mem_direction hv2 hp1],\n    symmetry' at hp,\n    rw [\u2190sub_eq_zero, \u2190vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hp,\n    rw [hp, vadd_vadd] },\n  { rintros \u27e8r, p3, hp3, rfl\u27e9,\n    use [r \u2022 (p2 -\u1d65 p1), submodule.mem_span_singleton.2 \u27e8r, rfl\u27e9, p3 -\u1d65 p1,\n         vsub_mem_direction hp3 hp1],\n    rw [vadd_vsub_assoc, add_comm] }\nend\n\nend affine_subspace\n\nsection maps\n\nvariables {k V\u2081 P\u2081 V\u2082 P\u2082 : Type*} [ring k]\nvariables [add_comm_group V\u2081] [module k V\u2081] [add_torsor V\u2081 P\u2081]\nvariables [add_comm_group V\u2082] [module k V\u2082] [add_torsor V\u2082 P\u2082]\ninclude V\u2081 V\u2082\n\nvariables (f : P\u2081 \u2192\u1d43[k] P\u2082)\n\n@[simp] lemma affine_map.vector_span_image_eq_submodule_map {s : set P\u2081} :\n  submodule.map f.linear (vector_span k s) = vector_span k (f '' s) :=\nby simp [f.image_vsub_image, vector_span_def]\n\nnamespace affine_subspace\n\n/-- The image of an affine subspace under an affine map as an affine subspace. -/\ndef map (s : affine_subspace k P\u2081) : affine_subspace k P\u2082 :=\n{ carrier := f '' s,\n  smul_vsub_vadd_mem :=\n    begin\n      rintros t - - - \u27e8p\u2081, h\u2081, rfl\u27e9 \u27e8p\u2082, h\u2082, rfl\u27e9 \u27e8p\u2083, h\u2083, rfl\u27e9,\n      use t \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2083,\n      suffices : t \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2083 \u2208 s, { by simp [this], },\n      exact s.smul_vsub_vadd_mem t h\u2081 h\u2082 h\u2083,\n    end }\n\n@[simp] lemma map_coe (s : affine_subspace k P\u2081) : (s.map f : set P\u2082) = f '' s := rfl\n\n@[simp] lemma map_bot : (\u22a5 : affine_subspace k P\u2081).map f = \u22a5 :=\nby { rw \u2190 ext_iff, exact image_empty f, }\n\n@[simp] lemma map_direction (s : affine_subspace k P\u2081) :\n  (s.map f).direction = s.direction.map f.linear :=\nby simp [direction_eq_vector_span]\n\nlemma map_span (s : set P\u2081) :\n  (affine_span k s).map f = affine_span k (f '' s) :=\nbegin\n  rcases s.eq_empty_or_nonempty with rfl | \u27e8p, hp\u27e9, { simp, },\n  apply ext_of_direction_eq,\n  { simp [direction_affine_span], },\n  { exact \u27e8f p, mem_image_of_mem f (subset_affine_span k _ hp),\n                subset_affine_span k _ (mem_image_of_mem f hp)\u27e9, },\nend\n\nend affine_subspace\n\nnamespace affine_map\n\n@[simp] lemma map_top_of_surjective (hf : function.surjective f) : affine_subspace.map f \u22a4 = \u22a4 :=\nbegin\n  rw \u2190 affine_subspace.ext_iff,\n  exact image_univ_of_surjective hf,\nend\n\nlemma span_eq_top_of_surjective {s : set P\u2081}\n  (hf : function.surjective f) (h : affine_span k s = \u22a4) :\n  affine_span k (f '' s) = \u22a4 :=\nby rw [\u2190 affine_subspace.map_span, h, map_top_of_surjective f hf]\n\nend affine_map\n\nlemma affine_equiv.span_eq_top_iff {s : set P\u2081} (e : P\u2081 \u2243\u1d43[k] P\u2082) :\n  affine_span k s = \u22a4 \u2194 affine_span k (e '' s) = \u22a4 :=\nbegin\n  refine \u27e8(e : P\u2081 \u2192\u1d43[k] P\u2082).span_eq_top_of_surjective e.surjective, _\u27e9,\n  intros h,\n  have : s = e.symm '' (e '' s), { simp [\u2190 image_comp], },\n  rw this,\n  exact (e.symm : P\u2082 \u2192\u1d43[k] P\u2081).span_eq_top_of_surjective e.symm.surjective h,\nend\n\nend maps\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/affine_space/affine_subspace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7117781056945827}}
{"text": "/-\nCopyright (c) 2019 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison, Justus Springer\n\n! This file was ported from Lean 3 source module category_theory.limits.lattice\n! leanprover-community/mathlib commit 69c6a5a12d8a2b159f20933e60115a4f2de62b58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.CompleteLattice\nimport Mathbin.Data.Fintype.Lattice\nimport Mathbin.CategoryTheory.Limits.Shapes.Pullbacks\nimport Mathbin.CategoryTheory.Category.Preorder\nimport Mathbin.CategoryTheory.Limits.Shapes.Products\nimport Mathbin.CategoryTheory.Limits.Shapes.FiniteLimits\n\n/-!\n# Limits in lattice categories are given by infimums and supremums.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\n\nuniverse w u\n\nopen CategoryTheory\n\nopen CategoryTheory.Limits\n\nnamespace CategoryTheory.Limits.CompleteLattice\n\nsection Semilattice\n\nvariable {\u03b1 : Type u}\n\nvariable {J : Type w} [SmallCategory J] [FinCategory J]\n\n#print CategoryTheory.Limits.CompleteLattice.finiteLimitCone /-\n/-- The limit cone over any functor from a finite diagram into a `semilattice_inf` with `order_top`.\n-/\ndef finiteLimitCone [SemilatticeInf \u03b1] [OrderTop \u03b1] (F : J \u2964 \u03b1) : LimitCone F\n    where\n  Cone :=\n    { pt := Finset.univ.inf F.obj\n      \u03c0 := { app := fun j => homOfLE (Finset.inf_le (Fintype.complete _)) } }\n  IsLimit := { lift := fun s => homOfLE (Finset.le_inf fun j _ => (s.\u03c0.app j).down.down) }\n#align category_theory.limits.complete_lattice.finite_limit_cone CategoryTheory.Limits.CompleteLattice.finiteLimitCone\n-/\n\n#print CategoryTheory.Limits.CompleteLattice.finiteColimitCocone /-\n/--\nThe colimit cocone over any functor from a finite diagram into a `semilattice_sup` with `order_bot`.\n-/\ndef finiteColimitCocone [SemilatticeSup \u03b1] [OrderBot \u03b1] (F : J \u2964 \u03b1) : ColimitCocone F\n    where\n  Cocone :=\n    { pt := Finset.univ.sup F.obj\n      \u03b9 := { app := fun i => homOfLE (Finset.le_sup (Fintype.complete _)) } }\n  IsColimit := { desc := fun s => homOfLE (Finset.sup_le fun j _ => (s.\u03b9.app j).down.down) }\n#align category_theory.limits.complete_lattice.finite_colimit_cocone CategoryTheory.Limits.CompleteLattice.finiteColimitCocone\n-/\n\n#print CategoryTheory.Limits.CompleteLattice.hasFiniteLimits_of_semilatticeInf_orderTop /-\n-- see Note [lower instance priority]\ninstance (priority := 100) hasFiniteLimits_of_semilatticeInf_orderTop [SemilatticeInf \u03b1]\n    [OrderTop \u03b1] : HasFiniteLimits \u03b1 :=\n  \u27e8fun J \ud835\udca5\u2081 \ud835\udca5\u2082 => { HasLimit := fun F => has_limit.mk (finite_limit_cone F) }\u27e9\n#align category_theory.limits.complete_lattice.has_finite_limits_of_semilattice_inf_order_top CategoryTheory.Limits.CompleteLattice.hasFiniteLimits_of_semilatticeInf_orderTop\n-/\n\n#print CategoryTheory.Limits.CompleteLattice.hasFiniteColimits_of_semilatticeSup_orderBot /-\n-- see Note [lower instance priority]\ninstance (priority := 100) hasFiniteColimits_of_semilatticeSup_orderBot [SemilatticeSup \u03b1]\n    [OrderBot \u03b1] : HasFiniteColimits \u03b1 :=\n  \u27e8fun J \ud835\udca5\u2081 \ud835\udca5\u2082 => { HasColimit := fun F => has_colimit.mk (finite_colimit_cocone F) }\u27e9\n#align category_theory.limits.complete_lattice.has_finite_colimits_of_semilattice_sup_order_bot CategoryTheory.Limits.CompleteLattice.hasFiniteColimits_of_semilatticeSup_orderBot\n-/\n\n/- warning: category_theory.limits.complete_lattice.finite_limit_eq_finset_univ_inf -> CategoryTheory.Limits.CompleteLattice.finite_limit_eq_finset_univ_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u2}} {J : Type.{u1}} [_inst_1 : CategoryTheory.SmallCategory.{u1} J] [_inst_2 : CategoryTheory.FinCategory.{u1} J _inst_1] [_inst_3 : SemilatticeInf.{u2} \u03b1] [_inst_4 : OrderTop.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3)))] (F : CategoryTheory.Functor.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3)))), Eq.{succ u2} \u03b1 (CategoryTheory.Limits.limit.{u1, u1, u2, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) F (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{u1, u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 (CategoryTheory.Limits.hasLimitsOfShape_of_hasFiniteLimits.{u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 _inst_2 (CategoryTheory.Limits.CompleteLattice.hasFiniteLimits_of_semilatticeInf_orderTop.{u2} \u03b1 _inst_3 _inst_4)) F)) (Finset.inf.{u2, u1} \u03b1 J _inst_3 _inst_4 (Finset.univ.{u1} J (CategoryTheory.FinCategory.fintypeObj.{u1} J _inst_1 _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) F))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {J : Type.{u1}} [_inst_1 : CategoryTheory.SmallCategory.{u1} J] [_inst_2 : CategoryTheory.FinCategory.{u1} J _inst_1] [_inst_3 : SemilatticeInf.{u2} \u03b1] [_inst_4 : OrderTop.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3)))] (F : CategoryTheory.Functor.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3)))), Eq.{succ u2} \u03b1 (CategoryTheory.Limits.limit.{u1, u1, u2, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) F (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{u1, u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 (CategoryTheory.Limits.hasLimitsOfShape_of_hasFiniteLimits.{u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 _inst_2 (CategoryTheory.Limits.CompleteLattice.hasFiniteLimits_of_semilatticeInf_orderTop.{u2} \u03b1 _inst_3 _inst_4)) F)) (Finset.inf.{u2, u1} \u03b1 J _inst_3 _inst_4 (Finset.univ.{u1} J (CategoryTheory.FinCategory.fintypeObj.{u1} J _inst_1 _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u1, u2} J (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} J (CategoryTheory.Category.toCategoryStruct.{u1, u1} J _inst_1)) \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u2, u2} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))))) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 _inst_3))) F)))\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.finite_limit_eq_finset_univ_inf CategoryTheory.Limits.CompleteLattice.finite_limit_eq_finset_univ_inf\u2093'. -/\n/-- The limit of a functor from a finite diagram into a `semilattice_inf` with `order_top` is the\ninfimum of the objects in the image.\n-/\ntheorem finite_limit_eq_finset_univ_inf [SemilatticeInf \u03b1] [OrderTop \u03b1] (F : J \u2964 \u03b1) :\n    limit F = Finset.univ.inf F.obj :=\n  (IsLimit.conePointUniqueUpToIso (limit.isLimit F) (finiteLimitCone F).IsLimit).to_eq\n#align category_theory.limits.complete_lattice.finite_limit_eq_finset_univ_inf CategoryTheory.Limits.CompleteLattice.finite_limit_eq_finset_univ_inf\n\n/- warning: category_theory.limits.complete_lattice.finite_colimit_eq_finset_univ_sup -> CategoryTheory.Limits.CompleteLattice.finite_colimit_eq_finset_univ_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u2}} {J : Type.{u1}} [_inst_1 : CategoryTheory.SmallCategory.{u1} J] [_inst_2 : CategoryTheory.FinCategory.{u1} J _inst_1] [_inst_3 : SemilatticeSup.{u2} \u03b1] [_inst_4 : OrderBot.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3)))] (F : CategoryTheory.Functor.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3)))), Eq.{succ u2} \u03b1 (CategoryTheory.Limits.colimit.{u1, u1, u2, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) F (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{u1, u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 (CategoryTheory.Limits.hasColimitsOfShape_of_hasFiniteColimits.{u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 _inst_2 (CategoryTheory.Limits.CompleteLattice.hasFiniteColimits_of_semilatticeSup_orderBot.{u2} \u03b1 _inst_3 _inst_4)) F)) (Finset.sup.{u2, u1} \u03b1 J _inst_3 _inst_4 (Finset.univ.{u1} J (CategoryTheory.FinCategory.fintypeObj.{u1} J _inst_1 _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) F))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {J : Type.{u1}} [_inst_1 : CategoryTheory.SmallCategory.{u1} J] [_inst_2 : CategoryTheory.FinCategory.{u1} J _inst_1] [_inst_3 : SemilatticeSup.{u2} \u03b1] [_inst_4 : OrderBot.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3)))] (F : CategoryTheory.Functor.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3)))), Eq.{succ u2} \u03b1 (CategoryTheory.Limits.colimit.{u1, u1, u2, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) F (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{u1, u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 (CategoryTheory.Limits.hasColimitsOfShape_of_hasFiniteColimits.{u1, u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) J _inst_1 _inst_2 (CategoryTheory.Limits.CompleteLattice.hasFiniteColimits_of_semilatticeSup_orderBot.{u2} \u03b1 _inst_3 _inst_4)) F)) (Finset.sup.{u2, u1} \u03b1 J _inst_3 _inst_4 (Finset.univ.{u1} J (CategoryTheory.FinCategory.fintypeObj.{u1} J _inst_1 _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u1, u2} J (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} J (CategoryTheory.Category.toCategoryStruct.{u1, u1} J _inst_1)) \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u2, u2} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u2, u2} \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))))) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u1, u2} J _inst_1 \u03b1 (Preorder.smallCategory.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeSup.toPartialOrder.{u2} \u03b1 _inst_3))) F)))\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.finite_colimit_eq_finset_univ_sup CategoryTheory.Limits.CompleteLattice.finite_colimit_eq_finset_univ_sup\u2093'. -/\n/-- The colimit of a functor from a finite diagram into a `semilattice_sup` with `order_bot`\nis the supremum of the objects in the image.\n-/\ntheorem finite_colimit_eq_finset_univ_sup [SemilatticeSup \u03b1] [OrderBot \u03b1] (F : J \u2964 \u03b1) :\n    colimit F = Finset.univ.sup F.obj :=\n  (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (finiteColimitCocone F).IsColimit).to_eq\n#align category_theory.limits.complete_lattice.finite_colimit_eq_finset_univ_sup CategoryTheory.Limits.CompleteLattice.finite_colimit_eq_finset_univ_sup\n\n#print CategoryTheory.Limits.CompleteLattice.finite_product_eq_finset_inf /-\n/--\nA finite product in the category of a `semilattice_inf` with `order_top` is the same as the infimum.\n-/\ntheorem finite_product_eq_finset_inf [SemilatticeInf \u03b1] [OrderTop \u03b1] {\u03b9 : Type u} [Fintype \u03b9]\n    (f : \u03b9 \u2192 \u03b1) : (\u220f f) = (Fintype.elems \u03b9).inf f :=\n  by\n  trans\n  exact\n    (is_limit.cone_point_unique_up_to_iso (limit.is_limit _)\n        (finite_limit_cone (discrete.functor f)).IsLimit).to_eq\n  change finset.univ.inf (f \u2218 discrete_equiv.to_embedding) = (Fintype.elems \u03b9).inf f\n  simp only [\u2190 Finset.inf_map, Finset.univ_map_equiv_to_embedding]\n  rfl\n#align category_theory.limits.complete_lattice.finite_product_eq_finset_inf CategoryTheory.Limits.CompleteLattice.finite_product_eq_finset_inf\n-/\n\n#print CategoryTheory.Limits.CompleteLattice.finite_coproduct_eq_finset_sup /-\n/-- A finite coproduct in the category of a `semilattice_sup` with `order_bot` is the same as the\nsupremum.\n-/\ntheorem finite_coproduct_eq_finset_sup [SemilatticeSup \u03b1] [OrderBot \u03b1] {\u03b9 : Type u} [Fintype \u03b9]\n    (f : \u03b9 \u2192 \u03b1) : (\u2210 f) = (Fintype.elems \u03b9).sup f :=\n  by\n  trans\n  exact\n    (is_colimit.cocone_point_unique_up_to_iso (colimit.is_colimit _)\n        (finite_colimit_cocone (discrete.functor f)).IsColimit).to_eq\n  change finset.univ.sup (f \u2218 discrete_equiv.to_embedding) = (Fintype.elems \u03b9).sup f\n  simp only [\u2190 Finset.sup_map, Finset.univ_map_equiv_to_embedding]\n  rfl\n#align category_theory.limits.complete_lattice.finite_coproduct_eq_finset_sup CategoryTheory.Limits.CompleteLattice.finite_coproduct_eq_finset_sup\n-/\n\n-- see Note [lower instance priority]\ninstance (priority := 100) [SemilatticeInf \u03b1] [OrderTop \u03b1] : HasBinaryProducts \u03b1 :=\n  by\n  have : \u2200 x y : \u03b1, has_limit (pair x y) :=\n    by\n    letI := hasFiniteLimits_of_hasFiniteLimits_of_size.{u} \u03b1\n    infer_instance\n  apply has_binary_products_of_has_limit_pair\n\n/- warning: category_theory.limits.complete_lattice.prod_eq_inf -> CategoryTheory.Limits.CompleteLattice.prod_eq_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b1] [_inst_4 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3)))] (x : \u03b1) (y : \u03b1), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.prod.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) (CategoryTheory.Discrete.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.discreteCategory.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.CompleteLattice.CategoryTheory.Limits.hasBinaryProducts.{u1} \u03b1 _inst_3 _inst_4) (CategoryTheory.Limits.pair.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 _inst_3) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b1] [_inst_4 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3)))] (x : \u03b1) (y : \u03b1), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.prod.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) (CategoryTheory.Discrete.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.discreteCategory.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.CompleteLattice.instHasBinaryProductsSmallCategoryToPreorderToPartialOrder.{u1} \u03b1 _inst_3 _inst_4) (CategoryTheory.Limits.pair.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toInf.{u1} \u03b1 _inst_3) x y)\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.prod_eq_inf CategoryTheory.Limits.CompleteLattice.prod_eq_inf\u2093'. -/\n/-- The binary product in the category of a `semilattice_inf` with `order_top` is the same as the\ninfimum.\n-/\n@[simp]\ntheorem prod_eq_inf [SemilatticeInf \u03b1] [OrderTop \u03b1] (x y : \u03b1) : Limits.prod x y = x \u2293 y :=\n  calc\n    Limits.prod x y = limit (pair x y) := rfl\n    _ = Finset.univ.inf (pair x y).obj := by rw [finite_limit_eq_finset_univ_inf (pair.{u} x y)]\n    _ = x \u2293 (y \u2293 \u22a4) := rfl\n    -- Note: finset.inf is realized as a fold, hence the definitional equality\n        _ =\n        x \u2293 y :=\n      by rw [inf_top_eq]\n    \n#align category_theory.limits.complete_lattice.prod_eq_inf CategoryTheory.Limits.CompleteLattice.prod_eq_inf\n\n-- see Note [lower instance priority]\ninstance (priority := 100) [SemilatticeSup \u03b1] [OrderBot \u03b1] : HasBinaryCoproducts \u03b1 :=\n  by\n  have : \u2200 x y : \u03b1, has_colimit (pair x y) :=\n    by\n    letI := hasFiniteColimits_of_hasFiniteColimits_of_size.{u} \u03b1\n    infer_instance\n  apply has_binary_coproducts_of_has_colimit_pair\n\n/- warning: category_theory.limits.complete_lattice.coprod_eq_sup -> CategoryTheory.Limits.CompleteLattice.coprod_eq_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b1] [_inst_4 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3)))] (x : \u03b1) (y : \u03b1), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.coprod.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) x y (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) (CategoryTheory.Discrete.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.discreteCategory.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.CompleteLattice.CategoryTheory.Limits.hasBinaryCoproducts.{u1} \u03b1 _inst_3 _inst_4) (CategoryTheory.Limits.pair.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) x y))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 _inst_3) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b1] [_inst_4 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3)))] (x : \u03b1) (y : \u03b1), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.coprod.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) x y (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) (CategoryTheory.Discrete.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.discreteCategory.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.CompleteLattice.instHasBinaryCoproductsSmallCategoryToPreorderToPartialOrder.{u1} \u03b1 _inst_3 _inst_4) (CategoryTheory.Limits.pair.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) x y))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 _inst_3) x y)\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.coprod_eq_sup CategoryTheory.Limits.CompleteLattice.coprod_eq_sup\u2093'. -/\n/-- The binary coproduct in the category of a `semilattice_sup` with `order_bot` is the same as the\nsupremum.\n-/\n@[simp]\ntheorem coprod_eq_sup [SemilatticeSup \u03b1] [OrderBot \u03b1] (x y : \u03b1) : Limits.coprod x y = x \u2294 y :=\n  calc\n    Limits.coprod x y = colimit (pair x y) := rfl\n    _ = Finset.univ.sup (pair x y).obj := by rw [finite_colimit_eq_finset_univ_sup (pair x y)]\n    _ = x \u2294 (y \u2294 \u22a5) := rfl\n    -- Note: finset.sup is realized as a fold, hence the definitional equality\n        _ =\n        x \u2294 y :=\n      by rw [sup_bot_eq]\n    \n#align category_theory.limits.complete_lattice.coprod_eq_sup CategoryTheory.Limits.CompleteLattice.coprod_eq_sup\n\n/- warning: category_theory.limits.complete_lattice.pullback_eq_inf -> CategoryTheory.Limits.CompleteLattice.pullback_eq_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b1] [_inst_4 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3)))] {x : \u03b1} {y : \u03b1} {z : \u03b1} (f : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))))) x z) (g : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))))) y z), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.pullback.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y z f g (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingCospan (CategoryTheory.Limits.WidePullbackShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.hasLimitsOfShape_of_hasFiniteLimits.{0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingCospan (CategoryTheory.Limits.WidePullbackShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.finCategoryWidePullback.{0} CategoryTheory.Limits.WalkingPair CategoryTheory.Limits.fintypeWalkingPair) (CategoryTheory.Limits.CompleteLattice.hasFiniteLimits_of_semilatticeInf_orderTop.{u1} \u03b1 _inst_3 _inst_4)) (CategoryTheory.Limits.cospan.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y z f g))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 _inst_3) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeInf.{u1} \u03b1] [_inst_4 : OrderTop.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3)))] {x : \u03b1} {y : \u03b1} {z : \u03b1} (f : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))))) x z) (g : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))))) y z), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.pullback.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y z f g (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingCospan (CategoryTheory.Limits.WidePullbackShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.hasLimitsOfShape_of_hasFiniteLimits.{0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingCospan (CategoryTheory.Limits.WidePullbackShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.finCategoryWidePullback.{0} CategoryTheory.Limits.WalkingPair CategoryTheory.Limits.fintypeWalkingPair) (CategoryTheory.Limits.CompleteLattice.hasFiniteLimits_of_semilatticeInf_orderTop.{u1} \u03b1 _inst_3 _inst_4)) (CategoryTheory.Limits.cospan.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 _inst_3))) x y z f g))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toInf.{u1} \u03b1 _inst_3) x y)\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.pullback_eq_inf CategoryTheory.Limits.CompleteLattice.pullback_eq_inf\u2093'. -/\n/-- The pullback in the category of a `semilattice_inf` with `order_top` is the same as the infimum\nover the objects.\n-/\n@[simp]\ntheorem pullback_eq_inf [SemilatticeInf \u03b1] [OrderTop \u03b1] {x y z : \u03b1} (f : x \u27f6 z) (g : y \u27f6 z) :\n    pullback f g = x \u2293 y :=\n  calc\n    pullback f g = limit (cospan f g) := rfl\n    _ = Finset.univ.inf (cospan f g).obj := by rw [finite_limit_eq_finset_univ_inf]\n    _ = z \u2293 (x \u2293 (y \u2293 \u22a4)) := rfl\n    _ = z \u2293 (x \u2293 y) := by rw [inf_top_eq]\n    _ = x \u2293 y := inf_eq_right.mpr (inf_le_of_left_le f.le)\n    \n#align category_theory.limits.complete_lattice.pullback_eq_inf CategoryTheory.Limits.CompleteLattice.pullback_eq_inf\n\n/- warning: category_theory.limits.complete_lattice.pushout_eq_sup -> CategoryTheory.Limits.CompleteLattice.pushout_eq_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b1] [_inst_4 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3)))] (x : \u03b1) (y : \u03b1) (z : \u03b1) (f : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))))) z x) (g : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))))) z y), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.pushout.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) z x y f g (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingSpan (CategoryTheory.Limits.WidePushoutShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.hasColimitsOfShape_of_hasFiniteColimits.{0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingSpan (CategoryTheory.Limits.WidePushoutShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.finCategoryWidePushout.{0} CategoryTheory.Limits.WalkingPair CategoryTheory.Limits.fintypeWalkingPair) (CategoryTheory.Limits.CompleteLattice.hasFiniteColimits_of_semilatticeSup_orderBot.{u1} \u03b1 _inst_3 _inst_4)) (CategoryTheory.Limits.span.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) z x y f g))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 _inst_3) x y)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_3 : SemilatticeSup.{u1} \u03b1] [_inst_4 : OrderBot.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3)))] (x : \u03b1) (y : \u03b1) (z : \u03b1) (f : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))))) z x) (g : Quiver.Hom.{succ u1, u1} \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))))) z y), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.pushout.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) z x y f g (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{0, 0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingSpan (CategoryTheory.Limits.WidePushoutShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.hasColimitsOfShape_of_hasFiniteColimits.{0, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) CategoryTheory.Limits.WalkingSpan (CategoryTheory.Limits.WidePushoutShape.category.{0} CategoryTheory.Limits.WalkingPair) (CategoryTheory.Limits.finCategoryWidePushout.{0} CategoryTheory.Limits.WalkingPair CategoryTheory.Limits.fintypeWalkingPair) (CategoryTheory.Limits.CompleteLattice.hasFiniteColimits_of_semilatticeSup_orderBot.{u1} \u03b1 _inst_3 _inst_4)) (CategoryTheory.Limits.span.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeSup.toPartialOrder.{u1} \u03b1 _inst_3))) z x y f g))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 _inst_3) x y)\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.pushout_eq_sup CategoryTheory.Limits.CompleteLattice.pushout_eq_sup\u2093'. -/\n/-- The pushout in the category of a `semilattice_sup` with `order_bot` is the same as the supremum\nover the objects.\n-/\n@[simp]\ntheorem pushout_eq_sup [SemilatticeSup \u03b1] [OrderBot \u03b1] (x y z : \u03b1) (f : z \u27f6 x) (g : z \u27f6 y) :\n    pushout f g = x \u2294 y :=\n  calc\n    pushout f g = colimit (span f g) := rfl\n    _ = Finset.univ.sup (span f g).obj := by rw [finite_colimit_eq_finset_univ_sup]\n    _ = z \u2294 (x \u2294 (y \u2294 \u22a5)) := rfl\n    _ = z \u2294 (x \u2294 y) := by rw [sup_bot_eq]\n    _ = x \u2294 y := sup_eq_right.mpr (le_sup_of_le_left f.le)\n    \n#align category_theory.limits.complete_lattice.pushout_eq_sup CategoryTheory.Limits.CompleteLattice.pushout_eq_sup\n\nend Semilattice\n\nvariable {\u03b1 : Type u} [CompleteLattice \u03b1]\n\nvariable {J : Type u} [SmallCategory J]\n\n#print CategoryTheory.Limits.CompleteLattice.limitCone /-\n/-- The limit cone over any functor into a complete lattice.\n-/\ndef limitCone (F : J \u2964 \u03b1) : LimitCone F\n    where\n  Cone :=\n    { pt := inf\u1d62 F.obj\n      \u03c0 := { app := fun j => homOfLE (CompleteLattice.inf_le _ _ (Set.mem_range_self _)) } }\n  IsLimit :=\n    {\n      lift := fun s =>\n        homOfLE (CompleteLattice.le_inf _ _ (by rintro _ \u27e8j, rfl\u27e9; exact (s.\u03c0.app j).le)) }\n#align category_theory.limits.complete_lattice.limit_cone CategoryTheory.Limits.CompleteLattice.limitCone\n-/\n\n#print CategoryTheory.Limits.CompleteLattice.colimitCocone /-\n/-- The colimit cocone over any functor into a complete lattice.\n-/\ndef colimitCocone (F : J \u2964 \u03b1) : ColimitCocone F\n    where\n  Cocone :=\n    { pt := sup\u1d62 F.obj\n      \u03b9 := { app := fun j => homOfLE (CompleteLattice.le_sup _ _ (Set.mem_range_self _)) } }\n  IsColimit :=\n    {\n      desc := fun s =>\n        homOfLE (CompleteLattice.sup_le _ _ (by rintro _ \u27e8j, rfl\u27e9; exact (s.\u03b9.app j).le)) }\n#align category_theory.limits.complete_lattice.colimit_cocone CategoryTheory.Limits.CompleteLattice.colimitCocone\n-/\n\n#print CategoryTheory.Limits.CompleteLattice.hasLimits_of_completeLattice /-\n-- It would be nice to only use the `Inf` half of the complete lattice, but\n-- this seems not to have been described separately.\n-- see Note [lower instance priority]\ninstance (priority := 100) hasLimits_of_completeLattice : HasLimits \u03b1\n    where HasLimitsOfShape J \ud835\udca5 := { HasLimit := fun F => has_limit.mk (limit_cone F) }\n#align category_theory.limits.complete_lattice.has_limits_of_complete_lattice CategoryTheory.Limits.CompleteLattice.hasLimits_of_completeLattice\n-/\n\n#print CategoryTheory.Limits.CompleteLattice.hasColimits_of_completeLattice /-\n-- see Note [lower instance priority]\ninstance (priority := 100) hasColimits_of_completeLattice : HasColimits \u03b1\n    where HasColimitsOfShape J \ud835\udca5 := { HasColimit := fun F => has_colimit.mk (colimit_cocone F) }\n#align category_theory.limits.complete_lattice.has_colimits_of_complete_lattice CategoryTheory.Limits.CompleteLattice.hasColimits_of_completeLattice\n-/\n\n/- warning: category_theory.limits.complete_lattice.limit_eq_infi -> CategoryTheory.Limits.CompleteLattice.limit_eq_inf\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] {J : Type.{u1}} [_inst_2 : CategoryTheory.SmallCategory.{u1} J] (F : CategoryTheory.Functor.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))))), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.limit.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.hasLimitsOfShapeOfHasLimits.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.CompleteLattice.hasLimits_of_completeLattice.{u1} \u03b1 _inst_1)) F)) (inf\u1d62.{u1, succ u1} \u03b1 (CompleteSemilatticeInf.toHasInf.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)) J (CategoryTheory.Functor.obj.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] {J : Type.{u1}} [_inst_2 : CategoryTheory.SmallCategory.{u1} J] (F : CategoryTheory.Functor.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))))), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.limit.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F (CategoryTheory.Limits.hasLimitOfHasLimitsOfShape.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.hasLimitsOfShapeOfHasLimits.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.CompleteLattice.hasLimits_of_completeLattice.{u1} \u03b1 _inst_1)) F)) (inf\u1d62.{u1, succ u1} \u03b1 (CompleteLattice.toInfSet.{u1} \u03b1 _inst_1) J (Prefunctor.obj.{succ u1, succ u1, u1, u1} J (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} J (CategoryTheory.Category.toCategoryStruct.{u1, u1} J _inst_2)) \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))))) (CategoryTheory.Functor.toPrefunctor.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F)))\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.limit_eq_infi CategoryTheory.Limits.CompleteLattice.limit_eq_inf\u1d62\u2093'. -/\n/-- The limit of a functor into a complete lattice is the infimum of the objects in the image.\n-/\ntheorem limit_eq_inf\u1d62 (F : J \u2964 \u03b1) : limit F = inf\u1d62 F.obj :=\n  (IsLimit.conePointUniqueUpToIso (limit.isLimit F) (limitCone F).IsLimit).to_eq\n#align category_theory.limits.complete_lattice.limit_eq_infi CategoryTheory.Limits.CompleteLattice.limit_eq_inf\u1d62\n\n/- warning: category_theory.limits.complete_lattice.colimit_eq_supr -> CategoryTheory.Limits.CompleteLattice.colimit_eq_sup\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] {J : Type.{u1}} [_inst_2 : CategoryTheory.SmallCategory.{u1} J] (F : CategoryTheory.Functor.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))))), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.colimit.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.hasColimitsOfShapeOfHasColimitsOfSize.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.CompleteLattice.hasColimits_of_completeLattice.{u1} \u03b1 _inst_1)) F)) (sup\u1d62.{u1, succ u1} \u03b1 (CompleteSemilatticeSup.toHasSup.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeSup.{u1} \u03b1 _inst_1)) J (CategoryTheory.Functor.obj.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CompleteLattice.{u1} \u03b1] {J : Type.{u1}} [_inst_2 : CategoryTheory.SmallCategory.{u1} J] (F : CategoryTheory.Functor.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1))))), Eq.{succ u1} \u03b1 (CategoryTheory.Limits.colimit.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F (CategoryTheory.Limits.hasColimitOfHasColimitsOfShape.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.hasColimitsOfShapeOfHasColimitsOfSize.{u1, u1, u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) J _inst_2 (CategoryTheory.Limits.CompleteLattice.hasColimits_of_completeLattice.{u1} \u03b1 _inst_1)) F)) (sup\u1d62.{u1, succ u1} \u03b1 (CompleteLattice.toSupSet.{u1} \u03b1 _inst_1) J (Prefunctor.obj.{succ u1, succ u1, u1, u1} J (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} J (CategoryTheory.Category.toCategoryStruct.{u1, u1} J _inst_2)) \u03b1 (CategoryTheory.CategoryStruct.toQuiver.{u1, u1} \u03b1 (CategoryTheory.Category.toCategoryStruct.{u1, u1} \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))))) (CategoryTheory.Functor.toPrefunctor.{u1, u1, u1, u1} J _inst_2 \u03b1 (Preorder.smallCategory.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (CompleteSemilatticeInf.toPartialOrder.{u1} \u03b1 (CompleteLattice.toCompleteSemilatticeInf.{u1} \u03b1 _inst_1)))) F)))\nCase conversion may be inaccurate. Consider using '#align category_theory.limits.complete_lattice.colimit_eq_supr CategoryTheory.Limits.CompleteLattice.colimit_eq_sup\u1d62\u2093'. -/\n/-- The colimit of a functor into a complete lattice is the supremum of the objects in the image.\n-/\ntheorem colimit_eq_sup\u1d62 (F : J \u2964 \u03b1) : colimit F = sup\u1d62 F.obj :=\n  (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (colimitCocone F).IsColimit).to_eq\n#align category_theory.limits.complete_lattice.colimit_eq_supr CategoryTheory.Limits.CompleteLattice.colimit_eq_sup\u1d62\n\nend CategoryTheory.Limits.CompleteLattice\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/CategoryTheory/Limits/Lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7117432405070033}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\n\nimport algebra.algebra.basic\nimport algebra.order.smul\n\n/-!\n# Ordered algebras\n\nAn ordered algebra is an ordered semiring, which is an algebra over an ordered commutative semiring,\nfor which scalar multiplication is \"compatible\" with the two orders.\n\nThe prototypical example is 2x2 matrices over the reals or complexes (or indeed any C^* algebra)\nwhere the ordering the one determined by the positive cone of positive operators,\ni.e. `A \u2264 B` iff `B - A = star R * R` for some `R`.\n(We don't yet have this example in mathlib.)\n\n## Implementation\n\nBecause the axioms for an ordered algebra are exactly the same as those for the underlying\nmodule being ordered, we don't actually introduce a new class, but just use the `ordered_smul`\nmixin.\n\n## Tags\n\nordered algebra\n-/\n\nsection ordered_algebra\n\nvariables {R A : Type*} {a b : A} {r : R}\n\nvariables [ordered_comm_ring R] [ordered_ring A] [algebra R A] [ordered_smul R A]\n\nlemma algebra_map_monotone : monotone (algebra_map R A) :=\n\u03bb a b h,\nbegin\n  rw [algebra.algebra_map_eq_smul_one, algebra.algebra_map_eq_smul_one, \u2190sub_nonneg, \u2190sub_smul],\n  transitivity (b - a) \u2022 (0 : A),\n  { simp, },\n  { exact smul_le_smul_of_nonneg zero_le_one (sub_nonneg.mpr h) }\nend\n\nend ordered_algebra\n\nsection instances\n\nvariables {R : Type*} [linear_ordered_comm_ring R]\n\ninstance linear_ordered_comm_ring.to_ordered_smul : ordered_smul R R :=\n{ smul_lt_smul_of_pos       := ordered_semiring.mul_lt_mul_of_pos_left,\n  lt_of_smul_lt_smul_of_pos := \u03bb a b c w\u2081 w\u2082, (mul_lt_mul_left w\u2082).mp w\u2081 }\n\nend instances\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/order/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7117432374856344}}
{"text": "/-\nCopyright (c) 2020 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.erase_lead\nimport Mathlib.data.polynomial.degree.default\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Reverse of a univariate polynomial\n\nThe main definition is `reverse`.  Applying `reverse` to a polynomial `f : polynomial R` produces\nthe polynomial with a reversed list of coefficients, equivalent to `X^f.nat_degree * f(1/X)`.\n\nThe main result is that `reverse (f * g) = reverse (f) * reverse (g)`, provided the leading\ncoefficients of `f` and `g` do not multiply to zero.\n-/\n\nnamespace polynomial\n\n\n/-- If `i \u2264 N`, then `rev_at_fun N i` returns `N - i`, otherwise it returns `i`.\nThis is the map used by the embedding `rev_at`.\n-/\ndef rev_at_fun (N : \u2115) (i : \u2115) : \u2115 :=\n  ite (i \u2264 N) (N - i) i\n\ntheorem rev_at_fun_invol {N : \u2115} {i : \u2115} : rev_at_fun N (rev_at_fun N i) = i := sorry\n\ntheorem rev_at_fun_inj {N : \u2115} : function.injective (rev_at_fun N) := sorry\n\n/-- If `i \u2264 N`, then `rev_at N i` returns `N - i`, otherwise it returns `i`.\nEssentially, this embedding is only used for `i \u2264 N`.\nThe advantage of `rev_at N i` over `N - i` is that `rev_at` is an involution.\n-/\ndef rev_at (N : \u2115) : \u2115 \u21aa \u2115 :=\n  function.embedding.mk (fun (i : \u2115) => ite (i \u2264 N) (N - i) i) rev_at_fun_inj\n\n/-- We prefer to use the bundled `rev_at` over unbundled `rev_at_fun`. -/\n@[simp] theorem rev_at_fun_eq (N : \u2115) (i : \u2115) : rev_at_fun N i = coe_fn (rev_at N) i :=\n  rfl\n\n@[simp] theorem rev_at_invol {N : \u2115} {i : \u2115} : coe_fn (rev_at N) (coe_fn (rev_at N) i) = i :=\n  rev_at_fun_invol\n\n@[simp] theorem rev_at_le {N : \u2115} {i : \u2115} (H : i \u2264 N) : coe_fn (rev_at N) i = N - i :=\n  if_pos H\n\ntheorem rev_at_add {N : \u2115} {O : \u2115} {n : \u2115} {o : \u2115} (hn : n \u2264 N) (ho : o \u2264 O) : coe_fn (rev_at (N + O)) (n + o) = coe_fn (rev_at N) n + coe_fn (rev_at O) o := sorry\n\n/-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (rev_at N i)`.\nIn other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`.\n\nIn practice, `reflect` is only used when `N` is at least as large as the degree of `f`.\n\nEventually, it will be used with `N` exactly equal to the degree of `f`.  -/\ndef reflect {R : Type u_1} [semiring R] (N : \u2115) (f : polynomial R) : polynomial R :=\n  finsupp.emb_domain (rev_at N) f\n\ntheorem reflect_support {R : Type u_1} [semiring R] (N : \u2115) (f : polynomial R) : finsupp.support (reflect N f) = finset.image (\u21d1(rev_at N)) (finsupp.support f) := sorry\n\n@[simp] theorem coeff_reflect {R : Type u_1} [semiring R] (N : \u2115) (f : polynomial R) (i : \u2115) : coeff (reflect N f) i = coeff f (coe_fn (rev_at N) i) := sorry\n\n@[simp] theorem reflect_zero {R : Type u_1} [semiring R] {N : \u2115} : reflect N 0 = 0 :=\n  rfl\n\n@[simp] theorem reflect_eq_zero_iff {R : Type u_1} [semiring R] {N : \u2115} {f : polynomial R} : reflect N f = 0 \u2194 f = 0 := sorry\n\n@[simp] theorem reflect_add {R : Type u_1} [semiring R] (f : polynomial R) (g : polynomial R) (N : \u2115) : reflect N (f + g) = reflect N f + reflect N g := sorry\n\n@[simp] theorem reflect_C_mul {R : Type u_1} [semiring R] (f : polynomial R) (r : R) (N : \u2115) : reflect N (coe_fn C r * f) = coe_fn C r * reflect N f := sorry\n\n@[simp] theorem reflect_C_mul_X_pow {R : Type u_1} [semiring R] (N : \u2115) (n : \u2115) {c : R} : reflect N (coe_fn C c * X ^ n) = coe_fn C c * X ^ coe_fn (rev_at N) n := sorry\n\n@[simp] theorem reflect_monomial {R : Type u_1} [semiring R] (N : \u2115) (n : \u2115) : reflect N (X ^ n) = X ^ coe_fn (rev_at N) n := sorry\n\ntheorem reflect_mul_induction {R : Type u_1} [semiring R] (cf : \u2115) (cg : \u2115) (N : \u2115) (O : \u2115) (f : polynomial R) (g : polynomial R) : finset.card (finsupp.support f) \u2264 Nat.succ cf \u2192\n  finset.card (finsupp.support g) \u2264 Nat.succ cg \u2192\n    nat_degree f \u2264 N \u2192 nat_degree g \u2264 O \u2192 reflect (N + O) (f * g) = reflect N f * reflect O g := sorry\n\n@[simp] theorem reflect_mul {R : Type u_1} [semiring R] (f : polynomial R) (g : polynomial R) {F : \u2115} {G : \u2115} (Ff : nat_degree f \u2264 F) (Gg : nat_degree g \u2264 G) : reflect (F + G) (f * g) = reflect F f * reflect G g :=\n  reflect_mul_induction (finset.card (finsupp.support f)) (finset.card (finsupp.support g)) F G f g\n    (nat.le_succ (finset.card (finsupp.support f))) (nat.le_succ (finset.card (finsupp.support g))) Ff Gg\n\n/-- The reverse of a polynomial f is the polynomial obtained by \"reading f backwards\".\nEven though this is not the actual definition, reverse f = f (1/X) * X ^ f.nat_degree. -/\ndef reverse {R : Type u_1} [semiring R] (f : polynomial R) : polynomial R :=\n  reflect (nat_degree f) f\n\n@[simp] theorem reverse_zero {R : Type u_1} [semiring R] : reverse 0 = 0 :=\n  rfl\n\ntheorem reverse_mul {R : Type u_1} [semiring R] {f : polynomial R} {g : polynomial R} (fg : leading_coeff f * leading_coeff g \u2260 0) : reverse (f * g) = reverse f * reverse g := sorry\n\n@[simp] theorem reverse_mul_of_domain {R : Type u_1} [domain R] (f : polynomial R) (g : polynomial R) : reverse (f * g) = reverse f * reverse g := sorry\n\n@[simp] theorem coeff_zero_reverse {R : Type u_1} [semiring R] (f : polynomial R) : coeff (reverse f) 0 = leading_coeff f := sorry\n\n@[simp] theorem coeff_one_reverse {R : Type u_1} [semiring R] (f : polynomial R) : coeff (reverse f) 1 = next_coeff f := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/polynomial/reverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.7117336974045183}}
{"text": "/-\nCopyright (c) 2019 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.regular.basic\nimport linear_algebra.matrix.mv_polynomial\nimport linear_algebra.matrix.polynomial\nimport ring_theory.polynomial.basic\n\n/-!\n# Cramer's rule and adjugate matrices\n\nThe adjugate matrix is the transpose of the cofactor matrix.\nIt is calculated with Cramer's rule, which we introduce first.\nThe vectors returned by Cramer's rule are given by the linear map `cramer`,\nwhich sends a matrix `A` and vector `b` to the vector consisting of the\ndeterminant of replacing the `i`th column of `A` with `b` at index `i`\n(written as `(A.update_column i b).det`).\nUsing Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`.\nThe entries of the adjugate are the minors of `A`.\nInstead of defining a minor by deleting row `i` and column `j` of `A`, we\nreplace the `i`th row of `A` with the `j`th basis vector; the resulting matrix\nhas the same determinant but more importantly equals Cramer's rule applied\nto `A` and the `j`th basis vector, simplifying the subsequent proofs.\nWe prove the adjugate behaves like `det A \u2022 A\u207b\u00b9`.\n\n## Main definitions\n\n * `matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`.\n * `matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`.\n\n## References\n\n  * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix\n\n## Tags\n\ncramer, cramer's rule, adjugate\n-/\n\nnamespace matrix\nuniverses u v\nvariables {n : Type u} [decidable_eq n] [fintype n] {\u03b1 : Type v} [comm_ring \u03b1]\nopen_locale matrix big_operators polynomial\nopen equiv equiv.perm finset\n\nsection cramer\n/-!\n  ### `cramer` section\n\n  Introduce the linear map `cramer` with values defined by `cramer_map`.\n  After defining `cramer_map` and showing it is linear,\n  we will restrict our proofs to using `cramer`.\n-/\nvariables (A : matrix n n \u03b1) (b : n \u2192 \u03b1)\n\n/--\n  `cramer_map A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,\n  and thus `cramer_map A b` is the vector output by Cramer's rule on `A` and `b`.\n\n  If `A \u2b1d x = b` has a unique solution in `x`, `cramer_map A` sends the vector `b` to `A.det \u2022 x`.\n  Otherwise, the outcome of `cramer_map` is well-defined but not necessarily useful.\n-/\ndef cramer_map (i : n) : \u03b1 := (A.update_column i b).det\n\nlemma cramer_map_is_linear (i : n) : is_linear_map \u03b1 (\u03bb b, cramer_map A b i) :=\n{ map_add := det_update_column_add _ _,\n  map_smul := det_update_column_smul _ _ }\n\nlemma cramer_is_linear : is_linear_map \u03b1 (cramer_map A) :=\nbegin\n  split; intros; ext i,\n  { apply (cramer_map_is_linear A i).1 },\n  { apply (cramer_map_is_linear A i).2 }\nend\n\n/--\n  `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,\n  and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`.\n\n  If `A \u2b1d x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det \u2022 x`.\n  Otherwise, the outcome of `cramer` is well-defined but not necessarily useful.\n -/\ndef cramer (A : matrix n n \u03b1) : (n \u2192 \u03b1) \u2192\u2097[\u03b1] (n \u2192 \u03b1) :=\nis_linear_map.mk' (cramer_map A) (cramer_is_linear A)\n\nlemma cramer_apply (i : n) : cramer A b i = (A.update_column i b).det := rfl\n\nlemma cramer_transpose_apply (i : n) : cramer A\u1d40 b i = (A.update_row i b).det :=\nby rw [cramer_apply, update_column_transpose, det_transpose]\n\nlemma cramer_transpose_row_self (i : n) :\n  A\u1d40.cramer (A i) = pi.single i A.det :=\nbegin\n  ext j,\n  rw [cramer_apply, pi.single_apply],\n  split_ifs with h,\n  { -- i = j: this entry should be `A.det`\n    subst h,\n    simp only [update_column_transpose, det_transpose, update_row, function.update_eq_self] },\n  { -- i \u2260 j: this entry should be 0\n    rw [update_column_transpose, det_transpose],\n    apply det_zero_of_row_eq h,\n    rw [update_row_self, update_row_ne (ne.symm h)] }\nend\n\nlemma cramer_row_self (i : n) (h : \u2200 j, b j = A j i) :\n  A.cramer b = pi.single i A.det :=\nbegin\n  rw [\u2190 transpose_transpose A, det_transpose],\n  convert cramer_transpose_row_self A\u1d40 i,\n  exact funext h\nend\n\n@[simp] lemma cramer_one : cramer (1 : matrix n n \u03b1) = 1 :=\nbegin\n  ext i j,\n  convert congr_fun (cramer_row_self (1 : matrix n n \u03b1) (pi.single i 1) i _) j,\n  { simp },\n  { intros j, rw [matrix.one_eq_pi_single, pi.single_comm] }\nend\n\nlemma cramer_smul (r : \u03b1) (A : matrix n n \u03b1) :\n  cramer (r \u2022 A) = r ^ (fintype.card n - 1) \u2022 cramer A :=\nlinear_map.ext $ \u03bb b, funext $ \u03bb _, det_update_column_smul' _ _ _ _\n\n@[simp] lemma cramer_subsingleton_apply [subsingleton n] (A : matrix n n \u03b1) (b : n \u2192 \u03b1) (i : n) :\n  cramer A b i = b i :=\nby rw [cramer_apply, det_eq_elem_of_subsingleton _ i, update_column_self]\n\nlemma cramer_zero [nontrivial n] : cramer (0 : matrix n n \u03b1) = 0 :=\nbegin\n  ext i j,\n  obtain \u27e8j', hj'\u27e9 : \u2203 j', j' \u2260 j := exists_ne j,\n  apply det_eq_zero_of_column_eq_zero j',\n  intro j'',\n  simp [update_column_ne hj'],\nend\n\n/-- Use linearity of `cramer` to take it out of a summation. -/\nlemma sum_cramer {\u03b2} (s : finset \u03b2) (f : \u03b2 \u2192 n \u2192 \u03b1) :\n  \u2211 x in s, cramer A (f x) = cramer A (\u2211 x in s, f x) :=\n(linear_map.map_sum (cramer A)).symm\n\n/-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/\nlemma sum_cramer_apply {\u03b2} (s : finset \u03b2) (f : n \u2192 \u03b2 \u2192 \u03b1) (i : n) :\n\u2211 x in s, cramer A (\u03bb j, f j x) i = cramer A (\u03bb (j : n), \u2211 x in s, f j x) i :=\ncalc \u2211 x in s, cramer A (\u03bb j, f j x) i\n    = (\u2211 x in s, cramer A (\u03bb j, f j x)) i : (finset.sum_apply i s _).symm\n... = cramer A (\u03bb (j : n), \u2211 x in s, f j x) i :\n  by { rw [sum_cramer, cramer_apply], congr' with j, apply finset.sum_apply }\n\nend cramer\n\nsection adjugate\n/-!\n### `adjugate` section\n\nDefine the `adjugate` matrix and a few equations.\nThese will hold for any matrix over a commutative ring.\n-/\n\n/-- The adjugate matrix is the transpose of the cofactor matrix.\n\n  Typically, the cofactor matrix is defined by taking minors,\n  i.e. the determinant of the matrix with a row and column removed.\n  However, the proof of `mul_adjugate` becomes a lot easier if we use the\n  matrix replacing a column with a basis vector, since it allows us to use\n  facts about the `cramer` map.\n-/\ndef adjugate (A : matrix n n \u03b1) : matrix n n \u03b1 := \u03bb i, cramer A\u1d40 (pi.single i 1)\n\nlemma adjugate_def (A : matrix n n \u03b1) :\n  adjugate A = \u03bb i, cramer A\u1d40 (pi.single i 1) := rfl\n\nlemma adjugate_apply (A : matrix n n \u03b1) (i j : n) :\n  adjugate A i j = (A.update_row j (pi.single i 1)).det :=\nby { rw adjugate_def, simp only, rw [cramer_apply, update_column_transpose, det_transpose], }\n\nlemma adjugate_transpose (A : matrix n n \u03b1) : (adjugate A)\u1d40 = adjugate (A\u1d40) :=\nbegin\n  ext i j,\n  rw [transpose_apply, adjugate_apply, adjugate_apply, update_row_transpose, det_transpose],\n  rw [det_apply', det_apply'],\n  apply finset.sum_congr rfl,\n  intros \u03c3 _,\n  congr' 1,\n\n  by_cases i = \u03c3 j,\n  { -- Everything except `(i , j)` (= `(\u03c3 j , j)`) is given by A, and the rest is a single `1`.\n    congr; ext j',\n    subst h,\n    have : \u03c3 j' = \u03c3 j \u2194 j' = j := \u03c3.injective.eq_iff,\n    rw [update_row_apply, update_column_apply],\n    simp_rw this,\n    rw [\u2190dite_eq_ite, \u2190dite_eq_ite],\n    congr' 1 with rfl,\n    rw [pi.single_eq_same, pi.single_eq_same], },\n  { -- Otherwise, we need to show that there is a `0` somewhere in the product.\n    have : (\u220f j' : n, update_column A j (pi.single i 1) (\u03c3 j') j') = 0,\n    { apply prod_eq_zero (mem_univ j),\n      rw [update_column_self, pi.single_eq_of_ne' h], },\n    rw this,\n    apply prod_eq_zero (mem_univ (\u03c3\u207b\u00b9 i)),\n    erw [apply_symm_apply \u03c3 i, update_row_self],\n    apply pi.single_eq_of_ne,\n    intro h',\n    exact h ((symm_apply_eq \u03c3).mp h') }\nend\n\n/-- Since the map `b \u21a6 cramer A b` is linear in `b`, it must be multiplication by some matrix. This\nmatrix is `A.adjugate`. -/\nlemma cramer_eq_adjugate_mul_vec (A : matrix n n \u03b1) (b : n \u2192 \u03b1) :\n  cramer A b = A.adjugate.mul_vec b :=\nbegin\n  nth_rewrite 1 \u2190 A.transpose_transpose,\n  rw [\u2190 adjugate_transpose, adjugate_def],\n  have : b = \u2211 i, (b i) \u2022 (pi.single i 1),\n  { refine (pi_eq_sum_univ b).trans _, congr' with j, simp [pi.single_apply, eq_comm] },\n  nth_rewrite 0 this, ext k,\n  simp [mul_vec, dot_product, mul_comm],\nend\n\nlemma mul_adjugate_apply (A : matrix n n \u03b1) (i j k) :\n  A i k * adjugate A k j = cramer A\u1d40 (pi.single k (A i k)) j :=\nbegin\n  erw [\u2190smul_eq_mul, \u2190pi.smul_apply, \u2190linear_map.map_smul, \u2190pi.single_smul', smul_eq_mul, mul_one],\nend\n\nlemma mul_adjugate (A : matrix n n \u03b1) : A \u2b1d adjugate A = A.det \u2022 1 :=\nbegin\n  ext i j,\n  rw [mul_apply, pi.smul_apply, pi.smul_apply, one_apply, smul_eq_mul, mul_boole],\n  simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, pi.single_apply, eq_comm]\nend\n\nlemma adjugate_mul (A : matrix n n \u03b1) : adjugate A \u2b1d A = A.det \u2022 1 :=\ncalc adjugate A \u2b1d A = (A\u1d40 \u2b1d (adjugate A\u1d40))\u1d40 :\n  by rw [\u2190adjugate_transpose, \u2190transpose_mul, transpose_transpose]\n... = A.det \u2022 1 : by rw [mul_adjugate (A\u1d40), det_transpose, transpose_smul, transpose_one]\n\nlemma adjugate_smul (r : \u03b1) (A : matrix n n \u03b1) :\n  adjugate (r \u2022 A) = r ^ (fintype.card n - 1) \u2022 adjugate A :=\nbegin\n  rw [adjugate, adjugate, transpose_smul, cramer_smul],\n  refl,\nend\n\n/-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A \u2b1d x = b` even\nif the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det`\ndivides `b`. -/\n@[simp] lemma mul_vec_cramer (A : matrix n n \u03b1) (b : n \u2192 \u03b1) :\n  A.mul_vec (cramer A b) = A.det \u2022 b :=\nby rw [cramer_eq_adjugate_mul_vec, mul_vec_mul_vec, mul_adjugate, smul_mul_vec_assoc, one_mul_vec]\n\nlemma adjugate_subsingleton [subsingleton n] (A : matrix n n \u03b1) : adjugate A = 1 :=\nbegin\n  ext i j,\n  simp [subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i]\nend\n\nlemma adjugate_eq_one_of_card_eq_one {A : matrix n n \u03b1} (h : fintype.card n = 1) : adjugate A = 1 :=\nbegin\n  haveI : subsingleton n := fintype.card_le_one_iff_subsingleton.mp h.le,\n  exact adjugate_subsingleton _\nend\n\n@[simp] lemma adjugate_zero [nontrivial n] : adjugate (0 : matrix n n \u03b1) = 0 :=\nbegin\n  ext i j,\n  obtain \u27e8j', hj'\u27e9 : \u2203 j', j' \u2260 j := exists_ne j,\n  apply det_eq_zero_of_column_eq_zero j',\n  intro j'',\n  simp [update_column_ne hj'],\nend\n\n@[simp] lemma adjugate_one : adjugate (1 : matrix n n \u03b1) = 1 :=\nby { ext, simp [adjugate_def, matrix.one_apply, pi.single_apply, eq_comm] }\n\n@[simp] lemma adjugate_diagonal (v : n \u2192 \u03b1) :\n  adjugate (diagonal v) = diagonal (\u03bb i, \u220f j in finset.univ.erase i, v j) :=\nbegin\n  ext,\n  simp only [adjugate_def, cramer_apply, diagonal_transpose],\n  obtain rfl | hij := eq_or_ne i j,\n  { rw [diagonal_apply_eq, diagonal_update_column_single, det_diagonal,\n      prod_update_of_mem (finset.mem_univ _), sdiff_singleton_eq_erase, one_mul] },\n  { rw diagonal_apply_ne _ hij,\n    refine det_eq_zero_of_row_eq_zero j (\u03bb k, _),\n    obtain rfl | hjk := eq_or_ne k j,\n    { rw [update_column_self, pi.single_eq_of_ne' hij] },\n    { rw [update_column_ne hjk, diagonal_apply_ne' _ hjk]} },\nend\n\nlemma _root_.ring_hom.map_adjugate {R S : Type*} [comm_ring R] [comm_ring S] (f : R \u2192+* S)\n  (M : matrix n n R) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) :=\nbegin\n  ext i k,\n  have : pi.single i (1 : S) = f \u2218 pi.single i 1,\n  { rw \u2190f.map_one,\n    exact pi.single_op (\u03bb i, f) (\u03bb i, f.map_zero) i (1 : R) },\n  rw [adjugate_apply, ring_hom.map_matrix_apply, map_apply, ring_hom.map_matrix_apply,\n      this, \u2190map_update_row, \u2190ring_hom.map_matrix_apply, \u2190ring_hom.map_det, \u2190adjugate_apply]\nend\n\nlemma _root_.alg_hom.map_adjugate {R A B : Type*} [comm_semiring R] [comm_ring A] [comm_ring B]\n  [algebra R A] [algebra R B] (f : A \u2192\u2090[R] B)\n  (M : matrix n n A) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) :=\nf.to_ring_hom.map_adjugate _\n\n\nlemma det_adjugate (A : matrix n n \u03b1) : (adjugate A).det = A.det ^ (fintype.card n - 1) :=\nbegin\n  -- get rid of the `- 1`\n  cases (fintype.card n).eq_zero_or_pos with h_card h_card,\n  { haveI : is_empty n := fintype.card_eq_zero_iff.mp h_card,\n    rw [h_card, nat.zero_sub, pow_zero, adjugate_subsingleton, det_one] },\n  replace h_card := tsub_add_cancel_of_le h_card.nat_succ_le,\n\n  -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring\n  -- where `A'.det` is non-zero.\n  let A' := mv_polynomial_X n n \u2124,\n  suffices : A'.adjugate.det = A'.det ^ (fintype.card n - 1),\n  { rw [\u2190mv_polynomial_X_map_matrix_aeval \u2124 A, \u2190alg_hom.map_adjugate, \u2190alg_hom.map_det,\n      \u2190alg_hom.map_det, \u2190alg_hom.map_pow, this] },\n\n  apply mul_left_cancel\u2080 (show A'.det \u2260 0, from det_mv_polynomial_X_ne_zero n \u2124),\n  calc  A'.det * A'.adjugate.det\n      = (A' \u2b1d adjugate A').det                 : (det_mul _ _).symm\n  ... = A'.det ^ fintype.card n                : by rw [mul_adjugate, det_smul, det_one, mul_one]\n  ... = A'.det * A'.det ^ (fintype.card n - 1) : by rw [\u2190pow_succ, h_card],\nend\n\n@[simp] lemma adjugate_fin_zero (A : matrix (fin 0) (fin 0) \u03b1) : adjugate A = 0 :=\nsubsingleton.elim _ _\n\n@[simp] lemma adjugate_fin_one (A : matrix (fin 1) (fin 1) \u03b1) : adjugate A = 1 :=\nadjugate_subsingleton A\n\nlemma adjugate_fin_two (A : matrix (fin 2) (fin 2) \u03b1) :\n  adjugate A = !![A 1 1, -A 0 1; -A 1 0, A 0 0] :=\nbegin\n  ext i j,\n  rw [adjugate_apply, det_fin_two],\n  fin_cases i; fin_cases j;\n  simp only [one_mul, fin.one_eq_zero_iff, pi.single_eq_same, mul_zero, sub_zero,\n    pi.single_eq_of_ne, ne.def, not_false_iff, update_row_self, update_row_ne, cons_val_zero,\n    of_apply, nat.succ_succ_ne_one, pi.single_eq_of_ne, update_row_self, pi.single_eq_of_ne, ne.def,\n    fin.zero_eq_one_iff, nat.succ_succ_ne_one, not_false_iff, update_row_ne, fin.one_eq_zero_iff,\n    zero_mul, pi.single_eq_same, one_mul, zero_sub, of_apply, cons_val', cons_val_fin_one,\n    cons_val_one, head_fin_const, neg_inj, eq_self_iff_true, cons_val_zero, head_cons, mul_one]\nend\n\n@[simp] lemma adjugate_fin_two_of (a b c d : \u03b1) :\n  adjugate !![a, b; c, d] = !![d, -b; -c, a] :=\nadjugate_fin_two _\n\nlemma adjugate_conj_transpose [star_ring \u03b1] (A : matrix n n \u03b1) : A.adjugate\u1d34 = adjugate (A\u1d34) :=\nbegin\n  dsimp only [conj_transpose],\n  have : A\u1d40.adjugate.map star = adjugate (A\u1d40.map star) := ((star_ring_end \u03b1).map_adjugate A\u1d40),\n  rw [A.adjugate_transpose, this],\nend\n\nlemma is_regular_of_is_left_regular_det {A : matrix n n \u03b1} (hA : is_left_regular A.det) :\n  is_regular A :=\nbegin\n  split,\n  { intros B C h,\n    refine hA.matrix _,\n    rw [\u2190matrix.one_mul B, \u2190matrix.one_mul C, \u2190matrix.smul_mul, \u2190matrix.smul_mul, \u2190adjugate_mul,\n        matrix.mul_assoc, matrix.mul_assoc, \u2190mul_eq_mul A, h, mul_eq_mul] },\n  { intros B C h,\n    simp only [mul_eq_mul] at h,\n    refine hA.matrix _,\n    rw [\u2190matrix.mul_one B, \u2190matrix.mul_one C, \u2190matrix.mul_smul, \u2190matrix.mul_smul, \u2190mul_adjugate,\n        \u2190matrix.mul_assoc, \u2190matrix.mul_assoc, h] }\nend\n\nlemma adjugate_mul_distrib_aux (A B : matrix n n \u03b1)\n  (hA : is_left_regular A.det)\n  (hB : is_left_regular B.det) :\n  adjugate (A \u2b1d B) = adjugate B \u2b1d adjugate A :=\nbegin\n  have hAB : is_left_regular (A \u2b1d B).det,\n  { rw [det_mul],\n    exact hA.mul hB },\n  refine (is_regular_of_is_left_regular_det hAB).left _,\n  rw [mul_eq_mul, mul_adjugate, mul_eq_mul, matrix.mul_assoc, \u2190matrix.mul_assoc B, mul_adjugate,\n      smul_mul, matrix.one_mul, mul_smul, mul_adjugate, smul_smul, mul_comm, \u2190det_mul]\nend\n\n/--\nProof follows from \"The trace Cayley-Hamilton theorem\" by Darij Grinberg, Section 5.3\n-/\nlemma adjugate_mul_distrib (A B : matrix n n \u03b1) : adjugate (A \u2b1d B) = adjugate B \u2b1d adjugate A :=\nbegin\n  let g : matrix n n \u03b1 \u2192 matrix n n \u03b1[X] :=\n    \u03bb M, M.map polynomial.C + (polynomial.X : \u03b1[X]) \u2022 1,\n  let f' : matrix n n \u03b1[X] \u2192+* matrix n n \u03b1 := (polynomial.eval_ring_hom 0).map_matrix,\n  have f'_inv : \u2200 M, f' (g M) = M,\n  { intro,\n    ext,\n    simp [f', g], },\n  have f'_adj : \u2200 (M : matrix n n \u03b1), f' (adjugate (g M)) = adjugate M,\n  { intro,\n    rw [ring_hom.map_adjugate, f'_inv] },\n  have f'_g_mul : \u2200 (M N : matrix n n \u03b1), f' (g M \u2b1d g N) = M \u2b1d N,\n  { intros,\n    rw [\u2190mul_eq_mul, ring_hom.map_mul, f'_inv, f'_inv, mul_eq_mul] },\n  have hu : \u2200 (M : matrix n n \u03b1), is_regular (g M).det,\n  { intros M,\n    refine polynomial.monic.is_regular _,\n    simp only [g, polynomial.monic.def, \u2190polynomial.leading_coeff_det_X_one_add_C M, add_comm] },\n  rw [\u2190f'_adj, \u2190f'_adj, \u2190f'_adj, \u2190mul_eq_mul (f' (adjugate (g B))), \u2190f'.map_mul, mul_eq_mul,\n      \u2190adjugate_mul_distrib_aux _ _ (hu A).left (hu B).left, ring_hom.map_adjugate,\n      ring_hom.map_adjugate, f'_inv, f'_g_mul]\nend\n\n@[simp] lemma adjugate_pow (A : matrix n n \u03b1) (k : \u2115) :\n  adjugate (A ^ k) = (adjugate A) ^ k :=\nbegin\n  induction k with k IH,\n  { simp },\n  { rw [pow_succ', mul_eq_mul, adjugate_mul_distrib, IH, \u2190mul_eq_mul, pow_succ] }\nend\n\nlemma det_smul_adjugate_adjugate (A : matrix n n \u03b1) :\n  det A \u2022 adjugate (adjugate A) = det A ^ (fintype.card n - 1) \u2022 A :=\nbegin\n  have : A \u2b1d (A.adjugate \u2b1d A.adjugate.adjugate) = A \u2b1d (A.det ^ (fintype.card n - 1) \u2022 1),\n  { rw [\u2190adjugate_mul_distrib, adjugate_mul, adjugate_smul, adjugate_one], },\n  rwa [\u2190matrix.mul_assoc, mul_adjugate, matrix.mul_smul, matrix.mul_one, matrix.smul_mul,\n    matrix.one_mul] at this,\nend\n\n/-- Note that this is not true for `fintype.card n = 1` since `1 - 2 = 0` and not `-1`. -/\n\n\n  -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring\n  -- where `A'.det` is non-zero.\n  let A' := mv_polynomial_X n n \u2124,\n  suffices : adjugate (adjugate A') = det A' ^ (fintype.card n - 2) \u2022 A',\n  { rw [\u2190mv_polynomial_X_map_matrix_aeval \u2124 A, \u2190alg_hom.map_adjugate, \u2190alg_hom.map_adjugate, this,\n      \u2190alg_hom.map_det, \u2190 alg_hom.map_pow, alg_hom.map_matrix_apply, alg_hom.map_matrix_apply,\n      matrix.map_smul' _ _ _ (_root_.map_mul _)] },\n  have h_card' : fintype.card n - 2 + 1 = fintype.card n - 1,\n  { simp [h_card] },\n\n  have is_reg : is_smul_regular (mv_polynomial (n \u00d7 n) \u2124) (det A') :=\n    \u03bb x y, mul_left_cancel\u2080 (det_mv_polynomial_X_ne_zero n \u2124),\n  apply is_reg.matrix,\n  rw [smul_smul, \u2190pow_succ, h_card', det_smul_adjugate_adjugate],\nend\n\n/-- A weaker version of `matrix.adjugate_adjugate` that uses `nontrivial`. -/\nlemma adjugate_adjugate' (A : matrix n n \u03b1) [nontrivial n] :\n  adjugate (adjugate A) = det A ^ (fintype.card n - 2) \u2022 A :=\nadjugate_adjugate _ $ fintype.one_lt_card.ne'\n\nend adjugate\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/adjugate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7117336929062599}}
{"text": "/-\nThe intersection of algebraic sets is an algebraic set.\n\nKevin Buzzard\n-/\n\nimport affine_algebraic_set.basic -- the basic theory of affine algebraic sets.\n\n/-\n# The intersection of (any number of) affine algebraic sets is affine.\n\nLet k be a field and let n be a natural number. We prove the following\ntheorem in this file:\n\nTheorem. If I is an index set, and for each i \u2208 I we have an\naffine algebraic subset V\u1d62 of k\u207f, then the intersection \u22c2_{i \u2208 I} V\u1d62\nis also an affine algebraic subset of k\u207f.\n\nLean version: \n\n** TODO\n\nMaths proof: if V\u1d62 is cut out by the set S\u1d62 \u2286 k[X_1,X_2,\u2026,X_n]\nand we consider the set S = \u22c3_{i \u2208 I} S\u1d62 then it is straightforward\nto check that this works.\n\n## References\n\nMartin Orr's lecture notes at\nhttps://homepages.warwick.ac.uk/staff/Martin.Orr/2017-8/alg-geom/\n\n## Tags\n\nalgebraic geometry, algebraic variety\n-/\n\n-- end of docstring; code starts here. \n\n-- We're proving theorems about affine algebraic sets so the names of the theorems\n-- should start with \"affine_algebraic_set\".\nnamespace affine_algebraic_set\n\n-- let k be a field\nvariables {k : Type*} [discrete_field k]\n\n-- and let \u03c3 be a set of indexes for our polynomial variables e.g. \u03c3 = {1,2,...,n}\nvariable {\u03c3 : Type*}\n\n-- We're working with multivariable polynomials, so let's get access to their notation\nopen mv_polynomial\n\n-- this should be proved by general nonsense really. \n\n/-- An arbitrary intersection of affine algebraic subsets of k\u207f\n  is an affine algebraic subset of k\u207f -/\ndef Inter (I : Type*) (V : I \u2192 affine_algebraic_set k \u03c3) :\n  affine_algebraic_set k \u03c3 :=\n{ carrier := \u22c2 (i : I), (V i : set (\u03c3 \u2192 k)), -- the underlying set is the union of the two sets defining V and W\n  is_algebraic' :=\n  -- We now need to prove that the union is cut out by some set of polynomials.\n  begin\n    use \u22c3 (i : I), (classical.some (V i).is_algebraic),\n    ext x,\n    rw \ud835\udd4d_Union,\n    congr',\n    funext i,\n    exact classical.some_spec (V i).is_algebraic,\n  end\n}\n\nend affine_algebraic_set", "meta": {"author": "ImperialCollegeLondon", "repo": "M4P33", "sha": "1a179372db71ad6802d11eacbc1f02f327d55f8f", "save_path": "github-repos/lean/ImperialCollegeLondon-M4P33", "path": "github-repos/lean/ImperialCollegeLondon-M4P33/M4P33-1a179372db71ad6802d11eacbc1f02f327d55f8f/src/affine_algebraic_set/intersection.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7117336886058735}}
{"text": "/-\nCopyright (c) 2022 Jiale Miao. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jiale Miao, Kevin Buzzard, Alexander Bentkamp\n\n! This file was ported from Lean 3 source module analysis.inner_product_space.gram_schmidt_ortho\n! leanprover-community/mathlib commit 46b633fd842bef9469441c0209906f6dddd2b4f5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.InnerProductSpace.PiL2\nimport Mathbin.LinearAlgebra.Matrix.Block\n\n/-!\n# Gram-Schmidt Orthogonalization and Orthonormalization\n\nIn this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization.\n\nThe Gram-Schmidt process takes a set of vectors as input\nand outputs a set of orthogonal vectors which have the same span.\n\n## Main results\n\n- `gram_schmidt` : the Gram-Schmidt process\n- `gram_schmidt_orthogonal` :\n  `gram_schmidt` produces an orthogonal system of vectors.\n- `span_gram_schmidt` :\n  `gram_schmidt` preserves span of vectors.\n- `gram_schmidt_ne_zero` :\n  If the input vectors of `gram_schmidt` are linearly independent,\n  then the output vectors are non-zero.\n- `gram_schmidt_basis` :\n  The basis produced by the Gram-Schmidt process when given a basis as input.\n- `gram_schmidt_normed` :\n  the normalized `gram_schmidt` (i.e each vector in `gram_schmidt_normed` has unit length.)\n- `gram_schmidt_orthornormal` :\n  `gram_schmidt_normed` produces an orthornormal system of vectors.\n- `gram_schmidt_orthonormal_basis`: orthonormal basis constructed by the Gram-Schmidt process from\n  an indexed set of vectors of the right size\n-/\n\n\nopen BigOperators\n\nopen Finset Submodule FiniteDimensional\n\nvariable (\ud835\udd5c : Type _) {E : Type _} [IsROrC \ud835\udd5c] [NormedAddCommGroup E] [InnerProductSpace \ud835\udd5c E]\n\nvariable {\u03b9 : Type _} [LinearOrder \u03b9] [LocallyFiniteOrderBot \u03b9] [IsWellOrder \u03b9 (\u00b7 < \u00b7)]\n\nattribute [local instance] IsWellOrder.toHasWellFounded\n\n-- mathport name: \u00abexpr\u27ea , \u27eb\u00bb\nlocal notation \"\u27ea\" x \", \" y \"\u27eb\" => @inner \ud835\udd5c _ _ x y\n\n/-- The Gram-Schmidt process takes a set of vectors as input\nand outputs a set of orthogonal vectors which have the same span. -/\nnoncomputable def gramSchmidt (f : \u03b9 \u2192 E) : \u03b9 \u2192 E\n  | n => f n - \u2211 i : Iio n, orthogonalProjection (\ud835\udd5c \u2219 gramSchmidt i) (f n)decreasing_by\n  exact mem_Iio.1 i.2\n#align gram_schmidt gramSchmidt\n\n/-- This lemma uses `\u2211 i in` instead of `\u2211 i :`.-/\ntheorem gramSchmidt_def (f : \u03b9 \u2192 E) (n : \u03b9) :\n    gramSchmidt \ud835\udd5c f n = f n - \u2211 i in Iio n, orthogonalProjection (\ud835\udd5c \u2219 gramSchmidt \ud835\udd5c f i) (f n) :=\n  by\n  rw [\u2190 sum_attach, attach_eq_univ, gramSchmidt]\n  rfl\n#align gram_schmidt_def gramSchmidt_def\n\ntheorem gramSchmidt_def' (f : \u03b9 \u2192 E) (n : \u03b9) :\n    f n = gramSchmidt \ud835\udd5c f n + \u2211 i in Iio n, orthogonalProjection (\ud835\udd5c \u2219 gramSchmidt \ud835\udd5c f i) (f n) := by\n  rw [gramSchmidt_def, sub_add_cancel]\n#align gram_schmidt_def' gramSchmidt_def'\n\ntheorem gramSchmidt_def'' (f : \u03b9 \u2192 E) (n : \u03b9) :\n    f n =\n      gramSchmidt \ud835\udd5c f n +\n        \u2211 i in Iio n, (\u27eagramSchmidt \ud835\udd5c f i, f n\u27eb / \u2016gramSchmidt \ud835\udd5c f i\u2016 ^ 2) \u2022 gramSchmidt \ud835\udd5c f i :=\n  by\n  convert gramSchmidt_def' \ud835\udd5c f n\n  ext i\n  rw [orthogonalProjection_singleton]\n#align gram_schmidt_def'' gramSchmidt_def''\n\n@[simp]\ntheorem gramSchmidt_zero {\u03b9 : Type _} [LinearOrder \u03b9] [LocallyFiniteOrder \u03b9] [OrderBot \u03b9]\n    [IsWellOrder \u03b9 (\u00b7 < \u00b7)] (f : \u03b9 \u2192 E) : gramSchmidt \ud835\udd5c f \u22a5 = f \u22a5 := by\n  rw [gramSchmidt_def, Iio_eq_Ico, Finset.Ico_self, Finset.sum_empty, sub_zero]\n#align gram_schmidt_zero gramSchmidt_zero\n\n/-- **Gram-Schmidt Orthogonalisation**:\n`gram_schmidt` produces an orthogonal system of vectors. -/\ntheorem gramSchmidt_orthogonal (f : \u03b9 \u2192 E) {a b : \u03b9} (h\u2080 : a \u2260 b) :\n    \u27eagramSchmidt \ud835\udd5c f a, gramSchmidt \ud835\udd5c f b\u27eb = 0 :=\n  by\n  suffices \u2200 a b : \u03b9, a < b \u2192 \u27eagramSchmidt \ud835\udd5c f a, gramSchmidt \ud835\udd5c f b\u27eb = 0\n    by\n    cases' h\u2080.lt_or_lt with ha hb\n    \u00b7 exact this _ _ ha\n    \u00b7 rw [inner_eq_zero_symm]\n      exact this _ _ hb\n  clear h\u2080 a b\n  intro a b h\u2080\n  revert a\n  apply WellFounded.induction (@IsWellFounded.wf \u03b9 (\u00b7 < \u00b7) _) b\n  intro b ih a h\u2080\n  simp only [gramSchmidt_def \ud835\udd5c f b, inner_sub_right, inner_sum, orthogonalProjection_singleton,\n    inner_smul_right]\n  rw [Finset.sum_eq_single_of_mem a (finset.mem_Iio.mpr h\u2080)]\n  \u00b7 by_cases h : gramSchmidt \ud835\udd5c f a = 0\n    \u00b7 simp only [h, inner_zero_left, zero_div, MulZeroClass.zero_mul, sub_zero]\n    \u00b7 rw [\u2190 inner_self_eq_norm_sq_to_K, div_mul_cancel, sub_self]\n      rwa [inner_self_ne_zero]\n  simp_intro i hi hia only [Finset.mem_range]\n  simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero]\n  right\n  cases' hia.lt_or_lt with hia\u2081 hia\u2082\n  \u00b7 rw [inner_eq_zero_symm]\n    exact ih a h\u2080 i hia\u2081\n  \u00b7 exact ih i (mem_Iio.1 hi) a hia\u2082\n#align gram_schmidt_orthogonal gramSchmidt_orthogonal\n\n/-- This is another version of `gram_schmidt_orthogonal` using `pairwise` instead. -/\ntheorem gramSchmidt_pairwise_orthogonal (f : \u03b9 \u2192 E) :\n    Pairwise fun a b => \u27eagramSchmidt \ud835\udd5c f a, gramSchmidt \ud835\udd5c f b\u27eb = 0 := fun a b =>\n  gramSchmidt_orthogonal \ud835\udd5c f\n#align gram_schmidt_pairwise_orthogonal gramSchmidt_pairwise_orthogonal\n\ntheorem gramSchmidt_inv_triangular (v : \u03b9 \u2192 E) {i j : \u03b9} (hij : i < j) :\n    \u27eagramSchmidt \ud835\udd5c v j, v i\u27eb = 0 := by\n  rw [gramSchmidt_def'' \ud835\udd5c v]\n  simp only [inner_add_right, inner_sum, inner_smul_right]\n  set b : \u03b9 \u2192 E := gramSchmidt \ud835\udd5c v\n  convert zero_add (0 : \ud835\udd5c)\n  \u00b7 exact gramSchmidt_orthogonal \ud835\udd5c v hij.ne'\n  apply Finset.sum_eq_zero\n  rintro k hki'\n  have hki : k < i := by simpa using hki'\n  have : \u27eab j, b k\u27eb = 0 := gramSchmidt_orthogonal \ud835\udd5c v (hki.trans hij).ne'\n  simp [this]\n#align gram_schmidt_inv_triangular gramSchmidt_inv_triangular\n\nopen Submodule Set Order\n\ntheorem mem_span_gramSchmidt (f : \u03b9 \u2192 E) {i j : \u03b9} (hij : i \u2264 j) :\n    f i \u2208 span \ud835\udd5c (gramSchmidt \ud835\udd5c f '' Iic j) :=\n  by\n  rw [gramSchmidt_def' \ud835\udd5c f i]\n  simp_rw [orthogonalProjection_singleton]\n  exact\n    Submodule.add_mem _ (subset_span <| mem_image_of_mem _ hij)\n      (Submodule.sum_mem _ fun k hk =>\n        smul_mem (span \ud835\udd5c (gramSchmidt \ud835\udd5c f '' Iic j)) _ <|\n          subset_span <| mem_image_of_mem (gramSchmidt \ud835\udd5c f) <| (Finset.mem_Iio.1 hk).le.trans hij)\n#align mem_span_gram_schmidt mem_span_gramSchmidt\n\ntheorem gramSchmidt_mem_span (f : \u03b9 \u2192 E) : \u2200 {j i}, i \u2264 j \u2192 gramSchmidt \ud835\udd5c f i \u2208 span \ud835\udd5c (f '' Iic j)\n  | j => fun i hij => by\n    rw [gramSchmidt_def \ud835\udd5c f i]\n    simp_rw [orthogonalProjection_singleton]\n    refine'\n      Submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij)) (Submodule.sum_mem _ fun k hk => _)\n    let hkj : k < j := (Finset.mem_Iio.1 hk).trans_le hij\n    exact\n      smul_mem _ _\n        (span_mono (image_subset f <| Iic_subset_Iic.2 hkj.le) <| gramSchmidt_mem_span le_rfl)\n#align gram_schmidt_mem_span gramSchmidt_mem_span\n\ntheorem span_gramSchmidt_Iic (f : \u03b9 \u2192 E) (c : \u03b9) :\n    span \ud835\udd5c (gramSchmidt \ud835\udd5c f '' Iic c) = span \ud835\udd5c (f '' Iic c) :=\n  span_eq_span (Set.image_subset_iff.2 fun i => gramSchmidt_mem_span _ _) <|\n    Set.image_subset_iff.2 fun i => mem_span_gramSchmidt _ _\n#align span_gram_schmidt_Iic span_gramSchmidt_Iic\n\ntheorem span_gramSchmidt_Iio (f : \u03b9 \u2192 E) (c : \u03b9) :\n    span \ud835\udd5c (gramSchmidt \ud835\udd5c f '' Iio c) = span \ud835\udd5c (f '' Iio c) :=\n  span_eq_span\n      (Set.image_subset_iff.2 fun i hi =>\n        span_mono (image_subset _ <| Iic_subset_Iio.2 hi) <| gramSchmidt_mem_span _ _ le_rfl) <|\n    Set.image_subset_iff.2 fun i hi =>\n      span_mono (image_subset _ <| Iic_subset_Iio.2 hi) <| mem_span_gramSchmidt _ _ le_rfl\n#align span_gram_schmidt_Iio span_gramSchmidt_Iio\n\n/-- `gram_schmidt` preserves span of vectors. -/\ntheorem span_gramSchmidt (f : \u03b9 \u2192 E) : span \ud835\udd5c (range (gramSchmidt \ud835\udd5c f)) = span \ud835\udd5c (range f) :=\n  span_eq_span\n      (range_subset_iff.2 fun i =>\n        span_mono (image_subset_range _ _) <| gramSchmidt_mem_span _ _ le_rfl) <|\n    range_subset_iff.2 fun i =>\n      span_mono (image_subset_range _ _) <| mem_span_gramSchmidt _ _ le_rfl\n#align span_gram_schmidt span_gramSchmidt\n\ntheorem gramSchmidt_of_orthogonal {f : \u03b9 \u2192 E} (hf : Pairwise fun i j => \u27eaf i, f j\u27eb = 0) :\n    gramSchmidt \ud835\udd5c f = f := by\n  ext i\n  rw [gramSchmidt_def]\n  trans f i - 0\n  \u00b7 congr\n    apply Finset.sum_eq_zero\n    intro j hj\n    rw [coe_eq_zero]\n    suffices span \ud835\udd5c (f '' Set.Iic j) \u2264 (\ud835\udd5c \u2219 f i)\u15ee\n      by\n      apply orthogonalProjection_mem_subspace_orthogonal_complement_eq_zero\n      rw [mem_orthogonal_singleton_iff_inner_left]\n      rw [\u2190 mem_orthogonal_singleton_iff_inner_right]\n      exact this (gramSchmidt_mem_span \ud835\udd5c f (le_refl j))\n    rw [span_le]\n    rintro - \u27e8k, hk, rfl\u27e9\n    rw [SetLike.mem_coe, mem_orthogonal_singleton_iff_inner_left]\n    apply hf\n    refine' (lt_of_le_of_lt hk _).Ne\n    simpa using hj\n  \u00b7 simp\n#align gram_schmidt_of_orthogonal gramSchmidt_of_orthogonal\n\nvariable {\ud835\udd5c}\n\ntheorem gramSchmidt_ne_zero_coe {f : \u03b9 \u2192 E} (n : \u03b9)\n    (h\u2080 : LinearIndependent \ud835\udd5c (f \u2218 (coe : Set.Iic n \u2192 \u03b9))) : gramSchmidt \ud835\udd5c f n \u2260 0 :=\n  by\n  by_contra h\n  have h\u2081 : f n \u2208 span \ud835\udd5c (f '' Iio n) :=\n    by\n    rw [\u2190 span_gramSchmidt_Iio \ud835\udd5c f n, gramSchmidt_def' _ f, h, zero_add]\n    apply Submodule.sum_mem _ _\n    simp_intro a ha only [Finset.mem_Ico]\n    simp only [Set.mem_image, Set.mem_Iio, orthogonalProjection_singleton]\n    apply Submodule.smul_mem _ _ _\n    rw [Finset.mem_Iio] at ha\n    refine' subset_span \u27e8a, ha, by rfl\u27e9\n  have h\u2082 :\n    (f \u2218 (coe : Set.Iic n \u2192 \u03b9)) \u27e8n, le_refl n\u27e9 \u2208\n      span \ud835\udd5c (f \u2218 (coe : Set.Iic n \u2192 \u03b9) '' Iio \u27e8n, le_refl n\u27e9) :=\n    by\n    rw [image_comp]\n    convert h\u2081 using 3\n    ext i\n    simpa using @le_of_lt _ _ i n\n  apply LinearIndependent.not_mem_span_image h\u2080 _ h\u2082\n  simp only [Set.mem_Iio, lt_self_iff_false, not_false_iff]\n#align gram_schmidt_ne_zero_coe gramSchmidt_ne_zero_coe\n\n/-- If the input vectors of `gram_schmidt` are linearly independent,\nthen the output vectors are non-zero. -/\ntheorem gramSchmidt_ne_zero {f : \u03b9 \u2192 E} (n : \u03b9) (h\u2080 : LinearIndependent \ud835\udd5c f) :\n    gramSchmidt \ud835\udd5c f n \u2260 0 :=\n  gramSchmidt_ne_zero_coe _ (LinearIndependent.comp h\u2080 _ Subtype.coe_injective)\n#align gram_schmidt_ne_zero gramSchmidt_ne_zero\n\n/-- `gram_schmidt` produces a triangular matrix of vectors when given a basis. -/\ntheorem gramSchmidt_triangular {i j : \u03b9} (hij : i < j) (b : Basis \u03b9 \ud835\udd5c E) :\n    b.repr (gramSchmidt \ud835\udd5c b i) j = 0 :=\n  by\n  have : gramSchmidt \ud835\udd5c b i \u2208 span \ud835\udd5c (gramSchmidt \ud835\udd5c b '' Set.Iio j) :=\n    subset_span ((Set.mem_image _ _ _).2 \u27e8i, hij, rfl\u27e9)\n  have : gramSchmidt \ud835\udd5c b i \u2208 span \ud835\udd5c (b '' Set.Iio j) := by rwa [\u2190 span_gramSchmidt_Iio \ud835\udd5c b j]\n  have : \u2191(b.repr (gramSchmidt \ud835\udd5c b i)).support \u2286 Set.Iio j :=\n    Basis.repr_support_subset_of_mem_span b (Set.Iio j) this\n  exact (Finsupp.mem_supported' _ _).1 ((Finsupp.mem_supported \ud835\udd5c _).2 this) j Set.not_mem_Iio_self\n#align gram_schmidt_triangular gramSchmidt_triangular\n\n/-- `gram_schmidt` produces linearly independent vectors when given linearly independent vectors. -/\ntheorem gramSchmidt_linearIndependent {f : \u03b9 \u2192 E} (h\u2080 : LinearIndependent \ud835\udd5c f) :\n    LinearIndependent \ud835\udd5c (gramSchmidt \ud835\udd5c f) :=\n  linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => gramSchmidt_ne_zero _ h\u2080) fun i j =>\n    gramSchmidt_orthogonal \ud835\udd5c f\n#align gram_schmidt_linear_independent gramSchmidt_linearIndependent\n\n/-- When given a basis, `gram_schmidt` produces a basis. -/\nnoncomputable def gramSchmidtBasis (b : Basis \u03b9 \ud835\udd5c E) : Basis \u03b9 \ud835\udd5c E :=\n  Basis.mk (gramSchmidt_linearIndependent b.LinearIndependent)\n    ((span_gramSchmidt \ud835\udd5c b).trans b.span_eq).ge\n#align gram_schmidt_basis gramSchmidtBasis\n\ntheorem coe_gramSchmidtBasis (b : Basis \u03b9 \ud835\udd5c E) : (gramSchmidtBasis b : \u03b9 \u2192 E) = gramSchmidt \ud835\udd5c b :=\n  Basis.coe_mk _ _\n#align coe_gram_schmidt_basis coe_gramSchmidtBasis\n\nvariable (\ud835\udd5c)\n\n/-- the normalized `gram_schmidt`\n(i.e each vector in `gram_schmidt_normed` has unit length.) -/\nnoncomputable def gramSchmidtNormed (f : \u03b9 \u2192 E) (n : \u03b9) : E :=\n  (\u2016gramSchmidt \ud835\udd5c f n\u2016 : \ud835\udd5c)\u207b\u00b9 \u2022 gramSchmidt \ud835\udd5c f n\n#align gram_schmidt_normed gramSchmidtNormed\n\nvariable {\ud835\udd5c}\n\ntheorem gramSchmidtNormed_unit_length_coe {f : \u03b9 \u2192 E} (n : \u03b9)\n    (h\u2080 : LinearIndependent \ud835\udd5c (f \u2218 (coe : Set.Iic n \u2192 \u03b9))) : \u2016gramSchmidtNormed \ud835\udd5c f n\u2016 = 1 := by\n  simp only [gramSchmidt_ne_zero_coe n h\u2080, gramSchmidtNormed, norm_smul_inv_norm, Ne.def,\n    not_false_iff]\n#align gram_schmidt_normed_unit_length_coe gramSchmidtNormed_unit_length_coe\n\ntheorem gramSchmidtNormed_unit_length {f : \u03b9 \u2192 E} (n : \u03b9) (h\u2080 : LinearIndependent \ud835\udd5c f) :\n    \u2016gramSchmidtNormed \ud835\udd5c f n\u2016 = 1 :=\n  gramSchmidtNormed_unit_length_coe _ (LinearIndependent.comp h\u2080 _ Subtype.coe_injective)\n#align gram_schmidt_normed_unit_length gramSchmidtNormed_unit_length\n\ntheorem gramSchmidtNormed_unit_length' {f : \u03b9 \u2192 E} {n : \u03b9} (hn : gramSchmidtNormed \ud835\udd5c f n \u2260 0) :\n    \u2016gramSchmidtNormed \ud835\udd5c f n\u2016 = 1 :=\n  by\n  rw [gramSchmidtNormed] at *\n  rw [norm_smul_inv_norm]\n  simpa using hn\n#align gram_schmidt_normed_unit_length' gramSchmidtNormed_unit_length'\n\n/-- **Gram-Schmidt Orthonormalization**:\n`gram_schmidt_normed` applied to a linearly independent set of vectors produces an orthornormal\nsystem of vectors. -/\ntheorem gram_schmidt_orthonormal {f : \u03b9 \u2192 E} (h\u2080 : LinearIndependent \ud835\udd5c f) :\n    Orthonormal \ud835\udd5c (gramSchmidtNormed \ud835\udd5c f) :=\n  by\n  unfold Orthonormal\n  constructor\n  \u00b7 simp only [gramSchmidtNormed_unit_length, h\u2080, eq_self_iff_true, imp_true_iff]\n  \u00b7 intro i j hij\n    simp only [gramSchmidtNormed, inner_smul_left, inner_smul_right, IsROrC.conj_inv,\n      IsROrC.conj_of_real, mul_eq_zero, inv_eq_zero, IsROrC.of_real_eq_zero, norm_eq_zero]\n    repeat' right\n    exact gramSchmidt_orthogonal \ud835\udd5c f hij\n#align gram_schmidt_orthonormal gram_schmidt_orthonormal\n\n/-- **Gram-Schmidt Orthonormalization**:\n`gram_schmidt_normed` produces an orthornormal system of vectors after removing the vectors which\nbecome zero in the process. -/\ntheorem gram_schmidt_orthonormal' (f : \u03b9 \u2192 E) :\n    Orthonormal \ud835\udd5c fun i : { i | gramSchmidtNormed \ud835\udd5c f i \u2260 0 } => gramSchmidtNormed \ud835\udd5c f i :=\n  by\n  refine' \u27e8fun i => gramSchmidtNormed_unit_length' i.Prop, _\u27e9\n  rintro i j (hij : \u00ac_)\n  rw [Subtype.ext_iff] at hij\n  simp [gramSchmidtNormed, inner_smul_left, inner_smul_right, gramSchmidt_orthogonal \ud835\udd5c f hij]\n#align gram_schmidt_orthonormal' gram_schmidt_orthonormal'\n\ntheorem span_gramSchmidtNormed (f : \u03b9 \u2192 E) (s : Set \u03b9) :\n    span \ud835\udd5c (gramSchmidtNormed \ud835\udd5c f '' s) = span \ud835\udd5c (gramSchmidt \ud835\udd5c f '' s) :=\n  by\n  refine'\n    span_eq_span\n      (Set.image_subset_iff.2 fun i hi => smul_mem _ _ <| subset_span <| mem_image_of_mem _ hi)\n      (Set.image_subset_iff.2 fun i hi =>\n        span_mono (image_subset _ <| singleton_subset_set_iff.2 hi) _)\n  simp only [coe_singleton, Set.image_singleton]\n  by_cases h : gramSchmidt \ud835\udd5c f i = 0\n  \u00b7 simp [h]\n  \u00b7 refine' mem_span_singleton.2 \u27e8\u2016gramSchmidt \ud835\udd5c f i\u2016, smul_inv_smul\u2080 _ _\u27e9\n    exact_mod_cast norm_ne_zero_iff.2 h\n#align span_gram_schmidt_normed span_gramSchmidtNormed\n\ntheorem span_gramSchmidtNormed_range (f : \u03b9 \u2192 E) :\n    span \ud835\udd5c (range (gramSchmidtNormed \ud835\udd5c f)) = span \ud835\udd5c (range (gramSchmidt \ud835\udd5c f)) := by\n  simpa only [image_univ.symm] using span_gramSchmidtNormed f univ\n#align span_gram_schmidt_normed_range span_gramSchmidtNormed_range\n\nsection OrthonormalBasis\n\nvariable [Fintype \u03b9] [FiniteDimensional \ud835\udd5c E] (h : finrank \ud835\udd5c E = Fintype.card \u03b9) (f : \u03b9 \u2192 E)\n\ninclude h\n\n/-- Given an indexed family `f : \u03b9 \u2192 E` of vectors in an inner product space `E`, for which the\nsize of the index set is the dimension of `E`, produce an orthonormal basis for `E` which agrees\nwith the orthonormal set produced by the Gram-Schmidt orthonormalization process on the elements of\n`\u03b9` for which this process gives a nonzero number. -/\nnoncomputable def gramSchmidtOrthonormalBasis : OrthonormalBasis \u03b9 \ud835\udd5c E :=\n  ((gram_schmidt_orthonormal' f).exists_orthonormalBasis_extension_of_card_eq h).some\n#align gram_schmidt_orthonormal_basis gramSchmidtOrthonormalBasis\n\ntheorem gramSchmidtOrthonormalBasis_apply {f : \u03b9 \u2192 E} {i : \u03b9} (hi : gramSchmidtNormed \ud835\udd5c f i \u2260 0) :\n    gramSchmidtOrthonormalBasis h f i = gramSchmidtNormed \ud835\udd5c f i :=\n  ((gram_schmidt_orthonormal' f).exists_orthonormalBasis_extension_of_card_eq h).choose_spec i hi\n#align gram_schmidt_orthonormal_basis_apply gramSchmidtOrthonormalBasis_apply\n\ntheorem gramSchmidtOrthonormalBasis_apply_of_orthogonal {f : \u03b9 \u2192 E}\n    (hf : Pairwise fun i j => \u27eaf i, f j\u27eb = 0) {i : \u03b9} (hi : f i \u2260 0) :\n    gramSchmidtOrthonormalBasis h f i = (\u2016f i\u2016\u207b\u00b9 : \ud835\udd5c) \u2022 f i :=\n  by\n  have H : gramSchmidtNormed \ud835\udd5c f i = (\u2016f i\u2016\u207b\u00b9 : \ud835\udd5c) \u2022 f i := by\n    rw [gramSchmidtNormed, gramSchmidt_of_orthogonal \ud835\udd5c hf]\n  rw [gramSchmidtOrthonormalBasis_apply h, H]\n  simpa [H] using hi\n#align gram_schmidt_orthonormal_basis_apply_of_orthogonal gramSchmidtOrthonormalBasis_apply_of_orthogonal\n\ntheorem inner_gramSchmidtOrthonormalBasis_eq_zero {f : \u03b9 \u2192 E} {i : \u03b9}\n    (hi : gramSchmidtNormed \ud835\udd5c f i = 0) (j : \u03b9) : \u27eagramSchmidtOrthonormalBasis h f i, f j\u27eb = 0 :=\n  by\n  rw [\u2190 mem_orthogonal_singleton_iff_inner_right]\n  suffices span \ud835\udd5c (gramSchmidtNormed \ud835\udd5c f '' Iic j) \u2264 (\ud835\udd5c \u2219 gramSchmidtOrthonormalBasis h f i)\u15ee\n    by\n    apply this\n    rw [span_gramSchmidtNormed]\n    simpa using mem_span_gramSchmidt \ud835\udd5c f (le_refl j)\n  rw [span_le]\n  rintro - \u27e8k, -, rfl\u27e9\n  rw [SetLike.mem_coe, mem_orthogonal_singleton_iff_inner_left]\n  by_cases hk : gramSchmidtNormed \ud835\udd5c f k = 0\n  \u00b7 simp [hk]\n  rw [\u2190 gramSchmidtOrthonormalBasis_apply h hk]\n  have : k \u2260 i := by\n    rintro rfl\n    exact hk hi\n  exact (gramSchmidtOrthonormalBasis h f).Orthonormal.2 this\n#align inner_gram_schmidt_orthonormal_basis_eq_zero inner_gramSchmidtOrthonormalBasis_eq_zero\n\ntheorem gramSchmidtOrthonormalBasis_inv_triangular {i j : \u03b9} (hij : i < j) :\n    \u27eagramSchmidtOrthonormalBasis h f j, f i\u27eb = 0 :=\n  by\n  by_cases hi : gramSchmidtNormed \ud835\udd5c f j = 0\n  \u00b7 rw [inner_gramSchmidtOrthonormalBasis_eq_zero h hi]\n  \u00b7\n    simp [gramSchmidtOrthonormalBasis_apply h hi, gramSchmidtNormed, inner_smul_left,\n      gramSchmidt_inv_triangular \ud835\udd5c f hij]\n#align gram_schmidt_orthonormal_basis_inv_triangular gramSchmidtOrthonormalBasis_inv_triangular\n\ntheorem gramSchmidtOrthonormalBasis_inv_triangular' {i j : \u03b9} (hij : i < j) :\n    (gramSchmidtOrthonormalBasis h f).repr (f i) j = 0 := by\n  simpa [OrthonormalBasis.repr_apply_apply] using gramSchmidtOrthonormalBasis_inv_triangular h f hij\n#align gram_schmidt_orthonormal_basis_inv_triangular' gramSchmidtOrthonormalBasis_inv_triangular'\n\n/-- Given an indexed family `f : \u03b9 \u2192 E` of vectors in an inner product space `E`, for which the\nsize of the index set is the dimension of `E`, the matrix of coefficients of `f` with respect to the\northonormal basis `gram_schmidt_orthonormal_basis` constructed from `f` is upper-triangular. -/\ntheorem gramSchmidtOrthonormalBasis_inv_blockTriangular :\n    ((gramSchmidtOrthonormalBasis h f).toBasis.toMatrix f).BlockTriangular id := fun i j =>\n  gramSchmidtOrthonormalBasis_inv_triangular' h f\n#align gram_schmidt_orthonormal_basis_inv_block_triangular gramSchmidtOrthonormalBasis_inv_blockTriangular\n\ntheorem gramSchmidtOrthonormalBasis_det :\n    (gramSchmidtOrthonormalBasis h f).toBasis.det f =\n      \u220f i, \u27eagramSchmidtOrthonormalBasis h f i, f i\u27eb :=\n  by\n  convert Matrix.det_of_upper_triangular (gramSchmidtOrthonormalBasis_inv_blockTriangular h f)\n  ext i\n  exact ((gramSchmidtOrthonormalBasis h f).repr_apply_apply (f i) i).symm\n#align gram_schmidt_orthonormal_basis_det gramSchmidtOrthonormalBasis_det\n\nend OrthonormalBasis\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/InnerProductSpace/GramSchmidtOrtho.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7117336820563577}}
{"text": "import solutions.world1_addition -- addition lemmas\n\nimport mynat.mul\n/- Here's what you get from the import:\n\n1) The following data:\n  * a function called mynat.mul, and notation a * b for this function\n\n2) The following axioms:\n\n  * `mul_zero : \u2200 a : mynat, a * 0 = 0`\n  * `mul_succ : \u2200 a b : mynat, a * succ(b) = a * b + a`\n\nThese axiom between them tell you how to work out a * x for every x; use induction on x to\nreduce to the case either `x = 0` or `x = succ b`, and then use `mul_zero` or `mul_succ` appropriately.\n-/\n\nnamespace mynat\n\n--MULTIPLICATION WORLD\n\n--Level 1 :\nlemma zero_mul (m : mynat) : 0 * m = 0 :=\nbegin [nat_num_game]\n  -- On fait une induction sur m :\n  induction m with d hd,\n\n  -- Le cas de base :\n  rw mul_zero,\n  refl,\n\n  -- Le cas d'induction :\n  rw mul_succ,\n  rw add_zero,\n  rw hd,\n  refl,\nend\n\n--Level 2 :\nlemma mul_one (m : mynat) : m * 1 = m :=\nbegin [nat_num_game]\n  -- On fait une induction sur m :\n  induction m with d hd,\n\n  -- Le cas de base :\n  rw zero_mul,\n  refl,\n\n  -- Le cas d'induction :\n  rw one_eq_succ_zero,\n  rw mul_succ,\n  rw mul_zero,\n  rw zero_add,\n  refl,\nend\n\n--Level 3 :\nlemma one_mul (m : mynat) : 1 * m = m :=\nbegin [nat_num_game]\n  -- On fait une induction sur m :\n  induction m with d hd,\n  \n  -- Le cas de base :\n  rw mul_zero,\n  refl,\n\n  -- Le cas d'induction :\n  rw mul_succ,\n  rw hd,\n  rw succ_eq_add_one,\n  refl,\nend\n\n-- mul_assoc immediately, leads to this:\n-- \u22a2 a * (b * d) + a * b = a * (b * d + b)\n\n-- so let's prove mul_add first.\n\n--Level 4 :\nlemma mul_add (a b c : mynat) : a * (b + c) = a * b + a * c :=\nbegin [nat_num_game]\n  -- On fait une induction sur b :\n  induction c with d hd,\n\n  -- Le cas de base :\n  refl,\n\n  -- Le cas d'induction :  \n  rw mul_succ,\n  rw \u2190 add_assoc,\n  rw \u2190 hd,\n  rw add_succ,\n  rw mul_succ,\n  refl,\nend\n\n-- just ignore this\ndef left_distrib := mul_add -- stupid field name, \n-- I just don't instinctively know what left_distrib means\n\n--Level 5 :\nlemma mul_assoc (a b c : mynat) : (a * b) * c = a * (b * c) :=\nbegin [nat_num_game]\n  -- On fait une induction sur c :\n  induction c with d hd,\n\n  -- Le cas de base :\n  repeat {rw mul_zero},\n\n  -- Le cas d'induction :\n  repeat {rw mul_succ},\n  rw mul_add,\n  rw hd,\n  refl,\nend\n\n-- goal : mul_comm. \n-- mul_comm leads to \u22a2 a * d + a = succ d * a\n-- so perhaps we need add_mul\n-- but add_mul leads to either a+b+c=a+c+b or (a+b)+(c+d)=(a+c)+(b+d)\n-- (depending on whether we do induction on b or c)\n\n-- I need this for mul_comm\n--Level 6 :\nlemma succ_mul (a b : mynat) : succ a * b = a * b + b :=\nbegin [nat_num_game]\n-- Attention, ne pas oublier de taper 'espace' apr\u00e8s les '\\l' !!!\n  -- On fait une induction sur b :\n  induction b with d hd,\n\n  -- Le cas de base :\n  refl,\n\n  -- Le cas d'induction :\n  rw succ_eq_add_one d,\n  rw mul_add,\n  rw hd,\n  rw succ_eq_add_one,\n  rw mul_add,\n  repeat {rw mul_one},\n  repeat {rw \u2190 add_assoc},\n  rw add_assoc,\n  rw add_assoc  (a * d) (d) (a + 1),\n  rw add_comm d _,\n  rw add_right_comm,\n  rw \u2190 add_assoc (a*d) (a+d) 1,\n  rw \u2190 add_assoc (a*d) a d,\n  refl,\nend\n\n--Level 7 :\nlemma add_mul (a b c : mynat) : (a + b) * c = a * c + b * c :=\nbegin [nat_num_game]\n  -- On fait une induction sur t :\n  induction c with d hd,\n\n  -- Le cas de base :\n  refl,\n\n  -- Le cas d'induction :  \n  repeat {rw mul_succ},\n  rw hd,\n  rw \u2190 add_assoc,\n  rw \u2190 add_assoc (a*d +a) _ _,\n  rw add_assoc (a*d) a _,\n  rw add_comm a (b*d),\n  rw \u2190 add_assoc,\n  refl,\nend\n\n-- ignore this\ndef right_distrib := add_mul -- stupid field name, \n\n--Level 8 :\nlemma mul_comm (a b : mynat) : a * b = b * a :=\nbegin [nat_num_game]\n  -- On fait une induction sur b :\n  induction b with d hd,\n\n  -- Le cas de base :\n  rw zero_mul,\n  rw mul_zero,\n  refl,\n\n  -- Le cas d'induction :  \n  rw mul_succ,\n  rw succ_mul,\n  rw hd,\n  refl,\nend\n\n--Level 9 :\nlemma mul_left_comm (a b c : mynat) : a * (b * c) = b * (a * c) :=\nbegin [nat_num_game]\n  -- On met tout dans le bon ordre\n  rw \u2190 mul_assoc,\n  rw mul_comm a b,\n  rw mul_assoc,\n  refl,\nend\n\n\n--ADVANCED MULTIPLICATION WORLD\n\n--Level 1 :\ntheorem mul_pos (a b : mynat) : a \u2260 0 \u2192 b \u2260 0 \u2192 a * b \u2260 0 :=\nbegin [nat_num_game]\n  intros ha hb hab,\n  apply ha,\n\n  --On divise le goal en 2 cas :\n  cases b with n,\n  \n  --Le cas 'b = 0' :\n  exfalso,\n  apply hb,\n  refl,\n\n  --Le cas 'b = succ n' :\n  rw mul_succ at hab,\n  rw add_left_eq_zero hab,\n  refl,\nend\n\n--Level 2 :\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero \u2983a b : mynat\u2984 (h : a * b = 0) : a = 0 \u2228 b = 0 :=\nbegin [nat_num_game]\n  --On fait une distintion de cas sur b :\n  cases b with n,\n\n  --Cas 'b = 0' :\n  right,\n  refl,\n\n  --Cas 'b = succ n' :\n  rw mul_succ at h,   --Pas strictement n\u00e9cessaire car les notations sont \u00e9gales par d\u00e9finition.\n  left,\n  apply add_left_eq_zero h,\nend\n\n--Level 3 :\ntheorem mul_eq_zero_iff : \u2200 (a b : mynat), a * b = 0 \u2194 a = 0 \u2228 b = 0 :=\nbegin [nat_num_game]\n  intros a b,\n  --On divise le goal en 2 implications :\n  split,\n\n  --Sens \u2192 \n  intro h,\n  exact eq_zero_or_eq_zero_of_mul_eq_zero h,\n\n  --Sens \u2190 \n  intro h,\n  cases h with g h,\n  rw g,\n  rw zero_mul,\n  refl,\n  rw h,\n  rw mul_zero,\n  refl,\nend\n\ninstance : comm_semiring mynat := by structure_helper\n\n--Level 4 :\ntheorem mul_left_cancel \u2983a b c : mynat\u2984 (ha : a \u2260 0) : a * b = a * c \u2192 b = c :=\nbegin [nat_num_game]\n-- Attention, ne pas oublier de taper 'espace' apr\u00e8s les '\\or' et '\\ne'!!!\n  revert b,\n  -- On fait une induction sur c :\n  induction c with n hn,\n\n  --Le cas de base :\n  rw mul_zero,\n  intros b h,\n  rw mul_eq_zero_iff a b at h,\n  --On casse le \u2228 :\n  cases h with hha hhb,\n  --Si 'a = 0' :\n  exfalso,\n  apply ha,\n  exact hha,\n  --Si 'b = 0' :\n  exact hhb,\n\n  --Le cas d'induction :\n  intros b h,\n  --On fait une distinction de cas sur b :\n  cases b with c,\n\n  --Cas 'b = 0' :\n  rw mul_zero at h,\n  exfalso,\n  apply mul_pos a (succ n), --On a besoin de d\u00e9montrer les hypoth\u00e8ses de mul_pos :\n  --Hypoth\u00e8se 'a \u2260 0' :\n  exact ha,\n  --Hypoth\u00e8se 'succ n \u2260 0' :\n  intro hnn,\n  exact succ_ne_zero hnn,\n  --Retour \u00e0 la preuve par l'absurde :\n  symmetry,\n  exact h,\n\n  --Cas 'b = succ c' :\n  repeat {rw succ_eq_add_one},\n  rw add_right_cancel_iff,\n  apply hn,\n  repeat {rw mul_succ at h},\n  rw add_right_cancel_iff at h,\n  exact h,\nend\n\nend mynat\n", "meta": {"author": "RaitoBezarius", "repo": "projet-maths-lean", "sha": "42356e980e021a20c3468f5ca1639fec01bb934f", "save_path": "github-repos/lean/RaitoBezarius-projet-maths-lean", "path": "github-repos/lean/RaitoBezarius-projet-maths-lean/projet-maths-lean-42356e980e021a20c3468f5ca1639fec01bb934f/Lean Game/world2_multiplication.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7117336816606133}}
{"text": "\n\ndef fib : Nat \u2192 Nat\n| 0   => 1\n| 1   => 1\n| n+2 => fib n + fib (n+1)\n\nexample : fib 0 = 1 := rfl\nexample : fib 1 = 1 := rfl\nexample (n : Nat) : fib (n+2) = fib n + fib (n+1) := rfl\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/def5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9615338057771058, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.7117026712700167}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module order.monotone.basic\n! leanprover-community/mathlib commit ac5a7cec422c3909db52e13dde2e729657d19b0e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Init.Data.Int.Order\nimport Mathlib.Order.Compare\nimport Mathlib.Order.Max\nimport Mathlib.Order.RelClasses\nimport Mathlib.Tactic.Choose\nimport Mathlib.Tactic.SimpRw\nimport Mathlib.Tactic.Coe\n\n/-!\n# Monotonicity\n\nThis file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage,\n\"monotone\"/\"mono\" here means \"increasing\", not \"increasing or decreasing\". We use \"antitone\"/\"anti\"\nto mean \"decreasing\".\n\n## Definitions\n\n* `Monotone f`: A function `f` between two preorders is monotone if `a \u2264 b` implies `f a \u2264 f b`.\n* `Antitone f`: A function `f` between two preorders is antitone if `a \u2264 b` implies `f b \u2264 f a`.\n* `MonotoneOn f s`: Same as `Monotone f`, but for all `a, b \u2208 s`.\n* `AntitoneoN f s`: Same as `Antitone f`, but for all `a, b \u2208 s`.\n* `StrictMono f` : A function `f` between two preorders is strictly monotone if `a < b` implies\n  `f a < f b`.\n* `StrictAnti f` : A function `f` between two preorders is strictly antitone if `a < b` implies\n  `f b < f a`.\n* `StrictMonoOn f s`: Same as `StrictMono f`, but for all `a, b \u2208 s`.\n* `StrictAntiOn f s`: Same as `StrictAnti f`, but for all `a, b \u2208 s`.\n\n## Main theorems\n\n* `monotone_nat_of_le_succ`, `monotone_int_of_le_succ`: If `f : \u2115 \u2192 \u03b1` or `f : \u2124 \u2192 \u03b1` and\n  `f n \u2264 f (n + 1)` for all `n`, then `f` is monotone.\n* `antitone_nat_of_succ_le`, `antitone_int_of_succ_le`: If `f : \u2115 \u2192 \u03b1` or `f : \u2124 \u2192 \u03b1` and\n  `f (n + 1) \u2264 f n` for all `n`, then `f` is antitone.\n* `strictMono_nat_of_lt_succ`, `strictMono_int_of_lt_succ`: If `f : \u2115 \u2192 \u03b1` or `f : \u2124 \u2192 \u03b1` and\n  `f n < f (n + 1)` for all `n`, then `f` is strictly monotone.\n* `strictAnti_nat_of_succ_lt`, `strictAnti_int_of_succ_lt`: If `f : \u2115 \u2192 \u03b1` or `f : \u2124 \u2192 \u03b1` and\n  `f (n + 1) < f n` for all `n`, then `f` is strictly antitone.\n\n## Implementation notes\n\nSome of these definitions used to only require `LE \u03b1` or `LT \u03b1`. The advantage of this is\nunclear and it led to slight elaboration issues. Now, everything requires `Preorder \u03b1` and seems to\nwork fine. Related Zulip discussion:\nhttps://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352.\n\n## TODO\n\nThe above theorems are also true in `\u2115+`, `Fin n`... To make that work, we need `SuccOrder \u03b1`\nand `SuccArchmidean \u03b1`.\n\n## Tags\n\nmonotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing,\ndecreasing, strictly decreasing\n-/\n\n\nopen Function OrderDual\n\nuniverse u v w\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type _} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nsection MonotoneDef\n\nvariable [Preorder \u03b1] [Preorder \u03b2]\n\n/-- A function `f` is monotone if `a \u2264 b` implies `f a \u2264 f b`. -/\ndef Monotone (f : \u03b1 \u2192 \u03b2) : Prop :=\n  \u2200 \u2983a b\u2984, a \u2264 b \u2192 f a \u2264 f b\n#align monotone Monotone\n\n/-- A function `f` is antitone if `a \u2264 b` implies `f b \u2264 f a`. -/\ndef Antitone (f : \u03b1 \u2192 \u03b2) : Prop :=\n  \u2200 \u2983a b\u2984, a \u2264 b \u2192 f b \u2264 f a\n#align antitone Antitone\n\n/-- A function `f` is monotone on `s` if, for all `a, b \u2208 s`, `a \u2264 b` implies `f a \u2264 f b`. -/\ndef MonotoneOn (f : \u03b1 \u2192 \u03b2) (s : Set \u03b1) : Prop :=\n  \u2200 \u2983a\u2984 (_ : a \u2208 s) \u2983b\u2984 (_ : b \u2208 s), a \u2264 b \u2192 f a \u2264 f b\n#align monotone_on MonotoneOn\n\n/-- A function `f` is antitone on `s` if, for all `a, b \u2208 s`, `a \u2264 b` implies `f b \u2264 f a`. -/\ndef AntitoneOn (f : \u03b1 \u2192 \u03b2) (s : Set \u03b1) : Prop :=\n  \u2200 \u2983a\u2984 (_ : a \u2208 s) \u2983b\u2984 (_ : b \u2208 s), a \u2264 b \u2192 f b \u2264 f a\n#align antitone_on AntitoneOn\n\n/-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/\ndef StrictMono (f : \u03b1 \u2192 \u03b2) : Prop :=\n  \u2200 \u2983a b\u2984, a < b \u2192 f a < f b\n#align strict_mono StrictMono\n\n/-- A function `f` is strictly antitone if `a < b` implies `f b < f a`. -/\ndef StrictAnti (f : \u03b1 \u2192 \u03b2) : Prop :=\n  \u2200 \u2983a b\u2984, a < b \u2192 f b < f a\n#align strict_anti StrictAnti\n\n/-- A function `f` is strictly monotone on `s` if, for all `a, b \u2208 s`, `a < b` implies\n`f a < f b`. -/\ndef StrictMonoOn (f : \u03b1 \u2192 \u03b2) (s : Set \u03b1) : Prop :=\n  \u2200 \u2983a\u2984 (_ : a \u2208 s) \u2983b\u2984 (_ : b \u2208 s), a < b \u2192 f a < f b\n#align strict_mono_on StrictMonoOn\n\n/-- A function `f` is strictly antitone on `s` if, for all `a, b \u2208 s`, `a < b` implies\n`f b < f a`. -/\ndef StrictAntiOn (f : \u03b1 \u2192 \u03b2) (s : Set \u03b1) : Prop :=\n  \u2200 \u2983a\u2984 (_ : a \u2208 s) \u2983b\u2984 (_ : b \u2208 s), a < b \u2192 f b < f a\n#align strict_anti_on StrictAntiOn\n\nend MonotoneDef\n\n/-! ### Monotonicity on the dual order\n\nStrictly, many of the `*On.dual` lemmas in this section should use `ofDual \u207b\u00b9' s` instead of `s`,\nbut right now this is not possible as `Set.preimage` is not defined yet, and importing it creates\nan import cycle.\n\nOften, you should not need the rewriting lemmas. Instead, you probably want to add `.dual`,\n`.dual_left` or `.dual_right` to your `Monotone`/`Antitone` hypothesis.\n-/\n\n\nsection OrderDual\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1}\n\n@[simp]\ntheorem monotone_comp_ofDual_iff : Monotone (f \u2218 ofDual) \u2194 Antitone f :=\n  forall_swap\n#align monotone_comp_of_dual_iff monotone_comp_ofDual_iff\n\n@[simp]\ntheorem antitone_comp_ofDual_iff : Antitone (f \u2218 ofDual) \u2194 Monotone f :=\n  forall_swap\n#align antitone_comp_of_dual_iff antitone_comp_ofDual_iff\n\n-- Porting note:\n-- Here (and below) without the type ascription, Lean is seeing through the\n-- defeq `\u03b2\u1d52\u1d48 = \u03b2` and picking up the wrong `Preorder` instance.\n-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/logic.2Eequiv.2Ebasic.20mathlib4.23631/near/311744939\n@[simp]\ntheorem monotone_toDual_comp_iff : Monotone (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) \u2194 Antitone f :=\n  Iff.rfl\n#align monotone_to_dual_comp_iff monotone_toDual_comp_iff\n\n@[simp]\ntheorem antitone_toDual_comp_iff : Antitone (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) \u2194 Monotone f :=\n  Iff.rfl\n#align antitone_to_dual_comp_iff antitone_toDual_comp_iff\n\n@[simp]\ntheorem monotoneOn_comp_ofDual_iff : MonotoneOn (f \u2218 ofDual) s \u2194 AntitoneOn f s :=\n  forall\u2082_swap\n#align monotone_on_comp_of_dual_iff monotoneOn_comp_ofDual_iff\n\n@[simp]\ntheorem antitoneOn_comp_ofDual_iff : AntitoneOn (f \u2218 ofDual) s \u2194 MonotoneOn f s :=\n  forall\u2082_swap\n#align antitone_on_comp_of_dual_iff antitoneOn_comp_ofDual_iff\n\n@[simp]\ntheorem monotoneOn_toDual_comp_iff : MonotoneOn (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) s \u2194 AntitoneOn f s :=\n  Iff.rfl\n#align monotone_on_to_dual_comp_iff monotoneOn_toDual_comp_iff\n\n@[simp]\ntheorem antitoneOn_toDual_comp_iff : AntitoneOn (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) s \u2194 MonotoneOn f s :=\n  Iff.rfl\n#align antitone_on_to_dual_comp_iff antitoneOn_toDual_comp_iff\n\n@[simp]\ntheorem strictMono_comp_ofDual_iff : StrictMono (f \u2218 ofDual) \u2194 StrictAnti f :=\n  forall_swap\n#align strict_mono_comp_of_dual_iff strictMono_comp_ofDual_iff\n\n@[simp]\ntheorem strictAnti_comp_ofDual_iff : StrictAnti (f \u2218 ofDual) \u2194 StrictMono f :=\n  forall_swap\n#align strict_anti_comp_of_dual_iff strictAnti_comp_ofDual_iff\n\n@[simp]\ntheorem strictMono_toDual_comp_iff : StrictMono (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) \u2194 StrictAnti f :=\n  Iff.rfl\n#align strict_mono_to_dual_comp_iff strictMono_toDual_comp_iff\n\n@[simp]\ntheorem strictAnti_toDual_comp_iff : StrictAnti (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) \u2194 StrictMono f :=\n  Iff.rfl\n#align strict_anti_to_dual_comp_iff strictAnti_toDual_comp_iff\n\n@[simp]\ntheorem strictMonoOn_comp_ofDual_iff : StrictMonoOn (f \u2218 ofDual) s \u2194 StrictAntiOn f s :=\n  forall\u2082_swap\n#align strict_mono_on_comp_of_dual_iff strictMonoOn_comp_ofDual_iff\n\n@[simp]\ntheorem strictAntiOn_comp_ofDual_iff : StrictAntiOn (f \u2218 ofDual) s \u2194 StrictMonoOn f s :=\n  forall\u2082_swap\n#align strict_anti_on_comp_of_dual_iff strictAntiOn_comp_ofDual_iff\n\n@[simp]\ntheorem strictMonoOn_toDual_comp_iff : StrictMonoOn (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) s \u2194 StrictAntiOn f s :=\n  Iff.rfl\n#align strict_mono_on_to_dual_comp_iff strictMonoOn_toDual_comp_iff\n\n@[simp]\ntheorem strictAntiOn_toDual_comp_iff : StrictAntiOn (toDual \u2218 f : \u03b1 \u2192 \u03b2\u1d52\u1d48) s \u2194 StrictMonoOn f s :=\n  Iff.rfl\n#align strict_anti_on_to_dual_comp_iff strictAntiOn_toDual_comp_iff\n\nprotected theorem Monotone.dual (hf : Monotone f) : Monotone (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) :=\n  swap hf\n#align monotone.dual Monotone.dual\n\nprotected theorem Antitone.dual (hf : Antitone f) : Antitone (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) :=\n  swap hf\n#align antitone.dual Antitone.dual\n\nprotected theorem MonotoneOn.dual (hf : MonotoneOn f s) :\n    MonotoneOn (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) s :=\n  swap\u2082 hf\n#align monotone_on.dual MonotoneOn.dual\n\nprotected theorem AntitoneOn.dual (hf : AntitoneOn f s) :\n    AntitoneOn (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) s :=\n  swap\u2082 hf\n#align antitone_on.dual AntitoneOn.dual\n\nprotected theorem StrictMono.dual (hf : StrictMono f) :\n    StrictMono (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) :=\n  swap hf\n#align strict_mono.dual StrictMono.dual\n\nprotected theorem StrictAnti.dual (hf : StrictAnti f) :\n    StrictAnti (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) :=\n  swap hf\n#align strict_anti.dual StrictAnti.dual\n\nprotected theorem StrictMonoOn.dual (hf : StrictMonoOn f s) :\n    StrictMonoOn (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) s :=\n  swap\u2082 hf\n#align strict_mono_on.dual StrictMonoOn.dual\n\nprotected theorem StrictAntiOn.dual (hf : StrictAntiOn f s) :\n    StrictAntiOn (toDual \u2218 f \u2218 ofDual : \u03b1\u1d52\u1d48 \u2192 \u03b2\u1d52\u1d48) s :=\n  swap\u2082 hf\n#align strict_anti_on.dual StrictAntiOn.dual\n\nalias antitone_comp_ofDual_iff \u2194 _ Monotone.dual_left\n#align monotone.dual_left Monotone.dual_left\n\nalias monotone_comp_ofDual_iff \u2194 _ Antitone.dual_left\n#align antitone.dual_left Antitone.dual_left\n\nalias antitone_toDual_comp_iff \u2194 _ Monotone.dual_right\n#align monotone.dual_right Monotone.dual_right\n\nalias monotone_toDual_comp_iff \u2194 _ Antitone.dual_right\n#align antitone.dual_right Antitone.dual_right\n\nalias antitoneOn_comp_ofDual_iff \u2194 _ MonotoneOn.dual_left\n#align monotone_on.dual_left MonotoneOn.dual_left\n\nalias monotoneOn_comp_ofDual_iff \u2194 _ AntitoneOn.dual_left\n#align antitone_on.dual_left AntitoneOn.dual_left\n\nalias antitoneOn_toDual_comp_iff \u2194 _ MonotoneOn.dual_right\n#align monotone_on.dual_right MonotoneOn.dual_right\n\nalias monotoneOn_toDual_comp_iff \u2194 _ AntitoneOn.dual_right\n#align antitone_on.dual_right AntitoneOn.dual_right\n\nalias strictAnti_comp_ofDual_iff \u2194 _ StrictMono.dual_left\n#align strict_mono.dual_left StrictMono.dual_left\n\nalias strictMono_comp_ofDual_iff \u2194 _ StrictAnti.dual_left\n#align strict_anti.dual_left StrictAnti.dual_left\n\nalias strictAnti_toDual_comp_iff \u2194 _ StrictMono.dual_right\n#align strict_mono.dual_right StrictMono.dual_right\n\nalias strictMono_toDual_comp_iff \u2194 _ StrictAnti.dual_right\n#align strict_anti.dual_right StrictAnti.dual_right\n\nalias strictAntiOn_comp_ofDual_iff \u2194 _ StrictMonoOn.dual_left\n#align strict_mono_on.dual_left StrictMonoOn.dual_left\n\nalias strictMonoOn_comp_ofDual_iff \u2194 _ StrictAntiOn.dual_left\n#align strict_anti_on.dual_left StrictAntiOn.dual_left\n\nalias strictAntiOn_toDual_comp_iff \u2194 _ StrictMonoOn.dual_right\n#align strict_mono_on.dual_right StrictMonoOn.dual_right\n\nalias strictMonoOn_toDual_comp_iff \u2194 _ StrictAntiOn.dual_right\n#align strict_anti_on.dual_right StrictAntiOn.dual_right\n\nend OrderDual\n\n/-! ### Monotonicity in function spaces -/\n\n\nsection Preorder\n\nvariable [Preorder \u03b1]\n\ntheorem Monotone.comp_le_comp_left\n    [Preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {g h : \u03b3 \u2192 \u03b2} (hf : Monotone f) (le_gh : g \u2264 h) :\n    LE.le.{max w u} (f \u2218 g) (f \u2218 h) :=\n  fun x \u21a6 hf (le_gh x)\n#align monotone.comp_le_comp_left Monotone.comp_le_comp_left\n\nvariable [Preorder \u03b3]\n\ntheorem monotone_lam {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} (hf : \u2200 b, Monotone fun a \u21a6 f a b) : Monotone f :=\n  fun _ _ h b \u21a6 hf b h\n#align monotone_lam monotone_lam\n\ntheorem monotone_app (f : \u03b2 \u2192 \u03b1 \u2192 \u03b3) (b : \u03b2) (hf : Monotone fun a b \u21a6 f b a) : Monotone (f b) :=\n  fun _ _ h \u21a6 hf h b\n#align monotone_app monotone_app\n\ntheorem antitone_lam {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} (hf : \u2200 b, Antitone fun a \u21a6 f a b) : Antitone f :=\n  fun _ _ h b \u21a6 hf b h\n#align antitone_lam antitone_lam\n\ntheorem antitone_app (f : \u03b2 \u2192 \u03b1 \u2192 \u03b3) (b : \u03b2) (hf : Antitone fun a b \u21a6 f b a) : Antitone (f b) :=\n  fun _ _ h \u21a6 hf h b\n#align antitone_app antitone_app\n\nend Preorder\n\ntheorem Function.monotone_eval {\u03b9 : Type u} {\u03b1 : \u03b9 \u2192 Type v} [\u2200 i, Preorder (\u03b1 i)] (i : \u03b9) :\n    Monotone (Function.eval i : (\u2200 i, \u03b1 i) \u2192 \u03b1 i) := fun _ _ H \u21a6 H i\n#align function.monotone_eval Function.monotone_eval\n\n/-! ### Monotonicity hierarchy -/\n\n\nsection Preorder\n\nvariable [Preorder \u03b1]\n\nsection Preorder\n\nvariable [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a b : \u03b1}\n\n/-!\nThese four lemmas are there to strip off the semi-implicit arguments `\u2983a b : \u03b1\u2984`. This is useful\nwhen you do not want to apply a `Monotone` assumption (i.e. your goal is `a \u2264 b \u2192 f a \u2264 f b`).\nHowever if you find yourself writing `hf.imp h`, then you should have written `hf h` instead.\n-/\n\n\ntheorem Monotone.imp (hf : Monotone f) (h : a \u2264 b) : f a \u2264 f b :=\n  hf h\n#align monotone.imp Monotone.imp\n\ntheorem Antitone.imp (hf : Antitone f) (h : a \u2264 b) : f b \u2264 f a :=\n  hf h\n#align antitone.imp Antitone.imp\n\ntheorem StrictMono.imp (hf : StrictMono f) (h : a < b) : f a < f b :=\n  hf h\n#align strict_mono.imp StrictMono.imp\n\ntheorem StrictAnti.imp (hf : StrictAnti f) (h : a < b) : f b < f a :=\n  hf h\n#align strict_anti.imp StrictAnti.imp\n\nprotected theorem Monotone.monotoneOn (hf : Monotone f) (s : Set \u03b1) : MonotoneOn f s :=\n  fun _ _ _ _ \u21a6 hf.imp\n#align monotone.monotone_on Monotone.monotoneOn\n\nprotected theorem Antitone.antitoneOn (hf : Antitone f) (s : Set \u03b1) : AntitoneOn f s :=\n  fun _ _ _ _ \u21a6 hf.imp\n#align antitone.antitone_on Antitone.antitoneOn\n\n@[simp] theorem monotoneOn_univ : MonotoneOn f Set.univ \u2194 Monotone f :=\n  \u27e8fun h _ _ \u21a6 h trivial trivial, fun h \u21a6 h.monotoneOn _\u27e9\n#align monotone_on_univ monotoneOn_univ\n\n@[simp] theorem antitoneOn_univ : AntitoneOn f Set.univ \u2194 Antitone f :=\n  \u27e8fun h _ _ \u21a6 h trivial trivial, fun h \u21a6 h.antitoneOn _\u27e9\n#align antitone_on_univ antitoneOn_univ\n\nprotected theorem StrictMono.strictMonoOn (hf : StrictMono f) (s : Set \u03b1) : StrictMonoOn f s :=\n  fun _ _ _ _ \u21a6 hf.imp\n#align strict_mono.strict_mono_on StrictMono.strictMonoOn\n\nprotected theorem StrictAnti.strictAntiOn (hf : StrictAnti f) (s : Set \u03b1) : StrictAntiOn f s :=\n  fun _ _ _ _ \u21a6 hf.imp\n#align strict_anti.strict_anti_on StrictAnti.strictAntiOn\n\n@[simp] theorem strictMonoOn_univ : StrictMonoOn f Set.univ \u2194 StrictMono f :=\n  \u27e8fun h _ _ \u21a6 h trivial trivial, fun h \u21a6 h.strictMonoOn _\u27e9\n#align strict_mono_on_univ strictMonoOn_univ\n\n@[simp] theorem strictAntiOn_univ : StrictAntiOn f Set.univ \u2194 StrictAnti f :=\n  \u27e8fun h _ _ \u21a6 h trivial trivial, fun h \u21a6 h.strictAntiOn _\u27e9\n#align strict_anti_on_univ strictAntiOn_univ\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b2] {f : \u03b1 \u2192 \u03b2}\n\ntheorem Monotone.strictMono_of_injective (h\u2081 : Monotone f) (h\u2082 : Injective f) : StrictMono f :=\n  fun _ _ h \u21a6 (h\u2081 h.le).lt_of_ne fun H \u21a6 h.ne <| h\u2082 H\n#align monotone.strict_mono_of_injective Monotone.strictMono_of_injective\n\ntheorem Antitone.strictAnti_of_injective (h\u2081 : Antitone f) (h\u2082 : Injective f) : StrictAnti f :=\n  fun _ _ h \u21a6 (h\u2081 h.le).lt_of_ne fun H \u21a6 h.ne <| h\u2082 H.symm\n#align antitone.strict_anti_of_injective Antitone.strictAnti_of_injective\n\nend PartialOrder\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1}\n\ntheorem monotone_iff_forall_lt : Monotone f \u2194 \u2200 \u2983a b\u2984, a < b \u2192 f a \u2264 f b :=\n  forall\u2082_congr fun _ _ \u21a6\n    \u27e8fun hf h \u21a6 hf h.le, fun hf h \u21a6 h.eq_or_lt.elim (fun H \u21a6 (congr_arg _ H).le) hf\u27e9\n#align monotone_iff_forall_lt monotone_iff_forall_lt\n\ntheorem antitone_iff_forall_lt : Antitone f \u2194 \u2200 \u2983a b\u2984, a < b \u2192 f b \u2264 f a :=\n  forall\u2082_congr fun _ _ \u21a6\n    \u27e8fun hf h \u21a6 hf h.le, fun hf h \u21a6 h.eq_or_lt.elim (fun H \u21a6 (congr_arg _ H).ge) hf\u27e9\n#align antitone_iff_forall_lt antitone_iff_forall_lt\n\ntheorem monotoneOn_iff_forall_lt :\n    MonotoneOn f s \u2194 \u2200 \u2983a\u2984 (_ : a \u2208 s) \u2983b\u2984 (_ : b \u2208 s), a < b \u2192 f a \u2264 f b :=\n  \u27e8fun hf _ ha _ hb h \u21a6 hf ha hb h.le,\n   fun hf _ ha _ hb h \u21a6 h.eq_or_lt.elim (fun H \u21a6 (congr_arg _ H).le) (hf ha hb)\u27e9\n#align monotone_on_iff_forall_lt monotoneOn_iff_forall_lt\n\ntheorem antitoneOn_iff_forall_lt :\n    AntitoneOn f s \u2194 \u2200 \u2983a\u2984 (_ : a \u2208 s) \u2983b\u2984 (_ : b \u2208 s), a < b \u2192 f b \u2264 f a :=\n  \u27e8fun hf _ ha _ hb h \u21a6 hf ha hb h.le,\n   fun hf _ ha _ hb h \u21a6 h.eq_or_lt.elim (fun H \u21a6 (congr_arg _ H).ge) (hf ha hb)\u27e9\n#align antitone_on_iff_forall_lt antitoneOn_iff_forall_lt\n\n-- `Preorder \u03b1` isn't strong enough: if the preorder on `\u03b1` is an equivalence relation,\n-- then `StrictMono f` is vacuously true.\nprotected theorem StrictMonoOn.monotoneOn (hf : StrictMonoOn f s) : MonotoneOn f s :=\n  monotoneOn_iff_forall_lt.2 fun _ ha _ hb h \u21a6 (hf ha hb h).le\n#align strict_mono_on.monotone_on StrictMonoOn.monotoneOn\n\nprotected theorem StrictAntiOn.antitoneOn (hf : StrictAntiOn f s) : AntitoneOn f s :=\n  antitoneOn_iff_forall_lt.2 fun _ ha _ hb h \u21a6 (hf ha hb h).le\n#align strict_anti_on.antitone_on StrictAntiOn.antitoneOn\n\nprotected theorem StrictMono.monotone (hf : StrictMono f) : Monotone f :=\n  monotone_iff_forall_lt.2 fun _ _ h \u21a6 (hf h).le\n#align strict_mono.monotone StrictMono.monotone\n\nprotected theorem StrictAnti.antitone (hf : StrictAnti f) : Antitone f :=\n  antitone_iff_forall_lt.2 fun _ _ h \u21a6 (hf h).le\n#align strict_anti.antitone StrictAnti.antitone\n\nend PartialOrder\n\n/-! ### Monotonicity from and to subsingletons -/\n\n\nnamespace Subsingleton\n\nvariable [Preorder \u03b1] [Preorder \u03b2]\n\nprotected \n\nprotected theorem antitone [Subsingleton \u03b1] (f : \u03b1 \u2192 \u03b2) : Antitone f :=\n  fun _ _ _ \u21a6 (congr_arg _ <| Subsingleton.elim _ _).le\n#align subsingleton.antitone Subsingleton.antitone\n\ntheorem monotone' [Subsingleton \u03b2] (f : \u03b1 \u2192 \u03b2) : Monotone f :=\n  fun _ _ _ \u21a6 (Subsingleton.elim _ _).le\n#align subsingleton.monotone' Subsingleton.monotone'\n\ntheorem antitone' [Subsingleton \u03b2] (f : \u03b1 \u2192 \u03b2) : Antitone f :=\n  fun _ _ _ \u21a6 (Subsingleton.elim _ _).le\n#align subsingleton.antitone' Subsingleton.antitone'\n\nprotected theorem strictMono [Subsingleton \u03b1] (f : \u03b1 \u2192 \u03b2) : StrictMono f :=\n  fun _ _ h \u21a6 (h.ne <| Subsingleton.elim _ _).elim\n#align subsingleton.strict_mono Subsingleton.strictMono\n\nprotected theorem strictAnti [Subsingleton \u03b1] (f : \u03b1 \u2192 \u03b2) : StrictAnti f :=\n  fun _ _ h \u21a6 (h.ne <| Subsingleton.elim _ _).elim\n#align subsingleton.strict_anti Subsingleton.strictAnti\n\nend Subsingleton\n\n/-! ### Miscellaneous monotonicity results -/\n\n\ntheorem monotone_id [Preorder \u03b1] : Monotone (id : \u03b1 \u2192 \u03b1) := fun _ _ \u21a6 id\n#align monotone_id monotone_id\n\ntheorem monotoneOn_id [Preorder \u03b1] {s : Set \u03b1} : MonotoneOn id s := fun _ _ _ _ \u21a6 id\n#align monotone_on_id monotoneOn_id\n\ntheorem strictMono_id [Preorder \u03b1] : StrictMono (id : \u03b1 \u2192 \u03b1) := fun _ _ \u21a6 id\n#align strict_mono_id strictMono_id\n\ntheorem strictMonoOn_id [Preorder \u03b1] {s : Set \u03b1} : StrictMonoOn id s := fun _ _ _ _ \u21a6 id\n#align strict_mono_on_id strictMonoOn_id\n\ntheorem monotone_const [Preorder \u03b1] [Preorder \u03b2] {c : \u03b2} : Monotone fun _ : \u03b1 \u21a6 c :=\n  fun _ _ _ \u21a6 le_rfl\n#align monotone_const monotone_const\n\ntheorem monotoneOn_const [Preorder \u03b1] [Preorder \u03b2] {c : \u03b2} {s : Set \u03b1} :\n    MonotoneOn (fun _ : \u03b1 \u21a6 c) s :=\n  fun _ _ _ _ _ \u21a6 le_rfl\n#align monotone_on_const monotoneOn_const\n\ntheorem antitone_const [Preorder \u03b1] [Preorder \u03b2] {c : \u03b2} : Antitone fun _ : \u03b1 \u21a6 c :=\n  fun _ _ _ \u21a6 le_refl c\n#align antitone_const antitone_const\n\ntheorem antitoneOn_const [Preorder \u03b1] [Preorder \u03b2] {c : \u03b2} {s : Set \u03b1} :\n    AntitoneOn (fun _ : \u03b1 \u21a6 c) s :=\n  fun _ _ _ _ _ \u21a6 le_rfl\n#align antitone_on_const antitoneOn_const\n\ntheorem strictMono_of_le_iff_le [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (h : \u2200 x y, x \u2264 y \u2194 f x \u2264 f y) : StrictMono f :=\n  fun _ _ \u21a6 (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1\n#align strict_mono_of_le_iff_le strictMono_of_le_iff_le\n\ntheorem strictAnti_of_le_iff_le [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (h : \u2200 x y, x \u2264 y \u2194 f y \u2264 f x) : StrictAnti f :=\n  fun _ _ \u21a6 (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1\n#align strict_anti_of_le_iff_le strictAnti_of_le_iff_le\n\n-- Porting note: mathlib3 proof uses `contrapose` tactic\ntheorem injective_of_lt_imp_ne [LinearOrder \u03b1] {f : \u03b1 \u2192 \u03b2} (h : \u2200 x y, x < y \u2192 f x \u2260 f y) :\n    Injective f := by\n  intro x y hf\n  rcases lt_trichotomy x y with (hxy | rfl | hxy)\n  \u00b7 exact absurd hf <| h _ _ hxy\n  \u00b7 rfl\n  \u00b7 exact absurd hf.symm <| h _ _ hxy\n#align injective_of_lt_imp_ne injective_of_lt_imp_ne\n\ntheorem injective_of_le_imp_le [PartialOrder \u03b1] [Preorder \u03b2] (f : \u03b1 \u2192 \u03b2)\n    (h : \u2200 {x y}, f x \u2264 f y \u2192 x \u2264 y) : Injective f :=\n  fun _ _ hxy \u21a6 (h hxy.le).antisymm (h hxy.ge)\n#align injective_of_le_imp_le injective_of_le_imp_le\n\nsection Preorder\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n\ntheorem StrictMono.isMax_of_apply (hf : StrictMono f) (ha : IsMax (f a)) : IsMax a :=\n  of_not_not fun h \u21a6\n    let \u27e8_, hb\u27e9 := not_isMax_iff.1 h\n    (hf hb).not_isMax ha\n#align strict_mono.is_max_of_apply StrictMono.isMax_of_apply\n\ntheorem StrictMono.isMin_of_apply (hf : StrictMono f) (ha : IsMin (f a)) : IsMin a :=\n  of_not_not fun h \u21a6\n    let \u27e8_, hb\u27e9 := not_isMin_iff.1 h\n    (hf hb).not_isMin ha\n#align strict_mono.is_min_of_apply StrictMono.isMin_of_apply\n\ntheorem StrictAnti.isMax_of_apply (hf : StrictAnti f) (ha : IsMin (f a)) : IsMax a :=\n  of_not_not fun h \u21a6\n    let \u27e8_, hb\u27e9 := not_isMax_iff.1 h\n    (hf hb).not_isMin ha\n#align strict_anti.is_max_of_apply StrictAnti.isMax_of_apply\n\ntheorem StrictAnti.isMin_of_apply (hf : StrictAnti f) (ha : IsMax (f a)) : IsMin a :=\n  of_not_not fun h \u21a6\n    let \u27e8_, hb\u27e9 := not_isMin_iff.1 h\n    (hf hb).not_isMax ha\n#align strict_anti.is_min_of_apply StrictAnti.isMin_of_apply\n\nprotected theorem StrictMono.ite' (hf : StrictMono f) (hg : StrictMono g) {p : \u03b1 \u2192 Prop}\n    [DecidablePred p]\n    (hp : \u2200 \u2983x y\u2984, x < y \u2192 p y \u2192 p x) (hfg : \u2200 \u2983x y\u2984, p x \u2192 \u00acp y \u2192 x < y \u2192 f x < g y) :\n    StrictMono fun x \u21a6 if p x then f x else g x := by\n  intro x y h\n  by_cases hy:p y\n  \u00b7 have hx : p x := hp h hy\n    simpa [hx, hy] using hf h\n  by_cases hx:p x\n  \u00b7 simpa [hx, hy] using hfg hx hy h\n  \u00b7 simpa [hx, hy] using hg h\n#align strict_mono.ite' StrictMono.ite'\n\nprotected theorem StrictMono.ite (hf : StrictMono f) (hg : StrictMono g) {p : \u03b1 \u2192 Prop}\n    [DecidablePred p] (hp : \u2200 \u2983x y\u2984, x < y \u2192 p y \u2192 p x) (hfg : \u2200 x, f x \u2264 g x) :\n    StrictMono fun x \u21a6 if p x then f x else g x :=\n  (hf.ite' hg hp) fun _ y _ _ h \u21a6 (hf h).trans_le (hfg y)\n#align strict_mono.ite StrictMono.ite\n\n-- Porting note: `Strict*.dual_right` dot notation is not working here for some reason\nprotected theorem StrictAnti.ite' (hf : StrictAnti f) (hg : StrictAnti g) {p : \u03b1 \u2192 Prop}\n    [DecidablePred p]\n    (hp : \u2200 \u2983x y\u2984, x < y \u2192 p y \u2192 p x) (hfg : \u2200 \u2983x y\u2984, p x \u2192 \u00acp y \u2192 x < y \u2192 g y < f x) :\n    StrictAnti fun x \u21a6 if p x then f x else g x :=\n  StrictMono.ite' (StrictAnti.dual_right hf) (StrictAnti.dual_right hg) hp hfg\n#align strict_anti.ite' StrictAnti.ite'\n\nprotected theorem StrictAnti.ite (hf : StrictAnti f) (hg : StrictAnti g) {p : \u03b1 \u2192 Prop}\n    [DecidablePred p] (hp : \u2200 \u2983x y\u2984, x < y \u2192 p y \u2192 p x) (hfg : \u2200 x, g x \u2264 f x) :\n    StrictAnti fun x \u21a6 if p x then f x else g x :=\n  (hf.ite' hg hp) fun _ y _ _ h \u21a6 (hfg y).trans_lt (hf h)\n#align strict_anti.ite StrictAnti.ite\n\nend Preorder\n\n/-! ### Monotonicity under composition -/\n\n\nsection Composition\n\nvariable [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1}\n\nprotected theorem Monotone.comp (hg : Monotone g) (hf : Monotone f) : Monotone (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align monotone.comp Monotone.comp\n\ntheorem Monotone.comp_antitone (hg : Monotone g) (hf : Antitone f) : Antitone (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align monotone.comp_antitone Monotone.comp_antitone\n\nprotected theorem Antitone.comp (hg : Antitone g) (hf : Antitone f) : Monotone (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align antitone.comp Antitone.comp\n\ntheorem Antitone.comp_monotone (hg : Antitone g) (hf : Monotone f) : Antitone (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align antitone.comp_monotone Antitone.comp_monotone\n\nprotected theorem Monotone.iterate {f : \u03b1 \u2192 \u03b1} (hf : Monotone f) (n : \u2115) : Monotone (f^[n]) :=\n  Nat.recOn n monotone_id fun _ h \u21a6 h.comp hf\n#align monotone.iterate Monotone.iterate\n\nprotected theorem Monotone.comp_monotoneOn (hg : Monotone g) (hf : MonotoneOn f s) :\n    MonotoneOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align monotone.comp_monotone_on Monotone.comp_monotoneOn\n\ntheorem Monotone.comp_antitoneOn (hg : Monotone g) (hf : AntitoneOn f s) : AntitoneOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align monotone.comp_antitone_on Monotone.comp_antitoneOn\n\nprotected theorem Antitone.comp_antitoneOn (hg : Antitone g) (hf : AntitoneOn f s) :\n    MonotoneOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align antitone.comp_antitone_on Antitone.comp_antitoneOn\n\ntheorem Antitone.comp_monotoneOn (hg : Antitone g) (hf : MonotoneOn f s) : AntitoneOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align antitone.comp_monotone_on Antitone.comp_monotoneOn\n\nprotected theorem StrictMono.comp (hg : StrictMono g) (hf : StrictMono f) : StrictMono (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align strict_mono.comp StrictMono.comp\n\ntheorem StrictMono.comp_strictAnti (hg : StrictMono g) (hf : StrictAnti f) : StrictAnti (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align strict_mono.comp_strict_anti StrictMono.comp_strictAnti\n\nprotected theorem StrictAnti.comp (hg : StrictAnti g) (hf : StrictAnti f) : StrictMono (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align strict_anti.comp StrictAnti.comp\n\ntheorem StrictAnti.comp_strictMono (hg : StrictAnti g) (hf : StrictMono f) : StrictAnti (g \u2218 f) :=\n  fun _ _ h \u21a6 hg (hf h)\n#align strict_anti.comp_strict_mono StrictAnti.comp_strictMono\n\nprotected theorem StrictMono.iterate {f : \u03b1 \u2192 \u03b1} (hf : StrictMono f) (n : \u2115) : StrictMono (f^[n]) :=\n  Nat.recOn n strictMono_id fun _ h \u21a6 h.comp hf\n#align strict_mono.iterate StrictMono.iterate\n\nprotected theorem StrictMono.comp_strictMonoOn (hg : StrictMono g) (hf : StrictMonoOn f s) :\n    StrictMonoOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align strict_mono.comp_strict_mono_on StrictMono.comp_strictMonoOn\n\ntheorem StrictMono.comp_strictAntiOn (hg : StrictMono g) (hf : StrictAntiOn f s) :\n    StrictAntiOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align strict_mono.comp_strict_anti_on StrictMono.comp_strictAntiOn\n\nprotected theorem StrictAnti.comp_strictAntiOn (hg : StrictAnti g) (hf : StrictAntiOn f s) :\n    StrictMonoOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align strict_anti.comp_strict_anti_on StrictAnti.comp_strictAntiOn\n\ntheorem StrictAnti.comp_strictMonoOn (hg : StrictAnti g) (hf : StrictMonoOn f s) :\n    StrictAntiOn (g \u2218 f) s :=\n  fun _ ha _ hb h \u21a6 hg (hf ha hb h)\n#align strict_anti.comp_strict_mono_on StrictAnti.comp_strictMonoOn\n\nend Composition\n\nnamespace List\n\nsection Fold\n\ntheorem foldl_monotone [Preorder \u03b1] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b1} (H : \u2200 b, Monotone fun a \u21a6 f a b)\n    (l : List \u03b2) : Monotone fun a \u21a6 l.foldl f a :=\n  List.recOn l (fun _ _ \u21a6 id) fun _ _ hl _ _ h \u21a6 hl (H _ h)\n#align list.foldl_monotone List.foldl_monotone\n\ntheorem foldr_monotone [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} (H : \u2200 a, Monotone (f a)) (l : List \u03b1) :\n    Monotone fun b \u21a6 l.foldr f b := fun _ _ h \u21a6 List.recOn l h fun i _ hl \u21a6 H i hl\n#align list.foldr_monotone List.foldr_monotone\n\ntheorem foldl_strictMono [Preorder \u03b1] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b1} (H : \u2200 b, StrictMono fun a \u21a6 f a b)\n    (l : List \u03b2) : StrictMono fun a \u21a6 l.foldl f a :=\n  List.recOn l (fun _ _ \u21a6 id) fun _ _ hl _ _ h \u21a6 hl (H _ h)\n#align list.foldl_strict_mono List.foldl_strictMono\n\ntheorem foldr_strictMono [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b2} (H : \u2200 a, StrictMono (f a)) (l : List \u03b1) :\n    StrictMono fun b \u21a6 l.foldr f b := fun _ _ h \u21a6 List.recOn l h fun i _ hl \u21a6 H i hl\n#align list.foldr_strict_mono List.foldr_strictMono\n\nend Fold\n\nend List\n\n/-! ### Monotonicity in linear orders  -/\n\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1]\n\nsection Preorder\n\nvariable [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1}\n\nopen Ordering\n\ntheorem Monotone.reflect_lt (hf : Monotone f) {a b : \u03b1} (h : f a < f b) : a < b :=\n  lt_of_not_ge fun h' \u21a6 h.not_le (hf h')\n#align monotone.reflect_lt Monotone.reflect_lt\n\ntheorem Antitone.reflect_lt (hf : Antitone f) {a b : \u03b1} (h : f a < f b) : b < a :=\n  lt_of_not_ge fun h' \u21a6 h.not_le (hf h')\n#align antitone.reflect_lt Antitone.reflect_lt\n\ntheorem MonotoneOn.reflect_lt (hf : MonotoneOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s)\n    (h : f a < f b) : a < b :=\n  lt_of_not_ge fun h' \u21a6 h.not_le <| hf hb ha h'\n#align monotone_on.reflect_lt MonotoneOn.reflect_lt\n\ntheorem AntitoneOn.reflect_lt (hf : AntitoneOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s)\n    (h : f a < f b) : b < a :=\n  lt_of_not_ge fun h' \u21a6 h.not_le <| hf ha hb h'\n#align antitone_on.reflect_lt AntitoneOn.reflect_lt\n\ntheorem StrictMonoOn.le_iff_le (hf : StrictMonoOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s)\n    : f a \u2264 f b \u2194 a \u2264 b :=\n  \u27e8fun h \u21a6 le_of_not_gt fun h' \u21a6 (hf hb ha h').not_le h, fun h \u21a6\n    h.lt_or_eq_dec.elim (fun h' \u21a6 (hf ha hb h').le) fun h' \u21a6 h' \u25b8 le_rfl\u27e9\n#align strict_mono_on.le_iff_le StrictMonoOn.le_iff_le\n\ntheorem StrictAntiOn.le_iff_le (hf : StrictAntiOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n    f a \u2264 f b \u2194 b \u2264 a :=\n  hf.dual_right.le_iff_le hb ha\n#align strict_anti_on.le_iff_le StrictAntiOn.le_iff_le\n\ntheorem StrictMonoOn.eq_iff_eq (hf : StrictMonoOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n    f a = f b \u2194 a = b :=\n  \u27e8fun h \u21a6 le_antisymm ((hf.le_iff_le ha hb).mp h.le) ((hf.le_iff_le hb ha).mp h.ge), by\n    rintro rfl\n    rfl\u27e9\n#align strict_mono_on.eq_iff_eq StrictMonoOn.eq_iff_eq\n\ntheorem StrictAntiOn.eq_iff_eq (hf : StrictAntiOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n    f a = f b \u2194 b = a :=\n  (hf.dual_right.eq_iff_eq ha hb).trans eq_comm\n#align strict_anti_on.eq_iff_eq StrictAntiOn.eq_iff_eq\n\ntheorem StrictMonoOn.lt_iff_lt (hf : StrictMonoOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n    f a < f b \u2194 a < b := by\n  rw [lt_iff_le_not_le, lt_iff_le_not_le, hf.le_iff_le ha hb, hf.le_iff_le hb ha]\n#align strict_mono_on.lt_iff_lt StrictMonoOn.lt_iff_lt\n\ntheorem StrictAntiOn.lt_iff_lt (hf : StrictAntiOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n    f a < f b \u2194 b < a :=\n  hf.dual_right.lt_iff_lt hb ha\n#align strict_anti_on.lt_iff_lt StrictAntiOn.lt_iff_lt\n\ntheorem StrictMono.le_iff_le (hf : StrictMono f) {a b : \u03b1} : f a \u2264 f b \u2194 a \u2264 b :=\n  (hf.strictMonoOn Set.univ).le_iff_le trivial trivial\n#align strict_mono.le_iff_le StrictMono.le_iff_le\n\ntheorem StrictAnti.le_iff_le (hf : StrictAnti f) {a b : \u03b1} : f a \u2264 f b \u2194 b \u2264 a :=\n  (hf.strictAntiOn Set.univ).le_iff_le trivial trivial\n#align strict_anti.le_iff_le StrictAnti.le_iff_le\n\ntheorem StrictMono.lt_iff_lt (hf : StrictMono f) {a b : \u03b1} : f a < f b \u2194 a < b :=\n  (hf.strictMonoOn Set.univ).lt_iff_lt trivial trivial\n#align strict_mono.lt_iff_lt StrictMono.lt_iff_lt\n\ntheorem StrictAnti.lt_iff_lt (hf : StrictAnti f) {a b : \u03b1} : f a < f b \u2194 b < a :=\n  (hf.strictAntiOn Set.univ).lt_iff_lt trivial trivial\n#align strict_anti.lt_iff_lt StrictAnti.lt_iff_lt\n\nprotected theorem StrictMonoOn.compares (hf : StrictMonoOn f s) {a b : \u03b1} (ha : a \u2208 s)\n    (hb : b \u2208 s) : \u2200 {o : Ordering}, o.Compares (f a) (f b) \u2194 o.Compares a b\n  | Ordering.lt => hf.lt_iff_lt ha hb\n  | Ordering.eq => \u27e8fun h \u21a6 ((hf.le_iff_le ha hb).1 h.le).antisymm\n                      ((hf.le_iff_le hb ha).1 h.symm.le), congr_arg _\u27e9\n  | Ordering.gt => hf.lt_iff_lt hb ha\n#align strict_mono_on.compares StrictMonoOn.compares\n\nprotected theorem StrictAntiOn.compares (hf : StrictAntiOn f s) {a b : \u03b1} (ha : a \u2208 s)\n    (hb : b \u2208 s) {o : Ordering} : o.Compares (f a) (f b) \u2194 o.Compares b a :=\n  toDual_compares_toDual.trans <| hf.dual_right.compares hb ha\n#align strict_anti_on.compares StrictAntiOn.compares\n\nprotected theorem StrictMono.compares (hf : StrictMono f) {a b : \u03b1} {o : Ordering} :\n    o.Compares (f a) (f b) \u2194 o.Compares a b :=\n  (hf.strictMonoOn Set.univ).compares trivial trivial\n#align strict_mono.compares StrictMono.compares\n\nprotected theorem StrictAnti.compares (hf : StrictAnti f) {a b : \u03b1} {o : Ordering} :\n    o.Compares (f a) (f b) \u2194 o.Compares b a :=\n  (hf.strictAntiOn Set.univ).compares trivial trivial\n#align strict_anti.compares StrictAnti.compares\n\ntheorem StrictMono.injective (hf : StrictMono f) : Injective f :=\n  fun x y h \u21a6 show Compares eq x y from hf.compares.1 h\n#align strict_mono.injective StrictMono.injective\n\ntheorem StrictAnti.injective (hf : StrictAnti f) : Injective f :=\n  fun x y h \u21a6 show Compares eq x y from hf.compares.1 h.symm\n#align strict_anti.injective StrictAnti.injective\n\ntheorem StrictMono.maximal_of_maximal_image (hf : StrictMono f) {a} (hmax : \u2200 p, p \u2264 f a) (x : \u03b1) :\n    x \u2264 a :=\n  hf.le_iff_le.mp (hmax (f x))\n#align strict_mono.maximal_of_maximal_image StrictMono.maximal_of_maximal_image\n\ntheorem StrictMono.minimal_of_minimal_image (hf : StrictMono f) {a} (hmin : \u2200 p, f a \u2264 p) (x : \u03b1) :\n    a \u2264 x :=\n  hf.le_iff_le.mp (hmin (f x))\n#align strict_mono.minimal_of_minimal_image StrictMono.minimal_of_minimal_image\n\ntheorem StrictAnti.minimal_of_maximal_image (hf : StrictAnti f) {a} (hmax : \u2200 p, p \u2264 f a) (x : \u03b1) :\n    a \u2264 x :=\n  hf.le_iff_le.mp (hmax (f x))\n#align strict_anti.minimal_of_maximal_image StrictAnti.minimal_of_maximal_image\n\ntheorem StrictAnti.maximal_of_minimal_image (hf : StrictAnti f) {a} (hmin : \u2200 p, f a \u2264 p) (x : \u03b1) :\n    x \u2264 a :=\n  hf.le_iff_le.mp (hmin (f x))\n#align strict_anti.maximal_of_minimal_image StrictAnti.maximal_of_minimal_image\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b2] {f : \u03b1 \u2192 \u03b2}\n\ntheorem Monotone.strictMono_iff_injective (hf : Monotone f) : StrictMono f \u2194 Injective f :=\n  \u27e8fun h \u21a6 h.injective, hf.strictMono_of_injective\u27e9\n#align monotone.strict_mono_iff_injective Monotone.strictMono_iff_injective\n\ntheorem Antitone.strictAnti_iff_injective (hf : Antitone f) : StrictAnti f \u2194 Injective f :=\n  \u27e8fun h \u21a6 h.injective, hf.strictAnti_of_injective\u27e9\n#align antitone.strict_anti_iff_injective Antitone.strictAnti_iff_injective\n\nend PartialOrder\n\nvariable [LinearOrder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1} {x y : \u03b1}\n\n/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or\ndownright. -/\nlemma not_monotone_not_antitone_iff_exists_le_le :\n  \u00ac Monotone f \u2227 \u00ac Antitone f \u2194 \u2203 a b c, a \u2264 b \u2227 b \u2264 c \u2227\n    (f a < f b \u2227 f c < f b \u2228 f b < f a \u2227 f b < f c) := by\n  simp_rw [Monotone, Antitone, not_forall, not_le]\n  refine' Iff.symm \u27e8_, _\u27e9\n  { rintro \u27e8a, b, c, hab, hbc, \u27e8hfab, hfcb\u27e9 | \u27e8hfba, hfbc\u27e9\u27e9\n    exacts [\u27e8\u27e8_, _, hbc, hfcb\u27e9, _, _, hab, hfab\u27e9, \u27e8\u27e8_, _, hab, hfba\u27e9, _, _, hbc, hfbc\u27e9] }\n  rintro \u27e8\u27e8a, b, hab, hfba\u27e9, c, d, hcd, hfcd\u27e9\n  obtain hda | had := le_total d a\n  { obtain hfad | hfda := le_total (f a) (f d)\n    { exact \u27e8c, d, b, hcd, hda.trans hab, Or.inl \u27e8hfcd, hfba.trans_le hfad\u27e9\u27e9 }\n    { exact \u27e8c, a, b, hcd.trans hda, hab, Or.inl \u27e8hfcd.trans_le hfda, hfba\u27e9\u27e9 } }\n  obtain hac | hca := le_total a c\n  { obtain hfdb | hfbd := le_or_lt (f d) (f b)\n    { exact \u27e8a, c, d, hac, hcd, Or.inr \u27e8hfcd.trans $ hfdb.trans_lt hfba, hfcd\u27e9\u27e9 }\n    obtain hfca | hfac := lt_or_le (f c) (f a)\n    { exact \u27e8a, c, d, hac, hcd, Or.inr \u27e8hfca, hfcd\u27e9\u27e9 }\n    obtain hbd | hdb := le_total b d\n    { exact \u27e8a, b, d, hab, hbd, Or.inr \u27e8hfba, hfbd\u27e9\u27e9 }\n    { exact \u27e8a, d, b, had, hdb, Or.inl \u27e8hfac.trans_lt hfcd, hfbd\u27e9\u27e9 } }\n  { obtain hfdb | hfbd := le_or_lt (f d) (f b)\n    { exact \u27e8c, a, b, hca, hab, Or.inl \u27e8hfcd.trans $ hfdb.trans_lt hfba, hfba\u27e9\u27e9 }\n    obtain hfca | hfac := lt_or_le (f c) (f a)\n    { exact \u27e8c, a, b, hca, hab, Or.inl \u27e8hfca, hfba\u27e9\u27e9 }\n    obtain hbd | hdb := le_total b d\n    { exact \u27e8a, b, d, hab, hbd, Or.inr \u27e8hfba, hfbd\u27e9\u27e9 }\n    { exact \u27e8a, d, b, had, hdb, Or.inl \u27e8hfac.trans_lt hfcd, hfbd\u27e9\u27e9 } }\n#align not_monotone_not_antitone_iff_exists_le_le not_monotone_not_antitone_iff_exists_le_le\n\n/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or\ndownright. -/\nlemma not_monotone_not_antitone_iff_exists_lt_lt :\n  \u00ac Monotone f \u2227 \u00ac Antitone f \u2194 \u2203 a b c, a < b \u2227 b < c \u2227\n    (f a < f b \u2227 f c < f b \u2228 f b < f a \u2227 f b < f c) := by\n  simp_rw [not_monotone_not_antitone_iff_exists_le_le, \u2190and_assoc]\n  refine' exists\u2083_congr (fun a b c \u21a6 and_congr_left $\n    fun h \u21a6 (Ne.le_iff_lt _).and $ Ne.le_iff_lt _) <;>\n  (rintro rfl; simp at h)\n#align not_monotone_not_antitone_iff_exists_lt_lt not_monotone_not_antitone_iff_exists_lt_lt\n\n/-!\n### Strictly monotone functions and `cmp`\n-/\n\n\nvariable [LinearOrder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1} {x y : \u03b1}\n\ntheorem StrictMonoOn.cmp_map_eq (hf : StrictMonoOn f s) (hx : x \u2208 s) (hy : y \u2208 s) :\n    cmp (f x) (f y) = cmp x y :=\n  ((hf.compares hx hy).2 (cmp_compares x y)).cmp_eq\n#align strict_mono_on.cmp_map_eq StrictMonoOn.cmp_map_eq\n\ntheorem StrictMono.cmp_map_eq (hf : StrictMono f) (x y : \u03b1) : cmp (f x) (f y) = cmp x y :=\n  (hf.strictMonoOn Set.univ).cmp_map_eq trivial trivial\n#align strict_mono.cmp_map_eq StrictMono.cmp_map_eq\n\ntheorem StrictAntiOn.cmp_map_eq (hf : StrictAntiOn f s) (hx : x \u2208 s) (hy : y \u2208 s) :\n    cmp (f x) (f y) = cmp y x :=\n  hf.dual_right.cmp_map_eq hy hx\n#align strict_anti_on.cmp_map_eq StrictAntiOn.cmp_map_eq\n\ntheorem StrictAnti.cmp_map_eq (hf : StrictAnti f) (x y : \u03b1) : cmp (f x) (f y) = cmp y x :=\n  (hf.strictAntiOn Set.univ).cmp_map_eq trivial trivial\n#align strict_anti.cmp_map_eq StrictAnti.cmp_map_eq\n\nend LinearOrder\n\n/-! ### Monotonicity in `\u2115` and `\u2124` -/\n\n\nsection Preorder\n\nvariable [Preorder \u03b1]\n\ntheorem Nat.rel_of_forall_rel_succ_of_le_of_lt (r : \u03b2 \u2192 \u03b2 \u2192 Prop) [IsTrans \u03b2 r] {f : \u2115 \u2192 \u03b2} {a : \u2115}\n    (h : \u2200 n, a \u2264 n \u2192 r (f n) (f (n + 1))) \u2983b c : \u2115\u2984 (hab : a \u2264 b) (hbc : b < c) :\n    r (f b) (f c) := by\n  induction' hbc with k b_lt_k r_b_k\n  exacts[h _ hab, _root_.trans r_b_k (h _ (hab.trans_lt b_lt_k).le)]\n#align nat.rel_of_forall_rel_succ_of_le_of_lt Nat.rel_of_forall_rel_succ_of_le_of_lt\n\ntheorem Nat.rel_of_forall_rel_succ_of_le_of_le (r : \u03b2 \u2192 \u03b2 \u2192 Prop) [IsRefl \u03b2 r] [IsTrans \u03b2 r]\n    {f : \u2115 \u2192 \u03b2} {a : \u2115} (h : \u2200 n, a \u2264 n \u2192 r (f n) (f (n + 1)))\n    \u2983b c : \u2115\u2984 (hab : a \u2264 b) (hbc : b \u2264 c) : r (f b) (f c) :=\n  hbc.eq_or_lt.elim (fun h \u21a6 h \u25b8 refl _) (Nat.rel_of_forall_rel_succ_of_le_of_lt r h hab)\n#align nat.rel_of_forall_rel_succ_of_le_of_le Nat.rel_of_forall_rel_succ_of_le_of_le\n\ntheorem Nat.rel_of_forall_rel_succ_of_lt (r : \u03b2 \u2192 \u03b2 \u2192 Prop) [IsTrans \u03b2 r] {f : \u2115 \u2192 \u03b2}\n    (h : \u2200 n, r (f n) (f (n + 1))) \u2983a b : \u2115\u2984 (hab : a < b) : r (f a) (f b) :=\n  Nat.rel_of_forall_rel_succ_of_le_of_lt r (fun n _ \u21a6 h n) le_rfl hab\n#align nat.rel_of_forall_rel_succ_of_lt Nat.rel_of_forall_rel_succ_of_lt\n\ntheorem Nat.rel_of_forall_rel_succ_of_le (r : \u03b2 \u2192 \u03b2 \u2192 Prop) [IsRefl \u03b2 r] [IsTrans \u03b2 r] {f : \u2115 \u2192 \u03b2}\n    (h : \u2200 n, r (f n) (f (n + 1))) \u2983a b : \u2115\u2984 (hab : a \u2264 b) : r (f a) (f b) :=\n  Nat.rel_of_forall_rel_succ_of_le_of_le r (fun n _ \u21a6 h n) le_rfl hab\n#align nat.rel_of_forall_rel_succ_of_le Nat.rel_of_forall_rel_succ_of_le\n\ntheorem monotone_nat_of_le_succ {f : \u2115 \u2192 \u03b1} (hf : \u2200 n, f n \u2264 f (n + 1)) : Monotone f :=\n  Nat.rel_of_forall_rel_succ_of_le (\u00b7 \u2264 \u00b7) hf\n#align monotone_nat_of_le_succ monotone_nat_of_le_succ\n\ntheorem antitone_nat_of_succ_le {f : \u2115 \u2192 \u03b1} (hf : \u2200 n, f (n + 1) \u2264 f n) : Antitone f :=\n  @monotone_nat_of_le_succ \u03b1\u1d52\u1d48 _ _ hf\n#align antitone_nat_of_succ_le antitone_nat_of_succ_le\n\ntheorem strictMono_nat_of_lt_succ {f : \u2115 \u2192 \u03b1} (hf : \u2200 n, f n < f (n + 1)) : StrictMono f :=\n  Nat.rel_of_forall_rel_succ_of_lt (\u00b7 < \u00b7) hf\n#align strict_mono_nat_of_lt_succ strictMono_nat_of_lt_succ\n\ntheorem strictAnti_nat_of_succ_lt {f : \u2115 \u2192 \u03b1} (hf : \u2200 n, f (n + 1) < f n) : StrictAnti f :=\n  @strictMono_nat_of_lt_succ \u03b1\u1d52\u1d48 _ f hf\n#align strict_anti_nat_of_succ_lt strictAnti_nat_of_succ_lt\n\nnamespace Nat\n\n/-- If `\u03b1` is a preorder with no maximal elements, then there exists a strictly monotone function\n`\u2115 \u2192 \u03b1` with any prescribed value of `f 0`. -/\ntheorem exists_strictMono' [NoMaxOrder \u03b1] (a : \u03b1) : \u2203 f : \u2115 \u2192 \u03b1, StrictMono f \u2227 f 0 = a := by\n  choose g hg using fun x : \u03b1 \u21a6 exists_gt x\n  exact \u27e8fun n \u21a6 Nat.recOn n a fun _ \u21a6 g, strictMono_nat_of_lt_succ fun n \u21a6 hg _, rfl\u27e9\n#align nat.exists_strict_mono' Nat.exists_strictMono'\n\n/-- If `\u03b1` is a preorder with no maximal elements, then there exists a strictly antitone function\n`\u2115 \u2192 \u03b1` with any prescribed value of `f 0`. -/\ntheorem exists_strictAnti' [NoMinOrder \u03b1] (a : \u03b1) : \u2203 f : \u2115 \u2192 \u03b1, StrictAnti f \u2227 f 0 = a :=\n  exists_strictMono' (OrderDual.toDual a)\n#align nat.exists_strict_anti' Nat.exists_strictAnti'\n\nvariable (\u03b1)\n\n/-- If `\u03b1` is a nonempty preorder with no maximal elements, then there exists a strictly monotone\nfunction `\u2115 \u2192 \u03b1`. -/\ntheorem exists_strictMono [Nonempty \u03b1] [NoMaxOrder \u03b1] : \u2203 f : \u2115 \u2192 \u03b1, StrictMono f :=\n  let \u27e8a\u27e9 := \u2039Nonempty \u03b1\u203a\n  let \u27e8f, hf, _\u27e9 := exists_strictMono' a\n  \u27e8f, hf\u27e9\n#align nat.exists_strict_mono Nat.exists_strictMono\n\n/-- If `\u03b1` is a nonempty preorder with no minimal elements, then there exists a strictly antitone\nfunction `\u2115 \u2192 \u03b1`. -/\ntheorem exists_strictAnti [Nonempty \u03b1] [NoMinOrder \u03b1] : \u2203 f : \u2115 \u2192 \u03b1, StrictAnti f :=\n  exists_strictMono \u03b1\u1d52\u1d48\n#align nat.exists_strict_anti Nat.exists_strictAnti\n\nend Nat\n\ntheorem Int.rel_of_forall_rel_succ_of_lt (r : \u03b2 \u2192 \u03b2 \u2192 Prop) [IsTrans \u03b2 r] {f : \u2124 \u2192 \u03b2}\n    (h : \u2200 n, r (f n) (f (n + 1))) \u2983a b : \u2124\u2984 (hab : a < b) : r (f a) (f b) := by\n  rcases lt.dest hab with \u27e8n, rfl\u27e9\n  clear hab\n  induction' n with n ihn\n  \u00b7 rw [Int.ofNat_one]\n    apply h\n  \u00b7 rw [Int.ofNat_succ, \u2190 Int.add_assoc]\n    exact _root_.trans ihn (h _)\n#align int.rel_of_forall_rel_succ_of_lt Int.rel_of_forall_rel_succ_of_lt\n\ntheorem Int.rel_of_forall_rel_succ_of_le (r : \u03b2 \u2192 \u03b2 \u2192 Prop) [IsRefl \u03b2 r] [IsTrans \u03b2 r] {f : \u2124 \u2192 \u03b2}\n    (h : \u2200 n, r (f n) (f (n + 1))) \u2983a b : \u2124\u2984 (hab : a \u2264 b) : r (f a) (f b) :=\n  hab.eq_or_lt.elim (fun h \u21a6 h \u25b8 refl _) fun h' \u21a6 Int.rel_of_forall_rel_succ_of_lt r h h'\n#align int.rel_of_forall_rel_succ_of_le Int.rel_of_forall_rel_succ_of_le\n\ntheorem monotone_int_of_le_succ {f : \u2124 \u2192 \u03b1} (hf : \u2200 n, f n \u2264 f (n + 1)) : Monotone f :=\n  Int.rel_of_forall_rel_succ_of_le (\u00b7 \u2264 \u00b7) hf\n#align monotone_int_of_le_succ monotone_int_of_le_succ\n\ntheorem antitone_int_of_succ_le {f : \u2124 \u2192 \u03b1} (hf : \u2200 n, f (n + 1) \u2264 f n) : Antitone f :=\n  Int.rel_of_forall_rel_succ_of_le (\u00b7 \u2265 \u00b7) hf\n#align antitone_int_of_succ_le antitone_int_of_succ_le\n\ntheorem strictMono_int_of_lt_succ {f : \u2124 \u2192 \u03b1} (hf : \u2200 n, f n < f (n + 1)) : StrictMono f :=\n  Int.rel_of_forall_rel_succ_of_lt (\u00b7 < \u00b7) hf\n#align strict_mono_int_of_lt_succ strictMono_int_of_lt_succ\n\ntheorem strictAnti_int_of_succ_lt {f : \u2124 \u2192 \u03b1} (hf : \u2200 n, f (n + 1) < f n) : StrictAnti f :=\n  Int.rel_of_forall_rel_succ_of_lt (\u00b7 > \u00b7) hf\n#align strict_anti_int_of_succ_lt strictAnti_int_of_succ_lt\n\nnamespace Int\n\nvariable (\u03b1) [Preorder \u03b1] [Nonempty \u03b1] [NoMinOrder \u03b1] [NoMaxOrder \u03b1]\n\n/-- If `\u03b1` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly\nmonotone function `f : \u2124 \u2192 \u03b1`. -/\ntheorem exists_strictMono : \u2203 f : \u2124 \u2192 \u03b1, StrictMono f := by\n  inhabit \u03b1\n  rcases Nat.exists_strictMono' (default : \u03b1) with \u27e8f, hf, hf\u2080\u27e9\n  rcases Nat.exists_strictAnti' (default : \u03b1) with \u27e8g, hg, hg\u2080\u27e9\n  refine' \u27e8fun n \u21a6 Int.casesOn n f fun n \u21a6 g (n + 1), strictMono_int_of_lt_succ _\u27e9\n  rintro (n | _ | n)\n  \u00b7 exact hf n.lt_succ_self\n  \u00b7 show g 1 < f 0\n    rw [hf\u2080, \u2190 hg\u2080]\n    exact hg Nat.zero_lt_one\n  \u00b7 exact hg (Nat.lt_succ_self _)\n\n#align int.exists_strict_mono Int.exists_strictMono\n\n/-- If `\u03b1` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly\nantitone function `f : \u2124 \u2192 \u03b1`. -/\ntheorem exists_strictAnti : \u2203 f : \u2124 \u2192 \u03b1, StrictAnti f :=\n  exists_strictMono \u03b1\u1d52\u1d48\n#align int.exists_strict_anti Int.exists_strictAnti\n\nend Int\n\n-- TODO@Yael: Generalize the following four to succ orders\n/-- If `f` is a monotone function from `\u2115` to a preorder such that `x` lies between `f n` and\n  `f (n + 1)`, then `x` doesn't lie in the range of `f`. -/\ntheorem Monotone.ne_of_lt_of_lt_nat {f : \u2115 \u2192 \u03b1} (hf : Monotone f) (n : \u2115) {x : \u03b1} (h1 : f n < x)\n    (h2 : x < f (n + 1)) (a : \u2115) : f a \u2260 x := by\n  rintro rfl\n  exact (hf.reflect_lt h1).not_le (Nat.le_of_lt_succ <| hf.reflect_lt h2)\n#align monotone.ne_of_lt_of_lt_nat Monotone.ne_of_lt_of_lt_nat\n\n/-- If `f` is an antitone function from `\u2115` to a preorder such that `x` lies between `f (n + 1)` and\n`f n`, then `x` doesn't lie in the range of `f`. -/\ntheorem Antitone.ne_of_lt_of_lt_nat {f : \u2115 \u2192 \u03b1} (hf : Antitone f) (n : \u2115) {x : \u03b1}\n    (h1 : f (n + 1) < x) (h2 : x < f n) (a : \u2115) : f a \u2260 x := by\n  rintro rfl\n  exact (hf.reflect_lt h2).not_le (Nat.le_of_lt_succ <| hf.reflect_lt h1)\n#align antitone.ne_of_lt_of_lt_nat Antitone.ne_of_lt_of_lt_nat\n\n/-- If `f` is a monotone function from `\u2124` to a preorder and `x` lies between `f n` and\n  `f (n + 1)`, then `x` doesn't lie in the range of `f`. -/\ntheorem Monotone.ne_of_lt_of_lt_int {f : \u2124 \u2192 \u03b1} (hf : Monotone f) (n : \u2124) {x : \u03b1} (h1 : f n < x)\n    (h2 : x < f (n + 1)) (a : \u2124) : f a \u2260 x := by\n  rintro rfl\n  exact (hf.reflect_lt h1).not_le (Int.le_of_lt_add_one <| hf.reflect_lt h2)\n#align monotone.ne_of_lt_of_lt_int Monotone.ne_of_lt_of_lt_int\n\n/-- If `f` is an antitone function from `\u2124` to a preorder and `x` lies between `f (n + 1)` and\n`f n`, then `x` doesn't lie in the range of `f`. -/\ntheorem Antitone.ne_of_lt_of_lt_int {f : \u2124 \u2192 \u03b1} (hf : Antitone f) (n : \u2124) {x : \u03b1}\n    (h1 : f (n + 1) < x) (h2 : x < f n) (a : \u2124) : f a \u2260 x := by\n  rintro rfl\n  exact (hf.reflect_lt h2).not_le (Int.le_of_lt_add_one <| hf.reflect_lt h1)\n#align antitone.ne_of_lt_of_lt_int Antitone.ne_of_lt_of_lt_int\n\ntheorem StrictMono.id_le {\u03c6 : \u2115 \u2192 \u2115} (h : StrictMono \u03c6) : \u2200 n, n \u2264 \u03c6 n := fun n \u21a6\n  Nat.recOn n (Nat.zero_le _) fun n hn \u21a6 Nat.succ_le_of_lt (hn.trans_lt <| h <| Nat.lt_succ_self n)\n#align strict_mono.id_le StrictMono.id_le\n\nend Preorder\n\ntheorem Subtype.mono_coe [Preorder \u03b1] (t : Set \u03b1) : Monotone ((\u2191) : Subtype t \u2192 \u03b1) :=\n  fun _ _ \u21a6 id\n#align subtype.mono_coe Subtype.mono_coe\n\ntheorem Subtype.strictMono_coe [Preorder \u03b1] (t : Set \u03b1) :\n    StrictMono ((\u2191) : Subtype t \u2192 \u03b1) :=\n  fun _ _ \u21a6 id\n#align subtype.strict_mono_coe Subtype.strictMono_coe\n\nsection Preorder\n\nvariable [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] [Preorder \u03b4] {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b4} {a b : \u03b1}\n\ntheorem monotone_fst : Monotone (@Prod.fst \u03b1 \u03b2) := fun _ _ \u21a6 And.left\n#align monotone_fst monotone_fst\n\ntheorem monotone_snd : Monotone (@Prod.snd \u03b1 \u03b2) := fun _ _ \u21a6 And.right\n#align monotone_snd monotone_snd\n\ntheorem Monotone.prod_map (hf : Monotone f) (hg : Monotone g) : Monotone (Prod.map f g) :=\n  fun _ _ h \u21a6 \u27e8hf h.1, hg h.2\u27e9\n#align monotone.prod_map Monotone.prod_map\n\ntheorem Antitone.prod_map (hf : Antitone f) (hg : Antitone g) : Antitone (Prod.map f g) :=\n  fun _ _ h \u21a6 \u27e8hf h.1, hg h.2\u27e9\n#align antitone.prod_map Antitone.prod_map\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b1] [PartialOrder \u03b2] [Preorder \u03b3] [Preorder \u03b4] {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b4}\n\ntheorem StrictMono.prod_map (hf : StrictMono f) (hg : StrictMono g) : StrictMono (Prod.map f g) :=\n  fun a b \u21a6 by\n  simp only [Prod.lt_iff]\n  exact Or.imp (And.imp hf.imp hg.monotone.imp) (And.imp hf.monotone.imp hg.imp)\n#align strict_mono.prod_map StrictMono.prod_map\n\ntheorem StrictAnti.prod_map (hf : StrictAnti f) (hg : StrictAnti g) : StrictAnti (Prod.map f g) :=\n  fun a b \u21a6 by\n  simp only [Prod.lt_iff]\n  exact Or.imp (And.imp hf.imp hg.antitone.imp) (And.imp hf.antitone.imp hg.imp)\n#align strict_anti.prod_map StrictAnti.prod_map\n\nend PartialOrder\n\nnamespace Function\n\nvariable [Preorder \u03b1]\n\ntheorem const_mono : Monotone (const \u03b2 : \u03b1 \u2192 \u03b2 \u2192 \u03b1) := fun _ _ h _ \u21a6 h\n#align function.const_mono Function.const_mono\n\ntheorem const_strictMono [Nonempty \u03b2] : StrictMono (const \u03b2 : \u03b1 \u2192 \u03b2 \u2192 \u03b1) :=\n  fun _ _ \u21a6 const_lt_const.2\n#align function.const_strict_mono Function.const_strictMono\n\nend Function\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/Monotone/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013355, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.711693734536091}}
{"text": "import tactic\n\nexample (n m k : \u2115) : n * (m - k) = n * m - n * k :=\nbegin\n  -- library_search,\n  exact nat.mul_sub_left_distrib n m k,\nend\n\n-- Al colocar el cursor sobre library_search escribe\n--    Try this: exact nat.mul_sub_left_distrib n m k\n\nexample (n m k : \u2115) : n * (m - k) = n * m - n * k :=\nbegin\n  exact nat.mul_sub_left_distrib n m k,\nend\n\n-- Ver la documentaci\u00f3n en https://bit.ly/3dEmh0l\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/La_tactica_libray_search.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7116220577418603}}
{"text": "/-\nCopyright (c) 2022 Wrenna Robson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Wrenna Robson\n\n! This file was ported from Lean 3 source module topology.metric_space.infsep\n! leanprover-community/mathlib commit 5316314b553dcf8c6716541851517c1a9715e22b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.MetricSpace.Basic\n\n/-!\n# Infimum separation\n\nThis file defines the extended infimum separation of a set. This is approximately dual to the\ndiameter of a set, but where the extended diameter of a set is the supremum of the extended distance\nbetween elements of the set, the extended infimum separation is the infimum of the (extended)\ndistance between *distinct* elements in the set.\n\nWe also define the infimum separation as the cast of the extended infimum separation to the reals.\nThis is the infimum of the distance between distinct elements of the set when in a pseudometric\nspace.\n\nAll lemmas and definitions are in the `set` namespace to give access to dot notation.\n\n## Main definitions\n* `Set.einfsep`: Extended infimum separation of a set.\n* `Set.infsep`: Infimum separation of a set (when in a pseudometric space).\n\n!-/\n\n\nvariable {\u03b1 \u03b2 : Type _}\n\nnamespace Set\n\nsection Einfsep\n\nopen ENNReal\n\nopen Function\n\n/-- The \"extended infimum separation\" of a set with an edist function. -/\nnoncomputable def einfsep [EDist \u03b1] (s : Set \u03b1) : \u211d\u22650\u221e :=\n  \u2a05 (x \u2208 s) (y \u2208 s) (_hxy : x \u2260 y), edist x y\n#align set.einfsep Set.einfsep\n\nsection EDist\n\nvariable [EDist \u03b1] {x y : \u03b1} {s t : Set \u03b1}\n\ntheorem le_einfsep_iff {d} :\n    d \u2264 s.einfsep \u2194 \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), d \u2264 edist x y := by\n  simp_rw [einfsep, le_inf\u1d62_iff]\n#align set.le_einfsep_iff Set.le_einfsep_iff\n\ntheorem einfsep_zero :\n    s.einfsep = 0 \u2194\n      \u2200 (C) (_hC : 0 < C), \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), edist x y < C :=\n  by simp_rw [einfsep, \u2190 _root_.bot_eq_zero, inf\u1d62_eq_bot, inf\u1d62_lt_iff]\n#align set.einfsep_zero Set.einfsep_zero\n\ntheorem einfsep_pos :\n    0 < s.einfsep \u2194\n      \u2203 (C : _)(_hC : 0 < C), \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), C \u2264 edist x y := by\n  rw [pos_iff_ne_zero, Ne.def, einfsep_zero]\n  simp only [not_forall, not_exists, not_lt]\n#align set.einfsep_pos Set.einfsep_pos\n\ntheorem einfsep_top :\n    s.einfsep = \u221e \u2194 \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), edist x y = \u221e := by\n  simp_rw [einfsep, inf\u1d62_eq_top]\n#align set.einfsep_top Set.einfsep_top\n\ntheorem einfsep_lt_top :\n    s.einfsep < \u221e \u2194 \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), edist x y < \u221e := by\n  simp_rw [einfsep, inf\u1d62_lt_iff]\n#align set.einfsep_lt_top Set.einfsep_lt_top\n\ntheorem einfsep_ne_top :\n    s.einfsep \u2260 \u221e \u2194 \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), edist x y \u2260 \u221e := by\n  simp_rw [\u2190 lt_top_iff_ne_top, einfsep_lt_top]\n#align set.einfsep_ne_top Set.einfsep_ne_top\n\ntheorem einfsep_lt_iff {d} :\n    s.einfsep < d \u2194 \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_h : x \u2260 y), edist x y < d := by\n  simp_rw [einfsep, inf\u1d62_lt_iff]\n#align set.einfsep_lt_iff Set.einfsep_lt_iff\n\ntheorem nontrivial_of_einfsep_lt_top (hs : s.einfsep < \u221e) : s.Nontrivial := by\n  rcases einfsep_lt_top.1 hs with \u27e8_, hx, _, hy, hxy, _\u27e9\n  exact \u27e8_, hx, _, hy, hxy\u27e9\n#align set.nontrivial_of_einfsep_lt_top Set.nontrivial_of_einfsep_lt_top\n\ntheorem nontrivial_of_einfsep_ne_top (hs : s.einfsep \u2260 \u221e) : s.Nontrivial :=\n  nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs)\n#align set.nontrivial_of_einfsep_ne_top Set.nontrivial_of_einfsep_ne_top\n\ntheorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = \u221e := by\n  rw [einfsep_top]\n  exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim\n#align set.subsingleton.einfsep Set.Subsingleton.einfsep\n\ntheorem le_einfsep_image_iff {d} {f : \u03b2 \u2192 \u03b1} {s : Set \u03b2} :\n    d \u2264 einfsep (f '' s) \u2194 \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s), f x \u2260 f y \u2192 d \u2264 edist (f x) (f y) :=\n  by simp_rw [le_einfsep_iff, ball_image_iff]\n#align set.le_einfsep_image_iff Set.le_einfsep_image_iff\n\ntheorem le_edist_of_le_einfsep {d x} (hx : x \u2208 s) {y} (hy : y \u2208 s) (hxy : x \u2260 y)\n    (hd : d \u2264 s.einfsep) : d \u2264 edist x y :=\n  le_einfsep_iff.1 hd x hx y hy hxy\n#align set.le_edist_of_le_einfsep Set.le_edist_of_le_einfsep\n\ntheorem einfsep_le_edist_of_mem {x} (hx : x \u2208 s) {y} (hy : y \u2208 s) (hxy : x \u2260 y) :\n    s.einfsep \u2264 edist x y :=\n  le_edist_of_le_einfsep hx hy hxy le_rfl\n#align set.einfsep_le_edist_of_mem Set.einfsep_le_edist_of_mem\n\ntheorem einfsep_le_of_mem_of_edist_le {d x} (hx : x \u2208 s) {y} (hy : y \u2208 s) (hxy : x \u2260 y)\n    (hxy' : edist x y \u2264 d) : s.einfsep \u2264 d :=\n  le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy'\n#align set.einfsep_le_of_mem_of_edist_le Set.einfsep_le_of_mem_of_edist_le\n\ntheorem le_einfsep {d} (h : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), d \u2264 edist x y) :\n    d \u2264 s.einfsep :=\n  le_einfsep_iff.2 h\n#align set.le_einfsep Set.le_einfsep\n\n@[simp]\ntheorem einfsep_empty : (\u2205 : Set \u03b1).einfsep = \u221e :=\n  subsingleton_empty.einfsep\n#align set.einfsep_empty Set.einfsep_empty\n\n@[simp]\ntheorem einfsep_singleton : ({x} : Set \u03b1).einfsep = \u221e :=\n  subsingleton_singleton.einfsep\n#align set.einfsep_singleton Set.einfsep_singleton\n\ntheorem einfsep_union\u1d62_mem_option {\u03b9 : Type _} (o : Option \u03b9) (s : \u03b9 \u2192 Set \u03b1) :\n    (\u22c3 i \u2208 o, s i).einfsep = \u2a05 i \u2208 o, (s i).einfsep := by cases o <;> simp\n#align set.einfsep_Union_mem_option Set.einfsep_union\u1d62_mem_option\n\ntheorem einfsep_anti (hst : s \u2286 t) : t.einfsep \u2264 s.einfsep :=\n  le_einfsep fun _x hx _y hy => einfsep_le_edist_of_mem (hst hx) (hst hy)\n#align set.einfsep_anti Set.einfsep_anti\n\ntheorem einfsep_insert_le : (insert x s).einfsep \u2264 \u2a05 (y \u2208 s) (_hxy : x \u2260 y), edist x y := by\n  simp_rw [le_inf\u1d62_iff]\n  refine' fun _ hy hxy => einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy\n#align set.einfsep_insert_le Set.einfsep_insert_le\n\ntheorem le_einfsep_pair : edist x y \u2293 edist y x \u2264 ({x, y} : Set \u03b1).einfsep := by\n  simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff]\n  rintro a (rfl | rfl) b (rfl | rfl) hab <;> simp only [le_refl, true_or, or_true] <;> contradiction\n#align set.le_einfsep_pair Set.le_einfsep_pair\n\ntheorem einfsep_pair_le_left (hxy : x \u2260 y) : ({x, y} : Set \u03b1).einfsep \u2264 edist x y :=\n  einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy\n#align set.einfsep_pair_le_left Set.einfsep_pair_le_left\n\ntheorem einfsep_pair_le_right (hxy : x \u2260 y) : ({x, y} : Set \u03b1).einfsep \u2264 edist y x := by\n  rw [pair_comm] ; exact einfsep_pair_le_left hxy.symm\n#align set.einfsep_pair_le_right Set.einfsep_pair_le_right\n\ntheorem einfsep_pair_eq_inf (hxy : x \u2260 y) : ({x, y} : Set \u03b1).einfsep = edist x y \u2293 edist y x :=\n  le_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair\n#align set.einfsep_pair_eq_inf Set.einfsep_pair_eq_inf\n\ntheorem einfsep_eq_inf\u1d62 : s.einfsep = \u2a05 d : s.offDiag, (uncurry edist) (d : \u03b1 \u00d7 \u03b1) := by\n  refine' eq_of_forall_le_iff fun _ => _\n  simp_rw [le_einfsep_iff, le_inf\u1d62_iff, imp_forall_iff, SetCoe.forall, Subtype.coe_mk, mem_offDiag,\n    Prod.forall, uncurry_apply_pair, and_imp]\n#align set.einfsep_eq_infi Set.einfsep_eq_inf\u1d62\n\n\n\ntheorem Finite.einfsep (hs : s.Finite) : s.einfsep = hs.offDiag.toFinset.inf (uncurry edist) := by\n  refine' eq_of_forall_le_iff fun _ => _\n  simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, Finite.mem_toFinset, mem_offDiag,\n    Prod.forall, uncurry_apply_pair, and_imp]\n#align set.finite.einfsep Set.Finite.einfsep\n\ntheorem Finset.coe_einfsep [DecidableEq \u03b1] {s : Finset \u03b1} :\n    (s : Set \u03b1).einfsep = s.offDiag.inf (uncurry edist) := by\n  simp_rw [einfsep_of_fintype, \u2190 Finset.coe_offDiag, Finset.toFinset_coe]\n#align set.finset.coe_einfsep Set.Finset.coe_einfsep\n\ntheorem Nontrivial.einfsep_exists_of_finite [Finite s] (hs : s.Nontrivial) :\n    \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), s.einfsep = edist x y := by\n  classical\n    cases nonempty_fintype s\n    simp_rw [einfsep_of_fintype]\n    rcases@Finset.exists_mem_eq_inf _ _ _ _ s.offDiag.toFinset (by simpa) (uncurry edist) with\n      \u27e8w, hxy, hed\u27e9\n    simp_rw [mem_toFinset] at hxy\n    refine' \u27e8w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed\u27e9\n#align set.nontrivial.einfsep_exists_of_finite Set.Nontrivial.einfsep_exists_of_finite\n\ntheorem Finite.einfsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) :\n    \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), s.einfsep = edist x y :=\n  letI := hsf.fintype\n  hs.einfsep_exists_of_finite\n#align set.finite.einfsep_exists_of_nontrivial Set.Finite.einfsep_exists_of_nontrivial\n\nend EDist\n\nsection PseudoEMetricSpace\n\nvariable [PseudoEMetricSpace \u03b1] {x y z : \u03b1} {s t : Set \u03b1}\n\ntheorem einfsep_pair (hxy : x \u2260 y) : ({x, y} : Set \u03b1).einfsep = edist x y := by\n  nth_rw 1 [\u2190 min_self (edist x y)]\n  convert einfsep_pair_eq_inf hxy using 2\n  rw [edist_comm]\n#align set.einfsep_pair Set.einfsep_pair\n\ntheorem einfsep_insert : einfsep (insert x s) = (\u2a05 (y \u2208 s) (_hxy : x \u2260 y), edist x y) \u2293 s.einfsep :=\n  by\n  refine' le_antisymm (le_min einfsep_insert_le (einfsep_anti (subset_insert _ _))) _\n  simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff]\n  rintro y (rfl | hy) z (rfl | hz) hyz\n  \u00b7 exact False.elim (hyz rfl)\n  \u00b7 exact Or.inl (inf\u1d62_le_of_le _ (inf\u1d62\u2082_le hz hyz))\n  \u00b7 rw [edist_comm]\n    exact Or.inl (inf\u1d62_le_of_le _ (inf\u1d62\u2082_le hy hyz.symm))\n  \u00b7 exact Or.inr (einfsep_le_edist_of_mem hy hz hyz)\n#align set.einfsep_insert Set.einfsep_insert\n\ntheorem einfsep_triple (hxy : x \u2260 y) (hyz : y \u2260 z) (hxz : x \u2260 z) :\n    einfsep ({x, y, z} : Set \u03b1) = edist x y \u2293 edist x z \u2293 edist y z := by\n  simp_rw [einfsep_insert, inf\u1d62_insert, inf\u1d62_singleton, einfsep_singleton, inf_top_eq,\n    cinf\u1d62_pos hxy, cinf\u1d62_pos hyz, cinf\u1d62_pos hxz]\n#align set.einfsep_triple Set.einfsep_triple\n\ntheorem le_einfsep_pi_of_le {\u03c0 : \u03b2 \u2192 Type _} [Fintype \u03b2] [\u2200 b, PseudoEMetricSpace (\u03c0 b)]\n    {s : \u2200 b : \u03b2, Set (\u03c0 b)} {c : \u211d\u22650\u221e} (h : \u2200 b, c \u2264 einfsep (s b)) :\n    c \u2264 einfsep (Set.pi univ s) := by\n  refine' le_einfsep fun x hx y hy hxy => _\n  rw [mem_univ_pi] at hx hy\n  rcases Function.ne_iff.mp hxy with \u27e8i, hi\u27e9\n  exact le_trans (le_einfsep_iff.1 (h i) _ (hx _) _ (hy _) hi) (edist_le_pi_edist _ _ i)\n#align set.le_einfsep_pi_of_le Set.le_einfsep_pi_of_le\n\nend PseudoEMetricSpace\n\nsection PseudoMetricSpace\n\nvariable [PseudoMetricSpace \u03b1] {s : Set \u03b1}\n\ntheorem subsingleton_of_einfsep_eq_top (hs : s.einfsep = \u221e) : s.Subsingleton := by\n  rw [einfsep_top] at hs\n  exact fun _ hx _ hy => of_not_not fun hxy => edist_ne_top _ _ (hs _ hx _ hy hxy)\n#align set.subsingleton_of_einfsep_eq_top Set.subsingleton_of_einfsep_eq_top\n\ntheorem einfsep_eq_top_iff : s.einfsep = \u221e \u2194 s.Subsingleton :=\n  \u27e8subsingleton_of_einfsep_eq_top, Subsingleton.einfsep\u27e9\n#align set.einfsep_eq_top_iff Set.einfsep_eq_top_iff\n\ntheorem Nontrivial.einfsep_ne_top (hs : s.Nontrivial) : s.einfsep \u2260 \u221e := by\n  contrapose! hs\n  rw [not_nontrivial_iff]\n  exact subsingleton_of_einfsep_eq_top hs\n#align set.nontrivial.einfsep_ne_top Set.Nontrivial.einfsep_ne_top\n\ntheorem Nontrivial.einfsep_lt_top (hs : s.Nontrivial) : s.einfsep < \u221e := by\n  rw [lt_top_iff_ne_top]\n  exact hs.einfsep_ne_top\n#align set.nontrivial.einfsep_lt_top Set.Nontrivial.einfsep_lt_top\n\ntheorem einfsep_lt_top_iff : s.einfsep < \u221e \u2194 s.Nontrivial :=\n  \u27e8nontrivial_of_einfsep_lt_top, Nontrivial.einfsep_lt_top\u27e9\n#align set.einfsep_lt_top_iff Set.einfsep_lt_top_iff\n\ntheorem einfsep_ne_top_iff : s.einfsep \u2260 \u221e \u2194 s.Nontrivial :=\n  \u27e8nontrivial_of_einfsep_ne_top, Nontrivial.einfsep_ne_top\u27e9\n#align set.einfsep_ne_top_iff Set.einfsep_ne_top_iff\n\ntheorem le_einfsep_of_forall_dist_le {d}\n    (h : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), d \u2264 dist x y) :\n    ENNReal.ofReal d \u2264 s.einfsep :=\n  le_einfsep fun x hx y hy hxy => (edist_dist x y).symm \u25b8 ENNReal.ofReal_le_ofReal (h x hx y hy hxy)\n#align set.le_einfsep_of_forall_dist_le Set.le_einfsep_of_forall_dist_le\n\nend PseudoMetricSpace\n\nsection EMetricSpace\n\nvariable [EMetricSpace \u03b1] {x y z : \u03b1} {s t : Set \u03b1} {C : \u211d\u22650\u221e} {sC : Set \u211d\u22650\u221e}\n\ntheorem einfsep_pos_of_finite [Finite s] : 0 < s.einfsep := by\n  cases nonempty_fintype s\n  by_cases hs : s.Nontrivial\n  \u00b7 rcases hs.einfsep_exists_of_finite with \u27e8x, _hx, y, _hy, hxy, hxy'\u27e9\n    exact hxy'.symm \u25b8 edist_pos.2 hxy\n  \u00b7 rw [not_nontrivial_iff] at hs\n    exact hs.einfsep.symm \u25b8 WithTop.zero_lt_top\n#align set.einfsep_pos_of_finite Set.einfsep_pos_of_finite\n\ntheorem relatively_discrete_of_finite [Finite s] :\n    \u2203 (C : _)(_hC : 0 < C), \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), C \u2264 edist x y := by\n  rw [\u2190 einfsep_pos]\n  exact einfsep_pos_of_finite\n#align set.relatively_discrete_of_finite Set.relatively_discrete_of_finite\n\ntheorem Finite.einfsep_pos (hs : s.Finite) : 0 < s.einfsep :=\n  letI := hs.fintype\n  einfsep_pos_of_finite\n#align set.finite.einfsep_pos Set.Finite.einfsep_pos\n\ntheorem Finite.relatively_discrete (hs : s.Finite) :\n    \u2203 (C : _)(_hC : 0 < C), \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), C \u2264 edist x y :=\n  letI := hs.fintype\n  relatively_discrete_of_finite\n#align set.finite.relatively_discrete Set.Finite.relatively_discrete\n\nend EMetricSpace\n\nend Einfsep\n\nsection Infsep\n\nopen ENNReal\n\nopen Set Function\n\n/-- The \"infimum separation\" of a set with an edist function. -/\nnoncomputable def infsep [EDist \u03b1] (s : Set \u03b1) : \u211d :=\n  ENNReal.toReal s.einfsep\n#align set.infsep Set.infsep\n\nsection EDist\n\nvariable [EDist \u03b1] {x y : \u03b1} {s : Set \u03b1}\n\ntheorem infsep_zero : s.infsep = 0 \u2194 s.einfsep = 0 \u2228 s.einfsep = \u221e := by\n  rw [infsep, ENNReal.toReal_eq_zero_iff]\n#align set.infsep_zero Set.infsep_zero\n\ntheorem infsep_nonneg : 0 \u2264 s.infsep :=\n  ENNReal.toReal_nonneg\n#align set.infsep_nonneg Set.infsep_nonneg\n\ntheorem infsep_pos : 0 < s.infsep \u2194 0 < s.einfsep \u2227 s.einfsep < \u221e := by\n  simp_rw [infsep, ENNReal.toReal_pos_iff]\n#align set.infsep_pos Set.infsep_pos\n\ntheorem Subsingleton.infsep_zero (hs : s.Subsingleton) : s.infsep = 0 := by\n  rw [infsep_zero.mpr]\n  right\n  exact hs.einfsep\n#align set.subsingleton.infsep_zero Set.Subsingleton.infsep_zero\n\ntheorem nontrivial_of_infsep_pos (hs : 0 < s.infsep) : s.Nontrivial := by\n  contrapose hs\n  rw [not_nontrivial_iff] at hs\n  exact hs.infsep_zero \u25b8 lt_irrefl _\n#align set.nontrivial_of_infsep_pos Set.nontrivial_of_infsep_pos\n\ntheorem infsep_empty : (\u2205 : Set \u03b1).infsep = 0 :=\n  subsingleton_empty.infsep_zero\n#align set.infsep_empty Set.infsep_empty\n\ntheorem infsep_singleton : ({x} : Set \u03b1).infsep = 0 :=\n  subsingleton_singleton.infsep_zero\n#align set.infsep_singleton Set.infsep_singleton\n\ntheorem infsep_pair_le_toReal_inf (hxy : x \u2260 y) :\n    ({x, y} : Set \u03b1).infsep \u2264 (edist x y \u2293 edist y x).toReal := by\n  simp_rw [infsep, einfsep_pair_eq_inf hxy]\n  simp\n#align set.infsep_pair_le_to_real_inf Set.infsep_pair_le_toReal_inf\n\nend EDist\n\nsection PseudoEMetricSpace\n\nvariable [PseudoEMetricSpace \u03b1] {x y : \u03b1} {s : Set \u03b1}\n\ntheorem infsep_pair_eq_toReal : ({x, y} : Set \u03b1).infsep = (edist x y).toReal := by\n  by_cases hxy : x = y\n  \u00b7 rw [hxy]\n    simp only [infsep_singleton, pair_eq_singleton, edist_self, ENNReal.zero_toReal]\n  \u00b7 rw [infsep, einfsep_pair hxy]\n#align set.infsep_pair_eq_to_real Set.infsep_pair_eq_toReal\n\nend PseudoEMetricSpace\n\nsection PseudoMetricSpace\n\nvariable [PseudoMetricSpace \u03b1] {x y z : \u03b1} {s t : Set \u03b1}\n\ntheorem Nontrivial.le_infsep_iff {d} (hs : s.Nontrivial) :\n    d \u2264 s.infsep \u2194 \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), d \u2264 dist x y := by\n  simp_rw [infsep, \u2190 ENNReal.ofReal_le_iff_le_toReal hs.einfsep_ne_top, le_einfsep_iff, edist_dist,\n    ENNReal.ofReal_le_ofReal_iff dist_nonneg]\n#align set.nontrivial.le_infsep_iff Set.Nontrivial.le_infsep_iff\n\ntheorem Nontrivial.infsep_lt_iff {d} (hs : s.Nontrivial) :\n    s.infsep < d \u2194 \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), dist x y < d := by\n  rw [\u2190 not_iff_not]\n  push_neg\n  exact hs.le_infsep_iff\n#align set.nontrivial.infsep_lt_iff Set.Nontrivial.infsep_lt_iff\n\ntheorem Nontrivial.le_infsep {d} (hs : s.Nontrivial)\n    (h : \u2200 (x) (_ : x \u2208 s) (y) (_ : y \u2208 s) (_hxy : x \u2260 y), d \u2264 dist x y) : d \u2264 s.infsep :=\n  hs.le_infsep_iff.2 h\n#align set.nontrivial.le_infsep Set.Nontrivial.le_infsep\n\ntheorem le_edist_of_le_infsep {d x} (hx : x \u2208 s) {y} (hy : y \u2208 s) (hxy : x \u2260 y)\n    (hd : d \u2264 s.infsep) : d \u2264 dist x y := by\n  by_cases hs : s.Nontrivial\n  \u00b7 exact hs.le_infsep_iff.1 hd x hx y hy hxy\n  \u00b7 rw [not_nontrivial_iff] at hs\n    rw [hs.infsep_zero] at hd\n    exact le_trans hd dist_nonneg\n#align set.le_edist_of_le_infsep Set.le_edist_of_le_infsep\n\ntheorem infsep_le_dist_of_mem (hx : x \u2208 s) (hy : y \u2208 s) (hxy : x \u2260 y) : s.infsep \u2264 dist x y :=\n  le_edist_of_le_infsep hx hy hxy le_rfl\n#align set.infsep_le_dist_of_mem Set.infsep_le_dist_of_mem\n\ntheorem infsep_le_of_mem_of_edist_le {d x} (hx : x \u2208 s) {y} (hy : y \u2208 s) (hxy : x \u2260 y)\n    (hxy' : dist x y \u2264 d) : s.infsep \u2264 d :=\n  le_trans (infsep_le_dist_of_mem hx hy hxy) hxy'\n#align set.infsep_le_of_mem_of_edist_le Set.infsep_le_of_mem_of_edist_le\n\ntheorem infsep_pair : ({x, y} : Set \u03b1).infsep = dist x y := by\n  rw [infsep_pair_eq_toReal, edist_dist]\n  exact ENNReal.toReal_ofReal dist_nonneg\n#align set.infsep_pair Set.infsep_pair\n\ntheorem infsep_triple (hxy : x \u2260 y) (hyz : y \u2260 z) (hxz : x \u2260 z) :\n    ({x, y, z} : Set \u03b1).infsep = dist x y \u2293 dist x z \u2293 dist y z := by\n  simp only [infsep, einfsep_triple hxy hyz hxz, ENNReal.toReal_inf, edist_ne_top x y,\n    edist_ne_top x z, edist_ne_top y z, dist_edist, Ne.def, inf_eq_top_iff, and_self_iff,\n    not_false_iff]\n#align set.infsep_triple Set.infsep_triple\n\ntheorem Nontrivial.infsep_anti (hs : s.Nontrivial) (hst : s \u2286 t) : t.infsep \u2264 s.infsep :=\n  ENNReal.toReal_mono hs.einfsep_ne_top (einfsep_anti hst)\n#align set.nontrivial.infsep_anti Set.Nontrivial.infsep_anti\n\ntheorem infsep_eq_inf\u1d62 [Decidable s.Nontrivial] :\n    s.infsep = if s.Nontrivial then \u2a05 d : s.offDiag, (uncurry dist) (d : \u03b1 \u00d7 \u03b1) else 0 := by\n  split_ifs with hs\n  \u00b7 have hb : BddBelow (uncurry dist '' s.offDiag) := by\n      refine' \u27e80, fun d h => _\u27e9\n      simp_rw [mem_image, Prod.exists, uncurry_apply_pair] at h\n      rcases h with \u27e8_, _, _, rfl\u27e9\n      exact dist_nonneg\n    refine' eq_of_forall_le_iff fun _ => _\n    simp_rw [hs.le_infsep_iff, le_cinf\u1d62_set_iff (offDiag_nonempty.mpr hs) hb, imp_forall_iff,\n      mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp]\n  \u00b7 exact (not_nontrivial_iff.mp hs).infsep_zero\n#align set.infsep_eq_infi Set.infsep_eq_inf\u1d62\n\ntheorem Nontrivial.infsep_eq_inf\u1d62 (hs : s.Nontrivial) :\n    s.infsep = \u2a05 d : s.offDiag, (uncurry dist) (d : \u03b1 \u00d7 \u03b1) := by\n  classical rw [Set.infsep_eq_inf\u1d62, if_pos hs]\n#align set.nontrivial.infsep_eq_infi Set.Nontrivial.infsep_eq_inf\u1d62\n\ntheorem infsep_of_fintype [Decidable s.Nontrivial] [DecidableEq \u03b1] [Fintype s] :\n    s.infsep = if hs : s.Nontrivial then s.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 :=\n  by\n  split_ifs with hs\n  \u00b7 refine' eq_of_forall_le_iff fun _ => _\n    simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, mem_toFinset, mem_offDiag,\n      Prod.forall, uncurry_apply_pair, and_imp]\n  \u00b7 rw [not_nontrivial_iff] at hs\n    exact hs.infsep_zero\n#align set.infsep_of_fintype Set.infsep_of_fintype\n\ntheorem Nontrivial.infsep_of_fintype [DecidableEq \u03b1] [Fintype s] (hs : s.Nontrivial) :\n    s.infsep = s.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by\n  classical rw [Set.infsep_of_fintype, dif_pos hs]\n#align set.nontrivial.infsep_of_fintype Set.Nontrivial.infsep_of_fintype\n\ntheorem Finite.infsep [Decidable s.Nontrivial] (hsf : s.Finite) :\n    s.infsep =\n      if hs : s.Nontrivial then hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 := by\n  split_ifs with hs\n  \u00b7 refine' eq_of_forall_le_iff fun _ => _\n    simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, Finite.mem_toFinset,\n      mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp]\n  \u00b7 rw [not_nontrivial_iff] at hs\n    exact hs.infsep_zero\n#align set.finite.infsep Set.Finite.infsep\n\ntheorem Finite.infsep_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) :\n    s.infsep = hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by\n  classical simp_rw [hsf.infsep, dif_pos hs]\n#align set.finite.infsep_of_nontrivial Set.Finite.infsep_of_nontrivial\n\ntheorem Finset.coe_infsep [DecidableEq \u03b1] (s : Finset \u03b1) :\n    (s : Set \u03b1).infsep = if hs : s.offDiag.Nonempty then s.offDiag.inf' hs (uncurry dist) else 0 :=\n  by\n  have H : (s : Set \u03b1).Nontrivial \u2194 s.offDiag.Nonempty := by\n    rw [\u2190 Set.offDiag_nonempty, \u2190 Finset.coe_offDiag, Finset.coe_nonempty]\n  split_ifs with hs\n  \u00b7 simp_rw [(H.mpr hs).infsep_of_fintype, \u2190 Finset.coe_offDiag, Finset.toFinset_coe]\n  \u00b7 exact (not_nontrivial_iff.mp (H.mp.mt hs)).infsep_zero\n#align finset.coe_infsep Set.Finset.coe_infsep\n\ntheorem Finset.coe_infsep_of_offDiag_nonempty [DecidableEq \u03b1] {s : Finset \u03b1}\n    (hs : s.offDiag.Nonempty) : (s : Set \u03b1).infsep = s.offDiag.inf' hs (uncurry dist) := by\n  rw [Finset.coe_infsep, dif_pos hs]\n#align finset.coe_infsep_of_off_diag_nonempty Set.Finset.coe_infsep_of_offDiag_nonempty\n\ntheorem Finset.coe_infsep_of_offDiag_empty [DecidableEq \u03b1] {s : Finset \u03b1} (hs : s.offDiag = \u2205) :\n    (s : Set \u03b1).infsep = 0 := by\n  rw [\u2190 Finset.not_nonempty_iff_eq_empty] at hs\n  rw [Finset.coe_infsep, dif_neg hs]\n#align finset.coe_infsep_of_off_diag_empty Set.Finset.coe_infsep_of_offDiag_empty\n\ntheorem Nontrivial.infsep_exists_of_finite [Finite s] (hs : s.Nontrivial) :\n    \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), s.infsep = dist x y := by\n  classical\n    cases nonempty_fintype s\n    simp_rw [hs.infsep_of_fintype]\n    rcases@Finset.exists_mem_eq_inf' _ _ _ s.offDiag.toFinset (by simpa) (uncurry dist) with\n      \u27e8w, hxy, hed\u27e9\n    simp_rw [mem_toFinset] at hxy\n    exact \u27e8w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed\u27e9\n#align set.nontrivial.infsep_exists_of_finite Set.Nontrivial.infsep_exists_of_finite\n\ntheorem Finite.infsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) :\n    \u2203 (x : _)(_ : x \u2208 s)(y : _)(_ : y \u2208 s)(_hxy : x \u2260 y), s.infsep = dist x y :=\n  letI := hsf.fintype\n  hs.infsep_exists_of_finite\n#align set.finite.infsep_exists_of_nontrivial Set.Finite.infsep_exists_of_nontrivial\n\nend PseudoMetricSpace\n\nsection MetricSpace\n\nvariable [MetricSpace \u03b1] {s : Set \u03b1}\n\ntheorem infsep_zero_iff_subsingleton_of_finite [Finite s] : s.infsep = 0 \u2194 s.Subsingleton := by\n  rw [infsep_zero, einfsep_eq_top_iff, or_iff_right_iff_imp]\n  exact fun H => (einfsep_pos_of_finite.ne' H).elim\n#align set.infsep_zero_iff_subsingleton_of_finite Set.infsep_zero_iff_subsingleton_of_finite\n\ntheorem infsep_pos_iff_nontrivial_of_finite [Finite s] : 0 < s.infsep \u2194 s.Nontrivial := by\n  rw [infsep_pos, einfsep_lt_top_iff, and_iff_right_iff_imp]\n  exact fun _ => einfsep_pos_of_finite\n#align set.infsep_pos_iff_nontrivial_of_finite Set.infsep_pos_iff_nontrivial_of_finite\n\ntheorem Finite.infsep_zero_iff_subsingleton (hs : s.Finite) : s.infsep = 0 \u2194 s.Subsingleton :=\n  letI := hs.fintype\n  infsep_zero_iff_subsingleton_of_finite\n#align set.finite.infsep_zero_iff_subsingleton Set.Finite.infsep_zero_iff_subsingleton\n\ntheorem Finite.infsep_pos_iff_nontrivial (hs : s.Finite) : 0 < s.infsep \u2194 s.Nontrivial :=\n  letI := hs.fintype\n  infsep_pos_iff_nontrivial_of_finite\n#align set.finite.infsep_pos_iff_nontrivial Set.Finite.infsep_pos_iff_nontrivial\n\ntheorem Finset.infsep_zero_iff_subsingleton (s : Finset \u03b1) :\n    (s : Set \u03b1).infsep = 0 \u2194 (s : Set \u03b1).Subsingleton :=\n  infsep_zero_iff_subsingleton_of_finite\n#align finset.infsep_zero_iff_subsingleton Set.Finset.infsep_zero_iff_subsingleton\n\ntheorem Finset.infsep_pos_iff_nontrivial (s : Finset \u03b1) :\n    0 < (s : Set \u03b1).infsep \u2194 (s : Set \u03b1).Nontrivial :=\n  infsep_pos_iff_nontrivial_of_finite\n#align finset.infsep_pos_iff_nontrivial Set.Finset.infsep_pos_iff_nontrivial\n\nend MetricSpace\n\nend Infsep\n\nend Set\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/MetricSpace/Infsep.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460027, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7116220574961188}}
{"text": "import analysis.analytic.basic\nimport hp.tactic.hp_interactive\nuniverse u\n\nnamespace examples\n\nlemma x_sub_x_union_y {\u03b1 : Type} {A B : set \u03b1} : A \u2286 A \u222a B :=\n\u03bb a h, or.inl h\n\nlemma y_sub_x_union_y {\u03b1 : Type} {A B : set \u03b1} : B \u2286 A \u222a B :=\n\u03bb a h, or.inr h\n\n\n\nclass met_space (X : Type) extends has_dist X :=\n(dist_self : \u2200 x, dist x x = 0)\n(dist_comm : \u2200 x y, dist x y = dist y x)\n(dist_triangle : \u2200 x y z, dist x z \u2264 dist x y + dist y z)\n\nattribute [classnoun \"metric space\"] met_space\n\nopen met_space\n\nvariables {X Y: Type} [met_space X] [met_space Y] {A B : set X}\n\ndef open_ball (\u03b5 : \u211d) (x : X) := {y | dist x y < \u03b5}\n\ndef is_open (A : set X) : Prop :=\n\u2200 (y : X), y \u2208 A \u2192 \u2203 (\u03b5 : \u211d), (\u03b5 > 0) \u2227 \u2200 (x : X), dist x y < \u03b5 \u2192 x \u2208 A\n\n@[relational_noun_predicate \"uniform limit\" \"uniform limits\" \"of\"]\ndef is_uniform_limit (f : \u2115 \u2192 X \u2192 Y) (g : X \u2192 Y) :=\n\u2200 (\u03b5 : \u211d), \u03b5 > 0 \u2192 \u2203 (N : \u2115), \u2200 (x : X), \u2200 (n : \u2115), (n \u2265 N) \u2192 dist (f n x) (g x) < \u03b5\n\n@[adjective \"continuous\"]\ndef continuous (f : X \u2192 Y) :=\n\u2200 (x : X), \u2200 (\u03b5 : \u211d), (\u03b5 > 0) \u2192 \u2203 (\u03b4 : \u211d), (\u03b4 > 0) \u2227 \u2200 (y : X), dist x y < \u03b4 \u2192 dist (f x) (f y) < \u03b5\n\n@[relational_noun \"sequence\" \"sequences\" \"of\"]\ndef sequence (X : Type) := \u2115 \u2192 X\n\nlemma dist_helper {\u03b5 \u03b7 \u03b8}\n  {x y z : X}\n  (h\u2081 : dist x y < \u03b7)\n  (h\u2082 : dist y z < \u03b8)\n  (h\u2083 : \u03b7 + \u03b8 \u2264 \u03b5)\n  : dist x z < \u03b5 :=\ncalc _ \u2264 dist x y + dist y z : dist_triangle _ _ _\n   ... < \u03b7 + \u03b8               : add_lt_add h\u2081 h\u2082\n   ... \u2264 \u03b5                   : h\u2083\n\nexample (f : sequence (X \u2192 Y)) (g : X \u2192 Y)\n  (h\u2081 : is_uniform_limit f g)\n  (h\u2082 : \u2200 n, continuous (f n)) : continuous g :=\nbegin\n  assume (x : X) (\u03b5 : \u211d) (\u03b5_pos : \u03b5 > 0),\n  have h\u2084 : \u03b5 / 3 > 0,\n    show \u03b5 / 3 > 0, apply div_pos \u03b5_pos,\n    show 0 < (3 : \u211d), norm_num,\n  obtain \u27e8N, h\u2085\u27e9 : \u2203 N, \u2200 (x : X) (n : \u2115), n \u2265 N \u2192 dist (f n x) (g x) < \u03b5 / 3,\n    apply h\u2081 (\u03b5 / 3) h\u2084,\n  obtain \u27e8\u03b4, \u03b4_pos, h\u2086\u27e9 : \u2203 \u03b4, \u03b4 > 0 \u2227 \u2200 y, dist x y < \u03b4 \u2192 dist (f N x) (f N y) < \u03b5 / 3,\n    apply h\u2082 N x (\u03b5 / 3) h\u2084,\n  existsi \u03b4,\n  existsi \u03b4_pos,\n  assume (y : X) (h\u2083 : dist x y < \u03b4),\n  show dist (g x) (g y) < \u03b5,\n  apply dist_helper,\n  calc dist (g x) (f N x) = dist (f N x) (g x) : by rw examples.met_space.dist_comm\n                      ... < \u03b5 / 3 : by apply h\u2085 x N (le_refl N),\n  show dist (f N x) (g y) < (\u03b5 / 3 + \u03b5 / 3),\n    apply dist_helper,\n  show dist (f N x) (f N y) < \u03b5 / 3,\n    apply h\u2086 y h\u2083,\n  show dist (f N y) (g y) < \u03b5 / 3,\n    apply h\u2085 y N (le_refl N),\n  show \u03b5 / 3 + \u03b5 / 3 \u2264 \u03b5 / 3 + \u03b5 / 3,\n    apply le_refl,\n  show \u03b5 / 3 + (\u03b5 / 3 + \u03b5 / 3) \u2264 \u03b5,\n    apply le_of_eq,\n    show \u03b5 / 3 + (\u03b5 / 3 + \u03b5 / 3) = \u03b5, by ring\nend\n\nexample {A B : set X} : is_open A \u2192 is_open B \u2192 is_open (A \u2229 B)\n| oa ob y \u27e8ha, hb\u27e9 :=\n  let \u27e8\u03b5a, h2a, h3a\u27e9 := oa y ha in\n  let \u27e8\u03b5b, h2b, h3b\u27e9 := ob y hb in\n  \u27e8 \u03b5a \u2293 \u03b5b\n  , lt_min h2a h2b\n  , \u03bb x dh,\n    \u27e8 h3a _ $ lt_of_lt_of_le dh $ min_le_left  _ _\n    , h3b _ $ lt_of_lt_of_le dh $ min_le_right _ _\n    \u27e9\n  \u27e9\n\n\n\n\nend examples", "meta": {"author": "EdAyers", "repo": "lean-humanproof-thesis", "sha": "ce8331df1883f286ab8cc7b61a328afdc006a059", "save_path": "github-repos/lean/EdAyers-lean-humanproof-thesis", "path": "github-repos/lean/EdAyers-lean-humanproof-thesis/lean-humanproof-thesis-ce8331df1883f286ab8cc7b61a328afdc006a059/src/examples/analysis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.7116220572503773}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Ya\u00ebl Dillies\n-/\nimport order.complete_lattice\nimport order.directed\nimport logic.equiv.set\n\n/-!\n# Frames, completely distributive lattices and Boolean algebras\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define and provide API for frames, completely distributive lattices and completely\ndistributive Boolean algebras.\n\n## Typeclasses\n\n* `order.frame`: Frame: A complete lattice whose `\u2293` distributes over `\u2a06`.\n* `order.coframe`: Coframe: A complete lattice whose `\u2294` distributes over `\u2a05`.\n* `complete_distrib_lattice`: Completely distributive lattices: A complete lattice whose `\u2293` and `\u2294`\n  distribute over `\u2a06` and `\u2a05` respectively.\n* `complete_boolean_algebra`: Completely distributive Boolean algebra: A Boolean algebra whose `\u2293`\n  and `\u2294` distribute over `\u2a06` and `\u2a05` respectively.\n\nA set of opens gives rise to a topological space precisely if it forms a frame. Such a frame is also\ncompletely distributive, but not all frames are. `filter` is a coframe but not a completely\ndistributive lattice.\n\n## TODO\n\nAdd instances for `prod`\n\n## References\n\n* [Wikipedia, *Complete Heyting algebra*](https://en.wikipedia.org/wiki/Complete_Heyting_algebra)\n* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]\n-/\n\nset_option old_structure_cmd true\n\nopen function set\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b9 : Sort w} {\u03ba : \u03b9 \u2192 Sort*}\n\n/-- A frame, aka complete Heyting algebra, is a complete lattice whose `\u2293` distributes over `\u2a06`. -/\nclass order.frame (\u03b1 : Type*) extends complete_lattice \u03b1 :=\n(inf_Sup_le_supr_inf (a : \u03b1) (s : set \u03b1) : a \u2293 Sup s \u2264 \u2a06 b \u2208 s, a \u2293 b)\n\n/-- A coframe, aka complete Brouwer algebra or complete co-Heyting algebra, is a complete lattice\nwhose `\u2294` distributes over `\u2a05`. -/\nclass order.coframe (\u03b1 : Type*) extends complete_lattice \u03b1 :=\n(infi_sup_le_sup_Inf (a : \u03b1) (s : set \u03b1) : (\u2a05 b \u2208 s, a \u2294 b) \u2264 a \u2294 Inf s)\n\nopen order\n\n/-- A completely distributive lattice is a complete lattice whose `\u2294` and `\u2293` respectively\ndistribute over `\u2a05` and `\u2a06`. -/\nclass complete_distrib_lattice (\u03b1 : Type*) extends frame \u03b1 :=\n(infi_sup_le_sup_Inf : \u2200 a s, (\u2a05 b \u2208 s, a \u2294 b) \u2264 a \u2294 Inf s)\n\n@[priority 100] -- See note [lower instance priority]\ninstance complete_distrib_lattice.to_coframe [complete_distrib_lattice \u03b1] : coframe \u03b1 :=\n{ .. \u2039complete_distrib_lattice \u03b1\u203a }\n\nsection frame\nvariables [frame \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\ninstance order_dual.coframe : coframe \u03b1\u1d52\u1d48 :=\n{ infi_sup_le_sup_Inf := frame.inf_Sup_le_supr_inf, ..order_dual.complete_lattice \u03b1 }\n\nlemma inf_Sup_eq : a \u2293 Sup s = \u2a06 b \u2208 s, a \u2293 b :=\n(frame.inf_Sup_le_supr_inf _ _).antisymm supr_inf_le_inf_Sup\n\nlemma Sup_inf_eq : Sup s \u2293 b = \u2a06 a \u2208 s, a \u2293 b :=\nby simpa only [inf_comm] using @inf_Sup_eq \u03b1 _ s b\n\nlemma supr_inf_eq (f : \u03b9 \u2192 \u03b1) (a : \u03b1) : (\u2a06 i, f i) \u2293 a = \u2a06 i, f i \u2293 a :=\nby rw [supr, Sup_inf_eq, supr_range]\n\nlemma inf_supr_eq (a : \u03b1) (f : \u03b9 \u2192 \u03b1) : a \u2293 (\u2a06 i, f i) = \u2a06 i, a \u2293 f i :=\nby simpa only [inf_comm] using supr_inf_eq f a\n\nlemma bsupr_inf_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : (\u2a06 i j, f i j) \u2293 a = \u2a06 i j, f i j \u2293 a :=\nby simp only [supr_inf_eq]\n\nlemma inf_bsupr_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : a \u2293 (\u2a06 i j, f i j) = \u2a06 i j, a \u2293 f i j :=\nby simp only [inf_supr_eq]\n\nlemma supr_inf_supr {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} :\n  (\u2a06 i, f i) \u2293 (\u2a06 j, g j) = \u2a06 i : \u03b9 \u00d7 \u03b9', f i.1 \u2293 g i.2 :=\nby simp only [inf_supr_eq, supr_inf_eq, supr_prod]\n\nlemma bsupr_inf_bsupr {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} {s : set \u03b9} {t : set \u03b9'} :\n  (\u2a06 i \u2208 s, f i) \u2293 (\u2a06 j \u2208 t, g j) = \u2a06 p \u2208 s \u00d7\u02e2 t, f (p : \u03b9 \u00d7 \u03b9').1 \u2293 g p.2 :=\nbegin\n  simp only [supr_subtype', supr_inf_supr],\n  exact (equiv.surjective _).supr_congr (equiv.set.prod s t).symm (\u03bb x, rfl)\nend\n\nlemma Sup_inf_Sup : Sup s \u2293 Sup t = \u2a06 p \u2208 s \u00d7\u02e2 t, (p : \u03b1 \u00d7 \u03b1).1 \u2293 p.2 :=\nby simp only [Sup_eq_supr, bsupr_inf_bsupr]\n\nlemma supr_disjoint_iff {f : \u03b9 \u2192 \u03b1} : disjoint (\u2a06 i, f i) a \u2194 \u2200 i, disjoint (f i) a :=\nby simp only [disjoint_iff, supr_inf_eq, supr_eq_bot]\n\nlemma disjoint_supr_iff {f : \u03b9 \u2192 \u03b1} : disjoint a (\u2a06 i, f i) \u2194 \u2200 i, disjoint a (f i) :=\nby simpa only [disjoint.comm] using supr_disjoint_iff\n\nlemma supr\u2082_disjoint_iff {f : \u03a0 i, \u03ba i \u2192 \u03b1} :\n  disjoint (\u2a06 i j, f i j) a \u2194 \u2200 i j, disjoint (f i j) a :=\nby simp_rw supr_disjoint_iff\n\nlemma disjoint_supr\u2082_iff {f : \u03a0 i, \u03ba i \u2192 \u03b1} :\n  disjoint a (\u2a06 i j, f i j) \u2194 \u2200 i j, disjoint a (f i j) :=\nby simp_rw disjoint_supr_iff\n\nlemma Sup_disjoint_iff {s : set \u03b1} : disjoint (Sup s) a \u2194 \u2200 b \u2208 s, disjoint b a :=\nby simp only [disjoint_iff, Sup_inf_eq, supr_eq_bot]\n\nlemma disjoint_Sup_iff {s : set \u03b1} : disjoint a (Sup s) \u2194 \u2200 b \u2208 s, disjoint a b :=\nby simpa only [disjoint.comm] using Sup_disjoint_iff\n\nlemma supr_inf_of_monotone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (\u2264)] {f g : \u03b9 \u2192 \u03b1}\n  (hf : monotone f) (hg : monotone g) :\n  (\u2a06 i, f i \u2293 g i) = (\u2a06 i, f i) \u2293 (\u2a06 i, g i) :=\nbegin\n  refine (le_supr_inf_supr f g).antisymm _,\n  rw [supr_inf_supr],\n  refine supr_mono' (\u03bb i, _),\n  rcases directed_of (\u2264) i.1 i.2 with \u27e8j, h\u2081, h\u2082\u27e9,\n  exact \u27e8j, inf_le_inf (hf h\u2081) (hg h\u2082)\u27e9\nend\n\nlemma supr_inf_of_antitone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (swap (\u2264))] {f g : \u03b9 \u2192 \u03b1}\n  (hf : antitone f) (hg : antitone g) :\n  (\u2a06 i, f i \u2293 g i) = (\u2a06 i, f i) \u2293 (\u2a06 i, g i) :=\n@supr_inf_of_monotone \u03b1 _ \u03b9\u1d52\u1d48 _ _ f g hf.dual_left hg.dual_left\n\ninstance pi.frame {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*} [\u03a0 i, frame (\u03c0 i)] : frame (\u03a0 i, \u03c0 i) :=\n{ inf_Sup_le_supr_inf := \u03bb a s i,\n    by simp only [complete_lattice.Sup, Sup_apply, supr_apply, pi.inf_apply, inf_supr_eq,\n      \u2190 supr_subtype''],\n  ..pi.complete_lattice }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance frame.to_distrib_lattice : distrib_lattice \u03b1 :=\ndistrib_lattice.of_inf_sup_le $ \u03bb a b c,\n  by rw [\u2190Sup_pair, \u2190Sup_pair, inf_Sup_eq, \u2190Sup_image, image_pair]\n\nend frame\n\nsection coframe\nvariables [coframe \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\ninstance order_dual.frame : frame \u03b1\u1d52\u1d48 :=\n{ inf_Sup_le_supr_inf := coframe.infi_sup_le_sup_Inf, ..order_dual.complete_lattice \u03b1 }\n\nlemma sup_Inf_eq : a \u2294 Inf s = \u2a05 b \u2208 s, a \u2294 b := @inf_Sup_eq \u03b1\u1d52\u1d48 _ _ _\nlemma Inf_sup_eq : Inf s \u2294 b = \u2a05 a \u2208 s, a \u2294 b := @Sup_inf_eq \u03b1\u1d52\u1d48 _ _ _\n\nlemma infi_sup_eq (f : \u03b9 \u2192 \u03b1) (a : \u03b1) : (\u2a05 i, f i) \u2294 a = \u2a05 i, f i \u2294 a := @supr_inf_eq \u03b1\u1d52\u1d48 _ _ _ _\nlemma sup_infi_eq (a : \u03b1) (f : \u03b9 \u2192 \u03b1) : a \u2294 (\u2a05 i, f i) = \u2a05 i, a \u2294 f i := @inf_supr_eq \u03b1\u1d52\u1d48 _ _ _ _\n\nlemma binfi_sup_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : (\u2a05 i j, f i j) \u2294 a = \u2a05 i j, f i j \u2294 a :=\n@bsupr_inf_eq \u03b1\u1d52\u1d48 _ _ _ _ _\n\nlemma sup_binfi_eq {f : \u03a0 i, \u03ba i \u2192 \u03b1} (a : \u03b1) : a \u2294 (\u2a05 i j, f i j) = \u2a05 i j, a \u2294 f i j :=\n@inf_bsupr_eq \u03b1\u1d52\u1d48 _ _ _ _ _\n\nlemma infi_sup_infi {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} :\n  (\u2a05 i, f i) \u2294 (\u2a05 i, g i) = \u2a05 i : \u03b9 \u00d7 \u03b9', f i.1 \u2294 g i.2 :=\n@supr_inf_supr \u03b1\u1d52\u1d48 _ _ _ _ _\n\nlemma binfi_sup_binfi {\u03b9 \u03b9' : Type*} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} {s : set \u03b9} {t : set \u03b9'} :\n  (\u2a05 i \u2208 s, f i) \u2294 (\u2a05 j \u2208 t, g j) = \u2a05 p \u2208 s \u00d7\u02e2 t, f (p : \u03b9 \u00d7 \u03b9').1 \u2294 g p.2 :=\n@bsupr_inf_bsupr \u03b1\u1d52\u1d48 _ _ _ _ _ _ _\n\ntheorem Inf_sup_Inf : Inf s \u2294 Inf t = (\u2a05 p \u2208 s \u00d7\u02e2 t, (p : \u03b1 \u00d7 \u03b1).1 \u2294 p.2) :=\n@Sup_inf_Sup \u03b1\u1d52\u1d48 _ _ _\n\nlemma infi_sup_of_monotone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (swap (\u2264))] {f g : \u03b9 \u2192 \u03b1}\n  (hf : monotone f) (hg : monotone g) :\n  (\u2a05 i, f i \u2294 g i) = (\u2a05 i, f i) \u2294 (\u2a05 i, g i) :=\nsupr_inf_of_antitone hf.dual_right hg.dual_right\n\nlemma infi_sup_of_antitone {\u03b9 : Type*} [preorder \u03b9] [is_directed \u03b9 (\u2264)] {f g : \u03b9 \u2192 \u03b1}\n  (hf : antitone f) (hg : antitone g) :\n  (\u2a05 i, f i \u2294 g i) = (\u2a05 i, f i) \u2294 (\u2a05 i, g i) :=\nsupr_inf_of_monotone hf.dual_right hg.dual_right\n\ninstance pi.coframe {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*} [\u03a0 i, coframe (\u03c0 i)] : coframe (\u03a0 i, \u03c0 i) :=\n{ Inf := Inf,\n  infi_sup_le_sup_Inf := \u03bb a s i,\n    by simp only [\u2190sup_infi_eq, Inf_apply, \u2190infi_subtype'', infi_apply, pi.sup_apply],\n  ..pi.complete_lattice }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance coframe.to_distrib_lattice : distrib_lattice \u03b1 :=\n{ le_sup_inf := \u03bb a b c, by rw [\u2190Inf_pair, \u2190Inf_pair, sup_Inf_eq, \u2190Inf_image, image_pair],\n  ..\u2039coframe \u03b1\u203a }\n\nend coframe\n\nsection complete_distrib_lattice\nvariables [complete_distrib_lattice \u03b1] {a b : \u03b1} {s t : set \u03b1}\n\ninstance : complete_distrib_lattice \u03b1\u1d52\u1d48 := { ..order_dual.frame, ..order_dual.coframe }\n\ninstance pi.complete_distrib_lattice {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*}\n  [\u03a0 i, complete_distrib_lattice (\u03c0 i)] : complete_distrib_lattice (\u03a0 i, \u03c0 i) :=\n{ ..pi.frame, ..pi.coframe }\n\nend complete_distrib_lattice\n\n/-- A complete Boolean algebra is a completely distributive Boolean algebra. -/\nclass complete_boolean_algebra \u03b1 extends boolean_algebra \u03b1, complete_distrib_lattice \u03b1\n\ninstance pi.complete_boolean_algebra {\u03b9 : Type*} {\u03c0 : \u03b9 \u2192 Type*}\n  [\u2200 i, complete_boolean_algebra (\u03c0 i)] : complete_boolean_algebra (\u03a0 i, \u03c0 i) :=\n{ .. pi.boolean_algebra, .. pi.complete_distrib_lattice }\n\ninstance Prop.complete_boolean_algebra : complete_boolean_algebra Prop :=\n{ infi_sup_le_sup_Inf := \u03bb p s, iff.mp $\n    by simp only [forall_or_distrib_left, complete_lattice.Inf, infi_Prop_eq, sup_Prop_eq],\n  inf_Sup_le_supr_inf := \u03bb p s, iff.mp $\n    by simp only [complete_lattice.Sup, exists_and_distrib_left, inf_Prop_eq, supr_Prop_eq],\n  .. Prop.boolean_algebra, .. Prop.complete_lattice }\n\nsection complete_boolean_algebra\nvariables [complete_boolean_algebra \u03b1] {a b : \u03b1} {s : set \u03b1} {f : \u03b9 \u2192 \u03b1}\n\ntheorem compl_infi : (infi f)\u1d9c = (\u2a06 i, (f i)\u1d9c) :=\nle_antisymm\n  (compl_le_of_compl_le $ le_infi $ \u03bb i, compl_le_of_compl_le $ le_supr (compl \u2218 f) i)\n  (supr_le $ \u03bb i, compl_le_compl $ infi_le _ _)\n\ntheorem compl_supr : (supr f)\u1d9c = (\u2a05 i, (f i)\u1d9c) :=\ncompl_injective (by simp [compl_infi])\n\nlemma compl_Inf : (Inf s)\u1d9c = (\u2a06 i \u2208 s, i\u1d9c) := by simp only [Inf_eq_infi, compl_infi]\nlemma compl_Sup : (Sup s)\u1d9c = (\u2a05 i \u2208 s, i\u1d9c) := by simp only [Sup_eq_supr, compl_supr]\nlemma compl_Inf' : (Inf s)\u1d9c = Sup (compl '' s) := compl_Inf.trans Sup_image.symm\nlemma compl_Sup' : (Sup s)\u1d9c = Inf (compl '' s) := compl_Sup.trans Inf_image.symm\n\nend complete_boolean_algebra\n\nsection lift\n\n/-- Pullback an `order.frame` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.frame [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1] [has_Inf \u03b1] [has_top \u03b1]\n  [has_bot \u03b1] [frame \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5) :\n  frame \u03b1 :=\n{ inf_Sup_le_supr_inf := \u03bb a s, begin\n    change f (a \u2293 Sup s) \u2264 f _,\n    rw [\u2190Sup_image, map_inf, map_Sup s, inf_bsupr_eq],\n    simp_rw \u2190map_inf,\n    exact ((map_Sup _).trans supr_image).ge,\n  end,\n  ..hf.complete_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot }\n\n/-- Pullback an `order.coframe` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.coframe [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1] [has_Inf \u03b1] [has_top \u03b1]\n  [has_bot \u03b1] [coframe \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5) :\n  coframe \u03b1 :=\n{ infi_sup_le_sup_Inf := \u03bb a s, begin\n    change f _ \u2264 f (a \u2294 Inf s),\n    rw [\u2190Inf_image, map_sup, map_Inf s, sup_binfi_eq],\n    simp_rw \u2190map_sup,\n    exact ((map_Inf _).trans infi_image).le,\n  end,\n  ..hf.complete_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot }\n\n/-- Pullback a `complete_distrib_lattice` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.complete_distrib_lattice [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1]\n  [has_Inf \u03b1] [has_top \u03b1] [has_bot \u03b1] [complete_distrib_lattice \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : function.injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5) :\n  complete_distrib_lattice \u03b1 :=\n{ ..hf.frame f map_sup map_inf map_Sup map_Inf map_top map_bot,\n  ..hf.coframe f map_sup map_inf map_Sup map_Inf map_top map_bot }\n\n/-- Pullback a `complete_boolean_algebra` along an injection. -/\n@[reducible] -- See note [reducible non-instances]\nprotected def function.injective.complete_boolean_algebra [has_sup \u03b1] [has_inf \u03b1] [has_Sup \u03b1]\n  [has_Inf \u03b1] [has_top \u03b1] [has_bot \u03b1] [has_compl \u03b1] [has_sdiff \u03b1] [complete_boolean_algebra \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (hf : function.injective f) (map_sup : \u2200 a b, f (a \u2294 b) = f a \u2294 f b)\n  (map_inf : \u2200 a b, f (a \u2293 b) = f a \u2293 f b) (map_Sup : \u2200 s, f (Sup s) = \u2a06 a \u2208 s, f a)\n  (map_Inf : \u2200 s, f (Inf s) = \u2a05 a \u2208 s, f a) (map_top : f \u22a4 = \u22a4) (map_bot : f \u22a5 = \u22a5)\n  (map_compl : \u2200 a, f a\u1d9c = (f a)\u1d9c) (map_sdiff : \u2200 a b, f (a \\ b) = f a \\ f b) :\n  complete_boolean_algebra \u03b1 :=\n{ ..hf.complete_distrib_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot,\n  ..hf.boolean_algebra f map_sup map_inf map_top map_bot map_compl map_sdiff }\n\nend lift\n\nnamespace punit\nvariables (s : set punit.{u+1}) (x y : punit.{u+1})\n\ninstance : complete_boolean_algebra punit :=\nby refine_struct\n{ Sup := \u03bb _, star,\n  Inf := \u03bb _, star,\n  ..punit.boolean_algebra };\n    intros; trivial <|> simp only [eq_iff_true_of_subsingleton, not_true, and_false]\n\n@[simp] lemma Sup_eq : Sup s = star := rfl\n@[simp] lemma Inf_eq : Inf s = star := rfl\n\nend punit\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/complete_boolean_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7116220551369163}}
{"text": "import data.nat.basic\nimport data.int.basic\nimport data.rat.basic\nimport data.real.basic\nimport data.complex.basic\nimport data.list\n\nimport tactic\nimport tactic.rewrite_search.frontend\n\n\nnamespace notes\n\nsection\n  parameters (G : Type) [has_mul G]\n  -- parameters (mul_assoc : \u2200 a b c : G, a * (b * c) = (a * b) * c)\n  -- parameters (mul_comm : \u2200 a b : G, a * b = b * a)\n\n  def is_left_id  (e : G) : Prop := \u2200 g : G, e * g = g\n  def is_right_id (e : G) : Prop := \u2200 g : G, g * e = g\n\n  section\n    parameters (e\u2081 : G) (he\u2081 : is_left_id e\u2081)\n    parameters (e\u2082 : G) (he\u2082 : is_right_id e\u2082)\n\n    lemma left_id_eq_right_id : e\u2081 = e\u2082 := eq.trans (eq.symm (he\u2082 e\u2081)) (he\u2081 e\u2082)\n  end\n\n  def is_id (e : G) : Prop := is_left_id e \u2227 is_right_id e\n\n  section\n    parameters (e : G) (he : is_id e)\n    parameters (e' : G) (he' : is_id e')\n\n    lemma id_unique : e = e' :=\n      left_id_eq_right_id _ he.left _ he'.right\n  end\n\n  section\n    parameters (e : G) (he : is_left_id e \u2227 is_right_id e)\n    parameters (g : G)\n\n    def has_left_inv_of  (h : G) : Prop := h * g = e\n    def has_right_inv_of (h : G) : Prop := g * h = e\n\n    section\n      parameters (mul_assoc' : \u2200 a b c : G, a * (b * c) = (a * b) * c)\n      parameters (h\u2081 : G) (hh\u2081 : has_left_inv_of h\u2081)\n      parameters (h\u2082 : G) (hh\u2082 : has_right_inv_of h\u2082)\n\n      -- h\u2081 = h\u2081 * e = h\u2081 * (g * h\u2082) = (h\u2081 * g) * h\u2082 = e * h\u2082 = h\u2082\n      include g e he h\u2081 hh\u2081 h\u2082 hh\u2082 mul_assoc'\n      lemma left_inv_eq_right_inv : h\u2081 = h\u2082 := by\n        calc  h\u2081\n            = h\u2081 * e        : eq.symm (he.right h\u2081)\n        ... = h\u2081 * (g * h\u2082) : congr_arg2 (*) rfl hh\u2082.symm\n        ... = (h\u2081 * g) * h\u2082 : mul_assoc' _ _ _\n        ... = e * h\u2082        : congr_arg2 (*) hh\u2081 rfl\n        ... = h\u2082            : he.left h\u2082\n\n      -- I don't know why tactics are not working properly here!\n      -- Probably another reason why I have to invent my own prover...\n    end\n\n    def has_inv_of (h : G) : Prop := h * g = e \u2227 g * h = e\n\n    section\n      parameters (mul_assoc' : \u2200 a b c : G, a * (b * c) = (a * b) * c)\n      parameters (h : G) (hh : has_inv_of h)\n      parameters (h' : G) (hh' : has_inv_of h')\n\n      include g e he h hh h' hh' mul_assoc'\n      lemma inv_unique : h = h' :=\n        left_inv_eq_right_inv mul_assoc' _ hh.left _ hh'.right\n    end\n  end\nend\n\n@[class]\nstructure group (G : Type) : Type :=\n  (mul : G \u2192 G \u2192 G)\n  (mul_assoc : \u2200 a b c : G, mul (mul a b) c = mul a (mul b c))\n  (e : G)\n  (he : \u2200 g : G, mul e g = g \u2227 mul g e = g)\n  (i : G \u2192 G)\n  (hi : \u2200 g : G, mul (i g) g = e \u2227 mul g (i g) = e)\n\n\n\nend notes\n", "meta": {"author": "bridgekat", "repo": "lean-notes", "sha": "18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d", "save_path": "github-repos/lean/bridgekat-lean-notes", "path": "github-repos/lean/bridgekat-lean-notes/lean-notes-18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d/src/3_groups/groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7116220466830724}}
{"text": "-- Producto_de_potencias_de_la_misma_base_en_monoides.lean\n-- Producto_de_potencias_de_la_misma_base_en_monoides\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 30 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En los [monoides](https://en.wikipedia.org/wiki/Monoid) se define la\n-- potencia con exponentes naturales. En Lean la potencia x^n se\n-- se caracteriza por los siguientes lemas:\n--    pow_zero : x^0 = 1\n--    pow_succ : x^(succ n) = x * x^n\n--\n-- Demostrar que\n--    x^(m + n) = x^m * x^n\n-- ---------------------------------------------------------------------\n\nimport algebra.group_power.basic\nopen monoid nat\n\nvariables {M : Type} [monoid M]\nvariable  x : M\nvariables (m n : \u2115)\n\n-- Para que no use la notaci\u00f3n con puntos\nset_option pp.structure_projections false\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  x^(m + n) = x^m * x^n :=\nbegin\n  induction m with m HI,\n  { calc x^(0 + n)\n         = x^n             : congr_arg ((^) x) (nat.zero_add n)\n     ... = 1 * x^n         : (monoid.one_mul (x^n)).symm\n     ... = x^0 * x^n       : congr_arg (* (x^n)) (pow_zero x).symm, },\n  { calc x^(succ m + n)\n         = x^succ (m + n)  : congr_arg ((^) x) (succ_add m n)\n     ... = x * x^(m + n)   : pow_succ x (m + n)\n     ... = x * (x^m * x^n) : congr_arg ((*) x) HI\n     ... = (x * x^m) * x^n : (monoid.mul_assoc x (x^m) (x^n)).symm\n     ... = x^succ m * x^n  : congr_arg (* x^n) (pow_succ x m).symm, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  x^(m + n) = x^m * x^n :=\nbegin\n  induction m with m HI,\n  { calc x^(0 + n)\n         = x^n             : by simp only [nat.zero_add]\n     ... = 1 * x^n         : by simp only [monoid.one_mul]\n     ... = x^0 * x^n       : by simp [pow_zero] },\n  { calc x^(succ m + n)\n         = x^succ (m + n)  : by simp only [succ_add]\n     ... = x * x^(m + n)   : by simp only [pow_succ]\n     ... = x * (x^m * x^n) : by simp only [HI]\n     ... = (x * x^m) * x^n : (monoid.mul_assoc x (x^m) (x^n)).symm\n     ... = x^succ m * x^n  : by simp only [pow_succ], },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  x^(m + n) = x^m * x^n :=\nbegin\n  induction m with m HI,\n  { calc x^(0 + n)\n         = x^n             : by simp [nat.zero_add]\n     ... = 1 * x^n         : by simp\n     ... = x^0 * x^n       : by simp, },\n  { calc x^(succ m + n)\n         = x^succ (m + n)  : by simp [succ_add]\n     ... = x * x^(m + n)   : by simp [pow_succ]\n     ... = x * (x^m * x^n) : by simp [HI]\n     ... = (x * x^m) * x^n : (monoid.mul_assoc x (x^m) (x^n)).symm\n     ... = x^succ m * x^n  : by simp [pow_succ], },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  x^(m + n) = x^m * x^n :=\nbegin\n  induction m with m HI,\n  { show x^(0 + n) = x^0 * x^n,\n      by simp [nat.zero_add] },\n  { show x^(succ m + n) = x^succ m * x^n,\n      by finish [succ_add,\n                 HI,\n                 monoid.mul_assoc,\n                 pow_succ], },\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample :\n  x^(m + n) = x^m * x^n :=\npow_add x m n\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Producto_de_potencias_de_la_misma_base_en_monoides.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7115864979545296}}
{"text": "import algebra.ring tactic.ext \n\n/-!\nThis file includes definitions of standard\ncoordinate tuples represented as lists and \nthe usual coordinate-wise operations needed\nfor linear algebra. This file supports our\nformalization of affine coordinate spaces. \n-/\n\n\nuniverses u v\nvariables {k : Type u} [ring k] [inhabited k] {\u03b1 : Type v} [has_add \u03b1]\n(a b : \u03b1) (al bl : list \u03b1)\n(x y : k) (xl yl : list k)\n(n : \u2115)\n\nopen list\n\nnamespace vecl\n\ndef ladd : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1 := zip_with has_add.add\n\n/-- addition is compatible with list constructor -/\n@[simp] theorem add_cons_cons (a b : \u03b1) (l\u2081 l\u2082 : list \u03b1) :\n  ladd (a :: l\u2081) (b :: l\u2082) = (a + b) :: ladd l\u2081 l\u2082 := rfl\n\n/-- adding the empty list to a list gives you the empty list -/\n@[simp] theorem add_nil_left (l : list \u03b1) : ladd ([] : list \u03b1) l = [] := rfl\n\n/-- adding a list to the empty list gives you the empty list -/\n@[simp] theorem add_nil_right (l : list \u03b1) : ladd l ([] : list \u03b1) = [] :=\nby cases l; refl\n\n\n@[simp] theorem length_sum : \u2200 (l\u2081 : list \u03b1) (l\u2082 : list \u03b1),\n   length (ladd l\u2081 l\u2082) = min (length l\u2081) (length l\u2082)\n| []      l\u2082      := rfl\n| l\u2081      []      := by simp -- TODO: figure out which simp lemmata are being used, and use \"simp only\"\n| (a::l\u2081) (b::l\u2082) := --by simp only [length, add_cons_cons, length_sum l\u2081 l\u2082, min_succ_succ]\nbegin\nsimp only [length, add_cons_cons, length_sum l\u2081 l\u2082],\nexact ((length l\u2081).min_succ_succ (length l\u2082)).symm,\nend\n\n@[simp] theorem zip_with_cons_cons {\u03b1 \u03b2 \u03b3} (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (a : \u03b1) (b : \u03b2) (l\u2081 : list \u03b1) (l\u2082 : list \u03b2) :\n  list.zip_with f (a :: l\u2081) (b :: l\u2082) = f a b :: list.zip_with f l\u2081 l\u2082 := rfl\n\n/-- the empty list is of length 0 -/\n@[simp] lemma len_nil : length ([] : list \u03b1) = 0 := rfl\n/-- every list is one longer than its tail -/\n@[simp] lemma len_cons : length (a :: al) = length al + 1 := rfl\n\n--! IMPORTANT: NO has_add INSTANCE ANYMORE\n\n/-- may or may not need this -/\nlemma ladd_defn : ladd al bl = (zip_with has_add.add) al bl := by {intros, refl}\n\n/-- returns list of 0 vector of given length. -/\ndef zero_vector (k : Type*) [ring k] : \u2115 \u2192 list k\n| 0 := [0]\n| (nat.succ n) := 0 :: (zero_vector n)\n\nlemma field_zero_sep : \u2200 n : \u2115, n \u2260 0 \u2192 zero_vector k n = 0 :: zero_vector k (n - 1) :=\nbegin\nintros n h,\ninduction n with n',\n{contradiction},\n{refl}\nend\n\n/-- returns a list multiplied element-wise by a scalar. -/\ndef scalar_mul : k \u2192 list k \u2192 list k\n| x [] := []\n| x (a :: l) := (x * a) :: (scalar_mul x l)\n\n/-- definitional lemmata for scalar_mul -/\nlemma scalar_nil : scalar_mul x [] = [] := rfl\nlemma scalar_cons : scalar_mul y (x :: xl) = (y * x) :: (scalar_mul y xl) := rfl\n\n/-- scaling a vector does not change its length -/\nlemma scale_len : length (scalar_mul x xl) = length xl := \nbegin\ninduction xl,\nrw scalar_nil,\nsimp only [scalar_cons, len_cons, xl_ih],\nend\n\n/-- scaling by 1 returns the original vector -/\nlemma one_smul_cons : scalar_mul 1 xl = xl :=\nbegin\ninduction xl,\nrefl,\nrw [scalar_cons, one_mul, xl_ih],\nend\n\n/-- scaling by 0 returns the zero vector -/\nlemma zero_smul_cons : xl \u2260 [] \u2192 scalar_mul 0 xl = zero_vector k (xl.length - 1) :=\nbegin\nintros,\ninduction xl,\ncontradiction,\ncases xl_tl,\nhave h\u2081 : scalar_mul 0 [xl_hd] = [0*xl_hd] := rfl,\nhave h\u2082 : zero_vector k ([xl_hd].length - 1) = [0] := rfl,\nrw [h\u2081, h\u2082, zero_mul],\n\nrw [scalar_cons, field_zero_sep],\nhave h\u2084 : (xl_hd :: xl_tl_hd :: xl_tl_tl).length - 1 - 1 = (xl_tl_hd :: xl_tl_tl).length - 1 := rfl,\nrw [h\u2084, xl_ih, zero_mul],\nrepeat {contradiction},\nend\n\n/-- scaling the zero vector with anything returns the zero vector -/\nlemma smul_zero_cons : scalar_mul x (zero_vector k n) = zero_vector k n :=\nbegin\ninduction n with n',\nhave h\u2081 : zero_vector k 0 = [0] := rfl,\nhave h\u2082 : scalar_mul x [0] = [x*0] := rfl,\nrw [h\u2081, h\u2082, mul_zero],\n\nhave h\u2083 : n'.succ - 1 = n' := rfl,\nrw [field_zero_sep, scalar_cons, mul_zero, h\u2083, n_ih],\ncontradiction\nend\n\n/-- scaling is consistent with ring multiplication -/\nlemma smul_assoc : scalar_mul (x*y) xl = scalar_mul x (scalar_mul y xl) :=\nbegin\ninduction xl,\nrefl,\nsimp only [scalar_cons],\nsplit,\nrw mul_assoc,\nexact xl_ih,\nend\n\n/-- neg function for rings -/\ndef ring_neg : k \u2192 k := \u03bb a, -a\n/-- neg function for lists -/\ndef vecl_neg : list k \u2192 list k := map ring_neg\n\nlemma neg_cons : vecl_neg (x :: xl) = (-x) :: vecl_neg xl := rfl\n\n/-- length of -x is the same as the length of x-/\n@[simp] theorem len_neg : length (vecl_neg xl) = length xl := \nbegin\ninduction xl,\n{\n    dsimp only [vecl_neg, ring_neg, map, length], refl,\n},\n{\n  have t : vecl_neg (xl_hd :: xl_tl) = (-xl_hd :: vecl_neg xl_tl) := rfl,\n  simp only [t, len_cons, xl_ih],\n},\nend\n\nlemma ladd_assoc : \u2200 x y z : list k, ladd (ladd x y) z = ladd x (ladd y z) :=\nbegin\nintros x y z,\ninduction x generalizing y z,\nsimp only [add_nil_left, add_nil_right],\ninduction y generalizing z,\nsimp only [add_nil_left, add_nil_right],\ncases z,\nsimp only [add_nil_left, add_nil_right],\nrw ladd at x_ih y_ih \u22a2,\nrepeat {rw zip_with_cons_cons},\nrw add_assoc,\nrw x_ih,\nend\n\nlemma zero_ladd : \u2200 x : list k, ladd (zero_vector k (length x - 1)) x = x :=\nbegin\nintro x,\ninduction x,\n{refl},\n{\n  have tl_len : length (x_hd :: x_tl) - 1 = length x_tl := rfl,\n  rw tl_len,\n  induction x_tl,\n  {\n    have field_zero_zero : zero_vector k 0 = [0] := rfl,\n    have add_list : ladd [0] [x_hd] = [0 + x_hd] := rfl,\n    rw [len_nil, field_zero_zero, add_list, zero_add]\n  },\n  {\n    have zero_tl : zero_vector k (length (x_tl_hd :: x_tl_tl)) = 0 :: zero_vector k (length x_tl_tl) :=\n      begin\n      have len_x : length (x_tl_hd :: x_tl_tl) \u2260 0 :=\n        begin\n        intro h,\n        have len_x' : length (x_tl_hd :: x_tl_tl) = length x_tl_tl + 1 := rfl,\n        contradiction\n        end,\n      apply field_zero_sep,\n      exact len_x\n      end,\n      have sep_head : ladd (0 :: (zero_vector k (length x_tl_tl))) (x_hd :: (x_tl_hd :: x_tl_tl)) =\n        (0 + x_hd) :: ladd (zero_vector k (length x_tl_tl)) (x_tl_hd :: x_tl_tl) := rfl,\n      have head_add : 0 + x_hd = x_hd := by rw zero_add,\n      have len_x_tl : length x_tl_tl = length (x_tl_hd :: x_tl_tl) - 1 := rfl,\n      rw [zero_tl, sep_head, head_add, len_x_tl, x_ih]\n  }\n}\nend\n\nlemma zero_ladd' : \u2200 x : list k, \u2200 n : \u2115, length x = n + 1 \u2192 ladd (zero_vector k n) x = x :=\nbegin\nintros x n x_len,\ninduction x,\ncontradiction,\nhave tl_l : length (x_hd :: x_tl) - 1 = length x_tl := rfl,\nhave tl_len : length x_tl = n := nat.succ.inj x_len,\nrw (eq.symm tl_len),\nrw (eq.symm tl_l),\napply zero_ladd,\nend \n\nlemma ladd_zero : \u2200 x : list k, ladd x (zero_vector k (length x - 1)) = x :=\nbegin\nintro x,\ninduction x,\n{refl},\n{\n  have tl_len : length (x_hd :: x_tl) - 1 = length x_tl := rfl,\n  rw tl_len,\n  induction x_tl,\n  {\n    have field_zero_zero : zero_vector k 0 = [0] := rfl,\n    have add_list : ladd [x_hd] [0] = [x_hd + 0] := rfl,\n    rw [len_nil, field_zero_zero, add_list, add_zero]\n  },\n  {\n    have zero_tl : zero_vector k (length (x_tl_hd :: x_tl_tl)) = 0 :: zero_vector k (length (x_tl_hd :: x_tl_tl) - 1) :=\n      begin\n      have len_x : length (x_tl_hd :: x_tl_tl) \u2260 0 :=\n        begin\n        intro h,\n        have len_x' : length (x_tl_hd :: x_tl_tl) = length x_tl_tl + 1 := rfl,\n        contradiction\n        end,\n      apply field_zero_sep,\n      exact len_x\n      end,\n    have sep_head : ladd (x_hd :: (x_tl_hd :: x_tl_tl)) (0 :: zero_vector k (length (x_tl_hd :: x_tl_tl) - 1)) =\n      (x_hd + 0) :: ladd (x_tl_hd :: x_tl_tl) (zero_vector k (length (x_tl_hd :: x_tl_tl) - 1)) := rfl,\n    have head_add : x_hd + 0 = x_hd := by rw add_zero,\n    rw [zero_tl, sep_head, head_add, x_ih]\n  }\n}\nend \n\nlemma ladd_zero' : \u2200 x : list k, \u2200 n : \u2115, length x = n + 1 \u2192 ladd x (zero_vector k n) = x :=\nbegin\nintros x n x_len,\ninduction x,\ncontradiction,\nhave tl_l : length (x_hd :: x_tl) - 1 = length x_tl := rfl,\nhave tl_len : length x_tl = n := nat.succ.inj x_len,\nrw (eq.symm tl_len),\nrw (eq.symm tl_l),\napply ladd_zero,\nend\n\nlemma ladd_left_neg : \u2200 x : list k, x \u2260 [] \u2192 ladd (vecl_neg x) x = zero_vector k ((length x) - 1) :=\nbegin\nintros x x_h,\ninduction x,\n{contradiction},\n{\n  induction x_tl,\n  {\n    have neg_x : vecl_neg [x_hd] = [-x_hd] := rfl,\n    have list_sum : ladd [-x_hd] [x_hd] = [-x_hd + x_hd] := rfl,\n    have x_hd_sum : -x_hd + x_hd = 0 := by apply add_left_neg,\n    have zero_is : zero_vector k (length [x_hd] - 1) = [0] := rfl,\n    rw [neg_x, list_sum, x_hd_sum, zero_is],\n  },\n  {\n    have neg_x : vecl_neg (x_hd :: x_tl_hd :: x_tl_tl) = (-x_hd) :: (vecl_neg (x_tl_hd :: x_tl_tl)) := rfl,\n    have list_sum : ladd (-x_hd :: (vecl_neg (x_tl_hd :: x_tl_tl))) (x_hd :: x_tl_hd :: x_tl_tl) =\n      (-x_hd + x_hd) :: ladd (vecl_neg (x_tl_hd :: x_tl_tl)) (x_tl_hd :: x_tl_tl) := rfl,\n    have x_hd_sum : -x_hd + x_hd = 0 := by apply add_left_neg,\n    have x_tl_sum : ladd (vecl_neg (x_tl_hd :: x_tl_tl)) (x_tl_hd :: x_tl_tl) = zero_vector k (length (x_tl_hd :: x_tl_tl) - 1) :=\n      begin\n      apply x_ih,\n      contradiction\n      end,\n    have zero_is : zero_vector k (length (x_hd :: x_tl_hd :: x_tl_tl) - 1) = 0 :: zero_vector k (length (x_hd :: x_tl_tl) - 1) := rfl,\n    rw [neg_x, list_sum, x_hd_sum, x_tl_sum, zero_is],\n    refl,\n  }\n}\nend\n\nlemma ladd_comm : \u2200 x y : list k, ladd x y = ladd y x :=\nbegin\nintros l l',\n  induction l with hd tl hl generalizing l',\n  \n  rw [add_nil_left, add_nil_right],\n  \n  cases l' with hd' tl',\n  rw [add_nil_left, add_nil_right],\n  rw ladd at hl \u22a2,\n  rw [zip_with_cons_cons, zip_with_cons_cons, hl, add_comm]\nend\n\nlemma ladd_free : \u2200 (xl yl zl : list k), zl.length = xl.length \u2192 zl.length = yl.length \u2192 zl \u2260 nil \u2192 ladd xl zl = ladd yl zl \u2192 xl = yl :=\nbegin\nintros xl yl zl x_len y_len z_cons h\u2080,\nhave h\u2081 : ladd (ladd xl zl) (vecl_neg zl) = ladd (ladd yl zl) (vecl_neg zl) := by rw h\u2080,\nrepeat {rw ladd_assoc at h\u2081},\nhave h\u2082 : ladd zl (vecl_neg zl) = ladd (vecl_neg zl) zl := by rw ladd_comm,\nhave h\u2083 : xl.length = yl.length := eq.trans (eq.symm x_len) y_len,\nrw [h\u2082, ladd_left_neg, x_len, ladd_zero, h\u2083, ladd_zero] at h\u2081,\nexact h\u2081,\nexact z_cons\nend\n\nlemma smul_ladd : scalar_mul x (ladd xl yl) = ladd (scalar_mul x xl) (scalar_mul x yl) :=\nbegin\ninduction xl generalizing yl,\nrefl,\n\ncases yl,\nrefl,\n\nrw [add_cons_cons, scalar_cons, scalar_cons, scalar_cons, add_cons_cons, left_distrib, xl_ih]\nend\n\nlemma ladd_smul : scalar_mul (x + y) xl = ladd (scalar_mul x xl) (scalar_mul y xl) :=\nbegin\ninduction xl,\nrefl,\n\nrepeat {rw scalar_cons},\nrw [add_cons_cons, right_distrib, xl_ih]\nend\n\n#check zip_with\n\nend vecl", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/old/old/list_as_k_tuple.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912749233991, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7115864961871927}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.coeff\n\n/-!\n# Theory of univariate polynomials\n\nThe main results are `induction_on` and `as_sum`.\n-/\n\nnoncomputable theory\n\nopen finsupp finset\n\nnamespace polynomial\nuniverses u v w x y z\nvariables {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type x} {k : Type y} {A : Type z}\n  {a b : R} {m n : \u2115}\n\nsection semiring\nvariables [semiring R] {p q r : polynomial R}\n\nlemma sum_C_mul_X_eq (p : polynomial R) : p.sum (\u03bbn a, C a * X^n) = p :=\neq.trans (sum_congr rfl $ assume n hn, single_eq_C_mul_X.symm) (finsupp.sum_single _)\n\nlemma sum_monomial_eq (p : polynomial R) : p.sum (\u03bbn a, monomial n a) = p :=\nby simp only [single_eq_C_mul_X, sum_C_mul_X_eq]\n\n@[elab_as_eliminator] protected lemma induction_on {M : polynomial R \u2192 Prop} (p : polynomial R)\n  (h_C : \u2200a, M (C a))\n  (h_add : \u2200p q, M p \u2192 M q \u2192 M (p + q))\n  (h_monomial : \u2200(n : \u2115) (a : R), M (C a * X^n) \u2192 M (C a * X^(n+1))) :\n  M p :=\nhave \u2200{n:\u2115} {a}, M (C a * X^n),\nbegin\n  assume n a,\n  induction n with n ih,\n  { simp only [pow_zero, mul_one, h_C] },\n  { exact h_monomial _ _ ih }\nend,\nfinsupp.induction p\n  (suffices M (C 0), by { convert this, exact single_zero.symm, },\n    h_C 0)\n  (assume n a p _ _ hp, suffices M (C a * X^n + p), by { convert this, exact single_eq_C_mul_X },\n    h_add _ _ this hp)\n\n/--\nTo prove something about polynomials,\nit suffices to show the condition is closed under taking sums,\nand it holds for monomials.\n-/\n@[elab_as_eliminator] protected lemma induction_on' {M : polynomial R \u2192 Prop} (p : polynomial R)\n  (h_add : \u2200p q, M p \u2192 M q \u2192 M (p + q))\n  (h_monomial : \u2200(n : \u2115) (a : R), M (monomial n a)) :\n  M p :=\npolynomial.induction_on p (h_monomial 0) h_add\n(\u03bb n a h, begin rw \u2190 single_eq_C_mul_X at \u22a2, exact h_monomial _ _, end)\n\n\nsection coeff\n\ntheorem coeff_mul_monomial (p : polynomial R) (n d : \u2115) (r : R) :\n  coeff (p * monomial n r) (d + n) = coeff p d * r :=\nby rw [single_eq_C_mul_X, \u2190X_pow_mul, \u2190mul_assoc, coeff_mul_C, coeff_mul_X_pow]\n\ntheorem coeff_monomial_mul (p : polynomial R) (n d : \u2115) (r : R) :\n  coeff (monomial n r * p) (d + n) = r * coeff p d :=\nby rw [single_eq_C_mul_X, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow]\n\n-- This can already be proved by `simp`.\ntheorem coeff_mul_monomial_zero (p : polynomial R) (d : \u2115) (r : R) :\n  coeff (p * monomial 0 r) d = coeff p d * r :=\ncoeff_mul_monomial p 0 d r\n\n-- This can already be proved by `simp`.\ntheorem coeff_monomial_zero_mul (p : polynomial R) (d : \u2115) (r : R) :\n  coeff (monomial 0 r * p) d = r * coeff p d :=\ncoeff_monomial_mul p 0 d r\n\nend coeff\n\nend semiring\nend polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/polynomial/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7115864851256691}}
{"text": "import algebra.group_power algebra.big_operators data.nat.choose\n-- This appears to be a proof of the binomial theorem by Chris.\nopen finset nat\nvariable {\u03b1 : Type*}\n\nlocal notation f ` \u2211 ` : 90 n : 90  := finset.sum (finset.range n) f\n\n/-\ntheorem add_pow [comm_semiring \u03b1] (x y : \u03b1) : \u2200 n : \u2115,\n    (x + y)^n = (\u03bb m, x^m * y^(n - m) * choose n m) \u2211 succ n\n| 0        := by simp\n| (succ n) :=\nhave h\u2081 : x * (x^n * y^(n - n) * choose n n) = x^succ n * y^(succ n - succ n)\n    * choose (succ n) (succ n) :=\n  by simp [_root_.pow_succ, mul_assoc, mul_comm, mul_left_comm],\nhave  h\u2082 : y * (x^0 * y^(n - 0) * choose n 0) = x^0 * y^(succ n - 0) * choose (succ n) 0 := \n  by simp [_root_.pow_succ, mul_assoc, mul_comm, mul_left_comm],\nhave h\u2083 : (\u03bb m, x * (x^m * y^(n - m) * choose n m) + y * (x^succ m * y^(n - succ m)\n    * choose n (succ m))) \u2211 n \n    = (\u03bb m, x^succ m * y^(succ n - succ m) * \u2191(choose (succ n) (succ m))) \u2211 n := \n  finset.sum_congr rfl $ \u03bb m hm, begin \n      rw finset.mem_range at hm,\n      rw [\u2190 mul_assoc y, \u2190 mul_assoc y, mul_right_comm y, \u2190 _root_.pow_succ, add_one, \u2190 succ_sub hm],\n      simp [succ_sub_succ, _root_.pow_succ, choose_succ_succ, mul_add, mul_comm, \n          mul_assoc, mul_left_comm]\n    end,\nby rw [_root_.pow_succ, add_pow, add_mul, finset.mul_sum, finset.mul_sum, sum_range_succ, sum_range_succ',\n    sum_range_succ, sum_range_succ', add_assoc, \u2190 add_assoc (_ \u2211 n), \u2190 finset.sum_add_distrib, h\u2081, h\u2082, h\u2083]\n-/\n\n", "meta": {"author": "kbuzzard", "repo": "lean-stacks-project", "sha": "b57be17aa917f1c3a23c59db5ee37b1aa21112c2", "save_path": "github-repos/lean/kbuzzard-lean-stacks-project", "path": "github-repos/lean/kbuzzard-lean-stacks-project/lean-stacks-project-b57be17aa917f1c3a23c59db5ee37b1aa21112c2/src/chris_ring_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.7115760712937085}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport data.real.basic -- imports the real numbers\n\n/-!\n\n# Doing algebra in the real numbers\n\nThe `ring` tactic will prove algebraic identities like\n(x + y) ^ 2 = x ^ 2 + 2 * x * y + y ^ 2 in rings, and Lean\nknows that the real numbers are a ring. See if you can use\n`ring` to prove these theorems.\n\n## New tactics you will need\n\n* `ring`\n* `intro` (new functionality: use on a goal of type `\u22a2 \u2200 x, ...`)\n\n-/\n\nexample (x y : \u211d) : (x + y) ^ 2  = x ^ 2 + 2 * x * y + y ^ 2 :=\nbegin\n  ring,\nend\n\nexample : \u2200 (a b : \u211d), \u2203 x, \n  (a + b) ^ 3 = a ^ 3 + x * a ^ 2 * b + 3 * a * b ^ 2 + b ^ 3 :=\nbegin\n  intros a b,use 3, ring,\nend\n\nexample : \u2203 (x : \u211d), \u2200 y, y + y = x * y :=\nbegin\n  use 2,intro y,ring,\nend\n\nexample : \u2200 (x : \u211d), \u2203 y, x + y = 2 :=\nbegin\n  intro x,use 2-x,ring,\nend\n\nexample : \u2200 (x : \u211d), \u2203 y, x + y \u2260 2 :=\nbegin\n  intro x, use -12-x,ring_nf,norm_num, \nend\n", "meta": {"author": "yakimk", "repo": "lean2022", "sha": "145d03ca2f5a8d2508de05fe78597299051fb8e9", "save_path": "github-repos/lean/yakimk-lean2022", "path": "github-repos/lean/yakimk-lean2022/lean2022-145d03ca2f5a8d2508de05fe78597299051fb8e9/src/section02reals/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506716354847, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.7115124402027109}}
{"text": "import data.real.basic\n\nopen function\n\n-- BEGIN\nexample {c : \u211d} : surjective (\u03bb x, x + c) :=\nbegin\n  intro x,\n  use x - c,\n  dsimp, ring\nend\n\nexample {c : \u211d} (h : c \u2260 0) : surjective (\u03bb x, c * x) :=\nbegin\n  intro x, \n  dsimp,\n  use x / c,\n  sorry,\nend\n\n/- Alternatively, using the field_simp tactic -/\n\nexample {c : \u211d} (h : c \u2260 0) : surjective (\u03bb x, c * x) :=\nbegin\n  intro x, \n  dsimp,\n  use x / c,\n  field_simp, /- clear denominators in a useful way -/\n  sorry,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/8_use/ex2_use_surject.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7114395261469123}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen, Devon Tuma\n\n! This file was ported from Lean 3 source module ring_theory.polynomial.scale_roots\n! leanprover-community/mathlib commit 40ac1b258344e0c2b4568dc37bfad937ec35a727\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.RingTheory.NonZeroDivisors\nimport Mathlib.Data.Polynomial.AlgebraMap\n\n/-!\n# Scaling the roots of a polynomial\n\nThis file defines `scaleRoots p s` for a polynomial `p` in one variable and a ring element `s` to\nbe the polynomial with root `r * s` for each root `r` of `p` and proves some basic results about it.\n-/\n\n\nvariable {A K R S : Type _} [CommRing A] [IsDomain A] [Field K] [CommRing R] [CommRing S]\n\nvariable {M : Submonoid A}\n\nnamespace Polynomial\n\nopen BigOperators Polynomial\n\n/-- `scaleRoots p s` is a polynomial with root `r * s` for each root `r` of `p`. -/\nnoncomputable def scaleRoots (p : R[X]) (s : R) : R[X] :=\n  \u2211 i in p.support, monomial i (p.coeff i * s ^ (p.natDegree - i))\n#align polynomial.scale_roots Polynomial.scaleRoots\n\n@[simp]\ntheorem coeff_scaleRoots (p : R[X]) (s : R) (i : \u2115) :\n    (scaleRoots p s).coeff i = coeff p i * s ^ (p.natDegree - i) := by\n  simp (config := { contextual := true }) [scaleRoots, coeff_monomial]\n#align polynomial.coeff_scale_roots Polynomial.coeff_scaleRoots\n\ntheorem coeff_scaleRoots_natDegree (p : R[X]) (s : R) :\n    (scaleRoots p s).coeff p.natDegree = p.leadingCoeff := by\n  rw [leadingCoeff, coeff_scaleRoots, tsub_self, pow_zero, mul_one]\n#align polynomial.coeff_scale_roots_nat_degree Polynomial.coeff_scaleRoots_natDegree\n\n@[simp]\ntheorem zero_scaleRoots (s : R) : scaleRoots 0 s = 0 := by\n  ext\n  simp\n#align polynomial.zero_scale_roots Polynomial.zero_scaleRoots\n\n\n\ntheorem support_scaleRoots_le (p : R[X]) (s : R) : (scaleRoots p s).support \u2264 p.support := by\n  intro\n  simpa using left_ne_zero_of_mul\n#align polynomial.support_scale_roots_le Polynomial.support_scaleRoots_le\n\ntheorem support_scaleRoots_eq (p : R[X]) {s : R} (hs : s \u2208 nonZeroDivisors R) :\n    (scaleRoots p s).support = p.support :=\n  le_antisymm (support_scaleRoots_le p s)\n    (by intro i\n        simp only [coeff_scaleRoots, Polynomial.mem_support_iff]\n        intro p_ne_zero ps_zero\n        have := pow_mem hs (p.natDegree - i) _ ps_zero\n        contradiction)\n#align polynomial.support_scale_roots_eq Polynomial.support_scaleRoots_eq\n\n@[simp]\ntheorem degree_scaleRoots (p : R[X]) {s : R} : degree (scaleRoots p s) = degree p := by\n  haveI := Classical.propDecidable\n  by_cases hp : p = 0\n  \u00b7 rw [hp, zero_scaleRoots]\n  refine' le_antisymm (Finset.sup_mono (support_scaleRoots_le p s)) (degree_le_degree _)\n  rw [coeff_scaleRoots_natDegree]\n  intro h\n  have := leadingCoeff_eq_zero.mp h\n  contradiction\n#align polynomial.degree_scale_roots Polynomial.degree_scaleRoots\n\n@[simp]\ntheorem natDegree_scaleRoots (p : R[X]) (s : R) : natDegree (scaleRoots p s) = natDegree p := by\n  simp only [natDegree, degree_scaleRoots]\n#align polynomial.nat_degree_scale_roots Polynomial.natDegree_scaleRoots\n\ntheorem monic_scaleRoots_iff {p : R[X]} (s : R) : Monic (scaleRoots p s) \u2194 Monic p := by\n  simp only [Monic, leadingCoeff, natDegree_scaleRoots, coeff_scaleRoots_natDegree]\n#align polynomial.monic_scale_roots_iff Polynomial.monic_scaleRoots_iff\n\ntheorem scaleRoots_eval\u2082_mul {p : S[X]} (f : S \u2192+* R) (r : R) (s : S) :\n    eval\u2082 f (f s * r) (scaleRoots p s) = f s ^ p.natDegree * eval\u2082 f r p :=\n  calc\n    _ = (scaleRoots p s).support.sum fun i =>\n          f (coeff p i * s ^ (p.natDegree - i)) * (f s * r) ^ i :=\n      by simp [eval\u2082_eq_sum, sum_def]\n    _ = p.support.sum fun i => f (coeff p i * s ^ (p.natDegree - i)) * (f s * r) ^ i :=\n      (Finset.sum_subset (support_scaleRoots_le p s) fun i _hi hi' =>\n        by\n        let this : coeff p i * s ^ (p.natDegree - i) = 0 := by simpa using hi'\n        simp [this])\n    _ = p.support.sum fun i : \u2115 => f (p.coeff i) * f s ^ (p.natDegree - i + i) * r ^ i :=\n      (Finset.sum_congr rfl fun i _hi => by\n        simp_rw [f.map_mul, f.map_pow, pow_add, mul_pow, mul_assoc])\n    _ = p.support.sum fun i : \u2115 => f s ^ p.natDegree * (f (p.coeff i) * r ^ i) :=\n      (Finset.sum_congr rfl fun i hi =>\n        by\n        rw [mul_assoc, mul_left_comm, tsub_add_cancel_of_le]\n        exact le_natDegree_of_ne_zero (Polynomial.mem_support_iff.mp hi))\n    _ = f s ^ p.natDegree * p.support.sum fun i : \u2115 => f (p.coeff i) * r ^ i := Finset.mul_sum.symm\n    _ = f s ^ p.natDegree * eval\u2082 f r p := by simp [eval\u2082_eq_sum, sum_def]\n    \n#align polynomial.scale_roots_eval\u2082_mul Polynomial.scaleRoots_eval\u2082_mul\n\ntheorem scaleRoots_eval\u2082_eq_zero {p : S[X]} (f : S \u2192+* R) {r : R} {s : S} (hr : eval\u2082 f r p = 0) :\n    eval\u2082 f (f s * r) (scaleRoots p s) = 0 := by rw [scaleRoots_eval\u2082_mul, hr, mul_zero]\n#align polynomial.scale_roots_eval\u2082_eq_zero Polynomial.scaleRoots_eval\u2082_eq_zero\n\ntheorem scaleRoots_aeval_eq_zero [Algebra S R] {p : S[X]} {r : R} {s : S} (hr : aeval r p = 0) :\n    aeval (algebraMap S R s * r) (scaleRoots p s) = 0 :=\n  scaleRoots_eval\u2082_eq_zero (algebraMap S R) hr\n#align polynomial.scale_roots_aeval_eq_zero Polynomial.scaleRoots_aeval_eq_zero\n\ntheorem scaleRoots_eval\u2082_eq_zero_of_eval\u2082_div_eq_zero {p : A[X]} {f : A \u2192+* K}\n    (hf : Function.Injective f) {r s : A} (hr : eval\u2082 f (f r / f s) p = 0)\n    (hs : s \u2208 nonZeroDivisors A) : eval\u2082 f (f r) (scaleRoots p s) = 0 := by\n  convert @scaleRoots_eval\u2082_eq_zero _ _ _ _ p f _ s hr\n  rw [\u2190 mul_div_assoc, mul_comm, mul_div_cancel]\n  exact map_ne_zero_of_mem_nonZeroDivisors _ hf hs\n#align polynomial.scale_roots_eval\u2082_eq_zero_of_eval\u2082_div_eq_zero Polynomial.scaleRoots_eval\u2082_eq_zero_of_eval\u2082_div_eq_zero\n\ntheorem scaleRoots_aeval_eq_zero_of_aeval_div_eq_zero [Algebra A K]\n    (inj : Function.Injective (algebraMap A K)) {p : A[X]} {r s : A}\n    (hr : aeval (algebraMap A K r / algebraMap A K s) p = 0) (hs : s \u2208 nonZeroDivisors A) :\n    aeval (algebraMap A K r) (scaleRoots p s) = 0 :=\n  scaleRoots_eval\u2082_eq_zero_of_eval\u2082_div_eq_zero inj hr hs\n#align polynomial.scale_roots_aeval_eq_zero_of_aeval_div_eq_zero Polynomial.scaleRoots_aeval_eq_zero_of_aeval_div_eq_zero\n\ntheorem map_scaleRoots (p : R[X]) (x : R) (f : R \u2192+* S) (h : f p.leadingCoeff \u2260 0) :\n    (p.scaleRoots x).map f = (p.map f).scaleRoots (f x) := by\n  ext\n  simp [Polynomial.natDegree_map_of_leadingCoeff_ne_zero _ h]\n#align polynomial.map_scale_roots Polynomial.map_scaleRoots\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/Polynomial/ScaleRoots.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7114395209616321}}
{"text": "import data.nat.prime\nimport tactic.linarith\n\nopen nat\n\ntheorem infinitude_of_primes : \u2200 N, \u2203 p \u2265 N, prime p :=\nbegin\n  intro N,\n\n  let M := fact N + 1,\n  let p := min_fac M,\n\n  have pp : prime p :=\n  begin\n    refine min_fac_prime _,\n    have : fact N > 0 := fact_pos N,\n    linarith,\n  end,\n\n  use p,\n  split,\n  { by_contradiction,\n    have h\u2081 : p \u2223 fact N + 1 := min_fac_dvd M,\n    have h\u2082 : p \u2223 fact N := (prime.dvd_fact pp).mpr (le_of_not_ge a),\n    have h : p \u2223 1 := (nat.dvd_add_right h\u2082).mp h\u2081,\n    exact prime.not_dvd_one pp h, },\n  { exact pp, },\nend\n\n------------------------------------------------------------------------\n-- \u00a7 Referencia                                                       --\n------------------------------------------------------------------------\n\n-- Basado en la presentaci\u00f3n \"Infinitude of primes: a Lean theorem\n-- prover demo\" de Scott Morrison que se encuentra en\n-- https://youtu.be/b59fpAJ8Mfs  \n", "meta": {"author": "jaalonso", "repo": "Lean_para_matematicos", "sha": "924c77b7f010604b84f82d2f79967ad8b9cddc6e", "save_path": "github-repos/lean/jaalonso-Lean_para_matematicos", "path": "github-repos/lean/jaalonso-Lean_para_matematicos/Lean_para_matematicos-924c77b7f010604b84f82d2f79967ad8b9cddc6e/src/Primos/Infinitud_de_los_primos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693659780477, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.7113851787409261}}
{"text": "import Mathlib.Init.Data.Nat.Basic\nimport Mathlib.Init.Data.Int.Basic\n/-!\n## Types and Terms\n\n_Simple type theory_ (also called higher-order logic) corresponds roughly to the\n[simply typed \u03bb-calculus](../bib.md#5) extended with an equality operator (=). It is an abstract,\nextremely simplified version of a programming language with a function-calling\nmechanism that prefigures functional programming. It can also be viewed as a\ngeneralization of first-order logic (also called predicate logic).\n\n### Types\n\nTypes are either basic types such as `\u2124`, `\u211a`, and bool or total functions `\u03c3 \u2192 \u03c4`, where\n`\u03c3` and `\u03c4` are themselves types. Types indicate which values an expression may\nevaluate to. They introduce a discipline that is followed somewhat implicitly in\nmathematics. In principle, nothing prevents a mathematician from stating `1 \u2208 2`,\nbut a typing discipline would mark this as the error it likely is.\n\nSemantically, types can be viewed as sets. We would normally define the types\n`\u2124`, `\u211a`, and `bool` so that they faithfully capture the mathematicians\u2019 `\u2124` and `\u211a` and\nthe computer scientists\u2019 Booleans, and similarly for the function arrow (`\u2192`). But\ndespite their similarities, Lean and mathematics are distinct languages. Lean\u2019s\ntypes may be interpreted as sets, but they are not sets.\n\nHigher-order types are types containing left-nested `\u2192` arrows. Values of such\ntypes are functions that take other functions as arguments. Accordingly, the type\n`(\u2124 \u2192 \u2124) \u2192 \u211a`  is the type of unary functions that take a function of type `\u2124 \u2192 \u2124` as\nargument and that return a value of type `\u211a`.\n\n### Terms\n\nThe _terms_, or expressions, of simple type theory consist of\n\n- _constants_ c;\n- _variables_ x;\n- _applications_ t u;\n- _\u03bb-expressions_ \u03bbx => t.\n\nAbove, `t` and `u` denote arbitrary terms. We can also write `t : \u03c3` to indicate that the\nterm `t` has the type `\u03c3`.\n\nA constant `c : \u03c3` is a symbol of type `\u03c3` whose meaning is fixed in the current\nglobal context. For example, an arithmetic theory might contain constants such\nas `0 : \u2124`, `1 : \u2124`, `abs : \u2124 \u2192 \u2115`, `square : \u2115 \u2192 \u2115`, and `prime : \u2115 \u2192 Bool`. Constants\ninclude functions (e.g., `abs`) and predicates (e.g., `prime`).\n\nA variable `x : \u03c3` is either bound or free. A bound variable refers back to the\ninput of a \u03bb-expression `\u03bb x : \u03c3 => t` enclosing it. In `\u03bb x : \u2124 => square (abs x)`\nthe second `x` is a variable that refers back to the \u03bb binder\u2019s input `x`. By contrast, a free\nvariable is declared in the local context&mdash;a concept that will be explained below.\n\nAn application `t u`, where `t : \u03c3 \u2192 \u03c4` and `u : \u03c3`, is a term of type `\u03c4` denoting the\nresult of applying the function `t` to the argument `u`\u2014e.g., `abs 0`. No parentheses\nare needed around the argument, unless it is a complex term\u2014e.g., `prime (abs 0)`.\n\nGiven a term `t : \u03c4`, a \u03bb-expression `\u03bb x : \u03c3 => t` denotes the total function of type\n`\u03c3 \u2192 \u03c4` that maps each input value `x` of type `\u03c3` to the function body `t`, where `t` may\ncontain `x`. For example, `\u03bb x : \u2124 => square (abs x)` denotes the function that maps\n(the value denoted by) `0` to (the value denoted by) `square (abs 0)`, that maps `1` to\n`square (abs 1)`, and so on. A more intuitive syntax might have been\n`x \u21a6 square (abs x)`, but this is not supported by Lean.\n\nApplications and \u03bb-expressions mirror each other: A \u03bb-expression \u201cbuilds\u201d a\nfunction; an application \u201cdestructs\u201d a function. Although our functions are unary\n(i.e., they take one argument), we can build _n_-ary functions by nesting \u03bbs, using\nan ingenious technique called _currying_. For example, `\u03bb x : \u03c3 => (\u03bb y : \u03c4 => x)` denotes\nthe function of type `\u03c3 \u2192 (\u03c4 \u2192 \u03c3)` that takes two arguments and returns the first\none. Strictly speaking, `\u03c3 \u2192 (\u03c4 \u2192 \u03c3)` takes a single argument and returns a function,\nwhich in turn takes an argument. Applications work in the same way: If\n`K := (\u03bbx : \u2124 => (\u03bb y : Z => x))`, then `K 1 = (\u03bb y : Z => 1)` and `(K 1) 0 = 1`.\nThe function `K` in `K 1`, which is applied to a single argument, is said to be _partially applied_.\n\nCurrying is so useful a concept that we will omit most parentheses, writing\n\n- `\u03c3 \u2192 \u03c4 \u2192 \u03c5` for `\u03c3 \u2192 (\u03c4 \u2192 \u03c5)`\n- `t u v` for `(t u) v`\n- `\u03bb x : \u03c3 => \u03bb y : \u03c4 => t` for `\u03bb x : \u03c3 => `(\u03bb y : \u03c4 => t)`\n\nand also\n\n- `\u03bb (x : \u03c3) (y : \u03c4) => t` for `\u03bb x : \u03c3 => \u03bb y : \u03c4 => t`\n- `\u03bb x y : \u03c3 => t` for `\u03bb (x : \u03c3) (y : \u03c3) => t`\n\nIn mathematics, it is customary to write binary operators in infix syntax\u2014e.g.,\n`x + y`. Such notations are also possible in Lean, as syntactic sugar for `Add.add x y`.\nPartial application is possible with this syntax. For example,  `Add.add 1`\ndenotes the unary function that adds one to its argument. Other ways to write\nthis function are `\u03bb x => Add.add 1 x` and `\u03bb x => 1 + x`.\n\nNo we can move some of this into the Lean language, declaring some simple\ntyped values and functions using the `def` command as follows:\n-/\n-- These are defined in Mathlib:\n-- notation \"\u2124\" => Int   -- associates the notation \u2124 with Integer type.\n-- notation \"\u2115\" => Nat   -- associates the notation \u2115 with Nat type for natural numbers.\n\ndef a : \u2124 := 1\ndef b : \u2124 := 2\ndef f : \u2124 \u2192 \u2124  := \u03bb x => x + 1\ndef g : \u2124 \u2192 \u2124 \u2192 \u2124 := \u03bb x y => x + y\n\n#check \u03bb x : \u2124 => g (f (g a x)) (g x b)   -- \u2124 \u2192 \u2124\n#check \u03bb x => g (f (g a x)) (g x b)       -- \u2124 \u2192 \u2124\n\n/-!\nThe first two lines declare tow constants (a, b), both of type Integer with\nthe respective value of 1 and 2.  The definition for `f` defines a funciton\nof type `\u2124 \u2192 \u2124` implemented by a lambda expression that adds 1 to its argument.\nThe definition for `g` defines a function of type `\u2124 \u2192 \u2124 \u2192 \u2124` implemented by a\nlambda expression that takes two arguments and adds them together.\n\nThe last two lines use the `#check` command to type-check some terms and\nshow their types. The # prefix identifies interactive commands: commands that are\nuseful for debugging but that we would normally not keep in a Lean program.\n\nThe `abbrev` command can be used to define a new name for an existing type:\n-/\nabbrev foo := Int\n\n#check foo -- foo : Type\n\n#check (5 : foo)    -- 5 : foo\n\n#reduce (5 : foo)   -- Int.ofNat 5\n/-!\nHere we see that `foo` is a `Type` and it is synonymous for the type `Int`.\n\n### Type Checking and Type Inference\n\nWhen Lean parses a term, it checks whether the term is well typed. In the process,\nit tries to infer the types of bound variables if those are omitted\u2014e.g., the type of\n`x` in `\u03bb x => 1 + x`. Type inference lightens notations and saves some typing.\n\nFor simple type theory, type checking and type inference are decidable problems.\nAdvanced features such as overloading (the possibility to reuse the same\nname for several constants\u2014e.g., `0 : \u2115`  and `0 : \u211d`) can lead to [undecidability](../bib.md#30).\nLean takes a pragmatic, computer-science-oriented approach and assumes that\nnumerals `0, 1, 2, . . .` are of type `Nat` if several types are possible.\n\nLean\u2019s type system can be expressed as a formal system. A formal system\nconsists of judgments and of (derivation) rules for producing judgments. A typing\njudgment has the form `C \u22a2 t : \u03c3`, meaning that term `t` has type `\u03c3` in local context `C`.\nThe local context gives the types of the variables in `t` that are not bound by a `\u03bb`.\nThe local context is used to keep track of the variables bound by \u03bb\u2019s outside `t`.\nFor a function definition, it will consist of the function\u2019s parameters. For example,\nin Lean, the right-hand side of the last equation of fib\u2019s above would be type-checked\nin a local context consisting of `n : \u2115`.\n\nFor simple type theory, there are four typing rules, one per kind of term:\n\n\\\\( \\cfrac{}{C \u22a2 c : \u03c3} {\\large C}{\\normalsize ST} \\quad\u2001\\\\text{if c is declared with type \u03c3 } \\\\)\n\n\\\\( \\cfrac{}{C \u22a2 x : \u03c3} {\\large V}{\\normalsize AR} \\quad\u2001\\\\text{if x : \u03c3 is the last occurrence of x in C } \\\\)\n\n\\\\( \\cfrac{C \u22a2 t : \u03c3 \u2192 \u03c4 \\quad C \u22a2 u : \u03c3 }{C \u22a2 t\\enspace{u} : \u03c4} {\\large A}{\\normalsize PP} \\\\)\n\n\\\\( \\cfrac{C, x : \u03c3 \u22a2 t : \u03c4 }{C \u22a2 (\u03bb\\enspace{x} : \u03c3 => t) : \u03c3 \u2192 \u03c4} {\\large L}{\\normalsize AM} \\\\)\n\nEach rule has zero or more premises (above the horizontal bar), a conclusion\n(below the bar), and possibly a side condition. The premises are typing judgments,\nwhereas the side conditions are arbitrary mathematical conditions on the mathematical\nvariables occurring in the rule. To discharge the premises, we need to\ncontinue performing a derivation upward, as we will see in a moment. As for the\nside conditions, we can use the entire arsenal of mathematics to show that they\nare true.\n\nThe first two rules, labeled `CST` and `VAR`, have no premises, but they have side\nconditions that must be satisfied for the rules to apply. The last two rules take\none or two judgments as premises and produce a new judgment. `LAM` is the only\nrule that modifies the local context: As we enter the body `t` of a \u03bb-expression, we\nneed to record the existence of the bound variable `x` and its type to be ready when\nwe meet `x` in `t`\n\nWe can use this rule system to prove that a given term is well typed by working our way backwards\n(i.e., upwards) and applying the rules, building a formal derivation of a typing judgment. Like\nnatural trees, derivation trees are drawn with the root at the bottom. The derived judgment appears\nat the root, and each branch ends with the application of a premise-less rule. Rule applications are\nindicated by a horizontal bar and a label. The following typing derivation establishes that the term\n`\u03bb x : \u2124 => abs x` has type `\u2124 \u2192 \u2115`  in an arbitrary local context `C`:\n\n\\\\( \\cfrac{ \\cfrac{}{C, x : \u2124 \u22a2 abs : \u2124 \u2192 \u2115} {\\large C}{\\normalsize ST} \\quad\u2001\\cfrac{}{C, x : \u2124 \u22a2 x : \u2124 } {\\large V}{\\normalsize AR}} { \\cfrac{C, x : \u2124 \u22a2 abs\\enspace{x} : \u2115}{C \u22a2 (\u03bb\\enspace{x} : \u2124 => abs\\enspace{x}): \u2124 \u2192 \u2115} {\\large C}{\\normalsize ST} } {\\large A}{\\normalsize PP}\\\\)\n\nReading the proof from the root upwards, notice how the local context is threaded\nthrough and how it is extended by the `LAM` rule. The rule moves the variable bound\nby the \u03bb-expression to the local context, making an application of `VAR` possible\nfurther up the tree. If the variable `x` is already declared in `C`, it becomes shadowed\nby `x : \u2124` after entering the \u03bb-expression.\n\nThe above type system only checks that terms are well typed. It does not check\nthat types are well formed. For example, `List \u2124`  is well formed, whereas `\u2124 List`\nand `List List` are ill-formed. For simple type theory, well-formedness is easy\nto check: Only declared type constructors should be used, and each _n_-ary type\nconstructor should be passed exactly _n_ type arguments.\n\nAs a side note, type inference is a generalization of type checking where the\ntypes on the right-hand side of the colon (`:`) in judgments may be replaced by\nplaceholders. Lean\u2019s type inference is based on an algorithm due to [Hindley](../bib.md#15)\nand [Milner](../bib.md#25), which also forms the basis of Haskell, OCaml, and Standard ML.\nThe algorithm generates type constraints involving type variables `?\u03b1, ?\u03b2, ?\u03b3, . . .`,\nand attempts to solve them using a type unification procedure. For example, when\ninferring the type `?\u03b1` of `\u03bb x => abs x`, Lean would perform the following schematic\ntype derivation:\n\n\\\\( \\cfrac{ \\cfrac{}{x :\\thinspace{?\u03b2} \u22a2 abs :\\thinspace{?\u03b2} \u2192 \u03b3} {\\large C}{\\normalsize ST} \\quad\u2001\\cfrac{}{x :\\thinspace{?\u03b2} \u22a2 x :\\thinspace{?\u03b2}} {\\large V}{\\normalsize AR}} { \\cfrac{x :\\thinspace{?\u03b2} \u22a2 abs\\enspace{x}:\\thinspace{?\u03b3}}{\u22a2 (\u03bb\\enspace{x} => abs\\enspace{x}) :\\thinspace{?\u03b1}} {\\large C}{\\normalsize ST} } {\\large A}{\\normalsize PP}\\\\)\n\nIn addition, Lean would generate the following constraints to ensure that all the\nrule applications are legal:\n\n1. For the application of `LAM`, the type of `\u03bb x => abs x` must be of the form `?\u03b2 \u2192 ?\u03b3`,\nfor some types `?\u03b2` and `?\u03b3`. Thus, Lean would generate the constraint `?\u03b1 = ?\u03b2 \u2192 ?\u03b3`\n2. For the application of `CST`, the type of `abs` must correspond to the declaration as `\u2124 \u2192 \u2115`.\nThus, Lean would generate the constraint `?\u03b2 \u2192 ?\u03b3 = \u2124 \u2192 \u2115`\n\nSolving the two constraints yields `?\u03b1 := \u2124 \u2192 \u2115`, which is indeed the type that Lean\ninfers for `\u03bb x => abs x`.\n\n### Type Inhabitation\n\nGiven a type `\u03c3`, the type inhabitation problem consists of finding an \u201cinhabitant\u201d\nof that type\u2014a term of type `\u03c3`\u2014within the empty local context. It may seem like a\npointless exercise, but as we will see in Chapter 3, this problem is closely related\nto that of finding a proof of a proposition. Seemingly silly exercises of the form\n\u201cfind a term of type `\u03c3`\u201d are good practice towards mastery of theorem proving.\n\nTo create a term of a given type, start with the placeholder _ and recursively\napply a combination of the following two steps:\n\n1. If the type is of the form `\u03c3 \u2192 \u03c4`, a possible inhabitant is an anonymous function,\nof the form `\u03bb x : \u03c3 => _`, where `_` is a placeholder for a missing term of\ntype `\u03c4`. Lean will mark `_` as an error; if you hover over it in Visual Studio\nCode, a tooltip will show the missing term\u2019s type as well as any variables\ndeclared in the local context.\n\n2. Given a type `\u03c3` (which may be a function type), you can use any constant `c`\nor variable `x : \u03c4\u2081 \u2192 \u00b7 \u00b7 \u00b7 \u2192 \u03c4\u2099 \u2192 \u03c3` to build a term of that type. For each\nargument, you need to put a placeholder, yielding `c _ . . . _` or `x _ . . . _`\n\nThe placeholders can be eliminated recursively using the same procedure.\nAs an example, we will apply the procedure to find a term of type\n`(\u03b1 \u2192 \u03b2 \u2192 \u03b3) \u2192 ((\u03b2 \u2192 \u03b1) \u2192 \u03b2) \u2192 \u03b1 \u2192 \u03b3`.\n\nInitially, only step 1 is applicable, with `\u03c3 := \u03b1 \u2192 \u03b2 \u2192 \u03b3` and `\u03c4 := ((\u03b2 \u2192 \u03b1) \u2192 \u03b2) \u2192 \u03b1 \u2192 \u03b3`.\n(Recall that `\u2192` is right-associative: `\u03c3 \u2192 \u03c4 \u2192 \u03c5` stands for `\u03c3 \u2192 (\u03c4 \u2192 \u03c5)`.)\nThis results in the term `\u03bb f => _`, which has the right type but has a placeholder left.\nSince the argument `f` has type `\u03c3`, a function type, it makes sense to use the name\n`f` for it. Then we continue recursively with the placeholder, of type `\u03c4`. Again, only\nstep 1 is possible, so we end up with the term `\u03bb f => \u03bb g => _`, where `g` has type\n`(\u03b2 \u2192 \u03b1) \u2192 \u03b2` and the placeholder has type `\u03b1 \u2192 \u03b3`. A third application of step 1 yields\n`\u03bb f => \u03bb g => \u03bb a => _`, where `a` has type `\u03b1` and the placeholder has type `\u03b3`.\n\nAt this point, step 1 is no longer possible. Let us see if step 2 is applicable. The\ncontext surrounding the placeholder contains the following variables:\n```lean\nf : \u03b1 \u2192 \u03b2 \u2192 \u03b3\ng : (\u03b2 \u2192 \u03b1) \u2192 \u03b2\na : \u03b1\n```\n\nRecall that we are trying to build a term of type `\u03b3`. The only variable we can use\nto achieve this is `f`: It takes two arguments and returns a value of type `\u03b3`. So\nwe replace the placeholder with the term `f _ _`, where the two new placeholders\nstand for the two missing arguments. Putting everything together, we now have\nthe term `\u03bb f => \u03bb g => \u03bb a => f _ _`.\n\nFollowing f\u2019s type, the placeholders are of type `\u03b1` and `\u03b2`, respectively. The first\nplaceholder is easy to fill, using step 2 again, by simply supplying `a`, of type `\u03b1`, with\nno arguments. For the second placeholder, we apply step 2 with the variable `g`,\nwhich is the only source of \u03b2s. Since `g` takes an argument, we must supply a\nplaceholder. This means our current term is `\u03bb f => \u03bb g => \u03bb a => f a (g _)`.\n\nWe are almost done. The only placeholder left has type `\u03b2 \u2192 \u03b1`, which is g\u2019s\nargument type. Applying step 1, we replace the placeholder with `\u03bb b => _`, where `_`\nhas type `\u03b1`. Here, we can simply supply `a`. Our final term is\n`\u03bb f => \u03bb g => \u03bb a => f a (g (\u03bb b => a))`\u2014i.e., `\u03bb f g a => f a (g (\u03bb b => a))`.\n\nThe above derivation was tedious but deterministic: At each point, either step\n1 or 2 was applicable, but not both. In general, this will not always be the case.\nFor some other types, we might encounter dead ends and need to backtrack. We\nmight also fail altogether, with nowhere to backtrack to. Notably, with an empty\nlocal context, it is impossible to supply a witness for `\u03b1`.\n\nThe key idea is that the term should be syntactically correct at all times. The\nonly red underlining we should see in Visual Studio Code should appear under the\nplaceholders. In general, a good principle for software development is to start\nwith a program that compiles, perform the smallest change possible to obtain a\nnew compiling program, and repeat until the program is complete.\n-/", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/Basics/TypesAndTerms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7113778389579014}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\nSome proofs and docs came from `algebra/commute` (c) Neil Strickland\n\n! This file was ported from Lean 3 source module algebra.group.semiconj\n! leanprover-community/mathlib commit a148d797a1094ab554ad4183a4ad6f130358ef64\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Units\n\n/-!\n# Semiconjugate elements of a semigroup\n\n## Main definitions\n\nWe say that `x` is semiconjugate to `y` by `a` (`SemiconjBy a x y`), if `a * x = y * a`.\nIn this file we provide operations on `SemiconjBy _ _ _`.\n\nIn the names of these operations, we treat `a` as the \u201cleft\u201d argument, and both `x` and `y` as\n\u201cright\u201d arguments. This way most names in this file agree with the names of the corresponding lemmas\nfor `Commute a b = SemiconjBy a b b`. As a side effect, some lemmas have only `_right` version.\n\nLean does not immediately recognise these terms as equations, so for rewriting we need syntax like\n`rw [(h.pow_right 5).eq]` rather than just `rw [h.pow_right 5]`.\n\nThis file provides only basic operations (`mul_left`, `mul_right`, `inv_right` etc). Other\noperations (`pow_right`, field inverse etc) are in the files that define corresponding notions.\n-/\n\n/-- `x` is semiconjugate to `y` by `a`, if `a * x = y * a`. -/\n@[to_additive AddSemiconjBy \"`x` is additive semiconjugate to `y` by `a` if `a + x = y + a`\"]\ndef SemiconjBy [Mul M] (a x y : M) : Prop :=\n  a * x = y * a\n#align semiconj_by SemiconjBy\n#align add_semiconj_by AddSemiconjBy\n\nnamespace SemiconjBy\n\n/-- Equality behind `SemiconjBy a x y`; useful for rewriting. -/\n@[to_additive \"Equality behind `AddSemiconjBy a x y`; useful for rewriting.\"]\nprotected theorem eq [Mul S] {a x y : S} (h : SemiconjBy a x y) : a * x = y * a :=\n  h\n#align semiconj_by.eq SemiconjBy.eq\n#align add_semiconj_by.eq AddSemiconjBy.eq\n\nsection Semigroup\n\nvariable [Semigroup S] {a b x y z x' y' : S}\n\n/-- If `a` semiconjugates `x` to `y` and `x'` to `y'`,\nthen it semiconjugates `x * x'` to `y * y'`. -/\n@[to_additive (attr := simp) \"If `a` semiconjugates `x` to `y` and `x'` to `y'`,\nthen it semiconjugates `x + x'` to `y + y'`.\"]\ntheorem mul_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') :\n    SemiconjBy a (x * x') (y * y') := by\n  unfold SemiconjBy\n  -- TODO this could be done using `assoc_rw` if/when this is ported to mathlib4\n  rw [\u2190mul_assoc, h.eq, mul_assoc, h'.eq, \u2190mul_assoc]\n#align semiconj_by.mul_right SemiconjBy.mul_right\n#align add_semiconj_by.add_right AddSemiconjBy.add_right\n\n/-- If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a * b`\nsemiconjugates `x` to `z`. -/\n@[to_additive \"If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a + b`\nsemiconjugates `x` to `z`.\"]\ntheorem mul_left (ha : SemiconjBy a y z) (hb : SemiconjBy b x y) : SemiconjBy (a * b) x z := by\n  unfold SemiconjBy\n  rw [mul_assoc, hb.eq, \u2190mul_assoc, ha.eq, mul_assoc]\n#align semiconj_by.mul_left SemiconjBy.mul_left\n#align add_semiconj_by.add_left AddSemiconjBy.add_left\n\n/-- The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on a semigroup\nis transitive. -/\n@[to_additive \"The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on an additive\nsemigroup is transitive.\"]\nprotected theorem transitive : Transitive fun a b : S \u21a6 \u2203 c, SemiconjBy c a b\n  | _, _, _, \u27e8x, hx\u27e9, \u27e8y, hy\u27e9 => \u27e8y * x, hy.mul_left hx\u27e9\n#align semiconj_by.transitive SemiconjBy.transitive\n#align add_semiconj_by.transitive SemiconjBy.transitive\n\nend Semigroup\n\nsection MulOneClass\n\nvariable [MulOneClass M]\n\n/-- Any element semiconjugates `1` to `1`. -/\n@[to_additive (attr := simp) \"Any element semiconjugates `0` to `0`.\"]\ntheorem one_right (a : M) : SemiconjBy a 1 1 := by rw [SemiconjBy, mul_one, one_mul]\n#align semiconj_by.one_right SemiconjBy.one_right\n#align add_semiconj_by.zero_right AddSemiconjBy.zero_right\n\n/-- One semiconjugates any element to itself. -/\n@[to_additive (attr := simp) \"Zero semiconjugates any element to itself.\"]\ntheorem one_left (x : M) : SemiconjBy 1 x x :=\n  Eq.symm <| one_right x\n#align semiconj_by.one_left SemiconjBy.one_left\n#align add_semiconj_by.zero_left AddSemiconjBy.zero_left\n\n/-- The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on a monoid (or, more\ngenerally, on `MulOneClass` type) is reflexive. -/\n@[to_additive \"The relation \u201cthere exists an element that semiconjugates `a` to `b`\u201d on an additive\nmonoid (or, more generally, on a `AddZeroClass` type) is reflexive.\"]\nprotected theorem reflexive : Reflexive fun a b : M \u21a6 \u2203 c, SemiconjBy c a b\n  | a => \u27e81, one_left a\u27e9\n#align semiconj_by.reflexive SemiconjBy.reflexive\n#align add_semiconj_by.reflexive AddSemiconjBy.reflexive\n\nend MulOneClass\n\nsection Monoid\n\nvariable [Monoid M]\n\n/-- If `a` semiconjugates a unit `x` to a unit `y`, then it semiconjugates `x\u207b\u00b9` to `y\u207b\u00b9`. -/\n@[to_additive \"If `a` semiconjugates an additive unit `x` to an additive unit `y`, then it\nsemiconjugates `-x` to `-y`.\"]\ntheorem units_inv_right {a : M} {x y : M\u02e3} (h : SemiconjBy a x y) : SemiconjBy a \u2191x\u207b\u00b9 \u2191y\u207b\u00b9 :=\n  calc\n    a * \u2191x\u207b\u00b9 = \u2191y\u207b\u00b9 * (y * a) * \u2191x\u207b\u00b9 := by rw [Units.inv_mul_cancel_left]\n    _        = \u2191y\u207b\u00b9 * a              := by rw [\u2190 h.eq, mul_assoc, Units.mul_inv_cancel_right]\n#align semiconj_by.units_inv_right SemiconjBy.units_inv_right\n#align add_semiconj_by.add_units_neg_right AddSemiconjBy.addUnits_neg_right\n\n@[to_additive (attr := simp)]\ntheorem units_inv_right_iff {a : M} {x y : M\u02e3} : SemiconjBy a \u2191x\u207b\u00b9 \u2191y\u207b\u00b9 \u2194 SemiconjBy a x y :=\n  \u27e8units_inv_right, units_inv_right\u27e9\n#align semiconj_by.units_inv_right_iff SemiconjBy.units_inv_right_iff\n#align add_semiconj_by.add_units_neg_right_iff AddSemiconjBy.addUnits_neg_right_iff\n\n/-- If a unit `a` semiconjugates `x` to `y`, then `a\u207b\u00b9` semiconjugates `y` to `x`. -/\n@[to_additive \"If an additive unit `a` semiconjugates `x` to `y`, then `-a` semiconjugates `y` to\n`x`.\"]\ntheorem units_inv_symm_left {a : M\u02e3} {x y : M} (h : SemiconjBy (\u2191a) x y) : SemiconjBy (\u2191a\u207b\u00b9) y x :=\n  calc\n    \u2191a\u207b\u00b9 * y = \u2191a\u207b\u00b9 * (y * a * \u2191a\u207b\u00b9) := by rw [Units.mul_inv_cancel_right]\n    _ = x * \u2191a\u207b\u00b9 := by rw [\u2190 h.eq, \u2190 mul_assoc, Units.inv_mul_cancel_left]\n#align semiconj_by.units_inv_symm_left SemiconjBy.units_inv_symm_left\n#align add_semiconj_by.add_units_neg_symm_left AddSemiconjBy.addUnits_neg_symm_left\n\n@[to_additive (attr := simp)]\ntheorem units_inv_symm_left_iff {a : M\u02e3} {x y : M} : SemiconjBy (\u2191a\u207b\u00b9) y x \u2194 SemiconjBy (\u2191a) x y :=\n  \u27e8units_inv_symm_left, units_inv_symm_left\u27e9\n#align semiconj_by.units_inv_symm_left_iff SemiconjBy.units_inv_symm_left_iff\n#align add_semiconj_by.add_units_neg_symm_left_iff AddSemiconjBy.addUnits_neg_symm_left_iff\n\n@[to_additive]\ntheorem units_val {a x y : M\u02e3} (h : SemiconjBy a x y) : SemiconjBy (a : M) x y :=\n  congr_arg Units.val h\n#align semiconj_by.units_coe SemiconjBy.units_val\n#align add_semiconj_by.add_units_coe AddSemiconjBy.addUnits_val\n\n@[to_additive]\ntheorem units_of_val {a x y : M\u02e3} (h : SemiconjBy (a : M) x y) : SemiconjBy a x y :=\n  Units.ext h\n#align semiconj_by.units_of_coe SemiconjBy.units_of_val\n#align add_semiconj_by.add_units_of_coe AddSemiconjBy.addUnits_of_val\n\n@[to_additive (attr := simp)]\ntheorem units_val_iff {a x y : M\u02e3} : SemiconjBy (a : M) x y \u2194 SemiconjBy a x y :=\n  \u27e8units_of_val, units_val\u27e9\n#align semiconj_by.units_coe_iff SemiconjBy.units_val_iff\n#align add_semiconj_by.add_units_coe_iff AddSemiconjBy.addUnits_val_iff\n\n@[to_additive (attr := simp)]\ntheorem pow_right {a x y : M} (h : SemiconjBy a x y) (n : \u2115) : SemiconjBy a (x ^ n) (y ^ n) := by\n  induction' n with n ih\n  \u00b7 rw [pow_zero, pow_zero]\n    exact SemiconjBy.one_right _\n  \u00b7 rw [pow_succ, pow_succ]\n    exact h.mul_right ih\n#align semiconj_by.pow_right SemiconjBy.pow_right\n#align add_semiconj_by.nsmul_right AddSemiconjBy.nsmul_right\n\nend Monoid\n\nsection DivisionMonoid\n\nvariable [DivisionMonoid G] {a x y : G}\n\n@[to_additive (attr := simp)]\ntheorem inv_inv_symm_iff : SemiconjBy a\u207b\u00b9 x\u207b\u00b9 y\u207b\u00b9 \u2194 SemiconjBy a y x :=\n  inv_involutive.injective.eq_iff.symm.trans <| by\n    rw [mul_inv_rev, mul_inv_rev, inv_inv, inv_inv, inv_inv, eq_comm, SemiconjBy]\n#align semiconj_by.inv_inv_symm_iff SemiconjBy.inv_inv_symm_iff\n#align add_semiconj_by.neg_neg_symm_iff AddSemiconjBy.neg_neg_symm_iff\n\n@[to_additive]\n\n\nend DivisionMonoid\n\nsection Group\n\nvariable [Group G] {a x y : G}\n\n@[to_additive (attr := simp)]\ntheorem inv_right_iff : SemiconjBy a x\u207b\u00b9 y\u207b\u00b9 \u2194 SemiconjBy a x y :=\n  @units_inv_right_iff G _ a \u27e8x, x\u207b\u00b9, mul_inv_self x, inv_mul_self x\u27e9\n    \u27e8y, y\u207b\u00b9, mul_inv_self y, inv_mul_self y\u27e9\n#align semiconj_by.inv_right_iff SemiconjBy.inv_right_iff\n#align add_semiconj_by.neg_right_iff AddSemiconjBy.neg_right_iff\n\n@[to_additive]\ntheorem inv_right : SemiconjBy a x y \u2192 SemiconjBy a x\u207b\u00b9 y\u207b\u00b9 :=\n  inv_right_iff.2\n#align semiconj_by.inv_right SemiconjBy.inv_right\n#align add_semiconj_by.neg_right AddSemiconjBy.neg_right\n\n@[to_additive (attr := simp)]\ntheorem inv_symm_left_iff : SemiconjBy a\u207b\u00b9 y x \u2194 SemiconjBy a x y :=\n  @units_inv_symm_left_iff G _ \u27e8a, a\u207b\u00b9, mul_inv_self a, inv_mul_self a\u27e9 _ _\n#align semiconj_by.inv_symm_left_iff SemiconjBy.inv_symm_left_iff\n#align add_semiconj_by.neg_symm_left_iff AddSemiconjBy.neg_symm_left_iff\n\n@[to_additive]\ntheorem inv_symm_left : SemiconjBy a x y \u2192 SemiconjBy a\u207b\u00b9 y x :=\n  inv_symm_left_iff.2\n#align semiconj_by.inv_symm_left SemiconjBy.inv_symm_left\n#align add_semiconj_by.neg_symm_left AddSemiconjBy.neg_symm_left\n\n/-- `a` semiconjugates `x` to `a * x * a\u207b\u00b9`. -/\n@[to_additive \"`a` semiconjugates `x` to `a + x + -a`.\"]\ntheorem conj_mk (a x : G) : SemiconjBy a x (a * x * a\u207b\u00b9) := by\n  unfold SemiconjBy; rw [mul_assoc, inv_mul_self, mul_one]\n#align semiconj_by.conj_mk SemiconjBy.conj_mk\n#align add_semiconj_by.conj_mk AddSemiconjBy.conj_mk\n\nend Group\n\nend SemiconjBy\n\n@[to_additive (attr := simp) addSemiconjBy_iff_eq]\ntheorem semiconjBy_iff_eq [CancelCommMonoid M] {a x y : M} : SemiconjBy a x y \u2194 x = y :=\n  \u27e8fun h => mul_left_cancel (h.trans (mul_comm _ _)), fun h => by rw [h, SemiconjBy, mul_comm]\u27e9\n#align semiconj_by_iff_eq semiconjBy_iff_eq\n#align add_semiconj_by_iff_eq addSemiconjBy_iff_eq\n\n/-- `a` semiconjugates `x` to `a * x * a\u207b\u00b9`. -/\n@[to_additive AddUnits.mk_addSemiconjBy \"`a` semiconjugates `x` to `a + x + -a`.\"]\ntheorem Units.mk_semiconjBy [Monoid M] (u : M\u02e3) (x : M) : SemiconjBy (\u2191u) x (u * x * \u2191u\u207b\u00b9) := by\n  unfold SemiconjBy; rw [Units.inv_mul_cancel_right]\n#align units.mk_semiconj_by Units.mk_semiconjBy\n#align add_units.mk_semiconj_by AddUnits.mk_addSemiconjBy\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Group/Semiconj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7113778314184676}}
{"text": "/-\nCopyright (c) 2022 Hanting Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hanting Zhang\n\n! This file was ported from Lean 3 source module linear_algebra.affine_space.pointwise\n! leanprover-community/mathlib commit e96bdfbd1e8c98a09ff75f7ac6204d142debc840\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.LinearAlgebra.AffineSpace.AffineSubspace\n\n/-! # Pointwise instances on `AffineSubspace`s\n\nThis file provides the additive action `AffineSubspace.pointwiseAddAction` in the\n`Pointwise` locale.\n\n-/\n\n\nopen Affine Pointwise\n\nopen Set\n\nnamespace AffineSubspace\n\nvariable {k : Type _} [Ring k]\n\nvariable {V P V\u2081 P\u2081 V\u2082 P\u2082 : Type _}\n\nvariable [AddCommGroup V] [Module k V] [AffineSpace V P]\n\nvariable [AddCommGroup V\u2081] [Module k V\u2081] [AddTorsor V\u2081 P\u2081]\n\nvariable [AddCommGroup V\u2082] [Module k V\u2082] [AddTorsor V\u2082 P\u2082]\n\n/-- The additive action on an affine subspace corresponding to applying the action to every element.\n\nThis is available as an instance in the `Pointwise` locale. -/\nprotected def pointwiseAddAction : AddAction V (AffineSubspace k P) where\n  vadd x S := S.map (AffineEquiv.constVAdd k P x)\n  zero_vadd p := ((congr_arg fun f => p.map f) <| AffineMap.ext <| zero_vadd _).trans p.map_id\n  add_vadd _ _ p :=\n    ((congr_arg fun f => p.map f) <| AffineMap.ext <| add_vadd _ _).trans (p.map_map _ _).symm\n#align affine_subspace.pointwise_add_action AffineSubspace.pointwiseAddAction\n\nscoped[Pointwise] attribute [instance] AffineSubspace.pointwiseAddAction\n\nopen Pointwise\n\n--Porting note: new theorem\ntheorem pointwise_vadd_eq_map (v : V) (s : AffineSubspace k P) :\n    v +\u1d65 s = s.map (AffineEquiv.constVAdd k P v) :=\n  rfl\n\n@[simp]\ntheorem coe_pointwise_vadd (v : V) (s : AffineSubspace k P) :\n    ((v +\u1d65 s : AffineSubspace k P) : Set P) = v +\u1d65 (s : Set P) :=\n  rfl\n#align affine_subspace.coe_pointwise_vadd AffineSubspace.coe_pointwise_vadd\n\ntheorem vadd_mem_pointwise_vadd_iff {v : V} {s : AffineSubspace k P} {p : P} :\n    v +\u1d65 p \u2208 v +\u1d65 s \u2194 p \u2208 s :=\n  vadd_mem_vadd_set_iff\n#align affine_subspace.vadd_mem_pointwise_vadd_iff AffineSubspace.vadd_mem_pointwise_vadd_iff\n\ntheorem pointwise_vadd_bot (v : V) : v +\u1d65 (\u22a5 : AffineSubspace k P) = \u22a5 := by\n  ext; simp [pointwise_vadd_eq_map, map_bot]\n#align affine_subspace.pointwise_vadd_bot AffineSubspace.pointwise_vadd_bot\n\ntheorem pointwise_vadd_direction (v : V) (s : AffineSubspace k P) :\n    (v +\u1d65 s).direction = s.direction := by\n  rw [pointwise_vadd_eq_map, map_direction]\n  exact Submodule.map_id _\n#align affine_subspace.pointwise_vadd_direction AffineSubspace.pointwise_vadd_direction\n\ntheorem pointwise_vadd_span (v : V) (s : Set P) : v +\u1d65 affineSpan k s = affineSpan k (v +\u1d65 s) :=\n  map_span _ s\n#align affine_subspace.pointwise_vadd_span AffineSubspace.pointwise_vadd_span\n\ntheorem map_pointwise_vadd (f : P\u2081 \u2192\u1d43[k] P\u2082) (v : V\u2081) (s : AffineSubspace k P\u2081) :\n    (v +\u1d65 s).map f = f.linear v +\u1d65 s.map f := by\n  erw [pointwise_vadd_eq_map, pointwise_vadd_eq_map, map_map, map_map]\n  congr 1\n  ext\n  exact f.map_vadd _ _\n#align affine_subspace.map_pointwise_vadd AffineSubspace.map_pointwise_vadd\n\nend AffineSubspace\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/LinearAlgebra/AffineSpace/Pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7113778294734935}}
{"text": "import number_theory.padics.padic_norm\nimport basic\nimport order.filter.basic\nimport analysis.special_functions.log.base\nimport analysis.normed.ring.seminorm\nimport data.nat.digits\nimport mul_ring_norm_rat\n\nopen_locale big_operators\n\n/-!\n# Ostrowski's theorem for \u211a\n\nThis file states some basic lemmas when the norm is nonarchimedean.\n\n-/\n\nnoncomputable theory\n\nvariable {f : mul_ring_norm \u211a}\n\n-- If the norm is nonarchimedean, then it's less than one for all naturals. \n-- (Done)\nlemma nat_norm_le_one (n : \u2115) (harc : is_nonarchimedean f) : f n \u2264 1 :=\nbegin\n  induction n with c hc,\n  { simp only [nat.cast_zero, map_zero, zero_le_one], },\n  { rw nat.succ_eq_add_one,\n    specialize harc c 1,\n    rw map_one at harc,\n    simp only [nat.cast_add, nat.cast_one],\n    exact le_trans harc (max_le hc rfl.ge), },\nend\n\n-- If the norm is nonarchimedean, then it's less than one for all integers.\n-- (Done)\nlemma int_norm_le_one (z : \u2124) (harc : is_nonarchimedean f) : f z \u2264 1 :=\nint_norm_bound_iff_nat_norm_bound.mp (\u03bb n, nat_norm_le_one n harc) z\n\n-- If the norm is nonarchimedean, then nontrivial on \u211a implies nontrivial on \u2115.\n-- (Not sure whether should be in mathlib or not)\nlemma nat_nontriv_of_rat_nontriv (harc : is_nonarchimedean f) (hf : f \u2260 1): \n  \u2203 n : \u2115, n \u2260 0 \u2227 f n < 1 := \nbegin\n  revert hf,\n  contrapose!,\n  intro hfnge1,\n  have hfnateq1 : \u2200 n : \u2115, n \u2260 0 \u2192 f n = 1,\n  { intros n hnneq0,\n    specialize hfnge1 n hnneq0,\n    have := nat_norm_le_one n harc,\n    linarith },\n  ext,\n  by_cases h : x = 0,\n  { simp only [h, map_zero]},\n  { simp,\n    rw \u2190 rat.num_div_denom x,\n    have hdenomnon0 : (x.denom : \u211a) \u2260 0,\n    { norm_cast,\n      linarith [x.pos] }, --probably rw on x.pos\n    rw ring_norm.div_eq (x.num : \u211a) hdenomnon0,\n    have H\u2081 : f x.num = 1,\n    { have pos_num_f_eq_1 : \u2200 a : \u211a , (a.num > 0 \u2192 f a.num = 1),\n      { intros a num_pos,\n        have coe_eq : (a.num : \u211a) = (a.num.to_nat : \u211a),\n      { norm_cast,\n        exact (int.to_nat_of_nonneg (by linarith)).symm, },\n      rw coe_eq,\n      have a_num_nat_nonzero : a.num.to_nat \u2260 0,\n      { intro H,\n        rw int.to_nat_eq_zero at H,\n        linarith },\n      exact hfnateq1 _ a_num_nat_nonzero },\n      by_cases hsign : x.num \u2265 0,\n      { apply pos_num_f_eq_1,\n        rw [rat.zero_iff_num_zero, \u2190ne.def] at h,\n        exact lt_of_le_of_ne hsign h.symm },\n      { push_neg at hsign,\n        rw \u2190f.to_fun_eq_coe,\n        rw \u2190f.neg' x.num,\n        rw f.to_fun_eq_coe,\n        norm_cast,\n        rw \u2190rat.num_neg_eq_neg_num,\n        apply pos_num_f_eq_1, \n        rw rat.num_neg_eq_neg_num,\n        exact neg_pos.mpr hsign} },\n    simp [h], \n    rw H\u2081,\n    rw [hfnateq1 x.denom (by linarith [x.pos])],\n    norm_num,\n  }\nend\n\n-- I couldn't find this lemma in mathlib. A similar version in mathlib is `one_le_prod_of_one_le`.\nlemma real.one_le_prod_of_one_le {l : list \u211d} (hl : \u2200 x : \u211d, x \u2208 l \u2192 1 \u2264 x) : 1 \u2264 l.prod :=\nbegin\n  induction l with a l ih,\n  { simp only [list.prod_nil], },\n  { simp only [list.prod_cons],\n    have goal := (ih $ \u03bb a ha, hl a $ list.mem_cons_of_mem _ ha),\n    have goal1 := (hl _ $ list.mem_cons_self _ _),\n    nlinarith, },\nend\n\n-- Show that there is a prime with norm < 1\n-- (Not sure whether should be in mathlib or not)\nlemma ex_prime_norm_lt_one (harc : is_nonarchimedean f) \n  (h : f \u2260 1) : \u2203 (p : \u2115) [hp : fact (nat.prime p)], f p < 1 :=\nbegin\n  by_contra',\n  obtain \u27e8n, hn1, hn2\u27e9 := nat_nontriv_of_rat_nontriv harc h,\n  rw \u2190 nat.prod_factors hn1 at hn2,\n  have exp : \u2200 q : \u2115, q \u2208 nat.factors n \u2192 1 \u2264 f q,\n  { intros q hq,\n    letI : fact (nat.prime q) := {out := nat.prime_of_mem_factors hq},\n    specialize this q,\n    exact this, },\n  simp only [nat.cast_list_prod] at hn2,\n  let g : monoid_hom \u211a \u211d :=\n  { to_fun   := f,\n    map_one' := f.map_one',\n    map_mul' := f.map_mul' },\n  have hf_mh: f.to_fun = g.to_fun := rfl,\n  rw [\u2190 f.to_fun_eq_coe, hf_mh, g.to_fun_eq_coe, map_list_prod] at hn2,\n  simp only [list.map_map] at hn2,\n  have h : \u2200 (x \u2208 (list.map (g \u2218 (coe : \u2115 \u2192 \u211a)) n.factors)), 1 \u2264 x,\n  { intros x hx,\n    simp only [list.mem_map, function.comp_app] at hx,\n    rcases hx with \u27e8a, ha1, ha2\u27e9,\n    letI : fact (nat.prime a) := {out := nat.prime_of_mem_factors ha1},\n    specialize exp a ha1,\n    rw \u2190 ha2,\n    convert exp, },\n  suffices goal : (1 : \u211d) \u2264 (list.map (g \u2218 (coe : \u2115 \u2192 \u211a)) n.factors).prod,\n  { linarith },\n  { exact real.one_le_prod_of_one_le h },\nend\n\n-- (Not sure whether should be in mathlib or not)\nlemma prime_triv_nat_triv (harc : is_nonarchimedean f) (H : \u2200 p : \u2115 , p.prime \u2192 f p = 1) \n  (n : \u2115) (n_pos : n \u2260 0) : f n = 1 :=\nbegin\n  induction n using nat.strong_induction_on with n hn,\n  by_cases nge2 : n < 2,\n  { interval_cases n,\n    { exfalso, apply n_pos, refl },\n    { exact f.map_one' } },\n  { push_neg at hn,\n    have : n \u2260 1,\n    { intro H,\n      rw H at nge2,\n      apply nge2,\n      norm_num },\n    obtain \u27e8p, p_prime, p_div\u27e9 := nat.exists_prime_and_dvd this,\n    obtain \u27e8k, hk\u27e9 := p_div,\n    rw hk,\n    rw nat.cast_mul,\n    rw f_mul_eq,\n    rw H p p_prime,\n    rw one_mul,\n    have k_pos : k \u2260 0,\n    { intro k_zero, apply n_pos, rw hk, rw k_zero, rw mul_zero },\n    have kltn : k < n,\n    { have := nat.prime.two_le p_prime,\n      rw hk,\n      have ineq1 : 2*k \u2264 p*k,\n      { exact mul_le_mul_right' this k },\n      have ineq2 : k < 2 * k,\n      { nth_rewrite 0 \u2190one_mul k,\n        have : 0 < k,\n        { exact zero_lt_iff.mpr k_pos },\n        apply (mul_lt_mul_right this).mpr,\n        norm_num, },\n      exact lt_of_lt_of_le ineq2 ineq1 },\n    exact hn k kltn k_pos }\nend", "meta": {"author": "mariainesdff", "repo": "ostrowski", "sha": "b29d8bd9d98923ec2fab923cb67c76a54aa70386", "save_path": "github-repos/lean/mariainesdff-ostrowski", "path": "github-repos/lean/mariainesdff-ostrowski/ostrowski-b29d8bd9d98923ec2fab923cb67c76a54aa70386/src/nonarchimedean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7113778219340596}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Jens Wagemaker, Aaron Anderson\n-/\nimport ring_theory.coprime.basic\nimport ring_theory.principal_ideal_domain\n\n/-!\n# Divisibility over \u2115 and \u2124\n\nThis file collects results for the integers and natural numbers that use abstract algebra in\ntheir proofs or cases of \u2115 and \u2124 being examples of structures in abstract algebra.\n\n## Main statements\n\n* `nat.factors_eq`: the multiset of elements of `nat.factors` is equal to the factors\n   given by the `unique_factorization_monoid` instance\n* \u2124 is a `normalization_monoid`\n* \u2124 is a `gcd_monoid`\n\n## Tags\n\nprime, irreducible, natural numbers, integers, normalization monoid, gcd monoid,\ngreatest common divisor, prime factorization, prime factors, unique factorization,\nunique factors\n-/\n\nnamespace nat\n\ninstance : wf_dvd_monoid \u2115 :=\n\u27e8begin\n  refine rel_hom_class.well_founded\n    (\u27e8\u03bb (x : \u2115), if x = 0 then (\u22a4 : with_top \u2115) else x, _\u27e9 : dvd_not_unit \u2192r (<))\n    (with_top.well_founded_lt nat.lt_wf),\n  intros a b h,\n  cases a,\n  { exfalso, revert h, simp [dvd_not_unit] },\n  cases b,\n  { simp [succ_ne_zero, with_top.coe_lt_top] },\n  cases dvd_and_not_dvd_iff.2 h with h1 h2,\n  simp only [succ_ne_zero, with_top.coe_lt_coe, if_false],\n  apply lt_of_le_of_ne (nat.le_of_dvd (nat.succ_pos _) h1) (\u03bb con, h2 _),\n  rw con,\nend\u27e9\n\ninstance : unique_factorization_monoid \u2115 :=\n\u27e8\u03bb _, nat.irreducible_iff_prime\u27e9\n\nend nat\n\n/-- `\u2115` is a gcd_monoid. -/\ninstance : gcd_monoid \u2115 :=\n{ gcd := nat.gcd,\n  lcm := nat.lcm,\n  gcd_dvd_left := nat.gcd_dvd_left ,\n  gcd_dvd_right := nat.gcd_dvd_right,\n  dvd_gcd := \u03bb a b c, nat.dvd_gcd,\n  gcd_mul_lcm := \u03bb a b, by rw [nat.gcd_mul_lcm],\n  lcm_zero_left := nat.lcm_zero_left,\n  lcm_zero_right := nat.lcm_zero_right }\n\ninstance : normalized_gcd_monoid \u2115 :=\n{ normalize_gcd := \u03bb a b, normalize_eq _,\n  normalize_lcm := \u03bb a b, normalize_eq _,\n  .. (infer_instance : gcd_monoid \u2115),\n  .. (infer_instance : normalization_monoid \u2115) }\n\nlemma gcd_eq_nat_gcd (m n : \u2115) : gcd m n = nat.gcd m n := rfl\n\nlemma lcm_eq_nat_lcm (m n : \u2115) : lcm m n = nat.lcm m n := rfl\n\nnamespace int\n\nsection normalization_monoid\n\ninstance : normalization_monoid \u2124 :=\n{ norm_unit      := \u03bba:\u2124, if 0 \u2264 a then 1 else -1,\n  norm_unit_zero := if_pos le_rfl,\n  norm_unit_mul  := assume a b hna hnb,\n  begin\n    cases hna.lt_or_lt with ha ha; cases hnb.lt_or_lt with hb hb;\n      simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]\n  end,\n  norm_unit_coe_units := assume u, (units_eq_one_or u).elim\n    (assume eq, eq.symm \u25b8 if_pos zero_le_one)\n    (assume eq, eq.symm \u25b8 if_neg (not_le_of_gt $ show (-1:\u2124) < 0, by dec_trivial)), }\n\nlemma normalize_of_nonneg {z : \u2124} (h : 0 \u2264 z) : normalize z = z :=\nshow z * \u2191(ite _ _ _) = z, by rw [if_pos h, units.coe_one, mul_one]\n\nlemma normalize_of_neg {z : \u2124} (h : z < 0) : normalize z = -z :=\nshow z * \u2191(ite _ _ _) = -z,\nby rw [if_neg (not_le_of_gt h), units.coe_neg, units.coe_one, mul_neg_one]\n\nlemma normalize_coe_nat (n : \u2115) : normalize (n : \u2124) = n :=\nnormalize_of_nonneg (coe_nat_le_coe_nat_of_le $ nat.zero_le n)\n\ntheorem coe_nat_abs_eq_normalize (z : \u2124) : (z.nat_abs : \u2124) = normalize z :=\nbegin\n  by_cases 0 \u2264 z,\n  { simp [nat_abs_of_nonneg h, normalize_of_nonneg h] },\n  { simp [of_nat_nat_abs_of_nonpos (le_of_not_ge h), normalize_of_neg (lt_of_not_ge h)] }\nend\n\nlemma nonneg_of_normalize_eq_self {z : \u2124} (hz : normalize z = z) : 0 \u2264 z :=\ncalc 0 \u2264 (z.nat_abs : \u2124) : coe_zero_le _\n... = normalize z : coe_nat_abs_eq_normalize _\n... = z : hz\n\nlemma nonneg_iff_normalize_eq_self (z : \u2124) : normalize z = z \u2194 0 \u2264 z :=\n\u27e8nonneg_of_normalize_eq_self, normalize_of_nonneg\u27e9\n\nlemma eq_of_associated_of_nonneg {a b : \u2124} (h : associated a b) (ha : 0 \u2264 a) (hb : 0 \u2264 b) : a = b :=\ndvd_antisymm_of_normalize_eq (normalize_of_nonneg ha) (normalize_of_nonneg hb) h.dvd h.symm.dvd\n\nend normalization_monoid\n\nsection gcd_monoid\n\ninstance : gcd_monoid \u2124 :=\n{ gcd            := \u03bba b, int.gcd a b,\n  lcm            := \u03bba b, int.lcm a b,\n  gcd_dvd_left   := assume a b, int.gcd_dvd_left _ _,\n  gcd_dvd_right  := assume a b, int.gcd_dvd_right _ _,\n  dvd_gcd        := assume a b c, dvd_gcd,\n  gcd_mul_lcm    := \u03bb a b, by\n  { rw [\u2190 int.coe_nat_mul, gcd_mul_lcm, coe_nat_abs_eq_normalize],\n    exact normalize_associated (a * b) },\n  lcm_zero_left  := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_left _,\n  lcm_zero_right := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_right _}\n\ninstance : normalized_gcd_monoid \u2124 :=\n{ normalize_gcd  := \u03bb a b, normalize_coe_nat _,\n  normalize_lcm  := \u03bb a b, normalize_coe_nat _,\n  .. int.normalization_monoid,\n  .. (infer_instance : gcd_monoid \u2124) }\n\nlemma coe_gcd (i j : \u2124) : \u2191(int.gcd i j) = gcd_monoid.gcd i j := rfl\nlemma coe_lcm (i j : \u2124) : \u2191(int.lcm i j) = gcd_monoid.lcm i j := rfl\n\nlemma nat_abs_gcd (i j : \u2124) : nat_abs (gcd_monoid.gcd i j) = int.gcd i j := rfl\nlemma nat_abs_lcm (i j : \u2124) : nat_abs (gcd_monoid.lcm i j) = int.lcm i j := rfl\n\nend gcd_monoid\n\nlemma exists_unit_of_abs (a : \u2124) : \u2203 (u : \u2124) (h : is_unit u), (int.nat_abs a : \u2124) = u * a :=\nbegin\n  cases (nat_abs_eq a) with h,\n  { use [1, is_unit_one], rw [\u2190 h, one_mul], },\n  { use [-1, is_unit_one.neg], rw [ \u2190 neg_eq_iff_neg_eq.mp (eq.symm h)],\n    simp only [neg_mul_eq_neg_mul_symm, one_mul] }\nend\n\nlemma gcd_eq_nat_abs {a b : \u2124} : int.gcd a b = nat.gcd a.nat_abs b.nat_abs := rfl\n\nlemma gcd_eq_one_iff_coprime {a b : \u2124} : int.gcd a b = 1 \u2194 is_coprime a b :=\nbegin\n  split,\n  { intro hg,\n    obtain \u27e8ua, hua, ha\u27e9 := exists_unit_of_abs a,\n    obtain \u27e8ub, hub, hb\u27e9 := exists_unit_of_abs b,\n    use [(nat.gcd_a (int.nat_abs a) (int.nat_abs b)) * ua,\n        (nat.gcd_b (int.nat_abs a) (int.nat_abs b)) * ub],\n    rw [mul_assoc, \u2190 ha, mul_assoc, \u2190 hb, mul_comm, mul_comm _ (int.nat_abs b : \u2124),\n      \u2190 nat.gcd_eq_gcd_ab, \u2190gcd_eq_nat_abs, hg, int.coe_nat_one] },\n  { rintro \u27e8r, s, h\u27e9,\n    by_contradiction hg,\n    obtain \u27e8p, \u27e8hp, ha, hb\u27e9\u27e9 := nat.prime.not_coprime_iff_dvd.mp hg,\n    apply nat.prime.not_dvd_one hp,\n    rw [\u2190coe_nat_dvd, int.coe_nat_one, \u2190 h],\n    exact dvd_add ((coe_nat_dvd_left.mpr ha).mul_left _)\n      ((coe_nat_dvd_left.mpr hb).mul_left _) }\nend\n\nlemma coprime_iff_nat_coprime {a b : \u2124} : is_coprime a b \u2194 nat.coprime a.nat_abs b.nat_abs :=\nby rw [\u2190gcd_eq_one_iff_coprime, nat.coprime_iff_gcd_eq_one, gcd_eq_nat_abs]\n\nlemma sq_of_gcd_eq_one {a b c : \u2124} (h : int.gcd a b = 1) (heq : a * b = c ^ 2) :\n  \u2203 (a0 : \u2124), a = a0 ^ 2 \u2228 a = - (a0 ^ 2) :=\nbegin\n  have h' : is_unit (gcd_monoid.gcd a b), { rw [\u2190 coe_gcd, h, int.coe_nat_one], exact is_unit_one },\n  obtain \u27e8d, \u27e8u, hu\u27e9\u27e9 := exists_associated_pow_of_mul_eq_pow h' heq,\n  use d,\n  rw \u2190 hu,\n  cases int.units_eq_one_or u with hu' hu'; { rw hu', simp }\nend\n\nlemma sq_of_coprime {a b c : \u2124} (h : is_coprime a b) (heq : a * b = c ^ 2) :\n  \u2203 (a0 : \u2124), a = a0 ^ 2 \u2228 a = - (a0 ^ 2) := sq_of_gcd_eq_one (gcd_eq_one_iff_coprime.mpr h) heq\n\nlemma nat_abs_euclidean_domain_gcd (a b : \u2124) :\n  int.nat_abs (euclidean_domain.gcd a b) = int.gcd a b :=\nbegin\n  apply nat.dvd_antisymm; rw \u2190 int.coe_nat_dvd,\n  { rw int.nat_abs_dvd,\n    exact int.dvd_gcd (euclidean_domain.gcd_dvd_left _ _) (euclidean_domain.gcd_dvd_right _ _) },\n  { rw int.dvd_nat_abs,\n    exact euclidean_domain.dvd_gcd (int.gcd_dvd_left _ _) (int.gcd_dvd_right _ _) }\nend\n\nend int\n\nlemma nat.prime_iff_prime_int {p : \u2115} : p.prime \u2194 _root_.prime (p : \u2124) :=\n\u27e8\u03bb hp, \u27e8int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt int.is_unit_iff_nat_abs_eq.1 hp.ne_one,\n  \u03bb a b h, by rw [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;\n    rwa [\u2190 int.dvd_nat_abs, int.coe_nat_dvd, \u2190 int.dvd_nat_abs, int.coe_nat_dvd]\u27e9,\n  \u03bb hp, nat.prime_iff.2 \u27e8int.coe_nat_ne_zero.1 hp.1,\n      mt nat.is_unit_iff.1 $ \u03bb h, by simpa [h, not_prime_one] using hp,\n    \u03bb a b, by simpa only [int.coe_nat_dvd, (int.coe_nat_mul _ _).symm] using hp.2.2 a b\u27e9\u27e9\n\n/-- Maps an associate class of integers consisting of `-n, n` to `n : \u2115` -/\ndef associates_int_equiv_nat : associates \u2124 \u2243 \u2115 :=\nbegin\n  refine \u27e8\u03bbz, z.out.nat_abs, \u03bbn, associates.mk n, _, _\u27e9,\n  { refine (assume a, quotient.induction_on' a $ assume a,\n      associates.mk_eq_mk_iff_associated.2 $ associated.symm $ \u27e8norm_unit a, _\u27e9),\n    show normalize a = int.nat_abs (normalize a),\n    rw [int.coe_nat_abs_eq_normalize, normalize_idem] },\n  { intro n,\n    dsimp,\n    rw [\u2190normalize_apply, \u2190 int.coe_nat_abs_eq_normalize, int.nat_abs_of_nat, int.nat_abs_of_nat] }\nend\n\nlemma int.prime.dvd_mul {m n : \u2124} {p : \u2115}\n  (hp : nat.prime p) (h : (p : \u2124) \u2223 m * n) : p \u2223 m.nat_abs \u2228 p \u2223 n.nat_abs :=\nbegin\n  apply (nat.prime.dvd_mul hp).mp,\n  rw \u2190 int.nat_abs_mul,\n  exact int.coe_nat_dvd_left.mp h\nend\n\nlemma int.prime.dvd_mul' {m n : \u2124} {p : \u2115}\n  (hp : nat.prime p) (h : (p : \u2124) \u2223 m * n) : (p : \u2124) \u2223 m \u2228 (p : \u2124) \u2223 n :=\nbegin\n  rw [int.coe_nat_dvd_left, int.coe_nat_dvd_left],\n  exact int.prime.dvd_mul hp h\nend\n\nlemma int.prime.dvd_pow {n : \u2124} {k p : \u2115}\n  (hp : nat.prime p) (h : (p : \u2124) \u2223 n ^ k) : p  \u2223 n.nat_abs :=\nbegin\n  apply @nat.prime.dvd_of_dvd_pow _ _ k hp,\n  rw \u2190 int.nat_abs_pow,\n  exact int.coe_nat_dvd_left.mp h\nend\n\nlemma int.prime.dvd_pow' {n : \u2124} {k p : \u2115}\n  (hp : nat.prime p) (h : (p : \u2124) \u2223 n ^ k) : (p : \u2124)  \u2223 n :=\nbegin\n  rw int.coe_nat_dvd_left,\n  exact int.prime.dvd_pow hp h\nend\n\nlemma prime_two_or_dvd_of_dvd_two_mul_pow_self_two {m : \u2124} {p : \u2115}\n  (hp : nat.prime p) (h : (p : \u2124) \u2223 2 * m ^ 2) : p = 2 \u2228 p \u2223 int.nat_abs m :=\nbegin\n  cases int.prime.dvd_mul hp h with hp2 hpp,\n  { apply or.intro_left,\n    exact le_antisymm (nat.le_of_dvd zero_lt_two hp2) (nat.prime.two_le hp) },\n  { apply or.intro_right,\n    rw [sq, int.nat_abs_mul] at hpp,\n    exact (or_self _).mp ((nat.prime.dvd_mul hp).mp hpp)}\nend\n\nlemma int.exists_prime_and_dvd {n : \u2124} (n2 : 2 \u2264 n.nat_abs) : \u2203 p, prime p \u2227 p \u2223 n :=\nbegin\n  obtain \u27e8p, pp, pd\u27e9 := nat.exists_prime_and_dvd n2,\n  exact \u27e8p, nat.prime_iff_prime_int.mp pp, int.coe_nat_dvd_left.mpr pd\u27e9,\nend\n\nopen unique_factorization_monoid\n\ntheorem nat.factors_eq {n : \u2115} : normalized_factors n = n.factors :=\nbegin\n  cases n, { simp },\n  rw [\u2190 multiset.rel_eq, \u2190 associated_eq_eq],\n  apply factors_unique (irreducible_of_normalized_factor) _,\n  { rw [multiset.coe_prod, nat.prod_factors (nat.succ_pos _)],\n    apply normalized_factors_prod (nat.succ_ne_zero _) },\n  { apply_instance },\n  { intros x hx,\n    rw [nat.irreducible_iff_prime, \u2190 nat.prime_iff],\n    exact nat.prime_of_mem_factors hx }\nend\n\nlemma nat.factors_multiset_prod_of_irreducible\n  {s : multiset \u2115} (h : \u2200 (x : \u2115), x \u2208 s \u2192 irreducible x) :\n  normalized_factors (s.prod) = s :=\nbegin\n  rw [\u2190 multiset.rel_eq, \u2190 associated_eq_eq],\n  apply unique_factorization_monoid.factors_unique irreducible_of_normalized_factor h\n    (normalized_factors_prod _),\n  rw [ne.def, multiset.prod_eq_zero_iff],\n  intro con,\n  exact not_irreducible_zero (h 0 con),\nend\n\nnamespace multiplicity\n\nlemma finite_int_iff_nat_abs_finite {a b : \u2124} : finite a b \u2194 finite a.nat_abs b.nat_abs :=\nby simp only [finite_def, \u2190 int.nat_abs_dvd_iff_dvd, int.nat_abs_pow]\n\nlemma finite_int_iff {a b : \u2124} : finite a b \u2194 (a.nat_abs \u2260 1 \u2227 b \u2260 0) :=\nby rw [finite_int_iff_nat_abs_finite, finite_nat_iff, pos_iff_ne_zero, int.nat_abs_ne_zero]\n\ninstance decidable_nat : decidable_rel (\u03bb a b : \u2115, (multiplicity a b).dom) :=\n\u03bb a b, decidable_of_iff _ finite_nat_iff.symm\n\ninstance decidable_int : decidable_rel (\u03bb a b : \u2124, (multiplicity a b).dom) :=\n\u03bb a b, decidable_of_iff _ finite_int_iff.symm\n\nend multiplicity\n\nlemma induction_on_primes {P : \u2115 \u2192 Prop} (h\u2080 : P 0) (h\u2081 : P 1)\n  (h : \u2200 p a : \u2115, p.prime \u2192 P a \u2192 P (p * a)) (n : \u2115) : P n :=\nbegin\n  apply unique_factorization_monoid.induction_on_prime,\n  exact h\u2080,\n  { intros n h,\n    rw nat.is_unit_iff.1 h,\n    exact h\u2081, },\n  { intros a p _ hp ha,\n    exact h p a (nat.prime_iff.2 hp) ha, },\nend\n\nlemma int.associated_nat_abs (k : \u2124) : associated k k.nat_abs :=\nassociated_of_dvd_dvd (int.coe_nat_dvd_right.mpr dvd_rfl) (int.nat_abs_dvd.mpr dvd_rfl)\n\nlemma int.prime_iff_nat_abs_prime {k : \u2124} : prime k \u2194 nat.prime k.nat_abs :=\n(int.associated_nat_abs k).prime_iff.trans nat.prime_iff_prime_int.symm\n\ntheorem int.associated_iff_nat_abs {a b : \u2124} : associated a b \u2194 a.nat_abs = b.nat_abs :=\nbegin\n  rw [\u2190dvd_dvd_iff_associated, \u2190int.nat_abs_dvd_iff_dvd,\n      \u2190int.nat_abs_dvd_iff_dvd, dvd_dvd_iff_associated],\n  exact associated_iff_eq,\nend\n\nlemma int.associated_iff {a b : \u2124} : associated a b \u2194 (a = b \u2228 a = -b) :=\nbegin\n  rw int.associated_iff_nat_abs,\n  exact int.nat_abs_eq_nat_abs_iff,\nend\n\nnamespace int\n\nlemma zmultiples_nat_abs (a : \u2124) :\n  add_subgroup.zmultiples (a.nat_abs : \u2124) = add_subgroup.zmultiples a :=\nle_antisymm\n  (add_subgroup.zmultiples_subset (mem_zmultiples_iff.mpr (dvd_nat_abs.mpr (dvd_refl a))))\n  (add_subgroup.zmultiples_subset (mem_zmultiples_iff.mpr (nat_abs_dvd.mpr (dvd_refl a))))\n\nlemma span_nat_abs (a : \u2124) : ideal.span ({a.nat_abs} : set \u2124) = ideal.span {a} :=\nby { rw ideal.span_singleton_eq_span_singleton, exact (associated_nat_abs _).symm }\n\ntheorem eq_pow_of_mul_eq_pow_bit1_left {a b c : \u2124}\n  (hab : is_coprime a b) {k : \u2115} (h : a * b = c ^ (bit1 k)) : \u2203 d, a = d ^ (bit1 k) :=\nbegin\n  obtain \u27e8d, hd\u27e9 := exists_associated_pow_of_mul_eq_pow' hab h,\n  replace hd := hd.symm,\n  rw [associated_iff_nat_abs, nat_abs_eq_nat_abs_iff, \u2190neg_pow_bit1] at hd,\n  obtain rfl|rfl := hd; exact \u27e8_, rfl\u27e9,\nend\n\ntheorem eq_pow_of_mul_eq_pow_bit1_right {a b c : \u2124}\n  (hab : is_coprime a b) {k : \u2115} (h : a * b = c ^ (bit1 k)) : \u2203 d, b = d ^ (bit1 k) :=\neq_pow_of_mul_eq_pow_bit1_left hab.symm (by rwa mul_comm at h)\n\ntheorem eq_pow_of_mul_eq_pow_bit1 {a b c : \u2124}\n  (hab : is_coprime a b) {k : \u2115} (h : a * b = c ^ (bit1 k)) :\n  (\u2203 d, a = d ^ (bit1 k)) \u2227 (\u2203 e, b = e ^ (bit1 k)) :=\n\u27e8eq_pow_of_mul_eq_pow_bit1_left hab h, eq_pow_of_mul_eq_pow_bit1_right hab h\u27e9\n\nend int\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/ring_theory/int/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7113347412370608}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\n! This file was ported from Lean 3 source module data.int.basic\n! leanprover-community/mathlib commit 728baa2f54e6062c5879a3e397ac6bac323e506f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Tactic.Convert\nimport Mathlib.Init.Data.Int.Order\nimport Mathlib.Data.Int.Cast.Basic\nimport Mathlib.Algebra.Ring.Basic\nimport Mathlib.Order.Monotone.Basic\nimport Mathlib.Logic.Nontrivial\n\n/-!\n# Basic operations on the integers\n\nThis file contains:\n* instances on `\u2124`. The stronger one is `Int.linearOrderedCommRing`.\n* some basic lemmas about integers\n-/\n\nopen Nat\n\nnamespace Int\n\ninstance : Nontrivial \u2124 := \u27e8\u27e80, 1, Int.zero_ne_one\u27e9\u27e9\n\ninstance : CommRing \u2124 where\n  zero_mul := Int.zero_mul\n  mul_zero := Int.mul_zero\n  mul_comm := Int.mul_comm\n  left_distrib := Int.mul_add\n  right_distrib := Int.add_mul\n  mul_one := Int.mul_one\n  one_mul := Int.one_mul\n  npow n x := x ^ n\n  npow_zero _ := rfl\n  npow_succ _ _ := by rw [Int.mul_comm]; rfl\n  mul_assoc := Int.mul_assoc\n  add_comm := Int.add_comm\n  add_assoc := Int.add_assoc\n  add_zero := Int.add_zero\n  zero_add := Int.zero_add\n  add_left_neg := Int.add_left_neg\n  nsmul := (\u00b7*\u00b7)\n  nsmul_zero := Int.zero_mul\n  nsmul_succ n x :=\n    show (n + 1 : \u2124) * x = x + n * x\n    by rw [Int.add_mul, Int.add_comm, Int.one_mul]\n  zsmul := (\u00b7*\u00b7)\n  zsmul_zero' := Int.zero_mul\n  zsmul_succ' m n := by\n    simp only [ofNat_eq_coe, ofNat_succ, Int.add_mul, Int.add_comm, Int.one_mul]\n  zsmul_neg' m n := by simp only [negSucc_coe, ofNat_succ, Int.neg_mul]\n  sub_eq_add_neg _ _ := Int.sub_eq_add_neg\n  natCast := (\u00b7)\n  natCast_zero := rfl\n  natCast_succ _ := rfl\n  intCast := (\u00b7)\n  intCast_ofNat _ := rfl\n  intCast_negSucc _ := rfl\n\n@[simp, norm_cast] lemma cast_id : Int.cast n = n := rfl\n\n@[simp] lemma ofNat_eq_cast : Int.ofNat n = n := rfl\n\nlemma cast_Nat_cast [AddGroupWithOne R] : (Int.cast (Nat.cast n) : R) = Nat.cast n :=\n  Int.cast_ofNat _\n\n@[norm_cast]\nlemma cast_eq_cast_iff_Nat (m n : \u2115) : (m : \u2124) = (n : \u2124) \u2194 m = n := ofNat_inj\n\n@[simp, norm_cast]\nlemma natAbs_cast (n : \u2115) : natAbs \u2191n = n := rfl\n\n@[norm_cast]\nprotected lemma coe_nat_sub {n m : \u2115} : n \u2264 m \u2192 (\u2191(m - n) : \u2124) = \u2191m - \u2191n := ofNat_sub\n\n@[to_additive (attr := simp, norm_cast) coe_nat_zsmul]\ntheorem _root_.zpow_coe_nat [DivInvMonoid G] (a : G) (n : \u2115) : a ^ (Nat.cast n : \u2124) = a ^ n :=\nzpow_ofNat ..\n#align coe_nat_zsmul coe_nat_zsmul\n\n/-! ### Extra instances to short-circuit type class resolution\n\nThese also prevent non-computable instances like `Int.normedCommRing` being used to construct\nthese instances non-computably.\n-/\ninstance : AddCommMonoid \u2124    := by infer_instance\ninstance : AddMonoid \u2124        := by infer_instance\ninstance : Monoid \u2124           := by infer_instance\ninstance : CommMonoid \u2124       := by infer_instance\ninstance : CommSemigroup \u2124    := by infer_instance\ninstance : Semigroup \u2124        := by infer_instance\ninstance : AddCommGroup \u2124     := by infer_instance\ninstance : AddGroup \u2124         := by infer_instance\ninstance : AddCommSemigroup \u2124 := by infer_instance\ninstance : AddSemigroup \u2124     := by infer_instance\ninstance : CommSemiring \u2124     := by infer_instance\ninstance : Semiring \u2124         := by infer_instance\ninstance : Ring \u2124             := by infer_instance\ninstance : Distrib \u2124          := by infer_instance\n\n#align int.neg_succ_not_nonneg Int.negSucc_not_nonneg\n#align int.neg_succ_not_pos Int.negSucc_not_pos\n#align int.neg_succ_sub_one Int.negSucc_sub_one\n#align int.coe_nat_mul_neg_succ Int.ofNat_mul_negSucc\n#align int.neg_succ_mul_coe_nat Int.negSucc_mul_ofNat\n#align int.neg_succ_mul_neg_succ Int.negSucc_mul_negSucc\n\n#align int.coe_nat_le Int.ofNat_le\n#align int.coe_nat_lt Int.ofNat_lt\n\ntheorem coe_nat_inj' {m n : \u2115} : (\u2191m : \u2124) = \u2191n \u2194 m = n := Int.ofNat_inj\n#align int.coe_nat_inj' Int.coe_nat_inj'\n\ntheorem coe_nat_strictMono : StrictMono (\u00b7 : \u2115 \u2192 \u2124) := fun _ _ \u21a6 Int.ofNat_lt.2\n#align int.coe_nat_strict_mono Int.coe_nat_strictMono\n\ntheorem coe_nat_nonneg (n : \u2115) : 0 \u2264 (n : \u2124) := ofNat_le.2 (Nat.zero_le _)\n#align int.coe_nat_nonneg Int.coe_nat_nonneg\n\n#align int.neg_of_nat_ne_zero Int.negSucc_ne_zero\n#align int.zero_ne_neg_of_nat Int.zero_ne_negSucc\n\n@[simp]\ntheorem sign_coe_add_one (n : \u2115) : Int.sign (n + 1) = 1 :=\n  rfl\n#align int.sign_coe_add_one Int.sign_coe_add_one\n\n@[simp]\ntheorem sign_negSucc (n : \u2115) : Int.sign -[n+1] = -1 :=\n  rfl\n#align int.sign_neg_succ_of_nat Int.sign_negSucc\n\n/-! ### succ and pred -/\n\n/-- Immediate successor of an integer: `succ n = n + 1` -/\ndef succ (a : \u2124) := a + 1\n#align int.succ Int.succ\n\n/-- Immediate predecessor of an integer: `pred n = n - 1` -/\ndef pred (a : \u2124) := a - 1\n#align int.pred Int.pred\n\ntheorem nat_succ_eq_int_succ (n : \u2115) : (Nat.succ n : \u2124) = Int.succ n := rfl\n#align int.nat_succ_eq_int_succ Int.nat_succ_eq_int_succ\n\ntheorem pred_succ (a : \u2124) : pred (succ a) = a := add_sub_cancel _ _\n#align int.pred_succ Int.pred_succ\n\ntheorem succ_pred (a : \u2124) : succ (pred a) = a := sub_add_cancel _ _\n#align int.succ_pred Int.succ_pred\n\ntheorem neg_succ (a : \u2124) : -succ a = pred (-a) := neg_add _ _\n#align int.neg_succ Int.neg_succ\n\ntheorem succ_neg_succ (a : \u2124) : succ (-succ a) = -a := by rw [neg_succ, succ_pred]\n#align int.succ_neg_succ Int.succ_neg_succ\n\ntheorem neg_pred (a : \u2124) : -pred a = succ (-a) := by\n  rw [neg_eq_iff_eq_neg.mp (neg_succ (-a)), neg_neg]\n#align int.neg_pred Int.neg_pred\n\ntheorem pred_neg_pred (a : \u2124) : pred (-pred a) = -a := by rw [neg_pred, pred_succ]\n#align int.pred_neg_pred Int.pred_neg_pred\n\ntheorem pred_nat_succ (n : \u2115) : pred (Nat.succ n) = n := pred_succ n\n#align int.pred_nat_succ Int.pred_nat_succ\n\ntheorem neg_nat_succ (n : \u2115) : -(Nat.succ n : \u2124) = pred (-n) := neg_succ n\n#align int.neg_nat_succ Int.neg_nat_succ\n\n\n\n@[norm_cast] theorem coe_pred_of_pos {n : \u2115} (h : 0 < n) : ((n - 1 : \u2115) : \u2124) = (n : \u2124) - 1 := by\n  cases n; cases h; simp\n#align int.coe_pred_of_pos Int.coe_pred_of_pos\n\n@[elab_as_elim] protected theorem induction_on {p : \u2124 \u2192 Prop} (i : \u2124)\n    (hz : p 0) (hp : \u2200 i : \u2115, p i \u2192 p (i + 1)) (hn : \u2200 i : \u2115, p (-i) \u2192 p (-i - 1)) : p i := by\n  induction i with\n  | ofNat i =>\n    induction i with\n    | zero => exact hz\n    | succ i ih => exact hp _ ih\n  | negSucc i =>\n    suffices \u2200 n : \u2115, p (-n) from this (i + 1)\n    intro n; induction n with\n    | zero => simp [hz, Nat.cast_zero]\n    | succ n ih => convert hn _ ih using 1; simp [sub_eq_neg_add]\n#align int.induction_on Int.induction_on\n\n/-! ### nat abs -/\n\n#align int.nat_abs_add_le Int.natAbs_add_le\n#align int.nat_abs_sub_le Int.natAbs_sub_le\n#align int.nat_abs_neg_of_nat Int.natAbs_negOfNat\n#align int.nat_abs_mul Int.natAbs_mul\n#align int.nat_abs_mul_nat_abs_eq Int.natAbs_mul_natAbs_eq\n#align int.nat_abs_mul_self' Int.natAbs_mul_self'\n#align int.neg_succ_of_nat_eq' Int.negSucc_eq'\n\n@[deprecated natAbs_ne_zero]\ntheorem natAbs_ne_zero_of_ne_zero : \u2200 {a : \u2124}, a \u2260 0 \u2192 natAbs a \u2260 0 := natAbs_ne_zero.2\n#align int.nat_abs_ne_zero_of_ne_zero Int.natAbs_ne_zero_of_ne_zero\n\n#align int.nat_abs_eq_zero Int.natAbs_eq_zero\n#align int.nat_abs_ne_zero Int.natAbs_ne_zero\n#align int.nat_abs_lt_nat_abs_of_nonneg_of_lt Int.natAbs_lt_natAbs_of_nonneg_of_lt\n#align int.nat_abs_eq_nat_abs_iff Int.natAbs_eq_natAbs_iff\n#align int.nat_abs_eq_iff Int.natAbs_eq_iff\n\n/-! ### `/`  -/\n\n-- Porting note: Many of the theorems in this section are dubious alignments because the default\n-- division on `Int` has changed from the E-rounding convention to the T-rounding convention\n-- (see `Int.ediv`). We have attempted to align the theorems to continue to use the `/` symbol\n-- where possible, but some theorems fail to hold on T-rounding division and have been aligned to\n-- `Int.ediv` instead.\n\n#align int.of_nat_div Int.ofNat_div\n\n@[simp, norm_cast] theorem coe_nat_div (m n : \u2115) : ((m / n : \u2115) : \u2124) = m / n := rfl\n#align int.coe_nat_div Int.coe_nat_div\n\ntheorem coe_nat_ediv (m n : \u2115) : ((m / n : \u2115) : \u2124) = ediv m n := rfl\n\n#align int.neg_succ_of_nat_div Int.negSucc_ediv\n\n#align int.div_neg Int.div_neg\u2093 -- int div alignment\n\ntheorem ediv_of_neg_of_pos {a b : \u2124} (Ha : a < 0) (Hb : 0 < b) : ediv a b = -((-a - 1) / b + 1) :=\n  match a, b, eq_negSucc_of_lt_zero Ha, eq_succ_of_zero_lt Hb with\n  | _, _, \u27e8m, rfl\u27e9, \u27e8n, rfl\u27e9 => by\n    rw [show (- -[m+1] : \u2124) = (m + 1 : \u2124) by rfl]; rw [add_sub_cancel]; rfl\n#align int.div_of_neg_of_pos Int.ediv_of_neg_of_pos\n\n#align int.div_nonneg Int.div_nonneg\u2093 -- int div alignment\n#align int.div_neg' Int.ediv_neg'\n#align int.div_one Int.div_one\u2093 -- int div alignment\n#align int.div_eq_zero_of_lt Int.div_eq_zero_of_lt\u2093 -- int div alignment\n\n/-! ### mod -/\n\n#align int.of_nat_mod Int.ofNat_mod_ofNat\n\n@[simp, norm_cast] theorem coe_nat_mod (m n : \u2115) : (\u2191(m % n) : \u2124) = \u2191m % \u2191n := rfl\n#align int.coe_nat_mod Int.coe_nat_mod\n\n#align int.neg_succ_of_nat_mod Int.negSucc_emod\n#align int.mod_neg Int.mod_neg\u2093 -- int div alignment\n#align int.zero_mod Int.zero_mod\u2093 -- int div alignment\n#align int.mod_zero Int.mod_zero\u2093 -- int div alignment\n#align int.mod_one Int.mod_one\u2093 -- int div alignment\n#align int.mod_eq_of_lt Int.emod_eq_of_lt -- int div alignment\n#align int.mod_add_div Int.emod_add_ediv -- int div alignment\n#align int.div_add_mod Int.div_add_mod\u2093 -- int div alignment\n#align int.mod_add_div' Int.mod_add_div'\u2093 -- int div alignment\n#align int.div_add_mod' Int.div_add_mod'\u2093 -- int div alignment\n#align int.mod_def Int.mod_def\u2093 -- int div alignment\n\n/-! ### properties of `/` and `%` -/\n\n#align int.mul_div_mul_of_pos Int.mul_ediv_mul_of_pos\n#align int.mul_div_mul_of_pos_left Int.mul_ediv_mul_of_pos_left\n#align int.mul_mod_mul_of_pos Int.mul_emod_mul_of_pos\n#align int.mul_div_cancel_of_mod_eq_zero Int.mul_div_cancel_of_mod_eq_zero\u2093 -- int div alignment\n#align int.div_mul_cancel_of_mod_eq_zero Int.div_mul_cancel_of_mod_eq_zero\u2093 -- int div alignment\n\n#align int.nat_abs_sign Int.natAbs_sign\n#align int.nat_abs_sign_of_nonzero Int.natAbs_sign_of_nonzero\n\ntheorem sign_coe_nat_of_nonzero {n : \u2115} (hn : n \u2260 0) : Int.sign n = 1 := sign_ofNat_of_nonzero hn\n#align int.sign_coe_nat_of_nonzero Int.sign_coe_nat_of_nonzero\n\n#align int.div_sign Int.div_sign -- int div alignment\n#align int.of_nat_add_neg_succ_of_nat_of_lt Int.ofNat_add_negSucc_of_lt\n#align int.neg_add_neg Int.negSucc_add_negSucc\n\n/-! ### toNat -/\n\n#align int.to_nat_eq_max Int.toNat_eq_max\n#align int.to_nat_zero Int.toNat_zero\n#align int.to_nat_one Int.toNat_one\n#align int.to_nat_of_nonneg Int.toNat_of_nonneg\n\n@[simp] theorem toNat_coe_nat (n : \u2115) : toNat \u2191n = n := rfl\n#align int.to_nat_coe_nat Int.toNat_coe_nat\n\n@[simp] theorem toNat_coe_nat_add_one {n : \u2115} : ((n : \u2124) + 1).toNat = n + 1 := rfl\n#align int.to_nat_coe_nat_add_one Int.toNat_coe_nat_add_one\n\n#align int.le_to_nat Int.self_le_toNat\n#align int.le_to_nat_iff Int.le_toNat\n#align int.to_nat_add Int.toNat_add\n#align int.to_nat_add_nat Int.toNat_add_nat\n#align int.pred_to_nat Int.pred_toNat\n#align int.to_nat_sub_to_nat_neg Int.toNat_sub_toNat_neg\n#align int.to_nat_add_to_nat_neg_eq_nat_abs Int.toNat_add_toNat_neg_eq_natAbs\n#align int.mem_to_nat' Int.mem_toNat'\n#align int.to_nat_neg_nat Int.toNat_neg_nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7113347404948209}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\nimport data.equiv.list\nimport data.set.finite\n\n/-!\n# Countable sets\n-/\nnoncomputable theory\n\nopen function set encodable\n\nopen classical (hiding some)\nopen_locale classical\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nnamespace set\n\n/-- A set is countable if there exists an encoding of the set into the natural numbers.\nAn encoding is an injection with a partial inverse, which can be viewed as a\nconstructive analogue of countability. (For the most part, theorems about\n`countable` will be classical and `encodable` will be constructive.)\n-/\ndef countable (s : set \u03b1) : Prop := nonempty (encodable s)\n\nlemma countable_iff_exists_injective {s : set \u03b1} :\n  countable s \u2194 \u2203f:s \u2192 \u2115, injective f :=\n\u27e8\u03bb \u27e8h\u27e9, by exactI \u27e8encode, encode_injective\u27e9,\n \u03bb \u27e8f, h\u27e9, \u27e8\u27e8f, partial_inv f, partial_inv_left h\u27e9\u27e9\u27e9\n\n/-- A set `s : set \u03b1` is countable if and only if there exists a function `\u03b1 \u2192 \u2115` injective\non `s`. -/\nlemma countable_iff_exists_inj_on {s : set \u03b1} :\n  countable s \u2194 \u2203 f : \u03b1 \u2192 \u2115, inj_on f s :=\ncountable_iff_exists_injective.trans\n\u27e8\u03bb \u27e8f, hf\u27e9, \u27e8\u03bb a, if h : a \u2208 s then f \u27e8a, h\u27e9 else 0,\n   \u03bb a as b bs h, congr_arg subtype.val $\n     hf $ by simpa [as, bs] using h\u27e9,\n \u03bb \u27e8f, hf\u27e9, \u27e8_, inj_on_iff_injective.1 hf\u27e9\u27e9\n\nlemma countable_iff_exists_surjective [ne : nonempty \u03b1] {s : set \u03b1} :\n  countable s \u2194 \u2203f:\u2115 \u2192 \u03b1, s \u2286 range f :=\n\u27e8\u03bb \u27e8h\u27e9, by inhabit \u03b1; exactI \u27e8\u03bb n, ((decode s n).map subtype.val).iget,\n  \u03bb a as, \u27e8encode (\u27e8a, as\u27e9 : s), by simp [encodek]\u27e9\u27e9,\n \u03bb \u27e8f, hf\u27e9, \u27e8\u27e8\n  \u03bb x, inv_fun f x.1,\n  \u03bb n, if h : f n \u2208 s then some \u27e8f n, h\u27e9 else none,\n  \u03bb \u27e8x, hx\u27e9, begin\n    have := inv_fun_eq (hf hx), dsimp at this \u22a2,\n    simp [this, hx]\n  end\u27e9\u27e9\u27e9\n\n/--\nA non-empty set is countable iff there exists a surjection from the\nnatural numbers onto the subtype induced by the set.\n-/\nlemma countable_iff_exists_surjective_to_subtype {s : set \u03b1} (hs : s.nonempty) :\n  countable s \u2194 \u2203 f : \u2115 \u2192 s, surjective f :=\nhave inhabited s, from \u27e8classical.choice hs.to_subtype\u27e9,\nhave countable s \u2192 \u2203 f : \u2115 \u2192 s, surjective f, from assume \u27e8h\u27e9,\n  by exactI \u27e8\u03bb n, (decode s n).iget, \u03bb a, \u27e8encode a, by simp [encodek]\u27e9\u27e9,\nhave (\u2203 f : \u2115 \u2192 s, surjective f) \u2192 countable s, from assume \u27e8f, fsurj\u27e9,\n  \u27e8\u27e8inv_fun f, option.some \u2218 f,\n    by intro h; simp [(inv_fun_eq (fsurj h) : f (inv_fun f h) = h)]\u27e9\u27e9,\nby split; assumption\n\n/-- Convert `countable s` to `encodable s` (noncomputable). -/\ndef countable.to_encodable {s : set \u03b1} : countable s \u2192 encodable s :=\nclassical.choice\n\nlemma countable_encodable' (s : set \u03b1) [H : encodable s] : countable s :=\n\u27e8H\u27e9\n\nlemma countable_encodable [encodable \u03b1] (s : set \u03b1) : countable s :=\n\u27e8by apply_instance\u27e9\n\n/-- If `s : set \u03b1` is a nonempty countable set, then there exists a map\n`f : \u2115 \u2192 \u03b1` such that `s = range f`. -/\nlemma countable.exists_surjective {s : set \u03b1} (hc : countable s) (hs : s.nonempty) :\n  \u2203f:\u2115 \u2192 \u03b1, s = range f :=\nbegin\n  letI : encodable s := countable.to_encodable hc,\n  letI : nonempty s := hs.to_subtype,\n  have : countable (univ : set s) := countable_encodable _,\n  rcases countable_iff_exists_surjective.1 this with \u27e8g, hg\u27e9,\n  have : range g = univ := univ_subset_iff.1 hg,\n  use coe \u2218 g,\n  simp only [range_comp, this, image_univ, subtype.range_coe]\nend\n\n@[simp] \n\n@[simp] lemma countable_singleton (a : \u03b1) : countable ({a} : set \u03b1) :=\n\u27e8of_equiv _ (equiv.set.singleton a)\u27e9\n\nlemma countable.mono {s\u2081 s\u2082 : set \u03b1} (h : s\u2081 \u2286 s\u2082) : countable s\u2082 \u2192 countable s\u2081\n| \u27e8H\u27e9 := \u27e8@of_inj _ _ H _ (embedding_of_subset _ _ h).2\u27e9\n\nlemma countable.image {s : set \u03b1} (hs : countable s) (f : \u03b1 \u2192 \u03b2) : countable (f '' s) :=\nlet f' : s \u2192 f '' s := \u03bb\u27e8a, ha\u27e9, \u27e8f a, mem_image_of_mem f ha\u27e9 in\nhave hf' : surjective f', from assume \u27e8b, a, ha, hab\u27e9, \u27e8\u27e8a, ha\u27e9, subtype.eq hab\u27e9,\n\u27e8@encodable.of_inj _ _ hs.to_encodable (surj_inv hf') (injective_surj_inv hf')\u27e9\n\nlemma countable_range [encodable \u03b1] (f : \u03b1 \u2192 \u03b2) : countable (range f) :=\nby rw \u2190 image_univ; exact (countable_encodable _).image _\n\nlemma exists_seq_supr_eq_top_iff_countable [complete_lattice \u03b1] {p : \u03b1 \u2192 Prop} (h : \u2203 x, p x) :\n  (\u2203 s : \u2115 \u2192 \u03b1, (\u2200 n, p (s n)) \u2227 (\u2a06 n, s n) = \u22a4) \u2194\n    \u2203 S : set \u03b1, countable S \u2227 (\u2200 s \u2208 S, p s) \u2227 Sup S = \u22a4 :=\nbegin\n  split,\n  { rintro \u27e8s, hps, hs\u27e9,\n    refine \u27e8range s, countable_range s, forall_range_iff.2 hps, _\u27e9, rwa Sup_range },\n  { rintro \u27e8S, hSc, hps, hS\u27e9,\n    rcases eq_empty_or_nonempty S with rfl|hne,\n    { rw [Sup_empty] at hS, haveI := subsingleton_of_bot_eq_top hS,\n      rcases h with \u27e8x, hx\u27e9, exact \u27e8\u03bb n, x, \u03bb n, hx, subsingleton.elim _ _\u27e9 },\n    { rcases (countable_iff_exists_surjective_to_subtype hne).1 hSc with \u27e8s, hs\u27e9,\n      refine \u27e8\u03bb n, s n, \u03bb n, hps _ (s n).coe_prop, _\u27e9,\n      rwa [hs.supr_comp, \u2190 Sup_eq_supr'] } }\nend\n\nlemma exists_seq_cover_iff_countable {p : set \u03b1 \u2192 Prop} (h : \u2203 s, p s) :\n  (\u2203 s : \u2115 \u2192 set \u03b1, (\u2200 n, p (s n)) \u2227 (\u22c3 n, s n) = univ) \u2194\n    \u2203 S : set (set \u03b1), countable S \u2227 (\u2200 s \u2208 S, p s) \u2227 \u22c3\u2080 S = univ :=\nexists_seq_supr_eq_top_iff_countable h\n\nlemma countable_of_injective_of_countable_image {s : set \u03b1} {f : \u03b1 \u2192 \u03b2}\n  (hf : inj_on f s) (hs : countable (f '' s)) : countable s :=\nlet \u27e8g, hg\u27e9 := countable_iff_exists_inj_on.1 hs in\ncountable_iff_exists_inj_on.2 \u27e8g \u2218 f, hg.comp hf (maps_to_image _ _)\u27e9\n\nlemma countable_Union {t : \u03b1 \u2192 set \u03b2} [encodable \u03b1] (ht : \u2200a, countable (t a)) :\n  countable (\u22c3a, t a) :=\nby haveI := (\u03bb a, (ht a).to_encodable);\n   rw Union_eq_range_sigma; apply countable_range\n\nlemma countable.bUnion\n  {s : set \u03b1} {t : \u03a0 x \u2208 s, set \u03b2} (hs : countable s) (ht : \u2200a\u2208s, countable (t a \u2039_\u203a)) :\n  countable (\u22c3a\u2208s, t a \u2039_\u203a) :=\nbegin\n  rw bUnion_eq_Union,\n  haveI := hs.to_encodable,\n  exact countable_Union (by simpa using ht)\nend\n\nlemma countable.sUnion {s : set (set \u03b1)} (hs : countable s) (h : \u2200a\u2208s, countable a) :\n  countable (\u22c3\u2080 s) :=\nby rw sUnion_eq_bUnion; exact hs.bUnion h\n\nlemma countable_Union_Prop {p : Prop} {t : p \u2192 set \u03b2} (ht : \u2200h:p, countable (t h)) :\n  countable (\u22c3h:p, t h) :=\nby by_cases p; simp [h, ht]\n\nlemma countable.union\n  {s\u2081 s\u2082 : set \u03b1} (h\u2081 : countable s\u2081) (h\u2082 : countable s\u2082) : countable (s\u2081 \u222a s\u2082) :=\nby rw union_eq_Union; exact\ncountable_Union (bool.forall_bool.2 \u27e8h\u2082, h\u2081\u27e9)\n\nlemma countable.insert {s : set \u03b1} (a : \u03b1) (h : countable s) : countable (insert a s) :=\nby { rw [set.insert_eq], exact (countable_singleton _).union h }\n\nlemma finite.countable {s : set \u03b1} : finite s \u2192 countable s\n| \u27e8h\u27e9 := trunc.nonempty (by exactI trunc_encodable_of_fintype s)\n\n/-- The set of finite subsets of a countable set is countable. -/\nlemma countable_set_of_finite_subset {s : set \u03b1} : countable s \u2192\n  countable {t | finite t \u2227 t \u2286 s} | \u27e8h\u27e9 :=\nbegin\n  resetI,\n  refine countable.mono _ (countable_range\n    (\u03bb t : finset s, {a | \u2203 h:a \u2208 s, subtype.mk a h \u2208 t})),\n  rintro t \u27e8\u27e8ht\u27e9, ts\u27e9, resetI,\n  refine \u27e8finset.univ.map (embedding_of_subset _ _ ts),\n    set.ext $ \u03bb a, _\u27e9,\n  suffices : a \u2208 s \u2227 a \u2208 t \u2194 a \u2208 t, by simpa,\n  exact \u27e8and.right, \u03bb h, \u27e8ts h, h\u27e9\u27e9\nend\n\nlemma countable_pi {\u03c0 : \u03b1 \u2192 Type*} [fintype \u03b1] {s : \u03a0a, set (\u03c0 a)} (hs : \u2200a, countable (s a)) :\n  countable {f : \u03a0a, \u03c0 a | \u2200a, f a \u2208 s a} :=\ncountable.mono\n  (show {f : \u03a0a, \u03c0 a | \u2200a, f a \u2208 s a} \u2286 range (\u03bbf : \u03a0a, s a, \u03bba, (f a).1), from\n    assume f hf, \u27e8\u03bba, \u27e8f a, hf a\u27e9, funext $ assume a, rfl\u27e9) $\nhave trunc (encodable (\u03a0 (a : \u03b1), s a)), from\n  @encodable.fintype_pi \u03b1 _ _ _ (assume a, (hs a).to_encodable),\ntrunc.induction_on this $ assume h,\n@countable_range _ _ h _\n\nprotected lemma countable.prod {s : set \u03b1} {t : set \u03b2} (hs : countable s) (ht : countable t) :\n  countable (set.prod s t) :=\nbegin\n  haveI : encodable s := hs.to_encodable,\n  haveI : encodable t := ht.to_encodable,\n  haveI : encodable (s \u00d7 t) := by apply_instance,\n  have : range (prod.map coe coe : s \u00d7 t \u2192 \u03b1 \u00d7 \u03b2) = set.prod s t,\n    by rw [range_prod_map, subtype.range_coe, subtype.range_coe],\n  rw \u2190 this,\n  exact countable_range _\nend\n\nlemma countable.image2 {s : set \u03b1} {t : set \u03b2} (hs : countable s) (ht : countable t)\n  (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) : countable (image2 f s t) :=\nby { rw \u2190 image_prod, exact (hs.prod ht).image _ }\n\nsection enumerate\n\n/-- Enumerate elements in a countable set.-/\ndef enumerate_countable {s : set \u03b1} (h : countable s) (default : \u03b1) : \u2115 \u2192 \u03b1 :=\nassume n, match @encodable.decode s (h.to_encodable) n with\n        | (some y) := y\n        | (none)   := default\n        end\n\nlemma subset_range_enumerate {s : set \u03b1} (h : countable s) (default : \u03b1) :\n   s \u2286 range (enumerate_countable h default) :=\nassume x hx,\n\u27e8@encodable.encode s h.to_encodable \u27e8x, hx\u27e9,\nby simp [enumerate_countable, encodable.encodek]\u27e9\n\nend enumerate\n\nend set\n\nlemma finset.countable_to_set (s : finset \u03b1) : set.countable (\u2191s : set \u03b1) :=\ns.finite_to_set.countable\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/set/countable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7113347351253149}}
{"text": "/-\nCopyright (c) 2021 Tian Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tian Chen\n-/\n\nimport analysis.special_functions.sqrt\n\n/-!\n# IMO 2006 Q3\n\nDetermine the least real number $M$ such that\n$$\n\\left| ab(a^2 - b^2) + bc(b^2 - c^2) + ca(c^2 - a^2) \\right|\n\u2264 M (a^2 + b^2 + c^2)^2\n$$\nfor all real numbers $a$, $b$, $c$.\n\n## Solution\n\nThe answer is $M = \\frac{9 \\sqrt 2}{32}$.\n\nThis is essentially a translation of the solution in\nhttps://web.evanchen.cc/exams/IMO-2006-notes.pdf.\n\nIt involves making the substitution\n`x = a - b`, `y = b - c`, `z = c - a`, `s = a + b + c`.\n-/\n\nopen real\n\n/-- Replacing `x` and `y` with their average increases the left side. -/\nlemma lhs_ineq {x y : \u211d} (hxy : 0 \u2264 x * y) :\n  16 * x ^ 2 * y ^ 2 * (x + y) ^ 2 \u2264 ((x + y) ^ 2) ^ 3 :=\nbegin\n  conv_rhs { rw pow_succ' },\n  refine mul_le_mul_of_nonneg_right _ (sq_nonneg _),\n  apply le_of_sub_nonneg,\n  calc  ((x + y) ^ 2) ^ 2 - 16 * x ^ 2 * y ^ 2\n      = (x - y) ^ 2 * ((x + y) ^ 2 + 4 * (x * y))\n          : by ring\n  ... \u2265 0 : mul_nonneg (sq_nonneg _) $ add_nonneg (sq_nonneg _) $\n              mul_nonneg zero_lt_four.le hxy\nend\n\nlemma four_pow_four_pos : (0 : \u211d) < 4 ^ 4 := pow_pos zero_lt_four _\n\nlemma mid_ineq {s t : \u211d} :\n  s * t ^ 3 \u2264 (3 * t + s) ^ 4 / 4 ^ 4 :=\n(le_div_iff four_pow_four_pos).mpr $ le_of_sub_nonneg $\n  calc  (3 * t + s) ^ 4 - s * t ^ 3 * 4 ^ 4\n      = (s - t) ^ 2 * ((s + 7 * t) ^ 2 + 2 * (4 * t) ^ 2)\n          : by ring\n  ... \u2265 0 : mul_nonneg (sq_nonneg _) $ add_nonneg (sq_nonneg _) $\n              mul_nonneg zero_le_two (sq_nonneg _)\n\n/-- Replacing `x` and `y` with their average decreases the right side. -/\nlemma rhs_ineq {x y : \u211d} :\n  3 * (x + y) ^ 2 \u2264 2 * (x ^ 2 + y ^ 2 + (x + y) ^ 2) :=\nle_of_sub_nonneg $\n  calc _ = (x - y) ^ 2 : by ring\n     ... \u2265 0           : sq_nonneg _\n\nlemma zero_lt_32 : (0 : \u211d) < 32 := by norm_num\n\ntheorem subst_wlog {x y z s : \u211d} (hxy : 0 \u2264 x * y) (hxyz : x + y + z = 0) :\n  32 * |x * y * z * s| \u2264 sqrt 2 * (x^2 + y^2 + z^2 + s^2)^2 :=\nhave hz : (x + y)^2 = z^2 := neg_eq_of_add_eq_zero_right hxyz \u25b8 (neg_sq _).symm,\nhave hs : 0 \u2264 2 * s ^ 2 := mul_nonneg zero_le_two (sq_nonneg s),\nhave this : _ :=\n  calc  (2 * s^2) * (16 * x^2 * y^2 * (x + y)^2)\n      \u2264 (3 * (x + y)^2 + 2 * s^2)^4 / 4^4 :\n          le_trans (mul_le_mul_of_nonneg_left (lhs_ineq hxy) hs) mid_ineq\n  ... \u2264 (2 * (x^2 + y^2 + (x + y)^2) + 2 * s^2)^4 / 4^4 :\n          div_le_div_of_le four_pow_four_pos.le $ pow_le_pow_of_le_left\n            (add_nonneg (mul_nonneg zero_lt_three.le (sq_nonneg _)) hs)\n            (add_le_add_right rhs_ineq _) _,\nle_of_pow_le_pow _ (mul_nonneg (sqrt_nonneg _) (sq_nonneg _)) nat.succ_pos' $\n  calc  (32 * |x * y * z * s|) ^ 2\n      = 32 * ((2 * s^2) * (16 * x^2 * y^2 * (x + y)^2)) :\n          by rw [mul_pow, sq_abs, hz]; ring\n  ... \u2264 32 * ((2 * (x^2 + y^2 + (x + y)^2) + 2 * s^2)^4 / 4^4) :\n          mul_le_mul_of_nonneg_left this zero_lt_32.le\n  ... = (sqrt 2 * (x^2 + y^2 + z^2 + s^2)^2)^2 :\n          by rw [mul_pow, sq_sqrt zero_le_two, hz, \u2190pow_mul, \u2190mul_add, mul_pow, \u2190mul_comm_div,\n            \u2190mul_assoc, show 32 / 4 ^ 4 * 2 ^ 4 = (2 : \u211d), by norm_num, show 2 * 2 = 4, by refl]\n\n/-- Proof that `M = 9 * sqrt 2 / 32` works with the substitution. -/\ntheorem subst_proof\u2081 (x y z s : \u211d) (hxyz : x + y + z = 0) :\n  |x * y * z * s| \u2264 sqrt 2 / 32 * (x^2 + y^2 + z^2 + s^2)^2 :=\nbegin\n  wlog h' : 0 \u2264 x * y generalizing x y z, swap,\n  { rw [div_mul_eq_mul_div, le_div_iff' zero_lt_32],\n    exact subst_wlog h' hxyz },\n  cases (mul_nonneg_of_three x y z).resolve_left h' with h h,\n  { specialize this y z x _ h,\n    { rw \u2190 hxyz, ring, },\n    { convert this using 2; ring } },\n  { specialize this z x y _ h,\n    { rw \u2190 hxyz, ring, },\n    { convert this using 2; ring } },\nend\n\nlemma lhs_identity (a b c : \u211d) :\n  a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)\n  = (a - b) * (b - c) * (c - a) * -(a + b + c) :=\nby ring\n\ntheorem proof\u2081 {a b c : \u211d} :\n  |a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)| \u2264\n  9 * sqrt 2 / 32 * (a^2 + b^2 + c^2)^2 :=\ncalc _ = _ : congr_arg _ $ lhs_identity a b c\n   ... \u2264 _ : subst_proof\u2081 (a - b) (b - c) (c - a) (-(a + b + c)) (by ring)\n   ... = _ : by ring\n\ntheorem proof\u2082 (M : \u211d)\n  (h : \u2200 a b c : \u211d,\n    |a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)| \u2264\n    M * (a^2 + b^2 + c^2)^2) :\n  9 * sqrt 2 / 32 \u2264 M :=\nbegin\n  have h\u2081 : \u2200 x : \u211d,\n    (2 - 3 * x - 2) * (2 - (2 + 3 * x)) * (2 + 3 * x - (2 - 3 * x)) *\n    -(2 - 3 * x + 2 + (2 + 3 * x)) = -(18 ^ 2 * x ^ 2 * x),\n  { intro, ring },\n  have h\u2082 : \u2200 x : \u211d, (2 - 3 * x) ^ 2 + 2 ^ 2 + (2 + 3 * x) ^ 2 = 18 * x ^ 2 + 12,\n  { intro, ring },\n  have := h (2 - 3 * sqrt 2) 2 (2 + 3 * sqrt 2),\n  rw [lhs_identity, h\u2081, h\u2082, sq_sqrt zero_le_two,\n    abs_neg, abs_eq_self.mpr, \u2190 div_le_iff] at this,\n  { convert this using 1, ring },\n  { apply pow_pos, norm_num },\n  { exact mul_nonneg (mul_nonneg (sq_nonneg _) zero_le_two) (sqrt_nonneg _) }\nend\n\ntheorem imo2006_q3 (M : \u211d) :\n  (\u2200 a b c : \u211d,\n    |a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)| \u2264\n    M * (a^2 + b^2 + c^2)^2) \u2194\n  9 * sqrt 2 / 32 \u2264 M :=\n\u27e8proof\u2082 M, \u03bb h _ _ _, le_trans proof\u2081 $ mul_le_mul_of_nonneg_right h $ sq_nonneg _\u27e9\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2006_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7113347313272017}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module data.finsupp.lex\n! leanprover-community/mathlib commit dc6c365e751e34d100e80fe6e314c3c3e0fd2988\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finsupp.Order\nimport Mathlib.Data.Dfinsupp.Lex\nimport Mathlib.Data.Finsupp.ToDfinsupp\n\n/-!\n# Lexicographic order on finitely supported functions\n\nThis file defines the lexicographic order on `Finsupp`.\n-/\n\n\nvariable {\u03b1 N : Type _}\n\nnamespace Finsupp\n\nsection NHasZero\n\nvariable [Zero N]\n\n/-- `Finsupp.Lex r s` is the lexicographic relation on `\u03b1 \u2192\u2080 N`, where `\u03b1` is ordered by `r`,\nand `N` is ordered by `s`.\n\nThe type synonym `Lex (\u03b1 \u2192\u2080 N)` has an order given by `Finsupp.Lex (\u00b7 < \u00b7) (\u00b7 < \u00b7)`.\n-/\nprotected def Lex (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : N \u2192 N \u2192 Prop) (x y : \u03b1 \u2192\u2080 N) : Prop :=\n  Pi.Lex r s x y\n#align finsupp.lex Finsupp.Lex\n\n-- Porting note: Added `_root_` to better align with Lean 3.\ntheorem _root_.Pi.lex_eq_finsupp_lex {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : N \u2192 N \u2192 Prop} (a b : \u03b1 \u2192\u2080 N) :\n    Pi.Lex r s a b = Finsupp.Lex r s a b :=\n  rfl\n#align pi.lex_eq_finsupp_lex Pi.lex_eq_finsupp_lex\n\ntheorem lex_def {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : N \u2192 N \u2192 Prop} {a b : \u03b1 \u2192\u2080 N} :\n    Finsupp.Lex r s a b \u2194 \u2203 j, (\u2200 d, r d j \u2192 a d = b d) \u2227 s (a j) (b j) :=\n  Iff.rfl\n#align finsupp.lex_def Finsupp.lex_def\n\ntheorem lex_eq_invImage_dfinsupp_lex (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : N \u2192 N \u2192 Prop) :\n    Finsupp.Lex r s = InvImage (Dfinsupp.Lex r fun _ \u21a6 s) toDfinsupp :=\n  rfl\n#align finsupp.lex_eq_inv_image_dfinsupp_lex Finsupp.lex_eq_invImage_dfinsupp_lex\n\ninstance [LT \u03b1] [LT N] : LT (Lex (\u03b1 \u2192\u2080 N)) :=\n  \u27e8fun f g \u21a6 Finsupp.Lex (\u00b7 < \u00b7) (\u00b7 < \u00b7) (ofLex f) (ofLex g)\u27e9\n\ntheorem lex_lt_of_lt_of_preorder [Preorder N] (r) [IsStrictOrder \u03b1 r] {x y : \u03b1 \u2192\u2080 N} (hlt : x < y) :\n    \u2203 i, (\u2200 j, r j i \u2192 x j \u2264 y j \u2227 y j \u2264 x j) \u2227 x i < y i :=\n  Dfinsupp.lex_lt_of_lt_of_preorder r (id hlt : x.toDfinsupp < y.toDfinsupp)\n#align finsupp.lex_lt_of_lt_of_preorder Finsupp.lex_lt_of_lt_of_preorder\n\ntheorem lex_lt_of_lt [PartialOrder N] (r) [IsStrictOrder \u03b1 r] {x y : \u03b1 \u2192\u2080 N} (hlt : x < y) :\n    Pi.Lex r (\u00b7 < \u00b7) x y :=\n  Dfinsupp.lex_lt_of_lt r (id hlt : x.toDfinsupp < y.toDfinsupp)\n#align finsupp.lex_lt_of_lt Finsupp.lex_lt_of_lt\n\ninstance Lex.isStrictOrder [LinearOrder \u03b1] [PartialOrder N] :\n    IsStrictOrder (Lex (\u03b1 \u2192\u2080 N)) (\u00b7 < \u00b7) :=\n  let i : IsStrictOrder (Lex (\u03b1 \u2192 N)) (\u00b7 < \u00b7) := Pi.Lex.isStrictOrder\n  { irrefl := toLex.surjective.forall.2 fun _ \u21a6 @irrefl _ _ i.toIsIrrefl _\n    trans := toLex.surjective.forall\u2083.2 fun _ _ _ \u21a6 @trans _ _ i.toIsTrans _ _ _ }\n#align finsupp.lex.is_strict_order Finsupp.Lex.isStrictOrder\n\nvariable [LinearOrder \u03b1]\n\n/-- The partial order on `Finsupp`s obtained by the lexicographic ordering.\nSee `Finsupp.Lex.linearOrder` for a proof that this partial order is in fact linear. -/\ninstance Lex.partialOrder [PartialOrder N] : PartialOrder (Lex (\u03b1 \u2192\u2080 N)) :=\n  PartialOrder.lift (fun x \u21a6 toLex (\u21d1(ofLex x))) (FunLike.coe_injective (F := Finsupp \u03b1 N))\n#align finsupp.lex.partial_order Finsupp.Lex.partialOrder\n\n/-- The linear order on `Finsupp`s obtained by the lexicographic ordering. -/\ninstance Lex.linearOrder [LinearOrder N] : LinearOrder (Lex (\u03b1 \u2192\u2080 N)) :=\n  { @Lex.partialOrder \u03b1 N _ _ _,  -- Porting note: Added types to avoid typeclass inference problem.\n    LinearOrder.lift' (toLex \u2218 toDfinsupp \u2218 ofLex) finsuppEquivDfinsupp.injective with }\n#align finsupp.lex.linear_order Finsupp.Lex.linearOrder\n\nvariable [PartialOrder N]\n\ntheorem toLex_monotone : Monotone (@toLex (\u03b1 \u2192\u2080 N)) :=\n  fun a b h \u21a6 Dfinsupp.toLex_monotone (id h : \u2200 i, ofLex (toDfinsupp a) i \u2264 ofLex (toDfinsupp b) i)\n#align finsupp.to_lex_monotone Finsupp.toLex_monotone\n\n\n\nend NHasZero\n\nsection Covariants\n\nvariable [LinearOrder \u03b1] [AddMonoid N] [LinearOrder N]\n\n/-!  We are about to sneak in a hypothesis that might appear to be too strong.\nWe assume `CovariantClass` with *strict* inequality `<` also when proving the one with the\n*weak* inequality `\u2264`.  This is actually necessary: addition on `Lex (\u03b1 \u2192\u2080 N)` may fail to be\nmonotone, when it is \"just\" monotone on `N`.\n\nSee `counterexamples.zero_divisors_in_add_monoid_algebras` for a counterexample. -/\n\n\nsection Left\n\nvariable [CovariantClass N N (\u00b7 + \u00b7) (\u00b7 < \u00b7)]\n\ninstance Lex.covariantClass_lt_left :\n    CovariantClass (Lex (\u03b1 \u2192\u2080 N)) (Lex (\u03b1 \u2192\u2080 N)) (\u00b7 + \u00b7) (\u00b7 < \u00b7) :=\n  \u27e8fun _ _ _ \u27e8a, lta, ha\u27e9 \u21a6 \u27e8a, fun j ja \u21a6 congr_arg _ (lta j ja), add_lt_add_left ha _\u27e9\u27e9\n#align finsupp.lex.covariant_class_lt_left Finsupp.Lex.covariantClass_lt_left\n\ninstance Lex.covariantClass_le_left :\n    CovariantClass (Lex (\u03b1 \u2192\u2080 N)) (Lex (\u03b1 \u2192\u2080 N)) (\u00b7 + \u00b7) (\u00b7 \u2264 \u00b7) :=\n  Add.to_covariantClass_left _\n#align finsupp.lex.covariant_class_le_left Finsupp.Lex.covariantClass_le_left\n\nend Left\n\nsection Right\n\nvariable [CovariantClass N N (Function.swap (\u00b7 + \u00b7)) (\u00b7 < \u00b7)]\n\ninstance Lex.covariantClass_lt_right :\n    CovariantClass (Lex (\u03b1 \u2192\u2080 N)) (Lex (\u03b1 \u2192\u2080 N)) (Function.swap (\u00b7 + \u00b7)) (\u00b7 < \u00b7) :=\n  \u27e8fun f _ _ \u27e8a, lta, ha\u27e9 \u21a6\n    \u27e8a, fun j ja \u21a6 congr_arg (\u00b7 + ofLex f j) (lta j ja), add_lt_add_right ha _\u27e9\u27e9\n#align finsupp.lex.covariant_class_lt_right Finsupp.Lex.covariantClass_lt_right\n\ninstance Lex.covariantClass_le_right :\n    CovariantClass (Lex (\u03b1 \u2192\u2080 N)) (Lex (\u03b1 \u2192\u2080 N)) (Function.swap (\u00b7 + \u00b7)) (\u00b7 \u2264 \u00b7) :=\n  Add.to_covariantClass_right _\n#align finsupp.lex.covariant_class_le_right Finsupp.Lex.covariantClass_le_right\n\nend Right\n\nend Covariants\n\nend Finsupp\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Finsupp/Lex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7113347185799115}}
{"text": "-- 1\nsection\n  variable A : Type\n  variable f : A \u2192 A\n  variable P : A \u2192 Prop\n  variable  h : \u2200x, P x \u2192 P (f x)\n\n  example : \u2200y, P y \u2192 P (f (f y)) :=\n  assume y,\n  assume Py,\n  have Pfy : P (f y), from h y Py,\n  h (f y) Pfy\nend\n\n\n-- 2\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2200x, A x \u2227 B x) \u2192 \u2200x, A x :=\n  assume h1 : (\u2200 x, A x \u2227 B x),\n  assume x,\n  have AxBx : A x \u2227 B x, from h1 x,\n  show A x, from and.elim_left AxBx\nend\n\n\n-- 3\nsection\n  variable U : Type\n  variables A B C : U \u2192 Prop\n\n  variable h1 : \u2200x, A x \u2228 B x\n  variable h2 : \u2200x, A x \u2192 C x\n  variable h3 : \u2200x, B x \u2192 C x\n\n  example : \u2200x, C x :=\n  assume x,\n  or.elim (h1 x)\n      (assume Ax, h2 x Ax)\n      (assume Bx, h3 x Bx)\nend\n\n\n-- 4\nopen classical\n\naxiom not_iff_not_self (P : Prop) : \u00ac(P \u2194 \u00acP)\n\nexample (Q : Prop) : \u00ac(Q \u2194 \u00acQ) :=\nnot_iff_not_self Q\n\nsection\n  variable Person : Type\n  variable shaves : Person \u2192 Person \u2192 Prop\n  variable barber : Person\n  variable h : \u2200x, shaves barber x \u2194 \u00acshaves x x\n\n  example : false :=\n  (not_iff_not_self (shaves barber barber)) (h barber)\nend\n\n\n-- 5\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2203x, A x) \u2192 \u2203x, A x \u2228 B x :=\n  assume Ax,\n  exists.elim Ax $\n  assume x Ax,\n  have A x \u2228 B x, from or.inl Ax,\n  exists.intro x \u2039A x \u2228 B x\u203a\nend\n\n\n-- 6\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  variable h1 : \u2200x, A x \u2192 B x\n  variable h2 : \u2203x, A x\n\n  example : \u2203x, B x :=\n  exists.elim h2 $\n  assume x Ax,\n  exists.intro x (h1 x Ax)\nend\n\n\n-- 7\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example (h1 : \u2203x, A x \u2227 B x) (h2 : \u2200x, B x \u2192 C x) :\n      \u2203x, A x \u2227 C x :=\n      exists.elim h1 $\n      assume x AxBx,\n      have A x, from and.elim_left AxBx,\n      have B x, from and.elim_right AxBx,\n      have C x, from h2 x \u2039B x\u203a,\n      exists.intro x \u27e8\u2039A x\u203a, \u2039C x\u203a\u27e9\nend\n\n\n-- 8\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example : (\u00ac\u2203x, A x) \u2192 \u2200x, \u00acA x :=\n  assume h1 : \u00ac \u2203 x, A x,\n  assume x,\n  assume : A x,\n  have h2 : \u2203 x, A x, from exists.intro x \u2039A x\u203a,\n  h1 h2\nend\n\n\n-- 9\nsection\n  variable  U : Type\n  variables A B C : U \u2192 Prop\n\n  example : (\u2200x, \u00acA x) \u2192 \u00ac\u2203x, A x :=\n  assume h1 : \u2200 x, \u00ac A x,\n  assume h2 : \u2203 x, A x,\n  exists.elim h2 $\n  assume x (_ : A x),\n  have \u00ac A x, from h1 x,\n  show false, from \u2039\u00ac A x\u203a \u2039A x\u203a\nend\n\n\n-- 10\nsection\n  variable  U : Type\n  variables R : U \u2192 U \u2192 Prop\n\n  example : (\u2203x, \u2200y, R x y) \u2192 \u2200y, \u2203x, R x y :=\n    assume h1 : \u2203 x, \u2200 y, R x y,\n   exists.elim h1 $\n   assume x (h2 : \u2200 y, R x y),\n   assume y,\n   have R x y, from h2 y,\n   exists.intro x \u2039R x y\u203a\nend\n", "meta": {"author": "rohanparikh65", "repo": "Discrete-Structures", "sha": "b02f362ccf7e9f2da99405dcbe219fd8db8916ae", "save_path": "github-repos/lean/rohanparikh65-Discrete-Structures", "path": "github-repos/lean/rohanparikh65-Discrete-Structures/Discrete-Structures-b02f362ccf7e9f2da99405dcbe219fd8db8916ae/Assignment-2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7113159950859579}}
{"text": "import data.real.basic\nimport topology.continuous_on\nimport topology.instances.real\nimport topology.basic\nimport tactic\nimport lecture1\n\nopen filter\nopen_locale filter topological_space\n\n/-\nOne alternative definition of what a countinuous function is that if x\u2099 \u2192 a, then f(x\u2099) \u2192 f(a).\n\nFor now, we will use the mathlib definition of continuity, and show that it implies this.\n-/\nlemma tendsto_comp_of_continuous_at {a : \u211d} {f : \u211d \u2192 \u211d} (hf : continuous_at f a) \n  {x : \u2115 \u2192 \u211d} (hx : tendsto x at_top (\ud835\udcdd a)) : tendsto (f \u2218 x) at_top (\ud835\udcdd (f a)) :=\nbegin\n  rw metric.continuous_at_iff at hf,\n  rw metric.tendsto_at_top at \u22a2 hx,\n  intros \u03b5 h\u03b5,\n  rcases hf \u03b5 h\u03b5 with \u27e8\u03b4, h\u03b4pos, h\u03b4\u27e9,\n  rcases hx \u03b4 h\u03b4pos with \u27e8N, hN\u27e9,\n  use N,\n  intros n hn,\n  exact h\u03b4 (hN _ hn),\nend\n\n/-\nSqueeze\n-/\nlemma tendsto_of_le_of_le {x y z : \u2115 \u2192 \u211d} {t : \u211d} (hx : tendsto x at_top (\ud835\udcdd t)) \n  (hz : tendsto z at_top (\ud835\udcdd t)) (hxy : \u2200 n, x n \u2264 y n) (hyz : \u2200 n, y n \u2264 z n) : \n  tendsto y at_top (\ud835\udcdd t) :=\nbegin\n  rw tendsto_seq_iff at *,\n  intros \u03b5 h\u03b5,\n  cases hx (\u03b5/2) (half_pos h\u03b5) with N\u2081 hN\u2081,\n  cases hz (\u03b5/2) (half_pos h\u03b5) with N\u2082 hN\u2082,\n  use max N\u2081 N\u2082,\n  intros n hn,\n  specialize hxy n,\n  specialize hyz n,\n  specialize hN\u2081 n (le_of_max_le_left hn),\n  specialize hN\u2082 n (le_of_max_le_right hn),\n  rw abs_sub_lt_iff at *,\n  cases hN\u2081 with hN\u2081 hN\u2081',\n  cases hN\u2082 with hN\u2082 hN\u2082',\n  split;\n  linarith,\nend\n\n/-\nIf the sequence us bounded below, then so is its limit\n-/\nlemma tendsto_lim_le_of_le' {x : \u2115 \u2192 \u211d} {a A : \u211d} (hx\u2081 : \u2200 n, A \u2264 x n) \n  (hx\u2082 : tendsto x at_top (\ud835\udcdd a)) : A \u2264 a :=\nbegin\n  by_contra h,\n  rw not_le at h,\n  set \u03b5 := A - a with h\u03b5,\n  have h\u03b5' : 0 < \u03b5,\n  { linarith },\n  rw tendsto_seq_iff at hx\u2082,\n  specialize hx\u2082 \u03b5 h\u03b5',\n  cases hx\u2082 with N hN,\n  specialize hN N (le_refl _),\n  rw abs_sub_lt_iff at hN,\n  cases hN,\n  specialize hx\u2081 N,\n  linarith,\nend\n\n/-\nTODO : Loosen requirement to just `hf : continuous_on f (set.Icc a b)`\n\nNote however that with if we change just `hf`, then the statement is not true. That is, there is the\nspecial case where c = a or c = b, and in that case, it is not true that f is continuous at a or b,\nwhen f : \u211d \u2192 \u211d. If we instead had f : set.Icc a b \u2192 \u211d, then it would be true.\n-/\nlemma ivt {a b : \u211d} (h : a < b) (f : \u211d \u2192 \u211d) (hf : continuous f) (hfab : f a < f b) \n  {\u03b7 : \u211d} (h\u03b7 : \u03b7 \u2208 set.Ioo (f a) (f b)) : \u2203 c \u2208 set.Icc a b, f c = \u03b7 :=\nbegin\n  -- Let S be the set of all x such that f(x) < \u03b7\n  let S := {x | f x < \u03b7 \u2227 x \u2208 set.Icc a b},\n  -- S is nonempty\n  have hS\u2081 : \u2203 k, k \u2208 S := \u27e8a, h\u03b7.1, le_refl _, le_of_lt h\u27e9,\n  -- and bounded above, so Sup S exists.\n  have hS\u2082 : \u2203 k, \u2200 x \u2208 S, x \u2264 k := \u27e8b, \u03bb _ \u27e8_, _, hx\u27e9, hx\u27e9,\n  have hbS : b \u2209 S,\n  { rintro \u27e8h, -\u27e9,\n    cases h\u03b7,\n    linarith },\n  -- Let c := Sup S.\n  let c := Sup S,\n  -- Then a \u2264 c \u2264 b\n  have hac : a \u2264 c := real.le_Sup _ hS\u2082 \u27e8h\u03b7.1, le_refl _, le_of_lt h\u27e9,\n  have hbc : c \u2264 b := real.Sup_le_ub _ hS\u2081 (\u03bb x \u27e8_, _, hx\u27e9, hx),\n  -- We also have that f(x) is continuous at c\n  have hcontc : continuous_at f c := hf.continuous_at,\n  -- Now, we claim that f(c) = \u03b7\n  use c,\n  refine \u27e8\u27e8real.le_Sup S hS\u2082 \u27e8h\u03b7.1, le_refl _, le_of_lt h\u27e9, hbc\u27e9, _\u27e9,\n  -- We will do this by showing f(c) \u2264 \u03b7, and \u03b7 \u2264 f(c). However the proof for \u03b7 \u2264 f(c) requires \n  -- f(c) \u2264 \u03b7, so we prove this separately.\n  have hc\u03b7 : f c \u2264 \u03b7,\n  -- Let c\u2082(n) := c - 1/n\n  { let c\u2082 : \u2115 \u2192 \u211d := \u03bb n, c - (1/(n+1)),\n    -- Then c\u2082(n) \u2192 c as n \u2192 \u221e\n    have hc\u2082 : tendsto c\u2082 at_top (\ud835\udcdd c),\n    { convert @filter.tendsto.sub \u2115 \u211d _ _ _ (\u03bb n, c) (\u03bb n, 1/(n+1)) _ c 0 tendsto_const_nhds tendsto_one_div,\n      exact (sub_zero _).symm, },\n    -- and for all n, c\u2082(n) < c\n    have hc\u2082' : \u2200 n, c\u2082 n < c,\n    { intro n,\n      change c - (1/(n+1)) < c,\n      simp only [one_div, sub_lt_self_iff, inv_pos],\n      linarith [@nat.cast_nonneg \u211d _ n] },\n    -- Then, for each n, there exists some x \u2208 S such that c\u2082(n) < x \u2264 c, as C = Sup S.\n    have hc\u2082'' : \u2200 n, \u2203 x \u2208 S, c\u2082 n < x \u2227 x \u2264 c,\n    { intro n,\n      rcases (real.lt_Sup _ hS\u2081 hS\u2082).mp (hc\u2082' n) with \u27e8z, hz\u2081, hz\u2082\u27e9,\n      use [z, hz\u2081, hz\u2082, real.le_Sup _ hS\u2082 hz\u2081] }, \n    -- Using this, we can define a sequence x\u2099.\n    let x : \u2115 \u2192 \u211d := \u03bb n, classical.some (hc\u2082'' n),\n    -- Next, we can show that for all n, f(x\u2099) < \u03b7.\n    have hx\u2081 : \u2200 n, f (x n) < \u03b7,\n    { intro n,\n      rcases classical.some_spec (hc\u2082'' n) with \u27e8\u27e8hx : f (x n) < \u03b7, -\u27e9, -\u27e9,\n      exact hx },\n    -- and by the squeeze theorem, x\u2099 \u2192 c.\n    have hx\u2082 : tendsto x at_top (\ud835\udcdd c),\n    { apply tendsto_of_le_of_le hc\u2082 tendsto_const_nhds,\n      { intro n,\n        rcases classical.some_spec (hc\u2082'' n) with \u27e8\u27e8-, -\u27e9, hx : c\u2082 n < x n, -\u27e9,\n        exact le_of_lt hx },\n      { intro n,\n        rcases classical.some_spec (hc\u2082'' n) with \u27e8\u27e8-, -\u27e9, -, hx : x n \u2264 c\u27e9,\n        exact hx } },\n    -- so now we get that f(x\u2099) \u2192 f(c) and f(c) \u2264 \u03b7.\n    apply tendsto_lim_le_of_le,\n    { intro n,\n      apply le_of_lt (hx\u2081 n) },\n    { exact tendsto_comp_of_continuous_at hcontc hx\u2082 } },\n  -- Now, all we need to do is to show that \u03b7 \u2264 f(c).\n  { apply le_antisymm hc\u03b7,\n    have hc\u2081 : c \u2264 b,\n    { apply real.Sup_le_ub _ hS\u2081,\n      rintros x \u27e8-, -, hx\u27e9,\n      exact hx },\n    have hc\u2082 : c < b,\n    { apply lt_of_le_of_ne hc\u2081,\n      intro h,\n      have : f b \u2264 \u03b7,\n      { rwa h at hc\u03b7 },\n      cases h\u03b7,\n      linarith },\n    have hbc : 0 < b - c,\n    { linarith },\n    cases exists_nat_one_div_lt hbc with n hn,\n    let x : \u2115 \u2192 \u211d := \u03bb i, c + 1/(n + i + 1),\n    have hx\u2081 : tendsto x at_top (\ud835\udcdd c),\n    { convert @filter.tendsto.add \u2115 \u211d _ _ _ (\u03bb i, c) (\u03bb i, 1/(n+i+1)) _ c 0 tendsto_const_nhds _,\n      { exact (add_zero _).symm },\n      convert @tendsto_subseq _ _ (\u03bb i, n + i) _ tendsto_one_div,\n      { ext j,\n        change (1/(n+j+1) : \u211d) = 1/((n+j : \u2115)+1),\n        rw [nat.cast_add] },\n      intro k,\n      dsimp only,\n      rw \u2190add_assoc,\n      exact nat.lt_succ_self _ },\n    have hx\u2082 : \u2200 i, x i \u2208 set.Icc a b,\n    { intro i,\n      split,\n      { change a \u2264 c + 1/(n + i + 1),\n        have h\u2081: a \u2264 c := real.le_Sup _ hS\u2082 \u27e8h\u03b7.1, le_refl _, le_of_lt h\u27e9,\n        have h\u2082 : (0 : \u211d) < 1/(n + i + 1),\n        { rw one_div_pos,\n          linarith [@nat.cast_nonneg \u211d _ n, @nat.cast_nonneg \u211d _ i] },\n        linarith },\n      { change c + 1/(n + i + 1) \u2264 b,\n        have : (1/(n + i + 1) : \u211d) \u2264 1/(n + 1),\n        { rw one_div_le_one_div;\n          linarith [@nat.cast_nonneg \u211d _ n, @nat.cast_nonneg \u211d _ i] },\n        linarith } },\n    have hx\u2083 : \u2200 i, \u03b7 \u2264 f (x i),\n    { intro i,\n      by_contra hcontra,\n      rw not_le at hcontra,\n      have hxS : x i \u2208 S,\n      { exact \u27e8hcontra, hx\u2082 i\u27e9 },\n      have hxc : x i \u2264 c,\n      { exact real.le_Sup _ hS\u2082 hxS },\n      have h\u2081 : (0 : \u211d) < 1/(n + i + 1),\n      { rw one_div_pos,\n        linarith [@nat.cast_nonneg \u211d _ n, @nat.cast_nonneg \u211d _ i] },\n      change c + 1/(n+i+1) \u2264 c at hxc,\n      linarith },\n    exact tendsto_lim_le_of_le' hx\u2083 (tendsto_comp_of_continuous_at hcontc hx\u2081), }\nend\n", "meta": {"author": "shingtaklam1324", "repo": "analysis-i", "sha": "928dd413014ca6668560c504592e0a15a83ea63a", "save_path": "github-repos/lean/shingtaklam1324-analysis-i", "path": "github-repos/lean/shingtaklam1324-analysis-i/analysis-i-928dd413014ca6668560c504592e0a15a83ea63a/src/ivt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7113159947477209}}
{"text": "-- bundled subgroups\n\n-- We're going to make one object which is all the subgroups of G.\n\n-- first let's do some tests\n\nimport group_theory.subgroup\nimport algebra.group.hom\n\n\n --#print notation \u21a5 \n --coe_sort #0\n --#print notation \u2191\n --coe\n\nexample (G1 G2 : Type*) [group G1] [group G2]\n  (f : G1 \u2192 G2) [is_group_hom f] (H1 : set G1) [is_subgroup H1] (a b : H1) :\n  is_subgroup (f '' H1) :=\n{ one_mem := \nbegin\nshow (1:G2) \u2208 f '' H1,\nunfold set.image,\nuse (1),\nsplit,\n{exact is_submonoid.one_mem H1},\n{exact is_group_hom.map_one f}    \nend,\n  mul_mem := \n  begin\n -- intro j,\n -- intro k,\n -- intro n,\n -- change j \u2208 f '' H1 at n,\n -- intro m,\n -- change k \u2208 f '' H1 at m,\n -- show j*k \u2208 f '' H1,\n -- cases n with j' hj',\n -- cases m with k' hk',\n  \n  rintro j k \u27e8j', hj', rfl\u27e9 \u27e8k', hk', rfl\u27e9,\n  show (f j') * (f k') \u2208 f '' H1,\n  rw [\u2190 is_mul_hom.map_mul f j' k'],\n unfold set.image,\n dsimp,\n use j'*k',\n split,\n   apply is_submonoid.mul_mem,\n     assumption,\n   assumption,\n refl,  \n-- need to get rid of the fs\n  --apply is_submonoid.mul_mem,\n  end,\n  \n  inv_mem := \n  begin\n  --intro j,\n  --intro n,\n  --change j \u2208 f '' H1 at n,\n  --show j\u207b\u00b9 \u2208 f '' H1,\n \n\n rintro j \u27e8j', hj', rfl\u27e9,\n show (f j')\u207b\u00b9 \u2208 f '' H1,\n rw [\u2190 is_group_hom.map_inv f j'],\n unfold set.image,\n dsimp,\n use j'\u207b\u00b9,\n split,\n   rw [is_subgroup.inv_mem_iff H1],\n   assumption,\nrefl,\n-- need to get rid of the fs\n --rw [is_subgroup.inv_mem_iff H1],\n  end\n   }\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "lean-groups", "sha": "9a82d2a66ef7f549107fcb4e1504d734c43ebb33", "save_path": "github-repos/lean/ImperialCollegeLondon-lean-groups", "path": "github-repos/lean/ImperialCollegeLondon-lean-groups/lean-groups-9a82d2a66ef7f549107fcb4e1504d734c43ebb33/src/subgroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7113159923232375}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies, Ella Yu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Ella Yu\n\n! This file was ported from Lean 3 source module combinatorics.additive.energy\n! leanprover-community/mathlib commit 327c3c0d9232d80e250dc8f65e7835b82b266ea5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Finset.Prod\nimport Mathbin.Data.Fintype.Prod\n\n/-!\n# Additive energy\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the additive energy of two finsets of a group. This is a central quantity in\nadditive combinatorics.\n\n## TODO\n\nIt's possibly interesting to have\n`(s \u00d7\u02e2 s) \u00d7\u02e2 t \u00d7\u02e2 t).filter (\u03bb x : (\u03b1 \u00d7 \u03b1) \u00d7 \u03b1 \u00d7 \u03b1, x.1.1 * x.2.1 = x.1.2 * x.2.2)` (whose `card` is\n`multiplicative_energy s t`) as a standalone definition.\n-/\n\n\nsection\n\nvariable {\u03b1 : Type _} [PartialOrder \u03b1] {x y : \u03b1}\n\nend\n\nvariable {\u03b1 : Type _} [DecidableEq \u03b1]\n\nnamespace Finset\n\nsection Mul\n\nvariable [Mul \u03b1] {s s\u2081 s\u2082 t t\u2081 t\u2082 : Finset \u03b1}\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n#print Finset.multiplicativeEnergy /-\n/-- The multiplicative energy of two finsets `s` and `t` in a group is the number of quadruples\n`(a\u2081, a\u2082, b\u2081, b\u2082) \u2208 s \u00d7 s \u00d7 t \u00d7 t` such that `a\u2081 * b\u2081 = a\u2082 * b\u2082`. -/\n@[to_additive additive_energy\n      \"The additive energy of two finsets `s` and `t` in a group is the\\nnumber of quadruples `(a\u2081, a\u2082, b\u2081, b\u2082) \u2208 s \u00d7 s \u00d7 t \u00d7 t` such that `a\u2081 + b\u2081 = a\u2082 + b\u2082`.\"]\ndef multiplicativeEnergy (s t : Finset \u03b1) : \u2115 :=\n  (((s \u00d7\u02e2 s) \u00d7\u02e2 t \u00d7\u02e2 t).filter\u2093 fun x : (\u03b1 \u00d7 \u03b1) \u00d7 \u03b1 \u00d7 \u03b1 => x.1.1 * x.2.1 = x.1.2 * x.2.2).card\n#align finset.multiplicative_energy Finset.multiplicativeEnergy\n#align finset.additive_energy Finset.additiveEnergy\n-/\n\n#print Finset.multiplicativeEnergy_mono /-\n@[to_additive additive_energy_mono]\ntheorem multiplicativeEnergy_mono (hs : s\u2081 \u2286 s\u2082) (ht : t\u2081 \u2286 t\u2082) :\n    multiplicativeEnergy s\u2081 t\u2081 \u2264 multiplicativeEnergy s\u2082 t\u2082 :=\n  card_le_of_subset <|\n    filter_subset_filter _ <|\n      product_subset_product (product_subset_product hs hs) <| product_subset_product ht ht\n#align finset.multiplicative_energy_mono Finset.multiplicativeEnergy_mono\n#align finset.additive_energy_mono Finset.additiveEnergy_mono\n-/\n\n#print Finset.multiplicativeEnergy_mono_left /-\n@[to_additive additive_energy_mono_left]\ntheorem multiplicativeEnergy_mono_left (hs : s\u2081 \u2286 s\u2082) :\n    multiplicativeEnergy s\u2081 t \u2264 multiplicativeEnergy s\u2082 t :=\n  multiplicativeEnergy_mono hs Subset.rfl\n#align finset.multiplicative_energy_mono_left Finset.multiplicativeEnergy_mono_left\n#align finset.additive_energy_mono_left Finset.additiveEnergy_mono_left\n-/\n\n#print Finset.multiplicativeEnergy_mono_right /-\n@[to_additive additive_energy_mono_right]\ntheorem multiplicativeEnergy_mono_right (ht : t\u2081 \u2286 t\u2082) :\n    multiplicativeEnergy s t\u2081 \u2264 multiplicativeEnergy s t\u2082 :=\n  multiplicativeEnergy_mono Subset.rfl ht\n#align finset.multiplicative_energy_mono_right Finset.multiplicativeEnergy_mono_right\n#align finset.additive_energy_mono_right Finset.additiveEnergy_mono_right\n-/\n\n#print Finset.le_multiplicativeEnergy /-\n@[to_additive le_additive_energy]\ntheorem le_multiplicativeEnergy : s.card * t.card \u2264 multiplicativeEnergy s t :=\n  by\n  rw [\u2190 card_product]\n  refine'\n    card_le_card_of_inj_on (fun x => ((x.1, x.1), x.2, x.2)) (by simp [\u2190 and_imp]) fun a _ b _ => _\n  simp only [Prod.mk.inj_iff, and_self_iff, and_imp]\n  exact Prod.ext\n#align finset.le_multiplicative_energy Finset.le_multiplicativeEnergy\n#align finset.le_additive_energy Finset.le_additiveEnergy\n-/\n\n#print Finset.multiplicativeEnergy_pos /-\n@[to_additive additive_energy_pos]\ntheorem multiplicativeEnergy_pos (hs : s.Nonempty) (ht : t.Nonempty) :\n    0 < multiplicativeEnergy s t :=\n  (mul_pos hs.card_pos ht.card_pos).trans_le le_multiplicativeEnergy\n#align finset.multiplicative_energy_pos Finset.multiplicativeEnergy_pos\n#align finset.additive_energy_pos Finset.additiveEnergy_pos\n-/\n\nvariable (s t)\n\n#print Finset.multiplicativeEnergy_empty_left /-\n@[simp, to_additive additive_energy_empty_left]\ntheorem multiplicativeEnergy_empty_left : multiplicativeEnergy \u2205 t = 0 := by\n  simp [multiplicative_energy]\n#align finset.multiplicative_energy_empty_left Finset.multiplicativeEnergy_empty_left\n#align finset.additive_energy_empty_left Finset.additiveEnergy_empty_left\n-/\n\n#print Finset.multiplicativeEnergy_empty_right /-\n@[simp, to_additive additive_energy_empty_right]\ntheorem multiplicativeEnergy_empty_right : multiplicativeEnergy s \u2205 = 0 := by\n  simp [multiplicative_energy]\n#align finset.multiplicative_energy_empty_right Finset.multiplicativeEnergy_empty_right\n#align finset.additive_energy_empty_right Finset.additiveEnergy_empty_right\n-/\n\nvariable {s t}\n\n#print Finset.multiplicativeEnergy_pos_iff /-\n@[simp, to_additive additive_energy_pos_iff]\ntheorem multiplicativeEnergy_pos_iff : 0 < multiplicativeEnergy s t \u2194 s.Nonempty \u2227 t.Nonempty :=\n  \u27e8fun h =>\n    of_not_not fun H => by\n      simp_rw [not_and_or, not_nonempty_iff_eq_empty] at H\n      obtain rfl | rfl := H <;> simpa [Nat.not_lt_zero] using h,\n    fun h => multiplicativeEnergy_pos h.1 h.2\u27e9\n#align finset.multiplicative_energy_pos_iff Finset.multiplicativeEnergy_pos_iff\n#align finset.additive_energy_pos_iff Finset.additiveEnergy_pos_iff\n-/\n\n#print Finset.multiplicativeEnergy_eq_zero_iff /-\n@[simp, to_additive additive_energy_eq_zero_iff]\ntheorem multiplicativeEnergy_eq_zero_iff : multiplicativeEnergy s t = 0 \u2194 s = \u2205 \u2228 t = \u2205 := by\n  simp [\u2190 (Nat.zero_le _).not_gt_iff_eq, not_and_or]\n#align finset.multiplicative_energy_eq_zero_iff Finset.multiplicativeEnergy_eq_zero_iff\n#align finset.additive_energy_eq_zero_iff Finset.additive_energy_eq_zero_iff\n-/\n\nend Mul\n\nsection CommMonoid\n\nvariable [CommMonoid \u03b1]\n\n/- warning: finset.multiplicative_energy_comm -> Finset.multiplicativeEnergy_comm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : DecidableEq.{succ u1} \u03b1] [_inst_2 : CommMonoid.{u1} \u03b1] (s : Finset.{u1} \u03b1) (t : Finset.{u1} \u03b1), Eq.{1} Nat (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (CommMonoid.toMonoid.{u1} \u03b1 _inst_2))) s t) (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (CommMonoid.toMonoid.{u1} \u03b1 _inst_2))) t s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : DecidableEq.{succ u1} \u03b1] [_inst_2 : CommMonoid.{u1} \u03b1] (s : Finset.{u1} \u03b1) (t : Finset.{u1} \u03b1), Eq.{1} Nat (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (CommMonoid.toMonoid.{u1} \u03b1 _inst_2))) s t) (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (CommMonoid.toMonoid.{u1} \u03b1 _inst_2))) t s)\nCase conversion may be inaccurate. Consider using '#align finset.multiplicative_energy_comm Finset.multiplicativeEnergy_comm\u2093'. -/\n@[to_additive additive_energy_comm]\ntheorem multiplicativeEnergy_comm (s t : Finset \u03b1) :\n    multiplicativeEnergy s t = multiplicativeEnergy t s :=\n  by\n  rw [multiplicative_energy, \u2190 Finset.card_map (Equiv.prodComm _ _).toEmbedding, map_filter]\n  simp [-Finset.card_map, eq_comm, multiplicative_energy, mul_comm, map_eq_image, Function.comp]\n#align finset.multiplicative_energy_comm Finset.multiplicativeEnergy_comm\n#align finset.additive_energy_comm Finset.additiveEnergy_comm\n\nend CommMonoid\n\nsection CommGroup\n\nvariable [CommGroup \u03b1] [Fintype \u03b1] (s t : Finset \u03b1)\n\n/- warning: finset.multiplicative_energy_univ_left -> Finset.multiplicativeEnergy_univ_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : DecidableEq.{succ u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : Fintype.{u1} \u03b1] (t : Finset.{u1} \u03b1), Eq.{1} Nat (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) (Finset.univ.{u1} \u03b1 _inst_3) t) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Fintype.card.{u1} \u03b1 _inst_3) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) (Finset.card.{u1} \u03b1 t) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : DecidableEq.{succ u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : Fintype.{u1} \u03b1] (t : Finset.{u1} \u03b1), Eq.{1} Nat (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) (Finset.univ.{u1} \u03b1 _inst_3) t) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Fintype.card.{u1} \u03b1 _inst_3) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) (Finset.card.{u1} \u03b1 t) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))))\nCase conversion may be inaccurate. Consider using '#align finset.multiplicative_energy_univ_left Finset.multiplicativeEnergy_univ_left\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[simp, to_additive additive_energy_univ_left]\ntheorem multiplicativeEnergy_univ_left :\n    multiplicativeEnergy univ t = Fintype.card \u03b1 * t.card ^ 2 :=\n  by\n  simp only [multiplicative_energy, univ_product_univ, Fintype.card, sq, \u2190 card_product]\n  set f : \u03b1 \u00d7 \u03b1 \u00d7 \u03b1 \u2192 (\u03b1 \u00d7 \u03b1) \u00d7 \u03b1 \u00d7 \u03b1 := fun x => ((x.1 * x.2.2, x.1 * x.2.1), x.2) with hf\n  have : (\u2191((univ : Finset \u03b1) \u00d7\u02e2 t \u00d7\u02e2 t) : Set (\u03b1 \u00d7 \u03b1 \u00d7 \u03b1)).InjOn f :=\n    by\n    rintro \u27e8a\u2081, b\u2081, c\u2081\u27e9 h\u2081 \u27e8a\u2082, b\u2082, c\u2082\u27e9 h\u2082 h\n    simp_rw [Prod.ext_iff] at h\n    obtain \u27e8h, rfl, rfl\u27e9 := h\n    rw [mul_right_cancel h.1]\n  rw [\u2190 card_image_of_inj_on this]\n  congr with a\n  simp only [hf, mem_filter, mem_product, mem_univ, true_and_iff, mem_image, exists_prop,\n    Prod.exists]\n  refine' \u27e8fun h => \u27e8a.1.1 * a.2.2\u207b\u00b9, _, _, h.1, by simp [mul_right_comm, h.2]\u27e9, _\u27e9\n  rintro \u27e8b, c, d, hcd, rfl\u27e9\n  simpa [mul_right_comm]\n#align finset.multiplicative_energy_univ_left Finset.multiplicativeEnergy_univ_left\n#align finset.additive_energy_univ_left Finset.additiveEnergy_univ_left\n\n/- warning: finset.multiplicative_energy_univ_right -> Finset.multiplicativeEnergy_univ_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : DecidableEq.{succ u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : Fintype.{u1} \u03b1] (s : Finset.{u1} \u03b1), Eq.{1} Nat (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) s (Finset.univ.{u1} \u03b1 _inst_3)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Fintype.card.{u1} \u03b1 _inst_3) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) (Finset.card.{u1} \u03b1 s) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : DecidableEq.{succ u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : Fintype.{u1} \u03b1] (s : Finset.{u1} \u03b1), Eq.{1} Nat (Finset.multiplicativeEnergy.{u1} \u03b1 (fun (a : \u03b1) (b : \u03b1) => _inst_1 a b) (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) s (Finset.univ.{u1} \u03b1 _inst_3)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Fintype.card.{u1} \u03b1 _inst_3) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) (Finset.card.{u1} \u03b1 s) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))))\nCase conversion may be inaccurate. Consider using '#align finset.multiplicative_energy_univ_right Finset.multiplicativeEnergy_univ_right\u2093'. -/\n@[simp, to_additive additive_energy_univ_right]\ntheorem multiplicativeEnergy_univ_right :\n    multiplicativeEnergy s univ = Fintype.card \u03b1 * s.card ^ 2 := by\n  rw [multiplicative_energy_comm, multiplicative_energy_univ_left]\n#align finset.multiplicative_energy_univ_right Finset.multiplicativeEnergy_univ_right\n#align finset.additive_energy_univ_right Finset.additiveEnergy_univ_right\n\nend CommGroup\n\nend Finset\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/Additive/Energy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7113159864027353}}
{"text": "import Mathlib.Data.Nat.Basic\nimport Mathlib.Tactic.Linarith\n\n/- \n# Sorting a list\n\n-/\n\nnamespace Notes\n\nvariable {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [DecidableRel r]\n\n/- \nWe sort lists of type `\u03b1` using the comparison function \n`f` (or `r`). \n\nIf `f a\u2081 a\u2082 = true`, then this is the \"correct\" order. \nOtherwise, it is \"incorrect\"\n\nIf `r a\u2081 a\u2082` has a proof, then this is the \"correct\" order. \nOtherwise, it is \"incorrect\"\n\nWhat are some examples of sorted lists?\n\n- [] is should be sorted\n- for any `a:\u03b1`, then `[a]` is sorted \n- for any `a\u2081 a\u2082 : \u03b1` and any `as : List \u03b1` such that \n  `f a\u2081 a\u2082  = true` and `a\u2082 :: as` is sorted, then \n  `a\u2081 :: a\u2082 :: as` is sorted \n-/\n\ninductive Sorted (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : List \u03b1 \u2192 Prop where \n  | nil : Sorted r []\n  | single {a : \u03b1} : Sorted r [a]\n  | longer {a\u2081 a\u2082 : \u03b1} {as : List \u03b1} (h : r a\u2081 a\u2082) \n    (h' : Sorted r (a\u2082 :: as)) : Sorted r (a\u2081::a\u2082::as)\n\nopen Sorted\n\n/- We can check that particular lists are `Sorted` -/\nexample : Sorted (\u00b7\u2264\u00b7) [1,2,3] := by \n  apply longer\n  \u00b7 simp \n  \u00b7 apply longer \n    \u00b7 simp \n    \u00b7 apply single\n\n/- We can also prove basic facts about our implementation \nof sorted lists -/\ntheorem sorted_tail_of_sorted (a : \u03b1) (as : List \u03b1) \n    (h : Sorted r (a::as)) : Sorted r as := by\n  match h with \n  | single => apply nil  \n  | longer _ h'' => exact h''\n\n/- We now we want to implement an algortihm to sort \nlists and then _prove_ that it always produces a `Sorted` \nlist. \n\nWe will use insert sort. We will recursively sort the \ntail of a list and then insert the head in the \nappropriate place. We first give the insertion function.-/\n\n/-- \n`insert` places `a` before the first element `a'` \nof `l` which satisfies `f a a'`. \n-/\ndef insert (a : \u03b1) (l : List \u03b1) : List \u03b1 :=\n  match l with \n  | [] => [a] \n  | a'::as => \n    if r a a' then a::a'::as else a'::insert a as\n\n#check insert \n\n/- We prove a basic result about the length of inserted \nlist and tag it with `@[simp]` for use with `simp` -/\n@[simp]\ntheorem len_insert_eq_succ_len {a : \u03b1} {l : List \u03b1} : \n    (insert r a l).length = l.length + 1 := \n  match l with \n  | [] => by simp [insert]\n  | a'::as =>\n    if h : r a a' then by simp [insert, h] else\n    by simp [insert, h]; apply len_insert_eq_succ_len \n\n/--\nWe sort `l` recursively sorting the tail first and then \ninserting the head at the appropriate location.\n-/\ndef insertSort (l : List \u03b1) : List \u03b1 :=\n  match l with \n  | [] => [] \n  | a::as => insert r a <| insertSort as\n\n#check insertSort\n\n/- Some examples our polymorphic sorting algorithm applies to -/\n#eval insertSort (\u00b7\u2264\u00b7) [4,5,2,4,5,6]\n#eval insertSort (fun (b b' : Bool) => b && b') [true,false,false]\n#eval insertSort (fun _ _ => true) [4,5,2,4,5,6]\n\n\n/- For a general `f`, we will not be able to show that the \noutput of `insert f l` satsisfies `Sorted f l`. For example, \nfor `fun _ _ => false`, if we have `Sorted f l` then \n`l.length` is 0 or 1. This is a reasonable class of `f` to \nmake sorting work as expected -/\nclass Asymmetric (r : \u03b1 \u2192 \u03b1 \u2192 Prop) where\n  asym {a a'} : \u00ac r a a' \u2192 r a' a\n\nopen Asymmetric\n\n/- A helpful constructor for `Sorted` that unifies the \nnonempty cases -/\ndef Sorted.cons {a : \u03b1} {l : List \u03b1} (h\u2081 : Sorted r l) \n    (h\u2082 : l.length > 0) (h\u2083 : r a l[0]) : Sorted r (a::l) :=\n  match h\u2081 with \n  | nil => single\n  | single => longer h\u2083 single\n  | longer h h' => longer h\u2083 <| longer h h'\n\n/- If we have a `Sorted` list with at least two elements, \nthen the first elements are ordered appropriately with \nrespect to `f` -/\ntheorem ordered_of_sorted {a a' : \u03b1} {as : List \u03b1} \n    (h : Sorted r (a::a'::as)) : r a a' :=\n  match h with \n  | longer h' _ => h'\n\n/- If we have a `Sorted` list `a'::as` where `a` and `a'` are \nordered wrong, then the first two elements of `a'::insert f a as` \nare ordered correctly -/\ntheorem ordered_cons_insert_of_unordered {a a' : \u03b1} {as : List \u03b1}\n    (h : Sorted r (a'::as)) (h' : r a' a) : r a' (insert r a as)[0] :=\n  match as with \n  | [] => by simp [insert]; assumption\n  | a''::as' => \n    if h'' : r a a'' then\n    by simpa [insert, h'']\n    else\n    by simp [insert, h'']; apply ordered_of_sorted r h\n\n/- We prove that if we insert an element into a `Sorted` list \nit will remain `Sorted` assuming `f` is `Asymmetric` -/\ntheorem insert_sorted_of_sorted {a : \u03b1} {l : List \u03b1} [Asymmetric r] \n    (h : Sorted r l) : Sorted r <| insert r a l :=\n  match l with \n  | [] => single\n  | a'::as =>\n    if h' : r a a' then \n    by simp [insert, h']; apply longer h' h \n    else\n    by\n      simp [insert, h']\n      apply cons r\n      \u00b7 apply insert_sorted_of_sorted <| sorted_tail_of_sorted r a' as h   \n      \u00b7 apply ordered_cons_insert_of_unordered r h \n        \u00b7 apply asym; simp; assumption\n\n/- Finally, we prove that if `f` is `Asymmetric` then `insertSort` \nalways produces a `Sorted` list no matter `\u03b1` or `f` -/\ntheorem sorted_of_insertSort (l : List \u03b1) [Asymmetric r] : \n    Sorted r <| insertSort r l :=\n  match l with \n  | [] => nil\n  | a::as => by\n    dsimp [insertSort]\n    apply insert_sorted_of_sorted r <| sorted_of_insertSort as\n\nvariable [Trans r r r]\n\nclass Transitive (r : \u03b1 \u2192 \u03b1 \u2192 Prop) where\n  trans' {a\u2081 a\u2082 a\u2083} : r a\u2081 a\u2082 \u2192 r a\u2082 a\u2083 \u2192 r a\u2081 a\u2083 \n\ntheorem Nat.succ_of_lt {i j : \u2115} (h : i < j) : \u2203 l, l+1 = j := sorry\n\nopen Transitive\n\ntheorem totally_ordered_of_sorted [Transitive r] {l : List \u03b1} (h : Sorted r l) :\n    \u2200 {i j : \u2115}, (i < j) \u2192 (_ : i < l.length) \u2192 (_ : j < l.length) \u2192 r l[i] l[j] :=\n  match h with\n  | nil => fun _ h' _ => False.elim <| by\n    rw [List.length_nil] at h'\n    exact Nat.not_lt_zero _ h'\n  | single => fun h hi hj => by \n    dsimp at hi hj\n    apply False.elim\n    linarith\n  | longer h\u2081 h\u2082 => by \n    intro h' hi hj\n    rename_i i j a\u2081 a\u2082 as\n    have \u27e8l,hl\u27e9 := Nat.succ_of_lt h'\n    rw [\u2190hl] at hj h'\n    simp only [\u2190hl]\n    have : l < (a\u2082 :: as).length := \n      Nat.pred_lt_pred (by simp) hj\n    have hl' : (a\u2081::a\u2082::as)[l+1] = (a\u2082::as)[l] := rfl\n    by_cases i = 0 \n    \u00b7 simp [h,hl'] at *\n      by_cases l = 0\n      \u00b7 simp [h,h\u2081] \n      \u00b7 apply trans'\n        . exact h\u2081 \n        \u00b7 change r (a\u2082::as)[0] (a\u2082::as)[l]\n          apply totally_ordered_of_sorted h\u2082\n          apply Nat.one_le_iff_ne_zero.mpr h\n    \u00b7 have \u27e8k,hk\u27e9 := Nat.exists_eq_succ_of_ne_zero h\n      rw [hk] at hi h'\n      simp only [hk]\n      have : k < (a\u2082::as).length :=\n        Nat.pred_lt_pred (by simp) hi\n      have hk' : (a\u2081::a\u2082::as)[k+1] = (a\u2082::as)[k] := rfl\n      rw [hk',hl']\n      apply totally_ordered_of_sorted h\u2082 \n      apply Nat.pred_lt_pred (by simp) h'\n", "meta": {"author": "UofSC-Spring-2023-SCHC-411-H01", "repo": "notes", "sha": "ef57142df34fbe92f6204d8eb636ec5061729bd0", "save_path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes", "path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes/notes-ef57142df34fbe92f6204d8eb636ec5061729bd0/Notes4/IndPred2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7113159818920055}}
{"text": "import Mathlib.Data.Nat.Basic\n\n/- \n# Sorting a list\n\n-/\n\nnamespace Notes\n\nvariable {\u03b1 : Type} (f : \u03b1 \u2192 \u03b1 \u2192 Bool) (r : \u03b1 \u2192 \u03b1 \u2192 Prop) \n\n/- \nWe sort lists of type `\u03b1` using the comparison function \n`f` (or `r`). \n\nIf `f a\u2081 a\u2082 = true`, then this is the \"correct\" order. \nOtherwise, it is \"incorrect\"\n\nIf `r a\u2081 a\u2082` has a proof, then this is the \"correct\" order. \nOtherwise, it is \"incorrect\"\n\nWhat are some examples of sorted lists?\n\n- [] is should be sorted\n- for any `a:\u03b1`, then `[a]` is sorted \n- for any `a\u2081 a\u2082 : \u03b1` and any `as : List \u03b1` such that \n  `f a\u2081 a\u2082  = true` and `a\u2082 :: as` is sorted, then \n  `a\u2081 :: a\u2082 :: as` is sorted \n-/\n\ninductive Sorted (f : \u03b1 \u2192 \u03b1 \u2192 Bool) : List \u03b1 \u2192 Prop where \n  | nil : Sorted f []\n  | single {a : \u03b1} : Sorted f [a]\n  | longer {a\u2081 a\u2082 : \u03b1} {as : List \u03b1} (h : f a\u2081 a\u2082) \n    (h' : Sorted f (a\u2082 :: as)) : Sorted f (a\u2081::a\u2082::as)\n\nopen Sorted\n\n/- We can check that particular lists are `Sorted` -/\nexample : Sorted (\u00b7\u2264\u00b7) [1,2,3] := by \n  apply longer\n  \u00b7 simp \n  \u00b7 apply longer \n    \u00b7 simp \n    \u00b7 apply single\n\n/- We can also prove basic facts about our implementation \nof sorted lists -/\ntheorem sorted_tail_of_sorted (a : \u03b1) (as : List \u03b1) \n    (h : Sorted f (a::as)) : Sorted f as := by\n  match h with \n  | single => apply nil  \n  | longer _ h'' => exact h''\n\n/- We now we want to implement an algortihm to sort \nlists and then _prove_ that it always produces a `Sorted` \nlist. \n\nWe will use insert sort. We will recursively sort the \ntail of a list and then insert the head in the \nappropriate place. We first give the insertion function.-/\n\n/-- \n`insert` places `a` before the first element `a'` \nof `l` which satisfies `f a a'`. \n-/\ndef insert (a : \u03b1) (l : List \u03b1) : List \u03b1 :=\n  match l with \n  | [] => [a] \n  | a'::as => \n    match f a a' with \n    | true => a::a'::as \n    | false => a'::insert a as \n\n#check insert \n\n/- We prove a basic result about the length of inserted \nlist and tag it with `@[simp]` for use with `simp` -/\n@[simp]\ntheorem len_insert_eq_succ_len {a : \u03b1} {l : List \u03b1} : \n    (insert f a l).length = l.length + 1 := by \n  match l with \n  | [] => simp [insert]\n  | a'::as =>\n    match h : f a a' with \n    | true => simp [insert, h]\n    | false => simp [insert, h]; apply len_insert_eq_succ_len \n\n/--\nWe sort `l` recursively sorting the tail first and then \ninserting the head at the appropriate location.\n-/\ndef insertSort (l : List \u03b1) : List \u03b1 :=\n  match l with \n  | [] => [] \n  | a::as => insert f a <| insertSort as\n\n#check insertSort\n\n/- Some examples our polymorphic sorting algorithm applies to -/\n#eval insertSort (\u00b7\u2264\u00b7) [4,5,2,4,5,6]\n#eval insertSort (fun (b b' : Bool) => b && b') [true,false,false]\n#eval insertSort (fun _ _ => true) [4,5,2,4,5,6]\n\n\n/- For a general `f`, we will not be able to show that the \noutput of `insert f l` satsisfies `Sorted f l`. For example, \nfor `fun _ _ => false`, if we have `Sorted f l` then \n`l.length` is 0 or 1. This is a reasonable class of `f` to \nmake sorting work as expected -/\nclass Asymmetric (f : \u03b1 \u2192 \u03b1 \u2192 Bool) where\n  asym {a a'} : !f a a' \u2192 f a' a\n\nopen Asymmetric\n\n/- A helpful constructor for `Sorted` that unifies the \nnonempty cases -/\ndef Sorted.cons {a : \u03b1} {l : List \u03b1} (h\u2081 : Sorted f l) \n    (h\u2082 : l.length > 0) (h\u2083 : f a l[0]) : Sorted f (a::l) :=\n  match h\u2081 with \n  | nil => single\n  | single => longer h\u2083 single\n  | longer h h' => longer h\u2083 <| longer h h'\n\n/- If we have a `Sorted` list with at least two elements, \nthen the first elements are ordered appropriately with \nrespect to `f` -/\ntheorem ordered_of_sorted {a a' : \u03b1} {as : List \u03b1} \n    (h : Sorted f (a::a'::as)) : f a a' :=\n  match h with \n  | longer h' _ => h'\n\n/- If we have a `Sorted` list `a'::as` where `a` and `a'` are \nordered wrong, then the first two elements of `a'::insert f a as` \nare ordered correctly -/\ntheorem ordered_cons_insert_of_unordered {a a' : \u03b1} {as : List \u03b1}\n    (h : Sorted f (a'::as)) (h' : f a' a) : f a' (insert f a as)[0] :=\n  match as with \n  | [] => by simpa [insert]\n  | a''::as' => \n  match h'' : f a a'' with \n    | true => by simpa [insert, h'']\n    | false => by simp [insert, h'']; apply ordered_of_sorted f h\n\n/- We prove that if we insert an element into a `Sorted` list \nit will remain `Sorted` assuming `f` is `Asymmetric` -/\ntheorem insert_sorted_of_sorted {a : \u03b1} {l : List \u03b1} [Asymmetric f] \n    (h : Sorted f l) : Sorted f <| insert f a l :=\n  match l with \n  | [] => single\n  | a'::as =>\n    match h' : f a a' with \n    | true => by simp [insert, h']; apply longer h' h \n    | false => by\n      simp [insert, h']\n      apply cons f\n      \u00b7 apply insert_sorted_of_sorted <| sorted_tail_of_sorted f a' as h   \n      \u00b7 apply ordered_cons_insert_of_unordered f h \n        \u00b7 apply asym; simp; assumption\n\n/- Finally, we prove that if `f` is `Asymmetric` then `insertSort` \nalways produces a `Sorted` list no matter `\u03b1` or `f` -/\ntheorem sorted_of_insertSort (l : List \u03b1) [Asymmetric f] : \n    Sorted f <| insertSort f l :=\n  match l with \n  | [] => nil\n  | a::as => by\n    dsimp [insertSort]\n    apply insert_sorted_of_sorted f <| sorted_of_insertSort as\n\n", "meta": {"author": "UofSC-Spring-2023-SCHC-411-H01", "repo": "notes", "sha": "ef57142df34fbe92f6204d8eb636ec5061729bd0", "save_path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes", "path": "github-repos/lean/UofSC-Spring-2023-SCHC-411-H01-notes/notes-ef57142df34fbe92f6204d8eb636ec5061729bd0/Notes4/IndPred.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7111764475228866}}
{"text": "/-\nCopyright (c) 2022 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport topology.local_extr\nimport topology.algebra.order.basic\n\n/-!\n# Maximum/minimum on the closure of a set\n\nIn this file we prove several versions of the following statement: if `f : X \u2192 Y` has a (local or\nnot) maximum (or minimum) on a set `s` at a point `a` and is continuous on the closure of `s`, then\n`f` has an extremum of the same type on `closure s` at `a`.\n-/\n\nopen filter set\nopen_locale topological_space\n\nvariables {X Y : Type*} [topological_space X] [topological_space Y] [preorder Y]\n  [order_closed_topology Y] {f g : X \u2192 Y} {s : set X} {a : X}\n\nprotected lemma is_max_on.closure (h : is_max_on f s a) (hc : continuous_on f (closure s)) :\n  is_max_on f (closure s) a :=\n\u03bb x hx, continuous_within_at.closure_le hx ((hc x hx).mono subset_closure)\n  continuous_within_at_const h\n\nprotected lemma is_min_on.closure (h : is_min_on f s a) (hc : continuous_on f (closure s)) :\n  is_min_on f (closure s) a :=\nh.dual.closure hc\n\nprotected lemma is_extr_on.closure (h : is_extr_on f s a) (hc : continuous_on f (closure s)) :\n  is_extr_on f (closure s) a :=\nh.elim (\u03bb h, or.inl $ h.closure hc) (\u03bb h, or.inr $ h.closure hc)\n\nprotected lemma is_local_max_on.closure (h : is_local_max_on f s a)\n  (hc : continuous_on f (closure s)) :\n  is_local_max_on f (closure s) a :=\nbegin\n  rcases mem_nhds_within.1 h with \u27e8U, Uo, aU, hU\u27e9,\n  refine mem_nhds_within.2 \u27e8U, Uo, aU, _\u27e9,\n  rintro x \u27e8hxU, hxs\u27e9,\n  refine continuous_within_at.closure_le _ _ continuous_within_at_const hU,\n  { rwa [mem_closure_iff_nhds_within_ne_bot, nhds_within_inter_of_mem,\n      \u2190 mem_closure_iff_nhds_within_ne_bot],\n    exact nhds_within_le_nhds (Uo.mem_nhds hxU) },\n  { exact (hc _ hxs).mono ((inter_subset_right _ _).trans subset_closure) }\nend\n\nprotected lemma is_local_min_on.closure (h : is_local_min_on f s a)\n  (hc : continuous_on f (closure s)) :\n  is_local_min_on f (closure s) a :=\nis_local_max_on.closure h.dual hc\n\nprotected lemma is_local_extr_on.closure (h : is_local_extr_on f s a)\n  (hc : continuous_on f (closure s)) :\n  is_local_extr_on f (closure s) a :=\nh.elim (\u03bb h, or.inl $ h.closure hc) (\u03bb h, or.inr $ h.closure hc)\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/topology/algebra/order/extr_closure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.711176430278666}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau, Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes\n-/\nimport data.finset.order\nimport algebra.direct_sum.module\nimport ring_theory.free_comm_ring\nimport ring_theory.ideal.quotient_operations\n/-!\n# Direct limit of modules, abelian groups, rings, and fields.\n\nSee Atiyah-Macdonald PP.32-33, Matsumura PP.269-270\n\nGeneralizes the notion of \"union\", or \"gluing\", of incomparable modules over the same ring,\nor incomparable abelian groups, or rings, or fields.\n\nIt is constructed as a quotient of the free module (for the module case) or quotient of\nthe free commutative ring (for the ring case) instead of a quotient of the disjoint union\nso as to make the operations (addition etc.) \"computable\".\n\n## Main definitions\n\n* `directed_system f`\n* `module.direct_limit G f`\n* `add_comm_group.direct_limit G f`\n* `ring.direct_limit G f`\n\n-/\nuniverses u v w u\u2081\n\nopen submodule\n\nvariables {R : Type u} [ring R]\nvariables {\u03b9 : Type v}\nvariables [dec_\u03b9 : decidable_eq \u03b9] [preorder \u03b9]\nvariables (G : \u03b9 \u2192 Type w)\n\n/-- A directed system is a functor from a category (directed poset) to another category. -/\nclass directed_system (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192 G j) : Prop :=\n(map_self [] : \u2200 i x h, f i i h x = x)\n(map_map [] : \u2200 {i j k} hij hjk x, f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x)\n\nnamespace module\n\nvariables [\u03a0 i, add_comm_group (G i)] [\u03a0 i, module R (G i)]\n\nvariables {G} (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192\u2097[R] G j)\n\n/-- A copy of `directed_system.map_self` specialized to linear maps, as otherwise the\n`\u03bb i j h, f i j h` can confuse the simplifier. -/\nlemma directed_system.map_self [directed_system G (\u03bb i j h, f i j h)] (i x h) :\n  f i i h x = x :=\ndirected_system.map_self (\u03bb i j h, f i j h) i x h\n\n/-- A copy of `directed_system.map_map` specialized to linear maps, as otherwise the\n`\u03bb i j h, f i j h` can confuse the simplifier. -/\nlemma directed_system.map_map [directed_system G (\u03bb i j h, f i j h)] {i j k} (hij hjk x) :\n  f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x :=\ndirected_system.map_map (\u03bb i j h, f i j h) hij hjk x\n\nvariables (G)\n\ninclude dec_\u03b9\n\n/-- The direct limit of a directed system is the modules glued together along the maps. -/\ndef direct_limit : Type (max v w) :=\ndirect_sum \u03b9 G \u29f8 (span R $ { a | \u2203 (i j) (H : i \u2264 j) x,\n  direct_sum.lof R \u03b9 G i x - direct_sum.lof R \u03b9 G j (f i j H x) = a })\n\nnamespace direct_limit\n\ninstance : add_comm_group (direct_limit G f) := quotient.add_comm_group _\ninstance : module R (direct_limit G f) := quotient.module _\n\ninstance : inhabited (direct_limit G f) := \u27e80\u27e9\n\nvariables (R \u03b9)\n/-- The canonical map from a component to the direct limit. -/\ndef of (i) : G i \u2192\u2097[R] direct_limit G f :=\n(mkq _).comp $ direct_sum.lof R \u03b9 G i\nvariables {R \u03b9 G f}\n\n@[simp] lemma of_f {i j hij x} : (of R \u03b9 G f j (f i j hij x)) = of R \u03b9 G f i x :=\neq.symm $ (submodule.quotient.eq _).2 $ subset_span \u27e8i, j, hij, x, rfl\u27e9\n\n/-- Every element of the direct limit corresponds to some element in\nsome component of the directed system. -/\n\n\n@[elab_as_eliminator]\nprotected theorem induction_on [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {C : direct_limit G f \u2192 Prop}\n  (z : direct_limit G f)\n  (ih : \u2200 i x, C (of R \u03b9 G f i x)) : C z :=\nlet \u27e8i, x, h\u27e9 := exists_of z in h \u25b8 ih i x\n\nvariables {P : Type u\u2081} [add_comm_group P] [module R P] (g : \u03a0 i, G i \u2192\u2097[R] P)\nvariables (Hg : \u2200 i j hij x, g j (f i j hij x) = g i x)\ninclude Hg\n\nvariables (R \u03b9 G f)\n/-- The universal property of the direct limit: maps from the components to another module\nthat respect the directed system structure (i.e. make some diagram commute) give rise\nto a unique map out of the direct limit. -/\ndef lift : direct_limit G f \u2192\u2097[R] P :=\nliftq _ (direct_sum.to_module R \u03b9 P g)\n  (span_le.2 $ \u03bb a \u27e8i, j, hij, x, hx\u27e9, by rw [\u2190 hx, set_like.mem_coe, linear_map.sub_mem_ker_iff,\n    direct_sum.to_module_lof, direct_sum.to_module_lof, Hg])\nvariables {R \u03b9 G f}\n\nomit Hg\nlemma lift_of {i} (x) : lift R \u03b9 G f g Hg (of R \u03b9 G f i x) = g i x :=\ndirect_sum.to_module_lof R _ _\n\ntheorem lift_unique [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (F : direct_limit G f \u2192\u2097[R] P) (x) :\n  F x = lift R \u03b9 G f (\u03bb i, F.comp $ of R \u03b9 G f i)\n    (\u03bb i j hij x, by rw [linear_map.comp_apply, of_f]; refl) x :=\ndirect_limit.induction_on x $ \u03bb i x, by rw lift_of; refl\n\nsection totalize\nopen_locale classical\nvariables (G f)\nomit dec_\u03b9\n\n/-- `totalize G f i j` is a linear map from `G i` to `G j`, for *every* `i` and `j`.\nIf `i \u2264 j`, then it is the map `f i j` that comes with the directed system `G`,\nand otherwise it is the zero map. -/\nnoncomputable def totalize (i j) : G i \u2192\u2097[R] G j :=\nif h : i \u2264 j then f i j h else 0\nvariables {G f}\n\nlemma totalize_of_le {i j} (h : i \u2264 j) : totalize G f i j = f i j h := dif_pos h\n\nlemma totalize_of_not_le {i j} (h : \u00ac(i \u2264 j)) : totalize G f i j = 0 := dif_neg h\n\nend totalize\n\nvariables [directed_system G (\u03bb i j h, f i j h)]\nopen_locale classical\n\nlemma to_module_totalize_of_le {x : direct_sum \u03b9 G} {i j : \u03b9}\n  (hij : i \u2264 j) (hx : \u2200 k \u2208 x.support, k \u2264 i) :\n  direct_sum.to_module R \u03b9 (G j) (\u03bb k, totalize G f k j) x =\n  f i j hij (direct_sum.to_module R \u03b9 (G i) (\u03bb k, totalize G f k i) x) :=\nbegin\n  rw [\u2190 @dfinsupp.sum_single \u03b9 G _ _ _ x],\n  unfold dfinsupp.sum,\n  simp only [linear_map.map_sum],\n  refine finset.sum_congr rfl (\u03bb k hk, _),\n  rw [direct_sum.single_eq_lof R k (x k), direct_sum.to_module_lof, direct_sum.to_module_lof,\n    totalize_of_le (hx k hk), totalize_of_le (le_trans (hx k hk) hij), directed_system.map_map],\nend\n\nlemma of.zero_exact_aux [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {x : direct_sum \u03b9 G}\n  (H : submodule.quotient.mk x = (0 : direct_limit G f)) :\n  \u2203 j, (\u2200 k \u2208 x.support, k \u2264 j) \u2227\n    direct_sum.to_module R \u03b9 (G j) (\u03bb i, totalize G f i j) x = (0 : G j) :=\nnonempty.elim (by apply_instance) $ assume ind : \u03b9,\nspan_induction ((quotient.mk_eq_zero _).1 H)\n  (\u03bb x \u27e8i, j, hij, y, hxy\u27e9, let \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n    \u27e8k, begin\n      clear_,\n      subst hxy,\n      split,\n      { intros i0 hi0,\n        rw [dfinsupp.mem_support_iff, direct_sum.sub_apply, \u2190 direct_sum.single_eq_lof,\n            \u2190 direct_sum.single_eq_lof, dfinsupp.single_apply, dfinsupp.single_apply] at hi0,\n        split_ifs at hi0 with hi hj hj, { rwa hi at hik }, { rwa hi at hik }, { rwa hj at hjk },\n        exfalso, apply hi0, rw sub_zero },\n      simp [linear_map.map_sub, totalize_of_le, hik, hjk,\n        directed_system.map_map, direct_sum.apply_eq_component,\n        direct_sum.component.of],\n    end\u27e9)\n  \u27e8ind, \u03bb _ h, (finset.not_mem_empty _ h).elim, linear_map.map_zero _\u27e9\n  (\u03bb x y \u27e8i, hi, hxi\u27e9 \u27e8j, hj, hyj\u27e9,\n    let \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n    \u27e8k, \u03bb l hl,\n      (finset.mem_union.1 (dfinsupp.support_add hl)).elim\n        (\u03bb hl, le_trans (hi _ hl) hik)\n        (\u03bb hl, le_trans (hj _ hl) hjk),\n      by simp [linear_map.map_add, hxi, hyj,\n          to_module_totalize_of_le hik hi,\n          to_module_totalize_of_le hjk hj]\u27e9)\n  (\u03bb a x \u27e8i, hi, hxi\u27e9,\n    \u27e8i, \u03bb k hk, hi k (direct_sum.support_smul _ _ hk),\n      by simp [linear_map.map_smul, hxi]\u27e9)\n\n/-- A component that corresponds to zero in the direct limit is already zero in some\nbigger module in the directed system. -/\ntheorem of.zero_exact [is_directed \u03b9 (\u2264)] {i x} (H : of R \u03b9 G f i x = 0) :\n  \u2203 j hij, f i j hij x = (0 : G j) :=\nby haveI : nonempty \u03b9 := \u27e8i\u27e9; exact\nlet \u27e8j, hj, hxj\u27e9 := of.zero_exact_aux H in\nif hx0 : x = 0 then \u27e8i, le_rfl, by simp [hx0]\u27e9\nelse\n  have hij : i \u2264 j, from hj _ $\n    by simp [direct_sum.apply_eq_component, hx0],\n  \u27e8j, hij, by simpa [totalize_of_le hij] using hxj\u27e9\n\nend direct_limit\n\nend module\n\n\nnamespace add_comm_group\n\nvariables [\u03a0 i, add_comm_group (G i)]\ninclude dec_\u03b9\n\n/-- The direct limit of a directed system is the abelian groups glued together along the maps. -/\ndef direct_limit (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192+ G j) : Type* :=\n@module.direct_limit \u2124 _ \u03b9 _ _ G _ _\n  (\u03bb i j hij, (f i j hij).to_int_linear_map)\n\nnamespace direct_limit\n\nvariables (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192+ G j)\n\nomit dec_\u03b9\n\nprotected lemma directed_system [h : directed_system G (\u03bb i j h, f i j h)] :\n  directed_system G (\u03bb i j hij, (f i j hij).to_int_linear_map) :=\nh\n\ninclude dec_\u03b9\n\nlocal attribute [instance] direct_limit.directed_system\n\ninstance : add_comm_group (direct_limit G f) :=\nmodule.direct_limit.add_comm_group G (\u03bb i j hij, (f i j hij).to_int_linear_map)\n\ninstance : inhabited (direct_limit G f) := \u27e80\u27e9\n\n/-- The canonical map from a component to the direct limit. -/\ndef of (i) : G i \u2192\u2097[\u2124] direct_limit G f :=\nmodule.direct_limit.of \u2124 \u03b9 G (\u03bb i j hij, (f i j hij).to_int_linear_map) i\nvariables {G f}\n\n@[simp] lemma of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=\nmodule.direct_limit.of_f\n\n@[elab_as_eliminator]\nprotected theorem induction_on [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {C : direct_limit G f \u2192 Prop}\n  (z : direct_limit G f) (ih : \u2200 i x, C (of G f i x)) : C z :=\nmodule.direct_limit.induction_on z ih\n\n/-- A component that corresponds to zero in the direct limit is already zero in some\nbigger module in the directed system. -/\ntheorem of.zero_exact [is_directed \u03b9 (\u2264)] [directed_system G (\u03bb i j h, f i j h)] (i x)\n  (h : of G f i x = 0) :\n  \u2203 j hij, f i j hij x = 0 :=\nmodule.direct_limit.of.zero_exact h\n\nvariables (P : Type u\u2081) [add_comm_group P]\nvariables (g : \u03a0 i, G i \u2192+ P)\nvariables (Hg : \u2200 i j hij x, g j (f i j hij x) = g i x)\n\nvariables (G f)\n/-- The universal property of the direct limit: maps from the components to another abelian group\nthat respect the directed system structure (i.e. make some diagram commute) give rise\nto a unique map out of the direct limit. -/\ndef lift : direct_limit G f \u2192\u2097[\u2124] P :=\nmodule.direct_limit.lift \u2124 \u03b9 G (\u03bb i j hij, (f i j hij).to_int_linear_map)\n  (\u03bb i, (g i).to_int_linear_map) Hg\nvariables {G f}\n\n@[simp] lemma lift_of (i x) : lift G f P g Hg (of G f i x) = g i x :=\nmodule.direct_limit.lift_of _ _ _\n\nlemma lift_unique [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (F : direct_limit G f \u2192+ P) (x) :\n  F x = lift G f P (\u03bb i, F.comp (of G f i).to_add_monoid_hom)\n    (\u03bb i j hij x, by simp) x :=\ndirect_limit.induction_on x $ \u03bb i x, by simp\n\nend direct_limit\n\nend add_comm_group\n\n\nnamespace ring\n\nvariables [\u03a0 i, comm_ring (G i)]\n\nsection\nvariables (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192 G j)\n\nopen free_comm_ring\n\n/-- The direct limit of a directed system is the rings glued together along the maps. -/\ndef direct_limit : Type (max v w) :=\nfree_comm_ring (\u03a3 i, G i) \u29f8 (ideal.span { a |\n  (\u2203 i j H x, of (\u27e8j, f i j H x\u27e9 : \u03a3 i, G i) - of \u27e8i, x\u27e9 = a) \u2228\n  (\u2203 i, of (\u27e8i, 1\u27e9 : \u03a3 i, G i) - 1 = a) \u2228\n  (\u2203 i x y, of (\u27e8i, x + y\u27e9 : \u03a3 i, G i) - (of \u27e8i, x\u27e9 + of \u27e8i, y\u27e9) = a) \u2228\n  (\u2203 i x y, of (\u27e8i, x * y\u27e9 : \u03a3 i, G i) - (of \u27e8i, x\u27e9 * of \u27e8i, y\u27e9) = a) })\n\nnamespace direct_limit\n\ninstance : comm_ring (direct_limit G f) :=\nideal.quotient.comm_ring _\n\ninstance : ring (direct_limit G f) :=\ncomm_ring.to_ring _\n\ninstance : inhabited (direct_limit G f) := \u27e80\u27e9\n\n/-- The canonical map from a component to the direct limit. -/\ndef of (i) : G i \u2192+* direct_limit G f :=\nring_hom.mk'\n{ to_fun := \u03bb x, ideal.quotient.mk _ (of (\u27e8i, x\u27e9 : \u03a3 i, G i)),\n  map_one' := ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inl \u27e8i, rfl\u27e9,\n  map_mul' := \u03bb x y, ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inr $ or.inr \u27e8i, x, y, rfl\u27e9, }\n(\u03bb x y, ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inr $ or.inl \u27e8i, x, y, rfl\u27e9)\n\nvariables {G f}\n\n@[simp] lemma of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=\nideal.quotient.eq.2 $ subset_span $ or.inl \u27e8i, j, hij, x, rfl\u27e9\n\n/-- Every element of the direct limit corresponds to some element in\nsome component of the directed system. -/\ntheorem exists_of [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (z : direct_limit G f) :\n  \u2203 i x, of G f i x = z :=\nnonempty.elim (by apply_instance) $ assume ind : \u03b9,\nquotient.induction_on' z $ \u03bb x, free_abelian_group.induction_on x\n  \u27e8ind, 0, (of _ _ ind).map_zero\u27e9\n  (\u03bb s, multiset.induction_on s\n    \u27e8ind, 1, (of _ _ ind).map_one\u27e9\n    (\u03bb a s ih, let \u27e8i, x\u27e9 := a, \u27e8j, y, hs\u27e9 := ih, \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n      \u27e8k, f i k hik x * f j k hjk y, by rw [(of _ _ _).map_mul, of_f, of_f, hs]; refl\u27e9))\n  (\u03bb s \u27e8i, x, ih\u27e9, \u27e8i, -x, by rw [(of _ _ _).map_neg, ih]; refl\u27e9)\n  (\u03bb p q \u27e8i, x, ihx\u27e9 \u27e8j, y, ihy\u27e9, let \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j in\n    \u27e8k, f i k hik x + f j k hjk y, by rw [(of _ _ _).map_add, of_f, of_f, ihx, ihy]; refl\u27e9)\n\n\nsection\nopen_locale classical\nopen polynomial\n\nvariables {f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j}\n\ntheorem polynomial.exists_of [nonempty \u03b9] [is_directed \u03b9 (\u2264)]\n  (q : polynomial (direct_limit G (\u03bb i j h, f' i j h))) :\n  \u2203 i p, polynomial.map (of G (\u03bb i j h, f' i j h) i) p = q :=\npolynomial.induction_on q\n  (\u03bb z, let \u27e8i, x, h\u27e9 := exists_of z in \u27e8i, C x, by rw [map_C, h]\u27e9)\n  (\u03bb q\u2081 q\u2082 \u27e8i\u2081, p\u2081, ih\u2081\u27e9 \u27e8i\u2082, p\u2082, ih\u2082\u27e9, let \u27e8i, h1, h2\u27e9 := exists_ge_ge i\u2081 i\u2082 in\n    \u27e8i, p\u2081.map (f' i\u2081 i h1) + p\u2082.map (f' i\u2082 i h2),\n     by { rw [polynomial.map_add, map_map, map_map, \u2190 ih\u2081, \u2190 ih\u2082],\n      congr' 2; ext x; simp_rw [ring_hom.comp_apply, of_f] }\u27e9)\n  (\u03bb n z ih, let \u27e8i, x, h\u27e9 := exists_of z in \u27e8i, C x * X ^ (n + 1),\n    by rw [polynomial.map_mul, map_C, h, polynomial.map_pow, map_X]\u27e9)\n\nend\n\n@[elab_as_eliminator] theorem induction_on [nonempty \u03b9] [is_directed \u03b9 (\u2264)]\n  {C : direct_limit G f \u2192 Prop}\n  (z : direct_limit G f) (ih : \u2200 i x, C (of G f i x)) : C z :=\nlet \u27e8i, x, hx\u27e9 := exists_of z in hx \u25b8 ih i x\n\nsection of_zero_exact\nopen_locale classical\n\nvariables (f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j)\nvariables [directed_system G (\u03bb i j h, f' i j h)]\nvariables (G f)\n\nlemma of.zero_exact_aux2 {x : free_comm_ring \u03a3 i, G i} {s t} (hxs : is_supported x s) {j k}\n  (hj : \u2200 z : \u03a3 i, G i, z \u2208 s \u2192 z.1 \u2264 j) (hk : \u2200 z : \u03a3 i, G i, z \u2208 t \u2192 z.1 \u2264 k)\n  (hjk : j \u2264 k) (hst : s \u2286 t) :\n  f' j k hjk (lift (\u03bb ix : s, f' ix.1.1 j (hj ix ix.2) ix.1.2) (restriction s x)) =\n  lift (\u03bb ix : t, f' ix.1.1 k (hk ix ix.2) ix.1.2) (restriction t x) :=\nbegin\n  refine subring.in_closure.rec_on hxs _ _ _ _,\n  { rw [(restriction _).map_one, (free_comm_ring.lift _).map_one, (f' j k hjk).map_one,\n        (restriction _).map_one, (free_comm_ring.lift _).map_one] },\n  { rw [(restriction _).map_neg, (restriction _).map_one,\n        (free_comm_ring.lift _).map_neg, (free_comm_ring.lift _).map_one,\n        (f' j k hjk).map_neg, (f' j k hjk).map_one,\n        (restriction _).map_neg, (restriction _).map_one,\n        (free_comm_ring.lift _).map_neg, (free_comm_ring.lift _).map_one] },\n  { rintros _ \u27e8p, hps, rfl\u27e9 n ih,\n    rw [(restriction _).map_mul, (free_comm_ring.lift _).map_mul,\n        (f' j k hjk).map_mul, ih,\n        (restriction _).map_mul, (free_comm_ring.lift _).map_mul,\n        restriction_of, dif_pos hps, lift_of, restriction_of, dif_pos (hst hps), lift_of],\n    dsimp only,\n    have := directed_system.map_map (\u03bb i j h, f' i j h),\n    dsimp only at this,\n    rw this, refl },\n  { rintros x y ihx ihy,\n    rw [(restriction _).map_add, (free_comm_ring.lift _).map_add,\n        (f' j k hjk).map_add, ihx, ihy,\n        (restriction _).map_add, (free_comm_ring.lift _).map_add] }\nend\nvariables {G f f'}\n\nlemma of.zero_exact_aux [nonempty \u03b9] [is_directed \u03b9 (\u2264)] {x : free_comm_ring \u03a3 i, G i}\n  (H : ideal.quotient.mk _ x = (0 : direct_limit G (\u03bb i j h, f' i j h))) :\n  \u2203 j s, \u2203 H : (\u2200 k : \u03a3 i, G i, k \u2208 s \u2192 k.1 \u2264 j), is_supported x s \u2227\n    lift (\u03bb ix : s, f' ix.1.1 j (H ix ix.2) ix.1.2) (restriction s x) = (0 : G j) :=\nbegin\n  refine span_induction (ideal.quotient.eq_zero_iff_mem.1 H) _ _ _ _,\n  { rintros x (\u27e8i, j, hij, x, rfl\u27e9 | \u27e8i, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9),\n    { refine \u27e8j, {\u27e8i, x\u27e9, \u27e8j, f' i j hij x\u27e9}, _,\n        is_supported_sub (is_supported_of.2 $ or.inr rfl) (is_supported_of.2 $ or.inl rfl), _\u27e9,\n      { rintros k (rfl | \u27e8rfl | _\u27e9), exact hij, refl },\n      { rw [(restriction _).map_sub, (free_comm_ring.lift _).map_sub,\n            restriction_of, dif_pos, restriction_of, dif_pos, lift_of, lift_of],\n        dsimp only,\n        have := directed_system.map_map (\u03bb i j h, f' i j h),\n        dsimp only at this,\n        rw this, exact sub_self _,\n        exacts [or.inr rfl, or.inl rfl] } },\n    { refine \u27e8i, {\u27e8i, 1\u27e9}, _, is_supported_sub (is_supported_of.2 rfl) is_supported_one, _\u27e9,\n      { rintros k (rfl|h), refl },\n      { rw [(restriction _).map_sub, (free_comm_ring.lift _).map_sub, restriction_of, dif_pos,\n          (restriction _).map_one, lift_of, (free_comm_ring.lift _).map_one],\n        dsimp only, rw [(f' i i _).map_one, sub_self],\n        { exact set.mem_singleton _ } } },\n    { refine \u27e8i, {\u27e8i, x+y\u27e9, \u27e8i, x\u27e9, \u27e8i, y\u27e9}, _,\n        is_supported_sub (is_supported_of.2 $ or.inl rfl)\n          (is_supported_add (is_supported_of.2 $ or.inr $ or.inl rfl)\n            (is_supported_of.2 $ or.inr $ or.inr rfl)), _\u27e9,\n      { rintros k (rfl | \u27e8rfl | \u27e8rfl | hk\u27e9\u27e9); refl },\n      { rw [(restriction _).map_sub, (restriction _).map_add,\n            restriction_of, restriction_of, restriction_of,\n            dif_pos, dif_pos, dif_pos,\n            (free_comm_ring.lift _).map_sub, (free_comm_ring.lift _).map_add,\n            lift_of, lift_of, lift_of],\n        dsimp only, rw (f' i i _).map_add, exact sub_self _,\n        exacts [or.inl rfl, or.inr (or.inr rfl), or.inr (or.inl rfl)] } },\n    { refine \u27e8i, {\u27e8i, x*y\u27e9, \u27e8i, x\u27e9, \u27e8i, y\u27e9}, _,\n        is_supported_sub (is_supported_of.2 $ or.inl rfl)\n          (is_supported_mul (is_supported_of.2 $ or.inr $ or.inl rfl)\n            (is_supported_of.2 $ or.inr $ or.inr rfl)), _\u27e9,\n      { rintros k (rfl | \u27e8rfl | \u27e8rfl | hk\u27e9\u27e9); refl },\n      { rw [(restriction _).map_sub, (restriction _).map_mul,\n            restriction_of, restriction_of, restriction_of,\n            dif_pos, dif_pos, dif_pos,\n            (free_comm_ring.lift _).map_sub, (free_comm_ring.lift _).map_mul,\n            lift_of, lift_of, lift_of],\n        dsimp only, rw (f' i i _).map_mul,\n        exacts [sub_self _, or.inl rfl, or.inr (or.inr rfl),\n          or.inr (or.inl rfl)] } } },\n  { refine nonempty.elim (by apply_instance) (assume ind : \u03b9, _),\n    refine \u27e8ind, \u2205, \u03bb _, false.elim, is_supported_zero, _\u27e9,\n    rw [(restriction _).map_zero, (free_comm_ring.lift _).map_zero] },\n  { rintros x y \u27e8i, s, hi, hxs, ihs\u27e9 \u27e8j, t, hj, hyt, iht\u27e9,\n    obtain \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j,\n    have : \u2200 z : \u03a3 i, G i, z \u2208 s \u222a t \u2192 z.1 \u2264 k,\n    { rintros z (hz | hz), exact le_trans (hi z hz) hik, exact le_trans (hj z hz) hjk },\n    refine \u27e8k, s \u222a t, this, is_supported_add (is_supported_upwards hxs $ set.subset_union_left s t)\n      (is_supported_upwards hyt $ set.subset_union_right s t), _\u27e9,\n    { rw [(restriction _).map_add, (free_comm_ring.lift _).map_add,\n        \u2190 of.zero_exact_aux2 G f' hxs hi this hik (set.subset_union_left s t),\n        \u2190 of.zero_exact_aux2 G f' hyt hj this hjk (set.subset_union_right s t),\n        ihs, (f' i k hik).map_zero, iht, (f' j k hjk).map_zero, zero_add] } },\n  { rintros x y \u27e8j, t, hj, hyt, iht\u27e9, rw smul_eq_mul,\n    rcases exists_finset_support x with \u27e8s, hxs\u27e9,\n    rcases (s.image sigma.fst).exists_le with \u27e8i, hi\u27e9,\n    obtain \u27e8k, hik, hjk\u27e9 := exists_ge_ge i j,\n    have : \u2200 z : \u03a3 i, G i, z \u2208 \u2191s \u222a t \u2192 z.1 \u2264 k,\n    { rintros z (hz | hz),\n      exacts [(hi z.1 $ finset.mem_image.2 \u27e8z, hz, rfl\u27e9).trans hik, (hj z hz).trans hjk] },\n    refine \u27e8k, \u2191s \u222a t, this, is_supported_mul\n      (is_supported_upwards hxs $ set.subset_union_left \u2191s t)\n      (is_supported_upwards hyt $ set.subset_union_right \u2191s t), _\u27e9,\n    rw [(restriction _).map_mul, (free_comm_ring.lift _).map_mul,\n        \u2190 of.zero_exact_aux2 G f' hyt hj this hjk (set.subset_union_right \u2191s t),\n        iht, (f' j k hjk).map_zero, mul_zero] }\nend\n\n/-- A component that corresponds to zero in the direct limit is already zero in some\nbigger module in the directed system. -/\nlemma of.zero_exact [is_directed \u03b9 (\u2264)] {i x} (hix : of G (\u03bb i j h, f' i j h) i x = 0) :\n  \u2203 j (hij : i \u2264 j), f' i j hij x = 0 :=\nby haveI : nonempty \u03b9 := \u27e8i\u27e9; exact\nlet \u27e8j, s, H, hxs, hx\u27e9 := of.zero_exact_aux hix in\nhave hixs : (\u27e8i, x\u27e9 : \u03a3 i, G i) \u2208 s, from is_supported_of.1 hxs,\n\u27e8j, H \u27e8i, x\u27e9 hixs, by rw [restriction_of, dif_pos hixs, lift_of] at hx; exact hx\u27e9\nend of_zero_exact\n\nvariables (f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j)\n\n/-- If the maps in the directed system are injective, then the canonical maps\nfrom the components to the direct limits are injective. -/\ntheorem of_injective [is_directed \u03b9 (\u2264)] [directed_system G (\u03bb i j h, f' i j h)]\n  (hf : \u2200 i j hij, function.injective (f' i j hij)) (i) :\n  function.injective (of G (\u03bb i j h, f' i j h) i) :=\nbegin\n  suffices : \u2200 x, of G (\u03bb i j h, f' i j h) i x = 0 \u2192 x = 0,\n  { intros x y hxy, rw \u2190 sub_eq_zero, apply this,\n    rw [(of G _ i).map_sub, hxy, sub_self] },\n  intros x hx, rcases of.zero_exact hx with \u27e8j, hij, hfx\u27e9,\n  apply hf i j hij, rw [hfx, (f' i j hij).map_zero]\nend\n\nvariables (P : Type u\u2081) [comm_ring P]\nvariables (g : \u03a0 i, G i \u2192+* P)\nvariables (Hg : \u2200 i j hij x, g j (f i j hij x) = g i x)\ninclude Hg\n\nopen free_comm_ring\n\nvariables (G f)\n/-- The universal property of the direct limit: maps from the components to another ring\nthat respect the directed system structure (i.e. make some diagram commute) give rise\nto a unique map out of the direct limit.\n-/\ndef lift : direct_limit G f \u2192+* P :=\nideal.quotient.lift _ (free_comm_ring.lift $ \u03bb (x : \u03a3 i, G i), g x.1 x.2) begin\n  suffices : ideal.span _ \u2264\n    ideal.comap (free_comm_ring.lift (\u03bb (x : \u03a3 (i : \u03b9), G i), g (x.fst) (x.snd))) \u22a5,\n  { intros x hx, exact (mem_bot P).1 (this hx) },\n  rw ideal.span_le, intros x hx,\n  rw [set_like.mem_coe, ideal.mem_comap, mem_bot],\n  rcases hx with \u27e8i, j, hij, x, rfl\u27e9 | \u27e8i, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9 | \u27e8i, x, y, rfl\u27e9;\n  simp only [ring_hom.map_sub, lift_of, Hg, ring_hom.map_one, ring_hom.map_add, ring_hom.map_mul,\n      (g i).map_one, (g i).map_add, (g i).map_mul, sub_self]\nend\n\nvariables {G f}\nomit Hg\n\n@[simp] lemma lift_of (i x) : lift G f P g Hg (of G f i x) = g i x := free_comm_ring.lift_of _ _\n\ntheorem lift_unique [nonempty \u03b9] [is_directed \u03b9 (\u2264)] (F : direct_limit G f \u2192+* P) (x) :\n  F x = lift G f P (\u03bb i, F.comp $ of G f i) (\u03bb i j hij x, by simp) x :=\ndirect_limit.induction_on x $ \u03bb i x, by simp\n\nend direct_limit\n\nend\n\nend ring\n\n\nnamespace field\n\nvariables [nonempty \u03b9] [is_directed \u03b9 (\u2264)] [\u03a0 i, field (G i)]\nvariables (f : \u03a0 i j, i \u2264 j \u2192 G i \u2192 G j)\nvariables (f' : \u03a0 i j, i \u2264 j \u2192 G i \u2192+* G j)\n\nnamespace direct_limit\n\ninstance nontrivial [directed_system G (\u03bb i j h, f' i j h)] :\n  nontrivial (ring.direct_limit G (\u03bb i j h, f' i j h)) :=\n\u27e8\u27e80, 1, nonempty.elim (by apply_instance) $ assume i : \u03b9, begin\n  change (0 : ring.direct_limit G (\u03bb i j h, f' i j h)) \u2260 1,\n  rw \u2190 (ring.direct_limit.of _ _ _).map_one,\n  intros H, rcases ring.direct_limit.of.zero_exact H.symm with \u27e8j, hij, hf\u27e9,\n  rw (f' i j hij).map_one at hf,\n  exact one_ne_zero hf\nend \u27e9\u27e9\n\ntheorem exists_inv {p : ring.direct_limit G f} : p \u2260 0 \u2192 \u2203 y, p * y = 1 :=\nring.direct_limit.induction_on p $ \u03bb i x H,\n\u27e8ring.direct_limit.of G f i (x\u207b\u00b9), by erw [\u2190 (ring.direct_limit.of _ _ _).map_mul,\n    mul_inv_cancel (assume h : x = 0, H $ by rw [h, (ring.direct_limit.of _ _ _).map_zero]),\n    (ring.direct_limit.of _ _ _).map_one]\u27e9\n\nsection\nopen_locale classical\n\n/-- Noncomputable multiplicative inverse in a direct limit of fields. -/\nnoncomputable def inv (p : ring.direct_limit G f) : ring.direct_limit G f :=\nif H : p = 0 then 0 else classical.some (direct_limit.exists_inv G f H)\n\nprotected theorem mul_inv_cancel {p : ring.direct_limit G f} (hp : p \u2260 0) : p * inv G f p = 1 :=\nby rw [inv, dif_neg hp, classical.some_spec (direct_limit.exists_inv G f hp)]\n\nprotected theorem inv_mul_cancel {p : ring.direct_limit G f} (hp : p \u2260 0) : inv G f p * p = 1 :=\nby rw [_root_.mul_comm, direct_limit.mul_inv_cancel G f hp]\n\n/-- Noncomputable field structure on the direct limit of fields.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected noncomputable def field [directed_system G (\u03bb i j h, f' i j h)] :\n  field (ring.direct_limit G (\u03bb i j h, f' i j h)) :=\n{ inv := inv G (\u03bb i j h, f' i j h),\n  mul_inv_cancel := \u03bb p, direct_limit.mul_inv_cancel G (\u03bb i j h, f' i j h),\n  inv_zero := dif_pos rfl,\n  .. ring.direct_limit.comm_ring G (\u03bb i j h, f' i j h),\n  .. direct_limit.nontrivial G (\u03bb i j h, f' i j h) }\n\nend\n\nend direct_limit\n\nend field\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/direct_limit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7111764276818221}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Floris van Doorn\n-/\nimport algebra.big_operators.basic\nimport algebra.module.basic\nimport data.finset.preimage\nimport data.set.finite\nimport group_theory.submonoid.basic\n\n/-!\n# Pointwise addition, multiplication, scalar multiplication and vector subtraction of sets.\n\nThis file defines pointwise algebraic operations on sets.\n* For a type `\u03b1` with multiplication, multiplication is defined on `set \u03b1` by taking\n  `s * t` to be the set of all `x * y` where `x \u2208 s` and `y \u2208 t`. Similarly for addition.\n* For `\u03b1` a semigroup, `set \u03b1` is a semigroup.\n* If `\u03b1` is a (commutative) monoid, we define an alias `set_semiring \u03b1` for `set \u03b1`, which then\n  becomes a (commutative) semiring with union as addition and pointwise multiplication as\n  multiplication.\n* For a type `\u03b2` with scalar multiplication by another type `\u03b1`, this\n  file defines a scalar multiplication of `set \u03b2` by `set \u03b1` and a separate scalar\n  multiplication of `set \u03b2` by `\u03b1`.\n* We also define pointwise multiplication on `finset`.\n\nAppropriate definitions and results are also transported to the additive theory via `to_additive`.\n\n## Implementation notes\n* The following expressions are considered in simp-normal form in a group:\n  `(\u03bb h, h * g) \u207b\u00b9' s`, `(\u03bb h, g * h) \u207b\u00b9' s`, `(\u03bb h, h * g\u207b\u00b9) \u207b\u00b9' s`, `(\u03bb h, g\u207b\u00b9 * h) \u207b\u00b9' s`,\n  `s * t`, `s\u207b\u00b9`, `(1 : set _)` (and similarly for additive variants).\n  Expressions equal to one of these will be simplified.\n* We put all instances in the locale `pointwise`, so that these instances are not available by\n  default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])\n  since we expect the locale to be open whenever the instances are actually used (and making the\n  instances reducible changes the behavior of `simp`).\n\n## Tags\n\nset multiplication, set addition, pointwise addition, pointwise multiplication,\npointwise subtraction\n-/\n\nopen function\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\nnamespace set\n\n/-! ### Properties about 1 -/\n\nsection one\nvariables [has_one \u03b1] {s : set \u03b1} {a : \u03b1}\n\n/-- The set `(1 : set \u03b1)` is defined as `{1}` in locale `pointwise`. -/\n@[to_additive\n/-\"The set `(0 : set \u03b1)` is defined as `{0}` in locale `pointwise`. \"-/]\nprotected def has_one : has_one (set \u03b1) := \u27e8{1}\u27e9\n\nlocalized \"attribute [instance] set.has_one set.has_zero\" in pointwise\n\n@[to_additive]\nlemma singleton_one : ({1} : set \u03b1) = 1 := rfl\n\n@[simp, to_additive]\nlemma mem_one : a \u2208 (1 : set \u03b1) \u2194 a = 1 := iff.rfl\n\n@[to_additive]\nlemma one_mem_one : (1 : \u03b1) \u2208 (1 : set \u03b1) := eq.refl _\n\n@[simp, to_additive]\nlemma one_subset : 1 \u2286 s \u2194 (1 : \u03b1) \u2208 s := singleton_subset_iff\n\n@[to_additive]\nlemma one_nonempty : (1 : set \u03b1).nonempty := \u27e81, rfl\u27e9\n\n@[simp, to_additive]\nlemma image_one {f : \u03b1 \u2192 \u03b2} : f '' 1 = {f 1} := image_singleton\n\nend one\n\nopen_locale pointwise\n\n/-! ### Properties about multiplication -/\n\nsection mul\nvariables {s s\u2081 s\u2082 t t\u2081 t\u2082 u : set \u03b1} {a b : \u03b1}\n\n/-- The set `(s * t : set \u03b1)` is defined as `{x * y | x \u2208 s, y \u2208 t}` in locale `pointwise`. -/\n@[to_additive\n/-\" The set `(s + t : set \u03b1)` is defined as `{x + y | x \u2208 s, y \u2208 t}` in locale `pointwise`.\"-/]\nprotected def has_mul [has_mul \u03b1] : has_mul (set \u03b1) := \u27e8image2 has_mul.mul\u27e9\n\nlocalized \"attribute [instance] set.has_mul set.has_add\" in pointwise\n\nsection has_mul\nvariables {\u03b9 : Sort*} {\u03ba : \u03b9 \u2192 Sort*} [has_mul \u03b1]\n\n@[simp, to_additive]\nlemma image2_mul : image2 has_mul.mul s t = s * t := rfl\n\n@[to_additive]\nlemma mem_mul : a \u2208 s * t \u2194 \u2203 x y, x \u2208 s \u2227 y \u2208 t \u2227 x * y = a := iff.rfl\n\n@[to_additive]\nlemma mul_mem_mul (ha : a \u2208 s) (hb : b \u2208 t) : a * b \u2208 s * t := mem_image2_of_mem ha hb\n\n@[to_additive]\nlemma mul_subset_mul (h\u2081 : s\u2081 \u2286 t\u2081) (h\u2082 : s\u2082 \u2286 t\u2082) : s\u2081 * s\u2082 \u2286 t\u2081 * t\u2082 := image2_subset h\u2081 h\u2082\n\n@[to_additive add_image_prod]\nlemma image_mul_prod : (\u03bb x : \u03b1 \u00d7 \u03b1, x.fst * x.snd) '' (s \u00d7\u02e2 t) = s * t := image_prod _\n\n@[simp, to_additive] lemma empty_mul : \u2205 * s = \u2205 := image2_empty_left\n@[simp, to_additive] lemma mul_empty : s * \u2205 = \u2205 := image2_empty_right\n\n@[simp, to_additive] lemma mul_singleton : s * {b} = (* b) '' s := image2_singleton_right\n@[simp, to_additive] lemma singleton_mul : {a} * t = ((*) a) '' t := image2_singleton_left\n\n@[simp, to_additive]\nlemma singleton_mul_singleton : ({a} : set \u03b1) * {b} = {a * b} := image2_singleton\n\n@[to_additive] lemma mul_subset_mul_left (h : t\u2081 \u2286 t\u2082) : s * t\u2081 \u2286 s * t\u2082 := image2_subset_left h\n@[to_additive] lemma mul_subset_mul_right (h : s\u2081 \u2286 s\u2082) : s\u2081 * t \u2286 s\u2082 * t := image2_subset_right h\n\n@[to_additive] lemma union_mul : (s\u2081 \u222a s\u2082) * t = s\u2081 * t \u222a s\u2082 * t := image2_union_left\n@[to_additive] lemma mul_union : s * (t\u2081 \u222a t\u2082) = s * t\u2081 \u222a s * t\u2082 := image2_union_right\n\n@[to_additive]\nlemma inter_mul_subset : (s\u2081 \u2229 s\u2082) * t \u2286 s\u2081 * t \u2229 (s\u2082 * t) := image2_inter_subset_left\n\n@[to_additive]\nlemma mul_inter_subset : s * (t\u2081 \u2229 t\u2082) \u2286 s * t\u2081 \u2229 (s * t\u2082) := image2_inter_subset_right\n\n@[to_additive]\nlemma Union_mul_left_image : (\u22c3 a \u2208 s, (\u03bb x, a * x) '' t) = s * t := Union_image_left _\n\n@[to_additive]\nlemma Union_mul_right_image : (\u22c3 a \u2208 t, (\u03bb x, x * a) '' s) = s * t := Union_image_right _\n\n@[to_additive]\nlemma Union_mul (s : \u03b9 \u2192 set \u03b1) (t : set \u03b1) : (\u22c3 i, s i) * t = \u22c3 i, s i * t :=\nimage2_Union_left _ _ _\n\n@[to_additive]\nlemma mul_Union (s : set \u03b1) (t : \u03b9 \u2192 set \u03b1) : s * (\u22c3 i, t i) = \u22c3 i, s * t i :=\nimage2_Union_right _ _ _\n\n@[to_additive]\nlemma Union\u2082_mul (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b1) : (\u22c3 i j, s i j) * t = \u22c3 i j, s i j * t :=\nimage2_Union\u2082_left _ _ _\n\n@[to_additive]\nlemma mul_Union\u2082 (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b1) : s * (\u22c3 i j, t i j) = \u22c3 i j, s * t i j :=\nimage2_Union\u2082_right _ _ _\n\n@[to_additive]\nlemma Inter_mul_subset (s : \u03b9 \u2192 set \u03b1) (t : set \u03b1) : (\u22c2 i, s i) * t \u2286 \u22c2 i, s i * t :=\nimage2_Inter_subset_left _ _ _\n\n@[to_additive]\nlemma mul_Inter_subset (s : set \u03b1) (t : \u03b9 \u2192 set \u03b1) : s * (\u22c2 i, t i) \u2286 \u22c2 i, s * t i :=\nimage2_Inter_subset_right _ _ _\n\n@[to_additive]\nlemma Inter\u2082_mul_subset (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b1) :\n  (\u22c2 i j, s i j) * t \u2286 \u22c2 i j, s i j * t :=\nimage2_Inter\u2082_subset_left _ _ _\n\n@[to_additive]\nlemma mul_Inter\u2082_subset (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b1) :\n  s * (\u22c2 i j, t i j) \u2286 \u22c2 i j, s * t i j :=\nimage2_Inter\u2082_subset_right _ _ _\n\n/-- Under `[has_mul M]`, the `singleton` map from `M` to `set M` as a `mul_hom`, that is, a map\nwhich preserves multiplication. -/\n@[to_additive \"Under `[has_add A]`, the `singleton` map from `A` to `set A` as an `add_hom`,\nthat is, a map which preserves addition.\", simps]\ndef singleton_mul_hom : mul_hom \u03b1 (set \u03b1) :=\n{ to_fun := singleton,\n  map_mul' := \u03bb a b, singleton_mul_singleton.symm }\n\nend has_mul\n\n@[simp, to_additive]\nlemma image_mul_left [group \u03b1] : ((*) a) '' t = ((*) a\u207b\u00b9) \u207b\u00b9' t :=\nby { rw image_eq_preimage_of_inverse; intro c; simp }\n\n@[simp, to_additive]\nlemma image_mul_right [group \u03b1] : (* b) '' t = (* b\u207b\u00b9) \u207b\u00b9' t :=\nby { rw image_eq_preimage_of_inverse; intro c; simp }\n\n@[to_additive]\nlemma image_mul_left' [group \u03b1] : (\u03bb b, a\u207b\u00b9 * b) '' t = (\u03bb b, a * b) \u207b\u00b9' t := by simp\n\n@[to_additive]\nlemma image_mul_right' [group \u03b1] : (* b\u207b\u00b9) '' t = (* b) \u207b\u00b9' t := by simp\n\n@[simp, to_additive]\nlemma preimage_mul_left_singleton [group \u03b1] : ((*) a) \u207b\u00b9' {b} = {a\u207b\u00b9 * b} :=\nby rw [\u2190 image_mul_left', image_singleton]\n\n@[simp, to_additive]\nlemma preimage_mul_right_singleton [group \u03b1] : (* a) \u207b\u00b9' {b} = {b * a\u207b\u00b9} :=\nby rw [\u2190 image_mul_right', image_singleton]\n\n@[simp, to_additive]\nlemma preimage_mul_left_one [group \u03b1] : ((*) a) \u207b\u00b9' 1 = {a\u207b\u00b9} :=\nby rw [\u2190 image_mul_left', image_one, mul_one]\n\n@[simp, to_additive]\nlemma preimage_mul_right_one [group \u03b1] : (* b) \u207b\u00b9' 1 = {b\u207b\u00b9} :=\nby rw [\u2190 image_mul_right', image_one, one_mul]\n\n@[to_additive]\nlemma preimage_mul_left_one' [group \u03b1] : (\u03bb b, a\u207b\u00b9 * b) \u207b\u00b9' 1 = {a} := by simp\n\n@[to_additive]\nlemma preimage_mul_right_one' [group \u03b1] : (* b\u207b\u00b9) \u207b\u00b9' 1 = {b} := by simp\n\n@[to_additive]\nprotected lemma mul_comm [comm_semigroup \u03b1] : s * t = t * s :=\nby simp only [\u2190 image2_mul, image2_swap _ s, mul_comm]\n\n/-- `set \u03b1` is a `mul_one_class` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_zero_class` under pointwise operations if `\u03b1` is.\"-/]\nprotected def mul_one_class [mul_one_class \u03b1] : mul_one_class (set \u03b1) :=\n{ mul_one := \u03bb s, by { simp only [\u2190 singleton_one, mul_singleton, mul_one, image_id'] },\n  one_mul := \u03bb s, by { simp only [\u2190 singleton_one, singleton_mul, one_mul, image_id'] },\n  ..set.has_one, ..set.has_mul }\n\n/-- `set \u03b1` is a `semigroup` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_semigroup` under pointwise operations if `\u03b1` is. \"-/]\nprotected def semigroup [semigroup \u03b1] : semigroup (set \u03b1) :=\n{ mul_assoc := \u03bb _ _ _, image2_assoc mul_assoc,\n  ..set.has_mul }\n\n/-- `set \u03b1` is a `monoid` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_monoid` under pointwise operations if `\u03b1` is. \"-/]\nprotected def monoid [monoid \u03b1] : monoid (set \u03b1) :=\n{ ..set.semigroup,\n  ..set.mul_one_class }\n\n/-- `set \u03b1` is a `comm_monoid` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`set \u03b1` is an `add_comm_monoid` under pointwise operations if `\u03b1` is. \"-/]\nprotected def comm_monoid [comm_monoid \u03b1] : comm_monoid (set \u03b1) :=\n{ mul_comm := \u03bb _ _, set.mul_comm, ..set.monoid }\n\nlocalized \"attribute [instance] set.mul_one_class set.add_zero_class set.semigroup set.add_semigroup\n  set.monoid set.add_monoid set.comm_monoid set.add_comm_monoid\" in pointwise\n\n@[to_additive nsmul_mem_nsmul]\nlemma pow_mem_pow [monoid \u03b1] (ha : a \u2208 s) (n : \u2115) :\n  a ^ n \u2208 s ^ n :=\nbegin\n  induction n with n ih,\n  { rw pow_zero,\n    exact set.mem_singleton 1 },\n  { rw pow_succ,\n    exact set.mul_mem_mul ha ih },\nend\n\n@[to_additive empty_nsmul]\nlemma empty_pow [monoid \u03b1] (n : \u2115) (hn : n \u2260 0) : (\u2205 : set \u03b1) ^ n = \u2205 :=\nby rw [\u2190 tsub_add_cancel_of_le (nat.succ_le_of_lt $ nat.pos_of_ne_zero hn), pow_succ, empty_mul]\n\ninstance decidable_mem_mul [monoid \u03b1] [fintype \u03b1] [decidable_eq \u03b1]\n  [decidable_pred (\u2208 s)] [decidable_pred (\u2208 t)] :\n  decidable_pred (\u2208 s * t) :=\n\u03bb _, decidable_of_iff _ mem_mul.symm\n\ninstance decidable_mem_pow [monoid \u03b1] [fintype \u03b1] [decidable_eq \u03b1]\n  [decidable_pred (\u2208 s)] (n : \u2115) :\n  decidable_pred (\u2208 (s ^ n)) :=\nbegin\n  induction n with n ih,\n  { simp_rw [pow_zero, mem_one], apply_instance },\n  { letI := ih, rw pow_succ, apply_instance }\nend\n\n@[to_additive]\nlemma subset_mul_left [mul_one_class \u03b1] (s : set \u03b1) {t : set \u03b1} (ht : (1 : \u03b1) \u2208 t) : s \u2286 s * t :=\n\u03bb x hx, \u27e8x, 1, hx, ht, mul_one _\u27e9\n\n@[to_additive]\nlemma subset_mul_right [mul_one_class \u03b1] {s : set \u03b1} (t : set \u03b1) (hs : (1 : \u03b1) \u2208 s) : t \u2286 s * t :=\n\u03bb x hx, \u27e81, x, hs, hx, one_mul _\u27e9\n\nlemma pow_subset_pow [monoid \u03b1] (hst : s \u2286 t) (n : \u2115) :\n  s ^ n \u2286 t ^ n :=\nbegin\n  induction n with n ih,\n  { rw pow_zero,\n    exact subset.rfl },\n  { rw [pow_succ, pow_succ],\n    exact mul_subset_mul hst ih },\nend\n\n@[simp, to_additive]\nlemma univ_mul_univ [monoid \u03b1] : (univ : set \u03b1) * univ = univ :=\nbegin\n  have : \u2200x, \u2203a b : \u03b1, a * b = x := \u03bbx, \u27e8x, \u27e81, mul_one x\u27e9\u27e9,\n  simpa only [mem_mul, eq_univ_iff_forall, mem_univ, true_and]\nend\n\n@[simp, to_additive]\nlemma mul_univ [group \u03b1] (hs : s.nonempty) : s * (univ : set \u03b1) = univ :=\nlet \u27e8a, ha\u27e9 := hs in eq_univ_of_forall $ \u03bb b, \u27e8a, a\u207b\u00b9 * b, ha, trivial, mul_inv_cancel_left _ _\u27e9\n\n@[simp, to_additive]\nlemma univ_mul [group \u03b1] (ht : t.nonempty) : (univ : set \u03b1) * t = univ :=\nlet \u27e8a, ha\u27e9 := ht in eq_univ_of_forall $ \u03bb b, \u27e8b * a\u207b\u00b9, a, trivial, ha, inv_mul_cancel_right _ _\u27e9\n\n/-- `singleton` is a monoid hom. -/\n@[to_additive singleton_add_hom \"singleton is an add monoid hom\"]\ndef singleton_hom [monoid \u03b1] : \u03b1 \u2192* set \u03b1 :=\n{ to_fun := singleton, map_one' := rfl, map_mul' := \u03bb a b, singleton_mul_singleton.symm }\n\n@[to_additive]\nlemma nonempty.mul [has_mul \u03b1] : s.nonempty \u2192 t.nonempty \u2192 (s * t).nonempty := nonempty.image2\n\n@[to_additive]\nlemma finite.mul [has_mul \u03b1] (hs : finite s) (ht : finite t) : finite (s * t) :=\nhs.image2 _ ht\n\n/-- multiplication preserves finiteness -/\n@[to_additive \"addition preserves finiteness\"]\ndef fintype_mul [has_mul \u03b1] [decidable_eq \u03b1] (s t : set \u03b1) [hs : fintype s] [ht : fintype t] :\n  fintype (s * t : set \u03b1) :=\nset.fintype_image2 _ s t\n\n@[to_additive]\nlemma bdd_above_mul [ordered_comm_monoid \u03b1] {A B : set \u03b1} :\n  bdd_above A \u2192 bdd_above B \u2192 bdd_above (A * B) :=\nbegin\n  rintros \u27e8bA, hbA\u27e9 \u27e8bB, hbB\u27e9,\n  use bA * bB,\n  rintros x \u27e8xa, xb, hxa, hxb, rfl\u27e9,\n  exact mul_le_mul' (hbA hxa) (hbB hxb),\nend\n\nend mul\n\nopen_locale pointwise\n\nsection big_operators\nopen_locale big_operators\n\nvariables {\u03b9 : Type*} [comm_monoid \u03b1]\n\n/-- The n-ary version of `set.mem_mul`. -/\n@[to_additive /-\" The n-ary version of `set.mem_add`. \"-/]\nlemma mem_finset_prod (t : finset \u03b9) (f : \u03b9 \u2192 set \u03b1) (a : \u03b1) :\n  a \u2208 \u220f i in t, f i \u2194 \u2203 (g : \u03b9 \u2192 \u03b1) (hg : \u2200 {i}, i \u2208 t \u2192 g i \u2208 f i), \u220f i in t, g i = a :=\nbegin\n  classical,\n  induction t using finset.induction_on with i is hi ih generalizing a,\n  { simp_rw [finset.prod_empty, set.mem_one],\n    exact \u27e8\u03bb h, \u27e8\u03bb i, a, \u03bb i, false.elim, h.symm\u27e9, \u03bb \u27e8f, _, hf\u27e9, hf.symm\u27e9 },\n  rw [finset.prod_insert hi, set.mem_mul],\n  simp_rw [finset.prod_insert hi],\n  simp_rw ih,\n  split,\n  { rintros \u27e8x, y, hx, \u27e8g, hg, rfl\u27e9, rfl\u27e9,\n    refine \u27e8function.update g i x, \u03bb j hj, _, _\u27e9,\n    obtain rfl | hj := finset.mem_insert.mp hj,\n    { rw function.update_same, exact hx },\n    { rw update_noteq (ne_of_mem_of_not_mem hj hi), exact hg hj, },\n    rw [finset.prod_update_of_not_mem hi, function.update_same], },\n  { rintros \u27e8g, hg, rfl\u27e9,\n    exact \u27e8g i, is.prod g, hg (is.mem_insert_self _),\n      \u27e8g, \u03bb i hi, hg (finset.mem_insert_of_mem hi), rfl\u27e9, rfl\u27e9 },\nend\n\n/-- A version of `set.mem_finset_prod` with a simpler RHS for products over a fintype. -/\n@[to_additive /-\" A version of `set.mem_finset_sum` with a simpler RHS for sums over a fintype. \"-/]\nlemma mem_fintype_prod [fintype \u03b9] (f : \u03b9 \u2192 set \u03b1) (a : \u03b1) :\n  a \u2208 \u220f i, f i \u2194 \u2203 (g : \u03b9 \u2192 \u03b1) (hg : \u2200 i, g i \u2208 f i), \u220f i, g i = a :=\nby { rw mem_finset_prod, simp }\n\n/-- The n-ary version of `set.mul_mem_mul`. -/\n@[to_additive /-\" The n-ary version of `set.add_mem_add`. \"-/]\nlemma finset_prod_mem_finset_prod (t : finset \u03b9) (f : \u03b9 \u2192 set \u03b1)\n  (g : \u03b9 \u2192 \u03b1) (hg : \u2200 i \u2208 t, g i \u2208 f i) :\n  \u220f i in t, g i \u2208 \u220f i in t, f i :=\nby { rw mem_finset_prod, exact \u27e8g, hg, rfl\u27e9 }\n\n/-- The n-ary version of `set.mul_subset_mul`. -/\n@[to_additive /-\" The n-ary version of `set.add_subset_add`. \"-/]\nlemma finset_prod_subset_finset_prod (t : finset \u03b9) (f\u2081 f\u2082 : \u03b9 \u2192 set \u03b1)\n  (hf : \u2200 {i}, i \u2208 t \u2192 f\u2081 i \u2286 f\u2082 i) :\n  \u220f i in t, f\u2081 i \u2286 \u220f i in t, f\u2082 i :=\nbegin\n  intro a,\n  rw [mem_finset_prod, mem_finset_prod],\n  rintro \u27e8g, hg, rfl\u27e9,\n  exact \u27e8g, \u03bb i hi, hf hi $ hg hi, rfl\u27e9\nend\n\n@[to_additive]\nlemma finset_prod_singleton {M \u03b9 : Type*} [comm_monoid M] (s : finset \u03b9) (I : \u03b9 \u2192 M) :\n  \u220f (i : \u03b9) in s, ({I i} : set M) = {\u220f (i : \u03b9) in s, I i} :=\nbegin\n  letI := classical.dec_eq \u03b9,\n  refine finset.induction_on s _ _,\n  { simpa },\n  { intros _ _ H ih,\n    rw [finset.prod_insert H, finset.prod_insert H, ih],\n    simp }\nend\n\n/-! TODO: define `decidable_mem_finset_prod` and `decidable_mem_finset_sum`. -/\n\nend big_operators\n\n/-! ### Properties about inversion -/\n\nsection inv\nvariables {s t : set \u03b1} {a : \u03b1}\n\n/-- The set `(s\u207b\u00b9 : set \u03b1)` is defined as `{x | x\u207b\u00b9 \u2208 s}` in locale `pointwise`.\nIt is equal to `{x\u207b\u00b9 | x \u2208 s}`, see `set.image_inv`. -/\n@[to_additive\n/-\" The set `(-s : set \u03b1)` is defined as `{x | -x \u2208 s}` in locale `pointwise`.\nIt is equal to `{-x | x \u2208 s}`, see `set.image_neg`. \"-/]\nprotected def has_inv [has_inv \u03b1] : has_inv (set \u03b1) :=\n\u27e8preimage has_inv.inv\u27e9\n\nlocalized \"attribute [instance] set.has_inv set.has_neg\" in pointwise\n\n@[simp, to_additive]\nlemma inv_empty [has_inv \u03b1] : (\u2205 : set \u03b1)\u207b\u00b9 = \u2205 := rfl\n\n@[simp, to_additive]\nlemma inv_univ [has_inv \u03b1] : (univ : set \u03b1)\u207b\u00b9 = univ := rfl\n\n@[simp, to_additive]\nlemma nonempty_inv [group \u03b1] {s : set \u03b1} : s\u207b\u00b9.nonempty \u2194 s.nonempty :=\ninv_involutive.surjective.nonempty_preimage\n\n@[to_additive] lemma nonempty.inv [group \u03b1] {s : set \u03b1} (h : s.nonempty) : s\u207b\u00b9.nonempty :=\nnonempty_inv.2 h\n\n@[simp, to_additive]\nlemma mem_inv [has_inv \u03b1] : a \u2208 s\u207b\u00b9 \u2194 a\u207b\u00b9 \u2208 s := iff.rfl\n\n@[to_additive]\nlemma inv_mem_inv [group \u03b1] : a\u207b\u00b9 \u2208 s\u207b\u00b9 \u2194 a \u2208 s :=\nby simp only [mem_inv, inv_inv]\n\n@[simp, to_additive]\nlemma inv_preimage [has_inv \u03b1] : has_inv.inv \u207b\u00b9' s = s\u207b\u00b9 := rfl\n\n@[simp, to_additive]\nlemma image_inv [group \u03b1] : has_inv.inv '' s = s\u207b\u00b9 :=\nby { simp only [\u2190 inv_preimage], rw [image_eq_preimage_of_inverse]; intro; simp only [inv_inv] }\n\n@[simp, to_additive]\nlemma inter_inv [has_inv \u03b1] : (s \u2229 t)\u207b\u00b9 = s\u207b\u00b9 \u2229 t\u207b\u00b9 := preimage_inter\n\n@[simp, to_additive]\nlemma union_inv [has_inv \u03b1] : (s \u222a t)\u207b\u00b9 = s\u207b\u00b9 \u222a t\u207b\u00b9 := preimage_union\n\n@[simp, to_additive]\nlemma Inter_inv {\u03b9 : Sort*} [has_inv \u03b1] (s : \u03b9 \u2192 set \u03b1) : (\u22c2 i, s i)\u207b\u00b9 = \u22c2 i, (s i)\u207b\u00b9 :=\npreimage_Inter\n\n@[simp, to_additive]\nlemma Union_inv {\u03b9 : Sort*} [has_inv \u03b1] (s : \u03b9 \u2192 set \u03b1) : (\u22c3 i, s i)\u207b\u00b9 = \u22c3 i, (s i)\u207b\u00b9 :=\npreimage_Union\n\n@[simp, to_additive]\nlemma compl_inv [has_inv \u03b1] : (s\u1d9c)\u207b\u00b9 = (s\u207b\u00b9)\u1d9c := preimage_compl\n\n@[simp, to_additive]\nprotected lemma inv_inv [group \u03b1] : s\u207b\u00b9\u207b\u00b9 = s :=\nby { simp only [\u2190 inv_preimage, preimage_preimage, inv_inv, preimage_id'] }\n\n@[simp, to_additive]\nprotected lemma univ_inv [group \u03b1] : (univ : set \u03b1)\u207b\u00b9 = univ := preimage_univ\n\n@[simp, to_additive]\nlemma inv_subset_inv [group \u03b1] {s t : set \u03b1} : s\u207b\u00b9 \u2286 t\u207b\u00b9 \u2194 s \u2286 t :=\n(equiv.inv \u03b1).surjective.preimage_subset_preimage_iff\n\n@[to_additive] lemma inv_subset [group \u03b1] {s t : set \u03b1} : s\u207b\u00b9 \u2286 t \u2194 s \u2286 t\u207b\u00b9 :=\nby { rw [\u2190 inv_subset_inv, set.inv_inv] }\n\n@[to_additive] lemma finite.inv [group \u03b1] {s : set \u03b1} (hs : finite s) : finite s\u207b\u00b9 :=\nhs.preimage $ inv_injective.inj_on _\n\n@[to_additive] lemma inv_singleton {\u03b2 : Type*} [group \u03b2] (x : \u03b2) : ({x} : set \u03b2)\u207b\u00b9 = {x\u207b\u00b9} :=\nby { ext1 y, rw [mem_inv, mem_singleton_iff, mem_singleton_iff, inv_eq_iff_inv_eq, eq_comm], }\n\n@[to_additive] protected lemma mul_inv_rev [group \u03b1] (s t : set \u03b1) : (s * t)\u207b\u00b9 = t\u207b\u00b9 * s\u207b\u00b9 :=\nby simp_rw [\u2190image_inv, \u2190image2_mul, image_image2, image2_image_left, image2_image_right,\n              mul_inv_rev, image2_swap _ s t]\n\nend inv\n\n/-! ### Properties about scalar multiplication -/\n\nsection smul\n\n/-- The scaling of a set `(x \u2022 s : set \u03b2)` by a scalar `x \u2236 \u03b1` is defined as `{x \u2022 y | y \u2208 s}`\nin locale `pointwise`. -/\n@[to_additive has_vadd_set \"The translation of a set `(x +\u1d65 s : set \u03b2)` by a scalar `x \u2236 \u03b1` is\ndefined as `{x +\u1d65 y | y \u2208 s}` in locale `pointwise`.\"]\nprotected def has_scalar_set [has_scalar \u03b1 \u03b2] : has_scalar \u03b1 (set \u03b2) :=\n\u27e8\u03bb a, image (has_scalar.smul a)\u27e9\n\n/-- The pointwise scalar multiplication `(s \u2022 t : set \u03b2)` by a set of scalars `s \u2236 set \u03b1`\nis defined as `{x \u2022 y | x \u2208 s, y \u2208 t}` in locale `pointwise`. -/\n@[to_additive has_vadd \"The pointwise translation `(s +\u1d65 t : set \u03b2)` by a set of constants\n`s \u2236 set \u03b1` is defined as `{x +\u1d65 y | x \u2208 s, y \u2208 t}` in locale `pointwise`.\"]\nprotected def has_scalar [has_scalar \u03b1 \u03b2] : has_scalar (set \u03b1) (set \u03b2) :=\n\u27e8image2 has_scalar.smul\u27e9\n\nlocalized \"attribute [instance] set.has_scalar_set set.has_scalar\" in pointwise\nlocalized \"attribute [instance] set.has_vadd_set set.has_vadd\" in pointwise\n\nsection has_scalar\nvariables {\u03b9 : Sort*} {\u03ba : \u03b9 \u2192 Sort*} [has_scalar \u03b1 \u03b2] {s s\u2081 s\u2082 : set \u03b1} {t t\u2081 t\u2082 u : set \u03b2} {a : \u03b1}\n  {b : \u03b2}\n\n@[simp, to_additive]\nlemma image2_smul : image2 has_scalar.smul s t = s \u2022 t := rfl\n\n@[to_additive add_image_prod]\nlemma image_smul_prod : (\u03bb x : \u03b1 \u00d7 \u03b2, x.fst \u2022 x.snd) '' (s \u00d7\u02e2 t) = s \u2022 t := image_prod _\n\n@[to_additive]\nlemma mem_smul : b \u2208 s \u2022 t \u2194 \u2203 x y, x \u2208 s \u2227 y \u2208 t \u2227 x \u2022 y = b := iff.rfl\n\n@[to_additive]\nlemma smul_mem_smul (ha : a \u2208 s) (hb : b \u2208 t) : a \u2022 b \u2208 s \u2022 t := mem_image2_of_mem ha hb\n\n@[to_additive]\nlemma smul_subset_smul (hs : s\u2081 \u2286 s\u2082) (ht : t\u2081 \u2286 t\u2082) : s\u2081 \u2022 t\u2081 \u2286 s\u2082 \u2022 t\u2082 := image2_subset hs ht\n\n@[to_additive] lemma smul_subset_iff : s \u2022 t \u2286 u \u2194 \u2200 (a \u2208 s) (b \u2208 t), a \u2022 b \u2208 u := image2_subset_iff\n\n@[simp, to_additive] lemma empty_smul : (\u2205 : set \u03b1) \u2022 t = \u2205 := image2_empty_left\n@[simp, to_additive] lemma smul_empty : s \u2022 (\u2205 : set \u03b2) = \u2205 := image2_empty_right\n\n@[simp, to_additive] lemma smul_singleton : s \u2022 {b} = (\u2022 b) '' s := image2_singleton_right\n@[simp, to_additive] lemma singleton_smul : ({a} : set \u03b1) \u2022 t = a \u2022 t := image2_singleton_left\n\n@[simp, to_additive]\nlemma singleton_smul_singleton : ({a} : set \u03b1) \u2022 ({b} : set \u03b2) = {a \u2022 b} := image2_singleton\n\n@[to_additive] lemma smul_subset_smul_left (h : t\u2081 \u2286 t\u2082) : s \u2022 t\u2081 \u2286 s \u2022 t\u2082 := image2_subset_left h\n@[to_additive] lemma smul_subset_smul_right (h : s\u2081 \u2286 s\u2082) : s\u2081 \u2022 t \u2286 s\u2082 \u2022 t := image2_subset_right h\n\n@[to_additive] lemma union_smul : (s\u2081 \u222a s\u2082) \u2022 t = s\u2081 \u2022 t \u222a s\u2082 \u2022 t := image2_union_left\n@[to_additive] lemma smul_union : s \u2022 (t\u2081 \u222a t\u2082) = s \u2022 t\u2081 \u222a s \u2022 t\u2082 := image2_union_right\n\n@[to_additive]\nlemma inter_smul_subset : (s\u2081 \u2229 s\u2082) \u2022 t \u2286 s\u2081 \u2022 t \u2229 s\u2082 \u2022 t := image2_inter_subset_left\n\n@[to_additive]\nlemma smul_inter_subset : s \u2022 (t\u2081 \u2229 t\u2082) \u2286 s \u2022 t\u2081 \u2229 s \u2022 t\u2082 := image2_inter_subset_right\n\n@[to_additive]\nlemma Union_smul_left_image : (\u22c3 a \u2208 s, a \u2022 t) = s \u2022 t := Union_image_left _\n\n@[to_additive]\nlemma Union_smul_right_image : (\u22c3 a \u2208 t, (\u03bb x, x \u2022 a) '' s) = s \u2022 t := Union_image_right _\n\n@[to_additive]\nlemma Union_smul (s : \u03b9 \u2192 set \u03b1) (t : set \u03b2) : (\u22c3 i, s i) \u2022 t = \u22c3 i, s i \u2022 t :=\nimage2_Union_left _ _ _\n\n@[to_additive]\nlemma smul_Union (s : set \u03b1) (t : \u03b9 \u2192 set \u03b2) : s \u2022 (\u22c3 i, t i) = \u22c3 i, s \u2022 t i :=\nimage2_Union_right _ _ _\n\n@[to_additive]\nlemma Union\u2082_smul (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b2) : (\u22c3 i j, s i j) \u2022 t = \u22c3 i j, s i j \u2022 t :=\nimage2_Union\u2082_left _ _ _\n\n@[to_additive]\nlemma smul_Union\u2082 (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b2) : s \u2022 (\u22c3 i j, t i j) = \u22c3 i j, s \u2022 t i j :=\nimage2_Union\u2082_right _ _ _\n\n@[to_additive]\nlemma Inter_smul_subset (s : \u03b9 \u2192 set \u03b1) (t : set \u03b2) : (\u22c2 i, s i) \u2022 t \u2286 \u22c2 i, s i \u2022 t :=\nimage2_Inter_subset_left _ _ _\n\n@[to_additive]\nlemma smul_Inter_subset (s : set \u03b1) (t : \u03b9 \u2192 set \u03b2) : s \u2022 (\u22c2 i, t i) \u2286 \u22c2 i, s \u2022 t i :=\nimage2_Inter_subset_right _ _ _\n\n@[to_additive]\nlemma Inter\u2082_smul_subset (s : \u03a0 i, \u03ba i \u2192 set \u03b1) (t : set \u03b2) :\n  (\u22c2 i j, s i j) \u2022 t \u2286 \u22c2 i j, s i j \u2022 t :=\nimage2_Inter\u2082_subset_left _ _ _\n\n@[to_additive]\nlemma smul_Inter\u2082_subset (s : set \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b2) :\n  s \u2022 (\u22c2 i j, t i j) \u2286 \u22c2 i j, s \u2022 t i j :=\nimage2_Inter\u2082_subset_right _ _ _\n\nend has_scalar\n\nsection has_scalar_set\nvariables {\u03b9 : Sort*} {\u03ba : \u03b9 \u2192 Sort*} [has_scalar \u03b1 \u03b2] {s t t\u2081 t\u2082 : set \u03b2} {a : \u03b1} {b : \u03b2} {x y : \u03b2}\n\n@[simp, to_additive] lemma image_smul : (\u03bb x, a \u2022 x) '' t = a \u2022 t := rfl\n\n@[to_additive] lemma mem_smul_set : x \u2208 a \u2022 t \u2194 \u2203 y, y \u2208 t \u2227 a \u2022 y = x := iff.rfl\n\n@[to_additive] lemma smul_mem_smul_set (hy : y \u2208 t) : a \u2022 y \u2208 a \u2022 t := \u27e8y, hy, rfl\u27e9\n\n@[to_additive]\nlemma mem_smul_of_mem {s : set \u03b1} (ha : a \u2208 s) (hb : b \u2208 t) : a \u2022 b \u2208 s \u2022 t :=\nmem_image2_of_mem ha hb\n\n@[simp, to_additive] lemma smul_set_empty : a \u2022 (\u2205 : set \u03b2) = \u2205 := image_empty _\n\n@[simp, to_additive] lemma smul_set_singleton : a \u2022 ({b} : set \u03b2) = {a \u2022 b} := image_singleton\n\n@[to_additive] lemma smul_set_mono (h : s \u2286 t) : a \u2022 s \u2286 a \u2022 t := image_subset _ h\n\n@[to_additive] lemma smul_set_union : a \u2022 (t\u2081 \u222a t\u2082) = a \u2022 t\u2081 \u222a a \u2022 t\u2082 := image_union _ _ _\n\n@[to_additive]\nlemma smul_set_inter_subset : a \u2022 (t\u2081 \u2229 t\u2082) \u2286 a \u2022 t\u2081 \u2229 (a \u2022 t\u2082) := image_inter_subset _ _ _\n\n@[to_additive]\nlemma smul_set_Union (a : \u03b1) (s : \u03b9 \u2192 set \u03b2) : a \u2022 (\u22c3 i, s i) = \u22c3 i, a \u2022 s i := image_Union\n\n@[to_additive]\nlemma smul_set_Union\u2082 (a : \u03b1) (s : \u03a0 i, \u03ba i \u2192 set \u03b2) : a \u2022 (\u22c3 i j, s i j) = \u22c3 i j, a \u2022 s i j :=\nimage_Union\u2082 _ _\n\n@[to_additive]\nlemma smul_set_Inter_subset (a : \u03b1) (t : \u03b9 \u2192 set \u03b2) : a \u2022 (\u22c2 i, t i) \u2286 \u22c2 i, a \u2022 t i :=\nimage_Inter_subset _ _\n\n@[to_additive]\nlemma smul_set_Inter\u2082_subset (a : \u03b1) (t : \u03a0 i, \u03ba i \u2192 set \u03b2) :\n  a \u2022 (\u22c2 i j, t i j) \u2286 \u22c2 i j, a \u2022 t i j :=\nimage_Inter\u2082_subset _ _\n\n@[to_additive] lemma finite.smul_set (hs : finite s) : finite (a \u2022 s) := hs.image _\n\nend has_scalar_set\n\nvariables {s s\u2081 s\u2082 : set \u03b1} {t t\u2081 t\u2082 : set \u03b2} {a : \u03b1} {b : \u03b2}\n\n@[to_additive]\nlemma smul_set_inter [group \u03b1] [mul_action \u03b1 \u03b2] {s t : set \u03b2} :\n  a \u2022 (s \u2229 t) = a \u2022 s \u2229 a \u2022 t :=\n(image_inter $ mul_action.injective a).symm\n\nlemma smul_set_inter\u2080 [group_with_zero \u03b1] [mul_action \u03b1 \u03b2] {s t : set \u03b2} (ha : a \u2260 0) :\n  a \u2022 (s \u2229 t) = a \u2022 s \u2229 a \u2022 t :=\nshow units.mk0 a ha \u2022 _ = _, from smul_set_inter\n\n@[simp, to_additive]\nlemma smul_set_univ [group \u03b1] [mul_action \u03b1 \u03b2] {a : \u03b1} : a \u2022 (univ : set \u03b2) = univ :=\neq_univ_of_forall $ \u03bb b, \u27e8a\u207b\u00b9 \u2022 b, trivial, smul_inv_smul _ _\u27e9\n\n@[simp, to_additive]\nlemma smul_univ [group \u03b1] [mul_action \u03b1 \u03b2] {s : set \u03b1} (hs : s.nonempty) :\n  s \u2022 (univ : set \u03b2) = univ :=\nlet \u27e8a, ha\u27e9 := hs in eq_univ_of_forall $ \u03bb b, \u27e8a, a\u207b\u00b9 \u2022 b, ha, trivial, smul_inv_smul _ _\u27e9\n\n@[to_additive]\ntheorem range_smul_range {\u03b9 \u03ba : Type*} [has_scalar \u03b1 \u03b2] (b : \u03b9 \u2192 \u03b1) (c : \u03ba \u2192 \u03b2) :\n  range b \u2022 range c = range (\u03bb p : \u03b9 \u00d7 \u03ba, b p.1 \u2022 c p.2) :=\next $ \u03bb x, \u27e8\u03bb hx, let \u27e8p, q, \u27e8i, hi\u27e9, \u27e8j, hj\u27e9, hpq\u27e9 := set.mem_smul.1 hx in\n  \u27e8(i, j), hpq \u25b8 hi \u25b8 hj \u25b8 rfl\u27e9,\n\u03bb \u27e8\u27e8i, j\u27e9, h\u27e9, set.mem_smul.2 \u27e8b i, c j, \u27e8i, rfl\u27e9, \u27e8j, rfl\u27e9, h\u27e9\u27e9\n\n@[to_additive]\ninstance smul_comm_class_set [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [smul_comm_class \u03b1 \u03b2 \u03b3] :\n  smul_comm_class \u03b1 (set \u03b2) (set \u03b3) :=\n{ smul_comm := \u03bb a T T',\n    by simp only [\u2190image2_smul, \u2190image_smul, image2_image_right, image_image2, smul_comm] }\n\n@[to_additive]\ninstance smul_comm_class_set' [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [smul_comm_class \u03b1 \u03b2 \u03b3] :\n  smul_comm_class (set \u03b1) \u03b2 (set \u03b3) :=\nby haveI := smul_comm_class.symm \u03b1 \u03b2 \u03b3; exact smul_comm_class.symm _ _ _\n\n@[to_additive]\ninstance smul_comm_class [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3] [smul_comm_class \u03b1 \u03b2 \u03b3] :\n  smul_comm_class (set \u03b1) (set \u03b2) (set \u03b3) :=\n{ smul_comm := \u03bb T T' T'', begin\n    simp only [\u2190image2_smul, image2_swap _ T],\n    exact image2_assoc (\u03bb b c a, smul_comm a b c),\n  end }\n\ninstance is_scalar_tower [has_scalar \u03b1 \u03b2] [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3]\n  [is_scalar_tower \u03b1 \u03b2 \u03b3] :\n  is_scalar_tower \u03b1 \u03b2 (set \u03b3) :=\n{ smul_assoc := \u03bb a b T, by simp only [\u2190image_smul, image_image, smul_assoc] }\n\ninstance is_scalar_tower' [has_scalar \u03b1 \u03b2] [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3]\n  [is_scalar_tower \u03b1 \u03b2 \u03b3] :\n  is_scalar_tower \u03b1 (set \u03b2) (set \u03b3) :=\n{ smul_assoc := \u03bb a T T',\n    by simp only [\u2190image_smul, \u2190image2_smul, image_image2, image2_image_left, smul_assoc] }\n\ninstance is_scalar_tower'' [has_scalar \u03b1 \u03b2] [has_scalar \u03b1 \u03b3] [has_scalar \u03b2 \u03b3]\n  [is_scalar_tower \u03b1 \u03b2 \u03b3] :\n  is_scalar_tower (set \u03b1) (set \u03b2) (set \u03b3) :=\n{ smul_assoc := \u03bb T T' T'', image2_assoc smul_assoc }\n\ninstance is_central_scalar [has_scalar \u03b1 \u03b2] [has_scalar \u03b1\u1d50\u1d52\u1d56 \u03b2] [is_central_scalar \u03b1 \u03b2] :\n  is_central_scalar \u03b1 (set \u03b2) :=\n\u27e8\u03bb a S, congr_arg (\u03bb f, f '' S) $ by exact funext (\u03bb _, op_smul_eq_smul _ _)\u27e9\n\nend smul\n\nsection vsub\nvariables {\u03b9 : Sort*} {\u03ba : \u03b9 \u2192 Sort*} [has_vsub \u03b1 \u03b2] {s s\u2081 s\u2082 t t\u2081 t\u2082 : set \u03b2} {a : \u03b1}\n  {b c : \u03b2}\ninclude \u03b1\n\ninstance has_vsub : has_vsub (set \u03b1) (set \u03b2) := \u27e8image2 (-\u1d65)\u27e9\n\n@[simp] lemma image2_vsub : (image2 has_vsub.vsub s t : set \u03b1) = s -\u1d65 t := rfl\n\nlemma image_vsub_prod : (\u03bb x : \u03b2 \u00d7 \u03b2, x.fst -\u1d65 x.snd) '' (s \u00d7\u02e2 t) = s -\u1d65 t := image_prod _\n\nlemma mem_vsub : a \u2208 s -\u1d65 t \u2194 \u2203 x y, x \u2208 s \u2227 y \u2208 t \u2227 x -\u1d65 y = a := iff.rfl\n\nlemma vsub_mem_vsub (hb : b \u2208 s) (hc : c \u2208 t) : b -\u1d65 c \u2208 s -\u1d65 t := mem_image2_of_mem hb hc\n\nlemma vsub_subset_vsub (hs : s\u2081 \u2286 s\u2082) (ht : t\u2081 \u2286 t\u2082) : s\u2081 -\u1d65 t\u2081 \u2286 s\u2082 -\u1d65 t\u2082 := image2_subset hs ht\n\nlemma vsub_subset_iff {u : set \u03b1} : s -\u1d65 t \u2286 u \u2194 \u2200 (x \u2208 s) (y \u2208 t), x -\u1d65 y \u2208 u := image2_subset_iff\n\n@[simp] lemma empty_vsub (t : set \u03b2) : \u2205 -\u1d65 t = \u2205 := image2_empty_left\n@[simp] lemma vsub_empty (s : set \u03b2) : s -\u1d65 \u2205 = \u2205 := image2_empty_right\n\n@[simp] lemma vsub_singleton (s : set \u03b2) (b : \u03b2) : s -\u1d65 {b} = (-\u1d65 b) '' s := image2_singleton_right\n@[simp] lemma singleton_vsub (t : set \u03b2) (b : \u03b2) : {b} -\u1d65 t = ((-\u1d65) b) '' t := image2_singleton_left\n\n@[simp] lemma singleton_vsub_singleton : ({b} : set \u03b2) -\u1d65 {c} = {b -\u1d65 c} := image2_singleton\n\nlemma vsub_subset_vsub_left (h : t\u2081 \u2286 t\u2082) : s -\u1d65 t\u2081 \u2286 s -\u1d65 t\u2082 := image2_subset_left h\nlemma vsub_subset_vsub_right (h : s\u2081 \u2286 s\u2082) : s\u2081 -\u1d65 t \u2286 s\u2082 -\u1d65 t := image2_subset_right h\n\nlemma union_vsub : (s\u2081 \u222a s\u2082) -\u1d65 t = s\u2081 -\u1d65 t \u222a (s\u2082 -\u1d65 t) := image2_union_left\nlemma vsub_union : s -\u1d65 (t\u2081 \u222a t\u2082) = s -\u1d65 t\u2081 \u222a (s -\u1d65 t\u2082) := image2_union_right\n\nlemma inter_vsub_subset : s\u2081 \u2229 s\u2082 -\u1d65 t \u2286 (s\u2081 -\u1d65 t) \u2229 (s\u2082 -\u1d65 t) := image2_inter_subset_left\nlemma vsub_inter_subset : s -\u1d65 t\u2081 \u2229 t\u2082 \u2286 (s -\u1d65 t\u2081) \u2229 (s -\u1d65 t\u2082) := image2_inter_subset_right\n\nlemma Union_vsub_left_image : (\u22c3 a \u2208 s, ((-\u1d65) a) '' t) = s -\u1d65 t := Union_image_left _\nlemma Union_vsub_right_image : (\u22c3 a \u2208 t, (-\u1d65 a) '' s) = s -\u1d65 t := Union_image_right _\n\nlemma Union_vsub (s : \u03b9 \u2192 set \u03b2) (t : set \u03b2) : (\u22c3 i, s i) -\u1d65 t = \u22c3 i, s i -\u1d65 t :=\nimage2_Union_left _ _ _\n\nlemma vsub_Union (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) : s -\u1d65 (\u22c3 i, t i) = \u22c3 i, s -\u1d65 t i :=\nimage2_Union_right _ _ _\n\nlemma Union\u2082_vsub (s : \u03a0 i, \u03ba i \u2192 set \u03b2) (t : set \u03b2) : (\u22c3 i j, s i j) -\u1d65 t = \u22c3 i j, s i j -\u1d65 t :=\nimage2_Union\u2082_left _ _ _\n\nlemma vsub_Union\u2082 (s : set \u03b2) (t : \u03a0 i, \u03ba i \u2192 set \u03b2) : s -\u1d65 (\u22c3 i j, t i j) = \u22c3 i j, s -\u1d65 t i j :=\nimage2_Union\u2082_right _ _ _\n\nlemma Inter_vsub_subset (s : \u03b9 \u2192 set \u03b2) (t : set \u03b2) : (\u22c2 i, s i) -\u1d65 t \u2286 \u22c2 i, s i -\u1d65 t :=\nimage2_Inter_subset_left _ _ _\n\nlemma vsub_Inter_subset (s : set \u03b2) (t : \u03b9 \u2192 set \u03b2) : s -\u1d65 (\u22c2 i, t i) \u2286 \u22c2 i, s -\u1d65 t i :=\nimage2_Inter_subset_right _ _ _\n\nlemma Inter\u2082_vsub_subset (s : \u03a0 i, \u03ba i \u2192 set \u03b2) (t : set \u03b2) :\n  (\u22c2 i j, s i j) -\u1d65 t \u2286 \u22c2 i j, s i j -\u1d65 t :=\nimage2_Inter\u2082_subset_left _ _ _\n\nlemma vsub_Inter\u2082_subset (s : set \u03b2) (t : \u03a0 i, \u03ba i \u2192 set \u03b2) :\n  s -\u1d65 (\u22c2 i j, t i j) \u2286 \u22c2 i j, s -\u1d65 t i j :=\nimage2_Inter\u2082_subset_right _ _ _\n\nlemma finite.vsub (hs : finite s) (ht : finite t) : finite (s -\u1d65 t) := hs.image2 _ ht\n\nlemma vsub_self_mono (h : s \u2286 t) : s -\u1d65 s \u2286 t -\u1d65 t := vsub_subset_vsub h h\n\nend vsub\n\nopen_locale pointwise\n\nsection ring\nvariables [ring \u03b1] [add_comm_group \u03b2] [module \u03b1 \u03b2] {s : set \u03b1} {t : set \u03b2} {a : \u03b1}\n\n@[simp] lemma neg_smul_set : -a \u2022 t = -(a \u2022 t) :=\nby simp_rw [\u2190image_smul, \u2190image_neg, image_image, neg_smul]\n\n@[simp] lemma smul_set_neg : a \u2022 -t = -(a \u2022 t) :=\nby simp_rw [\u2190image_smul, \u2190image_neg, image_image, smul_neg]\n\n@[simp] protected lemma neg_smul : -s \u2022 t = -(s \u2022 t) :=\nby simp_rw [\u2190image2_smul, \u2190image_neg, image2_image_left, image_image2, neg_smul]\n\n@[simp] protected lemma smul_neg : s \u2022 -t = -(s \u2022 t) :=\nby simp_rw [\u2190image2_smul, \u2190image_neg, image2_image_right, image_image2, smul_neg]\n\nend ring\n\nsection monoid\n\n/-! ### `set \u03b1` as a `(\u222a,*)`-semiring -/\n\n/-- An alias for `set \u03b1`, which has a semiring structure given by `\u222a` as \"addition\" and pointwise\n  multiplication `*` as \"multiplication\". -/\n@[derive [inhabited, partial_order, order_bot]] def set_semiring (\u03b1 : Type*) : Type* := set \u03b1\n\n/-- The identitiy function `set \u03b1 \u2192 set_semiring \u03b1`. -/\nprotected def up (s : set \u03b1) : set_semiring \u03b1 := s\n/-- The identitiy function `set_semiring \u03b1 \u2192 set \u03b1`. -/\nprotected def set_semiring.down (s : set_semiring \u03b1) : set \u03b1 := s\n@[simp] protected lemma down_up {s : set \u03b1} : s.up.down = s := rfl\n@[simp] protected lemma up_down {s : set_semiring \u03b1} : s.down.up = s := rfl\n\n/- This lemma is not tagged `simp`, since otherwise the linter complains. -/\nlemma up_le_up {s t : set \u03b1} : s.up \u2264 t.up \u2194 s \u2286 t := iff.rfl\n/- This lemma is not tagged `simp`, since otherwise the linter complains. -/\nlemma up_lt_up {s t : set \u03b1} : s.up < t.up \u2194 s \u2282 t := iff.rfl\n\n@[simp] lemma down_subset_down {s t : set_semiring \u03b1} : s.down \u2286 t.down \u2194 s \u2264 t := iff.rfl\n@[simp] lemma down_ssubset_down {s t : set_semiring \u03b1} : s.down \u2282 t.down \u2194 s < t := iff.rfl\n\ninstance set_semiring.add_comm_monoid : add_comm_monoid (set_semiring \u03b1) :=\n{ add := \u03bb s t, (s \u222a t : set \u03b1),\n  zero := (\u2205 : set \u03b1),\n  add_assoc := union_assoc,\n  zero_add := empty_union,\n  add_zero := union_empty,\n  add_comm := union_comm, }\n\ninstance set_semiring.non_unital_non_assoc_semiring [has_mul \u03b1] :\n  non_unital_non_assoc_semiring (set_semiring \u03b1) :=\n{ zero_mul := \u03bb s, empty_mul,\n  mul_zero := \u03bb s, mul_empty,\n  left_distrib := \u03bb _ _ _, mul_union,\n  right_distrib := \u03bb _ _ _, union_mul,\n  ..set.has_mul, ..set_semiring.add_comm_monoid }\n\ninstance set_semiring.non_assoc_semiring [mul_one_class \u03b1] : non_assoc_semiring (set_semiring \u03b1) :=\n{ ..set_semiring.non_unital_non_assoc_semiring, ..set.mul_one_class }\n\ninstance set_semiring.non_unital_semiring [semigroup \u03b1] : non_unital_semiring (set_semiring \u03b1) :=\n{ ..set_semiring.non_unital_non_assoc_semiring, ..set.semigroup }\n\ninstance set_semiring.semiring [monoid \u03b1] : semiring (set_semiring \u03b1) :=\n{ ..set_semiring.non_assoc_semiring, ..set_semiring.non_unital_semiring }\n\ninstance set_semiring.comm_semiring [comm_monoid \u03b1] : comm_semiring (set_semiring \u03b1) :=\n{ ..set.comm_monoid, ..set_semiring.semiring }\n\n/-- A multiplicative action of a monoid on a type \u03b2 gives also a\n multiplicative action on the subsets of \u03b2. -/\n@[to_additive \"An additive action of an additive monoid on a type \u03b2 gives also an additive action\non the subsets of \u03b2.\"]\nprotected def mul_action_set [monoid \u03b1] [mul_action \u03b1 \u03b2] : mul_action \u03b1 (set \u03b2) :=\n{ mul_smul := by { intros, simp only [\u2190 image_smul, image_image, \u2190 mul_smul] },\n  one_smul := by { intros, simp only [\u2190 image_smul, image_eta, one_smul, image_id'] },\n  ..set.has_scalar_set }\n\nlocalized \"attribute [instance] set.mul_action_set set.add_action_set\" in pointwise\n\nsection mul_hom\n\nvariables [has_mul \u03b1] [has_mul \u03b2] (m : mul_hom \u03b1 \u03b2) {s t : set \u03b1}\n\n@[to_additive]\nlemma image_mul : m '' (s * t) = m '' s * m '' t :=\nby { simp only [\u2190 image2_mul, image_image2, image2_image_left, image2_image_right, m.map_mul] }\n\n@[to_additive]\nlemma preimage_mul_preimage_subset {s t : set \u03b2} : m \u207b\u00b9' s * m \u207b\u00b9' t \u2286 m \u207b\u00b9' (s * t) :=\nby { rintros _ \u27e8_, _, _, _, rfl\u27e9, exact \u27e8_, _, \u2039_\u203a, \u2039_\u203a, (m.map_mul _ _).symm \u27e9 }\n\ninstance set_semiring.no_zero_divisors : no_zero_divisors (set_semiring \u03b1) :=\n\u27e8\u03bb a b ab, a.eq_empty_or_nonempty.imp_right $ \u03bb ha, b.eq_empty_or_nonempty.resolve_right $\n  \u03bb hb, nonempty.ne_empty \u27e8_, mul_mem_mul ha.some_mem hb.some_mem\u27e9 ab\u27e9\n\n/- Since addition on `set_semiring` is commutative (it is set union), there is no need\nto also have the instance `covariant_class (set_semiring \u03b1) (set_semiring \u03b1) (swap (+)) (\u2264)`. -/\ninstance set_semiring.covariant_class_add :\n  covariant_class (set_semiring \u03b1) (set_semiring \u03b1) (+) (\u2264) :=\n{ elim := \u03bb a b c, union_subset_union_right _ }\n\ninstance set_semiring.covariant_class_mul_left :\n  covariant_class (set_semiring \u03b1) (set_semiring \u03b1) (*) (\u2264) :=\n{ elim := \u03bb a b c, mul_subset_mul_left }\n\ninstance set_semiring.covariant_class_mul_right :\n  covariant_class (set_semiring \u03b1) (set_semiring \u03b1) (swap (*)) (\u2264) :=\n{ elim := \u03bb a b c, mul_subset_mul_right }\n\nend mul_hom\n\n/-- The image of a set under a multiplicative homomorphism is a ring homomorphism\nwith respect to the pointwise operations on sets. -/\ndef image_hom [monoid \u03b1] [monoid \u03b2] (f : \u03b1 \u2192* \u03b2) : set_semiring \u03b1 \u2192+* set_semiring \u03b2 :=\n{ to_fun := image f,\n  map_zero' := image_empty _,\n  map_one' := by simp only [\u2190 singleton_one, image_singleton, f.map_one],\n  map_add' := image_union _,\n  map_mul' := \u03bb _ _, image_mul f.to_mul_hom }\n\nend monoid\n\nsection comm_monoid\n\nvariable [comm_monoid \u03b1]\n\ninstance : canonically_ordered_comm_semiring (set_semiring \u03b1) :=\n{ add_le_add_left := \u03bb a b, add_le_add_left,\n  le_iff_exists_add := \u03bb a b, \u27e8\u03bb ab, \u27e8b, (union_eq_right_iff_subset.2 ab).symm\u27e9,\n    by { rintro \u27e8c, rfl\u27e9, exact subset_union_left _ _ }\u27e9,\n  ..(infer_instance : comm_semiring (set_semiring \u03b1)),\n  ..(infer_instance : partial_order (set_semiring \u03b1)),\n  ..(infer_instance : order_bot (set_semiring \u03b1)),\n  ..(infer_instance : no_zero_divisors (set_semiring \u03b1)) }\n\nend comm_monoid\n\nend set\n\nopen set\nopen_locale pointwise\n\nsection\n\nsection smul_with_zero\nvariables [has_zero \u03b1] [has_zero \u03b2] [smul_with_zero \u03b1 \u03b2]\n\n/-- A nonempty set is scaled by zero to the singleton set containing 0. -/\nlemma zero_smul_set {s : set \u03b2} (h : s.nonempty) : (0 : \u03b1) \u2022 s = (0 : set \u03b2) :=\nby simp only [\u2190 image_smul, image_eta, zero_smul, h.image_const, singleton_zero]\n\nlemma zero_smul_subset (s : set \u03b2) : (0 : \u03b1) \u2022 s \u2286 0 := image_subset_iff.2 $ \u03bb x _, zero_smul \u03b1 x\n\nlemma subsingleton_zero_smul_set (s : set \u03b2) : ((0 : \u03b1) \u2022 s).subsingleton :=\nsubsingleton_singleton.mono (zero_smul_subset s)\n\nlemma zero_mem_smul_set {t : set \u03b2} {a : \u03b1} (h : (0 : \u03b2) \u2208 t) : (0 : \u03b2) \u2208 a \u2022 t :=\n\u27e80, h, smul_zero' _ _\u27e9\n\nvariables [no_zero_smul_divisors \u03b1 \u03b2] {s : set \u03b1} {t : set \u03b2} {a : \u03b1}\n\nlemma zero_mem_smul_iff : (0 : \u03b2) \u2208 s \u2022 t \u2194 (0 : \u03b1) \u2208 s \u2227 t.nonempty \u2228 (0 : \u03b2) \u2208 t \u2227 s.nonempty :=\nbegin\n  split,\n  { rintro \u27e8a, b, ha, hb, h\u27e9,\n    obtain rfl | rfl := eq_zero_or_eq_zero_of_smul_eq_zero h,\n    { exact or.inl \u27e8ha, b, hb\u27e9 },\n    { exact or.inr \u27e8hb, a, ha\u27e9 } },\n  { rintro (\u27e8hs, b, hb\u27e9 | \u27e8ht, a, ha\u27e9),\n    { exact \u27e80, b, hs, hb, zero_smul _ _\u27e9 },\n    { exact \u27e8a, 0, ha, ht, smul_zero' _ _\u27e9 } }\nend\n\nlemma zero_mem_smul_set_iff (ha : a \u2260 0) : (0 : \u03b2) \u2208 a \u2022 t \u2194 (0 : \u03b2) \u2208 t :=\nbegin\n  refine \u27e8_, zero_mem_smul_set\u27e9,\n  rintro \u27e8b, hb, h\u27e9,\n  rwa (eq_zero_or_eq_zero_of_smul_eq_zero h).resolve_left ha at hb,\nend\n\nend smul_with_zero\n\nlemma smul_add_set [monoid \u03b1] [add_monoid \u03b2] [distrib_mul_action \u03b1 \u03b2] (c : \u03b1) (s t : set \u03b2) :\n  c \u2022 (s + t) = c \u2022 s + c \u2022 t :=\nimage_add (distrib_mul_action.to_add_monoid_hom \u03b2 c).to_add_hom\n\nsection group\nvariables [group \u03b1] [mul_action \u03b1 \u03b2] {A B : set \u03b2} {a : \u03b1} {x : \u03b2}\n\n@[simp, to_additive]\nlemma smul_mem_smul_set_iff : a \u2022 x \u2208 a \u2022 A \u2194 x \u2208 A :=\n\u27e8\u03bb h, begin\n  rw [\u2190inv_smul_smul a x, \u2190inv_smul_smul a A],\n  exact smul_mem_smul_set h,\nend, smul_mem_smul_set\u27e9\n\n@[to_additive]\nlemma mem_smul_set_iff_inv_smul_mem : x \u2208 a \u2022 A \u2194 a\u207b\u00b9 \u2022 x \u2208 A :=\nshow x \u2208 mul_action.to_perm a '' A \u2194 _, from mem_image_equiv\n\n@[to_additive]\nlemma mem_inv_smul_set_iff : x \u2208 a\u207b\u00b9 \u2022 A \u2194 a \u2022 x \u2208 A :=\nby simp only [\u2190 image_smul, mem_image, inv_smul_eq_iff, exists_eq_right]\n\n@[to_additive]\nlemma preimage_smul (a : \u03b1) (t : set \u03b2) : (\u03bb x, a \u2022 x) \u207b\u00b9' t = a\u207b\u00b9 \u2022 t :=\n((mul_action.to_perm a).symm.image_eq_preimage _).symm\n\n@[to_additive]\nlemma preimage_smul_inv (a : \u03b1) (t : set \u03b2) : (\u03bb x, a\u207b\u00b9 \u2022 x) \u207b\u00b9' t = a \u2022 t :=\npreimage_smul (to_units a)\u207b\u00b9 t\n\n@[simp, to_additive]\nlemma set_smul_subset_set_smul_iff : a \u2022 A \u2286 a \u2022 B \u2194 A \u2286 B :=\nimage_subset_image_iff $ mul_action.injective _\n\n@[to_additive]\nlemma set_smul_subset_iff : a \u2022 A \u2286 B \u2194 A \u2286 a\u207b\u00b9 \u2022 B :=\n(image_subset_iff).trans $ iff_of_eq $ congr_arg _ $\n  preimage_equiv_eq_image_symm _ $ mul_action.to_perm _\n\n@[to_additive]\nlemma subset_set_smul_iff : A \u2286 a \u2022 B \u2194 a\u207b\u00b9 \u2022 A \u2286 B :=\niff.symm $ (image_subset_iff).trans $ iff.symm $ iff_of_eq $ congr_arg _ $\n  image_equiv_eq_preimage_symm _ $ mul_action.to_perm _\n\nend group\n\nsection group_with_zero\nvariables [group_with_zero \u03b1] [mul_action \u03b1 \u03b2] {s : set \u03b1} {a : \u03b1}\n\n@[simp] lemma smul_mem_smul_set_iff\u2080 (ha : a \u2260 0) (A : set \u03b2)\n  (x : \u03b2) : a \u2022 x \u2208 a \u2022 A \u2194 x \u2208 A :=\nshow units.mk0 a ha \u2022 _ \u2208 _ \u2194 _, from smul_mem_smul_set_iff\n\nlemma mem_smul_set_iff_inv_smul_mem\u2080 (ha : a \u2260 0) (A : set \u03b2) (x : \u03b2) :\n  x \u2208 a \u2022 A \u2194 a\u207b\u00b9 \u2022 x \u2208 A :=\nshow _ \u2208 units.mk0 a ha \u2022 _ \u2194 _, from mem_smul_set_iff_inv_smul_mem\n\nlemma mem_inv_smul_set_iff\u2080 (ha : a \u2260 0) (A : set \u03b2) (x : \u03b2) : x \u2208 a\u207b\u00b9 \u2022 A \u2194 a \u2022 x \u2208 A :=\nshow _ \u2208 (units.mk0 a ha)\u207b\u00b9 \u2022 _ \u2194 _, from mem_inv_smul_set_iff\n\nlemma preimage_smul\u2080 (ha : a \u2260 0) (t : set \u03b2) : (\u03bb x, a \u2022 x) \u207b\u00b9' t = a\u207b\u00b9 \u2022 t :=\npreimage_smul (units.mk0 a ha) t\n\nlemma preimage_smul_inv\u2080 (ha : a \u2260 0) (t : set \u03b2) :\n  (\u03bb x, a\u207b\u00b9 \u2022 x) \u207b\u00b9' t = a \u2022 t :=\npreimage_smul ((units.mk0 a ha)\u207b\u00b9) t\n\n@[simp] lemma set_smul_subset_set_smul_iff\u2080 (ha : a \u2260 0) {A B : set \u03b2} :\n  a \u2022 A \u2286 a \u2022 B \u2194 A \u2286 B :=\nshow units.mk0 a ha \u2022 _ \u2286 _ \u2194 _, from set_smul_subset_set_smul_iff\n\nlemma set_smul_subset_iff\u2080 (ha : a \u2260 0) {A B : set \u03b2} : a \u2022 A \u2286 B \u2194 A \u2286 a\u207b\u00b9 \u2022 B :=\nshow units.mk0 a ha \u2022 _ \u2286 _ \u2194 _, from set_smul_subset_iff\n\nlemma subset_set_smul_iff\u2080 (ha : a \u2260 0) {A B : set \u03b2} : A \u2286 a \u2022 B \u2194 a\u207b\u00b9 \u2022 A \u2286 B :=\nshow _ \u2286 units.mk0 a ha \u2022 _ \u2194 _, from subset_set_smul_iff\n\nlemma smul_univ\u2080 (hs : \u00ac s \u2286 0) : s \u2022 (univ : set \u03b2) = univ :=\nlet \u27e8a, ha, ha\u2080\u27e9 := not_subset.1 hs in eq_univ_of_forall $ \u03bb b,\n  \u27e8a, a\u207b\u00b9 \u2022 b, ha, trivial, smul_inv_smul\u2080 ha\u2080 _\u27e9\n\nlemma smul_set_univ\u2080 (ha : a \u2260 0) : a \u2022 (univ : set \u03b2) = univ :=\neq_univ_of_forall $ \u03bb b, \u27e8a\u207b\u00b9 \u2022 b, trivial, smul_inv_smul\u2080 ha _\u27e9\n\nend group_with_zero\n\nend\n\nnamespace finset\nvariables {a : \u03b1} {s s\u2081 s\u2082 t t\u2081 t\u2082 : finset \u03b1}\n\n/-- The finset `(1 : finset \u03b1)` is defined as `{1}` in locale `pointwise`. -/\n@[to_additive /-\"The finset `(0 : finset \u03b1)` is defined as `{0}` in locale `pointwise`. \"-/]\nprotected def has_one [has_one \u03b1] : has_one (finset \u03b1) := \u27e8{1}\u27e9\n\nlocalized \"attribute [instance] finset.has_one finset.has_zero\" in pointwise\n\n@[simp, to_additive]\nlemma mem_one [has_one \u03b1] : a \u2208 (1 : finset \u03b1) \u2194 a = 1 :=\nby simp [has_one.one]\n\n@[simp, to_additive]\ntheorem one_subset [has_one \u03b1] : (1 : finset \u03b1) \u2286 s \u2194 (1 : \u03b1) \u2208 s := singleton_subset_iff\n\nsection decidable_eq\nvariables [decidable_eq \u03b1]\n\n/-- The pointwise product of two finite sets `s` and `t`:\n`st = s \u2b1d t = s * t = { x * y | x \u2208 s, y \u2208 t }`. -/\n@[to_additive /-\"The pointwise sum of two finite sets `s` and `t`:\n`s + t = { x + y | x \u2208 s, y \u2208 t }`. \"-/]\nprotected def has_mul [has_mul \u03b1] : has_mul (finset \u03b1) :=\n\u27e8\u03bb s t, (s.product t).image (\u03bb p : \u03b1 \u00d7 \u03b1, p.1 * p.2)\u27e9\n\nlocalized \"attribute [instance] finset.has_mul finset.has_add\" in pointwise\n\nsection has_mul\nvariables [has_mul \u03b1]\n\n@[to_additive]\nlemma mul_def : s * t = (s.product t).image (\u03bb p : \u03b1 \u00d7 \u03b1, p.1 * p.2) := rfl\n\n@[to_additive]\nlemma mem_mul {x : \u03b1} : x \u2208 s * t \u2194 \u2203 y z, y \u2208 s \u2227 z \u2208 t \u2227 y * z = x :=\nby { simp only [finset.mul_def, and.assoc, mem_image, exists_prop, prod.exists, mem_product] }\n\n@[simp, norm_cast, to_additive]\nlemma coe_mul : (\u2191(s * t) : set \u03b1) = \u2191s * \u2191t :=\nby { ext, simp only [mem_mul, set.mem_mul, mem_coe] }\n\n@[to_additive]\nlemma mul_mem_mul {x y : \u03b1} (hx : x \u2208 s) (hy : y \u2208 t) : x * y \u2208 s * t :=\nby { simp only [finset.mem_mul], exact \u27e8x, y, hx, hy, rfl\u27e9 }\n\n@[to_additive]\nlemma mul_card_le : (s * t).card \u2264 s.card * t.card :=\nby { convert finset.card_image_le, rw [finset.card_product, mul_comm] }\n\n@[simp, to_additive] lemma empty_mul (s : finset \u03b1) : \u2205 * s = \u2205 :=\neq_empty_of_forall_not_mem (by simp [mem_mul])\n\n@[simp, to_additive] lemma mul_empty (s : finset \u03b1) : s * \u2205 = \u2205 :=\neq_empty_of_forall_not_mem (by simp [mem_mul])\n\n@[simp, to_additive]\nlemma mul_nonempty_iff (s t : finset \u03b1) : (s * t).nonempty \u2194 s.nonempty \u2227 t.nonempty :=\nby simp [finset.mul_def]\n\n@[to_additive, mono] lemma mul_subset_mul  (hs : s\u2081 \u2286 s\u2082) (ht : t\u2081 \u2286 t\u2082) : s\u2081 * t\u2081 \u2286 s\u2082 * t\u2082 :=\nimage_subset_image (product_subset_product hs ht)\n\nattribute [mono] add_subset_add\n\n@[simp, to_additive]\nlemma mul_singleton (a : \u03b1) : s * {a} = s.image (* a) :=\nby { rw [mul_def, product_singleton, map_eq_image, image_image], refl }\n\n@[simp, to_additive]\nlemma singleton_mul (a : \u03b1) : {a} * s = s.image ((*) a) :=\nby { rw [mul_def, singleton_product, map_eq_image, image_image], refl }\n\n@[simp, to_additive]\nlemma singleton_mul_singleton (a b : \u03b1) : ({a} : finset \u03b1) * {b} = {a * b} :=\nby rw [mul_def, singleton_product_singleton, image_singleton]\n\nend has_mul\n\nsection mul_zero_class\nvariables [mul_zero_class \u03b1]\n\nlemma mul_zero_subset (s : finset \u03b1) : s * 0 \u2286 0 := by simp [subset_iff, mem_mul]\n\nlemma zero_mul_subset (s : finset \u03b1) : 0 * s \u2286 0 := by simp [subset_iff, mem_mul]\n\nlemma nonempty.mul_zero (hs : s.nonempty) : s * 0 = 0 :=\ns.mul_zero_subset.antisymm $ by simpa [finset.mem_mul] using hs\n\nlemma nonempty.zero_mul (hs : s.nonempty) : 0 * s = 0 :=\ns.zero_mul_subset.antisymm $ by simpa [finset.mem_mul] using hs\n\nlemma singleton_zero_mul (s : finset \u03b1) :\n  {(0 : \u03b1)} * s \u2286 {0} :=\nby simp [subset_iff, mem_mul]\n\nend mul_zero_class\nend decidable_eq\n\nopen_locale pointwise\nvariables {u : finset \u03b1} {b : \u03b1} {x y : \u03b2}\n\n@[to_additive]\nlemma singleton_one [has_one \u03b1] : ({1} : finset \u03b1) = 1 := rfl\n\n@[to_additive]\nlemma one_mem_one [has_one \u03b1] : (1 : \u03b1) \u2208 (1 : finset \u03b1) := by simp [has_one.one]\n\n@[to_additive]\ntheorem one_nonempty [has_one \u03b1] : (1 : finset \u03b1).nonempty := \u27e81, one_mem_one\u27e9\n\n@[simp, to_additive]\ntheorem image_one [decidable_eq \u03b2] [has_one \u03b1] {f : \u03b1 \u2192 \u03b2} : image f 1 = {f 1} :=\nimage_singleton f 1\n\n@[to_additive add_image_prod]\nlemma image_mul_prod [decidable_eq \u03b1] [has_mul \u03b1] :\n  image (\u03bb x : \u03b1 \u00d7 \u03b1, x.fst * x.snd) (s.product t) = s * t := rfl\n\n@[simp, to_additive]\nlemma image_mul_left [decidable_eq \u03b1] [group \u03b1] :\n  image (\u03bb b, a * b) t = preimage t (\u03bb b, a\u207b\u00b9 * b) (assume x hx y hy, (mul_right_inj a\u207b\u00b9).mp) :=\ncoe_injective $ by simp\n\n@[simp, to_additive]\nlemma image_mul_right [decidable_eq \u03b1] [group \u03b1] :\n  image (* b) t = preimage t (* b\u207b\u00b9) (assume x hx y hy, (mul_left_inj b\u207b\u00b9).mp) :=\ncoe_injective $ by simp\n\n@[to_additive]\nlemma image_mul_left' [decidable_eq \u03b1] [group \u03b1] :\n  image (\u03bb b, a\u207b\u00b9 * b) t = preimage t (\u03bb b, a * b) (assume x hx y hy, (mul_right_inj a).mp) :=\nby simp\n\n@[to_additive]\nlemma image_mul_right' [decidable_eq \u03b1] [group \u03b1] :\n  image (* b\u207b\u00b9) t = preimage t (* b) (assume x hx y hy, (mul_left_inj b).mp) :=\nby simp\n\n@[simp, to_additive]\nlemma preimage_mul_left_singleton [group \u03b1] :\n  preimage {b} ((*) a) (assume x hx y hy, (mul_right_inj a).mp) = {a\u207b\u00b9 * b} :=\nby { classical, rw [\u2190 image_mul_left', image_singleton] }\n\n@[simp, to_additive]\nlemma preimage_mul_right_singleton [group \u03b1] :\n  preimage {b} (* a) (assume x hx y hy, (mul_left_inj a).mp) = {b * a\u207b\u00b9} :=\nby { classical, rw [\u2190 image_mul_right', image_singleton] }\n\n@[simp, to_additive]\nlemma preimage_mul_left_one [group \u03b1] :\n  preimage 1 (\u03bb b, a * b) (assume x hx y hy, (mul_right_inj a).mp) = {a\u207b\u00b9} :=\nby {classical, rw [\u2190 image_mul_left', image_one, mul_one] }\n\n@[simp, to_additive]\nlemma preimage_mul_right_one [group \u03b1] :\n  preimage 1 (* b) (assume x hx y hy, (mul_left_inj b).mp) = {b\u207b\u00b9} :=\nby {classical, rw [\u2190 image_mul_right', image_one, one_mul] }\n\n@[to_additive]\nlemma preimage_mul_left_one' [group \u03b1] :\n  preimage 1 (\u03bb b, a\u207b\u00b9 * b) (assume x hx y hy, (mul_right_inj _).mp) = {a} := by simp\n\n@[to_additive]\nlemma preimage_mul_right_one' [group \u03b1] :\n  preimage 1 (* b\u207b\u00b9) (assume x hx y hy, (mul_left_inj _).mp) = {b} := by simp\n\n@[to_additive]\nprotected lemma mul_comm [decidable_eq \u03b1] [comm_semigroup \u03b1] : s * t = t * s :=\nby exact_mod_cast @set.mul_comm _ (s : set \u03b1) t _\n\n/-- `finset \u03b1` is a `mul_one_class` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`finset \u03b1` is an `add_zero_class` under pointwise operations if `\u03b1` is.\"-/]\nprotected def mul_one_class [decidable_eq \u03b1] [mul_one_class \u03b1] : mul_one_class (finset \u03b1) :=\nfunction.injective.mul_one_class _ coe_injective (coe_singleton 1) (by simp)\n\n/-- `finset \u03b1` is a `semigroup` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`finset \u03b1` is an `add_semigroup` under pointwise operations if `\u03b1` is. \"-/]\nprotected def semigroup [decidable_eq \u03b1] [semigroup \u03b1] : semigroup (finset \u03b1) :=\nfunction.injective.semigroup _ coe_injective (by simp)\n\n/-- `finset \u03b1` is a `monoid` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`finset \u03b1` is an `add_monoid` under pointwise operations if `\u03b1` is. \"-/]\nprotected def monoid [decidable_eq \u03b1] [monoid \u03b1] : monoid (finset \u03b1) :=\nfunction.injective.monoid _ coe_injective (coe_singleton 1) (by simp)\n\n/-- `finset \u03b1` is a `comm_monoid` under pointwise operations if `\u03b1` is. -/\n@[to_additive /-\"`finset \u03b1` is an `add_comm_monoid` under pointwise operations if `\u03b1` is. \"-/]\nprotected def comm_monoid [decidable_eq \u03b1] [comm_monoid \u03b1] : comm_monoid (finset \u03b1) :=\nfunction.injective.comm_monoid _ coe_injective (coe_singleton 1) (by simp)\n\nlocalized \"attribute [instance] finset.mul_one_class finset.add_zero_class finset.semigroup\n  finset.add_semigroup finset.monoid finset.add_monoid finset.comm_monoid finset.add_comm_monoid\"\n  in pointwise\n\nopen_locale classical\n\n/-- A finite set `U` contained in the product of two sets `S * S'` is also contained in the product\nof two finite sets `T * T' \u2286 S * S'`. -/\n@[to_additive]\nlemma subset_mul {M : Type*} [monoid M] {S : set M} {S' : set M} {U : finset M} (f : \u2191U \u2286 S * S') :\n  \u2203 (T T' : finset M), \u2191T \u2286 S \u2227 \u2191T' \u2286 S' \u2227 U \u2286 T * T' :=\nbegin\n  apply finset.induction_on' U,\n  { use [\u2205, \u2205], simp only [finset.empty_subset, finset.coe_empty, set.empty_subset, and_self], },\n  rintros a s haU hs has \u27e8T, T', hS, hS', h\u27e9,\n  obtain \u27e8x, y, hx, hy, ha\u27e9 := set.mem_mul.1 (f haU),\n  use [insert x T, insert y T'],\n  simp only [finset.coe_insert],\n  repeat { rw [set.insert_subset], },\n  use [hx, hS, hy, hS'],\n  refine finset.insert_subset.mpr \u27e8_, _\u27e9,\n  { rw finset.mem_mul,\n    use [x,y],\n    simpa only [true_and, true_or, eq_self_iff_true, finset.mem_insert], },\n  { suffices g : (s : set M) \u2286 insert x T * insert y T', { norm_cast at g, assumption, },\n    transitivity \u2191(T * T'),\n    apply h,\n    rw finset.coe_mul,\n    apply set.mul_subset_mul (set.subset_insert x T) (set.subset_insert y T'), },\nend\n\nend finset\n\n/-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in\n  `group_theory.submonoid.basic`, but currently we cannot because that file is imported by this. -/\nnamespace submonoid\n\nvariables {M : Type*} [monoid M] {s t u : set M}\n\n@[to_additive]\nlemma mul_subset {S : submonoid M} (hs : s \u2286 S) (ht : t \u2286 S) : s * t \u2286 S :=\nby { rintro _ \u27e8p, q, hp, hq, rfl\u27e9, exact submonoid.mul_mem _ (hs hp) (ht hq) }\n\n@[to_additive]\nlemma mul_subset_closure (hs : s \u2286 u) (ht : t \u2286 u) : s * t \u2286 submonoid.closure u :=\nmul_subset (subset.trans hs submonoid.subset_closure) (subset.trans ht submonoid.subset_closure)\n\n@[to_additive]\nlemma coe_mul_self_eq (s : submonoid M) : (s : set M) * s = s :=\nbegin\n  ext x,\n  refine \u27e8_, \u03bb h, \u27e8x, 1, h, s.one_mem, mul_one x\u27e9\u27e9,\n  rintros \u27e8a, b, ha, hb, rfl\u27e9,\n  exact s.mul_mem ha hb\nend\n\n@[to_additive]\nlemma closure_mul_le (S T : set M) : closure (S * T) \u2264 closure S \u2294 closure T :=\nInf_le $ \u03bb x \u27e8s, t, hs, ht, hx\u27e9, hx \u25b8 (closure S \u2294 closure T).mul_mem\n    (set_like.le_def.mp le_sup_left $ subset_closure hs)\n    (set_like.le_def.mp le_sup_right $ subset_closure ht)\n\n@[to_additive]\nlemma sup_eq_closure (H K : submonoid M) : H \u2294 K = closure (H * K) :=\nle_antisymm\n  (sup_le\n    (\u03bb h hh, subset_closure \u27e8h, 1, hh, K.one_mem, mul_one h\u27e9)\n    (\u03bb k hk, subset_closure \u27e81, k, H.one_mem, hk, one_mul k\u27e9))\n  (by conv_rhs { rw [\u2190 closure_eq H, \u2190 closure_eq K] }; apply closure_mul_le)\n\nlemma pow_smul_mem_closure_smul {N : Type*} [comm_monoid N] [mul_action M N]\n  [is_scalar_tower M N N] (r : M) (s : set N) {x : N} (hx : x \u2208 closure s) :\n  \u2203 n : \u2115, r ^ n \u2022 x \u2208 closure (r \u2022 s) :=\nbegin\n  apply @closure_induction N _ s\n    (\u03bb (x : N), \u2203 n : \u2115, r ^ n \u2022 x \u2208 closure (r \u2022 s)) _ hx,\n  { intros x hx,\n    exact \u27e81, subset_closure \u27e8_, hx, by rw pow_one\u27e9\u27e9 },\n  { exact \u27e80, by simpa using one_mem _\u27e9 },\n  { rintros x y \u27e8nx, hx\u27e9 \u27e8ny, hy\u27e9,\n    use nx + ny,\n    convert mul_mem _ hx hy,\n    rw [pow_add, smul_mul_assoc, mul_smul, mul_comm, \u2190 smul_mul_assoc, mul_comm] }\nend\n\nend submonoid\n\nnamespace group\n\nlemma card_pow_eq_card_pow_card_univ_aux {f : \u2115 \u2192 \u2115} (h1 : monotone f)\n  {B : \u2115} (h2 : \u2200 n, f n \u2264 B) (h3 : \u2200 n, f n = f (n + 1) \u2192 f (n + 1) = f (n + 2)) :\n  \u2200 k, B \u2264 k \u2192 f k = f B :=\nbegin\n  have key : \u2203 n : \u2115, n \u2264 B \u2227 f n = f (n + 1),\n  { contrapose! h2,\n    suffices : \u2200 n : \u2115, n \u2264 B + 1 \u2192 n \u2264 f n,\n    { exact \u27e8B + 1, this (B + 1) (le_refl (B + 1))\u27e9 },\n    exact \u03bb n, nat.rec (\u03bb h, nat.zero_le (f 0)) (\u03bb n ih h, lt_of_le_of_lt (ih (n.le_succ.trans h))\n      (lt_of_le_of_ne (h1 n.le_succ) (h2 n (nat.succ_le_succ_iff.mp h)))) n },\n  { obtain \u27e8n, hn1, hn2\u27e9 := key,\n    replace key : \u2200 k : \u2115, f (n + k) = f (n + k + 1) \u2227 f (n + k) = f n :=\n    \u03bb k, nat.rec \u27e8hn2, rfl\u27e9 (\u03bb k ih, \u27e8h3 _ ih.1, ih.1.symm.trans ih.2\u27e9) k,\n    replace key : \u2200 k : \u2115, n \u2264 k \u2192 f k = f n :=\n    \u03bb k hk, (congr_arg f (add_tsub_cancel_of_le hk)).symm.trans (key (k - n)).2,\n    exact \u03bb k hk, (key k (hn1.trans hk)).trans (key B hn1).symm },\nend\n\nvariables {G : Type*} [group G] [fintype G] (S : set G)\n\n@[to_additive]\nlemma card_pow_eq_card_pow_card_univ [\u2200 (k : \u2115), decidable_pred (\u2208 (S ^ k))] :\n  \u2200 k, fintype.card G \u2264 k \u2192 fintype.card \u21a5(S ^ k) = fintype.card \u21a5(S ^ (fintype.card G)) :=\nbegin\n  have hG : 0 < fintype.card G := fintype.card_pos_iff.mpr \u27e81\u27e9,\n  by_cases hS : S = \u2205,\n  { refine \u03bb k hk, fintype.card_congr _,\n    rw [hS, empty_pow _ (ne_of_gt (lt_of_lt_of_le hG hk)), empty_pow _ (ne_of_gt hG)] },\n  obtain \u27e8a, ha\u27e9 := set.ne_empty_iff_nonempty.mp hS,\n  classical,\n  have key : \u2200 a (s t : set G), (\u2200 b : G, b \u2208 s \u2192 a * b \u2208 t) \u2192 fintype.card s \u2264 fintype.card t,\n  { refine \u03bb a s t h, fintype.card_le_of_injective (\u03bb \u27e8b, hb\u27e9, \u27e8a * b, h b hb\u27e9) _,\n    rintros \u27e8b, hb\u27e9 \u27e8c, hc\u27e9 hbc,\n    exact subtype.ext (mul_left_cancel (subtype.ext_iff.mp hbc)) },\n  have mono : monotone (\u03bb n, fintype.card \u21a5(S ^ n) : \u2115 \u2192 \u2115) :=\n  monotone_nat_of_le_succ (\u03bb n, key a _ _ (\u03bb b hb, set.mul_mem_mul ha hb)),\n  convert card_pow_eq_card_pow_card_univ_aux mono (\u03bb n, set_fintype_card_le_univ (S ^ n))\n    (\u03bb n h, le_antisymm (mono (n + 1).le_succ) (key a\u207b\u00b9 _ _ _)),\n  { simp only [finset.filter_congr_decidable, fintype.card_of_finset] },\n  replace h : {a} * S ^ n = S ^ (n + 1),\n  { refine set.eq_of_subset_of_card_le _ (le_trans (ge_of_eq h) _),\n    { exact mul_subset_mul (set.singleton_subset_iff.mpr ha) set.subset.rfl },\n    { convert key a (S ^ n) ({a} * S ^ n) (\u03bb b hb, set.mul_mem_mul (set.mem_singleton a) hb) } },\n  rw [pow_succ', \u2190h, mul_assoc, \u2190pow_succ', h],\n  rintros _ \u27e8b, c, hb, hc, rfl\u27e9,\n  rwa [set.mem_singleton_iff.mp hb, inv_mul_cancel_left],\nend\n\nend group\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7111764227312911}}
{"text": "import tactic\n\nvariables {\u03b1 : Type} {a a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1}\n\ndef pair (a b : \u03b1) : set (set \u03b1) := {{a}, {a, b}}\n\nlemma eq_of_eq_singleton (h : {b\u2081, b\u2082} = ({a} : set \u03b1)) : b\u2081 = b\u2082 := \nbegin\n  have h\u2081 := set.ext_iff.mp h b\u2081,\n  have h\u2082 := set.ext_iff.mp h b\u2082,\n  tidy\nend\n\nlemma fst_eq_fst_of_pair_eq_pair (h : pair a\u2081 b\u2081 = pair a\u2082 b\u2082) : a\u2081 = a\u2082 :=\nbegin\n  have : {a\u2082} \u2208 pair a\u2081 b\u2081, by simp [pair, h],\n  cases this,\n  { tidy },\n  { suffices : a\u2081 = b\u2081, by tidy,\n    simp [eq_of_eq_singleton (set.mem_singleton_iff.mp this).symm] }\nend\n\nlemma snd_eq_snd_of_pair_eq_pair (h : pair a\u2081 b\u2081 = pair a\u2082 b\u2082) : b\u2081 = b\u2082 :=\nbegin\n  obtain rfl := fst_eq_fst_of_pair_eq_pair h,\n  rename a\u2081 a,\n  unfold pair at h,\n  have : {a, b\u2082} \u2208 pair a b\u2081, by simp [pair, h],\n  cases this,\n  { obtain rfl := eq_of_eq_singleton this,\n    rw [set.pair_eq_singleton, set.pair_eq_singleton] at h,\n    have h := (@eq_of_eq_singleton (set \u03b1) _ _ _ h),\n    have h := eq_of_eq_singleton h.symm,\n    rw h },\n  { simp at this,\n    change (\u03bb x, x = a \u2228 x = b\u2082) = (\u03bb x, x = a \u2228 x = b\u2081) at this,\n    have h\u2081 := congr_fun this b\u2081, simp at h\u2081,\n    have h\u2082 := congr_fun this b\u2082, simp at h\u2082,\n    cases h\u2081; cases h\u2082; tidy }\nend\n\nexample : pair a\u2081 b\u2081 = pair a\u2082 b\u2082 \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082 :=\nbegin\n  split; intro h,\n  { simp [fst_eq_fst_of_pair_eq_pair h, snd_eq_snd_of_pair_eq_pair h] },\n  { simp [h] }\nend", "meta": {"author": "pedrominicz", "repo": "logic", "sha": "0945200787b9ab8ca8e8f91e2c8de7e7a75efe3a", "save_path": "github-repos/lean/pedrominicz-logic", "path": "github-repos/lean/pedrominicz-logic/logic-0945200787b9ab8ca8e8f91e2c8de7e7a75efe3a/src/beginning_mathematical_logic_a_study_guide/02_a_very_little_informal_set_theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7111764218997128}}
{"text": "namespace exc\n\ntheorem and_comm {P Q : Prop} : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  assume h : P \u2227 Q,\n  have hp : P, from h.left,\n  have hq : Q, from h.right,\n  show Q \u2227 P, from and.intro hq hp\nend\n\ntheorem and_comm_1 {P Q : Prop} : P \u2227 Q \u2192 Q \u2227 P :=\n  fun x : P \u2227 Q , and.intro x.right x.left\n\n\ntheorem or_comm (P Q : Prop) : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  assume h : P \u2228 Q,\n  cases h with hp hq,\n    right, exact hp,\n    left, exact hq\nend\n\ntheorem or_elim_0 (p q r : Prop) : (p \u2228 q) \u2192 (p \u2192 r) \u2192 (q \u2192 r) \u2192 r :=\nbegin\n  assume poq : p \u2228 q,\n  assume par : p \u2192 r,\n  assume qar : q \u2192 r,\n  cases poq with hp hq,\n    show r, from par(hp),\n    show r, from qar(hq)\nend\n\nvariable S : Type\nvariable P : S -> S -> Prop\n\nexample : (\u2203 x : S, \u2200 y : S, P x y) -> (\u2200 x : S, \u2203 y : S, P y x) :=\nbegin\n  intro h,\n  intro x,\n  cases h with x0,\n  existsi x0,\n  exact (h_h x),\nend\n\ntheorem contrapostition (R Q : Prop) : (R \u2192 Q) \u2192 \u00ac Q \u2192 \u00ac R :=\nbegin\n  assume h0,\n  assume h1,\n  assume h2,\n  exact h1(h0(h2))\nend\n\ntheorem id_S : S \u2192 S := fun (x : S), x\n\ntheorem transitivity (P Q R : Prop) : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 P \u2192 R :=\nbegin\n  assume pq,\n  assume qr,\n  assume p,\n  exact qr (pq p)\nend\n\n\ntheorem transitivity_0 (P Q R : Prop) : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 P \u2192 R :=\n  fun pq : P \u2192 Q,\n    fun qr : Q \u2192 R,\n      fun p : P,\n        qr (pq p)\n\n\n\nvariable R : Prop\nvariable r : R\nvariable Q : Prop\nvariable q : Q\nexample : R \u2228 Q := or.inl r\nexample : R \u2228 Q := or.inr q\n\nexample (P Q : Prop) : (P \u2227 Q) \u2192 (P \u2228 Q) :=\n  fun pq : P \u2227 Q,\n    or.inl pq.left\n\nexample (P Q : Prop) : (P \u2227 Q) \u2192 (P \u2228 Q) :=\n  fun pq : P \u2227 Q,\n    or.inr pq.right\n\nend exc", "meta": {"author": "BelegCuthalion", "repo": "lean-exc", "sha": "9143dc8b8aac62b9b2dcee85b619fe5c2e2a7144", "save_path": "github-repos/lean/BelegCuthalion-lean-exc", "path": "github-repos/lean/BelegCuthalion-lean-exc/lean-exc-9143dc8b8aac62b9b2dcee85b619fe5c2e2a7144/thm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7111764198912905}}
{"text": "/-\nCopyright (c) 2021 Jakob Scholbach. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jakob Scholbach\n-/\nimport algebra.algebra.basic\nimport algebra.char_p.exp_char\nimport field_theory.separable\n\n/-!\n\n# Separable degree\n\nThis file contains basics about the separable degree of a polynomial.\n\n## Main results\n\n- `is_separable_contraction`: is the condition that, for `g` a separable polynomial, we have that\n   `g(x^(q^m)) = f(x)` for some `m : \u2115`.\n- `has_separable_contraction`: the condition of having a separable contraction\n- `has_separable_contraction.degree`: the separable degree, defined as the degree of some\n  separable contraction\n- `irreducible.has_separable_contraction`: any irreducible polynomial can be contracted\n  to a separable polynomial\n- `has_separable_contraction.dvd_degree'`: the degree of a separable contraction divides the degree,\n  in function of the exponential characteristic of the field\n- `has_separable_contraction.dvd_degree` and `has_separable_contraction.eq_degree` specialize the\n  statement of `separable_degree_dvd_degree`\n- `is_separable_contraction.degree_eq`: the separable degree is well-defined, implemented as the\n  statement that the degree of any separable contraction equals `has_separable_contraction.degree`\n\n## Tags\n\nseparable degree, degree, polynomial\n-/\n\nnamespace polynomial\n\nnoncomputable theory\nopen_locale classical polynomial\n\nsection comm_semiring\n\nvariables {F : Type*} [comm_semiring F] (q : \u2115)\n\n/-- A separable contraction of a polynomial `f` is a separable polynomial `g` such that\n`g(x^(q^m)) = f(x)` for some `m : \u2115`.-/\ndef is_separable_contraction (f : F[X]) (g : F[X]) : Prop :=\ng.separable \u2227 \u2203 m : \u2115, expand F (q^m) g = f\n\n/-- The condition of having a separable contration. -/\ndef has_separable_contraction (f : F[X]) : Prop :=\n\u2203 g : F[X], is_separable_contraction q f g\n\nvariables {q} {f : F[X]} (hf : has_separable_contraction q f)\n\n/-- A choice of a separable contraction. -/\ndef has_separable_contraction.contraction : F[X] := classical.some hf\n\n/-- The separable degree of a polynomial is the degree of a given separable contraction. -/\ndef has_separable_contraction.degree : \u2115 := hf.contraction.nat_degree\n\n/-- The separable degree divides the degree, in function of the exponential characteristic of F. -/\nlemma is_separable_contraction.dvd_degree' {g} (hf : is_separable_contraction q f g) :\n  \u2203 m : \u2115, g.nat_degree * (q ^ m) = f.nat_degree :=\nbegin\n  obtain \u27e8m, rfl\u27e9 := hf.2,\n  use m,\n  rw nat_degree_expand,\nend\n\nlemma has_separable_contraction.dvd_degree' : \u2203 m : \u2115, hf.degree * (q ^ m) = f.nat_degree :=\n(classical.some_spec hf).dvd_degree'\n\n/-- The separable degree divides the degree. -/\nlemma has_separable_contraction.dvd_degree :\n  hf.degree \u2223 f.nat_degree :=\nlet \u27e8a, ha\u27e9 := hf.dvd_degree' in dvd.intro (q ^ a) ha\n\n/-- In exponential characteristic one, the separable degree equals the degree. -/\nlemma has_separable_contraction.eq_degree {f : F[X]}\n  (hf : has_separable_contraction 1 f) : hf.degree = f.nat_degree :=\nlet \u27e8a, ha\u27e9 := hf.dvd_degree' in by rw [\u2190ha, one_pow a, mul_one]\n\nend comm_semiring\n\nsection field\n\nvariables {F : Type*} [field F]\nvariables (q : \u2115) {f : F[X]} (hf : has_separable_contraction q f)\n\n/-- Every irreducible polynomial can be contracted to a separable polynomial.\nhttps://stacks.math.columbia.edu/tag/09H0 -/\nlemma _root_.irreducible.has_separable_contraction (q : \u2115) [hF : exp_char F q]\n  (f : F[X]) (irred : irreducible f) : has_separable_contraction q f :=\nbegin\n  casesI hF,\n  { exact \u27e8f, irred.separable, \u27e80, by rw [pow_zero, expand_one]\u27e9\u27e9 },\n  { rcases exists_separable_of_irreducible q irred \u2039q.prime\u203a.ne_zero with \u27e8n, g, hgs, hge\u27e9,\n    exact \u27e8g, hgs, n, hge\u27e9, }\nend\n\n/-- If two expansions (along the positive characteristic) of two separable polynomials `g` and `g'`\nagree, then they have the same degree. -/\ntheorem contraction_degree_eq_or_insep\n  [hq : ne_zero q] [char_p F q]\n  (g g' : F[X]) (m m' : \u2115)\n  (h_expand : expand F (q^m) g = expand F (q^m') g')\n  (hg : g.separable) (hg' : g'.separable) :\n  g.nat_degree = g'.nat_degree :=\nbegin\n  wlog hm : m \u2264 m',\n  { exact (this g' g m' m h_expand.symm hg' hg (le_of_not_le hm)).symm },\n  obtain \u27e8s, rfl\u27e9 := exists_add_of_le hm,\n  rw [pow_add, expand_mul, expand_inj (pow_pos (ne_zero.pos q) m)] at h_expand,\n  subst h_expand,\n  rcases is_unit_or_eq_zero_of_separable_expand q s (ne_zero.pos q) hg with h | rfl,\n  { rw [nat_degree_expand, nat_degree_eq_zero_of_is_unit h, zero_mul] },\n  { rw [nat_degree_expand, pow_zero, mul_one] },\nend\n\n/-- The separable degree equals the degree of any separable contraction, i.e., it is unique. -/\ntheorem is_separable_contraction.degree_eq [hF : exp_char F q]\n  (g : F[X]) (hg : is_separable_contraction q f g) :\n  g.nat_degree = hf.degree :=\nbegin\n  casesI hF,\n  { rcases hg with \u27e8g, m, hm\u27e9,\n    rw [one_pow, expand_one] at hm,\n    rw hf.eq_degree,\n    rw hm, },\n  { rcases hg with \u27e8hg, m, hm\u27e9,\n    let g' := classical.some hf,\n    cases (classical.some_spec hf).2 with m' hm',\n    haveI : fact q.prime := fact_iff.2 hF_hprime,\n    apply contraction_degree_eq_or_insep q g g' m m',\n    rw [hm, hm'],\n    exact hg, exact (classical.some_spec hf).1 }\nend\n\nend field\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/field_theory/separable_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7111659299551591}}
{"text": "import standard\n--import data.nat\n\nstructure Category :=\n  (Obj : Type)\n  (Hom : Obj \u2192 Obj \u2192 Type)\n  \n  (identity : \u03a0 A : Obj, Hom A A)\n  (compose : \u03a0 \u2983A B C : Obj\u2984, Hom A B \u2192 Hom B C \u2192 Hom A C)\n\n  (left_identity  : \u03a0 \u2983A B : Obj\u2984 (f : Hom A B), compose (identity _) f = f)\n  (right_identity : \u03a0 \u2983A B : Obj\u2984 (f : Hom A B), compose f (identity _) = f)\n  (associativity  : \u03a0 \u2983A B C D : Obj\u2984 (f : Hom A B) (g : Hom B C) (h : Hom C D),\n    compose (compose f g) h = compose f (compose g h))\n\nnamespace Category\n  -- Can we put this before the definition?\n  notation f \u2218 g := compose _ _ _ _ f g\n  -- infixr `\u2218` := compose _ _ _ _\n  infixl `\u27f6` :25 := Hom _\n\n  --def Mor := Hom\nend Category\n\n/-\ninstance \u2115Category : Category :=\n  { Category .\n    Obj      := unit,\n    Hom      := \u03bb a b, \u2115,\n    identity := \u03bb a, 0,\n    compose  := \u03bb a b c, add,\n\n    left_identity  := \u03bb a b, zero_add,\n    right_identity := \u03bb a b, add_zero,\n    associativity  := \u03bb a b c d, add_assoc }\n\n-- This is how Coq's program directive does it under the\n-- hood. Everything after the refine line should be able to be\n-- replaced by a single tactic (like crush).\ninstance \u2115Category' : Category :=\nbegin\n  refine (Category.mk unit (\u03bb a b, \u2115) (\u03bb a, 0) (\u03bb a b c, add) _ _ _),\n  intros A B,\n  exact zero_add,\n  intros A B,\n  exact add_zero,\n  intros A B C D,\n  exact add_assoc\nend\n-/\n\nopen Category \n\nprint Category\n\n-- This needs to use typeclasses; still trying to figure that out\n\nclass Functor (source target : Category) :=\n  (onObjects     : Obj source \u2192 Obj target)\n  (onMorphisms   : \u03a0 \u2983a b : Obj source\u2984, Hom _ a b \u2192 Hom _ (onObjects a) (onObjects b))\n--  \n--  (identities    : \u03a0 (a : Obj source), onMorphisms (Id _ a) = Id _ (onObjects a))\n--  (functoriality : \u03a0 \u2983a b c : Obj source\u2984 (f : Hom _ a b) (g : Hom _ b c),\n--                    onMorphisms (f \u2218 g) = onMorphisms f \u2218 onMorphisms g)\n\n--namespace Functor\n--  infix `<$>`:50 := \u03bb {C D : Category} (F : Functor C D) (a : Obj C), onObjects F a\n--  infix `<$>m`:50 := \u03bb {C D : Category} (F : Functor C D) {a b : Obj C}\n--                        (f : Hom _ a b), onMorphisms F f\n--end Functor\n--\n--open function\n\n-- This clearly shouldn't be here. In Lean 2, this could be done by blast\ntheorem double_order (n m p q : \u2115) : n + m + (p + q) = n + p + (m + q) :=\ncalc\n  n + m + (p + q) = n + (m + (p + q)) : add_assoc n m (p + q)\n              ... = n + (m + p + q)   : eq.symm (congr_arg (add n) (add_assoc m p q))\n              ... = n + (p + m + q)   : congr_arg (add n) (congr_arg (\u03bb n, n + q) (add_comm m p))\n              ... = n + (p + (m + q)) : congr_arg (add n) (add_assoc p m q)\n              ... = n + p + (m + q)   : eq.symm (add_assoc n p (m + q))\n\n--@[reducible]\n--def DoublingAsFunctor : Functor \u2115Category \u2115Category :=\n--  { Functor .\n--    onObj := id,\n--    onMor := \u03bb a b (n : \u2115), n + n,\n--\n--    respect_Id   := \u03bb a, rfl,\n--    respect_comp := begin\n--                    intros,\n--                    exact double_order f g f g\n--                    end }\n\n\n-- This was a part of the standard library in Lean 2. Let's put it in\n-- until they add it again.\ntheorem pair_eq {A B : Type} {a\u2081 a\u2082 : A} {b\u2081 b\u2082 : B} :\n    a\u2081 = a\u2082 \u2192 b\u2081 = b\u2082 \u2192 (a\u2081, b\u2081) = (a\u2082, b\u2082) :=\nassume H1 H2, H1 \u25b8 H2 \u25b8 rfl\n\nopen prod\n\n-- Needs to use typeclasses again.\n\n--instance ProductCategory (C D : Category) [Category] [Category] : Category :=\n--  { Category .\n--    Obj := Obj C \u00d7 Obj D,\n--    Hom := \u03bb a b, Hom C (fst a) (fst b) \u00d7 Hom D (snd a) (snd b),\n--\n--    identity := \u03bb a, (identity C (fst a), identity D (snd a)),\n--    compose  := \u03bb a b c f g, (fst f \u2218 fst g, snd f \u2218 snd g),\n--\n--    left_identities  := \u03bb a b c d, pair_eq (left_identity  C _) (left_identity  D _) ,\n--    right_identities := \u03bb a b c d, pair_eq (right_identity C _) (right_identity D _),\n--    associativity := begin\n--                     intros,\n--                     exact pair_eq (assoc C _ _ _ _ _) (assoc D _ _ _ _ _)\n--                     end }\n--\n--namespace ProductCategory\n--  notation C `\u00d7c` D := ProductCategory C D\n--end ProductCategory\n--\n--open Functor\n--open ProductCategory\n--\n--structure LaxMonoidalCategory :=\n--  (carrier : Category)\n--  (tensor : Functor (carrier \u00d7c carrier) carrier)\n--  (unit : let obj := Obj carrier in obj)\n--\n--  (associator : \u03a0 (a b c : Obj carrier),\n--                  Hom _ (tensor <$> (tensor <$> (a,b), c))\n--                       (tensor <$> (a, tensor <$> (b,c))))\n--  --(pentagon : \u03a0 (a b c d : Obj carrier),\n--  --              associator (tensor <$> (a,b)) c d \u2218c associator a b (tensor <$> (c,d)) = \n--\n----attribute [coercion] LaxMonoidalCategory.carrier\n----\n--namespace LaxMonoidalCategory\n--  infix `\u2297`:70 := \u03bb {C : LaxMonoidalCategory} (a b : Obj C), tensor C <$> (a,b)\n--  infix `\u2297m`:70 := \u03bb {C : LaxMonoidalCategory} {a b c d : Obj C}\n--                      (f : Hom a b) (g : Hom c d), tensor C <$> (f,g)\n--end LaxMonoidalCategory\n\n--@[reducible]\n--def \u2115TensorProduct : Functor (\u2115Category \u00d7c \u2115Category) \u2115Category :=\n--  { Functor .\n--    onObj := fst,\n--    onMor := \u03bb a b n, fst n + snd n,\n--\n--    respect_Id   := \u03bb a, rfl,\n--    respect_comp := begin\n--                    intros,\n--                    refine (double_order f g f g)\n--                    end }\n\n--def \u2115TensorProduct' : Functor (\u2115Category \u00d7c \u2115Category) \u2115Category :=\n--  Functor.mk pr1 (\u03bb a b (f : \u2115 \u00d7 \u2115), pr1 f + pr2 f) _ _ _\n--begin\n--  refine Functor.mk (pr1) (\u03bb (a b : unit), \u03bb (f : \u2115 \u00d7 \u2115), pr1 f + pr2 f) _ _,\n--end\n--\n--def \u2115LaxMonoidalCategory : LaxMonoidalCategory :=\n--  \u2983 LaxMonoidalCategory,\n--    carrier    := \u2115Category,\n--    tensor     := \u2115TensorProduct,\n--    unit       := unit.star,\n--\n--    associator := \u03bb a b c, Id _ _ \u2984\n--\n--open LaxMonoidalCategory\n\n--check (2 : Hom \u2115LaxMonoidalCategory unit.star unit.star)\n", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/category-theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7111659164275577}}
{"text": "/-\nCopyright (c) 2021 Jakob Scholbach. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jakob Scholbach\n-/\nimport algebra.algebra.basic\nimport algebra.char_p.exp_char\nimport field_theory.separable\n\n/-!\n\n# Separable degree\n\nThis file contains basics about the separable degree of a polynomial.\n\n## Main results\n\n- `is_separable_contraction`: is the condition that `g(x^(q^m)) = f(x)` for some `m : \u2115`\n- `has_separable_contraction`: the condition of having a separable contraction\n- `has_separable_contraction.degree`: the separable degree, defined as the degree of some\n  separable contraction\n- `irreducible_has_separable_contraction`: any irreducible polynomial can be contracted\n  to a separable polynomial\n- `has_separable_contraction.dvd_degree'`: the degree of a separable contraction divides the degree,\n  in function of the exponential characteristic of the field\n- `has_separable_contraction.dvd_degree` and `has_separable_contraction.eq_degree` specialize the\n  statement of `separable_degree_dvd_degree`\n- `is_separable_contraction.degree_eq`: the separable degree is well-defined, implemented as the\n  statement that the degree of any separable contraction equals `has_separable_contraction.degree`\n\n## Tags\n\nseparable degree, degree, polynomial\n-/\n\nnamespace polynomial\n\nnoncomputable theory\nopen_locale classical polynomial\n\nsection comm_semiring\n\nvariables {F : Type} [comm_semiring F] (q : \u2115)\n\n/-- A separable contraction of a polynomial `f` is a separable polynomial `g` such that\n`g(x^(q^m)) = f(x)` for some `m : \u2115`.-/\ndef is_separable_contraction (f : F[X]) (g : F[X]) : Prop :=\ng.separable \u2227 \u2203 m : \u2115, expand F (q^m) g = f\n\n/-- The condition of having a separable contration. -/\ndef has_separable_contraction (f : F[X]) : Prop :=\n\u2203 g : F[X], is_separable_contraction q f g\n\nvariables {q} {f : F[X]} (hf : has_separable_contraction q f)\n\n/-- A choice of a separable contraction. -/\ndef has_separable_contraction.contraction : F[X] := classical.some hf\n\n/-- The separable degree of a polynomial is the degree of a given separable contraction. -/\ndef has_separable_contraction.degree : \u2115 := hf.contraction.nat_degree\n\n/-- The separable degree divides the degree, in function of the exponential characteristic of F. -/\nlemma is_separable_contraction.dvd_degree' {g} (hf : is_separable_contraction q f g) :\n  \u2203 m : \u2115, g.nat_degree * (q ^ m) = f.nat_degree :=\nbegin\n  obtain \u27e8m, rfl\u27e9 := hf.2,\n  use m,\n  rw nat_degree_expand,\nend\n\nlemma has_separable_contraction.dvd_degree' : \u2203 m : \u2115, hf.degree * (q ^ m) = f.nat_degree :=\n(classical.some_spec hf).dvd_degree'\n\n/-- The separable degree divides the degree. -/\nlemma has_separable_contraction.dvd_degree :\n  hf.degree \u2223 f.nat_degree :=\nlet \u27e8a, ha\u27e9 := hf.dvd_degree' in dvd.intro (q ^ a) ha\n\n/-- In exponential characteristic one, the separable degree equals the degree. -/\nlemma has_separable_contraction.eq_degree {f : F[X]}\n  (hf : has_separable_contraction 1 f) : hf.degree = f.nat_degree :=\nlet \u27e8a, ha\u27e9 := hf.dvd_degree' in by rw [\u2190ha, one_pow a, mul_one]\n\nend comm_semiring\n\nsection field\n\nvariables {F : Type} [field F]\nvariables (q : \u2115) {f : F[X]} (hf : has_separable_contraction q f)\n\n/-- Every irreducible polynomial can be contracted to a separable polynomial.\nhttps://stacks.math.columbia.edu/tag/09H0 -/\nlemma irreducible_has_separable_contraction (q : \u2115) [hF : exp_char F q]\n  (f : F[X]) [irred : irreducible f] : has_separable_contraction q f :=\nbegin\n  casesI hF,\n  { exact \u27e8f, irred.separable, \u27e80, by rw [pow_zero, expand_one]\u27e9\u27e9 },\n  { rcases exists_separable_of_irreducible q irred \u2039q.prime\u203a.ne_zero with \u27e8n, g, hgs, hge\u27e9,\n    exact \u27e8g, hgs, n, hge\u27e9, }\nend\n\n/-- A helper lemma: if two expansions (along the positive characteristic) of two polynomials `g` and\n`g'` agree, and the one with the larger degree is separable, then their degrees are the same. -/\nlemma contraction_degree_eq_aux [hq : fact q.prime] [hF : char_p F q]\n  (g g' : F[X]) (m m' : \u2115)\n  (h_expand : expand F (q^m) g = expand F (q^m') g')\n  (h : m < m') (hg : g.separable):\n  g.nat_degree =  g'.nat_degree :=\nbegin\n  obtain \u27e8s, rfl\u27e9 := nat.exists_eq_add_of_lt h,\n  rw [add_assoc, pow_add, expand_mul] at h_expand,\n  let aux := expand_injective (pow_pos hq.1.pos m) h_expand,\n  rw aux at hg,\n  have := (is_unit_or_eq_zero_of_separable_expand q (s + 1) hq.out.pos hg).resolve_right\n    s.succ_ne_zero,\n  rw [aux, nat_degree_expand,\n    nat_degree_eq_of_degree_eq_some (degree_eq_zero_of_is_unit this),\n    zero_mul]\nend\n\n/-- If two expansions (along the positive characteristic) of two separable polynomials\n`g` and `g'` agree, then they have the same degree. -/\ntheorem contraction_degree_eq_or_insep\n  [hq : fact q.prime] [char_p F q]\n  (g g' : F[X]) (m m' : \u2115)\n  (h_expand : expand F (q^m) g = expand F (q^m') g')\n  (hg : g.separable) (hg' : g'.separable) :\n  g.nat_degree = g'.nat_degree :=\nbegin\n  by_cases h : m = m',\n  { -- if `m = m'` then we show `g.nat_degree = g'.nat_degree` by unfolding the definitions\n    rw h at h_expand,\n    have expand_deg : ((expand F (q ^ m')) g).nat_degree =\n      (expand F (q ^ m') g').nat_degree, by rw h_expand,\n    rw [nat_degree_expand (q^m') g, nat_degree_expand (q^m') g'] at expand_deg,\n    apply nat.eq_of_mul_eq_mul_left (pow_pos hq.1.pos m'),\n    rw [mul_comm] at expand_deg, rw expand_deg, rw [mul_comm] },\n  { cases ne.lt_or_lt h,\n    { exact contraction_degree_eq_aux q g g' m m' h_expand h_1 hg },\n    { exact (contraction_degree_eq_aux q g' g m' m h_expand.symm h_1 hg').symm, } }\nend\n\n/-- The separable degree equals the degree of any separable contraction, i.e., it is unique. -/\ntheorem is_separable_contraction.degree_eq [hF : exp_char F q]\n  (g : F[X]) (hg : is_separable_contraction q f g) :\n  g.nat_degree = hf.degree :=\nbegin\n  casesI hF,\n  { rcases hg with \u27e8g, m, hm\u27e9,\n    rw [one_pow, expand_one] at hm,\n    rw hf.eq_degree,\n    rw hm, },\n  { rcases hg with \u27e8hg, m, hm\u27e9,\n    let g' := classical.some hf,\n    cases (classical.some_spec hf).2 with m' hm',\n    haveI : fact q.prime := fact_iff.2 hF_hprime,\n    apply contraction_degree_eq_or_insep q g g' m m',\n    rw [hm, hm'],\n    exact hg, exact (classical.some_spec hf).1 }\nend\n\nend field\n\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/field_theory/separable_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7111659058899655}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport ring_theory.matrix_algebra\nimport data.polynomial.algebra_map\nimport data.matrix.basis\nimport data.matrix.dmatrix\n\n/-!\n# Algebra isomorphism between matrices of polynomials and polynomials of matrices\n\nGiven `[comm_ring R] [ring A] [algebra R A]`\nwe show `polynomial A \u2243\u2090[R] (A \u2297[R] polynomial R)`.\nCombining this with the isomorphism `matrix n n A \u2243\u2090[R] (A \u2297[R] matrix n n R)` proved earlier\nin `ring_theory.matrix_algebra`, we obtain the algebra isomorphism\n```\ndef mat_poly_equiv :\n  matrix n n (polynomial R) \u2243\u2090[R] polynomial (matrix n n R)\n```\nwhich is characterized by\n```\ncoeff (mat_poly_equiv m) k i j = coeff (m i j) k\n```\n\nWe will use this algebra isomorphism to prove the Cayley-Hamilton theorem.\n-/\n\nuniverses u v w\n\nopen_locale tensor_product\n\nopen polynomial\nopen tensor_product\nopen algebra.tensor_product (alg_hom_of_linear_map_tensor_product include_left)\n\nnoncomputable theory\n\nvariables (R A : Type*)\nvariables [comm_semiring R]\nvariables [semiring A] [algebra R A]\n\nnamespace poly_equiv_tensor\n\n/--\n(Implementation detail).\nThe function underlying `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`,\nas a bilinear function of two arguments.\n-/\n@[simps apply_apply]\ndef to_fun_bilinear : A \u2192\u2097[A] polynomial R \u2192\u2097[R] polynomial A :=\nlinear_map.to_span_singleton A _ (aeval (polynomial.X : polynomial A)).to_linear_map\n\nlemma to_fun_bilinear_apply_eq_sum (a : A) (p : polynomial R) :\n  to_fun_bilinear R A a p = p.sum (\u03bb n r, monomial n (a * algebra_map R A r)) :=\nbegin\n  dsimp [to_fun_bilinear_apply_apply, aeval_def, eval\u2082_eq_sum, polynomial.sum],\n  rw finset.smul_sum,\n  congr' with i : 1,\n  rw [\u2190algebra.smul_def, \u2190C_mul', mul_smul_comm, C_mul_X_pow_eq_monomial, \u2190algebra.commutes,\n    \u2190algebra.smul_def, smul_monomial],\nend\n\n/--\n(Implementation detail).\nThe function underlying `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`,\nas a linear map.\n-/\ndef to_fun_linear : A \u2297[R] polynomial R \u2192\u2097[R] polynomial A :=\ntensor_product.lift (to_fun_bilinear R A)\n\n@[simp]\nlemma to_fun_linear_tmul_apply (a : A) (p : polynomial R) :\n  to_fun_linear R A (a \u2297\u209c[R] p) = to_fun_bilinear R A a p := lift.tmul _ _\n\n-- We apparently need to provide the decidable instance here\n-- in order to successfully rewrite by this lemma.\nlemma to_fun_linear_mul_tmul_mul_aux_1\n  (p : polynomial R) (k : \u2115) (h : decidable (\u00acp.coeff k = 0)) (a : A) :\n  ite (\u00accoeff p k = 0) (a * (algebra_map R A) (coeff p k)) 0 = a * (algebra_map R A) (coeff p k) :=\nby { classical, split_ifs; simp *, }\n\nlemma to_fun_linear_mul_tmul_mul_aux_2 (k : \u2115) (a\u2081 a\u2082 : A) (p\u2081 p\u2082 : polynomial R) :\n  a\u2081 * a\u2082 * (algebra_map R A) ((p\u2081 * p\u2082).coeff k) =\n    (finset.nat.antidiagonal k).sum\n      (\u03bb x, a\u2081 * (algebra_map R A) (coeff p\u2081 x.1) * (a\u2082 * (algebra_map R A) (coeff p\u2082 x.2))) :=\nbegin\n  simp_rw [mul_assoc, algebra.commutes, \u2190finset.mul_sum, mul_assoc, \u2190finset.mul_sum],\n  congr,\n  simp_rw [algebra.commutes (coeff p\u2082 _), coeff_mul, ring_hom.map_sum, ring_hom.map_mul],\nend\n\nlemma to_fun_linear_mul_tmul_mul (a\u2081 a\u2082 : A) (p\u2081 p\u2082 : polynomial R) :\n  (to_fun_linear R A) ((a\u2081 * a\u2082) \u2297\u209c[R] (p\u2081 * p\u2082)) =\n    (to_fun_linear R A) (a\u2081 \u2297\u209c[R] p\u2081) * (to_fun_linear R A) (a\u2082 \u2297\u209c[R] p\u2082) :=\nbegin\n  simp only [to_fun_linear_tmul_apply, to_fun_bilinear_apply_eq_sum],\n  ext k,\n  simp_rw [coeff_sum, coeff_monomial, sum_def, finset.sum_ite_eq', mem_support_iff, ne.def],\n  conv_rhs { rw [coeff_mul] },\n  simp_rw [finset_sum_coeff, coeff_monomial,\n    finset.sum_ite_eq', mem_support_iff, ne.def,\n    mul_ite, mul_zero, ite_mul, zero_mul],\n  simp_rw [ite_mul_zero_left (\u00accoeff p\u2081 _ = 0) (a\u2081 * (algebra_map R A) (coeff p\u2081 _))],\n  simp_rw [ite_mul_zero_right (\u00accoeff p\u2082 _ = 0) _ (_ * _)],\n  simp_rw [to_fun_linear_mul_tmul_mul_aux_1, to_fun_linear_mul_tmul_mul_aux_2],\nend\n\nlemma to_fun_linear_algebra_map_tmul_one (r : R) :\n  (to_fun_linear R A) ((algebra_map R A) r \u2297\u209c[R] 1) = (algebra_map R (polynomial A)) r :=\nby rw [to_fun_linear_tmul_apply, to_fun_bilinear_apply_apply, polynomial.aeval_one,\n  algebra_map_smul, algebra.algebra_map_eq_smul_one]\n\n/--\n(Implementation detail).\nThe algebra homomorphism `A \u2297[R] polynomial R \u2192\u2090[R] polynomial A`.\n-/\ndef to_fun_alg_hom : A \u2297[R] polynomial R \u2192\u2090[R] polynomial A :=\nalg_hom_of_linear_map_tensor_product\n  (to_fun_linear R A)\n  (to_fun_linear_mul_tmul_mul R A)\n  (to_fun_linear_algebra_map_tmul_one R A)\n\n@[simp] lemma to_fun_alg_hom_apply_tmul (a : A) (p : polynomial R) :\n  to_fun_alg_hom R A (a \u2297\u209c[R] p) = p.sum (\u03bb n r, monomial n (a * (algebra_map R A) r)) :=\nbegin\n  dsimp [to_fun_alg_hom],\n  rw [to_fun_linear_tmul_apply, to_fun_bilinear_apply_eq_sum],\nend\n\n/--\n(Implementation detail.)\n\nThe bare function `polynomial A \u2192 A \u2297[R] polynomial R`.\n(We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.)\n-/\ndef inv_fun (p : polynomial A) : A \u2297[R] polynomial R :=\np.eval\u2082\n  (include_left : A \u2192\u2090[R] A \u2297[R] polynomial R)\n  ((1 : A) \u2297\u209c[R] (X : polynomial R))\n\n@[simp]\nlemma inv_fun_add {p q} : inv_fun R A (p + q) = inv_fun R A p + inv_fun R A q :=\nby simp only [inv_fun, eval\u2082_add]\n\nlemma inv_fun_monomial (n : \u2115) (a : A) :\n  inv_fun R A (monomial n a) = include_left a * ((1 : A) \u2297\u209c[R] (X : polynomial R)) ^ n :=\neval\u2082_monomial _ _\n\nlemma left_inv (x : A \u2297 polynomial R) :\n  inv_fun R A ((to_fun_alg_hom R A) x) = x :=\nbegin\n  apply tensor_product.induction_on x,\n  { simp [inv_fun], },\n  { intros a p, dsimp only [inv_fun],\n    rw [to_fun_alg_hom_apply_tmul, eval\u2082_sum],\n    simp_rw [eval\u2082_monomial, alg_hom.coe_to_ring_hom, algebra.tensor_product.tmul_pow, one_pow,\n      algebra.tensor_product.include_left_apply, algebra.tensor_product.tmul_mul_tmul,\n      mul_one, one_mul, \u2190algebra.commutes, \u2190algebra.smul_def, smul_tmul, sum_def, \u2190tmul_sum],\n    conv_rhs { rw [\u2190sum_C_mul_X_eq p], },\n    simp only [algebra.smul_def],\n    refl, },\n  { intros p q hp hq,\n    simp only [alg_hom.map_add, inv_fun_add, hp, hq], },\nend\n\nlemma right_inv (x : polynomial A) :\n  (to_fun_alg_hom R A) (inv_fun R A x) = x :=\nbegin\n  apply polynomial.induction_on' x,\n  { intros p q hp hq, simp only [inv_fun_add, alg_hom.map_add, hp, hq], },\n  { intros n a,\n    rw [inv_fun_monomial, algebra.tensor_product.include_left_apply,\n      algebra.tensor_product.tmul_pow, one_pow, algebra.tensor_product.tmul_mul_tmul,\n      mul_one, one_mul, to_fun_alg_hom_apply_tmul, X_pow_eq_monomial, sum_monomial_index];\n    simp, }\nend\n\n/--\n(Implementation detail)\n\nThe equivalence, ignoring the algebra structure, `(A \u2297[R] polynomial R) \u2243 polynomial A`.\n-/\ndef equiv : (A \u2297[R] polynomial R) \u2243 polynomial A :=\n{ to_fun := to_fun_alg_hom R A,\n  inv_fun := inv_fun R A,\n  left_inv := left_inv R A,\n  right_inv := right_inv R A, }\n\nend poly_equiv_tensor\n\nopen poly_equiv_tensor\n\n/--\nThe `R`-algebra isomorphism `polynomial A \u2243\u2090[R] (A \u2297[R] polynomial R)`.\n-/\ndef poly_equiv_tensor : polynomial A \u2243\u2090[R] (A \u2297[R] polynomial R) :=\nalg_equiv.symm\n{ ..(poly_equiv_tensor.to_fun_alg_hom R A), ..(poly_equiv_tensor.equiv R A) }\n\n@[simp]\nlemma poly_equiv_tensor_apply (p : polynomial A) :\n  poly_equiv_tensor R A p =\n    p.eval\u2082 (include_left : A \u2192\u2090[R] A \u2297[R] polynomial R) ((1 : A) \u2297\u209c[R] (X : polynomial R)) :=\nrfl\n\n@[simp]\nlemma poly_equiv_tensor_symm_apply_tmul (a : A) (p : polynomial R) :\n  (poly_equiv_tensor R A).symm (a \u2297\u209c p) = p.sum (\u03bb n r, monomial n (a * algebra_map R A r)) :=\nto_fun_alg_hom_apply_tmul _ _ _ _\n\nopen dmatrix matrix\nopen_locale big_operators\n\nvariables {R}\nvariables {n : Type w} [decidable_eq n] [fintype n]\n\n/--\nThe algebra isomorphism stating \"matrices of polynomials are the same as polynomials of matrices\".\n\n(You probably shouldn't attempt to use this underlying definition ---\nit's an algebra equivalence, and characterised extensionally by the lemma\n`mat_poly_equiv_coeff_apply` below.)\n-/\nnoncomputable def mat_poly_equiv :\n  matrix n n (polynomial R) \u2243\u2090[R] polynomial (matrix n n R) :=\n(((matrix_equiv_tensor R (polynomial R) n)).trans\n  (algebra.tensor_product.comm R _ _)).trans\n  (poly_equiv_tensor R (matrix n n R)).symm\n\nopen finset\n\nlemma mat_poly_equiv_coeff_apply_aux_1 (i j : n) (k : \u2115) (x : R) :\n  mat_poly_equiv (std_basis_matrix i j $ monomial k x) =\n    monomial k (std_basis_matrix i j x) :=\nbegin\n  simp only [mat_poly_equiv, alg_equiv.trans_apply,\n    matrix_equiv_tensor_apply_std_basis],\n  apply (poly_equiv_tensor R (matrix n n R)).injective,\n  simp only [alg_equiv.apply_symm_apply],\n  convert algebra.tensor_product.comm_tmul _ _ _ _ _,\n  simp only [poly_equiv_tensor_apply],\n  convert eval\u2082_monomial _ _,\n  simp only [algebra.tensor_product.tmul_mul_tmul, one_pow, one_mul, matrix.mul_one,\n    algebra.tensor_product.tmul_pow, algebra.tensor_product.include_left_apply, mul_eq_mul],\n  rw [monomial_eq_smul_X, \u2190 tensor_product.smul_tmul],\n  congr' with i' j'; simp\nend\n\nlemma mat_poly_equiv_coeff_apply_aux_2\n  (i j : n) (p : polynomial R) (k : \u2115) :\n  coeff (mat_poly_equiv (std_basis_matrix i j p)) k =\n    std_basis_matrix i j (coeff p k) :=\nbegin\n  apply polynomial.induction_on' p,\n  { intros p q hp hq, ext,\n    simp [hp, hq, coeff_add, add_apply, std_basis_matrix_add], },\n  { intros k x,\n    simp only [mat_poly_equiv_coeff_apply_aux_1, coeff_monomial],\n    split_ifs; { funext, simp, }, }\nend\n\n@[simp] lemma mat_poly_equiv_coeff_apply\n  (m : matrix n n (polynomial R)) (k : \u2115) (i j : n) :\n  coeff (mat_poly_equiv m) k i j = coeff (m i j) k :=\nbegin\n  apply matrix.induction_on' m,\n  { simp, },\n  { intros p q hp hq, simp [hp, hq], },\n  { intros i' j' x,\n    erw mat_poly_equiv_coeff_apply_aux_2,\n    dsimp [std_basis_matrix],\n    split_ifs,\n    { rcases h with \u27e8rfl, rfl\u27e9, simp [std_basis_matrix], },\n    { simp [std_basis_matrix, h], }, },\nend\n\n@[simp] lemma mat_poly_equiv_symm_apply_coeff\n  (p : polynomial (matrix n n R)) (i j : n) (k : \u2115) :\n  coeff (mat_poly_equiv.symm p i j) k = coeff p k i j :=\nbegin\n  have t : p = mat_poly_equiv\n    (mat_poly_equiv.symm p) := by simp,\n  conv_rhs { rw t, },\n  simp only [mat_poly_equiv_coeff_apply],\nend\n\nlemma mat_poly_equiv_smul_one (p : polynomial R) :\n  mat_poly_equiv (p \u2022 1) = p.map (algebra_map R (matrix n n R)) :=\nbegin\n  ext m i j,\n  simp only [coeff_map, one_apply, algebra_map_matrix_apply, mul_boole,\n    pi.smul_apply, mat_poly_equiv_coeff_apply],\n  split_ifs; simp,\nend\n\nlemma support_subset_support_mat_poly_equiv\n  (m : matrix n n (polynomial R)) (i j : n) :\n  support (m i j) \u2286 support (mat_poly_equiv m) :=\nbegin\n  assume k,\n  contrapose,\n  simp only [not_mem_support_iff],\n  assume hk,\n  rw [\u2190 mat_poly_equiv_coeff_apply, hk],\n  refl\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/polynomial_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.7111564946192861}}
{"text": "import data.set\nimport data.finset\nimport data.list.basic\nimport data.vector\nimport data.option.basic\nimport tactic\n\nimport myoption\nimport mylist\nimport myfinset\nimport myfintype\nimport konig\n\nnamespace graph\n\nopen set finset\n\nattribute [instance] classical.prop_decidable\n\n-- A graph is a collection of vertices with at most one edge between\n-- any pair of vertices.  Self-loops are allowed.\nstructure graph (X : Type) :=\n  mk :: (V : set X) (E : X \u2192 X \u2192 Prop) (sym : symmetric E)\n\n-- A subgraph consists of a subset of vertices and a \"subset\" of edges.\nprotected def is_subgraph {X} (G' : graph X) (G : graph X)\n:= G'.V \u2286 G.V \u2227 \u2200 v \u2208 G'.V, \u2200 w \u2208 G'.V, G'.E v w \u2192 G.E v w\n\n-- use G' \u2286 G to denote subgraphs\ninstance (X) : has_subset (graph X) := \u27e8graph.is_subgraph\u27e9\n\n-- A graph containing an edge between every pair of distinct vertices\ndef complete_graph {X} (V : set X) := graph.mk V (\u03bb v w, v \u2260 w) (by tauto)\n\n-- Gives the induced subgraph with vertex set W\ndef induced {X} (G : graph X) (W : set X) (sub : W \u2286 G.V) :=\n  graph.mk W G.E G.sym\n\nlemma induced_is_subgraph {X} (G : graph X) (W : set X) (sub : W \u2286 G.V)\n: induced G W sub \u2286 G\n:=\nbegin\n  split,\n  exact sub,\n  intros v w vin win indedge,\n  exact indedge,\nend\n\n-- A graph coloring is an assignment of a \"color\" to each vertex such\n-- that adjacent vertices have distinct colors.\ndef graph_coloring {X} {C} (G : graph X) (c : X \u2192 C) :=\n  \u2200 v \u2208 G.V, \u2200 w \u2208 G.V, G.E v w \u2192 c v \u2260 c w\n\n-- A graph is n-colorable if it is colorable using only the colors 0 through (n-1).\ndef ncolorable {X} (G : graph X) (n : \u2115) :=\n  \u2203 (c : X \u2192 \u2115), c '' G.V \u2286 \u2191(range n) \u2227 graph_coloring G c\n\nlemma std_ncoloring {X} {C} {G : graph X} (C' : finset C) (c : X \u2192 C)\n(nc : graph_coloring G c) (cod : \u2200 v \u2208 G.V, c v \u2208 C')\n: ncolorable G (card C')\n:= begin\n  rcases finset.inj_range C' with \u27e8f, hfdom, hfinj\u27e9,\n  use (f \u2218 c),\n  simp,\n  split, {\n    intros n nelt, simp at nelt,\n    rcases nelt with \u27e8v, velt, fcv_n\u27e9,\n    simp,\n    rw \u2190 fcv_n,\n    exact hfdom (c v) (cod v velt),\n  }, {\n    intros v vin w win hedge f,\n    specialize hfinj (c v) (cod v vin) (c w) (cod w win) f,\n    exact nc v vin w win hedge hfinj,\n  },\nend\n\ndef chromatic_number {X} (G : graph X) (n : \u2115) :=\n  ncolorable G n \u2227 \u2200 m < n, \u00acncolorable G m\n\n-- A complete graph of n vertices can be colored with n or more colors but no fewer.\nlemma complete_graph_chromatic_number (n : \u2115): chromatic_number (complete_graph (\u2191(range n) : set \u2115)) n\n:=\nbegin\n  split, {\n    set f := \u03bb (v : \u2115), v with feq,\n    use f,\n    split, {\n      dsimp only [complete_graph],\n      intros c cin,\n      rcases cin with \u27e8x,h\u27e9, rw feq at h, dsimp only at h, rw \u2190h.2, tauto,\n    }, {\n      intros v vin w win hedge,\n      dsimp [complete_graph] at vin, simp at vin,\n      dsimp [complete_graph] at win, simp at win,\n      dsimp [complete_graph] at hedge,\n      rw feq, dsimp only, tauto,\n    },\n  }, {\n    intros m msmall notcolor,\n    rcases notcolor with \u27e8f,fim,coloring\u27e9,\n    dsimp [complete_graph] at fim,\n    dsimp [graph_coloring,complete_graph] at coloring, simp at coloring,\n    have h : \u2200 x < n, f x < m, {\n      intros x xin,\n      have xin' : x \u2208 range n, rw \u2190 finset.mem_range at xin, exact xin,\n      have fxin' : f x \u2208 f '' \u2191(range n), exact mem_image_of_mem f xin',\n      specialize fim fxin', simp at fim, exact fim,\n    },\n    have rangen := range n,\n    have coloring' : \u2200 v \u2208 range n, \u2200 w \u2208 range n, f v = f w \u2192 v = w,\n      intros v velt w welt, simp at velt, simp at welt, specialize coloring v velt w welt, contrapose, assumption,\n    have hh := card_image_of_inj_on coloring',\n    have hh' := range_sup f n m h,\n    dsimp only at hh, rw hh at hh',\n    simp at hh', linarith,\n  },\nend\n\n-- An n-colored graph can be colored with more than n colors.\nlemma can_color_with_more {X} (G : graph X) (n m : \u2115) (gt : m \u2265 n) (able : ncolorable G n) : ncolorable G m\n:=\nbegin\n  rcases able with \u27e8c, cod, col\u27e9,\n  have dom' : \u2200 v \u2208 G.V, c v < m,\n    intros v vin,\n    have code' := cod (mem_image_of_mem c vin),\n    simp at code',\n    linarith,\n  unfold ncolorable,\n  use c,\n  split, {\n    intros c celt,\n    rcases celt with \u27e8v, velt, cv_eq\u27e9,\n    specialize dom' v velt,\n    rw cv_eq at dom', simpa,\n  }, {\n    assumption,    \n  },\nend\n\nlemma can_color_subgraph {X} {H G : graph X} (sub : H \u2286 G) (c : X \u2192 \u2115) (is_coloring : graph_coloring G c)\n: graph_coloring H c\n:=\nbegin\n  intros v vin w win vwedgeH,\n  have vwedgeG : G.E v w := sub.2 v vin w win vwedgeH,\n  exact is_coloring v (sub.1 vin) w (sub.1 win) vwedgeG,\nend\n\n-- The following theorem is an application of K\u00f6nig's lemma, pointed\n-- out by C. St. J. A. Nash-Williams in \"Infinite graphs --- a survey\"\n-- (1967).\ntheorem can_color_countable_infinite (n : \u2115) (pos : n > 0)\n(G : graph \u2115) (fcol : \u2200 (V : finset \u2115) (sub : \u2191V \u2286 G.V), ncolorable (induced G \u2191V sub) n)\n: ncolorable G n\n:= begin\n  let Vfin := \u03bb n, G.V \u2229 \u2191(finset.range n),\n  have sub : \u2200 n, Vfin n \u2286 G.V, {\n    intro n, exact G.V.sep_subset _,\n  },\n  let Gfin := \u03bb k, induced G (Vfin k) (sub k),\n\n  let zero : {i : \u2115 // i < n} := \u27e80, pos\u27e9,\n  let X := list {i : \u2115 // i < n},\n  let S : \u2115 \u2192 set X := \u03bb (k : \u2115), {v : X | v.length = k \u2227 graph_coloring (Gfin k) (v.as_fn zero)},\n  let fns := \u03bb (k : \u2115) (v : X), v.init,\n\n  have sys : konig.inv_system S fns, {\n    intros k x xel,\n    simp [fns] at xel \u22a2,\n    rcases xel with \u27e8xlen, coloring\u27e9,\n    have nonnil : x \u2260 [], {\n      by_contradiction f, push_neg at f,\n      rw f at xlen, simp at xlen, exact (nat.succ_ne_zero k).symm xlen,\n    },\n    have h := list.init_length_is_pred nonnil,\n    rw xlen at h, simp at h, rw h, simp,\n\n    intros v vel w wel hedge,\n    dsimp only [Gfin, Vfin, induced] at hedge,\n    dsimp only [Gfin, Vfin, induced] at vel wel, simp at vel wel,\n    dsimp only [graph_coloring, Gfin, Vfin, induced] at coloring, simp at coloring,\n    specialize coloring v vel.1 (by linarith) w wel.1 (by linarith) hedge,\n    have x_nonnil : x \u2260 [], intro is_nil, rw is_nil at xlen, simp at xlen, tauto,\n    have xinit_len : x.init.length = k,\n      have hlen := list.init_length_is_pred x_nonnil, rw xlen at hlen, exact hlen,\n    have vtineq : v < x.init.length,\n      rw \u2190 xinit_len at vel, exact vel.right,\n    have wtineq : w < x.init.length,\n      rw \u2190 xinit_len at wel, exact wel.right,\n    rw list.as_fn_inrange vtineq,\n    rw list.as_fn_inrange wtineq,\n    exact coloring,\n  },\n  have nonempty : \u2200 k, \u2203 c, c \u2208 S k, {\n    intro k,\n    specialize fcol ((finset.range k).filter(\u03bb k, k \u2208 G.V)),\n    have sub : \u2191(filter (\u03bb (k : \u2115), k \u2208 G.V) (range k)) \u2286 G.V, {\n      simp, exact (\u2191(finset.range k) : set \u2115).inter_subset_right G.V,\n    },\n    specialize fcol sub, simp at fcol,\n    rcases fcol with \u27e8c, hcdom, hcol\u27e9,\n    let c' := \u03bb i, if i \u2208 G.V then c i else 0,\n    have rng : \u2200 i < k, c' i < n, {\n      intros i iineq,\n      dsimp [c'],\n      by_cases h : i \u2208 G.V,\n      have htrue : i \u2208 G.V \u2194 true, tauto,\n      rw htrue, simp,\n      dsimp [induced] at hcdom,\n      have elt : i \u2208 {x \u2208 \u2191(range k) | x \u2208 G.V}, {\n        have irange : i \u2208 (\u2191(range k) : set \u2115), simpa,\n        exact mem_sep irange h,\n      },\n      have celt : c i \u2208 range n, {\n        apply hcdom, exact mem_image_of_mem c elt,\n      },\n      simp at celt, exact celt,\n      have hfalse : i \u2208 G.V \u2194 false, tauto,\n      rw hfalse, simp, linarith,\n    },\n    let c'' := \u03bb i, if i < k then c' i else 0,\n    have rng' : \u2200 i, c'' i < n, {\n      intro i,\n      dsimp [c''],\n      by_cases h : i < k, {\n        have htrue : i < k \u2194 true, tauto,\n        rw htrue, simp,\n        exact rng i h,\n      }, {\n        have hfalse : i < k \u2194 false, tauto,\n        rw hfalse, simp,\n        linarith,\n      },\n    },\n    let c''' : \u2115 \u2192 {x : \u2115 // x < n} := \u03bb i, \u27e8c'' i, rng' i\u27e9,\n    let clis := (list.range2 0 k).map c''',\n    use clis,\n    dsimp [S],\n    split, {\n      dsimp [clis], simp,\n    }, {\n      intros v vin w win hedge,\n      dsimp [Gfin, Vfin, induced] at vin win hedge, simp at vin win,\n      dsimp [clis, list.as_fn], simp,\n      have rngv := list.range2_nth 0 k v vin.2,\n      have rngw := list.range2_nth 0 k w win.2,\n      rw [rngv, rngw], simp,\n      dsimp [c'', c'],\n      have vkt : v < k \u2194 true, tauto,\n      have wkt : w < k \u2194 true, tauto,\n      have vint : v \u2208 G.V \u2194 true, tauto,\n      have wint : w \u2208 G.V \u2194 true, tauto,\n      simp [vkt, wkt, vint, wint],\n      dsimp [graph_coloring, induced] at hcol, simp at hcol,\n      exact hcol v vin.2 vin.1 w win.2 win.1 hedge,\n    },\n  },\n\n  rcases konig.weak_konig_lemma sys nonempty with \u27e8u, invlim\u27e9,\n  use (\u03bb v, list.as_fn \u2191(u (v+1)) zero v),\n  have zup : (0:\u2115) = \u2191zero, unfold_coes,\n  split, {\n    intros c cin,\n    simp at cin, simp,\n    rcases cin with \u27e8v, vin, cdef\u27e9,\n    dsimp [list.as_fn] at cdef,\n    rw zup at cdef,\n    norm_cast at cdef, unfold_coes at cdef,\n    set lu := ((list.nth (u (v + 1)) v).get_or_else zero) with lueq,\n    rw \u2190 cdef, exact lu.property,\n  }, {\n    intros v vin w win hedge,\n    dsimp [list.as_fn], rw zup, norm_cast, unfold_coes,\n    have rsys : \u2200 k, u k = list.init (u (k + 1)), {\n      intro k,\n      have f := invlim k,\n      dsimp [fns] at f,\n      exact f.right,\n    },\n    have lens : \u2200 k, (u k).length = k, {\n      intro k,\n      have f := (invlim k).left,\n      dsimp [S] at f, exact f.1,\n    },\n    let K := max (v + 1) (w + 1),\n    have liftv := list.init_rep_nth u rsys lens v (v + 1) K (by linarith) (le_max_left (v + 1) (w + 1)),\n    have liftw := list.init_rep_nth u rsys lens w (w + 1) K (by linarith) (le_max_right (v + 1) (w + 1)),\n    rw [liftv, liftw],\n    have uKelt := (invlim K).left,\n    dsimp [S,graph_coloring,Gfin,Vfin,list.as_fn,induced] at uKelt, simp at uKelt,\n    have vlt : v < v + 1 \u2228 v < w + 1, left, linarith,\n    have wlt : w < v + 1 \u2228 w < w + 1, right, linarith,\n    have uKelt' := uKelt.right v vin vlt w win wlt hedge,\n    intro as_eq,\n    have as_eq' := subtype.eq as_eq,\n    exact uKelt' as_eq',\n  },\n\nend\n\nend graph\n", "meta": {"author": "kmill", "repo": "lean-graphcoloring", "sha": "1bb2050ed358ff647186f89922d6a09b838444e5", "save_path": "github-repos/lean/kmill-lean-graphcoloring", "path": "github-repos/lean/kmill-lean-graphcoloring/lean-graphcoloring-1bb2050ed358ff647186f89922d6a09b838444e5/src/graph.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7111411506569689}}
{"text": "import .A2\nimport category_theory.functor_category \nimport algebra.category.CommRing.basic \nuniverses v u\nopen A2\ndef map_A2 {A B :Type v}[comm_ring A][comm_ring B](f : A \u2192  B)[is_ring_hom  f] : A2 A \u2192 A2 B := \u03bb \u03b6,  begin  \n    use { a := f \u03b6.a, b := f \u03b6.b},\nend \nvariables (A B :Type v)[comm_ring A][comm_ring B]\ndef map_a_b (f : A \u2192  B)[is_ring_hom  f] (\u03b6 : A2 A)  : (map_A2 (f) \u03b6).a = f \u03b6.a  \u2227 (map_A2 (f) \u03b6).b = f \u03b6.b := \nbegin \n        split, \n        exact rfl,\n        exact rfl,\nend\ndef \ud835\udd382 : CommRing \u2964 Type v :=  \n{ obj := \u03bb R, A2 R,\n  map := \u03bb R R' f, map_A2 f, \n--   map_id' := \u03bb R, begin\n--      funext,\n--      rw category_theory.types_id,\n--      ext,\n--      exact rfl,\n--      exact rfl,\n--      end,\n}\n#print \ud835\udd382 \n#print \ud835\udd382._proof_2\n/--\ntheorem \ud835\udd382._proof_2 : \u2200 (X : CommRing), map_A2 \u21d1(\ud835\udfd9 X) = \ud835\udfd9 (A2 \u21a5X) :=\n\u03bb (X : CommRing),\n  id\n    (\u03bb (X : CommRing),\n       funext\n         (\u03bb (x : A2 \u21a5X),\n            id\n              (\u03bb (X : CommRing) (x : A2 \u21a5X),\n                 ext (eq.refl (map_A2 \u21d1(\ud835\udfd9 X) x).a) (eq.refl (map_A2 \u21d1(\ud835\udfd9 X) x).b))\n              X\n              x))\n    X\n-/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"author": "Or7ando", "repo": "lean", "sha": "d41169cf4e416a0d42092fb6bdc14131cee9dd15", "save_path": "github-repos/lean/Or7ando-lean", "path": "github-repos/lean/Or7ando-lean/lean-d41169cf4e416a0d42092fb6bdc14131cee9dd15/.github/workflows/project_1_a_decrire/projet_A2/A2_functor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7111411317610103}}
{"text": "/-\nCS 2102 F19, Homework #8, Predicate Logic & Proofs.\n-/\n\nnamespace hw8\n\n/-\n#1. Equality and proofs of equality. \n-/\n\n/-\nA. [10 points] Fill in the blank.\n\nWhen we say that the binary equality relation, \n=, on objects of any type, \u03b1, is reflexive, we\nmean that for any value, a, of type, \u03b1, _______.\n\nANSWER: \n-/\n\n\n/- \nB. [10 points]\nComplete the following definition in Lean\nto formalize the proposition that 1 equals\n1.\n-/\n\ndef one_eq_one : Prop := \n    -- ANSWER\n    _\n\n\n/-\nC. [10 points]\nGive an English language proof of the\nproposition that 1 = 1 by completing the\nfollowing incomplete proof.\n\nTo obtain a proof of 1 = 1 we apply the ________ \nproperty of the ________ relation to the specific\nvalue, _________.\n\nANSWER: \n-/\n\n\n/- \nD. [10 points]\nGive a formal proof of this proposition\nby completing the following definition.\n-/\n\ndef proof_that_one_eq_one : one_eq_one :=\n    -- ANSWER\n    _\n\n\n/- [10 points]\nE. Complete the following test case to produce \nan example that suggests (correctly) that Lean\nwill accept a proof that two *different terms* are \nequal as long as they reduce to the same value. \n-/\n\n-- ANSWER: Give a proposition and proof in Lean\n\ndef two_plus_two_eq_four : _ := _\n\n-- ANSWER Does eq.refl work as suggested? _____ \n\n\n/-\n#2. Predicates and Properties\n\nA predicate is a parameterized proposition. By\napplying a predicate to different arguments, we get\ndifferent propositions. Such a propopsition can \nbe said to be \"about\" the argument to which it was \napplied. \n\nWe interpret such a proposition as asserting that \nits argument has a *property* of interest. If the\nproposition has a proof (is true), the object does\nhave the asserted property, and if the proposition\nis not true, the object doesn't have that property.\n\nIn the  following set of problems, we will take the \nproperty of a natural number \"being even\" as a case\nin point. \n\nIn natural language, we will say that a natural \nnumber, n, is even if and only if (1) it is zero,\nor, (2) it is two more than another even number.\n\nThink about this inductive definition. Why does it\ncover all possible cases -- an infinitude of cases?\n(No need for an answer here.)\n-/\n\n/-\n\nA. [10 points]\n\nWe have accepted as *axioms* in our definition\nof evennness that zero is even and that any number\nthat is two more than another even number is even.\nThese are the only axioms you may use in giving a\nproof that four is even. Give a natural language \nproof now. Hint, start by saying the following:\n\nProof: To prove that four is even, *it will suffice*\nto show that 2 is even, because if two is even then,\ngiven that 4 is two more than two, if two is even\nthen so is four, by rule (2). Now all that remains\nto be proved is that _______________.\n\nGive the rest of your natural language proof here,\nand be sure to indicate which of the two rules you\nare applying at each step in your reasoning.\n\nANSWER: \n\n-/\n\n/-\nB. [10 points]\n\nWe formalize a predicate, such as is_even, as a\nfamily of \"inductive propositions\" given by a\nfunction from argument values to propositions. \nSuch an inductive definition thus has the type, \n\u03b1 \u2192 Prop, where \u03b1 is the type of argument to \nwhich the predicate is applied. \n\nPlease see the first line of the definition of \nis_even that follows for an example.\n\nHaving specified the *type* of a predicate, in\nthis case from \u2115 \u2192 Prop, we then define the set\nof constructors to define the logical rules that\ncan be used to construct proofs of any such\nproposition. \n\nThese rules are the (formal) axioms that can be\nused to construct proofs. The first one (below)\nstates that the term, pf_zero_is_even, is to be\naccepted as a proof of is_even 0 (which is how\nwe write the application of a predicate to a value\nto obtain a proposition, here that \"0 is even\").\n\nThe second constructor/axiom/rule provides a way\nto build a proof of (is_even 2+n) by applying the\nconstructor to any n along with a proof that that\nparticular n is even. (Yes: the \u2200 specifies the\nfirst argument to pf_even_plus_two_is_even. This\nis necessary to give the argument a name, here n,\nso that that name can be used in defining the rest\nof the constructor's type). \n-/\n\ninductive is_even : \u2115 \u2192 Prop\n| pf_zero_is_even : (is_even 0)\n| pf_even_plus_two_is_even : \n    \u2200 (n : \u2115), is_even n \u2192 is_even (nat.succ (nat.succ n))\n\n/-\nGive formal proofs for each of the following\npropositions. (Notice how we obtain different\npropositions by applying the predicate, is_even,\nto different argument values. This is what we\nmean when we say that a predicate defines a\nfamily of propositions.)\n-/\n\nopen is_even\n\ntheorem zero_even   : is_even 0 := \n    -- ANSWER\n    _\n\n/-\nIn this case, give a proof term without using\na begin/end proof script.\n-/\ntheorem two_even    : is_even 2 := \n    -- ANSWER\n    pf_even_plus_two_is_even _ _\n\n/-\nIn this case, give a proof using a begin/end\nproof script.\n-/\ntheorem eight_even  : is_even 8 := \nbegin\n    apply pf_even_plus_two_is_even,\n    sorry   -- replace this with answer\nend\n\n/-\nC. [10 points]\n\nFormally specify a predicate, is_odd, on the \nnatural numbers.  You can reason about any\nnatural number being odd using two rules, just\nas for being even. Once you've defined your\npredicate (an inductive family of proposition,\njust like is_even), formally state and prove\nthe following propositions (however you wish).\n\n- 1 is odd\n- 7 is odd\n\n-/\n\n-- ANSWER\n\nopen is_odd\n\n-- ANSWER\n\n\n-- ANSWER\n\n\n\n/-\nIntroducing an important concept. In the preceding\nproblems, we've seen that we can think of a predicate\nwith one argument as defining a property objects, such\nas the property of being even. Now we shift perspective\nfrom the concept of a property, per se, to the concept\nof \"the set of objects that have a given property.\" The\nset of objects that have the is_even property, for\nexample, could be written as\n\n    evens = {0, 2, 4, 6, 8, 10, ...}\n\nor more formally as\n\n    evens = { n : \u2115 | is_even n}\n\nThe elements of these sets are all, and only,\nthe values that \"satisfy\" the is_even predicate.\nA value satisfies its predicate if, when plugged\nin, the resulting proposition has a proof (and so\nis true). The key conclusion is that a predicate\nwith a single argument defines a *set*, namely \nthe set of all and only those objects that have\nthat property.\n-/\n\n/-\n#4. Predicates and binary relations\n\nMathematicians define *binary relations* as sets\nof ordered pairs. For example, the equality relation\non natural numbers comprises the set of of all pairs\nof natural numbers such that the first and second\nelements are the same. We could write this set like\nthis:\n\n    equals = { (0,0), (1,1), (2,2), ...},\n\nor like this:\n\n    equals = { (m : \u2115, n : \u2115) | m = n }\n\nWe formalize binary relations as predicates with \n*two* arguments. The type of such a predicate in \nLean is thus \u03b1 \u2192 \u03b2 \u2192 Prop, where \u03b1 and \u03b2 are the\ntypes of the arguments.\n\nIn our example, we have a two-place predicate that\ndefines the set of ordered pairs of natural numbers\nwhere the two elements of each pair are co-equal.\n\nStudy and understand the following specification\nof this binary relation. Look at the construtor,\nmk, in particular: it says that you can construct\na proof that a pair of values, n and m, is in our\nid_nat_relation if you have a proof of n = m. (In \nother words, it suffices to show that n = m using\nLean's built in equality relation to construct a\nproof that (n, m) is in our id_nat_relation.) \n-/\n\ninductive id_nat_relation : \u2115 \u2192 \u2115 \u2192 Prop\n| mk : \u2200 (n m : \u2115), n = m \u2192 id_nat_relation n m\n\n/-\nA. [10 points]\n\nGive a formal proof that id_nat_relation contains \nthe pair, (3, 3). Do it by completing the following\nproof. Think carefully about the third argument: you\nneed a *value* of what type here? What do we call a\nvalue of a logical type?\n-/\n\ntheorem three_three_in_id : id_nat_relation 3 3 :=\n    -- ANSWER (apply a constructor, of course)\n    id_nat_relation.mk _ _ _\n\n/-\nB. [10 points]\n\nExplain in just a few words why it is not\npossible to prove that (3,5) is in this relation.\n-/\n\n-- ANSWER\n\n\n\n/-\nEXTRA CREDIT.\n-/\n\n/-\nHere's a definition of what it means for a\nrelation to be reflexive.\n-/\n\ndef reflexive {\u03b1 : Type} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n    \u2200 (a : \u03b1), r a a\n\n/-\nA. Formally state and prove that id_nat_relation\nis reflexive. Hint: use a script and start it\nwith \"assume (a : \u2115)\". Remember that to prove a \u2200\nproposition, we *assume* that we're given some\narbitrary but specific value of the given type,\nthen we prove the rest of the proposition about\nit. But because we didn't say anything about \nthe element we picked, we can conclude that the\nstatement must be true of any element of the type. \n-/\n\n-- ANSWER\n\ntheorem id_nat_refl : reflexive id_nat_relation :=\nbegin\nassume (a : \u2115),\nsorry               -- replace this\nend\n\n/-\nB. [Double extra credit.]\n\nFormally define what we mean by a relation being\nsymmetric and transitive, in the style of the above\ndefinition of reflexive, and formally state and show\nthat our id_nat_reflexive relation is also symmetric\nand transitive.\n-/\n\n\nend hw8", "meta": {"author": "kevinsullivan", "repo": "uva-cs-dm-f19", "sha": "09a950752884bd7ade4be33e9e89a2c4b1927167", "save_path": "github-repos/lean/kevinsullivan-uva-cs-dm-f19", "path": "github-repos/lean/kevinsullivan-uva-cs-dm-f19/uva-cs-dm-f19-09a950752884bd7ade4be33e9e89a2c4b1927167/assignments/hw8_intro_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979306, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7110372816209779}}
{"text": "-- Prueba por inducci\u00f3n 5: m^(succ n) = m * m^n\n-- ============================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Sean m y n n\u00fameros naturales. Demostrar que\n--    m^(succ n) = m * m^n\n-- ----------------------------------------------------\n\nimport data.nat.basic\nopen nat\n\nvariables (m n : \u2115)\n\n-- #check nat.pow_zero\n-- #check nat.pow_succ\n-- #check nat.mul_one\n-- #check nat.one_mul\n-- #check nat.mul_assoc\n-- #check nat.mul_comm\n\n-- 1\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nbegin\n  induction n with n HI,\n  { rw pow_succ',\n    rw pow_zero,\n    rw nat.one_mul,\n    rw nat.mul_one, },\n  { rw pow_succ',\n    rw HI,\n    rw nat.mul_assoc,\n    rw nat.mul_comm (m^n), },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nbegin\n  induction n with n HI,\n  rw [pow_succ', pow_zero, one_mul, mul_one],\n  rw [pow_succ', HI, mul_assoc, mul_comm (m^n)],\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nbegin\n  induction n with n HI,\n  { simp only [pow_succ', pow_zero, one_mul, mul_one]},\n  { simp only [pow_succ', HI, mul_assoc, mul_comm (m^n)]},\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nby induction n;\n   simp only [*,\n              pow_succ',\n              pow_zero,\n              nat.one_mul,\n              nat.mul_one,\n              nat.mul_assoc,\n              nat.mul_comm]\n\n-- 5\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nby induction n;\n   simp [*,\n         pow_succ',\n         mul_comm]\n\n-- 6\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { simp [pow_succ', HI],\n    cc, },\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nbegin\n  induction n with n HI,\n  { calc\n      m^(succ 0)\n          = m^0 * m : by rw pow_succ'\n      ... = 1 * m   : by rw pow_zero\n      ... = m       : by rw nat.one_mul\n      ... = m * 1   : by rw nat.mul_one\n      ... = m * m^0 : by rw pow_zero, },\n  { calc\n      m^(succ (succ n))\n          = m^(succ n) * m   : by rw pow_succ'\n      ... = (m * m^n) * m    : by rw HI\n      ... = m * (m^n * m)    : by rw nat.mul_assoc\n      ... = m * m^(succ n)   : by rw pow_succ', },\nend\n\n-- 8\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * m^n :=\nnat.rec_on n\n  (show m^(succ 0) = m * m^0, from calc\n    m^(succ 0) = m^0 * m : by rw pow_succ'\n           ... = 1 * m   : by rw pow_zero\n           ... = m       : by rw one_mul\n           ... = m * 1   : by rw mul_one\n           ... = m * m^0 : by rw pow_zero)\n  (assume n,\n    assume HI : m^(succ n) = m * m^n,\n    show m^(succ (succ n)) = m * m^(succ n), from calc\n      m^(succ (succ n)) = m^(succ n) * m   : by rw pow_succ'\n                    ... = (m * m^n) * m    : by rw HI\n                    ... = m * (m^n * m)    : by rw mul_assoc\n                    ... = m * m^(succ n)   : by rw pow_succ')\n\n-- 9\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * (m^n) :=\nnat.rec_on n\n  (show m^(succ 0) = m * m^0,\n    by rw [pow_succ', pow_zero, mul_one, one_mul])\n  (assume n,\n    assume HI : m^(succ n) = m * m^n,\n    show m^(succ (succ n)) = m * m^(succ n),\n      by rw [pow_succ', HI, mul_assoc, mul_comm (m^n)])\n\n-- 10\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * (m^n) :=\nnat.rec_on n\n  (show m^(succ 0) = m * m^0,\n    by simp )\n  (assume n,\n    assume HI : m^(succ n) = m * m^n,\n    show m^(succ (succ n)) = m * m^(succ n),\n      by finish [pow_succ', HI] )\n\n-- 11\u00aa demostraci\u00f3n\nexample : m^(succ n) = m * (m^n) :=\nnat.rec_on n\n  (by simp)\n  (\u03bb n HI, by finish [pow_succ', HI])\n\n-- 12\u00aa demostraci\u00f3n\nlemma aux : \u2200 m n : \u2115, m^(succ n) = m * (m^n)\n| m 0     := by simp\n| m (n+1) := by simp [pow_succ',\n                      aux m n,\n                      mul_assoc,\n                      mul_comm (m^n)]\n\n-- 13\u00aa demostraci\u00f3n\nlemma aux2 : \u2200 m n : \u2115, m^(succ n) = m * (m^n)\n| m 0     := by simp only [pow_succ',\n                           pow_zero,\n                           one_mul,\n                           mul_one]\n| m (n+1) := by simp only [pow_succ',\n                           aux2 m n,\n                           mul_assoc,\n                           mul_comm (m^n)]\n\n-- 14\u00aa demostraci\u00f3n\nlemma aux3 : \u2200 m n : \u2115, m^(succ n) = m * (m^n)\n| m 0     := by simp\n| m (n+1) := by simp [pow_succ', aux3 m n] ; cc\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/6_Naturales/Prueba_por_induccion_5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.71103727349542}}
{"text": "/-\nCopyright (c) 2018 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport algebra.big_operators.ring\nimport data.real.pointwise\nimport algebra.indicator_function\nimport algebra.algebra.basic\nimport algebra.order.module\nimport algebra.order.nonneg\n\n/-!\n# Nonnegative real numbers\n\nIn this file we define `nnreal` (notation: `\u211d\u22650`) to be the type of non-negative real numbers,\na.k.a. the interval `[0, \u221e)`. We also define the following operations and structures on `\u211d\u22650`:\n\n* the order on `\u211d\u22650` is the restriction of the order on `\u211d`; these relations define a conditionally\n  complete linear order with a bottom element, `conditionally_complete_linear_order_bot`;\n\n* `a + b` and `a * b` are the restrictions of addition and multiplication of real numbers to `\u211d\u22650`;\n  these operations together with `0 = \u27e80, _\u27e9` and `1 = \u27e81, _\u27e9` turn `\u211d\u22650` into a conditionally\n  complete linear ordered archimedean commutative semifield; we have no typeclass for this in\n  `mathlib` yet, so we define the following instances instead:\n\n  - `linear_ordered_semiring \u211d\u22650`;\n  - `ordered_comm_semiring \u211d\u22650`;\n  - `canonically_ordered_comm_semiring \u211d\u22650`;\n  - `linear_ordered_comm_group_with_zero \u211d\u22650`;\n  - `canonically_linear_ordered_add_monoid \u211d\u22650`;\n  - `archimedean \u211d\u22650`;\n  - `conditionally_complete_linear_order_bot \u211d\u22650`.\n\n  These instances are derived from corresponding instances about the type `{x : \u03b1 // 0 \u2264 x}` in an\n  appropriate ordered field/ring/group/monoid `\u03b1`. See `algebra/order/nonneg`.\n\n* `real.to_nnreal x` is defined as `\u27e8max x 0, _\u27e9`, i.e. `\u2191(real.to_nnreal x) = x` when `0 \u2264 x` and\n  `\u2191(real.to_nnreal x) = 0` otherwise.\n\nWe also define an instance `can_lift \u211d \u211d\u22650`. This instance can be used by the `lift` tactic to\nreplace `x : \u211d` and `hx : 0 \u2264 x` in the proof context with `x : \u211d\u22650` while replacing all occurences\nof `x` with `\u2191x`. This tactic also works for a function `f : \u03b1 \u2192 \u211d` with a hypothesis\n`hf : \u2200 x, 0 \u2264 f x`.\n\n## Notations\n\nThis file defines `\u211d\u22650` as a localized notation for `nnreal`.\n\n## TODO\n\n`semifield` instance\n-/\n\nopen_locale classical big_operators\n\n/-- Nonnegative real numbers. -/\n@[derive [\n  ordered_semiring, comm_monoid_with_zero, -- to ensure these instance are computable\n  floor_semiring,\n  semilattice_inf, densely_ordered, order_bot,\n  canonically_linear_ordered_add_monoid, linear_ordered_comm_group_with_zero, archimedean,\n  linear_ordered_semiring, ordered_comm_semiring, canonically_ordered_comm_semiring,\n  has_sub, has_ordered_sub, has_div, inhabited]]\ndef nnreal := {r : \u211d // 0 \u2264 r}\nlocalized \"notation ` \u211d\u22650 ` := nnreal\" in nnreal\n\nnamespace nnreal\n\ninstance : has_coe \u211d\u22650 \u211d := \u27e8subtype.val\u27e9\n\n/- Simp lemma to put back `n.val` into the normal form given by the coercion. -/\n@[simp] lemma val_eq_coe (n : \u211d\u22650) : n.val = n := rfl\n\ninstance : can_lift \u211d \u211d\u22650 :=\n{ coe := coe,\n  cond := \u03bb r, 0 \u2264 r,\n  prf := \u03bb x hx, \u27e8\u27e8x, hx\u27e9, rfl\u27e9 }\n\nprotected lemma eq {n m : \u211d\u22650} : (n : \u211d) = (m : \u211d) \u2192 n = m := subtype.eq\n\nprotected lemma eq_iff {n m : \u211d\u22650} : (n : \u211d) = (m : \u211d) \u2194 n = m :=\niff.intro nnreal.eq (congr_arg coe)\n\nlemma ne_iff {x y : \u211d\u22650} : (x : \u211d) \u2260 (y : \u211d) \u2194 x \u2260 y :=\nnot_iff_not_of_iff $ nnreal.eq_iff\n\nprotected lemma \u00abforall\u00bb {p : \u211d\u22650 \u2192 Prop} : (\u2200 x : \u211d\u22650, p x) \u2194 \u2200 (x : \u211d) (hx : 0 \u2264 x), p \u27e8x, hx\u27e9 :=\nsubtype.forall\n\nprotected lemma \u00abexists\u00bb {p : \u211d\u22650 \u2192 Prop} : (\u2203 x : \u211d\u22650, p x) \u2194 \u2203 (x : \u211d) (hx : 0 \u2264 x), p \u27e8x, hx\u27e9 :=\nsubtype.exists\n\n/-- Reinterpret a real number `r` as a non-negative real number. Returns `0` if `r < 0`. -/\nnoncomputable def _root_.real.to_nnreal (r : \u211d) : \u211d\u22650 := \u27e8max r 0, le_max_right _ _\u27e9\n\nlemma _root_.real.coe_to_nnreal (r : \u211d) (hr : 0 \u2264 r) : (real.to_nnreal r : \u211d) = r :=\nmax_eq_left hr\n\nlemma _root_.real.le_coe_to_nnreal (r : \u211d) : r \u2264 real.to_nnreal r :=\nle_max_left r 0\n\nlemma coe_nonneg (r : \u211d\u22650) : (0 : \u211d) \u2264 r := r.2\n@[norm_cast]\ntheorem coe_mk (a : \u211d) (ha) : ((\u27e8a, ha\u27e9 : \u211d\u22650) : \u211d) = a := rfl\n\nexample : has_zero \u211d\u22650  := by apply_instance\nexample : has_one \u211d\u22650   := by apply_instance\nexample : has_add \u211d\u22650   := by apply_instance\nnoncomputable example : has_sub \u211d\u22650   := by apply_instance\nexample : has_mul \u211d\u22650   := by apply_instance\nnoncomputable example : has_inv \u211d\u22650   := by apply_instance\nnoncomputable example : has_div \u211d\u22650   := by apply_instance\nexample : has_le \u211d\u22650    := by apply_instance\nexample : has_bot \u211d\u22650   := by apply_instance\nexample : inhabited \u211d\u22650 := by apply_instance\nexample : nontrivial \u211d\u22650 := by apply_instance\n\nprotected lemma coe_injective : function.injective (coe : \u211d\u22650 \u2192 \u211d) := subtype.coe_injective\n@[simp, norm_cast] protected lemma coe_eq {r\u2081 r\u2082 : \u211d\u22650} : (r\u2081 : \u211d) = r\u2082 \u2194 r\u2081 = r\u2082 :=\nnnreal.coe_injective.eq_iff\nprotected lemma coe_zero : ((0 : \u211d\u22650) : \u211d) = 0 := rfl\nprotected lemma coe_one  : ((1 : \u211d\u22650) : \u211d) = 1 := rfl\nprotected lemma coe_add (r\u2081 r\u2082 : \u211d\u22650) : ((r\u2081 + r\u2082 : \u211d\u22650) : \u211d) = r\u2081 + r\u2082 := rfl\nprotected lemma coe_mul (r\u2081 r\u2082 : \u211d\u22650) : ((r\u2081 * r\u2082 : \u211d\u22650) : \u211d) = r\u2081 * r\u2082 := rfl\nprotected lemma coe_inv (r : \u211d\u22650) : ((r\u207b\u00b9 : \u211d\u22650) : \u211d) = r\u207b\u00b9 := rfl\nprotected lemma coe_div (r\u2081 r\u2082 : \u211d\u22650) : ((r\u2081 / r\u2082 : \u211d\u22650) : \u211d) = r\u2081 / r\u2082 := rfl\n@[simp, norm_cast] protected \n\n@[simp, norm_cast] protected lemma coe_sub {r\u2081 r\u2082 : \u211d\u22650} (h : r\u2082 \u2264 r\u2081) :\n  ((r\u2081 - r\u2082 : \u211d\u22650) : \u211d) = r\u2081 - r\u2082 :=\nmax_eq_left $ le_sub.2 $ by simp [show (r\u2082 : \u211d) \u2264 r\u2081, from h]\n\n-- TODO: setup semifield!\n@[simp, norm_cast] protected lemma coe_eq_zero (r : \u211d\u22650) : \u2191r = (0 : \u211d) \u2194 r = 0 :=\nby rw [\u2190 nnreal.coe_zero, nnreal.coe_eq]\n\n@[simp, norm_cast] protected lemma coe_eq_one (r : \u211d\u22650) : \u2191r = (1 : \u211d) \u2194 r = 1 :=\nby rw [\u2190 nnreal.coe_one, nnreal.coe_eq]\n\nlemma coe_ne_zero {r : \u211d\u22650} : (r : \u211d) \u2260 0 \u2194 r \u2260 0 := by norm_cast\n\nexample : comm_semiring \u211d\u22650 := by apply_instance\n\n/-- Coercion `\u211d\u22650 \u2192 \u211d` as a `ring_hom`. -/\ndef to_real_hom : \u211d\u22650 \u2192+* \u211d :=\n\u27e8coe, nnreal.coe_one, nnreal.coe_mul, nnreal.coe_zero, nnreal.coe_add\u27e9\n\n@[simp] lemma coe_to_real_hom : \u21d1to_real_hom = coe := rfl\n\nsection actions\n\n/-- A `mul_action` over `\u211d` restricts to a `mul_action` over `\u211d\u22650`. -/\ninstance {M : Type*} [mul_action \u211d M] : mul_action \u211d\u22650 M :=\nmul_action.comp_hom M to_real_hom.to_monoid_hom\n\nlemma smul_def {M : Type*} [mul_action \u211d M] (c : \u211d\u22650) (x : M) :\n  c \u2022 x = (c : \u211d) \u2022 x := rfl\n\ninstance {M N : Type*} [mul_action \u211d M] [mul_action \u211d N] [has_scalar M N]\n  [is_scalar_tower \u211d M N] : is_scalar_tower \u211d\u22650 M N :=\n{ smul_assoc := \u03bb r, (smul_assoc (r : \u211d) : _)}\n\ninstance smul_comm_class_left {M N : Type*} [mul_action \u211d N] [has_scalar M N]\n  [smul_comm_class \u211d M N] : smul_comm_class \u211d\u22650 M N :=\n{ smul_comm := \u03bb r, (smul_comm (r : \u211d) : _)}\n\ninstance smul_comm_class_right {M N : Type*} [mul_action \u211d N] [has_scalar M N]\n  [smul_comm_class M \u211d N] : smul_comm_class M \u211d\u22650 N :=\n{ smul_comm := \u03bb m r, (smul_comm m (r : \u211d) : _)}\n\n/-- A `distrib_mul_action` over `\u211d` restricts to a `distrib_mul_action` over `\u211d\u22650`. -/\ninstance {M : Type*} [add_monoid M] [distrib_mul_action \u211d M] : distrib_mul_action \u211d\u22650 M :=\ndistrib_mul_action.comp_hom M to_real_hom.to_monoid_hom\n\n/-- A `module` over `\u211d` restricts to a `module` over `\u211d\u22650`. -/\ninstance {M : Type*} [add_comm_monoid M] [module \u211d M] : module \u211d\u22650 M :=\nmodule.comp_hom M to_real_hom\n\n/-- An `algebra` over `\u211d` restricts to an `algebra` over `\u211d\u22650`. -/\ninstance {A : Type*} [semiring A] [algebra \u211d A] : algebra \u211d\u22650 A :=\n{ smul := (\u2022),\n  commutes' := \u03bb r x, by simp [algebra.commutes],\n  smul_def' := \u03bb r x, by simp [\u2190algebra.smul_def (r : \u211d) x, smul_def],\n  to_ring_hom := ((algebra_map \u211d A).comp (to_real_hom : \u211d\u22650 \u2192+* \u211d)) }\n\n-- verify that the above produces instances we might care about\nexample : algebra \u211d\u22650 \u211d := by apply_instance\nexample : distrib_mul_action \u211d\u22650\u02e3 \u211d := by apply_instance\n\nend actions\n\nexample : monoid_with_zero \u211d\u22650 := by apply_instance\nexample : comm_monoid_with_zero \u211d\u22650 := by apply_instance\nnoncomputable example : comm_group_with_zero \u211d\u22650 := by apply_instance\n\n@[simp, norm_cast] lemma coe_indicator {\u03b1} (s : set \u03b1) (f : \u03b1 \u2192 \u211d\u22650) (a : \u03b1) :\n  ((s.indicator f a : \u211d\u22650) : \u211d) = s.indicator (\u03bb x, f x) a :=\n(to_real_hom : \u211d\u22650 \u2192+ \u211d).map_indicator _ _ _\n\n@[simp, norm_cast] lemma coe_pow (r : \u211d\u22650) (n : \u2115) : ((r^n : \u211d\u22650) : \u211d) = r^n :=\nto_real_hom.map_pow r n\n\n@[simp, norm_cast] lemma coe_zpow (r : \u211d\u22650) (n : \u2124) : ((r^n : \u211d\u22650) : \u211d) = r^n :=\nby cases n; simp\n\n@[norm_cast] lemma coe_list_sum (l : list \u211d\u22650) :\n  ((l.sum : \u211d\u22650) : \u211d) = (l.map coe).sum :=\nto_real_hom.map_list_sum l\n\n@[norm_cast] lemma coe_list_prod (l : list \u211d\u22650) :\n  ((l.prod : \u211d\u22650) : \u211d) = (l.map coe).prod :=\nto_real_hom.map_list_prod l\n\n@[norm_cast] lemma coe_multiset_sum (s : multiset \u211d\u22650) :\n  ((s.sum : \u211d\u22650) : \u211d) = (s.map coe).sum :=\nto_real_hom.map_multiset_sum s\n\n@[norm_cast] lemma coe_multiset_prod (s : multiset \u211d\u22650) :\n  ((s.prod : \u211d\u22650) : \u211d) = (s.map coe).prod :=\nto_real_hom.map_multiset_prod s\n\n@[norm_cast] lemma coe_sum {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d\u22650} :\n  \u2191(\u2211 a in s, f a) = \u2211 a in s, (f a : \u211d) :=\nto_real_hom.map_sum _ _\n\nlemma _root_.real.to_nnreal_sum_of_nonneg {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d}\n  (hf : \u2200 a, a \u2208 s \u2192 0 \u2264 f a) :\n  real.to_nnreal (\u2211 a in s, f a) = \u2211 a in s, real.to_nnreal (f a) :=\nbegin\n  rw [\u2190nnreal.coe_eq, nnreal.coe_sum, real.coe_to_nnreal _ (finset.sum_nonneg hf)],\n  exact finset.sum_congr rfl (\u03bb x hxs, by rw real.coe_to_nnreal _ (hf x hxs)),\nend\n\n@[norm_cast] lemma coe_prod {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d\u22650} :\n  \u2191(\u220f a in s, f a) = \u220f a in s, (f a : \u211d) :=\nto_real_hom.map_prod _ _\n\nlemma _root_.real.to_nnreal_prod_of_nonneg {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d}\n  (hf : \u2200 a, a \u2208 s \u2192 0 \u2264 f a) :\n  real.to_nnreal (\u220f a in s, f a) = \u220f a in s, real.to_nnreal (f a) :=\nbegin\n  rw [\u2190nnreal.coe_eq, nnreal.coe_prod, real.coe_to_nnreal _ (finset.prod_nonneg hf)],\n  exact finset.prod_congr rfl (\u03bb x hxs, by rw real.coe_to_nnreal _ (hf x hxs)),\nend\n\nlemma nsmul_coe (r : \u211d\u22650) (n : \u2115) : \u2191(n \u2022 r) = n \u2022 (r:\u211d) :=\nby norm_cast\n\n@[simp, norm_cast] protected lemma coe_nat_cast (n : \u2115) : (\u2191(\u2191n : \u211d\u22650) : \u211d) = n :=\nmap_nat_cast to_real_hom n\n\nnoncomputable example : linear_order \u211d\u22650 := by apply_instance\n\n@[simp, norm_cast] protected lemma coe_le_coe {r\u2081 r\u2082 : \u211d\u22650} : (r\u2081 : \u211d) \u2264 r\u2082 \u2194 r\u2081 \u2264 r\u2082 := iff.rfl\n@[simp, norm_cast] protected lemma coe_lt_coe {r\u2081 r\u2082 : \u211d\u22650} : (r\u2081 : \u211d) < r\u2082 \u2194 r\u2081 < r\u2082 := iff.rfl\n@[simp, norm_cast] protected lemma coe_pos {r : \u211d\u22650} : (0 : \u211d) < r \u2194 0 < r := iff.rfl\n\nprotected lemma coe_mono : monotone (coe : \u211d\u22650 \u2192 \u211d) := \u03bb _ _, nnreal.coe_le_coe.2\n\nprotected lemma _root_.real.to_nnreal_mono : monotone real.to_nnreal :=\n\u03bb x y h, max_le_max h (le_refl 0)\n\n@[simp] lemma _root_.real.to_nnreal_coe {r : \u211d\u22650} : real.to_nnreal r = r :=\nnnreal.eq $ max_eq_left r.2\n\n@[simp] lemma mk_coe_nat (n : \u2115) : @eq \u211d\u22650 (\u27e8(n : \u211d), n.cast_nonneg\u27e9 : \u211d\u22650) n :=\nnnreal.eq (nnreal.coe_nat_cast n).symm\n\n@[simp] lemma to_nnreal_coe_nat (n : \u2115) : real.to_nnreal n = n :=\nnnreal.eq $ by simp [real.coe_to_nnreal]\n\n/-- `real.to_nnreal` and `coe : \u211d\u22650 \u2192 \u211d` form a Galois insertion. -/\nnoncomputable def gi : galois_insertion real.to_nnreal coe :=\ngalois_insertion.monotone_intro nnreal.coe_mono real.to_nnreal_mono\n  real.le_coe_to_nnreal (\u03bb _, real.to_nnreal_coe)\n\n-- note that anything involving the (decidability of the) linear order, including `\u2294`/`\u2293` (min, max)\n-- will be noncomputable, everything else should not be.\nexample : order_bot \u211d\u22650 := by apply_instance\nexample : partial_order \u211d\u22650 := by apply_instance\nnoncomputable example : canonically_linear_ordered_add_monoid \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_add_comm_monoid \u211d\u22650 := by apply_instance\nnoncomputable example : distrib_lattice \u211d\u22650 := by apply_instance\nnoncomputable example : semilattice_inf \u211d\u22650 := by apply_instance\nnoncomputable example : semilattice_sup \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_semiring \u211d\u22650 := by apply_instance\nexample : ordered_comm_semiring \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_comm_monoid  \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_comm_monoid_with_zero \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_comm_group_with_zero \u211d\u22650 := by apply_instance\nexample : canonically_ordered_comm_semiring \u211d\u22650 := by apply_instance\nexample : densely_ordered \u211d\u22650 := by apply_instance\nexample : no_max_order \u211d\u22650 := by apply_instance\n\n/-- If `a` is a nonnegative real number, then the closed interval `[0, a]` in `\u211d` is order\nisomorphic to the interval `set.Iic a`. -/\n@[simps apply_coe_coe] def order_iso_Icc_zero_coe (a : \u211d\u22650) : set.Icc (0 : \u211d) a \u2243o set.Iic a :=\n{ to_equiv := equiv.set.sep (set.Ici 0) (\u03bb x, x \u2264 a),\n  map_rel_iff' := \u03bb x y, iff.rfl }\n\n@[simp] lemma order_iso_Icc_zero_coe_symm_apply_coe (a : \u211d\u22650) (b : set.Iic a) :\n  ((order_iso_Icc_zero_coe a).symm b : \u211d) = b :=\nrfl\n\n-- note we need the `@` to make the `has_mem.mem` have a sensible type\nlemma coe_image {s : set \u211d\u22650} : coe '' s = {x : \u211d | \u2203 h : 0 \u2264 x, @has_mem.mem (\u211d\u22650) _ _ \u27e8x, h\u27e9 s} :=\nsubtype.coe_image\n\nlemma bdd_above_coe {s : set \u211d\u22650} : bdd_above ((coe : \u211d\u22650 \u2192 \u211d) '' s) \u2194 bdd_above s :=\niff.intro\n  (assume \u27e8b, hb\u27e9, \u27e8real.to_nnreal b, assume \u27e8y, hy\u27e9 hys, show y \u2264 max b 0, from\n    le_max_of_le_left $ hb $ set.mem_image_of_mem _ hys\u27e9)\n  (assume \u27e8b, hb\u27e9, \u27e8b, assume y \u27e8x, hx, eq\u27e9, eq \u25b8 hb hx\u27e9)\n\nlemma bdd_below_coe (s : set \u211d\u22650) : bdd_below ((coe : \u211d\u22650 \u2192 \u211d) '' s) :=\n\u27e80, assume r \u27e8q, _, eq\u27e9, eq \u25b8 q.2\u27e9\n\nnoncomputable instance : conditionally_complete_linear_order_bot \u211d\u22650 :=\nnonneg.conditionally_complete_linear_order_bot real.Sup_empty.le\n\n@[norm_cast] lemma coe_Sup (s : set \u211d\u22650) : (\u2191(Sup s) : \u211d) = Sup ((coe : \u211d\u22650 \u2192 \u211d) '' s) :=\neq.symm $ @subset_Sup_of_within \u211d (set.Ici 0) _ \u27e8(0 : \u211d\u22650)\u27e9 s $\n  real.Sup_nonneg _ $ \u03bb y \u27e8x, _, hy\u27e9, hy \u25b8 x.2\n\n@[norm_cast] lemma coe_supr {\u03b9 : Sort*} (s : \u03b9 \u2192 \u211d\u22650) : (\u2191(\u2a06 i, s i) : \u211d) = \u2a06 i, (s i) :=\nby rw [supr, supr, coe_Sup, set.range_comp]\n\n@[norm_cast] lemma coe_Inf (s : set \u211d\u22650) : (\u2191(Inf s) : \u211d) = Inf ((coe : \u211d\u22650 \u2192 \u211d) '' s) :=\neq.symm $ @subset_Inf_of_within \u211d (set.Ici 0) _ \u27e8(0 : \u211d\u22650)\u27e9 s $\n  real.Inf_nonneg _ $ \u03bb y \u27e8x, _, hy\u27e9, hy \u25b8 x.2\n\n@[simp] lemma Inf_empty : Inf (\u2205 : set \u211d\u22650) = 0 :=\nby rw [\u2190 nnreal.coe_eq_zero, coe_Inf, set.image_empty, real.Inf_empty]\n\n@[norm_cast] lemma coe_infi {\u03b9 : Sort*} (s : \u03b9 \u2192 \u211d\u22650) : (\u2191(\u2a05 i, s i) : \u211d) = \u2a05 i, (s i) :=\nby rw [infi, infi, coe_Inf, set.range_comp]\n\nlemma le_infi_add_infi {\u03b9 \u03b9' : Sort*} [nonempty \u03b9] [nonempty \u03b9'] {f : \u03b9 \u2192 \u211d\u22650} {g : \u03b9' \u2192 \u211d\u22650}\n  {a : \u211d\u22650} (h : \u2200 i j, a \u2264 f i + g j) : a \u2264 (\u2a05 i, f i) + \u2a05 j, g j :=\nbegin\n  rw [\u2190 nnreal.coe_le_coe, nnreal.coe_add, coe_infi, coe_infi],\n  exact le_cinfi_add_cinfi h\nend\n\nexample : archimedean \u211d\u22650 := by apply_instance\n\n-- TODO: why are these three instances necessary? why aren't they inferred?\ninstance covariant_add : covariant_class \u211d\u22650 \u211d\u22650 (+) (\u2264) :=\nordered_add_comm_monoid.to_covariant_class_left \u211d\u22650\n\ninstance contravariant_add : contravariant_class \u211d\u22650 \u211d\u22650 (+) (<) :=\nordered_cancel_add_comm_monoid.to_contravariant_class_left \u211d\u22650\n\ninstance covariant_mul : covariant_class \u211d\u22650 \u211d\u22650 (*) (\u2264) :=\nordered_comm_monoid.to_covariant_class_left \u211d\u22650\n\nlemma le_of_forall_pos_le_add {a b : \u211d\u22650} (h : \u2200\u03b5, 0 < \u03b5 \u2192 a \u2264 b + \u03b5) : a \u2264 b :=\nle_of_forall_le_of_dense $ assume x hxb,\nbegin\n  rcases le_iff_exists_add.1 (le_of_lt hxb) with \u27e8\u03b5, rfl\u27e9,\n  exact h _ ((lt_add_iff_pos_right b).1 hxb)\nend\n\n-- TODO: generalize to some ordered add_monoids, based on #6145\nlemma le_of_add_le_left {a b c : \u211d\u22650} (h : a + b \u2264 c) : a \u2264 c :=\nby { refine le_trans _ h, exact (le_add_iff_nonneg_right _).mpr zero_le' }\n\nlemma le_of_add_le_right {a b c : \u211d\u22650} (h : a + b \u2264 c) : b \u2264 c :=\nby { refine le_trans _ h, exact (le_add_iff_nonneg_left _).mpr zero_le' }\n\nlemma lt_iff_exists_rat_btwn (a b : \u211d\u22650) :\n  a < b \u2194 (\u2203q:\u211a, 0 \u2264 q \u2227 a < real.to_nnreal q \u2227 real.to_nnreal q < b) :=\niff.intro\n  (assume (h : (\u2191a:\u211d) < (\u2191b:\u211d)),\n    let \u27e8q, haq, hqb\u27e9 := exists_rat_btwn h in\n    have 0 \u2264 (q : \u211d), from le_trans a.2 $ le_of_lt haq,\n    \u27e8q, rat.cast_nonneg.1 this,\n      by simp [real.coe_to_nnreal _ this, nnreal.coe_lt_coe.symm, haq, hqb]\u27e9)\n  (assume \u27e8q, _, haq, hqb\u27e9, lt_trans haq hqb)\n\nlemma bot_eq_zero : (\u22a5 : \u211d\u22650) = 0 := rfl\n\nlemma mul_sup (a b c : \u211d\u22650) : a * (b \u2294 c) = (a * b) \u2294 (a * c) :=\nmul_max_of_nonneg _ _ $ zero_le a\n\nlemma sup_mul (a b c : \u211d\u22650) : (a \u2294 b) * c = (a * c) \u2294 (b * c) :=\nmax_mul_of_nonneg _ _ $ zero_le c\n\nlemma mul_finset_sup {\u03b1} (r : \u211d\u22650) (s : finset \u03b1) (f : \u03b1 \u2192 \u211d\u22650) :\n  r * s.sup f = s.sup (\u03bb a, r * f a) :=\n(finset.comp_sup_eq_sup_comp _ (nnreal.mul_sup r) (mul_zero r))\n\nlemma finset_sup_mul {\u03b1} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d\u22650) (r : \u211d\u22650) :\n  s.sup f * r = s.sup (\u03bb a, f a * r) :=\n(finset.comp_sup_eq_sup_comp (* r) (\u03bb x y, nnreal.sup_mul x y r) (zero_mul r))\n\nlemma finset_sup_div {\u03b1} {f : \u03b1 \u2192 \u211d\u22650} {s : finset \u03b1} (r : \u211d\u22650) :\n  s.sup f / r = s.sup (\u03bb a, f a / r) :=\nby simp only [div_eq_inv_mul, mul_finset_sup]\n\n@[simp, norm_cast] lemma coe_max (x y : \u211d\u22650) :\n  ((max x y : \u211d\u22650) : \u211d) = max (x : \u211d) (y : \u211d) :=\nnnreal.coe_mono.map_max\n\n@[simp, norm_cast] lemma coe_min (x y : \u211d\u22650) :\n  ((min x y : \u211d\u22650) : \u211d) = min (x : \u211d) (y : \u211d) :=\nnnreal.coe_mono.map_min\n\n@[simp] lemma zero_le_coe {q : \u211d\u22650} : 0 \u2264 (q : \u211d) := q.2\n\nend nnreal\n\nnamespace real\n\nsection to_nnreal\n\n@[simp] lemma to_nnreal_zero : real.to_nnreal 0 = 0 :=\nby simp [real.to_nnreal]; refl\n\n@[simp] lemma to_nnreal_one : real.to_nnreal 1 = 1 :=\nby simp [real.to_nnreal, max_eq_left (zero_le_one : (0 :\u211d) \u2264 1)]; refl\n\n@[simp] lemma to_nnreal_pos {r : \u211d} : 0 < real.to_nnreal r \u2194 0 < r :=\nby simp [real.to_nnreal, nnreal.coe_lt_coe.symm, lt_irrefl]\n\n@[simp] lemma to_nnreal_eq_zero {r : \u211d} : real.to_nnreal r = 0 \u2194 r \u2264 0 :=\nby simpa [-to_nnreal_pos] using (not_iff_not.2 (@to_nnreal_pos r))\n\nlemma to_nnreal_of_nonpos {r : \u211d} : r \u2264 0 \u2192 real.to_nnreal r = 0 :=\nto_nnreal_eq_zero.2\n\n@[simp] lemma coe_to_nnreal' (r : \u211d) : (real.to_nnreal r : \u211d) = max r 0 := rfl\n\n@[simp] lemma to_nnreal_le_to_nnreal_iff {r p : \u211d} (hp : 0 \u2264 p) :\n  real.to_nnreal r \u2264 real.to_nnreal p \u2194 r \u2264 p :=\nby simp [nnreal.coe_le_coe.symm, real.to_nnreal, hp]\n\n@[simp] lemma to_nnreal_lt_to_nnreal_iff' {r p : \u211d} :\n  real.to_nnreal r < real.to_nnreal p \u2194 r < p \u2227 0 < p :=\nnnreal.coe_lt_coe.symm.trans max_lt_max_left_iff\n\nlemma to_nnreal_lt_to_nnreal_iff {r p : \u211d} (h : 0 < p) :\n  real.to_nnreal r < real.to_nnreal p \u2194 r < p :=\nto_nnreal_lt_to_nnreal_iff'.trans (and_iff_left h)\n\nlemma to_nnreal_lt_to_nnreal_iff_of_nonneg {r p : \u211d} (hr : 0 \u2264 r) :\n  real.to_nnreal r < real.to_nnreal p \u2194 r < p :=\nto_nnreal_lt_to_nnreal_iff'.trans \u27e8and.left, \u03bb h, \u27e8h, lt_of_le_of_lt hr h\u27e9\u27e9\n\n@[simp] lemma to_nnreal_add {r p : \u211d} (hr : 0 \u2264 r) (hp : 0 \u2264 p) :\n  real.to_nnreal (r + p) = real.to_nnreal r + real.to_nnreal p :=\nnnreal.eq $ by simp [real.to_nnreal, hr, hp, add_nonneg]\n\nlemma to_nnreal_add_to_nnreal {r p : \u211d} (hr : 0 \u2264 r) (hp : 0 \u2264 p) :\n  real.to_nnreal r + real.to_nnreal p = real.to_nnreal (r + p) :=\n(real.to_nnreal_add hr hp).symm\n\nlemma to_nnreal_le_to_nnreal {r p : \u211d} (h : r \u2264 p) :\n  real.to_nnreal r \u2264 real.to_nnreal p :=\nreal.to_nnreal_mono h\n\nlemma to_nnreal_add_le {r p : \u211d} :\n  real.to_nnreal (r + p) \u2264 real.to_nnreal r + real.to_nnreal p :=\nnnreal.coe_le_coe.1 $ max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) nnreal.zero_le_coe\n\nlemma to_nnreal_le_iff_le_coe {r : \u211d} {p : \u211d\u22650} : real.to_nnreal r \u2264 p \u2194 r \u2264 \u2191p :=\nnnreal.gi.gc r p\n\nlemma le_to_nnreal_iff_coe_le {r : \u211d\u22650} {p : \u211d} (hp : 0 \u2264 p) : r \u2264 real.to_nnreal p \u2194 \u2191r \u2264 p :=\nby rw [\u2190 nnreal.coe_le_coe, real.coe_to_nnreal p hp]\n\nlemma le_to_nnreal_iff_coe_le' {r : \u211d\u22650} {p : \u211d} (hr : 0 < r) : r \u2264 real.to_nnreal p \u2194 \u2191r \u2264 p :=\n(le_or_lt 0 p).elim le_to_nnreal_iff_coe_le $ \u03bb hp,\n  by simp only [(hp.trans_le r.coe_nonneg).not_le, to_nnreal_eq_zero.2 hp.le, hr.not_le]\n\nlemma to_nnreal_lt_iff_lt_coe {r : \u211d} {p : \u211d\u22650} (ha : 0 \u2264 r) : real.to_nnreal r < p \u2194 r < \u2191p :=\nby rw [\u2190 nnreal.coe_lt_coe, real.coe_to_nnreal r ha]\n\nlemma lt_to_nnreal_iff_coe_lt {r : \u211d\u22650} {p : \u211d} : r < real.to_nnreal p \u2194 \u2191r < p :=\nbegin\n  cases le_total 0 p,\n  { rw [\u2190 nnreal.coe_lt_coe, real.coe_to_nnreal p h] },\n  { rw [to_nnreal_eq_zero.2 h], split,\n    { intro, have := not_lt_of_le (zero_le r), contradiction },\n    { intro rp, have : \u00ac(p \u2264 0) := not_le_of_lt (lt_of_le_of_lt (nnreal.coe_nonneg _) rp),\n      contradiction } }\nend\n\n@[simp] lemma to_nnreal_bit0 {r : \u211d} (hr : 0 \u2264 r) :\n  real.to_nnreal (bit0 r) = bit0 (real.to_nnreal r) :=\nreal.to_nnreal_add hr hr\n\n@[simp] lemma to_nnreal_bit1 {r : \u211d} (hr : 0 \u2264 r) :\n  real.to_nnreal (bit1 r) = bit1 (real.to_nnreal r) :=\n(real.to_nnreal_add (by simp [hr]) zero_le_one).trans (by simp [to_nnreal_one, bit1, hr])\n\nend to_nnreal\n\nend real\n\nopen real\n\nnamespace nnreal\n\nsection mul\n\nlemma mul_eq_mul_left {a b c : \u211d\u22650} (h : a \u2260 0) : (a * b = a * c \u2194 b = c) :=\nbegin\n  rw [\u2190 nnreal.eq_iff, \u2190 nnreal.eq_iff, nnreal.coe_mul, nnreal.coe_mul], split,\n  { exact mul_left_cancel\u2080 (mt (@nnreal.eq_iff a 0).1 h) },\n  { assume h, rw [h] }\nend\n\nlemma _root_.real.to_nnreal_mul {p q : \u211d} (hp : 0 \u2264 p) :\n  real.to_nnreal (p * q) = real.to_nnreal p * real.to_nnreal q :=\nbegin\n  cases le_total 0 q with hq hq,\n  { apply nnreal.eq,\n    simp [real.to_nnreal, hp, hq, max_eq_left, mul_nonneg] },\n  { have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq,\n    rw [to_nnreal_eq_zero.2 hq, to_nnreal_eq_zero.2 hpq, mul_zero] }\nend\n\nend mul\n\nsection pow\n\nlemma pow_antitone_exp {a : \u211d\u22650} (m n : \u2115) (mn : m \u2264 n) (a1 : a \u2264 1) :\n  a ^ n \u2264 a ^ m :=\npow_le_pow_of_le_one (zero_le a) a1 mn\n\nlemma exists_pow_lt_of_lt_one {a b : \u211d\u22650} (ha : 0 < a) (hb : b < 1) : \u2203 n : \u2115, b ^ n < a :=\nby simpa only [\u2190 coe_pow, nnreal.coe_lt_coe]\n  using exists_pow_lt_of_lt_one (nnreal.coe_pos.2 ha) (nnreal.coe_lt_coe.2 hb)\n\nlemma exists_mem_Ico_zpow\n  {x : \u211d\u22650} {y : \u211d\u22650} (hx : x \u2260 0) (hy : 1 < y) :\n  \u2203 n : \u2124, x \u2208 set.Ico (y ^ n) (y ^ (n + 1)) :=\nbegin\n  obtain \u27e8n, hn, h'n\u27e9 : \u2203 n : \u2124, (y : \u211d) ^ n \u2264 x \u2227 (x : \u211d) < y ^ (n + 1) :=\n    exists_mem_Ico_zpow (bot_lt_iff_ne_bot.mpr hx) hy,\n  rw \u2190 nnreal.coe_zpow at hn h'n,\n  exact \u27e8n, hn, h'n\u27e9,\nend\n\nlemma exists_mem_Ioc_zpow\n  {x : \u211d\u22650} {y : \u211d\u22650} (hx : x \u2260 0) (hy : 1 < y) :\n  \u2203 n : \u2124, x \u2208 set.Ioc (y ^ n) (y ^ (n + 1)) :=\nbegin\n  obtain \u27e8n, hn, h'n\u27e9 : \u2203 n : \u2124, (y : \u211d) ^ n < x \u2227 (x : \u211d) \u2264 y ^ (n + 1) :=\n    exists_mem_Ioc_zpow (bot_lt_iff_ne_bot.mpr hx) hy,\n  rw \u2190 nnreal.coe_zpow at hn h'n,\n  exact \u27e8n, hn, h'n\u27e9,\nend\n\nend pow\n\nsection sub\n/-!\n### Lemmas about subtraction\n\nIn this section we provide a few lemmas about subtraction that do not fit well into any other\ntypeclass. For lemmas about subtraction and addition see lemmas\nabout `has_ordered_sub` in the file `algebra.order.sub`. See also `mul_tsub` and `tsub_mul`. -/\n\nlemma sub_def {r p : \u211d\u22650} : r - p = real.to_nnreal (r - p) := rfl\n\nlemma coe_sub_def {r p : \u211d\u22650} : \u2191(r - p) = max (r - p : \u211d) 0 := rfl\n\nnoncomputable example : has_ordered_sub \u211d\u22650 := by apply_instance\n\nlemma sub_div (a b c : \u211d\u22650) : (a - b) / c = a / c - b / c :=\nby simp only [div_eq_mul_inv, tsub_mul]\n\nend sub\n\nsection inv\n\nlemma sum_div {\u03b9} (s : finset \u03b9) (f : \u03b9 \u2192 \u211d\u22650) (b : \u211d\u22650) :\n  (\u2211 i in s, f i) / b = \u2211 i in s, (f i / b) :=\nby simp only [div_eq_mul_inv, finset.sum_mul]\n\n@[simp] lemma inv_pos {r : \u211d\u22650} : 0 < r\u207b\u00b9 \u2194 0 < r :=\nby simp [pos_iff_ne_zero]\n\nlemma div_pos {r p : \u211d\u22650} (hr : 0 < r) (hp : 0 < p) : 0 < r / p :=\nby simpa only [div_eq_mul_inv] using mul_pos hr (inv_pos.2 hp)\n\nlemma div_self_le (r : \u211d\u22650) : r / r \u2264 1 := div_self_le_one (r : \u211d)\n\n@[simp] lemma inv_le {r p : \u211d\u22650} (h : r \u2260 0) : r\u207b\u00b9 \u2264 p \u2194 1 \u2264 r * p :=\nby rw [\u2190 mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h]\n\nlemma inv_le_of_le_mul {r p : \u211d\u22650} (h : 1 \u2264 r * p) : r\u207b\u00b9 \u2264 p :=\nby by_cases r = 0; simp [*, inv_le]\n\n@[simp] lemma le_inv_iff_mul_le {r p : \u211d\u22650} (h : p \u2260 0) : (r \u2264 p\u207b\u00b9 \u2194 r * p \u2264 1) :=\nby rw [\u2190 mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]\n\n@[simp] lemma lt_inv_iff_mul_lt {r p : \u211d\u22650} (h : p \u2260 0) : (r < p\u207b\u00b9 \u2194 r * p < 1) :=\nby rw [\u2190 mul_lt_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]\n\nlemma mul_le_iff_le_inv {a b r : \u211d\u22650} (hr : r \u2260 0) : r * a \u2264 b \u2194 a \u2264 r\u207b\u00b9 * b :=\nhave 0 < r, from lt_of_le_of_ne (zero_le r) hr.symm,\nby rw [\u2190 @mul_le_mul_left _ _ a _ r this, \u2190 mul_assoc, mul_inv_cancel hr, one_mul]\n\nlemma le_div_iff_mul_le {a b r : \u211d\u22650} (hr : r \u2260 0) : a \u2264 b / r \u2194 a * r \u2264 b :=\nby rw [div_eq_inv_mul, \u2190 mul_le_iff_le_inv hr, mul_comm]\n\nlemma div_le_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r \u2264 b \u2194 a \u2264 b * r :=\n@div_le_iff \u211d _ a r b $ pos_iff_ne_zero.2 hr\n\nlemma div_le_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r \u2264 b \u2194 a \u2264 r * b :=\n@div_le_iff' \u211d _ a r b $ pos_iff_ne_zero.2 hr\n\nlemma div_le_of_le_mul {a b c : \u211d\u22650} (h : a \u2264 b * c) : a / c \u2264 b :=\nif h0 : c = 0 then by simp [h0] else (div_le_iff h0).2 h\n\nlemma div_le_of_le_mul' {a b c : \u211d\u22650} (h : a \u2264 b * c) : a / b \u2264 c :=\ndiv_le_of_le_mul $ mul_comm b c \u25b8 h\n\nlemma le_div_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a \u2264 b / r \u2194 a * r \u2264 b :=\n@le_div_iff \u211d _ a b r $ pos_iff_ne_zero.2 hr\n\nlemma le_div_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a \u2264 b / r \u2194 r * a \u2264 b :=\n@le_div_iff' \u211d _ a b r $ pos_iff_ne_zero.2 hr\n\nlemma div_lt_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r < b \u2194 a < b * r :=\nlt_iff_lt_of_le_iff_le (le_div_iff hr)\n\nlemma div_lt_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r < b \u2194 a < r * b :=\nlt_iff_lt_of_le_iff_le (le_div_iff' hr)\n\nlemma lt_div_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a < b / r \u2194 a * r < b :=\nlt_iff_lt_of_le_iff_le (div_le_iff hr)\n\nlemma lt_div_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a < b / r \u2194 r * a < b :=\nlt_iff_lt_of_le_iff_le (div_le_iff' hr)\n\nlemma mul_lt_of_lt_div {a b r : \u211d\u22650} (h : a < b / r) : a * r < b :=\nbegin\n  refine (lt_div_iff $ \u03bb hr, false.elim _).1 h,\n  subst r,\n  simpa using h\nend\n\nlemma div_le_div_left_of_le {a b c : \u211d\u22650} (b0 : 0 < b) (c0 : 0 < c) (cb : c \u2264 b) :\n  a / b \u2264 a / c :=\nbegin\n  by_cases a0 : a = 0,\n  { rw [a0, zero_div, zero_div] },\n  { cases a with a ha,\n    replace a0 : 0 < a := lt_of_le_of_ne ha (ne_of_lt (zero_lt_iff.mpr a0)),\n    exact (div_le_div_left a0 b0 c0).mpr cb }\nend\n\nlemma div_le_div_left {a b c : \u211d\u22650} (a0 : 0 < a) (b0 : 0 < b) (c0 : 0 < c) :\n  a / b \u2264 a / c \u2194 c \u2264 b :=\nby rw [nnreal.div_le_iff b0.ne.symm, div_mul_eq_mul_div, nnreal.le_div_iff_mul_le c0.ne.symm,\n  mul_le_mul_left a0]\n\nlemma le_of_forall_lt_one_mul_le {x y : \u211d\u22650} (h : \u2200a<1, a * x \u2264 y) : x \u2264 y :=\nle_of_forall_ge_of_dense $ assume a ha,\n  have hx : x \u2260 0 := pos_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha),\n  have hx' : x\u207b\u00b9 \u2260 0, by rwa [(\u2260), inv_eq_zero],\n  have a * x\u207b\u00b9 < 1, by rwa [\u2190 lt_inv_iff_mul_lt hx', inv_inv],\n  have (a * x\u207b\u00b9) * x \u2264 y, from h _ this,\n  by rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this\n\nlemma div_add_div_same (a b c : \u211d\u22650) : a / c + b / c = (a + b) / c :=\neq.symm $ right_distrib a b (c\u207b\u00b9)\n\nlemma half_pos {a : \u211d\u22650} (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two\n\nlemma add_halves (a : \u211d\u22650) : a / 2 + a / 2 = a := nnreal.eq (add_halves a)\n\nlemma half_le_self (a : \u211d\u22650) : a / 2 \u2264 a := nnreal.coe_le_coe.mp $ half_le_self a.coe_nonneg\n\nlemma half_lt_self {a : \u211d\u22650} (h : a \u2260 0) : a / 2 < a :=\nby rw [\u2190 nnreal.coe_lt_coe, nnreal.coe_div]; exact\nhalf_lt_self (bot_lt_iff_ne_bot.2 h)\n\nlemma two_inv_lt_one : (2\u207b\u00b9:\u211d\u22650) < 1 :=\nby simpa using half_lt_self zero_ne_one.symm\n\nlemma div_lt_one_of_lt {a b : \u211d\u22650} (h : a < b) : a / b < 1 :=\nbegin\n  rwa [div_lt_iff, one_mul],\n  exact ne_of_gt (lt_of_le_of_lt (zero_le _) h)\nend\n\n@[field_simps] lemma div_add_div (a : \u211d\u22650) {b : \u211d\u22650} (c : \u211d\u22650) {d : \u211d\u22650}\n  (hb : b \u2260 0) (hd : d \u2260 0) : a / b + c / d = (a * d + b * c) / (b * d) :=\nbegin\n  rw \u2190 nnreal.eq_iff,\n  simp only [nnreal.coe_add, nnreal.coe_div, nnreal.coe_mul],\n  exact div_add_div _ _ (coe_ne_zero.2 hb) (coe_ne_zero.2 hd)\nend\n\n@[field_simps] lemma add_div' (a b c : \u211d\u22650) (hc : c \u2260 0) :\n  b + a / c = (b * c + a) / c :=\nby simpa using div_add_div b a one_ne_zero hc\n\n@[field_simps] lemma div_add' (a b c : \u211d\u22650) (hc : c \u2260 0) :\n  a / c + b = (a + b * c) / c :=\nby rwa [add_comm, add_div', add_comm]\n\nlemma _root_.real.to_nnreal_inv {x : \u211d} :\n  real.to_nnreal x\u207b\u00b9 = (real.to_nnreal x)\u207b\u00b9 :=\nbegin\n  by_cases hx : 0 \u2264 x,\n  { nth_rewrite 0 \u2190 real.coe_to_nnreal x hx,\n    rw [\u2190nnreal.coe_inv, real.to_nnreal_coe], },\n  { have hx' := le_of_not_ge hx,\n    rw [to_nnreal_eq_zero.mpr hx', inv_zero, to_nnreal_eq_zero.mpr (inv_nonpos.mpr hx')], },\nend\n\nlemma _root_.real.to_nnreal_div {x y : \u211d} (hx : 0 \u2264 x) :\n  real.to_nnreal (x / y) = real.to_nnreal x / real.to_nnreal y :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, \u2190 real.to_nnreal_inv, \u2190 real.to_nnreal_mul hx]\n\nlemma _root_.real.to_nnreal_div' {x y : \u211d} (hy : 0 \u2264 y) :\n  real.to_nnreal (x / y) = real.to_nnreal x / real.to_nnreal y :=\nby rw [div_eq_inv_mul, div_eq_inv_mul, real.to_nnreal_mul (inv_nonneg.2 hy), real.to_nnreal_inv]\n\nlemma inv_lt_one_iff {x : \u211d\u22650} (hx : x \u2260 0) : x\u207b\u00b9 < 1 \u2194 1 < x :=\nby rwa [\u2190 one_div, div_lt_iff hx, one_mul]\n\nlemma inv_lt_one {x : \u211d\u22650} (hx : 1 < x) : x\u207b\u00b9 < 1 :=\n(inv_lt_one_iff (zero_lt_one.trans hx).ne').2 hx\n\nlemma zpow_pos {x : \u211d\u22650} (hx : x \u2260 0) (n : \u2124) : 0 < x ^ n :=\nbegin\n  cases n,\n  { simp [pow_pos hx.bot_lt _] },\n  { simp [pow_pos hx.bot_lt _] }\nend\n\nlemma inv_lt_inv_iff {x y : \u211d\u22650} (hx : x \u2260 0) (hy : y \u2260 0) :\n  y\u207b\u00b9 < x\u207b\u00b9 \u2194 x < y :=\nby rw [\u2190 one_div, div_lt_iff hy, \u2190 div_eq_inv_mul, lt_div_iff hx, one_mul]\n\nlemma inv_lt_inv {x y : \u211d\u22650} (hx : x \u2260 0) (h : x < y) : y\u207b\u00b9 < x\u207b\u00b9 :=\n(inv_lt_inv_iff hx ((bot_le.trans_lt h).ne')).2 h\n\nend inv\n\n@[simp] lemma abs_eq (x : \u211d\u22650) : |(x : \u211d)| = x :=\nabs_of_nonneg x.property\n\nsection csupr\nopen set\n\nvariables {\u03b9 : Sort*} {f : \u03b9 \u2192 \u211d\u22650}\n\nlemma le_to_nnreal_of_coe_le {x : \u211d\u22650} {y : \u211d} (h : \u2191x \u2264 y) : x \u2264 y.to_nnreal :=\n(le_to_nnreal_iff_coe_le $ x.2.trans h).2 h\n\nlemma Sup_of_not_bdd_above {s : set \u211d\u22650} (hs : \u00acbdd_above s) : has_Sup.Sup s = 0 :=\nbegin\n  rw [\u2190 bdd_above_coe] at hs,\n  rw [\u2190 nnreal.coe_eq, coe_Sup],\n  exact Sup_of_not_bdd_above hs,\nend\n\nlemma supr_of_not_bdd_above (hf : \u00ac bdd_above (range f)) : (\u2a06 i, f i) = 0 :=\nSup_of_not_bdd_above hf\n\nlemma infi_empty [is_empty \u03b9] (f : \u03b9 \u2192 \u211d\u22650) : (\u2a05 i, f i) = 0 :=\nby { rw [\u2190 nnreal.coe_eq, coe_infi], exact real.cinfi_empty _, }\n\n@[simp] lemma infi_const_zero {\u03b1 : Sort*} : (\u2a05 i : \u03b1, (0 : \u211d\u22650)) = 0 :=\nby { rw [\u2190 nnreal.coe_eq, coe_infi], exact real.cinfi_const_zero, }\n\nlemma infi_mul (f : \u03b9 \u2192 \u211d\u22650) (a : \u211d\u22650)  : infi f * a = \u2a05 i, f i * a :=\nbegin\n  rw [\u2190 nnreal.coe_eq, nnreal.coe_mul, coe_infi, coe_infi],\n  exact real.infi_mul_of_nonneg (nnreal.coe_nonneg _) _,\nend\n\nlemma mul_infi (f : \u03b9 \u2192 \u211d\u22650) (a : \u211d\u22650) : a * infi f = \u2a05 i, a * f i :=\nby simpa only [mul_comm] using infi_mul f a\n\nlemma mul_supr (f : \u03b9 \u2192 \u211d\u22650) (a : \u211d\u22650) : a * (\u2a06 i, f i) = \u2a06 i, a * f i :=\nbegin\n  rw [\u2190 nnreal.coe_eq, nnreal.coe_mul, nnreal.coe_supr, nnreal.coe_supr],\n  exact real.mul_supr_of_nonneg (nnreal.coe_nonneg _) _,\nend\n\nlemma supr_mul (f : \u03b9 \u2192 \u211d\u22650) (a : \u211d\u22650) : (\u2a06 i, f i) * a = \u2a06 i, f i * a :=\nby { rw [mul_comm, mul_supr], simp_rw [mul_comm] }\n\nlemma supr_div (f : \u03b9 \u2192 \u211d\u22650) (a : \u211d\u22650) : (\u2a06 i, f i) / a = \u2a06 i, f i / a :=\nby simp only [div_eq_mul_inv, supr_mul]\n\nvariable [nonempty \u03b9]\n\nlemma le_mul_infi {a : \u211d\u22650} {g : \u211d\u22650} {h : \u03b9 \u2192 \u211d\u22650} (H : \u2200 j, a \u2264 g * h j) : a \u2264 g * infi h :=\nby { rw [mul_infi], exact le_cinfi H }\n\nlemma mul_supr_le {a : \u211d\u22650} {g : \u211d\u22650} {h : \u03b9 \u2192 \u211d\u22650} (H : \u2200 j, g * h j \u2264 a) : g * supr h \u2264 a :=\nby { rw [mul_supr], exact csupr_le H }\n\nlemma le_infi_mul {a : \u211d\u22650} {g : \u03b9 \u2192 \u211d\u22650} {h : \u211d\u22650} (H : \u2200 i, a \u2264 g i * h) : a \u2264 infi g * h :=\nby { rw infi_mul, exact le_cinfi H }\n\nlemma supr_mul_le {a : \u211d\u22650} {g : \u03b9 \u2192 \u211d\u22650} {h : \u211d\u22650} (H : \u2200 i, g i * h \u2264 a) : supr g * h \u2264 a :=\nby { rw supr_mul, exact csupr_le H }\n\nlemma le_infi_mul_infi {a : \u211d\u22650} {g h : \u03b9 \u2192 \u211d\u22650} (H : \u2200 i j, a \u2264 g i * h j) :\n  a \u2264 infi g * infi h :=\nle_infi_mul  $ \u03bb i, le_mul_infi $ H i\n\nlemma supr_mul_supr_le {a : \u211d\u22650} {g h : \u03b9 \u2192 \u211d\u22650} (H : \u2200 i j, g i * h j \u2264 a) :\n  supr g * supr h \u2264 a :=\nsupr_mul_le $ \u03bb i, mul_supr_le $ H _\n\nend csupr\n\nend nnreal\n\nnamespace real\n\n/-- The absolute value on `\u211d` as a map to `\u211d\u22650`. -/\n@[pp_nodot] noncomputable def nnabs : \u211d \u2192*\u2080 \u211d\u22650 :=\n{ to_fun := \u03bb x, \u27e8|x|, abs_nonneg x\u27e9,\n  map_zero' := by { ext, simp },\n  map_one' := by { ext, simp },\n  map_mul' := \u03bb x y, by { ext, simp [abs_mul] } }\n\n@[norm_cast, simp] lemma coe_nnabs (x : \u211d) : (nnabs x : \u211d) = |x| :=\nrfl\n\n@[simp] lemma nnabs_of_nonneg {x : \u211d} (h : 0 \u2264 x) : nnabs x = to_nnreal x :=\nby { ext, simp [coe_to_nnreal x h, abs_of_nonneg h] }\n\nlemma coe_to_nnreal_le (x : \u211d) : (to_nnreal x : \u211d) \u2264 |x| :=\nmax_le (le_abs_self _) (abs_nonneg _)\n\nlemma cast_nat_abs_eq_nnabs_cast (n : \u2124) :\n  (n.nat_abs : \u211d\u22650) = nnabs n :=\nby { ext, rw [nnreal.coe_nat_cast, int.cast_nat_abs, real.coe_nnabs] }\n\nend real\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/real/nnreal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7110372701759918}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport topology.continuous_function.bounded\nimport topology.uniform_space.compact_separated\nimport topology.compact_open\nimport topology.sets.compacts\n\n/-!\n# Continuous functions on a compact space\n\nContinuous functions `C(\u03b1, \u03b2)` from a compact space `\u03b1` to a metric space `\u03b2`\nare automatically bounded, and so acquire various structures inherited from `\u03b1 \u2192\u1d47 \u03b2`.\n\nThis file transfers these structures, and restates some lemmas\ncharacterising these structures.\n\nIf you need a lemma which is proved about `\u03b1 \u2192\u1d47 \u03b2` but not for `C(\u03b1, \u03b2)` when `\u03b1` is compact,\nyou should restate it here. You can also use\n`bounded_continuous_function.equiv_continuous_map_of_compact` to move functions back and forth.\n\n-/\n\nnoncomputable theory\nopen_locale topological_space classical nnreal bounded_continuous_function big_operators\n\nopen set filter metric\n\nopen bounded_continuous_function\n\nnamespace continuous_map\n\nvariables {\u03b1 \u03b2 E : Type*} [topological_space \u03b1] [compact_space \u03b1] [metric_space \u03b2] [normed_group E]\n\nsection\n\nvariables (\u03b1 \u03b2)\n\n/--\nWhen `\u03b1` is compact, the bounded continuous maps `\u03b1 \u2192\u1d47 \u03b2` are\nequivalent to `C(\u03b1, \u03b2)`.\n-/\n@[simps { fully_applied := ff }]\ndef equiv_bounded_of_compact : C(\u03b1, \u03b2) \u2243 (\u03b1 \u2192\u1d47 \u03b2) :=\n\u27e8mk_of_compact, bounded_continuous_function.to_continuous_map,\n \u03bb f, by { ext, refl, }, \u03bb f, by { ext, refl, }\u27e9\n\nlemma uniform_inducing_equiv_bounded_of_compact :\n  uniform_inducing (equiv_bounded_of_compact \u03b1 \u03b2) :=\nuniform_inducing.mk'\nbegin\n  simp only [has_basis_compact_convergence_uniformity.mem_iff, uniformity_basis_dist_le.mem_iff],\n  exact \u03bb s, \u27e8\u03bb \u27e8\u27e8a, b\u27e9, \u27e8ha, \u27e8\u03b5, h\u03b5, hb\u27e9\u27e9, hs\u27e9, \u27e8{p | \u2200 x, (p.1 x, p.2 x) \u2208 b},\n    \u27e8\u03b5, h\u03b5, \u03bb _ h x, hb (by exact (dist_le h\u03b5.le).mp h x)\u27e9, \u03bb f g h, hs (by exact \u03bb x hx, h x)\u27e9,\n    \u03bb \u27e8t, \u27e8\u03b5, h\u03b5, ht\u27e9, hs\u27e9, \u27e8\u27e8set.univ, {p | dist p.1 p.2 \u2264 \u03b5}\u27e9, \u27e8compact_univ, \u27e8\u03b5, h\u03b5, \u03bb _ h, h\u27e9\u27e9,\n    \u03bb \u27e8f, g\u27e9 h, hs _ _ (ht (by exact (dist_le h\u03b5.le).mpr (\u03bb x, h x (mem_univ x))))\u27e9\u27e9,\nend\n\nlemma uniform_embedding_equiv_bounded_of_compact :\n  uniform_embedding (equiv_bounded_of_compact \u03b1 \u03b2) :=\n{ inj := (equiv_bounded_of_compact \u03b1 \u03b2).injective,\n  .. uniform_inducing_equiv_bounded_of_compact \u03b1 \u03b2 }\n\n/--\nWhen `\u03b1` is compact, the bounded continuous maps `\u03b1 \u2192\u1d47 \ud835\udd5c` are\nadditively equivalent to `C(\u03b1, \ud835\udd5c)`.\n-/\n@[simps apply symm_apply { fully_applied := ff }]\ndef add_equiv_bounded_of_compact [add_monoid \u03b2] [has_lipschitz_add \u03b2] :\n  C(\u03b1, \u03b2) \u2243+ (\u03b1 \u2192\u1d47 \u03b2) :=\n({ .. to_continuous_map_add_hom \u03b1 \u03b2,\n   .. (equiv_bounded_of_compact \u03b1 \u03b2).symm, } : (\u03b1 \u2192\u1d47 \u03b2) \u2243+ C(\u03b1, \u03b2)).symm\n\ninstance : metric_space C(\u03b1, \u03b2) :=\n(uniform_embedding_equiv_bounded_of_compact \u03b1 \u03b2).comap_metric_space _\n\n/--\nWhen `\u03b1` is compact, and `\u03b2` is a metric space, the bounded continuous maps `\u03b1 \u2192\u1d47 \u03b2` are\nisometric to `C(\u03b1, \u03b2)`.\n-/\n@[simps to_equiv apply symm_apply { fully_applied := ff }]\ndef isometric_bounded_of_compact :\n  C(\u03b1, \u03b2) \u2243\u1d62 (\u03b1 \u2192\u1d47 \u03b2) :=\n{ isometry_to_fun := \u03bb x y, rfl,\n  to_equiv := equiv_bounded_of_compact \u03b1 \u03b2 }\n\nend\n\n@[simp] lemma _root_.bounded_continuous_function.dist_mk_of_compact (f g : C(\u03b1, \u03b2)) :\n  dist (mk_of_compact f) (mk_of_compact g) = dist f g := rfl\n\n@[simp] lemma _root_.bounded_continuous_function.dist_to_continuous_map (f g : \u03b1 \u2192\u1d47 \u03b2) :\n  dist (f.to_continuous_map) (g.to_continuous_map) = dist f g := rfl\n\nopen bounded_continuous_function\n\nsection\nvariables {\u03b1 \u03b2} {f g : C(\u03b1, \u03b2)} {C : \u211d}\n\n/-- The pointwise distance is controlled by the distance between functions, by definition. -/\nlemma dist_apply_le_dist (x : \u03b1) : dist (f x) (g x) \u2264 dist f g :=\nby simp only [\u2190 dist_mk_of_compact, dist_coe_le_dist, \u2190 mk_of_compact_apply]\n\n/-- The distance between two functions is controlled by the supremum of the pointwise distances -/\nlemma dist_le (C0 : (0 : \u211d) \u2264 C) : dist f g \u2264 C \u2194 \u2200x:\u03b1, dist (f x) (g x) \u2264 C :=\nby simp only [\u2190 dist_mk_of_compact, dist_le C0, mk_of_compact_apply]\n\nlemma dist_le_iff_of_nonempty [nonempty \u03b1] :\n  dist f g \u2264 C \u2194 \u2200 x, dist (f x) (g x) \u2264 C :=\nby simp only [\u2190 dist_mk_of_compact, dist_le_iff_of_nonempty, mk_of_compact_apply]\n\nlemma dist_lt_iff_of_nonempty [nonempty \u03b1] :\n  dist f g < C \u2194 \u2200x:\u03b1, dist (f x) (g x) < C :=\nby simp only [\u2190 dist_mk_of_compact, dist_lt_iff_of_nonempty_compact, mk_of_compact_apply]\n\nlemma dist_lt_of_nonempty [nonempty \u03b1] (w : \u2200x:\u03b1, dist (f x) (g x) < C) : dist f g < C :=\n(dist_lt_iff_of_nonempty).2 w\n\nlemma dist_lt_iff (C0 : (0 : \u211d) < C) :\n  dist f g < C \u2194 \u2200x:\u03b1, dist (f x) (g x) < C :=\nby simp only [\u2190 dist_mk_of_compact, dist_lt_iff_of_compact C0, mk_of_compact_apply]\n\nend\n\ninstance [complete_space \u03b2] : complete_space (C(\u03b1, \u03b2)) :=\n(isometric_bounded_of_compact \u03b1 \u03b2).complete_space\n\n/-- See also `continuous_map.continuous_eval'` -/\n@[continuity] lemma continuous_eval : continuous (\u03bb p : C(\u03b1, \u03b2) \u00d7 \u03b1, p.1 p.2) :=\ncontinuous_eval.comp ((isometric_bounded_of_compact \u03b1 \u03b2).continuous.prod_map continuous_id)\n\n/-- See also `continuous_map.continuous_eval_const` -/\n@[continuity] lemma continuous_eval_const (x : \u03b1) : continuous (\u03bb f : C(\u03b1, \u03b2), f x) :=\ncontinuous_eval.comp (continuous_id.prod_mk continuous_const)\n\n/-- See also `continuous_map.continuous_coe'` -/\nlemma continuous_coe : @continuous (C(\u03b1, \u03b2)) (\u03b1 \u2192 \u03b2) _ _ coe_fn :=\ncontinuous_pi continuous_eval_const\n\n-- TODO at some point we will need lemmas characterising this norm!\n-- At the moment the only way to reason about it is to transfer `f : C(\u03b1,E)` back to `\u03b1 \u2192\u1d47 E`.\ninstance : has_norm C(\u03b1, E) :=\n{ norm := \u03bb x, dist x 0 }\n\n@[simp] lemma _root_.bounded_continuous_function.norm_mk_of_compact (f : C(\u03b1, E)) :\n  \u2225mk_of_compact f\u2225 = \u2225f\u2225 := rfl\n\n@[simp] lemma _root_.bounded_continuous_function.norm_to_continuous_map_eq (f : \u03b1 \u2192\u1d47 E) :\n  \u2225f.to_continuous_map\u2225 = \u2225f\u2225 :=\nrfl\n\nopen bounded_continuous_function\n\ninstance : normed_group C(\u03b1, E) :=\n{ dist_eq := \u03bb x y, by\n    rw [\u2190 norm_mk_of_compact, \u2190 dist_mk_of_compact, dist_eq_norm, mk_of_compact_sub],\n  dist := dist, norm := norm, .. continuous_map.metric_space _ _, .. continuous_map.add_comm_group }\n\nsection\nvariables (f : C(\u03b1, E))\n-- The corresponding lemmas for `bounded_continuous_function` are stated with `{f}`,\n-- and so can not be used in dot notation.\n\nlemma norm_coe_le_norm (x : \u03b1) : \u2225f x\u2225 \u2264 \u2225f\u2225 :=\n(mk_of_compact f).norm_coe_le_norm x\n\n/-- Distance between the images of any two points is at most twice the norm of the function. -/\nlemma dist_le_two_norm (x y : \u03b1) : dist (f x) (f y) \u2264 2 * \u2225f\u2225 :=\n(mk_of_compact f).dist_le_two_norm x y\n\n/-- The norm of a function is controlled by the supremum of the pointwise norms -/\nlemma norm_le {C : \u211d} (C0 : (0 : \u211d) \u2264 C) : \u2225f\u2225 \u2264 C \u2194 \u2200x:\u03b1, \u2225f x\u2225 \u2264 C :=\n@bounded_continuous_function.norm_le _ _ _ _\n  (mk_of_compact f) _ C0\n\nlemma norm_le_of_nonempty [nonempty \u03b1] {M : \u211d} : \u2225f\u2225 \u2264 M \u2194 \u2200 x, \u2225f x\u2225 \u2264 M :=\n@bounded_continuous_function.norm_le_of_nonempty _ _ _ _ _ (mk_of_compact f) _\n\nlemma norm_lt_iff {M : \u211d} (M0 : 0 < M) : \u2225f\u2225 < M \u2194 \u2200 x, \u2225f x\u2225 < M :=\n@bounded_continuous_function.norm_lt_iff_of_compact _ _ _ _ _ (mk_of_compact f) _ M0\n\nlemma norm_lt_iff_of_nonempty [nonempty \u03b1] {M : \u211d} :\n  \u2225f\u2225 < M \u2194 \u2200 x, \u2225f x\u2225 < M :=\n@bounded_continuous_function.norm_lt_iff_of_nonempty_compact _ _ _ _ _ _ (mk_of_compact f) _\n\nlemma apply_le_norm (f : C(\u03b1, \u211d)) (x : \u03b1) : f x \u2264 \u2225f\u2225 :=\nle_trans (le_abs.mpr (or.inl (le_refl (f x)))) (f.norm_coe_le_norm x)\n\nlemma neg_norm_le_apply (f : C(\u03b1, \u211d)) (x : \u03b1) : -\u2225f\u2225 \u2264 f x :=\nle_trans (neg_le_neg (f.norm_coe_le_norm x)) (neg_le.mp (neg_le_abs_self (f x)))\n\nlemma norm_eq_supr_norm : \u2225f\u2225 = \u2a06 x : \u03b1, \u2225f x\u2225 :=\n(mk_of_compact f).norm_eq_supr_norm\n\nend\n\nsection\nvariables {R : Type*} [normed_ring R]\n\ninstance : normed_ring C(\u03b1,R) :=\n{ norm_mul := \u03bb f g, norm_mul_le (mk_of_compact f) (mk_of_compact g),\n  ..(infer_instance : normed_group C(\u03b1,R)),\n  .. continuous_map.ring }\n\nend\n\nsection\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [normed_space \ud835\udd5c E]\n\ninstance : normed_space \ud835\udd5c C(\u03b1,E) :=\n{ norm_smul_le := \u03bb c f, le_of_eq (norm_smul c (mk_of_compact f)) }\n\nsection\nvariables (\u03b1 \ud835\udd5c E)\n\n/--\nWhen `\u03b1` is compact and `\ud835\udd5c` is a normed field,\nthe `\ud835\udd5c`-algebra of bounded continuous maps `\u03b1 \u2192\u1d47 \u03b2` is\n`\ud835\udd5c`-linearly isometric to `C(\u03b1, \u03b2)`.\n-/\ndef linear_isometry_bounded_of_compact :\n  C(\u03b1, E) \u2243\u2097\u1d62[\ud835\udd5c] (\u03b1 \u2192\u1d47 E) :=\n{ map_smul' := \u03bb c f, by { ext, simp, },\n  norm_map' := \u03bb f, rfl,\n  .. add_equiv_bounded_of_compact \u03b1 E }\n\nend\n\n-- this lemma and the next are the analogues of those autogenerated by `@[simps]` for\n-- `equiv_bounded_of_compact`, `add_equiv_bounded_of_compact`\n@[simp] lemma linear_isometry_bounded_of_compact_symm_apply (f : \u03b1 \u2192\u1d47 E) :\n  (linear_isometry_bounded_of_compact \u03b1 E \ud835\udd5c).symm f = f.to_continuous_map :=\nrfl\n\n@[simp] lemma linear_isometry_bounded_of_compact_apply_apply (f : C(\u03b1, E)) (a : \u03b1) :\n  (linear_isometry_bounded_of_compact \u03b1 E \ud835\udd5c f) a = f a :=\nrfl\n\n\n@[simp]\nlemma linear_isometry_bounded_of_compact_to_isometric :\n  (linear_isometry_bounded_of_compact \u03b1 E \ud835\udd5c).to_isometric = (isometric_bounded_of_compact \u03b1 E) :=\nrfl\n\n@[simp]\nlemma linear_isometry_bounded_of_compact_to_add_equiv :\n  (linear_isometry_bounded_of_compact \u03b1 E \ud835\udd5c).to_linear_equiv.to_add_equiv =\n    (add_equiv_bounded_of_compact \u03b1 E) :=\nrfl\n\n@[simp]\nlemma linear_isometry_bounded_of_compact_of_compact_to_equiv :\n  (linear_isometry_bounded_of_compact \u03b1 E \ud835\udd5c).to_linear_equiv.to_equiv =\n    (equiv_bounded_of_compact \u03b1 E) :=\nrfl\n\nend\n\nsection\nvariables {\ud835\udd5c : Type*} {\u03b3 : Type*} [normed_field \ud835\udd5c] [normed_ring \u03b3] [normed_algebra \ud835\udd5c \u03b3]\n\ninstance : normed_algebra \ud835\udd5c C(\u03b1, \u03b3) :=\n{ ..continuous_map.normed_space }\n\nend\n\nend continuous_map\n\nnamespace continuous_map\n\nsection uniform_continuity\nvariables {\u03b1 \u03b2 : Type*}\nvariables [metric_space \u03b1] [compact_space \u03b1] [metric_space \u03b2]\n\n/-!\nWe now set up some declarations making it convenient to use uniform continuity.\n-/\n\nlemma uniform_continuity\n  (f : C(\u03b1, \u03b2)) (\u03b5 : \u211d) (h : 0 < \u03b5) :\n  \u2203 \u03b4 > 0, \u2200 {x y}, dist x y < \u03b4 \u2192 dist (f x) (f y) < \u03b5 :=\nmetric.uniform_continuous_iff.mp\n  (compact_space.uniform_continuous_of_continuous f.continuous) \u03b5 h\n\n/--\nAn arbitrarily chosen modulus of uniform continuity for a given function `f` and `\u03b5 > 0`.\n-/\n-- This definition allows us to separate the choice of some `\u03b4`,\n-- and the corresponding use of `dist a b < \u03b4 \u2192 dist (f a) (f b) < \u03b5`,\n-- even across different declarations.\ndef modulus (f : C(\u03b1, \u03b2)) (\u03b5 : \u211d) (h : 0 < \u03b5) : \u211d :=\nclassical.some (uniform_continuity f \u03b5 h)\n\nlemma modulus_pos (f : C(\u03b1, \u03b2)) {\u03b5 : \u211d} {h : 0 < \u03b5} : 0 < f.modulus \u03b5 h :=\n(classical.some_spec (uniform_continuity f \u03b5 h)).fst\n\nlemma dist_lt_of_dist_lt_modulus\n  (f : C(\u03b1, \u03b2)) (\u03b5 : \u211d) (h : 0 < \u03b5) {a b : \u03b1} (w : dist a b < f.modulus \u03b5 h) :\n  dist (f a) (f b) < \u03b5 :=\n(classical.some_spec (uniform_continuity f \u03b5 h)).snd w\n\nend uniform_continuity\n\nend continuous_map\n\nsection comp_left\nvariables (X : Type*) {\ud835\udd5c \u03b2 \u03b3 : Type*} [topological_space X] [compact_space X]\n  [nondiscrete_normed_field \ud835\udd5c]\nvariables [normed_group \u03b2] [normed_space \ud835\udd5c \u03b2] [normed_group \u03b3] [normed_space \ud835\udd5c \u03b3]\n\nopen continuous_map\n\n/--\nPostcomposition of continuous functions into a normed module by a continuous linear map is a\ncontinuous linear map.\nTransferred version of `continuous_linear_map.comp_left_continuous_bounded`,\nupgraded version of `continuous_linear_map.comp_left_continuous`,\nsimilar to `linear_map.comp_left`. -/\nprotected def continuous_linear_map.comp_left_continuous_compact (g : \u03b2 \u2192L[\ud835\udd5c] \u03b3) :\n  C(X, \u03b2) \u2192L[\ud835\udd5c] C(X, \u03b3) :=\n(linear_isometry_bounded_of_compact X \u03b3 \ud835\udd5c).symm.to_linear_isometry.to_continuous_linear_map.comp $\n(g.comp_left_continuous_bounded X).comp $\n(linear_isometry_bounded_of_compact X \u03b2 \ud835\udd5c).to_linear_isometry.to_continuous_linear_map\n\n@[simp] lemma continuous_linear_map.to_linear_comp_left_continuous_compact (g : \u03b2 \u2192L[\ud835\udd5c] \u03b3) :\n  (g.comp_left_continuous_compact X : C(X, \u03b2) \u2192\u2097[\ud835\udd5c] C(X, \u03b3)) = g.comp_left_continuous \ud835\udd5c X :=\nby { ext f, refl }\n\n@[simp] lemma continuous_linear_map.comp_left_continuous_compact_apply (g : \u03b2 \u2192L[\ud835\udd5c] \u03b3)\n  (f : C(X, \u03b2)) (x : X) :\n  g.comp_left_continuous_compact X f x = g (f x) :=\nrfl\n\nend comp_left\n\nnamespace continuous_map\n/-!\nWe now setup variations on `comp_right_* f`, where `f : C(X, Y)`\n(that is, precomposition by a continuous map),\nas a morphism `C(Y, T) \u2192 C(X, T)`, respecting various types of structure.\n\nIn particular:\n* `comp_right_continuous_map`, the bundled continuous map (for this we need `X Y` compact).\n* `comp_right_homeomorph`, when we precompose by a homeomorphism.\n* `comp_right_alg_hom`, when `T = R` is a topological ring.\n-/\nsection comp_right\n\n/--\nPrecomposition by a continuous map is itself a continuous map between spaces of continuous maps.\n-/\ndef comp_right_continuous_map {X Y : Type*} (T : Type*)\n  [topological_space X] [compact_space X] [topological_space Y] [compact_space Y] [normed_group T]\n  (f : C(X, Y)) : C(C(Y, T), C(X, T)) :=\n{ to_fun := \u03bb g, g.comp f,\n  continuous_to_fun :=\n  begin\n    refine metric.continuous_iff.mpr _,\n    intros g \u03b5 \u03b5_pos,\n    refine \u27e8\u03b5, \u03b5_pos, \u03bb g' h, _\u27e9,\n    rw continuous_map.dist_lt_iff \u03b5_pos at h \u22a2,\n    { exact \u03bb x, h (f x), },\n  end }\n\n@[simp] lemma comp_right_continuous_map_apply {X Y : Type*} (T : Type*)\n  [topological_space X] [compact_space X] [topological_space Y] [compact_space Y] [normed_group T]\n  (f : C(X, Y)) (g : C(Y, T)) :\n  (comp_right_continuous_map T f) g = g.comp f :=\nrfl\n\n/--\nPrecomposition by a homeomorphism is itself a homeomorphism between spaces of continuous maps.\n-/\ndef comp_right_homeomorph {X Y : Type*} (T : Type*)\n  [topological_space X] [compact_space X] [topological_space Y] [compact_space Y] [normed_group T]\n  (f : X \u2243\u209c Y) : C(Y, T) \u2243\u209c C(X, T) :=\n{ to_fun := comp_right_continuous_map T f.to_continuous_map,\n  inv_fun := comp_right_continuous_map T f.symm.to_continuous_map,\n  left_inv := by tidy,\n  right_inv := by tidy, }\n\n/--\nPrecomposition of functions into a normed ring by continuous map is an algebra homomorphism.\n-/\ndef comp_right_alg_hom {X Y : Type*} (R : Type*)\n  [topological_space X] [topological_space Y] [normed_comm_ring R] (f : C(X, Y)) :\n  C(Y, R) \u2192\u2090[R] C(X, R) :=\n{ to_fun := \u03bb g, g.comp f,\n  map_zero' := by { ext, simp, },\n  map_add' := \u03bb g\u2081 g\u2082, by { ext, simp, },\n  map_one' := by { ext, simp, },\n  map_mul' := \u03bb g\u2081 g\u2082, by { ext, simp, },\n  commutes' := \u03bb r, by { ext, simp, }, }\n\n@[simp] lemma comp_right_alg_hom_apply {X Y : Type*} (R : Type*)\n  [topological_space X] [topological_space Y] [normed_comm_ring R] (f : C(X, Y)) (g : C(Y, R)) :\n  (comp_right_alg_hom R f) g = g.comp f :=\nrfl\n\nlemma comp_right_alg_hom_continuous {X Y : Type*} (R : Type*)\n  [topological_space X] [compact_space X] [topological_space Y] [compact_space Y]\n  [normed_comm_ring R] (f : C(X, Y)) :\n  continuous (comp_right_alg_hom R f) :=\nbegin\n  change continuous (comp_right_continuous_map R f),\n  continuity,\nend\n\nend comp_right\n\nsection weierstrass\n\nopen topological_space\n\nvariables {X : Type*} [topological_space X] [t2_space X] [locally_compact_space X]\nvariables {E : Type*} [normed_group E] [complete_space E]\n\nlemma summable_of_locally_summable_norm {\u03b9 : Type*} {F : \u03b9 \u2192 C(X, E)}\n  (hF : \u2200 K : compacts X, summable (\u03bb i, \u2225(F i).restrict K\u2225)) :\n  summable F :=\nbegin\n  refine (continuous_map.exists_tendsto_compact_open_iff_forall _).2 (\u03bb K hK, _),\n  lift K to compacts X using hK,\n  have A : \u2200 s : finset \u03b9, restrict \u2191K (\u2211 i in s, F i) = \u2211 i in s, restrict K (F i),\n  { intro s, ext1 x, simp },\n  simpa only [has_sum, A] using summable_of_summable_norm (hF K)\nend\n\nend weierstrass\n\n\n/-!\n### Star structures\n\nIn this section, if `\u03b2` is a normed \u22c6-group, then so is the space of\ncontinuous functions from `\u03b1` to `\u03b2`, by using the star operation pointwise.\n\nFurthermore, if `\u03b1` is compact and `\u03b2` is a C\u22c6-ring, then `C(\u03b1, \u03b2)` is a C\u22c6-ring.  -/\n\nsection normed_space\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariables [topological_space \u03b1] [normed_group \u03b2] [star_add_monoid \u03b2] [normed_star_group \u03b2]\n\nlemma _root_.bounded_continuous_function.mk_of_compact_star [compact_space \u03b1] (f : C(\u03b1, \u03b2)) :\n  mk_of_compact (star f) = star (mk_of_compact f) := rfl\n\ninstance [compact_space \u03b1] : normed_star_group C(\u03b1, \u03b2) :=\n{ norm_star := \u03bb f, by rw [\u2190bounded_continuous_function.norm_mk_of_compact,\n                          bounded_continuous_function.mk_of_compact_star, norm_star,\n                          bounded_continuous_function.norm_mk_of_compact] }\n\nend normed_space\n\nsection cstar_ring\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariables [topological_space \u03b1] [normed_ring \u03b2] [star_ring \u03b2]\n\ninstance [compact_space \u03b1] [cstar_ring \u03b2] : cstar_ring C(\u03b1, \u03b2) :=\n{ norm_star_mul_self :=\n  begin\n    intros f,\n    refine le_antisymm _ _,\n    { rw [\u2190sq, continuous_map.norm_le _ (sq_nonneg _)],\n      intro x,\n      simp only [continuous_map.coe_mul, coe_star, pi.mul_apply, pi.star_apply,\n                 cstar_ring.norm_star_mul_self, \u2190sq],\n      refine sq_le_sq' _ _,\n      { linarith [norm_nonneg (f x), norm_nonneg f] },\n      { exact continuous_map.norm_coe_le_norm f x }, },\n    { rw [\u2190sq, \u2190real.le_sqrt (norm_nonneg _) (norm_nonneg _),\n          continuous_map.norm_le _ (real.sqrt_nonneg _)],\n      intro x,\n      rw [real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, \u2190cstar_ring.norm_star_mul_self],\n      exact continuous_map.norm_coe_le_norm (star f * f) x },\n  end }\n\nend cstar_ring\n\nend continuous_map\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/topology/continuous_function/compact.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7109122961607722}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n\nDefinitions and properties of gcd, lcm, and coprime.\n-/\nimport .div\nopen eq.ops well_founded decidable prod\n\nnamespace nat\n\n/- gcd -/\n\nprivate definition pair_nat.lt : nat \u00d7 nat \u2192 nat \u00d7 nat \u2192 Prop := measure pr\u2082\nprivate definition pair_nat.lt.wf : well_founded pair_nat.lt :=\nintro_k (measure.wf pr\u2082) 20  -- we use intro_k to be able to execute gcd efficiently in the kernel\n\nlocal attribute pair_nat.lt.wf [instance]      -- instance will not be saved in .olean\nlocal infixl ` \u227a `:50 := pair_nat.lt\n\nprivate definition gcd.lt.dec (x y\u2081 : nat) : (succ y\u2081, x % succ y\u2081) \u227a (x, succ y\u2081) :=\n!mod_lt (succ_pos y\u2081)\n\ndefinition gcd.F : \u03a0 (p\u2081 : nat \u00d7 nat), (\u03a0 p\u2082 : nat \u00d7 nat, p\u2082 \u227a p\u2081 \u2192 nat) \u2192 nat\n| (x, 0)      f := x\n| (x, succ y) f := f (succ y, x % succ y) !gcd.lt.dec\n\ndefinition gcd (x y : nat) := fix gcd.F (x, y)\n\ntheorem gcd_zero_right [simp] (x : nat) : gcd x 0 = x := rfl\n\ntheorem gcd_succ [simp] (x y : nat) : gcd x (succ y) = gcd (succ y) (x % succ y) :=\nwell_founded.fix_eq gcd.F (x, succ y)\n\ntheorem gcd_one_right (n : \u2115) : gcd n 1 = 1 :=\ncalc gcd n 1 = gcd 1 (n % 1)  : gcd_succ\n         ... = gcd 1 0        : mod_one\n\ntheorem gcd_def (x : \u2115) : \u03a0 (y : \u2115), gcd x y = if y = 0 then x else gcd y (x % y)\n| 0        := !gcd_zero_right\n| (succ y) := !gcd_succ \u2b1d (if_neg !succ_ne_zero)\u207b\u00b9\n\n\ntheorem gcd_self : \u03a0 (n : \u2115), gcd n n = n\n| 0         := rfl\n| (succ n\u2081) := calc\n    gcd (succ n\u2081) (succ n\u2081) = gcd (succ n\u2081) (succ n\u2081 % succ n\u2081) : gcd_succ\n                      ...   = gcd (succ n\u2081) 0                     : mod_self\n\ntheorem gcd_zero_left : \u03a0 (n : \u2115), gcd 0 n = n\n| 0         := rfl\n| (succ n\u2081) := calc\n    gcd 0 (succ n\u2081) = gcd (succ n\u2081) (0 % succ n\u2081) : gcd_succ\n                ... = gcd (succ n\u2081) 0               : zero_mod\n\ntheorem gcd_of_pos (m : \u2115) {n : \u2115} (H : n > 0) : gcd m n = gcd n (m % n) :=\ngcd_def m n \u2b1d if_neg (ne_zero_of_pos H)\n\ntheorem gcd_rec (m n : \u2115) : gcd m n = gcd n (m % n) :=\nby_cases_zero_pos n\n  (calc\n          m = gcd 0 m       : gcd_zero_left\n        ... = gcd 0 (m % 0) : mod_zero)\n  (take n, assume H : 0 < n, gcd_of_pos m H)\n\ntheorem gcd.induction {P : \u2115 \u2192 \u2115 \u2192 Prop}\n                   (m n : \u2115)\n                   (H0 : \u2200m, P m 0)\n                   (H1 : \u2200m n, 0 < n \u2192 P n (m % n) \u2192 P m n) :\n                 P m n :=\ninduction (m, n) (prod.rec (\u03bbm, nat.rec (\u03bb IH, H0 m)\n   (\u03bb n\u2081 v (IH : \u2200p\u2082, p\u2082 \u227a (m, succ n\u2081) \u2192 P (pr\u2081 p\u2082) (pr\u2082 p\u2082)),\n      H1 m (succ n\u2081) !succ_pos (IH _ !gcd.lt.dec))))\n\ntheorem gcd_dvd (m n : \u2115) : (gcd m n \u2223 m) \u2227 (gcd m n \u2223 n) :=\ngcd.induction m n\n  (take m, and.intro (!one_mul \u25b8 !dvd_mul_left) !dvd_zero)\n  (take m n (npos : 0 < n), and.rec\n     (assume (IH\u2081 : gcd n (m % n) \u2223 n) (IH\u2082 : gcd n (m % n) \u2223 (m % n)),\n    have H : (gcd n (m % n) \u2223 (m / n * n + m % n)), from\n      dvd_add (dvd.trans IH\u2081 !dvd_mul_left) IH\u2082,\n    have H1 : (gcd n (m % n) \u2223 m), from !eq_div_mul_add_mod\u207b\u00b9 \u25b8 H,\n    show (gcd m n \u2223 m) \u2227 (gcd m n \u2223 n), from !gcd_rec\u207b\u00b9 \u25b8 (and.intro H1 IH\u2081)))\n\ntheorem gcd_dvd_left (m n : \u2115) : gcd m n \u2223 m := and.left !gcd_dvd\n\ntheorem gcd_dvd_right (m n : \u2115) : gcd m n \u2223 n := and.right !gcd_dvd\n\ntheorem dvd_gcd {m n k : \u2115} : k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 gcd m n :=\ngcd.induction m n (take m, imp.intro)\n  (take m n (npos : n > 0)\n    (IH : k \u2223 n \u2192 k \u2223 m % n \u2192 k \u2223 gcd n (m % n))\n    (H1 : k \u2223 m) (H2 : k \u2223 n),\n    have H3 : k \u2223 m / n * n + m % n, from !eq_div_mul_add_mod \u25b8 H1,\n    have H4 : k \u2223 m % n, from nat.dvd_of_dvd_add_left H3 (dvd.trans H2 !dvd_mul_left),\n    !gcd_rec\u207b\u00b9 \u25b8 IH H2 H4)\n\ntheorem gcd.comm (m n : \u2115) : gcd m n = gcd n m :=\ndvd.antisymm\n  (dvd_gcd !gcd_dvd_right !gcd_dvd_left)\n  (dvd_gcd !gcd_dvd_right !gcd_dvd_left)\n\ntheorem gcd.assoc (m n k : \u2115) : gcd (gcd m n) k = gcd m (gcd n k) :=\ndvd.antisymm\n  (dvd_gcd\n    (dvd.trans !gcd_dvd_left !gcd_dvd_left)\n    (dvd_gcd (dvd.trans !gcd_dvd_left !gcd_dvd_right) !gcd_dvd_right))\n  (dvd_gcd\n    (dvd_gcd !gcd_dvd_left (dvd.trans !gcd_dvd_right !gcd_dvd_left))\n    (dvd.trans !gcd_dvd_right !gcd_dvd_right))\n\ntheorem gcd_one_left (m : \u2115) : gcd 1 m = 1 :=\n!gcd.comm \u2b1d !gcd_one_right\n\ntheorem gcd_mul_left (m n k : \u2115) : gcd (m * n) (m * k) = m * gcd n k :=\ngcd.induction n k\n  (take n, calc gcd (m * n) (m * 0) = gcd (m * n) 0 : mul_zero)\n  (take n k,\n    assume H : 0 < k,\n    assume IH : gcd (m * k) (m * (n % k)) = m * gcd k (n % k),\n    calc\n      gcd (m * n) (m * k) = gcd (m * k) (m * n % (m * k)) : !gcd_rec\n                      ... = gcd (m * k) (m * (n % k))     : mul_mod_mul_left\n                      ... = m * gcd k (n % k)             : IH\n                      ... = m * gcd n k                   : !gcd_rec)\n\ntheorem gcd_mul_right (m n k : \u2115) : gcd (m * n) (k * n) = gcd m k * n :=\ncalc\n  gcd (m * n) (k * n) = gcd (n * m) (k * n) : mul.comm\n                  ... = gcd (n * m) (n * k) : mul.comm\n                  ... = n * gcd m k         : gcd_mul_left\n                  ... = gcd m k * n         : mul.comm\n\ntheorem gcd_pos_of_pos_left {m : \u2115} (n : \u2115) (mpos : m > 0) : gcd m n > 0 :=\npos_of_dvd_of_pos !gcd_dvd_left mpos\n\ntheorem gcd_pos_of_pos_right (m : \u2115) {n : \u2115} (npos : n > 0) : gcd m n > 0 :=\npos_of_dvd_of_pos !gcd_dvd_right npos\n\ntheorem eq_zero_of_gcd_eq_zero_left {m n : \u2115} (H : gcd m n = 0) : m = 0 :=\nor.elim (eq_zero_or_pos m)\n  (assume H1, H1)\n  (assume H1 : m > 0, absurd H\u207b\u00b9 (ne_of_lt (!gcd_pos_of_pos_left H1)))\n\ntheorem eq_zero_of_gcd_eq_zero_right {m n : \u2115} (H : gcd m n = 0) : n = 0 :=\neq_zero_of_gcd_eq_zero_left (!gcd.comm \u25b8 H)\n\ntheorem gcd_div {m n k : \u2115} (H1 : k \u2223 m) (H2 : k \u2223 n) :\n  gcd (m / k) (n / k) = gcd m n / k :=\nor.elim (eq_zero_or_pos k)\n  (assume H3 : k = 0, by subst k; rewrite *nat.div_zero)\n  (assume H3 : k > 0, (nat.div_eq_of_eq_mul_left H3 (calc\n        gcd m n = gcd m (n / k * k)             : nat.div_mul_cancel H2\n            ... = gcd (m / k * k) (n / k * k) : nat.div_mul_cancel H1\n            ... = gcd (m / k) (n / k) * k     : gcd_mul_right))\u207b\u00b9)\n\ntheorem gcd_dvd_gcd_mul_left (m n k : \u2115) : gcd m n \u2223 gcd (k * m) n :=\ndvd_gcd (dvd.trans !gcd_dvd_left !dvd_mul_left) !gcd_dvd_right\n\ntheorem gcd_dvd_gcd_mul_right (m n k : \u2115) : gcd m n \u2223 gcd (m * k) n :=\n!mul.comm \u25b8 !gcd_dvd_gcd_mul_left\n\ntheorem gcd_dvd_gcd_mul_left_right (m n k : \u2115) : gcd m n \u2223 gcd m (k * n) :=\ndvd_gcd  !gcd_dvd_left (dvd.trans !gcd_dvd_right !dvd_mul_left)\n\ntheorem gcd_dvd_gcd_mul_right_right (m n k : \u2115) : gcd m n \u2223 gcd m (n * k) :=\n!mul.comm \u25b8 !gcd_dvd_gcd_mul_left_right\n\n/- lcm -/\n\ndefinition lcm (m n : \u2115) : \u2115 := m * n / (gcd m n)\n\ntheorem lcm.comm (m n : \u2115) : lcm m n = lcm n m :=\ncalc\n  lcm m n = m * n / gcd m n : rfl\n      ... = n * m / gcd m n : mul.comm\n      ... = n * m / gcd n m : gcd.comm\n      ... = lcm n m           : rfl\n\ntheorem lcm_zero_left (m : \u2115) : lcm 0 m = 0 :=\ncalc\n  lcm 0 m = 0 * m / gcd 0 m : rfl\n      ... = 0 / gcd 0 m     : zero_mul\n      ... = 0                 : nat.zero_div\n\ntheorem lcm_zero_right (m : \u2115) : lcm m 0 = 0 := !lcm.comm \u25b8 !lcm_zero_left\n\ntheorem lcm_one_left (m : \u2115) : lcm 1 m = m :=\ncalc\n  lcm 1 m = 1 * m / gcd 1 m : rfl\n      ... = m / gcd 1 m     : one_mul\n      ... = m / 1           : gcd_one_left\n      ... = m                 : nat.div_one\n\ntheorem lcm_one_right (m : \u2115) : lcm m 1 = m := !lcm.comm \u25b8 !lcm_one_left\n\ntheorem lcm_self (m : \u2115) : lcm m m = m :=\nhave H : m * m / m = m, from\n  by_cases_zero_pos m !nat.div_zero (take m, assume H1 : m > 0, !nat.mul_div_cancel H1),\ncalc\n  lcm m m = m * m / gcd m m : rfl\n      ... = m * m / m       : gcd_self\n      ... = m                 : H\n\ntheorem dvd_lcm_left (m n : \u2115) : m \u2223 lcm m n :=\nhave H : lcm m n = m * (n / gcd m n), from nat.mul_div_assoc _ !gcd_dvd_right,\ndvd.intro H\u207b\u00b9\n\ntheorem dvd_lcm_right (m n : \u2115) : n \u2223 lcm m n :=\n!lcm.comm \u25b8 !dvd_lcm_left\n\ntheorem gcd_mul_lcm (m n : \u2115) : gcd m n * lcm m n = m * n :=\neq.symm (nat.eq_mul_of_div_eq_right (dvd.trans !gcd_dvd_left !dvd_mul_right) rfl)\n\ntheorem lcm_dvd {m n k : \u2115} (H1 : m \u2223 k) (H2 : n \u2223 k) : lcm m n \u2223 k :=\nor.elim (eq_zero_or_pos k)\n  (assume kzero : k = 0, !kzero\u207b\u00b9 \u25b8 !dvd_zero)\n  (assume kpos : k > 0,\n    have mpos : m > 0, from pos_of_dvd_of_pos H1 kpos,\n    have npos : n > 0, from pos_of_dvd_of_pos H2 kpos,\n    have gcd_pos : gcd m n > 0, from !gcd_pos_of_pos_left mpos,\n    obtain p (km : k = m * p), from exists_eq_mul_right_of_dvd H1,\n    obtain q (kn : k = n * q), from exists_eq_mul_right_of_dvd H2,\n    have ppos : p > 0, from pos_of_mul_pos_left (km \u25b8 kpos),\n    have qpos : q > 0, from pos_of_mul_pos_left (kn \u25b8 kpos),\n    have H3 : p * q * (m * n * gcd p q) = p * q * (gcd m n * k), from\n    calc\n      p * q * (m * n * gcd p q)\n            = m * p * (n * q * gcd p q)       : by rewrite [*mul.assoc, *mul.left_comm q,\n                                                             mul.left_comm p]\n        ... = k * (k * gcd p q)               : by rewrite [-kn, -km]\n        ... = k * gcd (k * p) (k * q)         : by rewrite gcd_mul_left\n        ... = k * gcd (n * q * p) (m * p * q) : by rewrite [-kn, -km]\n        ... = k * (gcd n m * (p * q))         : by rewrite [*mul.assoc, mul.comm q, gcd_mul_right]\n        ... = p * q * (gcd m n * k)           : by rewrite [mul.comm, mul.comm (gcd n m), gcd.comm,\n                                                             *mul.assoc],\n    have H4 : m * n * gcd p q = gcd m n * k,\n      from !eq_of_mul_eq_mul_left (mul_pos ppos qpos) H3,\n    have H5 : gcd m n * (lcm m n * gcd p q) = gcd m n * k,\n      from !mul.assoc \u25b8 !gcd_mul_lcm\u207b\u00b9 \u25b8 H4,\n    have H6 : lcm m n * gcd p q = k,\n      from !eq_of_mul_eq_mul_left gcd_pos H5,\n    dvd.intro H6)\n\ntheorem lcm.assoc (m n k : \u2115) : lcm (lcm m n) k = lcm m (lcm n k) :=\ndvd.antisymm\n  (lcm_dvd\n    (lcm_dvd !dvd_lcm_left (dvd.trans !dvd_lcm_left !dvd_lcm_right))\n    (dvd.trans !dvd_lcm_right !dvd_lcm_right))\n  (lcm_dvd\n    (dvd.trans !dvd_lcm_left !dvd_lcm_left)\n    (lcm_dvd (dvd.trans !dvd_lcm_right !dvd_lcm_left) !dvd_lcm_right))\n\n/- coprime -/\n\ndefinition coprime [reducible] (m n : \u2115) : Prop := gcd m n = 1\n\nlemma gcd_eq_one_of_coprime {m n : \u2115} : coprime m n \u2192 gcd m n = 1 :=\n\u03bb h, h\n\ntheorem coprime_swap {m n : \u2115} (H : coprime n m) : coprime m n :=\n!gcd.comm \u25b8 H\n\ntheorem dvd_of_coprime_of_dvd_mul_right {m n k : \u2115} (H1 : coprime k n) (H2 : k \u2223 m * n) : k \u2223 m :=\nhave H3 : gcd (m * k) (m * n) = m, from\n  calc\n    gcd (m * k) (m * n) = m * gcd k n : gcd_mul_left\n                    ... = m * 1       : H1\n                    ... = m           : mul_one,\nhave H4 : (k \u2223 gcd (m * k) (m * n)), from dvd_gcd !dvd_mul_left H2,\nH3 \u25b8 H4\n\ntheorem dvd_of_coprime_of_dvd_mul_left {m n k : \u2115} (H1 : coprime k m) (H2 : k \u2223 m * n) : k \u2223 n :=\ndvd_of_coprime_of_dvd_mul_right H1 (!mul.comm \u25b8 H2)\n\ntheorem gcd_mul_left_cancel_of_coprime {k : \u2115} (m : \u2115) {n : \u2115} (H : coprime k n) :\n   gcd (k * m) n = gcd m n :=\nhave H1 : coprime (gcd (k * m) n) k, from\n  calc\n    gcd (gcd (k * m) n) k\n         = gcd (k * gcd 1 m) n : by rewrite [-gcd_mul_left, mul_one, gcd.comm, gcd.assoc]\n     ... = 1                   : by rewrite [gcd_one_left, mul_one, \u2191coprime at H, H],\ndvd.antisymm\n  (dvd_gcd (dvd_of_coprime_of_dvd_mul_left H1 !gcd_dvd_left) !gcd_dvd_right)\n  (dvd_gcd (dvd.trans !gcd_dvd_left !dvd_mul_left) !gcd_dvd_right)\n\ntheorem gcd_mul_right_cancel_of_coprime (m : \u2115) {k n : \u2115} (H : coprime k n) :\n   gcd (m * k) n = gcd m n :=\n!mul.comm \u25b8 !gcd_mul_left_cancel_of_coprime H\n\ntheorem gcd_mul_left_cancel_of_coprime_right {k m : \u2115} (n : \u2115) (H : coprime k m) :\n   gcd m (k * n) = gcd m n :=\n!gcd.comm \u25b8 !gcd.comm \u25b8 !gcd_mul_left_cancel_of_coprime H\n\ntheorem gcd_mul_right_cancel_of_coprime_right {k m : \u2115} (n : \u2115) (H : coprime k m) :\n   gcd m (n * k) = gcd m n :=\n!gcd.comm \u25b8 !gcd.comm \u25b8 !gcd_mul_right_cancel_of_coprime H\n\ntheorem coprime_div_gcd_div_gcd {m n : \u2115} (H : gcd m n > 0) :\n  coprime (m / gcd m n) (n / gcd m n) :=\ncalc\n  gcd (m / gcd m n) (n / gcd m n) = gcd m n / gcd m n : gcd_div !gcd_dvd_left !gcd_dvd_right\n     ... = 1 : nat.div_self H\n\ntheorem not_coprime_of_dvd_of_dvd {m n d : \u2115} (dgt1 : d > 1) (Hm : d \u2223 m) (Hn : d \u2223 n) :\n  \u00ac coprime m n :=\nassume co : coprime m n,\nhave d \u2223 gcd m n, from dvd_gcd Hm Hn,\nhave d \u2223 1, by rewrite [\u2191coprime at co, co at this]; apply this,\nhave d \u2264 1, from le_of_dvd dec_trivial this,\nshow false, from not_lt_of_ge `d \u2264 1` `d > 1`\n\ntheorem exists_coprime {m n : \u2115} (H : gcd m n > 0) :\n  exists m' n', coprime m' n' \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n :=\nhave H1 : m = (m / gcd m n) * gcd m n, from (nat.div_mul_cancel !gcd_dvd_left)\u207b\u00b9,\nhave H2 : n = (n / gcd m n) * gcd m n, from (nat.div_mul_cancel !gcd_dvd_right)\u207b\u00b9,\nexists.intro _ (exists.intro _ (and.intro (coprime_div_gcd_div_gcd H) (and.intro H1 H2)))\n\ntheorem coprime_mul {m n k : \u2115} (H1 : coprime m k) (H2 : coprime n k) : coprime (m * n) k :=\ncalc\n  gcd (m * n) k = gcd n k : !gcd_mul_left_cancel_of_coprime H1\n            ... = 1       : H2\n\ntheorem coprime_mul_right {k m n : \u2115} (H1 : coprime k m) (H2 : coprime k n) : coprime k (m * n) :=\ncoprime_swap (coprime_mul (coprime_swap H1) (coprime_swap H2))\n\ntheorem coprime_of_coprime_mul_left {k m n : \u2115} (H : coprime (k * m) n) : coprime m n :=\nhave H1 : (gcd m n \u2223 gcd (k * m) n), from !gcd_dvd_gcd_mul_left,\neq_one_of_dvd_one (H \u25b8 H1)\n\ntheorem coprime_of_coprime_mul_right {k m n : \u2115} (H : coprime (m * k) n) : coprime m n :=\ncoprime_of_coprime_mul_left (!mul.comm \u25b8 H)\n\ntheorem coprime_of_coprime_mul_left_right {k m n : \u2115} (H : coprime m (k * n)) : coprime m n :=\ncoprime_swap (coprime_of_coprime_mul_left (coprime_swap H))\n\ntheorem coprime_of_coprime_mul_right_right {k m n : \u2115} (H : coprime m (n * k)) : coprime m n :=\ncoprime_of_coprime_mul_left_right (!mul.comm \u25b8 H)\n\ntheorem comprime_one_left : \u2200 n, coprime 1 n :=\n\u03bb n, !gcd_one_left\n\ntheorem comprime_one_right : \u2200 n, coprime n 1 :=\n\u03bb n, !gcd_one_right\n\ntheorem exists_eq_prod_and_dvd_and_dvd {m n k : nat} (H : k \u2223 m * n) :\n  \u2203 m' n', k = m' * n' \u2227 m' \u2223 m \u2227 n' \u2223 n :=\nor.elim (eq_zero_or_pos (gcd k m))\n (assume H1 : gcd k m = 0,\n    have H2 : k = 0, from eq_zero_of_gcd_eq_zero_left H1,\n    have H3 : m = 0, from eq_zero_of_gcd_eq_zero_right H1,\n    have H4 : k = 0 * n, from H2 \u2b1d !zero_mul\u207b\u00b9,\n    have H5 : 0 \u2223 m, from H3\u207b\u00b9 \u25b8 !dvd.refl,\n    have H6 : n \u2223 n, from !dvd.refl,\n    exists.intro _ (exists.intro _ (and.intro H4 (and.intro H5 H6))))\n  (assume H1 : gcd k m > 0,\n    have H2 : gcd k m \u2223 k, from !gcd_dvd_left,\n    have H3 : k / gcd k m \u2223 (m * n) / gcd k m, from nat.div_dvd_div H2 H,\n    have H4 : (m * n) / gcd k m = (m / gcd k m) * n, from\n      calc\n        m * n / gcd k m = n * m / gcd k m   : mul.comm\n                      ... = n * (m / gcd k m) : !nat.mul_div_assoc !gcd_dvd_right\n                      ... = m / gcd k m * n   : mul.comm,\n    have H5 : k / gcd k m \u2223 (m / gcd k m) * n, from H4 \u25b8 H3,\n    have H6 : coprime (k / gcd k m) (m / gcd k m), from coprime_div_gcd_div_gcd H1,\n    have H7 : k / gcd k m \u2223 n, from dvd_of_coprime_of_dvd_mul_left H6 H5,\n    have H8 : k = gcd k m * (k / gcd k m), from (nat.mul_div_cancel' H2)\u207b\u00b9,\n    exists.intro _ (exists.intro _ (and.intro H8 (and.intro !gcd_dvd_right H7))))\n\nend nat\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/nat/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.710912292373904}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport linear_algebra.matrix.nonsingular_inverse\n\n/-!\n# Integer powers of square matrices\n\nIn this file, we define integer power of matrices, relying on\nthe nonsingular inverse definition for negative powers.\n\n## Implementation details\n\nThe main definition is a direct recursive call on the integer inductive type,\nas provided by the `div_inv_monoid.zpow` default implementation.\nThe lemma names are taken from `algebra.group_with_zero.power`.\n\n## Tags\n\nmatrix inverse, matrix powers\n-/\n\nopen_locale matrix\n\nnamespace matrix\n\nvariables {n' : Type*} [decidable_eq n'] [fintype n'] {R : Type*} [comm_ring R]\n\nlocal notation `M` := matrix n' n' R\n\nnoncomputable instance : div_inv_monoid M :=\n{ ..(show monoid M, by apply_instance),\n  ..(show has_inv M, by apply_instance) }\n\nsection nat_pow\n\n@[simp] theorem inv_pow' (A : M) (n : \u2115) : (A\u207b\u00b9) ^ n = (A ^ n)\u207b\u00b9 :=\nbegin\n  induction n with n ih,\n  { simp },\n  { rw [pow_succ A, mul_eq_mul, mul_inv_rev, \u2190 ih, \u2190 mul_eq_mul, \u2190 pow_succ'] }\nend\n\ntheorem pow_sub' (A : M) {m n : \u2115} (ha : is_unit A.det) (h : n \u2264 m) :\n  A ^ (m - n) = A ^ m \u2b1d (A ^ n)\u207b\u00b9 :=\nbegin\n  rw [\u2190tsub_add_cancel_of_le h, pow_add, mul_eq_mul, matrix.mul_assoc, mul_nonsing_inv,\n      tsub_add_cancel_of_le h, matrix.mul_one],\n  simpa using ha.pow n\nend\n\ntheorem pow_inv_comm' (A : M) (m n : \u2115) : (A\u207b\u00b9) ^ m \u2b1d A ^ n = A ^ n \u2b1d (A\u207b\u00b9) ^ m :=\nbegin\n  induction n with n IH generalizing m,\n  { simp },\n  cases m,\n  { simp },\n  rcases nonsing_inv_cancel_or_zero A with \u27e8h, h'\u27e9 | h,\n  { calc  A\u207b\u00b9 ^ (m + 1) \u2b1d A ^ (n + 1)\n        = A\u207b\u00b9 ^ m \u2b1d (A\u207b\u00b9 \u2b1d A) \u2b1d A ^ n :\n          by simp only [pow_succ' A\u207b\u00b9, pow_succ A, mul_eq_mul, matrix.mul_assoc]\n    ... = A ^ n \u2b1d A\u207b\u00b9 ^ m :\n          by simp only [h, matrix.mul_one, matrix.one_mul, IH m]\n    ... = A ^ n \u2b1d (A \u2b1d A\u207b\u00b9) \u2b1d A\u207b\u00b9 ^ m :\n          by simp only [h', matrix.mul_one, matrix.one_mul]\n    ... = A ^ (n + 1) \u2b1d A\u207b\u00b9 ^ (m + 1) :\n          by simp only [pow_succ' A, pow_succ A\u207b\u00b9, mul_eq_mul, matrix.mul_assoc] },\n  { simp [h] }\nend\n\nend nat_pow\n\nsection zpow\nopen int\n\n@[simp] theorem one_zpow : \u2200 (n : \u2124), (1 : M) ^ n = 1\n| (n : \u2115) := by rw [zpow_coe_nat, one_pow]\n| -[1+ n] := by rw [zpow_neg_succ_of_nat, one_pow, inv_one]\n\nlemma zero_zpow : \u2200 z : \u2124, z \u2260 0 \u2192 (0 : M) ^ z = 0\n| (n : \u2115) h := by { rw [zpow_coe_nat, zero_pow], refine lt_of_le_of_ne n.zero_le (ne.symm _),\n  simpa using h  }\n| -[1+n]  h := by simp [zero_pow n.zero_lt_succ]\n\nlemma zero_zpow_eq (n : \u2124) : (0 : M) ^ n = if n = 0 then 1 else 0 :=\nbegin\n  split_ifs with h,\n  { rw [h, zpow_zero] },\n  { rw [zero_zpow _ h] }\nend\n\ntheorem inv_zpow (A : M) : \u2200n:\u2124, A\u207b\u00b9 ^ n = (A ^ n)\u207b\u00b9\n| (n : \u2115) := by rw [zpow_coe_nat, zpow_coe_nat, inv_pow']\n| -[1+ n] := by rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, inv_pow']\n\n@[simp] lemma zpow_neg_one (A : M) : A ^ (-1 : \u2124) = A\u207b\u00b9 :=\nbegin\n  convert div_inv_monoid.zpow_neg' 0 A,\n  simp only [zpow_one, int.coe_nat_zero, int.coe_nat_succ, zpow_eq_pow, zero_add]\nend\n\ntheorem zpow_coe_nat (A : M) (n : \u2115) : A ^ (n : \u2124) = (A ^ n) :=\nzpow_coe_nat _ _\n\n@[simp] theorem zpow_neg_coe_nat (A : M) (n : \u2115) : A ^ (-n : \u2124) = (A ^ n)\u207b\u00b9 :=\nbegin\n  cases n,\n  { simp },\n  { exact div_inv_monoid.zpow_neg' _ _ }\nend\n\nlemma _root_.is_unit.det_zpow {A : M} (h : is_unit A.det) (n : \u2124) : is_unit (A ^ n).det :=\nbegin\n  cases n,\n  { simpa using h.pow n },\n  { simpa using h.pow n.succ }\nend\n\nlemma is_unit_det_zpow_iff {A : M} {z : \u2124} :\n  is_unit (A ^ z).det \u2194 is_unit A.det \u2228 z = 0 :=\nbegin\n  induction z using int.induction_on with z IH z IH,\n  { simp },\n  { rw [\u2190int.coe_nat_succ, zpow_coe_nat, det_pow, is_unit_pow_succ_iff, \u2190int.coe_nat_zero,\n        int.coe_nat_eq_coe_nat_iff],\n    simp },\n  { rw [\u2190neg_add', \u2190int.coe_nat_succ, zpow_neg_coe_nat, is_unit_nonsing_inv_det_iff, det_pow,\n        is_unit_pow_succ_iff, neg_eq_zero, \u2190int.coe_nat_zero, int.coe_nat_eq_coe_nat_iff],\n    simp }\nend\n\ntheorem zpow_neg {A : M} (h : is_unit A.det) : \u2200 (n : \u2124), A ^ -n = (A ^ n)\u207b\u00b9\n| (n : \u2115) := zpow_neg_coe_nat _ _\n| -[1+ n] := by { rw [zpow_neg_succ_of_nat, neg_neg_of_nat_succ, of_nat_eq_coe, zpow_coe_nat,\n                      nonsing_inv_nonsing_inv],\n                  rw det_pow,\n                  exact h.pow _ }\n\nlemma inv_zpow' {A : M} (h : is_unit A.det) (n : \u2124) :\n  (A \u207b\u00b9) ^ n = A ^ (-n) :=\nby rw [zpow_neg h, inv_zpow]\n\nlemma zpow_add_one {A : M} (h : is_unit A.det) : \u2200 n : \u2124, A ^ (n + 1) = A ^ n * A\n| (n : \u2115)        := by simp only [\u2190 nat.cast_succ, pow_succ', zpow_coe_nat]\n| -((n : \u2115) + 1) :=\ncalc  A ^ (-(n + 1) + 1 : \u2124)\n    = (A ^ n)\u207b\u00b9 : by rw [neg_add, neg_add_cancel_right, zpow_neg h, zpow_coe_nat]\n... = (A \u2b1d A ^ n)\u207b\u00b9 \u2b1d A : by rw [mul_inv_rev, matrix.mul_assoc, nonsing_inv_mul _ h, matrix.mul_one]\n... = A ^ -(n + 1 : \u2124) * A :\n      by rw [zpow_neg h, \u2190 int.coe_nat_succ, zpow_coe_nat, pow_succ, mul_eq_mul, mul_eq_mul]\n\nlemma zpow_sub_one {A : M} (h : is_unit A.det) (n : \u2124) : A ^ (n - 1) = A ^ n * A\u207b\u00b9 :=\ncalc A ^ (n - 1) = A ^ (n - 1) * A * A\u207b\u00b9 : by rw [mul_assoc, mul_eq_mul A, mul_nonsing_inv _ h,\n                                                  mul_one]\n             ... = A^n * A\u207b\u00b9             : by rw [\u2190 zpow_add_one h, sub_add_cancel]\n\nlemma zpow_add {A : M} (ha : is_unit A.det) (m n : \u2124) : A ^ (m + n) = A ^ m * A ^ n :=\nbegin\n  induction n using int.induction_on with n ihn n ihn,\n  case hz : { simp },\n  { simp only [\u2190 add_assoc, zpow_add_one ha, ihn, mul_assoc] },\n  { rw [zpow_sub_one ha, \u2190 mul_assoc, \u2190 ihn, \u2190 zpow_sub_one ha, add_sub_assoc] }\nend\n\nlemma zpow_add_of_nonpos {A : M} {m n : \u2124} (hm : m \u2264 0) (hn : n \u2264 0) :\n  A ^ (m + n) = A ^ m * A ^ n :=\nbegin\n  rcases nonsing_inv_cancel_or_zero A with \u27e8h, h'\u27e9 | h,\n  { exact zpow_add (is_unit_det_of_left_inverse h) m n },\n  { obtain \u27e8k, rfl\u27e9 := exists_eq_neg_of_nat hm,\n    obtain \u27e8l, rfl\u27e9 := exists_eq_neg_of_nat hn,\n    simp_rw [\u2190neg_add, \u2190int.coe_nat_add, zpow_neg_coe_nat, \u2190inv_pow', h, pow_add] }\nend\n\nlemma zpow_add_of_nonneg {A : M} {m n : \u2124} (hm : 0 \u2264 m) (hn : 0 \u2264 n) :\n  A ^ (m + n) = A ^ m * A ^ n :=\nbegin\n  obtain \u27e8k, rfl\u27e9 := eq_coe_of_zero_le hm,\n  obtain \u27e8l, rfl\u27e9 := eq_coe_of_zero_le hn,\n  rw [\u2190int.coe_nat_add, zpow_coe_nat, zpow_coe_nat, zpow_coe_nat, pow_add],\nend\n\ntheorem zpow_one_add {A : M} (h : is_unit A.det) (i : \u2124) : A ^ (1 + i) = A * A ^ i :=\nby rw [zpow_add h, zpow_one]\n\ntheorem semiconj_by.zpow_right {A X Y : M} (hx : is_unit X.det) (hy : is_unit Y.det)\n  (h : semiconj_by A X Y) :\n  \u2200 m : \u2124, semiconj_by A (X^m) (Y^m)\n| (n : \u2115) := by simp [h.pow_right n]\n| -[1+n]  := begin\n  have hx' : is_unit (X ^ n.succ).det,\n  { rw det_pow,\n    exact hx.pow n.succ },\n  have hy' : is_unit (Y ^ n.succ).det,\n  { rw det_pow,\n    exact hy.pow n.succ },\n  rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, nonsing_inv_apply _ hx', nonsing_inv_apply _ hy',\n      semiconj_by],\n  refine (is_regular_of_is_left_regular_det hy'.is_regular.left).left _,\n  rw [\u2190mul_assoc, \u2190(h.pow_right n.succ).eq, mul_assoc, mul_eq_mul (X ^ _), mul_smul, mul_adjugate,\n      mul_eq_mul, mul_eq_mul, mul_eq_mul, \u2190matrix.mul_assoc, mul_smul (Y ^ _) (\u2191(hy'.unit)\u207b\u00b9 : R),\n      mul_adjugate, smul_smul, smul_smul, hx'.coe_inv_mul,\n      hy'.coe_inv_mul, one_smul, matrix.mul_one, matrix.one_mul],\nend\n\ntheorem commute.zpow_right {A B : M} (h : commute A B) (m : \u2124) : commute A (B^m) :=\nbegin\n  rcases nonsing_inv_cancel_or_zero B with \u27e8hB, hB'\u27e9 | hB,\n  { refine semiconj_by.zpow_right _ _ h _;\n    exact is_unit_det_of_left_inverse hB },\n  { cases m,\n    { simpa using h.pow_right _ },\n    { simp [\u2190inv_pow', hB] } }\nend\n\ntheorem commute.zpow_left {A B : M} (h : commute A B) (m : \u2124) : commute (A^m) B :=\n(commute.zpow_right h.symm m).symm\n\ntheorem commute.zpow_zpow {A B : M} (h : commute A B) (m n : \u2124) : commute (A^m) (B^n) :=\ncommute.zpow_right (commute.zpow_left h _) _\n\ntheorem commute.zpow_self (A : M) (n : \u2124) : commute (A^n) A :=\ncommute.zpow_left (commute.refl A) _\n\ntheorem commute.self_zpow (A : M) (n : \u2124) : commute A (A^n) :=\ncommute.zpow_right (commute.refl A) _\n\ntheorem commute.zpow_zpow_self (A : M) (m n : \u2124) : commute (A^m) (A^n) :=\ncommute.zpow_zpow (commute.refl A) _ _\n\ntheorem zpow_bit0 (A : M) (n : \u2124) : A ^ bit0 n = A ^ n * A ^ n :=\nbegin\n  cases le_total 0 n with nonneg nonpos,\n  { exact zpow_add_of_nonneg nonneg nonneg },\n  { exact zpow_add_of_nonpos nonpos nonpos }\nend\n\nlemma zpow_add_one_of_ne_neg_one {A : M} : \u2200 (n : \u2124), n \u2260 -1 \u2192 A ^ (n + 1) = A ^ n * A\n| (n : \u2115) _ := by simp only [pow_succ', \u2190 nat.cast_succ, zpow_coe_nat]\n| (-1) h := absurd rfl h\n| (-((n : \u2115) + 2)) _ := begin\n  rcases nonsing_inv_cancel_or_zero A with \u27e8h, h'\u27e9 | h,\n  { apply zpow_add_one (is_unit_det_of_left_inverse h) },\n  { show A ^ (-((n + 1 : \u2115) : \u2124)) = A ^ -((n + 2 : \u2115) : \u2124) * A,\n    simp_rw [zpow_neg_coe_nat, \u2190inv_pow', h, zero_pow nat.succ_pos', zero_mul] }\nend\n\ntheorem zpow_bit1 (A : M) (n : \u2124) : A ^ bit1 n = A ^ n * A ^ n * A :=\nbegin\n  rw [bit1, zpow_add_one_of_ne_neg_one, zpow_bit0],\n  intro h,\n  simpa using congr_arg bodd h\nend\n\ntheorem zpow_mul (A : M) (h : is_unit A.det) : \u2200 m n : \u2124, A ^ (m * n) = (A ^ m) ^ n\n| (m : \u2115) (n : \u2115) := by rw [zpow_coe_nat, zpow_coe_nat, \u2190 pow_mul, \u2190 zpow_coe_nat, int.coe_nat_mul]\n| (m : \u2115) -[1+ n] := by rw [zpow_coe_nat, zpow_neg_succ_of_nat, \u2190 pow_mul, coe_nat_mul_neg_succ,\n    \u2190int.coe_nat_mul, zpow_neg_coe_nat]\n| -[1+ m] (n : \u2115) := by rw [zpow_coe_nat, zpow_neg_succ_of_nat, \u2190 inv_pow', \u2190 pow_mul,\n    neg_succ_mul_coe_nat, \u2190int.coe_nat_mul, zpow_neg_coe_nat, inv_pow']\n| -[1+ m] -[1+ n] := by { rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, neg_succ_mul_neg_succ,\n    \u2190int.coe_nat_mul, zpow_coe_nat, inv_pow', \u2190pow_mul, nonsing_inv_nonsing_inv],\n    rw det_pow,\n    exact h.pow _ }\n\ntheorem zpow_mul' (A : M) (h : is_unit A.det) (m n : \u2124) : A ^ (m * n) = (A ^ n) ^ m :=\nby rw [mul_comm, zpow_mul _ h]\n\n@[simp, norm_cast] lemma coe_units_zpow (u : M\u02e3) :\n  \u2200 (n : \u2124), ((u ^ n : M\u02e3) : M) = u ^ n\n| (n : \u2115) := by rw [_root_.zpow_coe_nat, zpow_coe_nat, units.coe_pow]\n| -[1+k] := by rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, \u2190inv_pow, u\u207b\u00b9.coe_pow, \u2190inv_pow',\n                   coe_units_inv]\n\nlemma zpow_ne_zero_of_is_unit_det [nonempty n'] [nontrivial R] {A : M}\n  (ha : is_unit A.det) (z : \u2124) : A ^ z \u2260 0 :=\nbegin\n  have := ha.det_zpow z,\n  contrapose! this,\n  rw [this, det_zero \u2039_\u203a],\n  exact not_is_unit_zero\nend\n\nlemma zpow_sub {A : M} (ha : is_unit A.det) (z1 z2 : \u2124) : A ^ (z1 - z2) = A ^ z1 / A ^ z2 :=\nby rw [sub_eq_add_neg, zpow_add ha, zpow_neg ha, div_eq_mul_inv]\n\nlemma commute.mul_zpow {A B : M} (h : commute A B) :\n  \u2200 (i : \u2124), (A * B) ^ i = (A ^ i) * (B ^ i)\n| (n : \u2115) := by simp [h.mul_pow n, -mul_eq_mul]\n| -[1+n]  := by rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, zpow_neg_succ_of_nat,\n                    mul_eq_mul (_\u207b\u00b9), \u2190mul_inv_rev, \u2190mul_eq_mul, h.mul_pow n.succ,\n                    (h.pow_pow _ _).eq]\n\ntheorem zpow_bit0' (A : M) (n : \u2124) : A ^ bit0 n = (A * A) ^ n :=\n(zpow_bit0 A n).trans (commute.mul_zpow (commute.refl A) n).symm\n\ntheorem zpow_bit1' (A : M) (n : \u2124) : A ^ bit1 n = (A * A) ^ n * A :=\nby rw [zpow_bit1, commute.mul_zpow (commute.refl A)]\n\ntheorem zpow_neg_mul_zpow_self (n : \u2124) {A : M} (h : is_unit A.det) :\n  A ^ (-n) * A ^ n = 1 :=\nby rw [zpow_neg h, mul_eq_mul, nonsing_inv_mul _ (h.det_zpow _)]\n\ntheorem one_div_pow {A : M} (n : \u2115) :\n  (1 / A) ^ n = 1 / A ^ n :=\nby simp only [one_div, inv_pow']\n\ntheorem one_div_zpow {A : M} (n : \u2124) :\n  (1 / A) ^ n = 1 / A ^ n :=\nby simp only [one_div, inv_zpow]\n\n@[simp] theorem transpose_zpow (A : M) : \u2200 (n : \u2124), (A ^ n)\u1d40 = A\u1d40 ^ n\n| (n : \u2115) := by rw [zpow_coe_nat, zpow_coe_nat, transpose_pow]\n| -[1+ n] := by\n  rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, transpose_nonsing_inv, transpose_pow]\n\n@[simp] theorem conj_transpose_zpow [star_ring R] (A : M) : \u2200 (n : \u2124), (A ^ n)\u1d34 = A\u1d34 ^ n\n| (n : \u2115) := by rw [zpow_coe_nat, zpow_coe_nat, conj_transpose_pow]\n| -[1+ n] := by\n  rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, conj_transpose_nonsing_inv, conj_transpose_pow]\n\nend zpow\n\nend matrix\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/matrix/zpow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7109122891197893}}
{"text": "/-\nCopyright (c) 2022 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n\n! This file was ported from Lean 3 source module combinatorics.simple_graph.trails\n! leanprover-community/mathlib commit f47581155c818e6361af4e4fda60d27d020c226b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Combinatorics.SimpleGraph.Connectivity\nimport Mathbin.Data.Nat.Parity\n\n/-!\n\n# Trails and Eulerian trails\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis module contains additional theory about trails, including Eulerian trails (also known\nas Eulerian circuits).\n\n## Main definitions\n\n* `simple_graph.walk.is_eulerian` is the predicate that a trail is an Eulerian trail.\n* `simple_graph.walk.is_trail.even_countp_edges_iff` gives a condition on the number of edges\n  in a trail that can be incident to a given vertex.\n* `simple_graph.walk.is_eulerian.even_degree_iff` gives a condition on the degrees of vertices\n  when there exists an Eulerian trail.\n* `simple_graph.walk.is_eulerian.card_odd_degree` gives the possible numbers of odd-degree\n  vertices when there exists an Eulerian trail.\n\n## Todo\n\n* Prove that there exists an Eulerian trail when the conclusion to\n  `simple_graph.walk.is_eulerian.card_odd_degree` holds.\n\n## Tags\n\nEulerian trails\n\n-/\n\n\nnamespace SimpleGraph\n\nvariable {V : Type _} {G : SimpleGraph V}\n\nnamespace Walk\n\n#print SimpleGraph.Walk.IsTrail.edgesFinset /-\n/-- The edges of a trail as a finset, since each edge in a trail appears exactly once. -/\n@[reducible]\ndef IsTrail.edgesFinset {u v : V} {p : G.Walk u v} (h : p.IsTrail) : Finset (Sym2 V) :=\n  \u27e8p.edges, h.edges_nodup\u27e9\n#align simple_graph.walk.is_trail.edges_finset SimpleGraph.Walk.IsTrail.edgesFinset\n-/\n\nvariable [DecidableEq V]\n\n#print SimpleGraph.Walk.IsTrail.even_countp_edges_iff /-\ntheorem IsTrail.even_countp_edges_iff {u v : V} {p : G.Walk u v} (ht : p.IsTrail) (x : V) :\n    Even (p.edges.countp fun e => x \u2208 e) \u2194 u \u2260 v \u2192 x \u2260 u \u2227 x \u2260 v :=\n  by\n  induction' p with u u v w huv p ih\n  \u00b7 simp\n  \u00b7 rw [cons_is_trail_iff] at ht\n    specialize ih ht.1\n    simp only [List.countp_cons, Ne.def, edges_cons, Sym2.mem_iff]\n    split_ifs with h\n    \u00b7 obtain rfl | rfl := h\n      \u00b7 rw [Nat.even_add_one, ih]\n        simp only [huv.ne, imp_false, Ne.def, not_false_iff, true_and_iff, not_forall,\n          Classical.not_not, exists_prop, eq_self_iff_true, not_true, false_and_iff,\n          and_iff_right_iff_imp]\n        rintro rfl rfl\n        exact G.loopless _ huv\n      \u00b7 rw [Nat.even_add_one, ih, \u2190 not_iff_not]\n        simp only [huv.ne.symm, Ne.def, eq_self_iff_true, not_true, false_and_iff, not_forall,\n          not_false_iff, exists_prop, and_true_iff, Classical.not_not, true_and_iff, iff_and_self]\n        rintro rfl\n        exact huv.ne\n    \u00b7 rw [not_or] at h\n      simp only [h.1, h.2, not_false_iff, true_and_iff, add_zero, Ne.def] at ih\u22a2\n      rw [ih]\n      constructor <;>\n        \u00b7 rintro h' h'' rfl\n          simp only [imp_false, eq_self_iff_true, not_true, Classical.not_not] at h'\n          cases h'\n          simpa using h\n#align simple_graph.walk.is_trail.even_countp_edges_iff SimpleGraph.Walk.IsTrail.even_countp_edges_iff\n-/\n\n#print SimpleGraph.Walk.IsEulerian /-\n/-- An *Eulerian trail* (also known as an \"Eulerian path\") is a walk\n`p` that visits every edge exactly once.  The lemma `simple_graph.walk.is_eulerian.is_trail` shows\nthat these are trails.\n\nCombine with `p.is_circuit` to get an Eulerian circuit (also known as an \"Eulerian cycle\"). -/\ndef IsEulerian {u v : V} (p : G.Walk u v) : Prop :=\n  \u2200 e, e \u2208 G.edgeSetEmbedding \u2192 p.edges.count e = 1\n#align simple_graph.walk.is_eulerian SimpleGraph.Walk.IsEulerian\n-/\n\n#print SimpleGraph.Walk.IsEulerian.isTrail /-\ntheorem IsEulerian.isTrail {u v : V} {p : G.Walk u v} (h : p.IsEulerian) : p.IsTrail :=\n  by\n  rw [is_trail_def, List.nodup_iff_count_le_one]\n  intro e\n  by_cases he : e \u2208 p.edges\n  \u00b7 exact (h e (edges_subset_edge_set _ he)).le\n  \u00b7 simp [he]\n#align simple_graph.walk.is_eulerian.is_trail SimpleGraph.Walk.IsEulerian.isTrail\n-/\n\n/- warning: simple_graph.walk.is_eulerian.mem_edges_iff -> SimpleGraph.Walk.IsEulerian.mem_edges_iff is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (forall {e : Sym2.{u1} V}, Iff (Membership.Mem.{u1, u1} (Sym2.{u1} V) (List.{u1} (Sym2.{u1} V)) (List.hasMem.{u1} (Sym2.{u1} V)) e (SimpleGraph.Walk.edges.{u1} V G u v p)) (Membership.Mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.hasMem.{u1} (Sym2.{u1} V)) e (coeFn.{succ u1, succ u1} (OrderEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (SimpleGraph.hasLe.{u1} V) (Set.hasLe.{u1} (Sym2.{u1} V))) (fun (_x : RelEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) => (SimpleGraph.{u1} V) -> (Set.{u1} (Sym2.{u1} V))) (RelEmbedding.hasCoeToFun.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) (SimpleGraph.edgeSetEmbedding.{u1} V) G)))\nbut is expected to have type\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (forall {e : Sym2.{u1} V}, Iff (Membership.mem.{u1, u1} (Sym2.{u1} V) (List.{u1} (Sym2.{u1} V)) (List.instMembershipList.{u1} (Sym2.{u1} V)) e (SimpleGraph.Walk.edges.{u1} V G u v p)) (Membership.mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.instMembershipSet.{u1} (Sym2.{u1} V)) e (SimpleGraph.edgeSet.{u1} V G)))\nCase conversion may be inaccurate. Consider using '#align simple_graph.walk.is_eulerian.mem_edges_iff SimpleGraph.Walk.IsEulerian.mem_edges_iff\u2093'. -/\ntheorem IsEulerian.mem_edges_iff {u v : V} {p : G.Walk u v} (h : p.IsEulerian) {e : Sym2 V} :\n    e \u2208 p.edges \u2194 e \u2208 G.edgeSetEmbedding :=\n  \u27e8fun h => p.edges_subset_edgeSet h, fun he => by simpa using (h e he).ge\u27e9\n#align simple_graph.walk.is_eulerian.mem_edges_iff SimpleGraph.Walk.IsEulerian.mem_edges_iff\n\n/- warning: simple_graph.walk.is_eulerian.fintype_edge_set -> SimpleGraph.Walk.IsEulerian.fintypeEdgeSet is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (Fintype.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} (Sym2.{u1} V)) Type.{u1} (Set.hasCoeToSort.{u1} (Sym2.{u1} V)) (coeFn.{succ u1, succ u1} (OrderEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (SimpleGraph.hasLe.{u1} V) (Set.hasLe.{u1} (Sym2.{u1} V))) (fun (_x : RelEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) => (SimpleGraph.{u1} V) -> (Set.{u1} (Sym2.{u1} V))) (RelEmbedding.hasCoeToFun.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) (SimpleGraph.edgeSetEmbedding.{u1} V) G)))\nbut is expected to have type\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (Fintype.{u1} (Set.Elem.{u1} (Sym2.{u1} V) (SimpleGraph.edgeSet.{u1} V G)))\nCase conversion may be inaccurate. Consider using '#align simple_graph.walk.is_eulerian.fintype_edge_set SimpleGraph.Walk.IsEulerian.fintypeEdgeSet\u2093'. -/\n/-- The edge set of an Eulerian graph is finite. -/\ndef IsEulerian.fintypeEdgeSet {u v : V} {p : G.Walk u v} (h : p.IsEulerian) :\n    Fintype G.edgeSetEmbedding :=\n  Fintype.ofFinset h.IsTrail.edgesFinset fun e => by\n    simp only [Finset.mem_mk, Multiset.mem_coe, h.mem_edges_iff]\n#align simple_graph.walk.is_eulerian.fintype_edge_set SimpleGraph.Walk.IsEulerian.fintypeEdgeSet\n\n/- warning: simple_graph.walk.is_trail.is_eulerian_of_forall_mem -> SimpleGraph.Walk.IsTrail.isEulerian_of_forall_mem is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsTrail.{u1} V G u v p) -> (forall (e : Sym2.{u1} V), (Membership.Mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.hasMem.{u1} (Sym2.{u1} V)) e (coeFn.{succ u1, succ u1} (OrderEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (SimpleGraph.hasLe.{u1} V) (Set.hasLe.{u1} (Sym2.{u1} V))) (fun (_x : RelEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) => (SimpleGraph.{u1} V) -> (Set.{u1} (Sym2.{u1} V))) (RelEmbedding.hasCoeToFun.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) (SimpleGraph.edgeSetEmbedding.{u1} V) G)) -> (Membership.Mem.{u1, u1} (Sym2.{u1} V) (List.{u1} (Sym2.{u1} V)) (List.hasMem.{u1} (Sym2.{u1} V)) e (SimpleGraph.Walk.edges.{u1} V G u v p))) -> (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p)\nbut is expected to have type\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsTrail.{u1} V G u v p) -> (forall (e : Sym2.{u1} V), (Membership.mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.instMembershipSet.{u1} (Sym2.{u1} V)) e (SimpleGraph.edgeSet.{u1} V G)) -> (Membership.mem.{u1, u1} (Sym2.{u1} V) (List.{u1} (Sym2.{u1} V)) (List.instMembershipList.{u1} (Sym2.{u1} V)) e (SimpleGraph.Walk.edges.{u1} V G u v p))) -> (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p)\nCase conversion may be inaccurate. Consider using '#align simple_graph.walk.is_trail.is_eulerian_of_forall_mem SimpleGraph.Walk.IsTrail.isEulerian_of_forall_mem\u2093'. -/\ntheorem IsTrail.isEulerian_of_forall_mem {u v : V} {p : G.Walk u v} (h : p.IsTrail)\n    (hc : \u2200 e, e \u2208 G.edgeSetEmbedding \u2192 e \u2208 p.edges) : p.IsEulerian := fun e he =>\n  List.count_eq_one_of_mem h.edges_nodup (hc e he)\n#align simple_graph.walk.is_trail.is_eulerian_of_forall_mem SimpleGraph.Walk.IsTrail.isEulerian_of_forall_mem\n\n/- warning: simple_graph.walk.is_eulerian_iff -> SimpleGraph.Walk.isEulerian_iff is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} (p : SimpleGraph.Walk.{u1} V G u v), Iff (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) (And (SimpleGraph.Walk.IsTrail.{u1} V G u v p) (forall (e : Sym2.{u1} V), (Membership.Mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.hasMem.{u1} (Sym2.{u1} V)) e (coeFn.{succ u1, succ u1} (OrderEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (SimpleGraph.hasLe.{u1} V) (Set.hasLe.{u1} (Sym2.{u1} V))) (fun (_x : RelEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) => (SimpleGraph.{u1} V) -> (Set.{u1} (Sym2.{u1} V))) (RelEmbedding.hasCoeToFun.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) (SimpleGraph.edgeSetEmbedding.{u1} V) G)) -> (Membership.Mem.{u1, u1} (Sym2.{u1} V) (List.{u1} (Sym2.{u1} V)) (List.hasMem.{u1} (Sym2.{u1} V)) e (SimpleGraph.Walk.edges.{u1} V G u v p))))\nbut is expected to have type\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] {u : V} {v : V} (p : SimpleGraph.Walk.{u1} V G u v), Iff (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) (And (SimpleGraph.Walk.IsTrail.{u1} V G u v p) (forall (e : Sym2.{u1} V), (Membership.mem.{u1, u1} (Sym2.{u1} V) (Set.{u1} (Sym2.{u1} V)) (Set.instMembershipSet.{u1} (Sym2.{u1} V)) e (SimpleGraph.edgeSet.{u1} V G)) -> (Membership.mem.{u1, u1} (Sym2.{u1} V) (List.{u1} (Sym2.{u1} V)) (List.instMembershipList.{u1} (Sym2.{u1} V)) e (SimpleGraph.Walk.edges.{u1} V G u v p))))\nCase conversion may be inaccurate. Consider using '#align simple_graph.walk.is_eulerian_iff SimpleGraph.Walk.isEulerian_iff\u2093'. -/\ntheorem isEulerian_iff {u v : V} (p : G.Walk u v) :\n    p.IsEulerian \u2194 p.IsTrail \u2227 \u2200 e, e \u2208 G.edgeSetEmbedding \u2192 e \u2208 p.edges :=\n  by\n  constructor\n  \u00b7 intro h\n    exact \u27e8h.is_trail, fun _ => h.mem_edges_iff.mpr\u27e9\n  \u00b7 rintro \u27e8h, hl\u27e9\n    exact h.is_eulerian_of_forall_mem hl\n#align simple_graph.walk.is_eulerian_iff SimpleGraph.Walk.isEulerian_iff\n\n/- warning: simple_graph.walk.is_eulerian.edges_finset_eq -> SimpleGraph.Walk.IsEulerian.edgesFinset_eq is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] [_inst_2 : Fintype.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} (Sym2.{u1} V)) Type.{u1} (Set.hasCoeToSort.{u1} (Sym2.{u1} V)) (coeFn.{succ u1, succ u1} (OrderEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (SimpleGraph.hasLe.{u1} V) (Set.hasLe.{u1} (Sym2.{u1} V))) (fun (_x : RelEmbedding.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) => (SimpleGraph.{u1} V) -> (Set.{u1} (Sym2.{u1} V))) (RelEmbedding.hasCoeToFun.{u1, u1} (SimpleGraph.{u1} V) (Set.{u1} (Sym2.{u1} V)) (LE.le.{u1} (SimpleGraph.{u1} V) (SimpleGraph.hasLe.{u1} V)) (LE.le.{u1} (Set.{u1} (Sym2.{u1} V)) (Set.hasLe.{u1} (Sym2.{u1} V)))) (SimpleGraph.edgeSetEmbedding.{u1} V) G))] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v} (h : SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p), Eq.{succ u1} (Finset.{u1} (Sym2.{u1} V)) (SimpleGraph.Walk.IsTrail.edgesFinset.{u1} V G u v p (SimpleGraph.Walk.IsEulerian.isTrail.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p h)) (SimpleGraph.edgeFinset.{u1} V G _inst_2)\nbut is expected to have type\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] [_inst_2 : Fintype.{u1} (Set.Elem.{u1} (Sym2.{u1} V) (SimpleGraph.edgeSet.{u1} V G))] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v} (h : SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p), Eq.{succ u1} (Finset.{u1} (Sym2.{u1} V)) (SimpleGraph.Walk.IsTrail.edgesFinset.{u1} V G u v p (SimpleGraph.Walk.IsEulerian.isTrail.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p h)) (SimpleGraph.edgeFinset.{u1} V G _inst_2)\nCase conversion may be inaccurate. Consider using '#align simple_graph.walk.is_eulerian.edges_finset_eq SimpleGraph.Walk.IsEulerian.edgesFinset_eq\u2093'. -/\ntheorem IsEulerian.edgesFinset_eq [Fintype G.edgeSetEmbedding] {u v : V} {p : G.Walk u v}\n    (h : p.IsEulerian) : h.IsTrail.edgesFinset = G.edgeFinset :=\n  by\n  ext e\n  simp [h.mem_edges_iff]\n#align simple_graph.walk.is_eulerian.edges_finset_eq SimpleGraph.Walk.IsEulerian.edgesFinset_eq\n\n#print SimpleGraph.Walk.IsEulerian.even_degree_iff /-\ntheorem IsEulerian.even_degree_iff {x u v : V} {p : G.Walk u v} (ht : p.IsEulerian) [Fintype V]\n    [DecidableRel G.Adj] : Even (G.degree x) \u2194 u \u2260 v \u2192 x \u2260 u \u2227 x \u2260 v :=\n  by\n  convert ht.is_trail.even_countp_edges_iff x\n  rw [\u2190 Multiset.coe_countp, Multiset.countp_eq_card_filter, \u2190 card_incidence_finset_eq_degree]\n  change Multiset.card _ = _\n  congr 1\n  convert_to _ = (ht.is_trail.edges_finset.filter (Membership.Mem x)).val\n  rw [ht.edges_finset_eq, G.incidence_finset_eq_filter x]\n#align simple_graph.walk.is_eulerian.even_degree_iff SimpleGraph.Walk.IsEulerian.even_degree_iff\n-/\n\n/- warning: simple_graph.walk.is_eulerian.card_filter_odd_degree -> SimpleGraph.Walk.IsEulerian.card_filter_odd_degree is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] [_inst_2 : Fintype.{u1} V] [_inst_3 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (forall {s : Finset.{u1} V}, (Eq.{succ u1} (Finset.{u1} V) s (Finset.filter.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))) (fun (a : V) => Nat.Odd.decidablePred (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) a))) (Finset.univ.{u1} V _inst_2))) -> (Or (Eq.{1} Nat (Finset.card.{u1} V s) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (Eq.{1} Nat (Finset.card.{u1} V s) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne)))))))\nbut is expected to have type\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] [_inst_2 : Fintype.{u1} V] [_inst_3 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (forall {s : Finset.{u1} V}, (Eq.{succ u1} (Finset.{u1} V) s (Finset.filter.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))) (fun (a : V) => Nat.instDecidablePredNatOddSemiring (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) a))) (Finset.univ.{u1} V _inst_2))) -> (Or (Eq.{1} Nat (Finset.card.{u1} V s) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (Eq.{1} Nat (Finset.card.{u1} V s) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)))))\nCase conversion may be inaccurate. Consider using '#align simple_graph.walk.is_eulerian.card_filter_odd_degree SimpleGraph.Walk.IsEulerian.card_filter_odd_degree\u2093'. -/\ntheorem IsEulerian.card_filter_odd_degree [Fintype V] [DecidableRel G.Adj] {u v : V}\n    {p : G.Walk u v} (ht : p.IsEulerian) {s}\n    (h : s = (Finset.univ : Finset V).filter\u2093 fun v => Odd (G.degree v)) :\n    s.card = 0 \u2228 s.card = 2 := by\n  subst s\n  simp only [Nat.odd_iff_not_even, Finset.card_eq_zero]\n  simp only [ht.even_degree_iff, Ne.def, not_forall, not_and, Classical.not_not, exists_prop]\n  obtain rfl | hn := eq_or_ne u v\n  \u00b7 left\n    simp\n  \u00b7 right\n    convert_to _ = ({u, v} : Finset V).card\n    \u00b7 simp [hn]\n    \u00b7 congr\n      ext x\n      simp [hn, imp_iff_not_or]\n#align simple_graph.walk.is_eulerian.card_filter_odd_degree SimpleGraph.Walk.IsEulerian.card_filter_odd_degree\n\n/- warning: simple_graph.walk.is_eulerian.card_odd_degree -> SimpleGraph.Walk.IsEulerian.card_odd_degree is a dubious translation:\nlean 3 declaration is\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] [_inst_2 : Fintype.{u1} V] [_inst_3 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (Or (Eq.{1} Nat (Fintype.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} V) Type.{u1} (Set.hasCoeToSort.{u1} V) (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (Subtype.fintype.{u1} V (fun (x : V) => Membership.Mem.{u1, u1} V (Set.{u1} V) (Set.hasMem.{u1} V) x (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (fun (a : V) => Set.decidableSetOf.{u1} V a (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))) (Nat.Odd.decidablePred (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) a)))) _inst_2)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (Eq.{1} Nat (Fintype.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} V) Type.{u1} (Set.hasCoeToSort.{u1} V) (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (Subtype.fintype.{u1} V (fun (x : V) => Membership.Mem.{u1, u1} V (Set.{u1} V) (Set.hasMem.{u1} V) x (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (fun (a : V) => Set.decidableSetOf.{u1} V a (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))) (Nat.Odd.decidablePred (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) a)))) _inst_2)) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))))\nbut is expected to have type\n  forall {V : Type.{u1}} {G : SimpleGraph.{u1} V} [_inst_1 : DecidableEq.{succ u1} V] [_inst_2 : Fintype.{u1} V] [_inst_3 : DecidableRel.{succ u1} V (SimpleGraph.Adj.{u1} V G)] {u : V} {v : V} {p : SimpleGraph.Walk.{u1} V G u v}, (SimpleGraph.Walk.IsEulerian.{u1} V G (fun (a : V) (b : V) => _inst_1 a b) u v p) -> (Or (Eq.{1} Nat (Fintype.card.{u1} (Set.Elem.{u1} V (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (Subtype.fintype.{u1} V (fun (x : V) => Membership.mem.{u1, u1} V (Set.{u1} V) (Set.instMembershipSet.{u1} V) x (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (fun (a : V) => Set.decidableSetOf.{u1} V a (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))) (Nat.instDecidablePredNatOddSemiring (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) a)))) _inst_2)) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (Eq.{1} Nat (Fintype.card.{u1} (Set.Elem.{u1} V (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (Subtype.fintype.{u1} V (fun (x : V) => Membership.mem.{u1, u1} V (Set.{u1} V) (Set.instMembershipSet.{u1} V) x (setOf.{u1} V (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))))) (fun (a : V) => Set.decidableSetOf.{u1} V a (fun (v : V) => Odd.{0} Nat Nat.semiring (SimpleGraph.degree.{u1} V G v (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) v))) (Nat.instDecidablePredNatOddSemiring (SimpleGraph.degree.{u1} V G a (SimpleGraph.neighborSetFintype.{u1} V G _inst_2 (fun (a : V) (b : V) => _inst_3 a b) a)))) _inst_2)) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))))\nCase conversion may be inaccurate. Consider using '#align simple_graph.walk.is_eulerian.card_odd_degree SimpleGraph.Walk.IsEulerian.card_odd_degree\u2093'. -/\ntheorem IsEulerian.card_odd_degree [Fintype V] [DecidableRel G.Adj] {u v : V} {p : G.Walk u v}\n    (ht : p.IsEulerian) :\n    Fintype.card { v : V | Odd (G.degree v) } = 0 \u2228 Fintype.card { v : V | Odd (G.degree v) } = 2 :=\n  by\n  rw [\u2190 Set.toFinset_card]\n  apply is_eulerian.card_filter_odd_degree ht\n  ext v\n  simp\n#align simple_graph.walk.is_eulerian.card_odd_degree SimpleGraph.Walk.IsEulerian.card_odd_degree\n\nend Walk\n\nend SimpleGraph\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/SimpleGraph/Trails.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7109122845697878}}
{"text": "import algebra.order.field.basic algebra.order.floor\n\n/-! # IMO 2010 A1 (P1) -/\n\nnamespace IMOSL\nnamespace IMO2010A1\n\nvariables {F : Type*} [linear_ordered_field F] [floor_ring F]\n\n/-- For any `r : F` with `1 < r`, we have `\u230ar\u207b\u00b9\u230b = 0`. -/\nlemma inv_floor_eq_zero {r : F} (h : 1 < r) : \u230ar\u207b\u00b9\u230b = 0 :=\n  by rw [int.floor_eq_iff, int.cast_zero, zero_add, inv_nonneg];\n    exact \u27e8le_of_lt (lt_trans zero_lt_one h), inv_lt_one h\u27e9\n\n\n\n/-- Final solution -/\ntheorem final_solution {R : Type*} [linear_ordered_ring R] [floor_ring R] (f : F \u2192 R) :\n  (\u2200 x y : F, f (\u230ax\u230b * y) = f x * \u230af y\u230b) \u2194 \u2203 C : R, (\u230aC\u230b = 1 \u2228 C = 0) \u2227 f = \u03bb _, C :=\nbegin\n  ---- `\u2192` direction\n  symmetry; refine \u27e8\u03bb h x y, _, \u03bb h, \u27e8f 0, _\u27e9\u27e9,\n  rcases h with \u27e8C, h | rfl, rfl\u27e9,\n  rw [h, int.cast_one, mul_one],\n  rw zero_mul,\n\n  ---- `\u2190` direction; the case `\u230af(0)\u230b = 1` is easier\n  have h0 := h 0 0,\n  rw [mul_zero, eq_comm, mul_right_eq_self\u2080, \u2190 int.cast_one, int.cast_inj] at h0,\n  refine \u27e8h0, _\u27e9; cases h0 with h0 h0,\n  funext x; replace h := h x 0,\n  rwa [mul_zero, h0, int.cast_one, mul_one, eq_comm] at h,\n\n  ---- Now work on the case `f(0) = 0`\n  suffices h1 : f 1 = 0,\n    funext x; rw h0; replace h := h 1 x;\n      rwa [h1, zero_mul, int.floor_one, int.cast_one, one_mul] at h,\n  suffices h1 : \u230af 2\u207b\u00b9\u230b = 0,\n    replace h := h 2 2\u207b\u00b9; rwa [h1, int.cast_zero, mul_zero, \u2190 int.cast_two,\n      int.floor_int_cast, int.cast_two, mul_inv_cancel (two_ne_zero : (2 : F) \u2260 0)] at h,\n  replace h := h 2\u207b\u00b9 2\u207b\u00b9,\n  rw [inv_floor_eq_zero (one_lt_two : (1 : F) < 2), int.cast_zero, zero_mul, h0, zero_eq_mul] at h,\n  cases h with h h,\n  rw [h, int.floor_zero],\n  rwa int.cast_eq_zero at h\nend\n\nend IMO2010A1\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2010/A1/A1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7109122841378257}}
{"text": "import .love06_monads_demo\n\n\n/-! # LoVe Exercise 6: Monads -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: A State Monad with Failure\n\nWe introduce a richer notion of lawful monad that provides an `orelse`\noperator `<|>` satisfying some laws, given below. `emp` denotes failure.\n`x <|> y` tries `x` first, falling back on `y` on failure. -/\n\n@[class] structure lawful_monad_with_orelse (m : Type \u2192 Type)\n  extends lawful_monad m, has_orelse m : Type 1 :=\n(emp {} {\u03b1 : Type} : m \u03b1)\n(emp_orelse {\u03b1 : Type} (a : m \u03b1) :\n  (emp <|> a) = a)\n(orelse_emp {\u03b1 : Type} (a : m \u03b1) :\n  (a <|> emp) = a)\n(orelse_assoc {\u03b1 : Type} (a b c : m \u03b1) :\n  ((a <|> b) <|> c) = (a <|> (b <|> c)))\n(emp_bind {\u03b1 \u03b2 : Type} (f : \u03b1 \u2192 m \u03b2) :\n  (emp >>= f) = emp)\n(bind_emp {\u03b1 \u03b2 : Type} (f : m \u03b1) :\n  (f >>= (\u03bba, emp : \u03b1 \u2192 m \u03b2)) = emp)\n\n/-! 1.1. We set up the `option` type constructor to be a\n`lawful_monad_with_orelse`. Complete the proofs.\n\nHint: Use `simp [(>>=)]` if you want to unfold the definition of the bind\noperator. -/\n\ndef option.orelse {\u03b1 : Type} : option \u03b1 \u2192 option \u03b1 \u2192 option \u03b1\n| option.none     ma' := ma'\n| (option.some a) _   := option.some a\n\n@[instance] def lawful_monad_with_orelse_option :\n  lawful_monad_with_orelse option :=\n{ emp          := \u03bb\u03b1, option.none,\n  orelse       := @option.orelse,\n  emp_orelse   :=\n    begin\n      intros \u03b1 a,\n      refl\n    end,\n  orelse_emp   :=\n    begin\n      intros \u03b1 a,\n      cases' a,\n      { refl },\n      { refl }\n    end,\n  orelse_assoc :=\n    begin\n      intros \u03b1 a b c,\n      cases' a,\n      { refl },\n      { refl }\n    end,\n  emp_bind     :=\n    begin\n      intros \u03b1 \u03b2 f,\n      refl\n    end,\n  bind_emp     :=\n    begin\n      intros \u03b1 \u03b2 g,\n      cases' g,\n      { refl },\n      { refl }\n    end,\n  .. option.lawful_monad }\n\n@[simp] lemma option.some_bind {\u03b1 \u03b2 : Type} (a : \u03b1) (g : \u03b1 \u2192 option \u03b2) :\n  (option.some a >>= g) = g a :=\nby refl\n\n/-! Let us enable some convenient pattern matching syntax, by instantiating\nLean's `monad_fail` type class. (Do not worry if you do not understand what\nwe are referring to.) -/\n\n@[instance] def lawful_monad_with_orelse.monad_fail {m : Type \u2192 Type}\n  [lawful_monad_with_orelse m] : monad_fail m :=\n{ fail := \u03bb\u03b1 msg, lawful_monad_with_orelse.emp }\n\n/-! Now we can write definitions such as the following: -/\n\ndef first_of_three {m : Type \u2192 Type} [lawful_monad_with_orelse m]\n  (c : m (list \u2115)) : m \u2115 :=\ndo\n  [n, _, _] \u2190 c,\n  pure n\n\n#eval first_of_three (option.some [1])\n#eval first_of_three (option.some [1, 2, 3])\n#eval first_of_three (option.some [1, 2, 3, 4])\n\n/-! Using `lawful_monad_with_orelse` and the `monad_fail` syntax, we can give a\nconcise definition for the `sum_2_5_7` function seen in the lecture. -/\n\ndef sum_2_5_7\u2087 {m : Type \u2192 Type} [lawful_monad_with_orelse m]\n  (c : m (list \u2115)) : m \u2115 :=\ndo\n  (_ :: n2 :: _ :: _ :: n5 :: _ :: n7 :: _) \u2190 c,\n  pure (n2 + n5 + n7)\n\n/-! 1.2. Now we are ready to define `faction \u03c3` (\"eff action\"): a monad with an\ninternal state of type `\u03c3` that can fail (unlike `action \u03c3`).\n\nWe start with defining `faction \u03c3 \u03b1`, where `\u03c3` is the type of the internal\nstate, and `\u03b1` is the type of the value stored in the monad. We use `option` to\nmodel failure. This means we can also use the monad operations of `option` when\ndefining the monad operations on `faction`.\n\nHints:\n\n* Remember that `faction \u03c3 \u03b1` is an alias for a function type, so you can use\n  pattern matching and `\u03bbs, \u2026` to define values of type `faction \u03c3 \u03b1`.\n\n* `faction` is very similar to `action` from the lecture's demo. You can look\n  there for inspiration. -/\n\ndef faction (\u03c3 : Type) (\u03b1 : Type) : Type :=\n\u03c3 \u2192 option (\u03b1 \u00d7 \u03c3)\n\n/-! 1.3. Define the `get` and `set` function for `faction`, where `get` returns\nthe state passed along the state monad and `set s` changes the state to `s`. -/\n\ndef get {\u03c3 : Type} : faction \u03c3 \u03c3\n| s := option.some (s, s)\n\ndef set {\u03c3 : Type} (s : \u03c3) : faction \u03c3 unit\n| _ := option.some ((), s)\n\n/-! We set up the `>>=` syntax on `faction`: -/\n\ndef faction.bind {\u03c3 \u03b1 \u03b2 : Type} (f : faction \u03c3 \u03b1) (g : \u03b1 \u2192 faction \u03c3 \u03b2) :\n  faction \u03c3 \u03b2\n| s := f s >>= (\u03bbas, g (prod.fst as) (prod.snd as))\n\n@[instance] def faction.has_bind {\u03c3 : Type} : has_bind (faction \u03c3) :=\n{ bind := @faction.bind \u03c3 }\n\nlemma faction.bind_apply {\u03c3 \u03b1 \u03b2 : Type} (f : faction \u03c3 \u03b1) (g : \u03b1 \u2192 faction \u03c3 \u03b2)\n    (s : \u03c3) :\n  (f >>= g) s = (f s >>= (\u03bbas, g (prod.fst as) (prod.snd as))) :=\nby refl\n\n/-! 1.4. Define the operator `pure` for `faction`, in such a way that it will\nsatisfy the three laws. -/\n\ndef faction.pure {\u03c3 \u03b1 : Type} (a : \u03b1) : faction \u03c3 \u03b1\n| s := option.some (a, s)\n\n/-! We set up the syntax for `pure` on `faction`: -/\n\n@[instance] def faction.has_pure {\u03c3 : Type} : has_pure (faction \u03c3) :=\n{ pure := @faction.pure \u03c3 }\n\nlemma faction.pure_apply {\u03c3 \u03b1 : Type} (a : \u03b1) (s : \u03c3) :\n  (pure a : faction \u03c3 \u03b1) s = option.some (a, s) :=\nby refl\n\n/-! 1.3. Register `faction` as a monad.\n\nHints:\n\n* The `funext` lemma is useful when you need to prove equality between two\n  functions.\n\n* `cases' f s` only works when `f s` appears in your goal, so you may need to\n  unfold some constants before you can invoke `cases'`. -/\n\n@[instance] def faction.lawful_monad {\u03c3 : Type} : lawful_monad (faction \u03c3) :=\n{ pure_bind  :=\n    begin\n      intros \u03b1 \u03b2 a f,\n      apply funext,\n      intro s,\n      refl\n    end,\n  bind_pure  :=\n    begin\n      intros \u03b1 ma,\n      apply funext,\n      intro s,\n      simp [faction.bind_apply, faction.pure_apply],\n      apply lawful_monad.bind_pure\n    end,\n  bind_assoc :=\n    begin\n      intros \u03b1 \u03b2 \u03b3 f g ma,\n      apply funext,\n      intro s,\n      simp [faction.bind_apply],\n      cases' ma s,\n      { refl },\n      { cases' val,\n        refl }\n    end,\n  .. faction.has_bind,\n  .. faction.has_pure }\n\n\n/-! ## Question 2: Kleisli Operator\n\nThe Kleisli operator `>=>` (not to be confused with `>>=`) is useful for\npipelining effectful functions. Note that `\u03bba, f a >>= g` is to be parsed as\n`\u03bba, (f a >>= g)`, not as `(\u03bba, f a) >>= g`. -/\n\ndef kleisli {m : Type \u2192 Type} [lawful_monad m] {\u03b1 \u03b2 \u03b3 : Type} (f : \u03b1 \u2192 m \u03b2)\n  (g : \u03b2 \u2192 m \u03b3) : \u03b1 \u2192 m \u03b3 :=\n\u03bba, f a >>= g\n\ninfixr ` >=> ` : 90 := kleisli\n\n/-! 2.1. Prove that `pure` is a left and right unit for the Kleisli operator. -/\n\nlemma pure_kleisli {m : Type \u2192 Type} [lawful_monad m] {\u03b1 \u03b2 : Type}\n    (f : \u03b1 \u2192 m \u03b2) :\n  (pure >=> f) = f :=\nbegin\n  apply funext,\n  intro a,\n  exact lawful_monad.pure_bind a f\nend\n\nlemma kleisli_pure {m : Type \u2192 Type} [lawful_monad m] {\u03b1 \u03b2 : Type}\n    (f : \u03b1 \u2192 m \u03b2) :\n  (f >=> pure) = f :=\nbegin\n  apply funext,\n  intro a,\n  exact lawful_monad.bind_pure (f a)\nend\n\n/-! 2.2. Prove that the Kleisli operator is associative. -/\n\nlemma kleisli_assoc {m : Type \u2192 Type} [lawful_monad m] {\u03b1 \u03b2 \u03b3 \u03b4 : Type}\n    (f : \u03b1 \u2192 m \u03b2) (g : \u03b2 \u2192 m \u03b3) (h : \u03b3 \u2192 m \u03b4) :\n  ((f >=> g) >=> h) = (f >=> (g >=> h)) :=\nbegin\n  apply funext,\n  intro a,\n  exact lawful_monad.bind_assoc g h (f a)\nend\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2021", "sha": "23b469c79afd482fa66da82e4726a317e3a7b5d5", "save_path": "github-repos/lean/blanchette-logical_verification_2021", "path": "github-repos/lean/blanchette-logical_verification_2021/logical_verification_2021-23b469c79afd482fa66da82e4726a317e3a7b5d5/lean/love06_monads_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7108768518192328}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n\n! This file was ported from Lean 3 source module group_theory.free_group\n! leanprover-community/mathlib commit f93c11933efbc3c2f0299e47b8ff83e9b539cbf6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Fintype.Basic\nimport Mathlib.Data.List.Sublists\nimport Mathlib.Data.List.Basic\nimport Mathlib.GroupTheory.Subgroup.Basic\n\n/-!\n# Free groups\n\nThis file defines free groups over a type. Furthermore, it is shown that the free group construction\nis an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful\nfunctor from groups to types, see `Algebra/Category/Group/Adjunctions`.\n\n## Main definitions\n\n* `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type\n  `\u03b1` defined as the words over `a : \u03b1 \u00d7 Bool` modulo the relation `a * x * x\u207b\u00b9 * b = a * b`.\n* `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (\u03b1 \u00d7 Bool) \u2192 FreeGroup \u03b1`.\n* `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `\u03b1 \u2192 FreeGroup \u03b1`.\n* `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup \u03b1 \u2192* G`\n  given a group `G` and a function `f : \u03b1 \u2192 G`.\n\n## Main statements\n\n* `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word\n  reduction (also known as Newman's diamond lemma).\n* `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type\n  is isomorphic to the integers.\n* The free group construction is an instance of a monad.\n\n## Implementation details\n\nFirst we introduce the one step reduction relation `FreeGroup.Red.Step`:\n`w * x * x\u207b\u00b9 * v   ~>   w * v`, its reflexive transitive closure `FreeGroup.Red.trans`\nand prove that its join is an equivalence relation. Then we introduce `FreeGroup \u03b1` as a quotient\nover `FreeGroup.Red.Step`.\n\nFor the additive version we introduce the same relation under a different name so that we can\ndistinguish the quotient types more easily.\n\n\n## Tags\n\nfree group, Newman's diamond lemma, Church-Rosser theorem\n-/\n\nopen Relation\n\nuniverse u v w\n\nvariable {\u03b1 : Type u}\n\nattribute [local simp] List.append_eq_has_append\n\n-- porting notes: to_additive.map_namespace is not supported yet\n-- worked aruond it by putting a few extra manual mappings (but not too many all in all)\n-- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup\n\n/-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/\ninductive FreeAddGroup.Red.Step : List (\u03b1 \u00d7 Bool) \u2192 List (\u03b1 \u00d7 Bool) \u2192 Prop\n  | not {L\u2081 L\u2082 x b} : FreeAddGroup.Red.Step (L\u2081 ++ (x, b) :: (x, not b) :: L\u2082) (L\u2081 ++ L\u2082)\n#align free_add_group.red.step FreeAddGroup.Red.Step\n\nattribute [simp] FreeAddGroup.Red.Step.not\n\n/-- Reduction step for the multiplicative free group relation: `w * x * x\u207b\u00b9 * v ~> w * v` -/\n@[to_additive FreeAddGroup.Red.Step]\ninductive FreeGroup.Red.Step : List (\u03b1 \u00d7 Bool) \u2192 List (\u03b1 \u00d7 Bool) \u2192 Prop\n  | not {L\u2081 L\u2082 x b} : FreeGroup.Red.Step (L\u2081 ++ (x, b) :: (x, not b) :: L\u2082) (L\u2081 ++ L\u2082)\n#align free_group.red.step FreeGroup.Red.Step\n\nattribute [simp] FreeGroup.Red.Step.not\n\nnamespace FreeGroup\n\nvariable {L L\u2081 L\u2082 L\u2083 L\u2084 : List (\u03b1 \u00d7 Bool)}\n\n/-- Reflexive-transitive closure of `Red.Step` -/\n@[to_additive FreeAddGroup.Red \"Reflexive-transitive closure of `Red.Step`\"]\ndef Red : List (\u03b1 \u00d7 Bool) \u2192 List (\u03b1 \u00d7 Bool) \u2192 Prop :=\n  ReflTransGen Red.Step\n#align free_group.red FreeGroup.Red\n#align free_add_group.red FreeAddGroup.Red\n\n@[to_additive (attr:=refl)]\ntheorem Red.refl : Red L L :=\n  ReflTransGen.refl\n#align free_group.red.refl FreeGroup.Red.refl\n#align free_add_group.red.refl FreeAddGroup.Red.refl\n\n@[to_additive (attr:=trans)]\ntheorem Red.trans : Red L\u2081 L\u2082 \u2192 Red L\u2082 L\u2083 \u2192 Red L\u2081 L\u2083 :=\n  ReflTransGen.trans\n#align free_group.red.trans FreeGroup.Red.trans\n#align free_add_group.red.trans FreeAddGroup.Red.trans\n\nnamespace Red\n\n/-- Predicate asserting that the word `w\u2081` can be reduced to `w\u2082` in one step, i.e. there are words\n`w\u2083 w\u2084` and letter `x` such that `w\u2081 = w\u2083xx\u207b\u00b9w\u2084` and `w\u2082 = w\u2083w\u2084`  -/\n@[to_additive \"Predicate asserting that the word `w\u2081` can be reduced to `w\u2082` in one step, i.e. there\n  are words `w\u2083 w\u2084` and letter `x` such that `w\u2081 = w\u2083 + x + (-x) + w\u2084` and `w\u2082 = w\u2083w\u2084`\"]\ntheorem Step.length : \u2200 {L\u2081 L\u2082 : List (\u03b1 \u00d7 Bool)}, Step L\u2081 L\u2082 \u2192 L\u2082.length + 2 = L\u2081.length\n  | _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl\n#align free_group.red.step.length FreeGroup.Red.Step.length\n#align free_add_group.red.step.length FreeAddGroup.Red.Step.length\n\n@[to_additive (attr:=simp)]\ntheorem Step.not_rev {x b} : Step (L\u2081 ++ (x, !b) :: (x, b) :: L\u2082) (L\u2081 ++ L\u2082) := by\n  cases b <;> exact Step.not\n#align free_group.red.step.bnot_rev FreeGroup.Red.Step.not_rev\n#align free_add_group.red.step.bnot_rev FreeAddGroup.Red.Step.not_rev\n\n@[to_additive (attr:=simp)]\ntheorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L :=\n  @Step.not _ [] _ _ _\n#align free_group.red.step.cons_bnot FreeGroup.Red.Step.cons_not\n#align free_add_group.red.step.cons_bnot FreeAddGroup.Red.Step.cons_not\n\n@[to_additive (attr:=simp)]\ntheorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L :=\n  @Red.Step.not_rev _ [] _ _ _\n#align free_group.red.step.cons_bnot_rev FreeGroup.Red.Step.cons_not_rev\n#align free_add_group.red.step.cons_bnot_rev FreeAddGroup.Red.Step.cons_not_rev\n\n@[to_additive]\ntheorem Step.append_left : \u2200 {L\u2081 L\u2082 L\u2083 : List (\u03b1 \u00d7 Bool)}, Step L\u2082 L\u2083 \u2192 Step (L\u2081 ++ L\u2082) (L\u2081 ++ L\u2083)\n  | _, _, _, Red.Step.not => by rw [\u2190 List.append_assoc, \u2190 List.append_assoc]; constructor\n#align free_group.red.step.append_left FreeGroup.Red.Step.append_left\n#align free_add_group.red.step.append_left FreeAddGroup.Red.Step.append_left\n\n@[to_additive]\ntheorem Step.cons {x} (H : Red.Step L\u2081 L\u2082) : Red.Step (x :: L\u2081) (x :: L\u2082) :=\n  @Step.append_left _ [x] _ _ H\n#align free_group.red.step.cons FreeGroup.Red.Step.cons\n#align free_add_group.red.step.cons FreeAddGroup.Red.Step.cons\n\n@[to_additive]\ntheorem Step.append_right : \u2200 {L\u2081 L\u2082 L\u2083 : List (\u03b1 \u00d7 Bool)}, Step L\u2081 L\u2082 \u2192 Step (L\u2081 ++ L\u2083) (L\u2082 ++ L\u2083)\n  | _, _, _, Red.Step.not => by simp\n#align free_group.red.step.append_right FreeGroup.Red.Step.append_right\n#align free_add_group.red.step.append_right FreeAddGroup.Red.Step.append_right\n\n@[to_additive]\ntheorem not_step_nil : \u00acStep [] L := by\n  generalize h' : [] = L'\n  intro h\n  cases' h with L\u2081 L\u2082\n  simp [List.nil_eq_append] at h'\n#align free_group.red.not_step_nil FreeGroup.Red.not_step_nil\n#align free_add_group.red.not_step_nil FreeAddGroup.Red.not_step_nil\n\n@[to_additive]\ntheorem Step.cons_left_iff {a : \u03b1} {b : Bool} :\n    Step ((a, b) :: L\u2081) L\u2082 \u2194 (\u2203 L, Step L\u2081 L \u2227 L\u2082 = (a, b) :: L) \u2228 L\u2081 = (a, ! b) :: L\u2082 := by\n  constructor\n  \u00b7 generalize hL : ((a, b) :: L\u2081 : List _) = L\n    rintro @\u27e8_ | \u27e8p, s'\u27e9, e, a', b'\u27e9\n    \u00b7 simp at hL\n      simp [*]\n    \u00b7 simp at hL\n      rcases hL with \u27e8rfl, rfl\u27e9\n      refine' Or.inl \u27e8s' ++ e, Step.not, _\u27e9\n      simp\n  \u00b7 rintro (\u27e8L, h, rfl\u27e9 | rfl)\n    \u00b7 exact Step.cons h\n    \u00b7 exact Step.cons_not\n#align free_group.red.step.cons_left_iff FreeGroup.Red.Step.cons_left_iff\n#align free_add_group.red.step.cons_left_iff FreeAddGroup.Red.Step.cons_left_iff\n\n@[to_additive]\ntheorem not_step_singleton : \u2200 {p : \u03b1 \u00d7 Bool}, \u00acStep [p] L\n  | (a, b) => by simp [Step.cons_left_iff, not_step_nil]\n#align free_group.red.not_step_singleton FreeGroup.Red.not_step_singleton\n#align free_add_group.red.not_step_singleton FreeAddGroup.Red.not_step_singleton\n\n@[to_additive]\ntheorem Step.cons_cons_iff : \u2200 {p : \u03b1 \u00d7 Bool}, Step (p :: L\u2081) (p :: L\u2082) \u2194 Step L\u2081 L\u2082 := by\n  simp (config := { contextual := true }) [Step.cons_left_iff, iff_def, or_imp]\n#align free_group.red.step.cons_cons_iff FreeGroup.Red.Step.cons_cons_iff\n#align free_add_group.red.step.cons_cons_iff FreeAddGroup.Red.Step.cons_cons_iff\n\n@[to_additive]\ntheorem Step.append_left_iff : \u2200 L, Step (L ++ L\u2081) (L ++ L\u2082) \u2194 Step L\u2081 L\u2082\n  | [] => by simp\n  | p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff]\n#align free_group.red.step.append_left_iff FreeGroup.Red.Step.append_left_iff\n#align free_add_group.red.step.append_left_iff FreeAddGroup.Red.Step.append_left_iff\n\n@[to_additive]\ntheorem Step.diamond_aux :\n    \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : List (\u03b1 \u00d7 Bool)} {x1 b1 x2 b2},\n      L\u2081 ++ (x1, b1) :: (x1, !b1) :: L\u2082 = L\u2083 ++ (x2, b2) :: (x2, !b2) :: L\u2084 \u2192\n        L\u2081 ++ L\u2082 = L\u2083 ++ L\u2084 \u2228 \u2203 L\u2085, Red.Step (L\u2081 ++ L\u2082) L\u2085 \u2227 Red.Step (L\u2083 ++ L\u2084) L\u2085\n  | [], _, [], _, _, _, _, _, H => by injections ; subst_vars ; simp\n  | [], _, [(x3, b3)], _, _, _, _, _, H => by injections ; subst_vars ; simp\n  | [(x3, b3)], _, [], _, _, _, _, _, H => by injections ; subst_vars ; simp\n  | [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by\n    injections ; subst_vars ; simp ; right ; exact \u27e8_, Red.Step.not, Red.Step.cons_not\u27e9\n  | (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by\n    injections ; subst_vars ; simp ; right ; exact \u27e8_, Red.Step.cons_not, Red.Step.not\u27e9\n  | (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H =>\n    let \u27e8H1, H2\u27e9 := List.cons.inj H\n    match Step.diamond_aux H2 with\n    | Or.inl H3 => Or.inl <| by simp [H1, H3]\n    | Or.inr \u27e8L\u2085, H3, H4\u27e9 => Or.inr \u27e8_, Step.cons H3, by simpa [H1] using Step.cons H4\u27e9\n#align free_group.red.step.diamond_aux FreeGroup.Red.Step.diamond_aux\n#align free_add_group.red.step.diamond_aux FreeAddGroup.Red.Step.diamond_aux\n\n@[to_additive]\ntheorem Step.diamond :\n    \u2200 {L\u2081 L\u2082 L\u2083 L\u2084 : List (\u03b1 \u00d7 Bool)},\n      Red.Step L\u2081 L\u2083 \u2192 Red.Step L\u2082 L\u2084 \u2192 L\u2081 = L\u2082 \u2192 L\u2083 = L\u2084 \u2228 \u2203 L\u2085, Red.Step L\u2083 L\u2085 \u2227 Red.Step L\u2084 L\u2085\n  | _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H\n#align free_group.red.step.diamond FreeGroup.Red.Step.diamond\n#align free_add_group.red.step.diamond FreeAddGroup.Red.Step.diamond\n\n@[to_additive]\ntheorem Step.to_red : Step L\u2081 L\u2082 \u2192 Red L\u2081 L\u2082 :=\n  ReflTransGen.single\n#align free_group.red.step.to_red FreeGroup.Red.Step.to_red\n#align free_add_group.red.step.to_red FreeAddGroup.Red.Step.to_red\n\n/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces\nto `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`\nrespectively. This is also known as Newman's diamond lemma. -/\n@[to_additive\n  \"**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces\n  to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`\n  respectively. This is also known as Newman's diamond lemma.\"]\ntheorem church_rosser : Red L\u2081 L\u2082 \u2192 Red L\u2081 L\u2083 \u2192 Join Red L\u2082 L\u2083 :=\n  Relation.church_rosser fun a b c hab hac =>\n    match b, c, Red.Step.diamond hab hac rfl with\n    | b, _, Or.inl rfl => \u27e8b, by rfl, by rfl\u27e9\n    | b, c, Or.inr \u27e8d, hbd, hcd\u27e9 => \u27e8d, ReflGen.single hbd, hcd.to_red\u27e9\n#align free_group.red.church_rosser FreeGroup.Red.church_rosser\n#align free_add_group.red.church_rosser FreeAddGroup.Red.church_rosser\n\n@[to_additive]\ntheorem cons_cons {p} : Red L\u2081 L\u2082 \u2192 Red (p :: L\u2081) (p :: L\u2082) :=\n  ReflTransGen.lift (List.cons p) fun _ _ => Step.cons\n#align free_group.red.cons_cons FreeGroup.Red.cons_cons\n#align free_add_group.red.cons_cons FreeAddGroup.Red.cons_cons\n\n@[to_additive]\ntheorem cons_cons_iff (p) : Red (p :: L\u2081) (p :: L\u2082) \u2194 Red L\u2081 L\u2082 :=\n  Iff.intro\n    (by\n      generalize eq\u2081 : (p :: L\u2081 : List _) = LL\u2081\n      generalize eq\u2082 : (p :: L\u2082 : List _) = LL\u2082\n      intro h\n      induction' h using Relation.ReflTransGen.head_induction_on\n        with L\u2081 L\u2082 h\u2081\u2082 h ih\n        generalizing L\u2081 L\u2082\n      \u00b7 subst_vars\n        cases eq\u2082\n        cases eq\u2081\n        constructor\n      \u00b7 subst_vars\n        cases eq\u2082\n        cases' p with a b\n        rw [Step.cons_left_iff] at h\u2081\u2082\n        rcases h\u2081\u2082 with (\u27e8L, h\u2081\u2082, rfl\u27e9 | rfl)\n        \u00b7 exact (ih rfl rfl).head h\u2081\u2082\n        \u00b7 exact (cons_cons h).tail Step.cons_not_rev)\n    cons_cons\n#align free_group.red.cons_cons_iff FreeGroup.Red.cons_cons_iff\n#align free_add_group.red.cons_cons_iff FreeAddGroup.Red.cons_cons_iff\n\n@[to_additive]\ntheorem append_append_left_iff : \u2200 L, Red (L ++ L\u2081) (L ++ L\u2082) \u2194 Red L\u2081 L\u2082\n  | [] => Iff.rfl\n  | p :: L => by simp [append_append_left_iff L, cons_cons_iff]\n#align free_group.red.append_append_left_iff FreeGroup.Red.append_append_left_iff\n#align free_add_group.red.append_append_left_iff FreeAddGroup.Red.append_append_left_iff\n\n@[to_additive]\ntheorem append_append (h\u2081 : Red L\u2081 L\u2083) (h\u2082 : Red L\u2082 L\u2084) : Red (L\u2081 ++ L\u2082) (L\u2083 ++ L\u2084) :=\n  (h\u2081.lift (fun L => L ++ L\u2082) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h\u2082)\n#align free_group.red.append_append FreeGroup.Red.append_append\n#align free_add_group.red.append_append FreeAddGroup.Red.append_append\n\n@[to_additive]\ntheorem to_append_iff : Red L (L\u2081 ++ L\u2082) \u2194 \u2203 L\u2083 L\u2084, L = L\u2083 ++ L\u2084 \u2227 Red L\u2083 L\u2081 \u2227 Red L\u2084 L\u2082 :=\n  Iff.intro\n    (by\n      generalize eq : L\u2081 ++ L\u2082 = L\u2081\u2082\n      intro h\n      induction' h with L' L\u2081\u2082 hLL' h ih generalizing L\u2081 L\u2082\n      \u00b7 exact \u27e8_, _, eq.symm, by rfl, by rfl\u27e9\n      \u00b7 cases' h with s e a b\n        rcases List.append_eq_append_iff.1 eq with (\u27e8s', rfl, rfl\u27e9 | \u27e8e', rfl, rfl\u27e9)\n        \u00b7 have : L\u2081 ++ (s' ++ (a, b) :: (a, not b) :: e) = L\u2081 ++ s' ++ (a, b) :: (a, not b) :: e :=\n            by simp\n          rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9\n          exact \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082.tail Step.not\u27e9\n        \u00b7 have : s ++ (a, b) :: (a, not b) :: e' ++ L\u2082 = s ++ (a, b) :: (a, not b) :: (e' ++ L\u2082) :=\n            by simp\n          rcases ih this with \u27e8w\u2081, w\u2082, rfl, h\u2081, h\u2082\u27e9\n          exact \u27e8w\u2081, w\u2082, rfl, h\u2081.tail Step.not, h\u2082\u27e9)\n    fun \u27e8L\u2083, L\u2084, Eq, h\u2083, h\u2084\u27e9 => Eq.symm \u25b8 append_append h\u2083 h\u2084\n#align free_group.red.to_append_iff FreeGroup.Red.to_append_iff\n#align free_add_group.red.to_append_iff FreeAddGroup.Red.to_append_iff\n\n/-- The empty word `[]` only reduces to itself. -/\n@[to_additive \"The empty word `[]` only reduces to itself.\"]\ntheorem nil_iff : Red [] L \u2194 L = [] :=\n  reflTransGen_iff_eq fun _ => Red.not_step_nil\n#align free_group.red.nil_iff FreeGroup.Red.nil_iff\n#align free_add_group.red.nil_iff FreeAddGroup.Red.nil_iff\n\n/-- A letter only reduces to itself. -/\n@[to_additive \"A letter only reduces to itself.\"]\ntheorem singleton_iff {x} : Red [x] L\u2081 \u2194 L\u2081 = [x] :=\n  reflTransGen_iff_eq fun _ => not_step_singleton\n#align free_group.red.singleton_iff FreeGroup.Red.singleton_iff\n#align free_add_group.red.singleton_iff FreeAddGroup.Red.singleton_iff\n\n/-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces\nto `x\u207b\u00b9` -/\n@[to_additive\n  \"If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w`\n  reduces to `-x`.\"]\ntheorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] \u2194 Red L [(x, not b)] :=\n  Iff.intro\n    (fun h => by\n      have h\u2081 : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h\n      have h\u2082 : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev\n      let \u27e8L', h\u2081, h\u2082\u27e9 := church_rosser h\u2081 h\u2082\n      rw [singleton_iff] at h\u2081\n      subst L'\n      assumption)\n    fun h => (cons_cons h).tail Step.cons_not\n#align free_group.red.cons_nil_iff_singleton FreeGroup.Red.cons_nil_iff_singleton\n#align free_add_group.red.cons_nil_iff_singleton FreeAddGroup.Red.cons_nil_iff_singleton\n\n@[to_additive]\ntheorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) \u2260 (x2, b2)) :\n    Red [(x1, !b1), (x2, b2)] L \u2194 L = [(x1, !b1), (x2, b2)] := by\n  apply reflTransGen_iff_eq\n  generalize eq : [(x1, not b1), (x2, b2)] = L'\n  intro L h'\n  cases h'\n  simp [List.cons_eq_append_iff, List.nil_eq_append] at eq\n  rcases eq with \u27e8rfl, \u27e8rfl, rfl\u27e9, \u27e8rfl, rfl\u27e9, rfl\u27e9; subst_vars\n  simp at h\n#align free_group.red.red_iff_irreducible FreeGroup.Red.red_iff_irreducible\n#align free_add_group.red.red_iff_irreducible FreeAddGroup.Red.red_iff_irreducible\n\n/-- If `x` and `y` are distinct letters and `w\u2081 w\u2082` are words such that `xw\u2081` reduces to `yw\u2082`, then\n`w\u2081` reduces to `x\u207b\u00b9yw\u2082`. -/\n@[to_additive \"If `x` and `y` are distinct letters and `w\u2081 w\u2082` are words such that `x + w\u2081` reduces\n  to `y + w\u2082`, then `w\u2081` reduces to `-x + y + w\u2082`.\"]\ntheorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) \u2260 (x2, b2))\n    (H2 : Red ((x1, b1) :: L\u2081) ((x2, b2) :: L\u2082)) : Red L\u2081 ((x1, not b1) :: (x2, b2) :: L\u2082) := by\n  have : Red ((x1, b1) :: L\u2081) ([(x2, b2)] ++ L\u2082) := H2\n  rcases to_append_iff.1 this with \u27e8_ | \u27e8p, L\u2083\u27e9, L\u2084, eq, h\u2081, h\u2082\u27e9\n  \u00b7 simp [nil_iff] at h\u2081\n  \u00b7 cases eq\n    show Red (L\u2083 ++ L\u2084) ([(x1, not b1), (x2, b2)] ++ L\u2082)\n    apply append_append _ h\u2082\n    have h\u2081 : Red ((x1, not b1) :: (x1, b1) :: L\u2083) [(x1, not b1), (x2, b2)] := cons_cons h\u2081\n    have h\u2082 : Red ((x1, not b1) :: (x1, b1) :: L\u2083) L\u2083 := Step.cons_not_rev.to_red\n    rcases church_rosser h\u2081 h\u2082 with \u27e8L', h\u2081, h\u2082\u27e9\n    rw [red_iff_irreducible H1] at h\u2081\n    rwa [h\u2081] at h\u2082\n#align free_group.red.inv_of_red_of_ne FreeGroup.Red.inv_of_red_of_ne\n#align free_add_group.red.neg_of_red_of_ne FreeAddGroup.Red.neg_of_red_of_ne\n\nopen List -- for <+ notation\n\n@[to_additive]\ntheorem Step.sublist (H : Red.Step L\u2081 L\u2082) : Sublist L\u2082 L\u2081 := by\n  cases H; simp; constructor; constructor; rfl\n#align free_group.red.step.sublist FreeGroup.Red.Step.sublist\n#align free_add_group.red.step.sublist FreeAddGroup.Red.Step.sublist\n\n/-- If `w\u2081 w\u2082` are words such that `w\u2081` reduces to `w\u2082`, then `w\u2082` is a sublist of `w\u2081`. -/\n@[to_additive \"If `w\u2081 w\u2082` are words such that `w\u2081` reduces to `w\u2082`, then `w\u2082` is a sublist of\n  `w\u2081`.\"]\nprotected theorem sublist : Red L\u2081 L\u2082 \u2192 L\u2082 <+ L\u2081 :=\n  @reflTransGen_of_transitive_reflexive\n    _ (fun a b => b <+ a) _ _ _\n    (fun l => List.Sublist.refl l)\n    (fun _a _b _c hab hbc => List.Sublist.trans hbc hab)\n    (fun _ _ => Red.Step.sublist)\n#align free_group.red.sublist FreeGroup.Red.sublist\n#align free_add_group.red.sublist FreeAddGroup.Red.sublist\n\n@[to_additive]\ntheorem length_le (h : Red L\u2081 L\u2082) : L\u2082.length \u2264 L\u2081.length :=\n  h.sublist.length_le\n#align free_group.red.length_le FreeGroup.Red.length_le\n#align free_add_group.red.length_le FreeAddGroup.Red.length_le\n\n\n@[to_additive]\ntheorem sizeof_of_step : \u2200 {L\u2081 L\u2082 : List (\u03b1 \u00d7 Bool)},\n    Step L\u2081 L\u2082 \u2192 sizeOf L\u2082 < sizeOf L\u2081\n  | _, _, @Step.not _ L1 L2 x b => by\n    induction' L1 with hd tl ih\n    case nil =>\n      -- dsimp [sizeOf]\n      dsimp\n      simp only [Bool.sizeOf_eq_one]\n\n      have H :\n        1 + (1 + 1) + (1 + (1 + 1) + sizeOf L2) =\n          sizeOf L2 + (1 + ((1 + 1) + (1 + 1) + 1)) :=\n        by ac_rfl\n      rw [H]\n      apply Nat.lt_add_of_pos_right\n      apply Nat.lt_add_right\n      apply Nat.zero_lt_one\n    case cons =>\n      dsimp\n      exact Nat.add_lt_add_left ih _\n#align free_group.red.sizeof_of_step FreeGroup.Red.sizeof_of_step\n#align free_add_group.red.sizeof_of_step FreeAddGroup.Red.sizeof_of_step\n\n@[to_additive]\ntheorem length (h : Red L\u2081 L\u2082) : \u2203 n, L\u2081.length = L\u2082.length + 2 * n := by\n  induction' h with L\u2082 L\u2083 _h\u2081\u2082 h\u2082\u2083 ih\n  \u00b7 exact \u27e80, rfl\u27e9\n  \u00b7 rcases ih with \u27e8n, eq\u27e9\n    exists 1 + n\n    simp [mul_add, eq, (Step.length h\u2082\u2083).symm, add_assoc]\n#align free_group.red.length FreeGroup.Red.length\n#align free_add_group.red.length FreeAddGroup.Red.length\n\n@[to_additive]\ntheorem antisymm (h\u2081\u2082 : Red L\u2081 L\u2082) (h\u2082\u2081 : Red L\u2082 L\u2081) : L\u2081 = L\u2082 :=\n  h\u2082\u2081.sublist.antisymm h\u2081\u2082.sublist\n#align free_group.red.antisymm FreeGroup.Red.antisymm\n#align free_add_group.red.antisymm FreeAddGroup.Red.antisymm\n\nend Red\n\n@[to_additive FreeAddGroup.equivalence_join_red]\ntheorem equivalence_join_red : Equivalence (Join (@Red \u03b1)) :=\n  equivalence_join_reflTransGen fun a b c hab hac =>\n    match b, c, Red.Step.diamond hab hac rfl with\n    | b, _, Or.inl rfl => \u27e8b, by rfl, by rfl\u27e9\n    | b, c, Or.inr \u27e8d, hbd, hcd\u27e9 => \u27e8d, ReflGen.single hbd, ReflTransGen.single hcd\u27e9\n#align free_group.equivalence_join_red FreeGroup.equivalence_join_red\n#align free_add_group.equivalence_join_red FreeAddGroup.equivalence_join_red\n\n@[to_additive FreeAddGroup.join_red_of_step]\ntheorem join_red_of_step (h : Red.Step L\u2081 L\u2082) : Join Red L\u2081 L\u2082 :=\n  join_of_single reflexive_reflTransGen h.to_red\n#align free_group.join_red_of_step FreeGroup.join_red_of_step\n#align free_add_group.join_red_of_step FreeAddGroup.join_red_of_step\n\n@[to_additive FreeAddGroup.eqvGen_step_iff_join_red]\ntheorem eqvGen_step_iff_join_red : EqvGen Red.Step L\u2081 L\u2082 \u2194 Join Red L\u2081 L\u2082 :=\n  Iff.intro\n    (fun h =>\n      have : EqvGen (Join Red) L\u2081 L\u2082 := h.mono fun _ _ => join_red_of_step\n      equivalence_join_red.eqvGen_iff.1 this)\n    (join_of_equivalence (EqvGen.is_equivalence _) fun _ _ =>\n      reflTransGen_of_equivalence (EqvGen.is_equivalence _) EqvGen.rel)\n#align free_group.eqv_gen_step_iff_join_red FreeGroup.eqvGen_step_iff_join_red\n#align free_add_group.eqv_gen_step_iff_join_red FreeAddGroup.eqvGen_step_iff_join_red\n\nend FreeGroup\n\n/-- The free group over a type, i.e. the words formed by the elements of the type and their formal\ninverses, quotient by one step reduction. -/\n@[to_additive \"The free additive group over a type, i.e. the words formed by the elements of the\n  type and their formal inverses, quotient by one step reduction.\"]\ndef FreeGroup (\u03b1 : Type u) : Type u :=\n  Quot <| @FreeGroup.Red.Step \u03b1\n#align free_group FreeGroup\n#align free_add_group FreeAddGroup\n\nnamespace FreeGroup\n\nvariable {L L\u2081 L\u2082 L\u2083 L\u2084 : List (\u03b1 \u00d7 Bool)}\n\n/-- The canonical map from `list (\u03b1 \u00d7 bool)` to the free group on `\u03b1`. -/\n@[to_additive \"The canonical map from `list (\u03b1 \u00d7 bool)` to the free additive group on `\u03b1`.\"]\ndef mk (L : List (\u03b1 \u00d7 Bool)) : FreeGroup \u03b1 :=\n  Quot.mk Red.Step L\n#align free_group.mk FreeGroup.mk\n#align free_add_group.mk FreeAddGroup.mk\n\n@[to_additive (attr:=simp)]\ntheorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L :=\n  rfl\n#align free_group.quot_mk_eq_mk FreeGroup.quot_mk_eq_mk\n#align free_add_group.quot_mk_eq_mk FreeAddGroup.quot_mk_eq_mk\n\n@[to_additive (attr:=simp)]\ntheorem quot_lift_mk (\u03b2 : Type v) (f : List (\u03b1 \u00d7 Bool) \u2192 \u03b2)\n    (H : \u2200 L\u2081 L\u2082, Red.Step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) : Quot.lift f H (mk L) = f L :=\n  rfl\n#align free_group.quot_lift_mk FreeGroup.quot_lift_mk\n#align free_add_group.quot_lift_mk FreeAddGroup.quot_lift_mk\n\n@[to_additive (attr:=simp)]\ntheorem quot_liftOn_mk (\u03b2 : Type v) (f : List (\u03b1 \u00d7 Bool) \u2192 \u03b2)\n    (H : \u2200 L\u2081 L\u2082, Red.Step L\u2081 L\u2082 \u2192 f L\u2081 = f L\u2082) : Quot.liftOn (mk L) f H = f L :=\n  rfl\n#align free_group.quot_lift_on_mk FreeGroup.quot_liftOn_mk\n#align free_add_group.quot_lift_on_mk FreeAddGroup.quot_liftOn_mk\n\n@[to_additive (attr:=simp)]\ntheorem quot_map_mk (\u03b2 : Type v) (f : List (\u03b1 \u00d7 Bool) \u2192 List (\u03b2 \u00d7 Bool))\n    (H : (Red.Step \u21d2 Red.Step) f f) : Quot.map f H (mk L) = mk (f L) :=\n  rfl\n#align free_group.quot_map_mk FreeGroup.quot_map_mk\n#align free_add_group.quot_map_mk FreeAddGroup.quot_map_mk\n\n@[to_additive]\ninstance : One (FreeGroup \u03b1) :=\n  \u27e8mk []\u27e9\n\n@[to_additive]\ntheorem one_eq_mk : (1 : FreeGroup \u03b1) = mk [] :=\n  rfl\n#align free_group.one_eq_mk FreeGroup.one_eq_mk\n#align free_add_group.zero_eq_mk FreeAddGroup.zero_eq_mk\n\n@[to_additive]\ninstance : Inhabited (FreeGroup \u03b1) :=\n  \u27e81\u27e9\n\n@[to_additive]\ninstance : Mul (FreeGroup \u03b1) :=\n  \u27e8fun x y =>\n    Quot.liftOn x\n      (fun L\u2081 =>\n        Quot.liftOn y (fun L\u2082 => mk <| L\u2081 ++ L\u2082) fun _L\u2082 _L\u2083 H =>\n          Quot.sound <| Red.Step.append_left H)\n      fun _L\u2081 _L\u2082 H => Quot.inductionOn y fun _L\u2083 => Quot.sound <| Red.Step.append_right H\u27e9\n\n@[to_additive (attr:=simp)]\ntheorem mul_mk : mk L\u2081 * mk L\u2082 = mk (L\u2081 ++ L\u2082) :=\n  rfl\n#align free_group.mul_mk FreeGroup.mul_mk\n#align free_add_group.add_mk FreeAddGroup.add_mk\n\n/-- Transform a word representing a free group element into a word representing its inverse. -/\n@[to_additive \"Transform a word representing a free group element into a word representing its\n  negative.\"]\ndef invRev (w : List (\u03b1 \u00d7 Bool)) : List (\u03b1 \u00d7 Bool) :=\n  (List.map (fun g : \u03b1 \u00d7 Bool => (g.1, not g.2)) w).reverse\n#align free_group.inv_rev FreeGroup.invRev\n#align free_add_group.neg_rev FreeAddGroup.negRev\n\n@[to_additive (attr:=simp)]\ntheorem invRev_length : (invRev L\u2081).length = L\u2081.length := by simp [invRev]\n#align free_group.inv_rev_length FreeGroup.invRev_length\n#align free_add_group.neg_rev_length FreeAddGroup.negRev_length\n\n@[to_additive (attr:=simp)]\ntheorem invRev_invRev : invRev (invRev L\u2081) = L\u2081 :=\n  by simp [invRev, List.map_reverse, (\u00b7 \u2218 \u00b7)]\n#align free_group.inv_rev_inv_rev FreeGroup.invRev_invRev\n#align free_add_group.neg_rev_neg_rev FreeAddGroup.negRev_negRev\n\n@[to_additive (attr:=simp)]\ntheorem invRev_empty : invRev ([] : List (\u03b1 \u00d7 Bool)) = [] :=\n  rfl\n#align free_group.inv_rev_empty FreeGroup.invRev_empty\n#align free_add_group.neg_rev_empty FreeAddGroup.negRev_empty\n\n@[to_additive]\ntheorem invRev_involutive : Function.Involutive (@invRev \u03b1) := fun _ => invRev_invRev\n#align free_group.inv_rev_involutive FreeGroup.invRev_involutive\n#align free_add_group.neg_rev_involutive FreeAddGroup.negRev_involutive\n\n@[to_additive]\ntheorem invRev_injective : Function.Injective (@invRev \u03b1) :=\n  invRev_involutive.injective\n#align free_group.inv_rev_injective FreeGroup.invRev_injective\n#align free_add_group.neg_rev_injective FreeAddGroup.negRev_injective\n\n@[to_additive]\ntheorem invRev_surjective : Function.Surjective (@invRev \u03b1) :=\n  invRev_involutive.surjective\n#align free_group.inv_rev_surjective FreeGroup.invRev_surjective\n#align free_add_group.neg_rev_surjective FreeAddGroup.negRev_surjective\n\n@[to_additive]\ntheorem invRev_bijective : Function.Bijective (@invRev \u03b1) :=\n  invRev_involutive.bijective\n#align free_group.inv_rev_bijective FreeGroup.invRev_bijective\n#align free_add_group.neg_rev_bijective FreeAddGroup.negRev_bijective\n\n@[to_additive]\ninstance : Inv (FreeGroup \u03b1) :=\n  \u27e8Quot.map invRev\n      (by\n        intro a b h\n        cases h\n        simp [invRev])\u27e9\n\n@[to_additive (attr:=simp)]\ntheorem inv_mk : (mk L)\u207b\u00b9 = mk (invRev L) :=\n  rfl\n#align free_group.inv_mk FreeGroup.inv_mk\n#align free_add_group.neg_mk FreeAddGroup.neg_mk\n\n@[to_additive]\ntheorem Red.Step.invRev {L\u2081 L\u2082 : List (\u03b1 \u00d7 Bool)} (h : Red.Step L\u2081 L\u2082) :\n    Red.Step (FreeGroup.invRev L\u2081) (FreeGroup.invRev L\u2082) := by\n  cases' h with a b x y\n  simp [FreeGroup.invRev]\n#align free_group.red.step.inv_rev FreeGroup.Red.Step.invRev\n#align free_add_group.red.step.neg_rev FreeAddGroup.Red.Step.negRev\n\n@[to_additive]\ntheorem Red.invRev {L\u2081 L\u2082 : List (\u03b1 \u00d7 Bool)} (h : Red L\u2081 L\u2082) : Red (invRev L\u2081) (invRev L\u2082) :=\n  Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h\n#align free_group.red.inv_rev FreeGroup.Red.invRev\n#align free_add_group.red.neg_rev FreeAddGroup.Red.negRev\n\n@[to_additive (attr:=simp)]\ntheorem Red.step_invRev_iff :\n  Red.Step (FreeGroup.invRev L\u2081) (FreeGroup.invRev L\u2082) \u2194 Red.Step L\u2081 L\u2082 :=\n  \u27e8fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev\u27e9\n#align free_group.red.step_inv_rev_iff FreeGroup.Red.step_invRev_iff\n#align free_add_group.red.step_neg_rev_iff FreeAddGroup.Red.step_negRev_iff\n\n@[to_additive (attr:=simp)]\ntheorem red_invRev_iff : Red (invRev L\u2081) (invRev L\u2082) \u2194 Red L\u2081 L\u2082 :=\n  \u27e8fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev\u27e9\n#align free_group.red_inv_rev_iff FreeGroup.red_invRev_iff\n#align free_add_group.red_neg_rev_iff FreeAddGroup.red_negRev_iff\n\n@[to_additive]\ninstance : Group (FreeGroup \u03b1) where\n  mul := (\u00b7 * \u00b7)\n  one := 1\n  inv := Inv.inv\n  mul_assoc := by rintro \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9 \u27e8L\u2083\u27e9; simp\n  one_mul := by rintro \u27e8L\u27e9; rfl\n  mul_one := by rintro \u27e8L\u27e9; simp [one_eq_mk]\n  mul_left_inv := by\n    rintro \u27e8L\u27e9\n    exact\n      List.recOn L rfl fun \u27e8x, b\u27e9 tl ih =>\n          Eq.trans (Quot.sound <| by simp [invRev, one_eq_mk]) ih\n\n/-- `of` is the canonical injection from the type to the free group over that type by sending each\nelement to the equivalence class of the letter that is the element. -/\n@[to_additive \"`of` is the canonical injection from the type to the free group over that type\n  by sending each element to the equivalence class of the letter that is the element.\"]\ndef of (x : \u03b1) : FreeGroup \u03b1 :=\n  mk [(x, true)]\n#align free_group.of FreeGroup.of\n#align free_add_group.of FreeAddGroup.of\n\n@[to_additive]\ntheorem Red.exact : mk L\u2081 = mk L\u2082 \u2194 Join Red L\u2081 L\u2082 :=\n  calc\n    mk L\u2081 = mk L\u2082 \u2194 EqvGen Red.Step L\u2081 L\u2082 := Iff.intro (Quot.exact _) Quot.EqvGen_sound\n    _ \u2194 Join Red L\u2081 L\u2082 := eqvGen_step_iff_join_red\n\n#align free_group.red.exact FreeGroup.Red.exact\n#align free_add_group.red.exact FreeAddGroup.Red.exact\n\n/-- The canonical map from the type to the free group is an injection. -/\n@[to_additive \"The canonical map from the type to the additive free group is an injection.\"]\ntheorem of_injective : Function.Injective (@of \u03b1) := fun _ _ H => by\n  let \u27e8L\u2081, hx, hy\u27e9 := Red.exact.1 H\n  simp [Red.singleton_iff] at hx hy ; aesop\n#align free_group.of_injective FreeGroup.of_injective\n#align free_add_group.of_injective FreeAddGroup.of_injective\n\nsection lift\n\nvariable {\u03b2 : Type v} [Group \u03b2] (f : \u03b1 \u2192 \u03b2) {x y : FreeGroup \u03b1}\n\n/-- Given `f : \u03b1 \u2192 \u03b2` with `\u03b2` a group, the canonical map `list (\u03b1 \u00d7 bool) \u2192 \u03b2` -/\n@[to_additive \"Given `f : \u03b1 \u2192 \u03b2` with `\u03b2` an additive group, the canonical map\n  `list (\u03b1 \u00d7 bool) \u2192 \u03b2`\"]\ndef Lift.aux : List (\u03b1 \u00d7 Bool) \u2192 \u03b2 := fun L =>\n  List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)\u207b\u00b9\n#align free_group.lift.aux FreeGroup.Lift.aux\n#align free_add_group.lift.aux FreeAddGroup.Lift.aux\n\n@[to_additive]\ntheorem Red.Step.lift {f : \u03b1 \u2192 \u03b2} (H : Red.Step L\u2081 L\u2082) : Lift.aux f L\u2081 = Lift.aux f L\u2082 := by\n  cases' H with _ _ _ b; cases b <;> simp [Lift.aux]\n#align free_group.red.step.lift FreeGroup.Red.Step.lift\n#align free_add_group.red.step.lift FreeAddGroup.Red.Step.lift\n\n/-- If `\u03b2` is a group, then any function from `\u03b1` to `\u03b2` extends uniquely to a group homomorphism\nfrom the free group over `\u03b1` to `\u03b2` -/\n@[to_additive (attr := simps symm_apply)\n  \"If `\u03b2` is an additive group, then any function from `\u03b1` to `\u03b2` extends uniquely to an\n  additive group homomorphism from the free additive group over `\u03b1` to `\u03b2`\"]\ndef lift : (\u03b1 \u2192 \u03b2) \u2243 (FreeGroup \u03b1 \u2192* \u03b2) where\n  toFun f :=\n    MonoidHom.mk' (Quot.lift (Lift.aux f) fun L\u2081 L\u2082 => Red.Step.lift) <| by\n      rintro \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9; simp [Lift.aux]\n  invFun g := g \u2218 of\n  left_inv f := one_mul _\n  right_inv g :=\n    MonoidHom.ext <| by\n      rintro \u27e8L\u27e9\n      exact List.recOn L\n        (g.map_one.symm)\n        (by\n        rintro \u27e8x, _ | _\u27e9 t (ih : _ = g (mk t))\n        \u00b7 show _ = g ((of x)\u207b\u00b9 * mk t)\n          simpa [Lift.aux] using ih\n        \u00b7 show _ = g (of x * mk t)\n          simpa [Lift.aux] using ih)\n#align free_group.lift FreeGroup.lift\n#align free_add_group.lift FreeAddGroup.lift\n#align free_group.lift_symm_apply FreeGroup.lift_symm_apply\n#align free_add_group.lift_symm_apply FreeAddGroup.lift_symm_apply\n\nvariable {f}\n\n@[to_additive (attr:=simp)]\ntheorem lift.mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)\u207b\u00b9) :=\n  rfl\n#align free_group.lift.mk FreeGroup.lift.mk\n#align free_add_group.lift.mk FreeAddGroup.lift.mk\n\n@[to_additive (attr:=simp)]\ntheorem lift.of {x} : lift f (of x) = f x :=\n  one_mul _\n#align free_group.lift.of FreeGroup.lift.of\n#align free_add_group.lift.of FreeAddGroup.lift.of\n\n@[to_additive]\ntheorem lift.unique (g : FreeGroup \u03b1 \u2192* \u03b2) (hg : \u2200 x, g (FreeGroup.of x) = f x) {x} :\n  g x = FreeGroup.lift f x :=\n  FunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g \u2218 FreeGroup.of = f)) x\n#align free_group.lift.unique FreeGroup.lift.unique\n#align free_add_group.lift.unique FreeAddGroup.lift.unique\n\n/-- Two homomorphisms out of a free group are equal if they are equal on generators.\n\nSee note [partially-applied ext lemmas]. -/\n@[ to_additive (attr:=ext) \"Two homomorphisms out of a free additive group are equal if they are\n  equal on generators. See note [partially-applied ext lemmas].\"]\ntheorem ext_hom {G : Type _} [Group G] (f g : FreeGroup \u03b1 \u2192* G) (h : \u2200 a, f (of a) = g (of a)) :\n    f = g :=\n  lift.symm.injective <| funext h\n#align free_group.ext_hom FreeGroup.ext_hom\n#align free_add_group.ext_hom FreeAddGroup.ext_hom\n\n@[to_additive]\ntheorem lift.of_eq (x : FreeGroup \u03b1) : lift FreeGroup.of x = x :=\n  FunLike.congr_fun (lift.apply_symm_apply (MonoidHom.id _)) x\n#align free_group.lift.of_eq FreeGroup.lift.of_eq\n#align free_add_group.lift.of_eq FreeAddGroup.lift.of_eq\n\n@[to_additive]\ntheorem lift.range_le {s : Subgroup \u03b2} (H : Set.range f \u2286 s) : (lift f).range \u2264 s := by\n  rintro _ \u27e8\u27e8L\u27e9, rfl\u27e9;\n    exact\n      List.recOn L s.one_mem fun \u27e8x, b\u27e9 tl ih =>\n        Bool.recOn b (by simp at ih\u22a2; exact s.mul_mem (s.inv_mem <| H \u27e8x, rfl\u27e9) ih)\n          (by simp at ih\u22a2; exact s.mul_mem (H \u27e8x, rfl\u27e9) ih)\n#align free_group.lift.range_le FreeGroup.lift.range_le\n#align free_add_group.lift.range_le FreeAddGroup.lift.range_le\n\n@[to_additive]\ntheorem lift.range_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by\n  apply le_antisymm (lift.range_le Subgroup.subset_closure)\n  rw [Subgroup.closure_le]\n  rintro _ \u27e8a, rfl\u27e9\n  exact \u27e8FreeGroup.of a, by simp only [lift.of]\u27e9\n#align free_group.lift.range_eq_closure FreeGroup.lift.range_eq_closure\n#align free_add_group.lift.range_eq_closure FreeAddGroup.lift.range_eq_closure\n\nend lift\n\nsection Map\n\nvariable {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) {x y : FreeGroup \u03b1}\n\n/-- Any function from `\u03b1` to `\u03b2` extends uniquely to a group homomorphism from the free group over\n  `\u03b1` to the free group over `\u03b2`. -/\n@[to_additive \"Any function from `\u03b1` to `\u03b2` extends uniquely to an additive group homomorphism from\n  the additive free group over `\u03b1` to the additive free group over `\u03b2`.\"]\ndef map : FreeGroup \u03b1 \u2192* FreeGroup \u03b2 :=\n  MonoidHom.mk'\n    (Quot.map (List.map fun x => (f x.1, x.2)) fun L\u2081 L\u2082 H => by cases H ; simp)\n    (by rintro \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9; simp)\n#align free_group.map FreeGroup.map\n#align free_add_group.map FreeAddGroup.map\n\nvariable {f}\n\n@[to_additive (attr:=simp)]\ntheorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) :=\n  rfl\n#align free_group.map.mk FreeGroup.map.mk\n#align free_add_group.map.mk FreeAddGroup.map.mk\n\n@[to_additive (attr:=simp)]\ntheorem map.id (x : FreeGroup \u03b1) : map id x = x := by rcases x with \u27e8L\u27e9; simp [List.map_id']\n#align free_group.map.id FreeGroup.map.id\n#align free_add_group.map.id FreeAddGroup.map.id\n\n@[to_additive (attr:=simp)]\ntheorem map.id' (x : FreeGroup \u03b1) : map (fun z => z) x = x :=\n  map.id x\n#align free_group.map.id' FreeGroup.map.id'\n#align free_add_group.map.id' FreeAddGroup.map.id'\n\n@[to_additive]\ntheorem map.comp {\u03b3 : Type w} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3) (x) :\n  map g (map f x) = map (g \u2218 f) x := by\n  rcases x with \u27e8L\u27e9; simp [(\u00b7 \u2218 \u00b7)]\n#align free_group.map.comp FreeGroup.map.comp\n#align free_add_group.map.comp FreeAddGroup.map.comp\n\n@[to_additive (attr:=simp)]\ntheorem map.of {x} : map f (of x) = of (f x) :=\n  rfl\n#align free_group.map.of FreeGroup.map.of\n#align free_add_group.map.of FreeAddGroup.map.of\n\n@[to_additive]\ntheorem map.unique (g : FreeGroup \u03b1 \u2192* FreeGroup \u03b2)\n  (hg : \u2200 x, g (FreeGroup.of x) = FreeGroup.of (f x)) :\n  \u2200 {x}, g x = map f x := by\n  rintro \u27e8L\u27e9\n  exact List.recOn L g.map_one fun \u27e8x, b\u27e9 t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) =>\n    Bool.recOn b\n      (show g ((FreeGroup.of x)\u207b\u00b9 * FreeGroup.mk t) =\n          FreeGroup.map f ((FreeGroup.of x)\u207b\u00b9 * FreeGroup.mk t) by\n        simp [g.map_mul, g.map_inv, hg, ih])\n      (show g (FreeGroup.of x * FreeGroup.mk t) =\n          FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih])\n#align free_group.map.unique FreeGroup.map.unique\n#align free_add_group.map.unique FreeAddGroup.map.unique\n\n@[to_additive]\ntheorem map_eq_lift : map f x = lift (of \u2218 f) x :=\n  Eq.symm <| map.unique _ fun x => by simp\n#align free_group.map_eq_lift FreeGroup.map_eq_lift\n#align free_add_group.map_eq_lift FreeAddGroup.map_eq_lift\n\n/-- Equivalent types give rise to multiplicatively equivalent free groups.\n\nThe converse can be found in `GroupTheory.FreeAbelianGroupFinsupp`,\nas `Equiv.of_freeGroupEquiv`\n -/\n@[to_additive (attr := simps apply)\n  \"Equivalent types give rise to additively equivalent additive free groups.\"]\ndef freeGroupCongr {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) : FreeGroup \u03b1 \u2243* FreeGroup \u03b2 where\n  toFun := map e\n  invFun := map e.symm\n  left_inv x := by simp [Function.comp, map.comp]\n  right_inv x := by simp [Function.comp, map.comp]\n  map_mul' := MonoidHom.map_mul _\n#align free_group.free_group_congr FreeGroup.freeGroupCongr\n#align free_add_group.free_add_group_congr FreeAddGroup.freeAddGroupCongr\n#align free_group.free_group_congr_apply FreeGroup.freeGroupCongr_apply\n#align free_add_group.free_add_group_congr_apply FreeAddGroup.freeAddGroupCongr_apply\n\n@[to_additive (attr:=simp)]\ntheorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl \u03b1) = MulEquiv.refl _ :=\n  MulEquiv.ext map.id\n#align free_group.free_group_congr_refl FreeGroup.freeGroupCongr_refl\n#align free_add_group.free_add_group_congr_refl FreeAddGroup.freeAddGroupCongr_refl\n\n@[to_additive (attr:=simp)]\ntheorem freeGroupCongr_symm {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) : (freeGroupCongr e).symm = freeGroupCongr e.symm :=\n  rfl\n#align free_group.free_group_congr_symm FreeGroup.freeGroupCongr_symm\n#align free_add_group.free_add_group_congr_symm FreeAddGroup.freeAddGroupCongr_symm\n\n@[to_additive]\ntheorem freeGroupCongr_trans {\u03b1 \u03b2 \u03b3} (e : \u03b1 \u2243 \u03b2) (f : \u03b2 \u2243 \u03b3) :\n    (freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) :=\n  MulEquiv.ext <| map.comp _ _\n#align free_group.free_group_congr_trans FreeGroup.freeGroupCongr_trans\n#align free_add_group.free_add_group_congr_trans FreeAddGroup.freeAddGroupCongr_trans\n\nend Map\n\nsection Prod\n\nvariable [Group \u03b1] (x y : FreeGroup \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1` extends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the multiplicative version of `FreeGroup.sum`. -/\n@[to_additive \"If `\u03b1` is an additive group, then any function from `\u03b1` to `\u03b1` extends uniquely to an\n  additive homomorphism from the additive free group over `\u03b1` to `\u03b1`.\"]\ndef prod : FreeGroup \u03b1 \u2192* \u03b1 :=\n  lift id\n#align free_group.prod FreeGroup.prod\n#align free_add_group.sum FreeAddGroup.sum\n\nvariable {x y}\n\n@[to_additive (attr:=simp)]\ntheorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1\u207b\u00b9) :=\n  rfl\n#align free_group.prod_mk FreeGroup.prod_mk\n#align free_add_group.sum_mk FreeAddGroup.sum_mk\n\n@[to_additive (attr:=simp)]\ntheorem prod.of {x : \u03b1} : prod (of x) = x :=\n  lift.of\n#align free_group.prod.of FreeGroup.prod.of\n#align free_add_group.sum.of FreeAddGroup.sum.of\n\n@[to_additive]\ntheorem prod.unique (g : FreeGroup \u03b1 \u2192* \u03b1) (hg : \u2200 x, g (FreeGroup.of x) = x) {x} : g x = prod x :=\n  lift.unique g hg\n#align free_group.prod.unique FreeGroup.prod.unique\n#align free_add_group.sum.unique FreeAddGroup.sum.unique\n\nend Prod\n\n@[to_additive]\ntheorem lift_eq_prod_map {\u03b2 : Type v} [Group \u03b2] {f : \u03b1 \u2192 \u03b2} {x} : lift f x = prod (map f x) := by\n  rw [\u2190 lift.unique (prod.comp (map f))]\n  \u00b7 rfl\n  \u00b7 simp\n#align free_group.lift_eq_prod_map FreeGroup.lift_eq_prod_map\n#align free_add_group.lift_eq_sum_map FreeAddGroup.lift_eq_sum_map\n\nsection Sum\n\nvariable [AddGroup \u03b1] (x y : FreeGroup \u03b1)\n\n/-- If `\u03b1` is a group, then any function from `\u03b1` to `\u03b1` extends uniquely to a homomorphism from the\nfree group over `\u03b1` to `\u03b1`. This is the additive version of `prod`. -/\ndef sum : \u03b1 :=\n  @prod (Multiplicative _) _ x\n#align free_group.sum FreeGroup.sum\n\nvariable {x y}\n\n@[simp]\ntheorem sum_mk : sum (mk L) = List.sum (L.map fun x => cond x.2 x.1 (-x.1)) :=\n  rfl\n#align free_group.sum_mk FreeGroup.sum_mk\n\n@[simp]\ntheorem sum.of {x : \u03b1} : sum (of x) = x :=\n  prod.of\n#align free_group.sum.of FreeGroup.sum.of\n\n-- note: there are no bundled homs with different notation in the domain and codomain, so we copy\n-- these manually\n@[simp]\ntheorem sum.map_mul : sum (x * y) = sum x + sum y :=\n  (@prod (Multiplicative _) _).map_mul _ _\n#align free_group.sum.map_mul FreeGroup.sum.map_mul\n\n@[simp]\ntheorem sum.map_one : sum (1 : FreeGroup \u03b1) = 0 :=\n  (@prod (Multiplicative _) _).map_one\n#align free_group.sum.map_one FreeGroup.sum.map_one\n\n@[simp]\ntheorem sum.map_inv : sum x\u207b\u00b9 = -sum x :=\n  (prod : FreeGroup (Multiplicative \u03b1) \u2192* Multiplicative \u03b1).map_inv _\n#align free_group.sum.map_inv FreeGroup.sum.map_inv\n\nend Sum\n\n/-- The bijection between the free group on the empty type, and a type with one element. -/\n@[to_additive \"The bijection between the additive free group on the empty type, and a type with one\n  element.\"]\ndef freeGroupEmptyEquivUnit : FreeGroup Empty \u2243 Unit\n    where\n  toFun _ := ()\n  invFun _ := 1\n  left_inv := by rintro \u27e8_ | \u27e8\u27e8\u27e8\u27e9, _\u27e9, _\u27e9\u27e9; rfl\n  right_inv := fun \u27e8\u27e9 => rfl\n#align free_group.free_group_empty_equiv_unit FreeGroup.freeGroupEmptyEquivUnit\n#align free_add_group.free_add_group_empty_equiv_add_unit FreeAddGroup.freeAddGroupEmptyEquivAddUnit\n\n/-- The bijection between the free group on a singleton, and the integers. -/\ndef freeGroupUnitEquivInt : FreeGroup Unit \u2243 \u2124\n    where\n  toFun x := sum (by\n    revert x\n    change (FreeGroup Unit \u2192* FreeGroup \u2124)\n    apply map fun _ => (1 : \u2124))\n  invFun x := of () ^ x\n  left_inv := by\n    rintro \u27e8L\u27e9\n    simp\n    exact List.recOn L\n     (by rfl)\n     (fun \u27e8\u27e8\u27e9, b\u27e9 tl ih => by\n        cases b <;> simp [zpow_add] at ih\u22a2 <;> rw [ih] <;> rfl)\n  right_inv x :=\n    Int.induction_on x (by simp) (fun i ih => by simp at ih; simp [zpow_add, ih]) fun i ih => by\n      simp at ih; simp [zpow_add, ih, sub_eq_add_neg]\n#align free_group.free_group_unit_equiv_int FreeGroup.freeGroupUnitEquivInt\n\nsection Category\n\nvariable {\u03b2 : Type u}\n\n@[to_additive]\ninstance : Monad FreeGroup.{u} where\n  pure {_\u03b1} := of\n  map {_\u03b1} {_\u03b2} {f} := map f\n  bind {_\u03b1} {_\u03b2} {x} {f} := lift f x\n\n@[to_additive (attr := elab_as_elim)]\nprotected theorem induction_on {C : FreeGroup \u03b1 \u2192 Prop} (z : FreeGroup \u03b1) (C1 : C 1)\n    (Cp : \u2200 x, C <| pure x) (Ci : \u2200 x, C (pure x) \u2192 C (pure x)\u207b\u00b9)\n    (Cm : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) : C z :=\n  Quot.inductionOn z fun L =>\n    List.recOn L C1 fun \u27e8x, b\u27e9 _tl ih => Bool.recOn b (Cm _ _ (Ci _ <| Cp x) ih) (Cm _ _ (Cp x) ih)\n#align free_group.induction_on FreeGroup.induction_on\n#align free_add_group.induction_on FreeAddGroup.induction_on\n\n-- porting note: simp can prove this: by simp only [@map_pure]\n@[to_additive]\ntheorem map_pure (f : \u03b1 \u2192 \u03b2) (x : \u03b1) : f <$> (pure x : FreeGroup \u03b1) = pure (f x) :=\n  map.of\n#align free_group.map_pure FreeGroup.map_pure\n#align free_add_group.map_pure FreeAddGroup.map_pure\n\n@[to_additive (attr:=simp)]\ntheorem map_one (f : \u03b1 \u2192 \u03b2) : f <$> (1 : FreeGroup \u03b1) = 1 :=\n  (map f).map_one\n#align free_group.map_one FreeGroup.map_one\n#align free_add_group.map_zero FreeAddGroup.map_zero\n\n@[to_additive (attr:=simp)]\ntheorem map_mul (f : \u03b1 \u2192 \u03b2) (x y : FreeGroup \u03b1) : f <$> (x * y) = f <$> x * f <$> y :=\n  (map f).map_mul x y\n#align free_group.map_mul FreeGroup.map_mul\n#align free_add_group.map_add FreeAddGroup.map_add\n\n@[to_additive (attr:=simp)]\ntheorem map_inv (f : \u03b1 \u2192 \u03b2) (x : FreeGroup \u03b1) : f <$> x\u207b\u00b9 = (f <$> x)\u207b\u00b9 :=\n  (map f).map_inv x\n#align free_group.map_inv FreeGroup.map_inv\n#align free_add_group.map_neg FreeAddGroup.map_neg\n\n-- porting note: simp can prove this: by simp only [@pure_bind]\n@[to_additive]\ntheorem pure_bind (f : \u03b1 \u2192 FreeGroup \u03b2) (x) : pure x >>= f = f x :=\n  lift.of\n#align free_group.pure_bind FreeGroup.pure_bind\n#align free_add_group.pure_bind FreeAddGroup.pure_bind\n\n@[to_additive (attr:=simp)]\ntheorem one_bind (f : \u03b1 \u2192 FreeGroup \u03b2) : 1 >>= f = 1 :=\n  (lift f).map_one\n#align free_group.one_bind FreeGroup.one_bind\n#align free_add_group.zero_bind FreeAddGroup.zero_bind\n\n@[to_additive (attr:=simp)]\ntheorem mul_bind (f : \u03b1 \u2192 FreeGroup \u03b2) (x y : FreeGroup \u03b1) : x * y >>= f = (x >>= f) * (y >>= f) :=\n  (lift f).map_mul _ _\n#align free_group.mul_bind FreeGroup.mul_bind\n#align free_add_group.add_bind FreeAddGroup.add_bind\n\n@[to_additive (attr:=simp)]\ntheorem inv_bind (f : \u03b1 \u2192 FreeGroup \u03b2) (x : FreeGroup \u03b1) : x\u207b\u00b9 >>= f = (x >>= f)\u207b\u00b9 :=\n  (lift f).map_inv _\n#align free_group.inv_bind FreeGroup.inv_bind\n#align free_add_group.neg_bind FreeAddGroup.neg_bind\n\n@[to_additive]\ninstance : LawfulMonad FreeGroup.{u} := LawfulMonad.mk'\n  (id_map := fun x =>\n    FreeGroup.induction_on x (map_one id) (fun x => map_pure id x) (fun x ih => by rw [map_inv, ih])\n      fun x y ihx ihy => by rw [map_mul, ihx, ihy])\n  (pure_bind := fun x f => pure_bind f x)\n  (bind_assoc := fun x =>\n    FreeGroup.induction_on x\n      (by intros; iterate 3 rw [one_bind])\n      (fun x => by intros; iterate 2 rw [pure_bind])\n      (fun x ih => by intros; (iterate 3 rw [inv_bind]); rw [ih])\n      (fun x y ihx ihy => by intros; (iterate 3 rw [mul_bind]); rw [ihx, ihy]))\n  (bind_pure_comp  := fun f x =>\n    FreeGroup.induction_on x (by rw [one_bind, map_one]) (fun x => by rw [pure_bind, map_pure])\n      (fun x ih => by rw [inv_bind, map_inv, ih]) fun x y ihx ihy => by\n      rw [mul_bind, map_mul, ihx, ihy])\n\nend Category\n\nsection Reduce\n\nvariable [DecidableEq \u03b1]\n\n/-- The maximal reduction of a word. It is computable\niff `\u03b1` has decidable equality. -/\n@[to_additive \"The maximal reduction of a word. It is computable iff `\u03b1` has decidable equality.\"]\ndef reduce : (L : List (\u03b1 \u00d7 Bool)) -> List (\u03b1 \u00d7 Bool) :=\n  List.rec [] fun hd1 _tl1 ih =>\n    List.casesOn ih [hd1] fun hd2 tl2 =>\n      if hd1.1 = hd2.1 \u2227 hd1.2 = not hd2.2 then tl2 else hd1 :: hd2 :: tl2\n#align free_group.reduce FreeGroup.reduce\n#align free_add_group.reduce FreeAddGroup.reduce\n\n@[to_additive (attr:=simp)]\ntheorem reduce.cons (x) :\n    reduce (x :: L) =\n      List.casesOn (reduce L) [x] fun hd tl =>\n        if x.1 = hd.1 \u2227 x.2 = not hd.2 then tl else x :: hd :: tl :=\n  rfl\n#align free_group.reduce.cons FreeGroup.reduce.cons\n#align free_add_group.reduce.cons FreeAddGroup.reduce.cons\n\n/-- The first theorem that characterises the function `reduce`: a word reduces to its maximal\n  reduction. -/\n@[to_additive \"The first theorem that characterises the function `reduce`: a word reduces to its\n  maximal reduction.\"]\ntheorem reduce.red : Red L (reduce L) := by\n  induction' L with hd1 tl1 ih\n  case nil => constructor\n  case cons =>\n    dsimp\n    revert ih\n    generalize htl : reduce tl1 = TL\n    intro ih\n    cases' TL with hd2 tl2\n    case nil => exact Red.cons_cons ih\n    case cons =>\n      dsimp only\n      split_ifs with h\n      \u00b7 trans\n        \u00b7 cases hd1\n          cases hd2\n          cases h\n          dsimp at *\n          subst_vars\n          apply Red.trans (Red.cons_cons ih)\n          exact Red.Step.cons_not_rev.to_red\n      \u00b7 exact Red.cons_cons ih\n#align free_group.reduce.red FreeGroup.reduce.red\n#align free_add_group.reduce.red FreeAddGroup.reduce.red\n\n-- porting notes: deleted mathport junk and manually formatted below.\n@[to_additive]\ntheorem reduce.not {p : Prop}: \u2200 {L\u2081 L\u2082 L\u2083: List (\u03b1 \u00d7 Bool)} {x : \u03b1} {b},\n  ((reduce L\u2081) = L\u2082 ++ ((x,b)::(x ,!b)::L\u2083)) \u2192 p\n  | [], L2 ,L3, _, _ => fun h => by cases L2 <;> injections\n  | (x, b)::L1, L2, L3, x', b' => by\n      dsimp\n      cases r : reduce L1 with\n      | nil =>\n        dsimp\n        intro h\n        exfalso\n        have := congr_arg List.length h\n        simp [List.length] at this\n        rw [add_comm, add_assoc, add_assoc, add_comm, <-add_assoc] at this\n        simp [Nat.one_eq_succ_zero, Nat.succ_add] at this\n      | cons hd tail =>\n        cases' hd with y c\n        dsimp only\n        split_ifs with h <;> intro H\n        \u00b7 rw [ H ] at r\n          exact @reduce.not _ L1 ((y, c)::L2) L3 x' b' r\n        \u00b7 rcases L2 with ( _ | \u27e8 a , L2 \u27e9 )\n          \u00b7 injections\n            subst_vars\n            simp at h\n          \u00b7 refine' @reduce.not _ L1 L2 L3 x' b' _\n            injection H with _ H\n            rw [ r , H ]\n            rfl\n#align free_group.reduce.not FreeGroup.reduce.not\n#align free_add_group.reduce.not FreeAddGroup.reduce.not\n\n/-- The second theorem that characterises the function `reduce`: the maximal reduction of a word\nonly reduces to itself. -/\n@[to_additive \"The second theorem that characterises the function `reduce`: the maximal reduction of\n  a word  only reduces to itself.\"]\ntheorem reduce.min (H : Red (reduce L\u2081) L\u2082) : reduce L\u2081 = L\u2082 := by\n  induction' H with L1 L' L2 H1 H2 ih\n  \u00b7 rfl\n  \u00b7 cases' H1 with L4 L5 x b\n    exact reduce.not H2\n#align free_group.reduce.min FreeGroup.reduce.min\n#align free_add_group.reduce.min FreeAddGroup.reduce.min\n\n/-- `reduce` is idempotent, i.e. the maximal reduction of the maximal reduction of a word is the\n  maximal reduction of the word. -/\n@[to_additive (attr:=simp) \"`reduce` is idempotent, i.e. the maximal reduction of the maximal\n  reduction of a word is the maximal reduction of the word.\"]\ntheorem reduce.idem : reduce (reduce L) = reduce L :=\n  Eq.symm <| reduce.min reduce.red\n#align free_group.reduce.idem FreeGroup.reduce.idem\n#align free_add_group.reduce.idem FreeAddGroup.reduce.idem\n\n@[to_additive]\n\n\n/-- If a word reduces to another word, then they have a common maximal reduction. -/\n@[to_additive \"If a word reduces to another word, then they have a common maximal reduction.\"]\ntheorem reduce.eq_of_red (H : Red L\u2081 L\u2082) : reduce L\u2081 = reduce L\u2082 :=\n  let \u27e8_L\u2083, HR13, HR23\u27e9 := Red.church_rosser reduce.red (Red.trans H reduce.red)\n  (reduce.min HR13).trans (reduce.min HR23).symm\n#align free_group.reduce.eq_of_red FreeGroup.reduce.eq_of_red\n#align free_add_group.reduce.eq_of_red FreeAddGroup.reduce.eq_of_red\n\nalias reduce.eq_of_red \u2190 red.reduce_eq\n#align free_group.red.reduce_eq FreeGroup.red.reduce_eq\n\nalias FreeAddGroup.reduce.eq_of_red \u2190 freeAddGroup.red.reduce_eq\n#align free_group.free_add_group.red.reduce_eq FreeGroup.freeAddGroup.red.reduce_eq\n\n@[to_additive]\ntheorem Red.reduce_right (h : Red L\u2081 L\u2082) : Red L\u2081 (reduce L\u2082) :=\n  reduce.eq_of_red h \u25b8 reduce.red\n#align free_group.red.reduce_right FreeGroup.Red.reduce_right\n#align free_add_group.red.reduce_right FreeAddGroup.Red.reduce_right\n\n@[to_additive]\ntheorem Red.reduce_left (h : Red L\u2081 L\u2082) : Red L\u2082 (reduce L\u2081) :=\n  (reduce.eq_of_red h).symm \u25b8 reduce.red\n#align free_group.red.reduce_left FreeGroup.Red.reduce_left\n#align free_add_group.red.reduce_left FreeAddGroup.Red.reduce_left\n\n/-- If two words correspond to the same element in the free group, then they\nhave a common maximal reduction. This is the proof that the function that sends\nan element of the free group to its maximal reduction is well-defined. -/\n@[to_additive \"If two words correspond to the same element in the additive free group, then they\n  have a common maximal reduction. This is the proof that the function that sends an element of the\n  free group to its maximal reduction is well-defined.\"]\ntheorem reduce.sound (H : mk L\u2081 = mk L\u2082) : reduce L\u2081 = reduce L\u2082 :=\n  let \u27e8_L\u2083, H13, H23\u27e9 := Red.exact.1 H\n  (reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm\n#align free_group.reduce.sound FreeGroup.reduce.sound\n#align free_add_group.reduce.sound FreeAddGroup.reduce.sound\n\n/-- If two words have a common maximal reduction, then they correspond to the same element in the\n  free group. -/\n@[to_additive \"If two words have a common maximal reduction, then they correspond to the same\n  element in the additive free group.\"]\ntheorem reduce.exact (H : reduce L\u2081 = reduce L\u2082) : mk L\u2081 = mk L\u2082 :=\n  Red.exact.2 \u27e8reduce L\u2082, H \u25b8 reduce.red, reduce.red\u27e9\n#align free_group.reduce.exact FreeGroup.reduce.exact\n#align free_add_group.reduce.exact FreeAddGroup.reduce.exact\n\n/-- A word and its maximal reduction correspond to the same element of the free group. -/\n@[to_additive \"A word and its maximal reduction correspond to the same element of the additive free\n  group.\"]\ntheorem reduce.self : mk (reduce L) = mk L :=\n  reduce.exact reduce.idem\n#align free_group.reduce.self FreeGroup.reduce.self\n#align free_add_group.reduce.self FreeAddGroup.reduce.self\n\n/-- If words `w\u2081 w\u2082` are such that `w\u2081` reduces to `w\u2082`, then `w\u2082` reduces to the maximal reduction\n  of `w\u2081`. -/\n@[to_additive \"If words `w\u2081 w\u2082` are such that `w\u2081` reduces to `w\u2082`, then `w\u2082` reduces to the maximal\n  reduction of `w\u2081`.\"]\ntheorem reduce.rev (H : Red L\u2081 L\u2082) : Red L\u2082 (reduce L\u2081) :=\n  (reduce.eq_of_red H).symm \u25b8 reduce.red\n#align free_group.reduce.rev FreeGroup.reduce.rev\n#align free_add_group.reduce.rev FreeAddGroup.reduce.rev\n\n/-- The function that sends an element of the free group to its maximal reduction. -/\n@[to_additive \"The function that sends an element of the additive free group to its maximal\n  reduction.\"]\ndef toWord : FreeGroup \u03b1 \u2192 List (\u03b1 \u00d7 Bool) :=\n  Quot.lift reduce fun _L\u2081 _L\u2082 H => reduce.Step.eq H\n#align free_group.to_word FreeGroup.toWord\n#align free_add_group.to_word FreeAddGroup.toWord\n\n@[to_additive]\ntheorem mk_toWord : \u2200 {x : FreeGroup \u03b1}, mk (toWord x) = x := by rintro \u27e8L\u27e9; exact reduce.self\n#align free_group.mk_to_word FreeGroup.mk_toWord\n#align free_add_group.mk_to_word FreeAddGroup.mk_toWord\n\n@[to_additive]\ntheorem toWord_injective : Function.Injective (toWord : FreeGroup \u03b1 \u2192 List (\u03b1 \u00d7 Bool)) := by\n  rintro \u27e8L\u2081\u27e9 \u27e8L\u2082\u27e9; exact reduce.exact\n#align free_group.to_word_injective FreeGroup.toWord_injective\n#align free_add_group.to_word_injective FreeAddGroup.toWord_injective\n\n@[to_additive (attr:=simp)]\ntheorem toWord_inj {x y : FreeGroup \u03b1} : toWord x = toWord y \u2194 x = y :=\n  toWord_injective.eq_iff\n#align free_group.to_word_inj FreeGroup.toWord_inj\n#align free_add_group.to_word_inj FreeAddGroup.toWord_inj\n\n@[to_additive (attr:=simp)]\ntheorem toWord_mk : (mk L\u2081).toWord = reduce L\u2081 :=\n  rfl\n#align free_group.to_word_mk FreeGroup.toWord_mk\n#align free_add_group.to_word_mk FreeAddGroup.toWord_mk\n\n@[to_additive (attr:=simp)]\ntheorem reduce_toWord : \u2200 x : FreeGroup \u03b1, reduce (toWord x) = toWord x := by\n  rintro \u27e8L\u27e9\n  exact reduce.idem\n#align free_group.reduce_to_word FreeGroup.reduce_toWord\n#align free_add_group.reduce_to_word FreeAddGroup.reduce_toWord\n\n@[to_additive (attr:=simp)]\ntheorem toWord_one : (1 : FreeGroup \u03b1).toWord = [] :=\n  rfl\n#align free_group.to_word_one FreeGroup.toWord_one\n#align free_add_group.to_word_zero FreeAddGroup.toWord_zero\n\n@[to_additive (attr:=simp)]\ntheorem toWord_eq_nil_iff {x : FreeGroup \u03b1} : x.toWord = [] \u2194 x = 1 :=\n  toWord_injective.eq_iff' toWord_one\n#align free_group.to_word_eq_nil_iff FreeGroup.toWord_eq_nil_iff\n#align free_add_group.to_word_eq_nil_iff FreeAddGroup.toWord_eq_nil_iff\n\n@[to_additive]\ntheorem reduce_invRev {w : List (\u03b1 \u00d7 Bool)} : reduce (invRev w) = invRev (reduce w) := by\n  apply reduce.min\n  rw [\u2190 red_invRev_iff, invRev_invRev]\n  apply Red.reduce_left\n  have : Red (invRev (invRev w)) (invRev (reduce (invRev w))) := reduce.red.invRev\n  rwa [invRev_invRev] at this\n#align free_group.reduce_inv_rev FreeGroup.reduce_invRev\n#align free_add_group.reduce_neg_rev FreeAddGroup.reduce_negRev\n\n@[to_additive]\ntheorem toWord_inv {x : FreeGroup \u03b1} : x\u207b\u00b9.toWord = invRev x.toWord := by\n  rcases x with \u27e8L\u27e9\n  rw [quot_mk_eq_mk, inv_mk, toWord_mk, toWord_mk, reduce_invRev]\n#align free_group.to_word_inv FreeGroup.toWord_inv\n#align free_add_group.to_word_neg FreeAddGroup.toWord_neg\n\n/-- Constructive Church-Rosser theorem (compare `church_rosser`). -/\n@[to_additive \"Constructive Church-Rosser theorem (compare `church_rosser`).\"]\ndef reduce.churchRosser (H12 : Red L\u2081 L\u2082) (H13 : Red L\u2081 L\u2083) : { L\u2084 // Red L\u2082 L\u2084 \u2227 Red L\u2083 L\u2084 } :=\n  \u27e8reduce L\u2081, reduce.rev H12, reduce.rev H13\u27e9\n#align free_group.reduce.church_rosser FreeGroup.reduce.churchRosser\n#align free_add_group.reduce.church_rosser FreeAddGroup.reduce.churchRosser\n\n@[to_additive]\ninstance : DecidableEq (FreeGroup \u03b1) :=\n  toWord_injective.decidableEq\n\n-- TODO @[to_additive] doesn't succeed, possibly due to a bug\ninstance Red.decidableRel : DecidableRel (@Red \u03b1)\n  | [], [] => isTrue Red.refl\n  | [], _hd2 :: _tl2 => isFalse fun H => List.noConfusion (Red.nil_iff.1 H)\n  | (x, b) :: tl, [] =>\n    match Red.decidableRel tl [(x, not b)] with\n    | isTrue H => isTrue <| Red.trans (Red.cons_cons H) <| (@Red.Step.not _ [] [] _ _).to_red\n    | isFalse H => isFalse fun H2 => H <| Red.cons_nil_iff_singleton.1 H2\n  | (x1, b1) :: tl1, (x2, b2) :: tl2 =>\n    if h : (x1, b1) = (x2, b2) then\n      match Red.decidableRel tl1 tl2 with\n      | isTrue H => isTrue <| h \u25b8 Red.cons_cons H\n      | isFalse H => isFalse fun H2 => H $ (Red.cons_cons_iff _).1 $ h.symm \u25b8 H2\n    else\n      match Red.decidableRel tl1 ((x1, ! b1) :: (x2, b2) :: tl2) with\n      | isTrue H => isTrue <| (Red.cons_cons H).tail Red.Step.cons_not\n      | isFalse H => isFalse fun H2 => H <| Red.inv_of_red_of_ne h H2\n#align free_group.red.decidable_rel FreeGroup.Red.decidableRel\n\n/-- A list containing every word that `w\u2081` reduces to. -/\ndef Red.enum (L\u2081 : List (\u03b1 \u00d7 Bool)) : List (List (\u03b1 \u00d7 Bool)) :=\n  List.filter (Red L\u2081) (List.sublists L\u2081)\n#align free_group.red.enum FreeGroup.Red.enum\n\ntheorem Red.enum.sound (H : L\u2082 \u2208 List.filter (Red L\u2081) (List.sublists L\u2081)) : Red L\u2081 L\u2082 :=\n  of_decide_eq_true (@List.of_mem_filter _ _ L\u2082 _ H)\n#align free_group.red.enum.sound FreeGroup.Red.enum.sound\n\ntheorem Red.enum.complete (H : Red L\u2081 L\u2082) : L\u2082 \u2208 Red.enum L\u2081 :=\n  List.mem_filter_of_mem (List.mem_sublists.2 <| Red.sublist H) (decide_eq_true H)\n#align free_group.red.enum.complete FreeGroup.Red.enum.complete\n\ninstance : Fintype { L\u2082 // Red L\u2081 L\u2082 } :=\n  Fintype.subtype (List.toFinset <| Red.enum L\u2081) fun _L\u2082 =>\n    \u27e8fun H => Red.enum.sound <| List.mem_toFinset.1 H, fun H =>\n      List.mem_toFinset.2 <| Red.enum.complete H\u27e9\n\nend Reduce\n\nsection Metric\n\nvariable [DecidableEq \u03b1]\n\n/-- The length of reduced words provides a norm on a free group. -/\n@[to_additive \"The length of reduced words provides a norm on an additive free group.\"]\ndef norm (x : FreeGroup \u03b1) : \u2115 :=\n  x.toWord.length\n#align free_group.norm FreeGroup.norm\n#align free_add_group.norm FreeAddGroup.norm\n\n@[to_additive (attr:=simp)]\ntheorem norm_inv_eq {x : FreeGroup \u03b1} : norm x\u207b\u00b9 = norm x := by\n  simp only [norm, toWord_inv, invRev_length]\n#align free_group.norm_inv_eq FreeGroup.norm_inv_eq\n#align free_add_group.norm_neg_eq FreeAddGroup.norm_neg_eq\n\n@[to_additive (attr:=simp)]\ntheorem norm_eq_zero {x : FreeGroup \u03b1} : norm x = 0 \u2194 x = 1 := by\n  simp only [norm, List.length_eq_zero, toWord_eq_nil_iff]\n#align free_group.norm_eq_zero FreeGroup.norm_eq_zero\n#align free_add_group.norm_eq_zero FreeAddGroup.norm_eq_zero\n\n@[to_additive (attr:=simp)]\ntheorem norm_one : norm (1 : FreeGroup \u03b1) = 0 :=\n  rfl\n#align free_group.norm_one FreeGroup.norm_one\n#align free_add_group.norm_zero FreeAddGroup.norm_zero\n\n@[to_additive]\ntheorem norm_mk_le : norm (mk L\u2081) \u2264 L\u2081.length :=\n  reduce.red.length_le\n#align free_group.norm_mk_le FreeGroup.norm_mk_le\n#align free_add_group.norm_mk_le FreeAddGroup.norm_mk_le\n\n@[to_additive]\ntheorem norm_mul_le (x y : FreeGroup \u03b1) : norm (x * y) \u2264 norm x + norm y :=\n  calc\n    norm (x * y) = norm (mk (x.toWord ++ y.toWord)) := by rw [\u2190 mul_mk, mk_toWord, mk_toWord]\n    _ \u2264 (x.toWord ++ y.toWord).length := norm_mk_le\n    _ = norm x + norm y := List.length_append _ _\n\n#align free_group.norm_mul_le FreeGroup.norm_mul_le\n#align free_add_group.norm_add_le FreeAddGroup.norm_add_le\n\nend Metric\n\nend FreeGroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/GroupTheory/FreeGroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7108768414605292}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Kenny Lau, Scott Morrison\n\n! This file was ported from Lean 3 source module data.list.fin_range\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.List.OfFn\nimport Mathlib.Data.List.Perm\n\n/-!\n# Lists of elements of `Fin n`\n\nThis file develops some results on `finRange n`.\n-/\n\n\nuniverse u\n\nnamespace List\n\nvariable {\u03b1 : Type u}\n\n@[simp]\ntheorem map_coe_finRange (n : \u2115) : ((finRange n) : List (Fin n)).map (Fin.val) = List.range n := by\n  simp_rw [finRange, map_pmap, Fin.val_mk, pmap_eq_map]\n  exact List.map_id _\n#align list.map_coe_fin_range List.map_coe_finRange\n\ntheorem finRange_succ_eq_map (n : \u2115) : finRange n.succ = 0 :: (finRange n).map Fin.succ := by\n  apply map_injective_iff.mpr Fin.val_injective\n  rw [map_cons, map_coe_finRange, range_succ_eq_map, Fin.val_zero, \u2190 map_coe_finRange, map_map,\n    map_map]\n  simp only [Function.comp, Fin.val_succ]\n#align list.fin_range_succ_eq_map List.finRange_succ_eq_map\n\n-- Porting note : `map_nth_le` moved to `List.finRange_map_get` in Data.List.Range\n\ntheorem ofFn_eq_pmap {\u03b1 n} {f : Fin n \u2192 \u03b1} :\n    ofFn f = pmap (fun i hi => f \u27e8i, hi\u27e9) (range n) fun _ => mem_range.1 := by\n  (rw [pmap_eq_map_attach];\n    exact ext_get (by simp) fun i hi1 hi2 => by\n        simp [get_ofFn f \u27e8i, hi1\u27e9])\n#align list.of_fn_eq_pmap List.ofFn_eq_pmap\n\ntheorem ofFn_id (n) : ofFn id = finRange n :=\n  ofFn_eq_pmap\n#align list.of_fn_id List.ofFn_id\n\ntheorem ofFn_eq_map {\u03b1 n} {f : Fin n \u2192 \u03b1} : ofFn f = (finRange n).map f := by\n  rw [\u2190 ofFn_id, map_ofFn, Function.right_id]\n#align list.of_fn_eq_map List.ofFn_eq_map\n\ntheorem nodup_ofFn_ofInjective {\u03b1 n} {f : Fin n \u2192 \u03b1} (hf : Function.Injective f) :\n    Nodup (ofFn f) := by\n  rw [ofFn_eq_pmap]\n  exact (nodup_range n).pmap fun _ _ _ _ H => Fin.veq_of_eq <| hf H\n#align list.nodup_of_fn_of_injective List.nodup_ofFn_ofInjective\n\ntheorem nodup_ofFn {\u03b1 n} {f : Fin n \u2192 \u03b1} : Nodup (ofFn f) \u2194 Function.Injective f := by\n  refine' \u27e8_, nodup_ofFn_ofInjective\u27e9\n  refine' Fin.consInduction _ (fun x\u2080 xs ih => _) f\n  \u00b7 intro _\n    exact Function.injective_of_subsingleton _\n  \u00b7 intro h\n    rw [Fin.cons_injective_iff]\n    simp_rw [ofFn_succ, Fin.cons_succ, nodup_cons, Fin.cons_zero, mem_ofFn] at h\n    exact h.imp_right ih\n#align list.nodup_of_fn List.nodup_ofFn\n\nend List\n\nopen List\n\ntheorem Equiv.Perm.map_finRange_perm {n : \u2115} (\u03c3 : Equiv.Perm (Fin n)) :\n    map \u03c3 (finRange n) ~ finRange n := by\n  rw [perm_ext ((nodup_finRange n).map \u03c3.injective) <| nodup_finRange n]\n  simpa [mem_map, mem_finRange, true_and_iff, iff_true_iff] using \u03c3.surjective\n#align equiv.perm.map_fin_range_perm Equiv.Perm.map_finRange_perm\n\n/-- The list obtained from a permutation of a tuple `f` is permutation equivalent to\nthe list obtained from `f`. -/\ntheorem Equiv.Perm.ofFn_comp_perm {n : \u2115} {\u03b1 : Type u} (\u03c3 : Equiv.Perm (Fin n)) (f : Fin n \u2192 \u03b1) :\n    ofFn (f \u2218 \u03c3) ~ ofFn f := by\n  rw [ofFn_eq_map, ofFn_eq_map, \u2190 map_map]\n  exact \u03c3.map_finRange_perm.map f\n#align equiv.perm.of_fn_comp_perm Equiv.Perm.ofFn_comp_perm\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/List/FinRange.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7108768414605292}}
{"text": "-- Conmutatividad_del_supremo.lean\n-- Si R es un ret\u00edculo y x, y \u2208 R, entonces x \u2294 y = y \u2294 x.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 17-octubre-2022\n-- ---------------------------------------------------------------------\n\nimport order.lattice\n\nvariables {R : Type*} [lattice R]\nvariables x y : R\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nlemma aux1 : x \u2294 y \u2264 y \u2294 x :=\nbegin\n  have h1 : x \u2264 y \u2294 x,\n    by exact le_sup_right,\n  have h2 : y \u2264 y \u2294 x,\n    by exact le_sup_left,\n  show x \u2294 y \u2264 y \u2294 x,\n    by exact sup_le h1 h2,\nend\n\nexample : x \u2294 y = y \u2294 x :=\nbegin\n  have h1 : x \u2294 y \u2264 y \u2294 x,\n    by exact aux1 x y,\n  have h2 : y \u2294 x \u2264 x \u2294 y,\n    by exact aux1 y x,\n  show x \u2294 y = y \u2294 x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nlemma aux2 : x \u2294 y \u2264 y \u2294 x :=\nsup_le le_sup_right le_sup_left\n\nexample : x \u2294 y = y \u2294 x :=\nle_antisymm (aux2 x y) (aux2 y x)\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nlemma aux : x \u2294 y \u2264 y \u2294 x :=\nbegin\n  apply sup_le,\n  apply le_sup_right,\n  apply le_sup_left,\nend\n\nexample : x \u2294 y = y \u2294 x :=\nbegin\n  apply le_antisymm,\n  apply aux,\n  apply aux,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 y = y \u2294 x :=\nby apply le_antisymm; simp\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 y = y \u2294 x :=\n-- by library_search\nsup_comm\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 y = y \u2294 x :=\n-- by hint\nby finish\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Conmutatividad_del_supremo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7108768404617799}}
{"text": "-- Imagen_inversa_de_la_union.lean\n-- Imagen inversa de la uni\u00f3n\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 14 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables u v : set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    rw mem_preimage at h,\n    cases h with fxu fxv,\n    { left,\n      apply mem_preimage.mpr,\n      exact fxu, },\n    { right,\n      apply mem_preimage.mpr,\n      exact fxv, }},\n  { intro h,\n    rw mem_preimage,\n    cases h with xfu xfv,\n    { rw mem_preimage at xfu,\n      left,\n      exact xfu, },\n    { rw mem_preimage at xfv,\n      right,\n      exact xfv, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { intros h,\n    cases h with fxu fxv,\n    { left,\n      exact fxu, },\n    { right,\n      exact fxv, }},\n  { intro h,\n    cases h with xfu xfv,\n    { left,\n      exact xfu, },\n    { right,\n      exact xfv, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { rintro (fxu | fxv),\n    { exact or.inl fxu, },\n    { exact or.inr fxv, }},\n  { rintro (xfu | xfv),\n    { exact or.inl xfu, },\n    { exact or.inr xfv, }},\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  split,\n  { finish, },\n  { finish, } ,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nbegin\n  ext x,\n  finish,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nby ext; finish\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nby ext; refl\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nrfl\n\n-- 9\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\npreimage_union\n\n-- 10\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (u \u222a v) = f \u207b\u00b9' u \u222a f \u207b\u00b9' v :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Imagen_inversa_de_la_union.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7108768396423268}}
{"text": "-- import tactic\n/-\nStep 1:\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume (h\u2081 : p)(h\u2082 : q \u2227 r),\n_\n\np q r : Prop,\nh\u2081 : p,\nh\u2082 : q \u2227 r\n\u22a2 p \u2227 q\n\nStep 2:\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume (h\u2081 : p)(h\u2082 : q \u2227 r),\nhave h\u2083 : q, from and.left h\u2082,\n_\n\np q r : Prop,\nh\u2081 : p,\nh\u2082 : q \u2227 r,\nh\u2083 : q\n\u22a2 p \u2227 q\n\nStep 3:\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume (h\u2081 : p)(h\u2082 : q \u2227 r),\nhave h\u2083 : q, from and.left h\u2082,\nshow _, from and.intro _ _\n\np q r : Prop,\nh\u2081 : p,\nh\u2082 : q \u2227 r,\nh\u2083 : q\n\u22a2 p <=> h\u2081\n\u22a2 q <=> h\u2083\n\n-/\n\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume (h\u2081 : p)(h\u2082 : q \u2227 r),\nhave h\u2083 : q, from and.left h\u2082,\nshow p \u2227 q, from and.intro h\u2081 h\u2083\n\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume : p,\nassume : (q \u2227 r),\nhave q, from and.left this,\nshow p \u2227 q, from and.intro \u2039p\u203a this -- \u2039 = \\f, \u203a = \\frq\n\n-- \u2039p\u203a means (by assumption : p)\n-- \u2039_\u203a means (by assumption : _) means (by assumption)\n\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume : p,\nassume : (q \u2227 r),\nhave q, from and.left this,\nshow p \u2227 q, from and.intro (by assumption : p) this\n\n/-\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume (h\u2081 : p) (h\u2082 : q \u2227 r),\nsuffices h\u2083 : q, from _\n\np q r : Prop,\nh\u2081 : p,\nh\u2082 : q \u2227 r,\nh\u2083 : q\n\u22a2 p \u2227 q\n\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume (h\u2081 : p) (h\u2082 : q \u2227 r),\nsuffices h\u2083 : q, from and.intro h\u2081 h\u2083,\n_\n\np q r : Prop,\nh\u2081 : p,\nh\u2082 : q \u2227 r\n\u22a2 q <=> h\u2082.left\n-/\n\nexample (p q r : Prop) : p \u2192 (q \u2227 r) \u2192 p \u2227 q :=\nassume (h\u2081 : p) (h\u2082 : q \u2227 r),\nsuffices h\u2083 : q, from and.intro h\u2081 h\u2083,\nshow q, from h\u2082.left\n\n/- \nLean also supports calculational environment, which is\nintroduced with the keyword calc. The syntax is as follows:\ncalc\n  <expr>_0 'op_1' <expr>_1 ':' <proof>_1\n     '...' 'op_2' <expr>_2 ':' <proof>_2\n     ...\n     '...' 'op_n' <expr>_n ':' <proof>_n\n-/\n\nvariables (a b c d e : \u2115)\nvariable h1 : a = b\naxiom h2 : b = c + 1\nvariable h3 : c = d\nvariable h4 : e = 1 + d\n\n/-\nStep 1:\ntheorem T : a = e :=\ncalc\n  a   = b     : _ -- \u22a2 a = b\n  ... = c + 1 : _ -- \u22a2 b = c + 1\n  ... = d + 1 : _ -- \u22a2 c + 1 = d + 1\n  ... = 1 + d : _ -- \u22a2 d + 1 = 1 + d\n  ... = e     : _ -- \u22a2 1 + d = e\n\nStep 2:\n-/\n\n-- Equivalent ways of writing proof:\n-- 1. add_comm d _\n-- 2. by exact add_comm d _\n-- 3. by { exact add_comm d _, }\n-- 4. begin exact add_comm d _, end\n\ntheorem T : a = e :=\ncalc\n  a   = b     : h1 -- \u22a2 a = b\n  ... = c + 1 : h2 b c -- \u22a2 b = c + 1\n  ... = d + 1 : congr_arg nat.succ h3 -- \u22a2 c + 1 = d + 1\n  ... = 1 + d : add_comm d _ -- \u22a2 d + 1 = 1 + d, _ <=> (1 : \u2115)\n  ... = e     : h4.symm -- \u22a2 1 + d = e\n\n-- congr_arg : \u2200 {\u03b1 \u03b2 : Type} {a\u2081 a\u2082 : \u03b1}\n--   (f : \u03b1 \u2192 \u03b2), a\u2081 = a\u2082 \u2192 f a\u2081 = f a\u2082\n\n-- add_comm : \u2200 {\u03b1 : Type} [_inst_1 : add_comm_semigroup \u03b1]\n--   (a b : \u03b1), a + b = b + a\n\n-- eq.symm : \u2200 {\u03b1 : Type} {a b : \u03b1},\n--   a = b \u2192 b = a\n/-\nmeta def f : \u2115 \u2192 bool\n| 0 :=  bor (f 1) (f 2)\n| (nat.succ n) := f n\n-/\n\nconstant f : nat \u2192 bool\n\n-- Lean: invalid definition, it uses untrusted declaration 'f'\naxiom f\u2080 : f 0 = bor (f 1) (f 2)\naxiom f_ind : \u2200 n, n > 0 \u2192 f (n + 1) = f n\n\n-- let f 0 = false => f 1 \u2228 f 2 = false => f 1 = false, f 2 = false\n-- \u2200 n, n > 0 \u2192 f (n + 1) = f n => f 3 = f 2 = false, f 4 = f 3 = false, ... , f (n : nat, n > 0) = false = f 0\n\n-- let f 0 = true => f 1 \u2228 f 2 = true\n-- \u2200 n, n > 0 \u2192 f (n + 1) = f n => f 2 = f 1 => f 1 \u2228 f 1 = true => f 1 = true => f 2 = true => ... => f (n : nat, n > 0) = true = f 0\n\n-- => lemma \u2200 n, n > 0 \u2192 f n = f 0\n\nset_option trace.simplify.rewrite true\n\nlemma fn_eq_f0 : \u2200 n, n > 0 \u2192 f n = f 0 :=\nbegin\n  intros n n_gt_0,\n  have h : n > 0 \u2192 n = 1 \u2228 n > 1 := sorry,\n  cases (h n_gt_0) with h_n_eq_1 n_gt_1,\n  rw h_n_eq_1,\n  have h\u2080 : f 0 = tt \u2228 f 0 = ff := sorry,\n  cases h\u2080,\n  rw f\u2080,\n  suffices f\u2082_true : f 2 = tt,\n  rw f\u2082_true,\n  -- simp, -- [simplify.rewrite] [bor_tt]: f 1 || tt ==> tt\n  rw bor_tt,\n  by_contradiction H,\n  -- simp at H, -- [simplify.rewrite] [eq_ff_eq_not_eq_tt]: \u00acf 1 = tt ==> f 1 = ff\n  rw eq_ff_eq_not_eq_tt at H,\n  have ind\u2081 := f_ind 1,\n  change 1 > _ \u2192 f 2 = f 1 at ind\u2081,\n  have one_gt_zero : 1 > 0 := sorry,\n  have f\u2081_eq_f\u2082 := ind\u2081 one_gt_zero, clear ind\u2081,\n  rw f\u2081_eq_f\u2082 at f\u2082_true,\n  rw f\u2082_true at H,\n  contradiction,\n\n  all_goals { sorry, },\nend\n\n/-\nkernel failed to type check declaration 'fn_eq_f0' this is usually due to a buggy tactic or a bug in the builtin elaborator\nelaborated type:\n  \u2200 (n : \u2115), n > 0 \u2192 f n = f 0\nelaborated value:\n  \u03bb (n : \u2115) (n_gt_0 : n > 0), sorry\nnested exception message:\ninvalid definition, it uses untrusted declaration 'f'\n-/\n-- ************************************************************************************************************************************\n-- axiom f\u2080 : f 0 = bor (f 1) (f 2)\n-- axiom f_ind : \u2200 n, n > 0 \u2192 f (n + 1) = f n\n\n-- let f 0 = false => f 1 \u2228 f 2 = false => f 1 = false, f 2 = false\n-- \u2200 n, n > 0 \u2192 f (n + 1) = f n => f 3 = f 2 = false, f 4 = f 3 = false, ... , f (n : nat, n > 0) = false = f 0\n\n-- let f 0 = true => f 1 \u2228 f 2 = true\n-- \u2200 n, n > 0 \u2192 f (n + 1) = f n => f 2 = f 1 => f 1 \u2228 f 1 = true => f 1 = true => f 2 = true => ... => f (n : nat, n > 0) = true = f 0\n\n-- => lemma \u2200 n, n > 0 \u2192 f n = f 0\n-- ************************************************************************************************************************************\n\n-- ih : n > 0 \u2192 f n = f 0\n-- \u22a2 n.succ > 0 \u2192 f n.succ = f 0\nlemma induction_lemma_false_case (f\u2080_false : f 0 = ff) (f\u2081_false : f 1 = ff) \n  (n : \u2115): (n > 0 \u2192 f n = f 0) \u2192 n.succ > 0 \u2192 f n.succ = f 0 := sorry\n\nlemma fn_eq_f0'' : \u2200 n, n > 0 \u2192 f n = f 0 :=\nbegin\n  intro n,\n  have bool_f\u2080 : f 0 = ff \u2228 f 0 = tt, from sorry,\n  cases bool_f\u2080 with f\u2080_false f\u2080_true,\n  { -- f\u2080_false : f 0 = ff\n    have H : bor (f 1) (f 2) = ff, {\n      rw <-f\u2080_false,\n      apply f\u2080.symm,\n    },\n    have bool_lemma : \u2200 (a b : bool), a || b = ff = (a = ff \u2227 b = ff), {\n      intros a b,\n      -- simp, -- [bor_eq_false_eq_eq_ff_and_eq_ff]: a || b = ff ==> a = ff \u2227 b = ff\n      rw bor_eq_false_eq_eq_ff_and_eq_ff,\n      -- library_search, -- not return a result, still calculating...\n    },\n    have h2 := bool_lemma (f 1) (f 2),\n    rw h2 at H,\n    type_check H.1, -- f 1 = ff\n    type_check H.2, -- f 2 = ff\n    have f\u2081_false := H.1, have f\u2082_false := H.2, clear H h2 bool_lemma,\n\n    induction n with n ih,\n    have h := eq.refl (f 0),\n    -- have false_imp : \u2200 (a : Prop),  false \u2192 a, {\n    --   intro a,\n    --   rw false_implies_iff, trivial,\n    -- },\n    have zero_ge_zero_is_false : 0 > 0 = false, {\n      -- apply _,\n      sorry,\n    },\n    rw zero_ge_zero_is_false,\n    intro, exfalso, exact a,\n    exact induction_lemma_false_case f\u2080_false f\u2081_false n ih,\n  },\n  { -- f\u2080_true : f 0 = tt\n    sorry,\n  },\nend\n\nlemma fn_eq_f0' : \u2200 n, n > 0 \u2192 f n = f 0 :=\nbegin\n  intro n,\n  induction n with n ih,\n  case nat.zero {\n    -- \u22a2 0 > 0 \u2192 f 0 = f 0\n    simp,\n    -- [nat.nat_zero_eq_zero]: 0 ==> 0\n    -- [eq_self_iff_true]: f 0 = f 0 ==> true\n    -- [implies_true_iff]: 0 > 0 \u2192 true ==> true\n  },\n  case nat.succ {\n    -- \u22a2 n.succ > 0 \u2192 f n.succ = f 0\n    have bool_f\u2080 : f 0 = tt \u2228 f 0 = ff, from sorry,\n    cases bool_f\u2080 with f\u2080_true f\u2080_false,\n    case or.inl {\n      rw f\u2080_true,\n      rw f\u2080_true at ih,\n      sorry,\n    },\n    case or.inr {\n      -- rw f\u2080_false,\n      rw f\u2080_false at ih,\n      intro h_nsucc,\n      -- have H: f n = ff \u2192 f n.succ = ff, sorry,\n      have H := f_ind n,\n      change n > 0 \u2192 f n.succ = f n at H,\n      have h_gt_nat : n = 0 \u2228 n > 0, sorry,\n      cases h_gt_nat,\n      case or.inl {\n        rw h_gt_nat,\n        sorry,\n      },\n      case or.inr {\n        sorry,\n      },\n    },\n  },\nend\n", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/manual/structured_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7108768367357277}}
{"text": "import algebra.group.defs\nimport logic.function.basic\nimport algebra.group.basic\n\nsection group\n\nvariables {M : Type} [mul_one_class M]\n\nlemma eq_one_iff_eq_one_of_mul_eq_one' {a b : M} (h : a * b = 1) : a = 1 \u2194 b = 1 :=\n  by split; { rintro rfl, simpa using h}\n\nlemma one_mul_eq_id' : ((*) (1 : M)) = id := funext one_mul\n/-\nbegin\n  funext x,\n  simp only [one_mul, id.def],\nend\n-/\n\nvariables {G : Type} [group G] {a b c : G}\n\nlemma inv_mul_cancel_right' (a b : G) : a * b\u207b\u00b9 * b = a := -- by simp [mul_assoc]\nbegin\n  simp [mul_assoc],\nend\n\ntheorem mul_right_surjective' (a : G) : function.surjective (\u03bb x, x * a) := \n  \u03bb x, \u27e8x * a\u207b\u00b9, inv_mul_cancel_right x a\u27e9\n\n\n/-\nbegin\n  intros x,\n  use (x * a\u207b\u00b9),\n  apply inv_mul_cancel_right,\nend\n-/\n\ntheorem inv_eq_one' : a\u207b\u00b9 = 1 \u2194 a = 1 :=\nbegin\n  rw [\u2190 @inv_inj _ _ a 1, one_inv],\nend\n-- by rw [\u2190 @inv_inj _ _ a 1, one_inv]\n\n\nend group\n\nsection add_group\n\nvariables {G : Type} [add_group G] {a b c d : G}\n\nlemma eq_of_sub_eq_zero' (h : a - b = 0) : a = b :=\ncalc a = a - b + b : (sub_add_cancel a b).symm\n   ... = b         : by rw [h, zero_add]\n\n#check (sub_add_cancel a b).symm\n\nexample : a = a - b + b :=\nbegin\n  apply (sub_add_cancel a b).symm\nend\n\nlemma eq_of_sub_eq_zero'' (h : a - b = 0) : a = b :=\ncalc a = a - b + b : (sub_add_cancel a b).symm\n  ...  = b         : by rw [h, zero_add]\n\nend add_group", "meta": {"author": "jamesa9283", "repo": "LiaLeanTutor", "sha": "c7ac1400f26eb2992f5f1ee0aaafb54b74665072", "save_path": "github-repos/lean/jamesa9283-LiaLeanTutor", "path": "github-repos/lean/jamesa9283-LiaLeanTutor/LiaLeanTutor-c7ac1400f26eb2992f5f1ee0aaafb54b74665072/src/wk1/Notes/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7108768348278776}}
{"text": "import group_theory.coset set_theory.cardinal data.fintype.basic\n\n\nvariables (G : Type*) [set G][group G] \n\n\ndef subgroup_index (H:subgroup G) := cardinal.mk (quotient_group.quotient H)\n\n\nlemma index_in_finite_group_is_finite [h_fin : fintype G] (H: subgroup G)[h_dec : decidable_eq (quotient_group.quotient H)]: \nfintype (quotient_group.quotient H):= \n\nbegin\n    apply fintype.of_surjective quotient_group.mk,\n    intro b,\n    apply quot.exists_rep,\n    exact h_dec,\n    exact h_fin,\nend", "meta": {"author": "pglutz", "repo": "galois_theory", "sha": "4561c2c97d4c49377356e1d7a2051dedc87d30ba", "save_path": "github-repos/lean/pglutz-galois_theory", "path": "github-repos/lean/pglutz-galois_theory/galois_theory-4561c2c97d4c49377356e1d7a2051dedc87d30ba/src/index_of_subgroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172587090974, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.710821779487493}}
{"text": "/-\nCopyright (c) 2022 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n-/\n\nimport probability.variance\n\n/-!\n# Moments and moment generating function\n\n## Main definitions\n\n* `probability_theory.moment X p \u03bc`: `p`th moment of a real random variable `X` with respect to\n  measure `\u03bc`, `\u03bc[X^p]`\n* `probability_theory.central_moment X p \u03bc`:`p`th central moment of `X` with respect to measure `\u03bc`,\n  `\u03bc[(X - \u03bc[X])^p]`\n* `probability_theory.mgf X \u03bc t`: moment generating function of `X` with respect to measure `\u03bc`,\n  `\u03bc[exp(t*X)]`\n* `probability_theory.cgf X \u03bc t`: cumulant generating function, logarithm of the moment generating\n  function\n\n## Main results\n\n* `probability_theory.indep_fun.mgf_add`: if two real random variables `X` and `Y` are independent\n  and their mgf are defined at `t`, then `mgf (X + Y) \u03bc t = mgf X \u03bc t * mgf Y \u03bc t`\n* `probability_theory.indep_fun.cgf_add`: if two real random variables `X` and `Y` are independent\n  and their mgf are defined at `t`, then `cgf (X + Y) \u03bc t = cgf X \u03bc t + cgf Y \u03bc t`\n* `probability_theory.measure_ge_le_exp_cgf` and `probability_theory.measure_le_le_exp_cgf`:\n  Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that\n  the cgf exists, `\u2119(\u03b5 \u2264 X) \u2264 exp(- t*\u03b5 + cgf X \u2119 t)`. See also\n  `probability_theory.measure_ge_le_exp_mul_mgf` and\n  `probability_theory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead\n  of `cgf`.\n\n-/\n\nopen measure_theory filter finset real\n\nnoncomputable theory\n\nopen_locale big_operators measure_theory probability_theory ennreal nnreal\n\nnamespace probability_theory\n\nvariables {\u03a9 \u03b9 : Type*} {m : measurable_space \u03a9} {X : \u03a9 \u2192 \u211d} {p : \u2115} {\u03bc : measure \u03a9}\n\ninclude m\n\n/-- Moment of a real random variable, `\u03bc[X ^ p]`. -/\ndef moment (X : \u03a9 \u2192 \u211d) (p : \u2115) (\u03bc : measure \u03a9) : \u211d := \u03bc[X ^ p]\n\n/-- Central moment of a real random variable, `\u03bc[(X - \u03bc[X]) ^ p]`. -/\ndef central_moment (X : \u03a9 \u2192 \u211d) (p : \u2115) (\u03bc : measure \u03a9) : \u211d := \u03bc[(X - (\u03bb x, \u03bc[X])) ^ p]\n\n@[simp] lemma moment_zero (hp : p \u2260 0) : moment 0 p \u03bc = 0 :=\nby simp only [moment, hp, zero_pow', ne.def, not_false_iff, pi.zero_apply, integral_const,\n  algebra.id.smul_eq_mul, mul_zero]\n\n@[simp] lemma central_moment_zero (hp : p \u2260 0) : central_moment 0 p \u03bc = 0 :=\nby simp only [central_moment, hp, pi.zero_apply, integral_const, algebra.id.smul_eq_mul,\n  mul_zero, zero_sub, pi.pow_apply, pi.neg_apply, neg_zero, zero_pow', ne.def, not_false_iff]\n\nlemma central_moment_one' [is_finite_measure \u03bc] (h_int : integrable X \u03bc) :\n  central_moment X 1 \u03bc = (1 - (\u03bc set.univ).to_real) * \u03bc[X] :=\nbegin\n  simp only [central_moment, pi.sub_apply, pow_one],\n  rw integral_sub h_int (integrable_const _),\n  simp only [sub_mul, integral_const, algebra.id.smul_eq_mul, one_mul],\nend\n\n@[simp] lemma central_moment_one [is_probability_measure \u03bc] : central_moment X 1 \u03bc = 0 :=\nbegin\n  by_cases h_int : integrable X \u03bc,\n  { rw central_moment_one' h_int,\n    simp only [measure_univ, ennreal.one_to_real, sub_self, zero_mul], },\n  { simp only [central_moment, pi.sub_apply, pow_one],\n    have : \u00ac integrable (\u03bb x, X x - integral \u03bc X) \u03bc,\n    { refine \u03bb h_sub, h_int _,\n      have h_add : X = (\u03bb x, X x - integral \u03bc X) + (\u03bb x, integral \u03bc X),\n      { ext1 x, simp, },\n      rw h_add,\n      exact h_sub.add (integrable_const _), },\n    rw integral_undef this, },\nend\n\nlemma central_moment_two_eq_variance [is_finite_measure \u03bc] (hX : mem_\u2112p X 2 \u03bc) :\n  central_moment X 2 \u03bc = variance X \u03bc :=\nby { rw hX.variance_eq, refl, }\n\nsection moment_generating_function\n\nvariables {t : \u211d}\n\n/-- Moment generating function of a real random variable `X`: `\u03bb t, \u03bc[exp(t*X)]`. -/\ndef mgf (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) (t : \u211d) : \u211d := \u03bc[\u03bb \u03c9, exp (t * X \u03c9)]\n\n/-- Cumulant generating function of a real random variable `X`: `\u03bb t, log \u03bc[exp(t*X)]`. -/\ndef cgf (X : \u03a9 \u2192 \u211d) (\u03bc : measure \u03a9) (t : \u211d) : \u211d := log (mgf X \u03bc t)\n\n@[simp] lemma mgf_zero_fun : mgf 0 \u03bc t = (\u03bc set.univ).to_real :=\nby simp only [mgf, pi.zero_apply, mul_zero, exp_zero, integral_const, algebra.id.smul_eq_mul,\n  mul_one]\n\n@[simp] lemma cgf_zero_fun : cgf 0 \u03bc t = log (\u03bc set.univ).to_real :=\nby simp only [cgf, mgf_zero_fun]\n\n@[simp] lemma mgf_zero_measure : mgf X (0 : measure \u03a9) t = 0 :=\nby simp only [mgf, integral_zero_measure]\n\n@[simp] lemma cgf_zero_measure : cgf X (0 : measure \u03a9) t = 0 :=\nby simp only [cgf, log_zero, mgf_zero_measure]\n\n@[simp] lemma mgf_const' (c : \u211d) : mgf (\u03bb _, c) \u03bc t = (\u03bc set.univ).to_real * exp (t * c) :=\nby simp only [mgf, integral_const, algebra.id.smul_eq_mul]\n\n@[simp] lemma mgf_const (c : \u211d) [is_probability_measure \u03bc] : mgf (\u03bb _, c) \u03bc t = exp (t * c) :=\nby simp only [mgf_const', measure_univ, ennreal.one_to_real, one_mul]\n\n@[simp] lemma cgf_const' [is_finite_measure \u03bc] (h\u03bc : \u03bc \u2260 0) (c : \u211d) :\n  cgf (\u03bb _, c) \u03bc t = log (\u03bc set.univ).to_real + t * c :=\nbegin\n  simp only [cgf, mgf_const'],\n  rw log_mul _ (exp_pos _).ne',\n  { rw log_exp _, },\n  { rw [ne.def, ennreal.to_real_eq_zero_iff, measure.measure_univ_eq_zero],\n    simp only [h\u03bc, measure_ne_top \u03bc set.univ, or_self, not_false_iff], },\nend\n\n@[simp] lemma cgf_const [is_probability_measure \u03bc] (c : \u211d) : cgf (\u03bb _, c) \u03bc t = t * c :=\nby simp only [cgf, mgf_const, log_exp]\n\n@[simp] lemma mgf_zero' : mgf X \u03bc 0 = (\u03bc set.univ).to_real :=\nby simp only [mgf, zero_mul, exp_zero, integral_const, algebra.id.smul_eq_mul, mul_one]\n\n@[simp] lemma mgf_zero [is_probability_measure \u03bc] : mgf X \u03bc 0 = 1 :=\nby simp only [mgf_zero', measure_univ, ennreal.one_to_real]\n\n@[simp] lemma cgf_zero' : cgf X \u03bc 0 = log (\u03bc set.univ).to_real :=\nby simp only [cgf, mgf_zero']\n\n@[simp] lemma cgf_zero [is_probability_measure \u03bc] : cgf X \u03bc 0 = 0 :=\nby simp only [cgf_zero', measure_univ, ennreal.one_to_real, log_one]\n\nlemma mgf_undef (hX : \u00ac integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) : mgf X \u03bc t = 0 :=\nby simp only [mgf, integral_undef hX]\n\nlemma cgf_undef (hX : \u00ac integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) : cgf X \u03bc t = 0 :=\nby simp only [cgf, mgf_undef hX, log_zero]\n\nlemma mgf_nonneg : 0 \u2264 mgf X \u03bc t :=\nbegin\n  refine integral_nonneg _,\n  intro \u03c9,\n  simp only [pi.zero_apply],\n  exact (exp_pos _).le,\nend\n\nlemma mgf_pos' (h\u03bc : \u03bc \u2260 0) (h_int_X : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) : 0 < mgf X \u03bc t :=\nbegin\n  simp_rw mgf,\n  have : \u222b (x : \u03a9), exp (t * X x) \u2202\u03bc = \u222b (x : \u03a9) in set.univ, exp (t * X x) \u2202\u03bc,\n  { simp only [measure.restrict_univ], },\n  rw [this, set_integral_pos_iff_support_of_nonneg_ae _ _],\n  { have h_eq_univ : function.support (\u03bb (x : \u03a9), exp (t * X x)) = set.univ,\n    { ext1 x,\n      simp only [function.mem_support, set.mem_univ, iff_true],\n      exact (exp_pos _).ne', },\n    rw [h_eq_univ, set.inter_univ _],\n    refine ne.bot_lt _,\n    simp only [h\u03bc, ennreal.bot_eq_zero, ne.def, measure.measure_univ_eq_zero, not_false_iff], },\n  { refine eventually_of_forall (\u03bb x, _),\n    rw pi.zero_apply,\n    exact (exp_pos _).le, },\n  { rwa integrable_on_univ, },\nend\n\nlemma mgf_pos [is_probability_measure \u03bc] (h_int_X : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) :\n  0 < mgf X \u03bc t :=\nmgf_pos' (is_probability_measure.ne_zero \u03bc) h_int_X\n\nlemma mgf_neg : mgf (-X) \u03bc t = mgf X \u03bc (-t) :=\nby simp_rw [mgf, pi.neg_apply, mul_neg, neg_mul]\n\nlemma cgf_neg : cgf (-X) \u03bc t = cgf X \u03bc (-t) := by simp_rw [cgf, mgf_neg]\n\n/-- This is a trivial application of `indep_fun.comp` but it will come up frequently. -/\nlemma indep_fun.exp_mul {X Y : \u03a9 \u2192 \u211d} (h_indep : indep_fun X Y \u03bc) (s t : \u211d) :\n  indep_fun (\u03bb \u03c9, exp (s * X \u03c9)) (\u03bb \u03c9, exp (t * Y \u03c9)) \u03bc :=\nbegin\n  have h_meas : \u2200 t, measurable (\u03bb x, exp (t * x)) := \u03bb t, (measurable_id'.const_mul t).exp,\n  change indep_fun ((\u03bb x, exp (s * x)) \u2218 X) ((\u03bb x, exp (t * x)) \u2218 Y) \u03bc,\n  exact indep_fun.comp h_indep (h_meas s) (h_meas t),\nend\n\n\n\nlemma indep_fun.mgf_add' {X Y : \u03a9 \u2192 \u211d} (h_indep : indep_fun X Y \u03bc)\n  (hX : ae_strongly_measurable X \u03bc) (hY : ae_strongly_measurable Y \u03bc) :\n  mgf (X + Y) \u03bc t = mgf X \u03bc t * mgf Y \u03bc t :=\nbegin\n  have A : continuous (\u03bb (x : \u211d), exp (t * x)), by continuity,\n  have h'X : ae_strongly_measurable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc :=\n    A.ae_strongly_measurable.comp_ae_measurable hX.ae_measurable,\n  have h'Y : ae_strongly_measurable (\u03bb \u03c9, exp (t * Y \u03c9)) \u03bc :=\n    A.ae_strongly_measurable.comp_ae_measurable hY.ae_measurable,\n  exact h_indep.mgf_add h'X h'Y\nend\n\nlemma indep_fun.cgf_add {X Y : \u03a9 \u2192 \u211d} (h_indep : indep_fun X Y \u03bc)\n  (h_int_X : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc)\n  (h_int_Y : integrable (\u03bb \u03c9, exp (t * Y \u03c9)) \u03bc) :\n  cgf (X + Y) \u03bc t = cgf X \u03bc t + cgf Y \u03bc t :=\nbegin\n  by_cases h\u03bc : \u03bc = 0,\n  { simp [h\u03bc], },\n  simp only [cgf, h_indep.mgf_add h_int_X.ae_strongly_measurable h_int_Y.ae_strongly_measurable],\n  exact log_mul (mgf_pos' h\u03bc h_int_X).ne' (mgf_pos' h\u03bc h_int_Y).ne',\nend\n\nlemma ae_strongly_measurable_exp_mul_add {X Y : \u03a9 \u2192 \u211d}\n  (h_int_X : ae_strongly_measurable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc)\n  (h_int_Y : ae_strongly_measurable (\u03bb \u03c9, exp (t * Y \u03c9)) \u03bc) :\n  ae_strongly_measurable (\u03bb \u03c9, exp (t * (X + Y) \u03c9)) \u03bc :=\nbegin\n  simp_rw [pi.add_apply, mul_add, exp_add],\n  exact ae_strongly_measurable.mul h_int_X h_int_Y,\nend\n\nlemma ae_strongly_measurable_exp_mul_sum {X : \u03b9 \u2192 \u03a9 \u2192 \u211d} {s : finset \u03b9}\n  (h_int : \u2200 i \u2208 s, ae_strongly_measurable (\u03bb \u03c9, exp (t * X i \u03c9)) \u03bc) :\n  ae_strongly_measurable (\u03bb \u03c9, exp (t * (\u2211 i in s, X i) \u03c9)) \u03bc :=\nbegin\n  classical,\n  induction s using finset.induction_on with i s hi_notin_s h_rec h_int,\n  { simp only [pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero],\n    exact ae_strongly_measurable_const, },\n  { have : \u2200 (i : \u03b9), i \u2208 s \u2192 ae_strongly_measurable (\u03bb (\u03c9 : \u03a9), exp (t * X i \u03c9)) \u03bc,\n      from \u03bb i hi, h_int i (mem_insert_of_mem hi),\n    specialize h_rec this,\n    rw sum_insert hi_notin_s,\n    apply ae_strongly_measurable_exp_mul_add (h_int i (mem_insert_self _ _)) h_rec }\nend\n\nlemma indep_fun.integrable_exp_mul_add {X Y : \u03a9 \u2192 \u211d} (h_indep : indep_fun X Y \u03bc)\n  (h_int_X : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc)\n  (h_int_Y : integrable (\u03bb \u03c9, exp (t * Y \u03c9)) \u03bc) :\n  integrable (\u03bb \u03c9, exp (t * (X + Y) \u03c9)) \u03bc :=\nbegin\n  simp_rw [pi.add_apply, mul_add, exp_add],\n  exact (h_indep.exp_mul t t).integrable_mul h_int_X h_int_Y,\nend\n\nlemma Indep_fun.integrable_exp_mul_sum [is_probability_measure \u03bc]\n  {X : \u03b9 \u2192 \u03a9 \u2192 \u211d} (h_indep : Indep_fun (\u03bb i, infer_instance) X \u03bc) (h_meas : \u2200 i, measurable (X i))\n  {s : finset \u03b9} (h_int : \u2200 i \u2208 s, integrable (\u03bb \u03c9, exp (t * X i \u03c9)) \u03bc) :\n  integrable (\u03bb \u03c9, exp (t * (\u2211 i in s, X i) \u03c9)) \u03bc :=\nbegin\n  classical,\n  induction s using finset.induction_on with i s hi_notin_s h_rec h_int,\n  { simp only [pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero],\n    exact integrable_const _, },\n  { have : \u2200 (i : \u03b9), i \u2208 s \u2192 integrable (\u03bb (\u03c9 : \u03a9), exp (t * X i \u03c9)) \u03bc,\n      from \u03bb i hi, h_int i (mem_insert_of_mem hi),\n    specialize h_rec this,\n    rw sum_insert hi_notin_s,\n    refine indep_fun.integrable_exp_mul_add _ (h_int i (mem_insert_self _ _)) h_rec,\n    exact (h_indep.indep_fun_finset_sum_of_not_mem h_meas hi_notin_s).symm, },\nend\n\nlemma Indep_fun.mgf_sum [is_probability_measure \u03bc]\n  {X : \u03b9 \u2192 \u03a9 \u2192 \u211d} (h_indep : Indep_fun (\u03bb i, infer_instance) X \u03bc) (h_meas : \u2200 i, measurable (X i))\n  (s : finset \u03b9) :\n  mgf (\u2211 i in s, X i) \u03bc t = \u220f i in s, mgf (X i) \u03bc t :=\nbegin\n  classical,\n  induction s using finset.induction_on with i s hi_notin_s h_rec h_int,\n  { simp only [sum_empty, mgf_zero_fun, measure_univ, ennreal.one_to_real, prod_empty], },\n  { have h_int' : \u2200 (i : \u03b9), ae_strongly_measurable (\u03bb (\u03c9 : \u03a9), exp (t * X i \u03c9)) \u03bc,\n      from \u03bb i, ((h_meas i).const_mul t).exp.ae_strongly_measurable,\n    rw [sum_insert hi_notin_s, indep_fun.mgf_add\n          (h_indep.indep_fun_finset_sum_of_not_mem h_meas hi_notin_s).symm (h_int' i)\n          (ae_strongly_measurable_exp_mul_sum (\u03bb i hi, h_int' i)),\n        h_rec, prod_insert hi_notin_s] }\nend\n\nlemma Indep_fun.cgf_sum [is_probability_measure \u03bc]\n  {X : \u03b9 \u2192 \u03a9 \u2192 \u211d} (h_indep : Indep_fun (\u03bb i, infer_instance) X \u03bc) (h_meas : \u2200 i, measurable (X i))\n  {s : finset \u03b9} (h_int : \u2200 i \u2208 s, integrable (\u03bb \u03c9, exp (t * X i \u03c9)) \u03bc) :\n  cgf (\u2211 i in s, X i) \u03bc t = \u2211 i in s, cgf (X i) \u03bc t :=\nbegin\n  simp_rw cgf,\n  rw \u2190 log_prod _ _ (\u03bb j hj, _),\n  { rw h_indep.mgf_sum h_meas },\n  { exact (mgf_pos (h_int j hj)).ne', },\nend\n\n/-- **Chernoff bound** on the upper tail of a real random variable. -/\nlemma measure_ge_le_exp_mul_mgf [is_finite_measure \u03bc] (\u03b5 : \u211d) (ht : 0 \u2264 t)\n  (h_int : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) :\n  (\u03bc {\u03c9 | \u03b5 \u2264 X \u03c9}).to_real \u2264 exp (- t * \u03b5) * mgf X \u03bc t :=\nbegin\n  cases ht.eq_or_lt with ht_zero_eq ht_pos,\n  { rw ht_zero_eq.symm,\n    simp only [neg_zero, zero_mul, exp_zero, mgf_zero', one_mul],\n    rw ennreal.to_real_le_to_real (measure_ne_top \u03bc _) (measure_ne_top \u03bc _),\n    exact measure_mono (set.subset_univ _), },\n  calc (\u03bc {\u03c9 | \u03b5 \u2264 X \u03c9}).to_real\n      = (\u03bc {\u03c9 | exp (t * \u03b5) \u2264 exp (t * X \u03c9)}).to_real :\n    begin\n      congr' with \u03c9,\n      simp only [exp_le_exp, eq_iff_iff],\n      exact \u27e8\u03bb h, mul_le_mul_of_nonneg_left h ht_pos.le, \u03bb h, le_of_mul_le_mul_left h ht_pos\u27e9,\n    end\n  ... \u2264 (exp (t * \u03b5))\u207b\u00b9 * \u03bc[\u03bb \u03c9, exp (t * X \u03c9)] :\n    begin\n      have : exp (t * \u03b5) * (\u03bc {\u03c9 | exp (t * \u03b5) \u2264 exp (t * X \u03c9)}).to_real\n          \u2264 \u03bc[\u03bb \u03c9, exp (t * X \u03c9)],\n        from mul_meas_ge_le_integral_of_nonneg (\u03bb x, (exp_pos _).le) h_int _,\n      rwa [mul_comm (exp (t * \u03b5))\u207b\u00b9, \u2190 div_eq_mul_inv, le_div_iff' (exp_pos _)],\n    end\n  ... = exp (- t * \u03b5) * mgf X \u03bc t : by { rw [neg_mul, exp_neg], refl, },\nend\n\n/-- **Chernoff bound** on the lower tail of a real random variable. -/\nlemma measure_le_le_exp_mul_mgf [is_finite_measure \u03bc] (\u03b5 : \u211d) (ht : t \u2264 0)\n  (h_int : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) :\n  (\u03bc {\u03c9 | X \u03c9 \u2264 \u03b5}).to_real \u2264 exp (- t * \u03b5) * mgf X \u03bc t :=\nbegin\n  rw [\u2190 neg_neg t, \u2190 mgf_neg, neg_neg, \u2190 neg_mul_neg (-t)],\n  refine eq.trans_le _ (measure_ge_le_exp_mul_mgf (-\u03b5) (neg_nonneg.mpr ht) _),\n  { congr' with \u03c9,\n    simp only [pi.neg_apply, neg_le_neg_iff], },\n  { simp_rw [pi.neg_apply, neg_mul_neg],\n    exact h_int, },\nend\n\n/-- **Chernoff bound** on the upper tail of a real random variable. -/\nlemma measure_ge_le_exp_cgf [is_finite_measure \u03bc] (\u03b5 : \u211d) (ht : 0 \u2264 t)\n  (h_int : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) :\n  (\u03bc {\u03c9 | \u03b5 \u2264 X \u03c9}).to_real \u2264 exp (- t * \u03b5 + cgf X \u03bc t) :=\nbegin\n  refine (measure_ge_le_exp_mul_mgf \u03b5 ht h_int).trans _,\n  rw exp_add,\n  exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le,\nend\n\n/-- **Chernoff bound** on the lower tail of a real random variable. -/\nlemma measure_le_le_exp_cgf [is_finite_measure \u03bc] (\u03b5 : \u211d) (ht : t \u2264 0)\n  (h_int : integrable (\u03bb \u03c9, exp (t * X \u03c9)) \u03bc) :\n  (\u03bc {\u03c9 | X \u03c9 \u2264 \u03b5}).to_real \u2264 exp (- t * \u03b5 + cgf X \u03bc t) :=\nbegin\n  refine (measure_le_le_exp_mul_mgf \u03b5 ht h_int).trans _,\n  rw exp_add,\n  exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le,\nend\n\nend moment_generating_function\n\nend probability_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/probability/moments.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7107827022401384}}
{"text": "/- LoVe Exercise 10: Denotational Semantics -/\n\nimport .love10_denotational_semantics_demo\n\nnamespace LoVe\n\n\n/- Question 1: Monotonicity -/\n\n/- Prove the following two lemmas from the lecture. -/\n\nlemma monotone_comp {\u03b1 \u03b2 : Type} [partial_order \u03b1] (f g : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (\u03bba, f a \u25ef g a) :=\nsorry\n\nlemma monotone_restrict {\u03b1 \u03b2 : Type} [partial_order \u03b1] (f : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2))\n    (p : \u03b2 \u2192 Prop) (hf : monotone f) :\n  monotone (\u03bba, f a \u21c3 p) :=\nsorry\n\n\n/- Question 2: Kleene's Theorem -/\n\n/- We can compute the fixpoint by iteration by taking the union of all finite\niterations of `f`:\n\n    lfp f = \u22c3n, f^^[n] \u2205\n\nwhere\n\n    f^^[n] = f \u2218 \u22ef \u2218 f \u2218 id\n\niterates the function `f` `n` times. However, the above characterization of\n`lfp` only holds for continuous functions, a concept we will introduce below. -/\n\ndef iterate {\u03b1 : Type} (f : \u03b1 \u2192 \u03b1) : \u2115 \u2192 \u03b1 \u2192 \u03b1\n| 0       a := a\n| (n + 1) a := f (iterate n a)\n\nnotation f`^^[`n`]` := iterate f n\n\n/- 2.1. Fill in the missing proofs below. -/\n\ndef Union {\u03b1 : Type} (s : \u2115 \u2192 set \u03b1) : set \u03b1 :=\n{a | \u2203n, a \u2208 s n}\n\nlemma Union_le {\u03b1 : Type} {s : \u2115 \u2192 set \u03b1} (a : set \u03b1) (h : \u2200i, s i \u2264 a) :\n  Union s \u2264 a :=\nsorry\n\n/- A continuous function `f` is a function that commutes with the union of any\nmonotone sequence `s`: -/\n\ndef continuous {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) : Prop :=\n\u2200s : \u2115 \u2192 set \u03b1, monotone s \u2192 f (Union s) = Union (\u03bbn, f (s n))\n\n/- We need to prove that each continuous function is monotone. To achieve this,\nwe will need the following sequence: -/\n\ndef bi_seq {\u03b1 : Type} (a\u2081 a\u2082 : set \u03b1) : \u2115 \u2192 set \u03b1\n| 0       := a\u2081\n| (n + 1) := a\u2082\n\n/- For example, `bi_seq 0 1` is the sequence 0, 1, 1, 1, etc. -/\n\nlemma monotone_bi_seq {\u03b1 : Type} (a\u2081 a\u2082 : set \u03b1) (h : a\u2081 \u2264 a\u2082) :\n  monotone (bi_seq a\u2081 a\u2082)\n| 0       0       _ := le_refl _\n| 0       (n + 1) _ := h\n| (n + 1) (m + 1) _ := le_refl _\n\nlemma Union_bi_seq {\u03b1 : Type} (a\u2081 a\u2082 : set \u03b1) (ha : a\u2081 \u2264 a\u2082) :\n  Union (bi_seq a\u2081 a\u2082) = a\u2082 :=\nsorry\n\nlemma monotone_of_continuous {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1)\n    (hf : continuous f) :\n  monotone f :=\nsorry\n\n/- 2.2. Provide the following proof, using a similar case distinction as for\n`monotone_bi_seq` above. -/\n\nlemma monotone_iterate {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) (hf : monotone f) :\n  monotone (\u03bbn, f^^[n] \u2205)\n:= sorry\n\n/- 2.3. Prove the main theorem. A proof sketch is given below.\n\nWe break the proof into two proofs of inclusion.\n\nCase 1. lfp f \u2264 Union (\u03bbn, f^[n] \u2205): The key is to use the lemma `lfp_le`\ntogether with continuity of `f`.\n\nCase 2. Union (\u03bbn, f^[n] \u2205) \u2264 lfp f: The lemma `Union_le` gives us a natural\nnumber `i`, on which you can perform induction. You will also need the lemma\n`lfp_eq` to unfold one iteration of `lfp f`. -/\n\nlemma lfp_Kleene {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) (hf : continuous f) :\n  complete_lattice.lfp f = Union (\u03bbn, f^^[n] \u2205) :=\nsorry\n\n\n/- Question 3 (**optional**): Regular Expressions -/\n\ninductive regex (\u03b1 : Type) : Type\n| empty     {} : regex\n| nothing   {} : regex\n| atom (a : \u03b1) : regex\n| concat       : regex \u2192 regex \u2192 regex\n| alt          : regex \u2192 regex \u2192 regex\n| star         : regex \u2192 regex\n\n/- 3.1 (**optional**). Define a translation of regular expressions to relations.\nThe idea is that an atom corresponds to a relation, concatenation corresponds to\ncomposition of relations, and alternation is union. -/\n\ndef rel_of_regex {\u03b1 : Type} : regex (set (\u03b1 \u00d7 \u03b1)) \u2192 set (\u03b1 \u00d7 \u03b1)\n| regex.empty          := Id \u03b1\n| _                    := sorry\n\n/- 3.2 (**optional**). Prove the following recursive equation about your\ndefinition. -/\n\nlemma rel_of_regex_star {\u03b1 : Type} (r : regex (set (\u03b1 \u00d7 \u03b1))) :\n  rel_of_regex (regex.star r) =\n  rel_of_regex (regex.alt (regex.concat r (regex.star r)) regex.empty) :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love10_denotational_semantics_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7107688780624161}}
{"text": "def MT {p : Prop} {q : Prop}: (((p -> q) \u2227 \u00acq) -> \u00acp) :=\n  fun h1 : ((p -> q) \u2227 \u00acq) => \n    (fun (h2 : p) => h1.right (h1.left h2))\n\n--\u2200x(F(x) \u2192 G(x)), \u2203x(H(x) \u2227 \u00acG(x)) \u22a2 \u2203x(H(x) \u2227 \u00acF(x))\n\nvariable(F G H : \u2115 \u2192 Prop  )\nvariable(x y : \u2115 )\nvariable(a b : Prop )\n\n\nexample (h1 : \u2200 x : \u2115, F x \u2192 G x ) (h2 : \u2203 x : \u2115, H x \u2227 \u00acG x ) \n  : \u2203 x : \u2115, (H x \u2227 \u00ac F x) :=\nhave \u27e8a,(ha: H a \u2227 \u00acG a)\u27e9 := h2\nhave proofnotfa := MT $ And.intro (h1 a) ha.right\n\u27e8a, And.intro ha.left proofnotfa\u27e9 \n\n\n-- \u2203x(F(x) \u2227 \u00acG(x)), \u2200x(F(x) \u2192 H(x)) \u22a2 \u2203x(H(x) \u2227 \u00acG(x))\n\nexample (h1 : \u2203 x : \u2115, F x \u2227 \u00ac G x) (h2 : \u2200 x : \u2115, F x \u2192 H x)\n  : \u2203 x : \u2115, H x \u2227 \u00acG x :=\n\n  have \u27e8a, (ha: F a \u2227 \u00acG a )\u27e9 := h1\n  have proofha := (h2 a) ha.left\n  \u27e8a, And.intro proofha ha.right\u27e9  \n\n  --\u2200x(F(x) \u2192 G(x)), \u00ac\u2203x(G(x) \u2227 H(x)) \u22a2 \u00ac\u2203x(H(x) \u2227 F(x))\n\n  example (h1 : \u2200x : \u2115, F x \u2192 G x) (h2 : \u00ac\u2203 x : \u2115, G x \u2227 H x)\n    : \u00ac\u2203x : \u2115, H x \u2227 F x :=\n  fun (a1 : \u2203x : \u2115, H x \u2227 F x) => \n    have \u27e8a, (ha: H a \u2227 F a)\u27e9 := a1  \n    h2 \u27e8a, And.intro ((h1 a) ha.right) ha.left \u27e9 \n\n\n-- \u00ac\u2203x(F(x) \u2227 G(x)), \u2203x(H(x) \u2227 F(x)) \u22a2 \u2203x(H(x) \u2227 \u00acG(x))\nexample (h1 : \u00ac\u2203 x : \u2115, F x \u2227 G x) (h2 : \u2203 x : \u2115, H x \u2227 F x)\n  : \u2203 x : \u2115, H x \u2227 \u00acG x :=\nhave \u27e8a, (ha: H a \u2227 F a )\u27e9 := h2\nhave proofnga := \u03bb(ga : G a) => h1 \u27e8a, And.intro ha.right ga\u27e9 \n\u27e8a, And.intro ha.left proofnga\u27e9\n\n-- !(a v b) |- !a ^ !b\nexample (h1 : \u00ac(a \u2228 b)) : \u00aca \u2227 \u00acb :=\n\nhave proofna := \u03bb(a1 : a) => h1 $ Or.intro_left b a1\nhave proofnb := \u03bb(a2 : b) => h1 $ Or.intro_right a a2\n\nAnd.intro proofna proofnb\n\naxiom DNE {p : Prop} : \u00ac\u00acp -> p\n\n-- !(a ^ b) |- !a v !b\nexample(h1 : \u00ac(a \u2227 b)) : \u00aca \u2228 \u00acb :=\nDNE \u03bb(a1 : \u00ac(\u00aca \u2228 \u00acb)) => \n  have proofa := \u03bb(a2 : \u00aca) =>\n    a1 $ Or.intro_left (\u00acb) a2\n  have proofb := \u03bb(a3 : \u00acb) =>\n    a1 $ Or.intro_right (\u00aca) a3\n  h1 $ And.intro (DNE proofa) (DNE proofb)\n\n\n\n\n", "meta": {"author": "cmloura", "repo": "LeanPractice2023", "sha": "6819825e67228bfe5e69aa309f8d2bd37ef48ce3", "save_path": "github-repos/lean/cmloura-LeanPractice2023", "path": "github-repos/lean/cmloura-LeanPractice2023/LeanPractice2023-6819825e67228bfe5e69aa309f8d2bd37ef48ce3/pp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7107688757066982}}
{"text": "/-\nCopyright (c) 2021 Yourong Zang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yourong Zang\n\n! This file was ported from Lean 3 source module geometry.euclidean.angle.unoriented.conformal\n! leanprover-community/mathlib commit 46b633fd842bef9469441c0209906f6dddd2b4f5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Calculus.Conformal.NormedSpace\nimport Mathbin.Geometry.Euclidean.Angle.Unoriented.Basic\n\n/-!\n# Angles and conformal maps\n\nThis file proves that conformal maps preserve angles.\n\n-/\n\n\nnamespace InnerProductGeometry\n\nvariable {E F : Type _}\n\nvariable [NormedAddCommGroup E] [NormedAddCommGroup F]\n\nvariable [InnerProductSpace \u211d E] [InnerProductSpace \u211d F]\n\ntheorem IsConformalMap.preserves_angle {f' : E \u2192L[\u211d] F} (h : IsConformalMap f') (u v : E) :\n    angle (f' u) (f' v) = angle u v :=\n  by\n  obtain \u27e8c, hc, li, rfl\u27e9 := h\n  exact (angle_smul_smul hc _ _).trans (li.angle_map _ _)\n#align inner_product_geometry.is_conformal_map.preserves_angle InnerProductGeometry.IsConformalMap.preserves_angle\n\n/-- If a real differentiable map `f` is conformal at a point `x`,\n    then it preserves the angles at that point. -/\ntheorem ConformalAt.preserves_angle {f : E \u2192 F} {x : E} {f' : E \u2192L[\u211d] F} (h : HasFderivAt f f' x)\n    (H : ConformalAt f x) (u v : E) : angle (f' u) (f' v) = angle u v :=\n  let \u27e8f\u2081, h\u2081, c\u27e9 := H\n  h\u2081.unique h \u25b8 IsConformalMap.preserves_angle c u v\n#align inner_product_geometry.conformal_at.preserves_angle InnerProductGeometry.ConformalAt.preserves_angle\n\nend InnerProductGeometry\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Geometry/Euclidean/Angle/Unoriented/Conformal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7107688711867378}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport geometry.euclidean.angle.sphere\nimport geometry.euclidean.sphere.second_inter\n\n/-!\n# IMO 2019 Q2\n\nIn triangle `ABC`, point `A\u2081` lies on side `BC` and point `B\u2081` lies on side `AC`. Let `P` and\n`Q` be points on segments `AA\u2081` and `BB\u2081`, respectively, such that `PQ` is parallel to `AB`.\nLet `P\u2081` be a point on line `PB\u2081`, such that `B\u2081` lies strictly between `P` and `P\u2081`, and\n`\u2220PP\u2081C = \u2220BAC`. Similarly, let `Q\u2081` be a point on line `QA\u2081`, such that `A\u2081` lies strictly\nbetween `Q` and `Q\u2081`, and `\u2220CQ\u2081Q = \u2220CBA`.\n\nProve that points `P`, `Q`, `P\u2081`, and `Q\u2081` are concyclic.\n\nWe follow Solution 1 from the\n[official solutions](https://www.imo2019.uk/wp-content/uploads/2018/07/solutions-r856.pdf).\nLetting the rays `AA\u2081` and `BB\u2081` intersect the circumcircle of `ABC` at `A\u2082` and `B\u2082`\nrespectively, we show with an angle chase that `P`, `Q`, `A\u2082`, `B\u2082` are concyclic and let `\u03c9` be\nthe circle through those points. We then show that `C`, `Q\u2081`, `A\u2082`, `A\u2081` are concyclic, and\nthen that `Q\u2081` lies on `\u03c9`, and similarly that `P\u2081` lies on `\u03c9`, so the required four points are\nconcyclic.\n\nNote that most of the formal proof is actually proving nondegeneracy conditions needed for that\nangle chase / concyclicity argument, where an informal solution doesn't discuss those conditions\nat all. Also note that (as described in `geometry.euclidean.angle.oriented.basic`) the oriented\nangles used are modulo `2 * \u03c0`, so parts of the angle chase that are only valid for angles modulo\n`\u03c0` (as used in the informal solution) are represented as equalities of twice angles, which we write\nas `(2 : \u2124) \u2022 \u2221 _ _ _ = (2 : \u2124) \u2022 _ _ _`.\n-/\n\n/--\nWe apply the following conventions for formalizing IMO geometry problems. A problem is assumed\nto take place in the plane unless that is clearly not intended, so it is not required to prove\nthat the points are coplanar (whether or not that in fact follows from the other conditions).\nAngles in problem statements are taken to be unoriented. A reference to an angle `\u2220XYZ` is taken\nto imply that `X` and `Z` are not equal to `Y`, since choices of junk values play no role in\ninformal mathematics, and those implications are included as hypotheses for the problem whether\nor not they follow from the other hypotheses. Similar, a reference to `XY` as a line is taken to\nimply that `X` does not equal `Y` and that is included as a hypothesis, and a reference to `XY`\nbeing parallel to something is considered a reference to it as a line. However, such an implicit\nhypothesis about two points being different is included only once for any given two points (even\nif it follows from more than one reference to a line or an angle), if `X \u2260 Y` is included then\n`Y \u2260 X` is not included separately, and such hypotheses are not included in the case where there\nis also a reference in the problem to a triangle including those two points, or to strict\nbetweenness of three points including those two. If betweenness is stated, it is taken to be\nstrict betweenness. However, segments and sides are taken to include their endpoints (unless\nthis makes a problem false), although those degenerate cases might not necessarily have been\nconsidered when the problem was formulated and contestants might not have been expected to deal\nwith them. A reference to a point being on a side or a segment is expressed directly with `wbtw`\nrather than more literally with `affine_segment`.\n-/\nlibrary_note \"IMO geometry formalization conventions\"\n\nnoncomputable theory\n\nopen affine affine.simplex euclidean_geometry finite_dimensional\nopen_locale affine euclidean_geometry real\n\nlocal attribute [instance] fact_finite_dimensional_of_finrank_eq_succ\n\nvariables (V : Type*) (Pt : Type*)\nvariables [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space Pt]\nvariables [normed_add_torsor V Pt] [hd2 : fact (finrank \u211d V = 2)]\ninclude hd2\n\n/-- A configuration satisfying the conditions of the problem. We define this structure to avoid\npassing many hypotheses around as we build up information about the configuration; the final\nresult for a statement of the problem not using this structure is then deduced from one in terms\nof this structure. -/\n@[nolint has_nonempty_instance]\nstructure imo2019q2_cfg :=\n(A B C A\u2081 B\u2081 P Q P\u2081 Q\u2081 : Pt)\n(affine_independent_ABC : affine_independent \u211d ![A, B, C])\n(wbtw_B_A\u2081_C : wbtw \u211d B A\u2081 C)\n(wbtw_A_B\u2081_C : wbtw \u211d A B\u2081 C)\n(wbtw_A_P_A\u2081 : wbtw \u211d A P A\u2081)\n(wbtw_B_Q_B\u2081 : wbtw \u211d B Q B\u2081)\n(PQ_parallel_AB : line[\u211d, P, Q] \u2225 line[\u211d, A, B])\n-- A hypothesis implicit in the named line.\n(P_ne_Q : P \u2260 Q)\n(sbtw_P_B\u2081_P\u2081 : sbtw \u211d P B\u2081 P\u2081)\n(angle_PP\u2081C_eq_angle_BAC : \u2220 P P\u2081 C = \u2220 B A C)\n-- A hypothesis implicit in the first named angle.\n(C_ne_P\u2081 : C \u2260 P\u2081)\n(sbtw_Q_A\u2081_Q\u2081 : sbtw \u211d Q A\u2081 Q\u2081)\n(angle_CQ\u2081Q_eq_angle_CBA : \u2220 C Q\u2081 Q = \u2220 C B A)\n-- A hypothesis implicit in the first named angle.\n(C_ne_Q\u2081 : C \u2260 Q\u2081)\n\n/-- A default choice of orientation, for lemmas that need to pick one. -/\ndef some_orientation : module.oriented \u211d V (fin 2) :=\n\u27e8basis.orientation (fin_basis_of_finrank_eq _ _ hd2.out)\u27e9\n\nvariables {V Pt}\n\nnamespace imo2019q2_cfg\n\nvariables (cfg : imo2019q2_cfg V Pt)\n\n/-- The configuration has symmetry, allowing results proved for one point to be applied for\nanother (where the informal solution says \"similarly\"). -/\ndef symm : imo2019q2_cfg V Pt :=\n{ A := cfg.B,\n  B := cfg.A,\n  C := cfg.C,\n  A\u2081 := cfg.B\u2081,\n  B\u2081 := cfg.A\u2081,\n  P := cfg.Q,\n  Q := cfg.P,\n  P\u2081 := cfg.Q\u2081,\n  Q\u2081 := cfg.P\u2081,\n  affine_independent_ABC := begin\n    rw \u2190affine_independent_equiv (equiv.swap (0 : fin 3) 1),\n    convert cfg.affine_independent_ABC using 1,\n    ext x,\n    fin_cases x;\n      refl\n  end,\n  wbtw_B_A\u2081_C := cfg.wbtw_A_B\u2081_C,\n  wbtw_A_B\u2081_C := cfg.wbtw_B_A\u2081_C,\n  wbtw_A_P_A\u2081 := cfg.wbtw_B_Q_B\u2081,\n  wbtw_B_Q_B\u2081 := cfg.wbtw_A_P_A\u2081,\n  PQ_parallel_AB := set.pair_comm cfg.P cfg.Q \u25b8 set.pair_comm cfg.A cfg.B \u25b8 cfg.PQ_parallel_AB,\n  P_ne_Q := cfg.P_ne_Q.symm,\n  sbtw_P_B\u2081_P\u2081 := cfg.sbtw_Q_A\u2081_Q\u2081,\n  angle_PP\u2081C_eq_angle_BAC :=\n    angle_comm cfg.C cfg.Q\u2081 cfg.Q \u25b8 angle_comm cfg.C cfg.B cfg.A \u25b8 cfg.angle_CQ\u2081Q_eq_angle_CBA,\n  C_ne_P\u2081 := cfg.C_ne_Q\u2081,\n  sbtw_Q_A\u2081_Q\u2081 := cfg.sbtw_P_B\u2081_P\u2081,\n  angle_CQ\u2081Q_eq_angle_CBA :=\n    angle_comm cfg.P cfg.P\u2081 cfg.C \u25b8 angle_comm cfg.B cfg.A cfg.C \u25b8 cfg.angle_PP\u2081C_eq_angle_BAC,\n  C_ne_Q\u2081 := cfg.C_ne_P\u2081 }\n\n/-! ### Configuration properties that are obvious from the diagram, and construction of the\npoints `A\u2082` and `B\u2082` -/\n\nlemma A_ne_B : cfg.A \u2260 cfg.B := cfg.affine_independent_ABC.injective.ne\n  (dec_trivial : (0 : fin 3) \u2260 1)\n\nlemma A_ne_C : cfg.A \u2260 cfg.C := cfg.affine_independent_ABC.injective.ne\n  (dec_trivial : (0 : fin 3) \u2260 2)\n\nlemma B_ne_C : cfg.B \u2260 cfg.C := cfg.affine_independent_ABC.injective.ne\n  (dec_trivial : (1 : fin 3) \u2260 2)\n\nlemma not_collinear_ABC : \u00accollinear \u211d ({cfg.A, cfg.B, cfg.C} : set Pt) :=\naffine_independent_iff_not_collinear_set.1 cfg.affine_independent_ABC\n\n/-- `ABC` as a `triangle`. -/\ndef triangle_ABC : triangle \u211d Pt := \u27e8_, cfg.affine_independent_ABC\u27e9\n\nlemma A_mem_circumsphere : cfg.A \u2208 cfg.triangle_ABC.circumsphere :=\ncfg.triangle_ABC.mem_circumsphere 0\n\nlemma B_mem_circumsphere : cfg.B \u2208 cfg.triangle_ABC.circumsphere :=\ncfg.triangle_ABC.mem_circumsphere 1\n\nlemma C_mem_circumsphere : cfg.C \u2208 cfg.triangle_ABC.circumsphere :=\ncfg.triangle_ABC.mem_circumsphere 2\n\nlemma symm_triangle_ABC : cfg.symm.triangle_ABC = cfg.triangle_ABC.reindex (equiv.swap 0 1) :=\nby { ext i, fin_cases i; refl }\n\nlemma symm_triangle_ABC_circumsphere :\n  cfg.symm.triangle_ABC.circumsphere = cfg.triangle_ABC.circumsphere :=\nby rw [symm_triangle_ABC, affine.simplex.circumsphere_reindex]\n\n/-- `A\u2082` is the second point of intersection of the ray `AA\u2081` with the circumcircle of `ABC`. -/\ndef A\u2082 : Pt := cfg.triangle_ABC.circumsphere.second_inter cfg.A (cfg.A\u2081 -\u1d65 cfg.A)\n\n/-- `B\u2082` is the second point of intersection of the ray `BB\u2081` with the circumcircle of `ABC`. -/\ndef B\u2082 : Pt := cfg.triangle_ABC.circumsphere.second_inter cfg.B (cfg.B\u2081 -\u1d65 cfg.B)\n\nlemma A\u2082_mem_circumsphere : cfg.A\u2082 \u2208 cfg.triangle_ABC.circumsphere :=\n(sphere.second_inter_mem _).2 cfg.A_mem_circumsphere\n\nlemma B\u2082_mem_circumsphere : cfg.B\u2082 \u2208 cfg.triangle_ABC.circumsphere :=\n(sphere.second_inter_mem _).2 cfg.B_mem_circumsphere\n\nlemma symm_A\u2082 : cfg.symm.A\u2082 = cfg.B\u2082 :=\nby { simp_rw [A\u2082, B\u2082, symm_triangle_ABC_circumsphere], refl }\n\nlemma QP_parallel_BA : line[\u211d, cfg.Q, cfg.P] \u2225 line[\u211d, cfg.B, cfg.A] :=\nby { rw [set.pair_comm cfg.Q, set.pair_comm cfg.B], exact cfg.PQ_parallel_AB }\n\nlemma A_ne_A\u2081 : cfg.A \u2260 cfg.A\u2081 :=\nbegin\n  intro h,\n  have h' := cfg.not_collinear_ABC,\n  rw [h, set.insert_comm] at h',\n  exact h' cfg.wbtw_B_A\u2081_C.collinear\nend\n\nlemma collinear_PAA\u2081A\u2082 : collinear \u211d ({cfg.P, cfg.A, cfg.A\u2081, cfg.A\u2082} : set Pt) :=\nbegin\n  rw [A\u2082,\n      (cfg.triangle_ABC.circumsphere.second_inter_collinear cfg.A cfg.A\u2081).collinear_insert_iff_of_ne\n        (set.mem_insert _ _) (set.mem_insert_of_mem _ (set.mem_insert _ _)) cfg.A_ne_A\u2081,\n      set.insert_comm],\n  exact cfg.wbtw_A_P_A\u2081.collinear\nend\n\nlemma A\u2081_ne_C : cfg.A\u2081 \u2260 cfg.C :=\nbegin\n  intro h,\n  have hsbtw := cfg.sbtw_Q_A\u2081_Q\u2081,\n  rw h at hsbtw,\n  have ha := hsbtw.angle\u2082\u2083\u2081_eq_zero,\n  rw [angle_CQ\u2081Q_eq_angle_CBA, angle_comm] at ha,\n  exact (angle_ne_zero_of_not_collinear cfg.not_collinear_ABC) ha\nend\n\nlemma B\u2081_ne_C : cfg.B\u2081 \u2260 cfg.C := cfg.symm.A\u2081_ne_C\n\nlemma Q_not_mem_CB : cfg.Q \u2209 line[\u211d, cfg.C, cfg.B] :=\nbegin\n  intro hQ,\n  have hQA\u2081 : line[\u211d, cfg.Q, cfg.A\u2081] \u2264 line[\u211d, cfg.C, cfg.B] :=\n    affine_span_pair_le_of_mem_of_mem hQ cfg.wbtw_B_A\u2081_C.symm.mem_affine_span,\n  have hQ\u2081 : cfg.Q\u2081 \u2208 line[\u211d, cfg.C, cfg.B],\n  { rw affine_subspace.le_def' at hQA\u2081,\n    exact hQA\u2081 _ cfg.sbtw_Q_A\u2081_Q\u2081.right_mem_affine_span },\n  have hc : collinear \u211d ({cfg.C, cfg.Q\u2081, cfg.Q} : set Pt),\n  { have hc' : collinear \u211d ({cfg.B, cfg.C, cfg.Q\u2081, cfg.Q} : set Pt),\n    { rw [set.insert_comm cfg.B, set.insert_comm cfg.B, set.pair_comm, set.insert_comm cfg.C,\n          set.insert_comm cfg.C],\n      exact collinear_insert_insert_of_mem_affine_span_pair hQ\u2081 hQ },\n    exact hc'.subset (set.subset_insert _ _) },\n  rw [collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi, cfg.angle_CQ\u2081Q_eq_angle_CBA,\n      or_iff_right cfg.C_ne_Q\u2081, or_iff_right cfg.sbtw_Q_A\u2081_Q\u2081.left_ne_right, angle_comm] at hc,\n  exact cfg.not_collinear_ABC (hc.elim collinear_of_angle_eq_zero collinear_of_angle_eq_pi)\nend\n\nlemma Q_ne_B : cfg.Q \u2260 cfg.B :=\nbegin\n  intro h,\n  have h' := cfg.Q_not_mem_CB,\n  rw h at h',\n  exact h' (right_mem_affine_span_pair _ _ _)\nend\n\nlemma s_opp_side_CB_Q_Q\u2081 : line[\u211d, cfg.C, cfg.B].s_opp_side cfg.Q cfg.Q\u2081 :=\ncfg.sbtw_Q_A\u2081_Q\u2081.s_opp_side_of_not_mem_of_mem cfg.Q_not_mem_CB cfg.wbtw_B_A\u2081_C.symm.mem_affine_span\n\n/-! ### Relate the orientations of different angles in the configuration -/\n\nsection oriented\n\nvariables [module.oriented \u211d V (fin 2)]\n\nlemma oangle_CQ\u2081Q_sign_eq_oangle_CBA_sign :\n  (\u2221 cfg.C cfg.Q\u2081 cfg.Q).sign = (\u2221 cfg.C cfg.B cfg.A).sign :=\nby rw [\u2190cfg.sbtw_Q_A\u2081_Q\u2081.symm.oangle_eq_right,\n       cfg.s_opp_side_CB_Q_Q\u2081.oangle_sign_eq_neg (left_mem_affine_span_pair \u211d cfg.C cfg.B)\n        cfg.wbtw_B_A\u2081_C.symm.mem_affine_span, \u2190real.angle.sign_neg, \u2190oangle_rev,\n      cfg.wbtw_B_A\u2081_C.oangle_sign_eq_of_ne_right cfg.Q cfg.A\u2081_ne_C, oangle_rotate_sign,\n      cfg.wbtw_B_Q_B\u2081.oangle_eq_right cfg.Q_ne_B,\n      cfg.wbtw_A_B\u2081_C.symm.oangle_sign_eq_of_ne_left cfg.B cfg.B\u2081_ne_C.symm]\n\nlemma oangle_CQ\u2081Q_eq_oangle_CBA : \u2221 cfg.C cfg.Q\u2081 cfg.Q = \u2221 cfg.C cfg.B cfg.A :=\noangle_eq_of_angle_eq_of_sign_eq cfg.angle_CQ\u2081Q_eq_angle_CBA cfg.oangle_CQ\u2081Q_sign_eq_oangle_CBA_sign\n\nend oriented\n\n/-! ### More obvious configuration properties -/\n\nlemma A\u2081_ne_B : cfg.A\u2081 \u2260 cfg.B :=\nbegin\n  intro h,\n  have hwbtw := cfg.wbtw_A_P_A\u2081,\n  rw h at hwbtw,\n  have hPQ : line[\u211d, cfg.P, cfg.Q] = line[\u211d, cfg.A, cfg.B],\n  { rw affine_subspace.eq_iff_direction_eq_of_mem (left_mem_affine_span_pair _ _ _)\n         hwbtw.mem_affine_span,\n    exact cfg.PQ_parallel_AB.direction_eq },\n  haveI := some_orientation V,\n  have haQ : (2 : \u2124) \u2022 \u2221 cfg.C cfg.B cfg.Q = (2 : \u2124) \u2022 \u2221 cfg.C cfg.B cfg.A,\n  { rw [collinear.two_zsmul_oangle_eq_right _ cfg.A_ne_B cfg.Q_ne_B],\n    rw [set.pair_comm, set.insert_comm],\n    refine collinear_insert_of_mem_affine_span_pair _,\n    rw \u2190hPQ,\n    exact right_mem_affine_span_pair _ _ _ },\n  have ha : (2 : \u2124) \u2022 \u2221 cfg.C cfg.B cfg.Q = (2 : \u2124) \u2022 \u2221 cfg.C cfg.Q\u2081 cfg.Q,\n  { rw [oangle_CQ\u2081Q_eq_oangle_CBA, haQ] },\n  have hn : \u00accollinear \u211d ({cfg.C, cfg.B, cfg.Q} : set Pt),\n  { rw [collinear_iff_of_two_zsmul_oangle_eq haQ, set.pair_comm, set.insert_comm, set.pair_comm],\n    exact cfg.not_collinear_ABC },\n  have hc := cospherical_of_two_zsmul_oangle_eq_of_not_collinear ha hn,\n  have hBQ\u2081 : cfg.B \u2260 cfg.Q\u2081, { rw [\u2190h], exact cfg.sbtw_Q_A\u2081_Q\u2081.ne_right },\n  have hQQ\u2081 : cfg.Q \u2260 cfg.Q\u2081 := cfg.sbtw_Q_A\u2081_Q\u2081.left_ne_right,\n  have hBQ\u2081Q : affine_independent \u211d ![cfg.B, cfg.Q\u2081, cfg.Q] :=\n    hc.affine_independent_of_mem_of_ne (set.mem_insert_of_mem _ (set.mem_insert _ _))\n      (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert _ _)))\n      (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert_of_mem _\n        (set.mem_singleton _)))) hBQ\u2081 cfg.Q_ne_B.symm hQQ\u2081.symm,\n  rw affine_independent_iff_not_collinear_set at hBQ\u2081Q,\n  refine hBQ\u2081Q _,\n  rw [\u2190h, set.pair_comm, set.insert_comm],\n  exact cfg.sbtw_Q_A\u2081_Q\u2081.wbtw.collinear\nend\n\nlemma sbtw_B_A\u2081_C : sbtw \u211d cfg.B cfg.A\u2081 cfg.C := \u27e8cfg.wbtw_B_A\u2081_C, cfg.A\u2081_ne_B, cfg.A\u2081_ne_C\u27e9\n\nlemma sbtw_A_B\u2081_C : sbtw \u211d cfg.A cfg.B\u2081 cfg.C := cfg.symm.sbtw_B_A\u2081_C\n\nlemma sbtw_A_A\u2081_A\u2082 : sbtw \u211d cfg.A cfg.A\u2081 cfg.A\u2082 :=\nbegin\n  refine sphere.sbtw_second_inter cfg.A_mem_circumsphere _,\n  convert cfg.sbtw_B_A\u2081_C.dist_lt_max_dist _,\n  change _ = max (dist (cfg.triangle_ABC.points 1) _) (dist (cfg.triangle_ABC.points 2) _),\n  simp_rw [circumsphere_center, circumsphere_radius, dist_circumcenter_eq_circumradius, max_self]\nend\n\nlemma sbtw_B_B\u2081_B\u2082 : sbtw \u211d cfg.B cfg.B\u2081 cfg.B\u2082 :=\nby { rw \u2190cfg.symm_A\u2082, exact cfg.symm.sbtw_A_A\u2081_A\u2082 }\n\nlemma A\u2082_ne_A : cfg.A\u2082 \u2260 cfg.A := cfg.sbtw_A_A\u2081_A\u2082.left_ne_right.symm\n\nlemma A\u2082_ne_P : cfg.A\u2082 \u2260 cfg.P := (cfg.sbtw_A_A\u2081_A\u2082.trans_wbtw_left_ne cfg.wbtw_A_P_A\u2081).symm\n\nlemma A\u2082_ne_B : cfg.A\u2082 \u2260 cfg.B :=\nbegin\n  intro h,\n  have h\u2081 := cfg.sbtw_A_A\u2081_A\u2082,\n  rw h at h\u2081,\n  refine cfg.not_collinear_ABC _,\n  have hc : collinear \u211d ({cfg.A, cfg.C, cfg.B, cfg.A\u2081} : set Pt) :=\n    collinear_insert_insert_of_mem_affine_span_pair h\u2081.left_mem_affine_span\n      cfg.sbtw_B_A\u2081_C.right_mem_affine_span,\n  refine hc.subset _,\n  rw [set.pair_comm _ cfg.A\u2081, set.insert_comm _ cfg.A\u2081, set.insert_comm _ cfg.A\u2081, set.pair_comm],\n  exact set.subset_insert _ _\nend\n\nlemma A\u2082_ne_C : cfg.A\u2082 \u2260 cfg.C :=\nbegin\n  intro h,\n  have h\u2081 := cfg.sbtw_A_A\u2081_A\u2082,\n  rw h at h\u2081,\n  refine cfg.not_collinear_ABC _,\n  have hc : collinear \u211d ({cfg.A, cfg.B, cfg.C, cfg.A\u2081} : set Pt) :=\n    collinear_insert_insert_of_mem_affine_span_pair h\u2081.left_mem_affine_span\n      cfg.sbtw_B_A\u2081_C.left_mem_affine_span,\n  refine hc.subset (set.insert_subset_insert (set.insert_subset_insert _)),\n  rw set.singleton_subset_iff,\n  exact set.mem_insert _ _\nend\n\nlemma B\u2082_ne_B : cfg.B\u2082 \u2260 cfg.B := by { rw \u2190symm_A\u2082, exact cfg.symm.A\u2082_ne_A }\n\nlemma B\u2082_ne_Q : cfg.B\u2082 \u2260 cfg.Q := by { rw \u2190symm_A\u2082, exact cfg.symm.A\u2082_ne_P }\n\nlemma B\u2082_ne_A\u2082 : cfg.B\u2082 \u2260 cfg.A\u2082 :=\nbegin\n  intro h,\n  have hA : sbtw \u211d (cfg.triangle_ABC.points 1) cfg.A\u2081 (cfg.triangle_ABC.points 2) :=\n    cfg.sbtw_B_A\u2081_C,\n  have hB : sbtw \u211d (cfg.triangle_ABC.points 0) cfg.B\u2081 (cfg.triangle_ABC.points 2) :=\n    cfg.sbtw_A_B\u2081_C,\n  have hA' : cfg.A\u2082 \u2208 line[\u211d, cfg.triangle_ABC.points 0, cfg.A\u2081] :=\n    sphere.second_inter_vsub_mem_affine_span _ _ _,\n  have hB' : cfg.A\u2082 \u2208 line[\u211d, cfg.triangle_ABC.points 1, cfg.B\u2081],\n  { rw \u2190h, exact sphere.second_inter_vsub_mem_affine_span _ _ _ },\n  exact (sbtw_of_sbtw_of_sbtw_of_mem_affine_span_pair dec_trivial hA hB hA' hB').symm.not_rotate\n    cfg.sbtw_A_A\u2081_A\u2082.wbtw\nend\n\nlemma wbtw_B_Q_B\u2082 : wbtw \u211d cfg.B cfg.Q cfg.B\u2082 := cfg.sbtw_B_B\u2081_B\u2082.wbtw.trans_left cfg.wbtw_B_Q_B\u2081\n\n/-! ### The first equality in the first angle chase in the solution -/\n\nsection oriented\n\nvariables [module.oriented \u211d V (fin 2)]\n\nlemma two_zsmul_oangle_QPA\u2082_eq_two_zsmul_oangle_BAA\u2082 :\n  (2 : \u2124) \u2022 \u2221 cfg.Q cfg.P cfg.A\u2082 = (2 : \u2124) \u2022 \u2221 cfg.B cfg.A cfg.A\u2082 :=\nbegin\n  refine two_zsmul_oangle_of_parallel cfg.QP_parallel_BA _,\n  convert affine_subspace.parallel.refl _ using 1,\n  rw [cfg.collinear_PAA\u2081A\u2082.affine_span_eq_of_ne\n        (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert_of_mem _\n          (set.mem_singleton _))))\n        (set.mem_insert_of_mem _ (set.mem_insert _ _)) cfg.A\u2082_ne_A,\n      cfg.collinear_PAA\u2081A\u2082.affine_span_eq_of_ne\n        (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert_of_mem _\n          (set.mem_singleton _))))\n        (set.mem_insert _ _) cfg.A\u2082_ne_P]\nend\n\nend oriented\n\n/-! ### More obvious configuration properties -/\n\nlemma not_collinear_QPA\u2082 : \u00ac collinear \u211d ({cfg.Q, cfg.P, cfg.A\u2082} : set Pt) :=\nbegin\n  haveI := some_orientation V,\n  rw [collinear_iff_of_two_zsmul_oangle_eq cfg.two_zsmul_oangle_QPA\u2082_eq_two_zsmul_oangle_BAA\u2082,\n      \u2190affine_independent_iff_not_collinear_set],\n  have h : cospherical ({cfg.B, cfg.A, cfg.A\u2082} : set Pt),\n  { refine cfg.triangle_ABC.circumsphere.cospherical.subset _,\n    simp [set.insert_subset, cfg.A_mem_circumsphere, cfg.B_mem_circumsphere,\n          cfg.A\u2082_mem_circumsphere] },\n  exact h.affine_independent_of_ne cfg.A_ne_B.symm cfg.A\u2082_ne_B.symm cfg.A\u2082_ne_A.symm\nend\n\nlemma Q\u2081_ne_A\u2082 : cfg.Q\u2081 \u2260 cfg.A\u2082 :=\nbegin\n  intro h,\n  have h\u2081 := cfg.sbtw_Q_A\u2081_Q\u2081,\n  rw h at h\u2081,\n  refine cfg.not_collinear_QPA\u2082 _,\n  have hA\u2082 := cfg.sbtw_A_A\u2081_A\u2082.right_mem_affine_span,\n  have hA\u2082A\u2081 : line[\u211d, cfg.A\u2082, cfg.A\u2081] \u2264 line[\u211d, cfg.A, cfg.A\u2081] :=\n    affine_span_pair_le_of_left_mem hA\u2082,\n  have hQ : cfg.Q \u2208 line[\u211d, cfg.A, cfg.A\u2081],\n  { rw affine_subspace.le_def' at hA\u2082A\u2081,\n    exact hA\u2082A\u2081 _ h\u2081.left_mem_affine_span },\n  exact collinear_triple_of_mem_affine_span_pair hQ cfg.wbtw_A_P_A\u2081.mem_affine_span hA\u2082\nend\n\nlemma affine_independent_QPA\u2082 : affine_independent \u211d ![cfg.Q, cfg.P, cfg.A\u2082] :=\naffine_independent_iff_not_collinear_set.2 cfg.not_collinear_QPA\u2082\n\nlemma affine_independent_PQB\u2082 : affine_independent \u211d ![cfg.P, cfg.Q, cfg.B\u2082] :=\nby { rw \u2190symm_A\u2082, exact cfg.symm.affine_independent_QPA\u2082 }\n\n/-- `QPA\u2082` as a `triangle`. -/\ndef triangle_QPA\u2082 : triangle \u211d Pt := \u27e8_, cfg.affine_independent_QPA\u2082\u27e9\n\n/-- `PQB\u2082` as a `triangle`. -/\ndef triangle_PQB\u2082 : triangle \u211d Pt := \u27e8_, cfg.affine_independent_PQB\u2082\u27e9\n\nlemma symm_triangle_QPA\u2082 : cfg.symm.triangle_QPA\u2082 = cfg.triangle_PQB\u2082 :=\nby { simp_rw [triangle_PQB\u2082, \u2190symm_A\u2082], ext i, fin_cases i; refl }\n\n/-- `\u03c9` is the circle containing `Q`, `P` and `A\u2082`, which will be shown also to contain `B\u2082`,\n`P\u2081` and `Q\u2081`. -/\ndef \u03c9 : sphere Pt := cfg.triangle_QPA\u2082.circumsphere\n\nlemma P_mem_\u03c9 : cfg.P \u2208 cfg.\u03c9 := cfg.triangle_QPA\u2082.mem_circumsphere 1\n\nlemma Q_mem_\u03c9 : cfg.Q \u2208 cfg.\u03c9 := cfg.triangle_QPA\u2082.mem_circumsphere 0\n\n/-! ### The rest of the first angle chase in the solution -/\n\nsection oriented\n\nvariables [module.oriented \u211d V (fin 2)]\n\nlemma two_zsmul_oangle_QPA\u2082_eq_two_zsmul_oangle_QB\u2082A\u2082 :\n  (2 : \u2124) \u2022 \u2221 cfg.Q cfg.P cfg.A\u2082 = (2 : \u2124) \u2022 \u2221 cfg.Q cfg.B\u2082 cfg.A\u2082 :=\ncalc (2 : \u2124) \u2022 \u2221 cfg.Q cfg.P cfg.A\u2082 = (2 : \u2124) \u2022 \u2221 cfg.B cfg.A cfg.A\u2082 :\n    cfg.two_zsmul_oangle_QPA\u2082_eq_two_zsmul_oangle_BAA\u2082\n  ... = (2 : \u2124) \u2022 \u2221 cfg.B cfg.B\u2082 cfg.A\u2082 :\n    sphere.two_zsmul_oangle_eq cfg.B_mem_circumsphere cfg.A_mem_circumsphere\n      cfg.B\u2082_mem_circumsphere cfg.A\u2082_mem_circumsphere cfg.A_ne_B cfg.A\u2082_ne_A.symm\n      cfg.B\u2082_ne_B cfg.B\u2082_ne_A\u2082\n  ... = (2 : \u2124) \u2022 \u2221 cfg.Q cfg.B\u2082 cfg.A\u2082 :\n    by rw cfg.wbtw_B_Q_B\u2082.symm.oangle_eq_left cfg.B\u2082_ne_Q.symm\n\nend oriented\n\n/-! ### Conclusions from that first angle chase -/\n\nlemma cospherical_QPB\u2082A\u2082 : cospherical ({cfg.Q, cfg.P, cfg.B\u2082, cfg.A\u2082} : set Pt) :=\nbegin\n  haveI := some_orientation V,\n  exact cospherical_of_two_zsmul_oangle_eq_of_not_collinear\n    cfg.two_zsmul_oangle_QPA\u2082_eq_two_zsmul_oangle_QB\u2082A\u2082 cfg.not_collinear_QPA\u2082\nend\n\nlemma symm_\u03c9_eq_triangle_PQB\u2082_circumsphere : cfg.symm.\u03c9 = cfg.triangle_PQB\u2082.circumsphere :=\nby rw [\u03c9, symm_triangle_QPA\u2082]\n\nlemma symm_\u03c9 : cfg.symm.\u03c9 = cfg.\u03c9 :=\nbegin\n  rw [symm_\u03c9_eq_triangle_PQB\u2082_circumsphere, \u03c9],\n  refine circumsphere_eq_of_cospherical hd2.out cfg.cospherical_QPB\u2082A\u2082 _ _,\n  { simp only [triangle_PQB\u2082, matrix.range_cons, matrix.range_empty, set.singleton_union,\n               insert_emptyc_eq],\n    rw set.insert_comm,\n    refine set.insert_subset_insert (set.insert_subset_insert _),\n    simp },\n  { simp only [triangle_QPA\u2082, matrix.range_cons, matrix.range_empty, set.singleton_union,\n               insert_emptyc_eq],\n    refine set.insert_subset_insert (set.insert_subset_insert _),\n    simp }\nend\n\n/-! ### The second angle chase in the solution -/\n\nsection oriented\n\nvariables [module.oriented \u211d V (fin 2)]\n\nlemma two_zsmul_oangle_CA\u2082A\u2081_eq_two_zsmul_oangle_CBA :\n  (2 : \u2124) \u2022 \u2221 cfg.C cfg.A\u2082 cfg.A\u2081 = (2 : \u2124) \u2022 \u2221 cfg.C cfg.B cfg.A :=\ncalc (2 : \u2124) \u2022 \u2221 cfg.C cfg.A\u2082 cfg.A\u2081 = (2 : \u2124) \u2022 \u2221 cfg.C cfg.A\u2082 cfg.A :\n    by rw cfg.sbtw_A_A\u2081_A\u2082.symm.oangle_eq_right\n  ... = (2 : \u2124) \u2022 \u2221 cfg.C cfg.B cfg.A :\n    sphere.two_zsmul_oangle_eq cfg.C_mem_circumsphere cfg.A\u2082_mem_circumsphere\n      cfg.B_mem_circumsphere cfg.A_mem_circumsphere cfg.A\u2082_ne_C cfg.A\u2082_ne_A cfg.B_ne_C\n      cfg.A_ne_B.symm\n\nlemma two_zsmul_oangle_CA\u2082A\u2081_eq_two_zsmul_oangle_CQ\u2081A\u2081 :\n  (2 : \u2124) \u2022 \u2221 cfg.C cfg.A\u2082 cfg.A\u2081 = (2 : \u2124) \u2022 \u2221 cfg.C cfg.Q\u2081 cfg.A\u2081 :=\ncalc (2 : \u2124) \u2022 \u2221 cfg.C cfg.A\u2082 cfg.A\u2081 = (2 : \u2124) \u2022 \u2221 cfg.C cfg.B cfg.A :\n    cfg.two_zsmul_oangle_CA\u2082A\u2081_eq_two_zsmul_oangle_CBA\n  ... = (2 : \u2124) \u2022 \u2221 cfg.C cfg.Q\u2081 cfg.Q : by rw oangle_CQ\u2081Q_eq_oangle_CBA\n  ... = (2 : \u2124) \u2022 \u2221 cfg.C cfg.Q\u2081 cfg.A\u2081 : by rw cfg.sbtw_Q_A\u2081_Q\u2081.symm.oangle_eq_right\n\nend oriented\n\n/-! ### Conclusions from that second angle chase -/\n\nlemma not_collinear_CA\u2082A\u2081 : \u00accollinear \u211d ({cfg.C, cfg.A\u2082, cfg.A\u2081} : set Pt) :=\nbegin\n  haveI := some_orientation V,\n  rw [collinear_iff_of_two_zsmul_oangle_eq cfg.two_zsmul_oangle_CA\u2082A\u2081_eq_two_zsmul_oangle_CBA,\n      set.pair_comm, set.insert_comm, set.pair_comm],\n  exact cfg.not_collinear_ABC\nend\n\nlemma cospherical_A\u2081Q\u2081CA\u2082 : cospherical ({cfg.A\u2081, cfg.Q\u2081, cfg.C, cfg.A\u2082} : set Pt) :=\nbegin\n  haveI := some_orientation V,\n  rw [set.insert_comm cfg.Q\u2081, set.insert_comm cfg.A\u2081, set.pair_comm, set.insert_comm cfg.A\u2081,\n      set.pair_comm],\n  exact cospherical_of_two_zsmul_oangle_eq_of_not_collinear\n    cfg.two_zsmul_oangle_CA\u2082A\u2081_eq_two_zsmul_oangle_CQ\u2081A\u2081 cfg.not_collinear_CA\u2082A\u2081\nend\n\n/-! ### The third angle chase in the solution -/\n\nsection oriented\n\nvariables [module.oriented \u211d V (fin 2)]\n\nlemma two_zsmul_oangle_QQ\u2081A\u2082_eq_two_zsmul_oangle_QPA\u2082 :\n  (2 : \u2124) \u2022 \u2221 cfg.Q cfg.Q\u2081 cfg.A\u2082 = (2 : \u2124) \u2022 \u2221 cfg.Q cfg.P cfg.A\u2082 :=\ncalc (2 : \u2124) \u2022 \u2221 cfg.Q cfg.Q\u2081 cfg.A\u2082 = (2 : \u2124) \u2022 \u2221 cfg.A\u2081 cfg.Q\u2081 cfg.A\u2082 :\n    by rw cfg.sbtw_Q_A\u2081_Q\u2081.symm.oangle_eq_left\n  ... = (2 : \u2124) \u2022 \u2221 cfg.A\u2081 cfg.C cfg.A\u2082 :\n    cfg.cospherical_A\u2081Q\u2081CA\u2082.two_zsmul_oangle_eq cfg.sbtw_Q_A\u2081_Q\u2081.right_ne cfg.Q\u2081_ne_A\u2082\n      cfg.A\u2081_ne_C.symm cfg.A\u2082_ne_C.symm\n  ... = (2 : \u2124) \u2022 \u2221 cfg.B cfg.C cfg.A\u2082 : by rw cfg.sbtw_B_A\u2081_C.symm.oangle_eq_left\n  ... = (2 : \u2124) \u2022 \u2221 cfg.B cfg.A cfg.A\u2082 :\n    sphere.two_zsmul_oangle_eq cfg.B_mem_circumsphere cfg.C_mem_circumsphere\n      cfg.A_mem_circumsphere cfg.A\u2082_mem_circumsphere cfg.B_ne_C.symm cfg.A\u2082_ne_C.symm cfg.A_ne_B\n      cfg.A\u2082_ne_A.symm\n  ... = (2 : \u2124) \u2022 \u2221 cfg.Q cfg.P cfg.A\u2082 : cfg.two_zsmul_oangle_QPA\u2082_eq_two_zsmul_oangle_BAA\u2082.symm\n\nend oriented\n\n/-! ### Conclusions from that third angle chase -/\n\nlemma Q\u2081_mem_\u03c9 : cfg.Q\u2081 \u2208 cfg.\u03c9 :=\nbegin\n  haveI := some_orientation V,\n  exact affine.triangle.mem_circumsphere_of_two_zsmul_oangle_eq (dec_trivial : (0 : fin 3) \u2260 1)\n    (dec_trivial : (0 : fin 3) \u2260 2) dec_trivial cfg.two_zsmul_oangle_QQ\u2081A\u2082_eq_two_zsmul_oangle_QPA\u2082\nend\n\nlemma P\u2081_mem_\u03c9 : cfg.P\u2081 \u2208 cfg.\u03c9 := by { rw \u2190symm_\u03c9, exact cfg.symm.Q\u2081_mem_\u03c9 }\n\ntheorem result : concyclic ({cfg.P, cfg.Q, cfg.P\u2081, cfg.Q\u2081} : set Pt) :=\nbegin\n  refine \u27e8_, coplanar_of_fact_finrank_eq_two _\u27e9,\n  rw cospherical_iff_exists_sphere,\n  refine \u27e8cfg.\u03c9, _\u27e9,\n  simp only [set.insert_subset, set.singleton_subset_iff],\n  exact \u27e8cfg.P_mem_\u03c9, cfg.Q_mem_\u03c9, cfg.P\u2081_mem_\u03c9, cfg.Q\u2081_mem_\u03c9\u27e9\nend\n\nend imo2019q2_cfg\n\ntheorem imo2019_q2 (A B C A\u2081 B\u2081 P Q P\u2081 Q\u2081 : Pt)\n  (affine_independent_ABC : affine_independent \u211d ![A, B, C])\n  (wbtw_B_A\u2081_C : wbtw \u211d B A\u2081 C) (wbtw_A_B\u2081_C : wbtw \u211d A B\u2081 C) (wbtw_A_P_A\u2081 : wbtw \u211d A P A\u2081)\n  (wbtw_B_Q_B\u2081 : wbtw \u211d B Q B\u2081) (PQ_parallel_AB : line[\u211d, P, Q] \u2225 line[\u211d, A, B]) (P_ne_Q : P \u2260 Q)\n  (sbtw_P_B\u2081_P\u2081 : sbtw \u211d P B\u2081 P\u2081) (angle_PP\u2081C_eq_angle_BAC : \u2220 P P\u2081 C = \u2220 B A C)\n  (C_ne_P\u2081 : C \u2260 P\u2081) (sbtw_Q_A\u2081_Q\u2081 : sbtw \u211d Q A\u2081 Q\u2081)\n  (angle_CQ\u2081Q_eq_angle_CBA : \u2220 C Q\u2081 Q = \u2220 C B A) (C_ne_Q\u2081 : C \u2260 Q\u2081) :\n  concyclic ({P, Q, P\u2081, Q\u2081} : set Pt) :=\n(\u27e8A, B, C, A\u2081, B\u2081, P, Q, P\u2081, Q\u2081, affine_independent_ABC, wbtw_B_A\u2081_C, wbtw_A_B\u2081_C, wbtw_A_P_A\u2081,\n  wbtw_B_Q_B\u2081, PQ_parallel_AB, P_ne_Q, sbtw_P_B\u2081_P\u2081, angle_PP\u2081C_eq_angle_BAC, C_ne_P\u2081,\n  sbtw_Q_A\u2081_Q\u2081, angle_CQ\u2081Q_eq_angle_CBA, C_ne_Q\u2081\u27e9 : imo2019q2_cfg V Pt).result\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo2019_q2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7107688690224953}}
{"text": "import algebra.module\n\nuniverses u v w u\u2081 v\u2081\n\nclass is_ring_hom {\u03b1 : Type u} {\u03b2 : Type v} [comm_ring \u03b1] [comm_ring \u03b2] (f : \u03b1 \u2192 \u03b2) : Prop :=\n(map_add : \u2200 {x y}, f (x + y) = f x + f y)\n(map_mul : \u2200 {x y}, f (x * y) = f x * f y)\n(map_one : f 1 = 1)\n\nnamespace is_ring_hom\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [comm_ring \u03b1] [comm_ring \u03b2]\nvariables (f : \u03b1 \u2192 \u03b2) [is_ring_hom f] {x y : \u03b1}\n\nlemma map_zero : f 0 = 0 :=\ncalc f 0 = f (0 + 0) - f 0 : by rw [map_add f]; simp\n     ... = 0 : by simp\n\nlemma map_neg : f (-x) = -f x :=\ncalc f (-x) = f (-x + x) - f x : by rw [map_add f]; simp\n        ... = -f x : by simp [map_zero f]\n\nlemma map_sub : f (x - y) = f x - f y :=\nby simp [map_add f, map_neg f]\n\nend is_ring_hom\n\nsection bilinear\n\nvariables {\u03b1 : Type u} [comm_ring \u03b1]\ninclude \u03b1\n\nvariables {\u03b2 : Type v} {\u03b3 : Type w} {\u03b1\u2081 : Type u\u2081} {\u03b2\u2081 : Type v\u2081}\nvariables [module \u03b1 \u03b2] [module \u03b1 \u03b3] [module \u03b1 \u03b1\u2081] [module \u03b1 \u03b2\u2081]\n\nstructure is_bilinear_map {\u03b2 \u03b3 \u03b1\u2081}\n  [module \u03b1 \u03b2] [module \u03b1 \u03b3] [module \u03b1 \u03b1\u2081]\n  (f : \u03b2 \u2192 \u03b3 \u2192 \u03b1\u2081) : Prop :=\n(add_pair : \u2200 x y z, f (x + y) z = f x z + f y z)\n(pair_add : \u2200 x y z, f x (y + z) = f x y + f x z)\n(smul_pair : \u2200 r x y, f (r \u2022 x) y = r \u2022 f x y)\n(pair_smul : \u2200 r x y, f x (r \u2022 y) = r \u2022 f x y)\n\nvariables {f : \u03b2 \u2192 \u03b3 \u2192 \u03b1\u2081} (hf : is_bilinear_map f)\ninclude hf\n\ntheorem is_bilinear_map.zero_pair : \u2200 y, f 0 y = 0 :=\n\u03bb y, calc f 0 y\n        = f (0 + 0) y - f 0 y : by rw [hf.add_pair 0 0 y]; simp\n    ... = 0 : by simp\n\ntheorem is_bilinear_map.pair_zero : \u2200 x, f x 0 = 0 :=\n\u03bb x, calc f x 0\n        = f x (0 + 0) - f x 0 : by rw [hf.pair_add x 0 0]; simp\n    ... = 0 : by simp\n\ntheorem is_bilinear_map.linear_pair (y : \u03b3) : is_linear_map (\u03bb x, f x y) :=\n{ add  := \u03bb m n, hf.add_pair m n y,\n  smul := \u03bb r m, hf.smul_pair r m y }\n\ntheorem is_bilinear_map.pair_linear (x : \u03b2) : is_linear_map (\u03bb y, f x y) :=\n{ add  := \u03bb m n, hf.pair_add x m n,\n  smul := \u03bb r m, hf.pair_smul r x m }\n\ntheorem is_bilinear_map.smul_smul : \u2200 r\u2081 r\u2082 x y, f (r\u2081 \u2022 x) (r\u2082 \u2022 y) = (r\u2081 * r\u2082) \u2022 f x y :=\n\u03bb r\u2081 r\u2082 x y, by rw [hf.smul_pair, hf.pair_smul, mul_smul]\n\n\nvariables {g : \u03b1\u2081 \u2192 \u03b2\u2081} (hg : is_linear_map g)\ninclude hg\n\ntheorem is_bilinear_map.comp : is_bilinear_map (\u03bb x y, g (f x y)) :=\n{ add_pair  := \u03bb x y z, by rw [hf.add_pair, hg.add],\n  pair_add  := \u03bb x y z, by rw [hf.pair_add, hg.add],\n  smul_pair := \u03bb r x y, by rw [hf.smul_pair, hg.smul],\n  pair_smul := \u03bb r x y, by rw [hf.pair_smul, hg.smul] }\n\nend bilinear\n\n\n\nclass algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends module \u03b1 \u03b2, has_mul \u03b2 :=\n(mul_bilinear : is_bilinear_map $ @has_mul.mul \u03b2 _)\n\nclass alternative_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends algebra \u03b1 \u03b2 :=\n(mul_self_zero : \u2200 x : \u03b2, x * x = 0)\n\nclass associative_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends algebra \u03b1 \u03b2 :=\n(mul_assoc : \u2200 x y z : \u03b2, (x * y) * z = x * (y * z))\n\nclass power_associative_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends algebra \u03b1 \u03b2 :=\n(pow_assoc : \u2200 x : \u03b2, (x * x) * x = x * (x * x))\n\nclass commutative_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends algebra \u03b1 \u03b2 :=\n(mul_comm : \u2200 x y : \u03b2, x * y = y * x)\n\nclass unitary_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends algebra \u03b1 \u03b2, has_one \u03b2 :=\n(mul_one : \u2200 x : \u03b2, x * 1 = x)\n(one_mul : \u2200 x : \u03b2, 1 * x = x)\n\nclass unitary_division_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends unitary_algebra \u03b1 \u03b2 :=\n(zero_ne_one : (0:\u03b2) \u2260 (1:\u03b2))\n(left_inv : \u2200 x y : \u03b2, \u2203 z, z * x = y)\n(right_inv : \u2200 x y : \u03b2, \u2203 z, x * z = y)\n\nclass star_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends unitary_division_algebra \u03b1 \u03b2, has_inv \u03b2 :=\n(inv_inv : \u2200 x : \u03b2, (x\u207b\u00b9)\u207b\u00b9 = x)\n(mul_inv : \u2200 x y : \u03b2, (x * y)\u207b\u00b9 = y\u207b\u00b9 * x\u207b\u00b9)\n\nclass lie_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends alternative_algebra \u03b1 \u03b2 :=\n(jacobi : \u2200 x y z : \u03b2, x * (y * z) + y * (z * x) + z * (x * y) = 0)\n\n\n\nclass unitary_associative_commutative_algebra (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) extends unitary_algebra \u03b1 \u03b2 :=\n(mul_assoc : \u2200 x y z : \u03b2, (x * y) * z = x * (y * z))\n(mul_comm : \u2200 x y : \u03b2, x * y = y * x)\n\ninstance unitary_associative_commutative_algebra.has_mul (\u03b1 : out_param $ Type u) [comm_ring \u03b1] (\u03b2 : Type v) [unitary_associative_commutative_algebra \u03b1 \u03b2] : has_mul \u03b2 :=\nby apply_instance\n\ndef unitary_associative_commutative_algebra.of_is_ring_hom\n  {\u03b1 : Type u} [comm_ring \u03b1] {\u03b2 : Type v} [comm_ring \u03b2]\n  (f : \u03b1 \u2192 \u03b2) [is_ring_hom f] : unitary_associative_commutative_algebra \u03b1 \u03b2 :=\n{ smul := \u03bb x y, f x * y,\n  smul_add := \u03bb r x y, by simp [mul_add],\n  add_smul := \u03bb r\u2081 r\u2082 x, by simp [is_ring_hom.map_add f, add_mul],\n  mul_smul := \u03bb r\u2081 r\u2082 x, by simp [is_ring_hom.map_mul f, mul_assoc],\n  one_smul := \u03bb x, by simp [is_ring_hom.map_one f],\n  mul_bilinear :=\n    { add_pair  := add_mul,\n      pair_add  := mul_add,\n      smul_pair := \u03bb r x y, mul_assoc (f r) x y,\n      pair_smul := \u03bb r x y, mul_left_comm x (f r) y },\n  .. _inst_2 }\n\nnamespace unitary_associative_commutative_algebra\n\nvariables {\u03b1 : Type u} [comm_ring \u03b1]\nvariables {\u03b2 : Type v} [unitary_associative_commutative_algebra \u03b1 \u03b2]\ninclude \u03b1\n\ndef to_comm_ring : comm_ring \u03b2 :=\n{ left_distrib  := (algebra.mul_bilinear \u03b2).pair_add,\n  right_distrib := (algebra.mul_bilinear \u03b2).add_pair,\n  ..module.to_add_comm_group \u03b2, .._inst_2 }\n\nlocal attribute [instance] to_comm_ring\n\ndef to_is_ring_hom : is_ring_hom (\u03bb x:\u03b1, (x \u2022 1:\u03b2)) :=\n{ map_add := \u03bb x y, add_smul,\n  map_mul := \u03bb x y, (congr_arg _ (unitary_algebra.mul_one 1).symm).trans ((algebra.mul_bilinear \u03b2).smul_smul x y 1 1).symm,\n  map_one := one_smul }\n\nend unitary_associative_commutative_algebra\n\n\n\nsection lie_algebra\n\nvariables {\u03b1 : Type u} [comm_ring \u03b1]\nvariables {\u03b2 : Type v} [lie_algebra \u03b1 \u03b2] (x y : \u03b2)\n\ninclude \u03b1 \u03b2\n\ndef lie_algebra.has_mul : has_mul \u03b2 := by apply_instance\n\nlocal attribute [instance] lie_algebra.has_mul\n\ntheorem lie_algebra.anti_commutative  : x * y = -(y * x) :=\nhave h1 : _ := alternative_algebra.mul_self_zero (x + y),\nsorry\n\ntheorem lie_algebra.flexible  : (x * y) * x = x * (y * x) :=\nhave h1 : _ := @lie_algebra.jacobi \u03b1 _inst_1 \u03b2 _inst_2 x x y,\nhave h2 : _ := @lie_algebra.jacobi \u03b1 _inst_1 \u03b2 _inst_2 x y y,\nbegin end\n\nend lie_algebra\n", "meta": {"author": "kckennylau", "repo": "Lean", "sha": "907d0a4d2bd8f23785abd6142ad53d308c54fdcb", "save_path": "github-repos/lean/kckennylau-Lean", "path": "github-repos/lean/kckennylau-Lean/Lean-907d0a4d2bd8f23785abd6142ad53d308c54fdcb/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7107688600783116}}
{"text": "import data.real.basic\nimport data.real.nnreal\n\n\ntheorem JBMO_Problem_1_2000 (x  y : nnreal) : \nx^3 +y^3 +(x+y)^3 +30*x*y = 2000\n\u2192 x+y = 10 := sorry\n", "meta": {"author": "ahayat16", "repo": "lean_exos", "sha": "682f2552d5b04a8c8eb9e4ab15f875a91b03845c", "save_path": "github-repos/lean/ahayat16-lean_exos", "path": "github-repos/lean/ahayat16-lean_exos/lean_exos-682f2552d5b04a8c8eb9e4ab15f875a91b03845c/src_icannos_totilas/aops/2000-JBMO-Problem_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741295151718, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.710752707160899}}
{"text": "import game.max.level01 -- hide\n\nopen_locale classical -- hide\n\nnoncomputable theory -- hide\n\nnamespace xena -- hide\n\n/-\n# Chapter 4 : Max and abs\n\n## Level 2\n\n`max_comm` is the statement that `max a b = max b a`. See if you can prove it.\n-/\n\n/- Hint : Hint\nAgain, do a case split with `cases le_total a b`. \n-/\n\n/- Lemma\nFor any real numbers $a$ and $b$, we have $\\max(a,b) = \\max(b,a).$\n-/\ntheorem max_comm (a b : \u211d) : max a b = max b a :=\nbegin\n  cases le_total a b with h h;\n  rw max_eq_right h; \n  rw max_eq_left h,\n  \nend\n\nend xena --hide\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/max/level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.710748285175374}}
{"text": "-- import SciLean.Core.CoreFunctionProperties\nimport SciLean.Core.AdjDiff\n\nnamespace SciLean\n\n--------------------------------------------------------------------------------\n-- Variational Dual\n--------------------------------------------------------------------------------\n\n-- variational version of \u2020\nnoncomputable\ndef variationalDual (F : (X\u27ffY) \u2192 (LocIntDom X \u2192 \u211d)) : (X\u27ffY) :=\n  let has_dual := \u2203 A : (X\u27ffY) \u2192 (X\u27ff\u211d), HasAdjointT A \u2227 \u2200 \u03d5, F \u03d5 = \u222b (A \u03d5)\n  match Classical.propDecidable (has_dual) with\n  | isTrue h => \n    let A := Classical.choose h\n    A\u2020 (\u03bb _ \u27ff 1)\n  | isFalse _ => 0\n\ninstance (F : (X\u27ffY) \u2192 (LocIntDom X \u2192 \u211d)) \n  : Dagger F (variationalDual F) := \u27e8\u27e9\n\n-- variational version of \u2207 \nnoncomputable\ndef variationalGradient (F : (X\u27ffY) \u2192 LocIntDom X \u2192 \u211d) (f : X\u27ffY) : X \u27ff Y := (\u2202 F f)\u2020\n\ninstance (F : (X\u27ffY) \u2192 LocIntDom X \u2192 \u211d) : Nabla F (variationalGradient F) := \u27e8\u27e9\n\n\n-- Properties\n\ninstance integral.arg_f.isLin : IsLin (integral : (X\u27ffY) \u2192 LocIntDom X \u2192 Y) := sorry_proof\n\n-- @[simp \u2193 low, diff low]\n-- theorem variationalGradient_unfold (F : (X\u27ffY) \u2192 LocIntDom X \u2192 \u211d)\n--   : \u2207 F = \u03bb f => (\u2202 F f)\u2020 := by rfl\n\n@[simp \u2193, diff]\ntheorem varDual_smooth_fun (F : (X\u27ffY) \u2192 (X\u27ff\u211d)) [HasAdjointT F]\n  : (\u03bb (f : X \u27ff Y) => \u222b (F f))\u2020 = F\u2020 (\u03bb _ \u27ff 1) := sorry_proof\n\n\n@[simp \u2193, diff]\ntheorem variationalGradient_on_integral (F : (X\u27ffY) \u2192 (X\u27ff\u211d)) [inst : HasAdjDiffT F]\n  : \u2207 f, \u222b (F f) = \u03bb f => \u2202\u2020 F f (\u03bb _ \u27ff 1) := \nby \n  have _ := inst.1.1\n  have _ := inst.1.2\n  unfold variationalGradient\n  unfold adjointDifferential\n  symdiff\n  symdiff\n  done\n\n\n@[simp \u2193, diff]\ntheorem varDual_smooth_fun_elemwise [Hilbert Y] (A : X \u2192 Y \u2192 \u211d) [\u2200 x, HasAdjointT (A x)] [IsSmoothNT 2 A]\n  : (\u03bb (g : X \u27ff Y) => \u222b x, A x (g x))\u2020 = (\u03bb x \u27ff (A x)\u2020 1) := sorry_proof\n\n@[simp \u2193, diff]\ntheorem varDual_smooth_fun_elemwise' [Hilbert Y] [Vec Z] (f : X \u2192 Z) [IsSmoothT f] \n  (A : Y \u2192 Z \u2192 \u211d) [\u2200 z, HasAdjointT (\u03bb y => A y z)] [IsSmoothNT 2 A]\n  : (\u03bb (g : X \u27ff Y) => \u222b x, A (g x) (f x))\u2020 = (\u03bb x \u27ff (\u03bb y => A y (f x))\u2020 1) := \nby apply varDual_smooth_fun_elemwise (\u03bb x y => A y (f x)); done\n\n\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/SciLean/Core/VariationalDual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7107392132807009}}
{"text": "inductive bin : nat \u2192 Prop\n| bin_epsilon : bin 0\n| bin_0 : \u2200 (n: nat), bin n \u2192 bin (2 * n)\n| bin_1 : \u2200 (n: nat), bin n \u2192 bin (2 * n + 1)\n\ndef is_expressible_in_binary_notation := bin\n\nlemma two_gt_one_ : 2 > 1 :=\nbegin\n    exact dec_trivial\nend\n\nlemma two_gt_zero : 2 > 0 :=\nbegin\n    exact dec_trivial\nend\n\nexample : \u2200 (n : nat), is_expressible_in_binary_notation n :=\nbegin\n    intros,\n    unfold is_expressible_in_binary_notation,\n    apply well_founded.induction nat.lt_wf n _; clear n,\n    intros x ih,\n    let p := x % 2,\n    let q := x / 2,\n    have: p = 0 \u2228 p = 1,\n        apply nat.mod_two_eq_zero_or_one,\n    cases x,\n        apply bin.bin_epsilon,\n    have succ_x_gt_zero: nat.succ x > 0, from nat.zero_lt_succ x,\n    have div_2_lt : nat.succ x / 2 < nat.succ x,\n        from nat.div_lt_self succ_x_gt_zero two_gt_one_,\n    cases this,\n        have hoge : p + 2 * q = nat.succ x, from nat.mod_add_div (nat.succ x) 2,\n        rw \u2190hoge,\n        rw this,\n        rw zero_add,\n        apply bin.bin_0 q,\n        apply ih q,\n        assumption,\n    have hoge : p + 2 * q = nat.succ x, from nat.mod_add_div (nat.succ x) 2,\n    rw \u2190hoge,\n    rw this,\n    rw add_comm,\n    apply bin.bin_1 q,\n    apply ih q,\n    assumption,\nend\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/topprover/23.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.710739198677753}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.field_division\n! leanprover-community/mathlib commit bbeb185db4ccee8ed07dc48449414ebfa39cb821\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.Derivative\nimport Mathlib.Data.Polynomial.RingDivision\nimport Mathlib.RingTheory.EuclideanDomain\n\n/-!\n# Theory of univariate polynomials\n\nThis file starts looking like the ring theory of $ R[X] $\n\n-/\n\n\nnoncomputable section\n\nopen Classical BigOperators Polynomial\n\nnamespace Polynomial\n\nuniverse u v w y z\n\nvariable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : \u2115}\n\nsection IsDomain\n\nvariable [CommRing R] [IsDomain R]\n\ntheorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) :\n    p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by\n  rcases eq_or_ne p 0 with (rfl | hp)\n  \u00b7 simp\n  nth_rw 1 [\u2190 p.divByMonic_mul_pow_rootMultiplicity_eq t]\n  simp only [derivative_pow, derivative_mul, derivative_sub, derivative_X, derivative_C, sub_zero,\n    mul_one]\n  set n := p.rootMultiplicity t - 1\n  have hn : n + 1 = _ := tsub_add_cancel_of_le ((rootMultiplicity_pos hp).mpr hpt)\n  rw [\u2190 hn]\n  set q := p /\u2098 (X - C t) ^ (n + 1) with _hq\n  convert_to rootMultiplicity t ((X - C t) ^ n * (derivative q * (X - C t) + q * C \u2191(n + 1))) = n\n  \u00b7 congr\n    rw [mul_add, mul_left_comm <| (X - C t) ^ n, \u2190 pow_succ']\n    congr 1\n    rw [mul_left_comm <| (X - C t) ^ n, mul_comm <| (X - C t) ^ n]\n  have h : eval t (derivative q * (X - C t) + q * C (R := R) \u2191(n + 1)) \u2260 0 := by\n    suffices eval t q * \u2191(n + 1) \u2260 0 by simpa\n    refine' mul_ne_zero _ (Nat.cast_ne_zero.mpr n.succ_ne_zero)\n    convert eval_divByMonic_pow_rootMultiplicity_ne_zero t hp\n  rw [rootMultiplicity_mul, rootMultiplicity_X_sub_C_pow, rootMultiplicity_eq_zero h, add_zero]\n  refine' mul_ne_zero (pow_ne_zero n <| X_sub_C_ne_zero t) _\n  contrapose! h\n  rw [h, eval_zero]\n#align polynomial.derivative_root_multiplicity_of_root Polynomial.derivative_rootMultiplicity_of_root\n\ntheorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) :\n    p.rootMultiplicity t - 1 \u2264 p.derivative.rootMultiplicity t := by\n  by_cases p.IsRoot t\n  \u00b7 exact (derivative_rootMultiplicity_of_root h).symm.le\n  \u00b7 rw [rootMultiplicity_eq_zero h, zero_tsub]\n    exact zero_le _\n#align polynomial.root_multiplicity_sub_one_le_derivative_root_multiplicity Polynomial.rootMultiplicity_sub_one_le_derivative_rootMultiplicity\n\nsection NormalizationMonoid\n\nvariable [NormalizationMonoid R]\n\ninstance : NormalizationMonoid R[X] where\n  normUnit p :=\n    \u27e8C \u2191(normUnit p.leadingCoeff), C \u2191(normUnit p.leadingCoeff)\u207b\u00b9, by\n      rw [\u2190 RingHom.map_mul, Units.mul_inv, C_1], by rw [\u2190 RingHom.map_mul, Units.inv_mul, C_1]\u27e9\n  normUnit_zero := Units.ext (by simp)\n  normUnit_mul hp0 hq0 :=\n    Units.ext\n      (by\n        dsimp\n        rw [Ne.def, \u2190 leadingCoeff_eq_zero] at *\n        rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul])\n  normUnit_coe_units u :=\n    Units.ext\n      (by\n        dsimp\n        rw [\u2190 mul_one u\u207b\u00b9, Units.val_mul, Units.eq_inv_mul_iff_mul_eq]\n        rcases Polynomial.isUnit_iff.1 \u27e8u, rfl\u27e9 with \u27e8_, \u27e8w, rfl\u27e9, h2\u27e9\n        rw [\u2190 h2, leadingCoeff_C, normUnit_coe_units, \u2190 C_mul, Units.mul_inv, C_1]\n        rfl)\n\n@[simp]\ntheorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C \u2191(normUnit p.leadingCoeff) := by\n  simp [normUnit]\n#align polynomial.coe_norm_unit Polynomial.coe_normUnit\n\ntheorem leadingCoeff_normalize (p : R[X]) :\n    leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp\n#align polynomial.leading_coeff_normalize Polynomial.leadingCoeff_normalize\n\ntheorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by\n  simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one,\n    Units.val_one, Polynomial.C.map_one, mul_one]\n#align polynomial.monic.normalize_eq_self Polynomial.Monic.normalize_eq_self\n\ntheorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by\n  rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero]\n#align polynomial.roots_normalize Polynomial.roots_normalize\n\nend NormalizationMonoid\n\nend IsDomain\n\nsection DivisionRing\n\nvariable [DivisionRing R] {p q : R[X]}\n\ntheorem degree_pos_of_ne_zero_of_nonunit (hp0 : p \u2260 0) (hp : \u00acIsUnit p) : 0 < degree p :=\n  lt_of_not_ge fun h => by\n    rw [eq_C_of_degree_le_zero h] at hp0 hp\n    exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))))\n#align polynomial.degree_pos_of_ne_zero_of_nonunit Polynomial.degree_pos_of_ne_zero_of_nonunit\n\ntheorem monic_mul_leadingCoeff_inv (h : p \u2260 0) : Monic (p * C (leadingCoeff p)\u207b\u00b9) := by\n  rw [Monic, leadingCoeff_mul, leadingCoeff_C,\n    mul_inv_cancel (show leadingCoeff p \u2260 0 from mt leadingCoeff_eq_zero.1 h)]\n#align polynomial.monic_mul_leading_coeff_inv Polynomial.monic_mul_leadingCoeff_inv\n\ntheorem degree_mul_leadingCoeff_inv (p : R[X]) (h : q \u2260 0) :\n    degree (p * C (leadingCoeff q)\u207b\u00b9) = degree p := by\n  have h\u2081 : (leadingCoeff q)\u207b\u00b9 \u2260 0 := inv_ne_zero (mt leadingCoeff_eq_zero.1 h)\n  rw [degree_mul, degree_C h\u2081, add_zero]\n#align polynomial.degree_mul_leading_coeff_inv Polynomial.degree_mul_leadingCoeff_inv\n\n@[simp]\ntheorem map_eq_zero [Semiring S] [Nontrivial S] (f : R \u2192+* S) : p.map f = 0 \u2194 p = 0 := by\n  simp only [Polynomial.ext_iff]\n  congr!\n  simp [map_eq_zero, coeff_map, coeff_zero]\n#align polynomial.map_eq_zero Polynomial.map_eq_zero\n\ntheorem map_ne_zero [Semiring S] [Nontrivial S] {f : R \u2192+* S} (hp : p \u2260 0) : p.map f \u2260 0 :=\n  mt (map_eq_zero f).1 hp\n#align polynomial.map_ne_zero Polynomial.map_ne_zero\n\nend DivisionRing\n\nsection Field\n\nvariable [Field R] {p q : R[X]}\n\ntheorem isUnit_iff_degree_eq_zero : IsUnit p \u2194 degree p = 0 :=\n  \u27e8degree_eq_zero_of_isUnit, fun h =>\n    have : degree p \u2264 0 := by simp [*, le_refl]\n    have hc : coeff p 0 \u2260 0 := fun hc => by\n      rw [eq_C_of_degree_le_zero this, hc] at h; simp at h\n    isUnit_iff_dvd_one.2\n      \u27e8C (coeff p 0)\u207b\u00b9, by\n        conv in p => rw [eq_C_of_degree_le_zero this]\n        rw [\u2190 C_mul, _root_.mul_inv_cancel hc, C_1]\u27e9\u27e9\n#align polynomial.is_unit_iff_degree_eq_zero Polynomial.isUnit_iff_degree_eq_zero\n\n/-- Division of polynomials. See `polynomial.divByMonic` for more details.-/\ndef div (p q : R[X]) :=\n  C (leadingCoeff q)\u207b\u00b9 * (p /\u2098 (q * C (leadingCoeff q)\u207b\u00b9))\n#align polynomial.div Polynomial.div\n\n/-- Remainder of polynomial division. See `polynomial.modByMonic` for more details. -/\ndef mod (p q : R[X]) :=\n  p %\u2098 (q * C (leadingCoeff q)\u207b\u00b9)\n#align polynomial.mod Polynomial.mod\n\nprivate theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p :=\n  if h : q = 0 then by simp only [h, MulZeroClass.zero_mul, mod, modByMonic_zero, zero_add]\n  else\n    by\n    conv =>\n      rhs\n      rw [\u2190 modByMonic_add_div p (monic_mul_leadingCoeff_inv h)]\n    rw [div, mod, add_comm, mul_assoc]\n\nprivate theorem remainder_lt_aux (p : R[X]) (hq : q \u2260 0) : degree (mod p q) < degree q := by\n  rw [\u2190 degree_mul_leadingCoeff_inv q hq];\n    exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq)\n\ninstance : Div R[X] :=\n  \u27e8div\u27e9\n\ninstance : Mod R[X] :=\n  \u27e8mod\u27e9\n\ntheorem div_def : p / q = C (leadingCoeff q)\u207b\u00b9 * (p /\u2098 (q * C (leadingCoeff q)\u207b\u00b9)) :=\n  rfl\n#align polynomial.div_def Polynomial.div_def\n\ntheorem mod_def : p % q = p %\u2098 (q * C (leadingCoeff q)\u207b\u00b9) := rfl\n#align polynomial.mod_def Polynomial.mod_def\n\ntheorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %\u2098 q = p % q :=\n  show p %\u2098 q = p %\u2098 (q * C (leadingCoeff q)\u207b\u00b9) by simp only [Monic.def.1 hq, inv_one, mul_one, C_1]\n#align polynomial.mod_by_monic_eq_mod Polynomial.modByMonic_eq_mod\n\ntheorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /\u2098 q = p / q :=\n  show p /\u2098 q = C (leadingCoeff q)\u207b\u00b9 * (p /\u2098 (q * C (leadingCoeff q)\u207b\u00b9)) by\n    simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one]\n#align polynomial.div_by_monic_eq_div Polynomial.divByMonic_eq_div\n\ntheorem mod_x_sub_c_eq_c_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) :=\n  modByMonic_eq_mod p (monic_X_sub_C a) \u25b8 modByMonic_X_sub_C_eq_C_eval _ _\nset_option linter.uppercaseLean3 false in\n#align polynomial.mod_X_sub_C_eq_C_eval Polynomial.mod_x_sub_c_eq_c_eval\n\ntheorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p \u2194 IsRoot p a :=\n  divByMonic_eq_div p (monic_X_sub_C a) \u25b8 mul_divByMonic_eq_iff_isRoot\n#align polynomial.mul_div_eq_iff_is_root Polynomial.mul_div_eq_iff_isRoot\n\ninstance : EuclideanDomain R[X] :=\n  { Polynomial.commRing,\n    Polynomial.nontrivial with\n    quotient := (\u00b7 / \u00b7)\n    quotient_zero := by simp [div_def]\n    remainder := (\u00b7 % \u00b7)\n    r := _\n    r_wellFounded := degree_lt_wf\n    quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux\n    remainder_lt := fun p q hq => remainder_lt_aux _ hq\n    mul_left_not_lt := fun p q hq => not_lt_of_ge (degree_le_mul_left _ hq) }\n\ntheorem mod_eq_self_iff (hq0 : q \u2260 0) : p % q = p \u2194 degree p < degree q :=\n  \u27e8fun h => h \u25b8 EuclideanDomain.mod_lt _ hq0, fun h =>\n    by\n    have : \u00acdegree (q * C (leadingCoeff q)\u207b\u00b9) \u2264 degree p :=\n      not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0]\n    rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)]\n    unfold divModByMonicAux\n    dsimp\n    simp only [this, false_and_iff, if_false]\u27e9\n#align polynomial.mod_eq_self_iff Polynomial.mod_eq_self_iff\n\ntheorem div_eq_zero_iff (hq0 : q \u2260 0) : p / q = 0 \u2194 degree p < degree q :=\n  \u27e8fun h => by\n    have := EuclideanDomain.div_add_mod p q;\n      rwa [h, MulZeroClass.mul_zero, zero_add, mod_eq_self_iff hq0] at this,\n    fun h =>\n    by\n    have hlt : degree p < degree (q * C (leadingCoeff q)\u207b\u00b9) := by\n      rwa [degree_mul_leadingCoeff_inv q hq0]\n    have hm : Monic (q * C (leadingCoeff q)\u207b\u00b9) := monic_mul_leadingCoeff_inv hq0\n    rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, MulZeroClass.mul_zero]\u27e9\n#align polynomial.div_eq_zero_iff Polynomial.div_eq_zero_iff\n\ntheorem degree_add_div (hq0 : q \u2260 0) (hpq : degree q \u2264 degree p) :\n    degree q + degree (p / q) = degree p := by\n  have : degree (p % q) < degree (q * (p / q)) :=\n    calc\n      degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0\n      _ \u2264 _ := degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq))\n      \n  conv_rhs =>\n    rw [\u2190 EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul]\n#align polynomial.degree_add_div Polynomial.degree_add_div\n\ntheorem degree_div_le (p q : R[X]) : degree (p / q) \u2264 degree p :=\n  if hq : q = 0 then by simp [hq]\n  else by\n    rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _\n#align polynomial.degree_div_le Polynomial.degree_div_le\n\ntheorem degree_div_lt (hp : p \u2260 0) (hq : 0 < degree q) : degree (p / q) < degree p := by\n  have hq0 : q \u2260 0 := fun hq0 => by simp [hq0] at hq\n  rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0];\n    exact\n      degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp\n        (by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq)\n#align polynomial.degree_div_lt Polynomial.degree_div_lt\n\n@[simp]\ntheorem degree_map [DivisionRing k] (p : R[X]) (f : R \u2192+* k) : degree (p.map f) = degree p :=\n  p.degree_map_eq_of_injective f.injective\n#align polynomial.degree_map Polynomial.degree_map\n\n@[simp]\ntheorem natDegree_map [DivisionRing k] (f : R \u2192+* k) : natDegree (p.map f) = natDegree p :=\n  natDegree_eq_of_degree_eq (degree_map _ f)\n#align polynomial.nat_degree_map Polynomial.natDegree_map\n\n@[simp]\ntheorem leadingCoeff_map [DivisionRing k] (f : R \u2192+* k) :\n    leadingCoeff (p.map f) = f (leadingCoeff p) := by\n  simp only [\u2190 coeff_natDegree, coeff_map f, natDegree_map]\n#align polynomial.leading_coeff_map Polynomial.leadingCoeff_map\n\ntheorem monic_map_iff [DivisionRing k] {f : R \u2192+* k} {p : R[X]} : (p.map f).Monic \u2194 p.Monic := by\n  rw [Monic, leadingCoeff_map, \u2190 f.map_one, Function.Injective.eq_iff f.injective, Monic]\n#align polynomial.monic_map_iff Polynomial.monic_map_iff\n\n\n\ntheorem map_div [Field k] (f : R \u2192+* k) : (p / q).map f = p.map f / q.map f := by \n  if hq0 : q = 0 then simp [hq0]\n  else\n    rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0), \n      Polynomial.map_mul, map_C, leadingCoeff_map, map_inv\u2080]\n#align polynomial.map_div Polynomial.map_div\n\ntheorem map_mod [Field k] (f : R \u2192+* k) : (p % q).map f = p.map f % q.map f :=\n  if hq0 : q = 0 then by simp [hq0]\n  else by\n    rw [mod_def, mod_def, leadingCoeff_map f, \u2190 map_inv\u2080 f, \u2190 map_C f, \u2190 Polynomial.map_mul f,\n      map_modByMonic f (monic_mul_leadingCoeff_inv hq0)]\n#align polynomial.map_mod Polynomial.map_mod\n\nsection\n\nopen EuclideanDomain\n\ntheorem gcd_map [Field k] (f : R \u2192+* k) : gcd (p.map f) (q.map f) = (gcd p q).map f :=\n  GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left])\n    fun x y _ ih => by rw [gcd_val, \u2190 map_mod, ih, \u2190 gcd_val]\n#align polynomial.gcd_map Polynomial.gcd_map\n\nend\n\ntheorem eval\u2082_gcd_eq_zero [CommSemiring k] {\u03d5 : R \u2192+* k} {f g : R[X]} {\u03b1 : k} (hf : f.eval\u2082 \u03d5 \u03b1 = 0)\n    (hg : g.eval\u2082 \u03d5 \u03b1 = 0) : (EuclideanDomain.gcd f g).eval\u2082 \u03d5 \u03b1 = 0 := by\n  rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval\u2082_add, Polynomial.eval\u2082_mul,\n    Polynomial.eval\u2082_mul, hf, hg, MulZeroClass.zero_mul, MulZeroClass.zero_mul, zero_add]\n#align polynomial.eval\u2082_gcd_eq_zero Polynomial.eval\u2082_gcd_eq_zero\n\ntheorem eval_gcd_eq_zero {f g : R[X]} {\u03b1 : R} (hf : f.eval \u03b1 = 0) (hg : g.eval \u03b1 = 0) :\n    (EuclideanDomain.gcd f g).eval \u03b1 = 0 :=\n  eval\u2082_gcd_eq_zero hf hg\n#align polynomial.eval_gcd_eq_zero Polynomial.eval_gcd_eq_zero\n\ntheorem root_left_of_root_gcd [CommSemiring k] {\u03d5 : R \u2192+* k} {f g : R[X]} {\u03b1 : k}\n    (h\u03b1 : (EuclideanDomain.gcd f g).eval\u2082 \u03d5 \u03b1 = 0) : f.eval\u2082 \u03d5 \u03b1 = 0 := by\n  cases' EuclideanDomain.gcd_dvd_left f g with p hp\n  rw [hp, Polynomial.eval\u2082_mul, h\u03b1, MulZeroClass.zero_mul]\n#align polynomial.root_left_of_root_gcd Polynomial.root_left_of_root_gcd\n\ntheorem root_right_of_root_gcd [CommSemiring k] {\u03d5 : R \u2192+* k} {f g : R[X]} {\u03b1 : k}\n    (h\u03b1 : (EuclideanDomain.gcd f g).eval\u2082 \u03d5 \u03b1 = 0) : g.eval\u2082 \u03d5 \u03b1 = 0 := by\n  cases' EuclideanDomain.gcd_dvd_right f g with p hp\n  rw [hp, Polynomial.eval\u2082_mul, h\u03b1, MulZeroClass.zero_mul]\n#align polynomial.root_right_of_root_gcd Polynomial.root_right_of_root_gcd\n\ntheorem root_gcd_iff_root_left_right [CommSemiring k] {\u03d5 : R \u2192+* k} {f g : R[X]} {\u03b1 : k} :\n    (EuclideanDomain.gcd f g).eval\u2082 \u03d5 \u03b1 = 0 \u2194 f.eval\u2082 \u03d5 \u03b1 = 0 \u2227 g.eval\u2082 \u03d5 \u03b1 = 0 :=\n  \u27e8fun h => \u27e8root_left_of_root_gcd h, root_right_of_root_gcd h\u27e9, fun h => eval\u2082_gcd_eq_zero h.1 h.2\u27e9\n#align polynomial.root_gcd_iff_root_left_right Polynomial.root_gcd_iff_root_left_right\n\ntheorem isRoot_gcd_iff_isRoot_left_right {f g : R[X]} {\u03b1 : R} :\n    (EuclideanDomain.gcd f g).IsRoot \u03b1 \u2194 f.IsRoot \u03b1 \u2227 g.IsRoot \u03b1 :=\n  root_gcd_iff_root_left_right\n#align polynomial.is_root_gcd_iff_is_root_left_right Polynomial.isRoot_gcd_iff_isRoot_left_right\n\ntheorem isCoprime_map [Field k] (f : R \u2192+* k) : IsCoprime (p.map f) (q.map f) \u2194 IsCoprime p q := by\n  rw [\u2190 EuclideanDomain.gcd_isUnit_iff, \u2190 EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map]\n#align polynomial.is_coprime_map Polynomial.isCoprime_map\n\ntheorem mem_roots_map [CommRing k] [IsDomain k] {f : R \u2192+* k} {x : k} (hp : p \u2260 0) :\n    x \u2208 (p.map f).roots \u2194 p.eval\u2082 f x = 0 := by\n  rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map]\n#align polynomial.mem_roots_map Polynomial.mem_roots_map\n\n-- Porting note: previously could not synthesize Algebra R S\nset_option synthInstance.etaExperiment true in\ntheorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : \u2115} (hn : n \u2260 0) {a : R}\n    (ha : a \u2260 0) : (monomial n a).rootSet S = {0} := by\n  rw [rootSet, map_monomial, roots_monomial ((_root_.map_ne_zero (algebraMap R S)).2 ha),\n    Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton]\n#align polynomial.root_set_monomial Polynomial.rootSet_monomial\n\n-- Porting note: previously could not synthesize Algebra R S\nset_option synthInstance.etaExperiment true in\ntheorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : \u2115} (hn : n \u2260 0) {a : R}\n    (ha : a \u2260 0) : rootSet (C a * X ^ n) S = {0} := by\n  rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha]\nset_option linter.uppercaseLean3 false in\n#align polynomial.root_set_C_mul_X_pow Polynomial.rootSet_C_mul_X_pow\n\n-- Porting note: previously could not synthesize Algebra R S\nset_option synthInstance.etaExperiment true in\ntheorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : \u2115} (hn : n \u2260 0) :\n    (X ^ n : R[X]).rootSet S = {0} := by\n  rw [\u2190 one_mul (X ^ n : R[X]), \u2190 C_1, rootSet_C_mul_X_pow hn]\n  exact one_ne_zero\nset_option linter.uppercaseLean3 false in\n#align polynomial.root_set_X_pow Polynomial.rootSet_X_pow\n\n-- Porting note: previously could not synthesize Algebra R S\nset_option synthInstance.etaExperiment true in\ntheorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {\u03b9 : Type _} (f : \u03b9 \u2192 R[X])\n    (s : Finset \u03b9) (h : s.prod f \u2260 0) : (s.prod f).rootSet S = \u22c3 i \u2208 s, (f i).rootSet S := by\n  simp only [rootSet, \u2190 Finset.mem_coe]\n  rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_bunion\u1d62]\n  rwa [\u2190 Polynomial.map_prod, Ne, map_eq_zero]\n#align polynomial.root_set_prod Polynomial.rootSet_prod\n\ntheorem exists_root_of_degree_eq_one (h : degree p = 1) : \u2203 x, IsRoot p x :=\n  \u27e8-(p.coeff 0 / p.coeff 1),\n    by\n    have : p.coeff 1 \u2260 0 := by\n      have h' := natDegree_eq_of_degree_eq_some h\n      change natDegree p = 1 at h'; rw [\u2190h']\n      exact mt leadingCoeff_eq_zero.1 fun h0 => by simp [h0] at h\n    conv in p => rw [eq_X_add_C_of_degree_le_one (show degree p \u2264 1 by rw [h])]\n    simp [IsRoot, mul_div_cancel' _ this]\u27e9\n#align polynomial.exists_root_of_degree_eq_one Polynomial.exists_root_of_degree_eq_one\n\ntheorem coeff_inv_units (u : R[X]\u02e3) (n : \u2115) : ((\u2191u : R[X]).coeff n)\u207b\u00b9 = (\u2191u\u207b\u00b9 : R[X]).coeff n := by\n  rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u\u207b\u00b9),\n    coeff_C, coeff_C, inv_eq_one_div]\n  split_ifs\n  \u00b7\n    rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero,\n        coeff_zero_eq_eval_zero, \u2190 eval_mul, \u2190 Units.val_mul, inv_mul_self];\n      simp\n  \u00b7 simp\n#align polynomial.coeff_inv_units Polynomial.coeff_inv_units\n\n-- Porting note: previously could not synthesize NormalisationMonoid R[X]\nset_option synthInstance.etaExperiment true in\ntheorem monic_normalize (hp0 : p \u2260 0) : Monic (normalize p) := by\n  rw [Ne.def, \u2190 leadingCoeff_eq_zero, \u2190 Ne.def, \u2190 isUnit_iff_ne_zero] at hp0\n  rw [Monic, leadingCoeff_normalize, normalize_eq_one]\n  apply hp0\n#align polynomial.monic_normalize Polynomial.monic_normalize\n\ntheorem leadingCoeff_div (hpq : q.degree \u2264 p.degree) :\n    (p / q).leadingCoeff = p.leadingCoeff / q.leadingCoeff := by\n  by_cases hq : q = 0; \u00b7 simp [hq]\n  rw [div_def, leadingCoeff_mul, leadingCoeff_C,\n    leadingCoeff_divByMonic_of_monic (monic_mul_leadingCoeff_inv hq) _, mul_comm,\n    div_eq_mul_inv]\n  rwa [degree_mul_leadingCoeff_inv q hq]\n#align polynomial.leading_coeff_div Polynomial.leadingCoeff_div\n\ntheorem div_C_mul : p / (C a * q) = C a\u207b\u00b9 * (p / q) := by\n  by_cases ha : a = 0\n  \u00b7 simp [ha]\n  simp only [div_def, leadingCoeff_mul, mul_inv, leadingCoeff_C, C.map_mul, mul_assoc]\n  congr 3\n  rw [mul_left_comm q, \u2190 mul_assoc, \u2190 C.map_mul, mul_inv_cancel ha, C.map_one, one_mul]\nset_option linter.uppercaseLean3 false in\n#align polynomial.div_C_mul Polynomial.div_C_mul\n\ntheorem C_mul_dvd (ha : a \u2260 0) : C a * p \u2223 q \u2194 p \u2223 q :=\n  \u27e8fun h => dvd_trans (dvd_mul_left _ _) h, fun \u27e8r, hr\u27e9 =>\n    \u27e8C a\u207b\u00b9 * r, by\n      rw [mul_assoc, mul_left_comm p, \u2190 mul_assoc, \u2190 C.map_mul, _root_.mul_inv_cancel ha, C.map_one,\n        one_mul, hr]\u27e9\u27e9\nset_option linter.uppercaseLean3 false in\n#align polynomial.C_mul_dvd Polynomial.C_mul_dvd\n\ntheorem dvd_C_mul (ha : a \u2260 0) : p \u2223 Polynomial.C a * q \u2194 p \u2223 q :=\n  \u27e8fun \u27e8r, hr\u27e9 =>\n    \u27e8C a\u207b\u00b9 * r, by\n      rw [mul_left_comm p, \u2190 hr, \u2190 mul_assoc, \u2190 C.map_mul, _root_.inv_mul_cancel ha, C.map_one,\n        one_mul]\u27e9,\n    fun h => dvd_trans h (dvd_mul_left _ _)\u27e9\nset_option linter.uppercaseLean3 false in\n#align polynomial.dvd_C_mul Polynomial.dvd_C_mul\n\n-- Porting note: previously could not synthesize NormalisationMonoid R[X]\nset_option synthInstance.etaExperiment true in\ntheorem coe_normUnit_of_ne_zero (hp : p \u2260 0) : (normUnit p : R[X]) = C p.leadingCoeff\u207b\u00b9 := by\n  have : p.leadingCoeff \u2260 0 := mt leadingCoeff_eq_zero.mp hp\n  simp [CommGroupWithZero.coe_normUnit _ this]\n#align polynomial.coe_norm_unit_of_ne_zero Polynomial.coe_normUnit_of_ne_zero\n\n-- Porting note: previously could not synthesize NormalisationMonoid R[X]\nset_option synthInstance.etaExperiment true in\ntheorem normalize_monic (h : Monic p) : normalize p = p := by simp [h]\n#align polynomial.normalize_monic Polynomial.normalize_monic\n\n-- Porting note: previously could not synthesize NormalisationMonoid R[X]\nset_option synthInstance.etaExperiment true in\ntheorem map_dvd_map' [Field k] (f : R \u2192+* k) {x y : R[X]} : x.map f \u2223 y.map f \u2194 x \u2223 y :=\n  if H : x = 0 then by rw [H, Polynomial.map_zero, zero_dvd_iff, zero_dvd_iff, map_eq_zero]\n  else by\n    rw [\u2190 normalize_dvd_iff, \u2190 @normalize_dvd_iff R[X], normalize_apply, normalize_apply,\n      coe_normUnit_of_ne_zero H, coe_normUnit_of_ne_zero (mt (map_eq_zero f).1 H),\n      leadingCoeff_map, \u2190 map_inv\u2080 f, \u2190 map_C, \u2190 Polynomial.map_mul,\n      map_dvd_map _ f.injective (monic_mul_leadingCoeff_inv H)]\n#align polynomial.map_dvd_map' Polynomial.map_dvd_map'\n\n-- Porting note: previously could not synthesize NormalisationMonoid R[X]\nset_option synthInstance.etaExperiment true in\ntheorem degree_normalize : degree (normalize p) = degree p := by simp\n#align polynomial.degree_normalize Polynomial.degree_normalize\n\n-- Porting note: previously could not synthesize NormalisationMonoid R[X]\nset_option synthInstance.etaExperiment true in\ntheorem prime_of_degree_eq_one (hp1 : degree p = 1) : Prime p :=\n  have : Prime (normalize p) :=\n    Monic.prime_of_degree_eq_one (hp1 \u25b8 degree_normalize)\n      (monic_normalize fun hp0 => absurd hp1 (hp0.symm \u25b8 by simp))\n  (normalize_associated _).prime this\n#align polynomial.prime_of_degree_eq_one Polynomial.prime_of_degree_eq_one\n\ntheorem irreducible_of_degree_eq_one (hp1 : degree p = 1) : Irreducible p :=\n  (prime_of_degree_eq_one hp1).irreducible\n#align polynomial.irreducible_of_degree_eq_one Polynomial.irreducible_of_degree_eq_one\n\ntheorem not_irreducible_c (x : R) : \u00acIrreducible (C x) :=\n  if H : x = 0 then by\n    rw [H, C_0]\n    exact not_irreducible_zero\n  else fun hx => Irreducible.not_unit hx <| isUnit_C.2 <| isUnit_iff_ne_zero.2 H\nset_option linter.uppercaseLean3 false in\n#align polynomial.not_irreducible_C Polynomial.not_irreducible_c\n\ntheorem degree_pos_of_irreducible (hp : Irreducible p) : 0 < p.degree :=\n  lt_of_not_ge fun hp0 =>\n    have := eq_C_of_degree_le_zero hp0\n    not_irreducible_c (p.coeff 0) <| this \u25b8 hp\n#align polynomial.degree_pos_of_irreducible Polynomial.degree_pos_of_irreducible\n\n/- Porting note: factored out a have statement from isCoprime_of_is_root_of_eval_derivative_ne_zero \ninto multiple decls because the original proof was timing out -/\ntheorem X_sub_C_mul_divByMonic_eq_sub_modByMonic {K : Type _} [Field K] (f : K[X]) (a : K) :\n    (X - C a) * (f /\u2098 (X - C a)) = f - f %\u2098 (X - C a) := by\n  rw [eq_sub_iff_add_eq, \u2190 eq_sub_iff_add_eq', modByMonic_eq_sub_mul_div]\n  exact monic_X_sub_C a\n\n/- Porting note: factored out a have statement from isCoprime_of_is_root_of_eval_derivative_ne_zero \nbecause the original proof was timing out -/\ntheorem divByMonic_add_X_Sub_C_mul_derivate_divByMonic_eq_derivative\n    {K : Type _} [Field K] (f : K[X]) (a : K) :\n    f /\u2098 (X - C a) + (X - C a) * derivative (f /\u2098 (X - C a)) = derivative f := by\n  have key := by apply congrArg derivative <| X_sub_C_mul_divByMonic_eq_sub_modByMonic f a\n  rw [modByMonic_X_sub_C_eq_C_eval] at key\n  rw [derivative_mul,derivative_sub,derivative_X,derivative_sub] at key\n  rw [derivative_C,sub_zero,one_mul] at key\n  rw [derivative_C,sub_zero] at key\n  assumption\n\n/- Porting note: factored out another have statement from \nisCoprime_of_is_root_of_eval_derivative_ne_zero because the original proof was timing out -/\ntheorem X_sub_C_dvd_derivative_of_X_sub_C_dvd_divByMonic {K : Type _} [Field K] (f : K[X]) {a : K}\n    (hf : (X - C a) \u2223 f /\u2098 (X - C a)) : X - C a \u2223 derivative f := by\n  have key := divByMonic_add_X_Sub_C_mul_derivate_divByMonic_eq_derivative f a\n  have \u27e8u,hu\u27e9 := hf\n  rw [\u2190key,hu,\u2190mul_add (X - C a) u _]\n  use (u + derivative ((X - C a) * u))\n\n/-- If `f` is a polynomial over a field, and `a : K` satisfies `f' a \u2260 0`,\nthen `f / (X - a)` is coprime with `X - a`.\nNote that we do not assume `f a = 0`, because `f / (X - a) = (f - f a) / (X - a)`. -/\ntheorem isCoprime_of_is_root_of_eval_derivative_ne_zero {K : Type _} [Field K] (f : K[X]) (a : K)\n    (hf' : f.derivative.eval a \u2260 0) : IsCoprime (X - C a : K[X]) (f /\u2098 (X - C a)) := by\n  refine Or.resolve_left\n      (EuclideanDomain.dvd_or_coprime (X - C a) (f /\u2098 (X - C a))\n        (irreducible_of_degree_eq_one (Polynomial.degree_X_sub_C a))) ?_\n  contrapose! hf' with h\n  have : X - C a \u2223 derivative f := X_sub_C_dvd_derivative_of_X_sub_C_dvd_divByMonic f h\n  rw [\u2190 dvd_iff_modByMonic_eq_zero (monic_X_sub_C _), modByMonic_X_sub_C_eq_C_eval] at this\n  rw [\u2190 C_inj, C_0]\n  assumption\n#align polynomial.is_coprime_of_is_root_of_eval_derivative_ne_zero Polynomial.isCoprime_of_is_root_of_eval_derivative_ne_zero\n\nend Field\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/FieldDivision.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7107137112060644}}
{"text": "variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable r : Prop\n\nexample : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) :=\n    assume y: \u03b1,\n    iff.intro\n        (\n            assume h: (\u2200 x: \u03b1, r),\n            show r, from h y\n        )\n        (\n            assume h: r,\n            assume x: \u03b1,\n            h\n        )\n\n-- example : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r := sorry\n-- left to right requires classical logic\nexample : (\u2200 x, p x) \u2228 r \u2192 (\u2200 x, p x \u2228 r) :=\n    assume h: (\u2200 x, p x) \u2228 r,\n    or.elim h\n        (\n            assume h\u2081: \u2200 x, p x,\n            assume y: \u03b1,\n            or.intro_left r (h\u2081 y)\n        )\n        (\n            assume h\u2082: r,\n            assume y: \u03b1,\n            or.intro_right (p y) h\u2082\n        )\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\n    iff.intro\n        (\n            assume h: \u2200 x, r \u2192 p x,\n            assume hr: r,\n            assume y: \u03b1,\n            show p y, from (h y) hr\n        )\n        (\n            assume h: r \u2192 \u2200 x, p x,\n            assume y: \u03b1,\n            assume hr: r,\n            show p y, from (h hr) y\n        )\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/chap4_exercise2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7107137055621783}}
{"text": "import ..library.src_ordered_field\n\nnamespace mth1001\n\nnamespace myreal\n\nsection ordered\n\nvariables {R : Type} [myordered_field R]\n\nopen_locale classical\n\nopen myordered_field\n\n/-\nThe three basic axiom of an orderd field are:\n\n1. `trichotomy`,\n2. `pos_add_of_pos_of_pos`, and\n3. `pos_mul_of_pos_of_pos`,\n\nas exemplified below\n-/\n\nexample (x : R) : pos x \u2227 \u00acx = 0 \u2227 \u00acpos (-x)\n               \u2228 \u00acpos x \u2227 x = 0  \u2227 \u00acpos (-x)\n               \u2228 \u00acpos x \u2227 x \u2260 0 \u2227 pos (-x) := trichotomy x\n\nexample (x y : R) : pos x \u2192 pos y \u2192 pos (x + y) := pos_add_of_pos_of_pos x y\n\nexample (x y : R) : pos x \u2192 pos y \u2192 pos (x * y) := pos_mul_of_pos_of_pos x y\n\n-- In the example below, we see that the square of non-zero positive number is positive.\nexample (x : R) (h : x \u2260 (0 : R)) : pos (pow1 x 2) :=\nbegin\n  unfold pow1, -- Use the definition of exponentiation.\n  rcases trichotomy x with \u27e8hpx, _, _\u27e9 | \u27e8_, rfl, _\u27e9 | \u27e8_, _, hpnx\u27e9,\n  { rw one_mul, exact pos_mul_of_pos_of_pos _ _ hpx hpx, },\n  { rw mul_zero, contradiction, },\n  { rw [one_mul, \u2190neg_mul_neg_self],\n    exact pos_mul_of_pos_of_pos _ _ hpnx hpnx,},\nend\n\n-- Exercise 177:\n-- Use trichotomy on `(1 : R)`, as in the example above.\nlemma pos_one : pos (1 : R) :=\nbegin\n  sorry  \nend\n\n-- Below, we see that every non-zero natural number (seen as a term of type `R`) is positive.\nlemma pos_nat (n : \u2115) : n \u2260 0 \u2192 pos (n : R) :=\nbegin\n  induction n with k hk,\n  { intro _, contradiction, },\n  { intro _,\n    rw coe_nat_succ,\n    by_cases h\u2081 : k = 0,\n    { rw h\u2081,\n      change pos((0 : R) + (1 : R)),\n      rw zero_add,\n      exact pos_one, },\n    { exact pos_add_of_pos_of_pos _ _ (hk h\u2081) pos_one }, },\nend\n\n-- The lemmas below are used to work with the definition of `<`.\n\nlemma lt_iff_pos_sub (x y : R) : x < y \u2194 pos (y -x) := by refl\n\nlemma lt_iff_pos_neg (x y : R) : x < y \u2194 pos (y + -x) := by refl\n\n-- Exercise 178:\nlemma gt_zero_mul_of_gt_zero_of_gt_zero {a b : R} (h\u2081 : 0 < a) (h\u2082 : 0 < b) : 0 < a * b :=\nbegin\n  sorry  \nend\n\n-- Exercise 179:\nlemma neg_pos {x : R} : 0 < -x \u2194 x < 0:=\nbegin\n  repeat {rw lt_iff_pos_neg},\n  sorry  end\n\n-- Exercise 180:\nlemma trichotomy' (x y: R) : x < y \u2227 \u00acx = y \u2227 \u00acy < x \u2228\n                               \u00acx < y \u2227 x = y \u2227 \u00acy < x \u2228\n                               \u00acx < y \u2227 \u00acx = y \u2227 y < x :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  have : x - y = -(y - x),\n  { sorry, }, \n  sorry  \nend\n\n-- Exercise 181:\nlemma lt_trans {x y z : R} : x < y \u2192 y < z \u2192 x < z :=\nbegin\n  repeat {rw lt_iff_pos_sub},\n  sorry  \nend\n\n-- Exercise 182:\nlemma add_lt_add_iff_right_mpr {x y : R} (z : R) : x < y \u2192 x + z < y + z :=\nbegin\n  sorry  \nend\n\n-- Exercise 183:\nlemma add_lt_add_iff_right_mp {x y : R} (z : R) : x + z < y + z \u2192 x < y :=\nbegin\n  sorry  \nend\n\n-- Exercise 184:\nlemma add_lt_add_iff_right {x y : R} (z : R) : x + z < y + z \u2194 x < y :=\nbegin\n  sorry  \nend\n\n-- Exercise 185:\ntheorem neg_lt_neg_iff  {a b : R} : -a < -b \u2194 b < a :=\nbegin\n  sorry  \nend\n\n-- Exercise 186:\nlemma mul_lt_mul_left_mpr {x y z : R} : 0 < z \u2192 x < y \u2192 z * x < z * y :=\nbegin\n  sorry  \nend\n\n-- Exercise 187:\ntheorem add_lt_add {a b c d : R} : a < b \u2192 c < d \u2192 a + c < b + d :=\nbegin\n  sorry  \nend\n\n-- Exercise 188:\nlemma lt_irrefl {x : R} : \u00acx < x :=\nbegin\n  sorry  \nend\n\n-- Exercise 189:\n-- Use `lt_irrefl` to prove the following.\ntheorem ne_of_gt {a b : R} (h : a > b) : a \u2260 b :=\nbegin\n  sorry  end\n\n-- The following lemma is used to work with the definition of `\u2264`.\n\nlemma le_iff_lt_or_eq {x y : R} : x \u2264 y \u2194 ((x < y) \u2228 x = y) := by refl\n\n-- Exercise 190:\nlemma le_refl (x : R) : x \u2264 x :=\nsorry \n\n-- Exercise 191:\n-- Though it looks complicated, you can fill in the `sorry` below using only the\n-- `split`, `intro`, and `exact` tactics (with and introduction and hypotheses).\nlemma not_le_iff_lt (x y : R) : \u00ac(x \u2264 y) \u2194 (y < x) :=\nbegin\n  rw le_iff_lt_or_eq,\n  push_neg,\n  rcases trichotomy' x y with \u27e8hxlty, _, _\u27e9 | \u27e8_, hxy, hnyltx \u27e9  | \u27e8hnxlty, hnxy, hxlty \u27e9 ,\n  { split,\n    { rintro \u27e8hnxy, _\u27e9,\n      contradiction, },\n    { intros hyltx, exfalso,\n      exact lt_irrefl (lt_trans hxlty hyltx), }, },\n  { split,\n    { rintro \u27e8_, hnxy\u27e9,\n      contradiction, },\n    { intro hyltx, contradiction, }, },\n  { sorry, }, \nend\n\n-- Exercise 192:\n-- Use `neg_le_iff_lt` to prove the result below.\nlemma not_lt_iff_le (x y : R) : \u00ac(x < y) \u2194 (y \u2264 x) :=\nsorry \n\n-- Exercise 193:\nlemma neg_nonneg {x : R} : 0 \u2264 -x \u2194 x \u2264 0 :=\nbegin\n  repeat {rw le_iff_lt_or_eq},\n  have k : 0 < -x \u2194 x < 0, from neg_pos,\n  sorry  \nend\n\n\n-- Exercise 194:\nlemma le_trans (x y z : R) : x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z :=\nbegin\n  rintro (h\u2081 | rfl) (h\u2082 | rfl),\n  { sorry, }, \n  { sorry, }, \n  { sorry, }, \n  { sorry, }, \nend\n\n-- Exercise 195:\nlemma lt_of_le_of_lt {a b c : R} (h\u2081 : a \u2264 b) (h\u2082 : b < c) : a < c :=\nbegin\n  sorry    \nend\n\n-- Exercise 196:\n-- Use `rcases trichotomy' x y` (see examples above) to prove the following.\nlemma le_total (x y : R) : x \u2264 y \u2228 y \u2264 x :=\nbegin\n  sorry  \nend\n\n\n-- Exercise 197:\nlemma anti_symm {x y : R} : x \u2264 y \u2192 y \u2264 x \u2192 x = y :=\nbegin\n  sorry  \nend\n\n-- Exercise 198:\ntheorem neg_le_neg_iff {a b : R} : -a \u2264 -b \u2194 b \u2264 a :=\nbegin\n  repeat {rw le_iff_lt_or_eq},\n  split,\n  { rintro (hlt | heq),\n    { left, rwa \u2190neg_lt_neg_iff, },\n    { right, rw [\u2190neg_neg a, heq, neg_neg], }, },\n  { sorry, }, \nend\n\n-- Exercise 199:\ntheorem add_le_add {a b c d : R} : a \u2264 b \u2192 c \u2264 d \u2192 a + c \u2264 b + d :=\nbegin\n  sorry  \nend\n\n-- Exercise 200:\ntheorem mul_self_non_neg (a : R) : 0 \u2264 a * a:=\nbegin\n  rcases trichotomy' 0 a with \u27e8posa, _\u27e9 | \u27e8_, eq0, _\u27e9 | \u27e8_, _, nega\u27e9,\n  { sorry, }, \n  { sorry, }, \n  { sorry, }, \nend\n\n-- Exercise 201:\nlemma non_neg_mul_of_non_neg_of_non_neg {a b : R} (h\u2081 : 0 \u2264 a) (h\u2082 : 0 \u2264 b) : 0 \u2264 a * b :=\nbegin\n  cases h\u2081 with apos aeq0,\n  { cases h\u2082 with bpos beq0,\n    { sorry, },  \n    { right, rw [\u2190beq0, mul_zero], }, },\n  { sorry, }, \nend\n\n-- Exercise 202:\nlemma non_neg_of_non_neg_mul_of_pos {x y : R} (h\u2081 : 0 \u2264 x * y) (h\u2082 : 0 < x) : 0 \u2264 y :=\nbegin\n  sorry  \nend\n\nlemma non_neg_mul_iff_non_neg_and_non_neg_or_non_pos_and_non_pos (a b : R)\n  : 0 \u2264 a * b \u2194 (0 \u2264 a \u2227 0 \u2264 b) \u2228 (a \u2264 0 \u2227 b \u2264 0) :=\nbegin\n  split,\n  { intro h\u2081,\n    by_cases h\u2082 : 0 \u2264 a,\n    { by_cases h\u2083 : a = 0,\n      { rw h\u2083,\n        exact or.elim (le_total b 0) (\u03bb h\u2084, or.inr \u27e8le_refl 0, h\u2084\u27e9) (\u03bb h\u2084, or.inl \u27e8le_refl 0, h\u2084\u27e9), },\n      { have h\u2084 : 0 < a, from or.elim h\u2082 id (\u03bb aeq0, absurd aeq0.symm h\u2083), \n        have h\u2085 : 0 \u2264 b, from non_neg_of_non_neg_mul_of_pos h\u2081 h\u2084,\n        exact or.inl \u27e8or.inl h\u2084, h\u2085\u27e9, }, },\n    { rw not_le_iff_lt at h\u2082,\n      right,\n      have k : b \u2264 0,\n      { by_contra h\u2083,\n        rw not_le_iff_lt at h\u2083,\n        rw \u2190neg_pos at h\u2082,\n        have h\u2084 : 0 < b * -a, from gt_zero_mul_of_gt_zero_of_gt_zero h\u2083 h\u2082,\n        rw [\u2190neg_mul_eq_mul_neg, mul_comm, neg_pos] at h\u2084,\n        exact lt_irrefl (lt_of_le_of_lt h\u2081 h\u2084), },\n      exact \u27e8or.inl h\u2082, k\u27e9, }, },\n  { rintro (\u27e8h\u2081, h\u2082\u27e9 | \u27e8h\u2081, h\u2082\u27e9),\n    { exact non_neg_mul_of_non_neg_of_non_neg h\u2081 h\u2082, },\n    { rw \u2190neg_mul_neg a b,\n      rw \u2190neg_nonneg at h\u2081 h\u2082,\n      exact non_neg_mul_of_non_neg_of_non_neg h\u2081 h\u2082, }, },\nend\n\n-- Exercise 203:\n-- Modify the proof of the second case to prove the first case.\ntheorem inv_pos {a : R}  (h : a \u2260 0) : 0 < a\u207b\u00b9 \u2194 0 < a :=\nbegin\n  split,\n  { sorry, }, \n  { intro k,\n    have h\u2082 : 0 \u2264 (a\u207b\u00b9 * a\u207b\u00b9), from mul_self_non_neg a\u207b\u00b9,\n    rw le_iff_lt_or_eq at h\u2082,\n    cases h\u2082 with posainvsq eq0,\n    { convert mul_lt_mul_left_mpr k posainvsq,\n      { rw mul_zero, },\n      { rw [\u2190mul_assoc, mul_inv a h, one_mul], }, },\n    { have h\u2083 : a\u207b\u00b9 = 0,\n      { cases eq_zero_or_eq_zero_of_mul_eq_zero _ _ eq0.symm;\n        assumption, },\n      exact absurd h\u2083 (inv_ne_zero h), }, },\nend\n\n-- Exercise 204:\ntheorem inv_lt_inv {a b : R} (h\u2081 : 0  < a) (h\u2082 : 0 < b) : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nbegin\n  split,\n  { sorry, }, \n  { intro h\u2083,\n    have h\u2085 : a \u2260 0, from ne_of_gt h\u2081,\n    have k\u2081 : a\u207b\u00b9 > 0, from (inv_pos h\u2085).mpr h\u2081,\n    have h\u2084 : a\u207b\u00b9 * b < a\u207b\u00b9 * a, from mul_lt_mul_left_mpr k\u2081 h\u2083, \n    rw inv_mul a h\u2085 at h\u2084,\n    have h\u2087 : b \u2260 0, from ne_of_gt h\u2082,\n    have k\u2082 : b\u207b\u00b9 > 0, from (inv_pos h\u2087).mpr h\u2082,\n    have h\u2086 :  b\u207b\u00b9 * (a\u207b\u00b9 * b) < b\u207b\u00b9 * 1, from mul_lt_mul_left_mpr k\u2082 h\u2084,\n    rw [mul_comm, mul_assoc, mul_inv b h\u2087, mul_one, mul_one] at h\u2086,\n    exact h\u2086, },\nend\n\nend ordered\n\nsection max_abs\n\nvariables {R : Type} [myordered_field R]\n\nopen_locale classical\n\nopen myordered_field\n\n/-\nThe absolute value `abs a` of `a : R` is defined to be by maximum of\n`a` and `-a`.\n-/\n\nexample (a : R) : abs a = max a (-a) := rfl\n\n/-\nBy definition, `max a b` is `a` if `b \u2264 a`, otherwise it is `b`.\n\nNote the use of `if_pos` and `if_neg` below to distiguish between the cases where\n`b \u2264 a` and `\u00ac(b \u2264 a)` in the definition of `max`.\n-/\n\nlemma le_max_left (a b : R) : a \u2264 max a b :=\nbegin\n  unfold max,\n  by_cases h : b \u2264 a,\n  { rw (if_pos h),\n    exact le_refl a, },\n  { rw (if_neg h),\n    rw not_le_iff_lt at h,\n    left, exact h, },\nend\n\n-- Exercise 205:\nlemma le_max_right (a b : R) : b \u2264 max a b :=\nbegin\n  unfold max,\n  by_cases h : b \u2264 a,\n  { rw (if_pos h),\n    sorry, }, \n  { rw (if_neg h),\n    sorry, }, \nend\n\n-- Exercise 206:\n-- Prove this using the template of the above two results.\nlemma max_choice (a b : R) : max a b = a \u2228 max a b = b :=\nbegin\n  sorry  \nend\n\nlemma neg_le_abs (a : R) : -a \u2264 abs a :=\nbegin\n  unfold abs max,\n  by_cases h : -a \u2264 a,\n  { rw (if_pos h), exact h, },\n  { rw (if_neg h), exact le_refl (-a), },\nend\n\n-- Exercise 207:\nlemma le_abs_self (a : R) : a \u2264 abs a :=\nbegin\n  sorry  \nend\n\n-- Exercise 208:\ntheorem triangle_inequality (x y : R) : abs (x + y) \u2264 abs x + abs y :=\nbegin\n  by_cases h : -(x+y) \u2264 x+y,\n  { have : abs (x+y) = x + y,\n    { unfold abs max,\n      rw (if_pos h), },\n    rw this,\n    have h\u2081 : x \u2264 abs x, from le_abs_self x,\n    have h\u2082 : y \u2264 abs y, from le_abs_self y,\n    exact add_le_add h\u2081 h\u2082, },\n  { sorry, }, \nend\n\nend max_abs\n\nsection upper_bounds_lower_bounds_sup\n\nopen myordered_field\n\nvariables {R : Type} [myordered_field R]\n\n/-\nHere are archetypal applications of the definitions of `upper_bound`, `lower_bound`,\n`bounded_above`, `bounded_below`, `bounded`, and `is_sup`.\n-/\n\nexample (u : R) (S : set R) (h : \u2200 s \u2208 S, s \u2264 u) : upper_bound u S := h\nexample (v : R) (S : set R) (h : \u2200 s \u2208 S, v \u2264 s) : lower_bound v S := h\nexample (S : set R) (h : \u2203 u : R, upper_bound u S) : bounded_above S := h\nexample (S : set R) (h : \u2203 v : R, lower_bound v S) : bounded_below S := h\nexample (S : set R) (h\u2081 : bounded_above S) (h\u2082 : bounded_below S) : bounded S := and.intro h\u2081 h\u2082\nexample (u : R) (S : set R) (h\u2081 : upper_bound u S) (h\u2082 : \u2200 v : R, upper_bound v S \u2192 u \u2264 v)\n: is_sup u S := and.intro h\u2081 h\u2082\n\n-- Exercise 209:\ntheorem sup_uniqueness (S : set R) (a b : R) (h\u2081 : is_sup a S) (h\u2082 : is_sup b S) : a = b :=\nbegin\n  cases h\u2081 with h\u2083 h\u2084,\n  cases h\u2082 with h\u2085 h\u2086,\n  apply anti_symm,\n  { sorry, }, \n  { sorry, }, \nend\n\n-- Exercise 210:\n-- In this example, we show _every_ real number `u` is an upper bound of the empty set.\ntheorem empty_set_upper_bound (u : R) : upper_bound u \u2205 :=\nbegin\n  sorry    \nend\n\n-- Exercise 211:\ntheorem empty_set_lower_bound (v : R) : lower_bound v \u2205 :=\nbegin\n  sorry  \nend\n\n-- Exercise 212:\n-- Given `S` a set of real numbers, given `s \u2208 S`, given `u` and `v` are upper and lower bounds\n-- of `S`, respectively, then `v \u2264 u`.\nexample (S : set R) (u v : R) (h\u2081 : upper_bound u S) (h\u2082 : lower_bound v S) (s : R) (h\u2083 : s \u2208 S)\n  : v \u2264 u :=\nbegin\n  sorry  \nend\n\n-- Exercise 213:\n-- However, it's *not true* that for every set `S` of real numbers, for all real numbers `u` and `v`,\n-- if `u` and `v` are upper and lower bounds of `S`, respectively, then `v \u2264 u`.\n-- Hint: start with `push_neg` and think of the results above.\nexample : \u00ac(\u2200 (S : set R), \u2200 u v : R, upper_bound u S \u2192 lower_bound v S \u2192 v \u2264 u) :=\nbegin\n  sorry  \nend\n\nend upper_bounds_lower_bounds_sup\n\nend myreal\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_36_order_axioms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7107136971396348}}
{"text": "-- Exercises\n-- #2\n\nopen classical\n\nvariables p q r s : Prop\n\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\nassume h : p \u2192 r \u2228 s,\nshow (p \u2192 r) \u2228 (p \u2192 s),\nfrom or.elim (em p)\n  (assume hp : p,\n    have hrs : r \u2228 s := h hp,\n    or.elim hrs\n    (assume hr : r, or.inl (\u03bb hp' : p, hr))\n    (assume hs : s, or.inr (\u03bb hp' : p, hs))\n  )\n  (assume hnp : \u00acp,\n    or.inl (assume hp : p, show r, from absurd hp hnp)\n  )\n\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n  assume h : \u00ac(p \u2227 q),\n  show \u00acp \u2228 \u00acq,\n  from or.elim (em p)\n  (assume hp : p,\n    have hnq : \u00acq,\n    from (assume hq : q, h \u27e8hp, hq\u27e9), \n    or.inr hnq\n  )\n  (assume hnp : \u00acp, or.inl hnp)\n\n-- I need lemma1 and dne to prove the next example\n-- This seems too complicated.\n-- Is there a shorter proof of \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq?\nlemma lemma1 {p q : Prop} (h : \u00acq \u2192 \u00acp) : p \u2192 q :=\n  show p \u2192 q,\n  from assume hp : p,\n    or.elim (em q)\n      (assume hq : q, hq)\n      (assume hnq : \u00acq, absurd hp (h hnq))\n\ntheorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : \u00acp, absurd hnp h)\n\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\nassume h : \u00ac(p \u2192 q),\nhave hnq : \u00acq := (\u03bb hq : q, h (\u03bb hp : p, hq)),\nsuffices hp : p, from \u27e8hp, hnq\u27e9,\nshow p, \nfrom have hdnp : \u00ac\u00acp :=\n  (assume hnp: \u00acp,\n    have hnqnp : \u00acq \u2192 \u00acp := (\u03bb hnq' : \u00acq, hnp),\n    have hpq : p \u2192 q := lemma1 hnqnp,\n    show false, from (h hpq)\n  ),\n  dne hdnp\n\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\nassume h : p \u2192 q,\nor.elim (em p)\n(assume hp : p, or.inr (h hp))\n(assume hnp : \u00acp, or.inl hnp)\n\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\nassume h : \u00acq \u2192 \u00acp, lemma1 h\n\nexample : p \u2228 \u00acp := em p\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) :=\nassume h : (p \u2192 q) \u2192 p,\nor.elim (em q)\n(assume hq : q, h (assume hp : p, hq))\n(assume hnq : \u00acq,\n  dne (assume hnp: \u00acp,\n    have hnqnp : \u00acq \u2192 \u00acp := (\u03bb hnq', hnp),\n    have hpq : p \u2192 q := lemma1 hnqnp,\n    show false,\n    from hnp (h hpq)\n  )\n)\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/03-Propositions-and-Proofs/example-3.7-2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7107136962422732}}
{"text": "import data.set.basic\n/- \nTactics you may consider \n-intro(s)\n-apply\n-exact\n-/\n\nvariables {\u03b1 : Type*} (r s t : set \u03b1)\n\nexample : s \u2286 s :=\nby { intros x xs, exact xs }\n\ntheorem subset.refl : s \u2286 s := \u03bb x xs, xs\n\nexample : r \u2286 s \u2192 s \u2286 t \u2192 r \u2286 t :=\nbegin\n  intros rs st x xr,\n  apply st,\n  apply rs,\n  exact xr,\nend\n\ntheorem subset.trans : r \u2286 s \u2192 s \u2286 t \u2192 r \u2286 t := \nbegin\n  intros rs st x xr,\n  exact st (rs xr), \nend\n", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/2_intro(s)/ex6_intro_vari_h_subset_trans.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7107055242137985}}
{"text": "universe u\nvariables (\u03b1 : Type u) (a b c d : \u03b1)\nvariables (hab : a = b) (hcb : c = b) (hcd : c = d)\n\nexample : a = d := (hab.trans hcb.symm).trans hcd\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0204.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7107055193812897}}
{"text": "/-\nWarmup: Function composition.\n-/\n\n/-\nIf we know that P implies Q and that Q\nimplies R, we can conclude that P \u2192 R.\nThe name, \"hypothetical syllogism\", or\n\"chain rule\" is given to this reasoning\nprinciple.\n\nHere's an example.\n\nSuppose P \u2192 Q express the idea that \"if \nit's raining then the streets are wet, \nand Q \u2192 R, \"if the streets are wet then \nit takes longer to stop.\" We can deduce \n\"if it's raining then it takes longer \nto stop.\n\nThis rule is sometimes called the chain\nrule. It also shows that implication is\ntransitive. We can write it explicitly\nas an inference rule:\n\n\n{ P Q : Prop } (pq : P \u2192 Q) (qr : Q \u2192 R) \n---------------------------------------- chain\n              pr : (P \u2192 R)\n\n\nWe can also verify that it's a valid \nrule by proving it. The proof will be\na function that takes P, Q, R, pq, and\nqr as arguments and that derives a proof,\npr, of P \u2192 Q, the latter also a function\nthat assumes a proof of P and derives a\nproof of R. \n-/\n\ndef chain : \u2200 { P Q R : Prop }, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) := \n        /-\n        To prove this proposition, we ...\n        -/\n \n        /-\n        assume P, Q, and R are propositions...\n        -/\n        (\u03bb P : Prop, \n        (\u03bb Q : Prop,\n        (\u03bb R : Prop,\n        \n        /-\n        and assume we're given proofs of P \u2192 Q and Q \u2192 P\n        -/\n        (\u03bb pq : P \u2192 Q,\n        (\u03bb qr : Q \u2192 R,\n\n        /-\n        Now we show P \u2192 R by ...\n        first assuming a proof of P ...\n        -/\n        (\u03bb p : P,\n\n        /-\n        then deriving a proof of R.\n        -/\n        qr (pq p) \n\n        ) ) ) ) ) )\n\n/-\nNow we explain how we can simplify this\nexpression by letting Lean infer types\nand figure out grouping of expressions\non its own, without the parentheses.\n-/\n\n\n/-\nWe can leave out the explicit types and let\nLean infer them from context.\n-/\n\ndef chain' : \u2200 { P Q R : Prop }, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) := \n        (\u03bb P, (\u03bb Q, (\u03bb R, (\u03bb pq,(\u03bb qr, (\u03bb p, qr (pq p) ) ) ) ) ) )\n\n\n/-\nWe also don't need the parenthesis, as the\nlambda expressions associate to the right in\nany case.\n-/\ndef chain'' : \u2200 { P Q R : Prop }, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) := \n        \u03bb P, \u03bb Q, \u03bb R, \u03bb pq, \u03bb qr, \u03bb p, qr (pq p)\n\n/- Finally, Lean lets us use a single \u03bb followed \nby names for multiple arguments, giving us the\nsimplest statement of this theorem. \n-/\n\ndef chain''' : \u2200 { P Q R : Prop }, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) := \n        \u03bb P Q R pq qr p, qr (pq p)  \n\n/-\nTo make the logic a little clearer, we could \ninsert a lambda as follows. This might help\nthe reader by making it clearer that in the\ncontext of P, Q, R, pq, and pr, we can derive\nof a proof of P \u2192 R in the form of a function\nthat takes a proof, p : P and derives a proof\nof R.\n-/\ndef chain'''' : \u2200 { P Q R : Prop }, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) := \n        \u03bb P Q R pq qr, \n                \u03bb  p, qr (pq p)  \n\n/-\nWe could also write the proof as a tactic script.\n-/\n\ndef chain_tactic : \u2200 { P Q R : Prop }, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n        assume P Q R: Prop,\n        assume pq : P \u2192 Q,\n        assume qr : Q \u2192 R,\n        show P \u2192 R, \n        from\n                begin\n                assume p : P,\n                show R,\n                from qr (pq p) \n                end\nend\n\n/-\nWe can leave out the explicit types and run\nall the assume lines together here, as well,\nyielding this more concise, albeit perhaps\nless immediately understandable, script.\n-/\ndef chain_tactic' : \u2200 { P Q R : Prop }, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n        assume P Q R pq qr,\n        show P \u2192 R,\n        from \n        begin \n                assume p,\n                show R,\n                from qr (pq p)\n        end\nend\n\n/-\nFinally, you can write the same theorem in \nthe form of an ordinary function definition,\nin which case assumptions are represented as\narguments, the return type is made explicit,\nand the body of the function is just as it\nis in all the preceding examples. The return\ntype could be left implicit, but that would \nmake the code harder to understand, as it'd \nforce the reader to figure out the type of \nthe expression, qr (pq p).\n-/\n\ndef chain_prog (P Q R : Prop) (pq: (P \u2192 Q)) (qr: Q \u2192 R) (p : P): R :=\n        qr (pq p) \n\n\n/-\n-/\n\nvariables P Q R : Prop\nvariable pq : P \u2192 Q\nvariable qr : P \u2192 R\n\ntheorem pr : P \u2192 R :=\nbegin\napply chain Q,\nend\n\n\n\ndef compose { P Q R : Prop } (pq : P \u2194 Q) (qr: Q \u2194 R) \n        : P \u2194 R :=\n        iff.intro\n                (compose (qr.left) (pq.left) )\n                (compose (qr.right) (qr.left) )\n\n\n/-\ndef iff_compose (P Q R: Prop) (pq: P \u2194 Q) (qr: Q \u2194 R) : P \u2194 R :=\n        iff.intro \n                (compose ) \n                _\n-/\n\n/-\nEXERCISE:\n\nProve that \u2194 is transitive. That is, if you\nassume P, Q and R are arbitrary propositions, \nand that you have proof of P \u2194 Q and of Q \u2194 R,\nthen you can derive a proof of P \u2194 R.\n-/\n\n\n\n/-\nProve \u2200 P : Prop, P \u2194 (P \u2192 P)\n-/\n\n\n\ntheorem foo: \u2200 P : Prop, P \u2194 (P \u2192 P),\n        assume (P : Prop) (pfbi: P \u2194 (P \u2192 P)),\n        have forward := pfbi.left,        \n        have backward := pfbi.right,\n\n\n\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm", "sha": "bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c", "save_path": "github-repos/lean/kevinsullivan-cs-dm", "path": "github-repos/lean/kevinsullivan-cs-dm/cs-dm-bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c/08_Bi_implication/01_exercise_chain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7106941703986838}}
{"text": "-- Diferencia_de_diferencia_de_conjuntos.lean\n-- Diferencia de diferencia de conjuntos\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 23-abril-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    (s \\ t) \\ u \u2286 s \\ (t \u222a u)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t u : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x hx,\n  cases hx with hxst hxnu,\n  cases hxst with hxs hxnt,\n  split,\n  { exact hxs },\n  { dsimp,\n    by_contradiction hxtu,\n    cases hxtu with hxt hxu,\n    { apply hxnt,\n      exact hxt, },\n    { apply hxnu,\n      exact hxu, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8hxs, hxnt\u27e9, hxnu\u27e9,\n  split,\n  { exact hxs },\n  { by_contradiction hxtu,\n    cases hxtu with hxt hxu,\n    { exact hxnt hxt, },\n    { exact hxnu hxu, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8xs, xnt\u27e9, xnu\u27e9,\n  use xs,\n  rintros (xt | xu),\n  { contradiction, },\n  { contradiction, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8xs, xnt\u27e9, xnu\u27e9,\n  use xs,\n  rintros (xt | xu); contradiction,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x xstu,\n  simp at *,\n  finish,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x xstu,\n  finish,\nend\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nby rw diff_diff\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nby tidy\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Diferencia_de_diferencia_de_conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.710694155536839}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport algebra.group_with_zero.power\nimport data.list.prod_monoid\nimport data.multiset.basic\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `multiset.prod`: `s.prod f` is the product of `f i` over all `i \u2208 s`. Not to be mistaken with\n  the cartesian product `multiset.product`.\n* `multiset.sum`: `s.sum f` is the sum of `f i` over all `i \u2208 s`.\n-/\n\nvariables {\u03b9 \u03b1 \u03b2 \u03b3 : Type*}\n\nnamespace multiset\nsection comm_monoid\nvariables [comm_monoid \u03b1] {s t : multiset \u03b1} {a : \u03b1} {m : multiset \u03b9} {f g : \u03b9 \u2192 \u03b1}\n\n/-- Product of a multiset given a commutative monoid structure on `\u03b1`.\n  `prod {a, b, c} = a * b * c` -/\n@[to_additive \"Sum of a multiset given a commutative additive monoid structure on `\u03b1`.\n  `sum {a, b, c} = a + b + c`\"]\ndef prod : multiset \u03b1 \u2192 \u03b1 := foldr (*) (\u03bb x y z, by simp [mul_left_comm]) 1\n\n@[to_additive]\nlemma prod_eq_foldr (s : multiset \u03b1) :  prod s = foldr (*) (\u03bb x y z, by simp [mul_left_comm]) 1 s :=\nrfl\n\n@[to_additive]\nlemma prod_eq_foldl (s : multiset \u03b1) : prod s = foldl (*) (\u03bb x y z, by simp [mul_right_comm]) 1 s :=\n(foldr_swap _ _ _ _).trans (by simp [mul_comm])\n\n@[simp, norm_cast, to_additive] lemma coe_prod (l : list \u03b1) : prod \u2191l = l.prod := prod_eq_foldl _\n\n@[simp, to_additive]\nlemma prod_to_list (s : multiset \u03b1) : s.to_list.prod = s.prod :=\nbegin\n  conv_rhs { rw \u2190coe_to_list s },\n  rw coe_prod,\nend\n\n@[simp, to_additive] lemma prod_zero : @prod \u03b1 _ 0 = 1 := rfl\n\n@[simp, to_additive]\nlemma prod_cons (a : \u03b1) (s) : prod (a ::\u2098 s) = a * prod s := foldr_cons _ _ _ _ _\n\n@[simp, to_additive]\nlemma prod_singleton (a : \u03b1) : prod {a} = a :=\nby simp only [mul_one, prod_cons, singleton_eq_cons, eq_self_iff_true, prod_zero]\n\n@[simp, to_additive]\nlemma prod_add (s t : multiset \u03b1) : prod (s + t) = prod s * prod t :=\nquotient.induction_on\u2082 s t $ \u03bb l\u2081 l\u2082, by simp\n\nlemma prod_nsmul (m : multiset \u03b1) : \u2200 (n : \u2115), (n \u2022 m).prod = m.prod ^ n\n| 0       := by { rw [zero_nsmul, pow_zero], refl }\n| (n + 1) :=\n  by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul n]\n\n@[simp, to_additive] lemma prod_repeat (a : \u03b1) (n : \u2115) : (repeat a n).prod = a ^ n :=\nby simp [repeat, list.prod_repeat]\n\n@[to_additive nsmul_count]\nlemma pow_count [decidable_eq \u03b1] (a : \u03b1) : a ^ s.count a = (s.filter (eq a)).prod :=\nby rw [filter_eq, prod_repeat]\n\n@[to_additive]\nlemma prod_hom [comm_monoid \u03b2] (s : multiset \u03b1) (f : \u03b1 \u2192* \u03b2) : (s.map f).prod = f s.prod :=\nquotient.induction_on s $ \u03bb l, by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n\n@[to_additive]\nlemma prod_hom' [comm_monoid \u03b2] (s : multiset \u03b9) (f : \u03b1 \u2192* \u03b2) (g : \u03b9 \u2192 \u03b1) :\n  (s.map $ \u03bb i, f $ g i).prod = f (s.map g).prod :=\nby { convert (s.map g).prod_hom f, exact (map_map _ _ _).symm }\n\n@[to_additive]\nlemma prod_hom\u2082 [comm_monoid \u03b2] [comm_monoid \u03b3] (s : multiset \u03b9) (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3)\n  (hf : \u2200 a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f\u2081 : \u03b9 \u2192 \u03b1) (f\u2082 : \u03b9 \u2192 \u03b2) :\n  (s.map $ \u03bb i, f (f\u2081 i) (f\u2082 i)).prod = f (s.map f\u2081).prod (s.map f\u2082).prod :=\nquotient.induction_on s $ \u03bb l,\n  by simp only [l.prod_hom\u2082 f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n\n@[to_additive]\nlemma prod_hom_rel [comm_monoid \u03b2] (s : multiset \u03b9) {r : \u03b1 \u2192 \u03b2 \u2192 Prop} {f : \u03b9 \u2192 \u03b1} {g : \u03b9 \u2192 \u03b2}\n  (h\u2081 : r 1 1) (h\u2082 : \u2200 \u2983a b c\u2984, r b c \u2192 r (f a * b) (g a * c)) :\n  r (s.map f).prod (s.map g).prod :=\nquotient.induction_on s $ \u03bb l,\n  by simp only [l.prod_hom_rel h\u2081 h\u2082, quot_mk_to_coe, coe_map, coe_prod]\n\n@[to_additive]\nlemma prod_map_one : prod (m.map (\u03bb i, (1 : \u03b1))) = 1 := by rw [map_const, prod_repeat, one_pow]\n\n@[simp, to_additive]\nlemma prod_map_mul : (m.map $ \u03bb i, f i * g i).prod = (m.map f).prod * (m.map g).prod :=\nm.prod_hom\u2082 (*) mul_mul_mul_comm (mul_one _) _ _\n\n@[to_additive sum_map_nsmul]\nlemma prod_map_pow {n : \u2115} : (m.map $ \u03bb i, f i ^ n).prod = (m.map f).prod ^ n :=\nm.prod_hom' (pow_monoid_hom n) _\n\n@[to_additive]\nlemma prod_map_prod_map (m : multiset \u03b2) (n : multiset \u03b3) {f : \u03b2 \u2192 \u03b3 \u2192 \u03b1} :\n  prod (m.map $ \u03bb a, prod $ n.map $ \u03bb b, f a b) = prod (n.map $ \u03bb b, prod $ m.map $ \u03bb a, f a b) :=\nmultiset.induction_on m (by simp) (\u03bb a m ih, by simp [ih])\n\n@[to_additive]\nlemma prod_induction (p : \u03b1 \u2192 Prop) (s : multiset \u03b1) (p_mul : \u2200 a b, p a \u2192 p b \u2192 p (a * b))\n  (p_one : p 1) (p_s : \u2200 a \u2208 s, p a) :\n  p s.prod :=\nbegin\n  rw prod_eq_foldr,\n  exact foldr_induction (*) (\u03bb x y z, by simp [mul_left_comm]) 1 p s p_mul p_one p_s,\nend\n\n@[to_additive]\nlemma prod_induction_nonempty (p : \u03b1 \u2192 Prop) (p_mul : \u2200 a b, p a \u2192 p b \u2192 p (a * b))\n  (hs : s \u2260 \u2205) (p_s : \u2200 a \u2208 s, p a) :\n  p s.prod :=\nbegin\n  revert s,\n  refine multiset.induction _ _,\n  { intro h,\n    exfalso,\n    simpa using h },\n  intros a s hs hsa hpsa,\n  rw prod_cons,\n  by_cases hs_empty : s = \u2205,\n  { simp [hs_empty, hpsa a] },\n  have hps : \u2200 x, x \u2208 s \u2192 p x, from \u03bb x hxs, hpsa x (mem_cons_of_mem hxs),\n  exact p_mul a s.prod (hpsa a (mem_cons_self a s)) (hs hs_empty hps),\nend\n\nlemma dvd_prod : a \u2208 s \u2192 a \u2223 s.prod :=\nquotient.induction_on s (\u03bb l a h, by simpa using list.dvd_prod h) a\n\nlemma prod_dvd_prod_of_le (h : s \u2264 t) : s.prod \u2223 t.prod :=\nbegin\n  obtain \u27e8z, rfl\u27e9 := multiset.le_iff_exists_add.1 h,\n  simp only [prod_add, dvd_mul_right],\nend\n\nend comm_monoid\n\nlemma prod_dvd_prod_of_dvd [comm_monoid \u03b2] {S : multiset \u03b1} (g1 g2 : \u03b1 \u2192 \u03b2)\n  (h : \u2200 a \u2208 S, g1 a \u2223 g2 a) :\n  (multiset.map g1 S).prod \u2223 (multiset.map g2 S).prod :=\nbegin\n  apply multiset.induction_on' S, { simp },\n  intros a T haS _ IH,\n  simp [mul_dvd_mul (h a haS) IH]\nend\n\n\nsection add_comm_monoid\nvariables [add_comm_monoid \u03b1]\n\n/-- `multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`add_comm_monoid`s. -/\ndef sum_add_monoid_hom : multiset \u03b1 \u2192+ \u03b1 :=\n{ to_fun := sum,\n  map_zero' := sum_zero,\n  map_add' := sum_add }\n\n@[simp] lemma coe_sum_add_monoid_hom : (sum_add_monoid_hom : multiset \u03b1 \u2192 \u03b1) = sum := rfl\n\nend add_comm_monoid\n\nsection comm_monoid_with_zero\nvariables [comm_monoid_with_zero \u03b1]\n\nlemma prod_eq_zero {s : multiset \u03b1} (h : (0 : \u03b1) \u2208 s) : s.prod = 0 :=\nbegin\n  rcases multiset.exists_cons_of_mem h with \u27e8s', hs'\u27e9,\n  simp [hs', multiset.prod_cons]\nend\n\nvariables [no_zero_divisors \u03b1] [nontrivial \u03b1] {s : multiset \u03b1}\n\nlemma prod_eq_zero_iff : s.prod = 0 \u2194 (0 : \u03b1) \u2208 s :=\nquotient.induction_on s $ \u03bb l, by { rw [quot_mk_to_coe, coe_prod], exact list.prod_eq_zero_iff }\n\nlemma prod_ne_zero (h : (0 : \u03b1) \u2209 s) : s.prod \u2260 0 := mt prod_eq_zero_iff.1 h\n\nend comm_monoid_with_zero\n\nsection comm_group\nvariables [comm_group \u03b1] {m : multiset \u03b9} {f g : \u03b9 \u2192 \u03b1}\n\n@[simp, to_additive]\nlemma prod_map_inv' : (m.map $ \u03bb i, (f i)\u207b\u00b9).prod = (m.map f).prod \u207b\u00b9 :=\nby { convert (m.map f).prod_hom comm_group.inv_monoid_hom, rw map_map, refl }\n\n@[simp, to_additive]\nlemma prod_map_div : (m.map $ \u03bb i, f i / g i).prod = (m.map f).prod / (m.map g).prod :=\nm.prod_hom\u2082 (/) mul_div_comm' (div_one' _) _ _\n\n@[to_additive]\nlemma prod_map_zpow {n : \u2124} : (m.map $ \u03bb i, f i ^ n).prod = (m.map f).prod ^ n :=\nby { convert (m.map f).prod_hom (zpow_group_hom _), rw map_map, refl }\n\n@[simp] lemma coe_inv_monoid_hom : (comm_group.inv_monoid_hom : \u03b1 \u2192 \u03b1) = has_inv.inv := rfl\n\n@[simp, to_additive]\nlemma prod_map_inv (m : multiset \u03b1) : (m.map has_inv.inv).prod = m.prod\u207b\u00b9 :=\nm.prod_hom comm_group.inv_monoid_hom\n\nend comm_group\n\nsection comm_group_with_zero\nvariables [comm_group_with_zero \u03b1] {m : multiset \u03b9} {f g : \u03b9 \u2192 \u03b1}\n\n@[simp]\nlemma prod_map_inv\u2080 : (m.map $ \u03bb i, (f i)\u207b\u00b9).prod = (m.map f).prod \u207b\u00b9 :=\nby { convert (m.map f).prod_hom inv_monoid_with_zero_hom.to_monoid_hom, rw map_map, refl }\n\n@[simp]\nlemma prod_map_div\u2080 : (m.map $ \u03bb i, f i / g i).prod = (m.map f).prod / (m.map g).prod :=\nm.prod_hom\u2082 (/) (\u03bb _ _ _ _, (div_mul_div _ _ _ _).symm) (div_one _) _ _\n\nlemma prod_map_zpow\u2080 {n : \u2124} : prod (m.map $ \u03bb i, f i ^ n) = (m.map f).prod ^ n :=\nby { convert (m.map f).prod_hom (zpow_group_hom\u2080 _), rw map_map, refl }\n\nend comm_group_with_zero\n\nsection semiring\nvariables [semiring \u03b1] {a : \u03b1} {s : multiset \u03b9} {f : \u03b9 \u2192 \u03b1}\n\nlemma sum_map_mul_left : sum (s.map (\u03bb i, a * f i)) = a * sum (s.map f) :=\nmultiset.induction_on s (by simp) (\u03bb i s ih, by simp [ih, mul_add])\n\nlemma sum_map_mul_right : sum (s.map (\u03bb i, f i * a)) = sum (s.map f) * a :=\nmultiset.induction_on s (by simp) (\u03bb a s ih, by simp [ih, add_mul])\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring \u03b1]\n\nlemma dvd_sum {a : \u03b1} {s : multiset \u03b1} : (\u2200 x \u2208 s, a \u2223 x) \u2192 a \u2223 s.sum :=\nmultiset.induction_on s (\u03bb _, dvd_zero _)\n  (\u03bb x s ih h, by { rw sum_cons, exact dvd_add\n    (h _ (mem_cons_self _ _)) (ih $ \u03bb y hy, h _ $ mem_cons.2 $ or.inr hy) })\n\nend comm_semiring\n\n/-! ### Order -/\n\nsection ordered_comm_monoid\nvariables [ordered_comm_monoid \u03b1] {s t : multiset \u03b1} {a : \u03b1}\n\n@[to_additive sum_nonneg]\nlemma one_le_prod_of_one_le : (\u2200 x \u2208 s, (1 : \u03b1) \u2264 x) \u2192 1 \u2264 s.prod :=\nquotient.induction_on s $ \u03bb l hl, by simpa using list.one_le_prod_of_one_le hl\n\n@[to_additive]\nlemma single_le_prod : (\u2200 x \u2208 s, (1 : \u03b1) \u2264 x) \u2192 \u2200 x \u2208 s, x \u2264 s.prod :=\nquotient.induction_on s $ \u03bb l hl x hx, by simpa using list.single_le_prod hl x hx\n\n@[to_additive]\nlemma prod_le_of_forall_le (s : multiset \u03b1) (n : \u03b1) (h : \u2200 x \u2208 s, x \u2264 n) : s.prod \u2264 n ^ s.card :=\nbegin\n  induction s using quotient.induction_on,\n  simpa using list.prod_le_of_forall_le _ _ h,\nend\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\nlemma all_one_of_le_one_le_of_prod_eq_one :\n  (\u2200 x \u2208 s, (1 : \u03b1) \u2264 x) \u2192 s.prod = 1 \u2192 \u2200 x \u2208 s, x = (1 : \u03b1) :=\nbegin\n  apply quotient.induction_on s,\n  simp only [quot_mk_to_coe, coe_prod, mem_coe],\n  exact \u03bb l, list.all_one_of_le_one_le_of_prod_eq_one,\nend\n\n@[to_additive]\nlemma prod_le_prod_of_rel_le (h : s.rel (\u2264) t) : s.prod \u2264 t.prod :=\nbegin\n  induction h with _ _ _ _ rh _ rt,\n  { refl },\n  { rw [prod_cons, prod_cons],\n    exact mul_le_mul' rh rt }\nend\n\n@[to_additive]\nlemma prod_map_le_prod (f : \u03b1 \u2192 \u03b1) (h : \u2200 x, x \u2208 s \u2192 f x \u2264 x) : (s.map f).prod \u2264 s.prod :=\nprod_le_prod_of_rel_le $ rel_map_left.2 $ rel_refl_of_refl_on h\n\n@[to_additive]\nlemma prod_le_sum_prod (f : \u03b1 \u2192 \u03b1) (h : \u2200 x, x \u2208 s \u2192 x \u2264 f x) : s.prod \u2264 (s.map f).prod :=\n@prod_map_le_prod (order_dual \u03b1) _ _ f h\n\n@[to_additive card_nsmul_le_sum]\nlemma pow_card_le_prod (h : \u2200 x \u2208 s, a \u2264 x) : a ^ s.card \u2264 s.prod :=\nby { rw [\u2190multiset.prod_repeat, \u2190multiset.map_const], exact prod_map_le_prod _ h }\n\n@[to_additive sum_le_card_nsmul]\nlemma prod_le_pow_card (h : \u2200 x \u2208 s, x \u2264 a) : s.prod \u2264 a ^ s.card :=\n@pow_card_le_prod (order_dual \u03b1) _ _ _ h\n\nend ordered_comm_monoid\n\nlemma prod_nonneg [ordered_comm_semiring \u03b1] {m : multiset \u03b1} (h : \u2200 a \u2208 m, (0 : \u03b1) \u2264 a) :\n  0 \u2264 m.prod :=\nbegin\n  revert h,\n  refine m.induction_on _ _,\n  { rintro -, rw prod_zero, exact zero_le_one },\n  intros a s hs ih,\n  rw prod_cons,\n  exact mul_nonneg (ih _ $ mem_cons_self _ _) (hs $ \u03bb a ha, ih _ $ mem_cons_of_mem ha),\nend\n\n@[to_additive]\nlemma prod_eq_one_iff [canonically_ordered_monoid \u03b1] {m : multiset \u03b1} :\n  m.prod = 1 \u2194 \u2200 x \u2208 m, x = (1 : \u03b1) :=\nquotient.induction_on m $ \u03bb l, by simpa using list.prod_eq_one_iff l\n\n@[to_additive]\nlemma le_prod_of_mem [canonically_ordered_monoid \u03b1] {m : multiset \u03b1} {a : \u03b1} (h : a \u2208 m) :\n  a \u2264 m.prod :=\nbegin\n  obtain \u27e8m', rfl\u27e9 := exists_cons_of_mem h,\n  rw [prod_cons],\n  exact _root_.le_mul_right (le_refl a),\nend\n\n@[to_additive le_sum_of_subadditive_on_pred]\nlemma le_prod_of_submultiplicative_on_pred [comm_monoid \u03b1] [ordered_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (p : \u03b1 \u2192 Prop) (h_one : f 1 = 1) (hp_one : p 1)\n  (h_mul : \u2200 a b, p a \u2192 p b \u2192 f (a * b) \u2264 f a * f b)\n  (hp_mul : \u2200 a b, p a \u2192 p b \u2192 p (a * b)) (s : multiset \u03b1) (hps : \u2200 a, a \u2208 s \u2192 p a) :\n  f s.prod \u2264 (s.map f).prod :=\nbegin\n  revert s,\n  refine multiset.induction _ _,\n  { simp [le_of_eq h_one] },\n  intros a s hs hpsa,\n  have hps : \u2200 x, x \u2208 s \u2192 p x, from \u03bb x hx, hpsa x (mem_cons_of_mem hx),\n  have hp_prod : p s.prod, from prod_induction p s hp_mul hp_one hps,\n  rw [prod_cons, map_cons, prod_cons],\n  exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _),\nend\n\n@[to_additive le_sum_of_subadditive]\nlemma le_prod_of_submultiplicative [comm_monoid \u03b1] [ordered_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (h_one : f 1 = 1) (h_mul : \u2200 a b, f (a * b) \u2264 f a * f b) (s : multiset \u03b1) :\n  f s.prod \u2264 (s.map f).prod :=\nle_prod_of_submultiplicative_on_pred f (\u03bb i, true) h_one trivial (\u03bb x y _ _ , h_mul x y) (by simp)\n  s (by simp)\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\nlemma le_prod_nonempty_of_submultiplicative_on_pred [comm_monoid \u03b1] [ordered_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (p : \u03b1 \u2192 Prop) (h_mul : \u2200 a b, p a \u2192 p b \u2192 f (a * b) \u2264 f a * f b)\n  (hp_mul : \u2200 a b, p a \u2192 p b \u2192 p (a * b)) (s : multiset \u03b1) (hs_nonempty : s \u2260 \u2205)\n  (hs : \u2200 a, a \u2208 s \u2192 p a) :\n  f s.prod \u2264 (s.map f).prod :=\nbegin\n  revert s,\n  refine multiset.induction _ _,\n  { intro h,\n    exfalso,\n    exact h rfl },\n  rintros a s hs hsa_nonempty hsa_prop,\n  rw [prod_cons, map_cons, prod_cons],\n  by_cases hs_empty : s = \u2205,\n  { simp [hs_empty] },\n  have hsa_restrict : (\u2200 x, x \u2208 s \u2192 p x), from \u03bb x hx, hsa_prop x (mem_cons_of_mem hx),\n  have hp_sup : p s.prod,\n    from prod_induction_nonempty p hp_mul hs_empty hsa_restrict,\n  have hp_a : p a, from hsa_prop a (mem_cons_self a s),\n  exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _),\nend\n\n@[to_additive le_sum_nonempty_of_subadditive]\nlemma le_prod_nonempty_of_submultiplicative [comm_monoid \u03b1] [ordered_comm_monoid \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (h_mul : \u2200 a b, f (a * b) \u2264 f a * f b) (s : multiset \u03b1) (hs_nonempty : s \u2260 \u2205) :\n  f s.prod \u2264 (s.map f).prod :=\nle_prod_nonempty_of_submultiplicative_on_pred f (\u03bb i, true) (by simp [h_mul]) (by simp) s\n  hs_nonempty (by simp)\n\n@[simp] lemma sum_map_singleton (s : multiset \u03b1) : (s.map (\u03bb a, ({a} : multiset \u03b1))).sum = s :=\nmultiset.induction_on s (by simp) (by simp [singleton_eq_cons])\n\nlemma abs_sum_le_sum_abs [linear_ordered_add_comm_group \u03b1] {s : multiset \u03b1} :\n  abs s.sum \u2264 (s.map abs).sum :=\nle_sum_of_subadditive _ abs_zero abs_add s\n\nend multiset\n\n@[to_additive]\nlemma monoid_hom.map_multiset_prod [comm_monoid \u03b1] [comm_monoid \u03b2] (f : \u03b1 \u2192* \u03b2) (s : multiset \u03b1) :\n  f s.prod = (s.map f).prod :=\n(s.prod_hom f).symm\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/big_operators/multiset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.710694155536839}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson, Jalex Stark.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.monic\nimport Mathlib.tactic.linarith.default\nimport Mathlib.PostPort\n\nuniverses u w \n\nnamespace Mathlib\n\n/-!\n# Polynomials\n\nLemmas for the interaction between polynomials and \u2211 and \u220f.\n\n## Main results\n\n- `nat_degree_prod_of_monic` : the degree of a product of monic polynomials is the product of\n    degrees. We prove this only for [comm_semiring R],\n    but it ought to be true for [semiring R] and list.prod.\n- `nat_degree_prod` : for polynomials over an integral domain,\n    the degree of the product is the sum of degrees\n- `leading_coeff_prod` : for polynomials over an integral domain,\n    the leading coefficient is the product of leading coefficients\n- `prod_X_sub_C_coeff_card_pred` carries most of the content for computing\n    the second coefficient of the characteristic polynomial.\n-/\n\nnamespace polynomial\n\n\ntheorem nat_degree_prod_le {R : Type u} {\u03b9 : Type w} (s : finset \u03b9) [comm_semiring R] (f : \u03b9 \u2192 polynomial R) : nat_degree (finset.prod s fun (i : \u03b9) => f i) \u2264 finset.sum s fun (i : \u03b9) => nat_degree (f i) := sorry\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `leading_coeff_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\ntheorem leading_coeff_prod' {R : Type u} {\u03b9 : Type w} (s : finset \u03b9) [comm_semiring R] (f : \u03b9 \u2192 polynomial R) (h : (finset.prod s fun (i : \u03b9) => leading_coeff (f i)) \u2260 0) : leading_coeff (finset.prod s fun (i : \u03b9) => f i) = finset.prod s fun (i : \u03b9) => leading_coeff (f i) := sorry\n\n/--\nThe degree of a product of polynomials is equal to\nthe product of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `nat_degree_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\ntheorem nat_degree_prod' {R : Type u} {\u03b9 : Type w} (s : finset \u03b9) [comm_semiring R] (f : \u03b9 \u2192 polynomial R) (h : (finset.prod s fun (i : \u03b9) => leading_coeff (f i)) \u2260 0) : nat_degree (finset.prod s fun (i : \u03b9) => f i) = finset.sum s fun (i : \u03b9) => nat_degree (f i) := sorry\n\ntheorem nat_degree_prod_of_monic {R : Type u} {\u03b9 : Type w} (s : finset \u03b9) [comm_semiring R] (f : \u03b9 \u2192 polynomial R) [nontrivial R] (h : \u2200 (i : \u03b9), i \u2208 s \u2192 monic (f i)) : nat_degree (finset.prod s fun (i : \u03b9) => f i) = finset.sum s fun (i : \u03b9) => nat_degree (f i) := sorry\n\ntheorem coeff_zero_prod {R : Type u} {\u03b9 : Type w} (s : finset \u03b9) [comm_semiring R] (f : \u03b9 \u2192 polynomial R) : coeff (finset.prod s fun (i : \u03b9) => f i) 0 = finset.prod s fun (i : \u03b9) => coeff (f i) 0 := sorry\n\n-- Eventually this can be generalized with Vieta's formulas\n\n-- plus the connection between roots and factorization.\n\ntheorem prod_X_sub_C_next_coeff {R : Type u} {\u03b9 : Type w} [comm_ring R] [nontrivial R] {s : finset \u03b9} (f : \u03b9 \u2192 R) : next_coeff (finset.prod s fun (i : \u03b9) => X - coe_fn C (f i)) = -finset.sum s fun (i : \u03b9) => f i := sorry\n\ntheorem prod_X_sub_C_coeff_card_pred {R : Type u} {\u03b9 : Type w} [comm_ring R] [nontrivial R] (s : finset \u03b9) (f : \u03b9 \u2192 R) (hs : 0 < finset.card s) : coeff (finset.prod s fun (i : \u03b9) => X - coe_fn C (f i)) (finset.card s - 1) = -finset.sum s fun (i : \u03b9) => f i := sorry\n\ntheorem nat_degree_prod {R : Type u} {\u03b9 : Type w} (s : finset \u03b9) [comm_ring R] [no_zero_divisors R] (f : \u03b9 \u2192 polynomial R) [nontrivial R] (h : \u2200 (i : \u03b9), i \u2208 s \u2192 f i \u2260 0) : nat_degree (finset.prod s fun (i : \u03b9) => f i) = finset.sum s fun (i : \u03b9) => nat_degree (f i) := sorry\n\ntheorem leading_coeff_prod {R : Type u} {\u03b9 : Type w} (s : finset \u03b9) [comm_ring R] [no_zero_divisors R] (f : \u03b9 \u2192 polynomial R) : leading_coeff (finset.prod s fun (i : \u03b9) => f i) = finset.prod s fun (i : \u03b9) => leading_coeff (f i) := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/polynomial/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7106514415243875}}
{"text": "/-\nCopyright \u00a9 2020 Nicol\u00f2 Cavalleri. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Nicol\u00f2 Cavalleri\n-/\nimport geometry.manifold.algebra.lie_group\n\n/-!\n# Smooth structures\n\nIn this file we define smooth structures that build on Lie groups. We prefer using the term smooth\ninstead of Lie mainly because Lie ring has currently another use in mathematics.\n-/\n\nopen_locale manifold\n\nsection smooth_ring\nvariables {\ud835\udd5c : Type*} [nontrivially_normed_field \ud835\udd5c]\n{H : Type*} [topological_space H]\n{E : Type*} [normed_add_comm_group E] [normed_space \ud835\udd5c E]\n\nset_option default_priority 100 -- see Note [default priority]\n\n/-- A smooth (semi)ring is a (semi)ring `R` where addition and multiplication are smooth.\nIf `R` is a ring, then negation is automatically smooth, as it is multiplication with `-1`. -/\n-- See note [Design choices about smooth algebraic structures]\nclass smooth_ring (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [semiring R] [topological_space R] [charted_space H R]\n  extends has_smooth_add I R : Prop :=\n(smooth_mul : smooth (I.prod I) I (\u03bb p : R\u00d7R, p.1 * p.2))\n\ninstance smooth_ring.to_has_smooth_mul (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [semiring R] [topological_space R] [charted_space H R] [h : smooth_ring I R] :\n  has_smooth_mul I R := { ..h }\n\ninstance smooth_ring.to_lie_add_group (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [ring R] [topological_space R] [charted_space H R] [smooth_ring I R] :\n  lie_add_group I R :=\n{ compatible := \u03bb e e', has_groupoid.compatible (cont_diff_groupoid \u22a4 I),\n  smooth_add := smooth_add I,\n  smooth_neg := by simpa only [neg_one_mul] using @smooth_mul_left \ud835\udd5c _ H _ E _ _ I R _ _ _ _ (-1) }\n\nend smooth_ring\n\ninstance field_smooth_ring {\ud835\udd5c : Type*} [nontrivially_normed_field \ud835\udd5c] :\n  smooth_ring \ud835\udcd8(\ud835\udd5c) \ud835\udd5c :=\n{ smooth_mul :=\n  begin\n    rw smooth_iff,\n    refine \u27e8continuous_mul, \u03bb x y, _\u27e9,\n    simp only [prod.mk.eta] with mfld_simps,\n    rw cont_diff_on_univ,\n    exact cont_diff_mul,\n  end,\n  ..normed_space_lie_add_group }\n\nvariables {\ud835\udd5c R E H : Type*} [topological_space R] [topological_space H]\n  [nontrivially_normed_field \ud835\udd5c] [normed_add_comm_group E] [normed_space \ud835\udd5c E]\n  [charted_space H R] (I : model_with_corners \ud835\udd5c E H)\n\n/-- A smooth (semi)ring is a topological (semi)ring. This is not an instance for technical reasons,\nsee note [Design choices about smooth algebraic structures]. -/\nlemma topological_semiring_of_smooth [semiring R] [smooth_ring I R] :\n  topological_semiring R :=\n{ .. has_continuous_mul_of_smooth I, .. has_continuous_add_of_smooth I }\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/manifold/algebra/structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7106514370329688}}
{"text": "import topology.metric_space.basic\n\nsection\nvariables {\u03b1 : Type*} [partial_order \u03b1]\nvariables x y z : \u03b1\n\n#check x \u2264 y\n#check (le_refl x : x \u2264 x)\n#check (le_trans : x \u2264 y \u2192 y \u2264 z \u2192 x \u2264 z)\n\n#check x < y\n#check (lt_irrefl x : \u00ac x < x)\n#check (lt_trans : x < y \u2192 y < z \u2192 x < z)\n#check (lt_of_le_of_lt : x \u2264 y \u2192 y < z \u2192 x < z)\n#check (lt_of_lt_of_le : x < y \u2192 y \u2264 z \u2192 x < z)\n\nexample : x < y \u2194 x \u2264 y \u2227 x \u2260 y :=\nlt_iff_le_and_ne\n\nend\n\nsection\nvariables {\u03b1 : Type*} [lattice \u03b1]\nvariables x y z : \u03b1\n\n#check x \u2293 y\n#check (inf_le_left : x \u2293 y \u2264 x)\n#check (inf_le_right : x \u2293 y \u2264 y)\n#check (le_inf : z \u2264 x \u2192 z \u2264 y \u2192 z \u2264 x \u2293 y)\n\n#check x \u2294 y\n#check (le_sup_left : x \u2264 x \u2294 y)\n#check (le_sup_right: y \u2264 x \u2294 y)\n#check (sup_le : x \u2264 z \u2192 y \u2264 z \u2192 x \u2294 y \u2264 z)\n\nexample : x \u2293 y = y \u2293 x :=\nbegin\n  apply le_antisymm,\n  -- The original example (and solution) uses `repeat`\n  apply le_inf,\n  exact inf_le_right,\n  exact inf_le_left,\n  apply le_inf,\n  exact inf_le_right,\n  exact inf_le_left,\nend\n\nexample : x \u2293 y \u2293 z = x \u2293 (y \u2293 z) := sorry\nexample : x \u2294 y = y \u2294 x := sorry\nexample : x \u2294 y \u2294 z = x \u2294 (y \u2294 z) := sorry\n\ntheorem absorb1 : x \u2293 (x \u2294 y) = x := sorry\ntheorem absorb2 : x \u2294 (x \u2293 y) = x := sorry\n\nend\n\nsection\nvariables {\u03b1 : Type*} [distrib_lattice \u03b1]\nvariables x y z : \u03b1\n\n#check (inf_sup_left : x \u2293 (y \u2294 z) = (x \u2293 y) \u2294 (x \u2293 z))\n#check (inf_sup_right : (x \u2294 y) \u2293 z = (x \u2293 z) \u2294 (y \u2293 z))\n#check (sup_inf_left : x \u2294 (y \u2293 z) = (x \u2294 y) \u2293 (x \u2294 z))\n#check (sup_inf_right : (x \u2293 y) \u2294 z = (x \u2294 z) \u2293 (y \u2294 z))\n\nend\n\nsection\nvariables {\u03b1 : Type*} [lattice \u03b1]\nvariables a b c : \u03b1\n\nexample (h : \u2200 x y z : \u03b1, x \u2293 (y \u2294 z) = (x \u2293 y) \u2294 (x \u2293 z)) :\n  a \u2294 (b \u2293 c) = (a \u2294 b) \u2293 (a \u2294 c) :=\nsorry\n\nexample (h : \u2200 x y z : \u03b1, x \u2294 (y \u2293 z) = (x \u2294 y) \u2293 (x \u2294 z)) :\n  a \u2293 (b \u2294 c) = (a \u2293 b) \u2294 (a \u2293 c) :=\nsorry\n\nend\n\nsection\nvariables {R : Type*} [ordered_ring R]\nvariables a b c : R\n\n#check (add_le_add_left : a \u2264 b \u2192 \u2200 c, c + a \u2264 c + b)\n#check (mul_pos : 0 < a \u2192 0 < b \u2192 0 < a * b)\n\n#check (mul_nonneg : 0 \u2264 a \u2192 0 \u2264 b \u2192 0 \u2264 a * b)\n\nexample : a \u2264 b \u2192 0 \u2264 b - a := sorry\n\nexample : 0 \u2264 b - a \u2192 a \u2264 b := sorry\n\nexample (h : a \u2264 b) (h' : 0 \u2264 c) : a * c \u2264 b * c := sorry\n\nend\n\nsection\nvariables {X : Type*} [metric_space X]\nvariables x y z : X\n\n#check (dist_self x : dist x x = 0)\n#check (dist_comm x y : dist x y = dist y x)\n#check (dist_triangle x y z : dist x z \u2264 dist x y + dist y z)\n\nexample (x y : X) : 0 \u2264 dist x y :=\nbegin\n  have : 0 \u2264 dist x y * 2,\n  calc\n  0   = dist x x            : by rw dist_self\n  ... \u2264 dist x y + dist y x : dist_triangle x y x\n  ... \u2264 dist x y * 2        : by {rw dist_comm, ring},\n  linarith [nonneg_of_mul_nonneg_left this],\n  end\n\nend\n\n", "meta": {"author": "sterraf", "repo": "mylearninglean", "sha": "a8911234b2a4e15a48ec2c0f05d744e58f798ca7", "save_path": "github-repos/lean/sterraf-mylearninglean", "path": "github-repos/lean/sterraf-mylearninglean/mylearninglean-a8911234b2a4e15a48ec2c0f05d744e58f798ca7/src/mathematics_in_lean_src/02_Basics/05_Proving_Facts_about_Algebraic_Structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.7106210927833293}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,\nNeil Strickland, Aaron Anderson\n-/\n\nimport algebra.group_with_zero\n\n/-!\n# Divisibility\n\nThis file defines the basics of the divisibility relation in the context of `(comm_)` `monoid`s\n`(_with_zero)`.\n\n## Main definitions\n\n * `monoid.has_dvd`\n\n## Implementation notes\n\nThe divisibility relation is defined for all monoids, and as such, depends on the order of\n  multiplication if the monoid is not commutative. There are two possible conventions for\n  divisibility in the noncommutative context, and this relation follows the convention for ordinals,\n  so `a | b` is defined as `\u2203 c, b = a * c`.\n\n## Tags\n\ndivisibility, divides\n-/\n\nvariables {\u03b1 : Type*}\n\nsection monoid\n\nvariables [monoid \u03b1] {a b c : \u03b1}\n\n/-- There are two possible conventions for divisibility, which coincide in a `comm_monoid`.\n    This matches the convention for ordinals. -/\n@[priority 100]\ninstance monoid_has_dvd : has_dvd \u03b1 :=\nhas_dvd.mk (\u03bb a b, \u2203 c, b = a * c)\n\n-- TODO: this used to not have c explicit, but that seems to be important\n--       for use with tactics, similar to exist.intro\ntheorem dvd.intro (c : \u03b1) (h : a * c = b) : a \u2223 b :=\nexists.intro c h^.symm\n\nalias dvd.intro \u2190 dvd_of_mul_right_eq\n\ntheorem exists_eq_mul_right_of_dvd (h : a \u2223 b) : \u2203 c, b = a * c := h\n\ntheorem dvd.elim {P : Prop} {a b : \u03b1} (H\u2081 : a \u2223 b) (H\u2082 : \u2200 c, b = a * c \u2192 P) : P :=\nexists.elim H\u2081 H\u2082\n\n@[refl, simp] theorem dvd_refl (a : \u03b1) : a \u2223 a :=\ndvd.intro 1 (by simp)\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\n@[trans] theorem dvd_trans (h\u2081 : a \u2223 b) (h\u2082 : b \u2223 c) : a \u2223 c :=\nmatch h\u2081, h\u2082 with\n| \u27e8d, (h\u2083 : b = a * d)\u27e9, \u27e8e, (h\u2084 : c = b * e)\u27e9 :=\n  \u27e8d * e, show c = a * (d * e), by simp [h\u2083, h\u2084]\u27e9\nend\n\nalias dvd_trans \u2190 dvd.trans\n\ntheorem one_dvd (a : \u03b1) : 1 \u2223 a := dvd.intro a (by simp)\n\n@[simp] theorem dvd_mul_right (a b : \u03b1) : a \u2223 a * b := dvd.intro b rfl\n\ntheorem dvd_mul_of_dvd_left (h : a \u2223 b) (c : \u03b1) : a \u2223 b * c :=\ndvd.elim h (\u03bb d h', begin rw [h', mul_assoc], apply dvd_mul_right end)\n\ntheorem dvd_of_mul_right_dvd (h : a * b \u2223 c) : a \u2223 c :=\ndvd.elim h (begin intros d h\u2081, rw [h\u2081, mul_assoc], apply dvd_mul_right end)\n\nend monoid\n\nsection comm_monoid\n\nvariables [comm_monoid \u03b1] {a b c : \u03b1}\n\ntheorem dvd.intro_left (c : \u03b1) (h : c * a = b) : a \u2223 b :=\ndvd.intro _ (begin rewrite mul_comm at h, apply h end)\n\nalias dvd.intro_left \u2190 dvd_of_mul_left_eq\n\ntheorem exists_eq_mul_left_of_dvd (h : a \u2223 b) : \u2203 c, b = c * a :=\ndvd.elim h (assume c, assume H1 : b = a * c, exists.intro c (eq.trans H1 (mul_comm a c)))\n\ntheorem dvd.elim_left {P : Prop} (h\u2081 : a \u2223 b) (h\u2082 : \u2200 c, b = c * a \u2192 P) : P :=\nexists.elim (exists_eq_mul_left_of_dvd h\u2081) (assume c, assume h\u2083 : b = c * a, h\u2082 c h\u2083)\n\n@[simp] theorem dvd_mul_left (a b : \u03b1) : a \u2223 b * a := dvd.intro b (mul_comm a b)\n\ntheorem dvd_mul_of_dvd_right (h : a \u2223 b) (c : \u03b1) : a \u2223 c * b :=\nbegin rw mul_comm, exact dvd_mul_of_dvd_left h _ end\n\nlocal attribute [simp] mul_assoc mul_comm mul_left_comm\n\ntheorem mul_dvd_mul : \u2200 {a b c d : \u03b1}, a \u2223 b \u2192 c \u2223 d \u2192 a * c \u2223 b * d\n| a ._ c ._ \u27e8e, rfl\u27e9 \u27e8f, rfl\u27e9 := \u27e8e * f, by simp\u27e9\n\ntheorem mul_dvd_mul_left (a : \u03b1) {b c : \u03b1} (h : b \u2223 c) : a * b \u2223 a * c :=\nmul_dvd_mul (dvd_refl a) h\n\ntheorem mul_dvd_mul_right (h : a \u2223 b) (c : \u03b1) : a * c \u2223 b * c :=\nmul_dvd_mul h (dvd_refl c)\n\ntheorem dvd_of_mul_left_dvd (h : a * b \u2223 c) : b \u2223 c :=\ndvd.elim h (\u03bb d ceq, dvd.intro (a * d) (by simp [ceq]))\n\nend comm_monoid\n\nsection monoid_with_zero\n\nvariables [monoid_with_zero \u03b1] {a : \u03b1}\n\ntheorem eq_zero_of_zero_dvd (h : 0 \u2223 a) : a = 0 :=\ndvd.elim h (assume c, assume H' : a = 0 * c, eq.trans H' (zero_mul c))\n\n/-- Given an element `a` of a commutative monoid with zero, there exists another element whose\n    product with zero equals `a` iff `a` equals zero. -/\n@[simp] lemma zero_dvd_iff : 0 \u2223 a \u2194 a = 0 :=\n\u27e8eq_zero_of_zero_dvd, \u03bb h, by rw h\u27e9\n\n@[simp] theorem dvd_zero (a : \u03b1) : a \u2223 0 := dvd.intro 0 (by simp)\n\nend monoid_with_zero\n\n/-- Given two elements `b`, `c` of a `cancel_monoid_with_zero` and a nonzero element `a`,\n `a*b` divides `a*c` iff `b` divides `c`. -/\ntheorem mul_dvd_mul_iff_left [cancel_monoid_with_zero \u03b1] {a b c : \u03b1}\n  (ha : a \u2260 0) : a * b \u2223 a * c \u2194 b \u2223 c :=\nexists_congr $ \u03bb d, by rw [mul_assoc, mul_right_inj' ha]\n\n/-- Given two elements `a`, `b` of a commutative `cancel_monoid_with_zero` and a nonzero\n  element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/\ntheorem mul_dvd_mul_iff_right [comm_cancel_monoid_with_zero \u03b1] {a b c : \u03b1} (hc : c \u2260 0) :\n  a * c \u2223 b * c \u2194 a \u2223 b :=\nexists_congr $ \u03bb d, by rw [mul_right_comm, mul_left_inj' hc]\n\n/-!\n### Units in various monoids\n-/\n\nnamespace units\n\nsection monoid\nvariables [monoid \u03b1] {a b : \u03b1} {u : units \u03b1}\n\n/-- Elements of the unit group of a monoid represented as elements of the monoid\n    divide any element of the monoid. -/\nlemma coe_dvd : \u2191u \u2223 a := \u27e8\u2191u\u207b\u00b9 * a, by simp\u27e9\n\n/-- In a monoid, an element `a` divides an element `b` iff `a` divides all\n    associates of `b`. -/\nlemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\niff.intro\n  (assume \u27e8c, eq\u27e9, \u27e8c * \u2191u\u207b\u00b9, by rw [\u2190 mul_assoc, \u2190 eq, units.mul_inv_cancel_right]\u27e9)\n  (assume \u27e8c, eq\u27e9, eq.symm \u25b8 dvd_mul_of_dvd_left (dvd_mul_right _ _) _)\n\n/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/\nlemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\niff.intro\n  (\u03bb \u27e8c, eq\u27e9, \u27e8\u2191u * c, eq.trans (mul_assoc _ _ _)\u27e9)\n  (\u03bb h, dvd_trans (dvd.intro \u2191u\u207b\u00b9 (by rw [mul_assoc, u.mul_inv, mul_one])) h)\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] {a b : \u03b1} {u : units \u03b1}\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\nlemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b := by { rw mul_comm, apply dvd_mul_right }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\nlemma mul_left_dvd : \u2191u * a \u2223 b \u2194 a \u2223 b :=\nby { rw mul_comm, apply mul_right_dvd }\n\nend comm_monoid\n\nend units\n\nnamespace is_unit\n\nsection monoid\n\nvariables [monoid \u03b1] {a b u : \u03b1} (hu : is_unit u)\ninclude hu\n\n/-- Units of a monoid divide any element of the monoid. -/\n@[simp] lemma dvd : u \u2223 a := by { rcases hu with \u27e8u, rfl\u27e9, apply units.coe_dvd, }\n\n@[simp] lemma dvd_mul_right : a \u2223 b * u \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_right, }\n\n/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/\n@[simp] lemma mul_right_dvd : a * u \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_right_dvd, }\n\nend monoid\n\nsection comm_monoid\nvariables [comm_monoid \u03b1] (a b u : \u03b1) (hu : is_unit u)\ninclude hu\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\n@[simp] lemma dvd_mul_left : a \u2223 u * b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.dvd_mul_left, }\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff all\n  left associates of `a` divide `b`.-/\n@[simp] lemma mul_left_dvd : u * a \u2223 b \u2194 a \u2223 b :=\nby { rcases hu with \u27e8u, rfl\u27e9, apply units.mul_left_dvd, }\n\nend comm_monoid\n\nend is_unit\n\nsection comm_monoid_with_zero\n\nvariable [comm_monoid_with_zero \u03b1]\n\n/-- `dvd_not_unit a b` expresses that `a` divides `b` \"strictly\", i.e. that `b` divided by `a`\nis not a unit. -/\ndef dvd_not_unit (a b : \u03b1) : Prop := a \u2260 0 \u2227 \u2203 x, \u00acis_unit x \u2227 b = a * x\n\nlemma dvd_not_unit_of_dvd_of_not_dvd {a b : \u03b1} (hd : a \u2223 b) (hnd : \u00ac b \u2223 a) :\n  dvd_not_unit a b :=\nbegin\n  split,\n  { rintro rfl, exact hnd (dvd_zero _) },\n  { rcases hd with \u27e8c, rfl\u27e9,\n    refine \u27e8c, _, rfl\u27e9,\n    rintro \u27e8u, rfl\u27e9,\n    simpa using hnd }\nend\n\nend comm_monoid_with_zero\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.710621088695647}}
{"text": "import data.rat.basic\n       data.nat.parity\n       tactic\n\nlemma even_if_square_even {n : \u2115} (hn2 : 2 \u2223 (n*n)) : 2 \u2223 n :=\nbegin\n  by_contra hc,\n  have hmod2 : n % 2 = 1, from nat.not_even_iff.mp hc,\n  set k := n / 2 with hk,\n  have hn : n = 1 + 2*k,\n  { rw [\u2190nat.mod_add_div n 2, hmod2] },\n  have hnn : n*n = 1 + 2*(2*k + 2*k*k),\n  { rw hn, ring },\n  rw [nat.dvd_iff_mod_eq_zero, hnn] at hn2,\n  norm_num at hn2,\nend\n\ntheorem sqrt_2_irrational : \u00ac\u2203 (p : \u211a), p^2 = 2 :=\nbegin\n  by_contra h,\n  cases h with p hp,\n  set m := int.nat_abs p.num with hm,\n  set n := p.denom with hn,\n  have hm2 : p.num * p.num = m * m,\n  { norm_cast,\n    rw [hm, int.nat_abs_mul_self] },\n  have hcop := p.cop,\n  rw [\u2190hm, \u2190hn] at hcop,\n  rw [pow_two, rat.eq_iff_mul_eq_mul, rat.mul_self_num, rat.mul_self_denom, hm2, \u2190hn] at hp,\n  norm_cast at hp,\n  rw mul_one at hp,\n  have hmmeven : 2 \u2223 m * m,\n  { rw hp,\n    exact nat.dvd_mul_right _ _ },\n  have hmeven : 2 \u2223 m, from even_if_square_even hmmeven,\n  have hmeven := hmeven,\n  cases hmeven with k hk,\n  rw [hk, mul_mul_mul_comm, mul_assoc, nat.mul_right_inj (show 0 < 2, by norm_num)] at hp,\n  have hnneven : 2 \u2223 n * n,\n  { rw \u2190hp,\n    exact nat.dvd_mul_right _ _ },\n  have hneven : 2 \u2223 n, from even_if_square_even hnneven,\n  refine nat.not_coprime_of_dvd_of_dvd (by norm_num) hmeven hneven hcop,\nend\n", "meta": {"author": "shingtaklam1324", "repo": "lean_blog", "sha": "730670bb1066d081a4c6a1494badb5f4be27cdbc", "save_path": "github-repos/lean/shingtaklam1324-lean_blog", "path": "github-repos/lean/shingtaklam1324-lean_blog/lean_blog-730670bb1066d081a4c6a1494badb5f4be27cdbc/src/1_sqrt_2_irrational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7106210863722809}}
{"text": "/-\nTheorem 1 in Section 9.4 of the whitepaper, dealing with the encoding of an instruction as a field\nelement.\n-/\nimport starkware.cairo.lean.semantics.cpu\nimport starkware.cairo.lean.semantics.air_encoding.constraints\n\nopen_locale big_operators\n\n/-\nNote: this is needed for the `classical.some`, but we can possibly remove it\nbased on the data from the range_check, if we assume `F` has decidable equality.\n-/\nnoncomputable theory\n\n/-\nThe tilde encoding of bit vectors.\n-/\n\nnamespace bitvec\n\nvariables {n : \u2115} (b : bitvec n)\n\ndef tilde (i : fin (n + 1)) : \u2115 :=\n\u2211 j in i.rev.range, 2^(j.rev.cast_succ - i : \u2115) * (b.nth j.rev).to_nat\n\n@[simp] theorem tilde_last : b.tilde (fin.last n) = 0 :=\nby rw [tilde, fin.rev_last, fin.sum_range_zero]\n\ntheorem tilde_succ (i : fin n) :\n  b.tilde i.cast_succ = 2 * b.tilde i.succ + (b.nth i).to_nat :=\nbegin\n  rw [tilde, tilde, fin.rev_cast_succ, fin.sum_range_succ, finset.mul_sum,\n      add_comm, fin.rev_rev, nat.sub_self, pow_zero, one_mul, \u2190fin.cast_succ_rev],\n  congr' 1,\n  apply finset.sum_congr rfl,\n  intro j, rw [fin.mem_range, fin.cast_succ_lt_cast_succ_iff], intro hj,\n  rw [\u2190mul_assoc, \u2190pow_succ, fin.coe_succ, nat.sub_succ, fin.coe_cast_succ, fin.coe_cast_succ], congr, symmetry, apply nat.succ_pred_eq_of_pos,\n  apply nat.sub_pos_of_lt,\n  rwa [\u2190fin.lt_iff_coe_lt_coe, \u2190fin.rev_lt_rev_iff, fin.rev_rev]\nend\n\nsection\n\nvariables {\u03b1 : Type*} [semiring \u03b1]\n\ntheorem tilde_spec (f : fin (n + 1) \u2192 \u03b1)\n    (h0 : f (fin.last n) = 0)\n    (hsucc : \u2200 i : fin n, f i.cast_succ = 2 * f i.succ + (b.nth i).to_nat) :\n  f = \u03bb i, b.tilde i :=\nbegin\n  ext i, rw \u2190fin.rev_rev i,\n  generalize : i.rev = j,\n  apply fin.induction_on j,\n  { rw [fin.rev_zero, h0, tilde_last, nat.cast_zero] },\n  intros i ih,\n  rw [\u2190fin.cast_succ_rev, tilde_succ, hsucc, \u2190fin.rev_cast_succ, ih],\n  simp\nend\n\nend\n\ntheorem tilde_spec_nat (f : fin (n + 1) \u2192 \u2115)\n    (h0 : f (fin.last n) = 0)\n    (hsucc : \u2200 i : fin n, f i.cast_succ = 2 * f i.succ + (b.nth i).to_nat) :\n  f = b.tilde :=\nby { rw (tilde_spec b f h0); simp, exact hsucc }\n\ntheorem tilde_zero_eq : b.tilde 0 = b.to_natr :=\nbegin\n  rw [bitvec.to_natr, tilde, fin.rev_zero, fin.range_last, fin.coe_zero],\n  induction n with n ih,\n  { rw [vector.eq_nil b], refl },\n  rw [fin.sum_univ_cast_succ],\n  conv { to_rhs, rw \u2190vector.cons_head_tail b },\n  rw [vector.reverse_cons, bitvec.to_nat_append, \u2190ih (vector.tail b)],\n  congr,\n  { rw [mul_comm, finset.mul_sum],\n    apply finset.sum_congr rfl,\n    intros j _,\n    simp, rw [\u2190mul_assoc, \u2190pow_succ, fin.rev_cast_succ],\n    congr,\n    apply tsub_eq_of_eq_add_rev,\n    rw [add_comm, add_assoc, add_comm 1, nat.sub_add_cancel],\n    exact j.2, },\n  rw [bitvec.singleton_to_nat], simp\nend\n\ndef from_tilde (f : fin (n+1) \u2192 \u2115) : bitvec n :=\nvector.of_fn (\u03bb i : fin n, bool.of_nat $\n  (f i.cast_succ - 2 * f i.succ))\n\ntheorem from_tilde_tilde : from_tilde b.tilde = b :=\nbegin\n  ext i, dsimp [from_tilde],\n  rw [vector.nth_of_fn, tilde_succ, add_comm, nat.add_sub_cancel, bool.of_nat_to_nat]\nend\n\ntheorem tilde_zero_inj {b1 b2 : bitvec n} (h : b1.tilde 0 = b2.tilde 0) : b1 = b2 :=\nbegin\n  rw [tilde_zero_eq, tilde_zero_eq] at h,\n  have := to_nat_inj h,\n  have h' := congr_arg vector.reverse this,\n  rwa [vector.reverse_reverse, vector.reverse_reverse] at h'\nend\n\nend bitvec\n\n/-\nConverting an instruction to a natural number.\n\nThis is only needed for the uniqueness theorem below, which may not be necessary for the\ncorrectness proof.\n-/\n\nnamespace instruction\n\ntheorem to_nat_le (inst : instruction) : inst.to_nat < 2^63 :=\ncalc\n  inst.to_nat \u2264 (2^16 - 1) + 2^16 * (2^16 - 1) + 2^32 * (2^16 - 1) + 2^48 * (2^15 - 1) :\n    begin\n      apply add_le_add,\n      apply add_le_add,\n      apply add_le_add,\n      apply inst.off_dst.to_natr_le,\n      apply nat.mul_le_mul_left,\n      apply inst.off_op0.to_natr_le,\n      apply nat.mul_le_mul_left,\n      apply inst.off_op1.to_natr_le,\n      apply nat.mul_le_mul_left,\n      apply bitvec.to_natr_le\n    end\n  ... = 2^63 - 1 : by norm_num\n  ... < 2^63     : by norm_num\n\ntheorem to_nat_eq (inst : instruction) :\n  inst.to_nat = inst.off_dst.to_natr + 2^16 * (inst.off_op0.to_natr +\n    2^16 * (inst.off_op1.to_natr + 2^16 * inst.flags.to_natr)) :=\nby { rw [instruction.to_nat], ring }\n\ntheorem to_nat_inj {i1 i2 : instruction} (h : i1.to_nat = i2.to_nat) : i1 = i2 :=\nbegin\n  have nez : 2^16 \u2260 0, norm_num,\n  rw [to_nat_eq, to_nat_eq] at h,\n  have h1 : i1.off_dst.to_natr = i2.off_dst.to_natr,\n  { have := congr_arg (\u03bb i, i % 2^16) h, dsimp at this,\n    simp [nat.add_mul_mod_self_left] at this,\n    rw [nat.mod_eq_of_lt i1.off_dst.to_natr_lt] at this,\n    rwa [nat.mod_eq_of_lt i2.off_dst.to_natr_lt] at this },\n  rw [h1, add_right_inj, mul_right_inj' nez] at h,\n  have h2 : i1.off_op0.to_natr = i2.off_op0.to_natr,\n  { have := congr_arg (\u03bb i, i % 2^16) h, dsimp at this,\n    simp [nat.add_mul_mod_self_left] at this,\n    rw [nat.mod_eq_of_lt i1.off_op0.to_natr_lt] at this,\n    rwa [nat.mod_eq_of_lt i2.off_op0.to_natr_lt] at this },\n  rw [h2, add_right_inj, mul_right_inj' nez] at h,\n  have h3 : i1.off_op1.to_natr = i2.off_op1.to_natr,\n  { have := congr_arg (\u03bb i, i % 2^16) h, dsimp at this,\n    simp [nat.add_mul_mod_self_left] at this,\n    rw [nat.mod_eq_of_lt i1.off_op1.to_natr_lt] at this,\n    rwa [nat.mod_eq_of_lt i2.off_op1.to_natr_lt] at this },\n  rw [h3, add_right_inj, mul_right_inj' nez] at h,\n  apply instruction.ext _ _ (bitvec.to_natr_inj h1) (bitvec.to_natr_inj h2)\n      (bitvec.to_natr_inj h3) (bitvec.to_natr_inj h)\nend\n\nend instruction\n\n/-\nTheorem 1.\n-/\n\nsection theorem_one\n\nvariables {F : Type*} [field F]\n-- so far, this is not used: [fintype F]\nvariable  (char_ge: ring_char F \u2265 2^63)\n\n/- the data -/\n\nvariables {inst\n           off_op0_tilde\n           off_op1_tilde\n           off_dst_tilde : F }\n\nvariable  {f_tilde : tilde_type F}\n\n/- the constraints -/\n\nvariable  h_instruction : inst = off_dst_tilde + 2^16 * off_op0_tilde + 2^32 * off_op1_tilde +\n                                   2^48 * f_tilde 0\n\nvariable  h_bit : \u2200 i : fin 15, f_tilde.to_f i * (f_tilde.to_f i - 1) = 0\n\nvariable  h_last_value : f_tilde \u27e815, by norm_num\u27e9 = 0\n\nvariable  off_op0_in_range : \u2203 j : \u2115, j < 2^16 \u2227 off_op0_tilde = \u2191j\n\nvariable  off_op1_in_range : \u2203 j : \u2115, j < 2^16 \u2227 off_op1_tilde = \u2191j\n\nvariable  off_dst_in_range  : \u2203 j : \u2115, j < 2^16 \u2227 off_dst_tilde = \u2191j\n\n/- recovering the instruction -/\n\ndef off_op0_nat := classical.some off_op0_in_range\n\ntheorem off_op0_lt : @off_op0_nat F _ _ off_op0_in_range < 2^16 :=\n(classical.some_spec off_op0_in_range).left\n\ntheorem off_op0_eq : off_op0_tilde = \u2191(@off_op0_nat F _ _ off_op0_in_range) :=\n(classical.some_spec off_op0_in_range).right\n\ndef off_op1_nat := classical.some off_op1_in_range\n\ntheorem off_op1_lt : @off_op1_nat F _ _ off_op1_in_range < 2^16 :=\n(classical.some_spec off_op1_in_range).left\n\ntheorem off_op1_eq : off_op1_tilde = \u2191(@off_op1_nat F _ _ off_op1_in_range) :=\n(classical.some_spec off_op1_in_range).right\n\ndef off_dst_nat := classical.some off_dst_in_range\n\ntheorem off_dst_lt : @off_dst_nat F _ _ off_dst_in_range < 2^16 :=\n(classical.some_spec off_dst_in_range).left\n\ntheorem off_dst_eq : off_dst_tilde = \u2191(@off_dst_nat F _ _ off_dst_in_range) :=\n(classical.some_spec off_dst_in_range).right\n\nsection\n\ninclude h_bit\n\ntheorem exists_bool_f_tilde_eq (i : fin 15) :\n  \u2203 b : bool, f_tilde.to_f i = \u2191(b.to_nat) :=\nbegin\n  cases eq_zero_or_eq_zero_of_mul_eq_zero (h_bit i) with h h,\n  { use ff, rw [h], simp only [bool.to_nat, bool.cond_ff, nat.cast_zero]},\n  use tt, rw [eq_of_sub_eq_zero h], exact nat.cast_one.symm\nend\n\nend\n\ndef flag_vec : bitvec 15 := vector.of_fn $ \u03bb i, classical.some (exists_bool_f_tilde_eq h_bit i)\n\ntheorem flag_vec_spec (i : fin 15) : \u2191((flag_vec h_bit).nth i).to_nat = f_tilde.to_f i :=\nby rw [flag_vec, vector.nth_of_fn, \u2190classical.some_spec (exists_bool_f_tilde_eq h_bit i)]\n\nsection\ninclude h_bit h_last_value\n\ntheorem f_tilde_eq : f_tilde = \u03bb i, (flag_vec h_bit).tilde i :=\nbegin\n  apply bitvec.tilde_spec _ _ h_last_value,\n  intro i,\n  rw add_comm (2 * f_tilde _),\n  apply eq_add_of_sub_eq,\n  symmetry, apply flag_vec_spec\nend\nend\n\ndef the_instruction : instruction :=\n{ off_dst := bitvec.of_natr 16 (off_dst_nat off_dst_in_range),\n  off_op0 := bitvec.of_natr 16 (off_op0_nat off_op0_in_range),\n  off_op1 := bitvec.of_natr 16 (off_op1_nat off_op1_in_range),\n  flags   := flag_vec h_bit }\n\n/-\nThe main theorem:\n-/\n\nsection\ninclude h_instruction h_last_value\n\ntheorem inst_eq : inst = (the_instruction h_bit off_op0_in_range\n                        off_op1_in_range off_dst_in_range).to_nat :=\nbegin\n  rw [h_instruction, the_instruction, instruction.to_nat],\n  simp [bitvec.to_natr_of_natr],\n  have := congr_fun (f_tilde_eq h_bit h_last_value) 0,\n  dsimp at this,\n  rw [nat.mod_eq_of_lt (off_op0_lt off_op0_in_range),\n         nat.mod_eq_of_lt (off_op1_lt off_op1_in_range),\n         nat.mod_eq_of_lt (off_dst_lt off_dst_in_range),\n         \u2190off_op0_eq off_op0_in_range,\n         \u2190off_op1_eq off_op1_in_range,\n         \u2190off_dst_eq off_dst_in_range,\n         this, bitvec.tilde_zero_eq]\nend\nend\n\ntheorem off_dst_tilde_eq : off_dst_tilde =\n  \u2191(the_instruction h_bit off_op0_in_range off_op1_in_range off_dst_in_range).off_dst.to_natr :=\nbegin\n  dsimp [the_instruction],\n  transitivity,\n  apply (off_dst_eq off_dst_in_range),\n  rw [bitvec.to_natr_of_natr, nat.mod_eq_of_lt (off_dst_lt off_dst_in_range)]\nend\n\ntheorem off_op0_tilde_eq : off_op0_tilde =\n  \u2191(the_instruction h_bit off_op0_in_range  off_op1_in_range off_dst_in_range).off_op0.to_natr :=\nbegin\n  dsimp [the_instruction],\n  transitivity,\n  apply (off_op0_eq off_op0_in_range),\n  rw [bitvec.to_natr_of_natr, nat.mod_eq_of_lt (off_op0_lt off_op0_in_range)]\nend\n\ntheorem off_op1_tilde_eq : off_op1_tilde =\n  \u2191(the_instruction h_bit off_op0_in_range off_op1_in_range off_dst_in_range).off_op1.to_natr :=\nbegin\n  dsimp [the_instruction],\n  transitivity,\n  apply (@off_op1_eq F _ _ off_op1_in_range),\n  rw [bitvec.to_natr_of_natr, nat.mod_eq_of_lt (off_op1_lt off_op1_in_range)]\nend\n\ntheorem f_tilde_to_f_eq : \u2200 i, f_tilde.to_f i =\n  \u2191((the_instruction h_bit off_op0_in_range off_op1_in_range\n      off_dst_in_range).flags.nth i).to_nat :=\nbegin\n  intro i,\n  dsimp [the_instruction],\n  symmetry,\n  apply flag_vec_spec\nend\n\nsection uniqueness\ninclude char_ge\n\ntheorem inst_unique (i1 i2 : instruction) (h : (i1.to_nat : F) = i2.to_nat) :\n  i1 = i2 :=\nbegin\n  have h1 : i1.to_nat < ring_char F, from lt_of_lt_of_le i1.to_nat_le char_ge,\n  have h2 : i2.to_nat < ring_char F, from lt_of_lt_of_le i2.to_nat_le char_ge,\n  have : i1.to_nat = i2.to_nat, from nat.cast_inj_of_lt_char h1 h2 h,\n  exact instruction.to_nat_inj this\nend\n\ninclude h_instruction h_last_value\n\ntheorem inst_unique' (i : instruction) (h : inst = i.to_nat) :\n  i = the_instruction h_bit off_op0_in_range off_op1_in_range off_dst_in_range :=\nbegin\n  apply inst_unique char_ge,\n  rw \u2190h, apply inst_eq, apply h_instruction, apply h_last_value\nend\nend uniqueness\n\nend theorem_one\n", "meta": {"author": "starkware-libs", "repo": "formal-proofs", "sha": "35613c65b6715601bbc0a550d52754f8e7d93e30", "save_path": "github-repos/lean/starkware-libs-formal-proofs", "path": "github-repos/lean/starkware-libs-formal-proofs/formal-proofs-35613c65b6715601bbc0a550d52754f8e7d93e30/src/starkware/cairo/lean/semantics/air_encoding/instruction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.7106210778242159}}
{"text": "/-\nCopyright (c) 2020 Patrick Stevens. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Stevens\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.tactic.ring_exp\nimport Mathlib.data.nat.parity\nimport Mathlib.data.nat.choose.sum\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Primorial\n\nThis file defines the primorial function (the product of primes less than or equal to some bound),\nand proves that `primorial n \u2264 4 ^ n`.\n\n## Notations\n\nWe use the local notation `n#` for the primorial of `n`: that is, the product of the primes less\nthan or equal to `n`.\n-/\n\n/-- The primorial `n#` of `n` is the product of the primes less than or equal to `n`.\n-/\ndef primorial (n : \u2115) : \u2115 :=\n  finset.prod (finset.filter nat.prime (finset.range (n + 1))) fun (p : \u2115) => p\n\ntheorem primorial_succ {n : \u2115} (n_big : 1 < n) (r : n % bit0 1 = 1) : primorial (n + 1) = primorial n := sorry\n\ntheorem dvd_choose_of_middling_prime (p : \u2115) (is_prime : nat.prime p) (m : \u2115) (p_big : m + 1 < p) (p_small : p \u2264 bit0 1 * m + 1) : p \u2223 nat.choose (bit0 1 * m + 1) (m + 1) := sorry\n\ntheorem prod_primes_dvd {s : finset \u2115} (n : \u2115) (h : \u2200 (a : \u2115), a \u2208 s \u2192 nat.prime a) (div : \u2200 (a : \u2115), a \u2208 s \u2192 a \u2223 n) : (finset.prod s fun (p : \u2115) => p) \u2223 n := sorry\n\ntheorem primorial_le_4_pow (n : \u2115) : primorial n \u2264 bit0 (bit0 1) ^ n := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/number_theory/primorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7106210770788157}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Johannes H\u00f6lzl\n-/\nimport dynamics.fixed_points.basic\nimport topology.separation\n\n/-!\n# Topological properties of fixed points\n\nCurrently this file contains two lemmas:\n\n- `is_fixed_pt_of_tendsto_iterate`: if `f^n(x) \u2192 y` and `f` is continuous at `y`, then `f y = y`;\n- `is_closed_fixed_points`: the set of fixed points of a continuous map is a closed set.\n\n## TODO\n\nfixed points, iterates\n-/\n\nvariables {\u03b1 : Type*} [topological_space \u03b1] [t2_space \u03b1] {f : \u03b1 \u2192 \u03b1}\n\nopen function filter\nopen_locale topological_space\n\n/-- If the iterates `f^[n] x` converge to `y` and `f` is continuous at `y`,\nthen `y` is a fixed point for `f`. -/\nlemma is_fixed_pt_of_tendsto_iterate {x y : \u03b1} (hy : tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y))\n  (hf : continuous_at f y) :\n  is_fixed_pt f y :=\nbegin\n  refine tendsto_nhds_unique ((tendsto_add_at_top_iff_nat 1).1 _) hy,\n  simp only [iterate_succ' f],\n  exact hf.tendsto.comp hy\nend\n\n/-- The set of fixed points of a continuous map is a closed set. -/\nlemma is_closed_fixed_points (hf : continuous f) : is_closed (fixed_points f) :=\nis_closed_eq hf continuous_id\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/dynamics/fixed_points/topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7106210706677671}}
{"text": "import data.real.basic\nimport tactic\n\nnamespace vilnius\n\n\nexample (P Q : Prop) : P \u2227 Q \u2192 Q :=\nbegin\n  intro hPQ,\n  cases hPQ with hP hQ,\n  exact hQ,\nend\n\n\nexample (P Q R : Prop) : (R \u2192 P) \u2227 (P \u2192 Q) \u2192 (R \u2192 Q) :=\nbegin\n  intro hPQR,\n  intro hR,\n  cases hPQR with hRP hPQ,\n  apply hPQ,\n  apply hRP,\n  exact hR,\nend\n\nend vilnius", "meta": {"author": "FRANCHI-Charles", "repo": "TER", "sha": "a33d03b3833b826b57857557fca90b20a6163e70", "save_path": "github-repos/lean/FRANCHI-Charles-TER", "path": "github-repos/lean/FRANCHI-Charles-TER/TER-a33d03b3833b826b57857557fca90b20a6163e70/src/PresentationDec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7981867729389245, "lm_q1q2_score": 0.710621070667767}}
{"text": "\nimport Catlib4.Basic\nimport Catlib4.Category.Category\nimport Catlib4.Category.Remarkable\n\nnamespace CategoryTheory.Category\n\nuniverse u v\n\ndef product_category (C D : Category.{u,v+1}) : Category.{u,v+1} where\n  \u03b1 := C \u00d7 D\n  hom a b := (a.1 \u27f6 b.1) \u00d7 (a.2 \u27f6 b.2)\n  id a := (\ud835\udfd9 a.1, \ud835\udfd9 a.2)\n  comp f g := (f.1 \u226b g.1, f.2 \u226b g.2)\n  id_comp' _ := Prod.ext' (C.id_comp _) (D.id_comp _)\n  comp_id' _ := Prod.ext' (C.comp_id _) (D.comp_id _)\n  assoc' _ _ _ := Prod.ext' (C.assoc _ _ _) (D.assoc _ _ _)\n\ninstance : HasCatProduct Category Category Category where\n  catProduct := product_category\n\ninstance {C D : Category.{u,v+1}} : HasHom (C.\u03b1 \u00d7 D.\u03b1) :=\n  inferInstanceAs (HasHom (C \u00d7c D))\n\nnamespace Product\n\ndef assoc (A B C : Category) : ((A \u00d7c B) \u00d7c C) \u2964 (A \u00d7c (B \u00d7c C)) where\n  obj := \u03bb ((a, b), c) => (a, (b, c))\n  map := \u03bb ((f, g), h) => (f, (g, h))\n  map_id' := \u03bb _ => rfl\n  map_comp' := \u03bb _ _ => rfl\n\ndef symm (A B : Category) : (A \u00d7c B) \u2964 (B \u00d7c A) where\n  obj := \u03bb (a, b) => (b, a)\n  map := \u03bb (f, g) => (g, f)\n  map_id' := \u03bb _ => rfl\n  map_comp' := \u03bb _ _ => rfl\n\ntheorem symmetric (A B : Category) : symm A B \u226b symm B A = \ud835\udfd9 (A \u00d7c B) := rfl\n\ndef functor_product {A B C D : Category} (F : A \u2964 C) (G : B \u2964 D) : A \u00d7c B \u2964 C \u00d7c D where\n  obj := \u03bb (x, y) => (F.obj x, G.obj y)\n  map f := (F.map f.1, G.map f.2)\n  map_id' _ := Prod.ext' (F.map_id _) (G.map_id' _)\n  map_comp' _ _ := Prod.ext' (F.map_comp _ _) (G.map_comp _ _)\n\ninstance {A B C D : Category} : HasCatProduct (A \u2964 C) (B \u2964 D) (A \u00d7c B \u2964 C \u00d7c D) where\n  catProduct := functor_product\n\ndef unit_left (C : Category) : (1 : Category) \u00d7c C \u2964 C where\n  obj := \u03bb (_, a) => a\n  map := \u03bb (_, f) => f\n  map_id' _ := rfl\n  map_comp' _ _ := rfl\n\ndef unit_left_inv (C : Category) : C \u2964 (1 : Category) \u00d7c C where\n  obj := \u03bb a => (PUnit.unit, a)\n  map := \u03bb f => (PUnit.unit, f)\n  map_id' _ := rfl\n  map_comp' _ _ := rfl\n\ndef unit_right (C : Category) : C \u00d7c (1 : Category) \u2964 C where\n  obj := \u03bb (a, _) => a\n  map := \u03bb (f, _) => f\n  map_id' _ := rfl\n  map_comp' _ _ := rfl\n\ndef unit_right_inv (C : Category) : C \u2964 C \u00d7c (1 : Category) where\n  obj := \u03bb a => (a, PUnit.unit)\n  map := \u03bb f => (f, PUnit.unit)\n  map_id' _ := rfl\n  map_comp' _ _ := rfl\n\nend Product\n\nend CategoryTheory.Category\n", "meta": {"author": "thejohncrafter", "repo": "Catlib4", "sha": "98c09be3236fee517ceb86ee6661ee9d3b752543", "save_path": "github-repos/lean/thejohncrafter-Catlib4", "path": "github-repos/lean/thejohncrafter-Catlib4/Catlib4-98c09be3236fee517ceb86ee6661ee9d3b752543/Catlib4/Category/Product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7105274013875248}}
{"text": "/-\nCopyright (c) 2019 Patrick Massot All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Simon Hudon\n\nA tactic pushing negations into an expression\n-/\n\nimport logic.basic\nimport algebra.order\n\nopen tactic expr\n\nnamespace push_neg\nsection\n\nuniverse u\nvariable  {\u03b1 : Sort u}\nvariables (p q : Prop)\nvariable  (s : \u03b1 \u2192 Prop)\n\nlocal attribute [instance, priority 10] classical.prop_decidable\ntheorem not_not_eq : (\u00ac \u00ac p) = p := propext not_not\ntheorem not_and_eq : (\u00ac (p \u2227 q)) = (p \u2192 \u00ac q) := propext not_and\ntheorem not_or_eq : (\u00ac (p \u2228 q)) = (\u00ac p \u2227 \u00ac q) := propext not_or_distrib\ntheorem not_forall_eq : (\u00ac \u2200 x, s x) = (\u2203 x, \u00ac s x) := propext not_forall\ntheorem not_exists_eq : (\u00ac \u2203 x, s x) = (\u2200 x, \u00ac s x) := propext not_exists\ntheorem not_implies_eq : (\u00ac (p \u2192 q)) = (p \u2227 \u00ac q) := propext not_imp\n\ntheorem classical.implies_iff_not_or : (p \u2192 q) \u2194 (\u00ac p \u2228 q) := imp_iff_not_or\n\n\ntheorem not_eq (a b : \u03b1) : (\u00ac a = b) \u2194 (a \u2260 b) := iff.rfl\n\nvariable  {\u03b2 : Type u}\nvariable [linear_order \u03b2]\ntheorem not_le_eq (a b : \u03b2) : (\u00ac (a \u2264 b)) = (b < a) := propext not_le\ntheorem not_lt_eq (a b : \u03b2) : (\u00ac (a < b)) = (b \u2264 a) := propext not_lt\nend\n\nmeta def whnf_reducible (e : expr) : tactic expr := whnf e reducible\n\nprivate meta def transform_negation_step (e : expr) :\n  tactic (option (expr \u00d7 expr)) :=\ndo e \u2190 whnf_reducible e,\n   match e with\n   | `(\u00ac %%ne) :=\n      (do ne \u2190 whnf_reducible ne,\n      match ne with\n      | `(\u00ac %%a)      := do pr \u2190 mk_app ``not_not_eq [a],\n                            return (some (a, pr))\n      | `(%%a \u2227 %%b)  := do pr \u2190 mk_app ``not_and_eq [a, b],\n                            return (some (`((%%a : Prop) \u2192 \u00ac %%b), pr))\n      | `(%%a \u2228 %%b)  := do pr \u2190 mk_app ``not_or_eq [a, b],\n                            return (some (`(\u00ac %%a \u2227 \u00ac %%b), pr))\n      | `(%%a \u2264 %%b)  := do e \u2190 to_expr ``(%%b < %%a),\n                            pr \u2190 mk_app ``not_le_eq [a, b],\n                            return (some (e, pr))\n      | `(%%a < %%b)  := do e \u2190 to_expr ``(%%b \u2264 %%a),\n                            pr \u2190 mk_app ``not_lt_eq [a, b],\n                            return (some (e, pr))\n      | `(Exists %%p) := do pr \u2190 mk_app ``not_exists_eq [p],\n                            e \u2190 match p with\n                                | (lam n bi typ bo) := do\n                                    body \u2190 mk_app ``not [bo],\n                                    return (pi n bi typ body)\n                                | _ := tactic.fail \"Unexpected failure negating \u2203\"\n                                end,\n                            return (some (e, pr))\n      | (pi n bi d p) := if p.has_var then do\n                            pr \u2190 mk_app ``not_forall_eq [lam n bi d p],\n                            body \u2190 mk_app ``not [p],\n                            e \u2190  mk_app ``Exists [lam n bi d body],\n                            return (some (e, pr))\n                         else do\n                            pr \u2190 mk_app ``not_implies_eq [d, p],\n                            `(%%_ = %%e') \u2190 infer_type pr,\n                            return (some (e', pr))\n      | _             := return none\n      end)\n    | _        := return none\n  end\n\nprivate meta def transform_negation : expr \u2192 tactic (option (expr \u00d7 expr))\n| e :=\ndo (some (e', pr)) \u2190 transform_negation_step e | return none,\n   (some (e'', pr')) \u2190 transform_negation e' | return (some (e', pr)),\n   pr'' \u2190 mk_eq_trans pr pr',\n   return (some (e'', pr''))\n\nmeta def normalize_negations (t : expr) : tactic (expr \u00d7 expr) :=\ndo (_, e, pr) \u2190 simplify_top_down ()\n                   (\u03bb _, \u03bb e, do\n                       oepr \u2190 transform_negation e,\n                       match oepr with\n                       | (some (e', pr)) := return ((), e', pr)\n                       | none            := do pr \u2190 mk_eq_refl e, return ((), e, pr)\n                       end)\n                   t { eta := ff },\n   return (e, pr)\n\nmeta def push_neg_at_hyp (h : name) : tactic unit :=\ndo H \u2190 get_local h,\n   t \u2190 infer_type H,\n   (e, pr) \u2190 normalize_negations t,\n   replace_hyp H e pr,\n   skip\n\nmeta def push_neg_at_goal : tactic unit :=\ndo H \u2190 target,\n   (e, pr) \u2190 normalize_negations H,\n   replace_target e pr\nend push_neg\n\nopen interactive (parse loc.ns loc.wildcard)\nopen interactive.types (location texpr)\nopen lean.parser (tk ident many) interactive.loc\nlocal postfix `?`:9001 := optional\nlocal postfix *:9001 := many\nopen push_neg\n\n/--\nPush negations in the goal of some assumption.\n\nFor instance, a hypothesis `h : \u00ac \u2200 x, \u2203 y, x \u2264 y` will be transformed by `push_neg at h` into\n`h : \u2203 x, \u2200 y, y < x`. Variables names are conserved.\n\nThis tactic pushes negations inside expressions. For instance, given an assumption\n```lean\nh : \u00ac \u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192 |f x - y\u2080| \u2264 \u03b5)\n```\nwriting `push_neg at h` will turn `h` into\n```lean\nh : \u2203 \u03b5, \u03b5 > 0 \u2227 \u2200 \u03b4, \u03b4 > 0 \u2192 (\u2203 x, |x - x\u2080| \u2264 \u03b4 \u2227 \u03b5 < |f x - y\u2080|),\n```\n\n(the pretty printer does *not* use the abreviations `\u2200 \u03b4 > 0` and `\u2203 \u03b5 > 0` but this issue\nhas nothing to do with `push_neg`).\nNote that names are conserved by this tactic, contrary to what would happen with `simp`\nusing the relevant lemmas. One can also use this tactic at the goal using `push_neg`,\nat every assumption and the goal using `push_neg at *` or at selected assumptions and the goal\nusing say `push_neg at h h' \u22a2` as usual.\n-/\nmeta def tactic.interactive.push_neg : parse location \u2192 tactic unit\n| (loc.ns loc_l) :=\n  loc_l.mmap'\n    (\u03bb l, match l with\n          | some h := do push_neg_at_hyp h,\n                          try $ interactive.simp_core { eta := ff } failed tt\n                                 [simp_arg_type.expr ``(push_neg.not_eq)] []\n                                 (interactive.loc.ns [some h])\n          | none   := do push_neg_at_goal,\n                          try `[simp only [push_neg.not_eq] { eta := ff }]\n          end)\n| loc.wildcard := do\n    push_neg_at_goal,\n    local_context >>= mmap' (\u03bb h, push_neg_at_hyp (local_pp_name h)) ,\n    try `[simp only [push_neg.not_eq] at * { eta := ff }]\n\nadd_tactic_doc\n{ name       := \"push_neg\",\n  category   := doc_category.tactic,\n  decl_names := [`tactic.interactive.push_neg],\n  tags       := [\"logic\"] }\n\nlemma imp_of_not_imp_not (P Q : Prop) : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\n\u03bb h hP, classical.by_contradiction (\u03bb h', h h' hP)\n\n/-- Matches either an identifier \"h\" or a pair of identifiers \"h with k\" -/\nmeta def name_with_opt : lean.parser (name \u00d7 option name) :=\nprod.mk <$> ident <*> (some <$> (tk \"with\" >> ident) <|> return none)\n\n/--\nTransforms the goal into its contrapositive.\n\n* `contrapose`     turns a goal `P \u2192 Q` into `\u00ac Q \u2192 \u00ac P`\n* `contrapose!`    turns a goal `P \u2192 Q` into `\u00ac Q \u2192 \u00ac P` and pushes negations inside `P` and `Q`\n  using `push_neg`\n* `contrapose h`   first reverts the local assumption `h`, and then uses `contrapose` and `intro h`\n* `contrapose! h`  first reverts the local assumption `h`, and then uses `contrapose!` and `intro h`\n* `contrapose h with new_h` uses the name `new_h` for the introduced hypothesis\n-/\nmeta def tactic.interactive.contrapose (push : parse (tk \"!\" )?) :\n  parse name_with_opt? \u2192 tactic unit\n| (some (h, h')) := get_local h >>= revert >> tactic.interactive.contrapose none >>\n  intro (h'.get_or_else h) >> skip\n| none :=\n  do `(%%P \u2192 %%Q) \u2190 target | fail \"The goal is not an implication, and you didn't specify an assumption\",\n  cp \u2190 mk_mapp ``imp_of_not_imp_not [P, Q] <|> fail \"contrapose only applies to nondependent arrows between props\",\n  apply cp,\n  when push.is_some $ try (tactic.interactive.push_neg (loc.ns [none]))\n\nadd_tactic_doc\n{ name       := \"contrapose\",\n  category   := doc_category.tactic,\n  decl_names := [`tactic.interactive.contrapose],\n  tags       := [\"logic\"] }\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/tactic/push_neg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7105273953432588}}
{"text": "import Mathlib.Init.Algebra.Order\nimport Mathlib.Tactic.LibrarySearch\nimport Mathlib.Data.Vector.Basic\n\nimport Diploma.Polynomials.PolynomialCommon\nimport Diploma.Polynomials.Polynomial\n\nopen Vector\nopen polynomial\nopen Classical\nopen Nat\n\nnamespace algebra\n\nsection monomials_lex_order\n\nprivate def Order.ble_lex_impl (v\u2081 v\u2082 : Vector Nat n): Bool :=\n  match v\u2081, v\u2082 with\n    | \u27e8[], _\u27e9  , \u27e8[], _\u27e9   => true\n    | \u27e8x::_, _\u27e9, \u27e8y::_, _\u27e9 => if x == y then ble_lex_impl v\u2081.tail v\u2082.tail \n                              else x <= y\n\ndef Order.lex_impl (v\u2081 v\u2082 : Vector Nat n): Prop :=\n  match v\u2081, v\u2082 with\n    | \u27e8[], _\u27e9  , \u27e8[], _\u27e9   => True\n    | \u27e8x::_, _\u27e9, \u27e8y::_, _\u27e9 => if x = y then lex_impl v\u2081.tail v\u2082.tail \n                              else x <= y\n\ndef Order.lex (v\u2081 v\u2082 : Variables n): Prop := Order.lex_impl v\u2081 v\u2082\n\ntheorem lex_le_refl : \u2200 (a : Variables n), Order.lex a a := by\n  intro a\n  let rec aux (m: Nat) (v: Variables m) : Order.lex_impl v v := by \n    match v with \n      | \u27e8[], p\u27e9    => rw [Order.lex_impl]\n                      split\n                      simp at *\n                      simp at p\n                      simp at *                                   \n      | \u27e8x::xs, _\u27e9 => rw [Order.lex_impl]\n                      split\n                      simp\n                      simp at *\n                      simp at *\n                      simp [Nat.le_refl]\n                      rename_i x\u2081 _ x\u2082 _ h\u2081 h\u2082\n                      have h\u2083 := Eq.symm h\u2081.left\n                      have h\u2084 := Eq.symm h\u2082.left\n                      rw [h\u2083, h\u2084]\n                      simp [Nat.le_refl]\n                      apply aux (m-1) (tail \u27e8x::xs, _\u27e9)\n  exact aux n a\n\ntheorem lex_le_trans : \u2200 (a b c : Variables n), Order.lex a b \u2192 Order.lex b c \u2192 Order.lex a c := by\n  intros v\u2081 v\u2082 v\u2083 h\u2081 h\u2082\n  let rec aux (m: Nat) (a b c: Variables m) \n              (ab : Order.lex_impl a b) (bc : Order.lex_impl b c) : Order.lex_impl a c := by \n    match a, b, c with\n      | \u27e8[], p\u27e9,    \u27e8[], q\u27e9,    \u27e8[], l\u27e9    => rw [Order.lex_impl]\n                                              split\n                                              simp\n                                              simp at *\n      | \u27e8x::xs, p\u27e9, \u27e8y::ys, q\u27e9, \u27e8z::zs, l\u27e9 => rw [Order.lex_impl] \n                                              rw [Order.lex_impl] at ab bc\n                                              split at ab\n                                              split at bc\n                                              split <;> simp at *\n                                              split at bc\n                                              split\n                                              repeat (first \n                                                | rename_i heq\u2081 heq\u2082 _ _ _ _ _ _ _ _ heq\u2083 heq\u2084 _ _\n                                                  rw [heq\u2082] at heq\u2083\n                                                  simp at heq\u2083 \n                                                | split)\n                                              split at ab\n                                              split at bc\n                                              rename_i heq\u2081 heq\u2082 _ _ _ _ _ _ heq\u2083 heq\u2084\n                                              rw [heq\u2082] at heq\u2083\n                                              simp at heq\u2083\n                                              split at bc\n                                              apply aux (m-1) (tail \u27e8x::xs, p\u27e9) (tail \u27e8y::ys, q\u27e9) (tail \u27e8z::zs, l\u27e9) ab bc\n                                              simp at *\n                                              rename_i eq\u2081 eq\u2082 _ _ _ _ _  _ _ _ hneq heq\u2081 heq\u2082 heq\u2083 heq\u2084 \n                                              have x_cross_one_eq_x := Eq.symm (heq\u2081.left)\n                                              have y_cross_one_eq_y := Eq.symm (heq\u2082.left)\n                                              have x_cross_eq_x     := Eq.symm (heq\u2083.left)\n                                              have y_cross_eq_x     := Eq.symm (heq\u2084.left)\n                                              rw [x_cross_eq_x, y_cross_eq_x] at hneq\n                                              rw [x_cross_one_eq_x, y_cross_one_eq_y] at eq\u2082\n                                              rw [eq\u2082] at eq\u2081\n                                              contradiction\n                                              split at bc\n                                              simp at *\n                                              repeat (first | rename_i heq\u2081 heq\u2082 eq\u2081 neq\u2081 _ _ _ _ _ _ _ _ heq\u2083 heq\u2084 eq\u2082\n                                                              simp at heq\u2081 heq\u2082 heq\u2083 heq\u2084\n                                                              have x_cross_one_eq_x := Eq.symm (heq\u2081.left)\n                                                              have y_cross_one_eq_y := Eq.symm (heq\u2082.left)\n                                                              have x_cross_eq_x     := Eq.symm (heq\u2083.left)\n                                                              have y_cross_eq_x     := Eq.symm (heq\u2084.left)\n                                                              rw [x_cross_eq_x, y_cross_eq_x] at eq\u2082\n                                                              rw [x_cross_one_eq_x, y_cross_one_eq_y] at neq\u2081\n                                                              rw [eq\u2082] at neq\u2081\n                                                              contradiction\n                                                            | split at bc)\n                                              rename_i heq\u2081 heq\u2082 eq\u2081 neq\u2081 _ _ _ _ _ _ _ _ heq\u2083 heq\u2084 neq\u2082 \n                                              simp at heq\u2081 heq\u2082 heq\u2083 heq\u2084\n                                              have x_cross_one_eq_x := Eq.symm (heq\u2081.left)\n                                              have y_cross_one_eq_y := Eq.symm (heq\u2082.left)\n                                              have x_cross_eq_x     := Eq.symm (heq\u2083.left)\n                                              have y_cross_eq_x     := Eq.symm (heq\u2084.left)\n                                              rw [x_cross_eq_x, y_cross_eq_x] at neq\u2082 bc\n                                              rw [x_cross_one_eq_x, y_cross_one_eq_y] at neq\u2081 ab\n                                              rw [eq\u2081] at ab\n                                              have eq_eq := Nat.le_antisymm bc ab\n                                              contradiction \n                                              split at ab\n                                              split at bc\n                                              simp at *\n                                              split at bc\n                                              simp at *\n                                              rename_i neq\u2081 eq\u2081 _ _ _ _ _ _ _ _ eq\u2082 heq\u2081 heq\u2082 heq\u2083 heq\u2084\n                                              have x_cross_one_eq_x := Eq.symm (heq\u2081.left)\n                                              have y_cross_one_eq_y := Eq.symm (heq\u2082.left)\n                                              have x_cross_eq_x     := Eq.symm (heq\u2083.left)\n                                              have y_cross_eq_x     := Eq.symm (heq\u2084.left)\n                                              rw [x_cross_one_eq_x, y_cross_one_eq_y] at eq\u2081\n                                              rw [x_cross_eq_x, y_cross_eq_x] at eq\u2082\n                                              rw [eq\u2082] at eq\u2081\n                                              contradiction\n                                              repeat (first | simp at *\n                                                              rename_i neq\u2081 eq\u2081 _ _ _ _ _ _ _ _ eq\u2082 heq\u2081 heq\u2082 heq\u2083 heq\u2084\n                                                              have x_cross_one_eq_x := Eq.symm (heq\u2081.left)\n                                                              have y_cross_one_eq_y := Eq.symm (heq\u2082.left)\n                                                              have x_cross_eq_x     := Eq.symm (heq\u2083.left)\n                                                              have y_cross_eq_x     := Eq.symm (heq\u2084.left)\n                                                              rw [x_cross_one_eq_x, y_cross_one_eq_y] at eq\u2081\n                                                              rw [x_cross_eq_x, y_cross_eq_x] at bc\n                                                              rw [eq\u2081]\n                                                              exact bc\n                                                            | split at bc)\n                                              simp at *\n                                              split at bc <;> (simp at *\n                                                               rename_i neq\u2081 neq\u2082 _ _ _ _ _ _ _ _ _ heq\u2081 heq\u2082 heq\u2083 heq\u2084\n                                                               have x_cross_one_eq_x := Eq.symm (heq\u2081.left)\n                                                               have y_cross_one_eq_y := Eq.symm (heq\u2082.left)\n                                                               have x_cross_eq_x     := Eq.symm (heq\u2083.left)\n                                                               have y_cross_eq_x     := Eq.symm (heq\u2084.left))\n                                              rename_i eq\n                                              rw [x_cross_one_eq_x, y_cross_one_eq_y] at neq\u2082 ab\n                                              rw [x_cross_eq_x, y_cross_eq_x] at eq\n                                              rw [eq] at ab\n                                              exact ab\n                                              rename_i neq\u2083\n                                              rw [x_cross_one_eq_x, y_cross_one_eq_y] at neq\u2082 ab\n                                              rw [x_cross_eq_x, y_cross_eq_x] at neq\u2083 bc\n                                              have le_le := Nat.le_trans ab bc\n                                              exact le_le                        \n  exact aux n v\u2081 v\u2082 v\u2083 h\u2081 h\u2082\n\ntheorem lex_le_antisymm : \u2200 (a b : Variables n), Order.lex a b \u2192 Order.lex b a \u2192 a = b := by\n  intros v\u2081 v\u2082 h\u2081 h\u2082\n  let rec aux (m: Nat) (a b: Vector Nat m) (ab: Order.lex_impl a b) (ba: Order.lex_impl b a): a = b := by \n    match a, b with\n      | \u27e8[], p\u27e9, \u27e8[], q\u27e9       => simp \n      | \u27e8x::xs, p\u27e9, \u27e8y::ys, q\u27e9 => rw [Order.lex_impl] at ab ba\n                                  simp at *\n                                  split at ab\n                                  split at ba\n                                  rename_i heq\u2081 heq\u2082\n                                  simp [Vector]\n                                  constructor\n                                  exact heq\u2081 \n                                  have eq := aux (m-1) (tail \u27e8x::xs, p\u27e9) (tail \u27e8y::ys, q\u27e9) ab ba\n                                  simp [tail, Vector] at eq\n                                  exact eq\n                                  rename_i eq neq\n                                  have eq_symm := Eq.symm eq\n                                  contradiction\n                                  split at ba\n                                  rename_i neq eq\n                                  have eq_symm := Eq.symm eq\n                                  contradiction\n                                  rename_i neq\u2081 neq\u2082\n                                  have eq := Nat.le_antisymm ab ba\n                                  contradiction\n  exact aux n v\u2081 v\u2082 h\u2081 h\u2082 \n\ntheorem lex_le_total : \u2200 (a b : Variables n), Order.lex a b \u2228 Order.lex b a := by\n  intros v\u2081 v\u2082\n  let rec aux (m: Nat) (a b: Vector Nat m) : Order.lex_impl a b \u2228 Order.lex_impl b a := by\n    match a, b with\n      | \u27e8[], p\u27e9, \u27e8[], q\u27e9       => rw [Order.lex_impl]\n                                  split\n                                  simp\n                                  simp at *\n      | \u27e8x::xs, p\u27e9, \u27e8y::ys, q\u27e9 => rw [Order.lex_impl]\n                                  simp [Or.comm]\n                                  rw [Order.lex_impl]\n                                  split\n                                  simp\n                                  split\n                                  split\n                                  simp [Or.comm]\n                                  apply aux (m-1) (tail \u27e8x::xs, p\u27e9) (tail \u27e8y::ys, q\u27e9)\n                                  simp at *\n                                  rename_i eq neq heq\u2081 heq\u2082\n                                  have s_eq := Eq.symm eq\n                                  have eq_1 := Eq.symm heq\u2081.left\n                                  have eq_2 := Eq.symm heq\u2082.left\n                                  rw [eq_1, eq_2] at s_eq\n                                  contradiction\n                                  split\n                                  simp at *\n                                  rename_i neq eq heq\u2081 heq\u2082\n                                  have s_eq := Eq.symm eq\n                                  have eq_1 := heq\u2081.left\n                                  have eq_2 := heq\u2082.left\n                                  rw [eq_1, eq_2] at s_eq\n                                  contradiction\n                                  simp at *\n                                  rename_i heq\u2081 heq\u2082\n                                  have eq_1 := heq\u2081.left\n                                  have eq_2 := heq\u2082.left\n                                  rw [eq_1, eq_2]\n                                  simp [Nat.le_total]\n  exact aux n v\u2081 v\u2082\n\ntheorem Order.lex_true_of_ble_lex_true (h: Eq (Order.ble_lex_impl v\u2081 v\u2082) true): Order.lex v\u2081 v\u2082 := by\n  let rec aux (m: Nat) (a b: Vector Nat m) (h: Eq (Order.ble_lex_impl a b) true): Order.lex a b := by\n    rw [Order.lex]\n    rw [Order.lex_impl]\n    match a, b with\n      | \u27e8[], _\u27e9  , \u27e8[], _\u27e9     => simp\n      | \u27e8x::xs, _\u27e9, \u27e8y::ys, _\u27e9 => split\n                                  simp\n                                  split\n                                  rw [Order.ble_lex_impl] at h\n                                  simp at h\n                                  split at h\n                                  exact aux (m-1) (tail \u27e8x::xs, _\u27e9) (tail \u27e8y::ys, _\u27e9) h\n                                  simp at *\n                                  rename_i heq\u2081 hneq heq\u2082 heq\u2083\n                                  have eq\u2081 := heq\u2082.left\n                                  have eq\u2082 := heq\u2083.left\n                                  rw [eq\u2081, eq\u2082] at hneq\n                                  contradiction                                  \n                                  rename_i heq\u2081 heq\u2082 hneq\u2081 \n                                  rw [Order.ble_lex_impl] at h\n                                  split at h\n                                  simp at *\n                                  split at h\n                                  rename_i heq\u2083 heq\u2084 hneq\u2082\n                                  simp at heq\u2081 heq\u2082 heq\u2083 heq\u2084 hneq\u2082\n                                  have eq\u2081 := heq\u2081.left\n                                  have eq\u2082 := heq\u2082.left\n                                  have eq\u2083 := heq\u2083.left\n                                  have eq\u2084 := heq\u2084.left\n                                  rw [eq\u2081] at eq\u2083\n                                  rw [eq\u2082] at eq\u2084\n                                  rw [eq\u2083, eq\u2084] at hneq\u2081\n                                  contradiction\n                                  simp at h\n                                  rename_i heq\u2081 heq\u2082 _ _ _ _ _ _ _ _ _ _ _ heq\u2083 heq\u2084 _ \n                                  simp at heq\u2081 heq\u2082 heq\u2083 heq\u2084\n                                  have eq\u2081 := heq\u2081.left\n                                  have eq\u2082 := heq\u2082.left\n                                  have eq\u2083 := heq\u2083.left\n                                  have eq\u2084 := heq\u2084.left\n                                  rw [eq\u2081] at eq\u2083\n                                  rw [eq\u2082] at eq\u2084\n                                  rw [eq\u2083, eq\u2084]\n                                  exact h                                \n  rename_i n\n  exact aux n v\u2081 v\u2082 h                                 \n\ntheorem Order.ble_eq_true_of_lex (h: Order.lex_impl v\u2081 v\u2082) : Eq (Order.ble_lex_impl v\u2081 v\u2082) true := by\n  let rec aux (m: Nat) (a b: Vector Nat m) (h: Order.lex_impl a b): Eq (Order.ble_lex_impl a b) true := by \n     match a, b with\n      | \u27e8[], _\u27e9, \u27e8[], _\u27e9       => rw [Order.ble_lex_impl]\n      | \u27e8x::xs, _\u27e9, \u27e8y::ys, _\u27e9 => rw [Order.ble_lex_impl]\n                                  split;rfl\n                                  split\n                                  rw [lex_impl] at h\n                                  simp at h\n                                  split at h\n                                  apply Order.ble_eq_true_of_lex h\n                                  rename_i heq\u2081 heq\u2082 neq eq\n                                  simp at heq\u2081 heq\u2082\n                                  have eq\u2081 := heq\u2081.left\n                                  have eq\u2082 := heq\u2082.left\n                                  simp at neq\n                                  rw [eq\u2081, eq\u2082] at eq\n                                  contradiction\n                                  rw [lex_impl] at h\n                                  simp at h\n                                  split at h\n                                  rename_i heq\u2081 heq\u2082 neq eq\n                                  simp at heq\u2081 heq\u2082\n                                  have eq\u2081 := heq\u2081.left\n                                  have eq\u2082 := heq\u2082.left\n                                  simp at neq\n                                  rw [eq\u2081, eq\u2082] at eq\n                                  contradiction\n                                  simp\n                                  rename_i heq\u2081 heq\u2082 _ _\n                                  simp at heq\u2081 heq\u2082\n                                  have eq\u2081 := Eq.symm heq\u2081.left\n                                  have eq\u2082 := Eq.symm heq\u2082.left\n                                  rwa [eq\u2081, eq\u2082]\n  rename_i n\n  exact aux n v\u2081 v\u2082 h \n\ntheorem Order.lex_false_of_ble_lex_false (h: Not (Eq (Order.ble_lex_impl v\u2081 v\u2082) true)): Not (Order.lex v\u2081 v\u2082) :=\n  fun h' => absurd (Order.ble_eq_true_of_lex h') h\n\ninstance Order.lex_decidable (v\u2081 v\u2082: Variables n): Decidable (Order.lex v\u2081 v\u2082) :=\n  dite (Eq (Order.ble_lex_impl v\u2081 v\u2082) true) (fun h => isTrue (Order.lex_true_of_ble_lex_true h))\n                                            (fun h => isFalse (Order.lex_false_of_ble_lex_false h))\n\ninstance LexOrder: LinearOrder (Variables n) where\n  le           := Order.lex \n  le_refl      := lex_le_refl\n  le_trans     := lex_le_trans\n  le_antisymm  := lex_le_antisymm\n  le_total     := lex_le_total\n  decidable_le := Order.lex_decidable\n\ndef Ordering.lex (m\u2081 m\u2082: Monomial n): Ordering := \n  if m\u2081.snd = m\u2082.snd then Ordering.eq\n  else if Order.lex m\u2081.snd m\u2082.snd then Ordering.gt\n  else Ordering.lt\n\nend monomials_lex_order\n\n\nsection monomials_grlex_order\n\nprivate def Order.bgrlex (vs\u2081 vs\u2082: Variables n): Bool :=\n  let sum\u2081 := elem_sum vs\u2081 \n  let sum\u2082 := elem_sum vs\u2082   \n  if sum\u2081 < sum\u2082 then true\n  else if sum\u2081 = sum\u2082 then Order.lex vs\u2081 vs\u2082\n  else false\n  where\n    elem_sum (vs: Variables n): Nat :=\n      List.foldl (fun x y => x + y) 0 vs.toList\n\ndef Order.grlex (vs\u2081 vs\u2082: Variables n): Prop :=\n  let sum\u2081 := elem_sum vs\u2081 \n  let sum\u2082 := elem_sum vs\u2082   \n  if sum\u2081 < sum\u2082 then True\n  else if sum\u2081 = sum\u2082 then Order.lex vs\u2081 vs\u2082\n  else False\n  where\n    elem_sum (vs: Variables n): Nat :=\n      List.foldl (fun x y => x + y) 0 vs.toList\n\ntheorem grlex_le_refl: \u2200 (a : Variables n), Order.grlex a a := by \n  intros a\n  simp [Order.grlex]\n  apply lex_le_refl\n\ntheorem grlex_le_trans : \u2200 (a b c : Variables n), Order.grlex a b \u2192 Order.grlex b c \u2192 Order.grlex a c := by\n  intros a b c ab bc\n  simp [Order.grlex]\n  simp [Order.grlex] at ab bc\n  split <;> simp\n  split at ab\n  split at bc <;> split\n  rename_i nleq leq\u2081 leq\u2082 eq\n  rw [eq] at leq\u2081\n  simp at *\n  have asymm_leq\u2081 := Nat.lt_asymm leq\u2081\n  contradiction\n  rename_i nleq leq\u2081 leq\u2082 neq\n  have contr := Nat.lt_trans leq\u2081 leq\u2082 \n  contradiction\n  split at bc\n  rename_i nleq\u2081 leq\u2081 nleq\u2082 eq\u2081 eq\u2082\n  rw [eq\u2082] at leq\u2081\n  repeat contradiction\n  split at bc\n  rename_i nleq\u2081 leq\u2081 nleq\u2082 neq\u2081 eq\u2082\n  rw [eq\u2082] at leq\u2081\n  repeat contradiction\n  split <;> (split at ab; split at bc)\n  rename_i nleq\u2081 nleq\u2082 eq\u2081 eq\u2082 leq\n  have seq := Eq.symm eq\u2082\n  rw [seq] at leq\n  contradiction\n  split at bc\n  rename_i nleq\u2081 nleq\u2082 eq\u2081 eq\u2082 neq\u2081 eq\u2083\n  simp at *\n  apply lex_le_trans\n  exact ab\n  exact bc\n  repeat contradiction\n  rename_i nleq\u2081 nleq\u2082 neq\u2081 eq leq\n  rw [eq] at nleq\u2081\n  contradiction\n  split at bc\n  rename_i nleq\u2081 nleq\u2082 neq eq\u2081 nleq\u2083 eq\u2082\n  rw [eq\u2081] at neq\n  repeat contradiction\n  \ntheorem grlex_le_antisymm : \u2200 (a b : Variables n), Order.grlex a b \u2192 Order.grlex b a \u2192 a = b := by \n  intros a b ab ba\n  simp [Order.grlex] at ab ba\n  split at ab\n  split at ba\n  rename_i leq\u2081 leq\u2082\n  have asymm_leq\u2081 := Nat.lt_asymm leq\u2081\n  contradiction\n  split at ba\n  rename_i leq nleq eq\n  rw [eq] at leq\n  simp at leq\n  contradiction\n  split at ab\n  split at ba\n  rename_i nleq eq leq\n  have symm := Eq.symm eq\n  rw [symm] at leq\n  simp at leq\n  split at ba\n  apply lex_le_antisymm \n  exact ab\n  exact ba\n  repeat contradiction\n\ntheorem grlex_le_total : \u2200 (a b : Variables n), Order.grlex a b \u2228 Order.grlex b a := by \n  intros a b\n  simp [Order.grlex]\n  split <;> simp\n  split <;> repeat (first | split | simp)\n  simp [lex_le_total] \n  rename_i nleq\u2081 eq nleq\u2082 neq\n  have contr := Eq.symm eq \n  contradiction\n  rename_i nleq\u2081 neq nleq\u2082 eq\n  have contr := Eq.symm eq \n  contradiction\n  simp\n  rename_i nleq\u2081 neq nleq\u2082 eq\n  simp at *\n  have contr := Nat.le_antisymm nleq\u2081 nleq\u2082\n  contradiction\n\ntheorem grlex_true_of_ble_grlex_true (h: Eq (Order.bgrlex v\u2081 v\u2082) true): Order.grlex v\u2081 v\u2082 := by\n  simp [Order.grlex]\n  split\n  simp\n  split\n  simp [algebra.Order.bgrlex] at h\n  split at h\n  simp at h\n  simp at *\n  rw [Order.grlex.elem_sum, Order.grlex.elem_sum] at *\n  rw [algebra.Order.bgrlex.elem_sum, algebra.Order.bgrlex.elem_sum] at *\n  rename_i hh\n  simp [hh] at h\n  exact h\n  rename_i nleq eq _\n  contradiction\n  simp [algebra.Order.bgrlex] at h\n  split at h\n  contradiction\n  rename_i nleq neq\u2081 neq\u2082\n  have leq := Nat.le_of_not_lt nleq\n  exact h leq\n\ntheorem grble_eq_true_of_grlex (h: Order.grlex v\u2081 v\u2082): Eq (Order.bgrlex v\u2081 v\u2082) true := by\n  simp [Order.grlex] at h\n  split at h\n  simp [algebra.Order.bgrlex]\n  split\n  rename_i h\n  have le := Nat.le_of_eq h\n  simp [h]\n  rename_i hle _ \n  rw [Order.grlex.elem_sum, Order.grlex.elem_sum] at hle\n  rw [algebra.Order.bgrlex.elem_sum, algebra.Order.bgrlex.elem_sum] at h\n  rw [h] at hle\n  simp at hle\n  rename_i le neq\n  intros nleq\n  have le_contr := Nat.not_lt_of_le nleq\n  rw [Order.grlex.elem_sum, Order.grlex.elem_sum] at le\n  rw [algebra.Order.bgrlex.elem_sum, algebra.Order.bgrlex.elem_sum] at le_contr\n  contradiction\n  split at h\n  simp [algebra.Order.bgrlex]\n  intros le\n  split\n  exact h\n  rename_i nlt eq neq\n  rw [Order.grlex.elem_sum, Order.grlex.elem_sum] at nlt eq\n  rw [algebra.Order.bgrlex.elem_sum, algebra.Order.bgrlex.elem_sum] at le neq\n  repeat contradiction\n\ntheorem grlex_false_of_ble_grlex_false (h: Not (Eq (Order.bgrlex v\u2081 v\u2082) true)): Not (Order.grlex v\u2081 v\u2082) := \n  fun h' => absurd (grble_eq_true_of_grlex h') h\n  \ninstance Order.grlex_decidable (v\u2081 v\u2082: Variables n): Decidable (Order.grlex v\u2081 v\u2082) := \n  dite (Eq (Order.bgrlex v\u2081 v\u2082) true) (fun h => isTrue (grlex_true_of_ble_grlex_true h))\n                                      (fun h => isFalse (grlex_false_of_ble_grlex_false h))\n  \n-- instance GrlexOrder: LinearOrder (Variables n) where\n--   le           := Order.grlex \n--   le_refl      := grlex_le_refl\n--   le_trans     := grlex_le_trans\n--   le_antisymm  := grlex_le_antisymm\n--   le_total     := grlex_le_total\n--   decidable_le := Order.grlex_decidable\n\ndef Ordering.grlex (m\u2081 m\u2082: Monomial n): Ordering :=\n  if m\u2081.snd = m\u2082.snd then Ordering.eq\n  else if Order.grlex m\u2081.snd m\u2082.snd then Ordering.gt\n  else Ordering.lt\n\nend monomials_grlex_order\n\nend algebra\n", "meta": {"author": "NiclausCarlson", "repo": "Diploma", "sha": "2fcfa73cb3023df96ec7eaaf2b02efcc3979e3f5", "save_path": "github-repos/lean/NiclausCarlson-Diploma", "path": "github-repos/lean/NiclausCarlson-Diploma/Diploma-2fcfa73cb3023df96ec7eaaf2b02efcc3979e3f5/Diploma/Algebra/MonomialOrder.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7105273818142466}}
{"text": "/-\nCopyright (c) 2022 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis, Heather Macbeth\n-/\n\nimport field_theory.is_alg_closed.basic\nimport ring_theory.witt_vector.discrete_valuation_ring\n\n/-!\n# Solving equations about the Frobenius map on the field of fractions of `\ud835\udd4e k`\n\nThe goal of this file is to prove `witt_vector.exists_frobenius_solution_fraction_ring`,\nwhich says that for an algebraically closed field `k` of characteristic `p` and `a, b` in the\nfield of fractions of Witt vectors over `k`,\nthere is a solution `b` to the equation `\u03c6 b * a = p ^ m * b`, where `\u03c6` is the Frobenius map.\n\nMost of this file builds up the equivalent theorem over `\ud835\udd4e k` directly,\nmoving to the field of fractions at the end.\nSee `witt_vector.frobenius_rotation` and its specification.\n\nThe construction proceeds by recursively defining a sequence of coefficients as solutions to a\npolynomial equation in `k`. We must define these as generic polynomials using Witt vector API\n(`witt_vector.witt_mul`, `witt_polynomial`) to show that they satisfy the desired equation.\n\nPreliminary work is done in the dependency `ring_theory.witt_vector.mul_coeff`\nto isolate the `n+1`st coefficients of `x` and `y` in the `n+1`st coefficient of `x*y`.\n\nThis construction is described in Dupuis, Lewis, and Macbeth,\n[Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022].\nWe approximately follow an approach sketched on MathOverflow:\n<https://mathoverflow.net/questions/62468/about-frobenius-of-witt-vectors>\n\nThe result is a dependency for the proof of `witt_vector.isocrystal_classification`,\nthe classification of one-dimensional isocrystals over an algebraically closed field.\n-/\n\nnoncomputable theory\n\nnamespace witt_vector\n\nvariables (p : \u2115) [hp : fact p.prime]\nlocal notation `\ud835\udd4e` := witt_vector p\n\nnamespace recursion_main\n\n/-!\n\n## The recursive case of the vector coefficients\n\nThe first coefficient of our solution vector is easy to define below.\nIn this section we focus on the recursive case.\nThe goal is to turn `witt_poly_prod n` into a univariate polynomial\nwhose variable represents the `n`th coefficient of `x` in `x * a`.\n\n-/\n\nsection comm_ring\ninclude hp\nvariables {k : Type*} [comm_ring k] [char_p k p]\nopen polynomial\n\n/-- The root of this polynomial determines the `n+1`st coefficient of our solution. -/\ndef succ_nth_defining_poly (n : \u2115) (a\u2081 a\u2082 : \ud835\udd4e k) (bs : fin (n+1) \u2192 k) : polynomial k :=\nX^p * C (a\u2081.coeff 0 ^ (p^(n+1))) - X * C (a\u2082.coeff 0 ^ (p^(n+1)))\n  + C (a\u2081.coeff (n+1) * ((bs 0)^p)^(p^(n+1)) +\n      nth_remainder p n (\u03bb v, (bs v)^p) (truncate_fun (n+1) a\u2081) -\n      a\u2082.coeff (n+1) * (bs 0)^p^(n+1) - nth_remainder p n bs (truncate_fun (n+1) a\u2082))\n\nlemma succ_nth_defining_poly_degree [is_domain k] (n : \u2115) (a\u2081 a\u2082 : \ud835\udd4e k) (bs : fin (n+1) \u2192 k)\n  (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) :\n  (succ_nth_defining_poly p n a\u2081 a\u2082 bs).degree = p :=\nbegin\n  have : (X ^ p * C (a\u2081.coeff 0 ^ p ^ (n+1))).degree = p,\n  { rw [degree_mul, degree_C],\n    { simp only [nat.cast_with_bot, add_zero, degree_X, degree_pow, nat.smul_one_eq_coe] },\n    { exact pow_ne_zero _ ha\u2081 } },\n  have : (X ^ p * C (a\u2081.coeff 0 ^ p ^ (n+1)) - X * C (a\u2082.coeff 0 ^ p ^ (n+1))).degree = p,\n  { rw [degree_sub_eq_left_of_degree_lt, this],\n    rw [this, degree_mul, degree_C, degree_X, add_zero],\n    { exact_mod_cast hp.out.one_lt },\n    { exact pow_ne_zero _ ha\u2082 } },\n  rw [succ_nth_defining_poly, degree_add_eq_left_of_degree_lt, this],\n  apply lt_of_le_of_lt (degree_C_le),\n  rw [this],\n  exact_mod_cast hp.out.pos\nend\n\nend comm_ring\n\nsection is_alg_closed\ninclude hp\nvariables {k : Type*} [field k] [char_p k p] [is_alg_closed k]\n\nlemma root_exists (n : \u2115) (a\u2081 a\u2082 : \ud835\udd4e k) (bs : fin (n+1) \u2192 k)\n  (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) :\n  \u2203 b : k, (succ_nth_defining_poly p n a\u2081 a\u2082 bs).is_root b :=\nis_alg_closed.exists_root _ $\n  by simp [(succ_nth_defining_poly_degree p n a\u2081 a\u2082 bs ha\u2081 ha\u2082), hp.out.ne_zero]\n\n/-- This is the `n+1`st coefficient of our solution, projected from `root_exists`. -/\ndef succ_nth_val (n : \u2115) (a\u2081 a\u2082 : \ud835\udd4e k) (bs : fin (n+1) \u2192 k)\n  (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) : k :=\nclassical.some (root_exists p n a\u2081 a\u2082 bs ha\u2081 ha\u2082)\n\nlemma succ_nth_val_spec (n : \u2115) (a\u2081 a\u2082 : \ud835\udd4e k) (bs : fin (n+1) \u2192 k)\n  (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) :\n  (succ_nth_defining_poly p n a\u2081 a\u2082 bs).is_root (succ_nth_val p n a\u2081 a\u2082 bs ha\u2081 ha\u2082) :=\nclassical.some_spec (root_exists p n a\u2081 a\u2082 bs ha\u2081 ha\u2082)\n\nlemma succ_nth_val_spec' (n : \u2115) (a\u2081 a\u2082 : \ud835\udd4e k) (bs : fin (n+1) \u2192 k)\n  (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) :\n  (succ_nth_val p n a\u2081 a\u2082 bs ha\u2081 ha\u2082)^p * a\u2081.coeff 0 ^ (p^(n+1)) +\n    a\u2081.coeff (n+1) * ((bs 0)^p)^(p^(n+1)) +\n    nth_remainder p n (\u03bb v, (bs v)^p) (truncate_fun (n+1) a\u2081)\n   = (succ_nth_val p n a\u2081 a\u2082 bs ha\u2081 ha\u2082) * a\u2082.coeff 0 ^ (p^(n+1)) +\n     a\u2082.coeff (n+1) * (bs 0)^(p^(n+1)) + nth_remainder p n bs (truncate_fun (n+1) a\u2082) :=\nbegin\n  rw \u2190 sub_eq_zero,\n  have := succ_nth_val_spec p n a\u2081 a\u2082 bs ha\u2081 ha\u2082,\n  simp only [polynomial.map_add, polynomial.eval_X, polynomial.map_pow, polynomial.eval_C,\n    polynomial.eval_pow, succ_nth_defining_poly, polynomial.eval_mul, polynomial.eval_add,\n    polynomial.eval_sub, polynomial.map_mul, polynomial.map_sub, polynomial.is_root.def] at this,\n  convert this using 1,\n  ring\nend\n\nend is_alg_closed\nend recursion_main\n\nnamespace recursion_base\ninclude hp\nvariables {k : Type*} [field k] [is_alg_closed k]\n\nlemma solution_pow (a\u2081 a\u2082 : \ud835\udd4e k) :\n  \u2203 x : k, x^(p-1) = a\u2082.coeff 0 / a\u2081.coeff 0 :=\nis_alg_closed.exists_pow_nat_eq _ $ by linarith [hp.out.one_lt, le_of_lt hp.out.one_lt]\n\n/-- The base case (0th coefficient) of our solution vector. -/\ndef solution (a\u2081 a\u2082 : \ud835\udd4e k) : k :=\nclassical.some $ solution_pow p a\u2081 a\u2082\n\nlemma solution_spec (a\u2081 a\u2082 : \ud835\udd4e k) :\n  (solution p a\u2081 a\u2082)^(p-1) = a\u2082.coeff 0 / a\u2081.coeff 0 :=\nclassical.some_spec $ solution_pow p a\u2081 a\u2082\n\nlemma solution_nonzero {a\u2081 a\u2082 : \ud835\udd4e k} (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) :\n  solution p a\u2081 a\u2082 \u2260 0 :=\nbegin\n  intro h,\n  have := solution_spec p a\u2081 a\u2082,\n  rw [h, zero_pow] at this,\n  { simpa [ha\u2081, ha\u2082] using _root_.div_eq_zero_iff.mp this.symm },\n  { linarith [hp.out.one_lt, le_of_lt hp.out.one_lt] }\nend\n\nlemma solution_spec' {a\u2081 : \ud835\udd4e k} (ha\u2081 : a\u2081.coeff 0 \u2260 0) (a\u2082 : \ud835\udd4e k) :\n  (solution p a\u2081 a\u2082)^p * a\u2081.coeff 0 = (solution p a\u2081 a\u2082) * a\u2082.coeff 0 :=\nbegin\n  have := solution_spec p a\u2081 a\u2082,\n  cases nat.exists_eq_succ_of_ne_zero hp.out.ne_zero with q hq,\n  have hq' : q = p - 1 := by simp only [hq, tsub_zero, nat.succ_sub_succ_eq_sub],\n  conv_lhs {congr, congr, skip, rw hq},\n  rw [pow_succ', hq', this],\n  field_simp [ha\u2081, mul_comm],\nend\n\nend recursion_base\n\nopen recursion_main recursion_base\n\nsection frobenius_rotation\n\nsection is_alg_closed\ninclude hp\nvariables {k : Type*} [field k] [char_p k p] [is_alg_closed k]\n\n/--\nRecursively defines the sequence of coefficients for `witt_vector.frobenius_rotation`.\n-/\nnoncomputable def frobenius_rotation_coeff {a\u2081 a\u2082 : \ud835\udd4e k}\n  (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) : \u2115 \u2192 k\n| 0       := solution p a\u2081 a\u2082\n| (n + 1) := succ_nth_val p n a\u2081 a\u2082 (\u03bb i, frobenius_rotation_coeff i.val) ha\u2081 ha\u2082\nusing_well_founded { dec_tac := `[apply fin.is_lt] }\n\n/--\nFor nonzero `a\u2081` and `a\u2082`, `frobenius_rotation a\u2081 a\u2082` is a Witt vector that satisfies the\nequation `frobenius (frobenius_rotation a\u2081 a\u2082) * a\u2081 = (frobenius_rotation a\u2081 a\u2082) * a\u2082`.\n-/\ndef frobenius_rotation {a\u2081 a\u2082 : \ud835\udd4e k} (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) : \ud835\udd4e k :=\nwitt_vector.mk p (frobenius_rotation_coeff p ha\u2081 ha\u2082)\n\nlemma frobenius_rotation_nonzero {a\u2081 a\u2082 : \ud835\udd4e k} (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) :\n  frobenius_rotation p ha\u2081 ha\u2082 \u2260 0 :=\nbegin\n  intro h,\n  apply solution_nonzero p ha\u2081 ha\u2082,\n  simpa [\u2190 h, frobenius_rotation, frobenius_rotation_coeff] using witt_vector.zero_coeff p k 0\nend\n\nlemma frobenius_frobenius_rotation {a\u2081 a\u2082 : \ud835\udd4e k} (ha\u2081 : a\u2081.coeff 0 \u2260 0) (ha\u2082 : a\u2082.coeff 0 \u2260 0) :\n  frobenius (frobenius_rotation p ha\u2081 ha\u2082) * a\u2081 = (frobenius_rotation p ha\u2081 ha\u2082) * a\u2082 :=\nbegin\n  ext n,\n  induction n with n ih,\n  { simp only [witt_vector.mul_coeff_zero, witt_vector.coeff_frobenius_char_p,\n      frobenius_rotation, frobenius_rotation_coeff],\n    apply solution_spec' _ ha\u2081 },\n  { simp only [nth_remainder_spec, witt_vector.coeff_frobenius_char_p, frobenius_rotation_coeff,\n      frobenius_rotation, fin.val_eq_coe],\n    have := succ_nth_val_spec' p n a\u2081 a\u2082\n      (\u03bb (i : fin (n + 1)), frobenius_rotation_coeff p ha\u2081 ha\u2082 i.val) ha\u2081 ha\u2082,\n    simp only [frobenius_rotation_coeff, fin.val_eq_coe, fin.val_zero] at this,\n    convert this using 4,\n    apply truncated_witt_vector.ext,\n    intro i,\n    simp only [fin.val_eq_coe, witt_vector.coeff_truncate_fun, witt_vector.coeff_frobenius_char_p],\n    refl }\nend\n\nlocal notation `\u03c6` := is_fraction_ring.field_equiv_of_ring_equiv\n  (ring_equiv.of_bijective _ (frobenius_bijective p k))\n\n\n\nend is_alg_closed\n\nend frobenius_rotation\n\nend witt_vector\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/ring_theory/witt_vector/frobenius_fraction_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.710508818416489}}
{"text": "open set\n\n/- \nalunos:\n    - Lucas Machado Moschen\n-/\n\n-- ex 1\n\nsection\n    variable U : Type\n    variables A B C : set U\n\n    example : \u2200 x, x \u2208 A \u2229 C \u2192 x \u2208 A \u222a B :=\n    assume x,\n    assume h: x \u2208 A \u2229 C,\n    show x \u2208 A \u222a B, from or.inl h.left\n\n    example : \u2200 x, x \u2208 -(A \u222a B) \u2192 x \u2208 -A :=\n    assume x, \n    assume : x \u2208 -(A \u222a B),\n    have \u00ac x \u2208 (A \u222a B), from this,\n    assume : x \u2208 A, \n    show false, from \u2039\u00ac x \u2208 (A \u222a B)\u203a (or.inl this)\nend\n\n\n-- ex 2\n\nsection\n    variable {U : Type}\n\n    /- defining \"disjoint\" -/\n\n    def disj (A B : set U) : Prop := \u2200 \u2983x\u2984, x \u2208 A \u2192 x \u2208 B \u2192 false\n\n    example (A B : set U) (h : \u2200 x, \u00ac (x \u2208 A \u2227 x \u2208 B)) :\n    disj A B :=\n    assume x,\n    assume h1 : x \u2208 A,\n    assume h2 : x \u2208 B,\n    have h3 : x \u2208 A \u2227 x \u2208 B, from and.intro h1 h2,\n    show false, from h x h3\n\n    -- notice that we do not have to mention x when applying\n    --   h : disj A B\n    example (A B : set U) (h1 : disj A B) (x : U)\n        (h2 : x \u2208 A) (h3 : x \u2208 B) :\n    false :=\n    h1 h2 h3\n\n    -- the same is true of \u2286\n    example (A B : set U) (x : U) (h : A \u2286 B) (h1 : x \u2208 A) :\n    x \u2208 B :=\n    h h1\n\n    example (A B C D : set U) (h1 : disj A B) (h2 : C \u2286 A)\n        (h3 : D \u2286 B) :\n    disj C D :=\n    assume x,   \n    assume g1: x \u2208 C,\n    assume g2: x \u2208 D,\n    have g3: x \u2208 A, from h2 g1,\n    have g4: x \u2208 B, from h3 g2, \n    show false, from h1 g3 g4\nend\n\n-- ex 3\n\nsection\n    variables {I U : Type}\n    variables {A : I \u2192 set U} {B : I \u2192 set U} {C : set U}\n\n    def Union (A : I \u2192 set U) : set U := { x | \u2203 i : I, x \u2208 A i }\n    def Inter (A : I \u2192 set U) : set U := { x | \u2200 i : I, x \u2208 A i }\n\n    notation `\u22c3` binders `, ` r:(scoped f, Union f) := r\n    notation `\u22c2` binders `, ` r:(scoped f, Inter f) := r\n\n    theorem Inter.intro {x : U} (h : \u2200 i, x \u2208 A i) : x \u2208 \u22c2 i, A i :=\n        by simp; assumption\n\n    @[elab_simple]\n    theorem Inter.elim {x : U} (h : x \u2208 \u22c2 i, A i) (i : I) : x \u2208 A i :=\n        by simp at h; apply h\n\n    theorem Union.intro {x : U} (i : I) (h : x \u2208 A i) :\n    x \u2208 \u22c3 i, A i :=\n        by {simp, existsi i, exact h}\n\n    theorem Union.elim {b : Prop} {x : U}\n    (h\u2081 : x \u2208 \u22c3 i, A i) (h\u2082 : \u2200 (i : I), x \u2208 A i \u2192 b) : b :=\n        by {simp at h\u2081, cases h\u2081 with i h, exact h\u2082 i h}\n\n    example : (\u22c2 i, A i) \u2229 (\u22c2 i, B i) \u2286 (\u22c2 i, A i \u2229 B i) :=\n        assume x,\n        assume h: x \u2208 (\u22c2 i, A i) \u2229 (\u22c2 i, B i), \n        show x \u2208 (\u22c2 i, A i \u2229 B i), from \n            Inter.intro \n            (assume i: I,\n            have h1: x \u2208 A i, from Inter.elim h.left i,\n            have h2: x \u2208 B i, from Inter.elim h.right i,\n            show x \u2208 A i \u2229 B i, from and.intro h1 h2)\n\n    example : C \u2229 (\u22c3i, A i) \u2286 \u22c3i, C \u2229 A i :=\n        assume x : U,\n        assume h : x \u2208 C \u2229 (\u22c3i, A i),\n        show x \u2208 \u22c3 i, C \u2229 A i, from\n            Union.elim h.right \n            (assume i : I,\n            assume h1: x \u2208 A i,\n            show  x \u2208 \u22c3 i, C \u2229 A i, from \n                Union.intro i (and.intro h.left h1))\nend\n\n-- ex 4\n\nsection \n    variable  {U : Type}\n    variables A B C : set U\n\n    @[refl] theorem subset.refl (a : set U) : a \u2286 a := assume x, id\n\n    @[trans] theorem subset.trans {a b c : set U} (ab : a \u2286 b) (bc : b \u2286 c) : a \u2286 c :=\n        assume x h, bc (ab h)\n\n    example (h1 : A \u2286 B) (h2 : B \u2286 C) : A \u2286 C :=\n        subset.trans h1 h2\n\n    example : A \u2286 A :=\n        subset.refl A\n\n    example (h : A \u2286 B) : powerset A \u2286 powerset B :=\n        assume X : set U,\n        assume h1 : X \u2208 powerset A,\n        show X \u2208 powerset B, from subset.trans h1 h\n\n    example (h : powerset A \u2286 powerset B) : A \u2286 B :=\n        assume x: U,\n        assume h1 : x \u2208 A,\n        have h2: {y|x = y} \u2208 powerset A, from \n            assume z,\n            assume : z \u2208 {y| x = y},\n            have x = z, from this,\n            show z \u2208 A, from eq.subst this h1, \n        have h3: {y| x = y} \u2208 powerset B, from h h2, \n        have h4: x \u2208 {y| x = y}, from eq.refl x, \n        show x \u2208 B, from h3 h4\nend", "meta": {"author": "lucasmoschen", "repo": "discrete-mathematics", "sha": "0f1945cc5eb094814c926cd6ae4a8b4c5c579a1e", "save_path": "github-repos/lean/lucasmoschen-discrete-mathematics", "path": "github-repos/lean/lucasmoschen-discrete-mathematics/discrete-mathematics-0f1945cc5eb094814c926cd6ae4a8b4c5c579a1e/Exercises/Lista 5/cap12-LucasMoschen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7105088143798156}}
{"text": "import tactic --hide\n\n/-\nThis level proves that `\u2227` is a commutative operator. \n-/\n\n/-Lemma\nLet $P,Q$ be logical statements, then $P \u2227 Q$ is true iff $Q \u2227 P$ is true.\n-/\nlemma and_commutative (P Q : Prop) : P \u2227 Q \u2194 Q \u2227 P :=\nbegin\n  split,\n  intro h,\n  cases h,\n  split,\n  exact h_right,\n  exact h_left,\n  intro h,\n  split,\n  exact h.2,\n  exact h.1,\n\n  \nend", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic2/logical_andseasy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813488829418, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.7104547498820538}}
{"text": "import GMLInit.Data.Equiv\nimport GMLInit.Data.Nat.Basic\nimport GMLInit.Data.Nat.Order\n\nnamespace Nat\n\ndef tri : Nat \u2192 Nat\n| 0 => 0\n| n+1 => tri n + n + 1\n\ntheorem tri_zero : tri 0 = 0 := rfl\n\ntheorem tri_succ (n) : tri (n+1) = tri n + n + 1 := rfl\n\ntheorem tri_mono {m n : Nat} : m \u2264 n \u2192 tri m \u2264 tri n := by\n  induction m, n using Nat.recDiag with\n  | zero_zero => intro; reflexivity\n  | zero_succ n => intro; exact Nat.zero_le ..\n  | succ_zero m => intro; contradiction\n  | succ_succ m n H =>\n    intro h\n    rw [tri_succ, tri_succ]\n    apply Nat.add_le_add_right\n    apply Nat.add_le_add\n    \u00b7 apply H\n      exact Nat.le_of_succ_le_succ h\n    \u00b7 exact Nat.le_of_succ_le_succ h\n\ntheorem two_tri_eq (n : Nat) : 2 * tri n = n * (n + 1) := by\n  induction n with\n  | zero => rfl\n  | succ n ih =>\n    calc\n    _ = 2 * (tri n + (n + 1)) := by rfl\n    _ = 2 * tri n + 2 * (n + 1) := by rw [Nat.mul_add]\n    _ = n * (n + 1) + 2 * (n + 1) := by rw [ih]\n    _ = (n + 2) * (n + 1) := by rw [Nat.add_mul]\n    _ = (n + 1) * (n + 1 + 1) := by rw [Nat.mul_comm]\n\nprivate theorem tri_add_self_lt_tri_of_lt {m n : Nat} : m < n \u2192 tri m + m < tri n := by\n  intro h\n  transitivity (tri (m+1)) using LT.lt, LE.le\n  \u00b7 exact Nat.lt_succ_self ..\n  \u00b7 apply Nat.tri_mono\n    exact Nat.succ_le_of_lt h\n\ntheorem tri_add_inj {m\u2081 n\u2081 m\u2082 n\u2082} : m\u2081 \u2264 n\u2081 \u2192 m\u2082 \u2264 n\u2082 \u2192 tri n\u2081 + m\u2081 = tri n\u2082 + m\u2082 \u2192 n\u2081 = n\u2082 := by\n  intro h\u2081 h\u2082 h\n  by_cases n\u2081 \u2264 n\u2082, n\u2081 \u2265 n\u2082 with\n  | isTrue hle, isTrue hge =>\n    antisymmetry using LE.le\n    \u00b7 exact hle\n    \u00b7 exact hge\n  | _, isFalse hlt =>\n    absurd h\n    apply Nat.ne_of_lt\n    transitivity (tri n\u2081 + n\u2081) using LE.le, LT.lt\n    \u00b7 apply Nat.add_le_add_left\n      exact h\u2081\n    \u00b7 transitivity (tri n\u2082) using LT.lt, LE.le\n      \u00b7 apply Nat.tri_add_self_lt_tri_of_lt\n        exact Nat.lt_of_not_ge hlt\n      \u00b7 exact Nat.le_add_right ..\n  | isFalse hgt, _ =>\n    absurd h\n    symmetry using (.\u2260.)\n    apply Nat.ne_of_lt\n    transitivity (tri n\u2082 + n\u2082) using LE.le, LT.lt\n    \u00b7 apply Nat.add_le_add_left\n      exact h\u2082\n    \u00b7 transitivity (tri n\u2081) using LT.lt, LE.le\n      \u00b7 apply Nat.tri_add_self_lt_tri_of_lt\n        exact Nat.gt_of_not_le hgt\n      \u00b7 exact Nat.le_add_right ..\n\nabbrev pair (x y : Nat) : Nat := tri (x + y) + x\n\ntheorem pair_zero_right (x : Nat) : pair x 0 = tri x + x := rfl\n\ntheorem pair_succ_right (x y : Nat) : pair x (y+1) = pair x y + (x + y) + 1 :=\n  calc\n  _ = (tri (x + y) + (x + y) + 1) + x := by rfl\n  _ = ((tri (x + y) + (x + y)) + x) + 1 := by rw [Nat.add_right_comm _ x 1]\n  _ = ((tri (x + y) + x) + (x + y)) + 1 := by rw [Nat.add_right_comm _ (x+y) x]\n\ntheorem pair_zero_left (y : Nat) : pair 0 y = tri y :=\n  calc\n  _ = tri (0 + y) := by rfl\n  _ = tri y := by rw [Nat.zero_add]\n\ntheorem pair_succ_left (x y : Nat) : pair (x+1) y = pair x y + (x + y) + 2 :=\n  calc\n  _ = (tri (x + 1 + y)) + (x + 1) := by rfl\n  _ = (tri (x + y + 1)) + (x + 1) := by rw [Nat.add_right_comm _ y 1]\n  _ = (tri (x + y) + (x + y) + 1) + (x + 1) := by rfl\n  _ = (tri (x + y) + x + y + 1) + (x + 1) := by rw [Nat.add_assoc _ x y]\n  _ = (pair x y + y + 1) + (x + 1) := by rfl\n  _ = (pair x y + y) + (x + 1) + 1 := by rw [Nat.add_right_comm _ (x+1) 1]\n  _ = (pair x y + y) + x + 1 + 1 := by rw [Nat.add_assoc _ x 1]\n  _ = pair x y + (y + x) + 1 + 1 := by rw [Nat.add_assoc _ y x]\n  _ = pair x y + (x + y) + 1 + 1 := by rw [Nat.add_comm x y]\n\ndef split : Nat \u2192 (t : Nat) \u00d7 Fin (t+1)\n| 0 => \u27e80,0\u27e9\n| n+1 =>\n  match split n with\n  | \u27e8t,s,_\u27e9 =>\n    if h : s < t\n    then \u27e8t, s+1, Nat.succ_lt_succ h\u27e9\n    else \u27e8t+1, 0, Nat.zero_lt_succ (t+1)\u27e9\n\ntheorem split_eq (n : Nat) : tri (split n).fst + (split n).snd = n := by\n  induction n with\n  | zero => rfl\n  | succ n H =>\n    symmetry\n    transitivity (tri (split n).fst + ((split n).snd + 1))\n    \u00b7 rw [\u2190Nat.add_assoc (tri (split n).fst) (split n).snd 1, H]\n    \u00b7 symmetry\n      simp only [split]\n      split\n      next h =>\n        dsimp only [Nat.add_eq] at h \u22a2\n        rw [Nat.add_zero n] at h \u22a2\n        rw [dif_pos h]\n      next h =>\n        have h : \u00ac((split n).snd.val < (split n).fst) := h\n        have heq : (split n).snd.val = (split n).fst := by\n          apply Nat.le_antisymm\n          \u00b7 exact Nat.le_of_lt_succ (split n).snd.isLt\n          \u00b7 exact Nat.le_of_not_gt h\n        rw [dif_neg h, \u2190Nat.add_assoc, heq]; rfl\n\nprotected abbrev fst (n : Nat) : Nat := (split n).snd\n\nprotected abbrev snd (n : Nat) : Nat := (split n).fst - (split n).snd\n\nprivate theorem split_pair_fst (x y) : (split (pair x y)).fst = x + y := by\n  match h : split (pair x y) with\n  | \u27e8t,\u27e8s,hs\u27e9\u27e9 =>\n    apply Nat.tri_add_inj (Nat.le_of_lt_succ hs) (Nat.le_add_right x y)\n    transitivity (tri (split (pair x y)).fst + (split (pair x y)).snd)\n    \u00b7 rw [h]\n    \u00b7 rw [split_eq, pair]\n\nprivate theorem split_pair_snd (x y) : (split (pair x y)).snd = x := by\n  apply Nat.add_left_cancel (n:=tri (split (pair x y)).fst)\n  rw [split_eq, split_pair_fst, pair]\n\ntheorem fst_pair (x y) : (pair x y).fst = x := split_pair_snd x y\n\ntheorem snd_pair (x y) : (pair x y).snd = y := by\n  unfold Nat.snd\n  rw [Nat.split_pair_snd]\n  rw [Nat.split_pair_fst]\n  rw [Nat.add_sub_cancel_left]\n\ntheorem pair_fst_snd (n) : pair n.fst n.snd = n := by\n  unfold pair Nat.fst Nat.snd\n  match h : split n with\n  | \u27e8t,\u27e8s,hs\u27e9\u27e9 =>\n    rw [Nat.add_comm s, Nat.sub_add_cancel (Nat.le_of_lt_succ hs)]\n    rw [\u2190split_eq n, h]\n\ndef encodeProd (a : Nat \u00d7 Nat) : Nat := pair a.fst a.snd\n\ndef decodeProd (n : Nat) : Nat \u00d7 Nat := (n.fst, n.snd)\n\ndef prodEquiv : Equiv Nat (Nat \u00d7 Nat) where\n  fwd n := (n.fst, n.snd)\n  rev p := pair p.fst p.snd\n  spec := by intro\n    | n, (n\u2081,n\u2082) =>\n      clean\n      constr\n      \u00b7 intro h\n        cases h\n        rw [pair_fst_snd]\n      \u00b7 intro h\n        cases h\n        rw [fst_pair, snd_pair]\n\nend Nat\n", "meta": {"author": "fgdorais", "repo": "GMLInit", "sha": "a295111627ac907ebc6a86f906dd9b4d69b338d8", "save_path": "github-repos/lean/fgdorais-GMLInit", "path": "github-repos/lean/fgdorais-GMLInit/GMLInit-a295111627ac907ebc6a86f906dd9b4d69b338d8/GMLInit/Data/Nat/Coding/Prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.7853085859124003, "lm_q1q2_score": 0.7104298385213242}}
{"text": "import linear_algebra.basis\nimport linear_algebra.dual\n\nnoncomputable theory\n\nuniverse u\n\nopen function set submodule\nopen_locale classical big_operators\n\nsection\nvariables {R : Type*} [semiring R]\n          {M : Type*} [add_comm_monoid M] [module R M]\n\n/-- The span of the first `n` elements of an ordered basis. -/\ndef basis.flag {n : \u2115} (b : basis (fin n) R M) : fin (n + 1) \u2192 submodule R M :=\n\u03bb k, span R (b '' {j | (j : fin $ n + 1) < k })\n\n@[simp] lemma basis.flag_zero {n : \u2115} (b : basis (fin n) R M) : b.flag 0 = \u22a5 :=\nbegin\n  simp only [basis.flag, fin.coe_eq_cast_succ],\n  suffices : {j : fin n | fin.cast_succ j < 0} = \u2205, by simp [this],\n  ext l,\n  simp [l.cast_succ.zero_le]\nend\n\n@[simp] lemma basis.flag_last {n : \u2115} (b : basis (fin n) R M) : b.flag (fin.last n) = \u22a4  :=\nbegin\n  have : {j : fin n | (j : fin $ n+1) < fin.last n} = univ,\n  { ext l,\n    simp [fin.cast_succ_lt_last l] },\n  simp_rw [basis.flag, this],\n  simp [b.span_eq]\nend\n\nattribute [mono] submodule.span_mono\n\n@[simp] lemma basis.flag_mono {n : \u2115} (b : basis (fin n) R M) : monotone b.flag :=\nbegin\n  intros j k h,\n  dsimp [basis.flag],\n  mono*,\n  rintros l (hl : \u2191\u2191l < j),\n  exact hl.trans_le h\nend\n\nlemma fin.coe_succ_le_iff_le {n : \u2115} {j k : fin n} : (j : fin $ n+1) \u2264 k \u2194 j \u2264 k :=\nbegin\n  cases j,\n  cases k,\n  simp\nend\n\nlemma fin.coe_succ_lt_iff_lt {n : \u2115} {j k : fin n} : (j : fin $ n+1) < k \u2194 j < k :=\nbegin\n  cases j,\n  cases k,\n  simp\nend\n\nlemma fin.coe_lt_succ {n : \u2115} (k : fin n) : (k : fin $ n+1) < k.succ :=\nbegin\n  cases k,\n  simp\nend\n\nlemma basis.flag_span_succ {n : \u2115} (b : basis (fin n) R M) (k : fin n) :\n  b.flag k \u2294 span R {b k} = b.flag k.succ :=\nbegin\n  rw [basis.flag, \u2190 span_union, \u2190 image_singleton, \u2190 image_union],\n  congr,\n  ext j,\n  have : j = k \u2228 j < k \u2194 \u2191j < k.succ,\n  { cases j,\n    cases k,\n    simp [\u2190 le_iff_eq_or_lt, nat.lt_succ_iff.symm] },\n  simp [this]\nend\nend\n\nsection\nvariables {R : Type*} [comm_ring R]\n          {M : Type*} [add_comm_group M] [module R M]\n\nvariables {n : \u2115} (b : basis (fin n) R M)\n\nlemma basis.flag_le_ker_dual (k : fin n) : b.flag k \u2264 (b.dual_basis k).ker :=\nbegin\n  erw span_le,\n  rintros _ \u27e8j, hj : (j : fin $ n+1) < k, rfl\u27e9,\n  simp [(fin.coe_succ_lt_iff_lt.mp hj).ne]\nend\nend\n", "meta": {"author": "leanprover-community", "repo": "sphere-eversion", "sha": "324e02c1509db6177cf363618f6ac5be343ce2f5", "save_path": "github-repos/lean/leanprover-community-sphere-eversion", "path": "github-repos/lean/leanprover-community-sphere-eversion/sphere-eversion-324e02c1509db6177cf363618f6ac5be343ce2f5/src/to_mathlib/linear_algebra/basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7104298264086283}}
{"text": "import hahn\n\n/- \nThis file contains the definition of mutually singular measures,  \nthe Jordan decomposition theorem and the Lebesgue decomposition theorem.\n-/\n\nnoncomputable theory\nopen_locale classical big_operators nnreal ennreal\n\nvariables {\u03b1 \u03b2 : Type*} [measurable_space \u03b1]\n\nopen measure_theory\n\ndef measure.singular (\u03bc \u03bd : measure \u03b1) : Prop := \n\u2203 (i : set \u03b1) (hi\u2081 : measurable_set i), \u03bc i = 0 \u2227 \u03bd i\u1d9c = 0  \n\nnamespace signed_measure\n\ninfix ` \u22a5 `:60 := measure.singular\n\nvariables {\u03bc \u03bd : measure \u03b1}\n\nlemma singular_comm (h : \u03bc \u22a5 \u03bd) : \u03bd \u22a5 \u03bc :=\nlet \u27e8i, hi, his, hit\u27e9 := h in \n  \u27e8i\u1d9c, measurable_set.compl hi, hit, (compl_compl i).symm \u25b8 his\u27e9\n\n/-- The Jordan decomposition theorem: Given a signed measure `s`, there exists \na pair of mutually singular measures `\u03bc` and `\u03bd` such that `s = \u03bc - \u03bd`. -/\ntheorem exists_sigular_sub (s : signed_measure \u03b1) : \n  \u2203 (\u03bc \u03bd : measure \u03b1) [h\u03bc : finite_measure \u03bc] [h\u03bd : finite_measure \u03bd], \n    \u03bc \u22a5 \u03bd \u2227 s = @of_sub_measure _ _ \u03bc \u03bd h\u03bc h\u03bd :=\nbegin\n  obtain \u27e8i, hi\u2081, hi\u2082, hi\u2083\u27e9 := s.exists_compl_positive_negative,\n  have hi\u2084 := measurable_set.compl hi\u2081,\n  refine \u27e8s.positive_to_measure i hi\u2081 hi\u2082, s.negative_to_measure i\u1d9c hi\u2084 hi\u2083, _\u27e9,\n  refine \u27e8positive_to_measure_finite hi\u2081 hi\u2082, negative_to_measure_finite hi\u2084 hi\u2083, _, _\u27e9,\n  { refine \u27e8i\u1d9c, hi\u2084, _, _\u27e9,\n    { simp_rw [positive_to_measure_apply _ _ hi\u2084, \n               set.inter_compl_self, s.measure_of_empty], refl },\n    { simp_rw [negative_to_measure_apply _ _ (measurable_set.compl hi\u2084), \n               set.inter_compl_self, s.measure_of_empty, neg_zero], refl } },\n  { ext k hk,\n    rw [of_sub_measure_apply hk, positive_to_measure_apply hi\u2081 hi\u2082 hk, \n        negative_to_measure_apply hi\u2084 hi\u2083 hk],\n    simp only [ennreal.coe_to_real, subtype.coe_mk, ennreal.some_eq_coe, sub_neg_eq_add],\n    rw [\u2190 measure_of_union _ (measurable_set.inter hi\u2081 hk) (measurable_set.inter hi\u2084 hk), \n        set.inter_comm i, set.inter_comm i\u1d9c, set.inter_union_compl _ _],\n    rintro x \u27e8\u27e8hx\u2081, _\u27e9, hx\u2082, _\u27e9,\n    exact false.elim (hx\u2082 hx\u2081) }\nend\n\n/-- A Jordan decomposition provides a Hahn decomposition. -/\nlemma exists_compl_positive_negative_of_exists_sigular_sub \n  {s : signed_measure \u03b1} {\u03bc \u03bd : measure \u03b1}\n  [h\u03bc : finite_measure \u03bc] [h\u03bd : finite_measure \u03bd] \n  (h : \u03bc \u22a5 \u03bd \u2227 s = @of_sub_measure _ _ \u03bc \u03bd h\u03bc h\u03bd) :\n  \u2203 S (hS\u2081 : measurable_set S) (hS\u2084: s.negative S) (hS\u2085: s.positive S\u1d9c), \n  \u03bc S = 0 \u2227 \u03bd S\u1d9c = 0 :=\nbegin\n  obtain \u27e8\u27e8S, hS\u2081, hS\u2082, hS\u2083\u27e9, h\u2081\u27e9 := h,\n  refine \u27e8S, hS\u2081, _, _, hS\u2082, hS\u2083\u27e9,\n  { intros A hA hA\u2081,\n    rw [h\u2081, of_sub_measure_apply hA\u2081, \n        show \u03bc A = 0, by exact nonpos_iff_eq_zero.1 (hS\u2082 \u25b8 measure_mono hA), \n        ennreal.zero_to_real, zero_sub, neg_le, neg_zero],\n    exact ennreal.to_real_nonneg },\n  { intros A hA hA\u2081,\n    rw [h\u2081, of_sub_measure_apply hA\u2081, \n        show \u03bd A = 0, by exact nonpos_iff_eq_zero.1 (hS\u2083 \u25b8 measure_mono hA), \n        ennreal.zero_to_real, sub_zero],\n    exact ennreal.to_real_nonneg },\nend \n\nlemma subset_positive_null_set {s : signed_measure \u03b1} {u w t : set \u03b1} \n  (hw : measurable_set w) (ht : measurable_set t)\n  (hsu : s.positive u) (ht\u2081 : s t = 0) (ht\u2082 : t \u2286 u) (hwt : w \u2286 t) : s w = 0 :=\nbegin\n  have : s w + s (t \\ w) = 0,\n  { rw [\u2190 ht\u2081, \u2190 measure_of_union set.disjoint_diff hw (ht.diff hw), \n        set.union_diff_self, set.union_eq_self_of_subset_left hwt] },\n  rw add_eq_zero_iff' at this,\n  exacts [this.1, hsu _ (hwt.trans ht\u2082) hw, hsu _ ((t.diff_subset w).trans ht\u2082) (ht.diff hw)],\nend\n\nlemma subset_negative_null_set {s : signed_measure \u03b1} {u w t : set \u03b1} \n  (hw : measurable_set w) (ht : measurable_set t)\n  (hsu : s.negative u) (ht\u2081 : s t = 0) (ht\u2082 : t \u2286 u) (hwt : w \u2286 t) : s w = 0 :=\nbegin\n  have : s w + s (t \\ w) = 0,\n  { rw [\u2190 ht\u2081, \u2190 measure_of_union set.disjoint_diff hw (ht.diff hw), \n        set.union_diff_self, set.union_eq_self_of_subset_left hwt] },\n  linarith [hsu _ (hwt.trans ht\u2082) hw, hsu _ ((t.diff_subset w).trans ht\u2082) (ht.diff hw)]\nend\n\nlemma set.diff_disjoint_diff (u v : set \u03b1) : disjoint (u \\ v) (v \\ u) :=\nset.disjoint_of_subset_left (u.diff_subset v) set.disjoint_diff\n\nlemma of_diff_eq_zero_of_symm_diff_eq_zero_positive {s : signed_measure \u03b1} {u v : set \u03b1} \n  (hu : measurable_set u) (hv : measurable_set v) \n  (hsu : s.positive u) (hsv : s.positive v) (hs : s (u \u0394 v) = 0) : \n  s (u \\ v) = 0 \u2227 s (v \\ u) = 0 := \nbegin\n  rwa [\u2190 add_eq_zero_iff' (hsu _ (u.diff_subset v) (hu.diff hv)) \n           (hsv _ (v.diff_subset u) (hv.diff hu)), \n       \u2190 measure_of_union (set.diff_disjoint_diff u v) (hu.diff hv) (hv.diff hu)]\nend\n\nlemma of_diff_eq_zero_of_symm_diff_eq_zero_negative {s : signed_measure \u03b1} {u v : set \u03b1} \n  (hu : measurable_set u) (hv : measurable_set v) \n  (hsu : s.negative u) (hsv : s.negative v) (hs : s (u \u0394 v) = 0) : \n  s (u \\ v) = 0 \u2227 s (v \\ u) = 0 := \nbegin\n  have a := hsu _ (u.diff_subset v) (hu.diff hv),\n  have b := hsv _ (v.diff_subset u) (hv.diff hu),\n  erw [measure_of_union (set.diff_disjoint_diff u v) (hu.diff hv) (hv.diff hu)] at hs,\n  split; linarith,\nend\n\nlemma of_diff_of_symm_diff_eq_zero {s : signed_measure \u03b1} {u v : set \u03b1} \n  (hu : measurable_set u) (hv : measurable_set v)\n  (h : s (u \u0394 v) = 0) (h' : s (v \\ u) = 0) : s (u \\ v) + s v = s u :=\nbegin \n  symmetry,\n  calc s u = s (u \\ v \u222a u \u2229 v) : by simp only [set.diff_union_inter]\n       ... = s (u \\ v) + s (u \u2229 v) : \n  by { rw measure_of_union,\n       { rw disjoint.comm,\n         exact set.disjoint_of_subset_left (u.inter_subset_right v) set.disjoint_diff },\n       { exact hu.diff hv },\n       { exact hu.inter hv } }\n       ... = s (u \\ v) + s (u \u2229 v \u222a v \\ u) : \n  by { rw [measure_of_union, h', add_zero],\n       { exact set.disjoint_of_subset_left (u.inter_subset_left v) set.disjoint_diff },\n       { exact hu.inter hv },\n       { exact hv.diff hu } }\n       ... = s (u \\ v) + s v : \n  by { rw [set.union_comm, set.inter_comm, set.diff_union_inter] } \nend\n\nlemma of_inter_eq_of_symm_diff_eq_zero_positive {s : signed_measure \u03b1} {u v w : set \u03b1} \n  (hu : measurable_set u) (hv : measurable_set v) (hw : measurable_set w)\n  (hsu : s.positive u) (hsv : s.positive v) (hs : s (u \u0394 v) = 0) : \n  s (w \u2229 u) = s (w \u2229 v) := \nbegin\n  have hwuv : s ((w \u2229 u) \u0394 (w \u2229 v)) = 0,\n  { refine subset_positive_null_set _ _ (positive_union_positive hu hsu hv hsv) hs _ _,\n    { exact (hw.inter hu).symm_diff (hw.inter hv) },\n    { exact hu.symm_diff hv },\n    { exact symm_diff_le_sup u v },\n    { rintro x (\u27e8\u27e8hxw, hxu\u27e9, hx\u27e9 | \u27e8\u27e8hxw, hxv\u27e9, hx\u27e9);\n      rw [set.mem_inter_eq, not_and] at hx,\n      { exact or.inl \u27e8hxu, hx hxw\u27e9 },\n      { exact or.inr \u27e8hxv, hx hxw\u27e9 } } },\n  obtain \u27e8huv, hvu\u27e9 := of_diff_eq_zero_of_symm_diff_eq_zero_positive \n    (hw.inter hu) (hw.inter hv) \n    (positive_subset_positive hsu (w.inter_subset_right u)) \n    (positive_subset_positive hsv (w.inter_subset_right v)) hwuv,\n  rw [\u2190 of_diff_of_symm_diff_eq_zero (hw.inter hu) (hw.inter hv) hwuv hvu, huv, zero_add]\nend\n\nlemma of_inter_eq_of_symm_diff_eq_zero_negative {s : signed_measure \u03b1} {u v w : set \u03b1} \n  (hu : measurable_set u) (hv : measurable_set v) (hw : measurable_set w)\n  (hsu : s.negative u) (hsv : s.negative v) (hs : s (u \u0394 v) = 0) : \n  s (w \u2229 u) = s (w \u2229 v) := \nbegin\n  have hwuv : s ((w \u2229 u) \u0394 (w \u2229 v)) = 0,\n  { refine subset_negative_null_set _ _ (negative_union_negative hu hsu hv hsv) hs _ _,\n    { exact (hw.inter hu).symm_diff (hw.inter hv) },\n    { exact hu.symm_diff hv },\n    { exact symm_diff_le_sup u v },\n    { rintro x (\u27e8\u27e8hxw, hxu\u27e9, hx\u27e9 | \u27e8\u27e8hxw, hxv\u27e9, hx\u27e9);\n      rw [set.mem_inter_eq, not_and] at hx,\n      { exact or.inl \u27e8hxu, hx hxw\u27e9 },\n      { exact or.inr \u27e8hxv, hx hxw\u27e9 } } },\n  obtain \u27e8huv, hvu\u27e9 := of_diff_eq_zero_of_symm_diff_eq_zero_negative \n    (hw.inter hu) (hw.inter hv) \n    (negative_subset_negative hsu (w.inter_subset_right u)) \n    (negative_subset_negative hsv (w.inter_subset_right v)) hwuv,\n  rw [\u2190 of_diff_of_symm_diff_eq_zero (hw.inter hu) (hw.inter hv) hwuv hvu, huv, zero_add]\nend\n\n/-- The Jordan decomposition of a signed measure is unique. -/\ntheorem singular_sub_unique {s : signed_measure \u03b1} {\u03bc\u2081 \u03bd\u2081 \u03bc\u2082 \u03bd\u2082 : measure \u03b1} \n  [h\u03bc\u2081 : finite_measure \u03bc\u2081] [h\u03bd\u2081 : finite_measure \u03bd\u2081] \n  [h\u03bc\u2082 : finite_measure \u03bc\u2082] [h\u03bd\u2082 : finite_measure \u03bd\u2082] \n  (h\u2081 : \u03bc\u2081 \u22a5 \u03bd\u2081 \u2227 s = @of_sub_measure _ _ \u03bc\u2081 \u03bd\u2081 h\u03bc\u2081 h\u03bd\u2081) \n  (h\u2082 : \u03bc\u2082 \u22a5 \u03bd\u2082 \u2227 s = @of_sub_measure _ _ \u03bc\u2082 \u03bd\u2082 h\u03bc\u2082 h\u03bd\u2082) :\n  \u03bc\u2081 = \u03bc\u2082 \u2227 \u03bd\u2081 = \u03bd\u2082 :=\nbegin\n  obtain \u27e8S, hS\u2081, hS\u2082, hS\u2083, hS\u2084, hS\u2085\u27e9 := \n    exists_compl_positive_negative_of_exists_sigular_sub h\u2081,\n  obtain \u27e8T, hT\u2081, hT\u2082, hT\u2083, hT\u2084, hT\u2085\u27e9 := \n    exists_compl_positive_negative_of_exists_sigular_sub h\u2082,\n  obtain \u27e8hST\u2081, hST\u2082\u27e9 := of_symm_diff_compl_positive_negative hS\u2081.compl hT\u2081.compl \n    \u27e8hS\u2083, (compl_compl S).symm \u25b8 hS\u2082\u27e9 \u27e8hT\u2083, (compl_compl T).symm \u25b8 hT\u2082\u27e9,\n\n  rw [compl_compl, compl_compl] at hST\u2082,\n  split,\n  { refine measure_theory.measure.ext (\u03bb i hi, _), \n    have h\u03bc\u2081 : (\u03bc\u2081 i).to_real = s (i \u2229 S\u1d9c),\n    { rw [h\u2081.2, of_sub_measure_apply (hi.inter hS\u2081.compl), \n          show \u03bd\u2081 (i \u2229 S\u1d9c) = 0, by exact nonpos_iff_eq_zero.1 \n            (hS\u2085 \u25b8 measure_mono (set.inter_subset_right _ _)), \n          ennreal.zero_to_real, sub_zero],\n      conv_lhs { rw \u2190 set.inter_union_compl i S },\n      rw [measure_union, show \u03bc\u2081 (i \u2229 S) = 0, by exact nonpos_iff_eq_zero.1 \n            (hS\u2084 \u25b8 measure_mono (set.inter_subset_right _ _)), zero_add], \n      { exact set.disjoint_of_subset_left (set.inter_subset_right _ _) \n          (set.disjoint_of_subset_right (set.inter_subset_right _ _) S.disjoint_compl) },\n      { exact hi.inter hS\u2081 },\n      { exact hi.inter hS\u2081.compl } },\n    have h\u03bc\u2082 : (\u03bc\u2082 i).to_real = s (i \u2229 T\u1d9c),\n    { rw [h\u2082.2, of_sub_measure_apply (hi.inter hT\u2081.compl), \n          show \u03bd\u2082 (i \u2229 T\u1d9c) = 0, by exact nonpos_iff_eq_zero.1 \n            (hT\u2085 \u25b8 measure_mono (set.inter_subset_right _ _)), \n          ennreal.zero_to_real, sub_zero],\n      conv_lhs { rw \u2190 set.inter_union_compl i T },\n      rw [measure_union, show \u03bc\u2082 (i \u2229 T) = 0, by exact nonpos_iff_eq_zero.1 \n            (hT\u2084 \u25b8 measure_mono (set.inter_subset_right _ _)), zero_add], \n      { exact set.disjoint_of_subset_left (set.inter_subset_right _ _) \n          (set.disjoint_of_subset_right (set.inter_subset_right _ _) T.disjoint_compl) },\n      { exact hi.inter hT\u2081 },\n      { exact hi.inter hT\u2081.compl } }, \n    rw [\u2190 ennreal.to_real_eq_to_real (measure_lt_top _ _) (measure_lt_top _ _), \n        h\u03bc\u2081, h\u03bc\u2082],\n    exact of_inter_eq_of_symm_diff_eq_zero_positive hS\u2081.compl hT\u2081.compl hi hS\u2083 hT\u2083 hST\u2081,\n    all_goals { apply_instance } },\n\n  { refine measure_theory.measure.ext (\u03bb i hi, _), \n    have h\u03bd\u2081 : (\u03bd\u2081 i).to_real = - s (i \u2229 S),\n    { rw [h\u2081.2, of_sub_measure_apply (hi.inter hS\u2081), \n          show \u03bc\u2081 (i \u2229 S) = 0, by exact nonpos_iff_eq_zero.1 \n            (hS\u2084 \u25b8 measure_mono (set.inter_subset_right _ _)), \n          ennreal.zero_to_real, zero_sub],\n      conv_lhs { rw \u2190 set.inter_union_compl i S },\n      rw [measure_union, show \u03bd\u2081 (i \u2229 S\u1d9c) = 0, by exact nonpos_iff_eq_zero.1 \n            (hS\u2085 \u25b8 measure_mono (set.inter_subset_right _ _)), add_zero, neg_neg], \n      { exact set.disjoint_of_subset_left (set.inter_subset_right _ _) \n          (set.disjoint_of_subset_right (set.inter_subset_right _ _) S.disjoint_compl) },\n      { exact hi.inter hS\u2081 },\n      { exact hi.inter hS\u2081.compl } },\n    have h\u03bd\u2082 : (\u03bd\u2082 i).to_real = - s (i \u2229 T),\n    { rw [h\u2082.2, of_sub_measure_apply (hi.inter hT\u2081), \n          show \u03bc\u2082 (i \u2229 T) = 0, by exact nonpos_iff_eq_zero.1 \n            (hT\u2084 \u25b8 measure_mono (set.inter_subset_right _ _)), \n          ennreal.zero_to_real, zero_sub],\n      conv_lhs { rw \u2190 set.inter_union_compl i T },\n      rw [measure_union, show \u03bd\u2082 (i \u2229 T\u1d9c) = 0, by exact nonpos_iff_eq_zero.1 \n            (hT\u2085 \u25b8 measure_mono (set.inter_subset_right _ _)), add_zero, neg_neg], \n      { exact set.disjoint_of_subset_left (set.inter_subset_right _ _) \n          (set.disjoint_of_subset_right (set.inter_subset_right _ _) T.disjoint_compl) },\n      { exact hi.inter hT\u2081 },\n      { exact hi.inter hT\u2081.compl } },\n    rw [\u2190 ennreal.to_real_eq_to_real (measure_lt_top _ _) (measure_lt_top _ _), \n        h\u03bd\u2081, h\u03bd\u2082, neg_eq_iff_neg_eq, neg_neg],\n    exact eq.symm (of_inter_eq_of_symm_diff_eq_zero_negative hS\u2081 hT\u2081 hi hS\u2082 hT\u2082 hST\u2082),\n    all_goals { apply_instance } }\nend\n\nlemma measure.exists_measure_pos_of_measure_Union_pos (\u03bc : measure \u03b1) \n  (f : \u2115 \u2192 set \u03b1) (hf : 0 < \u03bc (\u22c3 n, f n)) : \n  \u2203 n, 0 < \u03bc (f n) :=\nbegin\n  by_contra, push_neg at h,\n  simp_rw nonpos_iff_eq_zero at h,\n  refine pos_iff_ne_zero.1 hf _,\n  rw \u2190 nonpos_iff_eq_zero,\n  refine le_trans (measure_Union_le (\u03bb (i : \u2115), f i)) _,\n  rw nonpos_iff_eq_zero,\n  convert tsum_zero, \n  { ext1 n, exact h n },\n  { apply_instance },\nend\n\nlemma exists_positive_of_sub_measure \n  (\u03bc \u03bd : measure \u03b1) [finite_measure \u03bc] [finite_measure \u03bd] (h : \u00ac \u03bc \u22a5 \u03bd) : \n  \u2203 (\u03b5 : \u211d\u22650) (h\u03b5 : 0 < \u03b5), \u2203 (E : set \u03b1) (hE : measurable_set E) (h\u03bdE : 0 < \u03bd E), \n  (of_sub_measure \u03bc (\u03b5 \u2022 \u03bd)).positive E :=\nbegin\n  have : \u2200 n : \u2115, \u2203 (i : set \u03b1) (hi\u2081 : measurable_set i), \n    (of_sub_measure \u03bc ((1 / (n + 1) : \u211d\u22650) \u2022 \u03bd)).positive i \u2227 \n    (of_sub_measure \u03bc ((1 / (n + 1) : \u211d\u22650) \u2022 \u03bd)).negative i\u1d9c,\n  { intro, exact exists_compl_positive_negative _ },\n\n  choose f hf\u2081 hf\u2082 hf\u2083 using this,\n  set A := \u22c2 n, (f n)\u1d9c with hA\u2081,\n\n  have hAmeas : measurable_set A,\n  { exact measurable_set.Inter (\u03bb n, measurable_set.compl (hf\u2081 n)) },\n  have hA\u2082 : \u2200 n : \u2115, (of_sub_measure \u03bc ((1 / (n + 1) : \u211d\u22650) \u2022 \u03bd)).negative A,\n  { intro n, exact negative_subset_negative (hf\u2083 n) (set.Inter_subset _ _) },\n  have hA\u2083 : \u2200 n : \u2115, \u03bc A \u2264 (1 / (n + 1) : \u211d\u22650) * \u03bd A,\n  { intro n, \n    have := negative_nonpos_measure hAmeas (hA\u2082 n),\n    rwa [of_sub_measure_apply hAmeas, sub_nonpos, ennreal.to_real_le_to_real] at this,\n    exacts [ne_of_lt (measure_lt_top _ _), ne_of_lt (measure_lt_top _ _)] },\n  have h\u03bc : \u03bc A = 0,\n  { apply @ennreal.eq_zero_of_le_one_div_nat_plus_one (\u03bc A) (\u03bd A) _ _,\n    { intro n, convert hA\u2083 n, simp },\n    { exact ne_of_lt (measure_lt_top _ _) },\n    { exact ne_of_lt (measure_lt_top _ _) } },\n\n  rw measure.singular at h,\n  push_neg at h,\n  have := h _ hAmeas h\u03bc,\n  simp_rw [hA\u2081, set.compl_Inter, compl_compl] at this,\n  obtain \u27e8n, hn\u27e9 := measure.exists_measure_pos_of_measure_Union_pos \u03bd _ \n    (pos_iff_ne_zero.mpr this),\n  exact \u27e81 / (n + 1), by simp, f n, hf\u2081 n, hn, hf\u2082 n\u27e9,\nend\n\n/-- Given two measures `\u03bc` and `\u03bd`, `measurable_le \u03bc \u03bd` is the set of measurable \nfunctions `f`, such that, for all measurable sets `A`, `\u222b\u207b x in A, f x \u2202\u03bc \u2264 \u03bd A`. \n\nThis is useful for the Lebesgue decomposition theorem. -/\ndef measurable_le (\u03bc \u03bd : measure \u03b1) : set (\u03b1 \u2192 \u211d\u22650\u221e) :=\n{ f | measurable f \u2227 \u2200 (A : set \u03b1) (hA : measurable_set A), \u222b\u207b x in A, f x \u2202\u03bc \u2264 \u03bd A }\n\nlemma zero_mem_measurable_le : (0 : \u03b1 \u2192 \u211d\u22650\u221e) \u2208 measurable_le \u03bc \u03bd :=\n\u27e8measurable_zero, \u03bb A hA, by simp\u27e9\n\nlemma min_mem_measurable_le (f g : \u03b1 \u2192 \u211d\u22650\u221e) \n  (hf : f \u2208 measurable_le \u03bc \u03bd) (hg : measurable g) : \n  (\u03bb a, min (f a) (g a)) \u2208 measurable_le \u03bc \u03bd := \n\u27e8measurable.min hf.1 hg, \n  \u03bb A hA, le_trans (lintegral_mono (\u03bb _, min_le_left _ _)) (hf.2 A hA)\u27e9\n\nlemma min_mem_measurable_le' (f g : \u03b1 \u2192 \u211d\u22650\u221e) \n  (hf : f \u2208 measurable_le \u03bc \u03bd) (hg : g \u2208 measurable_le \u03bc \u03bd) : \n  (\u03bb a, min (f a) (g a)) \u2208 measurable_le \u03bc \u03bd := \nmin_mem_measurable_le f g hf hg.1\n\nlemma max_mem_measurable_le (f g : \u03b1 \u2192 \u211d\u22650\u221e) \n  (hf : f \u2208 measurable_le \u03bc \u03bd) (hg : g \u2208 measurable_le \u03bc \u03bd) \n  (A : set \u03b1) (hA : measurable_set A): \n  \u222b\u207b a in A, max (f a) (g a) \u2202\u03bc\n    \u2264 \u222b\u207b a in A \u2229 { a | f a \u2264 g a }, g a \u2202\u03bc \n    + \u222b\u207b a in A \u2229 { a | g a < f a }, f a \u2202\u03bc := \nbegin\n  rw [\u2190 lintegral_indicator _ hA, \u2190 lintegral_indicator f, \n      \u2190 lintegral_indicator g, \u2190 lintegral_add],\n  { refine lintegral_mono (\u03bb a, _),\n    by_cases haA : a \u2208 A, \n    { by_cases f a \u2264 g a,\n      { simp only,\n        rw [set.indicator_of_mem haA, set.indicator_of_mem, set.indicator_of_not_mem, add_zero],\n        simp only [le_refl, max_le_iff, and_true, h],\n        { rintro \u27e8_, hc\u27e9,\n          exact false.elim ((not_lt.2 h) hc) },\n        { exact \u27e8haA, h\u27e9 } },\n      { simp only,\n        rw [set.indicator_of_mem haA, set.indicator_of_mem _ f, \n            set.indicator_of_not_mem, zero_add],\n        simp only [true_and, le_refl, max_le_iff, le_of_lt (not_le.1 h)],\n        { rintro \u27e8_, hc\u27e9, \n          exact false.elim (h hc) },\n        { exact \u27e8haA, not_le.1 h\u27e9 } } },\n    { simp [set.indicator_of_not_mem haA] } },\n  { exact measurable.indicator hg.1 (measurable_set.inter hA (measurable_set_le hf.1 hg.1)) },\n  { exact measurable.indicator hf.1 (measurable_set.inter hA (measurable_set_lt hg.1 hf.1)) },\n  { exact measurable_set.inter hA (measurable_set_le hf.1 hg.1) },\n  { exact measurable_set.inter hA (measurable_set_lt hg.1 hf.1) },\nend\n\nlemma sup_mem_measurable_le {f g : \u03b1 \u2192 \u211d\u22650\u221e} \n  (hf : f \u2208 measurable_le \u03bc \u03bd) (hg : g \u2208 measurable_le \u03bc \u03bd) : \n  (\u03bb a, f a \u2294 g a) \u2208 measurable_le \u03bc \u03bd := \nbegin\n  simp_rw ennreal.sup_eq_max,\n  refine \u27e8measurable.max hf.1 hg.1, \u03bb A hA, _\u27e9,\n  have h\u2081 := measurable_set.inter hA (measurable_set_le hf.1 hg.1),\n  have h\u2082 := measurable_set.inter hA (measurable_set_lt hg.1 hf.1),\n  refine le_trans (max_mem_measurable_le f g hf hg A hA) _,\n  refine le_trans (add_le_add (hg.2 _ h\u2081) (hf.2 _ h\u2082)) _,\n  { rw [\u2190 measure_union _ h\u2081 h\u2082],\n    { refine le_of_eq _,\n      congr, convert set.inter_union_compl A _,\n      ext a, simpa },\n    rintro x \u27e8\u27e8-, hx\u2081\u27e9, -, hx\u2082\u27e9,\n    exact (not_le.2 hx\u2082) hx\u2081 }\nend\n\nlemma supr_succ_eq_sup {\u03b1} (f : \u2115 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) (m : \u2115) (a : \u03b1) :\n  (\u2a06 (k : \u2115) (hk : k \u2264 m + 1), f k a) = f m.succ a \u2294 \u2a06 (k : \u2115) (hk : k \u2264 m), f k a :=\nbegin\n  ext x,\n  simp only [option.mem_def, ennreal.some_eq_coe],\n  split; intro h; rw \u2190 h, symmetry,\n  all_goals { \n    set c := (\u2a06 (k : \u2115) (hk : k \u2264 m + 1), f k a) with hc, -- What is going on?\n    set d := (f m.succ a \u2294 \u2a06 (k : \u2115) (hk : k \u2264 m), f k a) with hd,\n    suffices : c \u2264 d \u2227 d \u2264 c,\n    { change c = d, -- commenting this breaks?\n      exact le_antisymm this.1 this.2 },\n    rw [hc, hd],\n    refine \u27e8_, _\u27e9,\n    { refine bsupr_le (\u03bb n hn, _),\n      rcases nat.of_le_succ hn with (h | h),\n      { exact le_sup_of_le_right (le_bsupr n h) },\n      { exact h \u25b8 le_sup_left } },\n    { refine sup_le _ _,\n      { convert @le_bsupr _ _ _ (\u03bb i, i \u2264 m + 1) _ m.succ (le_refl _), refl },\n      { refine bsupr_le (\u03bb n hn, _),\n        have := (le_trans hn (nat.le_succ m)), -- repacing this breaks?\n        exact (le_bsupr n this) } } },\nend\n\nlemma supr_mem_measurable_le \n  (f : \u2115 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) (hf : \u2200 n, f n \u2208 measurable_le \u03bc \u03bd) (n : \u2115) : \n  (\u03bb x, \u2a06 k (hk : k \u2264 n), f k x) \u2208 measurable_le \u03bc \u03bd :=\nbegin\n  induction n with m hm,\n  { refine \u27e8_, _\u27e9,\n    { simp [(hf 0).1] },\n    { intros A hA, simp [(hf 0).2 A hA] } },\n  { have : (\u03bb (a : \u03b1), \u2a06 (k : \u2115) (hk : k \u2264 m + 1), f k a) =  \n      (\u03bb a, f m.succ a \u2294 \u2a06 (k : \u2115) (hk : k \u2264 m), f k a),\n    { exact funext (\u03bb _, supr_succ_eq_sup _ _ _) },\n    refine \u27e8measurable_supr (\u03bb n, measurable.supr_Prop _ (hf n).1), \u03bb A hA, _\u27e9,\n    rw this, exact (sup_mem_measurable_le (hf m.succ) hm).2 A hA }\nend\n\nlemma supr_mem_measurable_le' \n  (f : \u2115 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) (hf : \u2200 n, f n \u2208 measurable_le \u03bc \u03bd) (n : \u2115) : \n  (\u2a06 k (hk : k \u2264 n), f k) \u2208 measurable_le \u03bc \u03bd :=\nbegin\n  convert supr_mem_measurable_le f hf n,\n  ext, simp\nend\n\nlemma supr_monotone (f : \u2115 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) : \n  monotone (\u03bb n x, \u2a06 k (hk : k \u2264 n), f k x) :=\nbegin\n  intros n m hnm x,\n  simp only,\n  refine bsupr_le (\u03bb k hk, _),\n  have : k \u2264 m, exact le_trans hk hnm, -- same problem here\n  exact le_bsupr k this,\nend\n\nlemma supr_monotone' (f : \u2115 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) (x : \u03b1) : \n  monotone (\u03bb n, \u2a06 k (hk : k \u2264 n), f k x) :=\n\u03bb n m hnm, supr_monotone f hnm x\n\nlemma supr_le_le (f : \u2115 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) (n k : \u2115) (hk : k \u2264 n) : \n  f k \u2264 \u03bb x, \u2a06 k (hk : k \u2264 n), f k x :=\n\u03bb x, le_bsupr k hk\n\ndef M (\u03bc \u03bd : measure \u03b1) := (\u03bb f : \u03b1 \u2192 \u211d\u22650\u221e, \u222b\u207b x, f x \u2202\u03bc) '' measurable_le \u03bc \u03bd\n    \nlemma M_bdd_above : Sup (M \u03bc \u03bd) \u2264 \u03bd set.univ :=\nbegin\n  refine Sup_le _,\n  rintro _ \u27e8f, \u27e8hf\u2081, hf\u2082\u27e9, rfl\u27e9,\n  simp only,\n  rw \u2190 lintegral_univ_eq,\n  exact hf\u2082 set.univ measurable_set.univ,\nend\n\nvariables [finite_measure \u03bc] [finite_measure \u03bd]\n\nlocal infix ` . `:max := measure.with_density\n\nsection\n\nopen filter\n\nlemma tendsto_supr_le (f : \u2115 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) (x : \u03b1) :\n  tendsto (\u03bb n, \u2a06 k (hk : k \u2264 n), f k x) at_top (nhds  \u2a06 n k (hk : k \u2264 n), f k x) :=\ntendsto_at_top_supr (supr_monotone' f x)\n\nend\n\nlemma finite_measure_of_finite_lintegral \n  {f : \u03b1 \u2192 \u211d\u22650\u221e} (hf : \u222b\u207b a, f a \u2202\u03bc < \u221e) : finite_measure (\u03bc . f) := \n{ measure_univ_lt_top := by rwa [with_density_apply _ measurable_set.univ, lintegral_univ_eq] }\n\nlemma ennreal.to_real_sub_of_le {a b : \u211d\u22650\u221e} (h : b \u2264 a) (ha : a \u2260 \u221e): \n  (a - b).to_real = a.to_real - b.to_real :=\nbegin\n  lift b to \u211d\u22650 using ne_top_of_le_ne_top ha h,\n  lift a to \u211d\u22650 using ha,\n  simp only [\u2190 ennreal.coe_sub, ennreal.coe_to_real, nnreal.coe_sub (ennreal.coe_le_coe.mp h)],\nend\n\nexample (a b c : \u211d) (h : b = c) : b + a = c + a :=\nbegin\n  exact congr_fun (congr_arg has_add.add h) a,\nend\n\nlemma ennreal.lt_add_of_pos_right {a b : \u211d\u22650\u221e} (hb : 0 < b) (ha : a \u2260 \u22a4): a < a + b :=\nbegin\n  lift a to \u211d\u22650 using ha,\n  by_cases b = \u22a4,\n  { rw [h, ennreal.add_top],\n    exact ennreal.coe_lt_top },\n  { lift b to \u211d\u22650 using h,\n    rw [\u2190 ennreal.coe_add, ennreal.coe_lt_coe],\n    refine lt_add_of_pos_right a (ennreal.coe_pos.mp hb) }\nend\n\n/-- The Lebesgue decomposition theorem: Given finite measures `\u03bc` and `\u03bd`, there exists \nmeasures `\u03bd\u2081`, `\u03bd\u2082` such that `\u03bd\u2081` is mutually singular to `\u03bc` and there exists some \n`f : \u03b1 \u2192 \u211d\u22650\u221e` such that `\u03bd\u2082 = \u03bc.with_density f`. -/\ntheorem exists_singular_with_density (\u03bc \u03bd : measure \u03b1) [finite_measure \u03bc] [finite_measure \u03bd] : \n  \u2203 (\u03bd\u2081 \u03bd\u2082 : measure \u03b1) [finite_measure \u03bd\u2081] [finite_measure \u03bd\u2082] (h\u03bd : \u03bd = \u03bd\u2081 + \u03bd\u2082), \n  \u03bd\u2081 \u22a5 \u03bc \u2227 \u2203 (f : \u03b1 \u2192 \u211d\u22650\u221e) (hf : measurable f), \u03bd\u2082 = \u03bc . f := \nbegin\n  have h := @ennreal.exists_tendsto_Sup (M \u03bc \u03bd) _,\n  { choose g hg\u2081 hg\u2082 using h,\n    choose f hf\u2081 hf\u2082 using hg\u2081,\n\n    set \u03b6 := \u2a06 n k (hk : k \u2264 n), f k with h\u03b6,\n    have h\u03b6\u2081 : Sup (M \u03bc \u03bd) = \u222b\u207b a, \u03b6 a \u2202\u03bc,\n    { have := @lintegral_tendsto_of_tendsto_of_monotone _ _ \u03bc \n        (\u03bb n, \u2a06 k (hk : k \u2264 n), f k) (\u2a06 n k (hk : k \u2264 n), f k) _ _ _,\n      { refine tendsto_nhds_unique _ this,\n        refine tendsto_of_tendsto_of_tendsto_of_le_of_le hg\u2082 tendsto_const_nhds _ _,\n        { intro n, rw \u2190 hf\u2082 n,\n          apply lintegral_mono,\n          simp only [supr_apply, supr_le_le f n n (le_refl _)] },\n        { intro n,\n          exact le_Sup \u27e8\u2a06 (k : \u2115) (hk : k \u2264 n), f k, supr_mem_measurable_le' _ hf\u2081 _, rfl\u27e9 } },\n      { intro n, \n        refine measurable.ae_measurable _,\n        convert (supr_mem_measurable_le _ hf\u2081 n).1,\n        ext, simp },\n      { refine filter.eventually_of_forall (\u03bb a, _),\n        simp [supr_monotone' f _] },\n      { refine filter.eventually_of_forall (\u03bb a, _),\n        simp [tendsto_supr_le _ _] } },\n    have h\u03b6m : measurable \u03b6,\n      { convert measurable_supr (\u03bb n, (supr_mem_measurable_le _ hf\u2081 n).1),\n        ext, simp [h\u03b6] },\n\n    set \u03bd\u2081 := \u03bd - \u03bc . \u03b6 with h\u03bd\u2081,\n\n    have hle : \u03bc . \u03b6 \u2264 \u03bd,\n      { intros B hB,\n        rw [h\u03b6, with_density_apply _ hB],\n        simp_rw [supr_apply],\n        rw lintegral_supr (\u03bb i, (supr_mem_measurable_le _ hf\u2081 i).1) (supr_monotone _),\n        exact supr_le (\u03bb i, (supr_mem_measurable_le _ hf\u2081 i).2 B hB) },\n    haveI : finite_measure (\u03bc . \u03b6) := by\n      { refine finite_measure_of_finite_lintegral _,\n        have hle' := hle set.univ measurable_set.univ, \n        rw [with_density_apply _ measurable_set.univ, lintegral_univ_eq] at hle',\n        exact lt_of_le_of_lt hle' (measure_lt_top _ _) },\n\n    refine \u27e8\u03bd\u2081, \u03bc . \u03b6, infer_instance, infer_instance, _, _, \u03b6, h\u03b6m, rfl\u27e9,\n    { rw h\u03bd\u2081, ext1 A hA, \n      rw [measure.coe_add, pi.add_apply, measure.sub_apply hA hle, \n          add_comm, ennreal.add_sub_cancel_of_le (hle A hA)] },\n\n    { by_contra,\n      have hle : \u03bc . \u03b6 \u2264 \u03bd,\n      { intros B hB,\n        rw [h\u03b6, with_density_apply _ hB],\n        simp_rw [supr_apply],\n        rw lintegral_supr (\u03bb i, (supr_mem_measurable_le _ hf\u2081 i).1) (supr_monotone _),\n        exact supr_le (\u03bb i, (supr_mem_measurable_le _ hf\u2081 i).2 B hB) },\n      haveI : finite_measure (\u03bc . \u03b6) := by\n      { refine finite_measure_of_finite_lintegral _,\n        have hle' := hle set.univ measurable_set.univ, \n        rw [with_density_apply _ measurable_set.univ, lintegral_univ_eq] at hle',\n        exact lt_of_le_of_lt hle' (measure_lt_top _ _) },\n\n      obtain \u27e8\u03b5, h\u03b5\u2081, E, hE\u2081, hE\u2082, hE\u2083\u27e9 := exists_positive_of_sub_measure \u03bd\u2081 \u03bc h, \n      simp_rw h\u03bd\u2081 at hE\u2083,\n\n      have h\u03b6le : \u2200 A, measurable_set A \u2192 \u222b\u207b a in A, \u03b6 a \u2202\u03bc \u2264 \u03bd A,\n      { intros A hA, rw h\u03b6,\n        simp_rw [supr_apply],\n        rw lintegral_supr (\u03bb n, (supr_mem_measurable_le _ hf\u2081 n).1) (supr_monotone _),\n        exact supr_le (\u03bb n, (supr_mem_measurable_le _ hf\u2081 n).2 A hA) },\n\n      have h\u03b5\u2082 : \u2200 A : set \u03b1, measurable_set A \u2192 \n        \u222b\u207b a in A \u2229 E, \u03b5 + \u03b6 a \u2202\u03bc \u2264 \u03bd (A \u2229 E),\n      { intros A hA,\n        have := hE\u2083 (A \u2229 E) (set.inter_subset_right _ _) (measurable_set.inter hA hE\u2081),\n        rwa [of_sub_measure_apply (measurable_set.inter hA hE\u2081), \n            measure.sub_apply (measurable_set.inter hA hE\u2081) hle, \n            ennreal.to_real_sub_of_le _ (ne_of_lt (measure_lt_top _ _)), sub_nonneg, \n            le_sub_iff_add_le, \u2190 ennreal.to_real_add, ennreal.to_real_le_to_real, \n            measure.coe_nnreal_smul, pi.smul_apply, with_density_apply,\n            show \u03b5 \u2022 \u03bc (A \u2229 E) = (\u03b5 : \u211d\u22650\u221e) * \u03bc (A \u2229 E), by refl, \n            \u2190 set_lintegral_const, \u2190 lintegral_add measurable_const h\u03b6m] at this,\n        { exact measurable_set.inter hA hE\u2081 },    \n        { rw [ne.def, ennreal.add_eq_top, not_or_distrib],\n          exact \u27e8ne_of_lt (measure_lt_top _ _), ne_of_lt (measure_lt_top _ _)\u27e9 },\n        { exact ne_of_lt (measure_lt_top _ _) },\n        { exact ne_of_lt (measure_lt_top _ _) },\n        { exact ne_of_lt (measure_lt_top _ _) },\n        { rw with_density_apply _ (measurable_set.inter hA hE\u2081),\n          exact h\u03b6le (A \u2229 E) (measurable_set.inter hA hE\u2081) },\n        { apply_instance } },\n\n      have h\u03b6\u03b5 : \u03b6 + E.indicator (\u03bb _, \u03b5) \u2208 measurable_le \u03bc \u03bd,\n      { refine \u27e8measurable.add h\u03b6m (measurable.indicator measurable_const hE\u2081), \u03bb A hA, _\u27e9,\n        have : \u222b\u207b a in A, (\u03b6 + E.indicator (\u03bb _, \u03b5)) a \u2202\u03bc = \n              \u222b\u207b a in A \u2229 E, \u03b5 + \u03b6 a \u2202\u03bc + \u222b\u207b a in A \u2229 E\u1d9c, \u03b6 a \u2202\u03bc,\n        { rw [lintegral_add measurable_const h\u03b6m, add_assoc, \n              \u2190 lintegral_union (measurable_set.inter hA hE\u2081) \n                (measurable_set.inter hA (measurable_set.compl hE\u2081))\n                (disjoint.mono (set.inter_subset_right _ _) (set.inter_subset_right _ _) \n                E.disjoint_compl), set.inter_union_compl],\n          simp_rw [pi.add_apply],\n          rw [lintegral_add h\u03b6m (measurable.indicator measurable_const hE\u2081), add_comm],\n          refine congr_fun (congr_arg has_add.add _) _,\n          rw [set_lintegral_const, lintegral_indicator _ hE\u2081, set_lintegral_const, \n              measure.restrict_apply hE\u2081, set.inter_comm] },\n        conv_rhs { rw \u2190 set.inter_union_compl A E },\n        rw [this, measure_union (set.disjoint_inter_compl _ _) (measurable_set.inter hA hE\u2081) \n          (measurable_set.inter hA (measurable_set.compl hE\u2081))],\n        exact add_le_add (h\u03b5\u2082 A hA) \n          (h\u03b6le (A \u2229 E\u1d9c) (measurable_set.inter hA (measurable_set.compl hE\u2081))) },\n\n      have : \u222b\u207b a, \u03b6 a + E.indicator (\u03bb _, \u03b5) a \u2202\u03bc \u2264 Sup (M \u03bc \u03bd),\n      { exact le_Sup \u27e8\u03b6 + E.indicator (\u03bb _, \u03b5), h\u03b6\u03b5, rfl\u27e9 },\n\n      refine not_lt.2 this _,  \n      rw [h\u03b6\u2081, lintegral_add h\u03b6m (measurable.indicator (measurable_const) hE\u2081), \n          lintegral_indicator _ hE\u2081, set_lintegral_const],\n      refine ennreal.lt_add_of_pos_right (ennreal.mul_pos.2 \u27e8ennreal.coe_pos.2 h\u03b5\u2081, hE\u2082\u27e9) _,\n      rw [\u2190 lintegral_univ_eq, \u2190 with_density_apply _ measurable_set.univ],\n      exact ne_of_lt (measure_lt_top _ _) } },\n  { exact \u27e80, 0, zero_mem_measurable_le, by simp\u27e9 },\nend\n\nlemma measure.eq_of_sub_measure_eq_zero (\u03bc \u03bd : measure \u03b1) [finite_measure \u03bc] [finite_measure \u03bd] \n  (h : of_sub_measure \u03bc \u03bd = 0) : \u03bc = \u03bd :=\nbegin\n  refine measure_theory.measure.ext (\u03bb i hi, _), \n  rw [\u2190 ennreal.to_real_eq_to_real (measure_lt_top _ _) (measure_lt_top _ _), \n      \u2190 sub_eq_zero, \u2190 of_sub_measure_apply hi, h, zero_apply], \n  all_goals { apply_instance }\nend\n\n-- duplicated `measure.with_density_absolutely_continuous` in `conditional` \nlemma with_density.absolutely_continuous (f : \u03b1 \u2192 \u211d\u22650\u221e) : \u03bc . f \u226a \u03bc :=\nbegin\n  refine measure.absolutely_continuous.mk (\u03bb A hA h, _),\n  rw with_density_apply _ hA,\n  exact (measure.restrict_eq_zero.2 h).symm \u25b8 lintegral_zero_measure _,\nend\n\n/-- The Lebesgue decomposition is unique. -/\ntheorem singular_with_density_unique \n  (\u03bd\u2081 \u03bd\u2082 \u03bc\u2081 \u03bc\u2082 : measure \u03b1) \n  [finite_measure \u03bd\u2081] [finite_measure \u03bd\u2082] [finite_measure \u03bc\u2081] [finite_measure \u03bc\u2082]\n  (h\u03bd : \u03bd = \u03bd\u2081 + \u03bd\u2082) (h\u03bc : \u03bd = \u03bc\u2081 + \u03bc\u2082)\n  (h\u2081 : \u03bd\u2081 \u22a5 \u03bc \u2227 \u2203 (f : \u03b1 \u2192 \u211d\u22650\u221e) (hf : measurable f), \u03bd\u2082 = \u03bc . f) \n  (h\u2082 : \u03bc\u2081 \u22a5 \u03bc \u2227 \u2203 (f : \u03b1 \u2192 \u211d\u22650\u221e) (hf : measurable f), \u03bc\u2082 = \u03bc . f) :\n  \u03bd\u2081 = \u03bc\u2081 \u2227 \u03bd\u2082 = \u03bc\u2082 :=\nbegin\n  obtain \u27e8S, hS\u2081, hS\u2082, hS\u2083\u27e9 := h\u2081.1,\n  obtain \u27e8T, hT\u2081, hT\u2082, hT\u2083\u27e9 := h\u2082.1,\n  \n  have hsub : of_sub_measure \u03bd\u2081 \u03bc\u2081 = of_sub_measure \u03bc\u2082 \u03bd\u2082,\n  { ext i hi,\n    rw [of_sub_measure_apply hi, of_sub_measure_apply hi],\n    suffices : (\u03bd\u2081 i).to_real + (\u03bd\u2082 i).to_real = (\u03bc\u2081 i).to_real + (\u03bc\u2082 i).to_real,\n    { linarith },\n    rw [\u2190 ennreal.to_real_add, \u2190 ennreal.to_real_add, ennreal.to_real_eq_to_real, \n        \u2190 measure.add_apply, \u2190 measure.add_apply, \u2190 h\u03bd, \u2190 h\u03bc],\n    { exact (ennreal.add_lt_top.2 \u27e8measure_lt_top _ _, measure_lt_top _ _\u27e9) },\n    { exact (ennreal.add_lt_top.2 \u27e8measure_lt_top _ _, measure_lt_top _ _\u27e9) },\n    all_goals { exact ne_of_lt (measure_lt_top _ _) } },\n  have heq : \u2200 A (hA : measurable_set A), \n    of_sub_measure \u03bd\u2081 \u03bc\u2081 A = of_sub_measure \u03bd\u2081 \u03bc\u2081 (A \u2229 (S \u2229 T)\u1d9c),\n  { intros A hA,\n    have : A = (A \u2229 (S \u2229 T)\u1d9c) \u222a (A \u2229 (S \u2229 T)), \n    { rw [\u2190 set.inter_union_distrib_left, set.compl_union_self, set.inter_univ] },\n    conv_lhs { rw this },\n    rw measure_of_union (disjoint.comm.1 (set.disjoint_inter_compl A (S \u2229 T))),\n    suffices : (of_sub_measure \u03bd\u2081 \u03bc\u2081) (A \u2229 (S \u2229 T)) = 0,\n    { rw [this, add_zero] },\n    rw [of_sub_measure_apply, sub_eq_zero, ennreal.to_real_eq_to_real],\n    refine eq.trans (nonpos_iff_eq_zero.1 (hS\u2082 \u25b8 measure_mono _)) \n      (eq.symm ((nonpos_iff_eq_zero.1 (hT\u2082 \u25b8 measure_mono _)))),\n    { rw [set.inter_comm, set.inter_assoc],\n      exact set.inter_subset_left _ _ },\n    { rw \u2190 set.inter_assoc, exact set.inter_subset_right _ _ },\n    { exact measure_lt_top _ _ },\n    { exact measure_lt_top _ _ },\n    measurability },\n  have h\u03bd\u2082 : \u03bd\u2082 \u226a \u03bc, \n  { obtain \u27e8-, f, -, hf\u27e9 := h\u2081, rw hf,\n    exact with_density.absolutely_continuous _ },\n  have h\u03bc\u2082 : \u03bc\u2082 \u226a \u03bc, \n  { obtain \u27e8-, f, -, hf\u27e9 := h\u2082, rw hf,\n    exact with_density.absolutely_continuous _ },\n  have h\u03bcinter : \u03bc (S \u2229 T)\u1d9c = 0,\n    { rw set.compl_inter,\n      refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) _),\n      rw [hS\u2083, hT\u2083, add_zero], \n      exact le_refl _ },\n\n  suffices : of_sub_measure \u03bd\u2081 \u03bc\u2081 = 0,\n  { refine \u27e8measure.eq_of_sub_measure_eq_zero _ _ this, \n            eq.symm (measure.eq_of_sub_measure_eq_zero _ _ _)\u27e9,\n    rwa \u2190 hsub },\n\n  ext A hA,\n  rw [heq A hA, hsub, of_sub_measure_apply, h\u03bd\u2082, h\u03bc\u2082, ennreal.zero_to_real, \n      sub_zero, zero_apply],\n  { exact nonpos_iff_eq_zero.1 (h\u03bcinter \u25b8 measure_mono (set.inter_subset_right _ _)) },\n  { exact nonpos_iff_eq_zero.1 (h\u03bcinter \u25b8 measure_mono (set.inter_subset_right _ _)) },\n  { measurability }\nend\n\n/-- The Radon-Nikodym theorem: Given two finite measures `\u03bc` and `\u03bd`, if `\u03bd` is absolutely \ncontinuous with respect to `\u03bc`, then there exists a measurable function `f` such that \n`f` is the derivative of `\u03bd` with respect to `\u03bc`. -/\ntheorem exists_with_density_of_absolute_continuous \n  (\u03bc \u03bd : measure \u03b1) [finite_measure \u03bc] [finite_measure \u03bd] (h : \u03bd \u226a \u03bc) : \n  \u2203 (f : \u03b1 \u2192 \u211d\u22650\u221e) (hf : measurable f), \u03bd = \u03bc . f :=\nbegin\n  obtain \u27e8\u03bd\u2081, \u03bd\u2082, _, _, h\u03bd, \u27e8E, hE\u2081, hE\u2082, hE\u2083\u27e9, f, hf\u2081, hf\u2082\u27e9 := \n    exists_singular_with_density \u03bc \u03bd,\n  have : \u03bd\u2081 = 0,\n  { apply le_antisymm,\n    { intros A hA,\n      suffices : \u03bd\u2081 set.univ = 0,\n      { rw [measure.coe_zero, pi.zero_apply, \u2190 this],\n        exact measure_mono (set.subset_univ _) },\n      rw [\u2190 set.union_compl_self E, measure_union (set.disjoint_compl E) hE\u2081 \n            (measurable_set.compl hE\u2081), hE\u2082, zero_add],\n      have : (\u03bd\u2081 + \u03bd\u2082) E\u1d9c = \u03bd E\u1d9c, { rw h\u03bd },\n      rw [measure.coe_add, pi.add_apply, h hE\u2083] at this,\n      exact (add_eq_zero_iff.1 this).1 },\n    { exact measure.zero_le _} },\n  rw [this, zero_add] at h\u03bd, \n  exact \u27e8f, hf\u2081, h\u03bd.symm \u25b8 hf\u2082\u27e9,\nend \n\nend signed_measure", "meta": {"author": "JasonKYi", "repo": "probability_theory", "sha": "01aa0e1372cb0311c90be59ea18944c5ef5f2293", "save_path": "github-repos/lean/JasonKYi-probability_theory", "path": "github-repos/lean/JasonKYi-probability_theory/probability_theory-01aa0e1372cb0311c90be59ea18944c5ef5f2293/archive/singular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7104125309614596}}
{"text": "/-\nCopyright (c) 2021 Alex Zhao. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Zhao\n\n! This file was ported from Lean 3 source module number_theory.frobenius_number\n! leanprover-community/mathlib commit 1126441d6bccf98c81214a0780c73d499f6721fe\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.ModEq\nimport Mathlib.GroupTheory.Submonoid.Basic\nimport Mathlib.GroupTheory.Submonoid.Membership\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Zify\n\n/-!\n# Frobenius Number in Two Variables\n\nIn this file we first define a predicate for Frobenius numbers, then solve the 2-variable variant\nof this problem.\n\n## Theorem Statement\n\nGiven a finite set of relatively prime integers all greater than 1, their Frobenius number is the\nlargest positive integer that cannot be expressed as a sum of nonnegative multiples of these\nintegers. Here we show the Frobenius number of two relatively prime integers `m` and `n` greater\nthan 1 is `m * n - m - n`. This result is also known as the Chicken McNugget Theorem.\n\n## Implementation Notes\n\nFirst we define Frobenius numbers in general using `IsGreatest` and `AddSubmonoid.closure`. Then\nwe proceed to compute the Frobenius number of `m` and `n`.\n\nFor the upper bound, we begin with an auxiliary lemma showing `m * n` is not attainable, then show\n`m * n - m - n` is not attainable. Then for the construction, we create a `k_1` which is `k mod n`\nand `0 mod m`, then show it is at most `k`. Then `k_1` is a multiple of `m`, so `(k-k_1)`\nis a multiple of n, and we're done.\n\n## Tags\n\nfrobenius number, chicken mcnugget, chinese remainder theorem, add_submonoid.closure\n-/\n\n\nopen Nat\n\n/-- A natural number `n` is the **Frobenius number** of a set of natural numbers `s` if it is an\nupper bound on the complement of the additive submonoid generated by `s`.\nIn other words, it is the largest number that can not be expressed as a sum of numbers in `s`. -/\ndef FrobeniusNumber (n : \u2115) (s : Set \u2115) : Prop :=\n  IsGreatest { k | k \u2209 AddSubmonoid.closure s } n\n#align is_frobenius_number FrobeniusNumber\n\nvariable {m n : \u2115}\n\n/-- The **Chicken Mcnugget theorem** stating that the Frobenius number\n  of positive numbers `m` and `n` is `m * n - m - n`. -/\ntheorem frobeniusNumber_pair (cop : coprime m n) (hm : 1 < m) (hn : 1 < n) :\n    FrobeniusNumber (m * n - m - n) {m, n} := by\n  simp_rw [FrobeniusNumber, AddSubmonoid.mem_closure_pair]\n  have hmn : m + n \u2264 m * n := add_le_mul hm hn\n  constructor\n  \u00b7 push_neg\n    intro a b h\n    apply cop.mul_add_mul_ne_mul (add_one_ne_zero a) (add_one_ne_zero b)\n    simp only [Nat.sub_sub, smul_eq_mul] at h\n    zify [hmn] at h \u22a2\n    rw [\u2190 sub_eq_zero] at h \u22a2\n    rw [\u2190 h]\n    ring\n  \u00b7 intro k hk\n    dsimp at hk\n    contrapose! hk\n    let x := chineseRemainder cop 0 k\n    have hx : x.val < m * n := chineseRemainder_lt_mul cop 0 k (ne_bot_of_gt hm) (ne_bot_of_gt hn)\n    suffices key : x.1 \u2264 k\n    \u00b7 obtain \u27e8a, ha\u27e9 := modEq_zero_iff_dvd.mp x.2.1\n      obtain \u27e8b, hb\u27e9 := (modEq_iff_dvd' key).mp x.2.2\n      exact \u27e8a, b, by rw [mul_comm, \u2190 ha, mul_comm, \u2190 hb, Nat.add_sub_of_le key]\u27e9\n    refine' ModEq.le_of_lt_add x.2.2 (lt_of_le_of_lt _ (add_lt_add_right hk n))\n    rw [Nat.sub_add_cancel (le_tsub_of_add_le_left hmn)]\n    exact\n      ModEq.le_of_lt_add\n        (x.2.1.trans (modEq_zero_iff_dvd.mpr (Nat.dvd_sub' (dvd_mul_right m n) dvd_rfl)).symm)\n        (lt_of_lt_of_le hx le_tsub_add)\n#align is_frobenius_number_pair frobeniusNumber_pair\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/NumberTheory/FrobeniusNumber.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509314, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7103897786867729}}
{"text": "\ntheorem Ex006(a b c : Prop): a \u2228 b \u2192 a \u2228 c \u2192 a \u2228 (b \u2227 c) :=\nassume H1:a \u2228 b,\n  assume H2:a \u2228 c,\n  show a \u2228 (b \u2227 c), from or.elim H1 \n    ( \n      assume H :a,\n      show a \u2228 (b \u2227 c), from or.inl H\n    )\n    (\n      assume H: b,\n      show a \u2228 (b \u2227 c), from or.elim H2 \n        (\n          assume HH:a,\n          show a \u2228 (b \u2227 c), from or.inl HH\n        )\n        (\n          assume HH:c,\n          have H3:b \u2227 c, from and.intro H HH,\n          show a \u2228 (b \u2227 c), from or.inr H3\n        )\n    ) \n", "meta": {"author": "SvenWille", "repo": "LeanLogicExercises", "sha": "2dbc920feadd63bbc50f87e69646c0081db26eba", "save_path": "github-repos/lean/SvenWille-LeanLogicExercises", "path": "github-repos/lean/SvenWille-LeanLogicExercises/LeanLogicExercises-2dbc920feadd63bbc50f87e69646c0081db26eba/src/propLogic/Ex006.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7103897698530525}}
{"text": "import data.real.basic\n\nvariables {u : \u2115 \u2192 \u211d} {a l : \u211d}\n\nnotation `|`x`|` := abs x\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\ndef cauchy_sequence (u : \u2115 \u2192 \u211d) := \u2200 \u03b5 > 0, \u2203 N, \u2200 p q, p \u2265 N \u2192 q \u2265 N \u2192 |u p - u q| \u2264 \u03b5\n\nexample : (\u2203 l, seq_limit u l) \u2192 cauchy_sequence u :=\nbegin\n  intros h eps eps_pos,\n  cases h with l hl,\n  rw seq_limit at hl,\n  cases hl (eps/2) (by linarith) with N hN,\n  use N,\n  intros p q hp hq,\n  calc |u p - u q| = |(u p - l)+(l - u q)| : by ring\n              ... \u2264 |u p - l| + |l - u q|  : by apply abs_add\n              ... = |u p - l| + |u q - l|  : by rw abs_sub l (u q)\n              ... \u2264 eps/2 + eps/2          : by linarith [hN p hp, hN q hq]\n              ... = eps                    : by ring,\nend", "meta": {"author": "saradiazr11", "repo": "IMO_en_Lean", "sha": "d8fb219af4d0c1afaecb36556ac5ecf8dd03b453", "save_path": "github-repos/lean/saradiazr11-IMO_en_Lean", "path": "github-repos/lean/saradiazr11-IMO_en_Lean/IMO_en_Lean-d8fb219af4d0c1afaecb36556ac5ecf8dd03b453/src/Elementos/Convergente_Cauchy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090322, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.7103897663179914}}
{"text": "-- absoluto_resta.lean\n-- Si a, b \u2208 \u211d, entonces |a| - |b| \u2264 |a - b|\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 5-octubre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Sean a y b n\u00fameros reales. Demostrar que\n--    |a| - |b| \u2264 |a - b|\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : \u211d\n\nexample : |a| - |b| \u2264 |a - b| :=\ncalc |a| - |b|\n     = |a - b + b| - |b|     : by simp\n ... \u2264 (|a - b| + |b|) - |b| : sub_le_sub_right (abs_add (a - b) b) (|b|)\n ... = |a - b|               : add_sub_cancel (|a - b|) (|b|)\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/absoluto_resta.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7103897627829303}}
{"text": "/-\nCopyright (c) 2022 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport topology.local_extr\nimport topology.order.basic\n\n/-!\n# Maximum/minimum on the closure of a set\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove several versions of the following statement: if `f : X \u2192 Y` has a (local or\nnot) maximum (or minimum) on a set `s` at a point `a` and is continuous on the closure of `s`, then\n`f` has an extremum of the same type on `closure s` at `a`.\n-/\n\nopen filter set\nopen_locale topology\n\nvariables {X Y : Type*} [topological_space X] [topological_space Y] [preorder Y]\n  [order_closed_topology Y] {f g : X \u2192 Y} {s : set X} {a : X}\n\nprotected lemma is_max_on.closure (h : is_max_on f s a) (hc : continuous_on f (closure s)) :\n  is_max_on f (closure s) a :=\n\u03bb x hx, continuous_within_at.closure_le hx ((hc x hx).mono subset_closure)\n  continuous_within_at_const h\n\nprotected lemma is_min_on.closure (h : is_min_on f s a) (hc : continuous_on f (closure s)) :\n  is_min_on f (closure s) a :=\nh.dual.closure hc\n\nprotected lemma is_extr_on.closure (h : is_extr_on f s a) (hc : continuous_on f (closure s)) :\n  is_extr_on f (closure s) a :=\nh.elim (\u03bb h, or.inl $ h.closure hc) (\u03bb h, or.inr $ h.closure hc)\n\nprotected lemma is_local_max_on.closure (h : is_local_max_on f s a)\n  (hc : continuous_on f (closure s)) :\n  is_local_max_on f (closure s) a :=\nbegin\n  rcases mem_nhds_within.1 h with \u27e8U, Uo, aU, hU\u27e9,\n  refine mem_nhds_within.2 \u27e8U, Uo, aU, _\u27e9,\n  rintro x \u27e8hxU, hxs\u27e9,\n  refine continuous_within_at.closure_le _ _ continuous_within_at_const hU,\n  { rwa [mem_closure_iff_nhds_within_ne_bot, nhds_within_inter_of_mem,\n      \u2190 mem_closure_iff_nhds_within_ne_bot],\n    exact nhds_within_le_nhds (Uo.mem_nhds hxU) },\n  { exact (hc _ hxs).mono ((inter_subset_right _ _).trans subset_closure) }\nend\n\nprotected lemma is_local_min_on.closure (h : is_local_min_on f s a)\n  (hc : continuous_on f (closure s)) :\n  is_local_min_on f (closure s) a :=\nis_local_max_on.closure h.dual hc\n\nprotected lemma is_local_extr_on.closure (h : is_local_extr_on f s a)\n  (hc : continuous_on f (closure s)) :\n  is_local_extr_on f (closure s) a :=\nh.elim (\u03bb h, or.inl $ h.closure hc) (\u03bb h, or.inr $ h.closure hc)\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/order/extr_closure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.7103776361835302}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Scott Morrison, Ainsley Pahljina\n\n! This file was ported from Lean 3 source module number_theory.lucas_lehmer\n! leanprover-community/mathlib commit 10b4e499f43088dd3bb7b5796184ad5216648ab1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Parity\nimport Mathbin.Data.Pnat.Interval\nimport Mathbin.Data.Zmod.Basic\nimport Mathbin.GroupTheory.OrderOfElement\nimport Mathbin.RingTheory.Fintype\nimport Mathbin.Tactic.IntervalCases\nimport Mathbin.Tactic.RingExp\n\n/-!\n# The Lucas-Lehmer test for Mersenne primes.\n\nWe define `lucas_lehmer_residue : \u03a0 p : \u2115, zmod (2^p - 1)`, and\nprove `lucas_lehmer_residue p = 0 \u2192 prime (mersenne p)`.\n\nWe construct a tactic `lucas_lehmer.run_test`, which iteratively certifies the arithmetic\nrequired to calculate the residue, and enables us to prove\n\n```\nexample : prime (mersenne 127) :=\nlucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test)\n```\n\n## TODO\n\n- Show reverse implication.\n- Speed up the calculations using `n \u2261 (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`.\n- Find some bigger primes!\n\n## History\n\nThis development began as a student project by Ainsley Pahljina,\nand was then cleaned up for mathlib by Scott Morrison.\nThe tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro.\n-/\n\n\n/-- The Mersenne numbers, 2^p - 1. -/\ndef mersenne (p : \u2115) : \u2115 :=\n  2 ^ p - 1\n#align mersenne mersenne\n\ntheorem mersenne_pos {p : \u2115} (h : 0 < p) : 0 < mersenne p :=\n  by\n  dsimp [mersenne]\n  calc\n    0 < 2 ^ 1 - 1 := by norm_num\n    _ \u2264 2 ^ p - 1 := Nat.pred_le_pred (Nat.pow_le_pow_of_le_right (Nat.succ_pos 1) h)\n    \n#align mersenne_pos mersenne_pos\n\n@[simp]\ntheorem succ_mersenne (k : \u2115) : mersenne k + 1 = 2 ^ k :=\n  by\n  rw [mersenne, tsub_add_cancel_of_le]\n  exact one_le_pow_of_one_le (by norm_num) k\n#align succ_mersenne succ_mersenne\n\nnamespace LucasLehmer\n\nopen Nat\n\n/-!\nWe now define three(!) different versions of the recurrence\n`s (i+1) = (s i)^2 - 2`.\n\nThese versions take values either in `\u2124`, in `zmod (2^p - 1)`, or\nin `\u2124` but applying `% (2^p - 1)` at each step.\n\nThey are each useful at different points in the proof,\nso we take a moment setting up the lemmas relating them.\n-/\n\n\n/-- The recurrence `s (i+1) = (s i)^2 - 2` in `\u2124`. -/\ndef s : \u2115 \u2192 \u2124\n  | 0 => 4\n  | i + 1 => s i ^ 2 - 2\n#align lucas_lehmer.s LucasLehmer.s\n\n/-- The recurrence `s (i+1) = (s i)^2 - 2` in `zmod (2^p - 1)`. -/\ndef sZmod (p : \u2115) : \u2115 \u2192 ZMod (2 ^ p - 1)\n  | 0 => 4\n  | i + 1 => s_zmod i ^ 2 - 2\n#align lucas_lehmer.s_zmod LucasLehmer.sZmod\n\n/-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `\u2124`. -/\ndef sMod (p : \u2115) : \u2115 \u2192 \u2124\n  | 0 => 4 % (2 ^ p - 1)\n  | i + 1 => (s_mod i ^ 2 - 2) % (2 ^ p - 1)\n#align lucas_lehmer.s_mod LucasLehmer.sMod\n\ntheorem mersenne_int_ne_zero (p : \u2115) (w : 0 < p) : (2 ^ p - 1 : \u2124) \u2260 0 :=\n  by\n  apply ne_of_gt; simp only [gt_iff_lt, sub_pos]\n  exact_mod_cast Nat.one_lt_two_pow p w\n#align lucas_lehmer.mersenne_int_ne_zero LucasLehmer.mersenne_int_ne_zero\n\ntheorem sMod_nonneg (p : \u2115) (w : 0 < p) (i : \u2115) : 0 \u2264 sMod p i :=\n  by\n  cases i <;> dsimp [s_mod]\n  \u00b7 exact sup_eq_right.mp rfl\n  \u00b7 apply Int.emod_nonneg\n    exact mersenne_int_ne_zero p w\n#align lucas_lehmer.s_mod_nonneg LucasLehmer.sMod_nonneg\n\ntheorem sMod_mod (p i : \u2115) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [s_mod]\n#align lucas_lehmer.s_mod_mod LucasLehmer.sMod_mod\n\ntheorem sMod_lt (p : \u2115) (w : 0 < p) (i : \u2115) : sMod p i < 2 ^ p - 1 :=\n  by\n  rw [\u2190 s_mod_mod]\n  convert Int.emod_lt _ _\n  \u00b7 refine' (abs_of_nonneg _).symm\n    simp only [sub_nonneg, ge_iff_le]\n    exact_mod_cast Nat.one_le_two_pow p\n  \u00b7 exact mersenne_int_ne_zero p w\n#align lucas_lehmer.s_mod_lt LucasLehmer.sMod_lt\n\ntheorem sZmod_eq_s (p' : \u2115) (i : \u2115) : sZmod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) :=\n  by\n  induction' i with i ih\n  \u00b7 dsimp [s, s_zmod]\n    norm_num\n  \u00b7 push_cast [s, s_zmod, ih]\n#align lucas_lehmer.s_zmod_eq_s LucasLehmer.sZmod_eq_s\n\n-- These next two don't make good `norm_cast` lemmas.\ntheorem Int.coe_nat_pow_pred (b p : \u2115) (w : 0 < b) : ((b ^ p - 1 : \u2115) : \u2124) = (b ^ p - 1 : \u2124) :=\n  by\n  have : 1 \u2264 b ^ p := Nat.one_le_pow p b w\n  norm_cast\n#align lucas_lehmer.int.coe_nat_pow_pred LucasLehmer.Int.coe_nat_pow_pred\n\ntheorem Int.coe_nat_two_pow_pred (p : \u2115) : ((2 ^ p - 1 : \u2115) : \u2124) = (2 ^ p - 1 : \u2124) :=\n  Int.coe_nat_pow_pred 2 p (by decide)\n#align lucas_lehmer.int.coe_nat_two_pow_pred LucasLehmer.Int.coe_nat_two_pow_pred\n\ntheorem sZmod_eq_sMod (p : \u2115) (i : \u2115) : sZmod p i = (sMod p i : ZMod (2 ^ p - 1)) := by\n  induction i <;> push_cast [\u2190 int.coe_nat_two_pow_pred p, s_mod, s_zmod, *]\n#align lucas_lehmer.s_zmod_eq_s_mod LucasLehmer.sZmod_eq_sMod\n\n/-- The Lucas-Lehmer residue is `s p (p-2)` in `zmod (2^p - 1)`. -/\ndef lucasLehmerResidue (p : \u2115) : ZMod (2 ^ p - 1) :=\n  sZmod p (p - 2)\n#align lucas_lehmer.lucas_lehmer_residue LucasLehmer.lucasLehmerResidue\n\ntheorem residue_eq_zero_iff_sMod_eq_zero (p : \u2115) (w : 1 < p) :\n    lucasLehmerResidue p = 0 \u2194 sMod p (p - 2) = 0 :=\n  by\n  dsimp [lucas_lehmer_residue]\n  rw [s_zmod_eq_s_mod p]\n  constructor\n  \u00b7 -- We want to use that fact that `0 \u2264 s_mod p (p-2) < 2^p - 1`\n    -- and `lucas_lehmer_residue p = 0 \u2192 2^p - 1 \u2223 s_mod p (p-2)`.\n    intro h\n    simp [ZMod.int_cast_zmod_eq_zero_iff_dvd] at h\n    apply Int.eq_zero_of_dvd_of_nonneg_of_lt _ _ h <;> clear h\n    apply s_mod_nonneg _ (Nat.lt_of_succ_lt w)\n    exact s_mod_lt _ (Nat.lt_of_succ_lt w) (p - 2)\n  \u00b7 intro h\n    rw [h]\n    simp\n#align lucas_lehmer.residue_eq_zero_iff_s_mod_eq_zero LucasLehmer.residue_eq_zero_iff_sMod_eq_zero\n\n/-- A Mersenne number `2^p-1` is prime if and only if\nthe Lucas-Lehmer residue `s p (p-2) % (2^p - 1)` is zero.\n-/\ndef LucasLehmerTest (p : \u2115) : Prop :=\n  lucasLehmerResidue p = 0deriving DecidablePred\n#align lucas_lehmer.lucas_lehmer_test LucasLehmer.LucasLehmerTest\n\n/-- `q` is defined as the minimum factor of `mersenne p`, bundled as an `\u2115+`. -/\ndef q (p : \u2115) : \u2115+ :=\n  \u27e8Nat.minFac (mersenne p), Nat.minFac_pos (mersenne p)\u27e9\n#align lucas_lehmer.q LucasLehmer.q\n\n-- It would be nice to define this as (\u2124/q\u2124)[x] / (x^2 - 3),\n-- obtaining the ring structure for free,\n-- but that seems to be more trouble than it's worth;\n-- if it were easy to make the definition,\n-- cardinality calculations would be somewhat more involved, too.\n/-- We construct the ring `X q` as \u2124/q\u2124 + \u221a3 \u2124/q\u2124. -/\ndef X (q : \u2115+) : Type :=\n  ZMod q \u00d7 ZMod q deriving AddCommGroup, DecidableEq, Fintype, Inhabited\n#align lucas_lehmer.X LucasLehmer.X\n\nnamespace X\n\nvariable {q : \u2115+}\n\n@[ext]\ntheorem ext {x y : X q} (h\u2081 : x.1 = y.1) (h\u2082 : x.2 = y.2) : x = y :=\n  by\n  cases x; cases y\n  congr <;> assumption\n#align lucas_lehmer.X.ext LucasLehmer.X.ext\n\n@[simp]\ntheorem add_fst (x y : X q) : (x + y).1 = x.1 + y.1 :=\n  rfl\n#align lucas_lehmer.X.add_fst LucasLehmer.X.add_fst\n\n@[simp]\ntheorem add_snd (x y : X q) : (x + y).2 = x.2 + y.2 :=\n  rfl\n#align lucas_lehmer.X.add_snd LucasLehmer.X.add_snd\n\n@[simp]\ntheorem neg_fst (x : X q) : (-x).1 = -x.1 :=\n  rfl\n#align lucas_lehmer.X.neg_fst LucasLehmer.X.neg_fst\n\n@[simp]\ntheorem neg_snd (x : X q) : (-x).2 = -x.2 :=\n  rfl\n#align lucas_lehmer.X.neg_snd LucasLehmer.X.neg_snd\n\ninstance : Mul (X q) where mul x y := (x.1 * y.1 + 3 * x.2 * y.2, x.1 * y.2 + x.2 * y.1)\n\n@[simp]\ntheorem mul_fst (x y : X q) : (x * y).1 = x.1 * y.1 + 3 * x.2 * y.2 :=\n  rfl\n#align lucas_lehmer.X.mul_fst LucasLehmer.X.mul_fst\n\n@[simp]\ntheorem mul_snd (x y : X q) : (x * y).2 = x.1 * y.2 + x.2 * y.1 :=\n  rfl\n#align lucas_lehmer.X.mul_snd LucasLehmer.X.mul_snd\n\ninstance : One (X q) where one := \u27e81, 0\u27e9\n\n@[simp]\ntheorem one_fst : (1 : X q).1 = 1 :=\n  rfl\n#align lucas_lehmer.X.one_fst LucasLehmer.X.one_fst\n\n@[simp]\ntheorem one_snd : (1 : X q).2 = 0 :=\n  rfl\n#align lucas_lehmer.X.one_snd LucasLehmer.X.one_snd\n\n@[simp]\ntheorem bit0_fst (x : X q) : (bit0 x).1 = bit0 x.1 :=\n  rfl\n#align lucas_lehmer.X.bit0_fst LucasLehmer.X.bit0_fst\n\n@[simp]\ntheorem bit0_snd (x : X q) : (bit0 x).2 = bit0 x.2 :=\n  rfl\n#align lucas_lehmer.X.bit0_snd LucasLehmer.X.bit0_snd\n\n@[simp]\ntheorem bit1_fst (x : X q) : (bit1 x).1 = bit1 x.1 :=\n  rfl\n#align lucas_lehmer.X.bit1_fst LucasLehmer.X.bit1_fst\n\n@[simp]\ntheorem bit1_snd (x : X q) : (bit1 x).2 = bit0 x.2 :=\n  by\n  dsimp [bit1]\n  simp\n#align lucas_lehmer.X.bit1_snd LucasLehmer.X.bit1_snd\n\ninstance : Monoid (X q) :=\n  {\n    (inferInstance :\n      Mul\n        (X\n          q)) with\n    mul_assoc := fun x y z => by\n      ext <;>\n        \u00b7 dsimp\n          ring\n    one := \u27e81, 0\u27e9\n    one_mul := fun x => by ext <;> simp\n    mul_one := fun x => by ext <;> simp }\n\ninstance : AddGroupWithOne (X q) :=\n  { X.monoid, X.addCommGroup _ with\n    natCast := fun n => \u27e8n, 0\u27e9\n    natCast_zero := by simp\n    natCast_succ := by simp [Nat.cast, Monoid.one]\n    intCast := fun n => \u27e8n, 0\u27e9\n    intCast_ofNat := fun n => by simp <;> rfl\n    intCast_negSucc := fun n => by ext <;> simp <;> rfl }\n\ntheorem left_distrib (x y z : X q) : x * (y + z) = x * y + x * z := by\n  ext <;>\n    \u00b7 dsimp\n      ring\n#align lucas_lehmer.X.left_distrib LucasLehmer.X.left_distrib\n\ntheorem right_distrib (x y z : X q) : (x + y) * z = x * z + y * z := by\n  ext <;>\n    \u00b7 dsimp\n      ring\n#align lucas_lehmer.X.right_distrib LucasLehmer.X.right_distrib\n\ninstance : Ring (X q) :=\n  { X.addGroupWithOne, (inferInstance : AddCommGroup (X q)),\n    (inferInstance : Monoid (X q)) with\n    left_distrib := left_distrib\n    right_distrib := right_distrib }\n\ninstance : CommRing (X q) :=\n  { (inferInstance : Ring (X q)) with\n    mul_comm := fun x y => by\n      ext <;>\n        \u00b7 dsimp\n          ring }\n\ninstance [Fact (1 < (q : \u2115))] : Nontrivial (X q) :=\n  \u27e8\u27e80, 1, fun h => by\n      injection h with h1 _\n      exact zero_ne_one h1\u27e9\u27e9\n\n@[simp]\ntheorem nat_coe_fst (n : \u2115) : (n : X q).fst = (n : ZMod q) :=\n  rfl\n#align lucas_lehmer.X.nat_coe_fst LucasLehmer.X.nat_coe_fst\n\n@[simp]\ntheorem nat_coe_snd (n : \u2115) : (n : X q).snd = (0 : ZMod q) :=\n  rfl\n#align lucas_lehmer.X.nat_coe_snd LucasLehmer.X.nat_coe_snd\n\n@[simp]\ntheorem int_coe_fst (n : \u2124) : (n : X q).fst = (n : ZMod q) :=\n  rfl\n#align lucas_lehmer.X.int_coe_fst LucasLehmer.X.int_coe_fst\n\n@[simp]\ntheorem int_coe_snd (n : \u2124) : (n : X q).snd = (0 : ZMod q) :=\n  rfl\n#align lucas_lehmer.X.int_coe_snd LucasLehmer.X.int_coe_snd\n\n@[norm_cast]\ntheorem coe_mul (n m : \u2124) : ((n * m : \u2124) : X q) = (n : X q) * (m : X q) := by ext <;> simp <;> ring\n#align lucas_lehmer.X.coe_mul LucasLehmer.X.coe_mul\n\n@[norm_cast]\ntheorem coe_nat (n : \u2115) : ((n : \u2124) : X q) = (n : X q) := by ext <;> simp\n#align lucas_lehmer.X.coe_nat LucasLehmer.X.coe_nat\n\n/-- The cardinality of `X` is `q^2`. -/\ntheorem x_card : Fintype.card (X q) = q ^ 2 :=\n  by\n  dsimp [X]\n  rw [Fintype.card_prod, ZMod.card q]\n  ring\n#align lucas_lehmer.X.X_card LucasLehmer.X.x_card\n\n/-- There are strictly fewer than `q^2` units, since `0` is not a unit. -/\ntheorem units_card (w : 1 < q) : Fintype.card (X q)\u02e3 < q ^ 2 :=\n  by\n  haveI : Fact (1 < (q : \u2115)) := \u27e8w\u27e9\n  convert card_units_lt (X q)\n  rw [X_card]\n#align lucas_lehmer.X.units_card LucasLehmer.X.units_card\n\n/-- We define `\u03c9 = 2 + \u221a3`. -/\ndef \u03c9 : X q :=\n  (2, 1)\n#align lucas_lehmer.X.\u03c9 LucasLehmer.X.\u03c9\n\n/-- We define `\u03c9b = 2 - \u221a3`, which is the inverse of `\u03c9`. -/\ndef \u03c9b : X q :=\n  (2, -1)\n#align lucas_lehmer.X.\u03c9b LucasLehmer.X.\u03c9b\n\ntheorem \u03c9_mul_\u03c9b (q : \u2115+) : (\u03c9 : X q) * \u03c9b = 1 :=\n  by\n  dsimp [\u03c9, \u03c9b]\n  ext <;> simp <;> ring\n#align lucas_lehmer.X.\u03c9_mul_\u03c9b LucasLehmer.X.\u03c9_mul_\u03c9b\n\ntheorem \u03c9b_mul_\u03c9 (q : \u2115+) : (\u03c9b : X q) * \u03c9 = 1 :=\n  by\n  dsimp [\u03c9, \u03c9b]\n  ext <;> simp <;> ring\n#align lucas_lehmer.X.\u03c9b_mul_\u03c9 LucasLehmer.X.\u03c9b_mul_\u03c9\n\n/-- A closed form for the recurrence relation. -/\ntheorem closed_form (i : \u2115) : (s i : X q) = (\u03c9 : X q) ^ 2 ^ i + (\u03c9b : X q) ^ 2 ^ i :=\n  by\n  induction' i with i ih\n  \u00b7 dsimp [s, \u03c9, \u03c9b]\n    ext <;> \u00b7 simp <;> rfl\n  \u00b7\n    calc\n      (s (i + 1) : X q) = (s i ^ 2 - 2 : \u2124) := rfl\n      _ = (s i : X q) ^ 2 - 2 := by push_cast\n      _ = (\u03c9 ^ 2 ^ i + \u03c9b ^ 2 ^ i) ^ 2 - 2 := by rw [ih]\n      _ = (\u03c9 ^ 2 ^ i) ^ 2 + (\u03c9b ^ 2 ^ i) ^ 2 + 2 * (\u03c9b ^ 2 ^ i * \u03c9 ^ 2 ^ i) - 2 := by ring\n      _ = (\u03c9 ^ 2 ^ i) ^ 2 + (\u03c9b ^ 2 ^ i) ^ 2 := by\n        rw [\u2190 mul_pow \u03c9b \u03c9, \u03c9b_mul_\u03c9, one_pow, mul_one, add_sub_cancel]\n      _ = \u03c9 ^ 2 ^ (i + 1) + \u03c9b ^ 2 ^ (i + 1) := by rw [\u2190 pow_mul, \u2190 pow_mul, pow_succ']\n      \n#align lucas_lehmer.X.closed_form LucasLehmer.X.closed_form\n\nend X\n\nopen X\n\n/-!\nHere and below, we introduce `p' = p - 2`, in order to avoid using subtraction in `\u2115`.\n-/\n\n\n/-- If `1 < p`, then `q p`, the smallest prime factor of `mersenne p`, is more than 2. -/\ntheorem two_lt_q (p' : \u2115) : 2 < q (p' + 2) :=\n  by\n  by_contra H\n  simp at H\n  interval_cases; clear H\n  \u00b7 -- If q = 1, we get a contradiction from 2^p = 2\n    dsimp [q] at h\n    injection h with h'\n    clear h\n    simp [mersenne] at h'\n    exact\n      lt_irrefl 2\n        (calc\n          2 \u2264 p' + 2 := Nat.le_add_left _ _\n          _ < 2 ^ (p' + 2) := (Nat.lt_two_pow _)\n          _ = 2 := Nat.pred_inj (Nat.one_le_two_pow _) (by decide) h'\n          )\n  \u00b7 -- If q = 2, we get a contradiction from 2 \u2223 2^p - 1\n    dsimp [q] at h\n    injection h with h'\n    clear h\n    rw [mersenne, PNat.one_coe, Nat.minFac_eq_two_iff, pow_succ] at h'\n    exact Nat.two_not_dvd_two_mul_sub_one (Nat.one_le_two_pow _) h'\n#align lucas_lehmer.two_lt_q LucasLehmer.two_lt_q\n\ntheorem \u03c9_pow_formula (p' : \u2115) (h : lucasLehmerResidue (p' + 2) = 0) :\n    \u2203 k : \u2124,\n      (\u03c9 : X (q (p' + 2))) ^ 2 ^ (p' + 1) =\n        k * mersenne (p' + 2) * (\u03c9 : X (q (p' + 2))) ^ 2 ^ p' - 1 :=\n  by\n  dsimp [lucas_lehmer_residue] at h\n  rw [s_zmod_eq_s p'] at h\n  simp [ZMod.int_cast_zmod_eq_zero_iff_dvd] at h\n  cases' h with k h\n  use k\n  replace h := congr_arg (fun n : \u2124 => (n : X (q (p' + 2)))) h\n  -- coercion from \u2124 to X q\n  dsimp at h\n  rw [closed_form] at h\n  replace h := congr_arg (fun x => \u03c9 ^ 2 ^ p' * x) h\n  dsimp at h\n  have t : 2 ^ p' + 2 ^ p' = 2 ^ (p' + 1) := by ring\n  rw [mul_add, \u2190 pow_add \u03c9, t, \u2190 mul_pow \u03c9 \u03c9b (2 ^ p'), \u03c9_mul_\u03c9b, one_pow] at h\n  rw [mul_comm, coe_mul] at h\n  rw [mul_comm _ (k : X (q (p' + 2)))] at h\n  replace h := eq_sub_of_add_eq h\n  have : 1 \u2264 2 ^ (p' + 2) := Nat.one_le_pow _ _ (by decide)\n  exact_mod_cast h\n#align lucas_lehmer.\u03c9_pow_formula LucasLehmer.\u03c9_pow_formula\n\n/-- `q` is the minimum factor of `mersenne p`, so `M p = 0` in `X q`. -/\ntheorem mersenne_coe_x (p : \u2115) : (mersenne p : X (q p)) = 0 :=\n  by\n  ext <;> simp [mersenne, q, ZMod.nat_cast_zmod_eq_zero_iff_dvd, -pow_pos]\n  apply Nat.minFac_dvd\n#align lucas_lehmer.mersenne_coe_X LucasLehmer.mersenne_coe_x\n\ntheorem \u03c9_pow_eq_neg_one (p' : \u2115) (h : lucasLehmerResidue (p' + 2) = 0) :\n    (\u03c9 : X (q (p' + 2))) ^ 2 ^ (p' + 1) = -1 :=\n  by\n  cases' \u03c9_pow_formula p' h with k w\n  rw [mersenne_coe_X] at w\n  simpa using w\n#align lucas_lehmer.\u03c9_pow_eq_neg_one LucasLehmer.\u03c9_pow_eq_neg_one\n\ntheorem \u03c9_pow_eq_one (p' : \u2115) (h : lucasLehmerResidue (p' + 2) = 0) :\n    (\u03c9 : X (q (p' + 2))) ^ 2 ^ (p' + 2) = 1 :=\n  calc\n    (\u03c9 : X (q (p' + 2))) ^ 2 ^ (p' + 2) = (\u03c9 ^ 2 ^ (p' + 1)) ^ 2 := by rw [\u2190 pow_mul, \u2190 pow_succ']\n    _ = (-1) ^ 2 := by rw [\u03c9_pow_eq_neg_one p' h]\n    _ = 1 := by simp\n    \n#align lucas_lehmer.\u03c9_pow_eq_one LucasLehmer.\u03c9_pow_eq_one\n\n/-- `\u03c9` as an element of the group of units. -/\ndef \u03c9Unit (p : \u2115) : Units (X (q p)) where\n  val := \u03c9\n  inv := \u03c9b\n  val_inv := by simp [\u03c9_mul_\u03c9b]\n  inv_val := by simp [\u03c9b_mul_\u03c9]\n#align lucas_lehmer.\u03c9_unit LucasLehmer.\u03c9Unit\n\n@[simp]\ntheorem \u03c9Unit_coe (p : \u2115) : (\u03c9Unit p : X (q p)) = \u03c9 :=\n  rfl\n#align lucas_lehmer.\u03c9_unit_coe LucasLehmer.\u03c9Unit_coe\n\n/-- The order of `\u03c9` in the unit group is exactly `2^p`. -/\ntheorem order_\u03c9 (p' : \u2115) (h : lucasLehmerResidue (p' + 2) = 0) :\n    orderOf (\u03c9Unit (p' + 2)) = 2 ^ (p' + 2) :=\n  by\n  apply Nat.eq_prime_pow_of_dvd_least_prime_pow\n  -- the order of \u03c9 divides 2^p\n  \u00b7 exact Nat.prime_two\n  \u00b7 intro o\n    have \u03c9_pow := orderOf_dvd_iff_pow_eq_one.1 o\n    replace \u03c9_pow :=\n      congr_arg (Units.coeHom (X (q (p' + 2))) : Units (X (q (p' + 2))) \u2192 X (q (p' + 2))) \u03c9_pow\n    simp at \u03c9_pow\n    have h : (1 : ZMod (q (p' + 2))) = -1 :=\n      congr_arg Prod.fst (\u03c9_pow.symm.trans (\u03c9_pow_eq_neg_one p' h))\n    haveI : Fact (2 < (q (p' + 2) : \u2115)) := \u27e8two_lt_q _\u27e9\n    apply ZMod.neg_one_ne_one h.symm\n  \u00b7 apply orderOf_dvd_iff_pow_eq_one.2\n    apply Units.ext\n    push_cast\n    exact \u03c9_pow_eq_one p' h\n#align lucas_lehmer.order_\u03c9 LucasLehmer.order_\u03c9\n\ntheorem order_ineq (p' : \u2115) (h : lucasLehmerResidue (p' + 2) = 0) :\n    2 ^ (p' + 2) < (q (p' + 2) : \u2115) ^ 2 :=\n  calc\n    2 ^ (p' + 2) = orderOf (\u03c9Unit (p' + 2)) := (order_\u03c9 p' h).symm\n    _ \u2264 Fintype.card (X _)\u02e3 := orderOf_le_card_univ\n    _ < (q (p' + 2) : \u2115) ^ 2 := units_card (Nat.lt_of_succ_lt (two_lt_q _))\n    \n#align lucas_lehmer.order_ineq LucasLehmer.order_ineq\n\nend LucasLehmer\n\nexport LucasLehmer (LucasLehmerTest lucasLehmerResidue)\n\nopen LucasLehmer\n\ntheorem lucas_lehmer_sufficiency (p : \u2115) (w : 1 < p) : LucasLehmerTest p \u2192 (mersenne p).Prime :=\n  by\n  let p' := p - 2\n  have z : p = p' + 2 := (tsub_eq_iff_eq_add_of_le w.nat_succ_le).mp rfl\n  have w : 1 < p' + 2 := Nat.lt_of_sub_eq_succ rfl\n  contrapose\n  intro a t\n  rw [z] at a\n  rw [z] at t\n  have h\u2081 := order_ineq p' t\n  have h\u2082 := Nat.minFac_sq_le_self (mersenne_pos (Nat.lt_of_succ_lt w)) a\n  have h := lt_of_lt_of_le h\u2081 h\u2082\n  exact not_lt_of_ge (Nat.sub_le _ _) h\n#align lucas_lehmer_sufficiency lucas_lehmer_sufficiency\n\n-- Here we calculate the residue, very inefficiently, using `dec_trivial`. We can do much better.\nexample : (mersenne 5).Prime :=\n  lucas_lehmer_sufficiency 5 (by norm_num) (by decide)\n\n-- Next we use `norm_num` to calculate each `s p i`.\nnamespace LucasLehmer\n\nopen Tactic\n\ntheorem sMod_succ {p a i b c} (h1 : (2 ^ p - 1 : \u2124) = a) (h2 : sMod p i = b)\n    (h3 : (b * b - 2) % a = c) : sMod p (i + 1) = c :=\n  by\n  dsimp [s_mod, mersenne]\n  rw [h1, h2, sq, h3]\n#align lucas_lehmer.s_mod_succ LucasLehmer.sMod_succ\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/\n/-- Given a goal of the form `lucas_lehmer_test p`,\nattempt to do the calculation using `norm_num` to certify each step.\n-/\nunsafe def run_test : tactic Unit := do\n  let q(LucasLehmerTest $(p)) \u2190 target\n  sorry\n  sorry\n  let p \u2190 eval_expr \u2115 p\n  let-- Calculate the candidate Mersenne prime\n  M : \u2124 := 2 ^ p - 1\n  let t \u2190 to_expr ``(2 ^ $(q(p)) - 1 = $(q(M)))\n  let v \u2190 to_expr ``((by norm_num : 2 ^ $(q(p)) - 1 = $(q(M))))\n  let w \u2190 assertv `w t v\n  let t\n    \u2190-- base case\n        to_expr\n        ``(sMod $(q(p)) 0 = 4)\n  let v \u2190 to_expr ``((by norm_num [LucasLehmer.sMod] : sMod $(q(p)) 0 = 4))\n  let h \u2190 assertv `h t v\n  -- step case, repeated p-2 times\n      iterate_exactly\n      (p - 2) sorry\n  let h\n    \u2190-- now close the goal\n        get_local\n        `h\n  exact h\n#align lucas_lehmer.run_test lucas_lehmer.run_test\n\nend LucasLehmer\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic lucas_lehmer.run_test -/\n/-- We verify that the tactic works to prove `127.prime`. -/\nexample : (mersenne 7).Prime :=\n  lucas_lehmer_sufficiency _ (by norm_num)\n    (by\n      run_tac\n        lucas_lehmer.run_test)\n\n/-!\nThis implementation works successfully to prove `(2^127 - 1).prime`,\nand all the Mersenne primes up to this point appear in [archive/examples/mersenne_primes.lean].\n\n`(2^127 - 1).prime` takes about 5 minutes to run (depending on your CPU!),\nand unfortunately the next Mersenne prime `(2^521 - 1)`,\nwhich was the first \"computer era\" prime,\nis out of reach with the current implementation.\n\nThere's still low hanging fruit available to do faster computations\nbased on the formula\n```\nn \u2261 (n % 2^p) + (n / 2^p) [MOD 2^p - 1]\n```\nand the fact that `% 2^p` and `/ 2^p` can be very efficient on the binary representation.\nSomeone should do this, too!\n-/\n\n\ntheorem modEq_mersenne (n k : \u2115) : k \u2261 k / 2 ^ n + k % 2 ^ n [MOD 2 ^ n - 1] :=\n  by\n  -- See https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/help.20finding.20a.20lemma/near/177698446\n  conv in k => rw [\u2190 Nat.div_add_mod k (2 ^ n)]\n  refine' Nat.ModEq.add_right _ _\n  conv =>\n    congr\n    skip\n    skip\n    rw [\u2190 one_mul (k / 2 ^ n)]\n  exact (Nat.modEq_sub <| Nat.succ_le_of_lt <| pow_pos zero_lt_two _).mul_right _\n#align modeq_mersenne modEq_mersenne\n\n-- It's hard to know what the limiting factor for large Mersenne primes would be.\n-- In the purely computational world, I think it's the squaring operation in `s`.\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/LucasLehmer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7103776314075694}}
{"text": "import data.list.basic\n\nopen list\n\nvariables {\u03b1 : Type*} (x y z : \u03b1) (xs ys zs : list \u03b1)\n\ndef mk_symm (xs : list \u03b1) := xs ++ reverse xs\n\ntheorem reverse_mk_symm (xs : list \u03b1) :\n  reverse (mk_symm xs) = mk_symm xs :=\nby simp [mk_symm]\n\nsection\nlocal attribute [simp] reverse_mk_symm\n\nexample (xs ys : list \u2115) :\n  reverse (xs ++ mk_symm ys) = mk_symm ys ++ reverse xs :=\nby simp\n\nexample (xs ys : list \u2115) (p : list \u2115 \u2192 Prop)\n    (h : p (reverse (xs ++ (mk_symm ys)))) :\n  p (mk_symm ys ++ reverse xs) :=\nby simp at h; assumption\n\nend\n\nrun_cmd mk_simp_attr `my_simps\n\nattribute [my_simps] reverse_mk_symm\n\nexample (xs ys : list \u2115) :\n  reverse (xs ++ mk_symm ys) = mk_symm ys ++ reverse xs :=\nby {simp with my_simps}\n\nexample (xs ys : list \u2115) (p : list \u2115 \u2192 Prop)\n  (h : p (reverse (xs ++ (mk_symm ys)))) :\n    p (mk_symm ys ++ reverse xs) :=\nby simp with my_simps at h; assumption\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/05-Tactics/example-5.7-10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995028, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.710377631129354}}
{"text": "/-\nCopyright (c) 2018 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport tactic.basic\nimport data.nat.basic\nimport algebra.ordered_ring\n\n/- Turn off trace messages so they don't pollute the test build: -/\nset_option trace.silence_library_search true\n\nexample {a b : \u2115} (h : b > 0) (w : a \u2265 1) : b \u2264 a * b :=\nby library_search -- exact (le_mul_iff_one_le_left h).mpr w\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/test/library_search/ordered_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045996818987, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7103776292978042}}
{"text": "/-\nThis file defines the boolean XOR constraint on n variables.\n\nAuthors: Cayden Codel, Marijn Heule, Jeremy Avigad\nCarnegie Mellon University\n-/\n\nimport basic\nimport cnf.literal cnf.assignment cnf.clause cnf.cnf cnf.encoding\nimport parity.explode\nimport data.list.basic data.finset.basic\n\nuniverse u\n\nopen clause\nopen nat list\nopen encoding\n\n-- Represents the type of the variable stored in the literal\nvariables {V : Type*} [decidable_eq V]\n\n/- An n-variable XOR constraint is a map from a list of bools to an output bool -/\ndef parity : constraint := \u03bb l, (l.foldr bxor ff)\ndef parityF : constraint := \u03bb l, (l.foldr bxor tt)\n\nnamespace parity\n\n/-! # eval -/\nsection eval\n\nvariables (\u03c4 : assignment V) (l l\u2081 l\u2082 : list (literal V)) (lit : literal V)\n\n@[simp] theorem eval_nil : parity.eval \u03c4 [] = ff := rfl\n\n@[simp] theorem eval_singleton : parity.eval \u03c4 [lit] = lit.eval \u03c4 :=\nby simp only [constraint.eval, parity, map, bool.bxor_ff_right, foldr]\n\ntheorem eval_cons : parity.eval \u03c4 (lit :: l) = bxor (lit.eval \u03c4) (parity.eval \u03c4 l) :=\nby simp only [constraint.eval, parity, foldr, foldr_map]\n\ntheorem eval_append : \n  parity.eval \u03c4 (l\u2081 ++ l\u2082) = bxor (parity.eval \u03c4 l\u2081) (parity.eval \u03c4 l\u2082) :=\nbegin\n  induction l\u2081 with l ls ih,\n  { simp only [bool.bxor_ff_left, eval_nil, nil_append] },\n  { simp only [eval_cons, ih, cons_append, bool.bxor_assoc] }\nend\n\n/- Evaluates to true if an odd number of literals evaluates to true -/\ntheorem eval_eq_bodd_count_tt : parity.eval \u03c4 l = bodd (clause.count_tt \u03c4 l) :=\nbegin\n  induction l with l ls ih,\n  { simp only [bodd_zero, eval_nil, count_tt_nil] },\n  { cases h : (l.eval \u03c4); { simp [parity.eval_cons, count_tt_cons, h, ih] } }\nend\n\ntheorem eval_eq_of_perm {l\u2081 l\u2082 : list (literal V)} : l\u2081 ~ l\u2082 \u2192 \n  \u2200 (\u03c4 : assignment V), parity.eval \u03c4 l\u2081 = parity.eval \u03c4 l\u2082 :=\nbegin\n  intros hp \u03c4,\n  induction hp with x l\u2082 l\u2082' p IH  x y l\u2082  l\u2082 m\u2082 r\u2082 p\u2081 p\u2082 IH\u2081 IH\u2082,\n  { refl },\n  { simp [eval_cons, IH] },\n  { simp [eval_cons, \u2190 bool.bxor_assoc],\n    rw bool.bxor_comm (literal.eval \u03c4 y) (literal.eval \u03c4 x) },\n  { exact eq.trans IH\u2081 IH\u2082 }\nend\n\nopen assignment\n\ntheorem eval_eq_of_agree_on [decidable_eq V] {\u03c4\u2081 \u03c4\u2082 : assignment V} {l : list (literal V)} :\n  (agree_on \u03c4\u2081 \u03c4\u2082 (clause.vars l)) \u2192 parity.eval \u03c4\u2081 l = parity.eval \u03c4\u2082 l :=\nbegin\n  induction l with l ls ih,\n  { simp only [agree_on_nil, parity.eval_nil, forall_true_left, clause.vars_nil] },\n  { intro h,\n    simp only [parity.eval_cons],\n    rw eval_eq_of_agree_on_of_var_mem h (mem_vars_of_mem (mem_cons_self l ls)),\n    rw ih (agree_on_subset (vars_subset_of_vars_cons l ls) h) }\nend\n\nend eval\n\nend parity", "meta": {"author": "ccodel", "repo": "verified-encodings", "sha": "ee22a6a04ee56cc568f91fbee5a70d39e5e261f8", "save_path": "github-repos/lean/ccodel-verified-encodings", "path": "github-repos/lean/ccodel-verified-encodings/verified-encodings-ee22a6a04ee56cc568f91fbee5a70d39e5e261f8/src/parity/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7103776256347044}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module algebra.big_operators.option\n! leanprover-community/mathlib commit 008205aa645b3f194c1da47025c5f110c8406eab\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Finset.Option\n\n/-!\n# Lemmas about products and sums over finite sets in `Option \u03b1`\n\nIn this file we prove formulas for products and sums over `Finset.insertNone s` and\n`Finset.eraseNone s`.\n-/\n\nopen BigOperators\n\nopen Function\n\nnamespace Finset\n\nvariable {\u03b1 M : Type _} [CommMonoid M]\n\n@[to_additive (attr := simp)]\ntheorem prod_insertNone (f : Option \u03b1 \u2192 M) (s : Finset \u03b1) :\n    (\u220f x in insertNone s, f x) = f none * \u220f x in s, f (some x) := by simp [insertNone]\n#align finset.prod_insert_none Finset.prod_insertNone\n#align finset.sum_insert_none Finset.sum_insertNone\n\n@[to_additive]\ntheorem prod_eraseNone (f : \u03b1 \u2192 M) (s : Finset (Option \u03b1)) :\n    (\u220f x in eraseNone s, f x) = \u220f x in s, Option.elim' 1 f x := by\n  classical calc\n      (\u220f x in eraseNone s, f x) = \u220f x in (eraseNone s).map Embedding.some, Option.elim' 1 f x :=\n        (prod_map (eraseNone s) Embedding.some <| Option.elim' 1 f).symm\n      _ = \u220f x in s.erase none, Option.elim' 1 f x := by rw [map_some_eraseNone]\n      _ = \u220f x in s, Option.elim' 1 f x := prod_erase _ rfl\n#align finset.prod_erase_none Finset.prod_eraseNone\n#align finset.sum_erase_none Finset.sum_eraseNone\n\nend Finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/BigOperators/Option.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7103776155263516}}
{"text": "-- Pij means pigeon i is in pigeonhole j\nvariables P11 P12 P21 P22 P31 P32 : Prop\n\n/- I have to prove that: if there are three pigeons and two pigeonholes\n(and each pigeon are in a pigeonhole), there will be at least two pigeons\nin the same pigeonhole:\n(P11 \u2228 P12) \u2227 (P21 \u2228 P22) \u2227 (P31 \u2228 P32) \u2192 \n((P11 \u2227 P21) \u2228 (P11 \u2227 P31) \u2228 (P21 \u2227 P31)) \u2228\n((P12 \u2227 P22) \u2228 (P12 \u2227 P32) \u2228 (P22 \u2227 P32))\nThe whole exercise consists in dealing with or eliminations of the three or\nstatements in a chain. Example: I will assume P11, and I will have to deal with\nP21 \u2228 P22. But later I will assume P12, and I will also have to deal with P21 \u2228 P22.\nAnd for each P21 and P22 etc.-/\n\nlemma fifth_or_elim {P11 P12 P21 P22 P31 P32 : Prop}\n(h3 : P12) (h5 : P21) (h6 : P31 \u2228 P32) :\n((P11 \u2227 P21) \u2228 (P11 \u2227 P31) \u2228 (P21 \u2227 P31)) \u2228\n((P12 \u2227 P22) \u2228 (P12 \u2227 P32) \u2228 (P22 \u2227 P32)) :=\n    or.elim h6\n        (assume h7 : P31,\n        or.inl (or.inr (or.inr (and.intro h5 h7))))\n        (assume h7 : P32,\n        or.inr (or.inr (or.inl (and.intro h3 h7))))\n\nlemma fourth_or_elim {P11 P12 P21 P22 P31 P32 : Prop}\n(h1 : (P11 \u2228 P12) \u2227 (P21 \u2228 P22) \u2227 (P31 \u2228 P32)) (h3 : P12) (h4 : P21 \u2228 P22) :\n((P11 \u2227 P21) \u2228 (P11 \u2227 P31) \u2228 (P21 \u2227 P31)) \u2228\n((P12 \u2227 P22) \u2228 (P12 \u2227 P32) \u2228 (P22 \u2227 P32)) :=\n    or.elim h4\n    (assume h5 : P21,\n    have h6 : P31 \u2228 P32, from and.right (and.right h1),\n    fifth_or_elim h3 h5 h6)\n    (assume h5 : P22,\n    or.inr (or.inl (and.intro h3 h5)))\n\nlemma third_or_elim {P11 P12 P21 P22 P31 P32 : Prop}\n(h3 : P11) (h5 : P22) (h6 : P31 \u2228 P32) :\n((P11 \u2227 P21) \u2228 (P11 \u2227 P31) \u2228 (P21 \u2227 P31)) \u2228\n((P12 \u2227 P22) \u2228 (P12 \u2227 P32) \u2228 (P22 \u2227 P32)) :=\n    or.elim h6\n        (assume h7 : P31,\n        or.inl (or.inr (or.inl (and.intro h3 h7))))\n        (assume h7 : P32,\n        or.inr (or.inr (or.inr (and.intro h5 h7))))\n\nlemma second_or_elim {P11 P12 P21 P22 P31 P32 : Prop}\n(h1 : (P11 \u2228 P12) \u2227 (P21 \u2228 P22) \u2227 (P31 \u2228 P32)) (h3 : P11) (h4 : P21 \u2228 P22) :\n((P11 \u2227 P21) \u2228 (P11 \u2227 P31) \u2228 (P21 \u2227 P31)) \u2228\n((P12 \u2227 P22) \u2228 (P12 \u2227 P32) \u2228 (P22 \u2227 P32)) :=\n    or.elim h4\n        (assume h5 : P21,\n        have h6 : P31 \u2228 P32, from and.right (and.right h1),\n        or.inl (or.inl (and.intro h3 h5)))\n        (assume h5 : P22,\n        have h6 : P31 \u2228 P32, from and.right (and.right h1),\n        third_or_elim h3 h5 h6)\n\nlemma first_or_elim {P11 P12 P21 P22 P31 P32 : Prop}\n(h1 : (P11 \u2228 P12) \u2227 (P21 \u2228 P22) \u2227 (P31 \u2228 P32)) (h2 : P11 \u2228 P12) :\n((P11 \u2227 P21) \u2228 (P11 \u2227 P31) \u2228 (P21 \u2227 P31)) \u2228\n((P12 \u2227 P22) \u2228 (P12 \u2227 P32) \u2228 (P22 \u2227 P32)) :=\n    or.elim h2\n        (assume h3 : P11,\n        have h4 : P21 \u2228 P22, from and.left (and.right h1),\n        second_or_elim h1 h3 h4)\n        (assume h3 : P12,\n        have h4 : P21 \u2228 P22, from and.left (and.right h1),\n        fourth_or_elim h1 h3 h4)\n\ntheorem PHP3 : (P11 \u2228 P12) \u2227 (P21 \u2228 P22) \u2227 (P31 \u2228 P32) \u2192 \n((P11 \u2227 P21) \u2228 (P11 \u2227 P31) \u2228 (P21 \u2227 P31)) \u2228\n((P12 \u2227 P22) \u2228 (P12 \u2227 P32) \u2228 (P22 \u2227 P32)) :=\n    assume h1 : (P11 \u2228 P12) \u2227 (P21 \u2228 P22) \u2227 (P31 \u2228 P32),\n    have h2 : P11 \u2228 P12, from and.left h1,\n    first_or_elim h1 h2\n", "meta": {"author": "lucasresck", "repo": "Discrete-Mathematics", "sha": "0a08081c5f393e5765259d3f1253c3a6dd043dac", "save_path": "github-repos/lean/lucasresck-Discrete-Mathematics", "path": "github-repos/lean/lucasresck-Discrete-Mathematics/Discrete-Mathematics-0a08081c5f393e5765259d3f1253c3a6dd043dac/Lists of exercises/List 3/PHP-LucasDomingues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7103666076542765}}
{"text": "/-\nCopyright (c) 2019 Minchao Wu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Minchao Wu, Chris Hughes, Mantas Bak\u0161ys\n\n! This file was ported from Lean 3 source module data.list.min_max\n! leanprover-community/mathlib commit 6d0adfa76594f304b4650d098273d4366edeb61b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.List.Basic\n\n/-!\n# Minimum and maximum of lists\n\n## Main definitions\n\nThe main definitions are `argmax`, `argmin`, `minimum` and `maximum` for lists.\n\n`argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such that\n  `f a = f b`, it returns whichever of `a` or `b` comes first in the list.\n  `argmax f []` = none`\n\n`minimum l` returns an `WithTop \u03b1`, the smallest element of `l` for nonempty lists, and `\u22a4` for\n`[]`\n-/\n\n\nnamespace List\n\nvariable {\u03b1 \u03b2 : Type _}\n\nsection ArgAux\n\nvariable (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [DecidableRel r] {l : List \u03b1} {o : Option \u03b1} {a m : \u03b1}\n\n/-- Auxiliary definition for `argmax` and `argmin`. -/\ndef argAux (a : Option \u03b1) (b : \u03b1) : Option \u03b1 :=\n  Option.casesOn a (some b) fun c => if r b c then some b else some c\n#align list.arg_aux List.argAux\n\n@[simp]\ntheorem foldl_argAux_eq_none : l.foldl (argAux r) o = none \u2194 l = [] \u2227 o = none :=\n  List.reverseRecOn l (by simp) fun tl hd => by\n    simp [argAux]; cases foldl (argAux r) o tl <;> simp; try split_ifs <;> simp\n#align list.foldl_arg_aux_eq_none List.foldl_argAux_eq_none\n\nprivate theorem foldl_argAux_mem (l) : \u2200 a m : \u03b1, m \u2208 foldl (argAux r) (some a) l \u2192 m \u2208 a :: l :=\n  List.reverseRecOn l (by simp [eq_comm])\n    (by\n      intro tl hd ih a m\n      simp only [foldl_append, foldl_cons, foldl_nil, argAux]\n      cases hf : foldl (argAux r) (some a) tl\n      \u00b7 simp (config := { contextual := true })\n      \u00b7 dsimp only\n        split_ifs\n        \u00b7 simp (config := { contextual := true })\n        \u00b7 -- `finish [ih _ _ hf]` closes this goal\n          simp only [List.mem_cons] at ih\n          rcases ih _ _ hf with rfl | H\n          \u00b7 simp (config := { contextual := true }) only [Option.mem_def, Option.some.injEq,\n              find?, eq_comm, mem_cons, mem_append, mem_singleton, true_or, implies_true]\n          \u00b7 simp (config := { contextual := true }) [@eq_comm _ _ m, H])\n\n@[simp]\ntheorem argAux_self (hr\u2080 : Irreflexive r) (a : \u03b1) : argAux r (some a) a = a :=\n  if_neg <| hr\u2080 _\n#align list.arg_aux_self List.argAux_self\n\ntheorem not_of_mem_foldl_argAux (hr\u2080 : Irreflexive r) (hr\u2081 : Transitive r) :\n    \u2200 {a m : \u03b1} {o : Option \u03b1}, a \u2208 l \u2192 m \u2208 foldl (argAux r) o l \u2192 \u00acr a m := by\n  induction' l using List.reverseRecOn with tl a ih\n  \u00b7 simp\n  intro b m o hb ho\n  rw [foldl_append, foldl_cons, foldl_nil, argAux] at ho\n  cases' hf : foldl (argAux r) o tl with c\n  \u00b7 rw [hf] at ho\n    rw [foldl_argAux_eq_none] at hf\n    simp_all [hf.1, hf.2, hr\u2080 _]\n  rw [hf, Option.mem_def] at ho\n  dsimp only at ho\n  split_ifs at ho with hac <;> cases' mem_append.1 hb with h h <;>\n    injection ho with ho <;> subst ho\n  \u00b7 exact fun hba => ih h hf (hr\u2081 hba hac)\n  \u00b7 simp_all [hr\u2080 _]\n  \u00b7 exact ih h hf\n  \u00b7 simp_all\n#align list.not_of_mem_foldl_arg_aux List.not_of_mem_foldl_argAux\n\nend ArgAux\n\nsection Preorder\n\nvariable [Preorder \u03b2] [@DecidableRel \u03b2 (\u00b7 < \u00b7)] {f : \u03b1 \u2192 \u03b2} {l : List \u03b1} {o : Option \u03b1} {a m : \u03b1}\n\n/-- `argmax f l` returns `some a`, where `f a` is maximal among the elements of `l`, in the sense\nthat there is no `b \u2208 l` with `f a < f b`. If `a`, `b` are such that `f a = f b`, it returns\nwhichever of `a` or `b` comes first in the list. `argmax f []` = none`. -/\ndef argmax (f : \u03b1 \u2192 \u03b2) (l : List \u03b1) : Option \u03b1 :=\n  l.foldl (argAux fun b c => f c < f b) none\n#align list.argmax List.argmax\n\n/-- `argmin f l` returns `some a`, where `f a` is minimal among the elements of `l`, in the sense\nthat there is no `b \u2208 l` with `f b < f a`. If `a`, `b` are such that `f a = f b`, it returns\nwhichever of `a` or `b` comes first in the list. `argmin f []` = none`. -/\ndef argmin (f : \u03b1 \u2192 \u03b2) (l : List \u03b1) :=\n  l.foldl (argAux fun b c => f b < f c) none\n#align list.argmin List.argmin\n\n@[simp]\ntheorem argmax_nil (f : \u03b1 \u2192 \u03b2) : argmax f [] = none :=\n  rfl\n#align list.argmax_nil List.argmax_nil\n\n@[simp]\ntheorem argmin_nil (f : \u03b1 \u2192 \u03b2) : argmin f [] = none :=\n  rfl\n#align list.argmin_nil List.argmin_nil\n\n@[simp]\ntheorem argmax_singleton {f : \u03b1 \u2192 \u03b2} {a : \u03b1} : argmax f [a] = a :=\n  rfl\n#align list.argmax_singleton List.argmax_singleton\n\n@[simp]\ntheorem argmin_singleton {f : \u03b1 \u2192 \u03b2} {a : \u03b1} : argmin f [a] = a :=\n  rfl\n#align list.argmin_singleton List.argmin_singleton\n\ntheorem not_lt_of_mem_argmax : a \u2208 l \u2192 m \u2208 argmax f l \u2192 \u00acf m < f a :=\n  not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h)\n    (fun _ _ z hxy hyz => lt_trans (a := f z) hyz hxy)\n#align list.not_lt_of_mem_argmax List.not_lt_of_mem_argmax\n\ntheorem not_lt_of_mem_argmin : a \u2208 l \u2192 m \u2208 argmin f l \u2192 \u00acf a < f m :=\n  not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h)\n    (fun x _ _ hxy hyz => lt_trans (a := f x) hxy hyz)\n#align list.not_lt_of_mem_argmin List.not_lt_of_mem_argmin\n\ntheorem argmax_concat (f : \u03b1 \u2192 \u03b2) (a : \u03b1) (l : List \u03b1) :\n    argmax f (l ++ [a]) =\n      Option.casesOn (argmax f l) (some a) fun c => if f c < f a then some a else some c :=\n  by rw [argmax, argmax]; simp [argAux]\n#align list.argmax_concat List.argmax_concat\n\ntheorem argmin_concat (f : \u03b1 \u2192 \u03b2) (a : \u03b1) (l : List \u03b1) :\n    argmin f (l ++ [a]) =\n      Option.casesOn (argmin f l) (some a) fun c => if f a < f c then some a else some c :=\n  @argmax_concat _ \u03b2\u1d52\u1d48 _ _ _ _ _\n#align list.argmin_concat List.argmin_concat\n\ntheorem argmax_mem : \u2200 {l : List \u03b1} {m : \u03b1}, m \u2208 argmax f l \u2192 m \u2208 l\n  | [], m => by simp\n  | hd :: tl, m => by simpa [argmax, argAux] using foldl_argAux_mem _ tl hd m\n#align list.argmax_mem List.argmax_mem\n\ntheorem argmin_mem : \u2200 {l : List \u03b1} {m : \u03b1}, m \u2208 argmin f l \u2192 m \u2208 l :=\n  @argmax_mem _ \u03b2\u1d52\u1d48 _ _ _\n#align list.argmin_mem List.argmin_mem\n\n@[simp]\ntheorem argmax_eq_none : l.argmax f = none \u2194 l = [] := by simp [argmax]\n#align list.argmax_eq_none List.argmax_eq_none\n\n@[simp]\ntheorem argmin_eq_none : l.argmin f = none \u2194 l = [] :=\n  @argmax_eq_none _ \u03b2\u1d52\u1d48 _ _ _ _\n#align list.argmin_eq_none List.argmin_eq_none\n\nend Preorder\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : List \u03b1} {o : Option \u03b1} {a m : \u03b1}\n\ntheorem le_of_mem_argmax : a \u2208 l \u2192 m \u2208 argmax f l \u2192 f a \u2264 f m := fun ha hm =>\n  le_of_not_lt <| not_lt_of_mem_argmax ha hm\n#align list.le_of_mem_argmax List.le_of_mem_argmax\n\ntheorem le_of_mem_argmin : a \u2208 l \u2192 m \u2208 argmin f l \u2192 f m \u2264 f a :=\n  @le_of_mem_argmax _ \u03b2\u1d52\u1d48 _ _ _ _ _\n#align list.le_of_mem_argmin List.le_of_mem_argmin\n\ntheorem argmax_cons (f : \u03b1 \u2192 \u03b2) (a : \u03b1) (l : List \u03b1) :\n    argmax f (a :: l) =\n      Option.casesOn (argmax f l) (some a) fun c => if f a < f c then some c else some a :=\n  List.reverseRecOn l rfl fun hd tl ih => by\n    rw [\u2190 cons_append, argmax_concat, ih, argmax_concat]\n    cases' h : argmax f hd with m\n    \u00b7 simp [h]\n    dsimp\n    rw [\u2190 apply_ite, \u2190 apply_ite]\n    dsimp\n    split_ifs <;> try rfl\n    \u00b7 exact absurd (lt_trans \u2039f a < f m\u203a \u2039_\u203a) \u2039_\u203a\n    \u00b7 cases (\u2039f a < f tl\u203a.lt_or_lt _).elim \u2039_\u203a \u2039_\u203a\n#align list.argmax_cons List.argmax_cons\n\ntheorem argmin_cons (f : \u03b1 \u2192 \u03b2) (a : \u03b1) (l : List \u03b1) :\n    argmin f (a :: l) =\n      Option.casesOn (argmin f l) (some a) fun c => if f c < f a then some c else some a :=\n  @argmax_cons \u03b1 \u03b2\u1d52\u1d48 _ _ _ _\n#align list.argmin_cons List.argmin_cons\n\nvariable [DecidableEq \u03b1]\n\ntheorem index_of_argmax :\n    \u2200 {l : List \u03b1} {m : \u03b1}, m \u2208 argmax f l \u2192 \u2200 {a}, a \u2208 l \u2192 f m \u2264 f a \u2192 l.indexOf m \u2264 l.indexOf a\n  | [], m, _, _, _, _ => by simp\n  | hd :: tl, m, hm, a, ha, ham => by\n    simp only [indexOf_cons, argmax_cons, Option.mem_def] at hm\u22a2\n    cases h : argmax f tl\n    \u00b7 rw [h] at hm\n      simp_all\n    rw [h] at hm\n    dsimp only at hm\n    obtain ha | ha := ha <;> split_ifs at hm <;> injection hm with hm <;> subst hm\n    \u00b7 cases not_le_of_lt \u2039_\u203a \u2039_\u203a\n    \u00b7 rw [if_pos rfl]\n    . rw [if_neg, if_neg]\n      exact Nat.succ_le_succ (index_of_argmax h (by assumption) ham)\n      \u00b7 exact ne_of_apply_ne f (lt_of_lt_of_le \u2039_\u203a \u2039_\u203a).ne'\n      \u00b7 exact ne_of_apply_ne _ \u2039f hd < f _\u203a.ne'\n    . rw [if_pos rfl]\n      exact Nat.zero_le _\n#align list.index_of_argmax List.index_of_argmax\n\ntheorem index_of_argmin :\n    \u2200 {l : List \u03b1} {m : \u03b1}, m \u2208 argmin f l \u2192 \u2200 {a}, a \u2208 l \u2192 f a \u2264 f m \u2192 l.indexOf m \u2264 l.indexOf a :=\n  @index_of_argmax _ \u03b2\u1d52\u1d48 _ _ _\n#align list.index_of_argmin List.index_of_argmin\n\ntheorem mem_argmax_iff :\n    m \u2208 argmax f l \u2194\n      m \u2208 l \u2227 (\u2200 a \u2208 l, f a \u2264 f m) \u2227 \u2200 a \u2208 l, f m \u2264 f a \u2192 l.indexOf m \u2264 l.indexOf a :=\n  \u27e8fun hm => \u27e8argmax_mem hm, fun a ha => le_of_mem_argmax ha hm, fun _ => index_of_argmax hm\u27e9,\n    by\n    rintro \u27e8hml, ham, hma\u27e9\n    cases' harg : argmax f l with n\n    \u00b7 simp_all\n    \u00b7 have :=\n        _root_.le_antisymm (hma n (argmax_mem harg) (le_of_mem_argmax hml harg))\n          (index_of_argmax harg hml (ham _ (argmax_mem harg)))\n      rw [(indexOf_inj hml (argmax_mem harg)).1 this, Option.mem_def]\u27e9\n#align list.mem_argmax_iff List.mem_argmax_iff\n\ntheorem argmax_eq_some_iff :\n    argmax f l = some m \u2194\n      m \u2208 l \u2227 (\u2200 a \u2208 l, f a \u2264 f m) \u2227 \u2200 a \u2208 l, f m \u2264 f a \u2192 l.indexOf m \u2264 l.indexOf a :=\n  mem_argmax_iff\n#align list.argmax_eq_some_iff List.argmax_eq_some_iff\n\ntheorem mem_argmin_iff :\n    m \u2208 argmin f l \u2194\n      m \u2208 l \u2227 (\u2200 a \u2208 l, f m \u2264 f a) \u2227 \u2200 a \u2208 l, f a \u2264 f m \u2192 l.indexOf m \u2264 l.indexOf a :=\n  @mem_argmax_iff _ \u03b2\u1d52\u1d48 _ _ _ _ _\n#align list.mem_argmin_iff List.mem_argmin_iff\n\ntheorem argmin_eq_some_iff :\n    argmin f l = some m \u2194\n      m \u2208 l \u2227 (\u2200 a \u2208 l, f m \u2264 f a) \u2227 \u2200 a \u2208 l, f a \u2264 f m \u2192 l.indexOf m \u2264 l.indexOf a :=\n  mem_argmin_iff\n#align list.argmin_eq_some_iff List.argmin_eq_some_iff\n\nend LinearOrder\n\nsection MaximumMinimum\n\nsection Preorder\n\nvariable [Preorder \u03b1] [@DecidableRel \u03b1 (\u00b7 < \u00b7)] {l : List \u03b1} {a m : \u03b1}\n\n/-- `maximum l` returns an `WithBot \u03b1`, the largest element of `l` for nonempty lists, and `\u22a5` for\n`[]`  -/\ndef maximum (l : List \u03b1) : WithBot \u03b1 :=\n  argmax id l\n#align list.maximum List.maximum\n\n/-- `minimum l` returns an `WithTop \u03b1`, the smallest element of `l` for nonempty lists, and `\u22a4` for\n`[]`  -/\ndef minimum (l : List \u03b1) : WithTop \u03b1 :=\n  argmin id l\n#align list.minimum List.minimum\n\n@[simp]\ntheorem maximum_nil : maximum ([] : List \u03b1) = \u22a5 :=\n  rfl\n#align list.maximum_nil List.maximum_nil\n\n@[simp]\ntheorem minimum_nil : minimum ([] : List \u03b1) = \u22a4 :=\n  rfl\n#align list.minimum_nil List.minimum_nil\n\n@[simp]\ntheorem maximum_singleton (a : \u03b1) : maximum [a] = a :=\n  rfl\n#align list.maximum_singleton List.maximum_singleton\n\n@[simp]\ntheorem minimum_singleton (a : \u03b1) : minimum [a] = a :=\n  rfl\n#align list.minimum_singleton List.minimum_singleton\n\ntheorem maximum_mem {l : List \u03b1} {m : \u03b1} : (maximum l : WithTop \u03b1) = m \u2192 m \u2208 l :=\n  argmax_mem\n#align list.maximum_mem List.maximum_mem\n\ntheorem minimum_mem {l : List \u03b1} {m : \u03b1} : (minimum l : WithBot \u03b1) = m \u2192 m \u2208 l :=\n  argmin_mem\n#align list.minimum_mem List.minimum_mem\n\n@[simp]\ntheorem maximum_eq_none {l : List \u03b1} : l.maximum = none \u2194 l = [] :=\n  argmax_eq_none\n#align list.maximum_eq_none List.maximum_eq_none\n\n@[simp]\ntheorem minimum_eq_none {l : List \u03b1} : l.minimum = none \u2194 l = [] :=\n  argmin_eq_none\n#align list.minimum_eq_none List.minimum_eq_none\n\ntheorem not_lt_maximum_of_mem : a \u2208 l \u2192 (maximum l : WithBot \u03b1) = m \u2192 \u00acm < a :=\n  not_lt_of_mem_argmax\n#align list.not_lt_maximum_of_mem List.not_lt_maximum_of_mem\n\n\n\ntheorem not_lt_maximum_of_mem' (ha : a \u2208 l) : \u00acmaximum l < (a : WithBot \u03b1) := by\n  cases h : l.maximum\n  \u00b7 simp_all\n  \u00b7 simp [WithBot.some_eq_coe, WithBot.coe_lt_coe, not_lt_maximum_of_mem ha h, not_false_iff]\n#align list.not_lt_maximum_of_mem' List.not_lt_maximum_of_mem'\n\ntheorem not_lt_minimum_of_mem' (ha : a \u2208 l) : \u00ac(a : WithTop \u03b1) < minimum l :=\n  @not_lt_maximum_of_mem' \u03b1\u1d52\u1d48 _ _ _ _ ha\n#align list.not_lt_minimum_of_mem' List.not_lt_minimum_of_mem'\n\nend Preorder\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] {l : List \u03b1} {a m : \u03b1}\n\ntheorem maximum_concat (a : \u03b1) (l : List \u03b1) : maximum (l ++ [a]) = max (maximum l) a := by\n  simp only [maximum, argmax_concat, id]\n  cases h : argmax id l\n  \u00b7 exact (max_eq_right bot_le).symm\n  \u00b7 simp [WithBot.some_eq_coe, max_def_lt, WithBot.coe_lt_coe]\n#align list.maximum_concat List.maximum_concat\n\ntheorem le_maximum_of_mem : a \u2208 l \u2192 (maximum l : WithBot \u03b1) = m \u2192 a \u2264 m :=\n  le_of_mem_argmax\n#align list.le_maximum_of_mem List.le_maximum_of_mem\n\ntheorem minimum_le_of_mem : a \u2208 l \u2192 (minimum l : WithTop \u03b1) = m \u2192 m \u2264 a :=\n  le_of_mem_argmin\n#align list.minimum_le_of_mem List.minimum_le_of_mem\n\ntheorem le_maximum_of_mem' (ha : a \u2208 l) : (a : WithBot \u03b1) \u2264 maximum l :=\n  le_of_not_lt <| not_lt_maximum_of_mem' ha\n#align list.le_maximum_of_mem' List.le_maximum_of_mem'\n\ntheorem le_minimum_of_mem' (ha : a \u2208 l) : minimum l \u2264 (a : WithTop \u03b1) :=\n  @le_maximum_of_mem' \u03b1\u1d52\u1d48 _ _ _ ha\n#align list.le_minimum_of_mem' List.le_minimum_of_mem'\n\ntheorem minimum_concat (a : \u03b1) (l : List \u03b1) : minimum (l ++ [a]) = min (minimum l) a :=\n  @maximum_concat \u03b1\u1d52\u1d48 _ _ _\n#align list.minimum_concat List.minimum_concat\n\ntheorem maximum_cons (a : \u03b1) (l : List \u03b1) : maximum (a :: l) = max \u2191a (maximum l) :=\n  List.reverseRecOn l (by simp [@max_eq_left (WithBot \u03b1) _ _ _ bot_le]) fun tl hd ih => by\n    rw [\u2190 cons_append, maximum_concat, ih, maximum_concat, max_assoc]\n#align list.maximum_cons List.maximum_cons\n\ntheorem minimum_cons (a : \u03b1) (l : List \u03b1) : minimum (a :: l) = min \u2191a (minimum l) :=\n  @maximum_cons \u03b1\u1d52\u1d48 _ _ _\n#align list.minimum_cons List.minimum_cons\n\ntheorem maximum_eq_coe_iff : maximum l = m \u2194 m \u2208 l \u2227 \u2200 a \u2208 l, a \u2264 m := by\n  rw [maximum, \u2190 WithBot.some_eq_coe, argmax_eq_some_iff]\n  simp only [id_eq, and_congr_right_iff, and_iff_left_iff_imp]\n  intro _ h a hal hma\n  rw [_root_.le_antisymm hma (h a hal)]\n#align list.maximum_eq_coe_iff List.maximum_eq_coe_iff\n\ntheorem minimum_eq_coe_iff : minimum l = m \u2194 m \u2208 l \u2227 \u2200 a \u2208 l, m \u2264 a :=\n  @maximum_eq_coe_iff \u03b1\u1d52\u1d48 _ _ _\n#align list.minimum_eq_coe_iff List.minimum_eq_coe_iff\n\nend LinearOrder\n\nend MaximumMinimum\n\nsection Fold\n\nvariable [LinearOrder \u03b1]\n\nsection OrderBot\n\nvariable [OrderBot \u03b1] {l : List \u03b1}\n\n@[simp]\ntheorem foldr_max_of_ne_nil (h : l \u2260 []) : \u2191(l.foldr max \u22a5) = l.maximum := by\n  induction' l with hd tl IH\n  \u00b7 contradiction\n  \u00b7 rw [maximum_cons, foldr, WithBot.coe_max]\n    by_cases h : tl = []\n    \u00b7 simp [h]\n    \u00b7 simp [IH h]\n#align list.foldr_max_of_ne_nil List.foldr_max_of_ne_nil\n\ntheorem max_le_of_forall_le (l : List \u03b1) (a : \u03b1) (h : \u2200 x \u2208 l, x \u2264 a) : l.foldr max \u22a5 \u2264 a := by\n  induction' l with y l IH\n  \u00b7 simp\n  \u00b7 simpa [h y (mem_cons_self _ _)] using IH fun x hx => h x <| mem_cons_of_mem _ hx\n#align list.max_le_of_forall_le List.max_le_of_forall_le\n\ntheorem le_max_of_le {l : List \u03b1} {a x : \u03b1} (hx : x \u2208 l) (h : a \u2264 x) : a \u2264 l.foldr max \u22a5 := by\n  induction' l with y l IH\n  \u00b7 exact absurd hx (not_mem_nil _)\n  \u00b7 obtain hl | hl := hx\n    simp only [foldr, foldr_cons]\n    \u00b7 exact le_max_of_le_left h\n    \u00b7 exact le_max_of_le_right (IH (by assumption))\n#align list.le_max_of_le List.le_max_of_le\n\nend OrderBot\n\nsection OrderTop\n\nvariable [OrderTop \u03b1] {l : List \u03b1}\n\n@[simp]\ntheorem foldr_min_of_ne_nil (h : l \u2260 []) : \u2191(l.foldr min \u22a4) = l.minimum :=\n  @foldr_max_of_ne_nil \u03b1\u1d52\u1d48 _ _ _ h\n#align list.foldr_min_of_ne_nil List.foldr_min_of_ne_nil\n\ntheorem le_min_of_forall_le (l : List \u03b1) (a : \u03b1) (h : \u2200 x \u2208 l, a \u2264 x) : a \u2264 l.foldr min \u22a4 :=\n  @max_le_of_forall_le \u03b1\u1d52\u1d48 _ _ _ _ h\n#align list.le_min_of_forall_le List.le_min_of_forall_le\n\ntheorem min_le_of_le (l : List \u03b1) (a : \u03b1) {x : \u03b1} (hx : x \u2208 l) (h : x \u2264 a) : l.foldr min \u22a4 \u2264 a :=\n  @le_max_of_le \u03b1\u1d52\u1d48 _ _ _ _ _ hx h\n#align list.min_le_of_le List.min_le_of_le\n\nend OrderTop\n\nend Fold\n\nend List\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/List/MinMax.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7103665960419163}}
{"text": "import tactic.finish\n\nimport .transfer\n\n-- EXAMPLE 1: transfering ordering <= from nat to custom nat (bijection)\n-- this example is based on the one in the article by Zimmermann and Herbelin, 2015\nnamespace example1\n\n-- a custom type N that is the natural numbers, with an ordering like <=\ndef N : Type := sorry\ndef ordern : N \u2192 N \u2192 Prop := sorry\n\n-- functions mapping N to nat and back\ndef nto : N \u2192 nat := sorry\ndef nof : nat \u2192 N := sorry\n\naxiom nto_surj : function.surjective nto\naxiom nof_surj : function.surjective nof\naxiom le_ordern_nof : \u2200 m n : nat, m <= n \u2192 ordern (nof m) (nof n)\naxiom ordern_nof_le : \u2200 m n : nat, ordern (nof m) (nof n) \u2192 m <= n\n\n--suppose we have proven transitivity for <= in nat, and want to now prove it in N without doing the proof again\ntheorem transitiveorder_nat : \u2200 x y z : nat, x <= y \u2192 y <= z \u2192 x <= z := sorry\n\ntheorem transitiveorder_N : \u2200 x y z : N, ordern x y \u2192 ordern y z \u2192 ordern x z :=\nbegin\n  transfer.transfer1 ``(nof_surj) [``(ordern_nof_le _ _)] [``(le_ordern_nof), ``(transitiveorder_nat)],\nend\n\n--we could also prove it the other way, the proof is symmetric: using ax1 instead of ax2 and swapping ax3 and ax4\ntheorem transitiveorder_nat' : \u2200 x y z : nat, x <= y \u2192 y <= z \u2192 x <= z := \nbegin \n  transfer.transfer1 ``(nof_surj) [``(ordern_nof_le _ _)] [``(le_ordern_nof), ``(transitiveorder_nat)],\n  -- ! exact same command\nend\n\nend example1\n\n\n-- EXAMPLE 2: transfer the theorem that odd+odd=even from z to z mod 2 and back.\nnamespace example2\n\ndefinition even (n : int) : Prop := n % 2 = 0\n\n-- a custom type Z/2Z, with operation add and predicate even\ninductive Z2 : Type\n| zero : Z2\n| one : Z2\n\nopen Z2\n\ndef Z2.add : Z2 \u2192 Z2 \u2192 Z2\n| zero y := y\n| one zero := one \n| one one := zero\n\ninductive Z2.even : Z2 \u2192 Prop\n| zeroiseven : Z2.even zero\n\n-- mapping from int to Z2 (no inverse mapping)\ndef ztoz2 : int \u2192 Z2 := \u03bb n, if n % 2 = 0 then zero else one\n\n-- axioms needed for transfer:\naxiom surjectivemap : function.surjective ztoz2\n-- axiom transfer_add : \u2200 m n : int, (ztoz2 m).add (ztoz2 n) = ztoz2(m + n)\naxiom transfer_add' : \u2200 m n : int, ztoz2(m + n) = (ztoz2 m).add (ztoz2 n)\naxiom eventoz2 : \u2200 n : int, even n \u2192 Z2.even (ztoz2 n)\naxiom evenfromz2 : \u2200 n : int, Z2.even (ztoz2 n) \u2192 even n  -- specific wording of the axioms makes the proof go nicely\n\n-- theorem about adding two odd integers, now we want the same result in Z2\ntheorem thetheoremforint : \u2200 m n : int, \u00ac even m \u2192 \u00ac even n \u2192 even (m + n) := sorry\n\ntheorem thetheoremforZ2 : \u2200 x y : Z2, \u00ac Z2.even x \u2192 \u00ac Z2.even y \u2192 Z2.even (Z2.add x y) := \nbegin\n  transfer.transfer1 ``(surjectivemap) [``(transfer_add'), ``(eventoz2)] [``(thetheoremforint), ``(eventoz2)],\nend\n\n-- the other direction can also be shown\ntheorem thetheoremforint' : \u2200 x y : int, \u00ac even x \u2192 \u00ac even y \u2192 even (x + y) := \nbegin\n    transfer.transfer1 ``(surjectivemap) [``(transfer_add'), ``(eventoz2)] [``(thetheoremforint), ``(eventoz2)],\nend\n\nend example2\n\n\n-- EXAMPLE 3: even theorem but with injection natural numbers to integers\nnamespace example3\n\ndefinition even (n : nat) : Prop := n % 2 = 0\ndefinition evenint (x : int) : Prop := x % 2 = 0\n\n-- mapping between nat and int\ndef ntoi : nat \u2192 int := int.of_nat\ndef nofi : int \u2192 nat := int.nat_abs\n\n-- axioms needed for transfer:\n-- axiom inverse1way : \u2200 n : nat, nofi(ntoi n) = n\naxiom nofi_surj : function.surjective nofi\naxiom transfer_add : \u2200 x y : int, nofi x + nofi y = nofi (x + y)\naxiom eventoint: \u2200 x : int, even (nofi x) \u2192 evenint x\naxiom evenfromint : \u2200 x : int, evenint x \u2192 even (nofi x)\n\ntheorem thetheoremfornat : \u2200 m n : nat, \u00ac even m \u2192 \u00ac even n \u2192 even (m + n) := sorry\n\ntheorem thetheoremforint : \u2200 x y : int, \u00ac evenint x \u2192 \u00ac evenint y \u2192 evenint (x + y) :=\nbegin\n  transfer.transfer1 ``(nofi_surj) [``(eventoint), ``(transfer_add)] [``(thetheoremfornat), ``(eventoint)]\nend\n\ntheorem thetheoremfornat' : \u2200 m n : nat, \u00ac even m \u2192 \u00ac even n \u2192 even (m + n) :=\nbegin\n  transfer.transfer1 ``(nofi_surj) [``(eventoint), ``(transfer_add)] [``(thetheoremfornat), ``(eventoint)]\nend\n\nend example3", "meta": {"author": "KoenKahlman", "repo": "transfer", "sha": "b7de7b23ed00764dd02b5c6fd715a70c6e0b8374", "save_path": "github-repos/lean/KoenKahlman-transfer", "path": "github-repos/lean/KoenKahlman-transfer/transfer-b7de7b23ed00764dd02b5c6fd715a70c6e0b8374/examples_transfer1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7103305995018598}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Ya\u00ebl Dillies\n-/\nimport analysis.normed.group.basic\nimport topology.metric_space.hausdorff_distance\n\n/-!\n# Properties of pointwise addition of sets in normed groups\n\nWe explore the relationships between pointwise addition of sets in normed groups, and the norm.\nNotably, we show that the sum of bounded sets remain bounded.\n-/\n\nopen metric set\nopen_locale pointwise topology\n\nvariables {E : Type*}\n\nsection seminormed_group\nvariables [seminormed_group E] {\u03b5 \u03b4 : \u211d} {s t : set E} {x y : E}\n\n@[to_additive] lemma metric.bounded.mul (hs : bounded s) (ht : bounded t) : bounded (s * t) :=\nbegin\n  obtain \u27e8Rs, hRs\u27e9 : \u2203 R, \u2200 x \u2208 s, \u2016x\u2016 \u2264 R := hs.exists_norm_le',\n  obtain \u27e8Rt, hRt\u27e9 : \u2203 R, \u2200 x \u2208 t, \u2016x\u2016 \u2264 R := ht.exists_norm_le',\n  refine bounded_iff_forall_norm_le'.2 \u27e8Rs + Rt, _\u27e9,\n  rintro z \u27e8x, y, hx, hy, rfl\u27e9,\n  exact norm_mul_le_of_le (hRs x hx) (hRt y hy),\nend\n\n@[to_additive] lemma metric.bounded.inv : bounded s \u2192 bounded s\u207b\u00b9 :=\nby { simp_rw [bounded_iff_forall_norm_le', \u2190image_inv, ball_image_iff, norm_inv'], exact id }\n\n@[to_additive] lemma metric.bounded.div (hs : bounded s) (ht : bounded t) : bounded (s / t) :=\n(div_eq_mul_inv _ _).symm.subst $ hs.mul ht.inv\n\nend seminormed_group\n\nsection seminormed_comm_group\nvariables [seminormed_comm_group E] {\u03b5 \u03b4 : \u211d} {s t : set E} {x y : E}\n\nsection emetric\nopen emetric\n\n@[to_additive]\nlemma inf_edist_inv (x : E) (s : set E) : inf_edist x\u207b\u00b9 s = inf_edist x s\u207b\u00b9 :=\neq_of_forall_le_iff $ \u03bb r, by simp_rw [le_inf_edist, \u2190image_inv, ball_image_iff, edist_inv]\n\n@[simp, to_additive]\nlemma inf_edist_inv_inv (x : E) (s : set E) : inf_edist x\u207b\u00b9 s\u207b\u00b9 = inf_edist x s :=\nby rw [inf_edist_inv, inv_inv]\n\nend emetric\n\nvariables (\u03b5 \u03b4 s t x y)\n\n@[simp, to_additive] lemma inv_thickening : (thickening \u03b4 s)\u207b\u00b9 = thickening \u03b4 s\u207b\u00b9 :=\nby { simp_rw [thickening, \u2190inf_edist_inv], refl }\n\n@[simp, to_additive] lemma inv_cthickening : (cthickening \u03b4 s)\u207b\u00b9 = cthickening \u03b4 s\u207b\u00b9 :=\nby { simp_rw [cthickening, \u2190inf_edist_inv], refl }\n\n@[simp, to_additive] lemma inv_ball : (ball x \u03b4)\u207b\u00b9 = ball x\u207b\u00b9 \u03b4 :=\nby { simp_rw [ball, \u2190dist_inv], refl }\n\n@[simp, to_additive] lemma inv_closed_ball : (closed_ball x \u03b4)\u207b\u00b9 = closed_ball x\u207b\u00b9 \u03b4 :=\nby { simp_rw [closed_ball, \u2190dist_inv], refl }\n\n@[to_additive] lemma singleton_mul_ball : {x} * ball y \u03b4 = ball (x * y) \u03b4 :=\nby simp only [preimage_mul_ball, image_mul_left, singleton_mul, div_inv_eq_mul, mul_comm y x]\n\n@[to_additive] lemma singleton_div_ball : {x} / ball y \u03b4 = ball (x / y) \u03b4 :=\nby simp_rw [div_eq_mul_inv, inv_ball, singleton_mul_ball]\n\n@[to_additive] lemma ball_mul_singleton : ball x \u03b4 * {y} = ball (x * y) \u03b4 :=\nby rw [mul_comm, singleton_mul_ball, mul_comm y]\n\n@[to_additive] lemma ball_div_singleton : ball x \u03b4 / {y} = ball (x / y) \u03b4 :=\nby simp_rw [div_eq_mul_inv, inv_singleton, ball_mul_singleton]\n\n@[to_additive] lemma singleton_mul_ball_one : {x} * ball 1 \u03b4 = ball x \u03b4 := by simp\n\n@[to_additive] lemma singleton_div_ball_one : {x} / ball 1 \u03b4 = ball x \u03b4 :=\nby simp [singleton_div_ball]\n\n@[to_additive] lemma ball_one_mul_singleton : ball 1 \u03b4 * {x} = ball x \u03b4 :=\nby simp [ball_mul_singleton]\n\n@[to_additive] lemma ball_one_div_singleton : ball 1 \u03b4 / {x} = ball x\u207b\u00b9 \u03b4 :=\nby simp [ball_div_singleton]\n\n@[to_additive] lemma smul_ball_one : x \u2022 ball 1 \u03b4 = ball x \u03b4 :=\nby { ext, simp [mem_smul_set_iff_inv_smul_mem, inv_mul_eq_div, dist_eq_norm_div] }\n\n@[simp, to_additive]\nlemma singleton_mul_closed_ball : {x} * closed_ball y \u03b4 = closed_ball (x * y) \u03b4 :=\nby simp only [mul_comm y x, preimage_mul_closed_ball, image_mul_left, singleton_mul, div_inv_eq_mul]\n\n@[simp, to_additive]\nlemma singleton_div_closed_ball : {x} / closed_ball y \u03b4 = closed_ball (x / y) \u03b4 :=\nby simp_rw [div_eq_mul_inv, inv_closed_ball, singleton_mul_closed_ball]\n\n@[simp, to_additive]\nlemma closed_ball_mul_singleton : closed_ball x \u03b4 * {y} = closed_ball (x * y) \u03b4 :=\nby simp [mul_comm _ {y}, mul_comm y]\n\n@[simp, to_additive]\nlemma closed_ball_div_singleton : closed_ball x \u03b4 / {y} = closed_ball (x / y) \u03b4 :=\nby simp [div_eq_mul_inv]\n\n@[to_additive]\nlemma singleton_mul_closed_ball_one : {x} * closed_ball 1 \u03b4 = closed_ball x \u03b4 := by simp\n\n@[to_additive]\nlemma singleton_div_closed_ball_one : {x} / closed_ball 1 \u03b4 = closed_ball x \u03b4 := by simp\n\n@[to_additive]\nlemma closed_ball_one_mul_singleton : closed_ball 1 \u03b4 * {x} = closed_ball x \u03b4 := by simp\n\n@[to_additive]\nlemma closed_ball_one_div_singleton : closed_ball 1 \u03b4 / {x} = closed_ball x\u207b\u00b9 \u03b4 := by simp\n\n-- This is the `to_additive` version of the below, but it will later follow as a special case of\n-- `vadd_closed_ball` for `normed_add_torsor`s, so we give it higher simp priority.\n-- (There is no `normed_mul_torsor`, hence the asymmetry between additive and multiplicative\n-- versions.)\n@[simp, priority 1100] lemma vadd_closed_ball_zero {E : Type*} [seminormed_add_comm_group E] (\u03b4 : \u211d)\n  (x : E) :\n  x +\u1d65 metric.closed_ball 0 \u03b4 = metric.closed_ball x \u03b4 :=\nby { ext, simp [mem_vadd_set_iff_neg_vadd_mem, neg_add_eq_sub, dist_eq_norm_sub] }\n\n@[simp] lemma smul_closed_ball_one : x \u2022 closed_ball 1 \u03b4 = closed_ball x \u03b4 :=\nby { ext, simp [mem_smul_set_iff_inv_smul_mem, inv_mul_eq_div, dist_eq_norm_div] }\n\nattribute [to_additive] smul_closed_ball_one\n\n@[to_additive] lemma mul_ball_one : s * ball 1 \u03b4 = thickening \u03b4 s :=\nbegin\n  rw thickening_eq_bUnion_ball,\n  convert Union\u2082_mul (\u03bb x (_ : x \u2208 s), {x}) (ball (1 : E) \u03b4),\n  exact s.bUnion_of_singleton.symm,\n  ext x y,\n  simp_rw [singleton_mul_ball, mul_one],\nend\n\n@[to_additive]\nlemma div_ball_one : s / ball 1 \u03b4 = thickening \u03b4 s := by simp [div_eq_mul_inv, mul_ball_one]\n\n@[to_additive]\nlemma ball_mul_one : ball 1 \u03b4 * s = thickening \u03b4 s := by rw [mul_comm, mul_ball_one]\n\n@[to_additive]\nlemma ball_div_one : ball 1 \u03b4 / s = thickening \u03b4 s\u207b\u00b9 := by simp [div_eq_mul_inv, ball_mul_one]\n\n@[simp, to_additive] lemma mul_ball : s * ball x \u03b4 = x \u2022 thickening \u03b4 s :=\nby rw [\u2190smul_ball_one, mul_smul_comm, mul_ball_one]\n\n@[simp, to_additive] lemma div_ball : s / ball x \u03b4 = x\u207b\u00b9 \u2022 thickening \u03b4 s :=\nby simp [div_eq_mul_inv]\n\n@[simp, to_additive] lemma ball_mul : ball x \u03b4 * s = x \u2022 thickening \u03b4 s :=\nby rw [mul_comm, mul_ball]\n\n@[simp, to_additive] lemma ball_div : ball x \u03b4 / s = x \u2022 thickening \u03b4 s\u207b\u00b9 :=\nby simp [div_eq_mul_inv]\n\nvariables {\u03b5 \u03b4 s t x y}\n\n@[to_additive] lemma is_compact.mul_closed_ball_one (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) :\n  s * closed_ball 1 \u03b4 = cthickening \u03b4 s :=\nbegin\n  rw hs.cthickening_eq_bUnion_closed_ball h\u03b4,\n  ext x,\n  simp only [mem_mul, dist_eq_norm_div, exists_prop, mem_Union, mem_closed_ball,\n    exists_and_distrib_left, mem_closed_ball_one_iff, \u2190 eq_div_iff_mul_eq'', exists_eq_right],\nend\n\n@[to_additive] lemma is_compact.div_closed_ball_one (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) :\n  s / closed_ball 1 \u03b4 = cthickening \u03b4 s :=\nby simp [div_eq_mul_inv, hs.mul_closed_ball_one h\u03b4]\n\n@[to_additive] lemma is_compact.closed_ball_one_mul (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) :\n  closed_ball 1 \u03b4 * s = cthickening \u03b4 s :=\nby rw [mul_comm, hs.mul_closed_ball_one h\u03b4]\n\n@[to_additive] lemma is_compact.closed_ball_one_div (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) :\n  closed_ball 1 \u03b4 / s = cthickening \u03b4 s\u207b\u00b9 :=\nby simp [div_eq_mul_inv, mul_comm, hs.inv.mul_closed_ball_one h\u03b4]\n\n@[to_additive] lemma is_compact.mul_closed_ball (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  s * closed_ball x \u03b4 = x \u2022 cthickening \u03b4 s :=\nby rw [\u2190smul_closed_ball_one, mul_smul_comm, hs.mul_closed_ball_one h\u03b4]\n\n@[to_additive] lemma is_compact.div_closed_ball (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  s / closed_ball x \u03b4 = x\u207b\u00b9 \u2022 cthickening \u03b4 s :=\nby simp [div_eq_mul_inv, mul_comm, hs.mul_closed_ball h\u03b4]\n\n@[to_additive] lemma is_compact.closed_ball_mul (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  closed_ball x \u03b4 * s = x \u2022 cthickening \u03b4 s :=\nby rw [mul_comm, hs.mul_closed_ball h\u03b4]\n\n@[to_additive] lemma is_compact.closed_ball_div (hs : is_compact s) (h\u03b4 : 0 \u2264 \u03b4) (x : E) :\n  closed_ball x \u03b4 * s = x \u2022 cthickening \u03b4 s :=\nby simp [div_eq_mul_inv, mul_comm, hs.closed_ball_mul h\u03b4]\n\nend seminormed_comm_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/normed/group/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417086, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7103305975709311}}
{"text": "import .love02_backward_proofs_exercise_sheet\n\n\n/-! # LoVe Homework 2: Backward Proofs\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace backward_proofs\n\n\n/-! ## Question 1 (4 points): Connectives and Quantifiers\n\n1.1 (3 points). Complete the following proofs using basic tactics such as\n`intro`, `apply`, and `exact`.\n\nHint: Some strategies for carrying out such proofs are described at the end of\nSection 2.3 in the Hitchhiker's Guide. -/\n\nlemma B (a b c : Prop) :\n  (a \u2192 b) \u2192 (c \u2192 a) \u2192 c \u2192 b :=\nsorry\n\nlemma S (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 (a \u2192 b) \u2192 a \u2192 c :=\nsorry\n\nlemma more_nonsense (a b c : Prop) :\n  (c \u2192 (a \u2192 b) \u2192 a) \u2192 c \u2192 b \u2192 a :=\nsorry\n\nlemma even_more_nonsense (a b c : Prop) :\n  (a \u2192 a \u2192 b) \u2192 (b \u2192 c) \u2192 a \u2192 b \u2192 c :=\nsorry\n\n/-! 1.2 (1 point). Prove the following lemma using basic tactics. -/\n\nlemma weak_peirce (a b : Prop) :\n  ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\n\n/-! ## Question 2 (5 points): Logical Connectives\n\n2.1 (1 point). Prove the following property about implication using basic\ntactics.\n\nHints:\n\n* Keep in mind that `\u00ac a` is the same as `a \u2192 false`. You can start by invoking\n  `rw not_def` if this helps you.\n\n* You will need to apply the elimination rules for `\u2228` and `false` at some\n  point. -/\n\nlemma about_implication (a b : Prop) :\n  \u00ac a \u2228 b \u2192 a \u2192 b :=\nsorry\n\n/-! 2.2 (2 points). Prove the missing link in our chain of classical axiom\nimplications.\n\nHints:\n\n* You can use `rw double_negation` to unfold the definition of\n  `double_negation`, and similarly for the other definitions.\n\n* You will need to apply the double negation hypothesis for `a \u2228 \u00ac a`. You will\n  also need the left and right introduction rules for `\u2228` at some point. -/\n\n#check excluded_middle\n#check peirce\n#check double_negation\n\nlemma em_of_dn :\n  double_negation \u2192 excluded_middle :=\nsorry\n\n/-! 2.3 (2 points). We have proved three of the six possible implications\nbetween `excluded_middle`, `peirce`, and `double_negation`. State and prove the\nthree missing implications, exploiting the three theorems we already have. -/\n\n#check peirce_of_em\n#check dn_of_peirce\n#check em_of_dn\n\n-- enter your solution here\n\nend backward_proofs\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2022", "sha": "5aee593fbef9b63d4338288b4789d85851d258aa", "save_path": "github-repos/lean/blanchette-logical_verification_2022", "path": "github-repos/lean/blanchette-logical_verification_2022/logical_verification_2022-5aee593fbef9b63d4338288b4789d85851d258aa/lean/love02_backward_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385543, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.7103305920171875}}
{"text": "/-\nCopyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Kontorovich, Heather Macbeth, Marc Masdeu\n-/\n\nimport analysis.complex.upper_half_plane.basic\nimport linear_algebra.general_linear_group\nimport analysis.matrix\n\n/-!\n# The action of the modular group SL(2, \u2124) on the upper half-plane\n\nWe define the action of `SL(2,\u2124)` on `\u210d` (via restriction of the `SL(2,\u211d)` action in\n`analysis.complex.upper_half_plane`). We then define the standard fundamental domain\n(`modular_group.fd`, `\ud835\udc9f`) for this action and show\n(`modular_group.exists_smul_mem_fd`) that any point in `\u210d` can be\nmoved inside `\ud835\udc9f`.\n\n## Main definitions\n\nThe standard (closed) fundamental domain of the action of `SL(2,\u2124)` on `\u210d`, denoted `\ud835\udc9f`:\n`fd := {z | 1 \u2264 (z : \u2102).norm_sq \u2227 |z.re| \u2264 (1 : \u211d) / 2}`\n\nThe standard open fundamental domain of the action of `SL(2,\u2124)` on `\u210d`, denoted `\ud835\udc9f\u1d52`:\n`fdo := {z | 1 < (z : \u2102).norm_sq \u2227 |z.re| < (1 : \u211d) / 2}`\n\nThese notations are localized in the `modular` locale and can be enabled via `open_locale modular`.\n\n## Main results\n\nAny `z : \u210d` can be moved to `\ud835\udc9f` by an element of `SL(2,\u2124)`:\n`exists_smul_mem_fd (z : \u210d) : \u2203 g : SL(2,\u2124), g \u2022 z \u2208 \ud835\udc9f`\n\nIf both `z` and `\u03b3 \u2022 z` are in the open domain `\ud835\udc9f\u1d52` then `z = \u03b3 \u2022 z`:\n`eq_smul_self_of_mem_fdo_mem_fdo {z : \u210d} {g : SL(2,\u2124)} (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : z = g \u2022 z`\n\n# Discussion\n\nStandard proofs make use of the identity\n\n`g \u2022 z = a / c - 1 / (c (cz + d))`\n\nfor `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`.\nInstead, our proof makes use of the following perhaps novel identity (see\n`modular_group.smul_eq_lc_row0_add`):\n\n`g \u2022 z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`\n\nwhere there is no issue of division by zero.\n\nAnother feature is that we delay until the very end the consideration of special matrices\n`T=[[1,1],[0,1]]` (see `modular_group.T`) and `S=[[0,-1],[1,0]]` (see `modular_group.S`), by\ninstead using abstract theory on the properness of certain maps (phrased in terms of the filters\n`filter.cocompact`, `filter.cofinite`, etc) to deduce existence theorems, first to prove the\nexistence of `g` maximizing `(g\u2022z).im` (see `modular_group.exists_max_im`), and then among\nthose, to minimize `|(g\u2022z).re|` (see `modular_group.exists_row_one_eq_and_min_re`).\n-/\n\n/- Disable these instances as they are not the simp-normal form, and having them disabled ensures\nwe state lemmas in this file without spurious `coe_fn` terms. -/\nlocal attribute [-instance] matrix.special_linear_group.has_coe_to_fun\nlocal attribute [-instance] matrix.general_linear_group.has_coe_to_fun\n\nopen complex (hiding abs_one abs_two abs_mul abs_add)\nopen matrix (hiding mul_smul) matrix.special_linear_group upper_half_plane\nnoncomputable theory\n\nlocal notation `SL(` n `, ` R `)`:= special_linear_group (fin n) R\nlocal prefix `\u2191\u2098`:1024 := @coe _ (matrix (fin 2) (fin 2) \u2124) _\n\nopen_locale upper_half_plane complex_conjugate\n\nlocal attribute [instance] fintype.card_fin_even\n\nnamespace modular_group\n\nvariables {g : SL(2, \u2124)} (z : \u210d)\n\nsection bottom_row\n\n/-- The two numbers `c`, `d` in the \"bottom_row\" of `g=[[*,*],[c,d]]` in `SL(2, \u2124)` are coprime. -/\nlemma bottom_row_coprime {R : Type*} [comm_ring R] (g : SL(2, R)) :\n  is_coprime ((\u2191g : matrix (fin 2) (fin 2) R) 1 0) ((\u2191g : matrix (fin 2) (fin 2) R) 1 1) :=\nbegin\n  use [- (\u2191g : matrix (fin 2) (fin 2) R) 0 1, (\u2191g : matrix (fin 2) (fin 2) R) 0 0],\n  rw [add_comm, neg_mul, \u2190sub_eq_add_neg, \u2190det_fin_two],\n  exact g.det_coe,\nend\n\n/-- Every pair `![c, d]` of coprime integers is the \"bottom_row\" of some element `g=[[*,*],[c,d]]`\nof `SL(2,\u2124)`. -/\nlemma bottom_row_surj {R : Type*} [comm_ring R] :\n  set.surj_on (\u03bb g : SL(2, R), @coe _ (matrix (fin 2) (fin 2) R) _ g 1) set.univ\n    {cd | is_coprime (cd 0) (cd 1)} :=\nbegin\n  rintros cd \u27e8b\u2080, a, gcd_eqn\u27e9,\n  let A := ![![a, -b\u2080], cd],\n  have det_A_1 : det A = 1,\n  { convert gcd_eqn,\n    simp [A, det_fin_two, (by ring : a * (cd 1) + b\u2080 * (cd 0) = b\u2080 * (cd 0) + a * (cd 1))] },\n  refine \u27e8\u27e8A, det_A_1\u27e9, set.mem_univ _, _\u27e9,\n  ext; simp [A]\nend\n\nend bottom_row\n\nsection tendsto_lemmas\n\nopen filter continuous_linear_map\nlocal attribute [instance] matrix.normed_group matrix.normed_space\nlocal attribute [simp] coe_smul\n\n/-- The function `(c,d) \u2192 |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite.\n-/\nlemma tendsto_norm_sq_coprime_pair :\n  filter.tendsto (\u03bb p : fin 2 \u2192 \u2124, ((p 0 : \u2102) * z + p 1).norm_sq)\n  cofinite at_top :=\nbegin\n  let \u03c0\u2080 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d := linear_map.proj 0,\n  let \u03c0\u2081 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d := linear_map.proj 1,\n  let f : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u2102 := \u03c0\u2080.smul_right (z:\u2102) + \u03c0\u2081.smul_right 1,\n  have f_def : \u21d1f = \u03bb (p : fin 2 \u2192 \u211d), (p 0 : \u2102) * \u2191z + p 1,\n  { ext1,\n    dsimp only [linear_map.coe_proj, real_smul,\n      linear_map.coe_smul_right, linear_map.add_apply],\n    rw mul_one, },\n  have : (\u03bb (p : fin 2 \u2192 \u2124), norm_sq ((p 0 : \u2102) * \u2191z + \u2191(p 1)))\n    = norm_sq \u2218 f \u2218 (\u03bb p : fin 2 \u2192 \u2124, (coe : \u2124 \u2192 \u211d) \u2218 p),\n  { ext1,\n    rw f_def,\n    dsimp only [function.comp],\n    rw [of_real_int_cast, of_real_int_cast], },\n  rw this,\n  have hf : f.ker = \u22a5,\n  { let g : \u2102 \u2192\u2097[\u211d] (fin 2 \u2192 \u211d) :=\n      linear_map.pi ![im_lm, im_lm.comp ((z:\u2102) \u2022 (conj_ae  : \u2102 \u2192\u2097[\u211d] \u2102))],\n    suffices : ((z:\u2102).im\u207b\u00b9 \u2022 g).comp f = linear_map.id,\n    { exact linear_map.ker_eq_bot_of_inverse this },\n    apply linear_map.ext,\n    intros c,\n    have hz : (z:\u2102).im \u2260 0 := z.2.ne',\n    rw [linear_map.comp_apply, linear_map.smul_apply, linear_map.id_apply],\n    ext i,\n    dsimp only [g, pi.smul_apply, linear_map.pi_apply, smul_eq_mul],\n    fin_cases i,\n    { show ((z : \u2102).im)\u207b\u00b9 * (f c).im = c 0,\n      rw [f_def, add_im, of_real_mul_im, of_real_im, add_zero, mul_left_comm,\n        inv_mul_cancel hz, mul_one], },\n    { show ((z : \u2102).im)\u207b\u00b9 * ((z : \u2102) * conj (f c)).im = c 1,\n      rw [f_def, ring_hom.map_add, ring_hom.map_mul, mul_add, mul_left_comm, mul_conj,\n        conj_of_real, conj_of_real, \u2190 of_real_mul, add_im, of_real_im, zero_add,\n        inv_mul_eq_iff_eq_mul\u2080 hz],\n      simp only [of_real_im, of_real_re, mul_im, zero_add, mul_zero] } },\n  have h\u2081 := (linear_equiv.closed_embedding_of_injective hf).tendsto_cocompact,\n  have h\u2082 : tendsto (\u03bb p : fin 2 \u2192 \u2124, (coe : \u2124 \u2192 \u211d) \u2218 p) cofinite (cocompact _),\n  { convert tendsto.pi_map_Coprod (\u03bb i, int.tendsto_coe_cofinite),\n    { rw Coprod_cofinite },\n    { rw Coprod_cocompact } },\n  exact tendsto_norm_sq_cocompact_at_top.comp (h\u2081.comp h\u2082)\nend\n\n\n/-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`.\n  This is the linear map version of this operation.\n-/\ndef lc_row0 (p : fin 2 \u2192 \u2124) : (matrix (fin 2) (fin 2) \u211d) \u2192\u2097[\u211d] \u211d :=\n((p 0:\u211d) \u2022 linear_map.proj 0 + (p 1:\u211d) \u2022 linear_map.proj 1 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d).comp\n  (linear_map.proj 0)\n\n@[simp] lemma lc_row0_apply (p : fin 2 \u2192 \u2124) (g : matrix (fin 2) (fin 2) \u211d) :\n  lc_row0 p g = p 0 * g 0 0 + p 1 * g 0 1 :=\nrfl\n\n/-- Linear map sending the matrix [a, b; c, d] to the matrix [ac\u2080 + bd\u2080, - ad\u2080 + bc\u2080; c, d], for\nsome fixed `(c\u2080, d\u2080)`. -/\n@[simps] def lc_row0_extend {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  (matrix (fin 2) (fin 2) \u211d) \u2243\u2097[\u211d] matrix (fin 2) (fin 2) \u211d :=\nlinear_equiv.Pi_congr_right\n![begin\n    refine linear_map.general_linear_group.general_linear_equiv \u211d (fin 2 \u2192 \u211d)\n      (general_linear_group.to_linear (plane_conformal_matrix (cd 0 : \u211d) (-(cd 1 : \u211d)) _)),\n    norm_cast,\n    rw neg_sq,\n    exact hcd.sq_add_sq_ne_zero\n  end,\n  linear_equiv.refl \u211d (fin 2 \u2192 \u211d)]\n\n/-- The map `lc_row0` is proper, that is, preimages of cocompact sets are finite in\n`[[* , *], [c, d]]`.-/\ntheorem tendsto_lc_row0 {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  tendsto (\u03bb g : {g : SL(2, \u2124) // \u2191\u2098g 1 = cd}, lc_row0 cd \u2191(\u2191g : SL(2, \u211d)))\n    cofinite (cocompact \u211d) :=\nbegin\n  let mB : \u211d \u2192 (matrix (fin 2) (fin 2)  \u211d) := \u03bb t, ![![t, (-(1:\u2124):\u211d)], coe \u2218 cd],\n  have hmB : continuous mB,\n  { simp only [continuous_pi_iff, fin.forall_fin_two, mB, continuous_const, continuous_id',\n      cons_val_zero, cons_val_one, and_self ] },\n  refine filter.tendsto.of_tendsto_comp _ (comap_cocompact_le hmB),\n  let f\u2081 : SL(2, \u2124) \u2192 matrix (fin 2) (fin 2) \u211d :=\n    \u03bb g, matrix.map (\u2191g : matrix _ _ \u2124) (coe : \u2124 \u2192 \u211d),\n  have cocompact_\u211d_to_cofinite_\u2124_matrix :\n    tendsto (\u03bb m : matrix (fin 2) (fin 2) \u2124, matrix.map m (coe : \u2124 \u2192 \u211d)) cofinite (cocompact _),\n  { simpa only [Coprod_cofinite, Coprod_cocompact]\n      using tendsto.pi_map_Coprod (\u03bb i : fin 2, tendsto.pi_map_Coprod\n        (\u03bb j : fin 2, int.tendsto_coe_cofinite)) },\n  have hf\u2081 : tendsto f\u2081 cofinite (cocompact _) :=\n    cocompact_\u211d_to_cofinite_\u2124_matrix.comp subtype.coe_injective.tendsto_cofinite,\n  have hf\u2082 : closed_embedding (lc_row0_extend hcd) :=\n    (lc_row0_extend hcd).to_continuous_linear_equiv.to_homeomorph.closed_embedding,\n  convert hf\u2082.tendsto_cocompact.comp (hf\u2081.comp subtype.coe_injective.tendsto_cofinite) using 1,\n  ext \u27e8g, rfl\u27e9 i j : 3,\n  fin_cases i; [fin_cases j, skip],\n  -- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts.\n  { simp only [mB, mul_vec, dot_product, fin.sum_univ_two, _root_.coe_coe, coe_matrix_coe,\n      int.coe_cast_ring_hom, lc_row0_apply, function.comp_app, cons_val_zero, lc_row0_extend_apply,\n      linear_map.general_linear_group.coe_fn_general_linear_equiv,\n      general_linear_group.to_linear_apply, coe_plane_conformal_matrix, neg_neg, mul_vec_lin_apply,\n      cons_val_one, head_cons] },\n  { convert congr_arg (\u03bb n : \u2124, (-n:\u211d)) g.det_coe.symm using 1,\n    simp only [f\u2081, mul_vec, dot_product, fin.sum_univ_two, matrix.det_fin_two, function.comp_app,\n      subtype.coe_mk, lc_row0_extend_apply, cons_val_zero,\n      linear_map.general_linear_group.coe_fn_general_linear_equiv,\n      general_linear_group.to_linear_apply, coe_plane_conformal_matrix, mul_vec_lin_apply,\n      cons_val_one, head_cons, map_apply, neg_mul, int.cast_sub, int.cast_mul, neg_sub],\n    ring },\n  { refl }\nend\n\n/-- This replaces `(g\u2022z).re = a/c + *` in the standard theory with the following novel identity:\n  `g \u2022 z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`\n  which does not need to be decomposed depending on whether `c = 0`. -/\nlemma smul_eq_lc_row0_add {p : fin 2 \u2192 \u2124} (hp : is_coprime (p 0) (p 1)) (hg : \u2191\u2098g 1 = p) :\n  \u2191(g \u2022 z) = ((lc_row0 p \u2191(g : SL(2, \u211d))) : \u2102) / (p 0 ^ 2 + p 1 ^ 2)\n    + ((p 1 : \u2102) * z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1)) :=\nbegin\n  have nonZ1 : (p 0 : \u2102) ^ 2 + (p 1) ^ 2 \u2260 0 := by exact_mod_cast hp.sq_add_sq_ne_zero,\n  have : (coe : \u2124 \u2192 \u211d) \u2218 p \u2260 0 := \u03bb h, hp.ne_zero (by ext i; simpa using congr_fun h i),\n  have nonZ2 : (p 0 : \u2102) * z + p 1 \u2260 0 := by simpa using linear_ne_zero _ z this,\n  field_simp [nonZ1, nonZ2, denom_ne_zero, -upper_half_plane.denom, -denom_apply],\n  rw (by simp : (p 1 : \u2102) * z - p 0 = ((p 1) * z - p 0) * \u2191(det (\u2191g : matrix (fin 2) (fin 2) \u2124))),\n  rw [\u2190hg, det_fin_two],\n  simp only [int.coe_cast_ring_hom, coe_matrix_coe, int.cast_mul, of_real_int_cast, map_apply,\n  denom, int.cast_sub, _root_.coe_coe,coe_GL_pos_coe_GL_coe_matrix],\n  ring,\nend\n\nlemma tendsto_abs_re_smul {p : fin 2 \u2192 \u2124} (hp : is_coprime (p 0) (p 1)) :\n  tendsto (\u03bb g : {g : SL(2, \u2124) // \u2191\u2098g 1 = p}, |((g : SL(2, \u2124)) \u2022 z).re|)\n    cofinite at_top :=\nbegin\n  suffices : tendsto (\u03bb g : (\u03bb g : SL(2, \u2124), \u2191\u2098g 1) \u207b\u00b9' {p}, (((g : SL(2, \u2124)) \u2022 z).re))\n    cofinite (cocompact \u211d),\n  { exact tendsto_norm_cocompact_at_top.comp this },\n  have : ((p 0 : \u211d) ^ 2 + p 1 ^ 2)\u207b\u00b9 \u2260 0,\n  { apply inv_ne_zero,\n    exact_mod_cast hp.sq_add_sq_ne_zero },\n  let f := homeomorph.mul_right\u2080 _ this,\n  let ff := homeomorph.add_right (((p 1:\u2102)* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re,\n  convert ((f.trans ff).closed_embedding.tendsto_cocompact).comp (tendsto_lc_row0 hp),\n  ext g,\n  change ((g : SL(2, \u2124)) \u2022 z).re = (lc_row0 p \u2191(\u2191g : SL(2, \u211d))) / (p 0 ^ 2 + p 1 ^ 2)\n  + (((p 1:\u2102 )* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re,\n  exact_mod_cast (congr_arg complex.re (smul_eq_lc_row0_add z hp g.2))\nend\n\nend tendsto_lemmas\n\nsection fundamental_domain\n\nlocal attribute [simp] coe_smul re_smul\n\n/-- For `z : \u210d`, there is a `g : SL(2,\u2124)` maximizing `(g\u2022z).im` -/\nlemma exists_max_im :\n  \u2203 g : SL(2, \u2124), \u2200 g' : SL(2, \u2124), (g' \u2022 z).im \u2264 (g \u2022 z).im :=\nbegin\n  classical,\n  let s : set (fin 2 \u2192 \u2124) := {cd | is_coprime (cd 0) (cd 1)},\n  have hs : s.nonempty := \u27e8![1, 1], is_coprime_one_left\u27e9,\n  obtain \u27e8p, hp_coprime, hp\u27e9 :=\n    filter.tendsto.exists_within_forall_le hs (tendsto_norm_sq_coprime_pair z),\n  obtain \u27e8g, -, hg\u27e9 := bottom_row_surj hp_coprime,\n  refine \u27e8g, \u03bb g', _\u27e9,\n  rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq,\n    div_le_div_left],\n  { simpa [\u2190 hg] using hp (\u2191\u2098g' 1) (bottom_row_coprime g') },\n  { exact z.im_pos },\n  { exact norm_sq_denom_pos g' z },\n  { exact norm_sq_denom_pos g z },\nend\n\n/-- Given `z : \u210d` and a bottom row `(c,d)`, among the `g : SL(2,\u2124)` with this bottom row, minimize\n  `|(g\u2022z).re|`.  -/\nlemma exists_row_one_eq_and_min_re {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  \u2203 g : SL(2,\u2124), \u2191\u2098g 1 = cd \u2227 (\u2200 g' : SL(2,\u2124), \u2191\u2098g 1 = \u2191\u2098g' 1 \u2192\n  |(g \u2022 z).re| \u2264 |(g' \u2022 z).re|) :=\nbegin\n  haveI : nonempty {g : SL(2, \u2124) // \u2191\u2098g 1 = cd} :=\n    let \u27e8x, hx\u27e9 := bottom_row_surj hcd in \u27e8\u27e8x, hx.2\u27e9\u27e9,\n  obtain \u27e8g, hg\u27e9 := filter.tendsto.exists_forall_le (tendsto_abs_re_smul z hcd),\n  refine \u27e8g, g.2, _\u27e9,\n  { intros g1 hg1,\n    have : g1 \u2208 ((\u03bb g : SL(2, \u2124), \u2191\u2098g 1) \u207b\u00b9' {cd}),\n    { rw [set.mem_preimage, set.mem_singleton_iff],\n      exact eq.trans hg1.symm (set.mem_singleton_iff.mp (set.mem_preimage.mp g.2)) },\n    exact hg \u27e8g1, this\u27e9 },\nend\n\n/-- The matrix `T = [[1,1],[0,1]]` as an element of `SL(2,\u2124)` -/\ndef T : SL(2,\u2124) := \u27e8![![1, 1], ![0, 1]], by norm_num [matrix.det_fin_two]\u27e9\n\n/-- The matrix `S = [[0,-1],[1,0]]` as an element of `SL(2,\u2124)` -/\ndef S : SL(2,\u2124) := \u27e8![![0, -1], ![1, 0]], by norm_num [matrix.det_fin_two]\u27e9\n\nlemma coe_S : \u2191\u2098S = ![![0, -1], ![1, 0]] := rfl\n\nlemma coe_T : \u2191\u2098T = ![![1, 1], ![0, 1]] := rfl\n\nlemma coe_T_inv : \u2191\u2098(T\u207b\u00b9) = ![![1, -1], ![0, 1]] := by simp [coe_inv, coe_T, adjugate_fin_two]\n\nlemma coe_T_zpow (n : \u2124) : \u2191\u2098(T ^ n) = ![![1, n], ![0,1]] :=\nbegin\n  induction n using int.induction_on with n h n h,\n  { ext i j, fin_cases i; fin_cases j;\n    simp, },\n  { rw [zpow_add, zpow_one, coe_mul, h, coe_T],\n    ext i j, fin_cases i; fin_cases j;\n    simp [matrix.mul_apply, fin.sum_univ_succ, add_comm (1 : \u2124)], },\n  { rw [zpow_sub, zpow_one, coe_mul, h, coe_T_inv],\n    ext i j, fin_cases i; fin_cases j;\n    simp [matrix.mul_apply, fin.sum_univ_succ, neg_add_eq_sub (1 : \u2124)], },\nend\n\nvariables {z}\n\nlemma coe_T_zpow_smul_eq {n : \u2124} : (\u2191((T^n) \u2022 z) : \u2102) = z + n :=\nby simp [coe_T_zpow]\n\n-- If instead we had `g` and `T` of type `PSL(2, \u2124)`, then we could simply state `g = T^n`.\nlemma exists_eq_T_zpow_of_c_eq_zero (hc : \u2191\u2098g 1 0 = 0) :\n  \u2203 (n : \u2124), \u2200 (z : \u210d), g \u2022 z = T^n \u2022 z :=\nbegin\n  have had := g.det_coe,\n  replace had : \u2191\u2098g 0 0 * \u2191\u2098g 1 1 = 1, { rw [det_fin_two, hc] at had, linarith, },\n  rcases int.eq_one_or_neg_one_of_mul_eq_one' had with \u27e8ha, hd\u27e9 | \u27e8ha, hd\u27e9,\n  { use \u2191\u2098g 0 1,\n    suffices : g = T^(\u2191\u2098g 0 1), { intros z, conv_lhs { rw this, }, },\n    ext i j, fin_cases i; fin_cases j;\n    simp [ha, hc, hd, coe_T_zpow], },\n  { use -\u2191\u2098g 0 1,\n    suffices : g = -T^(-\u2191\u2098g 0 1), { intros z, conv_lhs { rw [this, SL_neg_smul], }, },\n    ext i j, fin_cases i; fin_cases j;\n    simp [ha, hc, hd, coe_T_zpow], },\nend\n\n/- If `c = 1`, then `g` factorises into a product terms involving only `T` and `S`. -/\nlemma g_eq_of_c_eq_one (hc : \u2191\u2098g 1 0 = 1) :\n  g = T^(\u2191\u2098g 0 0) * S * T^(\u2191\u2098g 1 1) :=\nbegin\n  have hg := g.det_coe.symm,\n  replace hg : \u2191\u2098g 0 1 = \u2191\u2098g 0 0 * \u2191\u2098g 1 1 - 1, { rw [det_fin_two, hc] at hg, linarith, },\n  ext i j, fin_cases i; fin_cases j;\n  simp [coe_S, coe_T_zpow, matrix.mul_apply, fin.sum_univ_succ, hg, hc],\nend\n\n/-- If `1 < |z|`, then `|S \u2022 z| < 1`. -/\nlemma norm_sq_S_smul_lt_one (h: 1 < norm_sq z) : norm_sq \u2191(S \u2022 z) < 1 :=\nby simpa [coe_S] using (inv_lt_inv z.norm_sq_pos zero_lt_one).mpr h\n\n/-- If `|z| < 1`, then applying `S` strictly decreases `im`. -/\nlemma im_lt_im_S_smul (h: norm_sq z < 1) : z.im < (S \u2022 z).im :=\nbegin\n  have : z.im < z.im / norm_sq (z:\u2102),\n  { have imz : 0 < z.im := im_pos z,\n    apply (lt_div_iff z.norm_sq_pos).mpr,\n    nlinarith },\n  convert this,\n  simp only [special_linear_group.im_smul_eq_div_norm_sq],\n  field_simp [norm_sq_denom_ne_zero, norm_sq_ne_zero, S]\nend\n\n/-- The standard (closed) fundamental domain of the action of `SL(2,\u2124)` on `\u210d`. -/\ndef fd : set \u210d :=\n{z | 1 \u2264 (z : \u2102).norm_sq \u2227 |z.re| \u2264 (1 : \u211d) / 2}\n\n/-- The standard open fundamental domain of the action of `SL(2,\u2124)` on `\u210d`. -/\ndef fdo : set \u210d :=\n{z | 1 < (z : \u2102).norm_sq \u2227 |z.re| < (1 : \u211d) / 2}\n\nlocalized \"notation `\ud835\udc9f` := modular_group.fd\" in modular\n\nlocalized \"notation `\ud835\udc9f\u1d52` := modular_group.fdo\" in modular\n\nlemma abs_two_mul_re_lt_one_of_mem_fdo (h : z \u2208 \ud835\udc9f\u1d52) : |2 * z.re| < 1 :=\nbegin\n  rw [abs_mul, abs_two, \u2190 lt_div_iff' (@two_pos \u211d _ _)],\n  exact h.2,\nend\n\nlemma three_lt_four_mul_im_sq_of_mem_fdo (h : z \u2208 \ud835\udc9f\u1d52) : 3 < 4 * z.im^2 :=\nbegin\n  have : 1 < z.re * z.re + z.im * z.im := by simpa [complex.norm_sq_apply] using h.1,\n  have := h.2,\n  cases abs_cases z.re;\n  nlinarith,\nend\n\n/-- If `z \u2208 \ud835\udc9f\u1d52`, and `n : \u2124`, then `|z + n| > 1`. -/\nlemma one_lt_norm_sq_T_zpow_smul (hz : z \u2208 \ud835\udc9f\u1d52) (n : \u2124) : 1 < norm_sq (((T^n) \u2022 z) : \u210d) :=\nbegin\n  have hz\u2081 : 1 < z.re * z.re + z.im * z.im := hz.1,\n  have hzn := int.nneg_mul_add_sq_of_abs_le_one n (abs_two_mul_re_lt_one_of_mem_fdo hz).le,\n  have : 1 < (z.re + \u2191n) * (z.re + \u2191n) + z.im * z.im, { linarith, },\n  simpa [coe_T_zpow, norm_sq],\nend\n\nlemma eq_zero_of_mem_fdo_of_T_zpow_mem_fdo {n : \u2124} (hz : z \u2208 \ud835\udc9f\u1d52) (hg : (T^n) \u2022 z \u2208 \ud835\udc9f\u1d52) : n = 0 :=\nbegin\n  suffices : |(n : \u211d)| < 1,\n  { rwa [\u2190 int.cast_abs, \u2190 int.cast_one, int.cast_lt, int.abs_lt_one_iff] at this, },\n  have h\u2081 := hz.2,\n  have h\u2082 := hg.2,\n  rw [\u2190 coe_re, coe_T_zpow_smul_eq, add_re, int_cast_re, coe_re] at h\u2082,\n  calc |(n : \u211d)| \u2264 |z.re| + |z.re + (n : \u211d)| : abs_add' (n : \u211d) z.re\n             ... < 1/2 + 1/2 : add_lt_add h\u2081 h\u2082\n             ... = 1 : add_halves 1,\nend\n\n/-- Any `z : \u210d` can be moved to `\ud835\udc9f` by an element of `SL(2,\u2124)`  -/\nlemma exists_smul_mem_fd (z : \u210d) : \u2203 g : SL(2,\u2124), g \u2022 z \u2208 \ud835\udc9f :=\nbegin\n  -- obtain a g\u2080 which maximizes im (g \u2022 z),\n  obtain \u27e8g\u2080, hg\u2080\u27e9 := exists_max_im z,\n  -- then among those, minimize re\n  obtain \u27e8g, hg, hg'\u27e9 := exists_row_one_eq_and_min_re z (bottom_row_coprime g\u2080),\n  refine \u27e8g, _\u27e9,\n  -- `g` has same max im property as `g\u2080`\n  have hg\u2080' : \u2200 (g' : SL(2,\u2124)), (g' \u2022 z).im \u2264 (g \u2022 z).im,\n  { have hg'' : (g \u2022 z).im = (g\u2080 \u2022 z).im,\n    { rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq,\n      denom_apply, denom_apply, hg]},\n    simpa only [hg''] using hg\u2080 },\n  split,\n  { -- Claim: `1 \u2264 \u21d1norm_sq \u2191(g \u2022 z)`. If not, then `S\u2022g\u2022z` has larger imaginary part\n    contrapose! hg\u2080',\n    refine \u27e8S * g, _\u27e9,\n    rw mul_action.mul_smul,\n    exact im_lt_im_S_smul hg\u2080' },\n  { show |(g \u2022 z).re| \u2264 1 / 2, -- if not, then either `T` or `T'` decrease |Re|.\n    rw abs_le,\n    split,\n    { contrapose! hg',\n      refine \u27e8T * g, by simp [T, matrix.mul, matrix.dot_product, fin.sum_univ_succ], _\u27e9,\n      rw mul_action.mul_smul,\n      have : |(g \u2022 z).re + 1| < |(g \u2022 z).re| :=\n        by cases abs_cases ((g \u2022 z).re + 1); cases abs_cases (g \u2022 z).re; linarith,\n      convert this,\n      simp [T] },\n    { contrapose! hg',\n      refine \u27e8T\u207b\u00b9 * g, by simp [coe_T_inv, matrix.mul, matrix.dot_product, fin.sum_univ_succ], _\u27e9,\n      rw mul_action.mul_smul,\n      have : |(g \u2022 z).re - 1| < |(g \u2022 z).re| :=\n        by cases abs_cases ((g \u2022 z).re - 1); cases abs_cases (g \u2022 z).re; linarith,\n      convert this,\n      simp [coe_T_inv, sub_eq_add_neg] } }\nend\n\nsection unique_representative\n\nvariables {z}\n\n/-- An auxiliary result en route to `modular_group.c_eq_zero`. -/\nlemma abs_c_le_one (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : |\u2191\u2098g 1 0| \u2264 1 :=\nbegin\n  let c' : \u2124 := \u2191\u2098g 1 0,\n  let c : \u211d := (c' : \u211d),\n  suffices : 3 * c^2 < 4,\n  { rw [\u2190 int.cast_pow, \u2190 int.cast_three, \u2190 int.cast_four, \u2190 int.cast_mul, int.cast_lt] at this,\n    replace this : c' ^ 2 \u2264 1 ^ 2, { linarith, },\n    rwa [sq_le_sq, abs_one] at this },\n  suffices : c \u2260 0 \u2192 9 * c^4 < 16,\n  { rcases eq_or_ne c 0 with hc | hc,\n    { rw hc, norm_num, },\n    { refine (abs_lt_of_sq_lt_sq' _ (by norm_num)).2,\n      specialize this hc,\n      linarith, }, },\n  intros hc,\n  replace hc : 0 < c^4, { rw pow_bit0_pos_iff; trivial, },\n  have h\u2081 := mul_lt_mul_of_pos_right (mul_lt_mul'' (three_lt_four_mul_im_sq_of_mem_fdo hg)\n      (three_lt_four_mul_im_sq_of_mem_fdo hz) (by linarith) (by linarith)) hc,\n  have h\u2082 : (c * z.im) ^ 4 / norm_sq (denom \u2191g z) ^ 2 \u2264 1 :=\n    div_le_one_of_le (pow_four_le_pow_two_of_pow_two_le\n      (upper_half_plane.c_mul_im_sq_le_norm_sq_denom z g)) (sq_nonneg _),\n  let nsq := norm_sq (denom g z),\n  calc 9 * c^4 < c^4 * z.im^2 * (g \u2022 z).im^2 * 16 : by linarith\n           ... = c^4 * z.im^4 / nsq^2 * 16 : by { rw [special_linear_group.im_smul_eq_div_norm_sq,\n            div_pow], ring, }\n           ... \u2264 16 : by { rw \u2190 mul_pow, linarith, },\nend\n\n/-- An auxiliary result en route to `modular_group.eq_smul_self_of_mem_fdo_mem_fdo`. -/\nlemma c_eq_zero (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : \u2191\u2098g 1 0 = 0 :=\nbegin\n  have hp : \u2200 {g' : SL(2, \u2124)} (hg' : g' \u2022 z \u2208 \ud835\udc9f\u1d52), \u2191\u2098g' 1 0 \u2260 1,\n  { intros,\n    by_contra hc,\n    let a := \u2191\u2098g' 0 0,\n    let d := \u2191\u2098g' 1 1,\n    have had : T^(-a) * g' = S * T^d, { rw g_eq_of_c_eq_one hc, group, },\n    let w := T^(-a) \u2022 (g' \u2022 z),\n    have h\u2081 : w = S \u2022 (T^d \u2022 z), { simp only [w, \u2190 mul_smul, had], },\n    replace h\u2081 : norm_sq w < 1 := h\u2081.symm \u25b8 norm_sq_S_smul_lt_one (one_lt_norm_sq_T_zpow_smul hz d),\n    have h\u2082 : 1 < norm_sq w := one_lt_norm_sq_T_zpow_smul hg' (-a),\n    linarith, },\n  have hn : \u2191\u2098g 1 0 \u2260 -1,\n  { intros hc,\n    replace hc : \u2191\u2098(-g) 1 0 = 1, { simp [eq_neg_of_eq_neg hc], },\n    replace hg : (-g) \u2022 z \u2208 \ud835\udc9f\u1d52 := (SL_neg_smul g z).symm \u25b8 hg,\n    exact hp hg hc, },\n  specialize hp hg,\n  rcases (int.abs_le_one_iff.mp $ abs_c_le_one hz hg);\n  tauto,\nend\n\n/-- Second Main Fundamental Domain Lemma: if both `z` and `g \u2022 z` are in the open domain `\ud835\udc9f\u1d52`,\nwhere `z : \u210d` and `g : SL(2,\u2124)`, then `z = g \u2022 z`. -/\nlemma eq_smul_self_of_mem_fdo_mem_fdo (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : z = g \u2022 z :=\nbegin\n  obtain \u27e8n, hn\u27e9 := exists_eq_T_zpow_of_c_eq_zero (c_eq_zero hz hg),\n  rw hn at hg \u22a2,\n  simp [eq_zero_of_mem_fdo_of_T_zpow_mem_fdo hz hg, one_smul],\nend\n\nend unique_representative\n\nend fundamental_domain\n\nend modular_group\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/number_theory/modular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7103054605877226}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Kevin Buzzard\n\n! This file was ported from Lean 3 source module ring_theory.noetherian\n! leanprover-community/mathlib commit da420a8c6dd5bdfb85c4ced85c34388f633bc6ff\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Algebra.Subalgebra.Basic\nimport Mathlib.Algebra.Algebra.Tower\nimport Mathlib.Algebra.Ring.Idempotents\nimport Mathlib.GroupTheory.Finiteness\nimport Mathlib.LinearAlgebra.LinearIndependent\nimport Mathlib.Order.CompactlyGenerated\nimport Mathlib.Order.OrderIsoNat\nimport Mathlib.RingTheory.Finiteness\nimport Mathlib.RingTheory.Nilpotent\n\n/-!\n# Noetherian rings and modules\n\nThe following are equivalent for a module M over a ring R:\n1. Every increasing chain of submodules M\u2081 \u2286 M\u2082 \u2286 M\u2083 \u2286 \u22ef eventually stabilises.\n2. Every submodule is finitely generated.\n\nA module satisfying these equivalent conditions is said to be a *Noetherian* R-module.\nA ring is a *Noetherian ring* if it is Noetherian as a module over itself.\n\n(Note that we do not assume yet that our rings are commutative,\nso perhaps this should be called \"left Noetherian\".\nTo avoid cumbersome names once we specialize to the commutative case,\nwe don't make this explicit in the declaration names.)\n\n## Main definitions\n\nLet `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`.\n\n* `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class,\n  implemented as the predicate that all `R`-submodules of `M` are finitely generated.\n\n## Main statements\n\n* `isNoetherian_iff_wellFounded` is the theorem that an R-module M is Noetherian iff\n  `>` is well-founded on `Submodule R M`.\n\nNote that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X],\nis proved in `RingTheory.Polynomial`.\n\n## References\n\n* [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald]\n* [samuel1967]\n\n## Tags\n\nNoetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module\n\n-/\n\n\nopen Set\n\nopen BigOperators Pointwise\n\n/-- `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module,\nimplemented as the predicate that all `R`-submodules of `M` are finitely generated.\n-/\n-- Porting note: should this be renamed to `Noetherian`?\nclass IsNoetherian (R M) [Semiring R] [AddCommMonoid M] [Module R M] : Prop where\n  noetherian : \u2200 s : Submodule R M, s.Fg\n#align is_noetherian IsNoetherian\n\nattribute [inherit_doc IsNoetherian] IsNoetherian.noetherian\n\nsection\n\nvariable {R : Type _} {M : Type _} {P : Type _}\n\nvariable [Semiring R] [AddCommMonoid M] [AddCommMonoid P]\n\nvariable [Module R M] [Module R P]\n\nopen IsNoetherian\n\n/-- An R-module is Noetherian iff all its submodules are finitely-generated. -/\ntheorem isNoetherian_def : IsNoetherian R M \u2194 \u2200 s : Submodule R M, s.Fg :=\n  \u27e8fun h => h.noetherian, IsNoetherian.mk\u27e9\n#align is_noetherian_def isNoetherian_def\n\ntheorem isNoetherian_submodule {N : Submodule R M} :\n    IsNoetherian R N \u2194 \u2200 s : Submodule R M, s \u2264 N \u2192 s.Fg := by\n  refine \u27e8fun \u27e8hn\u27e9 => fun s hs =>\n    have : s \u2264 LinearMap.range N.subtype := N.range_subtype.symm \u25b8 hs\n    Submodule.map_comap_eq_self this \u25b8 (hn _).map _,\n    fun h => \u27e8fun s => ?_\u27e9\u27e9\n  have f := (Submodule.equivMapOfInjective N.subtype Subtype.val_injective s).symm\n  have h\u2081 := h (s.map N.subtype) (Submodule.map_subtype_le N s)\n  have h\u2082 : (\u22a4 : Submodule R (s.map N.subtype)).map f = \u22a4 := by simp\n  have h\u2083 := ((Submodule.fg_top _).2 h\u2081).map (\u2191f : _ \u2192\u2097[R] s)\n  exact (Submodule.fg_top _).1 (h\u2082 \u25b8 h\u2083)\n#align is_noetherian_submodule isNoetherian_submodule\n\ntheorem isNoetherian_submodule_left {N : Submodule R M} :\n    IsNoetherian R N \u2194 \u2200 s : Submodule R M, (N \u2293 s).Fg :=\n  isNoetherian_submodule.trans \u27e8fun H _ => H _ inf_le_left, fun H _ hs => inf_of_le_right hs \u25b8 H _\u27e9\n#align is_noetherian_submodule_left isNoetherian_submodule_left\n\ntheorem isNoetherian_submodule_right {N : Submodule R M} :\n    IsNoetherian R N \u2194 \u2200 s : Submodule R M, (s \u2293 N).Fg :=\n  isNoetherian_submodule.trans \u27e8fun H _ => H _ inf_le_right, fun H _ hs => inf_of_le_left hs \u25b8 H _\u27e9\n#align is_noetherian_submodule_right isNoetherian_submodule_right\n\ninstance isNoetherian_submodule' [IsNoetherian R M] (N : Submodule R M) : IsNoetherian R N :=\n  isNoetherian_submodule.2 fun _ _ => IsNoetherian.noetherian _\n#align is_noetherian_submodule' isNoetherian_submodule'\n\ntheorem isNoetherian_of_le {s t : Submodule R M} [ht : IsNoetherian R t] (h : s \u2264 t) :\n    IsNoetherian R s :=\n  isNoetherian_submodule.mpr fun _ hs' => isNoetherian_submodule.mp ht _ (le_trans hs' h)\n#align is_noetherian_of_le isNoetherian_of_le\n\nvariable (M)\n\ntheorem isNoetherian_of_surjective (f : M \u2192\u2097[R] P) (hf : LinearMap.range f = \u22a4) [IsNoetherian R M] :\n    IsNoetherian R P :=\n  \u27e8fun s =>\n    have : (s.comap f).map f = s := Submodule.map_comap_eq_self <| hf.symm \u25b8 le_top\n    this \u25b8 (noetherian _).map _\u27e9\n#align is_noetherian_of_surjective isNoetherian_of_surjective\n\nvariable {M}\n\ntheorem isNoetherian_of_linearEquiv (f : M \u2243\u2097[R] P) [IsNoetherian R M] : IsNoetherian R P :=\n  isNoetherian_of_surjective _ f.toLinearMap f.range\n#align is_noetherian_of_linear_equiv isNoetherian_of_linearEquiv\n\ntheorem isNoetherian_top_iff : IsNoetherian R (\u22a4 : Submodule R M) \u2194 IsNoetherian R M := by\n  constructor <;> intro h\n  \u00b7 exact isNoetherian_of_linearEquiv (LinearEquiv.ofTop (\u22a4 : Submodule R M) rfl)\n  \u00b7 exact isNoetherian_of_linearEquiv (LinearEquiv.ofTop (\u22a4 : Submodule R M) rfl).symm\n#align is_noetherian_top_iff isNoetherian_top_iff\n\ntheorem isNoetherian_of_injective [IsNoetherian R P] (f : M \u2192\u2097[R] P) (hf : Function.Injective f) :\n    IsNoetherian R M :=\n  isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f hf).symm\n#align is_noetherian_of_injective isNoetherian_of_injective\n\ntheorem fg_of_injective [IsNoetherian R P] {N : Submodule R M} (f : M \u2192\u2097[R] P)\n    (hf : Function.Injective f) : N.Fg :=\n  haveI := isNoetherian_of_injective f hf\n  IsNoetherian.noetherian N\n#align fg_of_injective fg_of_injective\n\nend\n\nnamespace Module\n\nvariable {R M N : Type _}\n\nvariable [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]\n\nvariable (R M)\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsNoetherian.finite [IsNoetherian R M] : Finite R M :=\n  \u27e8IsNoetherian.noetherian \u22a4\u27e9\n#align module.is_noetherian.finite Module.IsNoetherian.finite\n\nvariable {R M}\n\ntheorem Finite.of_injective [IsNoetherian R N] (f : M \u2192\u2097[R] N) (hf : Function.Injective f) :\n    Finite R M :=\n  \u27e8fg_of_injective f hf\u27e9\n#align module.finite.of_injective Module.Finite.of_injective\n\nend Module\n\nsection\n\nvariable {R : Type _} {M : Type _} {P : Type _}\n\nvariable [Ring R] [AddCommGroup M] [AddCommGroup P]\n\nvariable [Module R M] [Module R P]\n\nopen IsNoetherian\n\nset_option synthInstance.etaExperiment true in\ntheorem isNoetherian_of_ker_bot [IsNoetherian R P] (f : M \u2192\u2097[R] P) (hf : LinearMap.ker f = \u22a5) :\n    IsNoetherian R M :=\n  isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f <| LinearMap.ker_eq_bot.mp hf).symm\n#align is_noetherian_of_ker_bot isNoetherian_of_ker_bot\n\nset_option synthInstance.etaExperiment true in\ntheorem fg_of_ker_bot [IsNoetherian R P] {N : Submodule R M} (f : M \u2192\u2097[R] P)\n    (hf : LinearMap.ker f = \u22a5) : N.Fg :=\n  haveI := isNoetherian_of_ker_bot f hf\n  IsNoetherian.noetherian N\n#align fg_of_ker_bot fg_of_ker_bot\n\ninstance isNoetherian_prod [IsNoetherian R M] [IsNoetherian R P] : IsNoetherian R (M \u00d7 P) :=\n  \u27e8fun s =>\n    Submodule.fg_of_fg_map_of_fg_inf_ker (LinearMap.snd R M P) (noetherian _) <|\n      have : s \u2293 LinearMap.ker (LinearMap.snd R M P) \u2264 LinearMap.range (LinearMap.inl R M P) :=\n        fun x \u27e8_, hx2\u27e9 => \u27e8x.1, Prod.ext rfl <| Eq.symm <| LinearMap.mem_ker.1 hx2\u27e9\n      Submodule.map_comap_eq_self this \u25b8 (noetherian _).map _\u27e9\n#align is_noetherian_prod isNoetherian_prod\n\ninstance isNoetherian_pi {R \u03b9 : Type _} {M : \u03b9 \u2192 Type _}\n    [Ring R] [\u2200 i, AddCommGroup (M i)] [\u2200 i, Module R (M i)] [Finite \u03b9]\n    [\u2200 i, IsNoetherian R (M i)] : IsNoetherian R (\u2200 i, M i) := by\n  cases nonempty_fintype \u03b9\n  haveI := Classical.decEq \u03b9\n  suffices on_finset : \u2200 s : Finset \u03b9, IsNoetherian R (\u2200 i : s, M i)\n  \u00b7 let coe_e := Equiv.subtypeUnivEquiv <| @Finset.mem_univ \u03b9 _\n    letI : IsNoetherian R (\u2200 i : Finset.univ, M (coe_e i)) := on_finset Finset.univ\n    exact isNoetherian_of_linearEquiv (LinearEquiv.piCongrLeft R M coe_e)\n  intro s\n  induction' s using Finset.induction with a s has ih\n  \u00b7 exact \u27e8fun s => by\n      have : s = \u22a5 := by simp only [eq_iff_true_of_subsingleton]\n      rw [this]\n      apply Submodule.fg_bot\u27e9\n  refine\n    @isNoetherian_of_linearEquiv R (M a \u00d7 ((i : s) \u2192 M i)) _ _ _ _ _ _ ?_ <|\n      @isNoetherian_prod R (M a) _ _ _ _ _ _ _ ih\n  refine\n  { toFun := fun f i =>\n      (Finset.mem_insert.1 i.2).by_cases\n        (fun h : i.1 = a => show M i.1 from Eq.recOn h.symm f.1)\n        (fun h : i.1 \u2208 s => show M i.1 from f.2 \u27e8i.1, h\u27e9),\n    invFun := fun f =>\n      (f \u27e8a, Finset.mem_insert_self _ _\u27e9, fun i => f \u27e8i.1, Finset.mem_insert_of_mem i.2\u27e9),\n    map_add' := ?_,\n    map_smul' := ?_\n    left_inv := ?_,\n    right_inv := ?_ }\n  \u00b7 intro f g\n    ext i\n    unfold Or.by_cases\n    cases' i with i hi\n    rcases Finset.mem_insert.1 hi with (rfl | h)\n    \u00b7 change _ = _ + _\n      simp only [dif_pos]\n      rfl\n    \u00b7 change _ = _ + _\n      have : \u00aci = a := by\n        rintro rfl\n        exact has h\n      simp only [dif_neg this, dif_pos h]\n      rfl\n  \u00b7 intro c f\n    ext i\n    unfold Or.by_cases\n    cases' i with i hi\n    rcases Finset.mem_insert.1 hi with (rfl | h)\n    \u00b7 dsimp\n      simp only [dif_pos]\n    \u00b7 dsimp\n      have : \u00aci = a := by\n        rintro rfl\n        exact has h\n      simp only [dif_neg this, dif_pos h]\n  \u00b7 intro f\n    apply Prod.ext\n    \u00b7 simp only [Or.by_cases, dif_pos]\n    \u00b7 ext \u27e8i, his\u27e9\n      have : \u00aci = a := by\n        rintro rfl\n        exact has his\n      simp only [Or.by_cases, this, not_false_iff, dif_neg]\n  \u00b7 intro f\n    ext \u27e8i, hi\u27e9\n    rcases Finset.mem_insert.1 hi with (rfl | h)\n    \u00b7 simp only [Or.by_cases, dif_pos]\n    \u00b7 have : \u00aci = a := by\n        rintro rfl\n        exact has h\n      simp only [Or.by_cases, dif_neg this, dif_pos h]\n#align is_noetherian_pi isNoetherian_pi\n\n/-- A version of `isNoetherian_pi` for non-dependent functions. We need this instance because\nsometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to\nprove that `\u03b9 \u2192 \u211d` is finite dimensional over `\u211d`). -/\ninstance isNoetherian_pi' {R \u03b9 M : Type _} [Ring R] [AddCommGroup M] [Module R M] [Finite \u03b9]\n    [IsNoetherian R M] : IsNoetherian R (\u03b9 \u2192 M) :=\n  isNoetherian_pi\n#align is_noetherian_pi' isNoetherian_pi'\n\nend\n\nopen IsNoetherian Submodule Function\n\nsection\n\nuniverse w\n\nvariable {R M P : Type _} {N : Type w} [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N]\n  [Module R N] [AddCommMonoid P] [Module R P]\n\ntheorem isNoetherian_iff_wellFounded :\n    IsNoetherian R M \u2194 WellFounded ((\u00b7 > \u00b7) : Submodule R M \u2192 Submodule R M \u2192 Prop) := by\n  have := (CompleteLattice.wellFounded_characterisations <| Submodule R M).out 0 3\n  -- Porting note: inlining this makes rw complain about it being a metavariable\n  rw [this]\n  exact\n    \u27e8fun \u27e8h\u27e9 => fun k => (fg_iff_compact k).mp (h k), fun h =>\n      \u27e8fun k => (fg_iff_compact k).mpr (h k)\u27e9\u27e9\n#align is_noetherian_iff_well_founded isNoetherian_iff_wellFounded\n\ntheorem isNoetherian_iff_fg_wellFounded :\n    IsNoetherian R M \u2194\n      WellFounded\n        ((\u00b7 > \u00b7) : { N : Submodule R M // N.Fg } \u2192 { N : Submodule R M // N.Fg } \u2192 Prop) := by\n  let \u03b1 := { N : Submodule R M // N.Fg }\n  constructor\n  \u00b7 intro H\n    let f : \u03b1 \u21aao Submodule R M := OrderEmbedding.subtype _\n    exact OrderEmbedding.wellFounded f.dual (isNoetherian_iff_wellFounded.mp H)\n  \u00b7 intro H\n    constructor\n    intro N\n    obtain \u27e8\u27e8N\u2080, h\u2081\u27e9, e : N\u2080 \u2264 N, h\u2082\u27e9 :=\n      WellFounded.wellFounded_iff_has_max'.mp H { N' : \u03b1 | N'.1 \u2264 N }\n        \u27e8\u27e8\u22a5, Submodule.fg_bot\u27e9, @bot_le _ _ _ N\u27e9\n    convert h\u2081\n    refine' (e.antisymm _).symm\n    by_contra h\u2083\n    obtain \u27e8x, hx\u2081 : x \u2208 N, hx\u2082 : x \u2209 N\u2080\u27e9 := Set.not_subset.mp h\u2083\n    apply hx\u2082\n    have := h\u2082 \u27e8(R \u2219 x) \u2294 N\u2080, ?_\u27e9 ?_ ?_\n    \u00b7 injection this with eq\n      rw [\u2190 eq]\n      exact (le_sup_left : (R \u2219 x) \u2264 (R \u2219 x) \u2294 N\u2080) (Submodule.mem_span_singleton_self _)\n    \u00b7 exact Submodule.Fg.sup \u27e8{x}, by rw [Finset.coe_singleton]\u27e9 h\u2081\n    \u00b7 exact sup_le ((Submodule.span_singleton_le_iff_mem _ _).mpr hx\u2081) e\n    \u00b7 show N\u2080 \u2264 (R \u2219 x) \u2294 N\u2080\n      exact le_sup_right\n#align is_noetherian_iff_fg_well_founded isNoetherian_iff_fg_wellFounded\n\nvariable (R M)\n\ntheorem wellFounded_submodule_gt (R M) [Semiring R] [AddCommMonoid M] [Module R M] :\n    \u2200 [IsNoetherian R M], WellFounded ((\u00b7 > \u00b7) : Submodule R M \u2192 Submodule R M \u2192 Prop) :=\n  isNoetherian_iff_wellFounded.mp \u2039_\u203a\n#align well_founded_submodule_gt wellFounded_submodule_gt\n\nvariable {R M}\n\n/-- A module is Noetherian iff every nonempty set of submodules has a maximal submodule among them.\n-/\ntheorem set_has_maximal_iff_noetherian :\n    (\u2200 a : Set <| Submodule R M, a.Nonempty \u2192 \u2203 M' \u2208 a, \u2200 I \u2208 a, M' \u2264 I \u2192 I = M') \u2194\n      IsNoetherian R M :=\n  by rw [isNoetherian_iff_wellFounded, WellFounded.wellFounded_iff_has_max']\n#align set_has_maximal_iff_noetherian set_has_maximal_iff_noetherian\n\n/-- A module is Noetherian iff every increasing chain of submodules stabilizes. -/\ntheorem monotone_stabilizes_iff_noetherian :\n    (\u2200 f : \u2115 \u2192o Submodule R M, \u2203 n, \u2200 m, n \u2264 m \u2192 f n = f m) \u2194 IsNoetherian R M := by\n  rw [isNoetherian_iff_wellFounded, WellFounded.monotone_chain_condition]\n#align monotone_stabilizes_iff_noetherian monotone_stabilizes_iff_noetherian\n\n/-- If `\u2200 I > J, P I` implies `P J`, then `P` holds for all submodules. -/\ntheorem IsNoetherian.induction [IsNoetherian R M] {P : Submodule R M \u2192 Prop}\n    (hgt : \u2200 I, (\u2200 J > I, P J) \u2192 P I) (I : Submodule R M) : P I :=\n  WellFounded.recursion (wellFounded_submodule_gt R M) I hgt\n#align is_noetherian.induction IsNoetherian.induction\n\nend\n\nsection\n\nuniverse w\n\nvariable {R M P : Type _} {N : Type w} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N]\n  [Module R N] [AddCommGroup P] [Module R P]\n\ntheorem finite_of_linearIndependent [Nontrivial R] [IsNoetherian R M] {s : Set M}\n    (hs : LinearIndependent R ((\u2191) : s \u2192 M)) : s.Finite := by\n  refine'\n    by_contradiction fun hf =>\n      (RelEmbedding.wellFounded_iff_no_descending_seq.1 (wellFounded_submodule_gt R M)).elim' _\n  have f : \u2115 \u21aa s := Set.Infinite.natEmbedding s hf\n  have : \u2200 n, (\u2191) \u2218 f '' { m | m \u2264 n } \u2286 s := by\n    rintro n x \u27e8y, _, rfl\u27e9\n    exact (f y).2\n  let coe' : s \u2192 M := (\u2191)\n  have : \u2200 a b : \u2115, a \u2264 b \u2194\n    span R (coe' \u2218 f '' { m | m \u2264 a }) \u2264 span R ((\u2191) \u2218 f '' { m | m \u2264 b }) := by\n    intro a b\n    rw [span_le_span_iff hs (this a) (this b),\n      Set.image_subset_image_iff (Subtype.coe_injective.comp f.injective), Set.subset_def]\n    exact \u27e8fun hab x (hxa : x \u2264 a) => le_trans hxa hab, fun hx => hx a (le_refl a)\u27e9\n  exact\n    \u27e8\u27e8fun n => span R (coe' \u2218 f '' { m | m \u2264 n }), fun x y => by\n        rw [le_antisymm_iff, (this x y).symm, (this y x).symm, \u2190le_antisymm_iff, imp_self]\n        trivial\u27e9,\n      by dsimp [GT.gt]; simp only [lt_iff_le_not_le, (this _ _).symm]; tauto\u27e9\n#align finite_of_linear_independent finite_of_linearIndependent\n\nset_option synthInstance.etaExperiment true in\n/-- If the first and final modules in a short exact sequence are Noetherian,\n  then the middle module is also Noetherian. -/\ntheorem isNoetherian_of_range_eq_ker [IsNoetherian R M] [IsNoetherian R P] (f : M \u2192\u2097[R] N)\n    (g : N \u2192\u2097[R] P) (hf : Function.Injective f) (hg : Function.Surjective g)\n    (h : LinearMap.range f = LinearMap.ker g) :\n    IsNoetherian R N :=\n  isNoetherian_iff_wellFounded.2 <|\n    wellFounded_gt_exact_sequence (wellFounded_submodule_gt R M) (wellFounded_submodule_gt R P)\n      (LinearMap.range f) (Submodule.map f) (Submodule.comap f) (Submodule.comap g)\n      (Submodule.map g) (Submodule.gciMapComap hf) (Submodule.giMapComap hg)\n      (by simp [Submodule.map_comap_eq, inf_comm]) (by simp [Submodule.comap_map_eq, h])\n#align is_noetherian_of_range_eq_ker isNoetherian_of_range_eq_ker\n\n/- Porting note (lean4#2074): this seems to cause a diamond with Ring.toSemiring when going to\nNonAssocSemiring -/\nattribute [-instance] Ring.toNonAssocRing\n\n/-- For any endomorphism of a Noetherian module, there is some nontrivial iterate\nwith disjoint kernel and range.\n-/\ntheorem IsNoetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot [I : IsNoetherian R M]\n    (f : M \u2192\u2097[R] M) :\n    \u2203 n : \u2115, n \u2260 0 \u2227 LinearMap.ker (f ^ n) \u2293 LinearMap.range (f ^ n) = \u22a5 := by\n  obtain \u27e8n, w\u27e9 :=\n    monotone_stabilizes_iff_noetherian.mpr I\n      (f.iterateKer.comp \u27e8fun n => n + 1, fun n m w => by linarith\u27e9)\n  specialize w (2 * n + 1) (by linarith only)\n  dsimp at w\n  refine' \u27e8n + 1, Nat.succ_ne_zero _, _\u27e9\n  rw [eq_bot_iff]\n  rintro - \u27e8h, \u27e8y, rfl\u27e9\u27e9\n  rw [mem_bot, \u2190 LinearMap.mem_ker, w]\n  erw [LinearMap.mem_ker] at h\u22a2\n  change (f ^ (n + 1) * f ^ (n + 1)) y = 0 at h\n  rw [\u2190 pow_add] at h\n  convert h using 3\n  ring\n#align is_noetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot IsNoetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot\n\n/-- Any surjective endomorphism of a Noetherian module is injective. -/\ntheorem IsNoetherian.injective_of_surjective_endomorphism [IsNoetherian R M] (f : M \u2192\u2097[R] M)\n    (s : Surjective f) : Injective f := by\n  obtain \u27e8n, ne, w\u27e9 := IsNoetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot f\n  rw [LinearMap.range_eq_top.mpr (LinearMap.iterate_surjective s n), inf_top_eq,\n    LinearMap.ker_eq_bot] at w\n  exact LinearMap.injective_of_iterate_injective ne w\n#align is_noetherian.injective_of_surjective_endomorphism IsNoetherian.injective_of_surjective_endomorphism\n\n/-- Any surjective endomorphism of a Noetherian module is bijective. -/\ntheorem IsNoetherian.bijective_of_surjective_endomorphism [IsNoetherian R M] (f : M \u2192\u2097[R] M)\n    (s : Surjective f) : Bijective f :=\n  \u27e8IsNoetherian.injective_of_surjective_endomorphism f s, s\u27e9\n#align is_noetherian.bijective_of_surjective_endomorphism IsNoetherian.bijective_of_surjective_endomorphism\n\n/-- A sequence `f` of submodules of a noetherian module,\nwith `f (n+1)` disjoint from the supremum of `f 0`, ..., `f n`,\nis eventually zero.\n-/\ntheorem IsNoetherian.disjoint_partialSups_eventually_bot [I : IsNoetherian R M]\n    (f : \u2115 \u2192 Submodule R M) (h : \u2200 n, Disjoint (partialSups f n) (f (n + 1))) :\n    \u2203 n : \u2115, \u2200 m, n \u2264 m \u2192 f m = \u22a5 := by\n  -- A little off-by-one cleanup first:\n  suffices t : \u2203 n : \u2115, \u2200 m, n \u2264 m \u2192 f (m + 1) = \u22a5\n  \u00b7 obtain \u27e8n, w\u27e9 := t\n    use n + 1\n    rintro (_ | m) p\n    \u00b7 cases p\n    \u00b7 apply w\n      exact Nat.succ_le_succ_iff.mp p\n  obtain \u27e8n, w\u27e9 := monotone_stabilizes_iff_noetherian.mpr I (partialSups f)\n  exact\n    \u27e8n, fun m p =>\n      (h m).eq_bot_of_ge <| sup_eq_left.1 <| (w (m + 1) <| le_add_right p).symm.trans <| w m p\u27e9\n#align is_noetherian.disjoint_partial_sups_eventually_bot IsNoetherian.disjoint_partialSups_eventually_bot\n\n/-- If `M \u2295 N` embeds into `M`, for `M` noetherian over `R`, then `N` is trivial.\n-/\nnoncomputable def IsNoetherian.equivPunitOfProdInjective [IsNoetherian R M] (f : M \u00d7 N \u2192\u2097[R] M)\n    (i : Injective f) : N \u2243\u2097[R] PUnit.{w + 1} := by\n  apply Nonempty.some\n  obtain \u27e8n, w\u27e9 :=\n    IsNoetherian.disjoint_partialSups_eventually_bot (f.tailing i) (f.tailings_disjoint_tailing i)\n  specialize w n (le_refl n)\n  apply Nonempty.intro\n  -- Porting note: refine' makes this line time out at elaborator\n  refine (LinearMap.tailingLinearEquiv f i n).symm \u226a\u226b\u2097 ?_\n  rw [w]\n  exact Submodule.botEquivPUnit\n#align is_noetherian.equiv_punit_of_prod_injective IsNoetherian.equivPunitOfProdInjective\n\nend\n\n/-- A (semi)ring is Noetherian if it is Noetherian as a module over itself,\ni.e. all its ideals are finitely generated.\n-/\n@[reducible]\ndef IsNoetherianRing (R) [Semiring R] :=\n  IsNoetherian R R\n#align is_noetherian_ring IsNoetherianRing\n\ntheorem isNoetherianRing_iff {R} [Semiring R] : IsNoetherianRing R \u2194 IsNoetherian R R :=\n  Iff.rfl\n#align is_noetherian_ring_iff isNoetherianRing_iff\n\n/-- A ring is Noetherian if and only if all its ideals are finitely-generated. -/\ntheorem isNoetherianRing_iff_ideal_fg (R : Type _) [Semiring R] :\n    IsNoetherianRing R \u2194 \u2200 I : Ideal R, I.Fg :=\n  isNoetherianRing_iff.trans isNoetherian_def\n#align is_noetherian_ring_iff_ideal_fg isNoetherianRing_iff_ideal_fg\n\n-- see Note [lower instance priority]\ninstance (priority := 80) isNoetherian_of_finite (R M) [Finite M] [Semiring R] [AddCommMonoid M]\n    [Module R M] : IsNoetherian R M :=\n  \u27e8fun s => \u27e8(s : Set M).toFinite.toFinset, by rw [Set.Finite.coe_toFinset, Submodule.span_eq]\u27e9\u27e9\n#align is_noetherian_of_finite isNoetherian_of_finite\n\n-- see Note [lower instance priority]\n/-- Modules over the trivial ring are Noetherian. -/\ninstance (priority := 100) isNoetherian_of_subsingleton (R M) [Subsingleton R] [Semiring R]\n    [AddCommMonoid M] [Module R M] : IsNoetherian R M :=\n  haveI := Module.subsingleton R M\n  isNoetherian_of_finite R M\n#align is_noetherian_of_subsingleton isNoetherian_of_subsingleton\n\ntheorem isNoetherian_of_submodule_of_noetherian (R M) [Semiring R] [AddCommMonoid M] [Module R M]\n    (N : Submodule R M) (h : IsNoetherian R M) : IsNoetherian R N := by\n  rw [isNoetherian_iff_wellFounded] at h\u22a2\n  exact OrderEmbedding.wellFounded (Submodule.MapSubtype.orderEmbedding N).dual h\n#align is_noetherian_of_submodule_of_noetherian isNoetherian_of_submodule_of_noetherian\n\ninstance Submodule.Quotient.isNoetherian {R} [Ring R] {M} [AddCommGroup M] [Module R M]\n    (N : Submodule R M) [h : IsNoetherian R M] : IsNoetherian R (M \u29f8 N) := by\n  rw [isNoetherian_iff_wellFounded] at h\u22a2\n  exact OrderEmbedding.wellFounded (Submodule.comapMkQOrderEmbedding N).dual h\n#align submodule.quotient.is_noetherian Submodule.Quotient.isNoetherian\n\n/-- If `M / S / R` is a scalar tower, and `M / R` is Noetherian, then `M / S` is\nalso noetherian. -/\ntheorem isNoetherian_of_tower (R) {S M} [Semiring R] [Semiring S] [AddCommMonoid M] [SMul R S]\n    [Module S M] [Module R M] [IsScalarTower R S M] (h : IsNoetherian R M) : IsNoetherian S M := by\n  rw [isNoetherian_iff_wellFounded] at h\u22a2\n  refine' (Submodule.restrictScalarsEmbedding R S M).dual.wellFounded h\n#align is_noetherian_of_tower isNoetherian_of_tower\n\ntheorem isNoetherian_of_fg_of_noetherian {R M} [Ring R] [AddCommGroup M] [Module R M]\n    (N : Submodule R M) [I : IsNoetherianRing R] (hN : N.Fg) : IsNoetherian R N := by\n  let \u27e8s, hs\u27e9 := hN\n  haveI := Classical.decEq M\n  haveI := Classical.decEq R\n  -- Porting note: etaExperiment fixes inferInstance proof\n  letI : IsNoetherian R R := I\n  have : \u2200 x \u2208 s, x \u2208 N := fun x hx => hs \u25b8 Submodule.subset_span hx\n  refine\n    @isNoetherian_of_surjective\n      R ((\u2191s : Set M) \u2192 R) N _ _ _ (Pi.module _ _ _) _ ?_ ?_ isNoetherian_pi\n  \u00b7 fapply LinearMap.mk\n    \u00b7 fapply AddHom.mk\n      \u00b7 exact fun f => \u27e8\u2211 i in s.attach, f i \u2022 i.1, N.sum_mem fun c _ => N.smul_mem _ <| this _ c.2\u27e9\n      \u00b7 intro f g\n        apply Subtype.eq\n        change (\u2211 i in s.attach, (f i + g i) \u2022 _) = _\n        simp only [add_smul, Finset.sum_add_distrib]\n        rfl\n    \u00b7 intro c f\n      apply Subtype.eq\n      change (\u2211 i in s.attach, (c \u2022 f i) \u2022 _) = _\n      simp only [smul_eq_mul, mul_smul]\n      exact Finset.smul_sum.symm\n  \u00b7 rw [LinearMap.range_eq_top]\n    rintro \u27e8n, hn\u27e9\n    change n \u2208 N at hn\n    rw [\u2190 hs, \u2190 Set.image_id (s : Set M), Finsupp.mem_span_image_iff_total] at hn\n    rcases hn with \u27e8l, hl1, hl2\u27e9\n    refine' \u27e8fun x => l x, Subtype.ext _\u27e9\n    change (\u2211 i in s.attach, l i \u2022 (i : M)) = n\n    rw [@Finset.sum_attach M M s _ fun i => l i \u2022 i, \u2190 hl2,\n      Finsupp.total_apply, Finsupp.sum, eq_comm]\n    refine' Finset.sum_subset hl1 fun x _ hx => _\n    rw [Finsupp.not_mem_support_iff.1 hx, zero_smul]\n#align is_noetherian_of_fg_of_noetherian isNoetherian_of_fg_of_noetherian\n\ntheorem isNoetherian_of_fg_of_noetherian' {R M} [Ring R] [AddCommGroup M] [Module R M]\n    [IsNoetherianRing R] (h : (\u22a4 : Submodule R M).Fg) : IsNoetherian R M :=\n  have : IsNoetherian R (\u22a4 : Submodule R M) := isNoetherian_of_fg_of_noetherian _ h\n  isNoetherian_of_linearEquiv (LinearEquiv.ofTop (\u22a4 : Submodule R M) rfl)\n#align is_noetherian_of_fg_of_noetherian' isNoetherian_of_fg_of_noetherian'\n\n/-- In a module over a Noetherian ring, the submodule generated by finitely many vectors is\nNoetherian. -/\ntheorem isNoetherian_span_of_finite (R) {M} [Ring R] [AddCommGroup M] [Module R M]\n    [IsNoetherianRing R] {A : Set M} (hA : A.Finite) : IsNoetherian R (Submodule.span R A) :=\n  isNoetherian_of_fg_of_noetherian _ (Submodule.fg_def.mpr \u27e8A, hA, rfl\u27e9)\n#align is_noetherian_span_of_finite isNoetherian_span_of_finite\n\nset_option synthInstance.etaExperiment true in\ntheorem isNoetherianRing_of_surjective (R) [Ring R] (S) [Ring S] (f : R \u2192+* S)\n    (hf : Function.Surjective f) [H : IsNoetherianRing R] : IsNoetherianRing S := by\n  rw [isNoetherianRing_iff, isNoetherian_iff_wellFounded] at H\u22a2\n  exact OrderEmbedding.wellFounded (Ideal.orderEmbeddingOfSurjective f hf).dual H\n#align is_noetherian_ring_of_surjective isNoetherianRing_of_surjective\n\ninstance isNoetherianRing_range {R} [Ring R] {S} [Ring S] (f : R \u2192+* S) [IsNoetherianRing R] :\n    IsNoetherianRing f.range :=\n  isNoetherianRing_of_surjective R f.range f.rangeRestrict f.rangeRestrict_surjective\n#align is_noetherian_ring_range isNoetherianRing_range\n\ntheorem isNoetherianRing_of_ringEquiv (R) [Ring R] {S} [Ring S] (f : R \u2243+* S) [IsNoetherianRing R] :\n    IsNoetherianRing S :=\n  isNoetherianRing_of_surjective R S f.toRingHom f.toEquiv.surjective\n#align is_noetherian_ring_of_ring_equiv isNoetherianRing_of_ringEquiv\n\ntheorem IsNoetherianRing.isNilpotent_nilradical (R : Type _) [CommRing R] [IsNoetherianRing R] :\n    IsNilpotent (nilradical R) := by\n  obtain \u27e8n, hn\u27e9 := Ideal.exists_radical_pow_le_of_fg (\u22a5 : Ideal R) (IsNoetherian.noetherian _)\n  exact \u27e8n, eq_bot_iff.mpr hn\u27e9\n#align is_noetherian_ring.is_nilpotent_nilradical IsNoetherianRing.isNilpotent_nilradical\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/Noetherian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656671, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7103054467172646}}
{"text": "-- Ejercicios de l\u00f3gica proposicional\n-- ==================================\n\nimport tactic\nvariables (p q r s : Prop)\n\n-- \u00a7 Implicaciones\n-- ================\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Demostrar\n--      p \u27f6 q, p \u22a2 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hp  : p)\n  : q :=\nHpq Hp\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hp  : p)\n  : q :=\nby tauto\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar\n--    p \u2192 q, q \u2192 r, p \u22a2 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3m\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  (Hp : p)\n  : r :=\nbegin\n  apply Hqr,\n  apply Hpq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3m\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  (Hp : p)\n  : r :=\nbegin\n  apply Hqr,\n  exact Hpq Hp,\nend\n\n-- 3\u00aa demostraci\u00f3m\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  (Hp : p)\n  : r :=\nbegin\n  exact Hqr (Hpq Hp),\nend\n\n-- 3\u00aa demostraci\u00f3m\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  (Hp : p)\n  : r :=\nHqr (Hpq Hp)\n\n-- 4\u00aa demostraci\u00f3m\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  (Hp : p)\n  : r :=\nby tauto\n\n-- 5\u00aa demostraci\u00f3m\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  (Hp : p)\n  : r :=\nhave Hq : q,\n  from Hpq Hp,\nshow r,\n  from Hqr Hq\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Demostrar\n--    p \u2192 (q \u2192 r), p \u2192 q, p \u22a2 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  (Hpq  : p \u2192 q)\n  (Hp   : p)\n  : r :=\nbegin\n  have Hqr : q \u2192 r, from Hpqr Hp,\n  apply Hqr,\n  apply Hpq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  (Hpq  : p \u2192 q)\n  (Hp   : p)\n  : r :=\nbegin\n  have Hqr : q \u2192 r, from Hpqr Hp,\n  apply Hqr,\n  exact Hpq Hp,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  (Hpq  : p \u2192 q)\n  (Hp   : p)\n  : r :=\nbegin\n  have Hqr : q \u2192 r, from Hpqr Hp,\n  exact Hqr (Hpq Hp),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  (Hpq  : p \u2192 q)\n  (Hp   : p)\n  : r :=\n(Hpqr Hp) (Hpq Hp)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  (Hpq  : p \u2192 q)\n  (Hp   : p)\n  : r :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 4. Demostrar\n--    p \u2192 q, q \u2192 r \u22a2 p \u2192 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\nbegin\n  intro Hp,\n  apply Hqr,\n  apply Hpq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\nbegin\n  intro Hp,\n  apply Hqr,\n  exact Hpq Hp,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\nbegin\n  intro Hp,\n  exact Hqr (Hpq Hp),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\n\u03bb Hp, Hqr (Hpq Hp)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\nshow r,\n  from Hqr Hq\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\nHqr Hq\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\nassume Hp : p,\nHqr (Hpq Hp)\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\n\u03bb Hp, Hqr (Hpq Hp)\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\n-- by hint\nby tauto\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  (Hqr : q \u2192 r)\n  : p \u2192 r :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 5. Demostrar\n--    p \u2192 (q \u2192 r) \u22a2 q \u2192 (p \u2192 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nbegin\n  intro Hq,\n  intro Hp,\n  have Hqr : q \u2192 r,\n    from Hpqr Hp,\n  apply Hqr,\n  exact Hq,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nbegin\n  intro Hq,\n  intro Hp,\n  have Hqr : q \u2192 r,\n    from Hpqr Hp,\n  exact Hqr Hq,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nbegin\n  intro Hq,\n  intro Hp,\n  exact (Hpqr Hp) Hq,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nbegin\n  intros Hq Hp,\n  exact (Hpqr Hp) Hq,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\n\u03bb Hq Hp, (Hpqr Hp) Hq\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nbegin\n  intros Hq Hp,\n  apply Hpqr,\n  { exact Hp, },\n  { exact Hq, },\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nassume Hq : q,\nassume Hp : p,\nhave Hqr : q \u2192 r,\n  from Hpqr Hp,\nshow r,\n  from Hqr Hq\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nassume Hq : q,\nassume Hp : p,\nhave Hqr : q \u2192 r,\n  from Hpqr Hp,\nHqr Hq\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nassume Hq : q,\nassume Hp : p,\n(Hpqr Hp) Hq\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\n\u03bb Hq Hp, (Hpqr Hp) Hq\n\n-- 11\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\n-- by hint\nby tauto\n\n-- 12\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : q \u2192 (p \u2192 r) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 6. Demostrar\n--    p \u2192 (q \u2192 r) \u22a2 (p \u2192 q) \u2192 (p \u2192 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nbegin\n  intros Hpq Hp,\n  have Hqr : q \u2192 r,\n    from Hpqr Hp,\n  apply Hqr,\n  apply Hpq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nbegin\n  intros Hpq Hp,\n  have Hqr : q \u2192 r,\n    from Hpqr Hp,\n  apply Hqr,\n  exact Hpq Hp,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nbegin\n  intros Hpq Hp,\n  have Hqr : q \u2192 r,\n    from Hpqr Hp,\n  exact Hqr (Hpq Hp),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nbegin\n  intros Hpq Hp,\n  exact (Hpqr Hp) (Hpq Hp),\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\n\u03bb Hpq Hp, (Hpqr Hp) (Hpq Hp)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\nhave Hqr : q \u2192 r,\n  from Hpqr Hp,\nhave Hq : q,\n  from Hpq Hp,\nshow r,\n  from Hqr Hq\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\nhave Hqr : q \u2192 r,\n  from Hpqr Hp,\nhave Hq : q,\n  from Hpq Hp,\nHqr Hq\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\nhave Hqr : q \u2192 r,\n  from Hpqr Hp,\nHqr (Hpq Hp)\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\n(Hpqr Hp) (Hpq Hp)\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\n\u03bb Hpq Hp, (Hpqr Hp) (Hpq Hp)\n\n-- 11\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 7. Demostrar\n--    p \u22a2 q \u2192 p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  : q \u2192 p :=\nbegin\n  intro Hq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : q \u2192 p :=\n\u03bb _, H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  : q \u2192 p :=\nassume Hq : q,\nshow p,\n  from Hp\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  : q \u2192 p :=\n-- by library_search\nimp_intro Hp\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  : q \u2192 p :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  : q \u2192 p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 8. Demostrar\n--    \u22a2 p \u2192 (q \u2192 p)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  p \u2192 (q \u2192 p) :=\nbegin\n  intros Hp Hq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  p \u2192 (q \u2192 p) :=\n\u03bb Hp _, Hp\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  p \u2192 (q \u2192 p) :=\nassume Hp : p,\nassume Hq : q,\nshow p,\n  from Hp\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  p \u2192 (q \u2192 p) :=\n-- by library_search\nimp_intro\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  p \u2192 (q \u2192 p) :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  p \u2192 (q \u2192 p) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 9. Demostrar\n--    p \u2192 q \u22a2 (q \u2192 r) \u2192 (p \u2192 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\nbegin\n  intros Hqr Hp,\n  apply Hqr,\n  apply Hpq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\nbegin\n  intros Hqr Hp,\n  apply Hqr,\n  exact Hpq Hp,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\nbegin\n  intros Hqr Hp,\n  exact Hqr (Hpq Hp),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\n\u03bb Hqr Hp, Hqr (Hpq Hp)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\nassume Hqr : q \u2192 r,\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\nshow r,\n  from Hqr Hq\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\nassume Hqr : q \u2192 r,\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\nHqr Hq\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\n\u03bb Hqr Hp, Hqr (Hpq Hp)\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\n-- by hint\nby tauto\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2192 q)\n  : (q \u2192 r) \u2192 (p \u2192 r) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 10. Demostrar\n--    p \u2192 (q \u2192 (r \u2192 s)) \u22a2 r \u2192 (q \u2192 (p \u2192 s))\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\nbegin\n  intros Hr Hq Hp,\n  apply H,\n  { exact Hp, },\n  { exact Hq, },\n  { exact Hr, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\nbegin\n  intros Hr Hq Hp,\n  exact H Hp Hq Hr,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\n\u03bb Hr Hq Hp, H Hp Hq Hr\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\nassume Hr : r,\nassume Hq : q,\nassume Hp : p,\nhave H1 : q \u2192 (r \u2192 s),\n  from H Hp,\nhave H2 : r \u2192 s,\n  from H1 Hq,\nshow s,\n  from H2 Hr\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\nassume Hr : r,\nassume Hq : q,\nassume Hp : p,\nhave H1 : q \u2192 (r \u2192 s),\n  from H Hp,\nhave H2 : r \u2192 s,\n  from H1 Hq,\nH2 Hr\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\nassume Hr : r,\nassume Hq : q,\nassume Hp : p,\nhave H1 : q \u2192 (r \u2192 s),\n  from H Hp,\n(H1 Hq) Hr\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\nassume Hr : r,\nassume Hq : q,\nassume Hp : p,\n((H Hp) Hq) Hr\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\n\u03bb Hr Hq Hp, ((H Hp) Hq) Hr\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 (r \u2192 s)))\n  : r \u2192 (q \u2192 (p \u2192 s)) :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 11. Demostrar\n--    \u22a2 (p \u2192 (q \u2192 r)) \u2192 ((p \u2192 q) \u2192 (p \u2192 r))\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nbegin\n  intros Hpq Hp,\n  apply Hpqr,\n  { exact Hp, },\n  { apply Hpq,\n    exact Hp, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nbegin\n  intros Hpq Hp,\n  apply Hpqr,\n  { exact Hp, },\n  { exact Hpq Hp, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nbegin\n  intros Hpq Hp,\n  exact Hpqr Hp (Hpq Hp),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\n\u03bb Hpq Hp, Hpqr Hp (Hpq Hp)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\nhave Hqr : q \u2192 r,\n  from Hpqr Hp,\nshow r,\n  from Hqr Hq\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\nhave Hqr : q \u2192 r,\n  from Hpqr Hp,\nHqr Hq\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\n(Hpqr Hp) Hq\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\nassume Hpq : p \u2192 q,\nassume Hp : p,\n(Hpqr Hp) (Hpq Hp)\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\n\u03bb Hpq Hp, (Hpqr Hp) (Hpq Hp)\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2192 (q \u2192 r))\n  : (p \u2192 q) \u2192 (p \u2192 r) :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 12. Demostrar\n--    (p \u2192 q) \u2192 r \u22a2 p \u2192 (q \u2192 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nbegin\n  intros Hp Hq,\n  apply Hpqr,\n  intro Hp,\n  exact Hq,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nbegin\n  intros Hp Hq,\n  apply Hpqr,\n  exact (\u03bb Hp, Hq),\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nbegin\n  intros Hp Hq,\n  exact Hpqr (\u03bb Hp, Hq),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\n\u03bb Hp Hq, Hpqr (\u03bb Hp, Hq)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nassume Hp : p,\nassume Hq : q,\nhave Hpq : p \u2192 q,\n  { assume p,\n    show q,\n      from Hq },\nshow r,\n  from Hpqr Hpq\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nassume Hp : p,\nassume Hq : q,\nhave Hpq : p \u2192 q,\n  { assume p,\n    show q,\n      from Hq },\nHpqr Hpq\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nassume Hp : p,\nassume Hq : q,\nhave Hpq : p \u2192 q,\n  from (\u03bb p, Hq),\nHpqr Hpq\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nassume Hp : p,\nassume Hq : q,\nHpqr (\u03bb p, Hq)\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\n\u03bb Hp Hq, Hpqr (\u03bb p, Hq)\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2192 q) \u2192 r)\n  : p \u2192 (q \u2192 r) :=\n-- by hint\nby finish\n\n-- \u00a7 Conjunciones\n-- ==============\n\n-- ----------------------------------------------------\n-- Ejercicio 13. Demostrar\n--    p, q \u22a2  p \u2227 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  (Hq : q)\n  : p \u2227 q :=\nbegin\n  split,\n  { exact Hp, },\n  { exact Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  (Hq : q)\n  : p \u2227 q :=\nand.intro Hp Hq\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  (Hq : q)\n  : p \u2227 q :=\n-- by library_search\n\u27e8Hp, Hq\u27e9\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  (Hq : q)\n  : p \u2227 q :=\n-- by hint\nby tauto\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hp : p)\n  (Hq : q)\n  : p \u2227 q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 14. Demostrar\n--    p \u2227 q \u22a2 p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\nbegin\n  cases H with Hp Hq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\nand.elim_left H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\nand.left H\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\nH.left\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\nH.1\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\n-- by library_search\nH.left\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\n-- by hint\nby tauto\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 15. Demostrar\n--    p \u2227 q \u22a2 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\nbegin\n  cases H with Hp Hq,\n  exact Hq,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\nand.elim_right H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\nand.right H\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\nH.right\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\nH.2\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\n-- by library_search\nH.right\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\n-- by hint\nby tauto\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 16. Demostrar\n--    p \u2227 (q \u2227 r) \u22a2 (p \u2227 q) \u2227 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\nbegin\n  cases Hpqr with Hp Hqr,\n  cases Hqr with Hq Hr,\n  split,\n  { split,\n    { exact Hp, },\n    { exact Hq, }},\n  { exact Hr, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\nbegin\n  cases Hpqr with Hp Hqr,\n  cases Hqr with Hq Hr,\n  split,\n  { exact \u27e8Hp, Hq\u27e9, },\n  { exact Hr, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\nbegin\n  cases Hpqr with Hp Hqr,\n  cases Hqr with Hq Hr,\n  exact \u27e8\u27e8Hp, Hq\u27e9, Hr\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\nbegin\n  rcases Hpqr with \u27e8Hp, \u27e8Hq, Hr\u27e9\u27e9,\n  exact \u27e8\u27e8Hp, Hq\u27e9, Hr\u27e9,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  p \u2227 (q \u2227 r) \u2192 (p \u2227 q) \u2227 r :=\nbegin\n  rintros \u27e8Hp, \u27e8Hq, Hr\u27e9\u27e9,\n  exact \u27e8\u27e8Hp, Hq\u27e9, Hr\u27e9,\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  p \u2227 (q \u2227 r) \u2192 (p \u2227 q) \u2227 r :=\n\u03bb \u27e8Hp, \u27e8Hq, Hr\u27e9\u27e9, \u27e8\u27e8Hp, Hq\u27e9, Hr\u27e9\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\nhave Hp : p,\n  from and.left Hpqr,\nhave Hqr : q \u2227 r,\n  from and.right Hpqr,\nhave Hq : q,\n  from and.left Hqr,\nhave Hr : r,\n  from and.right Hqr,\nhave Hpq : p \u2227 q,\n  from and.intro Hp Hq,\nshow (p \u2227 q) \u2227 r,\n  from and.intro Hpq Hr\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\n-- by library_search\n(and_assoc p q).mpr Hpqr\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\n-- by hint\nby tauto\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (Hpqr : p \u2227 (q \u2227 r))\n  : (p \u2227 q) \u2227 r :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 17. Demostrar\n--    (p \u2227 q) \u2227 r \u22a2 p \u2227 (q \u2227 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2227 q) \u2227 r)\n  : p \u2227 (q \u2227 r) :=\nbegin\n  rcases Hpqr with \u27e8\u27e8Hp, Hq\u27e9, Hr\u27e9,\n  exact \u27e8Hp, \u27e8Hq, Hr\u27e9\u27e9,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  : (p \u2227 q) \u2227 r \u2192 p \u2227 (q \u2227 r) :=\nbegin\n  rintros \u27e8\u27e8Hp, Hq\u27e9, Hr\u27e9,\n  exact \u27e8Hp, \u27e8Hq, Hr\u27e9\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  : (p \u2227 q) \u2227 r \u2192 p \u2227 (q \u2227 r) :=\n\u03bb \u27e8\u27e8Hp, Hq\u27e9, Hr\u27e9, \u27e8Hp, \u27e8Hq, Hr\u27e9\u27e9\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2227 q) \u2227 r)\n  : p \u2227 (q \u2227 r) :=\nhave Hpq : p \u2227 q,\n  from and.left Hpqr,\nhave Hr : r,\n  from and.right Hpqr,\nhave Hp : p,\n  from and.left Hpq,\nhave Hq : q,\n  from and.right Hpq,\nhave Hqr : q \u2227 r,\n  from and.intro Hq Hr,\nshow p \u2227 (q \u2227 r),\n  from and.intro Hp Hqr\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2227 q) \u2227 r)\n  : p \u2227 (q \u2227 r) :=\n-- by library_search\n(and_assoc p q).mp Hpqr\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2227 q) \u2227 r)\n  : p \u2227 (q \u2227 r) :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpqr : (p \u2227 q) \u2227 r)\n  : p \u2227 (q \u2227 r) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 18. Demostrar\n--    p \u2227 q \u22a2 p \u2192 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2227 q)\n  : p \u2192 q :=\nbegin\n  intro p,\n  exact Hpq.right,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2227 q)\n  : p \u2192 q :=\n\u03bb _, Hpq.2\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2227 q)\n  : p \u2192 q :=\nassume Hp : p,\nshow q,\n  from and.right Hpq\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2227 q)\n  : p \u2192 q :=\n-- by hint\nby tauto\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2227 q)\n  : p \u2192 q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 19. Demostrar\n--    (p \u2192 q) \u2227 (p \u2192 r) \u22a2 p \u2192 q \u2227 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2227 (p \u2192 r))\n  : p \u2192 q \u2227 r :=\nbegin\n  cases H with Hpq Hpr,\n  intro Hp,\n  split,\n  { apply Hpq,\n    exact Hp, },\n  { apply Hpr,\n    exact Hp, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2227 (p \u2192 r))\n  : p \u2192 q \u2227 r :=\nbegin\n  cases H with Hpq Hpr,\n  intro Hp,\n  split,\n  { exact Hpq Hp, },\n  { exact Hpr Hp, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2227 (p \u2192 r))\n  : p \u2192 q \u2227 r :=\nbegin\n  cases H with Hpq Hpr,\n  intro Hp,\n  exact \u27e8Hpq Hp, Hpr Hp\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  : (p \u2192 q) \u2227 (p \u2192 r) \u2192 (p \u2192 q \u2227 r) :=\nbegin\n  rintros \u27e8Hpq, Hpr\u27e9 Hp,\n  exact \u27e8Hpq Hp, Hpr Hp\u27e9,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  : (p \u2192 q) \u2227 (p \u2192 r) \u2192 (p \u2192 q \u2227 r) :=\n\u03bb \u27e8Hpq, Hpr\u27e9 Hp, \u27e8Hpq Hp, Hpr Hp\u27e9\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2227 (p \u2192 r))\n  : p \u2192 q \u2227 r :=\nhave Hpq : p \u2192 q,\n  from and.left H,\nhave Hpr : p \u2192 r,\n  from and.right H,\nassume Hp : p,\nhave Hq : q,\n  from Hpq Hp,\nhave Hr : r,\n  from Hpr Hp,\nshow q \u2227 r,\n  from and.intro Hq Hr\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2227 (p \u2192 r))\n  : p \u2192 q \u2227 r :=\n-- by library_search\nimp_and_distrib.mpr H\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2227 (p \u2192 r))\n  : p \u2192 q \u2227 r :=\n-- by hint\nby tauto\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2227 (p \u2192 r))\n  : p \u2192 q \u2227 r :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 20. Demostrar\n--    p \u2192 q \u2227 r \u22a2 (p \u2192 q) \u2227 (p \u2192 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q \u2227 r)\n  : (p \u2192 q) \u2227 (p \u2192 r) :=\nbegin\n  split,\n  { intro Hp,\n    have Hqr : q \u2227 r,\n      from H Hp,\n    exact Hqr.left, },\n  { intro Hp,\n    have Hqr : q \u2227 r,\n      from H Hp,\n    exact Hqr.right, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q \u2227 r)\n  : (p \u2192 q) \u2227 (p \u2192 r) :=\nbegin\n  split,\n  { intro Hp,\n    exact (H Hp).left, },\n  { intro Hp,\n    exact (H Hp).right, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q \u2227 r)\n  : (p \u2192 q) \u2227 (p \u2192 r) :=\n\u27e8\u03bb Hp, (H Hp).left,\n \u03bb Hp, (H Hp).right\u27e9\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q \u2227 r)\n  : (p \u2192 q) \u2227 (p \u2192 r) :=\nhave Hpq : p \u2192 q, from\n  assume Hp : p,\n  have Hqr : q \u2227 r,\n    from H Hp,\n  show q,\n    from and.left Hqr,\nhave Hpr : p \u2192 r, from\n  assume Hp : p,\n  have Hqr : q \u2227 r,\n    from H Hp,\n  show r,\n    from and.right Hqr,\nshow (p \u2192 q) \u2227 (p \u2192 r),\n  from and.intro Hpq Hpr\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q \u2227 r)\n  : (p \u2192 q) \u2227 (p \u2192 r) :=\nand.intro\n  ( assume Hp : p,\n    have Hqr : q \u2227 r,\n      from H Hp,\n    show q,\n      from and.left Hqr)\n  ( assume Hp : p,\n    have Hqr : q \u2227 r,\n      from H Hp,\n    show r,\n      from and.right Hqr)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q \u2227 r)\n  : (p \u2192 q) \u2227 (p \u2192 r) :=\n-- by library_search\nimp_and_distrib.mp H\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q \u2227 r)\n  : (p \u2192 q) \u2227 (p \u2192 r) :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 21. Demostrar\n--    p \u2192 (q \u2192 r) \u22a2 p \u2227 q \u2192 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\nbegin\n  intro Hpq,\n  apply H,\n  { exact Hpq.left, },\n  { exact Hpq.right, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\nbegin\n  intro Hpq,\n  exact (H Hpq.left) Hpq.right,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\n\u03bb Hpq, (H Hpq.left) Hpq.right\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\n\u03bb Hpq, H Hpq.1 Hpq.2\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\nassume Hpq : p \u2227 q,\nhave Hp : p,\n  from and.left Hpq,\nhave Hq : q,\n  from and.right Hpq,\nhave Hqr : q \u2192 r,\n  from H Hp,\nshow r,\n  from Hqr Hq\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\n-- by library_search\nand_imp.mpr H\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\n-- by hint\nby tauto\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 (q \u2192 r))\n  : p \u2227 q \u2192 r :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 22. Demostrar\n--    p \u2227 q \u2192 r \u22a2 p \u2192 (q \u2192 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nbegin\n  intros Hp Hq,\n  apply H,\n  split,\n  { exact Hp, },\n  { exact Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nbegin\n  intros Hp Hq,\n  apply H,\n  exact \u27e8Hp, Hq\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nbegin\n  intros Hp Hq,\n  exact H \u27e8Hp, Hq\u27e9,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q \u2192 r)\n  : p \u2192 (q \u2192 r) :=\n\u03bb Hp Hq, H \u27e8Hp, Hq\u27e9\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q \u2192 r)\n  : p \u2192 (q \u2192 r) :=\nassume Hp : p,\nshow q \u2192 r, from\n  assume Hq : q,\n  have Hpq : p \u2227 q,\n    from and.intro Hp Hq,\n  show r,\n    from H Hpq\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q \u2192 r)\n  : p \u2192 (q \u2192 r) :=\n-- by library_search\nand_imp.mp H\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q \u2192 r)\n  : p \u2192 (q \u2192 r) :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 23. Demostrar\n--    (p \u2192 q) \u2192 r \u22a2 p \u2227 q \u2192 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2192 r)\n  : p \u2227 q \u2192 r :=\nbegin\n  intro Hpq,\n  apply H,\n  intro Hp,\n  exact Hpq.right,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2192 r)\n  : p \u2227 q \u2192 r :=\nbegin\n  intro Hpq,\n  apply H,\n  exact (\u03bb Hp, Hpq.right),\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2192 r)\n  : p \u2227 q \u2192 r :=\nbegin\n  intro Hpq,\n  exact H (\u03bb Hp, Hpq.right),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2192 r)\n  : p \u2227 q \u2192 r :=\n\u03bb Hpq, H (\u03bb _, Hpq.right)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2192 r)\n  : p \u2227 q \u2192 r :=\nassume Hpq : p \u2227 q,\nhave H1 : p \u2192 q, from\n  assume Hp : p,\n  show q,\n    from and.right Hpq,\nshow r,\n  from H H1\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 q) \u2192 r)\n  : p \u2227 q \u2192 r :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 24. Demostrar\n--    p \u2227 (q \u2192 r) \u22a2 (p \u2192 q) \u2192 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\nbegin\n  intro Hpq,\n  cases H with Hp Hqr,\n  apply Hqr,\n  apply Hpq,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\nbegin\n  intro Hpq,\n  cases H with Hp Hqr,\n  apply Hqr,\n  exact Hpq Hp,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\nbegin\n  intro Hpq,\n  cases H with Hp Hqr,\n  exact Hqr (Hpq Hp),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\nbegin\n  intro Hpq,\n  exact H.2 (Hpq H.1),\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\n\u03bb Hpq, H.2 (Hpq H.1)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\nassume Hpq : p \u2192 q,\nhave Hp : p,\n  from and.left H,\nhave Hq : q,\n  from Hpq Hp,\nhave Hqr : q \u2192 r,\n  from H.right,\nshow r,\n  from Hqr Hq\n\n-- 7\u00aa demostraci\u00f3\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\n-- by hint\nby tauto\n\n-- 8\u00aa demostraci\u00f3\nexample\n  (H : p \u2227 (q \u2192 r))\n  : (p \u2192 q) \u2192 r :=\n-- by hint\nby finish\n\n-- \u00a7 Disyunciones\n-- ==============\n\n-- ----------------------------------------------------\n-- Ejercicio 25. Demostrar\n--    p \u22a2 p \u2228 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 q :=\nbegin\n  left,\n  exact H,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 q :=\nor.intro_left q H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 q :=\n-- by library_search\nor.inl H\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 q :=\n-- by hint\nby tauto\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 26. Demostrar\n--    q \u22a2 p \u2228 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : q)\n  : p \u2228 q :=\nbegin\n  right,\n  exact H,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : q)\n  : p \u2228 q :=\nor.intro_right p H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : q)\n  : p \u2228 q :=\n-- by library_search\nor.inr H\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : q)\n  : p \u2228 q :=\n-- by hint\nby tauto\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : q)\n  : p \u2228 q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 27. Demostrar\n--    p \u2228 q \u22a2 q \u2228 p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\nbegin\n  cases H with Hp Hq,\n  { right,\n    exact Hp, },\n  { left,\n    exact Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\nbegin\n  cases H with Hp Hq,\n  { exact or.inr Hp, },\n  { exact or.inl Hq, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\nor.elim H\n  ( assume Hp : p,\n    show q \u2228 p,\n      from or.inr Hp)\n  ( assume Hq : q,\n    show q \u2228 p,\n      from or.inl Hq)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\nor.elim H\n  ( assume Hp : p,\n    or.inr Hp)\n  ( assume Hq : q,\n    or.inl Hq)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\nor.elim H\n  ( \u03bb Hp, or.inr Hp)\n  ( \u03bb Hq, or.inl Hq)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\nor.elim H or.inr or.inl\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\n-- by library_search\nor.swap H\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\n-- by hint\nby tauto\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : q \u2228 p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 28. Demostrar\n--    q \u2192 r \u22a2 p \u2228 q \u2192 p \u2228 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nbegin\n  intro H1,\n  cases H1 with Hp Hq,\n  { left,\n    exact Hp, },\n  { right,\n    apply H,\n    exact Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nbegin\n  rintro (Hp | Hq),\n  { left,\n    exact Hp, },\n  { right,\n    exact H Hq, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nbegin\n  rintro (Hp | Hq),\n  { exact or.inl Hp, },\n  { exact or.inr (H Hq), },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nassume H1 : p \u2228 q,\nor.elim H1\n  ( assume Hp : p,\n    show p \u2228 r,\n      from or.inl Hp)\n  ( assume Hq : q,\n    have Hr : r,\n      from H Hq,\n    show p \u2228 r,\n      from or.inr Hr)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nassume H1 : p \u2228 q,\nor.elim H1\n  ( assume Hp : p,\n    or.inl Hp)\n  ( assume Hq : q,\n    have Hr : r,\n      from H Hq,\n    or.inr Hr)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nassume H1 : p \u2228 q,\nor.elim H1\n  ( assume Hp : p,\n    or.inl Hp)\n  ( assume Hq : q,\n    or.inr (H Hq))\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nassume H1 : p \u2228 q,\nor.elim H1\n  ( \u03bb Hp, or.inl Hp)\n  ( \u03bb Hq, or.inr (H Hq))\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\nassume H1 : p \u2228 q,\nor.elim H1\n  or.inl\n  ( \u03bb Hq, or.inr (H Hq))\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\n\u03bb H1, or.elim H1 or.inl (\u03bb Hq, or.inr (H Hq))\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (H : q \u2192 r)\n  : p \u2228 q \u2192 p \u2228 r :=\n-- by library_search\nor.imp_right H\n\n-- ----------------------------------------------------\n-- Ejercicio 29. Demostrar\n--    p \u2228 p \u22a2 p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\nbegin\n  cases H with Hp Hp,\n  { exact Hp, },\n  { exact Hp, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\nby cases H ; assumption\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\nor.elim H\n  ( assume Hp : p,\n    show p,\n      from Hp)\n  ( assume Hp : p,\n    show p,\n      from Hp)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\nor.elim H\n  ( assume Hp : p,\n    Hp)\n  ( assume Hp : p,\n    Hp)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\nor.elim H\n  ( \u03bb Hp, Hp)\n  ( \u03bb Hp, Hp)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\nor.elim H id id\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\n-- by library_search\n(or_self p).mp H\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\n-- by hint\nby tauto\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 p)\n  : p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 30. Demostrar\n--    p \u22a2 p \u2228 p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 p :=\n-- by library_search\nor.inl H\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 p :=\n-- by hint\nby tauto\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : p \u2228 p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 31. Demostrar\n--    p \u2228 (q \u2228 r) \u22a2 (p \u2228 q) \u2228 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nbegin\n  cases H with Hp Hqr,\n  { left,\n    left,\n    exact Hp, },\n  { cases Hqr with Hq Hr,\n    { left,\n      right,\n      exact Hq, },\n    { right,\n      exact Hr, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    show (p \u2228 q) \u2228 r,\n      from or.inl Hpq)\n  ( assume Hqr : q \u2228 r,\n    show (p \u2228 q) \u2228 r, from\n      or.elim Hqr\n        ( assume Hq : q,\n          have Hpq : p \u2228 q,\n            from or.inr Hq,\n          show (p \u2228 q) \u2228 r,\n            from or.inl Hpq)\n        ( assume Hr : r,\n          show (p \u2228 q) \u2228 r,\n            from or.inr Hr))\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    show (p \u2228 q) \u2228 r,\n      from or.inl Hpq)\n  ( assume Hqr : q \u2228 r,\n    show (p \u2228 q) \u2228 r, from\n      or.elim Hqr\n        ( assume Hq : q,\n          have Hpq : p \u2228 q,\n            from or.inr Hq,\n          or.inl Hpq)\n        ( assume Hr : r,\n          or.inr Hr))\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    show (p \u2228 q) \u2228 r,\n      from or.inl Hpq)\n  ( assume Hqr : q \u2228 r,\n    show (p \u2228 q) \u2228 r, from\n      or.elim Hqr\n        ( assume Hq : q,\n          have Hpq : p \u2228 q,\n            from or.inr Hq,\n          or.inl Hpq)\n        or.inr)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    show (p \u2228 q) \u2228 r,\n      from or.inl Hpq)\n  ( assume Hqr : q \u2228 r,\n    show (p \u2228 q) \u2228 r, from\n      or.elim Hqr\n        ( \u03bb Hq, or.inl (or.inr Hq))\n        or.inr)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    show (p \u2228 q) \u2228 r,\n      from or.inl Hpq)\n  ( \u03bb Hqr, or.elim Hqr ( \u03bb Hq, or.inl (or.inr Hq)) or.inr)\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    or.inl Hpq)\n  (\u03bb Hqr, or.elim Hqr ( \u03bb Hq, or.inl (or.inr Hq)) or.inr)\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  ( assume Hp : p,\n    or.inl (or.inl Hp))\n  (\u03bb Hqr, or.elim Hqr ( \u03bb Hq, or.inl (or.inr Hq)) or.inr)\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nor.elim H\n  (\u03bb Hp, or.inl (or.inl Hp))\n  (\u03bb Hqr, or.elim Hqr ( \u03bb Hq, or.inl (or.inr Hq)) or.inr)\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\n-- by library_search\nor.assoc.mpr H\n\n-- 11\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\n-- by hint\nby tauto\n\n-- 12\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2228 r))\n  : (p \u2228 q) \u2228 r :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 32. Demostrar\n--    (p \u2228 q) \u2228 r \u22a2 p \u2228 (q \u2228 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2228 r)\n  : p \u2228 (q \u2228 r) :=\nbegin\n  rcases H with ((Hp | Hq) | Hr),\n  { left,\n    exact Hp, },\n  { right,\n    left,\n    exact Hq, },\n  { right,\n    right,\n    exact Hr, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2228 r)\n  : p \u2228 (q \u2228 r) :=\nor.elim H\n  ( assume Hpq : p \u2228 q,\n    show p \u2228 q \u2228 r, from\n      or.elim Hpq\n        ( assume Hp : p,\n          show p \u2228 (q \u2228 r),\n            from or.inl Hp)\n        ( assume Hq : q,\n          have Hqr: q \u2228 r,\n            from or.inl Hq,\n          show p \u2228 (q \u2228 r),\n            from or.inr Hqr))\n  ( assume Hr : r,\n    have Hqr: q \u2228 r,\n      from or.inr Hr,\n    show p \u2228 (q \u2228 r),\n      from or.inr Hqr)\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2228 r)\n  : p \u2228 (q \u2228 r) :=\nor.elim H\n  ( \u03bb Hpq, or.elim Hpq or.inl (\u03bb Hq, or.inr (or.inl Hq)))\n  ( \u03bb Hr, or.inr (or.inr Hr))\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2228 r)\n  : p \u2228 (q \u2228 r) :=\n-- by library_search\nor.assoc.mp H\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2228 r)\n  : p \u2228 (q \u2228 r) :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2228 r)\n  : p \u2228 (q \u2228 r) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 33. Demostrar\n--    p \u2227 (q \u2228 r) \u22a2 (p \u2227 q) \u2228 (p \u2227 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2228 r))\n  : (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  cases H with Hp Hqr,\n  cases Hqr with Hq Hr,\n  { left,\n    split,\n    { exact Hp, },\n    { exact Hq, }},\n  { right,\n    split,\n    { exact Hp, },\n    { exact Hr, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2228 r))\n  : (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  cases H with Hp Hqr,\n  cases Hqr with Hq Hr,\n  { left,\n    exact \u27e8Hp, Hq\u27e9, },\n  { right,\n    exact \u27e8Hp, Hr\u27e9, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2228 r))\n  : (p \u2227 q) \u2228 (p \u2227 r) :=\nhave Hp : p,\n  from and.left H,\nhave Hqr : q \u2228 r,\n  from and.right H,\nor.elim Hqr\n  ( assume Hq : q,\n    have Hpq : p \u2227 q,\n      from and.intro Hp Hq,\n    show (p \u2227 q) \u2228 (p \u2227 r),\n      from or.inl Hpq)\n  ( assume Hr : r,\n    have Hpr : p \u2227 r,\n      from and.intro Hp Hr,\n    show (p \u2227 q) \u2228 (p \u2227 r),\n      from or.inr Hpr)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2228 r))\n  : (p \u2227 q) \u2228 (p \u2227 r) :=\nor.elim H.2\n  (\u03bb Hq, or.inl \u27e8H.1, Hq\u27e9)\n  (\u03bb Hr, or.inr \u27e8H.1, Hr\u27e9)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2228 r))\n  : (p \u2227 q) \u2228 (p \u2227 r) :=\n-- by library_search\nand_or_distrib_left.mp H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 (q \u2228 r))\n  : (p \u2227 q) \u2228 (p \u2227 r) :=\n-- by hint\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 34. Demostrar\n--    (p \u2227 q) \u2228 (p \u2227 r) \u22a2 p \u2227 (q \u2228 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2227 q) \u2228 (p \u2227 r))\n  : p \u2227 (q \u2228 r) :=\nbegin\n  rcases H with (\u27e8Hp,Hq\u27e9 | \u27e8Hp, Hr\u27e9),\n  { exact \u27e8Hp, or.inl Hq\u27e9, },\n  { exact \u27e8Hp, or.inr Hr\u27e9, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2227 q) \u2228 (p \u2227 r))\n  : p \u2227 (q \u2228 r) :=\nor.elim H\n  ( assume Hpq : p \u2227 q,\n    have Hp : p,\n      from and.left Hpq,\n    have Hq : q,\n      from and.right Hpq,\n    have Hqr : q \u2228 r,\n      from or.inl Hq,\n    show p \u2227 (q \u2228 r),\n      from and.intro Hp Hqr)\n  ( assume Hpr : p \u2227 r,\n    have Hp : p,\n      from and.left Hpr,\n    have Hr : r,\n      from and.right Hpr,\n    have Hqr : q \u2228 r,\n      from or.inr Hr,\n    show p \u2227 (q \u2228 r),\n      from and.intro Hp Hqr)\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2227 q) \u2228 (p \u2227 r))\n  : p \u2227 (q \u2228 r) :=\nor.elim H\n  ( assume \u27e8Hp, Hq\u27e9,\n    have Hqr : q \u2228 r,\n      from or.inl Hq,\n    show p \u2227 (q \u2228 r),\n      from and.intro Hp Hqr)\n  ( assume \u27e8Hp, Hr\u27e9,\n    have Hqr : q \u2228 r,\n      from or.inr Hr,\n    show p \u2227 (q \u2228 r),\n      from and.intro Hp Hqr)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2227 q) \u2228 (p \u2227 r))\n  : p \u2227 (q \u2228 r) :=\nor.elim H\n  (\u03bb \u27e8Hp, Hq\u27e9, \u27e8Hp ,or.inl Hq\u27e9)\n  (\u03bb \u27e8Hp, Hr\u27e9, \u27e8Hp, or.inr Hr\u27e9)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2227 q) \u2228 (p \u2227 r))\n  : p \u2227 (q \u2228 r) :=\n-- by library_search\nand_or_distrib_left.mpr H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2227 q) \u2228 (p \u2227 r))\n  : p \u2227 (q \u2228 r) :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2227 q) \u2228 (p \u2227 r))\n  : p \u2227 (q \u2228 r) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 35. Demostrar\n--    p \u2228 (q \u2227 r) \u22a2 (p \u2228 q) \u2227 (p \u2228 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nbegin\n  cases H with Hp Hqr,\n  { split,\n    { left,\n      exact Hp, },\n    { left,\n      exact Hp, }},\n  { split,\n    { right,\n      exact Hqr.left, },\n    { right,\n      exact Hqr.right, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nbegin\n  cases H with Hp Hqr,\n  { split,\n    { exact or.inl Hp, },\n    { exact or.inl Hp, }},\n  { split,\n    { exact or.inr Hqr.left, },\n    { exact or.inr Hqr.right, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nbegin\n  cases H with Hp Hqr,\n  { exact \u27e8or.inl Hp, or.inl Hp\u27e9, },\n  { exact \u27e8or.inr Hqr.left, or.inr Hqr.right\u27e9, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  (\u03bb Hp, \u27e8or.inl Hp, or.inl Hp\u27e9)\n  (\u03bb Hqr, \u27e8or.inr Hqr.1, or.inr Hqr.2\u27e9)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  (\u03bb h, \u27e8or.inl h,   or.inl h\u27e9)\n  (\u03bb h, \u27e8or.inr h.1, or.inr h.2\u27e9)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n  ( assume Hqr : q \u2227 r,\n    have Hq : q,\n      from and.left Hqr,\n    have Hr : r,\n      from and.right Hqr,\n    have Hpq : p \u2228 q,\n      from or.inr Hq,\n    have Hpr : p \u2228 r,\n      from or.inr Hr,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n  ( assume Hqr : q \u2227 r,\n    have Hq : q,\n      from and.left Hqr,\n    have Hr : r,\n      from and.right Hqr,\n    have Hpq : p \u2228 q,\n      from or.inr Hq,\n    have Hpr : p \u2228 r,\n      from or.inr Hr,\n    and.intro Hpq Hpr)\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n  ( assume Hqr : q \u2227 r,\n    have Hq : q,\n      from and.left Hqr,\n    have Hr : r,\n      from and.right Hqr,\n    and.intro (or.inr Hq) (or.inr Hr))\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n  ( assume Hqr : q \u2227 r,\n    and.intro (or.inr (and.left Hqr)) (or.inr (and.right Hqr)))\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n  ( assume Hqr : q \u2227 r,\n    and.intro (or.inr Hqr.1) (or.inr Hqr.2))\n\n-- 11\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n  ( assume Hqr : q \u2227 r,\n    \u27e8or.inr Hqr.1, or.inr Hqr.2\u27e9)\n\n-- 12\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    show (p \u2228 q) \u2227 (p \u2228 r),\n      from and.intro Hpq Hpr)\n  ( \u03bb Hqr, \u27e8or.inr Hqr.1, or.inr Hqr.2\u27e9)\n\n-- 13\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    and.intro Hpq Hpr)\n  ( \u03bb Hqr, \u27e8or.inr Hqr.1, or.inr Hqr.2\u27e9)\n\n-- 14\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    have Hpr : p \u2228 r,\n      from or.inl Hp,\n    \u27e8Hpq, Hpr\u27e9)\n  ( \u03bb Hqr, \u27e8or.inr Hqr.1, or.inr Hqr.2\u27e9)\n\n-- 15\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( assume Hp : p,\n    \u27e8or.inl Hp, or.inl Hp\u27e9)\n  ( \u03bb Hqr, \u27e8or.inr Hqr.1, or.inr Hqr.2\u27e9)\n\n-- 16\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nor.elim H\n  ( \u03bb Hp, \u27e8or.inl Hp, or.inl Hp\u27e9)\n  ( \u03bb Hqr, \u27e8or.inr Hqr.1, or.inr Hqr.2\u27e9)\n\n-- 17\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\n-- by library_search\nor_and_distrib_left.mp H\n\n-- 18\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\n-- by hint\nby tauto\n\n-- 19\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 (q \u2227 r))\n  : (p \u2228 q) \u2227 (p \u2228 r) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 36. Demostrar\n--    (p \u2228 q) \u2227 (p \u2228 r) \u22a2 p \u2228 (q \u2227 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nbegin\n  cases H with Hpq Hpr,\n  cases Hpq with Hp Hq,\n  { left,\n    exact Hp, },\n  { cases Hpr with Hp Hr,\n    { left,\n      exact Hp, },\n    { right,\n      split,\n      { exact Hq, },\n      { exact Hr, }}},\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nbegin\n  cases H with Hpq Hpr,\n  cases Hpq with Hp Hq,\n  { left,\n    exact Hp, },\n  { cases Hpr with Hp Hr,\n    { left,\n      exact Hp, },\n    { right,\n      exact \u27e8Hq, Hr\u27e9, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nbegin\n  cases H with Hpq Hpr,\n  cases Hpq with Hp Hq,\n  { left,\n    exact Hp, },\n  { cases Hpr with Hp Hr,\n    { left,\n      exact Hp, },\n    { exact or.inr \u27e8Hq, Hr\u27e9, }},\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nbegin\n  cases H with Hpq Hpr,\n  cases Hpq with Hp Hq,\n  { left,\n    exact Hp, },\n  { cases Hpr with Hp Hr,\n    { exact or.inl Hp, },\n    { exact or.inr \u27e8Hq, Hr\u27e9, }},\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nbegin\n  cases H with Hpq Hpr,\n  cases Hpq with Hp Hq,\n  { exact or.inl Hp, },\n  { cases Hpr with Hp Hr,\n    { exact or.inl Hp, },\n    { exact or.inr \u27e8Hq, Hr\u27e9, }},\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nbegin\n  rcases H with \u27e8Hp | Hq, Hp | Hr\u27e9,\n  { exact or.inl Hp, },\n  { exact or.inl Hp, },\n  { exact or.inl Hp, },\n  { exact or.inr \u27e8Hq, Hr\u27e9, },\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\n-- by library_search\nor_and_distrib_left.mpr H\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nhave Hpq : p \u2228 q,\n  from and.left H,\nor.elim Hpq\n  ( assume Hp : p,\n    show p \u2228 (q \u2227 r),\n      from or.inl Hp )\n  ( assume Hq : q,\n    have Hpr : p \u2228 r,\n      from and.right H,\n    or.elim Hpr\n      ( assume Hp : p,\n        show p \u2228 (q \u2227 r),\n          from or.inl Hp )\n      ( assume Hr : r,\n        have Hqr : q \u2227 r,\n          from and.intro Hq Hr,\n        show p \u2228 (q \u2227 r),\n          from or.inr Hqr ))\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nor.elim (and.left H)\n  or.inl\n  (\u03bb Hq, or.elim (and.right H)\n           or.inl\n           (\u03bb Hr, or.inr \u27e8Hq, Hr\u27e9))\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\n-- by hint\nby tauto\n\n-- 11\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2228 q) \u2227 (p \u2228 r))\n  : p \u2228 (q \u2227 r) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 37. Demostrar\n--    (p \u2192 r) \u2227 (q \u2192 r) \u22a2 p \u2228 q \u2192 r\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nbegin\n  cases H with Hpr Hqr,\n  intro Hpq,\n  cases Hpq with Hp Hq,\n  { apply Hpr,\n    exact Hp, },\n  { apply Hqr,\n    exact Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nbegin\n  cases H with Hpr Hqr,\n  intro Hpq,\n  cases Hpq with Hp Hq,\n  { exact Hpr Hp, },\n  { exact Hqr Hq, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nbegin\n  intro Hpq,\n  cases Hpq with Hp Hq,\n  { exact H.left  Hp, },\n  { exact H.right Hq, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\n-- by library_search\nor_imp_distrib.mpr H\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nassume Hpq : p \u2228 q,\nor.elim Hpq\n  ( assume Hp : p,\n    have Hpr: p \u2192 r,\n      from and.left H,\n    show r,\n      from Hpr Hp )\n  ( assume Hq : q,\n    have Hqr : q \u2192 r,\n      from and.right H,\n    show r,\n      from Hqr Hq)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nassume Hpq : p \u2228 q,\nor.elim Hpq\n  ( assume Hp : p,\n    have Hpr: p \u2192 r,\n      from and.left H,\n    Hpr Hp )\n  ( assume Hq : q,\n    have Hqr : q \u2192 r,\n      from and.right H,\n    Hqr Hq)\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nassume Hpq : p \u2228 q,\nor.elim Hpq\n  ( assume Hp : p,\n    H.1 Hp )\n  ( assume Hq : q,\n    H.2 Hq)\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nassume Hpq : p \u2228 q,\nor.elim Hpq\n  (\u03bb Hp, H.1 Hp)\n  (\u03bb Hq, H.2 Hq)\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nassume Hpq : p \u2228 q,\nor.elim Hpq H.1 H.2\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\n\u03bb Hpq, or.elim Hpq H.1 H.2\n\n-- 11\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\n-- by hint\nby tauto\n\n-- 12\u00aa demostraci\u00f3n\nexample\n  (H : (p \u2192 r) \u2227 (q \u2192 r))\n  : p \u2228 q \u2192 r :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 38. Demostrar\n--    p \u2228 q \u2192 r \u22a2 (p \u2192 r) \u2227 (q \u2192 r)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\nbegin\n  split,\n  { intro Hp,\n    apply H,\n    left,\n    exact Hp, },\n  { intro Hq,\n    apply H,\n    right,\n    exact Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\nbegin\n  split,\n  { intro Hp,\n    apply H,\n    exact or.inl Hp, },\n  { intro Hq,\n    apply H,\n    exact or.inr Hq, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\nbegin\n  split,\n  { intro Hp,\n    exact H (or.inl Hp), },\n  { intro Hq,\n    exact H (or.inr Hq), },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\n\u27e8\u03bb Hp, H (or.inl Hp),\n \u03bb Hq, H (or.inr Hq)\u27e9\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\n-- by library_search\nor_imp_distrib.mp H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\nand.intro\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    show r,\n      from H Hpq)\n  ( assume Hq : q,\n    have Hpq : p \u2228 q,\n      from or.inr Hq,\n    show r,\n      from H Hpq)\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\nand.intro\n  ( assume Hp : p,\n    have Hpq : p \u2228 q,\n      from or.inl Hp,\n    H Hpq)\n  ( assume Hq : q,\n    have Hpq : p \u2228 q,\n      from or.inr Hq,\n    H Hpq)\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\nand.intro\n  ( assume Hp : p,\n    H (or.inl Hp))\n  ( assume Hq : q,\n    H (or.inr Hq))\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\nand.intro\n  (\u03bb Hp, H (or.inl Hp))\n  (\u03bb Hq, H (or.inr Hq))\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q \u2192 r)\n  : (p \u2192 r) \u2227 (q \u2192 r) :=\n\u27e8\u03bb Hp, H (or.inl Hp),\n \u03bb Hq, H (or.inr Hq)\u27e9\n\n-- \u00a7 Negaci\u00f3n\n-- ==========\n\n-- ----------------------------------------------------\n-- Ejercicio 39. Demostrar\n--    p \u22a2 \u00ac\u00acp\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : \u00ac\u00acp :=\nbegin\n  intro H1,\n  apply H1 H,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : \u00ac\u00acp :=\n\u03bb H1, H1 H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : \u00ac\u00acp :=\n-- by library_search\nnot_not.mpr H\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : \u00ac\u00acp :=\nassume H1 : \u00acp,\nshow false,\n  from H1 H\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : \u00ac\u00acp :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p)\n  : \u00ac\u00acp :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 40. Demostrar\n--    \u00acp \u22a2 p \u2192 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp)\n  : p \u2192 q :=\nbegin\n  intro Hp,\n  exfalso,\n  apply H,\n  exact Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp)\n  : p \u2192 q :=\nbegin\n  intro Hp,\n  exfalso,\n  exact H Hp,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp)\n  : p \u2192 q :=\nbegin\n  intro Hp,\n  exact absurd Hp H,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp)\n  : p \u2192 q :=\n\u03bb Hp, absurd Hp H\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp)\n  : p \u2192 q :=\n-- by library_search\nnot.elim H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp)\n  : p \u2192 q :=\nassume Hp : p,\nshow q,\n  from absurd Hp H\n\n-- ----------------------------------------------------\n-- Ejercicio 41. Demostrar\n--    p \u2192 q \u22a2 \u00acq \u2192 \u00acp\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nbegin\n  intro Hnq,\n  intro Hp,\n  apply Hnq,\n  exact H Hp,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nbegin\n  intro Hnq,\n  intro Hp,\n  exact Hnq (H Hp),\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nbegin\n  intros Hnq Hp,\n  exact Hnq (H Hp),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\n\u03bb Hnq Hp, Hnq (H Hp)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\n-- by library_search\nmt H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nassume Hnq : \u00acq,\nassume Hp : p,\nhave Hq : q,\n  from H Hp,\nshow false,\n  from Hnq Hq\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nassume Hnq : \u00acq,\nassume Hp : p,\nhave Hq : q,\n  from H Hp,\nHnq Hq\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nassume Hnq : \u00acq,\nassume Hp : p,\nHnq (H Hp)\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nassume Hnq : \u00acq,\n\u03bb Hp, Hnq (H Hp)\n\n-- 10\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\n\u03bb Hnq Hp, Hnq (H Hp)\n\n-- 11\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\n-- by hint\nby tauto\n\n-- 12\u00aa demostraci\u00f3n\nexample\n  (H : p \u2192 q)\n  : \u00acq \u2192 \u00acp :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 42. Demostrar\n--    p \u2228 q, \u00acq \u22a2 p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\nbegin\n  cases Hpq with Hp Hq,\n  { exact Hp, },\n  { exact absurd Hq Hnq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\n-- by library_search\nor.resolve_right Hpq Hnq\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\nor.elim Hpq\n  ( assume Hp : p,\n    show p,\n      from Hp)\n  ( assume Hq : q,\n    show p,\n      from absurd Hq Hnq)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\nor.elim Hpq\n  ( assume Hp : p,\n    show p,\n      from Hp)\n  ( assume Hq : q,\n    absurd Hq Hnq)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\nor.elim Hpq\n  ( assume Hp : p,\n    show p,\n      from Hp)\n  ( \u03bb Hq, absurd Hq Hnq)\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\nor.elim Hpq\n  ( assume Hp : p,\n    Hp)\n  ( \u03bb Hq, absurd Hq Hnq)\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\nor.elim Hpq id (\u03bb Hq, absurd Hq Hnq)\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\n-- by hint\nby tauto\n\n-- 9\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnq : \u00acq)\n  : p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 43. Demostrar\n--    p \u2228 q, \u00acp \u22a2 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnp: \u00acp)\n  : q :=\nbegin\n  cases Hpq with Hp Hq,\n  { exact absurd Hp Hnp, },\n  { exact Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnp: \u00acp)\n  : q :=\nor.elim Hpq (\u03bb Hp, absurd Hp Hnp) id\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnp: \u00acp)\n  : q :=\n-- by library_search\nor.resolve_left Hpq Hnp\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnp: \u00acp)\n  : q :=\nor.elim Hpq\n  ( assume Hp : p,\n    show q,\n      from absurd Hp Hnp)\n  ( assume Hq : q,\n    show q,\n      from Hq)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnp: \u00acp)\n  : q :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (Hpq : p \u2228 q)\n  (Hnp: \u00acp)\n  : q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 44. Demostrar\n--    p \u2228 q \u22a2 \u00ac(\u00acp \u2227 \u00acq)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : \u00ac(\u00acp \u2227 \u00acq) :=\nbegin\n  intro H1,\n  cases H1 with H2 H3,\n  cases H with H4 H5,\n  { exact H2 H4, },\n  { exact H3 H5, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : \u00ac(\u00acp \u2227 \u00acq) :=\nbegin\n  rintro \u27e8H2, H3\u27e9,\n  cases H with H4 H5,\n  { exact H2 H4, },\n  { exact H3 H5, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : \u00ac(\u00acp \u2227 \u00acq) :=\n\u03bb \u27e8H2, H3\u27e9, or.elim H (\u03bb H4, H2 H4) (\u03bb H5, H3 H5)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : \u00ac(\u00acp \u2227 \u00acq) :=\n-- by library_search\nor_iff_not_and_not.mp H\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : \u00ac(\u00acp \u2227 \u00acq) :=\nassume H3 : \u00acp \u2227 \u00acq,\nor.elim H\n  ( assume Hp : p,\n    show false,\n      from absurd Hp (and.left H3))\n  ( assume Hq : q,\n    show false,\n      from absurd Hq (and.right H3))\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : \u00ac(\u00acp \u2227 \u00acq) :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2228 q)\n  : \u00ac(\u00acp \u2227 \u00acq) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 45. Demostrar\n--    p \u2227 q \u22a2 \u00ac(\u00acp \u2228 \u00acq)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : \u00ac(\u00acp \u2228 \u00acq) :=\nbegin\n  intro H1,\n  cases H1 with H2 H3,\n  { apply H2,\n    exact H.left, },\n  { apply H3,\n    exact H.right, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : \u00ac(\u00acp \u2228 \u00acq) :=\nbegin\n  intro H1,\n  cases H1 with H2 H3,\n  { exact H2 H.left, },\n  { exact H3 H.right, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : \u00ac(\u00acp \u2228 \u00acq) :=\n\u03bb H1, or.elim H1 (\u03bb H2, H2 H.1) (\u03bb H3, H3 H.2)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : \u00ac(\u00acp \u2228 \u00acq) :=\nbegin\n  rintro (H2 | H3),\n  { exact H2 H.left, },\n  { exact H3 H.right, },\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : \u00ac(\u00acp \u2228 \u00acq) :=\n-- by library_search\nand_iff_not_or_not.mp H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : \u00ac(\u00acp \u2228 \u00acq) :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 q)\n  : \u00ac(\u00acp \u2228 \u00acq) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 46. Demostrar\n--    \u00ac(p \u2228 q) \u22a2 \u00acp \u2227 \u00acq\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2228 q))\n  : \u00acp \u2227 \u00acq :=\nbegin\n  split,\n  { intro Hp,\n    apply H,\n    exact or.inl Hp, },\n  { intro Hq,\n    apply H,\n    exact or.inr Hq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2228 q))\n  : \u00acp \u2227 \u00acq :=\nbegin\n  split,\n  { intro Hp,\n    exact H (or.inl Hp), },\n  { intro Hq,\n    exact H (or.inr Hq), },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2228 q))\n  : \u00acp \u2227 \u00acq :=\n\u27e8 \u03bb Hp, H (or.inl Hp),\n  \u03bb Hq, H (or.inr Hq)\u27e9\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2228 q))\n  : \u00acp \u2227 \u00acq :=\n-- by library_search\nnot_or_distrib.mp H\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2228 q))\n  : \u00acp \u2227 \u00acq :=\nhave H1 : \u00acp, from\n  assume Hp : p,\n  have H2: p \u2228 q,\n    from or.inl Hp,\n  show false,\n    from absurd H2 H,\nhave H3 : \u00acq, from\n  assume Hq : q,\n  have H4: p \u2228 q,\n    from or.inr Hq,\n  show false,\n    from absurd H4 H,\nshow \u00acp \u2227 \u00acq,\n  from and.intro H1 H3\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2228 q))\n  : \u00acp \u2227 \u00acq :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2228 q))\n  : \u00acp \u2227 \u00acq :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 47. Demostrar\n--    \u00acp \u2227 \u00acq \u22a2 \u00ac(p \u2228 q)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2227 \u00acq)\n  : \u00ac(p \u2228 q) :=\nbegin\n  intro H1,\n  cases H1 with H2 H3,\n  { exact absurd H2 H.1, },\n  { exact absurd H3 H.2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2227 \u00acq)\n  : \u00ac(p \u2228 q) :=\n\u03bb H1, or.elim H1 (\u03bb H2, absurd H2 H.1) (\u03bb H3, absurd H3 H.2)\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2227 \u00acq)\n  : \u00ac(p \u2228 q) :=\n-- by library_search\nnot_or_distrib.mpr H\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2227 \u00acq)\n  : \u00ac(p \u2228 q) :=\nassume Hpq : p \u2228 q,\nor.elim Hpq\n  ( assume Hp : p,\n    show false,\n      from absurd Hp H.left)\n  ( assume Hq : q,\n    show false,\n      from absurd Hq H.right)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2227 \u00acq)\n  : \u00ac(p \u2228 q) :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2227 \u00acq)\n  : \u00ac(p \u2228 q) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 48. Demostrar\n--    \u00acp \u2228 \u00acq \u22a2 \u00ac(p \u2227 q)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\nbegin\n  intro Hpq,\n  cases H with Hnp Hnq,\n  { apply Hnp,\n    exact Hpq.left, },\n  { apply Hnq,\n    exact Hpq.right, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\nbegin\n  intro Hpq,\n  cases H with Hnp Hnq,\n  { exact Hnp Hpq.1, },\n  { exact Hnq Hpq.2, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\nbegin\n  intro Hpq,\n  exact or.elim H (\u03bb Hnp, Hnp Hpq.1) (\u03bb Hnq, Hnq Hpq.2),\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\n\u03bb Hpq, or.elim H (\u03bb Hnp, Hnp Hpq.1) (\u03bb Hnq, Hnq Hpq.2)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\n-- by library_search\nnot_and_distrib.mpr H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\nassume Hpq : p \u2227 q,\nor.elim H\n  ( assume Hnp : \u00acp,\n    show false,\n      from Hnp (and.left Hpq))\n  ( assume Hnq : \u00acq,\n    show false,\n      from Hnq (and.right Hpq))\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\n-- by hint\nby tauto\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : \u00acp \u2228 \u00acq)\n  : \u00ac(p \u2227 q) :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 49. Demostrar\n--    \u22a2 \u00ac(p \u2227 \u00acp)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nbegin\n  intro H,\n  apply H.right,\n  exact H.left,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nbegin\n  intro H,\n  exact H.right (H.left),\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n\u03bb H, H.right (H.left)\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nbegin\n  rintro \u27e8H1, H2\u27e9,\n  exact H2 H1,\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n\u03bb \u27e8H1, H2\u27e9, H2 H1\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n-- by suggest\n(and_not_self p).mp\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nassume H : p \u2227 \u00acp,\nhave H1 : p,\n  from and.left H,\nhave H2 : \u00acp,\n  from and.right H,\nshow false,\n  from H2 H1\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\n-- by hint\nby tauto\n\n-- 9\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nby finish\n\n-- 10\u00aa demostraci\u00f3n\nexample :\n  \u00ac(p \u2227 \u00acp) :=\nby simp\n\n-- ----------------------------------------------------\n-- Ejercicio 50. Demostrar\n--    p \u2227 \u00acp \u22a2 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 \u00acp)\n  : q :=\nbegin\n  exfalso,\n  apply H.2,\n  exact H.1,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 \u00acp)\n  : q :=\nbegin\n  exfalso,\n  exact H.2 H.1,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 \u00acp)\n  : q :=\nfalse.elim (H.2 H.1)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 \u00acp)\n  : q :=\nhave Hp : p,\n  from and.left H,\nhave Hnp : \u00acp,\n  from and.right H,\nhave Hf : false,\n  from Hnp Hp,\nshow q,\n  from false.elim Hf\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 \u00acp)\n  : q :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : p \u2227 \u00acp)\n  : q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 51. Demostrar\n--    \u00ac\u00acp \u22a2 p\n-- ----------------------------------------------------\n\nopen_locale classical\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acp)\n  : p :=\nby_contra\n  ( assume h2 : \u00acp,\n    show false,\n      from h1 h2 )\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acp)\n  : p :=\nby_contra\n  ( assume h2 : \u00acp,\n    h1 h2 )\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acp)\n  : p :=\nby_contra (\u03bb h2, h1 h2)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acp)\n  : p :=\n-- by library_search\nnot_not.mp h1\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acp)\n  : p :=\nbegin\n  by_contradiction h2,\n  exact h1 h2,\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acp)\n  : p :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nlemma aux\n  (h1 : \u00ac\u00acp)\n  : p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 52. Demostrar\n--    \u22a2 p \u2228 \u00acp\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( assume h1 : \u00ac(p \u2228 \u00acp),\n    have h2 : \u00acp, from\n      assume h3 : p,\n      have h4 : p \u2228 \u00acp, from or.inl h3,\n      show false, from h1 h4,\n    have h5 : p \u2228 \u00acp, from or.inr h2,\n    show false, from h1 h5 )\n\n-- 2\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( assume h1 : \u00ac(p \u2228 \u00acp),\n    have h2 : \u00acp, from\n      assume h3 : p,\n      have h4 : p \u2228 \u00acp, from or.inl h3,\n      show false, from h1 h4,\n    have h5 : p \u2228 \u00acp, from or.inr h2,\n    h1 h5 )\n\n-- 3\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( assume h1 : \u00ac(p \u2228 \u00acp),\n    have h2 : \u00acp, from\n      assume h3 : p,\n      have h4 : p \u2228 \u00acp, from or.inl h3,\n      show false, from h1 h4,\n    h1 (or.inr h2) )\n\n-- 4\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( assume h1 : \u00ac(p \u2228 \u00acp),\n    have h2 : \u00acp, from\n      assume h3 : p,\n      have h4 : p \u2228 \u00acp, from or.inl h3,\n      h1 h4,\n    h1 (or.inr h2) )\n\n-- 5\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( assume h1 : \u00ac(p \u2228 \u00acp),\n    have h2 : \u00acp, from\n      assume h3 : p,\n      h1 (or.inl h3),\n    h1 (or.inr h2) )\n\n-- 6\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( assume h1 : \u00ac(p \u2228 \u00acp),\n    have h2 : \u00acp, from\n      \u03bb h3, h1 (or.inl h3),\n    h1 (or.inr h2) )\n\n-- 7\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( assume h1 : \u00ac(p \u2228 \u00acp),\n    h1 (or.inr (\u03bb h3, h1 (or.inl h3))) )\n\n-- 8\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contradiction\n  ( \u03bb h1, h1 (or.inr (\u03bb h3, h1 (or.inl h3))) )\n\n-- 9\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\n-- by library_search\nem p\n\n-- #print axioms em\n\n-- 10\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nbegin\n  by_contra h1,\n  apply h1,\n  apply or.inr,\n  intro h2,\n  apply h1,\n  exact or.inl h2,\nend\n\n-- 11\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nbegin\n  by_contra h1,\n  apply h1,\n  apply or.inr,\n  intro h2,\n  exact h1 (or.inl h2),\nend\n\n-- 12\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nbegin\n  by_contra h1,\n  apply h1,\n  apply or.inr,\n  exact \u03bb h2, h1 (or.inl h2),\nend\n\n-- 13\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nbegin\n  by_contra h1,\n  apply h1,\n  exact or.inr (\u03bb h2, h1 (or.inl h2)),\nend\n\n-- 14\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nbegin\n  by_contra h1,\n  exact h1 (or.inr (\u03bb h2, h1 (or.inl h2))),\nend\n\n-- 15\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby_contra (\u03bb h1, h1 (or.inr (\u03bbh2, h1 (or.inl h2))))\n\n-- 16\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nbegin\n  by_contra h1,\n  apply h1,\n  right,\n  intro h2,\n  apply h1,\n  left,\n  exact h2,\nend\n\n-- 17\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\n-- by hint\nby tauto\n\n-- 18\u00aa demostraci\u00f3n\nexample : p \u2228 \u00acp :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 53. Demostrar\n--    \u22a2 ((p \u2192 q) \u2192 p) \u2192 p\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  ((p \u2192 q) \u2192 p) \u2192 p :=\nbegin\n  intro h1,\n  by_cases h2 : p \u2192 q,\n  { exact h1 h2, },\n  { by_contra h3,\n    apply h2,\n    intro h4,\n    exfalso,\n    exact h3 h4, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  ((p \u2192 q) \u2192 p) \u2192 p :=\nbegin\n  by_cases hp : p,\n  { intro h1,\n    exact hp, },\n  { intro h2,\n    exact h2 hp.elim, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  ((p \u2192 q) \u2192 p) \u2192 p :=\nif hp : p then \u03bb h, hp else \u03bb h, h hp.elim\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  ((p \u2192 q) \u2192 p) \u2192 p :=\n-- by library_search\npeirce p q\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  ((p \u2192 q) \u2192 p) \u2192 p :=\nassume h1 : (p \u2192 q) \u2192 p,\nshow p, from\n  by_contradiction\n    ( assume h2 : \u00acp,\n      have h3 : \u00ac(p \u2192 q),\n        by exact mt h1 h2,\n      have h4 : p \u2192 q, from\n        assume h5 : p,\n        show q,\n          from not.elim h2 h5,\n      show false,\n        from h3 h4)\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  ((p \u2192 q) \u2192 p) \u2192 p :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  ((p \u2192 q) \u2192 p) \u2192 p :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 54. Demostrar\n--    \u00acq \u2192 \u00acp \u22a2 p \u2192 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00acq \u2192 \u00acp)\n  : p \u2192 q :=\nbegin\n  intro Hp,\n  by_contra Hnq,\n  apply not.elim _ Hp,\n  exact H Hnq,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00acq \u2192 \u00acp)\n  : p \u2192 q :=\n-- by library_search\nnot_imp_not.mp H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00acq \u2192 \u00acp)\n  : p \u2192 q :=\nassume Hp : p,\nshow q, from\n  by_contradiction\n    ( assume Hnq : \u00acq,\n      have Hnp : \u00acp,\n        from H Hnq,\n      show false,\n        from Hnp Hp )\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00acq \u2192 \u00acp)\n  : p \u2192 q :=\n-- by hint\nby tauto\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00acq \u2192 \u00acp)\n  : p \u2192 q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 55. Demostrar\n--    \u00ac(\u00acp \u2227 \u00acq) \u22a2 p \u2228 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2227 \u00acq))\n  : p \u2228 q :=\nbegin\n  by_cases Hp : p,\n  { exact or.inl Hp, },\n  { by_cases Hq : q,\n    { exact or.inr Hq, },\n    { exfalso,\n      apply H,\n      exact and.intro Hp Hq, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2227 \u00acq))\n  : p \u2228 q :=\n-- by library_search\nor_iff_not_and_not.mpr H\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2227 \u00acq))\n  : p \u2228 q :=\nor.elim (em p)\n  ( assume Hp : p,\n    show p \u2228 q ,\n      from or.inl Hp)\n  ( assume Hnp : \u00acp,\n    show p \u2228 q, from\n      or.elim (em q)\n        ( assume Hq : q,\n          show p \u2228 q,\n            from or.inr Hq)\n        ( assume Hnq : \u00acq,\n          have H' : \u00acp \u2227 \u00acq,\n            from and.intro Hnp Hnq,\n          show p \u2228 q,\n            from not.elim H H'))\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2227 \u00acq))\n  : p \u2228 q :=\nor.elim (em p)\n  or.inl\n  (\u03bb Hnp, or.elim (em q)\n            or.inr\n            (\u03bb Hnq, not.elim H (and.intro Hnp Hnq)))\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2227 \u00acq))\n  : p \u2228 q :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2227 \u00acq))\n  : p \u2228 q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 56. Demostrar\n--    \u00ac(\u00acp \u2228 \u00acq) \u22a2 p \u2227 q\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\nbegin\n  split,\n  { by_contra Hnp,\n    apply H,\n    exact or.inl Hnp, },\n  { by_contra Hnq,\n    apply H,\n    exact or.inr Hnq, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\nbegin\n  split,\n  { by_contra Hnp,\n    exact H (or.inl Hnp), },\n  { by_contra Hnq,\n    exact H (or.inr Hnq), },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\nbegin\n  split,\n  { exact by_contra (\u03bb Hnp, H (or.inl Hnp)), },\n  { exact by_contra (\u03bb Hnq, H (or.inr Hnq)), },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\n\u27e8by_contra (\u03bb Hnp, H (or.inl Hnp)),\n by_contra (\u03bb Hnq, H (or.inr Hnq))\u27e9\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\n-- by library_search\nand_iff_not_or_not.mpr H\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\nand.intro\n  ( show p, from by_contradiction\n      ( assume Hnp : \u00acp,\n        have H' : \u00acp \u2228 \u00ac q,\n          from or.inl Hnp,\n        show false,\n          from H H'))\n  ( show q, from by_contradiction\n      ( assume Hnq : \u00acq,\n        have H' : \u00acp \u2228 \u00ac q,\n          from or.inr Hnq,\n        show false,\n          from H H'))\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\n-- by hint\nby tauto\n\n-- 8\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(\u00acp \u2228 \u00acq))\n  : p \u2227 q :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 57. Demostrar\n--    \u00ac(p \u2227 q) \u22a2 \u00acp \u2228 \u00acq\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2227 q))\n  : \u00acp \u2228 \u00acq :=\nbegin\n  by_cases Hp : p,\n  { by_cases Hq : q,\n    { exfalso,\n      apply H,\n      exact \u27e8Hp, Hq\u27e9, },\n    { exact or.inr Hq, }},\n  { exact or.inl Hp, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2227 q))\n  : \u00acp \u2228 \u00acq :=\nif Hp : p\nthen if Hq : q\n     then not.elim H \u27e8Hp, Hq\u27e9\n     else or.inr Hq\nelse or.inl Hp\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2227 q))\n  : \u00acp \u2228 \u00acq :=\n-- by library_search\nnot_and_distrib.mp H\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2227 q))\n  : \u00acp \u2228 \u00acq :=\nor.elim (em p)\n  ( assume Hp : p,\n    or.elim (em q)\n      ( assume Hq : q,\n        show \u00acp \u2228 \u00acq,\n          from not.elim H \u27e8Hp, Hq\u27e9)\n      ( assume Hnq : \u00acq,\n        show \u00acp \u2228 \u00acq,\n          from or.inr Hnq))\n  ( assume Hnp : \u00acp,\n    show \u00acp \u2228 \u00acq,\n      from or.inl Hnp)\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2227 q))\n  : \u00acp \u2228 \u00acq :=\nor.elim (em p)\n  (\u03bb Hp, or.elim (em q)\n           (\u03bb Hq, not.elim H \u27e8Hp, Hq\u27e9)\n           or.inr)\n  or.inl\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2227 q))\n  : \u00acp \u2228 \u00acq :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nexample\n  (H : \u00ac(p \u2227 q))\n  : \u00acp \u2228 \u00acq :=\nby finish\n\n-- ----------------------------------------------------\n-- Ejercicio 58. Demostrar\n--    \u22a2 (p \u2192 q) \u2228 (q \u2192 p)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nbegin\n  by_cases H1 : p,\n  { right,\n    intro,\n    exact H1, },\n  { left,\n    intro H2,\n    exfalso,\n    exact H1 H2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nbegin\n  cases (em p) with Hp Hnp,\n  { exact or.inr (\u03bb Hq, Hp), },\n  { exact or.inl (\u03bb Hp, not.elim Hnp Hp), },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nor.elim (em p)\n  (\u03bb Hp, or.inr (\u03bb Hq, Hp))\n  (\u03bb Hnp, or.inl (\u03bb Hp, not.elim Hnp Hp))\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nif Hp : p\n   then or.inr (\u03bb _, Hp)\n   else or.inl (\u03bb H, not.elim Hp H)\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nby finish\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/1_Proposicional/Ejercicios/Ejercicios_de_logica_proposicional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7102747295547136}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport data.set.finite\nimport algebra.big_operators.basic\n\n/-!\n# Preimage of a `finset` under an injective map.\n-/\n\nopen set function\n\nopen_locale big_operators\n\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b9 : Sort w} {\u03b3 : Type x}\n\nnamespace finset\n\nsection preimage\n\n/-- Preimage of `s : finset \u03b2` under a map `f` injective of `f \u207b\u00b9' s` as a `finset`.  -/\nnoncomputable def preimage (s : finset \u03b2) (f : \u03b1 \u2192 \u03b2)\n  (hf : set.inj_on f (f \u207b\u00b9' \u2191s)) : finset \u03b1 :=\n(s.finite_to_set.preimage hf).to_finset\n\n@[simp] lemma mem_preimage {f : \u03b1 \u2192 \u03b2} {s : finset \u03b2} {hf : set.inj_on f (f \u207b\u00b9' \u2191s)} {x : \u03b1} :\n  x \u2208 preimage s f hf \u2194 f x \u2208 s :=\nset.finite.mem_to_finset _\n\n@[simp, norm_cast] lemma coe_preimage {f : \u03b1 \u2192 \u03b2} (s : finset \u03b2)\n  (hf : set.inj_on f (f \u207b\u00b9' \u2191s)) : (\u2191(preimage s f hf) : set \u03b1) = f \u207b\u00b9' \u2191s :=\nset.finite.coe_to_finset _\n\n@[simp] lemma preimage_empty {f : \u03b1 \u2192 \u03b2} : preimage \u2205 f (by simp [inj_on]) = \u2205 :=\nfinset.coe_injective (by simp)\n\n@[simp] lemma preimage_univ {f : \u03b1 \u2192 \u03b2} [fintype \u03b1] [fintype \u03b2] (hf) :\n  preimage univ f hf = univ :=\nfinset.coe_injective (by simp)\n\n@[simp] lemma preimage_inter [decidable_eq \u03b1] [decidable_eq \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : finset \u03b2}\n  (hs : set.inj_on f (f \u207b\u00b9' \u2191s)) (ht : set.inj_on f (f \u207b\u00b9' \u2191t)) :\n  preimage (s \u2229 t) f (\u03bb x\u2081 hx\u2081 x\u2082 hx\u2082, hs (mem_of_mem_inter_left hx\u2081) (mem_of_mem_inter_left hx\u2082))\n    = preimage s f hs \u2229 preimage t f ht :=\nfinset.coe_injective (by simp)\n\n@[simp] lemma preimage_union [decidable_eq \u03b1] [decidable_eq \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : finset \u03b2} (hst) :\n  preimage (s \u222a t) f hst\n    = preimage s f (\u03bb x\u2081 hx\u2081 x\u2082 hx\u2082, hst (mem_union_left _ hx\u2081) (mem_union_left _ hx\u2082))\n    \u222a preimage t f (\u03bb x\u2081 hx\u2081 x\u2082 hx\u2082, hst (mem_union_right _ hx\u2081) (mem_union_right _ hx\u2082)) :=\nfinset.coe_injective (by simp)\n\n@[simp] lemma preimage_compl [decidable_eq \u03b1] [decidable_eq \u03b2] [fintype \u03b1] [fintype \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (s : finset \u03b2) (hf : function.injective f) :\n  preimage s\u1d9c f (hf.inj_on _) = (preimage s f (hf.inj_on _))\u1d9c :=\nfinset.coe_injective (by simp)\n\nlemma monotone_preimage {f : \u03b1 \u2192 \u03b2} (h : injective f) :\n  monotone (\u03bb s, preimage s f (h.inj_on _)) :=\n\u03bb s t hst x hx, mem_preimage.2 (hst $ mem_preimage.1 hx)\n\nlemma image_subset_iff_subset_preimage [decidable_eq \u03b2] {f : \u03b1 \u2192 \u03b2} {s : finset \u03b1} {t : finset \u03b2}\n  (hf : set.inj_on f (f \u207b\u00b9' \u2191t)) :\n  s.image f \u2286 t \u2194 s \u2286 t.preimage f hf :=\nimage_subset_iff.trans $ by simp only [subset_iff, mem_preimage]\n\nlemma map_subset_iff_subset_preimage {f : \u03b1 \u21aa \u03b2} {s : finset \u03b1} {t : finset \u03b2} :\n  s.map f \u2286 t \u2194 s \u2286 t.preimage f (f.injective.inj_on _) :=\nby classical; rw [map_eq_image, image_subset_iff_subset_preimage]\n\nlemma image_preimage [decidable_eq \u03b2] (f : \u03b1 \u2192 \u03b2) (s : finset \u03b2) [\u03a0 x, decidable (x \u2208 set.range f)]\n  (hf : set.inj_on f (f \u207b\u00b9' \u2191s)) :\n  image f (preimage s f hf) = s.filter (\u03bb x, x \u2208 set.range f) :=\nfinset.coe_inj.1 $ by simp only [coe_image, coe_preimage, coe_filter,\n  set.image_preimage_eq_inter_range, set.sep_mem_eq]\n\nlemma image_preimage_of_bij [decidable_eq \u03b2] (f : \u03b1 \u2192 \u03b2) (s : finset \u03b2)\n  (hf : set.bij_on f (f \u207b\u00b9' \u2191s) \u2191s) :\n  image f (preimage s f hf.inj_on) = s :=\nfinset.coe_inj.1 $ by simpa using hf.image_eq\n\nlemma sigma_preimage_mk {\u03b2 : \u03b1 \u2192 Type*} [decidable_eq \u03b1] (s : finset (\u03a3 a, \u03b2 a)) (t : finset \u03b1) :\n  t.sigma (\u03bb a, s.preimage (sigma.mk a) $ sigma_mk_injective.inj_on _) = s.filter (\u03bb a, a.1 \u2208 t) :=\nby { ext x, simp [and_comm] }\n\nlemma sigma_preimage_mk_of_subset {\u03b2 : \u03b1 \u2192 Type*} [decidable_eq \u03b1] (s : finset (\u03a3 a, \u03b2 a))\n  {t : finset \u03b1} (ht : s.image sigma.fst \u2286 t) :\n  t.sigma (\u03bb a, s.preimage (sigma.mk a) $ sigma_mk_injective.inj_on _) = s :=\nby rw [sigma_preimage_mk, filter_true_of_mem $ image_subset_iff.1 ht]\n\nlemma sigma_image_fst_preimage_mk {\u03b2 : \u03b1 \u2192 Type*} [decidable_eq \u03b1] (s : finset (\u03a3 a, \u03b2 a)) :\n  (s.image sigma.fst).sigma (\u03bb a, s.preimage (sigma.mk a) $ sigma_mk_injective.inj_on _) = s :=\ns.sigma_preimage_mk_of_subset (subset.refl _)\n\nend preimage\n\n@[to_additive]\nlemma prod_preimage' [comm_monoid \u03b2] (f : \u03b1 \u2192 \u03b3) [decidable_pred $ \u03bb x, x \u2208 set.range f]\n  (s : finset \u03b3) (hf : set.inj_on f (f \u207b\u00b9' \u2191s)) (g : \u03b3 \u2192 \u03b2) :\n  \u220f x in s.preimage f hf, g (f x) = \u220f x in s.filter (\u03bb x, x \u2208 set.range f), g x :=\nby haveI := classical.dec_eq \u03b3;\ncalc \u220f x in preimage s f hf, g (f x) = \u220f x in image f (preimage s f hf), g x :\n  eq.symm $ prod_image $ by simpa only [mem_preimage, inj_on] using hf\n  ... = \u220f x in s.filter (\u03bb x, x \u2208 set.range f), g x : by rw [image_preimage]\n\n@[to_additive]\n\n\n@[to_additive]\nlemma prod_preimage_of_bij [comm_monoid \u03b2] (f : \u03b1 \u2192 \u03b3) (s : finset \u03b3)\n  (hf : set.bij_on f (f \u207b\u00b9' \u2191s) \u2191s) (g : \u03b3 \u2192 \u03b2) :\n  \u220f x in s.preimage f hf.inj_on, g (f x) = \u220f x in s, g x :=\nprod_preimage _ _ hf.inj_on g $ \u03bb x hxs hxf, (hxf $ hf.subset_range hxs).elim\n\nend finset\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/finset/preimage.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7102747109784872}}
{"text": "-- Propiedad: \u2200 a b : \u211d, a = a * b \u2192 a = 0 \u2228 b = 1\n-- ===============================================\n\nimport data.real.basic\n\nvariables (a b : \u211d)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Demostrar que para todo a y b, n\u00fameros\n-- reales, se tiene\n--    a = a * b \u2192 a = 0 \u2228 b = 1\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  a = a * b \u2192 a = 0 \u2228 b = 1 :=\nbegin\n  intro h1,\n  have h2 : a * (1 - b) = 0,\n    calc a * (1 - b)\n         = a * 1 - a * b : mul_sub a 1 b\n     ... = a - a * b     : by simp\n     ... = 0             : by linarith,\n  rw mul_eq_zero at h2,\n  cases h2 with ha hb,\n    { left,\n      exact ha, },\n    { right,\n      linarith, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  a = a * b \u2192 a = 0 \u2228 b = 1 :=\nbegin\n  intro h1,\n  have h2 : a * (1 - b) = 0,\n    { calc a * (1 - b)\n           = a - a * b     : by ring\n       ... = 0             : by linarith, },\n  rw mul_eq_zero at h2,\n  cases h2 with ha hb,\n    { left,\n      exact ha, },\n    { right,\n      linarith, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  a = a * b \u2192 a = 0 \u2228 b = 1 :=\nbegin\n  intro h1,\n  have h2 : a * (1 - b) = 0,\n    { by linarith, },\n  rw mul_eq_zero at h2,\n  cases h2 with ha hb,\n    { left,\n      exact ha, },\n    { right,\n      linarith, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  a = a * b \u2192 a = 0 \u2228 b = 1 :=\nassume h1: a = a * b,\nhave h2 : a * (1 - b) = 0,\n  by linarith,\nhave h3 : a = 0 \u2228 1 - b = 0,\n  from mul_eq_zero.mp h2,\nor.elim h3\n  ( assume h3a : a = 0,\n    show a = 0 \u2228 b = 1,\n      from or.inl h3a)\n  ( assume h3b : 1 - b = 0,\n    have h4 : b = 1,\n      from by linarith,\n    show a = 0 \u2228 b = 1,\n      from or.inr h4)\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/3_Cuantificadores/Propiedad:_aIaPb\u2192aI0\u2228bI1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7102747105404059}}
{"text": "theorem le_total (a b : mynat) : a \u2264 b \u2228 b \u2264 a :=\nbegin\nrevert a,\ninduction b with d hd,\nintro a,\nright,\nexact zero_le _,\nintro a,\ncases a,\nleft,\nexact zero_le _,\ncases hd a,\nleft,\nexact succ_le_succ _ _ h,\nright,\nexact succ_le_succ _ _ h,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world10/level09.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897459384732, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7102162838878344}}
{"text": "import mynat.definition\n\nnamespace mynat\n\ntheorem succ_succ_inj (a b : mynat) (h : succ(succ(a)) = succ(succ(b))) : a = b :=\nbegin\n    apply succ_inj,\n    apply succ_inj,\n    exact h,\nend\n\nend mynat", "meta": {"author": "nomoid", "repo": "lean-proofs", "sha": "b9f03a24623d1a1d111d6c2bbf53c617e2596d6a", "save_path": "github-repos/lean/nomoid-lean-proofs", "path": "github-repos/lean/nomoid-lean-proofs/lean-proofs-b9f03a24623d1a1d111d6c2bbf53c617e2596d6a/src/world8/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107984180245, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.7102130779920387}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Heather Macbeth\n\n! This file was ported from Lean 3 source module analysis.normed_space.ball_action\n! leanprover-community/mathlib commit 3339976e2bcae9f1c81e620836d1eb736e3c4700\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Normed.Field.UnitBall\nimport Mathbin.Analysis.NormedSpace.Basic\n\n/-!\n# Multiplicative actions of/on balls and spheres\n\nLet `E` be a normed vector space over a normed field `\ud835\udd5c`. In this file we define the following\nmultiplicative actions.\n\n- The closed unit ball in `\ud835\udd5c` acts on open balls and closed balls centered at `0` in `E`.\n- The unit sphere in `\ud835\udd5c` acts on open balls, closed balls, and spheres centered at `0` in `E`.\n-/\n\n\nopen Metric Set\n\nvariable {\ud835\udd5c \ud835\udd5c' E : Type _} [NormedField \ud835\udd5c] [NormedField \ud835\udd5c'] [SeminormedAddCommGroup E]\n  [NormedSpace \ud835\udd5c E] [NormedSpace \ud835\udd5c' E] {r : \u211d}\n\nsection ClosedBall\n\ninstance mulActionClosedBallBall : MulAction (closedBall (0 : \ud835\udd5c) 1) (ball (0 : E) r)\n    where\n  smul c x :=\n    \u27e8(c : \ud835\udd5c) \u2022 x,\n      mem_ball_zero_iff.2 <| by\n        simpa only [norm_smul, one_mul] using\n          mul_lt_mul' (mem_closedBall_zero_iff.1 c.2) (mem_ball_zero_iff.1 x.2) (norm_nonneg _)\n            one_pos\u27e9\n  one_smul x := Subtype.ext <| one_smul \ud835\udd5c _\n  mul_smul c\u2081 c\u2082 x := Subtype.ext <| mul_smul _ _ _\n#align mul_action_closed_ball_ball mulActionClosedBallBall\n\ninstance continuousSMul_closedBall_ball : ContinuousSMul (closedBall (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n  \u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n#align has_continuous_smul_closed_ball_ball continuousSMul_closedBall_ball\n\ninstance mulActionClosedBallClosedBall : MulAction (closedBall (0 : \ud835\udd5c) 1) (closedBall (0 : E) r)\n    where\n  smul c x :=\n    \u27e8(c : \ud835\udd5c) \u2022 x,\n      mem_closedBall_zero_iff.2 <| by\n        simpa only [norm_smul, one_mul] using\n          mul_le_mul (mem_closedBall_zero_iff.1 c.2) (mem_closedBall_zero_iff.1 x.2) (norm_nonneg _)\n            zero_le_one\u27e9\n  one_smul x := Subtype.ext <| one_smul \ud835\udd5c _\n  mul_smul c\u2081 c\u2082 x := Subtype.ext <| mul_smul _ _ _\n#align mul_action_closed_ball_closed_ball mulActionClosedBallClosedBall\n\ninstance continuousSMul_closedBall_closedBall :\n    ContinuousSMul (closedBall (0 : \ud835\udd5c) 1) (closedBall (0 : E) r) :=\n  \u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n#align has_continuous_smul_closed_ball_closed_ball continuousSMul_closedBall_closedBall\n\nend ClosedBall\n\nsection Sphere\n\ninstance mulActionSphereBall : MulAction (sphere (0 : \ud835\udd5c) 1) (ball (0 : E) r)\n    where\n  smul c x := inclusion sphere_subset_closedBall c \u2022 x\n  one_smul x := Subtype.ext <| one_smul _ _\n  mul_smul c\u2081 c\u2082 x := Subtype.ext <| mul_smul _ _ _\n#align mul_action_sphere_ball mulActionSphereBall\n\ninstance continuousSMul_sphere_ball : ContinuousSMul (sphere (0 : \ud835\udd5c) 1) (ball (0 : E) r) :=\n  \u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n#align has_continuous_smul_sphere_ball continuousSMul_sphere_ball\n\ninstance mulActionSphereClosedBall : MulAction (sphere (0 : \ud835\udd5c) 1) (closedBall (0 : E) r)\n    where\n  smul c x := inclusion sphere_subset_closedBall c \u2022 x\n  one_smul x := Subtype.ext <| one_smul _ _\n  mul_smul c\u2081 c\u2082 x := Subtype.ext <| mul_smul _ _ _\n#align mul_action_sphere_closed_ball mulActionSphereClosedBall\n\ninstance continuousSMul_sphere_closedBall :\n    ContinuousSMul (sphere (0 : \ud835\udd5c) 1) (closedBall (0 : E) r) :=\n  \u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n#align has_continuous_smul_sphere_closed_ball continuousSMul_sphere_closedBall\n\ninstance mulActionSphereSphere : MulAction (sphere (0 : \ud835\udd5c) 1) (sphere (0 : E) r)\n    where\n  smul c x :=\n    \u27e8(c : \ud835\udd5c) \u2022 x,\n      mem_sphere_zero_iff_norm.2 <| by\n        rw [norm_smul, mem_sphere_zero_iff_norm.1 c.coe_prop, mem_sphere_zero_iff_norm.1 x.coe_prop,\n          one_mul]\u27e9\n  one_smul x := Subtype.ext <| one_smul _ _\n  mul_smul c\u2081 c\u2082 x := Subtype.ext <| mul_smul _ _ _\n#align mul_action_sphere_sphere mulActionSphereSphere\n\ninstance continuousSMul_sphere_sphere : ContinuousSMul (sphere (0 : \ud835\udd5c) 1) (sphere (0 : E) r) :=\n  \u27e8(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _\u27e9\n#align has_continuous_smul_sphere_sphere continuousSMul_sphere_sphere\n\nend Sphere\n\nsection IsScalarTower\n\nvariable [NormedAlgebra \ud835\udd5c \ud835\udd5c'] [IsScalarTower \ud835\udd5c \ud835\udd5c' E]\n\ninstance isScalarTower_closedBall_closedBall_closedBall :\n    IsScalarTower (closedBall (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (closedBall (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align is_scalar_tower_closed_ball_closed_ball_closed_ball isScalarTower_closedBall_closedBall_closedBall\n\ninstance isScalarTower_closedBall_closedBall_ball :\n    IsScalarTower (closedBall (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align is_scalar_tower_closed_ball_closed_ball_ball isScalarTower_closedBall_closedBall_ball\n\ninstance isScalarTower_sphere_closedBall_closedBall :\n    IsScalarTower (sphere (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (closedBall (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align is_scalar_tower_sphere_closed_ball_closed_ball isScalarTower_sphere_closedBall_closedBall\n\ninstance isScalarTower_sphere_closedBall_ball :\n    IsScalarTower (sphere (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align is_scalar_tower_sphere_closed_ball_ball isScalarTower_sphere_closedBall_ball\n\ninstance isScalarTower_sphere_sphere_closedBall :\n    IsScalarTower (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (closedBall (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align is_scalar_tower_sphere_sphere_closed_ball isScalarTower_sphere_sphere_closedBall\n\ninstance isScalarTower_sphere_sphere_ball :\n    IsScalarTower (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align is_scalar_tower_sphere_sphere_ball isScalarTower_sphere_sphere_ball\n\ninstance isScalarTower_sphere_sphere_sphere :\n    IsScalarTower (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (sphere (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align is_scalar_tower_sphere_sphere_sphere isScalarTower_sphere_sphere_sphere\n\ninstance isScalarTower_sphere_ball_ball :\n    IsScalarTower (sphere (0 : \ud835\udd5c) 1) (ball (0 : \ud835\udd5c') 1) (ball (0 : \ud835\udd5c') 1) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : \ud835\udd5c')\u27e9\n#align is_scalar_tower_sphere_ball_ball isScalarTower_sphere_ball_ball\n\ninstance isScalarTower_closedBall_ball_ball :\n    IsScalarTower (closedBall (0 : \ud835\udd5c) 1) (ball (0 : \ud835\udd5c') 1) (ball (0 : \ud835\udd5c') 1) :=\n  \u27e8fun a b c => Subtype.ext <| smul_assoc (a : \ud835\udd5c) (b : \ud835\udd5c') (c : \ud835\udd5c')\u27e9\n#align is_scalar_tower_closed_ball_ball_ball isScalarTower_closedBall_ball_ball\n\nend IsScalarTower\n\nsection SMulCommClass\n\nvariable [SMulCommClass \ud835\udd5c \ud835\udd5c' E]\n\ninstance sMulCommClass_closedBall_closedBall_closedBall :\n    SMulCommClass (closedBall (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (closedBall (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align smul_comm_class_closed_ball_closed_ball_closed_ball sMulCommClass_closedBall_closedBall_closedBall\n\ninstance sMulCommClass_closedBall_closedBall_ball :\n    SMulCommClass (closedBall (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align smul_comm_class_closed_ball_closed_ball_ball sMulCommClass_closedBall_closedBall_ball\n\ninstance sMulCommClass_sphere_closedBall_closedBall :\n    SMulCommClass (sphere (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (closedBall (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align smul_comm_class_sphere_closed_ball_closed_ball sMulCommClass_sphere_closedBall_closedBall\n\ninstance sMulCommClass_sphere_closedBall_ball :\n    SMulCommClass (sphere (0 : \ud835\udd5c) 1) (closedBall (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align smul_comm_class_sphere_closed_ball_ball sMulCommClass_sphere_closedBall_ball\n\ninstance sMulCommClass_sphere_ball_ball [NormedAlgebra \ud835\udd5c \ud835\udd5c'] :\n    SMulCommClass (sphere (0 : \ud835\udd5c) 1) (ball (0 : \ud835\udd5c') 1) (ball (0 : \ud835\udd5c') 1) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : \ud835\udd5c')\u27e9\n#align smul_comm_class_sphere_ball_ball sMulCommClass_sphere_ball_ball\n\ninstance sMulCommClass_sphere_sphere_closedBall :\n    SMulCommClass (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (closedBall (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align smul_comm_class_sphere_sphere_closed_ball sMulCommClass_sphere_sphere_closedBall\n\ninstance sMulCommClass_sphere_sphere_ball :\n    SMulCommClass (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (ball (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align smul_comm_class_sphere_sphere_ball sMulCommClass_sphere_sphere_ball\n\ninstance sMulCommClass_sphere_sphere_sphere :\n    SMulCommClass (sphere (0 : \ud835\udd5c) 1) (sphere (0 : \ud835\udd5c') 1) (sphere (0 : E) r) :=\n  \u27e8fun a b c => Subtype.ext <| smul_comm (a : \ud835\udd5c) (b : \ud835\udd5c') (c : E)\u27e9\n#align smul_comm_class_sphere_sphere_sphere sMulCommClass_sphere_sphere_sphere\n\nend SMulCommClass\n\nvariable (\ud835\udd5c) [CharZero \ud835\udd5c]\n\ntheorem ne_neg_of_mem_sphere {r : \u211d} (hr : r \u2260 0) (x : sphere (0 : E) r) : x \u2260 -x := fun h =>\n  ne_zero_of_mem_sphere hr x\n    ((self_eq_neg \ud835\udd5c _).mp\n      (by\n        conv_lhs => rw [h]\n        simp))\n#align ne_neg_of_mem_sphere ne_neg_of_mem_sphere\n\ntheorem ne_neg_of_mem_unit_sphere (x : sphere (0 : E) 1) : x \u2260 -x :=\n  ne_neg_of_mem_sphere \ud835\udd5c one_ne_zero x\n#align ne_neg_of_mem_unit_sphere ne_neg_of_mem_unit_sphere\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/NormedSpace/BallAction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7102006319215687}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Floris van Doorn, S\u00e9bastien Gou\u00ebzel, Alex J. Best\n-/\nimport data.int.order.basic\nimport data.list.forall2\n\n/-!\n# Sums and products from lists\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides basic results about `list.prod`, `list.sum`, which calculate the product and sum\nof elements of a list and `list.alternating_prod`, `list.alternating_sum`, their alternating\ncounterparts. These are defined in [`data.list.defs`](./defs).\n-/\n\nvariables {\u03b9 \u03b1 M N P M\u2080 G R : Type*}\n\nnamespace list\nsection monoid\nvariables [monoid M] [monoid N] [monoid P] {l l\u2081 l\u2082 : list M} {a : M}\n\n@[simp, to_additive]\nlemma prod_nil : ([] : list M).prod = 1 := rfl\n\n@[to_additive]\nlemma prod_singleton : [a].prod = a := one_mul a\n\n@[simp, to_additive]\nlemma prod_cons : (a :: l).prod = a * l.prod :=\ncalc (a :: l).prod = foldl (*) (a * 1) l : by simp only [list.prod, foldl_cons, one_mul, mul_one]\n  ... = _ : foldl_assoc\n\n@[simp, to_additive]\nlemma prod_append : (l\u2081 ++ l\u2082).prod = l\u2081.prod * l\u2082.prod :=\ncalc (l\u2081 ++ l\u2082).prod = foldl (*) (foldl (*) 1 l\u2081 * 1) l\u2082 : by simp [list.prod]\n  ... = l\u2081.prod * l\u2082.prod : foldl_assoc\n\n@[to_additive]\nlemma prod_concat : (l.concat a).prod = l.prod * a :=\nby rw [concat_eq_append, prod_append, prod_singleton]\n\n@[simp, to_additive]\nlemma prod_join {l : list (list M)} : l.join.prod = (l.map list.prod).prod :=\nby induction l; [refl, simp only [*, list.join, map, prod_append, prod_cons]]\n\n@[to_additive]\nlemma prod_eq_foldr : l.prod = foldr (*) 1 l :=\nlist.rec_on l rfl $ \u03bb a l ihl, by rw [prod_cons, foldr_cons, ihl]\n\n@[simp, priority 500, to_additive]\ntheorem prod_replicate (n : \u2115) (a : M) : (replicate n a).prod = a ^ n :=\nbegin\n  induction n with n ih,\n  { rw pow_zero, refl },\n  { rw [list.replicate_succ, list.prod_cons, ih, pow_succ] }\nend\n\n@[to_additive sum_eq_card_nsmul]\nlemma prod_eq_pow_card (l : list M) (m : M) (h : \u2200 (x \u2208 l), x = m) :\n  l.prod = m ^ l.length :=\nby rw [\u2190 prod_replicate, \u2190 eq_replicate_length.2 h]\n\n@[to_additive]\nlemma prod_hom_rel (l : list \u03b9) {r : M \u2192 N \u2192 Prop} {f : \u03b9 \u2192 M} {g : \u03b9 \u2192 N} (h\u2081 : r 1 1)\n  (h\u2082 : \u2200 \u2983i a b\u2984, r a b \u2192 r (f i * a) (g i * b)) :\n  r (l.map f).prod (l.map g).prod :=\nlist.rec_on l h\u2081 (\u03bb a l hl, by simp only [map_cons, prod_cons, h\u2082 hl])\n\n@[to_additive]\nlemma prod_hom (l : list M) {F : Type*} [monoid_hom_class F M N] (f : F) :\n  (l.map f).prod = f l.prod :=\nby { simp only [prod, foldl_map, \u2190 map_one f],\n  exact l.foldl_hom _ _ _ 1 (map_mul f) }\n\n@[to_additive]\nlemma prod_hom\u2082 (l : list \u03b9) (f : M \u2192 N \u2192 P)\n  (hf : \u2200 a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f\u2081 : \u03b9 \u2192 M) (f\u2082 : \u03b9 \u2192 N) :\n  (l.map $ \u03bb i, f (f\u2081 i) (f\u2082 i)).prod = f (l.map f\u2081).prod (l.map f\u2082).prod :=\nbegin\n  simp only [prod, foldl_map],\n  convert l.foldl_hom\u2082 (\u03bb a b, f a b) _ _ _ _ _ (\u03bb a b i, _),\n  { exact hf'.symm },\n  { exact hf _ _ _ _ }\nend\n\n@[simp, to_additive]\nlemma prod_map_mul {\u03b1 : Type*} [comm_monoid \u03b1] {l : list \u03b9} {f g : \u03b9 \u2192 \u03b1} :\n  (l.map $ \u03bb i, f i * g i).prod = (l.map f).prod * (l.map g).prod :=\nl.prod_hom\u2082 (*) mul_mul_mul_comm (mul_one _) _ _\n\n@[simp]\nlemma prod_map_neg {\u03b1} [comm_monoid \u03b1] [has_distrib_neg \u03b1] (l : list \u03b1) :\n  (l.map has_neg.neg).prod = (-1) ^ l.length * l.prod :=\nby simpa only [id, neg_mul, one_mul, map_const', prod_replicate, map_id]\n    using @prod_map_mul \u03b1 \u03b1 _ l (\u03bb _, -1) id\n\n@[to_additive]\nlemma prod_map_hom (L : list \u03b9) (f : \u03b9 \u2192 M) {G : Type*} [monoid_hom_class G M N] (g : G) :\n  (L.map (g \u2218 f)).prod = g ((L.map f).prod) :=\nby rw [\u2190 prod_hom, map_map]\n\n@[to_additive]\nlemma prod_is_unit : \u03a0 {L : list M} (u : \u2200 m \u2208 L, is_unit m), is_unit L.prod\n| [] _ := by simp\n| (h :: t) u :=\nbegin\n  simp only [list.prod_cons],\n  exact is_unit.mul (u h (mem_cons_self h t)) (prod_is_unit (\u03bb m mt, u m (mem_cons_of_mem h mt)))\nend\n\n@[to_additive]\nlemma prod_is_unit_iff {\u03b1 : Type*} [comm_monoid \u03b1] {L : list \u03b1} :\n  is_unit L.prod \u2194 \u2200 m \u2208 L, is_unit m :=\nbegin\n  refine \u27e8\u03bb h, _, prod_is_unit\u27e9,\n  induction L with m L ih,\n  { exact \u03bb m' h', false.elim (not_mem_nil m' h'), },\n  rw [prod_cons, is_unit.mul_iff] at h,\n  exact \u03bb m' h', or.elim (eq_or_mem_of_mem_cons h') (\u03bb H, H.substr h.1) (\u03bb H, ih h.2 _ H),\nend\n\n@[simp, to_additive]\nlemma prod_take_mul_prod_drop :\n  \u2200 (L : list M) (i : \u2115), (L.take i).prod * (L.drop i).prod = L.prod\n| [] i := by simp [nat.zero_le]\n| L 0 := by simp\n| (h :: t) (n+1) := by { dsimp, rw [prod_cons, prod_cons, mul_assoc, prod_take_mul_prod_drop] }\n\n@[simp, to_additive]\nlemma prod_take_succ :\n  \u2200 (L : list M) (i : \u2115) (p), (L.take (i + 1)).prod = (L.take i).prod * L.nth_le i p\n| [] i p := by cases p\n| (h :: t) 0 _ := by simp\n| (h :: t) (n+1) _ := by { dsimp, rw [prod_cons, prod_cons, prod_take_succ, mul_assoc] }\n\n/-- A list with product not one must have positive length. -/\n@[to_additive \"A list with sum not zero must have positive length.\"]\nlemma length_pos_of_prod_ne_one (L : list M) (h : L.prod \u2260 1) : 0 < L.length :=\nby { cases L, { contrapose h, simp }, { simp } }\n\n/-- A list with product greater than one must have positive length. -/\n@[to_additive length_pos_of_sum_pos \"A list with positive sum must have positive length.\"]\nlemma length_pos_of_one_lt_prod [preorder M] (L : list M) (h : 1 < L.prod) :\n  0 < L.length :=\nlength_pos_of_prod_ne_one L h.ne'\n\n/-- A list with product less than one must have positive length. -/\n@[to_additive \"A list with negative sum must have positive length.\"]\nlemma length_pos_of_prod_lt_one [preorder M] (L : list M) (h : L.prod < 1) :\n  0 < L.length :=\nlength_pos_of_prod_ne_one L h.ne\n\n@[to_additive]\nlemma prod_update_nth : \u2200 (L : list M) (n : \u2115) (a : M),\n  (L.update_nth n a).prod =\n    (L.take n).prod * (if n < L.length then a else 1) * (L.drop (n + 1)).prod\n| (x :: xs) 0     a := by simp [update_nth]\n| (x :: xs) (i+1) a := by simp [update_nth, prod_update_nth xs i a, mul_assoc]\n| []      _     _ := by simp [update_nth, (nat.zero_le _).not_lt, nat.zero_le]\n\nopen mul_opposite\n\n/-- We'd like to state this as `L.head * L.tail.prod = L.prod`, but because `L.head` relies on an\ninhabited instance to return a garbage value on the empty list, this is not possible.\nInstead, we write the statement in terms of `(L.nth 0).get_or_else 1`.\n-/\n@[to_additive \"We'd like to state this as `L.head + L.tail.sum = L.sum`, but because `L.head`\nrelies on an inhabited instance to return a garbage value on the empty list, this is not possible.\nInstead, we write the statement in terms of `(L.nth 0).get_or_else 0`.\"]\nlemma nth_zero_mul_tail_prod (l : list M) : (l.nth 0).get_or_else 1 * l.tail.prod = l.prod :=\nby cases l; simp\n\n/-- Same as `nth_zero_mul_tail_prod`, but avoiding the `list.head` garbage complication by requiring\nthe list to be nonempty. -/\n@[to_additive \"Same as `nth_zero_add_tail_sum`, but avoiding the `list.head` garbage complication\nby requiring the list to be nonempty.\"]\nlemma head_mul_tail_prod_of_ne_nil [inhabited M] (l : list M) (h : l \u2260 []) :\n  l.head * l.tail.prod = l.prod :=\nby cases l; [contradiction, simp]\n\n@[to_additive]\nlemma _root_.commute.list_prod_right (l : list M) (y : M) (h : \u2200 (x \u2208 l), commute y x) :\n  commute y l.prod :=\nbegin\n  induction l with z l IH,\n  { simp },\n  { rw list.ball_cons at h,\n    rw list.prod_cons,\n    exact commute.mul_right h.1 (IH h.2), }\nend\n\n@[to_additive]\nlemma _root_.commute.list_prod_left (l : list M) (y : M) (h : \u2200 (x \u2208 l), commute x y) :\n  commute l.prod y  :=\n(commute.list_prod_right _ _ $ \u03bb x hx, (h _ hx).symm).symm\n\n@[to_additive sum_le_sum] lemma forall\u2082.prod_le_prod' [preorder M]\n  [covariant_class M M (function.swap (*)) (\u2264)] [covariant_class M M (*) (\u2264)]\n  {l\u2081 l\u2082 : list M} (h : forall\u2082 (\u2264) l\u2081 l\u2082) : l\u2081.prod \u2264 l\u2082.prod :=\nbegin\n  induction h with a b la lb hab ih ih',\n  { refl },\n  { simpa only [prod_cons] using mul_le_mul' hab ih' }\nend\n\n/-- If `l\u2081` is a sublist of `l\u2082` and all elements of `l\u2082` are greater than or equal to one, then\n`l\u2081.prod \u2264 l\u2082.prod`. One can prove a stronger version assuming `\u2200 a \u2208 l\u2082.diff l\u2081, 1 \u2264 a` instead\nof `\u2200 a \u2208 l\u2082, 1 \u2264 a` but this lemma is not yet in `mathlib`. -/\n@[to_additive sum_le_sum \"If `l\u2081` is a sublist of `l\u2082` and all elements of `l\u2082` are nonnegative,\nthen `l\u2081.sum \u2264 l\u2082.sum`. One can prove a stronger version assuming `\u2200 a \u2208 l\u2082.diff l\u2081, 0 \u2264 a` instead\nof `\u2200 a \u2208 l\u2082, 0 \u2264 a` but this lemma is not yet in `mathlib`.\"]\nlemma sublist.prod_le_prod' [preorder M] [covariant_class M M (function.swap (*)) (\u2264)]\n  [covariant_class M M (*) (\u2264)] {l\u2081 l\u2082 : list M} (h : l\u2081 <+ l\u2082) (h\u2081 : \u2200 a \u2208 l\u2082, (1 : M) \u2264 a) :\n  l\u2081.prod \u2264 l\u2082.prod :=\nbegin\n  induction h, { refl },\n  case cons : l\u2081 l\u2082 a ih ih'\n  { simp only [prod_cons, forall_mem_cons] at h\u2081 \u22a2,\n    exact (ih' h\u2081.2).trans (le_mul_of_one_le_left' h\u2081.1) },\n  case cons2 : l\u2081 l\u2082 a ih ih'\n  { simp only [prod_cons, forall_mem_cons] at h\u2081 \u22a2,\n    exact mul_le_mul_left' (ih' h\u2081.2) _ }\nend\n\n@[to_additive sum_le_sum] lemma sublist_forall\u2082.prod_le_prod' [preorder M]\n  [covariant_class M M (function.swap (*)) (\u2264)] [covariant_class M M (*) (\u2264)]\n  {l\u2081 l\u2082 : list M} (h : sublist_forall\u2082 (\u2264) l\u2081 l\u2082) (h\u2081 : \u2200 a \u2208 l\u2082, (1 : M) \u2264 a) :\n  l\u2081.prod \u2264 l\u2082.prod :=\nlet \u27e8l, hall, hsub\u27e9 := sublist_forall\u2082_iff.1 h\nin hall.prod_le_prod'.trans $ hsub.prod_le_prod' h\u2081\n\n@[to_additive sum_le_sum] lemma prod_le_prod' [preorder M]\n  [covariant_class M M (function.swap (*)) (\u2264)] [covariant_class M M (*) (\u2264)]\n  {l : list \u03b9} {f g : \u03b9 \u2192 M} (h : \u2200 i \u2208 l, f i \u2264 g i) :\n  (l.map f).prod \u2264 (l.map g).prod :=\nforall\u2082.prod_le_prod' $ by simpa\n\n@[to_additive sum_lt_sum] lemma prod_lt_prod'\n  [preorder M] [covariant_class M M (*) (<)] [covariant_class M M (*) (\u2264)]\n  [covariant_class M M (function.swap (*)) (<)] [covariant_class M M (function.swap (*)) (\u2264)]\n  {l : list \u03b9} (f g : \u03b9 \u2192 M) (h\u2081 : \u2200 i \u2208 l, f i \u2264 g i) (h\u2082 : \u2203 i \u2208 l, f i < g i) :\n  (l.map f).prod < (l.map g).prod :=\nbegin\n  induction l with i l ihl, { rcases h\u2082 with \u27e8_, \u27e8\u27e9, _\u27e9 },\n  simp only [ball_cons, bex_cons, map_cons, prod_cons] at h\u2081 h\u2082 \u22a2,\n  cases h\u2082,\n  exacts [mul_lt_mul_of_lt_of_le h\u2082 (prod_le_prod' h\u2081.2),\n    mul_lt_mul_of_le_of_lt h\u2081.1 $ ihl h\u2081.2 h\u2082]\nend\n\n@[to_additive] lemma prod_lt_prod_of_ne_nil\n  [preorder M] [covariant_class M M (*) (<)] [covariant_class M M (*) (\u2264)]\n  [covariant_class M M (function.swap (*)) (<)] [covariant_class M M (function.swap (*)) (\u2264)]\n  {l : list \u03b9} (hl : l \u2260 []) (f g : \u03b9 \u2192 M) (hlt : \u2200 i \u2208 l, f i < g i) :\n  (l.map f).prod < (l.map g).prod :=\nprod_lt_prod' f g (\u03bb i hi, (hlt i hi).le) $ (exists_mem_of_ne_nil l hl).imp $ \u03bb i hi, \u27e8hi, hlt i hi\u27e9\n\n@[to_additive sum_le_card_nsmul]\nlemma prod_le_pow_card [preorder M]\n  [covariant_class M M (function.swap (*)) (\u2264)] [covariant_class M M (*) (\u2264)]\n  (l : list M) (n : M) (h : \u2200 (x \u2208 l), x \u2264 n) :\n  l.prod \u2264 n ^ l.length :=\nby simpa only [map_id'', map_const, prod_replicate] using prod_le_prod' h\n\n@[to_additive exists_lt_of_sum_lt] lemma exists_lt_of_prod_lt' [linear_order M]\n  [covariant_class M M (function.swap (*)) (\u2264)] [covariant_class M M (*) (\u2264)] {l : list \u03b9}\n  (f g : \u03b9 \u2192 M) (h : (l.map f).prod < (l.map g).prod) :\n  \u2203 i \u2208 l, f i < g i :=\nby { contrapose! h, exact prod_le_prod' h }\n\n@[to_additive exists_le_of_sum_le]\nlemma exists_le_of_prod_le' [linear_order M] [covariant_class M M (*) (<)]\n  [covariant_class M M (*) (\u2264)] [covariant_class M M (function.swap (*)) (<)]\n  [covariant_class M M (function.swap (*)) (\u2264)] {l : list \u03b9} (hl : l \u2260 [])\n  (f g : \u03b9 \u2192 M) (h : (l.map f).prod \u2264 (l.map g).prod) :\n  \u2203 x \u2208 l, f x \u2264 g x :=\nby { contrapose! h, exact prod_lt_prod_of_ne_nil hl _ _ h }\n\n@[to_additive sum_nonneg]\nlemma one_le_prod_of_one_le [preorder M] [covariant_class M M (*) (\u2264)] {l : list M}\n  (hl\u2081 : \u2200 x \u2208 l, (1 : M) \u2264 x) :\n  1 \u2264 l.prod :=\nbegin\n  -- We don't use `pow_card_le_prod` to avoid assumption\n  -- [covariant_class M M (function.swap (*)) (\u2264)]\n  induction l with hd tl ih, { refl },\n  rw prod_cons,\n  exact one_le_mul (hl\u2081 hd (mem_cons_self hd tl)) (ih (\u03bb x h, hl\u2081 x (mem_cons_of_mem hd h)))\nend\n\nend monoid\n\nsection monoid_with_zero\n\nvariables [monoid_with_zero M\u2080]\n\n/-- If zero is an element of a list `L`, then `list.prod L = 0`. If the domain is a nontrivial\nmonoid with zero with no divisors, then this implication becomes an `iff`, see\n`list.prod_eq_zero_iff`. -/\nlemma prod_eq_zero {L : list M\u2080} (h : (0 : M\u2080) \u2208 L) : L.prod = 0 :=\nbegin\n  induction L with a L ihL,\n  { exact absurd h (not_mem_nil _) },\n  { rw prod_cons,\n    cases (mem_cons_iff _ _ _).1 h with ha hL,\n    exacts [mul_eq_zero_of_left ha.symm _, mul_eq_zero_of_right _ (ihL hL)] }\nend\n\n/-- Product of elements of a list `L` equals zero if and only if `0 \u2208 L`. See also\n`list.prod_eq_zero` for an implication that needs weaker typeclass assumptions. -/\n@[simp] \n\nlemma prod_ne_zero [nontrivial M\u2080] [no_zero_divisors M\u2080] {L : list M\u2080} (hL : (0 : M\u2080) \u2209 L) :\n  L.prod \u2260 0 :=\nmt prod_eq_zero_iff.1 hL\n\nend monoid_with_zero\n\nsection group\nvariables [group G]\n\n/-- This is the `list.prod` version of `mul_inv_rev` -/\n@[to_additive \"This is the `list.sum` version of `add_neg_rev`\"]\nlemma prod_inv_reverse : \u2200 (L : list G), L.prod\u207b\u00b9 = (L.map (\u03bb x, x\u207b\u00b9)).reverse.prod\n| [] := by simp\n| (x :: xs) := by simp [prod_inv_reverse xs]\n\n/-- A non-commutative variant of `list.prod_reverse` -/\n@[to_additive \"A non-commutative variant of `list.sum_reverse`\"]\nlemma prod_reverse_noncomm : \u2200 (L : list G), L.reverse.prod = (L.map (\u03bb x, x\u207b\u00b9)).prod\u207b\u00b9 :=\nby simp [prod_inv_reverse]\n\n/-- Counterpart to `list.prod_take_succ` when we have an inverse operation -/\n@[simp, to_additive /-\"Counterpart to `list.sum_take_succ` when we have an negation operation\"-/]\nlemma prod_drop_succ :\n  \u2200 (L : list G) (i : \u2115) (p), (L.drop (i + 1)).prod = (L.nth_le i p)\u207b\u00b9 * (L.drop i).prod\n| [] i p := false.elim (nat.not_lt_zero _ p)\n| (x :: xs) 0 p := by simp\n| (x :: xs) (i + 1) p := prod_drop_succ xs i _\n\nend group\n\nsection comm_group\nvariables [comm_group G]\n\n/-- This is the `list.prod` version of `mul_inv` -/\n@[to_additive \"This is the `list.sum` version of `add_neg`\"]\nlemma prod_inv : \u2200 (L : list G), L.prod\u207b\u00b9 = (L.map (\u03bb x, x\u207b\u00b9)).prod\n| [] := by simp\n| (x :: xs) := by simp [mul_comm, prod_inv xs]\n\n/-- Alternative version of `list.prod_update_nth` when the list is over a group -/\n@[to_additive /-\"Alternative version of `list.sum_update_nth` when the list is over a group\"-/]\nlemma prod_update_nth' (L : list G) (n : \u2115) (a : G) :\n  (L.update_nth n a).prod =\n    L.prod * (if hn : n < L.length then (L.nth_le n hn)\u207b\u00b9 * a else 1) :=\nbegin\n  refine (prod_update_nth L n a).trans _,\n  split_ifs with hn hn,\n  { rw [mul_comm _ a, mul_assoc a, prod_drop_succ L n hn, mul_comm _ (drop n L).prod,\n      \u2190 mul_assoc (take n L).prod, prod_take_mul_prod_drop, mul_comm a, mul_assoc] },\n  { simp only [take_all_of_le (le_of_not_lt hn), prod_nil, mul_one,\n      drop_eq_nil_of_le ((le_of_not_lt hn).trans n.le_succ)] }\nend\n\nend comm_group\n\n@[to_additive]\nlemma eq_of_prod_take_eq [left_cancel_monoid M] {L L' : list M} (h : L.length = L'.length)\n  (h' : \u2200 i \u2264 L.length, (L.take i).prod = (L'.take i).prod) : L = L' :=\nbegin\n  apply ext_le h (\u03bb i h\u2081 h\u2082, _),\n  have : (L.take (i + 1)).prod = (L'.take (i + 1)).prod := h' _ (nat.succ_le_of_lt h\u2081),\n  rw [prod_take_succ L i h\u2081, prod_take_succ L' i h\u2082, h' i (le_of_lt h\u2081)] at this,\n  convert mul_left_cancel this\nend\n\n@[to_additive]\nlemma monotone_prod_take [canonically_ordered_monoid M] (L : list M) :\n  monotone (\u03bb i, (L.take i).prod) :=\nbegin\n  apply monotone_nat_of_le_succ (\u03bb n, _),\n  cases lt_or_le n L.length with h h,\n  { rw prod_take_succ _ _ h,\n    exact le_self_mul },\n  { simp [take_all_of_le h, take_all_of_le (le_trans h (nat.le_succ _))] }\nend\n\n@[to_additive sum_pos]\nlemma one_lt_prod_of_one_lt [ordered_comm_monoid M] :\n  \u2200 (l : list M) (hl : \u2200 x \u2208 l, (1 : M) < x) (hl\u2082 : l \u2260 []), 1 < l.prod\n| [] _ h := (h rfl).elim\n| [b] h _ := by simpa using h\n| (a :: b :: l) hl\u2081 hl\u2082 :=\nbegin\n  simp only [forall_eq_or_imp, list.mem_cons_iff _ a] at hl\u2081,\n  rw list.prod_cons,\n  apply one_lt_mul_of_lt_of_le' hl\u2081.1,\n  apply le_of_lt ((b :: l).one_lt_prod_of_one_lt hl\u2081.2 (l.cons_ne_nil b)),\nend\n\n@[to_additive]\nlemma single_le_prod [ordered_comm_monoid M] {l : list M} (hl\u2081 : \u2200 x \u2208 l, (1 : M) \u2264 x) :\n  \u2200 x \u2208 l, x \u2264 l.prod :=\nbegin\n  induction l,\n  { simp },\n  simp_rw [prod_cons, forall_mem_cons] at \u22a2 hl\u2081,\n  split,\n  { exact le_mul_of_one_le_right' (one_le_prod_of_one_le hl\u2081.2) },\n  { exact \u03bb x H, le_mul_of_one_le_of_le hl\u2081.1 (l_ih hl\u2081.right x H) },\nend\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\nlemma all_one_of_le_one_le_of_prod_eq_one [ordered_comm_monoid M]\n  {l : list M} (hl\u2081 : \u2200 x \u2208 l, (1 : M) \u2264 x) (hl\u2082 : l.prod = 1) {x : M} (hx : x \u2208 l) :\n  x = 1 :=\nle_antisymm (hl\u2082 \u25b8 single_le_prod hl\u2081 _ hx) (hl\u2081 x hx)\n\n/-- Slightly more general version of `list.prod_eq_one_iff` for a non-ordered `monoid` -/\n@[to_additive \"Slightly more general version of `list.sum_eq_zero_iff`\n  for a non-ordered `add_monoid`\"]\nlemma prod_eq_one [monoid M] {l : list M} (hl : \u2200 (x \u2208 l), x = (1 : M)) : l.prod = 1 :=\nbegin\n  induction l with i l hil,\n  { refl },\n  rw [list.prod_cons, hil (\u03bb x hx, hl _ (mem_cons_of_mem i hx)), hl _ (mem_cons_self i l), one_mul]\nend\n\n@[to_additive]\nlemma exists_mem_ne_one_of_prod_ne_one [monoid M] {l : list M} (h : l.prod \u2260 1) :\n  \u2203 (x \u2208 l), x \u2260 (1 : M) :=\nby simpa only [not_forall] using mt prod_eq_one h\n\n-- TODO: develop theory of tropical rings\nlemma sum_le_foldr_max [add_monoid M] [add_monoid N] [linear_order N] (f : M \u2192 N)\n  (h0 : f 0 \u2264 0) (hadd : \u2200 x y, f (x + y) \u2264 max (f x) (f y)) (l : list M) :\n  f l.sum \u2264 (l.map f).foldr max 0 :=\nbegin\n  induction l with hd tl IH,\n  { simpa using h0 },\n  simp only [list.sum_cons, list.foldr_map, list.foldr] at IH \u22a2,\n  exact (hadd _ _).trans (max_le_max le_rfl IH)\nend\n\n@[simp, to_additive]\nlemma prod_erase [decidable_eq M] [comm_monoid M] {a} :\n  \u2200 {l : list M}, a \u2208 l \u2192 a * (l.erase a).prod = l.prod\n| (b :: l) h :=\n  begin\n    obtain rfl | \u27e8ne, h\u27e9 := decidable.list.eq_or_ne_mem_of_mem h,\n    { simp only [list.erase, if_pos, prod_cons] },\n    { simp only [list.erase, if_neg (mt eq.symm ne), prod_cons, prod_erase h, mul_left_comm a b] }\n  end\n\n@[simp, to_additive]\nlemma prod_map_erase [decidable_eq \u03b9] [comm_monoid M] (f : \u03b9 \u2192 M) {a} :\n  \u2200 {l : list \u03b9}, a \u2208 l \u2192 f a * ((l.erase a).map f).prod = (l.map f).prod\n| (b :: l) h :=\n  begin\n    obtain rfl | \u27e8ne, h\u27e9 := decidable.list.eq_or_ne_mem_of_mem h,\n    { simp only [map, erase_cons_head, prod_cons] },\n    { simp only [map, erase_cons_tail _ ne.symm, prod_cons, prod_map_erase h,\n        mul_left_comm (f a) (f b)], }\n  end\n\nlemma sum_const_nat (m n : \u2115) : sum (replicate m n) = m * n :=\nby rw [sum_replicate, smul_eq_mul]\n\n/-- The product of a list of positive natural numbers is positive,\nand likewise for any nontrivial ordered semiring. -/\nlemma prod_pos [strict_ordered_semiring R] (l : list R) (h : \u2200 a \u2208 l, (0 : R) < a) : 0 < l.prod :=\nbegin\n  induction l with a l ih,\n  { simp },\n  { rw prod_cons,\n    exact mul_pos (h _ $ mem_cons_self _ _) (ih $ \u03bb a ha, h a $ mem_cons_of_mem _ ha) }\nend\n\n/-- A variant of `list.prod_pos` for `canonically_ordered_comm_semiring`. -/\n@[simp]\nlemma _root_.canonically_ordered_comm_semiring.list_prod_pos\n  {\u03b1 : Type*} [canonically_ordered_comm_semiring \u03b1] [nontrivial \u03b1] :\n    \u03a0 {l : list \u03b1}, 0 < l.prod \u2194 (\u2200 x \u2208 l, (0 : \u03b1) < x)\n| [] := \u27e8\u03bb h x hx, hx.elim, \u03bb _, zero_lt_one\u27e9\n| (x :: xs) := by simp_rw [prod_cons, mem_cons_iff, forall_eq_or_imp,\n    canonically_ordered_comm_semiring.mul_pos,\n    _root_.canonically_ordered_comm_semiring.list_prod_pos]\n\n/-!\nSeveral lemmas about sum/head/tail for `list \u2115`.\nThese are hard to generalize well, as they rely on the fact that `default \u2115 = 0`.\nIf desired, we could add a class stating that `default = 0`.\n-/\n\n/-- This relies on `default \u2115 = 0`. -/\nlemma head_add_tail_sum (L : list \u2115) : L.head + L.tail.sum = L.sum :=\nby { cases L, { simp, refl }, { simp } }\n\n/-- This relies on `default \u2115 = 0`. -/\nlemma head_le_sum (L : list \u2115) : L.head \u2264 L.sum := nat.le.intro (head_add_tail_sum L)\n\n/-- This relies on `default \u2115 = 0`. -/\nlemma tail_sum (L : list \u2115) : L.tail.sum = L.sum - L.head :=\nby rw [\u2190 head_add_tail_sum L, add_comm, add_tsub_cancel_right]\n\nsection alternating\nsection\nvariables [has_one \u03b1] [has_mul \u03b1] [has_inv \u03b1]\n\n@[simp, to_additive] lemma alternating_prod_nil : alternating_prod ([] : list \u03b1) = 1 := rfl\n@[simp, to_additive] lemma alternating_prod_singleton (a : \u03b1) : alternating_prod [a] = a := rfl\n\n@[to_additive] lemma alternating_prod_cons_cons' (a b : \u03b1) (l : list \u03b1) :\n  alternating_prod (a :: b :: l) = a * b\u207b\u00b9 * alternating_prod l := rfl\n\nend\n\n@[to_additive] lemma alternating_prod_cons_cons [div_inv_monoid \u03b1] (a b : \u03b1) (l : list \u03b1) :\n  alternating_prod (a :: b :: l) = a / b * alternating_prod l :=\nby rw [div_eq_mul_inv, alternating_prod_cons_cons']\n\nvariables [comm_group \u03b1]\n\n@[to_additive] lemma alternating_prod_cons' :\n  \u2200 (a : \u03b1) (l : list \u03b1), alternating_prod (a :: l) = a * (alternating_prod l)\u207b\u00b9\n| a [] := by rw [alternating_prod_nil, inv_one, mul_one, alternating_prod_singleton]\n| a (b :: l) :=\nby rw [alternating_prod_cons_cons', alternating_prod_cons' b l, mul_inv, inv_inv, mul_assoc]\n\n@[simp, to_additive] lemma alternating_prod_cons (a : \u03b1) (l : list \u03b1) :\n  alternating_prod (a :: l) = a / alternating_prod l :=\nby rw [div_eq_mul_inv, alternating_prod_cons']\n\nend alternating\n\nlemma sum_nat_mod (l : list \u2115) (n : \u2115) : l.sum % n = (l.map (% n)).sum % n :=\nby induction l; simp [nat.add_mod, *]\n\nlemma prod_nat_mod (l : list \u2115) (n : \u2115) : l.prod % n = (l.map (% n)).prod % n :=\nby induction l; simp [nat.mul_mod, *]\n\nlemma sum_int_mod (l : list \u2124) (n : \u2124) : l.sum % n = (l.map (% n)).sum % n :=\nby induction l; simp [int.add_mod, *]\n\nlemma prod_int_mod (l : list \u2124) (n : \u2124) : l.prod % n = (l.map (% n)).prod % n :=\nby induction l; simp [int.mul_mod, *]\n\nend list\n\nsection monoid_hom\n\nvariables [monoid M] [monoid N]\n\n@[to_additive]\nlemma map_list_prod {F : Type*} [monoid_hom_class F M N] (f : F)\n  (l : list M) : f l.prod = (l.map f).prod :=\n(l.prod_hom f).symm\n\nnamespace monoid_hom\n\n/-- Deprecated, use `_root_.map_list_prod` instead. -/\n@[to_additive \"Deprecated, use `_root_.map_list_sum` instead.\"]\nprotected lemma map_list_prod (f : M \u2192* N) (l : list M) :\n  f l.prod = (l.map f).prod :=\nmap_list_prod f l\n\nend monoid_hom\n\nend monoid_hom\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/list/big_operators/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.7101369274495268}}
{"text": "-- Asociatividad_de_la_concatenacion_de_listas.lean\n-- Asociatividad de la concatenaci\u00f3n de listas\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 8 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean la operaci\u00f3n de concatenaci\u00f3n de listas se representa por\n-- (++) y est\u00e1 caracterizada por los siguientes lemas\n--    nil_append  : [] ++ ys = ys\n--    cons_append : (x :: xs) ++ y = x :: (xs ++ ys)\n--\n-- Demostrar que la concatenaci\u00f3n es asociativa; es decir,\n--    xs ++ (ys ++ zs) = (xs ++ ys) ++ zs\n-- ---------------------------------------------------------------------\n\nimport data.list.basic\nimport tactic\nopen list\n\nvariable  {\u03b1 : Type}\nvariable  (x : \u03b1)\nvariables (xs ys zs : list \u03b1)\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nbegin\n  induction xs with a as HI,\n  { calc [] ++ (ys ++ zs)\n         = ys ++ zs                : append.equations._eqn_1 (ys ++ zs)\n     ... = ([] ++ ys) ++ zs        : congr_arg2 (++) (append.equations._eqn_1 ys) rfl, },\n  { calc (a :: as) ++ (ys ++ zs)\n         = a :: (as ++ (ys ++ zs)) : append.equations._eqn_2 a as (ys ++ zs)\n     ... = a :: ((as ++ ys) ++ zs) : congr_arg2 (::) rfl HI\n     ... = (a :: (as ++ ys)) ++ zs : (append.equations._eqn_2 a (as ++ ys) zs).symm\n     ... = ((a :: as) ++ ys) ++ zs : congr_arg2 (++) (append.equations._eqn_2 a as ys).symm rfl, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nbegin\n  induction xs with a as HI,\n  { calc [] ++ (ys ++ zs)\n         = ys ++ zs                : nil_append (ys ++ zs)\n     ... = ([] ++ ys) ++ zs        : congr_arg2 (++) (nil_append ys) rfl, },\n  { calc (a :: as) ++ (ys ++ zs)\n         = a :: (as ++ (ys ++ zs)) : cons_append a as (ys ++ zs)\n     ... = a :: ((as ++ ys) ++ zs) : congr_arg2 (::) rfl HI\n     ... = (a :: (as ++ ys)) ++ zs : (cons_append a (as ++ ys) zs).symm\n     ... = ((a :: as) ++ ys) ++ zs : congr_arg2 (++) (cons_append a as ys).symm rfl, },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nbegin\n  induction xs with a as HI,\n  { calc [] ++ (ys ++ zs)\n         = ys ++ zs                : by rw nil_append\n     ... = ([] ++ ys) ++ zs        : by rw nil_append, },\n  { calc (a :: as) ++ (ys ++ zs)\n         = a :: (as ++ (ys ++ zs)) : by rw cons_append\n     ... = a :: ((as ++ ys) ++ zs) : by rw HI\n     ... = (a :: (as ++ ys)) ++ zs : by rw cons_append\n     ... = ((a :: as) ++ ys) ++ zs : by rw \u2190 cons_append, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nbegin\n  induction xs with a as HI,\n  { calc [] ++ (ys ++ zs)\n         = ys ++ zs                : rfl\n     ... = ([] ++ ys) ++ zs        : rfl, },\n  { calc (a :: as) ++ (ys ++ zs)\n         = a :: (as ++ (ys ++ zs)) : rfl\n     ... = a :: ((as ++ ys) ++ zs) : by rw HI\n     ... = (a :: (as ++ ys)) ++ zs : rfl\n     ... = ((a :: as) ++ ys) ++ zs : rfl, },\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nbegin\n  induction xs with a as HI,\n  { calc [] ++ (ys ++ zs)\n         = ys ++ zs                : by simp\n     ... = ([] ++ ys) ++ zs        : by simp, },\n  { calc (a :: as) ++ (ys ++ zs)\n         = a :: (as ++ (ys ++ zs)) : by simp\n     ... = a :: ((as ++ ys) ++ zs) : congr_arg (cons a) HI\n     ... = (a :: (as ++ ys)) ++ zs : by simp\n     ... = ((a :: as) ++ ys) ++ zs : by simp, },\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nbegin\n  induction xs with a as HI,\n  { by simp, },\n  { by exact (cons_inj a).mpr HI, },\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nbegin\n  induction xs with a as HI,\n  { rw nil_append,\n    rw nil_append, },\n  { rw cons_append,\n    rw HI,\n    rw cons_append,\n    rw cons_append, },\nend\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nlist.rec_on xs\n  ( show [] ++ (ys ++ zs) = ([] ++ ys) ++ zs,\n      from calc\n        [] ++ (ys ++ zs)\n            = ys ++ zs         : by rw nil_append\n        ... = ([] ++ ys) ++ zs : by rw nil_append )\n  ( assume a as,\n    assume HI : as ++ (ys ++ zs) = (as ++ ys) ++ zs,\n    show (a :: as) ++ (ys  ++ zs) = ((a :: as) ++ ys) ++ zs,\n      from calc\n        (a :: as) ++ (ys ++ zs)\n            = a :: (as ++ (ys ++ zs)) : by rw cons_append\n        ... = a :: ((as ++ ys) ++ zs) : by rw HI\n        ... = (a :: (as ++ ys)) ++ zs : by rw cons_append\n        ... = ((a :: as) ++ ys) ++ zs : by rw \u2190 cons_append)\n\n-- 9\u00aa demostraci\u00f3n\nexample :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs :=\nlist.rec_on xs\n  (by simp)\n  (by simp [*])\n\n-- 10\u00aa demostraci\u00f3n\nlemma conc_asoc_1 :\n  \u2200 xs, xs ++ (ys ++ zs) = (xs ++ ys) ++ zs\n| [] := by calc\n    [] ++ (ys ++ zs)\n        = ys ++ zs         : by rw nil_append\n    ... = ([] ++ ys) ++ zs : by rw nil_append\n| (a :: as) := by calc\n    (a :: as) ++ (ys ++ zs)\n        = a :: (as ++ (ys ++ zs)) : by rw cons_append\n    ... = a :: ((as ++ ys) ++ zs) : by rw conc_asoc_1\n    ... = (a :: (as ++ ys)) ++ zs : by rw cons_append\n    ... = ((a :: as) ++ ys) ++ zs : by rw \u2190 cons_append\n\n-- 11\u00aa demostraci\u00f3n\nexample :\n  (xs ++ ys) ++ zs = xs ++ (ys ++ zs) :=\n-- by library_search\nappend_assoc xs ys zs\n\n-- 12\u00aa demostraci\u00f3n\nexample :\n  (xs ++ ys) ++ zs = xs ++ (ys ++ zs) :=\nby induction xs ; simp [*]\n\n-- 13\u00aa demostraci\u00f3n\nexample :\n  (xs ++ ys) ++ zs = xs ++ (ys ++ zs) :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Asociatividad_de_la_concatenacion_de_listas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7101369231466911}}
{"text": "/-\nCopyright (c) 2021 Noam Atar. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Noam Atar\n\n! This file was ported from Lean 3 source module order.prime_ideal\n! leanprover-community/mathlib commit 740acc0e6f9adf4423f92a485d0456fc271482da\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Ideal\nimport Mathlib.Order.PFilter\n\n/-!\n# Prime ideals\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections require more\nstructure, such as a bottom element, a top element, or a join-semilattice structure.\n\n- `Order.Ideal.PrimePair`: A pair of an `ideal` and a `pfilter` which form a partition of `P`.\n  This is useful as giving the data of a prime ideal is the same as giving the data of a prime\n  filter.\n- `Order.Ideal.IsPrime`: a predicate for prime ideals. Dual to the notion of a prime filter.\n- `Order.PFilter.IsPrime`: a predicate for prime filters. Dual to the notion of a prime ideal.\n\n## References\n\n- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>\n\n## Tags\n\nideal, prime\n\n-/\n\n\nopen Order.PFilter\n\nnamespace Order\n\nvariable {P : Type _}\n\nnamespace Ideal\n\n/-- A pair of an `ideal` and a `pfilter` which form a partition of `P`.\n-/\n-- porting note: no attr @[nolint has_nonempty_instance]\nstructure PrimePair (P : Type _) [Preorder P] where\n  I : Ideal P\n  F : PFilter P\n  isCompl_I_F : IsCompl (I : Set P) F\n#align order.ideal.prime_pair Order.Ideal.PrimePair\n\nnamespace PrimePair\n\nvariable [Preorder P] (IF : PrimePair P)\n\n\n\ntheorem compl_F_eq_I : (IF.F : Set P)\u1d9c = IF.I :=\n  IF.isCompl_I_F.eq_compl.symm\nset_option linter.uppercaseLean3 false in\n#align order.ideal.prime_pair.compl_F_eq_I Order.Ideal.PrimePair.compl_F_eq_I\n\ntheorem I_isProper : IsProper IF.I := by\n  cases' IF.F.nonempty with w h\n  apply isProper_of_not_mem (_ : w \u2209 IF.I)\n  rwa [\u2190 IF.compl_I_eq_F] at h\nset_option linter.uppercaseLean3 false in\n#align order.ideal.prime_pair.I_is_proper Order.Ideal.PrimePair.I_isProper\n\nprotected theorem disjoint : Disjoint (IF.I : Set P) IF.F :=\n  IF.isCompl_I_F.Disjoint\n#align order.ideal.prime_pair.disjoint Order.Ideal.PrimePair.disjoint\n\ntheorem I_union_F : (IF.I : Set P) \u222a IF.F = Set.univ :=\n  IF.isCompl_I_F.sup_eq_top\nset_option linter.uppercaseLean3 false in\n#align order.ideal.prime_pair.I_union_F Order.Ideal.PrimePair.I_union_F\n\ntheorem F_union_I : (IF.F : Set P) \u222a IF.I = Set.univ :=\n  IF.isCompl_I_F.symm.sup_eq_top\nset_option linter.uppercaseLean3 false in\n#align order.ideal.prime_pair.F_union_I Order.Ideal.PrimePair.F_union_I\n\nend PrimePair\n\n/-- An ideal `I` is prime if its complement is a filter.\n-/\n@[mk_iff]\nclass IsPrime [Preorder P] (I : Ideal P) extends IsProper I : Prop where\n  compl_filter : IsPFilter ((I : Set P)\u1d9c)\n#align order.ideal.is_prime Order.Ideal.IsPrime\n\nsection Preorder\n\nvariable [Preorder P]\n\n/-- Create an element of type `Order.Ideal.PrimePair` from an ideal satisfying the predicate\n`Order.Ideal.IsPrime`. -/\ndef IsPrime.toPrimePair {I : Ideal P} (h : IsPrime I) : PrimePair P :=\n  { I\n    F := h.compl_filter.toPFilter\n    isCompl_I_F := isCompl_compl }\n#align order.ideal.is_prime.to_prime_pair Order.Ideal.IsPrime.toPrimePair\n\ntheorem PrimePair.I_isPrime (IF : PrimePair P) : IsPrime IF.I :=\n  { IF.I_isProper with\n    compl_filter := by\n      rw [IF.compl_I_eq_F]\n      exact IF.F.isPFilter }\nset_option linter.uppercaseLean3 false in\n#align order.ideal.prime_pair.I_is_prime Order.Ideal.PrimePair.I_isPrime\n\nend Preorder\n\nsection SemilatticeInf\n\nvariable [SemilatticeInf P] {x y : P} {I : Ideal P}\n\ntheorem IsPrime.mem_or_mem (hI : IsPrime I) {x y : P} : x \u2293 y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I := by\n  contrapose!\n  let F := hI.compl_filter.toPFilter\n  show x \u2208 F \u2227 y \u2208 F \u2192 x \u2293 y \u2208 F\n  exact fun h => inf_mem h.1 h.2\n#align order.ideal.is_prime.mem_or_mem Order.Ideal.IsPrime.mem_or_mem\n\ntheorem IsPrime.of_mem_or_mem [IsProper I] (hI : \u2200 {x y : P}, x \u2293 y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I) :\n    IsPrime I := by\n  rw [IsPrime_iff]\n  use \u2039_\u203a\n  refine .of_def ?_ ?_ ?_\n  \u00b7 exact Set.nonempty_compl.2 (I.IsProper_iff.1 \u2039_\u203a)\n  \u00b7 intro x hx y hy\n    exact \u27e8x \u2293 y, fun h => (hI h).elim hx hy, inf_le_left, inf_le_right\u27e9\n  \u00b7 exact @mem_compl_of_ge _ _ _\n#align order.ideal.is_prime.of_mem_or_mem Order.Ideal.IsPrime.of_mem_or_mem\n\ntheorem isPrime_iff_mem_or_mem [IsProper I] : IsPrime I \u2194 \u2200 {x y : P}, x \u2293 y \u2208 I \u2192 x \u2208 I \u2228 y \u2208 I :=\n  \u27e8IsPrime.mem_or_mem, IsPrime.of_mem_or_mem\u27e9\n#align order.ideal.is_prime_iff_mem_or_mem Order.Ideal.isPrime_iff_mem_or_mem\n\nend SemilatticeInf\n\nsection DistribLattice\n\nvariable [DistribLattice P] {I : Ideal P}\n\ninstance (priority := 100) IsMaximal.isPrime [IsMaximal I] : IsPrime I := by\n  rw [isPrime_iff_mem_or_mem]\n  intro x y\n  contrapose!\n  rintro \u27e8hx, hynI\u27e9 hxy\n  apply hynI\n  let J := I \u2294 principal x\n  have hJuniv : (J : Set P) = Set.univ :=\n    IsMaximal.maximal_proper (lt_sup_principal_of_not_mem \u2039_\u203a)\n  have hyJ : y \u2208 \u2191J := Set.eq_univ_iff_forall.mp hJuniv y\n  rw [coe_sup_eq] at hyJ\n  rcases hyJ with \u27e8a, ha, b, hb, hy\u27e9\n  rw [hy]\n  refine' sup_mem ha (I.lower (le_inf hb _) hxy)\n  rw [hy]\n  exact le_sup_right\n#align order.ideal.is_maximal.is_prime Order.Ideal.IsMaximal.isPrime\n\nend DistribLattice\n\nsection BooleanAlgebra\n\nvariable [BooleanAlgebra P] {x : P} {I : Ideal P}\n\ntheorem IsPrime.mem_or_compl_mem (hI : IsPrime I) : x \u2208 I \u2228 x\u1d9c \u2208 I := by\n  apply hI.mem_or_mem\n  rw [inf_compl_eq_bot]\n  exact I.bot_mem\n#align order.ideal.is_prime.mem_or_compl_mem Order.Ideal.IsPrime.mem_or_compl_mem\n\ntheorem IsPrime.mem_compl_of_not_mem (hI : IsPrime I) (hxnI : x \u2209 I) : x\u1d9c \u2208 I :=\n  hI.mem_or_compl_mem.resolve_left hxnI\n#align order.ideal.is_prime.mem_compl_of_not_mem Order.Ideal.IsPrime.mem_compl_of_not_mem\n\ntheorem isPrime_of_mem_or_compl_mem [IsProper I] (h : \u2200 {x : P}, x \u2208 I \u2228 x\u1d9c \u2208 I) : IsPrime I := by\n  simp only [isPrime_iff_mem_or_mem, or_iff_not_imp_left]\n  intro x y hxy hxI\n  have hxcI : x\u1d9c \u2208 I := h.resolve_left hxI\n  have ass : x \u2293 y \u2294 y \u2293 x\u1d9c \u2208 I := sup_mem hxy (I.lower inf_le_right hxcI)\n  rwa [inf_comm, sup_inf_inf_compl] at ass\n#align order.ideal.is_prime_of_mem_or_compl_mem Order.Ideal.isPrime_of_mem_or_compl_mem\n\ntheorem isPrime_iff_mem_or_compl_mem [IsProper I] : IsPrime I \u2194 \u2200 {x : P}, x \u2208 I \u2228 x\u1d9c \u2208 I :=\n  \u27e8fun h _ => h.mem_or_compl_mem, isPrime_of_mem_or_compl_mem\u27e9\n#align order.ideal.is_prime_iff_mem_or_compl_mem Order.Ideal.isPrime_iff_mem_or_compl_mem\n\ninstance (priority := 100) IsPrime.isMaximal [IsPrime I] : IsMaximal I := by\n  simp only [IsMaximal_iff, Set.eq_univ_iff_forall, IsPrime.toIsProper, true_and]\n  intro J hIJ x\n  rcases Set.exists_of_ssubset hIJ with \u27e8y, hyJ, hyI\u27e9\n  suffices ass : x \u2293 y \u2294 x \u2293 y\u1d9c \u2208 J\n  \u00b7 rwa [sup_inf_inf_compl] at ass\n  exact\n    sup_mem (J.lower inf_le_right hyJ)\n      (hIJ.le <| I.lower inf_le_right <| IsPrime.mem_compl_of_not_mem \u2039_\u203a hyI)\n#align order.ideal.is_prime.is_maximal Order.Ideal.IsPrime.isMaximal\n\nend BooleanAlgebra\n\nend Ideal\n\nnamespace PFilter\n\nvariable [Preorder P]\n\n/-- A filter `F` is prime if its complement is an ideal.\n-/\n@[mk_iff]\nclass IsPrime (F : PFilter P) : Prop where\n  compl_ideal : IsIdeal ((F : Set P)\u1d9c)\n#align order.pfilter.is_prime Order.PFilter.IsPrime\n\n/-- Create an element of type `Order.Ideal.PrimePair` from a filter satisfying the predicate\n`Order.PFilter.IsPrime`. -/\ndef IsPrime.toPrimePair {F : PFilter P} (h : IsPrime F) : Ideal.PrimePair P :=\n  { I := h.compl_ideal.toIdeal\n    F\n    isCompl_I_F := isCompl_compl.symm }\n#align order.pfilter.is_prime.to_prime_pair Order.PFilter.IsPrime.toPrimePair\n\ntheorem _root_.Order.Ideal.PrimePair.F_isPrime (IF : Ideal.PrimePair P) : IsPrime IF.F :=\n  {\n    compl_ideal := by\n      rw [IF.compl_F_eq_I]\n      exact IF.I.isIdeal }\nset_option linter.uppercaseLean3 false in\n#align order.ideal.prime_pair.F_is_prime Order.Ideal.PrimePair.F_isPrime\n\nend PFilter\n\nend Order\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/PrimeIdeal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.7101192408771007}}
{"text": "import game.sets.sets_level02 -- hide\n\nnamespace xena -- hide\n\nopen_locale classical -- hide\n\nvariable X : Type -- hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 3 : intersection (\u2229)\n-/\n\n\n/- \nNow prove that for any two sets $A$ and $B$, $A \u2229 B \u2286 A$.\n   \nYou will need to rewrite the following term:\n\n```\nmem_inter_iff : x \u2208 A \u2229 B \u2194 x \u2208 A \u2227 x \u2208 B \n```\n-/\n\n/- Axiom : mem_inter_iff :\nx \u2208 A \u2229 B \u2194 x \u2208 A \u2227 x \u2208 B\n-/\n\n/- Hint : Stuck?\nYou need to start the same way as in the previous levels.\nTry and get yourself into a situation where you have a\n*hypothesis* `hAB : x \u2208 A \u2229 B` and then use `rw mem_inter_iff at hAB`. \n-/\n\n/- Hint: A note on `x \u2208 A \u2227 x \u2208 B \u2192 x \u2208 A`\nBy convention, \u2227 binds more tightly than \u2192\n(i.e. `x \u2208 A \u2227 x \u2208 B \u2192 x \u2208 A` means `(x \u2208 A \u2227 x \u2208 B) \u2192 x \u2208 A`)\n-/\n\n/- Hint : Reminder about `cases` \nThe `cases h with hP hQ` tactic turns `h : P \u2227 Q` into `hP : P` and `hQ : Q`\n-/\n\n/- Hint : The `tauto!` tactic\nThe `tauto!` tactic solves goals in propositional logic (i.e. problems where\nthe relevant hypotheses and goal just involve `\u2227`, `\u2228`, `\u00ac` and `\u2192` and\npropositions -- for example it could easily solve this goal:\n\n```\nh : P \u2227 Q\n\u22a2 P\n```\n-/\n\n/- Lemma\nIf $A$ and $B$ are sets of any type $X$, then\n$$ A \\cap B \\subseteq A.$$\n-/\ntheorem intersection_subset (A B : set X) : A \u2229 B \u2286 A  :=\nbegin\n  rw subset_iff,\n  intro h, -- or cases, assumption\n  intro j,\n  rw mem_inter_iff at j,\n  cases j with h,\n  exact h,\n\n  \nend\n\nend xena -- hide\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/sets/sets_level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7101192310692493}}
{"text": "import game.order.level07\nimport data.real.irrational\n\nopen real\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 8\n\nProve by example that there exist pairs of real numbers\n$a$ and $b$ such that $a \\in \\mathbb{R} \\setminus \\mathbb{Q}$, \n$b \\in \\mathbb{R} \\setminus \\mathbb{Q}$,\nbut their product $a \\cdot b$ is a rational number, $(a \\cdot b) \\in \\mathbb{Q}$.\nYou may use this result in the Lean mathlib library:\n\n`irrational_sqrt_two : irrational (sqrt 2)\n-/\n\n\n/- Lemma\nNot true that for any $a$, $b$, irrational numbers, the product is \nalso an irrational number.\n-/\ntheorem not_prod_irrational : \n    \u00ac ( \u2200 (a b : \u211d), irrational a \u2192  irrational b \u2192 irrational (a*b) ) :=\nbegin\n  intro H,\n  have H2 := H (sqrt 2) (sqrt 2),\n  have H3 := H2 irrational_sqrt_two irrational_sqrt_two,\n  apply H3,\n  existsi (2 : \u211a),\n  simp, norm_num, done\nend\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/order/level08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7100147477568051}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport order.rel_iso\nimport order.lattice_intervals\nimport order.galois_connection\n\n/-!\n# Modular Lattices\nThis file defines Modular Lattices, a kind of lattice useful in algebra.\nFor examples, look to the subobject lattices of abelian groups, submodules, and ideals, or consider\nany distributive lattice.\n\n## Main Definitions\n- `is_modular_lattice` defines a modular lattice to be one such that\n  `x \u2264 z \u2192 (x \u2294 y) \u2293 z \u2264 x \u2294 (y \u2293 z)`\n- `inf_Icc_order_iso_Icc_sup` gives an order isomorphism between the intervals\n  `[a \u2293 b, a]` and `[b, a \u2294 b]`.\n  This corresponds to the diamond (or second) isomorphism theorems of algebra.\n\n## Main Results\n- `is_modular_lattice_iff_inf_sup_inf_assoc`:\n  Modularity is equivalent to the `inf_sup_inf_assoc`: `(x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z`\n- `distrib_lattice.is_modular_lattice`: Distributive lattices are modular.\n\n## To do\n- Relate atoms and coatoms in modular lattices\n\n-/\n\nvariable {\u03b1 : Type*}\n\n/-- A modular lattice is one with a limited associativity between `\u2293` and `\u2294`. -/\nclass is_modular_lattice \u03b1 [lattice \u03b1] : Prop :=\n(sup_inf_le_assoc_of_le : \u2200 {x : \u03b1} (y : \u03b1) {z : \u03b1}, x \u2264 z \u2192 (x \u2294 y) \u2293 z \u2264 x \u2294 (y \u2293 z))\n\nsection is_modular_lattice\nvariables [lattice \u03b1] [is_modular_lattice \u03b1]\n\ntheorem sup_inf_assoc_of_le {x : \u03b1} (y : \u03b1) {z : \u03b1} (h : x \u2264 z) :\n  (x \u2294 y) \u2293 z = x \u2294 (y \u2293 z) :=\nle_antisymm (is_modular_lattice.sup_inf_le_assoc_of_le y h)\n  (le_inf (sup_le_sup_left inf_le_left _) (sup_le h inf_le_right))\n\ntheorem is_modular_lattice.inf_sup_inf_assoc {x y z : \u03b1} :\n  (x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z :=\n(sup_inf_assoc_of_le y inf_le_right).symm\n\nlemma inf_sup_assoc_of_le {x : \u03b1} (y : \u03b1) {z : \u03b1} (h : z \u2264 x) :\n  (x \u2293 y) \u2294 z = x \u2293 (y \u2294 z) :=\nby rw [inf_comm, sup_comm, \u2190 sup_inf_assoc_of_le y h, inf_comm, sup_comm]\n\ninstance : is_modular_lattice \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb x y z xz, le_of_eq (by { rw [inf_comm, sup_comm, eq_comm, inf_comm, sup_comm],\n  convert sup_inf_assoc_of_le (order_dual.of_dual y) (order_dual.dual_le.2 xz) })\u27e9\n\nvariables {x y z : \u03b1}\n\ntheorem is_modular_lattice.sup_inf_sup_assoc :\n  (x \u2294 z) \u2293 (y \u2294 z) = ((x \u2294 z) \u2293 y) \u2294 z :=\n@is_modular_lattice.inf_sup_inf_assoc \u03b1\u1d52\u1d48 _ _ _ _ _\n\ntheorem eq_of_le_of_inf_le_of_sup_le (hxy : x \u2264 y) (hinf : y \u2293 z \u2264 x \u2293 z) (hsup : y \u2294 z \u2264 x \u2294 z) :\n  x = y :=\nle_antisymm hxy $\n  have h : y \u2264 x \u2294 z,\n    from calc y \u2264 y \u2294 z : le_sup_left\n      ... \u2264 x \u2294 z : hsup,\n  calc y \u2264 (x \u2294 z) \u2293 y : le_inf h le_rfl\n    ... = x \u2294 (z \u2293 y) : sup_inf_assoc_of_le _ hxy\n    ... \u2264 x \u2294 (z \u2293 x) : sup_le_sup_left\n      (by rw [inf_comm, @inf_comm _ _ z]; exact hinf) _\n    ... \u2264 x : sup_le le_rfl inf_le_right\n\ntheorem sup_lt_sup_of_lt_of_inf_le_inf (hxy : x < y) (hinf : y \u2293 z \u2264 x \u2293 z) : x \u2294 z < y \u2294 z :=\nlt_of_le_of_ne\n  (sup_le_sup_right (le_of_lt hxy) _)\n  (\u03bb hsup, ne_of_lt hxy $ eq_of_le_of_inf_le_of_sup_le (le_of_lt hxy) hinf\n    (le_of_eq hsup.symm))\n\ntheorem inf_lt_inf_of_lt_of_sup_le_sup (hxy : x < y) (hinf : y \u2294 z \u2264 x \u2294 z) : x \u2293 z < y \u2293 z :=\n@sup_lt_sup_of_lt_of_inf_le_inf \u03b1\u1d52\u1d48 _ _ _ _ _ hxy hinf\n\n/-- A generalization of the theorem that if `N` is a submodule of `M` and\n  `N` and `M / N` are both Artinian, then `M` is Artinian. -/\ntheorem well_founded_lt_exact_sequence\n  {\u03b2 \u03b3 : Type*} [partial_order \u03b2] [preorder \u03b3]\n  (h\u2081 : well_founded ((<) : \u03b2 \u2192 \u03b2 \u2192 Prop))\n  (h\u2082 : well_founded ((<) : \u03b3 \u2192 \u03b3 \u2192 Prop))\n  (K : \u03b1) (f\u2081 : \u03b2 \u2192 \u03b1) (f\u2082 : \u03b1 \u2192 \u03b2) (g\u2081 : \u03b3 \u2192 \u03b1) (g\u2082 : \u03b1 \u2192 \u03b3)\n  (gci : galois_coinsertion f\u2081 f\u2082)\n  (gi : galois_insertion g\u2082 g\u2081)\n  (hf : \u2200 a, f\u2081 (f\u2082 a) = a \u2293 K)\n  (hg : \u2200 a, g\u2081 (g\u2082 a) = a \u2294 K) :\n  well_founded ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\nsubrelation.wf\n  (\u03bb A B hAB, show prod.lex (<) (<) (f\u2082 A, g\u2082 A) (f\u2082 B, g\u2082 B),\n    begin\n      simp only [prod.lex_def, lt_iff_le_not_le, \u2190 gci.l_le_l_iff,\n        \u2190 gi.u_le_u_iff, hf, hg, le_antisymm_iff],\n      simp only [gci.l_le_l_iff, gi.u_le_u_iff, \u2190 lt_iff_le_not_le, \u2190 le_antisymm_iff],\n      cases lt_or_eq_of_le (inf_le_inf_right K (le_of_lt hAB)) with h h,\n      { exact or.inl h },\n      { exact or.inr \u27e8h, sup_lt_sup_of_lt_of_inf_le_inf hAB (le_of_eq h.symm)\u27e9 }\n    end)\n  (inv_image.wf _ (prod.lex_wf h\u2081 h\u2082))\n\n/-- A generalization of the theorem that if `N` is a submodule of `M` and\n  `N` and `M / N` are both Noetherian, then `M` is Noetherian.  -/\ntheorem well_founded_gt_exact_sequence\n  {\u03b2 \u03b3 : Type*} [preorder \u03b2] [partial_order \u03b3]\n  (h\u2081 : well_founded ((>) : \u03b2 \u2192 \u03b2 \u2192 Prop))\n  (h\u2082 : well_founded ((>) : \u03b3 \u2192 \u03b3 \u2192 Prop))\n  (K : \u03b1) (f\u2081 : \u03b2 \u2192 \u03b1) (f\u2082 : \u03b1 \u2192 \u03b2) (g\u2081 : \u03b3 \u2192 \u03b1) (g\u2082 : \u03b1 \u2192 \u03b3)\n  (gci : galois_coinsertion f\u2081 f\u2082)\n  (gi : galois_insertion g\u2082 g\u2081)\n  (hf : \u2200 a, f\u2081 (f\u2082 a) = a \u2293 K)\n  (hg : \u2200 a, g\u2081 (g\u2082 a) = a \u2294 K) :\n  well_founded ((>) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n@well_founded_lt_exact_sequence \u03b1\u1d52\u1d48 _ _ \u03b3\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ h\u2082 h\u2081 K g\u2081 g\u2082 f\u2081 f\u2082 gi.dual gci.dual hg hf\n\n/-- The diamond isomorphism between the intervals `[a \u2293 b, a]` and `[b, a \u2294 b]` -/\ndef inf_Icc_order_iso_Icc_sup (a b : \u03b1) : set.Icc (a \u2293 b) a \u2243o set.Icc b (a \u2294 b) :=\n{ to_fun := \u03bb x, \u27e8x \u2294 b, \u27e8le_sup_right, sup_le_sup_right x.prop.2 b\u27e9\u27e9,\n  inv_fun := \u03bb x, \u27e8a \u2293 x, \u27e8inf_le_inf_left a x.prop.1, inf_le_left\u27e9\u27e9,\n  left_inv := \u03bb x, subtype.ext (by { change a \u2293 (\u2191x \u2294 b) = \u2191x,\n    rw [sup_comm, \u2190 inf_sup_assoc_of_le _ x.prop.2, sup_eq_right.2 x.prop.1] }),\n  right_inv := \u03bb x, subtype.ext (by { change a \u2293 \u2191x \u2294 b = \u2191x,\n    rw [inf_comm, inf_sup_assoc_of_le _ x.prop.1, inf_eq_left.2 x.prop.2] }),\n  map_rel_iff' := \u03bb x y, begin\n    simp only [subtype.mk_le_mk, equiv.coe_fn_mk, and_true, le_sup_right],\n    rw [\u2190 subtype.coe_le_coe],\n    refine \u27e8\u03bb h, _, \u03bb h, sup_le_sup_right h _\u27e9,\n    rw [\u2190 sup_eq_right.2 x.prop.1, inf_sup_assoc_of_le _ x.prop.2, sup_comm,\n      \u2190 sup_eq_right.2 y.prop.1, inf_sup_assoc_of_le _ y.prop.2, @sup_comm _ _ b],\n    exact inf_le_inf_left _ h\n  end }\nend is_modular_lattice\n\nnamespace is_compl\nvariables [lattice \u03b1] [bounded_order \u03b1] [is_modular_lattice \u03b1]\n\n/-- The diamond isomorphism between the intervals `set.Iic a` and `set.Ici b`. -/\ndef Iic_order_iso_Ici {a b : \u03b1} (h : is_compl a b) : set.Iic a \u2243o set.Ici b :=\n(order_iso.set_congr (set.Iic a) (set.Icc (a \u2293 b) a) (h.inf_eq_bot.symm \u25b8 set.Icc_bot.symm)).trans $\n  (inf_Icc_order_iso_Icc_sup a b).trans\n  (order_iso.set_congr (set.Icc b (a \u2294 b)) (set.Ici b) (h.sup_eq_top.symm \u25b8 set.Icc_top))\n\nend is_compl\n\ntheorem is_modular_lattice_iff_inf_sup_inf_assoc [lattice \u03b1] :\n  is_modular_lattice \u03b1 \u2194 \u2200 (x y z : \u03b1), (x \u2293 z) \u2294 (y \u2293 z) = ((x \u2293 z) \u2294 y) \u2293 z :=\n\u27e8\u03bb h, @is_modular_lattice.inf_sup_inf_assoc _ _ h, \u03bb h, \u27e8\u03bb x y z xz, by rw [\u2190 inf_eq_left.2 xz, h]\u27e9\u27e9\n\nnamespace distrib_lattice\n\n@[priority 100]\ninstance [distrib_lattice \u03b1] : is_modular_lattice \u03b1 :=\n\u27e8\u03bb x y z xz, by rw [inf_sup_right, inf_eq_left.2 xz]\u27e9\n\nend distrib_lattice\n\ntheorem disjoint.disjoint_sup_right_of_disjoint_sup_left\n  [lattice \u03b1] [order_bot \u03b1] [is_modular_lattice \u03b1] {a b c : \u03b1}\n  (h : disjoint a b) (hsup : disjoint (a \u2294 b) c) :\n  disjoint a (b \u2294 c) :=\nbegin\n  rw [disjoint, \u2190 h.eq_bot, sup_comm],\n  apply le_inf inf_le_left,\n  apply (inf_le_inf_right (c \u2294 b) le_sup_right).trans,\n  rw [sup_comm, is_modular_lattice.sup_inf_sup_assoc, hsup.eq_bot, bot_sup_eq]\nend\n\ntheorem disjoint.disjoint_sup_left_of_disjoint_sup_right\n  [lattice \u03b1] [order_bot \u03b1] [is_modular_lattice \u03b1] {a b c : \u03b1}\n  (h : disjoint b c) (hsup : disjoint a (b \u2294 c)) :\n  disjoint (a \u2294 b) c :=\nbegin\n  rw [disjoint.comm, sup_comm],\n  apply disjoint.disjoint_sup_right_of_disjoint_sup_left h.symm,\n  rwa [sup_comm, disjoint.comm] at hsup,\nend\n\nnamespace is_modular_lattice\n\nvariables [lattice \u03b1] [is_modular_lattice \u03b1] {a : \u03b1}\n\ninstance is_modular_lattice_Iic : is_modular_lattice (set.Iic a) :=\n\u27e8\u03bb x y z xz, (sup_inf_le_assoc_of_le (y : \u03b1) xz : (\u2191x \u2294 \u2191y) \u2293 \u2191z \u2264 \u2191x \u2294 \u2191y \u2293 \u2191z)\u27e9\n\ninstance is_modular_lattice_Ici : is_modular_lattice (set.Ici a) :=\n\u27e8\u03bb x y z xz, (sup_inf_le_assoc_of_le (y : \u03b1) xz : (\u2191x \u2294 \u2191y) \u2293 \u2191z \u2264 \u2191x \u2294 \u2191y \u2293 \u2191z)\u27e9\n\nsection is_complemented\nvariables [bounded_order \u03b1] [is_complemented \u03b1]\n\ninstance is_complemented_Iic : is_complemented (set.Iic a) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, let \u27e8y, hy\u27e9 := exists_is_compl x in\n  \u27e8\u27e8y \u2293 a, set.mem_Iic.2 inf_le_right\u27e9, begin\n    split,\n    { change x \u2293 (y \u2293 a) \u2264 \u22a5, -- improve lattice subtype API\n      rw \u2190 inf_assoc,\n      exact le_trans inf_le_left hy.1 },\n    { change a \u2264 x \u2294 (y \u2293 a), -- improve lattice subtype API\n      rw [\u2190 sup_inf_assoc_of_le _ (set.mem_Iic.1 hx), top_le_iff.1 hy.2, top_inf_eq] }\n  end\u27e9\u27e9\n\ninstance is_complemented_Ici : is_complemented (set.Ici a) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, let \u27e8y, hy\u27e9 := exists_is_compl x in\n  \u27e8\u27e8y \u2294 a, set.mem_Ici.2 le_sup_right\u27e9, begin\n    split,\n    { change x \u2293 (y \u2294 a) \u2264 a, -- improve lattice subtype API\n      rw [\u2190 inf_sup_assoc_of_le _ (set.mem_Ici.1 hx),  le_bot_iff.1 hy.1, bot_sup_eq] },\n    { change \u22a4 \u2264 x \u2294 (y \u2294 a), -- improve lattice subtype API\n      rw \u2190 sup_assoc,\n      exact le_trans hy.2 le_sup_left }\n  end\u27e9\u27e9\n\nend is_complemented\n\nend is_modular_lattice\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/modular_lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7099532346915871}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.calculus.mean_value\nimport data.nat.parity\nimport analysis.special_functions.pow\n\n/-!\n# Collection of convex functions\n\nIn this file we prove that the following functions are convex:\n\n* `convex_on_exp` : the exponential function is convex on $(-\u221e, +\u221e)$;\n* `convex_on_pow_of_even` : given an even natural number $n$, the function $f(x)=x^n$\n  is convex on $(-\u221e, +\u221e)$;\n* `convex_on_pow` : for a natural $n$, the function $f(x)=x^n$ is convex on $[0, +\u221e)$;\n* `convex_on_fpow` : for an integer $m$, the function $f(x)=x^m$ is convex on $(0, +\u221e)$.\n* `convex_on_rpow : \u2200 p : \u211d, 1 \u2264 p \u2192 convex_on (Ici 0) (\u03bb x, x ^ p)`\n* `concave_on_log_Ioi` and `concave_on_log_Iio`: log is concave on `Ioi 0` and `Iio 0` respectively.\n-/\n\nopen real set\nopen_locale big_operators\n\n/-- `exp` is convex on the whole real line -/\nlemma convex_on_exp : convex_on univ exp :=\nconvex_on_univ_of_deriv2_nonneg differentiable_exp (by simp)\n  (assume x, (iter_deriv_exp 2).symm \u25b8 le_of_lt (exp_pos x))\n\n/-- `x^n`, `n : \u2115` is convex on the whole real line whenever `n` is even -/\nlemma convex_on_pow_of_even {n : \u2115} (hn : even n) : convex_on set.univ (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_univ_of_deriv2_nonneg differentiable_pow,\n  { simp only [deriv_pow', differentiable.mul, differentiable_const, differentiable_pow] },\n  { intro x,\n    rcases nat.even.sub_even hn (nat.even_bit0 1) with \u27e8k, hk\u27e9,\n    simp only [iter_deriv_pow, finset.prod_range_succ, finset.prod_range_zero, nat.sub_zero,\n      mul_one, hk, pow_mul', sq],\n    exact mul_nonneg (nat.cast_nonneg _) (mul_self_nonneg _) }\nend\n\n/-- `x^n`, `n : \u2115` is convex on `[0, +\u221e)` for all `n` -/\nlemma convex_on_pow (n : \u2115) : convex_on (Ici 0) (\u03bb x : \u211d, x^n) :=\nbegin\n  apply convex_on_of_deriv2_nonneg (convex_Ici _) (continuous_pow n).continuous_on;\n    simp only [interior_Ici, differentiable_on_pow, deriv_pow',\n      differentiable_on_const, differentiable_on.mul, iter_deriv_pow],\n  intros x hx,\n  exact mul_nonneg (nat.cast_nonneg _) (pow_nonneg (le_of_lt hx) _)\nend\n\nlemma finset.prod_nonneg_of_card_nonpos_even\n  {\u03b1 \u03b2 : Type*} [linear_ordered_comm_ring \u03b2]\n  {f : \u03b1 \u2192 \u03b2} [decidable_pred (\u03bb x, f x \u2264 0)]\n  {s : finset \u03b1} (h0 : even (s.filter (\u03bb x, f x \u2264 0)).card) :\n  0 \u2264 \u220f x in s, f x :=\ncalc 0 \u2264 (\u220f x in s, ((if f x \u2264 0 then (-1:\u03b2) else 1) * f x)) :\n  finset.prod_nonneg (\u03bb x _, by\n    { split_ifs with hx hx, by simp [hx], simp at hx \u22a2, exact le_of_lt hx })\n... = _ : by rw [finset.prod_mul_distrib, finset.prod_ite, finset.prod_const_one,\n  mul_one, finset.prod_const, neg_one_pow_eq_pow_mod_two, nat.even_iff.1 h0, pow_zero, one_mul]\n\nlemma int_prod_range_nonneg (m : \u2124) (n : \u2115) (hn : even n) :\n  0 \u2264 \u220f k in finset.range n, (m - k) :=\nbegin\n  cases (le_or_lt \u2191n m) with hnm hmn,\n  { exact finset.prod_nonneg (\u03bb k hk, sub_nonneg.2 (le_trans\n      (int.coe_nat_le.2 $ le_of_lt $ finset.mem_range.1 hk) hnm)) },\n  cases le_or_lt 0 m with hm hm,\n  { lift m to \u2115 using hm,\n    exact le_of_eq (eq.symm $ finset.prod_eq_zero\n      (finset.mem_range.2 $ int.coe_nat_lt.1 hmn) (sub_self _)) },\n  clear hmn,\n  apply finset.prod_nonneg_of_card_nonpos_even,\n  convert hn,\n  convert finset.card_range n,\n  ext k,\n  simp only [finset.mem_filter, finset.mem_range],\n  refine \u27e8and.left, \u03bb hk, \u27e8hk, sub_nonpos.2 $ le_trans (le_of_lt hm) _\u27e9\u27e9,\n  exact int.coe_nat_nonneg k\nend\n\n/-- `x^m`, `m : \u2124` is convex on `(0, +\u221e)` for all `m` -/\nlemma convex_on_fpow (m : \u2124) : convex_on (Ioi 0) (\u03bb x : \u211d, x^m) :=\nbegin\n  apply convex_on_of_deriv2_nonneg (convex_Ioi 0); try { rw [interior_Ioi] },\n  { exact (differentiable_on_fpow $ lt_irrefl _).continuous_on },\n  { exact differentiable_on_fpow (lt_irrefl _) },\n  { have : eq_on (deriv (\u03bbx:\u211d, x^m)) (\u03bbx, \u2191m * x^(m-1)) (Ioi 0),\n      from \u03bb x hx, deriv_fpow (ne_of_gt hx),\n    refine (differentiable_on_congr this).2 _,\n    exact (differentiable_on_fpow (lt_irrefl _)).const_mul _ },\n  { intros x hx,\n    simp only [iter_deriv_fpow (ne_of_gt hx)],\n    refine mul_nonneg (int.cast_nonneg.2 _) (fpow_nonneg (le_of_lt hx) _),\n    exact int_prod_range_nonneg _ _ (nat.even_bit0 1) }\nend\n\nlemma convex_on_rpow {p : \u211d} (hp : 1 \u2264 p) : convex_on (Ici 0) (\u03bb x : \u211d, x^p) :=\nbegin\n  have A : deriv (\u03bb (x : \u211d), x ^ p) = \u03bb x, p * x^(p-1), by { ext x, simp [hp] },\n  apply convex_on_of_deriv2_nonneg (convex_Ici 0),\n  { apply (continuous_rpow_of_pos (\u03bb _, lt_of_lt_of_le zero_lt_one hp)\n      continuous_id continuous_const).continuous_on },\n  { apply differentiable.differentiable_on, simp [hp] },\n  { rw A,\n    assume x hx,\n    replace hx : x \u2260 0, by { simp at hx, exact ne_of_gt hx },\n    simp [differentiable_at.differentiable_within_at, hx] },\n  { assume x hx,\n    replace hx : 0 < x, by simpa using hx,\n    suffices : 0 \u2264 p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],\n    apply mul_nonneg (le_trans zero_le_one hp),\n    exact mul_nonneg (sub_nonneg_of_le hp) (rpow_nonneg_of_nonneg (le_of_lt hx) _) }\nend\n\nlemma concave_on_log_Ioi : concave_on (Ioi 0) log :=\nbegin\n  have h\u2081 : Ioi 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { intros x hx hx',\n    rw [mem_singleton_iff] at hx',\n    rw [hx'] at hx,\n    exact lt_irrefl 0 hx },\n  refine concave_on_open_of_deriv2_nonpos (convex_Ioi 0) is_open_Ioi _ _ _,\n  { exact differentiable_on_log.mono h\u2081 },\n  { refine ((times_cont_diff_on_log.deriv_of_open _ le_top).differentiable_on le_top).mono h\u2081,\n    exact is_open_compl_singleton },\n  { intros x hx,\n    rw [function.iterate_succ, function.iterate_one],\n    change (deriv (deriv log)) x \u2264 0,\n    rw [deriv_log', deriv_inv (show x \u2260 0, by {rintro rfl, exact lt_irrefl 0 hx})],\n    exact neg_nonpos.mpr (inv_nonneg.mpr (sq_nonneg x)) }\nend\n\nlemma concave_on_log_Iio : concave_on (Iio 0) log :=\nbegin\n  have h\u2081 : Iio 0 \u2286 ({0} : set \u211d)\u1d9c,\n  { intros x hx hx',\n    rw [mem_singleton_iff] at hx',\n    rw [hx'] at hx,\n    exact lt_irrefl 0 hx },\n  refine concave_on_open_of_deriv2_nonpos (convex_Iio 0) is_open_Iio _ _ _,\n  { exact differentiable_on_log.mono h\u2081 },\n  { refine ((times_cont_diff_on_log.deriv_of_open _ le_top).differentiable_on le_top).mono h\u2081,\n    exact is_open_compl_singleton },\n  { intros x hx,\n    rw [function.iterate_succ, function.iterate_one],\n    change (deriv (deriv log)) x \u2264 0,\n    rw [deriv_log', deriv_inv (show x \u2260 0, by {rintro rfl, exact lt_irrefl 0 hx})],\n    exact neg_nonpos.mpr (inv_nonneg.mpr (sq_nonneg x)) }\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/convex/specific_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451416, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.7099532315591671}}
{"text": "import data.set.lattice\n\nopen set function\n\nuniverses u1 u2 u3\nvariable  {\u03b1 : Type u1}\nvariable  {\u03b2 : Type u2}\nvariable  {I : Type u3}\nvariable  f : \u03b1 \u2192 \u03b2\nvariable  A : I \u2192 set \u03b1\nvariable  B : I \u2192 set \u03b2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    f '' (\u22c3 i, A i) = \u22c3 i, f '' A i\n-- ----------------------------------------------------------------------\n\nexample : f '' (\u22c3 i, A i) = \u22c3 i, f '' A i :=\nbegin\n  ext y, \n  simp,\n  split,\n  { rintros \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9,\n    use [i, x, xAi, fxeq] },\n  { rintros \u27e8i, x, xAi, fxeq\u27e9,\n    exact \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9 },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u1,\n\u03b2 : Type u2,\nI : Type u3,\nf : \u03b1 \u2192 \u03b2,\nA : I \u2192 set \u03b1\n\u22a2 (f '' \u22c3 (i : I), A i) = \u22c3 (i : I), f '' A i\n  >> ext y, \ny : \u03b2\n\u22a2 (y \u2208 f '' \u22c3 (i : I), A i) \u2194 y \u2208 \u22c3 (i : I), f '' A i\n  >> simp,\n\u22a2 (\u2203 (x : \u03b1), (\u2203 (i : I), x \u2208 A i) \u2227 f x = y) \u2194 \n  \u2203 (i : I) (x : \u03b1), x \u2208 A i \u2227 f x = y\n  >> split,\n| \u22a2 (\u2203 (x : \u03b1), (\u2203 (i : I), x \u2208 A i) \u2227 f x = y) \u2192 \n|   (\u2203 (i : I) (x : \u03b1), x \u2208 A i \u2227 f x = y)\n|   >> { rintros \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9,\n| x : \u03b1,\n| fxeq : f x = y,\n| i : I,\n| xAi : x \u2208 A i\n| \u22a2 \u2203 (i : I) (x : \u03b1), x \u2208 A i \u2227 f x = y\n|   >>   use [i, x, xAi, fxeq] },\n\u22a2 (\u2203 (i : I) (x : \u03b1), x \u2208 A i \u2227 f x = y) \u2192 \n  (\u2203 (x : \u03b1), (\u2203 (i : I), x \u2208 A i) \u2227 f x = y)\n  >> { rintros \u27e8i, x, xAi, fxeq\u27e9,\ni : I,\nx : \u03b1,\nxAi : x \u2208 A i,\nfxeq : f x = y\n\u22a2 \u2203 (x : \u03b1), (\u2203 (i : I), x \u2208 A i) \u2227 f x = y\n  >>   exact \u27e8x, \u27e8i, xAi\u27e9, fxeq\u27e9 },\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i\n-- ----------------------------------------------------------------------\n\nexample : f '' (\u22c2 i, A i) \u2286 \u22c2 i, f '' A i :=\nbegin\n  intro y, \n  simp,\n  intros x h fxeq i,\n  use [x, h i, fxeq],\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u1,\n\u03b2 : Type u2,\nI : Type u3,\nf : \u03b1 \u2192 \u03b2,\nA : I \u2192 set \u03b1\n\u22a2 (f '' \u22c2 (i : I), A i) \u2286 \u22c2 (i : I), f '' A i\n  >> intro y, \ny : \u03b2\n\u22a2 (y \u2208 f '' \u22c2 (i : I), A i) \u2192 (y \u2208 \u22c2 (i : I), f '' A i)\n  >> simp,\n\u22a2 \u2200 (x : \u03b1), (\u2200 (i : I), x \u2208 A i) \u2192 f x = y \u2192 \n  \u2200 (i : I), \u2203 (x : \u03b1), x \u2208 A i \u2227 f x = y\n  >> intros x h fxeq i,\nx : \u03b1,\nh : \u2200 (i : I), x \u2208 A i,\nfxeq : f x = y,\ni : I\n\u22a2 \u2203 (x : \u03b1), x \u2208 A i \u2227 f x = y\n  >> use [x, h i, fxeq],\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es inyectiva e I no vac\u00edo, entonces\n--    (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i)\n-- ----------------------------------------------------------------------\n\nexample \n  (i : I) \n  (injf : injective f) \n  : (\u22c2 i, f '' A i) \u2286 f '' (\u22c2 i, A i) :=\nbegin\n  intro y, \n  simp,\n  intro h,\n  rcases h i with \u27e8x, xAi, fxeq\u27e9,\n  use x, \n  split,\n  { intro i',\n    rcases h i' with \u27e8x', x'Ai, fx'eq\u27e9,\n    have : f x = f x', by rw [fxeq, fx'eq],\n    have : x = x', from injf this,\n    rw this,\n    exact x'Ai },\n  { exact fxeq },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u1,\n\u03b2 : Type u2,\nI : Type u3,\nf : \u03b1 \u2192 \u03b2,\nA : I \u2192 set \u03b1,\ni : I,\ninjf : injective f\n\u22a2 (\u22c2 (i : I), f '' A i) \u2286 f '' \u22c2 (i : I), A i\n  >> intro y, \ny : \u03b2\n\u22a2 (y \u2208 \u22c2 (i : I), f '' A i) \u2192 (y \u2208 f '' \u22c2 (i : I), A i)\n  >> simp,\n\u22a2 (\u2200 (i : I), \u2203 (x : \u03b1), x \u2208 A i \u2227 f x = y) \u2192 \n  (\u2203 (x : \u03b1), (\u2200 (i : I), x \u2208 A i) \u2227 f x = y)\n  >> intro h,\nh : \u2200 (i : I), \u2203 (x : \u03b1), x \u2208 A i \u2227 f x = y\n\u22a2 \u2203 (x : \u03b1), (\u2200 (i : I), x \u2208 A i) \u2227 f x = y\n  >> rcases h i with \u27e8x, xAi, fxeq\u27e9,\nx : \u03b1,\nxAi : x \u2208 A i,\nfxeq : f x = y\n\u22a2 \u2203 (x : \u03b1), (\u2200 (i : I), x \u2208 A i) \u2227 f x = y\n  >> use x, \n\u22a2 (\u2200 (i : I), x \u2208 A i) \u2227 f x = y\n  >> split,\n| \u22a2 \u2200 (i : I), x \u2208 A i\n|   >> { intro i',\n| i' : I\n| \u22a2 x \u2208 A i'\n|   >>   rcases h i' with \u27e8x', x'Ai, fx'eq\u27e9,\n| i' : I,\n| x' : \u03b1,\n| x'Ai : x' \u2208 A i',\n| fx'eq : f x' = y\n| \u22a2 x \u2208 A i'\n|   >>   have : f x = f x', by rw [fxeq, fx'eq],\n| this : f x = f x'\n| \u22a2 x \u2208 A i'\n|   >>   have : x = x', from injf this,\n| this : x = x'\n| \u22a2 x \u2208 A i'\n|   >>   rw this,\n| \u22a2 x' \u2208 A i'\n|   >>   exact x'Ai },\n\u22a2 f x = y\n  >> { exact fxeq },\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i)\n-- ----------------------------------------------------------------------\n\nexample : f \u207b\u00b9' (\u22c3 i, B i) = \u22c3 i, f \u207b\u00b9' (B i) :=\nby { ext x, simp }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i)\n-- ----------------------------------------------------------------------\n\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nby { ext x, simp }\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Ejercicios_de_imagenes_y_uniones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7099532294120977}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n-/\nimport order.bounds\nimport data.set.intervals.image_preimage\nimport tactic.linarith\n\n/-!\n# Intervals without endpoints ordering\nIn any decidable linear order `\u03b1`, we define the set of elements lying between two elements `a` and\n`b` as `Icc (min a b) (max a b)`.\n`Icc a b` requires the assumption `a \u2264 b` to be meaningful, which is sometimes inconvenient. The\ninterval as defined in this file is always the set of things lying between `a` and `b`, regardless\nof the relative order of `a` and `b`.\nFor real numbers, `Icc (min a b) (max a b)` is the same as `segment a b`.\n## Notation\nWe use the localized notation `[a, b]` for `interval a b`. One can open the locale `interval` to\nmake the notation available.\n-/\n\nuniverse u\n\nnamespace set\n\nsection linear_order\n\nvariables {\u03b1 : Type u} [linear_order \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 x : \u03b1}\n\n/-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/\ndef interval (a b : \u03b1) := Icc (min a b) (max a b)\n\nlocalized \"notation `[`a `, ` b `]` := interval a b\" in interval\n\n@[simp] lemma interval_of_le (h : a \u2264 b) : [a, b] = Icc a b :=\nby rw [interval, min_eq_left h, max_eq_right h]\n\n@[simp] lemma interval_of_ge (h : b \u2264 a) : [a, b] = Icc b a :=\nby { rw [interval, min_eq_right h, max_eq_left h] }\n\nlemma interval_swap (a b : \u03b1) : [a, b] = [b, a] :=\nor.elim (le_total a b) (by simp {contextual := tt}) (by simp {contextual := tt})\n\nlemma interval_of_lt (h : a < b) : [a, b] = Icc a b :=\ninterval_of_le (le_of_lt h)\n\nlemma interval_of_gt (h : b < a) : [a, b] = Icc b a :=\ninterval_of_ge (le_of_lt h)\n\nlemma interval_of_not_le (h : \u00ac a \u2264 b) : [a, b] = Icc b a :=\ninterval_of_gt (lt_of_not_ge h)\n\nlemma interval_of_not_ge (h : \u00ac b \u2264 a) : [a, b] = Icc a b :=\ninterval_of_lt (lt_of_not_ge h)\n\n@[simp] lemma interval_self : [a, a] = {a} :=\nset.ext $ by simp [le_antisymm_iff, and_comm]\n\n@[simp] lemma nonempty_interval : set.nonempty [a, b] :=\nby { simp only [interval, min_le_iff, le_max_iff, nonempty_Icc], left, left, refl }\n\n@[simp] lemma left_mem_interval : a \u2208 [a, b] :=\nby { rw [interval, mem_Icc], exact \u27e8min_le_left _ _, le_max_left _ _\u27e9 }\n\n@[simp] lemma right_mem_interval : b \u2208 [a, b] :=\nby { rw interval_swap, exact left_mem_interval }\n\nlemma Icc_subset_interval : Icc a b \u2286 [a, b] :=\nby { assume x h, rwa interval_of_le, exact le_trans h.1 h.2 }\n\nlemma Icc_subset_interval' : Icc b a \u2286 [a, b] :=\nby { rw interval_swap, apply Icc_subset_interval }\n\nlemma mem_interval_of_le (ha : a \u2264 x) (hb : x \u2264 b) : x \u2208 [a, b] :=\nIcc_subset_interval \u27e8ha, hb\u27e9\n\nlemma mem_interval_of_ge (hb : b \u2264 x) (ha : x \u2264 a) : x \u2208 [a, b] :=\nIcc_subset_interval' \u27e8hb, ha\u27e9\n\nlemma interval_subset_interval (h\u2081 : a\u2081 \u2208 [a\u2082, b\u2082]) (h\u2082 : b\u2081 \u2208 [a\u2082, b\u2082]) : [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] :=\nIcc_subset_Icc (le_min h\u2081.1 h\u2082.1) (max_le h\u2081.2 h\u2082.2)\n\nlemma interval_subset_interval_iff_mem : [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] \u2194 a\u2081 \u2208 [a\u2082, b\u2082] \u2227 b\u2081 \u2208 [a\u2082, b\u2082] :=\niff.intro (\u03bbh, \u27e8h left_mem_interval, h right_mem_interval\u27e9) (\u03bb h, interval_subset_interval h.1 h.2)\n\nlemma interval_subset_interval_iff_le :\n  [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] \u2194 min a\u2082 b\u2082 \u2264 min a\u2081 b\u2081 \u2227 max a\u2081 b\u2081 \u2264 max a\u2082 b\u2082 :=\nby { rw [interval, interval, Icc_subset_Icc_iff], exact min_le_max }\n\nlemma interval_subset_interval_right (h : x \u2208 [a, b]) : [x, b] \u2286 [a, b] :=\ninterval_subset_interval h right_mem_interval\n\nlemma interval_subset_interval_left (h : x \u2208 [a, b]) : [a, x] \u2286 [a, b] :=\ninterval_subset_interval left_mem_interval h\n\nlemma bdd_below_bdd_above_iff_subset_interval (s : set \u03b1) :\n  bdd_below s \u2227 bdd_above s \u2194 \u2203 a b, s \u2286 [a, b] :=\nbegin\n  rw [bdd_below_bdd_above_iff_subset_Icc],\n  split,\n  { rintro \u27e8a, b, h\u27e9, exact \u27e8a, b, \u03bb x hx, Icc_subset_interval (h hx)\u27e9 },\n  { rintro \u27e8a, b, h\u27e9, exact \u27e8min a b, max a b, h\u27e9 }\nend\n\nend linear_order\n\nopen_locale interval\n\nsection ordered_add_comm_group\n\nvariables {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1] (a b c x y : \u03b1)\n\n@[simp] lemma preimage_const_add_interval : (\u03bb x, a + x) \u207b\u00b9' [b, c] = [b - a, c - a] :=\nby simp only [interval, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right]\n\n@[simp] lemma preimage_add_const_interval : (\u03bb x, x + a) \u207b\u00b9' [b, c] = [b - a, c - a] :=\nby simpa only [add_comm] using preimage_const_add_interval a b c\n\n@[simp] lemma preimage_neg_interval : -([a, b]) = [-a, -b] :=\nby simp only [interval, preimage_neg_Icc, min_neg_neg, max_neg_neg]\n\n@[simp] lemma preimage_sub_const_interval : (\u03bb x, x - a) \u207b\u00b9' [b, c] = [b + a, c + a] :=\nby simp [sub_eq_add_neg]\n\n@[simp] lemma preimage_const_sub_interval : (\u03bb x, a - x) \u207b\u00b9' [b, c] = [a - b, a - c] :=\nby { rw [interval, interval, preimage_const_sub_Icc],\n  simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg], }\n\n@[simp] lemma image_const_add_interval : (\u03bb x, a + x) '' [b, c] = [a + b, a + c] :=\nby simp [add_comm]\n\n@[simp] lemma image_add_const_interval : (\u03bb x, x + a) '' [b, c] = [b + a, c + a] :=\nby simp\n\n@[simp] lemma image_const_sub_interval : (\u03bb x, a - x) '' [b, c] = [a - b, a - c] :=\nby simp [sub_eq_add_neg, image_comp (\u03bb x, a + x) (\u03bb x, -x)]\n\n@[simp] lemma image_sub_const_interval : (\u03bb x, x - a) '' [b, c] = [b - a, c - a] :=\nby simp [sub_eq_add_neg, add_comm]\n\nlemma image_neg_interval : has_neg.neg '' [a, b] = [-a, -b] := by simp\n\nvariables {a b c x y}\n\n/-- If `[x, y]` is a subinterval of `[a, b]`, then the distance between `x` and `y`\nis less than or equal to that of `a` and `b` -/\nlemma abs_sub_le_of_subinterval (h : [x, y] \u2286 [a, b]) : abs (y - x) \u2264 abs (b - a) :=\nbegin\n  rw [\u2190 max_sub_min_eq_abs, \u2190 max_sub_min_eq_abs],\n  rw [interval_subset_interval_iff_le] at h,\n  exact sub_le_sub h.2 h.1,\nend\n\n/-- If `x \u2208 [a, b]`, then the distance between `a` and `x` is less than or equal to\nthat of `a` and `b`  -/\nlemma abs_sub_left_of_mem_interval (h : x \u2208 [a, b]) : abs (x - a) \u2264 abs (b - a) :=\nabs_sub_le_of_subinterval (interval_subset_interval_left h)\n\n/-- If `x \u2208 [a, b]`, then the distance between `x` and `b` is less than or equal to\nthat of `a` and `b`  -/\nlemma abs_sub_right_of_mem_interval (h : x \u2208 [a, b]) : abs (b - x) \u2264 abs (b - a) :=\nabs_sub_le_of_subinterval (interval_subset_interval_right h)\n\nend ordered_add_comm_group\n\nsection linear_ordered_field\n\nvariables {k : Type u} [linear_ordered_field k] {a : k}\n\n@[simp] lemma preimage_mul_const_interval (ha : a \u2260 0) (b c : k) :\n  (\u03bb x, x * a) \u207b\u00b9' [b, c] = [b / a, c / a] :=\n(lt_or_gt_of_ne ha).elim\n  (\u03bb ha, by simp [interval, ha, ha.le, min_div_div_right_of_nonpos, max_div_div_right_of_nonpos])\n  (\u03bb (ha : 0 < a), by simp [interval, ha, ha.le, min_div_div_right, max_div_div_right])\n\n@[simp] lemma preimage_const_mul_interval (ha : a \u2260 0) (b c : k) :\n  (\u03bb x, a * x) \u207b\u00b9' [b, c] = [b / a, c / a] :=\nby simp only [\u2190 preimage_mul_const_interval ha, mul_comm]\n\n@[simp] lemma preimage_div_const_interval (ha : a \u2260 0) (b c : k) :\n  (\u03bb x, x / a) \u207b\u00b9' [b, c] = [b * a, c * a] :=\n(preimage_mul_const_interval (inv_ne_zero ha) _ _).trans $ by simp [div_eq_mul_inv]\n\n@[simp] lemma image_mul_const_interval (a b c : k) : (\u03bb x, x * a) '' [b, c] = [b * a, c * a] :=\nif ha : a = 0 then by simp [ha] else\ncalc (\u03bb x, x * a) '' [b, c] = (\u03bb x, x / a) \u207b\u00b9' [b, c] :\n  (units.mk0 a ha).mul_right.image_eq_preimage _\n... = [b * a, c * a] : preimage_div_const_interval ha _ _\n\n@[simp] lemma image_const_mul_interval (a b c : k) : (\u03bb x, a * x) '' [b, c] = [a * b, a * c] :=\nby simpa only [mul_comm] using image_mul_const_interval a b c\n\n@[simp] lemma image_div_const_interval (a b c : k) : (\u03bb x, x / a) '' [b, c] = [b / a, c / a] :=\nimage_mul_const_interval _ _ _\n\nend linear_ordered_field\n\nsection intervals \n\nvariables (\u03b1 : Type u) [linear_ordered_field \u03b1] \n\n@[reducible] def intervals := { I // \u2203 (a b : \u03b1), a < b \u2227 I = [a, b] }\n-- Should be \u2264.\n\nsection ordered_add_comm_group\n\nvariable {\u03b1}\n\nlemma mem_Icc_iff_exists_affine_form (a b : \u03b1) (h : a < b)\n: \u2200 x, x \u2208 Icc a b \u2194 \n  \u2203 \u03b3 \u2208 (Icc (-1) 1 : set \u03b1), x = ((a + b) / 2) + \u03b3 * ((b - a) / 2) :=\nbegin \n  replace h := sub_pos.2 h,\n  have h2 : 0 < (b - a) / 2 := div_pos h (by linarith),\n  intros x, split, \n  { rintros \u27e8hax, hxb\u27e9, \n    use [(2*x - a - b) / (b - a)], refine \u27e8\u27e8_, _\u27e9, _\u27e9, \n      { simp [le_div_iff h], linarith, },\n      { simp [div_le_iff h], linarith, },\n      { simp [mul_comm, \u2190mul_div_assoc, mul_div_cancel_left _ (ne_of_gt h)], ring, }, },\n  { rintros \u27e8\u03b3, \u27e8h\u03b3lb, h\u03b3ub\u27e9, hx\u27e9, rw hx, split,\n    { apply le_add_of_sub_left_le, \n      refine le_trans _ ((mul_le_mul_right h2).2 h\u03b3lb),\n      linarith, },\n    { apply add_le_of_le_sub_left,\n      refine le_trans ((mul_le_mul_right h2).2 h\u03b3ub) _,\n      linarith, }, },\nend\n\nlemma add_intervals (a b c d : \u03b1) (h1 : a < b) (h2 : c < d) \n: Icc a b + Icc c d = Icc (a + c) (b + d) :=\nbegin \n  have h3 : a + c < b + d := add_lt_add h1 h2,\n  ext x, split, \n  { rintros \u27e8y, z, \u27e8hay, hyb\u27e9, \u27e8hcz, hzd\u27e9, hx\u27e9, \n    rw \u2190hx, exact \u27e8add_le_add hay hcz, add_le_add hyb hzd\u27e9, },\n  { intros hx, replace hx := (mem_Icc_iff_exists_affine_form _ _ h3 x).1 hx,\n    rcases hx with \u27e8\u03b3, h\u03b3, hx\u27e9,\n    use [((a + b) / 2) + \u03b3 * ((b - a) / 2)],\n    use [((c + d) / 2) + \u03b3 * ((d - c) / 2)],\n    refine \u27e8_, _, _\u27e9,\n    { rw mem_Icc_iff_exists_affine_form _ _ h1, use [\u03b3, h\u03b3], },\n    { rw mem_Icc_iff_exists_affine_form _ _ h2, use [\u03b3, h\u03b3], },\n    { rw hx, ring, }, }, \nend \n\nlemma add_intervals' (a b c d : \u03b1) (h1 : a < b) (h2 : c < d) \n: [a, b] + [c, d] = [a + c, b + d] :=\nbegin \n  rw [interval_of_lt h1, interval_of_lt h2, interval_of_lt (add_lt_add h1 h2)],\n  exact add_intervals a b c d h1 h2,\nend \n\nset_option trace.eqn_compiler.elim_match true\n\ninstance : has_add (intervals \u03b1) := {\n  add := \u03bb I J, \u27e8I.1 + J.1, \n    begin \n      rcases I.2 with \u27e8a, b, hab, hI\u27e9, \n      rcases J.2 with \u27e8c, d, hcd, hJ\u27e9, \n      have hacbd := add_lt_add hab hcd,\n      use [a + c, b + d, hacbd], rw [hI, hJ],\n      exact add_intervals' a b c d hab hcd,\n    end\u27e9\n}\n\ninstance : linear_ordered_add_comm_group (intervals \u03b1) := {\n  add := has_add.add, \n  add_assoc := sorry, \n  zero := sorry,\n  zero_add := sorry, \n  add_zero := sorry,\n  neg := sorry,\n  add_left_neg := sorry,\n  add_comm := sorry,\n  le := sorry,\n  le_refl := sorry,\n  le_trans := sorry,\n  le_antisymm := sorry,\n  le_total := sorry,\n  decidable_le := sorry,\n  add_le_add_left := sorry,\n}\n\nend ordered_add_comm_group\n\nend intervals \n\nend set\n", "meta": {"author": "ramonfmir", "repo": "lean-experiments", "sha": "041c8727bb540fb8d1519c1ad84924d473885c27", "save_path": "github-repos/lean/ramonfmir-lean-experiments", "path": "github-repos/lean/ramonfmir-lean-experiments/lean-experiments-041c8727bb540fb8d1519c1ad84924d473885c27/src/picard_lindelof/interval_arithmetic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7099532294120977}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones\n-- 1. Importar la librer\u00eda tactic\n-- 2. Abrir el espacio de nombres set\n-- 3. Declarar u y v como variables de universos.\n-- 4. Declarar \u03b1 como una variable de tipos en u.\n-- 5. Declarar I como una variable de tipos en v.\n-- 6. Declarar A y B como variables sobre funciones de I en \u03b1.\n-- 7. Declarar s como variable sobre conjuntos de elementos de \u03b1.\n-- ----------------------------------------------------------------------\n\nimport tactic                 -- 1\nopen set                      -- 2\nuniverses u v                 -- 3\nvariable (\u03b1 : Type u)         -- 4\nvariable (I : Type v)         -- 5\nvariables (A B : I \u2192 set \u03b1)   -- 6\nvariable  s : set \u03b1           -- 7\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s)\n-- ----------------------------------------------------------------------\n\nexample : s \u2229 (\u22c3 i, A i) = \u22c3 i, (A i \u2229 s) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Union],\n  split,\n  { rintros \u27e8xs, \u27e8i, xAi\u27e9\u27e9,\n    exact \u27e8i, xAi, xs\u27e9 },\n  { rintros \u27e8i, xAi, xs\u27e9,\n    exact \u27e8xs, \u27e8i, xAi\u27e9\u27e9 },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u,\nI : Type v,\nA : I \u2192 set \u03b1,\ns : set \u03b1\n\u22a2 (s \u2229 \u22c3 (i : I), A i) = \u22c3 (i : I), A i \u2229 s\n  >> ext x,\nx : \u03b1\n\u22a2 (x \u2208 s \u2229 \u22c3 (i : I), A i) \u2194 x \u2208 \u22c3 (i : I), A i \u2229 s\n  >> simp only [mem_inter_eq, mem_Union],\n\u22a2 (x \u2208 s \u2227 \u2203 (i : I), x \u2208 A i) \u2194 \u2203 (i : I), x \u2208 A i \u2227 x \u2208 s\n  >> split,\n| \u22a2 (x \u2208 s \u2227 \u2203 (i : I), x \u2208 A i) \u2192 (\u2203 (i : I), x \u2208 A i \u2227 x \u2208 s)\n|   >> { rintros \u27e8xs, \u27e8i, xAi\u27e9\u27e9,\n| x : \u03b1,\n| xs : x \u2208 s,\n| i : I,\n| xAi : x \u2208 A i\n| \u22a2 \u2203 (i : I), x \u2208 A i \u2227 x \u2208 s\n|   >>   exact \u27e8i, xAi, xs\u27e9 },\n\u22a2 (\u2203 (i : I), x \u2208 A i \u2227 x \u2208 s) \u2192 (x \u2208 s \u2227 \u2203 (i : I), x \u2208 A i)\n  >> { rintros \u27e8i, xAi, xs\u27e9,\nx : \u03b1,\ni : I,\nxAi : x \u2208 A i,\nxs : x \u2208 s\n\u22a2 x \u2208 s \u2227 \u2203 (i : I), x \u2208 A i\n  >>   exact \u27e8xs, \u27e8i, xAi\u27e9\u27e9 },\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + mem_inter_eq: x \u2208 a \u2229 b = (x \u2208 a \u2227 x \u2208 b)\n-- + mem_Union : x \u2208 Union A \u2194 \u2203 (i : I), x \u2208 A i\n\n-- Comprobaci\u00f3n\nvariable x : \u03b1\nvariables (a b : set \u03b1)\n-- #check @mem_inter_eq _ x a b\n-- #check @mem_Union \u03b1 I x A\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i)\n-- ----------------------------------------------------------------------\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Inter],\n  split,\n  { intro h,\n    split,\n    { intro i,\n      exact (h i).1 },\n    { intro i,\n      exact (h i).2 }},\n  { rintros \u27e8h1, h2\u27e9 i,\n    split,\n    { exact h1 i },\n    { exact h2 i }},\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u,\nI : Type v,\nA B : I \u2192 set \u03b1\n\u22a2 (\u22c2 (i : I), A i \u2229 B i) = (\u22c2 (i : I), A i) \u2229 \u22c2 (i : I), B i\n  >> ext x,\nx : \u03b1\n\u22a2 (x \u2208 \u22c2 (i : I), A i \u2229 B i) \u2194 x \u2208 (\u22c2 (i : I), A i) \u2229 \u22c2 (i : I), B i\n  >> simp only [mem_inter_eq, mem_Inter],\n\u22a2 (\u2200 (i : I), x \u2208 A i \u2227 x \u2208 B i) \u2194 (\u2200 (i : I), x \u2208 A i) \u2227 \u2200 (i : I), x \u2208 B i\n  >> split,\n| \u22a2 (\u2200 (i : I), x \u2208 A i \u2227 x \u2208 B i) \u2192 ((\u2200 (i : I), x \u2208 A i) \u2227 \u2200 (i : I), x \u2208 B i)\n|   >> { intro h,\n| h : \u2200 (i : I), x \u2208 A i \u2227 x \u2208 B i\n| \u22a2 (\u2200 (i : I), x \u2208 A i) \u2227 \u2200 (i : I), x \u2208 B i\n|   >>   split,\n| | \u22a2 \u2200 (i : I), x \u2208 A i\n| |   >>   { intro i,\n| | i : I\n| | \u22a2 x \u2208 A i\n| |   >>     exact (h i).1 },\n| \u22a2 \u2200 (i : I), x \u2208 B i\n|   >>   { intro i,\n| i : I\n| \u22a2 x \u2208 B i\n|   >>     exact (h i).2 }},\n\u22a2 ((\u2200 (i : I), x \u2208 A i) \u2227 \u2200 (i : I), x \u2208 B i) \u2192 \u2200 (i : I), x \u2208 A i \u2227 x \u2208 B i\n  >> { rintros \u27e8h1, h2\u27e9 i,\ni : I,\nh1 : \u2200 (i : I), x \u2208 A i,\nh2 : \u2200 (i : I), x \u2208 B i\n\u22a2 x \u2208 A i \u2227 x \u2208 B i\n  >>   split,\n| \u22a2 x \u2208 A i\n|   >>   { exact h1 i },\n\u22a2 x \u2208 B i\n  >>   { exact h2 i }},\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + mem_inter_eq: x \u2208 a \u2229 b = (x \u2208 a \u2227 x \u2208 b)\n-- + mem_Inter : x \u2208 Inter A \u2194 \u2200 (i : I), x \u2208 A i\n\n-- Comprobaci\u00f3n\n-- #check @mem_inter_eq _ x a b\n-- #check @mem_Inter \u03b1 I x A\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Ejemplos_de_uniones_e_intersecciones_generales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7099532274517474}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.induction\n! leanprover-community/mathlib commit 63417e01fbc711beaf25fa73b6edb395c0cfddd0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.RingTheory.Ideal.Basic\nimport Mathlib.Data.Polynomial.Basic\n\n/-!\n# Induction on polynomials\n\nThis file contains lemmas dealing with different flavours of induction on polynomials.\nSee also `Data/Polynomial/Inductions.lean` (with an `s`!).\n\nThe main result is `Polynomial.induction_on`.\n-/\n\n\nnoncomputable section\n\nopen Finsupp Finset\n\nnamespace Polynomial\n\nopen Polynomial\n\nuniverse u v w x y z\n\nvariable {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type x} {k : Type y} {A : Type z} {a b : R}\n  {m n : \u2115}\n\nsection Semiring\n\nvariable [Semiring R] {p q r : R[X]}\n\n@[elab_as_elim]\nprotected theorem induction_on {M : R[X] \u2192 Prop} (p : R[X]) (h_C : \u2200 a, M (C a))\n    (h_add : \u2200 p q, M p \u2192 M q \u2192 M (p + q))\n    (h_monomial : \u2200 (n : \u2115) (a : R), M (C a * X ^ n) \u2192 M (C a * X ^ (n + 1))) : M p := by\n  have A : \u2200 {n : \u2115} {a}, M (C a * X ^ n) := by\n    intro n a\n    induction' n with n ih\n    \u00b7 rw [pow_zero, mul_one]; exact h_C a\n    \u00b7 exact h_monomial _ _ ih\n  have B : \u2200 s : Finset \u2115, M (s.sum fun n : \u2115 => C (p.coeff n) * X ^ n) := by\n    apply Finset.induction\n    \u00b7 convert h_C 0\n      exact C_0.symm\n    \u00b7 intro n s ns ih\n      rw [sum_insert ns]\n      exact h_add _ _ A ih\n  rw [\u2190 sum_C_mul_X_pow_eq p, Polynomial.sum]\n  exact B (support p)\n#align polynomial.induction_on Polynomial.induction_on\n\n/-- To prove something about polynomials,\nit suffices to show the condition is closed under taking sums,\nand it holds for monomials.\n-/\n@[elab_as_elim]\nprotected theorem induction_on' {M : R[X] \u2192 Prop} (p : R[X]) (h_add : \u2200 p q, M p \u2192 M q \u2192 M (p + q))\n    (h_monomial : \u2200 (n : \u2115) (a : R), M (monomial n a)) : M p :=\n  Polynomial.induction_on p (h_monomial 0) h_add fun n a _h =>\n    by rw [C_mul_X_pow_eq_monomial]; exact h_monomial _ _\n#align polynomial.induction_on' Polynomial.induction_on'\n\nopen Submodule Polynomial Set\n\nvariable {f : R[X]} {I : Ideal R[X]}\n\n/-- If the coefficients of a polynomial belong to an ideal, then that ideal contains\nthe ideal spanned by the coefficients of the polynomial. -/\ntheorem span_le_of_C_coeff_mem (cf : \u2200 i : \u2115, C (f.coeff i) \u2208 I) :\n    Ideal.span { g | \u2203 i, g = C (f.coeff i) } \u2264 I := by\n  simp (config := { singlePass := true }) only [@eq_comm _ _ (C _)]\n  exact (Ideal.span_le.trans range_subset_iff).mpr cf\nset_option linter.uppercaseLean3 false in\n#align polynomial.span_le_of_C_coeff_mem Polynomial.span_le_of_C_coeff_mem\n\ntheorem mem_span_C_coeff : f \u2208 Ideal.span { g : R[X] | \u2203 i : \u2115, g = C (coeff f i) } := by\n  let p := Ideal.span { g : R[X] | \u2203 i : \u2115, g = C (coeff f i) }\n  nth_rw 1 [(sum_C_mul_X_pow_eq f).symm]\n  refine' Submodule.sum_mem _ fun n _hn => _\n  dsimp\n  have : C (coeff f n) \u2208 p := by\n    apply subset_span\n    rw [mem_setOf_eq]\n    use n\n  have : monomial n (1 : R) \u2022 C (coeff f n) \u2208 p := p.smul_mem _ this\n  convert this using 1\n  simp only [monomial_mul_C, one_mul, smul_eq_mul]\n  rw [\u2190 C_mul_X_pow_eq_monomial]\nset_option linter.uppercaseLean3 false in\n#align polynomial.mem_span_C_coeff Polynomial.mem_span_C_coeff\n\ntheorem exists_C_coeff_not_mem : f \u2209 I \u2192 \u2203 i : \u2115, C (coeff f i) \u2209 I :=\n  Not.imp_symm fun cf => span_le_of_C_coeff_mem (not_exists_not.mp cf) mem_span_C_coeff\nset_option linter.uppercaseLean3 false in\n#align polynomial.exists_C_coeff_not_mem Polynomial.exists_C_coeff_not_mem\n\nend Semiring\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7098711981134843}}
{"text": "/-\nCopyright (c) 2021 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n\n! This file was ported from Lean 3 source module combinatorics.set_family.compression.uv\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Card\nimport Mathlib.Tactic.ScopedNS -- Porting note: scoped\n\n/-!\n# UV-compressions\n\nThis file defines UV-compression. It is an operation on a set family that reduces its shadow.\n\nUV-compressing `a : \u03b1` along `u v : \u03b1` means replacing `a` by `(a \u2294 u) \\ v` if `a` and `u` are\ndisjoint and `v \u2264 a`. In some sense, it's moving `a` from `v` to `u`.\n\nUV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that\ncompressing a set family might decrease the size of its shadow, so iterated compressions hopefully\nminimise the shadow.\n\n## Main declarations\n\n* `UV.compress`: `compress u v a` is `a` compressed along `u` and `v`.\n* `UV.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`.\n  It is the compressions of the elements of `s` whose compression is not already in `s` along with\n  the element whose compression is already in `s`. This way of splitting into what moves and what\n  does not ensures the compression doesn't squash the set family, which is proved by\n  `UV.card_compress`.\n\n## Notation\n\n`\ud835\udcd2` (typed with `\\MCC`) is notation for `UV.compression` in locale `FinsetFamily`.\n\n## Notes\n\nEven though our emphasis is on `Finset \u03b1`, we define UV-compressions more generally in a generalized\nboolean algebra, so that one can use it for `Set \u03b1`.\n\n## TODO\n\nProve that compressing reduces the size of shadow. This result and some more already exist on the\nbranch `Combinatorics`.\n\n## References\n\n* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf\n\n## Tags\n\ncompression, UV-compression, shadow\n-/\n\n\nopen Finset\n\nvariable {\u03b1 : Type _}\n\n/-- UV-compression is injective on the elements it moves. See `UV.compress`. -/\ntheorem sup_sdiff_injOn [GeneralizedBooleanAlgebra \u03b1] (u v : \u03b1) :\n    { x | Disjoint u x \u2227 v \u2264 x }.InjOn fun x => (x \u2294 u) \\ v :=\n  by\n  rintro a ha b hb hab\n  have h : ((a \u2294 u) \\ v) \\ u \u2294 v = ((b \u2294 u) \\ v) \\ u \u2294 v :=\n    by\n    dsimp at hab\n    rw [hab]\n  rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm,\n    hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h\n#align sup_sdiff_inj_on sup_sdiff_injOn\n\n-- The namespace is here to distinguish from other compressions.\nnamespace UV\n\n/-! ### UV-compression in generalized boolean algebras -/\n\n\nsection GeneralizedBooleanAlgebra\n\nvariable [GeneralizedBooleanAlgebra \u03b1] [DecidableRel (@Disjoint \u03b1 _ _)]\n  [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)] {s : Finset \u03b1} {u v a b : \u03b1}\n\nattribute [local instance] decidableEq_of_decidableLE\n\n/-- To UV-compress `a`, if it doesn't touch `U` and does contain `V`, we remove `V` and\nput `U` in. We'll only really use this when `|U| = |V|` and `U \u2229 V = \u2205`. -/\ndef compress (u v a : \u03b1) : \u03b1 :=\n  if Disjoint u a \u2227 v \u2264 a then (a \u2294 u) \\ v else a\n#align uv.compress UV.compress\n\n/-- To UV-compress a set family, we compress each of its elements, except that we don't want to\nreduce the cardinality, so we keep all elements whose compression is already present. -/\ndef compression (u v : \u03b1) (s : Finset \u03b1) :=\n  (s.filter fun a => compress u v a \u2208 s) \u222a (s.image <| compress u v).filter fun a => a \u2209 s\n#align uv.compression UV.compression\n\n@[inherit_doc]\nscoped[FinsetFamily] notation \"\ud835\udcd2 \" => UV.compression\nopen FinsetFamily\n\n/-- `IsCompressed u v s` expresses that `s` is UV-compressed. -/\ndef IsCompressed (u v : \u03b1) (s : Finset \u03b1) :=\n  \ud835\udcd2 u v s = s\n#align uv.is_compressed UV.IsCompressed\n\ntheorem compress_of_disjoint_of_le (hua : Disjoint u a) (hva : v \u2264 a) :\n    compress u v a = (a \u2294 u) \\ v :=\n  if_pos \u27e8hua, hva\u27e9\n#align uv.compress_of_disjoint_of_le UV.compress_of_disjoint_of_le\n\n/-- `a` is in the UV-compressed family iff it's in the original and its compression is in the\noriginal, or it's not in the original but it's the compression of something in the original. -/\ntheorem mem_compression :\n    a \u2208 \ud835\udcd2 u v s \u2194\n      a \u2208 s \u2227 compress u v a \u2208 s \u2228 a \u2209 s \u2227 \u2203 b \u2208 s, compress u v b = a := by\n  simp [compression, mem_union, mem_filter, mem_image, and_comm]\n#align uv.mem_compression UV.mem_compression\n\n@[simp]\ntheorem compress_self (u a : \u03b1) : compress u u a = a := by\n  unfold compress\n  split_ifs\n  \u00b7 exact \u2039Disjoint u a \u2227 u \u2264 a\u203a.1.symm.sup_sdiff_cancel_right\n  \u00b7 rfl\n#align uv.compress_self UV.compress_self\n\n@[simp]\ntheorem compression_self (u : \u03b1) (s : Finset \u03b1) : \ud835\udcd2 u u s = s := by\n  unfold compression\n  convert union_empty s\n  \u00b7 ext a\n    simp [mem_filter, compress_self, and_self_iff]\n  \u00b7 refine' eq_empty_of_forall_not_mem fun a ha => _\n    simp_rw [mem_filter, mem_image, compress_self] at ha\n    obtain \u27e8\u27e8b, hb, rfl\u27e9, hb'\u27e9 := ha\n    exact hb' hb\n#align uv.compression_self UV.compression_self\n\n/-- Any family is compressed along two identical elements. -/\ntheorem is_compressed_self (u : \u03b1) (s : Finset \u03b1) : IsCompressed u u s :=\n  compression_self u s\n#align uv.is_compressed_self UV.is_compressed_self\n\ntheorem compress_disjoint (u v : \u03b1) :\n    Disjoint (s.filter fun a => compress u v a \u2208 s)\n      ((s.image <| compress u v).filter fun a => a \u2209 s) :=\n  disjoint_left.2 fun _a ha\u2081 ha\u2082 => (mem_filter.1 ha\u2082).2 (mem_filter.1 ha\u2081).1\n#align uv.compress_disjoint UV.compress_disjoint\n\n/-- Compressing an element is idempotent. -/\n@[simp]\ntheorem compress_idem (u v a : \u03b1) : compress u v (compress u v a) = compress u v a :=\n  by\n  unfold compress\n  split_ifs with h h' <;> try rfl\n  rw [le_sdiff_iff.1 h'.2, sdiff_bot, sdiff_bot, sup_assoc, sup_idem]\n#align uv.compress_idem UV.compress_idem\n\ntheorem compress_mem_compression (ha : a \u2208 s) : compress u v a \u2208 \ud835\udcd2 u v s := by\n  rw [mem_compression]\n  by_cases h : compress u v a \u2208 s\n  \u00b7 rw [compress_idem]\n    exact Or.inl \u27e8h, h\u27e9\n  \u00b7 exact Or.inr \u27e8h, a, ha, rfl\u27e9\n#align uv.compress_mem_compression UV.compress_mem_compression\n\n-- This is a special case of `compress_mem_compression` once we have `compression_idem`.\ntheorem compress_mem_compression_of_mem_compression (ha : a \u2208 \ud835\udcd2 u v s) :\n    compress u v a \u2208 compression u v s := by\n  rw [mem_compression] at ha\u22a2\n  simp only [compress_idem, exists_prop]\n  obtain \u27e8_, ha\u27e9 | \u27e8_, b, hb, rfl\u27e9 := ha\n  \u00b7 exact Or.inl \u27e8ha, ha\u27e9\n  \u00b7 exact Or.inr \u27e8by rwa [compress_idem], b, hb, (compress_idem _ _ _).symm\u27e9\n#align\n  uv.compress_mem_compression_of_mem_compression\n  UV.compress_mem_compression_of_mem_compression\n\n/-- Compressing a family is idempotent. -/\n@[simp]\ntheorem compression_idem (u v : \u03b1) (s : Finset \u03b1) :\n  \ud835\udcd2 u v (\ud835\udcd2 u v s) = \ud835\udcd2 u v s := by\n  have h : filter (fun a => compress u v a \u2209 \ud835\udcd2 u v s) (\ud835\udcd2 u v s) = \u2205 :=\n    filter_false_of_mem fun a ha h => h <| compress_mem_compression_of_mem_compression ha\n  rw [compression, image_filter]\n  simp_rw [Function.comp]\n  rw [h, image_empty, \u2190 h]\n  exact filter_union_filter_neg_eq _ (compression u v s)\n#align uv.compression_idem UV.compression_idem\n\n/-- Compressing a family doesn't change its size. -/\ntheorem card_compression (u v : \u03b1) (s : Finset \u03b1) : (\ud835\udcd2 u v s).card = s.card := by\n  rw [compression, card_disjoint_union (compress_disjoint _ _), image_filter, card_image_of_injOn,\n    \u2190 card_disjoint_union]\n  simp_rw [Function.comp]\n  rw [filter_union_filter_neg_eq]\n  \u00b7 rw [disjoint_iff_inter_eq_empty]\n    exact filter_inter_filter_neg_eq _ _ _\n  intro a ha b hb hab\n  dsimp at hab\n  rw [mem_coe, mem_filter, Function.comp_apply] at ha hb\n  rw [compress] at ha hab\n  split_ifs  at ha hab with has\n  \u00b7 rw [compress] at hb hab\n    split_ifs  at hb hab with hbs\n    \u00b7 exact sup_sdiff_injOn u v has hbs hab\n    \u00b7 exact (hb.2 hb.1).elim\n  \u00b7 exact (ha.2 ha.1).elim\n#align uv.card_compression UV.card_compression\n\n/-- If `a` is in the family compression and can be compressed, then its compression is in the\noriginal family. -/\ntheorem sup_sdiff_mem_of_mem_compression (ha : a \u2208 \ud835\udcd2 u v s)\n  (hva : v \u2264 a) (hua : Disjoint u a) :\n    (a \u2294 u) \\ v \u2208 s := by\n  rw [mem_compression, compress_of_disjoint_of_le hua hva] at ha\n  obtain \u27e8_, ha\u27e9 | \u27e8_, b, hb, rfl\u27e9 := ha\n  \u00b7 exact ha\n  have hu : u = \u22a5 :=\n    by\n    suffices Disjoint u (u \\ v) by rwa [(hua.mono_right hva).sdiff_eq_left, disjoint_self] at this\n    refine' hua.mono_right _\n    rw [\u2190 compress_idem, compress_of_disjoint_of_le hua hva]\n    exact sdiff_le_sdiff_right le_sup_right\n  have hv : v = \u22a5 := by\n    rw [\u2190 disjoint_self]\n    apply Disjoint.mono_right hva\n    rw [\u2190 compress_idem, compress_of_disjoint_of_le hua hva]\n    exact disjoint_sdiff_self_right\n  rwa [hu, hv, compress_self, sup_bot_eq, sdiff_bot]\n#align uv.sup_sdiff_mem_of_mem_compression UV.sup_sdiff_mem_of_mem_compression\n\n/-- If `a` is in the `u, v`-compression but `v \u2264 a`, then `a` must have been in the original\nfamily. -/\ntheorem mem_of_mem_compression (ha : a \u2208 \ud835\udcd2 u v s) (hva : v \u2264 a) (hvu : v = \u22a5 \u2192 u = \u22a5) :\n  a \u2208 s := by\n  rw [mem_compression] at ha\n  obtain ha | \u27e8_, b, hb, h\u27e9 := ha\n  \u00b7 exact ha.1\n  unfold compress at h\n  split_ifs at h\n  \u00b7 rw [\u2190 h, le_sdiff_iff] at hva\n    rw [hvu hva, hva, sup_bot_eq, sdiff_bot] at h\n    rwa [\u2190 h]\n  \u00b7 rwa [\u2190 h]\n#align uv.mem_of_mem_compression UV.mem_of_mem_compression\n\nend GeneralizedBooleanAlgebra\n\n/-! ### UV-compression on finsets -/\n\nopen FinsetFamily\n\nvariable [DecidableEq \u03b1] {\ud835\udc9c : Finset (Finset \u03b1)} {U V A : Finset \u03b1}\n\n-- porting note: needed to insert decidableDforallFinset instance here\n/-- Compressing a finset doesn't change its size. -/\ntheorem card_compress (hUV : U.card = V.card) (A : Finset \u03b1) :\n    (@compress (Finset \u03b1) _ _ (fun _ _ => Finset.decidableDforallFinset) U V A).card = A.card := by\n  unfold compress\n  split_ifs with h\n  \u00b7 rw [card_sdiff (h.2.trans le_sup_left), sup_eq_union, card_disjoint_union h.1.symm, hUV,\n      add_tsub_cancel_right]\n  \u00b7 rfl\n#align uv.card_compress UV.card_compress\n\nend UV\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/SetFamily/Compression/UV.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7098711913241672}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Julian Kuelshammer\n-/\nimport algebra.hom.iterate\nimport data.nat.modeq\nimport data.set.pointwise\nimport dynamics.periodic_pts\nimport group_theory.index\n\n/-!\n# Order of an element\n\nThis file defines the order of an element of a finite group. For a finite group `G` the order of\n`x \u2208 G` is the minimal `n \u2265 1` such that `x ^ n = 1`.\n\n## Main definitions\n\n* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite\n  order.\n* `is_of_fin_add_order` is the additive analogue of `is_of_fin_order`.\n* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`\n  if `x` has infinite order.\n* `add_order_of` is the additive analogue of `order_of`.\n\n## Tags\norder of an element\n-/\n\nopen function nat\nopen_locale pointwise\n\nuniverses u v\n\nvariables {G : Type u} {A : Type v}\nvariables {x y : G} {a b : A} {n m : \u2115}\n\nsection monoid_add_monoid\n\nvariables [monoid G] [add_monoid A]\n\nsection is_of_fin_order\n\n@[to_additive]\nlemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 \u2194 x ^ n = 1 :=\nby rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]\n\n/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite\norder, i.e. there exists `n \u2265 1` such that `n \u2022 a = 0`.-/\ndef is_of_fin_add_order (a : A) : Prop :=\n(0 : A) \u2208 periodic_pts ((+) a)\n\n/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there\nexists `n \u2265 1` such that `x ^ n = 1`.-/\n@[to_additive is_of_fin_add_order]\ndef is_of_fin_order (x : G) : Prop :=\n(1 : G) \u2208 periodic_pts ((*) x)\n\nlemma is_of_fin_add_order_of_mul_iff :\n  is_of_fin_add_order (additive.of_mul x) \u2194 is_of_fin_order x := iff.rfl\n\nlemma is_of_fin_order_of_add_iff :\n  is_of_fin_order (multiplicative.of_add a) \u2194 is_of_fin_add_order a := iff.rfl\n\n@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]\nlemma is_of_fin_order_iff_pow_eq_one (x : G) :\n  is_of_fin_order x \u2194 \u2203 n, 0 < n \u2227 x ^ n = 1 :=\nby { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }\n\n/-- Elements of finite order are of finite order in submonoids.-/\n@[to_additive is_of_fin_add_order_iff_coe]\nlemma is_of_fin_order_iff_coe (H : submonoid G) (x : H) :\n  is_of_fin_order x \u2194 is_of_fin_order (x : G) :=\nby { rw [is_of_fin_order_iff_pow_eq_one, is_of_fin_order_iff_pow_eq_one], norm_cast }\n\n/-- The image of an element of finite order has finite order. -/\n@[to_additive add_monoid_hom.is_of_fin_order\n  \"The image of an element of finite additive order has finite additive order.\"]\nlemma monoid_hom.is_of_fin_order\n  {H : Type v} [monoid H] (f : G \u2192* H) {x : G} (h : is_of_fin_order x) :\n  is_of_fin_order $ f x :=\n(is_of_fin_order_iff_pow_eq_one _).mpr $ begin\n  rcases (is_of_fin_order_iff_pow_eq_one _).mp h with \u27e8n, npos, hn\u27e9,\n  exact \u27e8n, npos, by rw [\u2190f.map_pow, hn, f.map_one]\u27e9,\nend\n\n/-- If a direct product has finite order then so does each component. -/\n@[to_additive \"If a direct product has finite additive order then so does each component.\"]\nlemma is_of_fin_order.apply\n  {\u03b7 : Type*} {Gs : \u03b7 \u2192 Type*} [\u2200 i, monoid (Gs i)] {x : \u03a0 i, Gs i} (h : is_of_fin_order x) :\n\u2200 i, is_of_fin_order (x i) := begin\n  rcases (is_of_fin_order_iff_pow_eq_one _).mp h with \u27e8n, npos, hn\u27e9,\n  exact \u03bb _, (is_of_fin_order_iff_pow_eq_one _).mpr \u27e8n, npos, (congr_fun hn.symm _).symm\u27e9,\nend\n\n/-- 1 is of finite order in any monoid. -/\n@[to_additive \"0 is of finite order in any additive monoid.\"]\nlemma is_of_fin_order_one : is_of_fin_order (1 : G) :=\n(is_of_fin_order_iff_pow_eq_one 1).mpr \u27e81, _root_.one_pos, one_pow 1\u27e9\n\nend is_of_fin_order\n\n/-- `order_of x` is the order of the element `x`, i.e. the `n \u2265 1`, s.t. `x ^ n = 1` if it exists.\nOtherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/\n@[to_additive add_order_of\n\"`add_order_of a` is the order of the element `a`, i.e. the `n \u2265 1`, s.t. `n \u2022 a = 0` if it\nexists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention.\"]\nnoncomputable def order_of (x : G) : \u2115 :=\nminimal_period ((*) x) 1\n\n@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :\n  add_order_of (additive.of_mul x) = order_of x := rfl\n\n@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :\n  order_of (multiplicative.of_add a) = add_order_of a := rfl\n\n@[to_additive add_order_of_pos']\nlemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=\nminimal_period_pos_of_mem_periodic_pts h\n\n@[to_additive add_order_of_nsmul_eq_zero]\nlemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=\nbegin\n  convert is_periodic_pt_minimal_period ((*) x) _,\n  rw [order_of, mul_left_iterate, mul_one],\nend\n\n@[to_additive add_order_of_eq_zero]\nlemma order_of_eq_zero (h : \u00ac is_of_fin_order x) : order_of x = 0 :=\nby rwa [order_of, minimal_period, dif_neg]\n\n@[to_additive add_order_of_eq_zero_iff] lemma order_of_eq_zero_iff :\n  order_of x = 0 \u2194 \u00ac is_of_fin_order x :=\n\u27e8\u03bb h H, (order_of_pos' H).ne' h, order_of_eq_zero\u27e9\n\n@[to_additive add_order_of_eq_zero_iff'] lemma order_of_eq_zero_iff' :\n  order_of x = 0 \u2194 \u2200 n : \u2115, 0 < n \u2192 x ^ n \u2260 1 :=\nby simp_rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one, not_exists, not_and]\n\n/-- A group element has finite order iff its order is positive. -/\n@[to_additive add_order_of_pos_iff\n  \"A group element has finite additive order iff its order is positive.\"]\nlemma order_of_pos_iff : 0 < order_of x \u2194 is_of_fin_order x :=\nby rwa [iff_not_comm.mp order_of_eq_zero_iff, pos_iff_ne_zero]\n\n@[to_additive nsmul_ne_zero_of_lt_add_order_of']\nlemma pow_ne_one_of_lt_order_of' (n0 : n \u2260 0) (h : n < order_of x) : x ^ n \u2260 1 :=\n\u03bb j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h\n  ((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)\n\n@[to_additive add_order_of_le_of_nsmul_eq_zero]\nlemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x \u2264 n :=\nis_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)\n\n@[simp, to_additive] lemma order_of_one : order_of (1 : G) = 1 :=\nby rw [order_of, one_mul_eq_id, minimal_period_id]\n\n@[simp, to_additive add_monoid.order_of_eq_one_iff] lemma order_of_eq_one_iff :\n  order_of x = 1 \u2194 x = 1 :=\nby rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]\n\n@[to_additive nsmul_eq_mod_add_order_of]\nlemma pow_eq_mod_order_of {n : \u2115} : x ^ n = x ^ (n % order_of x) :=\ncalc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]\n       ... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]\n\n@[to_additive add_order_of_dvd_of_nsmul_eq_zero]\nlemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x \u2223 n :=\nis_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)\n\n@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]\nlemma order_of_dvd_iff_pow_eq_one {n : \u2115} : order_of x \u2223 n \u2194 x ^ n = 1 :=\n\u27e8\u03bb h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one\u27e9\n\n@[to_additive add_order_of_map_dvd]\nlemma order_of_map_dvd {H : Type*} [monoid H] (\u03c8 : G \u2192* H) (x : G) :\n  order_of (\u03c8 x) \u2223 order_of x :=\nby { apply order_of_dvd_of_pow_eq_one, rw [\u2190map_pow, pow_order_of_eq_one], apply map_one }\n\n@[to_additive]\nlemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :\n  \u2203 m : \u2115, (x ^ n) ^ m = x :=\nbegin\n  by_cases h0 : order_of x = 0,\n  { rw [h0, coprime_zero_right] at h,\n    exact \u27e81, by rw [h, pow_one, pow_one]\u27e9 },\n  by_cases h1 : order_of x = 1,\n  { exact \u27e80, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]\u27e9 },\n  obtain \u27e8m, hm\u27e9 :=\n    exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr \u27e8h0, h1\u27e9),\n  exact \u27e8m, by rw [\u2190pow_mul, pow_eq_mod_order_of, hm, pow_one]\u27e9,\nend\n\n/--\nIf `x^n = 1`, but `x^(n/p) \u2260 1` for all prime factors `p` of `r`,\nthen `x` has order `n` in `G`.\n-/\n@[to_additive add_order_of_eq_of_nsmul_and_div_prime_nsmul]\ntheorem order_of_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x^n = 1)\n  (hd : \u2200 p : \u2115, p.prime \u2192 p \u2223 n \u2192 x^(n/p) \u2260 1) :\n  order_of x = n :=\nbegin\n  -- Let `a` be `n/(order_of x)`, and show `a = 1`\n  cases exists_eq_mul_right_of_dvd (order_of_dvd_of_pow_eq_one hx) with a ha,\n  suffices : a = 1, by simp [this, ha],\n  -- Assume `a` is not one...\n  by_contra,\n  have a_min_fac_dvd_p_sub_one : a.min_fac \u2223 n,\n  { obtain \u27e8b, hb\u27e9 : \u2203 (b : \u2115), a = b * a.min_fac := exists_eq_mul_left_of_dvd a.min_fac_dvd,\n    rw [hb, \u2190mul_assoc] at ha,\n    exact dvd.intro_left (order_of x * b) ha.symm, },\n  -- Use the minimum prime factor of `a` as `p`.\n  refine hd a.min_fac (nat.min_fac_prime h) a_min_fac_dvd_p_sub_one _,\n  rw [\u2190order_of_dvd_iff_pow_eq_one, nat.dvd_div_iff (a_min_fac_dvd_p_sub_one),\n      ha, mul_comm, nat.mul_dvd_mul_iff_left (order_of_pos' _)],\n  { exact nat.min_fac_dvd a, },\n  { rw is_of_fin_order_iff_pow_eq_one,\n    exact Exists.intro n (id \u27e8hn, hx\u27e9) },\nend\n\n@[to_additive add_order_of_eq_add_order_of_iff]\nlemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :\n  order_of x = order_of y \u2194 \u2200 n : \u2115, x ^ n = 1 \u2194 y ^ n = 1 :=\nby simp_rw [\u2190 is_periodic_pt_mul_iff_pow_eq_one, \u2190 minimal_period_eq_minimal_period_iff, order_of]\n\n@[to_additive add_order_of_injective]\nlemma order_of_injective {H : Type*} [monoid H] (f : G \u2192* H)\n  (hf : function.injective f) (x : G) : order_of (f x) = order_of x :=\nby simp_rw [order_of_eq_order_of_iff, \u2190f.map_pow, \u2190f.map_one, hf.eq_iff, iff_self, forall_const]\n\n@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}\n  (y : H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive]\nlemma order_of_units {y : G\u02e3} : order_of (y : G) = order_of y :=\norder_of_injective (units.coe_hom G) units.ext y\n\nvariables (x)\n\n@[to_additive add_order_of_nsmul']\nlemma order_of_pow' (h : n \u2260 0) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd h,\n  simp only [order_of, mul_left_iterate],\nend\n\nvariables (a) (n)\n\n@[to_additive add_order_of_nsmul'']\nlemma order_of_pow'' (h : is_of_fin_order x) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd' h,\n  simp only [order_of, mul_left_iterate],\nend\n\n@[to_additive]\nlemma commute.order_of_mul_dvd_lcm {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 nat.lcm (order_of x) (order_of y) :=\nbegin\n  convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,\n  rw [order_of, comp_mul_left],\nend\n\n@[to_additive add_order_of_add_dvd_mul_add_order_of]\nlemma commute.order_of_mul_dvd_mul_order_of {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 (order_of x) * (order_of y) :=\ndvd_trans h.order_of_mul_dvd_lcm (lcm_dvd_mul _ _)\n\n@[to_additive add_order_of_add_eq_mul_add_order_of_of_coprime]\nlemma commute.order_of_mul_eq_mul_order_of_of_coprime {x y : G} (h : commute x y)\n  (hco : nat.coprime (order_of x) (order_of y)) :\n  order_of (x * y) = (order_of x) * (order_of y) :=\nbegin\n  convert h.function_commute_mul_left.minimal_period_of_comp_eq_mul_of_coprime hco,\n  simp only [order_of, comp_mul_left],\nend\n\n/-- Commuting elements of finite order are closed under multiplication. -/\n@[to_additive \"Commuting elements of finite additive order are closed under addition.\"]\nlemma commute.is_of_fin_order_mul\n  {x} (h : commute x y) (hx : is_of_fin_order x) (hy : is_of_fin_order y) :\n  is_of_fin_order (x * y) :=\norder_of_pos_iff.mp $\n  pos_of_dvd_of_pos h.order_of_mul_dvd_mul_order_of $ mul_pos (order_of_pos' hx) (order_of_pos' hy)\n\nsection p_prime\n\nvariables {a x n} {p : \u2115} [hp : fact p.prime]\ninclude hp\n\n@[to_additive add_order_of_eq_prime]\nlemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x \u2260 1) : order_of x = p :=\nminimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)\n  (by rwa [is_fixed_pt, mul_one])\n\n@[to_additive add_order_of_eq_prime_pow]\nlemma order_of_eq_prime_pow (hnot : \u00ac x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :\n  order_of x = p ^ (n + 1) :=\nbegin\n  apply minimal_period_eq_prime_pow;\n  rwa is_periodic_pt_mul_iff_pow_eq_one,\nend\n\n@[to_additive exists_add_order_of_eq_prime_pow_iff]\nlemma exists_order_of_eq_prime_pow_iff :\n  (\u2203 k : \u2115, order_of x = p ^ k) \u2194 (\u2203 m : \u2115, x ^ (p : \u2115) ^ m = 1) :=\n\u27e8\u03bb \u27e8k, hk\u27e9, \u27e8k, by rw [\u2190hk, pow_order_of_eq_one]\u27e9, \u03bb \u27e8_, hm\u27e9,\nbegin\n  obtain \u27e8k, _, hk\u27e9 := (nat.dvd_prime_pow hp.elim).mp (order_of_dvd_of_pow_eq_one hm),\n  exact \u27e8k, hk\u27e9,\nend\u27e9\n\nomit hp\n-- An example on how to determine the order of an element of a finite group.\nexample : order_of (-1 : \u2124\u02e3) = 2 :=\norder_of_eq_prime (int.units_sq _) dec_trivial\n\nend p_prime\n\nend monoid_add_monoid\n\nsection cancel_monoid\nvariables [left_cancel_monoid G] (x y)\n\n@[to_additive nsmul_injective_of_lt_add_order_of]\nlemma pow_injective_of_lt_order_of\n  (hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\neq_of_lt_minimal_period_of_iterate_eq hn hm (by simpa only [mul_left_iterate, mul_one])\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of']\nlemma mem_powers_iff_mem_range_order_of' [decidable_eq G] (hx : 0 < order_of x) :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' hx (\u03bb i, pow_eq_mod_order_of.symm)\n\nlemma pow_eq_one_iff_modeq : x ^ n = 1 \u2194 n \u2261 0 [MOD (order_of x)] :=\nby rw [modeq_zero_iff_dvd, order_of_dvd_iff_pow_eq_one]\n\nlemma pow_eq_pow_iff_modeq : x ^ n = x ^ m \u2194 n \u2261 m [MOD (order_of x)] :=\nbegin\n  wlog hmn : m \u2264 n,\n  obtain \u27e8k, rfl\u27e9 := nat.exists_eq_add_of_le hmn,\n  rw [\u2190 mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modeq],\n  exact \u27e8\u03bb h, nat.modeq.add_left _ h, \u03bb h, nat.modeq.add_left_cancel' _ h\u27e9,\nend\n\nend cancel_monoid\n\nsection group\nvariables [group G] [add_group A] {x a} {i : \u2124}\n\n/-- Inverses of elements of finite order have finite order. -/\n@[to_additive \"Inverses of elements of finite additive order have finite additive order.\"]\nlemma is_of_fin_order.inv {x : G} (hx : is_of_fin_order x) : is_of_fin_order x\u207b\u00b9 :=\n(is_of_fin_order_iff_pow_eq_one _).mpr $ begin\n  rcases (is_of_fin_order_iff_pow_eq_one x).mp hx with \u27e8n, npos, hn\u27e9,\n  refine \u27e8n, npos, by simp_rw [inv_pow, hn, inv_one]\u27e9,\nend\n\n/-- Inverses of elements of finite order have finite order. -/\n@[simp, to_additive \"Inverses of elements of finite additive order have finite additive order.\"]\nlemma is_of_fin_order_inv_iff {x : G} : is_of_fin_order x\u207b\u00b9 \u2194 is_of_fin_order x :=\n\u27e8\u03bb h, inv_inv x \u25b8 h.inv, is_of_fin_order.inv\u27e9\n\n@[to_additive add_order_of_dvd_iff_zsmul_eq_zero]\nlemma order_of_dvd_iff_zpow_eq_one : (order_of x : \u2124) \u2223 i \u2194 x ^ i = 1 :=\nbegin\n  rcases int.eq_coe_or_neg i with \u27e8i, rfl|rfl\u27e9,\n  { rw [int.coe_nat_dvd, order_of_dvd_iff_pow_eq_one, zpow_coe_nat] },\n  { rw [dvd_neg, int.coe_nat_dvd, zpow_neg, inv_eq_one, zpow_coe_nat,\n      order_of_dvd_iff_pow_eq_one] }\nend\n\n@[simp, to_additive]\nlemma order_of_inv (x : G) : order_of x\u207b\u00b9 = order_of x :=\nby simp [order_of_eq_order_of_iff]\n\n@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}\n  (y: H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive zsmul_eq_mod_add_order_of]\nlemma zpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=\ncalc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :\n    by rw [int.mod_add_div]\n       ... = x ^ (i % order_of x) :\n    by simp [zpow_add, zpow_mul, pow_order_of_eq_one]\n\n@[to_additive nsmul_inj_iff_of_add_order_of_eq_zero]\nlemma pow_inj_iff_of_order_of_eq_zero (h : order_of x = 0) {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n = m :=\nbegin\n  rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one] at h,\n  push_neg at h,\n  induction n with n IH generalizing m,\n  { cases m,\n    { simp },\n    { simpa [eq_comm] using h m.succ m.zero_lt_succ } },\n  { cases m,\n    { simpa using h n.succ n.zero_lt_succ },\n    { simp [pow_succ, IH] } }\nend\n\n@[to_additive]\nlemma pow_inj_mod {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n % order_of x = m % order_of x :=\nbegin\n  cases (order_of x).zero_le.eq_or_lt with hx hx,\n  { simp [pow_inj_iff_of_order_of_eq_zero, hx.symm] },\n  rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ m],\n  exact \u27e8pow_injective_of_lt_order_of _ (nat.mod_lt _ hx) (nat.mod_lt _ hx), \u03bb h, congr_arg _ h\u27e9\nend\n\nend group\n\nsection comm_monoid\n\nvariables [comm_monoid G]\n\n/-- Elements of finite order are closed under multiplication. -/\n@[to_additive \"Elements of finite additive order are closed under addition.\"]\nlemma is_of_fin_order.mul (hx : is_of_fin_order x) (hy : is_of_fin_order y) :\n  is_of_fin_order (x * y) :=\n(commute.all x y).is_of_fin_order_mul hx hy\n\nend comm_monoid\n\nsection fintype\nvariables [fintype G] [fintype A]\n\nsection finite_monoid\nvariables [monoid G] [add_monoid A]\nopen_locale big_operators\n\n@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]\nlemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :\n  \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n  = (finset.univ.filter (\u03bb x : G, x ^ n = 1)).card :=\ncalc \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n    = _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm\n... = _ : congr_arg finset.card (finset.ext (begin\n  assume x,\n  suffices : order_of x \u2264 n \u2227 order_of x \u2223 n \u2194 x ^ n = 1,\n  { simpa [nat.lt_succ_iff], },\n  exact \u27e8\u03bb h, let \u27e8m, hm\u27e9 := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],\n    \u03bb h, \u27e8order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h\u27e9\u27e9\nend))\n\nend finite_monoid\n\nsection finite_cancel_monoid\n-- TODO: Of course everything also works for right_cancel_monoids.\nvariables [left_cancel_monoid G] [add_left_cancel_monoid A]\n\n-- TODO: Use this to show that a finite left cancellative monoid is a group.\n@[to_additive]\nlemma exists_pow_eq_one (x : G) : is_of_fin_order x :=\nbegin\n  refine (is_of_fin_order_iff_pow_eq_one _).mpr _,\n  obtain \u27e8i, j, a_eq, ne\u27e9 : \u2203(i j : \u2115), x ^ i = x ^ j \u2227 i \u2260 j :=\n    by simpa only [not_forall, exists_prop, injective]\n      using (not_injective_infinite_fintype (\u03bbi:\u2115, x^i)),\n  wlog h'' : j \u2264 i,\n  refine \u27e8i - j, tsub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _\u27e9,\n  rw [mul_one, \u2190 pow_add, \u2190 a_eq, add_tsub_cancel_of_le h''],\nend\n\n@[to_additive add_order_of_le_card_univ]\nlemma order_of_le_card_univ : order_of x \u2264 fintype.card G :=\nfinset.le_card_of_inj_on_range ((^) x)\n  (assume n _, finset.mem_univ _)\n  (assume i hi j hj, pow_injective_of_lt_order_of x hi hj)\n\n/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative monoid.-/\n@[to_additive add_order_of_pos\n\"This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative additive monoid.\"]\nlemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)\n\nopen nat\n\n/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is\nautomatic in the case of a finite cancellative monoid.-/\n@[to_additive add_order_of_nsmul\n\"This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less\nwhich is automatic in the case of a finite cancellative additive monoid.\"]\nlemma order_of_pow (x : G) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of]\nlemma mem_powers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)\n  (assume i, pow_eq_mod_order_of.symm)\n\n@[to_additive decidable_multiples]\nnoncomputable instance decidable_powers [decidable_eq G] :\n  decidable_pred (\u2208 submonoid.powers x) :=\nbegin\n  assume y,\n  apply decidable_of_iff'\n    (y \u2208 (finset.range (order_of x)).image ((^) x)),\n  exact mem_powers_iff_mem_range_order_of\nend\n\n/--The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`.\"-/\n@[to_additive fin_equiv_multiples \"The equivalence between `fin (add_order_of a)` and\n`add_submonoid.multiples a`, sending `i` to `i \u2022 a`.\"]\nnoncomputable def fin_equiv_powers (x : G) :\n  fin (order_of x) \u2243 (submonoid.powers x : set G) :=\nequiv.of_bijective (\u03bb n, \u27e8x ^ \u2191n, \u27e8n, rfl\u27e9\u27e9) \u27e8\u03bb \u27e8i, hi\u27e9 \u27e8j, hj\u27e9 ij,\n  subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),\n  \u03bb \u27e8_, i, rfl\u27e9, \u27e8\u27e8i % order_of x, mod_lt i (order_of_pos x)\u27e9, subtype.eq pow_eq_mod_order_of.symm\u27e9\u27e9\n\n@[simp, to_additive fin_equiv_multiples_apply]\nlemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :\n  fin_equiv_powers x n = \u27e8x ^ \u2191n, n, rfl\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_multiples_symm_apply]\nlemma fin_equiv_powers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2115), x ^ m = x ^ n} :\n  ((fin_equiv_powers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,\n  pow_eq_mod_order_of, fin.coe_mk]\n\n/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive multiples_equiv_multiples\n\"The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def powers_equiv_powers (h : order_of x = order_of y) :\n  (submonoid.powers x : set G) \u2243 (submonoid.powers y : set G) :=\n(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))\n\n@[simp, to_additive multiples_equiv_multiples_apply]\nlemma powers_equiv_powers_apply (h : order_of x = order_of y)\n  (n : \u2115) : powers_equiv_powers h \u27e8x ^ n, n, rfl\u27e9 = \u27e8y ^ n, n, rfl\u27e9 :=\nbegin\n  rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_powers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_powers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_of_eq_card_multiples]\nlemma order_eq_card_powers [decidable_eq G] :\n  order_of x = fintype.card (submonoid.powers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_powers x\u27e9)\n\nend finite_cancel_monoid\n\nsection finite_group\nvariables [group G] [add_group A]\n\n@[to_additive]\nlemma exists_zpow_eq_one (x : G) : \u2203 (i : \u2124) (H : i \u2260 0), x ^ (i : \u2124) = 1 :=\nbegin\n  rcases exists_pow_eq_one x with \u27e8w, hw1, hw2\u27e9,\n  refine \u27e8w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _\u27e9,\n  rw zpow_coe_nat,\n  exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,\nend\n\nopen subgroup\n\n@[to_additive mem_multiples_iff_mem_zmultiples]\nlemma mem_powers_iff_mem_zpowers : y \u2208 submonoid.powers x \u2194 y \u2208 zpowers x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, \u27e8n, by simp * at *\u27e9,\n\u03bb \u27e8i, hi\u27e9, \u27e8(i % order_of x).nat_abs,\n  by rwa [\u2190 zpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _\n    (int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),\n    \u2190 zpow_eq_mod_order_of]\u27e9\u27e9\n\n@[to_additive multiples_eq_zmultiples]\nlemma powers_eq_zpowers (x : G) : (submonoid.powers x : set G) = zpowers x :=\nset.ext $ \u03bb x, mem_powers_iff_mem_zpowers\n\n@[to_additive mem_zmultiples_iff_mem_range_add_order_of]\nlemma mem_zpowers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 subgroup.zpowers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nby rw [\u2190 mem_powers_iff_mem_zpowers, mem_powers_iff_mem_range_order_of]\n\n@[to_additive decidable_zmultiples]\nnoncomputable instance decidable_zpowers [decidable_eq G] :\n  decidable_pred (\u2208 subgroup.zpowers x) :=\nbegin\n  simp_rw \u2190set_like.mem_coe,\n  rw \u2190 powers_eq_zpowers,\n  exact decidable_powers,\nend\n\n/-- The equivalence between `fin (order_of x)` and `subgroup.zpowers x`, sending `i` to `x ^ i`. -/\n@[to_additive fin_equiv_zmultiples\n\"The equivalence between `fin (add_order_of a)` and `subgroup.zmultiples a`, sending `i`\nto `i \u2022 a`.\"]\nnoncomputable def fin_equiv_zpowers (x : G) :\n  fin (order_of x) \u2243 (subgroup.zpowers x : set G) :=\n(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_zpowers x))\n\n@[simp, to_additive fin_equiv_zmultiples_apply]\nlemma fin_equiv_zpowers_apply {n : fin (order_of x)} :\n  fin_equiv_zpowers x n = \u27e8x ^ (n : \u2115), n, zpow_coe_nat x n\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_zmultiples_symm_apply]\nlemma fin_equiv_zpowers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2124), x ^ m = x ^ n} :\n  ((fin_equiv_zpowers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby { rw [fin_equiv_zpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],\n  exact fin_equiv_powers_symm_apply x n }\n\n/-- The equivalence between `subgroup.zpowers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive zmultiples_equiv_zmultiples\n\"The equivalence between `subgroup.zmultiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def zpowers_equiv_zpowers (h : order_of x = order_of y) :\n  (subgroup.zpowers x : set G) \u2243 (subgroup.zpowers y : set G) :=\n(fin_equiv_zpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_zpowers y))\n\n@[simp, to_additive zmultiples_equiv_zmultiples_apply]\nlemma zpowers_equiv_zpowers_apply (h : order_of x = order_of y)\n  (n : \u2115) : zpowers_equiv_zpowers h \u27e8x ^ n, n, zpow_coe_nat x n\u27e9 = \u27e8y ^ n, n, zpow_coe_nat y n\u27e9 :=\nbegin\n  rw [zpowers_equiv_zpowers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_zpowers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_zpowers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_eq_card_zmultiples]\nlemma order_eq_card_zpowers [decidable_eq G] : order_of x = fintype.card (zpowers x) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_zpowers x\u27e9)\n\nopen quotient_group\n\n/- TODO: use cardinal theory, introduce `card : set G \u2192 \u2115`, or setup decidability for cosets -/\n@[to_additive add_order_of_dvd_card_univ]\nlemma order_of_dvd_card_univ : order_of x \u2223 fintype.card G :=\nbegin\n  classical,\n  have ft_prod : fintype ((G \u29f8 zpowers x) \u00d7 zpowers x),\n    from fintype.of_equiv G group_equiv_quotient_times_subgroup,\n  have ft_s : fintype (zpowers x),\n    from @fintype.prod_right _ _ _ ft_prod _,\n  have ft_cosets : fintype (G \u29f8 zpowers x),\n    from @fintype.prod_left _ _ _ ft_prod \u27e8\u27e81, (zpowers x).one_mem\u27e9\u27e9,\n  have eq\u2081 : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,\n    from calc fintype.card G = @fintype.card _ ft_prod :\n        @fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup\n      ... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :\n        congr_arg (@fintype.card _) $ subsingleton.elim _ _\n      ... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :\n        @fintype.card_prod _ _ ft_cosets ft_s,\n  have eq\u2082 : order_of x = @fintype.card _ ft_s,\n    from calc order_of x = _ : order_eq_card_zpowers\n      ... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,\n  exact dvd.intro (@fintype.card (G \u29f8 subgroup.zpowers x) ft_cosets)\n          (by rw [eq\u2081, eq\u2082, mul_comm])\nend\n\n@[simp, to_additive card_nsmul_eq_zero] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=\nlet \u27e8m, hm\u27e9 := @order_of_dvd_card_univ _ x _ _ in\nby simp [hm, pow_mul, pow_order_of_eq_one]\n\n@[to_additive] lemma subgroup.pow_index_mem {G : Type*} [group G] (H : subgroup G)\n  [fintype (G \u29f8 H)] [normal H] (g : G) : g ^ index H \u2208 H :=\nby rw [\u2190eq_one_iff, quotient_group.coe_pow H, index_eq_card, pow_card_eq_one]\n\n@[to_additive] lemma pow_eq_mod_card (n : \u2115) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [pow_eq_mod_order_of, \u2190nat.mod_mod_of_dvd n order_of_dvd_card_univ,\n  \u2190 pow_eq_mod_order_of]\n\n@[to_additive] lemma zpow_eq_mod_card (n : \u2124) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [zpow_eq_mod_order_of, \u2190 int.mod_mod_of_dvd n (int.coe_nat_dvd.2 order_of_dvd_card_univ),\n  \u2190 zpow_eq_mod_order_of]\n\n/-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/\n@[to_additive \"If `gcd(|G|,n)=1` then the smul by `n` is a bijection\", simps]\n  def pow_coprime (h : nat.coprime (fintype.card G) n) : G \u2243 G :=\n{ to_fun := \u03bb g, g ^ n,\n  inv_fun := \u03bb g, g ^ (nat.gcd_b (fintype.card G) n),\n  left_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul, zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key },\n  right_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul', zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key } }\n\n@[simp, to_additive] lemma pow_coprime_one (h : nat.coprime (fintype.card G) n) :\n  pow_coprime h 1 = 1 := one_pow n\n\n@[simp, to_additive] lemma pow_coprime_inv (h : nat.coprime (fintype.card G) n) {g : G} :\n  pow_coprime h g\u207b\u00b9 = (pow_coprime h g)\u207b\u00b9 := inv_pow g n\n\n@[to_additive add_inf_eq_bot_of_coprime]\nlemma inf_eq_bot_of_coprime {G : Type*} [group G] {H K : subgroup G} [fintype H] [fintype K]\n  (h : nat.coprime (fintype.card H) (fintype.card K)) : H \u2293 K = \u22a5 :=\nbegin\n  refine (H \u2293 K).eq_bot_iff_forall.mpr (\u03bb x hx, _),\n  rw [\u2190order_of_eq_one_iff, \u2190nat.dvd_one, \u2190h.gcd_eq_one, nat.dvd_gcd_iff],\n  exact \u27e8(congr_arg (\u2223 fintype.card H) (order_of_subgroup \u27e8x, hx.1\u27e9)).mpr order_of_dvd_card_univ,\n    (congr_arg (\u2223 fintype.card K) (order_of_subgroup \u27e8x, hx.2\u27e9)).mpr order_of_dvd_card_univ\u27e9,\nend\n\nvariable (a)\n\n/-- TODO: Generalise to `submonoid.powers`.-/\n@[to_additive image_range_add_order_of]\nlemma image_range_order_of [decidable_eq G] :\n  finset.image (\u03bb i, x ^ i) (finset.range (order_of x)) = (zpowers x : set G).to_finset :=\nby { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_zpowers_iff_mem_range_order_of] }\n\n/-- TODO: Generalise to `finite_cancel_monoid`. -/\n@[to_additive gcd_nsmul_card_eq_zero_iff]\nlemma pow_gcd_card_eq_one_iff : x ^ n = 1 \u2194 x ^ (gcd n (fintype.card G)) = 1 :=\n\u27e8\u03bb h, pow_gcd_eq_one _ h $ pow_card_eq_one,\n  \u03bb h, let \u27e8m, hm\u27e9 := gcd_dvd_left n (fintype.card G) in\n    by rw [hm, pow_mul, h, one_pow]\u27e9\n\nend finite_group\n\nend fintype\n\nsection pow_is_subgroup\n\n/-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/\n@[to_additive \"A nonempty idempotent subset of a finite cancellative add monoid is a submonoid\"]\ndef submonoid_of_idempotent {M : Type*} [left_cancel_monoid M] [fintype M] (S : set M)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : submonoid M :=\nhave pow_mem : \u2200 a : M, a \u2208 S \u2192 \u2200 n : \u2115, a ^ (n + 1) \u2208 S :=\n\u03bb a ha, nat.rec (by rwa [zero_add, pow_one])\n  (\u03bb n ih, (congr_arg2 (\u2208) (pow_succ a (n + 1)).symm hS2).mp (set.mul_mem_mul ha ih)),\n{ carrier := S,\n  one_mem' := by\n  { obtain \u27e8a, ha\u27e9 := hS1,\n    rw [\u2190pow_order_of_eq_one a, \u2190 tsub_add_cancel_of_le (succ_le_of_lt (order_of_pos a))],\n    exact pow_mem a ha (order_of a - 1) },\n  mul_mem' := \u03bb a b ha hb, (congr_arg2 (\u2208) rfl hS2).mp (set.mul_mem_mul ha hb) }\n\n/-- A nonempty idempotent subset of a finite group is a subgroup -/\n@[to_additive \"A nonempty idempotent subset of a finite add group is a subgroup\"]\ndef subgroup_of_idempotent {G : Type*} [group G] [fintype G] (S : set G)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : subgroup G :=\n{ carrier := S,\n  inv_mem' := \u03bb a ha, show a\u207b\u00b9 \u2208 submonoid_of_idempotent S hS1 hS2, by\n  { rw [\u2190one_mul a\u207b\u00b9, \u2190pow_one a, \u2190pow_order_of_eq_one a, \u2190pow_sub a (order_of_pos a)],\n    exact pow_mem ha (order_of a - 1) },\n  .. submonoid_of_idempotent S hS1 hS2 }\n\n/-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/\n@[to_additive smul_card_add_subgroup \"If `S` is a nonempty subset of a finite add group `G`,\n  then `|G| \u2022 S` is a subgroup\", simps]\ndef pow_card_subgroup {G : Type*} [group G] [fintype G] (S : set G) (hS : S.nonempty) :\n  subgroup G :=\nhave one_mem : (1 : G) \u2208 (S ^ fintype.card G) := by\n{ obtain \u27e8a, ha\u27e9 := hS,\n  rw \u2190 pow_card_eq_one,\n  exact set.pow_mem_pow ha (fintype.card G) },\nsubgroup_of_idempotent (S ^ (fintype.card G)) \u27e81, one_mem\u27e9 begin\n  classical!,\n  refine (set.eq_of_subset_of_card_le (set.subset_mul_left _ one_mem) (ge_of_eq _)).symm,\n  simp_rw [\u2190 pow_add, group.card_pow_eq_card_pow_card_univ S (fintype.card G) le_rfl,\n      group.card_pow_eq_card_pow_card_univ S (fintype.card G + fintype.card G) le_add_self],\nend\n\nend pow_is_subgroup\n\nsection linear_ordered_ring\n\nvariable [linear_ordered_ring G]\n\nlemma order_of_abs_ne_one (h : |x| \u2260 1) : order_of x = 0 :=\nbegin\n  rw order_of_eq_zero_iff',\n  intros n hn hx,\n  replace hx : |x| ^ n = 1 := by simpa only [abs_one, abs_pow] using congr_arg abs hx,\n  cases h.lt_or_lt with h h,\n  { exact ((pow_lt_one (abs_nonneg x) h hn.ne').ne hx).elim },\n  { exact ((one_lt_pow h hn.ne').ne' hx).elim }\nend\n\nlemma linear_ordered_ring.order_of_le_two : order_of x \u2264 2 :=\nbegin\n  cases ne_or_eq (|x|) 1 with h h,\n  { simp [order_of_abs_ne_one h] },\n  rcases eq_or_eq_neg_of_abs_eq h with rfl | rfl,\n  { simp },\n  apply order_of_le_of_pow_eq_one; norm_num\nend\n\nend linear_ordered_ring\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/group_theory/order_of_element.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7098711913241671}}
{"text": "import matroid.axioms  \nimport prelim.collections prelim.size \n\nuniverses u \n\n----------------------------------------------------------------\nopen set \nnoncomputable theory \n\nnamespace matroid \n\nsection dual\nvariables {\u03b1 : Type*} [fintype \u03b1]\n \nlemma rank_empt (M : matroid \u03b1) :\n  M.r \u2205 = 0 :=\nle_antisymm (calc M.r \u2205 \u2264 _ : M.R1 \u2205 ... = 0 : size_empty \u03b1) (M.R0 \u2205)\n\n-- Every matroid has a dual.\ndef dual :\n  matroid \u03b1 \u2192 matroid \u03b1 :=\nfun M, {\n  r := (fun X, size X + M.r X\u1d9c - M.r univ),\n  R0 := (fun X,\n    calc 0 \u2264 M.r X  + M.r X\u1d9c - M.r (X \u222a X\u1d9c) - M.r (X \u2229 X\u1d9c) : by linarith [M.R3 X X\u1d9c]\n    ...    = M.r X  + M.r X\u1d9c - M.r univ        - M.r \u2205        : by rw [union_compl_self X, inter_compl_self X]\n    ...    \u2264 size X + M.r X\u1d9c - M.r univ                       : by linarith [M.R1 X, rank_empt M]),\n  R1 := (fun X, by {simp only, linarith [M.R2 _ _ (subset_univ X\u1d9c)]}),\n  R2 := (fun X Y h, let\n    Z := X\u1d9c \u2229 Y,\n    h\u2081 :=\n      calc Y\u1d9c \u222a Z = (X\u1d9c \u2229 Y) \u222a Y\u1d9c        : by apply union_comm\n      ...         = (X\u1d9c \u222a Y\u1d9c) \u2229 (Y \u222a Y\u1d9c) : by apply union_distrib_right\n      ...         = (X \u2229 Y)\u1d9c \u2229 univ         : by rw [compl_inter X Y, union_compl_self Y]\n      ...         = (X \u2229 Y)\u1d9c             : by apply inter_univ\n      ...         = X\u1d9c                   : by rw [subset_iff_inter_eq_left.mp h],\n    h\u2082 :=\n      calc Y\u1d9c \u2229 Z = (X\u1d9c \u2229 Y) \u2229 Y\u1d9c : by apply inter_comm\n      ...         = X\u1d9c \u2229 (Y \u2229 Y\u1d9c) : by apply inter_assoc\n      ...         = X\u1d9c \u2229 \u2205        : by rw [inter_compl_self Y]\n      ...         = \u2205             : by apply inter_empty,\n    h\u2083 :=\n      calc M.r X\u1d9c = M.r X\u1d9c + M.r \u2205              : by linarith [rank_empt M]\n      ...         = M.r (Y\u1d9c \u222a Z) + M.r (Y\u1d9c \u2229 Z) : by rw [h\u2081, h\u2082]\n      ...         \u2264 M.r Y\u1d9c + M.r Z              : by apply M.R3\n      ...         \u2264 M.r Y\u1d9c + size Z             : by linarith [M.R1 Z]\n      ...         = M.r Y\u1d9c + size (X\u1d9c \u2229 Y)      : by refl\n      ...         = M.r Y\u1d9c + size Y - size X    : by linarith [compl_inter_size_subset h]\n    in by {simp only, linarith}),\n  R3 := (fun X Y,\n    calc  size (X \u222a Y) + M.r (X \u222a Y)\u1d9c  - M.r univ + (size (X \u2229 Y) + M.r (X \u2229 Y)\u1d9c  - M.r univ)\n        = size (X \u222a Y) + M.r (X\u1d9c \u2229 Y\u1d9c) - M.r univ + (size (X \u2229 Y) + M.r (X\u1d9c \u222a Y\u1d9c) - M.r univ) : by rw [compl_union X Y, compl_inter X Y]\n    ... \u2264 size X       + M.r X\u1d9c        - M.r univ + (size Y       + M.r Y\u1d9c        - M.r univ) : by linarith [size_modular X Y, M.R3 X\u1d9c Y\u1d9c]),\n}\n\n-- Duality is an involution \n@[simp] lemma dual_dual (M : matroid \u03b1) :\n  dual (dual M) = M :=\nbegin\n  apply rankfun.ext, apply funext, intro X, calc\n  (dual (dual M)).r X = size X + (size X\u1d9c + M.r X\u1d9c\u1d9c - M.r univ) - (size univ + M.r univ\u1d9c - M.r univ) : rfl\n  ...                 = size X + (size X\u1d9c + M.r X   - M.r univ) - (size univ + M.r \u2205  - M.r univ) : by rw [compl_compl, compl_univ]\n  ...                 = M.r X                                                             : by linarith [size_compl X, rank_empt M]\nend\n\nlemma dual_inj {M\u2081 M\u2082 : matroid \u03b1} :\n  dual M\u2081 = dual M\u2082 \u2192 M\u2081 = M\u2082 := \n\u03bb h, by rw [\u2190dual_dual M\u2081, \u2190dual_dual M\u2082, h]\n\nlemma dual_inj_iff {M\u2081 M\u2082 : matroid \u03b1} :\n  dual M\u2081 = dual M\u2082 \u2194 M\u2081 = M\u2082 := \n\u27e8\u03bb h, dual_inj h, \u03bb h, by rw h\u27e9\n\nlemma dual_r (M : matroid \u03b1) (X : set \u03b1) :\n  (dual M).r X = size X + M.r X\u1d9c - M.r univ := \nrfl \n\nend /-section-/ dual\n\nend matroid \n\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_basic/dual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7098206600910664}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module algebra.star.basic\n! leanprover-community/mathlib commit 30413fc89f202a090a54d78e540963ed3de0056e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Ring.Aut\nimport Mathlib.Algebra.Ring.CompTypeclasses\nimport Mathlib.Data.Rat.Cast\nimport Mathlib.GroupTheory.GroupAction.Opposite\nimport Mathlib.Data.SetLike.Basic\nimport Mathlib.Tactic.ScopedNS\n\n/-!\n# Star monoids, rings, and modules\n\nWe introduce the basic algebraic notions of star monoids, star rings, and star modules.\nA star algebra is simply a star ring that is also a star module.\n\nThese are implemented as \"mixin\" typeclasses, so to summon a star ring (for example)\none needs to write `(R : Type _) [Ring R] [StarRing R]`.\nThis avoids difficulties with diamond inheritance.\n\nWe also define the class `StarOrderedRing R`, which says that the order on `R` respects the\nstar operation, i.e. an element `r` is nonnegative iff there exists an `s` such that\n`r = star s * s`.\n\nFor now we simply do not introduce notations,\nas different users are expected to feel strongly about the relative merits of\n`r^*`, `r\u2020`, `r\u1601`, and so on.\n\nOur star rings are actually star semirings, but of course we can prove\n`star_neg : star (-r) = - star r` when the underlying semiring is a ring.\n\n## TODO\n\n* In a Banach star algebra without a well-defined square root, the natural ordering is given by the\npositive cone which is the closure of the sums of elements `star r * r`. A weaker version of\n`StarOrderedRing` could be defined for this case. Note that the current definition has the\nadvantage of not requiring a topology.\n-/\n\n-- Porting note: `assert_not_exists` not implemented yet\n--assert_not_exists finset\n--assert_not_exists subgroup\n\nuniverse u v\n\nopen MulOpposite\n\n/-- Notation typeclass (with no default notation!) for an algebraic structure with a star operation.\n-/\nclass Star (R : Type u) where\n  star : R \u2192 R\n#align has_star Star\n\nvariable {R : Type u}\n\nexport Star (star)\n\n/-- A star operation (e.g. complex conjugate).\n-/\nadd_decl_doc star\n\n/-- `StarMemClass S G` states `S` is a type of subsets `s \u2286 G` closed under star. -/\nclass StarMemClass (S R : Type _) [Star R] [SetLike S R] where\n  /-- Closure under star. -/\n  star_mem : \u2200 {s : S} {r : R}, r \u2208 s \u2192 star r \u2208 s\n#align star_mem_class StarMemClass\n\nexport StarMemClass (star_mem)\n\nnamespace StarMemClass\n\nvariable {S : Type u} [Star R] [SetLike S R] [hS : StarMemClass S R] (s : S)\n\nnonrec instance star : Star s where\n  star r := \u27e8star (r : R), star_mem r.prop\u27e9\n\nend StarMemClass\n\n/-- Typeclass for a star operation with is involutive.\n-/\nclass InvolutiveStar (R : Type u) extends Star R where\n  /-- Involutive condition. -/\n  star_involutive : Function.Involutive star\n#align has_involutive_star InvolutiveStar\n\nexport InvolutiveStar (star_involutive)\n\n@[simp]\ntheorem star_star [InvolutiveStar R] (r : R) : star (star r) = r :=\n  star_involutive _\n#align star_star star_star\n\ntheorem star_injective [InvolutiveStar R] : Function.Injective (star : R \u2192 R) :=\n  Function.Involutive.injective star_involutive\n#align star_injective star_injective\n\n/-- `star` as an equivalence when it is involutive. -/\nprotected def Equiv.star [InvolutiveStar R] : Equiv.Perm R :=\n  star_involutive.toPerm _\n#align equiv.star Equiv.star\n\ntheorem eq_star_of_eq_star [InvolutiveStar R] {r s : R} (h : r = star s) : s = star r := by\n  simp [h]\n#align eq_star_of_eq_star eq_star_of_eq_star\n\ntheorem eq_star_iff_eq_star [InvolutiveStar R] {r s : R} : r = star s \u2194 s = star r :=\n  \u27e8eq_star_of_eq_star, eq_star_of_eq_star\u27e9\n#align eq_star_iff_eq_star eq_star_iff_eq_star\n\ntheorem star_eq_iff_star_eq [InvolutiveStar R] {r s : R} : star r = s \u2194 star s = r :=\n  eq_comm.trans <| eq_star_iff_eq_star.trans eq_comm\n#align star_eq_iff_star_eq star_eq_iff_star_eq\n\n/-- Typeclass for a trivial star operation. This is mostly meant for `\u211d`.\n-/\nclass TrivialStar (R : Type u) [Star R] : Prop where\n  /-- Condition that star is trivial-/\n  star_trivial : \u2200 r : R, star r = r\n#align has_trivial_star TrivialStar\n\nexport TrivialStar (star_trivial)\n\nattribute [simp] star_trivial\n\n/-- A `*`-semigroup is a semigroup `R` with an involutive operation `star`\nsuch that `star (r * s) = star s * star r`.\n-/\nclass StarSemigroup (R : Type u) [Semigroup R] extends InvolutiveStar R where\n  /-- `star` skew-distributes over multiplication. -/\n  star_mul : \u2200 r s : R, star (r * s) = star s * star r\n#align star_semigroup StarSemigroup\n\nexport StarSemigroup (star_mul)\n\nattribute [simp 900] star_mul\n\n/-- In a commutative ring, make `simp` prefer leaving the order unchanged. -/\n@[simp]\ntheorem star_mul' [CommSemigroup R] [StarSemigroup R] (x y : R) : star (x * y) = star x * star y :=\n  (star_mul x y).trans (mul_comm _ _)\n#align star_mul' star_mul'\n\n/-- `star` as a `MulEquiv` from `R` to `R\u1d50\u1d52\u1d56` -/\n@[simps apply]\ndef starMulEquiv [Semigroup R] [StarSemigroup R] : R \u2243* R\u1d50\u1d52\u1d56 :=\n  {\n    (InvolutiveStar.star_involutive.toPerm star).trans\n      opEquiv with\n    toFun := fun x => MulOpposite.op (star x)\n    map_mul' := fun x y => by simp only [star_mul, op_mul] }\n#align star_mul_equiv starMulEquiv\n#align star_mul_equiv_apply starMulEquiv_apply\n\n/-- `star` as a `MulAut` for commutative `R`. -/\n@[simps apply]\ndef starMulAut [CommSemigroup R] [StarSemigroup R] : MulAut R :=\n  {\n    InvolutiveStar.star_involutive.toPerm\n      star with\n    toFun := star\n    map_mul' := star_mul' }\n#align star_mul_aut starMulAut\n#align star_mul_aut_apply starMulAut_apply\n\nvariable (R)\n\n@[simp]\ntheorem star_one [Monoid R] [StarSemigroup R] : star (1 : R) = 1 :=\n  op_injective <| (starMulEquiv : R \u2243* R\u1d50\u1d52\u1d56).map_one.trans (op_one _).symm\n#align star_one star_one\n\nvariable {R}\n\n@[simp]\ntheorem star_pow [Monoid R] [StarSemigroup R] (x : R) (n : \u2115) : star (x ^ n) = star x ^ n :=\n  op_injective <|\n    ((starMulEquiv : R \u2243* R\u1d50\u1d52\u1d56).toMonoidHom.map_pow x n).trans (op_pow (star x) n).symm\n#align star_pow star_pow\n\n@[simp]\ntheorem star_inv [Group R] [StarSemigroup R] (x : R) : star x\u207b\u00b9 = (star x)\u207b\u00b9 :=\n  op_injective <| ((starMulEquiv : R \u2243* R\u1d50\u1d52\u1d56).toMonoidHom.map_inv x).trans (op_inv (star x)).symm\n#align star_inv star_inv\n\n@[simp]\ntheorem star_zpow [Group R] [StarSemigroup R] (x : R) (z : \u2124) : star (x ^ z) = star x ^ z :=\n  op_injective <|\n    ((starMulEquiv : R \u2243* R\u1d50\u1d52\u1d56).toMonoidHom.map_zpow x z).trans (op_zpow (star x) z).symm\n#align star_zpow star_zpow\n\n/-- When multiplication is commutative, `star` preserves division. -/\n@[simp]\ntheorem star_div [CommGroup R] [StarSemigroup R] (x y : R) : star (x / y) = star x / star y :=\n  map_div (starMulAut : R \u2243* R) _ _\n#align star_div star_div\n\n/-- Any commutative monoid admits the trivial `*`-structure.\n\nSee note [reducible non-instances].\n-/\n@[reducible]\ndef starSemigroupOfComm {R : Type _} [CommMonoid R] : StarSemigroup R where\n  star := id\n  star_involutive _ := rfl\n  star_mul := mul_comm\n#align star_semigroup_of_comm starSemigroupOfComm\n\nsection\n\nattribute [local instance] starSemigroupOfComm\n\n/-- Note that since `starSemigroupOfComm` is reducible, `simp` can already prove this. -/\ntheorem star_id_of_comm {R : Type _} [CommSemiring R] {x : R} : star x = x :=\n  rfl\n#align star_id_of_comm star_id_of_comm\n\nend\n\n/-- A `*`-additive monoid `R` is an additive monoid with an involutive `star` operation which\npreserves addition.  -/\nclass StarAddMonoid (R : Type u) [AddMonoid R] extends InvolutiveStar R where\n  /-- `star` commutes with addition -/\n  star_add : \u2200 r s : R, star (r + s) = star r + star s\n#align star_add_monoid StarAddMonoid\n\nexport StarAddMonoid (star_add)\n\nattribute [simp] star_add\n\n/-- `star` as an `AddEquiv` -/\n@[simps apply]\ndef starAddEquiv [AddMonoid R] [StarAddMonoid R] : R \u2243+ R :=\n  {\n    InvolutiveStar.star_involutive.toPerm\n      star with\n    toFun := star\n    map_add' := star_add }\n#align star_add_equiv starAddEquiv\n#align star_add_equiv_apply starAddEquiv_apply\n\nvariable (R)\n\n@[simp]\ntheorem star_zero [AddMonoid R] [StarAddMonoid R] : star (0 : R) = 0 :=\n  (starAddEquiv : R \u2243+ R).map_zero\n#align star_zero star_zero\n\nvariable {R}\n\n@[simp]\ntheorem star_eq_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x = 0 \u2194 x = 0 :=\n  starAddEquiv.map_eq_zero_iff\n#align star_eq_zero star_eq_zero\n\ntheorem star_ne_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x \u2260 0 \u2194 x \u2260 0 := by\n  simp only [ne_eq, star_eq_zero]\n#align star_ne_zero star_ne_zero\n\n@[simp]\ntheorem star_neg [AddGroup R] [StarAddMonoid R] (r : R) : star (-r) = -star r :=\n  (starAddEquiv : R \u2243+ R).map_neg _\n#align star_neg star_neg\n\n@[simp]\ntheorem star_sub [AddGroup R] [StarAddMonoid R] (r s : R) : star (r - s) = star r - star s :=\n  (starAddEquiv : R \u2243+ R).map_sub _ _\n#align star_sub star_sub\n\n@[simp]\ntheorem star_nsmul [AddMonoid R] [StarAddMonoid R] (x : R) (n : \u2115) : star (n \u2022 x) = n \u2022 star x :=\n  (starAddEquiv : R \u2243+ R).toAddMonoidHom.map_nsmul _ _\n#align star_nsmul star_nsmul\n\n@[simp]\ntheorem star_zsmul [AddGroup R] [StarAddMonoid R] (x : R) (n : \u2124) : star (n \u2022 x) = n \u2022 star x :=\n  (starAddEquiv : R \u2243+ R).toAddMonoidHom.map_zsmul _ _\n#align star_zsmul star_zsmul\n\n/-- A `*`-ring `R` is a (semi)ring with an involutive `star` operation which is additive\nwhich makes `R` with its multiplicative structure into a `*`-semigroup\n(i.e. `star (r * s) = star s * star r`).  -/\nclass StarRing (R : Type u) [NonUnitalSemiring R] extends StarSemigroup R where\n  /-- `star` commutes with addition -/\n  star_add : \u2200 r s : R, star (r + s) = star r + star s\n#align star_ring StarRing\n\ninstance (priority := 100) StarRing.toStarAddMonoid [NonUnitalSemiring R] [StarRing R] :\n    StarAddMonoid R where star_add := StarRing.star_add\n#align star_ring.to_star_add_monoid StarRing.toStarAddMonoid\n\n/-- `star` as an `RingEquiv` from `R` to `R\u1d50\u1d52\u1d56` -/\n@[simps apply]\ndef starRingEquiv [NonUnitalSemiring R] [StarRing R] : R \u2243+* R\u1d50\u1d52\u1d56 :=\n  { starAddEquiv.trans (MulOpposite.opAddEquiv : R \u2243+ R\u1d50\u1d52\u1d56), starMulEquiv with\n    toFun := fun x => MulOpposite.op (star x) }\n#align star_ring_equiv starRingEquiv\n#align star_ring_equiv_apply starRingEquiv_apply\n\n@[simp, norm_cast]\ntheorem star_natCast [Semiring R] [StarRing R] (n : \u2115) : star (n : R) = n :=\n  (congr_arg unop (map_natCast (starRingEquiv : R \u2243+* R\u1d50\u1d52\u1d56) n)).trans (unop_natCast _)\n#align star_nat_cast star_natCast\n\n--Porting note: new theorem\n@[simp]\ntheorem star_ofNat [Semiring R] [StarRing R] (n : \u2115) [n.AtLeastTwo]:\n    star (OfNat.ofNat n : R) = OfNat.ofNat n :=\n  star_natCast _\n\nsection\n-- Porting note: This takes too long\nset_option maxHeartbeats 0\n\n@[simp, norm_cast]\ntheorem star_intCast [Ring R] [StarRing R] (z : \u2124) : star (z : R) = z :=\n  (congr_arg unop <| map_intCast (starRingEquiv : R \u2243+* R\u1d50\u1d52\u1d56) z).trans (unop_intCast _)\n#align star_int_cast star_intCast\n\n@[simp, norm_cast]\ntheorem star_ratCast [DivisionRing R] [StarRing R] (r : \u211a) : star (r : R) = r :=\n  (congr_arg unop <| map_ratCast (starRingEquiv : R \u2243+* R\u1d50\u1d52\u1d56) r).trans (unop_ratCast _)\n#align star_rat_cast star_ratCast\n\nend\n\n/-- `star` as a ring automorphism, for commutative `R`. -/\n@[simps apply]\ndef starRingAut [CommSemiring R] [StarRing R] : RingAut R :=\n  { starAddEquiv, starMulAut (R := R) with toFun := star }\n#align star_ring_aut starRingAut\n#align star_ring_aut_apply starRingAut_apply\n\nvariable (R)\n\n/-- `star` as a ring endomorphism, for commutative `R`. This is used to denote complex\nconjugation, and is available under the notation `conj` in the locale `ComplexConjugate`.\n\nNote that this is the preferred form (over `starRingAut`, available under the same hypotheses)\nbecause the notation `E \u2192\u2097\u22c6[R] F` for an `R`-conjugate-linear map (short for\n`E \u2192\u209b\u2097[starRingEnd R] F`) does not pretty-print if there is a coercion involved, as would be the\ncase for `(\u2191starRingAut : R \u2192* R)`. -/\ndef starRingEnd [CommSemiring R] [StarRing R] : R \u2192+* R :=\n  @starRingAut R _ _\n#align star_ring_end starRingEnd\n\nvariable {R}\n\n-- mathport name: star_ring_end\n@[inherit_doc]\nscoped[ComplexConjugate] notation \"conj\" => starRingEnd _\n\n/-- This is not a simp lemma, since we usually want simp to keep `starRingEnd` bundled.\n For example, for complex conjugation, we don't want simp to turn `conj x`\n into the bare function `star x` automatically since most lemmas are about `conj x`. -/\ntheorem starRingEnd_apply [CommSemiring R] [StarRing R] {x : R} : starRingEnd R x = star x :=\n  rfl\n#align star_ring_end_apply starRingEnd_apply\n\n/- Porting note: removed `simp` attribute due to report by linter:\n\nsimp can prove this:\n  by simp only [RingHomCompTriple.comp_apply, RingHom.id_apply]\nOne of the lemmas above could be a duplicate.\nIf that's not the case try reordering lemmas or adding @[priority].\n -/\n-- @[simp]\ntheorem starRingEnd_self_apply [CommSemiring R] [StarRing R] (x : R) :\n    starRingEnd R (starRingEnd R x) = x :=\n  star_star x\n#align star_ring_end_self_apply starRingEnd_self_apply\n\ninstance RingHom.involutiveStar {S : Type _} [NonAssocSemiring S] [CommSemiring R] [StarRing R] :\n    InvolutiveStar (S \u2192+* R)\n    where\n  toStar := { star := fun f => RingHom.comp (starRingEnd R) f }\n  star_involutive := by\n    intro\n    ext\n    simp only [RingHom.coe_comp, Function.comp_apply, starRingEnd_self_apply]\n#align ring_hom.has_involutive_star RingHom.involutiveStar\n\ntheorem RingHom.star_def {S : Type _} [NonAssocSemiring S] [CommSemiring R] [StarRing R]\n    (f : S \u2192+* R) : Star.star f = RingHom.comp (starRingEnd R) f :=\n  rfl\n#align ring_hom.star_def RingHom.star_def\n\ntheorem RingHom.star_apply {S : Type _} [NonAssocSemiring S] [CommSemiring R] [StarRing R]\n    (f : S \u2192+* R) (s : S) : star f s = star (f s) :=\n  rfl\n#align ring_hom.star_apply RingHom.star_apply\n\n-- A more convenient name for complex conjugation\nalias starRingEnd_self_apply \u2190 Complex.conj_conj\n#align complex.conj_conj Complex.conj_conj\n\nalias starRingEnd_self_apply \u2190 IsROrC.conj_conj\nset_option linter.uppercaseLean3 false in\n#align is_R_or_C.conj_conj IsROrC.conj_conj\n\n@[simp]\ntheorem star_inv' [DivisionSemiring R] [StarRing R] (x : R) : star x\u207b\u00b9 = (star x)\u207b\u00b9 :=\n  op_injective <| (map_inv\u2080 (starRingEquiv : R \u2243+* R\u1d50\u1d52\u1d56) x).trans (op_inv (star x)).symm\n#align star_inv' star_inv'\n\n@[simp]\ntheorem star_zpow\u2080 [DivisionSemiring R] [StarRing R] (x : R) (z : \u2124) : star (x ^ z) = star x ^ z :=\n  op_injective <| (map_zpow\u2080 (starRingEquiv : R \u2243+* R\u1d50\u1d52\u1d56) x z).trans (op_zpow (star x) z).symm\n#align star_zpow\u2080 star_zpow\u2080\n\n/-- When multiplication is commutative, `star` preserves division. -/\n@[simp]\ntheorem star_div' [Semifield R] [StarRing R] (x y : R) : star (x / y) = star x / star y := by\n  apply op_injective\n  rw [division_def, op_div, mul_comm, star_mul, star_inv', op_mul, op_inv]\n#align star_div' star_div'\n\nsection\n\nset_option linter.deprecated false\n\n@[simp]\ntheorem star_bit0 [AddMonoid R] [StarAddMonoid R] (r : R) : star (bit0 r) = bit0 (star r) := by\n  simp [bit0]\n#align star_bit0 star_bit0\n\n@[simp]\ntheorem star_bit1 [Semiring R] [StarRing R] (r : R) : star (bit1 r) = bit1 (star r) := by\n  simp [bit1]\n#align star_bit1 star_bit1\n\nend\n\n/-- Any commutative semiring admits the trivial `*`-structure.\n\nSee note [reducible non-instances].\n-/\n@[reducible]\ndef starRingOfComm {R : Type _} [CommSemiring R] : StarRing R :=\n  { starSemigroupOfComm with\n    star := id\n    star_add := fun _ _ => rfl }\n#align star_ring_of_comm starRingOfComm\n\n/-- An ordered `*`-ring is a ring which is both an `OrderedAddCommGroup` and a `*`-ring,\nand `0 \u2264 r \u2194 \u2203 s, r = star s * s`.\n-/\nclass StarOrderedRing (R : Type u) [NonUnitalSemiring R] [PartialOrder R] extends StarRing R where\n  /-- addition commutes with `\u2264` -/\n  add_le_add_left : \u2200 a b : R, a \u2264 b \u2192 \u2200 c : R, c + a \u2264 c + b\n  /--characterization of non-negativity  -/\n  nonneg_iff : \u2200 r : R, 0 \u2264 r \u2194 \u2203 s, r = star s * s\n#align star_ordered_ring StarOrderedRing\n\nnamespace StarOrderedRing\n\n-- see note [lower instance priority]\ninstance (priority := 100) [NonUnitalRing R] [PartialOrder R] [StarOrderedRing R] :\n    OrderedAddCommGroup R :=\n  { inferInstanceAs (NonUnitalRing R), inferInstanceAs (PartialOrder R),\n    inferInstanceAs (StarOrderedRing R) with }\n\nend StarOrderedRing\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring R] [PartialOrder R] [StarOrderedRing R]\n\ntheorem star_mul_self_nonneg {r : R} : 0 \u2264 star r * r :=\n  (StarOrderedRing.nonneg_iff _).mpr \u27e8r, rfl\u27e9\n#align star_mul_self_nonneg star_mul_self_nonneg\n\ntheorem star_mul_self_nonneg' {r : R} : 0 \u2264 r * star r := by\n  have : r * star r = star (star r) * star r := by simp only [star_star]\n  rw [this]\n  exact star_mul_self_nonneg\n#align star_mul_self_nonneg' star_mul_self_nonneg'\n\ntheorem conjugate_nonneg {a : R} (ha : 0 \u2264 a) (c : R) : 0 \u2264 star c * a * c := by\n  obtain \u27e8x, h\u27e9 := (StarOrderedRing.nonneg_iff _).1 ha\n  apply (StarOrderedRing.nonneg_iff _).2\n  exists x * c\n  simp only [h, star_mul, \u2190 mul_assoc]\n#align conjugate_nonneg conjugate_nonneg\n\ntheorem conjugate_nonneg' {a : R} (ha : 0 \u2264 a) (c : R) : 0 \u2264 c * a * star c := by\n  simpa only [star_star] using conjugate_nonneg ha (star c)\n#align conjugate_nonneg' conjugate_nonneg'\n\nend NonUnitalSemiring\n\nsection NonUnitalRing\n\nvariable [NonUnitalRing R] [PartialOrder R] [StarOrderedRing R]\n\ntheorem conjugate_le_conjugate {a b : R} (hab : a \u2264 b) (c : R) :\n    star c * a * c \u2264 star c * b * c := by\n  rw [\u2190 sub_nonneg] at hab\u22a2\n  convert conjugate_nonneg hab c using 1\n  simp only [mul_sub, sub_mul]\n#align conjugate_le_conjugate conjugate_le_conjugate\n\ntheorem conjugate_le_conjugate' {a b : R} (hab : a \u2264 b) (c : R) :\n    c * a * star c \u2264 c * b * star c := by\n  simpa only [star_star] using conjugate_le_conjugate hab (star c)\n#align conjugate_le_conjugate' conjugate_le_conjugate'\n\nend NonUnitalRing\n\n/-- A star module `A` over a star ring `R` is a module which is a star add monoid,\nand the two star structures are compatible in the sense\n`star (r \u2022 a) = star r \u2022 star a`.\n\nNote that it is up to the user of this typeclass to enforce\n`[Semiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A]`, and that\nthe statement only requires `[Star R] [Star A] [SMul R A]`.\n\nIf used as `[CommRing R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A]`, this represents a\nstar algebra.\n-/\n\nclass StarModule (R : Type u) (A : Type v) [Star R] [Star A] [SMul R A] : Prop where\n  /-- `star` commutes with scalar multiplication -/\n  star_smul : \u2200 (r : R) (a : A), star (r \u2022 a) = star r \u2022 star a\n#align star_module StarModule\n\nexport StarModule (star_smul)\n\nattribute [simp] star_smul\n\n/-- A commutative star monoid is a star module over itself via `Monoid.toMulAction`. -/\ninstance StarSemigroup.to_starModule [CommMonoid R] [StarSemigroup R] : StarModule R R :=\n  \u27e8star_mul'\u27e9\n#align star_semigroup.to_star_module StarSemigroup.to_starModule\n\nnamespace RingHomInvPair\n\n/-- Instance needed to define star-linear maps over a commutative star ring\n(ex: conjugate-linear maps when R = \u2102).  -/\ninstance [CommSemiring R] [StarRing R] : RingHomInvPair (starRingEnd R) (starRingEnd R) :=\n  \u27e8RingHom.ext star_star, RingHom.ext star_star\u27e9\n\nend RingHomInvPair\n\nsection\n\n/-- `StarHomClass F R S` states that `F` is a type of `star`-preserving maps from `R` to `S`. -/\nclass StarHomClass (F : Type _) (R S : outParam (Type _)) [Star R] [Star S] extends\n  FunLike F R fun _ => S where\n  /-- the maps preserve star -/\n  map_star : \u2200 (f : F) (r : R), f (star r) = star (f r)\n#align star_hom_class StarHomClass\n\nexport StarHomClass (map_star)\n\nend\n\n/-! ### Instances -/\n\n\nnamespace Units\n\nvariable [Monoid R] [StarSemigroup R]\n\ninstance : StarSemigroup R\u02e3\n    where\n  star u :=\n    { val := star u\n      inv := star \u2191u\u207b\u00b9\n      val_inv := (star_mul _ _).symm.trans <| (congr_arg star u.inv_val).trans <| star_one _\n      inv_val := (star_mul _ _).symm.trans <| (congr_arg star u.val_inv).trans <| star_one _ }\n  star_involutive _ := Units.ext (star_involutive _)\n  star_mul _ _ := Units.ext (star_mul _ _)\n\n@[simp]\ntheorem coe_star (u : R\u02e3) : \u2191(star u) = (star \u2191u : R) :=\n  rfl\n#align units.coe_star Units.coe_star\n\n@[simp]\ntheorem coe_star_inv (u : R\u02e3) : \u2191(star u)\u207b\u00b9 = (star \u2191u\u207b\u00b9 : R) :=\n  rfl\n#align units.coe_star_inv Units.coe_star_inv\n\ninstance {A : Type _} [Star A] [SMul R A] [StarModule R A] : StarModule R\u02e3 A :=\n  \u27e8fun u a => star_smul (u : R) a\u27e9\n\nend Units\n\ntheorem IsUnit.star [Monoid R] [StarSemigroup R] {a : R} : IsUnit a \u2192 IsUnit (star a)\n  | \u27e8u, hu\u27e9 => \u27e8Star.star u, hu \u25b8 rfl\u27e9\n#align is_unit.star IsUnit.star\n\n@[simp]\ntheorem isUnit_star [Monoid R] [StarSemigroup R] {a : R} : IsUnit (star a) \u2194 IsUnit a :=\n  \u27e8fun h => star_star a \u25b8 h.star, IsUnit.star\u27e9\n#align is_unit_star isUnit_star\n\ntheorem Ring.inverse_star [Semiring R] [StarRing R] (a : R) :\n    Ring.inverse (star a) = star (Ring.inverse a) := by\n  by_cases ha : IsUnit a\n  \u00b7 obtain \u27e8u, rfl\u27e9 := ha\n    rw [Ring.inverse_unit, \u2190 Units.coe_star, Ring.inverse_unit, \u2190 Units.coe_star_inv]\n  rw [Ring.inverse_non_unit _ ha, Ring.inverse_non_unit _ (mt isUnit_star.mp ha), star_zero]\n#align ring.inverse_star Ring.inverse_star\n\ninstance Invertible.star {R : Type _} [Monoid R] [StarSemigroup R] (r : R) [Invertible r] :\n    Invertible (star r) where\n  invOf := Star.star (\u215f r)\n  invOf_mul_self := by rw [\u2190 star_mul, mul_invOf_self, star_one]\n  mul_invOf_self := by rw [\u2190 star_mul, invOf_mul_self, star_one]\n#align invertible.star Invertible.star\n\ntheorem star_invOf {R : Type _} [Monoid R] [StarSemigroup R] (r : R) [Invertible r]\n    [Invertible (star r)] : star (\u215f r) = \u215f (star r) := by\n  have : star (\u215f r) = star (\u215f r) * ((star r) * \u215f (star r)) := by\n    simp only [mul_invOf_self, mul_one]\n  rw [this, \u2190 mul_assoc]\n  have : (star (\u215f r)) * (star r) = star 1 := by rw [\u2190 star_mul, mul_invOf_self]\n  rw [this, star_one, one_mul]\n#align star_inv_of star_invOf\n\nnamespace MulOpposite\n\n/-- The opposite type carries the same star operation. -/\ninstance [Star R] : Star R\u1d50\u1d52\u1d56 where star r := op (star r.unop)\n\n@[simp]\ntheorem unop_star [Star R] (r : R\u1d50\u1d52\u1d56) : unop (star r) = star (unop r) :=\n  rfl\n#align mul_opposite.unop_star MulOpposite.unop_star\n\n@[simp]\ntheorem op_star [Star R] (r : R) : op (star r) = star (op r) :=\n  rfl\n#align mul_opposite.op_star MulOpposite.op_star\n\ninstance [InvolutiveStar R] : InvolutiveStar R\u1d50\u1d52\u1d56\n    where star_involutive r := unop_injective (star_star r.unop)\n\ninstance [Monoid R] [StarSemigroup R] : StarSemigroup R\u1d50\u1d52\u1d56\n    where star_mul x y := unop_injective (star_mul y.unop x.unop)\n\ninstance [AddMonoid R] [StarAddMonoid R] : StarAddMonoid R\u1d50\u1d52\u1d56\n    where star_add x y := unop_injective (star_add x.unop y.unop)\n\ninstance [Semiring R] [StarRing R] : StarRing R\u1d50\u1d52\u1d56\n  where star_add x y := unop_injective (star_add x.unop y.unop)\n\nend MulOpposite\n\n/-- A commutative star monoid is a star module over its opposite via\n`Monoid.toOppositeMulAction`. -/\ninstance StarSemigroup.toOpposite_starModule [CommMonoid R] [StarSemigroup R] :\n    StarModule R\u1d50\u1d52\u1d56 R :=\n  \u27e8fun r s => star_mul' s r.unop\u27e9\n#align star_semigroup.to_opposite_star_module StarSemigroup.toOpposite_starModule\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Star/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7098068904736698}}
{"text": "import data.int.basic\n\nnamespace int\n\ndef dvd (m n : \u2124) : Prop := \u2203 k, n = m * k\ninstance : has_dvd int  := \u27e8int.dvd\u27e9\n\n@[simp]\ntheorem dvd_zero (n : \u2124) : dvd n 0 :=\n\u27e80, by simp\u27e9\n\ntheorem dvd_intro {m n : \u2124} (k : \u2124) (h : n = m * k) : dvd m n :=\n\u27e8k, h\u27e9\n\nend int\n\nopen int\n\nsection mod_m\nparameter (m : \u2124)\nvariables (a b c : \u2124)\n\ndefinition mod_equiv := dvd m (b - a)\n\n#check mod_equiv\n#print mod_equiv\n\nlocal infix `\u2261`:50 := mod_equiv\n\ntheorem mod_refl : a \u2261 a :=\nshow dvd m (a - a), by simp\n\ntheorem mod_symm (h : a \u2261 b) : b \u2261 a :=\nby cases h with c hc; apply dvd_intro (-c); simp [eq.symm hc]\n\nlocal attribute [simp] add_assoc add_comm add_left_comm\n\ntheorem mod_trans (h\u2081 : a \u2261 b) (h\u2082 : b \u2261 c) : a \u2261 c :=\nbegin\n  cases h\u2081 with d hd,\n  cases h\u2082 with e he,\n  apply dvd_intro (d + e),\n  simp [mul_add, eq.symm hd, eq.symm he, sub_eq_add_neg]\nend\n\nend mod_m\n\n#check (mod_refl : \u2200 (m a : \u2124), mod_equiv m a a)\n\n#check (mod_symm : \u2200 (m a b : \u2124), mod_equiv m a b \u2192 mod_equiv m b a)\n\n#check (mod_trans : \u2200 (m a b c : \u2124), mod_equiv m a b \u2192 mod_equiv m b c \u2192 mod_equiv m a c)\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/06-Interacting-with-Lean/example-6.6-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.709806879204829}}
{"text": "/-\nCopyright (c) 2019 Rohan Mitta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport analysis.specific_limits.basic\nimport data.setoid.basic\nimport dynamics.fixed_points.topology\n\n/-!\n# Contracting maps\n\nA Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*.\nIn this file we prove the Banach fixed point theorem, some explicit estimates on the rate\nof convergence, and some properties of the map sending a contracting map to its fixed point.\n\n## Main definitions\n\n* `contracting_with K f` : a Lipschitz continuous self-map with `K < 1`;\n* `efixed_point` : given a contracting map `f` on a complete emetric space and a point `x`\n  such that `edist x (f x) \u2260 \u221e`, `efixed_point f hf x hx` is the unique fixed point of `f`\n  in `emetric.ball x \u221e`;\n* `fixed_point` : the unique fixed point of a contracting map on a complete nonempty metric space.\n\n## Tags\n\ncontracting map, fixed point, Banach fixed point theorem\n-/\n\nopen_locale nnreal topology classical ennreal\nopen filter function\n\nvariables {\u03b1 : Type*}\n\n/-- A map is said to be `contracting_with K`, if `K < 1` and `f` is `lipschitz_with K`. -/\ndef contracting_with [emetric_space \u03b1] (K : \u211d\u22650) (f : \u03b1 \u2192 \u03b1) :=\n(K < 1) \u2227 lipschitz_with K f\n\nnamespace contracting_with\n\nvariables [emetric_space \u03b1] [cs : complete_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1}\n\nopen emetric set\n\nlemma to_lipschitz_with (hf : contracting_with K f) : lipschitz_with K f := hf.2\n\nlemma one_sub_K_pos' (hf : contracting_with K f) : (0:\u211d\u22650\u221e) < 1 - K := by simp [hf.1]\n\nlemma one_sub_K_ne_zero (hf : contracting_with K f) : (1:\u211d\u22650\u221e) - K \u2260 0 :=\nne_of_gt hf.one_sub_K_pos'\n\nlemma one_sub_K_ne_top : (1:\u211d\u22650\u221e) - K \u2260 \u221e :=\nby { norm_cast, exact ennreal.coe_ne_top }\n\nlemma edist_inequality (hf : contracting_with K f) {x y} (h : edist x y \u2260 \u221e) :\n  edist x y \u2264 (edist x (f x) + edist y (f y)) / (1 - K) :=\nsuffices edist x y \u2264 edist x (f x) + edist y (f y) + K * edist x y,\n  by rwa [ennreal.le_div_iff_mul_le (or.inl hf.one_sub_K_ne_zero) (or.inl one_sub_K_ne_top),\n    mul_comm, ennreal.sub_mul (\u03bb _ _, h), one_mul, tsub_le_iff_right],\ncalc edist x y \u2264 edist x (f x) + edist (f x) (f y) + edist (f y) y : edist_triangle4 _ _ _ _\n  ... = edist x (f x) + edist y (f y) + edist (f x) (f y) : by rw [edist_comm y, add_right_comm]\n  ... \u2264 edist x (f x) + edist y (f y) + K * edist x y : add_le_add le_rfl (hf.2 _ _)\n\nlemma edist_le_of_fixed_point (hf : contracting_with K f) {x y}\n  (h : edist x y \u2260 \u221e) (hy : is_fixed_pt f y) :\n  edist x y \u2264 (edist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h\n\nlemma eq_or_edist_eq_top_of_fixed_points (hf : contracting_with K f) {x y}\n  (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) :\n  x = y \u2228 edist x y = \u221e :=\nbegin\n  refine or_iff_not_imp_right.2 (\u03bb h, edist_le_zero.1 _),\n  simpa only [hx.eq, edist_self, add_zero, ennreal.zero_div]\n    using hf.edist_le_of_fixed_point h hy\nend\n\n/-- If a map `f` is `contracting_with K`, and `s` is a forward-invariant set, then\nrestriction of `f` to `s` is `contracting_with K` as well. -/\nlemma restrict (hf : contracting_with K f) {s : set \u03b1} (hs : maps_to f s s) :\n  contracting_with K (hs.restrict f s s) :=\n\u27e8hf.1, \u03bb x y, hf.2 x y\u27e9\n\ninclude cs\n\n/-- Banach fixed-point theorem, contraction mapping theorem, `emetric_space` version.\nA contracting map on a complete metric space has a fixed point.\nWe include more conclusions in this theorem to avoid proving them again later.\n\nThe main API for this theorem are the functions `efixed_point` and `fixed_point`,\nand lemmas about these functions. -/\ntheorem exists_fixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) \u2260 \u221e) :\n  \u2203 y, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nhave cauchy_seq (\u03bb n, f^[n] x),\nfrom cauchy_seq_of_edist_le_geometric K (edist x (f x)) (ennreal.coe_lt_one_iff.2 hf.1)\n  hx (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x),\nlet \u27e8y, hy\u27e9 := cauchy_seq_tendsto_of_complete this in\n\u27e8y, is_fixed_pt_of_tendsto_iterate hy hf.2.continuous.continuous_at, hy,\n  edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x))\n    (hf.to_lipschitz_with.edist_iterate_succ_le_geometric x) hy\u27e9\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map,\nand `edist x (f x) \u2260 \u221e`. Then `efixed_point` is the unique fixed point of `f`\nin `emetric.ball x \u221e`. -/\nnoncomputable def efixed_point (hf : contracting_with K f) (x : \u03b1) (hx : edist x (f x) \u2260 \u221e) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point x hx\n\nvariables {f}\n\nlemma efixed_point_is_fixed_pt (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  is_fixed_pt f (efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).1\n\nlemma tendsto_iterate_efixed_point (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point f hf x hx) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.1\n\nlemma apriori_edist_iterate_efixed_point_le (hf : contracting_with K f)\n  {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) (n : \u2115) :\n  edist (f^[n] x) (efixed_point f hf x hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point x hx).2.2 n\n\nlemma edist_efixed_point_le (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point f hf x hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le hx 0, simp only [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point f hf x hx) < \u221e :=\n(hf.edist_efixed_point_le hx).trans_lt (ennreal.mul_lt_top hx $\n  ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\nlemma efixed_point_eq_of_edist_lt_top (hf : contracting_with K f) {x : \u03b1} (hx : edist x (f x) \u2260 \u221e)\n  {y : \u03b1} (hy : edist y (f y) \u2260 \u221e) (h : edist x y \u2260 \u221e) :\n  efixed_point f hf x hx = efixed_point f hf y hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, exact hf.edist_efixed_point_lt_top hx },\n  transitivity y,\n  exacts [lt_top_iff_ne_top.2 h, hf.edist_efixed_point_lt_top hy]\nend\n\nomit cs\n\n/-- Banach fixed-point theorem for maps contracting on a complete subset. -/\ntheorem exists_fixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  \u2203 y \u2208 s, is_fixed_pt f y \u2227 tendsto (\u03bb n, f^[n] x) at_top (\ud835\udcdd y) \u2227\n    \u2200 n:\u2115, edist (f^[n] x) y \u2264 (edist x (f x)) * K^n / (1 - K) :=\nbegin\n  haveI := hsc.complete_space_coe,\n  rcases hf.exists_fixed_point \u27e8x, hxs\u27e9 hx with \u27e8y, hfy, h_tendsto, hle\u27e9,\n  refine \u27e8y, y.2, subtype.ext_iff_val.1 hfy, _, \u03bb n, _\u27e9,\n  { convert (continuous_subtype_coe.tendsto _).comp h_tendsto, ext n,\n    simp only [(\u2218), maps_to.iterate_restrict, maps_to.coe_restrict_apply, subtype.coe_mk] },\n  { convert hle n,\n    rw [maps_to.iterate_restrict, eq_comm, maps_to.coe_restrict_apply, subtype.coe_mk] }\nend\n\nvariable (f) -- avoid `efixed_point _` in pretty printer\n\n/-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s`\nand `x \u2208 s` satisfies `edist x (f x) \u2260 \u221e`, then `efixed_point'` is the unique fixed point\nof the restriction of `f` to `s \u2229 emetric.ball x \u221e`. -/\nnoncomputable def efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) (x : \u03b1) (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  \u03b1 :=\nclassical.some $ hf.exists_fixed_point' hsc hsf hxs hx\n\nvariables {f}\n\nlemma efixed_point_mem' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  efixed_point' f hsc hsf hf x hxs hx \u2208 s :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).fst\n\nlemma efixed_point_is_fixed_pt' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  is_fixed_pt f (efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.1\n\nlemma tendsto_iterate_efixed_point' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ efixed_point' f hsc hsf hf x hxs hx) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.1\n\nlemma apriori_edist_iterate_efixed_point_le' {s : set \u03b1} (hsc : is_complete s)\n  (hsf : maps_to f s s) (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s)\n  (hx : edist x (f x) \u2260 \u221e) (n : \u2115) :\n  edist (f^[n] x) (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) * K^n / (1 - K) :=\n(classical.some_spec $ hf.exists_fixed_point' hsc hsf hxs hx).snd.2.2 n\n\nlemma edist_efixed_point_le' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) \u2264 (edist x (f x)) / (1 - K) :=\nby { convert hf.apriori_edist_iterate_efixed_point_le' hsc hsf hxs hx 0,\n  rw [pow_zero, mul_one] }\n\nlemma edist_efixed_point_lt_top' {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hf : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e) :\n  edist x (efixed_point' f hsc hsf hf x hxs hx) < \u221e :=\n(hf.edist_efixed_point_le' hsc hsf hxs hx).trans_lt (ennreal.mul_lt_top hx $\n  ennreal.inv_ne_top.2 hf.one_sub_K_ne_zero)\n\n/-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`,\nand `x \u2208 s` is at a finite distance from `y \u2208 t`, then the `efixed_point'` constructed by `x`\nis the same as the `efixed_point'` constructed by `y`.\n\nThis lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way\nit can be used to prove the desired equality with non-trivial proofs of these facts. -/\nlemma efixed_point_eq_of_edist_lt_top' (hf : contracting_with K f)\n  {s : set \u03b1} (hsc : is_complete s) (hsf : maps_to f s s)\n  (hfs : contracting_with K $ hsf.restrict f s s) {x : \u03b1} (hxs : x \u2208 s) (hx : edist x (f x) \u2260 \u221e)\n  {t : set \u03b1} (htc : is_complete t) (htf : maps_to f t t)\n  (hft : contracting_with K $ htf.restrict f t t) {y : \u03b1} (hyt : y \u2208 t) (hy : edist y (f y) \u2260 \u221e)\n  (hxy : edist x y \u2260 \u221e) :\n  efixed_point' f hsc hsf hfs x hxs hx = efixed_point' f htc htf hft y hyt hy :=\nbegin\n  refine (hf.eq_or_edist_eq_top_of_fixed_points _ _).elim id (\u03bb h', false.elim (ne_of_lt _ h'));\n    try { apply efixed_point_is_fixed_pt' },\n  change edist_lt_top_setoid.rel _ _,\n  transitivity x, by { symmetry, apply edist_efixed_point_lt_top' },\n  transitivity y,\n  exact lt_top_iff_ne_top.2 hxy,\n  apply edist_efixed_point_lt_top'\nend\n\nend contracting_with\n\nnamespace contracting_with\n\nvariables [metric_space \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b1} (hf : contracting_with K f)\ninclude hf\n\nlemma one_sub_K_pos (hf : contracting_with K f) : (0:\u211d) < 1 - K := sub_pos.2 hf.1\n\nlemma dist_le_mul (x y : \u03b1) : dist (f x) (f y) \u2264 K * dist x y :=\nhf.to_lipschitz_with.dist_le_mul x y\n\nlemma dist_inequality (x y) : dist x y \u2264 (dist x (f x) + dist y (f y)) / (1 - K) :=\nsuffices dist x y \u2264 dist x (f x) + dist y (f y) + K * dist x y,\n  by rwa [le_div_iff hf.one_sub_K_pos, mul_comm, sub_mul, one_mul, sub_le_iff_le_add],\ncalc dist x y \u2264 dist x (f x) + dist y (f y) + dist (f x) (f y) : dist_triangle4_right _ _ _ _\n          ... \u2264 dist x (f x) + dist y (f y) + K * dist x y :\n  add_le_add_left (hf.dist_le_mul _ _) _\n\nlemma dist_le_of_fixed_point (x) {y} (hy : is_fixed_pt f y) :\n  dist x y \u2264 (dist x (f x)) / (1 - K) :=\nby simpa only [hy.eq, dist_self, add_zero] using hf.dist_inequality x y\n\ntheorem fixed_point_unique' {x y} (hx : is_fixed_pt f x) (hy : is_fixed_pt f y) : x = y :=\n(hf.eq_or_edist_eq_top_of_fixed_points hx hy).resolve_right (edist_ne_top _ _)\n\n/-- Let `f` be a contracting map with constant `K`; let `g` be another map uniformly\n`C`-close to `f`. If `x` and `y` are their fixed points, then `dist x y \u2264 C / (1 - K)`. -/\n\n\nnoncomputable theory\n\nvariables [nonempty \u03b1] [complete_space \u03b1]\n\nvariable (f)\n/-- The unique fixed point of a contracting map in a nonempty complete metric space. -/\ndef fixed_point : \u03b1 :=\nefixed_point f hf _ (edist_ne_top (classical.choice \u2039nonempty \u03b1\u203a) _)\nvariable {f}\n\n/-- The point provided by `contracting_with.fixed_point` is actually a fixed point. -/\nlemma fixed_point_is_fixed_pt : is_fixed_pt f (fixed_point f hf) :=\nhf.efixed_point_is_fixed_pt _\n\nlemma fixed_point_unique {x} (hx : is_fixed_pt f x) : x = fixed_point f hf :=\nhf.fixed_point_unique' hx hf.fixed_point_is_fixed_pt\n\nlemma dist_fixed_point_le (x) : dist x (fixed_point f hf) \u2264 (dist x (f x)) / (1 - K) :=\nhf.dist_le_of_fixed_point x hf.fixed_point_is_fixed_pt\n\n/-- Aposteriori estimates on the convergence of iterates to the fixed point. -/\nlemma aposteriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist (f^[n] x) (f^[n+1] x)) / (1 - K) :=\nby { rw [iterate_succ'], apply hf.dist_fixed_point_le }\n\nlemma apriori_dist_iterate_fixed_point_le (x n) :\n  dist (f^[n] x) (fixed_point f hf) \u2264 (dist x (f x)) * K^n / (1 - K) :=\nle_trans (hf.aposteriori_dist_iterate_fixed_point_le x n) $\n  (div_le_div_right hf.one_sub_K_pos).2 $\n    hf.to_lipschitz_with.dist_iterate_succ_le_geometric x n\n\nlemma tendsto_iterate_fixed_point (x) :\n  tendsto (\u03bbn, f^[n] x) at_top (\ud835\udcdd $ fixed_point f hf) :=\nbegin\n  convert tendsto_iterate_efixed_point hf (edist_ne_top x _),\n  refine (fixed_point_unique _ _).symm,\n  apply efixed_point_is_fixed_pt\nend\n\nlemma fixed_point_lipschitz_in_map {g : \u03b1 \u2192 \u03b1} (hg : contracting_with K g)\n  {C} (hfg : \u2200 z, dist (f z) (g z) \u2264 C) :\n  dist (fixed_point f hf) (fixed_point g hg) \u2264 C / (1 - K) :=\nhf.dist_fixed_point_fixed_point_of_dist_le' g hf.fixed_point_is_fixed_pt\n  hg.fixed_point_is_fixed_pt hfg\n\nomit hf\n\n/-- If a map `f` has a contracting iterate `f^[n]`, then the fixed point of `f^[n]` is also a fixed\npoint of `f`. -/\nlemma is_fixed_pt_fixed_point_iterate {n : \u2115} (hf : contracting_with K (f^[n])) :\n  is_fixed_pt f (hf.fixed_point (f^[n])) :=\nbegin\n  set x := hf.fixed_point (f^[n]),\n  have hx : (f^[n] x) = x := hf.fixed_point_is_fixed_pt,\n  have := hf.to_lipschitz_with.dist_le_mul x (f x),\n  rw [\u2190 iterate_succ_apply, iterate_succ_apply', hx] at this,\n  contrapose! this,\n  have := dist_pos.2 (ne.symm this),\n  simpa only [nnreal.coe_one, one_mul, nnreal.val_eq_coe] using (mul_lt_mul_right this).mpr hf.left\nend\n\nend contracting_with\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/metric_space/contracting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7097391885130204}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport measure_theory.prod\nimport measure_theory.group\n\n/-!\n# Measure theory in the product of groups\n\nIn this file we show properties about measure theory in products of topological groups\nand properties of iterated integrals in topological groups.\n\nThese lemmas show the uniqueness of left invariant measures on locally compact groups, up to\nscaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos.\n\nThe idea of the proof is to use the translation invariance of measures to prove `\u03bc(F) = c * \u03bc(E)`\nfor two sets `E` and `F`, where `c` is a constant that does not depend on `\u03bc`. Let `e` and `f` be\nthe characteristic functions of `E` and `F`.\nAssume that `\u03bc` and `\u03bd` are left-invariant measures. Then the map `(x, y) \u21a6 (y * x, x\u207b\u00b9)`\npreserves the measure `\u03bc.prod \u03bd`, which means that\n```\n  \u222b x, \u222b y, h x y \u2202\u03bd \u2202\u03bc = \u222b x, \u222b y, h (y * x) x\u207b\u00b9 \u2202\u03bd \u2202\u03bc\n```\nIf we apply this to `h x y := e x * f y\u207b\u00b9 / \u03bd ((\u03bb h, h * y\u207b\u00b9) \u207b\u00b9' E)`, we can rewrite the RHS to\n`\u03bc(F)`, and the LHS to `c * \u03bc(E)`, where `c = c(\u03bd)` does not depend on `\u03bc`.\nApplying this to `\u03bc` and to `\u03bd` gives `\u03bc (F) / \u03bc (E) = \u03bd (F) / \u03bd (E)`, which is the uniqueness up to\nscalar multiplication.\n\nThe proof in [Halmos] seems to contain an omission in \u00a760 Th. A, see\n`measure_theory.measure_lintegral_div_measure` and\nhttps://math.stackexchange.com/questions/3974485/does-right-translation-preserve-finiteness-for-a-left-invariant-measure\n-/\n\nnoncomputable theory\nopen topological_space set (hiding prod_eq) function\nopen_locale classical ennreal\n\nnamespace measure_theory\n\nopen measure\n\nvariables {G : Type*} [topological_space G] [measurable_space G] [second_countable_topology G]\n  [borel_space G] [group G] [topological_group G]\nvariables {\u03bc \u03bd : measure G} [sigma_finite \u03bd] [sigma_finite \u03bc]\n\n/-- This condition is part of the definition of a measurable group in [Halmos, \u00a759].\n  There, the map in this lemma is called `S`. -/\nlemma map_prod_mul_eq (h\u03bd : is_mul_left_invariant \u03bd) :\n  map (\u03bb z : G \u00d7 G, (z.1, z.1 * z.2)) (\u03bc.prod \u03bd) = \u03bc.prod \u03bd :=\nbegin\n  refine (prod_eq _).symm, intros s t hs ht,\n  simp_rw [map_apply (measurable_fst.prod_mk (measurable_fst.mul measurable_snd)) (hs.prod ht),\n    prod_apply ((measurable_fst.prod_mk (measurable_fst.mul measurable_snd)) (hs.prod ht)),\n    preimage_preimage],\n  conv_lhs { congr, skip, funext, rw [mk_preimage_prod_right_fn_eq_if ((*) x), measure_if] },\n  simp_rw [h\u03bd _ ht, lintegral_indicator _ hs, set_lintegral_const, mul_comm]\nend\n\n/-- The function we are mapping along is `SR` in [Halmos, \u00a759],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\nlemma map_prod_mul_eq_swap (h\u03bc : is_mul_left_invariant \u03bc) :\n  map (\u03bb z : G \u00d7 G, (z.2, z.2 * z.1)) (\u03bc.prod \u03bd) = \u03bd.prod \u03bc :=\nbegin\n  rw [\u2190 prod_swap],\n  simp_rw [map_map (measurable_snd.prod_mk (measurable_snd.mul measurable_fst)) measurable_swap],\n  exact map_prod_mul_eq h\u03bc\nend\n\n/-- The function we are mapping along is `S\u207b\u00b9` in [Halmos, \u00a759],\n  where `S` is the map in `map_prod_mul_eq`. -/\nlemma map_prod_inv_mul_eq (h\u03bd : is_mul_left_invariant \u03bd) :\n  map (\u03bb z : G \u00d7 G, (z.1, z.1\u207b\u00b9 * z.2)) (\u03bc.prod \u03bd) = \u03bc.prod \u03bd :=\n(homeomorph.shear_mul_right G).to_measurable_equiv.map_apply_eq_iff_map_symm_apply_eq.mp $\n  map_prod_mul_eq h\u03bd\n\n/-- The function we are mapping along is `S\u207b\u00b9R` in [Halmos, \u00a759],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\nlemma map_prod_inv_mul_eq_swap (h\u03bc : is_mul_left_invariant \u03bc) :\n  map (\u03bb z : G \u00d7 G, (z.2, z.2\u207b\u00b9 * z.1)) (\u03bc.prod \u03bd) = \u03bd.prod \u03bc :=\nbegin\n  rw [\u2190 prod_swap],\n  simp_rw\n    [map_map (measurable_snd.prod_mk $ measurable_snd.inv.mul measurable_fst) measurable_swap],\n  exact map_prod_inv_mul_eq h\u03bc\nend\n\n/-- The function we are mapping along is `S\u207b\u00b9RSR` in [Halmos, \u00a759],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\nlemma map_prod_mul_inv_eq (h\u03bc : is_mul_left_invariant \u03bc) (h\u03bd : is_mul_left_invariant \u03bd) :\n  map (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) (\u03bc.prod \u03bd) = \u03bc.prod \u03bd :=\nbegin\n  let S := (homeomorph.shear_mul_right G).to_measurable_equiv,\n  suffices : map ((\u03bb z : G \u00d7 G, (z.2, z.2\u207b\u00b9 * z.1)) \u2218 (\u03bb z : G \u00d7 G, (z.2, z.2 * z.1))) (\u03bc.prod \u03bd) =\n    \u03bc.prod \u03bd,\n  { convert this, ext1 \u27e8x, y\u27e9, simp },\n  simp_rw [\u2190 map_map (measurable_snd.prod_mk (measurable_snd.inv.mul measurable_fst))\n    (measurable_snd.prod_mk (measurable_snd.mul measurable_fst)), map_prod_mul_eq_swap h\u03bc,\n    map_prod_inv_mul_eq_swap h\u03bd]\nend\n\nlemma measure_null_of_measure_inv_null (h\u03bc : is_mul_left_invariant \u03bc)\n  {E : set G} (hE : measurable_set E) (h2E : \u03bc ((\u03bb x, x\u207b\u00b9) \u207b\u00b9' E) = 0) : \u03bc E = 0 :=\nbegin\n  have hf : measurable (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) :=\n  (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  suffices : map (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) (\u03bc.prod \u03bc) (E.prod E) = 0,\n  { simpa only [map_prod_mul_inv_eq h\u03bc h\u03bc, prod_prod hE hE, mul_eq_zero, or_self] using this },\n  simp_rw [map_apply hf (hE.prod hE), prod_apply_symm (hf (hE.prod hE)), preimage_preimage,\n    mk_preimage_prod],\n  convert lintegral_zero, ext1 x, refine measure_mono_null (inter_subset_right _ _) h2E\nend\n\nlemma measure_inv_null (h\u03bc : is_mul_left_invariant \u03bc) {E : set G} (hE : measurable_set E) :\n  \u03bc ((\u03bb x, x\u207b\u00b9) \u207b\u00b9' E) = 0 \u2194 \u03bc E = 0 :=\nbegin\n  refine \u27e8measure_null_of_measure_inv_null h\u03bc hE, _\u27e9,\n  intro h2E,\n  apply measure_null_of_measure_inv_null h\u03bc (measurable_inv hE),\n  convert h2E using 2,\n  exact set.inv_inv\nend\n\nlemma measurable_measure_mul_right {E : set G} (hE : measurable_set E) :\n  measurable (\u03bb x, \u03bc ((\u03bb y, y * x) \u207b\u00b9' E)) :=\nbegin\n  suffices :\n    measurable (\u03bb y, \u03bc ((\u03bb x, (x, y)) \u207b\u00b9' ((\u03bb z : G \u00d7 G, (1, z.1 * z.2)) \u207b\u00b9' set.prod univ E))),\n  { convert this, ext1 x, congr' 1 with y : 1, simp },\n  apply measurable_measure_prod_mk_right,\n  exact measurable_const.prod_mk (measurable_fst.mul measurable_snd) (measurable_set.univ.prod hE)\nend\n\nlemma lintegral_lintegral_mul_inv (h\u03bc : is_mul_left_invariant \u03bc) (h\u03bd : is_mul_left_invariant \u03bd)\n  (f : G \u2192 G \u2192 \u211d\u22650\u221e) (hf : ae_measurable (uncurry f) (\u03bc.prod \u03bd)) :\n  \u222b\u207b x, \u222b\u207b y, f (y * x) x\u207b\u00b9 \u2202\u03bd \u2202\u03bc = \u222b\u207b x, \u222b\u207b y, f x y \u2202\u03bd \u2202\u03bc :=\nbegin\n  have h : measurable (\u03bb z : G \u00d7 G, (z.2 * z.1, z.1\u207b\u00b9)) :=\n  (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  have h2f : ae_measurable (uncurry $ \u03bb x y, f (y * x) x\u207b\u00b9) (\u03bc.prod \u03bd),\n  { apply hf.comp_measurable' h (map_prod_mul_inv_eq h\u03bc h\u03bd).absolutely_continuous },\n  simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf],\n  conv_rhs { rw [\u2190 map_prod_mul_inv_eq h\u03bc h\u03bd] },\n  symmetry,\n  exact lintegral_map' (hf.mono' (map_prod_mul_inv_eq h\u03bc h\u03bd).absolutely_continuous) h,\nend\n\nlemma measure_mul_right_null (h\u03bc : is_mul_left_invariant \u03bc) {E : set G} (hE : measurable_set E)\n  (y : G) : \u03bc ((\u03bb x, x * y) \u207b\u00b9' E) = 0 \u2194 \u03bc E = 0 :=\nbegin\n  rw [\u2190 measure_inv_null h\u03bc hE, \u2190 h\u03bc y\u207b\u00b9 (measurable_inv hE),\n    \u2190 measure_inv_null h\u03bc (measurable_mul_const y hE)],\n  convert iff.rfl using 3, ext x, simp,\nend\n\nlemma measure_mul_right_ne_zero (h\u03bc : is_mul_left_invariant \u03bc) {E : set G} (hE : measurable_set E)\n  (h2E : \u03bc E \u2260 0) (y : G) : \u03bc ((\u03bb x, x * y) \u207b\u00b9' E) \u2260 0 :=\n(not_iff_not_of_iff (measure_mul_right_null h\u03bc hE y)).mpr h2E\n\n/-- A technical lemma relating two different measures. This is basically [Halmos, \u00a760 Th. A].\n  Note that if `f` is the characteristic function of a measurable set `F` this states that\n  `\u03bc F = c * \u03bc E` for a constant `c` that does not depend on `\u03bc`.\n  There seems to be a gap in the last step of the proof in [Halmos].\n  In the last line, the equality `g(x\u207b\u00b9)\u03bd(Ex\u207b\u00b9) = f(x)` holds if we can prove that\n  `0 < \u03bd(Ex\u207b\u00b9) < \u221e`. The first inequality follows from \u00a759, Th. D, but I couldn't find the second\n  inequality. For this reason, we use a compact `E` instead of a measurable `E` as in [Halmos], and\n  additionally assume that `\u03bd` is a regular measure (we only need that it is finite on compact\n  sets). -/\nlemma measure_lintegral_div_measure [t2_space G] (h\u03bc : is_mul_left_invariant \u03bc)\n  (h\u03bd : is_mul_left_invariant \u03bd) (h2\u03bd : regular \u03bd) {E : set G} (hE : is_compact E) (h2E : \u03bd E \u2260 0)\n  (f : G \u2192 \u211d\u22650\u221e) (hf : measurable f) :\n  \u03bc E * \u222b\u207b y, f y\u207b\u00b9 / \u03bd ((\u03bb h, h * y\u207b\u00b9) \u207b\u00b9' E) \u2202\u03bd = \u222b\u207b x, f x \u2202\u03bc :=\nbegin\n  have Em := hE.measurable_set,\n  symmetry,\n  set g := \u03bb y, f y\u207b\u00b9 / \u03bd ((\u03bb h, h * y\u207b\u00b9) \u207b\u00b9' E),\n  have hg : measurable g := (hf.comp measurable_inv).div\n    ((measurable_measure_mul_right Em).comp measurable_inv),\n  rw [\u2190 set_lintegral_one, \u2190 lintegral_indicator _ Em,\n    \u2190 lintegral_lintegral_mul (measurable_const.indicator Em).ae_measurable hg.ae_measurable,\n    \u2190 lintegral_lintegral_mul_inv h\u03bc h\u03bd],\n  swap, { exact (((measurable_const.indicator Em).comp measurable_fst).mul\n      (hg.comp measurable_snd)).ae_measurable },\n  have mE : \u2200 x : G, measurable (\u03bb y, ((\u03bb z, z * x) \u207b\u00b9' E).indicator (\u03bb z, (1 : \u211d\u22650\u221e)) y) :=\n  \u03bb x, measurable_const.indicator (measurable_mul_const _ Em),\n  have : \u2200 x y, E.indicator (\u03bb (z : G), (1 : \u211d\u22650\u221e)) (y * x) =\n    ((\u03bb z, z * x) \u207b\u00b9' E).indicator (\u03bb (b : G), 1) y,\n  { intros x y, symmetry, convert indicator_comp_right (\u03bb y, y * x), ext1 z, simp },\n  have h3E : \u2200 y, \u03bd ((\u03bb x, x * y) \u207b\u00b9' E) \u2260 \u221e :=\n  \u03bb y, ennreal.lt_top_iff_ne_top.mp (h2\u03bd.lt_top_of_is_compact $\n    (homeomorph.mul_right _).compact_preimage.mpr hE),\n  simp_rw [this, lintegral_mul_const _ (mE _), lintegral_indicator _ (measurable_mul_const _ Em),\n    set_lintegral_one, g, inv_inv,\n    ennreal.mul_div_cancel' (measure_mul_right_ne_zero h\u03bd Em h2E _) (h3E _)]\nend\n\n/-- This is roughly the uniqueness (up to a scalar) of left invariant Borel measures on a second\n  countable locally compact group. The uniqueness of Haar measure is proven from this in\n  `measure_theory.measure.haar_measure_unique` -/\nlemma measure_mul_measure_eq [t2_space G] (h\u03bc : is_mul_left_invariant \u03bc)\n  (h\u03bd : is_mul_left_invariant \u03bd) (h2\u03bd : regular \u03bd) {E F : set G}\n  (hE : is_compact E) (hF : measurable_set F) (h2E : \u03bd E \u2260 0) : \u03bc E * \u03bd F = \u03bd E * \u03bc F :=\nbegin\n  have h1 := measure_lintegral_div_measure h\u03bd h\u03bd h2\u03bd hE h2E (F.indicator (\u03bb x, 1))\n    (measurable_const.indicator hF),\n  have h2 := measure_lintegral_div_measure h\u03bc h\u03bd h2\u03bd hE h2E (F.indicator (\u03bb x, 1))\n    (measurable_const.indicator hF),\n  rw [lintegral_indicator _ hF, set_lintegral_one] at h1 h2,\n  rw [\u2190 h1, mul_left_comm, h2],\nend\n\nend measure_theory\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/measure_theory/prod_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7097391728733782}}
{"text": "-- Reglas de la uni\u00f3n general\n-- ==========================\n\nimport data.set\n\nopen set\n\nvariables {I U : Type}\nvariables {A : I \u2192 set U}\nvariable  {x : U}\nvariable  (i : I)\n\n-- Regla de introducci\u00f3n de la uni\u00f3n\n-- =================================\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (h : x \u2208 A i) \n  : x \u2208 \u22c3 i, A i :=\nbegin\n  simp,\n  existsi i, \n  exact h\nend\n\n-- 2\u00aa demostraci\u00f3n\ntheorem Union.intro \n  (h : x \u2208 A i) \n  : x \u2208 \u22c3 i, A i :=\nby {simp, existsi i, exact h}\n\n-- Regla de eliminaci\u00f3n de la uni\u00f3n\n-- ================================\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  {b : Prop}\n  (h\u2081 : x \u2208 \u22c3 i, A i) \n  (h\u2082 : \u2200 (i : I), x \u2208 A i \u2192 b) \n  : b :=\nbegin\n  simp at h\u2081, \n  cases h\u2081 with i h,\n  exact h\u2082 i h,\nend\n\n-- 2\u00aa demostraci\u00f3n\ntheorem Union.elim \n  {b : Prop}\n  (h\u2081 : x \u2208 \u22c3 i, A i) \n  (h\u2082 : \u2200 (i : I), x \u2208 A i \u2192 b) \n  : b :=\nby {simp at h\u2081, cases h\u2081 with i h, exact h\u2082 i h}\n\n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/3_Conjuntos/Reglas_de_la_union_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7097391717023094}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Michael Howes\n-/\nimport data.finite.card\nimport group_theory.commutator\nimport group_theory.finiteness\n\n/-!\n# The abelianization of a group\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the commutator and the abelianization of a group. It furthermore prepares for the\nresult that the abelianization is left adjoint to the forgetful functor from abelian groups to\ngroups, which can be found in `algebra/category/Group/adjunctions`.\n\n## Main definitions\n\n* `commutator`: defines the commutator of a group `G` as a subgroup of `G`.\n* `abelianization`: defines the abelianization of a group `G` as the quotient of a group by its\n  commutator subgroup.\n* `abelianization.map`: lifts a group homomorphism to a homomorphism between the abelianizations\n* `mul_equiv.abelianization_congr`: Equivalent groups have equivalent abelianizations\n\n-/\n\nuniverses u v w\n\n-- Let G be a group.\nvariables (G : Type u) [group G]\n\n/-- The commutator subgroup of a group G is the normal subgroup\n  generated by the commutators [p,q]=`p*q*p\u207b\u00b9*q\u207b\u00b9`. -/\n@[derive subgroup.normal]\ndef commutator : subgroup G :=\n\u2045(\u22a4 : subgroup G), \u22a4\u2046\n\nlemma commutator_def : commutator G = \u2045(\u22a4 : subgroup G), \u22a4\u2046 := rfl\n\nlemma commutator_eq_closure : commutator G = subgroup.closure (commutator_set G) :=\nby simp [commutator, subgroup.commutator_def, commutator_set]\n\nlemma commutator_eq_normal_closure :\n  commutator G = subgroup.normal_closure (commutator_set G) :=\nby simp [commutator, subgroup.commutator_def', commutator_set]\n\ninstance commutator_characteristic : (commutator G).characteristic :=\nsubgroup.commutator_characteristic \u22a4 \u22a4\n\ninstance [finite (commutator_set G)] : group.fg (commutator G) :=\nbegin\n  rw commutator_eq_closure,\n  apply group.closure_finite_fg,\nend\n\nlemma rank_commutator_le_card [finite (commutator_set G)] :\n  group.rank (commutator G) \u2264 nat.card (commutator_set G) :=\nbegin\n  rw subgroup.rank_congr (commutator_eq_closure G),\n  apply subgroup.rank_closure_finite_le_nat_card,\nend\n\nlemma commutator_centralizer_commutator_le_center :\n  \u2045(commutator G).centralizer, (commutator G).centralizer\u2046 \u2264 subgroup.center G :=\nbegin\n  rw [\u2190subgroup.centralizer_top, \u2190subgroup.commutator_eq_bot_iff_le_centralizer],\n  suffices : \u2045\u2045\u22a4, (commutator G).centralizer\u2046, (commutator G).centralizer\u2046 = \u22a5,\n  { refine subgroup.commutator_commutator_eq_bot_of_rotate _ this,\n    rwa subgroup.commutator_comm (commutator G).centralizer },\n  rw [subgroup.commutator_comm, subgroup.commutator_eq_bot_iff_le_centralizer],\n  exact set.centralizer_subset (subgroup.commutator_mono le_top le_top),\nend\n\n/-- The abelianization of G is the quotient of G by its commutator subgroup. -/\ndef abelianization : Type u :=\nG \u29f8 (commutator G)\n\nnamespace abelianization\n\nlocal attribute [instance] quotient_group.left_rel\n\ninstance : comm_group (abelianization G) :=\n{ mul_comm := \u03bb x y, quotient.induction_on\u2082' x y $ \u03bb a b, quotient.sound' $\n    quotient_group.left_rel_apply.mpr $\n    subgroup.subset_closure \u27e8b\u207b\u00b9, subgroup.mem_top b\u207b\u00b9, a\u207b\u00b9, subgroup.mem_top a\u207b\u00b9, by group\u27e9,\n.. quotient_group.quotient.group _ }\n\ninstance : inhabited (abelianization G) := \u27e81\u27e9\n\ninstance [fintype G] [decidable_pred (\u2208 commutator G)] :\n  fintype (abelianization G) :=\nquotient_group.fintype (commutator G)\n\ninstance [finite G] : finite (abelianization G) :=\nquotient.finite _\n\nvariable {G}\n\n/-- `of` is the canonical projection from G to its abelianization. -/\ndef of : G \u2192* abelianization G :=\n{ to_fun := quotient_group.mk,\n  map_one' := rfl,\n  map_mul' := \u03bb x y, rfl }\n\n@[simp] lemma mk_eq_of (a : G) : quot.mk _ a = of a := rfl\n\nsection lift\n-- So far we have built G\u1d43\u1d47 and proved it's an abelian group.\n-- Furthremore we defined the canonical projection `of : G \u2192 G\u1d43\u1d47`\n\n-- Let `A` be an abelian group and let `f` be a group homomorphism from `G` to `A`.\nvariables {A : Type v} [comm_group A] (f : G \u2192* A)\n\nlemma commutator_subset_ker : commutator G \u2264 f.ker :=\nbegin\n  rw [commutator_eq_closure, subgroup.closure_le],\n  rintros x \u27e8p, q, rfl\u27e9,\n  simp [monoid_hom.mem_ker, mul_right_comm (f p) (f q), commutator_element_def],\nend\n\n/-- If `f : G \u2192 A` is a group homomorphism to an abelian group, then `lift f` is the unique map from\n  the abelianization of a `G` to `A` that factors through `f`. -/\ndef lift : (G \u2192* A) \u2243 (abelianization G \u2192* A) :=\n{ to_fun := \u03bb f, quotient_group.lift _ f (\u03bb x h, f.mem_ker.2 $ commutator_subset_ker _ h),\n  inv_fun := \u03bb F, F.comp of,\n  left_inv := \u03bb f, monoid_hom.ext $ \u03bb x, rfl,\n  right_inv := \u03bb F, monoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ \u03bb z, rfl }\n\n@[simp] lemma lift.of (x : G) : lift f (of x) = f x :=\nrfl\n\ntheorem lift.unique\n  (\u03c6 : abelianization G \u2192* A)\n  -- h\u03c6 : \u03c6 agrees with f on the image of G in G\u1d43\u1d47\n  (h\u03c6 : \u2200 (x : G), \u03c6 (of x) = f x)\n  {x : abelianization G} :\n  \u03c6 x = lift f x :=\nquotient_group.induction_on x h\u03c6\n\n@[simp] lemma lift_of : lift of = monoid_hom.id (abelianization G) :=\nlift.apply_symm_apply $ monoid_hom.id _\n\nend lift\n\nvariables {A : Type v} [monoid A]\n\n/-- See note [partially-applied ext lemmas]. -/\n@[ext]\ntheorem hom_ext (\u03c6 \u03c8 : abelianization G \u2192* A)\n  (h : \u03c6.comp of = \u03c8.comp of) : \u03c6 = \u03c8 :=\nmonoid_hom.ext $ \u03bb x, quotient_group.induction_on x $ monoid_hom.congr_fun h\n\nsection map\n\nvariables {H : Type v} [group H] (f : G \u2192* H)\n\n/-- The map operation of the `abelianization` functor -/\ndef map : abelianization G \u2192* abelianization H := lift (of.comp f)\n\n@[simp]\nlemma map_of (x : G) : map f (of x) = of (f x) := rfl\n\n@[simp]\nlemma map_id : map (monoid_hom.id G) = monoid_hom.id (abelianization G) := hom_ext _ _ rfl\n\n@[simp]\nlemma map_comp {I : Type w} [group I] (g : H \u2192* I) :\n  (map g).comp (map f) = map (g.comp f) := hom_ext _ _ rfl\n\n@[simp]\nlemma map_map_apply {I : Type w} [group I] {g : H \u2192* I} {x : abelianization G}:\n  map g (map f x) = map (g.comp f) x := monoid_hom.congr_fun (map_comp _ _) x\n\nend map\n\nend abelianization\n\nsection abelianization_congr\n\nvariables {G} {H : Type v} [group H] (e : G \u2243* H)\n\n/-- Equivalent groups have equivalent abelianizations -/\ndef mul_equiv.abelianization_congr : abelianization G \u2243* abelianization H :=\n{ to_fun := abelianization.map e.to_monoid_hom,\n  inv_fun := abelianization.map e.symm.to_monoid_hom,\n  left_inv := by { rintros \u27e8a\u27e9, simp },\n  right_inv := by { rintros \u27e8a\u27e9, simp },\n  map_mul' := monoid_hom.map_mul _ }\n\n@[simp]\nlemma abelianization_congr_of (x : G) :\n  (e.abelianization_congr) (abelianization.of x) = abelianization.of (e x) := rfl\n\n@[simp]\nlemma abelianization_congr_refl :\n  (mul_equiv.refl G).abelianization_congr = mul_equiv.refl (abelianization G) :=\nmul_equiv.to_monoid_hom_injective abelianization.lift_of\n\n@[simp]\nlemma abelianization_congr_symm  :\n  e.abelianization_congr.symm = e.symm.abelianization_congr := rfl\n\n@[simp]\nlemma abelianization_congr_trans {I : Type v} [group I] (e\u2082 : H \u2243* I) :\n  e.abelianization_congr.trans e\u2082.abelianization_congr = (e.trans e\u2082).abelianization_congr :=\nmul_equiv.to_monoid_hom_injective (abelianization.hom_ext _ _ rfl)\n\nend abelianization_congr\n\n/-- An Abelian group is equivalent to its own abelianization. -/\n@[simps] def abelianization.equiv_of_comm {H : Type*} [comm_group H] :\n  H \u2243* abelianization H :=\n{ to_fun    := abelianization.of,\n  inv_fun   := abelianization.lift (monoid_hom.id H),\n  left_inv  := \u03bb a, rfl,\n  right_inv := by { rintros \u27e8a\u27e9, refl, },\n  .. abelianization.of }\n\nsection commutator_representatives\n\nopen subgroup\n\n/-- Representatives `(g\u2081, g\u2082) : G \u00d7 G` of commutator_set `\u2045g\u2081, g\u2082\u2046 \u2208 G`. -/\ndef commutator_representatives : set (G \u00d7 G) :=\nset.range (\u03bb g : commutator_set G, (g.2.some, g.2.some_spec.some))\n\ninstance [finite (commutator_set G)] : finite (commutator_representatives G) :=\nset.finite_coe_iff.mpr (set.finite_range _)\n\n/-- Subgroup generated by representatives `g\u2081 g\u2082 : G` of commutators `\u2045g\u2081, g\u2082\u2046 \u2208 G`. -/\ndef closure_commutator_representatives : subgroup G :=\nclosure (prod.fst '' commutator_representatives G \u222a prod.snd '' commutator_representatives G)\n\ninstance closure_commutator_representatives_fg [finite (commutator_set G)] :\n  group.fg (closure_commutator_representatives G) :=\ngroup.closure_finite_fg _\n\nlemma rank_closure_commutator_representations_le [finite (commutator_set G)] :\n  group.rank (closure_commutator_representatives G) \u2264 2 * nat.card (commutator_set G) :=\nbegin\n  rw two_mul,\n  exact (subgroup.rank_closure_finite_le_nat_card _).trans ((set.card_union_le _ _).trans\n    (add_le_add ((finite.card_image_le _).trans (finite.card_range_le _))\n    ((finite.card_image_le _).trans (finite.card_range_le _ )))),\nend\n\nlemma image_commutator_set_closure_commutator_representatives :\n  (closure_commutator_representatives G).subtype ''\n    (commutator_set (closure_commutator_representatives G)) = commutator_set G :=\nbegin\n  apply set.subset.antisymm,\n  { rintros - \u27e8-, \u27e8g\u2081, g\u2082, rfl\u27e9, rfl\u27e9,\n    exact \u27e8g\u2081, g\u2082, rfl\u27e9 },\n  { exact \u03bb g hg, \u27e8_,\n      \u27e8\u27e8_, subset_closure (or.inl \u27e8_, \u27e8\u27e8g, hg\u27e9, rfl\u27e9, rfl\u27e9)\u27e9,\n       \u27e8_, subset_closure (or.inr \u27e8_, \u27e8\u27e8g, hg\u27e9, rfl\u27e9, rfl\u27e9)\u27e9,\n       rfl\u27e9,\n      hg.some_spec.some_spec\u27e9 },\nend\n\nlemma card_commutator_set_closure_commutator_representatives :\n  nat.card (commutator_set (closure_commutator_representatives G)) = nat.card (commutator_set G) :=\nbegin\n  rw \u2190 image_commutator_set_closure_commutator_representatives G,\n  exact nat.card_congr (equiv.set.image _ _ (subtype_injective _)),\nend\n\nlemma card_commutator_closure_commutator_representatives :\n  nat.card (commutator (closure_commutator_representatives G)) = nat.card (commutator G) :=\nbegin\n  rw [commutator_eq_closure G, \u2190image_commutator_set_closure_commutator_representatives,\n      \u2190monoid_hom.map_closure, \u2190commutator_eq_closure],\n  exact nat.card_congr (equiv.set.image _ _ (subtype_injective _)),\nend\n\ninstance [finite (commutator_set G)] :\n  finite (commutator_set (closure_commutator_representatives G)) :=\nbegin\n  apply nat.finite_of_card_ne_zero,\n  rw card_commutator_set_closure_commutator_representatives,\n  exact finite.card_pos.ne',\nend\n\nend commutator_representatives\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/abelianization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7097391717023094}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n-/\n\nimport algebra.big_operators.multiset.basic\nimport data.pnat.prime\nimport data.nat.factors\nimport data.multiset.sort\n\n/-!\n# Prime factors of nonzero naturals\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the factorization of a nonzero natural number `n` as a multiset of primes,\nthe multiplicity of `p` in this factors multiset being the p-adic valuation of `n`.\n\n## Main declarations\n\n* `prime_multiset`: Type of multisets of prime numbers.\n* `factor_multiset n`: Multiset of prime factors of `n`.\n-/\n\n/-- The type of multisets of prime numbers.  Unique factorization\n gives an equivalence between this set and \u2115+, as we will formalize\n below. -/\n@[derive [inhabited, canonically_ordered_add_monoid, distrib_lattice,\n  semilattice_sup, order_bot, has_sub, has_ordered_sub]]\ndef prime_multiset := multiset nat.primes\n\nnamespace prime_multiset\n\n-- `@[derive]` doesn't work for `meta` instances\nmeta instance : has_repr prime_multiset := by delta prime_multiset; apply_instance\n\n/-- The multiset consisting of a single prime -/\ndef of_prime (p : nat.primes) : prime_multiset := ({p} : multiset nat.primes)\n\ntheorem card_of_prime (p : nat.primes) : multiset.card (of_prime p) = 1 := rfl\n\n/-- We can forget the primality property and regard a multiset\n of primes as just a multiset of positive integers, or a multiset\n of natural numbers.  In the opposite direction, if we have a\n multiset of positive integers or natural numbers, together with\n a proof that all the elements are prime, then we can regard it\n as a multiset of primes.  The next block of results records\n obvious properties of these coercions.\n-/\ndef to_nat_multiset : prime_multiset \u2192 multiset \u2115 :=\n\u03bb v, v.map (\u03bb p, (p : \u2115))\n\ninstance coe_nat : has_coe prime_multiset (multiset \u2115) := \u27e8to_nat_multiset\u27e9\n\n/-- `prime_multiset.coe`, the coercion from a multiset of primes to a multiset of\nnaturals, promoted to an `add_monoid_hom`. -/\ndef coe_nat_monoid_hom : prime_multiset \u2192+ multiset \u2115 :=\n{ to_fun := coe,\n  .. multiset.map_add_monoid_hom coe }\n\n@[simp] lemma coe_coe_nat_monoid_hom :\n  (coe_nat_monoid_hom : prime_multiset \u2192 multiset \u2115) = coe := rfl\n\ntheorem coe_nat_injective : function.injective (coe : prime_multiset \u2192 multiset \u2115) :=\nmultiset.map_injective nat.primes.coe_nat_injective\n\ntheorem coe_nat_of_prime (p : nat.primes) :\n((of_prime p) : multiset \u2115) = {p} := rfl\n\ntheorem coe_nat_prime (v : prime_multiset)\n(p : \u2115) (h : p \u2208 (v : multiset \u2115)) : p.prime :=\nby { rcases multiset.mem_map.mp h with \u27e8\u27e8p', hp'\u27e9, \u27e8h_mem, h_eq\u27e9\u27e9,\n     exact h_eq \u25b8 hp' }\n\n/-- Converts a `prime_multiset` to a `multiset \u2115+`. -/\ndef to_pnat_multiset : prime_multiset \u2192 multiset \u2115+ :=\n\u03bb v, v.map (\u03bb p, (p : \u2115+))\n\ninstance coe_pnat : has_coe prime_multiset (multiset \u2115+) := \u27e8to_pnat_multiset\u27e9\n\n/-- `coe_pnat`, the coercion from a multiset of primes to a multiset of positive\nnaturals, regarded as an `add_monoid_hom`. -/\ndef coe_pnat_monoid_hom : prime_multiset \u2192+ multiset \u2115+ :=\n{ to_fun := coe,\n  .. multiset.map_add_monoid_hom coe }\n\n@[simp] lemma coe_coe_pnat_monoid_hom :\n  (coe_pnat_monoid_hom : prime_multiset \u2192 multiset \u2115+) = coe := rfl\n\ntheorem coe_pnat_injective : function.injective (coe : prime_multiset \u2192 multiset \u2115+) :=\nmultiset.map_injective nat.primes.coe_pnat_injective\n\ntheorem coe_pnat_of_prime (p : nat.primes) :\n  ((of_prime p) : multiset \u2115+) = {(p : \u2115+)} := rfl\n\ntheorem coe_pnat_prime (v : prime_multiset)\n  (p : \u2115+) (h : p \u2208 (v : multiset \u2115+)) : p.prime :=\nby { rcases multiset.mem_map.mp h with \u27e8\u27e8p', hp'\u27e9, \u27e8h_mem, h_eq\u27e9\u27e9,\n     exact h_eq \u25b8 hp' }\n\ninstance coe_multiset_pnat_nat : has_coe (multiset \u2115+) (multiset \u2115) :=\n\u27e8\u03bb v, v.map (\u03bb n, (n : \u2115))\u27e9\n\ntheorem coe_pnat_nat (v : prime_multiset) :\n  ((v : (multiset \u2115+)) : (multiset \u2115)) = (v : multiset \u2115) :=\nby { change (v.map (coe : nat.primes \u2192 \u2115+)).map subtype.val = v.map subtype.val,\n     rw [multiset.map_map], congr }\n\n/-- The product of a `prime_multiset`, as a `\u2115+`. -/\ndef prod (v : prime_multiset) : \u2115+ := (v : multiset pnat).prod\n\ntheorem coe_prod (v : prime_multiset) : (v.prod : \u2115) = (v : multiset \u2115).prod :=\nbegin\n  let h : (v.prod : \u2115) = ((v.map coe).map coe).prod :=\n    (pnat.coe_monoid_hom.map_multiset_prod v.to_pnat_multiset),\n  rw [multiset.map_map] at h,\n  have : (coe : \u2115+ \u2192 \u2115) \u2218 (coe : nat.primes \u2192 \u2115+) = coe := funext (\u03bb p, rfl),\n  rw[this] at h, exact h,\nend\n\ntheorem prod_of_prime (p : nat.primes) : (of_prime p).prod = (p : \u2115+) :=\nmultiset.prod_singleton _\n\n/-- If a `multiset \u2115` consists only of primes, it can be recast as a `prime_multiset`. -/\ndef of_nat_multiset\n  (v : multiset \u2115) (h : \u2200 (p : \u2115), p \u2208 v \u2192 p.prime) : prime_multiset :=\n@multiset.pmap \u2115 nat.primes nat.prime (\u03bb p hp, \u27e8p, hp\u27e9) v h\n\ntheorem to_of_nat_multiset (v : multiset \u2115) (h) :\n  ((of_nat_multiset v h) : multiset \u2115) = v :=\nbegin\n  unfold_coes,\n  dsimp [of_nat_multiset, to_nat_multiset],\n  have : (\u03bb (p : \u2115) (h : p.prime), ((\u27e8p, h\u27e9 : nat.primes) : \u2115)) = (\u03bb p h, id p) :=\n    by {funext p h, refl},\n  rw [multiset.map_pmap, this, multiset.pmap_eq_map, multiset.map_id]\nend\n\ntheorem prod_of_nat_multiset (v : multiset \u2115) (h) :\n  ((of_nat_multiset v h).prod : \u2115) = (v.prod : \u2115) :=\nby rw[coe_prod, to_of_nat_multiset]\n\n/-- If a `multiset \u2115+` consists only of primes, it can be recast as a `prime_multiset`. -/\ndef of_pnat_multiset\n  (v : multiset \u2115+) (h : \u2200 (p : \u2115+), p \u2208 v \u2192 p.prime) : prime_multiset :=\n@multiset.pmap \u2115+ nat.primes pnat.prime (\u03bb p hp, \u27e8(p : \u2115), hp\u27e9) v h\n\ntheorem to_of_pnat_multiset (v : multiset \u2115+) (h) :\n ((of_pnat_multiset v h) : multiset \u2115+) = v :=\nbegin\n  unfold_coes, dsimp[of_pnat_multiset, to_pnat_multiset],\n  have : (\u03bb (p : \u2115+) (h : p.prime), ((coe : nat.primes \u2192 \u2115+) \u27e8p, h\u27e9)) = (\u03bb p h, id p) :=\n    by {funext p h, apply subtype.eq, refl},\n  rw[multiset.map_pmap, this, multiset.pmap_eq_map, multiset.map_id]\nend\n\ntheorem prod_of_pnat_multiset (v : multiset \u2115+) (h) :\n ((of_pnat_multiset v h).prod : \u2115+) = v.prod :=\nby { dsimp [prod], rw [to_of_pnat_multiset] }\n\n/-- Lists can be coerced to multisets; here we have some results\nabout how this interacts with our constructions on multisets. -/\ndef of_nat_list (l : list \u2115) (h : \u2200 (p : \u2115), p \u2208 l \u2192 p.prime) : prime_multiset :=\nof_nat_multiset (l : multiset \u2115) h\n\ntheorem prod_of_nat_list (l : list \u2115) (h) : ((of_nat_list l h).prod : \u2115) = l.prod :=\nby { have := prod_of_nat_multiset (l : multiset \u2115) h,\n     rw [multiset.coe_prod] at this, exact this }\n\n/-- If a `list \u2115+` consists only of primes, it can be recast as a `prime_multiset` with\nthe coercion from lists to multisets. -/\ndef of_pnat_list (l : list \u2115+) (h : \u2200 (p : \u2115+), p \u2208 l \u2192 p.prime) : prime_multiset :=\nof_pnat_multiset (l : multiset \u2115+) h\n\ntheorem prod_of_pnat_list (l : list \u2115+) (h) : (of_pnat_list l h).prod = l.prod :=\nby { have := prod_of_pnat_multiset (l : multiset \u2115+) h,\n     rw [multiset.coe_prod] at this, exact this }\n\n/-- The product map gives a homomorphism from the additive monoid\nof multisets to the multiplicative monoid \u2115+. -/\ntheorem prod_zero : (0 : prime_multiset).prod = 1 :=\nby { dsimp [prod], exact multiset.prod_zero }\n\ntheorem prod_add (u v : prime_multiset) : (u + v).prod = u.prod * v.prod :=\nbegin\n  change (coe_pnat_monoid_hom (u + v)).prod = _,\n  rw coe_pnat_monoid_hom.map_add,\n  exact multiset.prod_add _ _,\nend\n\n\n\nend prime_multiset\n\nnamespace pnat\n\n/-- The prime factors of n, regarded as a multiset -/\ndef factor_multiset (n : \u2115+) : prime_multiset :=\nprime_multiset.of_nat_list (nat.factors n) (@nat.prime_of_mem_factors n)\n\n/-- The product of the factors is the original number -/\ntheorem prod_factor_multiset (n : \u2115+) : (factor_multiset n).prod = n :=\neq $ by { dsimp [factor_multiset],\n          rw [prime_multiset.prod_of_nat_list],\n          exact nat.prod_factors n.ne_zero }\n\ntheorem coe_nat_factor_multiset (n : \u2115+) :\n  ((factor_multiset n) : (multiset \u2115)) = ((nat.factors n) : multiset \u2115) :=\nprime_multiset.to_of_nat_multiset (nat.factors n) (@nat.prime_of_mem_factors n)\n\nend pnat\n\nnamespace prime_multiset\n\n/-- If we start with a multiset of primes, take the product and\n then factor it, we get back the original multiset. -/\ntheorem factor_multiset_prod (v : prime_multiset) :\n  v.prod.factor_multiset = v :=\nbegin\n  apply prime_multiset.coe_nat_injective,\n  rw [v.prod.coe_nat_factor_multiset, prime_multiset.coe_prod],\n  rcases v with \u27e8l\u27e9,\n  unfold_coes,\n  dsimp [prime_multiset.to_nat_multiset],\n  rw [multiset.coe_prod],\n  let l' := l.map (coe : nat.primes \u2192 \u2115),\n  have : \u2200 (p : \u2115), p \u2208 l' \u2192 p.prime :=\n    \u03bb p hp, by {rcases list.mem_map.mp hp with \u27e8\u27e8p', hp'\u27e9, \u27e8h_mem, h_eq\u27e9\u27e9,\n                exact h_eq \u25b8 hp'},\n  exact multiset.coe_eq_coe.mpr (@nat.factors_unique _ l' rfl this).symm,\nend\n\nend prime_multiset\n\nnamespace pnat\n\n/-- Positive integers biject with multisets of primes. -/\ndef factor_multiset_equiv : \u2115+ \u2243 prime_multiset :=\n{ to_fun    := factor_multiset,\n  inv_fun   := prime_multiset.prod,\n  left_inv  := prod_factor_multiset,\n  right_inv := prime_multiset.factor_multiset_prod }\n\n/-- Factoring gives a homomorphism from the multiplicative\n monoid \u2115+ to the additive monoid of multisets. -/\ntheorem factor_multiset_one : factor_multiset 1 = 0 :=\nby simp [factor_multiset, prime_multiset.of_nat_list, prime_multiset.of_nat_multiset]\n\ntheorem factor_multiset_mul (n m : \u2115+) :\n  factor_multiset (n * m) = (factor_multiset n) + (factor_multiset m) :=\nbegin\n  let u := factor_multiset n,\n  let v := factor_multiset m,\n  have : n = u.prod := (prod_factor_multiset n).symm, rw[this],\n  have : m = v.prod := (prod_factor_multiset m).symm, rw[this],\n  rw[\u2190 prime_multiset.prod_add],\n  repeat {rw[prime_multiset.factor_multiset_prod]},\nend\n\ntheorem factor_multiset_pow (n : \u2115+) (m : \u2115) :\n  factor_multiset (n ^ m) = m \u2022 (factor_multiset n) :=\nbegin\n  let u := factor_multiset n,\n  have : n = u.prod := (prod_factor_multiset n).symm,\n  rw[this, \u2190 prime_multiset.prod_smul],\n  repeat {rw[prime_multiset.factor_multiset_prod]},\nend\n\n/-- Factoring a prime gives the corresponding one-element multiset. -/\ntheorem factor_multiset_of_prime (p : nat.primes) :\n  (p : \u2115+).factor_multiset = prime_multiset.of_prime p :=\nbegin\n  apply factor_multiset_equiv.symm.injective,\n  change (p : \u2115+).factor_multiset.prod = (prime_multiset.of_prime p).prod,\n  rw[(p : \u2115+).prod_factor_multiset, prime_multiset.prod_of_prime],\nend\n\n/-- We now have four different results that all encode the\n idea that inequality of multisets corresponds to divisibility\n of positive integers. -/\ntheorem factor_multiset_le_iff {m n : \u2115+} :\n  factor_multiset m \u2264 factor_multiset n \u2194 m \u2223 n :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190 prod_factor_multiset m, \u2190 prod_factor_multiset m],\n    apply dvd.intro (n.factor_multiset - m.factor_multiset).prod,\n    rw [\u2190 prime_multiset.prod_add, prime_multiset.factor_multiset_prod,\n        add_tsub_cancel_of_le h, prod_factor_multiset] },\n  { intro  h,\n    rw [\u2190 mul_div_exact h, factor_multiset_mul],\n    exact le_self_add }\nend\n\ntheorem factor_multiset_le_iff' {m : \u2115+} {v : prime_multiset}:\n factor_multiset m \u2264 v \u2194 m \u2223 v.prod :=\nby { let h := @factor_multiset_le_iff m v.prod,\n     rw [v.factor_multiset_prod] at h, exact h }\n\nend pnat\n\nnamespace prime_multiset\n\ntheorem prod_dvd_iff {u v : prime_multiset} : u.prod \u2223 v.prod \u2194 u \u2264 v :=\nby { let h := @pnat.factor_multiset_le_iff' u.prod v,\n     rw [u.factor_multiset_prod] at h, exact h.symm }\n\ntheorem prod_dvd_iff' {u : prime_multiset} {n : \u2115+} : u.prod \u2223 n \u2194 u \u2264 n.factor_multiset :=\nby { let h := @prod_dvd_iff u n.factor_multiset,\n     rw [n.prod_factor_multiset] at h, exact h }\n\nend prime_multiset\n\nnamespace pnat\n\n/-- The gcd and lcm operations on positive integers correspond\n to the inf and sup operations on multisets. -/\ntheorem factor_multiset_gcd (m n : \u2115+) :\n factor_multiset (gcd m n) = (factor_multiset m) \u2293 (factor_multiset n) :=\nbegin\n  apply le_antisymm,\n  { apply le_inf_iff.mpr; split; apply factor_multiset_le_iff.mpr,\n    exact gcd_dvd_left m n, exact gcd_dvd_right m n},\n  { rw[\u2190 prime_multiset.prod_dvd_iff, prod_factor_multiset],\n    apply dvd_gcd; rw[prime_multiset.prod_dvd_iff'],\n    exact inf_le_left, exact inf_le_right}\nend\n\ntheorem factor_multiset_lcm (m n : \u2115+) :\n factor_multiset (lcm m n) = (factor_multiset m) \u2294 (factor_multiset n) :=\nbegin\n  apply le_antisymm,\n  { rw[\u2190 prime_multiset.prod_dvd_iff, prod_factor_multiset],\n    apply lcm_dvd; rw[\u2190 factor_multiset_le_iff'],\n    exact le_sup_left, exact le_sup_right},\n  { apply sup_le_iff.mpr; split; apply factor_multiset_le_iff.mpr,\n    exact dvd_lcm_left m n, exact dvd_lcm_right m n },\nend\n\n/-- The number of occurrences of p in the factor multiset of m\n is the same as the p-adic valuation of m. -/\ntheorem count_factor_multiset (m : \u2115+) (p : nat.primes) (k : \u2115) :\n (p : \u2115+) ^ k \u2223 m \u2194 k \u2264 m.factor_multiset.count p :=\nbegin\n  intros,\n  rw [multiset.le_count_iff_replicate_le],\n  rw [\u2190 factor_multiset_le_iff, factor_multiset_pow, factor_multiset_of_prime],\n  congr' 2,\n  apply multiset.eq_replicate.mpr,\n  split,\n  { rw [multiset.card_nsmul, prime_multiset.card_of_prime, mul_one] },\n  { intros q h, rw [prime_multiset.of_prime, multiset.nsmul_singleton _ k] at h,\n    exact multiset.eq_of_mem_replicate h }\nend\n\nend pnat\n\nnamespace prime_multiset\n\ntheorem prod_inf (u v : prime_multiset) :\n (u \u2293 v).prod = pnat.gcd u.prod v.prod :=\nbegin\n  let n := u.prod,\n  let m := v.prod,\n  change (u \u2293 v).prod = pnat.gcd n m,\n  have : u = n.factor_multiset := u.factor_multiset_prod.symm, rw [this],\n  have : v = m.factor_multiset := v.factor_multiset_prod.symm, rw [this],\n  rw [\u2190 pnat.factor_multiset_gcd n m, pnat.prod_factor_multiset]\nend\n\ntheorem prod_sup (u v : prime_multiset) :\n (u \u2294 v).prod = pnat.lcm u.prod v.prod :=\nbegin\n  let n := u.prod,\n  let m := v.prod,\n  change (u \u2294 v).prod = pnat.lcm n m,\n  have : u = n.factor_multiset := u.factor_multiset_prod.symm, rw [this],\n  have : v = m.factor_multiset := v.factor_multiset_prod.symm, rw [this],\n  rw[\u2190 pnat.factor_multiset_lcm n m, pnat.prod_factor_multiset]\nend\n\nend prime_multiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/pnat/factors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.815232480373843, "lm_q1q2_score": 0.7097391650570194}}
{"text": "import Smt\n\ndef Nat.max' (x y : Nat) : Nat := if x \u2264 y then y else x\n\ntheorem Nat.not_le_of_reverse_le {m n : Nat} : \u00ac m \u2264 n \u2192 n \u2264 m := fun hn =>\n  match Nat.le_total m n with\n  | Or.inl h => absurd h hn\n  | Or.inr h => h\n\ntheorem Nat.max'_ge : \u2200 x y : Nat, x \u2264 max' x y \u2227 y \u2264 max' x y := by\n  intro x y\n  smt\n  by_cases h : x \u2264 y <;> simp [max', h]\n  apply not_le_of_reverse_le h\n\ntheorem Nat.max'_ge' : \u2200 x y : Nat, x \u2264 max' x y \u2227 y \u2264 max' x y := by\n  intro x y\n  smt [max']\n  by_cases h : x \u2264 y <;> simp [max', h]\n  apply not_le_of_reverse_le h\n", "meta": {"author": "ufmg-smite", "repo": "lean-smt", "sha": "6de0c4b216a918a14cf7a47d9a6faccaf8c8a209", "save_path": "github-repos/lean/ufmg-smite-lean-smt", "path": "github-repos/lean/ufmg-smite-lean-smt/lean-smt-6de0c4b216a918a14cf7a47d9a6faccaf8c8a209/Test/Nat/Max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7097210139080354}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport order.liminf_limsup\nimport topology.instances.nnreal\n\n/-!\n# Limsup\n\nWe prove some auxiliary results about limsups, infis, and suprs.\n\n## Main Results\n\n* `ennreal.le_infi_mul_infi` : if `f g : \u03b9 \u2192 ennreal` take real values, and\n  `\u2200 (i j : \u03b9), a \u2264 f i * g j`, then `a \u2264 infi f * infi g`.\n* `ennreal.infi_mul_le_mul_infi` : if `u v : \u03b9 \u2192 ennreal` take real values and are antitone, then \n  `infi (u * v) \u2264 infi u * infi v`. \n* `ennreal.limsup_mul_le` : if `u v : \u2115 \u2192 \u211d\u22650\u221e` are bounded above by real numbers, then\n  `filter.limsup (u * v) at_top \u2264 filter.limsup u at_top * filter.limsup v at_top`. \n* `real.limsup_mul_le` : If `u v : \u2115 \u2192 \u211d` are nonnegative and bounded above, then\n  `filter.limsup (u * v) at_top \u2264 filter.limsup u at_top * filter.limsup v at_top `.\n\n## Tags\n\nlimsup, real, nnreal, ennreal\n-/\n\nnoncomputable theory\n\nnamespace filter\n\n/-- If `u : \u03b2 \u2192 \u03b1` is nonnegative and `is_bounded_under has_le.le f u`, then `0 \u2264 limsup u f`. -/\nlemma limsup_nonneg_of_nonneg {\u03b1 \u03b2 : Type*} [has_zero \u03b1] [conditionally_complete_linear_order \u03b1]\n  {f : filter \u03b2} [hf_ne_bot : f.ne_bot] {u : \u03b2 \u2192 \u03b1}\n  (hfu : is_bounded_under has_le.le f u) (h : 0 \u2264 u) : 0 \u2264 limsup u f := \nle_limsup_of_frequently_le (frequently_of_forall h) hfu\n\n/-- If `filter.limsup u at_top \u2264 x`, then for all `\u03b5 > 0`, eventually we have `u a < x + \u03b5`.  -/\nlemma eventually_lt_add_pos_of_limsup_le {\u03b1 : Type*} [preorder \u03b1] {x : \u211d} {u : \u03b1 \u2192 \u211d} \n  (hu_bdd : is_bounded_under has_le.le at_top u) (hu : filter.limsup u at_top \u2264 x) \n  {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) : \u2200\u1da0 (a : \u03b1) in at_top, u a < x + \u03b5 :=\neventually_lt_of_limsup_lt (lt_of_le_of_lt hu (lt_add_of_pos_right x h\u03b5)) hu_bdd\n\n/-- If `filter.limsup u at_top \u2264 x`, then for all `\u03b5 > 0`, there exists a positive natural\n  number `n` such that `u n < x + \u03b5`.  -/\nlemma exists_lt_of_limsup_le {x : \u211d} {u : \u2115 \u2192 \u211d} (hu_bdd : is_bounded_under has_le.le at_top u)\n  (hu : filter.limsup u at_top \u2264 x) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n  \u2203 n : pnat, u n < x + \u03b5 :=\nbegin\n  have h : \u2200\u1da0 (a : \u2115) in at_top, u a < x + \u03b5 := eventually_lt_add_pos_of_limsup_le hu_bdd hu h\u03b5,\n  simp only [eventually_at_top, ge_iff_le] at h,\n  obtain \u27e8n, hn\u27e9 := h,\n  exact \u27e8\u27e8n + 1, nat.succ_pos _\u27e9, hn (n + 1) (nat.le_succ _)\u27e9,\nend\n\nend filter\n\nopen filter\nopen_locale topological_space nnreal ennreal\n\nlemma bdd_above.is_bounded_under {\u03b1 : Type*} [preorder \u03b1] {u : \u03b1 \u2192 \u211d} \n  (hu_bdd : bdd_above (set.range u)) : is_bounded_under has_le.le at_top u :=\nbegin\n  obtain \u27e8b, hb\u27e9 := hu_bdd,\n  use b,\n  simp only [mem_upper_bounds, set.mem_range, forall_exists_index,\n    forall_apply_eq_imp_iff'] at hb,\n  exact eventually_map.mpr (eventually_of_forall hb)\nend\n\nnamespace nnreal\n\nlemma coe_limsup {u : \u2115 \u2192 \u211d} (hu : 0 \u2264 u) :\n  limsup u at_top = (((limsup (\u03bb n, (\u27e8u n, hu n\u27e9 : \u211d\u22650)) at_top) : \u211d\u22650) : \u211d) :=\nbegin\n  simp only [limsup_eq],\n  norm_cast,\n  apply congr_arg,\n  ext x,\n  simp only [set.mem_set_of_eq, set.mem_image],\n  refine \u27e8\u03bb hx, _, \u03bb hx, _\u27e9,\n  { have hx' := hx,\n    simp only [eventually_at_top, ge_iff_le] at hx',\n    obtain \u27e8N, hN\u27e9 := hx',\n    have hx0 : 0 \u2264 x := le_trans (hu N) (hN N (le_refl _)),\n    exact \u27e8\u27e8x, hx0\u27e9, hx, rfl\u27e9, },\n  { obtain \u27e8y, hy, hyx\u27e9 := hx,\n    simp_rw [\u2190 nnreal.coe_le_coe, nnreal.coe_mk, hyx] at hy,\n    exact hy }\nend\n\n/-- If `u : \u2115 \u2192 \u211d` is bounded above an nonnegative, it is also bounded above when regarded as \n  a function to `\u211d\u22650`. -/\nlemma bdd_above' {u : \u2115 \u2192 \u211d} (hu0 : 0 \u2264 u) (hu_bdd: bdd_above (set.range u)) :\n  bdd_above (set.range (\u03bb (n : \u2115), (\u27e8u n, hu0 n\u27e9 : \u211d\u22650))) :=\nbegin\n  obtain \u27e8B, hB\u27e9 := hu_bdd,\n  simp only [mem_upper_bounds, set.mem_range, forall_exists_index, forall_apply_eq_imp_iff'] at hB,\n  have hB0 : 0 \u2264 B := le_trans (hu0 0) (hB 0),\n  use (\u27e8B, hB0\u27e9 : \u211d\u22650),\n  simp only [mem_upper_bounds, set.mem_range, forall_exists_index, subtype.forall, \n    subtype.mk_le_mk],\n  rintros x - n hn,\n  rw \u2190 hn,\n  exact hB n,\nend\n\nlemma eventually_le_of_bdd_above' {u : \u2115 \u2192 \u211d\u22650} (hu : bdd_above (set.range u)) :\n  {a : \u211d\u22650 | \u2200\u1da0 (n : \u2115) in at_top, u n \u2264 a}.nonempty :=\nbegin\n  obtain \u27e8B, hB\u27e9 := hu,\n  simp only [mem_upper_bounds, set.mem_range, forall_exists_index, forall_apply_eq_imp_iff'] \n    at hB,\n  exact \u27e8B, eventually_of_forall hB\u27e9,\nend\n\nend nnreal\n\nnamespace ennreal\n\n/-- If `f g : \u03b9 \u2192 \u211d\u22650\u221e` take real values, and `\u2200 (i j : \u03b9), a \u2264 f i * g j`, then\n  `a \u2264 infi f * infi g`. -/\nlemma le_infi_mul_infi {\u03b9 : Sort*} [h\u03b9 : nonempty \u03b9] {a : \u211d\u22650\u221e} {f g : \u03b9 \u2192 \u211d\u22650\u221e} \n  (hf : \u2200 x, f x \u2260 \u22a4) (hg : \u2200 x, g x \u2260 \u22a4) (H : \u2200 (i j : \u03b9), a \u2264 f i * g j) :\n  a \u2264 infi f * infi g :=\nbegin\n  have hg' : infi g \u2260 \u22a4,\n  { rw [ne.def, infi_eq_top, not_forall], exact \u27e8h\u03b9.some, hg h\u03b9.some\u27e9 },\n  rw infi_mul hg',\n  refine le_infi _,\n  intros i,\n  rw mul_infi (hf i),\n  exact le_infi (H i),\n  { apply_instance },\n  { apply_instance },\nend\n\n/-- If `u v : \u03b9 \u2192 \u211d\u22650\u221e` take real values and are antitone, then `infi (u * v) \u2264 infi u * infi v`. -/\nlemma infi_mul_le_mul_infi {u v : \u2115 \u2192 \u211d\u22650\u221e} (hu_top : \u2200 x, u x \u2260 \u22a4) (hu : antitone u) \n  (hv_top : \u2200 x, v x \u2260 \u22a4) (hv : antitone v) : infi (u * v) \u2264 infi u * infi v :=\nbegin\n  rw infi_le_iff,\n  intros b hb,\n  apply le_infi_mul_infi hu_top hv_top,\n  intros m n,\n  exact le_trans (hb (max m n)) (mul_le_mul (hu (le_max_left _ _)) (hv (le_max_right _ _))),\nend\n\nlemma supr_tail_seq (u : \u2115 \u2192 \u211d\u22650\u221e) (n : \u2115) : \n  (\u2a06 (k : \u2115) (x : n \u2264 k), u k) = \u2a06 (k : { k : \u2115 // n \u2264 k}), u k :=\nby rw supr_subtype; refl\n\nlemma le_supr_prop (u : \u2115 \u2192 \u211d\u22650\u221e) {n k : \u2115} (hnk : n \u2264 k) :\n  u k \u2264 \u2a06 (k : \u2115) (x : n \u2264 k), u k :=\nbegin\n  refine le_supr_of_le k _,\n  rw csupr_pos hnk,\n  exact le_refl _,\nend\n\n/-- The function sending `n : \u2115` to `\u2a06 (k : \u2115) (x : n \u2264 k), u k` is antitone. -/\nlemma antitone.supr {u : \u2115 \u2192 \u211d\u22650\u221e} :\n  antitone (\u03bb (n : \u2115), \u2a06 (k : \u2115) (x : n \u2264 k), u k) :=\nbegin\n  apply antitone_nat_of_succ_le _,\n  intros n,\n  rw [supr\u2082_le_iff],\n  intros k hk,\n  exact le_supr_prop u (le_trans (nat.le_succ n) hk),\nend\n\n/-- If `u : \u2115 \u2192 \u211d\u22650\u221e` is bounded above by a real number, then its `supr` is finite. -/\nlemma supr_le_top_of_bdd_above {u : \u2115 \u2192 \u211d\u22650\u221e} {B : \u211d\u22650} (hu : \u2200 x, u x \u2264 B) (n : \u2115):\n  (\u2a06 (k : \u2115) (x : n \u2264 k), u k) \u2260 \u22a4 :=\nbegin\n  have h_le : (\u2a06 (k : \u2115) (x : n \u2264 k), u k) \u2264 B,\n  { rw supr_tail_seq,\n    exact supr_le (\u03bb m, hu m), },\n  exact ne_top_of_le_ne_top coe_ne_top h_le\nend\n\n/-- If `u v : \u2115 \u2192 \u211d\u22650\u221e` are bounded above by real numbers, then\n  `filter.limsup (u * v) at_top \u2264 filter.limsup u at_top * filter.limsup v at_top`. -/\nlemma limsup_mul_le {u v : \u2115 \u2192 \u211d\u22650\u221e} {Bu Bv : \u211d\u22650} (hu : \u2200 x, u x \u2264 Bu) (hv : \u2200 x, v x \u2264 Bv) :\n  filter.limsup (u * v) at_top \u2264 filter.limsup u at_top * filter.limsup v at_top :=\nbegin\n  have h_le : (\u2a05 (n : \u2115), \u2a06 (i : \u2115) (x : n \u2264 i), u i * v i) \u2264 \n    (\u2a05 (n : \u2115), (\u2a06 (i : \u2115) (x : n \u2264 i), u i) *(\u2a06 (j : \u2115) (x : n \u2264 j), v j)),\n  { refine infi_mono _,\n    intros n,\n    apply supr_le _,\n    intros k,\n    apply supr_le _,\n    intros hk, \n    exact mul_le_mul (le_supr_prop u hk) (le_supr_prop v hk), },\n  simp only [filter.limsup_eq_infi_supr_of_nat, ge_iff_le, pi.mul_apply],\n  exact le_trans h_le (infi_mul_le_mul_infi (supr_le_top_of_bdd_above hu) antitone.supr\n    (supr_le_top_of_bdd_above hv) antitone.supr),\nend\n\nlemma coe_limsup {u : \u2115 \u2192 \u211d\u22650} (hu : bdd_above (set.range u)) :\n  (((limsup u at_top) : \u211d\u22650) : \u211d\u22650\u221e) = limsup (\u03bb n, (u n : \u211d\u22650\u221e)) at_top :=\nbegin\n  simp only [limsup_eq],\n  rw [coe_Inf (nnreal.eventually_le_of_bdd_above' hu), Inf_eq_infi],\n  simp only [eventually_at_top, ge_iff_le, set.mem_set_of_eq, infi_exists],\n  { apply le_antisymm,\n    { apply le_infi\u2082 _,\n      intros x n,\n      apply le_infi _,\n      intro h,\n      cases x,\n      { simp only [none_eq_top, le_top], },\n      { simp only [some_eq_coe, coe_le_coe] at h,\n        exact infi\u2082_le_of_le x n (infi_le_of_le h (le_refl _)) }},\n    { apply le_infi\u2082 _,\n      intros x n,\n      apply le_infi _,\n      intro h,\n      refine infi\u2082_le_of_le x n _,\n      simp_rw coe_le_coe,\n      exact infi_le_of_le h (le_refl _) }},\nend\n\nlemma coe_limsup' {u : \u2115 \u2192 \u211d} (hu : bdd_above (set.range u)) (hu0 : 0 \u2264 u) :\n  (limsup (\u03bb n, ((coe : \u211d\u22650 \u2192 \u211d\u22650\u221e) (\u27e8u n, hu0 n\u27e9 : \u211d\u22650))) at_top) =\n  (coe : \u211d\u22650 \u2192 \u211d\u22650\u221e) (\u27e8limsup u at_top, limsup_nonneg_of_nonneg hu.is_bounded_under hu0\u27e9 : \u211d\u22650) :=\nby rw [\u2190 ennreal.coe_limsup (nnreal.bdd_above' hu0 hu), ennreal.coe_eq_coe, \u2190 nnreal.coe_eq,\n  subtype.coe_mk, nnreal.coe_limsup]\n\nend ennreal\n\n\nnamespace real\n\n/-- If `u v : \u2115 \u2192 \u211d` are nonnegative and bounded above, then `u * v` is bounded above. -/\nlemma range_bdd_above_mul {u v : \u2115 \u2192 \u211d} (hu : bdd_above (set.range u)) (hu0 : 0 \u2264 u)\n   (hv : bdd_above (set.range v)) (hv0 : 0 \u2264 v) :  bdd_above (set.range (u * v)) :=\nbegin\n  obtain \u27e8bu, hbu\u27e9 := hu,\n  obtain \u27e8bv, hbv\u27e9 := hv,\n  use bu*bv,\n  simp only [mem_upper_bounds, set.mem_range, pi.mul_apply, forall_exists_index,\n    forall_apply_eq_imp_iff'] at hbu hbv \u22a2,\n  intros n,\n  exact mul_le_mul (hbu n) (hbv n) (hv0 n) (le_trans (hu0 n) (hbu n)),\nend\n\n/-- If `u v : \u2115 \u2192 \u211d` are nonnegative and bounded above, then\n  `filter.limsup (u * v) at_top \u2264 filter.limsup u at_top * filter.limsup v at_top `.-/\nlemma limsup_mul_le {u v : \u2115 \u2192 \u211d} (hu_bdd : bdd_above (set.range u)) (hu0 : 0 \u2264 u) \n  (hv_bdd : bdd_above (set.range v)) (hv0 : 0 \u2264 v) :\n  filter.limsup (u * v) at_top \u2264 filter.limsup u at_top * filter.limsup v at_top :=\nbegin\n  have h_bdd : bdd_above (set.range (u * v)),\n  { exact range_bdd_above_mul hu_bdd hu0 hv_bdd hv0 },\n  have hc : \u2200 n : \u2115, (\u27e8u n * v n, (mul_nonneg (hu0 n) (hv0 n))\u27e9 : \u211d\u22650) = \u27e8u n, hu0 n\u27e9*\u27e8v n, hv0 n\u27e9,\n  { intro n, simp only [nonneg.mk_mul_mk], },\n  rw [\u2190 nnreal.coe_mk _ (limsup_nonneg_of_nonneg h_bdd.is_bounded_under (mul_nonneg hu0 hv0)),\n    \u2190 nnreal.coe_mk _ (limsup_nonneg_of_nonneg hu_bdd.is_bounded_under hu0),\n    \u2190 nnreal.coe_mk _ (limsup_nonneg_of_nonneg hv_bdd.is_bounded_under hv0),\n    \u2190 nnreal.coe_mul, nnreal.coe_le_coe, \u2190 ennreal.coe_le_coe, ennreal.coe_mul],\n  simp only [\u2190 ennreal.coe_limsup', pi.mul_apply, hc, ennreal.coe_mul],\n  obtain \u27e8Bu, hBu\u27e9 := hu_bdd,\n  obtain \u27e8Bv, hBv\u27e9 := hv_bdd,\n  simp only [mem_upper_bounds, set.mem_range, forall_exists_index, forall_apply_eq_imp_iff'] \n    at hBu hBv,\n  have hBu_0 : 0 \u2264 Bu := le_trans (hu0 0) (hBu 0),\n  have hBu' : \u2200 (n : \u2115), (\u27e8u n, hu0 n\u27e9 : \u211d\u22650)  \u2264 (\u27e8Bu, hBu_0\u27e9 : \u211d\u22650),\n  { simp only [\u2190 nnreal.coe_le_coe, nnreal.coe_mk], exact hBu },\n  have hBv_0 : 0 \u2264 Bv := le_trans (hv0 0) (hBv 0),\n  have hBv' : \u2200 (n : \u2115), (\u27e8v n, hv0 n\u27e9 : \u211d\u22650) \u2264 (\u27e8Bv, hBv_0\u27e9 : \u211d\u22650),\n  { simp only [\u2190 nnreal.coe_le_coe, nnreal.coe_mk], exact hBv },\n  simp_rw \u2190 ennreal.coe_le_coe at hBu' hBv',\n  exact ennreal.limsup_mul_le hBu' hBv',\nend\n\n-- Alternative proof of limsup_mul_le\nlemma limsup_mul_le' {u v : \u2115 \u2192 \u211d} (hu_bdd : bdd_above (set.range u)) (hu0 : 0 \u2264 u) \n  (hv_bdd : bdd_above (set.range v)) (hv0 : 0 \u2264 v) :\n  filter.limsup (u * v) at_top \u2264 filter.limsup u at_top * filter.limsup v at_top :=\nbegin\n  have h_bdd : bdd_above (set.range (u * v)),\n  { exact range_bdd_above_mul hu_bdd hu0 hv_bdd hv0 },\n  have hc : \u2200 n : \u2115, (\u27e8u n * v n, (mul_nonneg (hu0 n) (hv0 n))\u27e9 : \u211d\u22650) = \u27e8u n, hu0 n\u27e9*\u27e8v n, hv0 n\u27e9,\n  { intro n, simp only [nonneg.mk_mul_mk], },\n  rw [nnreal.coe_limsup (mul_nonneg hu0 hv0), nnreal.coe_limsup  hu0, nnreal.coe_limsup hv0,\n    \u2190 nnreal.coe_mul, nnreal.coe_le_coe, \u2190 ennreal.coe_le_coe, ennreal.coe_mul,\n    ennreal.coe_limsup (nnreal.bdd_above' _ h_bdd), \n    ennreal.coe_limsup (nnreal.bdd_above' hu0 hu_bdd),\n    ennreal.coe_limsup (nnreal.bdd_above' hv0 hv_bdd)],\n\n  simp only [pi.mul_apply, hc, ennreal.coe_mul],\n  obtain \u27e8Bu, hBu\u27e9 := hu_bdd,\n  obtain \u27e8Bv, hBv\u27e9 := hv_bdd,\n  simp only [mem_upper_bounds, set.mem_range, forall_exists_index, forall_apply_eq_imp_iff'] \n    at hBu hBv,\n  have hBu_0 : 0 \u2264 Bu := le_trans (hu0 0) (hBu 0),\n  have hBu' : \u2200 (n : \u2115), (\u27e8u n, hu0 n\u27e9 : \u211d\u22650)  \u2264 (\u27e8Bu, hBu_0\u27e9 : \u211d\u22650),\n  { simp only [\u2190 nnreal.coe_le_coe, nnreal.coe_mk], exact hBu },\n  have hBv_0 : 0 \u2264 Bv := le_trans (hv0 0) (hBv 0),\n  have hBv' : \u2200 (n : \u2115), (\u27e8v n, hv0 n\u27e9 : \u211d\u22650) \u2264 (\u27e8Bv, hBv_0\u27e9 : \u211d\u22650),\n  { simp only [\u2190 nnreal.coe_le_coe, nnreal.coe_mk], exact hBv },\n\n  simp_rw \u2190 ennreal.coe_le_coe at hBu' hBv',\n  exact ennreal.limsup_mul_le hBu' hBv',\nend\n\nend real", "meta": {"author": "mariainesdff", "repo": "local_fields", "sha": "53a20ab87cf8f6ab27eedef2d9da929898951d82", "save_path": "github-repos/lean/mariainesdff-local_fields", "path": "github-repos/lean/mariainesdff-local_fields/local_fields-53a20ab87cf8f6ab27eedef2d9da929898951d82/src/limsup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907010924213, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7097210084123222}}
{"text": "/-\nCopyright (c) 2022 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Chambert-Loir, Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n\n! This file was ported from Lean 3 source module ring_theory.mv_polynomial.weighted_homogeneous\n! leanprover-community/mathlib commit bcbee715ab85a4f516c814effdf232618c0322af\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.GradedMonoid\nimport Mathbin.Data.MvPolynomial.Variables\n\n/-!\n# Weighted homogeneous polynomials\n\nIt is possible to assign weights (in a commutative additive monoid `M`) to the variables of a\nmultivariate polynomial ring, so that monomials of the ring then have a weighted degree with\nrespect to the weights of the variables. The weights are represented by a function `w : \u03c3 \u2192 M`,\nwhere `\u03c3` are the indeterminates.\n\nA multivariate polynomial `\u03c6` is weighted homogeneous of weighted degree `m : M` if all monomials\noccuring in `\u03c6` have the same weighted degree `m`.\n\n## Main definitions/lemmas\n\n* `weighted_total_degree' w \u03c6` : the weighted total degree of a multivariate polynomial with respect\nto the weights `w`, taking values in `with_bot M`.\n\n* `weighted_total_degree w \u03c6` : When `M` has a `\u22a5` element, we can define the weighted total degree\nof a multivariate polynomial as a function taking values in `M`.\n\n* `is_weighted_homogeneous w \u03c6 m`: a predicate that asserts that `\u03c6` is weighted homogeneous\nof weighted degree `m` with respect to the weights `w`.\n\n* `weighted_homogeneous_submodule R w m`: the submodule of homogeneous polynomials\nof weighted degree `m`.\n\n* `weighted_homogeneous_component w m`: the additive morphism that projects polynomials\nonto their summand that is weighted homogeneous of degree `n` with respect to `w`.\n\n* `sum_weighted_homogeneous_component`: every polynomial is the sum of its weighted homogeneous\ncomponents.\n-/\n\n\nnoncomputable section\n\nopen Classical BigOperators\n\nopen Set Function Finset Finsupp AddMonoidAlgebra\n\nvariable {R M : Type _} [CommSemiring R]\n\nnamespace MvPolynomial\n\nvariable {\u03c3 : Type _}\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid M]\n\n/-! ### `weighted_degree'` -/\n\n\n#print MvPolynomial.weightedDegree' /-\n/-- The `weighted degree'` of the finitely supported function `s : \u03c3 \u2192\u2080 \u2115` is the sum\n  `\u2211(s i)\u2022(w i)`. -/\ndef weightedDegree' (w : \u03c3 \u2192 M) : (\u03c3 \u2192\u2080 \u2115) \u2192+ M :=\n  (Finsupp.total \u03c3 M \u2115 w).toAddMonoidHom\n#align mv_polynomial.weighted_degree' MvPolynomial.weightedDegree'\n-/\n\nsection SemilatticeSup\n\nvariable [SemilatticeSup M]\n\n#print MvPolynomial.weightedTotalDegree' /-\n/-- The weighted total degree of a multivariate polynomial, taking values in `with_bot M`. -/\ndef weightedTotalDegree' (w : \u03c3 \u2192 M) (p : MvPolynomial \u03c3 R) : WithBot M :=\n  p.support.sup fun s => weightedDegree' w s\n#align mv_polynomial.weighted_total_degree' MvPolynomial.weightedTotalDegree'\n-/\n\n/- warning: mv_polynomial.weighted_total_degree'_eq_bot_iff -> MvPolynomial.weightedTotalDegree'_eq_bot_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : SemilatticeSup.{u2} M] (w : \u03c3 -> M) (p : MvPolynomial.{u3, u1} \u03c3 R _inst_1), Iff (Eq.{succ u2} (WithBot.{u2} M) (MvPolynomial.weightedTotalDegree'.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 w p) (Bot.bot.{u2} (WithBot.{u2} M) (WithBot.hasBot.{u2} M))) (Eq.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) p (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))))))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] [_inst_3 : SemilatticeSup.{u1} M] (w : \u03c3 -> M) (p : MvPolynomial.{u3, u2} \u03c3 R _inst_1), Iff (Eq.{succ u1} (WithBot.{u1} M) (MvPolynomial.weightedTotalDegree'.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 w p) (Bot.bot.{u1} (WithBot.{u1} M) (WithBot.bot.{u1} M))) (Eq.{max (succ u2) (succ u3)} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) p (OfNat.ofNat.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_total_degree'_eq_bot_iff MvPolynomial.weightedTotalDegree'_eq_bot_iff\u2093'. -/\n/-- The `weighted_total_degree'` of a polynomial `p` is `\u22a5` if and only if `p = 0`. -/\ntheorem weightedTotalDegree'_eq_bot_iff (w : \u03c3 \u2192 M) (p : MvPolynomial \u03c3 R) :\n    weightedTotalDegree' w p = \u22a5 \u2194 p = 0 :=\n  by\n  simp only [weighted_total_degree', Finset.sup_eq_bot_iff, mem_support_iff, WithBot.coe_ne_bot,\n    MvPolynomial.eq_zero_iff]\n  exact forall_congr' fun _ => Classical.not_not\n#align mv_polynomial.weighted_total_degree'_eq_bot_iff MvPolynomial.weightedTotalDegree'_eq_bot_iff\n\n/- warning: mv_polynomial.weighted_total_degree'_zero -> MvPolynomial.weightedTotalDegree'_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : SemilatticeSup.{u2} M] (w : \u03c3 -> M), Eq.{succ u2} (WithBot.{u2} M) (MvPolynomial.weightedTotalDegree'.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 w (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))))))))) (Bot.bot.{u2} (WithBot.{u2} M) (WithBot.hasBot.{u2} M))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u3} M] [_inst_3 : SemilatticeSup.{u3} M] (w : \u03c3 -> M), Eq.{succ u3} (WithBot.{u3} M) (MvPolynomial.weightedTotalDegree'.{u2, u3, u1} R M _inst_1 \u03c3 _inst_2 _inst_3 w (OfNat.ofNat.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))))) (Bot.bot.{u3} (WithBot.{u3} M) (WithBot.bot.{u3} M))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_total_degree'_zero MvPolynomial.weightedTotalDegree'_zero\u2093'. -/\n/-- The `weighted_total_degree'` of the zero polynomial is `\u22a5`. -/\ntheorem weightedTotalDegree'_zero (w : \u03c3 \u2192 M) : weightedTotalDegree' w (0 : MvPolynomial \u03c3 R) = \u22a5 :=\n  by simp only [weighted_total_degree', support_zero, Finset.sup_empty]\n#align mv_polynomial.weighted_total_degree'_zero MvPolynomial.weightedTotalDegree'_zero\n\nsection OrderBot\n\nvariable [OrderBot M]\n\n#print MvPolynomial.weightedTotalDegree /-\n/-- When `M` has a `\u22a5` element, we can define the weighted total degree of a multivariate\n  polynomial as a function taking values in `M`. -/\ndef weightedTotalDegree (w : \u03c3 \u2192 M) (p : MvPolynomial \u03c3 R) : M :=\n  p.support.sup fun s => weightedDegree' w s\n#align mv_polynomial.weighted_total_degree MvPolynomial.weightedTotalDegree\n-/\n\n/- warning: mv_polynomial.weighted_total_degree_coe -> MvPolynomial.weightedTotalDegree_coe is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : SemilatticeSup.{u2} M] [_inst_4 : OrderBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3)))] (w : \u03c3 -> M) (p : MvPolynomial.{u3, u1} \u03c3 R _inst_1), (Ne.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) p (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))))))))) -> (Eq.{succ u2} (WithBot.{u2} M) (MvPolynomial.weightedTotalDegree'.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 w p) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) M (WithBot.{u2} M) (HasLiftT.mk.{succ u2, succ u2} M (WithBot.{u2} M) (CoeTC\u2093.coe.{succ u2, succ u2} M (WithBot.{u2} M) (WithBot.hasCoeT.{u2} M))) (MvPolynomial.weightedTotalDegree.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w p)))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] [_inst_3 : SemilatticeSup.{u1} M] [_inst_4 : OrderBot.{u1} M (Preorder.toLE.{u1} M (PartialOrder.toPreorder.{u1} M (SemilatticeSup.toPartialOrder.{u1} M _inst_3)))] (w : \u03c3 -> M) (p : MvPolynomial.{u3, u2} \u03c3 R _inst_1), (Ne.{max (succ u2) (succ u3)} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) p (OfNat.ofNat.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))))) -> (Eq.{succ u1} (WithBot.{u1} M) (MvPolynomial.weightedTotalDegree'.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 w p) (WithBot.some.{u1} M (MvPolynomial.weightedTotalDegree.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w p)))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_total_degree_coe MvPolynomial.weightedTotalDegree_coe\u2093'. -/\n/-- This lemma relates `weighted_total_degree` and `weighted_total_degree'`. -/\ntheorem weightedTotalDegree_coe (w : \u03c3 \u2192 M) (p : MvPolynomial \u03c3 R) (hp : p \u2260 0) :\n    weightedTotalDegree' w p = \u2191(weightedTotalDegree w p) :=\n  by\n  rw [Ne.def, \u2190 weighted_total_degree'_eq_bot_iff w p, \u2190 Ne.def, WithBot.ne_bot_iff_exists] at hp\n  obtain \u27e8m, hm\u27e9 := hp\n  apply le_antisymm\n  \u00b7 simp only [weighted_total_degree, weighted_total_degree', Finset.sup_le_iff, WithBot.coe_le_coe]\n    intro b\n    exact Finset.le_sup\n  \u00b7 simp only [weighted_total_degree]\n    have hm' : weighted_total_degree' w p \u2264 m := le_of_eq hm.symm\n    rw [\u2190 hm]\n    simpa [weighted_total_degree'] using hm'\n#align mv_polynomial.weighted_total_degree_coe MvPolynomial.weightedTotalDegree_coe\n\n/- warning: mv_polynomial.weighted_total_degree_zero -> MvPolynomial.weightedTotalDegree_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : SemilatticeSup.{u2} M] [_inst_4 : OrderBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3)))] (w : \u03c3 -> M), Eq.{succ u2} M (MvPolynomial.weightedTotalDegree.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))))))))) (Bot.bot.{u2} M (OrderBot.toHasBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3))) _inst_4))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u3} M] [_inst_3 : SemilatticeSup.{u3} M] [_inst_4 : OrderBot.{u3} M (Preorder.toLE.{u3} M (PartialOrder.toPreorder.{u3} M (SemilatticeSup.toPartialOrder.{u3} M _inst_3)))] (w : \u03c3 -> M), Eq.{succ u3} M (MvPolynomial.weightedTotalDegree.{u2, u3, u1} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w (OfNat.ofNat.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))))) (Bot.bot.{u3} M (OrderBot.toBot.{u3} M (Preorder.toLE.{u3} M (PartialOrder.toPreorder.{u3} M (SemilatticeSup.toPartialOrder.{u3} M _inst_3))) _inst_4))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_total_degree_zero MvPolynomial.weightedTotalDegree_zero\u2093'. -/\n/-- The `weighted_total_degree` of the zero polynomial is `\u22a5`. -/\ntheorem weightedTotalDegree_zero (w : \u03c3 \u2192 M) : weightedTotalDegree w (0 : MvPolynomial \u03c3 R) = \u22a5 :=\n  by simp only [weighted_total_degree, support_zero, Finset.sup_empty]\n#align mv_polynomial.weighted_total_degree_zero MvPolynomial.weightedTotalDegree_zero\n\n/- warning: mv_polynomial.le_weighted_total_degree -> MvPolynomial.le_weightedTotalDegree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : SemilatticeSup.{u2} M] [_inst_4 : OrderBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3)))] (w : \u03c3 -> M) {\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero}, (Membership.Mem.{u3, u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) (Finset.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero)) (Finset.hasMem.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero)) d (MvPolynomial.support.{u1, u3} R \u03c3 _inst_1 \u03c6)) -> (LE.le.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3))) (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) (MvPolynomial.weightedTotalDegree.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w \u03c6))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] [_inst_3 : SemilatticeSup.{u1} M] [_inst_4 : OrderBot.{u1} M (Preorder.toLE.{u1} M (PartialOrder.toPreorder.{u1} M (SemilatticeSup.toPartialOrder.{u1} M _inst_3)))] (w : \u03c3 -> M) {\u03c6 : MvPolynomial.{u3, u2} \u03c3 R _inst_1} {d : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)}, (Membership.mem.{u3, u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finset.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero))) (Finset.instMembershipFinset.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero))) d (MvPolynomial.support.{u2, u3} R \u03c3 _inst_1 \u03c6)) -> (LE.le.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (Preorder.toLE.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (PartialOrder.toPreorder.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (SemilatticeSup.toPartialOrder.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) _inst_3))) (FunLike.coe.{max (succ u1) (succ u3), succ u3, succ u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))))) (MvPolynomial.weightedDegree'.{u1, u3} M \u03c3 _inst_2 w) d) (MvPolynomial.weightedTotalDegree.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w \u03c6))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.le_weighted_total_degree MvPolynomial.le_weightedTotalDegree\u2093'. -/\ntheorem le_weightedTotalDegree (w : \u03c3 \u2192 M) {\u03c6 : MvPolynomial \u03c3 R} {d : \u03c3 \u2192\u2080 \u2115}\n    (hd : d \u2208 \u03c6.support) : weightedDegree' w d \u2264 \u03c6.weightedTotalDegree w :=\n  le_sup hd\n#align mv_polynomial.le_weighted_total_degree MvPolynomial.le_weightedTotalDegree\n\nend OrderBot\n\nend SemilatticeSup\n\n#print MvPolynomial.IsWeightedHomogeneous /-\n/-- A multivariate polynomial `\u03c6` is weighted homogeneous of weighted degree `m` if all monomials\n  occuring in `\u03c6` have weighted degree `m`. -/\ndef IsWeightedHomogeneous (w : \u03c3 \u2192 M) (\u03c6 : MvPolynomial \u03c3 R) (m : M) : Prop :=\n  \u2200 \u2983d\u2984, coeff d \u03c6 \u2260 0 \u2192 weightedDegree' w d = m\n#align mv_polynomial.is_weighted_homogeneous MvPolynomial.IsWeightedHomogeneous\n-/\n\nvariable (R)\n\n#print MvPolynomial.weightedHomogeneousSubmodule /-\n/-- The submodule of homogeneous `mv_polynomial`s of degree `n`. -/\ndef weightedHomogeneousSubmodule (w : \u03c3 \u2192 M) (m : M) : Submodule R (MvPolynomial \u03c3 R)\n    where\n  carrier := { x | x.IsWeightedHomogeneous w m }\n  smul_mem' r a ha c hc := by\n    rw [coeff_smul] at hc\n    exact ha (right_ne_zero_of_mul hc)\n  zero_mem' d hd := False.elim (hd <| coeff_zero _)\n  add_mem' a b ha hb c hc := by\n    rw [coeff_add] at hc\n    obtain h | h : coeff c a \u2260 0 \u2228 coeff c b \u2260 0 :=\n      by\n      contrapose! hc\n      simp only [hc, add_zero]\n    \u00b7 exact ha h\n    \u00b7 exact hb h\n#align mv_polynomial.weighted_homogeneous_submodule MvPolynomial.weightedHomogeneousSubmodule\n-/\n\n/- warning: mv_polynomial.mem_weighted_homogeneous_submodule -> MvPolynomial.mem_weightedHomogeneousSubmodule is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (m : M) (p : MvPolynomial.{u3, u1} \u03c3 R _inst_1), Iff (Membership.Mem.{max u3 u1, max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (SetLike.hasMem.{max u3 u1, max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Submodule.setLike.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))))) p (MvPolynomial.weightedHomogeneousSubmodule.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w m)) (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w p m)\nbut is expected to have type\n  forall (R : Type.{u2}) {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] (w : \u03c3 -> M) (m : M) (p : MvPolynomial.{u3, u2} \u03c3 R _inst_1), Iff (Membership.mem.{max u2 u3, max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Submodule.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (SetLike.instMembership.{max u2 u3, max u2 u3} (Submodule.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Submodule.setLike.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))))) p (MvPolynomial.weightedHomogeneousSubmodule.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w m)) (MvPolynomial.IsWeightedHomogeneous.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w p m)\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.mem_weighted_homogeneous_submodule MvPolynomial.mem_weightedHomogeneousSubmodule\u2093'. -/\n@[simp]\ntheorem mem_weightedHomogeneousSubmodule (w : \u03c3 \u2192 M) (m : M) (p : MvPolynomial \u03c3 R) :\n    p \u2208 weightedHomogeneousSubmodule R w m \u2194 p.IsWeightedHomogeneous w m :=\n  Iff.rfl\n#align mv_polynomial.mem_weighted_homogeneous_submodule MvPolynomial.mem_weightedHomogeneousSubmodule\n\nvariable (R)\n\n/- warning: mv_polynomial.weighted_homogeneous_submodule_eq_finsupp_supported -> MvPolynomial.weightedHomogeneousSubmodule_eq_finsupp_supported is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (m : M), Eq.{succ (max u3 u1)} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousSubmodule.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w m) (Finsupp.supported.{u3, u1, u1} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) R R (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (setOf.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) (fun (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) => Eq.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) m)))\nbut is expected to have type\n  forall (R : Type.{u3}) {M : Type.{u1}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u2}} [_inst_2 : AddCommMonoid.{u1} M] (w : \u03c3 -> M) (m : M), Eq.{max (succ u3) (succ u2)} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.weightedHomogeneousSubmodule.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w m) (Finsupp.supported.{u2, u3, u3} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) R R (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (setOf.{u2} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (d : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u1 u2, u2, u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u2} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u1 u2, u2, u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))))) (MvPolynomial.weightedDegree'.{u1, u2} M \u03c3 _inst_2 w) d) m)))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_submodule_eq_finsupp_supported MvPolynomial.weightedHomogeneousSubmodule_eq_finsupp_supported\u2093'. -/\n/-- The submodule ` weighted_homogeneous_submodule R w m` of homogeneous `mv_polynomial`s of\n  degree `n` is equal to the `R`-submodule of all `p : (\u03c3 \u2192\u2080 \u2115) \u2192\u2080 R` such that\n  `p.support \u2286 {d | weighted_degree' w d = m}`. While equal, the former has a\n  convenient definitional reduction. -/\ntheorem weightedHomogeneousSubmodule_eq_finsupp_supported (w : \u03c3 \u2192 M) (m : M) :\n    weightedHomogeneousSubmodule R w m = Finsupp.supported _ R { d | weightedDegree' w d = m } :=\n  by\n  ext\n  simp only [mem_supported, Set.subset_def, Finsupp.mem_support_iff, mem_coe]\n  rfl\n#align mv_polynomial.weighted_homogeneous_submodule_eq_finsupp_supported MvPolynomial.weightedHomogeneousSubmodule_eq_finsupp_supported\n\nvariable {R}\n\n/- warning: mv_polynomial.weighted_homogeneous_submodule_mul -> MvPolynomial.weightedHomogeneousSubmodule_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (m : M) (n : M), LE.le.{max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (Preorder.toLE.{max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (PartialOrder.toPreorder.{max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (SetLike.partialOrder.{max u3 u1, max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Submodule.setLike.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))))))) (HMul.hMul.{max u3 u1, max u3 u1, max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (instHMul.{max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (Submodule.mul.{u1, max u3 u1} R _inst_1 (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)) (MvPolynomial.algebra.{u1, u1, u3} R R \u03c3 _inst_1 _inst_1 (Algebra.id.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousSubmodule.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w m) (MvPolynomial.weightedHomogeneousSubmodule.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n)) (MvPolynomial.weightedHomogeneousSubmodule.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) m n))\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u2}} [_inst_2 : AddCommMonoid.{u1} M] (w : \u03c3 -> M) (m : M) (n : M), LE.le.{max u3 u2} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (Preorder.toLE.{max u3 u2} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (PartialOrder.toPreorder.{max u3 u2} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (OmegaCompletePartialOrder.toPartialOrder.{max u3 u2} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (CompleteLattice.instOmegaCompletePartialOrder.{max u3 u2} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (Submodule.completeLattice.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))))))) (HMul.hMul.{max u3 u2, max u3 u2, max u3 u2} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (instHMul.{max u3 u2} (Submodule.{u3, max u3 u2} R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (Submodule.mul.{u3, max u3 u2} R _inst_1 (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1)) (MvPolynomial.algebra.{u3, u3, u2} R R \u03c3 _inst_1 _inst_1 (Algebra.id.{u3} R _inst_1)))) (MvPolynomial.weightedHomogeneousSubmodule.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w m) (MvPolynomial.weightedHomogeneousSubmodule.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w n)) (MvPolynomial.weightedHomogeneousSubmodule.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w (HAdd.hAdd.{u1, u1, u1} M M M (instHAdd.{u1} M (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)))) m n))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_submodule_mul MvPolynomial.weightedHomogeneousSubmodule_mul\u2093'. -/\n/-- The submodule generated by products `Pm *Pn` of weighted homogeneous polynomials of degrees `m`\n  and `n` is contained in the submodule of weighted homogeneous polynomials of degree `m + n`. -/\ntheorem weightedHomogeneousSubmodule_mul (w : \u03c3 \u2192 M) (m n : M) :\n    weightedHomogeneousSubmodule R w m * weightedHomogeneousSubmodule R w n \u2264\n      weightedHomogeneousSubmodule R w (m + n) :=\n  by\n  rw [Submodule.mul_le]\n  intro \u03c6 h\u03c6 \u03c8 h\u03c8 c hc\n  rw [coeff_mul] at hc\n  obtain \u27e8\u27e8d, e\u27e9, hde, H\u27e9 := Finset.exists_ne_zero_of_sum_ne_zero hc\n  have aux : coeff d \u03c6 \u2260 0 \u2227 coeff e \u03c8 \u2260 0 :=\n    by\n    contrapose! H\n    by_cases h : coeff d \u03c6 = 0 <;>\n      simp_all only [Ne.def, not_false_iff, MulZeroClass.zero_mul, MulZeroClass.mul_zero]\n  rw [\u2190 finsupp.mem_antidiagonal.mp hde, \u2190 h\u03c6 aux.1, \u2190 h\u03c8 aux.2, map_add]\n#align mv_polynomial.weighted_homogeneous_submodule_mul MvPolynomial.weightedHomogeneousSubmodule_mul\n\n/- warning: mv_polynomial.is_weighted_homogeneous_monomial -> MvPolynomial.isWeightedHomogeneous_monomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) (r : R) {m : M}, (Eq.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) m) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (coeFn.{max (succ u1) (succ (max u3 u1)), max (succ u1) (succ (max u3 u1))} (LinearMap.{u1, u1, u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => R -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, max u3 u1} R R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.monomial.{u1, u3} R \u03c3 _inst_1 d) r) m)\nbut is expected to have type\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (d : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (r : R) {m : M}, (Eq.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u2) (succ u3), succ u3, succ u2} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u2 u3, u3, u2} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u2 u3, u3, u2} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) m) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (FunLike.coe.{max (succ u3) (succ u1), succ u1, max (succ u3) (succ u1)} (LinearMap.{u1, u1, u1, max u1 u3} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => MvPolynomial.{u3, u1} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u1, max u3 u1} R R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u1 u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.monomial.{u1, u3} R \u03c3 _inst_1 d) r) m)\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous_monomial MvPolynomial.isWeightedHomogeneous_monomial\u2093'. -/\n/-- Monomials are weighted homogeneous. -/\ntheorem isWeightedHomogeneous_monomial (w : \u03c3 \u2192 M) (d : \u03c3 \u2192\u2080 \u2115) (r : R) {m : M}\n    (hm : weightedDegree' w d = m) : IsWeightedHomogeneous w (monomial d r) m :=\n  by\n  intro c hc\n  rw [coeff_monomial] at hc\n  split_ifs  at hc with h\n  \u00b7 subst c\n    exact hm\n  \u00b7 contradiction\n#align mv_polynomial.is_weighted_homogeneous_monomial MvPolynomial.isWeightedHomogeneous_monomial\n\n/- warning: mv_polynomial.is_weighted_homogeneous_of_total_degree_zero -> MvPolynomial.isWeightedHomogeneous_of_total_degree_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : SemilatticeSup.{u2} M] [_inst_4 : OrderBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3)))] (w : \u03c3 -> M) {p : MvPolynomial.{u3, u1} \u03c3 R _inst_1}, (Eq.{succ u2} M (MvPolynomial.weightedTotalDegree.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w p) (Bot.bot.{u2} M (OrderBot.toHasBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3))) _inst_4))) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w p (Bot.bot.{u2} M (OrderBot.toHasBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3))) _inst_4)))\nbut is expected to have type\n  forall {R : Type.{u1}} {M : Type.{u3}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u2}} [_inst_2 : AddCommMonoid.{u3} M] [_inst_3 : SemilatticeSup.{u3} M] [_inst_4 : OrderBot.{u3} M (Preorder.toLE.{u3} M (PartialOrder.toPreorder.{u3} M (SemilatticeSup.toPartialOrder.{u3} M _inst_3)))] (w : \u03c3 -> M) {p : MvPolynomial.{u2, u1} \u03c3 R _inst_1}, (Eq.{succ u3} M (MvPolynomial.weightedTotalDegree.{u1, u3, u2} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w p) (Bot.bot.{u3} M (OrderBot.toBot.{u3} M (Preorder.toLE.{u3} M (PartialOrder.toPreorder.{u3} M (SemilatticeSup.toPartialOrder.{u3} M _inst_3))) _inst_4))) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u3, u2} R M _inst_1 \u03c3 _inst_2 w p (Bot.bot.{u3} M (OrderBot.toBot.{u3} M (Preorder.toLE.{u3} M (PartialOrder.toPreorder.{u3} M (SemilatticeSup.toPartialOrder.{u3} M _inst_3))) _inst_4)))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous_of_total_degree_zero MvPolynomial.isWeightedHomogeneous_of_total_degree_zero\u2093'. -/\n/-- A polynomial of weighted_total_degree `\u22a5` is weighted_homogeneous of degree `\u22a5`. -/\ntheorem isWeightedHomogeneous_of_total_degree_zero [SemilatticeSup M] [OrderBot M] (w : \u03c3 \u2192 M)\n    {p : MvPolynomial \u03c3 R} (hp : weightedTotalDegree w p = (\u22a5 : M)) :\n    IsWeightedHomogeneous w p (\u22a5 : M) := by\n  intro d hd\n  have h := weighted_total_degree_coe w p (mv_polynomial.ne_zero_iff.mpr \u27e8d, hd\u27e9)\n  simp only [weighted_total_degree', hp] at h\n  rw [eq_bot_iff, \u2190 WithBot.coe_le_coe, \u2190 h]\n  exact Finset.le_sup (mem_support_iff.mpr hd)\n#align mv_polynomial.is_weighted_homogeneous_of_total_degree_zero MvPolynomial.isWeightedHomogeneous_of_total_degree_zero\n\n/- warning: mv_polynomial.is_weighted_homogeneous_C -> MvPolynomial.isWeightedHomogeneous_C is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (r : R), MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (coeFn.{max (succ u1) (succ (max u3 u1)), max (succ u1) (succ (max u3 u1))} (RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (fun (_x : RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) => R -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (RingHom.hasCoeToFun.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (MvPolynomial.C.{u1, u3} R \u03c3 _inst_1) r) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))))\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (r : R), MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w (FunLike.coe.{max (succ u1) (succ u3), succ u3, max (succ u1) (succ u3)} (RingHom.{u3, max u3 u1} R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u1, u3} \u03c3 R _inst_1) _x) (MulHomClass.toFunLike.{max u1 u3, u3, max u1 u3} (RingHom.{u3, max u3 u1} R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1)))) R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u3} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (NonUnitalNonAssocSemiring.toMul.{max u1 u3} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u1 u3} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))) (NonUnitalRingHomClass.toMulHomClass.{max u1 u3, u3, max u1 u3} (RingHom.{u3, max u3 u1} R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1)))) R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u1 u3} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1)))) (RingHomClass.toNonUnitalRingHomClass.{max u1 u3, u3, max u1 u3} (RingHom.{u3, max u3 u1} R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1)))) R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))) (RingHom.instRingHomClassRingHom.{u3, max u1 u3} R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))))) (MvPolynomial.C.{u3, u1} R \u03c3 _inst_1) r) (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous_C MvPolynomial.isWeightedHomogeneous_C\u2093'. -/\n/-- Constant polynomials are weighted homogeneous of degree 0. -/\ntheorem isWeightedHomogeneous_C (w : \u03c3 \u2192 M) (r : R) :\n    IsWeightedHomogeneous w (C r : MvPolynomial \u03c3 R) 0 :=\n  isWeightedHomogeneous_monomial _ _ _ (map_zero _)\n#align mv_polynomial.is_weighted_homogeneous_C MvPolynomial.isWeightedHomogeneous_C\n\nvariable (R)\n\n/- warning: mv_polynomial.is_weighted_homogeneous_zero -> MvPolynomial.isWeightedHomogeneous_zero is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (m : M), MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))))) m\nbut is expected to have type\n  forall (R : Type.{u3}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (m : M), MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))) m\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous_zero MvPolynomial.isWeightedHomogeneous_zero\u2093'. -/\n/-- 0 is weighted homogeneous of any degree. -/\ntheorem isWeightedHomogeneous_zero (w : \u03c3 \u2192 M) (m : M) :\n    IsWeightedHomogeneous w (0 : MvPolynomial \u03c3 R) m :=\n  (weightedHomogeneousSubmodule R w m).zero_mem\n#align mv_polynomial.is_weighted_homogeneous_zero MvPolynomial.isWeightedHomogeneous_zero\n\n/- warning: mv_polynomial.is_weighted_homogeneous_one -> MvPolynomial.isWeightedHomogeneous_one is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M), MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 1 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 1 (One.one.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (AddMonoidWithOne.toOne.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (AddCommMonoidWithOne.toAddMonoidWithOne.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toAddCommMonoidWithOne.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))))) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))))\nbut is expected to have type\n  forall (R : Type.{u3}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M), MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) 1 (One.toOfNat1.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toOne.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))) (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous_one MvPolynomial.isWeightedHomogeneous_one\u2093'. -/\n/-- 1 is weighted homogeneous of degree 0. -/\ntheorem isWeightedHomogeneous_one (w : \u03c3 \u2192 M) : IsWeightedHomogeneous w (1 : MvPolynomial \u03c3 R) 0 :=\n  isWeightedHomogeneous_C _ _\n#align mv_polynomial.is_weighted_homogeneous_one MvPolynomial.isWeightedHomogeneous_one\n\n/- warning: mv_polynomial.is_weighted_homogeneous_X -> MvPolynomial.isWeightedHomogeneous_X is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (i : \u03c3), MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (MvPolynomial.X.{u1, u3} R \u03c3 _inst_1 i) (w i)\nbut is expected to have type\n  forall (R : Type.{u3}) {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (i : \u03c3), MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w (MvPolynomial.X.{u3, u1} R \u03c3 _inst_1 i) (w i)\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous_X MvPolynomial.isWeightedHomogeneous_X\u2093'. -/\n/-- An indeterminate `i : \u03c3` is weighted homogeneous of degree `w i`. -/\ntheorem isWeightedHomogeneous_X (w : \u03c3 \u2192 M) (i : \u03c3) :\n    IsWeightedHomogeneous w (X i : MvPolynomial \u03c3 R) (w i) :=\n  by\n  apply is_weighted_homogeneous_monomial\n  simp only [weighted_degree', LinearMap.toAddMonoidHom_coe, total_single, one_nsmul]\n#align mv_polynomial.is_weighted_homogeneous_X MvPolynomial.isWeightedHomogeneous_X\n\nnamespace IsWeightedHomogeneous\n\nvariable {R} {\u03c6 \u03c8 : MvPolynomial \u03c3 R} {m n : M}\n\n/- warning: mv_polynomial.is_weighted_homogeneous.coeff_eq_zero -> MvPolynomial.IsWeightedHomogeneous.coeff_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {n : M} {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (forall (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero), (Ne.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) n) -> (Eq.{succ u1} R (MvPolynomial.coeff.{u1, u3} R \u03c3 _inst_1 d \u03c6) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))))))))))\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u1, u3} \u03c3 R _inst_1} {n : M} {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (forall (d : Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)), (Ne.{succ u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u2) (succ u1), succ u1, succ u2} (AddMonoidHom.{u1, u2} (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u1, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u2 u1, u1, u2} (AddMonoidHom.{u1, u2} (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u1, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u1} (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u1, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u2 u1, u1, u2} (AddMonoidHom.{u1, u2} (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u1, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u1, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u1, u2} (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u1, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))) (MvPolynomial.weightedDegree'.{u2, u1} M \u03c3 _inst_2 w) d) n) -> (Eq.{succ u3} R (MvPolynomial.coeff.{u3, u1} R \u03c3 _inst_1 d \u03c6) (OfNat.ofNat.{u3} R 0 (Zero.toOfNat0.{u3} R (CommMonoidWithZero.toZero.{u3} R (CommSemiring.toCommMonoidWithZero.{u3} R _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous.coeff_eq_zero MvPolynomial.IsWeightedHomogeneous.coeff_eq_zero\u2093'. -/\n/-- The weighted degree of a weighted homogeneous polynomial controls its support. -/\ntheorem coeff_eq_zero {w : \u03c3 \u2192 M} (h\u03c6 : IsWeightedHomogeneous w \u03c6 n) (d : \u03c3 \u2192\u2080 \u2115)\n    (hd : weightedDegree' w d \u2260 n) : coeff d \u03c6 = 0 :=\n  by\n  have aux := mt (@h\u03c6 d) hd\n  rwa [Classical.not_not] at aux\n#align mv_polynomial.is_weighted_homogeneous.coeff_eq_zero MvPolynomial.IsWeightedHomogeneous.coeff_eq_zero\n\n/- warning: mv_polynomial.is_weighted_homogeneous.inj_right -> MvPolynomial.IsWeightedHomogeneous.inj_right is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {m : M} {n : M} {w : \u03c3 -> M}, (Ne.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) \u03c6 (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))))))))) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c6 m) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (Eq.{succ u2} M m n)\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u2}} [_inst_2 : AddCommMonoid.{u1} M] {\u03c6 : MvPolynomial.{u2, u3} \u03c3 R _inst_1} {m : M} {n : M} {w : \u03c3 -> M}, (Ne.{max (succ u3) (succ u2)} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6 (OfNat.ofNat.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1)))))) -> (MvPolynomial.IsWeightedHomogeneous.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w \u03c6 m) -> (MvPolynomial.IsWeightedHomogeneous.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (Eq.{succ u1} M m n)\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous.inj_right MvPolynomial.IsWeightedHomogeneous.inj_right\u2093'. -/\n/-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/\ntheorem inj_right {w : \u03c3 \u2192 M} (h\u03c6 : \u03c6 \u2260 0) (hm : IsWeightedHomogeneous w \u03c6 m)\n    (hn : IsWeightedHomogeneous w \u03c6 n) : m = n :=\n  by\n  obtain \u27e8d, hd\u27e9 : \u2203 d, coeff d \u03c6 \u2260 0 := exists_coeff_ne_zero h\u03c6\n  rw [\u2190 hm hd, \u2190 hn hd]\n#align mv_polynomial.is_weighted_homogeneous.inj_right MvPolynomial.IsWeightedHomogeneous.inj_right\n\n/- warning: mv_polynomial.is_weighted_homogeneous.add -> MvPolynomial.IsWeightedHomogeneous.add is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {\u03c8 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {n : M} {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c8 n) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (HAdd.hAdd.{max u3 u1, max u3 u1, max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (instHAdd.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Distrib.toHasAdd.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toDistrib.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))) \u03c6 \u03c8) n)\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u1, u3} \u03c3 R _inst_1} {\u03c8 : MvPolynomial.{u1, u3} \u03c3 R _inst_1} {n : M} {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w \u03c8 n) -> (MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w (HAdd.hAdd.{max u3 u1, max u3 u1, max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (instHAdd.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Distrib.toAdd.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toDistrib.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))))) \u03c6 \u03c8) n)\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous.add MvPolynomial.IsWeightedHomogeneous.add\u2093'. -/\n/-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\ntheorem add {w : \u03c3 \u2192 M} (h\u03c6 : IsWeightedHomogeneous w \u03c6 n) (h\u03c8 : IsWeightedHomogeneous w \u03c8 n) :\n    IsWeightedHomogeneous w (\u03c6 + \u03c8) n :=\n  (weightedHomogeneousSubmodule R w n).add_mem h\u03c6 h\u03c8\n#align mv_polynomial.is_weighted_homogeneous.add MvPolynomial.IsWeightedHomogeneous.add\n\n/- warning: mv_polynomial.is_weighted_homogeneous.sum -> MvPolynomial.IsWeightedHomogeneous.sum is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {\u03b9 : Type.{u4}} (s : Finset.{u4} \u03b9) (\u03c6 : \u03b9 -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (n : M) {w : \u03c3 -> M}, (forall (i : \u03b9), (Membership.Mem.{u4, u4} \u03b9 (Finset.{u4} \u03b9) (Finset.hasMem.{u4} \u03b9) i s) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (\u03c6 i) n)) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (Finset.sum.{max u3 u1, u4} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) \u03b9 (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) s (fun (i : \u03b9) => \u03c6 i)) n)\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] {\u03b9 : Type.{u4}} (s : Finset.{u4} \u03b9) (\u03c6 : \u03b9 -> (MvPolynomial.{u3, u2} \u03c3 R _inst_1)) (n : M) {w : \u03c3 -> M}, (forall (i : \u03b9), (Membership.mem.{u4, u4} \u03b9 (Finset.{u4} \u03b9) (Finset.instMembershipFinset.{u4} \u03b9) i s) -> (MvPolynomial.IsWeightedHomogeneous.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w (\u03c6 i) n)) -> (MvPolynomial.IsWeightedHomogeneous.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w (Finset.sum.{max u3 u2, u4} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03b9 (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) s (fun (i : \u03b9) => \u03c6 i)) n)\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous.sum MvPolynomial.IsWeightedHomogeneous.sum\u2093'. -/\n/-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\ntheorem sum {\u03b9 : Type _} (s : Finset \u03b9) (\u03c6 : \u03b9 \u2192 MvPolynomial \u03c3 R) (n : M) {w : \u03c3 \u2192 M}\n    (h : \u2200 i \u2208 s, IsWeightedHomogeneous w (\u03c6 i) n) : IsWeightedHomogeneous w (\u2211 i in s, \u03c6 i) n :=\n  (weightedHomogeneousSubmodule R w n).sum_mem h\n#align mv_polynomial.is_weighted_homogeneous.sum MvPolynomial.IsWeightedHomogeneous.sum\n\n/- warning: mv_polynomial.is_weighted_homogeneous.mul -> MvPolynomial.IsWeightedHomogeneous.mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {\u03c8 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {m : M} {n : M} {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c6 m) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c8 n) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (HMul.hMul.{max u3 u1, max u3 u1, max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (instHMul.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Distrib.toHasMul.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toDistrib.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))) \u03c6 \u03c8) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) m n))\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u1, u3} \u03c3 R _inst_1} {\u03c8 : MvPolynomial.{u1, u3} \u03c3 R _inst_1} {m : M} {n : M} {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w \u03c6 m) -> (MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w \u03c8 n) -> (MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w (HMul.hMul.{max u3 u1, max u3 u1, max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (instHMul.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMul.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1)))))) \u03c6 \u03c8) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) m n))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous.mul MvPolynomial.IsWeightedHomogeneous.mul\u2093'. -/\n/-- The product of weighted homogeneous polynomials of weighted degrees `m` and `n` is weighted\n  homogeneous of weighted degree `m + n`. -/\ntheorem mul {w : \u03c3 \u2192 M} (h\u03c6 : IsWeightedHomogeneous w \u03c6 m) (h\u03c8 : IsWeightedHomogeneous w \u03c8 n) :\n    IsWeightedHomogeneous w (\u03c6 * \u03c8) (m + n) :=\n  weightedHomogeneousSubmodule_mul w m n <| Submodule.mul_mem_mul h\u03c6 h\u03c8\n#align mv_polynomial.is_weighted_homogeneous.mul MvPolynomial.IsWeightedHomogeneous.mul\n\n/- warning: mv_polynomial.is_weighted_homogeneous.prod -> MvPolynomial.IsWeightedHomogeneous.prod is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {\u03b9 : Type.{u4}} (s : Finset.{u4} \u03b9) (\u03c6 : \u03b9 -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (n : \u03b9 -> M) {w : \u03c3 -> M}, (forall (i : \u03b9), (Membership.Mem.{u4, u4} \u03b9 (Finset.{u4} \u03b9) (Finset.hasMem.{u4} \u03b9) i s) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (\u03c6 i) (n i))) -> (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (Finset.prod.{max u3 u1, u4} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) \u03b9 (CommSemiring.toCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)) s (fun (i : \u03b9) => \u03c6 i)) (Finset.sum.{u2, u4} M \u03b9 _inst_2 s (fun (i : \u03b9) => n i)))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] {\u03b9 : Type.{u4}} (s : Finset.{u4} \u03b9) (\u03c6 : \u03b9 -> (MvPolynomial.{u3, u2} \u03c3 R _inst_1)) (n : \u03b9 -> M) {w : \u03c3 -> M}, (forall (i : \u03b9), (Membership.mem.{u4, u4} \u03b9 (Finset.{u4} \u03b9) (Finset.instMembershipFinset.{u4} \u03b9) i s) -> (MvPolynomial.IsWeightedHomogeneous.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w (\u03c6 i) (n i))) -> (MvPolynomial.IsWeightedHomogeneous.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w (Finset.prod.{max u3 u2, u4} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03b9 (CommSemiring.toCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)) s (fun (i : \u03b9) => \u03c6 i)) (Finset.sum.{u1, u4} M \u03b9 _inst_2 s (fun (i : \u03b9) => n i)))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous.prod MvPolynomial.IsWeightedHomogeneous.prod\u2093'. -/\n/-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree\n  equal to the sum of the weighted degrees. -/\ntheorem prod {\u03b9 : Type _} (s : Finset \u03b9) (\u03c6 : \u03b9 \u2192 MvPolynomial \u03c3 R) (n : \u03b9 \u2192 M) {w : \u03c3 \u2192 M} :\n    (\u2200 i \u2208 s, IsWeightedHomogeneous w (\u03c6 i) (n i)) \u2192\n      IsWeightedHomogeneous w (\u220f i in s, \u03c6 i) (\u2211 i in s, n i) :=\n  by\n  apply Finset.induction_on s\n  \u00b7 intro\n    simp only [is_weighted_homogeneous_one, Finset.sum_empty, Finset.prod_empty]\n  \u00b7 intro i s his IH h\n    simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff]\n    apply (h i (Finset.mem_insert_self _ _)).mul (IH _)\n    intro j hjs\n    exact h j (Finset.mem_insert_of_mem hjs)\n#align mv_polynomial.is_weighted_homogeneous.prod MvPolynomial.IsWeightedHomogeneous.prod\n\n/- warning: mv_polynomial.is_weighted_homogeneous.weighted_total_degree -> MvPolynomial.IsWeightedHomogeneous.weighted_total_degree is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1} {n : M} [_inst_3 : SemilatticeSup.{u2} M] {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (Ne.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) \u03c6 (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))))))))) -> (Eq.{succ u2} (WithBot.{u2} M) (MvPolynomial.weightedTotalDegree'.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 w \u03c6) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) M (WithBot.{u2} M) (HasLiftT.mk.{succ u2, succ u2} M (WithBot.{u2} M) (CoeTC\u2093.coe.{succ u2, succ u2} M (WithBot.{u2} M) (WithBot.hasCoeT.{u2} M))) n))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u3} M] {\u03c6 : MvPolynomial.{u1, u2} \u03c3 R _inst_1} {n : M} [_inst_3 : SemilatticeSup.{u3} M] {w : \u03c3 -> M}, (MvPolynomial.IsWeightedHomogeneous.{u2, u3, u1} R M _inst_1 \u03c3 _inst_2 w \u03c6 n) -> (Ne.{max (succ u2) (succ u1)} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6 (OfNat.ofNat.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))))) -> (Eq.{succ u3} (WithBot.{u3} M) (MvPolynomial.weightedTotalDegree'.{u2, u3, u1} R M _inst_1 \u03c3 _inst_2 _inst_3 w \u03c6) (WithBot.some.{u3} M n))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.is_weighted_homogeneous.weighted_total_degree MvPolynomial.IsWeightedHomogeneous.weighted_total_degree\u2093'. -/\n/-- A non zero weighted homogeneous polynomial of weighted degree `n` has weighted total degree\n  `n`. -/\ntheorem weighted_total_degree [SemilatticeSup M] {w : \u03c3 \u2192 M} (h\u03c6 : IsWeightedHomogeneous w \u03c6 n)\n    (h : \u03c6 \u2260 0) : weightedTotalDegree' w \u03c6 = n :=\n  by\n  simp only [weighted_total_degree']\n  apply le_antisymm\n  \u00b7 simp only [Finset.sup_le_iff, mem_support_iff, WithBot.coe_le_coe]\n    exact fun d hd => le_of_eq (h\u03c6 hd)\n  \u00b7 obtain \u27e8d, hd\u27e9 : \u2203 d, coeff d \u03c6 \u2260 0 := exists_coeff_ne_zero h\n    simp only [\u2190 h\u03c6 hd, Finsupp.sum]\n    replace hd := finsupp.mem_support_iff.mpr hd\n    exact Finset.le_sup hd\n#align mv_polynomial.is_weighted_homogeneous.weighted_total_degree MvPolynomial.IsWeightedHomogeneous.weighted_total_degree\n\n#print MvPolynomial.IsWeightedHomogeneous.WeightedHomogeneousSubmodule.gcomm_monoid /-\n/-- The weighted homogeneous submodules form a graded monoid. -/\ninstance WeightedHomogeneousSubmodule.gcomm_monoid {w : \u03c3 \u2192 M} :\n    SetLike.GradedMonoid (weightedHomogeneousSubmodule R w)\n    where\n  one_mem := isWeightedHomogeneous_one R w\n  mul_mem i j xi xj := IsWeightedHomogeneous.mul\n#align mv_polynomial.is_weighted_homogeneous.weighted_homogeneous_submodule.gcomm_monoid MvPolynomial.IsWeightedHomogeneous.WeightedHomogeneousSubmodule.gcomm_monoid\n-/\n\nend IsWeightedHomogeneous\n\nvariable {R}\n\n#print MvPolynomial.weightedHomogeneousComponent /-\n/-- `weighted_homogeneous_component w n \u03c6` is the part of `\u03c6` that is weighted homogeneous of\n  weighted degree `n`, with respect to the weights `w`.\n  See `sum_weighted_homogeneous_component` for the statement that `\u03c6` is equal to the sum\n  of all its weighted homogeneous components. -/\ndef weightedHomogeneousComponent (w : \u03c3 \u2192 M) (n : M) : MvPolynomial \u03c3 R \u2192\u2097[R] MvPolynomial \u03c3 R :=\n  (Submodule.subtype _).comp <| Finsupp.restrictDom _ _ { d | weightedDegree' w d = n }\n#align mv_polynomial.weighted_homogeneous_component MvPolynomial.weightedHomogeneousComponent\n-/\n\nsection WeightedHomogeneousComponent\n\nvariable {w : \u03c3 \u2192 M} (n : M) (\u03c6 \u03c8 : MvPolynomial \u03c3 R)\n\n/- warning: mv_polynomial.coeff_weighted_homogeneous_component -> MvPolynomial.coeff_weightedHomogeneousComponent is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1) (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero), Eq.{succ u1} R (MvPolynomial.coeff.{u1, u3} R \u03c3 _inst_1 d (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6)) (ite.{succ u1} R (Eq.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) n) (Classical.propDecidable (Eq.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) n)) (MvPolynomial.coeff.{u1, u3} R \u03c3 _inst_1 d \u03c6) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))))))))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) (d : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)), Eq.{succ u2} R (MvPolynomial.coeff.{u2, u3} R \u03c3 _inst_1 d (FunLike.coe.{max (succ u3) (succ u2), max (succ u3) (succ u2), max (succ u3) (succ u2)} (LinearMap.{u2, u2, max u2 u3, max u2 u3} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u3 u2, max u3 u2} R R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6)) (ite.{succ u2} R (Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u1) (succ u3), succ u3, succ u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))))) (MvPolynomial.weightedDegree'.{u1, u3} M \u03c3 _inst_2 w) d) n) (Classical.propDecidable (Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u1) (succ u3), succ u3, succ u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))))) (MvPolynomial.weightedDegree'.{u1, u3} M \u03c3 _inst_2 w) d) n)) (MvPolynomial.coeff.{u2, u3} R \u03c3 _inst_1 d \u03c6) (OfNat.ofNat.{u2} R 0 (Zero.toOfNat0.{u2} R (CommMonoidWithZero.toZero.{u2} R (CommSemiring.toCommMonoidWithZero.{u2} R _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.coeff_weighted_homogeneous_component MvPolynomial.coeff_weightedHomogeneousComponent\u2093'. -/\ntheorem coeff_weightedHomogeneousComponent (d : \u03c3 \u2192\u2080 \u2115) :\n    coeff d (weightedHomogeneousComponent w n \u03c6) =\n      if weightedDegree' w d = n then coeff d \u03c6 else 0 :=\n  Finsupp.filter_apply (fun d : \u03c3 \u2192\u2080 \u2115 => weightedDegree' w d = n) \u03c6 d\n#align mv_polynomial.coeff_weighted_homogeneous_component MvPolynomial.coeff_weightedHomogeneousComponent\n\n/- warning: mv_polynomial.weighted_homogeneous_component_apply -> MvPolynomial.weightedHomogeneousComponent_apply is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1), Eq.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) (Finset.sum.{max u3 u1, u3} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Finset.filter.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) (fun (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) => Eq.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) n) (fun (a : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) => Classical.propDecidable ((fun (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) => Eq.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) n) a)) (MvPolynomial.support.{u1, u3} R \u03c3 _inst_1 \u03c6)) (fun (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) => coeFn.{max (succ u1) (succ (max u3 u1)), max (succ u1) (succ (max u3 u1))} (LinearMap.{u1, u1, u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => R -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, u1, max u3 u1} R R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.monomial.{u1, u3} R \u03c3 _inst_1 d) (MvPolynomial.coeff.{u1, u3} R \u03c3 _inst_1 d \u03c6)))\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u2}} [_inst_2 : AddCommMonoid.{u1} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u2, u3} \u03c3 R _inst_1), Eq.{max (succ u3) (succ u2)} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6) (FunLike.coe.{max (succ u2) (succ u3), max (succ u2) (succ u3), max (succ u2) (succ u3)} (LinearMap.{u3, u3, max u3 u2, max u3 u2} R R (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u3, u3, max u2 u3, max u2 u3} R R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) (Finset.sum.{max u3 u2, u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (Finset.filter.{u2} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (d : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u1 u2, u2, u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u2} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u1 u2, u2, u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))))) (MvPolynomial.weightedDegree'.{u1, u2} M \u03c3 _inst_2 w) d) n) (fun (a : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => Classical.propDecidable ((fun (d : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => Eq.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u1 u2, u2, u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u2} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u1 u2, u2, u1} (AddMonoidHom.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u2, u1} (Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u2, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))))) (MvPolynomial.weightedDegree'.{u1, u2} M \u03c3 _inst_2 w) d) n) a)) (MvPolynomial.support.{u3, u2} R \u03c3 _inst_1 \u03c6)) (fun (d : Finsupp.{u2, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => FunLike.coe.{max (succ u2) (succ u3), succ u3, max (succ u2) (succ u3)} (LinearMap.{u3, u3, u3, max u3 u2} R R (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : R) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u3, u3, u3, max u2 u3} R R R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.monomial.{u3, u2} R \u03c3 _inst_1 d) (MvPolynomial.coeff.{u3, u2} R \u03c3 _inst_1 d \u03c6)))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_apply MvPolynomial.weightedHomogeneousComponent_apply\u2093'. -/\ntheorem weightedHomogeneousComponent_apply :\n    weightedHomogeneousComponent w n \u03c6 =\n      \u2211 d in \u03c6.support.filter\u2093 fun d => weightedDegree' w d = n, monomial d (coeff d \u03c6) :=\n  Finsupp.filter_eq_sum (fun d : \u03c3 \u2192\u2080 \u2115 => weightedDegree' w d = n) \u03c6\n#align mv_polynomial.weighted_homogeneous_component_apply MvPolynomial.weightedHomogeneousComponent_apply\n\n/- warning: mv_polynomial.weighted_homogeneous_component_is_weighted_homogeneous -> MvPolynomial.weightedHomogeneousComponent_isWeightedHomogeneous is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1), MvPolynomial.IsWeightedHomogeneous.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) n\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u1, u3} \u03c3 R _inst_1), MvPolynomial.IsWeightedHomogeneous.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w (FunLike.coe.{max (succ u1) (succ u3), max (succ u1) (succ u3), max (succ u1) (succ u3)} (LinearMap.{u3, u3, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u1} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.module.{u3, u3, u1} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u1, u3} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u3} \u03c3 R _inst_1) => MvPolynomial.{u1, u3} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u3, u3, max u1 u3, max u1 u3} R R (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u1, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u1} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.module.{u3, u3, u1} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u3, u2, u1} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) n\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_is_weighted_homogeneous MvPolynomial.weightedHomogeneousComponent_isWeightedHomogeneous\u2093'. -/\n/-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of\nweighted degree `n`. -/\ntheorem weightedHomogeneousComponent_isWeightedHomogeneous :\n    (weightedHomogeneousComponent w n \u03c6).IsWeightedHomogeneous w n :=\n  by\n  intro d hd\n  contrapose! hd\n  rw [coeff_weighted_homogeneous_component, if_neg hd]\n#align mv_polynomial.weighted_homogeneous_component_is_weighted_homogeneous MvPolynomial.weightedHomogeneousComponent_isWeightedHomogeneous\n\n/- warning: mv_polynomial.weighted_homogeneous_component_C_mul -> MvPolynomial.weightedHomogeneousComponent_C_mul is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1) (n : M) (r : R), Eq.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n) (HMul.hMul.{max u3 u1, max u3 u1, max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (instHMul.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Distrib.toHasMul.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toDistrib.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))) (coeFn.{max (succ u1) (succ (max u3 u1)), max (succ u1) (succ (max u3 u1))} (RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (fun (_x : RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) => R -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (RingHom.hasCoeToFun.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (MvPolynomial.C.{u1, u3} R \u03c3 _inst_1) r) \u03c6)) (HMul.hMul.{max u3 u1, max u3 u1, max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (instHMul.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Distrib.toHasMul.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toDistrib.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))) (coeFn.{max (succ u1) (succ (max u3 u1)), max (succ u1) (succ (max u3 u1))} (RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (fun (_x : RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) => R -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (RingHom.hasCoeToFun.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (MvPolynomial.C.{u1, u3} R \u03c3 _inst_1) r) (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] {w : \u03c3 -> M} (\u03c6 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) (n : M) (r : R), Eq.{max (succ u3) (succ u2)} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) (HMul.hMul.{max u2 u3, max u2 u3, max u3 u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (instHMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonUnitalNonAssocSemiring.toMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (Semiring.toNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (CommSemiring.toSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))))) (FunLike.coe.{max (succ u3) (succ u2), succ u2, max (succ u3) (succ u2)} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (fun (a : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) a) (MulHomClass.toFunLike.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (NonUnitalNonAssocSemiring.toMul.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalRingHomClass.toMulHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) (RingHomClass.toNonUnitalRingHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))) (RingHom.instRingHomClassRingHom.{u2, max u3 u2} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))))) (MvPolynomial.C.{u2, u3} R \u03c3 _inst_1) r) \u03c6)) (FunLike.coe.{max (succ u3) (succ u2), max (succ u3) (succ u2), max (succ u3) (succ u2)} (LinearMap.{u2, u2, max u2 u3, max u2 u3} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u3 u2, max u3 u2} R R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w n) (HMul.hMul.{max u2 u3, max u2 u3, max u3 u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (instHMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonUnitalNonAssocSemiring.toMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (Semiring.toNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (CommSemiring.toSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))))) (FunLike.coe.{max (succ u3) (succ u2), succ u2, max (succ u3) (succ u2)} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) _x) (MulHomClass.toFunLike.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (NonUnitalNonAssocSemiring.toMul.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalRingHomClass.toMulHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) (RingHomClass.toNonUnitalRingHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))) (RingHom.instRingHomClassRingHom.{u2, max u3 u2} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))))) (MvPolynomial.C.{u2, u3} R \u03c3 _inst_1) r) \u03c6)) (HMul.hMul.{max u2 u3, max u2 u3, max u3 u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03c6) ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) (HMul.hMul.{max u2 u3, max u2 u3, max u3 u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (instHMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonUnitalNonAssocSemiring.toMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (Semiring.toNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (CommSemiring.toSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))))) (FunLike.coe.{max (succ u3) (succ u2), succ u2, max (succ u3) (succ u2)} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (fun (a : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) a) (MulHomClass.toFunLike.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (NonUnitalNonAssocSemiring.toMul.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalRingHomClass.toMulHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) (RingHomClass.toNonUnitalRingHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))) (RingHom.instRingHomClassRingHom.{u2, max u3 u2} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))))) (MvPolynomial.C.{u2, u3} R \u03c3 _inst_1) r) \u03c6)) (instHMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonUnitalNonAssocSemiring.toMul.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (Semiring.toNonAssocSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (CommSemiring.toSemiring.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) r) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))))) (FunLike.coe.{max (succ u3) (succ u2), succ u2, max (succ u3) (succ u2)} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) _x) (MulHomClass.toFunLike.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (NonUnitalNonAssocSemiring.toMul.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalRingHomClass.toMulHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) (RingHomClass.toNonUnitalRingHomClass.{max u3 u2, u2, max u3 u2} (RingHom.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))) R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))) (RingHom.instRingHomClassRingHom.{u2, max u3 u2} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))))) (MvPolynomial.C.{u2, u3} R \u03c3 _inst_1) r) (FunLike.coe.{max (succ u3) (succ u2), max (succ u3) (succ u2), max (succ u3) (succ u2)} (LinearMap.{u2, u2, max u2 u3, max u2 u3} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u3 u2, max u3 u2} R R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_C_mul MvPolynomial.weightedHomogeneousComponent_C_mul\u2093'. -/\n@[simp]\ntheorem weightedHomogeneousComponent_C_mul (n : M) (r : R) :\n    weightedHomogeneousComponent w n (C r * \u03c6) = C r * weightedHomogeneousComponent w n \u03c6 := by\n  simp only [C_mul', LinearMap.map_smul]\n#align mv_polynomial.weighted_homogeneous_component_C_mul MvPolynomial.weightedHomogeneousComponent_C_mul\n\n/- warning: mv_polynomial.weighted_homogeneous_component_eq_zero' -> MvPolynomial.weightedHomogeneousComponent_eq_zero' is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1), (forall (d : Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero), (Membership.Mem.{u3, u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) (Finset.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero)) (Finset.hasMem.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero)) d (MvPolynomial.support.{u1, u3} R \u03c3 _inst_1 \u03c6)) -> (Ne.{succ u2} M (coeFn.{max (succ u2) (succ u3), max (succ u3) (succ u2)} (AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (fun (_x : AddMonoidHom.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) => (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) -> M) (AddMonoidHom.hasCoeToFun.{u3, u2} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MvPolynomial.weightedDegree'.{u2, u3} M \u03c3 _inst_2 w) d) n)) -> (Eq.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))))))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u3, u2} \u03c3 R _inst_1), (forall (d : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)), (Membership.mem.{u3, u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finset.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero))) (Finset.instMembershipFinset.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero))) d (MvPolynomial.support.{u2, u3} R \u03c3 _inst_1 \u03c6)) -> (Ne.{succ u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) d) (FunLike.coe.{max (succ u1) (succ u3), succ u3, succ u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (fun (_x : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) => M) _x) (AddHomClass.toFunLike.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (AddZeroClass.toAdd.{u3} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid))) (AddZeroClass.toAdd.{u1} M (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (AddMonoidHomClass.toAddHomClass.{max u1 u3, u3, u1} (AddMonoidHom.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))) (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2)) (AddMonoidHom.addMonoidHomClass.{u3, u1} (Finsupp.{u3, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) M (Finsupp.addZeroClass.{u3, 0} \u03c3 Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoid.toAddZeroClass.{u1} M (AddCommMonoid.toAddMonoid.{u1} M _inst_2))))) (MvPolynomial.weightedDegree'.{u1, u3} M \u03c3 _inst_2 w) d) n)) -> (Eq.{max (succ u2) (succ u3)} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03c6) (FunLike.coe.{max (succ u3) (succ u2), max (succ u3) (succ u2), max (succ u3) (succ u2)} (LinearMap.{u2, u2, max u2 u3, max u2 u3} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u3 u2, max u3 u2} R R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) (OfNat.ofNat.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03c6) 0 (Zero.toOfNat0.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03c6) (CommMonoidWithZero.toZero.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03c6) (CommSemiring.toCommMonoidWithZero.{max u2 u3} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) \u03c6) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_eq_zero' MvPolynomial.weightedHomogeneousComponent_eq_zero'\u2093'. -/\ntheorem weightedHomogeneousComponent_eq_zero'\n    (h : \u2200 d : \u03c3 \u2192\u2080 \u2115, d \u2208 \u03c6.support \u2192 weightedDegree' w d \u2260 n) :\n    weightedHomogeneousComponent w n \u03c6 = 0 :=\n  by\n  rw [weighted_homogeneous_component_apply, sum_eq_zero]\n  intro d hd; rw [mem_filter] at hd\n  exfalso; exact h _ hd.1 hd.2\n#align mv_polynomial.weighted_homogeneous_component_eq_zero' MvPolynomial.weightedHomogeneousComponent_eq_zero'\n\n/- warning: mv_polynomial.weighted_homogeneous_component_eq_zero -> MvPolynomial.weightedHomogeneousComponent_eq_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1) [_inst_3 : SemilatticeSup.{u2} M] [_inst_4 : OrderBot.{u2} M (Preorder.toLE.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3)))], (LT.lt.{u2} M (Preorder.toLT.{u2} M (PartialOrder.toPreorder.{u2} M (SemilatticeSup.toPartialOrder.{u2} M _inst_3))) (MvPolynomial.weightedTotalDegree.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w \u03c6) n) -> (Eq.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))))))))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u3} M] {w : \u03c3 -> M} (n : M) (\u03c6 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) [_inst_3 : SemilatticeSup.{u3} M] [_inst_4 : OrderBot.{u3} M (Preorder.toLE.{u3} M (PartialOrder.toPreorder.{u3} M (SemilatticeSup.toPartialOrder.{u3} M _inst_3)))], (LT.lt.{u3} M (Preorder.toLT.{u3} M (PartialOrder.toPreorder.{u3} M (SemilatticeSup.toPartialOrder.{u3} M _inst_3))) (MvPolynomial.weightedTotalDegree.{u2, u3, u1} R M _inst_1 \u03c3 _inst_2 _inst_3 _inst_4 w \u03c6) n) -> (Eq.{max (succ u2) (succ u1)} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (LinearMap.{u2, u2, max u2 u1, max u2 u1} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u1 u2, max u1 u2} R R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u3, u1} R M _inst_1 \u03c3 _inst_2 w n) \u03c6) (OfNat.ofNat.{max u2 u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) 0 (Zero.toOfNat0.{max u2 u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (CommMonoidWithZero.toZero.{max u2 u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (CommSemiring.toCommMonoidWithZero.{max u2 u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_eq_zero MvPolynomial.weightedHomogeneousComponent_eq_zero\u2093'. -/\ntheorem weightedHomogeneousComponent_eq_zero [SemilatticeSup M] [OrderBot M]\n    (h : weightedTotalDegree w \u03c6 < n) : weightedHomogeneousComponent w n \u03c6 = 0 :=\n  by\n  rw [weighted_homogeneous_component_apply, sum_eq_zero]\n  intro d hd; rw [mem_filter] at hd\n  exfalso\n  apply lt_irrefl n\n  nth_rw 1 [\u2190 hd.2]\n  exact lt_of_le_of_lt (le_weighted_total_degree w hd.1) h\n#align mv_polynomial.weighted_homogeneous_component_eq_zero MvPolynomial.weightedHomogeneousComponent_eq_zero\n\n/- warning: mv_polynomial.weighted_homogeneous_component_finsupp -> MvPolynomial.weightedHomogeneousComponent_finsupp is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1), Set.Finite.{u2} M (Function.support.{u2, max u3 u1} M (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))))) (fun (m : M) => coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w m) \u03c6))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u1}} [_inst_2 : AddCommMonoid.{u3} M] {w : \u03c3 -> M} (\u03c6 : MvPolynomial.{u1, u2} \u03c3 R _inst_1), Set.Finite.{u3} M (Function.support.{u3, max u2 u1} M ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (CommMonoidWithZero.toZero.{max u2 u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (CommSemiring.toCommMonoidWithZero.{max u2 u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))) (fun (m : M) => FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (LinearMap.{u2, u2, max u2 u1, max u2 u1} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u1 u2, max u1 u2} R R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u3, u1} R M _inst_1 \u03c3 _inst_2 w m) \u03c6))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_finsupp MvPolynomial.weightedHomogeneousComponent_finsupp\u2093'. -/\ntheorem weightedHomogeneousComponent_finsupp :\n    (Function.support fun m => weightedHomogeneousComponent w m \u03c6).Finite :=\n  by\n  suffices\n    (Function.support fun m => weighted_homogeneous_component w m \u03c6) \u2286\n      (fun d => weighted_degree' w d) '' \u03c6.support\n    by\n    exact finite.subset ((fun d : \u03c3 \u2192\u2080 \u2115 => (weighted_degree' w) d) '' \u2191(support \u03c6)).toFinite this\n  intro m hm\n  by_contra hm'\n  apply hm\n  simp only [mem_support, Ne.def] at hm\n  simp only [Set.mem_image, not_exists, not_and] at hm'\n  exact weighted_homogeneous_component_eq_zero' m \u03c6 hm'\n#align mv_polynomial.weighted_homogeneous_component_finsupp MvPolynomial.weightedHomogeneousComponent_finsupp\n\nvariable (w)\n\n/- warning: mv_polynomial.sum_weighted_homogeneous_component -> MvPolynomial.sum_weightedHomogeneousComponent is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] (w : \u03c3 -> M) (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1), Eq.{succ (max u3 u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (finsum.{max u3 u1, succ u2} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) M (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (fun (m : M) => coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w m) \u03c6)) \u03c6\nbut is expected to have type\n  forall {R : Type.{u3}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u3} R] {\u03c3 : Type.{u2}} [_inst_2 : AddCommMonoid.{u1} M] (w : \u03c3 -> M) (\u03c6 : MvPolynomial.{u2, u3} \u03c3 R _inst_1), Eq.{max (succ u3) (succ u2)} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6) (finsum.{max u3 u2, succ u1} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6) M (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6) (Semiring.toNonAssocSemiring.{max u3 u2} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6) (CommSemiring.toSemiring.{max u3 u2} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) \u03c6) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (fun (m : M) => FunLike.coe.{max (succ u2) (succ u3), max (succ u2) (succ u3), max (succ u2) (succ u3)} (LinearMap.{u3, u3, max u3 u2, max u3 u2} R R (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u2, u3} \u03c3 R _inst_1) => MvPolynomial.{u2, u3} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u3, u3, max u2 u3, max u2 u3} R R (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (CommSemiring.toSemiring.{u3} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u2} (MvPolynomial.{u2, u3} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u3, u2} R \u03c3 _inst_1))))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (MvPolynomial.module.{u3, u3, u2} R R \u03c3 (CommSemiring.toSemiring.{u3} R _inst_1) _inst_1 (Semiring.toModule.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1))) (RingHom.id.{u3} R (Semiring.toNonAssocSemiring.{u3} R (CommSemiring.toSemiring.{u3} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u3, u1, u2} R M _inst_1 \u03c3 _inst_2 w m) \u03c6)) \u03c6\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.sum_weighted_homogeneous_component MvPolynomial.sum_weightedHomogeneousComponent\u2093'. -/\n/-- Every polynomial is the sum of its weighted homogeneous components. -/\ntheorem sum_weightedHomogeneousComponent :\n    (finsum fun m => weightedHomogeneousComponent w m \u03c6) = \u03c6 :=\n  by\n  rw [finsum_eq_sum _ (weighted_homogeneous_component_finsupp \u03c6)]\n  ext1 d\n  simp only [coeff_sum, coeff_weighted_homogeneous_component]\n  rw [Finset.sum_eq_single (weighted_degree' w d)]\n  \u00b7 rw [if_pos rfl]\n  \u00b7 intro m hm hm'\n    rw [if_neg hm'.symm]\n  \u00b7 intro hm\n    rw [if_pos rfl]\n    simp only [finite.mem_to_finset, mem_support, Ne.def, Classical.not_not] at hm\n    have := coeff_weighted_homogeneous_component _ \u03c6 d\n    rw [hm, if_pos rfl, coeff_zero] at this\n    exact this.symm\n#align mv_polynomial.sum_weighted_homogeneous_component MvPolynomial.sum_weightedHomogeneousComponent\n\nvariable {w}\n\n/- warning: mv_polynomial.weighted_homogeneous_component_weighted_homogeneous_polynomial -> MvPolynomial.weightedHomogeneousComponent_weighted_homogeneous_polynomial is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u2} M] {w : \u03c3 -> M} (m : M) (n : M) (p : MvPolynomial.{u3, u1} \u03c3 R _inst_1), (Membership.Mem.{max u3 u1, max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (SetLike.hasMem.{max u3 u1, max u3 u1} (Submodule.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Submodule.setLike.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))))) p (MvPolynomial.weightedHomogeneousSubmodule.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w n)) -> (Eq.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 _inst_2 w m) p) (ite.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Eq.{succ u2} M m n) (Classical.propDecidable (Eq.{succ u2} M m n)) p (OfNat.ofNat.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (OfNat.mk.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) 0 (Zero.zero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MulZeroClass.toHasZero.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMulZeroClass.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))))))))))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u1}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u3}} [_inst_2 : AddCommMonoid.{u1} M] {w : \u03c3 -> M} (m : M) (n : M) (p : MvPolynomial.{u3, u2} \u03c3 R _inst_1), (Membership.mem.{max u2 u3, max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Submodule.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (SetLike.instMembership.{max u2 u3, max u2 u3} (Submodule.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Submodule.setLike.{u2, max u2 u3} R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))))) p (MvPolynomial.weightedHomogeneousSubmodule.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w n)) -> (Eq.{max (succ u2) (succ u3)} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) p) (FunLike.coe.{max (succ u3) (succ u2), max (succ u3) (succ u2), max (succ u3) (succ u2)} (LinearMap.{u2, u2, max u2 u3, max u2 u3} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u3, u2} \u03c3 R _inst_1) => MvPolynomial.{u3, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u3 u2, max u3 u2} R R (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u3} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u1, u3} R M _inst_1 \u03c3 _inst_2 w m) p) (ite.{max (succ u2) (succ u3)} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (Eq.{succ u1} M m n) (Classical.propDecidable (Eq.{succ u1} M m n)) p (OfNat.ofNat.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) 0 (Zero.toOfNat0.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommMonoidWithZero.toZero.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (CommSemiring.toCommMonoidWithZero.{max u2 u3} (MvPolynomial.{u3, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u3} R \u03c3 _inst_1)))))))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_weighted_homogeneous_polynomial MvPolynomial.weightedHomogeneousComponent_weighted_homogeneous_polynomial\u2093'. -/\n/-- The weighted homogeneous components of a weighted homogeneous polynomial. -/\ntheorem weightedHomogeneousComponent_weighted_homogeneous_polynomial (m n : M)\n    (p : MvPolynomial \u03c3 R) (h : p \u2208 weightedHomogeneousSubmodule R w n) :\n    weightedHomogeneousComponent w m p = if m = n then p else 0 :=\n  by\n  simp only [mem_weighted_homogeneous_submodule] at h\n  ext x\n  rw [coeff_weighted_homogeneous_component]\n  by_cases zero_coeff : coeff x p = 0\n  \u00b7 split_ifs\n    all_goals simp only [zero_coeff, coeff_zero]\n  \u00b7 rw [h zero_coeff]\n    simp only [show n = m \u2194 m = n from eq_comm]\n    split_ifs with h1\n    \u00b7 rfl\n    \u00b7 simp only [coeff_zero]\n#align mv_polynomial.weighted_homogeneous_component_weighted_homogeneous_polynomial MvPolynomial.weightedHomogeneousComponent_weighted_homogeneous_polynomial\n\nend WeightedHomogeneousComponent\n\nend AddCommMonoid\n\nsection CanonicallyOrderedAddMonoid\n\nvariable [CanonicallyOrderedAddMonoid M] {w : \u03c3 \u2192 M} (\u03c6 : MvPolynomial \u03c3 R)\n\n/- warning: mv_polynomial.weighted_homogeneous_component_zero -> MvPolynomial.weightedHomogeneousComponent_zero is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : CommSemiring.{u1} R] {\u03c3 : Type.{u3}} [_inst_2 : CanonicallyOrderedAddMonoid.{u2} M] {w : \u03c3 -> M} (\u03c6 : MvPolynomial.{u3, u1} \u03c3 R _inst_1) [_inst_3 : NoZeroSMulDivisors.{0, u2} Nat M Nat.hasZero (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (OrderedAddCommMonoid.toAddCommMonoid.{u2} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u2} M _inst_2))))) (AddMonoid.SMul.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (OrderedAddCommMonoid.toAddCommMonoid.{u2} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u2} M _inst_2))))], (forall (i : \u03c3), Ne.{succ u2} M (w i) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (OrderedAddCommMonoid.toAddCommMonoid.{u2} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u2} M _inst_2))))))))) -> (Eq.{max (succ u3) (succ u1)} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (coeFn.{succ (max u3 u1), succ (max u3 u1)} (LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (fun (_x : LinearMap.{u1, u1, max u3 u1, max u3 u1} R R (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) => (MvPolynomial.{u3, u1} \u03c3 R _inst_1) -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (LinearMap.hasCoeToFun.{u1, u1, max u3 u1, max u3 u1} R R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (CommSemiring.toSemiring.{u1} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1))))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (MvPolynomial.module.{u1, u1, u3} R R \u03c3 (CommSemiring.toSemiring.{u1} R _inst_1) _inst_1 (Semiring.toModule.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1))) (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u1, u2, u3} R M _inst_1 \u03c3 (OrderedAddCommMonoid.toAddCommMonoid.{u2} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u2} M _inst_2)) w (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (OrderedAddCommMonoid.toAddCommMonoid.{u2} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u2} M _inst_2))))))))) \u03c6) (coeFn.{max (succ u1) (succ (max u3 u1)), max (succ u1) (succ (max u3 u1))} (RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (fun (_x : RingHom.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) => R -> (MvPolynomial.{u3, u1} \u03c3 R _inst_1)) (RingHom.hasCoeToFun.{u1, max u3 u1} R (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u1} R (CommSemiring.toSemiring.{u1} R _inst_1)) (Semiring.toNonAssocSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u3 u1} (MvPolynomial.{u3, u1} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u1, u3} R \u03c3 _inst_1)))) (MvPolynomial.C.{u1, u3} R \u03c3 _inst_1) (MvPolynomial.coeff.{u1, u3} R \u03c3 _inst_1 (OfNat.ofNat.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) 0 (OfNat.mk.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) 0 (Zero.zero.{u3} (Finsupp.{u3, 0} \u03c3 Nat Nat.hasZero) (Finsupp.zero.{u3, 0} \u03c3 Nat Nat.hasZero)))) \u03c6)))\nbut is expected to have type\n  forall {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : CommSemiring.{u2} R] {\u03c3 : Type.{u1}} [_inst_2 : CanonicallyOrderedAddMonoid.{u3} M] {w : \u03c3 -> M} (\u03c6 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) [_inst_3 : NoZeroSMulDivisors.{0, u3} Nat M (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (OrderedAddCommMonoid.toAddCommMonoid.{u3} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u3} M _inst_2)))) (AddMonoid.SMul.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (OrderedAddCommMonoid.toAddCommMonoid.{u3} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u3} M _inst_2))))], (forall (i : \u03c3), Ne.{succ u3} M (w i) (OfNat.ofNat.{u3} M 0 (Zero.toOfNat0.{u3} M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (OrderedAddCommMonoid.toAddCommMonoid.{u3} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u3} M _inst_2))))))) -> (Eq.{max (succ u2) (succ u1)} ((fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) \u03c6) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (LinearMap.{u2, u2, max u2 u1, max u2 u1} R R (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (fun (_x : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => (fun (x._@.Mathlib.Algebra.Module.LinearMap._hyg.6190 : MvPolynomial.{u1, u2} \u03c3 R _inst_1) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, max u1 u2, max u1 u2} R R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (CommSemiring.toSemiring.{u2} R _inst_1) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (MvPolynomial.module.{u2, u2, u1} R R \u03c3 (CommSemiring.toSemiring.{u2} R _inst_1) _inst_1 (Semiring.toModule.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (MvPolynomial.weightedHomogeneousComponent.{u2, u3, u1} R M _inst_1 \u03c3 (OrderedAddCommMonoid.toAddCommMonoid.{u3} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u3} M _inst_2)) w (OfNat.ofNat.{u3} M 0 (Zero.toOfNat0.{u3} M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M (OrderedAddCommMonoid.toAddCommMonoid.{u3} M (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u3} M _inst_2))))))) \u03c6) (FunLike.coe.{max (succ u1) (succ u2), succ u2, max (succ u1) (succ u2)} (RingHom.{u2, max u2 u1} R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))) R (fun (_x : R) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : R) => MvPolynomial.{u1, u2} \u03c3 R _inst_1) _x) (MulHomClass.toFunLike.{max u1 u2, u2, max u1 u2} (RingHom.{u2, max u2 u1} R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))) R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonUnitalNonAssocSemiring.toMul.{u2} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)))) (NonUnitalNonAssocSemiring.toMul.{max u1 u2} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u1 u2} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))) (NonUnitalRingHomClass.toMulHomClass.{max u1 u2, u2, max u1 u2} (RingHom.{u2, max u2 u1} R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))) R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} R (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{max u1 u2} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))) (RingHomClass.toNonUnitalRingHomClass.{max u1 u2, u2, max u1 u2} (RingHom.{u2, max u2 u1} R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1)))) R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))) (RingHom.instRingHomClassRingHom.{u2, max u1 u2} R (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (Semiring.toNonAssocSemiring.{u2} R (CommSemiring.toSemiring.{u2} R _inst_1)) (Semiring.toNonAssocSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (CommSemiring.toSemiring.{max u2 u1} (MvPolynomial.{u1, u2} \u03c3 R _inst_1) (MvPolynomial.commSemiring.{u2, u1} R \u03c3 _inst_1))))))) (MvPolynomial.C.{u2, u1} R \u03c3 _inst_1) (MvPolynomial.coeff.{u2, u1} R \u03c3 _inst_1 (OfNat.ofNat.{u1} (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) 0 (Zero.toOfNat0.{u1} (Finsupp.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)) (Finsupp.zero.{u1, 0} \u03c3 Nat (LinearOrderedCommMonoidWithZero.toZero.{0} Nat Nat.linearOrderedCommMonoidWithZero)))) \u03c6)))\nCase conversion may be inaccurate. Consider using '#align mv_polynomial.weighted_homogeneous_component_zero MvPolynomial.weightedHomogeneousComponent_zero\u2093'. -/\n/-- If `M` is a `canonically_ordered_add_monoid`, then the `weighted_homogeneous_component`\n  of weighted degree `0` of a polynomial is its constant coefficient. -/\n@[simp]\ntheorem weightedHomogeneousComponent_zero [NoZeroSMulDivisors \u2115 M] (hw : \u2200 i : \u03c3, w i \u2260 0) :\n    weightedHomogeneousComponent w 0 \u03c6 = C (coeff 0 \u03c6) :=\n  by\n  ext1 d\n  rcases em (d = 0) with (rfl | hd)\n  \u00b7 simp only [coeff_weighted_homogeneous_component, if_pos, map_zero, coeff_zero_C]\n  \u00b7 rw [coeff_weighted_homogeneous_component, if_neg, coeff_C, if_neg (Ne.symm hd)]\n    simp only [weighted_degree', LinearMap.toAddMonoidHom_coe, Finsupp.total_apply, Finsupp.sum,\n      sum_eq_zero_iff, Finsupp.mem_support_iff, Ne.def, smul_eq_zero, not_forall, not_or,\n      and_self_left, exists_prop]\n    simp only [Finsupp.ext_iff, Finsupp.coe_zero, Pi.zero_apply, not_forall] at hd\n    obtain \u27e8i, hi\u27e9 := hd\n    exact \u27e8i, hi, hw i\u27e9\n#align mv_polynomial.weighted_homogeneous_component_zero MvPolynomial.weightedHomogeneousComponent_zero\n\nend CanonicallyOrderedAddMonoid\n\nend MvPolynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RingTheory/MvPolynomial/WeightedHomogeneous.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7097209923253561}}
{"text": "import data.nat.basic\nopen nat\n\n\nprivate lemma induction_strong_version (P : \u2115 \u2192 Prop) (n : \u2115) : \n  (\u2200 x : \u2115, (\u2200 y : \u2115, y < x \u2192 (P y)) \u2192 (P x))  \u2192  (\u2200 z : \u2115, z < n \u2192 (P z))  :=\nbegin\n  intro ass,\n  induction n with m ih,\n\n    -- base case --\n    intros z z_neg,\n    exfalso,\n    exact nat.not_lt_zero z z_neg,\n\n    -- induction step --\n    intros z z_le_m,\n    rw lt_succ_iff at z_le_m,\n    cases eq_or_lt_of_le z_le_m with z_eq_m z_lt_m,\n\n      -- case of z = m\n      specialize ass m,\n      rw z_eq_m,\n      exact ass ih,\n\n      -- case of z < m\n      exact ih z z_lt_m,\nend\n\n\ntheorem induction_complete (P : \u2115 \u2192 Prop) : \n  (\u2200 x : \u2115, (\u2200 y : \u2115, y < x \u2192 (P y)) \u2192 (P x))  \u2192  (\u2200 n : \u2115, P n)  :=\nbegin\n  intro assum,\n  intro n,\n  exact induction_strong_version P (n+1) assum n (lt_succ_self n),\nend\n", "meta": {"author": "madvorak", "repo": "Lean-first-steps", "sha": "4cfee162afaa53b589ec7a94986d78d75cf1c85e", "save_path": "github-repos/lean/madvorak-Lean-first-steps", "path": "github-repos/lean/madvorak-Lean-first-steps/Lean-first-steps-4cfee162afaa53b589ec7a94986d78d75cf1c85e/src/Complete_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.7096710204619429}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module category_theory.single_obj\n! leanprover-community/mathlib commit 56adee5b5eef9e734d82272918300fca4f3e7cef\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.Endomorphism\nimport Mathlib.CategoryTheory.Category.Cat\nimport Mathlib.Algebra.Category.MonCat.Basic\nimport Mathlib.Combinatorics.Quiver.SingleObj\n\n/-!\n# Single-object category\n\nSingle object category with a given monoid of endomorphisms.\nIt is defined to facilitate transfering some definitions and lemmas (e.g., conjugacy etc.)\nfrom category theory to monoids and groups.\n\n## Main definitions\n\nGiven a type `\u03b1` with a monoid structure, `SingleObj \u03b1` is `Unit` type with `Category` structure\nsuch that `End (SingleObj \u03b1).star` is the monoid `\u03b1`.  This can be extended to a functor\n`MonCat \u2964 Cat`.\n\nIf `\u03b1` is a group, then `SingleObj \u03b1` is a groupoid.\n\nAn element `x : \u03b1` can be reinterpreted as an element of `End (SingleObj.star \u03b1)` using\n`SingleObj.toEnd`.\n\n## Implementation notes\n\n- `categoryStruct.comp` on `End (SingleObj.star \u03b1)` is `flip (*)`, not `(*)`. This way\n  multiplication on `End` agrees with the multiplication on `\u03b1`.\n\n- By default, Lean puts instances into `CategoryTheory` namespace instead of\n  `CategoryTheory.SingleObj`, so we give all names explicitly.\n-/\n\n\nuniverse u v w\n\nnamespace CategoryTheory\n\n/-- Abbreviation that allows writing `CategoryTheory.SingleObj` rather than `Quiver.SingleObj`.\n-/\nabbrev SingleObj :=\n  Quiver.SingleObj\n#align category_theory.single_obj CategoryTheory.SingleObj\n\nnamespace SingleObj\n\nvariable (\u03b1 : Type u)\n\n/-- One and `flip (*)` become `id` and `comp` for morphisms of the single object category. -/\ninstance categoryStruct [One \u03b1] [Mul \u03b1] : CategoryStruct (SingleObj \u03b1)\n    where\n  Hom _ _ := \u03b1\n  comp x y := y * x\n  id _ := 1\n#align category_theory.single_obj.category_struct CategoryTheory.SingleObj.categoryStruct\n\n/-- Monoid laws become category laws for the single object category. -/\ninstance category [Monoid \u03b1] : Category (SingleObj \u03b1)\n    where\n  comp_id := one_mul\n  id_comp := mul_one\n  assoc x y z := (mul_assoc z y x).symm\n#align category_theory.single_obj.category CategoryTheory.SingleObj.category\n\ntheorem id_as_one [Monoid \u03b1] (x : SingleObj \u03b1) : \ud835\udfd9 x = 1 :=\n  rfl\n#align category_theory.single_obj.id_as_one CategoryTheory.SingleObj.id_as_one\n\ntheorem comp_as_mul [Monoid \u03b1] {x y z : SingleObj \u03b1} (f : x \u27f6 y) (g : y \u27f6 z) : f \u226b g = g * f :=\n  rfl\n#align category_theory.single_obj.comp_as_mul CategoryTheory.SingleObj.comp_as_mul\n\n/-- Groupoid structure on `SingleObj \u03b1`.\n\nSee <https://stacks.math.columbia.edu/tag/0019>.\n-/\ninstance groupoid [Group \u03b1] : Groupoid (SingleObj \u03b1)\n    where\n  inv x := x\u207b\u00b9\n  inv_comp := mul_right_inv\n  comp_inv := mul_left_inv\n#align category_theory.single_obj.groupoid CategoryTheory.SingleObj.groupoid\n\ntheorem inv_as_inv [Group \u03b1] {x y : SingleObj \u03b1} (f : x \u27f6 y) : inv f = f\u207b\u00b9 := by\n  apply IsIso.inv_eq_of_hom_inv_id\n  rw [comp_as_mul, inv_mul_self, id_as_one]\n#align category_theory.single_obj.inv_as_inv CategoryTheory.SingleObj.inv_as_inv\n\n/-- Abbreviation that allows writing `CategoryTheory.SingleObj.star` rather than\n`Quiver.SingleObj.star`.\n-/\nabbrev star : SingleObj \u03b1 :=\n  Quiver.SingleObj.star \u03b1\n#align category_theory.single_obj.star CategoryTheory.SingleObj.star\n\n/-- The endomorphisms monoid of the only object in `SingleObj \u03b1` is equivalent to the original\n     monoid \u03b1. -/\ndef toEnd [Monoid \u03b1] : \u03b1 \u2243* End (SingleObj.star \u03b1) :=\n  { Equiv.refl \u03b1 with map_mul' := fun _ _ => rfl }\n#align category_theory.single_obj.to_End CategoryTheory.SingleObj.toEnd\n\ntheorem toEnd_def [Monoid \u03b1] (x : \u03b1) : toEnd \u03b1 x = x :=\n  rfl\n#align category_theory.single_obj.to_End_def CategoryTheory.SingleObj.toEnd_def\n\n/-- There is a 1-1 correspondence between monoid homomorphisms `\u03b1 \u2192 \u03b2` and functors between the\n    corresponding single-object categories. It means that `SingleObj` is a fully faithful\n    functor.\n\nSee <https://stacks.math.columbia.edu/tag/001F> --\nalthough we do not characterize when the functor is full or faithful.\n-/\ndef mapHom (\u03b1 : Type u) (\u03b2 : Type v) [Monoid \u03b1] [Monoid \u03b2] : (\u03b1 \u2192* \u03b2) \u2243 SingleObj \u03b1 \u2964 SingleObj \u03b2\n    where\n  toFun f :=\n    { obj := id\n      map := \u21d1f\n      map_id := fun _ => f.map_one\n      map_comp := fun x y => f.map_mul y x }\n  invFun f :=\n    { toFun := fun x => f.map ((toEnd \u03b1) x)\n      map_one' := f.map_id _\n      map_mul' := fun x y => f.map_comp y x }\n  left_inv := by aesop_cat\n  right_inv := by aesop_cat\n#align category_theory.single_obj.map_hom CategoryTheory.SingleObj.mapHom\n\ntheorem mapHom_id (\u03b1 : Type u) [Monoid \u03b1] : mapHom \u03b1 \u03b1 (MonoidHom.id \u03b1) = \ud835\udfed _ :=\n  rfl\n#align category_theory.single_obj.map_hom_id CategoryTheory.SingleObj.mapHom_id\n\ntheorem mapHom_comp {\u03b1 : Type u} {\u03b2 : Type v} [Monoid \u03b1] [Monoid \u03b2] (f : \u03b1 \u2192* \u03b2) {\u03b3 : Type w}\n    [Monoid \u03b3] (g : \u03b2 \u2192* \u03b3) : mapHom \u03b1 \u03b3 (g.comp f) = mapHom \u03b1 \u03b2 f \u22d9 mapHom \u03b2 \u03b3 g :=\n  rfl\n#align category_theory.single_obj.map_hom_comp CategoryTheory.SingleObj.mapHom_comp\n\n/-- Given a function `f : C \u2192 G` from a category to a group, we get a functor\n    `C \u2964 G` sending any morphism `x \u27f6 y` to `f y * (f x)\u207b\u00b9`. -/\n@[simps]\ndef differenceFunctor {C G} [Category C] [Group G] (f : C \u2192 G) : C \u2964 SingleObj G\n    where\n  obj _ := ()\n  map {x y} _ := f y * (f x)\u207b\u00b9\n  map_id := by\n    intro\n    simp only [SingleObj.id_as_one, mul_right_inv]\n  map_comp := by\n    intros\n    dsimp\n    rw [SingleObj.comp_as_mul, \u2190 mul_assoc, mul_left_inj, mul_assoc, inv_mul_self, mul_one]\n#align category_theory.single_obj.difference_functor CategoryTheory.SingleObj.differenceFunctor\n\nend SingleObj\n\nend CategoryTheory\n\nopen CategoryTheory\n\nnamespace MonoidHom\n\n/-- Reinterpret a monoid homomorphism `f : \u03b1 \u2192 \u03b2` as a functor `(single_obj \u03b1) \u2964 (single_obj \u03b2)`.\nSee also `category_theory.single_obj.map_hom` for an equivalence between these types. -/\n@[reducible]\ndef toFunctor {\u03b1 : Type u} {\u03b2 : Type v} [Monoid \u03b1] [Monoid \u03b2] (f : \u03b1 \u2192* \u03b2) :\n    SingleObj \u03b1 \u2964 SingleObj \u03b2 :=\n  SingleObj.mapHom \u03b1 \u03b2 f\n#align monoid_hom.to_functor MonoidHom.toFunctor\n\n@[simp]\ntheorem id_toFunctor (\u03b1 : Type u) [Monoid \u03b1] : (id \u03b1).toFunctor = \ud835\udfed _ :=\n  rfl\n#align monoid_hom.id_to_functor MonoidHom.id_toFunctor\n\n@[simp]\ntheorem comp_toFunctor {\u03b1 : Type u} {\u03b2 : Type v} [Monoid \u03b1] [Monoid \u03b2] (f : \u03b1 \u2192* \u03b2) {\u03b3 : Type w}\n    [Monoid \u03b3] (g : \u03b2 \u2192* \u03b3) : (g.comp f).toFunctor = f.toFunctor \u22d9 g.toFunctor :=\n  rfl\n#align monoid_hom.comp_to_functor MonoidHom.comp_toFunctor\n\nend MonoidHom\n\nnamespace Units\n\nvariable (\u03b1 : Type u) [Monoid \u03b1]\n\n-- porting note: it was necessary to add `by exact` in this definition, presumably\n-- so that Lean4 is not confused by the fact that `\u03b1` has two opposite multiplications\n/-- The units in a monoid are (multiplicatively) equivalent to\nthe automorphisms of `star` when we think of the monoid as a single-object category. -/\ndef toAut : \u03b1\u02e3 \u2243* Aut (SingleObj.star \u03b1) :=\n  MulEquiv.trans (Units.mapEquiv (by exact SingleObj.toEnd \u03b1))\n    (Aut.unitsEndEquivAut (SingleObj.star \u03b1))\nset_option linter.uppercaseLean3 false in\n#align units.to_Aut Units.toAut\n\n@[simp]\ntheorem toAut_hom (x : \u03b1\u02e3) : (toAut \u03b1 x).hom = SingleObj.toEnd \u03b1 x :=\n  rfl\nset_option linter.uppercaseLean3 false in\n#align units.to_Aut_hom Units.toAut_hom\n\n@[simp]\ntheorem toAut_inv (x : \u03b1\u02e3) : (toAut \u03b1 x).inv = SingleObj.toEnd \u03b1 (x\u207b\u00b9 : \u03b1\u02e3) :=\n  rfl\nset_option linter.uppercaseLean3 false in\n#align units.to_Aut_inv Units.toAut_inv\n\nend Units\n\nnamespace MonCat\n\nopen CategoryTheory\n\n/-- The fully faithful functor from `MonCat` to `Cat`. -/\ndef toCat : MonCat \u2964 Cat where\n  obj x := Cat.of (SingleObj x)\n  map {x y} f := SingleObj.mapHom x y f\nset_option linter.uppercaseLean3 false in\n#align Mon.to_Cat MonCat.toCat\n\ninstance toCatFull : Full toCat where\n  preimage := (SingleObj.mapHom _ _).invFun\n  witness _ := rfl\nset_option linter.uppercaseLean3 false in\n#align Mon.to_Cat_full MonCat.toCatFull\n\ninstance toCat_faithful : Faithful toCat where\n  map_injective h := by simpa [toCat] using h\nset_option linter.uppercaseLean3 false in\n#align Mon.to_Cat_faithful MonCat.toCat_faithful\n\nend MonCat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/SingleObj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7096628593742336}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module algebra.monoid_algebra.support\n! leanprover-community/mathlib commit 16749fc4661828cba18cd0f4e3c5eb66a8e80598\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.MonoidAlgebra.Basic\n\n/-!\n#  Lemmas about the support of a finitely supported function\n-/\n\n\nuniverse u\u2081 u\u2082 u\u2083\n\nnamespace MonoidAlgebra\n\nopen Finset Finsupp\n\nvariable {k : Type u\u2081} {G : Type u\u2082} [Semiring k]\n\ntheorem support_single_mul_subset [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) (r : k) (a : G) :\n    (single a r * f : MonoidAlgebra k G).support \u2286 Finset.image ((\u00b7 * \u00b7) a) f.support := by\n  intro x hx\n  contrapose hx\n  have : \u2200 y, a * y = x \u2192 f y = 0 := by\n    simpa only [not_and', mem_image, mem_support_iff, exists_prop, not_exists,\n      Classical.not_not] using hx\n  simp only [mem_support_iff, mul_apply, sum_single_index, zero_mul, ite_self, sum_zero,\n    Classical.not_not]\n  exact\n    Finset.sum_eq_zero\n      (by\n        simp (config := { contextual := true }) only [this, mem_support_iff, mul_zero, Ne.def,\n          ite_eq_right_iff, eq_self_iff_true, imp_true_iff])\n#align monoid_algebra.support_single_mul_subset MonoidAlgebra.support_single_mul_subset\n\ntheorem support_mul_single_subset [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) (r : k) (a : G) :\n    (f * single a r).support \u2286 Finset.image (\u00b7 * a) f.support := by\n  intro x hx\n  contrapose hx\n  have : \u2200 y, y * a = x \u2192 f y = 0 := by\n    simpa only [not_and', mem_image, mem_support_iff, exists_prop, not_exists,\n      Classical.not_not] using hx\n  simp only [mem_support_iff, mul_apply, sum_single_index, zero_mul, ite_self, sum_zero,\n    Classical.not_not]\n  exact\n    Finset.sum_eq_zero\n      (by\n        simp (config := { contextual := true }) only [this, sum_single_index, ite_eq_right_iff,\n          eq_self_iff_true, imp_true_iff, zero_mul])\n#align monoid_algebra.support_mul_single_subset MonoidAlgebra.support_mul_single_subset\n\ntheorem support_single_mul_eq_image [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) {r : k}\n    (hr : \u2200 y, r * y = 0 \u2194 y = 0) {x : G} (lx : IsLeftRegular x) :\n    (single x r * f : MonoidAlgebra k G).support = Finset.image ((\u00b7 * \u00b7) x) f.support := by\n  refine' subset_antisymm (support_single_mul_subset f _ _) fun y hy => _\n  obtain \u27e8y, yf, rfl\u27e9 : \u2203 a : G, a \u2208 f.support \u2227 x * a = y := by\n    simpa only [Finset.mem_image, exists_prop] using hy\n  simp only [mul_apply, mem_support_iff.mp yf, hr, mem_support_iff, sum_single_index,\n    Finsupp.sum_ite_eq', Ne.def, not_false_iff, if_true, zero_mul, ite_self, sum_zero, lx.eq_iff]\n#align monoid_algebra.support_single_mul_eq_image MonoidAlgebra.support_single_mul_eq_image\n\ntheorem support_mul_single_eq_image [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) {r : k}\n    (hr : \u2200 y, y * r = 0 \u2194 y = 0) {x : G} (rx : IsRightRegular x) :\n    (f * single x r).support = Finset.image (\u00b7 * x) f.support := by\n  refine' subset_antisymm (support_mul_single_subset f _ _) fun y hy => _\n  obtain \u27e8y, yf, rfl\u27e9 : \u2203 a : G, a \u2208 f.support \u2227 a * x = y := by\n    simpa only [Finset.mem_image, exists_prop] using hy\n  simp only [mul_apply, mem_support_iff.mp yf, hr, mem_support_iff, sum_single_index,\n    Finsupp.sum_ite_eq', Ne.def, not_false_iff, if_true, mul_zero, ite_self, sum_zero, rx.eq_iff]\n#align monoid_algebra.support_mul_single_eq_image MonoidAlgebra.support_mul_single_eq_image\n\ntheorem support_mul [Mul G] [DecidableEq G] (a b : MonoidAlgebra k G) :\n    (a * b).support \u2286 a.support.bunion\u1d62 fun a\u2081 => b.support.bunion\u1d62 fun a\u2082 => {a\u2081 * a\u2082} :=\n  Subset.trans support_sum <|\n    bunion\u1d62_mono fun _ _ =>\n      Subset.trans support_sum <| bunion\u1d62_mono fun _a\u2082 _ => support_single_subset\n#align monoid_algebra.support_mul MonoidAlgebra.support_mul\n\ntheorem support_mul_single [RightCancelSemigroup G] (f : MonoidAlgebra k G) (r : k)\n    (hr : \u2200 y, y * r = 0 \u2194 y = 0) (x : G) :\n    (f * single x r).support = f.support.map (mulRightEmbedding x) := by\n  classical\n    ext\n    simp only [support_mul_single_eq_image f hr (isRightRegular_of_rightCancelSemigroup x),\n      mem_image, mem_map, mulRightEmbedding_apply]\n#align monoid_algebra.support_mul_single MonoidAlgebra.support_mul_single\n\ntheorem support_single_mul [LeftCancelSemigroup G] (f : MonoidAlgebra k G) (r : k)\n    (hr : \u2200 y, r * y = 0 \u2194 y = 0) (x : G) :\n    (single x r * f : MonoidAlgebra k G).support = f.support.map (mulLeftEmbedding x) := by\n  classical\n    ext\n    simp only [support_single_mul_eq_image f hr (isLeftRegular_of_leftCancelSemigroup x), mem_image,\n      mem_map, mulLeftEmbedding_apply]\n#align monoid_algebra.support_single_mul MonoidAlgebra.support_single_mul\n\nsection Span\n\nvariable [MulOneClass G]\n\n/-- An element of `MonoidAlgebra k G` is in the subalgebra generated by its support. -/\ntheorem mem_span_support (f : MonoidAlgebra k G) :\n    f \u2208 Submodule.span k (of k G '' (f.support : Set G)) := by\n  erw [of, MonoidHom.coe_mk, \u2190 supported_eq_span_single, Finsupp.mem_supported]\n#align monoid_algebra.mem_span_support MonoidAlgebra.mem_span_support\n\nend Span\n\nend MonoidAlgebra\n\nnamespace AddMonoidAlgebra\n\nopen Finset Finsupp MulOpposite\n\nvariable {k : Type u\u2081} {G : Type u\u2082} [Semiring k]\n\ntheorem support_mul [DecidableEq G] [Add G] (a b : AddMonoidAlgebra k G) :\n    (a * b).support \u2286 a.support.bunion\u1d62 fun a\u2081 => b.support.bunion\u1d62 fun a\u2082 => {a\u2081 + a\u2082} :=\n  @MonoidAlgebra.support_mul k (Multiplicative G) _ _ _ _ _\n#align add_monoid_algebra.support_mul AddMonoidAlgebra.support_mul\n\ntheorem support_mul_single [AddRightCancelSemigroup G] (f : AddMonoidAlgebra k G) (r : k)\n    (hr : \u2200 y, y * r = 0 \u2194 y = 0) (x : G) :\n    (f * single x r : AddMonoidAlgebra k G).support = f.support.map (addRightEmbedding x) :=\n  @MonoidAlgebra.support_mul_single k (Multiplicative G) _ _ _ _ hr _\n#align add_monoid_algebra.support_mul_single AddMonoidAlgebra.support_mul_single\n\ntheorem support_single_mul [AddLeftCancelSemigroup G] (f : AddMonoidAlgebra k G) (r : k)\n    (hr : \u2200 y, r * y = 0 \u2194 y = 0) (x : G) :\n    (single x r * f : AddMonoidAlgebra k G).support = f.support.map (addLeftEmbedding x) :=\n  @MonoidAlgebra.support_single_mul k (Multiplicative G) _ _ _ _ hr _\n#align add_monoid_algebra.support_single_mul AddMonoidAlgebra.support_single_mul\n\nsection Span\n\n/-- An element of `AddMonoidAlgebra k G` is in the submodule generated by its support. -/\ntheorem mem_span_support [AddZeroClass G] (f : AddMonoidAlgebra k G) :\n    f \u2208 Submodule.span k (of k G '' (f.support : Set G)) := by\n  erw [of, MonoidHom.coe_mk, \u2190 Finsupp.supported_eq_span_single, Finsupp.mem_supported]\n#align add_monoid_algebra.mem_span_support AddMonoidAlgebra.mem_span_support\n\n/-- An element of `AddMonoidAlgebra k G` is in the subalgebra generated by its support, using\nunbundled inclusion. -/\ntheorem mem_span_support' (f : AddMonoidAlgebra k G) :\n    f \u2208 Submodule.span k (of' k G '' (f.support : Set G)) := by\n  delta of'\n  rw [\u2190 Finsupp.supported_eq_span_single, Finsupp.mem_supported]\n#align add_monoid_algebra.mem_span_support' AddMonoidAlgebra.mem_span_support'\n\nend Span\n\nend AddMonoidAlgebra\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/MonoidAlgebra/Support.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7096628527733463}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n\nLinear independence and basis sets in a module or vector space.\n\nThis file is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.\n\nWe define the following concepts:\n\n* `linear_independent \u03b1 s`: states that `s` are linear independent\n\n* `linear_independent.repr s b`: choose the linear combination representing `b` on the linear\n  independent vectors `s`. `b` should be in `span \u03b1 b` (uses classical choice)\n\n* `is_basis \u03b1 s`: if `s` is a basis, i.e. linear independent and spans the entire space\n\n* `is_basis.repr s b`: like `linear_independent.repr` but as a `linear_map`\n\n* `is_basis.constr s g`: constructs a `linear_map` by extending `g` from the basis `s`\n\n-/\nimport linear_algebra.linear_combination order.zorn\nnoncomputable theory\n\nopen function lattice set submodule\nlocal attribute [instance] classical.prop_decidable\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*} {\u03b4 : Type*}\n\nsection module\nvariables [ring \u03b1] [add_comm_group \u03b2] [add_comm_group \u03b3] [add_comm_group \u03b4]\nvariables [module \u03b1 \u03b2] [module \u03b1 \u03b3] [module \u03b1 \u03b4]\nvariables {a b : \u03b1} {s t : set \u03b2} {x y : \u03b2}\ninclude \u03b1\n\nvariables (\u03b1)\n/-- Linearly independent set of vectors -/\ndef linear_independent (s : set \u03b2) : Prop :=\ndisjoint (lc.supported \u03b1 s) (lc.total \u03b1 \u03b2).ker\nvariables {\u03b1}\n\ntheorem linear_independent_iff : linear_independent \u03b1 s \u2194\n  \u2200l \u2208 lc.supported \u03b1 s, lc.total \u03b1 \u03b2 l = 0 \u2192 l = 0 :=\nby simp [linear_independent, linear_map.disjoint_ker]\n\ntheorem linear_independent_iff_total_on : linear_independent \u03b1 s \u2194 (lc.total_on \u03b1 s).ker = \u22a5 :=\nby rw [lc.total_on, linear_map.ker, linear_map.comap_cod_restrict, map_bot, comap_bot,\n  linear_map.ker_comp, linear_independent, disjoint, \u2190 map_comap_subtype, map_le_iff_le_comap,\n  comap_bot, ker_subtype, le_bot_iff]\n\nlemma linear_independent_empty : linear_independent \u03b1 (\u2205 : set \u03b2) :=\nby simp [linear_independent]\n\nlemma linear_independent.mono (h : t \u2286 s) : linear_independent \u03b1 s \u2192 linear_independent \u03b1 t :=\ndisjoint_mono_left (lc.supported_mono h)\n\nlemma linear_independent.unique (hs : linear_independent \u03b1 s) {l\u2081 l\u2082 : lc \u03b1 \u03b2} :\n  l\u2081 \u2208 lc.supported \u03b1 s \u2192 l\u2082 \u2208 lc.supported \u03b1 s \u2192\n  lc.total \u03b1 \u03b2 l\u2081 = lc.total \u03b1 \u03b2 l\u2082 \u2192 l\u2081 = l\u2082 :=\nlinear_map.disjoint_ker'.1 hs _ _\n\nlemma zero_not_mem_of_linear_independent (ne : 0 \u2260 (1:\u03b1)) (hs : linear_independent \u03b1 s) : (0:\u03b2) \u2209 s :=\n\u03bb h, ne $ eq.symm begin\n  suffices : (finsupp.single 0 1 : lc \u03b1 \u03b2) 0 = 0, {simpa},\n  rw disjoint_def.1 hs _ (lc.single_mem_supported 1 h),\n  {refl}, {simp}\nend\n\nlemma linear_independent_union {s t : set \u03b2}\n  (hs : linear_independent \u03b1 s) (ht : linear_independent \u03b1 t)\n  (hst : disjoint (span \u03b1 s) (span \u03b1 t)) : linear_independent \u03b1 (s \u222a t) :=\nbegin\n  rw [linear_independent, disjoint_def, lc.supported_union],\n  intros l h\u2081 h\u2082, rw mem_sup at h\u2081,\n  rcases h\u2081 with \u27e8ls, hls, lt, hlt, rfl\u27e9,\n  rw [span_eq_map_lc, span_eq_map_lc] at hst,\n  have : lc.total \u03b1 \u03b2 ls \u2208 map (lc.total \u03b1 \u03b2) (lc.supported \u03b1 t),\n  { apply (add_mem_iff_left (map _ _) (mem_image_of_mem _ hlt)).1,\n    rw [\u2190 linear_map.map_add, linear_map.mem_ker.1 h\u2082],\n    apply zero_mem },\n  have ls0 := disjoint_def.1 hs _ hls (linear_map.mem_ker.2 $\n    disjoint_def.1 hst _ (mem_image_of_mem _ hls) this),\n  subst ls0, simp [-linear_map.mem_ker] at this h\u2082 \u22a2,\n  exact disjoint_def.1 ht _ hlt h\u2082\nend\n\nlemma linear_independent_of_finite\n  (H : \u2200 t \u2286 s, finite t \u2192 linear_independent \u03b1 t) :\n  linear_independent \u03b1 s :=\nlinear_independent_iff.2 $ \u03bb l hl,\nlinear_independent_iff.1 (H _ hl (finset.finite_to_set _)) l (subset.refl _)\n\nlemma linear_independent_Union_of_directed {\u03b9 : Type*}\n  {s : \u03b9 \u2192 set \u03b2} (hs : directed (\u2286) s)\n  (h : \u2200 i, linear_independent \u03b1 (s i)) : linear_independent \u03b1 (\u22c3 i, s i) :=\nbegin\n  by_cases h\u03b9 : nonempty \u03b9,\n  { refine linear_independent_of_finite (\u03bb t ht ft, _),\n    rcases finite_subset_Union ft ht with \u27e8I, fi, hI\u27e9,\n    rcases hs.finset_le h\u03b9 fi.to_finset with \u27e8i, hi\u27e9,\n    exact (h i).mono (subset.trans hI $ bUnion_subset $\n      \u03bb j hj, hi j (finite.mem_to_finset.2 hj)) },\n  { refine linear_independent_empty.mono _,\n    rintro _ \u27e8_, \u27e8i, _\u27e9, _\u27e9, exact h\u03b9 \u27e8i\u27e9 }\nend\n\nlemma linear_independent_sUnion_of_directed {s : set (set \u03b2)}\n  (hs : directed_on (\u2286) s)\n  (h : \u2200 a \u2208 s, linear_independent \u03b1 a) : linear_independent \u03b1 (\u22c3\u2080 s) :=\nby rw sUnion_eq_Union; exact\nlinear_independent_Union_of_directed\n  ((directed_on_iff_directed _).1 hs) (by simpa using h)\n\nlemma linear_independent_bUnion_of_directed {\u03b9} {s : set \u03b9} {t : \u03b9 \u2192 set \u03b2}\n  (hs : directed_on (t \u207b\u00b9'o (\u2286)) s) (h : \u2200a\u2208s, linear_independent \u03b1 (t a)) :\n  linear_independent \u03b1 (\u22c3a\u2208s, t a) :=\nby rw bUnion_eq_Union; exact\nlinear_independent_Union_of_directed\n  ((directed_comp _ _ _).2 $ (directed_on_iff_directed _).1 hs)\n  (by simpa using h)\n\nlemma linear_independent_Union_finite {\u03b9 : Type*} {f : \u03b9 \u2192 set \u03b2}\n  (hl : \u2200i, linear_independent \u03b1 (f i))\n  (hd : \u2200i, \u2200t:set \u03b9, finite t \u2192 i \u2209 t \u2192 disjoint (span \u03b1 (f i)) (\u2a06i\u2208t, span \u03b1 (f i))) :\n  linear_independent \u03b1 (\u22c3i, f i) :=\nbegin\n  classical,\n  rw [Union_eq_Union_finset f],\n  refine linear_independent_Union_of_directed (directed_of_sup _) _,\n  exact (assume t\u2081 t\u2082 ht, Union_subset_Union $ assume i, Union_subset_Union_const $ assume h, ht h),\n  assume t, rw [set.Union, \u2190 finset.sup_eq_supr],\n  refine t.induction_on _ _,\n  { exact linear_independent_empty },\n  { rintros \u27e8i\u27e9 s his ih,\n    rw [finset.sup_insert],\n    refine linear_independent_union (hl _) ih _,\n    rw [finset.sup_eq_supr],\n    refine disjoint_mono (le_refl _) _ (hd i _ _ his),\n    { simp only [(span_Union _).symm],\n      refine span_mono (@supr_le_supr2 (set \u03b2) _ _ _ _ _ _),\n      rintros \u27e8i\u27e9, exact \u27e8i, le_refl _\u27e9 },\n    { change finite (plift.up \u207b\u00b9' s.to_set),\n      exact finite_preimage (assume i j, plift.up.inj) s.finite_to_set } }\nend\n\nsection repr\nvariables (hs : linear_independent \u03b1 s)\n\ndef linear_independent.total_equiv : lc.supported \u03b1 s \u2243\u2097 span \u03b1 s :=\nlinear_equiv.of_bijective (lc.total_on \u03b1 s)\n  (linear_independent_iff_total_on.1 hs) (lc.total_on_range _)\n\ndef linear_independent.repr : span \u03b1 s \u2192\u2097[\u03b1] lc \u03b1 \u03b2 :=\n(submodule.subtype _).comp (hs.total_equiv.symm : span \u03b1 s \u2192\u2097[\u03b1] lc.supported \u03b1 s)\n\nlemma linear_independent.total_repr (x) : lc.total \u03b1 \u03b2 (hs.repr x) = x :=\nsubtype.ext.1 $ hs.total_equiv.right_inv x\n\nlemma linear_independent.total_comp_repr : (lc.total \u03b1 \u03b2).comp hs.repr = submodule.subtype _ :=\nlinear_map.ext $ hs.total_repr\n\nlemma linear_independent.repr_ker : hs.repr.ker = \u22a5 :=\nby rw [linear_independent.repr, linear_map.ker_comp, ker_subtype, comap_bot,\n       linear_equiv.ker]\n\nlemma linear_independent.repr_range : hs.repr.range = lc.supported \u03b1 s :=\nby rw [linear_independent.repr, linear_map.range_comp,\n       linear_equiv.range, map_top, range_subtype]\n\nlemma linear_independent.repr_eq {l : lc \u03b1 \u03b2} (h : l \u2208 lc.supported \u03b1 s) {x} (eq : lc.total \u03b1 \u03b2 l = \u2191x) : hs.repr x = l :=\nby rw \u2190 (subtype.eq' eq : (lc.total_on \u03b1 s : lc.supported \u03b1 s \u2192\u2097 span \u03b1 s) \u27e8l, h\u27e9 = x);\n   exact subtype.ext.1 (hs.total_equiv.left_inv \u27e8l, h\u27e9)\n\nlemma linear_independent.repr_eq_single (x) (hx : \u2191x \u2208 s) : hs.repr x = finsupp.single x 1 :=\nhs.repr_eq (lc.single_mem_supported _ hx) (by simp)\n\nlemma linear_independent.repr_supported (x) : hs.repr x \u2208 lc.supported \u03b1 s :=\n((hs.total_equiv.symm : span \u03b1 s \u2192\u2097[\u03b1] lc.supported \u03b1 s) x).2\n\nlemma linear_independent.repr_eq_repr_of_subset\n  (h : t \u2286 s) (x y) (e : (\u2191x:\u03b2) = \u2191y) :\n  (hs.mono h).repr x = hs.repr y :=\neq.symm $ hs.repr_eq (lc.supported_mono h $ (hs.mono h).repr_supported _)\n  (by rw [\u2190 e, (hs.mono h).total_repr]).\n\nlemma linear_independent_iff_not_smul_mem_span :\n  linear_independent \u03b1 s \u2194 (\u2200 (x \u2208 s) (a : \u03b1), a \u2022 x \u2208 span \u03b1 (s \\ {x}) \u2192 a = 0) :=\n\u27e8\u03bb hs x hx a ha, begin\n  rw [span_eq_map_lc, mem_map] at ha,\n  rcases ha with \u27e8l, hl, e\u27e9,\n  have := (lc.supported \u03b1 s).sub_mem\n    (lc.supported_mono (diff_subset _ _) hl) (lc.single_mem_supported a hx),\n  rw [sub_eq_zero.1 (linear_independent_iff.1 hs _ this $ by simp [e])] at hl,\n  by_contra hn,\n  exact (not_mem_of_mem_diff (hl $ by simp [hn])) (mem_singleton _)\nend, \u03bb H, linear_independent_iff.2 $ \u03bb l ls l0, begin\n  ext x, simp,\n  by_contra hn,\n  have xs : x \u2208 s := ls (finsupp.mem_support_iff.2 hn),\n  refine hn (H _ xs _ _),\n  refine mem_span_iff_lc.2 \u27e8finsupp.single x (l x) - l, _, _\u27e9,\n  { have : finsupp.single x (l x) - l \u2208 lc.supported \u03b1 s :=\n      sub_mem _ (lc.single_mem_supported _ xs) ls,\n    refine \u03bb y hy, \u27e8this hy, \u03bb e, _\u27e9,\n    simp at e hy, apply hy, simp [e] },\n  { simp [l0] }\nend\u27e9\n\nend repr\n\nlemma eq_of_linear_independent_of_span (nz : (1 : \u03b1) \u2260 0)\n  (hs : linear_independent \u03b1 s) (h : t \u2286 s) (hst : s \u2286 span \u03b1 t) : s = t :=\nbegin\n  refine subset.antisymm (\u03bb b hb, _) h,\n  have : (hs.mono h).repr \u27e8b, hst hb\u27e9 = finsupp.single b 1 :=\n    (hs.repr_eq_repr_of_subset h \u27e8b, hst hb\u27e9 \u27e8b, subset_span hb\u27e9 rfl).trans\n      (hs.repr_eq_single \u27e8b, _\u27e9 hb),\n  have ss := (hs.mono h).repr_supported _,\n  rw this at ss, exact ss (by simp [nz]),\nend\n\nsection\nvariables {f : \u03b2 \u2192\u2097[\u03b1] \u03b3}\n  (hs : linear_independent \u03b1 (f '' s))\n  (hf_inj : \u2200 a b \u2208 s, f a = f b \u2192 a = b)\ninclude hs hf_inj\nopen linear_map\n\nlemma linear_independent.supported_disjoint_ker :\n  disjoint (lc.supported \u03b1 s) (ker (f.comp (lc.total \u03b1 \u03b2))) :=\nbegin\n  refine le_trans (le_inf inf_le_left _) (lc.map_disjoint_ker f hf_inj),\n  rw [linear_independent, disjoint_iff, \u2190 lc.map_supported f] at hs,\n  rw [\u2190 lc.map_total, le_ker_iff_map],\n  refine eq_bot_mono (le_inf (map_mono inf_le_left) _) hs,\n  rw [map_le_iff_le_comap, \u2190 ker_comp], exact inf_le_right\nend\n\nlemma linear_independent.of_image : linear_independent \u03b1 s :=\ndisjoint_mono_right (ker_le_ker_comp _ _) (hs.supported_disjoint_ker hf_inj)\n\nlemma linear_independent.disjoint_ker : disjoint (span \u03b1 s) f.ker :=\nby rw [span_eq_map_lc, disjoint_iff, map_inf_eq_map_inf_comap,\n  \u2190 ker_comp, disjoint_iff.1 (hs.supported_disjoint_ker hf_inj), map_bot]\n\nend\n\nlemma linear_independent.inj_span_iff_inj {s : set \u03b2} {f : \u03b2 \u2192\u2097[\u03b1] \u03b3}\n  (hfs : linear_independent \u03b1 (f '' s)) :\n  disjoint (span \u03b1 s) f.ker \u2194 (\u2200a b \u2208 s, f a = f b \u2192 a = b) :=\n\u27e8linear_map.inj_of_disjoint_ker subset_span, hfs.disjoint_ker\u27e9\n\nopen linear_map\nlemma linear_independent.image {s : set \u03b2} {f : \u03b2 \u2192\u2097 \u03b3} (hs : linear_independent \u03b1 s)\n  (hf_inj : disjoint (span \u03b1 s) f.ker) : linear_independent \u03b1 (f '' s) :=\nby rw [disjoint, span_eq_map_lc, map_inf_eq_map_inf_comap,\n    map_le_iff_le_comap, comap_bot] at hf_inj;\n  rw [linear_independent, disjoint, \u2190 lc.map_supported f, map_inf_eq_map_inf_comap,\n    map_le_iff_le_comap, \u2190 ker_comp, lc.map_total, ker_comp];\n  exact le_trans (le_inf inf_le_left hf_inj) (le_trans hs bot_le)\n\nlemma linear_map.linear_independent_image_iff {s : set \u03b2} {f : \u03b2 \u2192\u2097 \u03b3}\n  (hf_inj : disjoint (span \u03b1 s) f.ker) :\n  linear_independent \u03b1 (f '' s) \u2194 linear_independent \u03b1 s :=\n\u27e8\u03bb hs, hs.of_image (linear_map.inj_of_disjoint_ker subset_span hf_inj),\n \u03bb hs, hs.image hf_inj\u27e9\n\nlemma linear_independent_inl_union_inr {s : set \u03b2} {t : set \u03b3}\n  (hs : linear_independent \u03b1 s) (ht : linear_independent \u03b1 t) :\n  linear_independent \u03b1 (inl \u03b1 \u03b2 \u03b3 '' s \u222a inr \u03b1 \u03b2 \u03b3 '' t) :=\nlinear_independent_union (hs.image $ by simp) (ht.image $ by simp) $\nby rw [span_image, span_image]; simp [disjoint_iff, prod_inf_prod]\n\nvariables (\u03b1)\n/-- A set of vectors is a basis if it is linearly independent and all vectors are in the span \u03b1 -/\ndef is_basis (s : set \u03b2) := linear_independent \u03b1 s \u2227 span \u03b1 s = \u22a4\nvariables {\u03b1}\n\nsection is_basis\nvariables (hs : is_basis \u03b1 s)\n\nlemma is_basis.mem_span (hs : is_basis \u03b1 s) : \u2200 x, x \u2208 span \u03b1 s := eq_top_iff'.1 hs.2\n\ndef is_basis.repr : \u03b2 \u2192\u2097 lc \u03b1 \u03b2 :=\n(hs.1.repr).comp (linear_map.id.cod_restrict _ hs.mem_span)\n\nlemma is_basis.total_repr (x) : lc.total \u03b1 \u03b2 (hs.repr x) = x :=\nhs.1.total_repr \u27e8x, _\u27e9\n\nlemma is_basis.total_comp_repr : (lc.total \u03b1 \u03b2).comp hs.repr = linear_map.id :=\nlinear_map.ext hs.total_repr\n\nlemma is_basis.repr_ker : hs.repr.ker = \u22a5 :=\nlinear_map.ker_eq_bot.2 $ injective_of_left_inverse hs.total_repr\n\nlemma is_basis.repr_range : hs.repr.range = lc.supported \u03b1 s :=\nby  rw [is_basis.repr, linear_map.range, submodule.map_comp,\n  linear_map.map_cod_restrict, submodule.map_id, comap_top, map_top, hs.1.repr_range]\n\nlemma is_basis.repr_supported (x) : hs.repr x \u2208 lc.supported \u03b1 s :=\nhs.1.repr_supported \u27e8x, _\u27e9\n\nlemma is_basis.repr_eq_single {x} : x \u2208 s \u2192 hs.repr x = finsupp.single x 1 :=\nhs.1.repr_eq_single \u27e8x, _\u27e9\n\n/-- Construct a linear map given the value at the basis. -/\ndef is_basis.constr (f : \u03b2 \u2192 \u03b3) : \u03b2 \u2192\u2097 \u03b3 :=\n(lc.total \u03b1 \u03b3).comp $ (lc.map \u03b1 f).comp hs.repr\n\ntheorem is_basis.constr_apply (f : \u03b2 \u2192 \u03b3) (x : \u03b2) :\n  (hs.constr f : \u03b2 \u2192 \u03b3) x = (hs.repr x).sum (\u03bbb a, a \u2022 f b) :=\nby dsimp [is_basis.constr];\n   rw [lc.total_apply, finsupp.sum_map_domain_index]; simp [add_smul]\n\nlemma is_basis.ext {f g : \u03b2 \u2192\u2097[\u03b1] \u03b3} (hs : is_basis \u03b1 s) (h : \u2200x\u2208s, f x = g x) : f = g :=\nlinear_map.ext $ \u03bb x, linear_eq_on h (hs.mem_span x)\n\nlemma constr_congr {f g : \u03b2 \u2192 \u03b3} {x : \u03b2} (hs : is_basis \u03b1 s) (h : \u2200x\u2208s, f x = g x) :\n  hs.constr f = hs.constr g :=\nby ext y; simp [is_basis.constr_apply]; exact\nfinset.sum_congr rfl (\u03bb x hx, by simp [h x (hs.repr_supported _ hx)])\n\nlemma constr_basis {f : \u03b2 \u2192 \u03b3} {b : \u03b2} (hs : is_basis \u03b1 s) (hb : b \u2208 s) :\n  (hs.constr f : \u03b2 \u2192 \u03b3) b = f b :=\nby simp [is_basis.constr_apply, hs.repr_eq_single hb, finsupp.sum_single_index]\n\nlemma constr_eq {g : \u03b2 \u2192 \u03b3} {f : \u03b2 \u2192\u2097[\u03b1] \u03b3} (hs : is_basis \u03b1 s)\n  (h : \u2200x\u2208s, g x = f x) : hs.constr g = f :=\nhs.ext $ \u03bb x hx, (constr_basis hs hx).trans (h _ hx)\n\nlemma constr_self (f : \u03b2 \u2192\u2097[\u03b1] \u03b3) : hs.constr f = f :=\nconstr_eq hs $ \u03bb x hx, rfl\n\nlemma constr_zero (hs : is_basis \u03b1 s) : hs.constr (\u03bbb, (0 : \u03b3)) = 0 :=\nconstr_eq hs $ \u03bb x hx, rfl\n\nlemma constr_add {g f : \u03b2 \u2192 \u03b3} (hs : is_basis \u03b1 s) :\n  hs.constr (\u03bbb, f b + g b) = hs.constr f + hs.constr g :=\nconstr_eq hs $ by simp [constr_basis hs] {contextual := tt}\n\nlemma constr_neg {f : \u03b2 \u2192 \u03b3} (hs : is_basis \u03b1 s) : hs.constr (\u03bbb, - f b) = - hs.constr f :=\nconstr_eq hs $ by simp [constr_basis hs] {contextual := tt}\n\nlemma constr_sub {g f : \u03b2 \u2192 \u03b3} (hs : is_basis \u03b1 s) :\n  hs.constr (\u03bbb, f b - g b) = hs.constr f - hs.constr g :=\nby simp [constr_add, constr_neg]\n\n-- this only works on functions if `\u03b1` is a commutative ring\nlemma constr_smul {\u03b1 \u03b2 \u03b3} [comm_ring \u03b1]\n  [add_comm_group \u03b2] [add_comm_group \u03b3] [module \u03b1 \u03b2] [module \u03b1 \u03b3]\n  {f : \u03b2 \u2192 \u03b3} {a : \u03b1} {s : set \u03b2} (hs : is_basis \u03b1 s) {b : \u03b2} :\n  hs.constr (\u03bbb, a \u2022 f b) = a \u2022 hs.constr f :=\nconstr_eq hs $ by simp [constr_basis hs] {contextual := tt}\n\nlemma constr_range (hs : is_basis \u03b1 s) {f : \u03b2 \u2192 \u03b3} : (hs.constr f).range = span \u03b1 (f '' s) :=\nby rw [is_basis.constr, linear_map.range_comp, linear_map.range_comp,\n       is_basis.repr_range, lc.map_supported, span_eq_map_lc]\n\ndef module_equiv_lc (hs : is_basis \u03b1 s) : \u03b2 \u2243\u2097 lc.supported \u03b1 s :=\n(hs.1.total_equiv.trans (linear_equiv.of_top _ hs.2)).symm\n\ndef equiv_of_is_basis {s : set \u03b2} {t : set \u03b3} {f : \u03b2 \u2192 \u03b3} {g : \u03b3 \u2192 \u03b2}\n  (hs : is_basis \u03b1 s) (ht : is_basis \u03b1 t) (hf : \u2200b\u2208s, f b \u2208 t) (hg : \u2200c\u2208t, g c \u2208 s)\n  (hgf : \u2200b\u2208s, g (f b) = b) (hfg : \u2200c\u2208t, f (g c) = c) :\n  \u03b2 \u2243\u2097 \u03b3 :=\n{ inv_fun := ht.constr g,\n  left_inv :=\n    have (ht.constr g).comp (hs.constr f) = linear_map.id,\n    from hs.ext $ by simp [constr_basis, hs, ht, hf, hgf, (\u2218)] {contextual := tt},\n    \u03bb x, congr_arg (\u03bb h:\u03b2 \u2192\u2097[\u03b1] \u03b2, h x) this,\n  right_inv :=\n    have (hs.constr f).comp (ht.constr g) = linear_map.id,\n    from ht.ext $ by simp [constr_basis, hs, ht, hg, hfg, (\u2218)] {contextual := tt},\n    \u03bb y, congr_arg (\u03bb h:\u03b3 \u2192\u2097[\u03b1] \u03b3, h y) this,\n  ..hs.constr f }\n\nlemma is_basis_inl_union_inr {s : set \u03b2} {t : set \u03b3}\n  (hs : is_basis \u03b1 s) (ht : is_basis \u03b1 t) : is_basis \u03b1 (inl \u03b1 \u03b2 \u03b3 '' s \u222a inr \u03b1 \u03b2 \u03b3 '' t) :=\n\u27e8linear_independent_inl_union_inr hs.1 ht.1,\n  by rw [span_union, span_image, span_image]; simp [hs.2, ht.2]\u27e9\n\nend is_basis\n\nlemma is_basis_singleton_one (\u03b1 : Type*) [ring \u03b1] : is_basis \u03b1 ({1} : set \u03b1) :=\n\u27e8 by simp [linear_independent_iff_not_smul_mem_span],\n  top_unique $ assume a h, by simp [submodule.mem_span_singleton]\u27e9\n\nlemma linear_equiv.is_basis {s : set \u03b2} (hs : is_basis \u03b1 s)\n  (f : \u03b2 \u2243\u2097[\u03b1] \u03b3) : is_basis \u03b1 (f '' s) :=\nshow is_basis \u03b1 ((f : \u03b2 \u2192\u2097[\u03b1] \u03b3) '' s), from\n\u27e8hs.1.image $ by simp, by rw [span_image, hs.2, map_top, f.range]\u27e9\n\nlemma is_basis_injective {s : set \u03b3} {f : \u03b2 \u2192\u2097[\u03b1] \u03b3}\n  (hs : linear_independent \u03b1 s) (h : function.injective f) (hfs : span \u03b1 s = f.range) :\n  is_basis \u03b1 (f \u207b\u00b9' s) :=\nhave s_eq : f '' (f \u207b\u00b9' s) = s :=\n  image_preimage_eq_of_subset $ by rw [\u2190 linear_map.range_coe, \u2190 hfs]; exact subset_span,\nhave linear_independent \u03b1 (f '' (f \u207b\u00b9' s)), from hs.mono (image_preimage_subset _ _),\nbegin\n  split,\n  exact (this.of_image $ assume a ha b hb eq, h eq),\n  refine (top_unique $ (linear_map.map_le_map_iff $ linear_map.ker_eq_bot.2 h).1 _),\n  rw [\u2190 span_image f,s_eq, hfs, linear_map.range],\n  exact le_refl _\nend\n\nlemma is_basis_span {s : set \u03b2} (hs : linear_independent \u03b1 s) : is_basis \u03b1 ((span \u03b1 s).subtype \u207b\u00b9' s) :=\nis_basis_injective hs subtype.val_injective (range_subtype _).symm\n\nlemma is_basis_empty (h : \u2200x:\u03b2, x = 0) : is_basis \u03b1 (\u2205 : set \u03b2) :=\n\u27e8linear_independent_empty, eq_top_iff'.2 $ assume x, (h x).symm \u25b8 submodule.zero_mem _\u27e9\n\nlemma is_basis_empty_bot : is_basis \u03b1 ({x | false } : set (\u22a5 : submodule \u03b1 \u03b2)) :=\nis_basis_empty $ assume \u27e8x, hx\u27e9,\n  by change x \u2208 (\u22a5 : submodule \u03b1 \u03b2) at hx; simpa [subtype.ext] using hx\n\nend module\n\nsection vector_space\nvariables [discrete_field \u03b1] [add_comm_group \u03b2] [add_comm_group \u03b3]\n  [vector_space \u03b1 \u03b2] [vector_space \u03b1 \u03b3] {s t : set \u03b2} {x y z : \u03b2}\ninclude \u03b1\nopen submodule\n\n/- TODO: some of the following proofs can generalized with a zero_ne_one predicate type class\n   (instead of a data containing type classs) -/\n\nset_option class.instance_max_depth 36\n\nlemma mem_span_insert_exchange : x \u2208 span \u03b1 (insert y s) \u2192 x \u2209 span \u03b1 s \u2192 y \u2208 span \u03b1 (insert x s) :=\nbegin\n  simp [mem_span_insert],\n  rintro a z hz rfl h,\n  refine \u27e8a\u207b\u00b9, -a\u207b\u00b9 \u2022 z, smul_mem _ _ hz, _\u27e9,\n  have a0 : a \u2260 0, {rintro rfl, simp * at *},\n  simp [a0, smul_add, smul_smul]\nend\n\nset_option class.instance_max_depth 32\n\nlemma linear_independent_iff_not_mem_span : linear_independent \u03b1 s \u2194 (\u2200x\u2208s, x \u2209 span \u03b1 (s \\ {x})) :=\nlinear_independent_iff_not_smul_mem_span.trans\n\u27e8\u03bb H x xs hx, one_ne_zero (H x xs 1 $ by simpa),\n \u03bb H x xs a hx, classical.by_contradiction $ \u03bb a0,\n   H x xs ((smul_mem_iff _ a0).1 hx)\u27e9\n\nlemma linear_independent_singleton {x : \u03b2} (hx : x \u2260 0) : linear_independent \u03b1 ({x} : set \u03b2) :=\nlinear_independent_iff_not_mem_span.mpr $ by simp [hx] {contextual := tt}\n\nlemma disjoint_span_singleton {p : submodule \u03b1 \u03b2} {x : \u03b2} (x0 : x \u2260 0) :\n  disjoint p (span \u03b1 {x}) \u2194 x \u2209 p :=\n\u27e8\u03bb H xp, x0 (disjoint_def.1 H _ xp (singleton_subset_iff.1 subset_span:_)),\nbegin\n  simp [disjoint_def, mem_span_singleton],\n  rintro xp y yp a rfl,\n  by_cases a0 : a = 0, {simp [a0]},\n  exact xp.elim ((smul_mem_iff p a0).1 yp),\nend\u27e9\n\nlemma linear_independent.insert (hs : linear_independent \u03b1 s) (hx : x \u2209 span \u03b1 s) :\n  linear_independent \u03b1 (insert x s) :=\nbegin\n  rw \u2190 union_singleton,\n  have x0 : x \u2260 0 := mt (by rintro rfl; apply zero_mem _) hx,\n  exact linear_independent_union hs (linear_independent_singleton x0)\n    ((disjoint_span_singleton x0).2 hx)\nend\n\nlemma exists_linear_independent (hs : linear_independent \u03b1 s) (hst : s \u2286 t) :\n  \u2203b\u2286t, s \u2286 b \u2227 t \u2286 span \u03b1 b \u2227 linear_independent \u03b1 b :=\nbegin\n  rcases zorn.zorn_subset\u2080 {b | b \u2286 t \u2227 linear_independent \u03b1 b} _ _\n    \u27e8hst, hs\u27e9 with \u27e8b, \u27e8bt, bi\u27e9, sb, h\u27e9,\n  { refine \u27e8b, bt, sb, \u03bb x xt, _, bi\u27e9,\n    by_contra hn,\n    apply hn,\n    rw \u2190 h _ \u27e8insert_subset.2 \u27e8xt, bt\u27e9, bi.insert hn\u27e9 (subset_insert _ _),\n    exact subset_span (mem_insert _ _) },\n  { refine \u03bb c hc cc c0, \u27e8\u22c3\u2080 c, \u27e8_, _\u27e9, \u03bb x, _\u27e9,\n    { exact sUnion_subset (\u03bb x xc, (hc xc).1) },\n    { exact linear_independent_sUnion_of_directed cc.directed_on (\u03bb x xc, (hc xc).2) },\n    { exact subset_sUnion_of_mem } }\nend\n\nlemma exists_subset_is_basis (hs : linear_independent \u03b1 s) : \u2203b, s \u2286 b \u2227 is_basis \u03b1 b :=\nlet \u27e8b, hb\u2080, hx, hb\u2082, hb\u2083\u27e9 := exists_linear_independent hs (@subset_univ _ _) in\n\u27e8b, hx, hb\u2083, eq_top_iff.2 hb\u2082\u27e9\n\nvariables (\u03b1 \u03b2)\nlemma exists_is_basis : \u2203b : set \u03b2, is_basis \u03b1 b :=\nlet \u27e8b, _, hb\u27e9 := exists_subset_is_basis linear_independent_empty in \u27e8b, hb\u27e9\nvariables {\u03b1 \u03b2}\n\n-- TODO(Mario): rewrite?\nlemma exists_of_linear_independent_of_finite_span {t : finset \u03b2}\n  (hs : linear_independent \u03b1 s) (hst : s \u2286 (span \u03b1 \u2191t : submodule \u03b1 \u03b2)) :\n  \u2203t':finset \u03b2, \u2191t' \u2286 s \u222a \u2191t \u2227 s \u2286 \u2191t' \u2227 t'.card = t.card :=\nhave \u2200t, \u2200(s' : finset \u03b2), \u2191s' \u2286 s \u2192 s \u2229 \u2191t = \u2205 \u2192 s \u2286 (span \u03b1 \u2191(s' \u222a t) : submodule \u03b1 \u03b2) \u2192\n  \u2203t':finset \u03b2, \u2191t' \u2286 s \u222a \u2191t \u2227 s \u2286 \u2191t' \u2227 t'.card = (s' \u222a t).card :=\nassume t, finset.induction_on t\n  (assume s' hs' _ hss',\n    have s = \u2191s', from eq_of_linear_independent_of_span (@one_ne_zero \u03b1 _) hs hs' $ by simpa using hss',\n    \u27e8s', by simp [this]\u27e9)\n  (assume b\u2081 t hb\u2081t ih s' hs' hst hss',\n    have hb\u2081s : b\u2081 \u2209 s,\n      from assume h,\n      have b\u2081 \u2208 s \u2229 \u2191(insert b\u2081 t), from \u27e8h, finset.mem_insert_self _ _\u27e9,\n      by rwa [hst] at this,\n    have hb\u2081s' : b\u2081 \u2209 s', from assume h, hb\u2081s $ hs' h,\n    have hst : s \u2229 \u2191t = \u2205,\n      from eq_empty_of_subset_empty $ subset.trans\n        (by simp [inter_subset_inter, subset.refl]) (le_of_eq hst),\n    classical.by_cases\n      (assume : s \u2286 (span \u03b1 \u2191(s' \u222a t) : submodule \u03b1 \u03b2),\n        let \u27e8u, hust, hsu, eq\u27e9 := ih _ hs' hst this in\n        have hb\u2081u : b\u2081 \u2209 u, from assume h, (hust h).elim hb\u2081s hb\u2081t,\n        \u27e8insert b\u2081 u, by simp [insert_subset_insert hust],\n          subset.trans hsu (by simp), by simp [eq, hb\u2081t, hb\u2081s', hb\u2081u]\u27e9)\n      (assume : \u00ac s \u2286 (span \u03b1 \u2191(s' \u222a t) : submodule \u03b1 \u03b2),\n        let \u27e8b\u2082, hb\u2082s, hb\u2082t\u27e9 := not_subset.mp this in\n        have hb\u2082t' : b\u2082 \u2209 s' \u222a t, from assume h, hb\u2082t $ subset_span h,\n        have s \u2286 (span \u03b1 \u2191(insert b\u2082 s' \u222a t) : submodule \u03b1 \u03b2), from\n          assume b\u2083 hb\u2083,\n          have \u2191(s' \u222a insert b\u2081 t) \u2286 insert b\u2081 (insert b\u2082 \u2191(s' \u222a t) : set \u03b2),\n            by simp [insert_eq, -singleton_union, -union_singleton, union_subset_union, subset.refl, subset_union_right],\n          have hb\u2083 : b\u2083 \u2208 span \u03b1 (insert b\u2081 (insert b\u2082 \u2191(s' \u222a t) : set \u03b2)),\n            from span_mono this (hss' hb\u2083),\n          have s \u2286 (span \u03b1 (insert b\u2081 \u2191(s' \u222a t)) : submodule \u03b1 \u03b2),\n            by simpa [insert_eq, -singleton_union, -union_singleton] using hss',\n          have hb\u2081 : b\u2081 \u2208 span \u03b1 (insert b\u2082 \u2191(s' \u222a t)),\n            from mem_span_insert_exchange (this hb\u2082s) hb\u2082t,\n          by rw [span_insert_eq_span hb\u2081] at hb\u2083; simpa using hb\u2083,\n        let \u27e8u, hust, hsu, eq\u27e9 := ih _ (by simp [insert_subset, hb\u2082s, hs']) hst this in\n        \u27e8u, subset.trans hust $ union_subset_union (subset.refl _) (by simp [subset_insert]),\n          hsu, by rw [finset.union_comm] at hb\u2082t'; simp [eq, hb\u2082t', hb\u2081t, hb\u2081s']\u27e9)),\nhave eq : t.filter (\u03bbx, x \u2208 s) \u222a t.filter (\u03bbx, x \u2209 s) = t,\n  from finset.ext.mpr $ assume x, by by_cases x \u2208 s; simp *,\nlet \u27e8u, h\u2081, h\u2082, h\u27e9 := this (t.filter (\u03bbx, x \u2209 s)) (t.filter (\u03bbx, x \u2208 s))\n  (by simp [set.subset_def]) (by simp [set.ext_iff] {contextual := tt}) (by rwa [eq]) in\n\u27e8u, subset.trans h\u2081 (by simp [subset_def, and_imp, or_imp_distrib] {contextual:=tt}),\n  h\u2082, by rwa [eq] at h\u27e9\n\nlemma exists_finite_card_le_of_finite_of_linear_independent_of_span\n  (ht : finite t) (hs : linear_independent \u03b1 s) (hst : s \u2286 span \u03b1 t) :\n  \u2203h : finite s, h.to_finset.card \u2264 ht.to_finset.card :=\nhave s \u2286 (span \u03b1 \u2191(ht.to_finset) : submodule \u03b1 \u03b2), by simp; assumption,\nlet \u27e8u, hust, hsu, eq\u27e9 := exists_of_linear_independent_of_finite_span hs this in\nhave finite s, from finite_subset u.finite_to_set hsu,\n\u27e8this, by rw [\u2190eq]; exact (finset.card_le_of_subset $ finset.coe_subset.mp $ by simp [hsu])\u27e9\n\nlemma exists_left_inverse_linear_map_of_injective {f : \u03b2 \u2192\u2097[\u03b1] \u03b3}\n  (hf_inj : f.ker = \u22a5) : \u2203g:\u03b3 \u2192\u2097 \u03b2, g.comp f = linear_map.id :=\nbegin\n  rcases exists_is_basis \u03b1 \u03b2 with \u27e8B, hB\u27e9,\n  have : linear_independent \u03b1 (f '' B) :=\n    hB.1.image (by simp [hf_inj]),\n  rcases exists_subset_is_basis this with \u27e8C, BC, hC\u27e9,\n  haveI : inhabited \u03b2 := \u27e80\u27e9,\n  refine \u27e8hC.constr (inv_fun f), hB.ext $ \u03bb b bB, _\u27e9,\n  rw image_subset_iff at BC,\n  simp [constr_basis hC (BC bB)],\n  exact left_inverse_inv_fun (linear_map.ker_eq_bot.1 hf_inj) _\nend\n\nlemma exists_right_inverse_linear_map_of_surjective {f : \u03b2 \u2192\u2097[\u03b1] \u03b3}\n  (hf_surj : f.range = \u22a4) : \u2203g:\u03b3 \u2192\u2097 \u03b2, f.comp g = linear_map.id :=\nbegin\n  rcases exists_is_basis \u03b1 \u03b3 with \u27e8C, hC\u27e9,\n  haveI : inhabited \u03b2 := \u27e80\u27e9,\n  refine \u27e8hC.constr (inv_fun f), hC.ext $ \u03bb c cC, _\u27e9,\n  simp [constr_basis hC cC],\n  exact right_inverse_inv_fun (linear_map.range_eq_top.1 hf_surj) _\nend\n\nset_option class.instance_max_depth 49\nopen submodule linear_map\ntheorem quotient_prod_linear_equiv (p : submodule \u03b1 \u03b2) :\n  nonempty ((p.quotient \u00d7 p) \u2243\u2097[\u03b1] \u03b2) :=\nbegin\n  rcases exists_right_inverse_linear_map_of_surjective p.range_mkq with \u27e8f, hf\u27e9,\n  have mkf : \u2200 x, submodule.quotient.mk (f x) = x := linear_map.ext_iff.1 hf,\n  have fp : \u2200 x, x - f (p.mkq x) \u2208 p :=\n    \u03bb x, (submodule.quotient.eq p).1 (mkf (p.mkq x)).symm,\n  refine \u27e8linear_equiv.of_linear (f.copair p.subtype)\n    (p.mkq.pair (cod_restrict p (linear_map.id - f.comp p.mkq) fp))\n    (by ext; simp) _\u27e9,\n  ext \u27e8\u27e8x\u27e9, y, hy\u27e9; simp,\n  { apply (submodule.quotient.eq p).2,\n    simpa using sub_mem p hy (fp x) },\n  { refine subtype.coe_ext.2 _,\n    simp [mkf, (submodule.quotient.mk_eq_zero p).2 hy] }\nend.\n\nend vector_space\n\nnamespace pi\nopen set linear_map\n\nsection module\nvariables {\u03b9 : Type*} {\u03c6 : \u03b9 \u2192 Type*}\nvariables [ring \u03b1] [\u2200i, add_comm_group (\u03c6 i)] [\u2200i, module \u03b1 (\u03c6 i)] [fintype \u03b9] [decidable_eq \u03b9]\n\nlemma linear_independent_std_basis (s : \u03a0i, set (\u03c6 i)) (hs : \u2200i, linear_independent \u03b1 (s i)) :\n  linear_independent \u03b1 (\u22c3i, std_basis \u03b1 \u03c6 i '' s i) :=\nbegin\n  refine linear_independent_Union_finite _ _,\n  { assume i,\n    refine (linear_independent_image_iff _).2 (hs i),\n    simp only [ker_std_basis, disjoint_bot_right] },\n  { assume i J _ hiJ,\n    simp [(set.Union.equations._eqn_1 _).symm, submodule.span_image, submodule.span_Union],\n    have h\u2081 : map (std_basis \u03b1 \u03c6 i) (span \u03b1 (s i)) \u2264 (\u2a06j\u2208({i} : set \u03b9), range (std_basis \u03b1 \u03c6 j)),\n    { exact (le_supr_of_le i $ le_supr_of_le (set.mem_singleton _) $ map_mono $ le_top) },\n    have h\u2082 : (\u2a06j\u2208J, map (std_basis \u03b1 \u03c6 j) (span \u03b1 (s j))) \u2264 (\u2a06j\u2208J, range (std_basis \u03b1 \u03c6 j)),\n    { exact supr_le_supr (assume i, supr_le_supr $ assume hi, map_mono $ le_top) },\n    exact disjoint_mono h\u2081 h\u2082\n      (disjoint_std_basis_std_basis _ _ _ _ $ set.disjoint_singleton_left.2 hiJ) }\nend\n\nlemma is_basis_std_basis [fintype \u03b9] (s : \u03a0i, set (\u03c6 i)) (hs : \u2200i, is_basis \u03b1 (s i)) :\n  is_basis \u03b1 (\u22c3i, std_basis \u03b1 \u03c6 i '' s i) :=\nbegin\n  refine \u27e8linear_independent_std_basis _ (assume i, (hs i).1), _\u27e9,\n  simp only [submodule.span_Union, submodule.span_image, (assume i, (hs i).2), submodule.map_top,\n    supr_range_std_basis]\nend\n\nsection\nvariables (\u03b1 \u03b9)\nlemma is_basis_fun [fintype \u03b9] : is_basis \u03b1 (\u22c3i, std_basis \u03b1 (\u03bbi:\u03b9, \u03b1) i '' {1}) :=\nis_basis_std_basis _ (assume i, is_basis_singleton_one _)\nend\n\nend module\n\nend pi\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/linear_algebra/basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7096628351212492}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Johannes H\u00f6lzl\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.lattice\nimport Mathlib.data.set.basic\nimport Mathlib.PostPort\n\nuniverses u w v u_1 l \n\nnamespace Mathlib\n\n/-- A family of elements of \u03b1 is directed (with respect to a relation `\u227c` on \u03b1)\n  if there is a member of the family `\u227c`-above any pair in the family.  -/\ndef directed {\u03b1 : Type u} {\u03b9 : Sort w} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (f : \u03b9 \u2192 \u03b1) :=\n  \u2200 (x y : \u03b9), \u2203 (z : \u03b9), r (f x) (f z) \u2227 r (f y) (f z)\n\n/-- A subset of \u03b1 is directed if there is an element of the set `\u227c`-above any\n  pair of elements in the set. -/\ndef directed_on {\u03b1 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : set \u03b1) :=\n  \u2200 (x : \u03b1) (H : x \u2208 s) (y : \u03b1) (H : y \u2208 s), \u2203 (z : \u03b1), \u2203 (H : z \u2208 s), r x z \u2227 r y z\n\ntheorem directed_on_iff_directed {\u03b1 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : set \u03b1} : directed_on r s \u2194 directed r coe := sorry\n\ntheorem directed_on.directed_coe {\u03b1 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : set \u03b1} : directed_on r s \u2192 directed r coe :=\n  iff.mp directed_on_iff_directed\n\ntheorem directed_on_image {\u03b1 : Type u} {\u03b2 : Type v} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} : directed_on r (f '' s) \u2194 directed_on (f \u207b\u00b9'o r) s := sorry\n\ntheorem directed_on.mono {\u03b1 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : set \u03b1} (h : directed_on r s) {r' : \u03b1 \u2192 \u03b1 \u2192 Prop} (H : \u2200 {a b : \u03b1}, r a b \u2192 r' a b) : directed_on r' s := sorry\n\ntheorem directed_comp {\u03b1 : Type u} {\u03b2 : Type v} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {\u03b9 : Sort u_1} {f : \u03b9 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1} : directed r (g \u2218 f) \u2194 directed (g \u207b\u00b9'o r) f :=\n  iff.rfl\n\ntheorem directed.mono {\u03b1 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b1 \u2192 \u03b1 \u2192 Prop} {\u03b9 : Sort u_1} {f : \u03b9 \u2192 \u03b1} (H : \u2200 (a b : \u03b1), r a b \u2192 s a b) (h : directed r f) : directed s f := sorry\n\ntheorem directed.mono_comp {\u03b1 : Type u} {\u03b2 : Type v} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) {\u03b9 : Sort u_1} {rb : \u03b2 \u2192 \u03b2 \u2192 Prop} {g : \u03b1 \u2192 \u03b2} {f : \u03b9 \u2192 \u03b1} (hg : \u2200 {x y : \u03b1}, r x y \u2192 rb (g x) (g y)) (hf : directed r f) : directed rb (g \u2218 f) :=\n  iff.mpr directed_comp (directed.mono hg hf)\n\n/-- A monotone function on a sup-semilattice is directed. -/\ntheorem directed_of_sup {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_sup \u03b1] {f : \u03b1 \u2192 \u03b2} {r : \u03b2 \u2192 \u03b2 \u2192 Prop} (H : \u2200 {i j : \u03b1}, i \u2264 j \u2192 r (f i) (f j)) : directed r f :=\n  fun (a b : \u03b1) => Exists.intro (a \u2294 b) { left := H le_sup_left, right := H le_sup_right }\n\n/-- An antimonotone function on an inf-semilattice is directed. -/\ntheorem directed_of_inf {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_inf \u03b1] {r : \u03b2 \u2192 \u03b2 \u2192 Prop} {f : \u03b1 \u2192 \u03b2} (hf : \u2200 (a\u2081 a\u2082 : \u03b1), a\u2081 \u2264 a\u2082 \u2192 r (f a\u2082) (f a\u2081)) : directed r f :=\n  fun (x y : \u03b1) => Exists.intro (x \u2293 y) { left := hf (x \u2293 y) x inf_le_left, right := hf (x \u2293 y) y inf_le_right }\n\n/-- A `preorder` is a `directed_order` if for any two elements `i`, `j`\nthere is an element `k` such that `i \u2264 k` and `j \u2264 k`. -/\nclass directed_order (\u03b1 : Type u) \nextends preorder \u03b1\nwhere\n  directed : \u2200 (i j : \u03b1), \u2203 (k : \u03b1), i \u2264 k \u2227 j \u2264 k\n\nprotected instance linear_order.to_directed_order (\u03b1 : Type u_1) [linear_order \u03b1] : directed_order \u03b1 :=\n  directed_order.mk sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/directed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7096553540954028}}
{"text": "import data.nat.modeq\n\nimport ent.modeq\nimport ent.parity\n\nopen nat\n\nnamespace gcd\n  theorem gcd_row_op (a b k : \u2115) : gcd a b = gcd a (a * k + b) :=\n    have mods : b \u2261 a * k + b [MOD a] := modeq.modeq_of_rep.symm,\n    calc gcd a b = gcd (b % a) a            : by rw gcd_rec\n         ...     = gcd ((a * k + b) % a) a  : begin unfold modeq at mods, rw mods end\n         ...     = gcd a (a * k + b)        : by rw \u2190gcd_rec\n\n  lemma sum_difference_sum {a c : \u2115} (H : a \u2264 c) : (c - a) + (c + a) = 2 * c :=\n    calc (c - a) + (c + a) = (c - a) + (a + c)  : by rw add_comm a c\n         ...               = ((c - a) + a) + c  : by rw add_assoc\n         ...               = (a + (c - a)) + c  : by rw add_comm (c - a) a\n         ...               = c + c              : by rw add_sub_of_le H\n         ...               = 2 * c              : by rw two_mul\n\n  lemma sum_difference_difference {a c : \u2115} (H : a \u2264 c) : (c + a) - (c - a) = 2 * a :=\n    calc (c + a) - (c - a) = (a + c) - (c - a)  : by rw add_comm c a\n         ...               = a + (c - (c - a))  : by rw nat.add_sub_assoc (sub_le c a) a\n         ...               = a + a              : by rw nat.sub_sub_self H\n         ...               = 2 * a              : by rw two_mul\n\n  lemma sum_difference_of_coprime (a c : \u2115) (H : a \u2264 c) : coprime a c \u2192 gcd (c - a) (c + a) \u2223 2 :=\n    begin\n      intros ac,\n      let g := gcd (c - a) (c + a),\n      cases gcd_dvd (c - a) (c + a) with gminus gplus,\n      have g2c : g \u2223 2 * c := by rw \u2190sum_difference_sum H; apply dvd_add; assumption,\n      have : c - a \u2264 c + a := trans (nat.sub_le c a) (le_add_right c a),\n      have g2a : g \u2223 2 * a := by rw \u2190sum_difference_difference H; apply nat.dvd_sub this; assumption,\n      have g2ac : g \u2223 gcd (2 * a) (2 * c) := dvd_gcd g2a g2c,\n      rw [gcd_mul_left 2 a c, ac.gcd_eq_one] at g2ac,\n      exact g2ac\n    end\n\n  lemma sum_difference_of_coprime_odd (a c : \u2115) (H : a \u2264 c) : coprime a c \u2192 odd a \u2192 odd c \u2192 gcd (c - a) (c + a) = 2 :=\n    begin\n      intros ac oa oc,\n      apply nat.dvd_antisymm,\n      { exact sum_difference_of_coprime a c H ac },\n      { exact\n         dvd_gcd (even_iff_two_dvd.mp (odd_minus_odd_is_even H oa oc))\n                 (even_iff_two_dvd.mp (odd_plus_odd_is_even oc oa))\n      }\n    end\n\n  lemma coprime_iff_squares_coprime {x y : \u2115} : coprime (x^2) (y^2) \u2194 coprime x y :=\n    iff.intro\n      (\u03bb H, coprime.coprime_dvd_left self_divides_square\n            (coprime.coprime_dvd_right self_divides_square H))\n      (coprime.pow 2 2)\nend gcd\n\n\nlemma coprime_square_product {x y z : \u2115} : x * y = z^2 \u2192 coprime x y \u2192\n                                           \u2203 x1 y1, x = x1^2 \u2227 y = y1^2 :=\n  begin\n    intros,\n    rw nat.pow_two at a,\n    cases eq_zero_or_pos x with xzero xpos,\n    { -- x = 0\n      have y1 : y = 1 :=\n        begin simp [xzero, coprime, gcd_zero_left] at a_1, exact a_1 end,\n      existsi [0, 1],\n      split,\n      { rw xzero, refl }, { rw y1, refl }\n    },\n    -- x > 0\n    have H : x \u2223 z * z := begin rw \u2190a, apply dvd_mul_right end,\n    cases exists_eq_prod_and_dvd_and_dvd H with x1 H1,\n    cases H1 with x2,\n    cases H1_h,\n    cases H1_h_right,\n    existsi [x1, (z/x1)],\n    let y1 := z / x1,\n    let y2 := z / x2,\n    have xyz1 : x1 * y1 = z :=\n      begin\n        show x1 * (z / x1) = z,\n        apply nat.mul_div_cancel',\n        exact H1_h_right_left\n      end,\n    have xyz2 : x2 * y2 = z :=\n      begin\n        show x2 * (z / x2) = z,\n        apply nat.mul_div_cancel',\n        exact H1_h_right_right\n      end,\n    have y1y2 : y = y1 * y2 :=\n      begin\n        show y = (z / x1) * (z / x2),\n        rw [\u2190nat.mul_left_inj xpos, a, H1_h_left],\n        have res : z * z = x1 * x2 * (z / x1 * (z / x2)) :=\n          calc z * z = (x1 * (z / x1)) * z      : by rw nat.mul_div_cancel' H1_h_right_left\n               ...   = (x1 * (z / x1)) * (x2 * (z / x2)) : by rw nat.mul_div_cancel' H1_h_right_right\n               ...   = x1 * ((z / x1) * (x2 * (z / x2))) : by rw mul_assoc\n               ...   = x1 * (((z / x1) * x2) * (z / x2)) : by rw mul_assoc\n               ...   = x1 * ((x2 * (z / x1)) * (z / x2)) : by rw mul_comm (z / x1) x2\n               ...   = x1 * (x2 * ((z / x1) * (z / x2))) : by rw mul_assoc\n               ...   = (x1 * x2) * ((z / x1) * (z / x2)) : by rw mul_assoc,\n        exact res\n      end,\n    have xeq : x1 = x2 :=\n      begin\n        rw [H1_h_left, y1y2] at a_1,\n        have cx1y2 : gcd x1 y2 = 1 := a_1.coprime_mul_right.coprime_mul_left_right,\n        have cx2y1 : gcd x2 y1 = 1 := a_1.coprime_mul_left.coprime_mul_right_right,\n        have g2 : gcd x z = x2 :=\n          begin\n            rw [H1_h_left, \u2190xyz2, mul_comm x2 y2],\n            calc gcd (x1 * x2) (y2 * x2) = gcd x1 y2 * x2 : by rw gcd_mul_right\n                 ...                     = 1 * x2         : by rw cx1y2\n                 ...                     = x2             : by simp\n          end,\n        have g1 : gcd x z = x1 :=\n          begin\n            rw [H1_h_left, \u2190xyz1],\n            calc gcd (x1 * x2) (x1 * y1) = x1 * gcd x2 y1 : by rw gcd_mul_left\n                 ...                     = x1 * 1         : by rw cx2y1\n                 ...                     = x1             : by simp\n          end,\n        exact (symm g1).trans g2\n      end,\n    split,\n    { rw [nat.pow_two], rwa \u2190xeq at H1_h_left },\n    { have yeq : y1 = y2 := begin show z / x1 = z / x2, rw xeq end,\n      rw [nat.pow_two],\n      calc y = y1 * y2                : y1y2\n           ... = y1 * y1              : by rw yeq\n           ... = (z / x1) * (z / x1)  : by simp\n    }\n  end\n\n/-\n\nx y = z^2, x _|_ y \n\nx = z1 z2\ny = (z / z1) (z / z2)\n\nIf p divides z2 more times than z1 then p will also divide z / z1 at least once,\nand then z / z1 and z2 will not be relatively prime.\n\ngcd(z2, z/z1) = 1 => gcd(z1 z2, z) = z1\ngcd(z1, z/z2) = 1 => gcd(z1 z2, z) = z2\n\n-/\n", "meta": {"author": "rwbarton", "repo": "lean-elementary-number-theory", "sha": "fabef0737fd2486e3f24f9e04652db4c182d5425", "save_path": "github-repos/lean/rwbarton-lean-elementary-number-theory", "path": "github-repos/lean/rwbarton-lean-elementary-number-theory/lean-elementary-number-theory-fabef0737fd2486e3f24f9e04652db4c182d5425/src/ent/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7096553540954027}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n\nVery simple (sqrt n) function that returns s s.t.\n    s*s \u2264 n \u2264 s*s + s + s\n-/\nimport data.nat.order data.nat.sub\n\nnamespace nat\nopen decidable\n\n-- This is the simplest possible function that just performs a linear search\ndefinition sqrt_aux : nat \u2192 nat \u2192 nat\n| 0        n := 0\n| (succ s) n := if (succ s)*(succ s) \u2264 n then succ s else sqrt_aux s n\n\ntheorem sqrt_aux_succ_of_pos {s n} : (succ s)*(succ s) \u2264 n \u2192 sqrt_aux (succ s) n = (succ s) :=\nassume h, if_pos h\n\ntheorem sqrt_aux_succ_of_neg {s n} : \u00ac (succ s)*(succ s) \u2264 n \u2192 sqrt_aux (succ s) n = sqrt_aux s n :=\nassume h, if_neg h\n\ntheorem sqrt_aux_of_le : \u2200 {s n : nat}, s * s \u2264 n \u2192 sqrt_aux s n = s\n| 0        n h := rfl\n| (succ s) n h := by rewrite [sqrt_aux_succ_of_pos h]\n\ntheorem sqrt_aux_le : \u2200 (s n), sqrt_aux s n \u2264 s\n| 0        n := !zero_le\n| (succ s) n := or.elim (em ((succ s)*(succ s) \u2264 n))\n  (\u03bb h, begin unfold sqrt_aux, rewrite [if_pos h] end)\n  (\u03bb h,\n    have sqrt_aux s n \u2264 succ s, from le.step (sqrt_aux_le s n),\n    begin unfold sqrt_aux, rewrite [if_neg h], assumption end)\n\ndefinition sqrt (n : nat) : nat :=\nsqrt_aux n n\n\ntheorem sqrt_aux_lower : \u2200 {s n : nat}, s \u2264 n \u2192 sqrt_aux s n * sqrt_aux s n \u2264 n\n| 0        n h := h\n| (succ s) n h := by_cases\n  (\u03bb h\u2081 : (succ s)*(succ s) \u2264 n,   by rewrite [sqrt_aux_succ_of_pos h\u2081]; exact h\u2081)\n  (\u03bb h\u2082 : \u00ac (succ s)*(succ s) \u2264 n,\n     have aux : s \u2264 n, from le_of_succ_le h,\n     by rewrite [sqrt_aux_succ_of_neg h\u2082]; exact (sqrt_aux_lower aux))\n\ntheorem sqrt_lower (n : nat) : sqrt n * sqrt n \u2264 n :=\nsqrt_aux_lower (le.refl n)\n\ntheorem sqrt_aux_upper : \u2200 {s n : nat}, n \u2264 s*s + s + s \u2192 n \u2264 sqrt_aux s n * sqrt_aux s n + sqrt_aux s n + sqrt_aux s n\n| 0         n   h := h\n| (succ s)  n   h := by_cases\n  (\u03bb h\u2081 : (succ s)*(succ s) \u2264 n,\n    by rewrite [sqrt_aux_succ_of_pos h\u2081]; exact h)\n  (\u03bb h\u2082 : \u00ac (succ s)*(succ s) \u2264 n,\n    have h\u2083 : n < (succ s) * (succ s), from lt_of_not_ge h\u2082,\n    have h\u2084 : n \u2264 s * s + s + s, by rewrite [succ_mul_succ_eq at h\u2083]; exact le_of_lt_succ h\u2083,\n    by rewrite [sqrt_aux_succ_of_neg h\u2082]; exact (sqrt_aux_upper h\u2084))\n\ntheorem sqrt_upper (n : nat) : n \u2264 sqrt n * sqrt n + sqrt n + sqrt n :=\nhave aux : n \u2264 n*n + n + n, from le_add_of_le_right (le_add_of_le_left (le.refl n)),\nsqrt_aux_upper aux\n\nprivate theorem le_squared : \u2200 (n : nat), n \u2264 n*n\n| 0        := !le.refl\n| (succ n) :=\n  have aux\u2081 : 1 \u2264 succ n, from succ_le_succ !zero_le,\n  have aux\u2082 : 1 * succ n \u2264 succ n * succ n, from nat.mul_le_mul aux\u2081 !le.refl,\n  by rewrite [one_mul at aux\u2082]; exact aux\u2082\n\nprivate theorem lt_squared : \u2200 {n : nat}, n > 1 \u2192 n < n * n\n| 0               h := absurd h dec_trivial\n| 1               h := absurd h dec_trivial\n| (succ (succ n)) h :=\n  have 1 < succ (succ n),                                   from dec_trivial,\n  have succ (succ n) * 1 < succ (succ n) * succ (succ n), from mul_lt_mul_of_pos_left this dec_trivial,\n  by rewrite [mul_one at this]; exact this\n\ntheorem sqrt_le (n : nat) : sqrt n \u2264 n :=\ncalc sqrt n \u2264 sqrt n * sqrt n : le_squared\n        ... \u2264 n               : sqrt_lower\n\ntheorem eq_zero_of_sqrt_eq_zero {n : nat} : sqrt n = 0 \u2192 n = 0 :=\nsuppose sqrt n = 0,\nhave n \u2264 sqrt n * sqrt n + sqrt n + sqrt n, from !sqrt_upper,\nhave n \u2264 0, by rewrite [*`sqrt n = 0` at this]; exact this,\neq_zero_of_le_zero this\n\ntheorem le_three_of_sqrt_eq_one {n : nat} : sqrt n = 1 \u2192 n \u2264 3 :=\nsuppose sqrt n = 1,\nhave n \u2264 sqrt n * sqrt n + sqrt n + sqrt n, from !sqrt_upper,\nshow   n \u2264 3, by rewrite [*`sqrt n = 1` at this]; exact this\n\ntheorem sqrt_lt : \u2200 {n : nat}, n > 1 \u2192 sqrt n < n\n| 0     h := absurd h dec_trivial\n| 1     h := absurd h dec_trivial\n| 2     h := dec_trivial\n| 3     h := dec_trivial\n| (n+4) h :=\n  have sqrt (n+4) > 1, from by_contradiction\n    (suppose \u00ac sqrt (n+4) > 1,\n     have sqrt (n+4) \u2264 1, from le_of_not_gt this,\n       or.elim (eq_or_lt_of_le this)\n         (suppose sqrt (n+4) = 1,\n          have n+4 \u2264 3, from le_three_of_sqrt_eq_one this,\n          absurd this dec_trivial)\n         (suppose sqrt (n+4) < 1,\n          have sqrt (n+4) = 0, from eq_zero_of_le_zero (le_of_lt_succ this),\n          have n + 4 = 0,      from eq_zero_of_sqrt_eq_zero this,\n          absurd this dec_trivial)),\n  calc sqrt (n+4) < sqrt (n+4) * sqrt (n+4) : lt_squared this\n              ... \u2264 n+4                     : sqrt_lower\n\ntheorem sqrt_pos_of_pos {n : nat} : n > 0 \u2192 sqrt n > 0 :=\nsuppose n > 0,\nhave sqrt n \u2260 0, from\n  suppose sqrt n = 0,\n  have n = 0, from eq_zero_of_sqrt_eq_zero this,\n  by subst n; exact absurd `0 > 0` !lt.irrefl,\npos_of_ne_zero this\n\ntheorem sqrt_aux_offset_eq {n k : nat} (h\u2081 : k \u2264 n + n) : \u2200 {s}, s \u2265 n \u2192 sqrt_aux s (n*n + k) = n\n| 0        h\u2082 :=\n  have neqz : n = 0, from eq_zero_of_le_zero h\u2082,\n  by rewrite neqz\n| (succ s) h\u2082 := by_cases\n  (\u03bb hl : (succ s)*(succ s) \u2264 n*n + k,\n     have l\u2081 : n*n + k \u2264 n*n + n + n,       from by rewrite [add.assoc]; exact (add_le_add_left h\u2081 (n*n)),\n     have l\u2082 : n*n + k < n*n + n + n + 1,   from lt_succ_of_le l\u2081,\n     have l\u2083 : n*n + k < (succ n)*(succ n), by rewrite [-succ_mul_succ_eq at l\u2082]; exact l\u2082,\n     have l\u2084 : (succ s)*(succ s) < (succ n)*(succ n), from lt_of_le_of_lt hl l\u2083,\n     have ng : \u00ac succ s > (succ n), from\n       assume g : succ s > succ n,\n         have g\u2081 : (succ s)*(succ s) > (succ n)*(succ n), from mul_lt_mul_of_le_of_le g g,\n         absurd (lt.trans g\u2081 l\u2084) !lt.irrefl,\n     have sslesn  : succ s \u2264 succ n, from le_of_not_gt ng,\n     have ssnesn  : succ s \u2260 succ n, from\n       assume sseqsn : succ s = succ n,\n         by rewrite [sseqsn at l\u2084]; exact (absurd l\u2084 !lt.irrefl),\n     have   sslen : s < n, from lt_of_succ_lt_succ (lt_of_le_of_ne sslesn ssnesn),\n     have sseqn : succ s = n, from le.antisymm sslen h\u2082,\n     by rewrite [sqrt_aux_succ_of_pos hl]; exact sseqn)\n  (\u03bb hg : \u00ac (succ s)*(succ s) \u2264 n*n + k,\n    or.elim (eq_or_lt_of_le h\u2082)\n     (\u03bb neqss : n = succ s,\n        have p : n*n \u2264 n*n + k, from !le_add_right,\n        have n : \u00ac n*n \u2264 n*n + k, by rewrite [-neqss at hg]; exact hg,\n        absurd p n)\n     (\u03bb sgen : succ s > n,\n        by rewrite [sqrt_aux_succ_of_neg hg]; exact (sqrt_aux_offset_eq (le_of_lt_succ sgen))))\n\ntheorem sqrt_offset_eq {n k : nat} : k \u2264 n + n \u2192 sqrt (n*n + k) = n :=\nassume h,\nhave h\u2081 : n \u2264 n*n + k, from le.trans !le_squared !le_add_right,\nsqrt_aux_offset_eq h h\u2081\n\ntheorem sqrt_eq (n : nat) : sqrt (n*n) = n :=\nsqrt_offset_eq !zero_le\n\ntheorem mul_square_cancel {a b : nat} : a*a = b*b \u2192 a = b :=\nassume h,\nhave aux : sqrt (a*a) = sqrt (b*b), by rewrite h,\nby rewrite [*sqrt_eq at aux]; exact aux\nend nat\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/nat/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7096553520345134}}
{"text": "import lib.m154\n\n/-\n# Un apercu du cours de Logique et d\u00e9monstations assist\u00e9es par ordinateur\n\nCe fichier ne contient pas d'exercice, son but est de montrer \u00e0 quoi\nva ressembler une d\u00e9monstration expliqu\u00e9e \u00e0 l'ordinateur au milieu du semestre.\nLe but de ce cours est de parvenir \u00e0 concevoir et r\u00e9diger ce genre de\nd\u00e9monstration sur papier.\n\nLa syntaxe et les diff\u00e9rentes commandes seront expliqu\u00e9es au fur et \u00e0 mesure.\nPour l'instant, il suffit de lire les d\u00e9finitions, l'\u00e9nonc\u00e9 et la d\u00e9monstration\nci-dessous et de ce convaincre que cela rappelle des souvenirs du cours d'analyse\ndu premier semestre.\n\nCe fichier est pr\u00e9vu pour \u00eatre ouvert dans l'\u00e9diteur Visual Studio Code (ou VSCodium).\nLa partie droite de l'\u00e9cran doit afficher une zone intitul\u00e9e \u00ab Lean Infoview \u00bb.\nSi ce n'est pas le cas, la combinaison de touche Ctrl-Maj-Entr\u00e9e \n(ou Cmd-Maj-Entr\u00e9e sur un Mac) doit la faire appara\u00eetre. Si cette zone\nInfoview se retrouve accidentellement dans un onglet difficile d'acc\u00e8s, le plus \nsimple est de fermer l'onglet et de rouvrir la zone par Ctrl-Maj-Entr\u00e9e.\n\nLorsque le curseur se trouve dans la d\u00e9monstration, la zone \u00ab Lean Infoview \u00bb\naffiche les objets et hypoth\u00e8ses intervenant \u00e0 ce stade de la d\u00e9monstration,\nainsi que le ou les buts de la d\u00e9monstration.\n-/\n\n-- D\u00e9finition de \u00ab f est continue en x\u2080 \u00bb\n-- Lean n'a pas besoin de parenth\u00e8se dans f(x)\ndef continue_en (f : \u211d \u2192 \u211d) (x\u2080 : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192 |f x - f x\u2080| \u2264 \u03b5\n\n-- Une suite u est une fonction de \u2115 dans \u211d\n-- D\u00e9finition de \u00ab u tend vers l \u00bb\ndef limite_suite (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\n-- Soit f une fonction, u une suite de r\u00e9els et x\u2080 un r\u00e9el.\n-- Si f est continue en x\u2080 et si la suite u tend vers x\u2080 alors la suite f \u2218 u,\n-- qui envoie n sur f (u n), tend vers f x\u2080\nexample (f : \u211d \u2192 \u211d) (u : \u2115 \u2192 \u211d) (x\u2080 : \u211d) \n  (hf : continue_en f x\u2080) (hu : limite_suite u x\u2080) :\n  limite_suite (f \u2218 u) (f x\u2080) :=\nbegin\n  Montrons que \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |(f \u2218 u) n - f x\u2080| \u2264 \u03b5,\n  Soit \u03b5 > 0,\n  Par hf appliqu\u00e9 \u00e0 [\u03b5, \u03b5_pos] on obtient \u03b4 : \u211d tel que \n    (\u03b4_pos : \u03b4 > 0) (h\u03b4f : \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192 |f x - f x\u2080| \u2264 \u03b5),\n  Par hu appliqu\u00e9 \u00e0 [\u03b4, \u03b4_pos] on obtient N : \u2115 tel que\n    (hNu : \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b4),\n  Montrons que N convient : \u2200 n \u2265 N, |(f \u2218 u) n - f x\u2080| \u2264 \u03b5,\n  Soit n \u2265 N,\n  Montrons que |(f \u2218 u) n - f x\u2080| \u2264 \u03b5,\n  Par h\u03b4f il suffit de montrer que |u n - x\u2080| \u2264 \u03b4,\n  On conclut par hNu appliqu\u00e9 \u00e0 [n, n_ge],\nend\n\n", "meta": {"author": "PatrickMassot", "repo": "MDD154", "sha": "00defe82a4b6b7992ed522a92f62abd685e8c943", "save_path": "github-repos/lean/PatrickMassot-MDD154", "path": "github-repos/lean/PatrickMassot-MDD154/MDD154-00defe82a4b6b7992ed522a92f62abd685e8c943/src/00_apercu.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7096553475529644}}
{"text": "/-\nCopyright (c) 2021 Antoine Labelle. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Labelle\n-/\nimport algebra.big_operators.basic\nimport algebra.big_operators.order\nimport data.fintype.card\nimport data.finset.sort\nimport data.fin.interval\nimport tactic.linarith\nimport tactic.by_contra\n\n/-!\n# IMO 1994 Q1\n\nLet `m` and `n` be two positive integers.\nLet `a\u2081, a\u2082, ..., a\u2098` be `m` different numbers from the set `{1, 2, ..., n}`\nsuch that for any two indices `i` and `j` with `1 \u2264 i \u2264 j \u2264 m` and `a\u1d62 + a\u2c7c \u2264 n`,\nthere exists an index `k` such that `a\u1d62 + a\u2c7c = a\u2096`.\nShow that `(a\u2081+a\u2082+...+a\u2098)/m \u2265 (n+1)/2`\n\n# Sketch of solution\n\nWe can order the numbers so that `a\u2081 \u2264 a\u2082 \u2264 ... \u2264 a\u2098`.\nThe key idea is to pair the numbers in the sum and show that `a\u1d62 + a\u2098\u208a\u2081\u208b\u1d62 \u2265 n+1`.\nIndeed, if we had `a\u1d62 + a\u2098\u208a\u2081\u208b\u1d62 \u2264 n`, then `a\u2081 + a\u2098\u208a\u2081\u208b\u1d62, a\u2082 + a\u2098\u208a\u2081\u208b\u1d62, ..., a\u1d62 + a\u2098\u208a\u2081\u208b\u1d62`\nwould be `m` elements of the set of `a\u1d62`'s all larger than `a\u2098\u208a\u2081\u208b\u1d62`, which is impossible.\n-/\n\nopen_locale big_operators\n\nopen finset\n\nlemma tedious (m : \u2115) (k : fin (m+1)) : m - (m + (m + 1 - \u2191k)) % (m + 1) = \u2191k  :=\nbegin\n  cases k with k hk,\n  rw [nat.lt_succ_iff,le_iff_exists_add] at hk,\n  rcases hk with \u27e8c, rfl\u27e9,\n  have : k + c + (k + c + 1 - k) = c + (k + c + 1),\n  { simp only [add_assoc, add_tsub_cancel_left], ring_nf, },\n  rw [fin.coe_mk, this, nat.add_mod_right, nat.mod_eq_of_lt, nat.add_sub_cancel],\n  linarith\nend\n\ntheorem imo1994_q1 (n : \u2115) (m : \u2115) (A : finset \u2115) (hm : A.card = m + 1)\n  (hrange : \u2200 a \u2208 A, 0 < a \u2227 a \u2264 n) (hadd : \u2200 (a b \u2208 A), a + b \u2264 n \u2192 a + b \u2208 A) :\n  (m+1)*(n+1) \u2264 2*(\u2211 x in A, x) :=\nbegin\n  set a := order_emb_of_fin A hm,  -- We sort the elements of `A`\n  have ha : \u2200 i, a i \u2208 A := \u03bb i, order_emb_of_fin_mem A hm i,\n  set rev := equiv.sub_left (fin.last m), -- `i \u21a6 m-i`\n\n  -- We reindex the sum by fin (m+1)\n  have : \u2211 x in A, x = \u2211 i : fin (m+1), a i,\n  { convert sum_image (\u03bb x hx y hy, (order_embedding.eq_iff_eq a).1),\n    rw \u2190coe_inj, simp },\n  rw this, clear this,\n\n  -- The main proof is a simple calculation by rearranging one of the two sums\n  suffices hpair : \u2200 k \u2208 univ, a k + a (rev k) \u2265 n+1,\n  calc 2 * \u2211 i : fin (m+1), a i\n      = \u2211 i : fin (m+1), a i + \u2211 i : fin (m+1), a i       : two_mul _\n  ... = \u2211 i : fin (m+1), a i + \u2211 i : fin (m+1), a (rev i) : by rw equiv.sum_comp rev\n  ... = \u2211 i : fin (m+1), (a i + a (rev i))                : sum_add_distrib.symm\n  ... \u2265 \u2211 i : fin (m+1), (n+1)                            : sum_le_sum hpair\n  ... = (m+1) * (n+1)                                     : by simp,\n\n  -- It remains to prove the key inequality, by contradiction\n  rintros k -,\n  by_contra' h : a k + a (rev k) < n + 1,\n\n  -- We exhibit `k+1` elements of `A` greater than `a (rev k)`\n  set f : fin (m+1) \u21aa \u2115 := \u27e8\u03bb i, a i + a (rev k),\n  begin\n    apply injective_of_le_imp_le,\n    intros i j hij,\n    rwa [add_le_add_iff_right, a.map_rel_iff] at hij,\n  end\u27e9,\n\n  -- Proof that the `f i` are greater than `a (rev k)` for `i \u2264 k`\n  have hf : map f (Icc 0 k) \u2286 map a.to_embedding (Ioc (rev k) (fin.last m)),\n  { intros x hx,\n    simp at h hx \u22a2,\n    rcases hx with \u27e8i, \u27e8hi, rfl\u27e9\u27e9,\n    have h1 : a i + a (fin.last m - k) \u2264 n,\n    { linarith only [h, a.monotone hi.2] },\n    have h2 : a i + a (fin.last m - k) \u2208 A := hadd _ _ (ha _) (ha _) h1,\n    rw [\u2190mem_coe, \u2190range_order_emb_of_fin A hm, set.mem_range] at h2,\n    cases h2 with j hj,\n    use j,\n    refine \u27e8\u27e8_, fin.le_last j\u27e9, hj\u27e9,\n    rw [\u2190 a.strict_mono.lt_iff_lt, hj],\n    simpa using (hrange (a i) (ha i)).1 },\n\n  -- A set of size `k+1` embed in one of size `k`, which yields a contradiction\n  have ineq := card_le_of_subset hf,\n  simp [fin.coe_sub, tedious] at ineq,\n  contradiction ,\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/archive/imo/imo1994_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.7905303211371899, "lm_q1q2_score": 0.7096553410619216}}
{"text": "import basic_defs_world.level1 --hide\nopen set --hide\nnamespace topological_space --hide\n\n\n/-\n# Level 2: Union of two open sets\n-/\n\n/- Lemma\nThe union of two open sets is open.\n-/\nlemma open_of_union {X : Type} [topological_space X] {U V : set X}\n(hU : is_open U) (hV : is_open V): is_open (U \u222a V) :=\nbegin\n  let I : set (set X) := {U, V},\n  have H : \u22c3\u2080 I = U \u222a V := sUnion_pair U V,\n  rw \u2190H,\n  apply union I,\n  intros B hB,\n  replace hB : B = U \u2228 B = V, by tauto,\n  cases hB; {rw hB, assumption},\n\n\n\n\nend\n\nend topological_space --hide\n", "meta": {"author": "joan-ferrer", "repo": "topologygameprova", "sha": "b0c0a320d52b77abeed145052bac15fa710b94be", "save_path": "github-repos/lean/joan-ferrer-topologygameprova", "path": "github-repos/lean/joan-ferrer-topologygameprova/topologygameprova-b0c0a320d52b77abeed145052bac15fa710b94be/src/basic_defs_world/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404116305639, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.7096126734748941}}
{"text": "import LeanUtils\nopen Nat\n\ntheorem square_of_even_number_is_even (m : Nat) (h\u2080 : even m) : (even (m ^ 2)) := by\n\n  have \u27e8n, h\u2081\u27e9 : \u2203 (n : Nat), m = 2 * n := by \n    simp at *; assumption\n  have h\u2082 : m^2 = 2*(2*n^2) := by \n    calc\n      m^2 = (2*n)^2 := by \n        repeat (first | ring | simp_all)\n      _ = 4*n^2 := by \n        repeat (first | ring | simp_all)\n      _ = 2*(2*n^2) := by \n        repeat (first | ring | simp_all)\n  \n  simp_all\n\n", "meta": {"author": "Augustindou", "repo": "natural2lean-lean-project-template", "sha": "62c1d7cf8b2f0cbffd84f240c3e2cd89b55f3c03", "save_path": "github-repos/lean/Augustindou-natural2lean-lean-project-template", "path": "github-repos/lean/Augustindou-natural2lean-lean-project-template/natural2lean-lean-project-template-62c1d7cf8b2f0cbffd84f240c3e2cd89b55f3c03/examples/working/m-sqr-even/theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.7096126589945485}}
{"text": "import algebra.divisibility\nimport algebra.ring\nimport data.real.basic\nimport algebra.order.ring\nimport tactic.linarith\n\ndef divides (a : \u2124) (b : \u2124) := exists c : \u2124, a * c = b\n\ntheorem s1p4 (a : \u2124) : divides a a :=\nbegin \n  rw divides,\n  use 1,\n  ring,\nend \n\ntheorem s1p5 (a b c : \u2124) (h : divides a b) : divides a (b*c) :=\nbegin\n  rw divides,\n  cases h with x,\n  have H : c*x*a=b*c,\n  { rw mul_assoc, rw mul_comm x a, rw h_h, ring },\n  use (x*c),\n  ring_nf,\n  exact H\nend\n\ntheorem s1p6 (k a b : \u2124) (ha : divides k a) (hb : divides k b) : divides k (a+b) :=\nbegin\n  rw divides,\n  cases ha with x,\n  cases hb with y,\n  use (x+y),\n  rw left_distrib,\n  rw ha_h, \n  rw hb_h,\nend\n\ntheorem s1p7 (a b c : \u2124) (ha : divides a b) (hb : divides b c) : divides a c :=\nbegin\n  rw divides,\n  cases ha with x,\n  cases hb with y,\n  use x*y,\n  rw <-mul_assoc,\n  rw ha_h,\n  rw hb_h,\nend\n\ntheorem s1p8 (a : \u2124) : a * 0 = 0 :=\nbegin\n  sorry\nend", "meta": {"author": "mbarz6", "repo": "ross_lean", "sha": "462ea6cfedb3370ca3f3a6d996b542056ede52c7", "save_path": "github-repos/lean/mbarz6-ross_lean", "path": "github-repos/lean/mbarz6-ross_lean/ross_lean-462ea6cfedb3370ca3f3a6d996b542056ede52c7/src/pset1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7096126569770818}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.rat.order\nimport Mathlib.data.int.sqrt\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Square root on rational numbers\n\nThis file defines the square root function on rational numbers, `rat.sqrt` and proves several theorems about it.\n\n-/\n\nnamespace rat\n\n\n/-- Square root function on rational numbers, defined by taking the (integer) square root of the\nnumerator and the square root (on natural numbers) of the denominator. -/\ndef sqrt (q : \u211a) : \u211a :=\n  mk (int.sqrt (num q)) \u2191(nat.sqrt (denom q))\n\ntheorem sqrt_eq (q : \u211a) : sqrt (q * q) = abs q := sorry\n\ntheorem exists_mul_self (x : \u211a) : (\u2203 (q : \u211a), q * q = x) \u2194 sqrt x * sqrt x = x := sorry\n\ntheorem sqrt_nonneg (q : \u211a) : 0 \u2264 sqrt q := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/rat/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.7096126515335396}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport topology.instances.real\nimport topology.subset_properties\n\nvariables (X Y : Type) [topological_space X] [topological_space Y] (f : X \u2192 Y)\n\nopen filter set\n\nopen_locale filter -- para acceder a la notaci\u00f3n \ud835\udcdf\nopen_locale topology -- para acceder a la notaci\u00f3n \ud835\udcdd \n\n/-\n## Filtro de entornos\nSi `\u03b1` es un espacio topol\u00f3gico y `a : \u03b1`, entonces `\ud835\udcdd a` es el filtro sobre `\u03b1`\ndeterminado por `X \u2208 \ud835\udcdd a` si y s\u00f3lo si `X` contiene un entorno abierto de `a`, \no equivalentemente, si `a` est\u00e1 en el interior de `X`.\n\nInterpretamos `\ud835\udcdd a` como el \"subconjunto generalizado\" de `\u03b1` \ncorrespondiente a un entorno abierto intinitesimal de `a`. \n-/\n\nvariables {\u03b1 : Type*} [topological_space \u03b1]\n\nopen set\n\n\n/- En este ejemplo vamos a demostrar que `\ud835\udcdd a` es un filtro.\n\nLemas \u00fatiles:\n\n`interior_univ : interior univ = univ`\n`mem_univ x : x \u2208 univ`\n`interior_mono : s \u2286 t \u2192 interior s \u2286 interior t`\n`??? : interior (s \u2229 t) = interior s \u2229 interior t` -- \u00bfPuedes encontrar este lema?\n -/\nexample (a : \u03b1): filter \u03b1 :=\n{ sets := {X : set \u03b1 | a \u2208 interior X},\n  univ_sets := begin\n    simp only [mem_set_of_eq, interior_univ],\n  end,\n  sets_of_superset := begin\n    intros S T hS hST,\n    simp only [mem_set_of_eq] at hS \u22a2,\n    exact mem_of_subset_of_mem (interior_mono hST) hS,\n  end,\n  inter_sets := begin\n    intros S T hS hT,\n    simp only [mem_set_of_eq, interior_inter, mem_inter_iff],\n    exact \u27e8hS, hT\u27e9,\n  end }\n\n/-\n## Puntos de acumulaci\u00f3n\n\nUn punto de acumulaci\u00f3n, o punto l\u00edmite (`cluster_pt` en mathlib) `x : \u03b1`\nde un filtro `F : filter \u03b1` en un espacio topol\u00f3gico `\u03b1` es un `x : \u03b1`\ntal que  `\ud835\udcdd x \u2293 F \u2260 \u22a5`.\n\n\u00bfQu\u00e9 significa esto? `\u22a5` denota el filtro m\u00e1s peque\u00f1o, es decir,\nel filtro que contiene todos los subconjuntos de `\u03b1`.\nPor otro lado, `\ud835\udcdd x \u2293 F` es el filtro generado por `F` y por los\nentornos de `x`,\nPor tanto, el enunciado `\ud835\udcdd x \u2293 F \u2260 \u22a5` dice que no existen conjuntos\n`A \u2208 \ud835\udcdd x` y `B \u2208 F` tal que `A \u2229 B = \u2205`, o en otras palabras, que \ncada elemento del filtro `F` interseca cada entorno de `x`.\n\nPor ejemplo, si `F = \ud835\udcdf S` es el filtro principal de un subconjunto `S` \nde `\u03b1`, entonces los puntos de acumulaci\u00f3n de `\ud835\udcdf S` son los puntos\n`x` tales que cualquier abierto que contiene a  `x` tiene intersecci\u00f3n\nno vac\u00eda con `S`. Equivalentemente, `x` est\u00e1 en la clausura de `S`.\n\nLa idea es que debemos pensar en el punto de acumulaci\u00f3n `a : \u03b1` de `F : filter \u03b1` \ncomo un punto en la clausura del \"subconjunto generalizado\" correspondiente a `F`. \n-/\n\n/-- Este lema se llama `cluster_pt.mono` en mathlib. \n\nLa idea es que si `F` y `G` son \"subconjuntos generalizados\" de un espacio\ntopol\u00f3gico y \"`F \u2286 G`\", entonces \"`clausura F \u2286 clausura G`\".\n\nEmpieza la demostraci\u00f3n reescribiendo `cluster_pt_iff`.-/\nexample {x : \u03b1} {F G : filter \u03b1} (hxF : cluster_pt x F) (hFG : F \u2264 G) :\n  cluster_pt x G :=\nbegin\n  rw cluster_pt_iff at hxF \u22a2,\n  intros S hS T hT,\n  exact hxF hS (hFG hT),\nend\n\n/-\n## Compacidad\nLa definici\u00f3n de compacto (`is_compact`) en mathlib est\u00e1 escrita utilizando\nfiltros: un subconjunto `S` de un espacio topol\u00f3gico `\u03b1` es *compacto*\nsi para todo filtro no trivial `F \u2260 \u22a5` tal que `S \u2208 F`,\nexiste `a : \u03b1` tal que todo subconjunto de `F` interseca todo entorno abierto de `a`:\n\n`def is_compact (S : set \u03b1) := \u2200 \u2983F\u2984 [ne_bot F], F \u2264 \ud835\udcdf S \u2192 \u2203 a \u2208 S, cluster_pt a F`\n\nEsta definici\u00f3n es equivalente a la definici\u00f3n \"usual\" de subconjunto compacto.\n\nEn el siguiente ejercicio, vamos a utilizarla para demostrar que un subconjunto\ncerrado de un conjunto compacto es compacto. En realidad demostraremos algo m\u00e1s \ngeneral: si `\u03b1` es un espacio topol\u00f3gico, entonces la intersecci\u00f3n de un\nsubconjunto compacto de `\u03b1` y un subconjunto cerrado de `\u03b1` es un subconjunto\ncompacto de `\u03b1`.\n-/\n\nlemma closed_of_compact (S : set X) (hS : is_compact S)\n  (C : set X) (hC : is_closed C) : is_compact (S \u2229 C) :=\nbegin\n  rw is_compact,\n  /-  Sea `F` un filtro distinto de `\u22a5`, y tal que `F \u2264 \ud835\udcdf (S \u2229 C)` \n  (es decir, que contiene `S \u2229 C`). -/\n  intros F hnF hFSC,\n  -- Tenemos que encontrar un punto l\u00edmite para `F` contenido en `S \u2229 C`.\n\n  /- Como `ne_bot f` est\u00e1 entre `[ ]` en la definici\u00f3n de `is_compact`,\n    el sistema de inferencia de clases va a buscarlo. Para que lo encuentre,\n    lo a\u00f1adimos expl\u00edcitamente con esta instrucci\u00f3n `haveI`.-/\n  haveI := hnF,\n\n  /- Primero demostraremos que, dado que `S` es compacto, podemos encontrar un\n    punto l\u00edmite `a` para `F` en `S`. -/\n  have hFS : \u2203 (a : X) (H : a \u2208 S), cluster_pt a F,\n  { apply hS,\n    apply le_trans hFSC,\n    rw principal_mono,\n    exact set.inter_subset_left _ _, },\n  obtain \u27e8a, haS, haF\u27e9 := hFS,\n\n  /- Ahora demostramos que `a` tambi\u00e9n est\u00e1 en `C`, porque `C` es cerrado.\n  Lemas \u00fatiles:\n  `is_closed.closure_eq : is_closed C \u2192 closure C = C`\n  `mem_closure_iff_cluster_pt : a \u2208 closure S \u2194 cluster_pt a (\ud835\udcdf S)`- -/\n  have haC : a \u2208 C,\n  { rw [\u2190 hC.closure_eq, mem_closure_iff_cluster_pt],\n    apply cluster_pt.mono haF,\n    apply le_trans hFSC,\n    rw principal_mono,\n    exact set.inter_subset_right _ _, },\n\n exact \u27e8a, \u27e8haS, haC\u27e9, haF\u27e9,\nend", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_6/soluciones/topologia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404008810105, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.7096126452603037}}
{"text": "import data.real.basic\n\nexample (x : \u211d) (h : 0 \u2264 x) : 0 \u2264 x ^ 3 - x ^ 2 + 1 :=\nbegin\n  by_cases x_vs_one : x \u2264 1,\n  {\n    convert_to 0 \u2264 x ^ 3 + 1 - x ^ 2,\n    { rw sub_add_eq_add_sub },\n    have x_cub : 0 \u2264 x ^ 3 := pow_nonneg h 3,\n    have x_sqr : x ^ 2 \u2264 1 := (sq_le_one_iff h).mpr x_vs_one,\n    have one_sub_x_sqr : 0 \u2264 1 - x ^ 2 := sub_nonneg.mpr x_sqr,\n    rw \u2190add_sub,\n    exact add_nonneg x_cub one_sub_x_sqr,\n  },\n  {\n    convert_to 0 \u2264 x ^ 2 * (x - 1) + 1,\n    { ring },\n    nlinarith,\n  },\nend\n", "meta": {"author": "madvorak", "repo": "Lean-first-steps", "sha": "4cfee162afaa53b589ec7a94986d78d75cf1c85e", "save_path": "github-repos/lean/madvorak-Lean-first-steps", "path": "github-repos/lean/madvorak-Lean-first-steps/Lean-first-steps-4cfee162afaa53b589ec7a94986d78d75cf1c85e/src/Polynomial_nneg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7096032782189425}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module analysis.subadditive\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.Instances.Real\nimport Mathlib.Order.Filter.Archimedean\n\n/-!\n# Convergence of subadditive sequences\n\nA subadditive sequence `u : \u2115 \u2192 \u211d` is a sequence satisfying `u (m + n) \u2264 u m + u n` for all `m, n`.\nWe define this notion as `Subadditive u`, and prove in `Subadditive.tendsto_lim` that, if `u n / n`\nis bounded below, then it converges to a limit (that we denote by `Subadditive.lim` for\nconvenience). This result is known as Fekete's lemma in the literature.\n\n## TODO\n\nDefine a bundled `SubadditiveHom`, use it.\n-/\n\nnoncomputable section\n\nopen Set Filter Topology\n\n/-- A real-valued sequence is subadditive if it satisfies the inequality `u (m + n) \u2264 u m + u n`\nfor all `m, n`. -/\ndef Subadditive (u : \u2115 \u2192 \u211d) : Prop :=\n  \u2200 m n, u (m + n) \u2264 u m + u n\n#align subadditive Subadditive\n\nnamespace Subadditive\n\nvariable {u : \u2115 \u2192 \u211d} (h : Subadditive u)\n\n/-- The limit of a bounded-below subadditive sequence. The fact that the sequence indeed tends to\nthis limit is given in `Subadditive.tendsto_lim` -/\n@[nolint unusedArguments] -- porting note: was irreducible\nprotected def lim (_h : Subadditive u) :=\n  inf\u209b ((fun n : \u2115 => u n / n) '' Ici 1)\n#align subadditive.lim Subadditive.lim\n\ntheorem lim_le_div (hbdd : BddBelow (range fun n => u n / n)) {n : \u2115} (hn : n \u2260 0) :\n    h.lim \u2264 u n / n := by\n  rw [Subadditive.lim]\n  exact cinf\u209b_le (hbdd.mono <| image_subset_range _ _) \u27e8n, hn.bot_lt, rfl\u27e9\n#align subadditive.lim_le_div Subadditive.lim_le_div\n\n\n\ntheorem eventually_div_lt_of_div_lt {L : \u211d} {n : \u2115} (hn : n \u2260 0) (hL : u n / n < L) :\n    \u2200\u1da0 p in atTop, u p / p < L := by\n  /- It suffices to prove the statement for each arithmetic progression `(n * \u00b7 + r)`. -/\n  refine .atTop_of_arithmetic hn fun r _ => ?_\n  /- `(k * u n + u r) / (k * n + r)` tends to `u n / n < L`, hence\n  `(k * u n + u r) / (k * n + r) < L` for sufficiently large `k`. -/\n  have A : Tendsto (fun x : \u211d => (u n + u r / x) / (n + r / x)) atTop (\ud835\udcdd ((u n + 0) / (n + 0))) :=\n    (tendsto_const_nhds.add <| tendsto_const_nhds.div_atTop tendsto_id).div\n      (tendsto_const_nhds.add <| tendsto_const_nhds.div_atTop tendsto_id) <| by simpa\n  have B : Tendsto (fun x => (x * u n + u r) / (x * n + r)) atTop (\ud835\udcdd (u n / n)) := by\n    rw [add_zero, add_zero] at A\n    refine A.congr' <| (eventually_ne_atTop 0).mono fun x hx => ?_\n    simp only [(\u00b7 \u2218 \u00b7), add_div' _ _ _ hx, div_div_div_cancel_right _ hx, mul_comm]\n  refine ((B.comp tendsto_nat_cast_atTop_atTop).eventually (gt_mem_nhds hL)).mono fun k hk => ?_\n  /- Finally, we use an upper estimate on `u (k * n + r)` to get an estimate on\n  `u (k * n + r) / (k * n + r)`. -/\n  rw [mul_comm]\n  refine lt_of_le_of_lt ?_ hk\n  simp only [(\u00b7 \u2218 \u00b7), \u2190 Nat.cast_add, \u2190 Nat.cast_mul]\n  exact div_le_div_of_le (Nat.cast_nonneg _) (h.apply_mul_add_le _ _ _)\n#align subadditive.eventually_div_lt_of_div_lt Subadditive.eventually_div_lt_of_div_lt\n\n/-- Fekete's lemma: a subadditive sequence which is bounded below converges. -/\ntheorem tendsto_lim (hbdd : BddBelow (range fun n => u n / n)) :\n    Tendsto (fun n => u n / n) atTop (\ud835\udcdd h.lim) := by\n  refine' tendsto_order.2 \u27e8fun l hl => _, fun L hL => _\u27e9\n  \u00b7 refine' eventually_atTop.2\n      \u27e81, fun n hn => hl.trans_le (h.lim_le_div hbdd (zero_lt_one.trans_le hn).ne')\u27e9\n  \u00b7 obtain \u27e8n, npos, hn\u27e9 : \u2203 n : \u2115, 0 < n \u2227 u n / n < L := by\n      rw [Subadditive.lim] at hL\n      rcases exists_lt_of_cinf\u209b_lt (by simp) hL with \u27e8x, hx, xL\u27e9\n      rcases (mem_image _ _ _).1 hx with \u27e8n, hn, rfl\u27e9\n      exact \u27e8n, zero_lt_one.trans_le hn, xL\u27e9\n    exact h.eventually_div_lt_of_div_lt npos.ne' hn\n#align subadditive.tendsto_lim Subadditive.tendsto_lim\n\nend Subadditive\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Analysis/Subadditive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.709598489186989}}
{"text": "import linear_algebra.basic\n\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}  {\u03b9 : Type x}\n\nnamespace linear_map\nsection\nvariables [ring \u03b1] [add_comm_group \u03b2] [add_comm_group \u03b3] [add_comm_group \u03b4] \nvariables [module \u03b1 \u03b2] [module \u03b1 \u03b3] [module \u03b1 \u03b4] \nvariables (f g : \u03b2 \u2192\u2097[\u03b1] \u03b3)\ninclude \u03b1\n\nlemma comp_eq_mul (f g : \u03b2 \u2192\u2097[\u03b1] \u03b2) : f.comp g = f * g := rfl\n\ndef restrict\n  (f : \u03b2 \u2192\u2097[\u03b1] \u03b3) (p : submodule \u03b1 \u03b2) (q : submodule \u03b1 \u03b3) (hf : \u2200 x \u2208 p, f x \u2208 q) : \n  p \u2192\u2097[\u03b1] q :=\n{ to_fun := \u03bb x, \u27e8f x, hf x.1 x.2\u27e9,\n  map_add' := begin intros, apply set_coe.ext, simp end,\n  map_smul' := begin intros, apply set_coe.ext, simp end }\n\nlemma restrict_apply (f : \u03b2 \u2192\u2097[\u03b1] \u03b3) (p : submodule \u03b1 \u03b2) (q : submodule \u03b1 \u03b3) (hf : \u2200 x \u2208 p, f x \u2208 q) (x : p) :\n  f.restrict p q hf x = \u27e8f x, hf x.1 x.2\u27e9 := rfl\n\nend\nend linear_map\n\nvariables {R : field \u03b1} [add_comm_group \u03b2] [add_comm_group \u03b3]\nvariables [vector_space \u03b1 \u03b2] [vector_space \u03b1 \u03b3]\nvariables (p p' : submodule \u03b1 \u03b2)\nvariables {r : \u03b1} {x y : \u03b2}\ninclude R\n\n\nlemma vector_space.smul_neq_zero (x : \u03b2) (hr : r \u2260 0) : r \u2022 x = 0 \u2194 x = 0 :=\nbegin\n  have := submodule.smul_mem_iff \u22a5 hr,\n  rwa [submodule.mem_bot, submodule.mem_bot] at this,\nend\n", "meta": {"author": "abentkamp", "repo": "spectral", "sha": "751645679ef1cb6266316349de9e492eff85484c", "save_path": "github-repos/lean/abentkamp-spectral", "path": "github-repos/lean/abentkamp-spectral/spectral-751645679ef1cb6266316349de9e492eff85484c/src/missing_mathlib/linear_algebra/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7095984880630767}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport order.conditionally_complete_lattice.basic\nimport data.int.least_greatest\n\n/-!\n## `\u2124` forms a conditionally complete linear order\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe integers form a conditionally complete linear order.\n-/\n\nopen int\nopen_locale classical\nnoncomputable theory\n\ninstance : conditionally_complete_linear_order \u2124 :=\n{ Sup := \u03bb s, if h : s.nonempty \u2227 bdd_above s then\n    greatest_of_bdd (classical.some h.2) (classical.some_spec h.2) h.1 else 0,\n  Inf := \u03bb s, if h : s.nonempty \u2227 bdd_below s then\n    least_of_bdd (classical.some h.2) (classical.some_spec h.2) h.1 else 0,\n  le_cSup := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_above s := \u27e8\u27e8n, hns\u27e9, hs\u27e9,\n    rw [dif_pos this],\n    exact (greatest_of_bdd _ _ _).2.2 n hns\n  end,\n  cSup_le := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_above s := \u27e8hs, \u27e8n, hns\u27e9\u27e9,\n    rw [dif_pos this],\n    exact hns (greatest_of_bdd _ (classical.some_spec this.2) _).2.1\n  end,\n  cInf_le := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_below s := \u27e8\u27e8n, hns\u27e9, hs\u27e9,\n    rw [dif_pos this],\n    exact (least_of_bdd _ _ _).2.2 n hns\n  end,\n  le_cInf := begin\n    intros s n hs hns,\n    have : s.nonempty \u2227 bdd_below s := \u27e8hs, \u27e8n, hns\u27e9\u27e9,\n    rw [dif_pos this],\n    exact hns (least_of_bdd _ (classical.some_spec this.2) _).2.1\n  end,\n  .. int.linear_order, ..linear_order.to_lattice }\n\nnamespace int\n\nlemma cSup_eq_greatest_of_bdd {s : set \u2124} [decidable_pred (\u2208 s)]\n  (b : \u2124) (Hb : \u2200 z \u2208 s, z \u2264 b) (Hinh : \u2203 z : \u2124, z \u2208 s) :\n  Sup s = greatest_of_bdd b Hb Hinh :=\nbegin\n  convert dif_pos _ using 1,\n  { convert coe_greatest_of_bdd_eq _ (classical.some_spec (\u27e8b, Hb\u27e9 : bdd_above s)) _ },\n  { exact \u27e8Hinh, b, Hb\u27e9, }\nend\n\n@[simp]\nlemma cSup_empty : Sup (\u2205 : set \u2124) = 0 := dif_neg (by simp)\n\nlemma cSup_of_not_bdd_above {s : set \u2124} (h : \u00ac bdd_above s) : Sup s = 0 := dif_neg (by simp [h])\n\nlemma cInf_eq_least_of_bdd {s : set \u2124} [decidable_pred (\u2208 s)]\n  (b : \u2124) (Hb : \u2200 z \u2208 s, b \u2264 z) (Hinh : \u2203 z : \u2124, z \u2208 s) :\n  Inf s = least_of_bdd b Hb Hinh :=\nbegin\n  convert dif_pos _ using 1,\n  { convert coe_least_of_bdd_eq _ (classical.some_spec (\u27e8b, Hb\u27e9 : bdd_below s)) _ },\n  { exact \u27e8Hinh, b, Hb\u27e9, }\nend\n\n@[simp]\nlemma cInf_empty : Inf (\u2205 : set \u2124) = 0 := dif_neg (by simp)\n\n\n\nlemma cSup_mem {s : set \u2124} (h1 : s.nonempty) (h2 : bdd_above s) : Sup s \u2208 s :=\nbegin\n  convert (greatest_of_bdd _ (classical.some_spec h2) h1).2.1,\n  exact dif_pos \u27e8h1, h2\u27e9,\nend\n\nlemma cInf_mem {s : set \u2124} (h1 : s.nonempty) (h2 : bdd_below s) : Inf s \u2208 s :=\nbegin\n  convert (least_of_bdd _ (classical.some_spec h2) h1).2.1,\n  exact dif_pos \u27e8h1, h2\u27e9,\nend\n\nend int\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/conditionally_complete_order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7095984875974257}}
{"text": "/-\nCopyright (c) 2021 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n-/\nimport data.set.lattice\nimport order.zorn\nimport tactic.by_contra\n\n/-!\n# Extend a partial order to a linear order\n\nThis file constructs a linear order which is an extension of the given partial order, using Zorn's\nlemma.\n-/\n\nuniverses u\nopen set classical\nopen_locale classical\n\n/--\nAny partial order can be extended to a linear order.\n-/\ntheorem extend_partial_order {\u03b1 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_partial_order \u03b1 r] :\n  \u2203 (s : \u03b1 \u2192 \u03b1 \u2192 Prop) (_ : is_linear_order \u03b1 s), r \u2264 s :=\nbegin\n  let S := {s | is_partial_order \u03b1 s},\n  have hS : \u2200 c, c \u2286 S \u2192 zorn.chain (\u2264) c \u2192 \u2200 y \u2208 c, (\u2203 ub \u2208 S, \u2200 z \u2208 c, z \u2264 ub),\n  { rintro c hc\u2081 hc\u2082 s hs,\n    haveI := (hc\u2081 hs).1,\n    refine \u27e8Sup c, _, \u03bb z hz, le_Sup hz\u27e9,\n    refine { refl := _, trans := _, antisymm := _ }; simp_rw binary_relation_Sup_iff,\n    { intro x,\n      exact \u27e8s, hs, refl x\u27e9 },\n    { rintro x y z \u27e8s\u2081, h\u2081s\u2081, h\u2082s\u2081\u27e9 \u27e8s\u2082, h\u2081s\u2082, h\u2082s\u2082\u27e9,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2081,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2082,\n      cases hc\u2082.total_of_refl h\u2081s\u2081 h\u2081s\u2082,\n      { exact \u27e8s\u2082, h\u2081s\u2082, trans (h _ _ h\u2082s\u2081) h\u2082s\u2082\u27e9 },\n      { exact \u27e8s\u2081, h\u2081s\u2081, trans h\u2082s\u2081 (h _ _ h\u2082s\u2082)\u27e9 } },\n    { rintro x y \u27e8s\u2081, h\u2081s\u2081, h\u2082s\u2081\u27e9 \u27e8s\u2082, h\u2081s\u2082, h\u2082s\u2082\u27e9,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2081,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2082,\n      cases hc\u2082.total_of_refl h\u2081s\u2081 h\u2081s\u2082,\n      { exact antisymm (h _ _ h\u2082s\u2081) h\u2082s\u2082 },\n      { apply antisymm h\u2082s\u2081 (h _ _ h\u2082s\u2082) } } },\n  obtain \u27e8s, hs\u2081 : is_partial_order _ _, rs, hs\u2082\u27e9 := zorn.zorn_nonempty_partial_order\u2080 S hS r \u2039_\u203a,\n  resetI,\n  refine \u27e8s, { total := _ }, rs\u27e9,\n  intros x y,\n  by_contra' h,\n  let s' := \u03bb x' y', s x' y' \u2228 s x' x \u2227 s y y',\n  rw \u2190hs\u2082 s' _ (\u03bb _ _, or.inl) at h,\n  { apply h.1 (or.inr \u27e8refl _, refl _\u27e9) },\n  { refine\n      { refl := \u03bb x, or.inl (refl _),\n        trans := _,\n        antisymm := _ },\n    { rintro a b c (ab | \u27e8ax : s a x, yb : s y b\u27e9) (bc | \u27e8bx : s b x, yc : s y c\u27e9),\n      { exact or.inl (trans ab bc), },\n      { exact or.inr \u27e8trans ab bx, yc\u27e9 },\n      { exact or.inr \u27e8ax, trans yb bc\u27e9 },\n      { exact or.inr \u27e8ax, yc\u27e9 } },\n    { rintro a b (ab | \u27e8ax : s a x, yb : s y b\u27e9) (ba | \u27e8bx : s b x, ya : s y a\u27e9),\n      { exact antisymm ab ba },\n      { exact (h.2 (trans ya (trans ab bx))).elim },\n      { exact (h.2 (trans yb (trans ba ax))).elim },\n      { exact (h.2 (trans yb bx)).elim } } },\nend\n\n/-- A type alias for `\u03b1`, intended to extend a partial order on `\u03b1` to a linear order. -/\ndef linear_extension (\u03b1 : Type u) : Type u := \u03b1\n\nnoncomputable instance {\u03b1 : Type u} [partial_order \u03b1] : linear_order (linear_extension \u03b1) :=\n{ le := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some,\n  le_refl := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.1.1.1.1,\n  le_trans := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.1.1.2.1,\n  le_antisymm := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.1.2.1,\n  le_total := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.2.1,\n  decidable_le := classical.dec_rel _ }\n\n/-- The embedding of `\u03b1` into `linear_extension \u03b1` as a relation homomorphism. -/\ndef to_linear_extension {\u03b1 : Type u} [partial_order \u03b1] :\n  ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop) \u2192r ((\u2264) : linear_extension \u03b1 \u2192 linear_extension \u03b1 \u2192 Prop) :=\n{ to_fun := \u03bb x, x,\n  map_rel' := \u03bb a b, (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some_spec _ _ }\n\ninstance {\u03b1 : Type u} [inhabited \u03b1] : inhabited (linear_extension \u03b1) :=\n\u27e8(default : \u03b1)\u27e9\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/extension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7095984768557027}}
{"text": "/-\nCopyright (c) 2021 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker\n-/\nimport analysis.normed_space.ordered\nimport analysis.asymptotics.asymptotics\n\n/-!\n# A collection of specific asymptotic results\n\nThis file contains specific lemmas about asymptotics which don't have their place in the general\ntheory developped in `analysis.asymptotics.asymptotics`.\n-/\n\nopen filter asymptotics\nopen_locale topological_space\n\nsection normed_field\n\n/-- If `f : \ud835\udd5c \u2192 E` is bounded in a punctured neighborhood of `a`, then `f(x) = o((x - a)\u207b\u00b9)` as\n`x \u2192 a`, `x \u2260 a`. -/\nlemma filter.is_bounded_under.is_o_sub_self_inv {\ud835\udd5c E : Type*} [normed_field \ud835\udd5c] [has_norm E]\n  {a : \ud835\udd5c} {f : \ud835\udd5c \u2192 E} (h : is_bounded_under (\u2264) (\ud835\udcdd[\u2260] a) (norm \u2218 f)) :\n  is_o f (\u03bb x, (x - a)\u207b\u00b9) (\ud835\udcdd[\u2260] a) :=\nbegin\n  refine (h.is_O_const (@one_ne_zero \u211d _ _)).trans_is_o (is_o_const_left.2 $ or.inr _),\n  simp only [(\u2218), normed_field.norm_inv],\n  exact (tendsto_norm_sub_self_punctured_nhds a).inv_tendsto_zero\nend\n\nend normed_field\n\nsection linear_ordered_field\n\nvariables {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c]\n\nlemma pow_div_pow_eventually_eq_at_top {p q : \u2115} :\n  (\u03bb x : \ud835\udd5c, x^p / x^q) =\u1da0[at_top] (\u03bb x, x^((p : \u2124) -q)) :=\nbegin\n  apply ((eventually_gt_at_top (0 : \ud835\udd5c)).mono (\u03bb x hx, _)),\n  simp [zpow_sub\u2080 hx.ne'],\nend\n\nlemma pow_div_pow_eventually_eq_at_bot {p q : \u2115} :\n  (\u03bb x : \ud835\udd5c, x^p / x^q) =\u1da0[at_bot] (\u03bb x, x^((p : \u2124) -q)) :=\nbegin\n  apply ((eventually_lt_at_bot (0 : \ud835\udd5c)).mono (\u03bb x hx, _)),\n  simp [zpow_sub\u2080 hx.ne'.symm],\nend\n\nlemma tendsto_zpow_at_top_at_top {n : \u2124}\n  (hn : 0 < n) : tendsto (\u03bb x : \ud835\udd5c, x^n) at_top at_top :=\nbegin\n  lift n to \u2115 using hn.le,\n  simp only [zpow_coe_nat],\n  exact tendsto_pow_at_top (nat.succ_le_iff.mpr $int.coe_nat_pos.mp hn)\nend\n\nlemma tendsto_pow_div_pow_at_top_at_top {p q : \u2115}\n  (hpq : q < p) : tendsto (\u03bb x : \ud835\udd5c, x^p / x^q) at_top at_top :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma tendsto_pow_div_pow_at_top_zero [topological_space \ud835\udd5c] [order_topology \ud835\udd5c] {p q : \u2115}\n  (hpq : p < q) : tendsto (\u03bb x : \ud835\udd5c, x^p / x^q) at_top (\ud835\udcdd 0) :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_zpow_at_top_zero,\n  linarith\nend\n\nend linear_ordered_field\n\nsection normed_linear_ordered_field\n\nvariables {\ud835\udd5c : Type*} [normed_linear_ordered_field \ud835\udd5c]\n\nlemma asymptotics.is_o_pow_pow_at_top_of_lt\n  [order_topology \ud835\udd5c] {p q : \u2115} (hpq : p < q) :\n  is_o (\u03bb x : \ud835\udd5c, x^p) (\u03bb x, x^q) at_top :=\nbegin\n  refine (is_o_iff_tendsto' _).mpr (tendsto_pow_div_pow_at_top_zero hpq),\n  exact (eventually_gt_at_top 0).mono (\u03bb x hx hxq, (pow_ne_zero q hx.ne' hxq).elim),\nend\n\nlemma asymptotics.is_O.trans_tendsto_norm_at_top {\u03b1 : Type*} {u v : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n  (huv : is_O u v l) (hu : tendsto (\u03bb x, \u2225u x\u2225) l at_top) : tendsto (\u03bb x, \u2225v x\u2225) l at_top :=\nbegin\n  rcases huv.exists_pos with \u27e8c, hc, hcuv\u27e9,\n  rw is_O_with at hcuv,\n  convert tendsto.at_top_div_const hc (tendsto_at_top_mono' l hcuv hu),\n  ext x,\n  rw mul_div_cancel_left _ hc.ne.symm,\nend\n\nend normed_linear_ordered_field\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/asymptotics/specific_asymptotics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970717197768, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7095984729378836}}
{"text": "variables (A : Type) (p q : A \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\niff.intro\n  (assume H : \u2200 x, p x \u2227 q x,\n    and.intro\n      (take y : A, and.left (H y))\n      (take y : A, and.right (H y)))\n  (assume H : (\u2200 x, p x) \u2227 (\u2200 x, q x),\n    take y : A,\n    and.intro (and.left H y) (and.right H y))\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\n  assume Hpq : \u2200 x, p x \u2192 q x,\n  assume Hp : \u2200 x, p x,\n  take y : A,\n  Hpq y (Hp y)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\n  assume Hpq,\n  take y : A,\n  or.elim Hpq\n    (\u03bb H : (\u2200 x, p x), or.inl (H y))\n    (\u03bb H : (\u2200 x, q x), or.inr (H y))\n\nvariables (a b c : Type) (f : a \u2192 b) (g : b \u2192 c)\n\n\nvariable r : Prop\n\nexample : A \u2192 ((\u2200 x : A, r) \u2194 r) :=\n  assume H : A,\n  iff.intro\n    (assume Hr : (\u2200 x : A, r), Hr H)\n    (assume Hr : r, take y, Hr)\n\nopen classical\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r :=\niff.intro\n  (assume H : \u2200 x, p x \u2228 r,\n    by_cases or.inr\n      (assume Hnr : \u00acr,\n        or.inl\n          (take y : A,\n            or.elim (H y) id (\u03bb Hr, absurd Hr Hnr))))\n  (assume H : (\u2200 x, p x) \u2228 r,\n    take y : A,\n    or.elim H\n      (\u03bb Hp, or.inl (Hp y))\n      or.inr)\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\niff.intro\n  (assume H : (\u2200 x, r \u2192 p x),\n    assume Hr : r,\n    take y : A, H y Hr)\n  (assume H : r \u2192 \u2200 x, p x,\n    take y : A,\n    assume Hr : r, H Hr y)\n\n\nvariables (men : Type) (barber : men) (shaves : men \u2192 men \u2192 Prop)\n\nexample (H : \u2200 x : men, shaves barber x \u2194 \u00acshaves x x) : false :=\n  have Hns : \u00acshaves barber barber, from\n    not.intro\n      (assume Hs : shaves barber barber,\n        iff.mp (H barber) Hs Hs),\n  have Hs : shaves barber barber, from\n    iff.mpr (H barber) Hns,\n  Hns Hs\n", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/quantifiers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7095766822830041}}
{"text": "/-\nCopyright (c) 2022 Henrik B\u00f6ving. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henrik B\u00f6ving\n-/\n\nnamespace Cpdt\nnamespace Chapter5\n\ninductive Exp where\n  | nat : Nat \u2192 Exp\n  | add : Exp \u2192 Exp \u2192 Exp\n  | bool : Bool \u2192 Exp\n  | and : Exp \u2192 Exp \u2192 Exp\n\ninductive Ty where\n  | nat : Ty\n  | bool : Ty\n  deriving DecidableEq\n\ninductive HasType : Exp \u2192 Ty \u2192 Prop where\n  | constNat (n : Nat) : HasType (.nat n) .nat\n  | constBool (b : Bool) : HasType (.bool b) .bool\n  | addApp (l r : Exp) (hl : HasType l .nat) (hr : HasType r .nat) : HasType (.add l r) .nat\n  | andApp (l r : Exp) (hl : HasType l .bool) (hr : HasType r .bool) : HasType (.and l r) .bool\n\ninductive Maybe (p : \u03b1 \u2192 Prop) where\n  | found : (a : \u03b1) \u2192 p a \u2192 Maybe p\n  | unknown : Maybe p\n\nnotation \"{{\" t \"|\" p \"}}\" => Maybe (fun t => p)\n\ndef Exp.typecheck : (e : Exp) \u2192 {{ t | HasType e t }}\n  | nat n => .found .nat (.constNat n)\n  | bool b => .found .bool (.constBool b)\n  | add l r =>\n    match l.typecheck, r.typecheck with\n    | .found .nat lth, .found .nat rth => .found .nat (.addApp l r lth rth)\n    | _, _ => .unknown\n  | and l r =>\n    match l.typecheck, r.typecheck with\n    | .found .bool lth, .found .bool rth => .found .bool (.andApp l r lth rth)\n    | _, _ => .unknown\n\ntheorem HasType_det : HasType e t1 \u2192 HasType e t2 \u2192 t1 = t2 := by\n  intro h1 h2\n  cases h1 <;> cases h2 <;> rfl\n\ntheorem Exp.typecheck_correct : HasType e t \u2192 typecheck e \u2260 .unknown \u2192 typecheck e = .found t h := by\n  intro ht1\n  cases typecheck e with\n  | found t2 ht2 =>\n    intros\n    have h : t = t2 := HasType_det ht1 ht2\n    simp [h]\n  | unknown =>\n    intros\n    contradiction\n\ntheorem Exp.typecheck_complete : typecheck e = .unknown \u2192 \u2200 t, \u00acHasType e t := by\n  induction e with simp [Exp.typecheck]\n  | add l r lih rih =>\n    split\n    case add.h_1 _ _ htl htr rl rr =>\n      intros\n      contradiction\n    case add.h_2 _ _ hnp =>\n      intro h t ht\n      cases ht with\n      | addApp lt rt lth rth =>\n        exact hnp lth rth (typecheck_correct lth (lih \u00b7 _ lth)) (typecheck_correct rth (rih \u00b7 _ rth))\n  | and l r lih rih =>\n    split\n    case and.h_1 _ _ htl htr rl rr =>\n      intros\n      contradiction\n    case and.h_2 _ _ hnp =>\n      intro h t ht\n      cases ht with\n      | andApp lt rt lth rth =>\n        exact hnp lth rth (typecheck_correct lth (lih \u00b7 _ lth)) (typecheck_correct rth (rih \u00b7 _ rth))\n\n\ndef Exp.typecheck' (e : Exp) : {t : Ty // HasType e t} \u2295' (\u2200 t, \u00acHasType e t) :=\n  match h:Exp.typecheck e with\n  | .found t ht => PSum.inl \u27e8t, ht\u27e9\n  | .unknown => PSum.inr (typecheck_complete h)\n\nend Chapter5\nend Cpdt\n", "meta": {"author": "hargoniX", "repo": "cpdt-lean", "sha": "65896137166a8ef74e816efc187346bc8f8bbd22", "save_path": "github-repos/lean/hargoniX-cpdt-lean", "path": "github-repos/lean/hargoniX-cpdt-lean/cpdt-lean-65896137166a8ef74e816efc187346bc8f8bbd22/Cpdt/Chapter5/Typechecker.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7095766817739524}}
{"text": "import data.set.basic -- hide\nimport tactic -- hide\n\n/-\n\n## Working with the image of a function\n\nIn this level we will learn how to work with the image of a function.\nIf `A: set X` and `B: set Y` are sets and we have `f : X \u2192 Y`, the image of `A` under `f`, $ f(A) $ is written as `f '' A`.\n\nIf we have a proof that an element `b` belongs to the image, `hb: b \u2208 f '' A` we can use `cases hb` to get a preimage and a proof that it belongs to the preimage.\n\n```\nhb_w : A\nhb_h : hb_w \u2208 A \u2227 f hb_w = b\n```\n\nWe can change the names using `cases hb with a ha` instead. Now we will get\n\n```\na: A\nha: a \u2208 A \u2227 f a = b\n```\n\nIf we want to prove something like `b \u2208 f '' A`, we can use the `use` tactic to provide\nan element `a : X`, and then prove that `a \u2208 A` and `f a = b`.\n-/\n\nvariables{X Y: Type} -- hide\nvariables {S : set X}\nvariables {y : Y}\nvariables {f : X \u2192 Y}\n\nlemma mem_image : y \u2208 f '' S \u2194 \u2203 x , x \u2208 S \u2227 f x = y\n:= set.mem_image f S y\n/- Axiom:\nmem_image : y \u2208 f '' S \u2194 \u2203 x , x \u2208 S \u2227 f x = y\n-/\n\n\n/- Lemma\nIf $ A \u2286 B $, then $ f(A) \u2286 f(B) $\n-/\nlemma image_subset (f : X \u2192 Y) (A B : set X) (h: A \u2286 B): f '' A \u2286  f '' B :=\nbegin\n  intros y hy,\n  cases hy with x hx,\n  use x,\n  split,\n  apply h,\n  exact hx.1,\n  exact hx.2,\n\n  \n\nend", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/set_theory_world/image_tutorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.7095555127749212}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_159\n  (b : \u211d)\n  (f : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = 3 * x^4 - 7 * x^3 + 2 * x^2 - b * x + 1)\n  (h\u2081 : f 1 = 1) :\n  b = -2 :=\nbegin\n  rw h\u2080 at h\u2081,\n  linarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p159.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7095555089844745}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport data.polynomial.derivative\nimport data.nat.choose.sum\nimport ring_theory.polynomial.pochhammer\nimport data.polynomial.algebra_map\nimport linear_algebra.linear_independent\nimport data.mv_polynomial.pderiv\n\n/-!\n# Bernstein polynomials\n\nThe definition of the Bernstein polynomials\n```\nbernstein_polynomial (R : Type*) [comm_ring R] (n \u03bd : \u2115) : polynomial R :=\n(choose n \u03bd) * X^\u03bd * (1 - X)^(n - \u03bd)\n```\nand the fact that for `\u03bd : fin (n+1)` these are linearly independent over `\u211a`.\n\nWe prove the basic identities\n* `(finset.range (n + 1)).sum (\u03bb \u03bd, bernstein_polynomial R n \u03bd) = 1`\n* `(finset.range (n + 1)).sum (\u03bb \u03bd, \u03bd \u2022 bernstein_polynomial R n \u03bd) = n \u2022 X`\n* `(finset.range (n + 1)).sum (\u03bb \u03bd, (\u03bd * (\u03bd-1)) \u2022 bernstein_polynomial R n \u03bd) = (n * (n-1)) \u2022 X^2`\n\n## Notes\n\nSee also `analysis.special_functions.bernstein`, which defines the Bernstein approximations\nof a continuous function `f : C([0,1], \u211d)`, and shows that these converge uniformly to `f`.\n-/\n\nnoncomputable theory\n\n\nopen nat (choose)\nopen polynomial (X)\n\nvariables (R : Type*) [comm_ring R]\n\n/--\n`bernstein_polynomial R n \u03bd` is `(choose n \u03bd) * X^\u03bd * (1 - X)^(n - \u03bd)`.\n\nAlthough the coefficients are integers, it is convenient to work over an arbitrary commutative ring.\n-/\ndef bernstein_polynomial (n \u03bd : \u2115) : polynomial R := choose n \u03bd * X^\u03bd * (1 - X)^(n - \u03bd)\n\nexample : bernstein_polynomial \u2124 3 2 = 3 * X^2 - 3 * X^3 :=\nbegin\n  norm_num [bernstein_polynomial, choose],\n  ring,\nend\n\nnamespace bernstein_polynomial\n\nlemma eq_zero_of_lt {n \u03bd : \u2115} (h : n < \u03bd) : bernstein_polynomial R n \u03bd = 0 :=\nby simp [bernstein_polynomial, nat.choose_eq_zero_of_lt h]\n\nsection\nvariables {R} {S : Type*} [comm_ring S]\n\n@[simp] lemma map (f : R \u2192+* S) (n \u03bd : \u2115) :\n  (bernstein_polynomial R n \u03bd).map f = bernstein_polynomial S n \u03bd :=\nby simp [bernstein_polynomial]\n\nend\n\nlemma flip (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (bernstein_polynomial R n \u03bd).comp (1-X) = bernstein_polynomial R n (n-\u03bd) :=\nbegin\n  dsimp [bernstein_polynomial],\n  simp [h, tsub_tsub_assoc, mul_right_comm],\nend\n\nlemma flip' (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  bernstein_polynomial R n \u03bd = (bernstein_polynomial R n (n-\u03bd)).comp (1-X) :=\nbegin\n  rw [\u2190flip _ _ _ h, polynomial.comp_assoc],\n  simp,\nend\n\nlemma eval_at_0 (n \u03bd : \u2115) : (bernstein_polynomial R n \u03bd).eval 0 = if \u03bd = 0 then 1 else 0 :=\nbegin\n  dsimp [bernstein_polynomial],\n  split_ifs,\n  { subst h, simp, },\n  { simp [zero_pow (nat.pos_of_ne_zero h)], },\nend\n\nlemma eval_at_1 (n \u03bd : \u2115) : (bernstein_polynomial R n \u03bd).eval 1 = if \u03bd = n then 1 else 0 :=\nbegin\n  dsimp [bernstein_polynomial],\n  split_ifs,\n  { subst h, simp, },\n  { obtain w | w := (n - \u03bd).eq_zero_or_pos,\n    { simp [nat.choose_eq_zero_of_lt ((tsub_eq_zero_iff_le.mp w).lt_of_ne (ne.symm h))] },\n    { simp [zero_pow w] } },\nend.\n\nlemma derivative_succ_aux (n \u03bd : \u2115) :\n  (bernstein_polynomial R (n+1) (\u03bd+1)).derivative =\n    (n+1) * (bernstein_polynomial R n \u03bd - bernstein_polynomial R n (\u03bd + 1)) :=\nbegin\n  dsimp [bernstein_polynomial],\n  suffices :\n    \u2191((n + 1).choose (\u03bd + 1)) * ((\u2191\u03bd + 1) * X ^ \u03bd) * (1 - X) ^ (n - \u03bd)\n      -(\u2191((n + 1).choose (\u03bd + 1)) * X ^ (\u03bd + 1) * (\u2191(n - \u03bd) * (1 - X) ^ (n - \u03bd - 1))) =\n    (\u2191n + 1) * (\u2191(n.choose \u03bd) * X ^ \u03bd * (1 - X) ^ (n - \u03bd) -\n         \u2191(n.choose (\u03bd + 1)) * X ^ (\u03bd + 1) * (1 - X) ^ (n - (\u03bd + 1))),\n  { simpa [polynomial.derivative_pow, \u2190sub_eq_add_neg], },\n  conv_rhs { rw mul_sub, },\n  -- We'll prove the two terms match up separately.\n  refine congr (congr_arg has_sub.sub _) _,\n  { simp only [\u2190mul_assoc],\n    refine congr (congr_arg (*) (congr (congr_arg (*) _) rfl)) rfl,\n    -- Now it's just about binomial coefficients\n    exact_mod_cast congr_arg (\u03bb m : \u2115, (m : polynomial R)) (nat.succ_mul_choose_eq n \u03bd).symm, },\n  { rw [\u2190 tsub_add_eq_tsub_tsub, \u2190 mul_assoc, \u2190 mul_assoc], congr' 1,\n    rw mul_comm , rw [\u2190mul_assoc,\u2190mul_assoc],  congr' 1,\n    norm_cast,\n    congr' 1,\n    convert (nat.choose_mul_succ_eq n (\u03bd + 1)).symm using 1,\n    { convert mul_comm _ _ using 2,\n      simp, },\n    { apply mul_comm, }, },\nend\n\nlemma derivative_succ (n \u03bd : \u2115) :\n  (bernstein_polynomial R n (\u03bd+1)).derivative =\n    n * (bernstein_polynomial R (n-1) \u03bd - bernstein_polynomial R (n-1) (\u03bd+1)) :=\nbegin\n  cases n,\n  { simp [bernstein_polynomial], },\n  { apply derivative_succ_aux, }\nend\n\nlemma derivative_zero (n : \u2115) :\n  (bernstein_polynomial R n 0).derivative = -n * bernstein_polynomial R (n-1) 0 :=\nbegin\n  dsimp [bernstein_polynomial],\n  simp [polynomial.derivative_pow],\nend\n\nlemma iterate_derivative_at_0_eq_zero_of_lt (n : \u2115) {\u03bd k : \u2115} :\n  k < \u03bd \u2192 (polynomial.derivative^[k] (bernstein_polynomial R n \u03bd)).eval 0 = 0 :=\nbegin\n  cases \u03bd,\n  { rintro \u27e8\u27e9, },\n  { rw nat.lt_succ_iff,\n    induction k with k ih generalizing n \u03bd,\n    { simp [eval_at_0], },\n    { simp only [derivative_succ, int.coe_nat_eq_zero, int.nat_cast_eq_coe_nat, mul_eq_zero,\n        function.comp_app, function.iterate_succ,\n        polynomial.iterate_derivative_sub, polynomial.iterate_derivative_cast_nat_mul,\n        polynomial.eval_mul, polynomial.eval_nat_cast, polynomial.eval_sub],\n      intro h,\n      apply mul_eq_zero_of_right,\n      rw [ih _ _ (nat.le_of_succ_le h), sub_zero],\n      convert ih _ _ (nat.pred_le_pred h),\n      exact (nat.succ_pred_eq_of_pos (k.succ_pos.trans_le h)).symm } },\nend\n\n@[simp]\nlemma iterate_derivative_succ_at_0_eq_zero (n \u03bd : \u2115) :\n  (polynomial.derivative^[\u03bd] (bernstein_polynomial R n (\u03bd+1))).eval 0 = 0 :=\niterate_derivative_at_0_eq_zero_of_lt R n (lt_add_one \u03bd)\n\nopen polynomial\n\n@[simp]\n\n\nlemma iterate_derivative_at_0_ne_zero [char_zero R] (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (polynomial.derivative^[\u03bd] (bernstein_polynomial R n \u03bd)).eval 0 \u2260 0 :=\nbegin\n  simp only [int.coe_nat_eq_zero, bernstein_polynomial.iterate_derivative_at_0, ne.def,\n    nat.cast_eq_zero],\n  simp only [\u2190pochhammer_eval_cast],\n  norm_cast,\n  apply ne_of_gt,\n  obtain rfl|h' := nat.eq_zero_or_pos \u03bd,\n  { simp, },\n  { rw \u2190 nat.succ_pred_eq_of_pos h' at h,\n    exact pochhammer_pos _ _ (tsub_pos_of_lt (nat.lt_of_succ_le h)) }\nend\n\n/-!\nRather than redoing the work of evaluating the derivatives at 1,\nwe use the symmetry of the Bernstein polynomials.\n-/\nlemma iterate_derivative_at_1_eq_zero_of_lt (n : \u2115) {\u03bd k : \u2115} :\n  k < n - \u03bd \u2192 (polynomial.derivative^[k] (bernstein_polynomial R n \u03bd)).eval 1 = 0 :=\nbegin\n  intro w,\n  rw flip' _ _ _ (tsub_pos_iff_lt.mp (pos_of_gt w)).le,\n  simp [polynomial.eval_comp, iterate_derivative_at_0_eq_zero_of_lt R n w],\nend\n\n@[simp]\nlemma iterate_derivative_at_1 (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (polynomial.derivative^[n-\u03bd] (bernstein_polynomial R n \u03bd)).eval 1 =\n    (-1)^(n-\u03bd) * (pochhammer R (n - \u03bd)).eval (\u03bd + 1) :=\nbegin\n  rw flip' _ _ _ h,\n  simp [polynomial.eval_comp, h],\n  obtain rfl | h' := h.eq_or_lt,\n  { simp, },\n  { congr,\n    norm_cast,\n    rw [\u2190 tsub_add_eq_tsub_tsub, tsub_tsub_cancel_of_le (nat.succ_le_iff.mpr h')] },\nend\n\nlemma iterate_derivative_at_1_ne_zero [char_zero R] (n \u03bd : \u2115) (h : \u03bd \u2264 n) :\n  (polynomial.derivative^[n-\u03bd] (bernstein_polynomial R n \u03bd)).eval 1 \u2260 0 :=\nbegin\n  rw [bernstein_polynomial.iterate_derivative_at_1 _ _ _ h, ne.def, neg_one_pow_mul_eq_zero_iff,\n    \u2190nat.cast_succ, \u2190pochhammer_eval_cast, \u2190nat.cast_zero, nat.cast_inj],\n  exact (pochhammer_pos _ _ (nat.succ_pos \u03bd)).ne',\nend\n\nopen submodule\n\nlemma linear_independent_aux (n k : \u2115) (h : k \u2264 n + 1):\n  linear_independent \u211a (\u03bb \u03bd : fin k, bernstein_polynomial \u211a n \u03bd) :=\nbegin\n  induction k with k ih,\n  { apply linear_independent_empty_type, },\n  { apply linear_independent_fin_succ'.mpr,\n    fsplit,\n    { exact ih (le_of_lt h), },\n    { -- The actual work!\n      -- We show that the (n-k)-th derivative at 1 doesn't vanish,\n      -- but vanishes for everything in the span.\n      clear ih,\n      simp only [nat.succ_eq_add_one, add_le_add_iff_right] at h,\n      simp only [fin.coe_last, fin.init_def],\n      dsimp,\n      apply not_mem_span_of_apply_not_mem_span_image ((polynomial.derivative_lhom \u211a)^(n-k)),\n      simp only [not_exists, not_and, submodule.mem_map, submodule.span_image],\n      intros p m,\n      apply_fun (polynomial.eval (1 : \u211a)),\n      simp only [polynomial.derivative_lhom_coe, linear_map.pow_apply],\n      -- The right hand side is nonzero,\n      -- so it will suffice to show the left hand side is always zero.\n      suffices : (polynomial.derivative^[n-k] p).eval 1 = 0,\n      { rw [this],\n        exact (iterate_derivative_at_1_ne_zero \u211a n k h).symm, },\n      apply span_induction m,\n      { simp,\n        rintro \u27e8a, w\u27e9, simp only [fin.coe_mk],\n        rw [iterate_derivative_at_1_eq_zero_of_lt \u211a n ((tsub_lt_tsub_iff_left_of_le h).mpr w)] },\n      { simp, },\n      { intros x y hx hy, simp [hx, hy], },\n      { intros a x h, simp [h], }, }, },\nend\n\n/--\nThe Bernstein polynomials are linearly independent.\n\nWe prove by induction that the collection of `bernstein_polynomial n \u03bd` for `\u03bd = 0, ..., k`\nare linearly independent.\nThe inductive step relies on the observation that the `(n-k)`-th derivative, evaluated at 1,\nannihilates `bernstein_polynomial n \u03bd` for `\u03bd < k`, but has a nonzero value at `\u03bd = k`.\n-/\n\nlemma linear_independent (n : \u2115) :\n  linear_independent \u211a (\u03bb \u03bd : fin (n+1), bernstein_polynomial \u211a n \u03bd) :=\nlinear_independent_aux n (n+1) (le_refl _)\n\nlemma sum (n : \u2115) : (finset.range (n + 1)).sum (\u03bb \u03bd, bernstein_polynomial R n \u03bd) = 1 :=\nbegin\n  -- We calculate `(x + (1-x))^n` in two different ways.\n  conv { congr, congr, skip, funext, dsimp [bernstein_polynomial], rw [mul_assoc, mul_comm], },\n  rw \u2190add_pow,\n  simp,\nend\n\n\nopen polynomial\nopen mv_polynomial\n\nlemma sum_smul (n : \u2115) :\n  (finset.range (n + 1)).sum (\u03bb \u03bd, \u03bd \u2022 bernstein_polynomial R n \u03bd) = n \u2022 X :=\nbegin\n  -- We calculate the `x`-derivative of `(x+y)^n`, evaluated at `y=(1-x)`,\n  -- either directly or by using the binomial theorem.\n\n  -- We'll work in `mv_polynomial bool R`.\n  let x : mv_polynomial bool R := mv_polynomial.X tt,\n  let y : mv_polynomial bool R := mv_polynomial.X ff,\n\n  have pderiv_tt_x : pderiv tt x = 1, { simp [x], },\n  have pderiv_tt_y : pderiv tt y = 0, { simp [pderiv_X, y], },\n\n  let e : bool \u2192 polynomial R := \u03bb i, cond i X (1-X),\n\n  -- Start with `(x+y)^n = (x+y)^n`,\n  -- take the `x`-derivative, evaluate at `x=X, y=1-X`, and multiply by `X`:\n  have h : (x+y)^n = (x+y)^n := rfl,\n  apply_fun (pderiv tt) at h,\n  apply_fun (aeval e) at h,\n  apply_fun (\u03bb p, p * X) at h,\n\n  -- On the left hand side we'll use the binomial theorem, then simplify.\n\n  -- We first prepare a tedious rewrite:\n  have w : \u2200 k : \u2115,\n    \u2191k * polynomial.X ^ (k - 1) * (1 - polynomial.X) ^ (n - k) * \u2191(n.choose k) * polynomial.X =\n      k \u2022 bernstein_polynomial R n k,\n  { rintro (_|k),\n    { simp, },\n    { dsimp [bernstein_polynomial],\n      simp only [\u2190nat_cast_mul, nat.succ_eq_add_one, nat.add_succ_sub_one, add_zero, pow_succ],\n      push_cast,\n      ring, }, },\n\n  conv at h\n  { to_lhs,\n    rw [add_pow, (pderiv tt).map_sum, (mv_polynomial.aeval e).map_sum, finset.sum_mul],\n    -- Step inside the sum:\n    apply_congr, skip,\n    simp [pderiv_mul, pderiv_tt_x, pderiv_tt_y, e, w], },\n  -- On the right hand side, we'll just simplify.\n  conv at h\n  { to_rhs,\n    rw [pderiv_pow, (pderiv tt).map_add, pderiv_tt_x, pderiv_tt_y],\n    simp [e] },\n  simpa using h,\nend\n\nlemma sum_mul_smul (n : \u2115) :\n  (finset.range (n + 1)).sum (\u03bb \u03bd, (\u03bd * (\u03bd-1)) \u2022 bernstein_polynomial R n \u03bd) =\n    (n * (n-1)) \u2022 X^2 :=\nbegin\n  -- We calculate the second `x`-derivative of `(x+y)^n`, evaluated at `y=(1-x)`,\n  -- either directly or by using the binomial theorem.\n\n  -- We'll work in `mv_polynomial bool R`.\n  let x : mv_polynomial bool R := mv_polynomial.X tt,\n  let y : mv_polynomial bool R := mv_polynomial.X ff,\n\n  have pderiv_tt_x : pderiv tt x = 1, { simp [x], },\n  have pderiv_tt_y : pderiv tt y = 0, { simp [pderiv_X, y], },\n\n  let e : bool \u2192 polynomial R := \u03bb i, cond i X (1-X),\n\n  -- Start with `(x+y)^n = (x+y)^n`,\n  -- take the second `x`-derivative, evaluate at `x=X, y=1-X`, and multiply by `X`:\n  have h : (x+y)^n = (x+y)^n := rfl,\n  apply_fun (pderiv tt) at h,\n  apply_fun (pderiv tt) at h,\n  apply_fun (aeval e) at h,\n  apply_fun (\u03bb p, p * X^2) at h,\n\n  -- On the left hand side we'll use the binomial theorem, then simplify.\n\n  -- We first prepare a tedious rewrite:\n  have w : \u2200 k : \u2115,\n    \u2191k * (\u2191(k-1) * polynomial.X ^ (k - 1 - 1)) *\n      (1 - polynomial.X) ^ (n - k) * \u2191(n.choose k) * polynomial.X^2 =\n      (k * (k-1)) \u2022 bernstein_polynomial R n k,\n  { rintro (_|k),\n    { simp, },\n    { rcases k with (_|k),\n      { simp, },\n      { dsimp [bernstein_polynomial],\n        simp only [\u2190nat_cast_mul, nat.succ_eq_add_one, nat.add_succ_sub_one, add_zero, pow_succ],\n        push_cast,\n        ring, }, }, },\n\n  conv at h\n  { to_lhs,\n    rw [add_pow, (pderiv tt).map_sum, (pderiv tt).map_sum, (mv_polynomial.aeval e).map_sum,\n      finset.sum_mul],\n    -- Step inside the sum:\n    apply_congr, skip,\n    simp [pderiv_mul, pderiv_tt_x, pderiv_tt_y, e, w] },\n  -- On the right hand side, we'll just simplify.\n  conv at h\n  { to_rhs,\n    simp only [pderiv_one, pderiv_mul, pderiv_pow, pderiv_nat_cast, (pderiv tt).map_add,\n      pderiv_tt_x, pderiv_tt_y],\n    simp [e, smul_smul] },\n  simpa using h,\nend\n\n/--\nA certain linear combination of the previous three identities,\nwhich we'll want later.\n-/\nlemma variance (n : \u2115) :\n  (finset.range (n+1)).sum (\u03bb \u03bd, (n \u2022 polynomial.X - \u03bd)^2 * bernstein_polynomial R n \u03bd) =\n    n \u2022 polynomial.X * (1 - polynomial.X) :=\nbegin\n  have p :\n    (finset.range (n+1)).sum (\u03bb \u03bd, (\u03bd * (\u03bd-1)) \u2022 bernstein_polynomial R n \u03bd) +\n    (1 - (2 * n) \u2022 polynomial.X) * (finset.range (n+1)).sum (\u03bb \u03bd, \u03bd \u2022 bernstein_polynomial R n \u03bd) +\n    (n^2 \u2022 X^2) * (finset.range (n+1)).sum (\u03bb \u03bd, bernstein_polynomial R n \u03bd) = _ := rfl,\n  conv at p { to_lhs,\n    rw [finset.mul_sum, finset.mul_sum, \u2190finset.sum_add_distrib, \u2190finset.sum_add_distrib],\n    simp only [\u2190nat_cast_mul],\n    simp only [\u2190mul_assoc],\n    simp only [\u2190add_mul], },\n  conv at p { to_rhs,\n    rw [sum, sum_smul, sum_mul_smul, \u2190nat_cast_mul], },\n  calc _ = _ : finset.sum_congr rfl (\u03bb k m, _)\n     ... = _ : p\n     ... = _ : _,\n  { congr' 1, simp only [\u2190nat_cast_mul] with push_cast,\n    cases k; { simp, ring, }, },\n  { simp only [\u2190nat_cast_mul] with push_cast,\n    cases n,\n    { simp, },\n    { simp, ring, }, },\nend\n\nend bernstein_polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/polynomial/bernstein.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7095554959474244}}
{"text": "import mynat.definition\nimport mynat.mul\nimport world2.level2\nimport world2.level5\nimport world2.level6\n\nnamespace mynat\n\nlemma succ_mul (a b : mynat) : succ(a) * b = a * b + b :=\nbegin [nat_num_game]\n    induction b with d hd,\n    {\n        repeat {rw mul_zero},\n        rw add_zero,\n        refl,\n    },\n    {\n        rw mul_succ,\n        rw hd,\n        rw mul_succ,\n        rw succ_eq_add_one,\n        rw succ_eq_add_one,\n        rw \u2190 add_assoc,\n        rw \u2190 add_assoc,\n        rw add_right_comm (a * d),\n        refl,\n    },\nend\n\nend mynat", "meta": {"author": "nomoid", "repo": "lean-proofs", "sha": "b9f03a24623d1a1d111d6c2bbf53c617e2596d6a", "save_path": "github-repos/lean/nomoid-lean-proofs", "path": "github-repos/lean/nomoid-lean-proofs/lean-proofs-b9f03a24623d1a1d111d6c2bbf53c617e2596d6a/src/world3/level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.958537730841905, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.7094850534162334}}
{"text": "namespace TBA\n\n-- Let's work with some inductive types other than `Nat`!\n\n-- Here is our very own definition of `List`:\ninductive List (\u03b1 : Type) where\n  | nil : List \u03b1\n  | cons (head : \u03b1) (tail : List \u03b1) : List \u03b1\n\nnotation  (priority := high) \"[\" \"]\" => List.nil   -- `[]`\ninfixr:67 (priority := high) \" :: \"  => List.cons  -- `a :: as`\n\n-- as a warm-up exercise, let's define concatenation of two lists\ndef append (as bs : List \u03b1) : List \u03b1 := _\n\ninfixl:65 (priority := high) \" ++ \" => append\n\nexample : 1::2::[] ++ 3::4::[] = 1::2::3::4::[] := rfl\n\n-- as with associativity on `Nat`, think twice about what induction variable to use!\ntheorem append_assoc : (as ++ bs) ++ cs = as ++ (bs ++ cs) := by\n\nopen Decidable\n\n/-\nOne important special case of `Decidable` is decidability of equalities:\n```\nabbrev DecidableEq (\u03b1 : Type) :=\n  (a b : \u03b1) \u2192 Decidable (a = b)\n\ndef decEq [s : DecidableEq \u03b1] (a b : \u03b1) : Decidable (a = b) :=\n  s a b\n```\nNote: `DecidableEq` is defined using `abbrev` instead of `def` because typeclass resolution only\nunfolds the former for performance reasons.\n\nLet's try to prove that `List` equality is decidable!\n-/\n-- hint: Something is still missing. Do we need to assume anything about `\u03b1`?\n-- hint: Apply `match` case distinctions until the the appropriate `Decidable` constructor is clear,\n--   then fill in its proof argument with `by`.\n--   We could also do everything in a `by` block, but it's nicer to reserve tactics for proofs so we have\n--   more control about the code of programs, i.e. the part that is actually executed\ndef ldecEq  (as bs : List \u03b1) : Decidable (as = bs) := _\n\n-- Let's declare the instance:\ninstance  : DecidableEq (List \u03b1) := _\n\n-- This should now work:\n#eval decEq (1::2::[]) (1::3::[])\n\n/-\n`DecidabePred` is another convenient abbreviation of `Decidable`\n```\nabbrev DecidablePred (r : \u03b1 \u2192 Prop) :=\n  (a : \u03b1) \u2192 Decidable (r a)\n```\nIf we have `[DecidablePred p]`, we can e.g. use `if p a then ...` for some `a : \u03b1`.\n\n`filter p as` is a simple list function that should remove all elements `a` for which `p a` does not hold.\n-/\ndef filter (p : \u03b1 \u2192 Prop) [DecidablePred p] (as : List \u03b1) : List \u03b1 := _\n\nexample : filter (fun x => x % 2 = 0) (1::2::3::4::[]) = 2::4::[] := rfl\n\nvariable {p : \u03b1 \u2192 Prop} [DecidablePred p] {as bs : List \u03b1}\n\n-- These helper theorems can be useful, also for manual rewriting\n@[simp] theorem filter_cons_true (h : p a) : filter p (a :: as) = a :: filter p as :=\n  by simp [filter, h]\n@[simp] theorem filter_cons_false (h : \u00ac p a) : filter p (a :: as) = filter p as :=\n  by simp [filter, h]\n-- It's worthwhile thinking about what's actually happening here:\n-- * first, `filter p (a :: as)` is unfolded to `if p a then a :: filter p as else filter p as`\n--   (note that the second `filter` cannot be unfolded)\n-- * then `if p a then ...` is rewritten to `if True then ...` using `h`\n-- * finally, `if True then a :: filter p as else ...` is rewritten to `a :: filter p as` using\n--   the built-in simp theorem `Lean.Simp.ite_true`\n\n-- useful tactic: `by_cases h : q` for a decidable proposition `q`\ntheorem filter_idem : filter p (filter p as) = filter p as := by\n\ntheorem filter_append : filter p (as ++ bs) = filter p as ++ filter p bs := by\n\n-- list membership as an inductive predicate:\ninductive Mem (a : \u03b1) : List \u03b1 \u2192 Prop where\n  -- either it's the first element...\n  | head {as} : Mem a (a::as)\n  -- or it's in the remainder list\n  | tail {as} : Mem a as \u2192 Mem a (a'::as)\n\ninfix:50 \" \u2208 \" => Mem\n\n-- recall that `a \u2260 b` is the same as `a = b \u2192 False`\ntheorem mem_of_nonempty_filter (h : \u2200 a, p a \u2192 a = x) : filter p as \u2260 [] \u2192 x \u2208 as := by\n\n-- This proof is pretty long! Some hints:\n-- * If you have an assumption `h : a \u2208 []`, you can solve the current goal by `cases h`:\n--   since there is no `Mem` constructor that could possibly match `[]`, there is nothing left to prove!\n--   This exclusion of cases, and case analysis on inductive predicates in general,\n--   is also called *rule inversion* since we (try to) apply the introduction rules (constructors)\n--   \"in reverse\".\n-- * On the other hand, if you try to do case analysis on a proof of e.g. `a \u2208 filter p as`,\n--   Lean will complain with \"dependent elimination failed\" since it *doesn't* know yet if\n--   the argument `filter p as` is of the form `_ :: _` as demanded by the `Mem` constructors.\n--   You need to get the assumption into the shape `_ \u2208 []` or `_ \u2208 _ :: _` before applying\n--   `(no)match/cases` to it.\ntheorem mem_filter : a \u2208 filter p as \u2194 a \u2208 as \u2227 p a := _\n\n-- Here is an alternative definition of list membership via `append`\ninductive Mem' (a : \u03b1) : List \u03b1 \u2192 Prop where\n  | intro (as bs) : Mem' a (as ++ (a :: bs))\n\ninfix:50 \" \u2208' \" => Mem'\n\n-- Let's prove that they are equivalent!\ntheorem mem_mem' : a \u2208 as \u2194 a \u2208' as := _\n\nend TBA\n", "meta": {"author": "IPDSnelting", "repo": "tba-2022", "sha": "1aa29ce5494c1287a282b88e798f8430f7e49af9", "save_path": "github-repos/lean/IPDSnelting-tba-2022", "path": "github-repos/lean/IPDSnelting-tba-2022/tba-2022-1aa29ce5494c1287a282b88e798f8430f7e49af9/TBA/Exercises/Exercise5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7094482347237164}}
{"text": "import data.polynomial\nimport missing_mathlib.ring_theory.algebra\n\nuniverse variables u v w\n\nnamespace polynomial\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\nopen polynomial\n\nlemma leading_coeff_X_add_C {\u03b1 : Type v} [integral_domain \u03b1] [decidable_eq \u03b1] (a b : \u03b1) (ha : a \u2260 0): \n  leading_coeff (C a * X + C b) = a :=\nbegin\n  rw [add_comm, leading_coeff_add_of_degree_lt],\n  { simp },\n  { simp [degree_C ha],\n    apply lt_of_le_of_lt degree_C_le (with_bot.coe_lt_coe.2 zero_lt_one)}\nend\n\nend polynomial\n\nsection eval\u2082\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [comm_ring \u03b1] [decidable_eq \u03b1] [semiring \u03b2]\nvariables (f : \u03b1 \u2192+* \u03b2) (x : \u03b2) (p q : polynomial \u03b1)\nopen is_semiring_hom\nopen polynomial finsupp finset\n\nlemma eval\u2082_mul_noncomm (hf : \u2200 b a, a * f b = f b * a) : \n  (p * q).eval\u2082 f x = p.eval\u2082 f x * q.eval\u2082 f x :=\nbegin\n  dunfold eval\u2082,\n  rw [add_monoid_algebra.mul_def, finsupp.sum_mul _ p], simp only [finsupp.mul_sum _ q], rw [sum_sum_index],\n  { apply sum_congr rfl, assume i hi, dsimp only, rw [sum_sum_index],\n    { apply sum_congr rfl, assume j hj, dsimp only,\n      rw [sum_single_index, is_semiring_hom.map_mul f, pow_add],\n      { rw [mul_assoc, \u2190mul_assoc _ (x ^ i), \u2190 hf _ (x ^ i)], \n        simp only [mul_assoc] },\n      { rw [is_semiring_hom.map_zero f, zero_mul] } },\n    { intro, rw [is_semiring_hom.map_zero f, zero_mul] },\n    { intros, rw [is_semiring_hom.map_add f, add_mul] } },\n  { intro, rw [is_semiring_hom.map_zero f, zero_mul] },\n  { intros, rw [is_semiring_hom.map_add f, add_mul] }\nend\n\nend eval\u2082\n\nlemma finsupp_sum_eq_eval\u2082 (\u03b1 : Type v) (\u03b2 : Type w)\n  [decidable_eq \u03b1] [comm_ring \u03b1] [decidable_eq \u03b2] [add_comm_group \u03b2] [module \u03b1 \u03b2]\n  (f : \u03b2 \u2192\u2097[\u03b1] \u03b2) (v : \u03b2) (p : polynomial \u03b1) : \n  (finsupp.sum p (\u03bb n b, b \u2022 (f ^ n) v))  \n    = polynomial.eval\u2082 (algebra_map \u03b1 (\u03b2 \u2192\u2097[\u03b1] \u03b2)) f p v :=\nbegin\n  dunfold polynomial.eval\u2082 finsupp.sum,\n  convert @finset.sum_hom _ _ _ _ _ p.support _ (\u03bb h : \u03b2 \u2192\u2097[\u03b1] \u03b2, h v) _,\n  simp [module.endomorphism_algebra_map_apply]\nend\n\nlemma eval\u2082_prod_noncomm {\u03b1 \u03b2 : Type*} [comm_ring \u03b1] [decidable_eq \u03b1] [semiring \u03b2]\n  (f : \u03b1 \u2192+* \u03b2) (hf : \u2200 b a, a * f b = f b * a) (x : \u03b2)\n  (ps : list (polynomial \u03b1)) : \n  polynomial.eval\u2082 f x ps.prod = (ps.map (\u03bb p, (polynomial.eval\u2082 f x p))).prod :=\nbegin \n  induction ps,\n  simp,\n  simp [eval\u2082_mul_noncomm f _ _ _ hf, ps_ih] {contextual := tt}\nend\n", "meta": {"author": "abentkamp", "repo": "spectral", "sha": "751645679ef1cb6266316349de9e492eff85484c", "save_path": "github-repos/lean/abentkamp-spectral", "path": "github-repos/lean/abentkamp-spectral/spectral-751645679ef1cb6266316349de9e492eff85484c/src/missing_mathlib/data/polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7093955182209679}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.polynomial.coeff\nimport data.nat.choose.basic\n\n/-!\n\n# Vandermonde's identity\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove Vandermonde's identity (`nat.add_choose_eq`):\n`(m + n).choose k = \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, m.choose ij.1 * n.choose ij.2`\n\nWe follow the algebraic proof from\nhttps://en.wikipedia.org/wiki/Vandermonde%27s_identity#Algebraic_proof .\n\n-/\n\nopen_locale big_operators\n\nopen polynomial finset.nat\n\n/-- Vandermonde's identity -/\nlemma nat.add_choose_eq (m n k : \u2115) :\n  (m + n).choose k = \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, m.choose ij.1 * n.choose ij.2 :=\nbegin\n  calc (m + n).choose k\n      = ((X + 1) ^ (m + n)).coeff k : _\n  ... = ((X + 1) ^ m * (X + 1) ^ n).coeff k : by rw pow_add\n  ... = \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, m.choose ij.1 * n.choose ij.2 : _,\n  { rw [coeff_X_add_one_pow, nat.cast_id], },\n  { rw [coeff_mul, finset.sum_congr rfl],\n    simp only [coeff_X_add_one_pow, nat.cast_id, eq_self_iff_true, imp_true_iff], }\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/choose/vandermonde.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7093955126433654}}
{"text": "import game.order.level08\nimport game.order.level02\nimport game.order.dumb\nimport game.order.lessdumb\nimport game.order.twocase\nopen real\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 9\n\nThis level invites you to work out a property of the absolute value.\nIn Lean the absolute value of $x$ is denoted by `abs x`. \nFor ease of use, a notation can be used around that definition as below.\nFeel free to use the triangle inequality on the real numbers,\n\n`abs_add : \u2200 (a b : ?M_1), |a + b| \u2264 |a| + |b|`\n\ntogether with the `linarith` and `norm_num` tactics.\n-/\n\nnotation `|` x `|` := abs x\n\n-- begin hide\n-- this to go in the side bar\nlemma eq_sqr_to_eq (a b : \u211d) (ha : 0 \u2264 a) (hb : 0 \u2264 b) : a^2 = b^2 \u2192 a = b :=\nbegin\n    intro h,\n    have h2 : sqrt (a ^ 2) = sqrt (a ^ 2),\n    refl,\n    --occurreneces.pos introduce\n    rw h at h2 {occs := occurrences.pos [2]},\n    have j := sqrt_sqr ha,\n    rw j at h2,\n    have k := sqrt_sqr hb,\n    rw k at h2,\n    exact h2,\n\nend\n-- end hide\n\n/- Lemma\nFor any two real numbers $a$ and $b$, we have that\n$$|a + b| = |a| + |b|$$ if and only if $ab \\ge 0$ .\n-/\ntheorem abs_sub_eq_sum_abs (a b : \u211d) : |a + b| = |a| + |b| \u2194 a * b \u2265 0 :=\nbegin\n    have H0 : (a+b)^2 = |a+b|^2, \n        have h01 := abs_mul_abs_self (a+b),\n        rw pow_two _, rw pow_two _, symmetry, exact h01,\n    have H1 : 0 \u2264 (a + b) ^ 2, exact pow_two_nonneg (a+b),\n    have H2 : (a+b) ^ 2 = a ^2 + 2 * a * b + b^2, ring,\n    have H3 : ( |a| + |b| )^2 = |a|^2 + 2*|a|*|b| + |b|^2, ring,\n    rw H0 at H2,\n    have Ha : a^2 = |a|^2, \n        have h01 := abs_mul_abs_self a,\n        rw pow_two _, rw pow_two _, symmetry, exact h01,\n    have Hb : b^2 = |b|^2, \n        have h01 := abs_mul_abs_self b,\n        rw pow_two _, rw pow_two _, symmetry, exact h01,\n    rw [Ha, Hb] at H2,\n\n    split,\n    intro j,\n    rw j at H2, rw H3 at H2, simp at H2,\n    rw mul_assoc at H2, rw mul_assoc at H2,\n    have g : (|a| * |b|) = (a * b),\n    linarith,\n    have g2 : |a * b| = |a| * |b|, exact abs_mul _ _,\n    rw \u2190 g2 at g,\n    by_contradiction hn, push_neg at hn,\n    have g3 : |a * b| = -(a * b),\n    exact abs_of_neg hn,\n    rw g at g3, linarith,\n\n    --add hints and comments and stuff\n    intro k,\n    have g : |a * b| = a * b,\n    exact abs_of_nonneg k,\n    have g2 : |a * b| = |a| * |b|,\n    exact abs_mul _ _,\n    rw g2 at g, rw mul_assoc 2 a b at H2,\n    rw \u2190 g at H2,\n    have g3 : |a| ^ 2 + 2 * ( |a| * |b| ) + |b| ^ 2 = ( |a| + |b| )^2, ring,\n    rw g3 at H2,\n    have g4 : sqrt ( |a + b| ^ 2 ) = sqrt ( |a + b| ^ 2), refl,\n    rw H2 at g4 {occs := occurrences.pos [2]},\n    have hab : 0 \u2264 |a + b|,  exact is_absolute_value.abv_nonneg abs (a+b),\n    have ha : 0 \u2264 |a|,  exact is_absolute_value.abv_nonneg abs a,\n    have hb : 0 \u2264 |b|,  exact is_absolute_value.abv_nonneg abs b,\n    have hc : 0 \u2264 |a| + |b|, linarith,\n    have G := eq_sqr_to_eq ( |a + b| ) ( |a| + |b| ) hab hc H2, exact G,\n    \nend\n\nend xena -- hide\n", "meta": {"author": "DavidTalone", "repo": "Real-Number-Game", "sha": "b159ae1219209c3da97566b64b8986b146ec9053", "save_path": "github-repos/lean/DavidTalone-Real-Number-Game", "path": "github-repos/lean/DavidTalone-Real-Number-Game/Real-Number-Game-b159ae1219209c3da97566b64b8986b146ec9053/src/game/order/level09.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7093955088136847}}
{"text": "/-\nCopyright (c) 2018 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport data.nat.interval\nimport data.nat.prime\nimport group_theory.perm.sign\nimport tactic.fin_cases\n\nexample (f : \u2115 \u2192 Prop) (p : fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val :=\nbegin\n  fin_cases *,\n  simp, assumption,\n  simp, assumption,\n  simp, assumption,\nend\n\nexample (f : \u2115 \u2192 Prop) (p : fin 0) : f p.val :=\nby fin_cases *\n\nexample (f : \u2115 \u2192 Prop) (p : fin 1) (h : f 0) : f p.val :=\nbegin\n  fin_cases p,\n  assumption\nend\n\nexample (x2 : fin 2) (x3 : fin 3) (n : nat) (y : fin n) : x2.val * x3.val = x3.val * x2.val :=\nbegin\n  fin_cases x2;\n  fin_cases x3,\n  success_if_fail { fin_cases * },\n  success_if_fail { fin_cases y },\n  all_goals { refl },\nend\n\nopen finset\nexample (x : \u2115) (h : x \u2208 Ico 2 5) : x = 2 \u2228 x = 3 \u2228 x = 4 :=\nbegin\n  fin_cases h,\n  all_goals { simp }\nend\n\nopen nat\nexample (x : \u2115) (h : x \u2208 [2,3,5,7]) : x = 2 \u2228 x = 3 \u2228 x = 5 \u2228 x = 7 :=\nbegin\n  fin_cases h,\n  all_goals { simp }\nend\n\nexample (x : \u2115) (h : x \u2208 [2,3,5,7]) : true :=\nbegin\n  success_if_fail { fin_cases h with [3,3,5,7] },\n  trivial\nend\n\nexample (x : list \u2115) (h : x \u2208 [[1],[2]]) : x.length = 1 :=\nbegin\n  fin_cases h with [[1],[1+1]],\n  simp,\n  guard_target (list.length [1 + 1] = 1),\n  simp\nend\n\n -- testing that `with` arguments are elaborated with respect to the expected type:\nexample (x : \u2124) (h : x \u2208 ([2,3] : list \u2124)) : x = 2 \u2228 x = 3 :=\nbegin\n  fin_cases h with [2,3],\n  all_goals { simp }\nend\n\n\ninstance (n : \u2115) : decidable (prime n) := decidable_prime_1 n\nexample (x : \u2115) (h : x \u2208 (range 10).filter prime) : x = 2 \u2228 x = 3 \u2228 x = 5 \u2228 x = 7 :=\nbegin\n  fin_cases h; exact dec_trivial\nend\n\nopen equiv.perm\nexample (x : (\u03a3 (a : fin 4), fin 4)) (h : x \u2208 fin_pairs_lt 4) : x.1.val < 4 :=\nbegin\n  fin_cases h; simp,\n  any_goals { exact dec_trivial },\nend\n\nexample (x : fin 3) : x.val < 5 :=\nbegin\n  fin_cases x; exact dec_trivial\nend\n\nexample (f : \u2115 \u2192 Prop) (p : fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val :=\nbegin\n  fin_cases *,\n  all_goals { assumption }\nend\n\nexample (n : \u2115) (h : n % 3 \u2208 [0,1]) : true :=\nbegin\n  fin_cases h,\n  guard_hyp h : n % 3 = 0, trivial,\n  guard_hyp h : n % 3 = 1, trivial,\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/test/fin_cases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7093914650755543}}
{"text": "import .auxiliary ...mathlib.data.list.basic\n\nvariables {\u03b1 \u03b2 \u03b3 : Type}\n\nnamespace list\n\ndef update_nth_force : list \u03b1 \u2192 \u2115 \u2192 \u03b1 \u2192 \u03b1 \u2192 list \u03b1\n| (x::xs) 0     a a' := a :: xs\n| (x::xs) (i+1) a a' := x :: update_nth_force xs i a a'\n| []      0     a a' := [a] \n| []      (i+1) a a' := a' :: update_nth_force [] i a a'\n\ndef zip_pad (a' b') : list \u03b1 \u2192 list \u03b2 \u2192 list (\u03b1 \u00d7 \u03b2)\n| [] [] := []\n| [] (b::bs) := (a',b)::(zip_pad [] bs)\n| (a::as) [] := (a,b')::(zip_pad as [])\n| (a::as) (b::bs) := (a,b)::(zip_pad as bs)\n\nlemma cons_zip_pad_cons {a b a' b'} {as : list \u03b1} {bs : list \u03b2} : \n  zip_pad a' b' (a::as) (b::bs) = (a,b)::(zip_pad a' b' as bs) :=\nbegin unfold zip_pad end\n\n@[simp] def map_mul [has_mul \u03b1] (a) (as : list \u03b1) : list \u03b1 :=\nlist.map (\u03bb x, a * x) as\n\n@[simp] def map_neg [has_neg \u03b1] (as : list \u03b1) : list \u03b1 :=\nlist.map (\u03bb x, -x) as\n\ndef comp_add [has_zero \u03b1] [has_add \u03b1] (as1 as2 : list \u03b1) : list \u03b1 := \nlist.map (\u03bb xy, prod.fst xy + prod.snd xy) (list.zip_pad 0 0 as1 as2)\n\ndef comp_sub [has_zero \u03b1] [has_neg \u03b1] [has_add \u03b1] (as1 as2 : list \u03b1) : list \u03b1 := \ncomp_add as1 (map_neg as2)\n\ndef dot_prod [has_zero \u03b1] [has_add \u03b1] [has_mul \u03b1] (as1 as2 : list \u03b1) : \u03b1 := \nlist.sum (list.map (\u03bb xy, prod.fst xy * prod.snd xy) (list.zip_pad 0 0 as1 as2))\n\n@[simp] lemma nil_dot_prod [semiring \u03b1] :\n  \u2200 (as : list \u03b1), dot_prod [] as = 0  \n| [] := \n  begin\n    unfold dot_prod, unfold list.zip_pad, simp\n  end\n| (a::as) := \n  begin\n    unfold dot_prod, unfold list.zip_pad,\n    simp, apply nil_dot_prod\n  end\n\n@[simp] lemma dot_prod_nil [semiring \u03b1] :\n  \u2200 (as : list \u03b1), dot_prod as [] = 0  \n| [] := \n  begin\n    unfold dot_prod, unfold list.zip_pad, simp\n  end\n| (a::as) := \n  begin\n    unfold dot_prod, unfold list.zip_pad,\n    simp, apply dot_prod_nil\n  end\n\n@[simp] lemma cons_dot_prod_cons [semiring \u03b1] (a1 a2 : \u03b1) (as1 as2 : list \u03b1) : \ndot_prod (a1::as1) (a2::as2) = (a1 * a2) + dot_prod as1 as2 := \nbegin unfold dot_prod, rewrite cons_zip_pad_cons, simp end\n\nlemma nil_comp_add [semiring \u03b1] :\n  \u2200 (as : list \u03b1), comp_add [] as = as \n| [] := rfl \n| (a::as) := \n  begin\n    unfold comp_add, unfold list.zip_pad,\n    unfold list.map, simp, \n    have h := nil_comp_add as,\n    unfold comp_add at h, rewrite h\n  end\n\nlemma comp_add_nil [semiring \u03b1] :\n  \u2200 (as : list \u03b1), comp_add as [] = as \n| [] := rfl\n| (a::as) := \n  begin\n    unfold comp_add, unfold list.zip_pad, \n    simp, have h := comp_add_nil as, \n    unfold comp_add at h, rewrite h \n  end\n\nlemma cons_comp_add_cons [semiring \u03b1] (a1 a2 : \u03b1) (as1 as2) :\ncomp_add (a1::as1) (a2::as2) = (a1 + a2)::(comp_add as1 as2) := \nbegin unfold comp_add, unfold list.zip_pad, simp end\n\nlemma comp_add_dot_prod [semiring \u03b1] :\n  \u2200 (as1 as2 as3 : list \u03b1), dot_prod (comp_add as1 as2) as3 = (dot_prod as1 as3) + (dot_prod as2 as3)\n| [] as2 as3 := \n  begin\n    rewrite nil_comp_add, \n    rewrite nil_dot_prod, simp\n  end\n| as1 [] as3 := \n  begin\n    rewrite comp_add_nil, \n    rewrite nil_dot_prod, simp\n  end\n| as1 as2 [] := \n  begin repeat {rewrite dot_prod_nil}, simp end\n| (a1::as1) (a2::as2) (a3::as3) := \n  begin\n    rewrite cons_comp_add_cons, \n    repeat {rewrite cons_dot_prod_cons},\n    simp, rewrite add_mul, rewrite add_assoc,\n    rewrite comp_add_dot_prod\n  end\n\nlemma map_mul_dot_prod [semiring \u03b1] (a : \u03b1) :\n  \u2200 (as1 as2), dot_prod (map_mul a as1) as2 = a * (dot_prod as1 as2) \n| [] as2 := \n  begin\n    unfold map_mul, simp,\n    repeat {rewrite nil_dot_prod}\n  end\n| as1 [] := \n  begin\n    repeat {rewrite dot_prod_nil},\n    rewrite mul_zero\n  end\n| (a1::as1) (a2::as2) := \n  begin\n    unfold map_mul, simp, repeat {rewrite cons_dot_prod_cons}, \n    have h := map_mul_dot_prod as1 as2, unfold map_mul at h, \n    rewrite h, rewrite mul_add, simp, rewrite mul_assoc\n  end\n\n@[simp] lemma mul_dot_prod [semiring \u03b1] {a : \u03b1} {as1 as2} :\n   a * (dot_prod as1 as2) = dot_prod (map_mul a as1) as2 :=\nby rewrite map_mul_dot_prod  \n\ndef neg_dot_prod [ring \u03b1] : \u2200 (as1 as2 : list \u03b1),  \n  dot_prod (list.map (\u03bb x, -x) as1) as2 = -(dot_prod as1 as2) := \nbegin\n  intros as1 as2,\n  rewrite eq.symm (one_mul (dot_prod as1 as2)),\n  rewrite neg_mul_eq_neg_mul, simp,\nend\n\nlemma sum_exp [has_zero \u03b1] [has_add \u03b1] (as : list \u03b1) :\n  sum as = foldl (+) 0 as:= refl _\n\n--def omap (f : \u03b1 \u2192 option \u03b2) : list \u03b1 \u2192 list \u03b2  \n--| [] := []\n--| (a::as) := \n--  match f a with \n--  | none := omap as \n--  | (some b) := b::(omap as) \n--  end\n--\n--lemma mem_omap {f : \u03b1 \u2192 option \u03b2} {a} {b} (he : f a = some b) : \n--  \u2200 {as : list \u03b1} (HM : a \u2208 as), b \u2208 omap f as  \n--| [] hm := by cases hm\n--| (a'::as) hm :=\n--  begin \n--    unfold has_mem.mem at hm, unfold list.mem at hm,\n--    cases hm with hm hm, subst hm,\n--    unfold omap, rewrite he, apply or.inl rfl,\n--    unfold omap, cases (f a'), \n--    apply mem_omap, apply hm, \n--    apply or.inr, apply mem_omap, apply hm \n--  end \n--\n--lemma mem_omap_of_mem_omap_tail {f : \u03b1 \u2192 option \u03b2} {a} {b} :\n--  \u2200 {as : list \u03b1}, b \u2208 omap f as \u2192 b \u2208 omap f (a::as) := \n--begin\n--  intros as h, unfold omap, cases (f a),\n--  apply h, apply or.inr h\n--end\n--\n--lemma exp_mem_omap {f : \u03b1 \u2192 option \u03b2} {b : \u03b2} : \u2200 {as : list \u03b1}, (b \u2208 omap f as) \u2194 \u2203 a, a \u2208 as \u2227 some b = f a \n--| [] := \n--  iff.intro \n--    (by {intro h, cases h}) \n--    (begin intro h, cases h with a ha, cases ha^.elim_left end)\n--| (a::as) := \n-- iff.intro \n-- (begin\n--    intro h, unfold omap at h, \n--    cases (dest_option (f a)) with ho ho, \n--    rewrite ho at h, \n--    cases (exp_mem_omap^.elim_left h) with a' ha', \n--    cases ha' with ha1' ha2',\n--    existsi a', apply and.intro (or.inr ha1') ha2',\n--    cases ho with b' hb', rewrite hb' at h,\n--    unfold omap at h, rewrite mem_cons_iff at h,\n--    cases h with h h, existsi a,\n--    apply and.intro (or.inl rfl), rewrite h,\n--    apply eq.symm hb',\n--    cases (exp_mem_omap^.elim_left h) with a' ha', \n--    cases ha' with ha1' ha2',\n--    existsi a', apply and.intro (or.inr ha1') ha2'\n--  end)\n-- (begin \n--   intro h, cases h with a' ha', \n--   cases ha' with h1 h2, rewrite mem_cons_iff at h1, \n--   cases h1 with h1 h1, \n--   unfold omap, subst h1, rewrite eq.symm h2, \n--   apply or.inl rfl, apply mem_omap_of_mem_omap_tail,\n--   apply exp_mem_omap^.elim_right, existsi a',\n--   apply and.intro h1 h2\n--  end)\n\nlemma exists_maximum [linear_order \u03b2] : \n\u2200 (bs : list \u03b2) (hi : bs \u2260 []), \u2203 b, b \u2208 bs \u2227 \u2200 b' \u2208 bs, b' \u2264 b \n| [] hi := begin exfalso, apply hi rfl end\n| [b] hi := \n  begin\n    existsi b, apply and.intro (or.inl rfl), \n    intros b' hb', cases hb' with hb' hb', \n    subst hb', cases hb',\n  end\n| (b::b'::bs') hi := \n  begin\n    cases (exists_maximum (b'::bs') _) with bm hbm, \n    cases hbm with hbm1 hbm2,\n    apply @classical.by_cases (b \u2264 bm); intro hle,\n\n    existsi bm, apply and.intro (or.inr hbm1), \n    intros bl hbl, rewrite mem_cons_iff at hbl, \n    cases hbl with hbl hbl, subst hbl, apply hle, \n    apply hbm2 _ hbl,\n\n    existsi b, apply and.intro (or.inl rfl),\n    intros bl hbl, rewrite mem_cons_iff at hbl, \n    cases hbl with hbl hbl, subst hbl, \n    apply le_trans, apply hbm2 _ hbl, \n    apply le_of_not_le hle, \n    intro hc, cases hc \n  end\n\nlemma exists_minimum [hlo : linear_order \u03b2] : \n\u2200 (bs : list \u03b2) (hi : bs \u2260 []), \u2203 b, b \u2208 bs \u2227 \u2200 b' \u2208 bs, b' \u2265 b :=  \n@exists_maximum _ (converse_linear_order hlo)\n\n\nlemma dest_list : \u2200 (as : list \u03b1), as = [] \u2228 \u2203 a' as', as = (a'::as')\n| [] := or.inl rfl \n| (a::as) := begin apply or.inr, existsi a, existsi as, refl end\n\n\n-- def list.product : list \u03b1 \u2192 list \u03b2 \u2192 list (\u03b1 \u00d7 \u03b2) \n-- | [] _ := []\n-- | (a1::l1) l2 := (list.map (\u03bb a2, \u27e8a1,a2\u27e9) l2) ++ list.product l1 l2 \n\ndef pluck (p : \u03b1 \u2192 Prop) [decidable_pred p] : list \u03b1 \u2192 option (\u03b1 \u00d7 list \u03b1)\n| []      := none \n| (a::as) := \n  if p a \n  then some (a, as) \n  else do (a',as') \u2190 pluck as, \n          some (a',a::as')\n\ndef pluck_true (p : \u03b1 \u2192 Prop) [decidable_pred p] (a as) (ha : p a) :\n  pluck p (a::as) = some (a,as) := \nbegin unfold pluck, rewrite ite_eq_of, apply ha end\n\ndef pluck_false (p : \u03b1 \u2192 Prop) [decidable_pred p] (a as) (ha : \u00ac p a) :\n  pluck p (a::as) \n  = (do (a',as') \u2190 pluck p as, some (a',a::as') ) := \nbegin unfold pluck, rewrite ite_eq_of_not, refl, apply ha end\n\n/- equiv -/\n\ndef equiv (l1 l2 : list \u03b1) := l1 \u2286 l2 \u2227 l2 \u2286 l1\n\nnotation l1 `\u2243` l2 := equiv l1 l2\n\ndef equiv.refl {l : list \u03b1} : l \u2243 l := \nand.intro (subset.refl _) (subset.refl _)\n\ndef equiv.symm {as1 as2 : list \u03b1} : (as1 \u2243 as2) \u2192 (as2 \u2243 as1) :=\nbegin\n  intro h, cases h with h1 h2, \n  apply and.intro; assumption\nend \n\nlemma equiv.trans {l1 l2 l3 : list \u03b1} : (l1 \u2243 l2) \u2192 (l2 \u2243 l3) \u2192 (l1 \u2243 l3) :=  \nbegin\n  intros h1 h2,\n  cases h1 with h1a h1b, cases h2 with h2a h2b, \n  apply and.intro (subset.trans h1a h2a) (subset.trans h2b h1b),\nend \n\nlemma subset.swap {a1 a2 : \u03b1} {l} : (a1::a2::l) \u2286 (a2::a1::l) :=  \nbegin\n  intros a ha, cases ha with ha ha,\n  apply or.inr (or.inl ha), cases ha with ha ha,\n  apply or.inl ha, apply or.inr (or.inr ha)\nend\n\nlemma equiv.swap {a1 a2 : \u03b1} {l} : (a1::a2::l) \u2243 (a2::a1::l) :=  \nbegin apply and.intro; apply subset.swap end\n\nlemma cons_equiv_cons {a : \u03b1} {l1 l2} : (l1 \u2243 l2) \u2192 ((a::l1) \u2243 (a::l2)) := \nbegin\n  intro h, cases h with hl hr,\n  apply and.intro; apply cons_subset_cons; assumption\nend\n\nlemma mem_iff_mem_of_equiv {as1 as2 : list \u03b1} :\n  (as1 \u2243 as2) \u2192 \u2200 (a : \u03b1), a \u2208 as1 \u2194 a \u2208 as2 := \nbegin\n  intros heqv a, cases heqv with hss1 hss2, \n  apply iff.intro; intro hm,\n  apply hss1; assumption,\n  apply hss2; assumption\nend\n\nlemma map_union [decidable_eq \u03b1] [decidable_eq \u03b2] \n  {f : \u03b1 \u2192 \u03b2} {as1 as2 : list \u03b1} :\n  map f (as1 \u222a as2) \u2243 (map f as1) \u222a (map f as2) := \nbegin\n  apply and.intro; intros x hx,\n  rewrite mem_map at hx, cases hx with y hy,\n  cases hy with hy1 hy2, subst hy2, \n  rewrite mem_union at hy1,\n  cases hy1 with hym hym, \n  apply mem_union_left, rewrite mem_map,\n  existsi y, apply and.intro, assumption, refl,\n  apply mem_union_right, rewrite mem_map,\n  existsi y, apply and.intro, assumption, refl,\n  rewrite mem_union at hx, cases hx with hx hx;\n  rewrite mem_map at hx; cases hx with y hy;\n  rewrite mem_map; existsi y; cases hy with hy1 hy2;\n  apply and.intro _ hy2,\n  apply mem_union_left hy1, \n  apply mem_union_right _ hy1\nend\n\nlemma map_subset_map_of_subset \n  {f : \u03b1 \u2192 \u03b2} {as1 as2 : list \u03b1} :\n  (as1 \u2286 as2) \u2192 (map f as1 \u2286 map f as2) :=\nbegin\n  intros hss b hb,\n  rewrite mem_map at *, cases hb with a ha,\n  cases ha with ha1 ha2, subst ha2, \n  existsi a, apply and.intro _ rfl,\n  apply hss ha1\nend \n\nlemma map_equiv_map_of_equiv \n  {f : \u03b1 \u2192 \u03b2} {as1 as2 : list \u03b1} :\n  (as1 \u2243 as2) \u2192 (map f as1 \u2243 map f as2) :=\nbegin\n  intro heqv, cases heqv with hss1 hss2,\n  apply and.intro; \n  apply map_subset_map_of_subset; assumption\nend \n\nlemma union_subset_union_of_subset [decidable_eq \u03b1]\n  {as1 as1' as2 : list \u03b1} : (as1 \u2286 as1') \u2192 (as1 \u222a as2 \u2286 as1' \u222a as2) :=\nbegin\n  intros h a ha, rewrite mem_union at ha,\n  cases ha with ha ha, \n  apply mem_union_left, apply h ha,\n  apply mem_union_right, apply ha\nend\n\nlemma union_equiv_union_of_equiv [decidable_eq \u03b1]\n  {as1 as1' as2 : list \u03b1} : (as1 \u2243 as1') \u2192 (as1 \u222a as2 \u2243 as1' \u222a as2) :=\nbegin\n  intro h, cases h with h1 h2,\n  apply and.intro; \n  apply union_subset_union_of_subset; assumption\nend\n\nlemma union_comm [decidable_eq \u03b1]\n {as1 as2 : list \u03b1} : (as1 \u222a as2 \u2243 as2 \u222a as1) :=\nbegin\n  apply and.intro; intros a ha;\n  rewrite mem_union at ha; cases ha with ha ha;\n  {apply mem_union_left ha <|> apply mem_union_right _ ha}\nend\n\nlemma filter_union [decidable_eq \u03b1]\n  {P : \u03b1 \u2192 Prop} [decidable_pred P]\n  {as1 as2 : list \u03b1} :\n  filter P (as1 \u222a as2) \u2243 (filter P as1 \u222a filter P as2) :=\nbegin\n  apply and.intro; intros a ha;\n  rewrite mem_union at *; repeat {rewrite mem_filter at *};\n  cases ha with ha1 ha2, rewrite mem_union at ha1,\n  cases ha1 with hm hm, apply or.inl, \n  apply and.intro; assumption, apply or.inr, \n  apply and.intro; assumption,\n  cases ha1 with hm hP,\n  apply and.intro _ hP, apply mem_union_left hm,\n  cases ha2 with hm hP,\n  apply and.intro _ hP, apply mem_union_right _ hm\nend\n\n\n\ndef anyp (P : \u03b1 \u2192 Prop) (l : list \u03b1) := \u2203 a, a \u2208 l \u2227 P a\n\nlemma cases_pluck (P : \u03b1 \u2192 Prop) [hd : decidable_pred P] : \u2200 (as : list \u03b1), \n(pluck P as = none \u2227 (\u2200 x \u2208 as, \u00ac P x)) \n\u2228 \u2203 (a) (as'), (pluck P as = some (a,as') \u2227 P a \u2227 (as \u2243 (a::as')))\n| [] := \n  begin \n    apply or.inl, apply and.intro, \n    unfold pluck, intros _ H, cases H\n  end\n| (a::as) :=\n  begin\n    cases (hd a) with ha ha, \n    cases (cases_pluck as) with has has,\n\n    apply or.inl, cases has with has1 has2,\n    apply and.intro, rewrite pluck_false,\n    rewrite has1, refl, apply ha,\n    rewrite forall_mem_cons,\n    apply and.intro ha has2,\n\n    apply or.inr, cases has with a' has,\n    cases has with as' has',\n    cases has' with h1 has', cases has' with h2 h3,\n    existsi a', existsi (a::as'),\n    apply and.intro, rewrite pluck_false, \n    rewrite h1, refl, apply ha, apply and.intro h2,\n    apply equiv.trans, apply cons_equiv_cons, \n    apply h3, apply equiv.swap,\n    \n    apply or.inr, existsi a, existsi as,\n    apply and.intro, rewrite pluck_true, apply ha,\n    apply and.intro ha equiv.refl\n  end\n\n\n\n@[simp] def nth_dft (a : \u03b1) (l : list \u03b1) (n : nat) : \u03b1 :=  \nmatch nth l n with \n| none := a \n| (some a') := a'\nend\n\ndef head_dft (a' : \u03b1) : list \u03b1 \u2192 \u03b1 \n| [] := a'\n| (a::as) := a \n\nlemma nth_pred (a : \u03b1) (l : list \u03b1) (n : nat) (H : n > 0) : \nnth (a::l) n = nth l (n - 1) := \nbegin cases n, cases H, simp end\n\nlemma nth_dft_pred {a a' : \u03b1} {l : list \u03b1} {n : nat} (H : n > 0) : \nnth_dft a (a'::l) n = nth_dft a l (n - 1) :=\nbegin unfold nth_dft, rewrite nth_pred, apply H  end\n\nlemma nth_dft_succ {a a' : \u03b1} {l : list \u03b1} {n : nat} : \nnth_dft a (a'::l) (n+1) = nth_dft a l n :=\nbegin unfold nth_dft, simp  end\n\nlemma nth_dft_head {a a' : \u03b1} {as : list \u03b1} : nth_dft a' (a::as) 0 = a := \nbegin unfold nth_dft, simp end\n\n@[simp] def append_pair {\u03b1 : Type} : (list \u03b1 \u00d7 list \u03b1) \u2192 list \u03b1  \n| (l1,l2) := l1 ++ l2 \n\ndef all_true (ps : list Prop) : Prop := \u2200 (p : Prop), p \u2208 ps \u2192 p\n\nlemma all_true_nil : all_true [] := \nby {intros _ H, cases H}\n\n-- def disj_list : list Prop \u2192 Prop \n-- | [] := false\n-- | (p::ps) := p \u2228 disj_list ps\n\ndef some_true (ps : list Prop) : Prop := \u2203 (p : Prop), p \u2208 ps \u2227 p\n\nlemma some_true_nil : some_true [] \u2194 false :=\nbegin\n  apply iff.intro; intro h, cases h with p hp,\n  cases hp^.elim_left, cases h\nend\n\nlemma some_true_cons (p ps) : some_true (p::ps) \u2194 (p \u2228 some_true ps) :=\nbegin\n  apply iff.intro; intro h, cases h with q hq,\n  cases hq with hq1 hq2, rewrite mem_cons_iff at hq1,\n  cases hq1 with hq1 hq1, subst hq1, apply or.inl hq2,\n  apply or.inr, existsi q, apply and.intro hq1 hq2,\n  cases h with h h, existsi p, simp, apply h,\n  cases h with q hq, cases hq with hq1 hq2,\n  existsi q, apply and.intro (or.inr hq1) hq2\nend\n\nlemma some_true_append {ps1 ps2} : some_true (ps1 ++ ps2) \u2194 (some_true ps1 \u2228 some_true ps2) := \nbegin\n  apply iff.intro; intro h, cases h with p hp,\n  cases hp with hp1 hp2, rewrite mem_append at hp1,\n  cases hp1 with hp1 hp1, \n  apply or.inl, existsi p, apply and.intro; assumption, \n  apply or.inr, existsi p, apply and.intro; assumption, \n  cases h with h h; cases h with p hp; cases hp with hp1 hp2;\n  existsi p; apply and.intro, \n  apply mem_append_left, apply hp1, apply hp2,\n  apply mem_append_right, apply hp1, apply hp2\nend\n\nlemma forall_mem_append {P : \u03b1 \u2192 Prop} {as1 as2 : list \u03b1} : \n  (\u2200 a \u2208 (as1 ++ as2), P a) \u2194 ((\u2200 a \u2208 as1, P a) \u2227 (\u2200 a \u2208 as2, P a)) := \nbegin\n  apply iff.intro; intro h, \n  apply and.intro; intros a ha; apply h,\n  apply mem_append_left _ ha,\n  apply mem_append_right _ ha,\n  intros a ha, rewrite mem_append at ha,\n  cases h with hl hr, cases ha with ha ha,\n  apply hl _ ha, apply hr _ ha\nend\n/-\nlemma some_true_iff_disj_list : \n  \u2200 {ps : list Prop}, some_true ps \u2194 disj_list ps \n| [] :=\n  begin \n    unfold some_true, unfold disj_list, \n    apply iff.intro; intro h, cases h with x hx,\n    cases hx^.elim_left, exfalso, apply h\n  end\n| (p::ps) := \n  begin\n    unfold some_true, unfold disj_list, \n    apply iff.intro; intro h, cases h with x hx,\n    cases hx with hx1 hx2, rewrite mem_cons_iff at hx1,\n    cases hx1 with hx1 hx1, subst hx1, apply or.inl hx2, \n    rewrite iff.symm some_true_iff_disj_list,\n    apply or.inr, existsi x, apply and.intro hx1 hx2,\n    cases h with h h, existsi p, \n    apply and.intro (or.inl rfl) h, \n    rewrite iff.symm some_true_iff_disj_list at h,\n    cases h with x hx, existsi x, cases hx with hx1 hx2,\n    apply and.intro (or.inr hx1) hx2 \n  end\n\nlemma disj_list_iff_some_true : \u2200 (ps : list Prop), disj_list ps \u2194 some_true ps \n| [] := \n  begin\n    apply iff.intro, intro H, cases H, \n    intro H, cases H with H1 H2, cases (H2^.elim_left) \n  end\n| (p::ps) :=\n  begin\n    apply iff.intro, intro H, cases H with H H, \n    existsi p, apply and.intro, \n    apply or.inl (eq.refl _), apply H, \n    cases ((disj_list_iff_some_true ps)^.elim_left H) with p Hp,\n    existsi p, apply and.intro, \n    apply or.inr (Hp^.elim_left),\n    apply Hp^.elim_right, \n    unfold some_true, unfold disj_list,\n    unfold has_mem.mem, unfold list.mem,\n    intro H, cases H with p' Hp', \n    cases (Hp'^.elim_left) with HM HM,\n    apply or.inl, rewrite (eq.symm HM), \n    apply Hp'^.elim_right, \n    apply or.inr, rewrite disj_list_iff_some_true,\n    existsi p', apply (and.intro HM Hp'^.elim_right)\n\n  end\n-/\n\n\n-- lemma disj_list_dist_append (l1 l2 : list Prop) : disj_list (l1 ++ l2) = (disj_list l1 \u2228 disj_list l2) :=  \n-- begin\n--   repeat {rewrite disj_list_iff_some_true}, \n--   apply propext, apply iff.intro,\n--   intro H, cases H with x Hx, \n--   cases Hx with Hl Hr, cases (mem_or_mem_of_mem_append Hl) with HM HM, \n--   apply or.inl, existsi x, apply and.intro HM Hr,\n--   apply or.inr, existsi x, apply and.intro HM Hr,\n--   intro H, cases H with H H; cases H with x Hx ; cases Hx with Hl Hr ; existsi x ; apply and.intro, \n--   apply mem_append_of_mem_or_mem, \n--   apply or.inl, apply Hl, apply Hr, \n--   apply mem_append_of_mem_or_mem, \n--   apply or.inr, apply Hl, apply Hr \n-- end\n\n\n-- def ex_arg_of_mem_map {f : \u03b1 \u2192 \u03b2} {b : \u03b2} : \n--   \u2200 {as : list \u03b1}, (b \u2208 list.map f as) \u2192 \u2203 a, a \u2208 as \u2227 b = f a \n-- | [] H := by cases H \n-- | (a::as) H := \n--   begin\n--     simp at H, cases H with H H, existsi a, \n--     apply and.intro (or.inl (eq.refl _)) H,  \n--     cases (list.exists_of_mem_map H) with a' Ha',\n--     existsi a', apply and.intro, \n--     apply or.inr (Ha'^.elim_left), \n--     apply Ha'^.elim_right\n--   end\n\n\nlemma fst_mem_of_mem_product : \n  \u2200 {as : list \u03b1} {bs : list \u03b2} {p : \u03b1 \u00d7 \u03b2}, \n    p \u2208 (product as bs) \u2192 (prod.fst p) \u2208 as  \n| [] bs b H := begin unfold product at H, cases H end\n| (a::as) bs ab h := \n  begin\n    unfold product at h, simp at h, cases h with h h,\n    \n    cases h with b hb, cases hb with hb1 hb2,\n    rewrite eq.symm hb2, apply or.inl rfl, \n\n    cases h with a' h, cases h with h1 h2, \n    cases h2 with b hb, cases hb with hb1 hb2, \n    rewrite eq.symm hb2, apply or.inr, apply h1\n  end\n\nlemma snd_mem_of_mem_product : \n  \u2200 {as : list \u03b1} {bs : list \u03b2} {p : \u03b1 \u00d7 \u03b2}, \n    p \u2208 (product as bs) \u2192 (prod.snd p) \u2208 bs \n| [] bs b H := begin unfold product at H, cases H end\n| (a::as) bs ab h := \n  begin\n    unfold product at h, simp at h, cases h with h h,\n    \n    cases h with b hb, cases hb with hb1 hb2,\n    rewrite eq.symm hb2, apply hb1, \n\n    cases h with a' h, cases h with h1 h2, \n    cases h2 with b hb, cases hb with hb1 hb2, \n    rewrite eq.symm hb2, apply hb1\n  end\n\n\nlemma forall_mem_map_of_forall_mem (P : \u03b1 \u2192 Prop) {Q : \u03b2 \u2192 Prop} {f : \u03b1 \u2192 \u03b2} {as} : \n(\u2200 a \u2208 as, P a) \u2192 (\u2200 a, P a \u2192 Q (f a)) \u2192 (\u2200 b \u2208 (map f as), Q b) := \nbegin\n  intros has hf b hb, \n  rewrite mem_map at hb, \n  cases hb with a ha, cases ha with ha1 ha2,\n  subst ha2, apply hf, apply has, apply ha1\nend\n\nlemma mem_product_of_mem_and_mem {as : list \u03b1} {bs : list \u03b2} \n  {a : \u03b1} {b : \u03b2} (h : a \u2208 as \u2227 b \u2208 bs) : (a,b) \u2208 product as bs := \nbegin rewrite mem_product, apply h end\n\n\nlemma map_eq (f g : \u03b1 \u2192 \u03b2) : \u2200 (as : list \u03b1) (H : \u2200 a \u2208 as, f a = g a), map f as = map g as \n| [] _ := eq.refl _\n| (a::as) H := \n  begin \n    unfold map, rewrite H, rewrite map_eq,\n    intros a Ha, apply (H _ (or.inr Ha)),  \n    apply (or.inl (eq.refl _))\n  end\n\nmeta def first_arg (f : \u03b1 \u2192 tactic \u03b2) : list \u03b1 \u2192 tactic \u03b2 \n| [] := tactic.failed \n| (a::as) := f a <|> (first_arg as)\n\nlemma forall_mem_filter_of_forall_mem {P Q : \u03b1 \u2192 Prop} [H : decidable_pred Q] \n  {as : list \u03b1} (h : \u2200 a \u2208 as, P a) : \u2200 a \u2208 (list.filter Q as), P a := \nbegin\n  intros a ha, apply h, \n  apply mem_of_mem_filter ha \nend\n\n@[simp] def allp (P : \u03b1 \u2192 Prop) (as : list \u03b1) := \u2200 a \u2208 as, P a\n\nlemma allp_iff_forall_mem (P : \u03b1 \u2192 Prop) (as : list \u03b1) :\n  (allp P as) \u2194 (\u2200 a \u2208 as, P a) :=\nby unfold allp\n\nlemma map_one_mul [monoid \u03b1] : \n  \u2200 (l : list \u03b1), map (has_mul.mul (1 : \u03b1)) l = l \n| [] := refl _\n| (a::as) := begin simp, apply map_one_mul end\n\nend list", "meta": {"author": "avigad", "repo": "qelim", "sha": "b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60", "save_path": "github-repos/lean/avigad-qelim", "path": "github-repos/lean/avigad-qelim/qelim-b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60/common/list.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7093914470209927}}
{"text": "import .prop_logic \nimport .bool_sat\n\nopen prop_logic \nopen prop_logic.var\nopen prop_logic.pExp\n\n\n/-\nAn example: The 0th, 1st, and \n2nd bits from the right in 100, \nthe binary numeral for decimal\n4, are 0, 0, and 1, respectively.\n-/\n#eval mth_bit_from_right_in_n 2 4\n\n/-\n#1. Write and evaluate expressions\n(using eval) to determine what is \nthe bit in the 9th position from\nthe right in the binary expansion\nof the decimal number 8485672345? \n\nHint: don't use reduce here. Eval\nuses hardware (machine) int values\nto represent nats, while reduce \nuses the unary nat representation. \n\nSelf-test: How much memory might \nit take to represent the decimal\nnumber, 8485672345, as a \u2115 value\nin unary? -- come back here\n-/\n\n#eval mth_bit_from_right_in_n 9 8485672345\n\n\n/-\nThe next section presents examples\nto set up test cases for definitions\nto follow.\n-/\n\n/-\nWe define a few variables to use\nin the rest of this assignment.\n-/\ndef P : pExp:= varExp (mkVar 0)\ndef Q: pExp := varExp (mkVar 1)\ndef R : pExp := varExp (mkVar 2)\n\n/-\nWe set parameter values used in\nsome function definitions to follow.\n-/\ndef max_var_index := 2\ndef num_vars := max_var_index + 1\n\n/-\nAn example of a propositional logic\nexpression.\n-/\ndef theExpr : pExp := (pImpl P (P \u2227 R))\n\n\n/-\nAn example using the truth_table_results\nfunction to compute and return a list of \nthe truth values of theExpr under each of \nits possible interpretations.\n-/\n#eval truth_table_results theExpr num_vars\n\n\n/-\n#2. Define interp5 to be the interpretation\nin the six row (m=5) of the truth table that\nour interps_for_n_vars functions returns for\nour three variables (P, Q, and R). \n\nHint: use the mth_interp_n_vars function.\nDefinitely check out the definition of the\nfunction, and any specification text, even \nif informal, given with the formal definition.\n-/\n#eval interps_for_n_vars 3\n#eval truth_table_results P\ndef interp5 := mth_interp_n_vars 5 3 \n\n/-\n#3. What Boolean values are assigned to \nP, Q, and R by this interpretation (interp5)? \nUse three #eval commands to compute answers by \nevaluating each variable expressions under the\ninterp5 interpretation.\n-/\n\n#eval interp5 (mkVar 0) -- P\n#eval interp5 (mkVar 1) -- Q\n#eval interp5 (mkVar 2) -- R\n\n\n\n/-\n#4. Write a truth table within this\ncomment block showing the values for\nP, Q, and R, in each row in the truth\ntable, represented by a corresponding\nvalue in the list of interpretations\nreturned by interps_for_n_vars. Label\nyour columns as R, Q, and P, in that\norder. (Try to understand why.) \nHint: Don't just write what you think\nthe answers are:, evaluate each of\nthe three variable expression under\neach interpretation. You can use the\nmth_interp_n_vars function if you want\nto obtain interpretation functions for\neach of the rows individually if you\nwant. \n\n\nAnswer: \n    R   |   Q   |   P  \n  ----------------------\n    F       F       F      \n    F       F       T      \n    F       T       F      \n    F       T       T      \n    T       F       F      \n    T       F       T      \n    T       T       F      \n    T       T       T      \n-/\n\n\n/-\n#5. Write an expression here to\ncompute the \"results\" column of\nthe truth table for \"theExpr\" as\ndefined above.\n-/\n\n#eval truth_table_results theExpr\n\n/-\n#6. Copy and paste the truth table\nfrom question #4 here and extend it\nwith the results you just obtained.\nCheck the results for correctness.\n\nAnswer here:\n\n    R   |   Q   |   P   | TheExpr\n  --------------------------------\n    F       F       F       T\n    F       F       T       T\n    F       T       F       T\n    F       T       T       T\n    T       F       F       F\n    T       F       T       T\n    T       T       F       F\n    T       T       T       T\n\n\n-/\n\n/-\n#7.\n\nWrite a \"predicate\" function, isModel,\nthat takes a propositional logic \nexpression, e, and an interpretation, \ni, as its arguments and that returns \nthe Boolean true (tt) value if and only\nif i is a model of e (otherwise false).\n-/\n\ndef isModel :pExp \u2192 (var \u2192 bool) \u2192 bool\n| pExp f := if \u2200 (b : truth_table_results pExp f) then tt else ff\n\n\n/-\n#8. Write a one-line implementation\nof a function, is_valid, that takes as\nits arguments a propositional expression, \ne, and the number of variables, n, in its\ntruth table, and that returns true if and\nonly if it is valid, construed to mean\ntha every result in the list returned by \nthe truth_table_results function is true.\n\nTo do so, define and use a fold function\nto reduce returned lists of Boolean truth\nvalues to single truth values. Define and\nuse a bool-specific function, fold_bool :\n    (bool \u2192 bool \u2192 bool) - binary operator\n     \u2192 \n    bool - identity element for that operator \n    \u2192 \n    (list bool) - list to be reduced\n    \n     \u2192 \n    bool,\nwhere the arguments are, respectively, \na binary operator, an identity element\nfor that operator, and a list of bools\nto be reduced to a single bool result. \n-/\n\ndef fold_bool :\n    (bool \u2192 bool \u2192 bool) \u2192 bool \u2192 (list bool) \u2192 bool\n| func id [] := id\n| func id (list.cons (h) (t)) :=  func h ( fold_bool func id t )\n \n#eval fold_bool band tt [tt,ff,tt]\n\ndef is_valid : pExp \u2192 \u2115 \u2192 bool\n|pExp num_vars := fold_bool band tt (truth_table_results pExp num_vars) \n\n/-\nWrite similar one-line implementations of the\nfunctions, is_satisfiable and is_unsatisfiable, \nrespectively. Do not use fold (directly) in your \nimplementation of is_unsatisfiable.\n-/\n\ndef is_satisfiable : pExp \u2192 \u2115 \u2192 bool\n|pExp num_vars := if fold_bool bor ff (truth_table_results pExp num_vars) \n  then tt\n  else ff \n\n\ndef is_unsatisfiable : pExp \u2192 \u2115 \u2192 bool\n|pExp num_vars := if fold_bool bor ff (truth_table_results pExp num_vars) \n  then ff\n  else tt\n\n/-\n9. Use your is_valid function to determine which\nof the following putative valid laws of reasoning\nreally are valid, and which ones are not. For each\none that is not, give a real-world scenario that\nshows that the rule doesn't always lead to a valid\ndeduction. Use #eval to evaluate the validity of \neach proposition. Use -- to put a comment after\neach of the following definitions indicating\neither \"-- valid\" or \"-- NOT valid\".\n-/\n\ndef true_intro : pExp := pTrue -- valid\n#eval is_valid true_intro 3\ndef false_elim := pImpl pFalse P -- valid\n#eval is_valid false_elim 3\ndef and_intro := pImpl P (pImpl Q (P \u2227 Q)) -- valid\n#eval is_valid and_intro 3   \ndef and_elim_left := pImpl (P \u2227 Q) P  -- valid\n#eval is_valid and_elim_left 3 \ndef and_elim_right := pImpl (P \u2227 Q) Q  \n#eval is_valid and_elim_right 3\ndef or_intro_left := pImpl P (P \u2228 Q)\ndef or_intro_right := pImpl Q (P \u2228 Q)\ndef or_elim := pImpl ( P \u2228 Q) (pImpl (pImpl P R)  (pImpl (pImpl Q R)  R))\ndef iff_intro := pImpl (pImpl P Q) (pImpl(pImpl Q  P) (P \u2194 Q))\ndef iff_elim_left := pImpl (P \u2194 Q) (pImpl P Q)\ndef iff_elim_right := pImpl (P \u2194 Q) (pImpl Q  P)\ndef arrow_elim := (pImpl P  Q) ( pImpl ( pImpl P  Q))\ndef affirm_consequence := (P \u21d2 Q) \u21d2 Q \u21d2 P\ndef resolution := (P \u2228 Q) \u21d2 (\u00ac Q \u2228 R) \u21d2 (P \u2228 R)\ndef unit_resolution := (P \u2228 Q) \u21d2 (\u00ac Q) \u21d2 P\ndef syllogism := (P \u21d2 Q) \u21d2 (Q \u21d2 R) \u21d2 (P \u21d2 R)\ndef modus_tollens := (P \u21d2 Q) \u21d2 \u00ac Q \u21d2 \u00ac P\ndef neg_elim := \u00ac \u00ac P \u21d2 P\ndef excluded_middle := P \u2228 \u00ac P\ndef neg_intro := (P \u21d2 pFalse) \u21d2 \u00ac P\ndef affirm_disjunct := (P \u2228 Q) \u21d2 P \u21d2 \u00ac Q\ndef deny_antecedent := (P \u21d2 Q) \u21d2 (\u00ac P \u21d2 \u00ac Q)\n\n-- Answer below\n", "meta": {"author": "avonstar21", "repo": "CS-2102", "sha": "2b99b40c9fe8c532afee5d334d87f6265a36bfec", "save_path": "github-repos/lean/avonstar21-CS-2102", "path": "github-repos/lean/avonstar21-CS-2102/CS-2102-2b99b40c9fe8c532afee5d334d87f6265a36bfec/My Work/Homeworks/hw7_sat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.7093914460626322}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport order.filter.at_top_bot\nimport algebra.archimedean\n\n/-!\n# `at_top` filter and archimedean (semi)rings/fields\n\nIn this file we prove that for a linear ordered archimedean semiring `R` and a function `f : \u03b1 \u2192 \u2115`,\nthe function `coe \u2218 f : \u03b1 \u2192 R` tends to `at_top` along a filter `l` if and only if so does `f`.\nWe also prove that `coe : \u2115 \u2192 R` tends to `at_top` along `at_top`, as well as version of these\ntwo results for `\u2124` (and a ring `R`) and `\u211a` (and a field `R`).\n-/\n\nvariables {\u03b1 R : Type*}\n\nopen filter\n\nlemma tendsto_coe_nat_at_top_iff [ordered_semiring R] [nontrivial R] [archimedean R]\n  {f : \u03b1 \u2192 \u2115} {l : filter \u03b1} :\n  tendsto (\u03bb n, (f n : R)) l at_top \u2194 tendsto f l at_top :=\ntendsto_at_top_embedding (assume a\u2081 a\u2082, nat.cast_le) exists_nat_ge\n\nlemma tendsto_coe_nat_at_top_at_top [ordered_semiring R] [archimedean R] :\n  tendsto (coe : \u2115 \u2192 R) at_top at_top :=\nnat.mono_cast.tendsto_at_top_at_top exists_nat_ge\n\nlemma tendsto_coe_int_at_top_iff [ordered_ring R] [nontrivial R] [archimedean R]\n  {f : \u03b1 \u2192 \u2124} {l : filter \u03b1} :\n  tendsto (\u03bb n, (f n : R)) l at_top \u2194 tendsto f l at_top :=\ntendsto_at_top_embedding (assume a\u2081 a\u2082, int.cast_le) $\n  assume r, let \u27e8n, hn\u27e9 := exists_nat_ge r in \u27e8(n:\u2124), hn\u27e9\n\nlemma tendsto_coe_int_at_top_at_top [ordered_ring R] [archimedean R] :\n  tendsto (coe : \u2124 \u2192 R) at_top at_top :=\nint.cast_mono.tendsto_at_top_at_top $ \u03bb b,\n  let \u27e8n, hn\u27e9 := exists_nat_ge b in \u27e8n, hn\u27e9\n\nlemma tendsto_coe_rat_at_top_iff [linear_ordered_field R] [archimedean R]\n  {f : \u03b1 \u2192 \u211a} {l : filter \u03b1} :\n  tendsto (\u03bb n, (f n : R)) l at_top \u2194 tendsto f l at_top :=\ntendsto_at_top_embedding (assume a\u2081 a\u2082, rat.cast_le) $\n  assume r, let \u27e8n, hn\u27e9 := exists_nat_ge r in \u27e8(n:\u211a), by assumption_mod_cast\u27e9\n\nvariables [linear_ordered_semiring R] [archimedean R]\nvariables {l : filter \u03b1} {f : \u03b1 \u2192 R} {r : R}\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the left) also tends to infinity. The archimedean assumption is convenient to get a\nstatement that works on `\u2115`, `\u2124` and `\u211d`, although not necessary (a version in ordered fields is\ngiven in `filter.tendsto.const_mul_at_top`). -/\nlemma filter.tendsto.const_mul_at_top' (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, r * f x) l at_top :=\nbegin\n  apply tendsto_at_top.2 (\u03bbb, _),\n  obtain \u27e8n : \u2115, hn : 1 \u2264 n \u2022 r\u27e9 := archimedean.arch 1 hr,\n  rw nsmul_eq_mul' at hn,\n  filter_upwards [tendsto_at_top.1 hf (n * max b 0)],\n  assume x hx,\n  calc b \u2264 1 * max b 0 : by { rw [one_mul], exact le_max_left _ _ }\n  ... \u2264 (r * n) * max b 0 : mul_le_mul_of_nonneg_right hn (le_max_right _ _)\n  ... = r * (n * max b 0) : by rw [mul_assoc]\n  ... \u2264 r * f x : mul_le_mul_of_nonneg_left hx (le_of_lt hr)\nend\n\n/-- If a function tends to infinity along a filter, then this function multiplied by a positive\nconstant (on the right) also tends to infinity. The archimedean assumption is convenient to get a\nstatement that works on `\u2115`, `\u2124` and `\u211d`, although not necessary (a version in ordered fields is\ngiven in `filter.tendsto.at_top_mul_const`). -/\nlemma filter.tendsto.at_top_mul_const' (hr : 0 < r) (hf : tendsto f l at_top) :\n  tendsto (\u03bbx, f x * r) l at_top :=\nbegin\n  apply tendsto_at_top.2 (\u03bbb, _),\n  obtain \u27e8n : \u2115, hn : 1 \u2264 n \u2022 r\u27e9 := archimedean.arch 1 hr,\n  have hn' : 1 \u2264 (n : R) * r, by rwa nsmul_eq_mul at hn,\n  filter_upwards [tendsto_at_top.1 hf (max b 0 * n)],\n  assume x hx,\n  calc b \u2264 max b 0 * 1 : by { rw [mul_one], exact le_max_left _ _ }\n  ... \u2264 max b 0 * (n * r) : mul_le_mul_of_nonneg_left hn' (le_max_right _ _)\n  ... = (max b 0 * n) * r : by rw [mul_assoc]\n  ... \u2264 f x * r : mul_le_mul_of_nonneg_right hx (le_of_lt hr)\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/filter/archimedean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.7093914432132652}}
{"text": "import algebra.big_operators.intervals\nimport algebra.big_operators.ring\nimport data.nat.prime\nimport algebra.associated\nimport data.int.basic\nimport tactic.ring\n\n/-\nHungarian Mathematical Olympiad 1998, Problem 6\n\nLet x, y, z be integers with z > 1. Show that\n\n (x + 1)\u00b2 + (x + 2)\u00b2 + ... + (x + 99)\u00b2 \u2260 y\u1dbb.\n-/\n\nopen_locale big_operators\n\nlemma sum_range_square_mul_six (n : \u2115) :\n  (\u2211(i:\u2115) in finset.range n, (i+1)^2) * 6 = n * (n + 1) * (2*n + 1) :=\nbegin\n  induction n with n ih,\n  { refl },\n  { have h : n.succ = n + 1 := rfl,\n    rw[finset.sum_range_succ, add_mul, ih, h],\n    ring,}\nend\n\nlemma sum_range_square (n : \u2115) :\n  \u2211(i:\u2115) in finset.range n, (i+1)^2 = n * (n + 1) * (2*n + 1)/6 :=\nbegin\n  by rw [\u2190 sum_range_square_mul_six n, nat.mul_div_cancel]; exact dec_trivial\nend\n\nlemma cast_sum_square (n : \u2115) :\n  \u2211(i:\u2115) in finset.range n, ((i:\u2124)+1)^2 =\n   (((\u2211(i:\u2115) in finset.range n, (i+1)^2):\u2115) :\u2124) :=\nbegin\n norm_cast\nend\n\ntheorem hungary1998_q6 (x y : \u2124) (z : \u2115) (hz : 1 < z) :\n    \u2211(i : \u2115) in finset.range 99, (x + i + 1)^2 \u2260 y^z :=\nbegin\n  -- Suppose (x + 1)\u00b2 + (x + 2)\u00b2 + ... + (x + 99)\u00b2 = y\u1dbb.\n\n  intro he,\n\n  -- We notice that\n  -- y^z = (x + 1)\u00b2 + (x + 2)\u00b2 + ... + (x + 99)\u00b2\n  --     = 99x\u00b2 + 2(1 + 2 + ... + 99)x + (1\u00b2 + 2\u00b2 + ... + 99\u00b2)\n  --     = 99x\u00b2 + 2[(99 \u2b1d 100)/2]x + (99 \u2b1d 100 \u2b1d 199)/6\n  --     = 33(3x\u00b2 + 300x + 50 \u2b1d 199).\n\n  have h2 : \u2211(i : \u2115) in finset.range 99, (x^2) = 99 * x^2 := by norm_num,\n\n  have h3 : \u2211(i : \u2115) in finset.range 99, (2 * x * (i + 1)) =\n         2 * x * \u2211(i : \u2115) in finset.range 99, (i + 1) := finset.mul_sum.symm,\n\n  have h4 : \u2211(i : \u2115) in finset.range 99, ((i:\u2124) + 1) =\n          \u2211(i : \u2115) in finset.range 100, (i:\u2124) := by\n  { rw[@finset.sum_range_succ' _ _ _ 99], refl},\n\n  have h5 : \u2211(i : \u2115) in finset.range 100, (i:\u2124) = 99 * 100 / 2,\n  { rw[\u2190 nat.cast_sum, finset.sum_range_id], norm_num},\n\n  have h6 : \u2211(i : \u2115) in finset.range 99, ((i:\u2124) + 1)^2 = (99 * 100 * 199)/6,\n  { rw[cast_sum_square, sum_range_square], norm_num },\n\n  have h7 := calc y^z\n      = \u2211(i : \u2115) in finset.range 99, ((x + i) + 1)^2 : he.symm\n  ... = \u2211(i : \u2115) in finset.range 99,\n          (x^2 + 2 * x * (i + 1) + (i + 1)^2) : by {congr, funext, ring}\n  ... = \u2211(i : \u2115) in finset.range 99, (x^2 + 2 * x * (i + 1)) +\n         \u2211(i : \u2115) in finset.range 99, ((i + 1)^2) : finset.sum_add_distrib\n  ... = \u2211(i : \u2115) in finset.range 99, (x^2) +\n          \u2211(i : \u2115) in finset.range 99, (2 * x * (i + 1)) +\n         \u2211(i : \u2115) in finset.range 99, ((i + 1)^2) : by rw[finset.sum_add_distrib]\n  ... = 99 * x^2 + 2 * x * (99 * 100 / 2) +  (99 * 100 * 199)/6\n        : by rw[h2, h3, h4, h5, h6]\n  ... = 3 * (11 * (3 * x^2 + 300 * x + 50 * 199)) : by {norm_num, ring},\n\n  -- which implies that 3\u2223y.\n  have h8 : 3 \u2223 y^z := dvd.intro _ (eq.symm h7),\n  have h9 : 3 \u2223 y := prime.dvd_of_dvd_pow int.prime_three h8,\n\n  obtain \u27e8k,hk\u27e9 := h9,\n  rw[hk] at h7,\n  cases z, { exact nat.not_lt_zero 1 hz },\n  cases z, { exact nat.lt_asymm hz hz },\n  rw[pow_succ,pow_succ] at h7,\n\n  -- Since z \u2265 2, 3\u00b2\u2223y\u1dbb, but 3\u00b2 does not divide\n  -- 33(3x\u00b2 + 300x + 50 \u2b1d 199), contradiction.\n\n  have h10 : 3 * k * (3 * k * (3 * k) ^ z) = 3 * (k * (3 * k * (3 * k) ^ z))\n       := by ring,\n  rw[h10] at h7,\n\n  have h11 : (3:\u2124) \u2260 0 := by norm_num,\n\n  have h12 : k * (3 * k * (3 * k) ^ z) = (11 * (3 * x ^ 2 + 300 * x + 50 * 199)),\n  { exact (mul_right_inj' h11).mp h7 },\n\n  have h14 : (k * (3 * k * (3 * k) ^ z)) = (3 * (k * k * (3 * k) ^ z)) :=\n    by ring,\n  have h16 : 11 * (3 * x ^ 2 + 300 * x + 50 * 199) =\n    3 * (11 * (x ^ 2 + 100 * x + 3316) + 7) + 1 := by ring,\n\n  rw[h14,h16] at h12,\n\n  have h18 : (3 * (k * k * (3 * k) ^ z)) % 3 =\n    (3 * (11 * (x ^ 2 + 100 * x + 3316) + 7) + 1) % 3 :=\n    congr_fun (congr_arg has_mod.mod h12) 3,\n\n  have h19 : (3 * (11 * (x ^ 2 + 100 * x + 3316) + 7) + 1) % 3 =\n   (((3 * (11 * (x ^ 2 + 100 * x + 3316) + 7))% 3) + (1%3)) % 3 :=\n   int.add_mod _ _ _,\n  rw[h19] at h18,\n  norm_num at h18,\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/hungary1998_q6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7093646915907559}}
{"text": "/-\nCopyright (c) 2022 Chris Birkbeck. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Birkbeck, David Loeffler\n-/\n\nimport algebra.module.submodule.basic\nimport analysis.complex.upper_half_plane.basic\nimport order.filter.zero_and_bounded_at_filter\n\n/-!\n# Bounded at infinity\n\nFor complex valued functions on the upper half plane, this file defines the filter `at_im_infty`\nrequired for defining when functions are bounded at infinity and zero at infinity.\nBoth of which are relevant for defining modular forms.\n\n-/\n\nopen complex filter\n\nopen_locale topology upper_half_plane\n\nnoncomputable theory\n\nnamespace upper_half_plane\n\n/-- Filter for approaching `i\u221e`. -/\ndef at_im_infty := filter.at_top.comap upper_half_plane.im\n\nlemma at_im_infty_basis : (at_im_infty).has_basis (\u03bb _, true) (\u03bb (i : \u211d), im \u207b\u00b9' set.Ici i) :=\nfilter.has_basis.comap upper_half_plane.im filter.at_top_basis\n\nlemma at_im_infty_mem (S : set \u210d) : S \u2208 at_im_infty \u2194 (\u2203 A : \u211d, \u2200 z : \u210d, A \u2264 im z \u2192 z \u2208 S) :=\nbegin\n  simp only [at_im_infty, filter.mem_comap', filter.mem_at_top_sets, ge_iff_le, set.mem_set_of_eq,\n    upper_half_plane.coe_im],\n  refine \u27e8\u03bb \u27e8a, h\u27e9, \u27e8a, (\u03bb z hz, h (im z) hz rfl)\u27e9, _\u27e9,\n  rintro \u27e8A, h\u27e9,\n  refine \u27e8A, \u03bb b hb x hx, h x _\u27e9,\n  rwa hx,\nend\n\n/-- A function ` f : \u210d \u2192 \u03b1` is bounded at infinity if it is bounded along `at_im_infty`. -/\ndef is_bounded_at_im_infty {\u03b1 : Type*} [has_norm \u03b1] (f : \u210d \u2192 \u03b1) : Prop :=\nbounded_at_filter at_im_infty f\n\n/-- A function ` f : \u210d \u2192 \u03b1` is zero at infinity it is zero along `at_im_infty`. -/\ndef is_zero_at_im_infty {\u03b1 : Type*} [has_zero \u03b1] [topological_space \u03b1] (f : \u210d \u2192 \u03b1) : Prop :=\nzero_at_filter at_im_infty f\n\nlemma zero_form_is_bounded_at_im_infty {\u03b1 : Type*} [normed_field \u03b1] :\n  is_bounded_at_im_infty (0 : \u210d \u2192 \u03b1) := const_bounded_at_filter at_im_infty (0:\u03b1)\n\n/-- Module of functions that are zero at infinity. -/\ndef zero_at_im_infty_submodule (\u03b1 : Type*) [normed_field \u03b1] : submodule \u03b1 (\u210d \u2192 \u03b1) :=\nzero_at_filter_submodule at_im_infty\n\n/-- ubalgebra of functions that are bounded at infinity. -/\ndef bounded_at_im_infty_subalgebra (\u03b1 : Type*) [normed_field \u03b1] : subalgebra \u03b1 (\u210d \u2192 \u03b1) :=\nbounded_filter_subalgebra at_im_infty\n\nlemma is_bounded_at_im_infty.mul {f g : \u210d \u2192 \u2102} (hf : is_bounded_at_im_infty f)\n  (hg : is_bounded_at_im_infty g) : is_bounded_at_im_infty (f * g) :=\nby simpa only [pi.one_apply, mul_one, norm_eq_abs] using hf.mul hg\n\nlemma bounded_mem (f : \u210d \u2192 \u2102) :\n  is_bounded_at_im_infty f \u2194 \u2203 (M A : \u211d), \u2200 z : \u210d, A \u2264 im z \u2192 abs (f z) \u2264 M :=\nby simp [is_bounded_at_im_infty, bounded_at_filter, asymptotics.is_O_iff, filter.eventually,\n    at_im_infty_mem]\n\nlemma zero_at_im_infty (f : \u210d \u2192 \u2102) :\n  is_zero_at_im_infty f \u2194 \u2200 \u03b5 : \u211d, 0 < \u03b5 \u2192 \u2203 A : \u211d, \u2200 z : \u210d, A \u2264 im z \u2192 abs (f z) \u2264 \u03b5 :=\nbegin\n  rw [is_zero_at_im_infty, zero_at_filter, tendsto_iff_forall_eventually_mem],\n  split,\n  {  simp_rw [filter.eventually, at_im_infty_mem],\n    intros h \u03b5 h\u03b5,\n    simpa using (h (metric.closed_ball (0 : \u2102) \u03b5) (metric.closed_ball_mem_nhds (0 : \u2102) h\u03b5))},\n  { simp_rw metric.mem_nhds_iff,\n    intros h s hs,\n    simp_rw [filter.eventually, at_im_infty_mem],\n    obtain \u27e8\u03b5, h1, h2\u27e9 := hs,\n    have h11 : 0 < (\u03b5/2), by {linarith,},\n    obtain \u27e8A, hA\u27e9 := (h (\u03b5/2) h11),\n    use A,\n    intros z hz,\n    have hzs : f z \u2208 s,\n    { apply h2,\n      simp only [mem_ball_zero_iff, norm_eq_abs],\n      apply lt_of_le_of_lt (hA z hz),\n      linarith },\n    apply hzs,}\nend\n\nend upper_half_plane\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/complex/upper_half_plane/functions_bounded_at_infty.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7093646895463263}}
{"text": "theorem add_le_add_right {a b : mynat} : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) :=\nbegin\nintros h t,\ncases h with c hc,\nrw hc,\nuse c,\nrw add_right_comm,\nrefl,\nend", "meta": {"author": "nicholaspun", "repo": "natural-number-game-solutions", "sha": "1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0", "save_path": "github-repos/lean/nicholaspun-natural-number-game-solutions", "path": "github-repos/lean/nicholaspun-natural-number-game-solutions/natural-number-game-solutions-1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0/8-inequality-world/l11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533107374444, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7092712143441857}}
{"text": "/-\nConsideraciones:\n  - Este ejercicio se puede resolver usando unicamente las herramientas vistas en clase, como\n    intro, apply y by_contradiction.\n  - Recuerde apoyarse en Lean_Tactics, pdf disponible en el material de la clase 2, sumado a lo\n    visto en auxiliar y los ejemplos presentados en la Demo de Lean, clase 2.\nMucho exito!\n-/\n\nlemma Proof_1 (A B : Prop) : A \u2192 \u00ac (\u00ac A \u2227 B) :=\nbegin\n    -- Complete\nend\n\nlemma Proof_2 (A B : Prop) : (\u00ac A \u2227 \u00ac B) \u2192 \u00ac (A \u2228 B) :=\nbegin\n    -- Complete\nend\n\nlemma Proof_3 (A B C : Prop) : A \u2192 (B \u2228 C) \u2192 (A \u2227 B) \u2228 (A \u2227 C) :=\nbegin\n    -- Complete\nend", "meta": {"author": "ahevia", "repo": "CC3101_2021", "sha": "178392747409383f39e357b0dde919553d214aeb", "save_path": "github-repos/lean/ahevia-CC3101_2021", "path": "github-repos/lean/ahevia-CC3101_2021/CC3101_2021-178392747409383f39e357b0dde919553d214aeb/Ejercicios/Ejercicio1/Enunciado_Ejercicio_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361628580401, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7092365074275119}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro\n-/\n\nimport algebra.algebra.basic\nimport algebra.category.Ring.basic\nimport ring_theory.ideal.operations\n\n/-!\n\n# Local rings\n\nDefine local rings as commutative rings having a unique maximal ideal.\n\n## Main definitions\n\n* `local_ring`: A predicate on commutative semirings, stating that for any pair of elements that\n  adds up to `1`, one of them is a unit. This is shown to be equivalent to the condition that there\n  exists a unique maximal ideal.\n* `local_ring.maximal_ideal`: The unique maximal ideal for a local rings. Its carrier set is the\n  set of non units.\n* `is_local_ring_hom`: A predicate on semiring homomorphisms, requiring that it maps nonunits\n  to nonunits. For local rings, this means that the image of the unique maximal ideal is again\n  contained in the unique maximal ideal.\n* `local_ring.residue_field`: The quotient of a local ring by its maximal ideal.\n\n-/\n\nuniverses u v w u'\n\nvariables {R : Type u} {S : Type v} {T : Type w} {K : Type u'}\n\n/-- A semiring is local if it is nontrivial and `a` or `b` is a unit whenever `a + b = 1`.\nNote that `local_ring` is a predicate. -/\nclass local_ring (R : Type u) [semiring R] extends nontrivial R : Prop :=\nof_is_unit_or_is_unit_of_add_one ::\n(is_unit_or_is_unit_of_add_one {a b : R} (h : a + b = 1) : is_unit a \u2228 is_unit b)\n\nsection comm_semiring\nvariables [comm_semiring R]\n\nnamespace local_ring\n\nlemma of_is_unit_or_is_unit_of_is_unit_add [nontrivial R]\n  (h : \u2200 a b : R, is_unit (a + b) \u2192 is_unit a \u2228 is_unit b) :\n  local_ring R :=\n\u27e8\u03bb a b hab,  h a b $ hab.symm \u25b8 is_unit_one\u27e9\n\n/-- A semiring is local if it is nontrivial and the set of nonunits is closed under the addition. -/\nlemma of_nonunits_add [nontrivial R]\n  (h : \u2200 a b : R, a \u2208 nonunits R \u2192 b \u2208 nonunits R \u2192 a + b \u2208 nonunits R) :\n  local_ring R :=\n\u27e8\u03bb a b hab, or_iff_not_and_not.2 $ \u03bb H, h a b H.1 H.2 $ hab.symm \u25b8 is_unit_one\u27e9\n\n/-- A semiring is local if it has a unique maximal ideal. -/\nlemma of_unique_max_ideal (h : \u2203! I : ideal R, I.is_maximal) :\n  local_ring R :=\n@of_nonunits_add _ _ (nontrivial_of_ne (0 : R) 1 $\n  let \u27e8I, Imax, _\u27e9 := h in (\u03bb (H : 0 = 1), Imax.1.1 $ I.eq_top_iff_one.2 $ H \u25b8 I.zero_mem)) $\n  \u03bb x y hx hy H,\n    let \u27e8I, Imax, Iuniq\u27e9 := h in\n    let \u27e8Ix, Ixmax, Hx\u27e9 := exists_max_ideal_of_mem_nonunits hx in\n    let \u27e8Iy, Iymax, Hy\u27e9 := exists_max_ideal_of_mem_nonunits hy in\n    have xmemI : x \u2208 I, from Iuniq Ix Ixmax \u25b8 Hx,\n    have ymemI : y \u2208 I, from Iuniq Iy Iymax \u25b8 Hy,\n    Imax.1.1 $ I.eq_top_of_is_unit_mem (I.add_mem xmemI ymemI) H\n\nlemma of_unique_nonzero_prime (h : \u2203! P : ideal R, P \u2260 \u22a5 \u2227 ideal.is_prime P) :\n  local_ring R :=\nof_unique_max_ideal begin\n  rcases h with \u27e8P, \u27e8hPnonzero, hPnot_top, _\u27e9, hPunique\u27e9,\n  refine \u27e8P, \u27e8\u27e8hPnot_top, _\u27e9\u27e9, \u03bb M hM, hPunique _ \u27e8_, ideal.is_maximal.is_prime hM\u27e9\u27e9,\n  { refine ideal.maximal_of_no_maximal (\u03bb M hPM hM, ne_of_lt hPM _),\n    exact (hPunique _ \u27e8ne_bot_of_gt hPM, ideal.is_maximal.is_prime hM\u27e9).symm },\n  { rintro rfl,\n    exact hPnot_top (hM.1.2 P (bot_lt_iff_ne_bot.2 hPnonzero)) },\nend\n\nvariables [local_ring R]\n\nlemma is_unit_or_is_unit_of_is_unit_add {a b : R} (h : is_unit (a + b)) :\n  is_unit a \u2228 is_unit b :=\nbegin\n  rcases h with \u27e8u, hu\u27e9,\n  rw [\u2190units.inv_mul_eq_one, mul_add] at hu,\n  apply or.imp _ _ (is_unit_or_is_unit_of_add_one hu);\n    exact is_unit_of_mul_is_unit_right,\nend\n\nlemma nonunits_add {a b : R} (ha : a \u2208 nonunits R) (hb : b \u2208 nonunits R) : a + b \u2208 nonunits R:=\n\u03bb H, not_or ha hb (is_unit_or_is_unit_of_is_unit_add H)\n\nvariables (R)\n\n/-- The ideal of elements that are not units. -/\ndef maximal_ideal : ideal R :=\n{ carrier := nonunits R,\n  zero_mem' := zero_mem_nonunits.2 $ zero_ne_one,\n  add_mem' := \u03bb x y hx hy, nonunits_add hx hy,\n  smul_mem' := \u03bb a x, mul_mem_nonunits_right }\n\ninstance maximal_ideal.is_maximal : (maximal_ideal R).is_maximal :=\nbegin\n  rw ideal.is_maximal_iff,\n  split,\n  { intro h, apply h, exact is_unit_one },\n  { intros I x hI hx H,\n    erw not_not at hx,\n    rcases hx with \u27e8u,rfl\u27e9,\n    simpa using I.mul_mem_left \u2191u\u207b\u00b9 H }\nend\n\nlemma maximal_ideal_unique : \u2203! I : ideal R, I.is_maximal :=\n\u27e8maximal_ideal R, maximal_ideal.is_maximal R,\n  \u03bb I hI, hI.eq_of_le (maximal_ideal.is_maximal R).1.1 $\n  \u03bb x hx, hI.1.1 \u2218 I.eq_top_of_is_unit_mem hx\u27e9\n\nvariable {R}\n\nlemma eq_maximal_ideal {I : ideal R} (hI : I.is_maximal) : I = maximal_ideal R :=\nunique_of_exists_unique (maximal_ideal_unique R) hI $ maximal_ideal.is_maximal R\n\nlemma le_maximal_ideal {J : ideal R} (hJ : J \u2260 \u22a4) : J \u2264 maximal_ideal R :=\nbegin\n  rcases ideal.exists_le_maximal J hJ with \u27e8M, hM1, hM2\u27e9,\n  rwa \u2190eq_maximal_ideal hM1\nend\n\n@[simp] lemma mem_maximal_ideal (x) : x \u2208 maximal_ideal R \u2194 x \u2208 nonunits R := iff.rfl\n\nend local_ring\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nnamespace local_ring\n\nlemma of_is_unit_or_is_unit_one_sub_self [nontrivial R]\n  (h : \u2200 a : R, is_unit a \u2228 is_unit (1 - a)) : local_ring R :=\n\u27e8\u03bb a b hab, add_sub_cancel' a b \u25b8 hab.symm \u25b8 h a\u27e9\n\nvariables [local_ring R]\n\nlemma is_unit_or_is_unit_one_sub_self (a : R) : is_unit a \u2228 is_unit (1 - a) :=\nis_unit_or_is_unit_of_is_unit_add $ (add_sub_cancel'_right a 1).symm \u25b8 is_unit_one\n\nlemma is_unit_of_mem_nonunits_one_sub_self (a : R) (h : 1 - a \u2208 nonunits R) :\n  is_unit a :=\nor_iff_not_imp_right.1 (is_unit_or_is_unit_one_sub_self a) h\n\nlemma is_unit_one_sub_self_of_mem_nonunits (a : R) (h : a \u2208 nonunits R) :\n  is_unit (1 - a) :=\nor_iff_not_imp_left.1 (is_unit_or_is_unit_one_sub_self a) h\n\nlemma of_surjective' [comm_ring S] [nontrivial S] (f : R \u2192+* S) (hf : function.surjective f) :\n  local_ring S :=\nof_is_unit_or_is_unit_one_sub_self\nbegin\n  intros b,\n  obtain \u27e8a, rfl\u27e9 := hf b,\n  apply (is_unit_or_is_unit_one_sub_self a).imp f.is_unit_map _,\n  rw [\u2190 f.map_one, \u2190 f.map_sub],\n  apply f.is_unit_map,\nend\n\nend local_ring\n\nend comm_ring\n\n/-- A local ring homomorphism is a homomorphism `f` between local rings such that `a` in the domain\n  is a unit if `f a` is a unit for any `a`. See `local_ring.local_hom_tfae` for other equivalent\n  definitions. -/\nclass is_local_ring_hom [semiring R] [semiring S] (f : R \u2192+* S) : Prop :=\n(map_nonunit : \u2200 a, is_unit (f a) \u2192 is_unit a)\n\nsection\nvariables [semiring R] [semiring S] [semiring T]\n\ninstance is_local_ring_hom_id (R : Type*) [semiring R] : is_local_ring_hom (ring_hom.id R) :=\n{ map_nonunit := \u03bb a, id }\n\n@[simp] lemma is_unit_map_iff (f : R \u2192+* S) [is_local_ring_hom f] (a) :\n  is_unit (f a) \u2194 is_unit a :=\n\u27e8is_local_ring_hom.map_nonunit a, f.is_unit_map\u27e9\n\n@[simp] lemma map_mem_nonunits_iff (f : R \u2192+* S) [is_local_ring_hom f] (a) :\n  f a \u2208 nonunits S \u2194 a \u2208 nonunits R :=\n\u27e8\u03bb h ha, h $ (is_unit_map_iff f a).mpr ha, \u03bb h ha, h $ (is_unit_map_iff f a).mp ha\u27e9\n\ninstance is_local_ring_hom_comp\n  (g : S \u2192+* T) (f : R \u2192+* S) [is_local_ring_hom g] [is_local_ring_hom f] :\n  is_local_ring_hom (g.comp f) :=\n{ map_nonunit := \u03bb a, is_local_ring_hom.map_nonunit a \u2218 is_local_ring_hom.map_nonunit (f a) }\n\ninstance is_local_ring_hom_equiv (f : R \u2243+* S) :\n  is_local_ring_hom (f : R \u2192+* S) :=\n{ map_nonunit := \u03bb a ha,\n  begin\n    convert (f.symm : S \u2192+* R).is_unit_map ha,\n    exact (ring_equiv.symm_apply_apply f a).symm,\n  end }\n\n@[simp] lemma is_unit_of_map_unit (f : R \u2192+* S) [is_local_ring_hom f]\n  (a) (h : is_unit (f a)) : is_unit a :=\nis_local_ring_hom.map_nonunit a h\n\ntheorem of_irreducible_map (f : R \u2192+* S) [h : is_local_ring_hom f] {x}\n  (hfx : irreducible (f x)) : irreducible x :=\n\u27e8\u03bb h, hfx.not_unit $ is_unit.map f h, \u03bb p q hx, let \u27e8H\u27e9 := h in\nor.imp (H p) (H q) $ hfx.is_unit_or_is_unit $ f.map_mul p q \u25b8 congr_arg f hx\u27e9\n\nlemma is_local_ring_hom_of_comp (f : R \u2192+* S) (g : S \u2192+* T) [is_local_ring_hom (g.comp f)] :\n  is_local_ring_hom f :=\n\u27e8\u03bb a ha, (is_unit_map_iff (g.comp f) _).mp (g.is_unit_map ha)\u27e9\n\ninstance _root_.CommRing.is_local_ring_hom_comp {R S T : CommRing} (f : R \u27f6 S) (g : S \u27f6 T)\n  [is_local_ring_hom g] [is_local_ring_hom f] :\n  is_local_ring_hom (f \u226b g) := is_local_ring_hom_comp _ _\n\n/-- If `f : R \u2192+* S` is a local ring hom, then `R` is a local ring if `S` is. -/\nlemma _root_.ring_hom.domain_local_ring {R S : Type*} [comm_semiring R] [comm_semiring S]\n  [H : _root_.local_ring S] (f : R \u2192+* S)\n  [is_local_ring_hom f] : _root_.local_ring R :=\nbegin\n  haveI : nontrivial R := pullback_nonzero f f.map_zero f.map_one,\n  apply local_ring.of_nonunits_add,\n  intros a b,\n  simp_rw [\u2190map_mem_nonunits_iff f, f.map_add],\n  exact local_ring.nonunits_add\nend\n\nsection\nopen category_theory\n\nlemma is_local_ring_hom_of_iso {R S : CommRing} (f : R \u2245 S) : is_local_ring_hom f.hom :=\n{ map_nonunit := \u03bb a ha,\n  begin\n    convert f.inv.is_unit_map ha,\n    rw category_theory.iso.hom_inv_id_apply,\n  end }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_local_ring_hom_of_is_iso {R S : CommRing} (f : R \u27f6 S) [is_iso f] :\n  is_local_ring_hom f :=\nis_local_ring_hom_of_iso (as_iso f)\n\nend\n\nend\n\nsection\nopen local_ring\nvariables [comm_semiring R] [local_ring R] [comm_semiring S] [local_ring S]\n\n/--\nThe image of the maximal ideal of the source is contained within the maximal ideal of the target.\n-/\nlemma map_nonunit (f : R \u2192+* S) [is_local_ring_hom f] (a : R) (h : a \u2208 maximal_ideal R) :\n  f a \u2208 maximal_ideal S :=\n\u03bb H, h $ is_unit_of_map_unit f a H\n\nend\n\nnamespace local_ring\n\nsection\nvariables [comm_semiring R] [local_ring R] [comm_semiring S] [local_ring S]\n\n/--\nA ring homomorphism between local rings is a local ring hom iff it reflects units,\ni.e. any preimage of a unit is still a unit. https://stacks.math.columbia.edu/tag/07BJ\n-/\ntheorem local_hom_tfae (f : R \u2192+* S) :\n  tfae [is_local_ring_hom f,\n        f '' (maximal_ideal R).1 \u2286 maximal_ideal S,\n        (maximal_ideal R).map f \u2264 maximal_ideal S,\n        maximal_ideal R \u2264 (maximal_ideal S).comap f,\n        (maximal_ideal S).comap f = maximal_ideal R] :=\nbegin\n  tfae_have : 1 \u2192 2, rintros _ _ \u27e8a,ha,rfl\u27e9,\n    resetI, exact map_nonunit f a ha,\n  tfae_have : 2 \u2192 4, exact set.image_subset_iff.1,\n  tfae_have : 3 \u2194 4, exact ideal.map_le_iff_le_comap,\n  tfae_have : 4 \u2192 1, intro h, fsplit, exact \u03bb x, not_imp_not.1 (@h x),\n  tfae_have : 1 \u2192 5, intro, resetI, ext,\n    exact not_iff_not.2 (is_unit_map_iff f x),\n  tfae_have : 5 \u2192 4, exact \u03bb h, le_of_eq h.symm,\n  tfae_finish,\nend\n\nend\n\nlemma of_surjective [comm_semiring R] [local_ring R] [comm_semiring S] [nontrivial S]\n  (f : R \u2192+* S) [is_local_ring_hom f] (hf : function.surjective f) :\n  local_ring S :=\nof_is_unit_or_is_unit_of_is_unit_add\nbegin\n  intros a b hab,\n  obtain \u27e8a, rfl\u27e9 := hf a,\n  obtain \u27e8b, rfl\u27e9 := hf b,\n  rw \u2190map_add at hab,\n  exact (is_unit_or_is_unit_of_is_unit_add $ is_local_ring_hom.map_nonunit _ hab).imp\n    f.is_unit_map f.is_unit_map\nend\n\nsection\nvariables (R) [comm_ring R] [local_ring R] [comm_ring S] [local_ring S]\n\n/-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/\ndef residue_field := R \u29f8 maximal_ideal R\n\nnoncomputable instance residue_field.field : field (residue_field R) :=\nideal.quotient.field (maximal_ideal R)\n\nnoncomputable instance : inhabited (residue_field R) := \u27e837\u27e9\n\n/-- The quotient map from a local ring to its residue field. -/\ndef residue : R \u2192+* (residue_field R) :=\nideal.quotient.mk _\n\nnoncomputable\ninstance residue_field.algebra : algebra R (residue_field R) := (residue R).to_algebra\n\nvariables {R}\n\nnamespace residue_field\n\n/-- The map on residue fields induced by a local homomorphism between local rings -/\nnoncomputable def map (f : R \u2192+* S) [is_local_ring_hom f] :\n  residue_field R \u2192+* residue_field S :=\nideal.quotient.lift (maximal_ideal R) ((ideal.quotient.mk _).comp f) $\n\u03bb a ha,\nbegin\n  erw ideal.quotient.eq_zero_iff_mem,\n  exact map_nonunit f a ha\nend\n\nend residue_field\n\nlemma ker_eq_maximal_ideal [field K] (\u03c6 : R \u2192+* K) (h\u03c6 : function.surjective \u03c6) :\n  \u03c6.ker = maximal_ideal R :=\nlocal_ring.eq_maximal_ideal $ (ring_hom.ker_is_maximal_of_surjective \u03c6) h\u03c6\n\nend\n\nend local_ring\n\nnamespace field\nvariables (K) [field K]\n\nopen_locale classical\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : local_ring K :=\nlocal_ring.of_is_unit_or_is_unit_one_sub_self $ \u03bb a,\n  if h : a = 0\n  then or.inr (by rw [h, sub_zero]; exact is_unit_one)\n  else or.inl $ is_unit.mk0 a h\n\nend field\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/ring_theory/ideal/local_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.7092365074275117}}
{"text": "prelude\nimport init.meta init.logic init.data.nat.lemmas\nimport init.data.char.basic\n\nnamespace char\nlemma val_of_nat_eq_of_is_valid {n : nat} : is_valid_char n \u2192 (of_nat n).val = n :=\nby intro h; unfold of_nat; rw [dif_pos h]\n\nlemma val_of_nat_eq_of_not_is_valid {n : nat} : \u00ac is_valid_char n \u2192 (of_nat n).val = 0 :=\nby intro h; unfold of_nat; rw [dif_neg h]\n\nlemma of_nat_eq_of_not_is_valid {n : nat} : \u00ac is_valid_char n \u2192 of_nat n = of_nat 0 :=\nby intro h; apply eq_of_veq; rw [val_of_nat_eq_of_not_is_valid h]; reflexivity\n\nlemma of_nat_ne_of_ne {n\u2081 n\u2082 : nat} (h\u2081 : n\u2081 \u2260 n\u2082) (h\u2082 : is_valid_char n\u2081) (h\u2083 : is_valid_char n\u2082) : of_nat n\u2081 \u2260 of_nat n\u2082 :=\nbegin\n  apply ne_of_vne,\n  rw [val_of_nat_eq_of_is_valid h\u2082, val_of_nat_eq_of_is_valid h\u2083],\n  assumption\nend\nend char\n", "meta": {"author": "subfish-zhou", "repo": "N2Lean", "sha": "8e858cc5b01f1ad921094dc355db3cb9473a42fd", "save_path": "github-repos/lean/subfish-zhou-N2Lean", "path": "github-repos/lean/subfish-zhou-N2Lean/N2Lean-8e858cc5b01f1ad921094dc355db3cb9473a42fd/library/init/data/char/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7092364943114776}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov, Alistair Tucker\n\n! This file was ported from Lean 3 source module topology.algebra.order.intermediate_value\n! leanprover-community/mathlib commit 50832daea47b195a48b5b33b1c8b2162c48c3afc\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.CompleteLatticeIntervals\nimport Mathbin.Topology.Order.Basic\n\n/-!\n# Intermediate Value Theorem\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove the Intermediate Value Theorem: if `f : \u03b1 \u2192 \u03b2` is a function defined on a\nconnected set `s` that takes both values `\u2264 a` and values `\u2265 a` on `s`, then it is equal to `a` at\nsome point of `s`. We also prove that intervals in a dense conditionally complete order are\npreconnected and any preconnected set is an interval. Then we specialize IVT to functions continuous\non intervals.\n\n## Main results\n\n* `is_preconnected_I??` : all intervals `I??` are preconnected,\n* `is_preconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for\n  connected sets and connected spaces, respectively;\n* `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions\n  on closed intervals.\n\n### Miscellaneous facts\n\n* `is_closed.Icc_subset_of_forall_mem_nhds_within` : \u201cContinuous induction\u201d principle;\n  if `s \u2229 [a, b]` is closed, `a \u2208 s`, and for each `x \u2208 [a, b) \u2229 s` some of its right neighborhoods\n  is included `s`, then `[a, b] \u2286 s`.\n* `is_closed.Icc_subset_of_forall_exists_gt`, `is_closed.mem_of_ge_of_forall_exists_gt` : two\n  other versions of the \u201ccontinuous induction\u201d principle.\n\n## Tags\n\nintermediate value theorem, connected space, connected set\n-/\n\n\nopen Filter OrderDual TopologicalSpace Function Set\n\nopen Topology Filter\n\nuniverse u v w\n\n/-!\n### Intermediate value theorem on a (pre)connected space\n\nIn this section we prove the following theorem (see `is_preconnected.intermediate_value\u2082`): if `f`\nand `g` are two functions continuous on a preconnected set `s`, `f a \u2264 g a` at some `a \u2208 s` and\n`g b \u2264 f b` at some `b \u2208 s`, then `f c = g c` at some `c \u2208 s`. We prove several versions of this\nstatement, including the classical IVT that corresponds to a constant function `g`.\n-/\n\n\nsection\n\nvariable {X : Type u} {\u03b1 : Type v} [TopologicalSpace X] [LinearOrder \u03b1] [TopologicalSpace \u03b1]\n  [OrderClosedTopology \u03b1]\n\n#print intermediate_value_univ\u2082 /-\n/-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions\non a preconnected space and `f a \u2264 g a` and `g b \u2264 f b`, then for some `x` we have `f x = g x`. -/\ntheorem intermediate_value_univ\u2082 [PreconnectedSpace X] {a b : X} {f g : X \u2192 \u03b1} (hf : Continuous f)\n    (hg : Continuous g) (ha : f a \u2264 g a) (hb : g b \u2264 f b) : \u2203 x, f x = g x :=\n  by\n  obtain \u27e8x, h, hfg, hgf\u27e9 : (univ \u2229 { x | f x \u2264 g x \u2227 g x \u2264 f x }).Nonempty\n  exact\n    isPreconnected_closed_iff.1 PreconnectedSpace.isPreconnected_univ _ _ (isClosed_le hf hg)\n      (isClosed_le hg hf) (fun x hx => le_total _ _) \u27e8a, trivial, ha\u27e9 \u27e8b, trivial, hb\u27e9\n  exact \u27e8x, le_antisymm hfg hgf\u27e9\n#align intermediate_value_univ\u2082 intermediate_value_univ\u2082\n-/\n\n#print intermediate_value_univ\u2082_eventually\u2081 /-\ntheorem intermediate_value_univ\u2082_eventually\u2081 [PreconnectedSpace X] {a : X} {l : Filter X} [NeBot l]\n    {f g : X \u2192 \u03b1} (hf : Continuous f) (hg : Continuous g) (ha : f a \u2264 g a) (he : g \u2264\u1da0[l] f) :\n    \u2203 x, f x = g x :=\n  let \u27e8c, hc\u27e9 := he.Frequently.exists\n  intermediate_value_univ\u2082 hf hg ha hc\n#align intermediate_value_univ\u2082_eventually\u2081 intermediate_value_univ\u2082_eventually\u2081\n-/\n\n#print intermediate_value_univ\u2082_eventually\u2082 /-\ntheorem intermediate_value_univ\u2082_eventually\u2082 [PreconnectedSpace X] {l\u2081 l\u2082 : Filter X} [NeBot l\u2081]\n    [NeBot l\u2082] {f g : X \u2192 \u03b1} (hf : Continuous f) (hg : Continuous g) (he\u2081 : f \u2264\u1da0[l\u2081] g)\n    (he\u2082 : g \u2264\u1da0[l\u2082] f) : \u2203 x, f x = g x :=\n  let \u27e8c\u2081, hc\u2081\u27e9 := he\u2081.Frequently.exists\n  let \u27e8c\u2082, hc\u2082\u27e9 := he\u2082.Frequently.exists\n  intermediate_value_univ\u2082 hf hg hc\u2081 hc\u2082\n#align intermediate_value_univ\u2082_eventually\u2082 intermediate_value_univ\u2082_eventually\u2082\n-/\n\n/- warning: is_preconnected.intermediate_value\u2082 -> IsPreconnected.intermediate_value\u2082 is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {b : X}, (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) a s) -> (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) b s) -> (forall {f : X -> \u03b1} {g : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 g s) -> (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))) (f a) (g a)) -> (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))) (g b) (f b)) -> (Exists.{succ u1} X (fun (x : X) => Exists.{0} (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) x s) (fun (H : Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) x s) => Eq.{succ u2} \u03b1 (f x) (g x))))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {b : X}, (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) a s) -> (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) b s) -> (forall {f : X -> \u03b1} {g : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 g s) -> (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))) (f a) (g a)) -> (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))) (g b) (f b)) -> (Exists.{succ u1} X (fun (x : X) => And (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) x s) (Eq.{succ u2} \u03b1 (f x) (g x))))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value\u2082 IsPreconnected.intermediate_value\u2082\u2093'. -/\n/-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous\non a preconnected set `s` and for some `a b \u2208 s` we have `f a \u2264 g a` and `g b \u2264 f b`,\nthen for some `x \u2208 s` we have `f x = g x`. -/\ntheorem IsPreconnected.intermediate_value\u2082 {s : Set X} (hs : IsPreconnected s) {a b : X}\n    (ha : a \u2208 s) (hb : b \u2208 s) {f g : X \u2192 \u03b1} (hf : ContinuousOn f s) (hg : ContinuousOn g s)\n    (ha' : f a \u2264 g a) (hb' : g b \u2264 f b) : \u2203 x \u2208 s, f x = g x :=\n  let \u27e8x, hx\u27e9 :=\n    @intermediate_value_univ\u2082 s \u03b1 _ _ _ _ (Subtype.preconnectedSpace hs) \u27e8a, ha\u27e9 \u27e8b, hb\u27e9 _ _\n      (continuousOn_iff_continuous_restrict.1 hf) (continuousOn_iff_continuous_restrict.1 hg) ha'\n      hb'\n  \u27e8x, x.2, hx\u27e9\n#align is_preconnected.intermediate_value\u2082 IsPreconnected.intermediate_value\u2082\n\n/- warning: is_preconnected.intermediate_value\u2082_eventually\u2081 -> IsPreconnected.intermediate_value\u2082_eventually\u2081 is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1} {g : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 g s) -> (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))) (f a) (g a)) -> (Filter.EventuallyLE.{u1, u2} X \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))) l g f) -> (Exists.{succ u1} X (fun (x : X) => Exists.{0} (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) x s) (fun (H : Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) x s) => Eq.{succ u2} \u03b1 (f x) (g x)))))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1} {g : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 g s) -> (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))) (f a) (g a)) -> (Filter.EventuallyLE.{u1, u2} X \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))) l g f) -> (Exists.{succ u1} X (fun (x : X) => And (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) x s) (Eq.{succ u2} \u03b1 (f x) (g x)))))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value\u2082_eventually\u2081 IsPreconnected.intermediate_value\u2082_eventually\u2081\u2093'. -/\ntheorem IsPreconnected.intermediate_value\u2082_eventually\u2081 {s : Set X} (hs : IsPreconnected s) {a : X}\n    {l : Filter X} (ha : a \u2208 s) [NeBot l] (hl : l \u2264 \ud835\udcdf s) {f g : X \u2192 \u03b1} (hf : ContinuousOn f s)\n    (hg : ContinuousOn g s) (ha' : f a \u2264 g a) (he : g \u2264\u1da0[l] f) : \u2203 x \u2208 s, f x = g x :=\n  by\n  rw [continuousOn_iff_continuous_restrict] at hf hg\n  obtain \u27e8b, h\u27e9 :=\n    @intermediate_value_univ\u2082_eventually\u2081 _ _ _ _ _ _ (Subtype.preconnectedSpace hs) \u27e8a, ha\u27e9 _\n      (comap_coe_ne_bot_of_le_principal hl) _ _ hf hg ha' (he.comap _)\n  exact \u27e8b, b.prop, h\u27e9\n#align is_preconnected.intermediate_value\u2082_eventually\u2081 IsPreconnected.intermediate_value\u2082_eventually\u2081\n\n/- warning: is_preconnected.intermediate_value\u2082_eventually\u2082 -> IsPreconnected.intermediate_value\u2082_eventually\u2082 is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1} {g : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 g s) -> (Filter.EventuallyLE.{u1, u2} X \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))) l\u2081 f g) -> (Filter.EventuallyLE.{u1, u2} X \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))) l\u2082 g f) -> (Exists.{succ u1} X (fun (x : X) => Exists.{0} (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) x s) (fun (H : Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) x s) => Eq.{succ u2} \u03b1 (f x) (g x))))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1} {g : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 g s) -> (Filter.EventuallyLE.{u1, u2} X \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))) l\u2081 f g) -> (Filter.EventuallyLE.{u1, u2} X \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))) l\u2082 g f) -> (Exists.{succ u1} X (fun (x : X) => And (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) x s) (Eq.{succ u2} \u03b1 (f x) (g x))))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value\u2082_eventually\u2082 IsPreconnected.intermediate_value\u2082_eventually\u2082\u2093'. -/\ntheorem IsPreconnected.intermediate_value\u2082_eventually\u2082 {s : Set X} (hs : IsPreconnected s)\n    {l\u2081 l\u2082 : Filter X} [NeBot l\u2081] [NeBot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f g : X \u2192 \u03b1}\n    (hf : ContinuousOn f s) (hg : ContinuousOn g s) (he\u2081 : f \u2264\u1da0[l\u2081] g) (he\u2082 : g \u2264\u1da0[l\u2082] f) :\n    \u2203 x \u2208 s, f x = g x :=\n  by\n  rw [continuousOn_iff_continuous_restrict] at hf hg\n  obtain \u27e8b, h\u27e9 :=\n    @intermediate_value_univ\u2082_eventually\u2082 _ _ _ _ _ _ (Subtype.preconnectedSpace hs) _ _\n      (comap_coe_ne_bot_of_le_principal hl\u2081) (comap_coe_ne_bot_of_le_principal hl\u2082) _ _ hf hg\n      (he\u2081.comap _) (he\u2082.comap _)\n  exact \u27e8b, b.prop, h\u27e9\n#align is_preconnected.intermediate_value\u2082_eventually\u2082 IsPreconnected.intermediate_value\u2082_eventually\u2082\n\n#print IsPreconnected.intermediate_value /-\n/-- **Intermediate Value Theorem** for continuous functions on connected sets. -/\ntheorem IsPreconnected.intermediate_value {s : Set X} (hs : IsPreconnected s) {a b : X} (ha : a \u2208 s)\n    (hb : b \u2208 s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s) : Icc (f a) (f b) \u2286 f '' s := fun x hx =>\n  mem_image_iff_bex.2 <| hs.intermediate_value\u2082 ha hb hf continuousOn_const hx.1 hx.2\n#align is_preconnected.intermediate_value IsPreconnected.intermediate_value\n-/\n\n/- warning: is_preconnected.intermediate_value_Ico -> IsPreconnected.intermediate_value_Ico is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l (nhds.{u2} \u03b1 _inst_3 v)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.Ico.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))) (f a) v) (Set.image.{u1, u2} X \u03b1 f s))))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l (nhds.{u2} \u03b1 _inst_3 v)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.Ico.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))) (f a) v) (Set.image.{u1, u2} X \u03b1 f s))))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Ico IsPreconnected.intermediate_value_Ico\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Ico {s : Set X} (hs : IsPreconnected s) {a : X}\n    {l : Filter X} (ha : a \u2208 s) [NeBot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s) {v : \u03b1}\n    (ht : Tendsto f l (\ud835\udcdd v)) : Ico (f a) v \u2286 f '' s := fun y h =>\n  bex_def.1 <|\n    hs.intermediate_value\u2082_eventually\u2081 ha hl hf continuousOn_const h.1\n      (eventually_ge_of_tendsto_gt h.2 ht)\n#align is_preconnected.intermediate_value_Ico IsPreconnected.intermediate_value_Ico\n\n/- warning: is_preconnected.intermediate_value_Ioc -> IsPreconnected.intermediate_value_Ioc is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l (nhds.{u2} \u03b1 _inst_3 v)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.Ioc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))) v (f a)) (Set.image.{u1, u2} X \u03b1 f s))))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l (nhds.{u2} \u03b1 _inst_3 v)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.Ioc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))) v (f a)) (Set.image.{u1, u2} X \u03b1 f s))))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Ioc IsPreconnected.intermediate_value_Ioc\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Ioc {s : Set X} (hs : IsPreconnected s) {a : X}\n    {l : Filter X} (ha : a \u2208 s) [NeBot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s) {v : \u03b1}\n    (ht : Tendsto f l (\ud835\udcdd v)) : Ioc v (f a) \u2286 f '' s := fun y h =>\n  bex_def.1 <|\n    (BEx.imp_right fun x _ => Eq.symm) <|\n      hs.intermediate_value\u2082_eventually\u2081 ha hl continuousOn_const hf h.2\n        (eventually_le_of_tendsto_lt h.1 ht)\n#align is_preconnected.intermediate_value_Ioc IsPreconnected.intermediate_value_Ioc\n\n/- warning: is_preconnected.intermediate_value_Ioo -> IsPreconnected.intermediate_value_Ioo is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v\u2081 : \u03b1} {v\u2082 : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (nhds.{u2} \u03b1 _inst_3 v\u2081)) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (nhds.{u2} \u03b1 _inst_3 v\u2082)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.Ioo.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))) v\u2081 v\u2082) (Set.image.{u1, u2} X \u03b1 f s)))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v\u2081 : \u03b1} {v\u2082 : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (nhds.{u2} \u03b1 _inst_3 v\u2081)) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (nhds.{u2} \u03b1 _inst_3 v\u2082)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.Ioo.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))) v\u2081 v\u2082) (Set.image.{u1, u2} X \u03b1 f s)))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Ioo IsPreconnected.intermediate_value_Ioo\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Ioo {s : Set X} (hs : IsPreconnected s) {l\u2081 l\u2082 : Filter X}\n    [NeBot l\u2081] [NeBot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s)\n    {v\u2081 v\u2082 : \u03b1} (ht\u2081 : Tendsto f l\u2081 (\ud835\udcdd v\u2081)) (ht\u2082 : Tendsto f l\u2082 (\ud835\udcdd v\u2082)) : Ioo v\u2081 v\u2082 \u2286 f '' s :=\n  fun y h =>\n  bex_def.1 <|\n    hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082 hf continuousOn_const\n      (eventually_le_of_tendsto_lt h.1 ht\u2081) (eventually_ge_of_tendsto_gt h.2 ht\u2082)\n#align is_preconnected.intermediate_value_Ioo IsPreconnected.intermediate_value_Ioo\n\n/- warning: is_preconnected.intermediate_value_Ici -> IsPreconnected.intermediate_value_Ici is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.Ici.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))) (f a)) (Set.image.{u1, u2} X \u03b1 f s)))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.Ici.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))) (f a)) (Set.image.{u1, u2} X \u03b1 f s)))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Ici IsPreconnected.intermediate_value_Ici\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Ici {s : Set X} (hs : IsPreconnected s) {a : X}\n    {l : Filter X} (ha : a \u2208 s) [NeBot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s)\n    (ht : Tendsto f l atTop) : Ici (f a) \u2286 f '' s := fun y h =>\n  bex_def.1 <|\n    hs.intermediate_value\u2082_eventually\u2081 ha hl hf continuousOn_const h (tendsto_atTop.1 ht y)\n#align is_preconnected.intermediate_value_Ici IsPreconnected.intermediate_value_Ici\n\n/- warning: is_preconnected.intermediate_value_Iic -> IsPreconnected.intermediate_value_Iic is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.Mem.{u1, u1} X (Set.{u1} X) (Set.hasMem.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.Iic.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))) (f a)) (Set.image.{u1, u2} X \u03b1 f s)))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {a : X} {l : Filter.{u1} X}, (Membership.mem.{u1, u1} X (Set.{u1} X) (Set.instMembershipSet.{u1} X) a s) -> (forall [_inst_5 : Filter.NeBot.{u1} X l], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.Iic.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))) (f a)) (Set.image.{u1, u2} X \u03b1 f s)))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Iic IsPreconnected.intermediate_value_Iic\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Iic {s : Set X} (hs : IsPreconnected s) {a : X}\n    {l : Filter X} (ha : a \u2208 s) [NeBot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s)\n    (ht : Tendsto f l atBot) : Iic (f a) \u2286 f '' s := fun y h =>\n  bex_def.1 <|\n    (BEx.imp_right fun x _ => Eq.symm) <|\n      hs.intermediate_value\u2082_eventually\u2081 ha hl continuousOn_const hf h (tendsto_atBot.1 ht y)\n#align is_preconnected.intermediate_value_Iic IsPreconnected.intermediate_value_Iic\n\n/- warning: is_preconnected.intermediate_value_Ioi -> IsPreconnected.intermediate_value_Ioi is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (nhds.{u2} \u03b1 _inst_3 v)) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.Ioi.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))) v) (Set.image.{u1, u2} X \u03b1 f s)))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (nhds.{u2} \u03b1 _inst_3 v)) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.Ioi.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))) v) (Set.image.{u1, u2} X \u03b1 f s)))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Ioi IsPreconnected.intermediate_value_Ioi\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Ioi {s : Set X} (hs : IsPreconnected s) {l\u2081 l\u2082 : Filter X}\n    [NeBot l\u2081] [NeBot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s)\n    {v : \u03b1} (ht\u2081 : Tendsto f l\u2081 (\ud835\udcdd v)) (ht\u2082 : Tendsto f l\u2082 atTop) : Ioi v \u2286 f '' s := fun y h =>\n  bex_def.1 <|\n    hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082 hf continuousOn_const\n      (eventually_le_of_tendsto_lt h ht\u2081) (tendsto_atTop.1 ht\u2082 y)\n#align is_preconnected.intermediate_value_Ioi IsPreconnected.intermediate_value_Ioi\n\n/- warning: is_preconnected.intermediate_value_Iio -> IsPreconnected.intermediate_value_Iio is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))))) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (nhds.{u2} \u03b1 _inst_3 v)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.Iio.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))) v) (Set.image.{u1, u2} X \u03b1 f s)))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (forall {v : \u03b1}, (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))))) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (nhds.{u2} \u03b1 _inst_3 v)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.Iio.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))) v) (Set.image.{u1, u2} X \u03b1 f s)))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Iio IsPreconnected.intermediate_value_Iio\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Iio {s : Set X} (hs : IsPreconnected s) {l\u2081 l\u2082 : Filter X}\n    [NeBot l\u2081] [NeBot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s)\n    {v : \u03b1} (ht\u2081 : Tendsto f l\u2081 atBot) (ht\u2082 : Tendsto f l\u2082 (\ud835\udcdd v)) : Iio v \u2286 f '' s := fun y h =>\n  bex_def.1 <|\n    hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082 hf continuousOn_const (tendsto_atBot.1 ht\u2081 y)\n      (eventually_ge_of_tendsto_gt h ht\u2082)\n#align is_preconnected.intermediate_value_Iio IsPreconnected.intermediate_value_Iio\n\n/- warning: is_preconnected.intermediate_value_Iii -> IsPreconnected.intermediate_value_Iii is a dubious translation:\nlean 3 declaration is\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.partialOrder.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))))) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (LinearOrder.toLattice.{u2} \u03b1 _inst_2)))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.hasSubset.{u2} \u03b1) (Set.univ.{u2} \u03b1) (Set.image.{u1, u2} X \u03b1 f s))))\nbut is expected to have type\n  forall {X : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} X] [_inst_2 : LinearOrder.{u2} \u03b1] [_inst_3 : TopologicalSpace.{u2} \u03b1] [_inst_4 : OrderClosedTopology.{u2} \u03b1 _inst_3 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2)))))] {s : Set.{u1} X}, (IsPreconnected.{u1} X _inst_1 s) -> (forall {l\u2081 : Filter.{u1} X} {l\u2082 : Filter.{u1} X} [_inst_5 : Filter.NeBot.{u1} X l\u2081] [_inst_6 : Filter.NeBot.{u1} X l\u2082], (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2081 (Filter.principal.{u1} X s)) -> (LE.le.{u1} (Filter.{u1} X) (Preorder.toLE.{u1} (Filter.{u1} X) (PartialOrder.toPreorder.{u1} (Filter.{u1} X) (Filter.instPartialOrderFilter.{u1} X))) l\u2082 (Filter.principal.{u1} X s)) -> (forall {f : X -> \u03b1}, (ContinuousOn.{u1, u2} X \u03b1 _inst_1 _inst_3 f s) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2081 (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))))) -> (Filter.Tendsto.{u1, u2} X \u03b1 f l\u2082 (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_2))))))) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b1) (Set.instHasSubsetSet.{u2} \u03b1) (Set.univ.{u2} \u03b1) (Set.image.{u1, u2} X \u03b1 f s))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.intermediate_value_Iii IsPreconnected.intermediate_value_Iii\u2093'. -/\ntheorem IsPreconnected.intermediate_value_Iii {s : Set X} (hs : IsPreconnected s) {l\u2081 l\u2082 : Filter X}\n    [NeBot l\u2081] [NeBot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1} (hf : ContinuousOn f s)\n    (ht\u2081 : Tendsto f l\u2081 atBot) (ht\u2082 : Tendsto f l\u2082 atTop) : univ \u2286 f '' s := fun y h =>\n  bex_def.1 <|\n    hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082 hf continuousOn_const (tendsto_atBot.1 ht\u2081 y)\n      (tendsto_atTop.1 ht\u2082 y)\n#align is_preconnected.intermediate_value_Iii IsPreconnected.intermediate_value_Iii\n\n#print intermediate_value_univ /-\n/-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/\ntheorem intermediate_value_univ [PreconnectedSpace X] (a b : X) {f : X \u2192 \u03b1} (hf : Continuous f) :\n    Icc (f a) (f b) \u2286 range f := fun x hx => intermediate_value_univ\u2082 hf continuous_const hx.1 hx.2\n#align intermediate_value_univ intermediate_value_univ\n-/\n\n#print mem_range_of_exists_le_of_exists_ge /-\n/-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/\ntheorem mem_range_of_exists_le_of_exists_ge [PreconnectedSpace X] {c : \u03b1} {f : X \u2192 \u03b1}\n    (hf : Continuous f) (h\u2081 : \u2203 a, f a \u2264 c) (h\u2082 : \u2203 b, c \u2264 f b) : c \u2208 range f :=\n  let \u27e8a, ha\u27e9 := h\u2081\n  let \u27e8b, hb\u27e9 := h\u2082\n  intermediate_value_univ a b hf \u27e8ha, hb\u27e9\n#align mem_range_of_exists_le_of_exists_ge mem_range_of_exists_le_of_exists_ge\n-/\n\n/-!\n### (Pre)connected sets in a linear order\n\nIn this section we prove the following results:\n\n* `is_preconnected.ord_connected`: any preconnected set `s` in a linear order is `ord_connected`,\n  i.e. `a \u2208 s` and `b \u2208 s` imply `Icc a b \u2286 s`;\n\n* `is_preconnected.mem_intervals`: any preconnected set `s` in a conditionally complete linear order\n  is one of the intervals `set.Icc`, `set.`Ico`, `set.Ioc`, `set.Ioo`, ``set.Ici`, `set.Iic`,\n  `set.Ioi`, `set.Iio`; note that this is false for non-complete orders: e.g., in `\u211d \\ {0}`, the set\n  of positive numbers cannot be represented as `set.Ioi _`.\n\n-/\n\n\n#print IsPreconnected.Icc_subset /-\n/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/\ntheorem IsPreconnected.Icc_subset {s : Set \u03b1} (hs : IsPreconnected s) {a b : \u03b1} (ha : a \u2208 s)\n    (hb : b \u2208 s) : Icc a b \u2286 s := by\n  simpa only [image_id] using hs.intermediate_value ha hb continuousOn_id\n#align is_preconnected.Icc_subset IsPreconnected.Icc_subset\n-/\n\n#print IsPreconnected.ordConnected /-\ntheorem IsPreconnected.ordConnected {s : Set \u03b1} (h : IsPreconnected s) : OrdConnected s :=\n  \u27e8fun x hx y hy => h.Icc_subset hx hy\u27e9\n#align is_preconnected.ord_connected IsPreconnected.ordConnected\n-/\n\n#print IsConnected.Icc_subset /-\n/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/\ntheorem IsConnected.Icc_subset {s : Set \u03b1} (hs : IsConnected s) {a b : \u03b1} (ha : a \u2208 s)\n    (hb : b \u2208 s) : Icc a b \u2286 s :=\n  hs.2.Icc_subset ha hb\n#align is_connected.Icc_subset IsConnected.Icc_subset\n-/\n\n#print IsPreconnected.eq_univ_of_unbounded /-\n/-- If preconnected set in a linear order space is unbounded below and above, then it is the whole\nspace. -/\ntheorem IsPreconnected.eq_univ_of_unbounded {s : Set \u03b1} (hs : IsPreconnected s) (hb : \u00acBddBelow s)\n    (ha : \u00acBddAbove s) : s = univ :=\n  by\n  refine' eq_univ_of_forall fun x => _\n  obtain \u27e8y, ys, hy\u27e9 : \u2203 y \u2208 s, y < x := not_bddBelow_iff.1 hb x\n  obtain \u27e8z, zs, hz\u27e9 : \u2203 z \u2208 s, x < z := not_bddAbove_iff.1 ha x\n  exact hs.Icc_subset ys zs \u27e8le_of_lt hy, le_of_lt hz\u27e9\n#align is_preconnected.eq_univ_of_unbounded IsPreconnected.eq_univ_of_unbounded\n-/\n\nend\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [ConditionallyCompleteLinearOrder \u03b1]\n  [TopologicalSpace \u03b1] [OrderTopology \u03b1] [ConditionallyCompleteLinearOrder \u03b2] [TopologicalSpace \u03b2]\n  [OrderTopology \u03b2] [Nonempty \u03b3]\n\n/- warning: is_connected.Ioo_cInf_cSup_subset -> IsConnected.Ioo_cinf\u209b_csup\u209b_subset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsConnected.{u1} \u03b1 _inst_2 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsConnected.{u1} \u03b1 _inst_2 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) s)\nCase conversion may be inaccurate. Consider using '#align is_connected.Ioo_cInf_cSup_subset IsConnected.Ioo_cinf\u209b_csup\u209b_subset\u2093'. -/\n/-- A bounded connected subset of a conditionally complete linear order includes the open interval\n`(Inf s, Sup s)`. -/\ntheorem IsConnected.Ioo_cinf\u209b_csup\u209b_subset {s : Set \u03b1} (hs : IsConnected s) (hb : BddBelow s)\n    (ha : BddAbove s) : Ioo (inf\u209b s) (sup\u209b s) \u2286 s := fun x hx =>\n  let \u27e8y, ys, hy\u27e9 := (isGLB_lt_iff (isGLB_cinf\u209b hs.Nonempty hb)).1 hx.1\n  let \u27e8z, zs, hz\u27e9 := (lt_isLUB_iff (isLUB_csup\u209b hs.Nonempty ha)).1 hx.2\n  hs.Icc_subset ys zs \u27e8le_of_lt hy, le_of_lt hz\u27e9\n#align is_connected.Ioo_cInf_cSup_subset IsConnected.Ioo_cinf\u209b_csup\u209b_subset\n\n/- warning: eq_Icc_cInf_cSup_of_connected_bdd_closed -> eq_Icc_cinf\u209b_csup\u209b_of_connected_bdd_closed is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsConnected.{u1} \u03b1 _inst_2 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (IsClosed.{u1} \u03b1 _inst_2 s) -> (Eq.{succ u1} (Set.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsConnected.{u1} \u03b1 _inst_2 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (IsClosed.{u1} \u03b1 _inst_2 s) -> (Eq.{succ u1} (Set.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)))\nCase conversion may be inaccurate. Consider using '#align eq_Icc_cInf_cSup_of_connected_bdd_closed eq_Icc_cinf\u209b_csup\u209b_of_connected_bdd_closed\u2093'. -/\ntheorem eq_Icc_cinf\u209b_csup\u209b_of_connected_bdd_closed {s : Set \u03b1} (hc : IsConnected s)\n    (hb : BddBelow s) (ha : BddAbove s) (hcl : IsClosed s) : s = Icc (inf\u209b s) (sup\u209b s) :=\n  Subset.antisymm (subset_Icc_cinf\u209b_csup\u209b hb ha) <|\n    hc.Icc_subset (hcl.cinf\u209b_mem hc.Nonempty hb) (hcl.csup\u209b_mem hc.Nonempty ha)\n#align eq_Icc_cInf_cSup_of_connected_bdd_closed eq_Icc_cinf\u209b_csup\u209b_of_connected_bdd_closed\n\n/- warning: is_preconnected.Ioi_cInf_subset -> IsPreconnected.Ioi_cinf\u209b_subset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsPreconnected.{u1} \u03b1 _inst_2 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (Not (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsPreconnected.{u1} \u03b1 _inst_2 s) -> (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (Not (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) s)\nCase conversion may be inaccurate. Consider using '#align is_preconnected.Ioi_cInf_subset IsPreconnected.Ioi_cinf\u209b_subset\u2093'. -/\ntheorem IsPreconnected.Ioi_cinf\u209b_subset {s : Set \u03b1} (hs : IsPreconnected s) (hb : BddBelow s)\n    (ha : \u00acBddAbove s) : Ioi (inf\u209b s) \u2286 s :=\n  by\n  have sne : s.nonempty := @nonempty_of_not_bddAbove \u03b1 _ s \u27e8Inf \u2205\u27e9 ha\n  intro x hx\n  obtain \u27e8y, ys, hy\u27e9 : \u2203 y \u2208 s, y < x := (isGLB_lt_iff (isGLB_cinf\u209b sne hb)).1 hx\n  obtain \u27e8z, zs, hz\u27e9 : \u2203 z \u2208 s, x < z := not_bddAbove_iff.1 ha x\n  exact hs.Icc_subset ys zs \u27e8le_of_lt hy, le_of_lt hz\u27e9\n#align is_preconnected.Ioi_cInf_subset IsPreconnected.Ioi_cinf\u209b_subset\n\n/- warning: is_preconnected.Iio_cSup_subset -> IsPreconnected.Iio_csup\u209b_subset is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsPreconnected.{u1} \u03b1 _inst_2 s) -> (Not (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s)) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsPreconnected.{u1} \u03b1 _inst_2 s) -> (Not (BddBelow.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s)) -> (BddAbove.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) s)\nCase conversion may be inaccurate. Consider using '#align is_preconnected.Iio_cSup_subset IsPreconnected.Iio_csup\u209b_subset\u2093'. -/\ntheorem IsPreconnected.Iio_csup\u209b_subset {s : Set \u03b1} (hs : IsPreconnected s) (hb : \u00acBddBelow s)\n    (ha : BddAbove s) : Iio (sup\u209b s) \u2286 s :=\n  @IsPreconnected.Ioi_cinf\u209b_subset \u03b1\u1d52\u1d48 _ _ _ s hs ha hb\n#align is_preconnected.Iio_cSup_subset IsPreconnected.Iio_csup\u209b_subset\n\n/- warning: is_preconnected.mem_intervals -> IsPreconnected.mem_intervals is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsPreconnected.{u1} \u03b1 _inst_2 s) -> (Membership.Mem.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasMem.{u1} (Set.{u1} \u03b1)) s (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Ici.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasInf.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Iic.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toHasSup.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.univ.{u1} \u03b1) (Singleton.singleton.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasSingleton.{u1} (Set.{u1} \u03b1)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1)))))))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {s : Set.{u1} \u03b1}, (IsPreconnected.{u1} \u03b1 _inst_2 s) -> (Membership.mem.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instMembershipSet.{u1} (Set.{u1} \u03b1)) s (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Ici.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (InfSet.inf\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toInfSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Iic.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (SupSet.sup\u209b.{u1} \u03b1 (ConditionallyCompleteLattice.toSupSet.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) s)) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.univ.{u1} \u03b1) (Singleton.singleton.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instSingletonSet.{u1} (Set.{u1} \u03b1)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1)))))))))))))\nCase conversion may be inaccurate. Consider using '#align is_preconnected.mem_intervals IsPreconnected.mem_intervals\u2093'. -/\n/-- A preconnected set in a conditionally complete linear order is either one of the intervals\n`[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +\u221e)`,\n`(Inf s, +\u221e)`, `(-\u221e, Sup s]`, `(-\u221e, Sup s)`, `(-\u221e, +\u221e)`, or `\u2205`. The converse statement requires\n`\u03b1` to be densely ordererd. -/\ntheorem IsPreconnected.mem_intervals {s : Set \u03b1} (hs : IsPreconnected s) :\n    s \u2208\n      ({Icc (inf\u209b s) (sup\u209b s), Ico (inf\u209b s) (sup\u209b s), Ioc (inf\u209b s) (sup\u209b s), Ioo (inf\u209b s) (sup\u209b s),\n          Ici (inf\u209b s), Ioi (inf\u209b s), Iic (sup\u209b s), Iio (sup\u209b s), univ, \u2205} :\n        Set (Set \u03b1)) :=\n  by\n  rcases s.eq_empty_or_nonempty with (rfl | hne)\n  \u00b7 apply_rules [Or.inr, mem_singleton]\n  have hs' : IsConnected s := \u27e8hne, hs\u27e9\n  by_cases hb : BddBelow s <;> by_cases ha : BddAbove s\n  \u00b7 rcases mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_cInf_cSup_subset hb ha)\n        (subset_Icc_cinf\u209b_csup\u209b hb ha) with (hs | hs | hs | hs)\n    \u00b7 exact Or.inl hs\n    \u00b7 exact Or.inr <| Or.inl hs\n    \u00b7 exact Or.inr <| Or.inr <| Or.inl hs\n    \u00b7 exact Or.inr <| Or.inr <| Or.inr <| Or.inl hs\n  \u00b7 refine' Or.inr <| Or.inr <| Or.inr <| Or.inr _\n    cases'\n      mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_cInf_subset hb ha) fun x hx => cinf\u209b_le hb hx with\n      hs hs\n    \u00b7 exact Or.inl hs\n    \u00b7 exact Or.inr (Or.inl hs)\n  \u00b7 iterate 6 apply Or.inr\n    cases'\n      mem_Iic_Iio_of_subset_of_subset (hs.Iio_cSup_subset hb ha) fun x hx => le_csup\u209b ha hx with\n      hs hs\n    \u00b7 exact Or.inl hs\n    \u00b7 exact Or.inr (Or.inl hs)\n  \u00b7 iterate 8 apply Or.inr\n    exact Or.inl (hs.eq_univ_of_unbounded hb ha)\n#align is_preconnected.mem_intervals IsPreconnected.mem_intervals\n\n/- warning: set_of_is_preconnected_subset_of_ordered -> setOf_isPreconnected_subset_of_ordered is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))], HasSubset.Subset.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasSubset.{u1} (Set.{u1} \u03b1)) (setOf.{u1} (Set.{u1} \u03b1) (fun (s : Set.{u1} \u03b1) => IsPreconnected.{u1} \u03b1 _inst_2 s)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ici.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iic.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.univ.{u1} \u03b1) (Singleton.singleton.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasSingleton.{u1} (Set.{u1} \u03b1)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))], HasSubset.Subset.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instHasSubsetSet.{u1} (Set.{u1} \u03b1)) (setOf.{u1} (Set.{u1} \u03b1) (fun (s : Set.{u1} \u03b1) => IsPreconnected.{u1} \u03b1 _inst_2 s)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ici.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iic.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.univ.{u1} \u03b1) (Singleton.singleton.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instSingletonSet.{u1} (Set.{u1} \u03b1)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))))))\nCase conversion may be inaccurate. Consider using '#align set_of_is_preconnected_subset_of_ordered setOf_isPreconnected_subset_of_ordered\u2093'. -/\n/-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`,\n`Iic`, `Iio`, or `univ`, or `\u2205`. The converse statement requires `\u03b1` to be densely ordered. Though\none can represent `\u2205` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve\nreadability. -/\ntheorem setOf_isPreconnected_subset_of_ordered :\n    { s : Set \u03b1 | IsPreconnected s } \u2286-- bounded intervals\n                range\n                (uncurry Icc) \u222a\n              range (uncurry Ico) \u222a\n            range (uncurry Ioc) \u222a\n          range (uncurry Ioo) \u222a\n        (-- unbounded intervals and `univ`\n                  range\n                  Ici \u222a\n                range Ioi \u222a\n              range Iic \u222a\n            range Iio \u222a\n          {univ, \u2205}) :=\n  by\n  intro s hs\n  rcases hs.mem_intervals with (hs | hs | hs | hs | hs | hs | hs | hs | hs | hs)\n  \u00b7 exact Or.inl <| Or.inl <| Or.inl <| Or.inl \u27e8(Inf s, Sup s), hs.symm\u27e9\n  \u00b7 exact Or.inl <| Or.inl <| Or.inl <| Or.inr \u27e8(Inf s, Sup s), hs.symm\u27e9\n  \u00b7 exact Or.inl <| Or.inl <| Or.inr \u27e8(Inf s, Sup s), hs.symm\u27e9\n  \u00b7 exact Or.inl <| Or.inr \u27e8(Inf s, Sup s), hs.symm\u27e9\n  \u00b7 exact Or.inr <| Or.inl <| Or.inl <| Or.inl <| Or.inl \u27e8Inf s, hs.symm\u27e9\n  \u00b7 exact Or.inr <| Or.inl <| Or.inl <| Or.inl <| Or.inr \u27e8Inf s, hs.symm\u27e9\n  \u00b7 exact Or.inr <| Or.inl <| Or.inl <| Or.inr \u27e8Sup s, hs.symm\u27e9\n  \u00b7 exact Or.inr <| Or.inl <| Or.inr \u27e8Sup s, hs.symm\u27e9\n  \u00b7 exact Or.inr <| Or.inr <| Or.inl hs\n  \u00b7 exact Or.inr <| Or.inr <| Or.inr hs\n#align set_of_is_preconnected_subset_of_ordered setOf_isPreconnected_subset_of_ordered\n\n/-!\n### Intervals are connected\n\nIn this section we prove that a closed interval (hence, any `ord_connected` set) in a dense\nconditionally complete linear order is preconnected.\n-/\n\n\n/- warning: is_closed.mem_of_ge_of_forall_exists_gt -> IsClosed.mem_of_ge_of_forall_exists_gt is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {a : \u03b1} {b : \u03b1} {s : Set.{u1} \u03b1}, (IsClosed.{u1} \u03b1 _inst_2 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) -> (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x b)))) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) b s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {a : \u03b1} {b : \u03b1} {s : Set.{u1} \u03b1}, (IsClosed.{u1} \u03b1 _inst_2 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a s) -> (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x b)))) -> (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) b s)\nCase conversion may be inaccurate. Consider using '#align is_closed.mem_of_ge_of_forall_exists_gt IsClosed.mem_of_ge_of_forall_exists_gt\u2093'. -/\n/-- A \"continuous induction principle\" for a closed interval: if a set `s` meets `[a, b]`\non a closed subset, contains `a`, and the set `s \u2229 [a, b)` has no maximal point, then `b \u2208 s`. -/\ntheorem IsClosed.mem_of_ge_of_forall_exists_gt {a b : \u03b1} {s : Set \u03b1} (hs : IsClosed (s \u2229 Icc a b))\n    (ha : a \u2208 s) (hab : a \u2264 b) (hgt : \u2200 x \u2208 s \u2229 Ico a b, (s \u2229 Ioc x b).Nonempty) : b \u2208 s :=\n  by\n  let S := s \u2229 Icc a b\n  replace ha : a \u2208 S\n  exact \u27e8ha, left_mem_Icc.2 hab\u27e9\n  have Sbd : BddAbove S := \u27e8b, fun z hz => hz.2.2\u27e9\n  let c := Sup (s \u2229 Icc a b)\n  have c_mem : c \u2208 S := hs.cSup_mem \u27e8_, ha\u27e9 Sbd\n  have c_le : c \u2264 b := csup\u209b_le \u27e8_, ha\u27e9 fun x hx => hx.2.2\n  cases' eq_or_lt_of_le c_le with hc hc\n  exact hc \u25b8 c_mem.1\n  exfalso\n  rcases hgt c \u27e8c_mem.1, c_mem.2.1, hc\u27e9 with \u27e8x, xs, cx, xb\u27e9\n  exact not_lt_of_le (le_csup\u209b Sbd \u27e8xs, le_trans (le_csup\u209b Sbd ha) (le_of_lt cx), xb\u27e9) cx\n#align is_closed.mem_of_ge_of_forall_exists_gt IsClosed.mem_of_ge_of_forall_exists_gt\n\n/- warning: is_closed.Icc_subset_of_forall_exists_gt -> IsClosed.Icc_subset_of_forall_exists_gt is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {a : \u03b1} {b : \u03b1} {s : Set.{u1} \u03b1}, (IsClosed.{u1} \u03b1 _inst_2 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) -> (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (forall (y : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x)) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x y))))) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] {a : \u03b1} {b : \u03b1} {s : Set.{u1} \u03b1}, (IsClosed.{u1} \u03b1 _inst_2 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a s) -> (forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (forall (y : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) y (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x)) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x y))))) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) s)\nCase conversion may be inaccurate. Consider using '#align is_closed.Icc_subset_of_forall_exists_gt IsClosed.Icc_subset_of_forall_exists_gt\u2093'. -/\n/-- A \"continuous induction principle\" for a closed interval: if a set `s` meets `[a, b]`\non a closed subset, contains `a`, and for any `a \u2264 x < y \u2264 b`, `x \u2208 s`, the set `s \u2229 (x, y]`\nis not empty, then `[a, b] \u2286 s`. -/\ntheorem IsClosed.Icc_subset_of_forall_exists_gt {a b : \u03b1} {s : Set \u03b1} (hs : IsClosed (s \u2229 Icc a b))\n    (ha : a \u2208 s) (hgt : \u2200 x \u2208 s \u2229 Ico a b, \u2200 y \u2208 Ioi x, (s \u2229 Ioc x y).Nonempty) : Icc a b \u2286 s :=\n  by\n  intro y hy\n  have : IsClosed (s \u2229 Icc a y) :=\n    by\n    suffices s \u2229 Icc a y = s \u2229 Icc a b \u2229 Icc a y\n      by\n      rw [this]\n      exact IsClosed.inter hs isClosed_Icc\n    rw [inter_assoc]\n    congr\n    exact (inter_eq_self_of_subset_right <| Icc_subset_Icc_right hy.2).symm\n  exact\n    IsClosed.mem_of_ge_of_forall_exists_gt this ha hy.1 fun x hx =>\n      hgt x \u27e8hx.1, Ico_subset_Ico_right hy.2 hx.2\u27e9 y hx.2.2\n#align is_closed.Icc_subset_of_forall_exists_gt IsClosed.Icc_subset_of_forall_exists_gt\n\nvariable [DenselyOrdered \u03b1] {a b : \u03b1}\n\n/- warning: is_closed.Icc_subset_of_forall_mem_nhds_within -> IsClosed.Icc_subset_of_forall_mem_nhdsWithin is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {a : \u03b1} {b : \u03b1} {s : Set.{u1} \u03b1}, (IsClosed.{u1} \u03b1 _inst_2 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) -> (forall (x : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.Mem.{u1, u1} (Set.{u1} \u03b1) (Filter.{u1} \u03b1) (Filter.hasMem.{u1} \u03b1) s (nhdsWithin.{u1} \u03b1 _inst_2 x (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x)))) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {a : \u03b1} {b : \u03b1} {s : Set.{u1} \u03b1}, (IsClosed.{u1} \u03b1 _inst_2 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) a s) -> (forall (x : \u03b1), (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))) -> (Membership.mem.{u1, u1} (Set.{u1} \u03b1) (Filter.{u1} \u03b1) (instMembershipSetFilter.{u1} \u03b1) s (nhdsWithin.{u1} \u03b1 _inst_2 x (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) x)))) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) s)\nCase conversion may be inaccurate. Consider using '#align is_closed.Icc_subset_of_forall_mem_nhds_within IsClosed.Icc_subset_of_forall_mem_nhdsWithin\u2093'. -/\n/-- A \"continuous induction principle\" for a closed interval: if a set `s` meets `[a, b]`\non a closed subset, contains `a`, and for any `x \u2208 s \u2229 [a, b)` the set `s` includes some open\nneighborhood of `x` within `(x, +\u221e)`, then `[a, b] \u2286 s`. -/\ntheorem IsClosed.Icc_subset_of_forall_mem_nhdsWithin {a b : \u03b1} {s : Set \u03b1}\n    (hs : IsClosed (s \u2229 Icc a b)) (ha : a \u2208 s) (hgt : \u2200 x \u2208 s \u2229 Ico a b, s \u2208 \ud835\udcdd[>] x) :\n    Icc a b \u2286 s := by\n  apply hs.Icc_subset_of_forall_exists_gt ha\n  rintro x \u27e8hxs, hxab\u27e9 y hyxb\n  have : s \u2229 Ioc x y \u2208 \ud835\udcdd[>] x :=\n    inter_mem (hgt x \u27e8hxs, hxab\u27e9) (Ioc_mem_nhdsWithin_Ioi \u27e8le_rfl, hyxb\u27e9)\n  exact (nhdsWithin_Ioi_self_neBot' \u27e8b, hxab.2\u27e9).nonempty_of_mem this\n#align is_closed.Icc_subset_of_forall_mem_nhds_within IsClosed.Icc_subset_of_forall_mem_nhdsWithin\n\n/- warning: is_preconnected_Icc_aux -> isPreconnected_Icc_aux is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {a : \u03b1} {b : \u03b1} (x : \u03b1) (y : \u03b1) (s : Set.{u1} \u03b1) (t : Set.{u1} \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) x y) -> (IsClosed.{u1} \u03b1 _inst_2 s) -> (IsClosed.{u1} \u03b1 _inst_2 t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) s)) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) y (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) t)) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) s t)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {a : \u03b1} {b : \u03b1} (x : \u03b1) (y : \u03b1) (s : Set.{u1} \u03b1) (t : Set.{u1} \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) x y) -> (IsClosed.{u1} \u03b1 _inst_2 s) -> (IsClosed.{u1} \u03b1 _inst_2 t) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t)) -> (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) x (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) s)) -> (Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) y (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) t)) -> (Set.Nonempty.{u1} \u03b1 (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) s t)))\nCase conversion may be inaccurate. Consider using '#align is_preconnected_Icc_aux isPreconnected_Icc_aux\u2093'. -/\ntheorem isPreconnected_Icc_aux (x y : \u03b1) (s t : Set \u03b1) (hxy : x \u2264 y) (hs : IsClosed s)\n    (ht : IsClosed t) (hab : Icc a b \u2286 s \u222a t) (hx : x \u2208 Icc a b \u2229 s) (hy : y \u2208 Icc a b \u2229 t) :\n    (Icc a b \u2229 (s \u2229 t)).Nonempty :=\n  by\n  have xyab : Icc x y \u2286 Icc a b := Icc_subset_Icc hx.1.1 hy.1.2\n  by_contra hst\n  suffices : Icc x y \u2286 s\n  exact hst \u27e8y, xyab <| right_mem_Icc.2 hxy, this <| right_mem_Icc.2 hxy, hy.2\u27e9\n  apply (IsClosed.inter hs isClosed_Icc).Icc_subset_of_forall_mem_nhdsWithin hx.2\n  rintro z \u27e8zs, hz\u27e9\n  have zt : z \u2208 t\u1d9c := fun zt => hst \u27e8z, xyab <| Ico_subset_Icc_self hz, zs, zt\u27e9\n  have : t\u1d9c \u2229 Ioc z y \u2208 \ud835\udcdd[>] z :=\n    by\n    rw [\u2190 nhdsWithin_Ioc_eq_nhdsWithin_Ioi hz.2]\n    exact mem_nhdsWithin.2 \u27e8t\u1d9c, ht.is_open_compl, zt, subset.refl _\u27e9\n  apply mem_of_superset this\n  have : Ioc z y \u2286 s \u222a t := fun w hw => hab (xyab \u27e8le_trans hz.1 (le_of_lt hw.1), hw.2\u27e9)\n  exact fun w \u27e8wt, wzy\u27e9 => (this wzy).elim id fun h => (wt h).elim\n#align is_preconnected_Icc_aux isPreconnected_Icc_aux\n\n#print isPreconnected_Icc /-\n/-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/\ntheorem isPreconnected_Icc : IsPreconnected (Icc a b) :=\n  isPreconnected_closed_iff.2\n    (by\n      rintro s t hs ht hab \u27e8x, hx\u27e9 \u27e8y, hy\u27e9\n      -- This used to use `wlog`, but it was causing timeouts.\n      cases le_total x y\n      \u00b7 exact isPreconnected_Icc_aux x y s t h hs ht hab hx hy\n      \u00b7 rw [inter_comm s t]\n        rw [union_comm s t] at hab\n        exact isPreconnected_Icc_aux y x t s h ht hs hab hy hx)\n#align is_preconnected_Icc isPreconnected_Icc\n-/\n\n#print isPreconnected_uIcc /-\ntheorem isPreconnected_uIcc : IsPreconnected (uIcc a b) :=\n  isPreconnected_Icc\n#align is_preconnected_uIcc isPreconnected_uIcc\n-/\n\n#print Set.OrdConnected.isPreconnected /-\ntheorem Set.OrdConnected.isPreconnected {s : Set \u03b1} (h : s.OrdConnected) : IsPreconnected s :=\n  isPreconnected_of_forall_pair fun x hx y hy =>\n    \u27e8uIcc x y, h.uIcc_subset hx hy, left_mem_uIcc, right_mem_uIcc, isPreconnected_uIcc\u27e9\n#align set.ord_connected.is_preconnected Set.OrdConnected.isPreconnected\n-/\n\n#print isPreconnected_iff_ordConnected /-\ntheorem isPreconnected_iff_ordConnected {s : Set \u03b1} : IsPreconnected s \u2194 OrdConnected s :=\n  \u27e8IsPreconnected.ordConnected, Set.OrdConnected.isPreconnected\u27e9\n#align is_preconnected_iff_ord_connected isPreconnected_iff_ordConnected\n-/\n\n#print isPreconnected_Ici /-\ntheorem isPreconnected_Ici : IsPreconnected (Ici a) :=\n  ordConnected_Ici.IsPreconnected\n#align is_preconnected_Ici isPreconnected_Ici\n-/\n\n#print isPreconnected_Iic /-\ntheorem isPreconnected_Iic : IsPreconnected (Iic a) :=\n  ordConnected_Iic.IsPreconnected\n#align is_preconnected_Iic isPreconnected_Iic\n-/\n\n#print isPreconnected_Iio /-\ntheorem isPreconnected_Iio : IsPreconnected (Iio a) :=\n  ordConnected_Iio.IsPreconnected\n#align is_preconnected_Iio isPreconnected_Iio\n-/\n\n#print isPreconnected_Ioi /-\ntheorem isPreconnected_Ioi : IsPreconnected (Ioi a) :=\n  ordConnected_Ioi.IsPreconnected\n#align is_preconnected_Ioi isPreconnected_Ioi\n-/\n\n#print isPreconnected_Ioo /-\ntheorem isPreconnected_Ioo : IsPreconnected (Ioo a b) :=\n  ordConnected_Ioo.IsPreconnected\n#align is_preconnected_Ioo isPreconnected_Ioo\n-/\n\n#print isPreconnected_Ioc /-\ntheorem isPreconnected_Ioc : IsPreconnected (Ioc a b) :=\n  ordConnected_Ioc.IsPreconnected\n#align is_preconnected_Ioc isPreconnected_Ioc\n-/\n\n#print isPreconnected_Ico /-\ntheorem isPreconnected_Ico : IsPreconnected (Ico a b) :=\n  ordConnected_Ico.IsPreconnected\n#align is_preconnected_Ico isPreconnected_Ico\n-/\n\n#print isConnected_Ici /-\ntheorem isConnected_Ici : IsConnected (Ici a) :=\n  \u27e8nonempty_Ici, isPreconnected_Ici\u27e9\n#align is_connected_Ici isConnected_Ici\n-/\n\n#print isConnected_Iic /-\ntheorem isConnected_Iic : IsConnected (Iic a) :=\n  \u27e8nonempty_Iic, isPreconnected_Iic\u27e9\n#align is_connected_Iic isConnected_Iic\n-/\n\n#print isConnected_Ioi /-\ntheorem isConnected_Ioi [NoMaxOrder \u03b1] : IsConnected (Ioi a) :=\n  \u27e8nonempty_Ioi, isPreconnected_Ioi\u27e9\n#align is_connected_Ioi isConnected_Ioi\n-/\n\n#print isConnected_Iio /-\ntheorem isConnected_Iio [NoMinOrder \u03b1] : IsConnected (Iio a) :=\n  \u27e8nonempty_Iio, isPreconnected_Iio\u27e9\n#align is_connected_Iio isConnected_Iio\n-/\n\n#print isConnected_Icc /-\ntheorem isConnected_Icc (h : a \u2264 b) : IsConnected (Icc a b) :=\n  \u27e8nonempty_Icc.2 h, isPreconnected_Icc\u27e9\n#align is_connected_Icc isConnected_Icc\n-/\n\n#print isConnected_Ioo /-\ntheorem isConnected_Ioo (h : a < b) : IsConnected (Ioo a b) :=\n  \u27e8nonempty_Ioo.2 h, isPreconnected_Ioo\u27e9\n#align is_connected_Ioo isConnected_Ioo\n-/\n\n#print isConnected_Ioc /-\ntheorem isConnected_Ioc (h : a < b) : IsConnected (Ioc a b) :=\n  \u27e8nonempty_Ioc.2 h, isPreconnected_Ioc\u27e9\n#align is_connected_Ioc isConnected_Ioc\n-/\n\n#print isConnected_Ico /-\ntheorem isConnected_Ico (h : a < b) : IsConnected (Ico a b) :=\n  \u27e8nonempty_Ico.2 h, isPreconnected_Ico\u27e9\n#align is_connected_Ico isConnected_Ico\n-/\n\n#print ordered_connected_space /-\ninstance (priority := 100) ordered_connected_space : PreconnectedSpace \u03b1 :=\n  \u27e8ordConnected_univ.IsPreconnected\u27e9\n#align ordered_connected_space ordered_connected_space\n-/\n\n/- warning: set_of_is_preconnected_eq_of_ordered -> setOf_isPreconnected_eq_of_ordered is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))], Eq.{succ u1} (Set.{u1} (Set.{u1} \u03b1)) (setOf.{u1} (Set.{u1} \u03b1) (fun (s : Set.{u1} \u03b1) => IsPreconnected.{u1} \u03b1 _inst_2 s)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.hasUnion.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ici.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iic.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasInsert.{u1} (Set.{u1} \u03b1)) (Set.univ.{u1} \u03b1) (Singleton.singleton.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.hasSingleton.{u1} (Set.{u1} \u03b1)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))], Eq.{succ u1} (Set.{u1} (Set.{u1} \u03b1)) (setOf.{u1} (Set.{u1} \u03b1) (fun (s : Set.{u1} \u03b1) => IsPreconnected.{u1} \u03b1 _inst_2 s)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) (Prod.{u1, u1} \u03b1 \u03b1) (Function.uncurry.{u1, u1, u1} \u03b1 \u03b1 (Set.{u1} \u03b1) (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))))) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Union.union.{u1} (Set.{u1} (Set.{u1} \u03b1)) (Set.instUnionSet.{u1} (Set.{u1} \u03b1)) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ici.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Ioi.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iic.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Set.range.{u1, succ u1} (Set.{u1} \u03b1) \u03b1 (Set.Iio.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))))) (Insert.insert.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instInsertSet.{u1} (Set.{u1} \u03b1)) (Set.univ.{u1} \u03b1) (Singleton.singleton.{u1, u1} (Set.{u1} \u03b1) (Set.{u1} (Set.{u1} \u03b1)) (Set.instSingletonSet.{u1} (Set.{u1} \u03b1)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))))))\nCase conversion may be inaccurate. Consider using '#align set_of_is_preconnected_eq_of_ordered setOf_isPreconnected_eq_of_ordered\u2093'. -/\n/-- In a dense conditionally complete linear order, the set of preconnected sets is exactly\nthe set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-\u221e, +\u221e)`,\nor `\u2205`. Though one can represent `\u2205` as `(Inf s, Inf s)`, we include it into the list of\npossible cases to improve readability. -/\ntheorem setOf_isPreconnected_eq_of_ordered :\n    { s : Set \u03b1 | IsPreconnected s } =-- bounded intervals\n                range\n                (uncurry Icc) \u222a\n              range (uncurry Ico) \u222a\n            range (uncurry Ioc) \u222a\n          range (uncurry Ioo) \u222a\n        (-- unbounded intervals and `univ`\n                  range\n                  Ici \u222a\n                range Ioi \u222a\n              range Iic \u222a\n            range Iio \u222a\n          {univ, \u2205}) :=\n  by\n  refine' subset.antisymm setOf_isPreconnected_subset_of_ordered _\n  simp only [subset_def, -mem_range, forall_range_iff, uncurry, or_imp, forall_and, mem_union,\n    mem_set_of_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true_iff,\n    isPreconnected_Icc, isPreconnected_Ico, isPreconnected_Ioc, isPreconnected_Ioo,\n    isPreconnected_Ioi, isPreconnected_Iio, isPreconnected_Ici, isPreconnected_Iic,\n    is_preconnected_univ, isPreconnected_empty]\n#align set_of_is_preconnected_eq_of_ordered setOf_isPreconnected_eq_of_ordered\n\n/-!\n### Intermediate Value Theorem on an interval\n\nIn this section we prove several versions of the Intermediate Value Theorem for a function\ncontinuous on an interval.\n-/\n\n\nvariable {\u03b4 : Type _} [LinearOrder \u03b4] [TopologicalSpace \u03b4] [OrderClosedTopology \u03b4]\n\n/- warning: intermediate_value_Icc -> intermediate_value_Icc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Icc.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f a) (f b)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Icc.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f a) (f b)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Icc intermediate_value_Icc\u2093'. -/\n/-- **Intermediate Value Theorem** for continuous functions on closed intervals, case\n`f a \u2264 t \u2264 f b`.-/\ntheorem intermediate_value_Icc {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : ContinuousOn f (Icc a b)) :\n    Icc (f a) (f b) \u2286 f '' Icc a b :=\n  isPreconnected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf\n#align intermediate_value_Icc intermediate_value_Icc\n\n/- warning: intermediate_value_Icc' -> intermediate_value_Icc' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Icc.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f b) (f a)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Icc.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f b) (f a)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Icc' intermediate_value_Icc'\u2093'. -/\n/-- **Intermediate Value Theorem** for continuous functions on closed intervals, case\n`f a \u2265 t \u2265 f b`.-/\ntheorem intermediate_value_Icc' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4}\n    (hf : ContinuousOn f (Icc a b)) : Icc (f b) (f a) \u2286 f '' Icc a b :=\n  isPreconnected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf\n#align intermediate_value_Icc' intermediate_value_Icc'\n\n/- warning: intermediate_value_uIcc -> intermediate_value_uIcc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1} {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.uIcc.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.uIcc.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9) (f a) (f b)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.uIcc.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)) a b)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1} {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.uIcc.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.uIcc.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)) (f a) (f b)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.uIcc.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)) a b)))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_uIcc intermediate_value_uIcc\u2093'. -/\n/-- **Intermediate Value Theorem** for continuous functions on closed intervals, unordered case. -/\ntheorem intermediate_value_uIcc {a b : \u03b1} {f : \u03b1 \u2192 \u03b4} (hf : ContinuousOn f (uIcc a b)) :\n    uIcc (f a) (f b) \u2286 f '' uIcc a b := by\n  cases le_total (f a) (f b) <;> simp [*, is_preconnected_uIcc.intermediate_value]\n#align intermediate_value_uIcc intermediate_value_uIcc\n\n/- warning: intermediate_value_Ico -> intermediate_value_Ico is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Ico.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f a) (f b)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Ico.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f a) (f b)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Ico.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Ico intermediate_value_Ico\u2093'. -/\ntheorem intermediate_value_Ico {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : ContinuousOn f (Icc a b)) :\n    Ico (f a) (f b) \u2286 f '' Ico a b :=\n  Or.elim (eq_or_lt_of_le hab) (fun he y h => absurd h.2 (not_lt_of_le (he \u25b8 h.1))) fun hlt =>\n    @IsPreconnected.intermediate_value_Ico _ _ _ _ _ _ _ isPreconnected_Ico _ _ \u27e8refl a, hlt\u27e9\n      (right_nhdsWithin_Ico_neBot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _\n      ((hf.ContinuousWithinAt \u27e8hab, refl b\u27e9).mono Ico_subset_Icc_self)\n#align intermediate_value_Ico intermediate_value_Ico\n\n/- warning: intermediate_value_Ico' -> intermediate_value_Ico' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Ioc.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f b) (f a)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Ico.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Ioc.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f b) (f a)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Ico.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Ico' intermediate_value_Ico'\u2093'. -/\ntheorem intermediate_value_Ico' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4}\n    (hf : ContinuousOn f (Icc a b)) : Ioc (f b) (f a) \u2286 f '' Ico a b :=\n  Or.elim (eq_or_lt_of_le hab) (fun he y h => absurd h.1 (not_lt_of_le (he \u25b8 h.2))) fun hlt =>\n    @IsPreconnected.intermediate_value_Ioc _ _ _ _ _ _ _ isPreconnected_Ico _ _ \u27e8refl a, hlt\u27e9\n      (right_nhdsWithin_Ico_neBot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _\n      ((hf.ContinuousWithinAt \u27e8hab, refl b\u27e9).mono Ico_subset_Icc_self)\n#align intermediate_value_Ico' intermediate_value_Ico'\n\n/- warning: intermediate_value_Ioc -> intermediate_value_Ioc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Ioc.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f a) (f b)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Ioc.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f a) (f b)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Ioc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Ioc intermediate_value_Ioc\u2093'. -/\ntheorem intermediate_value_Ioc {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : ContinuousOn f (Icc a b)) :\n    Ioc (f a) (f b) \u2286 f '' Ioc a b :=\n  Or.elim (eq_or_lt_of_le hab) (fun he y h => absurd h.2 (not_le_of_lt (he \u25b8 h.1))) fun hlt =>\n    @IsPreconnected.intermediate_value_Ioc _ _ _ _ _ _ _ isPreconnected_Ioc _ _ \u27e8hlt, refl b\u27e9\n      (left_nhdsWithin_Ioc_neBot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _\n      ((hf.ContinuousWithinAt \u27e8refl a, hab\u27e9).mono Ioc_subset_Icc_self)\n#align intermediate_value_Ioc intermediate_value_Ioc\n\n/- warning: intermediate_value_Ioc' -> intermediate_value_Ioc' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Ico.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f b) (f a)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Ico.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f b) (f a)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Ioc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Ioc' intermediate_value_Ioc'\u2093'. -/\ntheorem intermediate_value_Ioc' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4}\n    (hf : ContinuousOn f (Icc a b)) : Ico (f b) (f a) \u2286 f '' Ioc a b :=\n  Or.elim (eq_or_lt_of_le hab) (fun he y h => absurd h.1 (not_le_of_lt (he \u25b8 h.2))) fun hlt =>\n    @IsPreconnected.intermediate_value_Ico _ _ _ _ _ _ _ isPreconnected_Ioc _ _ \u27e8hlt, refl b\u27e9\n      (left_nhdsWithin_Ioc_neBot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _\n      ((hf.ContinuousWithinAt \u27e8refl a, hab\u27e9).mono Ioc_subset_Icc_self)\n#align intermediate_value_Ioc' intermediate_value_Ioc'\n\n/- warning: intermediate_value_Ioo -> intermediate_value_Ioo is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Ioo.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f a) (f b)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Ioo.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f a) (f b)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Ioo.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Ioo intermediate_value_Ioo\u2093'. -/\ntheorem intermediate_value_Ioo {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : ContinuousOn f (Icc a b)) :\n    Ioo (f a) (f b) \u2286 f '' Ioo a b :=\n  Or.elim (eq_or_lt_of_le hab) (fun he y h => absurd h.2 (not_lt_of_lt (he \u25b8 h.1))) fun hlt =>\n    @IsPreconnected.intermediate_value_Ioo _ _ _ _ _ _ _ isPreconnected_Ioo _ _\n      (left_nhdsWithin_Ioo_neBot hlt) (right_nhdsWithin_Ioo_neBot hlt) inf_le_right inf_le_right _\n      (hf.mono Ioo_subset_Icc_self) _ _\n      ((hf.ContinuousWithinAt \u27e8refl a, hab\u27e9).mono Ioo_subset_Icc_self)\n      ((hf.ContinuousWithinAt \u27e8hab, refl b\u27e9).mono Ioo_subset_Icc_self)\n#align intermediate_value_Ioo intermediate_value_Ioo\n\n/- warning: intermediate_value_Ioo' -> intermediate_value_Ioo' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u2} (Set.{u2} \u03b4) (Set.hasSubset.{u2} \u03b4) (Set.Ioo.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f b) (f a)) (Set.image.{u1, u2} \u03b1 \u03b4 f (Set.Ioo.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) a b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {a : \u03b1} {b : \u03b1}, (LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) a b) -> (forall {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f (Set.Icc.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b)) -> (HasSubset.Subset.{u1} (Set.{u1} \u03b4) (Set.instHasSubsetSet.{u1} \u03b4) (Set.Ioo.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f b) (f a)) (Set.image.{u2, u1} \u03b1 \u03b4 f (Set.Ioo.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) a b))))\nCase conversion may be inaccurate. Consider using '#align intermediate_value_Ioo' intermediate_value_Ioo'\u2093'. -/\ntheorem intermediate_value_Ioo' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4}\n    (hf : ContinuousOn f (Icc a b)) : Ioo (f b) (f a) \u2286 f '' Ioo a b :=\n  Or.elim (eq_or_lt_of_le hab) (fun he y h => absurd h.1 (not_lt_of_lt (he \u25b8 h.2))) fun hlt =>\n    @IsPreconnected.intermediate_value_Ioo _ _ _ _ _ _ _ isPreconnected_Ioo _ _\n      (right_nhdsWithin_Ioo_neBot hlt) (left_nhdsWithin_Ioo_neBot hlt) inf_le_right inf_le_right _\n      (hf.mono Ioo_subset_Icc_self) _ _\n      ((hf.ContinuousWithinAt \u27e8hab, refl b\u27e9).mono Ioo_subset_Icc_self)\n      ((hf.ContinuousWithinAt \u27e8refl a, hab\u27e9).mono Ioo_subset_Icc_self)\n#align intermediate_value_Ioo' intermediate_value_Ioo'\n\n/- warning: continuous_on.surj_on_Icc -> ContinuousOn.surjOn_Icc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {s : Set.{u1} \u03b1} [hs : Set.OrdConnected.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s] {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (forall {a : \u03b1} {b : \u03b1}, (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) b s) -> (Set.SurjOn.{u1, u2} \u03b1 \u03b4 f s (Set.Icc.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))) (f a) (f b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {s : Set.{u2} \u03b1} [hs : Set.OrdConnected.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) s] {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (forall {a : \u03b1} {b : \u03b1}, (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) -> (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) b s) -> (Set.SurjOn.{u2, u1} \u03b1 \u03b4 f s (Set.Icc.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))) (f a) (f b))))\nCase conversion may be inaccurate. Consider using '#align continuous_on.surj_on_Icc ContinuousOn.surjOn_Icc\u2093'. -/\n/-- **Intermediate value theorem**: if `f` is continuous on an order-connected set `s` and `a`,\n`b` are two points of this set, then `f` sends `s` to a superset of `Icc (f x) (f y)`. -/\ntheorem ContinuousOn.surjOn_Icc {s : Set \u03b1} [hs : OrdConnected s] {f : \u03b1 \u2192 \u03b4}\n    (hf : ContinuousOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) : SurjOn f s (Icc (f a) (f b)) :=\n  hs.IsPreconnected.intermediate_value ha hb hf\n#align continuous_on.surj_on_Icc ContinuousOn.surjOn_Icc\n\n/- warning: continuous_on.surj_on_uIcc -> ContinuousOn.surjOn_uIcc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {s : Set.{u1} \u03b1} [hs : Set.OrdConnected.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s] {f : \u03b1 -> \u03b4}, (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (forall {a : \u03b1} {b : \u03b1}, (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) b s) -> (Set.SurjOn.{u1, u2} \u03b1 \u03b4 f s (Set.uIcc.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9) (f a) (f b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {s : Set.{u2} \u03b1} [hs : Set.OrdConnected.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) s] {f : \u03b1 -> \u03b4}, (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (forall {a : \u03b1} {b : \u03b1}, (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) -> (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) b s) -> (Set.SurjOn.{u2, u1} \u03b1 \u03b4 f s (Set.uIcc.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)) (f a) (f b))))\nCase conversion may be inaccurate. Consider using '#align continuous_on.surj_on_uIcc ContinuousOn.surjOn_uIcc\u2093'. -/\n/-- **Intermediate value theorem**: if `f` is continuous on an order-connected set `s` and `a`,\n`b` are two points of this set, then `f` sends `s` to a superset of `[f x, f y]`. -/\ntheorem ContinuousOn.surjOn_uIcc {s : Set \u03b1} [hs : OrdConnected s] {f : \u03b1 \u2192 \u03b4}\n    (hf : ContinuousOn f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) : SurjOn f s (uIcc (f a) (f b)) :=\n  by cases' le_total (f a) (f b) with hab hab <;> simp [hf.surj_on_Icc, *]\n#align continuous_on.surj_on_uIcc ContinuousOn.surjOn_uIcc\n\n/- warning: continuous.surjective -> Continuous.surjective is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {f : \u03b1 -> \u03b4}, (Continuous.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f) -> (Filter.Tendsto.{u1, u2} \u03b1 \u03b4 f (Filter.atTop.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) (Filter.atTop.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Filter.Tendsto.{u1, u2} \u03b1 \u03b4 f (Filter.atBot.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) (Filter.atBot.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Function.Surjective.{succ u1, succ u2} \u03b1 \u03b4 f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {f : \u03b1 -> \u03b4}, (Continuous.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f) -> (Filter.Tendsto.{u2, u1} \u03b1 \u03b4 f (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) (Filter.atTop.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Filter.Tendsto.{u2, u1} \u03b1 \u03b4 f (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) (Filter.atBot.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Function.Surjective.{succ u2, succ u1} \u03b1 \u03b4 f)\nCase conversion may be inaccurate. Consider using '#align continuous.surjective Continuous.surjective\u2093'. -/\n/-- A continuous function which tendsto `at_top` `at_top` and to `at_bot` `at_bot` is surjective. -/\ntheorem Continuous.surjective {f : \u03b1 \u2192 \u03b4} (hf : Continuous f) (h_top : Tendsto f atTop atTop)\n    (h_bot : Tendsto f atBot atBot) : Function.Surjective f := fun p =>\n  mem_range_of_exists_le_of_exists_ge hf (h_bot.Eventually (eventually_le_atBot p)).exists\n    (h_top.Eventually (eventually_ge_atTop p)).exists\n#align continuous.surjective Continuous.surjective\n\n/- warning: continuous.surjective' -> Continuous.surjective' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {f : \u03b1 -> \u03b4}, (Continuous.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f) -> (Filter.Tendsto.{u1, u2} \u03b1 \u03b4 f (Filter.atBot.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) (Filter.atTop.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Filter.Tendsto.{u1, u2} \u03b1 \u03b4 f (Filter.atTop.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))) (Filter.atBot.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Function.Surjective.{succ u1, succ u2} \u03b1 \u03b4 f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {f : \u03b1 -> \u03b4}, (Continuous.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f) -> (Filter.Tendsto.{u2, u1} \u03b1 \u03b4 f (Filter.atBot.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) (Filter.atTop.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Filter.Tendsto.{u2, u1} \u03b1 \u03b4 f (Filter.atTop.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))) (Filter.atBot.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Function.Surjective.{succ u2, succ u1} \u03b1 \u03b4 f)\nCase conversion may be inaccurate. Consider using '#align continuous.surjective' Continuous.surjective'\u2093'. -/\n/-- A continuous function which tendsto `at_bot` `at_top` and to `at_top` `at_bot` is surjective. -/\ntheorem Continuous.surjective' {f : \u03b1 \u2192 \u03b4} (hf : Continuous f) (h_top : Tendsto f atBot atTop)\n    (h_bot : Tendsto f atTop atBot) : Function.Surjective f :=\n  @Continuous.surjective \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ _ _ hf h_top h_bot\n#align continuous.surjective' Continuous.surjective'\n\n/- warning: continuous_on.surj_on_of_tendsto -> ContinuousOn.surjOn_of_tendsto is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {f : \u03b1 -> \u03b4} {s : Set.{u1} \u03b1} [_inst_12 : Set.OrdConnected.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s], (Set.Nonempty.{u1} \u03b1 s) -> (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (Filter.Tendsto.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b4 (fun (x : coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) => f ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeBase.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeSubtype.{succ u1} \u03b1 (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))))) x)) (Filter.atBot.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) (Subtype.preorder.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))) (Filter.atBot.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Filter.Tendsto.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b4 (fun (x : coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) => f ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeBase.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeSubtype.{succ u1} \u03b1 (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))))) x)) (Filter.atTop.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) (Subtype.preorder.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))) (Filter.atTop.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Set.SurjOn.{u1, u2} \u03b1 \u03b4 f s (Set.univ.{u2} \u03b4))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {f : \u03b1 -> \u03b4} {s : Set.{u2} \u03b1} [_inst_12 : Set.OrdConnected.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) s], (Set.Nonempty.{u2} \u03b1 s) -> (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (Filter.Tendsto.{u2, u1} (Set.Elem.{u2} \u03b1 s) \u03b4 (fun (x : Set.Elem.{u2} \u03b1 s) => f (Subtype.val.{succ u2} \u03b1 (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) x)) (Filter.atBot.{u2} (Set.Elem.{u2} \u03b1 s) (Subtype.preorder.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s))) (Filter.atBot.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Filter.Tendsto.{u2, u1} (Set.Elem.{u2} \u03b1 s) \u03b4 (fun (x : Set.Elem.{u2} \u03b1 s) => f (Subtype.val.{succ u2} \u03b1 (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) x)) (Filter.atTop.{u2} (Set.Elem.{u2} \u03b1 s) (Subtype.preorder.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s))) (Filter.atTop.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Set.SurjOn.{u2, u1} \u03b1 \u03b4 f s (Set.univ.{u1} \u03b4))\nCase conversion may be inaccurate. Consider using '#align continuous_on.surj_on_of_tendsto ContinuousOn.surjOn_of_tendsto\u2093'. -/\n/-- If a function `f : \u03b1 \u2192 \u03b2` is continuous on a nonempty interval `s`, its restriction to `s`\ntends to `at_bot : filter \u03b2` along `at_bot : filter \u21a5s` and tends to `at_top : filter \u03b2` along\n`at_top : filter \u21a5s`, then the restriction of `f` to `s` is surjective. We formulate the\nconclusion as `surj_on f s univ`. -/\ntheorem ContinuousOn.surjOn_of_tendsto {f : \u03b1 \u2192 \u03b4} {s : Set \u03b1} [OrdConnected s] (hs : s.Nonempty)\n    (hf : ContinuousOn f s) (hbot : Tendsto (fun x : s => f x) atBot atBot)\n    (htop : Tendsto (fun x : s => f x) atTop atTop) : SurjOn f s univ :=\n  haveI := Classical.inhabited_of_nonempty hs.to_subtype\n  surj_on_iff_surjective.2 <| (continuousOn_iff_continuous_restrict.1 hf).Surjective htop hbot\n#align continuous_on.surj_on_of_tendsto ContinuousOn.surjOn_of_tendsto\n\n/- warning: continuous_on.surj_on_of_tendsto' -> ContinuousOn.surjOn_of_tendsto' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : ConditionallyCompleteLinearOrder.{u1} \u03b1] [_inst_2 : TopologicalSpace.{u1} \u03b1] [_inst_3 : OrderTopology.{u1} \u03b1 _inst_2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))))] {\u03b4 : Type.{u2}} [_inst_9 : LinearOrder.{u2} \u03b4] [_inst_10 : TopologicalSpace.{u2} \u03b4] [_inst_11 : OrderClosedTopology.{u2} \u03b4 _inst_10 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9))))] {f : \u03b1 -> \u03b4} {s : Set.{u1} \u03b1} [_inst_12 : Set.OrdConnected.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) s], (Set.Nonempty.{u1} \u03b1 s) -> (ContinuousOn.{u1, u2} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (Filter.Tendsto.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b4 (fun (x : coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) => f ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeBase.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeSubtype.{succ u1} \u03b1 (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))))) x)) (Filter.atBot.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) (Subtype.preorder.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))) (Filter.atTop.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Filter.Tendsto.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b4 (fun (x : coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) => f ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeBase.{succ u1, succ u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b1 (coeSubtype.{succ u1} \u03b1 (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))))) x)) (Filter.atTop.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) (Subtype.preorder.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (ConditionallyCompleteLattice.toLattice.{u1} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u1} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s))) (Filter.atBot.{u2} \u03b4 (PartialOrder.toPreorder.{u2} \u03b4 (SemilatticeInf.toPartialOrder.{u2} \u03b4 (Lattice.toSemilatticeInf.{u2} \u03b4 (LinearOrder.toLattice.{u2} \u03b4 _inst_9)))))) -> (Set.SurjOn.{u1, u2} \u03b1 \u03b4 f s (Set.univ.{u2} \u03b4))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : ConditionallyCompleteLinearOrder.{u2} \u03b1] [_inst_2 : TopologicalSpace.{u2} \u03b1] [_inst_3 : OrderTopology.{u2} \u03b1 _inst_2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1)))))] [_inst_8 : DenselyOrdered.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))))] {\u03b4 : Type.{u1}} [_inst_9 : LinearOrder.{u1} \u03b4] [_inst_10 : TopologicalSpace.{u1} \u03b4] [_inst_11 : OrderClosedTopology.{u1} \u03b4 _inst_10 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9)))))] {f : \u03b1 -> \u03b4} {s : Set.{u2} \u03b1} [_inst_12 : Set.OrdConnected.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) s], (Set.Nonempty.{u2} \u03b1 s) -> (ContinuousOn.{u2, u1} \u03b1 \u03b4 _inst_2 _inst_10 f s) -> (Filter.Tendsto.{u2, u1} (Set.Elem.{u2} \u03b1 s) \u03b4 (fun (x : Set.Elem.{u2} \u03b1 s) => f (Subtype.val.{succ u2} \u03b1 (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) x)) (Filter.atBot.{u2} (Set.Elem.{u2} \u03b1 s) (Subtype.preorder.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s))) (Filter.atTop.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Filter.Tendsto.{u2, u1} (Set.Elem.{u2} \u03b1 s) \u03b4 (fun (x : Set.Elem.{u2} \u03b1 s) => f (Subtype.val.{succ u2} \u03b1 (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) x)) (Filter.atTop.{u2} (Set.Elem.{u2} \u03b1 s) (Subtype.preorder.{u2} \u03b1 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (ConditionallyCompleteLattice.toLattice.{u2} \u03b1 (ConditionallyCompleteLinearOrder.toConditionallyCompleteLattice.{u2} \u03b1 _inst_1))))) (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s))) (Filter.atBot.{u1} \u03b4 (PartialOrder.toPreorder.{u1} \u03b4 (SemilatticeInf.toPartialOrder.{u1} \u03b4 (Lattice.toSemilatticeInf.{u1} \u03b4 (DistribLattice.toLattice.{u1} \u03b4 (instDistribLattice.{u1} \u03b4 _inst_9))))))) -> (Set.SurjOn.{u2, u1} \u03b1 \u03b4 f s (Set.univ.{u1} \u03b4))\nCase conversion may be inaccurate. Consider using '#align continuous_on.surj_on_of_tendsto' ContinuousOn.surjOn_of_tendsto'\u2093'. -/\n/-- If a function `f : \u03b1 \u2192 \u03b2` is continuous on a nonempty interval `s`, its restriction to `s`\ntends to `at_top : filter \u03b2` along `at_bot : filter \u21a5s` and tends to `at_bot : filter \u03b2` along\n`at_top : filter \u21a5s`, then the restriction of `f` to `s` is surjective. We formulate the\nconclusion as `surj_on f s univ`. -/\ntheorem ContinuousOn.surjOn_of_tendsto' {f : \u03b1 \u2192 \u03b4} {s : Set \u03b1} [OrdConnected s] (hs : s.Nonempty)\n    (hf : ContinuousOn f s) (hbot : Tendsto (fun x : s => f x) atBot atTop)\n    (htop : Tendsto (fun x : s => f x) atTop atBot) : SurjOn f s univ :=\n  @ContinuousOn.surjOn_of_tendsto \u03b1 _ _ _ _ \u03b4\u1d52\u1d48 _ _ _ _ _ _ hs hf hbot htop\n#align continuous_on.surj_on_of_tendsto' ContinuousOn.surjOn_of_tendsto'\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/Algebra/Order/IntermediateValue.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.709127028320894}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Floris van Doorn, Gabriel Ebner, Yury Kudryashov\n-/\nimport data.nat.enat\nimport order.conditionally_complete_lattice\n\n/-!\n# Conditionally complete linear order structure on `\u2115`\n\nIn this file we\n\n* define a `conditionally_complete_linear_order_bot` structure on `\u2115`;\n* define a `complete_linear_order` structure on `enat`;\n* prove a few lemmas about `supr`/`infi`/`set.Union`/`set.Inter` and natural numbers.\n-/\n\nopen set\n\nnamespace nat\n\nopen_locale classical\n\nnoncomputable instance : has_Inf \u2115 :=\n\u27e8\u03bbs, if h : \u2203n, n \u2208 s then @nat.find (\u03bbn, n \u2208 s) _ h else 0\u27e9\n\nnoncomputable instance : has_Sup \u2115 :=\n\u27e8\u03bbs, if h : \u2203n, \u2200a\u2208s, a \u2264 n then @nat.find (\u03bbn, \u2200a\u2208s, a \u2264 n) _ h else 0\u27e9\n\nlemma Inf_def {s : set \u2115} (h : s.nonempty) : Inf s = @nat.find (\u03bbn, n \u2208 s) _ h :=\ndif_pos _\n\nlemma Sup_def {s : set \u2115} (h : \u2203n, \u2200a\u2208s, a \u2264 n) :\n  Sup s = @nat.find (\u03bbn, \u2200a\u2208s, a \u2264 n) _ h :=\ndif_pos _\n\n@[simp] lemma Inf_eq_zero {s : set \u2115} : Inf s = 0 \u2194 0 \u2208 s \u2228 s = \u2205 :=\nbegin\n  cases eq_empty_or_nonempty s,\n  { subst h, simp only [or_true, eq_self_iff_true, iff_true, Inf, has_Inf.Inf,\n      mem_empty_eq, exists_false, dif_neg, not_false_iff] },\n  { have := ne_empty_iff_nonempty.mpr h,\n    simp only [this, or_false, nat.Inf_def, h, nat.find_eq_zero] }\nend\n\n@[simp] lemma Inf_empty : Inf \u2205 = 0 :=\nby { rw Inf_eq_zero, right, refl }\n\nlemma Inf_mem {s : set \u2115} (h : s.nonempty) : Inf s \u2208 s :=\nby { rw [nat.Inf_def h], exact nat.find_spec h }\n\nlemma not_mem_of_lt_Inf {s : set \u2115} {m : \u2115} (hm : m < Inf s) : m \u2209 s :=\nbegin\n  cases eq_empty_or_nonempty s,\n  { subst h, apply not_mem_empty },\n  { rw [nat.Inf_def h] at hm, exact nat.find_min h hm }\nend\n\nprotected lemma Inf_le {s : set \u2115} {m : \u2115} (hm : m \u2208 s) : Inf s \u2264 m :=\nby { rw [nat.Inf_def \u27e8m, hm\u27e9], exact nat.find_min' \u27e8m, hm\u27e9 hm }\n\nlemma nonempty_of_pos_Inf {s : set \u2115} (h : 0 < Inf s) : s.nonempty :=\nbegin\n  by_contradiction contra, rw set.not_nonempty_iff_eq_empty at contra,\n  have h' : Inf s \u2260 0, { exact ne_of_gt h, }, apply h',\n  rw nat.Inf_eq_zero, right, assumption,\nend\n\nlemma nonempty_of_Inf_eq_succ {s : set \u2115} {k : \u2115} (h : Inf s = k + 1) : s.nonempty :=\nnonempty_of_pos_Inf (h.symm \u25b8 (succ_pos k) : Inf s > 0)\n\nlemma eq_Ici_of_nonempty_of_upward_closed {s : set \u2115} (hs : s.nonempty)\n  (hs' : \u2200 (k\u2081 k\u2082 : \u2115), k\u2081 \u2264 k\u2082 \u2192 k\u2081 \u2208 s \u2192 k\u2082 \u2208 s) : s = Ici (Inf s) :=\next (\u03bb n, \u27e8\u03bb H, nat.Inf_le H, \u03bb H, hs' (Inf s) n H (Inf_mem hs)\u27e9)\n\nlemma Inf_upward_closed_eq_succ_iff {s : set \u2115}\n  (hs : \u2200 (k\u2081 k\u2082 : \u2115), k\u2081 \u2264 k\u2082 \u2192 k\u2081 \u2208 s \u2192 k\u2082 \u2208 s) (k : \u2115) :\n  Inf s = k + 1 \u2194 k + 1 \u2208 s \u2227 k \u2209 s :=\nbegin\n  split,\n  { intro H,\n    rw [eq_Ici_of_nonempty_of_upward_closed (nonempty_of_Inf_eq_succ H) hs, H, mem_Ici, mem_Ici],\n    exact \u27e8le_refl _, k.not_succ_le_self\u27e9, },\n  { rintro \u27e8H, H'\u27e9,\n    rw [Inf_def (\u27e8_, H\u27e9 : s.nonempty), find_eq_iff],\n    exact \u27e8H, \u03bb n hnk hns, H' $ hs n k (lt_succ_iff.mp hnk) hns\u27e9, },\nend\n\n/-- This instance is necessary, otherwise the lattice operations would be derived via\nconditionally_complete_linear_order_bot and marked as noncomputable. -/\ninstance : lattice \u2115 := lattice_of_linear_order\n\nnoncomputable instance : conditionally_complete_linear_order_bot \u2115 :=\n{ Sup := Sup, Inf := Inf,\n  le_cSup    := assume s a hb ha, by rw [Sup_def hb]; revert a ha; exact @nat.find_spec _ _ hb,\n  cSup_le    := assume s a hs ha, by rw [Sup_def \u27e8a, ha\u27e9]; exact nat.find_min' _ ha,\n  le_cInf    := assume s a hs hb,\n    by rw [Inf_def hs]; exact hb (@nat.find_spec (\u03bbn, n \u2208 s) _ _),\n  cInf_le    := assume s a hb ha, by rw [Inf_def \u27e8a, ha\u27e9]; exact nat.find_min' _ ha,\n  cSup_empty :=\n  begin\n    simp only [Sup_def, set.mem_empty_eq, forall_const, forall_prop_of_false, not_false_iff,\n      exists_const],\n    apply bot_unique (nat.find_min' _ _),\n    trivial\n  end,\n  .. (infer_instance : order_bot \u2115), .. (lattice_of_linear_order : lattice \u2115),\n  .. (infer_instance : linear_order \u2115) }\n\nlemma Inf_add {n : \u2115} {p : \u2115 \u2192 Prop} (hn : n \u2264 Inf {m | p m}) :\n  Inf {m | p (m + n)} + n = Inf {m | p m} :=\nbegin\n  obtain h | \u27e8m, hm\u27e9 := {m | p (m + n)}.eq_empty_or_nonempty,\n  { rw [h, nat.Inf_empty, zero_add],\n    obtain hnp | hnp := hn.eq_or_lt,\n    { exact hnp },\n    suffices hp : p (Inf {m | p m} - n + n),\n    { exact (h.subset hp).elim },\n    rw tsub_add_cancel_of_le hn,\n    exact Inf_mem (nonempty_of_pos_Inf $ n.zero_le.trans_lt hnp) },\n  { have hp : \u2203 n, n \u2208 {m | p m} := \u27e8_, hm\u27e9,\n    rw [nat.Inf_def \u27e8m, hm\u27e9, nat.Inf_def hp],\n    rw [nat.Inf_def hp] at hn,\n    exact find_add hn }\nend\n\n\n\nsection\n\nvariables {\u03b1 : Type*} [complete_lattice \u03b1]\n\nlemma supr_lt_succ (u : \u2115 \u2192 \u03b1) (n : \u2115) : (\u2a06 k < n + 1, u k) = (\u2a06 k < n, u k) \u2294 u n :=\nby simp [nat.lt_succ_iff_lt_or_eq, supr_or, supr_sup_eq]\n\nlemma supr_lt_succ' (u : \u2115 \u2192 \u03b1) (n : \u2115) : (\u2a06 k < n + 1, u k) = u 0 \u2294 (\u2a06 k < n, u (k + 1)) :=\nby { rw \u2190 sup_supr_nat_succ, simp }\n\nlemma infi_lt_succ (u : \u2115 \u2192 \u03b1) (n : \u2115) : (\u2a05 k < n + 1, u k) = (\u2a05 k < n, u k) \u2293 u n :=\n@supr_lt_succ (order_dual \u03b1) _ _ _\n\nlemma infi_lt_succ' (u : \u2115 \u2192 \u03b1) (n : \u2115) : (\u2a05 k < n + 1, u k) = u 0 \u2293 (\u2a05 k < n, u (k + 1)) :=\n@supr_lt_succ' (order_dual \u03b1) _ _ _\n\nend\n\nend nat\n\nnamespace set\n\nvariable {\u03b1 : Type*}\n\nlemma bUnion_lt_succ (u : \u2115 \u2192 set \u03b1) (n : \u2115) : (\u22c3 k < n + 1, u k) = (\u22c3 k < n, u k) \u222a u n :=\nnat.supr_lt_succ u n\n\nlemma bUnion_lt_succ' (u : \u2115 \u2192 set \u03b1) (n : \u2115) : (\u22c3 k < n + 1, u k) = u 0 \u222a (\u22c3 k < n, u (k + 1)) :=\nnat.supr_lt_succ' u n\n\nlemma bInter_lt_succ (u : \u2115 \u2192 set \u03b1) (n : \u2115) : (\u22c2 k < n + 1, u k) = (\u22c2 k < n, u k) \u2229 u n :=\nnat.infi_lt_succ u n\n\nlemma bInter_lt_succ' (u : \u2115 \u2192 set \u03b1) (n : \u2115) : (\u22c2 k < n + 1, u k) = u 0 \u2229 (\u22c2 k < n, u (k + 1)) :=\nnat.infi_lt_succ' u n\n\nend set\n\nnamespace enat\nopen_locale classical\n\nnoncomputable instance : complete_linear_order enat :=\n{ .. enat.linear_order,\n  .. with_top_order_iso.symm.to_galois_insertion.lift_complete_lattice }\n\nend enat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768108626046, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7091270193032649}}
{"text": "-- begin header\nimport M40001.M40001_C2\n\nnamespace M40001\n-- end header\n\nuniverse u\nvariables {X V : Type u}\n\n/- Theorem\nLet $X$ be a set and let $R$ be an equivalence relation on $X$. Then any partition of $X$ can form a equivalence relation. \n-/\ntheorem partition_equiv_relation -- I have defined rs to be: def rs (A : set (set(X))) (s t : X) := \u2203 B \u2208 A, s \u2208 B \u2227 t \u2208 B\n    (C : set (set(X))) (h : partition C) : equivalence (rs C) :=\nbegin\n    split,\n-- Proving reflexivity\n    {intro x,\n    cases h with ha hb,\n    replace ha : \n        \u2203 (B : set X) (H : B \u2208 C), x \u2208 B \u2227 \u2200 (D : set X), D \u2208 C \u2192 x \u2208 D \u2192 B = D := ha x,\n    rcases ha with \u27e8ha, \u27e8hb, \u27e8hc, hd\u27e9\u27e9\u27e9,\n    use ha, use hb,\n    split,\n    repeat {assumption}\n    },\n-- Proving symmtric\n    {split,\n        {rintros x y \u27e8ha, \u27e8hb, \u27e8hc, hd\u27e9\u27e9\u27e9,\n        use ha, use hb,\n        split,\n        repeat {assumption}\n        },\n-- Proving transitive\n        {rintros x y z \u27e8\u27e8ha, \u27e8hb, \u27e8hd, he\u27e9\u27e9\u27e9, \u27e8hf, \u27e8hg, \u27e8hk, hl\u27e9\u27e9\u27e9\u27e9,\n        use ha, use hb,\n        cases h with hm hn,\n        replace hm : \n            \u2203 (B : set X) (H : B \u2208 C), y \u2208 B \u2227 \u2200 (D : set X), D \u2208 C \u2192 y \u2208 D \u2192 B = D := hm y,\n        rcases hm with \u27e8ho, \u27e8hp, \u27e8hq, hr\u27e9\u27e9\u27e9,\n        have : hf = ha, \n            {suffices : hf = ho, {rw this, apply hr ha, repeat {assumption}},\n            rwa hr hf, repeat {assumption},\n            },\n        split,\n        {assumption},\n        {rwa \u2190this},\n        }\n    }\nend\n\nlemma class_relate_lem_c \n    (s t : X) (R : bin_rel X) (h : equivalence R) : R s t \u2194 cls R t = cls R s :=\nbegin\n    split,\n    {from class_relate_lem_b s t R h},\n    {intro ha,\n    unfold cls at ha,\n    have : t \u2208 {x : X | R t x}, by {rwa set.mem_set_of_eq, from equiv_refl R h t},\n    rwa [ha, set.mem_set_of_eq] at this\n    }\nend\n\nvariable {R : bin_rel X}\ndef Rf (g : X \u2192 V) (s t : X)  := g s = g t\n\ntheorem equiv_relation_equiv (f = \u03bb x, cls R x) (h : equivalence R) : \u2200 s t : X, R s t \u2194 Rf f s t :=\nbegin\n    intros s t,\n    unfold Rf, rw H, simp,\n    split,\n    {intro ha,\n    rwa [\u2190class_relate_lem_c, equiv_symm R h t s],\n    assumption\n    },\n    {intro ha,\n    rwa [class_relate_lem_c s t R h, ha]\n    }\nend\n\nend M40001", "meta": {"author": "JasonKYi", "repo": "M4000x_LEAN_formalisation", "sha": "6e99793f2fcbe88596e27644f430e46aa2a464df", "save_path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation", "path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation/M4000x_LEAN_formalisation-6e99793f2fcbe88596e27644f430e46aa2a464df/src/M40001/Partition_iso_equiv_class/M40001_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7091270186469323}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Patrick Massot\n-/\nimport topology.algebra.ordered.basic\nimport data.set.intervals.proj_Icc\n\n/-!\n# Projection onto a closed interval\n\nIn this file we prove that the projection `set.proj_Icc f a b h` is a quotient map, and use it\nto show that `Icc_extend h f` is continuous if and only if `f` is continuous.\n-/\n\nopen set filter\nopen_locale filter topological_space\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*} [linear_order \u03b1] [topological_space \u03b3] {a b c : \u03b1} {h : a \u2264 b}\n\nlemma filter.tendsto.Icc_extend (f : \u03b3 \u2192 Icc a b \u2192 \u03b2) {z : \u03b3} {l : filter \u03b1} {l' : filter \u03b2}\n  (hf : tendsto \u21bff (\ud835\udcdd z \u00d7\u1da0 l.map (proj_Icc a b h)) l') :\n  tendsto \u21bf(Icc_extend h \u2218 f) (\ud835\udcdd z \u00d7\u1da0 l) l' :=\nshow tendsto (\u21bff \u2218 prod.map id (proj_Icc a b h)) (\ud835\udcdd z \u00d7\u1da0 l) l', from\nhf.comp $ tendsto_id.prod_map tendsto_map\n\nvariables [topological_space \u03b1] [order_topology \u03b1] [topological_space \u03b2]\n\n@[continuity]\nlemma continuous_proj_Icc : continuous (proj_Icc a b h) :=\ncontinuous_subtype_mk _ $ continuous_const.max $ continuous_const.min continuous_id\n\nlemma quotient_map_proj_Icc : quotient_map (proj_Icc a b h) :=\nquotient_map_iff.2 \u27e8proj_Icc_surjective h, \u03bb s,\n  \u27e8\u03bb hs, hs.preimage continuous_proj_Icc,\n   \u03bb hs, \u27e8_, hs, by { ext, simp }\u27e9\u27e9\u27e9\n\n@[simp] lemma continuous_Icc_extend_iff {f : Icc a b \u2192 \u03b2} :\n  continuous (Icc_extend h f) \u2194 continuous f :=\nquotient_map_proj_Icc.continuous_iff.symm\n\n/-- See Note [continuity lemma statement]. -/\nlemma continuous.Icc_extend {f : \u03b3 \u2192 Icc a b \u2192 \u03b2} {g : \u03b3 \u2192 \u03b1}\n  (hf : continuous \u21bff) (hg : continuous g) : continuous (\u03bb a, Icc_extend h (f a) (g a)) :=\nhf.comp $ continuous_id.prod_mk $ continuous_proj_Icc.comp hg\n\n/-- A useful special case of `continuous.Icc_extend`. -/\n@[continuity]\nlemma continuous.Icc_extend' {f : Icc a b \u2192 \u03b2} (hf : continuous f) : continuous (Icc_extend h f) :=\nhf.comp continuous_proj_Icc\n\nlemma continuous_at.Icc_extend {x : \u03b3} (f : \u03b3 \u2192 Icc a b \u2192 \u03b2) {g : \u03b3 \u2192 \u03b1}\n  (hf : continuous_at \u21bff (x, proj_Icc a b h (g x))) (hg : continuous_at g x) :\n  continuous_at (\u03bb a, Icc_extend h (f a) (g a)) x :=\nshow continuous_at (\u21bff \u2218 \u03bb x, (x, proj_Icc a b h (g x))) x, from\ncontinuous_at.comp hf $ continuous_at_id.prod $ continuous_proj_Icc.continuous_at.comp hg\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/algebra/ordered/proj_Icc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7091270179905996}}
{"text": "/-\nCopyright (c) 2021 Lu-Ming Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Lu-Ming Zhang\n-/\nimport linear_algebra.matrix.symmetric\nimport linear_algebra.matrix.orthogonal\nimport data.matrix.kronecker\n\n/-!\n# Diagonal matrices\n\nThis file contains the definition and basic results about diagonal matrices.\n\n## Main results\n\n- `matrix.is_diag`: a proposition that states a given square matrix `A` is diagonal.\n\n## Tags\n\ndiag, diagonal, matrix\n-/\n\nnamespace matrix\n\nvariables {\u03b1 \u03b2 R n m : Type*}\n\nopen function\nopen_locale matrix kronecker\n\n/-- `A.is_diag` means square matrix `A` is a diagonal matrix. -/\ndef is_diag [has_zero \u03b1] (A : matrix n n \u03b1) : Prop := \u2200 \u2983i j\u2984, i \u2260 j \u2192 A i j = 0\n\n@[simp] lemma is_diag_diagonal [has_zero \u03b1] [decidable_eq n] (d : n \u2192 \u03b1) :\n  (diagonal d).is_diag :=\n\u03bb i j, matrix.diagonal_apply_ne\n\n/-- Diagonal matrices are generated by `matrix.diagonal`. -/\nlemma is_diag.exists_diagonal [has_zero \u03b1] [decidable_eq n] {A : matrix n n \u03b1} (h : A.is_diag) :\n  \u2203 d, diagonal d = A :=\nbegin\n  refine \u27e8\u03bb i, A i i, ext $ \u03bb i j, _\u27e9,\n  obtain rfl | hij := decidable.eq_or_ne i j,\n  { rw diagonal_apply_eq },\n  { rw [diagonal_apply_ne hij, h hij] },\nend\n\n/-- `matrix.is_diag.exists_diagonal` as an iff. -/\nlemma is_diag_iff_exists_diagonal [has_zero \u03b1] [decidable_eq n] (A : matrix n n \u03b1) :\n  A.is_diag \u2194 (\u2203 d, diagonal d = A) :=\n\u27e8is_diag.exists_diagonal, \u03bb \u27e8d, hd\u27e9, hd \u25b8 is_diag_diagonal d\u27e9\n\n/-- Every matrix indexed by a subsingleton is diagonal. -/\nlemma is_diag_of_subsingleton [has_zero \u03b1] [subsingleton n] (A : matrix n n \u03b1) : A.is_diag :=\n\u03bb i j h, (h $ subsingleton.elim i j).elim\n\n/-- Every zero matrix is diagonal. -/\n@[simp] lemma is_diag_zero [has_zero \u03b1] : (0 : matrix n n \u03b1).is_diag :=\n\u03bb i j h, rfl\n\n/-- Every identity matrix is diagonal. -/\n@[simp] lemma is_diag_one [decidable_eq n] [has_zero \u03b1] [has_one \u03b1] :\n  (1 : matrix n n \u03b1).is_diag :=\n\u03bb i j, one_apply_ne\n\nlemma is_diag.map [has_zero \u03b1] [has_zero \u03b2]\n{A : matrix n n \u03b1} (ha : A.is_diag) {f : \u03b1 \u2192 \u03b2} (hf : f 0 = 0) :\n  (A.map f).is_diag :=\nby { intros i j h, simp [ha h, hf] }\n\nlemma is_diag.neg [add_group \u03b1] {A : matrix n n \u03b1} (ha : A.is_diag) :\n  (-A).is_diag :=\nby { intros i j h, simp [ha h] }\n\n@[simp] lemma is_diag_neg_iff [add_group \u03b1] {A : matrix n n \u03b1} :\n  (-A).is_diag \u2194 A.is_diag :=\n\u27e8 \u03bb ha i j h, neg_eq_zero.1 (ha h), is_diag.neg \u27e9\n\nlemma is_diag.add\n  [add_zero_class \u03b1] {A B : matrix n n \u03b1} (ha : A.is_diag) (hb : B.is_diag) :\n  (A + B).is_diag :=\nby { intros i j h, simp [ha h, hb h] }\n\nlemma is_diag.sub [add_group \u03b1]\n  {A B : matrix n n \u03b1} (ha : A.is_diag) (hb : B.is_diag) :\n  (A - B).is_diag :=\nby { intros i j h, simp [ha h, hb h] }\n\nlemma is_diag.smul [monoid R] [add_monoid \u03b1] [distrib_mul_action R \u03b1]\n  (k : R) {A : matrix n n \u03b1} (ha : A.is_diag) :\n  (k \u2022 A).is_diag :=\nby { intros i j h, simp [ha h] }\n\n@[simp] lemma is_diag_smul_one (n) [semiring \u03b1] [decidable_eq n] (k : \u03b1) :\n  (k \u2022 (1 : matrix n n \u03b1)).is_diag :=\nis_diag_one.smul k\n\nlemma is_diag.transpose [has_zero \u03b1] {A : matrix n n \u03b1} (ha : A.is_diag) : A\u1d40.is_diag :=\n\u03bb i j h, ha h.symm\n\n@[simp] lemma is_diag_transpose_iff [has_zero \u03b1] {A : matrix n n \u03b1} :\n  A\u1d40.is_diag \u2194 A.is_diag :=\n\u27e8 is_diag.transpose, is_diag.transpose \u27e9\n\nlemma is_diag.conj_transpose\n  [semiring \u03b1] [star_ring \u03b1] {A : matrix n n \u03b1} (ha : A.is_diag) :\n  A\u1d34.is_diag :=\nha.transpose.map (star_zero _)\n\n@[simp] lemma is_diag_conj_transpose_iff [semiring \u03b1] [star_ring \u03b1] {A : matrix n n \u03b1} :\n  A\u1d34.is_diag \u2194 A.is_diag :=\n\u27e8 \u03bb ha, by {convert ha.conj_transpose, simp}, is_diag.conj_transpose \u27e9\n\nlemma is_diag.minor [has_zero \u03b1]\n  {A : matrix n n \u03b1} (ha : A.is_diag) {f : m \u2192 n} (hf : injective f) :\n  (A.minor f f).is_diag :=\n\u03bb i j h, ha (hf.ne h)\n\n/-- `(A \u2297 B).is_diag` if both `A` and `B` are diagonal. -/\nlemma is_diag.kronecker [mul_zero_class \u03b1]\n  {A : matrix m m \u03b1} {B : matrix n n \u03b1} (hA : A.is_diag) (hB : B.is_diag) :\n  (A \u2297\u2096 B).is_diag :=\nbegin\n  rintros \u27e8a, b\u27e9 \u27e8c, d\u27e9 h,\n  simp only [prod.mk.inj_iff, ne.def, not_and_distrib] at h,\n  cases h with hac hbd,\n  { simp [hA hac] },\n  { simp [hB hbd] },\nend\n\n\n\n/-- The block matrix `A.from_blocks 0 0 D` is diagonal if `A` and `D` are diagonal. -/\nlemma is_diag.from_blocks [has_zero \u03b1]\n  {A : matrix m m \u03b1} {D : matrix n n \u03b1}\n  (ha : A.is_diag) (hd : D.is_diag) :\n  (A.from_blocks 0 0 D).is_diag :=\nbegin\n  rintros (i | i) (j | j) hij,\n  { exact ha (ne_of_apply_ne _ hij) },\n  { refl },\n  { refl },\n  { exact hd (ne_of_apply_ne _ hij) },\nend\n\n/-- This is the `iff` version of `matrix.is_diag.from_blocks`. -/\nlemma is_diag_from_blocks_iff [has_zero \u03b1]\n  {A : matrix m m \u03b1} {B : matrix m n \u03b1} {C : matrix n m \u03b1} {D : matrix n n \u03b1} :\n  (A.from_blocks B C D).is_diag \u2194 A.is_diag \u2227 B = 0 \u2227 C = 0 \u2227 D.is_diag :=\nbegin\n  split,\n  { intros h,\n    refine \u27e8\u03bb i j hij, _, ext $ \u03bb i j, _, ext $ \u03bb i j, _, \u03bb i j hij, _\u27e9,\n    { exact h (sum.inl_injective.ne hij), },\n    { exact h sum.inl_ne_inr, },\n    { exact h sum.inr_ne_inl, },\n    { exact h (sum.inr_injective.ne hij), }, },\n  { rintros \u27e8ha, hb, hc, hd\u27e9,\n    convert is_diag.from_blocks ha hd }\nend\n\n/-- A symmetric block matrix `A.from_blocks B C D` is diagonal\n    if  `A` and `D` are diagonal and `B` is `0`. -/\nlemma is_diag.from_blocks_of_is_symm [has_zero \u03b1]\n  {A : matrix m m \u03b1} {C : matrix n m \u03b1} {D : matrix n n \u03b1}\n  (h : (A.from_blocks 0 C D).is_symm) (ha : A.is_diag) (hd : D.is_diag) :\n  (A.from_blocks 0 C D).is_diag :=\nbegin\n  rw \u2190(is_symm_from_blocks_iff.1 h).2.1,\n  exact ha.from_blocks hd,\nend\n\nlemma mul_transpose_self_is_diag_iff_has_orthogonal_rows\n  [fintype n] [has_mul \u03b1] [add_comm_monoid \u03b1] {A : matrix m n \u03b1} :\n  (A \u2b1d A\u1d40).is_diag \u2194 A.has_orthogonal_rows :=\niff.rfl\n\nlemma transpose_mul_self_is_diag_iff_has_orthogonal_cols\n  [fintype m] [has_mul \u03b1] [add_comm_monoid \u03b1] {A : matrix m n \u03b1} :\n  (A\u1d40 \u2b1d A).is_diag \u2194 A.has_orthogonal_cols :=\niff.rfl\n\nend matrix\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/matrix/is_diag.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7091270126351795}}
{"text": "/-\nJustin Cai, jc5pz\nHere is the practice exam. It provides you\nwith a set of problems illustrative of the\nmaterial to be tested. This is a homework\nassignment due this coming Thursday. We will\nreview the questions in class.\n\nCopy this file your \"work\" directory. Work\non it there. Upload to Collab when done.\n\nNote: An incorrect answer above or below\na correct answer can cause Lean to be unable\nto process the correct answer. If you are not\nable to complete a problem successfully please\ncomment out your incomplete answer so that we\ncan see your work but so that your incomplete\nwork does not cause problems for surrounding\nproblems and answers.\n-/\n\n/-\nPART I: Functions. Functions are an essential\nelement of the language of predicate logic. In\nthis section, you show that you understand how\nto define, use, and reason about functions in\nLean.\n-/\n\n/- 1.\nStudy each of the following definitions,\nthen answer the associated question about\nthe types involved in these definitions.\n-/\n\n-- Consider this function\ndef f (n : \u2115) (s : string) := s\n\n/-\na. What is it's return type? Answer:\nstring\n-/\n\n/-\nb. What is the type of (f 5)? Answer:\nstring\n-/\n\n/-\nc. What is the value of (f 0 \"yay\")\n\"yay\"\n-/\n\n/-\nd. What is the type of this function?\n\u2115 \u2192 string\n-/\n\n\n/- 2.\nDefine three functions called square,\nsquare', and square'', each of type\n\u2115 \u2192 \u2115. Each function must return the\nsquare of the value to which it is\napplied. Write the first function in\n\"C\" style, the second using a tactic\nscript, and the third using a lambda\nabstraction. Declare all argument and\nreturn types explicitly. Answer below.\n-/\ndef square (x: nat) : nat := x^2\n\ndef square': \u2115 \u2192 \u2115 :=\nbegin\n    assume x,\n    exact x*x,\nend\n\n\ndef square'': \u2115 \u2192 \u2115 := \u03bb x, x^2\n\n\n\n\n/- 3.\nConstruct three proofs to test your\nfunction definitions. The first must\nuse \"lemma\" to define a proof, called\nsquare_3_9, of the proposition that\n(square 3) equals 9. The second must\nuse \"theorem\" to define a proof, called\nsquare'_4_16, of the proposition that\nsquare' applied to 4 reduces to 16. The\nthird must prove that square'' 5 is\nequal to 25. This third proof must not\nuse the equals sign, =, but must use\n\"eq\" instead to state the proposition\nto be proved. Hint on #3, sometimes\nyou need to use parentheses to express\nhow you want terms to be grouped. Answer\nbelow.\n-/\n\nlemma square_3_9 : 9 = 9 :=\nbegin\n    apply eq.refl(square 3)\nend\n\ntheorem square'_4_16 : 16 = 16 :=\nbegin\n    apply eq.refl(square' 4)\nend\n\nexample: eq 25 25 := \nbegin\n    apply eq.refl(square'' 5)\nend\n\n\n\n\n\n/- 4.\nDefine a function called last_first.\nIt must take two string values, called\n\"first\" and \"last\" (without quotes),\nand return a string consisting of \"last\"\nfollowed by a comma and a space followed\nby \"first\".\n\nFor example (last_first \"Orson\" \"Welles\")\nmust return the string, \"Welles, Orson\".\nWrite a test case for your function to\nprove that (last_first \"Orson\" \"Welles\")\nis \"Welles, Orson\". Use \"example\", to\ncheck the proof. Hint: The ++ operator\nimplements the string append function.\nAnswer below.\n-/\ndef last_first (first: string) (last: string) := last ++ \", \" ++ first\nexample: last_first \"Orson\" \"Welles\" = \"Welles, Orson\" :=\nbegin\n    apply eq.refl\nend\n\n\n\n/- 5.\n\nComplete the following definition of a\nfunction, called apply3. It takes, as an\nargument, a function, you might call it f,\nof type \u2115 \u2192 \u2115. It must return a function,\nalso of type \u2115 to \u2115, that, when applied\nto a value, n, returns the result of\napplying the given function, f, to the\ngiven value, n, three times. The function\nreturned must compute f(f(f(n))) when it\nis applied to an argument, n.\n-/\n\ndef apply3 :(\u2115 \u2192 \u2115) \u2192 (\u2115 \u2192 \u2115) :=\n    \u03bb f : \u2115 \u2192 \u2115,\n    \u03bb n:\u2115 , \n    f(f(f n))\n\n/- 6.\n\nThe Lean libraries define a function,\nstring.length, that takes a string and\nreturns its length as a natural number.\nDefine a function, len2, that takes two\nstrings and returns the sum of their\nlengths. You may use the ++ operator\nbut not the + operator in your answer.\nFollow your function definition with a\ntest case in the form of a proof using\n\"example\" showing that len2 applied to\n\"Orson\" and \"Welles\" is 11. Remember:\nyou might need parenthesis in some\ncases to group terms correctly into\nlarger terms.\n-/\ndef len2 (first: string) (second: string) : \u2115 := \n    (first ++ second).length\nexample: len2 \"Orson\" \"Welles\" = 11 :=\nbegin\n    apply eq.refl\nend\n\n/- 7.\nUse \"example\" to prove that there is a\nfunction of the following type:\n\n((\u2115 \u2192 \u2115) \u2192 (\u2115 \u2192 \u2115)) \u2192\n    ((\u2115 \u2192 \u2115) \u2192 \u2115) \u2192\n        ((\u2115 \u2192 \u2115) \u2192 \u2115)\n-/\nexample: ((\u2115 \u2192 \u2115) \u2192 (\u2115 \u2192 \u2115)) \u2192 \n    ((\u2115 \u2192 \u2115 ) \u2192 \u2115 ) \u2192 ((\u2115\u2192\u2115) \u2192 \u2115) :=\nbegin\n    assume a b c,\n    exact b c\nend\n\n/-\nPART II: Functions, revisited. In\nmathematics,  functions play a central\nrole. A function, f, in the mathematical\nsense is a triple, f = { D, P, C }, where\nD, a set, is the domain of definition of\nf, C is the co-domain of f, and P is a\nset of ordered pairs, each with a first\nelement from D and a second element from\nC,. In addition, P has one additional\nessential  property, the subject of one\nof the following questions.\n-/\n\n/- 8.\n\nWhat one additional property is essential to\nthe definition of what it means for a triple,\n{ D, P, C } to be a function?\n\nName the property. Answer:\nSingle valued\n\nNow explain precisely what it means:  \"That there\nare no two pairs, (x, y) and (x', y') such that...\"\n\nFill in the blank, and use a logical \u2227 in answering.\nYou might also want to use = or \u2260.\n\nAnswer:\nx=x' \u2227 y \u2260 y'\nx can equal x' and y isn't equal to y'\n-/\n\n/- 9.\n\nGive names to the following concepts:\n\nThe set of all values appearing as the first\nelement of any pair in P.\n\nAnswer: Domain\n\nThe set of all values appearing as the second\nelement of any pair in P.\n\nAnswer: Range\n\nThe property that the set of all values\nappearing as the first element of P is the\nsame as the entire set, D.\n\nAnswer: Total\n\nThe property that the set of all \nvalues appearing as the second element of \nP is the same as the entire set, C. \n\nAnswer: Surjective\n\nThe property of being one-to-one and onto.\n\nAnswer: Bijective\n\n-/\n\n/- 10.\n\nWhat does it mean for a function, f, to be\ninjective? Give you answer by completing the\nfollowing sentences with logical expressions.\n\n\"A function, f, is said to be injective if\nit has no two pairs, (x, y) and (x', y'),\nsuch that ...\"\n\nAnswer: x \u2260 x' \u2227 y=y'\n\nIn other words, \"If (x, y) and (x', y') are\nrelated by f and x \u2260 x' then ...\"\n\nAnswer:\nf(x) \u2260 f(x')\n-/\n\n\n/- 11.\n\nSuppose that S and T are types and that f\nis defined to be a function, *in Lean*, of\ntype S \u2192 T. Which of the following properties,\nif any, does f necessarily have?\n\n- injective\n- surjective\n- bijective\n- one-to-many\n- one-to-one\n- onto\n- single-valued\n- partial\n- total\n\nAnswer:\nSurjective, total\n-/\n\n/-\nPART III: Logic and Proof.\n-/\n\n/- 12a.\n\nUse axiom and/or axioms in Lean to express,\nin formal logic, the following assumptions:\n\n- T is a type\n- t1 and t2 are values of type T\n- t1 = t2\n\nAnswer immediately after this comment block.\nIf you need to introduce a name, use eqt1t2.\n-/\naxiom T : Type\naxioms t1 t2 : T\naxiom eqt1t2 : t1 = t2\n\n\n/- 12b.\n\nUse axiom or axioms to represent the\nadditional assumptions that\n\n- P is a predicate expressing a property of objects of type T\n- t1 has property P\n\nIf you need to use a name, use Pt1\n-/\naxiom P : T \u2192 Prop\naxiom Pt1 : P t1\n\n\n/- 12 c.\n\nNow use \"example\" to assert, and then\nprove, that t2 also has property P.\n-/\nexample : P t2 := eq.subst eqt1t2 Pt1\n\n/- 13 a.\nDefine eq_1_0 to be the proposition, 1 = 0.\n-/\ndef eq_1_0 : Prop := 1 = 0\n\n\n/- 13 b.\nDefine pf_eq_0_0 to be a proof of the\nproposition that 0 = 0. Use the lemma\nkeyword.\n-/\nlemma pf_eq_0_0 : 0 = 0 := rfl\n\n/- 13 c.\nWrite a function, w, that takes three\nvalues, a, b, and c of type \u2115, and that\nalso takes proofs, cb : c = b, and\nba : b = a, and that returns a proof\nthat a = c.\n-/\ndef w (a b c: \u2115 ) (cb: c = b) (ba : b = a) : a = c := \n    eq.trans(eq.symm ba) (eq.symm cb)\n\n\n/- 13d.\n\nWhat is the type of this function?\n\nAnswer: \u2115 \u2192 c = b \u2192 b = a \u2192 a = c\n\nWhat is the form of this proposition?\n\nAnswer: \u2115 \u2192 Prop \u2192 Prop \u2192 Prop\n\nWhat's the form the proposition after the\ncomma?\n\nAnswer: \u2115 \u2192 Prop\n\nWhat is the premise of the proposition after\nthe comma?\n\nAnswer: For 3 Nats a b c given c = b and b = a, then a = b and b = c then a = c\n\n-/\n\n/- 14.\nComplete the following proofs. Give each one\nin the form indicated by a comment preceding\nthe statement of the conjecture to be proved.\nWhen using tactic scripts, remember to write\nbegin/end pairs right away, so Lean knowns\nyou want to use a tactic script.\n-/\n\n-- lambda expression\nexample : \u2200 (s : string), s = s :=\n\u03bb s: string,\neq.refl s\n\n\n-- lambda expresion\nexample : \u2200 (n : \u2115), \u2200 (m : \u2115), true :=\n\u03bb n m: \u2115, true.intro\n\n\n-- tactic script\nexample : \u2200 (T : Type), \u2200 (t : T), eq t t :=\nbegin\n    assume T: Type,\n    assume t: T,\n    exact eq.refl t\nend\n\n\n-- tactic script\nexample :\n    \u2200 (T : Type),\n    \u2200 (P : T \u2192 Prop),\n    \u2200 t1 t2 : T,\n    \u2200 Pt1 : P t1,\n    \u2200 t2t1 : t2 = t1,\n    P t2 :=\nbegin\n    assume T P t1 t2 Pt1 t2t1,\n    exact eq.subst (eq.symm(t2t1)) Pt1\nend\n\n/-\nThe following problems involve implications.\nFor example, false \u2192 P in an implication. To\nprove an implication, just show that there is\n(give) a function of the specified type.\n-/\n\n-- lambda expression\nexample : \u2200 (P : Prop), false \u2192 P :=\n\u03bb P i, false.elim i\n\n\n-- tactic script\nexample : \u2200 (P : Prop), false \u2192 P :=\nbegin\n    assume P i,\n    exact false.elim i\nend\n    \n\n\n-- lambda expression\nexample : \u2200 (P Q : Prop), P \u2227 Q \u2192 Q \u2227 P :=\n\u03bb P Q,\n    \u03bb pq: P \u2227 Q, \n        and.intro pq.elim_right pq.elim_left\n\n\n-- tactic script\nexample : \u2200 (P Q : Prop), P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n    assume P Q,\n    assume pq: P \u2227 Q,\n    exact and.intro pq.elim_right pq.elim_left\nend\n\n\n-- tactic script\nexample :\n    \u2200 T : Type,\n    \u2200 (t1 t2 t3 : T),\n    t1 = t2 \u2227 t2 = t3 \u2192 t1 = t3 :=\nbegin\n    assume T t1 t2 t3,\n    assume t1t2t3: t1 = t2 \u2227 t2 = t3,\n    exact eq.trans(t1t2t3.elim_left) (t1t2t3.elim_right)\nend\n\n\n\n/- 15.\n\nUse Lean to model a world in which there\nare Dogs, all Dogs are friendly, and Fido\nis a Dog, with a proof that in this world,\nFido must be friendly, too.\n-/\naxiom Dog : Type\naxiom Fido : Dog\naxiom Friendly: Dog \u2192 Prop\naxiom FriendlyDog : \u2200 d: Dog, Friendly d\nexample : Friendly Fido :=\nbegin\n    exact FriendlyDog Fido\nend\n", "meta": {"author": "justinqcai", "repo": "CS2102", "sha": "d309f0db3f1df52eb77206ee1e8665a3b49d7a0c", "save_path": "github-repos/lean/justinqcai-CS2102", "path": "github-repos/lean/justinqcai-CS2102/CS2102-d309f0db3f1df52eb77206ee1e8665a3b49d7a0c/hw5-exam1-practice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117983401363, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7091270081263646}}
{"text": "/- LoVe Exercise 8: Operational Semantics -/\n\nimport .love08_operational_semantics_demo\n\nnamespace LoVe\n\n\n/- Question 1: Program Equivalence -/\n\n/- For this question, we introduce the notation of program equivalence\n`p\u2081 \u2248 p\u2082`. -/\n\ndef program_equiv (S\u2081 S\u2082 : program) : Prop :=\n\u2200s t, (S\u2081, s) \u27f9 t \u2194 (S\u2082, s) \u27f9 t\n\nlocal infix ` \u2248 ` := program_equiv\n\n/- Program equivalence is a equivalence relation, i.e., it is reflexive,\nsymmetric, and transitive. -/\n\n@[refl] lemma program_equiv.refl {S} :\n  S \u2248 S :=\nassume s t,\nshow (S, s) \u27f9 t \u2194 (S, s) \u27f9 t,\n  by refl\n\n@[symm] lemma program_equiv.symm {S\u2081 S\u2082}:\n  S\u2081 \u2248 S\u2082 \u2192 S\u2082 \u2248 S\u2081 :=\nassume h s t,\nshow (S\u2082, s) \u27f9 t \u2194 (S\u2081, s) \u27f9 t,\n  from iff.symm (h s t)\n\n@[trans] lemma program_equiv.trans {S\u2081 S\u2082 S\u2083} (h\u2081\u2082 : S\u2081 \u2248 S\u2082) (h\u2082\u2083 : S\u2082 \u2248 S\u2083) :\n  S\u2081 \u2248 S\u2083 :=\nassume s t,\nshow (S\u2081, s) \u27f9 t \u2194 (S\u2083, s) \u27f9 t,\n  from iff.trans (h\u2081\u2082 s t) (h\u2082\u2083 s t)\n\n\n/- 1.1. Prove the following program equivalences. -/\n\nlemma program_equiv.seq_skip_left {S} :\n  skip ;; S \u2248 S :=\nsorry\n\nlemma program_equiv.seq_skip_right {S} :\n  S ;; skip \u2248 S :=\nsorry\n\nlemma program_equiv.seq_congr {S\u2081 S\u2082 T\u2081 T\u2082} (hS : S\u2081 \u2248 S\u2082) (hT : T\u2081 \u2248 T\u2082) :\n  S\u2081 ;; T\u2081 \u2248 S\u2082 ;; T\u2082 :=\nsorry\n\nlemma program_equiv.ite_seq_while {b S} :\n  ite b (S ;; while b S) skip \u2248 while b S :=\nsorry\n\n/- 1.2. Prove one more equivalence. -/\n\nlemma program_equiv.skip_assign_id {x} :\n  assign x (\u03bbs, s x) \u2248 skip :=\nsorry\n\n\n/- Question 2: Guarded Command Language (GCL) -/\n\n/- In 1976, E. W. Dijkstra introduced the guarded command language, a\nminimalistic imperative language with built-in nondeterminism. A grammar for one\nof its variants is given below:\n\n    S  ::=  x := e       -- assignment\n         |  assert b     -- assertion\n         |  S ; S        -- sequential composition\n         |  S | \u22ef | S    -- nondeterministic choice\n         |  loop S       -- nondeterministic iteration\n\nAssignment and sequential composition are as in the WHILE language. The other\nstatements have the following semantics:\n\n* `assert b` aborts if `b` evaluates to false; otherwise, the command is a\n  no-op.\n\n* `S | \u22ef | S` chooses **any** of the branches and executes it, ignoring the\n  other branches.\n\n* `loop S` executes `S` **any** number of times.\n\nIn Lean, GCL is captured by the following inductive type: -/\n\ninductive gcl (\u03c3 : Type) : Type\n| assign : string \u2192 (\u03c3 \u2192 \u2115) \u2192 gcl\n| assert : (\u03c3 \u2192 Prop) \u2192 gcl\n| seq    : gcl \u2192 gcl \u2192 gcl\n| choice : list gcl \u2192 gcl\n| loop   : gcl \u2192 gcl\n\ninfixr ` ;; `:90 := gcl.seq\n\nnamespace gcl\n\n/- The parameter `\u03c3` abstracts over the state type. It is necessary to work\naround a bug in Lean.\n\nThe big-step semantics is defined as follows: -/\n\ninductive big_step : (gcl state \u00d7 state) \u2192 state \u2192 Prop\n| assign {x a s} :\n  big_step (assign x a, s) (s{x \u21a6 a s})\n| assert {b : state \u2192 Prop} {s} (hcond : b s) :\n  big_step (assert b, s) s\n| seq {S T s t u} (h\u2081 : big_step (S, s) t) (h\u2082 : big_step (T, t) u) :\n  big_step (S ;; T, s) u\n| choice {Ss : list (gcl state)} {s t} (i : \u2115) (hless : i < list.length Ss)\n    (hbody : big_step (list.nth_le Ss i hless, s) t) :\n  big_step (choice Ss, s) t\n| loop_base {S s} :\n  big_step (loop S, s) s\n| loop_step {S s u} (t) (hbody : big_step (S, s) t)\n    (hrest : big_step (loop S, t) u) :\n  big_step (loop S, s) u\n\n/- Convenience syntax: -/\n\ninfix ` ~~> `:110 := big_step\n\n/- 2.1. Prove the following inversion rules, as we did in the lecture for the\nWHILE language. -/\n\n@[simp] lemma big_step_assign_iff {x a s t} :\n  (assign x a, s) ~~> t \u2194 t = s{x \u21a6 a s} :=\nsorry\n\n@[simp] lemma big_step_assert {b s t} :\n  (assert b, s) ~~> t \u2194 t = s \u2227 b s :=\nsorry\n\n@[simp] lemma big_step_seq_iff {S\u2081 S\u2082 s t} :\n  (S\u2081 ;; S\u2082, s) ~~> t \u2194 (\u2203u, (S\u2081, s) ~~> u \u2227 (S\u2082, u) ~~> t) :=\nsorry\n\nlemma big_step_loop {S s u} :\n  (loop S, s) ~~> u \u2194 (s = u \u2228 (\u2203t, (S, s) ~~> t \u2227 (loop S, t) ~~> u)) :=\nsorry\n\n@[simp] lemma big_step_choice {Ss s t} :\n  (choice Ss, s) ~~> t \u2194\n  (\u2203(i : \u2115) (hless : i < list.length Ss),\n    (list.nth_le Ss i hless, s) ~~> t) :=\nsorry\n\n/- 2.2. Complete the translation below of a deterministic program to a GCL\nprogram, by filling in the `sorry` placeholders below. -/\n\ndef of_program : program \u2192 gcl state\n| program.skip          := assert (\u03bb_, true)\n| (program.assign x f)  :=\n  sorry\n| (program.seq S\u2081 S\u2082)   :=\n  sorry\n| (program.ite b S\u2081 S\u2082) :=\n  choice [seq (assert b) (of_program S\u2081),\n    seq (assert (\u03bbs, \u00ac b s)) (of_program S\u2082)]\n| (program.while b S)   :=\n  seq (loop (seq (assert b) (of_program S))) (assert (\u03bbs, \u00ac b s))\n\n/- 2.3. In the definition of `of_program` above, `skip` is translated to\n`assert (\u03bb_, true)`. Looking at the big-step semantics of both constructs, we\ncan convince ourselves that it makes sense. Can you think of other correct ways\nto define the `skip` case? -/\n\n-- enter your answer here\n\nend gcl\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2019", "sha": "7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036", "save_path": "github-repos/lean/blanchette-logical_verification_2019", "path": "github-repos/lean/blanchette-logical_verification_2019/logical_verification_2019-7c5f1c90f6e5a0b221a02c8fa4e36c0c66393036/lean/love08_operational_semantics_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317473, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7091270061573665}}
{"text": "import data.nat.prime\nimport data.nat.totient\nimport data.list.basic\nimport data.nat.gcd\nimport .list\n\nnamespace nat\n\nopen finset\n\ntheorem totient_prime {p : \u2115} (hp : p.prime) : p.totient = p - 1 :=\nbegin\n\tunfold totient,\n\thave hcoprime : \u2200 x \u2208 (range p).erase 0, p.coprime x,\n\t{ intros x hx, rw prime.coprime_iff_not_dvd hp,\n\t\tapply not_dvd_of_pos_of_lt (nat.pos_of_ne_zero $ ne_of_mem_erase hx),\n\t\tapply mem_range.mp (mem_of_mem_erase hx) },\n\thave hunion : range p = {0} \u222a (range p).erase 0,\n\t{\trw [\u2190 insert_eq, insert_erase], simp, exact prime.pos hp },\n\trw [hunion, filter_union, filter_false_of_mem], swap,\n\t{\tintros x hx, simp at hx, simp [hx], intro h1, exact not_prime_one (h1 \u25b8 hp) },\n\trw [filter_true_of_mem hcoprime, empty_union, card_erase_of_mem, card_range],\n\t{ rw pred_eq_sub_one },\n\tsimp [prime.pos hp],\nend\n\ntheorem factors_ne_nil {n : \u2115} (hn : 1 < n) : n.factors \u2260 list.nil :=\nbegin\n\tinduction n with n ih,\n\t{\texfalso, exact (not_lt_of_gt nat.zero_lt_one) hn },\n\tinduction n with n ih,\n\t{ exfalso, exact (lt_irrefl 1) hn },\n\trw factors_add_two,\n\tintro h, injection h,\nend\n\ntheorem pow_count_factors_dvd (n k : \u2115) : k ^ list.count k n.factors \u2223 n :=\nbegin\n\tby_cases h0 : n = 0, { simp [h0] },\n\tconv { congr, skip, rw \u2190 prod_factors (nat.pos_of_ne_zero h0) },\n\tapply list.pow_count_dvd_prod,\nend\n\ntheorem pow_gt_count_factors_not_dvd {n p : \u2115} (hn : 0 < n) (hp : p.prime) :\n  \u2200 k, list.count p n.factors < k \u2192 \u00ac p ^ k \u2223 n :=\nbegin\n\thave aux : \u2200 l, (\u2200 x : \u2115, x \u2208 l \u2192 x.prime) \u2192 \u2200 p : \u2115, p.prime \u2192\n\t\t\u2200 k, list.count p l < k \u2192 \u00ac p ^ k \u2223 l.prod,\n\t{\tintros l hl p hp,\n\t\tinduction l with hd tl ih,\n\t\t{ intros k hk hdvd,\n\t\t\trw [list.count_nil] at hk,\n\t\t\trw [list.prod_nil, nat.dvd_one] at hdvd,\n\t\t\thave := pow_lt_pow (prime.one_lt hp) hk,\n\t\t\trw [hdvd, pow_zero] at this,\n\t\t\texact (lt_irrefl 1) this },\n\t\tintros k hk hdvd,\n\t\thave hkpos : 0 < k := lt_of_le_of_lt (zero_le _) hk,\n\t\trw [list.count_cons] at hk,\tsplit_ifs at hk,\n\t\t{ rw [\u2190 h, list.prod_cons, \u2190 succ_pred_eq_of_pos hkpos, pow_succ] at hdvd,\n\t\t\tcases hdvd with w hw,\n\t\t\trw [mul_assoc, mul_eq_mul_left_iff] at hw,\n\t\t\tcases hw with h1 h2, swap, { exact (prime.ne_zero hp) h2 },\n\t\t\tapply ih (\u03bb x hx, hl x (by simp [hx])) k.pred (lt_pred_iff.mpr hk),\n\t\t\tuse [w, h1] },\n\t\trw [list.prod_cons] at hdvd,\n\t\tapply ih (\u03bb x hx, hl x (by simp [hx])) k hk,\n\t\tapply coprime.dvd_of_dvd_mul_left _ hdvd,\n\t\trw [\u2190 pow_one hd], apply coprime.pow,\n\t\trwa coprime_primes hp (hl hd (by simp)) },\n\thave prod := prod_factors hn,\n\tconv in (\u00ac _ \u2223 n) { rw \u2190 prod },\n\tapply aux n.factors (\u03bb x, mem_factors) p hp,\nend\n\ntheorem mem_factors_dvd {n : \u2115} : \u2200 p \u2208 n.factors, p \u2223 n :=\n\u03bb p hp, decidable.by_cases\n\t(by { intro hn, exfalso, simp [hn, factors] at hp, assumption })\n\t(\u03bb hn, (mem_factors_iff_dvd (nat.pos_of_ne_zero hn) (mem_factors hp)).mp hp)\n\nlemma list_pos_prod_pos {l : list \u2115} (hpos : \u2200 x \u2208 l, 0 < x) : 0 < l.prod :=\nbegin\n\tinduction l with hd tl ih, { simp },\n\tsimp, apply mul_pos,\n\t{\tapply hpos, simp },\n\tapply ih, intros x hx, apply hpos, simp, right, exact hx,\nend\n\nlemma list_pos_prod_ge_sublist_prod {s t : list \u2115} (hpos : \u2200 x \u2208 s, 0 < x) (h : t <+ s) :\n\tt.prod \u2264 s.prod :=\nbegin\n\tinduction s with hd tl ih generalizing t,\n\t{\tsimp [list.eq_nil_of_sublist_nil h] },\n\tinduction t with hd' tl' ih',\n\t{\thave := succ_le_of_lt (list_pos_prod_pos hpos), simpa },\n\thave htlpos : \u2200 x \u2208 tl, 0 < x := \u03bb x hx, by { apply hpos x, simp, right, exact hx },\n\tby_cases heq : hd = hd',\n\t{\tsimp [heq], apply nat.mul_le_mul_of_nonneg_left, apply ih htlpos,\n\t\trw heq at h, apply list.sublist_of_cons_sublist_cons, exact h },\n\thave : hd' :: tl' <+ tl := list.cons_sublist_of_cons_sublist_cons (ne.symm heq) h,\n\thave := ih htlpos this,\n\tapply le_trans this,\n\trw [\u2190 nat.one_mul tl.prod, list.prod_cons],\n\thave := succ_le_of_lt (hpos hd (by simp)),\n\tapply nat.mul_le_mul_of_nonneg_right, assumption,\nend\n\ntheorem div_factor_ne_zero (n : \u2115) : \u2200 p \u2208 n.factors, n / p ^ list.count p n.factors \u2260 0 :=\nbegin\n\tby_cases h0 : n = 0,\n\t{\tintros p hmem, exfalso, simp [h0, factors] at hmem, exact hmem },\n\thave hpos : 0 < n := nat.pos_of_ne_zero h0,\n\thave hfactorspos : \u2200 x \u2208 n.factors, 0 < x := \u03bb x hx, prime.pos (mem_factors hx),\n\tintros p hmem h0,\n\trw nat.div_eq_zero_iff at h0, swap,\n\t{\tapply nat.pos_of_ne_zero, apply pow_ne_zero,\n\t\tintro h, apply not_prime_zero, rw \u2190 h, exact mem_factors hmem },\n\thave hleft := prod_factors hpos,\n\thave hright : p ^ list.count p n.factors = (list.repeat p $ list.count p n.factors).prod := by simp,\n\tconv at h0 {congr, rw \u2190 hleft, skip, rw hright },\n\tapply not_lt_of_ge (list_pos_prod_ge_sublist_prod hfactorspos _) h0,\n\trw \u2190 list.le_count_iff_repeat_sublist,\nend\n\nend nat", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/imo/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.7091270011301127}}
{"text": "-- Las_relaciones_definidas_por_particiones_son_simetricas.lean\n-- Las relaciones definidas por particiones son sim\u00e9tricas\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 10 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que la relaci\u00f3n correspondiente a unaa partici\u00f3n es\n-- sim\u00e9trica.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n@[ext] structure particion (A : Type) :=\n(Bloques    : set (set A))\n(Hno_vacios : \u2200 X \u2208 Bloques, (X : set A).nonempty)\n(Hrecubren  : \u2200 a, \u2203 X \u2208 Bloques, a \u2208 X)\n(Hdisjuntos : \u2200 X Y \u2208 Bloques, (X \u2229 Y : set A).nonempty \u2192 X = Y)\n\nnamespace particion\n\nvariable  {A : Type}\nvariables {X Y : set A}\nvariable  {P : particion A}\n\ndef relacion : (particion A) \u2192 (A \u2192 A \u2192 Prop) :=\n  \u03bb P a b, \u2200 X \u2208 Bloques P, a \u2208 X \u2192 b \u2208 X\n\n-- Se usar\u00e1n los siguientes lemas auxiliares\n\nlemma iguales_si_comun\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  : X = Y :=\nHdisjuntos P X hX Y hY \u27e8a, haX, haY\u27e9\n\nlemma pertenece_si_pertenece\n  (hX : X \u2208 Bloques P)\n  (hY : Y \u2208 Bloques P)\n  {a b : A}\n  (haX : a \u2208 X)\n  (haY : a \u2208 Y)\n  (hbX : b \u2208 X)\n  : b \u2208 Y :=\nbegin\n  convert hbX,\n  exact iguales_si_comun hY hX haY haX,\nend\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (P : particion A)\n  : symmetric (relacion P) :=\nbegin\n  rw symmetric,\n  intros a b hab,\n  unfold relacion at *,\n  intros X hX hbX,\n  obtain \u27e8Y, hY, haY\u27e9 := Hrecubren P a,\n  specialize hab Y hY haY,\n  exact pertenece_si_pertenece hY hX hab hbX haY,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (P : particion A)\n  : symmetric (relacion P) :=\nbegin\n  intros a b hab,\n  intros X hX hbX,\n  obtain \u27e8Y, hY, haY\u27e9 := Hrecubren P a,\n  specialize hab Y hY haY,\n  exact pertenece_si_pertenece hY hX hab hbX haY,\nend\n\n-- 3\u00aa demostraci\u00f3n\nlemma simetrica\n  (P : particion A)\n  : symmetric (relacion P) :=\nbegin\n  intros a b h X hX hbX,\n  obtain \u27e8Y, hY, haY\u27e9 := Hrecubren P a,\n  specialize h Y hY haY,\n  exact pertenece_si_pertenece hY hX h hbX haY,\nend\n\nend particion\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Las_relaciones_definidas_por_particiones_son_simetricas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7091269969494639}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Yury Kudryashov\n-/\nimport analysis.normed_space.basic\nimport topology.algebra.order.liminf_limsup\nimport topology.local_homeomorph\n\n/-!\n# Asymptotics\n\nWe introduce these relations:\n\n* `is_O_with c f g l` : \"f is big O of g along l with constant c\";\n* `is_O f g l` : \"f is big O of g along l\";\n* `is_o f g l` : \"f is little o of g along l\".\n\nHere `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains\nof `f` and `g` do not need to be the same; all that is needed that there is a norm associated with\nthese types, and it is the norm that is compared asymptotically.\n\nThe relation `is_O_with c` is introduced to factor out common algebraic arguments in the proofs of\nsimilar properties of `is_O` and `is_o`. Usually proofs outside of this file should use `is_O`\ninstead.\n\nOften the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute\nvalue. In general, we have\n\n  `is_O f g l \u2194 is_O (\u03bb x, \u2225f x\u2225) (\u03bb x, \u2225g x\u2225) l`,\n\nand similarly for `is_o`. But our setup allows us to use the notions e.g. with functions\nto the integers, rationals, complex numbers, or any normed vector space without mentioning the\nnorm explicitly.\n\nIf `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always\nnonzero, we have\n\n  `is_o f g l \u2194 tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0)`.\n\nIn fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction\nit suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining\nthe Fr\u00e9chet derivative.)\n-/\n\nopen filter set\nopen_locale topological_space big_operators classical filter nnreal\n\nnamespace asymptotics\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {E : Type*} {F : Type*} {G : Type*}\n  {E' : Type*} {F' : Type*} {G' : Type*} {R : Type*} {R' : Type*} {\ud835\udd5c : Type*} {\ud835\udd5c' : Type*}\n\nvariables [has_norm E] [has_norm F] [has_norm G] [normed_group E'] [normed_group F']\n  [normed_group G'] [normed_ring R] [normed_ring R'] [normed_field \ud835\udd5c] [normed_field \ud835\udd5c']\n  {c c' : \u211d} {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {k : \u03b1 \u2192 G} {f' : \u03b1 \u2192 E'} {g' : \u03b1 \u2192 F'} {k' : \u03b1 \u2192 G'}\n  {l l' : filter \u03b1}\n\nsection defs\n\n/-! ### Definitions -/\n\n/-- This version of the Landau notation `is_O_with C f g l` where `f` and `g` are two functions on\na type `\u03b1` and `l` is a filter on `\u03b1`, means that eventually for `l`, `\u2225f\u2225` is bounded by `C * \u2225g\u2225`.\nIn other words, `\u2225f\u2225 / \u2225g\u2225` is eventually bounded by `C`, modulo division by zero issues that are\navoided by this definition. Probably you want to use `is_O` instead of this relation. -/\n@[irreducible]\ndef is_O_with (c : \u211d) (f : \u03b1 \u2192 E) (g : \u03b1 \u2192 F) (l : filter \u03b1) : Prop :=\n\u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225\n\n/-- Definition of `is_O_with`. We record it in a lemma as we will set `is_O_with` to be irreducible\nat the end of this file. -/\nlemma is_O_with_iff {c : \u211d} {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O_with c f g l \u2194 \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 := by rw is_O_with\n\nalias is_O_with_iff \u2194 asymptotics.is_O_with.bound asymptotics.is_O_with.of_bound\n\n/-- The Landau notation `is_O f g l` where `f` and `g` are two functions on a type `\u03b1` and `l` is\na filter on `\u03b1`, means that eventually for `l`, `\u2225f\u2225` is bounded by a constant multiple of `\u2225g\u2225`.\nIn other words, `\u2225f\u2225 / \u2225g\u2225` is eventually bounded, modulo division by zero issues that are avoided\nby this definition. -/\n@[irreducible]\ndef is_O (f : \u03b1 \u2192 E) (g : \u03b1 \u2192 F) (l : filter \u03b1) : Prop := \u2203 c : \u211d, is_O_with c f g l\n\n/-- Definition of `is_O` in terms of `is_O_with`. We record it in a lemma as we will set\n`is_O` to be irreducible at the end of this file. -/\nlemma is_O_iff_is_O_with {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2194 \u2203 c : \u211d, is_O_with c f g l := by rw is_O\n\n/-- Definition of `is_O` in terms of filters. We record it in a lemma as we will set\n`is_O` to be irreducible at the end of this file. -/\nlemma is_O_iff {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2194 \u2203 c : \u211d, \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 := by simp [is_O, is_O_with]\n\nlemma is_O.of_bound (c : \u211d) {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1}\n  (h : \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225) : is_O f g l := is_O_iff.2 \u27e8c, h\u27e9\n\nlemma is_O.bound {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2192 \u2203 c : \u211d, \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 := is_O_iff.1\n\n/-- The Landau notation `is_o f g l` where `f` and `g` are two functions on a type `\u03b1` and `l` is\na filter on `\u03b1`, means that eventually for `l`, `\u2225f\u2225` is bounded by an arbitrarily small constant\nmultiple of `\u2225g\u2225`. In other words, `\u2225f\u2225 / \u2225g\u2225` tends to `0` along `l`, modulo division by zero\nissues that are avoided by this definition. -/\n@[irreducible]\ndef is_o (f : \u03b1 \u2192 E) (g : \u03b1 \u2192 F) (l : filter \u03b1) : Prop := \u2200 \u2983c : \u211d\u2984, 0 < c \u2192 is_O_with c f g l\n\n/-- Definition of `is_o` in terms of `is_O_with`. We record it in a lemma as we will set\n`is_o` to be irreducible at the end of this file. -/\nlemma is_o_iff_forall_is_O_with {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_o f g l \u2194 \u2200 \u2983c : \u211d\u2984, 0 < c \u2192 is_O_with c f g l := by rw is_o\n\nalias is_o_iff_forall_is_O_with \u2194 asymptotics.is_o.forall_is_O_with asymptotics.is_o.of_is_O_with\n\n/-- Definition of `is_o` in terms of filters. We record it in a lemma as we will set\n`is_o` to be irreducible at the end of this file. -/\nlemma is_o_iff {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_o f g l \u2194 \u2200 \u2983c : \u211d\u2984, 0 < c \u2192 \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 :=\nby simp only [is_o, is_O_with]\n\nalias is_o_iff \u2194 asymptotics.is_o.bound asymptotics.is_o.of_bound\n\nlemma is_o.def {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} (h : is_o f g l) {c : \u211d} (hc : 0 < c) :\n  \u2200\u1da0 x in l, \u2225 f x \u2225 \u2264 c * \u2225 g x \u2225 :=\nis_o_iff.1 h hc\n\nlemma is_o.def' {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} (h : is_o f g l) {c : \u211d} (hc : 0 < c) :\n  is_O_with c f g l :=\nis_O_with_iff.2 $ is_o_iff.1 h hc\n\nend defs\n\n/-! ### Conversions -/\n\ntheorem is_O_with.is_O (h : is_O_with c f g l) : is_O f g l := by rw is_O; exact \u27e8c, h\u27e9\n\ntheorem is_o.is_O_with (hgf : is_o f g l) : is_O_with 1 f g l := hgf.def' zero_lt_one\n\ntheorem is_o.is_O (hgf : is_o f g l) : is_O f g l := hgf.is_O_with.is_O\n\nlemma is_O.is_O_with {f : \u03b1 \u2192 E} {g : \u03b1 \u2192 F} {l : filter \u03b1} :\n  is_O f g l \u2192 \u2203 c : \u211d, is_O_with c f g l := is_O_iff_is_O_with.1\n\ntheorem is_O_with.weaken (h : is_O_with c f g' l) (hc : c \u2264 c') : is_O_with c' f g' l :=\nis_O_with.of_bound $ mem_of_superset h.bound $ \u03bb x hx,\ncalc \u2225f x\u2225 \u2264 c * \u2225g' x\u2225 : hx\n... \u2264 _ : mul_le_mul_of_nonneg_right hc (norm_nonneg _)\n\ntheorem is_O_with.exists_pos (h : is_O_with c f g' l) :\n  \u2203 c' (H : 0 < c'), is_O_with c' f g' l :=\n\u27e8max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken $ le_max_left c 1\u27e9\n\ntheorem is_O.exists_pos (h : is_O f g' l) : \u2203 c (H : 0 < c), is_O_with c f g' l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in hc.exists_pos\n\ntheorem is_O_with.exists_nonneg (h : is_O_with c f g' l) :\n  \u2203 c' (H : 0 \u2264 c'), is_O_with c' f g' l :=\nlet \u27e8c, cpos, hc\u27e9 := h.exists_pos in \u27e8c, le_of_lt cpos, hc\u27e9\n\ntheorem is_O.exists_nonneg (h : is_O f g' l) :\n  \u2203 c (H : 0 \u2264 c), is_O_with c f g' l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in hc.exists_nonneg\n\n/-- `f = O(g)` if and only if `is_O_with c f g` for all sufficiently large `c`. -/\nlemma is_O_iff_eventually_is_O_with : is_O f g' l \u2194 \u2200\u1da0 c in at_top, is_O_with c f g' l :=\nis_O_iff_is_O_with.trans\n  \u27e8\u03bb \u27e8c, hc\u27e9, mem_at_top_sets.2 \u27e8c, \u03bb c' hc', hc.weaken hc'\u27e9, \u03bb h, h.exists\u27e9\n\n/-- `f = O(g)` if and only if `\u2200\u1da0 x in l, \u2225f x\u2225 \u2264 c * \u2225g x\u2225` for all sufficiently large `c`. -/\nlemma is_O_iff_eventually : is_O f g' l \u2194 \u2200\u1da0 c in at_top, \u2200\u1da0 x in l, \u2225f x\u2225 \u2264 c * \u2225g' x\u2225 :=\nis_O_iff_eventually_is_O_with.trans $ by simp only [is_O_with]\n\n/-! ### Subsingleton -/\n\n@[nontriviality] lemma is_o_of_subsingleton [subsingleton E'] : is_o f' g' l :=\nis_o.of_bound $ \u03bb c hc, by simp [subsingleton.elim (f' _) 0, mul_nonneg hc.le]\n\n@[nontriviality] lemma is_O_of_subsingleton [subsingleton E'] : is_O f' g' l :=\nis_o_of_subsingleton.is_O\n\n/-! ### Congruence -/\n\ntheorem is_O_with_congr {c\u2081 c\u2082} {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n  (hc : c\u2081 = c\u2082) (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O_with c\u2081 f\u2081 g\u2081 l \u2194 is_O_with c\u2082 f\u2082 g\u2082 l :=\nbegin\n  unfold is_O_with,\n  subst c\u2082,\n  apply filter.eventually_congr,\n  filter_upwards [hf, hg] with _ e\u2081 e\u2082,\n  rw [e\u2081, e\u2082],\nend\n\ntheorem is_O_with.congr' {c\u2081 c\u2082} {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n  (hc : c\u2081 = c\u2082) (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O_with c\u2081 f\u2081 g\u2081 l \u2192 is_O_with c\u2082 f\u2082 g\u2082 l :=\n(is_O_with_congr hc hf hg).mp\n\ntheorem is_O_with.congr {c\u2081 c\u2082} {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n  (hc : c\u2081 = c\u2082) (hf : \u2200 x, f\u2081 x = f\u2082 x) (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O_with c\u2081 f\u2081 g\u2081 l \u2192 is_O_with c\u2082 f\u2082 g\u2082 l :=\n\u03bb h, h.congr' hc (univ_mem' hf) (univ_mem' hg)\n\ntheorem is_O_with.congr_left {f\u2081 f\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hf : \u2200 x, f\u2081 x = f\u2082 x) :\n  is_O_with c f\u2081 g l \u2192 is_O_with c f\u2082 g l :=\nis_O_with.congr rfl hf (\u03bb _, rfl)\n\ntheorem is_O_with.congr_right {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1} (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O_with c f g\u2081 l \u2192 is_O_with c f g\u2082 l :=\nis_O_with.congr rfl (\u03bb _, rfl) hg\n\ntheorem is_O_with.congr_const {c\u2081 c\u2082} {l : filter \u03b1} (hc : c\u2081 = c\u2082) :\n  is_O_with c\u2081 f g l \u2192 is_O_with c\u2082 f g l :=\nis_O_with.congr hc (\u03bb _, rfl) (\u03bb _, rfl)\n\ntheorem is_O_congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O f\u2081 g\u2081 l \u2194 is_O f\u2082 g\u2082 l :=\nby { unfold is_O, exact exists_congr (\u03bb c, is_O_with_congr rfl hf hg) }\n\ntheorem is_O.congr' {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_O f\u2081 g\u2081 l \u2192 is_O f\u2082 g\u2082 l :=\n(is_O_congr hf hg).mp\n\ntheorem is_O.congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : \u2200 x, f\u2081 x = f\u2082 x) (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O f\u2081 g\u2081 l \u2192 is_O f\u2082 g\u2082 l :=\n\u03bb h, h.congr' (univ_mem' hf) (univ_mem' hg)\n\ntheorem is_O.congr_left {f\u2081 f\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hf : \u2200 x, f\u2081 x = f\u2082 x) :\n  is_O f\u2081 g l \u2192 is_O f\u2082 g l :=\nis_O.congr hf (\u03bb _, rfl)\n\ntheorem is_O.congr_right {g\u2081 g\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_O f g\u2081 l \u2192 is_O f g\u2082 l :=\nis_O.congr (\u03bb _, rfl) hg\n\ntheorem is_o_congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_o f\u2081 g\u2081 l \u2194 is_o f\u2082 g\u2082 l :=\nby { unfold is_o, exact ball_congr (\u03bb c hc, is_O_with_congr (eq.refl c) hf hg) }\n\ntheorem is_o.congr' {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : f\u2081 =\u1da0[l] f\u2082) (hg : g\u2081 =\u1da0[l] g\u2082) :\n  is_o f\u2081 g\u2081 l \u2192 is_o f\u2082 g\u2082 l :=\n(is_o_congr hf hg).mp\n\ntheorem is_o.congr {f\u2081 f\u2082 : \u03b1 \u2192 E} {g\u2081 g\u2082 : \u03b1 \u2192 F} {l : filter \u03b1}\n    (hf : \u2200 x, f\u2081 x = f\u2082 x) (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_o f\u2081 g\u2081 l \u2192 is_o f\u2082 g\u2082 l :=\n\u03bb h, h.congr' (univ_mem' hf) (univ_mem' hg)\n\ntheorem is_o.congr_left {f\u2081 f\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hf : \u2200 x, f\u2081 x = f\u2082 x) :\n  is_o f\u2081 g l \u2192 is_o f\u2082 g l :=\nis_o.congr hf (\u03bb _, rfl)\n\ntheorem is_o.congr_right {g\u2081 g\u2082 : \u03b1 \u2192 E} {l : filter \u03b1} (hg : \u2200 x, g\u2081 x = g\u2082 x) :\n  is_o f g\u2081 l \u2192 is_o f g\u2082 l :=\nis_o.congr (\u03bb _, rfl) hg\n\n/-! ### Filter operations and transitivity -/\n\ntheorem is_O_with.comp_tendsto (hcfg : is_O_with c f g l)\n  {k : \u03b2 \u2192 \u03b1} {l' : filter \u03b2} (hk : tendsto k l' l):\n  is_O_with c (f \u2218 k) (g \u2218 k) l' :=\nis_O_with.of_bound $ hk hcfg.bound\n\ntheorem is_O.comp_tendsto (hfg : is_O f g l) {k : \u03b2 \u2192 \u03b1} {l' : filter \u03b2} (hk : tendsto k l' l) :\n  is_O (f \u2218 k) (g \u2218 k) l' :=\nis_O_iff_is_O_with.2 $ hfg.is_O_with.imp (\u03bb c h, h.comp_tendsto hk)\n\ntheorem is_o.comp_tendsto (hfg : is_o f g l) {k : \u03b2 \u2192 \u03b1} {l' : filter \u03b2} (hk : tendsto k l' l) :\n  is_o (f \u2218 k) (g \u2218 k) l' :=\nis_o.of_is_O_with $ \u03bb c cpos, (hfg.forall_is_O_with cpos).comp_tendsto hk\n\n@[simp] theorem is_O_with_map {k : \u03b2 \u2192 \u03b1} {l : filter \u03b2} :\n  is_O_with c f g (map k l) \u2194 is_O_with c (f \u2218 k) (g \u2218 k) l :=\nby { unfold is_O_with, exact mem_map }\n\n@[simp] theorem is_O_map {k : \u03b2 \u2192 \u03b1} {l : filter \u03b2} :\n  is_O f g (map k l) \u2194 is_O (f \u2218 k) (g \u2218 k) l :=\nby simp only [is_O, is_O_with_map]\n\n@[simp] theorem is_o_map {k : \u03b2 \u2192 \u03b1} {l : filter \u03b2} :\n  is_o f g (map k l) \u2194 is_o (f \u2218 k) (g \u2218 k) l :=\nby simp only [is_o, is_O_with_map]\n\ntheorem is_O_with.mono (h : is_O_with c f g l') (hl : l \u2264 l') : is_O_with c f g l :=\nis_O_with.of_bound $ hl h.bound\n\ntheorem is_O.mono (h : is_O f g l') (hl : l \u2264 l') : is_O f g l :=\nis_O_iff_is_O_with.2 $ h.is_O_with.imp (\u03bb c h, h.mono hl)\n\ntheorem is_o.mono (h : is_o f g l') (hl : l \u2264 l') : is_o f g l :=\nis_o.of_is_O_with $ \u03bb c cpos, (h.forall_is_O_with cpos).mono hl\n\ntheorem is_O_with.trans (hfg : is_O_with c f g l) (hgk : is_O_with c' g k l) (hc : 0 \u2264 c) :\n  is_O_with (c * c') f k l :=\nbegin\n  unfold is_O_with at *,\n  filter_upwards [hfg, hgk] with x hx hx',\n  calc \u2225f x\u2225 \u2264 c * \u2225g x\u2225 : hx\n  ... \u2264 c * (c' * \u2225k x\u2225) : mul_le_mul_of_nonneg_left hx' hc\n  ... = c * c' * \u2225k x\u2225 : (mul_assoc _ _ _).symm\nend\n\ntheorem is_O.trans (hfg : is_O f g' l) (hgk : is_O g' k l) : is_O f k l :=\nlet \u27e8c, cnonneg, hc\u27e9 := hfg.exists_nonneg, \u27e8c', hc'\u27e9 := hgk.is_O_with in\n(hc.trans hc' cnonneg).is_O\n\ntheorem is_o.trans_is_O_with (hfg : is_o f g l) (hgk : is_O_with c g k l) (hc : 0 < c) :\n  is_o f k l :=\nbegin\n  unfold is_o at *,\n  intros c' c'pos,\n  have : 0 < c' / c, from div_pos c'pos hc,\n  exact ((hfg this).trans hgk (le_of_lt this)).congr_const (div_mul_cancel _ (ne_of_gt hc))\nend\n\ntheorem is_o.trans_is_O (hfg : is_o f g l) (hgk : is_O g k' l) : is_o f k' l :=\nlet \u27e8c, cpos, hc\u27e9 := hgk.exists_pos in hfg.trans_is_O_with hc cpos\n\ntheorem is_O_with.trans_is_o (hfg : is_O_with c f g l) (hgk : is_o g k l) (hc : 0 < c) :\n  is_o f k l :=\nbegin\n  unfold is_o at *,\n  intros c' c'pos,\n  have : 0 < c' / c, from div_pos c'pos hc,\n  exact (hfg.trans (hgk this) (le_of_lt hc)).congr_const (mul_div_cancel' _ (ne_of_gt hc))\nend\n\ntheorem is_O.trans_is_o (hfg : is_O f g' l) (hgk : is_o g' k l) : is_o f k l :=\nlet \u27e8c, cpos, hc\u27e9 := hfg.exists_pos in hc.trans_is_o hgk cpos\n\ntheorem is_o.trans (hfg : is_o f g l) (hgk : is_o g k' l) : is_o f k' l :=\nhfg.trans_is_O hgk.is_O\n\ntheorem is_o.trans' (hfg : is_o f g' l) (hgk : is_o g' k l) : is_o f k l :=\nhfg.is_O.trans_is_o hgk\n\nsection\n\nvariable (l)\n\ntheorem is_O_with_of_le' (hfg : \u2200 x, \u2225f x\u2225 \u2264 c * \u2225g x\u2225) : is_O_with c f g l :=\nis_O_with.of_bound $ univ_mem' hfg\n\ntheorem is_O_with_of_le (hfg : \u2200 x, \u2225f x\u2225 \u2264 \u2225g x\u2225) : is_O_with 1 f g l :=\nis_O_with_of_le' l $ \u03bb x, by { rw one_mul, exact hfg x }\n\ntheorem is_O_of_le' (hfg : \u2200 x, \u2225f x\u2225 \u2264 c * \u2225g x\u2225) : is_O f g l :=\n(is_O_with_of_le' l hfg).is_O\n\ntheorem is_O_of_le (hfg : \u2200 x, \u2225f x\u2225 \u2264 \u2225g x\u2225) : is_O f g l :=\n(is_O_with_of_le l hfg).is_O\n\nend\n\ntheorem is_O_with_refl (f : \u03b1 \u2192 E) (l : filter \u03b1) : is_O_with 1 f f l :=\nis_O_with_of_le l $ \u03bb _, le_rfl\n\ntheorem is_O_refl (f : \u03b1 \u2192 E) (l : filter \u03b1) : is_O f f l := (is_O_with_refl f l).is_O\n\ntheorem is_O_with.trans_le (hfg : is_O_with c f g l) (hgk : \u2200 x, \u2225g x\u2225 \u2264 \u2225k x\u2225) (hc : 0 \u2264 c) :\n  is_O_with c f k l :=\n(hfg.trans (is_O_with_of_le l hgk) hc).congr_const $ mul_one c\n\ntheorem is_O.trans_le (hfg : is_O f g' l) (hgk : \u2200 x, \u2225g' x\u2225 \u2264 \u2225k x\u2225) :\n  is_O f k l :=\nhfg.trans (is_O_of_le l hgk)\n\ntheorem is_o.trans_le (hfg : is_o f g l) (hgk : \u2200 x, \u2225g x\u2225 \u2264 \u2225k x\u2225) :\n  is_o f k l :=\nhfg.trans_is_O_with (is_O_with_of_le _ hgk) zero_lt_one\n\nsection bot\n\nvariables (c f g)\n\n@[simp] theorem is_O_with_bot : is_O_with c f g \u22a5 := is_O_with.of_bound $ trivial\n\n@[simp] theorem is_O_bot : is_O f g \u22a5 := (is_O_with_bot 1 f g).is_O\n\n@[simp] theorem is_o_bot : is_o f g \u22a5 := is_o.of_is_O_with $ \u03bb c _, is_O_with_bot c f g\n\nend bot\n\n@[simp] theorem is_O_with_pure {x} : is_O_with c f g (pure x) \u2194 \u2225f x\u2225 \u2264 c * \u2225g x\u2225 := is_O_with_iff\n\ntheorem is_O_with.join (h : is_O_with c f g l) (h' : is_O_with c f g l') :\n  is_O_with c f g (l \u2294 l') :=\nis_O_with.of_bound $ mem_sup.2 \u27e8h.bound, h'.bound\u27e9\n\ntheorem is_O_with.join' (h : is_O_with c f g' l) (h' : is_O_with c' f g' l') :\n  is_O_with (max c c') f g' (l \u2294 l') :=\nis_O_with.of_bound $\nmem_sup.2 \u27e8(h.weaken $ le_max_left c c').bound, (h'.weaken $ le_max_right c c').bound\u27e9\n\ntheorem is_O.join (h : is_O f g' l) (h' : is_O f g' l') : is_O f g' (l \u2294 l') :=\nlet \u27e8c, hc\u27e9 := h.is_O_with, \u27e8c', hc'\u27e9 := h'.is_O_with in (hc.join' hc').is_O\n\ntheorem is_o.join (h : is_o f g l) (h' : is_o f g l') :\n  is_o f g (l \u2294 l') :=\nis_o.of_is_O_with $\n\u03bb c cpos, (h.forall_is_O_with cpos).join (h'.forall_is_O_with cpos)\n\n/-! ### Simplification : norm -/\n\n@[simp] theorem is_O_with_norm_right : is_O_with c f (\u03bb x, \u2225g' x\u2225) l \u2194 is_O_with c f g' l :=\nby simp only [is_O_with, norm_norm]\n\nalias is_O_with_norm_right \u2194 asymptotics.is_O_with.of_norm_right asymptotics.is_O_with.norm_right\n\n@[simp] theorem is_O_norm_right : is_O f (\u03bb x, \u2225g' x\u2225) l \u2194 is_O f g' l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_norm_right) }\n\nalias is_O_norm_right \u2194 asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right\n\n@[simp] theorem is_o_norm_right : is_o f (\u03bb x, \u2225g' x\u2225) l \u2194 is_o f g' l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_norm_right) }\n\nalias is_o_norm_right \u2194 asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right\n\n@[simp] theorem is_O_with_norm_left : is_O_with c (\u03bb x, \u2225f' x\u2225) g l \u2194 is_O_with c f' g l :=\nby simp only [is_O_with, norm_norm]\n\nalias is_O_with_norm_left \u2194 asymptotics.is_O_with.of_norm_left asymptotics.is_O_with.norm_left\n\n@[simp] theorem is_O_norm_left : is_O (\u03bb x, \u2225f' x\u2225) g l \u2194 is_O f' g l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_norm_left) }\n\nalias is_O_norm_left \u2194 asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left\n\n@[simp] theorem is_o_norm_left : is_o (\u03bb x, \u2225f' x\u2225) g l \u2194 is_o f' g l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_norm_left) }\n\nalias is_o_norm_left \u2194 asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left\n\ntheorem is_O_with_norm_norm :\n  is_O_with c (\u03bb x, \u2225f' x\u2225) (\u03bb x, \u2225g' x\u2225) l \u2194 is_O_with c f' g' l :=\nis_O_with_norm_left.trans is_O_with_norm_right\n\nalias is_O_with_norm_norm \u2194 asymptotics.is_O_with.of_norm_norm asymptotics.is_O_with.norm_norm\n\ntheorem is_O_norm_norm :\n  is_O (\u03bb x, \u2225f' x\u2225) (\u03bb x, \u2225g' x\u2225) l \u2194 is_O f' g' l :=\nis_O_norm_left.trans is_O_norm_right\n\nalias is_O_norm_norm \u2194 asymptotics.is_O.of_norm_norm asymptotics.is_O.norm_norm\n\ntheorem is_o_norm_norm :\n  is_o (\u03bb x, \u2225f' x\u2225) (\u03bb x, \u2225g' x\u2225) l \u2194 is_o f' g' l :=\nis_o_norm_left.trans is_o_norm_right\n\nalias is_o_norm_norm \u2194 asymptotics.is_o.of_norm_norm asymptotics.is_o.norm_norm\n\n/-! ### Simplification: negate -/\n\n@[simp] theorem is_O_with_neg_right : is_O_with c f (\u03bb x, -(g' x)) l \u2194 is_O_with c f g' l :=\nby simp only [is_O_with, norm_neg]\n\nalias is_O_with_neg_right \u2194 asymptotics.is_O_with.of_neg_right asymptotics.is_O_with.neg_right\n\n@[simp] theorem is_O_neg_right : is_O f (\u03bb x, -(g' x)) l \u2194 is_O f g' l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_neg_right) }\n\nalias is_O_neg_right \u2194 asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right\n\n@[simp] theorem is_o_neg_right : is_o f (\u03bb x, -(g' x)) l \u2194 is_o f g' l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_neg_right) }\n\nalias is_o_neg_right \u2194 asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right\n\n@[simp] theorem is_O_with_neg_left : is_O_with c (\u03bb x, -(f' x)) g l \u2194 is_O_with c f' g l :=\nby simp only [is_O_with, norm_neg]\n\nalias is_O_with_neg_left \u2194 asymptotics.is_O_with.of_neg_left asymptotics.is_O_with.neg_left\n\n@[simp] theorem is_O_neg_left : is_O (\u03bb x, -(f' x)) g l \u2194 is_O f' g l :=\nby { unfold is_O, exact exists_congr (\u03bb _, is_O_with_neg_left) }\n\nalias is_O_neg_left \u2194 asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left\n\n@[simp] theorem is_o_neg_left : is_o (\u03bb x, -(f' x)) g l \u2194 is_o f' g l :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb _ _, is_O_with_neg_left) }\n\nalias is_o_neg_left \u2194 asymptotics.is_o.of_neg_right asymptotics.is_o.neg_left\n\n/-! ### Product of functions (right) -/\n\nlemma is_O_with_fst_prod : is_O_with 1 f' (\u03bb x, (f' x, g' x)) l :=\nis_O_with_of_le l $ \u03bb x, le_max_left _ _\n\nlemma is_O_with_snd_prod : is_O_with 1 g' (\u03bb x, (f' x, g' x)) l :=\nis_O_with_of_le l $ \u03bb x, le_max_right _ _\n\nlemma is_O_fst_prod : is_O f' (\u03bb x, (f' x, g' x)) l := is_O_with_fst_prod.is_O\n\nlemma is_O_snd_prod : is_O g' (\u03bb x, (f' x, g' x)) l := is_O_with_snd_prod.is_O\n\nlemma is_O_fst_prod' {f' : \u03b1 \u2192 E' \u00d7 F'} : is_O (\u03bb x, (f' x).1) f' l :=\nby simpa [is_O, is_O_with] using is_O_fst_prod\n\nlemma is_O_snd_prod' {f' : \u03b1 \u2192 E' \u00d7 F'} : is_O (\u03bb x, (f' x).2) f' l :=\nby simpa [is_O, is_O_with] using is_O_snd_prod\n\nsection\n\nvariables (f' k')\n\n\n\nlemma is_O.prod_rightl (h : is_O f g' l) : is_O f (\u03bbx, (g' x, k' x)) l :=\nlet \u27e8c, cnonneg, hc\u27e9 := h.exists_nonneg in (hc.prod_rightl k' cnonneg).is_O\n\nlemma is_o.prod_rightl (h : is_o f g' l) : is_o f (\u03bb x, (g' x, k' x)) l :=\nis_o.of_is_O_with $\n\u03bb c cpos, (h.forall_is_O_with cpos).prod_rightl k' (le_of_lt cpos)\n\nlemma is_O_with.prod_rightr (h : is_O_with c f g' l) (hc : 0 \u2264 c) :\n  is_O_with c f (\u03bb x, (f' x, g' x)) l :=\n(h.trans is_O_with_snd_prod hc).congr_const (mul_one c)\n\nlemma is_O.prod_rightr (h : is_O f g' l) : is_O f (\u03bbx, (f' x, g' x)) l :=\nlet \u27e8c, cnonneg, hc\u27e9 := h.exists_nonneg in (hc.prod_rightr f' cnonneg).is_O\n\nlemma is_o.prod_rightr (h : is_o f g' l) : is_o f (\u03bbx, (f' x, g' x)) l :=\nis_o.of_is_O_with $\n\u03bb c cpos, (h.forall_is_O_with cpos).prod_rightr f' (le_of_lt cpos)\n\nend\n\nlemma is_O_with.prod_left_same (hf : is_O_with c f' k' l) (hg : is_O_with c g' k' l) :\n  is_O_with c (\u03bb x, (f' x, g' x)) k' l :=\nby rw is_O_with_iff at *; filter_upwards [hf, hg] with x using max_le\n\nlemma is_O_with.prod_left (hf : is_O_with c f' k' l) (hg : is_O_with c' g' k' l) :\n  is_O_with (max c c') (\u03bb x, (f' x, g' x)) k' l :=\n(hf.weaken $ le_max_left c c').prod_left_same (hg.weaken $ le_max_right c c')\n\nlemma is_O_with.prod_left_fst (h : is_O_with c (\u03bb x, (f' x, g' x)) k' l) :\n  is_O_with c f' k' l :=\n(is_O_with_fst_prod.trans h zero_le_one).congr_const $ one_mul c\n\nlemma is_O_with.prod_left_snd (h : is_O_with c (\u03bb x, (f' x, g' x)) k' l) :\n  is_O_with c g' k' l :=\n(is_O_with_snd_prod.trans h zero_le_one).congr_const $ one_mul c\n\nlemma is_O_with_prod_left :\n   is_O_with c (\u03bb x, (f' x, g' x)) k' l \u2194 is_O_with c f' k' l \u2227 is_O_with c g' k' l :=\n\u27e8\u03bb h, \u27e8h.prod_left_fst, h.prod_left_snd\u27e9, \u03bb h, h.1.prod_left_same h.2\u27e9\n\nlemma is_O.prod_left (hf : is_O f' k' l) (hg : is_O g' k' l) : is_O (\u03bb x, (f' x, g' x)) k' l :=\nlet \u27e8c, hf\u27e9 := hf.is_O_with, \u27e8c', hg\u27e9 := hg.is_O_with in (hf.prod_left hg).is_O\n\nlemma is_O.prod_left_fst (h : is_O (\u03bb x, (f' x, g' x)) k' l) : is_O f' k' l :=\nis_O_fst_prod.trans h\n\nlemma is_O.prod_left_snd (h : is_O (\u03bb x, (f' x, g' x)) k' l) : is_O g' k' l :=\nis_O_snd_prod.trans h\n\n@[simp] lemma is_O_prod_left :\n  is_O (\u03bb x, (f' x, g' x)) k' l \u2194 is_O f' k' l \u2227 is_O g' k' l :=\n\u27e8\u03bb h, \u27e8h.prod_left_fst, h.prod_left_snd\u27e9, \u03bb h, h.1.prod_left h.2\u27e9\n\nlemma is_o.prod_left (hf : is_o f' k' l) (hg : is_o g' k' l) : is_o (\u03bb x, (f' x, g' x)) k' l :=\nis_o.of_is_O_with $\n\u03bb c hc, (hf.forall_is_O_with hc).prod_left_same (hg.forall_is_O_with hc)\n\nlemma is_o.prod_left_fst (h : is_o (\u03bb x, (f' x, g' x)) k' l) : is_o f' k' l :=\nis_O_fst_prod.trans_is_o h\n\nlemma is_o.prod_left_snd (h : is_o (\u03bb x, (f' x, g' x)) k' l) : is_o g' k' l :=\nis_O_snd_prod.trans_is_o h\n\n@[simp] lemma is_o_prod_left :\n  is_o (\u03bb x, (f' x, g' x)) k' l \u2194 is_o f' k' l \u2227 is_o g' k' l :=\n\u27e8\u03bb h, \u27e8h.prod_left_fst, h.prod_left_snd\u27e9, \u03bb h, h.1.prod_left h.2\u27e9\n\nlemma is_O_with.eq_zero_imp (h : is_O_with c f' g' l) : \u2200\u1da0 x in l, g' x = 0 \u2192 f' x = 0 :=\neventually.mono h.bound $ \u03bb x hx hg, norm_le_zero_iff.1 $ by simpa [hg] using hx\n\nlemma is_O.eq_zero_imp (h : is_O f' g' l) : \u2200\u1da0 x in l, g' x = 0 \u2192 f' x = 0 :=\nlet \u27e8C, hC\u27e9 := h.is_O_with in hC.eq_zero_imp\n\n/-! ### Addition and subtraction -/\n\nsection add_sub\n\nvariables {c\u2081 c\u2082 : \u211d} {f\u2081 f\u2082 : \u03b1 \u2192 E'}\n\ntheorem is_O_with.add (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_O_with c\u2082 f\u2082 g l) :\n  is_O_with (c\u2081 + c\u2082) (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nby rw is_O_with at *; filter_upwards [h\u2081, h\u2082] with x hx\u2081 hx\u2082 using\ncalc \u2225f\u2081 x + f\u2082 x\u2225 \u2264 c\u2081 * \u2225g x\u2225 + c\u2082 * \u2225g x\u2225 : norm_add_le_of_le hx\u2081 hx\u2082\n               ... = (c\u2081 + c\u2082) * \u2225g x\u2225       : (add_mul _ _ _).symm\n\ntheorem is_O.add (h\u2081 : is_O f\u2081 g l) (h\u2082 : is_O f\u2082 g l) : is_O (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nlet \u27e8c\u2081, hc\u2081\u27e9 := h\u2081.is_O_with, \u27e8c\u2082, hc\u2082\u27e9 := h\u2082.is_O_with in (hc\u2081.add hc\u2082).is_O\n\ntheorem is_o.add (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_o f\u2082 g l) : is_o (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nis_o.of_is_O_with $ \u03bb c cpos, ((h\u2081.forall_is_O_with $ half_pos cpos).add\n  (h\u2082.forall_is_O_with $ half_pos cpos)).congr_const (add_halves c)\n\ntheorem is_o.add_add {g\u2081 g\u2082 : \u03b1 \u2192 F'} (h\u2081 : is_o f\u2081 g\u2081 l) (h\u2082 : is_o f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x + f\u2082 x) (\u03bb x, \u2225g\u2081 x\u2225 + \u2225g\u2082 x\u2225) l :=\nby refine (h\u2081.trans_le $ \u03bb x, _).add (h\u2082.trans_le _);\n  simp [real.norm_eq_abs, abs_of_nonneg, add_nonneg]\n\ntheorem is_O.add_is_o (h\u2081 : is_O f\u2081 g l) (h\u2082 : is_o f\u2082 g l) : is_O (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nh\u2081.add h\u2082.is_O\n\ntheorem is_o.add_is_O (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_O f\u2082 g l) : is_O (\u03bb x, f\u2081 x + f\u2082 x) g l :=\nh\u2081.is_O.add h\u2082\n\ntheorem is_O_with.add_is_o (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_o f\u2082 g l) (hc : c\u2081 < c\u2082) :\n  is_O_with c\u2082 (\u03bbx, f\u2081 x + f\u2082 x) g l :=\n(h\u2081.add (h\u2082.forall_is_O_with (sub_pos.2 hc))).congr_const (add_sub_cancel'_right _ _)\n\ntheorem is_o.add_is_O_with (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_O_with c\u2081 f\u2082 g l) (hc : c\u2081 < c\u2082) :\n  is_O_with c\u2082 (\u03bbx, f\u2081 x + f\u2082 x) g l :=\n(h\u2082.add_is_o h\u2081 hc).congr_left $ \u03bb _, add_comm _ _\n\ntheorem is_O_with.sub (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_O_with c\u2082 f\u2082 g l) :\n  is_O_with (c\u2081 + c\u2082) (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add h\u2082.neg_left\n\ntheorem is_O_with.sub_is_o (h\u2081 : is_O_with c\u2081 f\u2081 g l) (h\u2082 : is_o f\u2082 g l) (hc : c\u2081 < c\u2082) :\n  is_O_with c\u2082 (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add_is_o h\u2082.neg_left hc\n\ntheorem is_O.sub (h\u2081 : is_O f\u2081 g l) (h\u2082 : is_O f\u2082 g l) : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add h\u2082.neg_left\n\ntheorem is_o.sub (h\u2081 : is_o f\u2081 g l) (h\u2082 : is_o f\u2082 g l) : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l :=\nby simpa only [sub_eq_add_neg] using h\u2081.add h\u2082.neg_left\n\nend add_sub\n\n/-! ### Lemmas about `is_O (f\u2081 - f\u2082) g l` / `is_o (f\u2081 - f\u2082) g l` treated as a binary relation -/\n\nsection is_oO_as_rel\n\nvariables {f\u2081 f\u2082 f\u2083 : \u03b1 \u2192 E'}\n\ntheorem is_O_with.symm (h : is_O_with c (\u03bb x, f\u2081 x - f\u2082 x) g l) :\n  is_O_with c (\u03bb x, f\u2082 x - f\u2081 x) g l :=\nh.neg_left.congr_left $ \u03bb x, neg_sub _ _\n\ntheorem is_O_with_comm :\n  is_O_with c (\u03bb x, f\u2081 x - f\u2082 x) g l \u2194 is_O_with c (\u03bb x, f\u2082 x - f\u2081 x) g l :=\n\u27e8is_O_with.symm, is_O_with.symm\u27e9\n\ntheorem is_O.symm (h : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l) : is_O (\u03bb x, f\u2082 x - f\u2081 x) g l :=\nh.neg_left.congr_left $ \u03bb x, neg_sub _ _\n\ntheorem is_O_comm : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l \u2194 is_O (\u03bb x, f\u2082 x - f\u2081 x) g l :=\n\u27e8is_O.symm, is_O.symm\u27e9\n\ntheorem is_o.symm (h : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l) : is_o (\u03bb x, f\u2082 x - f\u2081 x) g l :=\nby simpa only [neg_sub] using h.neg_left\n\ntheorem is_o_comm : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l \u2194 is_o (\u03bb x, f\u2082 x - f\u2081 x) g l :=\n\u27e8is_o.symm, is_o.symm\u27e9\n\ntheorem is_O_with.triangle (h\u2081 : is_O_with c (\u03bb x, f\u2081 x - f\u2082 x) g l)\n  (h\u2082 : is_O_with c' (\u03bb x, f\u2082 x - f\u2083 x) g l) :\n  is_O_with (c + c') (\u03bb x, f\u2081 x - f\u2083 x) g l :=\n(h\u2081.add h\u2082).congr_left $ \u03bb x, sub_add_sub_cancel _ _ _\n\ntheorem is_O.triangle (h\u2081 : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l) (h\u2082 : is_O (\u03bb x, f\u2082 x - f\u2083 x) g l) :\n  is_O (\u03bb x, f\u2081 x - f\u2083 x) g l :=\n(h\u2081.add h\u2082).congr_left $ \u03bb x, sub_add_sub_cancel _ _ _\n\ntheorem is_o.triangle (h\u2081 : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l) (h\u2082 : is_o (\u03bb x, f\u2082 x - f\u2083 x) g l) :\n  is_o (\u03bb x, f\u2081 x - f\u2083 x) g l :=\n(h\u2081.add h\u2082).congr_left $ \u03bb x, sub_add_sub_cancel _ _ _\n\ntheorem is_O.congr_of_sub (h : is_O (\u03bb x, f\u2081 x - f\u2082 x) g l) :\n  is_O f\u2081 g l \u2194 is_O f\u2082 g l :=\n\u27e8\u03bb h', (h'.sub h).congr_left (\u03bb x, sub_sub_cancel _ _),\n \u03bb h', (h.add h').congr_left (\u03bb x, sub_add_cancel _ _)\u27e9\n\ntheorem is_o.congr_of_sub (h : is_o (\u03bb x, f\u2081 x - f\u2082 x) g l) :\n  is_o f\u2081 g l \u2194 is_o f\u2082 g l :=\n\u27e8\u03bb h', (h'.sub h).congr_left (\u03bb x, sub_sub_cancel _ _),\n \u03bb h', (h.add h').congr_left (\u03bb x, sub_add_cancel _ _)\u27e9\n\nend is_oO_as_rel\n\n/-! ### Zero, one, and other constants -/\n\nsection zero_const\n\nvariables (g g' l)\n\ntheorem is_o_zero : is_o (\u03bb x, (0 : E')) g' l :=\nis_o.of_bound $ \u03bb c hc, univ_mem' $ \u03bb x,\nby simpa using mul_nonneg hc.le (norm_nonneg $ g' x)\n\ntheorem is_O_with_zero (hc : 0 \u2264 c) : is_O_with c (\u03bb x, (0 : E')) g' l :=\nis_O_with.of_bound $ univ_mem' $ \u03bb x, by simpa using mul_nonneg hc (norm_nonneg $ g' x)\n\ntheorem is_O_with_zero' : is_O_with 0 (\u03bb x, (0 : E')) g l :=\nis_O_with.of_bound $ univ_mem' $ \u03bb x, by simp\n\ntheorem is_O_zero : is_O (\u03bb x, (0 : E')) g l :=\nis_O_iff_is_O_with.2 \u27e80, is_O_with_zero' _ _\u27e9\n\ntheorem is_O_refl_left : is_O (\u03bb x, f' x - f' x) g' l :=\n(is_O_zero g' l).congr_left $ \u03bb x, (sub_self _).symm\n\ntheorem is_o_refl_left : is_o (\u03bb x, f' x - f' x) g' l :=\n(is_o_zero g' l).congr_left $ \u03bb x, (sub_self _).symm\n\nvariables {g g' l}\n\n@[simp] theorem is_O_with_zero_right_iff :\n  is_O_with c f' (\u03bb x, (0 : F')) l \u2194 \u2200\u1da0 x in l, f' x = 0 :=\nby simp only [is_O_with, exists_prop, true_and, norm_zero, mul_zero, norm_le_zero_iff]\n\n@[simp] theorem is_O_zero_right_iff : is_O f' (\u03bb x, (0 : F')) l \u2194 \u2200\u1da0 x in l, f' x = 0 :=\n\u27e8\u03bb h, let \u27e8c, hc\u27e9 := h.is_O_with in is_O_with_zero_right_iff.1 hc,\n  \u03bb h, (is_O_with_zero_right_iff.2 h : is_O_with 1 _ _ _).is_O\u27e9\n\n@[simp] theorem is_o_zero_right_iff :\n  is_o f' (\u03bb x, (0 : F')) l \u2194 \u2200\u1da0 x in l, f' x = 0 :=\n\u27e8\u03bb h, is_O_zero_right_iff.1 h.is_O,\n  \u03bb h, is_o.of_is_O_with $ \u03bb c hc, is_O_with_zero_right_iff.2 h\u27e9\n\ntheorem is_O_with_const_const (c : E) {c' : F'} (hc' : c' \u2260 0) (l : filter \u03b1) :\n  is_O_with (\u2225c\u2225 / \u2225c'\u2225) (\u03bb x : \u03b1, c) (\u03bb x, c') l :=\nbegin\n  unfold is_O_with,\n  apply univ_mem',\n  intro x,\n  rw [mem_set_of_eq, div_mul_cancel],\n  rwa [ne.def, norm_eq_zero]\nend\n\ntheorem is_O_const_const (c : E) {c' : F'} (hc' : c' \u2260 0) (l : filter \u03b1) :\n  is_O (\u03bb x : \u03b1, c) (\u03bb x, c') l :=\n(is_O_with_const_const c hc' l).is_O\n\n@[simp] theorem is_O_const_const_iff {c : E'} {c' : F'} (l : filter \u03b1) [l.ne_bot] :\n  is_O (\u03bb x : \u03b1, c) (\u03bb x, c') l \u2194 (c' = 0 \u2192 c = 0) :=\nbegin\n  rcases eq_or_ne c' 0 with rfl|hc',\n  { simp },\n  { simp [hc', is_O_const_const _ hc'] }\nend\n\n@[simp] lemma is_O_pure {x} : is_O f' g' (pure x) \u2194 (g' x = 0 \u2192 f' x = 0) :=\ncalc is_O f' g' (pure x) \u2194 is_O (\u03bb y : \u03b1, f' x) (\u03bb _, g' x) (pure x) : is_O_congr rfl rfl\n                     ... \u2194 g' x = 0 \u2192 f' x = 0                       : is_O_const_const_iff _\n\nend zero_const\n\n@[simp] lemma is_O_with_top : is_O_with c f g \u22a4 \u2194 \u2200 x, \u2225f x\u2225 \u2264 c * \u2225g x\u2225 := by rw is_O_with; refl\n\n@[simp] lemma is_O_top : is_O f g \u22a4 \u2194 \u2203 C, \u2200 x, \u2225f x\u2225 \u2264 C * \u2225g x\u2225 := by rw is_O_iff; refl\n\n@[simp] lemma is_o_top : is_o f' g' \u22a4 \u2194 \u2200 x, f' x = 0 :=\nbegin\n  refine \u27e8_, \u03bb h, (is_o_zero g' \u22a4).congr (\u03bb x, (h x).symm) (\u03bb x, rfl)\u27e9,\n  simp only [is_o_iff, eventually_top],\n  refine \u03bb h x, norm_le_zero_iff.1 _,\n  have : tendsto (\u03bb c : \u211d, c * \u2225g' x\u2225) (\ud835\udcdd[>] 0) (\ud835\udcdd 0) :=\n    ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left,\n  exact le_of_tendsto_of_tendsto tendsto_const_nhds this\n    (eventually_nhds_within_iff.2 $ eventually_of_forall $ \u03bb c hc, h hc x)\nend\n\n@[simp] lemma is_O_with_principal {s : set \u03b1} :\n  is_O_with c f g (\ud835\udcdf s) \u2194 \u2200 x \u2208 s, \u2225f x\u2225 \u2264 c * \u2225g x\u2225 :=\nby rw is_O_with; refl\n\nlemma is_O_principal {s : set \u03b1} :\n  is_O f g (\ud835\udcdf s) \u2194 \u2203 c, \u2200 x \u2208 s, \u2225f x\u2225 \u2264 c * \u2225g x\u2225 :=\nby rw is_O_iff; refl\n\ntheorem is_O_with_const_one (c : E) (l : filter \u03b1) : is_O_with \u2225c\u2225 (\u03bb x : \u03b1, c) (\u03bb x, (1 : \ud835\udd5c)) l :=\nbegin\n  refine (is_O_with_const_const c _ l).congr_const _,\n  { rw [norm_one, div_one] },\n  { exact one_ne_zero }\nend\n\ntheorem is_O_const_one (c : E) (l : filter \u03b1) : is_O (\u03bb x : \u03b1, c) (\u03bb x, (1 : \ud835\udd5c)) l :=\n(is_O_with_const_one c l).is_O\n\nsection\n\nvariable (\ud835\udd5c)\n\ntheorem is_o_const_iff_is_o_one {c : F'} (hc : c \u2260 0) :\n  is_o f (\u03bb x, c) l \u2194 is_o f (\u03bb x, (1:\ud835\udd5c)) l :=\n\u27e8\u03bb h, h.trans_is_O $ is_O_const_one c l, \u03bb h, h.trans_is_O $ is_O_const_const _ hc _\u27e9\n\nend\n\ntheorem is_o_const_iff {c : F'} (hc : c \u2260 0) :\n  is_o f' (\u03bb x, c) l \u2194 tendsto f' l (\ud835\udcdd 0) :=\n(is_o_const_iff_is_o_one \u211d hc).trans\nbegin\n  clear hc c,\n  simp only [is_o, is_O_with, norm_one, mul_one, metric.nhds_basis_closed_ball.tendsto_right_iff,\n    metric.mem_closed_ball, dist_zero_right]\nend\n\nlemma is_o_id_const {c : F'} (hc : c \u2260 0) :\n  is_o (\u03bb (x : E'), x) (\u03bb x, c) (\ud835\udcdd 0) :=\n(is_o_const_iff hc).mpr (continuous_id.tendsto 0)\n\ntheorem _root_.filter.is_bounded_under.is_O_const (h : is_bounded_under (\u2264) l (norm \u2218 f))\n  {c : F'} (hc : c \u2260 0) : is_O f (\u03bb x, c) l :=\nbegin\n  rcases h with \u27e8C, hC\u27e9,\n  refine (is_O.of_bound 1 _).trans (is_O_const_const C hc l),\n  refine (eventually_map.1 hC).mono (\u03bb x h, _),\n  calc \u2225f x\u2225 \u2264 C : h\n  ... \u2264 abs C : le_abs_self C\n  ... = 1 * \u2225C\u2225 : (one_mul _).symm\nend\n\ntheorem is_O_const_of_tendsto {y : E'} (h : tendsto f' l (\ud835\udcdd y)) {c : F'} (hc : c \u2260 0) :\n  is_O f' (\u03bb x, c) l :=\nh.norm.is_bounded_under_le.is_O_const hc\n\nsection\n\nvariable (\ud835\udd5c)\n\ntheorem is_o_one_iff : is_o f' (\u03bb x, (1 : \ud835\udd5c)) l \u2194 tendsto f' l (\ud835\udcdd 0) :=\nis_o_const_iff one_ne_zero\n\ntheorem is_O_one_of_tendsto {y : E'} (h : tendsto f' l (\ud835\udcdd y)) :\n  is_O f' (\u03bb x, (1:\ud835\udd5c)) l :=\nis_O_const_of_tendsto h one_ne_zero\n\ntheorem is_O.trans_tendsto_nhds (hfg : is_O f g' l) {y : F'} (hg : tendsto g' l (\ud835\udcdd y)) :\n  is_O f (\u03bb x, (1:\ud835\udd5c)) l :=\nhfg.trans $ is_O_one_of_tendsto \ud835\udd5c hg\n\nend\n\ntheorem is_O.trans_tendsto (hfg : is_O f' g' l) (hg : tendsto g' l (\ud835\udcdd 0)) :\n  tendsto f' l (\ud835\udcdd 0) :=\n(is_o_one_iff \u211d).1 $ hfg.trans_is_o $ (is_o_one_iff \u211d).2 hg\n\ntheorem is_o.trans_tendsto (hfg : is_o f' g' l) (hg : tendsto g' l (\ud835\udcdd 0)) :\n  tendsto f' l (\ud835\udcdd 0) :=\nhfg.is_O.trans_tendsto hg\n\n/-! ### Multiplication by a constant -/\n\ntheorem is_O_with_const_mul_self (c : R) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O_with \u2225c\u2225 (\u03bb x, c * f x) f l :=\nis_O_with_of_le' _ $ \u03bb x, norm_mul_le _ _\n\ntheorem is_O_const_mul_self (c : R) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O (\u03bb x, c * f x) f l :=\n(is_O_with_const_mul_self c f l).is_O\n\ntheorem is_O_with.const_mul_left {f : \u03b1 \u2192 R} (h : is_O_with c f g l) (c' : R) :\n  is_O_with (\u2225c'\u2225 * c) (\u03bb x, c' * f x) g l :=\n(is_O_with_const_mul_self c' f l).trans h (norm_nonneg c')\n\ntheorem is_O.const_mul_left {f : \u03b1 \u2192 R} (h : is_O f g l) (c' : R) :\n  is_O (\u03bb x, c' * f x) g l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in (hc.const_mul_left c').is_O\n\ntheorem is_O_with_self_const_mul' (u : R\u02e3) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O_with \u2225(\u2191u\u207b\u00b9:R)\u2225 f (\u03bb x, \u2191u * f x) l :=\n(is_O_with_const_mul_self \u2191u\u207b\u00b9 _ l).congr_left $ \u03bb x, u.inv_mul_cancel_left (f x)\n\ntheorem is_O_with_self_const_mul (c : \ud835\udd5c) (hc : c \u2260 0) (f : \u03b1 \u2192 \ud835\udd5c) (l : filter \u03b1) :\n  is_O_with \u2225c\u2225\u207b\u00b9 f (\u03bb x, c * f x) l :=\n(is_O_with_self_const_mul' (units.mk0 c hc) f l).congr_const $\n  norm_inv c\n\ntheorem is_O_self_const_mul' {c : R} (hc : is_unit c) (f : \u03b1 \u2192 R) (l : filter \u03b1) :\n  is_O f (\u03bb x, c * f x) l :=\nlet \u27e8u, hu\u27e9 := hc in hu \u25b8 (is_O_with_self_const_mul' u f l).is_O\n\ntheorem is_O_self_const_mul (c : \ud835\udd5c) (hc : c \u2260 0) (f : \u03b1 \u2192 \ud835\udd5c) (l : filter \u03b1) :\n  is_O f (\u03bb x, c * f x) l :=\nis_O_self_const_mul' (is_unit.mk0 c hc) f l\n\ntheorem is_O_const_mul_left_iff' {f : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_O (\u03bb x, c * f x) g l \u2194 is_O f g l :=\n\u27e8(is_O_self_const_mul' hc f l).trans, \u03bb h, h.const_mul_left c\u27e9\n\ntheorem is_O_const_mul_left_iff {f : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O (\u03bb x, c * f x) g l \u2194 is_O f g l :=\nis_O_const_mul_left_iff' $ is_unit.mk0 c hc\n\ntheorem is_o.const_mul_left {f : \u03b1 \u2192 R} (h : is_o f g l) (c : R) :\n  is_o (\u03bb x, c * f x) g l :=\n(is_O_const_mul_self c f l).trans_is_o h\n\ntheorem is_o_const_mul_left_iff' {f : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_o (\u03bb x, c * f x) g l \u2194 is_o f g l :=\n\u27e8(is_O_self_const_mul' hc f l).trans_is_o, \u03bb h, h.const_mul_left c\u27e9\n\ntheorem is_o_const_mul_left_iff {f : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o (\u03bb x, c * f x) g l \u2194 is_o f g l :=\nis_o_const_mul_left_iff' $ is_unit.mk0 c hc\n\ntheorem is_O_with.of_const_mul_right {g : \u03b1 \u2192 R} {c : R} (hc' : 0 \u2264 c')\n  (h : is_O_with c' f (\u03bb x, c * g x) l) :\n  is_O_with (c' * \u2225c\u2225) f g l :=\nh.trans (is_O_with_const_mul_self c g l) hc'\n\ntheorem is_O.of_const_mul_right {g : \u03b1 \u2192 R} {c : R}\n  (h : is_O f (\u03bb x, c * g x) l) :\n  is_O f g l :=\nlet \u27e8c, cnonneg, hc\u27e9 := h.exists_nonneg in (hc.of_const_mul_right cnonneg).is_O\n\ntheorem is_O_with.const_mul_right' {g : \u03b1 \u2192 R} {u : R\u02e3} {c' : \u211d} (hc' : 0 \u2264 c')\n  (h : is_O_with c' f g l) :\n  is_O_with (c' * \u2225(\u2191u\u207b\u00b9:R)\u2225) f (\u03bb x, \u2191u * g x) l :=\nh.trans (is_O_with_self_const_mul' _ _ _) hc'\n\ntheorem is_O_with.const_mul_right {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0)\n  {c' : \u211d} (hc' : 0 \u2264 c') (h : is_O_with c' f g l) :\n  is_O_with (c' * \u2225c\u2225\u207b\u00b9) f (\u03bb x, c * g x) l :=\nh.trans (is_O_with_self_const_mul c hc g l) hc'\n\ntheorem is_O.const_mul_right' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) (h : is_O f g l) :\n  is_O f (\u03bb x, c * g x) l :=\nh.trans (is_O_self_const_mul' hc g l)\n\ntheorem is_O.const_mul_right {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) (h : is_O f g l) :\n  is_O f (\u03bb x, c * g x) l :=\nh.const_mul_right' $ is_unit.mk0 c hc\n\ntheorem is_O_const_mul_right_iff' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_O f (\u03bb x, c * g x) l \u2194 is_O f g l :=\n\u27e8\u03bb h, h.of_const_mul_right, \u03bb h, h.const_mul_right' hc\u27e9\n\ntheorem is_O_const_mul_right_iff {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O f (\u03bb x, c * g x) l \u2194 is_O f g l :=\nis_O_const_mul_right_iff' $ is_unit.mk0 c hc\n\ntheorem is_o.of_const_mul_right {g : \u03b1 \u2192 R} {c : R} (h : is_o f (\u03bb x, c * g x) l) :\n  is_o f g l :=\nh.trans_is_O (is_O_const_mul_self c g l)\n\ntheorem is_o.const_mul_right' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) (h : is_o f g l) :\n  is_o f (\u03bb x, c * g x) l :=\nh.trans_is_O (is_O_self_const_mul' hc g l)\n\ntheorem is_o.const_mul_right {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) (h : is_o f g l) :\n  is_o f (\u03bb x, c * g x) l :=\nh.const_mul_right' $ is_unit.mk0 c hc\n\ntheorem is_o_const_mul_right_iff' {g : \u03b1 \u2192 R} {c : R} (hc : is_unit c) :\n  is_o f (\u03bb x, c * g x) l \u2194 is_o f g l :=\n\u27e8\u03bb h, h.of_const_mul_right, \u03bb h, h.const_mul_right' hc\u27e9\n\ntheorem is_o_const_mul_right_iff {g : \u03b1 \u2192 \ud835\udd5c} {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o f (\u03bb x, c * g x) l \u2194 is_o f g l :=\nis_o_const_mul_right_iff' $ is_unit.mk0 c hc\n\n/-! ### Multiplication -/\n\ntheorem is_O_with.mul {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c} {c\u2081 c\u2082 : \u211d}\n  (h\u2081 : is_O_with c\u2081 f\u2081 g\u2081 l) (h\u2082 : is_O_with c\u2082 f\u2082 g\u2082 l) :\n  is_O_with (c\u2081 * c\u2082) (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nbegin\n  unfold is_O_with at *,\n  filter_upwards [h\u2081, h\u2082] with _ hx\u2081 hx\u2082,\n  apply le_trans (norm_mul_le _ _),\n  convert mul_le_mul hx\u2081 hx\u2082 (norm_nonneg _) (le_trans (norm_nonneg _) hx\u2081) using 1,\n  rw [norm_mul, mul_mul_mul_comm]\nend\n\ntheorem is_O.mul {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c}\n  (h\u2081 : is_O f\u2081 g\u2081 l) (h\u2082 : is_O f\u2082 g\u2082 l) :\n  is_O (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nlet \u27e8c, hc\u27e9 := h\u2081.is_O_with, \u27e8c', hc'\u27e9 := h\u2082.is_O_with in (hc.mul hc').is_O\n\ntheorem is_O.mul_is_o {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c}\n  (h\u2081 : is_O f\u2081 g\u2081 l) (h\u2082 : is_o f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nbegin\n  unfold is_o at *,\n  intros c cpos,\n  rcases h\u2081.exists_pos with \u27e8c', c'pos, hc'\u27e9,\n  exact (hc'.mul (h\u2082 (div_pos cpos c'pos))).congr_const (mul_div_cancel' _ (ne_of_gt c'pos))\nend\n\ntheorem is_o.mul_is_O {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c}\n  (h\u2081 : is_o f\u2081 g\u2081 l) (h\u2082 : is_O f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nbegin\n  unfold is_o at *,\n  intros c cpos,\n  rcases h\u2082.exists_pos with \u27e8c', c'pos, hc'\u27e9,\n  exact ((h\u2081 (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel _ (ne_of_gt c'pos))\nend\n\ntheorem is_o.mul {f\u2081 f\u2082 : \u03b1 \u2192 R} {g\u2081 g\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_o f\u2081 g\u2081 l) (h\u2082 : is_o f\u2082 g\u2082 l) :\n  is_o (\u03bb x, f\u2081 x * f\u2082 x) (\u03bb x, g\u2081 x * g\u2082 x) l :=\nh\u2081.mul_is_O h\u2082.is_O\n\ntheorem is_O_with.pow' {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_O_with c f g l) :\n  \u2200 n : \u2115, is_O_with (nat.cases_on n \u2225(1 : R)\u2225 (\u03bb n, c ^ (n + 1))) (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l\n| 0 := by simpa using is_O_with_const_const (1 : R) (@one_ne_zero \ud835\udd5c _ _) l\n| 1 := by simpa\n| (n + 2) := by simpa [pow_succ] using h.mul (is_O_with.pow' (n + 1))\n\ntheorem is_O_with.pow [norm_one_class R] {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_O_with c f g l) :\n  \u2200 n : \u2115, is_O_with (c ^ n) (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l\n| 0 := by simpa using h.pow' 0\n| (n + 1) := h.pow' (n + 1)\n\ntheorem is_O.pow {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_O f g l) (n : \u2115) :\n  is_O (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l :=\nlet \u27e8C, hC\u27e9 := h.is_O_with in is_O_iff_is_O_with.2 \u27e8_, hC.pow' n\u27e9\n\ntheorem is_o.pow {f : \u03b1 \u2192 R} {g : \u03b1 \u2192 \ud835\udd5c} (h : is_o f g l) {n : \u2115} (hn : 0 < n) :\n  is_o (\u03bb x, f x ^ n) (\u03bb x, g x ^ n) l :=\nbegin\n  cases n, exact hn.false.elim, clear hn,\n  induction n with n ihn, { simpa only [pow_one] },\n  convert h.mul ihn; simp [pow_succ]\nend\n\n/-! ### Inverse -/\n\ntheorem is_O_with.inv_rev {f : \u03b1 \u2192 \ud835\udd5c} {g : \u03b1 \u2192 \ud835\udd5c'} (h : is_O_with c f g l)\n  (h\u2080 : \u2200\u1da0 x in l, f x \u2260 0) : is_O_with c (\u03bb x, (g x)\u207b\u00b9) (\u03bb x, (f x)\u207b\u00b9) l :=\nbegin\n  refine is_O_with.of_bound (h.bound.mp (h\u2080.mono $ \u03bb x h\u2080 hle, _)),\n  cases le_or_lt c 0 with hc hc,\n  { refine (h\u2080 $ norm_le_zero_iff.1 _).elim,\n    exact hle.trans (mul_nonpos_of_nonpos_of_nonneg hc $ norm_nonneg _) },\n  { replace hle := inv_le_inv_of_le (norm_pos_iff.2 h\u2080) hle,\n    simpa only [norm_inv, mul_inv\u2080, \u2190 div_eq_inv_mul, div_le_iff hc] using hle }\nend\n\ntheorem is_O.inv_rev {f : \u03b1 \u2192 \ud835\udd5c} {g : \u03b1 \u2192 \ud835\udd5c'} (h : is_O f g l)\n  (h\u2080 : \u2200\u1da0 x in l, f x \u2260 0) : is_O (\u03bb x, (g x)\u207b\u00b9) (\u03bb x, (f x)\u207b\u00b9) l :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in (hc.inv_rev h\u2080).is_O\n\ntheorem is_o.inv_rev {f : \u03b1 \u2192 \ud835\udd5c} {g : \u03b1 \u2192 \ud835\udd5c'} (h : is_o f g l)\n  (h\u2080 : \u2200\u1da0 x in l, f x \u2260 0) : is_o (\u03bb x, (g x)\u207b\u00b9) (\u03bb x, (f x)\u207b\u00b9) l :=\nis_o.of_is_O_with $ \u03bb c hc, (h.def' hc).inv_rev h\u2080\n\n/-! ### Scalar multiplication -/\n\nsection smul_const\nvariables [normed_space \ud835\udd5c E']\n\ntheorem is_O_with.const_smul_left (h : is_O_with c f' g l) (c' : \ud835\udd5c) :\n  is_O_with (\u2225c'\u2225 * c) (\u03bb x, c' \u2022 f' x) g l :=\nby refine ((h.norm_left.const_mul_left (\u2225c'\u2225)).congr _ _ (\u03bb _, rfl)).of_norm_left;\n    intros; simp only [norm_norm, norm_smul]\n\ntheorem is_O_const_smul_left_iff {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O (\u03bb x, c \u2022 f' x) g l \u2194 is_O f' g l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_O_norm_left], simp only [norm_smul],\n  rw [is_O_const_mul_left_iff cne0, is_O_norm_left],\nend\n\ntheorem is_o_const_smul_left (h : is_o f' g l) (c : \ud835\udd5c) :\n  is_o (\u03bb x, c \u2022 f' x) g l :=\nbegin\n  refine ((h.norm_left.const_mul_left (\u2225c\u2225)).congr_left _).of_norm_left,\n  exact \u03bb x, (norm_smul _ _).symm\nend\n\ntheorem is_o_const_smul_left_iff {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o (\u03bb x, c \u2022 f' x) g l \u2194 is_o f' g l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_o_norm_left], simp only [norm_smul],\n  rw [is_o_const_mul_left_iff cne0, is_o_norm_left]\nend\n\ntheorem is_O_const_smul_right {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_O f (\u03bb x, c \u2022 f' x) l \u2194 is_O f f' l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_O_norm_right], simp only [norm_smul],\n  rw [is_O_const_mul_right_iff cne0, is_O_norm_right]\nend\n\ntheorem is_o_const_smul_right {c : \ud835\udd5c} (hc : c \u2260 0) :\n  is_o f (\u03bb x, c \u2022 f' x) l \u2194 is_o f f' l :=\nbegin\n  have cne0 : \u2225c\u2225 \u2260 0, from mt norm_eq_zero.mp hc,\n  rw [\u2190is_o_norm_right], simp only [norm_smul],\n  rw [is_o_const_mul_right_iff cne0, is_o_norm_right]\nend\n\nend smul_const\n\nsection smul\n\nvariables [normed_space \ud835\udd5c E'] [normed_space \ud835\udd5c F']\n\ntheorem is_O_with.smul {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_O_with c k\u2081 k\u2082 l) (h\u2082 : is_O_with c' f' g' l) :\n  is_O_with (c * c') (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul h\u2082.norm_norm).congr rfl _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_O.smul {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_O k\u2081 k\u2082 l) (h\u2082 : is_O f' g' l) :\n  is_O (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_O.smul_is_o {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_O k\u2081 k\u2082 l) (h\u2082 : is_o f' g' l) :\n  is_o (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul_is_o h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_o.smul_is_O {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_o k\u2081 k\u2082 l) (h\u2082 : is_O f' g' l) :\n  is_o (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul_is_O h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_o.smul {k\u2081 k\u2082 : \u03b1 \u2192 \ud835\udd5c} (h\u2081 : is_o k\u2081 k\u2082 l) (h\u2082 : is_o f' g' l) :\n  is_o (\u03bb x, k\u2081 x \u2022 f' x) (\u03bb x, k\u2082 x \u2022 g' x) l :=\nby refine ((h\u2081.norm_norm.mul h\u2082.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\nend smul\n\n/-! ### Sum -/\n\nsection sum\n\nvariables {\u03b9 : Type*} {A : \u03b9 \u2192 \u03b1 \u2192 E'} {C : \u03b9 \u2192 \u211d} {s : finset \u03b9}\n\ntheorem is_O_with.sum (h : \u2200 i \u2208 s, is_O_with (C i) (A i) g l) :\n  is_O_with (\u2211 i in s, C i) (\u03bb x, \u2211 i in s, A i x) g l :=\nbegin\n  induction s using finset.induction_on with i s is IH,\n  { simp only [is_O_with_zero', finset.sum_empty, forall_true_iff] },\n  { simp only [is, finset.sum_insert, not_false_iff],\n    exact (h _ (finset.mem_insert_self i s)).add (IH (\u03bb j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\ntheorem is_O.sum (h : \u2200 i \u2208 s, is_O (A i) g l) :\n  is_O (\u03bb x, \u2211 i in s, A i x) g l :=\nbegin\n  induction s using finset.induction_on with i s is IH,\n  { simp only [is_O_zero, finset.sum_empty, forall_true_iff] },\n  { simp only [is, finset.sum_insert, not_false_iff],\n    exact (h _ (finset.mem_insert_self i s)).add (IH (\u03bb j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\ntheorem is_o.sum (h : \u2200 i \u2208 s, is_o (A i) g' l) :\n  is_o (\u03bb x, \u2211 i in s, A i x) g' l :=\nbegin\n  induction s using finset.induction_on with i s is IH,\n  { simp only [is_o_zero, finset.sum_empty, forall_true_iff] },\n  { simp only [is, finset.sum_insert, not_false_iff],\n    exact (h _ (finset.mem_insert_self i s)).add (IH (\u03bb j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\nend sum\n\n/-! ### Relation between `f = o(g)` and `f / g \u2192 0` -/\n\ntheorem is_o.tendsto_div_nhds_zero {f g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1} (h : is_o f g l) :\n  tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0) :=\nhave eq\u2081 : is_o (\u03bb x, f x / g x) (\u03bb x, g x / g x) l,\n  by simpa only [div_eq_mul_inv] using h.mul_is_O (is_O_refl _ _),\nhave eq\u2082 : is_O (\u03bb x, g x / g x) (\u03bb x, (1 : \ud835\udd5c)) l,\n  from is_O_of_le _ (\u03bb x, by simp [div_self_le_one]),\n(is_o_one_iff \ud835\udd5c).mp (eq\u2081.trans_is_O eq\u2082)\n\ntheorem is_o.tendsto_inv_smul_nhds_zero [normed_space \ud835\udd5c E'] {f : \u03b1 \u2192 E'} {g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n  (h : is_o f g l) : tendsto (\u03bb x, (g x)\u207b\u00b9 \u2022 f x) l (\ud835\udcdd 0) :=\nby simpa only [div_eq_inv_mul, \u2190 norm_inv, \u2190 norm_smul,\n  \u2190 tendsto_zero_iff_norm_tendsto_zero] using h.norm_norm.tendsto_div_nhds_zero\n\ntheorem is_o_iff_tendsto' {f g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n    (hgf : \u2200\u1da0 x in l, g x = 0 \u2192 f x = 0) :\n  is_o f g l \u2194 tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0) :=\niff.intro is_o.tendsto_div_nhds_zero $ \u03bb h,\n  (((is_o_one_iff _).mpr h).mul_is_O (is_O_refl g l)).congr'\n    (hgf.mono $ \u03bb x, div_mul_cancel_of_imp) (eventually_of_forall $ \u03bb x, one_mul _)\n\ntheorem is_o_iff_tendsto {f g : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1}\n    (hgf : \u2200 x, g x = 0 \u2192 f x = 0) :\n  is_o f g l \u2194 tendsto (\u03bb x, f x / (g x)) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h, h.tendsto_div_nhds_zero, (is_o_iff_tendsto' (eventually_of_forall hgf)).2\u27e9\n\nalias is_o_iff_tendsto' \u2194 _ asymptotics.is_o_of_tendsto'\nalias is_o_iff_tendsto \u2194 _ asymptotics.is_o_of_tendsto\n\nlemma is_o_const_left_of_ne {c : E'} (hc : c \u2260 0) :\n  is_o (\u03bb x, c) g l \u2194 tendsto (norm \u2218 g) l at_top :=\nbegin\n  split; intro h,\n  { refine (at_top_basis' 1).tendsto_right_iff.2 (\u03bb C hC, _),\n    replace hC : 0 < C := zero_lt_one.trans_le hC,\n    replace h : is_o (\u03bb _, 1 : \u03b1 \u2192 \u211d) g l := (is_O_const_const _ hc _).trans_is_o h,\n    refine (h.def $ inv_pos.2 hC).mono (\u03bb x hx, _),\n    rwa [norm_one, \u2190 div_eq_inv_mul, one_le_div hC] at hx },\n  { suffices : is_o (\u03bb _, 1 : \u03b1 \u2192 \u211d) g l,\n      from (is_O_const_const c (@one_ne_zero \u211d _ _) _).trans_is_o this,\n    refine is_o_iff.2 (\u03bb \u03b5 \u03b50, (tendsto_at_top.1 h \u03b5\u207b\u00b9).mono (\u03bb x hx, _)),\n    rwa [norm_one, \u2190 inv_inv \u03b5, \u2190 div_eq_inv_mul, one_le_div (inv_pos.2 \u03b50)] }\nend\n\n@[simp] lemma is_o_const_left {c : E'} :\n  is_o (\u03bb x, c) g' l \u2194 c = 0 \u2228 tendsto (norm \u2218 g') l at_top :=\nbegin\n  rcases eq_or_ne c 0 with rfl | hc,\n  { simp only [is_o_zero, eq_self_iff_true, true_or] },\n  { simp only [hc, false_or, is_o_const_left_of_ne hc] }\nend\n\n@[simp] theorem is_o_const_const_iff [ne_bot l] {d : E'} {c : F'} :\n  is_o (\u03bb x, d) (\u03bb x, c) l \u2194 d = 0 :=\nhave \u00actendsto (function.const \u03b1 \u2225c\u2225) l at_top,\n  from not_tendsto_at_top_of_tendsto_nhds tendsto_const_nhds,\nby simp [function.const, this]\n\n@[simp] lemma is_o_pure {x} : is_o f' g' (pure x) \u2194 f' x = 0 :=\ncalc is_o f' g' (pure x) \u2194 is_o (\u03bb y : \u03b1, f' x) (\u03bb _, g' x) (pure x) : is_o_congr rfl rfl\n                     ... \u2194 f' x = 0                                  : is_o_const_const_iff\n\n/-!\n### Eventually (u / v) * v = u\n\nIf `u` and `v` are linked by an `is_O_with` relation, then we\neventually have `(u / v) * v = u`, even if `v` vanishes.\n-/\n\nsection eventually_mul_div_cancel\n\nvariables {u v : \u03b1 \u2192 \ud835\udd5c}\n\nlemma is_O_with.eventually_mul_div_cancel (h : is_O_with c u v l) :\n  (u / v) * v =\u1da0[l] u :=\neventually.mono h.bound (\u03bb y hy, div_mul_cancel_of_imp $ \u03bb hv, by simpa [hv] using hy)\n\n/-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/\nlemma is_O.eventually_mul_div_cancel (h : is_O u v l) :  (u / v) * v =\u1da0[l] u :=\nlet \u27e8c, hc\u27e9 := h.is_O_with in hc.eventually_mul_div_cancel\n\n/-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/\nlemma is_o.eventually_mul_div_cancel (h : is_o u v l) : (u / v) * v =\u1da0[l] u :=\n(h.forall_is_O_with zero_lt_one).eventually_mul_div_cancel\n\nend eventually_mul_div_cancel\n\n/-! ### Equivalent definitions of the form `\u2203 \u03c6, u =\u1da0[l] \u03c6 * v` in a `normed_field`. -/\n\nsection exists_mul_eq\n\nvariables {u v : \u03b1 \u2192 \ud835\udd5c}\n\n/-- If `\u2225\u03c6\u2225` is eventually bounded by `c`, and `u =\u1da0[l] \u03c6 * v`, then we have `is_O_with c u v l`.\n    This does not require any assumptions on `c`, which is why we keep this version along with\n    `is_O_with_iff_exists_eq_mul`. -/\nlemma is_O_with_of_eq_mul (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : \u2200\u1da0 x in l, \u2225\u03c6 x\u2225 \u2264 c) (h : u =\u1da0[l] \u03c6 * v) :\n  is_O_with c u v l :=\nbegin\n  unfold is_O_with,\n  refine h.symm.rw (\u03bb x a, \u2225a\u2225 \u2264 c * \u2225v x\u2225) (h\u03c6.mono $ \u03bb x hx, _),\n  simp only [norm_mul, pi.mul_apply],\n  exact mul_le_mul_of_nonneg_right hx (norm_nonneg _)\nend\n\nlemma is_O_with_iff_exists_eq_mul (hc : 0 \u2264 c) :\n  is_O_with c u v l \u2194 \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : \u2200\u1da0 x in l, \u2225\u03c6 x\u2225 \u2264 c), u =\u1da0[l] \u03c6 * v :=\nbegin\n  split,\n  { intro h,\n    use (\u03bb x, u x / v x),\n    refine \u27e8eventually.mono h.bound (\u03bb y hy, _), h.eventually_mul_div_cancel.symm\u27e9,\n    simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy },\n  { rintros \u27e8\u03c6, h\u03c6, h\u27e9,\n    exact is_O_with_of_eq_mul \u03c6 h\u03c6 h }\nend\n\nlemma is_O_with.exists_eq_mul (h : is_O_with c u v l) (hc : 0 \u2264 c) :\n  \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : \u2200\u1da0 x in l, \u2225\u03c6 x\u2225 \u2264 c), u =\u1da0[l] \u03c6 * v :=\n(is_O_with_iff_exists_eq_mul hc).mp h\n\nlemma is_O_iff_exists_eq_mul :\n  is_O u v l \u2194 \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : l.is_bounded_under (\u2264) (norm \u2218 \u03c6)), u =\u1da0[l] \u03c6 * v :=\nbegin\n  split,\n  { rintros h,\n    rcases h.exists_nonneg with \u27e8c, hnnc, hc\u27e9,\n    rcases hc.exists_eq_mul hnnc with \u27e8\u03c6, h\u03c6, huv\u03c6\u27e9,\n    exact \u27e8\u03c6, \u27e8c, h\u03c6\u27e9, huv\u03c6\u27e9 },\n  { rintros \u27e8\u03c6, \u27e8c, h\u03c6\u27e9, huv\u03c6\u27e9,\n    exact is_O_iff_is_O_with.2 \u27e8c, is_O_with_of_eq_mul \u03c6 h\u03c6 huv\u03c6\u27e9 }\nend\n\nalias is_O_iff_exists_eq_mul \u2194 asymptotics.is_O.exists_eq_mul _\n\nlemma is_o_iff_exists_eq_mul :\n  is_o u v l \u2194 \u2203 (\u03c6 : \u03b1 \u2192 \ud835\udd5c) (h\u03c6 : tendsto \u03c6 l (\ud835\udcdd 0)), u =\u1da0[l] \u03c6 * v :=\nbegin\n  split,\n  { exact \u03bb h, \u27e8\u03bb x, u x / v x, h.tendsto_div_nhds_zero, h.eventually_mul_div_cancel.symm\u27e9 },\n  { unfold is_o, rintros \u27e8\u03c6, h\u03c6, huv\u03c6\u27e9 c hpos,\n    rw normed_group.tendsto_nhds_zero at h\u03c6,\n    exact is_O_with_of_eq_mul _ ((h\u03c6 c hpos).mono $ \u03bb x, le_of_lt)  huv\u03c6 }\nend\n\nalias is_o_iff_exists_eq_mul \u2194 asymptotics.is_o.exists_eq_mul _\n\nend exists_mul_eq\n\n/-! ### Miscellanous lemmas -/\n\ntheorem div_is_bounded_under_of_is_O {\u03b1 : Type*} {l : filter \u03b1}\n  {f g : \u03b1 \u2192 \ud835\udd5c} (h : is_O f g l) :\n  is_bounded_under (\u2264) l (\u03bb x, \u2225f x / g x\u2225) :=\nbegin\n  obtain \u27e8c, hc\u27e9 := is_O_iff.mp h,\n  refine \u27e8max c 0, eventually_map.2 (filter.mem_of_superset hc (\u03bb x hx, _))\u27e9,\n  simp only [mem_set_of_eq, norm_div] at \u22a2 hx,\n  by_cases hgx : g x = 0,\n  { rw [hgx, norm_zero, div_zero, le_max_iff],\n    exact or.inr le_rfl },\n  { exact le_max_iff.2 (or.inl ((div_le_iff (norm_pos_iff.2 hgx)).2 hx)) }\nend\n\ntheorem is_O_iff_div_is_bounded_under {\u03b1 : Type*} {l : filter \u03b1}\n  {f g : \u03b1 \u2192 \ud835\udd5c} (hgf : \u2200\u1da0 x in l, g x = 0 \u2192 f x = 0) :\n  is_O f g l \u2194 is_bounded_under (\u2264) l (\u03bb x, \u2225f x / g x\u2225) :=\nbegin\n  refine \u27e8div_is_bounded_under_of_is_O, \u03bb h, _\u27e9,\n  obtain \u27e8c, hc\u27e9 := h,\n  rw filter.eventually_iff at hgf hc,\n  simp only [mem_set_of_eq, mem_map, norm_div] at hc,\n  refine is_O_iff.2 \u27e8c, filter.eventually_of_mem (inter_mem hgf hc) (\u03bb x hx, _)\u27e9,\n  by_cases hgx : g x = 0,\n  { simp [hx.1 hgx, hgx] },\n  { refine (div_le_iff (norm_pos_iff.2 hgx)).mp hx.2 },\nend\n\ntheorem is_O_of_div_tendsto_nhds {\u03b1 : Type*} {l : filter \u03b1}\n  {f g : \u03b1 \u2192 \ud835\udd5c} (hgf : \u2200\u1da0 x in l, g x = 0 \u2192 f x = 0)\n  (c : \ud835\udd5c) (H : filter.tendsto (f / g) l (\ud835\udcdd c)) :\n  is_O f g l :=\n(is_O_iff_div_is_bounded_under hgf).2 $ is_bounded_under_of_tendsto H\n\nlemma is_o.tendsto_zero_of_tendsto {\u03b1 E \ud835\udd5c : Type*} [normed_group E] [normed_field \ud835\udd5c] {u : \u03b1 \u2192 E}\n  {v : \u03b1 \u2192 \ud835\udd5c} {l : filter \u03b1} {y : \ud835\udd5c} (huv : is_o u v l) (hv : tendsto v l (\ud835\udcdd y)) :\n  tendsto u l (\ud835\udcdd 0) :=\nbegin\n  suffices h : is_o u (\u03bb x, (1 : \ud835\udd5c)) l,\n  { rwa is_o_one_iff at h },\n  exact huv.trans_is_O (is_O_one_of_tendsto \ud835\udd5c hv),\nend\n\ntheorem is_o_pow_pow {m n : \u2115} (h : m < n) :\n  is_o (\u03bb(x : \ud835\udd5c), x^n) (\u03bbx, x^m) (\ud835\udcdd 0) :=\nbegin\n  let p := n - m,\n  have nmp : n = m + p := (add_tsub_cancel_of_le (le_of_lt h)).symm,\n  have : (\u03bb(x : \ud835\udd5c), x^m) = (\u03bbx, x^m * 1), by simp only [mul_one],\n  simp only [this, pow_add, nmp],\n  refine is_O.mul_is_o (is_O_refl _ _) ((is_o_one_iff _).2 _),\n  convert (continuous_pow p).tendsto (0 : \ud835\udd5c),\n  exact (zero_pow (tsub_pos_of_lt h)).symm\nend\n\ntheorem is_o_norm_pow_norm_pow {m n : \u2115} (h : m < n) :\n  is_o (\u03bb(x : E'), \u2225x\u2225^n) (\u03bbx, \u2225x\u2225^m) (\ud835\udcdd (0 : E')) :=\n(is_o_pow_pow h).comp_tendsto tendsto_norm_zero\n\ntheorem is_o_pow_id {n : \u2115} (h : 1 < n) :\n  is_o (\u03bb(x : \ud835\udd5c), x^n) (\u03bbx, x) (\ud835\udcdd 0) :=\nby { convert is_o_pow_pow h, simp only [pow_one] }\n\ntheorem is_o_norm_pow_id {n : \u2115} (h : 1 < n) :\n  is_o (\u03bb(x : E'), \u2225x\u2225^n) (\u03bbx, x) (\ud835\udcdd 0) :=\nby simpa only [pow_one, is_o_norm_right] using @is_o_norm_pow_norm_pow E' _ _ _ h\n\ntheorem is_O_with.right_le_sub_of_lt_1 {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_O_with c f\u2081 f\u2082 l) (hc : c < 1) :\n  is_O_with (1 / (1 - c)) f\u2082 (\u03bbx, f\u2082 x - f\u2081 x) l :=\nis_O_with.of_bound $ mem_of_superset h.bound $ \u03bb x hx,\nbegin\n  simp only [mem_set_of_eq] at hx \u22a2,\n  rw [mul_comm, one_div, \u2190 div_eq_mul_inv, le_div_iff, mul_sub, mul_one, mul_comm],\n  { exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) },\n  { exact sub_pos.2 hc }\nend\n\ntheorem is_O_with.right_le_add_of_lt_1 {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_O_with c f\u2081 f\u2082 l) (hc : c < 1) :\n  is_O_with (1 / (1 - c)) f\u2082 (\u03bbx, f\u2081 x + f\u2082 x) l :=\n(h.neg_right.right_le_sub_of_lt_1 hc).neg_right.of_neg_left.congr rfl (\u03bb x, rfl)\n  (\u03bb x, by rw [neg_sub, sub_neg_eq_add])\n\ntheorem is_o.right_is_O_sub {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_o f\u2081 f\u2082 l) :\n  is_O f\u2082 (\u03bbx, f\u2082 x - f\u2081 x) l :=\n((h.def' one_half_pos).right_le_sub_of_lt_1 one_half_lt_one).is_O\n\ntheorem is_o.right_is_O_add {f\u2081 f\u2082 : \u03b1 \u2192 E'} (h : is_o f\u2081 f\u2082 l) :\n  is_O f\u2082 (\u03bbx, f\u2081 x + f\u2082 x) l :=\n((h.def' one_half_pos).right_le_add_of_lt_1 one_half_lt_one).is_O\n\n/-- If `f x = O(g x)` along `cofinite`, then there exists a positive constant `C` such that\n`\u2225f x\u2225 \u2264 C * \u2225g x\u2225` whenever `g x \u2260 0`. -/\ntheorem bound_of_is_O_cofinite (h : is_O f g' cofinite) :\n  \u2203 C > 0, \u2200 \u2983x\u2984, g' x \u2260 0 \u2192 \u2225f x\u2225 \u2264 C * \u2225g' x\u2225 :=\nbegin\n  rcases h.exists_pos with \u27e8C, C\u2080, hC\u27e9,\n  rw [is_O_with, eventually_cofinite] at hC,\n  rcases (hC.to_finset.image (\u03bb x, \u2225f x\u2225 / \u2225g' x\u2225)).exists_le with \u27e8C', hC'\u27e9,\n  have : \u2200 x, C * \u2225g' x\u2225 < \u2225f x\u2225 \u2192 \u2225f x\u2225 / \u2225g' x\u2225 \u2264 C', by simpa using hC',\n  refine \u27e8max C C', lt_max_iff.2 (or.inl C\u2080), \u03bb x h\u2080, _\u27e9,\n  rw [max_mul_of_nonneg _ _ (norm_nonneg _), le_max_iff, or_iff_not_imp_left, not_le],\n  exact \u03bb hx, (div_le_iff (norm_pos_iff.2 h\u2080)).1 (this _ hx)\nend\n\ntheorem is_O_cofinite_iff (h : \u2200 x, g' x = 0 \u2192 f' x = 0) :\n  is_O f' g' cofinite \u2194 \u2203 C, \u2200 x, \u2225f' x\u2225 \u2264 C * \u2225g' x\u2225 :=\n\u27e8\u03bb h', let \u27e8C, C\u2080, hC\u27e9 := bound_of_is_O_cofinite h' in\n  \u27e8C, \u03bb x, if hx : g' x = 0 then by simp [h _ hx, hx] else hC hx\u27e9,\n  \u03bb h, (is_O_top.2 h).mono le_top\u27e9\n\ntheorem bound_of_is_O_nat_at_top {f : \u2115 \u2192 E} {g' : \u2115 \u2192 E'} (h : is_O f g' at_top) :\n  \u2203 C > 0, \u2200 \u2983x\u2984, g' x \u2260 0 \u2192 \u2225f x\u2225 \u2264 C * \u2225g' x\u2225 :=\nbound_of_is_O_cofinite $ by rwa nat.cofinite_eq_at_top\n\ntheorem is_O_nat_at_top_iff {f : \u2115 \u2192 E'} {g : \u2115 \u2192 F'} (h : \u2200 x, g x = 0 \u2192 f x = 0) :\n  is_O f g at_top \u2194 \u2203 C, \u2200 x, \u2225f x\u2225 \u2264 C * \u2225g x\u2225 :=\nby rw [\u2190 nat.cofinite_eq_at_top, is_O_cofinite_iff h]\n\ntheorem is_O_one_nat_at_top_iff {f : \u2115 \u2192 E'} :\n  is_O f (\u03bb n, 1 : \u2115 \u2192 \u211d) at_top \u2194 \u2203 C, \u2200 n, \u2225f n\u2225 \u2264 C :=\niff.trans (is_O_nat_at_top_iff (\u03bb n h, (one_ne_zero h).elim)) $\n  by simp only [norm_one, mul_one]\n\ntheorem is_O_with_pi {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (E' i)]\n  {f : \u03b1 \u2192 \u03a0 i, E' i} {C : \u211d} (hC : 0 \u2264 C) :\n  is_O_with C f g' l \u2194 \u2200 i, is_O_with C (\u03bb x, f x i) g' l :=\nhave \u2200 x, 0 \u2264 C * \u2225g' x\u2225, from \u03bb x, mul_nonneg hC (norm_nonneg _),\nby simp only [is_O_with_iff, pi_norm_le_iff (this _), eventually_all]\n\n@[simp] theorem is_O_pi {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (E' i)]\n  {f : \u03b1 \u2192 \u03a0 i, E' i} :\n  is_O f g' l \u2194 \u2200 i, is_O (\u03bb x, f x i) g' l :=\nbegin\n  simp only [is_O_iff_eventually_is_O_with, \u2190 eventually_all],\n  exact eventually_congr (eventually_at_top.2 \u27e80, \u03bb c, is_O_with_pi\u27e9)\nend\n\n@[simp] theorem is_o_pi {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (E' i)]\n  {f : \u03b1 \u2192 \u03a0 i, E' i} :\n  is_o f g' l \u2194 \u2200 i, is_o (\u03bb x, f x i) g' l :=\nbegin\n  simp only [is_o, is_O_with_pi, le_of_lt] { contextual := tt },\n  exact \u27e8\u03bb h i c hc, h hc i, \u03bb h c hc i, h i hc\u27e9\nend\n\nend asymptotics\n\nopen asymptotics\n\nlemma summable_of_is_O {\u03b9 E} [normed_group E] [complete_space E] {f : \u03b9 \u2192 E} {g : \u03b9 \u2192 \u211d}\n  (hg : summable g) (h : is_O f g cofinite) : summable f :=\nlet \u27e8C, hC\u27e9 := h.is_O_with in\nsummable_of_norm_bounded_eventually (\u03bb x, C * \u2225g x\u2225) (hg.abs.mul_left _) hC.bound\n\nlemma summable_of_is_O_nat {E} [normed_group E] [complete_space E] {f : \u2115 \u2192 E} {g : \u2115 \u2192 \u211d}\n  (hg : summable g) (h : is_O f g at_top) : summable f :=\nsummable_of_is_O hg $ nat.cofinite_eq_at_top.symm \u25b8 h\n\nnamespace local_homeomorph\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n\nvariables {E : Type*} [has_norm E] {F : Type*} [has_norm F]\n\n/-- Transfer `is_O_with` over a `local_homeomorph`. -/\nlemma is_O_with_congr (e : local_homeomorph \u03b1 \u03b2) {b : \u03b2} (hb : b \u2208 e.target)\n  {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} {C : \u211d} :\n  is_O_with C f g (\ud835\udcdd b) \u2194 is_O_with C (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\n\u27e8\u03bb h, h.comp_tendsto $\n  by { convert e.continuous_at (e.map_target hb), exact (e.right_inv hb).symm },\n  \u03bb h, (h.comp_tendsto (e.continuous_at_symm hb)).congr' rfl\n    ((e.eventually_right_inverse hb).mono $ \u03bb x hx, congr_arg f hx)\n    ((e.eventually_right_inverse hb).mono $ \u03bb x hx, congr_arg g hx)\u27e9\n\n/-- Transfer `is_O` over a `local_homeomorph`. -/\nlemma is_O_congr (e : local_homeomorph \u03b1 \u03b2) {b : \u03b2} (hb : b \u2208 e.target) {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_O f g (\ud835\udcdd b) \u2194 is_O (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_O, exact exists_congr (\u03bb C, e.is_O_with_congr hb) }\n\n/-- Transfer `is_o` over a `local_homeomorph`. -/\nlemma is_o_congr (e : local_homeomorph \u03b1 \u03b2) {b : \u03b2} (hb : b \u2208 e.target) {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_o f g (\ud835\udcdd b) \u2194 is_o (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb c hc, e.is_O_with_congr hb) }\n\nend local_homeomorph\n\nnamespace homeomorph\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n\nvariables {E : Type*} [has_norm E] {F : Type*} [has_norm F]\n\nopen asymptotics\n\n/-- Transfer `is_O_with` over a `homeomorph`. -/\nlemma is_O_with_congr (e : \u03b1 \u2243\u209c \u03b2) {b : \u03b2} {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} {C : \u211d} :\n  is_O_with C f g (\ud835\udcdd b) \u2194 is_O_with C (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\ne.to_local_homeomorph.is_O_with_congr trivial\n\n/-- Transfer `is_O` over a `homeomorph`. -/\nlemma is_O_congr (e : \u03b1 \u2243\u209c \u03b2) {b : \u03b2} {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_O f g (\ud835\udcdd b) \u2194 is_O (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_O, exact exists_congr (\u03bb C, e.is_O_with_congr) }\n\n/-- Transfer `is_o` over a `homeomorph`. -/\nlemma is_o_congr (e : \u03b1 \u2243\u209c \u03b2) {b : \u03b2} {f : \u03b2 \u2192 E} {g : \u03b2 \u2192 F} :\n  is_o f g (\ud835\udcdd b) \u2194 is_o (f \u2218 e) (g \u2218 e) (\ud835\udcdd (e.symm b)) :=\nby { unfold is_o, exact forall\u2082_congr (\u03bb c hc, e.is_O_with_congr) }\n\nend homeomorph\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/asymptotics/asymptotics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7091180382016428}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Scott Morrison, Ainsley Pahljina\n-/\nimport tactic.ring_exp\nimport tactic.interval_cases\nimport data.nat.parity\nimport data.zmod.basic\nimport group_theory.order_of_element\nimport ring_theory.fintype\n\n/-!\n# The Lucas-Lehmer test for Mersenne primes.\n\nWe define `lucas_lehmer_residue : \u03a0 p : \u2115, zmod (2^p - 1)`, and\nprove `lucas_lehmer_residue p = 0 \u2192 prime (mersenne p)`.\n\nWe construct a tactic `lucas_lehmer.run_test`, which iteratively certifies the arithmetic\nrequired to calculate the residue, and enables us to prove\n\n```\nexample : prime (mersenne 127) :=\nlucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test)\n```\n\n## TODO\n\n- Show reverse implication.\n- Speed up the calculations using `n \u2261 (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`.\n- Find some bigger primes!\n\n## History\n\nThis development began as a student project by Ainsley Pahljina,\nand was then cleaned up for mathlib by Scott Morrison.\nThe tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro.\n-/\n\n/-- The Mersenne numbers, 2^p - 1. -/\ndef mersenne (p : \u2115) : \u2115 := 2^p - 1\n\nlemma mersenne_pos {p : \u2115} (h : 0 < p) : 0 < mersenne p :=\nbegin\n  dsimp [mersenne],\n  calc 0 < 2^1 - 1 : by norm_num\n     ... \u2264 2^p - 1 : nat.pred_le_pred (nat.pow_le_pow_of_le_right (nat.succ_pos 1) h)\nend\n\n@[simp]\nlemma succ_mersenne (k : \u2115) : mersenne k + 1 = 2 ^ k :=\nbegin\n  rw [mersenne, nat.sub_add_cancel],\n  exact one_le_pow_of_one_le (by norm_num) k\nend\n\nnamespace lucas_lehmer\n\nopen nat\n\n/-!\nWe now define three(!) different versions of the recurrence\n`s (i+1) = (s i)^2 - 2`.\n\nThese versions take values either in `\u2124`, in `zmod (2^p - 1)`, or\nin `\u2124` but applying `% (2^p - 1)` at each step.\n\nThey are each useful at different points in the proof,\nso we take a moment setting up the lemmas relating them.\n-/\n\n/-- The recurrence `s (i+1) = (s i)^2 - 2` in `\u2124`. -/\ndef s : \u2115 \u2192 \u2124\n| 0 := 4\n| (i+1) := (s i)^2 - 2\n\n/-- The recurrence `s (i+1) = (s i)^2 - 2` in `zmod (2^p - 1)`. -/\ndef s_zmod (p : \u2115) : \u2115 \u2192 zmod (2^p - 1)\n| 0 := 4\n| (i+1) := (s_zmod i)^2 - 2\n\n/-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `\u2124`. -/\ndef s_mod (p : \u2115) : \u2115 \u2192 \u2124\n| 0 := 4 % (2^p - 1)\n| (i+1) := ((s_mod i)^2 - 2) % (2^p - 1)\n\nlemma mersenne_int_ne_zero (p : \u2115) (w : 0 < p) : (2^p - 1 : \u2124) \u2260 0 :=\nbegin\n  apply ne_of_gt, simp only [gt_iff_lt, sub_pos],\n  exact_mod_cast nat.one_lt_two_pow p w,\nend\n\nlemma s_mod_nonneg (p : \u2115) (w : 0 < p) (i : \u2115) : 0 \u2264 s_mod p i :=\nbegin\n  cases i; dsimp [s_mod],\n  { exact sup_eq_left.mp rfl },\n  { apply int.mod_nonneg, exact mersenne_int_ne_zero p w },\nend\n\nlemma s_mod_mod (p i : \u2115) : s_mod p i % (2^p - 1) = s_mod p i :=\nby cases i; simp [s_mod]\n\nlemma s_mod_lt (p : \u2115) (w : 0 < p) (i : \u2115) : s_mod p i < 2^p - 1 :=\nbegin\n  rw \u2190s_mod_mod,\n  convert int.mod_lt _ _,\n  { refine (abs_of_nonneg _).symm,\n    simp only [sub_nonneg, ge_iff_le],\n    exact_mod_cast nat.one_le_two_pow p, },\n  { exact mersenne_int_ne_zero p w, },\nend\n\nlemma s_zmod_eq_s (p' : \u2115) (i : \u2115) : s_zmod (p'+2) i = (s i : zmod (2^(p'+2) - 1)):=\nbegin\n  induction i with i ih,\n  { dsimp [s, s_zmod], norm_num, },\n  { push_cast [s, s_zmod, ih] },\nend\n\n-- These next two don't make good `norm_cast` lemmas.\nlemma int.coe_nat_pow_pred (b p : \u2115) (w : 0 < b) : ((b^p - 1 : \u2115) : \u2124) = (b^p - 1 : \u2124) :=\nbegin\n  have : 1 \u2264 b^p := nat.one_le_pow p b w,\n  push_cast [this],\nend\n\nlemma int.coe_nat_two_pow_pred (p : \u2115) : ((2^p - 1 : \u2115) : \u2124) = (2^p - 1 : \u2124) :=\nint.coe_nat_pow_pred 2 p dec_trivial\n\nlemma s_zmod_eq_s_mod (p : \u2115) (i : \u2115) : s_zmod p i = (s_mod p i : zmod (2^p - 1)) :=\nby induction i; push_cast [\u2190int.coe_nat_two_pow_pred p, s_mod, s_zmod, *]\n\n/-- The Lucas-Lehmer residue is `s p (p-2)` in `zmod (2^p - 1)`. -/\ndef lucas_lehmer_residue (p : \u2115) : zmod (2^p - 1) := s_zmod p (p-2)\n\nlemma residue_eq_zero_iff_s_mod_eq_zero (p : \u2115) (w : 1 < p) :\n  lucas_lehmer_residue p = 0 \u2194 s_mod p (p-2) = 0 :=\nbegin\n  dsimp [lucas_lehmer_residue],\n  rw s_zmod_eq_s_mod p,\n  split,\n  { -- We want to use that fact that `0 \u2264 s_mod p (p-2) < 2^p - 1`\n    -- and `lucas_lehmer_residue p = 0 \u2192 2^p - 1 \u2223 s_mod p (p-2)`.\n    intro h,\n    simp [zmod.int_coe_zmod_eq_zero_iff_dvd] at h,\n    apply int.eq_zero_of_dvd_of_nonneg_of_lt _ _ h; clear h,\n    apply s_mod_nonneg _ (nat.lt_of_succ_lt w),\n    convert s_mod_lt _ (nat.lt_of_succ_lt w) (p-2),\n    push_cast [nat.one_le_two_pow p],\n    refl, },\n  { intro h, rw h, simp, },\nend\n\n/--\nA Mersenne number `2^p-1` is prime if and only if\nthe Lucas-Lehmer residue `s p (p-2) % (2^p - 1)` is zero.\n-/\n@[derive decidable_pred]\ndef lucas_lehmer_test (p : \u2115) : Prop := lucas_lehmer_residue p = 0\n\n/-- `q` is defined as the minimum factor of `mersenne p`, bundled as an `\u2115+`. -/\ndef q (p : \u2115) : \u2115+ := \u27e8nat.min_fac (mersenne p), nat.min_fac_pos (mersenne p)\u27e9\n\nlocal attribute [instance]\nlemma fact_pnat_pos (q : \u2115+) : fact (0 < (q : \u2115)) := \u27e8q.2\u27e9\n\n/-- We construct the ring `X q` as \u2124/q\u2124 + \u221a3 \u2124/q\u2124. -/\n-- It would be nice to define this as (\u2124/q\u2124)[x] / (x^2 - 3),\n-- obtaining the ring structure for free,\n-- but that seems to be more trouble than it's worth;\n-- if it were easy to make the definition,\n-- cardinality calculations would be somewhat more involved, too.\n@[derive [add_comm_group, decidable_eq, fintype, inhabited]]\ndef X (q : \u2115+) : Type := (zmod q) \u00d7 (zmod q)\n\nnamespace X\nvariable {q : \u2115+}\n\n@[ext]\nlemma ext {x y : X q} (h\u2081 : x.1 = y.1) (h\u2082 : x.2 = y.2) : x = y :=\nbegin\n  cases x, cases y,\n  congr; assumption\nend\n\n@[simp] lemma add_fst (x y : X q) : (x + y).1 = x.1 + y.1 := rfl\n@[simp] \n\n@[simp] lemma neg_fst (x : X q) : (-x).1 = -x.1 := rfl\n@[simp] lemma neg_snd (x : X q) : (-x).2 = -x.2 := rfl\n\ninstance : has_mul (X q) :=\n{ mul := \u03bb x y, (x.1*y.1 + 3*x.2*y.2, x.1*y.2 + x.2*y.1) }\n\n@[simp] lemma mul_fst (x y : X q) : (x * y).1 = x.1 * y.1 + 3 * x.2 * y.2 := rfl\n@[simp] lemma mul_snd (x y : X q) : (x * y).2 = x.1 * y.2 + x.2 * y.1 := rfl\n\ninstance : has_one (X q) :=\n{ one := \u27e81,0\u27e9 }\n\n@[simp] lemma one_fst : (1 : X q).1 = 1 := rfl\n@[simp] lemma one_snd : (1 : X q).2 = 0 := rfl\n\n@[simp] lemma bit0_fst (x : X q) : (bit0 x).1 = bit0 x.1 := rfl\n@[simp] lemma bit0_snd (x : X q) : (bit0 x).2 = bit0 x.2 := rfl\n@[simp] lemma bit1_fst (x : X q) : (bit1 x).1 = bit1 x.1 := rfl\n@[simp] lemma bit1_snd (x : X q) : (bit1 x).2 = bit0 x.2 := by { dsimp [bit1], simp, }\n\ninstance : monoid (X q) :=\n{ mul_assoc := \u03bb x y z, by { ext; { dsimp, ring }, },\n  one := \u27e81,0\u27e9,\n  one_mul := \u03bb x, by { ext; simp, },\n  mul_one := \u03bb x, by { ext; simp, },\n  ..(infer_instance : has_mul (X q)) }\n\nlemma left_distrib (x y z : X q) : x * (y + z) = x * y + x * z :=\nby { ext; { dsimp, ring }, }\n\nlemma right_distrib (x y z : X q) : (x + y) * z = x * z + y * z :=\nby { ext; { dsimp, ring }, }\n\ninstance : ring (X q) :=\n{ left_distrib := left_distrib,\n  right_distrib := right_distrib,\n  ..(infer_instance : add_comm_group (X q)),\n  ..(infer_instance : monoid (X q)) }\n\ninstance : comm_ring (X q) :=\n{ mul_comm := \u03bb x y, by { ext; { dsimp, ring }, },\n  ..(infer_instance : ring (X q))}\n\ninstance [fact (1 < (q : \u2115))] : nontrivial (X q) :=\n\u27e8\u27e80, 1, \u03bb h, by { injection h with h1 _, exact zero_ne_one h1 } \u27e9\u27e9\n\n@[simp]\nlemma nat_coe_fst (n : \u2115) : (n : X q).fst = (n : zmod q) :=\nbegin\n  induction n,\n  { refl, },\n  { dsimp, simp only [add_left_inj], exact n_ih, }\nend\n@[simp]\nlemma nat_coe_snd (n : \u2115) : (n : X q).snd = (0 : zmod q) :=\nbegin\n  induction n,\n  { refl, },\n  { dsimp, simp only [add_zero], exact n_ih, }\nend\n\n@[simp]\nlemma int_coe_fst (n : \u2124) : (n : X q).fst = (n : zmod q) :=\nby { induction n; simp, }\n@[simp]\nlemma int_coe_snd (n : \u2124) : (n : X q).snd = (0 : zmod q) :=\nby { induction n; simp, }\n\n@[norm_cast]\nlemma coe_mul (n m : \u2124) : ((n * m : \u2124) : X q) = (n : X q) * (m : X q) :=\nby { ext; simp; ring }\n\n@[norm_cast]\nlemma coe_nat (n : \u2115) : ((n : \u2124) : X q) = (n : X q) :=\nby { ext; simp, }\n\n/-- The cardinality of `X` is `q^2`. -/\nlemma X_card : fintype.card (X q) = q^2 :=\nbegin\n  dsimp [X],\n  rw [fintype.card_prod, zmod.card q],\n  ring,\nend\n\n/-- There are strictly fewer than `q^2` units, since `0` is not a unit. -/\nlemma units_card (w : 1 < q) : fintype.card (units (X q)) < q^2 :=\nbegin\n  haveI : fact (1 < (q:\u2115)) := \u27e8w\u27e9,\n  convert card_units_lt (X q),\n  rw X_card,\nend\n\n/-- We define `\u03c9 = 2 + \u221a3`. -/\ndef \u03c9 : X q := (2, 1)\n/-- We define `\u03c9b = 2 - \u221a3`, which is the inverse of `\u03c9`. -/\ndef \u03c9b : X q := (2, -1)\n\nlemma \u03c9_mul_\u03c9b (q : \u2115+) : (\u03c9 : X q) * \u03c9b = 1 :=\nbegin\n  dsimp [\u03c9, \u03c9b],\n  ext; simp; ring,\nend\n\nlemma \u03c9b_mul_\u03c9 (q : \u2115+) : (\u03c9b : X q) * \u03c9 = 1 :=\nbegin\n  dsimp [\u03c9, \u03c9b],\n  ext; simp; ring,\nend\n\n/-- A closed form for the recurrence relation. -/\nlemma closed_form (i : \u2115) : (s i : X q) = (\u03c9 : X q)^(2^i) + (\u03c9b : X q)^(2^i) :=\nbegin\n  induction i with i ih,\n  { dsimp [s, \u03c9, \u03c9b],\n    ext; { simp; refl, }, },\n  { calc (s (i + 1) : X q) = ((s i)^2 - 2 : \u2124) : rfl\n    ... = ((s i : X q)^2 - 2) : by push_cast\n    ... = (\u03c9^(2^i) + \u03c9b^(2^i))^2 - 2 : by rw ih\n    ... = (\u03c9^(2^i))^2 + (\u03c9b^(2^i))^2 + 2*(\u03c9b^(2^i)*\u03c9^(2^i)) - 2 : by ring\n    ... = (\u03c9^(2^i))^2 + (\u03c9b^(2^i))^2 :\n            by rw [\u2190mul_pow \u03c9b \u03c9, \u03c9b_mul_\u03c9, one_pow, mul_one, add_sub_cancel]\n    ... = \u03c9^(2^(i+1)) + \u03c9b^(2^(i+1)) : by rw [\u2190pow_mul, \u2190pow_mul, pow_succ'] }\nend\n\n\nend X\n\nopen X\n\n/-!\nHere and below, we introduce `p' = p - 2`, in order to avoid using subtraction in `\u2115`.\n-/\n\n/-- If `1 < p`, then `q p`, the smallest prime factor of `mersenne p`, is more than 2. -/\nlemma two_lt_q (p' : \u2115) : 2 < q (p'+2) := begin\n  by_contradiction H,\n  simp at H,\n  interval_cases q (p'+2); clear H,\n  { -- If q = 1, we get a contradiction from 2^p = 2\n    dsimp [q] at h, injection h with h', clear h,\n    simp [mersenne] at h',\n    exact lt_irrefl 2\n    (calc 2 \u2264 p'+2    : nat.le_add_left _ _\n      ...  < 2^(p'+2) : nat.lt_two_pow _\n      ...  = 2        : nat.pred_inj (nat.one_le_two_pow _) dec_trivial h'), },\n  { -- If q = 2, we get a contradiction from 2 \u2223 2^p - 1\n    dsimp [q] at h, injection h with h', clear h,\n    rw [mersenne, pnat.one_coe, nat.min_fac_eq_two_iff, pow_succ] at h',\n    exact nat.two_not_dvd_two_mul_sub_one (nat.one_le_two_pow _) h', }\nend\n\ntheorem \u03c9_pow_formula (p' : \u2115) (h : lucas_lehmer_residue (p'+2) = 0) :\n  \u2203 (k : \u2124), (\u03c9 : X (q (p'+2)))^(2^(p'+1)) =\n    k * (mersenne (p'+2)) * ((\u03c9 : X (q (p'+2)))^(2^p')) - 1 :=\nbegin\n  dsimp [lucas_lehmer_residue] at h,\n  rw s_zmod_eq_s p' at h,\n  simp [zmod.int_coe_zmod_eq_zero_iff_dvd] at h,\n  cases h with k h,\n  use k,\n  replace h := congr_arg (\u03bb (n : \u2124), (n : X (q (p'+2)))) h, -- coercion from \u2124 to X q\n  dsimp at h,\n  rw closed_form at h,\n  replace h := congr_arg (\u03bb x, \u03c9^2^p' * x) h,\n  dsimp at h,\n  have t : 2^p' + 2^p' = 2^(p'+1) := by ring_exp,\n  rw [mul_add, \u2190pow_add \u03c9, t, \u2190mul_pow \u03c9 \u03c9b (2^p'), \u03c9_mul_\u03c9b, one_pow] at h,\n  rw [mul_comm, coe_mul] at h,\n  rw [mul_comm _ (k : X (q (p'+2)))] at h,\n  replace h := eq_sub_of_add_eq h,\n  exact_mod_cast h,\nend\n\n/-- `q` is the minimum factor of `mersenne p`, so `M p = 0` in `X q`. -/\ntheorem mersenne_coe_X (p : \u2115) : (mersenne p : X (q p)) = 0 :=\nbegin\n  ext; simp [mersenne, q, zmod.nat_coe_zmod_eq_zero_iff_dvd, -pow_pos],\n  apply nat.min_fac_dvd,\nend\n\ntheorem \u03c9_pow_eq_neg_one (p' : \u2115) (h : lucas_lehmer_residue (p'+2) = 0) :\n  (\u03c9 : X (q (p'+2)))^(2^(p'+1)) = -1 :=\nbegin\n  cases \u03c9_pow_formula p' h with k w,\n  rw [mersenne_coe_X] at w,\n  simpa using w,\nend\n\ntheorem \u03c9_pow_eq_one (p' : \u2115) (h : lucas_lehmer_residue (p'+2) = 0) :\n  (\u03c9 : X (q (p'+2)))^(2^(p'+2)) = 1 :=\ncalc (\u03c9 : X (q (p'+2)))^2^(p'+2)\n        = (\u03c9^(2^(p'+1)))^2 : by rw [\u2190pow_mul, \u2190pow_succ']\n    ... = (-1)^2           : by rw \u03c9_pow_eq_neg_one p' h\n    ... = 1                : by simp\n\n/-- `\u03c9` as an element of the group of units. -/\ndef \u03c9_unit (p : \u2115) : units (X (q p)) :=\n{ val := \u03c9,\n  inv := \u03c9b,\n  val_inv := by simp [\u03c9_mul_\u03c9b],\n  inv_val := by simp [\u03c9b_mul_\u03c9], }\n\n@[simp] lemma \u03c9_unit_coe (p : \u2115) : (\u03c9_unit p : X (q p)) = \u03c9 := rfl\n\n/-- The order of `\u03c9` in the unit group is exactly `2^p`. -/\ntheorem order_\u03c9 (p' : \u2115) (h : lucas_lehmer_residue (p'+2) = 0) :\n  order_of (\u03c9_unit (p'+2)) = 2^(p'+2) :=\nbegin\n  apply nat.eq_prime_pow_of_dvd_least_prime_pow, -- the order of \u03c9 divides 2^p\n  { norm_num, },\n  { intro o,\n    have \u03c9_pow := order_of_dvd_iff_pow_eq_one.1 o,\n    replace \u03c9_pow := congr_arg (units.coe_hom (X (q (p'+2))) :\n      units (X (q (p'+2))) \u2192 X (q (p'+2))) \u03c9_pow,\n    simp at \u03c9_pow,\n    have h : (1 : zmod (q (p'+2))) = -1 :=\n      congr_arg (prod.fst) ((\u03c9_pow.symm).trans (\u03c9_pow_eq_neg_one p' h)),\n    haveI : fact (2 < (q (p'+2) : \u2115)) := \u27e8two_lt_q _\u27e9,\n    apply zmod.neg_one_ne_one h.symm, },\n  { apply order_of_dvd_iff_pow_eq_one.2,\n    apply units.ext,\n    push_cast,\n    exact \u03c9_pow_eq_one p' h, }\nend\n\nlemma order_ineq (p' : \u2115) (h : lucas_lehmer_residue (p'+2) = 0) : 2^(p'+2) < (q (p'+2) : \u2115)^2 :=\ncalc 2^(p'+2) = order_of (\u03c9_unit (p'+2)) : (order_\u03c9 p' h).symm\n     ... \u2264 fintype.card (units (X _))    : order_of_le_card_univ\n     ... < (q (p'+2) : \u2115)^2              : units_card (nat.lt_of_succ_lt (two_lt_q _))\n\nend lucas_lehmer\n\nexport lucas_lehmer (lucas_lehmer_test lucas_lehmer_residue)\n\nopen lucas_lehmer\n\ntheorem lucas_lehmer_sufficiency (p : \u2115) (w : 1 < p) : lucas_lehmer_test p \u2192 (mersenne p).prime :=\nbegin\n  let p' := p - 2,\n  have z : p = p' + 2 := (nat.sub_eq_iff_eq_add w).mp rfl,\n  have w : 1 < p' + 2 := (nat.lt_of_sub_eq_succ rfl),\n  contrapose,\n  intros a t,\n  rw z at a,\n  rw z at t,\n  have h\u2081 := order_ineq p' t,\n  have h\u2082 := nat.min_fac_sq_le_self (mersenne_pos (nat.lt_of_succ_lt w)) a,\n  have h := lt_of_lt_of_le h\u2081 h\u2082,\n  exact not_lt_of_ge (nat.sub_le _ _) h,\nend\n\n-- Here we calculate the residue, very inefficiently, using `dec_trivial`. We can do much better.\nexample : (mersenne 5).prime := lucas_lehmer_sufficiency 5 (by norm_num) dec_trivial\n\n-- Next we use `norm_num` to calculate each `s p i`.\nnamespace lucas_lehmer\nopen tactic\n\nmeta instance nat_pexpr : has_to_pexpr \u2115 := \u27e8pexpr.of_expr \u2218 \u03bb n, reflect n\u27e9\nmeta instance int_pexpr : has_to_pexpr \u2124 := \u27e8pexpr.of_expr \u2218 \u03bb n, reflect n\u27e9\n\nlemma s_mod_succ {p a i b c}\n  (h1 : (2^p - 1 : \u2124) = a)\n  (h2 : s_mod p i = b)\n  (h3 : (b * b - 2) % a = c) :\n  s_mod p (i+1) = c :=\nby { dsimp [s_mod, mersenne], rw [h1, h2, sq, h3] }\n\n/--\nGiven a goal of the form `lucas_lehmer_test p`,\nattempt to do the calculation using `norm_num` to certify each step.\n-/\nmeta def run_test : tactic unit :=\ndo `(lucas_lehmer_test %%p) \u2190 target,\n   `[dsimp [lucas_lehmer_test]],\n   `[rw lucas_lehmer.residue_eq_zero_iff_s_mod_eq_zero, swap, norm_num],\n   p \u2190 eval_expr \u2115 p,\n   -- Calculate the candidate Mersenne prime\n   let M : \u2124 := 2^p - 1,\n   t \u2190 to_expr ``(2^%%p - 1 = %%M),\n   v \u2190 to_expr ``(by norm_num : 2^%%p - 1 = %%M),\n   w \u2190 assertv `w t v,\n   -- Unfortunately this creates something like `w : 2^5 - 1 = int.of_nat 31`.\n   -- We could make a better `has_to_pexpr \u2124` instance, or just:\n   `[simp only [int.coe_nat_zero, int.coe_nat_succ,\n       int.of_nat_eq_coe, zero_add, int.coe_nat_bit1] at w],\n   -- base case\n   t \u2190 to_expr ``(s_mod %%p 0 = 4),\n   v \u2190 to_expr ``(by norm_num [lucas_lehmer.s_mod] : s_mod %%p 0 = 4),\n   h \u2190 assertv `h t v,\n   -- step case, repeated p-2 times\n   iterate_exactly (p-2) `[replace h := lucas_lehmer.s_mod_succ w h (by { norm_num, refl })],\n   -- now close the goal\n   h \u2190 get_local `h,\n   exact h\n\nend lucas_lehmer\n\n/-- We verify that the tactic works to prove `127.prime`. -/\nexample : (mersenne 7).prime := lucas_lehmer_sufficiency _ (by norm_num) (by lucas_lehmer.run_test).\n\n/-!\nThis implementation works successfully to prove `(2^127 - 1).prime`,\nand all the Mersenne primes up to this point appear in [archive/examples/mersenne_primes.lean].\n\n`(2^127 - 1).prime` takes about 5 minutes to run (depending on your CPU!),\nand unfortunately the next Mersenne prime `(2^521 - 1)`,\nwhich was the first \"computer era\" prime,\nis out of reach with the current implementation.\n\nThere's still low hanging fruit available to do faster computations\nbased on the formula\n  n \u2261 (n % 2^p) + (n / 2^p) [MOD 2^p - 1]\nand the fact that `% 2^p` and `/ 2^p` can be very efficient on the binary representation.\nSomeone should do this, too!\n-/\n\nlemma modeq_mersenne (n k : \u2115) : k \u2261 ((k / 2^n) + (k % 2^n)) [MOD 2^n - 1] :=\n-- See https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/help.20finding.20a.20lemma/near/177698446\nbegin\n  conv in k { rw \u2190 nat.div_add_mod k (2^n) },\n  refine nat.modeq.modeq_add _ (by refl),\n  conv { congr, skip, skip, rw \u2190 one_mul (k/2^n) },\n  refine nat.modeq.modeq_mul _ (by refl),\n  symmetry,\n  rw [nat.modeq.modeq_iff_dvd, int.coe_nat_sub],\n  exact pow_pos (show 0 < 2, from dec_trivial) _\nend\n\n-- It's hard to know what the limiting factor for large Mersenne primes would be.\n-- In the purely computational world, I think it's the squaring operation in `s`.\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/number_theory/lucas_lehmer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7091180288446433}}
{"text": "/-\nCopyright (c) 2017 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn\n\nDefines natural transformations between functors.\n\nIntroduces notations\n  `\u03c4.app X` for the components of natural transformations,\n  `F \u27f6 G` for the type of natural transformations between functors `F` and `G`,\n  `\u03c3 \u226b \u03c4` for vertical compositions, and\n  `\u03c3 \u25eb \u03c4` for horizontal compositions.\n-/\nimport category_theory.functor\n\nnamespace category_theory\n\n-- declare the `v`'s first; see `category_theory.category` for an explanation\nuniverses v\u2081 v\u2082 v\u2083 v\u2084 u\u2081 u\u2082 u\u2083 u\u2084\n\nvariables {C : Type u\u2081} [category.{v\u2081} C] {D : Type u\u2082} [category.{v\u2082} D]\n\n/--\n`nat_trans F G` represents a natural transformation between functors `F` and `G`.\n\nThe field `app` provides the components of the natural transformation.\n\nNaturality is expressed by `\u03b1.naturality_lemma`.\n-/\n@[ext]\nstructure nat_trans (F G : C \u2964 D) : Type (max u\u2081 v\u2082) :=\n(app : \u03a0 X : C, (F.obj X) \u27f6 (G.obj X))\n(naturality' : \u2200 {{X Y : C}} (f : X \u27f6 Y), (F.map f) \u226b (app Y) = (app X) \u226b (G.map f) . obviously)\n\nrestate_axiom nat_trans.naturality'\n-- Rather arbitrarily, we say that the 'simpler' form is\n-- components of natural transfomations moving earlier.\nattribute [simp, reassoc] nat_trans.naturality\n\nlemma congr_app {F G : C \u2964 D} {\u03b1 \u03b2 : nat_trans F G} (h : \u03b1 = \u03b2) (X : C) : \u03b1.app X = \u03b2.app X :=\ncongr_fun (congr_arg nat_trans.app h) X\n\nnamespace nat_trans\n\n/-- `nat_trans.id F` is the identity natural transformation on a functor `F`. -/\nprotected def id (F : C \u2964 D) : nat_trans F F :=\n{ app := \u03bb X, \ud835\udfd9 (F.obj X) }\n\n@[simp] lemma id_app' (F : C \u2964 D) (X : C) : (nat_trans.id F).app X = \ud835\udfd9 (F.obj X) := rfl\n\ninstance (F : C \u2964 D) : inhabited (nat_trans F F) := \u27e8nat_trans.id F\u27e9\n\nopen category\nopen category_theory.functor\n\nsection\nvariables {F G H I : C \u2964 D}\n\n/-- `vcomp \u03b1 \u03b2` is the vertical compositions of natural transformations. -/\ndef vcomp (\u03b1 : nat_trans F G) (\u03b2 : nat_trans G H) : nat_trans F H :=\n{ app := \u03bb X, (\u03b1.app X) \u226b (\u03b2.app X) }\n\n-- functor_category will rewrite (vcomp \u03b1 \u03b2) to (\u03b1 \u226b \u03b2), so this is not a\n-- suitable simp lemma.  We will declare the variant vcomp_app' there.\nlemma vcomp_app (\u03b1 : nat_trans F G) (\u03b2 : nat_trans G H) (X : C) :\n  (vcomp \u03b1 \u03b2).app X = (\u03b1.app X) \u226b (\u03b2.app X) := rfl\n\nend\n\n/--\nThe diagram\n    F(f)      F(g)      F(h)\nF X ----> F Y ----> F U ----> F U\n |         |         |         |\n | \u03b1(X)    | \u03b1(Y)    | \u03b1(U)    | \u03b1(V)\n v         v         v         v\nG X ----> G Y ----> G U ----> G V\n    G(f)      G(g)      G(h)\ncommutes.\n-/\nexample {F G : C \u2964 D} (\u03b1 : nat_trans F G) {X Y U V : C} (f : X \u27f6 Y) (g : Y \u27f6 U) (h : U \u27f6 V) :\n  \u03b1.app X \u226b G.map f \u226b G.map g \u226b G.map h =\n    F.map f \u226b F.map g \u226b F.map h \u226b \u03b1.app V :=\nby simp\n\nend nat_trans\n\nend category_theory\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/category_theory/natural_transformation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.709102680027324}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\nimport algebra.big_operators.order\nimport combinatorics.hall.basic\nimport data.fintype.card\nimport set_theory.fincard\n\n/-!\n# Configurations of Points and lines\nThis file introduces abstract configurations of points and lines, and proves some basic properties.\n\n## Main definitions\n* `configuration.nondegenerate`: Excludes certain degenerate configurations,\n  and imposes uniqueness of intersection points.\n* `configuration.has_points`: A nondegenerate configuration in which\n  every pair of lines has an intersection point.\n* `configuration.has_lines`:  A nondegenerate configuration in which\n  every pair of points has a line through them.\n* `configuration.line_count`: The number of lines through a given point.\n* `configuration.point_count`: The number of lines through a given line.\n\n## Main statements\n* `configuration.has_lines.card_le`: `has_lines` implies `|P| \u2264 |L|`.\n* `configuration.has_points.card_le`: `has_points` implies `|L| \u2264 |P|`.\n* `configuration.has_lines.has_points`: `has_lines` and `|P| = |L|` implies `has_points`.\n* `configuration.has_points.has_lines`: `has_points` and `|P| = |L|` implies `has_lines`.\nTogether, these four statements say that any two of the following properties imply the third:\n(a) `has_lines`, (b) `has_points`, (c) `|P| = |L|`.\n\n-/\n\nopen_locale big_operators\n\nnamespace configuration\n\nuniverse u\n\nvariables (P L : Type u) [has_mem P L]\n\n/-- A type synonym. -/\ndef dual := P\n\ninstance [this : inhabited P] : inhabited (dual P) := this\n\ninstance [this : fintype P] : fintype (dual P) := this\n\ninstance : has_mem (dual L) (dual P) :=\n\u27e8function.swap (has_mem.mem : P \u2192 L \u2192 Prop)\u27e9\n\n/-- A configuration is nondegenerate if:\n  1) there does not exist a line that passes through all of the points,\n  2) there does not exist a point that is on all of the lines,\n  3) there is at most one line through any two points,\n  4) any two lines have at most one intersection point.\n  Conditions 3 and 4 are equivalent. -/\nclass nondegenerate : Prop :=\n(exists_point : \u2200 l : L, \u2203 p, p \u2209 l)\n(exists_line : \u2200 p, \u2203 l : L, p \u2209 l)\n(eq_or_eq : \u2200 {p\u2081 p\u2082 : P} {l\u2081 l\u2082 : L}, p\u2081 \u2208 l\u2081 \u2192 p\u2082 \u2208 l\u2081 \u2192 p\u2081 \u2208 l\u2082 \u2192 p\u2082 \u2208 l\u2082 \u2192 p\u2081 = p\u2082 \u2228 l\u2081 = l\u2082)\n\n/-- A nondegenerate configuration in which every pair of lines has an intersection point. -/\nclass has_points extends nondegenerate P L : Type u :=\n(mk_point : \u2200 {l\u2081 l\u2082 : L} (h : l\u2081 \u2260 l\u2082), P)\n(mk_point_ax : \u2200 {l\u2081 l\u2082 : L} (h : l\u2081 \u2260 l\u2082), mk_point h \u2208 l\u2081 \u2227 mk_point h \u2208 l\u2082)\n\n/-- A nondegenerate configuration in which every pair of points has a line through them. -/\nclass has_lines extends nondegenerate P L : Type u :=\n(mk_line : \u2200 {p\u2081 p\u2082 : P} (h : p\u2081 \u2260 p\u2082), L)\n(mk_line_ax : \u2200 {p\u2081 p\u2082 : P} (h : p\u2081 \u2260 p\u2082), p\u2081 \u2208 mk_line h \u2227 p\u2082 \u2208 mk_line h)\n\nopen nondegenerate has_points has_lines\n\ninstance [nondegenerate P L] : nondegenerate (dual L) (dual P) :=\n{ exists_point := @exists_line P L _ _,\n  exists_line := @exists_point P L _ _,\n  eq_or_eq := \u03bb l\u2081 l\u2082 p\u2081 p\u2082 h\u2081 h\u2082 h\u2083 h\u2084, (@eq_or_eq P L _ _ p\u2081 p\u2082 l\u2081 l\u2082 h\u2081 h\u2083 h\u2082 h\u2084).symm }\n\ninstance [has_points P L] : has_lines (dual L) (dual P) :=\n{ mk_line := @mk_point P L _ _,\n  mk_line_ax := \u03bb _ _, mk_point_ax }\n\ninstance [has_lines P L] : has_points (dual L) (dual P) :=\n{ mk_point := @mk_line P L _ _,\n  mk_point_ax := \u03bb _ _, mk_line_ax }\n\nlemma has_points.exists_unique_point [has_points P L] (l\u2081 l\u2082 : L) (hl : l\u2081 \u2260 l\u2082) :\n  \u2203! p, p \u2208 l\u2081 \u2227 p \u2208 l\u2082 :=\n\u27e8mk_point hl, mk_point_ax hl,\n  \u03bb p hp, (eq_or_eq hp.1 (mk_point_ax hl).1 hp.2 (mk_point_ax hl).2).resolve_right hl\u27e9\n\nlemma has_lines.exists_unique_line [has_lines P L] (p\u2081 p\u2082 : P) (hp : p\u2081 \u2260 p\u2082) :\n  \u2203! l : L, p\u2081 \u2208 l \u2227 p\u2082 \u2208 l :=\nhas_points.exists_unique_point (dual L) (dual P) p\u2081 p\u2082 hp\n\nvariables {P L}\n\n/-- If a nondegenerate configuration has at least as many points as lines, then there exists\n  an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/\nlemma nondegenerate.exists_injective_of_card_le [nondegenerate P L]\n  [fintype P] [fintype L] (h : fintype.card L \u2264 fintype.card P) :\n  \u2203 f : L \u2192 P, function.injective f \u2227 \u2200 l, (f l) \u2209 l :=\nbegin\n  classical,\n  let t : L \u2192 finset P := \u03bb l, (set.to_finset {p | p \u2209 l}),\n  suffices : \u2200 s : finset L, s.card \u2264 (s.bUnion t).card, -- Hall's marriage theorem\n  { obtain \u27e8f, hf1, hf2\u27e9 := (finset.all_card_le_bUnion_card_iff_exists_injective t).mp this,\n    exact \u27e8f, hf1, \u03bb l, set.mem_to_finset.mp (hf2 l)\u27e9 },\n  intro s,\n  by_cases hs\u2080 : s.card = 0, -- If `s = \u2205`, then `s.card = 0 \u2264 (s.bUnion t).card`\n  { simp_rw [hs\u2080, zero_le] },\n  by_cases hs\u2081 : s.card = 1, -- If `s = {l}`, then pick a point `p \u2209 l`\n  { obtain \u27e8l, rfl\u27e9 := finset.card_eq_one.mp hs\u2081,\n    obtain \u27e8p, hl\u27e9 := exists_point l,\n    rw [finset.card_singleton, finset.singleton_bUnion, nat.one_le_iff_ne_zero],\n    exact finset.card_ne_zero_of_mem (set.mem_to_finset.mpr hl) },\n  suffices : (s.bUnion t)\u1d9c.card \u2264 s\u1d9c.card, -- Rephrase in terms of complements (uses `h`)\n  { rw [finset.card_compl, finset.card_compl, tsub_le_iff_left] at this,\n    replace := h.trans this,\n    rwa [\u2190add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left\n      (le_add_left s.card_le_univ), add_le_add_iff_right] at this },\n  have hs\u2082 : (s.bUnion t)\u1d9c.card \u2264 1, -- At most one line through two points of `s`\n  { refine finset.card_le_one_iff.mpr (\u03bb p\u2081 p\u2082 hp\u2081 hp\u2082, _),\n    simp_rw [finset.mem_compl, finset.mem_bUnion, exists_prop, not_exists, not_and,\n      set.mem_to_finset, set.mem_set_of_eq, not_not] at hp\u2081 hp\u2082,\n    obtain \u27e8l\u2081, l\u2082, hl\u2081, hl\u2082, hl\u2083\u27e9 :=\n    finset.one_lt_card_iff.mp (nat.one_lt_iff_ne_zero_and_ne_one.mpr \u27e8hs\u2080, hs\u2081\u27e9),\n    exact (eq_or_eq (hp\u2081 l\u2081 hl\u2081) (hp\u2082 l\u2081 hl\u2081) (hp\u2081 l\u2082 hl\u2082) (hp\u2082 l\u2082 hl\u2082)).resolve_right hl\u2083 },\n  by_cases hs\u2083 : s\u1d9c.card = 0,\n  { rw [hs\u2083, nat.le_zero_iff],\n    rw [finset.card_compl, tsub_eq_zero_iff_le, has_le.le.le_iff_eq (finset.card_le_univ _),\n        eq_comm, finset.card_eq_iff_eq_univ, hs\u2083, finset.eq_univ_iff_forall] at hs\u2083 \u22a2,\n    exact \u03bb p, exists.elim (exists_line p) -- If `s = univ`, then show `s.bUnion t = univ`\n      (\u03bb l hl, finset.mem_bUnion.mpr \u27e8l, finset.mem_univ l, set.mem_to_finset.mpr hl\u27e9) },\n  { exact hs\u2082.trans (nat.one_le_iff_ne_zero.mpr hs\u2083) }, -- If `s < univ`, then consequence of `hs\u2082`\nend\n\nvariables {P} (L)\n\n/-- Number of points on a given line. -/\nnoncomputable def line_count (p : P) : \u2115 := nat.card {l : L // p \u2208 l}\n\nvariables (P) {L}\n\n/-- Number of lines through a given point. -/\nnoncomputable def point_count (l : L) : \u2115 := nat.card {p : P // p \u2208 l}\n\nvariables (P L)\n\nlemma sum_line_count_eq_sum_point_count [fintype P] [fintype L] :\n  \u2211 p : P, line_count L p = \u2211 l : L, point_count P l :=\nbegin\n  classical,\n  simp only [line_count, point_count, nat.card_eq_fintype_card, \u2190fintype.card_sigma],\n  apply fintype.card_congr,\n  calc (\u03a3 p, {l : L // p \u2208 l}) \u2243 {x : P \u00d7 L // x.1 \u2208 x.2} :\n    (equiv.subtype_prod_equiv_sigma_subtype (\u2208)).symm\n  ... \u2243 {x : L \u00d7 P // x.2 \u2208 x.1} : (equiv.prod_comm P L).subtype_equiv (\u03bb x, iff.rfl)\n  ... \u2243 (\u03a3 l, {p // p \u2208 l}) : equiv.subtype_prod_equiv_sigma_subtype (\u03bb (l : L) (p : P), p \u2208 l),\nend\n\nvariables {P L}\n\nlemma has_lines.point_count_le_line_count [has_lines P L] {p : P} {l : L} (h : p \u2209 l)\n  [fintype {l : L // p \u2208 l}] : point_count P l \u2264 line_count L p :=\nbegin\n  by_cases hf : infinite {p : P // p \u2208 l},\n  { exactI (le_of_eq nat.card_eq_zero_of_infinite).trans (zero_le (line_count L p)) },\n  haveI := fintype_of_not_infinite hf,\n  rw [line_count, point_count, nat.card_eq_fintype_card, nat.card_eq_fintype_card],\n  have : \u2200 p' : {p // p \u2208 l}, p \u2260 p' := \u03bb p' hp', h ((congr_arg (\u2208 l) hp').mpr p'.2),\n  exact fintype.card_le_of_injective (\u03bb p', \u27e8mk_line (this p'), (mk_line_ax (this p')).1\u27e9)\n    (\u03bb p\u2081 p\u2082 hp, subtype.ext ((eq_or_eq p\u2081.2 p\u2082.2 (mk_line_ax (this p\u2081)).2\n      ((congr_arg _ (subtype.ext_iff.mp hp)).mpr (mk_line_ax (this p\u2082)).2)).resolve_right\n        (\u03bb h', (congr_arg _ h').mp h (mk_line_ax (this p\u2081)).1))),\nend\n\nlemma has_points.line_count_le_point_count [has_points P L] {p : P} {l : L} (h : p \u2209 l)\n  [hf : fintype {p : P // p \u2208 l}] : line_count L p \u2264 point_count P l :=\n@has_lines.point_count_le_line_count (dual L) (dual P) _ _ l p h hf\n\nvariables (P L)\n\n/-- If a nondegenerate configuration has a unique line through any two points, then `|P| \u2264 |L|`. -/\nlemma has_lines.card_le [has_lines P L] [fintype P] [fintype L] :\n  fintype.card P \u2264 fintype.card L :=\nbegin\n  classical,\n  by_contradiction hc\u2082,\n  obtain \u27e8f, hf\u2081, hf\u2082\u27e9 := nondegenerate.exists_injective_of_card_le (le_of_not_le hc\u2082),\n  have := calc \u2211 p, line_count L p = \u2211 l, point_count P l : sum_line_count_eq_sum_point_count P L\n  ... \u2264 \u2211 l, line_count L (f l) :\n    finset.sum_le_sum (\u03bb l hl, has_lines.point_count_le_line_count (hf\u2082 l))\n  ... = \u2211 p in finset.univ.image f, line_count L p :\n    finset.sum_bij (\u03bb l hl, f l) (\u03bb l hl, finset.mem_image_of_mem f hl) (\u03bb l hl, rfl)\n      (\u03bb l\u2081 l\u2082 hl\u2081 hl\u2082 hl\u2083, hf\u2081 hl\u2083) (\u03bb p, by simp_rw [finset.mem_image, eq_comm, imp_self])\n  ... < \u2211 p, line_count L p : _,\n  { exact lt_irrefl _ this },\n  { obtain \u27e8p, hp\u27e9 := not_forall.mp (mt (fintype.card_le_of_surjective f) hc\u2082),\n    refine finset.sum_lt_sum_of_subset ((finset.univ.image f).subset_univ) (finset.mem_univ p)\n      _ _ (\u03bb p hp\u2081 hp\u2082, zero_le (line_count L p)),\n    { simpa only [finset.mem_image, exists_prop, finset.mem_univ, true_and] },\n    { rw [line_count, nat.card_eq_fintype_card, fintype.card_pos_iff],\n      obtain \u27e8l, hl\u27e9 := @exists_line P L _ _ p,\n      exact let this := not_exists.mp hp l in \u27e8\u27e8mk_line this, (mk_line_ax this).2\u27e9\u27e9 } },\nend\n\n/-- If a nondegenerate configuration has a unique point on any two lines, then `|L| \u2264 |P|`. -/\nlemma has_points.card_le [has_points P L] [fintype P] [fintype L] :\n  fintype.card L \u2264 fintype.card P :=\n@has_lines.card_le (dual L) (dual P) _ _ _ _\n\nvariables {P L}\n\nlemma has_lines.exists_bijective_of_card_eq [has_lines P L]\n  [fintype P] [fintype L] (h : fintype.card P = fintype.card L) :\n  \u2203 f : L \u2192 P, function.bijective f \u2227 \u2200 l, point_count P l = line_count L (f l) :=\nbegin\n  classical,\n  obtain \u27e8f, hf1, hf2\u27e9 := nondegenerate.exists_injective_of_card_le (ge_of_eq h),\n  have hf3 := (fintype.bijective_iff_injective_and_card f).mpr \u27e8hf1, h.symm\u27e9,\n  refine \u27e8f, hf3, \u03bb l, (finset.sum_eq_sum_iff_of_le\n    (by exact \u03bb l hl, has_lines.point_count_le_line_count (hf2 l))).mp\n      ((sum_line_count_eq_sum_point_count P L).symm.trans ((finset.sum_bij (\u03bb l hl, f l)\n        (\u03bb l hl, finset.mem_univ (f l)) (\u03bb l hl, refl (line_count L (f l)))\n          (\u03bb l\u2081 l\u2082 hl\u2081 hl\u2082 hl, hf1 hl) (\u03bb p hp, _)).symm)) l (finset.mem_univ l)\u27e9,\n  obtain \u27e8l, rfl\u27e9 := hf3.2 p,\n  exact \u27e8l, finset.mem_univ l, rfl\u27e9,\nend\n\nlemma has_lines.line_count_eq_point_count [has_lines P L] [fintype P] [fintype L]\n  (hPL : fintype.card P = fintype.card L) {p : P} {l : L} (hpl : p \u2209 l) :\n  line_count L p = point_count P l :=\nbegin\n  classical,\n  obtain \u27e8f, hf1, hf2\u27e9 := has_lines.exists_bijective_of_card_eq hPL,\n  let s : finset (P \u00d7 L) := set.to_finset {i | i.1 \u2208 i.2},\n  have step1 : \u2211 i : P \u00d7 L, line_count L i.1 = \u2211 i : P \u00d7 L, point_count P i.2,\n  { rw [\u2190finset.univ_product_univ, finset.sum_product_right, finset.sum_product],\n    simp_rw [finset.sum_const, finset.card_univ, hPL, sum_line_count_eq_sum_point_count] },\n  have step2 : \u2211 i in s, line_count L i.1 = \u2211 i in s, point_count P i.2,\n  { rw [s.sum_finset_product finset.univ (\u03bb p, set.to_finset {l | p \u2208 l})],\n    rw [s.sum_finset_product_right finset.univ (\u03bb l, set.to_finset {p | p \u2208 l})],\n    refine (finset.sum_bij (\u03bb l hl, f l) (\u03bb l hl, finset.mem_univ (f l)) (\u03bb l hl, _)\n      (\u03bb _ _ _ _ h, hf1.1 h) (\u03bb p hp, _)).symm,\n    { simp_rw [finset.sum_const, set.to_finset_card, \u2190nat.card_eq_fintype_card],\n      change (point_count P l) \u2022 (point_count P l) = (line_count L (f l)) \u2022 (line_count L (f l)),\n      rw hf2 },\n    { obtain \u27e8l, hl\u27e9 := hf1.2 p,\n      exact \u27e8l, finset.mem_univ l, hl.symm\u27e9 },\n    all_goals { simp_rw [finset.mem_univ, true_and, set.mem_to_finset], exact \u03bb p, iff.rfl } },\n  have step3 : \u2211 i in s\u1d9c, line_count L i.1 = \u2211 i in s\u1d9c, point_count P i.2,\n  { rwa [\u2190s.sum_add_sum_compl, \u2190s.sum_add_sum_compl, step2, add_left_cancel_iff] at step1 },\n  rw \u2190 set.to_finset_compl at step3,\n  exact ((finset.sum_eq_sum_iff_of_le (by exact \u03bb i hi, has_lines.point_count_le_line_count\n    (set.mem_to_finset.mp hi))).mp step3.symm (p, l) (set.mem_to_finset.mpr hpl)).symm,\nend\n\nlemma has_points.line_count_eq_point_count [has_points P L] [fintype P] [fintype L]\n  (hPL : fintype.card P = fintype.card L) {p : P} {l : L} (hpl : p \u2209 l) :\n  line_count L p = point_count P l :=\n(@has_lines.line_count_eq_point_count (dual L) (dual P) _ _  _ _ hPL.symm l p hpl).symm\n\n/-- If a nondegenerate configuration has a unique line through any two points, and if `|P| = |L|`,\n  then there is a unique point on any two lines. -/\nnoncomputable def has_lines.has_points [has_lines P L] [fintype P] [fintype L]\n  (h : fintype.card P = fintype.card L) : has_points P L :=\nlet this : \u2200 l\u2081 l\u2082 : L, l\u2081 \u2260 l\u2082 \u2192 \u2203 p : P, p \u2208 l\u2081 \u2227 p \u2208 l\u2082 := \u03bb l\u2081 l\u2082 hl, begin\n  classical,\n  obtain \u27e8f, hf1, hf2\u27e9 := has_lines.exists_bijective_of_card_eq h,\n  haveI : nontrivial L := \u27e8\u27e8l\u2081, l\u2082, hl\u27e9\u27e9,\n  haveI := fintype.one_lt_card_iff_nontrivial.mp ((congr_arg _ h).mpr fintype.one_lt_card),\n  have h\u2081 : \u2200 p : P, 0 < line_count L p := \u03bb p, exists.elim (exists_ne p) (\u03bb q hq, (congr_arg _\n    nat.card_eq_fintype_card).mpr (fintype.card_pos_iff.mpr \u27e8\u27e8mk_line hq, (mk_line_ax hq).2\u27e9\u27e9)),\n  have h\u2082 : \u2200 l : L, 0 < point_count P l := \u03bb l, (congr_arg _ (hf2 l)).mpr (h\u2081 (f l)),\n  obtain \u27e8p, hl\u2081\u27e9 := fintype.card_pos_iff.mp ((congr_arg _ nat.card_eq_fintype_card).mp (h\u2082 l\u2081)),\n  by_cases hl\u2082 : p \u2208 l\u2082, exact \u27e8p, hl\u2081, hl\u2082\u27e9,\n  have key' : fintype.card {q : P // q \u2208 l\u2082} = fintype.card {l : L // p \u2208 l},\n  { exact ((has_lines.line_count_eq_point_count h hl\u2082).trans nat.card_eq_fintype_card).symm.trans\n    nat.card_eq_fintype_card, },\n  have : \u2200 q : {q // q \u2208 l\u2082}, p \u2260 q := \u03bb q hq, hl\u2082 ((congr_arg (\u2208 l\u2082) hq).mpr q.2),\n  let f : {q : P // q \u2208 l\u2082} \u2192 {l : L // p \u2208 l} := \u03bb q, \u27e8mk_line (this q), (mk_line_ax (this q)).1\u27e9,\n  have hf : function.injective f := \u03bb q\u2081 q\u2082 hq, subtype.ext ((eq_or_eq q\u2081.2 q\u2082.2\n    (mk_line_ax (this q\u2081)).2 ((congr_arg _ (subtype.ext_iff.mp hq)).mpr (mk_line_ax\n      (this q\u2082)).2)).resolve_right (\u03bb h, (congr_arg _ h).mp hl\u2082 (mk_line_ax (this q\u2081)).1)),\n  have key' := ((fintype.bijective_iff_injective_and_card f).mpr \u27e8hf, key'\u27e9).2,\n  obtain \u27e8q, hq\u27e9 := key' \u27e8l\u2081, hl\u2081\u27e9,\n  exact \u27e8q, (congr_arg _ (subtype.ext_iff.mp hq)).mp (mk_line_ax (this q)).2, q.2\u27e9,\nend in\n{ mk_point := \u03bb l\u2081 l\u2082 hl, classical.some (this l\u2081 l\u2082 hl),\n  mk_point_ax := \u03bb l\u2081 l\u2082 hl, classical.some_spec (this l\u2081 l\u2082 hl) }\n\n/-- If a nondegenerate configuration has a unique point on any two lines, and if `|P| = |L|`,\n  then there is a unique line through any two points. -/\nnoncomputable def has_points.has_lines [has_points P L] [fintype P] [fintype L]\n  (h : fintype.card P = fintype.card L) : has_lines P L :=\nlet this := @has_lines.has_points (dual L) (dual P) _ _ _ _ h.symm in\n{ mk_line := this.mk_point,\n  mk_line_ax := this.mk_point_ax }\n\nvariables (P L)\n\n/-- A projective plane is a nondegenerate configuration in which every pair of lines has\n  an intersection point, every pair of points has a line through them,\n  and which has three points in general position. -/\nclass projective_plane extends nondegenerate P L : Type u :=\n(mk_point : \u2200 {l\u2081 l\u2082 : L} (h : l\u2081 \u2260 l\u2082), P)\n(mk_point_ax : \u2200 {l\u2081 l\u2082 : L} (h : l\u2081 \u2260 l\u2082), mk_point h \u2208 l\u2081 \u2227 mk_point h \u2208 l\u2082)\n(mk_line : \u2200 {p\u2081 p\u2082 : P} (h : p\u2081 \u2260 p\u2082), L)\n(mk_line_ax : \u2200 {p\u2081 p\u2082 : P} (h : p\u2081 \u2260 p\u2082), p\u2081 \u2208 mk_line h \u2227 p\u2082 \u2208 mk_line h)\n(exists_config : \u2203 (p\u2081 p\u2082 p\u2083 : P) (l\u2081 l\u2082 l\u2083 : L), p\u2081 \u2209 l\u2082 \u2227 p\u2081 \u2209 l\u2083 \u2227\n  p\u2082 \u2209 l\u2081 \u2227 p\u2082 \u2208 l\u2082 \u2227 p\u2082 \u2208 l\u2083 \u2227 p\u2083 \u2209 l\u2081 \u2227 p\u2083 \u2208 l\u2082 \u2227 p\u2083 \u2209 l\u2083)\n\nnamespace projective_plane\n\n@[priority 100] -- see Note [lower instance priority]\ninstance has_points [h : projective_plane P L] : has_points P L := { .. h }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance has_lines [h : projective_plane P L] : has_lines P L := { .. h }\n\ninstance [projective_plane P L] : projective_plane (dual L) (dual P) :=\n{ mk_line := @mk_point P L _ _,\n  mk_line_ax := \u03bb _ _, mk_point_ax,\n  mk_point := @mk_line P L _ _,\n  mk_point_ax := \u03bb _ _, mk_line_ax,\n  exists_config := by\n  { obtain \u27e8p\u2081, p\u2082, p\u2083, l\u2081, l\u2082, l\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2081, h\u2082\u2082, h\u2082\u2083, h\u2083\u2081, h\u2083\u2082, h\u2083\u2083\u27e9 :=\n    @exists_config P L _ _,\n    exact \u27e8l\u2081, l\u2082, l\u2083, p\u2081, p\u2082, p\u2083, h\u2082\u2081, h\u2083\u2081, h\u2081\u2082, h\u2082\u2082, h\u2083\u2082, h\u2081\u2083, h\u2082\u2083, h\u2083\u2083\u27e9 },\n  .. dual.nondegenerate P L }\n\n/-- The order of a projective plane is one less than the number of lines through an arbitrary point.\nEquivalently, it is one less than the number of points on an arbitrary line. -/\nnoncomputable def order [projective_plane P L] : \u2115 :=\nline_count L (classical.some (@exists_config P L _ _)) - 1\n\nvariables [fintype P] [fintype L]\n\nlemma card_points_eq_card_lines [projective_plane P L] : fintype.card P = fintype.card L :=\nle_antisymm (has_lines.card_le P L) (has_points.card_le P L)\n\nvariables {P} (L)\n\nlemma line_count_eq_line_count [projective_plane P L] (p q : P) :\n  line_count L p = line_count L q :=\nbegin\n  obtain \u27e8p\u2081, p\u2082, p\u2083, l\u2081, l\u2082, l\u2083, h\u2081\u2082, h\u2081\u2083, h\u2082\u2081, h\u2082\u2082, h\u2082\u2083, h\u2083\u2081, h\u2083\u2082, h\u2083\u2083\u27e9 := exists_config,\n  have h := card_points_eq_card_lines P L,\n  let n := line_count L p\u2082,\n  have hp\u2082 : line_count L p\u2082 = n := rfl,\n  have hl\u2081 : point_count P l\u2081 = n := (has_lines.line_count_eq_point_count h h\u2082\u2081).symm.trans hp\u2082,\n  have hp\u2083 : line_count L p\u2083 = n := (has_lines.line_count_eq_point_count h h\u2083\u2081).trans hl\u2081,\n  have hl\u2083 : point_count P l\u2083 = n := (has_lines.line_count_eq_point_count h h\u2083\u2083).symm.trans hp\u2083,\n  have hp\u2081 : line_count L p\u2081 = n := (has_lines.line_count_eq_point_count h h\u2081\u2083).trans hl\u2083,\n  have hl\u2082 : point_count P l\u2082 = n := (has_lines.line_count_eq_point_count h h\u2081\u2082).symm.trans hp\u2081,\n  suffices : \u2200 p : P, line_count L p = n, { exact (this p).trans (this q).symm },\n  refine \u03bb p, or_not.elim (\u03bb h\u2082, _) (\u03bb h\u2082, (has_lines.line_count_eq_point_count h h\u2082).trans hl\u2082),\n  refine or_not.elim (\u03bb h\u2083, _) (\u03bb h\u2083, (has_lines.line_count_eq_point_count h h\u2083).trans hl\u2083),\n  rwa (eq_or_eq h\u2082 h\u2082\u2082 h\u2083 h\u2082\u2083).resolve_right (\u03bb h, h\u2083\u2083 ((congr_arg (has_mem.mem p\u2083) h).mp h\u2083\u2082)),\nend\n\nvariables (P) {L}\n\nlemma point_count_eq_point_count [projective_plane P L] (l m : L) :\n  point_count P l = point_count P m :=\nline_count_eq_line_count (dual P) l m\n\nvariables {P L}\n\nlemma line_count_eq_point_count [projective_plane P L] (p : P) (l : L) :\n  line_count L p = point_count P l :=\nexists.elim (exists_point l) (\u03bb q hq, (line_count_eq_line_count L p q).trans\n  (has_lines.line_count_eq_point_count (card_points_eq_card_lines P L) hq))\n\nvariables (P L)\n\nlemma dual.order [projective_plane P L] : order (dual L) (dual P) = order P L :=\ncongr_arg (\u03bb n, n - 1) (line_count_eq_point_count _ _)\n\nvariables {P} (L)\n\nlemma line_count_eq [projective_plane P L] (p : P) : line_count L p = order P L + 1 :=\nbegin\n  classical,\n  obtain \u27e8q, -, -, l, -, -, -, -, h, -\u27e9 := classical.some_spec (@exists_config P L _ _),\n  rw [order, line_count_eq_line_count L p q, line_count_eq_line_count L (classical.some _) q,\n      line_count, nat.card_eq_fintype_card, nat.sub_add_cancel],\n  exact fintype.card_pos_iff.mpr \u27e8\u27e8l, h\u27e9\u27e9,\nend\n\nvariables (P) {L}\n\nlemma point_count_eq [projective_plane P L] (l : L) : point_count P l = order P L + 1 :=\n(line_count_eq (dual P) l).trans (congr_arg (\u03bb n, n + 1) (dual.order P L))\n\nvariables (P L)\n\nlemma one_lt_order [projective_plane P L] : 1 < order P L :=\nbegin\n  obtain \u27e8p\u2081, p\u2082, p\u2083, l\u2081, l\u2082, l\u2083, -, -, h\u2082\u2081, h\u2082\u2082, h\u2082\u2083, h\u2083\u2081, h\u2083\u2082, h\u2083\u2083\u27e9 := @exists_config P L _ _,\n  classical,\n  rw [\u2190add_lt_add_iff_right, \u2190point_count_eq, point_count, nat.card_eq_fintype_card],\n  simp_rw [fintype.two_lt_card_iff, ne, subtype.ext_iff],\n  have h := mk_point_ax (\u03bb h, h\u2082\u2081 ((congr_arg _ h).mpr h\u2082\u2082)),\n  exact \u27e8\u27e8mk_point _, h.2\u27e9, \u27e8p\u2082, h\u2082\u2082\u27e9, \u27e8p\u2083, h\u2083\u2082\u27e9,\n    ne_of_mem_of_not_mem h.1 h\u2082\u2081, ne_of_mem_of_not_mem h.1 h\u2083\u2081, ne_of_mem_of_not_mem h\u2082\u2083 h\u2083\u2083\u27e9,\nend\n\nvariables {P} (L)\n\nlemma two_lt_line_count [projective_plane P L] (p : P) : 2 < line_count L p :=\nby simpa only [line_count_eq L p, nat.succ_lt_succ_iff] using one_lt_order P L\n\nvariables (P) {L}\n\nlemma two_lt_point_count [projective_plane P L] (l : L) : 2 < point_count P l :=\nby simpa only [point_count_eq P l, nat.succ_lt_succ_iff] using one_lt_order P L\n\nvariables (P) (L)\n\nlemma card_points [projective_plane P L] : fintype.card P = order P L ^ 2 + order P L + 1 :=\nbegin\n  let p : P := (classical.some (@exists_config P L _ _)),\n  let \u03d5 : {q // q \u2260 p} \u2243 \u03a3 (l : {l : L // p \u2208 l}), {q // q \u2208 l.1 \u2227 q \u2260 p} :=\n  { to_fun := \u03bb q, \u27e8\u27e8mk_line q.2, (mk_line_ax q.2).2\u27e9, q, (mk_line_ax q.2).1, q.2\u27e9,\n    inv_fun := \u03bb lq, \u27e8lq.2, lq.2.2.2\u27e9,\n    left_inv := \u03bb q, subtype.ext rfl,\n    right_inv := \u03bb lq, sigma.subtype_ext (subtype.ext ((eq_or_eq (mk_line_ax lq.2.2.2).1\n      (mk_line_ax lq.2.2.2).2 lq.2.2.1 lq.1.2).resolve_left lq.2.2.2)) rfl },\n  classical,\n  have h1 : fintype.card {q // q \u2260 p} + 1 = fintype.card P,\n  { apply (eq_tsub_iff_add_eq_of_le (nat.succ_le_of_lt (fintype.card_pos_iff.mpr \u27e8p\u27e9))).mp,\n    convert (fintype.card_subtype_compl).trans (congr_arg _ (fintype.card_subtype_eq p)) },\n  have h2 : \u2200 l : {l : L // p \u2208 l}, fintype.card {q // q \u2208 l.1 \u2227 q \u2260 p} = order P L,\n  { intro l,\n    rw [\u2190fintype.card_congr (equiv.subtype_subtype_equiv_subtype_inter _ _),\n        fintype.card_subtype_compl, \u2190nat.card_eq_fintype_card],\n    refine tsub_eq_of_eq_add ((point_count_eq P l.1).trans _),\n    rw \u2190 fintype.card_subtype_eq (\u27e8p, l.2\u27e9 : {q : P // q \u2208 l.1}),\n    simp_rw subtype.ext_iff_val },\n  simp_rw [\u2190h1, fintype.card_congr \u03d5, fintype.card_sigma, h2, finset.sum_const, finset.card_univ],\n  rw [\u2190nat.card_eq_fintype_card, \u2190line_count, line_count_eq, smul_eq_mul, nat.succ_mul, sq],\nend\n\nlemma card_lines [projective_plane P L] : fintype.card L = order P L ^ 2 + order P L + 1 :=\n(card_points (dual L) (dual P)).trans (congr_arg (\u03bb n, n ^ 2 + n + 1) (dual.order P L))\n\nend projective_plane\n\nend configuration\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/combinatorics/configuration.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7091026658186264}}
{"text": "-- https://www.youtube.com/watch?v=9Efsz2hIpxE\n-- deriving some results of the theory of fields, in Lean.\n\nnamespace hidden\n\nclass myfield (\u03b1 : Type)\nextends has_mul \u03b1, has_inv \u03b1, has_add \u03b1, has_neg \u03b1, has_zero \u03b1, has_one \u03b1 :=\n-- this axiom can be deduced, so we prove it as a theorem, near the\n-- end.\n-- (A1 (a b: \u03b1): a + b = b + a)\n(A2 (a b c: \u03b1): a + (b + c) =  (a + b) + c)\n(A3 (a: \u03b1): a + 0 = a)\n(A4 (a: \u03b1): a + (-a) = 0)\n(M1 (a b: \u03b1): a * b = b * a)\n(M2 (a b c: \u03b1): a * (b * c) = (a * b) * c)\n(M3 (a: \u03b1): a * 1 = a)\n(M4 (a: \u03b1): a \u2260 0 \u2192 a * (a\u207b\u00b9) = 1)\n(D (a b c: \u03b1): a * (b + c) = a * b + a * c)\n(Z: (0: \u03b1) \u2260 1)\n\nnamespace myfield\n\nvariables {\u03b1: Type} [myfield \u03b1]\n\nvariables (a b c x y: \u03b1)\n\n-- \"Axiom\" A1 is proved as Theorem A1.\n-- Problems 1-12 are labelled as \"theorem p_\".\n-- There are also some lemmas.\n-- This somewhat obscure naming scheme is used for compatibility with the video.\n\nlemma Z': (1: \u03b1) \u2260 0 :=\nbegin\n  from (\u03bb h, Z h.symm),\nend\n\nlemma l1: a + b = 0 \u2192 b + a = 0 :=\nbegin\n  assume h,\n  rw \u2190A4 b,\n  conv {\n    to_rhs,\n    congr,\n    rw \u2190A3 b,\n    rw \u2190h,\n  },\n  rw \u2190A2 b (a + b) (-b),\n  rw \u2190A2 a b (-b),\n  rw A4 b,\n  rw A3 a,\nend\n\nlemma l2: (-a) + a = 0 :=\nbegin\n  rw l1 a (-a) (A4 a),\nend\n\nlemma l3: 0 + a = a :=\nbegin\n  rw \u2190A4 a,\n  rw \u2190A2 a (-a) a,\n  rw l2 a,\n  rw A3 a,\nend\n\nlemma l4: a + b = 0 \u2192 a + c = 0 \u2192 b = c :=\nbegin\n  assume hab hac,\n  rw \u2190l3 c,\n  rw \u2190l1 a b hab,\n  rw \u2190A2 b a c,\n  rw hac,\n  rw A3 b,\nend\n\nlemma l5: a + b = a \u2192 b = 0 :=\nbegin\n  assume haba,\n  rw \u2190l2 a,\n  conv {\n    to_rhs,\n    congr, skip,\n    rw \u2190haba,\n  },\n  rw A2 (-a) a b,\n  rw l2 a,\n  rw l3 b,\nend\n\nlemma l6: (\u2203 a: \u03b1, a + x = a) \u2192 x = 0 :=\nbegin\n  assume h,\n  cases h with a ha,\n  rw \u2190l3 x,\n  rw \u2190l2 a,\n  rw \u2190A2 (-a) a x,\n  rw ha,\nend\n\nlemma l7: -(a + b) = -b + (-a) :=\nbegin\n  apply l4 (a + b) (-(a + b)) (-b + -a) (A4 (a + b)),\n  rw \u2190A2 a b (-b + -a),\n  rw A2 b (-b) (-a),\n  rw A4 b,\n  rw l3 (-a),\n  rw A4 a,\nend\n\nlemma l8: (\u2203 a, a \u2260 0 \u2227 a * x = a) \u2192 x = 1 :=\nbegin\n  assume h,\n  cases h with a ha,\n  rw \u2190M4 a ha.left,\n  conv {\n    to_rhs,\n    congr,\n    rw \u2190ha.right,\n  },\n  rw M1 a x,\n  rw \u2190M2 x a (a\u207b\u00b9),\n  rw M4 a ha.left,\n  rw M3 x,\nend\n\ntheorem p1: a + x = a + y \u2192 x = y :=\nbegin\n  assume haxay,\n  rw \u2190l3 x,\n  rw \u2190l2 a,\n  rw \u2190A2 (-a) a x,\n  rw haxay,\n  rw A2 (-a) a y,\n  rw l2 a,\n  rw l3 y,\nend\n\ntheorem p2: a * 0 = 0 :=\nbegin\n  apply p1 (a * 0),\n  rw \u2190D a 0 0,\n  rw A3 (0: \u03b1),\n  rw A3 (a * 0),\nend\n\nlemma l9: (-1) * a = -a :=\nbegin\n  apply l4 a ((-1) * a) (-a) _ (A4 a),\n  conv {\n    to_lhs,\n    congr,\n    rw \u2190M3 a,\n  },\n  rw \u2190M1 a,\n  rw \u2190D a 1 (-1),\n  rw A4 (1: \u03b1),\n  rw p2 a,\nend\n\nlemma l10: a \u2260 0 \u2192 a\u207b\u00b9 * a = 1 :=\nbegin\n  assume han0,\n  rw M1 (a\u207b\u00b9) a,\n  rw M4 a han0,\nend\n\nlemma l11: 1 * a = a :=\nbegin\n  rw M1 1 a,\n  rw M3 a,\nend\n\n-- hypothesis is much stronger than we need, since we know \u03b1 is\n-- inhabited.\ntheorem p3: (\u2200 a: \u03b1, a + x = a) \u2192 x = 0 :=\nbegin\n  assume h,\n  from l6 x \u27e80, h 0\u27e9,\nend\n\ntheorem p4: -(0: \u03b1) = 0 :=\nbegin\n  from l4 (0: \u03b1) (-0) 0 (A4 0) (A3 0),\nend\n\ntheorem p5: -(-a) = a :=\nbegin\n  from l4 (-a) (- -a) a (A4 (-a)) (l2 a),\nend\n\ntheorem p6: -(a + b) = -a + (-b) :=\nbegin\n  rw \u2190l9 (a + b),\n  rw D (-1) a b,\n  rw l9 a,\n  rw l9 b,\nend\n\ntheorem A1: a + b = b + a :=\nbegin\n  rw \u2190p5 a,\n  rw \u2190p5 b,\n  rw \u2190p6 (-a) (-b),\n  rw \u2190l7 (-a) (-b),\nend\n\ntheorem p7: (\u2200 a, a \u2260 0 \u2192 a * x = a) \u2192 x = 1 :=\nbegin\n  assume h,\n  from l8 x \u27e81, \u27e8Z', h 1 Z'\u27e9\u27e9,\nend\n\ntheorem p8: a \u2260 0 \u2192 a * x = a * y \u2192 x = y :=\nbegin\n  assume han0 haxay,\n  rw \u2190l11 x,\n  rw \u2190l10 a han0,\n  rw \u2190M2 (a\u207b\u00b9) a x,\n  rw haxay,\n  rw M2 (a\u207b\u00b9) a y,\n  rw l10 a han0,\n  rw l11 y,\nend\n\nlemma l12: a \u2260 0 \u2192 a\u207b\u00b9 \u2260 0 :=\nbegin\n  assume han0,\n  assume hai0,\n  apply @Z \u03b1 _,\n  rw \u2190M4 a han0,\n  rw hai0,\n  rw p2 a,\nend\n\ntheorem p9: a \u2260 0 \u2192 (a\u207b\u00b9)\u207b\u00b9 = a :=\nbegin\n  assume han0,\n  conv {\n    to_lhs,\n    rw \u2190M3 (a\u207b\u00b9\u207b\u00b9),\n    rw \u2190l10 a han0,\n    rw M2 (a\u207b\u00b9\u207b\u00b9) (a\u207b\u00b9) a,\n    rw l10 (a\u207b\u00b9) (l12 a han0),\n  },\n  rw l11 a,\nend\n\ntheorem p10: (a + b) * c = a * c + b * c :=\nbegin\n  rw M1 (a + b) c,\n  rw D,\n  rw M1 c a,\n  rw M1 c b,\nend\n\ntheorem p11: a * (-b) = -(a * b) :=\nbegin\n  rw \u2190l9 b,\n  rw \u2190l9 (a * b),\n  rw M2 a (-1) b,\n  rw M1 a (-1),\n  rw \u2190M2 (-1) a b,\nend\n\ntheorem p12: (-1: \u03b1) * (-1) = 1 :=\nbegin\n  rw p11 (-1: \u03b1) 1,\n  rw M1 (-1: \u03b1) 1,\n  rw p11 (1: \u03b1) 1,\n  rw p5 (1 * 1: \u03b1),\n  rw M3 (1: \u03b1),\nend\n\nend myfield\n\nend hidden\n", "meta": {"author": "Sterrs", "repo": "leaning", "sha": "3901cc953694b33adda86cb88ca30ba99594db31", "save_path": "github-repos/lean/Sterrs-leaning", "path": "github-repos/lean/Sterrs-leaning/leaning-3901cc953694b33adda86cb88ca30ba99594db31/src/principia/experimental/myfield/tom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7090842498997848}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module topology.metric_space.antilipschitz\n! leanprover-community/mathlib commit f47581155c818e6361af4e4fda60d27d020c226b\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.MetricSpace.Lipschitz\nimport Mathbin.Topology.UniformSpace.CompleteSeparated\n\n/-!\n# Antilipschitz functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe say that a map `f : \u03b1 \u2192 \u03b2` between two (extended) metric spaces is\n`antilipschitz_with K`, `K \u2265 0`, if for all `x, y` we have `edist x y \u2264 K * edist (f x) (f y)`.\nFor a metric space, the latter inequality is equivalent to `dist x y \u2264 K * dist (f x) (f y)`.\n\n## Implementation notes\n\nThe parameter `K` has type `\u211d\u22650`. This way we avoid conjuction in the definition and have\ncoercions both to `\u211d` and `\u211d\u22650\u221e`. We do not require `0 < K` in the definition, mostly because\nwe do not have a `posreal` type.\n-/\n\n\nvariable {\u03b1 : Type _} {\u03b2 : Type _} {\u03b3 : Type _}\n\nopen NNReal ENNReal uniformity\n\nopen Set Filter Bornology\n\n#print AntilipschitzWith /-\n/-- We say that `f : \u03b1 \u2192 \u03b2` is `antilipschitz_with K` if for any two points `x`, `y` we have\n`edist x y \u2264 K * edist (f x) (f y)`. -/\ndef AntilipschitzWith [PseudoEMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] (K : \u211d\u22650) (f : \u03b1 \u2192 \u03b2) :=\n  \u2200 x y, edist x y \u2264 K * edist (f x) (f y)\n#align antilipschitz_with AntilipschitzWith\n-/\n\n/- warning: antilipschitz_with.edist_lt_top -> AntilipschitzWith.edist_lt_top is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (EDist.edist.{u1} \u03b1 (PseudoEMetricSpace.toHasEdist.{u1} \u03b1 _inst_1) x y) (Top.top.{0} ENNReal (CompleteLattice.toHasTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LT.lt.{0} ENNReal (Preorder.toLT.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal))))) (EDist.edist.{u2} \u03b1 (PseudoEMetricSpace.toEDist.{u2} \u03b1 _inst_1) x y) (Top.top.{0} ENNReal (CompleteLattice.toTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal))))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.edist_lt_top AntilipschitzWith.edist_lt_top\u2093'. -/\ntheorem AntilipschitzWith.edist_lt_top [PseudoEMetricSpace \u03b1] [PseudoMetricSpace \u03b2] {K : \u211d\u22650}\n    {f : \u03b1 \u2192 \u03b2} (h : AntilipschitzWith K f) (x y : \u03b1) : edist x y < \u22a4 :=\n  (h x y).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_ne_top (edist_ne_top _ _)\n#align antilipschitz_with.edist_lt_top AntilipschitzWith.edist_lt_top\n\n/- warning: antilipschitz_with.edist_ne_top -> AntilipschitzWith.edist_ne_top is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), Ne.{1} ENNReal (EDist.edist.{u1} \u03b1 (PseudoEMetricSpace.toHasEdist.{u1} \u03b1 _inst_1) x y) (Top.top.{0} ENNReal (CompleteLattice.toHasTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), Ne.{1} ENNReal (EDist.edist.{u2} \u03b1 (PseudoEMetricSpace.toEDist.{u2} \u03b1 _inst_1) x y) (Top.top.{0} ENNReal (CompleteLattice.toTop.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal))))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.edist_ne_top AntilipschitzWith.edist_ne_top\u2093'. -/\ntheorem AntilipschitzWith.edist_ne_top [PseudoEMetricSpace \u03b1] [PseudoMetricSpace \u03b2] {K : \u211d\u22650}\n    {f : \u03b1 \u2192 \u03b2} (h : AntilipschitzWith K f) (x y : \u03b1) : edist x y \u2260 \u22a4 :=\n  (h.edist_lt_top x y).Ne\n#align antilipschitz_with.edist_ne_top AntilipschitzWith.edist_ne_top\n\nsection Metric\n\nvariable [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2}\n\n/- warning: antilipschitz_with_iff_le_mul_nndist -> antilipschitzWith_iff_le_mul_nndist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, Iff (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (OrderedCancelAddCommMonoid.toPartialOrder.{0} NNReal (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} NNReal NNReal.strictOrderedSemiring)))) (NNDist.nndist.{u1} \u03b1 (PseudoMetricSpace.toNNDist.{u1} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (Distrib.toHasMul.{0} NNReal (NonUnitalNonAssocSemiring.toDistrib.{0} NNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))) K (NNDist.nndist.{u2} \u03b2 (PseudoMetricSpace.toNNDist.{u2} \u03b2 _inst_2) (f x) (f y))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, Iff (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (StrictOrderedSemiring.toPartialOrder.{0} NNReal instNNRealStrictOrderedSemiring))) (NNDist.nndist.{u2} \u03b1 (PseudoMetricSpace.toNNDist.{u2} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (CanonicallyOrderedCommSemiring.toMul.{0} NNReal instNNRealCanonicallyOrderedCommSemiring)) K (NNDist.nndist.{u1} \u03b2 (PseudoMetricSpace.toNNDist.{u1} \u03b2 _inst_2) (f x) (f y))))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with_iff_le_mul_nndist antilipschitzWith_iff_le_mul_nndist\u2093'. -/\ntheorem antilipschitzWith_iff_le_mul_nndist :\n    AntilipschitzWith K f \u2194 \u2200 x y, nndist x y \u2264 K * nndist (f x) (f y) :=\n  by\n  simp only [AntilipschitzWith, edist_nndist]\n  norm_cast\n#align antilipschitz_with_iff_le_mul_nndist antilipschitzWith_iff_le_mul_nndist\n\n/- warning: antilipschitz_with.le_mul_nndist -> AntilipschitzWith.le_mul_nndist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (OrderedCancelAddCommMonoid.toPartialOrder.{0} NNReal (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} NNReal NNReal.strictOrderedSemiring)))) (NNDist.nndist.{u1} \u03b1 (PseudoMetricSpace.toNNDist.{u1} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (Distrib.toHasMul.{0} NNReal (NonUnitalNonAssocSemiring.toDistrib.{0} NNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))) K (NNDist.nndist.{u2} \u03b2 (PseudoMetricSpace.toNNDist.{u2} \u03b2 _inst_2) (f x) (f y))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (StrictOrderedSemiring.toPartialOrder.{0} NNReal instNNRealStrictOrderedSemiring))) (NNDist.nndist.{u2} \u03b1 (PseudoMetricSpace.toNNDist.{u2} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (CanonicallyOrderedCommSemiring.toMul.{0} NNReal instNNRealCanonicallyOrderedCommSemiring)) K (NNDist.nndist.{u1} \u03b2 (PseudoMetricSpace.toNNDist.{u1} \u03b2 _inst_2) (f x) (f y))))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.le_mul_nndist AntilipschitzWith.le_mul_nndist\u2093'. -/\n/- warning: antilipschitz_with.of_le_mul_nndist -> AntilipschitzWith.of_le_mul_nndist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (OrderedCancelAddCommMonoid.toPartialOrder.{0} NNReal (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} NNReal NNReal.strictOrderedSemiring)))) (NNDist.nndist.{u1} \u03b1 (PseudoMetricSpace.toNNDist.{u1} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (Distrib.toHasMul.{0} NNReal (NonUnitalNonAssocSemiring.toDistrib.{0} NNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))) K (NNDist.nndist.{u2} \u03b2 (PseudoMetricSpace.toNNDist.{u2} \u03b2 _inst_2) (f x) (f y)))) -> (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (StrictOrderedSemiring.toPartialOrder.{0} NNReal instNNRealStrictOrderedSemiring))) (NNDist.nndist.{u2} \u03b1 (PseudoMetricSpace.toNNDist.{u2} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (CanonicallyOrderedCommSemiring.toMul.{0} NNReal instNNRealCanonicallyOrderedCommSemiring)) K (NNDist.nndist.{u1} \u03b2 (PseudoMetricSpace.toNNDist.{u1} \u03b2 _inst_2) (f x) (f y)))) -> (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f)\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.of_le_mul_nndist AntilipschitzWith.of_le_mul_nndist\u2093'. -/\nalias antilipschitzWith_iff_le_mul_nndist \u2194\n  AntilipschitzWith.le_mul_nndist AntilipschitzWith.of_le_mul_nndist\n#align antilipschitz_with.le_mul_nndist AntilipschitzWith.le_mul_nndist\n#align antilipschitz_with.of_le_mul_nndist AntilipschitzWith.of_le_mul_nndist\n\n/- warning: antilipschitz_with_iff_le_mul_dist -> antilipschitzWith_iff_le_mul_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, Iff (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.hasLe (Dist.dist.{u1} \u03b1 (PseudoMetricSpace.toHasDist.{u1} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal Real (HasLiftT.mk.{1, 1} NNReal Real (CoeTC\u2093.coe.{1, 1} NNReal Real (coeBase.{1, 1} NNReal Real NNReal.Real.hasCoe))) K) (Dist.dist.{u2} \u03b2 (PseudoMetricSpace.toHasDist.{u2} \u03b2 _inst_2) (f x) (f y))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, Iff (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.instLEReal (Dist.dist.{u2} \u03b1 (PseudoMetricSpace.toDist.{u2} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.instMulReal) (NNReal.toReal K) (Dist.dist.{u1} \u03b2 (PseudoMetricSpace.toDist.{u1} \u03b2 _inst_2) (f x) (f y))))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with_iff_le_mul_dist antilipschitzWith_iff_le_mul_dist\u2093'. -/\ntheorem antilipschitzWith_iff_le_mul_dist :\n    AntilipschitzWith K f \u2194 \u2200 x y, dist x y \u2264 K * dist (f x) (f y) :=\n  by\n  simp only [antilipschitzWith_iff_le_mul_nndist, dist_nndist]\n  norm_cast\n#align antilipschitz_with_iff_le_mul_dist antilipschitzWith_iff_le_mul_dist\n\n/- warning: antilipschitz_with.le_mul_dist -> AntilipschitzWith.le_mul_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.hasLe (Dist.dist.{u1} \u03b1 (PseudoMetricSpace.toHasDist.{u1} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal Real (HasLiftT.mk.{1, 1} NNReal Real (CoeTC\u2093.coe.{1, 1} NNReal Real (coeBase.{1, 1} NNReal Real NNReal.Real.hasCoe))) K) (Dist.dist.{u2} \u03b2 (PseudoMetricSpace.toHasDist.{u2} \u03b2 _inst_2) (f x) (f y))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.instLEReal (Dist.dist.{u2} \u03b1 (PseudoMetricSpace.toDist.{u2} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.instMulReal) (NNReal.toReal K) (Dist.dist.{u1} \u03b2 (PseudoMetricSpace.toDist.{u1} \u03b2 _inst_2) (f x) (f y))))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.le_mul_dist AntilipschitzWith.le_mul_dist\u2093'. -/\n/- warning: antilipschitz_with.of_le_mul_dist -> AntilipschitzWith.of_le_mul_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.hasLe (Dist.dist.{u1} \u03b1 (PseudoMetricSpace.toHasDist.{u1} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal Real (HasLiftT.mk.{1, 1} NNReal Real (CoeTC\u2093.coe.{1, 1} NNReal Real (coeBase.{1, 1} NNReal Real NNReal.Real.hasCoe))) K) (Dist.dist.{u2} \u03b2 (PseudoMetricSpace.toHasDist.{u2} \u03b2 _inst_2) (f x) (f y)))) -> (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.instLEReal (Dist.dist.{u2} \u03b1 (PseudoMetricSpace.toDist.{u2} \u03b1 _inst_1) x y) (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.instMulReal) (NNReal.toReal K) (Dist.dist.{u1} \u03b2 (PseudoMetricSpace.toDist.{u1} \u03b2 _inst_2) (f x) (f y)))) -> (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f)\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.of_le_mul_dist AntilipschitzWith.of_le_mul_dist\u2093'. -/\nalias antilipschitzWith_iff_le_mul_dist \u2194\n  AntilipschitzWith.le_mul_dist AntilipschitzWith.of_le_mul_dist\n#align antilipschitz_with.le_mul_dist AntilipschitzWith.le_mul_dist\n#align antilipschitz_with.of_le_mul_dist AntilipschitzWith.of_le_mul_dist\n\nnamespace AntilipschitzWith\n\n/- warning: antilipschitz_with.mul_le_nndist -> AntilipschitzWith.mul_le_nndist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (OrderedCancelAddCommMonoid.toPartialOrder.{0} NNReal (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} NNReal NNReal.strictOrderedSemiring)))) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (Distrib.toHasMul.{0} NNReal (NonUnitalNonAssocSemiring.toDistrib.{0} NNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))) (Inv.inv.{0} NNReal (DivInvMonoid.toHasInv.{0} NNReal (GroupWithZero.toDivInvMonoid.{0} NNReal (DivisionSemiring.toGroupWithZero.{0} NNReal (Semifield.toDivisionSemiring.{0} NNReal (LinearOrderedSemifield.toSemifield.{0} NNReal (CanonicallyLinearOrderedSemifield.toLinearOrderedSemifield.{0} NNReal NNReal.canonicallyLinearOrderedSemifield)))))) K) (NNDist.nndist.{u1} \u03b1 (PseudoMetricSpace.toNNDist.{u1} \u03b1 _inst_1) x y)) (NNDist.nndist.{u2} \u03b2 (PseudoMetricSpace.toNNDist.{u2} \u03b2 _inst_2) (f x) (f y)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} NNReal (Preorder.toLE.{0} NNReal (PartialOrder.toPreorder.{0} NNReal (StrictOrderedSemiring.toPartialOrder.{0} NNReal instNNRealStrictOrderedSemiring))) (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (CanonicallyOrderedCommSemiring.toMul.{0} NNReal instNNRealCanonicallyOrderedCommSemiring)) (Inv.inv.{0} NNReal (CanonicallyLinearOrderedSemifield.toInv.{0} NNReal NNReal.instCanonicallyLinearOrderedSemifieldNNReal) K) (NNDist.nndist.{u2} \u03b1 (PseudoMetricSpace.toNNDist.{u2} \u03b1 _inst_1) x y)) (NNDist.nndist.{u1} \u03b2 (PseudoMetricSpace.toNNDist.{u1} \u03b2 _inst_2) (f x) (f y)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.mul_le_nndist AntilipschitzWith.mul_le_nndist\u2093'. -/\ntheorem mul_le_nndist (hf : AntilipschitzWith K f) (x y : \u03b1) :\n    K\u207b\u00b9 * nndist x y \u2264 nndist (f x) (f y) := by\n  simpa only [div_eq_inv_mul] using NNReal.div_le_of_le_mul' (hf.le_mul_nndist x y)\n#align antilipschitz_with.mul_le_nndist AntilipschitzWith.mul_le_nndist\n\n/- warning: antilipschitz_with.mul_le_dist -> AntilipschitzWith.mul_le_dist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.hasLe (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.hasMul) (Inv.inv.{0} Real Real.hasInv ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal Real (HasLiftT.mk.{1, 1} NNReal Real (CoeTC\u2093.coe.{1, 1} NNReal Real (coeBase.{1, 1} NNReal Real NNReal.Real.hasCoe))) K)) (Dist.dist.{u1} \u03b1 (PseudoMetricSpace.toHasDist.{u1} \u03b1 _inst_1) x y)) (Dist.dist.{u2} \u03b2 (PseudoMetricSpace.toHasDist.{u2} \u03b2 _inst_2) (f x) (f y)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} Real Real.instLEReal (HMul.hMul.{0, 0, 0} Real Real Real (instHMul.{0} Real Real.instMulReal) (NNReal.toReal (Inv.inv.{0} NNReal (CanonicallyLinearOrderedSemifield.toInv.{0} NNReal NNReal.instCanonicallyLinearOrderedSemifieldNNReal) K)) (Dist.dist.{u2} \u03b1 (PseudoMetricSpace.toDist.{u2} \u03b1 _inst_1) x y)) (Dist.dist.{u1} \u03b2 (PseudoMetricSpace.toDist.{u1} \u03b2 _inst_2) (f x) (f y)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.mul_le_dist AntilipschitzWith.mul_le_dist\u2093'. -/\ntheorem mul_le_dist (hf : AntilipschitzWith K f) (x y : \u03b1) :\n    (K\u207b\u00b9 * dist x y : \u211d) \u2264 dist (f x) (f y) := by exact_mod_cast hf.mul_le_nndist x y\n#align antilipschitz_with.mul_le_dist AntilipschitzWith.mul_le_dist\n\nend AntilipschitzWith\n\nend Metric\n\nnamespace AntilipschitzWith\n\nvariable [PseudoEMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] [PseudoEMetricSpace \u03b3]\n\nvariable {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2}\n\nopen Emetric\n\n#print AntilipschitzWith.k /-\n-- uses neither `f` nor `hf`\n/-- Extract the constant from `hf : antilipschitz_with K f`. This is useful, e.g.,\nif `K` is given by a long formula, and we want to reuse this value. -/\n@[nolint unused_arguments]\nprotected def k (hf : AntilipschitzWith K f) : \u211d\u22650 :=\n  K\n#align antilipschitz_with.K AntilipschitzWith.k\n-/\n\n/- warning: antilipschitz_with.injective -> AntilipschitzWith.injective is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : EMetricSpace.{u1} \u03b1] [_inst_5 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4) _inst_5 K f) -> (Function.Injective.{succ u1, succ u2} \u03b1 \u03b2 f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : EMetricSpace.{u2} \u03b1] [_inst_5 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) _inst_5 K f) -> (Function.Injective.{succ u2, succ u1} \u03b1 \u03b2 f)\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.injective AntilipschitzWith.injective\u2093'. -/\nprotected theorem injective {\u03b1 : Type _} {\u03b2 : Type _} [EMetricSpace \u03b1] [PseudoEMetricSpace \u03b2]\n    {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2} (hf : AntilipschitzWith K f) : Function.Injective f := fun x y h => by\n  simpa only [h, edist_self, MulZeroClass.mul_zero, edist_le_zero] using hf x y\n#align antilipschitz_with.injective AntilipschitzWith.injective\n\n/- warning: antilipschitz_with.mul_le_edist -> AntilipschitzWith.mul_le_edist is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (Distrib.toHasMul.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring)))))))) (Inv.inv.{0} ENNReal ENNReal.hasInv ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal ENNReal (HasLiftT.mk.{1, 1} NNReal ENNReal (CoeTC\u2093.coe.{1, 1} NNReal ENNReal (coeBase.{1, 1} NNReal ENNReal ENNReal.hasCoe))) K)) (EDist.edist.{u1} \u03b1 (PseudoEMetricSpace.toHasEdist.{u1} \u03b1 _inst_1) x y)) (EDist.edist.{u2} \u03b2 (PseudoEMetricSpace.toHasEdist.{u2} \u03b2 _inst_2) (f x) (f y)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (x : \u03b1) (y : \u03b1), LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal))))) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (CanonicallyOrderedCommSemiring.toMul.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)) (Inv.inv.{0} ENNReal ENNReal.instInvENNReal (ENNReal.some K)) (EDist.edist.{u2} \u03b1 (PseudoEMetricSpace.toEDist.{u2} \u03b1 _inst_1) x y)) (EDist.edist.{u1} \u03b2 (PseudoEMetricSpace.toEDist.{u1} \u03b2 _inst_2) (f x) (f y)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.mul_le_edist AntilipschitzWith.mul_le_edist\u2093'. -/\ntheorem mul_le_edist (hf : AntilipschitzWith K f) (x y : \u03b1) :\n    (K\u207b\u00b9 * edist x y : \u211d\u22650\u221e) \u2264 edist (f x) (f y) :=\n  by\n  rw [mul_comm, \u2190 div_eq_mul_inv]\n  exact ENNReal.div_le_of_le_mul' (hf x y)\n#align antilipschitz_with.mul_le_edist AntilipschitzWith.mul_le_edist\n\n/- warning: antilipschitz_with.ediam_preimage_le -> AntilipschitzWith.ediam_preimage_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (s : Set.{u2} \u03b2), LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (EMetric.diam.{u1} \u03b1 _inst_1 (Set.preimage.{u1, u2} \u03b1 \u03b2 f s)) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (Distrib.toHasMul.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring)))))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal ENNReal (HasLiftT.mk.{1, 1} NNReal ENNReal (CoeTC\u2093.coe.{1, 1} NNReal ENNReal (coeBase.{1, 1} NNReal ENNReal ENNReal.hasCoe))) K) (EMetric.diam.{u2} \u03b2 _inst_2 s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (s : Set.{u1} \u03b2), LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal))))) (EMetric.diam.{u2} \u03b1 _inst_1 (Set.preimage.{u2, u1} \u03b1 \u03b2 f s)) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (CanonicallyOrderedCommSemiring.toMul.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)) (ENNReal.some K) (EMetric.diam.{u1} \u03b2 _inst_2 s)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.ediam_preimage_le AntilipschitzWith.ediam_preimage_le\u2093'. -/\ntheorem ediam_preimage_le (hf : AntilipschitzWith K f) (s : Set \u03b2) : diam (f \u207b\u00b9' s) \u2264 K * diam s :=\n  diam_le fun x hx y hy => (hf x y).trans <| mul_le_mul_left' (edist_le_diam_of_mem hx hy) K\n#align antilipschitz_with.ediam_preimage_le AntilipschitzWith.ediam_preimage_le\n\n/- warning: antilipschitz_with.le_mul_ediam_image -> AntilipschitzWith.le_mul_ediam_image is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (s : Set.{u1} \u03b1), LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.completeLinearOrder))))) (EMetric.diam.{u1} \u03b1 _inst_1 s) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (Distrib.toHasMul.{0} ENNReal (NonUnitalNonAssocSemiring.toDistrib.{0} ENNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} ENNReal (Semiring.toNonAssocSemiring.{0} ENNReal (OrderedSemiring.toSemiring.{0} ENNReal (OrderedCommSemiring.toOrderedSemiring.{0} ENNReal (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{0} ENNReal ENNReal.canonicallyOrderedCommSemiring)))))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NNReal ENNReal (HasLiftT.mk.{1, 1} NNReal ENNReal (CoeTC\u2093.coe.{1, 1} NNReal ENNReal (coeBase.{1, 1} NNReal ENNReal ENNReal.hasCoe))) K) (EMetric.diam.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (s : Set.{u2} \u03b1), LE.le.{0} ENNReal (Preorder.toLE.{0} ENNReal (PartialOrder.toPreorder.{0} ENNReal (CompleteSemilatticeInf.toPartialOrder.{0} ENNReal (CompleteLattice.toCompleteSemilatticeInf.{0} ENNReal (CompleteLinearOrder.toCompleteLattice.{0} ENNReal ENNReal.instCompleteLinearOrderENNReal))))) (EMetric.diam.{u2} \u03b1 _inst_1 s) (HMul.hMul.{0, 0, 0} ENNReal ENNReal ENNReal (instHMul.{0} ENNReal (CanonicallyOrderedCommSemiring.toMul.{0} ENNReal ENNReal.instCanonicallyOrderedCommSemiringENNReal)) (ENNReal.some K) (EMetric.diam.{u1} \u03b2 _inst_2 (Set.image.{u2, u1} \u03b1 \u03b2 f s))))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.le_mul_ediam_image AntilipschitzWith.le_mul_ediam_image\u2093'. -/\ntheorem le_mul_ediam_image (hf : AntilipschitzWith K f) (s : Set \u03b1) : diam s \u2264 K * diam (f '' s) :=\n  (diam_mono (subset_preimage_image _ _)).trans (hf.ediam_preimage_le (f '' s))\n#align antilipschitz_with.le_mul_ediam_image AntilipschitzWith.le_mul_ediam_image\n\n#print AntilipschitzWith.id /-\nprotected theorem id : AntilipschitzWith 1 (id : \u03b1 \u2192 \u03b1) := fun x y => by\n  simp only [ENNReal.coe_one, one_mul, id, le_refl]\n#align antilipschitz_with.id AntilipschitzWith.id\n-/\n\n/- warning: antilipschitz_with.comp -> AntilipschitzWith.comp is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {\u03b3 : Type.{u3}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] [_inst_3 : PseudoEMetricSpace.{u3} \u03b3] {Kg : NNReal} {g : \u03b2 -> \u03b3}, (AntilipschitzWith.{u2, u3} \u03b2 \u03b3 _inst_2 _inst_3 Kg g) -> (forall {Kf : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 Kf f) -> (AntilipschitzWith.{u1, u3} \u03b1 \u03b3 _inst_1 _inst_3 (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (Distrib.toHasMul.{0} NNReal (NonUnitalNonAssocSemiring.toDistrib.{0} NNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))) Kf Kg) (Function.comp.{succ u1, succ u2, succ u3} \u03b1 \u03b2 \u03b3 g f)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u3}} {\u03b3 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u3} \u03b2] [_inst_3 : PseudoEMetricSpace.{u2} \u03b3] {Kg : NNReal} {g : \u03b2 -> \u03b3}, (AntilipschitzWith.{u3, u2} \u03b2 \u03b3 _inst_2 _inst_3 Kg g) -> (forall {Kf : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u3} \u03b1 \u03b2 _inst_1 _inst_2 Kf f) -> (AntilipschitzWith.{u1, u2} \u03b1 \u03b3 _inst_1 _inst_3 (HMul.hMul.{0, 0, 0} NNReal NNReal NNReal (instHMul.{0} NNReal (CanonicallyOrderedCommSemiring.toMul.{0} NNReal instNNRealCanonicallyOrderedCommSemiring)) Kf Kg) (Function.comp.{succ u1, succ u3, succ u2} \u03b1 \u03b2 \u03b3 g f)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.comp AntilipschitzWith.comp\u2093'. -/\ntheorem comp {Kg : \u211d\u22650} {g : \u03b2 \u2192 \u03b3} (hg : AntilipschitzWith Kg g) {Kf : \u211d\u22650} {f : \u03b1 \u2192 \u03b2}\n    (hf : AntilipschitzWith Kf f) : AntilipschitzWith (Kf * Kg) (g \u2218 f) := fun x y =>\n  calc\n    edist x y \u2264 Kf * edist (f x) (f y) := hf x y\n    _ \u2264 Kf * (Kg * edist (g (f x)) (g (f y))) := (ENNReal.mul_left_mono (hg _ _))\n    _ = _ := by rw [ENNReal.coe_mul, mul_assoc]\n    \n#align antilipschitz_with.comp AntilipschitzWith.comp\n\n/- warning: antilipschitz_with.restrict -> AntilipschitzWith.restrict is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (s : Set.{u1} \u03b1), AntilipschitzWith.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b2 (Subtype.pseudoEmetricSpace.{u1} \u03b1 (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) _inst_1) _inst_2 K (Set.restrict.{u1, u2} \u03b1 (fun (\u1fb0 : \u03b1) => \u03b2) s f))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall (s : Set.{u2} \u03b1), AntilipschitzWith.{u2, u1} (Set.Elem.{u2} \u03b1 s) \u03b2 (instPseudoEMetricSpaceSubtype.{u2} \u03b1 (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) _inst_1) _inst_2 K (Set.restrict.{u2, u1} \u03b1 (fun (\u1fb0 : \u03b1) => \u03b2) s f))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.restrict AntilipschitzWith.restrict\u2093'. -/\ntheorem restrict (hf : AntilipschitzWith K f) (s : Set \u03b1) : AntilipschitzWith K (s.restrict f) :=\n  fun x y => hf x y\n#align antilipschitz_with.restrict AntilipschitzWith.restrict\n\n/- warning: antilipschitz_with.cod_restrict -> AntilipschitzWith.codRestrict is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {s : Set.{u2} \u03b2} (hs : forall (x : \u03b1), Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) (f x) s), AntilipschitzWith.{u1, u2} \u03b1 (coeSort.{succ u2, succ (succ u2)} (Set.{u2} \u03b2) Type.{u2} (Set.hasCoeToSort.{u2} \u03b2) s) _inst_1 (Subtype.pseudoEmetricSpace.{u2} \u03b2 (fun (x : \u03b2) => Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) x s) _inst_2) K (Set.codRestrict.{u2, succ u1} \u03b2 \u03b1 f s hs))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {s : Set.{u1} \u03b2} (hs : forall (x : \u03b1), Membership.mem.{u1, u1} \u03b2 (Set.{u1} \u03b2) (Set.instMembershipSet.{u1} \u03b2) (f x) s), AntilipschitzWith.{u2, u1} \u03b1 (Set.Elem.{u1} \u03b2 s) _inst_1 (instPseudoEMetricSpaceSubtype.{u1} \u03b2 (fun (x : \u03b2) => Membership.mem.{u1, u1} \u03b2 (Set.{u1} \u03b2) (Set.instMembershipSet.{u1} \u03b2) x s) _inst_2) K (Set.codRestrict.{u1, succ u2} \u03b2 \u03b1 f s hs))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.cod_restrict AntilipschitzWith.codRestrict\u2093'. -/\ntheorem codRestrict (hf : AntilipschitzWith K f) {s : Set \u03b2} (hs : \u2200 x, f x \u2208 s) :\n    AntilipschitzWith K (s.codRestrict f hs) := fun x y => hf x y\n#align antilipschitz_with.cod_restrict AntilipschitzWith.codRestrict\n\n/- warning: antilipschitz_with.to_right_inv_on' -> AntilipschitzWith.to_right_inv_on' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1}, (AntilipschitzWith.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} \u03b1) Type.{u1} (Set.hasCoeToSort.{u1} \u03b1) s) \u03b2 (Subtype.pseudoEmetricSpace.{u1} \u03b1 (fun (x : \u03b1) => Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) x s) _inst_1) _inst_2 K (Set.restrict.{u1, u2} \u03b1 (fun (\u1fb0 : \u03b1) => \u03b2) s f)) -> (forall {g : \u03b2 -> \u03b1} {t : Set.{u2} \u03b2}, (Set.MapsTo.{u2, u1} \u03b2 \u03b1 g t s) -> (Set.RightInvOn.{u1, u2} \u03b1 \u03b2 g f t) -> (LipschitzWith.{u2, u1} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} \u03b2) Type.{u2} (Set.hasCoeToSort.{u2} \u03b2) t) \u03b1 (Subtype.pseudoEmetricSpace.{u2} \u03b2 (fun (x : \u03b2) => Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) x t) _inst_2) _inst_1 K (Set.restrict.{u2, u1} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) t g)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2} {s : Set.{u2} \u03b1}, (AntilipschitzWith.{u2, u1} (Set.Elem.{u2} \u03b1 s) \u03b2 (instPseudoEMetricSpaceSubtype.{u2} \u03b1 (fun (x : \u03b1) => Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) x s) _inst_1) _inst_2 K (Set.restrict.{u2, u1} \u03b1 (fun (\u1fb0 : \u03b1) => \u03b2) s f)) -> (forall {g : \u03b2 -> \u03b1} {t : Set.{u1} \u03b2}, (Set.MapsTo.{u1, u2} \u03b2 \u03b1 g t s) -> (Set.RightInvOn.{u2, u1} \u03b1 \u03b2 g f t) -> (LipschitzWith.{u1, u2} (Set.Elem.{u1} \u03b2 t) \u03b1 (instPseudoEMetricSpaceSubtype.{u1} \u03b2 (fun (x : \u03b2) => Membership.mem.{u1, u1} \u03b2 (Set.{u1} \u03b2) (Set.instMembershipSet.{u1} \u03b2) x t) _inst_2) _inst_1 K (Set.restrict.{u1, u2} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) t g)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.to_right_inv_on' AntilipschitzWith.to_right_inv_on'\u2093'. -/\ntheorem to_right_inv_on' {s : Set \u03b1} (hf : AntilipschitzWith K (s.restrict f)) {g : \u03b2 \u2192 \u03b1}\n    {t : Set \u03b2} (g_maps : MapsTo g t s) (g_inv : RightInvOn g f t) :\n    LipschitzWith K (t.restrict g) := fun x y => by\n  simpa only [restrict_apply, g_inv x.mem, g_inv y.mem, Subtype.edist_eq, Subtype.coe_mk] using\n    hf \u27e8g x, g_maps x.mem\u27e9 \u27e8g y, g_maps y.mem\u27e9\n#align antilipschitz_with.to_right_inv_on' AntilipschitzWith.to_right_inv_on'\n\n/- warning: antilipschitz_with.to_right_inv_on -> AntilipschitzWith.to_rightInvOn is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {g : \u03b2 -> \u03b1} {t : Set.{u2} \u03b2}, (Set.RightInvOn.{u1, u2} \u03b1 \u03b2 g f t) -> (LipschitzWith.{u2, u1} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} \u03b2) Type.{u2} (Set.hasCoeToSort.{u2} \u03b2) t) \u03b1 (Subtype.pseudoEmetricSpace.{u2} \u03b2 (fun (x : \u03b2) => Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) x t) _inst_2) _inst_1 K (Set.restrict.{u2, u1} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) t g)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {g : \u03b2 -> \u03b1} {t : Set.{u1} \u03b2}, (Set.RightInvOn.{u2, u1} \u03b1 \u03b2 g f t) -> (LipschitzWith.{u1, u2} (Set.Elem.{u1} \u03b2 t) \u03b1 (instPseudoEMetricSpaceSubtype.{u1} \u03b2 (fun (x : \u03b2) => Membership.mem.{u1, u1} \u03b2 (Set.{u1} \u03b2) (Set.instMembershipSet.{u1} \u03b2) x t) _inst_2) _inst_1 K (Set.restrict.{u1, u2} \u03b2 (fun (\u1fb0 : \u03b2) => \u03b1) t g)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.to_right_inv_on AntilipschitzWith.to_rightInvOn\u2093'. -/\ntheorem to_rightInvOn (hf : AntilipschitzWith K f) {g : \u03b2 \u2192 \u03b1} {t : Set \u03b2} (h : RightInvOn g f t) :\n    LipschitzWith K (t.restrict g) :=\n  (hf.restrict univ).to_right_inv_on' (mapsTo_univ g t) h\n#align antilipschitz_with.to_right_inv_on AntilipschitzWith.to_rightInvOn\n\n/- warning: antilipschitz_with.to_right_inverse -> AntilipschitzWith.to_rightInverse is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {g : \u03b2 -> \u03b1}, (Function.RightInverse.{succ u1, succ u2} \u03b1 \u03b2 g f) -> (LipschitzWith.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1 K g))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {g : \u03b2 -> \u03b1}, (Function.RightInverse.{succ u2, succ u1} \u03b1 \u03b2 g f) -> (LipschitzWith.{u1, u2} \u03b2 \u03b1 _inst_2 _inst_1 K g))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.to_right_inverse AntilipschitzWith.to_rightInverse\u2093'. -/\ntheorem to_rightInverse (hf : AntilipschitzWith K f) {g : \u03b2 \u2192 \u03b1} (hg : Function.RightInverse g f) :\n    LipschitzWith K g := by\n  intro x y\n  have := hf (g x) (g y)\n  rwa [hg x, hg y] at this\n#align antilipschitz_with.to_right_inverse AntilipschitzWith.to_rightInverse\n\n/- warning: antilipschitz_with.comap_uniformity_le -> AntilipschitzWith.comap_uniformity_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (LE.le.{u1} (Filter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Preorder.toLE.{u1} (Filter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (PartialOrder.toPreorder.{u1} (Filter.{u1} (Prod.{u1, u1} \u03b1 \u03b1)) (Filter.partialOrder.{u1} (Prod.{u1, u1} \u03b1 \u03b1)))) (Filter.comap.{u1, u2} (Prod.{u1, u1} \u03b1 \u03b1) (Prod.{u2, u2} \u03b2 \u03b2) (Prod.map.{u1, u2, u1, u2} \u03b1 \u03b2 \u03b1 \u03b2 f f) (uniformity.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2))) (uniformity.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (LE.le.{u2} (Filter.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Preorder.toLE.{u2} (Filter.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (PartialOrder.toPreorder.{u2} (Filter.{u2} (Prod.{u2, u2} \u03b1 \u03b1)) (Filter.instPartialOrderFilter.{u2} (Prod.{u2, u2} \u03b1 \u03b1)))) (Filter.comap.{u2, u1} (Prod.{u2, u2} \u03b1 \u03b1) (Prod.{u1, u1} \u03b2 \u03b2) (Prod.map.{u2, u1, u2, u1} \u03b1 \u03b2 \u03b1 \u03b2 f f) (uniformity.{u1} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 _inst_2))) (uniformity.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.comap_uniformity_le AntilipschitzWith.comap_uniformity_le\u2093'. -/\ntheorem comap_uniformity_le (hf : AntilipschitzWith K f) : (\ud835\udce4 \u03b2).comap (Prod.map f f) \u2264 \ud835\udce4 \u03b1 :=\n  by\n  refine' ((uniformity_basis_edist.comap _).le_basis_iff\u2093 uniformity_basis_edist).2 fun \u03b5 h\u2080 => _\n  refine' \u27e8K\u207b\u00b9 * \u03b5, ENNReal.mul_pos (ENNReal.inv_ne_zero.2 ENNReal.coe_ne_top) h\u2080.ne', _\u27e9\n  refine' fun x hx => (hf x.1 x.2).trans_lt _\n  rw [mul_comm, \u2190 div_eq_mul_inv] at hx\n  rw [mul_comm]\n  exact ENNReal.mul_lt_of_lt_div hx\n#align antilipschitz_with.comap_uniformity_le AntilipschitzWith.comap_uniformity_le\n\n/- warning: antilipschitz_with.uniform_inducing -> AntilipschitzWith.uniformInducing is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (UniformContinuous.{u1, u2} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1) (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2) f) -> (UniformInducing.{u1, u2} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1) (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2) f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (UniformContinuous.{u2, u1} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1) (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 _inst_2) f) -> (UniformInducing.{u2, u1} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1) (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 _inst_2) f)\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.uniform_inducing AntilipschitzWith.uniformInducing\u2093'. -/\nprotected theorem uniformInducing (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) :\n    UniformInducing f :=\n  \u27e8le_antisymm hf.comap_uniformity_le hfc.le_comap\u27e9\n#align antilipschitz_with.uniform_inducing AntilipschitzWith.uniformInducing\n\n/- warning: antilipschitz_with.uniform_embedding -> AntilipschitzWith.uniformEmbedding is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : EMetricSpace.{u1} \u03b1] [_inst_5 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4) _inst_5 K f) -> (UniformContinuous.{u1, u2} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4)) (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_5) f) -> (UniformEmbedding.{u1, u2} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4)) (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_5) f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : EMetricSpace.{u2} \u03b1] [_inst_5 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) _inst_5 K f) -> (UniformContinuous.{u2, u1} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4)) (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 _inst_5) f) -> (UniformEmbedding.{u2, u1} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4)) (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 _inst_5) f)\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.uniform_embedding AntilipschitzWith.uniformEmbedding\u2093'. -/\nprotected theorem uniformEmbedding {\u03b1 : Type _} {\u03b2 : Type _} [EMetricSpace \u03b1] [PseudoEMetricSpace \u03b2]\n    {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2} (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) :\n    UniformEmbedding f :=\n  \u27e8hf.UniformInducing hfc, hf.Injective\u27e9\n#align antilipschitz_with.uniform_embedding AntilipschitzWith.uniformEmbedding\n\n/- warning: antilipschitz_with.is_complete_range -> AntilipschitzWith.isComplete_range is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2} [_inst_4 : CompleteSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)], (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (UniformContinuous.{u1, u2} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1) (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2) f) -> (IsComplete.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 _inst_2) (Set.range.{u2, succ u1} \u03b2 \u03b1 f))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2} [_inst_4 : CompleteSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)], (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (UniformContinuous.{u2, u1} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1) (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 _inst_2) f) -> (IsComplete.{u1} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 _inst_2) (Set.range.{u1, succ u2} \u03b2 \u03b1 f))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.is_complete_range AntilipschitzWith.isComplete_range\u2093'. -/\ntheorem isComplete_range [CompleteSpace \u03b1] (hf : AntilipschitzWith K f)\n    (hfc : UniformContinuous f) : IsComplete (range f) :=\n  (hf.UniformInducing hfc).isComplete_range\n#align antilipschitz_with.is_complete_range AntilipschitzWith.isComplete_range\n\n/- warning: antilipschitz_with.is_closed_range -> AntilipschitzWith.isClosed_range is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : PseudoEMetricSpace.{u1} \u03b1] [_inst_5 : EMetricSpace.{u2} \u03b2] [_inst_6 : CompleteSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_4)] {f : \u03b1 -> \u03b2} {K : NNReal}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_4 (EMetricSpace.toPseudoEmetricSpace.{u2} \u03b2 _inst_5) K f) -> (UniformContinuous.{u1, u2} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 _inst_4) (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u2} \u03b2 _inst_5)) f) -> (IsClosed.{u2} \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u2} \u03b2 _inst_5))) (Set.range.{u2, succ u1} \u03b2 \u03b1 f))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : PseudoEMetricSpace.{u2} \u03b1] [_inst_5 : EMetricSpace.{u1} \u03b2] [_inst_6 : CompleteSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_4)] {f : \u03b1 -> \u03b2} {K : NNReal}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_4 (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5) K f) -> (UniformContinuous.{u2, u1} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 _inst_4) (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) f) -> (IsClosed.{u1} \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5))) (Set.range.{u1, succ u2} \u03b2 \u03b1 f))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.is_closed_range AntilipschitzWith.isClosed_range\u2093'. -/\ntheorem isClosed_range {\u03b1 \u03b2 : Type _} [PseudoEMetricSpace \u03b1] [EMetricSpace \u03b2] [CompleteSpace \u03b1]\n    {f : \u03b1 \u2192 \u03b2} {K : \u211d\u22650} (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) :\n    IsClosed (range f) :=\n  (hf.isComplete_range hfc).IsClosed\n#align antilipschitz_with.is_closed_range AntilipschitzWith.isClosed_range\n\n/- warning: antilipschitz_with.closed_embedding -> AntilipschitzWith.closedEmbedding is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : EMetricSpace.{u1} \u03b1] [_inst_5 : EMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2} [_inst_6 : CompleteSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4))], (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4) (EMetricSpace.toPseudoEmetricSpace.{u2} \u03b2 _inst_5) K f) -> (UniformContinuous.{u1, u2} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4)) (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u2} \u03b2 _inst_5)) f) -> (ClosedEmbedding.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b1 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4))) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u2} \u03b2 _inst_5))) f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : EMetricSpace.{u2} \u03b1] [_inst_5 : EMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2} [_inst_6 : CompleteSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4))], (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5) K f) -> (UniformContinuous.{u2, u1} \u03b1 \u03b2 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4)) (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5)) f) -> (ClosedEmbedding.{u2, u1} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoEMetricSpace.toUniformSpace.{u2} \u03b1 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4))) (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoEMetricSpace.toUniformSpace.{u1} \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_5))) f)\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.closed_embedding AntilipschitzWith.closedEmbedding\u2093'. -/\ntheorem closedEmbedding {\u03b1 : Type _} {\u03b2 : Type _} [EMetricSpace \u03b1] [EMetricSpace \u03b2] {K : \u211d\u22650}\n    {f : \u03b1 \u2192 \u03b2} [CompleteSpace \u03b1] (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) :\n    ClosedEmbedding f :=\n  { (hf.UniformEmbedding hfc).Embedding with closed_range := hf.isClosed_range hfc }\n#align antilipschitz_with.closed_embedding AntilipschitzWith.closedEmbedding\n\n#print AntilipschitzWith.subtype_coe /-\ntheorem subtype_coe (s : Set \u03b1) : AntilipschitzWith 1 (coe : s \u2192 \u03b1) :=\n  AntilipschitzWith.id.restrict s\n#align antilipschitz_with.subtype_coe AntilipschitzWith.subtype_coe\n-/\n\n/- warning: antilipschitz_with.of_subsingleton -> AntilipschitzWith.of_subsingleton is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2} [_inst_4 : Subsingleton.{succ u1} \u03b1] {K : NNReal}, AntilipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {f : \u03b1 -> \u03b2} [_inst_4 : Subsingleton.{succ u2} \u03b1] {K : NNReal}, AntilipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.of_subsingleton AntilipschitzWith.of_subsingleton\u2093'. -/\ntheorem of_subsingleton [Subsingleton \u03b1] {K : \u211d\u22650} : AntilipschitzWith K f := fun x y => by\n  simp only [Subsingleton.elim x y, edist_self, zero_le]\n#align antilipschitz_with.of_subsingleton AntilipschitzWith.of_subsingleton\n\n/- warning: antilipschitz_with.subsingleton -> AntilipschitzWith.subsingleton is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_4 : EMetricSpace.{u1} \u03b1] [_inst_5 : PseudoEMetricSpace.{u2} \u03b2] {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (EMetricSpace.toPseudoEmetricSpace.{u1} \u03b1 _inst_4) _inst_5 (OfNat.ofNat.{0} NNReal 0 (OfNat.mk.{0} NNReal 0 (Zero.zero.{0} NNReal (MulZeroClass.toHasZero.{0} NNReal (NonUnitalNonAssocSemiring.toMulZeroClass.{0} NNReal (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} NNReal (Semiring.toNonAssocSemiring.{0} NNReal NNReal.semiring))))))) f) -> (Subsingleton.{succ u1} \u03b1)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_4 : EMetricSpace.{u2} \u03b1] [_inst_5 : PseudoEMetricSpace.{u1} \u03b2] {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (EMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_4) _inst_5 (OfNat.ofNat.{0} NNReal 0 (Zero.toOfNat0.{0} NNReal instNNRealZero)) f) -> (Subsingleton.{succ u2} \u03b1)\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.subsingleton AntilipschitzWith.subsingleton\u2093'. -/\n/-- If `f : \u03b1 \u2192 \u03b2` is `0`-antilipschitz, then `\u03b1` is a `subsingleton`. -/\nprotected theorem subsingleton {\u03b1 \u03b2} [EMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (h : AntilipschitzWith 0 f) : Subsingleton \u03b1 :=\n  \u27e8fun x y => edist_le_zero.1 <| (h x y).trans_eq <| MulZeroClass.zero_mul _\u27e9\n#align antilipschitz_with.subsingleton AntilipschitzWith.subsingleton\n\nend AntilipschitzWith\n\nnamespace AntilipschitzWith\n\nopen Metric\n\nvariable [PseudoMetricSpace \u03b1] [PseudoMetricSpace \u03b2] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2}\n\n/- warning: antilipschitz_with.bounded_preimage -> AntilipschitzWith.bounded_preimage is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (forall {s : Set.{u2} \u03b2}, (Metric.Bounded.{u2} \u03b2 _inst_2 s) -> (Metric.Bounded.{u1} \u03b1 _inst_1 (Set.preimage.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (forall {s : Set.{u1} \u03b2}, (Metric.Bounded.{u1} \u03b2 _inst_2 s) -> (Metric.Bounded.{u2} \u03b1 _inst_1 (Set.preimage.{u2, u1} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.bounded_preimage AntilipschitzWith.bounded_preimage\u2093'. -/\ntheorem bounded_preimage (hf : AntilipschitzWith K f) {s : Set \u03b2} (hs : Bounded s) :\n    Bounded (f \u207b\u00b9' s) :=\n  Exists.intro (K * diam s) fun x hx y hy =>\n    calc\n      dist x y \u2264 K * dist (f x) (f y) := hf.le_mul_dist x y\n      _ \u2264 K * diam s := mul_le_mul_of_nonneg_left (dist_le_diam_of_mem hs hx hy) K.2\n      \n#align antilipschitz_with.bounded_preimage AntilipschitzWith.bounded_preimage\n\n/- warning: antilipschitz_with.tendsto_cobounded -> AntilipschitzWith.tendsto_cobounded is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : PseudoMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 _inst_2) K f) -> (Filter.Tendsto.{u1, u2} \u03b1 \u03b2 f (Bornology.cobounded.{u1} \u03b1 (PseudoMetricSpace.toBornology.{u1} \u03b1 _inst_1)) (Bornology.cobounded.{u2} \u03b2 (PseudoMetricSpace.toBornology.{u2} \u03b2 _inst_2)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : PseudoMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (AntilipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 _inst_2) K f) -> (Filter.Tendsto.{u2, u1} \u03b1 \u03b2 f (Bornology.cobounded.{u2} \u03b1 (PseudoMetricSpace.toBornology.{u2} \u03b1 _inst_1)) (Bornology.cobounded.{u1} \u03b2 (PseudoMetricSpace.toBornology.{u1} \u03b2 _inst_2)))\nCase conversion may be inaccurate. Consider using '#align antilipschitz_with.tendsto_cobounded AntilipschitzWith.tendsto_cobounded\u2093'. -/\ntheorem tendsto_cobounded (hf : AntilipschitzWith K f) : Tendsto f (cobounded \u03b1) (cobounded \u03b2) :=\n  compl_surjective.forall.2 fun s (hs : IsBounded s) =>\n    Metric.isBounded_iff.2 <| hf.bounded_preimage <| Metric.isBounded_iff.1 hs\n#align antilipschitz_with.tendsto_cobounded AntilipschitzWith.tendsto_cobounded\n\n#print AntilipschitzWith.properSpace /-\n/-- The image of a proper space under an expanding onto map is proper. -/\nprotected theorem properSpace {\u03b1 : Type _} [MetricSpace \u03b1] {K : \u211d\u22650} {f : \u03b1 \u2192 \u03b2} [ProperSpace \u03b1]\n    (hK : AntilipschitzWith K f) (f_cont : Continuous f) (hf : Function.Surjective f) :\n    ProperSpace \u03b2 :=\n  by\n  apply properSpace_of_compact_closedBall_of_le 0 fun x\u2080 r hr => _\n  let K := f \u207b\u00b9' closed_ball x\u2080 r\n  have A : IsClosed K := is_closed_ball.preimage f_cont\n  have B : bounded K := hK.bounded_preimage bounded_closed_ball\n  have : IsCompact K := is_compact_iff_is_closed_bounded.2 \u27e8A, B\u27e9\n  convert this.image f_cont\n  exact (hf.image_preimage _).symm\n#align antilipschitz_with.proper_space AntilipschitzWith.properSpace\n-/\n\nend AntilipschitzWith\n\n/- warning: lipschitz_with.to_right_inverse -> LipschitzWith.to_rightInverse is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoEMetricSpace.{u1} \u03b1] [_inst_2 : PseudoEMetricSpace.{u2} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (LipschitzWith.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {g : \u03b2 -> \u03b1}, (Function.RightInverse.{succ u1, succ u2} \u03b1 \u03b2 g f) -> (AntilipschitzWith.{u2, u1} \u03b2 \u03b1 _inst_2 _inst_1 K g))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoEMetricSpace.{u2} \u03b1] [_inst_2 : PseudoEMetricSpace.{u1} \u03b2] {K : NNReal} {f : \u03b1 -> \u03b2}, (LipschitzWith.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 K f) -> (forall {g : \u03b2 -> \u03b1}, (Function.RightInverse.{succ u2, succ u1} \u03b1 \u03b2 g f) -> (AntilipschitzWith.{u1, u2} \u03b2 \u03b1 _inst_2 _inst_1 K g))\nCase conversion may be inaccurate. Consider using '#align lipschitz_with.to_right_inverse LipschitzWith.to_rightInverse\u2093'. -/\ntheorem LipschitzWith.to_rightInverse [PseudoEMetricSpace \u03b1] [PseudoEMetricSpace \u03b2] {K : \u211d\u22650}\n    {f : \u03b1 \u2192 \u03b2} (hf : LipschitzWith K f) {g : \u03b2 \u2192 \u03b1} (hg : Function.RightInverse g f) :\n    AntilipschitzWith K g := fun x y => by simpa only [hg _] using hf (g x) (g y)\n#align lipschitz_with.to_right_inverse LipschitzWith.to_rightInverse\n\n/- warning: lipschitz_with.proper_space -> LipschitzWith.properSpace is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : PseudoMetricSpace.{u1} \u03b1] [_inst_2 : MetricSpace.{u2} \u03b2] [_inst_3 : ProperSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)] {K : NNReal} {f : Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoMetricSpace.toUniformSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)))}, (LipschitzWith.{u1, u2} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u1} \u03b1 _inst_1) (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)) K (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoMetricSpace.toUniformSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)))) (fun (_x : Homeomorph.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoMetricSpace.toUniformSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)))) => \u03b1 -> \u03b2) (Homeomorph.hasCoeToFun.{u1, u2} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u1} \u03b1 (PseudoMetricSpace.toUniformSpace.{u1} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u2} \u03b2 (PseudoMetricSpace.toUniformSpace.{u2} \u03b2 (MetricSpace.toPseudoMetricSpace.{u2} \u03b2 _inst_2)))) f)) -> (ProperSpace.{u1} \u03b1 _inst_1)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : PseudoMetricSpace.{u2} \u03b1] [_inst_2 : MetricSpace.{u1} \u03b2] [_inst_3 : ProperSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2)] {K : NNReal} {f : Homeomorph.{u2, u1} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoMetricSpace.toUniformSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2)))}, (LipschitzWith.{u2, u1} \u03b1 \u03b2 (PseudoMetricSpace.toPseudoEMetricSpace.{u2} \u03b1 _inst_1) (EMetricSpace.toPseudoEMetricSpace.{u1} \u03b2 (MetricSpace.toEMetricSpace.{u1} \u03b2 _inst_2)) K (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (Homeomorph.{u2, u1} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoMetricSpace.toUniformSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2)))) \u03b1 (fun (_x : \u03b1) => \u03b2) (EmbeddingLike.toFunLike.{max (succ u2) (succ u1), succ u2, succ u1} (Homeomorph.{u2, u1} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoMetricSpace.toUniformSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2)))) \u03b1 \u03b2 (EquivLike.toEmbeddingLike.{max (succ u2) (succ u1), succ u2, succ u1} (Homeomorph.{u2, u1} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoMetricSpace.toUniformSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2)))) \u03b1 \u03b2 (Homeomorph.instEquivLikeHomeomorph.{u2, u1} \u03b1 \u03b2 (UniformSpace.toTopologicalSpace.{u2} \u03b1 (PseudoMetricSpace.toUniformSpace.{u2} \u03b1 _inst_1)) (UniformSpace.toTopologicalSpace.{u1} \u03b2 (PseudoMetricSpace.toUniformSpace.{u1} \u03b2 (MetricSpace.toPseudoMetricSpace.{u1} \u03b2 _inst_2)))))) f)) -> (ProperSpace.{u2} \u03b1 _inst_1)\nCase conversion may be inaccurate. Consider using '#align lipschitz_with.proper_space LipschitzWith.properSpace\u2093'. -/\n/-- The preimage of a proper space under a Lipschitz homeomorphism is proper. -/\n@[protected]\ntheorem LipschitzWith.properSpace [PseudoMetricSpace \u03b1] [MetricSpace \u03b2] [ProperSpace \u03b2] {K : \u211d\u22650}\n    {f : \u03b1 \u2243\u209c \u03b2} (hK : LipschitzWith K f) : ProperSpace \u03b1 :=\n  (hK.to_rightInverse f.right_inv).ProperSpace f.symm.Continuous f.symm.Surjective\n#align lipschitz_with.proper_space LipschitzWith.properSpace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/MetricSpace/Antilipschitz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7090842407140768}}
{"text": "/- Various utilities for proving properties of orderings. -/\n\nnamespace order\n\n/-- Show le_total for a basic lexiographic-like order. -/\nprotected lemma lex_like.le_total\n    {\u03b1 \u03b2 : Type*} [linear_order \u03b1] [linear_order \u03b2]\n    (a a' : \u03b1) (b b' : \u03b2)\n  : (a < a' \u2228 (a = a' \u2227 b \u2264 b')) \u2228 (a' < a \u2228 (a' = a \u2227 b' \u2264 b))\n  := begin\n    cases le_total a a',\n    case or.inl : a_le {\n      cases lt_or_eq_of_le a_le,\n      case or.inl : lt { from or.inl (or.inl lt) },\n      case or.inr : eq {\n        cases eq,\n        from or.imp (\u03bb h, or.inr \u27e8 eq, h \u27e9) (\u03bb h, or.inr \u27e8 symm eq, h \u27e9)\n          (le_total b b')\n      }\n    },\n    case or.inr : b_le_a {\n      cases lt_or_eq_of_le b_le_a,\n      case or.inl : lt { from or.inr (or.inl lt) },\n      case or.inr : eq {\n        cases eq,\n        from or.imp (\u03bb h, or.inr \u27e8 eq, h \u27e9) (\u03bb h, or.inr \u27e8 symm eq, h \u27e9)\n          (le_total b b')\n      }\n    }\n  end\n\nend order\n", "meta": {"author": "continuouspi", "repo": "lean-cpi", "sha": "443bf2cb236feadc45a01387099c236ab2b78237", "save_path": "github-repos/lean/continuouspi-lean-cpi", "path": "github-repos/lean/continuouspi-lean-cpi/lean-cpi-443bf2cb236feadc45a01387099c236ab2b78237/src/order/lex_like.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7090842373603039}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module order.filter.modeq\n! leanprover-community/mathlib commit 13a5329a8625701af92e9a96ffc90fa787fff24d\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Parity\nimport Mathbin.Order.Filter.AtTopBot\n\n/-!\n# Numbers are frequently modeq to fixed numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove that `m \u2261 d [MOD n]` frequently as `m \u2192 \u221e`.\n-/\n\n\nopen Filter\n\nnamespace Nat\n\n#print Nat.frequently_modEq /-\n/-- Infinitely many natural numbers are equal to `d` mod `n`. -/\ntheorem frequently_modEq {n : \u2115} (h : n \u2260 0) (d : \u2115) : \u2203\u1da0 m in atTop, m \u2261 d [MOD n] :=\n  ((tendsto_add_atTop_nat d).comp (tendsto_id.nsmul_atTop h.bot_lt)).Frequently <|\n    frequently_of_forall fun m => by simp [Nat.modEq_iff_dvd, \u2190 sub_sub]\n#align nat.frequently_modeq Nat.frequently_modEq\n-/\n\n#print Nat.frequently_mod_eq /-\ntheorem frequently_mod_eq {d n : \u2115} (h : d < n) : \u2203\u1da0 m in atTop, m % n = d := by\n  simpa only [Nat.ModEq, mod_eq_of_lt h] using frequently_modeq h.ne_bot d\n#align nat.frequently_mod_eq Nat.frequently_mod_eq\n-/\n\n#print Nat.frequently_even /-\ntheorem frequently_even : \u2203\u1da0 m : \u2115 in atTop, Even m := by\n  simpa only [even_iff] using frequently_mod_eq zero_lt_two\n#align nat.frequently_even Nat.frequently_even\n-/\n\n#print Nat.frequently_odd /-\ntheorem frequently_odd : \u2203\u1da0 m : \u2115 in atTop, Odd m := by\n  simpa only [odd_iff] using frequently_mod_eq one_lt_two\n#align nat.frequently_odd Nat.frequently_odd\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/Filter/Modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7090842373603039}}
{"text": "import linear_algebra.basic algebra.field data.complex.basic data.real.basic analysis.metric_space analysis.topology.uniform_space\n\nopen vector_space field set complex real\nuniverses u v w\n\nclass semi_norm_space (V : Type u) extends module \u2102 V := \n(N : V \u2192 \u211d)\n(semi_norm_nonneg : \u2200 (x : V), N(x) \u2265 0)\n(semi_norm_sub_add : \u2200 (x y : V), N(x + y) \u2264 N(x) + N(y))\n(semi_norm_abs_hom : \u2200 (x : V), \u2200 (a : \u2102), N(a \u2022 x) = abs(a)*N(x))\n\nclass norm_space (V : Type u) extends module \u2102 V :=\n(N : V \u2192 \u211d)\n(norm_nonneg : \u2200 (x : V), N(x) \u2265 0)\n(norm_sub_add : \u2200 (x y : V), N(x + y) \u2264 N(x) + N(y))\n(norm_abs_hom : \u2200 (x : V), \u2200 (a : \u2102), N(a \u2022 x) = abs(a)*N(x))\n(norm_pos_def : \u2200 (x : V), N(x) = (0 : \u211d) \u2194 x = (0 : V))  \n\nopen norm_space\n\nvariables {V : Type u} [norm_space V] \n\n@[simp] lemma norm_zero : N(0 : V) = 0 := (norm_pos_def 0).mpr (refl 0)  \n\n@[simp] lemma norm_neg (x : V) : N(-x) = N(x) := \nbegin\nrw \u2190neg_one_smul,\nrw norm_abs_hom,\nsimp,\nend\n\nlemma norm_ne_zero_iff_ne_zero (x : V) :\nN(x) \u2260 0 \u2194 x \u2260 0 := --\u27e8\u03bb H, (iff_false_left H).mp (norm_pos_def x), \u03bb H, (iff_false_right H).mp (norm_pos_def x)\u27e9 \nbegin\nsplit,\n    intros H,\n    exact (iff_false_left H).mp (norm_pos_def x), \n\n    intros H,\n    exact (iff_false_right H).mp (norm_pos_def x),\nend\n\ntheorem norm_sub_le_sub_norm (x y : V) : complex.abs(N(x) - N(y)) \u2264 N(x - y) :=\nbegin\nrw \u2190of_real_sub,\nrw abs_of_real,\nrw abs_le,\nsplit,\n    ring,\n    have Hy : N((y - x) + x) = N(y),\n        simp,\n    have H1 : N((y - x) + x) \u2264 N(y - x) + N(x),\n        exact norm_sub_add (y - x) (x), \n    rw Hy at H1,\n    rw \u2190(add_le_add_iff_right (-N(x))) at H1,\n    ring at H1,\n    rw [\u2190neg_sub, norm_neg],\n    rw neg_le,\n    ring,\n    exact H1,\n\n\n    have Hx : N((x - y) + y) = N(x),\n        simp,\n    have H2 : N((x - y) + y) \u2264 N(x - y) + N(y),\n        exact norm_sub_add (x - y) (y), \n    rw Hx at H2,\n    rw \u2190(add_le_add_iff_right (-N(y))) at H2,\n    ring at H2,\n    exact H2,\nend\n\n\nnoncomputable def norm_dist (x y : V) := N(x - y)\n\nnoncomputable instance to_metric_space : has_coe (norm_space V) (metric_space V) :=\n\u27e8\u03bbh, {\ndist := norm_dist, \ndist_self := \n    begin\n    intros, \n    dunfold norm_dist,\n    simp,\n    end,\neq_of_dist_eq_zero :=\n    begin\n    dunfold norm_dist,\n    intros x y H,\n    exact sub_eq_zero.mp ((norm_pos_def (x - y)).mp H),\n    end,\ndist_comm := \n    begin\n    intros,\n    dunfold norm_dist,\n    rw \u2190neg_sub,\n    rw norm_neg,\n    end,\ndist_triangle := \n    begin \n    dunfold norm_dist,\n    intros,\n    have H : x - z = (x - y) + (y - z),\n        simp,\n    rw H, \n    exact norm_sub_add (x - y) (y - z),\n    end,\n} \u27e9 \n\ndef is_normalised (x : V) := N(x) = 1 \n\nnoncomputable def normalise (x : V) := \u2191(N(x))\u207b\u00b9 \u2022 x \n\ndef normalise_set :\nset V \u2192 set V := image(normalise)\n\nlemma normalised_linear_indep (s : set V) :\nlinear_independent s \u2192 linear_independent (normalise_set s) :=\nbegin\ndunfold linear_independent,\nintros H1 l H3 H4, \nhave H5 : \u2200 (x : V), x \u2209 s \u2192 x \u2208 normalise_set s,\n    intros x hx,\nend\n\n#print finsupp.sum\n#print finsupp\n#print coe_fn\n\n\nlemma normalised_span_spans (s : set V) : \nspan s = span (normalise_set s) :=\nbegin\nrw set_eq_def,\nintros,\ndunfold span, \nsplit,\n    intros H,\n    rw mem_set_of_eq at H,\n    apply exists.elim H,\n    intros v Hv,\n    \n    admit,\n\n    admit,\nend\n\ntheorem exists_normalised_basis : \n\u2203 (b : set V), is_basis b \u2227 \u2200 (x : V), x \u2208 b \u2192 is_normalised x :=\nbegin\nhave H1 : \u2203 (b : set V), is_basis b,\n    exact exists_is_basis V,\napply exists.elim H1,\nintros b Hb,\nexact exists.intro (normalise_set b) (and.intro (normalised_basis_is_basis b Hb) (normalise_set_normalises b (zero_not_mem_of_linear_independent (zero_ne_one \u2102) Hb.left))),\nend\n\nnoncomputable instance complex_is_norm_space : norm_space \u2102 :=\n{\nN := abs,\nnorm_nonneg := abs_nonneg,\nnorm_sub_add := by exact abs_add,\nnorm_abs_hom := by simp,\nnorm_pos_def := by simp; exact abs_eq_zero,\n}\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/inner_product_spaces/norm_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7090842321479094}}
{"text": "import tactic\nimport data.set.finite\n\nimport topological_spaces\nimport neighbourhoods\n\nopen set\n\nopen topological_space\n\n-- Convergence d'une suite :\ndef seq_lim {X : Type} [topological_space X] (u : \u2115 \u2192 X) (l : X) : Prop :=\n\u2200 (V : set X), V \u2208 neighbourhoods l \u2192 \u2203 (N : \u2115), \u2200 n \u2265 N, u n \u2208 V\n\n-- Fonction continue :\ndef continuous {X Y : Type} [topological_space X] [topological_space Y] (f : X \u2192 Y) : Prop :=\n\u2200 (U : set Y), is_open U \u2192 is_open (f \u207b\u00b9' U)\n\n-- Une fonction est continue si et seulement si l'image r\u00e9ciproque de tout ferm\u00e9 est un ferm\u00e9 :\nlemma continuous_closed {X Y : Type} [topological_space X] [topological_space Y] (f : X \u2192 Y) :\ncontinuous f \u2194 \u2200 (F : set Y), is_closed F \u2192 is_closed (f \u207b\u00b9' F) :=\nbegin\n  split,\n  { intro hyp,\n    intros F hF,\n    exact hyp (compl F) hF, },\n  { intro hyp,\n    intros U hU,\n    rw \u2190 compl_compl U at hU,\n    rw \u2190 compl_compl (f \u207b\u00b9' U),\n    exact hyp (compl U) hU, },\nend\n\n-- Int\u00e9rieur d'une partie :\ndef interior {X : Type} [topological_space X] (A : set X) : set X := \u22c3\u2080 {U : set X | is_open U \u2227 U \u2286 A}\n\n-- Point int\u00e9rieur :\nlemma interior_point {X : Type} [topological_space X] (A : set X) :\n\u2200 a \u2208 A, a \u2208 interior A \u2194 A \u2208 neighbourhoods a :=\nbegin\n  intros a ha,\n  rw is_neighbourhood_iff,\n  split,\n  rintro \u27e8U, \u27e8hU, hUA\u27e9, haU\u27e9,\n  use [U, hU, haU, hUA],\n  rintro \u27e8U, hU, hUA, haU\u27e9,\n  use [U, hU, haU, hUA],\nend\n\n-- Adh\u00e9rence d'une partie :\ndef closure {X : Type} [topological_space X] (A : set X) : set X := \u22c2\u2080 {F : set X | is_closed F \u2227 A \u2286 F}\n\n-- Partie dense :\ndef dense {X : Type} [topological_space X] (A : set X) : Prop := closure A = univ\n\n-- L'adh\u00e9rence d'une partie est ferm\u00e9e :\nlemma closure_closed {X : Type} [topological_space X] (A : set X) :\nis_closed (closure A) :=\nbegin\n  unfold is_closed, unfold closure,\n  rw compl_sInter,\n  apply union,\n  rintros U \u27e8F, \u27e8hF, hAF\u27e9, hU\u27e9,\n  rw \u2190 hU,\n  exact hF,\nend\n\n-- Une partie est ferm\u00e9e si et seulement si elle est \u00e9gale \u00e0 son adh\u00e9rence :\nlemma is_closed_iff {X : Type} [topological_space X] (F : set X) :\nis_closed F \u2194 F = closure F :=\nbegin\n  split,\n  { intro hyp,\n    apply le_antisymm,\n    { apply subset_sInter, simp, },\n    { apply sInter_subset_of_mem,\n      split,\n      exact hyp,\n      exact le_refl F, }, },\n  { intro hyp,\n    rw hyp,\n    exact closure_closed F, },\nend\n\n-- Croissance de l'adh\u00e9rence :\nlemma closure_subset {X : Type} [topological_space X] {A B : set X} :\nA \u2286 B \u2192 closure A \u2286 closure B :=\nbegin\n  intro hyp,\n  intros x hx,\n  rintros F \u27e8hF, hBF\u27e9,\n  apply hx F, split,\n  exact hF,\n  rw \u2190 le_eq_subset,\n  exact le_trans hyp hBF,\nend\n\n-- Point adh\u00e9rent :\nlemma point_of_closure {X : Type} [topological_space X] (A : set X) :\n\u2200 (x : X), x \u2208 closure A \u2194 \u2200 (V : set X), V \u2208 neighbourhoods x \u2192 (V \u2229 A).nonempty :=\nbegin\n  intro x,\n  split,\n  { intro hyp,\n    intros V hV,\n    rcases (is_neighbourhood_iff x).1 hV with \u27e8U, hU, hxU, hUV\u27e9,\n    by_contradiction hVA,\n    have H1 : is_closed (compl U),\n    { rw \u2190 (compl_compl U) at hU,\n      exact hU, },\n    have H2 : A \u2286 compl U,\n    { intros a haA,\n      simp, by_contradiction haU,\n      apply hVA,\n      use a,\n      exact \u27e8hUV haU, haA\u27e9, },\n    exact hyp (compl U) \u27e8H1, H2\u27e9 hxU, },\n  { intro hyp,\n    rintros F \u27e8hF, hAF\u27e9,\n    by_contradiction,\n    have clef : compl F \u2208 neighbourhoods x,\n      { apply generated_filter.generator,\n        exact \u27e8hF, h\u27e9, },\n    cases hyp (compl F) clef with x hx,\n    exact hx.1 (hAF hx.2), },\nend\n\n-- La limite d'une suite d'\u00e9l\u00e9ments de A est un point adh\u00e9rent de A :\nlemma seq_lim_closure {X : Type} [topological_space X] {A : set X} (u : \u2115 \u2192 X) {l : X} :\n(\u2200 n, u n \u2208 A) \u2227 (seq_lim u l) \u2192 l \u2208 closure A :=\nbegin\n  rintros \u27e8h1, h2\u27e9,\n  rw point_of_closure A l,\n  intros V hV,\n  cases h2 V hV with N hN,\n  use u N,\n  exact \u27e8hN N (by linarith), h1 N\u27e9,\nend\n\n-- Une caract\u00e9risation de la continuit\u00e9 :\nexample {X Y : Type} [topological_space X] [topological_space Y] (f : X \u2192 Y) :\ncontinuous f \u2194 \u2200 (A : set X), f '' (closure A) \u2286 closure (f '' A) :=\nbegin\n  split,\n  { intro hyp,\n    intro A,\n    rintros y \u27e8x, hx, hy\u27e9,\n    rw point_of_closure (f '' A) y,\n    intros V hV,\n    rcases (is_neighbourhood_iff y).1 hV with \u27e8U, hU, hyU, hUV\u27e9,\n    have clef : (f \u207b\u00b9' U) \u2208 neighbourhoods x,\n    { apply generated_filter.generator,\n      rw \u2190 hy at hyU,\n      exact \u27e8hyp U hU, hyU\u27e9, },\n    cases (point_of_closure A x).1 hx (f \u207b\u00b9' U) clef with x' hx',\n    use f x',\n    split,\n    exact hUV hx'.1,\n    use x', simp [hx'.2], },\n  { intro hyp,\n    rw continuous_closed,\n    intros F hF,\n    rw is_closed_iff,\n    apply le_antisymm,\n    { apply subset_sInter, simp, },\n    { specialize hyp (f \u207b\u00b9' F),\n      rw \u2190 le_eq_subset at hyp,\n      have hyp' := le_trans hyp (closure_subset (image_preimage_subset f F)),\n      rw \u2190 (is_closed_iff F).1 hF at hyp',\n      simp at hyp', exact hyp', }, },\nend", "meta": {"author": "amesnard0", "repo": "lean-topology", "sha": "e8f6a720c435cb59d098579a26f6eb70ea05f91a", "save_path": "github-repos/lean/amesnard0-lean-topology", "path": "github-repos/lean/amesnard0-lean-topology/lean-topology-e8f6a720c435cb59d098579a26f6eb70ea05f91a/src/topological_spaces2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.7090602255511573}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport order.filter.basic\n\n/-!\n# Minimum and maximum w.r.t. a filter and on a aet\n\n## Main Definitions\n\nThis file defines six predicates of the form `is_A_B`, where `A` is `min`, `max`, or `extr`,\nand `B` is `filter` or `on`.\n\n* `is_min_filter f l a` means that `f a \u2264 f x` in some `l`-neighborhood of `a`;\n* `is_max_filter f l a` means that `f x \u2264 f a` in some `l`-neighborhood of `a`;\n* `is_extr_filter f l a` means `is_min_filter f l a` or `is_max_filter f l a`.\n\nSimilar predicates with `_on` suffix are particular cases for `l = \ud835\udcdf s`.\n\n## Main statements\n\n### Change of the filter (set) argument\n\n* `is_*_filter.filter_mono` : replace the filter with a smaller one;\n* `is_*_filter.filter_inf` : replace a filter `l` with `l \u2293 l'`;\n* `is_*_on.on_subset` : restrict to a smaller set;\n* `is_*_on.inter` : replace a set `s` wtih `s \u2229 t`.\n\n### Composition\n\n* `is_*_*.comp_mono` : if `x` is an extremum for `f` and `g` is a monotone function,\n  then `x` is an extremum for `g \u2218 f`;\n* `is_*_*.comp_antimono` : similarly for the case of monotonically decreasing `g`;\n* `is_*_*.bicomp_mono` : if `x` is an extremum of the same type for `f` and `g`\n  and a binary operation `op` is monotone in both arguments, then `x` is an extremum\n  of the same type for `\u03bb x, op (f x) (g x)`.\n* `is_*_filter.comp_tendsto` : if `g x` is an extremum for `f` w.r.t. `l'` and `tendsto g l l'`,\n  then `x` is an extremum for `f \u2218 g` w.r.t. `l`.\n* `is_*_on.on_preimage` : if `g x` is an extremum for `f` on `s`, then `x` is an extremum\n  for `f \u2218 g` on `g \u207b\u00b9' s`.\n\n### Algebraic operations\n\n* `is_*_*.add` : if `x` is an extremum of the same type for two functions,\n  then it is an extremum of the same type for their sum;\n* `is_*_*.neg` : if `x` is an extremum for `f`, then it is an extremum\n  of the opposite type for `-f`;\n* `is_*_*.sub` : if `x` is an a minimum for `f` and a maximum for `g`,\n  then it is a minimum for `f - g` and a maximum for `g - f`;\n* `is_*_*.max`, `is_*_*.min`, `is_*_*.sup`, `is_*_*.inf` : similarly for `is_*_*.add`\n  for pointwise `max`, `min`, `sup`, `inf`, respectively.\n\n\n### Miscellaneous definitions\n\n* `is_*_*_const` : any point is both a minimum and maximum for a constant function;\n* `is_min/max_*.is_ext` : any minimum/maximum point is an extremum;\n* `is_*_*.dual`, `is_*_*.undual`: conversion between codomains `\u03b1` and `dual \u03b1`;\n\n## Missing features (TODO)\n\n* Multiplication and division;\n* `is_*_*.bicompl` : if `x` is a minimum for `f`, `y` is a minimum for `g`, and `op` is a monotone\n  binary operation, then `(x, y)` is a minimum for `uncurry (bicompl op f g)`. From this point\n  of view, `is_*_*.bicomp` is a composition\n* It would be nice to have a tactic that specializes `comp_(anti)mono` or `bicomp_mono`\n  based on a proof of monotonicity of a given (binary) function. The tactic should maintain a `meta`\n  list of known (anti)monotone (binary) functions with their names, as well as a list of special\n  types of filters, and define the missing lemmas once one of these two lists grows.\n-/\n\nuniverses u v w x\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}\n\nopen set filter\nopen_locale filter\n\nsection preorder\n\nvariables [preorder \u03b2] [preorder \u03b3]\n\nvariables (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (l : filter \u03b1) (a : \u03b1)\n\n/-! ### Definitions -/\n\n/-- `is_min_filter f l a` means that `f a \u2264 f x` in some `l`-neighborhood of `a` -/\ndef is_min_filter : Prop := \u2200\u1da0 x in l, f a \u2264 f x\n\n/-- `is_max_filter f l a` means that `f x \u2264 f a` in some `l`-neighborhood of `a` -/\ndef is_max_filter : Prop := \u2200\u1da0 x in l, f x \u2264 f a\n\n/-- `is_extr_filter f l a` means `is_min_filter f l a` or `is_max_filter f l a` -/\ndef is_extr_filter : Prop := is_min_filter f l a \u2228 is_max_filter f l a\n\n/-- `is_min_on f s a` means that `f a \u2264 f x` for all `x \u2208 a`. Note that we do not assume `a \u2208 s`. -/\ndef is_min_on := is_min_filter f (\ud835\udcdf s) a\n\n/-- `is_max_on f s a` means that `f x \u2264 f a` for all `x \u2208 a`. Note that we do not assume `a \u2208 s`. -/\ndef is_max_on := is_max_filter f (\ud835\udcdf s) a\n\n/-- `is_extr_on f s a` means `is_min_on f s a` or `is_max_on f s a` -/\ndef is_extr_on : Prop := is_extr_filter f (\ud835\udcdf s) a\n\nvariables {f s a l} {t : set \u03b1} {l' : filter \u03b1}\n\nlemma is_extr_on.elim {p : Prop} :\n  is_extr_on f s a \u2192 (is_min_on f s a \u2192 p) \u2192 (is_max_on f s a \u2192 p) \u2192 p :=\nor.elim\n\nlemma is_min_on_iff : is_min_on f s a \u2194 \u2200 x \u2208 s, f a \u2264 f x := iff.rfl\n\nlemma is_max_on_iff : is_max_on f s a \u2194 \u2200 x \u2208 s, f x \u2264 f a := iff.rfl\n\nlemma is_min_on_univ_iff : is_min_on f univ a \u2194 \u2200 x, f a \u2264 f x :=\nuniv_subset_iff.trans eq_univ_iff_forall\n\nlemma is_max_on_univ_iff : is_max_on f univ a \u2194 \u2200 x, f x \u2264 f a :=\nuniv_subset_iff.trans eq_univ_iff_forall\n\nlemma is_min_filter.tendsto_principal_Ici (h : is_min_filter f l a) :\n  tendsto f l (\ud835\udcdf $ Ici (f a)) :=\ntendsto_principal.2 h\n\nlemma is_max_filter.tendsto_principal_Iic (h : is_max_filter f l a) :\n  tendsto f l (\ud835\udcdf $ Iic (f a)) :=\ntendsto_principal.2 h\n\n/-! ### Conversion to `is_extr_*` -/\n\nlemma is_min_filter.is_extr : is_min_filter f l a \u2192 is_extr_filter f l a := or.inl\n\nlemma is_max_filter.is_extr : is_max_filter f l a \u2192 is_extr_filter f l a := or.inr\n\nlemma is_min_on.is_extr (h : is_min_on f s a) : is_extr_on f s a := h.is_extr\n\nlemma is_max_on.is_extr (h : is_max_on f s a) : is_extr_on f s a := h.is_extr\n\n/-! ### Constant function -/\n\nlemma is_min_filter_const {b : \u03b2} : is_min_filter (\u03bb _, b) l a :=\nuniv_mem_sets' $ \u03bb _, le_refl _\n\nlemma is_max_filter_const {b : \u03b2} : is_max_filter (\u03bb _, b) l a :=\nuniv_mem_sets' $ \u03bb _, le_refl _\n\nlemma is_extr_filter_const {b : \u03b2} : is_extr_filter (\u03bb _, b) l a := is_min_filter_const.is_extr\n\nlemma is_min_on_const {b : \u03b2} : is_min_on (\u03bb _, b) s a := is_min_filter_const\n\nlemma is_max_on_const {b : \u03b2} : is_max_on (\u03bb _, b) s a := is_max_filter_const\n\nlemma is_extr_on_const {b : \u03b2} : is_extr_on (\u03bb _, b) s a := is_extr_filter_const\n\n/-! ### Order dual -/\n\nlemma is_min_filter_dual_iff : @is_min_filter \u03b1 (order_dual \u03b2) _ f l a \u2194 is_max_filter f l a :=\niff.rfl\n\nlemma is_max_filter_dual_iff : @is_max_filter \u03b1 (order_dual \u03b2) _ f l a \u2194 is_min_filter f l a :=\niff.rfl\n\nlemma is_extr_filter_dual_iff : @is_extr_filter \u03b1 (order_dual \u03b2) _ f l a \u2194 is_extr_filter f l a :=\nor_comm _ _\n\nalias is_min_filter_dual_iff \u2194 is_min_filter.undual is_max_filter.dual\nalias is_max_filter_dual_iff \u2194 is_max_filter.undual is_min_filter.dual\nalias is_extr_filter_dual_iff \u2194 is_extr_filter.undual is_extr_filter.dual\n\nlemma is_min_on_dual_iff : @is_min_on \u03b1 (order_dual \u03b2) _ f s a \u2194 is_max_on f s a := iff.rfl\nlemma is_max_on_dual_iff : @is_max_on \u03b1 (order_dual \u03b2) _ f s a \u2194 is_min_on f s a := iff.rfl\nlemma is_extr_on_dual_iff : @is_extr_on \u03b1 (order_dual \u03b2) _ f s a \u2194 is_extr_on f s a := or_comm _ _\n\nalias is_min_on_dual_iff \u2194 is_min_on.undual is_max_on.dual\nalias is_max_on_dual_iff \u2194 is_max_on.undual is_min_on.dual\nalias is_extr_on_dual_iff \u2194 is_extr_on.undual is_extr_on.dual\n\n/-! ### Operations on the filter/set -/\n\nlemma is_min_filter.filter_mono (h : is_min_filter f l a) (hl : l' \u2264 l) :\n  is_min_filter f l' a := hl h\n\nlemma is_max_filter.filter_mono (h : is_max_filter f l a) (hl : l' \u2264 l) :\n  is_max_filter f l' a := hl h\n\nlemma is_extr_filter.filter_mono (h : is_extr_filter f l a) (hl : l' \u2264 l) :\n  is_extr_filter f l' a :=\nh.elim (\u03bb h, (h.filter_mono hl).is_extr) (\u03bb h, (h.filter_mono hl).is_extr)\n\nlemma is_min_filter.filter_inf (h : is_min_filter f l a) (l') : is_min_filter f (l \u2293 l') a :=\nh.filter_mono inf_le_left\n\nlemma is_max_filter.filter_inf (h : is_max_filter f l a) (l') : is_max_filter f (l \u2293 l') a :=\nh.filter_mono inf_le_left\n\nlemma is_extr_filter.filter_inf (h : is_extr_filter f l a) (l') : is_extr_filter f (l \u2293 l') a :=\nh.filter_mono inf_le_left\n\nlemma is_min_on.on_subset (hf : is_min_on f t a) (h : s \u2286 t) : is_min_on f s a :=\nhf.filter_mono $ principal_mono.2 h\n\nlemma is_max_on.on_subset (hf : is_max_on f t a) (h : s \u2286 t) : is_max_on f s a :=\nhf.filter_mono $ principal_mono.2 h\n\nlemma is_extr_on.on_subset (hf : is_extr_on f t a) (h : s \u2286 t) : is_extr_on f s a :=\nhf.filter_mono $ principal_mono.2 h\n\nlemma is_min_on.inter (hf : is_min_on f s a) (t) : is_min_on f (s \u2229 t) a :=\nhf.on_subset (inter_subset_left s t)\n\nlemma is_max_on.inter (hf : is_max_on f s a) (t) : is_max_on f (s \u2229 t) a :=\nhf.on_subset (inter_subset_left s t)\n\nlemma is_extr_on.inter (hf : is_extr_on f s a) (t) : is_extr_on f (s \u2229 t) a :=\nhf.on_subset (inter_subset_left s t)\n\n/-! ### Composition with (anti)monotone functions -/\n\nlemma is_min_filter.comp_mono (hf : is_min_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) :\n  is_min_filter (g \u2218 f) l a :=\nmem_sets_of_superset hf $ \u03bb x hx, hg hx\n\nlemma is_max_filter.comp_mono (hf : is_max_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) :\n  is_max_filter (g \u2218 f) l a :=\nmem_sets_of_superset hf $ \u03bb x hx, hg hx\n\nlemma is_extr_filter.comp_mono (hf : is_extr_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) :\n  is_extr_filter (g \u2218 f) l a :=\nhf.elim (\u03bb hf, (hf.comp_mono hg).is_extr)  (\u03bb hf, (hf.comp_mono hg).is_extr)\n\nlemma is_min_filter.comp_antimono (hf : is_min_filter f l a) {g : \u03b2 \u2192 \u03b3}\n  (hg : \u2200 \u2983x y\u2984, x \u2264 y \u2192 g y \u2264 g x) :\n  is_max_filter (g \u2218 f) l a :=\nhf.dual.comp_mono (\u03bb x y h, hg h)\n\nlemma is_max_filter.comp_antimono (hf : is_max_filter f l a) {g : \u03b2 \u2192 \u03b3}\n  (hg : \u2200 \u2983x y\u2984, x \u2264 y \u2192 g y \u2264 g x) :\n  is_min_filter (g \u2218 f) l a :=\nhf.dual.comp_mono (\u03bb x y h, hg h)\n\nlemma is_extr_filter.comp_antimono (hf : is_extr_filter f l a) {g : \u03b2 \u2192 \u03b3}\n  (hg : \u2200 \u2983x y\u2984, x \u2264 y \u2192 g y \u2264 g x) :\n  is_extr_filter (g \u2218 f) l a :=\nhf.dual.comp_mono (\u03bb x y h, hg h)\n\nlemma is_min_on.comp_mono (hf : is_min_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) :\n  is_min_on (g \u2218 f) s a :=\nhf.comp_mono hg\n\nlemma is_max_on.comp_mono (hf : is_max_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) :\n  is_max_on (g \u2218 f) s a :=\nhf.comp_mono hg\n\nlemma is_extr_on.comp_mono (hf : is_extr_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) :\n  is_extr_on (g \u2218 f) s a :=\nhf.comp_mono hg\n\nlemma is_min_on.comp_antimono (hf : is_min_on f s a) {g : \u03b2 \u2192 \u03b3}\n  (hg : \u2200 \u2983x y\u2984, x \u2264 y \u2192 g y \u2264 g x) :\n  is_max_on (g \u2218 f) s a :=\nhf.comp_antimono hg\n\nlemma is_max_on.comp_antimono (hf : is_max_on f s a) {g : \u03b2 \u2192 \u03b3}\n  (hg : \u2200 \u2983x y\u2984, x \u2264 y \u2192 g y \u2264 g x) :\n  is_min_on (g \u2218 f) s a :=\nhf.comp_antimono hg\n\nlemma is_extr_on.comp_antimono (hf : is_extr_on f s a) {g : \u03b2 \u2192 \u03b3}\n  (hg : \u2200 \u2983x y\u2984, x \u2264 y \u2192 g y \u2264 g x) :\n  is_extr_on (g \u2218 f) s a :=\nhf.comp_antimono hg\n\nlemma is_min_filter.bicomp_mono [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : ((\u2264) \u21d2 (\u2264) \u21d2 (\u2264)) op op)\n  (hf : is_min_filter f l a) {g : \u03b1 \u2192 \u03b3} (hg : is_min_filter g l a) :\n  is_min_filter (\u03bb x, op (f x) (g x)) l a :=\nmem_sets_of_superset (inter_mem_sets hf hg) $ \u03bb x \u27e8hfx, hgx\u27e9, hop hfx hgx\n\nlemma is_max_filter.bicomp_mono [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : ((\u2264) \u21d2 (\u2264) \u21d2 (\u2264)) op op)\n  (hf : is_max_filter f l a) {g : \u03b1 \u2192 \u03b3} (hg : is_max_filter g l a) :\n  is_max_filter (\u03bb x, op (f x) (g x)) l a :=\nmem_sets_of_superset (inter_mem_sets hf hg) $ \u03bb x \u27e8hfx, hgx\u27e9, hop hfx hgx\n\n-- No `extr` version because we need `hf` and `hg` to be of the same kind\n\nlemma is_min_on.bicomp_mono [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : ((\u2264) \u21d2 (\u2264) \u21d2 (\u2264)) op op)\n  (hf : is_min_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_min_on g s a) :\n  is_min_on (\u03bb x, op (f x) (g x)) s a :=\nhf.bicomp_mono hop hg\n\nlemma is_max_on.bicomp_mono [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : ((\u2264) \u21d2 (\u2264) \u21d2 (\u2264)) op op)\n  (hf : is_max_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_max_on g s a) :\n  is_max_on (\u03bb x, op (f x) (g x)) s a :=\nhf.bicomp_mono hop hg\n\n/-! ### Composition with `tendsto` -/\n\nlemma is_min_filter.comp_tendsto {g : \u03b4 \u2192 \u03b1} {l' : filter \u03b4} {b : \u03b4} (hf : is_min_filter f l (g b))\n  (hg : tendsto g l' l) :\n  is_min_filter (f \u2218 g) l' b :=\nhg hf\n\nlemma is_max_filter.comp_tendsto {g : \u03b4 \u2192 \u03b1} {l' : filter \u03b4} {b : \u03b4} (hf : is_max_filter f l (g b))\n  (hg : tendsto g l' l) :\n  is_max_filter (f \u2218 g) l' b :=\nhg hf\n\nlemma is_extr_filter.comp_tendsto {g : \u03b4 \u2192 \u03b1} {l' : filter \u03b4} {b : \u03b4}\n  (hf : is_extr_filter f l (g b)) (hg : tendsto g l' l) :\n  is_extr_filter (f \u2218 g) l' b :=\nhf.elim (\u03bb hf, (hf.comp_tendsto hg).is_extr) (\u03bb hf, (hf.comp_tendsto hg).is_extr)\n\nlemma is_min_on.on_preimage (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_min_on f s (g b)) :\n  is_min_on (f \u2218 g) (g \u207b\u00b9' s) b :=\nhf.comp_tendsto (tendsto_principal_principal.mpr $ subset.refl _)\n\nlemma is_max_on.on_preimage (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_max_on f s (g b)) :\n  is_max_on (f \u2218 g) (g \u207b\u00b9' s) b :=\nhf.comp_tendsto (tendsto_principal_principal.mpr $ subset.refl _)\n\nlemma is_extr_on.on_preimage (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_extr_on f s (g b)) :\n  is_extr_on (f \u2218 g) (g \u207b\u00b9' s) b :=\nhf.elim (\u03bb hf, (hf.on_preimage g).is_extr) (\u03bb hf, (hf.on_preimage g).is_extr)\n\nend preorder\n\n/-! ### Pointwise addition -/\nsection ordered_add_comm_monoid\n\nvariables [ordered_add_comm_monoid \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} {l : filter \u03b1}\n\nlemma is_min_filter.add (hf : is_min_filter f l a) (hg : is_min_filter g l a) :\n  is_min_filter (\u03bb x, f x + g x) l a :=\nshow is_min_filter (\u03bb x, f x + g x) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, add_le_add hx hy) hg\n\nlemma is_max_filter.add (hf : is_max_filter f l a) (hg : is_max_filter g l a) :\n  is_max_filter (\u03bb x, f x + g x) l a :=\nshow is_max_filter (\u03bb x, f x + g x) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, add_le_add hx hy) hg\n\nlemma is_min_on.add (hf : is_min_on f s a) (hg : is_min_on g s a) :\n  is_min_on (\u03bb x, f x + g x) s a :=\nhf.add hg\n\nlemma is_max_on.add (hf : is_max_on f s a) (hg : is_max_on g s a) :\n  is_max_on (\u03bb x, f x + g x) s a :=\nhf.add hg\n\nend ordered_add_comm_monoid\n\n/-! ### Pointwise negation and subtraction -/\n\nsection ordered_add_comm_group\n\nvariables [ordered_add_comm_group \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} {l : filter \u03b1}\n\nlemma is_min_filter.neg (hf : is_min_filter f l a) : is_max_filter (\u03bb x, -f x) l a :=\nhf.comp_antimono (\u03bb x y hx, neg_le_neg hx)\n\nlemma is_max_filter.neg (hf : is_max_filter f l a) : is_min_filter (\u03bb x, -f x) l a :=\nhf.comp_antimono (\u03bb x y hx, neg_le_neg hx)\n\nlemma is_extr_filter.neg (hf : is_extr_filter f l a) : is_extr_filter (\u03bb x, -f x) l a :=\nhf.elim (\u03bb hf, hf.neg.is_extr) (\u03bb hf, hf.neg.is_extr)\n\nlemma is_min_on.neg (hf : is_min_on f s a) : is_max_on (\u03bb x, -f x) s a :=\nhf.comp_antimono (\u03bb x y hx, neg_le_neg hx)\n\nlemma is_max_on.neg (hf : is_max_on f s a) : is_min_on (\u03bb x, -f x) s a :=\nhf.comp_antimono (\u03bb x y hx, neg_le_neg hx)\n\nlemma is_extr_on.neg (hf : is_extr_on f s a) : is_extr_on (\u03bb x, -f x) s a :=\nhf.elim (\u03bb hf, hf.neg.is_extr) (\u03bb hf, hf.neg.is_extr)\n\nlemma is_min_filter.sub (hf : is_min_filter f l a) (hg : is_max_filter g l a) :\n  is_min_filter (\u03bb x, f x - g x) l a :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\nlemma is_max_filter.sub (hf : is_max_filter f l a) (hg : is_min_filter g l a) :\n  is_max_filter (\u03bb x, f x - g x) l a :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\nlemma is_min_on.sub (hf : is_min_on f s a) (hg : is_max_on g s a) :\n  is_min_on (\u03bb x, f x - g x) s a :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\nlemma is_max_on.sub (hf : is_max_on f s a) (hg : is_min_on g s a) :\n  is_max_on (\u03bb x, f x - g x) s a :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\nend ordered_add_comm_group\n\n/-! ### Pointwise `sup`/`inf` -/\n\nsection semilattice_sup\n\nvariables [semilattice_sup \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} {l : filter \u03b1}\n\nlemma is_min_filter.sup (hf : is_min_filter f l a) (hg : is_min_filter g l a) :\n  is_min_filter (\u03bb x, f x \u2294 g x) l a :=\nshow is_min_filter (\u03bb x, f x \u2294 g x) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, sup_le_sup hx hy) hg\n\nlemma is_max_filter.sup (hf : is_max_filter f l a) (hg : is_max_filter g l a) :\n  is_max_filter (\u03bb x, f x \u2294 g x) l a :=\nshow is_max_filter (\u03bb x, f x \u2294 g x) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, sup_le_sup hx hy) hg\n\nlemma is_min_on.sup (hf : is_min_on f s a) (hg : is_min_on g s a) :\n  is_min_on (\u03bb x, f x \u2294 g x) s a :=\nhf.sup hg\n\nlemma is_max_on.sup (hf : is_max_on f s a) (hg : is_max_on g s a) :\n  is_max_on (\u03bb x, f x \u2294 g x) s a :=\nhf.sup hg\n\nend semilattice_sup\n\nsection semilattice_inf\n\nvariables [semilattice_inf \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} {l : filter \u03b1}\n\nlemma is_min_filter.inf (hf : is_min_filter f l a) (hg : is_min_filter g l a) :\n  is_min_filter (\u03bb x, f x \u2293 g x) l a :=\nshow is_min_filter (\u03bb x, f x \u2293 g x) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, inf_le_inf hx hy) hg\n\nlemma is_max_filter.inf (hf : is_max_filter f l a) (hg : is_max_filter g l a) :\n  is_max_filter (\u03bb x, f x \u2293 g x) l a :=\nshow is_max_filter (\u03bb x, f x \u2293 g x) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, inf_le_inf hx hy) hg\n\nlemma is_min_on.inf (hf : is_min_on f s a) (hg : is_min_on g s a) :\n  is_min_on (\u03bb x, f x \u2293 g x) s a :=\nhf.inf hg\n\nlemma is_max_on.inf (hf : is_max_on f s a) (hg : is_max_on g s a) :\n  is_max_on (\u03bb x, f x \u2293 g x) s a :=\nhf.inf hg\n\nend semilattice_inf\n\n/-! ### Pointwise `min`/`max` -/\n\nsection linear_order\n\nvariables [linear_order \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} {l : filter \u03b1}\n\nlemma is_min_filter.min (hf : is_min_filter f l a) (hg : is_min_filter g l a) :\n  is_min_filter (\u03bb x, min (f x) (g x)) l a :=\nshow is_min_filter (\u03bb x, min (f x) (g x)) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, min_le_min hx hy) hg\n\nlemma is_max_filter.min (hf : is_max_filter f l a) (hg : is_max_filter g l a) :\n  is_max_filter (\u03bb x, min (f x) (g x)) l a :=\nshow is_max_filter (\u03bb x, min (f x) (g x)) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, min_le_min hx hy) hg\n\nlemma is_min_on.min (hf : is_min_on f s a) (hg : is_min_on g s a) :\n  is_min_on (\u03bb x, min (f x) (g x)) s a :=\nhf.min hg\n\nlemma is_max_on.min (hf : is_max_on f s a) (hg : is_max_on g s a) :\n  is_max_on (\u03bb x, min (f x) (g x)) s a :=\nhf.min hg\n\nlemma is_min_filter.max (hf : is_min_filter f l a) (hg : is_min_filter g l a) :\n  is_min_filter (\u03bb x, max (f x) (g x)) l a :=\nshow is_min_filter (\u03bb x, max (f x) (g x)) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, max_le_max hx hy) hg\n\nlemma is_max_filter.max (hf : is_max_filter f l a) (hg : is_max_filter g l a) :\n  is_max_filter (\u03bb x, max (f x) (g x)) l a :=\nshow is_max_filter (\u03bb x, max (f x) (g x)) l a,\nfrom hf.bicomp_mono (\u03bb x x' hx y y' hy, max_le_max hx hy) hg\n\nlemma is_min_on.max (hf : is_min_on f s a) (hg : is_min_on g s a) :\n  is_min_on (\u03bb x, max (f x) (g x)) s a :=\nhf.max hg\n\nlemma is_max_on.max (hf : is_max_on f s a) (hg : is_max_on g s a) :\n  is_max_on (\u03bb x, max (f x) (g x)) s a :=\nhf.max hg\n\nend linear_order\n\nsection eventually\n\n/-! ### Relation with `eventually` comparisons of two functions -/\n\nlemma filter.eventually_le.is_max_filter {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n  {l : filter \u03b1} (hle : g \u2264\u1da0[l] f) (hfga : f a = g a) (h : is_max_filter f l a) :\n  is_max_filter g l a :=\nbegin\n  refine hle.mp (h.mono $ \u03bb x hf hgf, _),\n  rw \u2190 hfga,\n  exact le_trans hgf hf\nend\n\nlemma is_max_filter.congr {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1}\n  (h : is_max_filter f l a) (heq : f =\u1da0[l] g) (hfga : f a = g a) :\n  is_max_filter g l a :=\nheq.symm.le.is_max_filter hfga h\n\nlemma filter.eventually_eq.is_max_filter_iff {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n  {l : filter \u03b1} (heq : f =\u1da0[l] g) (hfga : f a = g a) :\n  is_max_filter f l a \u2194 is_max_filter g l a :=\n\u27e8\u03bb h, h.congr heq hfga, \u03bb h, h.congr heq.symm hfga.symm\u27e9\n\nlemma filter.eventually_le.is_min_filter {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n  {l : filter \u03b1} (hle : f \u2264\u1da0[l] g) (hfga : f a = g a) (h : is_min_filter f l a) :\n  is_min_filter g l a :=\n@filter.eventually_le.is_max_filter _ (order_dual \u03b2) _ _ _ _ _ hle hfga h\n\nlemma is_min_filter.congr {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1}\n  (h : is_min_filter f l a) (heq : f =\u1da0[l] g) (hfga : f a = g a) :\n  is_min_filter g l a :=\nheq.le.is_min_filter hfga h\n\nlemma filter.eventually_eq.is_min_filter_iff {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n  {l : filter \u03b1} (heq : f =\u1da0[l] g) (hfga : f a = g a) :\n  is_min_filter f l a \u2194 is_min_filter g l a :=\n\u27e8\u03bb h, h.congr heq hfga, \u03bb h, h.congr heq.symm hfga.symm\u27e9\n\nlemma is_extr_filter.congr {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1}\n  (h : is_extr_filter f l a) (heq : f =\u1da0[l] g) (hfga : f a = g a) :\n  is_extr_filter g l a :=\nbegin\n  rw is_extr_filter at *,\n  rwa [\u2190 heq.is_max_filter_iff hfga, \u2190 heq.is_min_filter_iff hfga],\nend\n\nlemma filter.eventually_eq.is_extr_filter_iff {\u03b1 \u03b2 : Type*} [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} {a : \u03b1}\n  {l : filter \u03b1} (heq : f =\u1da0[l] g) (hfga : f a = g a) :\n  is_extr_filter f l a \u2194 is_extr_filter g l a :=\n\u27e8\u03bb h, h.congr heq hfga, \u03bb h, h.congr heq.symm hfga.symm\u27e9\n\nend eventually\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/filter/extr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7090602246456086}}
{"text": "/-\nCopyright (c) 2020 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module topology.sets.closeds\n! leanprover-community/mathlib commit 34ee86e6a59d911a8e4f89b68793ee7577ae79c7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.Sets.Opens\n\n/-!\n# Closed sets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe define a few types of closed sets in a topological space.\n\n## Main Definitions\n\nFor a topological space `\u03b1`,\n* `closeds \u03b1`: The type of closed sets.\n* `clopens \u03b1`: The type of clopen sets.\n-/\n\n\nopen Order OrderDual Set\n\nvariable {\u03b9 \u03b1 \u03b2 : Type _} [TopologicalSpace \u03b1] [TopologicalSpace \u03b2]\n\nnamespace TopologicalSpace\n\n/-! ### Closed sets -/\n\n\n#print TopologicalSpace.Closeds /-\n/-- The type of closed subsets of a topological space. -/\nstructure Closeds (\u03b1 : Type _) [TopologicalSpace \u03b1] where\n  carrier : Set \u03b1\n  closed' : IsClosed carrier\n#align topological_space.closeds TopologicalSpace.Closeds\n-/\n\nnamespace Closeds\n\nvariable {\u03b1}\n\ninstance : SetLike (Closeds \u03b1) \u03b1 where\n  coe := Closeds.carrier\n  coe_injective' s t h := by\n    cases s\n    cases t\n    congr\n\n#print TopologicalSpace.Closeds.closed /-\ntheorem closed (s : Closeds \u03b1) : IsClosed (s : Set \u03b1) :=\n  s.closed'\n#align topological_space.closeds.closed TopologicalSpace.Closeds.closed\n-/\n\n#print TopologicalSpace.Closeds.ext /-\n@[ext]\nprotected theorem ext {s t : Closeds \u03b1} (h : (s : Set \u03b1) = t) : s = t :=\n  SetLike.ext' h\n#align topological_space.closeds.ext TopologicalSpace.Closeds.ext\n-/\n\n#print TopologicalSpace.Closeds.coe_mk /-\n@[simp]\ntheorem coe_mk (s : Set \u03b1) (h) : (mk s h : Set \u03b1) = s :=\n  rfl\n#align topological_space.closeds.coe_mk TopologicalSpace.Closeds.coe_mk\n-/\n\n#print TopologicalSpace.Closeds.closure /-\n/-- The closure of a set, as an element of `closeds`. -/\nprotected def closure (s : Set \u03b1) : Closeds \u03b1 :=\n  \u27e8closure s, isClosed_closure\u27e9\n#align topological_space.closeds.closure TopologicalSpace.Closeds.closure\n-/\n\n/- warning: topological_space.closeds.gc -> TopologicalSpace.Closeds.gc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], GaloisConnection.{u1, u1} (Set.{u1} \u03b1) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1))))))) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1))) (TopologicalSpace.Closeds.closure.{u1} \u03b1 _inst_1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], GaloisConnection.{u1, u1} (Set.{u1} \u03b1) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1))))))) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.instPartialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1))) (TopologicalSpace.Closeds.closure.{u1} \u03b1 _inst_1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.gc TopologicalSpace.Closeds.gc\u2093'. -/\ntheorem gc : GaloisConnection Closeds.closure (coe : Closeds \u03b1 \u2192 Set \u03b1) := fun s U =>\n  \u27e8subset_closure.trans, fun h => closure_minimal h U.closed\u27e9\n#align topological_space.closeds.gc TopologicalSpace.Closeds.gc\n\n/- warning: topological_space.closeds.gi -> TopologicalSpace.Closeds.gi is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], GaloisInsertion.{u1, u1} (Set.{u1} \u03b1) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.completeBooleanAlgebra.{u1} \u03b1))))))) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1))) (TopologicalSpace.Closeds.closure.{u1} \u03b1 _inst_1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], GaloisInsertion.{u1, u1} (Set.{u1} \u03b1) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (Set.{u1} \u03b1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Set.{u1} \u03b1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1))))))) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.instPartialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1))) (TopologicalSpace.Closeds.closure.{u1} \u03b1 _inst_1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.gi TopologicalSpace.Closeds.gi\u2093'. -/\n/-- The galois coinsertion between sets and opens. -/\ndef gi : GaloisInsertion (@Closeds.closure \u03b1 _) coe\n    where\n  choice s hs := \u27e8s, closure_eq_iff_isClosed.1 <| hs.antisymm subset_closure\u27e9\n  gc := gc\n  le_l_u _ := subset_closure\n  choice_eq s hs := SetLike.coe_injective <| subset_closure.antisymm hs\n#align topological_space.closeds.gi TopologicalSpace.Closeds.gi\n\ninstance : CompleteLattice (Closeds \u03b1) :=\n  CompleteLattice.copy\n    (GaloisInsertion.liftCompleteLattice gi)-- le\n    _\n    rfl-- top\n    \u27e8univ, isClosed_univ\u27e9\n    rfl-- bot\n    \u27e8\u2205, isClosed_empty\u27e9\n    (SetLike.coe_injective closure_empty.symm)\n    (-- sup\n    fun s t => \u27e8s \u222a t, s.2.union t.2\u27e9)\n    (funext fun s => funext fun t => SetLike.coe_injective (s.2.union t.2).closure_eq.symm)\n    (-- inf\n    fun s t => \u27e8s \u2229 t, s.2.inter t.2\u27e9)\n    rfl-- Sup\n    _\n    rfl\n    (-- Inf\n    fun S => \u27e8\u22c2 s \u2208 S, \u2191s, isClosed_binter\u1d62 fun s _ => s.2\u27e9)\n    (funext fun S => SetLike.coe_injective inf\u209b_image.symm)\n\n/-- The type of closed sets is inhabited, with default element the empty set. -/\ninstance : Inhabited (Closeds \u03b1) :=\n  \u27e8\u22a5\u27e9\n\n/- warning: topological_space.closeds.coe_sup -> TopologicalSpace.Closeds.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SemilatticeSup.toHasSup.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Lattice.toSemilatticeSup.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))))) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (Sup.sup.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SemilatticeSup.toSup.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Lattice.toSemilatticeSup.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))))) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_sup TopologicalSpace.Closeds.coe_sup\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_sup (s t : Closeds \u03b1) : (\u2191(s \u2294 t) : Set \u03b1) = s \u222a t :=\n  rfl\n#align topological_space.closeds.coe_sup TopologicalSpace.Closeds.coe_sup\n\n/- warning: topological_space.closeds.coe_inf -> TopologicalSpace.Closeds.coe_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (Inf.inf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SemilatticeInf.toHasInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Lattice.toSemilatticeInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))))) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (Inf.inf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Lattice.toInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1)))) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_inf TopologicalSpace.Closeds.coe_inf\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_inf (s t : Closeds \u03b1) : (\u2191(s \u2293 t) : Set \u03b1) = s \u2229 t :=\n  rfl\n#align topological_space.closeds.coe_inf TopologicalSpace.Closeds.coe_inf\n\n/- warning: topological_space.closeds.coe_top -> TopologicalSpace.Closeds.coe_top is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (Top.top.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toHasTop.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1)))) (Set.univ.{u1} \u03b1)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (Top.top.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toTop.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1)))) (Set.univ.{u1} \u03b1)\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_top TopologicalSpace.Closeds.coe_top\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_top : (\u2191(\u22a4 : Closeds \u03b1) : Set \u03b1) = univ :=\n  rfl\n#align topological_space.closeds.coe_top TopologicalSpace.Closeds.coe_top\n\n/- warning: topological_space.closeds.coe_bot -> TopologicalSpace.Closeds.coe_bot is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (Bot.bot.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toHasBot.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1)))) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (Bot.bot.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toBot.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1)))) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_bot TopologicalSpace.Closeds.coe_bot\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_bot : (\u2191(\u22a5 : Closeds \u03b1) : Set \u03b1) = \u2205 :=\n  rfl\n#align topological_space.closeds.coe_bot TopologicalSpace.Closeds.coe_bot\n\n/- warning: topological_space.closeds.coe_Inf -> TopologicalSpace.Closeds.coe_inf\u209b is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {S : Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)}, Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (InfSet.inf\u209b.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toHasInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))) S)) (Set.inter\u1d62.{u1, succ u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (fun (i : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) => Set.inter\u1d62.{u1, 0} \u03b1 (Membership.Mem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Set.hasMem.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) i S) (fun (H : Membership.Mem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Set.hasMem.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) i S) => (fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {S : Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)}, Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (InfSet.inf\u209b.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toInfSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))) S)) (Set.inter\u1d62.{u1, succ u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (fun (i : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) => Set.inter\u1d62.{u1, 0} \u03b1 (Membership.mem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Set.instMembershipSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) i S) (fun (H : Membership.mem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Set.instMembershipSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) i S) => SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) i)))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_Inf TopologicalSpace.Closeds.coe_inf\u209b\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_inf\u209b {S : Set (Closeds \u03b1)} : (\u2191(inf\u209b S) : Set \u03b1) = \u22c2 i \u2208 S, \u2191i :=\n  rfl\n#align topological_space.closeds.coe_Inf TopologicalSpace.Closeds.coe_inf\u209b\n\n/- warning: topological_space.closeds.coe_finset_sup -> TopologicalSpace.Closeds.coe_finset_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u2} \u03b1] (f : \u03b9 -> (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1)) (s : Finset.{u1} \u03b9), Eq.{succ u2} (Set.{u2} \u03b1) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u2} \u03b1 _inst_1)))) (Finset.sup.{u2, u1} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b9 (Lattice.toSemilatticeSup.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u2} \u03b1 _inst_1)))) (BoundedOrder.toOrderBot.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Preorder.toLE.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (PartialOrder.toPreorder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (SemilatticeSup.toPartialOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Lattice.toSemilatticeSup.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u2} \u03b1 _inst_1))))))) (CompleteLattice.toBoundedOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u2} \u03b1 _inst_1))) s f)) (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.completeBooleanAlgebra.{u2} \u03b1))))))) (GeneralizedBooleanAlgebra.toOrderBot.{u2} (Set.{u2} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} \u03b1) (Set.booleanAlgebra.{u2} \u03b1))) s (Function.comp.{succ u1, succ u2, succ u2} \u03b9 (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u2} \u03b1 _inst_1))))) f))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u2} \u03b1] (f : \u03b9 -> (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1)) (s : Finset.{u1} \u03b9), Eq.{succ u2} (Set.{u2} \u03b1) (SetLike.coe.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u2} \u03b1 _inst_1) (Finset.sup.{u2, u1} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b9 (Lattice.toSemilatticeSup.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u2} \u03b1 _inst_1)))) (BoundedOrder.toOrderBot.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Preorder.toLE.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (PartialOrder.toPreorder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (SemilatticeSup.toPartialOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Lattice.toSemilatticeSup.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u2} \u03b1 _inst_1))))))) (CompleteLattice.toBoundedOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u2} \u03b1 _inst_1))) s f)) (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1))))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (SemilatticeSup.toPartialOrder.{u2} (Set.{u2} \u03b1) (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) s (Function.comp.{succ u1, succ u2, succ u2} \u03b9 (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (SetLike.coe.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u2} \u03b1 _inst_1)) f))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_finset_sup TopologicalSpace.Closeds.coe_finset_sup\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_finset_sup (f : \u03b9 \u2192 Closeds \u03b1) (s : Finset \u03b9) :\n    (\u2191(s.sup f) : Set \u03b1) = s.sup (coe \u2218 f) :=\n  map_finset_sup (\u27e8\u27e8coe, coe_sup\u27e9, coe_bot\u27e9 : SupBotHom (Closeds \u03b1) (Set \u03b1)) _ _\n#align topological_space.closeds.coe_finset_sup TopologicalSpace.Closeds.coe_finset_sup\n\n/- warning: topological_space.closeds.coe_finset_inf -> TopologicalSpace.Closeds.coe_finset_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u2} \u03b1] (f : \u03b9 -> (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1)) (s : Finset.{u1} \u03b9), Eq.{succ u2} (Set.{u2} \u03b1) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u2} \u03b1 _inst_1)))) (Finset.inf.{u2, u1} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b9 (Lattice.toSemilatticeInf.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u2} \u03b1 _inst_1)))) (BoundedOrder.toOrderTop.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Preorder.toLE.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (PartialOrder.toPreorder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (SemilatticeInf.toPartialOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Lattice.toSemilatticeInf.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u2} \u03b1 _inst_1))))))) (CompleteLattice.toBoundedOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u2} \u03b1 _inst_1))) s f)) (Finset.inf.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeInf.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.completeBooleanAlgebra.{u2} \u03b1))))))) (Set.orderTop.{u2} \u03b1) s (Function.comp.{succ u1, succ u2, succ u2} \u03b9 (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (HasLiftT.mk.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (CoeTC\u2093.coe.{succ u2, succ u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (SetLike.Set.hasCoeT.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u2} \u03b1 _inst_1))))) f))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : TopologicalSpace.{u2} \u03b1] (f : \u03b9 -> (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1)) (s : Finset.{u1} \u03b9), Eq.{succ u2} (Set.{u2} \u03b1) (SetLike.coe.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u2} \u03b1 _inst_1) (Finset.inf.{u2, u1} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b9 (Lattice.toSemilatticeInf.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u2} \u03b1 _inst_1)))) (BoundedOrder.toOrderTop.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Preorder.toLE.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (PartialOrder.toPreorder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (SemilatticeInf.toPartialOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Lattice.toSemilatticeInf.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (ConditionallyCompleteLattice.toLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u2} \u03b1 _inst_1))))))) (CompleteLattice.toBoundedOrder.{u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u2} \u03b1 _inst_1))) s f)) (Finset.inf.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeInf.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1))))))) (Set.instOrderTopSetInstLESet.{u2} \u03b1) s (Function.comp.{succ u1, succ u2, succ u2} \u03b9 (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) (Set.{u2} \u03b1) (SetLike.coe.{u2, u2} (TopologicalSpace.Closeds.{u2} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u2} \u03b1 _inst_1)) f))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_finset_inf TopologicalSpace.Closeds.coe_finset_inf\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_finset_inf (f : \u03b9 \u2192 Closeds \u03b1) (s : Finset \u03b9) :\n    (\u2191(s.inf f) : Set \u03b1) = s.inf (coe \u2218 f) :=\n  map_finset_inf (\u27e8\u27e8coe, coe_inf\u27e9, coe_top\u27e9 : InfTopHom (Closeds \u03b1) (Set \u03b1)) _ _\n#align topological_space.closeds.coe_finset_inf TopologicalSpace.Closeds.coe_finset_inf\n\n/- warning: topological_space.closeds.infi_def -> TopologicalSpace.Closeds.inf\u1d62_def is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} (s : \u03b9 -> (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)), Eq.{succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toHasInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))) \u03b9 (fun (i : \u03b9) => s i)) (TopologicalSpace.Closeds.mk.{u1} \u03b1 _inst_1 (Set.inter\u1d62.{u1, u2} \u03b1 \u03b9 (fun (i : \u03b9) => (fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (s i))) (isClosed_inter\u1d62.{u1, u2} \u03b1 \u03b9 _inst_1 (fun (i : \u03b9) => (fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (s i)) (fun (i : \u03b9) => TopologicalSpace.Closeds.closed'.{u1} \u03b1 _inst_1 (s i))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} (s : \u03b9 -> (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)), Eq.{succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toInfSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))) \u03b9 (fun (i : \u03b9) => s i)) (TopologicalSpace.Closeds.mk.{u1} \u03b1 _inst_1 (Set.inter\u1d62.{u1, u2} \u03b1 \u03b9 (fun (i : \u03b9) => SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (s i))) (isClosed_inter\u1d62.{u1, u2} \u03b1 \u03b9 _inst_1 (fun (i : \u03b9) => SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (s i)) (fun (i : \u03b9) => TopologicalSpace.Closeds.closed'.{u1} \u03b1 _inst_1 (s i))))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.infi_def TopologicalSpace.Closeds.inf\u1d62_def\u2093'. -/\ntheorem inf\u1d62_def {\u03b9} (s : \u03b9 \u2192 Closeds \u03b1) :\n    (\u2a05 i, s i) = \u27e8\u22c2 i, s i, isClosed_inter\u1d62 fun i => (s i).2\u27e9 :=\n  by\n  ext\n  simp only [inf\u1d62, coe_Inf, bInter_range]\n  rfl\n#align topological_space.closeds.infi_def TopologicalSpace.Closeds.inf\u1d62_def\n\n/- warning: topological_space.closeds.infi_mk -> TopologicalSpace.Closeds.inf\u1d62_mk is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} (s : \u03b9 -> (Set.{u1} \u03b1)) (h : forall (i : \u03b9), IsClosed.{u1} \u03b1 _inst_1 (s i)), Eq.{succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toHasInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))) \u03b9 (fun (i : \u03b9) => TopologicalSpace.Closeds.mk.{u1} \u03b1 _inst_1 (s i) (h i))) (TopologicalSpace.Closeds.mk.{u1} \u03b1 _inst_1 (Set.inter\u1d62.{u1, u2} \u03b1 \u03b9 (fun (i : \u03b9) => s i)) (isClosed_inter\u1d62.{u1, u2} \u03b1 \u03b9 _inst_1 (fun (i : \u03b9) => s i) h))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} (s : \u03b9 -> (Set.{u1} \u03b1)) (h : forall (i : \u03b9), IsClosed.{u1} \u03b1 _inst_1 (s i)), Eq.{succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toInfSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))) \u03b9 (fun (i : \u03b9) => TopologicalSpace.Closeds.mk.{u1} \u03b1 _inst_1 (s i) (h i))) (TopologicalSpace.Closeds.mk.{u1} \u03b1 _inst_1 (Set.inter\u1d62.{u1, u2} \u03b1 \u03b9 (fun (i : \u03b9) => s i)) (isClosed_inter\u1d62.{u1, u2} \u03b1 \u03b9 _inst_1 (fun (i : \u03b9) => s i) h))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.infi_mk TopologicalSpace.Closeds.inf\u1d62_mk\u2093'. -/\n@[simp]\ntheorem inf\u1d62_mk {\u03b9} (s : \u03b9 \u2192 Set \u03b1) (h : \u2200 i, IsClosed (s i)) :\n    (\u2a05 i, \u27e8s i, h i\u27e9 : Closeds \u03b1) = \u27e8\u22c2 i, s i, isClosed_inter\u1d62 h\u27e9 := by simp [infi_def]\n#align topological_space.closeds.infi_mk TopologicalSpace.Closeds.inf\u1d62_mk\n\n/- warning: topological_space.closeds.coe_infi -> TopologicalSpace.Closeds.coe_inf\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} (s : \u03b9 -> (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toHasInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))) \u03b9 (fun (i : \u03b9) => s i))) (Set.inter\u1d62.{u1, u2} \u03b1 \u03b9 (fun (i : \u03b9) => (fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (s i)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} (s : \u03b9 -> (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toInfSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))) \u03b9 (fun (i : \u03b9) => s i))) (Set.inter\u1d62.{u1, u2} \u03b1 \u03b9 (fun (i : \u03b9) => SetLike.coe.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1) (s i)))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.coe_infi TopologicalSpace.Closeds.coe_inf\u1d62\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_inf\u1d62 {\u03b9} (s : \u03b9 \u2192 Closeds \u03b1) : ((\u2a05 i, s i : Closeds \u03b1) : Set \u03b1) = \u22c2 i, s i := by\n  simp [infi_def]\n#align topological_space.closeds.coe_infi TopologicalSpace.Closeds.coe_inf\u1d62\n\n/- warning: topological_space.closeds.mem_infi -> TopologicalSpace.Closeds.mem_inf\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} {x : \u03b1} {s : \u03b9 -> (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)}, Iff (Membership.Mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.hasMem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)) x (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toHasInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))) \u03b9 s)) (forall (i : \u03b9), Membership.Mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.hasMem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)) x (s i))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {\u03b9 : Sort.{u2}} {x : \u03b1} {s : \u03b9 -> (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)}, Iff (Membership.mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.instMembership.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1)) x (inf\u1d62.{u1, u2} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toInfSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))) \u03b9 s)) (forall (i : \u03b9), Membership.mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.instMembership.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1)) x (s i))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.mem_infi TopologicalSpace.Closeds.mem_inf\u1d62\u2093'. -/\n@[simp]\ntheorem mem_inf\u1d62 {\u03b9} {x : \u03b1} {s : \u03b9 \u2192 Closeds \u03b1} : x \u2208 inf\u1d62 s \u2194 \u2200 i, x \u2208 s i := by\n  simp [\u2190 SetLike.mem_coe]\n#align topological_space.closeds.mem_infi TopologicalSpace.Closeds.mem_inf\u1d62\n\n/- warning: topological_space.closeds.mem_Inf -> TopologicalSpace.Closeds.mem_inf\u209b is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {S : Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)} {x : \u03b1}, Iff (Membership.Mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.hasMem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)) x (InfSet.inf\u209b.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toHasInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))) S)) (forall (s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1), (Membership.Mem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Set.hasMem.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) s S) -> (Membership.Mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.hasMem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)) x s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] {S : Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)} {x : \u03b1}, Iff (Membership.mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.instMembership.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1)) x (InfSet.inf\u209b.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (ConditionallyCompleteLattice.toInfSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))) S)) (forall (s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1), (Membership.mem.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Set.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Set.instMembershipSet.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) s S) -> (Membership.mem.{u1, u1} \u03b1 (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.instMembership.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.instSetLikeCloseds.{u1} \u03b1 _inst_1)) x s))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.mem_Inf TopologicalSpace.Closeds.mem_inf\u209b\u2093'. -/\n@[simp]\ntheorem mem_inf\u209b {S : Set (Closeds \u03b1)} {x : \u03b1} : x \u2208 inf\u209b S \u2194 \u2200 s \u2208 S, x \u2208 s := by\n  simp_rw [inf\u209b_eq_inf\u1d62, mem_infi]\n#align topological_space.closeds.mem_Inf TopologicalSpace.Closeds.mem_inf\u209b\n\ninstance : Coframe (Closeds \u03b1) :=\n  { Closeds.completeLattice with\n    inf\u209b := inf\u209b\n    inf\u1d62_sup_le_sup_inf := fun a s =>\n      (SetLike.coe_injective <| by simp only [coe_sup, coe_infi, coe_Inf, Set.union_inter\u1d62\u2082]).le }\n\n#print TopologicalSpace.Closeds.singleton /-\n/-- The term of `closeds \u03b1` corresponding to a singleton. -/\n@[simps]\ndef singleton [T1Space \u03b1] (x : \u03b1) : Closeds \u03b1 :=\n  \u27e8{x}, isClosed_singleton\u27e9\n#align topological_space.closeds.singleton TopologicalSpace.Closeds.singleton\n-/\n\nend Closeds\n\n#print TopologicalSpace.Closeds.compl /-\n/-- The complement of a closed set as an open set. -/\n@[simps]\ndef Closeds.compl (s : Closeds \u03b1) : Opens \u03b1 :=\n  \u27e8s\u1d9c, s.2.isOpen_compl\u27e9\n#align topological_space.closeds.compl TopologicalSpace.Closeds.compl\n-/\n\n#print TopologicalSpace.Opens.compl /-\n/-- The complement of an open set as a closed set. -/\n@[simps]\ndef Opens.compl (s : Opens \u03b1) : Closeds \u03b1 :=\n  \u27e8s\u1d9c, s.2.isClosed_compl\u27e9\n#align topological_space.opens.compl TopologicalSpace.Opens.compl\n-/\n\n#print TopologicalSpace.Closeds.compl_compl /-\ntheorem Closeds.compl_compl (s : Closeds \u03b1) : s.compl.compl = s :=\n  Closeds.ext (compl_compl s)\n#align topological_space.closeds.compl_compl TopologicalSpace.Closeds.compl_compl\n-/\n\n#print TopologicalSpace.Opens.compl_compl /-\ntheorem Opens.compl_compl (s : Opens \u03b1) : s.compl.compl = s :=\n  Opens.ext (compl_compl s)\n#align topological_space.opens.compl_compl TopologicalSpace.Opens.compl_compl\n-/\n\n#print TopologicalSpace.Closeds.compl_bijective /-\ntheorem Closeds.compl_bijective : Function.Bijective (@Closeds.compl \u03b1 _) :=\n  Function.bijective_iff_has_inverse.mpr \u27e8Opens.compl, Closeds.compl_compl, Opens.compl_compl\u27e9\n#align topological_space.closeds.compl_bijective TopologicalSpace.Closeds.compl_bijective\n-/\n\n#print TopologicalSpace.Opens.compl_bijective /-\ntheorem Opens.compl_bijective : Function.Bijective (@Opens.compl \u03b1 _) :=\n  Function.bijective_iff_has_inverse.mpr \u27e8Closeds.compl, Opens.compl_compl, Closeds.compl_compl\u27e9\n#align topological_space.opens.compl_bijective TopologicalSpace.Opens.compl_bijective\n-/\n\nvariable (\u03b1)\n\n/- warning: topological_space.closeds.compl_order_iso -> TopologicalSpace.Closeds.complOrderIso is a dubious translation:\nlean 3 declaration is\n  forall (\u03b1 : Type.{u1}) [_inst_1 : TopologicalSpace.{u1} \u03b1], OrderIso.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (OrderDual.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1)) (Preorder.toLE.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (OrderDual.hasLe.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Opens.setLike.{u1} \u03b1 _inst_1)))))\nbut is expected to have type\n  forall (\u03b1 : Type.{u1}) [_inst_1 : TopologicalSpace.{u1} \u03b1], OrderIso.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (OrderDual.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1)) (Preorder.toLE.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))))) (OrderDual.instLEOrderDual.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (TopologicalSpace.Opens.instCompleteLatticeOpens.{u1} \u03b1 _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.compl_order_iso TopologicalSpace.Closeds.complOrderIso\u2093'. -/\n/-- `closeds.compl` as an `order_iso` to the order dual of `opens \u03b1`. -/\n@[simps]\ndef Closeds.complOrderIso : Closeds \u03b1 \u2243o (Opens \u03b1)\u1d52\u1d48\n    where\n  toFun := OrderDual.toDual \u2218 Closeds.compl\n  invFun := Opens.compl \u2218 OrderDual.ofDual\n  left_inv s := by simp [closeds.compl_compl]\n  right_inv s := by simp [opens.compl_compl]\n  map_rel_iff' s t := by\n    simpa only [Equiv.coe_fn_mk, Function.comp_apply, OrderDual.toDual_le_toDual] using\n      compl_subset_compl\n#align topological_space.closeds.compl_order_iso TopologicalSpace.Closeds.complOrderIso\n\n/- warning: topological_space.opens.compl_order_iso -> TopologicalSpace.Opens.complOrderIso is a dubious translation:\nlean 3 declaration is\n  forall (\u03b1 : Type.{u1}) [_inst_1 : TopologicalSpace.{u1} \u03b1], OrderIso.{u1, u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (OrderDual.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Preorder.toLE.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Opens.setLike.{u1} \u03b1 _inst_1)))) (OrderDual.hasLe.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))))\nbut is expected to have type\n  forall (\u03b1 : Type.{u1}) [_inst_1 : TopologicalSpace.{u1} \u03b1], OrderIso.{u1, u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (OrderDual.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1)) (Preorder.toLE.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (TopologicalSpace.Opens.instCompleteLatticeOpens.{u1} \u03b1 _inst_1))))) (OrderDual.instLEOrderDual.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align topological_space.opens.compl_order_iso TopologicalSpace.Opens.complOrderIso\u2093'. -/\n/-- `opens.compl` as an `order_iso` to the order dual of `closeds \u03b1`. -/\n@[simps]\ndef Opens.complOrderIso : Opens \u03b1 \u2243o (Closeds \u03b1)\u1d52\u1d48\n    where\n  toFun := OrderDual.toDual \u2218 Opens.compl\n  invFun := Closeds.compl \u2218 OrderDual.ofDual\n  left_inv s := by simp [opens.compl_compl]\n  right_inv s := by simp [closeds.compl_compl]\n  map_rel_iff' s t := by\n    simpa only [Equiv.coe_fn_mk, Function.comp_apply, OrderDual.toDual_le_toDual] using\n      compl_subset_compl\n#align topological_space.opens.compl_order_iso TopologicalSpace.Opens.complOrderIso\n\nvariable {\u03b1}\n\n/- warning: topological_space.closeds.is_atom_iff -> TopologicalSpace.Closeds.isAtom_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T1Space.{u1} \u03b1 _inst_1] {s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1}, Iff (IsAtom.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1))) (BoundedOrder.toOrderBot.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Closeds.setLike.{u1} \u03b1 _inst_1)))) (CompleteLattice.toBoundedOrder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.completeLattice.{u1} \u03b1 _inst_1))) s) (Exists.{succ u1} \u03b1 (fun (x : \u03b1) => Eq.{succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) s (TopologicalSpace.Closeds.singleton.{u1} \u03b1 _inst_1 _inst_3 x)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T1Space.{u1} \u03b1 _inst_1] {s : TopologicalSpace.Closeds.{u1} \u03b1 _inst_1}, Iff (IsAtom.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1)))) (BoundedOrder.toOrderBot.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))))) (CompleteLattice.toBoundedOrder.{u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) (TopologicalSpace.Closeds.instCompleteLatticeCloseds.{u1} \u03b1 _inst_1))) s) (Exists.{succ u1} \u03b1 (fun (x : \u03b1) => Eq.{succ u1} (TopologicalSpace.Closeds.{u1} \u03b1 _inst_1) s (TopologicalSpace.Closeds.singleton.{u1} \u03b1 _inst_1 _inst_3 x)))\nCase conversion may be inaccurate. Consider using '#align topological_space.closeds.is_atom_iff TopologicalSpace.Closeds.isAtom_iff\u2093'. -/\n/-- in a `t1_space`, atoms of `closeds \u03b1` are precisely the `closeds.singleton`s. -/\ntheorem Closeds.isAtom_iff [T1Space \u03b1] {s : Closeds \u03b1} : IsAtom s \u2194 \u2203 x, s = Closeds.singleton x :=\n  by\n  have : IsAtom (s : Set \u03b1) \u2194 IsAtom s :=\n    by\n    refine' closeds.gi.is_atom_iff' rfl (fun t ht => _) s\n    obtain \u27e8x, rfl\u27e9 := t.is_atom_iff.mp ht\n    exact closure_singleton\n  simpa only [\u2190 this, (s : Set \u03b1).isAtom_iff, SetLike.ext_iff, Set.ext_iff]\n#align topological_space.closeds.is_atom_iff TopologicalSpace.Closeds.isAtom_iff\n\n/- warning: topological_space.opens.is_coatom_iff -> TopologicalSpace.Opens.isCoatom_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T1Space.{u1} \u03b1 _inst_1] {s : TopologicalSpace.Opens.{u1} \u03b1 _inst_1}, Iff (IsCoatom.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Opens.setLike.{u1} \u03b1 _inst_1))) (BoundedOrder.toOrderTop.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (SetLike.partialOrder.{u1, u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Opens.setLike.{u1} \u03b1 _inst_1)))) (CompleteLattice.toBoundedOrder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (TopologicalSpace.Opens.completeLattice.{u1} \u03b1 _inst_1))) s) (Exists.{succ u1} \u03b1 (fun (x : \u03b1) => Eq.{succ u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) s (TopologicalSpace.Closeds.compl.{u1} \u03b1 _inst_1 (TopologicalSpace.Closeds.singleton.{u1} \u03b1 _inst_1 _inst_3 x))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] [_inst_3 : T1Space.{u1} \u03b1 _inst_1] {s : TopologicalSpace.Opens.{u1} \u03b1 _inst_1}, Iff (IsCoatom.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (TopologicalSpace.Opens.instCompleteLatticeOpens.{u1} \u03b1 _inst_1)))) (BoundedOrder.toOrderTop.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (Preorder.toLE.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (PartialOrder.toPreorder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (TopologicalSpace.Opens.instCompleteLatticeOpens.{u1} \u03b1 _inst_1))))) (CompleteLattice.toBoundedOrder.{u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) (TopologicalSpace.Opens.instCompleteLatticeOpens.{u1} \u03b1 _inst_1))) s) (Exists.{succ u1} \u03b1 (fun (x : \u03b1) => Eq.{succ u1} (TopologicalSpace.Opens.{u1} \u03b1 _inst_1) s (TopologicalSpace.Closeds.compl.{u1} \u03b1 _inst_1 (TopologicalSpace.Closeds.singleton.{u1} \u03b1 _inst_1 _inst_3 x))))\nCase conversion may be inaccurate. Consider using '#align topological_space.opens.is_coatom_iff TopologicalSpace.Opens.isCoatom_iff\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:73:14: unsupported tactic `congrm #[[expr \u00abexpr\u2203 , \u00bb((x), _)]] -/\n/-- in a `t1_space`, coatoms of `opens \u03b1` are precisely complements of singletons:\n`(closeds.singleton x).compl`. -/\ntheorem Opens.isCoatom_iff [T1Space \u03b1] {s : Opens \u03b1} :\n    IsCoatom s \u2194 \u2203 x, s = (Closeds.singleton x).compl :=\n  by\n  rw [\u2190 s.compl_compl, \u2190 isAtom_dual_iff_isCoatom]\n  change IsAtom (closeds.compl_order_iso \u03b1 s.compl) \u2194 _\n  rw [(closeds.compl_order_iso \u03b1).isAtom_iff, closeds.is_atom_iff]\n  trace\n    \"./././Mathport/Syntax/Translate/Tactic/Builtin.lean:73:14: unsupported tactic `congrm #[[expr \u00abexpr\u2203 , \u00bb((x), _)]]\"\n  exact closeds.compl_bijective.injective.eq_iff.symm\n#align topological_space.opens.is_coatom_iff TopologicalSpace.Opens.isCoatom_iff\n\n/-! ### Clopen sets -/\n\n\n#print TopologicalSpace.Clopens /-\n/-- The type of clopen sets of a topological space. -/\nstructure Clopens (\u03b1 : Type _) [TopologicalSpace \u03b1] where\n  carrier : Set \u03b1\n  clopen' : IsClopen carrier\n#align topological_space.clopens TopologicalSpace.Clopens\n-/\n\nnamespace Clopens\n\ninstance : SetLike (Clopens \u03b1) \u03b1 where\n  coe s := s.carrier\n  coe_injective' s t h := by\n    cases s\n    cases t\n    congr\n\n#print TopologicalSpace.Clopens.clopen /-\ntheorem clopen (s : Clopens \u03b1) : IsClopen (s : Set \u03b1) :=\n  s.clopen'\n#align topological_space.clopens.clopen TopologicalSpace.Clopens.clopen\n-/\n\n#print TopologicalSpace.Clopens.toOpens /-\n/-- Reinterpret a compact open as an open. -/\n@[simps]\ndef toOpens (s : Clopens \u03b1) : Opens \u03b1 :=\n  \u27e8s, s.clopen.IsOpen\u27e9\n#align topological_space.clopens.to_opens TopologicalSpace.Clopens.toOpens\n-/\n\n#print TopologicalSpace.Clopens.ext /-\n@[ext]\nprotected theorem ext {s t : Clopens \u03b1} (h : (s : Set \u03b1) = t) : s = t :=\n  SetLike.ext' h\n#align topological_space.clopens.ext TopologicalSpace.Clopens.ext\n-/\n\n#print TopologicalSpace.Clopens.coe_mk /-\n@[simp]\ntheorem coe_mk (s : Set \u03b1) (h) : (mk s h : Set \u03b1) = s :=\n  rfl\n#align topological_space.clopens.coe_mk TopologicalSpace.Clopens.coe_mk\n-/\n\ninstance : Sup (Clopens \u03b1) :=\n  \u27e8fun s t => \u27e8s \u222a t, s.clopen.union t.clopen\u27e9\u27e9\n\ninstance : Inf (Clopens \u03b1) :=\n  \u27e8fun s t => \u27e8s \u2229 t, s.clopen.inter t.clopen\u27e9\u27e9\n\ninstance : Top (Clopens \u03b1) :=\n  \u27e8\u27e8\u22a4, isClopen_univ\u27e9\u27e9\n\ninstance : Bot (Clopens \u03b1) :=\n  \u27e8\u27e8\u22a5, isClopen_empty\u27e9\u27e9\n\ninstance : SDiff (Clopens \u03b1) :=\n  \u27e8fun s t => \u27e8s \\ t, s.clopen.diff\u2093 t.clopen\u27e9\u27e9\n\ninstance : HasCompl (Clopens \u03b1) :=\n  \u27e8fun s => \u27e8s\u1d9c, s.clopen.compl\u27e9\u27e9\n\ninstance : BooleanAlgebra (Clopens \u03b1) :=\n  SetLike.coe_injective.BooleanAlgebra _ (fun _ _ => rfl) (fun _ _ => rfl) rfl rfl (fun _ => rfl)\n    fun _ _ => rfl\n\n/- warning: topological_space.clopens.coe_sup -> TopologicalSpace.Clopens.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.hasSup.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) (Sup.sup.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.instSupClopens.{u1} \u03b1 _inst_1) s t)) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.clopens.coe_sup TopologicalSpace.Clopens.coe_sup\u2093'. -/\n@[simp]\ntheorem coe_sup (s t : Clopens \u03b1) : (\u2191(s \u2294 t) : Set \u03b1) = s \u222a t :=\n  rfl\n#align topological_space.clopens.coe_sup TopologicalSpace.Clopens.coe_sup\n\n/- warning: topological_space.clopens.coe_inf -> TopologicalSpace.Clopens.coe_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) (Inf.inf.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.hasInf.{u1} \u03b1 _inst_1) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.hasInter.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) (Inf.inf.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.instInfClopens.{u1} \u03b1 _inst_1) s t)) (Inter.inter.{u1} (Set.{u1} \u03b1) (Set.instInterSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.clopens.coe_inf TopologicalSpace.Clopens.coe_inf\u2093'. -/\n@[simp]\ntheorem coe_inf (s t : Clopens \u03b1) : (\u2191(s \u2293 t) : Set \u03b1) = s \u2229 t :=\n  rfl\n#align topological_space.clopens.coe_inf TopologicalSpace.Clopens.coe_inf\n\n/- warning: topological_space.clopens.coe_top -> TopologicalSpace.Clopens.coe_top is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) (Top.top.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.hasTop.{u1} \u03b1 _inst_1))) (Set.univ.{u1} \u03b1)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) (Top.top.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.instTopClopens.{u1} \u03b1 _inst_1))) (Set.univ.{u1} \u03b1)\nCase conversion may be inaccurate. Consider using '#align topological_space.clopens.coe_top TopologicalSpace.Clopens.coe_top\u2093'. -/\n@[simp]\ntheorem coe_top : (\u2191(\u22a4 : Clopens \u03b1) : Set \u03b1) = univ :=\n  rfl\n#align topological_space.clopens.coe_top TopologicalSpace.Clopens.coe_top\n\n/- warning: topological_space.clopens.coe_bot -> TopologicalSpace.Clopens.coe_bot is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) (Bot.bot.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.hasBot.{u1} \u03b1 _inst_1))) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1], Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) (Bot.bot.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.instBotClopens.{u1} \u03b1 _inst_1))) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))\nCase conversion may be inaccurate. Consider using '#align topological_space.clopens.coe_bot TopologicalSpace.Clopens.coe_bot\u2093'. -/\n@[simp]\ntheorem coe_bot : (\u2191(\u22a5 : Clopens \u03b1) : Set \u03b1) = \u2205 :=\n  rfl\n#align topological_space.clopens.coe_bot TopologicalSpace.Clopens.coe_bot\n\n/- warning: topological_space.clopens.coe_sdiff -> TopologicalSpace.Clopens.coe_sdiff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) (SDiff.sdiff.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.hasSdiff.{u1} \u03b1 _inst_1) s t)) (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (t : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) (SDiff.sdiff.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.instSDiffClopens.{u1} \u03b1 _inst_1) s t)) (SDiff.sdiff.{u1} (Set.{u1} \u03b1) (Set.instSDiffSet.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) s) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align topological_space.clopens.coe_sdiff TopologicalSpace.Clopens.coe_sdiff\u2093'. -/\n@[simp]\ntheorem coe_sdiff (s t : Clopens \u03b1) : (\u2191(s \\ t) : Set \u03b1) = s \\ t :=\n  rfl\n#align topological_space.clopens.coe_sdiff TopologicalSpace.Clopens.coe_sdiff\n\n/- warning: topological_space.clopens.coe_compl -> TopologicalSpace.Clopens.coe_compl is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) (HasCompl.compl.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.hasCompl.{u1} \u03b1 _inst_1) s)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (HasLiftT.mk.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (CoeTC\u2093.coe.{succ u1, succ u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (Set.{u1} \u03b1) (SetLike.Set.hasCoeT.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.setLike.{u1} \u03b1 _inst_1)))) s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : TopologicalSpace.{u1} \u03b1] (s : TopologicalSpace.Clopens.{u1} \u03b1 _inst_1), Eq.{succ u1} (Set.{u1} \u03b1) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) (HasCompl.compl.{u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) (TopologicalSpace.Clopens.instHasComplClopens.{u1} \u03b1 _inst_1) s)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.instBooleanAlgebraSet.{u1} \u03b1)) (SetLike.coe.{u1, u1} (TopologicalSpace.Clopens.{u1} \u03b1 _inst_1) \u03b1 (TopologicalSpace.Clopens.instSetLikeClopens.{u1} \u03b1 _inst_1) s))\nCase conversion may be inaccurate. Consider using '#align topological_space.clopens.coe_compl TopologicalSpace.Clopens.coe_compl\u2093'. -/\n@[simp]\ntheorem coe_compl (s : Clopens \u03b1) : (\u2191(s\u1d9c) : Set \u03b1) = s\u1d9c :=\n  rfl\n#align topological_space.clopens.coe_compl TopologicalSpace.Clopens.coe_compl\n\ninstance : Inhabited (Clopens \u03b1) :=\n  \u27e8\u22a5\u27e9\n\nend Clopens\n\nend TopologicalSpace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/Sets/Closeds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7090602211509429}}
{"text": "-- Topology facts about \u2102\n\nimport data.complex.basic\nimport data.real.basic\nimport data.real.nnreal\nimport data.real.pi.bounds\nimport data.set.basic\nimport topology.metric_space.basic\n\nimport simple\nimport tactics\n\nopen metric (ball closed_ball)\nopen filter (at_top)\nopen_locale real nnreal topological_space\n\nnoncomputable theory\n\nlemma open_has_cball {s : set \u2102} (o : is_open s) (z \u2208 s) : \u2203 r : \u211d\u22650, r > 0 \u2227 closed_ball z r \u2286 s := begin\n  rw metric.is_open_iff at o,\n  have oz := o z H,\n  rcases oz with \u27e8t,ht,bs\u27e9,\n  set r : \u211d\u22650 := (t / 2).to_nnreal,\n  existsi r,\n  split,\n  refine real.to_nnreal_pos.mp _,\n  simp, linarith,\n  calc closed_ball z r \u2286 ball z t : metric.closed_ball_subset_ball _\n  ... \u2286 s : bs,\n  calc \u2191r = t/2 : real.coe_to_nnreal (t/2) (by linarith)\n  ... < t : by bound\nend\n\nlemma nhd_has_ball {z : \u2102} {s : set \u2102} (h : s \u2208 \ud835\udcdd z) : \u2203 r, r > 0 \u2227 metric.ball z r \u2286 s := begin\n  rcases mem_nhds_iff.mp h with \u27e8so,os,iso,zso\u27e9,\n  rcases metric.is_open_iff.mp iso z zso with \u27e8r,rp,rb\u27e9,\n  existsi r, constructor, assumption,\n  transitivity so, assumption, assumption\nend\n\n-- If something is true near c, it is true at c\nlemma filter.eventually.self {A : Type} [topological_space A] {p : A \u2192 Prop} {x : A}\n    (h : \u2200\u1da0 y in nhds x, p y) : p x := begin\n  rcases eventually_nhds_iff.mp h with \u27e8s,ps,_,xs\u27e9,\n  exact ps x xs,\nend\n\n-- Continuous functions achieve their supremum on compact sets\nlemma continuous_on.compact_max {A B : Type} [topological_space A] [topological_space B]\n    [conditionally_complete_linear_order B] [order_topology B]\n    {f : A \u2192 B} {s : set A} (fc : continuous_on f s) (cs : is_compact s) (sn : s.nonempty)\n    : \u2203 x, x \u2208 s \u2227 is_max_on f s x := begin\n  have ic := is_compact.image_of_continuous_on cs fc,\n  have ss := is_compact.Sup_mem ic (set.nonempty_image_iff.mpr sn),\n  rcases (set.mem_image _ _ _).mp ss with \u27e8x,xs,xm\u27e9,\n  existsi [x, xs],\n  rw is_max_on_iff, intros y ys, rw xm,\n  exact le_cSup ic.bdd_above ((set.mem_image _ _ _).mpr \u27e8y,ys,rfl\u27e9),\nend\n\n-- Continuous functions on compact sets are bounded\nlemma continuous_on.bounded {X : Type} [topological_space X]\n    {f : X \u2192 \u211d} {s : set X} (fc : continuous_on f s) (sc : is_compact s)\n    : \u2203 b : \u211d, b \u2265 0 \u2227 \u2200 x, x \u2208 s \u2192 f x \u2264 b := begin\n  by_cases n : s.nonempty, {\n    rcases fc.compact_max sc n with \u27e8x,xs,xm\u27e9,\n    use [max 0 (f x), by bound], intros y ys, exact trans (xm ys) (by bound),\n  }, {\n    rw set.not_nonempty_iff_eq_empty at n,\n    existsi [(0 : \u211d), le_refl _], simp [n],\n  },\nend  \n\n-- Continuous functions on compact sets have bounded norm\nlemma continuous_on.bounded_norm {X Y : Type} [topological_space X] [normed_add_comm_group Y]\n    {f : X \u2192 Y} {s : set X} (fc : continuous_on f s) (sc : is_compact s)\n    : \u2203 b : \u211d, b \u2265 0 \u2227 \u2200 x, x \u2208 s \u2192 \u2225f x\u2225 \u2264 b := begin\n  by_cases n : s.nonempty, {\n    have nc : continuous_on (\u03bb x, \u2225f x\u2225) s := continuous_norm.comp_continuous_on fc,\n    rcases nc.compact_max sc n with \u27e8x,xs,xm\u27e9,\n    existsi [\u2225f x\u2225, norm_nonneg _], intros y ys, exact xm ys,\n  }, {\n    rw set.not_nonempty_iff_eq_empty at n,\n    existsi [(0 : \u211d), le_refl _], simp [n],\n  }\nend  \n\n-- Uniform cauchy sequences are cauchy sequences at points\nlemma uniform_cauchy_seq_on.cauchy_seq {X Y : Type} [topological_space X] [metric_space Y]\n    {f : \u2115 \u2192 X \u2192 Y} {s : set X} (u : uniform_cauchy_seq_on f at_top s)\n    : \u2200 x, x \u2208 s \u2192 cauchy_seq (\u03bb n, f n x) := begin\n  intros x xs,\n  rw metric.cauchy_seq_iff,\n  rw metric.uniform_cauchy_seq_on_iff at u,\n  intros e ep, rcases u e ep with \u27e8N,H\u27e9,\n  existsi N, intros a aN b bN,\n  exact H a aN b bN x xs,\nend\n\n-- Uniform cauchy sequences on compact sets are uniformly bounded\nlemma uniform_cauchy_seq_on.bounded {X Y : Type} [topological_space X] [normed_add_comm_group Y]\n    {f : \u2115 \u2192 X \u2192 Y} {s : set X} (u : uniform_cauchy_seq_on f at_top s) (fc : \u2200 n, continuous_on (f n) s) (sc : is_compact s)\n    : \u2203 b : \u211d, b \u2265 0 \u2227 \u2200 n x, x \u2208 s \u2192 \u2225f n x\u2225 \u2264 b := begin\n  set c := \u03bb n, classical.some ((fc n).bounded_norm sc),\n  have cs : \u2200 n, 0 \u2264 c n \u2227 \u2200 x, x \u2208 s \u2192 \u2225f n x\u2225 \u2264 c n := \u03bb n, classical.some_spec ((fc n).bounded_norm sc),\n  rw metric.uniform_cauchy_seq_on_iff at u,\n  rcases u 1 (by norm_num) with \u27e8N,H\u27e9, clear u,\n  set bs := finset.image c (finset.range (N+1)),\n  have c0 : c 0 \u2208 bs, { simp, existsi 0, simp },\n  set b := 1 + bs.max' \u27e8_,c0\u27e9,\n  existsi b, constructor, {\n    bound [trans (cs 0).1 (finset.le_max' _ _ c0)],\n  }, {\n    intros n x xs,\n    by_cases nN : n \u2264 N, {\n      have cn : c n \u2208 bs, { simp, existsi n, simp [nat.lt_add_one_iff.mpr nN] },\n      exact trans ((cs n).2 x xs) (trans (finset.le_max' _ _ cn) (by bound)),\n    }, {\n      simp at nN,\n      specialize H N (by bound) n (by bound) x xs,\n      have cN : c N \u2208 bs, { simp, existsi N, simp },\n      have bN := trans ((cs N).2 x xs) (finset.le_max' _ _ cN),\n      rw dist_eq_norm at H,\n      calc \u2225f n x\u2225 = \u2225f N x - (f N x - f n x)\u2225 : by abel\n      ... \u2264 \u2225f N x\u2225 + \u2225f N x - f n x\u2225 : by bound\n      ... \u2264 bs.max' _ + 1 : by bound\n      ... = 1 + bs.max' _ : by abel\n      ... = b : rfl,\n    }\n  },\nend\n\n-- Functions from empty spaces are continuous\nlemma is_empty.continuous {A B : Type} [topological_space A] [topological_space B]\n    [is_empty A] (f : A \u2192 B) : continuous f := begin\n  rw continuous_def, intros s o,\n  have e : f \u207b\u00b9' s = \u2205, { apply set.subset_eq_empty (set.subset_univ _), simp, apply_instance },\n  simp [e],\nend", "meta": {"author": "girving", "repo": "ray", "sha": "e0c501756e067711e2d3667d4b1d18045d83a313", "save_path": "github-repos/lean/girving-ray", "path": "github-repos/lean/girving-ray/ray-e0c501756e067711e2d3667d4b1d18045d83a313/src/topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7090602142891418}}
{"text": "/-\nCopyright (c) 2021 Ashvni Narayanan. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ashvni Narayanan, Anne Baanen\n-/\n\nimport ring_theory.dedekind_domain.integral_closure\nimport algebra.char_p.algebra\n\n/-!\n# Number fields\nThis file defines a number field, the ring of integers corresponding to it and includes some\nbasic facts about the embeddings into an algebraic closed field.\n\n## Main definitions\n - `number_field` defines a number field as a field which has characteristic zero and is finite\n    dimensional over \u211a.\n - `ring_of_integers` defines the ring of integers (or number ring) corresponding to a number field\n    as the integral closure of \u2124 in the number field.\n\n## Main Result\n - `eq_roots`: let `x \u2208 K` with `K` number field and let `A` be an algebraic closed field of\n    char. 0, then the images of `x` by the embeddings of `K` in `A` are exactly the roots in\n    `A` of the minimal polynomial of `x` over `\u211a`.\n\n## Implementation notes\nThe definitions that involve a field of fractions choose a canonical field of fractions,\nbut are independent of that choice.\n\n## References\n* [D. Marcus, *Number Fields*][marcus1977number]\n* [J.W.S. Cassels, A. Fr\u00f6lich, *Algebraic Number Theory*][cassels1967algebraic]\n* [P. Samuel, *Algebraic Theory of Numbers*][samuel1970algebraic]\n\n## Tags\nnumber field, ring of integers\n-/\n\n/-- A number field is a field which has characteristic zero and is finite\ndimensional over \u211a. -/\nclass number_field (K : Type*) [field K] : Prop :=\n[to_char_zero : char_zero K]\n[to_finite_dimensional : finite_dimensional \u211a K]\n\nopen function\nopen_locale classical big_operators\n\n/-- `\u2124` with its usual ring structure is not a field. -/\nlemma int.not_is_field : \u00ac is_field \u2124 :=\n\u03bb h, int.not_even_one $ (h.mul_inv_cancel two_ne_zero).imp $ \u03bb a, (by rw \u2190 two_mul; exact eq.symm)\n\nnamespace number_field\n\nvariables (K L : Type*) [field K] [field L] [nf : number_field K]\n\ninclude nf\n\n-- See note [lower instance priority]\nattribute [priority 100, instance] number_field.to_char_zero number_field.to_finite_dimensional\n\nprotected lemma is_algebraic : algebra.is_algebraic \u211a K := algebra.is_algebraic_of_finite _ _\n\nomit nf\n\n/-- The ring of integers (or number ring) corresponding to a number field\nis the integral closure of \u2124 in the number field. -/\ndef ring_of_integers := integral_closure \u2124 K\n\nlocalized \"notation `\ud835\udcde` := number_field.ring_of_integers\" in number_field\n\nlemma mem_ring_of_integers (x : K) : x \u2208 \ud835\udcde K \u2194 is_integral \u2124 x := iff.rfl\n\n/-- Given an algebra between two fields, create an algebra between their two rings of integers.\n\nFor now, this is not an instance by default as it creates an equal-but-not-defeq diamond with\n`algebra.id` when `K = L`. This is caused by `x = \u27e8x, x.prop\u27e9` not being defeq on subtypes. This\nwill likely change in Lean 4. -/\ndef ring_of_integers_algebra [algebra K L] : algebra (\ud835\udcde K) (\ud835\udcde L) := ring_hom.to_algebra\n{ to_fun := \u03bb k, \u27e8algebra_map K L k, is_integral.algebra_map k.2\u27e9,\n  map_zero' := subtype.ext $ by simp only [subtype.coe_mk, subalgebra.coe_zero, map_zero],\n  map_one'  := subtype.ext $ by simp only [subtype.coe_mk, subalgebra.coe_one, map_one],\n  map_add' := \u03bb x y, subtype.ext $ by simp only [map_add, subalgebra.coe_add, subtype.coe_mk],\n  map_mul' := \u03bb x y, subtype.ext $ by simp only [subalgebra.coe_mul, map_mul, subtype.coe_mk] }\n\nnamespace ring_of_integers\n\nvariables {K}\n\ninstance [number_field K] : is_fraction_ring (\ud835\udcde K) K :=\nintegral_closure.is_fraction_ring_of_finite_extension \u211a _\n\ninstance : is_integral_closure (\ud835\udcde K) \u2124 K :=\nintegral_closure.is_integral_closure _ _\n\ninstance [number_field K] : is_integrally_closed (\ud835\udcde K) :=\nintegral_closure.is_integrally_closed_of_finite_extension \u211a\n\nlemma is_integral_coe (x : \ud835\udcde K) : is_integral \u2124 (x : K) :=\nx.2\n\n/-- The ring of integers of `K` are equivalent to any integral closure of `\u2124` in `K` -/\nprotected noncomputable def equiv (R : Type*) [comm_ring R] [algebra R K]\n  [is_integral_closure R \u2124 K] : \ud835\udcde K \u2243+* R :=\n(is_integral_closure.equiv \u2124 R K _).symm.to_ring_equiv\n\nvariables (K)\n\ninstance [number_field K] : char_zero (\ud835\udcde K) := char_zero.of_module _ K\n\n/-- The ring of integers of a number field is not a field. -/\nlemma not_is_field [number_field K] : \u00ac is_field (\ud835\udcde K) :=\nbegin\n  have h_inj : function.injective \u21d1(algebra_map \u2124 (\ud835\udcde K)),\n  { exact ring_hom.injective_int (algebra_map \u2124 (\ud835\udcde K)) },\n  intro hf,\n  exact int.not_is_field\n    (((is_integral_closure.is_integral_algebra \u2124 K).is_field_iff_is_field h_inj).mpr hf)\nend\n\ninstance [number_field K] : is_dedekind_domain (\ud835\udcde K) :=\nis_integral_closure.is_dedekind_domain \u2124 \u211a K _\n\nend ring_of_integers\n\nend number_field\n\nnamespace rat\n\nopen number_field\n\nlocal attribute [instance] subsingleton_rat_module\n\ninstance rat.number_field : number_field \u211a :=\n{ to_char_zero := infer_instance,\n  to_finite_dimensional :=\n    -- The vector space structure of `\u211a` over itself can arise in multiple ways:\n    -- all fields are vector spaces over themselves (used in `rat.finite_dimensional`)\n    -- all char 0 fields have a canonical embedding of `\u211a` (used in `number_field`).\n    -- Show that these coincide:\n    by convert (infer_instance : finite_dimensional \u211a \u211a), }\n\n/-- The ring of integers of `\u211a` as a number field is just `\u2124`. -/\nnoncomputable def ring_of_integers_equiv : ring_of_integers \u211a \u2243+* \u2124 :=\nring_of_integers.equiv \u2124\n\nend rat\n\nnamespace adjoin_root\n\nsection\n\nopen_locale polynomial\n\nlocal attribute [-instance] algebra_rat\n\n/-- The quotient of `\u211a[X]` by the ideal generated by an irreducible polynomial of `\u211a[X]`\nis a number field. -/\ninstance {f : \u211a[X]} [hf : irreducible f] : number_field (adjoin_root f) :=\n{ to_char_zero := char_zero_of_injective_algebra_map (algebra_map \u211a _).injective,\n  to_finite_dimensional := begin\n   let := (adjoin_root.power_basis (irreducible.ne_zero hf : f \u2260 0)),\n   convert power_basis.finite_dimensional this,\n   haveI : subsingleton (algebra \u211a (adjoin_root f)) := algebra_rat_subsingleton,\n   exact subsingleton.elim _ _,\n  end }\n\nend\n\nend adjoin_root\n\nnamespace number_field.embeddings\n\nsection number_field\n\nopen set finite_dimensional polynomial\n\nvariables {K L : Type*} [field K] [field L]\nvariables [number_field K] [number_field L]  (x : K)\n\nvariables {A : Type*} [field A] [char_zero A]\n\n/-- There are finitely many embeddings of a number field. -/\nnoncomputable instance : fintype (K \u2192+* A) := fintype.of_equiv (K \u2192\u2090[\u211a] A)\nring_hom.equiv_rat_alg_hom.symm\n\nvariables [is_alg_closed A]\n\n/-- The number of embeddings of a number field is its finrank. -/\nlemma card : fintype.card (K \u2192+* A) = finrank \u211a K :=\nby rw [fintype.of_equiv_card ring_hom.equiv_rat_alg_hom.symm, alg_hom.card]\n\n/-- For `x \u2208 K`, with `K` a number field, the images of `x` by the embeddings of `K` are exactly\nthe roots of the minimal polynomial of `x` over `\u211a` -/\nlemma eq_roots : range (\u03bb \u03c6 : K \u2192+* A, \u03c6 x) = (minpoly \u211a x).root_set A :=\nbegin\n  have hx : is_integral \u211a x := is_separable.is_integral \u211a x,\n  ext a, split,\n  { rintro \u27e8\u03c6, h\u03c6\u27e9,\n    rw [mem_root_set_iff, \u2190h\u03c6],\n    { let \u03c8 := ring_hom.equiv_rat_alg_hom \u03c6,\n      show (aeval (\u03c8 x)) (minpoly \u211a x) = 0,\n      rw aeval_alg_hom_apply \u03c8 x (minpoly \u211a x),\n      simp only [minpoly.aeval, map_zero], },\n    exact minpoly.ne_zero hx, },\n  { intro ha,\n    let Qx := adjoin_root (minpoly \u211a x),\n    haveI : irreducible (minpoly \u211a x) := minpoly.irreducible hx,\n    have hK : (aeval x) (minpoly \u211a x) = 0, { exact minpoly.aeval _ _, },\n    have hA : (aeval a) (minpoly \u211a x) = 0,\n    { rw [aeval_def, \u2190eval_map, \u2190mem_root_set_iff'],\n      exact ha,\n      refine polynomial.monic.ne_zero _,\n      exact polynomial.monic.map (algebra_map \u211a A) (minpoly.monic hx), },\n    let \u03c8 : Qx \u2192+* A := adjoin_root.lift (algebra_map \u211a A) a hA,\n    letI : algebra Qx A := ring_hom.to_algebra \u03c8,\n    letI : algebra Qx K := ring_hom.to_algebra (adjoin_root.lift (algebra_map \u211a K) x hK),\n    let \u03c6\u2080 : K \u2192\u2090[Qx] A := is_alg_closed.lift _,\n    swap,\n    { refine algebra.is_algebraic_of_larger_base \u211a Qx _,\n      exact number_field.is_algebraic _, },\n    let \u03c6 := \u03c6\u2080.to_ring_hom,\n    use \u03c6,\n    rw (_ : x = (algebra_map Qx K) (adjoin_root.root (minpoly \u211a x))),\n    { rw (_ : a = \u03c8 (adjoin_root.root (minpoly \u211a x))),\n      refine alg_hom.commutes _ _,\n      exact (adjoin_root.lift_root hA).symm, },\n    exact (adjoin_root.lift_root hK).symm, },\nend\n\nend number_field\n\nend number_field.embeddings\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/number_theory/number_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7090602128224038}}
{"text": "import .love10_denotational_semantics_demo\n\n\n/- # LoVe Homework 10: Denotational Semantics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1 (7 points): Denotational Semantics of DOWHILE -/\n\nnamespace do_while\n\n/- Consider the following DOWHILE language: -/\n\ninductive stmt : Type\n| skip     : stmt\n| assign   : string \u2192 (state \u2192 \u2115) \u2192 stmt\n| seq      : stmt \u2192 stmt \u2192 stmt\n| unless   : stmt \u2192 (state \u2192 Prop) \u2192 stmt\n| while    : (state \u2192 Prop) \u2192 stmt \u2192 stmt\n| do_while : stmt \u2192 (state \u2192 Prop) \u2192 stmt\n\ninfixr ` ;; ` : 90 := stmt.seq\n\n/- The `skip`, `assign`, `seq`, and `while constructs are as for the WHILE\nlanguage.\n\n`unless S b` executes `S` if `b` is false in the current state; otherwise, it\ndoes nothing. This statement is inspired by Perl's `unless` conditional.\n\n`do_while S b` first executes `S`. Then, if `b` is true in the resulting state,\nit re-enters the loop and executes `S` again, and continues executing `S` until\n`b` becomes `false`. The semantics is almost the same as `while b S`, except\nthat `p` is always executed at least once, even if the condition is not true\ninitially. This statement is inspired by C's and Java's `do { \u2026 } while (\u2026)`\nloop.\n\n1.1 (2 points). Give a denotational semantics of DOWHILE.\n\nHint: Your definition should make it easy to prove lemma `do_while_while` in\nquestion 1.2. -/\n\ndef denote : stmt \u2192 set (state \u00d7 state)\n| stmt.skip           := Id\n-- enter the missing cases here\n\nnotation `\u27e6` S `\u27e7`:= denote S\n\n/- 1.2 (1 point). Prove the following correspondence between `do_while` and\n`while`. -/\n\nlemma do_while_while (S : stmt) (b : state \u2192 Prop) :\n  \u27e6stmt.do_while S b\u27e7 = \u27e6S\u27e7 \u25ef \u27e6stmt.while b S\u27e7 :=\nsorry\n\n/- 1.3 (4 points). Prove the following lemmas.\n\nHint: For all of these, short proofs are possible. -/\n\nlemma lfp_const {\u03b1 : Type} [complete_lattice \u03b1] (a : \u03b1) :\n  lfp (\u03bbX, a) = a :=\nsorry\n\nlemma while_false (S : stmt) :\n  \u27e6stmt.while (\u03bb_, false) S\u27e7 = Id :=\nsorry\n\nlemma comp_Id {\u03b1 : Type} (r : set (\u03b1 \u00d7 \u03b1)) :\n  r \u25ef Id = r :=\nsorry\n\nlemma do_while_false (S : stmt) :\n  \u27e6stmt.do_while S (\u03bb_, false)\u27e7 = \u27e6S\u27e7 :=\nsorry\n\nend do_while\n\n\n/- ## Question 2 (2 points + 2 bonus points): Kleene's Theorem\n\nWe can compute the fixpoint by iteration by taking the union of all finite\niterations of `f`:\n\n    `lfp f = \u22c3i, (f ^^ i) \u2205`\n\nwhere\n\n    `f ^^ i = f \u2218 \u22ef \u2218 f`\n\niterates the function `f` `i` times. However, the above characterization of\n`lfp` only holds for continuous functions, a concept we will introduce below. -/\n\ndef iterate {\u03b1 : Type} (f : \u03b1 \u2192 \u03b1) : \u2115 \u2192 \u03b1 \u2192 \u03b1\n| 0       a := a\n| (n + 1) a := f (iterate n a)\n\nnotation f`^^`n := iterate f n\n\n/- 2.1 (2 points). Fill in the missing proofs below. -/\n\ndef Union {\u03b1 : Type} (s : \u2115 \u2192 set \u03b1) : set \u03b1 :=\n{a | \u2203n, a \u2208 s n}\n\nlemma Union_le {\u03b1 : Type} {s : \u2115 \u2192 set \u03b1} (A : set \u03b1) (h : \u2200i, s i \u2264 A) :\n  Union s \u2264 A :=\nsorry\n\n/- A continuous function `f` is a function that commutes with the union of any\nmonotone sequence `s`: -/\n\ndef continuous {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) : Prop :=\n\u2200s : \u2115 \u2192 set \u03b1, monotone s \u2192 f (Union s) = Union (\u03bbi, f (s i))\n\n/- We need to prove that each continuous function is monotone. To achieve this,\nwe will need the following sequence: -/\n\ndef bi_seq {\u03b1 : Type} (A B : set \u03b1) : \u2115 \u2192 set \u03b1\n| 0       := A\n| (n + 1) := B\n\n/- For example, `bi_seq A B` is the sequence A, B, B, B, \u2026. -/\n\nlemma monotone_bi_seq {\u03b1 : Type} (A B : set \u03b1) (h : A \u2264 B) :\n  monotone (bi_seq A B)\n| 0       0       _ := le_refl _\n| 0       (n + 1) _ := h\n| (n + 1) (m + 1) _ := le_refl _\n\nlemma Union_bi_seq {\u03b1 : Type} (A B : set \u03b1) (ha : A \u2264 B) :\n  Union (bi_seq A B) = B :=\nbegin\n  apply le_antisymm,\n  { sorry },\n  { sorry }\nend\n\nlemma monotone_of_continuous {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1)\n    (hf : continuous f) :\n  monotone f :=\nsorry\n\n/- 2.2 (1 bonus point). Provide the following proof, using a similar case\ndistinction as for `monotone_bi_seq` above. -/\n\nlemma monotone_iterate {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) (hf : monotone f) :\n  monotone (\u03bbi, (f ^^ i) \u2205) :=\nsorry\n\n/- 2.3 (1 bonus point). Prove the main theorem. A proof sketch is given below.\n\nWe break the proof into two proofs of inclusion.\n\nCase 1. `lfp f \u2264 Union (\u03bbi, (f ^^ i) \u2205)`: The key is to use the lemma `lfp_le`\ntogether with continuity of `f`.\n\nCase 2. `Union (\u03bbi, (f ^^ i) \u2205) \u2264 lfp f`: The lemma `Union_le` gives us a\nnatural number `i`, on which you can perform induction. We also need the lemma\n`lfp_eq` to unfold one iteration of `lfp f`. -/\n\nlemma lfp_Kleene {\u03b1 : Type} (f : set \u03b1 \u2192 set \u03b1) (hf : continuous f) :\n  lfp f = Union (\u03bbi, (f ^^ i) \u2205) :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love10_denotational_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7090602041495049}}
{"text": "import algebra.group.basic\nimport data.zmod.basic\nimport data.equiv.basic\nimport tactic\nimport data.set.basic \n\nimport .cayleys\n\nvariables {G\u2081 : Type*} {G\u2082 : Type*} [group G\u2081] [group G\u2082]\n\nopen equiv function set\n\ndef hom_induces_group (f : G\u2081 \u2192* G\u2082) : group (range f) :=\n{ mul := has_mul.mul,\n  mul_assoc := mul_assoc,\n  one := has_one.one,\n  one_mul := one_mul,\n  mul_one := mul_one,\n  inv := has_inv.inv,\n  mul_left_inv := mul_left_inv,\n}\n\ndef \u03c8 (h : G\u2081 \u2243* G\u2082): perm G\u2081 \u2192 perm G\u2082 := \u03bb \u03b8, \n{ to_fun := h.1 \u2218 \u03b8.1 \u2218 h.2,\n  inv_fun := h.1 \u2218 \u03b8.2 \u2218 h.2,\n  left_inv := begin\n    intro x,\n    calc (h.to_fun \u2218 \u03b8.inv_fun \u2218 h.inv_fun) ((h.to_fun \u2218 \u03b8.to_fun \u2218 h.inv_fun) x) \n          = (h.to_fun \u2218 \u03b8.inv_fun \u2218 (h.inv_fun \u2218 h.to_fun) \u2218 \u03b8.to_fun \u2218 h.inv_fun) x : rfl \n      ... = (h.to_fun \u2218 \u03b8.inv_fun \u2218 id \u2218 \u03b8.to_fun \u2218 h.inv_fun) x : by rw left_inverse.id h.3\n      ... = (h.to_fun \u2218 (\u03b8.inv_fun \u2218 \u03b8.to_fun) \u2218 h.inv_fun) x : rfl \n      ... = (h.to_fun \u2218 id \u2218 h.inv_fun) x : by rw left_inverse.id \u03b8.3\n      ... = (h.to_fun \u2218 h.inv_fun) x : rfl \n      ... = id x : by rw right_inverse.id h.4,\n  end,\n  right_inv := begin \n    intro x,\n    calc (h.to_fun \u2218 \u03b8.to_fun \u2218 h.inv_fun) ((h.to_fun \u2218 \u03b8.inv_fun \u2218 h.inv_fun) x)\n          = (h.to_fun \u2218 \u03b8.to_fun \u2218 (h.inv_fun \u2218 h.to_fun) \u2218 \u03b8.inv_fun \u2218 h.inv_fun) x : rfl \n      ... = (h.to_fun \u2218 \u03b8.to_fun \u2218 id \u2218 \u03b8.inv_fun \u2218 h.inv_fun) x : by rw left_inverse.id h.3\n      ... = (h.to_fun \u2218 (\u03b8.to_fun \u2218 \u03b8.inv_fun) \u2218 h.inv_fun) x : rfl \n      ... = (h.to_fun \u2218 id \u2218 h.inv_fun) x : by rw right_inverse.id \u03b8.4 \n      ... = (h.to_fun \u2218 h.inv_fun) x : rfl \n      ... = id x : by rw right_inverse.id h.4,\n  end,\n}\n\nlemma embedding_diagram_com (h : G\u2081 \u2243* G\u2082) \n  : (\u03c8 h) \u2218 (lift_to_perm G\u2081).1 = (lift_to_perm G\u2082).1 \u2218 h.1 := begin \n  ext g x,\n  have H\u2081 : ((\u03c8 h \u2218 (lift_to_perm G\u2081).to_fun) g) x = (h.1 g) * x,\n    calc ((\u03c8 h \u2218 (lift_to_perm G\u2081).to_fun) g) x \n          = h.1 (g * (h.2 x)) : rfl \n      ... = (h.1 g) * (h.1 (h.2 x)) : mul_equiv.map_mul h g (h.inv_fun x) \n      ... = (h.1 g) * ((h.1 \u2218 h.2) x) : rfl \n      ... = (h.1 g) * (id x) : by rw right_inverse.id h.4,\n  have H\u2082 : (((lift_to_perm G\u2082).to_fun \u2218 h.1) g) x = (h.1 g) * x := rfl,\n  rw [H\u2081, H\u2082],\nend ", "meta": {"author": "th-char", "repo": "cayleys_theorem", "sha": "c4862adbe1e6a8892fd607217c803f260ee74be2", "save_path": "github-repos/lean/th-char-cayleys_theorem", "path": "github-repos/lean/th-char-cayleys_theorem/cayleys_theorem-c4862adbe1e6a8892fd607217c803f260ee74be2/src/misc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7090318649608556}}
{"text": "import data.zmod.parity\nimport number_theory.pythagorean_triples\n\nimport number_theory.quadratic_reciprocity\n\n\n/-\nAuthors: Lisa Cenek, Brittany Gelb\n-/\n\n/-\nSeveral useful elementary properties of primitive pythagorean triples follow nicely from the \nclassification theorem. \n\nWe formalize some of those properties, starting with divisibility by 3 and 4.\n-/\n\nopen pythagorean_triple\n\n/-\nIf x,y,z is a primitive pythagorean triple, then exactly one of x,y is 0 mod 4.\n-/\ntheorem pythagorean_triple_exactly_one_div_four {x y z : \u2124} (h : pythagorean_triple x y z)\n  (h_coprime : int.gcd x y = 1):\n  ((x % 4 = 0) \u2227 (y % 4 \u2260 0)) \u2228 ((x % 4 \u2260 0) \u2227 (y % 4 = 0))  :=\nbegin\n  have k : pythagorean_triple x y z \u2227 int.gcd x y = 1,\n  split,\n  exact h,\n  exact h_coprime,\n  rw coprime_classification at k,\n  cases k with m km,\n  cases km with n kmn,\n\n  cases kmn with k1 k2,\n  cases k2 with k2 k3,\n  cases k3 with k3 k4,\n  cases k4 with k4 k5,\n  {\n    cases k1 with y_even x_even,\n    {\n      right,\n      cases y_even with x_odd y_even,\n      cases k4 with k4m k4n,\n      have eq1 := int.mod_add_div m 2,\n      rw k4m at eq1,\n      rw zero_add at eq1,\n      rw \u2190 eq1 at y_even,\n      rw \u2190 mul_assoc 2 2 (m / 2) at y_even,\n      have two_mul_two : (2 : \u2124 ) * 2 = 4 := by norm_num,\n      rw two_mul_two at y_even,\n      norm_num,\n      rw mul_assoc at y_even,\n      have four_div_y := dvd.intro (m / 2 * n) (eq.symm y_even),\n      refine \u27e8_, four_div_y\u27e9,\n      rw \u2190 imp_false,\n      intro j,\n      have four_div_one := int.dvd_gcd j four_div_y,\n      rw h_coprime at four_div_one,\n      norm_num at four_div_one,\n    },\n    {\n      left,\n      cases x_even with x_even y_odd,\n      cases k4 with k4m k4n,\n      have eq1 := int.mod_add_div m 2,\n      rw k4m at eq1,\n      rw zero_add at eq1,\n      rw \u2190 eq1 at x_even,\n      rw \u2190 mul_assoc 2 2 (m / 2) at x_even,\n      have two_mul_two : (2 : \u2124 ) * 2 = 4 := by norm_num,\n      rw two_mul_two at x_even,\n      norm_num,\n      rw mul_assoc at x_even,\n      have four_div_x := dvd.intro (m / 2 * n) (eq.symm x_even),\n      refine \u27e8four_div_x, _\u27e9,\n      rw \u2190 imp_false,\n      intro j,\n      have four_div_one := int.dvd_gcd four_div_x j,\n      rw h_coprime at four_div_one,\n      norm_num at four_div_one,\n    }\n\n  },\n\n{\n    cases k1 with y_even x_even,\n    {\n      right,\n      cases y_even with x_odd y_even,\n      cases k5 with k5m k5n,\n\n      have eq1 := int.mod_add_div n 2,\n      rw k5n at eq1,\n      rw zero_add at eq1,\n      rw mul_assoc at y_even,\n      rw mul_comm m n at y_even,\n      rw \u2190 mul_assoc at y_even,\n\n      rw \u2190 eq1 at y_even,\n\n      rw \u2190 mul_assoc 2 2 (n / 2) at y_even,\n\n      have two_mul_two : (2 : \u2124 ) * 2 = 4 := by norm_num,\n\n      rw two_mul_two at y_even,\n\n      norm_num,\n      rw mul_assoc at y_even,\n      have four_div_y := dvd.intro (n / 2 * m) (eq.symm y_even),\n\n      refine \u27e8_, four_div_y\u27e9,\n      rw \u2190 imp_false,\n      intro j,\n\n      have four_div_one := int.dvd_gcd j four_div_y,\n      rw h_coprime at four_div_one,\n      norm_num at four_div_one,\n\n    },\n    {\n      left,\n      cases x_even with x_even y_odd,\n      cases k5 with k5m k5n,\n\n      have eq1 := int.mod_add_div n 2,\n      rw k5n at eq1,\n      rw zero_add at eq1,\n      rw mul_assoc at x_even,\n      rw mul_comm m n at x_even,\n      rw \u2190 mul_assoc at x_even,\n      rw \u2190 eq1 at x_even,\n      rw \u2190 mul_assoc 2 2 (n / 2) at x_even,\n      have two_mul_two : (2 : \u2124 ) * 2 = 4 := by norm_num,\n      rw two_mul_two at x_even,\n\n      norm_num,\n      rw mul_assoc at x_even,\n      have four_div_x := dvd.intro (n / 2 * m) (eq.symm x_even),\n\n      refine \u27e8four_div_x, _\u27e9,\n      rw \u2190 imp_false,\n      intro j,\n\n      have four_div_one := int.dvd_gcd four_div_x j,\n      rw h_coprime at four_div_one,\n      norm_num at four_div_one,\n    }\n\n  }\n\n\nend\n\n\n/-\nLemma to obtain possible values modulo 3.\n(Modeled from data.nat.parity)\n-/\nlemma mod_three_eq_zero_or_one_or_two (n : \u2124) : n % 3 = 0 \u2228 n % 3 = 1 \u2228 n % 3 = 2 :=\nhave h : n % 3 < 3 := abs_of_nonneg (show 0 \u2264 (3 : \u2124), from dec_trivial) \u25b8 int.mod_lt _ dec_trivial,\nhave h\u2081 : 0 \u2264 n % 3 := int.mod_nonneg _ dec_trivial,\nmatch (n % 3), h, h\u2081 with\n| (0 : \u2115) := \u03bb _ _ , or.inl rfl\n| (1 : \u2115) := \u03bb _ _ , or.inr (or.inl rfl)\n| (2 : \u2115) := \u03bb _ _ , or.inr (or.inr rfl)\n| (k + 3 : \u2115) := \u03bb h _, absurd h dec_trivial\n| -[1+ a] := \u03bb _ h\u2081, absurd h\u2081 dec_trivial\nend\n\n\n\n\n/-\nIf x,y,z is a primitive pythagorean triple, then exactly one of x,y is 0 mod 3.\n-/\ntheorem pythagorean_triple_exactly_one_div_three {x y z : \u2124} (h : pythagorean_triple x y z)\n  (h_coprime : int.gcd x y = 1):\n  ((x % 3 = 0) \u2227 (y % 3 \u2260 0)) \u2228 ((x % 3 \u2260 0) \u2227 (y % 3 = 0))  :=\nbegin\n  by_contradiction H,\n  rw push_neg.not_or_eq at H,\n  cases H with h1 h2,\n  rw push_neg.not_and_eq at h1,\n  rw push_neg.not_and_eq at h2,\n  rw push_neg.not_not_eq at h1,\n\n  by_cases j : (x % 3 = 0),\n  {\n    have j' := h1 j,\n    simp at h1 j j',\n    have three_div_one := int.dvd_gcd j j',\n    rw h_coprime at three_div_one,\n    norm_num at three_div_one,\n  },\n  {\n  have j' := h2 j,\n\n  have xlem := mod_three_eq_zero_or_one_or_two x,\n  have ylem := mod_three_eq_zero_or_one_or_two y,\n\n  have xlem' := or.resolve_left xlem j,\n  have ylem' := or.resolve_left ylem j',\n\n  have pyth_mod : (x * x + y * y) % 3 = (x * x + y * y) % 3 := by refl,\n  have xyz : x * x + y * y = z * z := h,\n\n  have pyth_mod' : (x*x + y*y) % 3 = (z*z) % 3 := by {\n    calc (x*x + y*y) % 3 = (x*x + y*y) % 3 : by refl\n                  ...= (z*z) % 3 : by rw xyz,\n        },\n\n  cases xlem' with x1 x2,\n  {\n    cases ylem' with y1 y2,\n    {\n      have x_sq := int.mul_mod x x 3,\n      rw x1 at x_sq,\n      have y_sq := int.mul_mod y y 3,\n      rw y1 at y_sq,\n      norm_num at x_sq,\n      norm_num at y_sq,\n\n      rw int.add_mod (x*x) (y*y) 3 at pyth_mod',\n      rw x_sq at pyth_mod',\n      rw y_sq at pyth_mod',\n      norm_num at pyth_mod',\n\n      haveI : fact (nat.prime 3) := by sorry,\n      have two_not_zero : (2 : zmod 3) \u2260 0 := dec_trivial,\n      \n      have lem := zmod.euler_criterion 3 two_not_zero,\n      {\n        have two_not_euler_right : \u00ac ((2 : zmod 3)^(3/2) = 1):= by dec_trivial,\n        rw \u2190 not_iff_not at lem,\n        rw \u2190 lem at two_not_euler_right,\n        sorry,\n      },\n    }, sorry,\n  },\n  sorry,\n  },\nend", "meta": {"author": "lcenek21", "repo": "PPT-Properties", "sha": "64aa68179bf8bacafac2c768929d2a959226266b", "save_path": "github-repos/lean/lcenek21-PPT-Properties", "path": "github-repos/lean/lcenek21-PPT-Properties/PPT-Properties-64aa68179bf8bacafac2c768929d2a959226266b/my_project/src/PPT_properties.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.7090318567816295}}
{"text": "/-\nTODO: Add copyright information\nTODO: Add proper documentations\nTODO: Decide where to put this file\n-/\n\nimport algebra.geom_sum\nimport data.finset.basic\nimport data.nat.prime\nimport number_theory.arithmetic_function\nimport number_theory.divisors\nimport number_theory.lucas_lehmer\nimport tactic\n\n/-\nBelow are results leading up to Euclid-Euler Theorem\n-/\n\nopen finset\nopen nat.arithmetic_function\nopen_locale arithmetic_function\nopen_locale big_operators\n\n-- Lemma that allows us to cast mersenne numbers to integers\nlemma coe_mersenne {n : \u2115} : (mersenne n : \u2124) = (2 : \u2124) ^ n - 1 :=\nbegin\n  simp [mersenne],\nend\n\nlemma mersenne_inc {m n : \u2115} (h : m < n) : mersenne m < mersenne n :=\nbegin\n  suffices : (mersenne m : \u2124) < mersenne n,\n  { exact_mod_cast this, },\n  simp [coe_mersenne],\n  exact pow_lt_pow one_lt_two h,\nend\n\n-- Thank you to Kevin Buzzard, Niels Voss and Ya\u00ebl Dillies for helping with this!\nlemma mersenne_div {m n : \u2115} (h : m \u2223 n) : mersenne m \u2223 mersenne n :=\nbegin\n  rcases h with \u27e8k, rfl\u27e9,\n  simpa only [mersenne, pow_mul, one_pow] using nat_sub_dvd_pow_sub_pow _ 1 _,\nend\n\n-- set_option pp.all true\n\n-- 2^n - 1 is Mersenne prime implies n is prime\ntheorem mersenne_theorem {n : \u2115} (h : nat.prime (mersenne n)) : nat.prime n :=\nbegin\n  -- Auxillary lemma\n  have two_le_n : 2 \u2264 n,\n  {\n    by_contradiction h',\n    push_neg at h',\n\n    cases nat.lt_succ_iff.1 h' with _ h',\n    { simp [mersenne, nat.not_prime_one] at h, exact h, },\n    { simp [mersenne, nat.eq_zero_of_le_zero h', nat.not_prime_zero] at h, exact h, }\n  },\n\n  -- Assume n is composite\n  by_contradiction n_comp,\n  rcases nat.exists_dvd_of_not_prime two_le_n n_comp with \u27e8d, d_dvd, d_ne_one, d_ne_n\u27e9,\n\n  have d_pos : 0 < d,\n  { by_contradiction, simp at h, rw h at d_dvd, rw zero_dvd_iff at d_dvd, linarith, },\n  have two_le_d : 2 \u2264 d,\n  { cases d, omega, cases d; omega,},\n\n  -- Then mersenne n is not prime\n  rcases mersenne_div d_dvd with \u27e8md, hmd\u27e9,\n  suffices : \u00acnat.prime (mersenne n),\n  { exact this h, },\n\n  -- We cast to int for easier life\n  apply nat.not_prime_mul' hmd.symm,\n  {\n    have : (2 : \u2124) ^ 1 < 2 ^ d,\n    { exact pow_lt_pow one_lt_two two_le_d, },\n    have : (1 : \u2124) < (mersenne d : \u2124),\n    { simp [coe_mersenne], linarith, },\n    exact_mod_cast this,\n  },\n  {\n    have : mersenne d < mersenne n,\n    { apply mersenne_inc, exact lt_iff_le_and_ne.2 \u27e8nat.le_of_dvd (by linarith) d_dvd, d_ne_n\u27e9, },\n    simp [hmd] at this,\n    exact (lt_mul_iff_one_lt_right (mersenne_pos d_pos)).1 this,\n  }\nend\n\nlemma sigma_two_pow_eq_mersenne_succ (k : \u2115) : \u03c3 1 (2 ^ k) = 2 ^ (k + 1) - 1 :=\nbegin\n  simp [sigma_one_apply, nat.prime_two, \u2190 geom_sum_mul_add 1 (k+1)],\nend\n\n-- Euclid-Euler Theorem\ntheorem euclid_euler {n : \u2115} :\nnat.perfect n \u2227 even n \u2194\n(\u2203 (p : \u2115), nat.prime (2 ^ p - 1) \u2227 n = 2 ^ (p - 1) * (2 ^ p - 1)) :=\nbegin\n  split,\n\n  -- If n is perfect and even, then\n  -- n = 2^(p - 1) (2^p - 1) and (2^p - 1) is prime\n  {\n    contrapose!,\n    intro h,\n    contrapose!,\n    intro n_even,\n    sorry\n  },\n  {\n    -- If (2^p - 1) is prime, then n = 2^(p - 1) (2^p - 1) is perfect and even\n    rintros \u27e8p, hp, hn\u27e9,\n    let n\u2081 := 2 ^ (p - 1),\n    let n\u2082 := 2 ^ p - 1,\n    have n\u2082_pos : 1 \u2264 2 ^ p, { exact nat.one_le_two_pow p, },\n    have hpr : nat.prime p, { exact mersenne_theorem hp, },\n\n    split,\n    {\n      have h\u2082 : n\u2081.coprime n\u2082, { sorry },\n      have h : \u03c3 1 n = \u03c3 1 n\u2081 * \u03c3 1 n\u2082,\n      { rw [hn, is_multiplicative.map_mul_of_coprime is_multiplicative_sigma h\u2082], },\n      have h\u03c3\u2081 : \u2200 (n : \u2115), \u03c3 1 (2 ^ n) = 2 ^ (n + 1) - 1,\n      {\n        intro n,\n        simp [sigma_one_apply, nat.prime_two, \u2190 geom_sum_mul_add 1 (n + 1)],\n      },\n      have h\u03c3\u2082 : \u2200 (p : \u2115), nat.prime p \u2192 \u03c3 1 p = 1 + p,\n      {\n        intros p hpr,\n        simp [sigma_one_apply, hpr, add_comm],\n      },\n      rw nat.perfect_iff_sum_divisors_eq_two_mul,\n\n      -- I plan to make evaluating arithmetic functions easier\n      rw [\u2190 sigma_one_apply, h, h\u03c3\u2081 (p - 1), nat.sub_add_cancel (nat.prime.pos hpr)],\n      simp [h\u03c3\u2082 n\u2082 hp, n\u2082, \u2190 nat.add_sub_assoc n\u2082_pos, hn, \u2190 nat.pow_div (nat.prime.pos hpr)],\n      rw [\u2190 nat.mul_assoc, nat.mul_div_cancel', mul_comm],\n      apply nat.dvd_of_pow_dvd (nat.prime.pos hpr) (dvd_refl _),\n\n      -- Prove n > 0\n      simp [hn],\n      apply nat.le_self_pow (nat.prime.ne_zero hpr) 2,\n    },\n    {\n      -- If (2^p - 1) is prime, then n = 2^(p - 1) (2^p - 1) is even\n      simp [hn, n\u2081, n\u2082] with parity_simps,\n      left,\n      exact nat.prime.two_le hpr,\n    },\n  },\nend", "meta": {"author": "grhkm21", "repo": "lean", "sha": "52fe0ba1b5c78344c640b0813f11db71338fcba2", "save_path": "github-repos/lean/grhkm21-lean", "path": "github-repos/lean/grhkm21-lean/lean-52fe0ba1b5c78344c640b0813f11db71338fcba2/src/euclid_euler.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7089978345123245}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\nimport data.zmod.algebra\nimport number_theory.wilson\n\nopen_locale big_operators\n\n/-\n\n## -1 is a square mod p if p=1 mod 4\n\nI formalise the following constructive proof in the solutions: ((p-1)/2)! works!\nWhy does it work: claim 1*2*...*(p-1)/2 squared is -1\n1*2*....*(p-1)/2 -- p is 1 mod 4 so this is also\n-1 * -2 * ... * -((p-1)/2), and mod p this is the same\n(p-1) * (p-2) * ... ((p+1)/2), so i^2=1*2*....*(p-2)*(p-1)=(p-1)!\nWilson's theorem tels us that (p-1)! = -1 mod p if p is prime.\n\n-/\n\nlemma exists_sqrt_neg_one_of_one_mod_four (p : \u2115) (hp : p.prime) \n  (hp2 : \u2203 n, p = 4 * n + 1) : \u2203 i : zmod p, i^2 = -1 :=\nbegin\n  sorry,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section15number_theory/sheet8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.7089978230561208}}
{"text": "\n\n-- TOOD: Cylic is sent to Cyclic\n-- TODO: Dihedral is sent to Dihedral (x C2)\n\n\n\nimport pq_to_group\n\nimport algebra.group\nimport data.zmod.basic\nimport data.int.parity\n\nuniverses u v\n\nsection cyclic_pq_group\n\n\n@[ext] structure cyclic (n : nat) :=\n(val : zmod n)\n\nvariables {n : nat}\n\ndef cyclic_mul : cyclic n \u2192 cyclic n \u2192 cyclic n\n| \u27e8a\u27e9 \u27e8b\u27e9 := \u27e8a + b\u27e9\n\ndef cyclic_inv : cyclic n \u2192 cyclic n\n| \u27e8a\u27e9 := \u27e8-a\u27e9\n\ninstance cyclic_has_mul : has_mul (cyclic n) := \u27e8cyclic_mul\u27e9\n\ninstance cyclic_has_neg : has_inv (cyclic n) := \u27e8cyclic_inv\u27e9 \n\ninstance cyclic_has_one : has_one (cyclic n) := \u27e8\u27e80\u27e9\u27e9\n\n\nlemma cyclic_mul_def (a b : zmod n) : (\u27e8a\u27e9 * \u27e8b\u27e9 : cyclic n) = \u27e8a + b\u27e9 := rfl\n\nlemma cyclic_inv_def (a : zmod n) : (\u27e8a\u27e9\u207b\u00b9 : cyclic n) = \u27e8-a\u27e9 := rfl\n\nlemma cyclic_one_def : (1 : cyclic n) = \u27e80\u27e9 := rfl\n\n\ninstance cyclic_comm_group : comm_group (cyclic n) :=\n{\n    mul_assoc := begin\n        rintros \u27e8a\u27e9 \u27e8b\u27e9 \u27e8c\u27e9,\n        repeat {rw cyclic_mul_def},\n        apply congr_arg,\n        apply add_assoc,\n    end,\n    one_mul := begin\n        rintro \u27e8a\u27e9,\n        rw cyclic_one_def,\n        rw cyclic_mul_def,\n        apply congr_arg,\n        apply zero_add,\n    end,\n    mul_one := begin\n        rintro \u27e8a\u27e9,\n        rw cyclic_one_def,\n        rw cyclic_mul_def,\n        apply congr_arg,\n        apply add_zero,\n    end,\n    mul_left_inv := begin\n        rintro \u27e8a\u27e9,\n        rw cyclic_inv_def,\n        rw cyclic_mul_def,\n        rw cyclic_one_def,\n        apply congr_arg,\n        apply add_left_neg,\n    end,\n    mul_comm := begin\n        intros a b,\n        cases a,\n        cases b,\n        rw cyclic_mul_def,\n        rw cyclic_mul_def,\n        apply congr_arg,\n        exact add_comm a b,\n    end,\n    ..cyclic_has_mul,\n    ..cyclic_has_neg,\n    ..cyclic_has_one,\n}\n\nlemma one_val : (1 : (cyclic n)).val = 0 := rfl\n\ndef generator : (cyclic n) := \u27e81\u27e9 \n\nlemma cyclic_as_power (x : cyclic n) : \u2203 k : int, x = generator^k :=\nbegin\n    induction x,\n    use (zmod.val_min_abs x),\n    --simp at *,\n    have gen_pow : \u2200 k : int, (\u27e8k\u27e9 : cyclic n) = generator ^ k,\n    {\n        intro k,\n        induction k,\n        {\n            induction k with l hl,\n            {\n                refl,\n            },\n            {\n                simp at *,\n                rw gpow_add_one,\n                simp,\n                rw \u2190hl,\n                refl,\n            },\n        },\n        {\n            induction k with l hl,\n            {\n                simp,\n                refl,\n            },\n            {\n                simp at *,\n                rw pow_succ,\n                simp,\n                rw \u2190hl,\n                apply congr_arg,\n                ring,\n            },\n        },\n    },\n    have h := gen_pow (x.val_min_abs),\n    simp at h,\n    assumption,\nend\n\n\nlemma cyclic_counit_form : function.surjective (of : (cyclic n) \u2192 pq_group (cyclic n)) :=\nbegin\n    intro x,\n    induction x,\n    {\n        induction x,\n        {\n            use 1,\n            apply quotient.sound,\n            fconstructor,\n            apply pre_pq_group_rel'.pow_zero,\n            exact 1,\n        },\n        {\n            use x,\n            refl,\n        },\n        {\n            cases x_ih_a with a ha,\n            cases x_ih_b with b hb,\n            use (a * b),\n            --apply quotient.sound,\n            have ha2 := cyclic_as_power a,\n            have hb2 := cyclic_as_power b,\n            cases ha2 with k hk,\n            cases hb2 with l hl,\n            rw hk,\n            rw hl,\n            rw \u2190gpow_add,\n            rw of_pow_eq_pow_of,\n            have hr : quot.mk setoid.r (x_a.mul x_b) = ((quot.mk setoid.r x_a) * (quot.mk setoid.r x_b) : pq_group (cyclic n)),\n            {\n                refl,\n            },\n            rw hr,\n            rw \u2190ha,\n            rw \u2190hb,\n            rw hk,\n            rw hl,\n            rw of_pow_eq_pow_of,\n            rw of_pow_eq_pow_of,\n            rw \u2190gpow_add,\n        },\n        {\n            cases x_ih with y hy,\n            use (y ^ (-1 : int)),\n            rw of_pow_eq_pow_of,\n            rw hy,\n            simp,\n            refl,\n        },\n    },\n    {refl,},\nend\n\n\ntheorem cyclic_counit_bijective : function.bijective (counit : pq_group (cyclic n) \u2192 cyclic n) :=\nbegin\n    split,\n    {\n        intros x y,\n        intro hxy,\n        have hx := cyclic_counit_form x,\n        have hy := cyclic_counit_form y,\n        cases hx with xx hxx,\n        cases hy with yy hyy,\n        rw \u2190hxx at *,\n        rw \u2190hyy at *,\n        apply congr_arg,\n        repeat {rw counit_of at hxy},\n        assumption,\n    },\n    {\n        apply counit_surjective,\n    }\nend\n\n\nnoncomputable theorem comonad_cyclic_iso : pq_group (cyclic n) \u2243* cyclic n :=\nbegin\n    fapply mul_equiv.of_bijective,\n    exact counit,\n    exact cyclic_counit_bijective,\nend\n\n\nend cyclic_pq_group\n\n\nsection klein_pq_group\n\nlocal notation `C2` := (cyclic 2)\n\nlocal notation `K` := C2 \u00d7 C2\n\nlocal notation `g` := (\u27e81\u27e9 : C2) \n\nlemma cyclic2cases {p : cyclic 2 \u2192 Prop} (a : cyclic 2) (h0 : p 1) (h1 : p generator) : p a :=\nbegin\n    cases a,\n    cases a with a ha,\n    cases a,\n    {\n        exact h0,\n    },\n    {\n        cases a,\n        {\n            exact h1,\n        },\n        {\n            exfalso,\n            norm_num at ha,\n            have ha' := nat.lt_of_succ_lt_succ (nat.lt_of_succ_lt_succ ha),\n            exact nat.not_lt_zero a ha',\n        }\n    }\nend\n\n-- Stupid lemma\nlemma not_zero_eq_one (c : zmod 2) (hc0 : c \u2260 0) : c = 1 := \nbegin\n    by_contradiction hc1,\n    {\n        cases c with c hc,\n        cases c,\n        {\n            apply hc0,\n            refl,\n        },\n        {\n            cases c,\n            {\n                apply hc1,\n                refl,\n            },\n            {\n                clear hc0 hc1,\n                norm_num at hc,\n                have hc' := nat.lt_of_succ_lt_succ (nat.lt_of_succ_lt_succ hc),\n                exact nat.not_lt_zero c hc'\n            },\n        }\n    }\nend\n\n-- Stupid lemma\nlemma not_one_eq_zero (c : zmod 2) (hc1 : c \u2260 1) : c = 0 := \nbegin\n    by_contradiction hc0,\n    {\n        cases c with c hc,\n        cases c,\n        {\n            apply hc0,\n            refl,\n        },\n        {\n            cases c,\n            {\n                apply hc1,\n                refl,\n            },\n            {\n                clear hc0 hc1,\n                norm_num at hc,\n                have hc' := nat.lt_of_succ_lt_succ (nat.lt_of_succ_lt_succ hc),\n                exact nat.not_lt_zero c hc'\n            },\n        }\n    }\nend\n\nlemma pqK_of_commute (a b : K) : (of a) * (of b) = (of b) * (of a) :=\nbegin\n    apply pq_group_commute,\n    unfold commute,\n    unfold semiconj_by,\n    cases a with a1 a2;\n    cases b with b1 b2;\n    apply cyclic2cases a1;\n    apply cyclic2cases a2;\n    apply cyclic2cases b1;\n    apply cyclic2cases b2;\n    refl,\nend\n\nlemma pqK_commute (a b : pq_group K) : a * b = b * a :=\nbegin\n    induction a,\n    {\n        rw quot_mk_helper,\n        induction a,\n        {\n            rw incl_unit_eq_unit,\n            simp,\n        },\n        {\n            induction b,\n            {\n                rw quot_mk_helper,\n                induction b,\n                {\n                    rw incl_unit_eq_unit,\n                    simp,\n                },\n                {\n                    apply pqK_of_commute,\n                },\n                {\n                    rw \u2190mul_def,\n                    rw mul_assoc,\n                    rw \u2190b_ih_b,\n                    rw \u2190mul_assoc,\n                    rw b_ih_a,\n                    rw mul_assoc,\n                },\n                {\n                    rw \u2190inv_def,\n                    apply commute.inv_right,\n                    exact b_ih,\n                },\n            },\n            {refl,},\n        },\n        {\n            rw \u2190mul_def,\n            rw mul_assoc,\n            rw a_ih_b,\n            rw \u2190mul_assoc,\n            rw a_ih_a,\n            rw mul_assoc,\n        },\n        {\n            rw \u2190inv_def,\n            apply commute.inv_left,\n            exact a_ih,\n        }\n    },\n    {refl,},\nend\n\nlemma C2_self_mul (a : C2) : a * a = 1 :=\nbegin\n    apply cyclic2cases a;\n    refl,\nend\n\nlemma C2_inv_is_self (a : C2) : a\u207b\u00b9 = a :=\nbegin\n    apply cyclic2cases a;\n    refl,\nend\n\nlemma K_self_mul (a : K) : a * a = 1 := \nbegin\n    cases a with a b,\n    apply cyclic2cases a;\n    apply cyclic2cases b;\n    refl,\nend\n\nlemma pqK_self_mul (a : pq_group K) : a * a = 1 :=\nbegin\n    induction a,\n    {\n        rw quot_mk_helper,\n        induction a,\n        {\n            apply quotient.sound,\n            fconstructor,\n            apply pre_pq_group_rel'.mul_one,\n        },\n        {\n            rw \u2190pow_two,\n            rw \u2190gpow_of_nat,\n            rw \u2190of_def,\n            rw \u2190of_pow_eq_pow_of a (int.of_nat 2),\n            rw gpow_of_nat,\n            rw pow_two,\n            rw K_self_mul,\n            rw of_1_eq_unit,\n        },\n        {\n            rw \u2190mul_def,\n            have rw_order : \u2200 c d : pq_group K, commute c d \u2192 c * d * (c * d) = c * c * (d * d),\n            {\n                intros c d hcd,\n                have paren_rw : \u2200 (a1 a2 a3 a4 : pq_group K), a1 * a2 * (a3 * a4) = a1 * (a2 * a3) * a4,\n                {\n                    intros a1 a2 a3 a4,\n                    group,\n                },\n                unfold commute at hcd,\n                unfold semiconj_by at hcd,\n                rw paren_rw,\n                rw \u2190hcd,\n                rw \u2190paren_rw,\n            },\n            rw rw_order,\n            rw a_ih_a,\n            rw a_ih_b,\n            rw mul_one,\n            apply pqK_commute,\n        },\n        {\n            rw \u2190inv_def,\n            refine inv_inj.mp _,\n            simp,\n            exact a_ih,\n        }\n    },\n    {refl,},\nend\n\n\nlemma Kpow2k : \u2200 a : K, \u2200 k : int, a^(2*k) = 1 :=\nbegin\n    intros a k,\n    rw mul_comm,\n    rw gpow_mul,\n    rw gpow_bit0,\n    rw K_self_mul,\nend\n\n\nlemma Kpow2kplus1 : \u2200 a : K, \u2200 k : int, a^(2*k + 1) = a :=\nbegin\n    intros a k,\n    rw gpow_add_one,\n    rw Kpow2k,\n    simp only [one_mul],\nend\n\n\nlemma Kpow2kminus1 : \u2200 a : K, \u2200 k : int, a^(2*k - 1) = a :=\nbegin\n    intros a k,\n    have n_rw : 2 * k - 1 = 2*(k - 1) + 1,\n    {\n        ring,\n    },\n    rw n_rw,\n    rw Kpow2kplus1,\nend\n\n\nopen pre_pq_group\n\ndef f_pre_on_C2_fun : pre_pq_group K \u2192 C2\n| unit := 1\n| (incl (a, b)) := if (a.val = 1 \u2227 b.val = 1) then g else 1\n| (mul a b) := f_pre_on_C2_fun a * f_pre_on_C2_fun b\n| (inv a) := (f_pre_on_C2_fun a)\u207b\u00b9\n\nlemma f_pre_on_C2_fun_unit : f_pre_on_C2_fun (unit) = 1 := rfl\nlemma f_pre_on_C2_fun_incl (a b : C2) : f_pre_on_C2_fun (incl (a, b)) = (if (a.val = 1 \u2227 b.val = 1) then g else 1) := rfl\nlemma f_pre_on_C2_fun_mul (a b : pre_pq_group K) : f_pre_on_C2_fun (mul a b) = f_pre_on_C2_fun a * f_pre_on_C2_fun b := rfl\nlemma f_pre_on_C2_fun_inv (a : pre_pq_group K) : f_pre_on_C2_fun (inv a) = (f_pre_on_C2_fun a)\u207b\u00b9 := rfl\n\n\ndef f_on_C2_fun : pq_group K \u2192 C2 := quotient.lift f_pre_on_C2_fun (begin\n    intros a b,\n    intro hab,\n    induction hab with c d habr,\n    clear a,\n    clear b,\n    induction habr,\n    {\n        refl,\n    },\n    {\n        apply eq.symm,\n        assumption,\n    },\n    {\n        apply eq.trans habr_ih_hab habr_ih_hbc,\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        congr',\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        congr',\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        rw mul_assoc,\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        rw one_mul,\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        rw mul_one,\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        rw mul_left_inv,\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        simp only [mul_comm, inv_mul_cancel_left],\n        congr',\n        simp only [rhd_def_group, mul_comm, inv_mul_cancel_left],\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        --cases habr_a with a b,\n        --rw f_pre_on_C2_fun_incl,\n        by_cases (even habr_n),\n        {\n            unfold even at h,\n            cases h with k hk,\n            rw hk,\n            rw Kpow2k,\n            rw Kpow2kminus1,\n            rw C2_self_mul,\n            refl,\n        },\n        {\n            rw \u2190int.odd_iff_not_even at h,\n            unfold odd at h,\n            cases h with k hk,\n            rw hk,\n            simp only [add_sub_cancel],\n            rw Kpow2k,\n            rw Kpow2kplus1,\n            group,\n            refl,\n        }\n    },\n    {\n        unfold f_pre_on_C2_fun,\n        by_cases (even habr_n),\n        {\n            unfold even at h,\n            cases h with k hk,\n            rw hk,\n            rw Kpow2k,\n            rw Kpow2kplus1,\n            group,\n            refl,\n        },\n        {\n            rw \u2190int.odd_iff_not_even at h,\n            unfold odd at h,\n            cases h with k hk,\n            rw hk,\n            rw Kpow2kplus1,\n            have n_rw : 2 * k + 1 + 1 = 2 * (k + 1),\n            {\n                ring,\n            },\n            rw n_rw,\n            rw Kpow2k,\n            have is_one : f_pre_on_C2_fun (incl 1) = 1,\n            {\n                refl,\n            },\n            rw is_one,\n            simp,\n            rw C2_inv_is_self,\n        }\n    },\n    {\n        refl,\n    },\nend) \n\n\nlemma f_on_C2_fun_unit : f_on_C2_fun (\u27e6unit\u27e7) = 1 := rfl\nlemma f_on_C2_fun_incl (a b : C2) : f_on_C2_fun (\u27e6incl (a, b)\u27e7) = (if (a.val = 1 \u2227 b.val = 1) then g else 1) := rfl\nlemma f_on_C2_fun_mul (a b : pre_pq_group K) : f_on_C2_fun (\u27e6mul a b\u27e7) = f_on_C2_fun \u27e6a\u27e7 * f_on_C2_fun \u27e6b\u27e7 := rfl\nlemma f_on_C2_fun_inv (a : pre_pq_group K) : f_on_C2_fun \u27e6inv a\u27e7 = (f_on_C2_fun \u27e6a\u27e7)\u207b\u00b9 := rfl\n\nlemma f_on_C2_fun_of (a b : C2) : f_on_C2_fun (of (a, b)) = (if (a.val = 1 \u2227 b.val = 1) then g else 1) := rfl\n\n\ndef f_on_KC2_fun : pq_group K \u2192 K \u00d7 C2\n| a := (counit a, f_on_C2_fun a)\n\n\ndef f_on_KC2 : pq_group K \u2192* K \u00d7 C2 := \u27e8f_on_KC2_fun, rfl, begin\n    intros x y,\n    unfold f_on_KC2_fun,\n    simp only [true_and, monoid_hom.map_mul, prod.mk.inj_iff, eq_self_iff_true, prod.mk_mul_mk],\n    induction x,\n    induction y,\n    {\n        refl,\n    },\n    {refl,},\n    {refl,},\nend\u27e9\n\n\n/--\n\nConstruction of inverse:\nf_on_KC2 (x) = (counit x, of (g, g) -> g, 1 otherwise)\n\nInverse:\nf_on_KC2_inv (a, b, c) = of(a, b) * (c = 1 -> (of(g, 1)of(1, g)of(g, g)))\n\nLet's test:\nWe test f_on_KC2 of f_on_KC2_inv\n(0, 0, 1) -> of(g, 1)of(1, g)of(g, g) -> (0, 0, 1)\n(1, 1, 1) -> of(g, g)of(g, 1)of(1, g)of(g, g) -> (1, 1, 0) WRONG!!!\n(1, 1, 0) -> of (1, 1) -> (1, 1, 1)\n\n-/\n\n\ndef f_on_KC2_inv_fun : K \u00d7 C2 \u2192 pq_group K\n| (a, b) := of(a.1, 1) * of (1, a.2) * (if (b.val = 0) then 1 else of (1, g) * of (g, 1) * of (g, g))\n\nlemma of_mul_C2_left (a b : C2) : of(a * b, (1 : C2)) = of(a, 1) * of(b, 1) :=\nbegin\n    apply cyclic2cases a,\n    {\n        have one_eq2 : ((1, 1) : K) = 1 := rfl,\n        rw one_eq2,\n        rw of_1_eq_unit,\n        simp only [mul_one, one_mul],\n    },\n    {\n        apply cyclic2cases b,\n        {\n            have one_eq2 : ((1, 1) : K) = 1 := rfl,\n            rw one_eq2,\n            rw of_1_eq_unit,\n            simp only [mul_one, one_mul],\n        },\n        {\n            rw pqK_self_mul,\n            rw C2_self_mul,\n            have one_eq2 : ((1, 1) : K) = 1 := rfl,\n            rw one_eq2,\n            rw of_1_eq_unit,\n        },\n    },\nend\n\nlemma of_mul_C2_right (a b : C2) : of((1 : C2), a * b) = of(1, a) * of(1, b) :=\nbegin\n    apply cyclic2cases a,\n    {\n        have one_eq2 : ((1, 1) : K) = 1 := rfl,\n        rw one_eq2,\n        rw of_1_eq_unit,\n        simp only [mul_one, one_mul],\n    },\n    {\n        apply cyclic2cases b,\n        {\n            have one_eq2 : ((1, 1) : K) = 1 := rfl,\n            rw one_eq2,\n            rw of_1_eq_unit,\n            simp only [mul_one, one_mul],\n        },\n        {\n            rw pqK_self_mul,\n            rw C2_self_mul,\n            have one_eq2 : ((1, 1) : K) = 1 := rfl,\n            rw one_eq2,\n            rw of_1_eq_unit,\n        },\n    },\nend\n\ndef f_on_KC2_inv : K \u00d7 C2 \u2192* pq_group K := \u27e8f_on_KC2_inv_fun, begin\n    have one_eq : ((1, 1) : K \u00d7 C2) = 1 := rfl,\n    rw \u2190one_eq,\n    unfold f_on_KC2_inv_fun,\n    rw if_pos,\n    swap, refl,\n    simp only [mul_one, prod.snd_one, prod.fst_one],\n    have one_eq2 : ((1, 1) : K) = 1 := rfl,\n    rw one_eq2,\n    rw of_1_eq_unit,\n    simp only [mul_one],\nend, begin\n    intros x y,\n    cases x with x1 x2,\n    cases y with y1 y2,\n    have mul_rw : (x1, x2) * (y1, y2) = (x1 * y1, x2 * y2) := rfl,\n    rw mul_rw,\n    clear mul_rw,\n    unfold f_on_KC2_inv_fun,\n    have reorder : \u2200 a b c d : pq_group K, a * b * (c * d) = a * c * (b * d),\n    {\n        intros a b c d,\n        have redo_paren : \u2200 a b c d : pq_group K, a * b * (c * d) = a * (b * c) * d,\n        intros a b c d, group,\n        rw redo_paren,\n        rw pqK_commute b c,\n        rw \u2190redo_paren, \n    },\n    apply cyclic2cases x2;\n    apply cyclic2cases y2;\n    clear x2 y2,\n    {\n        rw if_pos,\n        swap, refl,\n        rw if_pos,\n        swap, refl,\n        simp only [prod.snd_mul, prod.fst_mul, mul_one],\n        cases x1 with x11 x12,\n        cases y1 with y11 y12,\n        simp only,\n        rw of_mul_C2_left,\n        rw of_mul_C2_right,\n        rw reorder,\n    },\n    {\n        rw if_neg,\n        swap, unfold generator, simp,\n        rw if_pos,\n        swap, refl,\n        rw if_neg,\n        swap, unfold generator, simp,\n        simp only [prod.snd_mul, prod.fst_mul, mul_one],\n        cases x1 with x11 x12,\n        cases y1 with y11 y12,\n        simp only,\n        rw of_mul_C2_left,\n        rw of_mul_C2_right,\n        suffices : of (x11, 1) * of (y11, 1) * (of (1, x12) * of (1, y12)) = of (x11, 1) * of (1, x12) * (of (y11, 1) * of (1, y12)),\n        rw this, group,\n        rw reorder,\n    },\n    {\n        rw if_neg,\n        swap, unfold generator, simp,\n        rw if_neg,\n        swap, unfold generator, simp,\n        rw if_pos,\n        swap, refl,\n        simp only [prod.snd_mul, prod.fst_mul, mul_one],\n        cases x1 with x11 x12,\n        cases y1 with y11 y12,\n        simp only,\n        rw of_mul_C2_left,\n        rw of_mul_C2_right,\n        rw pqK_commute _ ((of (y11, 1) * of (1, y12))),\n        group,\n        rw pqK_commute _ (of (1, y12)),\n        group,\n        rw pqK_commute _ (of (y11, 1)),\n        group,\n    },\n    {\n        rw if_pos,\n        swap, refl,\n        rw if_neg,\n        swap, unfold generator, simp,\n        simp only [prod.snd_mul, prod.fst_mul, mul_one],\n        cases x1 with x11 x12,\n        cases y1 with y11 y12,\n        simp only,\n        rw of_mul_C2_left,\n        rw of_mul_C2_right,\n        let x : pq_group K := (of (1, {val := 1}) * of ({val := 1}, 1) * of ({val := 1}, {val := 1})),\n        have x_def : x = (of (1, {val := 1}) * of ({val := 1}, 1) * of ({val := 1}, {val := 1})) := rfl,\n        rw \u2190x_def,\n        rw pqK_commute (of (y11, 1) * of (1, y12)) x,\n        rw reorder,\n        suffices : of (x11, 1) * of (1, x12) * (of (y11, 1) * of (1, y12)) = of (x11, 1) * of (1, x12) * (x * x) * (of (y11, 1) * of (1, y12)),\n        rw this, group,\n        rw pqK_self_mul,\n        simp only [mul_one],\n    },\nend\u27e9 \n\n\ntheorem f_on_KC2_inv_f_on_KC2 : f_on_KC2_inv \u2218 f_on_KC2 = id :=\nbegin\n    funext,\n    simp only [id.def, function.comp_app],\n    induction x,\n    {\n        rw quot_mk_helper,\n        induction x,\n        {\n            unfold f_on_KC2,\n            simp,\n            unfold f_on_KC2_fun,\n            rw counit_unit,\n            rw f_on_C2_fun_unit,\n            unfold f_on_KC2_inv,\n            simp only [monoid_hom.coe_mk],\n            unfold f_on_KC2_inv_fun,\n            rw if_pos,\n            swap, refl,\n            simp only [mul_one, prod.fst_one, prod.snd_one],\n            have h1 : ((1, 1) : K) = 1 := rfl,\n            rw h1,\n            rw \u2190unit_eq_incl_1,\n            apply quotient.sound,\n            fconstructor,\n            apply pre_pq_group_rel'.mul_one,\n        },\n        {\n            unfold f_on_KC2,\n            simp,\n            unfold f_on_KC2_fun,\n            rw counit_incl,\n            cases x with a b,\n            rw f_on_C2_fun_incl,\n            by_cases (a.val = 1 \u2227 b.val = 1),\n            {\n                rw if_pos,\n                unfold f_on_KC2_inv,\n                simp only [monoid_hom.coe_mk],\n                unfold f_on_KC2_inv_fun,\n                rw if_neg,\n                {\n                    simp,\n                    cases h with ha hb,\n                    have ha1 : a = \u27e81\u27e9,\n                    ext, rw ha,\n                    have hb1 : b = \u27e81\u27e9,\n                    ext, rw hb,\n                    rw ha1,\n                    rw hb1,\n                    rw \u2190of_def,\n                    suffices : \u2200 a b c : pq_group K, a * b * (b * a * c) = c,\n                    apply this,\n                    intros a b c,\n                    have rw_order : a * b * (b * a * c) = (a * (b * b) * a) * c,\n                    group,\n                    rw rw_order,\n                    simp only [mul_one, mul_left_eq_self, pqK_self_mul],\n                },\n                simp,\n                exact h,\n            },\n            {\n                rw if_neg,\n                swap, assumption,\n                unfold f_on_KC2_inv,\n                simp only [monoid_hom.coe_mk],\n                unfold f_on_KC2_inv_fun,\n                rw if_pos,\n                swap, refl,\n                rw \u2190of_def,\n                simp only [mul_one],\n                by_cases ha1 : (a.val = 1),\n                {\n                    push_neg at h,\n                    specialize h ha1,\n                    have hb1 := not_one_eq_zero (b.val) h,\n                    have ha : a = \u27e81\u27e9,\n                    ext, rw ha1,\n                    have hb : b = 1,\n                    ext, rw hb1, refl,\n                    rw ha,\n                    rw hb,\n                    simp,\n                    have one_eq : ((1, 1) : K) = 1 := rfl,\n                    rw one_eq,\n                    rw of_1_eq_unit,\n                },\n                {\n                    clear h,\n                    have ha2 := not_one_eq_zero (a.val) ha1,\n                    have ha : a = 1,\n                    ext, rw ha2, refl,\n                    rw ha,\n                    simp only [mul_left_eq_self],\n                    have one_eq : ((1, 1) : K) = 1 := rfl,\n                    rw one_eq,\n                    rw of_1_eq_unit,\n                },\n            },\n        },\n        {\n            rw \u2190mul_def,\n            rw monoid_hom.map_mul,\n            rw monoid_hom.map_mul,\n            congr',\n        },\n        {\n            rw \u2190inv_def,\n            rw monoid_hom.map_inv,\n            rw monoid_hom.map_inv,\n            congr',\n        },\n    },\n    {refl,},\nend\n\ntheorem f_on_KC2_f_on_KC2_inv : f_on_KC2 \u2218 f_on_KC2_inv = id :=\nbegin\n    funext,\n    simp only [id.def, function.comp_app],\n    cases x with y c,\n    by_cases (c.val = 0),\n    {\n        unfold f_on_KC2_inv,\n        simp only [monoid_hom.coe_mk],\n        unfold f_on_KC2_inv_fun,\n        rw if_pos,\n        swap, exact h,\n        unfold f_on_KC2,\n        simp,\n        unfold f_on_KC2_fun,\n        rw counit_of,\n        rw counit_of,\n        rw f_on_C2_fun_of,\n        rw if_neg,\n        swap, push_neg, intro, rw one_val, norm_num,\n        rw f_on_C2_fun_of,\n        rw if_neg,\n        swap, push_neg, rw one_val, norm_num,\n        simp,\n        cases c,\n        simp at h,\n        rw h,\n        refl,\n    },\n    {\n        unfold f_on_KC2_inv,\n        simp only [monoid_hom.coe_mk],\n        unfold f_on_KC2_inv_fun,\n        rw if_neg,\n        swap, exact h,\n        unfold f_on_KC2,\n        simp,\n        unfold f_on_KC2_fun,\n        repeat {rw counit_of,},\n        repeat {rw f_on_C2_fun_of,},\n        rw if_neg,\n        swap, push_neg, rw one_val, norm_num,\n        rw if_neg,\n        swap, push_neg, rw one_val, norm_num,\n        rw if_neg,\n        swap, push_neg, rw one_val, norm_num,\n        rw if_neg,\n        swap, push_neg, rw one_val, norm_num,\n        rw if_pos,\n        swap, split, refl, refl,\n        simp,\n        split,\n        refl,\n        cases c,\n        simp at *,\n        apply eq.symm,\n        apply not_zero_eq_one c h,\n    },\nend\n\ntheorem klein_pq_group_iso_klein_c2 : pq_group K \u2243* K \u00d7 C2 := \n{ to_fun := f_on_KC2,\n  inv_fun := f_on_KC2_inv,\n  left_inv := congr_fun f_on_KC2_inv_f_on_KC2,\n  right_inv := congr_fun f_on_KC2_f_on_KC2_inv,\n  map_mul' := is_mul_hom.map_mul \u21d1f_on_KC2 }\n\n\nend klein_pq_group\n\n", "meta": {"author": "torstein-vik", "repo": "power-quandle-lean", "sha": "452437602c4be2e6c5ad5f5224b068baabfdf9e1", "save_path": "github-repos/lean/torstein-vik-power-quandle-lean", "path": "github-repos/lean/torstein-vik-power-quandle-lean/power-quandle-lean-452437602c4be2e6c5ad5f5224b068baabfdf9e1/src/comonad_comp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195635, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7089230142318865}}
{"text": "theorem contrapositive (P Q : Prop) : \n(P \u2192 Q) \u2192  (\u00ac Q \u2192 \u00ac P) := \n\u03bb HPQ HnQ HP, HnQ (HPQ HP)\n\n-- what about the converse?\ntheorem of_contrapositive (P Q : Prop) :\n (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n  intro H1,\n  intro HP,\n  cc,\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/lean_together/5_minutes_on_how_cool_constructive_logic_is/5_iff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7089229990776211}}
{"text": "example (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  intro h,\n  exact\n    have hp: p, from h.left,\n    have hqr: q \u2228 r, from h.right,\n    show (p \u2227 q) \u2228 (p \u2227 r),\n    begin\n      cases hqr with hq hr,\n        exact or.inl \u27e8hp, hq\u27e9,\n        exact or.inr \u27e8hp, hr\u27e9\n    end\nend\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch5/ex0401.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7089229877145311}}
{"text": "import ..exercises.love02_backward_proofs_exercise_sheet\n\n\n/-! # LoVe Homework 2: Backward Proofs\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\nnamespace backward_proofs\n\n\n/-! ## Question 1 (4 points): Connectives and Quantifiers\n\n1.1 (3 points). Complete the following proofs using basic tactics such as\n`intro`, `apply`, and `exact`.\n\nHint: Some strategies for carrying out such proofs are described at the end of\nSection 2.3 in the Hitchhiker's Guide. -/\n\nlemma B (a b c : Prop) :\n  (a \u2192 b) \u2192 (c \u2192 a) \u2192 c \u2192 b :=\nsorry\n\nlemma S (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 (a \u2192 b) \u2192 a \u2192 c :=\nsorry\n\nlemma more_nonsense (a b c : Prop) :\n  (c \u2192 (a \u2192 b) \u2192 a) \u2192 c \u2192 b \u2192 a :=\nsorry\n\nlemma even_more_nonsense (a b c : Prop) :\n  (a \u2192 a \u2192 b) \u2192 (b \u2192 c) \u2192 a \u2192 b \u2192 c :=\nsorry\n\n/-! 1.2 (1 point). Prove the following lemma using basic tactics. -/\n\nlemma weak_peirce (a b : Prop) :\n  ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\n\n/-! ## Question 2 (6 points): Logical Connectives\n\n2.1 (2 points). Prove the following properties about logical connectives using\nbasic tactics.\n\nHints:\n\n* Keep in mind that `\u00ac a` is the same as `a \u2192 false`. You can start by invoking\n  `rw not_def` if this helps you.\n\n* You will need to apply the elimination rules for `\u2228` and `false` at some\n  point. -/\n\nlemma about_implication (a b : Prop) :\n  \u00ac a \u2228 b \u2192 a \u2192 b :=\nsorry\n\nlemma about_negation (a b : Prop) : \n  a \u2192 \u00ac (\u00ac a \u2227 b) :=\nsorry \n\n/-! 2.2 (2 points). Prove the missing link in our chain of classical axiom\nimplications.\n\nHints:\n\n* You can use `rw double_negation` to unfold the definition of\n  `double_negation`, and similarly for the other definitions.\n\n* You will need to apply the double negation hypothesis for `a \u2228 \u00ac a`. You will\n  also need the left and right introduction rules for `\u2228` at some point. -/\n\n#check excluded_middle\n#check peirce\n#check double_negation\n\nlemma em_of_dn :\n  double_negation \u2192 excluded_middle :=\nsorry\n\n/-! 2.3 (2 points). We have proved three of the six possible implications\nbetween `excluded_middle`, `peirce`, and `double_negation`. State and prove the\nthree missing implications, exploiting the three theorems we already have. -/\n\n#check peirce_of_em\n#check dn_of_peirce\n#check em_of_dn\n\n-- enter your solution here\n\nend backward_proofs\n\n\n/-! ## Question 3 (3 points): Equality\n\nYou may hear it said that equality is the smallest *reflexive*, *symmetric*, \n*transitive* relation. The following exercise shows that in the presence of \nreflexivity, the rules for symmetry and transitivity are equivalent to a single\nrule, \"symmtrans\". -/\n\naxiom symmtrans {A : Type} {a b c : A} : a = b \u2192 c = b \u2192 a = c\n\n-- You can now use `symmtrans` as a rule.\n\nexample (A : Type) (a b c : A) (h1 : a = b) (h2 : c = b) : a = c :=\nbegin \n  apply symmtrans,\n  apply h1,\n  apply h2\nend \n\n\nsection\n\nvariable {A : Type}\nvariables {a b c : A}\n\n/-! Replace the `sorry`s below with proofs, using `symmtrans` and `rfl`, without\nusing `eq.symm` or `eq.trans`. -/\n\ntheorem my_symm (h : b = a) : a = b :=\nsorry\n\ntheorem my_trans (h1 : a = b) (h2 : b = c) : a = c :=\nsorry \n\nend\n\n/-! ## Question 4 (3 points): Pythagorean Triples\n\nRecall that a Pythagorean triple is a 'triple' of three natural numbers a, b,\nand c such that a\u00b2 + b\u00b2 = c\u00b2, i.e. integer sides of a right triangle.-/\n\ndef isPythagoreanTriple (a b c : \u2115) : Prop :=\n  a^2 + b^2 = c^2\n\n/- By assuming Fermat's Last Theorem\n(https://en.wikipedia.org/wiki/Fermat%27s_Last_Theorem), we can show that if\n`a`, `b`, and `c` form a Pythagorean triple, then `a`, `b`, and `c` can't all be\nperfect squares. Use the definitions below to prove this. -/\n\naxiom fermats_last_theorem (x y n : \u2115) :\n  (n \u2265 3) \u2192 \u00ac\u2203 (z : \u2115), x^n + y^n = z^n\n\ndef isSquare (n : \u2115) : Prop := \u2203 (u : \u2115), n = u^2\n\n-- You may use the following lemma in your proof.\nlemma square_square (a b c : \u2115) :\n  (a^2)^2 + (b^2)^2 = (c^2)^2 \u2192 a^4 + b^4 = c^4 := \nby intro h; rw [\u2190pow_mul, \u2190pow_mul, \u2190pow_mul] at h; exact h\n\n/-! Hints:\n* You can use `and.elim` to extract both terms from a conjunction.\n* If you have a hypothesis `h : a = b` and want to replace `b` with `a` in your\n  goal (instead of `a` with `b`), use `rw \u2190h` (note the `\u2190`).\n* You can use `dec_trivial` to prove that 4 \u2265 3.\n-/\n\ntheorem pythagoren_triple_not_all_squares (a b c : \u2115) :\n  isPythagoreanTriple a b c \u2192 \u00ac(isSquare a \u2227 isSquare b \u2227 isSquare c) :=\nsorry\n\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/homework/love02_backward_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.7088663204871787}}
{"text": "import MyNat.Definition\nnamespace MyNat\n/-!\n\n# Tutorial world\n\n## Level 2: The `rewrite` tactic\n\nThe `rewrite` tactic is the way to \"substitute in\" the value of a variable. In general, if you have a\nhypothesis of the form `A = B`, and your goal mentions the left hand side `A` somewhere, then the\nrewrite tactic will replace the `A` in your goal with a `B`. Below is a theorem which cannot be proved\nusing `rfl` -- you need a `rewrite` first.\n\nTake a look in the InfoView at what you have. The variables\n`x` and `y` are natural numbers, and there is a proof `h` that `y = x + 7`.\nYour goal then is to prove that `2y = 2(x + 7)`. This goal is obvious -- you just substitute in\n`y = x + 7` and you're done. In Lean, you do this substitution using the `rewrite` tactic.\n\n## Lemma\n\nIf `x` and `y` are natural numbers, and `y = x + 7`, then `2y = 2(x + 7)`.\n-/\nlemma example2 (x y : MyNat) (h : y = x + 7) : 2 * y = 2 * (x + 7) := by\n  rewrite [h]\n  rfl\n\n/-!\nDid you see what happened to the goal? (Put your cursor at the end of the `rewrite` line).\nThe goal doesn't close, but it *changes* from `\u22a2 2 * y = 2 * (x + 7)` to `\u22a2 2 * (x + 7) = 2 * (x + 7)`.\nAnd since these are now identical you can just close this goal with `rfl`.\n\nYou should now see \"Goals accomplished \ud83c\udf89\" (with cursor at the end of the `rfl` line).\nThe square brackets here is a `List` object\nbecause `rewrite` can rewrite using multiple hypotheses in sequence.\n\nIf you are reading this book online you can move the mouse over each bubble that is\nadded to the end of each line (that look like this: <span class=\"alectryon-bubble\"></span>)\nto see what the tactic state is at that point in the proof.\n\nThe other way you know the goal is complete is to look a the Visual Studio Code\nProblems list window, if there are no error saying \"unsolved goals\" then you are done.\n\nThe documentation for `rewrite` will appear when you hover the mouse over it. We have also included\na [Tactics Section](../Tactics.lean.md) that lists all the tactics we use in this tutorial.\n\nNow, Lean has another similar tactic named `rw` which does both the `rewrite`\nand the `rfl`.  Try changing to `rw` above and you will see the `rfl` is\nno longer needed.\n\n## Details\n\nNow you are ready for [Level3.lean](./Level3.lean.md).\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/TutorialWorld/Level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8670357683915537, "lm_q1q2_score": 0.7088663141838779}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport algebra.big_operators.basic\nimport data.finset.sym\n\n/-!\n# Stars and bars\n\nIn this file, we prove the case `n = 2` of stars and bars.\n\n## Informal statement\n\nIf we have `n` objects to put in `k` boxes, we can do so in exactly `(n + k - 1).choose n` ways.\n\n## Formal statement\n\nWe can identify the `k` boxes with the elements of a fintype `\u03b1` of card `k`. Then placing `n`\nelements in those boxes corresponds to choosing how many of each element of `\u03b1` appear in a multiset\nof card `n`. `sym \u03b1 n` being the subtype of `multiset \u03b1` of multisets of card `n`, writing stars\nand bars using types gives\n```lean\n-- TODO: this lemma is not yet proven\nlemma stars_and_bars {\u03b1 : Type*} [fintype \u03b1] (n : \u2115) :\n  card (sym \u03b1 n) = (card \u03b1 + n - 1).choose (card \u03b1) := sorry\n```\n\n## TODO\n\nProve the general case of stars and bars.\n\n## Tags\n\nstars and bars\n-/\n\nopen finset fintype\n\nnamespace sym2\nvariables {\u03b1 : Type*} [decidable_eq \u03b1]\n\n/-- The `diag` of `s : finset \u03b1` is sent on a finset of `sym2 \u03b1` of card `s.card`. -/\nlemma card_image_diag (s : finset \u03b1) : (s.diag.image quotient.mk).card = s.card :=\nbegin\n  rw [card_image_of_inj_on, diag_card],\n  rintro \u27e8x\u2080, x\u2081\u27e9 hx _ _ h,\n  cases quotient.eq.1 h,\n  { refl },\n  { simp only [mem_coe, mem_diag] at hx,\n    rw hx.2 }\nend\n\nlemma two_mul_card_image_off_diag (s : finset \u03b1) :\n  2 * (s.off_diag.image quotient.mk).card = s.off_diag.card :=\nbegin\n  rw [card_eq_sum_card_fiberwise\n    (\u03bb x, mem_image_of_mem _ : \u2200 x \u2208 s.off_diag, quotient.mk x \u2208 s.off_diag.image quotient.mk),\n    sum_const_nat (quotient.ind _), mul_comm],\n  rintro \u27e8x, y\u27e9 hxy,\n  simp_rw [mem_image, exists_prop, mem_off_diag, quotient.eq] at hxy,\n  obtain \u27e8a, \u27e8ha\u2081, ha\u2082, ha\u27e9, h\u27e9 := hxy,\n  obtain \u27e8hx, hy, hxy\u27e9 : x \u2208 s \u2227 y \u2208 s \u2227 x \u2260 y,\n  { cases h; have := ha.symm; exact \u27e8\u2039_\u203a, \u2039_\u203a, \u2039_\u203a\u27e9 },\n  have hxy' : y \u2260 x := hxy.symm,\n  have : s.off_diag.filter (\u03bb z, \u27e6z\u27e7 = \u27e6(x, y)\u27e7) = ({(x, y), (y, x)} : finset _),\n  { ext \u27e8x\u2081, y\u2081\u27e9,\n    rw [mem_filter, mem_insert, mem_singleton, sym2.eq_iff, prod.mk.inj_iff, prod.mk.inj_iff,\n      and_iff_right_iff_imp],\n    rintro (\u27e8rfl, rfl\u27e9 | \u27e8rfl, rfl\u27e9); rw mem_off_diag; exact \u27e8\u2039_\u203a, \u2039_\u203a, \u2039_\u203a\u27e9 }, -- hxy' is used here\n  rw [this, card_insert_of_not_mem, card_singleton],\n  simp only [not_and, prod.mk.inj_iff, mem_singleton],\n  exact \u03bb _, hxy',\nend\n\n/-- The `off_diag` of `s : finset \u03b1` is sent on a finset of `sym2 \u03b1` of card `s.off_diag.card / 2`.\nThis is because every element `\u27e6(x, y)\u27e7` of `sym2 \u03b1` not on the diagonal comes from exactly two\npairs: `(x, y)` and `(y, x)`. -/\nlemma card_image_off_diag (s : finset \u03b1) :\n  (s.off_diag.image quotient.mk).card = s.card.choose 2 :=\nby rw [nat.choose_two_right, mul_tsub, mul_one, \u2190off_diag_card,\n  nat.div_eq_of_eq_mul_right zero_lt_two (two_mul_card_image_off_diag s).symm]\n\nlemma card_subtype_diag [fintype \u03b1] :\n  card {a : sym2 \u03b1 // a.is_diag} = card \u03b1 :=\nbegin\n  convert card_image_diag (univ : finset \u03b1),\n  rw [fintype.card_of_subtype, \u2190filter_image_quotient_mk_is_diag],\n  rintro x,\n  rw [mem_filter, univ_product_univ, mem_image],\n  obtain \u27e8a, ha\u27e9 := quotient.exists_rep x,\n  exact and_iff_right \u27e8a, mem_univ _, ha\u27e9,\nend\n\nlemma card_subtype_not_diag [fintype \u03b1] :\n  card {a : sym2 \u03b1 // \u00aca.is_diag} = (card \u03b1).choose 2 :=\nbegin\n  convert card_image_off_diag (univ : finset \u03b1),\n  rw [fintype.card_of_subtype, \u2190filter_image_quotient_mk_not_is_diag],\n  rintro x,\n  rw [mem_filter, univ_product_univ, mem_image],\n  obtain \u27e8a, ha\u27e9 := quotient.exists_rep x,\n  exact and_iff_right \u27e8a, mem_univ _, ha\u27e9,\nend\n\n/-- Finset **stars and bars** for the case `n = 2`. -/\nlemma _root_.finset.card_sym2 (s : finset \u03b1) : s.sym2.card = s.card * (s.card + 1) / 2 :=\nbegin\n  rw [\u2190image_diag_union_image_off_diag, card_union_eq, sym2.card_image_diag,\n    sym2.card_image_off_diag, nat.choose_two_right, add_comm, \u2190nat.triangle_succ, nat.succ_sub_one,\n    mul_comm],\n  rintro m he,\n  rw [inf_eq_inter, mem_inter, mem_image, mem_image] at he,\n  obtain \u27e8\u27e8a, ha, rfl\u27e9, b, hb, hab\u27e9 := he,\n  refine not_is_diag_mk_of_mem_off_diag hb _,\n  rw hab,\n  exact is_diag_mk_of_mem_diag ha,\nend\n\n/-- Type **stars and bars** for the case `n = 2`. -/\nprotected lemma card [fintype \u03b1] : card (sym2 \u03b1) = card \u03b1 * (card \u03b1 + 1) / 2 := finset.card_sym2 _\n\nend sym2\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/sym/card.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7088663036332729}}
{"text": "import .love02_backward_proofs_exercise_sheet\n\n\n/- # LoVe Homework 3: Forward Proofs\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1 (6 points + 1 bonus point): Connectives and Quantifiers\n\n1.1 (2 points). We have proved or stated three of the six possible implications\nbetween `excluded_middle`, `peirce`, and `double_negation`. Prove the three\nmissing implications using structured proofs, exploiting the three theorems we\nalready have. -/\n\nnamespace backward_proofs\n\n#check peirce_of_em\n#check dn_of_peirce\n#check sorry_lemmas.em_of_dn\n\nlemma peirce_of_dn :\n  double_negation \u2192 peirce :=\nsorry\n\nlemma em_of_peirce :\n  peirce \u2192 excluded_middle :=\nsorry\n\nlemma dn_of_em :\n  excluded_middle \u2192 double_negation :=\nsorry\n\nend backward_proofs\n\n/- 1.2 (4 points). Supply a structured proof of the commutativity of `\u2227` under\nan `\u2203` quantifier, using no other lemmas than the introduction and elimination\nrules for `\u2203`, `\u2227`, and `\u2194`. -/\n\nlemma exists_and_commute {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2203x, p x \u2227 q x) \u2194 (\u2203x, q x \u2227 p x) :=\nsorry\n\n/- 1.3 (1 bonus point). Supply a structured proof of the following property,\nwhich can be used pull a `\u2200`-quantifier past an `\u2203`-quantifier. -/\n\nlemma forall_exists_of_exists_forall {\u03b1 : Type} (p : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2203x, \u2200y, p x y) \u2192 (\u2200y, \u2203x, p x y) :=\nsorry\n\n\n/- ## Question 2 (3 points): Fokkink Logic Puzzles\n\nIf you have studied \"Logic and Sets\" with Prof. Fokkink, you will know he is\nvery fond of logic puzzles. This question is meant as a tribute.\n\nRecall the following tactical proof: -/\n\nlemma weak_peirce :\n  \u2200a b : Prop, ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nbegin\n  intros a b habaab,\n  apply habaab,\n  intro habaa,\n  apply habaa,\n  intro ha,\n  apply habaab,\n  intro haba,\n  apply ha\nend\n\n/- 2.1 (1 point). Prove the same lemma again, this time by providing a proof\nterm.\n\nHint: There is an easy way. -/\n\nlemma weak_peirce\u2082 :\n  \u2200a b : Prop, ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\n/- 2.2 (2 points). Prove the same Fokkink lemma again, this time by providing a\nstructured proof, with `assume`s and `show`s. -/\n\nlemma weak_peirce\u2083 :\n  \u2200a b : Prop, ((((a \u2192 b) \u2192 a) \u2192 a) \u2192 b) \u2192 b :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love03_forward_proofs_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7088662996165007}}
{"text": "import mynat.le -- import definition of \u2264\nimport game.world9.level4 -- hide\nimport game.world4.level8 -- hide\nnamespace mynat -- hide\n/- Axiom : le_iff_exists_add (a b : mynat)\n  a \u2264 b \u2194 \u2203 (c : mynat), b = a + c\n-/\n\n/- Tactic : use\n## Summary\n\n`use` works on the goal. If your goal is `\u22a2 \u2203 c : mynat, 1 + x = x + c`\nthen `use 1` will turn the goal into `\u22a2 1 + x = x + 1`, and the rather\nmore unwise `use 0` will turn it into the impossible-to-prove\n`\u22a2 1 + x = x + 0`.\n\n## Details\n\n`use` is a tactic which works on goals of the form `\u22a2 \u2203 c, P(c)` where\n`P(c)` is some proposition which depends on `c`. With a goal of this\nform, `use 0` will turn the goal into `\u22a2 P(0)`, `use x + y` (assuming\n`x` and `y` are natural numbers in your local context) will turn\nthe goal into `P(x + y)` and so on.\n-/\n\n/- \n\n# Inequality world. \n\nA new import, giving us a new definition. If `a` and `b` are naturals,\n`a \u2264 b` is *defined* to mean\n\n`\u2203 (c : mynat), b = a + c`\n\nThe upside-down E means \"there exists\". So in words, $a\\le b$\nif and only if there exists a natural $c$ such that $b=a+c$. \n\nIf you really want to change an `a \u2264 b` to `\u2203 c, b = a + c` then\nyou can do so with `rw le_iff_exists_add`:\n\n```\nle_iff_exists_add (a b : mynat) :\n  a \u2264 b \u2194 \u2203 (c : mynat), b = a + c\n```\n\nBut because `a \u2264 b` is *defined as* `\u2203 (c : mynat), b = a + c`, you\ndo not need to `rw le_iff_exists_add`, you can just pretend when you see `a \u2264 b`\nthat it says `\u2203 (c : mynat), b = a + c`. You will see a concrete\nexample of this below.\n\nA new construction like `\u2203` means that we need to learn how to manipulate it.\nThere are two situations. Firstly we need to know how to solve a goal\nof the form `\u22a2 \u2203 c, ...`, and secondly we need to know how to use a hypothesis\nof the form `\u2203 c, ...`. \n\n## Level 1: the `use` tactic.\n\nThe goal below is to prove $x\\le 1+x$ for any natural number $x$. \nFirst let's turn the goal explicitly into an existence problem with\n\n`rw le_iff_exists_add,`\n\nand now the goal has become `\u2203 c : mynat, 1 + x = x + c`. Clearly\nthis statement is true, and the proof is that $c=1$ will work (we also\nneed the fact that addition is commutative, but we proved that a long\ntime ago). How do we make progress with this goal?\n\nThe `use` tactic can be used on goals of the form `\u2203 c, ...`. The idea\nis that we choose which natural number we want to use, and then we use it.\nSo try\n\n`use 1,`\n\nand now the goal becomes `\u22a2 1 + x = x + 1`. You can solve this by\n`exact add_comm 1 x`, or if you are lazy you can just use the `ring` tactic,\nwhich is a powerful AI which will solve any equality in algebra which can\nbe proved using the standard rules of addition and multiplication. Now\nlook at your proof. We're going to remove a line.\n\n## Important\n\nAn important time-saver here is to note that because `a \u2264 b` is *defined*\nas `\u2203 c : mynat, b = a + c`, you *do not need to write* `rw le_iff_exists_add`.\nThe `use` tactic will work directly on a goal of the form `a \u2264 b`. Just\nuse the difference `b - a` (note that we have not defined subtraction so\nthis does not formally make sense, but you can do the calculation in your head).\nIf you have written `rw le_iff_exists_add` below, then just put two minus signs `--`\nbefore it and comment it out. See that the proof still compiles.\n-/\n\n/- Lemma : no-side-bar\nIf $x$ is a natural number, then $x\\le 1+x$.\n-/\nlemma one_add_le_self (x : mynat) : x \u2264 1 + x :=\nbegin\n  rw le_iff_exists_add,\n  use 1,\n  ring,\n\n\nend \nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world10/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.708760048090027}}
{"text": "/-\nCopyright (c) 2022 Kevin H. Wilson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin H. Wilson\n-/\nimport order.filter.prod\n\n/-!\n# Curried Filters\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides an operation (`filter.curry`) on filters which provides the equivalence\n`\u2200\u1da0 a in l, \u2200\u1da0 b in l', p (a, b) \u2194 \u2200\u1da0 c in (l.curry l'), p c` (see `filter.eventually_curry_iff`).\n\nTo understand when this operation might arise, it is helpful to think of `\u2200\u1da0` as a combination of\nthe quantifiers `\u2203 \u2200`. For instance, `\u2200\u1da0 n in at_top, p n \u2194 \u2203 N, \u2200 n \u2265 N, p n`. A curried filter\nyields the quantifier order `\u2203 \u2200 \u2203 \u2200`. For instance,\n`\u2200\u1da0 n in at_top.curry at_top, p n \u2194 \u2203 M, \u2200 m \u2265 M, \u2203 N, \u2200 n \u2265 N, p (m, n)`.\n\nThis is different from a product filter, which instead yields a quantifier order `\u2203 \u2203 \u2200 \u2200`. For\ninstance, `\u2200\u1da0 n in at_top \u00d7\u1da0 at_top, p n \u2194 \u2203 M, \u2203 N, \u2200 m \u2265 M, \u2200 n \u2265 N, p (m, n)`. This makes it\nclear that if something eventually occurs on the product filter, it eventually occurs on the curried\nfilter (see `filter.curry_le_prod` and `filter.eventually.curry`), but the converse is not true.\n\nAnother way to think about the curried versus the product filter is that tending to some limit on\nthe product filter is a version of uniform convergence (see `tendsto_prod_filter_iff`) whereas\ntending to some limit on a curried filter is just iterated limits (see `tendsto.curry`).\n\n## Main definitions\n\n* `filter.curry`: A binary operation on filters which represents iterated limits\n\n## Main statements\n\n* `filter.eventually_curry_iff`: An alternative definition of a curried filter\n* `filter.curry_le_prod`: Something that is eventually true on the a product filter is eventually\n   true on the curried filter\n\n## Tags\n\nuniform convergence, curried filters, product filters\n-/\n\nnamespace filter\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\n/-- This filter is characterized by `filter.eventually_curry_iff`:\n`(\u2200\u1da0 (x : \u03b1 \u00d7 \u03b2) in f.curry g, p x) \u2194 \u2200\u1da0 (x : \u03b1) in f, \u2200\u1da0 (y : \u03b2) in g, p (x, y)`. Useful\nin adding quantifiers to the middle of `tendsto`s. See\n`has_fderiv_at_of_tendsto_uniformly_on_filter`. -/\ndef curry (f : filter \u03b1) (g : filter \u03b2) : filter (\u03b1 \u00d7 \u03b2) :=\n{ sets := { s | \u2200\u1da0 (a : \u03b1) in f, \u2200\u1da0 (b : \u03b2) in g, (a, b) \u2208 s },\n  univ_sets := (by simp only [set.mem_set_of_eq, set.mem_univ, eventually_true]),\n  sets_of_superset := begin\n    intros x y hx hxy,\n    simp only [set.mem_set_of_eq] at hx \u22a2,\n    exact hx.mono (\u03bb a ha, ha.mono(\u03bb b hb, set.mem_of_subset_of_mem hxy hb)),\n  end,\n  inter_sets := begin\n    intros x y hx hy,\n    simp only [set.mem_set_of_eq, set.mem_inter_iff] at hx hy \u22a2,\n    exact (hx.and hy).mono (\u03bb a ha, (ha.1.and ha.2).mono (\u03bb b hb, hb)),\n  end, }\n\nlemma eventually_curry_iff {f : filter \u03b1} {g : filter \u03b2} {p : \u03b1 \u00d7 \u03b2 \u2192 Prop} :\n  (\u2200\u1da0 (x : \u03b1 \u00d7 \u03b2) in f.curry g, p x) \u2194 \u2200\u1da0 (x : \u03b1) in f, \u2200\u1da0 (y : \u03b2) in g, p (x, y) :=\niff.rfl\n\nlemma curry_le_prod {f : filter \u03b1} {g : filter \u03b2} :\n  f.curry g \u2264 f.prod g :=\nbegin\n  intros u hu,\n  rw \u2190eventually_mem_set at hu \u22a2,\n  rw eventually_curry_iff,\n  exact hu.curry,\nend\n\nlemma tendsto.curry {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {la : filter \u03b1} {lb : filter \u03b2} {lc : filter \u03b3} :\n  (\u2200\u1da0 a in la, tendsto (\u03bb b : \u03b2, f a b) lb lc) \u2192 tendsto \u21bff (la.curry lb) lc :=\nbegin\n  intros h,\n  rw tendsto_def,\n  simp only [curry, filter.mem_mk, set.mem_set_of_eq, set.mem_preimage],\n  simp_rw tendsto_def at h,\n  refine (\u03bb s hs, h.mono (\u03bb a ha, eventually_iff.mpr _)),\n  simpa [function.has_uncurry.uncurry, set.preimage] using ha s hs,\nend\n\nend filter\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/filter/curry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7087600406743527}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n-/\nimport algebra.order.monoid.canonical.defs\nimport algebra.order.group.defs\nimport algebra.order.monoid.order_dual\n\n/-!\n# Lemmas about densely linearly ordered groups.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {\u03b1 : Type*}\n\nsection densely_ordered\nvariables [group \u03b1] [linear_order \u03b1]\nvariables [covariant_class \u03b1 \u03b1 (*) (\u2264)]\nvariables [densely_ordered \u03b1] {a b c : \u03b1}\n\n@[to_additive]\nlemma le_of_forall_lt_one_mul_le (h : \u2200 \u03b5 < 1, a * \u03b5 \u2264 b) : a \u2264 b :=\n@le_of_forall_one_lt_le_mul \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ _ h\n\n@[to_additive]\nlemma le_of_forall_one_lt_div_le (h : \u2200 \u03b5 : \u03b1, 1 < \u03b5 \u2192 a / \u03b5 \u2264 b) : a \u2264 b :=\nle_of_forall_lt_one_mul_le $ \u03bb \u03b5 \u03b51,\n  by simpa only [div_eq_mul_inv, inv_inv]  using h \u03b5\u207b\u00b9 (left.one_lt_inv_iff.2 \u03b51)\n\n@[to_additive]\nlemma le_iff_forall_one_lt_le_mul : a \u2264 b \u2194 \u2200 \u03b5, 1 < \u03b5 \u2192 a \u2264 b * \u03b5 :=\n\u27e8\u03bb h \u03b5 \u03b5_pos, le_mul_of_le_of_one_le h \u03b5_pos.le, le_of_forall_one_lt_le_mul\u27e9\n\n@[to_additive]\nlemma le_iff_forall_lt_one_mul_le : a \u2264 b \u2194 \u2200 \u03b5 < 1, a * \u03b5 \u2264 b :=\n@le_iff_forall_one_lt_le_mul \u03b1\u1d52\u1d48 _ _ _ _ _ _\n\nend densely_ordered\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/group/densely_ordered.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.708760025852954}}
{"text": "/-\nAs another example of overloading, this short course module\nintroduces a typeclass, has_truish (\u03b1 : Type), that enables\noverloading of a function, truish : \u03b1 \u2192 bool, that takes any\nvalue of a type, \u03b1, to one of type Boolean, thereby allowing \nvalues of any such a type, \u03b1,to be used where Booleans are \nexpected, e.g., as conditions in conditional expressions or\nstatements. For example, in C and C++, the integer value, 0,\nwill be interpreted (converted to) false, while any other\ninteger value will be interpreted as true when used as the\ncondition in a conditional (if/then/else) statement.  \n-/\n\n\n/-\nThe has_truish typeclass enables overloading of the\n\"truish\" operator for any type, \u03b1, for which there is\na typeclass instance.\n-/\nclass has_truish (\u03b1 : Type) :=\n(truish : \u03b1 \u2192 bool)\n\n-- overload truish for bool\ninstance : has_truish bool :=\n\u27e8 \u03bb b, b \u27e9 \n\n-- overload truish for string\ninstance : has_truish string :=\n\u27e8\n  \u03bb s, \n    match s with\n    | \"\" := ff\n    | _ := tt\n    end \n\u27e9 \n\n-- overload truish for nat\ninstance : has_truish nat :=\n\u27e8\n  \u03bb s, \n    match s with\n    | 0 := ff\n    | _ := tt\n    end \n\u27e9 \n\n/-\nA function polymorphic in any \u03b1 for which truish is defined that takes\na value, a, of this type and returns a Boolean true or false (tt or ff)\nvalue, reflecting the truishness of a.\n-/\n-- open has_truish\n\ndef is_truish { \u03b1 : Type } [has_truish \u03b1] (a : \u03b1) : bool := has_truish.truish a\n\n/-\nExamples of ad hoc polymorphism\n-/\n#eval is_truish tt\n#eval is_truish ff\n#eval is_truish 0\n#eval is_truish 18\n#eval is_truish \"\"\n#eval is_truish \"Hello, Lean!\"\n\n\ndef if_truish_then_else { \u03b1 \u03b2 : Type } [has_truish \u03b1] (c : \u03b1) (t f : \u03b2) : \u03b2 :=\nif is_truish c then t else f\n\n--                        ad hoc  parametric\n#eval if_truish_then_else   tt    \"Yep\" \"Nope\" \n#eval if_truish_then_else   ff    \"Yep\" \"Nope\" \n#eval if_truish_then_else   0     tt    ff \n#eval if_truish_then_else   1     tt    ff\n\n/-\nClassic example. See YesNo in Learn You a Haskell.\n-/\n\n", "meta": {"author": "kevinsullivan", "repo": "cs6501s22", "sha": "c55d342145b127e7b7bf396c660966034e80a944", "save_path": "github-repos/lean/kevinsullivan-cs6501s22", "path": "github-repos/lean/kevinsullivan-cs6501s22/cs6501s22-c55d342145b127e7b7bf396c660966034e80a944/src/content/lectures/S_07_monads/overloading.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7087600217783125}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport analysis.convex.star\nimport analysis.normed_space.pointwise\nimport analysis.seminorm\nimport tactic.congrm\n\n/-!\n# The Minkowksi functional\n\nThis file defines the Minkowski functional, aka gauge.\n\nThe Minkowski functional of a set `s` is the function which associates each point to how much you\nneed to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is\na seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This\ninduces the equivalence of seminorms and locally convex topological vector spaces.\n\n## Main declarations\n\nFor a real vector space,\n* `gauge`: Aka Minkowksi functional. `gauge s x` is the least (actually, an infimum) `r` such\n  that `x \u2208 r \u2022 s`.\n* `gauge_seminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and\n  absorbent.\n\n## References\n\n* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]\n\n## Tags\n\nMinkowski functional, gauge\n-/\n\nopen normed_field set\nopen_locale pointwise\n\nnoncomputable theory\n\nvariables {E : Type*}\n\nsection add_comm_group\nvariables [add_comm_group E] [module \u211d E]\n\n/--The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional\nwhich sends `x : E` to the smallest `r : \u211d` such that `x` is in `s` scaled by `r`. -/\ndef gauge (s : set E) (x : E) : \u211d := Inf {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 s}\n\nvariables {s t : set E} {a : \u211d} {x : E}\n\nlemma gauge_def : gauge s x = Inf {r \u2208 set.Ioi 0 | x \u2208 r \u2022 s} := rfl\n\n/-- An alternative definition of the gauge using scalar multiplication on the element rather than on\nthe set. -/\nlemma gauge_def' : gauge s x = Inf {r \u2208 set.Ioi 0 | r\u207b\u00b9 \u2022 x \u2208 s} :=\nbegin\n  congrm Inf (\u03bb r, _),\n  exact and_congr_right (\u03bb hr, mem_smul_set_iff_inv_smul_mem\u2080 hr.ne' _ _),\nend\n\nprivate lemma gauge_set_bdd_below : bdd_below {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 s} := \u27e80, \u03bb r hr, hr.1.le\u27e9\n\n/-- If the given subset is `absorbent` then the set we take an infimum over in `gauge` is nonempty,\nwhich is useful for proving many properties about the gauge.  -/\nlemma absorbent.gauge_set_nonempty (absorbs : absorbent \u211d s) :\n  {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 s}.nonempty :=\nlet \u27e8r, hr\u2081, hr\u2082\u27e9 := absorbs x in \u27e8r, hr\u2081, hr\u2082 r (real.norm_of_nonneg hr\u2081.le).ge\u27e9\n\nlemma gauge_mono (hs : absorbent \u211d s) (h : s \u2286 t) : gauge t \u2264 gauge s :=\n\u03bb x, cInf_le_cInf gauge_set_bdd_below hs.gauge_set_nonempty $ \u03bb r hr, \u27e8hr.1, smul_set_mono h hr.2\u27e9\n\nlemma exists_lt_of_gauge_lt (absorbs : absorbent \u211d s) (h : gauge s x < a) :\n  \u2203 b, 0 < b \u2227 b < a \u2227 x \u2208 b \u2022 s :=\nbegin\n  obtain \u27e8b, \u27e8hb, hx\u27e9, hba\u27e9 := exists_lt_of_cInf_lt absorbs.gauge_set_nonempty h,\n  exact \u27e8b, hb, hba, hx\u27e9,\nend\n\n/-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s`\nbut, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/\n@[simp] lemma gauge_zero : gauge s 0 = 0 :=\nbegin\n  rw gauge_def',\n  by_cases (0 : E) \u2208 s,\n  { simp only [smul_zero, sep_true, h, cInf_Ioi] },\n  { simp only [smul_zero, sep_false, h, real.Inf_empty] }\nend\n\n@[simp] lemma gauge_zero' : gauge (0 : set E) = 0 :=\nbegin\n  ext,\n  rw gauge_def',\n  obtain rfl | hx := eq_or_ne x 0,\n  { simp only [cInf_Ioi, mem_zero, pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] },\n  { simp only [mem_zero, pi.zero_apply, inv_eq_zero, smul_eq_zero],\n    convert real.Inf_empty,\n    exact eq_empty_iff_forall_not_mem.2 (\u03bb r hr, hr.2.elim (ne_of_gt hr.1) hx) }\nend\n\n@[simp] lemma gauge_empty : gauge (\u2205 : set E) = 0 :=\nby { ext, simp only [gauge_def', real.Inf_empty, mem_empty_eq, pi.zero_apply, sep_false] }\n\nlemma gauge_of_subset_zero (h : s \u2286 0) : gauge s = 0 :=\nby { obtain rfl | rfl := subset_singleton_iff_eq.1 h, exacts [gauge_empty, gauge_zero'] }\n\n/-- The gauge is always nonnegative. -/\nlemma gauge_nonneg (x : E) : 0 \u2264 gauge s x := real.Inf_nonneg _ $ \u03bb x hx, hx.1.le\n\nlemma gauge_neg (symmetric : \u2200 x \u2208 s, -x \u2208 s) (x : E) : gauge s (-x) = gauge s x :=\nbegin\n  have : \u2200 x, -x \u2208 s \u2194 x \u2208 s := \u03bb x, \u27e8\u03bb h, by simpa using symmetric _ h, symmetric x\u27e9,\n  rw [gauge_def', gauge_def'],\n  simp_rw [smul_neg, this],\nend\n\nlemma gauge_le_of_mem (ha : 0 \u2264 a) (hx : x \u2208 a \u2022 s) : gauge s x \u2264 a :=\nbegin\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] },\n  { exact cInf_le gauge_set_bdd_below \u27e8ha', hx\u27e9 }\nend\n\nlemma gauge_le_eq (hs\u2081 : convex \u211d s) (hs\u2080 : (0 : E) \u2208 s) (hs\u2082 : absorbent \u211d s) (ha : 0 \u2264 a) :\n  {x | gauge s x \u2264 a} = \u22c2 (r : \u211d) (H : a < r), r \u2022 s :=\nbegin\n  ext,\n  simp_rw [set.mem_Inter, set.mem_set_of_eq],\n  refine \u27e8\u03bb h r hr, _, \u03bb h, le_of_forall_pos_lt_add (\u03bb \u03b5 h\u03b5, _)\u27e9,\n  { have hr' := ha.trans_lt hr,\n    rw mem_smul_set_iff_inv_smul_mem\u2080 hr'.ne',\n    obtain \u27e8\u03b4, \u03b4_pos, h\u03b4r, h\u03b4\u27e9 := exists_lt_of_gauge_lt hs\u2082 (h.trans_lt hr),\n    suffices : (r\u207b\u00b9 * \u03b4) \u2022 \u03b4\u207b\u00b9 \u2022 x \u2208 s,\n    { rwa [smul_smul, mul_inv_cancel_right\u2080 \u03b4_pos.ne'] at this },\n    rw mem_smul_set_iff_inv_smul_mem\u2080 \u03b4_pos.ne' at h\u03b4,\n    refine hs\u2081.smul_mem_of_zero_mem hs\u2080 h\u03b4\n      \u27e8mul_nonneg (inv_nonneg.2 hr'.le) \u03b4_pos.le, _\u27e9,\n    rw [inv_mul_le_iff hr', mul_one],\n    exact h\u03b4r.le },\n  { have h\u03b5' := (lt_add_iff_pos_right a).2 (half_pos h\u03b5),\n    exact (gauge_le_of_mem (ha.trans h\u03b5'.le) $ h _ h\u03b5').trans_lt\n      (add_lt_add_left (half_lt_self h\u03b5) _) }\nend\n\nlemma gauge_lt_eq' (absorbs : absorbent \u211d s) (a : \u211d) :\n  {x | gauge s x < a} = \u22c3 (r : \u211d) (H : 0 < r) (H : r < a), r \u2022 s :=\nbegin\n  ext,\n  simp_rw [mem_set_of_eq, mem_Union, exists_prop],\n  exact \u27e8exists_lt_of_gauge_lt absorbs,\n    \u03bb \u27e8r, hr\u2080, hr\u2081, hx\u27e9, (gauge_le_of_mem hr\u2080.le hx).trans_lt hr\u2081\u27e9,\nend\n\nlemma gauge_lt_eq (absorbs : absorbent \u211d s) (a : \u211d) :\n  {x | gauge s x < a} = \u22c3 (r \u2208 set.Ioo 0 (a : \u211d)), r \u2022 s :=\nbegin\n  ext,\n  simp_rw [mem_set_of_eq, mem_Union, exists_prop, mem_Ioo, and_assoc],\n  exact \u27e8exists_lt_of_gauge_lt absorbs,\n    \u03bb \u27e8r, hr\u2080, hr\u2081, hx\u27e9, (gauge_le_of_mem hr\u2080.le hx).trans_lt hr\u2081\u27e9,\nend\n\nlemma gauge_lt_one_subset_self (hs : convex \u211d s) (h\u2080 : (0 : E) \u2208 s) (absorbs : absorbent \u211d s) :\n  {x | gauge s x < 1} \u2286 s :=\nbegin\n  rw gauge_lt_eq absorbs,\n  refine set.Union\u2082_subset (\u03bb r hr _, _),\n  rintro \u27e8y, hy, rfl\u27e9,\n  exact hs.smul_mem_of_zero_mem h\u2080 hy (Ioo_subset_Icc_self hr),\nend\n\nlemma gauge_le_one_of_mem {x : E} (hx : x \u2208 s) : gauge s x \u2264 1 :=\ngauge_le_of_mem zero_le_one $ by rwa one_smul\n\nlemma self_subset_gauge_le_one : s \u2286 {x | gauge s x \u2264 1} := \u03bb x, gauge_le_one_of_mem\n\nlemma convex.gauge_le (hs : convex \u211d s) (h\u2080 : (0 : E) \u2208 s) (absorbs : absorbent \u211d s) (a : \u211d) :\n  convex \u211d {x | gauge s x \u2264 a} :=\nbegin\n  by_cases ha : 0 \u2264 a,\n  { rw gauge_le_eq hs h\u2080 absorbs ha,\n    exact convex_Inter (\u03bb i, convex_Inter (\u03bb hi, hs.smul _)) },\n  { convert convex_empty,\n    exact eq_empty_iff_forall_not_mem.2 (\u03bb x hx, ha $ (gauge_nonneg _).trans hx) }\nend\n\nlemma balanced.star_convex (hs : balanced \u211d s) : star_convex \u211d 0 s :=\nstar_convex_zero_iff.2 $ \u03bb x hx a ha\u2080 ha\u2081,\n  hs _ (by rwa real.norm_of_nonneg ha\u2080) (smul_mem_smul_set hx)\n\nlemma le_gauge_of_not_mem (hs\u2080 : star_convex \u211d 0 s) (hs\u2082 : absorbs \u211d s {x}) (hx : x \u2209 a \u2022 s) :\n  a \u2264 gauge s x :=\nbegin\n  rw star_convex_zero_iff at hs\u2080,\n  obtain \u27e8r, hr, h\u27e9 := hs\u2082,\n  refine le_cInf \u27e8r, hr, singleton_subset_iff.1 $ h _ (real.norm_of_nonneg hr.le).ge\u27e9 _,\n  rintro b \u27e8hb, x, hx', rfl\u27e9,\n  refine not_lt.1 (\u03bb hba, hx _),\n  have ha := hb.trans hba,\n  refine \u27e8(a\u207b\u00b9 * b) \u2022 x, hs\u2080 hx' (mul_nonneg (inv_nonneg.2 ha.le) hb.le) _, _\u27e9,\n  { rw \u2190div_eq_inv_mul,\n    exact div_le_one_of_le hba.le ha.le },\n  { rw [\u2190mul_smul, mul_inv_cancel_left\u2080 ha.ne'] }\nend\n\nlemma one_le_gauge_of_not_mem (hs\u2081 : star_convex \u211d 0 s) (hs\u2082 : absorbs \u211d s {x}) (hx : x \u2209 s) :\n  1 \u2264 gauge s x :=\nle_gauge_of_not_mem hs\u2081 hs\u2082 $ by rwa one_smul\n\nsection linear_ordered_field\nvariables {\u03b1 : Type*} [linear_ordered_field \u03b1] [mul_action_with_zero \u03b1 \u211d] [ordered_smul \u03b1 \u211d]\n\nlemma gauge_smul_of_nonneg [mul_action_with_zero \u03b1 E] [is_scalar_tower \u03b1 \u211d (set E)] {s : set E}\n  {a : \u03b1} (ha : 0 \u2264 a) (x : E) :\n  gauge s (a \u2022 x) = a \u2022 gauge s x :=\nbegin\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [zero_smul, gauge_zero, zero_smul] },\n  rw [gauge_def', gauge_def', \u2190real.Inf_smul_of_nonneg ha],\n  congr' 1,\n  ext r,\n  simp_rw [set.mem_smul_set, set.mem_sep_eq],\n  split,\n  { rintro \u27e8hr, hx\u27e9,\n    simp_rw mem_Ioi at \u22a2 hr,\n    rw \u2190mem_smul_set_iff_inv_smul_mem\u2080 hr.ne' at hx,\n    have := smul_pos (inv_pos.2 ha') hr,\n    refine \u27e8a\u207b\u00b9 \u2022 r, \u27e8this, _\u27e9, smul_inv_smul\u2080 ha'.ne' _\u27e9,\n    rwa [\u2190mem_smul_set_iff_inv_smul_mem\u2080 this.ne', smul_assoc,\n      mem_smul_set_iff_inv_smul_mem\u2080 (inv_ne_zero ha'.ne'), inv_inv] },\n  { rintro \u27e8r, \u27e8hr, hx\u27e9, rfl\u27e9,\n    rw mem_Ioi at \u22a2 hr,\n    rw \u2190mem_smul_set_iff_inv_smul_mem\u2080 hr.ne' at hx,\n    have := smul_pos ha' hr,\n    refine \u27e8this, _\u27e9,\n    rw [\u2190mem_smul_set_iff_inv_smul_mem\u2080 this.ne', smul_assoc],\n    exact smul_mem_smul_set hx }\nend\n\n/-- In textbooks, this is the homogeneity of the Minkowksi functional. -/\nlemma gauge_smul [module \u03b1 E] [is_scalar_tower \u03b1 \u211d (set E)] {s : set E}\n  (symmetric : \u2200 x \u2208 s, -x \u2208 s) (r : \u03b1) (x : E) :\n  gauge s (r \u2022 x) = abs r \u2022 gauge s x :=\nbegin\n  rw \u2190gauge_smul_of_nonneg (abs_nonneg r),\n  obtain h | h := abs_choice r,\n  { rw h },\n  { rw [h, neg_smul, gauge_neg symmetric] },\n  { apply_instance }\nend\n\nlemma gauge_smul_left_of_nonneg [mul_action_with_zero \u03b1 E] [smul_comm_class \u03b1 \u211d \u211d]\n  [is_scalar_tower \u03b1 \u211d \u211d] [is_scalar_tower \u03b1 \u211d E] {s : set E} {a : \u03b1} (ha : 0 \u2264 a) :\n  gauge (a \u2022 s) = a\u207b\u00b9 \u2022 gauge s :=\nbegin\n  obtain rfl | ha' := ha.eq_or_lt,\n  { rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)] },\n  ext,\n  rw [gauge_def', pi.smul_apply, gauge_def', \u2190real.Inf_smul_of_nonneg (inv_nonneg.2 ha)],\n  congr' 1,\n  ext r,\n  simp_rw [set.mem_smul_set, set.mem_sep_eq],\n  split,\n  { rintro \u27e8hr, y, hy, h\u27e9,\n    simp_rw [mem_Ioi] at \u22a2 hr,\n    refine \u27e8a \u2022 r, \u27e8smul_pos ha' hr, _\u27e9, inv_smul_smul\u2080 ha'.ne' _\u27e9,\n    rwa [smul_inv\u2080, smul_assoc, \u2190h, inv_smul_smul\u2080 ha'.ne'] },\n  { rintro \u27e8r, \u27e8hr, hx\u27e9, rfl\u27e9,\n    rw mem_Ioi at \u22a2 hr,\n    have := smul_pos ha' hr,\n    refine \u27e8smul_pos (inv_pos.2 ha') hr, r\u207b\u00b9 \u2022 x, hx, _\u27e9,\n    rw [smul_inv\u2080, smul_assoc, inv_inv] }\nend\n\nlemma gauge_smul_left [module \u03b1 E] [smul_comm_class \u03b1 \u211d \u211d] [is_scalar_tower \u03b1 \u211d \u211d]\n  [is_scalar_tower \u03b1 \u211d E] {s : set E} (symmetric : \u2200 x \u2208 s, -x \u2208 s) (a : \u03b1) :\n  gauge (a \u2022 s) = |a|\u207b\u00b9 \u2022 gauge s :=\nbegin\n  rw \u2190gauge_smul_left_of_nonneg (abs_nonneg a),\n  obtain h | h := abs_choice a,\n  { rw h },\n  { rw [h, set.neg_smul_set, \u2190set.smul_set_neg],\n    congr,\n    ext y,\n    refine \u27e8symmetric _, \u03bb hy, _\u27e9,\n    rw \u2190neg_neg y,\n    exact symmetric _ hy },\n  { apply_instance }\nend\n\nend linear_ordered_field\n\nsection topological_space\nvariables [topological_space E] [has_continuous_smul \u211d E]\n\nlemma interior_subset_gauge_lt_one (s : set E) : interior s \u2286 {x | gauge s x < 1} :=\nbegin\n  intros x hx,\n  let f : \u211d \u2192 E := \u03bb t, t \u2022 x,\n  have hf : continuous f,\n  { continuity },\n  let s' := f \u207b\u00b9' (interior s),\n  have hs' : is_open s' := hf.is_open_preimage _ is_open_interior,\n  have one_mem : (1 : \u211d) \u2208 s',\n  { simpa only [s', f, set.mem_preimage, one_smul] },\n  obtain \u27e8\u03b5, h\u03b5\u2080, h\u03b5\u27e9 := (metric.nhds_basis_closed_ball.1 _).1\n    (is_open_iff_mem_nhds.1 hs' 1 one_mem),\n  rw real.closed_ball_eq_Icc at h\u03b5,\n  have h\u03b5\u2081 : 0 < 1 + \u03b5 := h\u03b5\u2080.trans (lt_one_add \u03b5),\n  have : (1 + \u03b5)\u207b\u00b9 < 1,\n  { rw inv_lt_one_iff,\n    right,\n    linarith },\n  refine (gauge_le_of_mem (inv_nonneg.2 h\u03b5\u2081.le) _).trans_lt this,\n  rw mem_inv_smul_set_iff\u2080 h\u03b5\u2081.ne',\n  exact interior_subset\n    (h\u03b5 \u27e8(sub_le_self _ h\u03b5\u2080.le).trans ((le_add_iff_nonneg_right _).2 h\u03b5\u2080.le), le_rfl\u27e9),\nend\n\nlemma gauge_lt_one_eq_self_of_open (hs\u2081 : convex \u211d s) (hs\u2080 : (0 : E) \u2208 s) (hs\u2082 : is_open s) :\n  {x | gauge s x < 1} = s :=\nbegin\n  refine (gauge_lt_one_subset_self hs\u2081 \u2039_\u203a $ absorbent_nhds_zero $ hs\u2082.mem_nhds hs\u2080).antisymm _,\n  convert interior_subset_gauge_lt_one s,\n  exact hs\u2082.interior_eq.symm,\nend\n\nlemma gauge_lt_one_of_mem_of_open (hs\u2081 : convex \u211d s) (hs\u2080 : (0 : E) \u2208 s) (hs\u2082 : is_open s)\n  {x : E} (hx : x \u2208 s) :\n  gauge s x < 1 :=\nby rwa \u2190gauge_lt_one_eq_self_of_open hs\u2081 hs\u2080 hs\u2082 at hx\n\nlemma gauge_lt_of_mem_smul (x : E) (\u03b5 : \u211d) (h\u03b5 : 0 < \u03b5) (hs\u2080 : (0 : E) \u2208 s)\n  (hs\u2081 : convex \u211d s) (hs\u2082 : is_open s) (hx : x \u2208 \u03b5 \u2022 s) :\n  gauge s x < \u03b5 :=\nbegin\n  have : \u03b5\u207b\u00b9 \u2022 x \u2208 s,\n  { rwa \u2190mem_smul_set_iff_inv_smul_mem\u2080 h\u03b5.ne' },\n  have h_gauge_lt := gauge_lt_one_of_mem_of_open hs\u2081 hs\u2080 hs\u2082 this,\n  rwa [gauge_smul_of_nonneg (inv_nonneg.2 h\u03b5.le), smul_eq_mul, inv_mul_lt_iff h\u03b5, mul_one]\n    at h_gauge_lt,\n  apply_instance\nend\n\nend topological_space\n\nlemma gauge_add_le (hs : convex \u211d s) (absorbs : absorbent \u211d s) (x y : E) :\n  gauge s (x + y) \u2264 gauge s x + gauge s y :=\nbegin\n  refine le_of_forall_pos_lt_add (\u03bb \u03b5 h\u03b5, _),\n  obtain \u27e8a, ha, ha', hx\u27e9 := exists_lt_of_gauge_lt absorbs\n    (lt_add_of_pos_right (gauge s x) (half_pos h\u03b5)),\n  obtain \u27e8b, hb, hb', hy\u27e9 := exists_lt_of_gauge_lt absorbs\n    (lt_add_of_pos_right (gauge s y) (half_pos h\u03b5)),\n  rw mem_smul_set_iff_inv_smul_mem\u2080 ha.ne' at hx,\n  rw mem_smul_set_iff_inv_smul_mem\u2080 hb.ne' at hy,\n  suffices : gauge s (x + y) \u2264 a + b,\n  { linarith },\n  have hab : 0 < a + b := add_pos ha hb,\n  apply gauge_le_of_mem hab.le,\n  have := convex_iff_div.1 hs hx hy ha.le hb.le hab,\n  rwa [smul_smul, smul_smul, \u2190mul_div_right_comm, \u2190mul_div_right_comm, mul_inv_cancel ha.ne',\n    mul_inv_cancel hb.ne', \u2190smul_add, one_div, \u2190mem_smul_set_iff_inv_smul_mem\u2080 hab.ne'] at this,\nend\n\n/-- `gauge s` as a seminorm when `s` is symmetric, convex and absorbent. -/\n@[simps] def gauge_seminorm (hs\u2080 : \u2200 x \u2208 s, -x \u2208 s) (hs\u2081 : convex \u211d s) (hs\u2082 : absorbent \u211d s) :\n  seminorm \u211d E :=\nseminorm.of (gauge s) (gauge_add_le hs\u2081 hs\u2082)\n  (\u03bb r x, by rw [gauge_smul hs\u2080, real.norm_eq_abs, smul_eq_mul]; apply_instance)\n\nsection gauge_seminorm\nvariables {hs\u2080 : \u2200 x \u2208 s, -x \u2208 s} {hs\u2081 : convex \u211d s} {hs\u2082 : absorbent \u211d s}\n\nsection topological_space\nvariables [topological_space E] [has_continuous_smul \u211d E]\n\nlemma gauge_seminorm_lt_one_of_open (hs : is_open s) {x : E} (hx : x \u2208 s) :\n  gauge_seminorm hs\u2080 hs\u2081 hs\u2082 x < 1 :=\ngauge_lt_one_of_mem_of_open hs\u2081 hs\u2082.zero_mem hs hx\n\nend topological_space\nend gauge_seminorm\n\n/-- Any seminorm arises as the gauge of its unit ball. -/\n@[simp] protected lemma seminorm.gauge_ball (p : seminorm \u211d E) : gauge (p.ball 0 1) = p :=\nbegin\n  ext,\n  obtain hp | hp := {r : \u211d | 0 < r \u2227 x \u2208 r \u2022 p.ball 0 1}.eq_empty_or_nonempty,\n  { rw [gauge, hp, real.Inf_empty],\n    by_contra,\n    have hpx : 0 < p x := (p.nonneg x).lt_of_ne h,\n    have hpx\u2082 : 0 < 2 * p x := mul_pos zero_lt_two hpx,\n    refine hp.subset \u27e8hpx\u2082, (2 * p x)\u207b\u00b9 \u2022 x, _, smul_inv_smul\u2080 hpx\u2082.ne' _\u27e9,\n    rw [p.mem_ball_zero, p.smul, real.norm_eq_abs, abs_of_pos (inv_pos.2 hpx\u2082), inv_mul_lt_iff hpx\u2082,\n      mul_one],\n    exact lt_mul_of_one_lt_left hpx one_lt_two },\n  refine is_glb.cInf_eq \u27e8\u03bb r, _, \u03bb r hr, le_of_forall_pos_le_add $ \u03bb \u03b5 h\u03b5, _\u27e9 hp,\n  { rintro \u27e8hr, y, hy, rfl\u27e9,\n    rw p.mem_ball_zero at hy,\n    rw [p.smul, real.norm_eq_abs, abs_of_pos hr],\n    exact mul_le_of_le_one_right hr.le hy.le },\n  { have hp\u03b5 : 0 < p x + \u03b5 := add_pos_of_nonneg_of_pos (p.nonneg _) h\u03b5,\n    refine hr \u27e8hp\u03b5, (p x + \u03b5)\u207b\u00b9 \u2022 x, _, smul_inv_smul\u2080 hp\u03b5.ne' _\u27e9,\n    rw [p.mem_ball_zero, p.smul, real.norm_eq_abs, abs_of_pos (inv_pos.2 hp\u03b5), inv_mul_lt_iff hp\u03b5,\n      mul_one],\n    exact lt_add_of_pos_right _ h\u03b5 }\nend\n\nlemma seminorm.gauge_seminorm_ball (p : seminorm \u211d E) :\n  gauge_seminorm (\u03bb x, p.symmetric_ball_zero 1) (p.convex_ball 0 1)\n    (p.absorbent_ball_zero zero_lt_one) = p := fun_like.coe_injective p.gauge_ball\n\nend add_comm_group\n\nsection norm\nvariables [semi_normed_group E] [normed_space \u211d E] {s : set E} {r : \u211d} {x : E}\n\nlemma gauge_unit_ball (x : E) : gauge (metric.ball (0 : E) 1) x = \u2225x\u2225 :=\nbegin\n  obtain rfl | hx := eq_or_ne x 0,\n  { rw [norm_zero, gauge_zero] },\n  refine (le_of_forall_pos_le_add $ \u03bb \u03b5 h\u03b5, _).antisymm _,\n  { have := add_pos_of_nonneg_of_pos (norm_nonneg x) h\u03b5,\n    refine gauge_le_of_mem this.le _,\n    rw [smul_ball this.ne', smul_zero, real.norm_of_nonneg this.le, mul_one, mem_ball_zero_iff],\n    exact lt_add_of_pos_right _ h\u03b5 },\n  refine le_gauge_of_not_mem balanced_ball_zero.star_convex\n    (absorbent_ball_zero zero_lt_one).absorbs (\u03bb h, _),\n  obtain hx' | hx' := eq_or_ne (\u2225x\u2225) 0,\n  { rw hx' at h,\n    exact hx (zero_smul_set_subset _ h) },\n  { rw [mem_smul_set_iff_inv_smul_mem\u2080 hx', mem_ball_zero_iff, norm_smul, norm_inv, norm_norm,\n      inv_mul_cancel hx'] at h,\n    exact lt_irrefl _ h }\nend\n\nlemma gauge_ball (hr : 0 < r) (x : E) : gauge (metric.ball (0 : E) r) x = \u2225x\u2225 / r :=\nbegin\n  rw [\u2190smul_unit_ball_of_pos hr, gauge_smul_left, pi.smul_apply, gauge_unit_ball, smul_eq_mul,\n    abs_of_nonneg hr.le, div_eq_inv_mul],\n  simp_rw [mem_ball_zero_iff, norm_neg],\n  exact \u03bb _, id,\nend\n\nlemma mul_gauge_le_norm (hs : metric.ball (0 : E) r \u2286 s) : r * gauge s x \u2264 \u2225x\u2225 :=\nbegin\n  obtain hr | hr := le_or_lt r 0,\n  { exact (mul_nonpos_of_nonpos_of_nonneg hr $ gauge_nonneg _).trans (norm_nonneg _) },\n  rw [mul_comm, \u2190le_div_iff hr, \u2190gauge_ball hr],\n  exact gauge_mono (absorbent_ball_zero hr) hs x,\nend\n\nend norm\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/convex/gauge.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7087429349492944}}
{"text": "import data.real.basic \n\n-- TODO: Move. \nlemma mul_Inf {K : \u211d} (hK : 0 \u2264 K) {p : \u211d \u2192 Prop} \n(h : \u2203 x, 0 \u2264 x \u2227 p x) (hp : p (Inf {x | 0 \u2264 x \u2227 p x}))\n: K * Inf {x | 0 \u2264 x \u2227 p x} = Inf {y | \u2203 x, (y : \u211d) = K * x \u2227 0 \u2264 x \u2227 p x} :=\nbegin \n  rcases h with \u27e8i, hnni, hpi\u27e9,\n  let S := {y | \u2203 x, y = K * x \u2227 0 \u2264 x \u2227 p x},\n  apply le_antisymm,\n  { have h1 : (\u2203 (x : \u211d), x \u2208 S) := \u27e8K * i, \u27e8i, rfl, hnni, hpi\u27e9\u27e9,\n    have h2 : (\u2203 (x : \u211d), \u2200 (y : \u211d), y \u2208 S \u2192 x \u2264 y),\n    { existsi (0 : \u211d), rintros y \u27e8x, hy, hnnx, hpx\u27e9,\n      rw hy, exact mul_nonneg hK hnnx, },\n    rw real.le_Inf S h1 h2, rintros z \u27e8w, hz, hnnw, hpw\u27e9,\n    rw hz, mono,\n    { refine cInf_le _ \u27e8hnnw, hpw\u27e9, use 0, intros a ha, exact ha.1, },\n    { apply le_cInf,\n      { use [i, \u27e8hnni, hpi\u27e9], },\n      { intros b hb, exact hb.1, }, }, },\n  { apply real.Inf_le,\n    { use [0], intros y hy, rcases hy with \u27e8x, \u27e8hy, hnnx, hpx\u27e9\u27e9,\n      rw hy, exact mul_nonneg hK hnnx, },\n    { use [Inf {x : \u211d | 0 \u2264 x \u2227 p x}], refine \u27e8rfl, _, _\u27e9, \n      { apply le_cInf,\n        { use [i, \u27e8hnni, hpi\u27e9], },\n        { intros b hb, exact hb.1, }, },\n      { exact hp, }, }, },\nend\n", "meta": {"author": "ramonfmir", "repo": "lean-experiments", "sha": "041c8727bb540fb8d1519c1ad84924d473885c27", "save_path": "github-repos/lean/ramonfmir-lean-experiments", "path": "github-repos/lean/ramonfmir-lean-experiments/lean-experiments-041c8727bb540fb8d1519c1ad84924d473885c27/src/picard_lindelof/other/mul_Inf.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.708742933735252}}
{"text": "/-\nCopyright (c) 2022 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n\n! This file was ported from Lean 3 source module topology.algebra.order.extr_closure\n! leanprover-community/mathlib commit 4c19a16e4b705bf135cf9a80ac18fcc99c438514\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Topology.LocalExtr\nimport Mathlib.Topology.Order.Basic\n\n/-!\n# Maximum/minimum on the closure of a set\n\nIn this file we prove several versions of the following statement: if `f : X \u2192 Y` has a (local or\nnot) maximum (or minimum) on a set `s` at a point `a` and is continuous on the closure of `s`, then\n`f` has an extremum of the same type on `Closure s` at `a`.\n-/\n\n\nopen Filter Set\n\nopen Topology\n\nvariable {X Y : Type _} [TopologicalSpace X] [TopologicalSpace Y] [Preorder Y]\n  [OrderClosedTopology Y] {f g : X \u2192 Y} {s : Set X} {a : X}\n\nprotected theorem IsMaxOn.closure (h : IsMaxOn f s a) (hc : ContinuousOn f (closure s)) :\n    IsMaxOn f (closure s) a := fun x hx =>\n  ContinuousWithinAt.closure_le hx ((hc x hx).mono subset_closure) continuousWithinAt_const h\n#align is_max_on.closure IsMaxOn.closure\n\nprotected theorem IsMinOn.closure (h : IsMinOn f s a) (hc : ContinuousOn f (closure s)) :\n    IsMinOn f (closure s) a :=\n  h.dual.closure hc\n#align is_min_on.closure IsMinOn.closure\n\nprotected theorem IsExtrOn.closure (h : IsExtrOn f s a) (hc : ContinuousOn f (closure s)) :\n    IsExtrOn f (closure s) a :=\n  h.elim (fun h => Or.inl <| h.closure hc) fun h => Or.inr <| h.closure hc\n#align is_extr_on.closure IsExtrOn.closure\n\nprotected theorem IsLocalMaxOn.closure (h : IsLocalMaxOn f s a) (hc : ContinuousOn f (closure s)) :\n    IsLocalMaxOn f (closure s) a := by\n  rcases mem_nhdsWithin.1 h with \u27e8U, Uo, aU, hU\u27e9\n  refine' mem_nhdsWithin.2 \u27e8U, Uo, aU, _\u27e9\n  rintro x \u27e8hxU, hxs\u27e9\n  refine' ContinuousWithinAt.closure_le _ _ continuousWithinAt_const hU\n  \u00b7 rwa [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_inter_of_mem, \u2190\n      mem_closure_iff_nhdsWithin_neBot]\n    exact nhdsWithin_le_nhds (Uo.mem_nhds hxU)\n  \u00b7 exact (hc _ hxs).mono ((inter_subset_right _ _).trans subset_closure)\n#align is_local_max_on.closure IsLocalMaxOn.closure\n\nprotected theorem IsLocalMinOn.closure (h : IsLocalMinOn f s a) (hc : ContinuousOn f (closure s)) :\n    IsLocalMinOn f (closure s) a :=\n  IsLocalMaxOn.closure h.dual hc\n#align is_local_min_on.closure IsLocalMinOn.closure\n\nprotected theorem IsLocalExtrOn.closure (h : IsLocalExtrOn f s a)\n    (hc : ContinuousOn f (closure s)) : IsLocalExtrOn f (closure s) a :=\n  h.elim (fun h => Or.inl <| h.closure hc) fun h => Or.inr <| h.closure hc\n#align is_local_extr_on.closure IsLocalExtrOn.closure\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/Algebra/Order/ExtrClosure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7087429324659139}}
{"text": "-- We import all of Lean's standard tactics\nimport tactic\n\n/-!\n# Logic\n\nWe will develop the basic theory of following five basic logical symbols\n\n* `\u2192` (\"implies\" -- type with `\\l`)\n* `\u00ac` (\"not\" -- type with `\\not` or `\\n`)\n* `\u2227` (\"and\" -- type with `\\and` or `\\an`)\n* `\u2194` (\"iff\" -- type with `\\iff` or `\\lr`)\n* `\u2228` (\"or\" -- type with `\\or` or `\\v`\n\n# Tactics you will need to know\n\n* `intro`\n* `exact`\n* `apply`\n* `rw`\n* `cases`\n* `split`\n* `left`\n* `right`\n\nSee `README.md` in `src/week_1` for an explanation of what these\ntactics do.\n\nNote that there are plenty of other tactics, and indeed once you've\n\"got the hang of it\" you might want to try tactics such as `cc`, \n`tauto` and its variant `tauto!`, `finish`, and `library_search`.\n\n# What to do\n\nThe `example`s are to demonstrate things to you. They sometimes\nuse tactics you don't know. You can look at them but you don't\nneed to touch them. \n\nThe `theorem`s and `lemma`s are things which have no proof. You need to change\nthe `sorry`s into proofs which Lean will accept.\n\nThis paragraph is a comment, by the way. One-line comments\nare preceded with `--`.\n-/\n\n-- We work in a \"namespace\". All this means is that whenever it\n-- looks like we've defined a new theorem called `id`, its full\n-- name is `xena.id`. Which is good because `id` is already\n-- defined in Lean.\nnamespace xena\n\n-- Throughout this namespace, P Q and R will be arbitrary (variable)\n-- true-false statements.\nvariables (P Q R : Prop)\n\n/-!\n## implies (\u2192)\n\nTo prove the theorems in this section, you will need to know about\nthe tactics `intro`, `apply` and `exact`. You might also like\nthe `assumption` tactic.\n-/\n\n/-- Every proposition implies itself. -/\ntheorem id : P \u2192 P :=\nbegin\n  -- let hP be a proof of P\n  intro hP,\n  -- then hP is a proof of P!\n  exact hP\nend\n\n/-\nNote that \u2192 isn't associative!\nTry working out `false \u2192 (false \u2192 false) and (false \u2192 false) \u2192 false\n-/\n\nexample : (false \u2192 (false \u2192 false)) \u2194 true := by simp\nexample : ((false \u2192 false) \u2192 false) \u2194 false := by simp\n\n-- in Lean, `P \u2192 Q \u2192 R` is _defined_ to mean `P \u2192 (Q \u2192 R)`\n-- Here's a proof of what I just said.\nexample : (P \u2192 Q \u2192 R) \u2194 (P \u2192 (Q \u2192 R)) :=\nbegin\n  -- look at the goal!\n  refl -- true because \u2194 is reflexive\nend\n\ntheorem imp_intro : P \u2192 Q \u2192 P :=\nbegin\n  -- remember that by definition the goal is P \u2192 (Q \u2192 P),\n  -- so it's P implies something, so let's assume \n  -- that P is true and call this hypothesis hP.\n  intro hP,\n  -- Now we have to prove that Q implies P, so let's\n  -- assume that Q is true, and let's call this hypothesis hQ\n  intro hQ,\n  -- We now have to prove that P is true.\n  -- But this is exactly our hypothesis hP.\n  exact hP,\nend\n\n/-- If we know `P`, and we also know `P \u2192 Q`, we can deduce `Q`. -/\nlemma modus_ponens : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  -- remember this means \"P implies that ((P implies Q) implies Q)\"\n  -- so let's assume P is true\n  intro hP,\n  -- and let's assume hypothesis hPQ, that P implies Q\n  intro hPQ,\n  -- now `hPQ` says `P \u2192 Q` and we're trying to prove `Q`!\n  -- So by applying the hypothesis `hPQ`, we can reduce\n  -- this puzzle to proving `P`.\n  apply hPQ,\n  -- Now we have to prove `P`. But this is just an assumption\n  exact hP, -- or `assumption`\nend\n\n/-- implication is transitive -/\nlemma imp_trans : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  -- intros will let you intro many things at once\n  intros hPQ hQR hP,\n  -- The goal is now `\u22a2 R`, and `hQR : Q \u2192 R` so `apply hQR` reduces the goal to `Q`\n  apply hQR,\n  -- similarly `apply hPQ` reduces the goal to `P`.\n  apply hPQ,\n  -- We are kind of proving this result backwards! We already have\n  -- a proof of P. \n  exact hP\nend\n\n-- This one is a \"relative modus ponens\" -- in the\n-- presence of P, if Q -> R and Q then R.\nlemma forall_imp : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  -- Let `hPQR` be the hypothesis that `P \u2192 Q \u2192 R`. \n  intro hPQR,\n  -- We now need to prove that `(P \u2192 Q)` implies something.\n  -- So let `hPQ` be hypothesis that `P \u2192 Q`\n  intro hPQ,\n  -- We now need to prove that `P` implies something, so \n  -- let `hP` be the hypothesis that `P` is true.\n  intro hP,\n  -- We now have to prove `R`.\n  -- We know the hypothesis `hPQR : P \u2192 (Q \u2192 R)`.\n  -- If you think about this, it's the same as `(P \u2227 Q) \u2192 R`\n  -- So perhaps it's not surprising that after\n  apply hPQR,\n    -- we now have two goals!\n    -- The first goal is just to prove P, and this is an assumption\n    exact hP,\n  -- The number of goals is just one again.\n  -- the remaining goal is to prove `Q`. \n  -- But recall that `hPQ` is the hypothesis that `P` implies `Q`\n  -- so by applying it,\n  apply hPQ,\n  -- we change our goal to proving `P`. And this is a hypothesis\n  exact hP,\nend\n\n/-\n\n### not\n\n`not P`, with notation `\u00ac P`, is *defined* to mean `P \u2192 false` in Lean,\ni.e., the proposition that P implies false. You can easily check with\na truth table that P \u2192 false and \u00ac P are equivalent.\n\nWe develop a basic interface for `\u00ac`.\n-/\n\n\n-- I'll prove this one for you\ntheorem not_def : \u00ac P \u2194 (P \u2192 false) :=\nbegin\n  -- true by definition\n  refl\nend\n\ntheorem not_not_intro : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  intro hP,\n  -- You can use `rw not_def` to change `\u00ac X` into `X \u2192 false`. \n  rw not_def, rw not_def, -- but it's not necessary really,\n  intro hnP,\n  apply hnP,\n  exact hP,\nend\n\n-- Here is a funny alternative proof! Can you work out how it works?\nexample : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  apply modus_ponens,\nend\n\n-- Here is a proof which does not use tactics at all, but uses lambda calculus.\n-- It is called a \"term mode\" proof. We will not be discussing term mode\n-- much in this course. It is a cool way to do basic logic proofs, but\n-- it does not scale well in practice.\nexample : P \u2192 \u00ac (\u00ac P) :=\n\u03bb hP hnP, hnP hP\n\n-- This is \"modus tollens\". Some mathematicians think of it as\n-- \"proof by contradiction\".\ntheorem modus_tollens : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  -- this is (P \u2192 Q) \u2192 (Q \u2192 false) \u2192 (P \u2192 false) so we can just...\n  apply imp_trans,\nend\n\n-- This one cannot be proved using constructive mathematics!\n-- You _have_ to use a tactic like `by_contra` (or, if you're happy\n-- to cheat, the full \"truth table\" tactic `tauto!`.\n-- Try it without using these, and you'll get stuck!\ntheorem double_negation_elimination : \u00ac (\u00ac P) \u2192 P :=\nbegin\n  intro hnnP,\n  by_contra h,\n  -- hnnP is \u00ac P \u2192 false, and the goal is \u22a2 false, so we can do this\n  apply hnnP,\n  exact h,\nend\n\n/-!\n\n### and\n\nThe hypothesis `hPaQ : P \u2227 Q` in Lean, is equivalent to\nhypotheses `hP : P` and `hQ : Q`. \n\nIf you have `hPaQ` as a hypothesis, and you want to get to\n`hP` and `hQ`, you can use the `cases` tactic.\n\nIf you have `\u22a2 P \u2227 Q` as a goal, and want to turn the goal\ninto two goals `\u22a2 P` and `\u22a2 Q`, then use the `split` tactic.\n\nNote that after `split` it's good etiquette to use braces\ne.g.\n\nexample (hP : P) (hQ : Q) : P \u2227 Q :=\nbegin\n  split,\n  { exact hP },\n  { exact hQ }\nend\n\nbut for this sort of stuff I think principled indentation\nis OK\n\n```\nexample (hP : P) (hQ : Q) : P \u2227 Q :=\nbegin\n  split,\n    exact hP,\n  exact hQ\nend\n```\n\n-/\n\ntheorem and.elim_left : P \u2227 Q \u2192 P :=\nbegin\n  intro hPaQ,\n  cases hPaQ with hP hQ,\n  exact hP,\nend\n\ntheorem and.elim_right : P \u2227 Q \u2192 Q :=\nbegin\n  intro hPaQ,\n  -- here's a shortcut\n  exact hPaQ.2, -- if `h : P \u2227 Q` then `h.1 : P` and `h.2 : Q`\nend\n\n-- fancy term mode proof\nexample : P \u2227 Q \u2192 Q := \u03bb hPaQ, hPaQ.2\n\ntheorem and.intro : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  intros hP hQ,\n  split,\n  { assumption },\n  { assumption }\nend\n\n/-- the eliminator for `\u2227` -/ \ntheorem and.elim : P \u2227 Q \u2192 (P \u2192 Q \u2192 R) \u2192 R :=\nbegin\n  -- `rintro` does `intro` and `cases` in one go\n  rintro \u27e8hP, hQ\u27e9 hPQR,\n  -- hPQR is a function, so we can give it some inputs\n  exact hPQR hP hQ,\nend\n\n/-- The recursor for `\u2227` -/\ntheorem and.rec : (P \u2192 Q \u2192 R) \u2192 P \u2227 Q \u2192 R :=\nbegin\n  rintro hPQR \u27e8hP, hQ\u27e9,\n  exact hPQR hP hQ,\nend\n\n/-- `\u2227` is symmetric -/\ntheorem and.symm : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  -- see how quickly we can do this using \u27e8_, _\u27e9\n  rintro \u27e8hP, hQ\u27e9,\n  exact \u27e8hQ, hP\u27e9\nend\n\n-- term mode proof\nexample : P \u2227 Q \u2192 Q \u2227 P :=\n\u03bb \u27e8hP, hQ\u27e9, \u27e8hQ, hP\u27e9\n\n/-- `\u2227` is transitive -/\ntheorem and.trans : (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n  rintro \u27e8hP, hQ\u27e9 \u27e8hQ', hR\u27e9,\n  exact \u27e8hP, hR\u27e9,\nend\n\n/-\nRecall that the convention for the implies sign \u2192\nis that it is _right associative_, by which\nI mean that `P \u2192 Q \u2192 R` means `P \u2192 (Q \u2192 R)` by definition.\nNow note that if `P` implies `Q \u2192 R`\nthen this means that `P` and `Q` together, imply `R`,\nso `P \u2192 Q \u2192 R` is logically equivalent to `(P \u2227 Q) \u2192 R`.\n\nWe proved that `P \u2192 Q \u2192 R` implied `(P \u2227 Q) \u2192 R`; this was `and.rec`.\nLet's go the other way.\n-/\n\nlemma imp_imp_of_and_imp : ((P \u2227 Q) \u2192 R) \u2192 (P \u2192 Q \u2192 R) :=\nbegin\n  intros h hP hQ,\n  exact h \u27e8hP, hQ\u27e9\nend\n\n\n/-!\n\n### iff\n\nThe basic theory of `iff`.\n\nIn Lean, to prove `P \u2227 Q` you have to prove `P` and `Q`.\nSimilarly, to prove `P \u2194 Q` in Lean, you have to prove `P \u2192 Q`\nand `Q \u2192 P`. Just like `\u2227`, you can uses `cases h` if you have\na hypothesis `h : P \u2194 Q`, and `split` if you have a goal `\u22a2 P \u2194 Q`.\n-/\n\n/-- `P \u2194 P` is true for all propositions `P`, i.e. `\u2194` is reflexive. -/\ntheorem iff.refl : P \u2194 P :=\nbegin\n  split,\n  -- recall that we already proved `id : P \u2192 P`\n  { apply id },\n  { apply id }\nend\n\n-- If you get stuck, there is always the \"truth table\" tactic `tauto!`\nexample : P \u2194 P :=\nbegin\n  tauto!, -- the \"truth table\" tactic.\nend\n\n-- refl tactic also works\nexample : P \u2194 P :=\nbegin\n  refl -- `refl` knows that `=` and `\u2194` are reflexive.\nend\n\n/-- `\u2194` is symmetric -/\ntheorem iff.symm : (P \u2194 Q) \u2192 (Q \u2194 P) :=\nbegin\n  intro h,\n  /-\n  h: P \u2194 Q\n  \u22a2 Q \u2194 P\n  -/\n  rw h,\n  -- This changes the goal to `Q \u2194 Q`, which is automatically closed by `refl`\n  -- because `rw` tries a cheeky `refl` after every invocation, just to see\n  -- if it closes the goal\nend\n\n-- show-off term mode proof\nexample : (P \u2194 Q) \u2192 (Q \u2194 P) :=\n\u03bb \u27e8hPQ, hQP\u27e9, \u27e8hQP, hPQ\u27e9\n\n/-- `\u2194` is commutative -/\ntheorem iff.comm : (P \u2194 Q) \u2194 (Q \u2194 P) :=\nbegin\n  split,\n  { apply iff.symm },\n  { apply iff.symm }\nend\n\n-- without rw or cc this is painful!\n/-- `\u2194` is transitive -/\ntheorem iff.trans :  (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  intros hPQ hQR,\n  -- \u22a2 P \u2194 R\n  rw hPQ,\n  -- \u22a2 Q \u2194 R\n  exact hQR,\nend\n\n-- This can be done constructively, but it's hard. You'll need to know\n-- about the `have` tactic to do it. Alternatively the truth table\n-- tactic `tauto!` will do it.\ntheorem iff.boss : \u00ac (P \u2194 \u00ac P) :=\nbegin\n  rintro \u27e8h1, h2\u27e9,\n  have hnP : \u00ac P,\n  { intro hP,\n    exact h1 hP hP,\n  },\n  have hP : P := h2 hnP,\n  exact hnP hP,\nend\n\n-- Now we have iff we can go back to and.\n\n/-!\n### \u2194 and \u2227\n-/\n\n/-- `\u2227` is commutative -/\ntheorem and.comm : P \u2227 Q \u2194 Q \u2227 P :=\nbegin\n  split; -- semicolon means \"apply next tactic to all goals generated by this one\"\n  apply and.symm,\nend\n\n-- fancy term-mode proof\nexample : P \u2227 Q \u2194 Q \u2227 P :=\n\u27e8and.symm _ _, and.symm _ _\u27e9\n\n-- Note that \u2227 is \"right associative\" in Lean, which means\n-- that `P \u2227 Q \u2227 R` is _defined to mean_ `P \u2227 (Q \u2227 R)`.\n-- Associativity can hence be written like this:\n/-- `\u2227` is associative -/\ntheorem and_assoc : ((P \u2227 Q) \u2227 R) \u2194 (P \u2227 Q \u2227 R) :=\nbegin\n  split,\n  { rintro \u27e8\u27e8hP, hQ\u27e9, hR\u27e9,\n    exact \u27e8hP, hQ, hR\u27e9 },\n  { rintro \u27e8hP, hQ, hR\u27e9,\n    exact \u27e8\u27e8hP, hQ\u27e9, hR\u27e9 },\nend\n\n\n\n/-!\n\n## Or\n\n`P \u2228 Q` is true when at least one of `P` and `Q` are true.\nHere is how to work with `\u2228` in Lean.\n\nIf you have a hypothesis `hPoQ : P \u2228 Q` then you \ncan break into the two cases `hP : P` and `hQ : Q` using\n`cases hPoQ with hP hQ`\n\nIf you have a _goal_ of the form `\u22a2 P \u2228 Q` then you\nneed to decide whether you're going to prove `P` or `Q`.\nIf you want to prove `P` then use the `left` tactic,\nand if you want to prove `Q` then use the `right` tactic.\n\n-/\n\n-- recall that P, Q, R are Propositions. We'll need S for this one.\nvariable (S : Prop)\n\n-- You will need to use the `left `tactic for this one.\ntheorem or.intro_left : P \u2192 P \u2228 Q :=\nbegin\n  intro P, \n  left,\n  -- `assumption` means `exact <choose the correct hypothesis>`\n  assumption,\nend\n\ntheorem or.intro_right : Q \u2192 P \u2228 Q :=\nbegin\n  intro Q,\n  right,\n  assumption,\nend\n\n/-- the eliminator for `\u2228`. -/\ntheorem or.elim : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  intros hPoQ hPR hQR,\n  cases hPoQ with hP hQ,\n  { exact hPR hP },\n  { exact hQR hQ }\nend\n\n/-- `\u2228` is symmetric -/\ntheorem or.symm : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  intro hPoQ,\n  cases hPoQ with hP hQ,\n  { right, assumption },\n  { left, assumption }\nend\n\n/-- `\u2228` is commutative -/\ntheorem or.comm : P \u2228 Q \u2194 Q \u2228 P :=\nbegin\n  split; -- note semicolon\n  apply or.symm,\nend\n\n/-- `\u2228` is associative -/\ntheorem or.assoc : (P \u2228 Q) \u2228 R \u2194 P \u2228 Q \u2228 R :=\nbegin\n  split,\n  { -- rintro can do intro+cases in one go\n    rintro ((hP | hQ) | hR),\n    { left, assumption },\n    { right, left, assumption },\n    { right, right, assumption } },\n  { rintro (hP | hQ | hR),\n    { left, left, assumption },\n    { left, right, assumption },\n    { right, assumption } }\nend\n\n/-!\n### More about \u2192 and \u2228\n-/\n\ntheorem or.imp : (P \u2192 R) \u2192 (Q \u2192 S) \u2192 P \u2228 Q \u2192 R \u2228 S :=\nbegin\n  rintro hPR hQS (hP | hQ),\n  { left, exact hPR hP },\n  { right, exact hQS hQ }\nend\n\ntheorem or.imp_left : (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R :=\nbegin\n  rintro hPQ (hP | hR),\n  { left, exact hPQ hP },\n  { right, assumption },\nend\n\ntheorem or.imp_right : (P \u2192 Q) \u2192 R \u2228 P \u2192 R \u2228 Q :=\nbegin\n  -- reduce to previous lemma\n  rw or.comm R,\n  rw or.comm R,\n  apply or.imp_left,\nend\n\ntheorem or.left_comm : P \u2228 Q \u2228 R \u2194 Q \u2228 P \u2228 R :=\nbegin\n  rw [or.comm P, or.assoc, or.comm R],\nend\n\n/-- the recursor for `\u2228` -/\ntheorem or.rec : (P \u2192 R) \u2192 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R :=\nbegin\n  intros hPR hQR hPoQ,\n  exact or.elim _ _ _ hPoQ hPR hQR,\nend\n\ntheorem or_congr : (P \u2194 R) \u2192 (Q \u2194 S) \u2192 (P \u2228 Q \u2194 R \u2228 S) :=\nbegin\n  rintro hPR hQS,\n  rw [hPR, hQS],\nend\n\n/-!\n\n### true and false\n\n`true` is a true-false statement, which can be proved with the `trivial` tactic.\n\n`false` is a true-false statment which can only be proved if you manage\nto find a contradiction within your assumptions.\n\nIf you manage to end up with a hypothesis `h : false` then there's quite\na funny way to proceed, which we now explain.\n\nIf you have `h : P \u2227 Q` then you can uses `cases h with hP hQ` to split\ninto two cases. \n\nIf you have `h : false` then what do you think happens if we do `cases h`?\nHint: how many cases are there?\n-/\n\n\n/-- eliminator for `false` -/\ntheorem false.elim : false \u2192 P :=\nbegin\n  intro h,\n  cases h,\nend\n\ntheorem and_true_iff : P \u2227 true \u2194 P :=\nbegin\n  split,\n  { rintro \u27e8hP, -\u27e9,\n    exact hP },\n  { intro hP,\n    split,\n    { exact hP },\n    { trivial } }\nend\n\ntheorem or_false_iff : P \u2228 false \u2194 P :=\nbegin\n  split,\n  { rintro (hP | h),\n    { assumption },\n    { cases h} },\n  { intro hP,\n    left,\n    exact hP }\nend\n\n-- false.elim is handy for this one\ntheorem or.resolve_left : P \u2228 Q \u2192 \u00acP \u2192 Q :=\nbegin\n  rintro (hP | hQ) hnP,\n  { apply false.elim,\n    exact hnP hP },\n  { exact hQ },\nend\n\n-- this one you can't do constructively\ntheorem or_iff_not_imp_left : P \u2228 Q \u2194 \u00acP \u2192 Q :=\nbegin\n  split,\n  { apply or.resolve_left },\n  { intro hnPQ,\n    -- TODO : document this tactic\n    by_cases h : P,\n    { left, assumption },\n    { right, exact hnPQ h} }\nend\n\nend xena\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics", "sha": "7cf1d51c27e2038d2804561d63c74711924044a1", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics/formalising-mathematics-7cf1d51c27e2038d2804561d63c74711924044a1/src/week_1/kb_solutions/Part_A_logic_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.708742932061233}}
{"text": "/-\nCopyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Abhimanyu Pallavi Sudhir, Yury Kudryashov\n-/\nimport order.filter.ultrafilter\nimport order.filter.germ\n\n/-!\n# Ultraproducts\n\nIf `\u03c6` is an ultrafilter, then the space of germs of functions `f : \u03b1 \u2192 \u03b2` at `\u03c6` is called\nthe *ultraproduct*. In this file we prove properties of ultraproducts that rely on `\u03c6` being an\nultrafilter. Definitions and properties that work for any filter should go to `order.filter.germ`.\n\n## Tags\n\nultrafilter, ultraproduct\n-/\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03c6 : ultrafilter \u03b1}\nopen_locale classical\n\nnamespace filter\n\nlocal notation `\u2200*` binders `, ` r:(scoped p, filter.eventually p \u03c6) := r\n\nnamespace germ\n\nopen ultrafilter\n\nlocal notation `\u03b2*` := germ (\u03c6 : filter \u03b1) \u03b2\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a division ring. -/\ninstance [division_ring \u03b2] : division_ring \u03b2* :=\n{ mul_inv_cancel := \u03bb f, induction_on f $ \u03bb f hf, coe_eq.2 $ (\u03c6.em (\u03bb y, f y = 0)).elim\n    (\u03bb H, (hf $ coe_eq.2 H).elim) (\u03bb H, H.mono $ \u03bb x, mul_inv_cancel),\n  inv_zero := coe_eq.2 $ by simp only [(\u2218), inv_zero],\n  .. germ.ring, .. germ.div_inv_monoid, .. germ.nontrivial }\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a field. -/\ninstance [field \u03b2] : field \u03b2* :=\n{ .. germ.comm_ring, .. germ.division_ring }\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a linear order. -/\nnoncomputable instance [linear_order \u03b2] : linear_order \u03b2* :=\n{ le_total := \u03bb f g, induction_on\u2082 f g $ \u03bb f g, eventually_or.1 $ eventually_of_forall $\n    \u03bb x, le_total _ _,\n  decidable_le := by apply_instance,\n  .. germ.partial_order }\n\n@[simp, norm_cast] lemma const_div [division_ring \u03b2] (x y : \u03b2) : (\u2191(x / y) : \u03b2*) = \u2191x / \u2191y := rfl\n\nlemma coe_lt [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} : (f : \u03b2*) < g \u2194 \u2200* x, f x < g x :=\nby simp only [lt_iff_le_not_le, eventually_and, coe_le, eventually_not, eventually_le]\n\nlemma coe_pos [preorder \u03b2] [has_zero \u03b2] {f : \u03b1 \u2192 \u03b2} : 0 < (f : \u03b2*) \u2194 \u2200* x, 0 < f x :=\ncoe_lt\n\nlemma const_lt [preorder \u03b2] {x y : \u03b2} : (\u2191x : \u03b2*) < \u2191y \u2194 x < y :=\ncoe_lt.trans lift_rel_const_iff\n\nlemma lt_def [preorder \u03b2] : ((<) : \u03b2* \u2192 \u03b2* \u2192 Prop) = lift_rel (<) :=\nby { ext \u27e8f\u27e9 \u27e8g\u27e9, exact coe_lt }\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is an ordered ring. -/\ninstance [ordered_ring \u03b2] : ordered_ring \u03b2* :=\n{ zero_le_one := const_le zero_le_one,\n  mul_pos := \u03bb x y, induction_on\u2082 x y $ \u03bb f g hf hg, coe_pos.2 $\n    (coe_pos.1 hg).mp $ (coe_pos.1 hf).mono $ \u03bb x, mul_pos,\n  .. germ.ring, .. germ.ordered_add_comm_group, .. germ.nontrivial }\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a linear ordered ring. -/\nnoncomputable instance [linear_ordered_ring \u03b2] : linear_ordered_ring \u03b2* :=\n{ .. germ.ordered_ring, .. germ.linear_order, .. germ.nontrivial }\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a linear ordered field. -/\nnoncomputable instance [linear_ordered_field \u03b2] : linear_ordered_field \u03b2* :=\n{ .. germ.linear_ordered_ring, .. germ.field }\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a linear ordered commutative ring. -/\nnoncomputable instance [linear_ordered_comm_ring \u03b2] :\n  linear_ordered_comm_ring \u03b2* :=\n{ .. germ.linear_ordered_ring, .. germ.comm_monoid }\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a decidable linear ordered commutative\ngroup. -/\nnoncomputable instance [linear_ordered_add_comm_group \u03b2] : linear_ordered_add_comm_group \u03b2* :=\n{ .. germ.ordered_add_comm_group, .. germ.linear_order }\n\n\n\nlemma min_def [K : linear_order \u03b2] (x y : \u03b2*) : min x y = map\u2082 min x y :=\n\ninduction_on\u2082 x y $ \u03bb a b,\nbegin\n  cases le_total (a : \u03b2*) b,\n  { rw [min_eq_left h, map\u2082_coe, coe_eq], exact h.mono (\u03bb i hi, (min_eq_left hi).symm) },\n  { rw [min_eq_right h, map\u2082_coe, coe_eq], exact h.mono (\u03bb i hi, (min_eq_right hi).symm) }\nend\n\nlemma abs_def [linear_ordered_add_comm_group \u03b2] (x : \u03b2*) : abs x = map abs x :=\ninduction_on x $ \u03bb a, by rw [abs, \u2190 coe_neg, max_def, map\u2082_coe]; refl\n\n@[simp] lemma const_max [linear_order \u03b2] (x y : \u03b2) : (\u2191(max x y : \u03b2) : \u03b2*) = max \u2191x \u2191y :=\nby rw [max_def, map\u2082_const]\n\n@[simp] lemma const_min [linear_order \u03b2] (x y : \u03b2) : (\u2191(min x y : \u03b2) : \u03b2*) = min \u2191x \u2191y :=\nby rw [min_def, map\u2082_const]\n\n@[simp] lemma const_abs [linear_ordered_add_comm_group \u03b2] (x : \u03b2) :\n  (\u2191(abs x) : \u03b2*) = abs \u2191x :=\nconst_max x (-x)\n\nend germ\n\nend filter\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/filter/filter_product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7087155059346881}}
{"text": "variables p q : Prop\n\nexample (h : p \u2227 q) : q \u2227 p := and.intro (and.elim_right h) (and.elim_left h)\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch3/ex0304.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.708715500144343}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\n! This file was ported from Lean 3 source module data.int.order.lemmas\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Int.Order.Basic\nimport Mathbin.Algebra.GroupWithZero.Divisibility\nimport Mathbin.Algebra.Order.Ring.Abs\n\n/-!\n# Further lemmas about the integers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\nThe distinction between this file and `data.int.order.basic` is not particularly clear.\nThey are separated by now to minimize the porting requirements for tactics during the transition to\nmathlib4. After `data.rat.order` has been ported, please feel free to reorganize these two files.\n-/\n\n\nopen Nat\n\nnamespace Int\n\n/-! ### nat abs -/\n\n\nvariable {a b : \u2124} {n : \u2115}\n\n#print Int.natAbs_eq_iff_mul_self_eq /-\ntheorem natAbs_eq_iff_mul_self_eq {a b : \u2124} : a.natAbs = b.natAbs \u2194 a * a = b * b :=\n  by\n  rw [\u2190 abs_eq_iff_mul_self_eq, abs_eq_nat_abs, abs_eq_nat_abs]\n  exact int.coe_nat_inj'.symm\n#align int.nat_abs_eq_iff_mul_self_eq Int.natAbs_eq_iff_mul_self_eq\n-/\n\n#print Int.eq_natAbs_iff_mul_eq_zero /-\ntheorem eq_natAbs_iff_mul_eq_zero : a.natAbs = n \u2194 (a - n) * (a + n) = 0 := by\n  rw [nat_abs_eq_iff, mul_eq_zero, sub_eq_zero, add_eq_zero_iff_eq_neg]\n#align int.eq_nat_abs_iff_mul_eq_zero Int.eq_natAbs_iff_mul_eq_zero\n-/\n\n#print Int.natAbs_lt_iff_mul_self_lt /-\ntheorem natAbs_lt_iff_mul_self_lt {a b : \u2124} : a.natAbs < b.natAbs \u2194 a * a < b * b :=\n  by\n  rw [\u2190 abs_lt_iff_mul_self_lt, abs_eq_nat_abs, abs_eq_nat_abs]\n  exact int.coe_nat_lt.symm\n#align int.nat_abs_lt_iff_mul_self_lt Int.natAbs_lt_iff_mul_self_lt\n-/\n\n#print Int.natAbs_le_iff_mul_self_le /-\ntheorem natAbs_le_iff_mul_self_le {a b : \u2124} : a.natAbs \u2264 b.natAbs \u2194 a * a \u2264 b * b :=\n  by\n  rw [\u2190 abs_le_iff_mul_self_le, abs_eq_nat_abs, abs_eq_nat_abs]\n  exact int.coe_nat_le.symm\n#align int.nat_abs_le_iff_mul_self_le Int.natAbs_le_iff_mul_self_le\n-/\n\n/- warning: int.dvd_div_of_mul_dvd -> Int.dvd_div_of_mul_dvd is a dubious translation:\nlean 3 declaration is\n  forall {a : Int} {b : Int} {c : Int}, (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a b) c) -> (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) b (HDiv.hDiv.{0, 0, 0} Int Int Int (instHDiv.{0} Int Int.hasDiv) c a))\nbut is expected to have type\n  forall {a : Int} {b : Int} {c : Int}, (Dvd.dvd.{0} Int Int.instDvdInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a b) c) -> (Dvd.dvd.{0} Int Int.instDvdInt b (HDiv.hDiv.{0, 0, 0} Int Int Int (instHDiv.{0} Int Int.instDivInt_1) c a))\nCase conversion may be inaccurate. Consider using '#align int.dvd_div_of_mul_dvd Int.dvd_div_of_mul_dvd\u2093'. -/\ntheorem dvd_div_of_mul_dvd {a b c : \u2124} (h : a * b \u2223 c) : b \u2223 c / a :=\n  by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  \u00b7 simp only [Int.div_zero, dvd_zero]\n  rcases h with \u27e8d, rfl\u27e9\n  refine' \u27e8d, _\u27e9\n  rw [mul_assoc, Int.mul_ediv_cancel_left _ ha]\n#align int.dvd_div_of_mul_dvd Int.dvd_div_of_mul_dvd\n\n/-! ### units -/\n\n\n/- warning: int.eq_zero_of_abs_lt_dvd -> Int.eq_zero_of_abs_lt_dvd is a dubious translation:\nlean 3 declaration is\n  forall {m : Int} {x : Int}, (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) m x) -> (LT.lt.{0} Int Int.hasLt (Abs.abs.{0} Int (Neg.toHasAbs.{0} Int Int.hasNeg (SemilatticeSup.toHasSup.{0} Int (Lattice.toSemilatticeSup.{0} Int (LinearOrder.toLattice.{0} Int Int.linearOrder)))) x) m) -> (Eq.{1} Int x (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))\nbut is expected to have type\n  forall {m : Int} {x : Int}, (Dvd.dvd.{0} Int Int.instDvdInt m x) -> (LT.lt.{0} Int Int.instLTInt (Abs.abs.{0} Int (Neg.toHasAbs.{0} Int Int.instNegInt (SemilatticeSup.toSup.{0} Int (Lattice.toSemilatticeSup.{0} Int (DistribLattice.toLattice.{0} Int (instDistribLattice.{0} Int Int.instLinearOrderInt))))) x) m) -> (Eq.{1} Int x (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))\nCase conversion may be inaccurate. Consider using '#align int.eq_zero_of_abs_lt_dvd Int.eq_zero_of_abs_lt_dvd\u2093'. -/\ntheorem eq_zero_of_abs_lt_dvd {m x : \u2124} (h1 : m \u2223 x) (h2 : |x| < m) : x = 0 :=\n  by\n  by_cases hm : m = 0;\n  \u00b7 subst m\n    exact zero_dvd_iff.mp h1\n  rcases h1 with \u27e8d, rfl\u27e9\n  apply mul_eq_zero_of_right\n  rw [\u2190 abs_lt_one_iff, \u2190 mul_lt_iff_lt_one_right (abs_pos.mpr hm), \u2190 abs_mul]\n  exact lt_of_lt_of_le h2 (le_abs_self m)\n#align int.eq_zero_of_abs_lt_dvd Int.eq_zero_of_abs_lt_dvd\n\nend Int\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Int/Order/Lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.708670425381491}}
{"text": "/-\nCopyright (c) 2020 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n\n! This file was ported from Lean 3 source module measure_theory.measure.content\n! leanprover-community/mathlib commit d39590fc8728fbf6743249802486f8c91ffe07bc\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.MeasureSpace\nimport Mathbin.MeasureTheory.Measure.Regular\nimport Mathbin.Topology.Sets.Compacts\n\n/-!\n# Contents\n\nIn this file we work with *contents*. A content `\u03bb` is a function from a certain class of subsets\n(such as the compact subsets) to `\u211d\u22650` that is\n* additive: If `K\u2081` and `K\u2082` are disjoint sets in the domain of `\u03bb`,\n  then `\u03bb(K\u2081 \u222a K\u2082) = \u03bb(K\u2081) + \u03bb(K\u2082)`;\n* subadditive: If `K\u2081` and `K\u2082` are in the domain of `\u03bb`, then `\u03bb(K\u2081 \u222a K\u2082) \u2264 \u03bb(K\u2081) + \u03bb(K\u2082)`;\n* monotone: If `K\u2081 \u2286 K\u2082` are in the domain of `\u03bb`, then `\u03bb(K\u2081) \u2264 \u03bb(K\u2082)`.\n\nWe show that:\n* Given a content `\u03bb` on compact sets, let us define a function `\u03bb*` on open sets, by letting\n  `\u03bb* U` be the supremum of `\u03bb K` for `K` included in `U`. This is a countably subadditive map that\n  vanishes at `\u2205`. In Halmos (1950) this is called the *inner content* `\u03bb*` of `\u03bb`, and formalized\n  as `inner_content`.\n* Given an inner content, we define an outer measure `\u03bc*`, by letting `\u03bc* E` be the infimum of\n  `\u03bb* U` over the open sets `U` containing `E`. This is indeed an outer measure. It is formalized\n  as `outer_measure`.\n* Restricting this outer measure to Borel sets gives a regular measure `\u03bc`.\n\nWe define bundled contents as `content`.\nIn this file we only work on contents on compact sets, and inner contents on open sets, and both\ncontents and inner contents map into the extended nonnegative reals. However, in other applications\nother choices can be made, and it is not a priori clear what the best interface should be.\n\n## Main definitions\n\nFor `\u03bc : content G`, we define\n* `\u03bc.inner_content` : the inner content associated to `\u03bc`.\n* `\u03bc.outer_measure` : the outer measure associated to `\u03bc`.\n* `\u03bc.measure`       : the Borel measure associated to `\u03bc`.\n\nWe prove that, on a locally compact space, the measure `\u03bc.measure` is regular.\n\n## References\n\n* Paul Halmos (1950), Measure Theory, \u00a753\n* <https://en.wikipedia.org/wiki/Content_(measure_theory)>\n-/\n\n\nuniverse u v w\n\nnoncomputable section\n\nopen Set TopologicalSpace\n\nopen NNReal ENNReal MeasureTheory\n\nnamespace MeasureTheory\n\nvariable {G : Type w} [TopologicalSpace G]\n\n/-- A content is an additive function on compact sets taking values in `\u211d\u22650`. It is a device\nfrom which one can define a measure. -/\nstructure Content (G : Type w) [TopologicalSpace G] where\n  toFun : Compacts G \u2192 \u211d\u22650\n  mono' : \u2200 K\u2081 K\u2082 : Compacts G, (K\u2081 : Set G) \u2286 K\u2082 \u2192 to_fun K\u2081 \u2264 to_fun K\u2082\n  sup_disjoint' :\n    \u2200 K\u2081 K\u2082 : Compacts G, Disjoint (K\u2081 : Set G) K\u2082 \u2192 to_fun (K\u2081 \u2294 K\u2082) = to_fun K\u2081 + to_fun K\u2082\n  sup_le' : \u2200 K\u2081 K\u2082 : Compacts G, to_fun (K\u2081 \u2294 K\u2082) \u2264 to_fun K\u2081 + to_fun K\u2082\n#align measure_theory.content MeasureTheory.Content\n\ninstance : Inhabited (Content G) :=\n  \u27e8{  toFun := fun K => 0\n      mono' := by simp\n      sup_disjoint' := by simp\n      sup_le' := by simp }\u27e9\n\n/-- Although the `to_fun` field of a content takes values in `\u211d\u22650`, we register a coercion to\nfunctions taking values in `\u211d\u22650\u221e` as most constructions below rely on taking suprs and infs, which\nis more convenient in a complete lattice, and aim at constructing a measure. -/\ninstance : CoeFun (Content G) fun _ => Compacts G \u2192 \u211d\u22650\u221e :=\n  \u27e8fun \u03bc s => \u03bc.toFun s\u27e9\n\nnamespace Content\n\nvariable (\u03bc : Content G)\n\ntheorem apply_eq_coe_toFun (K : Compacts G) : \u03bc K = \u03bc.toFun K :=\n  rfl\n#align measure_theory.content.apply_eq_coe_to_fun MeasureTheory.Content.apply_eq_coe_toFun\n\ntheorem mono (K\u2081 K\u2082 : Compacts G) (h : (K\u2081 : Set G) \u2286 K\u2082) : \u03bc K\u2081 \u2264 \u03bc K\u2082 := by\n  simp [apply_eq_coe_to_fun, \u03bc.mono' _ _ h]\n#align measure_theory.content.mono MeasureTheory.Content.mono\n\ntheorem sup_disjoint (K\u2081 K\u2082 : Compacts G) (h : Disjoint (K\u2081 : Set G) K\u2082) :\n    \u03bc (K\u2081 \u2294 K\u2082) = \u03bc K\u2081 + \u03bc K\u2082 := by simp [apply_eq_coe_to_fun, \u03bc.sup_disjoint' _ _ h]\n#align measure_theory.content.sup_disjoint MeasureTheory.Content.sup_disjoint\n\ntheorem sup_le (K\u2081 K\u2082 : Compacts G) : \u03bc (K\u2081 \u2294 K\u2082) \u2264 \u03bc K\u2081 + \u03bc K\u2082 :=\n  by\n  simp only [apply_eq_coe_to_fun]\n  norm_cast\n  exact \u03bc.sup_le' _ _\n#align measure_theory.content.sup_le MeasureTheory.Content.sup_le\n\ntheorem lt_top (K : Compacts G) : \u03bc K < \u221e :=\n  ENNReal.coe_lt_top\n#align measure_theory.content.lt_top MeasureTheory.Content.lt_top\n\ntheorem empty : \u03bc \u22a5 = 0 := by\n  have := \u03bc.sup_disjoint' \u22a5 \u22a5\n  simpa [apply_eq_coe_to_fun] using this\n#align measure_theory.content.empty MeasureTheory.Content.empty\n\n/-- Constructing the inner content of a content. From a content defined on the compact sets, we\n  obtain a function defined on all open sets, by taking the supremum of the content of all compact\n  subsets. -/\ndef innerContent (U : Opens G) : \u211d\u22650\u221e :=\n  \u2a06 (K : Compacts G) (h : (K : Set G) \u2286 U), \u03bc K\n#align measure_theory.content.inner_content MeasureTheory.Content.innerContent\n\ntheorem le_innerContent (K : Compacts G) (U : Opens G) (h2 : (K : Set G) \u2286 U) :\n    \u03bc K \u2264 \u03bc.innerContent U :=\n  le_sup\u1d62_of_le K <| le_sup\u1d62 _ h2\n#align measure_theory.content.le_inner_content MeasureTheory.Content.le_innerContent\n\ntheorem innerContent_le (U : Opens G) (K : Compacts G) (h2 : (U : Set G) \u2286 K) :\n    \u03bc.innerContent U \u2264 \u03bc K :=\n  sup\u1d62\u2082_le fun K' hK' => \u03bc.mono _ _ (Subset.trans hK' h2)\n#align measure_theory.content.inner_content_le MeasureTheory.Content.innerContent_le\n\ntheorem innerContent_of_isCompact {K : Set G} (h1K : IsCompact K) (h2K : IsOpen K) :\n    \u03bc.innerContent \u27e8K, h2K\u27e9 = \u03bc \u27e8K, h1K\u27e9 :=\n  le_antisymm (sup\u1d62\u2082_le fun K' hK' => \u03bc.mono _ \u27e8K, h1K\u27e9 hK') (\u03bc.le_innerContent _ _ Subset.rfl)\n#align measure_theory.content.inner_content_of_is_compact MeasureTheory.Content.innerContent_of_isCompact\n\ntheorem innerContent_bot : \u03bc.innerContent \u22a5 = 0 :=\n  by\n  refine' le_antisymm _ (zero_le _)\n  rw [\u2190 \u03bc.empty]\n  refine' sup\u1d62\u2082_le fun K hK => _\n  have : K = \u22a5 := by\n    ext1\n    rw [subset_empty_iff.mp hK, compacts.coe_bot]\n  rw [this]\n  rfl\n#align measure_theory.content.inner_content_bot MeasureTheory.Content.innerContent_bot\n\n/-- This is \"unbundled\", because that it required for the API of `induced_outer_measure`. -/\ntheorem innerContent_mono \u2983U V : Set G\u2984 (hU : IsOpen U) (hV : IsOpen V) (h2 : U \u2286 V) :\n    \u03bc.innerContent \u27e8U, hU\u27e9 \u2264 \u03bc.innerContent \u27e8V, hV\u27e9 :=\n  bsup\u1d62_mono fun K hK => hK.trans h2\n#align measure_theory.content.inner_content_mono MeasureTheory.Content.innerContent_mono\n\ntheorem innerContent_exists_compact {U : Opens G} (hU : \u03bc.innerContent U \u2260 \u221e) {\u03b5 : \u211d\u22650}\n    (h\u03b5 : \u03b5 \u2260 0) : \u2203 K : Compacts G, (K : Set G) \u2286 U \u2227 \u03bc.innerContent U \u2264 \u03bc K + \u03b5 :=\n  by\n  have h'\u03b5 := ENNReal.coe_ne_zero.2 h\u03b5\n  cases le_or_lt (\u03bc.inner_content U) \u03b5\n  \u00b7 exact \u27e8\u22a5, empty_subset _, le_add_left h\u27e9\n  have := ENNReal.sub_lt_self hU h.ne_bot h'\u03b5\n  conv at this =>\n    rhs\n    rw [inner_content];\n  simp only [lt_sup\u1d62_iff] at this\n  rcases this with \u27e8U, h1U, h2U\u27e9; refine' \u27e8U, h1U, _\u27e9\n  rw [\u2190 tsub_le_iff_right]; exact le_of_lt h2U\n#align measure_theory.content.inner_content_exists_compact MeasureTheory.Content.innerContent_exists_compact\n\n/-- The inner content of a supremum of opens is at most the sum of the individual inner\ncontents. -/\ntheorem innerContent_Sup_nat [T2Space G] (U : \u2115 \u2192 Opens G) :\n    \u03bc.innerContent (\u2a06 i : \u2115, U i) \u2264 \u2211' i : \u2115, \u03bc.innerContent (U i) :=\n  by\n  have h3 : \u2200 (t : Finset \u2115) (K : \u2115 \u2192 compacts G), \u03bc (t.sup K) \u2264 t.Sum fun i => \u03bc (K i) :=\n    by\n    intro t K\n    refine' Finset.induction_on t _ _\n    \u00b7 simp only [\u03bc.empty, nonpos_iff_eq_zero, Finset.sum_empty, Finset.sup_empty]\n    \u00b7 intro n s hn ih\n      rw [Finset.sup_insert, Finset.sum_insert hn]\n      exact le_trans (\u03bc.sup_le _ _) (add_le_add_left ih _)\n  refine' sup\u1d62\u2082_le fun K hK => _\n  obtain \u27e8t, ht\u27e9 := K.is_compact.elim_finite_subcover _ (fun i => (U i).IsOpen) _\n  swap\n  \u00b7 rwa [\u2190 opens.coe_supr]\n  rcases K.is_compact.finite_compact_cover t (coe \u2218 U) (fun i _ => (U _).IsOpen)\n      (by simp only [ht]) with\n    \u27e8K', h1K', h2K', h3K'\u27e9\n  let L : \u2115 \u2192 compacts G := fun n => \u27e8K' n, h1K' n\u27e9\n  convert le_trans (h3 t L) _\n  \u00b7 ext1\n    rw [compacts.coe_finset_sup, Finset.sup_eq_sup\u1d62]\n    exact h3K'\n  refine' le_trans (Finset.sum_le_sum _) (ENNReal.sum_le_tsum t)\n  intro i hi\n  refine' le_trans _ (le_sup\u1d62 _ (L i))\n  refine' le_trans _ (le_sup\u1d62 _ (h2K' i))\n  rfl\n#align measure_theory.content.inner_content_Sup_nat MeasureTheory.Content.innerContent_Sup_nat\n\n/-- The inner content of a union of sets is at most the sum of the individual inner contents.\n  This is the \"unbundled\" version of `inner_content_Sup_nat`.\n  It required for the API of `induced_outer_measure`. -/\ntheorem innerContent_union\u1d62_nat [T2Space G] \u2983U : \u2115 \u2192 Set G\u2984 (hU : \u2200 i : \u2115, IsOpen (U i)) :\n    \u03bc.innerContent \u27e8\u22c3 i : \u2115, U i, isOpen_union\u1d62 hU\u27e9 \u2264 \u2211' i : \u2115, \u03bc.innerContent \u27e8U i, hU i\u27e9 :=\n  by\n  have := \u03bc.inner_content_Sup_nat fun i => \u27e8U i, hU i\u27e9\n  rwa [opens.supr_def] at this\n#align measure_theory.content.inner_content_Union_nat MeasureTheory.Content.innerContent_union\u1d62_nat\n\ntheorem innerContent_comap (f : G \u2243\u209c G) (h : \u2200 \u2983K : Compacts G\u2984, \u03bc (K.map f f.Continuous) = \u03bc K)\n    (U : Opens G) : \u03bc.innerContent (Opens.comap f.toContinuousMap U) = \u03bc.innerContent U :=\n  by\n  refine' (compacts.equiv f).Surjective.sup\u1d62_congr _ fun K => sup\u1d62_congr_Prop image_subset_iff _\n  intro hK; simp only [Equiv.coe_fn_mk, Subtype.mk_eq_mk, ENNReal.coe_eq_coe, compacts.equiv]\n  apply h\n#align measure_theory.content.inner_content_comap MeasureTheory.Content.innerContent_comap\n\n@[to_additive]\ntheorem is_mulLeft_invariant_innerContent [Group G] [TopologicalGroup G]\n    (h : \u2200 (g : G) {K : Compacts G}, \u03bc (K.map _ <| continuous_mul_left g) = \u03bc K) (g : G)\n    (U : Opens G) :\n    \u03bc.innerContent (Opens.comap (Homeomorph.mulLeft g).toContinuousMap U) = \u03bc.innerContent U := by\n  convert \u03bc.inner_content_comap (Homeomorph.mulLeft g) (fun K => h g) U\n#align measure_theory.content.is_mul_left_invariant_inner_content MeasureTheory.Content.is_mulLeft_invariant_innerContent\n#align measure_theory.content.is_add_left_invariant_inner_content MeasureTheory.Content.is_add_left_invariant_inner_content\n\n@[to_additive]\ntheorem innerContent_pos_of_is_mul_left_invariant [T2Space G] [Group G] [TopologicalGroup G]\n    (h3 : \u2200 (g : G) {K : Compacts G}, \u03bc (K.map _ <| continuous_mul_left g) = \u03bc K) (K : Compacts G)\n    (hK : \u03bc K \u2260 0) (U : Opens G) (hU : (U : Set G).Nonempty) : 0 < \u03bc.innerContent U :=\n  by\n  have : (interior (U : Set G)).Nonempty\n  rwa [U.is_open.interior_eq]\n  rcases compact_covered_by_mul_left_translates K.2 this with \u27e8s, hs\u27e9\n  suffices \u03bc K \u2264 s.card * \u03bc.inner_content U by\n    exact (ennreal.mul_pos_iff.mp <| hK.bot_lt.trans_le this).2\n  have : (K : Set G) \u2286 \u2191(\u2a06 g \u2208 s, opens.comap (Homeomorph.mulLeft g).toContinuousMap U) := by\n    simpa only [opens.supr_def, opens.coe_comap, Subtype.coe_mk]\n  refine' (\u03bc.le_inner_content _ _ this).trans _\n  refine'\n    (rel_sup\u1d62_sum \u03bc.inner_content \u03bc.inner_content_bot (\u00b7 \u2264 \u00b7) \u03bc.inner_content_Sup_nat _ _).trans _\n  simp only [\u03bc.is_mul_left_invariant_inner_content h3, Finset.sum_const, nsmul_eq_mul, le_refl]\n#align measure_theory.content.inner_content_pos_of_is_mul_left_invariant MeasureTheory.Content.innerContent_pos_of_is_mul_left_invariant\n#align measure_theory.content.inner_content_pos_of_is_add_left_invariant MeasureTheory.Content.inner_content_pos_of_is_add_left_invariant\n\ntheorem innerContent_mono' \u2983U V : Set G\u2984 (hU : IsOpen U) (hV : IsOpen V) (h2 : U \u2286 V) :\n    \u03bc.innerContent \u27e8U, hU\u27e9 \u2264 \u03bc.innerContent \u27e8V, hV\u27e9 :=\n  bsup\u1d62_mono fun K hK => hK.trans h2\n#align measure_theory.content.inner_content_mono' MeasureTheory.Content.innerContent_mono'\n\nsection OuterMeasure\n\n/-- Extending a content on compact sets to an outer measure on all sets. -/\nprotected def outerMeasure : OuterMeasure G :=\n  inducedOuterMeasure (fun U hU => \u03bc.innerContent \u27e8U, hU\u27e9) isOpen_empty \u03bc.innerContent_bot\n#align measure_theory.content.outer_measure MeasureTheory.Content.outerMeasure\n\nvariable [T2Space G]\n\ntheorem outerMeasure_opens (U : Opens G) : \u03bc.OuterMeasure U = \u03bc.innerContent U :=\n  inducedOuterMeasure_eq' (fun _ => isOpen_union\u1d62) \u03bc.innerContent_union\u1d62_nat \u03bc.innerContent_mono U.2\n#align measure_theory.content.outer_measure_opens MeasureTheory.Content.outerMeasure_opens\n\ntheorem outerMeasure_of_isOpen (U : Set G) (hU : IsOpen U) :\n    \u03bc.OuterMeasure U = \u03bc.innerContent \u27e8U, hU\u27e9 :=\n  \u03bc.outerMeasure_opens \u27e8U, hU\u27e9\n#align measure_theory.content.outer_measure_of_is_open MeasureTheory.Content.outerMeasure_of_isOpen\n\ntheorem outerMeasure_le (U : Opens G) (K : Compacts G) (hUK : (U : Set G) \u2286 K) :\n    \u03bc.OuterMeasure U \u2264 \u03bc K :=\n  (\u03bc.outerMeasure_opens U).le.trans <| \u03bc.innerContent_le U K hUK\n#align measure_theory.content.outer_measure_le MeasureTheory.Content.outerMeasure_le\n\ntheorem le_outerMeasure_compacts (K : Compacts G) : \u03bc K \u2264 \u03bc.OuterMeasure K :=\n  by\n  rw [content.outer_measure, induced_outer_measure_eq_infi]\n  \u00b7 exact le_inf\u1d62 fun U => le_inf\u1d62 fun hU => le_inf\u1d62 <| \u03bc.le_inner_content K \u27e8U, hU\u27e9\n  \u00b7 exact \u03bc.inner_content_Union_nat\n  \u00b7 exact \u03bc.inner_content_mono\n#align measure_theory.content.le_outer_measure_compacts MeasureTheory.Content.le_outerMeasure_compacts\n\ntheorem outerMeasure_eq_inf\u1d62 (A : Set G) :\n    \u03bc.OuterMeasure A = \u2a05 (U : Set G) (hU : IsOpen U) (h : A \u2286 U), \u03bc.innerContent \u27e8U, hU\u27e9 :=\n  inducedOuterMeasure_eq_inf\u1d62 _ \u03bc.innerContent_union\u1d62_nat \u03bc.innerContent_mono A\n#align measure_theory.content.outer_measure_eq_infi MeasureTheory.Content.outerMeasure_eq_inf\u1d62\n\ntheorem outerMeasure_interior_compacts (K : Compacts G) : \u03bc.OuterMeasure (interior K) \u2264 \u03bc K :=\n  (\u03bc.outerMeasure_opens <| Opens.interior K).le.trans <| \u03bc.innerContent_le _ _ interior_subset\n#align measure_theory.content.outer_measure_interior_compacts MeasureTheory.Content.outerMeasure_interior_compacts\n\ntheorem outerMeasure_exists_compact {U : Opens G} (hU : \u03bc.OuterMeasure U \u2260 \u221e) {\u03b5 : \u211d\u22650}\n    (h\u03b5 : \u03b5 \u2260 0) : \u2203 K : Compacts G, (K : Set G) \u2286 U \u2227 \u03bc.OuterMeasure U \u2264 \u03bc.OuterMeasure K + \u03b5 :=\n  by\n  rw [\u03bc.outer_measure_opens] at hU\u22a2\n  rcases \u03bc.inner_content_exists_compact hU h\u03b5 with \u27e8K, h1K, h2K\u27e9\n  exact \u27e8K, h1K, le_trans h2K <| add_le_add_right (\u03bc.le_outer_measure_compacts K) _\u27e9\n#align measure_theory.content.outer_measure_exists_compact MeasureTheory.Content.outerMeasure_exists_compact\n\ntheorem outerMeasure_exists_open {A : Set G} (hA : \u03bc.OuterMeasure A \u2260 \u221e) {\u03b5 : \u211d\u22650} (h\u03b5 : \u03b5 \u2260 0) :\n    \u2203 U : Opens G, A \u2286 U \u2227 \u03bc.OuterMeasure U \u2264 \u03bc.OuterMeasure A + \u03b5 :=\n  by\n  rcases induced_outer_measure_exists_set _ _ \u03bc.inner_content_mono hA\n      (ENNReal.coe_ne_zero.2 h\u03b5) with\n    \u27e8U, hU, h2U, h3U\u27e9\n  exact \u27e8\u27e8U, hU\u27e9, h2U, h3U\u27e9; swap; exact \u03bc.inner_content_Union_nat\n#align measure_theory.content.outer_measure_exists_open MeasureTheory.Content.outerMeasure_exists_open\n\ntheorem outerMeasure_preimage (f : G \u2243\u209c G) (h : \u2200 \u2983K : Compacts G\u2984, \u03bc (K.map f f.Continuous) = \u03bc K)\n    (A : Set G) : \u03bc.OuterMeasure (f \u207b\u00b9' A) = \u03bc.OuterMeasure A :=\n  by\n  refine'\n    induced_outer_measure_preimage _ \u03bc.inner_content_Union_nat \u03bc.inner_content_mono _\n      (fun s => f.is_open_preimage) _\n  intro s hs; convert \u03bc.inner_content_comap f h \u27e8s, hs\u27e9\n#align measure_theory.content.outer_measure_preimage MeasureTheory.Content.outerMeasure_preimage\n\ntheorem outerMeasure_lt_top_of_isCompact [LocallyCompactSpace G] {K : Set G} (hK : IsCompact K) :\n    \u03bc.OuterMeasure K < \u221e :=\n  by\n  rcases exists_compact_superset hK with \u27e8F, h1F, h2F\u27e9\n  calc\n    \u03bc.outer_measure K \u2264 \u03bc.outer_measure (interior F) := outer_measure.mono' _ h2F\n    _ \u2264 \u03bc \u27e8F, h1F\u27e9 := by\n      apply \u03bc.outer_measure_le \u27e8interior F, isOpen_interior\u27e9 \u27e8F, h1F\u27e9 interior_subset\n    _ < \u22a4 := \u03bc.lt_top _\n    \n#align measure_theory.content.outer_measure_lt_top_of_is_compact MeasureTheory.Content.outerMeasure_lt_top_of_isCompact\n\n@[to_additive]\ntheorem is_mul_left_invariant_outerMeasure [Group G] [TopologicalGroup G]\n    (h : \u2200 (g : G) {K : Compacts G}, \u03bc (K.map _ <| continuous_mul_left g) = \u03bc K) (g : G)\n    (A : Set G) : \u03bc.OuterMeasure ((fun h => g * h) \u207b\u00b9' A) = \u03bc.OuterMeasure A := by\n  convert \u03bc.outer_measure_preimage (Homeomorph.mulLeft g) (fun K => h g) A\n#align measure_theory.content.is_mul_left_invariant_outer_measure MeasureTheory.Content.is_mul_left_invariant_outerMeasure\n#align measure_theory.content.is_add_left_invariant_outer_measure MeasureTheory.Content.is_add_left_invariant_outer_measure\n\ntheorem outerMeasure_caratheodory (A : Set G) :\n    measurable_set[\u03bc.OuterMeasure.caratheodory] A \u2194\n      \u2200 U : Opens G, \u03bc.OuterMeasure (U \u2229 A) + \u03bc.OuterMeasure (U \\ A) \u2264 \u03bc.OuterMeasure U :=\n  by\n  rw [opens.forall]\n  apply induced_outer_measure_caratheodory\n  apply inner_content_Union_nat\n  apply inner_content_mono'\n#align measure_theory.content.outer_measure_caratheodory MeasureTheory.Content.outerMeasure_caratheodory\n\n@[to_additive]\ntheorem outerMeasure_pos_of_is_mul_left_invariant [Group G] [TopologicalGroup G]\n    (h3 : \u2200 (g : G) {K : Compacts G}, \u03bc (K.map _ <| continuous_mul_left g) = \u03bc K) (K : Compacts G)\n    (hK : \u03bc K \u2260 0) {U : Set G} (h1U : IsOpen U) (h2U : U.Nonempty) : 0 < \u03bc.OuterMeasure U :=\n  by\n  convert \u03bc.inner_content_pos_of_is_mul_left_invariant h3 K hK \u27e8U, h1U\u27e9 h2U\n  exact \u03bc.outer_measure_opens \u27e8U, h1U\u27e9\n#align measure_theory.content.outer_measure_pos_of_is_mul_left_invariant MeasureTheory.Content.outerMeasure_pos_of_is_mul_left_invariant\n#align measure_theory.content.outer_measure_pos_of_is_add_left_invariant MeasureTheory.Content.outer_measure_pos_of_is_add_left_invariant\n\nvariable [S : MeasurableSpace G] [BorelSpace G]\n\ninclude S\n\n/-- For the outer measure coming from a content, all Borel sets are measurable. -/\ntheorem borel_le_caratheodory : S \u2264 \u03bc.OuterMeasure.caratheodory :=\n  by\n  rw [@BorelSpace.measurable_eq G _ _]\n  refine' MeasurableSpace.generateFrom_le _\n  intro U hU\n  rw [\u03bc.outer_measure_caratheodory]\n  intro U'\n  rw [\u03bc.outer_measure_of_is_open ((U' : Set G) \u2229 U) (U'.is_open.inter hU)]\n  simp only [inner_content, sup\u1d62_subtype']\n  rw [opens.coe_mk]\n  haveI : Nonempty { L : compacts G // (L : Set G) \u2286 U' \u2229 U } := \u27e8\u27e8\u22a5, empty_subset _\u27e9\u27e9\n  rw [ENNReal.sup\u1d62_add]\n  refine' sup\u1d62_le _\n  rintro \u27e8L, hL\u27e9\n  simp only [subset_inter_iff] at hL\n  have : \u2191U' \\ U \u2286 U' \\ L := diff_subset_diff_right hL.2\n  refine' le_trans (add_le_add_left (\u03bc.outer_measure.mono' this) _) _\n  rw [\u03bc.outer_measure_of_is_open (\u2191U' \\ L) (IsOpen.sdiff U'.2 L.2.IsClosed)]\n  simp only [inner_content, sup\u1d62_subtype']\n  rw [opens.coe_mk]\n  haveI : Nonempty { M : compacts G // (M : Set G) \u2286 \u2191U' \\ L } := \u27e8\u27e8\u22a5, empty_subset _\u27e9\u27e9\n  rw [ENNReal.add_sup\u1d62]\n  refine' sup\u1d62_le _\n  rintro \u27e8M, hM\u27e9\n  simp only [subset_diff] at hM\n  have : (\u2191(L \u2294 M) : Set G) \u2286 U' := by\n    simp only [union_subset_iff, compacts.coe_sup, hM, hL, and_self_iff]\n  rw [\u03bc.outer_measure_of_is_open (\u2191U') U'.2]\n  refine' le_trans (ge_of_eq _) (\u03bc.le_inner_content _ _ this)\n  exact \u03bc.sup_disjoint _ _ hM.2.symm\n#align measure_theory.content.borel_le_caratheodory MeasureTheory.Content.borel_le_caratheodory\n\n/-- The measure induced by the outer measure coming from a content, on the Borel sigma-algebra. -/\nprotected def measure : Measure G :=\n  \u03bc.OuterMeasure.toMeasure \u03bc.borel_le_caratheodory\n#align measure_theory.content.measure MeasureTheory.Content.measure\n\ntheorem measure_apply {s : Set G} (hs : MeasurableSet s) : \u03bc.Measure s = \u03bc.OuterMeasure s :=\n  toMeasure_apply _ _ hs\n#align measure_theory.content.measure_apply MeasureTheory.Content.measure_apply\n\n/-- In a locally compact space, any measure constructed from a content is regular. -/\ninstance regular [LocallyCompactSpace G] : \u03bc.Measure.regular :=\n  by\n  have : \u03bc.measure.outer_regular :=\n    by\n    refine' \u27e8fun A hA r (hr : _ < _) => _\u27e9\n    rw [\u03bc.measure_apply hA, outer_measure_eq_infi] at hr\n    simp only [inf\u1d62_lt_iff] at hr\n    rcases hr with \u27e8U, hUo, hAU, hr\u27e9\n    rw [\u2190 \u03bc.outer_measure_of_is_open U hUo, \u2190 \u03bc.measure_apply hUo.measurable_set] at hr\n    exact \u27e8U, hAU, hUo, hr\u27e9\n  have : is_finite_measure_on_compacts \u03bc.measure :=\n    by\n    refine' \u27e8fun K hK => _\u27e9\n    rw [measure_apply _ hK.measurable_set]\n    exact \u03bc.outer_measure_lt_top_of_is_compact hK\n  refine' \u27e8fun U hU r hr => _\u27e9\n  rw [measure_apply _ hU.measurable_set, \u03bc.outer_measure_of_is_open U hU] at hr\n  simp only [inner_content, lt_sup\u1d62_iff] at hr\n  rcases hr with \u27e8K, hKU, hr\u27e9\n  refine' \u27e8K, hKU, K.2, hr.trans_le _\u27e9\n  exact (\u03bc.le_outer_measure_compacts K).trans (le_to_measure_apply _ _ _)\n#align measure_theory.content.regular MeasureTheory.Content.regular\n\nend OuterMeasure\n\nsection RegularContents\n\n/-- A content `\u03bc` is called regular if for every compact set `K`,\n  `\u03bc(K) = inf {\u03bc(K') : K \u2282 int K' \u2282 K'`. See Paul Halmos (1950), Measure Theory, \u00a754-/\ndef ContentRegular :=\n  \u2200 \u2983K : TopologicalSpace.Compacts G\u2984,\n    \u03bc K = \u2a05 (K' : TopologicalSpace.Compacts G) (hK : (K : Set G) \u2286 interior (K' : Set G)), \u03bc K'\n#align measure_theory.content.content_regular MeasureTheory.Content.ContentRegular\n\ntheorem contentRegular_exists_compact (H : ContentRegular \u03bc) (K : TopologicalSpace.Compacts G)\n    {\u03b5 : NNReal} (h\u03b5 : \u03b5 \u2260 0) :\n    \u2203 K' : TopologicalSpace.Compacts G, K.carrier \u2286 interior K'.carrier \u2227 \u03bc K' \u2264 \u03bc K + \u03b5 :=\n  by\n  by_contra hc\n  simp only [not_exists, not_and, not_le] at hc\n  have lower_bound_infi :\n    \u03bc K + \u03b5 \u2264\n      \u2a05 (K' : TopologicalSpace.Compacts G) (h : (K : Set G) \u2286 interior (K' : Set G)), \u03bc K' :=\n    le_inf\u1d62 fun K' => le_inf\u1d62 fun K'_hyp => le_of_lt (hc K' K'_hyp)\n  rw [\u2190 H] at lower_bound_infi\n  exact\n    (lt_self_iff_false (\u03bc K)).mp\n      (lt_of_le_of_lt' lower_bound_infi\n        (ENNReal.lt_add_right (ne_top_of_lt (\u03bc.lt_top K)) (ennreal.coe_ne_zero.mpr h\u03b5)))\n#align measure_theory.content.content_regular_exists_compact MeasureTheory.Content.contentRegular_exists_compact\n\nvariable [MeasurableSpace G] [T2Space G] [BorelSpace G]\n\n/-- If `\u03bc` is a regular content, then the measure induced by `\u03bc` will agree with `\u03bc`\n  on compact sets.-/\ntheorem measure_eq_content_of_regular (H : MeasureTheory.Content.ContentRegular \u03bc)\n    (K : TopologicalSpace.Compacts G) : \u03bc.Measure \u2191K = \u03bc K :=\n  by\n  refine' le_antisymm _ _\n  \u00b7 apply ENNReal.le_of_forall_pos_le_add\n    intro \u03b5 \u03b5pos content_K_finite\n    obtain \u27e8K', K'_hyp\u27e9 := content_regular_exists_compact \u03bc H K (ne_bot_of_gt \u03b5pos)\n    calc\n      \u03bc.measure \u2191K \u2264 \u03bc.measure (interior \u2191K') := _\n      _ \u2264 \u03bc K' := _\n      _ \u2264 \u03bc K + \u03b5 := K'_hyp.right\n      \n    \u00b7 rw [\u03bc.measure_apply isOpen_interior.MeasurableSet,\n        \u03bc.measure_apply K.is_compact.measurable_set]\n      exact \u03bc.outer_measure.mono K'_hyp.left\n    \u00b7 rw [\u03bc.measure_apply (IsOpen.measurableSet isOpen_interior)]\n      exact \u03bc.outer_measure_interior_compacts K'\n  \u00b7 rw [\u03bc.measure_apply (IsCompact.measurableSet K.is_compact)]\n    exact \u03bc.le_outer_measure_compacts K\n#align measure_theory.content.measure_eq_content_of_regular MeasureTheory.Content.measure_eq_content_of_regular\n\nend RegularContents\n\nend Content\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Measure/Content.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.7086670838211753}}
{"text": "/-\nCopyright (c) 2021 Lu-Ming Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Lu-Ming Zhang\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.orthogonal\n! leanprover-community/mathlib commit 790e98fbb5ec433d89d833320954607e79ae9071\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Matrix.Basic\n\n/-!\n# Orthogonal\n\nThis file contains definitions and properties concerning orthogonality of rows and columns.\n\n## Main results\n\n- `matrix.has_orthogonal_rows`:\n  `A.has_orthogonal_rows` means `A` has orthogonal (with respect to `dot_product`) rows.\n- `matrix.has_orthogonal_cols`:\n  `A.has_orthogonal_cols` means `A` has orthogonal (with respect to `dot_product`) columns.\n\n## Tags\n\northogonal\n-/\n\n\nnamespace Matrix\n\nvariable {\u03b1 n m : Type _}\n\nvariable [Mul \u03b1] [AddCommMonoid \u03b1]\n\nvariable (A : Matrix m n \u03b1)\n\nopen Matrix\n\n/-- `A.has_orthogonal_rows` means matrix `A` has orthogonal rows (with respect to\n`matrix.dot_product`). -/\ndef HasOrthogonalRows [Fintype n] : Prop :=\n  \u2200 \u2983i\u2081 i\u2082\u2984, i\u2081 \u2260 i\u2082 \u2192 dotProduct (A i\u2081) (A i\u2082) = 0\n#align matrix.has_orthogonal_rows Matrix.HasOrthogonalRows\n\n/-- `A.has_orthogonal_rows` means matrix `A` has orthogonal columns (with respect to\n`matrix.dot_product`). -/\ndef HasOrthogonalCols [Fintype m] : Prop :=\n  HasOrthogonalRows A\u1d40\n#align matrix.has_orthogonal_cols Matrix.HasOrthogonalCols\n\n/-- `A\u1d40` has orthogonal rows iff `A` has orthogonal columns. -/\n@[simp]\ntheorem transpose_hasOrthogonalRows_iff_hasOrthogonalCols [Fintype m] :\n    A\u1d40.HasOrthogonalRows \u2194 A.HasOrthogonalCols :=\n  Iff.rfl\n#align matrix.transpose_has_orthogonal_rows_iff_has_orthogonal_cols Matrix.transpose_hasOrthogonalRows_iff_hasOrthogonalCols\n\n/-- `A\u1d40` has orthogonal columns iff `A` has orthogonal rows. -/\n@[simp]\ntheorem transpose_hasOrthogonalCols_iff_hasOrthogonalRows [Fintype n] :\n    A\u1d40.HasOrthogonalCols \u2194 A.HasOrthogonalRows :=\n  Iff.rfl\n#align matrix.transpose_has_orthogonal_cols_iff_has_orthogonal_rows Matrix.transpose_hasOrthogonalCols_iff_hasOrthogonalRows\n\nvariable {A}\n\ntheorem HasOrthogonalRows.hasOrthogonalCols [Fintype m] (h : A\u1d40.HasOrthogonalRows) :\n    A.HasOrthogonalCols :=\n  h\n#align matrix.has_orthogonal_rows.has_orthogonal_cols Matrix.HasOrthogonalRows.hasOrthogonalCols\n\ntheorem HasOrthogonalCols.transpose_hasOrthogonalRows [Fintype m] (h : A.HasOrthogonalCols) :\n    A\u1d40.HasOrthogonalRows :=\n  h\n#align matrix.has_orthogonal_cols.transpose_has_orthogonal_rows Matrix.HasOrthogonalCols.transpose_hasOrthogonalRows\n\ntheorem HasOrthogonalCols.hasOrthogonalRows [Fintype n] (h : A\u1d40.HasOrthogonalCols) :\n    A.HasOrthogonalRows :=\n  h\n#align matrix.has_orthogonal_cols.has_orthogonal_rows Matrix.HasOrthogonalCols.hasOrthogonalRows\n\ntheorem HasOrthogonalRows.transpose_hasOrthogonalCols [Fintype n] (h : A.HasOrthogonalRows) :\n    A\u1d40.HasOrthogonalCols :=\n  h\n#align matrix.has_orthogonal_rows.transpose_has_orthogonal_cols Matrix.HasOrthogonalRows.transpose_hasOrthogonalCols\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/Orthogonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.7086670838211752}}
{"text": "-- vim: ts=2 sw=0 sts=-1 et ai tw=70\n\nimport .dvd\nimport .induction\nimport .fact\n\nnamespace hidden\n\nnamespace mynat\n\ndef prime (m: mynat) := m \u2260 1 \u2227 \u2200 k: mynat, k \u2223 m \u2192 k = 1 \u2228 k = m\ndef composite (m : mynat) := \u2203 a b: mynat, a \u2260 1 \u2227 b \u2260 1 \u2227 a * b = m\ndef coprime (m n : mynat) := \u2200 k: mynat, k \u2223 m \u2192 k \u2223 n \u2192 k = 1\n\nvariables {m n p k : mynat}\n\ntheorem zero_nprime: \u00acprime 0 :=\nbegin\n  assume h0pm,\n  cases h0pm with h0pm_left h0pm_right,\n  have h2d0: (2: mynat) \u2223 0 := dvd_zero,\n  have h2n2: 2 \u2260 2,\n  have h2eq01 := h0pm_right 2 h2d0,\n  repeat { cases h2eq01 },\n  from h2n2 rfl,\nend\n\ntheorem one_nprime: \u00acprime 1 :=\nbegin\n  assume h1pm,\n  cases h1pm with h1ne1 _,\n  from h1ne1 rfl,\nend\n\ntheorem zero_composite: composite 0 :=\nbegin\n  existsi zero,\n  existsi zero,\n  split, {\n    assume h01,\n    cases h01,\n  }, {\n    split, {\n    assume h01,\n    cases h01,\n    },\n    simp,\n  },\nend\n\ntheorem one_ncomposite: \u00accomposite 1 :=\nbegin\n  assume h1cmp,\n  cases h1cmp with a h,\n  cases h with b h,\n  cases h with han1 h,\n  cases h with hbn1 hab1,\n  from han1 (one_unit hab1),\nend\n\ntheorem two_ncomposite: \u00accomposite 2 :=\nbegin\n  assume h2cmp,\n  cases h2cmp with a h,\n  cases h with b h,\n  cases h with han1 h,\n  cases h with hbn1 hab2,\n  cases a, {\n    simp at hab2,\n    cases hab2,\n  }, {\n    cases b, {\n      simp at hab2,\n      cases hab2,\n    }, {\n      cases a, {\n        simp at han1,\n        contradiction,\n      }, {\n        cases b, {\n          simp at hbn1,\n          contradiction,\n        }, {\n          simp at hab2,\n          have h := succ_inj hab2,\n          have h' := succ_inj h,\n          from succ_ne_zero h',\n        },\n      },\n    },\n  },\nend\n\n-- prove 2 is prime by a massive case-bash\n-- frankly this was just proved by going into a tactics red mist\ntheorem two_prime: prime 2 :=\nbegin\n  split, {\n    assume h21,\n    cases h21,\n      }, {\n    intro k,\n    assume hk2,\n    cases hk2 with n hn,\n    cases k, {\n      simp at hn,\n      cases hn,\n    }, {\n      cases k, {\n        simp,\n      }, {\n        simp at hn,\n        cases n, {\n          simp at hn,\n          cases hn,\n        }, {\n          simp at hn,\n          cases n, {\n            simp at hn,\n            cc,\n          }, {\n            have hcontr' := succ_inj hn.symm,\n            simp at hcontr',\n            have hcontr := succ_inj hcontr',\n            simp at hcontr,\n            exfalso, from succ_ne_zero hcontr,\n          },\n        },\n      },\n    },\n  },\nend\n\n@[symm]\ntheorem coprime_symm {m n : mynat} : coprime m n \u2192 coprime n m :=\nbegin\n  assume h,\n  intro k,\n  assume hkn hkm,\n  exact h k hkm hkn,\nend\n\ntheorem coprime_one: coprime m 1 :=\nbegin\n  intro k,\n  assume _ hk,\n  from dvd_one hk,\nend\n\ntheorem one_coprime: coprime 1 m :=\ncoprime_symm coprime_one\n\ntheorem coprime_succ: coprime m (succ m) :=\nbegin\n  intro a,\n  assume hm hsucc,\n  cases hm with b hb,\n  cases hsucc with c hc,\n  rw [\u2190add_one_succ, hb] at hc,\n  have : a \u2223 1,\n    apply dvd_remainder (b * a) 1 (c * a) a,\n    rw mul_comm,\n    apply dvd_mul, refl,\n    rw mul_comm,\n    apply dvd_mul, refl,\n    assumption,\n  from dvd_one this,\nend\n\ntheorem succ_coprime: coprime (succ m) m :=\ncoprime_symm coprime_succ\n\ntheorem coprime_prime (hp : prime p) :\n\u00ac(coprime p n) \u2192 p \u2223 n :=\nbegin\n  assume hncoprime,\n  unfold coprime at hncoprime,\n  rw not_forall at hncoprime,\n  cases hncoprime with k hk,\n  rw [not_imp, not_imp] at hk,\n  cases hp.right k hk.left; subst h,\n    exfalso,\n    from hk.right.right rfl,\n  from hk.right.left,\nend\n\nopen classical\n\nlocal attribute [instance] prop_decidable\n\nlemma nprime_imp_ncomp_or_one:\n\u00acprime m \u2192 composite m \u2228 m = 1 :=\nbegin\n  assume h,\n  cases not_and_distrib.mp h with heq hnall, {\n    right,\n    from not_not.mp heq,\n  }, {\n    left,\n    cases not_forall.mp hnall with k hk,\n    cases not_imp.mp hk with hkdvdm heq1m,\n    cases hkdvdm with a hak,\n    existsi a,\n    existsi k,\n    split, {\n      assume ha1,\n      rw [ha1, one_mul] at hak,\n      have : k = 1 \u2228 k = m,\n        right, symmetry, assumption,\n      contradiction,\n    }, split, {\n      assume hk1,\n      have : k = 1 \u2228 k = m,\n        left, assumption,\n      contradiction,\n    }, {\n      symmetry, assumption,\n    },\n  },\nend\n\n-- Requires strong induction\ntheorem prime_divisor:\nm \u2260 1 \u2192 \u2203 p: mynat, prime p \u2227 p \u2223 m :=\nbegin\n  assume h,\n  apply strong_induction\n    (\u03bb m, m \u2260 1 \u2192 \u2203 p: mynat, prime p \u2227 p \u2223 m), {\n    assume h,\n    existsi (2: mynat),\n    split, from two_prime,\n    from dvd_zero,\n  }, {\n    intro n,\n    assume hn hn0,\n    cases em (prime (succ n)) with hp hnp, {\n      existsi succ n,\n      split, assumption, refl,\n    }, {\n      have hcomp_or_one :=\n        nprime_imp_ncomp_or_one hnp,\n      cases hcomp_or_one with hcomp h1, {\n        cases hcomp with a h\u2081,\n        cases h\u2081 with b hab,\n        have ha\u2081 := hn a,\n        have hadvds : a \u2223 succ n, {\n          have := hab.right.right,\n          existsi b,\n          symmetry,\n          rw mul_comm,\n          assumption,\n        },\n        have halen: a \u2264 n, {\n          apply le_iff_lt_succ.mpr,\n          have hasn := dvd_le succ_ne_zero hadvds,\n          have hansn: a \u2260 succ n, {\n            -- the oldest trick in the book: just wear it down by\n            -- cases\n            assume hasn,\n            have habsn := hab.right.right,\n            rw [hasn] at habsn,\n            cases b,\n              simp at habsn,\n              from succ_ne_zero habsn.symm,\n            cases b,\n              simp at hab,\n              assumption,\n            suffices : succ (succ b) = 1,\n              rw [\u2190one_eq_succ_zero] at this,\n              suffices hcontra : succ b = 0,\n                from mynat.no_confusion hcontra,\n              apply succ_inj,\n              assumption,\n            apply @mul_cancel_to_one (succ n) _,\n              assume hsucc0,\n              from mynat.no_confusion hsucc0,\n            symmetry,\n            assumption,\n          },\n          rw le_iff_lt_or_eq at hasn,\n          cases hasn,\n          assumption,\n          contradiction,\n        },\n        have ha\u2082 := ha\u2081 halen hab.left,\n        cases ha\u2082 with p hp,\n        existsi p,\n        split, from hp.left,\n        from dvd_trans hp.right hadvds,\n      }, contradiction,\n    },\n  },\n  assumption,\nend\n\ntheorem infinitude_of_primes:\ninfinitely_many prime :=\nbegin\n  -- Famously, this is a proof by contradiction\n  by_contradiction h,\n  -- As there are only finitely many primes, there exists an n than\n  -- which there is no prime greater\n  cases not_forall.mp h with n hn,\n  -- So any x greater than n is not prime\n  have halln : \u2200 x, n \u2264 x \u2192 \u00acprime x, {\n    have := not_exists.mp hn,\n    assume x hnx hpx,\n    have hx := this x,\n    from hx \u27e8hnx, hpx\u27e9,\n  },\n  -- We can form a contradiction if we can exhibit a k which is not 1,\n  -- and is not divisible by anything less than n except 1\n  suffices:\n      \u2203 k : mynat, k \u2260 1 \u2227 \u2200 x : mynat, x \u2260 1 \u2192 x \u2264 n \u2192 \u00ac(x \u2223 k), {\n    cases this with k h\u2081,\n    have hk := h\u2081.right,\n    -- and is not divisible by any prime\n    have hnoprimediv : \u2200 p : mynat, prime p \u2192 \u00ac(p \u2223 k), {\n      -- Since assume we have some prime divisor p\n      assume p hp,\n      -- If p were more than n, it wouldn't be prime\n      have := halln p,\n      -- And it's greater than or equal to n\n      by_cases (n \u2264 p), {\n        -- Which is a contradiction,\n        exfalso,\n        from this h hp,\n      }, {\n        -- Or less than or equal to n, so doesn't divide k!\n        from hk p hp.left (lt_impl_le h),\n      },\n    },\n    -- Which directly contradicts the fact that every natural > 1 is\n    -- divisible by a prime\n    have hprimediv := prime_divisor h\u2081.left,\n    cases hprimediv with p hp,\n    from hnoprimediv p hp.left hp.right,\n  },\n  -- Exhibit (fact n) + 1, and we are done.\n  existsi (fact n) + 1,\n  split, {\n    assume h\u2081,\n    have heq := h\u2081.symm,\n    clear h\u2081,\n    rw add_comm at heq,\n    suffices : fact n = 0,\n      from fact_nzero this,\n    apply add_cancel_to_zero,\n    assumption,\n  },\n  from fact_ndvd_lt,\nend\n\nend mynat\n\nend hidden\n", "meta": {"author": "Sterrs", "repo": "leaning", "sha": "3901cc953694b33adda86cb88ca30ba99594db31", "save_path": "github-repos/lean/Sterrs-leaning", "path": "github-repos/lean/Sterrs-leaning/leaning-3901cc953694b33adda86cb88ca30ba99594db31/src/principia/mynat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7086670659442584}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n-/\nimport algebra.support\n\n/-!\n# Indicator function\n\n- `indicator (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) (a : \u03b1)` is `f a` if `a \u2208 s` and is `0` otherwise.\n- `mul_indicator (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) (a : \u03b1)` is `f a` if `a \u2208 s` and is `1` otherwise.\n\n\n## Implementation note\n\nIn mathematics, an indicator function or a characteristic function is a function\nused to indicate membership of an element in a set `s`,\nhaving the value `1` for all elements of `s` and the value `0` otherwise.\nBut since it is usually used to restrict a function to a certain set `s`,\nwe let the indicator function take the value `f x` for some function `f`, instead of `1`.\nIf the usual indicator function is needed, just set `f` to be the constant function `\u03bbx, 1`.\n\n## Tags\nindicator, characteristic\n-/\n\nnoncomputable theory\nopen_locale classical big_operators\nopen function\n\nvariables {\u03b1 \u03b2 \u03b9 M N : Type*}\n\nnamespace set\n\nsection has_one\nvariables [has_one M] [has_one N] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1}\n\n/-- `indicator s f a` is `f a` if `a \u2208 s`, `0` otherwise.  -/\ndef indicator {M} [has_zero M] (s : set \u03b1) (f : \u03b1 \u2192 M) : \u03b1 \u2192 M := \u03bb x, if x \u2208 s then f x else 0\n\n/-- `mul_indicator s f a` is `f a` if `a \u2208 s`, `1` otherwise.  -/\n@[to_additive]\ndef mul_indicator (s : set \u03b1) (f : \u03b1 \u2192 M) : \u03b1 \u2192 M := \u03bb x, if x \u2208 s then f x else 1\n\n@[simp, to_additive] lemma piecewise_eq_mul_indicator : s.piecewise f 1 = s.mul_indicator f := rfl\n\n@[to_additive] lemma mul_indicator_apply (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s f a = if a \u2208 s then f a else 1 := rfl\n\n@[simp, to_additive] lemma mul_indicator_of_mem (h : a \u2208 s) (f : \u03b1 \u2192 M) :\n  mul_indicator s f a = f a := if_pos h\n\n@[simp, to_additive] lemma mul_indicator_of_not_mem (h : a \u2209 s) (f : \u03b1 \u2192 M) :\n  mul_indicator s f a = 1 := if_neg h\n\n@[to_additive] lemma mul_indicator_eq_one_or_self (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s f a = 1 \u2228 mul_indicator s f a = f a :=\nif h : a \u2208 s then or.inr (mul_indicator_of_mem h f) else or.inl (mul_indicator_of_not_mem h f)\n\n@[simp, to_additive] lemma mul_indicator_apply_eq_self :\n  s.mul_indicator f a = f a \u2194 (a \u2209 s \u2192 f a = 1) :=\nite_eq_left_iff.trans $ by rw [@eq_comm _ (f a)]\n\n@[simp, to_additive] lemma mul_indicator_eq_self : s.mul_indicator f = f \u2194 mul_support f \u2286 s :=\nby simp only [funext_iff, subset_def, mem_mul_support, mul_indicator_apply_eq_self, not_imp_comm]\n\n@[to_additive] lemma mul_indicator_eq_self_of_superset (h1 : s.mul_indicator f = f) (h2 : s \u2286 t) :\n  t.mul_indicator f = f :=\nby { rw mul_indicator_eq_self at h1 \u22a2, exact subset.trans h1 h2 }\n\n@[simp, to_additive] lemma mul_indicator_apply_eq_one :\n  mul_indicator s f a = 1 \u2194 (a \u2208 s \u2192 f a = 1) :=\nite_eq_right_iff\n\n@[simp, to_additive] lemma mul_indicator_eq_one :\n  mul_indicator s f = (\u03bb x, 1) \u2194 disjoint (mul_support f) s :=\nby simp only [funext_iff, mul_indicator_apply_eq_one, set.disjoint_left, mem_mul_support,\n  not_imp_not]\n\n@[simp, to_additive] lemma mul_indicator_eq_one' :\n  mul_indicator s f = 1 \u2194 disjoint (mul_support f) s :=\nmul_indicator_eq_one\n\n@[to_additive] lemma mul_indicator_eq_one_iff (a : \u03b1) :\n  s.mul_indicator f a \u2260 1 \u2194 a \u2208 s \u2229 mul_support f :=\nbegin\n  split; intro h,\n  { by_contra hmem,\n    simp only [set.mem_inter_eq, not_and, not_not, function.mem_mul_support] at hmem,\n    refine h _,\n    by_cases a \u2208 s,\n    { simp_rw [set.mul_indicator, if_pos h],\n      exact hmem h },\n    { simp_rw [set.mul_indicator, if_neg h] } },\n  { simp_rw [set.mul_indicator, if_pos h.1],\n    exact h.2 }\nend\n\n@[simp, to_additive] lemma mul_support_mul_indicator :\n  function.mul_support (s.mul_indicator f) = s \u2229 function.mul_support f :=\next $ \u03bb x, by simp [function.mem_mul_support, mul_indicator_apply_eq_one]\n\n/-- If a multiplicative indicator function is not equal to one at a point, then that\npoint is in the set. -/\n@[to_additive] lemma mem_of_mul_indicator_ne_one (h : mul_indicator s f a \u2260 1) : a \u2208 s :=\nnot_imp_comm.1 (\u03bb hn, mul_indicator_of_not_mem hn f) h\n\n@[to_additive] lemma eq_on_mul_indicator : eq_on (mul_indicator s f) f s :=\n\u03bb x hx, mul_indicator_of_mem hx f\n\n@[to_additive] lemma mul_support_mul_indicator_subset : mul_support (s.mul_indicator f) \u2286 s :=\n\u03bb x hx, hx.imp_symm (\u03bb h, mul_indicator_of_not_mem h f)\n\n@[simp, to_additive] lemma mul_indicator_mul_support : mul_indicator (mul_support f) f = f :=\nmul_indicator_eq_self.2 subset.rfl\n\n@[simp, to_additive] lemma mul_indicator_range_comp {\u03b9 : Sort*} (f : \u03b9 \u2192 \u03b1) (g : \u03b1 \u2192 M) :\n  mul_indicator (range f) g \u2218 f = g \u2218 f :=\npiecewise_range_comp _ _ _\n\n@[to_additive] lemma mul_indicator_congr (h : eq_on f g s) :\n  mul_indicator s f = mul_indicator s g :=\nfunext $ \u03bbx, by { simp only [mul_indicator], split_ifs, { exact h h_1 }, refl }\n\n@[simp, to_additive] lemma mul_indicator_univ (f : \u03b1 \u2192 M) : mul_indicator (univ : set \u03b1) f = f :=\nmul_indicator_eq_self.2 $ subset_univ _\n\n@[simp, to_additive] lemma mul_indicator_empty (f : \u03b1 \u2192 M) : mul_indicator (\u2205 : set \u03b1) f = \u03bba, 1 :=\nmul_indicator_eq_one.2 $ disjoint_empty _\n\n@[to_additive] lemma mul_indicator_empty' (f : \u03b1 \u2192 M) : mul_indicator (\u2205 : set \u03b1) f = 1 :=\nmul_indicator_empty f\n\nvariable (M)\n\n@[simp, to_additive] lemma mul_indicator_one (s : set \u03b1) :\n  mul_indicator s (\u03bbx, (1:M)) = \u03bbx, (1:M) :=\nmul_indicator_eq_one.2 $ by simp only [mul_support_one, empty_disjoint]\n\n@[simp, to_additive] lemma mul_indicator_one' {s : set \u03b1} : s.mul_indicator (1 : \u03b1 \u2192 M) = 1 :=\nmul_indicator_one M s\n\nvariable {M}\n\n@[to_additive] lemma mul_indicator_mul_indicator (s t : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator s (mul_indicator t f) = mul_indicator (s \u2229 t) f :=\nfunext $ \u03bbx, by { simp only [mul_indicator], split_ifs, repeat {simp * at * {contextual := tt}} }\n\n@[simp, to_additive] lemma mul_indicator_inter_mul_support (s : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator (s \u2229 mul_support f) f = mul_indicator s f :=\nby rw [\u2190 mul_indicator_mul_indicator, mul_indicator_mul_support]\n\n@[to_additive] lemma comp_mul_indicator (h : M \u2192 \u03b2) (f : \u03b1 \u2192 M) {s : set \u03b1} {x : \u03b1} :\n  h (s.mul_indicator f x) = s.piecewise (h \u2218 f) (const \u03b1 (h 1)) x :=\ns.apply_piecewise _ _ (\u03bb _, h)\n\n@[to_additive] lemma mul_indicator_comp_right {s : set \u03b1} (f : \u03b2 \u2192 \u03b1) {g : \u03b1 \u2192 M} {x : \u03b2} :\n  mul_indicator (f \u207b\u00b9' s) (g \u2218 f) x = mul_indicator s g (f x) :=\nby { simp only [mul_indicator], split_ifs; refl }\n\n@[to_additive] lemma mul_indicator_comp_of_one {g : M \u2192 N} (hg : g 1 = 1) :\n  mul_indicator s (g \u2218 f) = g \u2218 (mul_indicator s f) :=\nbegin\n  funext,\n  simp only [mul_indicator],\n  split_ifs; simp [*]\nend\n\n@[to_additive] lemma comp_mul_indicator_const (c : M) (f : M \u2192 N) (hf : f 1 = 1) :\n  (\u03bb x, f (s.mul_indicator (\u03bb x, c) x)) = s.mul_indicator (\u03bb x, f c) :=\n(mul_indicator_comp_of_one hf).symm\n\n@[to_additive] lemma mul_indicator_preimage (s : set \u03b1) (f : \u03b1 \u2192 M) (B : set M) :\n  (mul_indicator s f)\u207b\u00b9' B = s.ite (f \u207b\u00b9' B) (1 \u207b\u00b9' B) :=\npiecewise_preimage s f 1 B\n\n@[to_additive] lemma mul_indicator_preimage_of_not_mem (s : set \u03b1) (f : \u03b1 \u2192 M)\n  {t : set M} (ht : (1:M) \u2209 t) :\n  (mul_indicator s f)\u207b\u00b9' t = f \u207b\u00b9' t \u2229 s :=\nby simp [mul_indicator_preimage, pi.one_def, set.preimage_const_of_not_mem ht]\n\n@[to_additive] lemma mem_range_mul_indicator {r : M} {s : set \u03b1} {f : \u03b1 \u2192 M} :\n  r \u2208 range (mul_indicator s f) \u2194 (r = 1 \u2227 s \u2260 univ) \u2228 (r \u2208 f '' s) :=\nby simp [mul_indicator, ite_eq_iff, exists_or_distrib, eq_univ_iff_forall, and_comm, or_comm,\n  @eq_comm _ r 1]\n\n@[to_additive] lemma mul_indicator_rel_mul_indicator {r : M \u2192 M \u2192 Prop} (h1 : r 1 1)\n  (ha : a \u2208 s \u2192 r (f a) (g a)) :\n  r (mul_indicator s f a) (mul_indicator s g a) :=\nby { simp only [mul_indicator], split_ifs with has has, exacts [ha has, h1] }\n\nend has_one\n\nsection monoid\nvariables [mul_one_class M] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1}\n\n@[to_additive] lemma mul_indicator_union_mul_inter_apply (f : \u03b1 \u2192 M) (s t : set \u03b1) (a : \u03b1) :\n  mul_indicator (s \u222a t) f a * mul_indicator (s \u2229 t) f a =\n    mul_indicator s f a * mul_indicator t f a :=\nby by_cases hs : a \u2208 s; by_cases ht : a \u2208 t; simp *\n\n@[to_additive] lemma mul_indicator_union_mul_inter (f : \u03b1 \u2192 M) (s t : set \u03b1) :\n  mul_indicator (s \u222a t) f * mul_indicator (s \u2229 t) f = mul_indicator s f * mul_indicator t f :=\nfunext $ mul_indicator_union_mul_inter_apply f s t\n\n@[to_additive] lemma mul_indicator_union_of_not_mem_inter (h : a \u2209 s \u2229 t) (f : \u03b1 \u2192 M) :\n  mul_indicator (s \u222a t) f a = mul_indicator s f a * mul_indicator t f a :=\nby rw [\u2190 mul_indicator_union_mul_inter_apply f s t, mul_indicator_of_not_mem h, mul_one]\n\n@[to_additive] lemma mul_indicator_union_of_disjoint (h : disjoint s t) (f : \u03b1 \u2192 M) :\n  mul_indicator (s \u222a t) f = \u03bba, mul_indicator s f a * mul_indicator t f a :=\nfunext $ \u03bba, mul_indicator_union_of_not_mem_inter (\u03bb ha, h ha) _\n\n@[to_additive] lemma mul_indicator_mul (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  mul_indicator s (\u03bba, f a * g a) = \u03bba, mul_indicator s f a * mul_indicator s g a :=\nby { funext, simp only [mul_indicator], split_ifs, { refl }, rw mul_one }\n\n@[simp, to_additive] lemma mul_indicator_compl_mul_self_apply (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s\u1d9c f a * mul_indicator s f a = f a :=\nclassical.by_cases (\u03bb ha : a \u2208 s, by simp [ha]) (\u03bb ha, by simp [ha])\n\n@[simp, to_additive] lemma mul_indicator_compl_mul_self (s : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator s\u1d9c f * mul_indicator s f = f :=\nfunext $ mul_indicator_compl_mul_self_apply s f\n\n@[simp, to_additive] lemma mul_indicator_self_mul_compl_apply (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s f a * mul_indicator s\u1d9c f a = f a :=\nclassical.by_cases (\u03bb ha : a \u2208 s, by simp [ha]) (\u03bb ha, by simp [ha])\n\n@[simp, to_additive] \n\n@[to_additive] lemma mul_indicator_mul_eq_left {f g : \u03b1 \u2192 M}\n  (h : disjoint (mul_support f) (mul_support g)) :\n  (mul_support f).mul_indicator (f * g) = f :=\nbegin\n  refine (mul_indicator_congr $ \u03bb x hx, _).trans mul_indicator_mul_support,\n  have : g x = 1, from nmem_mul_support.1 (disjoint_left.1 h hx),\n  rw [pi.mul_apply, this, mul_one]\nend\n\n@[to_additive] lemma mul_indicator_mul_eq_right {f g : \u03b1 \u2192 M}\n  (h : disjoint (mul_support f) (mul_support g)) :\n  (mul_support g).mul_indicator (f * g) = g :=\nbegin\n  refine (mul_indicator_congr $ \u03bb x hx, _).trans mul_indicator_mul_support,\n  have : f x = 1, from nmem_mul_support.1 (disjoint_right.1 h hx),\n  rw [pi.mul_apply, this, one_mul]\nend\n\n/-- `set.mul_indicator` as a `monoid_hom`. -/\n@[to_additive \"`set.indicator` as an `add_monoid_hom`.\"]\ndef mul_indicator_hom {\u03b1} (M) [mul_one_class M] (s : set \u03b1) : (\u03b1 \u2192 M) \u2192* (\u03b1 \u2192 M) :=\n{ to_fun := mul_indicator s,\n  map_one' := mul_indicator_one M s,\n  map_mul' := mul_indicator_mul s }\n\nend monoid\n\nsection distrib_mul_action\n\nvariables {A : Type*} [add_monoid A] [monoid M] [distrib_mul_action M A]\n\nlemma indicator_smul_apply (s : set \u03b1) (r : M) (f : \u03b1 \u2192 A) (x : \u03b1) :\n  indicator s (\u03bb x, r \u2022 f x) x = r \u2022 indicator s f x :=\nby { dunfold indicator, split_ifs, exacts [rfl, (smul_zero r).symm] }\n\nlemma indicator_smul (s : set \u03b1) (r : M) (f : \u03b1 \u2192 A) :\n  indicator s (\u03bb (x : \u03b1), r \u2022 f x) = \u03bb (x : \u03b1), r \u2022 indicator s f x :=\nfunext $ indicator_smul_apply s r f\n\nend distrib_mul_action\n\nsection group\nvariables {G : Type*} [group G] {s t : set \u03b1} {f g : \u03b1 \u2192 G} {a : \u03b1}\n\n@[to_additive] lemma mul_indicator_inv' (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  mul_indicator s (f\u207b\u00b9) = (mul_indicator s f)\u207b\u00b9 :=\n(mul_indicator_hom G s).map_inv f\n\n@[to_additive] lemma mul_indicator_inv (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  mul_indicator s (\u03bba, (f a)\u207b\u00b9) = \u03bba, (mul_indicator s f a)\u207b\u00b9 :=\nmul_indicator_inv' s f\n\nlemma indicator_sub {G} [add_group G] (s : set \u03b1) (f g : \u03b1 \u2192 G) :\n  indicator s (\u03bba, f a - g a) = \u03bba, indicator s f a - indicator s g a :=\n(indicator_hom G s).map_sub f g\n\n@[to_additive indicator_compl'] lemma mul_indicator_compl (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  mul_indicator s\u1d9c f = f * (mul_indicator s f)\u207b\u00b9 :=\neq_mul_inv_of_mul_eq $ s.mul_indicator_compl_mul_self f\n\nlemma indicator_compl {G} [add_group G] (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  indicator s\u1d9c f = f - indicator s f :=\nby rw [sub_eq_add_neg, indicator_compl']\n\n@[to_additive indicator_diff'] lemma mul_indicator_diff (h : s \u2286 t) (f : \u03b1 \u2192 G) :\n  mul_indicator (t \\ s) f = mul_indicator t f * (mul_indicator s f)\u207b\u00b9 :=\neq_mul_inv_of_mul_eq $ by rw [pi.mul_def, \u2190 mul_indicator_union_of_disjoint disjoint_diff.symm f,\n  diff_union_self, union_eq_self_of_subset_right h]\n\nlemma indicator_diff {G : Type*} [add_group G] {s t : set \u03b1} (h : s \u2286 t) (f : \u03b1 \u2192 G) :\n  indicator (t \\ s) f = indicator t f - indicator s f :=\nby rw [indicator_diff' h, sub_eq_add_neg]\n\nend group\n\nsection comm_monoid\n\nvariables [comm_monoid M]\n\n/-- Consider a product of `g i (f i)` over a `finset`.  Suppose `g` is a\nfunction such as `pow`, which maps a second argument of `1` to\n`1`. Then if `f` is replaced by the corresponding multiplicative indicator\nfunction, the `finset` may be replaced by a possibly larger `finset`\nwithout changing the value of the sum. -/\n@[to_additive] lemma prod_mul_indicator_subset_of_eq_one [has_one N] (f : \u03b1 \u2192 N)\n  (g : \u03b1 \u2192 N \u2192 M) {s t : finset \u03b1} (h : s \u2286 t) (hg : \u2200 a, g a 1 = 1) :\n  \u220f i in s, g i (f i) = \u220f i in t, g i (mul_indicator \u2191s f i) :=\nbegin\n  rw \u2190 finset.prod_subset h _,\n  { apply finset.prod_congr rfl,\n    intros i hi,\n    congr,\n    symmetry,\n    exact mul_indicator_of_mem hi _ },\n  { refine \u03bb i hi hn, _,\n    convert hg i,\n    exact mul_indicator_of_not_mem hn _ }\nend\n\n/-- Consider a sum of `g i (f i)` over a `finset`.  Suppose `g` is a\nfunction such as multiplication, which maps a second argument of 0 to\n0.  (A typical use case would be a weighted sum of `f i * h i` or `f i\n\u2022 h i`, where `f` gives the weights that are multiplied by some other\nfunction `h`.)  Then if `f` is replaced by the corresponding indicator\nfunction, the `finset` may be replaced by a possibly larger `finset`\nwithout changing the value of the sum. -/\nadd_decl_doc set.sum_indicator_subset_of_eq_zero\n\n@[to_additive] lemma prod_mul_indicator_subset (f : \u03b1 \u2192 M) {s t : finset \u03b1} (h : s \u2286 t) :\n  \u220f i in s, f i = \u220f i in t, mul_indicator \u2191s f i :=\nprod_mul_indicator_subset_of_eq_one _ (\u03bb a b, b) h (\u03bb _, rfl)\n\n/-- Summing an indicator function over a possibly larger `finset` is\nthe same as summing the original function over the original\n`finset`. -/\nadd_decl_doc sum_indicator_subset\n\n@[to_additive] lemma _root_.finset.prod_mul_indicator_eq_prod_filter\n  (s : finset \u03b9) (f : \u03b9 \u2192 \u03b1 \u2192 M) (t : \u03b9 \u2192 set \u03b1) (g : \u03b9 \u2192 \u03b1) :\n  \u220f i in s, mul_indicator (t i) (f i) (g i) = \u220f i in s.filter (\u03bb i, g i \u2208 t i), f i (g i) :=\nbegin\n  refine (finset.prod_filter_mul_prod_filter_not s (\u03bb i, g i \u2208 t i) _).symm.trans _,\n  refine eq.trans _ (mul_one _),\n  exact congr_arg2 (*)\n    (finset.prod_congr rfl $ \u03bb x hx, mul_indicator_of_mem (finset.mem_filter.1 hx).2 _)\n    (finset.prod_eq_one $ \u03bb x hx, mul_indicator_of_not_mem (finset.mem_filter.1 hx).2 _)\nend\n\n@[to_additive] lemma mul_indicator_finset_prod (I : finset \u03b9) (s : set \u03b1) (f : \u03b9 \u2192 \u03b1 \u2192 M) :\n  mul_indicator s (\u220f i in I, f i) = \u220f i in I, mul_indicator s (f i) :=\n(mul_indicator_hom M s).map_prod _ _\n\n@[to_additive] lemma mul_indicator_finset_bUnion {\u03b9} (I : finset \u03b9)\n  (s : \u03b9 \u2192 set \u03b1) {f : \u03b1 \u2192 M} : (\u2200 (i \u2208 I) (j \u2208 I), i \u2260 j \u2192 disjoint (s i) (s j)) \u2192\n  mul_indicator (\u22c3 i \u2208 I, s i) f = \u03bb a, \u220f i in I, mul_indicator (s i) f a :=\nbegin\n  refine finset.induction_on I _ _,\n  { intro h, funext, simp },\n  assume a I haI ih hI,\n  funext,\n  rw [finset.prod_insert haI, finset.set_bUnion_insert, mul_indicator_union_of_not_mem_inter, ih _],\n  { assume i hi j hj hij,\n    exact hI i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij },\n  simp only [not_exists, exists_prop, mem_Union, mem_inter_eq, not_and],\n  assume hx a' ha',\n  refine disjoint_left.1 (hI a (finset.mem_insert_self _ _) a' (finset.mem_insert_of_mem ha') _) hx,\n  exact (ne_of_mem_of_not_mem ha' haI).symm\nend\n\nend comm_monoid\n\nsection mul_zero_class\n\nvariables [mul_zero_class M] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1}\n\nlemma indicator_mul (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  indicator s (\u03bba, f a * g a) = \u03bba, indicator s f a * indicator s g a :=\nby { funext, simp only [indicator], split_ifs, { refl }, rw mul_zero }\n\nlemma indicator_mul_left (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  indicator s (\u03bba, f a * g a) a = indicator s f a * g a :=\nby { simp only [indicator], split_ifs, { refl }, rw [zero_mul] }\n\nlemma indicator_mul_right (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  indicator s (\u03bba, f a * g a) a = f a * indicator s g a :=\nby { simp only [indicator], split_ifs, { refl }, rw [mul_zero] }\n\nlemma inter_indicator_mul {t1 t2 : set \u03b1} (f g : \u03b1 \u2192 M) (x : \u03b1) :\n  (t1 \u2229 t2).indicator (\u03bb x, f x * g x) x = t1.indicator f x * t2.indicator g x :=\nby { rw [\u2190 set.indicator_indicator], simp [indicator] }\n\nend mul_zero_class\n\nsection monoid_with_zero\n\nvariables [monoid_with_zero M]\n\nlemma indicator_prod_one {s : set \u03b1} {t : set \u03b2} {x : \u03b1} {y : \u03b2} :\n  (s.prod t).indicator (1 : _ \u2192 M) (x, y) = s.indicator 1 x * t.indicator 1 y :=\nby simp [indicator, \u2190 ite_and]\n\nend monoid_with_zero\n\nsection order\nvariables [has_one M] [preorder M] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1} {y : M}\n\n@[to_additive] lemma mul_indicator_apply_le' (hfg : a \u2208 s \u2192 f a \u2264 y) (hg : a \u2209 s \u2192 1 \u2264 y) :\n  mul_indicator s f a \u2264 y :=\nif ha : a \u2208 s then by simpa [ha] using hfg ha else by simpa [ha] using hg ha\n\n@[to_additive] lemma mul_indicator_le' (hfg : \u2200 a \u2208 s, f a \u2264 g a) (hg : \u2200 a \u2209 s, 1 \u2264 g a) :\n  mul_indicator s f \u2264 g :=\n\u03bb a, mul_indicator_apply_le' (hfg _) (hg _)\n\n@[to_additive] lemma le_mul_indicator_apply {y} (hfg : a \u2208 s \u2192 y \u2264 g a) (hf : a \u2209 s \u2192 y \u2264 1) :\n  y \u2264 mul_indicator s g a :=\n@mul_indicator_apply_le' \u03b1 (order_dual M) \u2039_\u203a _ _ _ _ _ hfg hf\n\n@[to_additive] lemma le_mul_indicator (hfg : \u2200 a \u2208 s, f a \u2264 g a) (hf : \u2200 a \u2209 s, f a \u2264 1) :\n  f \u2264 mul_indicator s g :=\n\u03bb a, le_mul_indicator_apply (hfg _) (hf _)\n\n@[to_additive indicator_apply_nonneg]\nlemma one_le_mul_indicator_apply (h : a \u2208 s \u2192 1 \u2264 f a) : 1 \u2264 mul_indicator s f a :=\nle_mul_indicator_apply h (\u03bb _, le_rfl)\n\n@[to_additive indicator_nonneg]\nlemma one_le_mul_indicator (h : \u2200 a \u2208 s, 1 \u2264 f a) (a : \u03b1) : 1 \u2264 mul_indicator s f a :=\none_le_mul_indicator_apply (h a)\n\n@[to_additive] lemma mul_indicator_apply_le_one (h : a \u2208 s \u2192 f a \u2264 1) : mul_indicator s f a \u2264 1 :=\nmul_indicator_apply_le' h (\u03bb _, le_rfl)\n\n@[to_additive] lemma mul_indicator_le_one (h : \u2200 a \u2208 s, f a \u2264 1) (a : \u03b1) :\n  mul_indicator s f a \u2264 1 :=\nmul_indicator_apply_le_one (h a)\n\n@[to_additive] lemma mul_indicator_le_mul_indicator (h : f a \u2264 g a) :\n  mul_indicator s f a \u2264 mul_indicator s g a :=\nmul_indicator_rel_mul_indicator (le_refl _) (\u03bb _, h)\n\nattribute [mono] mul_indicator_le_mul_indicator indicator_le_indicator\n\n@[to_additive] lemma mul_indicator_le_mul_indicator_of_subset (h : s \u2286 t) (hf : \u2200 a, 1 \u2264 f a)\n  (a : \u03b1) :\n  mul_indicator s f a \u2264 mul_indicator t f a :=\nmul_indicator_apply_le' (\u03bb ha, le_mul_indicator_apply (\u03bb _, le_rfl) (\u03bb hat, (hat $ h ha).elim))\n  (\u03bb ha, one_le_mul_indicator_apply (\u03bb _, hf _))\n\n@[to_additive] lemma mul_indicator_le_self' (hf : \u2200 x \u2209 s, 1 \u2264 f x) : mul_indicator s f \u2264 f :=\nmul_indicator_le' (\u03bb _ _, le_refl _) hf\n\n@[to_additive] lemma mul_indicator_Union_apply {\u03b9 M} [complete_lattice M] [has_one M]\n  (h1 : (\u22a5:M) = 1) (s : \u03b9 \u2192 set \u03b1) (f : \u03b1 \u2192 M) (x : \u03b1) :\n  mul_indicator (\u22c3 i, s i) f x = \u2a06 i, mul_indicator (s i) f x :=\nbegin\n  by_cases hx : x \u2208 \u22c3 i, s i,\n  { rw [mul_indicator_of_mem hx],\n    rw [mem_Union] at hx,\n    refine le_antisymm _ (supr_le $ \u03bb i, mul_indicator_le_self' (\u03bb x hx, h1 \u25b8 bot_le) x),\n    rcases hx with \u27e8i, hi\u27e9,\n    exact le_supr_of_le i (ge_of_eq $ mul_indicator_of_mem hi _) },\n  { rw [mul_indicator_of_not_mem hx],\n    simp only [mem_Union, not_exists] at hx,\n    simp [hx, \u2190 h1] }\nend\n\nend order\n\nsection canonically_ordered_monoid\n\nvariables [canonically_ordered_monoid M]\n\n@[to_additive] lemma mul_indicator_le_self (s : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator s f \u2264 f :=\nmul_indicator_le_self' $ \u03bb _ _, one_le _\n\n@[to_additive] lemma mul_indicator_apply_le {a : \u03b1} {s : set \u03b1} {f g : \u03b1 \u2192 M}\n  (hfg : a \u2208 s \u2192 f a \u2264 g a) :\n  mul_indicator s f a \u2264 g a :=\nmul_indicator_apply_le' hfg $ \u03bb _, one_le _\n\n@[to_additive] lemma mul_indicator_le {s : set \u03b1} {f g : \u03b1 \u2192 M} (hfg : \u2200 a \u2208 s, f a \u2264 g a) :\n  mul_indicator s f \u2264 g :=\nmul_indicator_le' hfg $ \u03bb _ _, one_le _\n\nend canonically_ordered_monoid\n\nlemma indicator_le_indicator_nonneg {\u03b2} [linear_order \u03b2] [has_zero \u03b2] (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  s.indicator f \u2264 {x | 0 \u2264 f x}.indicator f :=\nbegin\n  intro x,\n  simp_rw indicator_apply,\n  split_ifs,\n  { exact le_rfl, },\n  { exact (not_le.mp h_1).le, },\n  { exact h_1, },\n  { exact le_rfl, },\nend\n\nlemma indicator_nonpos_le_indicator {\u03b2} [linear_order \u03b2] [has_zero \u03b2] (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  {x | f x \u2264 0}.indicator f \u2264 s.indicator f :=\n@indicator_le_indicator_nonneg \u03b1 (order_dual \u03b2) _ _ s f\n\nend set\n\n@[to_additive] lemma monoid_hom.map_mul_indicator {M N : Type*} [monoid M] [monoid N] (f : M \u2192* N)\n  (s : set \u03b1) (g : \u03b1 \u2192 M) (x : \u03b1) :\n  f (s.mul_indicator g x) = s.mul_indicator (f \u2218 g) x :=\ncongr_fun (set.mul_indicator_comp_of_one f.map_one).symm x\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/indicator_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7086473930093145}}
{"text": "/-\nCopyright (c) 2021 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, S\u00e9bastien Gou\u00ebzel\n-/\nimport measure_theory.measure.lebesgue\nimport measure_theory.measure.haar\nimport linear_algebra.finite_dimensional\n\n/-!\n# Relationship between the Haar and Lebesgue measures\n\nWe prove that the Haar measure and Lebesgue measure are equal on `\u211d` and on `\u211d^\u03b9`, in\n`measure_theory.add_haar_measure_eq_volume` and `measure_theory.add_haar_measure_eq_volume_pi`.\n\nWe deduce basic properties of any Haar measure on a finite dimensional real vector space:\n* `map_linear_map_add_haar_eq_smul_add_haar`: a linear map rescales the Haar measure by the\n  absolute value of its determinant.\n* `add_haar_smul` : the measure of `r \u2022 s` is `|r| ^ dim * \u03bc s`.\n* `add_haar_ball`: the measure of `ball x r` is `r ^ dim * \u03bc (ball 0 1)`.\n* `add_haar_closed_ball`: the measure of `closed_ball x r` is `r ^ dim * \u03bc (ball 0 1)`.\n* `add_haar_sphere`: spheres have zero measure.\n\n-/\n\nopen topological_space set filter metric\nopen_locale ennreal pointwise topological_space\n\n/-- The interval `[0,1]` as a compact set with non-empty interior. -/\ndef topological_space.positive_compacts.Icc01 : positive_compacts \u211d :=\n\u27e8Icc 0 1, is_compact_Icc, by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one]\u27e9\n\nuniverse u\n\n/-- The set `[0,1]^\u03b9` as a compact set with non-empty interior. -/\ndef topological_space.positive_compacts.pi_Icc01 (\u03b9 : Type*) [fintype \u03b9] :\n  positive_compacts (\u03b9 \u2192 \u211d) :=\n\u27e8set.pi set.univ (\u03bb i, Icc 0 1), is_compact_univ_pi (\u03bb i, is_compact_Icc),\nby simp only [interior_pi_set, finite.of_fintype, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo,\n  implies_true_iff, zero_lt_one]\u27e9\n\nnamespace measure_theory\n\nopen measure topological_space.positive_compacts finite_dimensional\n\n/-!\n### The Lebesgue measure is a Haar measure on `\u211d` and on `\u211d^\u03b9`.\n-/\n\nlemma is_add_left_invariant_real_volume : is_add_left_invariant \u21d1(volume : measure \u211d) :=\nby simp [\u2190 map_add_left_eq_self, real.map_volume_add_left]\n\n/-- The Haar measure equals the Lebesgue measure on `\u211d`. -/\nlemma add_haar_measure_eq_volume : add_haar_measure Icc01 = volume :=\nbegin\n  convert (add_haar_measure_unique _ Icc01).symm,\n  { simp [Icc01] },\n  { apply_instance },\n  { exact is_add_left_invariant_real_volume }\nend\n\ninstance : is_add_haar_measure (volume : measure \u211d) :=\nby { rw \u2190 add_haar_measure_eq_volume, apply_instance }\n\nlemma is_add_left_invariant_real_volume_pi (\u03b9 : Type*) [fintype \u03b9] :\n  is_add_left_invariant \u21d1(volume : measure (\u03b9 \u2192 \u211d)) :=\nby simp [\u2190 map_add_left_eq_self, real.map_volume_pi_add_left]\n\n/-- The Haar measure equals the Lebesgue measure on `\u211d^\u03b9`. -/\nlemma add_haar_measure_eq_volume_pi (\u03b9 : Type*) [fintype \u03b9] :\n  add_haar_measure (pi_Icc01 \u03b9) = volume :=\nbegin\n  convert (add_haar_measure_unique _ (pi_Icc01 \u03b9)).symm,\n  { simp only [pi_Icc01, volume_pi_pi (\u03bb i, Icc (0 : \u211d) 1),\n      finset.prod_const_one, ennreal.of_real_one, real.volume_Icc, one_smul, sub_zero] },\n  { apply_instance },\n  { exact is_add_left_invariant_real_volume_pi \u03b9 }\nend\n\ninstance is_add_haar_measure_volume_pi (\u03b9 : Type*) [fintype \u03b9] :\n  is_add_haar_measure (volume : measure (\u03b9 \u2192 \u211d)) :=\nby { rw \u2190 add_haar_measure_eq_volume_pi, apply_instance }\n\nnamespace measure\n\n/-!\n### Applying a linear map rescales Haar measure by the determinant\n\nWe first prove this on `\u03b9 \u2192 \u211d`, using that this is already known for the product Lebesgue\nmeasure (thanks to matrices computations). Then, we extend this to any finite-dimensional real\nvector space by using a linear equiv with a space of the form `\u03b9 \u2192 \u211d`, and arguing that such a\nlinear equiv maps Haar measure to Haar measure.\n-/\n\nlemma map_linear_map_add_haar_pi_eq_smul_add_haar\n  {\u03b9 : Type*} [fintype \u03b9] {f : (\u03b9 \u2192 \u211d) \u2192\u2097[\u211d] (\u03b9 \u2192 \u211d)} (hf : f.det \u2260 0)\n  (\u03bc : measure (\u03b9 \u2192 \u211d)) [is_add_haar_measure \u03bc] :\n  measure.map f \u03bc = ennreal.of_real (abs (f.det)\u207b\u00b9) \u2022 \u03bc :=\nbegin\n  /- We have already proved the result for the Lebesgue product measure, using matrices.\n  We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/\n  have := add_haar_measure_unique (is_add_left_invariant_add_haar \u03bc) (pi_Icc01 \u03b9),\n  conv_lhs { rw this }, conv_rhs { rw this },\n  simp [add_haar_measure_eq_volume_pi, real.map_linear_map_volume_pi_eq_smul_volume_pi hf,\n    smul_smul, mul_comm],\nend\n\nlemma map_linear_map_add_haar_eq_smul_add_haar\n  {E : Type*} [normed_group E] [normed_space \u211d E] [measurable_space E] [borel_space E]\n  [finite_dimensional \u211d E] (\u03bc : measure E) [is_add_haar_measure \u03bc]\n  {f : E \u2192\u2097[\u211d] E} (hf : f.det \u2260 0) :\n  measure.map f \u03bc = ennreal.of_real (abs (f.det)\u207b\u00b9) \u2022 \u03bc :=\nbegin\n  -- we reduce to the case of `E = \u03b9 \u2192 \u211d`, for which we have already proved the result using\n  -- matrices in `map_linear_map_haar_pi_eq_smul_haar`.\n  let \u03b9 := fin (finrank \u211d E),\n  haveI : finite_dimensional \u211d (\u03b9 \u2192 \u211d) := by apply_instance,\n  have : finrank \u211d E = finrank \u211d (\u03b9 \u2192 \u211d), by simp,\n  have e : E \u2243\u2097[\u211d] \u03b9 \u2192 \u211d := linear_equiv.of_finrank_eq E (\u03b9 \u2192 \u211d) this,\n  -- next line is to avoid `g` getting reduced by `simp`.\n  obtain \u27e8g, hg\u27e9 : \u2203 g, g = (e : E \u2192\u2097[\u211d] (\u03b9 \u2192 \u211d)).comp (f.comp (e.symm : (\u03b9 \u2192 \u211d) \u2192\u2097[\u211d] E)) :=\n    \u27e8_, rfl\u27e9,\n  have gdet : g.det = f.det, by { rw [hg], exact linear_map.det_conj f e },\n  rw \u2190 gdet at hf \u22a2,\n  have fg : f = (e.symm : (\u03b9 \u2192 \u211d) \u2192\u2097[\u211d] E).comp (g.comp (e : E \u2192\u2097[\u211d] (\u03b9 \u2192 \u211d))),\n  { ext x,\n    simp only [linear_equiv.coe_coe, function.comp_app, linear_map.coe_comp,\n      linear_equiv.symm_apply_apply, hg] },\n  simp only [fg, linear_equiv.coe_coe, linear_map.coe_comp],\n  have Ce : continuous e := (e : E \u2192\u2097[\u211d] (\u03b9 \u2192 \u211d)).continuous_of_finite_dimensional,\n  have Cg : continuous g := linear_map.continuous_of_finite_dimensional g,\n  have Cesymm : continuous e.symm := (e.symm : (\u03b9 \u2192 \u211d) \u2192\u2097[\u211d] E).continuous_of_finite_dimensional,\n  rw [\u2190 map_map Cesymm.measurable (Cg.comp Ce).measurable, \u2190 map_map Cg.measurable Ce.measurable],\n  haveI : is_add_haar_measure (map e \u03bc) := is_add_haar_measure_map \u03bc e.to_add_equiv Ce Cesymm,\n  have ecomp : (e.symm) \u2218 e = id,\n    by { ext x, simp only [id.def, function.comp_app, linear_equiv.symm_apply_apply] },\n  rw [map_linear_map_add_haar_pi_eq_smul_add_haar hf (map e \u03bc), linear_map.map_smul,\n    map_map Cesymm.measurable Ce.measurable, ecomp, measure.map_id]\nend\n\n@[simp] lemma haar_preimage_linear_map\n  {E : Type*} [normed_group E] [normed_space \u211d E] [measurable_space E] [borel_space E]\n  [finite_dimensional \u211d E] (\u03bc : measure E) [is_add_haar_measure \u03bc]\n  {f : E \u2192\u2097[\u211d] E} (hf : f.det \u2260 0) (s : set E) :\n  \u03bc (f \u207b\u00b9' s) = ennreal.of_real (abs (f.det)\u207b\u00b9) * \u03bc s :=\ncalc \u03bc (f \u207b\u00b9' s) = measure.map f \u03bc s :\n  ((f.equiv_of_det_ne_zero hf).to_continuous_linear_equiv.to_homeomorph\n    .to_measurable_equiv.map_apply s).symm\n... = ennreal.of_real (abs (f.det)\u207b\u00b9) * \u03bc s :\n  by { rw map_linear_map_add_haar_eq_smul_add_haar \u03bc hf, refl }\n\n/-!\n### Basic properties of Haar measures on real vector spaces\n-/\n\nvariables {E : Type*} [normed_group E] [measurable_space E] [normed_space \u211d E]\n  [finite_dimensional \u211d E] [borel_space E] (\u03bc : measure E) [is_add_haar_measure \u03bc]\n\nlemma map_add_haar_smul {r : \u211d} (hr : r \u2260 0) :\n  measure.map ((\u2022) r) \u03bc = ennreal.of_real (abs (r ^ (finrank \u211d E))\u207b\u00b9) \u2022 \u03bc :=\nbegin\n  let f : E \u2192\u2097[\u211d] E := r \u2022 1,\n  change measure.map f \u03bc = _,\n  have hf : f.det \u2260 0,\n  { simp only [mul_one, linear_map.det_smul, ne.def, monoid_hom.map_one],\n    assume h,\n    exact hr (pow_eq_zero h) },\n  simp only [map_linear_map_add_haar_eq_smul_add_haar \u03bc hf, mul_one, linear_map.det_smul,\n    monoid_hom.map_one],\nend\n\nlemma add_haar_preimage_smul {r : \u211d} (hr : r \u2260 0) (s : set E) :\n  \u03bc (((\u2022) r) \u207b\u00b9' s) = ennreal.of_real (abs (r ^ (finrank \u211d E))\u207b\u00b9) * \u03bc s :=\ncalc \u03bc (((\u2022) r) \u207b\u00b9' s) = measure.map ((\u2022) r) \u03bc s :\n  ((homeomorph.smul (is_unit_iff_ne_zero.2 hr).unit).to_measurable_equiv.map_apply s).symm\n... = ennreal.of_real (abs (r^(finrank \u211d E))\u207b\u00b9) * \u03bc s : by { rw map_add_haar_smul \u03bc hr, refl }\n\n/-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/\nlemma add_haar_smul (r : \u211d) (s : set E) :\n  \u03bc (r \u2022 s) = ennreal.of_real (abs (r ^ (finrank \u211d E))) * \u03bc s :=\nbegin\n  rcases ne_or_eq r 0 with h|rfl,\n  { rw [\u2190 preimage_smul_inv\u2080 h, add_haar_preimage_smul \u03bc (inv_ne_zero h), inv_pow\u2080, inv_inv\u2080] },\n  rcases eq_empty_or_nonempty s with rfl|hs,\n  { simp only [measure_empty, mul_zero, smul_set_empty] },\n  rw [zero_smul_set hs, \u2190 singleton_zero],\n  by_cases h : finrank \u211d E = 0,\n  { haveI : subsingleton E := finrank_zero_iff.1 h,\n    simp only [h, one_mul, ennreal.of_real_one, abs_one, subsingleton.eq_univ_of_nonempty hs,\n      pow_zero, subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))] },\n  { haveI : nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h),\n    simp only [h, zero_mul, ennreal.of_real_zero, abs_zero, ne.def, not_false_iff, zero_pow',\n      measure_singleton] }\nend\n\n/-! We don't need to state `map_add_haar_neg` here, because it has already been proved for\ngeneral Haar measures on general commutative groups. -/\n\n/-! ### Measure of balls -/\n\nlemma add_haar_ball_center\n  {E : Type*} [normed_group E] [measurable_space E]\n  [borel_space E] (\u03bc : measure E) [is_add_haar_measure \u03bc] (x : E) (r : \u211d) :\n  \u03bc (ball x r) = \u03bc (ball (0 : E) r) :=\nbegin\n  have : ball (0 : E) r = ((+) x) \u207b\u00b9' (ball x r), by simp [preimage_add_ball],\n  rw [this, add_haar_preimage_add]\nend\n\nlemma add_haar_closed_ball_center\n  {E : Type*} [normed_group E] [measurable_space E]\n  [borel_space E] (\u03bc : measure E) [is_add_haar_measure \u03bc] (x : E) (r : \u211d) :\n  \u03bc (closed_ball x r) = \u03bc (closed_ball (0 : E) r) :=\nbegin\n  have : closed_ball (0 : E) r = ((+) x) \u207b\u00b9' (closed_ball x r), by simp [preimage_add_closed_ball],\n  rw [this, add_haar_preimage_add]\nend\n\nlemma add_haar_closed_ball_lt_top {E : Type*} [normed_group E] [proper_space E] [measurable_space E]\n  (\u03bc : measure E) [is_add_haar_measure \u03bc] (x : E) (r : \u211d) :\n  \u03bc (closed_ball x r) < \u221e :=\n(proper_space.is_compact_closed_ball x r).add_haar_lt_top \u03bc\n\nlemma add_haar_ball_lt_top {E : Type*} [normed_group E] [proper_space E] [measurable_space E]\n  (\u03bc : measure E) [is_add_haar_measure \u03bc] (x : E) (r : \u211d) :\n  \u03bc (ball x r) < \u221e :=\nlt_of_le_of_lt (measure_mono ball_subset_closed_ball) (add_haar_closed_ball_lt_top \u03bc x r)\n\nlemma add_haar_ball_pos {E : Type*} [normed_group E] [measurable_space E]\n  (\u03bc : measure E) [is_add_haar_measure \u03bc] (x : E) {r : \u211d} (hr : 0 < r) :\n  0 < \u03bc (ball x r) :=\nis_open_ball.add_haar_pos \u03bc (nonempty_ball.2 hr)\n\nlemma add_haar_closed_ball_pos {E : Type*} [normed_group E] [measurable_space E]\n  (\u03bc : measure E) [is_add_haar_measure \u03bc] (x : E) {r : \u211d} (hr : 0 < r) :\n  0 < \u03bc (closed_ball x r) :=\nlt_of_lt_of_le (add_haar_ball_pos \u03bc x hr) (measure_mono ball_subset_closed_ball)\n\nlemma add_haar_ball_of_pos (x : E) {r : \u211d} (hr : 0 < r) :\n  \u03bc (ball x r) = ennreal.of_real (r ^ (finrank \u211d E)) * \u03bc (ball 0 1) :=\nbegin\n  have : ball (0 : E) r = r \u2022 ball 0 1,\n    by simp [smul_ball hr.ne' (0 : E) 1, real.norm_eq_abs, abs_of_nonneg hr.le],\n  simp [this, add_haar_smul, abs_of_nonneg hr.le, add_haar_ball_center],\nend\n\nlemma add_haar_ball [nontrivial E] (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  \u03bc (ball x r) = ennreal.of_real (r ^ (finrank \u211d E)) * \u03bc (ball 0 1) :=\nbegin\n  rcases has_le.le.eq_or_lt hr with h|h,\n  { simp [\u2190 h, zero_pow finrank_pos] },\n  { exact add_haar_ball_of_pos \u03bc x h }\nend\n\n/-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball.\nUse instead `add_haar_closed_ball`, which uses the measure of the open unit ball as a standard\nform. -/\n\n\nlemma add_haar_closed_unit_ball_eq_add_haar_unit_ball :\n  \u03bc (closed_ball (0 : E) 1) = \u03bc (ball 0 1) :=\nbegin\n  apply le_antisymm _ (measure_mono ball_subset_closed_ball),\n  have A : tendsto (\u03bb (r : \u211d), ennreal.of_real (r ^ (finrank \u211d E)) * \u03bc (closed_ball (0 : E) 1))\n    (\ud835\udcdd[Iio 1] 1) (\ud835\udcdd (ennreal.of_real (1 ^ (finrank \u211d E)) * \u03bc (closed_ball (0 : E) 1))),\n  { refine ennreal.tendsto.mul _ (by simp) tendsto_const_nhds (by simp),\n    exact ennreal.tendsto_of_real ((tendsto_id' nhds_within_le_nhds).pow _) },\n  simp only [one_pow, one_mul, ennreal.of_real_one] at A,\n  refine le_of_tendsto A _,\n  refine mem_nhds_within_Iio_iff_exists_Ioo_subset.2 \u27e8(0 : \u211d), by simp, \u03bb r hr, _\u27e9,\n  dsimp,\n  rw \u2190 add_haar_closed_ball' \u03bc (0 : E) hr.1.le,\n  exact measure_mono (closed_ball_subset_ball hr.2)\nend\n\nlemma add_haar_closed_ball (x : E) {r : \u211d} (hr : 0 \u2264 r) :\n  \u03bc (closed_ball x r) = ennreal.of_real (r ^ (finrank \u211d E)) * \u03bc (ball 0 1) :=\nby rw [add_haar_closed_ball' \u03bc x hr, add_haar_closed_unit_ball_eq_add_haar_unit_ball]\n\nlemma add_haar_sphere_of_ne_zero (x : E) {r : \u211d} (hr : r \u2260 0) :\n  \u03bc (sphere x r) = 0 :=\nbegin\n  rcases lt_trichotomy r 0 with h|rfl|h,\n  { simp only [empty_diff, measure_empty, \u2190 closed_ball_diff_ball, closed_ball_eq_empty.2 h] },\n  { exact (hr rfl).elim },\n  { rw [\u2190 closed_ball_diff_ball,\n        measure_diff ball_subset_closed_ball measurable_set_closed_ball measurable_set_ball\n          ((add_haar_ball_lt_top \u03bc x r).ne),\n        add_haar_ball_of_pos \u03bc _ h, add_haar_closed_ball \u03bc _ h.le, tsub_self] }\nend\n\nlemma add_haar_sphere [nontrivial E] (x : E) (r : \u211d) :\n  \u03bc (sphere x r) = 0 :=\nbegin\n  rcases eq_or_ne r 0 with rfl|h,\n  { simp only [\u2190 closed_ball_diff_ball, diff_empty, closed_ball_zero,\n               ball_zero, measure_singleton] },\n  { exact add_haar_sphere_of_ne_zero \u03bc x h }\nend\n\nend measure\n\nend measure_theory\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/measure_theory/measure/haar_lebesgue.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545427, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.70864738615201}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Devon Tuma\n-/\nimport measure_theory.probability_mass_function.monad\n\n/-!\n# Specific Constructions of Probability Mass Functions\n\nThis file gives a number of different `pmf` constructions for common probability distributions.\n\n`map` and `seq` allow pushing a `pmf \u03b1` along a function `f : \u03b1 \u2192 \u03b2` (or distribution of\nfunctions `f : pmf (\u03b1 \u2192 \u03b2)`) to get a `pmf \u03b2`\n\n`of_finset` and `of_fintype` simplify the construction of a `pmf \u03b1` from a function `f : \u03b1 \u2192 \u211d\u22650`,\nby allowing the \"sum equals 1\" constraint to be in terms of `finset.sum` instead of `tsum`.\n`of_multiset`, `uniform_of_finset`, and `uniform_of_fintype` construct probability mass functions\nfrom the corresponding object, with proportional weighting for each element of the object.\n\n`normalize` constructs a `pmf \u03b1` by normalizing a function `f : \u03b1 \u2192 \u211d\u22650` by its sum,\nand `filter` uses this to filter the support of a `pmf` and re-normalize the new distribution.\n\n`bernoulli` represents the bernoulli distribution on `bool`\n\n-/\n\nnamespace pmf\n\nnoncomputable theory\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\nopen_locale classical big_operators nnreal ennreal\n\nsection map\n\n/-- The functorial action of a function on a `pmf`. -/\ndef map (f : \u03b1 \u2192 \u03b2) (p : pmf \u03b1) : pmf \u03b2 := bind p (pure \u2218 f)\n\nvariables (f : \u03b1 \u2192 \u03b2) (p : pmf \u03b1) (b : \u03b2)\n\n@[simp] lemma map_apply : (map f p) b = \u2211' a, if b = f a then p a else 0 := by simp [map]\n\n@[simp] lemma support_map : (map f p).support = f '' p.support :=\nset.ext (\u03bb b, by simp [map, @eq_comm \u03b2 b])\n\nlemma mem_support_map_iff : b \u2208 (map f p).support \u2194 \u2203 a \u2208 p.support, f a = b := by simp\n\nlemma bind_pure_comp : bind p (pure \u2218 f) = map f p := rfl\n\nlemma map_id : map id p = p := by simp [map]\n\nlemma map_comp (g : \u03b2 \u2192 \u03b3) : (p.map f).map g = p.map (g \u2218 f) :=\nby simp [map]\n\nlemma pure_map (a : \u03b1) : (pure a).map f = pure (f a) :=\nby simp [map]\n\nsection measure\n\nvariable (s : set \u03b2)\n\n@[simp] lemma to_outer_measure_map_apply :\n  (p.map f).to_outer_measure s = p.to_outer_measure (f \u207b\u00b9' s) :=\nby simp [map, set.indicator, to_outer_measure_apply p (f \u207b\u00b9' s)]\n\n@[simp] lemma to_measure_map_apply [measurable_space \u03b1] [measurable_space \u03b2] (hf : measurable f)\n  (hs : measurable_set s) : (p.map f).to_measure s = p.to_measure (f \u207b\u00b9' s) :=\nbegin\n  rw [to_measure_apply_eq_to_outer_measure_apply _ s hs,\n    to_measure_apply_eq_to_outer_measure_apply _ (f \u207b\u00b9' s) (measurable_set_preimage hf hs)],\n  exact to_outer_measure_map_apply f p s,\nend\n\nend measure\n\nend map\n\nsection seq\n\n/-- The monadic sequencing operation for `pmf`. -/\ndef seq (q : pmf (\u03b1 \u2192 \u03b2)) (p : pmf \u03b1) : pmf \u03b2 := q.bind (\u03bb m, p.bind $ \u03bb a, pure (m a))\n\nvariables (q : pmf (\u03b1 \u2192 \u03b2)) (p : pmf \u03b1) (b : \u03b2)\n\n@[simp] lemma seq_apply : (seq q p) b = \u2211' (f : \u03b1 \u2192 \u03b2) (a : \u03b1), if b = f a then q f * p a else 0 :=\nbegin\n  simp only [seq, mul_boole, bind_apply, pure_apply],\n  refine tsum_congr (\u03bb f, (nnreal.tsum_mul_left (q f) _).symm.trans (tsum_congr (\u03bb a, _))),\n  simpa only [mul_zero] using mul_ite (b = f a) (q f) (p a) 0\nend\n\n@[simp] lemma support_seq : (seq q p).support = \u22c3 f \u2208 q.support, f '' p.support :=\nset.ext (\u03bb b, by simp [-mem_support_iff, seq, @eq_comm \u03b2 b])\n\nlemma mem_support_seq_iff : b \u2208 (seq q p).support \u2194 \u2203 (f \u2208 q.support), b \u2208 f '' p.support :=\nby simp\n\nend seq\n\nsection of_finset\n\n/-- Given a finset `s` and a function `f : \u03b1 \u2192 \u211d\u22650` with sum `1` on `s`,\n  such that `f a = 0` for `a \u2209 s`, we get a `pmf` -/\ndef of_finset (f : \u03b1 \u2192 \u211d\u22650) (s : finset \u03b1) (h : \u2211 a in s, f a = 1)\n  (h' : \u2200 a \u2209 s, f a = 0) : pmf \u03b1 :=\n\u27e8f, h \u25b8 has_sum_sum_of_ne_finset_zero h'\u27e9\n\nvariables {f : \u03b1 \u2192 \u211d\u22650} {s : finset \u03b1} (h : \u2211 a in s, f a = 1) (h' : \u2200 a \u2209 s, f a = 0)\n\n@[simp] lemma of_finset_apply (a : \u03b1) : of_finset f s h h' a = f a := rfl\n\n@[simp] lemma support_of_finset : (of_finset f s h h').support = s \u2229 (function.support f) :=\nset.ext (\u03bb a, by simpa [mem_support_iff] using mt (h' a))\n\nlemma mem_support_of_finset_iff (a : \u03b1) : a \u2208 (of_finset f s h h').support \u2194 a \u2208 s \u2227 f a \u2260 0 :=\nby simp\n\nlemma of_finset_apply_of_not_mem {a : \u03b1} (ha : a \u2209 s) : of_finset f s h h' a = 0 :=\nh' a ha\n\nsection measure\n\nvariable (t : set \u03b1)\n\n@[simp] lemma to_outer_measure_of_finset_apply :\n  (of_finset f s h h').to_outer_measure t = \u2191(\u2211' x, t.indicator f x) :=\nto_outer_measure_apply' (of_finset f s h h') t\n\n@[simp] lemma to_measure_of_finset_apply [measurable_space \u03b1] (ht : measurable_set t) :\n  (of_finset f s h h').to_measure t = \u2191(\u2211' x, t.indicator f x) :=\n(to_measure_apply_eq_to_outer_measure_apply _ t ht).trans\n  (to_outer_measure_of_finset_apply h h' t)\n\nend measure\n\nend of_finset\n\nsection of_fintype\n\n/-- Given a finite type `\u03b1` and a function `f : \u03b1 \u2192 \u211d\u22650` with sum 1, we get a `pmf`. -/\ndef of_fintype [fintype \u03b1] (f : \u03b1 \u2192 \u211d\u22650) (h : \u2211 a, f a = 1) : pmf \u03b1 :=\nof_finset f finset.univ h (\u03bb a ha, absurd (finset.mem_univ a) ha)\n\nvariables [fintype \u03b1] {f : \u03b1 \u2192 \u211d\u22650} (h : \u2211 a, f a = 1)\n\n@[simp] lemma of_fintype_apply (a : \u03b1) : of_fintype f h a = f a := rfl\n\n@[simp] lemma support_of_fintype : (of_fintype f h).support = function.support f := rfl\n\nlemma mem_support_of_fintype_iff (a : \u03b1) : a \u2208 (of_fintype f h).support \u2194 f a \u2260 0 := iff.rfl\n\nsection measure\n\nvariable (s : set \u03b1)\n\n@[simp] lemma to_outer_measure_of_fintype_apply :\n  (of_fintype f h).to_outer_measure s = \u2191(\u2211' x, s.indicator f x) :=\nto_outer_measure_apply' (of_fintype f h) s\n\n@[simp] lemma to_measure_of_fintype_apply [measurable_space \u03b1] (hs : measurable_set s) :\n  (of_fintype f h).to_measure s = \u2191(\u2211' x, s.indicator f x) :=\n(to_measure_apply_eq_to_outer_measure_apply _ s hs).trans\n  (to_outer_measure_of_fintype_apply h s)\n\nend measure\n\nend of_fintype\n\nsection of_multiset\n\n/-- Given a non-empty multiset `s` we construct the `pmf` which sends `a` to the fraction of\n  elements in `s` that are `a`. -/\ndef of_multiset (s : multiset \u03b1) (hs : s \u2260 0) : pmf \u03b1 :=\n\u27e8\u03bb a, s.count a / s.card,\n  have \u2211 a in s.to_finset, (s.count a : \u211d) / s.card = 1,\n    by simp [div_eq_inv_mul, finset.mul_sum.symm, (nat.cast_sum _ _).symm, hs],\n  have \u2211 a in s.to_finset, (s.count a : \u211d\u22650) / s.card = 1,\n    by rw [\u2190 nnreal.eq_iff, nnreal.coe_one, \u2190 this, nnreal.coe_sum]; simp,\n  begin\n    rw \u2190 this,\n    apply has_sum_sum_of_ne_finset_zero,\n    simp {contextual := tt},\n  end\u27e9\n\nvariables {s : multiset \u03b1} (hs : s \u2260 0)\n\n@[simp] lemma of_multiset_apply (a : \u03b1) : of_multiset s hs a = s.count a / s.card := rfl\n\n@[simp] lemma support_of_multiset : (of_multiset s hs).support = s.to_finset :=\nset.ext (by simp [mem_support_iff, hs])\n\nlemma mem_support_of_multiset_iff (a : \u03b1) : a \u2208 (of_multiset s hs).support \u2194 a \u2208 s.to_finset :=\nby simp\n\nlemma of_multiset_apply_of_not_mem {a : \u03b1} (ha : a \u2209 s) : of_multiset s hs a = 0 :=\ndiv_eq_zero_iff.2 (or.inl $ nat.cast_eq_zero.2 $ multiset.count_eq_zero_of_not_mem ha)\n\nsection measure\n\nvariable (t : set \u03b1)\n\n@[simp] lemma to_outer_measure_of_multiset_apply :\n  (of_multiset s hs).to_outer_measure t = (\u2211' x, (s.filter (\u2208 t)).count x) / s.card :=\nbegin\n  rw [div_eq_mul_inv, \u2190 ennreal.tsum_mul_right, to_outer_measure_apply],\n  refine tsum_congr (\u03bb x, _),\n  by_cases hx : x \u2208 t,\n  { have : (multiset.card s : \u211d\u22650) \u2260 0 := by simp [hs],\n    simp [set.indicator, hx, div_eq_mul_inv, ennreal.coe_inv this] },\n  { simp [hx] }\nend\n\n@[simp] lemma to_measure_of_multiset_apply [measurable_space \u03b1] (ht : measurable_set t) :\n  (of_multiset s hs).to_measure t = (\u2211' x, (s.filter (\u2208 t)).count x) / s.card :=\n(to_measure_apply_eq_to_outer_measure_apply _ t ht).trans\n  (to_outer_measure_of_multiset_apply hs t)\n\nend measure\n\nend of_multiset\n\nsection uniform\n\nsection uniform_of_finset\n\n/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/\ndef uniform_of_finset (s : finset \u03b1) (hs : s.nonempty) : pmf \u03b1 :=\nof_finset (\u03bb a, if a \u2208 s then (s.card : \u211d\u22650)\u207b\u00b9 else 0) s (Exists.rec_on hs (\u03bb x hx,\n  calc \u2211 (a : \u03b1) in s, ite (a \u2208 s) (s.card : \u211d\u22650)\u207b\u00b9 0\n    = \u2211 (a : \u03b1) in s, (s.card : \u211d\u22650)\u207b\u00b9 : finset.sum_congr rfl (\u03bb x hx, by simp [hx])\n    ... = s.card \u2022 (s.card : \u211d\u22650)\u207b\u00b9 : finset.sum_const _\n    ... = (s.card : \u211d\u22650) * (s.card : \u211d\u22650)\u207b\u00b9 : by rw nsmul_eq_mul\n    ... = 1 : div_self (nat.cast_ne_zero.2 $ finset.card_ne_zero_of_mem hx)\n  )) (\u03bb x hx, by simp only [hx, if_false])\n\nvariables {s : finset \u03b1} (hs : s.nonempty) {a : \u03b1}\n\n@[simp] lemma uniform_of_finset_apply (a : \u03b1) :\n  uniform_of_finset s hs a = if a \u2208 s then (s.card : \u211d\u22650)\u207b\u00b9 else 0 := rfl\n\nlemma uniform_of_finset_apply_of_mem (ha : a \u2208 s) : uniform_of_finset s hs a = (s.card)\u207b\u00b9 :=\nby simp [ha]\n\nlemma uniform_of_finset_apply_of_not_mem (ha : a \u2209 s) : uniform_of_finset s hs a = 0 :=\nby simp [ha]\n\n@[simp] lemma support_uniform_of_finset : (uniform_of_finset s hs).support = s :=\nset.ext (let \u27e8a, ha\u27e9 := hs in by simp [mem_support_iff, finset.ne_empty_of_mem ha])\n\nlemma mem_support_uniform_of_finset_iff (a : \u03b1) : a \u2208 (uniform_of_finset s hs).support \u2194 a \u2208 s :=\nby simp\n\nsection measure\n\nvariable (t : set \u03b1)\n\n@[simp] lemma to_outer_measure_uniform_of_finset_apply :\n  (uniform_of_finset s hs).to_outer_measure t = (s.filter (\u2208 t)).card / s.card :=\ncalc (uniform_of_finset s hs).to_outer_measure t\n  = \u2191(\u2211' x, if x \u2208 t then (uniform_of_finset s hs x) else 0) :\n    to_outer_measure_apply' (uniform_of_finset s hs) t\n  ... = \u2191(\u2211' x, if x \u2208 s \u2227 x \u2208 t then (s.card : \u211d\u22650)\u207b\u00b9 else 0) :\n    begin\n      refine (ennreal.coe_eq_coe.2 $ tsum_congr (\u03bb x, _)),\n      by_cases hxt : x \u2208 t,\n      { by_cases hxs : x \u2208 s; simp [hxt, hxs] },\n      { simp [hxt] }\n    end\n  ... = \u2191(\u2211 x in (s.filter (\u2208 t)), if x \u2208 s \u2227 x \u2208 t then (s.card : \u211d\u22650)\u207b\u00b9 else 0) :\n    begin\n      refine ennreal.coe_eq_coe.2 (tsum_eq_sum (\u03bb x hx, _)),\n      have : \u00ac (x \u2208 s \u2227 x \u2208 t) := \u03bb h, hx (finset.mem_filter.2 h),\n      simp [this]\n    end\n  ... = \u2191(\u2211 x in (s.filter (\u2208 t)), (s.card : \u211d\u22650)\u207b\u00b9) :\n    ennreal.coe_eq_coe.2 (finset.sum_congr rfl $\n      \u03bb x hx, let this : x \u2208 s \u2227 x \u2208 t := by simpa using hx in by simp [this])\n  ... = (s.filter (\u2208 t)).card / s.card :\n    let this : (s.card : \u211d\u22650) \u2260 0 := nat.cast_ne_zero.2\n      (hs.rec_on $ \u03bb _, finset.card_ne_zero_of_mem) in\n    by simp [div_eq_mul_inv, ennreal.coe_inv this]\n\n@[simp] lemma to_measure_uniform_of_finset_apply [measurable_space \u03b1] (ht : measurable_set t) :\n  (uniform_of_finset s hs).to_measure t = (s.filter (\u2208 t)).card / s.card :=\n(to_measure_apply_eq_to_outer_measure_apply _ t ht).trans\n  (to_outer_measure_uniform_of_finset_apply hs t)\n\nend measure\n\nend uniform_of_finset\n\nsection uniform_of_fintype\n\n/-- The uniform pmf taking the same uniform value on all of the fintype `\u03b1` -/\ndef uniform_of_fintype (\u03b1 : Type*) [fintype \u03b1] [nonempty \u03b1] : pmf \u03b1 :=\n  uniform_of_finset (finset.univ) (finset.univ_nonempty)\n\nvariables [fintype \u03b1] [nonempty \u03b1]\n\n@[simp] lemma uniform_of_fintype_apply (a : \u03b1) : uniform_of_fintype \u03b1 a = (fintype.card \u03b1)\u207b\u00b9 :=\nby simpa only [uniform_of_fintype, finset.mem_univ, if_true, uniform_of_finset_apply]\n\n@[simp] lemma support_uniform_of_fintype (\u03b1 : Type*) [fintype \u03b1] [nonempty \u03b1] :\n  (uniform_of_fintype \u03b1).support = \u22a4 :=\nset.ext (\u03bb x, by simpa [mem_support_iff] using fintype.card_ne_zero)\n\nlemma mem_support_uniform_of_fintype (a : \u03b1) : a \u2208 (uniform_of_fintype \u03b1).support := by simp\n\nsection measure\n\nvariable (s : set \u03b1)\n\nlemma to_outer_measure_uniform_of_fintype_apply :\n  (uniform_of_fintype \u03b1).to_outer_measure s = fintype.card s / fintype.card \u03b1 :=\nby simpa [uniform_of_fintype]\n\nlemma to_measure_uniform_of_fintype_apply [measurable_space \u03b1] (hs : measurable_set s) :\n  (uniform_of_fintype \u03b1).to_measure s = fintype.card s / fintype.card \u03b1 :=\nby simpa [uniform_of_fintype, hs]\n\nend measure\n\nend uniform_of_fintype\n\nend uniform\n\nsection normalize\n\n/-- Given a `f` with non-zero sum, we get a `pmf` by normalizing `f` by it's `tsum` -/\ndef normalize (f : \u03b1 \u2192 \u211d\u22650) (hf0 : tsum f \u2260 0) : pmf \u03b1 :=\n\u27e8\u03bb a, f a * (\u2211' x, f x)\u207b\u00b9,\n  (mul_inv_cancel hf0) \u25b8 has_sum.mul_right (\u2211' x, f x)\u207b\u00b9\n    (not_not.mp (mt tsum_eq_zero_of_not_summable hf0 : \u00ac\u00acsummable f)).has_sum\u27e9\n\nvariables {f : \u03b1 \u2192 \u211d\u22650} (hf0 : tsum f \u2260 0)\n\n@[simp] lemma normalize_apply (a : \u03b1) : (normalize f hf0) a = f a * (\u2211' x, f x)\u207b\u00b9 := rfl\n\n@[simp] lemma support_normalize : (normalize f hf0).support = function.support f :=\nset.ext (by simp [mem_support_iff, hf0])\n\nlemma mem_support_normalize_iff (a : \u03b1) : a \u2208 (normalize f hf0).support \u2194 f a \u2260 0 := by simp\n\nend normalize\n\nsection filter\n\n/-- Create new `pmf` by filtering on a set with non-zero measure and normalizing -/\ndef filter (p : pmf \u03b1) (s : set \u03b1) (h : \u2203 a \u2208 s, a \u2208 p.support) : pmf \u03b1 :=\npmf.normalize (s.indicator p) $ nnreal.tsum_indicator_ne_zero p.2.summable h\n\nvariables {p : pmf \u03b1} {s : set \u03b1} (h : \u2203 a \u2208 s, a \u2208 p.support)\n\n@[simp]\nlemma filter_apply (a : \u03b1) : (p.filter s h) a = (s.indicator p a) * (\u2211' a', (s.indicator p) a')\u207b\u00b9 :=\nby rw [filter, normalize_apply]\n\nlemma filter_apply_eq_zero_of_not_mem {a : \u03b1} (ha : a \u2209 s) : (p.filter s h) a = 0 :=\nby rw [filter_apply, set.indicator_apply_eq_zero.mpr (\u03bb ha', absurd ha' ha), zero_mul]\n\n@[simp] lemma support_filter : (p.filter s h).support = s \u2229 p.support:=\nbegin\n  refine set.ext (\u03bb a, _),\n  rw [mem_support_iff, filter_apply, mul_ne_zero_iff, set.indicator_eq_zero_iff],\n  exact \u27e8\u03bb ha, ha.1, \u03bb ha, \u27e8ha, inv_ne_zero (nnreal.tsum_indicator_ne_zero p.2.summable h)\u27e9\u27e9\nend\n\nlemma mem_support_filter_iff (a : \u03b1) : a \u2208 (p.filter s h).support \u2194 a \u2208 s \u2227 a \u2208 p.support :=\nby simp\n\nlemma filter_apply_eq_zero_iff (a : \u03b1) : (p.filter s h) a = 0 \u2194 a \u2209 s \u2228 a \u2209 p.support :=\nby erw [apply_eq_zero_iff, support_filter, set.mem_inter_iff, not_and_distrib]\n\nlemma filter_apply_ne_zero_iff (a : \u03b1) : (p.filter s h) a \u2260 0 \u2194 a \u2208 s \u2227 a \u2208 p.support :=\nby rw [ne.def, filter_apply_eq_zero_iff, not_or_distrib, not_not, not_not]\n\nend filter\n\nsection bernoulli\n\n/-- A `pmf` which assigns probability `p` to `tt` and `1 - p` to `ff`. -/\ndef bernoulli (p : \u211d\u22650) (h : p \u2264 1) : pmf bool :=\nof_fintype (\u03bb b, cond b p (1 - p)) (nnreal.eq $ by simp [h])\n\nvariables {p : \u211d\u22650} (h : p \u2264 1) (b : bool)\n\n@[simp] lemma bernoulli_apply : bernoulli p h b = cond b p (1 - p) := rfl\n\n@[simp] lemma support_bernoulli : (bernoulli p h).support = {b | cond b (p \u2260 0) (p \u2260 1)} :=\nbegin\n  refine set.ext (\u03bb b, _),\n  induction b,\n  { simp_rw [mem_support_iff, bernoulli_apply, bool.cond_ff, ne.def, tsub_eq_zero_iff_le, not_le],\n    exact \u27e8ne_of_lt, lt_of_le_of_ne h\u27e9 },\n  { simp only [mem_support_iff, bernoulli_apply, bool.cond_tt, set.mem_set_of_eq], }\nend\n\nlemma mem_support_bernoulli_iff : b \u2208 (bernoulli p h).support \u2194 cond b (p \u2260 0) (p \u2260 1) := by simp\n\nend bernoulli\n\nend pmf\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/measure_theory/probability_mass_function/constructions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7086473842838925}}
{"text": "variable (P Q R S : Prop)\n\n/- \nLean has the logical connectives  `and`, `or`, `not` built-in.\n\nLean has special tactics to help us deal with them. \n\nNew tactics: `cases'`, `split`, `left` and `right`\n\n# And (conjunction)\n\n `P and Q` is written  `P \u2227 Q`. This is True iff P and Q are both True.\n\n# cases \n\n Given `h : P \u2227 Q` in the local context we can use `cases h with hp hq` \n to get the two parts so `hp : P` and `hq : Q` replace `h : P \u2227 Q` -/ \n\n-- 01\nexample (h : P \u2227 Q) : P:=\nby\n  exact h.1\n\n\n/- If our goal is `\u22a2 P \u2227 Q` then we can use `split` to create two new goals\none `\u22a2 P` and the other `\u22a2 Q` -/\n\n-- 02\nexample (hp : P) (hq : Q) : P \u2227 Q := by \napply And.intro \nexact hp\nexact hq\n\n\n\n/- \nDot notation: if we have `(hpq : P \u2227 Q)` then `hpq.1 : P` and `hpq.2 : Q`\n\n(This `dot` notation is very common in Lean.)\n\nConversely if we have `(hp : P)` and `(hq : Q)` then `\u27e8hp,hq\u27e9 : P \u2227 Q` \ni.e. `\u27e8hp,hq\u27e9` is a term of type `P \u2227 Q`. \n\nThe angled brackets are typed `\\<` and `\\>` -/\n-- 03\nexample (hpq : P \u2227 Q) : Q \u2227 P :=by\napply And.intro  \nexact hpq.2\nexact hpq.1\n  -- or more simply `exact \u27e8hpq.2,hpq.1\u27e9,`\n\n\n-- Having introduced `\u2192` and `\u2227` we get `iff` (written `\u2194`) for free\n-- `P \u2194 Q` is:  `P \u2192 Q` and `Q \u2192 P`\n-- 04\nexample : P \u2227 Q \u2194 Q \u2227 P := by\napply Iff.intro\n\u00b7 intro pq\n  exact \u27e8pq.2,pq.1\u27e9\n\u00b7 intro qp\n  apply And.intro\n  exact qp.2\n  exact qp.1\n\n\n\n\n\n\n-- 05 \nexample : P \u2227 Q \u2192 Q :=by\n  intro h\n  exact h.2\n\n\n-- in Lean `P \u2227 Q \u2227 R` means `P \u2227 (Q \u2227 R)` (\u2227 is right-associative)\n-- Find a single line `exact ...` solution to the following.\n-- (Hint: what are h.1 and h.2 in this example?)\n-- 06\nexample  (h: P \u2227 Q \u2227 R \u2227 S ) : R :=by\n  exact h.2.2.1\n\n\n-- 07\nexample : P \u2192 Q \u2192 P \u2227 Q :=by\n  intro p q\n  exact \u27e8p,q\u27e9\n\n\n-- 08\nexample : P \u2227 Q \u2192 Q \u2227 R \u2192 P \u2227 R :=by\n  intro pq qr\n  exact \u27e8pq.1,qr.2\u27e9\n\n-- 09\nexample :  P \u2227 R \u2227 Q \u2192 Q \u2227 P \u2227 R :=by\n  intro pqr\n  exact \u27e8pqr.2.2,pqr.1,pqr.2.1\u27e9\n  \n\n/-\n   # Or (disjunction)\n\nThe proposition `P or Q` is written  `P \u2228 Q`. \n \n `P \u2228 Q` is True iff P is True or Q is True.\n\nIf our goal is `\u22a2 P \u2228 Q` then we can accomplish this by either giving a term\nof type `P` or a term of type `Q`. We indicate which by using `left` for `P`\nand `right` for Q.\n -/\n\n-- 10\nexample (hp : P) : Q \u2228 P :=by\nexact Or.inr hp\n\n\n/-\nGiven `(hpq : P \u2228 Q)` in the local context we can use `cases hpq with hp hq` \nto split our goal into two subgoals, one in which `hp : P` and the other\nin which `hq : Q`\n-/\n-- 11\nexample (hpq : P \u2228 Q) : Q \u2228 P :=by\ncases hpq with\n| inl hp => exact Or.inr hp\n| inr hq => exact Or.inl hq\n\n-- 12 \nexample : (P \u2228 Q) \u2227 (P \u2192 Q) \u2192 Q :=by\n  intro \u27e8hporq,hpq\u27e9\n  cases hporq with\n  | inl hp => apply hpq hp\n  | inr hq => exact hq\n\n\n-- 13 \nexample : (P \u2228 Q) \u2227 (P \u2228 R) \u2192 P \u2228 (Q \u2227 R):=by \nintro \u27e8pq,pr\u27e9\ncases pq with\n| inl p => exact Or.inl p\n| inr q => cases pr with\n          | inl p => exact Or.inl p\n          | inr r=>  exact Or.inr \u27e8q,r\u27e9\n  \n\n\n-- 14 \nexample : (P \u2228 Q) \u2227 (R \u2228 S) \u2192 (P \u2227 R) \u2228 (P \u2227 S) \u2228 (Q \u2227 R) \u2228 (Q \u2227 S):=by\nintro \u27e8pq,rs\u27e9\ncases pq with\n| inl p => cases rs with\n          | inl r => exact Or.inl \u27e8p,r\u27e9\n          | inr s => apply Or.inr $ Or.inl \u27e8p,s\u27e9\n| inr q => cases rs with\n          | inl r => exact Or.inr $ Or.inr $ Or.inl \u27e8q,r\u27e9\n          | inr s => apply Or.inr $ Or.inr $ Or.inr \u27e8q,s\u27e9\n          \n\nexample  (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by\napply Iff.intro\n\u00b7 intro \u27e8hp,hqr\u27e9\n  cases hqr with\n  |inl hq => exact Or.inl \u27e8hp,hq\u27e9\n  |inr hr => exact Or.inr \u27e8hp,hr\u27e9\n\u00b7 intro hpqpr \n  cases hpqpr with\n  |inl hpq => exact \u27e8hpq.1,Or.inl hpq.2\u27e9\n  |inr hpr => exact \u27e8hpr.1,Or.inr hpr.2\u27e9\n\n\n/-\nThere are two special propositions : `False` and `True`\n\nTo prove `True` we use `triv`\n\nYou shouldn't be able to prove `False`.\n\nIf you have `False` in the local context then you have a `contradiction`\n-/\n#check True\n-- 15\nexample : True :=by trivial\n\n\n\n\n\n-- 16\nexample: P \u2192 True :=by\nintro _ \ntrivial\n\n\n-- 17\nexample : False \u2192 P:=by\nintro f\ncontradiction\n\n\n-- 18\nexample : False \u2192 True:=by\nintro _\ntrivial\n\n\n-- 19 \nexample : True \u2192 False \u2192 True \u2192 False \u2192 True :=by\nintro _ _ _ _\ntrivial\n\n\n\n/- \n# Negation\n\nIf `P : Prop` then `not P` is denoted `\u00ac P` this is defined to be `P \u2192 False`  -/\n-- 20\nexample : \u00acP \u2194 (P \u2192 False):=by \napply Iff.intro\n\u00b7 intro hnp hp\n  contradiction\n\u00b7 intro hpf hnp\n  exact hpf hnp\n\n  \n-- 21\nexample : \u00ac True \u2192 False :=by\nintro nt\napply nt\ntrivial\n\n-- 22\nexample : \u00ac False \u2192 True :=by\nintro _ \ntrivial\n\n\n-- 23\nexample : P \u2192 \u00ac\u00acP :=by\nintro hp\nintro nnp \ncontradiction\n\n-- 24\nexample (hp : P) (hnp : \u00ac P) : Q \u2227 R \u2192 \u00ac Q  :=by\nintro _ _\ncontradiction\n\n-- Can you explain how the following proof works?\n-- 25\nexample (hp : P) (hnp : \u00ac P) : Q :=by\ncases (hnp hp) -- Hint: what is `(hnp hp)`?\n\n\n", "meta": {"author": "jt496", "repo": "Lean4_Test", "sha": "ec62c927827ab38b6aedadb59783a6d5066f3eb0", "save_path": "github-repos/lean/jt496-Lean4_Test", "path": "github-repos/lean/jt496-Lean4_Test/Lean4_Test-ec62c927827ab38b6aedadb59783a6d5066f3eb0/src/2_logic/more_basics_and_or_not.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.708647369228447}}
{"text": "theorem succ_eq_succ_iff (a b : mynat) : succ a = succ b \u2194 a = b :=\nbegin\nsplit,\nexact succ_inj,\nexact succ_eq_succ_of_eq,\nend", "meta": {"author": "nicholaspun", "repo": "natural-number-game-solutions", "sha": "1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0", "save_path": "github-repos/lean/nicholaspun-natural-number-game-solutions", "path": "github-repos/lean/nicholaspun-natural-number-game-solutions/natural-number-game-solutions-1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0/6-advanced-addition-world/l4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693674025231, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.7085853401449619}}
{"text": "/-\nCopyright (c) 2020 Google LLC. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Wong\n\n! This file was ported from Lean 3 source module data.list.palindrome\n! leanprover-community/mathlib commit 5a3e819569b0f12cbec59d740a2613018e7b8eec\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.List.Basic\n\n/-!\n# Palindromes\n\nThis module defines *palindromes*, lists which are equal to their reverse.\n\nThe main result is the `Palindrome` inductive type, and its associated `Palindrome.rec` induction\nprinciple. Also provided are conversions to and from other equivalent definitions.\n\n## References\n\n* [Pierre Cast\u00e9ran, *On palindromes*][casteran]\n\n[casteran]: https://www.labri.fr/perso/casteran/CoqArt/inductive-prop-chap/palindrome.html\n\n## Tags\n\npalindrome, reverse, induction\n-/\n\n\nvariable {\u03b1 \u03b2 : Type _}\n\nnamespace List\n\n/-- `Palindrome l` asserts that `l` is a palindrome. This is defined inductively:\n\n* The empty list is a palindrome;\n* A list with one element is a palindrome;\n* Adding the same element to both ends of a palindrome results in a bigger palindrome.\n-/\ninductive Palindrome : List \u03b1 \u2192 Prop\n  | nil : Palindrome []\n  | singleton : \u2200 x, Palindrome [x]\n  | cons_concat : \u2200 (x) {l}, Palindrome l \u2192 Palindrome (x :: (l ++ [x]))\n#align list.palindrome List.Palindrome\n\nnamespace Palindrome\n\nvariable {l : List \u03b1}\n\ntheorem reverse_eq {l : List \u03b1} (p : Palindrome l) : reverse l = l := by\n  induction p <;> try (exact rfl)\n  simp; assumption\n#align list.palindrome.reverse_eq List.Palindrome.reverse_eq\n\n\n\ntheorem iff_reverse_eq {l : List \u03b1} : Palindrome l \u2194 reverse l = l :=\n  Iff.intro reverse_eq of_reverse_eq\n#align list.palindrome.iff_reverse_eq List.Palindrome.iff_reverse_eq\n\ntheorem append_reverse (l : List \u03b1) : Palindrome (l ++ reverse l) := by\n  apply of_reverse_eq\n  rw [reverse_append, reverse_reverse]\n#align list.palindrome.append_reverse List.Palindrome.append_reverse\n\nprotected theorem map (f : \u03b1 \u2192 \u03b2) (p : Palindrome l) : Palindrome (map f l) :=\n  of_reverse_eq <| by rw [\u2190 map_reverse, p.reverse_eq]\n#align list.palindrome.map List.Palindrome.map\n\ninstance [DecidableEq \u03b1] (l : List \u03b1) : Decidable (Palindrome l) :=\n  decidable_of_iff' _ iff_reverse_eq\n\nend Palindrome\n\nend List\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/List/Palindrome.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7085782815414962}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n\nNotation for vectors and matrices\n-/\n\nimport data.fintype.card\nimport data.matrix.basic\nimport tactic.fin_cases\n\n/-!\n# Matrix and vector notation\n\nThis file defines notation for vectors and matrices. Given `a b c d : \u03b1`,\nthe notation allows us to write `![a, b, c, d] : fin 4 \u2192 \u03b1`.\nNesting vectors gives a matrix, so `![![a, b], ![c, d]] : matrix (fin 2) (fin 2) \u03b1`.\nThis file includes `simp` lemmas for applying operations in\n`data.matrix.basic` to values built out of this notation.\n\n## Main definitions\n\n* `vec_empty` is the empty vector (or `0` by `n` matrix) `![]`\n* `vec_cons` prepends an entry to a vector, so `![a, b]` is `vec_cons a (vec_cons b vec_empty)`\n\n## Implementation notes\n\nThe `simp` lemmas require that one of the arguments is of the form `vec_cons _ _`.\nThis ensures `simp` works with entries only when (some) entries are already given.\nIn other words, this notation will only appear in the output of `simp` if it\nalready appears in the input.\n\n## Notations\n\nThe main new notation is `![a, b]`, which gets expanded to `vec_cons a (vec_cons b vec_empty)`.\n\n## Examples\n\nExamples of usage can be found in the `test/matrix.lean` file.\n-/\n\nnamespace matrix\n\nuniverse u\nvariables {\u03b1 : Type u}\n\nopen_locale matrix\n\nsection matrix_notation\n\n/-- `![]` is the vector with no entries. -/\ndef vec_empty : fin 0 \u2192 \u03b1 :=\nfin_zero_elim\n\n/-- `vec_cons h t` prepends an entry `h` to a vector `t`.\n\nThe inverse functions are `vec_head` and `vec_tail`.\nThe notation `![a, b, ...]` expands to `vec_cons a (vec_cons b ...)`.\n-/\ndef vec_cons {n : \u2115} (h : \u03b1) (t : fin n \u2192 \u03b1) : fin n.succ \u2192 \u03b1 :=\nfin.cons h t\n\nnotation `![` l:(foldr `, ` (h t, vec_cons h t) vec_empty `]`) := l\n\n/-- `vec_head v` gives the first entry of the vector `v` -/\ndef vec_head {n : \u2115} (v : fin n.succ \u2192 \u03b1) : \u03b1 :=\nv 0\n\n/-- `vec_tail v` gives a vector consisting of all entries of `v` except the first -/\ndef vec_tail {n : \u2115} (v : fin n.succ \u2192 \u03b1) : fin n \u2192 \u03b1 :=\nv \u2218 fin.succ\n\nend matrix_notation\n\nvariables {m n o : \u2115} {m' n' o' : Type*} [fintype m'] [fintype n'] [fintype o']\n\nlemma empty_eq (v : fin 0 \u2192 \u03b1) : v = ![] :=\nby { ext i, fin_cases i }\n\nsection val\n\n@[simp] lemma head_fin_const (a : \u03b1) : vec_head (\u03bb (i : fin (n + 1)), a) = a := rfl\n\n@[simp] lemma cons_val_zero (x : \u03b1) (u : fin m \u2192 \u03b1) : vec_cons x u 0 = x := rfl\n\nlemma cons_val_zero' (h : 0 < m.succ) (x : \u03b1) (u : fin m \u2192 \u03b1) :\n  vec_cons x u \u27e80, h\u27e9 = x :=\nrfl\n\n@[simp] lemma cons_val_succ (x : \u03b1) (u : fin m \u2192 \u03b1) (i : fin m) :\n  vec_cons x u i.succ = u i :=\nby simp [vec_cons]\n\n@[simp] lemma cons_val_succ' {i : \u2115} (h : i.succ < m.succ) (x : \u03b1) (u : fin m \u2192 \u03b1) :\n  vec_cons x u \u27e8i.succ, h\u27e9 = u \u27e8i, nat.lt_of_succ_lt_succ h\u27e9 :=\nby simp only [vec_cons, fin.cons, fin.cases_succ']\n\n@[simp] lemma head_cons (x : \u03b1) (u : fin m \u2192 \u03b1) :\n  vec_head (vec_cons x u) = x :=\nrfl\n\n@[simp] lemma tail_cons (x : \u03b1) (u : fin m \u2192 \u03b1) :\n  vec_tail (vec_cons x u) = u :=\nby { ext, simp [vec_tail] }\n\n@[simp] lemma empty_val' {n' : Type*} (j : n') :\n  (\u03bb i, (![] : fin 0 \u2192 n' \u2192 \u03b1) i j) = ![] :=\nempty_eq _\n\n@[simp] lemma cons_val' (v : n' \u2192 \u03b1) (B : matrix (fin m) n' \u03b1) (i j) :\n  vec_cons v B i j = vec_cons (v j) (\u03bb i, B i j) i :=\nby { refine fin.cases _ _ i; simp }\n\n@[simp] lemma head_val' (B : matrix (fin m.succ) n' \u03b1) (j : n') :\n  vec_head (\u03bb i, B i j) = vec_head B j := rfl\n\n@[simp] lemma tail_val' (B : matrix (fin m.succ) n' \u03b1) (j : n') :\n  vec_tail (\u03bb i, B i j) = \u03bb i, vec_tail B i j :=\nby { ext, simp [vec_tail] }\n\n@[simp] lemma cons_head_tail (u : fin m.succ \u2192 \u03b1) :\n vec_cons (vec_head u) (vec_tail u) = u :=\nfin.cons_self_tail _\n\n@[simp] lemma range_cons (x : \u03b1) (u : fin n \u2192 \u03b1) :\n  set.range (vec_cons x u) = {x} \u222a set.range u :=\nset.ext $ \u03bb y, by simp [fin.exists_fin_succ, eq_comm]\n\n@[simp] lemma range_empty (u : fin 0 \u2192 \u03b1) : set.range u = \u2205 :=\nset.range_eq_empty.2 $ \u03bb \u27e8k\u27e9, k.elim0\n\n/-- `![a, b, ...] 1` is equal to `b`.\n\n  The simplifier needs a special lemma for length `\u2265 2`, in addition to\n  `cons_val_succ`, because `1 : fin 1 = 0 : fin 1`.\n-/\n@[simp] lemma cons_val_one (x : \u03b1) (u : fin m.succ \u2192 \u03b1) :\n  vec_cons x u 1 = vec_head u :=\nby { rw [\u2190 fin.succ_zero_eq_one, cons_val_succ], refl }\n\n@[simp] lemma cons_val_fin_one (x : \u03b1) (u : fin 0 \u2192 \u03b1) (i : fin 1) :\n  vec_cons x u i = x :=\nby { fin_cases i, refl }\n\nlemma cons_fin_one (x : \u03b1) (u : fin 0 \u2192 \u03b1) : vec_cons x u = (\u03bb _, x) :=\nfunext (cons_val_fin_one x u)\n\n/-! ### Numeral (`bit0` and `bit1`) indices\nThe following definitions and `simp` lemmas are to allow any\nnumeral-indexed element of a vector given with matrix notation to\nbe extracted by `simp` (even when the numeral is larger than the\nnumber of elements in the vector, which is taken modulo that number\nof elements by virtue of the semantics of `bit0` and `bit1` and of\naddition on `fin n`).\n-/\n\n@[simp] lemma empty_append (v : fin n \u2192 \u03b1) : fin.append (zero_add _).symm ![] v = v :=\nby { ext, simp [fin.append] }\n\n@[simp] lemma cons_append (ho : o + 1 = m + 1 + n) (x : \u03b1) (u : fin m \u2192 \u03b1) (v : fin n \u2192 \u03b1) :\n  fin.append ho (vec_cons x u) v =\n    vec_cons x (fin.append (by rwa [add_assoc, add_comm 1, \u2190add_assoc,\n                                  add_right_cancel_iff] at ho) u v) :=\nbegin\n  ext i,\n  simp_rw [fin.append],\n  split_ifs with h,\n  { rcases i with \u27e8\u27e8\u27e9 | i, hi\u27e9,\n    { simp },\n    { simp only [nat.succ_eq_add_one, add_lt_add_iff_right, fin.coe_mk] at h,\n      simp [h] } },\n  { rcases i with \u27e8\u27e8\u27e9 | i, hi\u27e9,\n    { simpa using h },\n    { rw [not_lt, fin.coe_mk, nat.succ_eq_add_one, add_le_add_iff_right] at h,\n      simp [h] } }\nend\n\n/-- `vec_alt0 v` gives a vector with half the length of `v`, with\nonly alternate elements (even-numbered). -/\ndef vec_alt0 (hm : m = n + n) (v : fin m \u2192 \u03b1) (k : fin n) : \u03b1 :=\nv \u27e8(k : \u2115) + k, hm.symm \u25b8 add_lt_add k.property k.property\u27e9\n\n/-- `vec_alt1 v` gives a vector with half the length of `v`, with\nonly alternate elements (odd-numbered). -/\ndef vec_alt1 (hm : m = n + n) (v : fin m \u2192 \u03b1) (k : fin n) : \u03b1 :=\nv \u27e8(k : \u2115) + k + 1, hm.symm \u25b8 nat.add_succ_lt_add k.property k.property\u27e9\n\nlemma vec_alt0_append (v : fin n \u2192 \u03b1) : vec_alt0 rfl (fin.append rfl v v) = v \u2218 bit0 :=\nbegin\n  ext i,\n  simp_rw [function.comp, bit0, vec_alt0, fin.append],\n  split_ifs with h; congr,\n  { rw fin.coe_mk at h,\n    simp only [fin.ext_iff, fin.coe_add, fin.coe_mk],\n    exact (nat.mod_eq_of_lt h).symm },\n  { rw [fin.coe_mk, not_lt] at h,\n    simp only [fin.ext_iff, fin.coe_add, fin.coe_mk, nat.mod_eq_sub_mod h],\n    refine (nat.mod_eq_of_lt _).symm,\n    rw nat.sub_lt_left_iff_lt_add h,\n    exact add_lt_add i.property i.property }\nend\n\nlemma vec_alt1_append (v : fin (n + 1) \u2192 \u03b1) : vec_alt1 rfl (fin.append rfl v v) = v \u2218 bit1 :=\nbegin\n  ext i,\n  simp_rw [function.comp, vec_alt1, fin.append],\n  cases n,\n  { simp, congr },\n  { split_ifs with h; simp_rw [bit1, bit0]; congr,\n    { simp only [fin.ext_iff, fin.coe_add, fin.coe_mk],\n      rw fin.coe_mk at h,\n      rw fin.coe_one,\n      rw nat.mod_eq_of_lt (nat.lt_of_succ_lt h),\n      rw nat.mod_eq_of_lt h },\n    { rw [fin.coe_mk, not_lt] at h,\n      simp only [fin.ext_iff, fin.coe_add, fin.coe_mk, nat.mod_add_mod, fin.coe_one,\n                 nat.mod_eq_sub_mod h],\n      refine (nat.mod_eq_of_lt _).symm,\n      rw nat.sub_lt_left_iff_lt_add h,\n      exact nat.add_succ_lt_add i.property i.property } }\nend\n\n@[simp] lemma vec_head_vec_alt0 (hm : (m + 2) = (n + 1) + (n + 1)) (v : fin (m + 2) \u2192 \u03b1) :\n  vec_head (vec_alt0 hm v) = v 0 := rfl\n\n@[simp] lemma vec_head_vec_alt1 (hm : (m + 2) = (n + 1) + (n + 1)) (v : fin (m + 2) \u2192 \u03b1) :\n  vec_head (vec_alt1 hm v) = v 1 :=\nby simp [vec_head, vec_alt1]\n\n@[simp] lemma cons_vec_bit0_eq_alt0 (x : \u03b1) (u : fin n \u2192 \u03b1) (i : fin (n + 1)) :\n  vec_cons x u (bit0 i) = vec_alt0 rfl (fin.append rfl (vec_cons x u) (vec_cons x u)) i :=\nby rw vec_alt0_append\n\n@[simp] lemma cons_vec_bit1_eq_alt1 (x : \u03b1) (u : fin n \u2192 \u03b1) (i : fin (n + 1)) :\n  vec_cons x u (bit1 i) = vec_alt1 rfl (fin.append rfl (vec_cons x u) (vec_cons x u)) i :=\nby rw vec_alt1_append\n\n@[simp] lemma cons_vec_alt0 (h : m + 1 + 1 = (n + 1) + (n + 1)) (x y : \u03b1) (u : fin m \u2192 \u03b1) :\n  vec_alt0 h (vec_cons x (vec_cons y u)) = vec_cons x (vec_alt0\n    (by rwa [add_assoc n, add_comm 1, \u2190add_assoc, \u2190add_assoc, add_right_cancel_iff,\n             add_right_cancel_iff] at h) u) :=\nbegin\n  ext i,\n  simp_rw [vec_alt0],\n  rcases i with \u27e8\u27e8\u27e9 | i, hi\u27e9,\n  { refl },\n  { simp [vec_alt0, nat.succ_add] }\nend\n\n-- Although proved by simp, extracting element 8 of a five-element\n-- vector does not work by simp unless this lemma is present.\n@[simp] lemma empty_vec_alt0 (\u03b1) {h} : vec_alt0 h (![] : fin 0 \u2192 \u03b1) = ![] :=\nby simp\n\n@[simp] lemma cons_vec_alt1 (h : m + 1 + 1 = (n + 1) + (n + 1)) (x y : \u03b1) (u : fin m \u2192 \u03b1) :\n  vec_alt1 h (vec_cons x (vec_cons y u)) = vec_cons y (vec_alt1\n    (by rwa [add_assoc n, add_comm 1, \u2190add_assoc, \u2190add_assoc, add_right_cancel_iff,\n             add_right_cancel_iff] at h) u) :=\nbegin\n  ext i,\n  simp_rw [vec_alt1],\n  rcases i with \u27e8\u27e8\u27e9 | i, hi\u27e9,\n  { refl },\n  { simp [vec_alt1, nat.succ_add] }\nend\n\n-- Although proved by simp, extracting element 9 of a five-element\n-- vector does not work by simp unless this lemma is present.\n@[simp] lemma empty_vec_alt1 (\u03b1) {h} : vec_alt1 h (![] : fin 0 \u2192 \u03b1) = ![] :=\nby simp\n\nend val\n\nsection dot_product\n\nvariables [add_comm_monoid \u03b1] [has_mul \u03b1]\n\n@[simp] lemma dot_product_empty (v w : fin 0 \u2192 \u03b1) :\n  dot_product v w = 0 := finset.sum_empty\n\n@[simp] lemma cons_dot_product (x : \u03b1) (v : fin n \u2192 \u03b1) (w : fin n.succ \u2192 \u03b1) :\n  dot_product (vec_cons x v) w = x * vec_head w + dot_product v (vec_tail w) :=\nby simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail]\n\n@[simp] lemma dot_product_cons (v : fin n.succ \u2192 \u03b1) (x : \u03b1) (w : fin n \u2192 \u03b1) :\n  dot_product v (vec_cons x w) = vec_head v * x + dot_product (vec_tail v) w :=\nby simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail]\n\nend dot_product\n\nsection col_row\n\n@[simp] lemma col_empty (v : fin 0 \u2192 \u03b1) : col v = vec_empty :=\nempty_eq _\n\n@[simp] lemma col_cons (x : \u03b1) (u : fin m \u2192 \u03b1) :\n  col (vec_cons x u) = vec_cons (\u03bb _, x) (col u) :=\nby { ext i j, refine fin.cases _ _ i; simp [vec_head, vec_tail] }\n\n@[simp] lemma row_empty : row (vec_empty : fin 0 \u2192 \u03b1) = \u03bb _, vec_empty :=\nby { ext, refl }\n\n@[simp] lemma row_cons (x : \u03b1) (u : fin m \u2192 \u03b1) :\n  row (vec_cons x u) = \u03bb _, vec_cons x u :=\nby { ext, refl }\n\nend col_row\n\nsection transpose\n\n@[simp] lemma transpose_empty_rows (A : matrix m' (fin 0) \u03b1) : A\u1d40 = ![] := empty_eq _\n\n@[simp] lemma transpose_empty_cols : (![] : matrix (fin 0) m' \u03b1)\u1d40 = \u03bb i, ![] :=\nfunext (\u03bb i, empty_eq _)\n\n@[simp] lemma cons_transpose (v : n' \u2192 \u03b1) (A : matrix (fin m) n' \u03b1) :\n  (vec_cons v A)\u1d40 = \u03bb i, vec_cons (v i) (A\u1d40 i) :=\nby { ext i j, refine fin.cases _ _ j; simp }\n\n@[simp] lemma head_transpose (A : matrix m' (fin n.succ) \u03b1) : vec_head (A\u1d40) = vec_head \u2218 A :=\nrfl\n\n@[simp] lemma tail_transpose (A : matrix m' (fin n.succ) \u03b1) : vec_tail (A\u1d40) = (vec_tail \u2218 A)\u1d40 :=\nby { ext i j, refl }\n\nend transpose\n\nsection mul\n\nvariables [semiring \u03b1]\n\n@[simp] lemma empty_mul (A : matrix (fin 0) n' \u03b1) (B : matrix n' o' \u03b1) :\n  A \u2b1d B = ![] :=\nempty_eq _\n\n@[simp] lemma empty_mul_empty (A : matrix m' (fin 0) \u03b1) (B : matrix (fin 0) o' \u03b1) :\n  A \u2b1d B = 0 :=\nrfl\n\n@[simp] lemma mul_empty (A : matrix m' n' \u03b1) (B : matrix n' (fin 0) \u03b1) :\n  A \u2b1d B = \u03bb _, ![] :=\nfunext (\u03bb _, empty_eq _)\n\nlemma mul_val_succ (A : matrix (fin m.succ) n' \u03b1) (B : matrix n' o' \u03b1) (i : fin m) (j : o') :\n  (A \u2b1d B) i.succ j = (vec_tail A \u2b1d B) i j := rfl\n\n@[simp] lemma cons_mul (v : n' \u2192 \u03b1) (A : matrix (fin m) n' \u03b1) (B : matrix n' o' \u03b1) :\n  vec_cons v A \u2b1d B = vec_cons (vec_mul v B) (A  \u2b1d B) :=\nby { ext i j, refine fin.cases _ _ i, { refl }, simp [mul_val_succ] }\n\nend mul\n\nsection vec_mul\n\nvariables [semiring \u03b1]\n\n@[simp] lemma empty_vec_mul (v : fin 0 \u2192 \u03b1) (B : matrix (fin 0) o' \u03b1) :\n  vec_mul v B = 0 :=\nrfl\n\n@[simp] lemma vec_mul_empty (v : n' \u2192 \u03b1) (B : matrix n' (fin 0) \u03b1) :\n  vec_mul v B = ![] :=\nempty_eq _\n\n@[simp] lemma cons_vec_mul (x : \u03b1) (v : fin n \u2192 \u03b1) (B : matrix (fin n.succ) o' \u03b1) :\n  vec_mul (vec_cons x v) B = x \u2022 (vec_head B) + vec_mul v (vec_tail B) :=\nby { ext i, simp [vec_mul] }\n\n@[simp] lemma vec_mul_cons (v : fin n.succ \u2192 \u03b1) (w : o' \u2192 \u03b1) (B : matrix (fin n) o' \u03b1) :\n  vec_mul v (vec_cons w B) = vec_head v \u2022 w + vec_mul (vec_tail v) B :=\nby { ext i, simp [vec_mul] }\n\nend vec_mul\n\nsection mul_vec\n\nvariables [semiring \u03b1]\n\n@[simp] lemma empty_mul_vec (A : matrix (fin 0) n' \u03b1) (v : n' \u2192 \u03b1) :\n  mul_vec A v = ![] :=\nempty_eq _\n\n@[simp] lemma mul_vec_empty (A : matrix m' (fin 0) \u03b1) (v : fin 0 \u2192 \u03b1) :\n  mul_vec A v = 0 :=\nrfl\n\n@[simp] lemma cons_mul_vec (v : n' \u2192 \u03b1) (A : fin m \u2192 n' \u2192 \u03b1) (w : n' \u2192 \u03b1) :\n  mul_vec (vec_cons v A) w = vec_cons (dot_product v w) (mul_vec A w) :=\nby { ext i, refine fin.cases _ _ i; simp [mul_vec] }\n\n@[simp] lemma mul_vec_cons {\u03b1} [comm_semiring \u03b1] (A : m' \u2192 (fin n.succ) \u2192 \u03b1) (x : \u03b1)\n  (v : fin n \u2192 \u03b1) :\n  mul_vec A (vec_cons x v) = (x \u2022 vec_head \u2218 A) + mul_vec (vec_tail \u2218 A) v :=\nby { ext i, simp [mul_vec, mul_comm] }\n\nend mul_vec\n\nsection vec_mul_vec\n\nvariables [semiring \u03b1]\n\n@[simp] lemma empty_vec_mul_vec (v : fin 0 \u2192 \u03b1) (w : n' \u2192 \u03b1) :\n  vec_mul_vec v w = ![] :=\nempty_eq _\n\n@[simp] lemma vec_mul_vec_empty (v : m' \u2192 \u03b1) (w : fin 0 \u2192 \u03b1) :\n  vec_mul_vec v w = \u03bb _, ![] :=\nfunext (\u03bb i, empty_eq _)\n\n@[simp] lemma cons_vec_mul_vec (x : \u03b1) (v : fin m \u2192 \u03b1) (w : n' \u2192 \u03b1) :\n  vec_mul_vec (vec_cons x v) w = vec_cons (x \u2022 w) (vec_mul_vec v w) :=\nby { ext i, refine fin.cases _ _ i; simp [vec_mul_vec] }\n\n@[simp] lemma vec_mul_vec_cons (v : m' \u2192 \u03b1) (x : \u03b1) (w : fin n \u2192 \u03b1) :\n  vec_mul_vec v (vec_cons x w) = \u03bb i, v i \u2022 vec_cons x w :=\nby { ext i j, simp [vec_mul_vec]}\n\nend vec_mul_vec\n\nsection smul\n\nvariables [semiring \u03b1]\n\n@[simp] lemma smul_empty (x : \u03b1) (v : fin 0 \u2192 \u03b1) : x \u2022 v = ![] := empty_eq _\n\n@[simp] lemma smul_mat_empty {m' : Type*} (x : \u03b1) (A : fin 0 \u2192 m' \u2192 \u03b1) : x \u2022 A = ![] := empty_eq _\n\n@[simp] lemma smul_cons (x y : \u03b1) (v : fin n \u2192 \u03b1) :\n  x \u2022 vec_cons y v = vec_cons (x * y) (x \u2022 v) :=\nby { ext i, refine fin.cases _ _ i; simp }\n\n@[simp] lemma smul_mat_cons (x : \u03b1) (v : n' \u2192 \u03b1) (A : matrix (fin m) n' \u03b1) :\n  x \u2022 vec_cons v A = vec_cons (x \u2022 v) (x \u2022 A) :=\nby { ext i, refine fin.cases _ _ i; simp }\n\nend smul\n\nsection add\n\nvariables [has_add \u03b1]\n\n@[simp] lemma empty_add_empty (v w : fin 0 \u2192 \u03b1) : v + w = ![] := empty_eq _\n\n@[simp] lemma cons_add (x : \u03b1) (v : fin n \u2192 \u03b1) (w : fin n.succ \u2192 \u03b1) :\n  vec_cons x v + w = vec_cons (x + vec_head w) (v + vec_tail w) :=\nby { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }\n\n@[simp] lemma add_cons (v : fin n.succ \u2192 \u03b1) (y : \u03b1) (w : fin n \u2192 \u03b1) :\n  v + vec_cons y w = vec_cons (vec_head v + y) (vec_tail v + w) :=\nby { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }\n\n@[simp] lemma head_add (a b : fin n.succ \u2192 \u03b1) : vec_head (a + b) = vec_head a + vec_head b := rfl\n\n@[simp] lemma tail_add (a b : fin n.succ \u2192 \u03b1) : vec_tail (a + b) = vec_tail a + vec_tail b := rfl\n\nend add\n\nsection sub\n\nvariables [has_sub \u03b1]\n\n@[simp] lemma empty_sub_empty (v w : fin 0 \u2192 \u03b1) : v - w = ![] := empty_eq _\n\n@[simp] lemma cons_sub (x : \u03b1) (v : fin n \u2192 \u03b1) (w : fin n.succ \u2192 \u03b1) :\n  vec_cons x v - w = vec_cons (x - vec_head w) (v - vec_tail w) :=\nby { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }\n\n@[simp] lemma sub_cons (v : fin n.succ \u2192 \u03b1) (y : \u03b1) (w : fin n \u2192 \u03b1) :\n  v - vec_cons y w = vec_cons (vec_head v - y) (vec_tail v - w) :=\nby { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }\n\n@[simp] lemma head_sub (a b : fin n.succ \u2192 \u03b1) : vec_head (a - b) = vec_head a - vec_head b := rfl\n\n@[simp] lemma tail_sub (a b : fin n.succ \u2192 \u03b1) : vec_tail (a - b) = vec_tail a - vec_tail b := rfl\n\nend sub\n\nsection zero\n\nvariables [has_zero \u03b1]\n\n@[simp] lemma zero_empty : (0 : fin 0 \u2192 \u03b1) = ![] :=\nempty_eq _\n\n@[simp] lemma cons_zero_zero : vec_cons (0 : \u03b1) (0 : fin n \u2192 \u03b1) = 0 :=\nby { ext i j, refine fin.cases _ _ i, { refl }, simp }\n\n@[simp] lemma head_zero : vec_head (0 : fin n.succ \u2192 \u03b1) = 0 := rfl\n\n@[simp] lemma tail_zero : vec_tail (0 : fin n.succ \u2192 \u03b1) = 0 := rfl\n\n@[simp] lemma cons_eq_zero_iff {v : fin n \u2192 \u03b1} {x : \u03b1} :\n  vec_cons x v = 0 \u2194 x = 0 \u2227 v = 0 :=\n\u27e8 \u03bb h, \u27e8 congr_fun h 0, by { convert congr_arg vec_tail h, simp } \u27e9,\n  \u03bb \u27e8hx, hv\u27e9, by simp [hx, hv] \u27e9\n\nopen_locale classical\n\nlemma cons_nonzero_iff {v : fin n \u2192 \u03b1} {x : \u03b1} :\n  vec_cons x v \u2260 0 \u2194 (x \u2260 0 \u2228 v \u2260 0) :=\n\u27e8 \u03bb h, not_and_distrib.mp (h \u2218 cons_eq_zero_iff.mpr),\n  \u03bb h, mt cons_eq_zero_iff.mp (not_and_distrib.mpr h) \u27e9\n\nend zero\n\nsection neg\n\nvariables [has_neg \u03b1]\n\n@[simp] lemma neg_empty (v : fin 0 \u2192 \u03b1) : -v = ![] := empty_eq _\n\n@[simp] lemma neg_cons (x : \u03b1) (v : fin n \u2192 \u03b1) :\n  -(vec_cons x v) = vec_cons (-x) (-v) :=\nby { ext i, refine fin.cases _ _ i; simp }\n\n@[simp] lemma head_neg (a : fin n.succ \u2192 \u03b1) : vec_head (-a) = -vec_head a := rfl\n\n@[simp] lemma tail_neg (a : fin n.succ \u2192 \u03b1) : vec_tail (-a) = -vec_tail a := rfl\n\nend neg\n\nsection minor\n\n@[simp] lemma minor_empty (A : matrix m' n' \u03b1) (row : fin 0 \u2192 m') (col : o' \u2192 n') :\n  minor A row col = ![] :=\nempty_eq _\n\n@[simp] lemma minor_cons_row (A : matrix m' n' \u03b1) (i : m') (row : fin m \u2192 m') (col : o' \u2192 n') :\n  minor A (vec_cons i row) col = vec_cons (\u03bb j, A i (col j)) (minor A row col) :=\nby { ext i j, refine fin.cases _ _ i; simp [minor] }\n\nend minor\n\nend matrix\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/matrix/notation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332893, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7085782782003458}}
{"text": "/-\nExists introduction. To prove \u2203 (p : P), Q\n-/\n\n/-\nA proof of \u2203 (p : P), Q is a *dependent* pair,\n\u27e8 p, q \u27e9, where (p : P) is a \"witness\" to the\nexistential proposition, and q is a proof of \nQ. \n\nVery often, Q will be *about* p, e.g., that\np is an \"odd prime\", or a \"nice person\". Q \nwill be the result of aplying a predicate Q'\nto P. Q is short for Q' p, with Q' : Person \n\u2192 Prop being a property of a person, such as\nthe property of being nice. \n\n\u2203 (p : Person), Q' p thus asserts that there \nis *some* person with property Q'. So a proof\nof this proposition will be a dependent pair,\n\u27e8 (p : P), (q : Q' p) \u27e9, with Q' a predicate\non values, p, of type P.\n-/\n\nexample : \u2203 (n : nat), n = 0 :=\n\u27e8 0, eq.refl 0 \u27e9 \n\n/-\nThere exists a natural number that is the square\nof another natural number. \n-/\nexample : \u2203 (n : nat), \u2203 (m : nat), n = m*m :=\n\u27e84, \u27e82, rfl\u27e9 \u27e9 \n\nexample : \u2203 (n : nat), \u2203 (m : nat), n = m*m :=\nbegin\nend\n\n/-\nIf everyone likes Mary then someone likes Mary.\n-/\naxiom Person : Type\naxiom Mary : Person\naxiom Likes : Person \u2192 Person \u2192 Prop\n\n\nexample : \n(\u2200 (p : Person), Likes p Mary) \u2192 \n(\u2203 (q : Person), Likes q Mary) :=\nbegin\n  assume h,\n  refine \u27e8Mary, _\u27e9,\n  apply h Mary,\nend \n\n/-\nExercise: \u2203 elimination.\n-/\n\n\n/-\nPractice\n-/\n\n-- Proof of transitivity of \u2192 \nexample : \u2200 (P Q R : Prop), (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  assume P Q R pq qr p,\n  apply qr (pq p),\nend\n\nexample : \u2200 (P Q R : Prop), (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\n\u03bb P Q R pq qr p, \n  qr \n    (pq \n      p\n    )\n\nexample : \u2200 (P : Prop), P \u2227 \u00ac P \u2192 false :=\nbegin\n assume (P : Prop),\n assume (pnp : P \u2227 \u00ac P),\n cases pnp with p np,\n apply np p,\nend\n\nexample : \u2200 (n : nat), n = 0 \u2228 n \u2260 0 :=\nbegin\n  assume n,\n  cases n,\n  apply or.inl rfl,\n  apply or.inr _,\n  assume ns,\n  cases ns,\nend\n\nexample : \u2200 (n : nat), n = 0 \u2228 n \u2260 0 :=\n\u03bb (n : nat),\n  match n with\n  | nat.zero := or.inl (rfl)\n  | (nat.succ n') := or.inr (\u03bb sn, \n    match sn with\n    end\n  )\n  end\n\n/-\nProve, \u2200 (n : nat), n = 0 \u2228 n \u2260 0.\n\nProof. To begin, we'll assume that n\nis an arbitrary natural number (forall\nintroduction) and in this context what\nremains to be proved is n = 0 \u2228 n \u2260 0.\n\nProof: By case analysis on the possible\nforms of n.\n\nCase 1, base case: n = 0. In this case\nthe disjuction is 0 = 0 \u2228 ) \u2260 0 is true\nbecause the left disjuct is trivially \ntrue (by reflexivity of equality).\n\nCase 2: n = succ n'. What remains to be\nproved is succ n' = 0 \u2228 succ n' \u2260 0.  We\nwill prove this is true by proving that\nthe right hand side is true: succ n' \u2260 0.\n\nProof: This is true by Peano's axioms of\narithmetic. Zero is axomatically not equal\nto any other natural number. \n-/\n\nexample : \u2200 (n : nat), \u2203 m, m = n + 2 :=\n\u03bb n, \nbegin\n  apply exists.intro (n+2), \n  apply rfl,\nend\n\n\n", "meta": {"author": "kevinsullivan", "repo": "complogic-s21", "sha": "99039501b770248c8ceb39890be5dfe129dc1082", "save_path": "github-repos/lean/kevinsullivan-complogic-s21", "path": "github-repos/lean/kevinsullivan-complogic-s21/complogic-s21-99039501b770248c8ceb39890be5dfe129dc1082/src/inClassNotes/predicate_logic/exists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603725, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7085782779367233}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.real.basic\nimport data.real.sqrt\nimport data.real.nnreal\n\n/-!\n# IMO 2008 Q4\nFind all functions `f : (0,\u221e) \u2192 (0,\u221e)` (so, `f` is a function from the positive real\nnumbers to the positive real numbers) such that\n      ```\n      (f(w)^2 + f(x)^2)/(f(y^2) + f(z^2)) = (w^2 + x^2)/(y^2 + z^2)\n      ```\nfor all positive real numbers `w`, `x`, `y`, `z`, satisfying `wx = yz`.\n\n# Solution\nThe desired theorem is that either `f = \u03bb x, x` or `f = \u03bb x, 1/x`\n-/\n\nopen real\n\nlemma abs_eq_one_of_pow_eq_one (x : \u211d) (n : \u2115) (hn : n \u2260 0) (h : x ^ n = 1) : |x| = 1 :=\nby rw [\u2190 pow_left_inj (abs_nonneg x) zero_le_one (pos_iff_ne_zero.2 hn), one_pow, pow_abs, h,\n  abs_one]\n\ntheorem imo2008_q4\n  (f : \u211d \u2192 \u211d)\n  (H\u2081 : \u2200 x > 0, f(x) > 0) :\n  (\u2200 w x y z : \u211d, 0 < w \u2192 0 < x \u2192 0 < y \u2192 0 < z \u2192 w * x = y * z \u2192\n    (f(w) ^ 2 + f(x) ^ 2) / (f(y ^ 2) + f(z ^ 2)) = (w ^ 2 + x ^ 2) / (y ^ 2 + z ^ 2)) \u2194\n  ((\u2200 x > 0, f(x) = x) \u2228 (\u2200 x > 0, f(x) = 1 / x)) :=\nbegin\n  split, swap,\n  -- proof that f(x) = x and f(x) = 1/x satisfy the condition\n  { rintros (h | h),\n    { intros w x y z hw hx hy hz hprod,\n      rw [h w hw, h x hx, h (y ^ 2) (pow_pos hy 2), h (z ^ 2) (pow_pos hz 2)] },\n    { intros w x y z hw hx hy hz hprod,\n      rw [h w hw, h x hx, h (y ^ 2) (pow_pos hy 2), h (z ^ 2) (pow_pos hz 2)],\n      have hy2z2 : y ^ 2 + z ^ 2 \u2260 0 := ne_of_gt (add_pos (pow_pos hy 2) (pow_pos hz 2)),\n      have hz2y2 : z ^ 2 + y ^ 2 \u2260 0 := ne_of_gt (add_pos (pow_pos hz 2) (pow_pos hy 2)),\n      have hp2 : w ^ 2 * x ^ 2 = y ^ 2 * z ^ 2,\n      { rw [\u2190 mul_pow w x 2, \u2190 mul_pow y z 2, hprod] },\n      field_simp [ne_of_gt hw, ne_of_gt hx, ne_of_gt hy, ne_of_gt hz, hy2z2, hz2y2, hp2],\n      ring } },\n\n  -- proof that the only solutions are f(x) = x or f(x) = 1/x\n  intro H\u2082,\n  have h\u2080 : f(1) \u2260 0, { specialize H\u2081 1 zero_lt_one, exact ne_of_gt H\u2081 },\n\n  have h\u2081 : f(1) = 1,\n  { specialize H\u2082 1 1 1 1 zero_lt_one zero_lt_one zero_lt_one zero_lt_one rfl,\n    norm_num at H\u2082,\n    simp only [\u2190 two_mul] at H\u2082,\n    rw mul_div_mul_left (f(1) ^ 2) (f 1) two_ne_zero at H\u2082,\n    rwa \u2190 (div_eq_iff h\u2080).mpr (sq (f 1)) },\n\n  have h\u2082 : \u2200 x > 0, (f(x) - x) * (f(x) - 1 / x) = 0,\n  { intros x hx,\n    have h1xss : 1 * x = (sqrt x) * (sqrt x), { rw [one_mul, mul_self_sqrt (le_of_lt hx)] },\n    specialize H\u2082 1 x (sqrt x) (sqrt x) zero_lt_one hx (sqrt_pos.mpr hx) (sqrt_pos.mpr hx) h1xss,\n    rw [h\u2081, one_pow 2, sq_sqrt (le_of_lt hx), \u2190 two_mul (f(x)), \u2190 two_mul x] at H\u2082,\n    have hx_ne_0 : x \u2260 0 := ne_of_gt hx,\n    have hfx_ne_0 : f(x) \u2260 0, { specialize H\u2081 x hx, exact ne_of_gt H\u2081 },\n    field_simp at H\u2082,\n\n    have h1 : (2 * x) * ((f(x) - x) * (f(x) - 1 / x)) = 0,\n    { calc  (2 * x) * ((f(x) - x) * (f(x) - 1 / x))\n          = 2 * (f(x) - x) * (x * f(x) - x * 1 / x) : by ring\n      ... = 2 * (f(x) - x) * (x * f(x) - 1) : by rw (mul_div_cancel_left 1 hx_ne_0)\n      ... = ((1 + f(x) ^ 2) * (2 * x) - (1 + x ^ 2) * (2 * f(x))) : by ring\n      ... = 0 : sub_eq_zero.mpr H\u2082 },\n\n    have h2x_ne_0 : 2 * x \u2260 0 := mul_ne_zero two_ne_zero hx_ne_0,\n\n    calc  ((f(x) - x) * (f(x) - 1 / x))\n        = (2 * x) * ((f(x) - x) * (f(x) - 1 / x)) / (2 * x) : (mul_div_cancel_left _ h2x_ne_0).symm\n    ... = 0 : by { rw h1, exact zero_div (2 * x) } },\n\n  have h\u2083 : \u2200 x > 0, f(x) = x \u2228 f(x) = 1 / x, { simpa [sub_eq_zero] using h\u2082 },\n\n  by_contradiction,\n  push_neg at h,\n  rcases h with \u27e8\u27e8b, hb, hfb\u2081\u27e9, \u27e8a, ha, hfa\u2081\u27e9\u27e9,\n  obtain hfa\u2082 := or.resolve_right (h\u2083 a ha) hfa\u2081, -- f(a) \u2260 1/a, f(a) = a\n  obtain hfb\u2082 := or.resolve_left (h\u2083 b hb) hfb\u2081,  -- f(b) \u2260 b, f(b) = 1/b\n\n  have hab : a * b > 0 := mul_pos ha hb,\n  have habss : a * b = sqrt(a * b) * sqrt(a * b) := (mul_self_sqrt (le_of_lt hab)).symm,\n\n  specialize H\u2082 a b (sqrt (a * b)) (sqrt (a * b)) ha hb (sqrt_pos.mpr hab) (sqrt_pos.mpr hab) habss,\n  rw [sq_sqrt (le_of_lt hab), \u2190 two_mul (f(a * b)), \u2190 two_mul (a * b)] at H\u2082,\n  rw [hfa\u2082, hfb\u2082] at H\u2082,\n\n  have h2ab_ne_0 : 2 * (a * b) \u2260 0 := mul_ne_zero two_ne_zero (ne_of_gt hab),\n\n  specialize h\u2083 (a * b) hab,\n  cases h\u2083 with hab\u2081 hab\u2082,\n\n  -- f(ab) = ab \u2192 b^4 = 1 \u2192 b = 1 \u2192 f(b) = b \u2192 false\n  { have H\u2083 : (a ^ 2 + (1 / b) ^ 2) / (2 * (a * b)) = (a ^ 2 + b ^ 2) / (2 * (a * b)) \u2194\n              1 / b ^ 2 = b ^ 2 \u2228 2 * (a * b) = 0,\n    { field_simp [h2ab_ne_0], },\n    rw [hab\u2081, H\u2083] at H\u2082,\n    obtain hb\u2081 := or.resolve_right H\u2082 h2ab_ne_0,\n    field_simp [ne_of_gt hb] at hb\u2081,\n    rw (show b ^ 2 * b ^ 2 = b ^ 4, by ring) at hb\u2081,\n    obtain hb\u2082 := abs_eq_one_of_pow_eq_one b 4 (show 4 \u2260 0, by norm_num) hb\u2081.symm,\n    rw abs_of_pos hb at hb\u2082, rw hb\u2082 at hfb\u2081, exact hfb\u2081 h\u2081 },\n\n  -- f(ab) = 1/ab \u2192 a^4 = 1 \u2192 a = 1 \u2192 f(a) = 1/a \u2192 false\n  { have hb_ne_0 : b \u2260 0 := ne_of_gt hb,\n    rw hab\u2082 at H\u2082, field_simp at H\u2082,\n    rw \u2190 sub_eq_zero at H\u2082,\n    rw (show (a ^ 2 * b ^ 2 + 1) * (a * b) * (2 * (a * b)) - (a ^ 2 + b ^ 2) * (b ^ 2 * 2)\n            = 2 * (b ^ 4) * (a ^ 4 - 1), by ring) at H\u2082,\n    have h2b4_ne_0 : 2 * (b ^ 4) \u2260 0 := mul_ne_zero two_ne_zero (pow_ne_zero 4 hb_ne_0),\n    have ha\u2081 : a ^ 4 = 1, { simpa [sub_eq_zero, h2b4_ne_0] using H\u2082 },\n    obtain ha\u2082 := abs_eq_one_of_pow_eq_one a 4 (show 4 \u2260 0, by norm_num) ha\u2081,\n    rw abs_of_pos ha at ha\u2082, rw ha\u2082 at hfa\u2081, norm_num at hfa\u2081 },\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/archive/imo/imo2008_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7085782750349434}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, R\u00e9my Degenne\n-/\nimport algebra.order.group\nimport data.set.basic\nimport order.rel_iso\nimport order.order_dual\n\n/-!\n# Intervals\n\nIn any preorder `\u03b1`, we define intervals (which on each side can be either infinite, open, or\nclosed) using the following naming conventions:\n- `i`: infinite\n- `o`: open\n- `c`: closed\n\nEach interval has the name `I` + letter for left side + letter for right side. For instance,\n`Ioc a b` denotes the inverval `(a, b]`.\n\nThis file contains these definitions, and basic facts on inclusion, intersection, difference of\nintervals (where the precise statements may depend on the properties of the order, in particular\nfor some statements it should be `linear_order` or `densely_ordered`).\n\nTODO: This is just the beginning; a lot of rules are missing\n-/\n\nuniverse u\n\nnamespace set\n\nopen set\nopen order_dual (to_dual of_dual)\n\nsection intervals\nvariables {\u03b1 : Type u} [preorder \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 x : \u03b1}\n\n/-- Left-open right-open interval -/\ndef Ioo (a b : \u03b1) := {x | a < x \u2227 x < b}\n\n/-- Left-closed right-open interval -/\ndef Ico (a b : \u03b1) := {x | a \u2264 x \u2227 x < b}\n\n/-- Left-infinite right-open interval -/\ndef Iio (a : \u03b1) := {x | x < a}\n\n/-- Left-closed right-closed interval -/\ndef Icc (a b : \u03b1) := {x | a \u2264 x \u2227 x \u2264 b}\n\n/-- Left-infinite right-closed interval -/\ndef Iic (b : \u03b1) := {x | x \u2264 b}\n\n/-- Left-open right-closed interval -/\ndef Ioc (a b : \u03b1) := {x | a < x \u2227 x \u2264 b}\n\n/-- Left-closed right-infinite interval -/\ndef Ici (a : \u03b1) := {x | a \u2264 x}\n\n/-- Left-open right-infinite interval -/\ndef Ioi (a : \u03b1) := {x | a < x}\n\nlemma Ioo_def (a b : \u03b1) : {x | a < x \u2227 x < b} = Ioo a b := rfl\n\nlemma Ico_def (a b : \u03b1) : {x | a \u2264 x \u2227 x < b} = Ico a b := rfl\n\nlemma Iio_def (a : \u03b1) : {x | x < a} = Iio a := rfl\n\nlemma Icc_def (a b : \u03b1) : {x | a \u2264 x \u2227 x \u2264 b} = Icc a b := rfl\n\nlemma Iic_def (b : \u03b1) : {x | x \u2264 b} = Iic b := rfl\n\nlemma Ioc_def (a b : \u03b1) : {x | a < x \u2227 x \u2264 b} = Ioc a b := rfl\n\nlemma Ici_def (a : \u03b1) : {x | a \u2264 x} = Ici a := rfl\n\nlemma Ioi_def (a : \u03b1) : {x | a < x} = Ioi a := rfl\n\n@[simp] lemma mem_Ioo : x \u2208 Ioo a b \u2194 a < x \u2227 x < b := iff.rfl\n@[simp] lemma mem_Ico : x \u2208 Ico a b \u2194 a \u2264 x \u2227 x < b := iff.rfl\n@[simp] lemma mem_Iio : x \u2208 Iio b \u2194 x < b := iff.rfl\n@[simp] lemma mem_Icc : x \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b := iff.rfl\n@[simp] lemma mem_Iic : x \u2208 Iic b \u2194 x \u2264 b := iff.rfl\n@[simp] lemma mem_Ioc : x \u2208 Ioc a b \u2194 a < x \u2227 x \u2264 b := iff.rfl\n@[simp] lemma mem_Ici : x \u2208 Ici a \u2194 a \u2264 x := iff.rfl\n@[simp] lemma mem_Ioi : x \u2208 Ioi a \u2194 a < x := iff.rfl\n\n@[simp] lemma left_mem_Ioo : a \u2208 Ioo a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma left_mem_Ico : a \u2208 Ico a b \u2194 a < b := by simp [le_refl]\n@[simp] lemma left_mem_Icc : a \u2208 Icc a b \u2194 a \u2264 b := by simp [le_refl]\n@[simp] lemma left_mem_Ioc : a \u2208 Ioc a b \u2194 false := by simp [lt_irrefl]\nlemma left_mem_Ici : a \u2208 Ici a := by simp\n@[simp] lemma right_mem_Ioo : b \u2208 Ioo a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma right_mem_Ico : b \u2208 Ico a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma right_mem_Icc : b \u2208 Icc a b \u2194 a \u2264 b := by simp [le_refl]\n@[simp] lemma right_mem_Ioc : b \u2208 Ioc a b \u2194 a < b := by simp [le_refl]\nlemma right_mem_Iic : a \u2208 Iic a := by simp\n\n@[simp] lemma dual_Ici : Ici (to_dual a) = of_dual \u207b\u00b9' Iic a := rfl\n@[simp] lemma dual_Iic : Iic (to_dual a) = of_dual \u207b\u00b9' Ici a := rfl\n@[simp] lemma dual_Ioi : Ioi (to_dual a) = of_dual \u207b\u00b9' Iio a := rfl\n@[simp] lemma dual_Iio : Iio (to_dual a) = of_dual \u207b\u00b9' Ioi a := rfl\n@[simp] lemma dual_Icc : Icc (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Icc b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ioc : Ioc (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ico b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ico : Ico (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ioc b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ioo : Ioo (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ioo b a :=\nset.ext $ \u03bb x, and_comm _ _\n\n@[simp] lemma nonempty_Icc : (Icc a b).nonempty \u2194 a \u2264 b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans hx.2, \u03bb h, \u27e8a, left_mem_Icc.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ico : (Ico a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans_lt hx.2, \u03bb h, \u27e8a, left_mem_Ico.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ioc : (Ioc a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans_le hx.2, \u03bb h, \u27e8b, right_mem_Ioc.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ici : (Ici a).nonempty := \u27e8a, left_mem_Ici\u27e9\n\n@[simp] lemma nonempty_Iic : (Iic a).nonempty := \u27e8a, right_mem_Iic\u27e9\n\n@[simp] lemma nonempty_Ioo [densely_ordered \u03b1] : (Ioo a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, ha, hb\u27e9, ha.trans hb, exists_between\u27e9\n\n@[simp] lemma nonempty_Ioi [no_top_order \u03b1] : (Ioi a).nonempty := no_top a\n\n@[simp] lemma nonempty_Iio [no_bot_order \u03b1] : (Iio a).nonempty := no_bot a\n\nlemma nonempty_Icc_subtype (h : a \u2264 b) : nonempty (Icc a b) :=\nnonempty.to_subtype (nonempty_Icc.mpr h)\n\nlemma nonempty_Ico_subtype (h : a < b) : nonempty (Ico a b) :=\nnonempty.to_subtype (nonempty_Ico.mpr h)\n\nlemma nonempty_Ioc_subtype (h : a < b) : nonempty (Ioc a b) :=\nnonempty.to_subtype (nonempty_Ioc.mpr h)\n\n/-- An interval `Ici a` is nonempty. -/\ninstance nonempty_Ici_subtype : nonempty (Ici a) :=\nnonempty.to_subtype nonempty_Ici\n\n/-- An interval `Iic a` is nonempty. -/\ninstance nonempty_Iic_subtype : nonempty (Iic a) :=\nnonempty.to_subtype nonempty_Iic\n\nlemma nonempty_Ioo_subtype [densely_ordered \u03b1] (h : a < b) : nonempty (Ioo a b) :=\nnonempty.to_subtype (nonempty_Ioo.mpr h)\n\n/-- In a `no_top_order`, the intervals `Ioi` are nonempty. -/\ninstance nonempty_Ioi_subtype [no_top_order \u03b1] : nonempty (Ioi a) :=\nnonempty.to_subtype nonempty_Ioi\n\n/-- In a `no_bot_order`, the intervals `Iio` are nonempty. -/\ninstance nonempty_Iio_subtype [no_bot_order \u03b1] : nonempty (Iio a) :=\nnonempty.to_subtype nonempty_Iio\n\n@[simp] lemma Icc_eq_empty (h : \u00aca \u2264 b) : Icc a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans hb)\n\n@[simp] lemma Ico_eq_empty (h : \u00aca < b) : Ico a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans_lt hb)\n\n@[simp] lemma Ioc_eq_empty (h : \u00aca < b) : Ioc a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans_le hb)\n\n@[simp] lemma Ioo_eq_empty (h : \u00aca < b) : Ioo a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9,  h (ha.trans hb)\n\n@[simp] lemma Icc_eq_empty_of_lt (h : b < a) : Icc a b = \u2205 :=\nIcc_eq_empty h.not_le\n\n@[simp] lemma Ico_eq_empty_of_le (h : b \u2264 a) : Ico a b = \u2205 :=\nIco_eq_empty h.not_lt\n\n@[simp] lemma Ioc_eq_empty_of_le (h : b \u2264 a) : Ioc a b = \u2205 :=\nIoc_eq_empty h.not_lt\n\n@[simp] lemma Ioo_eq_empty_of_le (h : b \u2264 a) : Ioo a b = \u2205 :=\nIoo_eq_empty h.not_lt\n\n@[simp] lemma Ico_self (a : \u03b1) : Ico a a = \u2205 := Ico_eq_empty $ lt_irrefl _\n@[simp] lemma Ioc_self (a : \u03b1) : Ioc a a = \u2205 := Ioc_eq_empty $ lt_irrefl _\n@[simp] lemma Ioo_self (a : \u03b1) : Ioo a a = \u2205 := Ioo_eq_empty $ lt_irrefl _\n\nlemma Ici_subset_Ici : Ici a \u2286 Ici b \u2194 b \u2264 a :=\n\u27e8\u03bb h, h $ left_mem_Ici, \u03bb h x hx, h.trans hx\u27e9\n\nlemma Iic_subset_Iic : Iic a \u2286 Iic b \u2194 a \u2264 b :=\n@Ici_subset_Ici (order_dual \u03b1) _ _ _\n\nlemma Ici_subset_Ioi : Ici a \u2286 Ioi b \u2194 b < a :=\n\u27e8\u03bb h, h left_mem_Ici, \u03bb h x hx, h.trans_le hx\u27e9\n\nlemma Iic_subset_Iio : Iic a \u2286 Iio b \u2194 a < b :=\n\u27e8\u03bb h, h right_mem_Iic, \u03bb h x hx, lt_of_le_of_lt hx h\u27e9\n\nlemma Ioo_subset_Ioo (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ioo a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans_lt hx\u2081, hx\u2082.trans_le h\u2082\u27e9\n\nlemma Ioo_subset_Ioo_left (h : a\u2081 \u2264 a\u2082) : Ioo a\u2082 b \u2286 Ioo a\u2081 b :=\nIoo_subset_Ioo h le_rfl\n\nlemma Ioo_subset_Ioo_right (h : b\u2081 \u2264 b\u2082) : Ioo a b\u2081 \u2286 Ioo a b\u2082 :=\nIoo_subset_Ioo le_rfl h\n\nlemma Ico_subset_Ico (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ico a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans hx\u2081, hx\u2082.trans_le h\u2082\u27e9\n\nlemma Ico_subset_Ico_left (h : a\u2081 \u2264 a\u2082) : Ico a\u2082 b \u2286 Ico a\u2081 b :=\nIco_subset_Ico h le_rfl\n\nlemma Ico_subset_Ico_right (h : b\u2081 \u2264 b\u2082) : Ico a b\u2081 \u2286 Ico a b\u2082 :=\nIco_subset_Ico le_rfl h\n\nlemma Icc_subset_Icc (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Icc a\u2081 b\u2081 \u2286 Icc a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans hx\u2081, le_trans hx\u2082 h\u2082\u27e9\n\nlemma Icc_subset_Icc_left (h : a\u2081 \u2264 a\u2082) : Icc a\u2082 b \u2286 Icc a\u2081 b :=\nIcc_subset_Icc h le_rfl\n\nlemma Icc_subset_Icc_right (h : b\u2081 \u2264 b\u2082) : Icc a b\u2081 \u2286 Icc a b\u2082 :=\nIcc_subset_Icc le_rfl h\n\nlemma Icc_subset_Ioo (ha : a\u2082 < a\u2081) (hb : b\u2081 < b\u2082) :\n  Icc a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 :=\n\u03bb x hx, \u27e8ha.trans_le hx.1, hx.2.trans_lt hb\u27e9\n\nlemma Icc_subset_Ici_self : Icc a b \u2286 Ici a := \u03bb x, and.left\n\nlemma Icc_subset_Iic_self : Icc a b \u2286 Iic b := \u03bb x, and.right\n\nlemma Ioc_subset_Iic_self : Ioc a b \u2286 Iic b := \u03bb x, and.right\n\nlemma Ioc_subset_Ioc (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ioc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans_lt hx\u2081, hx\u2082.trans h\u2082\u27e9\n\nlemma Ioc_subset_Ioc_left (h : a\u2081 \u2264 a\u2082) : Ioc a\u2082 b \u2286 Ioc a\u2081 b :=\nIoc_subset_Ioc h le_rfl\n\nlemma Ioc_subset_Ioc_right (h : b\u2081 \u2264 b\u2082) : Ioc a b\u2081 \u2286 Ioc a b\u2082 :=\nIoc_subset_Ioc le_rfl h\n\nlemma Ico_subset_Ioo_left (h\u2081 : a\u2081 < a\u2082) : Ico a\u2082 b \u2286 Ioo a\u2081 b :=\n\u03bb x, and.imp_left h\u2081.trans_le\n\nlemma Ioc_subset_Ioo_right (h : b\u2081 < b\u2082) : Ioc a b\u2081 \u2286 Ioo a b\u2082 :=\n\u03bb x, and.imp_right $ \u03bb h', h'.trans_lt h\n\nlemma Icc_subset_Ico_right (h\u2081 : b\u2081 < b\u2082) : Icc a b\u2081 \u2286 Ico a b\u2082 :=\n\u03bb x, and.imp_right $ \u03bb h\u2082, h\u2082.trans_lt h\u2081\n\nlemma Ioo_subset_Ico_self : Ioo a b \u2286 Ico a b := \u03bb x, and.imp_left le_of_lt\n\nlemma Ioo_subset_Ioc_self : Ioo a b \u2286 Ioc a b := \u03bb x, and.imp_right le_of_lt\n\nlemma Ico_subset_Icc_self : Ico a b \u2286 Icc a b := \u03bb x, and.imp_right le_of_lt\n\nlemma Ioc_subset_Icc_self : Ioc a b \u2286 Icc a b := \u03bb x, and.imp_left le_of_lt\n\nlemma Ioo_subset_Icc_self : Ioo a b \u2286 Icc a b :=\nsubset.trans Ioo_subset_Ico_self Ico_subset_Icc_self\n\nlemma Ico_subset_Iio_self : Ico a b \u2286 Iio b := \u03bb x, and.right\n\nlemma Ioo_subset_Iio_self : Ioo a b \u2286 Iio b := \u03bb x, and.right\n\nlemma Ioc_subset_Ioi_self : Ioc a b \u2286 Ioi a := \u03bb x, and.left\n\nlemma Ioo_subset_Ioi_self : Ioo a b \u2286 Ioi a := \u03bb x, and.left\n\nlemma Ioi_subset_Ici_self : Ioi a \u2286 Ici a := \u03bb x hx, le_of_lt hx\n\nlemma Iio_subset_Iic_self : Iio a \u2286 Iic a := \u03bb x hx, le_of_lt hx\n\nlemma Ico_subset_Ici_self : Ico a b \u2286 Ici a := \u03bb x, and.left\n\nlemma Icc_subset_Icc_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Icc a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans hx, hx'.trans h'\u27e9\u27e9\n\nlemma Icc_subset_Ioo_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 \u2194 a\u2082 < a\u2081 \u2227 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans_le hx, hx'.trans_lt h'\u27e9\u27e9\n\nlemma Icc_subset_Ico_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans hx, hx'.trans_lt h'\u27e9\u27e9\n\nlemma Icc_subset_Ioc_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 \u2194 a\u2082 < a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans_le hx, hx'.trans h'\u27e9\u27e9\n\nlemma Icc_subset_Iio_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Iio b\u2082 \u2194 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, h \u27e8h\u2081, le_rfl\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, hx'.trans_lt h\u27e9\n\nlemma Icc_subset_Ioi_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioi a\u2082 \u2194 a\u2082 < a\u2081 :=\n\u27e8\u03bb h, h \u27e8le_rfl, h\u2081\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, h.trans_le hx\u27e9\n\nlemma Icc_subset_Iic_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Iic b\u2082 \u2194 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, h \u27e8h\u2081, le_rfl\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, hx'.trans h\u27e9\n\nlemma Icc_subset_Ici_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ici a\u2082 \u2194 a\u2082 \u2264 a\u2081 :=\n\u27e8\u03bb h, h \u27e8le_rfl, h\u2081\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, h.trans hx\u27e9\n\nlemma Icc_ssubset_Icc_left (hI : a\u2082 \u2264 b\u2082) (ha : a\u2082 < a\u2081) (hb : b\u2081 \u2264 b\u2082) :\n  Icc a\u2081 b\u2081 \u2282 Icc a\u2082 b\u2082 :=\n(ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr\n  \u27e8a\u2082, left_mem_Icc.mpr hI, not_and.mpr (\u03bb f g, lt_irrefl a\u2082 (ha.trans_le f))\u27e9\n\nlemma Icc_ssubset_Icc_right (hI : a\u2082 \u2264 b\u2082) (ha : a\u2082 \u2264 a\u2081) (hb : b\u2081 < b\u2082) :\n  Icc a\u2081 b\u2081 \u2282 Icc a\u2082 b\u2082 :=\n(ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr\n  \u27e8b\u2082, right_mem_Icc.mpr hI, (\u03bb f, lt_irrefl b\u2081 (hb.trans_le f.2))\u27e9\n\n/-- If `a \u2264 b`, then `(b, +\u221e) \u2286 (a, +\u221e)`. In preorders, this is just an implication. If you need\nthe equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/\nlemma Ioi_subset_Ioi (h : a \u2264 b) : Ioi b \u2286 Ioi a :=\n\u03bb x hx, h.trans_lt hx\n\n/-- If `a \u2264 b`, then `(b, +\u221e) \u2286 [a, +\u221e)`. In preorders, this is just an implication. If you need\nthe equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/\nlemma Ioi_subset_Ici (h : a \u2264 b) : Ioi b \u2286 Ici a :=\nsubset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self\n\n/-- If `a \u2264 b`, then `(-\u221e, a) \u2286 (-\u221e, b)`. In preorders, this is just an implication. If you need\nthe equivalence in linear orders, use `Iio_subset_Iio_iff`. -/\nlemma Iio_subset_Iio (h : a \u2264 b) : Iio a \u2286 Iio b :=\n\u03bb x hx, lt_of_lt_of_le hx h\n\n/-- If `a \u2264 b`, then `(-\u221e, a) \u2286 (-\u221e, b]`. In preorders, this is just an implication. If you need\nthe equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/\nlemma Iio_subset_Iic (h : a \u2264 b) : Iio a \u2286 Iic b :=\nsubset.trans (Iio_subset_Iio h) Iio_subset_Iic_self\n\nlemma Ici_inter_Iic : Ici a \u2229 Iic b = Icc a b := rfl\nlemma Ici_inter_Iio : Ici a \u2229 Iio b = Ico a b := rfl\nlemma Ioi_inter_Iic : Ioi a \u2229 Iic b = Ioc a b := rfl\nlemma Ioi_inter_Iio : Ioi a \u2229 Iio b = Ioo a b := rfl\n\nlemma mem_Icc_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Icc a b := Ioo_subset_Icc_self h\nlemma mem_Ico_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Ico a b := Ioo_subset_Ico_self h\nlemma mem_Ioc_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Ioc a b := Ioo_subset_Ioc_self h\nlemma mem_Icc_of_Ico (h : x \u2208 Ico a b) : x \u2208 Icc a b := Ico_subset_Icc_self h\nlemma mem_Icc_of_Ioc (h : x \u2208 Ioc a b) : x \u2208 Icc a b := Ioc_subset_Icc_self h\nlemma mem_Ici_of_Ioi (h : x \u2208 Ioi a) : x \u2208 Ici a := Ioi_subset_Ici_self h\nlemma mem_Iic_of_Iio (h : x \u2208 Iio a) : x \u2208 Iic a := Iio_subset_Iic_self h\n\nlemma Icc_eq_empty_iff : Icc a b = \u2205 \u2194 \u00aca \u2264 b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc]\n\nlemma Ico_eq_empty_iff : Ico a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico]\n\nlemma Ioc_eq_empty_iff : Ioc a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc]\n\nlemma Ioo_eq_empty_iff [densely_ordered \u03b1] : Ioo a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo]\n\nend intervals\n\nsection partial_order\nvariables {\u03b1 : Type u} [partial_order \u03b1] {a b : \u03b1}\n\n@[simp] lemma Icc_self (a : \u03b1) : Icc a a = {a} :=\nset.ext $ by simp [Icc, le_antisymm_iff, and_comm]\n\n@[simp] lemma Icc_diff_left : Icc a b \\ {a} = Ioc a b :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, eq_comm, and.right_comm]\n\n@[simp] lemma Icc_diff_right : Icc a b \\ {b} = Ico a b :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, and_assoc]\n\n@[simp] lemma Ico_diff_left : Ico a b \\ {a} = Ioo a b :=\next $ \u03bb x, by simp [and.right_comm, \u2190 lt_iff_le_and_ne, eq_comm]\n\n@[simp] lemma Ioc_diff_right : Ioc a b \\ {b} = Ioo a b :=\next $ \u03bb x, by simp [and_assoc, \u2190 lt_iff_le_and_ne]\n\n@[simp] lemma Icc_diff_both : Icc a b \\ {a, b} = Ioo a b :=\nby rw [insert_eq, \u2190 diff_diff, Icc_diff_left, Ioc_diff_right]\n\n@[simp] lemma Ici_diff_left : Ici a \\ {a} = Ioi a :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, eq_comm]\n\n@[simp] lemma Iic_diff_right : Iic a \\ {a} = Iio a :=\next $ \u03bb x, by simp [lt_iff_le_and_ne]\n\n@[simp] lemma Ico_diff_Ioo_same (h : a < b) : Ico a b \\ Ioo a b = {a} :=\nby rw [\u2190 Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 $ left_mem_Ico.2 h)]\n\n@[simp] lemma Ioc_diff_Ioo_same (h : a < b) : Ioc a b \\ Ioo a b = {b} :=\nby rw [\u2190 Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 $ right_mem_Ioc.2 h)]\n\n@[simp] lemma Icc_diff_Ico_same (h : a \u2264 b) : Icc a b \\ Ico a b = {b} :=\nby rw [\u2190 Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 $ right_mem_Icc.2 h)]\n\n@[simp] lemma Icc_diff_Ioc_same (h : a \u2264 b) : Icc a b \\ Ioc a b = {a} :=\nby rw [\u2190 Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 $ left_mem_Icc.2 h)]\n\n@[simp] lemma Icc_diff_Ioo_same (h : a \u2264 b) : Icc a b \\ Ioo a b = {a, b} :=\nby { rw [\u2190 Icc_diff_both, diff_diff_cancel_left], simp [insert_subset, h] }\n\n@[simp] lemma Ici_diff_Ioi_same : Ici a \\ Ioi a = {a} :=\nby rw [\u2190 Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)]\n\n@[simp] lemma Iic_diff_Iio_same : Iic a \\ Iio a = {a} :=\nby rw [\u2190 Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)]\n\n@[simp] lemma Ioi_union_left : Ioi a \u222a {a} = Ici a := ext $ \u03bb x, by simp [eq_comm, le_iff_eq_or_lt]\n\n@[simp] lemma Iio_union_right : Iio a \u222a {a} = Iic a := ext $ \u03bb x, le_iff_lt_or_eq.symm\n\nlemma Ioo_union_left (hab : a < b) : Ioo a b \u222a {a} = Ico a b :=\nby rw [\u2190 Ico_diff_left, diff_union_self,\n  union_eq_self_of_subset_right (singleton_subset_iff.2 $ left_mem_Ico.2 hab)]\n\nlemma Ioo_union_right (hab : a < b) : Ioo a b \u222a {b} = Ioc a b :=\nby simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual\n\nlemma Ioc_union_left (hab : a \u2264 b) : Ioc a b \u222a {a} = Icc a b :=\nby rw [\u2190 Icc_diff_left, diff_union_self,\n  union_eq_self_of_subset_right (singleton_subset_iff.2 $ left_mem_Icc.2 hab)]\n\nlemma Ico_union_right (hab : a \u2264 b) : Ico a b \u222a {b} = Icc a b :=\nby simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual\n\nlemma mem_Ici_Ioi_of_subset_of_subset {s : set \u03b1} (ho : Ioi a \u2286 s) (hc : s \u2286 Ici a) :\n  s \u2208 ({Ici a, Ioi a} : set (set \u03b1)) :=\nclassical.by_cases\n  (\u03bb h : a \u2208 s, or.inl $ subset.antisymm hc $ by rw [\u2190 Ioi_union_left, union_subset_iff]; simp *)\n  (\u03bb h, or.inr $ subset.antisymm (\u03bb x hx, lt_of_le_of_ne (hc hx) (\u03bb heq, h $ heq.symm \u25b8 hx)) ho)\n\nlemma mem_Iic_Iio_of_subset_of_subset {s : set \u03b1} (ho : Iio a \u2286 s) (hc : s \u2286 Iic a) :\n  s \u2208 ({Iic a, Iio a} : set (set \u03b1)) :=\n@mem_Ici_Ioi_of_subset_of_subset (order_dual \u03b1) _ a s ho hc\n\nlemma mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : set \u03b1} (ho : Ioo a b \u2286 s) (hc : s \u2286 Icc a b) :\n  s \u2208 ({Icc a b, Ico a b, Ioc a b, Ioo a b} : set (set \u03b1)) :=\nbegin\n  classical,\n  by_cases ha : a \u2208 s; by_cases hb : b \u2208 s,\n  { refine or.inl (subset.antisymm hc _),\n    rwa [\u2190 Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha,\n      \u2190 Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho },\n  { refine (or.inr $ or.inl $ subset.antisymm _ _),\n    { rw [\u2190 Icc_diff_right],\n      exact subset_diff_singleton hc hb },\n    { rwa [\u2190 Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho } },\n  { refine (or.inr $ or.inr $ or.inl $ subset.antisymm _ _),\n    { rw [\u2190 Icc_diff_left],\n      exact subset_diff_singleton hc ha },\n    { rwa [\u2190 Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho } },\n  { refine (or.inr $ or.inr $ or.inr $ subset.antisymm _ ho),\n    rw [\u2190 Ico_diff_left, \u2190 Icc_diff_right],\n    apply_rules [subset_diff_singleton] }\nend\n\nlemma mem_Ioo_or_eq_endpoints_of_mem_Icc {x : \u03b1} (hmem : x \u2208 Icc a b) :\n  x = a \u2228 x = b \u2228 x \u2208 Ioo a b :=\nbegin\n  rw [mem_Icc, le_iff_lt_or_eq, le_iff_lt_or_eq] at hmem,\n  rcases hmem with \u27e8hxa | hxa, hxb | hxb\u27e9,\n  { exact or.inr (or.inr \u27e8hxa, hxb\u27e9) },\n  { exact or.inr (or.inl hxb) },\n  all_goals { exact or.inl hxa.symm }\nend\n\nlemma mem_Ioo_or_eq_left_of_mem_Ico {x : \u03b1} (hmem : x \u2208 Ico a b) :\n  x = a \u2228 x \u2208 Ioo a b :=\nbegin\n  rw [mem_Ico, le_iff_lt_or_eq] at hmem,\n  rcases hmem with \u27e8hxa | hxa, hxb\u27e9,\n  { exact or.inr \u27e8hxa, hxb\u27e9 },\n  { exact or.inl hxa.symm }\nend\n\nlemma mem_Ioo_or_eq_right_of_mem_Ioc {x : \u03b1} (hmem : x \u2208 Ioc a b) :\n  x = b \u2228 x \u2208 Ioo a b :=\nbegin\n  have := @mem_Ioo_or_eq_left_of_mem_Ico _ _ (to_dual b) (to_dual a) (to_dual x),\n  rw [dual_Ioo, dual_Ico] at this,\n  exact this hmem\nend\n\nlemma Ici_singleton_of_top {a : \u03b1} (h_top : \u2200 x, x \u2264 a) : Ici a = {a} :=\nbegin\n  ext,\n  exact \u27e8\u03bb h, (h_top _).antisymm h, \u03bb h, h.ge\u27e9,\nend\n\nlemma Iic_singleton_of_bot {a : \u03b1} (h_bot : \u2200 x, a \u2264 x) : Iic a = {a} :=\n@Ici_singleton_of_top (order_dual \u03b1) _ a h_bot\n\nlemma Iic_inter_Ioc_of_le {a b c : \u03b1} (h : a \u2264 c) : Iic a \u2229 Ioc b c = Ioc b a :=\next $ \u03bb x, \u27e8\u03bb H, \u27e8H.2.1, H.1\u27e9, \u03bb H, \u27e8H.2, H.1, H.2.trans h\u27e9\u27e9\n\nend partial_order\n\nsection order_top\n\nvariables {\u03b1 : Type u} [preorder \u03b1] [order_top \u03b1] {a : \u03b1}\n\n@[simp] lemma Ici_top {\u03b1 : Type u} [partial_order \u03b1] [order_top \u03b1] :\n  Ici (\u22a4 : \u03b1) = {\u22a4} := Ici_singleton_of_top (\u03bb _, le_top)\n@[simp] lemma Iic_top : Iic (\u22a4 : \u03b1) = univ := eq_univ_of_forall $ \u03bb x, le_top\n@[simp] lemma Icc_top : Icc a \u22a4 = Ici a := by simp [\u2190 Ici_inter_Iic]\n@[simp] lemma Ioc_top : Ioc a \u22a4 = Ioi a := by simp [\u2190 Ioi_inter_Iic]\n\nend order_top\n\nsection order_bot\n\nvariables {\u03b1 : Type u} [preorder \u03b1] [order_bot \u03b1] {a : \u03b1}\n\n@[simp] lemma Iic_bot {\u03b1 : Type u} [partial_order \u03b1] [order_bot \u03b1] :\n  Iic (\u22a5 : \u03b1) = {\u22a5} := Iic_singleton_of_bot (\u03bb _, bot_le)\n@[simp] lemma Ici_bot : Ici (\u22a5 : \u03b1) = univ := @Iic_top (order_dual \u03b1) _ _\n@[simp] lemma Icc_bot : Icc \u22a5 a = Iic a := by simp [\u2190 Ici_inter_Iic]\n@[simp] lemma Ico_bot : Ico \u22a5 a = Iio a := by simp [\u2190 Ici_inter_Iio]\n\nend order_bot\n\nsection linear_order\nvariables {\u03b1 : Type u} [linear_order \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c d : \u03b1}\n\nlemma not_mem_Ici : c \u2209 Ici a \u2194 c < a := not_le\n\nlemma not_mem_Iic : c \u2209 Iic b \u2194 b < c := not_le\n\nlemma not_mem_Icc_of_lt (ha : c < a) : c \u2209 Icc a b :=\nnot_mem_subset Icc_subset_Ici_self $ not_mem_Ici.mpr ha\n\nlemma not_mem_Icc_of_gt (hb : b < c) : c \u2209 Icc a b :=\nnot_mem_subset Icc_subset_Iic_self $ not_mem_Iic.mpr hb\n\nlemma not_mem_Ico_of_lt (ha : c < a) : c \u2209 Ico a b :=\nnot_mem_subset Ico_subset_Ici_self $ not_mem_Ici.mpr ha\n\nlemma not_mem_Ioc_of_gt (hb : b < c) : c \u2209 Ioc a b :=\nnot_mem_subset Ioc_subset_Iic_self $ not_mem_Iic.mpr hb\n\nlemma not_mem_Ioi : c \u2209 Ioi a \u2194 c \u2264 a := not_lt\n\nlemma not_mem_Iio : c \u2209 Iio b \u2194 b \u2264 c := not_lt\n\nlemma not_mem_Ioc_of_le (ha : c \u2264 a) : c \u2209 Ioc a b :=\nnot_mem_subset Ioc_subset_Ioi_self $ not_mem_Ioi.mpr ha\n\nlemma not_mem_Ico_of_ge (hb : b \u2264 c) : c \u2209 Ico a b :=\nnot_mem_subset Ico_subset_Iio_self $ not_mem_Iio.mpr hb\n\nlemma not_mem_Ioo_of_le (ha : c \u2264 a) : c \u2209 Ioo a b :=\nnot_mem_subset Ioo_subset_Ioi_self $ not_mem_Ioi.mpr ha\n\nlemma not_mem_Ioo_of_ge (hb : b \u2264 c) : c \u2209 Ioo a b :=\nnot_mem_subset Ioo_subset_Iio_self $ not_mem_Iio.mpr hb\n\n@[simp] lemma compl_Iic : (Iic a)\u1d9c = Ioi a := ext $ \u03bb _, not_le\n@[simp] lemma compl_Ici : (Ici a)\u1d9c = Iio a := ext $ \u03bb _, not_le\n@[simp] lemma compl_Iio : (Iio a)\u1d9c = Ici a := ext $ \u03bb _, not_lt\n@[simp] lemma compl_Ioi : (Ioi a)\u1d9c = Iic a := ext $ \u03bb _, not_lt\n\n@[simp] lemma Ici_diff_Ici : Ici a \\ Ici b = Ico a b :=\nby rw [diff_eq, compl_Ici, Ici_inter_Iio]\n\n@[simp] lemma Ici_diff_Ioi : Ici a \\ Ioi b = Icc a b :=\nby rw [diff_eq, compl_Ioi, Ici_inter_Iic]\n\n@[simp] lemma Ioi_diff_Ioi : Ioi a \\ Ioi b = Ioc a b :=\nby rw [diff_eq, compl_Ioi, Ioi_inter_Iic]\n\n@[simp] lemma Ioi_diff_Ici : Ioi a \\ Ici b = Ioo a b :=\nby rw [diff_eq, compl_Ici, Ioi_inter_Iio]\n\n@[simp] lemma Iic_diff_Iic : Iic b \\ Iic a = Ioc a b :=\nby rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic]\n\n@[simp] lemma Iio_diff_Iic : Iio b \\ Iic a = Ioo a b :=\nby rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio]\n\n@[simp] lemma Iic_diff_Iio : Iic b \\ Iio a = Icc a b :=\nby rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic]\n\n@[simp] lemma Iio_diff_Iio : Iio b \\ Iio a = Ico a b :=\nby rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio]\n\nlemma Ico_subset_Ico_iff (h\u2081 : a\u2081 < b\u2081) :\n  Ico a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, have a\u2082 \u2264 a\u2081 \u2227 a\u2081 < b\u2082 := h \u27e8le_rfl, h\u2081\u27e9,\n  \u27e8this.1, le_of_not_lt $ \u03bb h', lt_irrefl b\u2082 (h \u27e8this.2.le, h'\u27e9).2\u27e9,\n \u03bb \u27e8h\u2081, h\u2082\u27e9, Ico_subset_Ico h\u2081 h\u2082\u27e9\n\nlemma Ioc_subset_Ioc_iff (h\u2081 : a\u2081 < b\u2081) :\n  Ioc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 \u2194 b\u2081 \u2264 b\u2082 \u2227 a\u2082 \u2264 a\u2081 :=\nby { convert @Ico_subset_Ico_iff (order_dual \u03b1) _ b\u2081 b\u2082 a\u2081 a\u2082 h\u2081; exact (@dual_Ico \u03b1 _ _ _).symm }\n\nlemma Ioo_subset_Ioo_iff [densely_ordered \u03b1] (h\u2081 : a\u2081 < b\u2081) :\n  Ioo a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, begin\n  rcases exists_between h\u2081 with \u27e8x, xa, xb\u27e9,\n  split; refine le_of_not_lt (\u03bb h', _),\n  { have ab := (h \u27e8xa, xb\u27e9).1.trans xb,\n    exact lt_irrefl _ (h \u27e8h', ab\u27e9).1 },\n  { have ab := xa.trans (h \u27e8xa, xb\u27e9).2,\n    exact lt_irrefl _ (h \u27e8ab, h'\u27e9).2 }\nend, \u03bb \u27e8h\u2081, h\u2082\u27e9, Ioo_subset_Ioo h\u2081 h\u2082\u27e9\n\nlemma Ico_eq_Ico_iff (h : a\u2081 < b\u2081 \u2228 a\u2082 < b\u2082) : Ico a\u2081 b\u2081 = Ico a\u2082 b\u2082 \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082 :=\n\u27e8\u03bb e, begin\n  simp [subset.antisymm_iff] at e, simp [le_antisymm_iff],\n  cases h; simp [Ico_subset_Ico_iff h] at e;\n    [ rcases e with \u27e8\u27e8h\u2081, h\u2082\u27e9, e'\u27e9, rcases e with \u27e8e', \u27e8h\u2081, h\u2082\u27e9\u27e9 ];\n    have := (Ico_subset_Ico_iff $ h\u2081.trans_lt $ h.trans_le h\u2082).1 e';\n    tauto\nend, \u03bb \u27e8h\u2081, h\u2082\u27e9, by rw [h\u2081, h\u2082]\u27e9\n\nopen_locale classical\n\n@[simp] lemma Ioi_subset_Ioi_iff : Ioi b \u2286 Ioi a \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Ioi_subset_Ioi h\u27e9,\n  by_contradiction ba,\n  exact lt_irrefl _ (h (not_le.mp ba))\nend\n\n@[simp] lemma Ioi_subset_Ici_iff [densely_ordered \u03b1] : Ioi b \u2286 Ici a \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Ioi_subset_Ici h\u27e9,\n  by_contradiction ba,\n  obtain \u27e8c, bc, ca\u27e9 : \u2203c, b < c \u2227 c < a := exists_between (not_le.mp ba),\n  exact lt_irrefl _ (ca.trans_le (h bc))\nend\n\n@[simp] lemma Iio_subset_Iio_iff : Iio a \u2286 Iio b \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Iio_subset_Iio h\u27e9,\n  by_contradiction ab,\n  exact lt_irrefl _ (h (not_le.mp ab))\nend\n\n@[simp] lemma Iio_subset_Iic_iff [densely_ordered \u03b1] : Iio a \u2286 Iic b \u2194 a \u2264 b :=\nby rw [\u2190diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt]\n\n/-! ### Unions of adjacent intervals -/\n\n/-! #### Two infinite intervals -/\n\n@[simp] lemma Iic_union_Ici : Iic a \u222a Ici a = univ := eq_univ_of_forall (\u03bb x, le_total x a)\n\n@[simp] lemma Iio_union_Ici : Iio a \u222a Ici a = univ := eq_univ_of_forall (\u03bb x, lt_or_le x a)\n\n@[simp] lemma Iic_union_Ioi : Iic a \u222a Ioi a = univ := eq_univ_of_forall (\u03bb x, le_or_lt x a)\n\n/-! #### A finite and an infinite interval -/\n\nlemma Ioo_union_Ioi' (h\u2081 : c < b) :\n  Ioo a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioo, mem_Ioi, min_lt_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x < b := (le_of_not_gt hc).trans_lt h\u2081,\n    tauto },\nend\n\nlemma Ioo_union_Ioi (h : c < max a b) :\n  Ioo a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ioo_union_Ioi' h },\n  { rw min_comm,\n    simp [*, min_eq_left_of_lt] },\nend\n\nlemma Ioi_subset_Ioo_union_Ici : Ioi a \u2286 Ioo a b \u222a Ici b :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b \u222a Ici b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_le) Ioi_subset_Ioo_union_Ici\n\nlemma Ici_subset_Ico_union_Ici : Ici a \u2286 Ico a b \u222a Ici b :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ico_union_Ici_eq_Ici (h : a \u2264 b) : Ico a b \u222a Ici b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans) Ici_subset_Ico_union_Ici\n\nlemma Ico_union_Ici' (h\u2081 : c \u2264 b) :\n  Ico a b \u222a Ici c = Ici (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ico, mem_Ici, min_le_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\nend\n\nlemma Ico_union_Ici  (h : c \u2264 max a b) :\n  Ico a b \u222a Ici c = Ici (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ico_union_Ici' h },\n  { simp [*] },\nend\n\nlemma Ioi_subset_Ioc_union_Ioi : Ioi a \u2286 Ioc a b \u222a Ioi b :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ioc_union_Ioi_eq_Ioi (h : a \u2264 b) : Ioc a b \u222a Ioi b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_lt) Ioi_subset_Ioc_union_Ioi\n\nlemma Ioc_union_Ioi' (h\u2081 : c \u2264 b) :\n  Ioc a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioc, mem_Ioi, min_lt_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081,\n    tauto },\nend\n\nlemma Ioc_union_Ioi (h : c \u2264 max a b) :\n  Ioc a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ioc_union_Ioi' h },\n  { simp [*] },\nend\n\nlemma Ici_subset_Icc_union_Ioi : Ici a \u2286 Icc a b \u222a Ioi b :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Icc_union_Ioi_eq_Ici (h : a \u2264 b) : Icc a b \u222a Ioi b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left $ \u03bb hx', h.trans $ le_of_lt hx') Ici_subset_Icc_union_Ioi\n\nlemma Ioi_subset_Ioc_union_Ici : Ioi a \u2286 Ioc a b \u222a Ici b :=\nsubset.trans Ioi_subset_Ioo_union_Ici (union_subset_union_left _ Ioo_subset_Ioc_self)\n\n@[simp] lemma Ioc_union_Ici_eq_Ioi (h : a < b) : Ioc a b \u222a Ici b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_le) Ioi_subset_Ioc_union_Ici\n\nlemma Ici_subset_Icc_union_Ici : Ici a \u2286 Icc a b \u222a Ici b :=\nsubset.trans Ici_subset_Ico_union_Ici (union_subset_union_left _ Ico_subset_Icc_self)\n\n@[simp] lemma Icc_union_Ici_eq_Ici (h : a \u2264 b) : Icc a b \u222a Ici b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans) Ici_subset_Icc_union_Ici\n\nlemma Icc_union_Ici' (h\u2081 : c \u2264 b) :\n  Icc a b \u222a Ici c = Ici (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Icc, mem_Ici, min_le_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\nend\n\nlemma Icc_union_Ici (h : c \u2264 max a b) :\n  Icc a b \u222a Ici c = Ici (min a c) :=\nbegin\n  cases le_or_lt a b with hab hab; simp [hab] at h,\n  { exact Icc_union_Ici' h },\n  { cases h,\n    { simp [*] },\n    { have hca : c \u2264 a := h.trans hab.le,\n      simp [*] } },\nend\n\n/-! #### An infinite and a finite interval -/\n\nlemma Iic_subset_Iio_union_Icc : Iic b \u2286 Iio a \u222a Icc a b :=\n\u03bb x hx, (lt_or_le x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iio_union_Icc_eq_Iic (h : a \u2264 b) : Iio a \u222a Icc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx, (le_of_lt hx).trans h) and.right)\n  Iic_subset_Iio_union_Icc\n\nlemma Iio_subset_Iio_union_Ico : Iio b \u2286 Iio a \u222a Ico a b :=\n\u03bb x hx, (lt_or_le x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iio_union_Ico_eq_Iio (h : a \u2264 b) : Iio a \u222a Ico a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_lt_of_le hx' h) and.right) Iio_subset_Iio_union_Ico\n\nlemma Iio_union_Ico' (h\u2081 : c \u2264 b) :\n  Iio b \u222a Ico c d = Iio (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iio, mem_Ico, lt_max_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\nend\n\nlemma Iio_union_Ico (h : min c d \u2264 b) :\n  Iio b \u222a Ico c d = Iio (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iio_union_Ico' h },\n  { simp [*] },\nend\n\nlemma Iic_subset_Iic_union_Ioc : Iic b \u2286 Iic a \u222a Ioc a b :=\n\u03bb x hx, (le_or_lt x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iic_union_Ioc_eq_Iic (h : a \u2264 b) : Iic a \u222a Ioc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', le_trans hx' h) and.right) Iic_subset_Iic_union_Ioc\n\nlemma Iic_union_Ioc' (h\u2081 : c < b) :\n  Iic b \u222a Ioc c d = Iic (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iic, mem_Ioc, le_max_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081.le,\n    tauto },\nend\n\nlemma Iic_union_Ioc (h : min c d < b) :\n  Iic b \u222a Ioc c d = Iic (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iic_union_Ioc' h },\n  { rw max_comm,\n    simp [*, max_eq_right_of_lt h] },\nend\n\nlemma Iio_subset_Iic_union_Ioo : Iio b \u2286 Iic a \u222a Ioo a b :=\n\u03bb x hx, (le_or_lt x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iic_union_Ioo_eq_Iio (h : a < b) : Iic a \u222a Ioo a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_le_of_lt hx' h) and.right) Iio_subset_Iic_union_Ioo\n\nlemma Iio_union_Ioo' (h\u2081 : c < b) :\n  Iio b \u222a Ioo c d = Iio (max b d) :=\nbegin\n  ext x,\n  cases lt_or_le x b with hba hba,\n  { simp [hba, h\u2081] },\n  { simp only [mem_Iio, mem_union_eq, mem_Ioo, lt_max_iff],\n    refine or_congr iff.rfl \u27e8and.right, _\u27e9,\n    exact \u03bb h\u2082, \u27e8h\u2081.trans_le hba, h\u2082\u27e9 },\nend\n\nlemma Iio_union_Ioo (h : min c d < b) :\n  Iio b \u222a Ioo c d = Iio (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iio_union_Ioo' h },\n  { rw max_comm,\n    simp [*, max_eq_right_of_lt h] },\nend\n\nlemma Iic_subset_Iic_union_Icc : Iic b \u2286 Iic a \u222a Icc a b :=\nsubset.trans Iic_subset_Iic_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)\n\n@[simp] lemma Iic_union_Icc_eq_Iic (h : a \u2264 b) : Iic a \u222a Icc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', le_trans hx' h) and.right) Iic_subset_Iic_union_Icc\n\nlemma Iic_union_Icc' (h\u2081 : c \u2264 b) :\n  Iic b \u222a Icc c d = Iic (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iic, mem_Icc, le_max_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\nend\n\nlemma Iic_union_Icc (h : min c d \u2264 b) :\n  Iic b \u222a Icc c d = Iic (max b d) :=\nbegin\n  cases le_or_lt c d with hcd hcd; simp [hcd] at h,\n  { exact Iic_union_Icc' h },\n  { cases h,\n    { have hdb : d \u2264 b := hcd.le.trans h,\n      simp [*] },\n    { simp [*] } },\nend\n\nlemma Iio_subset_Iic_union_Ico : Iio b \u2286 Iic a \u222a Ico a b :=\nsubset.trans Iio_subset_Iic_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Iic_union_Ico_eq_Iio (h : a < b) : Iic a \u222a Ico a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_le_of_lt hx' h) and.right) Iio_subset_Iic_union_Ico\n\n/-! #### Two finite intervals, `I?o` and `Ic?` -/\n\nlemma Ioo_subset_Ioo_union_Ico : Ioo a c \u2286 Ioo a b \u222a Ico b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioo_union_Ico_eq_Ioo (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioo a b \u222a Ico b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_le h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioo_subset_Ioo_union_Ico\n\nlemma Ico_subset_Ico_union_Ico : Ico a c \u2286 Ico a b \u222a Ico b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ico_union_Ico_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ico a b \u222a Ico b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_le h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Ico_subset_Ico_union_Ico\n\nlemma Ico_union_Ico' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Ico a b \u222a Ico c d = Ico (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ico, min_le_iff, lt_max_iff],\n  by_cases hc : c \u2264 x; by_cases hd : x < d,\n  { tauto },\n  { have hax : a \u2264 x := h\u2082.trans (le_of_not_gt hd),\n    tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\n  { tauto },\nend\n\nlemma Ico_union_Ico (h\u2081 : min a b \u2264 max c d) (h\u2082 : min c d \u2264 max a b) :\n  Ico a b \u222a Ico c d = Ico (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd; simp [hab, hcd] at h\u2081 h\u2082,\n  { exact Ico_union_Ico' h\u2082 h\u2081 },\n  all_goals { simp [*] },\nend\n\nlemma Icc_subset_Ico_union_Icc : Icc a c \u2286 Ico a b \u222a Icc b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ico_union_Icc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ico a b \u222a Icc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.le.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Icc_subset_Ico_union_Icc\n\nlemma Ioc_subset_Ioo_union_Icc : Ioc a c \u2286 Ioo a b \u222a Icc b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioo_union_Icc_eq_Ioc (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioo a b \u222a Icc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.le.trans h\u2082\u27e9)\n    (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioc_subset_Ioo_union_Icc\n\n/-! #### Two finite intervals, `I?c` and `Io?` -/\n\nlemma Ioo_subset_Ioc_union_Ioo : Ioo a c \u2286 Ioc a b \u222a Ioo b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioc_union_Ioo_eq_Ioo (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Ioc a b \u222a Ioo b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_lt hx.1, hx.2\u27e9))\n  Ioo_subset_Ioc_union_Ioo\n\nlemma Ico_subset_Icc_union_Ioo : Ico a c \u2286 Icc a b \u222a Ioo b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Icc_union_Ioo_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Icc a b \u222a Ioo b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9)\n    (\u03bb hx, \u27e8h\u2081.trans hx.1.le, hx.2\u27e9))\n  Ico_subset_Icc_union_Ioo\n\nlemma Icc_subset_Icc_union_Ioc : Icc a c \u2286 Icc a b \u222a Ioc b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Icc_union_Ioc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Icc a b \u222a Ioc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1.le, hx.2\u27e9))\n  Icc_subset_Icc_union_Ioc\n\nlemma Ioc_subset_Ioc_union_Ioc : Ioc a c \u2286 Ioc a b \u222a Ioc b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioc_union_Ioc_eq_Ioc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ioc a b \u222a Ioc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_lt hx.1, hx.2\u27e9))\n  Ioc_subset_Ioc_union_Ioc\n\nlemma Ioc_union_Ioc' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Ioc a b \u222a Ioc c d = Ioc (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioc, min_lt_iff, le_max_iff],\n  by_cases hc : c < x; by_cases hd : x \u2264 d,\n  { tauto },\n  { have hax : a < x := h\u2082.trans_lt (lt_of_not_ge hd),\n    tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081,\n    tauto },\n  { tauto },\nend\n\nlemma Ioc_union_Ioc (h\u2081 : min a b \u2264 max c d) (h\u2082 : min c d \u2264 max a b) :\n  Ioc a b \u222a Ioc c d = Ioc (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd; simp [hab, hcd] at h\u2081 h\u2082,\n  { exact Ioc_union_Ioc' h\u2082 h\u2081 },\n  all_goals { simp [*] },\nend\n\n/-! #### Two finite intervals with a common point -/\n\nlemma Ioo_subset_Ioc_union_Ico : Ioo a c \u2286 Ioc a b \u222a Ico b c :=\nsubset.trans Ioo_subset_Ioc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Ioc_union_Ico_eq_Ioo (h\u2081 : a < b) (h\u2082 : b < c) : Ioc a b \u222a Ico b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx', \u27e8hx'.1, hx'.2.trans_lt h\u2082\u27e9) (\u03bb hx', \u27e8h\u2081.trans_le hx'.1, hx'.2\u27e9))\n  Ioo_subset_Ioc_union_Ico\n\nlemma Ico_subset_Icc_union_Ico : Ico a c \u2286 Icc a b \u222a Ico b c :=\nsubset.trans Ico_subset_Icc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Icc_union_Ico_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Icc a b \u222a Ico b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Ico_subset_Icc_union_Ico\n\n\n\n@[simp] lemma Icc_union_Icc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Icc a b \u222a Icc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Icc_subset_Icc_union_Icc\n\nlemma Icc_union_Icc' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Icc a b \u222a Icc c d = Icc (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Icc, min_le_iff, le_max_iff],\n  by_cases hc : c \u2264 x; by_cases hd : x \u2264 d,\n  { tauto },\n  { have hax : a \u2264 x := h\u2082.trans (le_of_not_ge hd),\n    tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\n  { tauto }\nend\n\n/--\nWe cannot replace `<` by `\u2264` in the hypotheses.\nOtherwise for `b < a = d < c` the l.h.s. is `\u2205` and the r.h.s. is `{a}`.\n-/\nlemma Icc_union_Icc (h\u2081 : min a b < max c d) (h\u2082 : min c d < max a b) :\n  Icc a b \u222a Icc c d = Icc (min a c) (max b d) :=\nbegin\n  cases le_or_lt a b with hab hab; cases le_or_lt c d with hcd hcd;\n    simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, min_eq_left_of_lt,\n    min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt, hab, hcd] at h\u2081 h\u2082,\n  { exact Icc_union_Icc' h\u2082.le h\u2081.le },\n  all_goals { simp [*, min_eq_left_of_lt, max_eq_left_of_lt, min_eq_right_of_lt,\n    max_eq_right_of_lt] },\nend\n\nlemma Ioc_subset_Ioc_union_Icc : Ioc a c \u2286 Ioc a b \u222a Icc b c :=\nsubset.trans Ioc_subset_Ioc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)\n\n@[simp] lemma Ioc_union_Icc_eq_Ioc (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioc a b \u222a Icc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioc_subset_Ioc_union_Icc\n\nlemma Ioo_union_Ioo' (h\u2081 : c < b) (h\u2082 : a < d) :\n  Ioo a b \u222a Ioo c d = Ioo (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioo, min_lt_iff, lt_max_iff],\n  by_cases hc : c < x; by_cases hd : x < d,\n  { tauto },\n  { have hax : a < x := h\u2082.trans_le (le_of_not_lt hd),\n    tauto },\n  { have hxb : x < b := (le_of_not_lt hc).trans_lt h\u2081,\n    tauto },\n  { tauto }\nend\n\nlemma Ioo_union_Ioo (h\u2081 : min a b < max c d) (h\u2082 : min c d < max a b) :\n  Ioo a b \u222a Ioo c d = Ioo (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd;\n    simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, hab, hcd] at h\u2081 h\u2082,\n  { exact Ioo_union_Ioo' h\u2082 h\u2081 },\n  all_goals\n  { simp [*, min_eq_left_of_lt, min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt,\n      le_of_lt h\u2082, le_of_lt h\u2081] },\nend\n\nend linear_order\n\nsection lattice\n\nsection inf\n\nvariables {\u03b1 : Type u} [semilattice_inf \u03b1]\n\n@[simp] lemma Iic_inter_Iic {a b : \u03b1} : Iic a \u2229 Iic b = Iic (a \u2293 b) :=\nby { ext x, simp [Iic] }\n\n@[simp] lemma Iio_inter_Iio [is_total \u03b1 (\u2264)] {a b : \u03b1} : Iio a \u2229 Iio b = Iio (a \u2293 b) :=\nby { ext x, simp [Iio] }\n\n@[simp] lemma Ioc_inter_Iic (a b c : \u03b1) : Ioc a b \u2229 Iic c = Ioc a (b \u2293 c) :=\nby rw [\u2190 Ioi_inter_Iic, \u2190 Ioi_inter_Iic, inter_assoc, Iic_inter_Iic]\n\nend inf\n\nsection sup\n\nvariables {\u03b1 : Type u} [semilattice_sup \u03b1]\n\n@[simp] lemma Ici_inter_Ici {a b : \u03b1} : Ici a \u2229 Ici b = Ici (a \u2294 b) :=\nby { ext x, simp [Ici] }\n\n@[simp] lemma Ico_inter_Ici (a b c : \u03b1) : Ico a b \u2229 Ici c = Ico (a \u2294 c) b :=\nby rw [\u2190 Ici_inter_Iio, \u2190 Ici_inter_Iio, \u2190 Ici_inter_Ici, inter_right_comm]\n\n@[simp] lemma Ioi_inter_Ioi [is_total \u03b1 (\u2264)] {a b : \u03b1} : Ioi a \u2229 Ioi b = Ioi (a \u2294 b) :=\nby { ext x, simp [Ioi] }\n\n@[simp] lemma Ioc_inter_Ioi [is_total \u03b1 (\u2264)] {a b c : \u03b1} : Ioc a b \u2229 Ioi c = Ioc (a \u2294 c) b :=\nby rw [\u2190 Ioi_inter_Iic, inter_assoc, inter_comm, inter_assoc, Ioi_inter_Ioi, inter_comm,\n  Ioi_inter_Iic, sup_comm]\n\nend sup\n\nsection both\n\nvariables {\u03b1 : Type u} [lattice \u03b1] [ht : is_total \u03b1 (\u2264)] {a b c a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1}\n\nlemma Icc_inter_Icc : Icc a\u2081 b\u2081 \u2229 Icc a\u2082 b\u2082 = Icc (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_refl\n\n@[simp] lemma Icc_inter_Icc_eq_singleton (hab : a \u2264 b) (hbc : b \u2264 c) :\n  Icc a b \u2229 Icc b c = {b} :=\nby rw [Icc_inter_Icc, sup_of_le_right hab, inf_of_le_left hbc, Icc_self]\n\ninclude ht\n\nlemma Ico_inter_Ico : Ico a\u2081 b\u2081 \u2229 Ico a\u2082 b\u2082 = Ico (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ici_inter_Iio.symm, Ici_inter_Ici.symm, Iio_inter_Iio.symm]; ac_refl\n\nlemma Ioc_inter_Ioc : Ioc a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioc (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ioi_inter_Iic.symm, Ioi_inter_Ioi.symm, Iic_inter_Iic.symm]; ac_refl\n\nlemma Ioo_inter_Ioo : Ioo a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioo (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ioi_inter_Iio.symm, Ioi_inter_Ioi.symm, Iio_inter_Iio.symm]; ac_refl\n\nend both\n\nlemma Icc_bot_top {\u03b1} [partial_order \u03b1] [bounded_order \u03b1] : Icc (\u22a5 : \u03b1) \u22a4 = univ := by simp\n\nend lattice\n\nsection linear_order\nvariables {\u03b1 : Type u} [linear_order \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c d : \u03b1}\n\nlemma Ioc_inter_Ioo_of_left_lt (h : b\u2081 < b\u2082) : Ioc a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioc (max a\u2081 a\u2082) b\u2081 :=\next $ \u03bb x, by simp [and_assoc, @and.left_comm (x \u2264 _),\n  and_iff_left_iff_imp.2 (\u03bb h', lt_of_le_of_lt h' h)]\n\nlemma Ioc_inter_Ioo_of_right_le (h : b\u2082 \u2264 b\u2081) : Ioc a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioo (max a\u2081 a\u2082) b\u2082 :=\next $ \u03bb x, by simp [and_assoc, @and.left_comm (x \u2264 _),\n  and_iff_right_iff_imp.2 (\u03bb h', ((le_of_lt h').trans h))]\n\nlemma Ioo_inter_Ioc_of_left_le (h : b\u2081 \u2264 b\u2082) : Ioo a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioo (max a\u2081 a\u2082) b\u2081 :=\nby rw [inter_comm, Ioc_inter_Ioo_of_right_le h, max_comm]\n\nlemma Ioo_inter_Ioc_of_right_lt (h : b\u2082 < b\u2081) : Ioo a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioc (max a\u2081 a\u2082) b\u2082 :=\nby rw [inter_comm, Ioc_inter_Ioo_of_left_lt h, max_comm]\n\n@[simp] lemma Ico_diff_Iio : Ico a b \\ Iio c = Ico (max a c) b :=\nby rw [diff_eq, compl_Iio, Ico_inter_Ici, sup_eq_max]\n\n@[simp] lemma Ioc_diff_Ioi : Ioc a b \\ Ioi c = Ioc a (min b c) :=\next $ by simp [iff_def] {contextual:=tt}\n\n@[simp] lemma Ico_inter_Iio : Ico a b \u2229 Iio c = Ico a (min b c) :=\next $ by simp [iff_def] {contextual:=tt}\n\n@[simp] lemma Ioc_diff_Iic : Ioc a b \\ Iic c = Ioc (max a c) b :=\nby rw [diff_eq, compl_Iic, Ioc_inter_Ioi, sup_eq_max]\n\n@[simp] lemma Ioc_union_Ioc_right : Ioc a b \u222a Ioc a c = Ioc a (max b c) :=\nby rw [Ioc_union_Ioc, min_self]; exact (min_le_left _ _).trans (le_max_left _ _)\n\n@[simp] lemma Ioc_union_Ioc_left : Ioc a c \u222a Ioc b c = Ioc (min a b) c :=\nby rw [Ioc_union_Ioc, max_self]; exact (min_le_right _ _).trans (le_max_right _ _)\n\n@[simp] lemma Ioc_union_Ioc_symm : Ioc a b \u222a Ioc b a = Ioc (min a b) (max a b) :=\nby { rw max_comm, apply Ioc_union_Ioc; rw max_comm; exact min_le_max }\n\n@[simp] lemma Ioc_union_Ioc_union_Ioc_cycle :\n  Ioc a b \u222a Ioc b c \u222a Ioc c a = Ioc (min a (min b c)) (max a (max b c)) :=\nbegin\n  rw [Ioc_union_Ioc, Ioc_union_Ioc],\n  ac_refl,\n  all_goals { solve_by_elim [min_le_of_left_le, min_le_of_right_le, le_max_of_le_left,\n    le_max_of_le_right, le_refl] { max_depth := 5 }}\nend\n\nend linear_order\n\n/-!\n### Closed intervals in `\u03b1 \u00d7 \u03b2`\n-/\n\nsection prod\n\nvariables {\u03b1 \u03b2 : Type*} [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma Iic_prod_Iic (a : \u03b1) (b : \u03b2) : (Iic a).prod (Iic b) = Iic (a, b) := rfl\n\n@[simp] lemma Ici_prod_Ici (a : \u03b1) (b : \u03b2) : (Ici a).prod (Ici b) = Ici (a, b) := rfl\n\nlemma Ici_prod_eq (a : \u03b1 \u00d7 \u03b2) : Ici a = (Ici a.1).prod (Ici a.2) := rfl\n\nlemma Iic_prod_eq (a : \u03b1 \u00d7 \u03b2) : Iic a = (Iic a.1).prod (Iic a.2) := rfl\n\n@[simp] lemma Icc_prod_Icc (a\u2081 a\u2082 : \u03b1) (b\u2081 b\u2082 : \u03b2) :\n  (Icc a\u2081 a\u2082).prod (Icc b\u2081 b\u2082) = Icc (a\u2081, b\u2081) (a\u2082, b\u2082) :=\nby { ext \u27e8x, y\u27e9, simp [and.assoc, and_comm, and.left_comm] }\n\nlemma Icc_prod_eq (a b : \u03b1 \u00d7 \u03b2) :\n  Icc a b = (Icc a.1 b.1).prod (Icc a.2 b.2) :=\nby simp\n\nend prod\n\n/-! ### Lemmas about membership of arithmetic operations -/\n\nsection ordered_comm_group\n\nvariables {\u03b1 : Type*} [ordered_comm_group \u03b1] {a b c d : \u03b1}\n\n/-! `inv_mem_Ixx_iff`, `sub_mem_Ixx_iff` -/\n@[to_additive] lemma inv_mem_Icc_iff : a\u207b\u00b9 \u2208 set.Icc c d \u2194 a \u2208 set.Icc (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_le' le_inv'\n@[to_additive] lemma inv_mem_Ico_iff : a\u207b\u00b9 \u2208 set.Ico c d \u2194 a \u2208 set.Ioc (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_lt' le_inv'\n@[to_additive] lemma inv_mem_Ioc_iff : a\u207b\u00b9 \u2208 set.Ioc c d \u2194 a \u2208 set.Ico (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_le' lt_inv'\n@[to_additive] lemma inv_mem_Ioo_iff : a\u207b\u00b9 \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_lt' lt_inv'\n\nend ordered_comm_group\n\nsection ordered_add_comm_group\n\nvariables {\u03b1 : Type*} [ordered_add_comm_group \u03b1] {a b c d : \u03b1}\n\n/-! `add_mem_Ixx_iff_left` -/\nlemma add_mem_Icc_iff_left : a + b \u2208 set.Icc c d \u2194 a \u2208 set.Icc (c - b) (d - b) :=\n(and_congr sub_le_iff_le_add le_sub_iff_add_le).symm\nlemma add_mem_Ico_iff_left : a + b \u2208 set.Ico c d \u2194 a \u2208 set.Ico (c - b) (d - b) :=\n(and_congr sub_le_iff_le_add lt_sub_iff_add_lt).symm\nlemma add_mem_Ioc_iff_left : a + b \u2208 set.Ioc c d \u2194 a \u2208 set.Ioc (c - b) (d - b) :=\n(and_congr sub_lt_iff_lt_add le_sub_iff_add_le).symm\nlemma add_mem_Ioo_iff_left : a + b \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (c - b) (d - b) :=\n(and_congr sub_lt_iff_lt_add lt_sub_iff_add_lt).symm\n\n/-! `add_mem_Ixx_iff_right` -/\nlemma add_mem_Icc_iff_right : a + b \u2208 set.Icc c d \u2194 b \u2208 set.Icc (c - a) (d - a) :=\n(and_congr sub_le_iff_le_add' le_sub_iff_add_le').symm\nlemma add_mem_Ico_iff_right : a + b \u2208 set.Ico c d \u2194 b \u2208 set.Ico (c - a) (d - a) :=\n(and_congr sub_le_iff_le_add' lt_sub_iff_add_lt').symm\nlemma add_mem_Ioc_iff_right : a + b \u2208 set.Ioc c d \u2194 b \u2208 set.Ioc (c - a) (d - a) :=\n(and_congr sub_lt_iff_lt_add' le_sub_iff_add_le').symm\nlemma add_mem_Ioo_iff_right : a + b \u2208 set.Ioo c d \u2194 b \u2208 set.Ioo (c - a) (d - a) :=\n(and_congr sub_lt_iff_lt_add' lt_sub_iff_add_lt').symm\n\n/-! `sub_mem_Ixx_iff_left` -/\nlemma sub_mem_Icc_iff_left : a - b \u2208 set.Icc c d \u2194 a \u2208 set.Icc (c + b) (d + b) :=\nand_congr le_sub_iff_add_le sub_le_iff_le_add\nlemma sub_mem_Ico_iff_left : a - b \u2208 set.Ico c d \u2194 a \u2208 set.Ico (c + b) (d + b) :=\nand_congr le_sub_iff_add_le sub_lt_iff_lt_add\nlemma sub_mem_Ioc_iff_left : a - b \u2208 set.Ioc c d \u2194 a \u2208 set.Ioc (c + b) (d + b) :=\nand_congr lt_sub_iff_add_lt sub_le_iff_le_add\nlemma sub_mem_Ioo_iff_left : a - b \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (c + b) (d + b) :=\nand_congr lt_sub_iff_add_lt sub_lt_iff_lt_add\n\n/-! `sub_mem_Ixx_iff_right` -/\nlemma sub_mem_Icc_iff_right : a - b \u2208 set.Icc c d \u2194 b \u2208 set.Icc (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_le le_sub\nlemma sub_mem_Ico_iff_right : a - b \u2208 set.Ico c d \u2194 b \u2208 set.Ioc (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_lt le_sub\nlemma sub_mem_Ioc_iff_right : a - b \u2208 set.Ioc c d \u2194 b \u2208 set.Ico (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_le lt_sub\nlemma sub_mem_Ioo_iff_right : a - b \u2208 set.Ioo c d \u2194 b \u2208 set.Ioo (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_lt lt_sub\n\n-- I think that symmetric intervals deserve attention and API: they arise all the time,\n-- for instance when considering metric balls in `\u211d`.\nlemma mem_Icc_iff_abs_le {R : Type*} [linear_ordered_add_comm_group R] {x y z : R} :\n  |x - y| \u2264 z \u2194 y \u2208 Icc (x - z) (x + z) :=\nabs_le.trans $ (and_comm _ _).trans $ and_congr sub_le neg_le_sub_iff_le_add\n\nend ordered_add_comm_group\n\nsection linear_ordered_add_comm_group\n\nvariables {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1]\n\n/-- If we remove a smaller interval from a larger, the result is nonempty -/\nlemma nonempty_Ico_sdiff {x dx y dy : \u03b1} (h : dy < dx) (hx : 0 < dx) :\n  nonempty \u21a5(Ico x (x + dx) \\ Ico y (y + dy)) :=\nbegin\n  cases lt_or_le x y with h' h',\n  { use x, simp [*, not_le.2 h'] },\n  { use max x (x + dy), simp [*, le_refl] }\nend\n\nend linear_ordered_add_comm_group\n\nend set\n\nopen set\n\nnamespace order_iso\nvariables {\u03b1 \u03b2 : Type*}\n\nsection preorder\nvariables [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma preimage_Iic (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Iic b) = Iic (e.symm b) :=\nby { ext x, simp [\u2190 e.le_iff_le] }\n\n@[simp] lemma preimage_Ici (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Ici b) = Ici (e.symm b) :=\nby { ext x, simp [\u2190 e.le_iff_le] }\n\n@[simp] lemma preimage_Iio (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Iio b) = Iio (e.symm b) :=\nby { ext x, simp [\u2190 e.lt_iff_lt] }\n\n@[simp] lemma preimage_Ioi (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Ioi b) = Ioi (e.symm b) :=\nby { ext x, simp [\u2190 e.lt_iff_lt] }\n\n@[simp] lemma preimage_Icc (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Icc a b) = Icc (e.symm a) (e.symm b) :=\nby simp [\u2190 Ici_inter_Iic]\n\n@[simp] lemma preimage_Ico (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Ico a b) = Ico (e.symm a) (e.symm b) :=\nby simp [\u2190 Ici_inter_Iio]\n\n@[simp] lemma preimage_Ioc (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Ioc a b) = Ioc (e.symm a) (e.symm b) :=\nby simp [\u2190 Ioi_inter_Iic]\n\n@[simp] lemma preimage_Ioo (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Ioo a b) = Ioo (e.symm a) (e.symm b) :=\nby simp [\u2190 Ioi_inter_Iio]\n\n@[simp] lemma image_Iic (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Iic a) = Iic (e a) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Iic, e.symm_symm]\n\n@[simp] lemma image_Ici (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Ici a) = Ici (e a) :=\ne.dual.image_Iic a\n\n@[simp] lemma image_Iio (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Iio a) = Iio (e a) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Iio, e.symm_symm]\n\n@[simp] lemma image_Ioi (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Ioi a) = Ioi (e a) :=\ne.dual.image_Iio a\n\n@[simp] lemma image_Ioo (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Ioo a b) = Ioo (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Ioo, e.symm_symm]\n\n@[simp] lemma image_Ioc (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Ioc a b) = Ioc (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Ioc, e.symm_symm]\n\n@[simp] lemma image_Ico (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Ico a b) = Ico (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Ico, e.symm_symm]\n\n@[simp] lemma image_Icc (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Icc a b) = Icc (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Icc, e.symm_symm]\n\nend preorder\n\n/-- Order isomorphism between `Iic (\u22a4 : \u03b1)` and `\u03b1` when `\u03b1` has a top element -/\ndef Iic_top [preorder \u03b1] [order_top \u03b1] : set.Iic (\u22a4 : \u03b1) \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb x y, by refl,\n  .. (@equiv.subtype_univ_equiv \u03b1 (set.Iic (\u22a4 : \u03b1)) (\u03bb x, le_top)), }\n\n/-- Order isomorphism between `Ici (\u22a5 : \u03b1)` and `\u03b1` when `\u03b1` has a bottom element -/\ndef Ici_bot [preorder \u03b1] [order_bot \u03b1] : set.Ici (\u22a5 : \u03b1) \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb x y, by refl,\n  .. (@equiv.subtype_univ_equiv \u03b1 (set.Ici (\u22a5 : \u03b1)) (\u03bb x, bot_le)) }\n\nend order_iso\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/set/intervals/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8459424314825852, "lm_q1q2_score": 0.7085782684405164}}
{"text": "\n\nimport data.finset\n\nnoncomputable theory \nopen_locale classical\nopen finset\nuniverse u\n\n\n-- Coercion stuff\n\ninstance coe_subtype_finset {\u03b1 : Type*} {Y: set \u03b1} :\n    has_coe (finset Y) (finset \u03b1) := \u27e8\u03bb X, X.image subtype.val\u27e9 \n\nlemma union_lemma {\u03b1 : Type*} {Y: set \u03b1} (S T : finset Y) :\n    (((S \u222a T) : finset Y) : finset \u03b1) = S \u222a T := by apply image_union\n\n-- Structure \n\nstructure subadditive_fn_on (\u03b3 : Type u) := \n(f : finset \u03b3 \u2192 \u2115 )\n(hf : \u2200 (S T : finset \u03b3), f (S \u222a T) \u2264 f S + f T) \n\n\ndef restr {\u03b3 : Type u} (F : subadditive_fn_on \u03b3) (Y: set \u03b3) : subadditive_fn_on (\u21a5Y) :=\n{\n    f := \u03bb S, F.f (S: finset \u03b3), \n    hf := \u03bb S T,\n    begin\n        convert F.hf S T, \n        rw \u2190 union_lemma, \n        congr, \n    end, \n} \n\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old/matroid_bad.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.7085175660292109}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\n\nimport algebra.group.defs\nimport order.basic\nimport order.monotone.basic\n\n/-!\n\n# Covariants and contravariants\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains general lemmas and instances to work with the interactions between a relation and\nan action on a Type.\n\nThe intended application is the splitting of the ordering from the algebraic assumptions on the\noperations in the `ordered_[...]` hierarchy.\n\nThe strategy is to introduce two more flexible typeclasses, `covariant_class` and\n`contravariant_class`:\n\n* `covariant_class` models the implication `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone),\n* `contravariant_class` models the implication `a * b < a * c \u2192 b < c`.\n\nSince `co(ntra)variant_class` takes as input the operation (typically `(+)` or `(*)`) and the order\nrelation (typically `(\u2264)` or `(<)`), these are the only two typeclasses that I have used.\n\nThe general approach is to formulate the lemma that you are interested in and prove it, with the\n`ordered_[...]` typeclass of your liking.  After that, you convert the single typeclass,\nsay `[ordered_cancel_monoid M]`, into three typeclasses, e.g.\n`[left_cancel_semigroup M] [partial_order M] [covariant_class M M (function.swap (*)) (\u2264)]`\nand have a go at seeing if the proof still works!\n\nNote that it is possible to combine several co(ntra)variant_class assumptions together.\nIndeed, the usual ordered typeclasses arise from assuming the pair\n`[covariant_class M M (*) (\u2264)] [contravariant_class M M (*) (<)]`\non top of order/algebraic assumptions.\n\nA formal remark is that normally `covariant_class` uses the `(\u2264)`-relation, while\n`contravariant_class` uses the `(<)`-relation. This need not be the case in general, but seems to be\nthe most common usage. In the opposite direction, the implication\n```lean\n[semigroup \u03b1] [partial_order \u03b1] [contravariant_class \u03b1 \u03b1 (*) (\u2264)] => left_cancel_semigroup \u03b1\n```\nholds -- note the `co*ntra*` assumption on the `(\u2264)`-relation.\n\n# Formalization notes\n\nWe stick to the convention of using `function.swap (*)` (or `function.swap (+)`), for the\ntypeclass assumptions, since `function.swap` is slightly better behaved than `flip`.\nHowever, sometimes as a **non-typeclass** assumption, we prefer `flip (*)` (or `flip (+)`),\nas it is easier to use. -/\n\n-- TODO: convert `has_exists_mul_of_le`, `has_exists_add_of_le`?\n-- TODO: relationship with `con/add_con`\n-- TODO: include equivalence of `left_cancel_semigroup` with\n-- `semigroup partial_order contravariant_class \u03b1 \u03b1 (*) (\u2264)`?\n-- TODO : use \u21d2, as per Eric's suggestion?  See\n-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff/near/236148738\n-- for a discussion.\n\nopen function\n\nsection variants\nvariables {M N : Type*} (\u03bc : M \u2192 N \u2192 N) (r : N \u2192 N \u2192 Prop)\n\nvariables (M N)\n/-- `covariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `covariant_class` doc-string for its meaning. -/\ndef covariant     : Prop := \u2200 (m) {n\u2081 n\u2082}, r n\u2081 n\u2082 \u2192 r (\u03bc m n\u2081) (\u03bc m n\u2082)\n\n/-- `contravariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `contravariant_class` doc-string for its meaning. -/\ndef contravariant : Prop := \u2200 (m) {n\u2081 n\u2082}, r (\u03bc m n\u2081) (\u03bc m n\u2082) \u2192 r n\u2081 n\u2082\n\n/--  Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`covariant_class` says that \"the action `\u03bc` preserves the relation `r`.\"\n\nMore precisely, the `covariant_class` is a class taking two Types `M N`, together with an \"action\"\n`\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the assertion that\nfor all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the pair\n`(n\u2081, n\u2082)`, then, the relation `r` also holds for the pair `(\u03bc m n\u2081, \u03bc m n\u2082)`,\nobtained from `(n\u2081, n\u2082)` by acting upon it by `m`.\n\nIf `m : M` and `h : r n\u2081 n\u2082`, then `covariant_class.elim m h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`.\n-/\n@[protect_proj] class covariant_class : Prop :=\n(elim :  covariant M N \u03bc r)\n\n/--  Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`contravariant_class` says that \"if the result of the action `\u03bc` on a pair satisfies the\nrelation `r`, then the initial pair satisfied the relation `r`.\"\n\nMore precisely, the `contravariant_class` is a class taking two Types `M N`, together with an\n\"action\" `\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the\nassertion that for all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the\npair `(\u03bc m n\u2081, \u03bc m n\u2082)` obtained from `(n\u2081, n\u2082)` by acting upon it by `m`, then, the relation\n`r` also holds for the pair `(n\u2081, n\u2082)`.\n\nIf `m : M` and `h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`, then `contravariant_class.elim m h : r n\u2081 n\u2082`.\n-/\n@[protect_proj] class contravariant_class : Prop :=\n(elim : contravariant M N \u03bc r)\n\nlemma rel_iff_cov [covariant_class M N \u03bc r] [contravariant_class M N \u03bc r] (m : M) {a b : N} :\n  r (\u03bc m a) (\u03bc m b) \u2194 r a b :=\n\u27e8contravariant_class.elim _, covariant_class.elim _\u27e9\n\nsection flip\n\nvariables {M N \u03bc r}\n\nlemma covariant.flip (h : covariant M N \u03bc r) : covariant M N \u03bc (flip r) :=\n\u03bb a b c hbc, h a hbc\n\nlemma contravariant.flip (h : contravariant M N \u03bc r) : contravariant M N \u03bc (flip r) :=\n\u03bb a b c hbc, h a hbc\n\nend flip\n\nsection covariant\nvariables {M N \u03bc r} [covariant_class M N \u03bc r]\n\nlemma act_rel_act_of_rel (m : M) {a b : N} (ab : r a b) :\n  r (\u03bc m a) (\u03bc m b) :=\ncovariant_class.elim _ ab\n\n@[to_additive]\nlemma group.covariant_iff_contravariant [group N] :\n  covariant N N (*) r \u2194 contravariant N N (*) r :=\nbegin\n  refine \u27e8\u03bb h a b c bc, _, \u03bb h a b c bc, _\u27e9,\n  { rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c],\n    exact h a\u207b\u00b9 bc },\n  { rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c] at bc,\n    exact h a\u207b\u00b9 bc }\nend\n\n@[priority 100, to_additive]\ninstance group.covconv [group N] [covariant_class N N (*) r] :\n  contravariant_class N N (*) r :=\n\u27e8group.covariant_iff_contravariant.mp covariant_class.elim\u27e9\n\n@[to_additive]\nlemma group.covariant_swap_iff_contravariant_swap [group N] :\n  covariant N N (swap (*)) r \u2194 contravariant N N (swap (*)) r :=\nbegin\n  refine \u27e8\u03bb h a b c bc, _, \u03bb h a b c bc, _\u27e9,\n  { rw [\u2190 mul_inv_cancel_right b a, \u2190 mul_inv_cancel_right c a],\n    exact h a\u207b\u00b9 bc },\n  { rw [\u2190 mul_inv_cancel_right b a, \u2190 mul_inv_cancel_right c a] at bc,\n    exact h a\u207b\u00b9 bc }\nend\n\n@[priority 100, to_additive]\ninstance group.covconv_swap [group N] [covariant_class N N (swap (*)) r] :\n  contravariant_class N N (swap (*)) r :=\n\u27e8group.covariant_swap_iff_contravariant_swap.mp covariant_class.elim\u27e9\n\nsection is_trans\nvariables [is_trans N r] (m n : M) {a b c d : N}\n\n/-  Lemmas with 3 elements. -/\nlemma act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (\u03bc m b) c) :\n  r (\u03bc m a) c :=\ntrans (act_rel_act_of_rel m ab) rl\n\nlemma rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (\u03bc m a)) :\n  r c (\u03bc m b) :=\ntrans rr (act_rel_act_of_rel _ ab)\n\nend is_trans\n\nend covariant\n\n/-  Lemma with 4 elements. -/\nsection M_eq_N\nvariables {M N \u03bc r} {mu : N \u2192 N \u2192 N} [is_trans N r]\n  [covariant_class N N mu r] [covariant_class N N (swap mu) r] {a b c d : N}\n\nlemma act_rel_act_of_rel_of_rel (ab : r a b) (cd : r c d) :\n  r (mu a c) (mu b d) :=\ntrans (act_rel_act_of_rel c ab : _) (act_rel_act_of_rel b cd)\n\nend M_eq_N\n\nsection contravariant\nvariables {M N \u03bc r} [contravariant_class M N \u03bc r]\n\nlemma rel_of_act_rel_act (m : M) {a b : N} (ab : r (\u03bc m a) (\u03bc m b)) :\n  r a b :=\ncontravariant_class.elim _ ab\n\nsection is_trans\nvariables [is_trans N r] (m n : M) {a b c d : N}\n\n/-  Lemmas with 3 elements. -/\nlemma act_rel_of_act_rel_of_rel_act_rel (ab : r (\u03bc m a) b) (rl : r (\u03bc m b) (\u03bc m c)) :\n  r (\u03bc m a) c :=\ntrans ab (rel_of_act_rel_act m rl)\n\nlemma rel_act_of_act_rel_act_of_rel_act (ab : r (\u03bc m a) (\u03bc m b)) (rr : r b (\u03bc m c)) :\n  r a (\u03bc m c) :=\ntrans (rel_of_act_rel_act m ab) rr\n\nend is_trans\n\nend contravariant\n\nsection monotone\n\nvariables {\u03b1 : Type*} {M N \u03bc} [preorder \u03b1] [preorder N]\nvariable {f : N \u2192 \u03b1}\n\n/-- The partial application of a constant to a covariant operator is monotone. -/\nlemma covariant.monotone_of_const [covariant_class M N \u03bc (\u2264)] (m : M) : monotone (\u03bc m) :=\n\u03bb a b ha, covariant_class.elim m ha\n\n/-- A monotone function remains monotone when composed with the partial application\nof a covariant operator. E.g., `\u2200 (m : \u2115), monotone f \u2192 monotone (\u03bb n, f (m + n))`. -/\nlemma monotone.covariant_of_const [covariant_class M N \u03bc (\u2264)] (hf : monotone f) (m : M) :\n  monotone (\u03bb n, f (\u03bc m n)) :=\nhf.comp $ covariant.monotone_of_const m\n\n/-- Same as `monotone.covariant_of_const`, but with the constant on the other side of\nthe operator.  E.g., `\u2200 (m : \u2115), monotone f \u2192 monotone (\u03bb n, f (n + m))`. -/\nlemma monotone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [covariant_class N N (swap \u03bc) (\u2264)]\n  (hf : monotone f) (m : N) :\n  monotone (\u03bb n, f (\u03bc n m)) :=\nhf.comp $ covariant.monotone_of_const m\n\n/-- Dual of `monotone.covariant_of_const` -/\nlemma antitone.covariant_of_const [covariant_class M N \u03bc (\u2264)] (hf : antitone f) (m : M) :\n  antitone (\u03bb n, f (\u03bc m n)) :=\nhf.comp_monotone $ covariant.monotone_of_const m\n\n/-- Dual of `monotone.covariant_of_const'` -/\nlemma antitone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [covariant_class N N (swap \u03bc) (\u2264)]\n  (hf : antitone f) (m : N) :\n  antitone (\u03bb n, f (\u03bc n m)) :=\nhf.comp_monotone $ covariant.monotone_of_const m\n\nend monotone\n\nlemma covariant_le_of_covariant_lt [partial_order N] :\n  covariant M N \u03bc (<) \u2192 covariant M N \u03bc (\u2264) :=\nbegin\n  refine \u03bb h a b c bc, _,\n  rcases le_iff_eq_or_lt.mp bc with rfl | bc,\n  { exact rfl.le },\n  { exact (h _ bc).le }\nend\n\nlemma contravariant_lt_of_contravariant_le [partial_order N] :\n  contravariant M N \u03bc (\u2264) \u2192 contravariant M N \u03bc (<) :=\nbegin\n  refine \u03bb h a b c bc, lt_iff_le_and_ne.mpr \u27e8h a bc.le, _\u27e9,\n  rintro rfl,\n  exact lt_irrefl _ bc,\nend\n\nlemma covariant_le_iff_contravariant_lt [linear_order N] :\n  covariant M N \u03bc (\u2264) \u2194 contravariant M N \u03bc (<) :=\n\u27e8 \u03bb h a b c bc, not_le.mp (\u03bb k, not_le.mpr bc (h _ k)),\n  \u03bb h a b c bc, not_lt.mp (\u03bb k, not_lt.mpr bc (h _ k))\u27e9\n\nlemma covariant_lt_iff_contravariant_le [linear_order N] :\n  covariant M N \u03bc (<) \u2194 contravariant M N \u03bc (\u2264) :=\n\u27e8 \u03bb h a b c bc, not_lt.mp (\u03bb k, not_lt.mpr bc (h _ k)),\n  \u03bb h a b c bc, not_le.mp (\u03bb k, not_le.mpr bc (h _ k))\u27e9\n\n@[to_additive]\nlemma covariant_flip_mul_iff [comm_semigroup N] :\n  covariant N N (flip (*)) (r) \u2194 covariant N N (*) (r) :=\nby rw is_symm_op.flip_eq\n\n@[to_additive]\nlemma contravariant_flip_mul_iff [comm_semigroup N] :\n  contravariant N N (flip (*)) (r) \u2194 contravariant N N (*) (r) :=\nby rw is_symm_op.flip_eq\n\n@[to_additive]\ninstance contravariant_mul_lt_of_covariant_mul_le [has_mul N] [linear_order N]\n  [covariant_class N N (*) (\u2264)] : contravariant_class N N (*) (<) :=\n{ elim := (covariant_le_iff_contravariant_lt N N (*)).mp covariant_class.elim }\n\n@[to_additive]\ninstance covariant_mul_lt_of_contravariant_mul_le [has_mul N] [linear_order N]\n  [contravariant_class N N (*) (\u2264)] : covariant_class N N (*) (<) :=\n{ elim := (covariant_lt_iff_contravariant_le N N (*)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance covariant_swap_mul_le_of_covariant_mul_le [comm_semigroup N] [has_le N]\n  [covariant_class N N (*) (\u2264)] : covariant_class N N (swap (*)) (\u2264) :=\n{ elim := (covariant_flip_mul_iff N (\u2264)).mpr covariant_class.elim }\n\n@[to_additive]\ninstance contravariant_swap_mul_le_of_contravariant_mul_le [comm_semigroup N] [has_le N]\n  [contravariant_class N N (*) (\u2264)] : contravariant_class N N (swap (*)) (\u2264) :=\n{ elim := (contravariant_flip_mul_iff N (\u2264)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance contravariant_swap_mul_lt_of_contravariant_mul_lt [comm_semigroup N] [has_lt N]\n  [contravariant_class N N (*) (<)] : contravariant_class N N (swap (*)) (<) :=\n{ elim := (contravariant_flip_mul_iff N (<)).mpr contravariant_class.elim }\n\n@[to_additive]\ninstance covariant_swap_mul_lt_of_covariant_mul_lt [comm_semigroup N] [has_lt N]\n  [covariant_class N N (*) (<)] : covariant_class N N (swap (*)) (<) :=\n{ elim := (covariant_flip_mul_iff N (<)).mpr covariant_class.elim }\n\n@[to_additive]\ninstance left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le\n  [left_cancel_semigroup N] [partial_order N] [covariant_class N N (*) (\u2264)] :\n  covariant_class N N (*) (<) :=\n{ elim := \u03bb a b c bc, by { cases lt_iff_le_and_ne.mp bc with bc cb,\n    exact lt_iff_le_and_ne.mpr \u27e8covariant_class.elim a bc, (mul_ne_mul_right a).mpr cb\u27e9 } }\n\n@[to_additive]\ninstance right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le\n  [right_cancel_semigroup N] [partial_order N] [covariant_class N N (swap (*)) (\u2264)] :\n  covariant_class N N (swap (*)) (<) :=\n{ elim := \u03bb a b c bc, by { cases lt_iff_le_and_ne.mp bc with bc cb,\n    exact lt_iff_le_and_ne.mpr \u27e8covariant_class.elim a bc, (mul_ne_mul_left a).mpr cb\u27e9 } }\n\n@[to_additive]\ninstance left_cancel_semigroup.contravariant_mul_le_of_contravariant_mul_lt\n  [left_cancel_semigroup N] [partial_order N] [contravariant_class N N (*) (<)] :\n  contravariant_class N N (*) (\u2264) :=\n{ elim := \u03bb a b c bc, by { cases le_iff_eq_or_lt.mp bc with h h,\n    { exact ((mul_right_inj a).mp h).le },\n    { exact (contravariant_class.elim _ h).le } } }\n\n@[to_additive]\ninstance right_cancel_semigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt\n  [right_cancel_semigroup N] [partial_order N] [contravariant_class N N (swap (*)) (<)] :\n  contravariant_class N N (swap (*)) (\u2264) :=\n{ elim := \u03bb a b c bc, by { cases le_iff_eq_or_lt.mp bc with h h,\n    { exact ((mul_left_inj a).mp h).le },\n    { exact (contravariant_class.elim _ h).le } } }\n\nend variants\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/covariant_and_contravariant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7085138967972398}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Scott Morrison, Simon Hudon\n\n! This file was ported from Lean 3 source module category_theory.endomorphism\n! leanprover-community/mathlib commit 32253a1a1071173b33dc7d6a218cf722c6feb514\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Hom.Equiv.Basic\nimport Mathlib.CategoryTheory.Groupoid\nimport Mathlib.CategoryTheory.Opposites\nimport Mathlib.GroupTheory.GroupAction.Defs\n\n/-!\n# Endomorphisms\n\nDefinition and basic properties of endomorphisms and automorphisms of an object in a category.\n\nFor each `X : C`, we provide `CategoryTheory.End X := X \u27f6 X` with a monoid structure,\nand `CategoryTheory.Aut X := X \u2245 X ` with a group structure.\n-/\n\n\nuniverse v v' u u'\n\nnamespace CategoryTheory\n\n/-- Endomorphisms of an object in a category. Arguments order in multiplication agrees with\n`Function.comp`, not with `CategoryTheory.CategoryStruct.comp`. -/\ndef End {C : Type u} [CategoryStruct.{v} C] (X : C) := X \u27f6 X\n#align category_theory.End CategoryTheory.End\n\nnamespace End\n\nsection Struct\n\nvariable {C : Type u} [CategoryStruct.{v} C] (X : C)\n\nprotected instance one : One (End X) := \u27e8\ud835\udfd9 X\u27e9\n#align category_theory.End.has_one CategoryTheory.End.one\n\nprotected instance inhabited : Inhabited (End X) := \u27e8\ud835\udfd9 X\u27e9\n#align category_theory.End.inhabited CategoryTheory.End.inhabited\n\n/-- Multiplication of endomorphisms agrees with `Function.comp`, not with\n`CategoryTheory.CategoryStruct.comp`. -/\nprotected instance mul : Mul (End X) := \u27e8fun x y => y \u226b x\u27e9\n#align category_theory.End.has_mul CategoryTheory.End.mul\n\nvariable {X}\n\n/-- Assist the typechecker by expressing a morphism `X \u27f6 X` as a term of `CategoryTheory.End X`. -/\ndef of (f : X \u27f6 X) : End X := f\n#align category_theory.End.of CategoryTheory.End.of\n\n/-- Assist the typechecker by expressing an endomorphism `f : CategoryTheory.End X` as a term of\n`X \u27f6 X`. -/\ndef asHom (f : End X) : X \u27f6 X := f\n#align category_theory.End.as_hom CategoryTheory.End.asHom\n\n@[simp] -- porting note: todo: use `of`/`asHom`?\ntheorem one_def : (1 : End X) = \ud835\udfd9 X := rfl\n#align category_theory.End.one_def CategoryTheory.End.one_def\n\n@[simp] -- porting note: todo: use `of`/`asHom`?\ntheorem mul_def (xs ys : End X) : xs * ys = ys \u226b xs := rfl\n#align category_theory.End.mul_def CategoryTheory.End.mul_def\n\nend Struct\n\n/-- Endomorphisms of an object form a monoid -/\ninstance monoid {C : Type u} [Category.{v} C] {X : C} : Monoid (End X) where\n  mul_one := Category.id_comp\n  one_mul := Category.comp_id\n  mul_assoc := fun x y z => (Category.assoc z y x).symm\n#align category_theory.End.monoid CategoryTheory.End.monoid\n\nsection MulAction\n\nvariable {C : Type u} [Category.{v} C]\n\nopen Opposite\n\ninstance mulActionRight {X Y : C} : MulAction (End Y) (X \u27f6 Y) where\n  smul r f := f \u226b r\n  one_smul := Category.comp_id\n  mul_smul _ _ _ := Eq.symm <| Category.assoc _ _ _\n#align category_theory.End.mul_action_right CategoryTheory.End.mulActionRight\n\ninstance mulActionLeft {X : C\u1d52\u1d56} {Y : C} : MulAction (End X) (unop X \u27f6 Y) where\n  smul r f := r.unop \u226b f\n  one_smul := Category.id_comp\n  mul_smul _ _ _ := Category.assoc _ _ _\n#align category_theory.End.mul_action_left CategoryTheory.End.mulActionLeft\n\ntheorem smul_right {X Y : C} {r : End Y} {f : X \u27f6 Y} : r \u2022 f = f \u226b r :=\n  rfl\n#align category_theory.End.smul_right CategoryTheory.End.smul_right\n\ntheorem smul_left {X : C\u1d52\u1d56} {Y : C} {r : End X} {f : unop X \u27f6 Y} : r \u2022 f = r.unop \u226b f :=\n  rfl\n#align category_theory.End.smul_left CategoryTheory.End.smul_left\n\nend MulAction\n\n/-- In a groupoid, endomorphisms form a group -/\ninstance group {C : Type u} [Groupoid.{v} C] (X : C) : Group (End X) where\n  mul_left_inv := Groupoid.comp_inv\n  inv := Groupoid.inv\n#align category_theory.End.group CategoryTheory.End.group\n\nend End\n\ntheorem isUnit_iff_isIso {C : Type u} [Category.{v} C] {X : C} (f : End X) :\n    IsUnit (f : End X) \u2194 IsIso f :=\n  \u27e8fun h => { out := \u27e8h.unit.inv, \u27e8h.unit.inv_val, h.unit.val_inv\u27e9\u27e9 }, fun h =>\n    \u27e8\u27e8f, inv f, by simp, by simp\u27e9, rfl\u27e9\u27e9\n#align category_theory.is_unit_iff_is_iso CategoryTheory.isUnit_iff_isIso\n\nvariable {C : Type u} [Category.{v} C] (X : C)\n\n/-- Automorphisms of an object in a category.\n\nThe order of arguments in multiplication agrees with\n`Function.comp`, not with `CategoryTheory.CategoryStruct.comp`.\n-/\ndef Aut (X : C) := X \u2245 X\nset_option linter.uppercaseLean3 false in\n#align category_theory.Aut CategoryTheory.Aut\n\nnamespace Aut\n\nprotected instance inhabited : Inhabited (Aut X) := \u27e8Iso.refl X\u27e9\nset_option linter.uppercaseLean3 false in\n#align category_theory.Aut.inhabited CategoryTheory.Aut.inhabited\n\ninstance : Group (Aut X) where\n  one := Iso.refl X\n  inv := Iso.symm\n  mul x y := Iso.trans y x\n  mul_assoc _ _ _ := (Iso.trans_assoc _ _ _).symm\n  one_mul := Iso.trans_refl\n  mul_one := Iso.refl_trans\n  mul_left_inv := Iso.self_symm_id\n\ntheorem Aut_mul_def (f g : Aut X) : f * g = g.trans f := rfl\nset_option linter.uppercaseLean3 false in\n#align category_theory.Aut.Aut_mul_def CategoryTheory.Aut.Aut_mul_def\n\ntheorem Aut_inv_def (f : Aut X) : f\u207b\u00b9 = f.symm := rfl\nset_option linter.uppercaseLean3 false in\n#align category_theory.Aut.Aut_inv_def CategoryTheory.Aut.Aut_inv_def\n\n/-- Units in the monoid of endomorphisms of an object\nare (multiplicatively) equivalent to automorphisms of that object.\n-/\ndef unitsEndEquivAut : (End X)\u02e3 \u2243* Aut X where\n  toFun f := \u27e8f.1, f.2, f.4, f.3\u27e9\n  invFun f := \u27e8f.1, f.2, f.4, f.3\u27e9\n  left_inv := fun \u27e8f\u2081, f\u2082, f\u2083, f\u2084\u27e9 => rfl\n  right_inv := fun \u27e8f\u2081, f\u2082, f\u2083, f\u2084\u27e9 => rfl\n  map_mul' f g := by cases f; cases g; rfl\nset_option linter.uppercaseLean3 false in\n#align category_theory.Aut.units_End_equiv_Aut CategoryTheory.Aut.unitsEndEquivAut\n\n/-- Isomorphisms induce isomorphisms of the automorphism group -/\ndef autMulEquivOfIso {X Y : C} (h : X \u2245 Y) : Aut X \u2243* Aut Y where\n  toFun x := \u27e8h.inv \u226b x.hom \u226b h.hom, h.inv \u226b x.inv \u226b h.hom, _, _\u27e9\n  invFun y := \u27e8h.hom \u226b y.hom \u226b h.inv, h.hom \u226b y.inv \u226b h.inv, _, _\u27e9\n  left_inv _ := by aesop_cat\n  right_inv _ := by aesop_cat\n  map_mul' := by simp [Aut_mul_def]\nset_option linter.uppercaseLean3 false in\n#align category_theory.Aut.Aut_mul_equiv_of_iso CategoryTheory.Aut.autMulEquivOfIso\n\nend Aut\n\nnamespace Functor\n\nvariable {D : Type u'} [Category.{v'} D] (f : C \u2964 D)\n\n/-- `f.map` as a monoid hom between endomorphism monoids. -/\n@[simps]\ndef mapEnd : End X \u2192* End (f.obj X) where\n  toFun := f.map\n  map_mul' x y := f.map_comp y x\n  map_one' := f.map_id X\n#align category_theory.functor.map_End CategoryTheory.Functor.mapEnd\n\n/-- `f.mapIso` as a group hom between automorphism groups. -/\ndef mapAut : Aut X \u2192* Aut (f.obj X) where\n  toFun := f.mapIso\n  map_mul' x y := f.mapIso_trans y x\n  map_one' := f.mapIso_refl X\nset_option linter.uppercaseLean3 false in\n#align category_theory.functor.map_Aut CategoryTheory.Functor.mapAut\n\nend Functor\n\nend CategoryTheory\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Endomorphism.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7085138858437924}}
{"text": "import data.real.basic\n\ndef non_decreasing (f : \u211d \u2192 \u211d) := \u2200 x\u2081 x\u2082, x\u2081 \u2264 x\u2082 \u2192 f x\u2081 \u2264 f x\u2082\n\n-- 1\u00aa demostraci\u00f3n\nexample \n  (f : \u211d \u2192 \u211d) \n  (h : non_decreasing f) \n  (h' : \u2200 x, f (f x) = x) : \n  \u2200 x, f x = x :=\nbegin\n  intro x,\n  specialize h' x,\n  unfold non_decreasing at h,\n  cases le_total (f x) x with,\n  { specialize h (f x) x h_1,\n    rw h' at h,\n    exact le_antisymm h_1 h },\n  { specialize h x (f x) h_1,\n    rw h' at h,\n    exact le_antisymm h h_1 }\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample \n  (f : \u211d \u2192 \u211d) \n  (h : non_decreasing f) \n  (h' : \u2200 x, f (f x) = x) : \n  \u2200 x, f x = x :=\nbegin\n  intro x,\n  specialize h' x,\n  cases le_total x (f x);\n  linarith [h _ _ h_1]\nend\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/No_decreciente_involutiva_es_identidad.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7085138836114544}}
{"text": "import data.fintype.basic\nimport tactic\nimport matroid\nimport finset\nimport base_of\n\nvariables {\u03b1 : Type*} [fintype \u03b1] [decidable_eq \u03b1] {m : matroid \u03b1} {A B X: finset \u03b1}\n\nopen finset\n\nnamespace matroid\n\ninstance : decidable_pred m.ind := m.ind_dec\n\n-- def rank (m : matroid \u03b1) (A : finset \u03b1) : \u2115 := card (classical.some $ exists_base_of m A) \ndef rank (m : matroid \u03b1) (A : finset \u03b1) : \u2115 := sup (filter m.ind (powerset A)) card\n\n@[simp] lemma rank_def : rank m A = sup (filter m.ind (powerset A)) card := rfl\n\n@[simp] lemma rank_empty : rank m \u2205 = 0 := \nbegin\n  rw rank,\n  simp only [card_empty, filter_true_of_mem, forall_eq, powerset_empty, sup_singleton, ind_empty_def, mem_singleton],\nend\n\nlemma rank_eq_card_base_of (Bbase : m.base_of A B) : rank m A = B.card :=\nbegin\n  rw rank_def,\n  apply nat.le_antisymm, {\n    apply finset.sup_le,\n    intros C hC,\n    simp only [mem_powerset, mem_filter] at hC,\n    exact ind_card_le_base_of_card hC.1 hC.2 Bbase,\n  }, {\n    apply le_sup,\n    simp only [mem_powerset, mem_filter],\n    exact \u27e8Bbase.1, Bbase.2.1\u27e9,\n  }\nend\n\nlemma rank_exists_base_of (m : matroid \u03b1) (A : finset \u03b1) : \n  \u2203 (B : finset \u03b1), m.rank A = B.card \u2227 m.base_of A B :=\nbegin\n  obtain \u27e8B, Bbase\u27e9 := exists_base_of m A,\n  refine \u27e8B, rank_eq_card_base_of Bbase, Bbase\u27e9,\nend\n\n\ntheorem rank_le_card : rank m A \u2264 A.card :=\nbegin\n  obtain \u27e8bA, bAcard, bAbase\u27e9 := rank_exists_base_of m A,\n  rw bAcard,\n  exact card_le_of_subset bAbase.1,\nend\n\n@[simp] lemma rank_subset (hAB : A \u2286 B) : rank m A \u2264 rank m B :=\nbegin\n  obtain \u27e8bA, bAbase\u27e9 := exists_base_of m A,\n  obtain \u27e8bB, bBbase\u27e9 := exists_base_of m B,\n  rw rank_eq_card_base_of bAbase,\n  rw rank_eq_card_base_of bBbase,\n  refine ind_card_le_base_of_card (subset.trans bAbase.1 hAB) bAbase.2.1 bBbase,\nend\n\n@[simp] lemma rank_ind : m.ind A \u2194 rank m A = A.card :=\nbegin\n  split, {\n    intro Aind,\n    rw [base_of_refl_iff_ind] at Aind,\n    rw rank_eq_card_base_of Aind,\n  }, {\n    intro h_card,\n    obtain \u27e8B, Bcard, Bbase\u27e9 := rank_exists_base_of m A,\n    rw h_card at Bcard, \n    suffices h_eq : A = B, {\n      subst h_eq,\n      exact Bbase.2.1,\n    },\n    symmetry,\n    exact eq_of_subset_of_card_le Bbase.1 (le_of_eq Bcard),\n  }\nend\n\ntheorem rank_submodular : m.rank (A \u2229 B) + m.rank (A \u222a B) \u2264 m.rank A + m.rank B :=\nbegin\n  obtain \u27e8bInter, bInter_base\u27e9 := exists_base_of m (A \u2229 B),\n  have rankInter := rank_eq_card_base_of bInter_base,\n  \n  obtain \u27e8bA, bA_sub, bA_base\u27e9 := ind_subset_base_of (subset.trans bInter_base.1 (inter_subset_left _ _)) (bInter_base.2.1),\n  have rankA := rank_eq_card_base_of bA_base,\n  \n  obtain \u27e8bUnion, bUnion_sub, bUnion_base\u27e9 :=\n    ind_subset_base_of (subset.trans bA_base.1 (subset_union_left A B)) bA_base.2.1,\n  have rankUnion := rank_eq_card_base_of bUnion_base,\n  \n  obtain \u27e8bB, bB_base\u27e9 := exists_base_of m B,\n  have rankB := rank_eq_card_base_of bB_base,  \n  \n  have indB_sub : (bUnion \\ (bA \\ bInter)) \u2286 B := by {\n    intros x hx,\n    rw [mem_sdiff, not_mem_sdiff_iff] at hx,\n    rcases hx with \u27e8xBunion, xA | xInter\u27e9, {\n      have xAB := bUnion_base.1 xBunion,\n      cases (mem_union.1 xAB), {\n        exfalso,\n        have h_insert_dep := bA_base.2.2 _ xA h,\n        refine h_insert_dep (ind_subset_def _ (bUnion_base.2.1)),\n        rw \u2190 insert_eq_of_mem xBunion,\n        refine insert_subset_insert x bUnion_sub,\n      }, {\n        exact h,\n      }\n    }, {\n      exact mem_of_mem_inter_right (bInter_base.1 xInter),\n    },\n  },\n  have indB_ind : m.ind (bUnion \\ (bA \\ bInter)) := ind_subset_def (sdiff_subset _ _) bUnion_base.2.1,\n\n  have tmp := ind_card_le_base_of_card indB_sub indB_ind bB_base,\n  have indB_card : (bUnion \\ (bA \\ bInter)).card + bA.card = bUnion.card + bInter.card := by {\n    zify,\n    rw card_sdiff_\u2124 (subset.trans (sdiff_subset bA bInter) bUnion_sub),        \n    rw card_sdiff_\u2124 bA_sub,\n    ring,\n  },\n\n  rw [rankInter, rankA, rankUnion, rankB],\n  linarith,\nend\n\n\nend matroid", "meta": {"author": "VArtem", "repo": "lean-matroids", "sha": "a8969b1cb2456820ccbdce65e2e168c48c30d9bf", "save_path": "github-repos/lean/VArtem-lean-matroids", "path": "github-repos/lean/VArtem-lean-matroids/lean-matroids-a8969b1cb2456820ccbdce65e2e168c48c30d9bf/src/rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7085138747653992}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Anne Baanen\n\nA typeclass for the two-sided multiplicative inverse.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.char_zero\nimport Mathlib.algebra.char_p.basic\nimport Mathlib.PostPort\n\nuniverses u l u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# Invertible elements\n\nThis file defines a typeclass `invertible a` for elements `a` with a\nmultiplicative inverse.\n\nThe intent of the typeclass is to provide a way to write e.g. `\u215f2` in a ring\nlike `\u2124[1/2]` where some inverses exist but there is no general `\u207b\u00b9` operator;\nor to specify that a field has characteristic `\u2260 2`.\nIt is the `Type`-valued analogue to the `Prop`-valued `is_unit`.\n\nThis file also includes some instances of `invertible` for specific numbers in\ncharacteristic zero. Some more cases are given as a `def`, to be included only\nwhen needed. To construct instances for concrete numbers,\n`invertible_of_nonzero` is a useful definition.\n\n## Notation\n\n * `\u215fa` is `invertible.inv_of a`, the inverse of `a`\n\n## Implementation notes\n\nThe `invertible` class lives in `Type`, not `Prop`, to make computation easier.\nIf multiplication is associative, `invertible` is a subsingleton anyway.\n\nThe `simp` normal form tries to normalize `\u215fa` to `a \u207b\u00b9`. Otherwise, it pushes\n`\u215f` inside the expression as much as possible.\n\n## Tags\n\ninvertible, inverse element, inv_of, a half, one half, a third, one third, \u00bd, \u2153\n\n-/\n\n/-- `invertible a` gives a two-sided multiplicative inverse of `a`. -/\nclass invertible {\u03b1 : Type u} [Mul \u03b1] [HasOne \u03b1] (a : \u03b1) \nwhere\n  inv_of : \u03b1\n  inv_of_mul_self : inv_of * a = 1\n  mul_inv_of_self : a * inv_of = 1\n\nnotation:1024 \"\u215f\" => Mathlib.invertible.inv_of\n\n-- This notation has the same precedence as `has_inv.inv`.\n\n@[simp] theorem inv_of_mul_self {\u03b1 : Type u} [Mul \u03b1] [HasOne \u03b1] (a : \u03b1) [invertible a] : \u215f * a = 1 :=\n  invertible.inv_of_mul_self\n\n@[simp] theorem mul_inv_of_self {\u03b1 : Type u} [Mul \u03b1] [HasOne \u03b1] (a : \u03b1) [invertible a] : a * \u215f = 1 :=\n  invertible.mul_inv_of_self\n\n@[simp] theorem inv_of_mul_self_assoc {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) (b : \u03b1) [invertible a] : \u215f * (a * b) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u215f * (a * b) = b)) (Eq.symm (mul_assoc \u215f a b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u215f * a * b = b)) (inv_of_mul_self a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (1 * b = b)) (one_mul b))) (Eq.refl b)))\n\n@[simp] theorem mul_inv_of_self_assoc {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) (b : \u03b1) [invertible a] : a * (\u215f * b) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (\u215f * b) = b)) (Eq.symm (mul_assoc a \u215f b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * \u215f * b = b)) (mul_inv_of_self a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (1 * b = b)) (one_mul b))) (Eq.refl b)))\n\n@[simp] theorem mul_inv_of_mul_self_cancel {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) (b : \u03b1) [invertible b] : a * \u215f * b = a := sorry\n\n@[simp] theorem mul_mul_inv_of_self_cancel {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) (b : \u03b1) [invertible b] : a * b * \u215f = a := sorry\n\ntheorem inv_of_eq_right_inv {\u03b1 : Type u} [monoid \u03b1] {a : \u03b1} {b : \u03b1} [invertible a] (hac : a * b = 1) : \u215f = b :=\n  left_inv_eq_right_inv (inv_of_mul_self a) hac\n\ntheorem invertible_unique {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) (b : \u03b1) (h : a = b) [invertible a] [invertible b] : \u215f = \u215f :=\n  inv_of_eq_right_inv\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * \u215f = 1)) h))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b * \u215f = 1)) (mul_inv_of_self b))) (Eq.refl 1)))\n\nprotected instance invertible.subsingleton {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) : subsingleton (invertible a) :=\n  subsingleton.intro fun (_x : invertible a) => sorry\n\n/-- An `invertible` element is a unit. -/\ndef unit_of_invertible {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) [invertible a] : units \u03b1 :=\n  units.mk a \u215f sorry sorry\n\n@[simp] theorem unit_of_invertible_val {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) [invertible a] : \u2191(unit_of_invertible a) = a :=\n  rfl\n\n@[simp] theorem unit_of_invertible_inv {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) [invertible a] : \u2191(unit_of_invertible a\u207b\u00b9) = \u215f :=\n  rfl\n\ntheorem is_unit_of_invertible {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) [invertible a] : is_unit a :=\n  Exists.intro (unit_of_invertible a) rfl\n\n/-- Each element of a group is invertible. -/\ndef invertible_of_group {\u03b1 : Type u} [group \u03b1] (a : \u03b1) : invertible a :=\n  invertible.mk (a\u207b\u00b9) (inv_mul_self a) (mul_inv_self a)\n\n@[simp] theorem inv_of_eq_group_inv {\u03b1 : Type u} [group \u03b1] (a : \u03b1) [invertible a] : \u215f = (a\u207b\u00b9) :=\n  inv_of_eq_right_inv (mul_inv_self a)\n\n/-- `1` is the inverse of itself -/\ndef invertible_one {\u03b1 : Type u} [monoid \u03b1] : invertible 1 :=\n  invertible.mk 1 sorry sorry\n\n@[simp] theorem inv_of_one {\u03b1 : Type u} [monoid \u03b1] [invertible 1] : \u215f = 1 :=\n  inv_of_eq_right_inv (mul_one 1)\n\n/-- `-\u215fa` is the inverse of `-a` -/\ndef invertible_neg {\u03b1 : Type u} [ring \u03b1] (a : \u03b1) [invertible a] : invertible (-a) :=\n  invertible.mk (-\u215f) sorry sorry\n\n@[simp] theorem inv_of_neg {\u03b1 : Type u} [ring \u03b1] (a : \u03b1) [invertible a] [invertible (-a)] : \u215f = -\u215f := sorry\n\n@[simp] theorem one_sub_inv_of_two {\u03b1 : Type u} [ring \u03b1] [invertible (bit0 1)] : 1 - \u215f = \u215f := sorry\n\n/-- `a` is the inverse of `\u215fa`. -/\nprotected instance invertible_inv_of {\u03b1 : Type u} [HasOne \u03b1] [Mul \u03b1] {a : \u03b1} [invertible a] : invertible \u215f :=\n  invertible.mk a (mul_inv_of_self a) (inv_of_mul_self a)\n\n@[simp] theorem inv_of_inv_of {\u03b1 : Type u} [monoid \u03b1] {a : \u03b1} [invertible a] [invertible \u215f] : \u215f = a :=\n  inv_of_eq_right_inv (inv_of_mul_self a)\n\n/-- `\u215fb * \u215fa` is the inverse of `a * b` -/\ndef invertible_mul {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) (b : \u03b1) [invertible a] [invertible b] : invertible (a * b) :=\n  invertible.mk (\u215f * \u215f) sorry sorry\n\n@[simp] theorem inv_of_mul {\u03b1 : Type u} [monoid \u03b1] (a : \u03b1) (b : \u03b1) [invertible a] [invertible b] [invertible (a * b)] : \u215f = \u215f * \u215f := sorry\n\n/--\nIf `r` is invertible and `s = r`, then `s` is invertible.\n-/\ndef invertible.copy {\u03b1 : Type u} [monoid \u03b1] {r : \u03b1} (hr : invertible r) (s : \u03b1) (hs : s = r) : invertible s :=\n  invertible.mk \u215f sorry sorry\n\ntheorem commute_inv_of {M : Type u_1} [HasOne M] [Mul M] (m : M) [invertible m] : commute m \u215f :=\n  Eq.trans (mul_inv_of_self m) (Eq.symm (inv_of_mul_self m))\n\nprotected instance invertible_pow {M : Type u_1} [monoid M] (m : M) [invertible m] (n : \u2115) : invertible (m ^ n) :=\n  invertible.mk (\u215f ^ n) sorry sorry\n\ntheorem nonzero_of_invertible {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) [invertible a] : a \u2260 0 := sorry\n\n/-- `a\u207b\u00b9` is an inverse of `a` if `a \u2260 0` -/\ndef invertible_of_nonzero {\u03b1 : Type u} [group_with_zero \u03b1] {a : \u03b1} (h : a \u2260 0) : invertible a :=\n  invertible.mk (a\u207b\u00b9) (inv_mul_cancel h) (mul_inv_cancel h)\n\n@[simp] theorem inv_of_eq_inv {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) [invertible a] : \u215f = (a\u207b\u00b9) :=\n  inv_of_eq_right_inv (mul_inv_cancel (nonzero_of_invertible a))\n\n@[simp] theorem inv_mul_cancel_of_invertible {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) [invertible a] : a\u207b\u00b9 * a = 1 :=\n  inv_mul_cancel (nonzero_of_invertible a)\n\n@[simp] theorem mul_inv_cancel_of_invertible {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) [invertible a] : a * (a\u207b\u00b9) = 1 :=\n  mul_inv_cancel (nonzero_of_invertible a)\n\n@[simp] theorem div_mul_cancel_of_invertible {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) (b : \u03b1) [invertible b] : a / b * b = a :=\n  div_mul_cancel a (nonzero_of_invertible b)\n\n@[simp] theorem mul_div_cancel_of_invertible {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) (b : \u03b1) [invertible b] : a * b / b = a :=\n  mul_div_cancel a (nonzero_of_invertible b)\n\n@[simp] theorem div_self_of_invertible {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) [invertible a] : a / a = 1 :=\n  div_self (nonzero_of_invertible a)\n\n/-- `b / a` is the inverse of `a / b` -/\ndef invertible_div {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) (b : \u03b1) [invertible a] [invertible b] : invertible (a / b) :=\n  invertible.mk (b / a) sorry sorry\n\n@[simp] theorem inv_of_div {\u03b1 : Type u} [group_with_zero \u03b1] (a : \u03b1) (b : \u03b1) [invertible a] [invertible b] [invertible (a / b)] : \u215f = b / a := sorry\n\n/-- `a` is the inverse of `a\u207b\u00b9` -/\ndef invertible_inv {\u03b1 : Type u} [group_with_zero \u03b1] {a : \u03b1} [invertible a] : invertible (a\u207b\u00b9) :=\n  invertible.mk a sorry sorry\n\n/--\nMonoid homs preserve invertibility.\n-/\ndef invertible.map {R : Type u_1} {S : Type u_2} [monoid R] [monoid S] (f : R \u2192* S) (r : R) [invertible r] : invertible (coe_fn f r) :=\n  invertible.mk (coe_fn f \u215f) sorry sorry\n\n/-- A natural number `t` is invertible in a field `K` if the charactistic of `K` does not divide\n`t`. -/\ndef invertible_of_ring_char_not_dvd {K : Type u_1} [field K] {t : \u2115} (not_dvd : \u00acring_char K \u2223 t) : invertible \u2191t :=\n  invertible_of_nonzero sorry\n\n/-- A natural number `t` is invertible in a field `K` of charactistic `p` if `p` does not divide\n`t`. -/\ndef invertible_of_char_p_not_dvd {K : Type u_1} [field K] {p : \u2115} [char_p K p] {t : \u2115} (not_dvd : \u00acp \u2223 t) : invertible \u2191t :=\n  invertible_of_nonzero sorry\n\nprotected instance invertible_of_pos {K : Type u_1} [field K] [char_zero K] (n : \u2115) [h : fact (0 < n)] : invertible \u2191n :=\n  invertible_of_nonzero sorry\n\nprotected instance invertible_succ {\u03b1 : Type u} [division_ring \u03b1] [char_zero \u03b1] (n : \u2115) : invertible \u2191(Nat.succ n) :=\n  invertible_of_nonzero sorry\n\n/-!\nA few `invertible n` instances for small numerals `n`. Feel free to add your own\nnumber when you need its inverse.\n-/\n\nprotected instance invertible_two {\u03b1 : Type u} [division_ring \u03b1] [char_zero \u03b1] : invertible (bit0 1) :=\n  invertible_of_nonzero sorry\n\nprotected instance invertible_three {\u03b1 : Type u} [division_ring \u03b1] [char_zero \u03b1] : invertible (bit1 1) :=\n  invertible_of_nonzero sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7085138726371821}}
{"text": "import data.real.basic\nimport data.int.parity\nimport algebra.geom_sum\n\nopen set\nopen finset\n\nopen_locale big_operators\n\nnoncomputable theory\n\n-- exercici 9\nexample (\u03b8 \u03c7 : Prop) : \u03b8 \u2194 (\u03b8 \u2227 \u03c7) \u2228 (\u03b8 \u2227 (\u00ac \u03c7)) :=\nbegin\n  sorry\nend\n\nexample (\u03b8 \u03c7 : Prop) : \u03b8 \u2194 (\u03b8 \u2227 \u03c7) \u2228 (\u03b8 \u2227 (\u00ac \u03c7)) :=\nbegin\n  split;finish,\nend\n\n-- exercici 11\ndef R := \u03bb (x y : \u2115), x < y\ndef S := \u03bb (x y : \u2115), x > y\n\nexample : \u2200 x, \u2203 y, R x y :=\nbegin\n  unfold R,\n  intro x,\n  use x+10,\n  linarith,\nend\n\nexample : \u00ac (\u2200 x, \u2203 y, S x y) :=\nbegin\n  unfold S,\n  push_neg,\n  use 0,\n  intro y,\n  exact zero_le y,\nend\n\n-- exercici 12\ndef S' := \u03bb (a b c : \u2115), c = a + b\n\nexample : \u2203 (x : \u2115), \u2203 (z : \u2115), (\u00ac x = z) \u2227\n  (\u2203 y, S' y y x) \u2227\n  (\u2203 t, S' t t z) :=\nbegin\n  unfold S',\n  use 0,\n  use 2,\n  split,\n  {\n    change 0 \u2260 2,\n    exact two_ne_zero.symm,\n  },\n  split,\n  {\n    use 0,\n  },\n  {\n    use 1,\n  }\nend\n\n\nexample : \u00ac (\u2203 x, (\u2200 y, \u2203 z, S' y z x)) :=\nbegin\n  sorry\nend\n\n--@[simp]\n--lemma simp_succ (n : \u2115) : n.succ = n + 1 := rfl\n\n\n-- 14a\nexample (n : \u2115) : \u2211 k in range (n + 1), (k : \u211d) = n * (n + 1) / 2 :=\nbegin\n  induction n with n hn,\n  { \n    norm_num,\n  },\n  {\n    rw sum_range_succ,\n    simp at hn \u22a2,\n    rw hn,\n    ring,\n  }\nend\n\n-- 14b\nexample (n : \u2115) : \u2211 k in range (n + 1), (k^2 : \u211d) = n*(n + 1)*(2*n + 1) / 6 :=\nbegin\n  induction n with n hn,\n  { \n    norm_num,\n  },\n  {\n    rw sum_range_succ,\n    simp at hn \u22a2,\n    rw hn,\n    ring,\n  }\nend\n\n-- 14c\nexample (n : \u2115) : 6 \u2223 (n * (n^2 + 5)) :=\nbegin\n  sorry\nend\n\n-- exercici 15\nexample (n : \u2115) : 3 \u2223 (4:\u2124)^n - 1 :=\nbegin\n  sorry\nend\n\nexample : \u2203 (n:\u2115), \u00ac 3 \u2223 (4:\u2124)^n + 1 :=\nbegin\n  sorry\nend\n\n\n-- exercici 17\nexample (a : \u2115 \u2192 \u211d) (h1 : (\u2200 n, 0 < a n) \u2228 (\u2200 n, a n < 0)) \n(h2 : \u2200 n, a n > -1) (n : \u2115):\n1 + \u2211 i in range (n+2), a i < \u220f i in range (n+2), (1 + a i):=\nbegin\n  induction n with n hn,\n  sorry\nend\n\n\n-- exercici 17bis\nexample (a : \u2115 \u2192 \u211d) (h1 : (\u2200 n, 0 < a n) \u2228 (\u2200 n, a n < 0)) (h2 : \u2200 n, a n > -1) :\n\u2200 n : \u2115, 2 \u2264 n \u2192 1 + \u2211 i in range n, a i < \u220f i in range n, (1 + a i):=\nbegin\n  sorry\nend\n\n\n\n", "meta": {"author": "mmasdeu", "repo": "fonaments", "sha": "433c8a365b76471d1e9dad57626825ee11143ee9", "save_path": "github-repos/lean/mmasdeu-fonaments", "path": "github-repos/lean/mmasdeu-fonaments/fonaments-433c8a365b76471d1e9dad57626825ee11143ee9/src/exercises/llista1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159129, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7084890195698612}}
{"text": "import tactic \n\nvariables P Q R :  Prop\n\nexample : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n    intros h,\n    have hpq : P \u2192 Q,\n    exact h.left,\n    have hqr : Q \u2192 R,\n    exact h.right,\n    clear h,\n    intro hp,\n    have hq : Q,\n    exact hpq hp,\n    exact hqr hq,\nend\n\n-- Alternatively \nexample : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n    intros h,\n    have hpq : P \u2192 Q := h.left,\n    have hqr : Q \u2192 R := h.right,\n    clear h,\n    intro hp,\n    have hq : Q,\n    exact hpq hp,\n    exact hqr hq,\nend\n\n/- Alternatively, using the cases tactic -/\n\nexample : (P \u2192 Q) \u2227 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n    intros h,\n    cases h with hpq hqr,\n    intro hp,\n    exact (hqr (hpq (hp))),\nend\n", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/7_have/ex1_have_h_imp_trans.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7084890105589371}}
{"text": "import Init.WF\nimport Init.Data.Nat\n\n\n\ntheorem nat_lt : \u2200 n : Nat, \n  Acc (fun (x y : Nat) => x < y) n := by \n  intros n \n  induction n with \n  | zero =>\n    focus\n      apply Acc.intro\n      intros y Hy\n      cases Hy\n  | succ n ih => \n    focus \n      apply Acc.intro\n      intros y Hy \n      apply Acc.intro \n      intros z Hz \n      cases ih with\n      | _ _ R => \n        apply R  \n        have Ht := Nat.le_of_lt_succ Hy \n        have Hw := Nat.lt_of_lt_of_le Hz Ht \n        exact Hw \n\nclass One (\u03b1 : Type u) where\n  one : \u03b1\n\nclass Op (\u03b1 : Type u) where\n  op : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n\nclass Associative (\u03b1 : Type u) extends (One \u03b1), (Op \u03b1) where \n  op_associative : \u2200 (x y z : \u03b1), op x (op y z) = op (op x y) z \n\nclass LeftOne (\u03b1 : Type u) extends (One \u03b1), (Op \u03b1) where \n  left_one : \u2200 x : \u03b1, op one x = x \n\nclass RightOne (\u03b1 : Type u) extends (One \u03b1), (Op \u03b1) where \n  right_one : \u2200 x : \u03b1, op x one = x \n\nclass Monoid (\u03b1 : Type u) extends \n  (One \u03b1), (Op \u03b1), (Associative \u03b1), \n  (LeftOne \u03b1), (RightOne \u03b1)\n  \n\nclass Inv (\u03b1 : Type u) where \n   inv : \u03b1 \u2192 \u03b1 \n\nclass LeftInv (\u03b1 : Type u) extends (Inv \u03b1), (Op \u03b1) where \n  left_inv : forall x : \u03b1, op (inv x) x = one\n\nclass RightInv (\u03b1 : Type u) extends (Inv \u03b1), (Op \u03b1) where \n    right_inv : forall x : \u03b1, op x (inv x) = one\n\nclass Group (\u03b1 : Type u) extends (Monoid \u03b1), (Inv \u03b1), \n  (LeftInv \u03b1), (RightInv \u03b1)\n\n\ntheorem monoid_cancel_left\n  {\u03b1 : Type u} \n  [H : Monoid \u03b1] \n  (z iz x y : \u03b1) : \n  H.op iz z = H.one \u2192\n  (H.op z x = H.op z y \u2194 x = y) := by \n  intro ha\n  apply Iff.intro\n  focus\n    intro hb \n    have Hcut : (H.op iz  (H.op z x))  = (H.op iz (H.op z  y)) := by \n      rewrite [hb]; exact rfl \n    rewrite [H.op_associative, ha, H.left_one] at Hcut\n    rewrite [H.op_associative, ha, H.left_one] at Hcut\n    exact Hcut\n  focus \n    intro hb \n    rewrite [hb]\n    exact rfl \n\n\ntheorem monoid_cancel_right\n  {\u03b1 : Type u} \n  [H : Monoid \u03b1] \n  (z iz x y : \u03b1) : \n  H.op z iz = H.one \u2192\n  (H.op x z = H.op y z \u2194 x = y) := by \n  intro ha\n  apply Iff.intro\n  focus\n    intro hb \n    have Hcut : (H.op (H.op x z) iz)  = (H.op (H.op y z) iz) := by \n      rewrite [hb]; exact rfl\n    rewrite [<-H.op_associative, ha, H.right_one] at Hcut\n    rewrite [<-H.op_associative, ha, H.right_one] at Hcut\n    exact Hcut \n  focus \n    intro hb \n    subst hb \n    exact rfl \n\n  \n\n  \n\n\n\n\n\n\n\n  \n  \n  \n\n\n", "meta": {"author": "mukeshtiwari", "repo": "Leanplayground", "sha": "773deaf73fbb677cdf518d0db34ad62a79bad642", "save_path": "github-repos/lean/mukeshtiwari-Leanplayground", "path": "github-repos/lean/mukeshtiwari-Leanplayground/Leanplayground-773deaf73fbb677cdf518d0db34ad62a79bad642/Ideas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.7084889952007396}}
{"text": "import data.real.basic\nopen classical\nattribute [instance] prop_decidable\n\n/-\n  Rigorous definition of a limit\n  For a sequence x_n, we say that \\lim_{n \\to \\infty} x_n = l if\n    \u2200 \u03b5 > 0, \u2203 N, n \u2265 N \u2192 |x_n - l| < \u03b5\n-/\n\ndef lim_to_inf (x : \u2115 \u2192 \u211d) (l : \u211d) :=\n  \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, abs (x n - l) < \u03b5\n\ntheorem exercise_1p4 (x : \u2115 \u2192 \u211d) (l : \u211d) (h\u2081 : lim_to_inf x l) :\n  lim_to_inf (\u03bb n, abs (x n)) (abs l) := \nbegin\n    intros \u03b5 \u03b5_pos,\n    rcases h\u2081 \u03b5 \u03b5_pos with \u27e8N, hN\u27e9,\n    use N,\n    intros n hn,\n    calc \n    abs (abs (x n) - abs l) \u2264 abs ((x n) - l) : abs_abs_sub_le_abs_sub (x n) l\n    ... < \u03b5 : hN n hn\nend", "meta": {"author": "ezrasitorus", "repo": "codewars_lean", "sha": "6d1abcc1253403511f4cfd767c645596175e4fd3", "save_path": "github-repos/lean/ezrasitorus-codewars_lean", "path": "github-repos/lean/ezrasitorus-codewars_lean/codewars_lean-6d1abcc1253403511f4cfd767c645596175e4fd3/src/limit_of_seq3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012671214071, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.7084876406462701}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport order.bounds\n\n/-!\n# Intervals in Lattices\n\nIn this file, we provide instances of lattice structures on intervals within lattices.\nSome of them depend on the order of the endpoints of the interval, and thus are not made\nglobal instances. These are probably not all of the lattice instances that could be placed on these\nintervals, but more can be added easily along the same lines when needed.\n\n## Main definitions\nIn the following, `*` can represent either `c`, `o`, or `i`.\n  * `set.Ic*.order_bot`\n  * `set.Ii*.semillatice_inf`\n  * `set.I*c.order_top`\n  * `set.I*c.semillatice_inf`\n  * `set.I**.lattice`\n  * `set.Iic.bounded_order`, within an `order_bot`\n  * `set.Ici.bounded_order`, within an `order_top`\n\n-/\n\nvariable {\u03b1 : Type*}\n\nnamespace set\n\nnamespace Ico\n\nvariables {a b : \u03b1}\n\ninstance [semilattice_inf \u03b1] : semilattice_inf (Ico a b) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, \u27e8le_inf hx.1 hy.1, lt_of_le_of_lt inf_le_left hx.2\u27e9)\n\n/-- `Ico a b` has a bottom element whenever `a < b`. -/\n@[reducible] protected def order_bot [partial_order \u03b1] (h : a < b) : order_bot (Ico a b) :=\n(is_least_Ico h).order_bot\n\nend Ico\n\nnamespace Iio\n\ninstance [semilattice_inf \u03b1] {a : \u03b1} : semilattice_inf (Iio a) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, lt_of_le_of_lt inf_le_left hx)\n\nend Iio\n\nnamespace Ioc\n\nvariables {a b : \u03b1}\n\ninstance [semilattice_sup \u03b1] : semilattice_sup (Ioc a b) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, \u27e8lt_of_lt_of_le hx.1 le_sup_left, sup_le hx.2 hy.2\u27e9)\n\n/-- `Ioc a b` has a top element whenever `a < b`. -/\n@[reducible] protected def order_top [partial_order \u03b1] (h : a < b) : order_top (Ioc a b) :=\n(is_greatest_Ioc h).order_top\n\nend Ioc\n\nnamespace Iio\n\ninstance [semilattice_sup \u03b1] {a : \u03b1} : semilattice_sup (Ioi a) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, lt_of_lt_of_le hx le_sup_left)\n\nend Iio\n\nnamespace Iic\n\nvariables {a : \u03b1}\n\ninstance [semilattice_inf \u03b1] : semilattice_inf (Iic a) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, le_trans inf_le_left hx)\n\ninstance [semilattice_sup \u03b1] : semilattice_sup (Iic a) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, sup_le hx hy)\n\ninstance [lattice \u03b1] : lattice (Iic a) :=\n{ .. Iic.semilattice_inf,\n  .. Iic.semilattice_sup }\n\ninstance [preorder \u03b1] : order_top (Iic a) :=\n{ top := \u27e8a, le_refl a\u27e9,\n  le_top := \u03bb x, x.prop }\n\n@[simp] lemma coe_top [partial_order \u03b1] {a : \u03b1} : \u2191(\u22a4 : Iic a) = a := rfl\n\ninstance [preorder \u03b1] [order_bot \u03b1] : order_bot (Iic a) :=\n{ bot := \u27e8\u22a5, bot_le\u27e9,\n  bot_le := \u03bb \u27e8_,_\u27e9, subtype.mk_le_mk.2 bot_le }\n\n@[simp] lemma coe_bot [preorder \u03b1] [order_bot \u03b1] {a : \u03b1} : \u2191(\u22a5 : Iic a) = (\u22a5 : \u03b1) := rfl\n\ninstance [partial_order \u03b1] [no_min_order \u03b1] {a : \u03b1} : no_min_order (Iic a) :=\n\u27e8\u03bb x, let \u27e8y, hy\u27e9 := exists_lt x.1 in \u27e8\u27e8y, le_trans hy.le x.2\u27e9, hy\u27e9 \u27e9\n\ninstance [preorder \u03b1] [order_bot \u03b1] : bounded_order (Iic a) :=\n{ .. Iic.order_top,\n  .. Iic.order_bot }\n\nend Iic\n\nnamespace Ici\n\nvariables {a : \u03b1}\n\ninstance [semilattice_inf \u03b1] : semilattice_inf (Ici a) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, le_inf hx hy)\n\ninstance [semilattice_sup \u03b1] : semilattice_sup (Ici a) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, le_trans hx le_sup_left)\n\ninstance [lattice \u03b1] : lattice (Ici a) :=\n{ .. Ici.semilattice_inf,\n  .. Ici.semilattice_sup }\n\ninstance [preorder \u03b1] : order_bot (Ici a) :=\n{ bot := \u27e8a, le_refl a\u27e9,\n  bot_le := \u03bb x, x.prop }\n\n@[simp] lemma coe_bot [partial_order \u03b1] {a : \u03b1} : \u2191(\u22a5 : Ici a) = a := rfl\n\ninstance [preorder \u03b1] [order_top \u03b1] : order_top (Ici a) :=\n{ top := \u27e8\u22a4, le_top\u27e9,\n  le_top := \u03bb \u27e8_,_\u27e9, subtype.mk_le_mk.2 le_top }\n\n@[simp] lemma coe_top [preorder \u03b1] [order_top \u03b1] {a : \u03b1} : \u2191(\u22a4 : Ici a) = (\u22a4 : \u03b1) := rfl\n\ninstance [partial_order \u03b1] [no_max_order \u03b1] {a : \u03b1} : no_max_order (Ici a) :=\n\u27e8\u03bb x, let \u27e8y, hy\u27e9 := exists_gt x.1 in \u27e8\u27e8y, le_trans x.2 hy.le\u27e9, hy\u27e9 \u27e9\n\ninstance [preorder \u03b1] [order_top \u03b1] : bounded_order (Ici a) :=\n{ .. Ici.order_top,\n  .. Ici.order_bot }\n\nend Ici\n\nnamespace Icc\n\ninstance [semilattice_inf \u03b1] {a b : \u03b1} : semilattice_inf (Icc a b) :=\nsubtype.semilattice_inf (\u03bb x y hx hy, \u27e8le_inf hx.1 hy.1, le_trans inf_le_left hx.2\u27e9)\n\ninstance [semilattice_sup \u03b1] {a b : \u03b1} : semilattice_sup (Icc a b) :=\nsubtype.semilattice_sup (\u03bb x y hx hy, \u27e8le_trans hx.1 le_sup_left, sup_le hx.2 hy.2\u27e9)\n\ninstance [lattice \u03b1] {a b : \u03b1} : lattice (Icc a b) :=\n{ .. Icc.semilattice_inf,\n  .. Icc.semilattice_sup }\n\n/-- `Icc a b` has a bottom element whenever `a \u2264 b`. -/\n@[reducible] protected def order_bot [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) : order_bot (Icc a b) :=\n(is_least_Icc h).order_bot\n\n/-- `Icc a b` has a top element whenever `a \u2264 b`. -/\n@[reducible] protected def order_top [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) : order_top (Icc a b) :=\n(is_greatest_Icc h).order_top\n\n/-- `Icc a b` is a `bounded_order` whenever `a \u2264 b`. -/\n@[reducible] protected def bounded_order [preorder \u03b1] {a b : \u03b1} (h : a \u2264 b) :\n  bounded_order (Icc a b) :=\n{ .. Icc.order_top h,\n  .. Icc.order_bot h }\n\nend Icc\n\nend set\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/lattice_intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835411997897, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7084631007777755}}
{"text": "-- Interseccion_de_intersecciones.lean\n-- Intersecci\u00f3n de intersecciones\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 3 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariable  {\u03b1 : Type}\nvariables A B : \u2115 \u2192 set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Inter],\n  split,\n  { intro h,\n    split,\n    { intro i,\n      exact (h i).1 },\n    { intro i,\n      exact (h i).2 }},\n  { intros h i,\n    cases h with h1 h2,\n    split,\n    { exact h1 i },\n    { exact h2 i }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Inter],\n  exact \u27e8\u03bb h, \u27e8\u03bb i, (h i).1, \u03bb i, (h i).2\u27e9,\n         \u03bb \u27e8h1, h2\u27e9 i, \u27e8h1 i, h2 i\u27e9\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext,\n  simp only [mem_inter_eq, mem_Inter],\n  finish,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nbegin\n  ext,\n  finish [mem_inter_eq, mem_Inter],\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (\u22c2 i, A i \u2229 B i) = (\u22c2 i, A i) \u2229 (\u22c2 i, B i) :=\nby finish [mem_inter_eq, mem_Inter, ext_iff]\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Interseccion_de_intersecciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180245, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7084630898298696}}
{"text": "import tactic data.nat.prime\nopen nat\n\n/--------------------------------------------------------------------------\n\n``have``\n\n  ``have hp : P,`` creates a new goal with target ``P`` and\n  adds ``hp : P`` as a hypothesis to the original goal.\n\nYou'll need the following theorem from the library:\n\nnat.dvd_sub : n \u2264 m \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 m - n\n\n   (Note that you don't need to provide n m k as inputs to dvd_sub\n   Lean can infer these from the rest of the expression.\n   More on this tomorrow.)\n\nDelete the ``sorry,`` below and replace it with a legitimate proof.\n\n--------------------------------------------------------------------------/\n\ntheorem dvd_sub_one {p a : \u2115} : (p \u2223 a) \u2192 (p \u2223 a + 1) \u2192 (p \u2223 1) :=\nbegin\n  sorry,\nend", "meta": {"author": "awainverse", "repo": "mc2022-lean-examples", "sha": "91d4db1f785dbaa806831f3cdd8846ca45e2891e", "save_path": "github-repos/lean/awainverse-mc2022-lean-examples", "path": "github-repos/lean/awainverse-mc2022-lean-examples/mc2022-lean-examples-91d4db1f785dbaa806831f3cdd8846ca45e2891e/src/day3/have_exercise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7084457839502764}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Quotients in Lean -- how it works\n\nIf `X` is a type and `\u2248` is an equivalence relation on `X`, then I claim\nthat there exits a type `Y` and a map `q : X \u2192 Y` with the following\ntwo properties:\n\n1) `q` is surjective;\n2) `q(x\u2081) = q(x\u2082) \u2194 x\u2081 \u2248 x\u2082`.\n\nI want to call `Y` \"the quotient of `X` by `\u2248`\" but this name is problematic\nfor reasons I'll describe a little later on. An important exercise if you\nwant to understand what's going on here is to figure out what this type\n`Y` is before reading the spoiler below.\n\n## My favourite equivalence relation, and a spoiler.\n\nLet me tell you about my favourite equivalence relation. The type `X` is\nthe collection of red, green, blue and yellow plastic shapes in my office.\nI have several hundred of them; they are squares, triangles and pentagons,\nthey click together, and you can make some pretty cool 3D shapes with them. \nThe equivalence relation `\u2248` on `X` is that two shapes are equivalent if\n(and only if) they have the same colour. \n\nNow here's the spoiler. With notation as above (so back to the general\ncases, with `X` a general type and `\u2248` a general equivalence relation),\nwe can define `Y` to be the type of equivalence classes for `\u2248`. Let's\nuse the notation `\u27e6x\u27e7 : Y` to denote the equivalence class of `x : X`. \nThe function `q` sends `x` to `\u27e6x\u27e7`. You know from earlier on in your\nmathematical career that `\u27e6x\u2081\u27e7 = \u27e6x\u2082\u27e7` if and only if `x\u2081 \u2248 x\u2082`,\nand clearly `q` is surjective because given an arbitrary `y : Y`, it's\nan equivalence class and hence by definition equal to `\u27e6x\u27e7` for some\nelement `x` of the class. Hence `Y` and `q` satisfy all the axioms\nabove.\n\nIn the example above, my favourite equivalence relation, there are\nfour equivalence classes, so `Y` has four elements. One consists of \nabout 70 red plastic shapes, one consists of about 70 blue plastic shapes,\none is all the green shapes and one is all the yellow shapes, the\nfunction `q` sends a plastic shape `x` to the element corresponding to its\ncolour and you can easily check the two axioms above are satisfied.\n\nBut here is a second possibility for `Y`. We let `Y` be the set \n`{red, yellow, green, blue}`, and we let `q` be the map sending\na shape to its colour. Again it's easy to check that all the axioms work.\n\nSo in fact there is more than one answer to the question \"what is `Y`?\".\nLet's take a closer look at those two answers. Let's call `Y\u2081` the\nfirst answer (so an element of `Y\u2081` is a collection of shapes all of which\nhave the same colour, e.g. \"the 70 red shapes\"), and let's\ncall `Y\u2082` the second answer (so an element of `Y\u2082` is a colour, e.g. \"red\").\nThere are obvious bijections between `Y\u2081` and `Y\u2082`, and furthermore\none can check that those bijections \"commute with the `q`s\" in the sense\nthat if you do `q\u2081 : X \u2192 Y\u2081` and then do the bijection, you end up with\nthe map `q\u2082 : X \u2192 Y\u2082`. Quotients are unique up to unique isomorphism,\nbut they are not unique.\n\nThis is why I don't like to talk about *the* quotient of `X` by `\u2248`,\nI would rather talk about *a* quotient of `X` by `\u2248`.\n\nAnother example is the ring `\u2124/10\u2124`. When I was at school I imagined\nthat this quotient ring was `{0,1,2,3,4,5,6,7,8,9}`. At university\nI leant that actually the elements were cosets of the ideal `10\u2124` in\nthe ring `\u2124` and I was foolish enough to believe the lecturer who told\nme this. Both of these choices are just *models* for the quotient. \nIt doesn't make sense to talk about \"the\" quotient -- it's nice to know\nthat models exist, but when we're proving things about quotients\nlike `\u2124/10\u2124` (e.g. proving that it has a natural ring structure),\nthe model doesn't matter; all that matters is that there's a \"reduce mod 10\"\nmap from `\u2124` to `\u2124/10\u2124` and that the axioms above are satisfied.\n\n## Lean's quotients\n\nLean's choice of `Y` is called `quotient s`, where `s` is a term which packages\nup `X` and `\u2248` and the proof that `\u2248` is an equivalence relation all into\none thing. The type of `s` is `setoid X` and to give a term of type `setoid X`\nyou have to give two pieces of information: a binary relation on `X`,\nand a proof that it's an equivalence relation.\n\n## Let's make a quotient\n\nLet's make the quotient `\u2124/37\u2124`. We will do this by starting with the integers,\ndefining a binary relation `R` on them by `R a b` is true iff `a` and `b`\nare congruent mod `37`, proving it's an equivalence relation, making\nthe corresponding term `s : setoid \u2124` and then defining `Zmod37` to be the\nquotient.\n\n-/\n\n/-- The binary relation `R a b` is defined to be the statement that `a - b`\nis a multiple of 37. -/\ndef R (a b : \u2124) : Prop :=\n\u2203 z : \u2124, a - b = 37 * z\n\nlemma R_def (a b : \u2124) : R a b \u2194 \u2203 z : \u2124, a - b = 37 * z :=\nbegin\n  refl,\nend\n\n\nlemma R_reflexive : reflexive R :=\nbegin\n  unfold reflexive, -- if you like\n  sorry\nend\n\nlemma R_symmetric : symmetric R :=\nbegin\n  sorry\nend\n\nlemma R_transitive : transitive R :=\nbegin\n  sorry\nend\n\nlemma R_equivalence : equivalence R :=\nbegin\n  sorry,\nend\n\n-- The \"setoid\" -- everything we've defined and proved so far,\n-- all bundled up into one term\ndef s : setoid \u2124 :=\n{ r := R,\n  iseqv := R_equivalence }\n\n-- Let's not make a definition, let's just make notation\nnotation `Zmod37` := quotient s \n\n-- Then `Zmod37` and `quotient s` are syntactically equal \n\n/-\n\nIn the next sheet we'll start to learn about the\nAPI for `quotient`. We'll learn the name of the\nmap from `\u2124` to `Zmod37`, we'll set up the notation\n`\u2248` and `\u27e6x\u27e7`, and we'll prove the two axioms, as well\nas discussing another fundamental property of quotients.\n\n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section06quotients/sheet1definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.899121379297294, "lm_q1q2_score": 0.7084457744628481}}
{"text": "import data.real.basic\nimport tactic\n-- import C_Limits.fae_solutions.Course\n-- open vilnius\n\nnamespace vilnius\n\nlocal notation `|` x `|` := abs x\n\n\n-- Recall the\ndefinition is_limit (a : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < \u03b5\n\n\nexample {a : \u2115 \u2192 \u211d} {l : \u211d} (c : \u211d) (ha : is_limit a l) :\n  is_limit (\u03bb i, a i + c) (l + c) :=\nbegin\n  intros \u03b5 h\u03b5,\n  obtain \u27e8N, hN\u27e9 := ha \u03b5 h\u03b5,\n  use N,\n  intros k hk,\n  simp only,\n  rw add_sub_add_comm,\n  rw sub_self,\n  rw add_zero,\n  exact hN k hk,\nend\n\n\nexample (a : \u2115 \u2192 \u211d) (l : \u211d) :\n  is_limit a l \u2194 is_limit (\u03bb i, a i - l) 0 :=\nbegin\n  split,\n  all_goals { intros ha \u03b5 h\u03b5,\n    obtain \u27e8N, hN\u27e9 := ha \u03b5 h\u03b5,\n    use N,\n    intros n hn,\n    simp only [sub_zero] at *,\n    exact hN n hn},\nend\n\n\n/- Helpful things:\n`abs_pos : 0 < |a| \u2194 a \u2260 0`\n`div_pos : 0 < a \u2192 0 < b \u2192 0 < a / b`\n`abs_mul x y : |x * y| = |x| * |y|`\n`lt_div_iff' : 0 < c \u2192 (a < b / c \u2194 c * a < b)`\nI typically find these things myself with a combination of\nthe \"guess the name of the lemma\" game (and ctrl-space).\n\n\nRecall also that we have proved the-/\n\ntheorem is_limit_add {a b : \u2115 \u2192 \u211d} {l m : \u211d}\n  (h1 : is_limit a l) (h2 : is_limit b m) :\n  is_limit (a + b) (l + m) := sorry\n\n--as well as the \n\ntheorem is_limit_mul_const_left {a : \u2115 \u2192 \u211d} {l c : \u211d} (h : is_limit a l) :\n  is_limit (\u03bb n, c * (a n)) (c * l) := sorry\n\n-- And now, over to you!\n\n-- This should just be a couple of lines now.\nexample (a : \u2115 \u2192 \u211d) (b : \u2115 \u2192 \u211d) (\u03b1 \u03b2 c d : \u211d) \n    (ha : is_limit a \u03b1) (hb : is_limit b \u03b2) : \n    is_limit ( \u03bb n, c * (a n) + d * (b n) ) (c * \u03b1 + d * \u03b2) :=\nbegin\n  -- intros \u03b5 h\u03b5,**BAD IDEA**\n  apply is_limit_add,\n  apply is_limit_mul_const_left ha,\n  apply is_limit_mul_const_left hb,\nend\n\nexample (a : \u2115 \u2192 \u211d) (b : \u2115 \u2192 \u211d)\n  (l : \u211d) (m : \u211d) (hl : is_limit a l) (hm : is_limit b m) \n  (hle : \u2200 n, a n \u2264 b n) : l \u2264 m :=\nbegin\n  set \u03b5 := l - m with def_\u03b5,\n  by_cases h\u03b5 : \u03b5 \u2264 0,\n  { exact le_of_sub_nonpos h\u03b5 },\n  { cases hl (\u03b5 / 2) (half_pos (not_le.mp h\u03b5)) with N hN,\n    cases hm (\u03b5 / 2) (half_pos (not_le.mp h\u03b5)) with M hM,\n    specialize hN (max N M) (le_max_left N M),\n    specialize hM (max N M) (le_max_right N M),\n    rw abs_sub_lt_iff at hN hM,\n    replace hM := hM.1,\n    replace hN := hN.2,\n    rw def_\u03b5 at hM hN,\n    rw [sub_lt_iff_lt_add] at hM,\n    rw sub_lt at hN,\n    rw sub_div at hM hN,\n    have h_calc: l - (l / 2 - m /2 ) = l / 2 - m / 2 + m,\n    rw \u2190 sub_add,\n    rw sub_half,\n    rw sub_add,\n    rw half_sub,\n    rw sub_eq_add_neg,\n    rw neg_neg,    \n    by_contra,\n    rw h_calc at hN,\n    have := hM.trans hN,\n    rw \u2190 not_le at this,\n    apply this,\n    exact hle (max N M) },\nend\n\nend vilnius", "meta": {"author": "faenuccio", "repo": "May22_Vilnius", "sha": "2ff937dc7568e6118473b1e7f479ccb2a5fa9767", "save_path": "github-repos/lean/faenuccio-May22_Vilnius", "path": "github-repos/lean/faenuccio-May22_Vilnius/May22_Vilnius-2ff937dc7568e6118473b1e7f479ccb2a5fa9767/src/C_Limits/fae_solutions/Exercices.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7084457728654355}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.algebra.basic\nimport number_theory.class_number.admissible_absolute_value\n\n/-!\n# Admissible absolute value on the integers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\nThis file defines an admissible absolute value `absolute_value.abs_is_admissible`\nwhich we use to show the class number of the ring of integers of a number field\nis finite.\n\n## Main results\n\n * `absolute_value.abs_is_admissible` shows the \"standard\" absolute value on `\u2124`,\n   mapping negative `x` to `-x`, is admissible.\n-/\n\nnamespace absolute_value\n\nopen int\n\n/-- We can partition a finite family into `partition_card \u03b5` sets, such that the remainders\nin each set are close together. -/\nlemma exists_partition_int (n : \u2115) {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {b : \u2124} (hb : b \u2260 0) (A : fin n \u2192 \u2124) :\n  \u2203 (t : fin n \u2192 fin \u23081 / \u03b5\u2309\u208a),\n  \u2200 i\u2080 i\u2081, t i\u2080 = t i\u2081 \u2192 \u2191(abs (A i\u2081 % b - A i\u2080 % b)) < abs b \u2022 \u03b5 :=\nbegin\n  have hb' : (0 : \u211d) < \u2191(abs b) := int.cast_pos.mpr (abs_pos.mpr hb),\n  have hb\u03b5 : 0 < abs b \u2022 \u03b5,\n  { rw algebra.smul_def,\n    exact mul_pos hb' h\u03b5 },\n  have hfloor : \u2200 i, 0 \u2264 floor ((A i % b : \u2124) / (abs b \u2022 \u03b5) : \u211d),\n  { intro i,\n    exact floor_nonneg.mpr (div_nonneg (cast_nonneg.mpr (mod_nonneg _ hb)) hb\u03b5.le) },\n  refine \u27e8\u03bb i, \u27e8nat_abs (floor ((A i % b : \u2124) / (abs b \u2022 \u03b5) : \u211d)), _\u27e9, _\u27e9,\n  { rw [\u2190 coe_nat_lt, nat_abs_of_nonneg (hfloor i), floor_lt],\n    apply lt_of_lt_of_le _ (nat.le_ceil _),\n    rw [algebra.smul_def, eq_int_cast, \u2190 div_div, div_lt_div_right h\u03b5,\n        div_lt_iff hb', one_mul, cast_lt],\n    exact int.mod_lt _ hb },\n  intros i\u2080 i\u2081 hi,\n  have hi : (\u230a\u2191(A i\u2080 % b) / abs b \u2022 \u03b5\u230b.nat_abs : \u2124) = \u230a\u2191(A i\u2081 % b) / abs b \u2022 \u03b5\u230b.nat_abs :=\n    congr_arg (coe : \u2115 \u2192 \u2124) (fin.mk_eq_mk.mp hi),\n  rw [nat_abs_of_nonneg (hfloor i\u2080), nat_abs_of_nonneg (hfloor i\u2081)] at hi,\n  have hi := abs_sub_lt_one_of_floor_eq_floor hi,\n  rw [abs_sub_comm, \u2190 sub_div, abs_div, abs_of_nonneg hb\u03b5.le, div_lt_iff hb\u03b5, one_mul] at hi,\n  rwa [int.cast_abs, int.cast_sub]\nend\n\n/-- `abs : \u2124 \u2192 \u2124` is an admissible absolute value -/\nnoncomputable def abs_is_admissible : is_admissible absolute_value.abs :=\n{ card := \u03bb \u03b5, \u23081 / \u03b5\u2309\u208a,\n  exists_partition' := \u03bb n \u03b5 h\u03b5 b hb, exists_partition_int n h\u03b5 hb,\n  .. absolute_value.abs_is_euclidean }\n\nnoncomputable instance : inhabited (is_admissible absolute_value.abs) :=\n\u27e8abs_is_admissible\u27e9\n\nend absolute_value\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/class_number/admissible_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.7084457643459007}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport set_theory.game.winner\nimport tactic.nth_rewrite.default\nimport tactic.equiv_rw\n\n/-!\n# Basic definitions about impartial (pre-)games\n\nWe will define an impartial game, one in which left and right can make exactly the same moves.\nOur definition differs slightly by saying that the game is always equivalent to its negative,\nno matter what moves are played. This allows for games such as poker-nim to be classifed as\nimpartial.\n-/\n\nuniverse u\n\nnamespace pgame\n\nlocal infix ` \u2248 ` := equiv\n\n/-- The definition for a impartial game, defined using Conway induction -/\ndef impartial_aux : pgame \u2192 Prop\n| G := G \u2248 -G \u2227 (\u2200 i, impartial_aux (G.move_left i)) \u2227 (\u2200 j, impartial_aux (G.move_right j))\nusing_well_founded { dec_tac := pgame_wf_tac }\n\nlemma impartial_aux_def {G : pgame} : G.impartial_aux \u2194 G \u2248 -G \u2227\n  (\u2200 i, impartial_aux (G.move_left i)) \u2227 (\u2200 j, impartial_aux (G.move_right j)) :=\nbegin\n  split,\n  { intro hi,\n    unfold1 impartial_aux at hi,\n    exact hi },\n  { intro hi,\n    unfold1 impartial_aux,\n    exact hi }\nend\n\n/-- A typeclass on impartial games. -/\nclass impartial (G : pgame) : Prop := (out : impartial_aux G)\n\nlemma impartial_iff_aux {G : pgame} : G.impartial \u2194 G.impartial_aux :=\n\u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\nlemma impartial_def {G : pgame} : G.impartial \u2194 G \u2248 -G \u2227\n  (\u2200 i, impartial (G.move_left i)) \u2227 (\u2200 j, impartial (G.move_right j)) :=\nby simpa only [impartial_iff_aux] using impartial_aux_def\n\nnamespace impartial\n\ninstance impartial_zero : impartial 0 :=\nby { rw impartial_def, dsimp, simp }\n\nlemma neg_equiv_self (G : pgame) [h : G.impartial] : G \u2248 -G := (impartial_def.1 h).1\n\ninstance move_left_impartial {G : pgame} [h : G.impartial] (i : G.left_moves) :\n  (G.move_left i).impartial :=\n(impartial_def.1 h).2.1 i\n\ninstance move_right_impartial {G : pgame} [h : G.impartial] (j : G.right_moves) :\n  (G.move_right j).impartial :=\n(impartial_def.1 h).2.2 j\n\ninstance impartial_add : \u2200 (G H : pgame) [G.impartial] [H.impartial], (G + H).impartial\n| G H :=\nbegin\n  introsI hG hH,\n  rw impartial_def,\n  split,\n  { apply equiv_trans _ (neg_add_relabelling G H).equiv.symm,\n    exact add_congr (neg_equiv_self _) (neg_equiv_self _) },\n  split,\n  all_goals\n  { intro i,\n    equiv_rw pgame.left_moves_add G H at i <|> equiv_rw pgame.right_moves_add G H at i,\n    cases i },\n  all_goals\n  { simp only [add_move_left_inl, add_move_right_inl, add_move_left_inr, add_move_right_inr],\n    exact impartial_add _ _ }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\ninstance impartial_neg : \u2200 (G : pgame) [G.impartial], (-G).impartial\n| G :=\nbegin\n  introI hG,\n  rw impartial_def,\n  split,\n  { rw neg_neg,\n    symmetry,\n    exact neg_equiv_self G },\n  split,\n  all_goals\n  { intro i,\n    equiv_rw G.left_moves_neg at i <|> equiv_rw G.right_moves_neg at i,\n    simp only [move_left_left_moves_neg_symm, move_right_right_moves_neg_symm],\n    exact impartial_neg _ }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\nlemma winner_cases (G : pgame) [G.impartial] : G.first_loses \u2228 G.first_wins :=\nbegin\n  rcases G.winner_cases with hl | hr | hp | hn,\n  { cases hl with hpos hnonneg,\n    rw \u2190not_lt at hnonneg,\n    have hneg := lt_of_lt_of_equiv hpos (neg_equiv_self G),\n    rw [lt_iff_neg_gt, neg_neg, neg_zero] at hneg,\n    contradiction },\n  { cases hr with hnonpos hneg,\n    rw \u2190not_lt at hnonpos,\n    have hpos := lt_of_equiv_of_lt (neg_equiv_self G).symm hneg,\n    rw [lt_iff_neg_gt, neg_neg, neg_zero] at hpos,\n    contradiction },\n  { left, assumption },\n  { right, assumption }\nend\n\nlemma not_first_wins (G : pgame) [G.impartial] : \u00acG.first_wins \u2194 G.first_loses :=\nby cases winner_cases G; finish using [not_first_loses_of_first_wins]\n\nlemma not_first_loses (G : pgame) [G.impartial] : \u00acG.first_loses \u2194 G.first_wins :=\niff.symm $ iff_not_comm.1 $ iff.symm $ not_first_wins G\n\nlemma add_self (G : pgame) [G.impartial] : (G + G).first_loses :=\n  first_loses_is_zero.2 $ equiv_trans (add_congr (neg_equiv_self G) G.equiv_refl)\n  add_left_neg_equiv\n\nlemma equiv_iff_sum_first_loses (G H : pgame) [G.impartial] [H.impartial] :\n  G \u2248 H \u2194 (G + H).first_loses :=\nbegin\n  split,\n  { intro heq,\n    exact first_loses_of_equiv (add_congr (equiv_refl _) heq) (add_self G) },\n  { intro hGHp,\n    split,\n    { rw le_iff_sub_nonneg,\n      exact le_trans hGHp.2\n        (le_trans add_comm_le $ le_of_le_of_equiv (le_refl _) $ add_congr (equiv_refl _)\n        (neg_equiv_self G)) },\n    { rw le_iff_sub_nonneg,\n      exact le_trans hGHp.2\n        (le_of_le_of_equiv (le_refl _) $ add_congr (equiv_refl _) (neg_equiv_self H)) } }\nend\n\nlemma le_zero_iff {G : pgame} [G.impartial] : G \u2264 0 \u2194 0 \u2264 G :=\nby rw [le_zero_iff_zero_le_neg, le_congr (equiv_refl 0) (neg_equiv_self G)]\n\nlemma lt_zero_iff {G : pgame} [G.impartial] : G < 0 \u2194 0 < G :=\nby rw [lt_iff_neg_gt, neg_zero, lt_congr (equiv_refl 0) (neg_equiv_self G)]\n\nlemma first_loses_symm (G : pgame) [G.impartial] : G.first_loses \u2194 G \u2264 0 :=\n\u27e8and.left, \u03bb h, \u27e8h, le_zero_iff.1 h\u27e9\u27e9\n\nlemma first_wins_symm (G : pgame) [G.impartial] : G.first_wins \u2194 G < 0 :=\n\u27e8and.right, \u03bb h, \u27e8lt_zero_iff.1 h, h\u27e9\u27e9\n\nlemma first_loses_symm' (G : pgame) [G.impartial] : G.first_loses \u2194 0 \u2264 G :=\n\u27e8and.right, \u03bb h, \u27e8le_zero_iff.2 h, h\u27e9\u27e9\n\nlemma first_wins_symm' (G : pgame) [G.impartial] : G.first_wins \u2194 0 < G :=\n\u27e8and.left, \u03bb h, \u27e8h, lt_zero_iff.2 h\u27e9\u27e9\n\nlemma no_good_left_moves_iff_first_loses (G : pgame) [G.impartial] :\n  (\u2200 (i : G.left_moves), (G.move_left i).first_wins) \u2194 G.first_loses :=\nbegin\n  split,\n  { intro hbad,\n    rw [first_loses_symm G, le_def_lt],\n    split,\n    { intro i,\n      specialize hbad i,\n      exact hbad.2 },\n    { intro j,\n      exact pempty.elim j } },\n  { intros hp i,\n    rw first_wins_symm,\n    exact (le_def_lt.1 $ (first_loses_symm G).1 hp).1 i }\nend\n\nlemma no_good_right_moves_iff_first_loses (G : pgame) [G.impartial] :\n  (\u2200 (j : G.right_moves), (G.move_right j).first_wins) \u2194 G.first_loses :=\nbegin\n  rw [first_loses_of_equiv_iff (neg_equiv_self G), \u2190no_good_left_moves_iff_first_loses],\n  refine \u27e8\u03bb h i, _, \u03bb h i, _\u27e9,\n  { simpa [first_wins_of_equiv_iff (neg_equiv_self ((-G).move_left i))]\n    using h (left_moves_neg _ i) },\n  { simpa [first_wins_of_equiv_iff (neg_equiv_self (G.move_right i))]\n      using h ((left_moves_neg _).symm i) }\nend\n\nlemma good_left_move_iff_first_wins (G : pgame) [G.impartial] :\n  (\u2203 (i : G.left_moves), (G.move_left i).first_loses) \u2194 G.first_wins :=\nbegin\n  refine \u27e8\u03bb \u27e8i, hi\u27e9, (first_wins_symm' G).2 (lt_def_le.2 $ or.inl \u27e8i, hi.2\u27e9), \u03bb hn, _\u27e9,\n  rw [first_wins_symm' G, lt_def_le] at hn,\n  rcases hn with \u27e8i, hi\u27e9 | \u27e8j, _\u27e9,\n  { exact \u27e8i, (first_loses_symm' _).2 hi\u27e9 },\n  { exact pempty.elim j }\nend\n\nlemma good_right_move_iff_first_wins (G : pgame) [G.impartial] :\n  (\u2203 j : G.right_moves, (G.move_right j).first_loses) \u2194 G.first_wins :=\nbegin\n  refine \u27e8\u03bb \u27e8j, hj\u27e9, (first_wins_symm G).2 (lt_def_le.2 $ or.inr \u27e8j, hj.1\u27e9), \u03bb hn, _\u27e9,\n  rw [first_wins_symm G, lt_def_le] at hn,\n  rcases hn with \u27e8i, _\u27e9 | \u27e8j, hj\u27e9,\n  { exact pempty.elim i },\n  { exact \u27e8j, (first_loses_symm _).2 hj\u27e9 }\nend\n\nend impartial\nend pgame\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/set_theory/game/impartial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7084211743111155}}
{"text": "/-\nCopyright (c) 2014 Robert Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn\n-/\nimport algebra.ordered_ring\nimport algebra.field\nimport tactic.monotonicity.basic\n\n/-!\n# Linear ordered fields\n\nA linear ordered field is a field equipped with a linear order such that\n* addition respects the order: `a \u2264 b \u2192 c + a \u2264 c + b`;\n* multiplication of positives is positive: `0 < a \u2192 0 < b \u2192 0 < a * b`;\n* `0 < 1`.\n\n## Main Definitions\n\n* `linear_ordered_field`: the class of linear ordered fields.\n-/\n\nset_option old_structure_cmd true\n\nvariable {\u03b1 : Type*}\n\n/-- A linear ordered field is a field with a linear order respecting the operations. -/\n@[protect_proj] class linear_ordered_field (\u03b1 : Type*) extends linear_ordered_comm_ring \u03b1, field \u03b1\n\nsection linear_ordered_field\nvariables [linear_ordered_field \u03b1] {a b c d e : \u03b1}\n\n/-!\n### Lemmas about pos, nonneg, nonpos, neg\n-/\n\n@[simp] lemma inv_pos : 0 < a\u207b\u00b9 \u2194 0 < a :=\nsuffices \u2200 a : \u03b1, 0 < a \u2192 0 < a\u207b\u00b9,\nfrom \u27e8\u03bb h, inv_inv' a \u25b8 this _ h, this a\u27e9,\nassume a ha, flip lt_of_mul_lt_mul_left ha.le $ by simp [ne_of_gt ha, zero_lt_one]\n\n@[simp] lemma inv_nonneg : 0 \u2264 a\u207b\u00b9 \u2194 0 \u2264 a :=\nby simp only [le_iff_eq_or_lt, inv_pos, zero_eq_inv]\n\n@[simp] lemma inv_lt_zero : a\u207b\u00b9 < 0 \u2194 a < 0 :=\nby simp only [\u2190 not_le, inv_nonneg]\n\n@[simp] lemma inv_nonpos : a\u207b\u00b9 \u2264 0 \u2194 a \u2264 0 :=\nby simp only [\u2190 not_lt, inv_pos]\n\nlemma one_div_pos : 0 < 1 / a \u2194 0 < a :=\ninv_eq_one_div a \u25b8 inv_pos\n\nlemma one_div_neg : 1 / a < 0 \u2194 a < 0 :=\ninv_eq_one_div a \u25b8 inv_lt_zero\n\nlemma one_div_nonneg : 0 \u2264 1 / a \u2194 0 \u2264 a :=\ninv_eq_one_div a \u25b8 inv_nonneg\n\nlemma one_div_nonpos : 1 / a \u2264 0 \u2194 a \u2264 0 :=\ninv_eq_one_div a \u25b8 inv_nonpos\n\nlemma div_pos_iff : 0 < a / b \u2194 0 < a \u2227 0 < b \u2228 a < 0 \u2227 b < 0 :=\nby simp [division_def, mul_pos_iff]\n\nlemma div_neg_iff : a / b < 0 \u2194 0 < a \u2227 b < 0 \u2228 a < 0 \u2227 0 < b :=\nby simp [division_def, mul_neg_iff]\n\nlemma div_nonneg_iff : 0 \u2264 a / b \u2194 0 \u2264 a \u2227 0 \u2264 b \u2228 a \u2264 0 \u2227 b \u2264 0 :=\nby simp [division_def, mul_nonneg_iff]\n\nlemma div_nonpos_iff : a / b \u2264 0 \u2194 0 \u2264 a \u2227 b \u2264 0 \u2228 a \u2264 0 \u2227 0 \u2264 b :=\nby simp [division_def, mul_nonpos_iff]\n\nlemma div_pos (ha : 0 < a) (hb : 0 < b) : 0 < a / b :=\ndiv_pos_iff.2 $ or.inl \u27e8ha, hb\u27e9\n\nlemma div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=\ndiv_pos_iff.2 $ or.inr \u27e8ha, hb\u27e9\n\nlemma div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=\ndiv_neg_iff.2 $ or.inr \u27e8ha, hb\u27e9\n\nlemma div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=\ndiv_neg_iff.2 $ or.inl \u27e8ha, hb\u27e9\n\nlemma div_nonneg (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a / b :=\ndiv_nonneg_iff.2 $ or.inl \u27e8ha, hb\u27e9\n\nlemma div_nonneg_of_nonpos (ha : a \u2264 0) (hb : b \u2264 0) : 0 \u2264 a / b :=\ndiv_nonneg_iff.2 $ or.inr \u27e8ha, hb\u27e9\n\nlemma div_nonpos_of_nonpos_of_nonneg (ha : a \u2264 0) (hb : 0 \u2264 b) : a / b \u2264 0 :=\ndiv_nonpos_iff.2 $ or.inr \u27e8ha, hb\u27e9\n\nlemma div_nonpos_of_nonneg_of_nonpos (ha : 0 \u2264 a) (hb : b \u2264 0) : a / b \u2264 0 :=\ndiv_nonpos_iff.2 $ or.inl \u27e8ha, hb\u27e9\n\n/-!\n### Relating one division with another term.\n-/\n\nlemma le_div_iff (hc : 0 < c) : a \u2264 b / c \u2194 a * c \u2264 b :=\n\u27e8\u03bb h, div_mul_cancel b (ne_of_lt hc).symm \u25b8 mul_le_mul_of_nonneg_right h hc.le,\n  \u03bb h, calc\n    a   = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc).symm\n    ... \u2264 b * (1 / c)     : mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le\n    ... = b / c           : (div_eq_mul_one_div b c).symm\u27e9\n\nlemma le_div_iff' (hc : 0 < c) : a \u2264 b / c \u2194 c * a \u2264 b :=\nby rw [mul_comm, le_div_iff hc]\n\nlemma div_le_iff (hb : 0 < b) : a / b \u2264 c \u2194 a \u2264 c * b :=\n\u27e8\u03bb h, calc\n  a = a / b * b : by rw (div_mul_cancel _ (ne_of_lt hb).symm)\n  ... \u2264 c * b     : mul_le_mul_of_nonneg_right h hb.le,\n  \u03bb h, calc\n  a / b = a * (1 / b)     : div_eq_mul_one_div a b\n  ... \u2264 (c * b) * (1 / b) : mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le\n  ... = (c * b) / b       : (div_eq_mul_one_div (c * b) b).symm\n  ... = c                 : by refine (div_eq_iff (ne_of_gt hb)).mpr rfl\u27e9\n\nlemma div_le_iff' (hb : 0 < b) : a / b \u2264 c \u2194 a \u2264 b * c :=\nby rw [mul_comm, div_le_iff hb]\n\nlemma lt_div_iff (hc : 0 < c) : a < b / c \u2194 a * c < b :=\nlt_iff_lt_of_le_iff_le $ div_le_iff hc\n\nlemma lt_div_iff' (hc : 0 < c) : a < b / c \u2194 c * a < b :=\nby rw [mul_comm, lt_div_iff hc]\n\nlemma div_lt_iff (hc : 0 < c) : b / c < a \u2194 b < a * c :=\nlt_iff_lt_of_le_iff_le (le_div_iff hc)\n\nlemma div_lt_iff' (hc : 0 < c) : b / c < a \u2194 b < c * a :=\nby rw [mul_comm, div_lt_iff hc]\n\nlemma inv_mul_le_iff (h : 0 < b) : b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 b * c :=\nbegin\n  rw [inv_eq_one_div, mul_comm, \u2190 div_eq_mul_one_div],\n  exact div_le_iff' h,\nend\n\nlemma inv_mul_le_iff' (h : 0 < b) : b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 c * b :=\nby rw [inv_mul_le_iff h, mul_comm]\n\nlemma mul_inv_le_iff (h : 0 < b) : a * b\u207b\u00b9 \u2264 c \u2194 a \u2264 b * c :=\nby rw [mul_comm, inv_mul_le_iff h]\n\nlemma mul_inv_le_iff' (h : 0 < b) : a * b\u207b\u00b9 \u2264 c \u2194 a \u2264 c * b :=\nby rw [mul_comm, inv_mul_le_iff' h]\n\nlemma inv_mul_lt_iff (h : 0 < b) : b\u207b\u00b9 * a < c \u2194 a < b * c :=\nbegin\n  rw [inv_eq_one_div, mul_comm, \u2190 div_eq_mul_one_div],\n  exact div_lt_iff' h,\nend\n\nlemma inv_mul_lt_iff' (h : 0 < b) : b\u207b\u00b9 * a < c \u2194 a < c * b :=\nby rw [inv_mul_lt_iff h, mul_comm]\n\nlemma mul_inv_lt_iff (h : 0 < b) : a * b\u207b\u00b9 < c \u2194 a < b * c :=\nby rw [mul_comm, inv_mul_lt_iff h]\n\nlemma mul_inv_lt_iff' (h : 0 < b) : a * b\u207b\u00b9 < c \u2194 a < c * b :=\nby rw [mul_comm, inv_mul_lt_iff' h]\n\nlemma inv_pos_le_iff_one_le_mul (ha : 0 < a) : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 b * a :=\nby { rw [inv_eq_one_div], exact div_le_iff ha }\n\nlemma inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 a * b :=\nby { rw [inv_eq_one_div], exact div_le_iff' ha }\n\nlemma inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a\u207b\u00b9 < b \u2194 1 < b * a :=\nby { rw [inv_eq_one_div], exact div_lt_iff ha }\n\nlemma inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a\u207b\u00b9 < b \u2194 1 < a * b :=\nby { rw [inv_eq_one_div], exact div_lt_iff' ha }\n\nlemma div_le_iff_of_neg (hc : c < 0) : b / c \u2264 a \u2194 a * c \u2264 b :=\n\u27e8\u03bb h, div_mul_cancel b (ne_of_lt hc) \u25b8 mul_le_mul_of_nonpos_right h hc.le,\n  \u03bb h, calc\n    a = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc)\n  ... \u2265 b * (1 / c)     : mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le\n  ... = b / c           : (div_eq_mul_one_div b c).symm\u27e9\n\nlemma div_le_iff_of_neg' (hc : c < 0) : b / c \u2264 a \u2194 c * a \u2264 b :=\nby rw [mul_comm, div_le_iff_of_neg hc]\n\nlemma le_div_iff_of_neg (hc : c < 0) : a \u2264 b / c \u2194 b \u2264 a * c :=\nby rw [\u2190 neg_neg c, mul_neg_eq_neg_mul_symm, div_neg, le_neg,\n    div_le_iff (neg_pos.2 hc), neg_mul_eq_neg_mul_symm]\n\nlemma le_div_iff_of_neg' (hc : c < 0) : a \u2264 b / c \u2194 b \u2264 c * a :=\nby rw [mul_comm, le_div_iff_of_neg hc]\n\nlemma div_lt_iff_of_neg (hc : c < 0) : b / c < a \u2194 a * c < b :=\nlt_iff_lt_of_le_iff_le $ le_div_iff_of_neg hc\n\nlemma div_lt_iff_of_neg' (hc : c < 0) : b / c < a \u2194 c * a < b :=\nby rw [mul_comm, div_lt_iff_of_neg hc]\n\nlemma lt_div_iff_of_neg (hc : c < 0) : a < b / c \u2194 b < a * c :=\nlt_iff_lt_of_le_iff_le $ div_le_iff_of_neg hc\n\nlemma lt_div_iff_of_neg' (hc : c < 0) : a < b / c \u2194 b < c * a :=\nby rw [mul_comm, lt_div_iff_of_neg hc]\n\n/-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/\nlemma div_le_of_nonneg_of_le_mul (hb : 0 \u2264 b) (hc : 0 \u2264 c) (h : a \u2264 c * b) : a / b \u2264 c :=\nby { rcases eq_or_lt_of_le hb with rfl|hb', simp [hc], rwa [div_le_iff hb'] }\n\nlemma div_le_one_of_le (h : a \u2264 b) (hb : 0 \u2264 b) : a / b \u2264 1 :=\ndiv_le_of_nonneg_of_le_mul hb zero_le_one $ by rwa one_mul\n\n/-!\n### Bi-implications of inequalities using inversions\n-/\n\nlemma inv_le_inv_of_le (ha : 0 < a) (h : a \u2264 b) : b\u207b\u00b9 \u2264 a\u207b\u00b9 :=\nby rwa [\u2190 one_div a, le_div_iff' ha, \u2190 div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul]\n\n/-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/\nlemma inv_le_inv (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 \u2264 b\u207b\u00b9 \u2194 b \u2264 a :=\nby rw [\u2190 one_div, div_le_iff ha, \u2190 div_eq_inv_mul, le_div_iff hb, one_mul]\n\nlemma inv_le (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a :=\nby rw [\u2190 inv_le_inv hb (inv_pos.2 ha), inv_inv']\n\nlemma le_inv (ha : 0 < a) (hb : 0 < b) : a \u2264 b\u207b\u00b9 \u2194 b \u2264 a\u207b\u00b9 :=\nby rw [\u2190 inv_le_inv (inv_pos.2 hb) ha, inv_inv']\n\nlemma inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nlt_iff_lt_of_le_iff_le (inv_le_inv hb ha)\n\nlemma inv_lt (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 < b \u2194 b\u207b\u00b9 < a :=\nlt_iff_lt_of_le_iff_le (le_inv hb ha)\n\nlemma lt_inv (ha : 0 < a) (hb : 0 < b) : a < b\u207b\u00b9 \u2194 b < a\u207b\u00b9 :=\nlt_iff_lt_of_le_iff_le (inv_le hb ha)\n\nlemma inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 \u2264 b\u207b\u00b9 \u2194 b \u2264 a :=\nby rw [\u2190 one_div, div_le_iff_of_neg ha, \u2190 div_eq_inv_mul, div_le_iff_of_neg hb, one_mul]\n\nlemma inv_le_of_neg (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a :=\nby rw [\u2190 inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv']\n\nlemma le_inv_of_neg (ha : a < 0) (hb : b < 0) : a \u2264 b\u207b\u00b9 \u2194 b \u2264 a\u207b\u00b9 :=\nby rw [\u2190 inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv']\n\nlemma inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nlt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)\n\nlemma inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 < b \u2194 b\u207b\u00b9 < a :=\nlt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)\n\nlemma lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b\u207b\u00b9 \u2194 b < a\u207b\u00b9 :=\nlt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)\n\nlemma inv_lt_one (ha : 1 < a) : a\u207b\u00b9 < 1 :=\nby rwa [inv_lt ((@zero_lt_one \u03b1 _ _).trans ha) zero_lt_one, inv_one]\n\nlemma one_lt_inv (h\u2081 : 0 < a) (h\u2082 : a < 1) : 1 < a\u207b\u00b9 :=\nby rwa [lt_inv (@zero_lt_one \u03b1 _ _) h\u2081, inv_one]\n\nlemma inv_le_one (ha : 1 \u2264 a) : a\u207b\u00b9 \u2264 1 :=\nby rwa [inv_le ((@zero_lt_one \u03b1 _ _).trans_le ha) zero_lt_one, inv_one]\n\nlemma one_le_inv (h\u2081 : 0 < a) (h\u2082 : a \u2264 1) : 1 \u2264 a\u207b\u00b9 :=\nby rwa [le_inv (@zero_lt_one \u03b1 _ _) h\u2081, inv_one]\n\nlemma inv_lt_one_iff_of_pos (h\u2080 : 0 < a) : a\u207b\u00b9 < 1 \u2194 1 < a :=\n\u27e8\u03bb h\u2081, inv_inv' a \u25b8 one_lt_inv (inv_pos.2 h\u2080) h\u2081, inv_lt_one\u27e9\n\nlemma inv_lt_one_iff : a\u207b\u00b9 < 1 \u2194 a \u2264 0 \u2228 1 < a :=\nbegin\n  cases le_or_lt a 0 with ha ha,\n  { simp [ha, (inv_nonpos.2 ha).trans_lt zero_lt_one] },\n  { simp only [ha.not_le, false_or, inv_lt_one_iff_of_pos ha] }\nend\n\nlemma one_lt_inv_iff : 1 < a\u207b\u00b9 \u2194 0 < a \u2227 a < 1 :=\n\u27e8\u03bb h, \u27e8inv_pos.1 (zero_lt_one.trans h), inv_inv' a \u25b8 inv_lt_one h\u27e9, and_imp.2 one_lt_inv\u27e9\n\nlemma inv_le_one_iff : a\u207b\u00b9 \u2264 1 \u2194 a \u2264 0 \u2228 1 \u2264 a :=\nbegin\n  rcases em (a = 1) with (rfl|ha),\n  { simp [le_rfl] },\n  { simp only [ne.le_iff_lt (ne.symm ha), ne.le_iff_lt (mt inv_eq_one'.1 ha), inv_lt_one_iff] }\nend\n\nlemma one_le_inv_iff : 1 \u2264 a\u207b\u00b9 \u2194 0 < a \u2227 a \u2264 1 :=\n\u27e8\u03bb h, \u27e8inv_pos.1 (zero_lt_one.trans_le h), inv_inv' a \u25b8 inv_le_one h\u27e9, and_imp.2 one_le_inv\u27e9\n\n/-!\n### Relating two divisions.\n-/\n\n@[mono] lemma div_le_div_of_le (hc : 0 \u2264 c) (h : a \u2264 b) : a / c \u2264 b / c :=\nbegin\n  rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],\n  exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 hc)\nend\n\n@[mono] lemma div_le_div_of_le_left (ha : 0 \u2264 a) (hc : 0 < c) (h : c \u2264 b) : a / b \u2264 a / c :=\nbegin\n  rw [div_eq_mul_inv, div_eq_mul_inv],\n  exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha\nend\n\nlemma div_le_div_of_le_of_nonneg (hab : a \u2264 b) (hc : 0 \u2264 c) : a / c \u2264 b / c :=\ndiv_le_div_of_le hc hab\n\nlemma div_le_div_of_nonpos_of_le (hc : c \u2264 0) (h : b \u2264 a) : a / c \u2264 b / c :=\nbegin\n  rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],\n  exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc)\nend\n\nlemma div_lt_div_of_lt (hc : 0 < c) (h : a < b) : a / c < b / c :=\nbegin\n  rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],\n  exact mul_lt_mul_of_pos_right h (one_div_pos.2 hc)\nend\n\nlemma div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c :=\nbegin\n  rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],\n  exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc)\nend\n\nlemma div_le_div_right (hc : 0 < c) : a / c \u2264 b / c \u2194 a \u2264 b :=\n\u27e8le_imp_le_of_lt_imp_lt $ div_lt_div_of_lt hc, div_le_div_of_le $ hc.le\u27e9\n\nlemma div_le_div_right_of_neg (hc : c < 0) : a / c \u2264 b / c \u2194 b \u2264 a :=\n\u27e8le_imp_le_of_lt_imp_lt $ div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le $ hc.le\u27e9\n\nlemma div_lt_div_right (hc : 0 < c) : a / c < b / c \u2194 a < b :=\nlt_iff_lt_of_le_iff_le $ div_le_div_right hc\n\nlemma div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c \u2194 b < a :=\nlt_iff_lt_of_le_iff_le $ div_le_div_right_of_neg hc\n\nlemma div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c \u2194 c < b :=\nby simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc]\n\nlemma div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b \u2264 a / c \u2194 c \u2264 b :=\nle_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb)\n\nlemma div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) :\n  a / b < c / d \u2194 a * d < c * b :=\nby rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0]\n\nlemma div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b \u2264 c / d \u2194 a * d \u2264 c * b :=\nby rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0]\n\n@[mono] lemma div_le_div (hc : 0 \u2264 c) (hac : a \u2264 c) (hd : 0 < d) (hbd : d \u2264 b) : a / b \u2264 c / d :=\nby { rw div_le_div_iff (hd.trans_le hbd) hd, exact mul_le_mul hac hbd hd.le hc }\n\nlemma div_lt_div (hac : a < c) (hbd : d \u2264 b) (c0 : 0 \u2264 c) (d0 : 0 < d) :\n  a / b < c / d :=\n(div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0)\n\nlemma div_lt_div' (hac : a \u2264 c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) :\n  a / b < c / d :=\n(div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0)\n\nlemma div_lt_div_of_lt_left (hb : 0 < b) (h : b < a) (hc : 0 < c) : c / a < c / b :=\n(div_lt_div_left hc (hb.trans h) hb).mpr h\n\n/-!\n### Relating one division and involving `1`\n-/\n\nlemma one_le_div (hb : 0 < b) : 1 \u2264 a / b \u2194 b \u2264 a :=\nby rw [le_div_iff hb, one_mul]\n\nlemma div_le_one (hb : 0 < b) : a / b \u2264 1 \u2194 a \u2264 b :=\nby rw [div_le_iff hb, one_mul]\n\nlemma one_lt_div (hb : 0 < b) : 1 < a / b \u2194 b < a :=\nby rw [lt_div_iff hb, one_mul]\n\nlemma div_lt_one (hb : 0 < b) : a / b < 1 \u2194 a < b :=\nby rw [div_lt_iff hb, one_mul]\n\nlemma one_le_div_of_neg (hb : b < 0) : 1 \u2264 a / b \u2194 a \u2264 b :=\nby rw [le_div_iff_of_neg hb, one_mul]\n\nlemma div_le_one_of_neg (hb : b < 0) : a / b \u2264 1 \u2194 b \u2264 a :=\nby rw [div_le_iff_of_neg hb, one_mul]\n\nlemma one_lt_div_of_neg (hb : b < 0) : 1 < a / b \u2194 a < b :=\nby rw [lt_div_iff_of_neg hb, one_mul]\n\nlemma div_lt_one_of_neg (hb : b < 0) : a / b < 1 \u2194 b < a :=\nby rw [div_lt_iff_of_neg hb, one_mul]\n\nlemma one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a \u2264 b \u2194 1 / b \u2264 a :=\nby simpa using inv_le ha hb\n\nlemma one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b \u2194 1 / b < a :=\nby simpa using inv_lt ha hb\n\nlemma le_one_div (ha : 0 < a) (hb : 0 < b) : a \u2264 1 / b \u2194 b \u2264 1 / a :=\nby simpa using le_inv ha hb\n\nlemma lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b \u2194 b < 1 / a :=\nby simpa using lt_inv ha hb\n\nlemma one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a \u2264 b \u2194 1 / b \u2264 a :=\nby simpa using inv_le_of_neg ha hb\n\nlemma one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b \u2194 1 / b < a :=\nby simpa using inv_lt_of_neg ha hb\n\nlemma le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a \u2264 1 / b \u2194 b \u2264 1 / a :=\nby simpa using le_inv_of_neg ha hb\n\nlemma lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b \u2194 b < 1 / a :=\nby simpa using lt_inv_of_neg ha hb\n\nlemma one_lt_div_iff : 1 < a / b \u2194 0 < b \u2227 b < a \u2228 b < 0 \u2227 a < b :=\nbegin\n  rcases lt_trichotomy b 0 with (hb|rfl|hb),\n  { simp [hb, hb.not_lt, one_lt_div_of_neg] },\n  { simp [lt_irrefl, zero_le_one] },\n  { simp [hb, hb.not_lt, one_lt_div] }\nend\n\nlemma one_le_div_iff : 1 \u2264 a / b \u2194 0 < b \u2227 b \u2264 a \u2228 b < 0 \u2227 a \u2264 b :=\nbegin\n  rcases lt_trichotomy b 0 with (hb|rfl|hb),\n  { simp [hb, hb.not_lt, one_le_div_of_neg] },\n  { simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] },\n  { simp [hb, hb.not_lt, one_le_div] }\nend\n\nlemma div_lt_one_iff : a / b < 1 \u2194 0 < b \u2227 a < b \u2228 b = 0 \u2228 b < 0 \u2227 b < a :=\nbegin\n  rcases lt_trichotomy b 0 with (hb|rfl|hb),\n  { simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] },\n  { simp [zero_lt_one], },\n  { simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] }\nend\n\nlemma div_le_one_iff : a / b \u2264 1 \u2194 0 < b \u2227 a \u2264 b \u2228 b = 0 \u2228 b < 0 \u2227 b \u2264 a :=\nbegin\n  rcases lt_trichotomy b 0 with (hb|rfl|hb),\n  { simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] },\n  { simp [zero_le_one], },\n  { simp [hb, hb.not_lt, div_le_one, hb.ne.symm] }\nend\n\n/-!\n### Relating two divisions, involving `1`\n-/\nlemma one_div_le_one_div_of_le (ha : 0 < a) (h : a \u2264 b) : 1 / b \u2264 1 / a :=\nby simpa using inv_le_inv_of_le ha h\n\nlemma one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a :=\nby rwa [lt_div_iff' ha, \u2190 div_eq_mul_one_div, div_lt_one (ha.trans h)]\n\nlemma one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a \u2264 b) : 1 / b \u2264 1 / a :=\nby rwa [div_le_iff_of_neg' hb, \u2190 div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)]\n\nlemma one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a :=\nby rwa [div_lt_iff_of_neg' hb, \u2190 div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)]\n\nlemma le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a \u2264 1 / b) : b \u2264 a :=\nle_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h\n\nlemma lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=\nlt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h\n\nlemma le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a \u2264 1 / b) : b \u2264 a :=\nle_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h\n\nlemma lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a :=\nlt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h\n\n/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and\n  `le_of_one_div_le_one_div` -/\nlemma one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a \u2264 1 / b \u2194 b \u2264 a :=\ndiv_le_div_left zero_lt_one ha hb\n\n/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and\n  `lt_of_one_div_lt_one_div` -/\nlemma one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b \u2194 b < a :=\ndiv_lt_div_left zero_lt_one ha hb\n\n/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and\n  `lt_of_one_div_lt_one_div` -/\nlemma one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a \u2264 1 / b \u2194 b \u2264 a :=\nby simpa [one_div] using inv_le_inv_of_neg ha hb\n\n/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and\n  `lt_of_one_div_lt_one_div` -/\nlemma one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b \u2194 b < a :=\nlt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)\n\nlemma one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a :=\nby rwa [lt_one_div (@zero_lt_one \u03b1 _ _) h1, one_div_one]\n\nlemma one_le_one_div (h1 : 0 < a) (h2 : a \u2264 1) : 1 \u2264 1 / a :=\nby rwa [le_one_div (@zero_lt_one \u03b1 _ _) h1, one_div_one]\n\nlemma one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 :=\nsuffices 1 / a < 1 / -1, by rwa one_div_neg_one_eq_neg_one at this,\none_div_lt_one_div_of_neg_of_lt h1 h2\n\nlemma one_div_le_neg_one (h1 : a < 0) (h2 : -1 \u2264 a) : 1 / a \u2264 -1 :=\nsuffices 1 / a \u2264 1 / -1, by rwa one_div_neg_one_eq_neg_one at this,\none_div_le_one_div_of_neg_of_le h1 h2\n\n/-!\n### Results about halving.\n\nThe equalities also hold in fields of characteristic `0`. -/\nlemma add_halves (a : \u03b1) : a / 2 + a / 2 = a :=\nby rw [div_add_div_same, \u2190 two_mul, mul_div_cancel_left a two_ne_zero]\n\nlemma sub_self_div_two (a : \u03b1) : a - a / 2 = a / 2 :=\nsuffices a / 2 + a / 2 - a / 2 = a / 2, by rwa add_halves at this,\nby rw [add_sub_cancel]\n\nlemma div_two_sub_self (a : \u03b1) : a / 2 - a = - (a / 2) :=\nsuffices a / 2 - (a / 2 + a / 2) = - (a / 2), by rwa add_halves at this,\nby rw [sub_add_eq_sub_sub, sub_self, zero_sub]\n\nlemma add_self_div_two (a : \u03b1) : (a + a) / 2 = a :=\nby rw [\u2190 mul_two, mul_div_cancel a two_ne_zero]\n\nlemma half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two\n\nlemma one_half_pos : (0:\u03b1) < 1 / 2 := half_pos zero_lt_one\n\nlemma div_two_lt_of_pos (h : 0 < a) : a / 2 < a :=\nby { rw [div_lt_iff (@zero_lt_two \u03b1 _ _)], exact lt_mul_of_one_lt_right h one_lt_two }\n\nlemma half_lt_self : 0 < a \u2192 a / 2 < a := div_two_lt_of_pos\n\nlemma half_le_self (ha_nonneg : 0 \u2264 a) : a / 2 \u2264 a :=\nbegin\n  by_cases h0 : a = 0,\n  { simp [h0], },\n  { rw \u2190 ne.def at h0,\n    exact (half_lt_self (lt_of_le_of_ne ha_nonneg h0.symm)).le, },\nend\n\nlemma one_half_lt_one : (1 / 2 : \u03b1) < 1 := half_lt_self zero_lt_one\n\nlemma add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b :=\nbegin\n  rwa [\u2190 div_sub_div_same, sub_eq_add_neg, add_comm (b/2), \u2190 add_assoc, \u2190 sub_eq_add_neg,\n    \u2190 lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_right (@zero_lt_two \u03b1 _ _)]\nend\n\n\n/-!\n### Miscellaneous lemmas\n-/\n\n/-- Pullback a `linear_ordered_field` under an injective map. -/\ndef function.injective.linear_ordered_field {\u03b2 : Type*}\n  [has_zero \u03b2] [has_one \u03b2] [has_add \u03b2] [has_mul \u03b2] [has_neg \u03b2] [has_sub \u03b2] [has_inv \u03b2] [has_div \u03b2]\n  [nontrivial \u03b2]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : \u2200 x y, f (x + y) = f x + f y) (mul : \u2200 x y, f (x * y) = f x * f y)\n  (neg : \u2200 x, f (-x) = -f x) (sub : \u2200 x y, f (x - y) = f x - f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9) (div : \u2200 x y, f (x / y) = f x / f y) :\n  linear_ordered_field \u03b2 :=\n{ ..hf.linear_ordered_ring f zero one add mul neg sub,\n  ..hf.field f zero one add mul neg sub inv div}\n\nlemma mul_sub_mul_div_mul_neg_iff (hc : c \u2260 0) (hd : d \u2260 0) :\n  (a * d - b * c) / (c * d) < 0 \u2194 a / c < b / d :=\nby rw [mul_comm b c, \u2190 div_sub_div _ _ hc hd, sub_lt_zero]\n\nalias mul_sub_mul_div_mul_neg_iff \u2194 div_lt_div_of_mul_sub_mul_div_neg mul_sub_mul_div_mul_neg\n\nlemma mul_sub_mul_div_mul_nonpos_iff (hc : c \u2260 0) (hd : d \u2260 0) :\n      (a * d - b * c) / (c * d) \u2264 0 \u2194 a / c \u2264 b / d :=\nby rw [mul_comm b c, \u2190 div_sub_div _ _ hc hd, sub_nonpos]\n\nalias mul_sub_mul_div_mul_nonpos_iff \u2194\n  div_le_div_of_mul_sub_mul_div_nonpos mul_sub_mul_div_mul_nonpos\n\nlemma mul_le_mul_of_mul_div_le (h : a * (b / c) \u2264 d) (hc : 0 < c) : b * a \u2264 d * c :=\nbegin\n  rw [\u2190 mul_div_assoc] at h,\n  rwa [mul_comm b, \u2190 div_le_iff hc],\nend\n\nlemma div_mul_le_div_mul_of_div_le_div (h : a / b \u2264 c / d) (he : 0 \u2264 e) :\n  a / (b * e) \u2264 c / (d * e) :=\nbegin\n  rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div],\n  exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he)\nend\n\nlemma exists_add_lt_and_pos_of_lt (h : b < a) : \u2203 c : \u03b1, b + c < a \u2227 0 < c :=\n\u27e8(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two\u27e9\n\nlemma le_of_forall_sub_le (h : \u2200 \u03b5 > 0, b - \u03b5 \u2264 a) : b \u2264 a :=\nbegin\n  contrapose! h,\n  simpa only [and_comm ((0 : \u03b1) < _), lt_sub_iff_add_lt, gt_iff_lt]\n    using exists_add_lt_and_pos_of_lt h,\nend\n\nlemma monotone.div_const {\u03b2 : Type*} [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} (hf : monotone f)\n  {c : \u03b1} (hc : 0 \u2264 c) : monotone (\u03bb x, (f x) / c) :=\nby simpa only [div_eq_mul_inv] using hf.mul_const (inv_nonneg.2 hc)\n\nlemma strict_mono.div_const {\u03b2 : Type*} [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} (hf : strict_mono f)\n  {c : \u03b1} (hc : 0 < c) :\n  strict_mono (\u03bb x, (f x) / c) :=\nby simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_field.to_densely_ordered : densely_ordered \u03b1 :=\n{ dense := \u03bb a\u2081 a\u2082 h, \u27e8(a\u2081 + a\u2082) / 2,\n  calc a\u2081 = (a\u2081 + a\u2081) / 2 : (add_self_div_two a\u2081).symm\n      ... < (a\u2081 + a\u2082) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_left h _),\n  calc (a\u2081 + a\u2082) / 2 < (a\u2082 + a\u2082) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_right h _)\n                 ... = a\u2082            : add_self_div_two a\u2082\u27e9 }\n\nlemma mul_self_inj_of_nonneg (a0 : 0 \u2264 a) (b0 : 0 \u2264 b) : a * a = b * b \u2194 a = b :=\nmul_self_eq_mul_self_iff.trans $ or_iff_left_of_imp $\n  \u03bb h, by { subst a, have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0, rw [this, neg_zero] }\n\nlemma min_div_div_right {c : \u03b1} (hc : 0 \u2264 c) (a b : \u03b1) : min (a / c) (b / c) = (min a b) / c :=\neq.symm $ monotone.map_min (\u03bb x y, div_le_div_of_le hc)\n\nlemma max_div_div_right {c : \u03b1} (hc : 0 \u2264 c) (a b : \u03b1) : max (a / c) (b / c) = (max a b) / c :=\neq.symm $ monotone.map_max (\u03bb x y, div_le_div_of_le hc)\n\nlemma min_div_div_right_of_nonpos {c : \u03b1} (hc : c \u2264 0) (a b : \u03b1) :\n  min (a / c) (b / c) = (max a b) / c :=\neq.symm $ @monotone.map_max \u03b1 (order_dual \u03b1) _ _ _ _ _ (\u03bb x y, div_le_div_of_nonpos_of_le hc)\n\nlemma max_div_div_right_of_nonpos {c : \u03b1} (hc : c \u2264 0) (a b : \u03b1) :\n  max (a / c) (b / c) = (min a b) / c :=\neq.symm $ @monotone.map_min \u03b1 (order_dual \u03b1) _ _ _ _ _ (\u03bb x y, div_le_div_of_nonpos_of_le hc)\n\nlemma abs_div (a b : \u03b1) : abs (a / b) = abs a / abs b :=\n(abs_hom : monoid_with_zero_hom \u03b1 \u03b1).map_div a b\n\nlemma abs_one_div (a : \u03b1) : abs (1 / a) = 1 / abs a :=\nby rw [abs_div, abs_one]\n\nlemma abs_inv (a : \u03b1) : abs a\u207b\u00b9 = (abs a)\u207b\u00b9 :=\n(abs_hom : monoid_with_zero_hom \u03b1 \u03b1).map_inv' a\n\nend linear_ordered_field\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/ordered_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7084211603066277}}
{"text": "import measure_theory.interval_integral\nimport analysis.calculus.mean_value\n\nnoncomputable theory\n\nopen measure_theory set classical filter topological_space\nopen interval_integral\n\nopen_locale classical topological_space filter\n\nvariables {E : Type*} [measurable_space E] [normed_group E] \n                      [second_countable_topology E] [complete_space E] \n                      [normed_space \u211d E] [borel_space E]\nvariables {f : \u211d \u2192 \u211d} {a b : \u211d} \nvariables {f' g : \u211d \u2192 \u211d}\n\n-- Two cts functions with the same derivative in an interval and same initial\n-- value coincide in the whole interval.\ntheorem eq_of_deriv_eq\n  (contf : continuous_on f (Icc a b)) \n  (contg : continuous_on g (Icc a b))\n  (hfderiv : \u2200 x \u2208 Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)\n  (hgderiv : \u2200 x \u2208 Ico a b, has_deriv_within_at g (f' x) (Ioi x) x)\n  (hi : f a = g a) :\n  \u2200 y \u2208 Ico a b, f y = g y :=\nbegin\n  have hzero : \u2200 z \u2208 Ico a b, has_deriv_within_at (f - g) 0 (Ioi z) z,\n  { intros z hz,\n    convert has_deriv_within_at.sub (hfderiv z hz) (hgderiv z hz),\n    rw sub_self, },\n  have hbound : \u2200 z \u2208 Ico a b, \u2225(0 : \u211d)\u2225 \u2264 0 \n    := \u03bb _ _, by rw norm_le_zero_iff,\n  intros y hy,\n  have hnormle := norm_image_sub_le_of_norm_deriv_right_le_segment \n    (contf.sub contg) hzero hbound y (mem_Icc_of_Ico hy),\n  simpa [zero_mul, norm_le_zero_iff, sub_eq_zero, sub_eq_zero.mpr hi] using hnormle,\nend\n\n-- Has derivative from the right.\nlemma deriv_integral_right\n  (contf' : continuous f')\n  (derivf : \u2200 x \u2208 Ico a b, has_deriv_within_at f (f' x) (Ioi x) x) \n  (intgf' : \u2200 x \u2208 Icc a b, interval_integrable f' volume a x) :\n  \u2200 x \u2208 Ico a b, \n  has_deriv_within_at (\u03bb u, \u222b y in a..u, f' y) (f' x) (Ioi x) x :=\nbegin \n  intros x hx,\n  have intgf'r := intgf' x (mem_Icc_of_Ico hx),\n  have hderivci := @integral_has_deriv_within_at_right \n    _ _ _ _ _ _ _ _ _ _ intgf'r _ _ (FTC_filter.nhds_right x)\n    (continuous.continuous_within_at contf'),\n  have hderivxb := has_deriv_within_at.mono hderivci (@Icc_subset_Ici_self _ _ x b),\n  refine has_deriv_within_at.nhds_within hderivxb _,\n  apply Icc_mem_nhds_within_Ioi,\n  exact \u27e8le_refl x, hx.2\u27e9,\nend \n\n-- Benjamin's lemma. We should put it and versions of it in mathlib.\nlemma integral_sub_at_right \n  (a c d : \u211d) \n  (h1 : interval_integrable f' volume a d) \n  (h2 : interval_integrable f' volume a c) :\n  (\u222b (y : \u211d) in a..d, f' y) - \u222b (y : \u211d) in a..c, f' y = \u222b (y : \u211d) in c..d, f' y :=\nby rw [integral_interval_sub_interval_comm' h1 h2\n      (interval_integrable.refl (interval_integrable.measurable h1)), integral_same, sub_zero]\n\n-- TODO: Move\nlemma eventually_le_of_eq {\u03b1 \u03b2 : Type*} [preorder \u03b2] (l : filter \u03b1) (f g : \u03b1 \u2192 \u03b2) (h : f =\u1da0[l] g)\n: f \u2264\u1da0[l] g := \neventually_le.congr (eventually_le.refl _ _) (eventually_eq.refl _ _) h\n\n-- Second part of the Fundamental Theorem of Calculus.\ntheorem ftc2\n  (contf : continuous_on f (Icc a b)) \n  (contf' : continuous f')\n  (derivf : \u2200 x \u2208 Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)\n  (intgf' : \u2200 x \u2208 Icc a b, interval_integrable f' volume a x) :\n  \u2200 x \u2208 Ico a b, \u222b y in a..x, f' y = f x - f a :=\nbegin\n    intros x hx, \n    by_cases hab : b < a, \n    { have hc := lt_of_le_of_lt hx.1 (lt_trans hx.2 hab), \n      exfalso, exact lt_irrefl _ hc, },\n    -- We know a \u2264 b.\n    replace hab := le_of_not_lt hab,\n    have hbab : b \u2208 Icc a b := \u27e8hab, le_refl b\u27e9,\n    -- Needed to apply extreme value theorem.\n    have hneab := nonempty_Icc.2 hab,\n    have hcmpab := @compact_Icc a b,\n    have hctsnorm : continuous_on (\u03bb x, \u2225f' x\u2225) (Icc a b),\n    { apply continuous.continuous_on,\n      exact continuous.norm contf', },\n    have hfbdd := is_compact.exists_forall_ge hcmpab hneab hctsnorm,\n    apply eq_sub_of_add_eq, symmetry,\n    -- Derivative of integral of the derivative is the derivative.\n    have derivint : \u2200 z \u2208 Ico a b, \n      has_deriv_within_at (\u03bb u, (\u222b y in a..u, f' y) + f a) (f' z) (Ioi z) z,\n    { intros y hy, apply has_deriv_within_at.add_const,\n      exact (deriv_integral_right contf' derivf intgf' y hy), },\n    -- Ready to apply main result. Only thing missing is continuity.\n    refine (eq_of_deriv_eq contf _ derivf derivint _) x hx,\n    { refine continuous_on.add _ continuous_on_const,\n      rcases hfbdd with \u27e8z, hzab, hzbd\u27e9,\n      by_cases hfz : \u2225f' z\u2225 \u2264 0,\n      { -- If it is nonpositive, the function is zero on [a, b] and everything follows.\n        replace hfz := le_antisymm hfz (norm_nonneg (f' z)),\n        have hzero : \u2200 y \u2208 Icc a b, f' y = 0,\n        { intros y hy, apply norm_le_zero_iff.1,\n          specialize hzbd y hy, dsimp at hzbd, \n          rw hfz at hzbd, exact hzbd, },\n        have hrestrictint : restrict (\u03bb x, \u222b y in a..x, f' y) (Icc a b) = \u03bb x, 0,\n        { funext v, show \u222b y in a..v.val, f' y = 0,\n          have eventzero : f' =\u1d50[volume.restrict (Ioc a v.val)] 0,\n          { rw eventually_eq_iff_exists_mem, use [Ioc a v.val], split,\n            { simp, use univ, split,\n              { show volume univ\u1d9c = 0, rw compl_univ, simp, }, \n              { use [Ioc a v.val], split,\n                { exact subset.refl _, },\n                { erw [univ_inter _], exact subset.refl _, }, }, },\n            { intros w hw,\n              rw [hzero w \u27e8le_of_lt hw.1, le_trans hw.2 v.2.2\u27e9], refl, }, },\n          rw integral_eq_zero_iff_of_le_of_nonneg_ae v.2.1,\n          { exact eventzero, },\n          { apply @eventually_le.congr _ _ _ _ 0 0 0 f',\n            { exact eventually_le.refl _ _, },\n            { exact eventually_eq.refl _ _, },\n            { exact (eventually_eq.symm eventzero), }, },\n          { exact (intgf' v.1 v.2), }, },\n        rw continuous_on_iff_continuous_restrict,\n        erw hrestrictint, exact continuous_const, }, \n      replace hfz := lt_of_not_ge hfz,\n      -- Prove from first principles...\n      rw metric.continuous_on_iff, intros c hc \u03b5 h\u03b5, \n      -- Choose appropriate \u03b4.\n      let \u03b4 := \u03b5 / \u2225f' z\u2225,\n      have h\u03b4 : 0 < \u03b4 := div_pos h\u03b5 hfz,\n      use [\u03b4, h\u03b4], intros d hd hdist, rw [dist_eq_norm],\n      calc \u2225(\u222b (y : \u211d) in a..d, f' y) - \u222b (y : \u211d) in a..c, f' y\u2225 \n          -- Apply subtraction lemma.\n          = \u2225\u222b (y : \u211d) in c..d, f' y\u2225 \n          : begin \n              apply congr_arg norm,\n              exact (integral_sub_at_right a c d (intgf' d hd) (intgf' c hc)),\n            end\n            -- Since the norm of f' is bounded, its integral is bounded.\n      ... \u2264 \u2225f' z\u2225 * abs (d - c)\n          : begin \n              apply interval_integral.norm_integral_le_of_norm_le_const,\n              intros w hw, by_cases hcd : c \u2264 d,\n              { rw [min_eq_left hcd, max_eq_right hcd] at hw,\n                have haw : a \u2264 w := le_of_lt (lt_of_le_of_lt hc.1 hw.1),\n                have hwb : w \u2264 b := le_trans hw.2 hd.2,\n                exact hzbd w \u27e8haw, hwb\u27e9, },\n              { replace hcd := le_of_not_le hcd,\n                rw [min_eq_right hcd, max_eq_left hcd] at hw,\n                have haw : a \u2264 w := le_of_lt (lt_of_le_of_lt hd.1 hw.1),\n                have hwb : w \u2264 b := le_trans hw.2 hc.2,\n                exact hzbd w \u27e8haw, hwb\u27e9, },\n            end\n            -- abs is just dist.\n      ... = \u2225f' z\u2225 * dist d c \n          : by rw [dist_eq_norm, real.norm_eq_abs (d - c), abs_sub d c]\n            -- dist is less than \u03b4 by assumption.\n      ... < \u2225f' z\u2225 * \u03b4 \n          : mul_lt_mul_of_pos_left hdist hfz\n            -- and it was convenientyly chosen so that the whole thing is less than \u03b5. \n      ... = \u03b5\n          : begin \n              erw \u2190mul_div_assoc,\n              exact mul_div_cancel_left \u03b5 (ne_of_gt hfz), \n            end, },\n    { simp only [integral_same, zero_add], },\nend \n", "meta": {"author": "ramonfmir", "repo": "lean-experiments", "sha": "041c8727bb540fb8d1519c1ad84924d473885c27", "save_path": "github-repos/lean/ramonfmir-lean-experiments", "path": "github-repos/lean/ramonfmir-lean-experiments/lean-experiments-041c8727bb540fb8d1519c1ad84924d473885c27/src/picard_lindelof/other/ftc2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.708421156990156}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\nimport algebra.hom.equiv\nimport data.zmod.basic\nimport tactic.group\n\n/-!\n# Racks and Quandles\n\nThis file defines racks and quandles, algebraic structures for sets\nthat bijectively act on themselves with a self-distributivity\nproperty.  If `R` is a rack and `act : R \u2192 (R \u2243 R)` is the self-action,\nthen the self-distributivity is, equivalently, that\n```\nact (act x y) = act x * act y * (act x)\u207b\u00b9\n```\nwhere multiplication is composition in `R \u2243 R` as a group.\nQuandles are racks such that `act x x = x` for all `x`.\n\nOne example of a quandle (not yet in mathlib) is the action of a Lie\nalgebra on itself, defined by `act x y = Ad (exp x) y`.\n\nQuandles and racks were independently developed by multiple\nmathematicians.  David Joyce introduced quandles in his thesis\n[Joyce1982] to define an algebraic invariant of knot and link\ncomplements that is analogous to the fundamental group of the\nexterior, and he showed that the quandle associated to an oriented\nknot is invariant up to orientation-reversed mirror image.  Racks were\nused by Fenn and Rourke for framed codimension-2 knots and\nlinks.[FennRourke1992]\n\nThe name \"rack\" came from wordplay by Conway and Wraith for the \"wrack\nand ruin\" of forgetting everything but the conjugation operation for a\ngroup.\n\n## Main definitions\n\n* `shelf` is a type with a self-distributive action\n* `rack` is a shelf whose action for each element is invertible\n* `quandle` is a rack whose action for an element fixes that element\n* `quandle.conj` defines a quandle of a group acting on itself by conjugation.\n* `shelf_hom` is homomorphisms of shelves, racks, and quandles.\n* `rack.envel_group` gives the universal group the rack maps to as a conjugation quandle.\n* `rack.opp` gives the rack with the action replaced by its inverse.\n\n## Main statements\n* `rack.envel_group` is left adjoint to `quandle.conj` (`to_envel_group.map`).\n  The universality statements are `to_envel_group.univ` and `to_envel_group.univ_uniq`.\n\n## Notation\n\nThe following notation is localized in `quandles`:\n\n* `x \u25c3 y` is `shelf.act x y`\n* `x \u25c3\u207b\u00b9 y` is `rack.inv_act x y`\n* `S \u2192\u25c3 S'` is `shelf_hom S S'`\n\nUse `open_locale quandles` to use these.\n\n## Todo\n\n* If `g` is the Lie algebra of a Lie group `G`, then `(x \u25c3 y) = Ad (exp x) x` forms a quandle.\n* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,\n  forming a quandle.\n* Alexander quandle with `a \u25c3 b = t * b + (1 - t) * b`, with `a` and `b` elements\n  of a module over `Z[t,t\u207b\u00b9]`.\n* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by\n  `yH \u25c3 xH = yzy\u207b\u00b9xH`.  Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts\n  transitively on `Q` as a set) is isomorphic to such a quandle.\n  There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].\n\n## Tags\n\nrack, quandle\n-/\nopen mul_opposite\n\nuniverses u v\n\n/--\nA *shelf* is a structure with a self-distributive binary operation.\nThe binary operation is regarded as a left action of the type on itself.\n-/\nclass shelf (\u03b1 : Type u) :=\n(act : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(self_distrib : \u2200 {x y z : \u03b1}, act x (act y z) = act (act x y) (act x z))\n\n/--\nThe type of homomorphisms between shelves.\nThis is also the notion of rack and quandle homomorphisms.\n-/\n@[ext]\nstructure shelf_hom (S\u2081 : Type*) (S\u2082 : Type*) [shelf S\u2081] [shelf S\u2082] :=\n(to_fun : S\u2081 \u2192 S\u2082)\n(map_act' : \u2200 {x y : S\u2081}, to_fun (shelf.act x y) = shelf.act (to_fun x) (to_fun y))\n\n/--\nA *rack* is an automorphic set (a set with an action on itself by\nbijections) that is self-distributive.  It is a shelf such that each\nelement's action is invertible.\n\nThe notations `x \u25c3 y` and `x \u25c3\u207b\u00b9 y` denote the action and the\ninverse action, respectively, and they are right associative.\n-/\nclass rack (\u03b1 : Type u) extends shelf \u03b1 :=\n(inv_act : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(left_inv : \u2200 x, function.left_inverse (inv_act x) (act x))\n(right_inv : \u2200 x, function.right_inverse (inv_act x) (act x))\n\nlocalized \"infixr ` \u25c3 `:65 := shelf.act\" in quandles\nlocalized \"infixr ` \u25c3\u207b\u00b9 `:65 := rack.inv_act\" in quandles\nlocalized \"infixr ` \u2192\u25c3 `:25 := shelf_hom\" in quandles\n\nopen_locale quandles\n\nnamespace rack\nvariables {R : Type*} [rack R]\n\nlemma self_distrib {x y z : R} : x \u25c3 (y \u25c3 z) = (x \u25c3 y) \u25c3 (x \u25c3 z) :=\nshelf.self_distrib\n\n/--\nA rack acts on itself by equivalences.\n-/\ndef act (x : R) : R \u2243 R :=\n{ to_fun := shelf.act x,\n  inv_fun := inv_act x,\n  left_inv := left_inv x,\n  right_inv := right_inv x }\n\n@[simp] lemma act_apply (x y : R) : act x y = x \u25c3 y := rfl\n@[simp] lemma act_symm_apply (x y : R) : (act x).symm y = x \u25c3\u207b\u00b9 y := rfl\n@[simp] lemma inv_act_apply (x y : R) : (act x)\u207b\u00b9 y = x \u25c3\u207b\u00b9 y := rfl\n\n@[simp] lemma inv_act_act_eq (x y : R) : x \u25c3\u207b\u00b9 x \u25c3 y = y := left_inv x y\n@[simp] lemma act_inv_act_eq (x y : R) : x \u25c3 x \u25c3\u207b\u00b9 y = y := right_inv x y\n\nlemma left_cancel (x : R) {y y' : R} : x \u25c3 y = x \u25c3 y' \u2194 y = y' :=\nby { split, apply (act x).injective, rintro rfl, refl }\n\nlemma left_cancel_inv (x : R) {y y' : R} : x \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y' \u2194 y = y' :=\nby { split, apply (act x).symm.injective, rintro rfl, refl }\n\nlemma self_distrib_inv {x y z : R} : x \u25c3\u207b\u00b9 y \u25c3\u207b\u00b9 z = (x \u25c3\u207b\u00b9 y) \u25c3\u207b\u00b9 (x \u25c3\u207b\u00b9 z) :=\nbegin\n  rw [\u2190left_cancel (x \u25c3\u207b\u00b9 y), right_inv, \u2190left_cancel x, right_inv, self_distrib],\n  repeat {rw right_inv },\nend\n\n/--\nThe *adjoint action* of a rack on itself is `op'`, and the adjoint\naction of `x \u25c3 y` is the conjugate of the action of `y` by the action\nof `x`. It is another way to understand the self-distributivity axiom.\n\nThis is used in the natural rack homomorphism `to_conj` from `R` to\n`conj (R \u2243 R)` defined by `op'`.\n-/\nlemma ad_conj {R : Type*} [rack R] (x y : R) :\n  act (x \u25c3 y) = act x * act y * (act x)\u207b\u00b9 :=\nbegin\n  apply @mul_right_cancel _ _ _ (act x), ext z,\n  simp only [inv_mul_cancel_right],\n  apply self_distrib.symm,\nend\n\n/--\nThe opposite rack, swapping the roles of `\u25c3` and `\u25c3\u207b\u00b9`.\n-/\ninstance opposite_rack : rack R\u1d50\u1d52\u1d56 :=\n{ act := \u03bb x y, op (inv_act (unop x) (unop y)),\n  self_distrib := mul_opposite.rec $ \u03bb x, mul_opposite.rec $ \u03bb y, mul_opposite.rec $ \u03bb z, begin\n    simp only [unop_op, op_inj],\n    exact self_distrib_inv,\n  end,\n  inv_act := \u03bb x y, op (shelf.act (unop x) (unop y)),\n  left_inv := mul_opposite.rec $ \u03bb x, mul_opposite.rec $ \u03bb y, by simp,\n  right_inv := mul_opposite.rec $ \u03bb x, mul_opposite.rec $ \u03bb y, by simp }\n\n@[simp] lemma op_act_op_eq {x y : R} : (op x) \u25c3 (op y) = op (x \u25c3\u207b\u00b9 y) := rfl\n@[simp] lemma op_inv_act_op_eq {x y : R} : (op x) \u25c3\u207b\u00b9 (op y) = op (x \u25c3 y) := rfl\n\n@[simp]\nlemma self_act_act_eq {x y : R} : (x \u25c3 x) \u25c3 y = x \u25c3 y :=\nby { rw [\u2190right_inv x y, \u2190self_distrib] }\n\n@[simp]\nlemma self_inv_act_inv_act_eq {x y : R} : (x \u25c3\u207b\u00b9 x) \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y :=\nby { have h := @self_act_act_eq _ _ (op x) (op y), simpa using h }\n\n@[simp]\nlemma self_act_inv_act_eq {x y : R} : (x \u25c3 x) \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y :=\nby { rw \u2190left_cancel (x \u25c3 x), rw right_inv, rw self_act_act_eq, rw right_inv }\n\n@[simp]\nlemma self_inv_act_act_eq {x y : R} : (x \u25c3\u207b\u00b9 x) \u25c3 y = x \u25c3 y :=\nby { have h := @self_act_inv_act_eq _ _ (op x) (op y), simpa using h }\n\nlemma self_act_eq_iff_eq {x y : R} : x \u25c3 x = y \u25c3 y \u2194 x = y :=\nbegin\n  split, swap, rintro rfl, refl,\n  intro h,\n  transitivity (x \u25c3 x) \u25c3\u207b\u00b9 (x \u25c3 x),\n  rw [\u2190left_cancel (x \u25c3 x), right_inv, self_act_act_eq],\n  rw [h, \u2190left_cancel (y \u25c3 y), right_inv, self_act_act_eq],\nend\n\nlemma self_inv_act_eq_iff_eq {x y : R} : x \u25c3\u207b\u00b9 x = y \u25c3\u207b\u00b9 y \u2194 x = y :=\nby { have h := @self_act_eq_iff_eq _ _ (op x) (op y), simpa using h }\n\n/--\nThe map `x \u21a6 x \u25c3 x` is a bijection.  (This has applications for the\nregular isotopy version of the Reidemeister I move for knot diagrams.)\n-/\ndef self_apply_equiv (R : Type*) [rack R] : R \u2243 R :=\n{ to_fun := \u03bb x, x \u25c3 x,\n  inv_fun := \u03bb x, x \u25c3\u207b\u00b9 x,\n  left_inv := \u03bb x, by simp,\n  right_inv := \u03bb x, by simp }\n\n/--\nAn involutory rack is one for which `rack.op R x` is an involution for every x.\n-/\ndef is_involutory (R : Type*) [rack R] : Prop := \u2200 x : R, function.involutive (shelf.act x)\n\nlemma involutory_inv_act_eq_act {R : Type*} [rack R] (h : is_involutory R) (x y : R) :\n  x \u25c3\u207b\u00b9 y = x \u25c3 y :=\nbegin\n  rw [\u2190left_cancel x, right_inv],\n  exact ((h x).left_inverse y).symm,\nend\n\n/--\nAn abelian rack is one for which the mediality axiom holds.\n-/\ndef is_abelian (R : Type*) [rack R] : Prop :=\n\u2200 (x y z w : R), (x \u25c3 y) \u25c3 (z \u25c3 w) = (x \u25c3 z) \u25c3 (y \u25c3 w)\n\n/--\nAssociative racks are uninteresting.\n-/\nlemma assoc_iff_id {R : Type*} [rack R] {x y z : R} :\n  x \u25c3 y \u25c3 z = (x \u25c3 y) \u25c3 z \u2194 x \u25c3 z = z :=\nby { rw self_distrib, rw left_cancel }\n\nend rack\n\nnamespace shelf_hom\nvariables {S\u2081 : Type*} {S\u2082 : Type*} {S\u2083 : Type*} [shelf S\u2081] [shelf S\u2082] [shelf S\u2083]\n\ninstance : has_coe_to_fun (S\u2081 \u2192\u25c3 S\u2082) (\u03bb _, S\u2081 \u2192 S\u2082) := \u27e8shelf_hom.to_fun\u27e9\n\n@[simp] lemma to_fun_eq_coe (f : S\u2081 \u2192\u25c3 S\u2082) : f.to_fun = f := rfl\n\n@[simp] lemma map_act (f : S\u2081 \u2192\u25c3 S\u2082) {x y : S\u2081} : f (x \u25c3 y) = f x \u25c3 f y := map_act' f\n\n/-- The identity homomorphism -/\ndef id (S : Type*) [shelf S] : S \u2192\u25c3 S :=\n{ to_fun := id,\n  map_act' := by simp }\n\ninstance inhabited (S : Type*) [shelf S] : inhabited (S \u2192\u25c3 S) :=\n\u27e8id S\u27e9\n\n/-- The composition of shelf homomorphisms -/\ndef comp (g : S\u2082 \u2192\u25c3 S\u2083) (f : S\u2081 \u2192\u25c3 S\u2082) : S\u2081 \u2192\u25c3 S\u2083 :=\n{ to_fun := g.to_fun \u2218 f.to_fun,\n  map_act' := by simp }\n\n@[simp]\nlemma comp_apply (g : S\u2082 \u2192\u25c3 S\u2083) (f : S\u2081 \u2192\u25c3 S\u2082) (x : S\u2081) :\n  (g.comp f) x = g (f x) := rfl\n\nend shelf_hom\n\n/--\nA quandle is a rack such that each automorphism fixes its corresponding element.\n-/\nclass quandle (\u03b1 : Type*) extends rack \u03b1 :=\n(fix : \u2200 {x : \u03b1}, act x x = x)\n\nnamespace quandle\nopen rack\nvariables {Q : Type*} [quandle Q]\n\nattribute [simp] fix\n\n@[simp]\nlemma fix_inv {x : Q} : x \u25c3\u207b\u00b9 x = x :=\nby { rw \u2190left_cancel x, simp }\n\ninstance opposite_quandle : quandle Q\u1d50\u1d52\u1d56 :=\n{ fix := \u03bb x, by { induction x using mul_opposite.rec, simp } }\n\n/--\nThe conjugation quandle of a group.  Each element of the group acts by\nthe corresponding inner automorphism.\n-/\n@[nolint has_inhabited_instance]\ndef conj (G : Type*) := G\n\ninstance conj.quandle (G : Type*) [group G] : quandle (conj G) :=\n{ act := (\u03bb x, @mul_aut.conj G _ x),\n  self_distrib := \u03bb x y z, begin\n    dsimp only [mul_equiv.coe_to_equiv, mul_aut.conj_apply, conj],\n    group,\n  end,\n  inv_act := (\u03bb x, (@mul_aut.conj G _ x).symm),\n  left_inv := \u03bb x y, by { dsimp [act, conj], group },\n  right_inv := \u03bb x y, by { dsimp [act, conj], group },\n  fix := \u03bb x, by simp }\n\n@[simp]\nlemma conj_act_eq_conj {G : Type*} [group G] (x y : conj G) :\n  x \u25c3 y = ((x : G) * (y : G) * (x : G)\u207b\u00b9 : G) := rfl\n\nlemma conj_swap {G : Type*} [group G] (x y : conj G) :\n  x \u25c3 y = y \u2194 y \u25c3 x = x :=\nbegin\n  dsimp [conj] at *, split,\n  repeat { intro h, conv_rhs { rw eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h) }, simp, },\nend\n\n/--\n`conj` is functorial\n-/\ndef conj.map {G : Type*} {H : Type*} [group G] [group H] (f : G \u2192* H) : conj G \u2192\u25c3 conj H :=\n{ to_fun := f,\n  map_act' := by simp }\n\ninstance {G : Type*} {H : Type*} [group G] [group H] : has_lift (G \u2192* H) (conj G \u2192\u25c3 conj H) :=\n{ lift := conj.map }\n\n/--\nThe dihedral quandle. This is the conjugation quandle of the dihedral group restrict to flips.\n\nUsed for Fox n-colorings of knots.\n-/\n@[nolint has_inhabited_instance]\ndef dihedral (n : \u2115) := zmod n\n\n/--\nThe operation for the dihedral quandle.  It does not need to be an equivalence\nbecause it is an involution (see `dihedral_act.inv`).\n-/\ndef dihedral_act (n : \u2115) (a : zmod n) : zmod n \u2192 zmod n :=\n\u03bb b, 2 * a - b\n\nlemma dihedral_act.inv (n : \u2115) (a : zmod n) : function.involutive (dihedral_act n a) :=\nby { intro b, dsimp [dihedral_act], ring }\n\ninstance (n : \u2115) : quandle (dihedral n) :=\n{ act := dihedral_act n,\n  self_distrib := \u03bb x y z, begin\n    dsimp [dihedral_act], ring,\n  end,\n  inv_act := dihedral_act n,\n  left_inv := \u03bb x, (dihedral_act.inv n x).left_inverse,\n  right_inv := \u03bb x, (dihedral_act.inv n x).right_inverse,\n  fix := \u03bb x, begin\n    dsimp [dihedral_act], ring,\n  end }\n\nend quandle\n\nnamespace rack\n\n/--\nThis is the natural rack homomorphism to the conjugation quandle of the group `R \u2243 R`\nthat acts on the rack.\n-/\ndef to_conj (R : Type*) [rack R] : R \u2192\u25c3 quandle.conj (R \u2243 R) :=\n{ to_fun := act,\n  map_act' := ad_conj }\n\nsection envel_group\n\n/-!\n### Universal enveloping group of a rack\n\nThe universal enveloping group `envel_group R` of a rack `R` is the\nuniversal group such that every rack homomorphism `R \u2192\u25c3 conj G` is\ninduced by a unique group homomorphism `envel_group R \u2192* G`.\nFor quandles, Joyce called this group `AdConj R`.\n\nThe `envel_group` functor is left adjoint to the `conj` forgetful\nfunctor, and the way we construct the enveloping group is via a\ntechnique that should work for left adjoints of forgetful functors in\ngeneral.  It involves thinking a little about 2-categories, but the\npayoff is that the map `envel_group R \u2192* G` has a nice description.\n\nLet's think of a group as being a one-object category.  The first step\nis to define `pre_envel_group`, which gives formal expressions for all\nthe 1-morphisms and includes the unit element, elements of `R`,\nmultiplication, and inverses.  To introduce relations, the second step\nis to define `pre_envel_group_rel'`, which gives formal expressions\nfor all 2-morphisms between the 1-morphisms.  The 2-morphisms include\nassociativity, multiplication by the unit, multiplication by inverses,\ncompatibility with multiplication and inverses (`congr_mul` and\n`congr_inv`), the axioms for an equivalence relation, and,\nimportantly, the relationship between conjugation and the rack action\n(see `rack.ad_conj`).\n\nNone of this forms a 2-category yet, for example due to lack of\nassociativity of `trans`.  The `pre_envel_group_rel` relation is a\n`Prop`-valued version of `pre_envel_group_rel'`, and making it\n`Prop`-valued essentially introduces enough 3-isomorphisms so that\nevery pair of compatible 2-morphisms is isomorphic.  Now, while\ncomposition in `pre_envel_group` does not strictly satisfy the category\naxioms, `pre_envel_group` and `pre_envel_group_rel'` do form a weak\n2-category.\n\nSince we just want a 1-category, the last step is to quotient\n`pre_envel_group` by `pre_envel_group_rel'`, and the result is the\ngroup `envel_group`.\n\nFor a homomorphism `f : R \u2192\u25c3 conj G`, how does\n`envel_group.map f : envel_group R \u2192* G` work?  Let's think of `G` as\nbeing a 2-category with one object, a 1-morphism per element of `G`,\nand a single 2-morphism called `eq.refl` for each 1-morphism.  We\ndefine the map using a \"higher `quotient.lift`\" -- not only do we\nevaluate elements of `pre_envel_group` as expressions in `G` (this is\n`to_envel_group.map_aux`), but we evaluate elements of\n`pre_envel_group'` as expressions of 2-morphisms of `G` (this is\n`to_envel_group.map_aux.well_def`).  That is to say,\n`to_envel_group.map_aux.well_def` recursively evaluates formal\nexpressions of 2-morphisms as equality proofs in `G`.  Now that all\nmorphisms are accounted for, the map descends to a homomorphism\n`envel_group R \u2192* G`.\n\nNote: `Type`-valued relations are not common.  The fact it is\n`Type`-valued is what makes `to_envel_group.map_aux.well_def` have\nwell-founded recursion.\n-/\n\n/--\nFree generators of the enveloping group.\n-/\ninductive pre_envel_group (R : Type u) : Type u\n| unit : pre_envel_group\n| incl (x : R) : pre_envel_group\n| mul (a b : pre_envel_group) : pre_envel_group\n| inv (a : pre_envel_group) : pre_envel_group\n\ninstance pre_envel_group.inhabited (R : Type u) : inhabited (pre_envel_group R) :=\n\u27e8pre_envel_group.unit\u27e9\n\nopen pre_envel_group\n\n/--\nRelations for the enveloping group. This is a type-valued relation because\n`to_envel_group.map_aux.well_def` inducts on it to show `to_envel_group.map`\nis well-defined.  The relation `pre_envel_group_rel` is the `Prop`-valued version,\nwhich is used to define `envel_group` itself.\n-/\ninductive pre_envel_group_rel' (R : Type u) [rack R] :\n  pre_envel_group R \u2192 pre_envel_group R \u2192 Type u\n| refl {a : pre_envel_group R} : pre_envel_group_rel' a a\n| symm {a b : pre_envel_group R} (hab : pre_envel_group_rel' a b) : pre_envel_group_rel' b a\n| trans {a b c : pre_envel_group R}\n  (hab : pre_envel_group_rel' a b) (hbc : pre_envel_group_rel' b c) : pre_envel_group_rel' a c\n| congr_mul {a b a' b' : pre_envel_group R}\n  (ha : pre_envel_group_rel' a a') (hb : pre_envel_group_rel' b b') :\n  pre_envel_group_rel' (mul a b) (mul a' b')\n| congr_inv {a a' : pre_envel_group R} (ha : pre_envel_group_rel' a a') :\n  pre_envel_group_rel' (inv a) (inv a')\n| assoc (a b c : pre_envel_group R) : pre_envel_group_rel' (mul (mul a b) c) (mul a (mul b c))\n| one_mul (a : pre_envel_group R) : pre_envel_group_rel' (mul unit a) a\n| mul_one (a : pre_envel_group R) : pre_envel_group_rel' (mul a unit) a\n| mul_left_inv (a : pre_envel_group R) : pre_envel_group_rel' (mul (inv a) a) unit\n| act_incl (x y : R) :\n  pre_envel_group_rel' (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x \u25c3 y))\n\ninstance pre_envel_group_rel'.inhabited (R : Type u) [rack R] :\n  inhabited (pre_envel_group_rel' R unit unit) :=\n\u27e8pre_envel_group_rel'.refl\u27e9\n\n/--\nThe `pre_envel_group_rel` relation as a `Prop`.  Used as the relation for `pre_envel_group.setoid`.\n-/\ninductive pre_envel_group_rel (R : Type u) [rack R] : pre_envel_group R \u2192 pre_envel_group R \u2192 Prop\n| rel {a b : pre_envel_group R} (r : pre_envel_group_rel' R a b) : pre_envel_group_rel a b\n\n/--\nA quick way to convert a `pre_envel_group_rel'` to a `pre_envel_group_rel`.\n-/\nlemma pre_envel_group_rel'.rel {R : Type u} [rack R] {a b : pre_envel_group R} :\n  pre_envel_group_rel' R a b \u2192 pre_envel_group_rel R a b :=\npre_envel_group_rel.rel\n\n@[refl]\nlemma pre_envel_group_rel.refl {R : Type u} [rack R] {a : pre_envel_group R} :\n  pre_envel_group_rel R a a :=\npre_envel_group_rel.rel pre_envel_group_rel'.refl\n\n@[symm]\nlemma pre_envel_group_rel.symm {R : Type u} [rack R] {a b : pre_envel_group R} :\n  pre_envel_group_rel R a b \u2192 pre_envel_group_rel R b a\n| \u27e8r\u27e9 := r.symm.rel\n\n@[trans]\nlemma pre_envel_group_rel.trans {R : Type u} [rack R] {a b c : pre_envel_group R} :\n  pre_envel_group_rel R a b \u2192 pre_envel_group_rel R b c \u2192 pre_envel_group_rel R a c\n| \u27e8rab\u27e9 \u27e8rbc\u27e9 := (rab.trans rbc).rel\n\ninstance pre_envel_group.setoid (R : Type*) [rack R] : setoid (pre_envel_group R) :=\n{ r := pre_envel_group_rel R,\n  iseqv := begin\n    split, apply pre_envel_group_rel.refl,\n    split, apply pre_envel_group_rel.symm,\n    apply pre_envel_group_rel.trans\n  end }\n\n/--\nThe universal enveloping group for the rack R.\n-/\ndef envel_group (R : Type*) [rack R] := quotient (pre_envel_group.setoid R)\n\n-- Define the `group` instances in two steps so `inv` can be inferred correctly.\n-- TODO: is there a non-invasive way of defining the instance directly?\ninstance (R : Type*) [rack R] : div_inv_monoid (envel_group R) :=\n{ mul := \u03bb a b, quotient.lift_on\u2082 a b\n                  (\u03bb a b, \u27e6pre_envel_group.mul a b\u27e7)\n                  (\u03bb a b a' b' \u27e8ha\u27e9 \u27e8hb\u27e9,\n                    quotient.sound (pre_envel_group_rel'.congr_mul ha hb).rel),\n  one := \u27e6unit\u27e7,\n  inv := \u03bb a, quotient.lift_on a\n                (\u03bb a, \u27e6pre_envel_group.inv a\u27e7)\n                (\u03bb a a' \u27e8ha\u27e9,\n                  quotient.sound (pre_envel_group_rel'.congr_inv ha).rel),\n  mul_assoc := \u03bb a b c,\n    quotient.induction_on\u2083 a b c (\u03bb a b c, quotient.sound (pre_envel_group_rel'.assoc a b c).rel),\n  one_mul := \u03bb a,\n    quotient.induction_on a (\u03bb a, quotient.sound (pre_envel_group_rel'.one_mul a).rel),\n  mul_one := \u03bb a,\n    quotient.induction_on a (\u03bb a, quotient.sound (pre_envel_group_rel'.mul_one a).rel),}\n\ninstance (R : Type*) [rack R] : group (envel_group R) :=\n{ mul_left_inv := \u03bb a,\n    quotient.induction_on a (\u03bb a, quotient.sound (pre_envel_group_rel'.mul_left_inv a).rel),\n  .. envel_group.div_inv_monoid _ }\n\ninstance envel_group.inhabited (R : Type*) [rack R] : inhabited (envel_group R) := \u27e81\u27e9\n\n/--\nThe canonical homomorphism from a rack to its enveloping group.\nSatisfies universal properties given by `to_envel_group.map` and `to_envel_group.univ`.\n-/\ndef to_envel_group (R : Type*) [rack R] : R \u2192\u25c3 quandle.conj (envel_group R) :=\n{ to_fun := \u03bb x, \u27e6incl x\u27e7,\n  map_act' := \u03bb x y, quotient.sound (pre_envel_group_rel'.act_incl x y).symm.rel }\n\n/--\nThe preliminary definition of the induced map from the enveloping group.\nSee `to_envel_group.map`.\n-/\ndef to_envel_group.map_aux {R : Type*} [rack R] {G : Type*} [group G]\n  (f : R \u2192\u25c3 quandle.conj G) : pre_envel_group R \u2192 G\n| unit := 1\n| (incl x) := f x\n| (mul a b) := to_envel_group.map_aux a * to_envel_group.map_aux b\n| (inv a) := (to_envel_group.map_aux a)\u207b\u00b9\n\nnamespace to_envel_group.map_aux\nopen pre_envel_group_rel'\n\n/--\nShow that `to_envel_group.map_aux` sends equivalent expressions to equal terms.\n-/\nlemma well_def {R : Type*} [rack R] {G : Type*} [group G] (f : R \u2192\u25c3 quandle.conj G) :\n  \u03a0 {a b : pre_envel_group R}, pre_envel_group_rel' R a b \u2192\n  to_envel_group.map_aux f a = to_envel_group.map_aux f b\n| a b refl := rfl\n| a b (symm h) := (well_def h).symm\n| a b (trans hac hcb) := eq.trans (well_def hac) (well_def hcb)\n| _ _ (congr_mul ha hb) := by { simp [to_envel_group.map_aux, well_def ha, well_def hb] }\n| _ _ (congr_inv ha) := by { simp [to_envel_group.map_aux, well_def ha] }\n| _ _ (assoc a b c) := by { apply mul_assoc }\n| _ _ (one_mul a) := by { simp [to_envel_group.map_aux] }\n| _ _ (mul_one a) := by { simp [to_envel_group.map_aux] }\n| _ _ (mul_left_inv a) := by { simp [to_envel_group.map_aux] }\n| _ _ (act_incl x y) := by { simp [to_envel_group.map_aux] }\n\nend to_envel_group.map_aux\n\n/--\nGiven a map from a rack to a group, lift it to being a map from the enveloping group.\nMore precisely, the `envel_group` functor is left adjoint to `quandle.conj`.\n-/\ndef to_envel_group.map {R : Type*} [rack R] {G : Type*} [group G] :\n  (R \u2192\u25c3 quandle.conj G) \u2243 (envel_group R \u2192* G) :=\n{ to_fun := \u03bb f,\n  { to_fun := \u03bb x, quotient.lift_on x (to_envel_group.map_aux f)\n                    (\u03bb a b \u27e8hab\u27e9, to_envel_group.map_aux.well_def f hab),\n    map_one' := begin\n      change quotient.lift_on \u27e6rack.pre_envel_group.unit\u27e7 (to_envel_group.map_aux f) _ = 1,\n      simp [to_envel_group.map_aux],\n    end,\n    map_mul' := \u03bb x y, quotient.induction_on\u2082 x y (\u03bb x y, begin\n      change quotient.lift_on \u27e6mul x y\u27e7 (to_envel_group.map_aux f) _ = _,\n      simp [to_envel_group.map_aux],\n    end) },\n  inv_fun := \u03bb F, (quandle.conj.map F).comp (to_envel_group R),\n  left_inv := \u03bb f, by { ext, refl },\n  right_inv := \u03bb F, monoid_hom.ext $ \u03bb x, quotient.induction_on x $ \u03bb x, begin\n    induction x,\n    { exact F.map_one.symm, },\n    { refl, },\n    { have hm : \u27e6x_a.mul x_b\u27e7 = @has_mul.mul (envel_group R) _ \u27e6x_a\u27e7 \u27e6x_b\u27e7 := rfl,\n      rw [hm, F.map_mul, monoid_hom.map_mul, \u2190x_ih_a, \u2190x_ih_b] },\n    { have hm : \u27e6x_a.inv\u27e7 = @has_inv.inv (envel_group R) _ \u27e6x_a\u27e7 := rfl,\n      rw [hm, F.map_inv, monoid_hom.map_inv, x_ih], }\n  end, }\n\n/--\nGiven a homomorphism from a rack to a group, it factors through the enveloping group.\n-/\nlemma to_envel_group.univ (R : Type*) [rack R] (G : Type*) [group G]\n  (f : R \u2192\u25c3 quandle.conj G) :\n  (quandle.conj.map (to_envel_group.map f)).comp (to_envel_group R) = f :=\nto_envel_group.map.symm_apply_apply f\n\n/--\nThe homomorphism `to_envel_group.map f` is the unique map that fits into the commutative\ntriangle in `to_envel_group.univ`.\n-/\nlemma to_envel_group.univ_uniq (R : Type*) [rack R] (G : Type*) [group G]\n  (f : R \u2192\u25c3 quandle.conj G)\n  (g : envel_group R \u2192* G) (h : f = (quandle.conj.map g).comp (to_envel_group R)) :\n  g = to_envel_group.map f :=\nh.symm \u25b8 (to_envel_group.map.apply_symm_apply g).symm\n\n/--\nThe induced group homomorphism from the enveloping group into bijections of the rack,\nusing `rack.to_conj`. Satisfies the property `envel_action_prop`.\n\nThis gives the rack `R` the structure of an augmented rack over `envel_group R`.\n-/\ndef envel_action {R : Type*} [rack R] : envel_group R \u2192* (R \u2243 R) :=\nto_envel_group.map (to_conj R)\n\n@[simp]\n\n\nend envel_group\n\nend rack\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/quandle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7084211543315996}}
{"text": "/-\nCopyright (c) 2019 The Flypitch Project. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthors: Jesse Han, Floris van Doorn\n-/\nimport .fol\n\nopen fol\n\nlocal notation h :: t  := dvector.cons h t\nlocal notation `[]` := dvector.nil\nlocal notation `[` l:(foldr `, ` (h t, dvector.cons h t) dvector.nil `]`) := l\n\nnamespace abel\nsection\n\n/- The language of abelian groups -/\ninductive abel_functions : \u2115 \u2192 Type\n| zero : abel_functions 0\n| plus : abel_functions 2\n\ndef L_abel : Language := \u27e8abel_functions, \u03bbn, pempty\u27e9\n\ndef L_abel_plus {n} (t\u2081 t\u2082 : bounded_term L_abel n) : bounded_term L_abel n :=\n@bounded_term_of_function L_abel 2 n abel_functions.plus t\u2081 t\u2082\n\ndef zero {n} : bounded_term L_abel n := bd_const abel_functions.zero\n\nlocal infix ` +' `:100 := _root_.abel.L_abel_plus\n\ndef a_assoc : sentence L_abel := \u2200' \u2200' \u2200' (((&2 +' &1) +' &0) \u2243 (&2 +' (&1 +' &0)))\n\ndef a_zero_right : sentence L_abel := \u2200' (&0 +' zero \u2243 &0)\n\ndef a_zero_left : sentence L_abel := \u2200'(zero +' &0 \u2243 &0)\n\ndef a_inv : sentence L_abel := \u2200' \u2203' (&1 +' &0 \u2243 zero \u2293 &0 +' &1 \u2243 zero)\n\ndef a_comm : sentence L_abel := \u2200' \u2200' (&1 +' &0 \u2243 &0 +' &1)\n\n/- axioms of abelian groups -/\ndef T_ab : Theory L_abel := {a_assoc, a_zero_right, a_zero_left, a_inv, a_comm}\n\ndef L_abel_structure_of_int : Structure L_abel :=\nbegin\n  refine \u27e8\u2124,_,_\u27e9,\n  {intros n f, induction f,\n    exact \u03bb v, 0,\n    exact \u03bb v, (v.nth 0 (by repeat{constructor})) + (v.nth 1 (by repeat{constructor}))},\n  {intros, cases a}\nend\n\nnotation `\u2124'` := _root_.abel.L_abel_structure_of_int\n\n@[simp]lemma \u2124'_\u2124 : \u21a5(\u2124') = \u2124 := by refl\n\n@[reducible]instance has_zero_\u2124' : has_zero \u2124' := \u27e8(0 : \u2124)\u27e9\n\n@[reducible]instance has_add_\u2124' : has_add \u2124' := \u27e8\u03bbx y, (x + y : \u2124)\u27e9\n\n@[reducible]instance nonempty_\u2124' : nonempty \u2124' := by simp\n\n@[simp]lemma zero_is_zero : @realize_bounded_term L_abel \u2124' _ [] _ zero [] = (0 : \u2124) := by refl\n\n@[simp]lemma plus_is_plus_l : \u2200 x y : \u2124', realize_bounded_term ([x,y]) (&0 +' &1) [] = x + y := by {intros, refl}\n\n@[simp]lemma plus_is_plus_r : \u2200 x y : \u2124', realize_bounded_term ([x,y]) (&1 +' &0) [] = y + x := by {intros, refl}\n\n-- instance has_add_Structure_L_abel {S : Structure L_abel} : has_add S :=\n--   \u27e8\u03bb x y, realize_bounded_term ([x,y]) (&0 +' &1) []\u27e9\n\n-- @[simp]lemma plus_is_plus {S : Structure L_abel} {n} {t\u2081 t\u2082 : bounded_term L_abel n} {v : dvector S n} : realize_bounded_term v (t\u2081 +' t\u2082) [] = (realize_bounded_term v t\u2081 []) + (realize_bounded_term v t\u2082 []) := by refl\n\n/- Note: the above seems to confuse the elaborator when proving the theorem below. Probably because \u2124 has an existing has_add instance. -/\n\ndef presburger_arithmetic : Theory L_abel := Th \u2124'\n\ntheorem \u2124'_is_abelian_group : T_ab \u2286 presburger_arithmetic :=\nbegin\n  intros a H, repeat{cases H},\n  {intros x y, simp},\n  {intros x H, dsimp at H, unfold realize_bounded_formula, have : \u2203 y : \u2124, x + y = 0,\n  by {refine \u27e8-x, _\u27e9, simp}, rcases this with \u27e8y, hy\u27e9, apply H y, simp[hy], refl},\n  {intro x, change 0 + x = x, rw[zero_add]},\n  {intro x, change x + 0 = x, rw[add_zero]},\n  {intros x y z, change x + y + z = x + (y + z), rw[add_assoc]}\nend\n\nend\nend abel\n", "meta": {"author": "flypitch", "repo": "flypitch", "sha": "aea5800db1f4cce53fc4a113711454b27388ecf8", "save_path": "github-repos/lean/flypitch-flypitch", "path": "github-repos/lean/flypitch-flypitch/flypitch-aea5800db1f4cce53fc4a113711454b27388ecf8/src/abel.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7083698281882854}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport computability.DFA\nimport data.set.functor\n\n/-!\n# Nondeterministic Finite Automata\nThis file contains the definition of a Nondeterministic Finite Automaton (NFA), a state machine\nwhich determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular\nset by evaluating the string over every possible path.\nWe show that DFA's are equivalent to NFA's however the construction from NFA to DFA uses an\nexponential number of states.\nNote that this definition allows for Automaton with infinite states, a `fintype` instance must be\nsupplied for true NFA's.\n-/\n\nopen set\n\nuniverses u v\n\n/-- An NFA is a set of states (`\u03c3`), a transition function from state to state labelled by the\n  alphabet (`step`), a starting state (`start`) and a set of acceptance states (`accept`).\n  Note the transition function sends a state to a `set` of states. These are the states that it\n  may be sent to. -/\nstructure NFA (\u03b1 : Type u) (\u03c3 : Type v) :=\n(step : \u03c3 \u2192 \u03b1 \u2192 set \u03c3)\n(start : set \u03c3)\n(accept : set \u03c3)\n\nvariables {\u03b1 : Type u} {\u03c3 \u03c3' : Type v} (M : NFA \u03b1 \u03c3)\n\nnamespace NFA\n\ninstance : inhabited (NFA \u03b1 \u03c3) := \u27e8 NFA.mk (\u03bb _ _, \u2205) \u2205 \u2205 \u27e9\n\n/-- `M.step_set S a` is the union of `M.step s a` for all `s \u2208 S`. -/\ndef step_set (S : set \u03c3) (a : \u03b1) : set \u03c3 := \u22c3 s \u2208 S, M.step s a\n\nlemma mem_step_set (s : \u03c3) (S : set \u03c3) (a : \u03b1) : s \u2208 M.step_set S a \u2194 \u2203 t \u2208 S, s \u2208 M.step t a :=\nmem_Union\u2082\n\n@[simp] lemma step_set_empty (a : \u03b1) : M.step_set \u2205 a = \u2205 :=\nby simp_rw [step_set, Union_false, Union_empty]\n\n/-- `M.eval_from S x` computes all possible paths though `M` with input `x` starting at an element\n  of `S`. -/\ndef eval_from (start : set \u03c3) : list \u03b1 \u2192 set \u03c3 :=\nlist.foldl M.step_set start\n\n@[simp] lemma eval_from_nil (S : set \u03c3) : M.eval_from S [] = S := rfl\n@[simp] lemma eval_from_singleton (S : set \u03c3) (a : \u03b1) : M.eval_from S [a] = M.step_set S a := rfl\n@[simp] lemma eval_from_append_singleton (S : set \u03c3) (x : list \u03b1) (a : \u03b1) :\n  M.eval_from S (x ++ [a]) = M.step_set (M.eval_from S x) a :=\nby simp only [eval_from, list.foldl_append, list.foldl_cons, list.foldl_nil]\n\n/-- `M.eval x` computes all possible paths though `M` with input `x` starting at an element of\n  `M.start`. -/\ndef eval : list \u03b1 \u2192 set \u03c3 := M.eval_from M.start\n\n@[simp] lemma eval_nil : M.eval [] = M.start := rfl\n@[simp] lemma eval_singleton (a : \u03b1) : M.eval [a] = M.step_set M.start a := rfl\n@[simp] lemma eval_append_singleton (x : list \u03b1) (a : \u03b1) :\n  M.eval (x ++ [a]) = M.step_set (M.eval x) a :=\neval_from_append_singleton _ _ _ _\n\n/-- `M.accepts` is the language of `x` such that there is an accept state in `M.eval x`. -/\ndef accepts : language \u03b1 :=\n\u03bb x, \u2203 S \u2208 M.accept, S \u2208 M.eval x\n\n/-- `M.to_DFA` is an `DFA` constructed from a `NFA` `M` using the subset construction. The\n  states is the type of `set`s of `M.state` and the step function is `M.step_set`. -/\ndef to_DFA : DFA \u03b1 (set \u03c3) :=\n{ step := M.step_set,\n  start := M.start,\n  accept := {S | \u2203 s \u2208 S, s \u2208 M.accept} }\n\n@[simp] lemma to_DFA_correct :\n  M.to_DFA.accepts = M.accepts :=\nbegin\n  ext x,\n  rw [accepts, DFA.accepts, eval, DFA.eval],\n  change list.foldl _ _ _ \u2208 {S | _} \u2194 _,\n  split; { exact \u03bb \u27e8w, h2, h3\u27e9, \u27e8w, h3, h2\u27e9 },\nend\n\nlemma pumping_lemma [fintype \u03c3] {x : list \u03b1} (hx : x \u2208 M.accepts)\n  (hlen : fintype.card (set \u03c3) \u2264 list.length x) :\n  \u2203 a b c, x = a ++ b ++ c \u2227 a.length + b.length \u2264 fintype.card (set \u03c3) \u2227 b \u2260 [] \u2227\n  {a} * language.star {b} * {c} \u2264 M.accepts :=\nbegin\n  rw \u2190to_DFA_correct at hx \u22a2,\n  exact M.to_DFA.pumping_lemma hx hlen\nend\n\nend NFA\n\nnamespace DFA\n\n/-- `M.to_NFA` is an `NFA` constructed from a `DFA` `M` by using the same start and accept\n  states and a transition function which sends `s` with input `a` to the singleton `M.step s a`. -/\ndef to_NFA (M : DFA \u03b1 \u03c3') : NFA \u03b1 \u03c3' :=\n{ step := \u03bb s a, {M.step s a},\n  start := {M.start},\n  accept := M.accept }\n\n@[simp] lemma to_NFA_eval_from_match (M : DFA \u03b1 \u03c3) (start : \u03c3) (s : list \u03b1) :\n  M.to_NFA.eval_from {start} s = {M.eval_from start s} :=\nbegin\n  change list.foldl M.to_NFA.step_set {start} s = {list.foldl M.step start s},\n  induction s with a s ih generalizing start,\n  { tauto },\n  { rw [list.foldl, list.foldl,\n        show M.to_NFA.step_set {start} a = {M.step start a}, by simpa [NFA.step_set]],\n    tauto }\nend\n\n@[simp] lemma to_NFA_correct (M : DFA \u03b1 \u03c3) :\n  M.to_NFA.accepts = M.accepts :=\nbegin\n  ext x,\n  change (\u2203 S H, S \u2208 M.to_NFA.eval_from {M.start} x) \u2194 _,\n  rw to_NFA_eval_from_match,\n  split,\n  { rintro \u27e8 S, hS\u2081, hS\u2082 \u27e9,\n    rwa set.mem_singleton_iff.mp hS\u2082 at hS\u2081 },\n  { exact \u03bb h, \u27e8M.eval x, h, rfl\u27e9 }\nend\n\nend DFA\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/computability/NFA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.708369810137444}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 3 : \"not\" (`\u00ac`)\n\nWe learn about how to manipulate `\u00ac P` in Lean.\n\n# Important : the definition of `\u00ac P`\n\nIn Lean, `\u00ac P` is *defined* to mean `P \u2192 false`. So `\u00ac P` and `P \u2192 false`\nare *definitionally equal*. Check out the explanation of definitional\nequality in the \"equality\" section of Part B of the course notes.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand the following tactics may also be useful:\n\n* `change`\n* `by_contra`\n* `by_cases`\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : \u00ac true \u2192 false :=\nbegin\n  sorry\nend\n\nexample : false \u2192 \u00ac true :=\nbegin\n  sorry\nend\n\nexample : \u00ac false \u2192 true :=\nbegin\n  sorry\nend\n\nexample : true \u2192 \u00ac false :=\nbegin\n  sorry\nend\n\nexample : false \u2192 \u00ac P :=\nbegin\n  sorry\nend\n\nexample : P \u2192 \u00ac P \u2192 false :=\nbegin\n  sorry\nend\n\nexample : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  sorry\nend\n\nexample : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  sorry\nend\n\nexample : \u00ac \u00ac false \u2192 false :=\nbegin\n  sorry\nend\n\nexample : \u00ac \u00ac P \u2192 P :=\nbegin\n  sorry\nend\n\nexample : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n  sorry,\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section01logic/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.7083698038256993}}
{"text": "import analysis.inner_product_space.basic\nimport analysis.inner_product_space.pi_L2\nimport analysis.normed_space.pi_Lp\n\nvariables {F M m : Type*}\n[is_R_or_C F]\n[fintype m]\n[decidable_eq m]\n\n\ndef std_basis (F m : Type*) [is_R_or_C F] [fintype m] [decidable_eq m]: m \u2192 (euclidean_space F m) := \u03bb (i : m), (\u03bb (j : m), ite (i = j) 1 0)\n\nlemma std_basis_on : orthonormal F (std_basis F m) :=\nbegin\n  rw std_basis,\n  rw orthonormal,\n  split,\n  {\n    intro i,\n    rw euclidean_space.norm_eq,\n    simp,\n    have : (\u03bb (i_1 : m), \u2225 ite (i = i_1) (1:F) (0 : F) \u2225^2) = \u03bb (i_1 : m), ite (i = i_1) 1 0 :=\n    begin\n      ext,\n      split_ifs,\n      simp,\n      simp,\n    end,\n    rw this,\n    rw finset.sum_ite,\n    simp,\n    have : (finset.filter (eq i) finset.univ).card = 1 :=\n    begin\n      rw finset.card_eq_one,\n      use i,\n      ext,\n      split,\n      intro h,\n      have : a = i :=\n      begin\n        simp at h,\n        rw h,\n      end,\n      rw this,\n      simp,\n      intro h,\n      simp at h,\n      simp,\n      rw h,\n    end,\n    rw this,\n    simp,\n  },\n  {\n    intros i_1 i_2 hij,\n    unfold inner,\n    simp,\n    exact hij,\n  }\nend\n", "meta": {"author": "hparshall", "repo": "lean-matrix-analysis", "sha": "cc1b9949065257b6c19f047a5a996bfac29f178e", "save_path": "github-repos/lean/hparshall-lean-matrix-analysis", "path": "github-repos/lean/hparshall-lean-matrix-analysis/lean-matrix-analysis-cc1b9949065257b6c19f047a5a996bfac29f178e/src/examples/std_basis_proof.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.7083697991936877}}
{"text": "/-\nCopyright (c) 2020 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Devon Tuma\n-/\nimport ring_theory.ideal.operations\nimport ring_theory.polynomial.basic\n\n/-!\n# Jacobson radical\n\nThe Jacobson radical of a ring `R` is defined to be the intersection of all maximal ideals of `R`.\nThis is similar to how the nilradical is equal to the intersection of all prime ideals of `R`.\n\nWe can extend the idea of the nilradical to ideals of `R`,\nby letting the radical of an ideal `I` be the intersection of prime ideals containing `I`.\nUnder this extension, the original nilradical is the radical of the zero ideal `\u22a5`.\nHere we define the Jacobson radical of an ideal `I` in a similar way,\nas the intersection of maximal ideals containing `I`.\n\n## Main definitions\n\nLet `R` be a commutative ring, and `I` be an ideal of `R`\n\n* `jacobson I` is the jacobson radical, i.e. the infimum of all maximal ideals containing I.\n\n* `is_local I` is the proposition that the jacobson radical of `I` is itself a maximal ideal\n\n## Main statements\n\n* `mem_jacobson_iff` gives a characterization of members of the jacobson of I\n\n* `is_local_of_is_maximal_radical`: if the radical of I is maximal then so is the jacobson radical\n\n## Tags\n\nJacobson, Jacobson radical, Local Ideal\n\n-/\n\nuniverses u v\n\nnamespace ideal\nvariables {R : Type u} [comm_ring R] {I : ideal R}\nvariables {S : Type v} [comm_ring S]\n\nsection jacobson\n\n/-- The Jacobson radical of `I` is the infimum of all maximal ideals containing `I`. -/\ndef jacobson (I : ideal R) : ideal R :=\nInf {J : ideal R | I \u2264 J \u2227 is_maximal J}\n\nlemma le_jacobson : I \u2264 jacobson I :=\n\u03bb x hx, mem_Inf.mpr (\u03bb J hJ, hJ.left hx)\n\n@[simp] lemma jacobson_idem : jacobson (jacobson I) = jacobson I :=\nle_antisymm (Inf_le_Inf (\u03bb J hJ, \u27e8Inf_le hJ, hJ.2\u27e9)) le_jacobson\n\nlemma radical_le_jacobson : radical I \u2264 jacobson I :=\nle_Inf (\u03bb J hJ, (radical_eq_Inf I).symm \u25b8 Inf_le \u27e8hJ.left, is_maximal.is_prime hJ.right\u27e9)\n\nlemma eq_radical_of_eq_jacobson : jacobson I = I \u2192 radical I = I :=\n\u03bb h, le_antisymm (le_trans radical_le_jacobson (le_of_eq h)) le_radical\n\n@[simp] lemma jacobson_top : jacobson (\u22a4 : ideal R) = \u22a4 :=\neq_top_iff.2 le_jacobson\n\n@[simp] theorem jacobson_eq_top_iff : jacobson I = \u22a4 \u2194 I = \u22a4 :=\n\u27e8\u03bb H, classical.by_contradiction $ \u03bb hi, let \u27e8M, hm, him\u27e9 := exists_le_maximal I hi in\n  lt_top_iff_ne_top.1\n    (lt_of_le_of_lt (show jacobson I \u2264 M, from Inf_le \u27e8him, hm\u27e9) $\n      lt_top_iff_ne_top.2 hm.ne_top) H,\n\u03bb H, eq_top_iff.2 $ le_Inf $ \u03bb J \u27e8hij, hj\u27e9, H \u25b8 hij\u27e9\n\nlemma jacobson_eq_bot : jacobson I = \u22a5 \u2192 I = \u22a5 :=\n\u03bb h, eq_bot_iff.mpr (h \u25b8 le_jacobson)\n\nlemma jacobson_eq_self_of_is_maximal [H : is_maximal I] : I.jacobson = I :=\nle_antisymm (Inf_le \u27e8le_of_eq rfl, H\u27e9) le_jacobson\n\n@[priority 100]\ninstance jacobson.is_maximal [H : is_maximal I] : is_maximal (jacobson I) :=\n\u27e8\u27e8\u03bb htop, H.1.1 (jacobson_eq_top_iff.1 htop),\n  \u03bb J hJ, H.1.2 _ (lt_of_le_of_lt le_jacobson hJ)\u27e9\u27e9\n\ntheorem mem_jacobson_iff {x : R} : x \u2208 jacobson I \u2194 \u2200 y, \u2203 z, x * y * z + z - 1 \u2208 I :=\n\u27e8\u03bb hx y, classical.by_cases\n  (assume hxy : I \u2294 span {x * y + 1} = \u22a4,\n    let \u27e8p, hpi, q, hq, hpq\u27e9 := submodule.mem_sup.1 ((eq_top_iff_one _).1 hxy) in\n    let \u27e8r, hr\u27e9 := mem_span_singleton.1 hq in\n    \u27e8r, by rw [\u2190 one_mul r, \u2190 mul_assoc, \u2190 add_mul, mul_one, \u2190 hr, \u2190 hpq, \u2190 neg_sub,\n               add_sub_cancel]; exact I.neg_mem hpi\u27e9)\n  (assume hxy : I \u2294 span {x * y + 1} \u2260 \u22a4,\n    let \u27e8M, hm1, hm2\u27e9 := exists_le_maximal _ hxy in\n    suffices x \u2209 M, from (this $ mem_Inf.1 hx \u27e8le_trans le_sup_left hm2, hm1\u27e9).elim,\n    \u03bb hxm, hm1.1.1 $ (eq_top_iff_one _).2 $ add_sub_cancel' (x * y) 1 \u25b8 M.sub_mem\n      (le_trans le_sup_right hm2 $ mem_span_singleton.2 $ dvd_refl _)\n      (M.mul_mem_right _ hxm)),\n\u03bb hx, mem_Inf.2 $ \u03bb M \u27e8him, hm\u27e9, classical.by_contradiction $ \u03bb hxm,\n  let \u27e8y, hy\u27e9 := hm.exists_inv hxm, \u27e8z, hz\u27e9 := hx (-y) in\n  hm.1.1 $ (eq_top_iff_one _).2 $ sub_sub_cancel (x * -y * z + z) 1 \u25b8 M.sub_mem\n    (by { rw [\u2190 one_mul z, \u2190 mul_assoc, \u2190 add_mul, mul_one, mul_neg_eq_neg_mul_symm, neg_add_eq_sub,\n        \u2190 neg_sub, neg_mul_eq_neg_mul_symm, neg_mul_eq_mul_neg, mul_comm x y, mul_comm _ (- z)],\n      rcases hy with \u27e8i, hi, df\u27e9,\n      rw [\u2190 (sub_eq_iff_eq_add.mpr df.symm), sub_sub, add_comm, \u2190 sub_sub, sub_self, zero_sub],\n      refine M.mul_mem_left (-z) ((neg_mem_iff _).mpr hi) }) (him hz)\u27e9\n\n/-- An ideal equals its Jacobson radical iff it is the intersection of a set of maximal ideals.\nAllowing the set to include \u22a4 is equivalent, and is included only to simplify some proofs. -/\ntheorem eq_jacobson_iff_Inf_maximal :\n  I.jacobson = I \u2194 \u2203 M : set (ideal R), (\u2200 J \u2208 M, is_maximal J \u2228 J = \u22a4) \u2227 I = Inf M :=\nbegin\n  use \u03bb hI, \u27e8{J : ideal R | I \u2264 J \u2227 J.is_maximal}, \u27e8\u03bb _ hJ, or.inl hJ.right, hI.symm\u27e9\u27e9,\n  rintros \u27e8M, hM, hInf\u27e9,\n  refine le_antisymm (\u03bb x hx, _) le_jacobson,\n  rw [hInf, mem_Inf],\n  intros I hI,\n  cases hM I hI with is_max is_top,\n  { exact (mem_Inf.1 hx) \u27e8le_Inf_iff.1 (le_of_eq hInf) I hI, is_max\u27e9 },\n  { exact is_top.symm \u25b8 submodule.mem_top }\nend\n\ntheorem eq_jacobson_iff_Inf_maximal' :\n  I.jacobson = I \u2194 \u2203 M : set (ideal R), (\u2200 (J \u2208 M) (K : ideal R), J < K \u2192 K = \u22a4) \u2227 I = Inf M :=\neq_jacobson_iff_Inf_maximal.trans\n  \u27e8\u03bb h, let \u27e8M, hM\u27e9 := h in \u27e8M, \u27e8\u03bb J hJ K hK, or.rec_on (hM.1 J hJ) (\u03bb h, h.1.2 K hK)\n    (\u03bb h, eq_top_iff.2 (le_of_lt (h \u25b8 hK))), hM.2\u27e9\u27e9,\n  \u03bb h, let \u27e8M, hM\u27e9 := h in \u27e8M, \u27e8\u03bb J hJ, or.rec_on (classical.em (J = \u22a4)) (\u03bb h, or.inr h)\n    (\u03bb h, or.inl \u27e8\u27e8h, hM.1 J hJ\u27e9\u27e9), hM.2\u27e9\u27e9\u27e9\n\n/-- An ideal `I` equals its Jacobson radical if and only if every element outside `I`\nalso lies outside of a maximal ideal containing `I`. -/\nlemma eq_jacobson_iff_not_mem :\n  I.jacobson = I \u2194 \u2200 x \u2209 I, \u2203 M : ideal R, (I \u2264 M \u2227 M.is_maximal) \u2227 x \u2209 M :=\nbegin\n  split,\n  { intros h x hx,\n    erw [\u2190 h, mem_Inf] at hx,\n    push_neg at hx,\n    exact hx },\n  { refine \u03bb h, le_antisymm (\u03bb x hx, _) le_jacobson,\n    contrapose hx,\n    erw mem_Inf,\n    push_neg,\n    exact h x hx }\nend\n\ntheorem map_jacobson_of_surjective {f : R \u2192+* S} (hf : function.surjective f) :\n  ring_hom.ker f \u2264 I \u2192 map f (I.jacobson) = (map f I).jacobson :=\nbegin\n  intro h,\n  unfold ideal.jacobson,\n  have : \u2200 J \u2208 {J : ideal R | I \u2264 J \u2227 J.is_maximal}, f.ker \u2264 J := \u03bb J hJ, le_trans h hJ.left,\n  refine trans (map_Inf hf this) (le_antisymm _ _),\n  { refine Inf_le_Inf (\u03bb J hJ, \u27e8comap f J, \u27e8\u27e8le_comap_of_map_le hJ.1, _\u27e9,\n    map_comap_of_surjective f hf J\u27e9\u27e9),\n    haveI : J.is_maximal := hJ.right,\n    exact comap_is_maximal_of_surjective f hf },\n  { refine Inf_le_Inf_of_subset_insert_top (\u03bb j hj, hj.rec_on (\u03bb J hJ, _)),\n    rw \u2190 hJ.2,\n    cases map_eq_top_or_is_maximal_of_surjective f hf hJ.left.right with htop hmax,\n    { exact htop.symm \u25b8 set.mem_insert \u22a4 _ },\n    { exact set.mem_insert_of_mem \u22a4 \u27e8map_mono hJ.1.1, hmax\u27e9 } },\nend\n\nlemma map_jacobson_of_bijective {f : R \u2192+* S} (hf : function.bijective f) :\n  map f (I.jacobson) = (map f I).jacobson :=\nmap_jacobson_of_surjective hf.right\n  (le_trans (le_of_eq (f.injective_iff_ker_eq_bot.1 hf.left)) bot_le)\n\nlemma comap_jacobson {f : R \u2192+* S} {K : ideal S} :\n  comap f (K.jacobson) = Inf (comap f '' {J : ideal S | K \u2264 J \u2227 J.is_maximal}) :=\ntrans (comap_Inf' f _) (Inf_eq_infi).symm\n\ntheorem comap_jacobson_of_surjective {f : R \u2192+* S} (hf : function.surjective f) {K : ideal S} :\n  comap f (K.jacobson) = (comap f K).jacobson :=\nbegin\n  unfold ideal.jacobson,\n  refine le_antisymm _ _,\n  { refine le_trans (comap_mono (le_of_eq (trans top_inf_eq.symm Inf_insert.symm))) _,\n    rw [comap_Inf', Inf_eq_infi],\n    refine infi_le_infi_of_subset (\u03bb J hJ, _),\n    have : comap f (map f J) = J := trans (comap_map_of_surjective f hf J)\n      (le_antisymm (sup_le_iff.2 \u27e8le_of_eq rfl, le_trans (comap_mono bot_le) hJ.left\u27e9) le_sup_left),\n    cases map_eq_top_or_is_maximal_of_surjective _ hf hJ.right with htop hmax,\n    { refine \u27e8\u22a4, \u27e8set.mem_insert \u22a4 _, htop \u25b8 this\u27e9\u27e9 },\n    { refine \u27e8map f J, \u27e8set.mem_insert_of_mem _\n        \u27e8le_map_of_comap_le_of_surjective f hf hJ.1, hmax\u27e9, this\u27e9\u27e9 } },\n  { rw comap_Inf,\n    refine le_infi_iff.2 (\u03bb J, (le_infi_iff.2 (\u03bb hJ, _))),\n    haveI : J.is_maximal := hJ.right,\n    refine Inf_le \u27e8comap_mono hJ.left, comap_is_maximal_of_surjective _ hf\u27e9 }\nend\n\nlemma mem_jacobson_bot {x : R} : x \u2208 jacobson (\u22a5 : ideal R) \u2194 \u2200 y, is_unit (x * y + 1) :=\n\u27e8\u03bb hx y, let \u27e8z, hz\u27e9 := (mem_jacobson_iff.1 hx) y in\n  is_unit_iff_exists_inv.2 \u27e8z, by rwa [add_mul, one_mul, \u2190 sub_eq_zero]\u27e9,\n\u03bb h, mem_jacobson_iff.mpr (\u03bb y, (let \u27e8b, hb\u27e9 := is_unit_iff_exists_inv.1 (h y) in\n  \u27e8b, (submodule.mem_bot R).2 (hb \u25b8 (by ring))\u27e9))\u27e9\n\n/-- An ideal `I` of `R` is equal to its Jacobson radical if and only if\nthe Jacobson radical of the quotient ring `R/I` is the zero ideal -/\ntheorem jacobson_eq_iff_jacobson_quotient_eq_bot :\n  I.jacobson = I \u2194 jacobson (\u22a5 : ideal (I.quotient)) = \u22a5 :=\nbegin\n  have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I,\n  split,\n  { intro h,\n    replace h := congr_arg (map (quotient.mk I)) h,\n    rw map_jacobson_of_surjective hf (le_of_eq mk_ker) at h,\n    simpa using h },\n  { intro h,\n    replace h := congr_arg (comap (quotient.mk I)) h,\n    rw [comap_jacobson_of_surjective hf, \u2190 (quotient.mk I).ker_eq_comap_bot] at h,\n    simpa using h }\nend\n\n/-- The standard radical and Jacobson radical of an ideal `I` of `R` are equal if and only if\nthe nilradical and Jacobson radical of the quotient ring `R/I` coincide -/\ntheorem radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot :\n  I.radical = I.jacobson \u2194 radical (\u22a5 : ideal (I.quotient)) = jacobson \u22a5 :=\nbegin\n  have hf : function.surjective (quotient.mk I) := submodule.quotient.mk_surjective I,\n  split,\n  { intro h,\n    have := congr_arg (map (quotient.mk I)) h,\n    rw [map_radical_of_surjective hf (le_of_eq mk_ker),\n      map_jacobson_of_surjective hf (le_of_eq mk_ker)] at this,\n    simpa using this },\n  { intro h,\n    have := congr_arg (comap (quotient.mk I)) h,\n    rw [comap_radical, comap_jacobson_of_surjective hf, \u2190 (quotient.mk I).ker_eq_comap_bot] at this,\n    simpa using this }\nend\n\n@[mono] lemma jacobson_mono {I J : ideal R} : I \u2264 J \u2192 I.jacobson \u2264 J.jacobson :=\nbegin\n  intros h x hx,\n  erw mem_Inf at \u22a2 hx,\n  exact \u03bb K \u27e8hK, hK_max\u27e9, hx \u27e8trans h hK, hK_max\u27e9\nend\n\nlemma jacobson_radical_eq_jacobson :\n  I.radical.jacobson = I.jacobson :=\nle_antisymm (le_trans (le_of_eq (congr_arg jacobson (radical_eq_Inf I)))\n  (Inf_le_Inf (\u03bb J hJ, \u27e8Inf_le \u27e8hJ.1, hJ.2.is_prime\u27e9, hJ.2\u27e9))) (jacobson_mono le_radical)\n\nend jacobson\n\nsection polynomial\nopen polynomial\n\nlemma jacobson_bot_polynomial_le_Inf_map_maximal :\n  jacobson (\u22a5 : ideal (polynomial R)) \u2264 Inf (map C '' {J : ideal R | J.is_maximal}) :=\nbegin\n  refine le_Inf (\u03bb J, exists_imp_distrib.2 (\u03bb j hj, _)),\n  haveI : j.is_maximal := hj.1,\n  refine trans (jacobson_mono bot_le) (le_of_eq _ : J.jacobson \u2264 J),\n  suffices : (\u22a5 : ideal (polynomial j.quotient)).jacobson = \u22a5,\n  { rw [\u2190 hj.2, jacobson_eq_iff_jacobson_quotient_eq_bot],\n    replace this :=\n    congr_arg (map (polynomial_quotient_equiv_quotient_polynomial j).to_ring_hom) this,\n    rwa [map_jacobson_of_bijective _, map_bot] at this,\n    exact (ring_equiv.bijective (polynomial_quotient_equiv_quotient_polynomial j)) },\n  refine eq_bot_iff.2 (\u03bb f hf, _),\n  simpa [(\u03bb hX, by simpa using congr_arg (\u03bb f, coeff f 1) hX : (X : polynomial j.quotient) \u2260 0)]\n    using eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit ((mem_jacobson_bot.1 hf) X)),\nend\n\nlemma jacobson_bot_polynomial_of_jacobson_bot (h : jacobson (\u22a5 : ideal R) = \u22a5) :\n  jacobson (\u22a5 : ideal (polynomial R)) = \u22a5 :=\nbegin\n  refine eq_bot_iff.2 (le_trans jacobson_bot_polynomial_le_Inf_map_maximal _),\n  refine (\u03bb f hf, ((submodule.mem_bot _).2 (polynomial.ext (\u03bb n, trans _ (coeff_zero n).symm)))),\n  suffices : f.coeff n \u2208 ideal.jacobson \u22a5, by rwa [h, submodule.mem_bot] at this,\n  exact mem_Inf.2 (\u03bb j hj, (mem_map_C_iff.1 ((mem_Inf.1 hf) \u27e8j, \u27e8hj.2, rfl\u27e9\u27e9)) n),\nend\n\nend polynomial\n\nsection is_local\n\n/-- An ideal `I` is local iff its Jacobson radical is maximal. -/\nclass is_local (I : ideal R) : Prop := (out : is_maximal (jacobson I))\n\ntheorem is_local_iff {I : ideal R} : is_local I \u2194 is_maximal (jacobson I) :=\n\u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\ntheorem is_local_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) : is_local I :=\n\u27e8have radical I = jacobson I,\nfrom le_antisymm (le_Inf $ \u03bb M \u27e8him, hm\u27e9, hm.is_prime.radical_le_iff.2 him)\n  (Inf_le \u27e8le_radical, hi\u27e9),\nshow is_maximal (jacobson I), from this \u25b8 hi\u27e9\n\ntheorem is_local.le_jacobson {I J : ideal R} (hi : is_local I) (hij : I \u2264 J) (hj : J \u2260 \u22a4) :\n  J \u2264 jacobson I :=\nlet \u27e8M, hm, hjm\u27e9 := exists_le_maximal J hj in\nle_trans hjm $ le_of_eq $ eq.symm $ hi.1.eq_of_le hm.1.1 $ Inf_le \u27e8le_trans hij hjm, hm\u27e9\n\ntheorem is_local.mem_jacobson_or_exists_inv {I : ideal R} (hi : is_local I) (x : R) :\n  x \u2208 jacobson I \u2228 \u2203 y, y * x - 1 \u2208 I :=\nclassical.by_cases\n  (assume h : I \u2294 span {x} = \u22a4,\n    let \u27e8p, hpi, q, hq, hpq\u27e9 := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in\n    let \u27e8r, hr\u27e9 := mem_span_singleton.1 hq in\n    or.inr \u27e8r, by rw [\u2190 hpq, mul_comm, \u2190 hr, \u2190 neg_sub, add_sub_cancel]; exact I.neg_mem hpi\u27e9)\n  (assume h : I \u2294 span {x} \u2260 \u22a4,\n    or.inl $ le_trans le_sup_right (hi.le_jacobson le_sup_left h) $ mem_span_singleton.2 $\n      dvd_refl x)\n\nend is_local\n\ntheorem is_primary_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) :\n  is_primary I :=\nhave radical I = jacobson I,\nfrom le_antisymm (le_Inf $ \u03bb M \u27e8him, hm\u27e9, hm.is_prime.radical_le_iff.2 him)\n  (Inf_le \u27e8le_radical, hi\u27e9),\n\u27e8ne_top_of_lt $ lt_of_le_of_lt le_radical (lt_top_iff_ne_top.2 hi.1.1),\n\u03bb x y hxy, ((is_local_of_is_maximal_radical hi).mem_jacobson_or_exists_inv y).symm.imp\n  (\u03bb \u27e8z, hz\u27e9, by rw [\u2190 mul_one x, \u2190 sub_sub_cancel (z * y) 1, mul_sub, mul_left_comm]; exact\n    I.sub_mem (I.mul_mem_left _ hxy) (I.mul_mem_left _ hz))\n  (this \u25b8 id)\u27e9\n\n\nend ideal\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/jacobson_ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861582, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7083473504928665}}
{"text": "import M4R.Logic\n\nnamespace Nat\n\n  @[simp] theorem pred_zero : pred 0 = 0 := rfl\n  @[simp] theorem pred_succ (n : Nat) : pred (succ n) = n := rfl\n\n  protected theorem lt_one {n : Nat} (hn : n < 1) : n = 0 :=\n    Nat.eq_zero_of_le_zero (Nat.le_of_succ_le_succ hn)\n\n  protected theorem ne_of_lt {m n : Nat} : m < n \u2192 m \u2260 n :=\n    fun h h' => Nat.lt_irrefl n (by rw [h'] at h; exact h)\n\n  protected theorem le_or_lt (m n : Nat) : m \u2264 n \u2228 n < m :=\n    Or.elim (Nat.lt_or_ge n m) Or.inr Or.inl\n\n  protected theorem lt_or_eq_of_le {m n : Nat} (h : m \u2264 n) : m < n \u2228 m = n :=\n    Or.elim (Nat.lt_or_ge m n) Or.inl (fun h' => Or.inr (Nat.le_antisymm h h'))\n\n  protected theorem le_of_add_le_add_left {k n m : Nat} (h : k + n \u2264 k + m) : n \u2264 m :=\n    match le.dest h with\n    | \u27e8w, hw\u27e9 => @le.intro _ _ w (by rw [Nat.add_assoc] at hw; exact Nat.add_left_cancel hw)\n\n  protected theorem le_of_add_le_add_right {k n m : Nat} : n + k \u2264 m + k \u2192 n \u2264 m := by\n    rw [Nat.add_comm _ k, Nat.add_comm _ k]\n    exact Nat.le_of_add_le_add_left\n\n  protected theorem lt_of_add_lt_add_left {k n m : Nat} (h : k + n < k + m) : n < m :=\n    Nat.lt_of_le_and_ne (Nat.le_of_add_le_add_left (Nat.le_of_lt h))\n      (fun heq => Nat.lt_irrefl (k + m) (by rw [heq] at h; exact h))\n\n  protected theorem lt_of_add_lt_add_right {a b c : Nat} (h : a + b < c + b) : a < c :=\n    have : b + a < b + c := by rw [Nat.add_comm b a, Nat.add_comm b c]; exact h\n    Nat.lt_of_add_lt_add_left this\n\n  protected theorem le_iff_eq_or_lt {a b : Nat} : a \u2264 b \u2194 a = b \u2228 a < b :=\n    \u27e8fun h => (Nat.lt_or_eq_of_le h).comm, fun h => Or.elim h (\u00b7 \u25b8 Nat.le.refl) (Nat.le_of_lt)\u27e9\n\n  protected theorem lt_succ_if_le {a b : Nat} : a < b.succ \u2194 a \u2264 b :=\n    \u27e8le_of_lt_succ, lt_succ_of_le\u27e9\n\n  theorem succ_ne_self : \u2200 n : Nat, succ n \u2260 n\n  | 0  , h => absurd h (Nat.succ_ne_zero 0)\n  | n+1, h => succ_ne_self n (Nat.succ.inj h)\n\n  theorem lt_add_right (n m k : Nat) (h : n < m) : n < m + k := by\n    induction k with\n    | zero      => rw [Nat.add_zero]; exact h\n    | succ k ih => rw [Nat.add_succ]; exact Nat.lt_succ_of_le (Nat.le_of_lt ih)\n\n  theorem lt_add_left (n m k : Nat) (h : n < m) : n < k + m := by\n    rw [Nat.add_comm]; exact lt_add_right n m k h\n\n  @[simp] theorem zero_sub : \u2200 a : Nat, 0 - a = 0\n  | 0     => rfl\n  | (a+1) => congrArg pred (zero_sub a)\n\n  theorem succ_pred_eq_of_pos : \u2200 {n : Nat}, n > 0 \u2192 n.pred.succ = n\n  | 0, h      => absurd h (Nat.lt_irrefl 0)\n  | succ k, h => rfl\n\n  protected theorem add_left_cancel' {n m k : Nat} : n + m = n + k \u2194 m = k :=\n    \u27e8Nat.add_left_cancel, congrArg (n + \u00b7)\u27e9\n\n  protected theorem add_right_cancel' {n m k : Nat} : n + m = k + m \u2194 n = k :=\n    \u27e8Nat.add_right_cancel, congrArg (\u00b7 + m)\u27e9\n\n  theorem add_sub_add_right : \u2200 (n k m : Nat), (n + k) - (m + k) = n - m\n  | n, 0     , m => by rw [add_zero, add_zero]\n  | n, succ k, m => by rw [add_succ, add_succ, succ_sub_succ, add_sub_add_right n k m]\n\n  theorem add_sub_add_left (k n m : Nat) : (k + n) - (k + m) = n - m := by\n    rw [Nat.add_comm k n, Nat.add_comm k m, add_sub_add_right]\n\n  theorem add_sub_cancel (n m : Nat) : n + m - m = n := by\n    have : n + m - (0 + m) = n := by\n      rw [add_sub_add_right, Nat.sub_zero]\n    rw [Nat.zero_add] at this\n    exact this\n\n  theorem sub_self_add (n m : Nat) : n - (n + m) = 0 :=\n    have : (n + 0) - (n + m) = 0 := by rw [add_sub_add_left, Nat.zero_sub]\n    this\n\n  theorem sub_eq_zero_of_le {n m : Nat} (h : n \u2264 m) : n - m = 0 := by\n    let \u27e8k, hk\u27e9 := le.dest h\n    rw [\u2190hk, Nat.sub_self_add]\n\n  theorem le_of_sub_eq_zero : \u2200 {n m : Nat}, n - m = 0 \u2192 n \u2264 m\n  | n    , 0    , H => by rw [Nat.sub_zero] at H; rw [H]; exact Nat.le_refl 0\n  | 0    , (m+1), H => zero_le _\n  | (n+1), (m+1), H => Nat.add_le_add_right (le_of_sub_eq_zero (by simp only [add_sub_add_right] at H; exact H )) _\n\n  @[simp] theorem sub_eq_zero_iff_le (a b : Nat) : a - b = 0 \u2194 a \u2264 b :=\n    \u27e8le_of_sub_eq_zero, sub_eq_zero_of_le\u27e9\n\n  theorem add_sub_cancel_left (n m : Nat) : n + m - n = m :=\n    have : n + m - (n + 0) = m :=\n      by rw [add_sub_add_left, Nat.sub_zero]\n    this\n\n  theorem sub_sub : \u2200 (n m k : Nat), n - m - k = n - (m + k)\n  | n, m, zero   => by rw [add_zero, Nat.sub_zero]\n  | n, m, succ k => by rw [add_succ, sub_succ, sub_succ, sub_sub n m k]\n\n  theorem add_sub_of_le {n m : Nat} (h : n \u2264 m) : n + (m - n) = m := by\n    let \u27e8k, hk\u27e9 := le.dest h\n    rw [\u2190 hk, add_sub_cancel_left]\n\n  theorem sub_add_cancel {n m : Nat} (h : n \u2265 m) : n - m + m = n := by\n    rw [Nat.add_comm, add_sub_of_le h]\n\n  theorem add_sub_assoc {m k : Nat} (h : k \u2264 m) (n : Nat) : n + m - k = n + (m - k) := by\n    rw [\u2190Classical.choose_spec (le.dest h), add_sub_cancel_left, Nat.add_comm k, \u2190Nat.add_assoc, add_sub_cancel]\n\n  theorem succ_sub {m n : Nat} (h : m \u2265 n) : m.succ - n = (m - n).succ := by\n    let \u27e8k, hk\u27e9 := le.dest h\n    rw [\u2190hk, add_sub_cancel_left, \u2190add_succ, add_sub_cancel_left]\n\n  theorem sub_pos_of_lt {m n : Nat} (h : m < n) : n - m > 0 :=\n    have : 0 + m < n - m + m := by rw [Nat.zero_add, sub_add_cancel (Nat.le_of_lt h)]; exact h\n    Nat.lt_of_add_lt_add_right this\n\n  theorem sub_pred {m n : Nat} (h\u2081 : 0 < n) (h\u2082 : n \u2264 m) : m - n.pred = (m - n).succ := by\n    cases n with\n    | zero   => contradiction\n    | succ n =>\n      rw [Nat.pred_succ, Nat.sub_succ, Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h\u2082)]\n\n  theorem lt_of_sub_eq_succ {m n l : Nat} (H : m - n = succ l) : n < m :=\n    gt_of_not_le (mt (@sub_eq_zero_of_le m n) (fun h => by rw [h] at H; contradiction))\n\n  theorem sub_eq_iff_eq_add {a b c : Nat} (ab : b \u2264 a) : a - b = c \u2194 a = c + b :=\n    \u27e8fun h => by rw [\u2190h, sub_add_cancel ab], fun h => by rw [h, add_sub_cancel]\u27e9\n\n  theorem eq_sub_iff_add_eq {a b c : Nat} (bc : c \u2264 b) : a = b - c \u2194 a + c = b :=\n    \u27e8fun h => ((sub_eq_iff_eq_add bc).mp h.symm).symm, fun h => ((sub_eq_iff_eq_add bc).mpr h.symm).symm\u27e9\n\n  theorem mul_pred_left : \u2200 (n m : Nat), n.pred * m = n * m - m\n  | zero  , m => by simp\n  | succ n, m => by rw [pred_succ, succ_mul, add_sub_cancel]\n\n  theorem mul_sub_right_distrib : \u2200 (n m k : Nat), (n - m) * k = n * k - m * k\n  | n, zero  , k => by simp\n  | n, succ m, k => by rw [sub_succ, mul_pred_left, mul_sub_right_distrib, succ_mul, sub_sub]\n\n  theorem mul_sub_left_distrib (n m k : Nat) : n * (m - k) = n * m - n * k := by\n    rw [Nat.mul_comm, mul_sub_right_distrib, Nat.mul_comm m n, Nat.mul_comm n k]\n\n  theorem pos_iff_ne_zero {n : Nat} : 0 < n \u2194 n \u2260 0 :=\n    \u27e8fun h => (Nat.ne_of_lt h).symm,\n    fun h => Nat.lt_of_le_and_ne (Nat.zero_le n) h.symm\u27e9\n\n  theorem ge_one_iff_ne_zero {n : Nat} : 1 \u2264 n \u2194 n \u2260 0 := by\n    rw [\u2190pos_iff_ne_zero]; exact Iff.rfl\n\n  protected theorem sub_one (n : Nat) : n - 1 = pred n := rfl\n\n  theorem one_add (n : Nat) : 1 + n = succ n :=\n    (Nat.add_comm 1 n).trans (add_one n)\n\n  theorem pred_sub (n m : Nat) : pred n - m = pred (n - m) := by\n    rw [\u2190Nat.sub_one, sub_sub, one_add, sub_succ]\n\n  theorem le_of_not_ge {a b : Nat} : \u00ac a \u2265 b \u2192 a \u2264 b :=\n    Or.resolve_left (Nat.le_total b a)\n\n  theorem le_of_not_le {a b : Nat} : \u00ac a \u2264 b \u2192 b \u2264 a :=\n    Or.resolve_left (Nat.le_total a b)\n\n  theorem lt_trichotomy (a b : Nat) : a < b \u2228 a = b \u2228 b < a :=\n    Or.elim (Nat.le_total a b)\n      (fun h : a \u2264 b => Or.elim (Nat.lt_or_eq_of_le h)\n        (fun h : a < b => Or.inl h)\n        (fun h : a = b => Or.inr (Or.inl h)))\n      (fun h : b \u2264 a => Or.elim (Nat.lt_or_eq_of_le h)\n        (fun h : b < a => Or.inr (Or.inr h))\n        (fun h : b = a => Or.inr (Or.inl h.symm)))\n\n  theorem le_of_not_lt {a b : Nat} (h : \u00ac b < a) : a \u2264 b := by\n    cases lt_trichotomy a b with\n    | inl hlt => exact Nat.le_of_lt hlt\n    | inr h =>\n      cases h with\n      | inl heq => exact heq \u25b8 Nat.le_refl a\n      | inr hgt => exact absurd hgt h\n\n  theorem le_of_not_gt {a b : Nat} : \u00ac a > b \u2192 a \u2264 b := le_of_not_lt\n\n  theorem not_lt_of_ge {a b : Nat} (h : a \u2265 b) : \u00ac a < b :=\n    fun hab => Nat.not_le_of_gt hab h\n\n  @[simp] theorem not_lt {a b : Nat} : \u00ac a < b \u2194 b \u2264 a :=\n    \u27e8le_of_not_gt, not_lt_of_ge\u27e9\n\n  theorem not_lt_of_gt {a b : Nat} : a > b \u2192 \u00ac a \u2264 b :=\n    fun h\u2081 h\u2082 => absurd h\u2081 (not_lt_of_ge h\u2082)\n\n  @[simp] theorem not_le {a b : Nat} : \u00ac a \u2264 b \u2194 b < a :=\n    \u27e8gt_of_not_le, not_lt_of_gt\u27e9\n\n  theorem add_eq_zero {a b : Nat} : a + b = 0 \u2194 a = 0 \u2227 b = 0 :=\n    \u27e8fun h => by\n      induction a with\n      | zero => rw [Nat.zero_add] at h; exact \u27e8rfl, h\u27e9\n      | succ k ih => rw [succ_add] at h; exact absurd h (succ_ne_zero (k+b)),\n    fun \u27e8ha, hb\u27e9 => by rw [ha, hb]\u27e9\n\n  theorem add_eq_one {a b : Nat} : a + b = 1 \u2194 (a = 1 \u2227 b = 0) \u2228 (a = 0 \u2227 b = 1) := by\n    cases a with\n    | zero   =>\n      simp only [Nat.zero_eq, Nat.zero_add, false_and, false_or, true_and]; exact Iff.rfl\n    | succ a =>\n      simp only [false_and, or_false]\n      cases a with\n      | zero   =>\n        conv => lhs rhs rw [\u2190Nat.add_zero 1]\n        rw [Nat.add_left_cancel']; simp only [true_and]; exact Iff.rfl\n      | succ a =>\n        have : \u2200 n : Nat, \u00ac n.succ.succ = 1 := fun n h => absurd (Nat.succ.inj h) (Nat.succ_ne_zero n)\n        simp only [Nat.succ_add, this, false_and]\n\n  theorem mul_eq_zero (a b : Nat) : a * b = 0 \u2194 a = 0 \u2228 b = 0 :=\n    \u27e8fun h => by\n      induction a with\n      | zero      => exact Or.inl rfl\n      | succ k ih => rw [succ_mul, add_eq_zero] at h; exact Or.inr h.right,\n    fun h => by\n      cases h with\n      | inl h => rw [h, Nat.zero_mul]\n      | inr h => rw [h, Nat.mul_zero]\u27e9\n\n  theorem mul_neq_zero (a b : Nat) : a * b \u2260 0 \u2194 a \u2260 0 \u2227 b \u2260 0 := by\n    rw [\u2190M4R.not_or_iff_and_not, M4R.not_iff_not]; exact mul_eq_zero a b\n\n  theorem add_le {a b : Nat} : a + b \u2264 a \u2194 b = 0 :=\n    \u27e8fun h => by\n      conv at h => rhs rw [\u2190Nat.add_zero a]\n      exact Nat.eq_zero_of_le_zero (Nat.le_of_add_le_add_left h),\n    fun h => by rw [h, Nat.add_zero]; exact Nat.le_refl a\u27e9\n\n  theorem lt_not_symm {a b : Nat} : \u00ac(a < b \u2227 b < a) := by\n    rw [M4R.not_and_iff_or_not, Nat.not_lt, Nat.not_lt]; exact Nat.le_total b a\n\n  theorem add_sub_comm {a b c : Nat} (h : c \u2264 a) : a + b - c = a - c + b := by\n    induction b with\n    | zero      => rw [Nat.add_zero, Nat.add_zero]\n    | succ b ih =>\n      rw [Nat.add_succ, Nat.add_succ, \u2190ih, Nat.succ_sub]\n      exact Nat.add_zero _ \u25b8 Nat.add_le_add h (Nat.zero_le b)\n\n  section choose\n\n    protected def choose : Nat \u2192 Nat \u2192 Nat\n    | _    ,     0 => 1\n    | 0    , k + 1 => 0\n    | n + 1, k + 1 => Nat.choose n k + Nat.choose n (k + 1)\n\n    @[simp] theorem choose_zero_right (n : Nat) : n.choose 0 = 1 := by\n      cases n; rfl; rfl\n\n    theorem choose_zero_right_succ (n : Nat) : n.choose 0 = n.succ.choose 0 := by\n      rw [choose_zero_right, choose_zero_right]\n\n    @[simp] theorem choose_zero_succ (k : Nat) : (0 : Nat).choose k.succ = 0 := rfl\n\n    theorem choose_succ_succ (n k : Nat) : n.succ.choose k.succ = n.choose k + n.choose (succ k) := rfl\n\n    theorem choose_eq_zero_of_lt : \u2200 {n k : Nat}, n < k \u2192 n.choose k = 0\n    | _    ,     0, hk => absurd hk (Nat.not_lt_zero _)\n    | 0    , k + 1, hk => choose_zero_succ _\n    | n + 1, k + 1, hk => by\n      rw [choose_succ_succ, choose_eq_zero_of_lt (lt_of_succ_lt_succ hk),\n        choose_eq_zero_of_lt (lt_of_succ_lt hk)]\n\n    @[simp] theorem choose_self (n : Nat) : n.choose n = 1 := by\n      induction n with\n      | zero      => rfl\n      | succ n ih => simp only [Nat.choose]; rw [ih, choose_eq_zero_of_lt (lt_succ_self n)]\n\n    theorem choose_self_succ (n : Nat) : n.choose n = n.succ.choose n.succ := by\n      rw [choose_self, choose_self]\n\n    @[simp] theorem choose_succ_self (n : Nat) : n.choose n.succ = 0 :=\n      choose_eq_zero_of_lt (lt_succ_self _)\n\n    @[simp] theorem choose_one_right (n : Nat) : n.choose 1 = n := by\n      induction n with\n      | zero => rfl\n      | succ n ih => simp only [Nat.choose]; rw [ih, choose_zero_right, one_add]\n\n    theorem choose_pred {n k : Nat} (h : 0 < k) : n.choose k + n.choose k.pred = n.succ.choose k := by\n      cases k with\n      | zero => contradiction\n      | succ k => rw [Nat.pred_succ, Nat.add_comm]; rfl\n\n  end choose\n\n  theorem le_succ_pred (n : Nat) : n \u2264 n.pred.succ := by\n    byCases h : n > 0\n    { exact Nat.le_of_eq (succ_pred_eq_of_pos h).symm }\n    { exact Nat.eq_zero_of_le_zero (Nat.le_of_not_gt h) \u25b8 Nat.zero_le _ }\n\n  theorem pred_le_iff {n m : Nat} : n.pred \u2264 m \u2194 n \u2264 m.succ :=\n    \u27e8fun h => Nat.le_trans (le_succ_pred n) (succ_le_succ h),\n     fun h => by cases n with\n      | zero   => exact Nat.zero_le m\n      | succ n => exact Nat.le_of_succ_le_succ h\u27e9\n\n  theorem le_pred_iff {n m : Nat} (hm : m > 0) : n \u2264 m.pred \u2194 n.succ \u2264 m :=\n    \u27e8fun h => succ_pred_eq_of_pos hm \u25b8 Nat.succ_le_succ h,\n     fun h => by cases m with\n      | zero   => exact absurd hm (Nat.lt_irrefl 0)\n      | succ m => exact Nat.le_of_succ_le_succ h\u27e9\n\n  theorem sub_le_iff_right {a b c : Nat} : a - c \u2264 b \u2194 a \u2264 b + c := by\n    induction c generalizing b with\n    | zero      => rw [Nat.sub_zero, Nat.add_zero]; exact Iff.rfl\n    | succ c ih => rw [sub_succ, add_succ, \u2190succ_add, pred_le_iff]; exact ih\n\n  theorem le_zero {n : Nat} : n \u2264 0 \u2194 n = 0 :=\n    \u27e8Nat.eq_zero_of_le_zero, (\u00b7 \u25b8 Nat.le_refl n)\u27e9\n\n  theorem le_sub_iff_right {a b c : Nat} (h : c \u2264 b) : a \u2264 b - c \u2194 a + c \u2264 b := by\n    induction c generalizing a with\n    | zero      => rw [Nat.sub_zero, Nat.add_zero]; exact Iff.rfl\n    | succ c ih =>\n      rw [sub_succ, add_succ, \u2190succ_add, le_pred_iff (sub_pos_of_lt h)]\n      exact ih (Nat.le_trans (Nat.le_succ c) h)\n\n  theorem sub_le_sub {a b c : Nat} (ha : a \u2264 c) (hb : b \u2264 c) : a \u2264 b \u2194 c - b \u2264 c - a := by\n    rw [sub_le_iff_right, Nat.add_comm, \u2190add_sub_assoc ha, le_sub_iff_right\n      (Nat.le_trans ha (Nat.le_add_left c b)), Nat.add_comm]\n    exact \u27e8(Nat.add_le_add_right \u00b7 c), Nat.le_of_add_le_add_right\u27e9\n\n  theorem lt_sub_iff_right {a b c : Nat} (h : c \u2264 b) : a < b - c \u2194 a + c < b :=\n    \u27e8fun h' => Nat.lt_of_le_and_ne ((le_sub_iff_right h).mp (Nat.le_of_lt h'))\n      (fun h'' => absurd ((eq_sub_iff_add_eq h).mpr h'') (Nat.ne_of_lt h')),\n    fun h' => Nat.lt_of_le_and_ne ((le_sub_iff_right h).mpr (Nat.le_of_lt h'))\n      (fun h'' => absurd ((eq_sub_iff_add_eq h).mp h'') (Nat.ne_of_lt h'))\u27e9\n\n  theorem sub_lt_iff_right {a b c : Nat} (h : c \u2264 a) : a - c < b \u2194 a < b + c := by\n    apply M4R.not_iff_not.mp\n    simp only [Nat.not_lt]\n    exact le_sub_iff_right h\n\n  theorem zero_lt_iff_neq_zero {n : Nat} : 0 < n \u2194 n \u2260 0 :=\n    \u27e8fun h\u2081 h\u2082 => absurd (h\u2082 \u25b8 h\u2081) (Nat.lt_irrefl 0), fun h => by\n      cases n; contradiction; exact Nat.zero_lt_succ _\u27e9\n\n  theorem lt.dest {m n : Nat} (h : m < n) : \u2203 k, k \u2260 0 \u2227 m + k = n :=\n    let \u27e8k, hk\u27e9 := le.dest (Nat.le_of_lt h)\n    \u27e8k, fun h' => absurd ((h' \u25b8 hk : m + 0 = n) \u25b8 h) (Nat.lt_irrefl n), hk\u27e9\n\n  theorem ne_zero_dest {m : Nat} (h : m \u2260 0) : \u2203 k, m = k + 1 :=\n    \u27e8m.pred, (succ_pred_eq_of_pos (pos_iff_ne_zero.mpr h)).symm\u27e9\n\n  theorem of_lt_add_left {n m : Nat} (h : n < m + n) : 0 < m :=\n    Nat.sub_self n \u25b8 (sub_lt_iff_right (Nat.le_refl n)).mpr h\n\n  theorem of_lt_add_right {n m : Nat} (h : n < n + m) : 0 < m :=\n    of_lt_add_left (Nat.add_comm n m \u25b8 h : n < m + n)\n\n  theorem lt_add_pos_left (n : Nat) {m : Nat} (h : m \u2260 0) : n < m + n :=\n    Nat.lt_of_le_and_ne (le_add_left n m)\n      (fun h' => absurd (Nat.sub_self n \u25b8 (sub_eq_iff_eq_add (Nat.le_refl n)).mpr h') h.symm)\n\n  theorem lt_add_pos_right (n : Nat) {m : Nat} (h : m \u2260 0) : n < n + m :=\n    Nat.add_comm n m \u25b8 lt_add_pos_left n h\n\n  theorem sub_pos_iff_lt {m n : Nat} : 0 < m - n \u2194 n < m :=\n    (pos_iff_ne_zero.trans (M4R.not_iff_not.mpr (sub_eq_zero_iff_le m n))).trans Nat.not_le\n\n  theorem strong_induction (p : Nat \u2192 Prop) (ih : \u2200 n, (\u2200 m, m < n \u2192 p m) \u2192 p n) (n : Nat) : p n :=\n    ih n fun m hm => by\n      induction n generalizing m with\n      | zero       => contradiction\n      | succ n ih' => exact (Nat.lt_or_eq_of_le (Nat.le_of_succ_le_succ hm)).elim (ih' m) (fun h => ih m (h \u25b8 ih'))\n\nend Nat\n\nnamespace Int\n\n  /- Helper \"packing\" theorems -/\n  @[simp] theorem zero_eq : ofNat 0 = 0 := rfl\n  @[simp] theorem one_eq : ofNat 1 = 1 := rfl\n  @[simp] theorem add_eq : Int.add x y = x + y := rfl\n  @[simp] theorem sub_eq : Int.sub x y = x - y := rfl\n  @[simp] theorem mul_eq : Int.mul x y = x * y := rfl\n  @[simp] theorem neg_eq : Int.neg x = - x := rfl\n  @[simp] theorem lt_eq : Int.lt x y = (x < y) := rfl\n  @[simp] theorem le_eq : Int.le x y = (x \u2264 y) := rfl\n\n  @[simp] theorem negOfNat_of_succ (n : Nat) : -(ofNat n.succ) = negSucc n := rfl\n  @[simp] theorem ofNat_add_ofNat (m n : Nat) : ofNat m + ofNat n = ofNat (m + n) := rfl\n  @[simp] theorem ofNat_add_negSucc_ofNat (m n : Nat) :\n                  ofNat m + negSucc n = subNatNat m (n.succ) := rfl\n  @[simp] theorem negSucc_ofNat_add_ofNat (m n : Nat) :\n                  negSucc m + ofNat n = subNatNat n (m.succ) := rfl\n  @[simp] theorem negSucc_ofNat_add_negSucc_ofNat (m n : Nat) :\n                  negSucc m + negSucc n = negSucc (m + n).succ := rfl\n\n  @[simp] theorem ofNat_mul_ofNat (m n : Nat) : ofNat m * ofNat n = ofNat (m * n) := rfl\n  @[simp] theorem ofNat_mul_negSucc_ofNat (m n : Nat) :\n                  ofNat m * negSucc n = negOfNat (m * n.succ) := rfl\n  @[simp] theorem negSucc_ofNat_ofNat (m n : Nat) :\n                  negSucc m * ofNat n = negOfNat (m.succ * n) := rfl\n  @[simp] theorem mul_negSucc_ofNat_negSucc_ofNat (m n : Nat) :\n                negSucc m * negSucc n = ofNat (m.succ * n.succ) := rfl\n\n  @[simp] protected theorem neg_zero : - (0 : Int) = 0 := rfl\n  @[simp] protected theorem negOfNat_zero : negOfNat 0 = 0 := rfl\n\n  @[simp] theorem subNatNat_self: \u2200 n : Nat, subNatNat n n = 0\n  | 0            => rfl\n  | (Nat.succ m) => by simp only [subNatNat, Nat.sub_self]\n\n  @[simp] protected theorem add_neg : \u2200 n : Int, n + -n = 0\n  | ofNat 0 => rfl\n  | ofNat (Nat.succ k) => by\n    simp only [Neg.neg, Int.neg, negOfNat, HAdd.hAdd, Add.add, Int.add, subNatNat_self]\n  | negSucc k => by\n    simp only [Neg.neg, Int.neg, negOfNat, HAdd.hAdd, Add.add, Int.add, subNatNat_self]\n\n  protected theorem add_comm : \u2200 m n : Int, m + n = n + m\n  | ofNat   m', ofNat   n' => by simp [Nat.add_comm]\n  | ofNat   m', negSucc n' => rfl\n  | negSucc m', ofNat   n' => rfl\n  | negSucc m', negSucc n' => by simp [Nat.add_comm]\n\n  @[simp] protected theorem add_zero : \u2200 n : Int, n + 0 = n\n  | ofNat   k => rfl\n  | negSucc k => rfl\n\n  @[simp] protected theorem zero_add : \u2200 n : Int, 0 + n = n :=\n    fun n => by rw [Int.add_comm, Int.add_zero]\n\n  theorem subNatNat_elim (m n : Nat) (P : Nat \u2192 Nat \u2192 Int \u2192 Prop)\n    (hp : \u2200 i n : Nat, P (n + i) n (ofNat i))\n    (hn : \u2200 i m : Nat, P m (m + i + 1) (negSucc i)) :\n    P m n (subNatNat m n) := by\n      have H : \u2200 k : Nat, n - m = k \u2192 P m n (subNatNat m n) := by\n        intro k; simp only [subNatNat]; cases k with\n        | zero =>\n          intro e; simp only [e]\n          cases (Nat.le.dest (Nat.le_of_sub_eq_zero e)) with\n          | intro k h =>\n            rw [h.symm, Nat.add_sub_cancel_left]\n            exact hp k n\n        | succ k' =>\n          intro heq; simp only [heq]\n          have h : m \u2264 n := Nat.le_of_lt (Nat.lt_of_sub_eq_succ heq)\n          rw [Nat.sub_eq_iff_eq_add h] at heq\n          rw [heq, Nat.add_comm]\n          exact hn k' m\n      exact H (n - m) rfl\n\n  theorem subNatNat_add_left {m n : Nat} : subNatNat (m + n) m = ofNat n := by\n    simp only [subNatNat]\n    rw [Nat.sub_eq_zero_of_le, Nat.add_sub_cancel_left]\n    exact Nat.le_add_right m n\n\n  theorem subNatNat_add_right {m n : Nat} : subNatNat m (m + n + 1) = negSucc n := by\n    simp only [subNatNat, Nat.add_assoc, Nat.add_sub_cancel_left]; rfl\n\n  theorem subNatNat_add_add (m n k : Nat) : subNatNat (m + k) (n + k) = subNatNat m n :=\n    subNatNat_elim m n (fun m n i => subNatNat (m + k) (n + k) = i)\n      (fun i n => by\n        have : n + i + k = (n + k) + i := by simp only [Nat.add_comm, Nat.add_left_comm]\n        simp only [this]; exact subNatNat_add_left)\n      (fun i m => by\n        have : m + i + 1 + k = (m + k) + i + 1 := by simp only [Nat.add_comm, Nat.add_left_comm]\n        simp only [this]; exact subNatNat_add_right)\n\n  theorem subNatNat_of_sub_eq_zero {m n : Nat} (h : n - m = 0) : subNatNat m n = ofNat (m - n) := by\n    simp only [subNatNat, h]\n\n  theorem subNatNat_of_sub_eq_succ {m n k : Nat} (h : n - m = k.succ) : subNatNat m n = negSucc k := by\n    simp only [subNatNat, h]\n\n  theorem subNatNat_of_ge {m n : Nat} (h : m \u2265 n) : subNatNat m n = ofNat (m - n) :=\n    subNatNat_of_sub_eq_zero (Nat.sub_eq_zero_of_le h)\n\n  theorem subNatNat_of_lt {m n : Nat} (h : m < n) : subNatNat m n = negSucc (n - m).pred := by\n    rw [subNatNat_of_sub_eq_succ]\n    exact Eq.symm (Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h))\n\n  theorem subNatNat_sub {m n : Nat} (h : m \u2265 n) (k : Nat) : subNatNat (m - n) k = subNatNat m (k + n) := by\n      rw [\u2190subNatNat_add_add (m-n) k n, Nat.sub_add_cancel h]\n\n  theorem subNatNat_add (m n k : Nat) : subNatNat (m + n) k = ofNat m + subNatNat n k := by\n    cases Nat.le_or_lt k n with\n    | inl h =>\n      rw [subNatNat_of_ge h]\n      have h\u2082 : k \u2264 m + n := (Nat.le_trans h (Nat.le_add_left _ _))\n      simp [subNatNat_of_ge h\u2082, Nat.add_sub_assoc h]\n    | inr h =>\n      rw [subNatNat_of_lt h, ofNat_add_negSucc_ofNat, Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h)]\n      have := subNatNat_add_add m (k - n) n\n      rw [Nat.sub_add_cancel (Nat.le_of_lt h)] at this\n      exact this\n\n  theorem subNatNat_add_negSucc_ofNat (m n k : Nat) : subNatNat m n + negSucc k = subNatNat m (n + k.succ) := by\n    cases Nat.le_or_lt n m with\n    | inl h => rw [subNatNat_of_ge h, ofNat_add_negSucc_ofNat, subNatNat_sub h, Nat.add_comm]\n    | inr h =>\n      have h\u2082 : m < n + k.succ := Nat.lt_of_lt_of_le h (Nat.le_add_right _ _)\n      have h\u2083 : m \u2264 n + k := Nat.le_of_succ_le_succ h\u2082\n      rw [subNatNat_of_lt h, subNatNat_of_lt h\u2082]; simp; rw [Nat.add_comm, \u2190Nat.add_succ,\n        Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h), Nat.add_succ, Nat.succ_sub h\u2083,\n        Nat.pred_succ, Nat.add_comm n, Nat.add_sub_assoc (Nat.le_of_lt h)]\n\n  private theorem add_assoc\u2081 (a b : Nat) : \u2200 c : Int, ofNat a + ofNat b + c = ofNat a + (ofNat b + c)\n  | ofNat   c => by simp [Nat.add_assoc]\n  | negSucc c => by simp [subNatNat_add]\n\n  private theorem add_assoc\u2082 (a b c : Nat) : negSucc a + negSucc b + ofNat c = negSucc a + (negSucc b + ofNat c) := by\n    rw [negSucc_ofNat_add_negSucc_ofNat, Int.add_comm, ofNat_add_negSucc_ofNat,\n      Int.add_comm (negSucc b), ofNat_add_negSucc_ofNat, Int.add_comm, subNatNat_add_negSucc_ofNat,\n      Nat.add_succ, Nat.succ_add, Nat.add_comm]\n\n  protected theorem add_assoc : \u2200 a b c : Int, a + b + c = a + (b + c)\n  | ofNat   a, ofNat   b,         c => add_assoc\u2081 a b c\n  | ofNat   a,         b, ofNat   c => by\n    rw [Int.add_comm, \u2190add_assoc\u2081, Int.add_comm (ofNat c), add_assoc\u2081, Int.add_comm b]\n  |         a, ofNat   b, ofNat   c => by\n    rw [Int.add_comm, Int.add_comm a, \u2190add_assoc\u2081, Int.add_comm a, Int.add_comm (ofNat c)]\n  | negSucc a, negSucc b, ofNat   c => add_assoc\u2082 a b c\n  | negSucc a, ofNat   b, negSucc c => by\n    rw [Int.add_comm, \u2190add_assoc\u2082, Int.add_comm (ofNat b), \u2190add_assoc\u2082, Int.add_comm (negSucc a)]\n  | ofNat   a, negSucc b, negSucc c => by\n    rw [Int.add_comm, Int.add_comm (ofNat a), Int.add_comm (ofNat a), \u2190add_assoc\u2082, Int.add_comm (negSucc c)]\n  | negSucc a, negSucc b, negSucc c => by\n    simp [Nat.succ_eq_add_one] rw [Nat.add_right_comm b, \u2190Nat.add_assoc, \u2190Nat.add_assoc]\n\n  protected theorem mul_comm : \u2200 a b : Int, a * b = b * a\n  | ofNat   a, ofNat   b => by simp [Nat.mul_comm]\n  | ofNat   a, negSucc b => by simp [Nat.mul_comm]\n  | negSucc a, ofNat   b => by simp [Nat.mul_comm]\n  | negSucc a, negSucc b => by simp [Nat.mul_comm]\n\n  @[simp] protected theorem mul_one : \u2200 a : Int, a * 1 = a\n  | ofNat   a => by simp [HMul.hMul, Mul.mul, Int.mul]; exact Nat.mul_one a\n  | negSucc a => by simp [HMul.hMul, Mul.mul, Int.mul, negOfNat]; rw [Nat.mul_one a.succ]\n\n  @[simp] protected theorem one_mul : \u2200 a : Int, 1 * a = a :=\n    fun a => Int.mul_comm a 1 \u25b8 Int.mul_one a\n\n  @[simp] protected theorem mul_zero : \u2200 a : Int, a * 0 = 0\n  | ofNat   m => rfl\n  | negSucc m => rfl\n\n  @[simp] protected theorem zero_mul : \u2200 a : Int, 0 * a = 0 :=\n    fun a => Int.mul_comm a 0 \u25b8 Int.mul_zero a\n\n  theorem negOfNat_eq_subNatNat_zero : \u2200 n, negOfNat n = subNatNat 0 n\n  | Nat.zero   => rfl\n  | Nat.succ n => rfl\n\n  @[simp] theorem ofNat_mul_negOfNat (m : Nat) : \u2200n, ofNat m * negOfNat n = negOfNat (m * n)\n  | Nat.zero   => rfl\n  | Nat.succ n => by simp [negOfNat]\n\n  @[simp] theorem negOfNat_mul_ofNat (m n : Nat) : negOfNat m * ofNat n = negOfNat (m * n) := by\n    rw [Int.mul_comm]; simp only [ofNat_mul_negOfNat, Nat.mul_comm]\n\n  @[simp] theorem negSucc_ofNat_mul_negOfNat (m : Nat) : \u2200 n, negSucc m * negOfNat n = ofNat (m.succ * n)\n  | Nat.zero   => rfl\n  | Nat.succ n => by simp [negOfNat]\n\n  @[simp] theorem negOfNat_mul_negSucc_ofNat (m n : Nat) : negOfNat n * negSucc m = ofNat (n * m.succ) := by\n    rw [Int.mul_comm]; simp [negSucc_ofNat_mul_negOfNat, Nat.mul_comm]\n\n  @[simp] theorem ofNat_mul_subNatNat (m n k : Nat) : ofNat m * subNatNat n k = subNatNat (m * n) (m * k) := by\n    cases Nat.eq_zero_or_pos m with\n    | inl h => simp [h]\n    | inr h =>\n      cases Nat.lt_or_ge n k with\n      | inl h' =>\n        have : m * n < m * k := Nat.mul_lt_mul_of_pos_left h' h\n        rw [subNatNat_of_lt h', subNatNat_of_lt this]; simp\n        rw [Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h'),\n          \u2190negOfNat_of_succ, Nat.mul_sub_left_distrib,\n          Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt this)]; rfl\n      | inr h' =>\n        have : m * k \u2264 m * n := Nat.mul_le_mul_left _ h'\n        rw [subNatNat_of_ge h', subNatNat_of_ge this]; simp\n        rw [Nat.mul_sub_left_distrib]\n\n  @[simp] theorem negOfNat_add : \u2200 (m n : Nat), negOfNat m + negOfNat n = negOfNat (m + n)\n  | Nat.zero  ,          n   => by simp\n  | Nat.succ m,          0 => by simp\n  | Nat.succ m, Nat.succ n => by simp [Nat.succ_add]; rfl\n\n  @[simp] theorem negSucc_ofNat_mul_subNatNat (m n k : Nat) :\n    negSucc m * subNatNat n k = subNatNat (m.succ * k) (m.succ * n) := by\n      cases Nat.lt_or_ge n k with\n      | inl h =>\n        have h' : m.succ * n < m.succ * k := Nat.mul_lt_mul_of_pos_left h (Nat.succ_pos m)\n        rw [subNatNat_of_lt h, subNatNat_of_ge (Nat.le_of_lt h')]\n        simp [Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h), Nat.mul_sub_left_distrib]\n      | inr h =>\n        cases Nat.lt_or_eq_of_le h with\n        | inl h' =>\n          have h\u2081 : m.succ * n > m.succ * k := Nat.mul_lt_mul_of_pos_left h' (Nat.succ_pos m)\n          rw [subNatNat_of_ge h, subNatNat_of_lt h\u2081]; simp [Nat.mul_sub_left_distrib, Nat.mul_comm]\n          rw [Nat.mul_comm k, Nat.mul_comm n, \u2190Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h\u2081),\n              \u2190negOfNat_of_succ]; rfl\n        | inr h' => rw [h']; simp\n\n  protected theorem mul_assoc : \u2200 a b c : Int, (a * b) * c = a * (b * c)\n  | ofNat   a, ofNat   b, ofNat   c => by simp [Nat.mul_assoc]\n  | ofNat   a, ofNat   b, negSucc c => by simp [Nat.mul_assoc]\n  | ofNat   a, negSucc b, ofNat   c => by simp [Nat.mul_assoc]\n  | ofNat   a, negSucc b, negSucc c => by simp [Nat.mul_assoc]\n  | negSucc a, ofNat   b, ofNat   c => by simp [Nat.mul_assoc]\n  | negSucc a, ofNat   b, negSucc c => by simp [Nat.mul_assoc]\n  | negSucc a, negSucc b, ofNat   c => by simp [Nat.mul_assoc]\n  | negSucc a, negSucc b, negSucc c => by simp [Nat.mul_assoc]\n\n  protected theorem mul_distrib_left : \u2200 a b c : Int, a * (b + c) = a * b + a * c\n  | ofNat   a, ofNat   b, ofNat   c => by simp [Nat.left_distrib]\n  | ofNat   a, ofNat   b, negSucc c => by simp [negOfNat_eq_subNatNat_zero]; rw [\u2190subNatNat_add]; rfl\n  | ofNat   a, negSucc b, ofNat   c => by simp [negOfNat_eq_subNatNat_zero]; rw [Int.add_comm, \u2190subNatNat_add]; rfl\n  | ofNat   a, negSucc b, negSucc c => by simp; rw [\u2190Nat.left_distrib, Nat.succ_add, Nat.add_succ]\n  | negSucc a, ofNat   b, ofNat   c => by simp [Nat.mul_comm]; rw [\u2190Nat.right_distrib, Nat.mul_comm]\n  | negSucc a, ofNat   b, negSucc c => by simp [negOfNat_eq_subNatNat_zero]; rw [Int.add_comm, \u2190subNatNat_add]; rfl\n  | negSucc a, negSucc b, ofNat   c => by simp [negOfNat_eq_subNatNat_zero]; rw [\u2190subNatNat_add]; rfl\n  | negSucc a, negSucc b, negSucc c => by simp; rw [\u2190Nat.left_distrib, Nat.succ_add, Nat.add_succ]\n\n  protected theorem mul_distrib_right : \u2200 a b c : Int, (a + b) * c = a * c + b * c := fun a b c => by\n    rw [Int.mul_comm, Int.mul_distrib_left]; simp [Int.mul_comm]\n\nend Int\n", "meta": {"author": "Hop311", "repo": "M4R", "sha": "ebd1b04af344f9737d290bf8b48b3cde35e9787b", "save_path": "github-repos/lean/Hop311-M4R", "path": "github-repos/lean/Hop311-M4R/M4R-ebd1b04af344f9737d290bf8b48b3cde35e9787b/M4R/Numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656671, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7083473444314201}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module order.locally_finite\n! leanprover-community/mathlib commit 2445c98ae4b87eabebdde552593519b9b6dc350c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Preimage\nimport Mathlib.Data.Set.Intervals.UnorderedInterval\n\n/-!\n# Locally finite orders\n\nThis file defines locally finite orders.\n\nA locally finite order is an order for which all bounded intervals are finite. This allows to make\nsense of `Icc`/`Ico`/`Ioc`/`Ioo` as lists, multisets, or finsets.\nFurther, if the order is bounded above (resp. below), then we can also make sense of the\n\"unbounded\" intervals `Ici`/`Ioi` (resp. `Iic`/`Iio`).\n\nMany theorems about these intervals can be found in `Data.Finset.LocallyFinite`.\n\n## Examples\n\nNaturally occurring locally finite orders are `\u2115`, `\u2124`, `\u2115+`, `Fin n`, `\u03b1 \u00d7 \u03b2` the product of two\nlocally finite orders, `\u03b1 \u2192\u2080 \u03b2` the finitely supported functions to a locally finite order `\u03b2`...\n\n## Main declarations\n\nIn a `LocallyFiniteOrder`,\n* `Finset.Icc`: Closed-closed interval as a finset.\n* `Finset.Ico`: Closed-open interval as a finset.\n* `Finset.Ioc`: Open-closed interval as a finset.\n* `Finset.Ioo`: Open-open interval as a finset.\n* `Finset.uIcc`: Unordered closed interval as a finset.\n* `Multiset.Icc`: Closed-closed interval as a multiset.\n* `Multiset.Ico`: Closed-open interval as a multiset.\n* `Multiset.Ioc`: Open-closed interval as a multiset.\n* `Multiset.Ioo`: Open-open interval as a multiset.\n\nIn a `LocallyFiniteOrderTop`,\n* `Finset.Ici`: Closed-infinite interval as a finset.\n* `Finset.Ioi`: Open-infinite interval as a finset.\n* `Multiset.Ici`: Closed-infinite interval as a multiset.\n* `Multiset.Ioi`: Open-infinite interval as a multiset.\n\nIn a `LocallyFiniteOrderBot`,\n* `Finset.Iic`: Infinite-open interval as a finset.\n* `Finset.Iio`: Infinite-closed interval as a finset.\n* `Multiset.Iic`: Infinite-open interval as a multiset.\n* `Multiset.Iio`: Infinite-closed interval as a multiset.\n\n## Instances\n\nA `LocallyFiniteOrder` instance can be built\n* for a subtype of a locally finite order. See `Subtype.locallyFiniteOrder`.\n* for the product of two locally finite orders. See `Prod.locallyFiniteOrder`.\n* for any fintype (but not as an instance). See `Fintype.toLocallyFiniteOrder`.\n* from a definition of `Finset.Icc` alone. See `LocallyFiniteOrder.ofIcc`.\n* by pulling back `LocallyFiniteOrder \u03b2` through an order embedding `f : \u03b1 \u2192o \u03b2`. See\n  `OrderEmbedding.locallyFiniteOrder`.\n\nInstances for concrete types are proved in their respective files:\n* `\u2115` is in `Data.Nat.Interval`\n* `\u2124` is in `Data.Int.Interval`\n* `\u2115+` is in `Data.PNat.Interval`\n* `Fin n` is in `Data.Fin.Interval`\n* `Finset \u03b1` is in `Data.Finset.Interval`\n* `\u03a3 i, \u03b1 i` is in `Data.Sigma.Interval`\nAlong, you will find lemmas about the cardinality of those finite intervals.\n\n## TODO\n\nProvide the `LocallyFiniteOrder` instance for `\u03b1 \u00d7\u2097 \u03b2` where `LocallyFiniteOrder \u03b1` and\n`Fintype \u03b2`.\n\nProvide the `LocallyFiniteOrder` instance for `\u03b1 \u2192\u2080 \u03b2` where `\u03b2` is locally finite. Provide the\n`LocallyFiniteOrder` instance for `\u03a0\u2080 i, \u03b2 i` where all the `\u03b2 i` are locally finite.\n\nFrom `LinearOrder \u03b1`, `NoMaxOrder \u03b1`, `LocallyFiniteOrder \u03b1`, we can also define an\norder isomorphism `\u03b1 \u2243 \u2115` or `\u03b1 \u2243 \u2124`, depending on whether we have `OrderBot \u03b1` or\n`NoMinOrder \u03b1` and `Nonempty \u03b1`. When `OrderBot \u03b1`, we can match `a : \u03b1` to `(Iio a).card`.\n\nWe can provide `SuccOrder \u03b1` from `LinearOrder \u03b1` and `LocallyFiniteOrder \u03b1` using\n\n```lean\nlemma exists_min_greater [LinearOrder \u03b1] [LocallyFiniteOrder \u03b1] {x ub : \u03b1} (hx : x < ub) :\n  \u2203 lub, x < lub \u2227 \u2200 y, x < y \u2192 lub \u2264 y :=\nbegin -- very non golfed\n  have h : (Finset.Ioc x ub).Nonempty := \u27e8ub, Finset.mem_Ioc_iff.2 \u27e8hx, le_rfl\u27e9\u27e9\n  use Finset.min' (Finset.Ioc x ub) h\n  constructor\n  \u00b7 have := Finset.min'_mem _ h\n    simp * at *\n  rintro y hxy\n  obtain hy | hy := le_total y ub\n  apply Finset.min'_le\n  simp * at *\n  exact (Finset.min'_le _ _ (Finset.mem_Ioc_iff.2 \u27e8hx, le_rfl\u27e9)).trans hy\nend\n```\nNote that the converse is not true. Consider `{-2^z | z : \u2124} \u222a {2^z | z : \u2124}`. Any element has a\nsuccessor (and actually a predecessor as well), so it is a `SuccOrder`, but it's not locally finite\nas `Icc (-1) 1` is infinite.\n-/\n\n\nopen Finset Function\n\n/-- A locally finite order is an order where bounded intervals are finite. When you don't care too\nmuch about definitional equality, you can use `LocallyFiniteOrder.ofIcc` or\n`LocallyFiniteOrder.ofFiniteIcc` to build a locally finite order from just `Finset.Icc`. -/\nclass LocallyFiniteOrder (\u03b1 : Type _) [Preorder \u03b1] where\n  /-- Left-closed right-closed interval -/\n  finsetIcc : \u03b1 \u2192 \u03b1 \u2192 Finset \u03b1\n  /-- Left-closed right-open interval -/\n  finsetIco : \u03b1 \u2192 \u03b1 \u2192 Finset \u03b1\n  /-- Left-open right-closed interval -/\n  finsetIoc : \u03b1 \u2192 \u03b1 \u2192 Finset \u03b1\n  /-- Left-open right-open interval -/\n  finsetIoo : \u03b1 \u2192 \u03b1 \u2192 Finset \u03b1\n  /-- `x \u2208 finsetIcc a b \u2194 a \u2264 x \u2227 x \u2264 b` -/\n  finset_mem_Icc : \u2200 a b x : \u03b1, x \u2208 finsetIcc a b \u2194 a \u2264 x \u2227 x \u2264 b\n  /-- `x \u2208 finsetIco a b \u2194 a \u2264 x \u2227 x < b` -/\n  finset_mem_Ico : \u2200 a b x : \u03b1, x \u2208 finsetIco a b \u2194 a \u2264 x \u2227 x < b\n  /-- `x \u2208 finsetIoc a b \u2194 a < x \u2227 x \u2264 b` -/\n  finset_mem_Ioc : \u2200 a b x : \u03b1, x \u2208 finsetIoc a b \u2194 a < x \u2227 x \u2264 b\n  /-- `x \u2208 finsetIoo a b \u2194 a < x \u2227 x < b` -/\n  finset_mem_Ioo : \u2200 a b x : \u03b1, x \u2208 finsetIoo a b \u2194 a < x \u2227 x < b\n#align locally_finite_order LocallyFiniteOrder\n\n/-- A locally finite order top is an order where all intervals bounded above are finite. This is\nslightly weaker than `LocallyFiniteOrder` + `OrderTop` as it allows empty types. -/\nclass LocallyFiniteOrderTop (\u03b1 : Type _) [Preorder \u03b1] where\n  /-- Left-open right-infinite interval -/\n  finsetIoi : \u03b1 \u2192 Finset \u03b1\n  /-- Left-closed right-infinite interval -/\n  finsetIci : \u03b1 \u2192 Finset \u03b1\n  /-- `x \u2208 finsetIci a \u2194 a \u2264 x` -/\n  finset_mem_Ici : \u2200 a x : \u03b1, x \u2208 finsetIci a \u2194 a \u2264 x\n  /-- `x \u2208 finsetIoi a \u2194 a < x` -/\n  finset_mem_Ioi : \u2200 a x : \u03b1, x \u2208 finsetIoi a \u2194 a < x\n#align locally_finite_order_top LocallyFiniteOrderTop\n\n/-- A locally finite order bot is an order where all intervals bounded below are finite. This is\nslightly weaker than `LocallyFiniteOrder` + `OrderBot` as it allows empty types. -/\nclass LocallyFiniteOrderBot (\u03b1 : Type _) [Preorder \u03b1] where\n  /-- Left-infinite right-open interval -/\n  finsetIio : \u03b1 \u2192 Finset \u03b1\n  /-- Left-infinite right-closed interval -/\n  finsetIic : \u03b1 \u2192 Finset \u03b1\n  /-- `x \u2208 finsetIic a \u2194 x \u2264 a` -/\n  finset_mem_Iic : \u2200 a x : \u03b1, x \u2208 finsetIic a \u2194 x \u2264 a\n  /-- `x \u2208 finsetIio a \u2194 x < a` -/\n  finset_mem_Iio : \u2200 a x : \u03b1, x \u2208 finsetIio a \u2194 x < a\n#align locally_finite_order_bot LocallyFiniteOrderBot\n\n/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing\nthe ends. As opposed to `LocallyFiniteOrder.ofIcc`, this one requires `DecidableRel (\u00b7 \u2264 \u00b7)` but\nonly `Preorder`. -/\ndef LocallyFiniteOrder.ofIcc' (\u03b1 : Type _) [Preorder \u03b1] [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n    (finsetIcc : \u03b1 \u2192 \u03b1 \u2192 Finset \u03b1) (mem_Icc : \u2200 a b x, x \u2208 finsetIcc a b \u2194 a \u2264 x \u2227 x \u2264 b) :\n    LocallyFiniteOrder \u03b1 :=\n  { finsetIcc\n    finsetIco := fun a b => (finsetIcc a b).filter fun x => \u00acb \u2264 x\n    finsetIoc := fun a b => (finsetIcc a b).filter fun x => \u00acx \u2264 a\n    finsetIoo := fun a b => (finsetIcc a b).filter fun x => \u00acx \u2264 a \u2227 \u00acb \u2264 x\n    finset_mem_Icc := mem_Icc\n    finset_mem_Ico := fun a b x => by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_not_le]\n    finset_mem_Ioc := fun a b x => by\n      rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_not_le]\n    finset_mem_Ioo := fun a b x => by\n      rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_not_le, lt_iff_le_not_le] }\n#align locally_finite_order.of_Icc' LocallyFiniteOrder.ofIcc'\n\n/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing\nthe ends. As opposed to `LocallyFiniteOrder.ofIcc`, this one requires `PartialOrder` but only\n`DecidableEq`. -/\ndef LocallyFiniteOrder.ofIcc (\u03b1 : Type _) [PartialOrder \u03b1] [DecidableEq \u03b1]\n    (finsetIcc : \u03b1 \u2192 \u03b1 \u2192 Finset \u03b1) (mem_Icc : \u2200 a b x, x \u2208 finsetIcc a b \u2194 a \u2264 x \u2227 x \u2264 b) :\n    LocallyFiniteOrder \u03b1 :=\n  { finsetIcc\n    finsetIco := fun a b => (finsetIcc a b).filter fun x => x \u2260 b\n    finsetIoc := fun a b => (finsetIcc a b).filter fun x => a \u2260 x\n    finsetIoo := fun a b => (finsetIcc a b).filter fun x => a \u2260 x \u2227 x \u2260 b\n    finset_mem_Icc := mem_Icc\n    finset_mem_Ico := fun a b x => by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_and_ne]\n    finset_mem_Ioc := fun a b x => by\n      rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_and_ne]\n    finset_mem_Ioo := fun a b x => by\n      rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_and_ne, lt_iff_le_and_ne] }\n#align locally_finite_order.of_Icc LocallyFiniteOrder.ofIcc\n\n/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing\nthe ends. As opposed to `LocallyFiniteOrderTop.ofIci`, this one requires `DecidableRel (\u00b7 \u2264 \u00b7)` but\nonly `Preorder`. -/\ndef LocallyFiniteOrderTop.ofIci' (\u03b1 : Type _) [Preorder \u03b1] [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n    (finsetIci : \u03b1 \u2192 Finset \u03b1) (mem_Ici : \u2200 a x, x \u2208 finsetIci a \u2194 a \u2264 x) :\n    LocallyFiniteOrderTop \u03b1 :=\n  { finsetIci\n    finsetIoi := fun a => (finsetIci a).filter fun x => \u00acx \u2264 a\n    finset_mem_Ici := mem_Ici\n    finset_mem_Ioi := fun a x => by rw [mem_filter, mem_Ici, lt_iff_le_not_le] }\n#align locally_finite_order_top.of_Ici' LocallyFiniteOrderTop.ofIci'\n\n/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing\nthe ends. As opposed to `LocallyFiniteOrderTop.ofIci'`, this one requires `PartialOrder` but\nonly `DecidableEq`. -/\ndef LocallyFiniteOrderTop.ofIci (\u03b1 : Type _) [PartialOrder \u03b1] [DecidableEq \u03b1]\n    (finsetIci : \u03b1 \u2192 Finset \u03b1) (mem_Ici : \u2200 a x, x \u2208 finsetIci a \u2194 a \u2264 x) :\n    LocallyFiniteOrderTop \u03b1 :=\n  { finsetIci\n    finsetIoi := fun a => (finsetIci a).filter fun x => a \u2260 x\n    finset_mem_Ici := mem_Ici\n    finset_mem_Ioi := fun a x => by rw [mem_filter, mem_Ici, lt_iff_le_and_ne] }\n#align locally_finite_order_top.of_Ici LocallyFiniteOrderTop.ofIci\n\n/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing\nthe ends. As opposed to `LocallyFiniteOrder.ofIcc`, this one requires `DecidableRel (\u00b7 \u2264 \u00b7)` but\nonly `Preorder`. -/\ndef LocallyFiniteOrderBot.ofIic' (\u03b1 : Type _) [Preorder \u03b1] [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n    (finsetIic : \u03b1 \u2192 Finset \u03b1) (mem_Iic : \u2200 a x, x \u2208 finsetIic a \u2194 x \u2264 a) :\n    LocallyFiniteOrderBot \u03b1 :=\n  { finsetIic\n    finsetIio := fun a => (finsetIic a).filter fun x => \u00aca \u2264 x\n    finset_mem_Iic := mem_Iic\n    finset_mem_Iio := fun a x => by rw [mem_filter, mem_Iic, lt_iff_le_not_le] }\n#align locally_finite_order_bot.of_Iic' LocallyFiniteOrderBot.ofIic'\n\n/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing\nthe ends. As opposed to `LocallyFiniteOrderTop.ofIci'`, this one requires `PartialOrder` but\nonly `DecidableEq`. -/\ndef LocallyFiniteOrderTop.ofIic (\u03b1 : Type _) [PartialOrder \u03b1] [DecidableEq \u03b1]\n    (finsetIic : \u03b1 \u2192 Finset \u03b1) (mem_Iic : \u2200 a x, x \u2208 finsetIic a \u2194 x \u2264 a) :\n    LocallyFiniteOrderBot \u03b1 :=\n  { finsetIic\n    finsetIio := fun a => (finsetIic a).filter fun x => x \u2260 a\n    finset_mem_Iic := mem_Iic\n    finset_mem_Iio := fun a x => by rw [mem_filter, mem_Iic, lt_iff_le_and_ne] }\n#align locally_finite_order_top.of_Iic LocallyFiniteOrderTop.ofIic\n\nvariable {\u03b1 \u03b2 : Type _}\n\n-- See note [reducible non-instances]\n/-- An empty type is locally finite.\n\nThis is not an instance as it would not be defeq to more specific instances. -/\n@[reducible]\nprotected def IsEmpty.toLocallyFiniteOrder [Preorder \u03b1] [IsEmpty \u03b1] : LocallyFiniteOrder \u03b1 where\n  finsetIcc := isEmptyElim\n  finsetIco := isEmptyElim\n  finsetIoc := isEmptyElim\n  finsetIoo := isEmptyElim\n  finset_mem_Icc := isEmptyElim\n  finset_mem_Ico := isEmptyElim\n  finset_mem_Ioc := isEmptyElim\n  finset_mem_Ioo := isEmptyElim\n#align is_empty.to_locally_finite_order IsEmpty.toLocallyFiniteOrder\n\n-- See note [reducible non-instances]\n/-- An empty type is locally finite.\n\nThis is not an instance as it would not be defeq to more specific instances. -/\n@[reducible]\nprotected def IsEmpty.toLocallyFiniteOrderTop [Preorder \u03b1] [IsEmpty \u03b1] : LocallyFiniteOrderTop \u03b1\n    where\n  finsetIci := isEmptyElim\n  finsetIoi := isEmptyElim\n  finset_mem_Ici := isEmptyElim\n  finset_mem_Ioi := isEmptyElim\n#align is_empty.to_locally_finite_order_top IsEmpty.toLocallyFiniteOrderTop\n\n-- See note [reducible non-instances]\n/-- An empty type is locally finite.\n\nThis is not an instance as it would not be defeq to more specific instances. -/\n@[reducible]\nprotected def IsEmpty.toLocallyFiniteOrderBot [Preorder \u03b1] [IsEmpty \u03b1] : LocallyFiniteOrderBot \u03b1\n    where\n  finsetIic := isEmptyElim\n  finsetIio := isEmptyElim\n  finset_mem_Iic := isEmptyElim\n  finset_mem_Iio := isEmptyElim\n#align is_empty.to_locally_finite_order_bot IsEmpty.toLocallyFiniteOrderBot\n\n/-! ### Intervals as finsets -/\n\n\nnamespace Finset\n\nsection Preorder\n\nvariable [Preorder \u03b1]\n\nsection LocallyFiniteOrder\n\nvariable [LocallyFiniteOrder \u03b1] {a b x : \u03b1}\n\n/-- The finset of elements `x` such that `a \u2264 x` and `x \u2264 b`. Basically `Set.Icc a b` as a finset.\n-/\ndef Icc (a b : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrder.finsetIcc a b\n#align finset.Icc Finset.Icc\n\n/-- The finset of elements `x` such that `a \u2264 x` and `x < b`. Basically `Set.Ico a b` as a finset.\n-/\ndef Ico (a b : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrder.finsetIco a b\n#align finset.Ico Finset.Ico\n\n/-- The finset of elements `x` such that `a < x` and `x \u2264 b`. Basically `Set.Ioc a b` as a finset.\n-/\ndef Ioc (a b : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrder.finsetIoc a b\n#align finset.Ioc Finset.Ioc\n\n/-- The finset of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a finset.\n-/\ndef Ioo (a b : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrder.finsetIoo a b\n#align finset.Ioo Finset.Ioo\n\n@[simp]\ntheorem mem_Icc : x \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b :=\n  LocallyFiniteOrder.finset_mem_Icc a b x\n#align finset.mem_Icc Finset.mem_Icc\n\n@[simp]\ntheorem mem_Ico : x \u2208 Ico a b \u2194 a \u2264 x \u2227 x < b :=\n  LocallyFiniteOrder.finset_mem_Ico a b x\n#align finset.mem_Ico Finset.mem_Ico\n\n@[simp]\ntheorem mem_Ioc : x \u2208 Ioc a b \u2194 a < x \u2227 x \u2264 b :=\n  LocallyFiniteOrder.finset_mem_Ioc a b x\n#align finset.mem_Ioc Finset.mem_Ioc\n\n@[simp]\ntheorem mem_Ioo : x \u2208 Ioo a b \u2194 a < x \u2227 x < b :=\n  LocallyFiniteOrder.finset_mem_Ioo a b x\n#align finset.mem_Ioo Finset.mem_Ioo\n\n@[simp, norm_cast]\ntheorem coe_Icc (a b : \u03b1) : (Icc a b : Set \u03b1) = Set.Icc a b :=\n  Set.ext fun _ => mem_Icc\n#align finset.coe_Icc Finset.coe_Icc\n\n@[simp, norm_cast]\ntheorem coe_Ico (a b : \u03b1) : (Ico a b : Set \u03b1) = Set.Ico a b :=\n  Set.ext fun _ => mem_Ico\n#align finset.coe_Ico Finset.coe_Ico\n\n@[simp, norm_cast]\ntheorem coe_Ioc (a b : \u03b1) : (Ioc a b : Set \u03b1) = Set.Ioc a b :=\n  Set.ext fun _ => mem_Ioc\n#align finset.coe_Ioc Finset.coe_Ioc\n\n@[simp, norm_cast]\ntheorem coe_Ioo (a b : \u03b1) : (Ioo a b : Set \u03b1) = Set.Ioo a b :=\n  Set.ext fun _ => mem_Ioo\n#align finset.coe_Ioo Finset.coe_Ioo\n\nend LocallyFiniteOrder\n\nsection LocallyFiniteOrderTop\n\nvariable [LocallyFiniteOrderTop \u03b1] {a x : \u03b1}\n\n/-- The finset of elements `x` such that `a \u2264 x`. Basically `Set.Ici a` as a finset. -/\ndef Ici (a : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrderTop.finsetIci a\n#align finset.Ici Finset.Ici\n\n/-- The finset of elements `x` such that `a < x`. Basically `Set.Ioi a` as a finset. -/\ndef Ioi (a : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrderTop.finsetIoi a\n#align finset.Ioi Finset.Ioi\n\n@[simp]\ntheorem mem_Ici : x \u2208 Ici a \u2194 a \u2264 x :=\n  LocallyFiniteOrderTop.finset_mem_Ici _ _\n#align finset.mem_Ici Finset.mem_Ici\n\n@[simp]\ntheorem mem_Ioi : x \u2208 Ioi a \u2194 a < x :=\n  LocallyFiniteOrderTop.finset_mem_Ioi _ _\n#align finset.mem_Ioi Finset.mem_Ioi\n\n@[simp, norm_cast]\ntheorem coe_Ici (a : \u03b1) : (Ici a : Set \u03b1) = Set.Ici a :=\n  Set.ext fun _ => mem_Ici\n#align finset.coe_Ici Finset.coe_Ici\n\n@[simp, norm_cast]\ntheorem coe_Ioi (a : \u03b1) : (Ioi a : Set \u03b1) = Set.Ioi a :=\n  Set.ext fun _ => mem_Ioi\n#align finset.coe_Ioi Finset.coe_Ioi\n\nend LocallyFiniteOrderTop\n\nsection LocallyFiniteOrderBot\n\nvariable [LocallyFiniteOrderBot \u03b1] {a x : \u03b1}\n\n/-- The finset of elements `x` such that `a \u2264 x`. Basically `Set.Iic a` as a finset. -/\ndef Iic (a : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrderBot.finsetIic a\n#align finset.Iic Finset.Iic\n\n/-- The finset of elements `x` such that `a < x`. Basically `Set.Iio a` as a finset. -/\ndef Iio (a : \u03b1) : Finset \u03b1 :=\n  LocallyFiniteOrderBot.finsetIio a\n#align finset.Iio Finset.Iio\n\n@[simp]\ntheorem mem_Iic : x \u2208 Iic a \u2194 x \u2264 a :=\n  LocallyFiniteOrderBot.finset_mem_Iic _ _\n#align finset.mem_Iic Finset.mem_Iic\n\n@[simp]\ntheorem mem_Iio : x \u2208 Iio a \u2194 x < a :=\n  LocallyFiniteOrderBot.finset_mem_Iio _ _\n#align finset.mem_Iio Finset.mem_Iio\n\n@[simp, norm_cast]\ntheorem coe_Iic (a : \u03b1) : (Iic a : Set \u03b1) = Set.Iic a :=\n  Set.ext fun _ => mem_Iic\n#align finset.coe_Iic Finset.coe_Iic\n\n@[simp, norm_cast]\ntheorem coe_Iio (a : \u03b1) : (Iio a : Set \u03b1) = Set.Iio a :=\n  Set.ext fun _ => mem_Iio\n#align finset.coe_Iio Finset.coe_Iio\n\nend LocallyFiniteOrderBot\n\nsection OrderTop\n\nvariable [LocallyFiniteOrder \u03b1] [OrderTop \u03b1] {a x : \u03b1}\n\n-- See note [lower priority instance]\ninstance (priority := 100) LocallyFiniteOrder.toLocallyFiniteOrderTop : LocallyFiniteOrderTop \u03b1\n    where\n  finsetIci b := Icc b \u22a4\n  finsetIoi b := Ioc b \u22a4\n  finset_mem_Ici a x := by rw [mem_Icc, and_iff_left le_top]\n  finset_mem_Ioi a x := by rw [mem_Ioc, and_iff_left le_top]\n#align locally_finite_order.to_locally_finite_order_top Finset.LocallyFiniteOrder.toLocallyFiniteOrderTop\n\ntheorem Ici_eq_Icc (a : \u03b1) : Ici a = Icc a \u22a4 :=\n  rfl\n#align finset.Ici_eq_Icc Finset.Ici_eq_Icc\n\ntheorem Ioi_eq_Ioc (a : \u03b1) : Ioi a = Ioc a \u22a4 :=\n  rfl\n#align finset.Ioi_eq_Ioc Finset.Ioi_eq_Ioc\n\nend OrderTop\n\nsection OrderBot\n\nvariable [OrderBot \u03b1] [LocallyFiniteOrder \u03b1] {b x : \u03b1}\n\n-- See note [lower priority instance]\ninstance (priority := 100) LocallyFiniteOrder.toLocallyFiniteOrderBot : LocallyFiniteOrderBot \u03b1\n    where\n  finsetIic := Icc \u22a5\n  finsetIio := Ico \u22a5\n  finset_mem_Iic a x := by rw [mem_Icc, and_iff_right bot_le]\n  finset_mem_Iio a x := by rw [mem_Ico, and_iff_right bot_le]\n#align finset.locally_finite_order.to_locally_finite_order_bot Finset.LocallyFiniteOrder.toLocallyFiniteOrderBot\n\ntheorem Iic_eq_Icc : Iic = Icc (\u22a5 : \u03b1) :=\n  rfl\n#align finset.Iic_eq_Icc Finset.Iic_eq_Icc\n\ntheorem Iio_eq_Ico : Iio = Ico (\u22a5 : \u03b1) :=\n  rfl\n#align finset.Iio_eq_Ico Finset.Iio_eq_Ico\n\nend OrderBot\n\nend Preorder\n\nsection Lattice\n\nvariable [Lattice \u03b1] [LocallyFiniteOrder \u03b1] {a b x : \u03b1}\n\n/-- `Finset.uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included.\nNote that we define it more generally in a lattice as `Finset.Icc (a \u2293 b) (a \u2294 b)`. In a\nproduct type, `Finset.uIcc` corresponds to the bounding box of the two elements. -/\ndef uIcc (a b : \u03b1) : Finset \u03b1 :=\n  Icc (a \u2293 b) (a \u2294 b)\n#align finset.uIcc Finset.uIcc\n\n@[inherit_doc]\nscoped[FinsetInterval] notation \"[[\" a \", \" b \"]]\" => Finset.uIcc a b\n\n@[simp]\ntheorem mem_uIcc : x \u2208 uIcc a b \u2194 a \u2293 b \u2264 x \u2227 x \u2264 a \u2294 b :=\n  mem_Icc\n#align finset.mem_uIcc Finset.mem_uIcc\n\n@[simp, norm_cast]\ntheorem coe_uIcc (a b : \u03b1) : (Finset.uIcc a b : Set \u03b1) = Set.uIcc a b :=\n  coe_Icc _ _\n#align finset.coe_uIcc Finset.coe_uIcc\n\nend Lattice\n\nend Finset\n\n/-! ### Intervals as multisets -/\n\n\nnamespace Multiset\n\nvariable [Preorder \u03b1]\n\nsection LocallyFiniteOrder\n\nvariable [LocallyFiniteOrder \u03b1]\n\n/-- The multiset of elements `x` such that `a \u2264 x` and `x \u2264 b`. Basically `Set.Icc a b` as a\nmultiset. -/\ndef Icc (a b : \u03b1) : Multiset \u03b1 :=\n  (Finset.Icc a b).val\n#align multiset.Icc Multiset.Icc\n\n/-- The multiset of elements `x` such that `a \u2264 x` and `x < b`. Basically `Set.Ico a b` as a\nmultiset. -/\ndef Ico (a b : \u03b1) : Multiset \u03b1 :=\n  (Finset.Ico a b).val\n#align multiset.Ico Multiset.Ico\n\n/-- The multiset of elements `x` such that `a < x` and `x \u2264 b`. Basically `Set.Ioc a b` as a\nmultiset. -/\ndef Ioc (a b : \u03b1) : Multiset \u03b1 :=\n  (Finset.Ioc a b).val\n#align multiset.Ioc Multiset.Ioc\n\n/-- The multiset of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a\nmultiset. -/\ndef Ioo (a b : \u03b1) : Multiset \u03b1 :=\n  (Finset.Ioo a b).val\n#align multiset.Ioo Multiset.Ioo\n\n@[simp]\ntheorem mem_Icc {a b x : \u03b1} : x \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b := by\n  rw [Icc, \u2190 Finset.mem_def, Finset.mem_Icc]\n#align multiset.mem_Icc Multiset.mem_Icc\n\n@[simp]\ntheorem mem_Ico {a b x : \u03b1} : x \u2208 Ico a b \u2194 a \u2264 x \u2227 x < b := by\n  rw [Ico, \u2190 Finset.mem_def, Finset.mem_Ico]\n#align multiset.mem_Ico Multiset.mem_Ico\n\n@[simp]\ntheorem mem_Ioc {a b x : \u03b1} : x \u2208 Ioc a b \u2194 a < x \u2227 x \u2264 b := by\n  rw [Ioc, \u2190 Finset.mem_def, Finset.mem_Ioc]\n#align multiset.mem_Ioc Multiset.mem_Ioc\n\n@[simp]\ntheorem mem_Ioo {a b x : \u03b1} : x \u2208 Ioo a b \u2194 a < x \u2227 x < b := by\n  rw [Ioo, \u2190 Finset.mem_def, Finset.mem_Ioo]\n#align multiset.mem_Ioo Multiset.mem_Ioo\n\nend LocallyFiniteOrder\n\nsection LocallyFiniteOrderTop\n\nvariable [LocallyFiniteOrderTop \u03b1]\n\n/-- The multiset of elements `x` such that `a \u2264 x`. Basically `Set.Ici a` as a multiset. -/\ndef Ici (a : \u03b1) : Multiset \u03b1 :=\n  (Finset.Ici a).val\n#align multiset.Ici Multiset.Ici\n\n/-- The multiset of elements `x` such that `a < x`. Basically `Set.Ioi a` as a multiset. -/\ndef Ioi (a : \u03b1) : Multiset \u03b1 :=\n  (Finset.Ioi a).val\n#align multiset.Ioi Multiset.Ioi\n\n@[simp]\ntheorem mem_Ici {a x : \u03b1} : x \u2208 Ici a \u2194 a \u2264 x := by rw [Ici, \u2190 Finset.mem_def, Finset.mem_Ici]\n#align multiset.mem_Ici Multiset.mem_Ici\n\n@[simp]\ntheorem mem_Ioi {a x : \u03b1} : x \u2208 Ioi a \u2194 a < x := by rw [Ioi, \u2190 Finset.mem_def, Finset.mem_Ioi]\n#align multiset.mem_Ioi Multiset.mem_Ioi\n\nend LocallyFiniteOrderTop\n\nsection LocallyFiniteOrderBot\n\nvariable [LocallyFiniteOrderBot \u03b1]\n\n/-- The multiset of elements `x` such that `x \u2264 b`. Basically `Set.Iic b` as a multiset. -/\ndef Iic (b : \u03b1) : Multiset \u03b1 :=\n  (Finset.Iic b).val\n#align multiset.Iic Multiset.Iic\n\n/-- The multiset of elements `x` such that `x < b`. Basically `Set.Iio b` as a multiset. -/\ndef Iio (b : \u03b1) : Multiset \u03b1 :=\n  (Finset.Iio b).val\n#align multiset.Iio Multiset.Iio\n\n@[simp]\ntheorem mem_Iic {b x : \u03b1} : x \u2208 Iic b \u2194 x \u2264 b := by rw [Iic, \u2190 Finset.mem_def, Finset.mem_Iic]\n#align multiset.mem_Iic Multiset.mem_Iic\n\n@[simp]\ntheorem mem_Iio {b x : \u03b1} : x \u2208 Iio b \u2194 x < b := by rw [Iio, \u2190 Finset.mem_def, Finset.mem_Iio]\n#align multiset.mem_Iio Multiset.mem_Iio\n\nend LocallyFiniteOrderBot\n\nend Multiset\n\n/-! ### Finiteness of `Set` intervals -/\n\n\nnamespace Set\n\nsection Preorder\n\nvariable [Preorder \u03b1] [LocallyFiniteOrder \u03b1] (a b : \u03b1)\n\ninstance fintypeIcc : Fintype (Icc a b) :=\n  Fintype.ofFinset (Finset.Icc a b) fun x => by rw [Finset.mem_Icc, mem_Icc]\n#align set.fintype_Icc Set.fintypeIcc\n\ninstance fintypeIco : Fintype (Ico a b) :=\n  Fintype.ofFinset (Finset.Ico a b) fun x => by rw [Finset.mem_Ico, mem_Ico]\n#align set.fintype_Ico Set.fintypeIco\n\ninstance fintypeIoc : Fintype (Ioc a b) :=\n  Fintype.ofFinset (Finset.Ioc a b) fun x => by rw [Finset.mem_Ioc, mem_Ioc]\n#align set.fintype_Ioc Set.fintypeIoc\n\ninstance fintypeIoo : Fintype (Ioo a b) :=\n  Fintype.ofFinset (Finset.Ioo a b) fun x => by rw [Finset.mem_Ioo, mem_Ioo]\n#align set.fintype_Ioo Set.fintypeIoo\n\ntheorem finite_Icc : (Icc a b).Finite :=\n  (Icc a b).toFinite\n#align set.finite_Icc Set.finite_Icc\n\ntheorem finite_Ico : (Ico a b).Finite :=\n  (Ico a b).toFinite\n#align set.finite_Ico Set.finite_Ico\n\ntheorem finite_Ioc : (Ioc a b).Finite :=\n  (Ioc a b).toFinite\n#align set.finite_Ioc Set.finite_Ioc\n\ntheorem finite_Ioo : (Ioo a b).Finite :=\n  (Ioo a b).toFinite\n#align set.finite_Ioo Set.finite_Ioo\n\nend Preorder\n\nsection OrderTop\n\nvariable [Preorder \u03b1] [LocallyFiniteOrderTop \u03b1] (a : \u03b1)\n\ninstance fintypeIci : Fintype (Ici a) :=\n  Fintype.ofFinset (Finset.Ici a) fun x => by rw [Finset.mem_Ici, mem_Ici]\n#align set.fintype_Ici Set.fintypeIci\n\ninstance fintypeIoi : Fintype (Ioi a) :=\n  Fintype.ofFinset (Finset.Ioi a) fun x => by rw [Finset.mem_Ioi, mem_Ioi]\n#align set.fintype_Ioi Set.fintypeIoi\n\ntheorem finite_Ici : (Ici a).Finite :=\n  (Ici a).toFinite\n#align set.finite_Ici Set.finite_Ici\n\ntheorem finite_Ioi : (Ioi a).Finite :=\n  (Ioi a).toFinite\n#align set.finite_Ioi Set.finite_Ioi\n\nend OrderTop\n\nsection OrderBot\n\nvariable [Preorder \u03b1] [LocallyFiniteOrderBot \u03b1] (b : \u03b1)\n\ninstance fintypeIic : Fintype (Iic b) :=\n  Fintype.ofFinset (Finset.Iic b) fun x => by rw [Finset.mem_Iic, mem_Iic]\n#align set.fintype_Iic Set.fintypeIic\n\ninstance fintypeIio : Fintype (Iio b) :=\n  Fintype.ofFinset (Finset.Iio b) fun x => by rw [Finset.mem_Iio, mem_Iio]\n#align set.fintype_Iio Set.fintypeIio\n\ntheorem finite_Iic : (Iic b).Finite :=\n  (Iic b).toFinite\n#align set.finite_Iic Set.finite_Iic\n\ntheorem finite_Iio : (Iio b).Finite :=\n  (Iio b).toFinite\n#align set.finite_Iio Set.finite_Iio\n\nend OrderBot\n\nend Set\n\n/-! ### Instances -/\n\n\nopen Finset\n\nsection Preorder\n\nvariable [Preorder \u03b1] [Preorder \u03b2]\n\n/-- A noncomputable constructor from the finiteness of all closed intervals. -/\nnoncomputable def LocallyFiniteOrder.ofFiniteIcc (h : \u2200 a b : \u03b1, (Set.Icc a b).Finite) :\n    LocallyFiniteOrder \u03b1 :=\n  @LocallyFiniteOrder.ofIcc' \u03b1 _ (Classical.decRel _) (fun a b => (h a b).toFinset) fun a b x => by\n    rw [Set.Finite.mem_toFinset, Set.mem_Icc]\n#align locally_finite_order.of_finite_Icc LocallyFiniteOrder.ofFiniteIcc\n\n/-- A fintype is a locally finite order.\n\nThis is not an instance as it would not be defeq to better instances such as\n`Fin.locallyFiniteOrder`.\n-/\n@[reducible]\ndef Fintype.toLocallyFiniteOrder [Fintype \u03b1] [@DecidableRel \u03b1 (\u00b7 < \u00b7)] [@DecidableRel \u03b1 (\u00b7 \u2264 \u00b7)] :\n    LocallyFiniteOrder \u03b1 where\n  finsetIcc a b := (Set.Icc a b).toFinset\n  finsetIco a b := (Set.Ico a b).toFinset\n  finsetIoc a b := (Set.Ioc a b).toFinset\n  finsetIoo a b := (Set.Ioo a b).toFinset\n  finset_mem_Icc a b x := by simp only [Set.mem_toFinset, Set.mem_Icc]\n  finset_mem_Ico a b x := by simp only [Set.mem_toFinset, Set.mem_Ico]\n  finset_mem_Ioc a b x := by simp only [Set.mem_toFinset, Set.mem_Ioc]\n  finset_mem_Ioo a b x := by simp only [Set.mem_toFinset, Set.mem_Ioo]\n#align fintype.to_locally_finite_order Fintype.toLocallyFiniteOrder\n\ninstance : Subsingleton (LocallyFiniteOrder \u03b1) :=\n  Subsingleton.intro fun h\u2080 h\u2081 => by\n    cases' h\u2080 with h\u2080_finset_Icc h\u2080_finset_Ico h\u2080_finset_Ioc h\u2080_finset_Ioo\n      h\u2080_finset_mem_Icc h\u2080_finset_mem_Ico h\u2080_finset_mem_Ioc h\u2080_finset_mem_Ioo\n    cases' h\u2081 with h\u2081_finset_Icc h\u2081_finset_Ico h\u2081_finset_Ioc h\u2081_finset_Ioo\n      h\u2081_finset_mem_Icc h\u2081_finset_mem_Ico h\u2081_finset_mem_Ioc h\u2081_finset_mem_Ioo\n    have hIcc : h\u2080_finset_Icc = h\u2081_finset_Icc :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Icc, h\u2081_finset_mem_Icc]\n    have hIco : h\u2080_finset_Ico = h\u2081_finset_Ico :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Ico, h\u2081_finset_mem_Ico]\n    have hIoc : h\u2080_finset_Ioc = h\u2081_finset_Ioc :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Ioc, h\u2081_finset_mem_Ioc]\n    have hIoo : h\u2080_finset_Ioo = h\u2081_finset_Ioo :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Ioo, h\u2081_finset_mem_Ioo]\n    simp_rw [hIcc, hIco, hIoc, hIoo]\n\ninstance : Subsingleton (LocallyFiniteOrderTop \u03b1) :=\n  Subsingleton.intro fun h\u2080 h\u2081 => by\n    cases' h\u2080 with h\u2080_finset_Ioi h\u2080_finset_Ici h\u2080_finset_mem_Ici h\u2080_finset_mem_Ioi\n    cases' h\u2081 with h\u2081_finset_Ioi h\u2081_finset_Ici h\u2081_finset_mem_Ici h\u2081_finset_mem_Ioi\n    have hIci : h\u2080_finset_Ici = h\u2081_finset_Ici :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Ici, h\u2081_finset_mem_Ici]\n    have hIoi : h\u2080_finset_Ioi = h\u2081_finset_Ioi :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Ioi, h\u2081_finset_mem_Ioi]\n    simp_rw [hIci, hIoi]\n\ninstance : Subsingleton (LocallyFiniteOrderBot \u03b1) :=\n  Subsingleton.intro fun h\u2080 h\u2081 => by\n    cases' h\u2080 with h\u2080_finset_Iio h\u2080_finset_Iic h\u2080_finset_mem_Iic h\u2080_finset_mem_Iio\n    cases' h\u2081 with h\u2081_finset_Iio h\u2081_finset_Iic h\u2081_finset_mem_Iic h\u2081_finset_mem_Iio\n    have hIic : h\u2080_finset_Iic = h\u2081_finset_Iic :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Iic, h\u2081_finset_mem_Iic]\n    have hIio : h\u2080_finset_Iio = h\u2081_finset_Iio :=\n      by\n      ext (a b x)\n      rw [h\u2080_finset_mem_Iio, h\u2081_finset_mem_Iio]\n    simp_rw [hIic, hIio]\n\n-- Should this be called `LocallyFiniteOrder.lift`?\n/-- Given an order embedding `\u03b1 \u21aao \u03b2`, pulls back the `LocallyFiniteOrder` on `\u03b2` to `\u03b1`. -/\nprotected noncomputable def OrderEmbedding.locallyFiniteOrder [LocallyFiniteOrder \u03b2] (f : \u03b1 \u21aao \u03b2) :\n    LocallyFiniteOrder \u03b1 where\n  finsetIcc a b := (Icc (f a) (f b)).preimage f (f.toEmbedding.injective.injOn _)\n  finsetIco a b := (Ico (f a) (f b)).preimage f (f.toEmbedding.injective.injOn _)\n  finsetIoc a b := (Ioc (f a) (f b)).preimage f (f.toEmbedding.injective.injOn _)\n  finsetIoo a b := (Ioo (f a) (f b)).preimage f (f.toEmbedding.injective.injOn _)\n  finset_mem_Icc a b x := by rw [mem_preimage, mem_Icc, f.le_iff_le, f.le_iff_le]\n  finset_mem_Ico a b x := by rw [mem_preimage, mem_Ico, f.le_iff_le, f.lt_iff_lt]\n  finset_mem_Ioc a b x := by rw [mem_preimage, mem_Ioc, f.lt_iff_lt, f.le_iff_le]\n  finset_mem_Ioo a b x := by rw [mem_preimage, mem_Ioo, f.lt_iff_lt, f.lt_iff_lt]\n#align order_embedding.locally_finite_order OrderEmbedding.locallyFiniteOrder\n\nopen OrderDual\n\nsection LocallyFiniteOrder\n\nvariable [LocallyFiniteOrder \u03b1] (a b : \u03b1)\n\n/-- Note we define `Icc (toDual a) (toDual b)` as `Icc \u03b1 _ _ b a` (which has type `Finset \u03b1` not\n`Finset \u03b1\u1d52\u1d48`!) instead of `(Icc b a).map toDual.toEmbedding` as this means the\nfollowing is defeq:\n```\nlemma this : (Icc (toDual (toDual a)) (toDual (toDual b)) : _) = (Icc a b : _) := rfl\n```\n-/\ninstance OrderDual.locallyFiniteOrder : LocallyFiniteOrder \u03b1\u1d52\u1d48 where\n  finsetIcc a b := @Icc \u03b1 _ _ (ofDual b) (ofDual a)\n  finsetIco a b := @Ioc \u03b1 _ _ (ofDual b) (ofDual a)\n  finsetIoc a b := @Ico \u03b1 _ _ (ofDual b) (ofDual a)\n  finsetIoo a b := @Ioo \u03b1 _ _ (ofDual b) (ofDual a)\n  finset_mem_Icc _ _ _ := (mem_Icc (\u03b1 := \u03b1)).trans and_comm\n  finset_mem_Ico _ _ _ := (mem_Ioc (\u03b1 := \u03b1)).trans and_comm\n  finset_mem_Ioc _ _ _ := (mem_Ico (\u03b1 := \u03b1)).trans and_comm\n  finset_mem_Ioo _ _ _ := (mem_Ioo (\u03b1 := \u03b1)).trans and_comm\n\ntheorem Icc_toDual : Icc (toDual a) (toDual b) = (Icc b a).map toDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Icc, mem_Icc (\u03b1 := \u03b1)]\n  exact and_comm\n#align Icc_to_dual Icc_toDual\n\ntheorem Ico_toDual : Ico (toDual a) (toDual b) = (Ioc b a).map toDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Ico, mem_Ioc (\u03b1 := \u03b1)]\n  exact and_comm\n#align Ico_to_dual Ico_toDual\n\ntheorem Ioc_toDual : Ioc (toDual a) (toDual b) = (Ico b a).map toDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Ioc, mem_Ico (\u03b1 := \u03b1)]\n  exact and_comm\n#align Ioc_to_dual Ioc_toDual\n\ntheorem Ioo_toDual : Ioo (toDual a) (toDual b) = (Ioo b a).map toDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Ioo, mem_Ioo (\u03b1 := \u03b1)]\n  exact and_comm\n#align Ioo_to_dual Ioo_toDual\n\ntheorem Icc_ofDual (a b : \u03b1\u1d52\u1d48) : Icc (ofDual a) (ofDual b) = (Icc b a).map ofDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Icc, mem_Icc (\u03b1 := \u03b1\u1d52\u1d48)]\n  exact and_comm\n#align Icc_of_dual Icc_ofDual\n\ntheorem Ico_ofDual (a b : \u03b1\u1d52\u1d48) : Ico (ofDual a) (ofDual b) = (Ioc b a).map ofDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Ico, mem_Ioc (\u03b1 := \u03b1\u1d52\u1d48)]\n  exact and_comm\n#align Ico_of_dual Ico_ofDual\n\ntheorem Ioc_ofDual (a b : \u03b1\u1d52\u1d48) : Ioc (ofDual a) (ofDual b) = (Ico b a).map ofDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Ioc, mem_Ico (\u03b1 := \u03b1\u1d52\u1d48)]\n  exact and_comm\n#align Ioc_of_dual Ioc_ofDual\n\ntheorem Ioo_ofDual (a b : \u03b1\u1d52\u1d48) : Ioo (ofDual a) (ofDual b) = (Ioo b a).map ofDual.toEmbedding := by\n  refine' Eq.trans _ map_refl.symm\n  ext c\n  rw [mem_Ioo, mem_Ioo (\u03b1 := \u03b1\u1d52\u1d48)]\n  exact and_comm\n#align Ioo_of_dual Ioo_ofDual\n\nend LocallyFiniteOrder\n\nsection LocallyFiniteOrderTop\n\nvariable [LocallyFiniteOrderTop \u03b1]\n\n/-- Note we define `Iic (toDual a)` as `Ici a` (which has type `Finset \u03b1` not `Finset \u03b1\u1d52\u1d48`!)\ninstead of `(Ici a).map toDual.toEmbedding` as this means the following is defeq:\n```\nlemma this : (Iic (toDual (toDual a)) : _) = (Iic a : _) := rfl\n```\n-/\ninstance : LocallyFiniteOrderBot \u03b1\u1d52\u1d48 where\n  finsetIic a := @Ici \u03b1 _ _ (ofDual a)\n  finsetIio a := @Ioi \u03b1 _ _ (ofDual a)\n  finset_mem_Iic _ _ := mem_Ici (\u03b1 := \u03b1)\n  finset_mem_Iio _ _ := mem_Ioi (\u03b1 := \u03b1)\n\ntheorem Iic_toDual (a : \u03b1) : Iic (toDual a) = (Ici a).map toDual.toEmbedding :=\n  map_refl.symm\n#align Iic_to_dual Iic_toDual\n\ntheorem Iio_toDual (a : \u03b1) : Iio (toDual a) = (Ioi a).map toDual.toEmbedding :=\n  map_refl.symm\n#align Iio_to_dual Iio_toDual\n\ntheorem Ici_ofDual (a : \u03b1\u1d52\u1d48) : Ici (ofDual a) = (Iic a).map ofDual.toEmbedding :=\n  map_refl.symm\n#align Ici_of_dual Ici_ofDual\n\ntheorem Ioi_ofDual (a : \u03b1\u1d52\u1d48) : Ioi (ofDual a) = (Iio a).map ofDual.toEmbedding :=\n  map_refl.symm\n#align Ioi_of_dual Ioi_ofDual\n\nend LocallyFiniteOrderTop\n\nsection LocallyFiniteOrderTop\n\nvariable [LocallyFiniteOrderBot \u03b1]\n\n/-- Note we define `Ici (toDual a)` as `Iic a` (which has type `Finset \u03b1` not `Finset \u03b1\u1d52\u1d48`!)\ninstead of `(Iic a).map toDual.toEmbedding` as this means the following is defeq:\n```\nlemma this : (Ici (toDual (toDual a)) : _) = (Ici a : _) := rfl\n```\n-/\ninstance : LocallyFiniteOrderTop \u03b1\u1d52\u1d48 where\n  finsetIci a := @Iic \u03b1 _ _ (ofDual a)\n  finsetIoi a := @Iio \u03b1 _ _ (ofDual a)\n  finset_mem_Ici _ _ := mem_Iic (\u03b1 := \u03b1)\n  finset_mem_Ioi _ _ := mem_Iio (\u03b1 := \u03b1)\n\ntheorem Ici_toDual (a : \u03b1) : Ici (toDual a) = (Iic a).map toDual.toEmbedding :=\n  map_refl.symm\n#align Ici_to_dual Ici_toDual\n\ntheorem Ioi_toDual (a : \u03b1) : Ioi (toDual a) = (Iio a).map toDual.toEmbedding :=\n  map_refl.symm\n#align Ioi_to_dual Ioi_toDual\n\ntheorem Iic_ofDual (a : \u03b1\u1d52\u1d48) : Iic (ofDual a) = (Ici a).map ofDual.toEmbedding :=\n  map_refl.symm\n#align Iic_of_dual Iic_ofDual\n\ntheorem Iio_ofDual (a : \u03b1\u1d52\u1d48) : Iio (ofDual a) = (Ioi a).map ofDual.toEmbedding :=\n  map_refl.symm\n#align Iio_of_dual Iio_ofDual\n\nend LocallyFiniteOrderTop\n\nnamespace Prod\n\ninstance [LocallyFiniteOrder \u03b1] [LocallyFiniteOrder \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] : LocallyFiniteOrder (\u03b1 \u00d7 \u03b2) :=\n  LocallyFiniteOrder.ofIcc' (\u03b1 \u00d7 \u03b2) (fun a b => Icc a.fst b.fst \u00d7\u1da0 Icc a.snd b.snd) fun a b x =>\n    by\n    rw [mem_product, mem_Icc, mem_Icc, and_and_and_comm]\n    rfl\n\ninstance [LocallyFiniteOrderTop \u03b1] [LocallyFiniteOrderTop \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] : LocallyFiniteOrderTop (\u03b1 \u00d7 \u03b2) :=\n  LocallyFiniteOrderTop.ofIci' (\u03b1 \u00d7 \u03b2) (fun a => Ici a.fst \u00d7\u1da0 Ici a.snd) fun a x =>\n    by\n    rw [mem_product, mem_Ici, mem_Ici]\n    rfl\n\ninstance [LocallyFiniteOrderBot \u03b1] [LocallyFiniteOrderBot \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] : LocallyFiniteOrderBot (\u03b1 \u00d7 \u03b2) :=\n  LocallyFiniteOrderBot.ofIic' (\u03b1 \u00d7 \u03b2) (fun a => Iic a.fst \u00d7\u1da0 Iic a.snd) fun a x =>\n    by\n    rw [mem_product, mem_Iic, mem_Iic]\n    rfl\n\ntheorem Icc_eq [LocallyFiniteOrder \u03b1] [LocallyFiniteOrder \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] (p q : \u03b1 \u00d7 \u03b2) :\n    Finset.Icc p q = Finset.Icc p.1 q.1 \u00d7\u1da0 Finset.Icc p.2 q.2 :=\n  rfl\n#align prod.Icc_eq Prod.Icc_eq\n\n@[simp]\ntheorem Icc_mk_mk [LocallyFiniteOrder \u03b1] [LocallyFiniteOrder \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] (a\u2081 a\u2082 : \u03b1) (b\u2081 b\u2082 : \u03b2) :\n    Finset.Icc (a\u2081, b\u2081) (a\u2082, b\u2082) = Finset.Icc a\u2081 a\u2082 \u00d7\u1da0 Finset.Icc b\u2081 b\u2082 :=\n  rfl\n#align prod.Icc_mk_mk Prod.Icc_mk_mk\n\ntheorem card_Icc [LocallyFiniteOrder \u03b1] [LocallyFiniteOrder \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] (p q : \u03b1 \u00d7 \u03b2) :\n    (Finset.Icc p q).card = (Finset.Icc p.1 q.1).card * (Finset.Icc p.2 q.2).card :=\n  Finset.card_product _ _\n#align prod.card_Icc Prod.card_Icc\n\nend Prod\n\nend Preorder\n\nnamespace Prod\n\nvariable [Lattice \u03b1] [Lattice \u03b2]\n\ntheorem uIcc_eq [LocallyFiniteOrder \u03b1] [LocallyFiniteOrder \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] (p q : \u03b1 \u00d7 \u03b2) :\n    Finset.uIcc p q = Finset.uIcc p.1 q.1 \u00d7\u1da0 Finset.uIcc p.2 q.2 :=\n  rfl\n#align prod.uIcc_eq Prod.uIcc_eq\n\n@[simp]\ntheorem uIcc_mk_mk [LocallyFiniteOrder \u03b1] [LocallyFiniteOrder \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] (a\u2081 a\u2082 : \u03b1) (b\u2081 b\u2082 : \u03b2) :\n    Finset.uIcc (a\u2081, b\u2081) (a\u2082, b\u2082) = Finset.uIcc a\u2081 a\u2082 \u00d7\u1da0 Finset.uIcc b\u2081 b\u2082 :=\n  rfl\n#align prod.uIcc_mk_mk Prod.uIcc_mk_mk\n\ntheorem card_uIcc [LocallyFiniteOrder \u03b1] [LocallyFiniteOrder \u03b2]\n    [DecidableRel ((\u00b7 \u2264 \u00b7) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1 \u00d7 \u03b2 \u2192 Prop)] (p q : \u03b1 \u00d7 \u03b2) :\n    (Finset.uIcc p q).card = (Finset.uIcc p.1 q.1).card * (Finset.uIcc p.2 q.2).card :=\n  Prod.card_Icc _ _\n#align prod.card_uIcc Prod.card_uIcc\n\nend Prod\n\n/-!\n#### `WithTop`, `WithBot`\n\nAdding a `\u22a4` to a locally finite `OrderTop` keeps it locally finite.\nAdding a `\u22a5` to a locally finite `OrderBot` keeps it locally finite.\n-/\n\n\nnamespace WithTop\n\nvariable (\u03b1) [PartialOrder \u03b1] [OrderTop \u03b1] [LocallyFiniteOrder \u03b1]\n\n-- Porting note: removed attribute [local match_pattern] coe\n\nattribute [local simp] Option.mem_iff\n\nprivate lemma aux (x : \u03b1) (p : \u03b1 \u2192 Prop) :\n    (\u2203 a : \u03b1, p a \u2227 Option.some a = Option.some x) \u2194 p x := by\n  -- Porting note: `simp [Option.some_inj]` has no effect\n  constructor\n  \u00b7 rintro \u27e8x', hx, hx'\u27e9\n    obtain rfl := Option.some_inj.mp hx'\n    exact hx\n  \u00b7 exact fun h => \u27e8x, h, rfl\u27e9\n\ninstance locallyFiniteOrder : LocallyFiniteOrder (WithTop \u03b1) where\n  finsetIcc a b :=\n    match a, b with\n    | \u22a4, \u22a4 => {\u22a4}\n    | \u22a4, (b : \u03b1) => \u2205\n    | (a : \u03b1), \u22a4 => insertNone (Ici a)\n    | (a : \u03b1), (b : \u03b1) => (Icc a b).map Embedding.some\n  finsetIco a b :=\n    match a, b with\n    | \u22a4, _ => \u2205\n    | (a : \u03b1), \u22a4 => (Ici a).map Embedding.some\n    | (a : \u03b1), (b : \u03b1) => (Ico a b).map Embedding.some\n  finsetIoc a b :=\n    match a, b with\n    | \u22a4, _ => \u2205\n    | (a : \u03b1), \u22a4 => insertNone (Ioi a)\n    | (a : \u03b1), (b : \u03b1) => (Ioc a b).map Embedding.some\n  finsetIoo a b :=\n    match a, b with\n    | \u22a4, _ => \u2205\n    | (a : \u03b1), \u22a4 => (Ioi a).map Embedding.some\n    | (a : \u03b1), (b : \u03b1) => (Ioo a b).map Embedding.some\n  -- Porting note: the proofs below got much worse\n  finset_mem_Icc a b x :=\n    match a, b, x with\n    | \u22a4, \u22a4, x => mem_singleton.trans (le_antisymm_iff.trans and_comm)\n    | \u22a4, (b : \u03b1), x =>\n      iff_of_false (not_mem_empty _) fun h => (h.1.trans h.2).not_lt <| coe_lt_top _\n    | (a : \u03b1), \u22a4, \u22a4 => by simp [WithTop.some, WithTop.top, insertNone]\n    | (a : \u03b1), \u22a4, (x : \u03b1) => by\n        simp only [some, le_eq_subset, some_le_some, le_top, and_true]\n        rw [some_mem_insertNone]\n        simp\n    | (a : \u03b1), (b : \u03b1), \u22a4 => by\n        simp only [some, le_eq_subset, mem_map, mem_Icc, le_top, top_le_iff, and_false, iff_false,\n          not_exists, not_and, and_imp, Embedding.some, forall_const]\n    | (a : \u03b1), (b : \u03b1), (x : \u03b1) => by\n        simp only [some, le_eq_subset, Embedding.some, mem_map, mem_Icc, Embedding.coeFn_mk,\n          some_le_some, aux]\n  finset_mem_Ico a b x :=\n    match a, b, x with\n    | \u22a4, b, x => iff_of_false (not_mem_empty _) fun h => not_top_lt <| h.1.trans_lt h.2\n    | (a : \u03b1), \u22a4, \u22a4 => by simp [some, Embedding.some]\n    | (a : \u03b1), \u22a4, (x : \u03b1) => by\n        simp only [some, Embedding.some, mem_map, mem_Ici, Embedding.coeFn_mk, some_le_some, aux,\n          top, some_lt_none, and_true]\n    | (a : \u03b1), (b : \u03b1), \u22a4 => by simp [some, Embedding.some]\n    | (a : \u03b1), (b : \u03b1), (x : \u03b1) => by simp [some, Embedding.some, aux]\n  finset_mem_Ioc a b x :=\n    match a, b, x with\n    | \u22a4, b, x => iff_of_false (not_mem_empty _) fun h => not_top_lt <| h.1.trans_le h.2\n    | (a : \u03b1), \u22a4, \u22a4 => by simp [some, insertNone, top]\n    | (a : \u03b1), \u22a4, (x : \u03b1) => by simp [some, Embedding.some, insertNone, aux]\n    | (a : \u03b1), (b : \u03b1), \u22a4 => by simp [some, Embedding.some, insertNone]\n    | (a : \u03b1), (b : \u03b1), (x : \u03b1) => by simp [some, Embedding.some, insertNone, aux]\n  finset_mem_Ioo a b x :=\n    match a, b, x with\n    | \u22a4, b, x => iff_of_false (not_mem_empty _) fun h => not_top_lt <| h.1.trans h.2\n    | (a : \u03b1), \u22a4, \u22a4 => by simp [some, Embedding.some, insertNone]\n    | (a : \u03b1), \u22a4, (x : \u03b1) => by simp [some, Embedding.some, insertNone, aux, top]\n    | (a : \u03b1), (b : \u03b1), \u22a4 => by simp [some, Embedding.some, insertNone]\n    | (a : \u03b1), (b : \u03b1), (x : \u03b1) => by\n      simp [some, Embedding.some, insertNone, aux]\n\nvariable (a b : \u03b1)\n\ntheorem Icc_coe_top : Icc (a : WithTop \u03b1) \u22a4 = insertNone (Ici a) :=\n  rfl\n#align with_top.Icc_coe_top WithTop.Icc_coe_top\n\ntheorem Icc_coe_coe : Icc (a : WithTop \u03b1) b = (Icc a b).map Embedding.some :=\n  rfl\n#align with_top.Icc_coe_coe WithTop.Icc_coe_coe\n\ntheorem Ico_coe_top : Ico (a : WithTop \u03b1) \u22a4 = (Ici a).map Embedding.some :=\n  rfl\n#align with_top.Ico_coe_top WithTop.Ico_coe_top\n\ntheorem Ico_coe_coe : Ico (a : WithTop \u03b1) b = (Ico a b).map Embedding.some :=\n  rfl\n#align with_top.Ico_coe_coe WithTop.Ico_coe_coe\n\ntheorem Ioc_coe_top : Ioc (a : WithTop \u03b1) \u22a4 = insertNone (Ioi a) :=\n  rfl\n#align with_top.Ioc_coe_top WithTop.Ioc_coe_top\n\ntheorem Ioc_coe_coe : Ioc (a : WithTop \u03b1) b = (Ioc a b).map Embedding.some :=\n  rfl\n#align with_top.Ioc_coe_coe WithTop.Ioc_coe_coe\n\ntheorem Ioo_coe_top : Ioo (a : WithTop \u03b1) \u22a4 = (Ioi a).map Embedding.some :=\n  rfl\n#align with_top.Ioo_coe_top WithTop.Ioo_coe_top\n\ntheorem Ioo_coe_coe : Ioo (a : WithTop \u03b1) b = (Ioo a b).map Embedding.some :=\n  rfl\n#align with_top.Ioo_coe_coe WithTop.Ioo_coe_coe\n\nend WithTop\n\nnamespace WithBot\n\nvariable (\u03b1) [PartialOrder \u03b1] [OrderBot \u03b1] [LocallyFiniteOrder \u03b1]\n\ninstance : LocallyFiniteOrder (WithBot \u03b1) :=\n  OrderDual.locallyFiniteOrder (\u03b1 := WithTop \u03b1\u1d52\u1d48)\n\nvariable (a b : \u03b1)\n\ntheorem Icc_bot_coe : Icc (\u22a5 : WithBot \u03b1) b = insertNone (Iic b) :=\n  rfl\n#align with_bot.Icc_bot_coe WithBot.Icc_bot_coe\n\ntheorem Icc_coe_coe : Icc (a : WithBot \u03b1) b = (Icc a b).map Embedding.some :=\n  rfl\n#align with_bot.Icc_coe_coe WithBot.Icc_coe_coe\n\ntheorem Ico_bot_coe : Ico (\u22a5 : WithBot \u03b1) b = insertNone (Iio b) :=\n  rfl\n#align with_bot.Ico_bot_coe WithBot.Ico_bot_coe\n\ntheorem Ico_coe_coe : Ico (a : WithBot \u03b1) b = (Ico a b).map Embedding.some :=\n  rfl\n#align with_bot.Ico_coe_coe WithBot.Ico_coe_coe\n\ntheorem Ioc_bot_coe : Ioc (\u22a5 : WithBot \u03b1) b = (Iic b).map Embedding.some :=\n  rfl\n#align with_bot.Ioc_bot_coe WithBot.Ioc_bot_coe\n\ntheorem Ioc_coe_coe : Ioc (a : WithBot \u03b1) b = (Ioc a b).map Embedding.some :=\n  rfl\n#align with_bot.Ioc_coe_coe WithBot.Ioc_coe_coe\n\ntheorem Ioo_bot_coe : Ioo (\u22a5 : WithBot \u03b1) b = (Iio b).map Embedding.some :=\n  rfl\n#align with_bot.Ioo_bot_coe WithBot.Ioo_bot_coe\n\ntheorem Ioo_coe_coe : Ioo (a : WithBot \u03b1) b = (Ioo a b).map Embedding.some :=\n  rfl\n#align with_bot.Ioo_coe_coe WithBot.Ioo_coe_coe\n\nend WithBot\n\nnamespace OrderIso\n\nvariable [Preorder \u03b1] [Preorder \u03b2]\n\n/-! #### Transfer locally finite orders across order isomorphisms -/\n\n\n-- See note [reducible non-instances]\n/-- Transfer `LocallyFiniteOrder` across an `OrderIso`. -/\n@[reducible]\ndef locallyFiniteOrder [LocallyFiniteOrder \u03b2] (f : \u03b1 \u2243o \u03b2) : LocallyFiniteOrder \u03b1 where\n  finsetIcc a b := (Icc (f a) (f b)).map f.symm.toEquiv.toEmbedding\n  finsetIco a b := (Ico (f a) (f b)).map f.symm.toEquiv.toEmbedding\n  finsetIoc a b := (Ioc (f a) (f b)).map f.symm.toEquiv.toEmbedding\n  finsetIoo a b := (Ioo (f a) (f b)).map f.symm.toEquiv.toEmbedding\n  finset_mem_Icc := by simp\n  finset_mem_Ico := by simp\n  finset_mem_Ioc := by simp\n  finset_mem_Ioo := by simp\n#align order_iso.locally_finite_order OrderIso.locallyFiniteOrder\n\n-- See note [reducible non-instances]\n/-- Transfer `LocallyFiniteOrderTop` across an `OrderIso`. -/\n@[reducible]\ndef locallyFiniteOrderTop [LocallyFiniteOrderTop \u03b2] (f : \u03b1 \u2243o \u03b2) : LocallyFiniteOrderTop \u03b1 where\n  finsetIci a := (Ici (f a)).map f.symm.toEquiv.toEmbedding\n  finsetIoi a := (Ioi (f a)).map f.symm.toEquiv.toEmbedding\n  finset_mem_Ici := by simp\n  finset_mem_Ioi := by simp\n#align order_iso.locally_finite_order_top OrderIso.locallyFiniteOrderTop\n\n-- See note [reducible non-instances]\n/-- Transfer `LocallyFiniteOrderBot` across an `OrderIso`. -/\n@[reducible]\ndef locallyFiniteOrderBot [LocallyFiniteOrderBot \u03b2] (f : \u03b1 \u2243o \u03b2) : LocallyFiniteOrderBot \u03b1 where\n  finsetIic a := (Iic (f a)).map f.symm.toEquiv.toEmbedding\n  finsetIio a := (Iio (f a)).map f.symm.toEquiv.toEmbedding\n  finset_mem_Iic := by simp\n  finset_mem_Iio := by simp\n#align order_iso.locally_finite_order_bot OrderIso.locallyFiniteOrderBot\n\nend OrderIso\n\n/-! #### Subtype of a locally finite order -/\n\n\nvariable [Preorder \u03b1] (p : \u03b1 \u2192 Prop) [DecidablePred p]\n\ninstance [LocallyFiniteOrder \u03b1] : LocallyFiniteOrder (Subtype p) where\n  finsetIcc a b := (Icc (a : \u03b1) b).subtype p\n  finsetIco a b := (Ico (a : \u03b1) b).subtype p\n  finsetIoc a b := (Ioc (a : \u03b1) b).subtype p\n  finsetIoo a b := (Ioo (a : \u03b1) b).subtype p\n  finset_mem_Icc a b x := by simp_rw [Finset.mem_subtype, mem_Icc, Subtype.coe_le_coe]\n  finset_mem_Ico a b x := by\n    simp_rw [Finset.mem_subtype, mem_Ico, Subtype.coe_le_coe, Subtype.coe_lt_coe]\n  finset_mem_Ioc a b x := by\n    simp_rw [Finset.mem_subtype, mem_Ioc, Subtype.coe_le_coe, Subtype.coe_lt_coe]\n  finset_mem_Ioo a b x := by simp_rw [Finset.mem_subtype, mem_Ioo, Subtype.coe_lt_coe]\n\ninstance [LocallyFiniteOrderTop \u03b1] : LocallyFiniteOrderTop (Subtype p) where\n  finsetIci a := (Ici (a : \u03b1)).subtype p\n  finsetIoi a := (Ioi (a : \u03b1)).subtype p\n  finset_mem_Ici a x := by simp_rw [Finset.mem_subtype, mem_Ici, Subtype.coe_le_coe]\n  finset_mem_Ioi a x := by simp_rw [Finset.mem_subtype, mem_Ioi, Subtype.coe_lt_coe]\n\ninstance [LocallyFiniteOrderBot \u03b1] : LocallyFiniteOrderBot (Subtype p) where\n  finsetIic a := (Iic (a : \u03b1)).subtype p\n  finsetIio a := (Iio (a : \u03b1)).subtype p\n  finset_mem_Iic a x := by simp_rw [Finset.mem_subtype, mem_Iic, Subtype.coe_le_coe]\n  finset_mem_Iio a x := by simp_rw [Finset.mem_subtype, mem_Iio, Subtype.coe_lt_coe]\n\nnamespace Finset\n\nsection LocallyFiniteOrder\n\nvariable [LocallyFiniteOrder \u03b1] (a b : Subtype p)\n\ntheorem subtype_Icc_eq : Icc a b = (Icc (a : \u03b1) b).subtype p :=\n  rfl\n#align finset.subtype_Icc_eq Finset.subtype_Icc_eq\n\ntheorem subtype_Ico_eq : Ico a b = (Ico (a : \u03b1) b).subtype p :=\n  rfl\n#align finset.subtype_Ico_eq Finset.subtype_Ico_eq\n\ntheorem subtype_Ioc_eq : Ioc a b = (Ioc (a : \u03b1) b).subtype p :=\n  rfl\n#align finset.subtype_Ioc_eq Finset.subtype_Ioc_eq\n\ntheorem subtype_Ioo_eq : Ioo a b = (Ioo (a : \u03b1) b).subtype p :=\n  rfl\n#align finset.subtype_Ioo_eq Finset.subtype_Ioo_eq\n\nvariable (hp : \u2200 \u2983a b x\u2984, a \u2264 x \u2192 x \u2264 b \u2192 p a \u2192 p b \u2192 p x)\n\ntheorem map_subtype_embedding_Icc : (Icc a b).map (Embedding.subtype p) = (Icc a b : Finset \u03b1) := by\n  rw [subtype_Icc_eq]\n  refine' Finset.subtype_map_of_mem fun x hx => _\n  rw [mem_Icc] at hx\n  exact hp hx.1 hx.2 a.prop b.prop\n#align finset.map_subtype_embedding_Icc Finset.map_subtype_embedding_Icc\n\ntheorem map_subtype_embedding_Ico : (Ico a b).map (Embedding.subtype p) = (Ico a b : Finset \u03b1) := by\n  rw [subtype_Ico_eq]\n  refine' Finset.subtype_map_of_mem fun x hx => _\n  rw [mem_Ico] at hx\n  exact hp hx.1 hx.2.le a.prop b.prop\n#align finset.map_subtype_embedding_Ico Finset.map_subtype_embedding_Ico\n\ntheorem map_subtype_embedding_Ioc : (Ioc a b).map (Embedding.subtype p) = (Ioc a b : Finset \u03b1) := by\n  rw [subtype_Ioc_eq]\n  refine' Finset.subtype_map_of_mem fun x hx => _\n  rw [mem_Ioc] at hx\n  exact hp hx.1.le hx.2 a.prop b.prop\n#align finset.map_subtype_embedding_Ioc Finset.map_subtype_embedding_Ioc\n\ntheorem map_subtype_embedding_Ioo : (Ioo a b).map (Embedding.subtype p) = (Ioo a b : Finset \u03b1) := by\n  rw [subtype_Ioo_eq]\n  refine' Finset.subtype_map_of_mem fun x hx => _\n  rw [mem_Ioo] at hx\n  exact hp hx.1.le hx.2.le a.prop b.prop\n#align finset.map_subtype_embedding_Ioo Finset.map_subtype_embedding_Ioo\n\nend LocallyFiniteOrder\n\nsection LocallyFiniteOrderTop\n\nvariable [LocallyFiniteOrderTop \u03b1] (a : Subtype p)\n\ntheorem subtype_Ici_eq : Ici a = (Ici (a : \u03b1)).subtype p :=\n  rfl\n#align finset.subtype_Ici_eq Finset.subtype_Ici_eq\n\ntheorem subtype_Ioi_eq : Ioi a = (Ioi (a : \u03b1)).subtype p :=\n  rfl\n#align finset.subtype_Ioi_eq Finset.subtype_Ioi_eq\n\nvariable (hp : \u2200 \u2983a x\u2984, a \u2264 x \u2192 p a \u2192 p x)\n\ntheorem map_subtype_embedding_Ici : (Ici a).map (Embedding.subtype p) = (Ici a : Finset \u03b1) := by\n  rw [subtype_Ici_eq]\n  exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ici.1 hx) a.prop\n#align finset.map_subtype_embedding_Ici Finset.map_subtype_embedding_Ici\n\n\n\nend LocallyFiniteOrderTop\n\nsection LocallyFiniteOrderBot\n\nvariable [LocallyFiniteOrderBot \u03b1] (a : Subtype p)\n\ntheorem subtype_Iic_eq : Iic a = (Iic (a : \u03b1)).subtype p :=\n  rfl\n#align finset.subtype_Iic_eq Finset.subtype_Iic_eq\n\ntheorem subtype_Iio_eq : Iio a = (Iio (a : \u03b1)).subtype p :=\n  rfl\n#align finset.subtype_Iio_eq Finset.subtype_Iio_eq\n\nvariable (hp : \u2200 \u2983a x\u2984, x \u2264 a \u2192 p a \u2192 p x)\n\ntheorem map_subtype_embedding_Iic : (Iic a).map (Embedding.subtype p) = (Iic a : Finset \u03b1) := by\n  rw [subtype_Iic_eq]\n  exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iic.1 hx) a.prop\n#align finset.map_subtype_embedding_Iic Finset.map_subtype_embedding_Iic\n\ntheorem map_subtype_embedding_Iio : (Iio a).map (Embedding.subtype p) = (Iio a : Finset \u03b1) := by\n  rw [subtype_Iio_eq]\n  exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iio.1 hx).le a.prop\n#align finset.map_subtype_embedding_Iio Finset.map_subtype_embedding_Iio\n\nend LocallyFiniteOrderBot\n\nend Finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/LocallyFinite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7083018958340204}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Oliver Nash\n-/\nimport data.finset.card\n\n/-!\n# Finsets in product types\n\nThis file defines finset constructions on the product type `\u03b1 \u00d7 \u03b2`. Beware not to confuse with the\n`finset.prod` operation which computes the multiplicative product.\n\n## Main declarations\n\n* `finset.product`: Turns `s : finset \u03b1`, `t : finset \u03b2` into their product in `finset (\u03b1 \u00d7 \u03b2)`.\n* `finset.diag`: For `s : finset \u03b1`, `s.diag` is the `finset (\u03b1 \u00d7 \u03b1)` of pairs `(a, a)` with\n  `a \u2208 s`.\n* `finset.off_diag`: For `s : finset \u03b1`, `s.off_diag` is the `finset (\u03b1 \u00d7 \u03b1)` of pairs `(a, b)` with\n  `a, b \u2208 s` and `a \u2260 b`.\n-/\n\nopen multiset\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\nnamespace finset\n\n/-! ### prod -/\nsection prod\nvariables {s s' : finset \u03b1} {t t' : finset \u03b2} {a : \u03b1} {b : \u03b2}\n\n/-- `product s t` is the set of pairs `(a, b)` such that `a \u2208 s` and `b \u2208 t`. -/\nprotected def product (s : finset \u03b1) (t : finset \u03b2) : finset (\u03b1 \u00d7 \u03b2) := \u27e8_, s.nodup.product t.nodup\u27e9\n\n@[simp] lemma product_val : (s.product t).1 = s.1.product t.1 := rfl\n\n@[simp] lemma mem_product {p : \u03b1 \u00d7 \u03b2} : p \u2208 s.product t \u2194 p.1 \u2208 s \u2227 p.2 \u2208 t := mem_product\n\nlemma mk_mem_product (ha : a \u2208 s) (hb : b \u2208 t) : (a, b) \u2208 s.product t := mem_product.2 \u27e8ha, hb\u27e9\n\n@[simp, norm_cast] lemma coe_product (s : finset \u03b1) (t : finset \u03b2) :\n  (s.product t : set (\u03b1 \u00d7 \u03b2)) = (s : set \u03b1) \u00d7\u02e2 (t : set \u03b2) :=\nset.ext $ \u03bb x, finset.mem_product\n\nlemma subset_product [decidable_eq \u03b1] [decidable_eq \u03b2] {s : finset (\u03b1 \u00d7 \u03b2)} :\n  s \u2286 (s.image prod.fst).product (s.image prod.snd) :=\n\u03bb p hp, mem_product.2 \u27e8mem_image_of_mem _ hp, mem_image_of_mem _ hp\u27e9\n\nlemma product_subset_product (hs : s \u2286 s') (ht : t \u2286 t') : s.product t \u2286 s'.product t' :=\n\u03bb \u27e8x,y\u27e9 h, mem_product.2 \u27e8hs (mem_product.1 h).1, ht (mem_product.1 h).2\u27e9\n\nlemma product_subset_product_left (hs : s \u2286 s') : s.product t \u2286 s'.product t :=\nproduct_subset_product hs (subset.refl _)\n\nlemma product_subset_product_right (ht : t \u2286 t') : s.product t \u2286 s.product t' :=\nproduct_subset_product (subset.refl _) ht\n\nlemma product_eq_bUnion [decidable_eq \u03b1] [decidable_eq \u03b2] (s : finset \u03b1) (t : finset \u03b2) :\n  s.product t = s.bUnion (\u03bba, t.image $ \u03bbb, (a, b)) :=\next $ \u03bb \u27e8x, y\u27e9, by simp only [mem_product, mem_bUnion, mem_image, exists_prop, prod.mk.inj_iff,\n  and.left_comm, exists_and_distrib_left, exists_eq_right, exists_eq_left]\n\nlemma product_eq_bUnion_right [decidable_eq \u03b1] [decidable_eq \u03b2] (s : finset \u03b1) (t : finset \u03b2) :\n  s.product t = t.bUnion (\u03bb b, s.image $ \u03bb a, (a, b)) :=\next $ \u03bb \u27e8x, y\u27e9, by simp only [mem_product, mem_bUnion, mem_image, exists_prop, prod.mk.inj_iff,\n  and.left_comm, exists_and_distrib_left, exists_eq_right, exists_eq_left]\n\n/-- See also `finset.sup_product_left`. -/\n@[simp] lemma product_bUnion [decidable_eq \u03b3] (s : finset \u03b1) (t : finset \u03b2) (f : \u03b1 \u00d7 \u03b2 \u2192 finset \u03b3) :\n  (s.product t).bUnion f = s.bUnion (\u03bb a, t.bUnion (\u03bb b, f (a, b))) :=\nby { classical, simp_rw [product_eq_bUnion, bUnion_bUnion, image_bUnion] }\n\n@[simp] lemma card_product (s : finset \u03b1) (t : finset \u03b2) : card (s.product t) = card s * card t :=\nmultiset.card_product _ _\n\nlemma filter_product (p : \u03b1 \u2192 Prop) (q : \u03b2 \u2192 Prop) [decidable_pred p] [decidable_pred q] :\n  (s.product t).filter (\u03bb (x : \u03b1 \u00d7 \u03b2), p x.1 \u2227 q x.2) = (s.filter p).product (t.filter q) :=\nby { ext \u27e8a, b\u27e9, simp only [mem_filter, mem_product],\n     exact and_and_and_comm (a \u2208 s) (b \u2208 t) (p a) (q b) }\n\nlemma filter_product_card (s : finset \u03b1) (t : finset \u03b2)\n  (p : \u03b1 \u2192 Prop) (q : \u03b2 \u2192 Prop) [decidable_pred p] [decidable_pred q] :\n  ((s.product t).filter (\u03bb (x : \u03b1 \u00d7 \u03b2), p x.1 \u2194 q x.2)).card =\n  (s.filter p).card * (t.filter q).card + (s.filter (not \u2218 p)).card * (t.filter (not \u2218 q)).card :=\nbegin\n  classical,\n  rw [\u2190 card_product, \u2190 card_product, \u2190 filter_product, \u2190 filter_product, \u2190 card_union_eq],\n  { apply congr_arg, ext \u27e8a, b\u27e9, simp only [filter_union_right, mem_filter, mem_product],\n    split; intros h; use h.1,\n    simp only [function.comp_app, and_self, h.2, em (q b)],\n    cases h.2; { try { simp at h_1 }, simp [h_1] } },\n  { rw disjoint_iff, change _ \u2229 _ = \u2205, ext \u27e8a, b\u27e9, rw mem_inter,\n    simp only [and_imp, mem_filter, not_and, not_not, function.comp_app, iff_false, mem_product,\n     not_mem_empty], intros, assumption }\nend\n\nlemma empty_product (t : finset \u03b2) : (\u2205 : finset \u03b1).product t = \u2205 := rfl\n\nlemma product_empty (s : finset \u03b1) : s.product (\u2205 : finset \u03b2) = \u2205 :=\neq_empty_of_forall_not_mem (\u03bb x h, (finset.mem_product.1 h).2)\n\nlemma nonempty.product (hs : s.nonempty) (ht : t.nonempty) : (s.product t).nonempty :=\nlet \u27e8x, hx\u27e9 := hs, \u27e8y, hy\u27e9 := ht in \u27e8(x, y), mem_product.2 \u27e8hx, hy\u27e9\u27e9\n\nlemma nonempty.fst (h : (s.product t).nonempty) : s.nonempty :=\nlet \u27e8xy, hxy\u27e9 := h in \u27e8xy.1, (mem_product.1 hxy).1\u27e9\n\nlemma nonempty.snd (h : (s.product t).nonempty) : t.nonempty :=\nlet \u27e8xy, hxy\u27e9 := h in \u27e8xy.2, (mem_product.1 hxy).2\u27e9\n\n@[simp] lemma nonempty_product : (s.product t).nonempty \u2194 s.nonempty \u2227 t.nonempty :=\n\u27e8\u03bb h, \u27e8h.fst, h.snd\u27e9, \u03bb h, h.1.product h.2\u27e9\n\n@[simp] lemma product_eq_empty {s : finset \u03b1} {t : finset \u03b2} : s.product t = \u2205 \u2194 s = \u2205 \u2228 t = \u2205 :=\nby rw [\u2190not_nonempty_iff_eq_empty, nonempty_product, not_and_distrib, not_nonempty_iff_eq_empty,\n  not_nonempty_iff_eq_empty]\n\n@[simp] lemma singleton_product {a : \u03b1} :\n  ({a} : finset \u03b1).product t = t.map \u27e8prod.mk a, prod.mk.inj_left _\u27e9 :=\nby { ext \u27e8x, y\u27e9, simp [and.left_comm, eq_comm] }\n\n@[simp] lemma product_singleton {b : \u03b2} :\n  s.product {b} = s.map \u27e8\u03bb i, (i, b), prod.mk.inj_right _\u27e9 :=\nby { ext \u27e8x, y\u27e9, simp [and.left_comm, eq_comm] }\n\nlemma singleton_product_singleton {a : \u03b1} {b : \u03b2} :\n  ({a} : finset \u03b1).product ({b} : finset \u03b2) = {(a, b)} :=\nby simp only [product_singleton, function.embedding.coe_fn_mk, map_singleton]\n\n@[simp] lemma union_product [decidable_eq \u03b1] [decidable_eq \u03b2] :\n  (s \u222a s').product t = s.product t \u222a s'.product t :=\nby { ext \u27e8x, y\u27e9, simp only [or_and_distrib_right, mem_union, mem_product] }\n\n@[simp] lemma product_union [decidable_eq \u03b1] [decidable_eq \u03b2] :\n  s.product (t \u222a t') = s.product t \u222a s.product t' :=\nby { ext \u27e8x, y\u27e9, simp only [and_or_distrib_left, mem_union, mem_product] }\n\nend prod\n\nsection diag\nvariables (s : finset \u03b1) [decidable_eq \u03b1]\n\n/-- Given a finite set `s`, the diagonal, `s.diag` is the set of pairs of the form `(a, a)` for\n`a \u2208 s`. -/\ndef diag := (s.product s).filter (\u03bb (a : \u03b1 \u00d7 \u03b1), a.fst = a.snd)\n\n/-- Given a finite set `s`, the off-diagonal, `s.off_diag` is the set of pairs `(a, b)` with `a \u2260 b`\nfor `a, b \u2208 s`. -/\ndef off_diag := (s.product s).filter (\u03bb (a : \u03b1 \u00d7 \u03b1), a.fst \u2260 a.snd)\n\n@[simp] lemma mem_diag (x : \u03b1 \u00d7 \u03b1) : x \u2208 s.diag \u2194 x.1 \u2208 s \u2227 x.1 = x.2 :=\nby { simp only [diag, mem_filter, mem_product], split; intros h;\n     simp only [h, and_true, eq_self_iff_true, and_self], rw \u2190h.2, exact h.1 }\n\n@[simp] lemma mem_off_diag (x : \u03b1 \u00d7 \u03b1) : x \u2208 s.off_diag \u2194 x.1 \u2208 s \u2227 x.2 \u2208 s \u2227 x.1 \u2260 x.2 :=\nby { simp only [off_diag, mem_filter, mem_product], split; intros h;\n     simp only [h, ne.def, not_false_iff, and_self] }\n\n@[simp] lemma diag_card : (diag s).card = s.card :=\nbegin\n  suffices : diag s = s.image (\u03bb a, (a, a)),\n  { rw this, apply card_image_of_inj_on, exact \u03bb x1 h1 x2 h2 h3, (prod.mk.inj h3).1 },\n  ext \u27e8a\u2081, a\u2082\u27e9, rw mem_diag, split; intros h; rw finset.mem_image at *,\n  { use [a\u2081, h.1, prod.mk.inj_iff.mpr \u27e8rfl, h.2\u27e9] },\n  { rcases h with \u27e8a, h1, h2\u27e9, have h := prod.mk.inj h2, rw [\u2190h.1, \u2190h.2], use h1 },\nend\n\n@[simp] lemma off_diag_card : (off_diag s).card = s.card * s.card - s.card :=\nbegin\n  suffices : (diag s).card + (off_diag s).card = s.card * s.card,\n  { nth_rewrite 2 \u2190 s.diag_card, simp only [diag_card] at *, rw tsub_eq_of_eq_add_rev, rw this },\n  rw \u2190 card_product,\n  apply filter_card_add_filter_neg_card_eq_card,\nend\n\n@[simp] lemma diag_empty : (\u2205 : finset \u03b1).diag = \u2205 := rfl\n\n@[simp] lemma off_diag_empty : (\u2205 : finset \u03b1).off_diag = \u2205 := rfl\n\n@[simp] lemma diag_union_off_diag : s.diag \u222a s.off_diag = s.product s :=\nfilter_union_filter_neg_eq _ _\n\n@[simp] lemma disjoint_diag_off_diag : disjoint s.diag s.off_diag := disjoint_filter_filter_neg _ _\n\nend diag\nend finset\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/finset/prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7083018891486978}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.star.basic\nimport algebra.star.module\nimport analysis.special_functions.exponential\n\n/-! # The exponential map from selfadjoint to unitary\nIn this file, we establish various propreties related to the map `\u03bb a, exp \u2102 A (I \u2022 a)` between the\nsubtypes `self_adjoint A` and `unitary A`.\n\n## TODO\n\n* Show that any exponential unitary is path-connected in `unitary A` to `1 : unitary A`.\n* Prove any unitary whose distance to `1 : unitary A` is less than `1` can be expressed as an\n  exponential unitary.\n* A unitary is in the path component of `1` if and only if it is a finite product of exponential\n  unitaries.\n-/\n\nsection star\n\nvariables {A : Type*}\n[normed_ring A] [normed_algebra \u2102 A] [star_ring A] [has_continuous_star A] [complete_space A]\n[star_module \u2102 A]\n\nopen complex\n\nlemma self_adjoint.exp_i_smul_unitary {a : A} (ha : a \u2208 self_adjoint A) :\n  exp \u2102 (I \u2022 a) \u2208 unitary A :=\nbegin\n  rw [unitary.mem_iff, star_exp],\n  simp only [star_smul, is_R_or_C.star_def, self_adjoint.mem_iff.mp ha, conj_I, neg_smul],\n  rw \u2190@exp_add_of_commute \u2102 A _ _ _ _ _ _ ((commute.refl (I \u2022 a)).neg_left),\n  rw \u2190@exp_add_of_commute \u2102 A _ _ _ _ _ _ ((commute.refl (I \u2022 a)).neg_right),\n  simpa only [add_right_neg, add_left_neg, and_self] using (exp_zero : exp \u2102 (0 : A) = 1),\nend\n\n/-- The map from the selfadjoint real subspace to the unitary group. This map only makes sense\nover \u2102. -/\n@[simps]\nnoncomputable def self_adjoint.exp_unitary (a : self_adjoint A) : unitary A :=\n\u27e8exp \u2102 (I \u2022 a), self_adjoint.exp_i_smul_unitary (a.property)\u27e9\n\nopen self_adjoint\n\nlemma commute.exp_unitary_add {a b : self_adjoint A} (h : commute (a : A) (b : A)) :\n  exp_unitary (a + b) = exp_unitary a * exp_unitary b :=\nbegin\n  ext,\n  have hcomm : commute (I \u2022 (a : A)) (I \u2022 (b : A)),\n  calc _ = _ : by simp only [h.eq, algebra.smul_mul_assoc, algebra.mul_smul_comm],\n  simpa only [exp_unitary_coe, add_subgroup.coe_add, smul_add] using exp_add_of_commute hcomm,\nend\n\nlemma commute.exp_unitary {a b : self_adjoint A} (h : commute (a : A) (b : A)) :\n  commute (exp_unitary a) (exp_unitary b) :=\ncalc (exp_unitary a) * (exp_unitary b) = (exp_unitary b) * (exp_unitary a)\n  : by rw [\u2190h.exp_unitary_add, \u2190h.symm.exp_unitary_add, add_comm]\n\nend star\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/normed_space/star/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7083018842225544}}
{"text": "import tactic -- hide\nimport data.real.basic -- hide\n\n/-\n## More on `cases`\n\nWhat if we have a *disjunction* in an hypothesis? In this case, the proof usually\nsplits into two paths, one which assumes the left condition, and the other which assumes\nthe right one. This is also achieved with the `cases` tactic. If `h : P \u2228 Q`, then\n`cases h,` will produce two goals. In the first one, we will have `h : P` and in the second\n`h : Q`.\n-/\n\n/- Lemma : no-side-bar\nIf $a = 3$ or $a = -3$, then $a^2=9$.\n-/\nlemma c2 (a : \u2124) (h : a = 3 \u2228 a = -3) : a^2 = 9 :=\nbegin\n  cases h,\n  {\n    rw h,\n    ring,\n  },\n  {\n    rw h,\n    ring,\n  }\n\n\n\n\n\nend", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/tactics_world/07_cases2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.708301876129446}}
{"text": "-- Las_familias_de_conjuntos_definen_relaciones_simetricas.lean\n-- Las familias de conjuntos definen relaciones sim\u00e9tricas\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 26 de agosto de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Cada familia de conjuntos P define una relaci\u00f3n de forma que dos\n-- elementos est\u00e1n relacionados si alg\u00fan conjunto de P contiene a ambos\n-- elementos. Se puede definir en Lean por\n--    def relacion (P : set (set X)) (x y : X) :=\n--      \u2203 A \u2208 P, x \u2208 A \u2227 y \u2208 A\n--\n-- Demostrar que si P es una familia de subconjunt\u2759os de X, entonces la\n-- relaci\u00f3n definida por P es sim\u00e9trica.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\nvariable {X : Type}\nvariable (P : set (set X))\n\ndef relacion (P : set (set X)) (x y : X) :=\n  \u2203 A \u2208 P, x \u2208 A \u2227 y \u2208 A\n\n-- 1\u00aa demostraci\u00f3n\nexample : symmetric (relacion P) :=\nbegin\n  unfold symmetric,\n  intros x y hxy,\n  unfold relacion at *,\n  rcases hxy with \u27e8B, hBP, \u27e8hxB, hyB\u27e9\u27e9,\n  use B,\n  repeat { split },\n  { exact hBP, },\n  { exact hyB, },\n  { exact hxB, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample : symmetric (relacion P) :=\nbegin\n  intros x y hxy,\n  rcases hxy with \u27e8B, hBP, \u27e8hxB, hyB\u27e9\u27e9,\n  use B,\n  repeat { split } ;\n  assumption,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample : symmetric (relacion P) :=\nbegin\n  intros x y hxy,\n  rcases hxy with \u27e8B, hBP, \u27e8hxB, hyB\u27e9\u27e9,\n  use [B, \u27e8hBP, hyB, hxB\u27e9],\nend\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Las_familias_de_conjuntos_definen_relaciones_simetricas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7082958117080965}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Bhavik Mehta\n-/\nimport data.nat.factorial\n/-!\n# Binomial coefficients\n\nThis file contains a definition of binomial coefficients and simple lemmas (i.e. those not\nrequiring more imports).\n\n## Main definition and results\n\n- `nat.choose`: binomial coefficients, defined inductively\n- `nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`\n- `nat.choose_symm`: symmetry of binomial coefficients\n- `nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`\n- `nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`\n\n-/\n\nopen_locale nat\n\nnamespace nat\n\n/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial\ncoefficients. -/\ndef choose : \u2115 \u2192 \u2115 \u2192 \u2115\n| _             0 := 1\n| 0       (k + 1) := 0\n| (n + 1) (k + 1) := choose n k + choose n (k + 1)\n\n@[simp] lemma choose_zero_right (n : \u2115) : choose n 0 = 1 := by cases n; refl\n\n@[simp] lemma choose_zero_succ (k : \u2115) : choose 0 (succ k) = 0 := rfl\n\nlemma choose_succ_succ (n k : \u2115) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl\n\nlemma choose_eq_zero_of_lt : \u2200 {n k}, n < k \u2192 choose n k = 0\n| _             0 hk := absurd hk dec_trivial\n| 0       (k + 1) hk := choose_zero_succ _\n| (n + 1) (k + 1) hk :=\n  have hnk : n < k, from lt_of_succ_lt_succ hk,\n  have hnk1 : n < k + 1, from lt_of_succ_lt hk,\n  by rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]\n\n@[simp] lemma choose_self (n : \u2115) : choose n n = 1 :=\nby induction n; simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]\n\n@[simp] lemma choose_succ_self (n : \u2115) : choose n (succ n) = 0 :=\nchoose_eq_zero_of_lt (lt_succ_self _)\n\n@[simp] lemma choose_one_right (n : \u2115) : choose n 1 = n :=\nby induction n; simp [*, choose, add_comm]\n\n/- The `n+1`-st triangle number is `n` more than the `n`-th triangle number -/\nlemma triangle_succ (n : \u2115) : (n + 1) * ((n + 1) - 1) / 2 = n * (n - 1) / 2 + n :=\nbegin\n  rw [\u2190 add_mul_div_left, mul_comm 2 n, \u2190 mul_add, nat.add_sub_cancel, mul_comm],\n  cases n; refl, apply zero_lt_succ\nend\n\n/-- `choose n 2` is the `n`-th triangle number. -/\nlemma choose_two_right (n : \u2115) : choose n 2 = n * (n - 1) / 2 :=\nbegin\n  induction n with n ih,\n  simp,\n  {rw triangle_succ n, simp [choose, ih], rw add_comm},\nend\n\nlemma choose_pos : \u2200 {n k}, k \u2264 n \u2192 0 < choose n k\n| 0             _ hk := by rw [eq_zero_of_le_zero hk]; exact dec_trivial\n| (n + 1)       0 hk := by simp; exact dec_trivial\n| (n + 1) (k + 1) hk := by rw choose_succ_succ;\n    exact add_pos_of_pos_of_nonneg (choose_pos (le_of_succ_le_succ hk)) (nat.zero_le _)\n\nlemma succ_mul_choose_eq : \u2200 n k, succ n * choose n k = choose (succ n) (succ k) * succ k\n| 0             0 := dec_trivial\n| 0       (k + 1) := by simp [choose]\n| (n + 1)       0 := by simp\n| (n + 1) (k + 1) :=\n  by rw [choose_succ_succ (succ n) (succ k), add_mul, \u2190succ_mul_choose_eq, mul_succ,\n  \u2190succ_mul_choose_eq, add_right_comm, \u2190mul_add, \u2190choose_succ_succ, \u2190succ_mul]\n\nlemma choose_mul_factorial_mul_factorial : \u2200 {n k}, k \u2264 n \u2192 choose n k * k! * (n - k)! = n!\n| 0              _ hk := by simp [eq_zero_of_le_zero hk]\n| (n + 1)        0 hk := by simp\n| (n + 1) (succ k) hk :=\nbegin\n  cases lt_or_eq_of_le hk with hk\u2081 hk\u2081,\n  { have h : choose n k * k.succ! * (n-k)! = k.succ * n! :=\n      by rw \u2190 choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk);\n      simp [factorial_succ, mul_comm, mul_left_comm],\n    have h\u2081 : (n - k)! = (n - k) * (n - k.succ)! :=\n      by rw [\u2190 succ_sub_succ, succ_sub (le_of_lt_succ hk\u2081), factorial_succ],\n    have h\u2082 : choose n (succ k) * k.succ! * ((n - k) * (n - k.succ)!) = (n - k) * n! :=\n      by rw \u2190 choose_mul_factorial_mul_factorial (le_of_lt_succ hk\u2081);\n      simp [factorial_succ, mul_comm, mul_left_comm, mul_assoc],\n    have h\u2083 : k * n! \u2264 n * n! := mul_le_mul_right _ (le_of_succ_le_succ hk),\n  rw [choose_succ_succ, add_mul, add_mul, succ_sub_succ, h, h\u2081, h\u2082, \u2190 add_one, add_mul,\n      nat.mul_sub_right_distrib, factorial_succ, \u2190 nat.add_sub_assoc h\u2083, add_assoc, \u2190 add_mul,\n      nat.add_sub_cancel_left, add_comm] },\n  { simp [hk\u2081, mul_comm, choose, nat.sub_self] }\nend\n\ntheorem choose_eq_factorial_div_factorial {n k : \u2115} (hk : k \u2264 n) :\n  choose n k = n! / (k! * (n - k)!) :=\nbegin\n  rw [\u2190 choose_mul_factorial_mul_factorial hk, mul_assoc],\n  exact (mul_div_left _ (mul_pos (factorial_pos _) (factorial_pos _))).symm\nend\n\nlemma add_choose (i j : \u2115) : (i + j).choose j = (i + j)! / (i! * j!) :=\nby rw [choose_eq_factorial_div_factorial (le_add_left j i), nat.add_sub_cancel, mul_comm]\n\n\n\ntheorem factorial_mul_factorial_dvd_factorial {n k : \u2115} (hk : k \u2264 n) : k! * (n - k)! \u2223 n! :=\nby rw [\u2190choose_mul_factorial_mul_factorial hk, mul_assoc]; exact dvd_mul_left _ _\n\nlemma factorial_mul_factorial_dvd_factorial_add (i j : \u2115) :\n  i! * j! \u2223 (i + j)! :=\nbegin\n  convert factorial_mul_factorial_dvd_factorial (le.intro rfl),\n  rw nat.add_sub_cancel_left\nend\n\n@[simp] lemma choose_symm {n k : \u2115} (hk : k \u2264 n) : choose n (n-k) = choose n k :=\nby rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (sub_le _ _),\n  nat.sub_sub_self hk, mul_comm]\n\nlemma choose_symm_of_eq_add {n a b : \u2115} (h : n = a + b) : nat.choose n a = nat.choose n b :=\nby { convert nat.choose_symm (nat.le_add_left _ _), rw nat.add_sub_cancel}\n\nlemma choose_symm_add {a b : \u2115} : choose (a+b) a = choose (a+b) b :=\nchoose_symm_of_eq_add rfl\n\nlemma choose_symm_half (m : \u2115) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m :=\nby { apply choose_symm_of_eq_add,\n  rw [add_comm m 1, add_assoc 1 m m, add_comm (2 * m) 1, two_mul m] }\n\nlemma choose_succ_right_eq (n k : \u2115) : choose n (k + 1) * (k + 1) = choose n k * (n - k) :=\nbegin\n  have e : (n+1) * choose n k = choose n k * (k+1) + choose n (k+1) * (k+1),\n    rw [\u2190 right_distrib, \u2190 choose_succ_succ, succ_mul_choose_eq],\n  rw [\u2190 nat.sub_eq_of_eq_add e, mul_comm, \u2190 nat.mul_sub_left_distrib, nat.add_sub_add_right]\nend\n\n@[simp] lemma choose_succ_self_right : \u2200 (n:\u2115), (n+1).choose n = n+1\n| 0     := rfl\n| (n+1) := by rw [choose_succ_succ, choose_succ_self_right, choose_self]\n\nlemma choose_mul_succ_eq (n k : \u2115) :\n  (n.choose k) * (n + 1) = ((n+1).choose k) * (n + 1 - k) :=\nbegin\n  induction k with k ih, { simp },\n  by_cases hk : n < k + 1,\n  { rw [choose_eq_zero_of_lt hk, sub_eq_zero_of_le hk, zero_mul, mul_zero] },\n  push_neg at hk,\n  replace hk : k + 1 \u2264 n + 1 := _root_.le_add_right hk,\n  rw [choose_succ_succ],\n  rw [add_mul, succ_sub_succ],\n  rw [\u2190 choose_succ_right_eq],\n  rw [\u2190 succ_sub_succ, nat.mul_sub_left_distrib],\n  symmetry,\n  apply nat.add_sub_cancel',\n  exact mul_le_mul_left _ hk,\nend\n\n/-! ### Inequalities -/\n\n/-- Show that `nat.choose` is increasing for small values of the right argument. -/\nlemma choose_le_succ_of_lt_half_left {r n : \u2115} (h : r < n/2) :\n  choose n r \u2264 choose n (r+1) :=\nbegin\n  refine le_of_mul_le_mul_right _ (nat.lt_sub_left_of_add_lt (lt_of_lt_of_le h (n.div_le_self 2))),\n  rw \u2190 choose_succ_right_eq,\n  apply nat.mul_le_mul_left,\n  rw [\u2190 nat.lt_iff_add_one_le, nat.lt_sub_left_iff_add_lt, \u2190 mul_two],\n  exact lt_of_lt_of_le (mul_lt_mul_of_pos_right h zero_lt_two) (n.div_mul_le_self 2),\nend\n\n/-- Show that for small values of the right argument, the middle value is largest. -/\nprivate lemma choose_le_middle_of_le_half_left {n r : \u2115} (hr : r \u2264 n/2) :\n  choose n r \u2264 choose n (n/2) :=\ndecreasing_induction\n  (\u03bb _ k a,\n      (eq_or_lt_of_le a).elim\n        (\u03bb t, t.symm \u25b8 le_refl _)\n        (\u03bb h, trans (choose_le_succ_of_lt_half_left h) (k h)))\n  hr (\u03bb _, le_refl _) hr\n\n/-- `choose n r` is maximised when `r` is `n/2`. -/\nlemma choose_le_middle (r n : \u2115) : choose n r \u2264 choose n (n/2) :=\nbegin\n  cases le_or_gt r n with b b,\n  { cases le_or_lt r (n/2) with a h,\n    { apply choose_le_middle_of_le_half_left a },\n    { rw \u2190 choose_symm b,\n      apply choose_le_middle_of_le_half_left,\n      rw [div_lt_iff_lt_mul' zero_lt_two] at h,\n      rw [le_div_iff_mul_le' zero_lt_two, nat.mul_sub_right_distrib, nat.sub_le_iff,\n          mul_two, nat.add_sub_cancel],\n      exact le_of_lt h } },\n  { rw choose_eq_zero_of_lt b,\n    apply zero_le }\nend\n\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/choose/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384595, "lm_q2_score": 0.7853085884247212, "lm_q1q2_score": 0.7082860595674251}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.box_integral.partition.additive\nimport measure_theory.measure.lebesgue\n\n/-!\n# Box-additive functions defined by measures\n\nIn this file we prove a few simple facts about rectangular boxes, partitions, and measures:\n\n- given a box `I : box \u03b9`, its coercion to `set (\u03b9 \u2192 \u211d)` and `I.Icc` are measurable sets;\n- if `\u03bc` is a locally finite measure, then `(I : set (\u03b9 \u2192 \u211d))` and `I.Icc` have finite measure;\n- if `\u03bc` is a locally finite measure, then `\u03bb J, (\u03bc J).to_real` is a box additive function.\n\nFor the last statement, we both prove it as a proposition and define a bundled\n`box_integral.box_additive` function.\n\n### Tags\n\nrectangular box, measure\n-/\n\nopen set\nnoncomputable theory\nopen_locale ennreal big_operators classical box_integral\n\nvariables {\u03b9 : Type*}\n\nnamespace box_integral\n\nopen measure_theory\n\nnamespace box\nvariables (I : box \u03b9)\n\nlemma measure_Icc_lt_top (\u03bc : measure (\u03b9 \u2192 \u211d)) [is_locally_finite_measure \u03bc] : \u03bc I.Icc < \u221e :=\nshow \u03bc (Icc I.lower I.upper) < \u221e, from I.is_compact_Icc.measure_lt_top\n\nlemma measure_coe_lt_top (\u03bc : measure (\u03b9 \u2192 \u211d)) [is_locally_finite_measure \u03bc] : \u03bc I < \u221e :=\n(measure_mono $ coe_subset_Icc).trans_lt (I.measure_Icc_lt_top \u03bc)\n\nsection countable\nvariables [countable \u03b9]\n\nlemma measurable_set_coe : measurable_set (I : set (\u03b9 \u2192 \u211d)) :=\nby { rw coe_eq_pi, exact measurable_set.univ_pi (\u03bb i, measurable_set_Ioc) }\n\nlemma measurable_set_Icc : measurable_set I.Icc := measurable_set_Icc\n\nlemma measurable_set_Ioo : measurable_set I.Ioo := measurable_set.univ_pi $ \u03bb i, measurable_set_Ioo\n\nend countable\n\nvariables [fintype \u03b9]\n\nlemma coe_ae_eq_Icc : (I : set (\u03b9 \u2192 \u211d)) =\u1d50[volume] I.Icc :=\nby { rw coe_eq_pi, exact measure.univ_pi_Ioc_ae_eq_Icc }\n\nlemma Ioo_ae_eq_Icc : I.Ioo =\u1d50[volume] I.Icc :=\nmeasure.univ_pi_Ioo_ae_eq_Icc\n\nend box\n\nlemma prepartition.measure_Union_to_real [finite \u03b9] {I : box \u03b9} (\u03c0 : prepartition I)\n  (\u03bc : measure (\u03b9 \u2192 \u211d)) [is_locally_finite_measure \u03bc] :\n  (\u03bc \u03c0.Union).to_real = \u2211 J in \u03c0.boxes, (\u03bc J).to_real :=\nbegin\n  erw [\u2190 ennreal.to_real_sum, \u03c0.Union_def, measure_bUnion_finset \u03c0.pairwise_disjoint],\n  exacts [\u03bb J hJ, J.measurable_set_coe, \u03bb J hJ, (J.measure_coe_lt_top \u03bc).ne]\nend\n\nend box_integral\n\nopen box_integral box_integral.box\n\nvariables [fintype \u03b9]\n\nnamespace measure_theory\n\nnamespace measure\n\n/-- If `\u03bc` is a locally finite measure on `\u211d\u207f`, then `\u03bb J, (\u03bc J).to_real` is a box-additive\nfunction. -/\n@[simps] def to_box_additive (\u03bc : measure (\u03b9 \u2192 \u211d)) [is_locally_finite_measure \u03bc] :\n  \u03b9 \u2192\u1d47\u1d43[\u22a4] \u211d :=\n{ to_fun := \u03bb J, (\u03bc J).to_real,\n  sum_partition_boxes' := \u03bb J hJ \u03c0 h\u03c0, by rw [\u2190 \u03c0.measure_Union_to_real, h\u03c0.Union_eq] }\n\nend measure\n\nend measure_theory\n\nnamespace box_integral\n\nopen measure_theory\n\nnamespace box\n\n@[simp] lemma volume_apply (I : box \u03b9) :\n  (volume : measure (\u03b9 \u2192 \u211d)).to_box_additive I = \u220f i, (I.upper i - I.lower i) :=\nby rw [measure.to_box_additive_apply, coe_eq_pi, real.volume_pi_Ioc_to_real I.lower_le_upper]\n\nlemma volume_face_mul {n} (i : fin (n + 1)) (I : box (fin (n + 1))) :\n  (\u220f j, ((I.face i).upper j - (I.face i).lower j)) * (I.upper i - I.lower i) =\n    \u220f j, (I.upper j - I.lower j) :=\nby simp only [face_lower, face_upper, (\u2218), fin.prod_univ_succ_above _ i, mul_comm]\n\nend box\n\nnamespace box_additive_map\n\n/-- Box-additive map sending each box `I` to the continuous linear endomorphism\n`x \u21a6 (volume I).to_real \u2022 x`. -/\nprotected def volume {E : Type*} [normed_add_comm_group E] [normed_space \u211d E] :\n  \u03b9 \u2192\u1d47\u1d43 (E \u2192L[\u211d] E) :=\n(volume : measure (\u03b9 \u2192 \u211d)).to_box_additive.to_smul\n\nlemma volume_apply {E : Type*} [normed_add_comm_group E] [normed_space \u211d E] (I : box \u03b9) (x : E) :\n  box_additive_map.volume I x = (\u220f j, (I.upper j - I.lower j)) \u2022 x :=\ncongr_arg2 (\u2022) I.volume_apply rfl\n\nend box_additive_map\n\nend box_integral\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/box_integral/partition/measure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7082860424181112}}
{"text": "import Lean\n\nopen Lean\nopen Lean.Meta\nopen Lean.Elab.Tactic\n\nuniverses u\naxiom elimEx (motive : Nat \u2192 Nat \u2192 Sort u) (x y : Nat)\n  (diag  : (a : Nat) \u2192 motive a a)\n  (upper : (delta a : Nat) \u2192 motive a (a + delta.succ))\n  (lower : (delta a : Nat) \u2192 motive (a + delta.succ) a)\n  : motive y x\n\ntheorem ex1 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => apply Or.inl; apply Nat.leRefl\n  | lower d => apply Or.inl; show p \u2264 p + d.succ; admit\n  | upper d => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex2 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx\n  case lower => admit\n  case upper => admit\n  case diag  => apply Or.inl; apply Nat.leRefl\n\naxiom Nat.parityElim (motive : Nat \u2192 Sort u)\n  (even : (n : Nat) \u2192 motive (2*n))\n  (odd  : (n : Nat) \u2192 motive (2*n+1))\n  (n : Nat)\n  : motive n\n\ntheorem time2Eq (n : Nat) : 2*n = n + n := by\n  rw [Nat.mul_comm]\n  show (0 + n) + n = n+n\n  simp\n\ntheorem ex3 (n : Nat) : Exists (fun m => n = m + m \u2228 n = m + m + 1) := by\n  cases n using Nat.parityElim with\n  | even i =>\n    apply Exists.intro i\n    apply Or.inl\n    rw [time2Eq]\n  | odd i =>\n    apply Exists.intro i\n    apply Or.inr\n    rw [time2Eq]\n\nopen Nat in\ntheorem ex3b (n : Nat) : Exists (fun m => n = m + m \u2228 n = m + m + 1) := by\n  cases n using parityElim with\n  | even i =>\n    apply Exists.intro i\n    apply Or.inl\n    rw [time2Eq]\n  | odd i =>\n    apply Exists.intro i\n    apply Or.inr\n    rw [time2Eq]\n\ndef ex4 {\u03b1} (xs : List \u03b1) (h : xs = [] \u2192 False) : \u03b1 := by\n  cases he:xs with\n  | nil      => contradiction\n  | cons x _ => exact x\n\ndef ex5 {\u03b1} (xs : List \u03b1) (h : xs = [] \u2192 False) : \u03b1 := by\n  cases he:xs using List.casesOn with\n  | nil      => contradiction\n  | cons x _ => exact x\n\ntheorem ex6 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false :=\n  match he:f xs with\n  | true  => False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex7 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false := by\n  cases he:f xs with\n  | true  => exact False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex8 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false := by\n  cases he:f xs using Bool.casesOn with\n  | true  => exact False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex9 (xs : List \u03b1) (h : xs = [] \u2192 False) : Nonempty \u03b1 := by\n  cases xs using List.rec with\n  | nil      => contradiction\n  | cons x _ => apply Nonempty.intro; assumption\n\ntheorem modLt (x : Nat) {y : Nat} (h : y > 0) : x % y < y := by\n  induction x, y using Nat.mod.inductionOn with\n  | ind x y h\u2081 ih =>\n    rw [Nat.mod_eq_sub_mod h\u2081.2]\n    exact ih h\n  | base x y h\u2081 =>\n    match Iff.mp (Decidable.notAndIffOrNot ..) h\u2081 with\n    | Or.inl h\u2081 => contradiction\n    | Or.inr h\u2081 =>\n      have hgt := Nat.gtOfNotLe h\u2081\n      have heq := Nat.mod_eq_of_lt hgt\n      rw [\u2190 heq] at hgt\n      assumption\n\ntheorem ex11 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\n  induction h using Or.casesOn with\n  | inr h  => ?myright\n  | inl h  => ?myleft\n  case myleft  => exact Or.inr h\n  case myright => exact Or.inl h\n\ntheorem ex12 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\n  cases h using Or.casesOn with\n  | inr h  => ?myright\n  | inl h  => ?myleft\n  case myleft  => exact Or.inr h\n  case myright => exact Or.inl h\n\ntheorem ex13 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => ?hlower\n  | upper d => ?hupper\n  case hdiag  => apply Or.inl; apply Nat.leRefl\n  case hlower => apply Or.inl; show p \u2264 p + d.succ; admit\n  case hupper => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex14 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => _\n  | upper d => ?hupper\n  case hdiag  => apply Or.inl; apply Nat.leRefl\n  case lower => apply Or.inl; show p \u2264 p + d.succ; admit\n  case hupper => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex15 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => _\n  | upper d => ?hupper\n  { apply Or.inl; apply Nat.leRefl }\n  { apply Or.inr; show q + d.succ > q; admit }\n  { apply Or.inl; show p \u2264 p + d.succ; admit }\n\ntheorem ex16 {p q : Prop} (h : p \u2228 q) : q \u2228 p := by\n  induction h\n  case inl h' => exact Or.inr h'\n  case inr h' => exact Or.inl h'\n\ntheorem ex17 (n : Nat) : 0 + n = n := by\n  induction n\n  case zero => rfl\n  case succ m ih =>\n    show Nat.succ (0 + m) = Nat.succ m\n    rw [ih]\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/casesUsing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.7082860420269109}}
{"text": "theorem le_antisymm (a b : mynat) (hab : a \u2264 b) (hba : b \u2264 a) : a = b :=\nbegin\ncases hab with c hc,\ncases hba with d hd,\nrw hd at hc,\nrw add_assoc at hc,\nsymmetry at hc,\nhave h := eq_zero_of_add_right_eq_self hc,\nhave h2 := add_right_eq_zero h,\nrw h2 at hd,\nrw add_zero at hd,\nexact hd,\nend", "meta": {"author": "nicholaspun", "repo": "natural-number-game-solutions", "sha": "1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0", "save_path": "github-repos/lean/nicholaspun-natural-number-game-solutions", "path": "github-repos/lean/nicholaspun-natural-number-game-solutions/natural-number-game-solutions-1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0/8-inequality-world/l6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7082860337456539}}
{"text": "/-\nCopyright (c) 2015 Nathaniel Thomas. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Nathaniel Thomas, Jeremy Avigad, Johannes H\u00f6lzl, Mario Carneiro\n\n! This file was ported from Lean 3 source module algebra.module.basic\n! leanprover-community/mathlib commit 30413fc89f202a090a54d78e540963ed3de0056e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.SMulWithZero\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Rat.Basic\nimport Mathlib.GroupTheory.GroupAction.Group\nimport Mathlib.Tactic.Abel\nimport Mathlib.Tactic.NthRewrite\n\n/-!\n# Modules over a ring\n\nIn this file we define\n\n* `Module R M` : an additive commutative monoid `M` is a `Module` over a\n  `Semiring R` if for `r : R` and `x : M` their \"scalar multiplication\" `r \u2022 x : M` is defined, and\n  the operation `\u2022` satisfies some natural associativity and distributivity axioms similar to those\n  on a ring.\n\n## Implementation notes\n\nIn typical mathematical usage, our definition of `Module` corresponds to \"semimodule\", and the\nword \"module\" is reserved for `Module R M` where `R` is a `ring` and `M` an `AddCommGroup`.\nIf `R` is a `Field` and `M` an `AddCommGroup`, `M` would be called an `R`-vector space.\nSince those assumptions can be made by changing the typeclasses applied to `R` and `M`,\nwithout changing the axioms in `Module`, mathlib calls everything a `Module`.\n\nIn older versions of mathlib3, we had separate `semimodule` and `vector_space` abbreviations.\nThis caused inference issues in some cases, while not providing any real advantages, so we decided\nto use a canonical `Module` typeclass throughout.\n\n## Tags\n\nsemimodule, module, vector space\n-/\n\n\nopen Function\n\nuniverse u v\n\nvariable {\u03b1 R k S M M\u2082 M\u2083 \u03b9 : Type _}\n\n/-- A module is a generalization of vector spaces to a scalar semiring.\n  It consists of a scalar semiring `R` and an additive monoid of \"vectors\" `M`,\n  connected by a \"scalar multiplication\" operation `r \u2022 x : M`\n  (where `r : R` and `x : M`) with some natural associativity and\n  distributivity axioms similar to those on a ring. -/\n@[ext]\nclass Module (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] extends\n  DistribMulAction R M where\n  /-- Scalar multiplication distributes over addition from the right. -/\n  protected add_smul : \u2200 (r s : R) (x : M), (r + s) \u2022 x = r \u2022 x + s \u2022 x\n  /-- Scalar multiplication by zero gives zero. -/\n  protected zero_smul : \u2200 x : M, (0 : R) \u2022 x = 0\n#align module Module\n#align module.ext Module.ext\n#align module.ext_iff Module.ext_iff\n\nsection AddCommMonoid\n\nvariable [Semiring R] [AddCommMonoid M] [Module R M] (r s : R) (x y : M)\n\n-- see Note [lower instance priority]\n/-- A module over a semiring automatically inherits a `MulActionWithZero` structure. -/\ninstance (priority := 100) Module.toMulActionWithZero : MulActionWithZero R M :=\n  { (inferInstance : MulAction R M) with\n    smul_zero := smul_zero\n    zero_smul := Module.zero_smul }\n#align module.to_mul_action_with_zero Module.toMulActionWithZero\n\ninstance AddCommMonoid.natModule : Module \u2115 M where\n  one_smul := one_nsmul\n  mul_smul m n a := mul_nsmul' a m n\n  smul_add n a b := nsmul_add a b n\n  smul_zero := nsmul_zero\n  zero_smul := zero_nsmul\n  add_smul r s x := add_nsmul x r s\n#align add_comm_monoid.nat_module AddCommMonoid.natModule\n\ntheorem AddMonoid.End.nat_cast_def (n : \u2115) :\n    (\u2191n : AddMonoid.End M) = DistribMulAction.toAddMonoidEnd \u2115 M n :=\n  rfl\n#align add_monoid.End.nat_cast_def AddMonoid.End.nat_cast_def\n\ntheorem add_smul : (r + s) \u2022 x = r \u2022 x + s \u2022 x :=\n  Module.add_smul r s x\n#align add_smul add_smul\n\ntheorem Convex.combo_self {a b : R} (h : a + b = 1) (x : M) : a \u2022 x + b \u2022 x = x := by\n  rw [\u2190 add_smul, h, one_smul]\n#align convex.combo_self Convex.combo_self\n\nvariable (R)\n\n-- Porting note: this is the letter of the mathlib3 version, but not really the spirit\ntheorem two_smul : (2 : R) \u2022 x = x + x := by rw [\u2190 one_add_one_eq_two, add_smul, one_smul]\n#align two_smul two_smul\n\nset_option linter.deprecated false in\n@[deprecated] theorem two_smul' : (2 : R) \u2022 x = bit0 x :=\n  two_smul R x\n#align two_smul' two_smul'\n\n@[simp]\ntheorem inv_of_two_smul_add_inv_of_two_smul [Invertible (2 : R)] (x : M) :\n    (\u215f 2 : R) \u2022 x + (\u215f 2 : R) \u2022 x = x :=\n  Convex.combo_self invOf_two_add_invOf_two _\n#align inv_of_two_smul_add_inv_of_two_smul inv_of_two_smul_add_inv_of_two_smul\n\n/-- Pullback a `Module` structure along an injective additive monoid homomorphism.\nSee note [reducible non-instances]. -/\n@[reducible]\nprotected def Function.Injective.module [AddCommMonoid M\u2082] [SMul R M\u2082] (f : M\u2082 \u2192+ M)\n    (hf : Injective f) (smul : \u2200 (c : R) (x), f (c \u2022 x) = c \u2022 f x) : Module R M\u2082 :=\n  { hf.distribMulAction f smul with\n    smul := (\u00b7 \u2022 \u00b7)\n    add_smul := fun c\u2081 c\u2082 x => hf <| by simp only [smul, f.map_add, add_smul]\n    zero_smul := fun x => hf <| by simp only [smul, zero_smul, f.map_zero] }\n#align function.injective.module Function.Injective.module\n\n/-- Pushforward a `Module` structure along a surjective additive monoid homomorphism. -/\nprotected def Function.Surjective.module [AddCommMonoid M\u2082] [SMul R M\u2082] (f : M \u2192+ M\u2082)\n    (hf : Surjective f) (smul : \u2200 (c : R) (x), f (c \u2022 x) = c \u2022 f x) : Module R M\u2082 :=\n  { hf.distribMulAction f smul with\n    smul := (\u00b7 \u2022 \u00b7)\n    add_smul := fun c\u2081 c\u2082 x => by\n      rcases hf x with \u27e8x, rfl\u27e9\n      simp only [add_smul, \u2190 smul, \u2190 f.map_add]\n    zero_smul := fun x => by\n      rcases hf x with \u27e8x, rfl\u27e9\n      rw [\u2190 f.map_zero, \u2190 smul, zero_smul] }\n#align function.surjective.module Function.Surjective.module\n\n/-- Push forward the action of `R` on `M` along a compatible surjective map `f : R \u2192+* S`.\n\nSee also `Function.Surjective.mulActionLeft` and `Function.Surjective.distribMulActionLeft`.\n-/\n@[reducible]\ndef Function.Surjective.moduleLeft {R S M : Type _} [Semiring R] [AddCommMonoid M] [Module R M]\n    [Semiring S] [SMul S M] (f : R \u2192+* S) (hf : Function.Surjective f)\n    (hsmul : \u2200 (c) (x : M), f c \u2022 x = c \u2022 x) : Module S M :=\n  { hf.distribMulActionLeft f.toMonoidHom hsmul with\n    smul := (\u00b7 \u2022 \u00b7)\n    zero_smul := fun x => by rw [\u2190 f.map_zero, hsmul, zero_smul]\n    add_smul := hf.forall\u2082.mpr fun a b x => by simp only [\u2190 f.map_add, hsmul, add_smul] }\n#align function.surjective.module_left Function.Surjective.moduleLeft\n\nvariable {R} (M)\n\n/-- Compose a `Module` with a `RingHom`, with action `f s \u2022 m`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef Module.compHom [Semiring S] (f : S \u2192+* R) : Module S M :=\n  { MulActionWithZero.compHom M f.toMonoidWithZeroHom, DistribMulAction.compHom M (f : S \u2192* R) with\n    smul := SMul.comp.smul f\n    -- Porting note: the `show f (r + s) \u2022 x = f r \u2022 x + f s \u2022 x ` wasn't needed in mathlib3.\n    -- Somehow, now that `SMul` is heterogeneous, it can't unfold earlier fields of a definition for\n    -- use in later fields.  See\n    -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Heterogeneous.20scalar.20multiplication\n    add_smul := fun r s x => show f (r + s) \u2022 x = f r \u2022 x + f s \u2022 x by simp [add_smul] }\n#align module.comp_hom Module.compHom\n\nvariable (R)\n\n/-- `(\u2022)` as an `AddMonoidHom`.\n\nThis is a stronger version of `DistribMulAction.toAddMonoidEnd` -/\n@[simps! apply_apply]\ndef Module.toAddMonoidEnd : R \u2192+* AddMonoid.End M :=\n  { DistribMulAction.toAddMonoidEnd R M with\n    -- Porting note: the two `show`s weren't needed in mathlib3.\n    -- Somehow, now that `SMul` is heterogeneous, it can't unfold earlier fields of a definition for\n    -- use in later fields.  See\n    -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Heterogeneous.20scalar.20multiplication\n    map_zero' := AddMonoidHom.ext fun r => show (0:R) \u2022 r = 0 by simp\n    map_add' := fun x y =>\n      AddMonoidHom.ext fun r => show (x + y) \u2022 r = x \u2022 r + y \u2022 r by simp [add_smul] }\n#align module.to_add_monoid_End Module.toAddMonoidEnd\n#align module.to_add_monoid_End_apply_apply Module.toAddMonoidEnd_apply_apply\n\n/-- A convenience alias for `Module.toAddMonoidEnd` as an `AddMonoidHom`, usually to allow the\nuse of `AddMonoidHom.flip`. -/\ndef smulAddHom : R \u2192+ M \u2192+ M :=\n  (Module.toAddMonoidEnd R M).toAddMonoidHom\n#align smul_add_hom smulAddHom\n\nvariable {R M}\n\n@[simp]\ntheorem smulAddHom_apply (r : R) (x : M) : smulAddHom R M r x = r \u2022 x :=\n  rfl\n#align smul_add_hom_apply smulAddHom_apply\n\ntheorem Module.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by\n  rw [\u2190 one_smul R x, \u2190 zero_eq_one, zero_smul]\n#align module.eq_zero_of_zero_eq_one Module.eq_zero_of_zero_eq_one\n\n@[simp]\ntheorem smul_add_one_sub_smul {R : Type _} [Ring R] [Module R M] {r : R} {m : M} :\n    r \u2022 m + (1 - r) \u2022 m = m := by rw [\u2190 add_smul, add_sub_cancel'_right, one_smul]\n#align smul_add_one_sub_smul smul_add_one_sub_smul\n\nend AddCommMonoid\n\nvariable (R)\n\n/-- An `AddCommMonoid` that is a `Module` over a `Ring` carries a natural `AddCommGroup`\nstructure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef Module.addCommMonoidToAddCommGroup [Ring R] [AddCommMonoid M] [Module R M] : AddCommGroup M :=\n  { (inferInstance : AddCommMonoid M) with\n    neg := fun a => (-1 : R) \u2022 a\n    add_left_neg := fun a =>\n      show (-1 : R) \u2022 a + a = 0 by\n        nth_rw 2 [\u2190 one_smul R a]\n        rw [\u2190 add_smul, add_left_neg, zero_smul] }\n#align module.add_comm_monoid_to_add_comm_group Module.addCommMonoidToAddCommGroup\n\nvariable {R}\n\nsection AddCommGroup\n\nvariable (R M) [Semiring R] [AddCommGroup M]\n\ninstance AddCommGroup.intModule : Module \u2124 M where\n  one_smul := one_zsmul\n  mul_smul m n a := mul_zsmul a m n\n  smul_add n a b := zsmul_add a b n\n  smul_zero := zsmul_zero\n  zero_smul := zero_zsmul\n  add_smul r s x := add_zsmul x r s\n#align add_comm_group.int_module AddCommGroup.intModule\n\ntheorem AddMonoid.End.int_cast_def (z : \u2124) :\n    (\u2191z : AddMonoid.End M) = DistribMulAction.toAddMonoidEnd \u2124 M z :=\n  rfl\n#align add_monoid.End.int_cast_def AddMonoid.End.int_cast_def\n\n/-- A structure containing most informations as in a module, except the fields `zero_smul`\nand `smul_zero`. As these fields can be deduced from the other ones when `M` is an `AddCommGroup`,\nthis provides a way to construct a module structure by checking less properties, in\n`Module.ofCore`. -/\n-- Porting note: removed @[nolint has_nonempty_instance]\nstructure Module.Core extends SMul R M where\n  /-- Scalar multiplication distributes over addition from the left. -/\n  smul_add : \u2200 (r : R) (x y : M), r \u2022 (x + y) = r \u2022 x + r \u2022 y\n  /-- Scalar multiplication distributes over addition from the right. -/\n  add_smul : \u2200 (r s : R) (x : M), (r + s) \u2022 x = r \u2022 x + s \u2022 x\n  /-- Scalar multiplication distributes over multiplication from the right. -/\n  mul_smul : \u2200 (r s : R) (x : M), (r * s) \u2022 x = r \u2022 s \u2022 x\n  /-- Scalar multiplication by one is the identity. -/\n  one_smul : \u2200 x : M, (1 : R) \u2022 x = x\n#align module.core Module.Core\n\nvariable {R M}\n\n/-- Define `Module` without proving `zero_smul` and `smul_zero` by using an auxiliary\nstructure `Module.Core`, when the underlying space is an `AddCommGroup`. -/\ndef Module.ofCore (H : Module.Core R M) : Module R M :=\n  letI := H.toSMul\n  { H with\n    zero_smul := fun x =>\n      (AddMonoidHom.mk' (fun r : R => r \u2022 x) fun r s => H.add_smul r s x).map_zero\n    smul_zero := fun r => (AddMonoidHom.mk' ((\u00b7 \u2022 \u00b7) r) (H.smul_add r)).map_zero }\n#align module.of_core Module.ofCore\n\ntheorem Convex.combo_eq_smul_sub_add [Module R M] {x y : M} {a b : R} (h : a + b = 1) :\n    a \u2022 x + b \u2022 y = b \u2022 (y - x) + x :=\n  calc\n    a \u2022 x + b \u2022 y = b \u2022 y - b \u2022 x + (a \u2022 x + b \u2022 x) := by abel\n    _ = b \u2022 (y - x) + x := by rw [smul_sub, Convex.combo_self h]\n\n#align convex.combo_eq_smul_sub_add Convex.combo_eq_smul_sub_add\n\nend AddCommGroup\n\n-- We'll later use this to show `Module \u2115 M` and `Module \u2124 M` are subsingletons.\n/-- A variant of `Module.ext` that's convenient for term-mode. -/\ntheorem Module.ext' {R : Type _} [Semiring R] {M : Type _} [AddCommMonoid M] (P Q : Module R M)\n    (w : \u2200 (r : R) (m : M), (haveI := P; r \u2022 m) = (haveI := Q; r \u2022 m)) :\n    P = Q := by\n  ext\n  exact w _ _\n#align module.ext' Module.ext'\n\nsection Module\n\nvariable [Ring R] [AddCommGroup M] [Module R M] (r s : R) (x y : M)\n\n@[simp]\ntheorem neg_smul : -r \u2022 x = -(r \u2022 x) :=\n  eq_neg_of_add_eq_zero_left <| by rw [\u2190 add_smul, add_left_neg, zero_smul]\n#align neg_smul neg_smul\n\n-- Porting note: simp can prove this\n--@[simp]\ntheorem neg_smul_neg : -r \u2022 -x = r \u2022 x := by rw [neg_smul, smul_neg, neg_neg]\n#align neg_smul_neg neg_smul_neg\n\n@[simp]\ntheorem Units.neg_smul (u : R\u02e3) (x : M) : -u \u2022 x = -(u \u2022 x) := by\n  rw [Units.smul_def, Units.val_neg, _root_.neg_smul, Units.smul_def]\n#align units.neg_smul Units.neg_smul\n\nvariable (R)\n\ntheorem neg_one_smul (x : M) : (-1 : R) \u2022 x = -x := by simp\n#align neg_one_smul neg_one_smul\n\nvariable {R}\n\ntheorem sub_smul (r s : R) (y : M) : (r - s) \u2022 y = r \u2022 y - s \u2022 y := by\n  simp [add_smul, sub_eq_add_neg]\n#align sub_smul sub_smul\n\nend Module\n\n/-- A module over a `Subsingleton` semiring is a `Subsingleton`. We cannot register this\nas an instance because Lean has no way to guess `R`. -/\nprotected theorem Module.subsingleton (R M : Type _) [Semiring R] [Subsingleton R] [AddCommMonoid M]\n    [Module R M] : Subsingleton M :=\n  MulActionWithZero.subsingleton R M\n#align module.subsingleton Module.subsingleton\n\n/-- A semiring is `Nontrivial` provided that there exists a nontrivial module over this semiring. -/\nprotected theorem Module.nontrivial (R M : Type _) [Semiring R] [Nontrivial M] [AddCommMonoid M]\n    [Module R M] : Nontrivial R :=\n  MulActionWithZero.nontrivial R M\n#align module.nontrivial Module.nontrivial\n\n-- see Note [lower instance priority]\ninstance (priority := 910) Semiring.toModule [Semiring R] : Module R R where\n  smul_add := mul_add\n  add_smul := add_mul\n  zero_smul := zero_mul\n  smul_zero := mul_zero\n#align semiring.to_module Semiring.toModule\n\n-- see Note [lower instance priority]\n/-- Like `Semiring.toModule`, but multiplies on the right. -/\ninstance (priority := 910) Semiring.toOppositeModule [Semiring R] : Module R\u1d50\u1d52\u1d56 R :=\n  { MonoidWithZero.toOppositeMulActionWithZero R with\n    smul_add := fun _ _ _ => add_mul _ _ _\n    add_smul := fun _ _ _ => mul_add _ _ _ }\n#align semiring.to_opposite_module Semiring.toOppositeModule\n\n/-- A ring homomorphism `f : R \u2192+* M` defines a module structure by `r \u2022 x = f r * x`. -/\ndef RingHom.toModule [Semiring R] [Semiring S] (f : R \u2192+* S) : Module R S :=\n  Module.compHom S f\n#align ring_hom.to_module RingHom.toModule\n\n/-- The tautological action by `R \u2192+* R` on `R`.\n\nThis generalizes `Function.End.applyMulAction`. -/\ninstance RingHom.applyDistribMulAction [Semiring R] : DistribMulAction (R \u2192+* R) R where\n  smul := (\u00b7 <| \u00b7)\n  smul_zero := RingHom.map_zero\n  smul_add := RingHom.map_add\n  one_smul _ := rfl\n  mul_smul _ _ _ := rfl\n#align ring_hom.apply_distrib_mul_action RingHom.applyDistribMulAction\n\n@[simp]\nprotected theorem RingHom.smul_def [Semiring R] (f : R \u2192+* R) (a : R) : f \u2022 a = f a :=\n  rfl\n#align ring_hom.smul_def RingHom.smul_def\n\n/-- `RingHom.applyDistribMulAction` is faithful. -/\ninstance RingHom.applyFaithfulSMul [Semiring R] : FaithfulSMul (R \u2192+* R) R :=\n  \u27e8fun {_ _} h => RingHom.ext h\u27e9\n#align ring_hom.apply_has_faithful_smul RingHom.applyFaithfulSMul\n\nsection AddCommMonoid\n\nvariable [Semiring R] [AddCommMonoid M] [Module R M]\n\nsection\n\nvariable (R)\n\n/-- `nsmul` is equal to any other module structure via a cast. -/\ntheorem nsmul_eq_smul_cast (n : \u2115) (b : M) : n \u2022 b = (n : R) \u2022 b := by\n  induction' n with n ih\n  \u00b7 rw [Nat.zero_eq, Nat.cast_zero, zero_smul, zero_smul]\n  \u00b7 rw [Nat.succ_eq_add_one, Nat.cast_succ, add_smul, add_smul, one_smul, ih, one_smul]\n#align nsmul_eq_smul_cast nsmul_eq_smul_cast\n\nend\n\n/-- Convert back any exotic `\u2115`-smul to the canonical instance. This should not be needed since in\nmathlib all `AddCommMonoid`s should normally have exactly one `\u2115`-module structure by design.\n-/\ntheorem nat_smul_eq_nsmul (h : Module \u2115 M) (n : \u2115) (x : M) :\n    @SMul.smul \u2115 M h.toSMul n x = n \u2022 x := by rw [nsmul_eq_smul_cast \u2115 n x, Nat.cast_id]; rfl\n#align nat_smul_eq_nsmul nat_smul_eq_nsmul\n\n/-- All `\u2115`-module structures are equal. Not an instance since in mathlib all `AddCommMonoid`\nshould normally have exactly one `\u2115`-module structure by design. -/\ndef AddCommMonoid.natModule.unique : Unique (Module \u2115 M) where\n  default := by infer_instance\n  uniq P := (Module.ext' P _) fun n => by convert nat_smul_eq_nsmul P n\n#align add_comm_monoid.nat_module.unique AddCommMonoid.natModule.unique\n\ninstance AddCommMonoid.nat_isScalarTower : IsScalarTower \u2115 R M where\n  smul_assoc n x y :=\n    Nat.recOn n (by simp only [Nat.zero_eq, zero_smul])\n    fun n ih => by simp only [Nat.succ_eq_add_one, add_smul, one_smul, ih]\n#align add_comm_monoid.nat_is_scalar_tower AddCommMonoid.nat_isScalarTower\n\nend AddCommMonoid\n\nsection AddCommGroup\n\nvariable [Semiring S] [Ring R] [AddCommGroup M] [Module S M] [Module R M]\n\nsection\n\nvariable (R)\n\n/-- `zsmul` is equal to any other module structure via a cast. -/\ntheorem zsmul_eq_smul_cast (n : \u2124) (b : M) : n \u2022 b = (n : R) \u2022 b :=\n  have : (smulAddHom \u2124 M).flip b = ((smulAddHom R M).flip b).comp (Int.castAddHom R) := by\n    apply AddMonoidHom.ext_int\n    simp\n  FunLike.congr_fun this n\n#align zsmul_eq_smul_cast zsmul_eq_smul_cast\n\nend\n\n/-- Convert back any exotic `\u2124`-smul to the canonical instance. This should not be needed since in\nmathlib all `AddCommGroup`s should normally have exactly one `\u2124`-module structure by design. -/\ntheorem int_smul_eq_zsmul (h : Module \u2124 M) (n : \u2124) (x : M) :\n    @SMul.smul \u2124 M h.toSMul n x = n \u2022 x := by rw [zsmul_eq_smul_cast \u2124 n x, Int.cast_id]; rfl\n#align int_smul_eq_zsmul int_smul_eq_zsmul\n\n/-- All `\u2124`-module structures are equal. Not an instance since in mathlib all `AddCommGroup`\nshould normally have exactly one `\u2124`-module structure by design. -/\ndef AddCommGroup.intModule.unique : Unique (Module \u2124 M) where\n  default := by infer_instance\n  uniq P := (Module.ext' P _) fun n => by convert int_smul_eq_zsmul P n\n#align add_comm_group.int_module.unique AddCommGroup.intModule.unique\n\nend AddCommGroup\n\ntheorem map_int_cast_smul [AddCommGroup M] [AddCommGroup M\u2082] {F : Type _} [AddMonoidHomClass F M M\u2082]\n    (f : F) (R S : Type _) [Ring R] [Ring S] [Module R M] [Module S M\u2082] (x : \u2124) (a : M) :\n    f ((x : R) \u2022 a) = (x : S) \u2022 f a := by simp only [\u2190 zsmul_eq_smul_cast, map_zsmul]\n#align map_int_cast_smul map_int_cast_smul\n\ntheorem map_nat_cast_smul [AddCommMonoid M] [AddCommMonoid M\u2082] {F : Type _}\n    [AddMonoidHomClass F M M\u2082] (f : F) (R S : Type _) [Semiring R] [Semiring S] [Module R M]\n    [Module S M\u2082] (x : \u2115) (a : M) : f ((x : R) \u2022 a) = (x : S) \u2022 f a := by\n  simp only [\u2190 nsmul_eq_smul_cast, AddMonoidHom.map_nsmul, map_nsmul]\n#align map_nat_cast_smul map_nat_cast_smul\n\ntheorem map_inv_nat_cast_smul [AddCommMonoid M] [AddCommMonoid M\u2082] {F : Type _}\n    [AddMonoidHomClass F M M\u2082] (f : F) (R S : Type _)\n    [DivisionSemiring R] [DivisionSemiring S] [Module R M]\n    [Module S M\u2082] (n : \u2115) (x : M) : f ((n\u207b\u00b9 : R) \u2022 x) = (n\u207b\u00b9 : S) \u2022 f x := by\n  by_cases hR : (n : R) = 0 <;> by_cases hS : (n : S) = 0\n  \u00b7 simp [hR, hS, map_zero f]\n  \u00b7 suffices \u2200 y, f y = 0 by rw [this, this, smul_zero]\n    clear x\n    intro x\n    rw [\u2190 inv_smul_smul\u2080 hS (f x), \u2190 map_nat_cast_smul f R S]\n    simp [hR, map_zero f]\n  \u00b7 suffices \u2200 y, f y = 0 by simp [this]\n    clear x\n    intro x\n    rw [\u2190 smul_inv_smul\u2080 hR x, map_nat_cast_smul f R S, hS, zero_smul]\n  \u00b7 rw [\u2190 inv_smul_smul\u2080 hS (f _), \u2190 map_nat_cast_smul f R S, smul_inv_smul\u2080 hR]\n#align map_inv_nat_cast_smul map_inv_nat_cast_smul\n\ntheorem map_inv_int_cast_smul [AddCommGroup M] [AddCommGroup M\u2082] {F : Type _}\n    [AddMonoidHomClass F M M\u2082] (f : F) (R S : Type _) [DivisionRing R] [DivisionRing S] [Module R M]\n    [Module S M\u2082] (z : \u2124) (x : M) : f ((z\u207b\u00b9 : R) \u2022 x) = (z\u207b\u00b9 : S) \u2022 f x := by\n  obtain \u27e8n, rfl | rfl\u27e9 := z.eq_nat_or_neg\n  \u00b7 rw [Int.cast_Nat_cast, Int.cast_Nat_cast, map_inv_nat_cast_smul _ R S]\n  \u00b7 simp_rw [Int.cast_neg, Int.cast_Nat_cast, inv_neg, neg_smul, map_neg,\n      map_inv_nat_cast_smul _ R S]\n#align map_inv_int_cast_smul map_inv_int_cast_smul\n\ntheorem map_rat_cast_smul [AddCommGroup M] [AddCommGroup M\u2082] {F : Type _} [AddMonoidHomClass F M M\u2082]\n    (f : F) (R S : Type _) [DivisionRing R] [DivisionRing S] [Module R M] [Module S M\u2082] (c : \u211a)\n    (x : M) : f ((c : R) \u2022 x) = (c : S) \u2022 f x := by\n  rw [Rat.cast_def, Rat.cast_def, div_eq_mul_inv, div_eq_mul_inv, mul_smul, mul_smul,\n    map_int_cast_smul f R S, map_inv_nat_cast_smul f R S]\n#align map_rat_cast_smul map_rat_cast_smul\n\ntheorem map_rat_smul [AddCommGroup M] [AddCommGroup M\u2082] [Module \u211a M] [Module \u211a M\u2082] {F : Type _}\n    [AddMonoidHomClass F M M\u2082] (f : F) (c : \u211a) (x : M) : f (c \u2022 x) = c \u2022 f x :=\n  map_rat_cast_smul f \u211a \u211a c x\n#align map_rat_smul map_rat_smul\n\n/-- There can be at most one `Module \u211a E` structure on an additive commutative group. -/\ninstance subsingleton_rat_module (E : Type _) [AddCommGroup E] : Subsingleton (Module \u211a E) :=\n  \u27e8fun P Q => (Module.ext' P Q) fun r x => @map_rat_smul _ _ _ _ P Q _ _ (AddMonoidHom.id E) r x\u27e9\n#align subsingleton_rat_module subsingleton_rat_module\n\n/-- If `E` is a vector space over two division semirings `R` and `S`, then scalar multiplications\nagree on inverses of natural numbers in `R` and `S`. -/\ntheorem inv_nat_cast_smul_eq {E : Type _} (R S : Type _) [AddCommMonoid E] [DivisionSemiring R]\n    [DivisionSemiring S] [Module R E] [Module S E] (n : \u2115) (x : E) :\n    (n\u207b\u00b9 : R) \u2022 x = (n\u207b\u00b9 : S) \u2022 x :=\n  map_inv_nat_cast_smul (AddMonoidHom.id E) R S n x\n#align inv_nat_cast_smul_eq inv_nat_cast_smul_eq\n\n/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications\nagree on inverses of integer numbers in `R` and `S`. -/\ntheorem inv_int_cast_smul_eq {E : Type _} (R S : Type _) [AddCommGroup E] [DivisionRing R]\n    [DivisionRing S] [Module R E] [Module S E] (n : \u2124) (x : E) : (n\u207b\u00b9 : R) \u2022 x = (n\u207b\u00b9 : S) \u2022 x :=\n  map_inv_int_cast_smul (AddMonoidHom.id E) R S n x\n#align inv_int_cast_smul_eq inv_int_cast_smul_eq\n\n/-- If `E` is a vector space over a division semiring `R` and has a monoid action by `\u03b1`, then that\naction commutes by scalar multiplication of inverses of natural numbers in `R`. -/\ntheorem inv_nat_cast_smul_comm {\u03b1 E : Type _} (R : Type _) [AddCommMonoid E] [DivisionSemiring R]\n    [Monoid \u03b1] [Module R E] [DistribMulAction \u03b1 E] (n : \u2115) (s : \u03b1) (x : E) :\n    (n\u207b\u00b9 : R) \u2022 s \u2022 x = s \u2022 (n\u207b\u00b9 : R) \u2022 x :=\n  (map_inv_nat_cast_smul (DistribMulAction.toAddMonoidHom E s) R R n x).symm\n#align inv_nat_cast_smul_comm inv_nat_cast_smul_comm\n\n/-- If `E` is a vector space over a division ring `R` and has a monoid action by `\u03b1`, then that\naction commutes by scalar multiplication of inverses of integers in `R` -/\ntheorem inv_int_cast_smul_comm {\u03b1 E : Type _} (R : Type _) [AddCommGroup E] [DivisionRing R]\n    [Monoid \u03b1] [Module R E] [DistribMulAction \u03b1 E] (n : \u2124) (s : \u03b1) (x : E) :\n    (n\u207b\u00b9 : R) \u2022 s \u2022 x = s \u2022 (n\u207b\u00b9 : R) \u2022 x :=\n  (map_inv_int_cast_smul (DistribMulAction.toAddMonoidHom E s) R R n x).symm\n#align inv_int_cast_smul_comm inv_int_cast_smul_comm\n\n/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications\nagree on rational numbers in `R` and `S`. -/\ntheorem rat_cast_smul_eq {E : Type _} (R S : Type _) [AddCommGroup E] [DivisionRing R]\n    [DivisionRing S] [Module R E] [Module S E] (r : \u211a) (x : E) : (r : R) \u2022 x = (r : S) \u2022 x :=\n  map_rat_cast_smul (AddMonoidHom.id E) R S r x\n#align rat_cast_smul_eq rat_cast_smul_eq\n\ninstance AddCommGroup.intIsScalarTower {R : Type u} {M : Type v} [Ring R] [AddCommGroup M]\n    [Module R M] : IsScalarTower \u2124 R M where\n  smul_assoc n x y := ((smulAddHom R M).flip y).map_zsmul x n\n#align add_comm_group.int_is_scalar_tower AddCommGroup.intIsScalarTower\n\ninstance IsScalarTower.rat {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M]\n    [Module \u211a R] [Module \u211a M] : IsScalarTower \u211a R M where\n  smul_assoc r x y := map_rat_smul ((smulAddHom R M).flip y) r x\n#align is_scalar_tower.rat IsScalarTower.rat\n\ninstance SMulCommClass.rat {R : Type u} {M : Type v} [Semiring R] [AddCommGroup M] [Module R M]\n    [Module \u211a M] : SMulCommClass \u211a R M where\n  smul_comm r x y := (map_rat_smul (smulAddHom R M x) r y).symm\n#align smul_comm_class.rat SMulCommClass.rat\n\ninstance SMulCommClass.rat' {R : Type u} {M : Type v} [Semiring R] [AddCommGroup M] [Module R M]\n    [Module \u211a M] : SMulCommClass R \u211a M :=\n  SMulCommClass.symm _ _ _\n#align smul_comm_class.rat' SMulCommClass.rat'\n\nsection NoZeroSMulDivisors\n\n/-! ### `NoZeroSMulDivisors`\n\nThis section defines the `NoZeroSMulDivisors` class, and includes some tests\nfor the vanishing of elements (especially in modules over division rings).\n-/\n\n\n/-- `NoZeroSMulDivisors R M` states that a scalar multiple is `0` only if either argument is `0`.\nThis a version of saying that `M` is torsion free, without assuming `R` is zero-divisor free.\n\nThe main application of `NoZeroSMulDivisors R M`, when `M` is a module,\nis the result `smul_eq_zero`: a scalar multiple is `0` iff either argument is `0`.\n\nIt is a generalization of the `NoZeroDivisors` class to heterogeneous multiplication.\n-/\nclass NoZeroSMulDivisors (R M : Type _) [Zero R] [Zero M] [SMul R M] : Prop where\n  /-- If scalar multiplication yields zero, either the scalar or the vector was zero. -/\n  eq_zero_or_eq_zero_of_smul_eq_zero : \u2200 {c : R} {x : M}, c \u2022 x = 0 \u2192 c = 0 \u2228 x = 0\n#align no_zero_smul_divisors NoZeroSMulDivisors\n\nexport NoZeroSMulDivisors (eq_zero_or_eq_zero_of_smul_eq_zero)\n\n/-- Pullback a `NoZeroSMulDivisors` instance along an injective function. -/\ntheorem Function.Injective.noZeroSMulDivisors {R M N : Type _} [Zero R] [Zero M] [Zero N]\n    [SMul R M] [SMul R N] [NoZeroSMulDivisors R N] (f : M \u2192 N) (hf : Function.Injective f)\n    (h0 : f 0 = 0) (hs : \u2200 (c : R) (x : M), f (c \u2022 x) = c \u2022 f x) : NoZeroSMulDivisors R M :=\n  \u27e8fun {_ _} h =>\n    Or.imp_right (@hf _ _) <| h0.symm \u25b8 eq_zero_or_eq_zero_of_smul_eq_zero (by rw [\u2190 hs, h, h0])\u27e9\n#align function.injective.no_zero_smul_divisors Function.Injective.noZeroSMulDivisors\n\n-- See note [lower instance priority]\ninstance (priority := 100) NoZeroDivisors.toNoZeroSMulDivisors [Zero R] [Mul R]\n    [NoZeroDivisors R] : NoZeroSMulDivisors R R :=\n  \u27e8fun {_ _} => eq_zero_or_eq_zero_of_mul_eq_zero\u27e9\n#align no_zero_divisors.to_no_zero_smul_divisors NoZeroDivisors.toNoZeroSMulDivisors\n\ntheorem smul_ne_zero [Zero R] [Zero M] [SMul R M] [NoZeroSMulDivisors R M] {c : R} {x : M}\n    (hc : c \u2260 0) (hx : x \u2260 0) : c \u2022 x \u2260 0 := fun h =>\n  (eq_zero_or_eq_zero_of_smul_eq_zero h).elim hc hx\n#align smul_ne_zero smul_ne_zero\n\nsection SMulWithZero\n\nvariable [Zero R] [Zero M] [SMulWithZero R M] [NoZeroSMulDivisors R M] {c : R} {x : M}\n\n@[simp]\ntheorem smul_eq_zero : c \u2022 x = 0 \u2194 c = 0 \u2228 x = 0 :=\n  \u27e8eq_zero_or_eq_zero_of_smul_eq_zero, fun h =>\n    h.elim (fun h => h.symm \u25b8 zero_smul R x) fun h => h.symm \u25b8 smul_zero c\u27e9\n#align smul_eq_zero smul_eq_zero\n\ntheorem smul_ne_zero_iff : c \u2022 x \u2260 0 \u2194 c \u2260 0 \u2227 x \u2260 0 := by rw [Ne.def, smul_eq_zero, not_or]\n#align smul_ne_zero_iff smul_ne_zero_iff\n\nend SMulWithZero\n\nsection Module\n\nvariable [Semiring R] [AddCommMonoid M] [Module R M]\n\nsection Nat\n\nvariable [NoZeroSMulDivisors R M] [CharZero R]\nvariable (R) (M)\n\n--include R\n\ntheorem Nat.noZeroSMulDivisors : NoZeroSMulDivisors \u2115 M :=\n  \u27e8by\n    intro c x\n    rw [nsmul_eq_smul_cast R, smul_eq_zero]\n    simp\u27e9\n#align nat.no_zero_smul_divisors Nat.noZeroSMulDivisors\n\n-- Porting note: left-hand side never simplifies when using simp on itself\n--@[simp]\ntheorem two_nsmul_eq_zero {v : M} : 2 \u2022 v = 0 \u2194 v = 0 := by\n  haveI := Nat.noZeroSMulDivisors R M\n  simp [smul_eq_zero]\n#align two_nsmul_eq_zero two_nsmul_eq_zero\n\nend Nat\n\nvariable (R M)\n\n/-- If `M` is an `R`-module with one and `M` has characteristic zero, then `R` has characteristic\nzero as well. Usually `M` is an `R`-algebra. -/\ntheorem CharZero.of_module (M) [AddCommMonoidWithOne M] [CharZero M] [Module R M] : CharZero R := by\n  refine' \u27e8fun m n h => @Nat.cast_injective M _ _ _ _ _\u27e9\n  rw [\u2190 nsmul_one, \u2190 nsmul_one, nsmul_eq_smul_cast R m (1 : M), nsmul_eq_smul_cast R n (1 : M), h]\n#align char_zero.of_module CharZero.of_module\n\nend Module\n\nsection AddCommGroup\n\n-- `R` can still be a semiring here\nvariable [Semiring R] [AddCommGroup M] [Module R M]\n\nsection SMulInjective\n\nvariable (M)\n\ntheorem smul_right_injective [NoZeroSMulDivisors R M] {c : R} (hc : c \u2260 0) :\n    Function.Injective ((\u00b7 \u2022 \u00b7) c : M \u2192 M) :=\n  (injective_iff_map_eq_zero (smulAddHom R M c)).2 fun _ ha => (smul_eq_zero.mp ha).resolve_left hc\n#align smul_right_injective smul_right_injective\n\nvariable {M}\n\ntheorem smul_right_inj [NoZeroSMulDivisors R M] {c : R} (hc : c \u2260 0) {x y : M} :\n    c \u2022 x = c \u2022 y \u2194 x = y :=\n  (smul_right_injective M hc).eq_iff\n#align smul_right_inj smul_right_inj\n\nend SMulInjective\n\nsection Nat\n\nvariable [NoZeroSMulDivisors R M] [CharZero R]\nvariable (R M)\n--include R\n\ntheorem self_eq_neg {v : M} : v = -v \u2194 v = 0 := by\n  rw [\u2190 two_nsmul_eq_zero R M, two_smul, add_eq_zero_iff_eq_neg]\n#align self_eq_neg self_eq_neg\n\ntheorem neg_eq_self {v : M} : -v = v \u2194 v = 0 := by rw [eq_comm, self_eq_neg R M]\n#align neg_eq_self neg_eq_self\n\ntheorem self_ne_neg {v : M} : v \u2260 -v \u2194 v \u2260 0 :=\n  (self_eq_neg R M).not\n#align self_ne_neg self_ne_neg\n\ntheorem neg_ne_self {v : M} : -v \u2260 v \u2194 v \u2260 0 :=\n  (neg_eq_self R M).not\n#align neg_ne_self neg_ne_self\n\nend Nat\n\nend AddCommGroup\n\nsection Module\n\nvariable [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]\n\nsection SMulInjective\n\nvariable (R)\n\ntheorem smul_left_injective {x : M} (hx : x \u2260 0) : Function.Injective fun c : R => c \u2022 x :=\n  fun c d h =>\n  sub_eq_zero.mp\n    ((smul_eq_zero.mp\n          (calc\n            (c - d) \u2022 x = c \u2022 x - d \u2022 x := sub_smul c d x\n            _ = 0 := sub_eq_zero.mpr h\n            )).resolve_right\n      hx)\n#align smul_left_injective smul_left_injective\n\nend SMulInjective\n\nend Module\n\nsection GroupWithZero\n\nvariable [GroupWithZero R] [AddMonoid M] [DistribMulAction R M]\n\n-- see note [lower instance priority]\n/-- This instance applies to `DivisionSemiring`s, in particular `NNReal` and `NNRat`. -/\ninstance (priority := 100) GroupWithZero.toNoZeroSMulDivisors : NoZeroSMulDivisors R M :=\n  \u27e8fun {_ _} h => or_iff_not_imp_left.2 fun hc => (smul_eq_zero_iff_eq' hc).1 h\u27e9\n#align group_with_zero.to_no_zero_smul_divisors GroupWithZero.toNoZeroSMulDivisors\n\nend GroupWithZero\n\n-- see note [lower instance priority]\ninstance (priority := 100) RatModule.noZeroSMulDivisors [AddCommGroup M] [Module \u211a M] :\n    NoZeroSMulDivisors \u2124 M :=\n  \u27e8fun {k} {x : M} h => by\n    simpa only [zsmul_eq_smul_cast \u211a k x, smul_eq_zero, Rat.zero_iff_num_zero] using h\u27e9\n  -- Porting note: old proof was:\n  --\u27e8fun {k x} h => by simpa [zsmul_eq_smul_cast \u211a k x] using h\u27e9\n#align rat_module.no_zero_smul_divisors RatModule.noZeroSMulDivisors\n\nend NoZeroSMulDivisors\n\n-- Porting note: simp can prove this\n--@[simp]\ntheorem Nat.smul_one_eq_coe {R : Type _} [Semiring R] (m : \u2115) : m \u2022 (1 : R) = \u2191m := by\n  rw [nsmul_eq_mul, mul_one]\n#align nat.smul_one_eq_coe Nat.smul_one_eq_coe\n\n-- Porting note: simp can prove this\n--@[simp]\ntheorem Int.smul_one_eq_coe {R : Type _} [Ring R] (m : \u2124) : m \u2022 (1 : R) = \u2191m := by\n  rw [zsmul_eq_mul, mul_one]\n#align int.smul_one_eq_coe Int.smul_one_eq_coe\n\n-- Porting note: `assert_not_exists` not implemented yet\n-- assert_not_exists multiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Module/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438124, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7082689327460419}}
{"text": "/-\nCopyright (c) 2021 Christopher Hoskin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Christopher Hoskin\n\n! This file was ported from Lean 3 source module algebra.order.lattice_group\n! leanprover-community/mathlib commit f2f413b9d4be3a02840d0663dace76e8fe3da053\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.GroupPower.Basic\nimport Mathbin.Algebra.Order.Group.Abs\nimport Mathbin.Tactic.NthRewrite.Default\n\n/-!\n# Lattice ordered groups\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nLattice ordered groups were introduced by [Birkhoff][birkhoff1942].\nThey form the algebraic underpinnings of vector lattices, Banach lattices, AL-space, AM-space etc.\n\nThis file develops the basic theory, concentrating on the commutative case.\n\n## Main statements\n\n- `pos_div_neg`: Every element `a` of a lattice ordered commutative group has a decomposition\n  `a\u207a-a\u207b` into the difference of the positive and negative component.\n- `pos_inf_neg_eq_one`: The positive and negative components are coprime.\n- `abs_triangle`: The absolute value operation satisfies the triangle inequality.\n\nIt is shown that the inf and sup operations are related to the absolute value operation by a\nnumber of equations and inequalities.\n\n## Notations\n\n- `a\u207a = a \u2294 0`: The *positive component* of an element `a` of a lattice ordered commutative group\n- `a\u207b = (-a) \u2294 0`: The *negative component* of an element `a` of a lattice ordered commutative group\n- `|a| = a\u2294(-a)`: The *absolute value* of an element `a` of a lattice ordered commutative group\n\n## Implementation notes\n\nA lattice ordered commutative group is a type `\u03b1` satisfying:\n\n* `[lattice \u03b1]`\n* `[comm_group \u03b1]`\n* `[covariant_class \u03b1 \u03b1 (*) (\u2264)]`\n\nThe remainder of the file establishes basic properties of lattice ordered commutative groups. A\nnumber of these results also hold in the non-commutative case ([Birkhoff][birkhoff1942],\n[Fuchs][fuchs1963]) but we have not developed that here, since we are primarily interested in vector\nlattices.\n\n## References\n\n* [Birkhoff, Lattice-ordered Groups][birkhoff1942]\n* [Bourbaki, Algebra II][bourbaki1981]\n* [Fuchs, Partially Ordered Algebraic Systems][fuchs1963]\n* [Zaanen, Lectures on \"Riesz Spaces\"][zaanen1966]\n* [Banasiak, Banach Lattices in Applications][banasiak]\n\n## Tags\n\nlattice, ordered, group\n-/\n\n\n-- Needed for squares\n-- Needed for squares\nuniverse u\n\n/- warning: linear_ordered_comm_group.to_covariant_class -> LinearOrderedCommGroup.to_covariantClass is a dubious translation:\nlean 3 declaration is\n  forall (\u03b1 : Type.{u1}) [_inst_1 : LinearOrderedCommGroup.{u1} \u03b1], CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 (OrderedCommGroup.toCommGroup.{u1} \u03b1 (LinearOrderedCommGroup.toOrderedCommGroup.{u1} \u03b1 _inst_1))))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (OrderedCommGroup.toPartialOrder.{u1} \u03b1 (LinearOrderedCommGroup.toOrderedCommGroup.{u1} \u03b1 _inst_1)))))\nbut is expected to have type\n  forall (\u03b1 : Type.{u1}) [_inst_1 : LinearOrderedCommGroup.{u1} \u03b1], CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.18 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.20 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 (OrderedCommGroup.toCommGroup.{u1} \u03b1 (LinearOrderedCommGroup.toOrderedCommGroup.{u1} \u03b1 _inst_1)))))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.18 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.20) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.33 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.35 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (OrderedCommGroup.toPartialOrder.{u1} \u03b1 (LinearOrderedCommGroup.toOrderedCommGroup.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.33 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.35)\nCase conversion may be inaccurate. Consider using '#align linear_ordered_comm_group.to_covariant_class LinearOrderedCommGroup.to_covariantClass\u2093'. -/\n-- A linearly ordered additive commutative group is a lattice ordered commutative group\n-- see Note [lower instance priority]\n@[to_additive]\ninstance (priority := 100) LinearOrderedCommGroup.to_covariantClass (\u03b1 : Type u)\n    [LinearOrderedCommGroup \u03b1] : CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)\n    where elim a b c bc := LinearOrderedCommGroup.mul_le_mul_left _ _ bc a\n#align linear_ordered_comm_group.to_covariant_class LinearOrderedCommGroup.to_covariantClass\n#align linear_ordered_add_comm_group.to_covariant_class LinearOrderedAddCommGroup.to_covariantClass\n\nvariable {\u03b1 : Type u} [Lattice \u03b1] [CommGroup \u03b1]\n\n/- warning: mul_sup -> mul_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b)) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.91 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.93 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.91 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.93) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.106 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.108 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.106 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.108)] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b)) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c b))\nCase conversion may be inaccurate. Consider using '#align mul_sup mul_sup\u2093'. -/\n-- Special case of Bourbaki A.VI.9 (1)\n-- c + (a \u2294 b) = (c + a) \u2294 (c + b)\n@[to_additive]\ntheorem mul_sup [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b c : \u03b1) : c * (a \u2294 b) = c * a \u2294 c * b :=\n  by\n  refine' le_antisymm _ (by simp)\n  rw [\u2190 mul_le_mul_iff_left c\u207b\u00b9, \u2190 mul_assoc, inv_mul_self, one_mul]\n  exact sup_le (by simp) (by simp)\n#align mul_sup mul_sup\n#align add_sup add_sup\n\n/- warning: mul_inf -> mul_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a b)) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.302 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.304 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.302 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.304) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.317 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.319 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.317 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.319)] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a b)) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c b))\nCase conversion may be inaccurate. Consider using '#align mul_inf mul_inf\u2093'. -/\n@[to_additive]\ntheorem mul_inf [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b c : \u03b1) : c * (a \u2293 b) = c * a \u2293 c * b :=\n  by\n  refine' le_antisymm (by simp) _\n  rw [\u2190 mul_le_mul_iff_left c\u207b\u00b9, \u2190 mul_assoc, inv_mul_self, one_mul]\n  exact le_inf (by simp) (by simp)\n#align mul_inf mul_inf\n#align add_inf add_inf\n\n/- warning: inv_sup_eq_inv_inf_inv -> inv_sup_eq_inv_inf_inv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b)) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.513 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.515 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.513 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.515) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.528 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.530 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.528 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.530)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b)) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) b))\nCase conversion may be inaccurate. Consider using '#align inv_sup_eq_inv_inf_inv inv_sup_eq_inv_inf_inv\u2093'. -/\n-- Special case of Bourbaki A.VI.9 (2)\n-- -(a \u2294 b)=(-a) \u2293 (-b)\n@[to_additive]\ntheorem inv_sup_eq_inv_inf_inv [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) :\n    (a \u2294 b)\u207b\u00b9 = a\u207b\u00b9 \u2293 b\u207b\u00b9 := by\n  apply le_antisymm\n  \u00b7 refine' le_inf _ _\n    \u00b7 rw [inv_le_inv_iff]\n      exact le_sup_left\n    \u00b7 rw [inv_le_inv_iff]\n      exact le_sup_right\n  \u00b7 rw [\u2190 inv_le_inv_iff, inv_inv]\n    refine' sup_le _ _\n    \u00b7 rw [\u2190 inv_le_inv_iff]\n      simp\n    \u00b7 rw [\u2190 inv_le_inv_iff]\n      simp\n#align inv_sup_eq_inv_inf_inv inv_sup_eq_inv_inf_inv\n#align neg_sup_eq_neg_inf_neg neg_sup_eq_neg_inf_neg\n\n/- warning: inv_inf_eq_sup_inv -> inv_inf_eq_sup_inv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a b)) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.757 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.759 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.757 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.759) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.772 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.774 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.772 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.774)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a b)) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) b))\nCase conversion may be inaccurate. Consider using '#align inv_inf_eq_sup_inv inv_inf_eq_sup_inv\u2093'. -/\n-- -(a \u2293 b) = -a \u2294 -b\n@[to_additive]\ntheorem inv_inf_eq_sup_inv [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) : (a \u2293 b)\u207b\u00b9 = a\u207b\u00b9 \u2294 b\u207b\u00b9 :=\n  by rw [\u2190 inv_inv (a\u207b\u00b9 \u2294 b\u207b\u00b9), inv_sup_eq_inv_inf_inv a\u207b\u00b9 b\u207b\u00b9, inv_inv, inv_inv]\n#align inv_inf_eq_sup_inv inv_inf_eq_sup_inv\n#align neg_inf_eq_sup_neg neg_inf_eq_sup_neg\n\n/- warning: inf_mul_sup -> inf_mul_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a b) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.878 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.880 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.878 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.880) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.893 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.895 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.893 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.895)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a b) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b)\nCase conversion may be inaccurate. Consider using '#align inf_mul_sup inf_mul_sup\u2093'. -/\n-- Bourbaki A.VI.10 Prop 7\n-- a \u2293 b + (a \u2294 b) = a + b\n@[to_additive]\ntheorem inf_mul_sup [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) : (a \u2293 b) * (a \u2294 b) = a * b :=\n  calc\n    (a \u2293 b) * (a \u2294 b) = (a \u2293 b) * (a * b * (b\u207b\u00b9 \u2294 a\u207b\u00b9)) :=\n      by\n      rw [mul_sup b\u207b\u00b9 a\u207b\u00b9 (a * b)]\n      simp\n    _ = (a \u2293 b) * (a * b * (a \u2293 b)\u207b\u00b9) := by rw [inv_inf_eq_sup_inv, sup_comm]\n    _ = a * b := by rw [mul_comm, inv_mul_cancel_right]\n    \n#align inf_mul_sup inf_mul_sup\n#align inf_add_sup inf_add_sup\n\nnamespace LatticeOrderedCommGroup\n\n#print LatticeOrderedCommGroup.hasOneLatticeHasPosPart /-\n-- see Note [lower instance priority]\n/--\nLet `\u03b1` be a lattice ordered commutative group with identity `1`. For an element `a` of type `\u03b1`,\nthe element `a \u2294 1` is said to be the *positive component* of `a`, denoted `a\u207a`.\n-/\n@[to_additive\n      \"\\nLet `\u03b1` be a lattice ordered commutative group with identity `0`. For an element `a` of type `\u03b1`,\\nthe element `a \u2294 0` is said to be the *positive component* of `a`, denoted `a\u207a`.\\n\"]\ninstance (priority := 100) hasOneLatticeHasPosPart : PosPart \u03b1 :=\n  \u27e8fun a => a \u2294 1\u27e9\n#align lattice_ordered_comm_group.has_one_lattice_has_pos_part LatticeOrderedCommGroup.hasOneLatticeHasPosPart\n#align lattice_ordered_comm_group.has_zero_lattice_has_pos_part LatticeOrderedCommGroup.hasZeroLatticeHasPosPart\n-/\n\n/- warning: lattice_ordered_comm_group.m_pos_part_def -> LatticeOrderedCommGroup.m_pos_part_def is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.m_pos_part_def LatticeOrderedCommGroup.m_pos_part_def\u2093'. -/\n@[to_additive pos_part_def]\ntheorem m_pos_part_def (a : \u03b1) : a\u207a = a \u2294 1 :=\n  rfl\n#align lattice_ordered_comm_group.m_pos_part_def LatticeOrderedCommGroup.m_pos_part_def\n#align lattice_ordered_comm_group.pos_part_def LatticeOrderedCommGroup.pos_part_def\n\n#print LatticeOrderedCommGroup.hasOneLatticeHasNegPart /-\n-- see Note [lower instance priority]\n/--\nLet `\u03b1` be a lattice ordered commutative group with identity `1`. For an element `a` of type `\u03b1`,\nthe element `(-a) \u2294 1` is said to be the *negative component* of `a`, denoted `a\u207b`.\n-/\n@[to_additive\n      \"\\nLet `\u03b1` be a lattice ordered commutative group with identity `0`. For an element `a` of type `\u03b1`,\\nthe element `(-a) \u2294 0` is said to be the *negative component* of `a`, denoted `a\u207b`.\\n\"]\ninstance (priority := 100) hasOneLatticeHasNegPart : NegPart \u03b1 :=\n  \u27e8fun a => a\u207b\u00b9 \u2294 1\u27e9\n#align lattice_ordered_comm_group.has_one_lattice_has_neg_part LatticeOrderedCommGroup.hasOneLatticeHasNegPart\n#align lattice_ordered_comm_group.has_zero_lattice_has_neg_part LatticeOrderedCommGroup.hasZeroLatticeHasNegPart\n-/\n\n/- warning: lattice_ordered_comm_group.m_neg_part_def -> LatticeOrderedCommGroup.m_neg_part_def is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.m_neg_part_def LatticeOrderedCommGroup.m_neg_part_def\u2093'. -/\n@[to_additive neg_part_def]\ntheorem m_neg_part_def (a : \u03b1) : a\u207b = a\u207b\u00b9 \u2294 1 :=\n  rfl\n#align lattice_ordered_comm_group.m_neg_part_def LatticeOrderedCommGroup.m_neg_part_def\n#align lattice_ordered_comm_group.neg_part_def LatticeOrderedCommGroup.neg_part_def\n\n/- warning: lattice_ordered_comm_group.pos_one -> LatticeOrderedCommGroup.pos_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1], Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1], Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_one LatticeOrderedCommGroup.pos_one\u2093'. -/\n@[simp, to_additive]\ntheorem pos_one : (1 : \u03b1)\u207a = 1 :=\n  sup_idem\n#align lattice_ordered_comm_group.pos_one LatticeOrderedCommGroup.pos_one\n#align lattice_ordered_comm_group.pos_zero LatticeOrderedCommGroup.pos_zero\n\n/- warning: lattice_ordered_comm_group.neg_one -> LatticeOrderedCommGroup.neg_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1], Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1], Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_one LatticeOrderedCommGroup.neg_one\u2093'. -/\n@[simp, to_additive]\ntheorem neg_one : (1 : \u03b1)\u207b = 1 := by rw [m_neg_part_def, inv_one, sup_idem]\n#align lattice_ordered_comm_group.neg_one LatticeOrderedCommGroup.neg_one\n#align lattice_ordered_comm_group.neg_zero LatticeOrderedCommGroup.neg_zero\n\n/- warning: lattice_ordered_comm_group.neg_eq_inv_inf_one -> LatticeOrderedCommGroup.neg_eq_inv_inf_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1318 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1320 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1318 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1320) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1333 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1335 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1333 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1335)] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_eq_inv_inf_one LatticeOrderedCommGroup.neg_eq_inv_inf_one\u2093'. -/\n-- a\u207b = -(a \u2293 0)\n@[to_additive]\ntheorem neg_eq_inv_inf_one [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : a\u207b = (a \u2293 1)\u207b\u00b9 := by\n  rw [m_neg_part_def, \u2190 inv_inj, inv_sup_eq_inv_inf_inv, inv_inv, inv_inv, inv_one]\n#align lattice_ordered_comm_group.neg_eq_inv_inf_one LatticeOrderedCommGroup.neg_eq_inv_inf_one\n#align lattice_ordered_comm_group.neg_eq_neg_inf_zero LatticeOrderedCommGroup.neg_eq_neg_inf_zero\n\n/- warning: lattice_ordered_comm_group.le_mabs -> LatticeOrderedCommGroup.le_mabs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.le_mabs LatticeOrderedCommGroup.le_mabs\u2093'. -/\n@[to_additive le_abs]\ntheorem le_mabs (a : \u03b1) : a \u2264 |a| :=\n  le_sup_left\n#align lattice_ordered_comm_group.le_mabs LatticeOrderedCommGroup.le_mabs\n#align lattice_ordered_comm_group.le_abs LatticeOrderedCommGroup.le_abs\n\n/- warning: lattice_ordered_comm_group.inv_le_abs -> LatticeOrderedCommGroup.inv_le_abs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.inv_le_abs LatticeOrderedCommGroup.inv_le_abs\u2093'. -/\n-- -a \u2264 |a|\n@[to_additive]\ntheorem inv_le_abs (a : \u03b1) : a\u207b\u00b9 \u2264 |a| :=\n  le_sup_right\n#align lattice_ordered_comm_group.inv_le_abs LatticeOrderedCommGroup.inv_le_abs\n#align lattice_ordered_comm_group.neg_le_abs LatticeOrderedCommGroup.neg_le_abs\n\n/- warning: lattice_ordered_comm_group.one_le_pos -> LatticeOrderedCommGroup.one_le_pos is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.one_le_pos LatticeOrderedCommGroup.one_le_pos\u2093'. -/\n-- 0 \u2264 a\u207a\n@[to_additive pos_nonneg]\ntheorem one_le_pos (a : \u03b1) : 1 \u2264 a\u207a :=\n  le_sup_right\n#align lattice_ordered_comm_group.one_le_pos LatticeOrderedCommGroup.one_le_pos\n#align lattice_ordered_comm_group.pos_nonneg LatticeOrderedCommGroup.pos_nonneg\n\n/- warning: lattice_ordered_comm_group.one_le_neg -> LatticeOrderedCommGroup.one_le_neg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.one_le_neg LatticeOrderedCommGroup.one_le_neg\u2093'. -/\n-- 0 \u2264 a\u207b\n@[to_additive neg_nonneg]\ntheorem one_le_neg (a : \u03b1) : 1 \u2264 a\u207b :=\n  le_sup_right\n#align lattice_ordered_comm_group.one_le_neg LatticeOrderedCommGroup.one_le_neg\n#align lattice_ordered_comm_group.neg_nonneg LatticeOrderedCommGroup.neg_nonneg\n\n/- warning: lattice_ordered_comm_group.pos_le_one_iff -> LatticeOrderedCommGroup.pos_le_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_le_one_iff LatticeOrderedCommGroup.pos_le_one_iff\u2093'. -/\n-- pos_nonpos_iff\n@[to_additive]\ntheorem pos_le_one_iff {a : \u03b1} : a\u207a \u2264 1 \u2194 a \u2264 1 :=\n  by\n  rw [m_pos_part_def, sup_le_iff]\n  simp\n#align lattice_ordered_comm_group.pos_le_one_iff LatticeOrderedCommGroup.pos_le_one_iff\n#align lattice_ordered_comm_group.pos_nonpos_iff LatticeOrderedCommGroup.pos_nonpos_iff\n\n/- warning: lattice_ordered_comm_group.neg_le_one_iff -> LatticeOrderedCommGroup.neg_le_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_le_one_iff LatticeOrderedCommGroup.neg_le_one_iff\u2093'. -/\n-- neg_nonpos_iff\n@[to_additive]\ntheorem neg_le_one_iff {a : \u03b1} : a\u207b \u2264 1 \u2194 a\u207b\u00b9 \u2264 1 :=\n  by\n  rw [m_neg_part_def, sup_le_iff]\n  simp\n#align lattice_ordered_comm_group.neg_le_one_iff LatticeOrderedCommGroup.neg_le_one_iff\n#align lattice_ordered_comm_group.neg_nonpos_iff LatticeOrderedCommGroup.neg_nonpos_iff\n\n/- warning: lattice_ordered_comm_group.pos_eq_one_iff -> LatticeOrderedCommGroup.pos_eq_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_eq_one_iff LatticeOrderedCommGroup.pos_eq_one_iff\u2093'. -/\n@[to_additive]\ntheorem pos_eq_one_iff {a : \u03b1} : a\u207a = 1 \u2194 a \u2264 1 :=\n  by\n  rw [le_antisymm_iff]\n  simp only [one_le_pos, and_true_iff]\n  exact pos_le_one_iff\n#align lattice_ordered_comm_group.pos_eq_one_iff LatticeOrderedCommGroup.pos_eq_one_iff\n#align lattice_ordered_comm_group.pos_eq_zero_iff LatticeOrderedCommGroup.pos_eq_zero_iff\n\n/- warning: lattice_ordered_comm_group.neg_eq_one_iff' -> LatticeOrderedCommGroup.neg_eq_one_iff' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] {a : \u03b1}, Iff (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_eq_one_iff' LatticeOrderedCommGroup.neg_eq_one_iff'\u2093'. -/\n@[to_additive]\ntheorem neg_eq_one_iff' {a : \u03b1} : a\u207b = 1 \u2194 a\u207b\u00b9 \u2264 1 :=\n  by\n  rw [le_antisymm_iff]\n  simp only [one_le_neg, and_true_iff]\n  rw [neg_le_one_iff]\n#align lattice_ordered_comm_group.neg_eq_one_iff' LatticeOrderedCommGroup.neg_eq_one_iff'\n#align lattice_ordered_comm_group.neg_eq_zero_iff' LatticeOrderedCommGroup.neg_eq_zero_iff'\n\n/- warning: lattice_ordered_comm_group.neg_eq_one_iff -> LatticeOrderedCommGroup.neg_eq_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] {a : \u03b1}, Iff (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (Mul.mul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] {a : \u03b1}, Iff (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_eq_one_iff LatticeOrderedCommGroup.neg_eq_one_iff\u2093'. -/\n@[to_additive]\ntheorem neg_eq_one_iff [CovariantClass \u03b1 \u03b1 Mul.mul LE.le] {a : \u03b1} : a\u207b = 1 \u2194 1 \u2264 a :=\n  by\n  rw [le_antisymm_iff]\n  simp only [one_le_neg, and_true_iff]\n  rw [neg_le_one_iff, inv_le_one']\n#align lattice_ordered_comm_group.neg_eq_one_iff LatticeOrderedCommGroup.neg_eq_one_iff\n#align lattice_ordered_comm_group.neg_eq_zero_iff LatticeOrderedCommGroup.neg_eq_zero_iff\n\n#print LatticeOrderedCommGroup.m_le_pos /-\n@[to_additive le_pos]\ntheorem m_le_pos (a : \u03b1) : a \u2264 a\u207a :=\n  le_sup_left\n#align lattice_ordered_comm_group.m_le_pos LatticeOrderedCommGroup.m_le_pos\n#align lattice_ordered_comm_group.le_pos LatticeOrderedCommGroup.le_pos\n-/\n\n/- warning: lattice_ordered_comm_group.inv_le_neg -> LatticeOrderedCommGroup.inv_le_neg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.inv_le_neg LatticeOrderedCommGroup.inv_le_neg\u2093'. -/\n-- -a \u2264 a\u207b\n@[to_additive]\ntheorem inv_le_neg (a : \u03b1) : a\u207b\u00b9 \u2264 a\u207b :=\n  le_sup_left\n#align lattice_ordered_comm_group.inv_le_neg LatticeOrderedCommGroup.inv_le_neg\n#align lattice_ordered_comm_group.neg_le_neg LatticeOrderedCommGroup.neg_le_neg\n\n/- warning: lattice_ordered_comm_group.neg_eq_pos_inv -> LatticeOrderedCommGroup.neg_eq_pos_inv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_eq_pos_inv LatticeOrderedCommGroup.neg_eq_pos_inv\u2093'. -/\n-- Bourbaki A.VI.12\n--  a\u207b = (-a)\u207a\n@[to_additive]\ntheorem neg_eq_pos_inv (a : \u03b1) : a\u207b = a\u207b\u00b9\u207a :=\n  rfl\n#align lattice_ordered_comm_group.neg_eq_pos_inv LatticeOrderedCommGroup.neg_eq_pos_inv\n#align lattice_ordered_comm_group.neg_eq_pos_neg LatticeOrderedCommGroup.neg_eq_pos_neg\n\n/- warning: lattice_ordered_comm_group.pos_eq_neg_inv -> LatticeOrderedCommGroup.pos_eq_neg_inv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_eq_neg_inv LatticeOrderedCommGroup.pos_eq_neg_inv\u2093'. -/\n-- a\u207a = (-a)\u207b\n@[to_additive]\ntheorem pos_eq_neg_inv (a : \u03b1) : a\u207a = a\u207b\u00b9\u207b := by simp [neg_eq_pos_inv]\n#align lattice_ordered_comm_group.pos_eq_neg_inv LatticeOrderedCommGroup.pos_eq_neg_inv\n#align lattice_ordered_comm_group.pos_eq_neg_neg LatticeOrderedCommGroup.pos_eq_neg_neg\n\n/- warning: lattice_ordered_comm_group.mul_inf_eq_mul_inf_mul -> LatticeOrderedCommGroup.mul_inf_eq_mul_inf_mul is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a b)) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1941 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1943 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1941 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1943) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1956 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1958 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1956 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.1958)] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a b)) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) c b))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.mul_inf_eq_mul_inf_mul LatticeOrderedCommGroup.mul_inf_eq_mul_inf_mul\u2093'. -/\n-- We use this in Bourbaki A.VI.12  Prop 9 a)\n-- c + (a \u2293 b) = (c + a) \u2293 (c + b)\n@[to_additive]\ntheorem mul_inf_eq_mul_inf_mul [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b c : \u03b1) :\n    c * (a \u2293 b) = c * a \u2293 c * b :=\n  by\n  refine' le_antisymm (by simp) _\n  rw [\u2190 mul_le_mul_iff_left c\u207b\u00b9, \u2190 mul_assoc, inv_mul_self, one_mul, le_inf_iff]\n  simp\n#align lattice_ordered_comm_group.mul_inf_eq_mul_inf_mul LatticeOrderedCommGroup.mul_inf_eq_mul_inf_mul\n#align lattice_ordered_comm_group.add_inf_eq_add_inf_add LatticeOrderedCommGroup.add_inf_eq_add_inf_add\n\n/- warning: lattice_ordered_comm_group.pos_div_neg -> LatticeOrderedCommGroup.pos_div_neg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), Eq.{succ u1} \u03b1 (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)) a\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2088 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2090 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2088 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2090) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2103 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2105 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2103 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2105)] (a : \u03b1), Eq.{succ u1} \u03b1 (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)) a\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_div_neg LatticeOrderedCommGroup.pos_div_neg\u2093'. -/\n-- Bourbaki A.VI.12  Prop 9 a)\n-- a = a\u207a - a\u207b\n@[simp, to_additive]\ntheorem pos_div_neg [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : a\u207a / a\u207b = a :=\n  by\n  symm\n  rw [div_eq_mul_inv]\n  apply eq_mul_inv_of_mul_eq\n  rw [m_neg_part_def, mul_sup, mul_one, mul_right_inv, sup_comm, m_pos_part_def]\n#align lattice_ordered_comm_group.pos_div_neg LatticeOrderedCommGroup.pos_div_neg\n#align lattice_ordered_comm_group.pos_sub_neg LatticeOrderedCommGroup.pos_sub_neg\n\n/- warning: lattice_ordered_comm_group.pos_inf_neg_eq_one -> LatticeOrderedCommGroup.pos_inf_neg_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), Eq.{succ u1} \u03b1 (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2209 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2211 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2209 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2211) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2224 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2226 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2224 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2226)] (a : \u03b1), Eq.{succ u1} \u03b1 (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_inf_neg_eq_one LatticeOrderedCommGroup.pos_inf_neg_eq_one\u2093'. -/\n-- Bourbaki A.VI.12  Prop 9 a)\n-- a\u207a \u2293 a\u207b = 0 (`a\u207a` and `a\u207b` are co-prime, and, since they are positive, disjoint)\n@[to_additive]\ntheorem pos_inf_neg_eq_one [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : a\u207a \u2293 a\u207b = 1 := by\n  rw [\u2190 mul_right_inj (a\u207b)\u207b\u00b9, mul_inf_eq_mul_inf_mul, mul_one, mul_left_inv, mul_comm, \u2190\n    div_eq_mul_inv, pos_div_neg, neg_eq_inv_inf_one, inv_inv]\n#align lattice_ordered_comm_group.pos_inf_neg_eq_one LatticeOrderedCommGroup.pos_inf_neg_eq_one\n#align lattice_ordered_comm_group.pos_inf_neg_eq_zero LatticeOrderedCommGroup.pos_inf_neg_eq_zero\n\n/- warning: lattice_ordered_comm_group.sup_eq_mul_pos_div -> LatticeOrderedCommGroup.sup_eq_mul_pos_div is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) b (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2314 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2316 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2314 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2316) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2329 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2331 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2329 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2331)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) b (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b)))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.sup_eq_mul_pos_div LatticeOrderedCommGroup.sup_eq_mul_pos_div\u2093'. -/\n-- Bourbaki A.VI.12 (with a and b swapped)\n-- a\u2294b = b + (a - b)\u207a\n@[to_additive]\ntheorem sup_eq_mul_pos_div [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) : a \u2294 b = b * (a / b)\u207a :=\n  calc\n    a \u2294 b = b * (a / b) \u2294 b * 1 := by\n      rw [mul_one b, div_eq_mul_inv, mul_comm a, mul_inv_cancel_left]\n    _ = b * (a / b \u2294 1) := by rw [\u2190 mul_sup (a / b) 1 b]\n    \n#align lattice_ordered_comm_group.sup_eq_mul_pos_div LatticeOrderedCommGroup.sup_eq_mul_pos_div\n#align lattice_ordered_comm_group.sup_eq_add_pos_sub LatticeOrderedCommGroup.sup_eq_add_pos_sub\n\n/- warning: lattice_ordered_comm_group.inf_eq_div_pos_div -> LatticeOrderedCommGroup.inf_eq_div_pos_div is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a b) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2496 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2498 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2496 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2498) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2511 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2513 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2511 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2513)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a b) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b)))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.inf_eq_div_pos_div LatticeOrderedCommGroup.inf_eq_div_pos_div\u2093'. -/\n-- Bourbaki A.VI.12 (with a and b swapped)\n-- a\u2293b = a - (a - b)\u207a\n@[to_additive]\ntheorem inf_eq_div_pos_div [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) : a \u2293 b = a / (a / b)\u207a :=\n  calc\n    a \u2293 b = a * 1 \u2293 a * (b / a) := by\n      rw [mul_one a, div_eq_mul_inv, mul_comm b, mul_inv_cancel_left]\n    _ = a * (1 \u2293 b / a) := by rw [\u2190 mul_inf_eq_mul_inf_mul 1 (b / a) a]\n    _ = a * (b / a \u2293 1) := by rw [inf_comm]\n    _ = a * ((a / b)\u207b\u00b9 \u2293 1) := by\n      rw [div_eq_mul_inv]\n      nth_rw 1 [\u2190 inv_inv b]\n      rw [\u2190 mul_inv, mul_comm b\u207b\u00b9, \u2190 div_eq_mul_inv]\n    _ = a * ((a / b)\u207b\u00b9 \u2293 1\u207b\u00b9) := by rw [inv_one]\n    _ = a / (a / b \u2294 1) := by rw [\u2190 inv_sup_eq_inv_inf_inv, \u2190 div_eq_mul_inv]\n    \n#align lattice_ordered_comm_group.inf_eq_div_pos_div LatticeOrderedCommGroup.inf_eq_div_pos_div\n#align lattice_ordered_comm_group.inf_eq_sub_pos_sub LatticeOrderedCommGroup.inf_eq_sub_pos_sub\n\n/- warning: lattice_ordered_comm_group.m_le_iff_pos_le_neg_ge -> LatticeOrderedCommGroup.m_le_iff_pos_le_neg_ge is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Iff (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a b) (And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) b)) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) b) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2965 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2967 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2965 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2967) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2980 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2982 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2980 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.2982)] (a : \u03b1) (b : \u03b1), Iff (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a b) (And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) b)) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) b) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a)))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.m_le_iff_pos_le_neg_ge LatticeOrderedCommGroup.m_le_iff_pos_le_neg_ge\u2093'. -/\n-- Bourbaki A.VI.12 Prop 9 c)\n@[to_additive le_iff_pos_le_neg_ge]\ntheorem m_le_iff_pos_le_neg_ge [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) :\n    a \u2264 b \u2194 a\u207a \u2264 b\u207a \u2227 b\u207b \u2264 a\u207b := by\n  constructor <;> intro h\n  \u00b7 constructor\n    \u00b7 exact sup_le (h.trans (m_le_pos b)) (one_le_pos b)\n    \u00b7 rw [\u2190 inv_le_inv_iff] at h\n      exact sup_le (h.trans (inv_le_neg a)) (one_le_neg a)\n  \u00b7 rw [\u2190 pos_div_neg a, \u2190 pos_div_neg b]\n    exact div_le_div'' h.1 h.2\n#align lattice_ordered_comm_group.m_le_iff_pos_le_neg_ge LatticeOrderedCommGroup.m_le_iff_pos_le_neg_ge\n#align lattice_ordered_comm_group.le_iff_pos_le_neg_ge LatticeOrderedCommGroup.le_iff_pos_le_neg_ge\n\n/- warning: lattice_ordered_comm_group.m_neg_abs -> LatticeOrderedCommGroup.m_neg_abs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3157 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3159 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3157 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3159) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3172 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3174 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3172 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3174)] (a : \u03b1), Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.m_neg_abs LatticeOrderedCommGroup.m_neg_abs\u2093'. -/\n@[to_additive neg_abs]\ntheorem m_neg_abs [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : |a|\u207b = 1 :=\n  by\n  refine' le_antisymm _ _\n  \u00b7 rw [\u2190 pos_inf_neg_eq_one a]\n    apply le_inf\n    \u00b7 rw [pos_eq_neg_inv]\n      exact ((m_le_iff_pos_le_neg_ge _ _).mp (inv_le_abs a)).right\n    \u00b7 exact And.right (Iff.mp (m_le_iff_pos_le_neg_ge _ _) (le_mabs a))\n  \u00b7 exact one_le_neg _\n#align lattice_ordered_comm_group.m_neg_abs LatticeOrderedCommGroup.m_neg_abs\n#align lattice_ordered_comm_group.neg_abs LatticeOrderedCommGroup.neg_abs\n\n/- warning: lattice_ordered_comm_group.m_pos_abs -> LatticeOrderedCommGroup.m_pos_abs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3318 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3320 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3318 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3320) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3333 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3335 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3333 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3335)] (a : \u03b1), Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.m_pos_abs LatticeOrderedCommGroup.m_pos_abs\u2093'. -/\n@[to_additive pos_abs]\ntheorem m_pos_abs [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : |a|\u207a = |a| :=\n  by\n  nth_rw 2 [\u2190 pos_div_neg (|a|)]\n  rw [div_eq_mul_inv]\n  symm\n  rw [mul_right_eq_self, inv_eq_one]\n  exact m_neg_abs a\n#align lattice_ordered_comm_group.m_pos_abs LatticeOrderedCommGroup.m_pos_abs\n#align lattice_ordered_comm_group.pos_abs LatticeOrderedCommGroup.pos_abs\n\n/- warning: lattice_ordered_comm_group.one_le_abs -> LatticeOrderedCommGroup.one_le_abs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3476 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3478 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3476 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3478) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3491 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3493 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3491 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3493)] (a : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.one_le_abs LatticeOrderedCommGroup.one_le_abs\u2093'. -/\n@[to_additive abs_nonneg]\ntheorem one_le_abs [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : 1 \u2264 |a| :=\n  by\n  rw [\u2190 m_pos_abs]\n  exact one_le_pos _\n#align lattice_ordered_comm_group.one_le_abs LatticeOrderedCommGroup.one_le_abs\n#align lattice_ordered_comm_group.abs_nonneg LatticeOrderedCommGroup.abs_nonneg\n\n/- warning: lattice_ordered_comm_group.pos_mul_neg -> LatticeOrderedCommGroup.pos_mul_neg is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3563 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3565 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3563 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3565) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3578 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3580 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3578 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3580)] (a : \u03b1), Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_mul_neg LatticeOrderedCommGroup.pos_mul_neg\u2093'. -/\n-- The proof from Bourbaki A.VI.12 Prop 9 d)\n-- |a| = a\u207a - a\u207b\n@[to_additive]\ntheorem pos_mul_neg [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : |a| = a\u207a * a\u207b :=\n  by\n  refine' le_antisymm _ _\n  \u00b7 refine' sup_le _ _\n    \u00b7 nth_rw 1 [\u2190 mul_one a]\n      exact mul_le_mul' (m_le_pos a) (one_le_neg a)\n    \u00b7 nth_rw 1 [\u2190 one_mul a\u207b\u00b9]\n      exact mul_le_mul' (one_le_pos a) (inv_le_neg a)\n  \u00b7 rw [\u2190 inf_mul_sup, pos_inf_neg_eq_one, one_mul, \u2190 m_pos_abs a]\n    apply sup_le\n    \u00b7 exact ((m_le_iff_pos_le_neg_ge _ _).mp (le_mabs a)).left\n    \u00b7 rw [neg_eq_pos_inv]\n      exact ((m_le_iff_pos_le_neg_ge _ _).mp (inv_le_abs a)).left\n#align lattice_ordered_comm_group.pos_mul_neg LatticeOrderedCommGroup.pos_mul_neg\n#align lattice_ordered_comm_group.pos_add_neg LatticeOrderedCommGroup.pos_add_neg\n\n/- warning: lattice_ordered_comm_group.sup_div_inf_eq_abs_div -> LatticeOrderedCommGroup.sup_div_inf_eq_abs_div is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a b)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3818 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3820 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3818 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3820) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3833 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3835 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3833 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3835)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a b)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.sup_div_inf_eq_abs_div LatticeOrderedCommGroup.sup_div_inf_eq_abs_div\u2093'. -/\n-- a \u2294 b - (a \u2293 b) = |b - a|\n@[to_additive]\ntheorem sup_div_inf_eq_abs_div [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) :\n    (a \u2294 b) / (a \u2293 b) = |b / a| :=\n  by\n  rw [sup_eq_mul_pos_div, inf_comm, inf_eq_div_pos_div, div_eq_mul_inv]\n  nth_rw 2 [div_eq_mul_inv]\n  rw [mul_inv_rev, inv_inv, mul_comm, \u2190 mul_assoc, inv_mul_cancel_right, pos_eq_neg_inv (a / b)]\n  nth_rw 2 [div_eq_mul_inv]\n  rw [mul_inv_rev, \u2190 div_eq_mul_inv, inv_inv, \u2190 pos_mul_neg]\n#align lattice_ordered_comm_group.sup_div_inf_eq_abs_div LatticeOrderedCommGroup.sup_div_inf_eq_abs_div\n#align lattice_ordered_comm_group.sup_sub_inf_eq_abs_sub LatticeOrderedCommGroup.sup_sub_inf_eq_abs_sub\n\n/- warning: lattice_ordered_comm_group.sup_sq_eq_mul_mul_abs_div -> LatticeOrderedCommGroup.sup_sq_eq_mul_mul_abs_div is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HPow.hPow.{u1, 0, u1} \u03b1 Nat \u03b1 (instHPow.{u1, 0} \u03b1 Nat (Monoid.Pow.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3949 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3951 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3949 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3951) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3964 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3966 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3964 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.3966)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HPow.hPow.{u1, 0, u1} \u03b1 Nat \u03b1 (instHPow.{u1, 0} \u03b1 Nat (Monoid.Pow.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a b) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a)))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.sup_sq_eq_mul_mul_abs_div LatticeOrderedCommGroup.sup_sq_eq_mul_mul_abs_div\u2093'. -/\n-- 2\u2022(a \u2294 b) = a + b + |b - a|\n@[to_additive two_sup_eq_add_add_abs_sub]\ntheorem sup_sq_eq_mul_mul_abs_div [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) :\n    (a \u2294 b) ^ 2 = a * b * |b / a| := by\n  rw [\u2190 inf_mul_sup a b, \u2190 sup_div_inf_eq_abs_div, div_eq_mul_inv, \u2190 mul_assoc, mul_comm, mul_assoc,\n    \u2190 pow_two, inv_mul_cancel_left]\n#align lattice_ordered_comm_group.sup_sq_eq_mul_mul_abs_div LatticeOrderedCommGroup.sup_sq_eq_mul_mul_abs_div\n#align lattice_ordered_comm_group.two_sup_eq_add_add_abs_sub LatticeOrderedCommGroup.two_sup_eq_add_add_abs_sub\n\n/- warning: lattice_ordered_comm_group.inf_sq_eq_mul_div_abs_div -> LatticeOrderedCommGroup.inf_sq_eq_mul_div_abs_div is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HPow.hPow.{u1, 0, u1} \u03b1 Nat \u03b1 (instHPow.{u1, 0} \u03b1 Nat (Monoid.Pow.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a b) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4053 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4055 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4053 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4055) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4068 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4070 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4068 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4070)] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (HPow.hPow.{u1, 0, u1} \u03b1 Nat \u03b1 (instHPow.{u1, 0} \u03b1 Nat (Monoid.Pow.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a b) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a)))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.inf_sq_eq_mul_div_abs_div LatticeOrderedCommGroup.inf_sq_eq_mul_div_abs_div\u2093'. -/\n-- 2\u2022(a \u2293 b) = a + b - |b - a|\n@[to_additive two_inf_eq_add_sub_abs_sub]\ntheorem inf_sq_eq_mul_div_abs_div [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) :\n    (a \u2293 b) ^ 2 = a * b / |b / a| := by\n  rw [\u2190 inf_mul_sup a b, \u2190 sup_div_inf_eq_abs_div, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev,\n    inv_inv, mul_assoc, mul_inv_cancel_comm_assoc, \u2190 pow_two]\n#align lattice_ordered_comm_group.inf_sq_eq_mul_div_abs_div LatticeOrderedCommGroup.inf_sq_eq_mul_div_abs_div\n#align lattice_ordered_comm_group.two_inf_eq_add_sub_abs_sub LatticeOrderedCommGroup.two_inf_eq_add_sub_abs_sub\n\n/- warning: lattice_ordered_comm_group.lattice_ordered_comm_group_to_distrib_lattice -> LatticeOrderedCommGroup.latticeOrderedCommGroupToDistribLattice is a dubious translation:\nlean 3 declaration is\n  forall (\u03b1 : Type.{u1}) [s : Lattice.{u1} \u03b1] [_inst_3 : CommGroup.{u1} \u03b1] [_inst_4 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_3))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 s)))))], DistribLattice.{u1} \u03b1\nbut is expected to have type\n  forall (\u03b1 : Type.{u1}) [s : Lattice.{u1} \u03b1] [_inst_3 : CommGroup.{u1} \u03b1] [_inst_4 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4164 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4166 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_3)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4164 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4166) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4179 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4181 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 s)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4179 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4181)], DistribLattice.{u1} \u03b1\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.lattice_ordered_comm_group_to_distrib_lattice LatticeOrderedCommGroup.latticeOrderedCommGroupToDistribLattice\u2093'. -/\n/-- Every lattice ordered commutative group is a distributive lattice\n-/\n@[to_additive \"Every lattice ordered commutative additive group is a distributive lattice\"]\ndef latticeOrderedCommGroupToDistribLattice (\u03b1 : Type u) [s : Lattice \u03b1] [CommGroup \u03b1]\n    [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : DistribLattice \u03b1 :=\n  { s with\n    le_sup_inf := by\n      intros\n      rw [\u2190 mul_le_mul_iff_left (x \u2293 (y \u2293 z)), inf_mul_sup x (y \u2293 z), \u2190 inv_mul_le_iff_le_mul,\n        le_inf_iff]\n      constructor\n      \u00b7 rw [inv_mul_le_iff_le_mul, \u2190 inf_mul_sup x y]\n        apply mul_le_mul'\n        \u00b7 apply inf_le_inf_left\n          apply inf_le_left\n        \u00b7 apply inf_le_left\n      \u00b7 rw [inv_mul_le_iff_le_mul, \u2190 inf_mul_sup x z]\n        apply mul_le_mul'\n        \u00b7 apply inf_le_inf_left\n          apply inf_le_right\n        \u00b7 apply inf_le_right }\n#align lattice_ordered_comm_group.lattice_ordered_comm_group_to_distrib_lattice LatticeOrderedCommGroup.latticeOrderedCommGroupToDistribLattice\n#align lattice_ordered_comm_group.lattice_ordered_add_comm_group_to_distrib_lattice LatticeOrderedCommGroup.latticeOrderedAddCommGroupToDistribLattice\n\n/- warning: lattice_ordered_comm_group.abs_div_sup_mul_abs_div_inf -> LatticeOrderedCommGroup.abs_div_sup_mul_abs_div_inf is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a c) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a c) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) b c)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4361 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4363 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4361 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4363) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4376 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4378 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4376 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.4378)] (a : \u03b1) (b : \u03b1) (c : \u03b1), Eq.{succ u1} \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a c) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a c) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) b c)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.abs_div_sup_mul_abs_div_inf LatticeOrderedCommGroup.abs_div_sup_mul_abs_div_inf\u2093'. -/\n-- See, e.g. Zaanen, Lectures on Riesz Spaces\n-- 3rd lecture\n-- |a \u2294 c - (b \u2294 c)| + |a \u2293 c-b \u2293 c| = |a - b|\n@[to_additive]\ntheorem abs_div_sup_mul_abs_div_inf [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b c : \u03b1) :\n    |(a \u2294 c) / (b \u2294 c)| * |(a \u2293 c) / (b \u2293 c)| = |a / b| :=\n  by\n  letI : DistribLattice \u03b1 := lattice_ordered_comm_group_to_distrib_lattice \u03b1\n  calc\n    |(a \u2294 c) / (b \u2294 c)| * |(a \u2293 c) / (b \u2293 c)| =\n        (b \u2294 c \u2294 (a \u2294 c)) / ((b \u2294 c) \u2293 (a \u2294 c)) * |(a \u2293 c) / (b \u2293 c)| :=\n      by rw [sup_div_inf_eq_abs_div]\n    _ = (b \u2294 c \u2294 (a \u2294 c)) / ((b \u2294 c) \u2293 (a \u2294 c)) * ((b \u2293 c \u2294 a \u2293 c) / (b \u2293 c \u2293 (a \u2293 c))) := by\n      rw [sup_div_inf_eq_abs_div (b \u2293 c) (a \u2293 c)]\n    _ = (b \u2294 a \u2294 c) / (b \u2293 a \u2294 c) * (((b \u2294 a) \u2293 c) / (b \u2293 a \u2293 c)) :=\n      by\n      rw [\u2190 sup_inf_right, \u2190 inf_sup_right, sup_assoc]\n      nth_rw 2 [sup_comm]\n      rw [sup_right_idem, sup_assoc, inf_assoc]\n      nth_rw 4 [inf_comm]\n      rw [inf_right_idem, inf_assoc]\n    _ = (b \u2294 a \u2294 c) * ((b \u2294 a) \u2293 c) / ((b \u2293 a \u2294 c) * (b \u2293 a \u2293 c)) := by rw [div_mul_div_comm]\n    _ = (b \u2294 a) * c / ((b \u2293 a) * c) := by\n      rw [mul_comm, inf_mul_sup, mul_comm (b \u2293 a \u2294 c), inf_mul_sup]\n    _ = (b \u2294 a) / (b \u2293 a) := by\n      rw [div_eq_mul_inv, mul_inv_rev, mul_assoc, mul_inv_cancel_left, \u2190 div_eq_mul_inv]\n    _ = |a / b| := by rw [sup_div_inf_eq_abs_div]\n    \n#align lattice_ordered_comm_group.abs_div_sup_mul_abs_div_inf LatticeOrderedCommGroup.abs_div_sup_mul_abs_div_inf\n#align lattice_ordered_comm_group.abs_sub_sup_add_abs_sub_inf LatticeOrderedCommGroup.abs_sub_sup_add_abs_sub_inf\n\n/- warning: lattice_ordered_comm_group.pos_of_one_le -> LatticeOrderedCommGroup.pos_of_one_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) a) -> (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) a) -> (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_of_one_le LatticeOrderedCommGroup.pos_of_one_le\u2093'. -/\n-- pos_of_nonneg\n/-- If `a` is positive, then it is equal to its positive component `a\u207a`. -/\n@[to_additive \"If `a` is positive, then it is equal to its positive component `a\u207a`.\"]\ntheorem pos_of_one_le (a : \u03b1) (h : 1 \u2264 a) : a\u207a = a :=\n  by\n  rw [m_pos_part_def]\n  exact sup_of_le_left h\n#align lattice_ordered_comm_group.pos_of_one_le LatticeOrderedCommGroup.pos_of_one_le\n#align lattice_ordered_comm_group.pos_of_nonneg LatticeOrderedCommGroup.pos_of_nonneg\n\n/- warning: lattice_ordered_comm_group.pos_eq_self_of_one_lt_pos -> LatticeOrderedCommGroup.pos_eq_self_of_one_lt_pos is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b1] [_inst_4 : CommGroup.{u1} \u03b1] {x : \u03b1}, (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_3))))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_4)))))))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_3) _inst_4) x)) -> (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_3) _inst_4) x) x)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_3 : LinearOrder.{u1} \u03b1] [_inst_4 : CommGroup.{u1} \u03b1] {x : \u03b1}, (LT.lt.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_3)))))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_4))))))) (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_3)) _inst_4) x)) -> (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_3)) _inst_4) x) x)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_eq_self_of_one_lt_pos LatticeOrderedCommGroup.pos_eq_self_of_one_lt_pos\u2093'. -/\n-- pos_eq_self_of_pos_pos\n@[to_additive]\ntheorem pos_eq_self_of_one_lt_pos {\u03b1} [LinearOrder \u03b1] [CommGroup \u03b1] {x : \u03b1} (hx : 1 < x\u207a) :\n    x\u207a = x := by\n  rw [m_pos_part_def, right_lt_sup, not_le] at hx\n  rw [m_pos_part_def, sup_eq_left]\n  exact hx.le\n#align lattice_ordered_comm_group.pos_eq_self_of_one_lt_pos LatticeOrderedCommGroup.pos_eq_self_of_one_lt_pos\n#align lattice_ordered_comm_group.pos_eq_self_of_pos_pos LatticeOrderedCommGroup.pos_eq_self_of_pos_pos\n\n/- warning: lattice_ordered_comm_group.pos_of_le_one -> LatticeOrderedCommGroup.pos_of_le_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) -> (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) -> (Eq.{succ u1} \u03b1 (PosPart.pos.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasPosPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.pos_of_le_one LatticeOrderedCommGroup.pos_of_le_one\u2093'. -/\n-- 0 \u2264 a implies a\u207a = a\n-- pos_of_nonpos\n@[to_additive]\ntheorem pos_of_le_one (a : \u03b1) (h : a \u2264 1) : a\u207a = 1 :=\n  pos_eq_one_iff.mpr h\n#align lattice_ordered_comm_group.pos_of_le_one LatticeOrderedCommGroup.pos_of_le_one\n#align lattice_ordered_comm_group.pos_of_nonpos LatticeOrderedCommGroup.pos_of_nonpos\n\n/- warning: lattice_ordered_comm_group.neg_of_one_le_inv -> LatticeOrderedCommGroup.neg_of_one_le_inv is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a)) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a)) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_of_one_le_inv LatticeOrderedCommGroup.neg_of_one_le_inv\u2093'. -/\n@[to_additive neg_of_inv_nonneg]\ntheorem neg_of_one_le_inv (a : \u03b1) (h : 1 \u2264 a\u207b\u00b9) : a\u207b = a\u207b\u00b9 :=\n  by\n  rw [neg_eq_pos_inv]\n  exact pos_of_one_le _ h\n#align lattice_ordered_comm_group.neg_of_one_le_inv LatticeOrderedCommGroup.neg_of_one_le_inv\n#align lattice_ordered_comm_group.neg_of_inv_nonneg LatticeOrderedCommGroup.neg_of_inv_nonneg\n\n/- warning: lattice_ordered_comm_group.neg_of_inv_le_one -> LatticeOrderedCommGroup.neg_of_inv_le_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_of_inv_le_one LatticeOrderedCommGroup.neg_of_inv_le_one\u2093'. -/\n-- neg_of_neg_nonpos\n@[to_additive]\ntheorem neg_of_inv_le_one (a : \u03b1) (h : a\u207b\u00b9 \u2264 1) : a\u207b = 1 :=\n  neg_eq_one_iff'.mpr h\n#align lattice_ordered_comm_group.neg_of_inv_le_one LatticeOrderedCommGroup.neg_of_inv_le_one\n#align lattice_ordered_comm_group.neg_of_neg_nonpos LatticeOrderedCommGroup.neg_of_neg_nonpos\n\n/- warning: lattice_ordered_comm_group.neg_of_le_one -> LatticeOrderedCommGroup.neg_of_le_one is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))))) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Inv.inv.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5318 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5320 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5318 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5320) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5333 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5335 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5333 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5335)] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) a (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2)))))))) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (Inv.inv.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) a))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_of_le_one LatticeOrderedCommGroup.neg_of_le_one\u2093'. -/\n-- neg_of_nonpos\n@[to_additive]\ntheorem neg_of_le_one [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) (h : a \u2264 1) : a\u207b = a\u207b\u00b9 :=\n  by\n  refine' neg_of_one_le_inv _ _\n  rw [one_le_inv']\n  exact h\n#align lattice_ordered_comm_group.neg_of_le_one LatticeOrderedCommGroup.neg_of_le_one\n#align lattice_ordered_comm_group.neg_of_nonpos LatticeOrderedCommGroup.neg_of_nonpos\n\n/- warning: lattice_ordered_comm_group.neg_of_one_le -> LatticeOrderedCommGroup.neg_of_one_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) a) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5415 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5417 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5415 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5417) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5430 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5432 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5430 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5432)] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) a) -> (Eq.{succ u1} \u03b1 (NegPart.neg.{u1} \u03b1 (LatticeOrderedCommGroup.hasOneLatticeHasNegPart.{u1} \u03b1 _inst_1 _inst_2) a) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.neg_of_one_le LatticeOrderedCommGroup.neg_of_one_le\u2093'. -/\n-- neg_of_nonneg'\n@[to_additive]\ntheorem neg_of_one_le [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) (h : 1 \u2264 a) : a\u207b = 1 :=\n  neg_eq_one_iff.mpr h\n#align lattice_ordered_comm_group.neg_of_one_le LatticeOrderedCommGroup.neg_of_one_le\n#align lattice_ordered_comm_group.neg_of_nonneg LatticeOrderedCommGroup.neg_of_nonneg\n\n/- warning: lattice_ordered_comm_group.mabs_of_one_le -> LatticeOrderedCommGroup.mabs_of_one_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (OfNat.mk.{u1} \u03b1 1 (One.one.{u1} \u03b1 (MulOneClass.toHasOne.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))))) a) -> (Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5474 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5476 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5474 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5476) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5489 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5491 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5489 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5491)] (a : \u03b1), (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (OfNat.ofNat.{u1} \u03b1 1 (One.toOfNat1.{u1} \u03b1 (InvOneClass.toOne.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))))) a) -> (Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.mabs_of_one_le LatticeOrderedCommGroup.mabs_of_one_le\u2093'. -/\n-- 0 \u2264 a implies |a| = a\n@[to_additive abs_of_nonneg]\ntheorem mabs_of_one_le [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) (h : 1 \u2264 a) : |a| = a :=\n  by\n  unfold Abs.abs\n  rw [sup_eq_mul_pos_div, div_eq_mul_inv, inv_inv, \u2190 pow_two, inv_mul_eq_iff_eq_mul, \u2190 pow_two,\n    pos_of_one_le]\n  rw [pow_two]\n  apply one_le_mul h h\n#align lattice_ordered_comm_group.mabs_of_one_le LatticeOrderedCommGroup.mabs_of_one_le\n#align lattice_ordered_comm_group.abs_of_nonneg LatticeOrderedCommGroup.abs_of_nonneg\n\n/- warning: lattice_ordered_comm_group.mabs_mabs -> LatticeOrderedCommGroup.mabs_mabs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1), Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5600 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5602 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5600 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5602) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5615 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5617 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5615 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5617)] (a : \u03b1), Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a)\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.mabs_mabs LatticeOrderedCommGroup.mabs_mabs\u2093'. -/\n/-- The unary operation of taking the absolute value is idempotent. -/\n@[simp, to_additive abs_abs \"The unary operation of taking the absolute value is idempotent.\"]\ntheorem mabs_mabs [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a : \u03b1) : ||a|| = |a| :=\n  mabs_of_one_le _ (one_le_abs _)\n#align lattice_ordered_comm_group.mabs_mabs LatticeOrderedCommGroup.mabs_mabs\n#align lattice_ordered_comm_group.abs_abs LatticeOrderedCommGroup.abs_abs\n\n/- warning: lattice_ordered_comm_group.mabs_sup_div_sup_le_mabs -> LatticeOrderedCommGroup.mabs_sup_div_sup_le_mabs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1) (c : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a c) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5665 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5667 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5665 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5667) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5680 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5682 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5680 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5682)] (a : \u03b1) (b : \u03b1) (c : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a c) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.mabs_sup_div_sup_le_mabs LatticeOrderedCommGroup.mabs_sup_div_sup_le_mabs\u2093'. -/\n@[to_additive abs_sup_sub_sup_le_abs]\ntheorem mabs_sup_div_sup_le_mabs [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b c : \u03b1) :\n    |(a \u2294 c) / (b \u2294 c)| \u2264 |a / b| :=\n  by\n  apply le_of_mul_le_of_one_le_left\n  \u00b7 rw [abs_div_sup_mul_abs_div_inf]\n  \u00b7 exact one_le_abs _\n#align lattice_ordered_comm_group.mabs_sup_div_sup_le_mabs LatticeOrderedCommGroup.mabs_sup_div_sup_le_mabs\n#align lattice_ordered_comm_group.abs_sup_sub_sup_le_abs LatticeOrderedCommGroup.abs_sup_sub_sup_le_abs\n\n/- warning: lattice_ordered_comm_group.mabs_inf_div_inf_le_mabs -> LatticeOrderedCommGroup.mabs_inf_div_inf_le_mabs is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1) (c : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a c) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5772 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5774 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5772 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5774) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5787 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5789 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5787 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5789)] (a : \u03b1) (b : \u03b1) (c : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a c) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.mabs_inf_div_inf_le_mabs LatticeOrderedCommGroup.mabs_inf_div_inf_le_mabs\u2093'. -/\n@[to_additive abs_inf_sub_inf_le_abs]\ntheorem mabs_inf_div_inf_le_mabs [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b c : \u03b1) :\n    |(a \u2293 c) / (b \u2293 c)| \u2264 |a / b| :=\n  by\n  apply le_of_mul_le_of_one_le_right\n  \u00b7 rw [abs_div_sup_mul_abs_div_inf]\n  \u00b7 exact one_le_abs _\n#align lattice_ordered_comm_group.mabs_inf_div_inf_le_mabs LatticeOrderedCommGroup.mabs_inf_div_inf_le_mabs\n#align lattice_ordered_comm_group.abs_inf_sub_inf_le_abs LatticeOrderedCommGroup.abs_inf_sub_inf_le_abs\n\n/- warning: lattice_ordered_comm_group.m_Birkhoff_inequalities -> LatticeOrderedCommGroup.m_Birkhoff_inequalities is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1) (c : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a c) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a c) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) b c)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5879 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5881 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5879 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5881) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5894 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5896 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5894 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5896)] (a : \u03b1) (b : \u03b1) (c : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a c) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) b c))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a c) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) b c)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.m_Birkhoff_inequalities LatticeOrderedCommGroup.m_Birkhoff_inequalities\u2093'. -/\n-- Commutative case, Zaanen, 3rd lecture\n-- For the non-commutative case, see Birkhoff Theorem 19 (27)\n-- |(a \u2294 c) - (b \u2294 c)| \u2294 |(a \u2293 c) - (b \u2293 c)| \u2264 |a - b|\n@[to_additive Birkhoff_inequalities]\ntheorem m_Birkhoff_inequalities [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b c : \u03b1) :\n    |(a \u2294 c) / (b \u2294 c)| \u2294 |(a \u2293 c) / (b \u2293 c)| \u2264 |a / b| :=\n  sup_le (mabs_sup_div_sup_le_mabs a b c) (mabs_inf_div_inf_le_mabs a b c)\n#align lattice_ordered_comm_group.m_Birkhoff_inequalities LatticeOrderedCommGroup.m_Birkhoff_inequalities\n#align lattice_ordered_comm_group.Birkhoff_inequalities LatticeOrderedCommGroup.Birkhoff_inequalities\n\n/- warning: lattice_ordered_comm_group.mabs_mul_le -> LatticeOrderedCommGroup.mabs_mul_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5991 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5993 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5991 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.5993) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6006 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6008 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6006 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6008)] (a : \u03b1) (b : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) a b)) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) b))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.mabs_mul_le LatticeOrderedCommGroup.mabs_mul_le\u2093'. -/\n-- Banasiak Proposition 2.12, Zaanen 2nd lecture\n/-- The absolute value satisfies the triangle inequality.\n-/\n@[to_additive abs_add_le \"The absolute value satisfies the triangle inequality.\"]\ntheorem mabs_mul_le [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) : |a * b| \u2264 |a| * |b| :=\n  by\n  apply sup_le\n  \u00b7 exact mul_le_mul' (le_mabs a) (le_mabs b)\n  \u00b7 rw [mul_inv]\n    exact mul_le_mul' (inv_le_abs _) (inv_le_abs _)\n#align lattice_ordered_comm_group.mabs_mul_le LatticeOrderedCommGroup.mabs_mul_le\n#align lattice_ordered_comm_group.abs_add_le LatticeOrderedCommGroup.abs_add_le\n\n/- warning: lattice_ordered_comm_group.abs_inv_comm -> LatticeOrderedCommGroup.abs_inv_comm is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] (a : \u03b1) (b : \u03b1), Eq.{succ u1} \u03b1 (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b)) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) b a))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.abs_inv_comm LatticeOrderedCommGroup.abs_inv_comm\u2093'. -/\n-- |a - b| = |b - a|\n@[to_additive]\ntheorem abs_inv_comm (a b : \u03b1) : |a / b| = |b / a| :=\n  by\n  unfold Abs.abs\n  rw [inv_div a b, \u2190 inv_inv (a / b), inv_div, sup_comm]\n#align lattice_ordered_comm_group.abs_inv_comm LatticeOrderedCommGroup.abs_inv_comm\n#align lattice_ordered_comm_group.abs_neg_comm LatticeOrderedCommGroup.abs_neg_comm\n\n/- warning: lattice_ordered_comm_group.abs_abs_div_abs_le -> LatticeOrderedCommGroup.abs_abs_div_abs_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toHasMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))))))) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))))] (a : \u03b1) (b : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) b))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (DivInvMonoid.toHasInv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2))) (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toHasDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] [_inst_2 : CommGroup.{u1} \u03b1] [_inst_3 : CovariantClass.{u1, u1} \u03b1 \u03b1 (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6182 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6184 : \u03b1) => HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulOneClass.toMul.{u1} \u03b1 (Monoid.toMulOneClass.{u1} \u03b1 (DivInvMonoid.toMonoid.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6182 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6184) (fun (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6197 : \u03b1) (x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6199 : \u03b1) => LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6197 x._@.Mathlib.Algebra.Order.LatticeGroup._hyg.6199)] (a : \u03b1) (b : \u03b1), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) a) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) b))) (Abs.abs.{u1} \u03b1 (Inv.toHasAbs.{u1} \u03b1 (InvOneClass.toInv.{u1} \u03b1 (DivInvOneMonoid.toInvOneClass.{u1} \u03b1 (DivisionMonoid.toDivInvOneMonoid.{u1} \u03b1 (DivisionCommMonoid.toDivisionMonoid.{u1} \u03b1 (CommGroup.toDivisionCommMonoid.{u1} \u03b1 _inst_2))))) (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1))) (HDiv.hDiv.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHDiv.{u1} \u03b1 (DivInvMonoid.toDiv.{u1} \u03b1 (Group.toDivInvMonoid.{u1} \u03b1 (CommGroup.toGroup.{u1} \u03b1 _inst_2)))) a b))\nCase conversion may be inaccurate. Consider using '#align lattice_ordered_comm_group.abs_abs_div_abs_le LatticeOrderedCommGroup.abs_abs_div_abs_le\u2093'. -/\n-- | |a| - |b| | \u2264 |a - b|\n@[to_additive]\ntheorem abs_abs_div_abs_le [CovariantClass \u03b1 \u03b1 (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] (a b : \u03b1) : ||a| / |b|| \u2264 |a / b| :=\n  by\n  unfold Abs.abs\n  rw [sup_le_iff]\n  constructor\n  \u00b7 apply div_le_iff_le_mul.2\n    convert mabs_mul_le (a / b) b\n    \u00b7 rw [div_mul_cancel']\n    \u00b7 rw [div_mul_cancel']\n    \u00b7 exact covariant_swap_mul_le_of_covariant_mul_le \u03b1\n  \u00b7 rw [div_eq_mul_inv, mul_inv_rev, inv_inv, mul_inv_le_iff_le_mul, \u2190 abs_eq_sup_inv (a / b),\n      abs_inv_comm]\n    convert mabs_mul_le (b / a) a\n    \u00b7 rw [div_mul_cancel']\n    \u00b7 rw [div_mul_cancel']\n#align lattice_ordered_comm_group.abs_abs_div_abs_le LatticeOrderedCommGroup.abs_abs_div_abs_le\n#align lattice_ordered_comm_group.abs_abs_sub_abs_le LatticeOrderedCommGroup.abs_abs_sub_abs_le\n\nend LatticeOrderedCommGroup\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Order/LatticeGroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7082689316409965}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport order.zorn\nimport order.atoms\n\n/-!\n# Zorn lemma for (co)atoms\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we use Zorn's lemma to prove that a partial order is atomic if every nonempty chain\n`c`, `\u22a5 \u2209 c`, has a lower bound not equal to `\u22a5`. We also prove the order dual version of this\nstatement.\n-/\n\nopen set\n\n/-- **Zorn's lemma**: A partial order is coatomic if every nonempty chain `c`, `\u22a4 \u2209 c`, has an upper\nbound not equal to `\u22a4`. -/\nlemma is_coatomic.of_is_chain_bounded {\u03b1 : Type*} [partial_order \u03b1] [order_top \u03b1]\n  (h : \u2200 c : set \u03b1, is_chain (\u2264) c \u2192 c.nonempty \u2192 \u22a4 \u2209 c \u2192 \u2203 x \u2260 \u22a4, x \u2208 upper_bounds c) :\n  is_coatomic \u03b1 :=\nbegin\n  refine \u27e8\u03bb x, le_top.eq_or_lt.imp_right $ \u03bb hx, _\u27e9,\n  rcases zorn_nonempty_partial_order\u2080 (Ico x \u22a4) (\u03bb c hxc hc y hy, _) x (left_mem_Ico.2 hx)\n    with \u27e8y, \u27e8hxy, hy\u27e9, -, hy'\u27e9,\n  { refine \u27e8y, \u27e8hy.ne, \u03bb z hyz, le_top.eq_or_lt.resolve_right $ \u03bb hz, _\u27e9, hxy\u27e9,\n    exact hyz.ne' (hy' z \u27e8hxy.trans hyz.le, hz\u27e9 hyz.le) },\n  { rcases h c hc \u27e8y, hy\u27e9 (\u03bb h, (hxc h).2.ne rfl) with \u27e8z, hz, hcz\u27e9,\n    exact \u27e8z, \u27e8le_trans (hxc hy).1 (hcz hy), hz.lt_top\u27e9, hcz\u27e9 }\nend\n\n/-- **Zorn's lemma**: A partial order is atomic if every nonempty chain `c`, `\u22a5 \u2209 c`, has an lower\nbound not equal to `\u22a5`. -/\nlemma is_atomic.of_is_chain_bounded {\u03b1 : Type*} [partial_order \u03b1] [order_bot \u03b1]\n  (h : \u2200 c : set \u03b1, is_chain (\u2264) c \u2192 c.nonempty \u2192 \u22a5 \u2209 c \u2192 \u2203 x \u2260 \u22a5, x \u2208 lower_bounds c) :\n  is_atomic \u03b1 :=\nis_coatomic_dual_iff_is_atomic.mp $ is_coatomic.of_is_chain_bounded $ \u03bb c hc, h c hc.symm\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/zorn_atoms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7082689311942922}}
{"text": "theorem impNot {p q : Prop} : p \u2192 \u00ac q \u2194 \u00ac (p \u2227 q) := \n  \u27e8 \u03bb hpq h => hpq h.1 h.2, \u03bb h hp hq => h <| And.intro hp hq \u27e9  \n\ntheorem Exists.impNot {p q : \u03b1 \u2192 Prop} : (\u2203 x, p x \u2192 \u00ac q x) \u2194 \u2203 x, \u00ac (p x \u2227 q x) := by \n  apply Iff.intro\n  intro h\n  cases h with | intro x hx => \n  { exact \u27e8 x, \u03bb hs => hx hs.1 hs.2 \u27e9 }\n  intro h \n  cases h with | intro x hx => \n  { exact \u27e8 x, \u03bb hpx hqx => hx <| And.intro hpx hqx \u27e9 }\n\nnamespace Classical\n\ntheorem contrapositive {p q : Prop} : (\u00ac q \u2192 \u00ac p) \u2192 p \u2192 q := \n  \u03bb hqp hp => match em q with \n    | Or.inl h => h\n    | Or.inr h => False.elim <| hqp h hp\n  \ntheorem notNot {p : Prop} : \u00ac \u00ac p \u2194 p := by \n  apply Iff.intro\n  { intro hp; cases em p with \n    | inl   => assumption\n    | inr h => exact False.elim <| hp h }\n  { exact \u03bb hp hnp => False.elim <| hnp hp }\n\ntheorem notForall {p : \u03b1 \u2192 Prop} : (\u00ac \u2200 x, p x) \u2192 \u2203 x, \u00ac p x := by \n  { apply contrapositive; intro hx; rw notNot; intro x;\n    cases em (p x); { assumption }\n      { apply False.elim <| hx <| Exists.intro x _; assumption } }  \n\ntheorem notAnd {p q : Prop} : p \u2227 \u00ac q \u2194 \u00ac (p \u2192 q) := by\n  apply Iff.intro\n  { exact \u03bb h himp => h.2 <| himp h.1 }\n  { intro h; apply And.intro;\n    { revert h; apply contrapositive; rw notNot;\n      exact \u03bb hnp hp => False.elim <| hnp hp }\n    { exact \u03bb hq => h <| \u03bb _ => hq } }\n\ntheorem Exists.notAnd {p q : \u03b1 \u2192 Prop} : \n  (\u2203 x, p x \u2227 \u00ac q x) \u2194 \u2203 x, \u00ac (p x \u2192 q x) := by\n  apply Iff.intro\n  { intro h;\n    let \u27e8 x, \u27e8 hp, hnq \u27e9 \u27e9 := h;\n    exact Exists.intro x \u03bb h => hnq <| h hp }\n  { intro h;\n    let \u27e8 x, hx \u27e9 := h;\n    apply Exists.intro x;\n    apply And.intro;\n    { revert hx; apply contrapositive;\n      exact \u03bb hpx hpq => hpq \u03bb hp => False.elim <| hpx hp }\n    { intro foo;\n      apply hx;\n      intro bar;\n      assumption; } }\n\nend Classical\n\ndef Set (\u03b1 : Type u) := \u03b1 \u2192 Prop\n\ndef setOf (p : \u03b1 \u2192 Prop) : Set \u03b1 := p\n\nnamespace Set\n\ninstance : EmptyCollection (Set \u03b1) := \u27e8 \u03bb x => False \u27e9 \n\nvariable {zzz : Type u}\n\nvariable {\u03b1 : Type u}\nvariable {s : Set \u03b1}\n\ndef mem (a : \u03b1) (s : Set \u03b1) := s a\n\ninfix:55 \"\u2208\" => Set.mem\nnotation:55 x \"\u2209\" s => \u00ac x \u2208 s\n\ninstance : CoeSort (Set \u03b1) (Type u) where \n  coe s := Subtype s\n\ntheorem ext {s t : Set \u03b1} (h : \u2200 x, x \u2208 s \u2194 x \u2208 t) : s = t := \n  funext <| \u03bb x => propext <| h x\n\n-- Declaring the index category\ndeclare_syntax_cat index\nsyntax ident : index\nsyntax ident \":\" term : index \nsyntax ident \"\u2208\" term : index\n\n-- Notation for sets\nsyntax \"{\" index \"|\" term \"}\" : term\n\nmacro_rules \n| `({ $x:ident : $t | $p }) => `(setOf (\u03bb ($x:ident : $t) => $p))\n| `({ $x:ident | $p }) => `(setOf (\u03bb ($x:ident) => $p))\n| `({ $x:ident \u2208 $s | $p }) => `(setOf (\u03bb $x => $x \u2208 $s \u2192 $p))\n\ndef union (s t : Set \u03b1) : Set \u03b1 := { x : \u03b1 | x \u2208 s \u2228 x \u2208 t } \n\ndef inter (s t : Set \u03b1) : Set \u03b1 := { x : \u03b1 | x \u2208 s \u2227 x \u2208 t }\n\ntheorem unionDef (s t : Set \u03b1) : union s t = \u03bb x => s x \u2228 t x := rfl\n\ntheorem interDef (s t : Set \u03b1) : inter s t = \u03bb x => s x \u2227 t x := rfl\n\ninfix:60 \"\u222a\" => Set.union\ninfix:60 \"\u2229\" => Set.inter\n\ndef Union (s : Set (Set \u03b1)) : Set \u03b1 := { x : \u03b1 | \u2203 t : Set \u03b1, t \u2208 s \u2192 t x }\n\ndef Inter (s : Set (Set \u03b1)) : Set \u03b1 := { x : \u03b1 | \u2200 t : Set \u03b1, t \u2208 s \u2192 t x }\n\ndef UnionDef (s : Set (Set \u03b1)) : Union s = \u03bb x => \u2203 t : Set \u03b1, t \u2208 s \u2192 t x := rfl\n\ndef InterDef (s : Set (Set \u03b1)) : Inter s = \u03bb x => \u2200 t : Set \u03b1, t \u2208 s \u2192 t x := rfl\n\nsyntax \"\u22c3\" index \",\" term : term\nsyntax \"\u22c2\" index \",\" term : term\n\nmacro_rules\n| `(\u22c3 $s:ident \u2208 $c, $s) => `(Union $c)\n| `(\u22c2 $s:ident \u2208 $c, $s) => `(Inter $c)\n\n-- variables {s : Set (Set \u03b1)}\n\n-- #check \u22c2 t \u2208 s, t\n\n-- Notation for \u2200 x \u2208 s, p and \u2203 x \u2208 s, p\nsyntax \"\u2200\" index \",\" term : term\nsyntax \"\u2203\" index \",\" term : term\n\nmacro_rules\n| `(\u2200 $x:ident \u2208 $s, $p) => `(\u2200 $x:ident, $x \u2208 $s \u2192 $p)\n| `(\u2203 $x:ident \u2208 $s, $p) => `(\u2203 $x:ident, $x \u2208 $s \u2227 $p)\n\ndef Subset (s t : Set \u03b1) := \u2200 x \u2208 s, x \u2208 t\n\ninfix:50 \"\u2286\" => Subset\n\ntheorem Subset.def {s t : Set \u03b1} : s \u2286 t \u2194 \u2200 x \u2208 s, x \u2208 t := Iff.rfl\n\nnamespace Subset\n\ntheorem refl {s : Set \u03b1} : s \u2286 s := \u03bb _ hx => hx\n\ntheorem trans {s t v : Set \u03b1} (hst : s \u2286 t) (htv : t \u2286 v) : s \u2286 t := \n  \u03bb x hx => hst x hx\n\ntheorem antisymm {s t : Set \u03b1} (hst : s \u2286 t) (hts : t \u2286 s) : s = t := \n  Set.ext \u03bb x => \u27e8 \u03bb hx => hst x hx, \u03bb hx => hts x hx \u27e9\n\ntheorem antisymmIff {s t : Set \u03b1} : s = t \u2194 s \u2286 t \u2227 t \u2286 s :=\n  \u27e8 by { intro hst; subst hst; exact \u27e8 refl, refl \u27e9 }, \n    \u03bb \u27e8 hst, hts \u27e9 => antisymm hst hts \u27e9 \n\n-- \u2193 Uses classical logic\ntheorem notSubset : \u00ac s \u2286 t \u2194 \u2203 x \u2208 s, x \u2209 t := by \n  apply Iff.intro;\n  { intro hst; \n    rw Classical.Exists.notAnd;\n    apply Classical.notForall;\n    exact \u03bb h => hst \u03bb x hx => h x hx }\n  { intro h hst;\n    let \u27e8 x, \u27e8 hxs, hxt \u27e9 \u27e9 := h;\n    exact hxt <| hst x hxs }\n\nend Subset\n\ntheorem memEmptySet {x : \u03b1} (h : x \u2208 \u2205) : False := h\n\n@[simp] theorem memEmptySetIff : (\u2203 (x : \u03b1), x \u2208 \u2205) \u2194 False := \n  Iff.intro (\u03bb h => h.2) False.elim \n\n@[simp] theorem setOfFalse : { a : \u03b1 | False } = \u2205 := rfl\n\ndef univ : Set \u03b1 := { x | True }\n\n@[simp] theorem memUniv (x : \u03b1) : x \u2208 univ := True.intro\n\ntheorem Subset.subsetUniv {s : Set \u03b1} : s \u2286 univ := \u03bb x _ => memUniv x \n\ntheorem Subset.univSubsetIff {s : Set \u03b1} : univ \u2286 s \u2194 univ = s := by\n  apply Iff.intro \u03bb hs => Subset.antisymm hs Subset.subsetUniv \n  { intro h; subst h; exact Subset.refl }\n\ntheorem eqUnivIff {s : Set \u03b1} : s = univ \u2194 \u2200 x, x \u2208 s := by \n  apply Iff.intro \n  { intro h x; subst h; exact memUniv x }\n  { exact \u03bb h => ext \u03bb x => Iff.intro (\u03bb _ => memUniv _) \u03bb _ => h x }\n\n/-! ### Unions and Intersections -/\n\nmacro \"extia\" x:term : tactic => `(tactic| apply ext; intro $x; apply Iff.intro)\n\ntheorem unionSelf {s : Set \u03b1} : s \u222a s = s := by \n  extia x\n  { intro hx; cases hx; assumption; assumption }\n  { exact Or.inl }\n\ntheorem unionEmpty {s : Set \u03b1} : s \u222a \u2205 = s := by \n  extia x\n  { intro hx; cases hx with \n    | inl   => assumption\n    | inr h => exact False.elim <| memEmptySet h }\n  { exact Or.inl }\n\ntheorem unionSymm {s t : Set \u03b1} : s \u222a t = t \u222a s := by \n  extia x \n  allGoals { intro hx; cases hx with \n             | inl hx => exact Or.inr hx\n             | inr hx => exact Or.inl hx }\n\ntheorem emptyUnion {s : Set \u03b1} : \u2205 \u222a s = s := by \n  rw unionSymm; exact unionEmpty\n\ntheorem unionAssoc {s t w : Set \u03b1} : s \u222a t \u222a w = s \u222a (t \u222a w) := by \n  extia x\n  { intro hx; cases hx with \n    | inr hx   => exact Or.inr <| Or.inr hx\n    | inl hx   => cases hx with \n      | inr hx => exact Or.inr <| Or.inl hx\n      | inl hx => exact Or.inl hx }\n  { intro hx; cases hx with \n    | inl hx   => exact Or.inl <| Or.inl hx\n    | inr hx   => cases hx with \n      | inr hx => exact Or.inr hx\n      | inl hx => exact Or.inl <| Or.inr hx }\n\nend Set", "meta": {"author": "kbuzzard", "repo": "lean4-filters", "sha": "29f90055b7a2341c86d924954463c439bd128fb7", "save_path": "github-repos/lean/kbuzzard-lean4-filters", "path": "github-repos/lean/kbuzzard-lean4-filters/lean4-filters-29f90055b7a2341c86d924954463c439bd128fb7/other_peoples_work/jason_set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7082689229888378}}
{"text": "import linear_algebra.finsupp\n\nopen linear_map\n\nvariables {R : Type*} {M : Type*} {M\u2082 : Type*} {M\u2083 : Type*}\nvariables [ring R] [add_comm_group M] [add_comm_group M\u2082] [add_comm_group M\u2083]\nvariables [module R M] [module R M\u2082] [module R M\u2083]\nvariables {\u03b1 : Type*} (v : \u03b1 \u2192 M)\n\n/-- Given 2 surjective R-module homs `f : M \u2192\u2097[R] M\u2082, g : M\u2082 \u2192\u2097[R] M\u2083`, `g \u2218 f` is surjective.  -/\ntheorem range_eq_top_comp {f : M \u2192\u2097[R] M\u2082} {g : M\u2082 \u2192\u2097[R] M\u2083} (hf : range f = \u22a4)\n  (hg : range g = \u22a4) : range (g.comp f) = \u22a4 :=\nby rw [range_comp, hf, \u2190hg]; refl\n\n/-- Given 2 injective R-module homs `f : M \u2192\u2097[R] M\u2082, g : M\u2082 \u2192\u2097[R] M\u2083`, `g \u2218 f` is injective.-/\ntheorem ker_eq_bot_comp {f : M \u2192\u2097[R] M\u2082} {g : M\u2082 \u2192\u2097[R] M\u2083} (hf : f.ker = \u22a5) (hg : g.ker = \u22a5) :\n  ker (g.comp f) = \u22a5 :=\nby rw [ker_comp, hg, \u2190hf]; refl\n", "meta": {"author": "101damnations", "repo": "fg_over_pid", "sha": "a1a587c455a54a802f6ff61b07bb033701e451a7", "save_path": "github-repos/lean/101damnations-fg_over_pid", "path": "github-repos/lean/101damnations-fg_over_pid/fg_over_pid-a1a587c455a54a802f6ff61b07bb033701e451a7/src/mathlib_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7082598658469839}}
{"text": "/-\nCopyright (c) 2021 Gabriel Moise. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Gabriel Moise.\n-/\n\nimport data.complex.basic\nimport data.complex.module\nimport data.fintype.basic\nimport data.real.basic\nimport linear_algebra.matrix\n\n/-!\n# Symmetric Matrices\nThis module defines symmetric matrices, together with key properties about their eigenvalues & eigenvectors.\nIt uses a more restrictive definition of eigenvalues & eigenvectors, together with helping lemmas for vector-matrix\noperations and tools for complex numbers/vectors.\nTODO : make the eigen-definitions consistent with the ones already defined in linear_algebra.eigenspace\n## Main definitions\n* `vec_conj x` - the complex conjugate of a complex vector `x`\n* `vec_re x` - the vector containing the real parts of elements from x\n* `vec_im x` - the vector containing the imaginary parts of elements from x\n* `has_eigenpair M \u03bc x` - matrix `M` has non-zero eigenvector `x` with corresponding eigenvalue `\u03bc`\n* `has_eigenvector M x` - matrix `M` has non-zero eigenvector `x`\n* `has_eigenvalue M \u03bc`  - matrix `M` has eigenvalue `\u03bc`\n* `symm_matrix M` - `M` is a symmetric matrix\n## Main statements\n1. If x is an eigenvector of matrix M, then a \u2022 x is an eigenvector of M, for any non-zero a : \u2102.\n2. If there are two eigenvectors of M that have the same correspoding eigenvalue, then any linear combination of them\nis also an eigenvector of M with the same eigenvalue \u03bc.\n3. All eigenvalues of a symmetric real matrix M are real.\n4. For every real eigenvalue of a symmetric matrix M, there exists a corresponding real-valued eigenvector.\n5. If v and w are eigenvectors of a symmetric matrix M with different eigenvalues, then v and w are orthogonal.\n## References\n<https://www.doc.ic.ac.uk/~ae/papers/lecture05.pdf>\n<https://sharmaeklavya2.github.io/theoremdep/nodes/linear-algebra/eigenvectors/real-matrix-with-real-eigenvalue-has-real-eigenvectors.html>\n-/\n\nopen_locale matrix big_operators\nopen_locale complex_conjugate\nopen fintype finset matrix complex\n\nuniverses u\nvariables {\u03b1 : Type u}\nvariables {m n : Type*} [fintype m] [fintype n]\n\nlemma vec_eq_unfold (x y : n \u2192 \u03b1) : (\u03bb i : n, x i) = (\u03bb i : n, y i) \u2194 \u2200 i : n, x i = y i :=\nbegin\n  split,\n  { intros hyp i, exact congr_fun hyp i },\n  { intro hyp, ext, apply hyp }\nend\n\n-- ## Coercions\ninstance : has_coe (n \u2192 \u211d) (n \u2192 \u2102) := \u27e8\u03bb x, (\u03bb i, \u27e8x i, 0\u27e9)\u27e9\ninstance : has_coe (matrix m n \u211d) (matrix m n \u2102) := \u27e8\u03bb M, (\u03bb i j, \u27e8M i j, 0\u27e9)\u27e9\n\n-- ## Lemmas on \u2102\n\nlemma conj_of_zero_im {\u03bc : \u2102} (H_im : \u03bc.im = 0) : conj \u03bc = \u03bc :=\nby { ext; simp only [conj_re, conj_im, H_im, neg_zero] }\n\nlemma sum_complex_re {x : n \u2192 \u2102} : (\u2211 i : n, x i).re = \u2211 i : n, (x i).re := by exact complex.re_lm.map_sum\n\nlemma sum_complex_im {x : n \u2192 \u2102} : (\u2211 i : n, x i).im = \u2211 i : n, (x i).im := by exact complex.im_lm.map_sum\n\n-- The real and complex parts of a complex vector\ndef vec_re (x : n \u2192 \u2102) : n \u2192 \u211d := \u03bb i : n, (x i).re\ndef vec_im (x : n \u2192 \u2102) : n \u2192 \u211d := \u03bb i : n, (x i).im\n\n-- Defining the complex conjugate of a complex vector\nsection vec_conj\n\ndef vec_conj (x : n \u2192 \u2102) : n \u2192 \u2102 := \u03bb i : n, conj (x i)\n\n-- (\u03bc \u2022 x)* = \u03bc* \u2022 x*\nlemma vec_conj_smul (\u03bc : \u2102) (x : n \u2192 \u2102) :\n  vec_conj (\u03bc \u2022 x) = (conj \u03bc) \u2022 (vec_conj x) :=\nby { ext ; simp only [vec_conj, algebra.id.smul_eq_mul, pi.smul_apply, ring_hom.map_mul] }\n\n-- \u2191A i j = \u2191(A i j)\nlemma coe_matrix_coe_elem (i : m) (j : n) (A : matrix m n \u211d) : (A : matrix m n \u2102) i j = \u2191(A i j) := by exact rfl\n\n-- (A \u2b1d x)* = A \u2b1d x*\nlemma vec_conj_mul_vec [decidable_eq n] [nonempty n] (A : matrix m n \u211d) (x : n \u2192 \u2102) :\n  vec_conj ((A : matrix m n \u2102).mul_vec x) = (A : matrix m n \u2102).mul_vec (vec_conj x) :=\nbegin\n  ext,\n  simp only [vec_conj, mul_vec, dot_product, conj_re, coe_matrix_coe_elem, sum_complex_re, mul_re, of_real_im, zero_mul],\n  simp only [vec_conj, mul_vec, dot_product, conj_im, coe_matrix_coe_elem, sum_complex_im, mul_im, add_zero, of_real_im,\n    zero_mul, sum_neg_distrib],\nend\n\nlemma vec_norm_sq_zero {x : n \u2192 \u2102} (H_dot : dot_product (vec_conj x) x = 0) : x = 0 :=\nbegin\n  unfold dot_product at H_dot,\n  simp only [vec_conj, mul_comm, mul_conj, complex.ext_iff, sum_complex_re, zero_re, of_real_re] at H_dot,\n  cases H_dot with H_re H_im,\n  have key : \u2211 i in (univ : finset n), norm_sq (x i) = 0 \u2194 \u2200 i \u2208 (univ : finset n), norm_sq(x i) = 0,\n  { apply sum_eq_zero_iff_of_nonneg, intros i h_univ, exact norm_sq_nonneg (x i) },\n  simp only [forall_prop_of_true, mem_univ, monoid_with_zero_hom.map_eq_zero] at key,\n  rw key at H_re,\n  ext i;\n  { specialize H_re i, simp only [H_re, pi.zero_apply] }\nend\n\nlemma coe_vec_re (x : n \u2192 \u2102) {i : n} : (vec_re x : n \u2192 \u2102) i = ((x i).re : \u2102) :=\nby simpa only [vec_re]\n\nlemma vec_add_conj_eq_two_re (x : n \u2192 \u2102) : x + vec_conj x = (2 : \u2102) \u2022 (vec_re x : n \u2192 \u2102) :=\nbegin\n  ext,\n  { simp [vec_conj, coe_vec_re x], linarith },\n  { simp [vec_conj, coe_vec_re x] }\nend\n\nlemma vec_conj_add_zero {x : n \u2192 \u2102} (H : x + vec_conj x = 0) : vec_re x = 0 :=\nbegin\n  rw [vec_add_conj_eq_two_re, smul_eq_zero] at H,\n  cases H with H_20 H_x,\n  { exfalso, simp at H_20, assumption }, -- 2 = 0\n  { rw function.funext_iff at H_x,\n    ext i,\n    specialize H_x i,\n    rw coe_vec_re at H_x,\n    simp only [of_real_eq_zero, pi.zero_apply] at H_x,\n    simp only [vec_re, H_x, pi.zero_apply] }\nend\n\nend vec_conj\n\nnamespace matrix\n\nvariables (M : matrix n n \u2102)\n\ndef Coe (M : matrix m n \u211d) := (M : matrix m n \u2102)\n\n-- Defining the complex conjugate of a complex matrix\nsection mat_conj\n\ndef mat_conj (x : matrix m n \u2102) : matrix m n \u2102 := \u03bb i: m, (\u03bb j : n, conj (x i j))\n\n-- (M*)* = M\nlemma mat_conj_conj_eq_mat (x : matrix m n \u2102) :\n  mat_conj (mat_conj x) = x :=\nby { ext, unfold mat_conj, simp, unfold mat_conj, simp, }\n\n\n-- (\u03bc \u2022 M)* = \u03bc* \u2022 M*\nlemma mat_conj_smul (\u03bc : \u2102) (x : matrix n n \u2102) :\n  mat_conj (\u03bc \u2022 x) = (conj \u03bc) \u2022 (mat_conj x) :=\nby { ext ; simp only [mat_conj, algebra.id.smul_eq_mul, pi.smul_apply, ring_hom.map_mul] }\n\n-- (A \u2b1d x)* = A* \u2b1d x*\nlemma vec_conj_mul_vec [decidable_eq n] [nonempty n] (A : matrix m n \u2102) (x : n \u2192 \u2102) :\n  vec_conj ((A : matrix m n \u2102).mul_vec x) = (mat_conj A : matrix m n \u2102).mul_vec (vec_conj x) :=\nbegin\n  ext,\n  simp only [mat_conj, vec_conj, mul_vec, dot_product, conj_re, coe_matrix_coe_elem, sum_complex_re, mul_re, of_real_im, zero_mul],\n  simp only [mat_conj, vec_conj, mul_vec, dot_product, conj_im, coe_matrix_coe_elem, sum_complex_im, mul_im, add_zero, of_real_im,\n    zero_mul, sum_neg_distrib, mul_neg_eq_neg_mul_symm],\n    sorry\nend\n\nlemma vec_norm_sq_zero {x : n \u2192 \u2102} (H_dot : dot_product (vec_conj x) x = 0) : x = 0 :=\nbegin\n  unfold dot_product at H_dot,\n  simp only [vec_conj, mul_comm, mul_conj, complex.ext_iff, sum_complex_re, zero_re, of_real_re] at H_dot,\n  cases H_dot with H_re H_im,\n  have key : \u2211 i in (univ : finset n), norm_sq (x i) = 0 \u2194 \u2200 i \u2208 (univ : finset n), norm_sq(x i) = 0,\n  { apply sum_eq_zero_iff_of_nonneg, intros i h_univ, exact norm_sq_nonneg (x i) },\n  simp only [forall_prop_of_true, mem_univ, monoid_with_zero_hom.map_eq_zero] at key,\n  rw key at H_re,\n  ext i;\n  { specialize H_re i, simp only [H_re, pi.zero_apply] }\nend\n\nlemma coe_vec_re (x : n \u2192 \u2102) {i : n} : (vec_re x : n \u2192 \u2102) i = ((x i).re : \u2102) :=\nby simpa only [vec_re]\n\nlemma vec_add_conj_eq_two_re (x : n \u2192 \u2102) : x + vec_conj x = (2 : \u2102) \u2022 (vec_re x : n \u2192 \u2102) :=\nbegin\n  ext,\n  { simp [vec_conj, coe_vec_re x], linarith },\n  { simp [vec_conj, coe_vec_re x] }\nend\n\nlemma vec_conj_add_zero {x : n \u2192 \u2102} (H : x + vec_conj x = 0) : vec_re x = 0 :=\nbegin\n  rw [vec_add_conj_eq_two_re, smul_eq_zero] at H,\n  cases H with H_20 H_x,\n  { exfalso, simp at H_20, assumption }, -- 2 = 0\n  { rw function.funext_iff at H_x,\n    ext i,\n    specialize H_x i,\n    rw coe_vec_re at H_x,\n    simp only [of_real_eq_zero, pi.zero_apply] at H_x,\n    simp only [vec_re, H_x, pi.zero_apply] }\nend\n\nend mat_conj\n\n/--\n## Matrix definitions\nLet `M` be a square real matrix. An `eigenvector` of `M` is a complex vector `x` with `M \u2b1d x = \u03bc \u2022 x`\nfor some `\u03bc \u2208 \u2102`, which is called the `eigenvalue` of `M` corresponding to the `eigenvector x`.\n-/\ndef has_eigenpair (\u03bc : \u2102) (x : n \u2192 \u2102) : Prop :=\n  x \u2260 0 \u2227 (mul_vec M x = \u03bc \u2022 x)\n\ndef has_eigenvector (x : n \u2192 \u2102) : Prop :=\n  \u2203 \u03bc : \u2102, M.has_eigenpair \u03bc x\n\ndef has_eigenvalue (\u03bc : \u2102) : Prop :=\n  \u2203 x : n \u2192 \u2102, M.has_eigenpair \u03bc x\n\ndef herm_matrix : Prop := M = mat_conj M\u1d40\n\n-- ## Matrix : Helping lemmas\n\n-- (\u2191M)\u1d40 = \u2191M\u1d40\nlemma coe_transpose_matrix : (M.Coe)\u1d40 = (M\u1d40).Coe := by { unfold Coe,}\n\n-- -M i j = -(M i j)\nlemma neg_matrix_neg_elem (i j : n) : (-M) i j = -(M i j) := by exact rfl\n\n-- \u2191M i j = \u2191(M i j)\nlemma coe_matrix_coe_elem (i j : n) : (M) i j = (M i j) := by exact rfl\n\n-- (M x)* = M* x*\nlemma vec_conj_mul_vec (x : n \u2192 \u2102) :\n  vec_conj (mul_vec M x) = mul_vec (mat_conj M) (vec_conj x) :=\nbegin\n  ext ;\n  simp only [vec_conj, mat_conj, mul_vec, dot_product],\n  {simp  [sum_complex_re, of_real_im, zero_mul, conj_re, mul_re]},\n  simp [sum_complex_im, add_zero, of_real_im, zero_mul,\n      conj_im, mul_im,conj_re, mul_re,sum_neg_distrib, mul_neg_eq_neg_mul_symm, neg_matrix_neg_elem],\nend\n\n-- (\u21d1conj (\u2211 (i : n), \u2191(M x_1 i) * x i)).im = (\u2211 (i : n), \u2191(M x_1 i) * \u21d1conj (x i)).im\n\nlemma herm_matrix_coe (H_herm : herm_matrix M) : (M) = mat_conj (M)\u1d40 :=\nbegin\n  unfold herm_matrix at H_herm,\n  exact H_herm,\nend\n\n-- v\u1d40 (M w) = (v\u1d40 M)\u1d40 w\nlemma dot_product_mul_vec_vec_mul (v w : n \u2192 \u2102) :\n  dot_product v (mul_vec M.Coe w) = dot_product (vec_mul v M.Coe) w :=\nbegin\n  have key : vec_mul v M.Coe = \u03bb j, dot_product v (\u03bb i, M.Coe i j),\n  { ext ; unfold vec_mul },\n  rw [key, dot_product_assoc v w M.Coe],\n  ext ; simp only [dot_product, mul_vec],\nend\n\n-- 1. If x is an eigenvector of M, then a \u2022 x is an eigenvector of M, for any non-zero a : \u2102.\ntheorem has_eigenvector_smul (a : \u2102) (x : n \u2192 \u2102) (H_na : a \u2260 0) (H_eigenvector : has_eigenvector M x) :\n  has_eigenvector M (a \u2022 x) :=\nbegin\n  rcases H_eigenvector with \u27e8\u03bc, \u27e8H_nx, H_mul\u27e9\u27e9,\n  use \u03bc, -- corresponding eigenvalue \u03bc\n  split,\n  { intro hyp, rw smul_eq_zero at hyp, tauto }, -- a \u2022 x \u2260 0\n  calc (M).mul_vec (a \u2022 x)\n      = a \u2022 M.mul_vec x : -- M \u2b1d (a \u2022 x) = a \u2022 (M \u2b1d x)\n  by { rw mul_vec_smul_assoc }\n  ... = a \u2022 (\u03bc \u2022 x) :                 -- ... = a \u2022 (\u03bc \u2022 x)\n  by { rw H_mul }\n  ... = \u03bc \u2022 (a \u2022 x) :                 -- ... = \u03bc \u2022 (a \u2022 x)\n  by { simp only [smul_smul, mul_comm] }\nend\n\n-- 2. If there are two eigenvectors that have the same correspoding eigenvalue \u03bc,\n-- then any non-zero linear combination of them is also an eigenvector with the same eigenvalue \u03bc.\ntheorem has_eigenpair_linear (a b : \u2102) (v w : n \u2192 \u2102) (\u03bc : \u2102) (H_ne : a \u2022 v + b \u2022 w \u2260 0)\n(H\u2081 : has_eigenpair M \u03bc v) (H\u2082 : has_eigenpair M \u03bc w) : has_eigenpair M \u03bc (a \u2022 v + b \u2022 w) :=\nbegin\n  rcases H\u2081 with \u27e8H\u2081\u2081, H\u2081\u2082\u27e9,\n  rcases H\u2082 with \u27e8H\u2082\u2081, H\u2082\u2082\u27e9,\n  use H_ne, -- a \u2022 v + b \u2022 w \u2260 0\n  calc M.mul_vec (a \u2022 v + b \u2022 w) -- M \u2b1d (a \u2022 v + b \u2022 w) = M \u2b1d (a \u2022 v) + M \u2b1d (b \u2022 w)\n      = M.mul_vec(a \u2022 v) + M.mul_vec(b \u2022 w) :\n  by { ext ; simp only [mul_vec, pi.add_apply, dot_product_add] }\n  ... = a \u2022 M.mul_vec v + b \u2022 M.mul_vec w :  -- ... = a \u2022 (M \u2b1d v) + b \u2022 (M \u2b1d w)\n  by { ext ; simp only [mul_vec, algebra.id.smul_eq_mul,\n                        dot_product_smul, pi.add_apply, pi.smul_apply] }\n  ... = a \u2022 (\u03bc \u2022 v) + b \u2022 (\u03bc \u2022 w) :                  -- ... = a \u2022 (\u03bc \u2022 v) + b \u2022 (\u03bc \u2022 w)\n  by { rw [H\u2081\u2082, H\u2082\u2082] }\n  ... = \u03bc \u2022 (a \u2022 v + b \u2022 w) :                        -- ... = \u03bc \u2022 (a \u2022 v + b \u2022 w)\n  by { simp only [smul_smul, mul_comm, smul_add] }\nend\n\n-- 3. All eigenvalues of a symmetric real matrix M are real.\ntheorem herm_matrix_real_eigenvalues (H_herm : herm_matrix M) :\n  \u2200 (\u03bc : \u2102), has_eigenvalue M \u03bc \u2192 \u03bc.im = 0 :=\nbegin\n  -- (1) M \u2b1d x = \u03bc \u2022 x\n  rintro \u03bc \u27e8x, \u27e8H_x, H_eq\u2081\u27e9\u27e9,\n  -- (2) M \u2b1d x* = \u03bc* \u2022 x*\n  have H_eq\u2082 : mul_vec (mat_conj M) (vec_conj x) = (conj \u03bc) \u2022 (vec_conj x),\n  { \n    rw \u2190 vec_conj_smul \u03bc x,\n    -- vec_conj (mul_vec M x) = mul_vec (mat_conj M) (vec_conj x)\n    have hyp : mat_conj (mat_conj M) = M := mat_conj_conj_eq_mat M,\n    -- rw \u2190 hyp,\n    rw \u2190 M.vec_conj_mul_vec x,\n    rw \u2190 H_eq\u2081,\n    -- rw [\u2190 vec_conj_smul \u03bc x, \u2190 M.vec_conj_mul_vec x, H_eq\u2081]\n   },\n  -- (3) \u03bc ((x)\u1d40 x*) = \u03bc* ((x)\u1d40 x*)\n  have H_eq\u2083 : \u03bc * (dot_product x (vec_conj x)) = conj \u03bc * dot_product x (vec_conj x),\n\n  calc \u03bc * dot_product  x (vec_conj x)\n      = dot_product  (\u03bc \u2022 x) (vec_conj x):    -- \u03bc ((x)\u1d40 x*) = (\u03bc x)\u1d40 (x*)\n      by {\n        refine eq.symm _,\n        rw smul_dot_product \u03bc  x (vec_conj x),\n        simp [dot_product, vec_conj, \u2190 mul_assoc, mul_comm],\n      }\n  -- by { \n  --   -- sorry\n  -- rw \u2190 smul_dot_product \u03bc (vec_conj x) x,\n  --     --  simp [dot_product, vec_conj, \u2190 mul_assoc, mul_comm] \n  --     sorry\n  -- }\n  ... = dot_product (M.mul_vec x) (vec_conj x)  :  -- ... = (Mx)\u1d40 (x*)\n  by { rw \u2190 H_eq\u2081 }\n  ... = dot_product (M.Coe.mul_vec x) (vec_conj x)  :  -- ... = (Mx)\u1d40 (x*)\n  by { unfold Coe, }\n  ... = dot_product  x (M.Coe\u1d40.vec_mul (vec_conj x)) :  -- ... = (x\u1d40 M\u1d40)x*)\n  by { exact (dot_product_assoc x (vec_conj x) M.Coe).symm }\n  ... = dot_product (M.Coe\u1d40.mul_vec (vec_conj x)) x : -- ... = (M\u1d40 x*)\u1d40 x\n  by { rw \u2190 mul_vec_transpose M.Coe (vec_conj x) }\n  ... = dot_product (M.Coe.mul_vec (vec_conj x)) x :  -- ... = (M x*)\u1d40 x\n  by { sorry\n    -- have H : M.Coe = M.Coe\u1d40, { \n    -- unfold Coe, tidy }, rw \u2190 H \n    }\n  ... = dot_product (conj \u03bc \u2022 vec_conj x) x :         -- ... = (\u03bc* x*)\u1d40 x\n  by { rw H_eq\u2082 }\n  ... = conj \u03bc * dot_product (vec_conj x) x :         -- ... = \u03bc* ((x*)\u1d40 x)\n  by { \n    sorry\n    -- rw \u2190 smul_dot_product (conj \u03bc) (vec_conj x) x \n    },\n\n  -- (4) (\u03bc - \u03bc*) ((x*)\u1d40 x) = 0\n  have H_eq\u2084 : (\u03bc - conj \u03bc) * dot_product (vec_conj x) x = 0,\n  { rw sub_mul, simp only [H_eq\u2083, sub_self] },\n  -- \u03bc - \u03bc* = 0 \u2228 (x*)\u1d40 x = 0\n  rw mul_eq_zero at H_eq\u2084,\n  cases H_eq\u2084 with H_\u03bc H_prod,\n  { rw [sub_eq_zero, eq_comm, eq_conj_iff_real] at H_\u03bc,\n    cases H_\u03bc with r H_r,\n    rw [H_r, of_real_im] }, -- \u03bc - \u03bc* = 0\n  { exfalso,\n    exact H_x (vec_norm_sq_zero H_prod) }, -- (x*)\u1d40 x = 0\nend\n\n-- 4. For every real eigenvalue of a symmetric matrix M, there exists a corresponding real-valued eigenvector.\ntheorem symm_matrix_real_eigenvectors (H_symm : symm_matrix M) (\u03bc : \u2102) (H_eigenvalue : has_eigenvalue M \u03bc) :\n  \u2203 x : n \u2192 \u2102, has_eigenpair M \u03bc x \u2227 vec_im x = 0 :=\nbegin\n  -- We know that \u03bc \u2208 \u211d from before.\n  have H_\u03bc : \u03bc.im = 0,\n  { apply M.symm_matrix_real_eigenvalues H_symm \u03bc H_eigenvalue },\n  rcases H_eigenvalue with \u27e8x, \u27e8H_nx, H_mul\u27e9\u27e9,\n  by_cases H_re : vec_re x = 0,\n  -- 1) I \u2022 x will be used\n  { use (I \u2022 x),\n    split,\n    -- 1.1) I \u2022 x is an eigenvector\n    { split,\n      -- 1.1.1) I \u2022 x \u2260 0\n      { intro hyp, rw smul_eq_zero at hyp,\n        have H_nI : I \u2260 0, { exact I_ne_zero },\n        tauto },\n      -- 1.1.2) M (I \u2022 x) = \u03bc \u2022 (I \u2022 x)\n      { simp only [mul_vec_smul_assoc, H_mul, smul_smul, mul_comm] } },\n    -- 1.2) I \u2022 x \u2208 \u211d\u207f\n    { ext i,\n      simp only [vec_re, vec_eq_unfold] at H_re,\n      simp only [vec_im, algebra.id.smul_eq_mul, I_re, one_mul,\n                 I_im, zero_mul, mul_im, zero_add, pi.smul_apply],\n      exact H_re i } },\n  -- 2) x + x* will be used\n  { use (x + vec_conj x),\n    split,\n    -- 2.1) x + x* is an eigenvector\n    { split,\n      -- 2.1.1) x + x* \u2260 0\n      { intro hyp, exact H_re (vec_conj_add_zero hyp) },\n      -- 2.1.2) M (x + x*) = \u03bc \u2022 (x + x*)\n      { calc M.Coe.mul_vec (x + vec_conj x)\n            = M.Coe.mul_vec x + M.Coe.mul_vec (vec_conj x) :\n        by { apply mul_vec_add } -- M (x + x*) = M x + M x*\n        ... = M.Coe.mul_vec x + vec_conj (M.Coe.mul_vec x) :\n        by { rw \u2190 M.vec_conj_mul_vec_re x }     -- ... = M x + (M x)*\n        ... = \u03bc \u2022 x + vec_conj (\u03bc \u2022 x) :\n        by { rw H_mul }                         -- ... = \u03bc \u2022 x + (\u03bc \u2022 x)*\n        ... = \u03bc \u2022 x + (conj \u03bc) \u2022 (vec_conj x) :\n        by { rw vec_conj_smul }                 -- ... = \u03bc \u2022 x + \u03bc* \u2022 x*\n        ... = \u03bc \u2022 x + \u03bc \u2022 (vec_conj x) :\n        by { rw conj_of_zero_im H_\u03bc }           -- ... = \u03bc \u2022 x + \u03bc \u2022 x*\n        ... = \u03bc \u2022 (x + vec_conj x) :\n        by { simp only [smul_add] } } },        -- ... = \u03bc \u2022 (x + x*)\n    -- 2.2) x + x* \u2208 \u211d\u207f\n    { ext, simp [vec_add_conj_eq_two_re, vec_im, coe_vec_re] } }\nend\n\n-- 5. If v and w are eigenvectors of a symmetric matrix M with different eigenvalues, then v and w are orthogonal.\ntheorem dot_product_neq_eigenvalue_zero (H_symm : symm_matrix M) (v w : n \u2192 \u2102) (\u03bc \u03bc' : \u2102)\n(H_ne : \u03bc \u2260 \u03bc') (H\u2081 : has_eigenpair M \u03bc v) (H\u2082 : has_eigenpair M \u03bc' w) : dot_product v w = 0 :=\nbegin\n  have key : (\u03bc - \u03bc') * dot_product v w = 0,\n  calc (\u03bc - \u03bc') * dot_product v w\n      = \u03bc * dot_product v w - \u03bc' * dot_product v w :\n  by { apply mul_sub_right_distrib }-- (\u03bc - \u03bc')v\u1d40 w = \u03bc(v\u1d40 w) - \u03bc'(v\u1d40 w)\n  ... = dot_product (\u03bc \u2022 v) w - dot_product v (\u03bc' \u2022 w) :\n  by { sorry\n    -- simp only [dot_product_smul,\n  --      smul_dot_product] \n  }                   -- ... = (\u03bc \u2022 v)\u1d40w - v\u1d40(\u03bc' \u2022 w)\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product v (M.Coe.mul_vec w) :\n  by { rw [H\u2081.2, H\u2082.2] }                     -- ... = (M v)\u1d40w - v\u1d40(M w)\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product (vec_mul v M.Coe) w :\n  by { rw M.dot_product_mul_vec_vec_mul v w }-- ... = (M v)\u1d40w - (v\u1d40 M)\u1d40w\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product (vec_mul v M.Coe\u1d40) w:\n  by { rw \u2190 symm_matrix_coe M H_symm }  -- ... = (M v)\u1d40w - (v\u1d40 M\u1d40)\u1d40w\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product (mul_vec M.Coe v) w :\n  by { rw \u2190 vec_mul_transpose M.Coe v }       -- ... = (M v)\u1d40w - (M v)\u1d40w\n  ... = 0 :\n  by { simp only [sub_self] },               -- ... = 0\n  rw mul_eq_zero at key,\n  cases key with H_\u03bc H_dot,\n  { exfalso, rw sub_eq_zero at H_\u03bc, exact H_ne H_\u03bc }, -- \u03bc - \u03bc' = 0\n  { exact H_dot } -- v\u1d40 w = 0\nend\n\n-- TODOs :\n-- 1. positive semidefinite matrices\n-- 2. eigenvalues = roots of characteristic polynomial (char_poly)\n-- 3. eigendecomposition of a diagonalizable matrix\n\nend matrix", "meta": {"author": "NTULEAN", "repo": "Cauchy_Interlace_Theorem_Proof", "sha": "930c941a5c054201c6e3d9cc63f4bb4921030f85", "save_path": "github-repos/lean/NTULEAN-Cauchy_Interlace_Theorem_Proof", "path": "github-repos/lean/NTULEAN-Cauchy_Interlace_Theorem_Proof/Cauchy_Interlace_Theorem_Proof-930c941a5c054201c6e3d9cc63f4bb4921030f85/Gary/src/HermitianCode.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7081640084929488}}
{"text": "import data.nat.basic\nimport data.nat.modeq\nimport data.nat.prime\nimport data.nat.totient\nimport field_theory.finite.basic\n\nvariables (a b c d n : \u2115)\n\n-- Helpers for proof\nlemma mod_pow_mod : ((a % n) ^ b) % n = (a ^ b) % n :=\nbegin\n  -- Use either change here or write MOD form directly as goal\n  change (a % n) ^ b \u2261 (a ^ b) [MOD n],\n  apply nat.modeq.pow,\n  exact nat.mod_modeq _ _,\nend\n\nlemma mul_mod_right_distrib : (a * b) % n = ((a % n) * (b % n)) % n :=\nbegin\n  change (a * b) \u2261 a % n * (b % n) [MOD n],\n  apply nat.modeq.mul,\n  repeat {apply nat.modeq.symm, exact nat.mod_modeq _ _},\nend\n\nvariables (msg pub_e p q priv : \u2115)\n\n-- Encryption\ndef enc : \u2115 := (msg ^ pub_e) % (p * q)\n\n-- Decryption\ndef dec (enc : \u2115) : \u2115 := (enc ^ priv) % (p * q)\n\nlemma mul_coprime_or_coprime_and\n  (prime_p : p.prime)\n  (prime_q : q.prime)\n  (diff_pq : p \u2260 q)\n  : (p.coprime msg \u2227 q.coprime msg) \u2228 (\u00acp.coprime msg \u2228 \u00acq.coprime msg) :=\nbegin\n  by_cases h : (p * q).coprime msg,\n  { left,\n    exact \u27e8nat.coprime.coprime_mul_right h, nat.coprime.coprime_mul_left h\u27e9,\n  },\n  {\n    right,\n    rw nat.prime.not_coprime_iff_dvd at h,\n    cases h with k ncp,\n    cases ncp with prime_k ncp,\n    cases ncp with k_dvd_pq k_dvd_msg,\n    rw nat.prime.dvd_mul prime_k at k_dvd_pq,\n    cases k_dvd_pq with k_dvd_p k_dvd_q,\n    -- TODO use meta tactics to combine these two similar parts\n    { rw nat.dvd_prime prime_p at k_dvd_p,\n      cases k_dvd_p with k_one k_p,\n      { have k_ne_one : k \u2260 1 := nat.prime.ne_one prime_k,\n        exact absurd k_one k_ne_one,\n      },\n      { rw k_p at k_dvd_msg,\n        left,\n        rw \u2190nat.prime.dvd_iff_not_coprime prime_p,\n        assumption,\n      },\n    },\n    { rw nat.dvd_prime prime_q at k_dvd_q,\n      cases k_dvd_q with k_one k_q,\n      { have k_ne_one : k \u2260 1 := nat.prime.ne_one prime_k,\n        exact absurd k_one k_ne_one,\n      },\n      { rw k_q at k_dvd_msg,\n        right,\n        rw \u2190nat.prime.dvd_iff_not_coprime prime_q,\n        assumption,\n      },\n    },\n  },\nend\n\ntheorem dec_undoes_enc\n-- These are the picking requirements\n  (prime_p : p.prime)\n  (prime_q : q.prime)\n  (diff_pq : p \u2260 q)\n  (one_lt_pub_e : 1 < pub_e)\n  (msg_lt_pq : msg < (p * q))\n  (pub_e_lt_totient : pub_e < (p * q).totient)\n  (pub_e_coprime_totient : pub_e * priv \u2261 1 [MOD (p * q).totient])\n  (h : (p * q).coprime msg \u2228 \u00ac(p * q).coprime msg)\n  : msg = dec p q priv (enc msg pub_e p q) :=\nbegin\n  have msg_coprime_or_not := mul_coprime_or_coprime_and msg _ _ prime_p prime_q diff_pq,\n  rw [enc, dec, mod_pow_mod, \u2190pow_mul],\n  have msg_zero_or_gt : 0 = msg \u2228 0 < msg\n    := nat.eq_or_lt_of_le (nat.zero_le msg),\n  rw nat.modeq.comm at pub_e_coprime_totient,\n  have one_le_mul_pub_e_priv : 1 \u2264 pub_e * priv\n    := begin\n       apply nat.modeq.le_of_lt_add pub_e_coprime_totient _,\n       apply nat.lt_add_left,\n       exact nat.lt_trans one_lt_pub_e pub_e_lt_totient,\n    end,\n  cases msg_zero_or_gt with eq_zero gt_zero,\n  { rw [\u2190eq_zero, zero_pow one_le_mul_pub_e_priv],\n    simp },\n  { conv\n    begin\n      to_lhs,\n      rw \u2190nat.mod_eq_of_lt msg_lt_pq,\n    end,\n    have p_coprime_q : p.coprime q\n      := (nat.coprime_primes prime_p prime_q).mpr diff_pq,\n    rw [\u2190nat.modeq, \u2190nat.modeq_and_modeq_iff_modeq_mul p_coprime_q],\n    split,\n    all_goals { rw nat.modeq_iff_dvd' one_le_mul_pub_e_priv at pub_e_coprime_totient,\n      cases pub_e_coprime_totient with k h\u2081,\n      have h\u2082 : (pub_e * priv - 1).succ = ((p * q).totient * k).succ\n        := congr_arg nat.succ h\u2081,\n      rw [nat.sub_one,\n         nat.succ_pred_eq_of_pos (nat.lt_of_succ_le one_le_mul_pub_e_priv)]\n         at h\u2082,\n      rw h\u2082,\n      rw [pow_succ,\n        pow_mul,\n        nat.modeq, mul_mod_right_distrib,\n        \u2190mod_pow_mod],\n    },\n    show msg % q = msg % q * ((msg ^ (p * q).totient % q) ^ k % q) % q,\n    rw mul_comm p,\n    show msg % p = msg % p * ((msg ^ (p * q).totient % p) ^ k % p) % p,\n    all_goals {\n      cases msg_coprime_or_not with coprime ncoprime,\n      { rw [nat.totient_mul p_coprime_q,\n           pow_mul,\n           \u2190mod_pow_mod _ q.totient]\n        <|> rw [nat.totient_mul (nat.coprime.symm p_coprime_q),\n               pow_mul,\n               \u2190mod_pow_mod _ p.totient],\n        have h\u2083 := nat.modeq.pow_totient,\n        rw nat.modeq at h\u2083,\n        rw h\u2083 (nat.coprime.symm coprime.1)\n        <|> rw h\u2083 (nat.coprime.symm coprime.2),\n        repeat {rw nat.mod_eq_of_lt (nat.prime.one_lt prime_p)\n                <|> rw nat.mod_eq_of_lt (nat.prime.one_lt prime_q)\n                <|> rw one_pow},\n        simp,\n      },\n    },\n    -- TODO use meta tactics to combine these two similar parts\n    { cases ncoprime with np nq,\n      { rw [nat.totient_mul p_coprime_q,\n           pow_mul,\n           \u2190mod_pow_mod _ q.totient],\n        rw \u2190nat.prime.dvd_iff_not_coprime prime_p at np,\n        rw [\u2190nat.modeq_zero_iff_dvd, nat.modeq] at np,\n        rw [mul_mod_right_distrib, np],\n        simp,\n      },\n      { have msg_coprime_p : msg.coprime p := begin\n          rw [nat.coprime_comm, nat.prime.coprime_iff_not_dvd prime_p],\n          rw \u2190nat.prime.dvd_iff_not_coprime prime_q at nq,\n          exact begin\n            intro p_dvd_msg,\n            have pq_dvd_msg\n              := nat.prime.dvd_mul_of_dvd_ne\n                 diff_pq prime_p prime_q p_dvd_msg nq,\n            have pq_not_dvd_msg\n              := nat.not_dvd_of_pos_of_lt gt_zero msg_lt_pq,\n            exact absurd pq_dvd_msg pq_not_dvd_msg,\n          end,\n        end,\n        rw [nat.totient_mul p_coprime_q,\n          pow_mul,\n          \u2190mod_pow_mod _ q.totient],\n        have h\u2083 := nat.modeq.pow_totient,\n        rw nat.modeq at h\u2083,\n        rw h\u2083 msg_coprime_p,\n        repeat {rw nat.mod_eq_of_lt (nat.prime.one_lt prime_p)\n          <|> rw one_pow},\n        simp,\n      },\n    },\n    { cases ncoprime with np nq,\n      { have msg_coprime_q : msg.coprime q := begin\n          rw [nat.coprime_comm, nat.prime.coprime_iff_not_dvd prime_q],\n          rw \u2190nat.prime.dvd_iff_not_coprime prime_p at np,\n          exact begin\n            intro q_dvd_msg,\n            have pq_dvd_msg\n              := nat.prime.dvd_mul_of_dvd_ne\n                 diff_pq prime_p prime_q np q_dvd_msg,\n            have pq_not_dvd_msg\n              := nat.not_dvd_of_pos_of_lt gt_zero msg_lt_pq,\n            exact absurd pq_dvd_msg pq_not_dvd_msg,\n          end,\n        end,\n        rw [nat.totient_mul (nat.coprime.symm p_coprime_q),\n          pow_mul,\n          \u2190mod_pow_mod _ p.totient],\n        have h\u2083 := nat.modeq.pow_totient,\n        rw nat.modeq at h\u2083,\n        rw h\u2083 msg_coprime_q,\n        repeat {rw nat.mod_eq_of_lt (nat.prime.one_lt prime_q)\n          <|> rw one_pow},\n        simp,\n      },\n      { rw [nat.totient_mul (nat.coprime.symm p_coprime_q),\n           pow_mul,\n           \u2190mod_pow_mod _ p.totient],\n        rw \u2190nat.prime.dvd_iff_not_coprime prime_q at nq,\n        rw [\u2190nat.modeq_zero_iff_dvd, nat.modeq] at nq,\n        rw [mul_mod_right_distrib, nq],\n        simp,\n      },\n    },\n  },\nend\n", "meta": {"author": "aronerben", "repo": "lean-rsa", "sha": "8ca27c8fa4454431adb73281b7fdf55944ee3bb0", "save_path": "github-repos/lean/aronerben-lean-rsa", "path": "github-repos/lean/aronerben-lean-rsa/lean-rsa-8ca27c8fa4454431adb73281b7fdf55944ee3bb0/src/rsa.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7081640035605922}}
{"text": "/-\nCopyright (c) 2021 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport algebra.algebra.spectrum\nimport analysis.calculus.deriv\n/-!\n# The spectrum of elements in a complete normed algebra\n\nThis file contains the basic theory for the resolvent and spectrum of a Banach algebra.\n\n## Main definitions\n\n* `spectral_radius : \u211d\u22650\u221e`: supremum of `\u2225k\u2225\u208a` for all `k \u2208 spectrum \ud835\udd5c a`\n\n## Main statements\n\n* `spectrum.is_open_resolvent_set`: the resolvent set is open.\n* `spectrum.is_closed`: the spectrum is closed.\n* `spectrum.subset_closed_ball_norm`: the spectrum is a subset of closed disk of radius\n  equal to the norm.\n* `spectrum.is_compact`: the spectrum is compact.\n* `spectrum.spectral_radius_le_nnnorm`: the spectral radius is bounded above by the norm.\n* `spectrum.has_deriv_at_resolvent`: the resolvent function is differentiable on the resolvent set.\n\n\n## TODO\n\n* after we have Liouville's theorem, prove that the spectrum is nonempty when the\n  scalar field is \u2102.\n* compute all derivatives of `resolvent a`.\n\n-/\n\nopen_locale ennreal\n\n/-- The *spectral radius* is the supremum of the `nnnorm` (`\u2225\u2b1d\u2225\u208a`) of elements in the spectrum,\n    coerced into an element of `\u211d\u22650\u221e`. Note that it is possible for `spectrum \ud835\udd5c a = \u2205`. In this\n    case, `spectral_radius a = 0`.  It is also possible that `spectrum \ud835\udd5c a` be unbounded (though\n    not for Banach algebras, see `spectrum.is_bounded`, below).  In this case,\n    `spectral_radius a = \u221e`. -/\nnoncomputable def spectral_radius (\ud835\udd5c : Type*) {A : Type*} [normed_field \ud835\udd5c] [ring A]\n  [algebra \ud835\udd5c A] (a : A) : \u211d\u22650\u221e :=\n\u2a06 k \u2208 spectrum \ud835\udd5c a, \u2225k\u2225\u208a\n\nnamespace spectrum\n\nsection spectrum_compact\n\nvariables {\ud835\udd5c : Type*} {A : Type*}\nvariables [normed_field \ud835\udd5c] [normed_ring A] [normed_algebra \ud835\udd5c A] [complete_space A]\n\nlocal notation `\u03c3` := spectrum \ud835\udd5c\nlocal notation `\u03c1` := resolvent_set \ud835\udd5c\nlocal notation `\u2191\u2090` := algebra_map \ud835\udd5c A\n\nlemma is_open_resolvent_set (a : A) : is_open (\u03c1 a) :=\nunits.is_open.preimage ((algebra_map_isometry \ud835\udd5c A).continuous.sub continuous_const)\n\nlemma is_closed (a : A) : is_closed (\u03c3 a) :=\n(is_open_resolvent_set a).is_closed_compl\n\nlemma mem_resolvent_of_norm_lt {a : A} {k : \ud835\udd5c} (h : \u2225a\u2225 < \u2225k\u2225) :\n  k \u2208 \u03c1 a :=\nbegin\n  rw [resolvent_set, set.mem_set_of_eq, algebra.algebra_map_eq_smul_one],\n  have hk : k \u2260 0 := ne_zero_of_norm_pos (by linarith [norm_nonneg a]),\n  let ku := units.map (\u2191\u2090).to_monoid_hom (units.mk0 k hk),\n  have hku : \u2225-a\u2225 < \u2225(\u2191ku\u207b\u00b9:A)\u2225\u207b\u00b9 := by simpa [ku, algebra_map_isometry] using h,\n  simpa [ku, sub_eq_add_neg, algebra.algebra_map_eq_smul_one] using (ku.add (-a) hku).is_unit,\nend\n\nlemma norm_le_norm_of_mem {a : A} {k : \ud835\udd5c} (hk : k \u2208 \u03c3 a) :\n  \u2225k\u2225 \u2264 \u2225a\u2225 :=\nle_of_not_lt $ mt mem_resolvent_of_norm_lt hk\n\nlemma subset_closed_ball_norm (a : A) :\n  \u03c3 a \u2286 metric.closed_ball (0 : \ud835\udd5c) (\u2225a\u2225) :=\n\u03bb k hk, by simp [norm_le_norm_of_mem hk]\n\nlemma is_bounded (a : A) : metric.bounded (\u03c3 a) :=\n(metric.bounded_iff_subset_ball 0).mpr \u27e8\u2225a\u2225, subset_closed_ball_norm a\u27e9\n\ntheorem is_compact [proper_space \ud835\udd5c] (a : A) : is_compact (\u03c3 a) :=\nmetric.is_compact_of_is_closed_bounded (is_closed a) (is_bounded a)\n\ntheorem spectral_radius_le_nnnorm (a : A) :\n  spectral_radius \ud835\udd5c a \u2264 \u2225a\u2225\u208a :=\nbegin\n  suffices h : \u2200 k \u2208 \u03c3 a, (\u2225k\u2225\u208a : \u211d\u22650\u221e) \u2264 \u2225a\u2225\u208a,\n  { exact bsupr_le h, },\n  { by_cases ha : (\u03c3 a).nonempty,\n    { intros _ hk,\n      exact_mod_cast norm_le_norm_of_mem hk },\n    { rw set.not_nonempty_iff_eq_empty at ha,\n      simp [ha, set.ball_empty_iff] } }\nend\n\nend spectrum_compact\n\nsection resolvent_deriv\n\nvariables {\ud835\udd5c : Type*} {A : Type*}\nvariables [nondiscrete_normed_field \ud835\udd5c] [normed_ring A] [normed_algebra \ud835\udd5c A] [complete_space A]\n\nlocal notation `\u03c1` := resolvent_set \ud835\udd5c\nlocal notation `\u2191\u2090` := algebra_map \ud835\udd5c A\n\ntheorem has_deriv_at_resolvent {a : A} {k : \ud835\udd5c} (hk : k \u2208 \u03c1 a) :\n  has_deriv_at (resolvent a) (-(resolvent a k) ^ 2) k :=\nbegin\n  have H\u2081 : has_fderiv_at ring.inverse _ (\u2191\u2090k - a) := has_fderiv_at_ring_inverse hk.unit,\n  have H\u2082 : has_deriv_at (\u03bb k, \u2191\u2090k - a) 1 k,\n  { simpa using (algebra.linear_map \ud835\udd5c A).has_deriv_at.sub_const a },\n  simpa [resolvent, sq, hk.unit_spec, \u2190 ring.inverse_unit hk.unit] using H\u2081.comp_has_deriv_at k H\u2082,\nend\n\nend resolvent_deriv\n\nend spectrum\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/normed_space/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.7081639986282354}}
{"text": "import data.real.basic\nimport data.matrix.basic\nimport linear_algebra.basic\nimport linear_algebra.linear_independent\nimport linear_algebra.matrix.to_lin\nimport linear_algebra.unitary_group\nimport analysis.normed_space.basic\nimport analysis.inner_product_space.euclidean_dist\n\nvariables {n d : \u2115} (U : matrix (fin d) (fin n) \u211d)\n\nopen_locale big_operators matrix\n\ndef outer (v : fin d \u2192 \u211d) (u : fin d \u2192 \u211d) : matrix (fin d) (fin d) \u211d :=\n\u03bb i j, (v i) * (u j)\n\ndef outers (U : matrix (fin d) (fin n) \u211d) : matrix (fin d) (fin d) \u211d :=\n  \u2211 i : fin n, outer (U\u1d40 i) (U\u1d40 i)\n\n@[simp]\nlemma outer_smul_outer (v : fin d \u2192 \u211d) (u : fin d \u2192 \u211d) (c : \u211d) : outer (c \u2022 u) v = c \u2022 outer u v := sorry\n\n@[simp]\nlemma outer_outer_smul (v : fin d \u2192 \u211d) (u : fin d \u2192 \u211d) (c : \u211d) : outer u (c \u2022 v) = c \u2022 outer u v := sorry\n\n@[simp]\nlemma outers_smul (U : matrix (fin d) (fin n) \u211d) (c : \u211d) : outers (c \u2022 U) = c^2 \u2022 outers U := sorry\n\ndef norm_columns (U : matrix (fin d) (fin n) \u211d) : matrix (fin d) (fin n) \u211d := sorry\n\nlemma norm_columns_apply_sq (U : matrix (fin d) (fin n) \u211d) : \u2200 j : (fin n), \u2225 to_euclidean ((norm_columns U)\u1d40 j) \u2225^2 = 1  := sorry\n\nlemma norm_columns_apply (U : matrix (fin d) (fin n) \u211d) : \u2200 j : (fin n), \u2225 to_euclidean ((norm_columns U)\u1d40 j) \u2225 = 1  := sorry\n\ndef radial_isotropic (U : matrix (fin d) (fin n) \u211d) : Prop := outers (norm_columns U) = (n / d  : \u211d) \u2022 1\n\nlemma orthogonal_radial_isotropic_radial_isotropic (U : matrix (fin d) (fin n) \u211d)\n  (O : matrix (fin d) (fin d) \u211d) (hO : O \u2208 @matrix.orthogonal_group (fin d) _ _ \u211d _) :\n  radial_isotropic (O \u2b1d U) :=\nbegin\n  sorry,\nend\n\ndef make_radial_isotropic (U : matrix (fin d) (fin n) \u211d) \n  (hU : \u2200 f : (fin d) \u2192 (fin n), function.injective f \u2192\n  linear_independent \u211d (\u03bb i : fin d, U\u1d40 (f i))) : \n    matrix (fin d) (fin d) \u211d :=\nbegin\n  sorry\nend\n\ntheorem make_radial_isotropic_apply (U : matrix (fin d) (fin n) \u211d) \n  (hU : \u2200 f : (fin d) \u2192 (fin n), function.injective f \u2192\n  linear_independent \u211d (\u03bb i : fin d, U\u1d40 (f i))) : \n    radial_isotropic (make_radial_isotropic U hU \u2b1d U) :=\nbegin\n  sorry\nend\n\n\n\n", "meta": {"author": "Daniel-Packer", "repo": "paulsen-made-simple", "sha": "64f0b91375c6f9dfb959e47f347fa8a87b395e9a", "save_path": "github-repos/lean/Daniel-Packer-paulsen-made-simple", "path": "github-repos/lean/Daniel-Packer-paulsen-made-simple/paulsen-made-simple-64f0b91375c6f9dfb959e47f347fa8a87b395e9a/src/radial_isotropic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7081611405547887}}
{"text": "/-\nCopyright (c) 2021 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport logic.basic\n\n/-!\n# Girard's paradox\n\nGirard's paradox is a proof that `Type : Type` entails a contradiction. We can't say this directly\nin Lean because `Type : Type 1` and it's not possible to give `Type` a different type via an axiom,\nso instead we axiomatize the behavior of the Pi type and application if the typing rule for Pi was\n`(Type \u2192 Type) \u2192 Type` instead of `(Type \u2192 Type) \u2192 Type 1`.\n\nFurthermore, we don't actually want false axioms in mathlib, so rather than introducing the axioms\nusing `axiom` or `constant` declarations, we take them as assumptions to the `girard` theorem.\n\nBased on Watkins' LF implementation of Hurkens' simplification of Girard's paradox:\n<http://www.cs.cmu.edu/~kw/research/hurkens95tlca.elf>.\n\n## Main statements\n\n* `girard`: there are no Girard universes.\n-/\n\n/-- Girard's paradox: there are no universes `u` such that `Type u : Type u`.\nSince we can't actually change the type of Lean's `\u03a0` operator, we assume the existence of\n`pi`, `lam`, `app` and the `beta` rule equivalent to the `\u03a0` and `app` constructors of type theory.\n-/\ntheorem {u} girard\n  (pi : (Type u \u2192 Type u) \u2192 Type u)\n  (lam : \u2200 {A : Type u \u2192 Type u}, (\u2200 x, A x) \u2192 pi A)\n  (app : \u2200 {A}, pi A \u2192 \u2200 x, A x)\n  (beta : \u2200 {A : Type u \u2192 Type u} (f : \u2200 x, A x) (x), app (lam f) x = f x) : false :=\nlet F (X) := (set (set X) \u2192 X) \u2192 set (set X), U := pi F in\nlet G (T : set (set U)) (X) : F X := \u03bb f, {p | {x : U | f (app x X f) \u2208 p} \u2208 T} in\nlet \u03c4 (T : set (set U)) : U := lam (G T) in\nlet \u03c3 (S : U) : set (set U) := app S U \u03c4 in\nhave \u03c3\u03c4 : \u2200 {s S}, s \u2208 \u03c3 (\u03c4 S) \u2194 {x | \u03c4 (\u03c3 x) \u2208 s} \u2208 S := \u03bb s S,\n  iff_of_eq (congr_arg (\u03bb f : F U, s \u2208 f \u03c4) (beta (G S) U) : _),\nlet \u03c9 : set (set U) := {p | \u2200 x, p \u2208 \u03c3 x \u2192 x \u2208 p} in\nlet \u03b4 (S : set (set U)) := \u2200 p, p \u2208 S \u2192 \u03c4 S \u2208 p in\nhave \u03b4 \u03c9 := \u03bb p d, d (\u03c4 \u03c9) $ \u03c3\u03c4.2 $ \u03bb x h, d (\u03c4 (\u03c3 x)) (\u03c3\u03c4.2 h),\nthis {y | \u00ac \u03b4 (\u03c3 y)} (\u03bb x e f, f _ e (\u03bb p h, f _ (\u03c3\u03c4.1 h))) (\u03bb p h, this _ (\u03c3\u03c4.1 h))\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/logic/girard.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7081549870046652}}
{"text": "import topology.instances.real\nimport analysis.normed_space.banach_steinhaus\n\nopen set filter\nopen_locale topological_space filter\n\n/- TEXT:\n.. index:: topological space\n\n.. _topological_spaces:\n\nTopological spaces\n------------------\n\nFundamentals\n^^^^^^^^^^^^\n\nWe now go up in generality and introduce topological spaces. We will review the two main ways to define\ntopological spaces and then explain how the category of topological spaces is much better behaved than\nthe category of metric spaces. Note that we won't be using mathlib category theory here, only having \na somewhat categorical point of view.\n\nThe first way to think about the transition from metric spaces to topological spaces is that we only\nremember the notion of open sets (or equivalently the notion of closed sets). From this point of view,\na topological space is a type equipped with a collection of sets that are called open sets. This collection\nhas to satisfy a number of axioms presented below (this collection is slighly redundant but we will ignore that).\n\nBOTH: -/\n\n-- QUOTE:\nsection\n\nvariables {X : Type*} [topological_space X]\n\nexample : is_open (univ : set X) := is_open_univ\n\nexample : is_open (\u2205 : set X) := is_open_empty\n\nexample {\u03b9 : Type*} {s : \u03b9 \u2192 set X} (hs : \u2200 i, is_open $ s i) : \n  is_open (\u22c3 i, s i) := \nis_open_Union hs\n\nexample {\u03b9 : Type*} [fintype \u03b9] {s : \u03b9 \u2192 set X} (hs : \u2200 i, is_open $ s i) : \n  is_open (\u22c2 i, s i) := \nis_open_Inter hs\n\n\n-- QUOTE.\n\n/- TEXT:\n\nClosed sets are then defined as sets whose complement  is open. A function between topological spaces\nis (globally) continuous if all preimages of open sets are open. \nBOTH: -/\n\n-- QUOTE:\nvariables {Y : Type*} [topological_space Y]\n\nexample {f : X \u2192 Y} : continuous f \u2194 \u2200 s, is_open s \u2192 is_open (f \u207b\u00b9' s) :=\ncontinuous_def\n\n-- QUOTE.\n\n/- TEXT:\nWith this definition we already see that, compared to metric spaces, topological spaces only remember\nenough information to talk about continuous functions: two topological structures on a type are\nthe same if and only if they have the same continuous functions (indeed the identity function will\nbe continuous in both direction if and only if the two structures have the same open sets).\n\nHowever as soon as we move on to continuity at a point we see the limitations of the approach based \non open sets. In mathlib it is much more frequent to think of topological spaces as types equipped\nwith a neighborhood filter ``\ud835\udcdd x`` attached to each point ``x`` (the corresponding function\n``X \u2192 filter X`` satisfies certain conditions explained further down). Remember from the filters section that\nthese gadget play two related roles. First ``\ud835\udcdd x`` is seen as the generalized set of points of ``X``\nthat are close to ``x``. And then it is seen as giving a way to say, for any predicate ``P : X \u2192 Prop``,\nthat this predicates holds for points that are close enough to ``x``. Let us state\nthat ``f : X \u2192 Y`` is continuous at ``x``. The purely filtery way is to say that the direct image under\n``f`` of the generalized set of points that are close to ``x`` is contained in the generalized set of \npoints that are close to ``f x``. Recall this spelled either ``map f (\ud835\udcdd x) \u2264 \ud835\udcdd (f x)``\nor ``tendsto f (\ud835\udcdd x) (\ud835\udcdd (f x))``. \n\nBOTH: -/\n\n-- QUOTE:\n\nexample {f : X \u2192 Y} {x : X} : continuous_at f x \u2194 map f (\ud835\udcdd x) \u2264 \ud835\udcdd (f x) :=\niff.rfl\n\n-- QUOTE.\n\n/- TEXT:\nOne can also spell it using both neighborhoods seen as ordinary sets and a neighborhood filter \nseen as a generalized set: \"for any neighborhood ``U`` of ``f x``, all points close to ``x`` \nare sent to ``U``\". Note that the proof is again ``iff.rfl``, this point of view is definitionally \nequivalent to the previous one.\n\nBOTH: -/\n\n-- QUOTE:\nexample {f : X \u2192 Y} {x : X} : continuous_at f x \u2194 \u2200 U \u2208 \ud835\udcdd (f x), \u2200\u1da0 x in \ud835\udcdd x, f x \u2208 U :=\niff.rfl\n-- QUOTE.\n\n/- TEXT:\nWe now explain how to go from one point of view to the other. In terms of open sets, we can\nsimply define members of ``\ud835\udcdd x`` as sets that contain an open set containing ``x``.\n\n\nBOTH: -/\n\n-- QUOTE:\nexample {x : X} {s : set X} : s \u2208 \ud835\udcdd x \u2194 \u2203 t \u2286 s, is_open t \u2227 x \u2208 t :=\nmem_nhds_iff\n-- QUOTE.\n\n/- TEXT:\nTo go in the other direction we need to discuss the condition that ``\ud835\udcdd : X \u2192 filter X`` must satisfy\nin order to be the neighborhood function of a topology. \n\nThe first constraint is that ``\ud835\udcdd x``, seen as a generalized set, contains the set ``{x}`` seen as the generalized set\n``pure x`` (explaining this weird name would be too much of a digression, so we simply accept it for now). \nAnother way to say it is that if a predicate holds for points close to ``x`` then it holds at ``x``.\n\nBOTH: -/\n\n-- QUOTE:\nexample (x : X) : pure x \u2264 \ud835\udcdd x := pure_le_nhds x\n\nexample (x : X) (P : X \u2192 Prop) (h : \u2200\u1da0 y in \ud835\udcdd x, P y) : P x := \npure_le_nhds x h\n-- QUOTE.\n\n/- TEXT:\nThen a more subtle requirement is that, for any predicate ``P : X \u2192 Prop`` and any ``x``, if ``P y`` holds for ``y`` close\nto ``x`` then for ``y`` close to ``x`` and ``z`` close to ``y``, ``P z`` holds. More precisely we have:\nBOTH: -/\n\n-- QUOTE:\n\nexample {P : X \u2192 Prop} {x : X} (h : \u2200\u1da0 y in \ud835\udcdd x, P y) : \u2200\u1da0 y in \ud835\udcdd x, \u2200\u1da0 z in \ud835\udcdd y, P z :=\neventually_eventually_nhds.mpr h\n\n-- QUOTE.\n\n/- TEXT:\nThose two results characterize the functions ``X \u2192 filter X`` that are neighborhood functions for a topological space\nstructure on ``X``. There is a still a function ``topological_space.mk_of_nhds : (X \u2192 filter X) \u2192 topological_space X``\nbut it will give back its input as a neighborhood function only if it satistfy the above two constraints.\nMore precisely we have a lemma ``topological_space.nhds_mk_of_nhds`` saying that in a different way and our\nnext exercise deduces this different way from how we stated it above. \nBOTH: -/\n\n#check topological_space.mk_of_nhds\n#check topological_space.nhds_mk_of_nhds.\n\n-- QUOTE:\n\nexample {\u03b1 : Type*} (n : \u03b1 \u2192 filter \u03b1) (H\u2080 : \u2200 a, pure a \u2264 n a) \n  (H : \u2200 a : \u03b1, \u2200 p : \u03b1 \u2192 Prop, (\u2200\u1da0 x in n a, p x) \u2192 (\u2200\u1da0 y in n a, \u2200\u1da0 x in n y, p x)) :\n  \u2200 a, \u2200 s \u2208 n a, \u2203 t \u2208 n a, t \u2286 s \u2227 \u2200 a' \u2208 t, s \u2208 n a' :=\nsorry\n\n-- QUOTE.\n\n-- SOLUTIONS:\nexample {\u03b1 : Type*} (n : \u03b1 \u2192 filter \u03b1) (H\u2080 : \u2200 a, pure a \u2264 n a) \n  (H : \u2200 a : \u03b1, \u2200 p : \u03b1 \u2192 Prop, (\u2200\u1da0 x in n a, p x) \u2192 (\u2200\u1da0 y in n a, \u2200\u1da0 x in n y, p x)) :\n  \u2200 a, \u2200 s \u2208 n a, \u2203 t \u2208 n a, t \u2286 s \u2227 \u2200 a' \u2208 t, s \u2208 n a' :=\nbegin\n  intros a s s_in,\n  refine \u27e8{y | s \u2208 n y}, H a (\u03bb x, x \u2208 s) s_in, _, by tauto\u27e9,\n  rintros y (hy : s \u2208 n y),\n  exact H\u2080 y hy\nend\n-- BOTH:\nend\n-- BOTH.\n/- TEXT:\nNote that ``topological_space.mk_of_nhds`` is not so frequently used, but it still good to know in what\nprecise sense the neighborhood filters is all there is in a topological space structure.\n\nThe next thing to know in order to efficiently use topological spaces in mathlib is that we use a lot\nof formal properties of ``topological_space : Type u \u2192 Type u``. From a purely mathematical point of view,\nthose formal properties are a very clean way to explain how topological spaces solve issues that metric spaces \nhave. From this point of view, the issues solved by topological spaces is that metric spaces enjoy very \nlittle fonctoriality, and have very bad categorical properties in general. This comes on top of the fact \nalready discussed that metric spaces contain a lot of geometrical information that is not topologically relevant. \n\nLet us focus on fonctoriality first. A metric space structure can be induced on a subset or,\nequivalently, it can be pulled back by an injective map. But that's pretty much everything.\nThey cannot be pulled back by general map or pushed forward, even by surjective maps.\n\nIn particular there is no sensible distance to put on a quotient of a metric space or on an uncountable\nproducts of metric spaces. Consider for instance the type ``\u211d \u2192 \u211d``, seen as\na product of copies of ``\u211d`` indexed by ``\u211d``. We would like to say that pointwise convergence of\nsequences of functions is a respectable notion of convergence. But there is no distance on\n``\u211d \u2192 \u211d`` that gives this notion of convergence. Relatedly, there is no distance ensuring that\na map ``f : X \u2192 (\u211d \u2192 \u211d)`` is continuous if and only ``\u03bb x, f x t`` is continuous for every ``t : \u211d``.\n\nWe now review the data used to solve all those issues. First we can use any map ``f : X \u2192 Y`` to\npush or pull topologies from one side to the other. Those two operations form a Galois connection.\n\nBOTH: -/\n\n-- QUOTE:\nvariables {X Y : Type*}\n\nexample (f : X \u2192 Y) : topological_space X \u2192 topological_space Y :=\ntopological_space.coinduced f\n\nexample (f : X \u2192 Y) : topological_space Y \u2192 topological_space X :=\ntopological_space.induced f\n\nexample (f : X \u2192 Y) (T_X : topological_space X) (T_Y : topological_space Y) :\n  topological_space.coinduced f T_X \u2264 T_Y \u2194 T_X \u2264 topological_space.induced f T_Y :=\ncoinduced_le_iff_le_induced\n\n-- QUOTE.\n\n/- TEXT:\nThose operations are compactible with composition of functions. \nAs usual, pushing forward is covariant and pulling back is contravariant, see ``coinduced_compose`` and ``induced_compose``.\nOn paper we will use notations :math:`f_*T` for ``topological_space.coinduced f T`` and\n:math:`f^*T` for ``topological_space.induced f T``.\nBOTH: -/\n\n#check coinduced_compose\n#check induced_compose.\n\n/- TEXT:\n\nThen the next big piece is a complete lattice structure on ``topological_structure X`` \nfor any given structure. If you think of topologies are being primarily the data of open sets then you expect\nthe order relation on ``topological_structure X`` to come from ``set (set X)``, ie you expect ``t \u2264 t'``\nif a set ``u`` is open for ``t'`` as soon as it is open for ``t``. However we already know that mathlib focuses\non neighborhoods more than open sets so, for any ``x : X`` we want ``\u03bb T : topological_space X, @nhds X T x``\nto be order preserving. And we know the order relation on ``filter X`` is designed to ensure an order\npreserving ``principal : set X \u2192 filter X``, allowing to see filters as generalized sets.\nSo the order relation we do use on  ``topological_structure X`` is opposite to the one coming from ``set (set X)``.\n\nBOTH: -/\n\n-- QUOTE:\nexample {T T' : topological_space X} :\n  T \u2264 T' \u2194 \u2200 s, T'.is_open s \u2192 T.is_open s  :=\niff.rfl\n\n-- QUOTE.\n\n/- TEXT:\n\nNow we can recover continuity by combining the push-foward (or pull-back) operation with the order relation.\n\nBOTH: -/\n\n-- QUOTE:\nexample (T_X : topological_space X) (T_Y : topological_space Y) (f : X \u2192 Y) :\n  continuous f \u2194 topological_space.coinduced f T_X \u2264 T_Y :=\ncontinuous_iff_coinduced_le\n\n-- QUOTE.\n\n/- TEXT:\nWith this definition and the compatibility of push-forward and composition, we \nget for free the universal property that, for any topological space :math:`Z`,\na function :math:`g : Y \u2192 Z` is continuous for the topology :math:`f_*T_X` if and only if\n:math:`g \u2218 f` is continuous.\n\n.. math::\n  g \\text{ continuous } &\u21d4 g_*(f_*T_X) \u2264 T_Z \\\\\n  &\u21d4 (g \u2218 f)_* T_X \u2264 T_Z \\\\\n  &\u21d4 g \u2218 f \\text{ continuous}\n\n\nBOTH: -/\n\n-- QUOTE:\n\nexample {Z : Type*} (f : X \u2192 Y) \n  (T_X : topological_space X) (T_Z : topological_space Z) (g : Y \u2192 Z) :\n  @continuous Y Z (topological_space.coinduced f T_X) T_Z g \u2194 @continuous X Z T_X T_Z (g \u2218 f) :=\nby rw [continuous_iff_coinduced_le, coinduced_compose, continuous_iff_coinduced_le]\n\n-- QUOTE.\n\n/- TEXT:\n\nSo we already get quotient topologies (using the projection map as ``f``). This wasn't using that \n``topological_space X`` is a complete lattice for all ``X``. Let's now see how all this structure\nproves the existence of the product topology by abstract non-sense.\nWe considered the case of ``\u211d \u2192 \u211d`` above, but let's now consider the general case of ``\u03a0 i, X i`` for\nsome ``\u03b9 : Type*`` and ``X : \u03b9 \u2192 Type*``. We want, for any topological space ``Z`` and any function\n``f : Z \u2192 \u03a0 i, X i``, that ``f`` is continuous if and only if ``(\u03bb x, x i) \u2218 f`` is continuous.\nLet us explore that constraint \"on papar\" using notation :math:`p_i` for the projection \n``(\u03bb (x : \u03a0 i, X i), x i)``:\n\n.. math::\n  (\u2200 i, p_i \u2218 f \\text{ continuous}) &\u21d4 \u2200 i, (p_i \u2218 f)_* T_Z \u2264 T_{X_i} \\\\\n  &\u21d4 \u2200 i, (p_i)_* f_* T_Z \u2264 T_{X_i}\\\\\n  &\u21d4 \u2200 i, f_* T_Z \u2264 (p_i)^*T_{X_i}\\\\ \n  &\u21d4  f_* T_Z \u2264 \\inf \\left[(p_i)^*T_{X_i}\\right]\n\nSo we see that what is the topology we want on ``\u03a0 i, X i``:\nBOTH: -/\n\n-- QUOTE:\nexample (\u03b9 : Type*) (X : \u03b9 \u2192 Type*) (T_X : \u03a0 i, topological_space $ X i) :\n  (Pi.topological_space : topological_space (\u03a0 i, X i)) = \u2a05 i, topological_space.induced (\u03bb x, x i) (T_X i) :=\nrfl\n\n-- QUOTE.\n\n/- TEXT:\n\nThis ends our tour of how mathlib thinks that topological spaces fix defects of the theory of metric spaces\nby being a more functorial theory and having a complete lattice structure for any fixed type.\n\nSeparation and countability\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nWe saw that the category of topological spaces have very nice properties. The price to pay for\nthis is existence of rather pathological topological spaces. \nThere are a number of assumptions you can make on a topological space to ensure its behavior\nis closer to what metric spaces do. The most important is ``t2_space``, also called \"Hausdorff\", \nthat will ensure that limits are unique.\nA stronger separation property is regularity that ensure that each point has a basis of closed\nneighborhood. \n\nBOTH: -/\n\n-- QUOTE:\n\nexample [topological_space X] [t2_space X] {u : \u2115 \u2192 X} {a b : X} \n  (ha : tendsto u at_top (\ud835\udcdd a)) (hb : tendsto u at_top (\ud835\udcdd b)) : a = b :=\ntendsto_nhds_unique ha hb\n\nexample [topological_space X] [regular_space X] (a : X) :\n    (\ud835\udcdd a).has_basis (\u03bb (s : set X), s \u2208 \ud835\udcdd a \u2227 is_closed s) id :=\nclosed_nhds_basis a\n-- QUOTE.\n\n/- TEXT:\nNote that, in every topological space, each point has a basis of open neighborhood, by definition.\n\nBOTH: -/\n\n-- QUOTE:\nexample [topological_space X] {x : X} : (\ud835\udcdd x).has_basis (\u03bb t : set X, t \u2208 \ud835\udcdd x \u2227 is_open t) id :=\nnhds_basis_opens' x\n-- QUOTE.\n\n/- TEXT:\nOur main goal is now to prove the basic theorem which allows extension by continuity.\nFrom Bourbaki's general topology book, I.8.5, Theorem 1 (taking only the non-trivial implication):\n\nLet :math:`X` be a topological space, :math:`A` a dense subset of :math:`X`, :math:`f : A \u2192 Y`  \na continuous mapping of :math:`A` into a regular space :math:`Y`. If, for each :math:`x` in :math:`X`, \n:math:`f(y)` tends to a limit in :math:`Y` when :math:`y` tends to :math:`x`\nwhile remaining in :math:`A` then there exists a continuous extension :math:`\u03c6` of :math:`f` to \n:math:`X`.\n\nActually ``mathlib`` contains a more general version of the above lemma, ``dense_inducing.continuous_at_extend``,\nbut we'll stick to Bourbaki's version here.\n\nRemember that, given ``A : set X``, ``\u21a5A`` is the subtype associated to ``A``, and Lean will automatically\ninsert that funny up arrow when needed. And the (inclusion) coercion map is ``coe : A \u2192 X``.\nThe assumption \"tends to :math:`x` while remaining in :math:`A`\" corresponds to the pull-back filter\n``comap coe (\ud835\udcdd x)``.\n\nLet's prove first an auxilliary lemma, extracted to simplify the context\n(in particular we don't need Y to be a topological space here).\n\nBOTH: -/\n\n-- QUOTE:\nlemma aux {X Y A : Type*} [topological_space X] {c : A \u2192 X} {f : A \u2192 Y} {x : X} {F : filter Y}\n  (h : tendsto f (comap c (\ud835\udcdd x)) F) {V' : set Y} (V'_in : V' \u2208 F) :\n  \u2203 V \u2208 \ud835\udcdd x, is_open V \u2227 c \u207b\u00b9' V \u2286 f \u207b\u00b9' V' :=\nsorry\n\n-- QUOTE.\n\n-- SOLUTIONS:\nexample {X Y A : Type*} [topological_space X] {c : A \u2192 X} {f : A \u2192 Y} {x : X} {F : filter Y}\n  (h : tendsto f (comap c (\ud835\udcdd x)) F) {V' : set Y} (V'_in : V' \u2208 F) :\n  \u2203 V \u2208 \ud835\udcdd x, is_open V \u2227 c \u207b\u00b9' V \u2286 f \u207b\u00b9' V' :=\nbegin\n  simpa [and_assoc] using ((nhds_basis_opens' x).comap c).tendsto_left_iff.mp h V' V'_in\nend\n\n/- TEXT:\nLet's now turn to the main proof of the extension by continuity theorem.\n\nWhen Lean needs a topology on ``\u21a5A`` it will use the induced topology, thanks to the instance\n``subtype.topological_space``.\nThis all happens automatically. The only relevant lemma is\n``nhds_induced coe : \u2200 a : \u21a5A, \ud835\udcdd a = comap coe (\ud835\udcdd \u2191a)``\n(this is actually a general lemma about induced topologies).\n\nThe proof outline is:\n\nThe main assumption and the axiom of choice give a function ``\u03c6`` such that\n``\u2200 x, tendsto f (comap coe $ \ud835\udcdd x) (\ud835\udcdd (\u03c6 x))``\n(because ``Y`` is Hausdorff, ``\u03c6`` is entirely determined, but we won't need that until we try to\nprove that ``\u03c6`` indeed extends ``f``).\n\nLet's first prove ``\u03c6`` is continuous. Fix any ``x : X``.\nSince ``Y`` is regular, it suffices to check that for every *closed* neighborhood\n``V'`` of ``\u03c6 x``, ``\u03c6 \u207b\u00b9' V' \u2208 \ud835\udcdd x``.\nThe limit assumption gives (through the auxilliary lemma above)\nsome ``V \u2208 \ud835\udcdd x`` such ``is_open V \u2227 coe \u207b\u00b9' V \u2286 f \u207b\u00b9' V'``.\nSince ``V \u2208 \ud835\udcdd x``, it suffices to prove ``V \u2286 \u03c6 \u207b\u00b9' V'``, ie  ``\u2200 y \u2208 V, \u03c6 y \u2208 V'``.\nLet's fix ``y`` in ``V``. Because ``V`` is *open*, it is a neighborhood of ``y``.\nIn particular ``coe \u207b\u00b9' V \u2208 comap coe (\ud835\udcdd y)`` and a fortiori ``f \u207b\u00b9' V' \u2208 comap coe (\ud835\udcdd y)``.\nIn addition ``comap coe $ \ud835\udcdd y \u2260 \u22a5`` because ``A`` is dense.\nBecause we know ``tendsto f (comap coe $ \ud835\udcdd y) (\ud835\udcdd (\u03c6 y))`` this implies\n``\u03c6 y \u2208 closure V'`` and, since ``V'`` is closed, we have proved ``\u03c6 y \u2208 V'``.\n\nIt remains to prove that ``\u03c6`` extends ``f``. This is were continuity of ``f`` enters the discussion,\ntogether with the fact that ``Y`` is Hausdorff.\nBOTH: -/\n\n-- QUOTE:\n\nexample [topological_space X] [topological_space Y] [regular_space Y] \n  {A : set X} (hA : \u2200 x, x \u2208 closure A)\n  {f : A \u2192 Y} (f_cont : continuous f)\n  (hf : \u2200 x : X, \u2203 c : Y, tendsto f (comap coe $ \ud835\udcdd x) $ \ud835\udcdd c) :\n  \u2203 \u03c6 : X \u2192 Y, continuous \u03c6 \u2227 \u2200 a : A, \u03c6 a = f a :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\n\nexample [topological_space X] [topological_space Y] [regular_space Y] {A : set X} (hA : \u2200 x, x \u2208 closure A)\n  {f : A \u2192 Y} (f_cont : continuous f)\n  (hf : \u2200 x : X, \u2203 c : Y, tendsto f (comap coe $ \ud835\udcdd x) $ \ud835\udcdd c) :\n  \u2203 \u03c6 : X \u2192 Y, continuous \u03c6 \u2227 \u2200 a : A, \u03c6 a = f a :=\nbegin\n  choose \u03c6 h\u03c6 using hf,\n  use \u03c6,\n  split,\n  { rw continuous_iff_continuous_at,\n    intros x,\n    suffices : \u2200 V' \u2208 \ud835\udcdd (\u03c6 x), is_closed V' \u2192 \u03c6 \u207b\u00b9' V' \u2208 \ud835\udcdd x,\n      by simpa [continuous_at, (closed_nhds_basis _).tendsto_right_iff],\n    intros V' V'_in V'_closed,\n    obtain \u27e8V, V_in, V_op, hV\u27e9 : \u2203 V \u2208 \ud835\udcdd x, is_open V \u2227 coe \u207b\u00b9' V \u2286 f \u207b\u00b9' V',\n    { exact aux (h\u03c6 x) V'_in },\n    suffices : \u2200 y \u2208 V, \u03c6 y \u2208 V',\n      from mem_of_superset V_in this,\n    intros y y_in,\n    have hVx : V \u2208 \ud835\udcdd y := V_op.mem_nhds y_in,\n    haveI : (comap (coe : A \u2192 X) (\ud835\udcdd y)).ne_bot := by simpa [mem_closure_iff_comap_ne_bot] using hA y,\n    apply V'_closed.mem_of_tendsto (h\u03c6 y),\n    exact mem_of_superset (preimage_mem_comap hVx) hV },\n  { intros a,\n    have lim : tendsto f (\ud835\udcdd a) (\ud835\udcdd $ \u03c6 a),\n      by simpa [nhds_induced] using h\u03c6 a,\n    exact tendsto_nhds_unique lim f_cont.continuous_at },\nend\n\n\n/- TEXT:\nIn addition to separation property, the main kind of assumption you can make on a topological\nspace to bring it closer to metric spaces is countability assumption. The main one is first countability\nasking that every point has a countable neighborhood basic. In particular this ensures that closure\nof sets can be understood using sequences.\n\nBOTH: -/\n\n-- QUOTE:\n\nexample [topological_space X] [topological_space.first_countable_topology X] {s : set X} {a : X} :\n  a \u2208 closure s \u2194 \u2203 (u : \u2115 \u2192 X), (\u2200 n, u n \u2208 s) \u2227 tendsto u at_top (\ud835\udcdd a) :=\nmem_closure_iff_seq_limit\n\n-- QUOTE.\n\n/- TEXT:\nCompactness\n^^^^^^^^^^^\n\nLet us now discuss how compactness is defined for topological spaces. As usual there are several ways\nto think about it and mathlib goes for the filter version.\n\nWe first need to define cluster points of filters. Given a filter ``F`` on a topological space ``X``,\na point ``x : X`` is a cluster point of ``F`` if ``F``, seen as a generalized set, has non-empty intersection\nwith the generalized set of points that are close to ``x``.\n\nThen we can say that a set ``s`` is compact if every nonempty generalized set ``F`` contained in ``s``,\nie such that ``F \u2264 \ud835\udcdf s``, has a cluster point in ``s``. \n\nBOTH: -/\n\n-- QUOTE:\nvariables [topological_space X]\n\nexample {F : filter X} {x : X} : cluster_pt x F \u2194 ne_bot (\ud835\udcdd x \u2293 F) :=\niff.rfl\n\nexample {s : set X} : \n  is_compact s \u2194 \u2200 (F : filter X) [ne_bot F], F \u2264 \ud835\udcdf s \u2192 \u2203 a \u2208 s, cluster_pt a F :=\niff.rfl\n-- QUOTE.\n\n/- TEXT:\nFor instance if ``F`` is ``map u at_top``, the image under ``u : \u2115 \u2192 X`` of ``at_top``, the generalized set \nof very large natural numbers, then the assumption ``F \u2264 \ud835\udcdf s`` means that ``u n`` belongs to ``s`` for ``n``\nlarge enough. Saying that ``x`` is a cluster point of ``map u at_top`` says the image of very large numbers\nintersects the set of points that are close to ``x``. In case ``\ud835\udcdd x`` has a countable basis, we can\ninterpret this as saying that ``u`` has a subsequence converging to ``x``, and we get back what compactness\nlooks like in metric spaces.\nBOTH: -/\n\n-- QUOTE:\nexample [topological_space.first_countable_topology X] \n  {s : set X} {u : \u2115 \u2192 X} (hs : is_compact s) (hu : \u2200 n, u n \u2208 s) :\n  \u2203 (a \u2208 s) (\u03c6 : \u2115 \u2192 \u2115), strict_mono \u03c6 \u2227 tendsto (u \u2218 \u03c6) at_top (\ud835\udcdd a) :=\nhs.tendsto_subseq hu\n-- QUOTE.\n\n/- TEXT:\nCluster points behave nicely with continuous functions.\n\nBOTH: -/\n\n-- QUOTE:\n\nvariables [topological_space Y]\n\nexample {x : X} {F : filter X} {G : filter Y} (H : cluster_pt x F)\n  {f : X \u2192 Y} (hfx : continuous_at f x) (hf : tendsto f F G) :\n  cluster_pt (f x) G :=\ncluster_pt.map H hfx hf\n-- QUOTE.\n\n/- TEXT:\nAs an exercise, we will prove that the image of a compact set under a continuous map is\ncompact. In addition to what we saw already, you should use ``filter.push_pull`` and\n``ne_bot.of_map``.\nBOTH: -/\n\n-- QUOTE:\nexample [topological_space Y] {f : X  \u2192 Y} (hf : continuous f) \n  {s : set X} (hs : is_compact s) : is_compact (f '' s) :=\nbegin\n  intros F F_ne F_le,\n  have map_eq : map f (\ud835\udcdf s \u2293 comap f F) = \ud835\udcdf (f '' s) \u2293 F,\n  { sorry },\n  haveI Hne : (\ud835\udcdf s \u2293 comap f F).ne_bot,\n  { sorry },\n  have Hle : \ud835\udcdf s \u2293 comap f F \u2264 \ud835\udcdf s, from inf_le_left,\n  sorry\nend\n-- QUOTE.\n\n-- SOLUTIONS:\nexample [topological_space Y] {f : X  \u2192 Y} (hf : continuous f) \n  {s : set X} (hs : is_compact s) : is_compact (f '' s) :=\nbegin\n  intros F F_ne F_le,\n  have map_eq : map f (\ud835\udcdf s \u2293 comap f F) = \ud835\udcdf (f '' s) \u2293 F,\n  { rw [filter.push_pull, map_principal] },\n  haveI Hne : (\ud835\udcdf s \u2293 comap f F).ne_bot,\n  { apply ne_bot.of_map,\n    rwa [map_eq, inf_of_le_right F_le] },\n  have Hle : \ud835\udcdf s \u2293 comap f F \u2264 \ud835\udcdf s, from inf_le_left,\n  rcases hs Hle with \u27e8x, x_in, hx\u27e9,\n  refine \u27e8f x, mem_image_of_mem f x_in, _\u27e9,\n  apply hx.map hf.continuous_at,\n  rw [tendsto, map_eq],\n  exact inf_le_right\nend\n\n/- TEXT:\n\n\nOne can also express compactness in terms of open covers: ``s`` is compact if every family of open sets that\ncover ``s`` has a finite covering sub-family.\n\nBOTH: -/\n\n-- QUOTE:\nexample {\u03b9 : Type*} {s : set X} (hs : is_compact s)\n  (U : \u03b9 \u2192 set X) (hUo : \u2200 i, is_open (U i)) (hsU : s \u2286 \u22c3 i, U i) :\n  \u2203 t : finset \u03b9, s \u2286 \u22c3 i \u2208 t, U i :=\nhs.elim_finite_subcover U hUo hsU\n\n-- QUOTE.\n\n/- TEXT:\nA topological space ``X`` is compact if ``(univ : set X)`` is compact.\nBOTH: -/\n\n-- QUOTE:\nexample [compact_space X] : is_compact (univ : set X) :=\ncompact_univ\n-- QUOTE.\n", "meta": {"author": "avigad", "repo": "mathematics_in_lean_source", "sha": "4eeb8c43762522c1acaa7f799599609d6a48f59e", "save_path": "github-repos/lean/avigad-mathematics_in_lean_source", "path": "github-repos/lean/avigad-mathematics_in_lean_source/mathematics_in_lean_source-4eeb8c43762522c1acaa7f799599609d6a48f59e/lean_source/07_Topology/source_03_Topological_Spaces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7081549774826289}}
{"text": "/-\nCopyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Abhimanyu Pallavi Sudhir, Yury Kudryashov\n-/\nimport order.filter.ultrafilter\nimport order.filter.germ\n\n/-!\n# Ultraproducts\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIf `\u03c6` is an ultrafilter, then the space of germs of functions `f : \u03b1 \u2192 \u03b2` at `\u03c6` is called\nthe *ultraproduct*. In this file we prove properties of ultraproducts that rely on `\u03c6` being an\nultrafilter. Definitions and properties that work for any filter should go to `order.filter.germ`.\n\n## Tags\n\nultrafilter, ultraproduct\n-/\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03c6 : ultrafilter \u03b1}\nopen_locale classical\n\nnamespace filter\n\nlocal notation `\u2200*` binders `, ` r:(scoped p, filter.eventually p \u03c6) := r\n\nnamespace germ\n\nopen ultrafilter\n\nlocal notation `\u03b2*` := germ (\u03c6 : filter \u03b1) \u03b2\n\ninstance [division_semiring \u03b2] : division_semiring \u03b2* :=\n{ mul_inv_cancel := \u03bb f, induction_on f $ \u03bb f hf, coe_eq.2 $ (\u03c6.em (\u03bb y, f y = 0)).elim\n    (\u03bb H, (hf $ coe_eq.2 H).elim) (\u03bb H, H.mono $ \u03bb x, mul_inv_cancel),\n  inv_zero := coe_eq.2 $ by simp only [(\u2218), inv_zero],\n  ..germ.semiring, ..germ.div_inv_monoid, ..germ.nontrivial }\n\ninstance [division_ring \u03b2] : division_ring \u03b2* := { ..germ.ring, ..germ.division_semiring }\ninstance [semifield \u03b2] : semifield \u03b2* := { ..germ.comm_semiring, ..germ.division_semiring }\ninstance [field \u03b2] : field \u03b2* := { ..germ.comm_ring, ..germ.division_ring }\n\nlemma coe_lt [preorder \u03b2] {f g : \u03b1 \u2192 \u03b2} : (f : \u03b2*) < g \u2194 \u2200* x, f x < g x :=\nby simp only [lt_iff_le_not_le, eventually_and, coe_le, eventually_not, eventually_le]\n\nlemma coe_pos [preorder \u03b2] [has_zero \u03b2] {f : \u03b1 \u2192 \u03b2} : 0 < (f : \u03b2*) \u2194 \u2200* x, 0 < f x := coe_lt\n\nlemma const_lt [preorder \u03b2] {x y : \u03b2} : x < y \u2192 (\u2191x : \u03b2*) < \u2191y := coe_lt.mpr \u2218 lift_rel_const\n\n@[simp, norm_cast]\nlemma const_lt_iff [preorder \u03b2] {x y : \u03b2} : (\u2191x : \u03b2*) < \u2191y \u2194 x < y :=\ncoe_lt.trans lift_rel_const_iff\n\nlemma lt_def [preorder \u03b2] : ((<) : \u03b2* \u2192 \u03b2* \u2192 Prop) = lift_rel (<) :=\nby { ext \u27e8f\u27e9 \u27e8g\u27e9, exact coe_lt }\n\ninstance [has_sup \u03b2] : has_sup \u03b2* := \u27e8map\u2082 (\u2294)\u27e9\ninstance [has_inf \u03b2] : has_inf \u03b2* := \u27e8map\u2082 (\u2293)\u27e9\n\n@[simp, norm_cast] lemma const_sup [has_sup \u03b2] (a b : \u03b2) : \u2191(a \u2294 b) = (\u2191a \u2294 \u2191b : \u03b2*) := rfl\n@[simp, norm_cast] lemma const_inf [has_inf \u03b2] (a b : \u03b2) : \u2191(a \u2293 b) = (\u2191a \u2293 \u2191b : \u03b2*) := rfl\n\ninstance [semilattice_sup \u03b2] : semilattice_sup \u03b2* :=\n{ sup := (\u2294),\n  le_sup_left := \u03bb f g, induction_on\u2082 f g $ \u03bb f g,\n    eventually_of_forall $ \u03bb x, le_sup_left,\n  le_sup_right := \u03bb f g, induction_on\u2082 f g $ \u03bb f g,\n    eventually_of_forall $ \u03bb x, le_sup_right,\n  sup_le := \u03bb f\u2081 f\u2082 g, induction_on\u2083 f\u2081 f\u2082 g $ \u03bb f\u2081 f\u2082 g h\u2081 h\u2082,\n    h\u2082.mp $ h\u2081.mono $ \u03bb x, sup_le,\n  .. germ.partial_order }\n\ninstance [semilattice_inf \u03b2] : semilattice_inf \u03b2* :=\n{ inf := (\u2293),\n  inf_le_left := \u03bb f g, induction_on\u2082 f g $ \u03bb f g,\n    eventually_of_forall $ \u03bb x, inf_le_left,\n  inf_le_right := \u03bb f g, induction_on\u2082 f g $ \u03bb f g,\n    eventually_of_forall $ \u03bb x, inf_le_right,\n  le_inf := \u03bb f\u2081 f\u2082 g, induction_on\u2083 f\u2081 f\u2082 g $ \u03bb f\u2081 f\u2082 g h\u2081 h\u2082,\n    h\u2082.mp $ h\u2081.mono $ \u03bb x, le_inf,\n  .. germ.partial_order }\n\ninstance [lattice \u03b2] : lattice \u03b2* :=\n{ .. germ.semilattice_sup, .. germ.semilattice_inf }\n\ninstance [distrib_lattice \u03b2] : distrib_lattice \u03b2* :=\n{ le_sup_inf := \u03bb f g h, induction_on\u2083 f g h $ \u03bb f g h, eventually_of_forall $ \u03bb _, le_sup_inf,\n  .. germ.semilattice_sup, .. germ.semilattice_inf }\n\ninstance [has_le \u03b2] [is_total \u03b2 (\u2264)] : is_total \u03b2* (\u2264) :=\n\u27e8\u03bb f g, induction_on\u2082 f g $ \u03bb f g, eventually_or.1 $ eventually_of_forall $ \u03bb x, total_of _ _ _\u27e9\n\n/-- If `\u03c6` is an ultrafilter then the ultraproduct is a linear order. -/\nnoncomputable instance [linear_order \u03b2] : linear_order \u03b2* := lattice.to_linear_order _\n\n@[to_additive]\ninstance [ordered_comm_monoid \u03b2] : ordered_comm_monoid \u03b2* :=\n{ mul_le_mul_left := \u03bb f g, induction_on\u2082 f g $ \u03bb f g H h, induction_on h $ \u03bb h,\n    H.mono $ \u03bb x H, mul_le_mul_left' H _,\n  .. germ.partial_order, .. germ.comm_monoid }\n\n@[to_additive]\ninstance [ordered_cancel_comm_monoid \u03b2] : ordered_cancel_comm_monoid \u03b2* :=\n{ le_of_mul_le_mul_left := \u03bb f g h, induction_on\u2083 f g h $ \u03bb f g h H,\n    H.mono $ \u03bb x, le_of_mul_le_mul_left',\n  .. germ.partial_order, .. germ.ordered_comm_monoid }\n\n@[to_additive]\ninstance [ordered_comm_group \u03b2] : ordered_comm_group \u03b2* :=\n{ .. germ.ordered_cancel_comm_monoid, .. germ.comm_group }\n\n@[to_additive]\nnoncomputable instance [linear_ordered_comm_group \u03b2] : linear_ordered_comm_group \u03b2* :=\n{ .. germ.ordered_comm_group, .. germ.linear_order }\n\ninstance [ordered_semiring \u03b2] : ordered_semiring \u03b2* :=\n{ zero_le_one := const_le zero_le_one,\n  mul_le_mul_of_nonneg_left := \u03bb x y z, induction_on\u2083 x y z $ \u03bb f g h hfg hh, hh.mp $\n    hfg.mono $ \u03bb a, mul_le_mul_of_nonneg_left,\n  mul_le_mul_of_nonneg_right := \u03bb x y z, induction_on\u2083 x y z $ \u03bb f g h hfg hh, hh.mp $\n    hfg.mono $ \u03bb a, mul_le_mul_of_nonneg_right,\n  ..germ.semiring, ..germ.ordered_add_comm_monoid }\n\ninstance [ordered_comm_semiring \u03b2] : ordered_comm_semiring \u03b2* :=\n{ ..germ.ordered_semiring, ..germ.comm_semiring }\n\ninstance [ordered_ring \u03b2] : ordered_ring \u03b2* :=\n{ zero_le_one := const_le zero_le_one,\n  mul_nonneg := \u03bb x y, induction_on\u2082 x y $ \u03bb f g hf hg, hg.mp $ hf.mono $ \u03bb a, mul_nonneg,\n  ..germ.ring, ..germ.ordered_add_comm_group }\n\ninstance [ordered_comm_ring \u03b2] : ordered_comm_ring \u03b2* :=\n{ ..germ.ordered_ring, ..germ.ordered_comm_semiring }\n\ninstance [strict_ordered_semiring \u03b2] : strict_ordered_semiring \u03b2* :=\n{ mul_lt_mul_of_pos_left := \u03bb x y z, induction_on\u2083 x y z $ \u03bb f g h hfg hh, coe_lt.2 $\n   (coe_lt.1 hh).mp $ (coe_lt.1 hfg).mono $ \u03bb a, mul_lt_mul_of_pos_left,\n  mul_lt_mul_of_pos_right := \u03bb x y z, induction_on\u2083 x y z $ \u03bb f g h hfg hh, coe_lt.2 $\n   (coe_lt.1 hh).mp $ (coe_lt.1 hfg).mono $ \u03bb a, mul_lt_mul_of_pos_right,\n  ..germ.ordered_semiring, ..germ.ordered_cancel_add_comm_monoid, ..germ.nontrivial }\n\ninstance [strict_ordered_comm_semiring \u03b2] : strict_ordered_comm_semiring \u03b2* :=\n{ .. germ.strict_ordered_semiring, ..germ.ordered_comm_semiring }\n\ninstance [strict_ordered_ring \u03b2] : strict_ordered_ring \u03b2* :=\n{ zero_le_one := const_le zero_le_one,\n  mul_pos := \u03bb x y, induction_on\u2082 x y $ \u03bb f g hf hg, coe_pos.2 $\n    (coe_pos.1 hg).mp $ (coe_pos.1 hf).mono $ \u03bb x, mul_pos,\n  ..germ.ring, ..germ.strict_ordered_semiring }\n\ninstance [strict_ordered_comm_ring \u03b2] : strict_ordered_comm_ring \u03b2* :=\n{ .. germ.strict_ordered_ring, ..germ.ordered_comm_ring }\n\nnoncomputable instance [linear_ordered_ring \u03b2] : linear_ordered_ring \u03b2* :=\n{ ..germ.strict_ordered_ring, ..germ.linear_order }\n\nnoncomputable instance [linear_ordered_field \u03b2] : linear_ordered_field \u03b2* :=\n{ .. germ.linear_ordered_ring, .. germ.field }\n\nnoncomputable instance [linear_ordered_comm_ring \u03b2] : linear_ordered_comm_ring \u03b2* :=\n{ .. germ.linear_ordered_ring, .. germ.comm_monoid }\n\n\n\nlemma min_def [K : linear_order \u03b2] (x y : \u03b2*) : min x y = map\u2082 min x y :=\ninduction_on\u2082 x y $ \u03bb a b,\nbegin\n  cases le_total (a : \u03b2*) b,\n  { rw [min_eq_left h, map\u2082_coe, coe_eq], exact h.mono (\u03bb i hi, (min_eq_left hi).symm) },\n  { rw [min_eq_right h, map\u2082_coe, coe_eq], exact h.mono (\u03bb i hi, (min_eq_right hi).symm) }\nend\n\nlemma abs_def [linear_ordered_add_comm_group \u03b2] (x : \u03b2*) : |x| = map abs x :=\ninduction_on x $ \u03bb a, by exact rfl\n\n@[simp] lemma const_max [linear_order \u03b2] (x y : \u03b2) : (\u2191(max x y : \u03b2) : \u03b2*) = max \u2191x \u2191y :=\nby rw [max_def, map\u2082_const]\n\n@[simp] lemma const_min [linear_order \u03b2] (x y : \u03b2) : (\u2191(min x y : \u03b2) : \u03b2*) = min \u2191x \u2191y :=\nby rw [min_def, map\u2082_const]\n\n@[simp] lemma const_abs [linear_ordered_add_comm_group \u03b2] (x : \u03b2) :\n  (\u2191(|x|) : \u03b2*) = |\u2191x| :=\nby rw [abs_def, map_const]\n\nend germ\n\nend filter\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/filter/filter_product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7081549761057562}}
{"text": "-- ----------------------------------------------------\n-- Ejercicio. Demostrar\n--    \u22a2 (p \u2192 q) \u2228 (q \u2192 p)\n-- ----------------------------------------------------\n\nimport tactic\nvariables (p q : Prop)\n\nopen_locale classical\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nbegin\n  by_cases H1 : p,\n  { right,\n    intro,\n    exact H1, },\n  { left,\n    intro H2,\n    exfalso,\n    exact H1 H2, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nbegin\n  cases (em p) with Hp Hnp,\n  { exact or.inr (\u03bb Hq, Hp), },\n  { exact or.inl (\u03bb Hp, not.elim Hnp Hp), },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nor.elim (em p)\n  (\u03bb Hp, or.inr (\u03bb Hq, Hp))\n  (\u03bb Hnp, or.inl (\u03bb Hp, not.elim Hnp Hp))\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nif Hp : p\n   then or.inr (\u03bb _, Hp)\n   else or.inl (\u03bb H, not.elim Hp H)\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\n-- by hint\nby tauto\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  (p \u2192 q) \u2228 (q \u2192 p) :=\nby finish\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/1_Proposicional/Ejercicios/\u22a2(p\u2192q)\u2228(q\u2192p).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7081549734743382}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n-/\nimport computability.DFA\nimport data.fintype.powerset\n\n/-!\n# Nondeterministic Finite Automata\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\nThis file contains the definition of a Nondeterministic Finite Automaton (NFA), a state machine\nwhich determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular\nset by evaluating the string over every possible path.\nWe show that DFA's are equivalent to NFA's however the construction from NFA to DFA uses an\nexponential number of states.\nNote that this definition allows for Automaton with infinite states, a `fintype` instance must be\nsupplied for true NFA's.\n-/\n\nopen set\nopen_locale computability\n\nuniverses u v\n\n/-- An NFA is a set of states (`\u03c3`), a transition function from state to state labelled by the\n  alphabet (`step`), a starting state (`start`) and a set of acceptance states (`accept`).\n  Note the transition function sends a state to a `set` of states. These are the states that it\n  may be sent to. -/\nstructure NFA (\u03b1 : Type u) (\u03c3 : Type v) :=\n(step : \u03c3 \u2192 \u03b1 \u2192 set \u03c3)\n(start : set \u03c3)\n(accept : set \u03c3)\n\nvariables {\u03b1 : Type u} {\u03c3 \u03c3' : Type v} (M : NFA \u03b1 \u03c3)\n\nnamespace NFA\n\ninstance : inhabited (NFA \u03b1 \u03c3) := \u27e8 NFA.mk (\u03bb _ _, \u2205) \u2205 \u2205 \u27e9\n\n/-- `M.step_set S a` is the union of `M.step s a` for all `s \u2208 S`. -/\ndef step_set (S : set \u03c3) (a : \u03b1) : set \u03c3 := \u22c3 s \u2208 S, M.step s a\n\n\n\n@[simp] lemma step_set_empty (a : \u03b1) : M.step_set \u2205 a = \u2205 :=\nby simp_rw [step_set, Union_false, Union_empty]\n\n/-- `M.eval_from S x` computes all possible paths though `M` with input `x` starting at an element\n  of `S`. -/\ndef eval_from (start : set \u03c3) : list \u03b1 \u2192 set \u03c3 :=\nlist.foldl M.step_set start\n\n@[simp] lemma eval_from_nil (S : set \u03c3) : M.eval_from S [] = S := rfl\n@[simp] lemma eval_from_singleton (S : set \u03c3) (a : \u03b1) : M.eval_from S [a] = M.step_set S a := rfl\n@[simp] lemma eval_from_append_singleton (S : set \u03c3) (x : list \u03b1) (a : \u03b1) :\n  M.eval_from S (x ++ [a]) = M.step_set (M.eval_from S x) a :=\nby simp only [eval_from, list.foldl_append, list.foldl_cons, list.foldl_nil]\n\n/-- `M.eval x` computes all possible paths though `M` with input `x` starting at an element of\n  `M.start`. -/\ndef eval : list \u03b1 \u2192 set \u03c3 := M.eval_from M.start\n\n@[simp] lemma eval_nil : M.eval [] = M.start := rfl\n@[simp] lemma eval_singleton (a : \u03b1) : M.eval [a] = M.step_set M.start a := rfl\n@[simp] lemma eval_append_singleton (x : list \u03b1) (a : \u03b1) :\n  M.eval (x ++ [a]) = M.step_set (M.eval x) a :=\neval_from_append_singleton _ _ _ _\n\n/-- `M.accepts` is the language of `x` such that there is an accept state in `M.eval x`. -/\ndef accepts : language \u03b1 :=\n\u03bb x, \u2203 S \u2208 M.accept, S \u2208 M.eval x\n\n/-- `M.to_DFA` is an `DFA` constructed from a `NFA` `M` using the subset construction. The\n  states is the type of `set`s of `M.state` and the step function is `M.step_set`. -/\ndef to_DFA : DFA \u03b1 (set \u03c3) :=\n{ step := M.step_set,\n  start := M.start,\n  accept := {S | \u2203 s \u2208 S, s \u2208 M.accept} }\n\n@[simp] lemma to_DFA_correct :\n  M.to_DFA.accepts = M.accepts :=\nbegin\n  ext x,\n  rw [accepts, DFA.accepts, eval, DFA.eval],\n  change list.foldl _ _ _ \u2208 {S | _} \u2194 _,\n  split; { exact \u03bb \u27e8w, h2, h3\u27e9, \u27e8w, h3, h2\u27e9 },\nend\n\nlemma pumping_lemma [fintype \u03c3] {x : list \u03b1} (hx : x \u2208 M.accepts)\n  (hlen : fintype.card (set \u03c3) \u2264 list.length x) :\n  \u2203 a b c, x = a ++ b ++ c \u2227 a.length + b.length \u2264 fintype.card (set \u03c3) \u2227 b \u2260 [] \u2227\n    {a} * {b}\u2217 * {c} \u2264 M.accepts :=\nbegin\n  rw \u2190to_DFA_correct at hx \u22a2,\n  exact M.to_DFA.pumping_lemma hx hlen\nend\n\nend NFA\n\nnamespace DFA\n\n/-- `M.to_NFA` is an `NFA` constructed from a `DFA` `M` by using the same start and accept\n  states and a transition function which sends `s` with input `a` to the singleton `M.step s a`. -/\ndef to_NFA (M : DFA \u03b1 \u03c3') : NFA \u03b1 \u03c3' :=\n{ step := \u03bb s a, {M.step s a},\n  start := {M.start},\n  accept := M.accept }\n\n@[simp] lemma to_NFA_eval_from_match (M : DFA \u03b1 \u03c3) (start : \u03c3) (s : list \u03b1) :\n  M.to_NFA.eval_from {start} s = {M.eval_from start s} :=\nbegin\n  change list.foldl M.to_NFA.step_set {start} s = {list.foldl M.step start s},\n  induction s with a s ih generalizing start,\n  { tauto },\n  { rw [list.foldl, list.foldl,\n        show M.to_NFA.step_set {start} a = {M.step start a}, by simpa [NFA.step_set]],\n    tauto }\nend\n\n@[simp] lemma to_NFA_correct (M : DFA \u03b1 \u03c3) :\n  M.to_NFA.accepts = M.accepts :=\nbegin\n  ext x,\n  change (\u2203 S H, S \u2208 M.to_NFA.eval_from {M.start} x) \u2194 _,\n  rw to_NFA_eval_from_match,\n  split,\n  { rintro \u27e8 S, hS\u2081, hS\u2082 \u27e9,\n    rwa set.mem_singleton_iff.mp hS\u2082 at hS\u2081 },\n  { exact \u03bb h, \u27e8M.eval x, h, rfl\u27e9 }\nend\n\nend DFA\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/computability/NFA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7081549710938291}}
{"text": "\nuniverse u \nconstant \u03b1 : Type u\n#check \u03b1\n\ndef foo : (\u2115 \u2192 \u2115) \u2192 \u2115 := \u03bb f, f 0\n\n#check foo\n#print foo \n\ndef double (x : \u2115) : \u2115 := x + x\n#print double\n#check double 3\n#reduce double 3\n\ndef square (x : \u2115) : \u2115 := x * x\n#check square \n#reduce square 3\n\nconstants p q : Prop\ntheorem t1 : p \u2192 q \u2192 p := \u03bb hp : p, \u03bb hq : q, hp \n#print t1\n\n#check \u00acp \u2192 p \u2194 false\n\n#reduce true \u2227 false\n\n\ntheorem test (p q : Prop) (hp : p) (hq : q) : p \u2227 q \u2227 p :=\nbegin \n  apply and.intro,\n  exact hp,\n  apply and.intro,\n  exact hq,\n  exact hp\nend\n\nexample : \u2200 a b c : \u2115, a = b \u2192 a = c \u2192 c = b :=\nbegin \nintros,\ntransitivity a,\nsymmetry, \nassumption,\nassumption\nend \n\n\n\n\n\n", "meta": {"author": "swarnpriya", "repo": "Lean", "sha": "a0a9978fd058041eb1a09aec0e2dd7d19a7436a7", "save_path": "github-repos/lean/swarnpriya-Lean", "path": "github-repos/lean/swarnpriya-Lean/Lean-a0a9978fd058041eb1a09aec0e2dd7d19a7436a7/Formalization/test_lean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.70809465202274}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n-/\nimport algebra.group.pi\nimport group_theory.group_action\nimport data.support\nimport data.finset.lattice\n\n/-!\n# Indicator function\n\n- `indicator (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) (a : \u03b1)` is `f a` if `a \u2208 s` and is `0` otherwise.\n- `mul_indicator (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) (a : \u03b1)` is `f a` if `a \u2208 s` and is `1` otherwise.\n\n\n## Implementation note\n\nIn mathematics, an indicator function or a characteristic function is a function\nused to indicate membership of an element in a set `s`,\nhaving the value `1` for all elements of `s` and the value `0` otherwise.\nBut since it is usually used to restrict a function to a certain set `s`,\nwe let the indicator function take the value `f x` for some function `f`, instead of `1`.\nIf the usual indicator function is needed, just set `f` to be the constant function `\u03bbx, 1`.\n\n## Tags\nindicator, characteristic\n-/\n\nnoncomputable theory\nopen_locale classical big_operators\nopen function\n\nvariables {\u03b1 \u03b2 \u03b9 M N : Type*}\n\nnamespace set\n\nsection has_one\nvariables [has_one M] [has_one N] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1}\n\n/-- `indicator s f a` is `f a` if `a \u2208 s`, `0` otherwise.  -/\ndef indicator {M} [has_zero M] (s : set \u03b1) (f : \u03b1 \u2192 M) : \u03b1 \u2192 M := \u03bb x, if x \u2208 s then f x else 0\n\n/-- `mul_indicator s f a` is `f a` if `a \u2208 s`, `1` otherwise.  -/\n@[to_additive]\ndef mul_indicator (s : set \u03b1) (f : \u03b1 \u2192 M) : \u03b1 \u2192 M := \u03bb x, if x \u2208 s then f x else 1\n\n@[simp, to_additive] lemma piecewise_eq_mul_indicator : s.piecewise f 1 = s.mul_indicator f := rfl\n\n@[to_additive] lemma mul_indicator_apply (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s f a = if a \u2208 s then f a else 1 := rfl\n\n@[simp, to_additive] lemma mul_indicator_of_mem (h : a \u2208 s) (f : \u03b1 \u2192 M) :\n  mul_indicator s f a = f a := if_pos h\n\n@[simp, to_additive] lemma mul_indicator_of_not_mem (h : a \u2209 s) (f : \u03b1 \u2192 M) :\n  mul_indicator s f a = 1 := if_neg h\n\n@[to_additive] lemma mul_indicator_eq_one_or_self (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s f a = 1 \u2228 mul_indicator s f a = f a :=\nif h : a \u2208 s then or.inr (mul_indicator_of_mem h f) else or.inl (mul_indicator_of_not_mem h f)\n\n@[simp, to_additive] lemma mul_indicator_apply_eq_self :\n  s.mul_indicator f a = f a \u2194 (a \u2209 s \u2192 f a = 1) :=\nite_eq_left_iff.trans $ by rw [@eq_comm _ (f a)]\n\n@[simp, to_additive] lemma mul_indicator_eq_self : s.mul_indicator f = f \u2194 mul_support f \u2286 s :=\nby simp only [funext_iff, subset_def, mem_mul_support, mul_indicator_apply_eq_self, not_imp_comm]\n\n@[to_additive] lemma mul_indicator_eq_self_of_superset (h1 : s.mul_indicator f = f) (h2 : s \u2286 t) :\n  t.mul_indicator f = f :=\nby { rw mul_indicator_eq_self at h1 \u22a2, exact subset.trans h1 h2 }\n\n@[simp, to_additive] lemma mul_indicator_apply_eq_one :\n  mul_indicator s f a = 1 \u2194 (a \u2208 s \u2192 f a = 1) :=\nite_eq_right_iff\n\n@[simp, to_additive] lemma mul_indicator_eq_one :\n  mul_indicator s f = (\u03bb x, 1) \u2194 disjoint (mul_support f) s :=\nby simp only [funext_iff, mul_indicator_apply_eq_one, set.disjoint_left, mem_mul_support,\n  not_imp_not]\n\n@[simp, to_additive] lemma mul_indicator_eq_one' :\n  mul_indicator s f = 1 \u2194 disjoint (mul_support f) s :=\nmul_indicator_eq_one\n\n@[simp, to_additive] lemma mul_support_mul_indicator :\n  function.mul_support (s.mul_indicator f) = s \u2229 function.mul_support f :=\next $ \u03bb x, by simp [function.mem_mul_support, mul_indicator_apply_eq_one]\n\n/-- If a multiplicative indicator function is not equal to one at a point, then that\npoint is in the set. -/\n@[to_additive] lemma mem_of_mul_indicator_ne_one (h : mul_indicator s f a \u2260 1) : a \u2208 s :=\nnot_imp_comm.1 (\u03bb hn, mul_indicator_of_not_mem hn f) h\n\n@[to_additive] lemma eq_on_mul_indicator : eq_on (mul_indicator s f) f s :=\n\u03bb x hx, mul_indicator_of_mem hx f\n\n@[to_additive] lemma mul_support_mul_indicator_subset : mul_support (s.mul_indicator f) \u2286 s :=\n\u03bb x hx, hx.imp_symm (\u03bb h, mul_indicator_of_not_mem h f)\n\n@[simp, to_additive] lemma mul_indicator_mul_support : mul_indicator (mul_support f) f = f :=\nmul_indicator_eq_self.2 subset.rfl\n\n@[simp, to_additive] lemma mul_indicator_range_comp {\u03b9 : Sort*} (f : \u03b9 \u2192 \u03b1) (g : \u03b1 \u2192 M) :\n  mul_indicator (range f) g \u2218 f = g \u2218 f :=\npiecewise_range_comp _ _ _\n\n@[to_additive] lemma mul_indicator_congr (h : eq_on f g s) :\n  mul_indicator s f = mul_indicator s g :=\nfunext $ \u03bbx, by { simp only [mul_indicator], split_ifs, { exact h h_1 }, refl }\n\n@[simp, to_additive] lemma mul_indicator_univ (f : \u03b1 \u2192 M) : mul_indicator (univ : set \u03b1) f = f :=\nmul_indicator_eq_self.2 $ subset_univ _\n\n@[simp, to_additive] lemma mul_indicator_empty (f : \u03b1 \u2192 M) : mul_indicator (\u2205 : set \u03b1) f = \u03bba, 1 :=\nmul_indicator_eq_one.2 $ disjoint_empty _\n\nvariable (M)\n\n@[simp, to_additive] lemma mul_indicator_one (s : set \u03b1) :\n  mul_indicator s (\u03bbx, (1:M)) = \u03bbx, (1:M) :=\nmul_indicator_eq_one.2 $ by simp only [mul_support_one, empty_disjoint]\n\n@[simp, to_additive] lemma mul_indicator_one' {s : set \u03b1} : s.mul_indicator (1 : \u03b1 \u2192 M) = 1 :=\nmul_indicator_one M s\n\nvariable {M}\n\n@[to_additive] lemma mul_indicator_mul_indicator (s t : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator s (mul_indicator t f) = mul_indicator (s \u2229 t) f :=\nfunext $ \u03bbx, by { simp only [mul_indicator], split_ifs, repeat {simp * at * {contextual := tt}} }\n\n@[simp, to_additive] lemma mul_indicator_inter_mul_support (s : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator (s \u2229 mul_support f) f = mul_indicator s f :=\nby rw [\u2190 mul_indicator_mul_indicator, mul_indicator_mul_support]\n\n@[to_additive] lemma comp_mul_indicator (h : M \u2192 \u03b2) (f : \u03b1 \u2192 M) {s : set \u03b1} {x : \u03b1} :\n  h (s.mul_indicator f x) = s.piecewise (h \u2218 f) (const \u03b1 (h 1)) x :=\ns.apply_piecewise _ _ (\u03bb _, h)\n\n@[to_additive] lemma mul_indicator_comp_right {s : set \u03b1} (f : \u03b2 \u2192 \u03b1) {g : \u03b1 \u2192 M} {x : \u03b2} :\n  mul_indicator (f \u207b\u00b9' s) (g \u2218 f) x = mul_indicator s g (f x) :=\nby { simp only [mul_indicator], split_ifs; refl }\n\n@[to_additive] lemma mul_indicator_comp_of_one {g : M \u2192 N} (hg : g 1 = 1) :\n  mul_indicator s (g \u2218 f) = g \u2218 (mul_indicator s f) :=\nbegin\n  funext,\n  simp only [mul_indicator],\n  split_ifs; simp [*]\nend\n\n@[to_additive] lemma mul_indicator_preimage (s : set \u03b1) (f : \u03b1 \u2192 M) (B : set M) :\n  (mul_indicator s f)\u207b\u00b9' B = s.ite (f \u207b\u00b9' B) (1 \u207b\u00b9' B) :=\npiecewise_preimage s f 1 B\n\n@[to_additive] lemma mul_indicator_preimage_of_not_mem (s : set \u03b1) (f : \u03b1 \u2192 M)\n  {t : set M} (ht : (1:M) \u2209 t) :\n  (mul_indicator s f)\u207b\u00b9' t = f \u207b\u00b9' t \u2229 s :=\nby simp [mul_indicator_preimage, pi.one_def, set.preimage_const_of_not_mem ht]\n\n@[to_additive] lemma mem_range_mul_indicator {r : M} {s : set \u03b1} {f : \u03b1 \u2192 M} :\n  r \u2208 range (mul_indicator s f) \u2194 (r = 1 \u2227 s \u2260 univ) \u2228 (r \u2208 f '' s) :=\nby simp [mul_indicator, ite_eq_iff, exists_or_distrib, eq_univ_iff_forall, and_comm, or_comm,\n  @eq_comm _ r 1]\n\n@[to_additive] lemma mul_indicator_rel_mul_indicator {r : M \u2192 M \u2192 Prop} (h1 : r 1 1)\n  (ha : a \u2208 s \u2192 r (f a) (g a)) :\n  r (mul_indicator s f a) (mul_indicator s g a) :=\nby { simp only [mul_indicator], split_ifs with has has, exacts [ha has, h1] }\n\nend has_one\n\nsection monoid\nvariables [mul_one_class M] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1}\n\n@[to_additive] lemma mul_indicator_union_mul_inter_apply (f : \u03b1 \u2192 M) (s t : set \u03b1) (a : \u03b1) :\n  mul_indicator (s \u222a t) f a * mul_indicator (s \u2229 t) f a =\n    mul_indicator s f a * mul_indicator t f a :=\nby by_cases hs : a \u2208 s; by_cases ht : a \u2208 t; simp *\n\n@[to_additive] lemma mul_indicator_union_mul_inter (f : \u03b1 \u2192 M) (s t : set \u03b1) :\n  mul_indicator (s \u222a t) f * mul_indicator (s \u2229 t) f = mul_indicator s f * mul_indicator t f :=\nfunext $ mul_indicator_union_mul_inter_apply f s t\n\n@[to_additive] lemma mul_indicator_union_of_not_mem_inter (h : a \u2209 s \u2229 t) (f : \u03b1 \u2192 M) :\n  mul_indicator (s \u222a t) f a = mul_indicator s f a * mul_indicator t f a :=\nby rw [\u2190 mul_indicator_union_mul_inter_apply f s t, mul_indicator_of_not_mem h, mul_one]\n\n@[to_additive] lemma mul_indicator_union_of_disjoint (h : disjoint s t) (f : \u03b1 \u2192 M) :\n  mul_indicator (s \u222a t) f = \u03bba, mul_indicator s f a * mul_indicator t f a :=\nfunext $ \u03bba, mul_indicator_union_of_not_mem_inter (\u03bb ha, h ha) _\n\n@[to_additive] lemma mul_indicator_mul (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  mul_indicator s (\u03bba, f a * g a) = \u03bba, mul_indicator s f a * mul_indicator s g a :=\nby { funext, simp only [mul_indicator], split_ifs, { refl }, rw mul_one }\n\n@[simp, to_additive] lemma mul_indicator_compl_mul_self_apply (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s\u1d9c f a * mul_indicator s f a = f a :=\nclassical.by_cases (\u03bb ha : a \u2208 s, by simp [ha]) (\u03bb ha, by simp [ha])\n\n@[simp, to_additive] lemma mul_indicator_compl_mul_self (s : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator s\u1d9c f * mul_indicator s f = f :=\nfunext $ mul_indicator_compl_mul_self_apply s f\n\n@[simp, to_additive] lemma mul_indicator_self_mul_compl_apply (s : set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n  mul_indicator s f a * mul_indicator s\u1d9c f a = f a :=\nclassical.by_cases (\u03bb ha : a \u2208 s, by simp [ha]) (\u03bb ha, by simp [ha])\n\n@[simp, to_additive] lemma mul_indicator_self_mul_compl (s : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator s f * mul_indicator s\u1d9c f = f :=\nfunext $ mul_indicator_self_mul_compl_apply s f\n\n@[to_additive] lemma mul_indicator_mul_eq_left {f g : \u03b1 \u2192 M}\n  (h : disjoint (mul_support f) (mul_support g)) :\n  (mul_support f).mul_indicator (f * g) = f :=\nbegin\n  refine (mul_indicator_congr $ \u03bb x hx, _).trans mul_indicator_mul_support,\n  have : g x = 1, from nmem_mul_support.1 (disjoint_left.1 h hx),\n  rw [pi.mul_apply, this, mul_one]\nend\n\n@[to_additive] lemma mul_indicator_mul_eq_right {f g : \u03b1 \u2192 M}\n  (h : disjoint (mul_support f) (mul_support g)) :\n  (mul_support g).mul_indicator (f * g) = g :=\nbegin\n  refine (mul_indicator_congr $ \u03bb x hx, _).trans mul_indicator_mul_support,\n  have : f x = 1, from nmem_mul_support.1 (disjoint_right.1 h hx),\n  rw [pi.mul_apply, this, one_mul]\nend\n\n/-- `set.mul_indicator` as a `monoid_hom`. -/\n@[to_additive \"`set.indicator` as an `add_monoid_hom`.\"]\ndef mul_indicator_hom {\u03b1} (M) [mul_one_class M] (s : set \u03b1) : (\u03b1 \u2192 M) \u2192* (\u03b1 \u2192 M) :=\n{ to_fun := mul_indicator s,\n  map_one' := mul_indicator_one M s,\n  map_mul' := mul_indicator_mul s }\n\nend monoid\n\nsection distrib_mul_action\n\nvariables {A : Type*} [add_monoid A] [monoid M] [distrib_mul_action M A]\n\nlemma indicator_smul (s : set \u03b1) (r : M) (f : \u03b1 \u2192 A) :\n  indicator s (\u03bb (x : \u03b1), r \u2022 f x) = \u03bb (x : \u03b1), r \u2022 indicator s f x :=\nby { simp only [indicator], funext, split_ifs, refl, exact (smul_zero r).symm }\n\nend distrib_mul_action\n\nsection group\nvariables {G : Type*} [group G] {s t : set \u03b1} {f g : \u03b1 \u2192 G} {a : \u03b1}\n\n@[to_additive] lemma mul_indicator_inv' (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  mul_indicator s (f\u207b\u00b9) = (mul_indicator s f)\u207b\u00b9 :=\n(mul_indicator_hom G s).map_inv f\n\n@[to_additive] lemma mul_indicator_inv (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  mul_indicator s (\u03bba, (f a)\u207b\u00b9) = \u03bba, (mul_indicator s f a)\u207b\u00b9 :=\nmul_indicator_inv' s f\n\nlemma indicator_sub {G} [add_group G] (s : set \u03b1) (f g : \u03b1 \u2192 G) :\n  indicator s (\u03bba, f a - g a) = \u03bba, indicator s f a - indicator s g a :=\n(indicator_hom G s).map_sub f g\n\n@[to_additive indicator_compl'] lemma mul_indicator_compl (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  mul_indicator s\u1d9c f = f * (mul_indicator s f)\u207b\u00b9 :=\neq_mul_inv_of_mul_eq $ s.mul_indicator_compl_mul_self f\n\nlemma indicator_compl {G} [add_group G] (s : set \u03b1) (f : \u03b1 \u2192 G) :\n  indicator s\u1d9c f = f - indicator s f :=\nby rw [sub_eq_add_neg, indicator_compl']\n\n@[to_additive indicator_diff'] lemma mul_indicator_diff (h : s \u2286 t) (f : \u03b1 \u2192 G) :\n  mul_indicator (t \\ s) f = mul_indicator t f * (mul_indicator s f)\u207b\u00b9 :=\neq_mul_inv_of_mul_eq $ by rw [pi.mul_def, \u2190 mul_indicator_union_of_disjoint disjoint_diff.symm f,\n  diff_union_self, union_eq_self_of_subset_right h]\n\nlemma indicator_diff {G : Type*} [add_group G] {s t : set \u03b1} (h : s \u2286 t) (f : \u03b1 \u2192 G) :\n  indicator (t \\ s) f = indicator t f - indicator s f :=\nby rw [indicator_diff' h, sub_eq_add_neg]\n\nend group\n\nsection comm_monoid\n\nvariables [comm_monoid M]\n\n/-- Consider a product of `g i (f i)` over a `finset`.  Suppose `g` is a\nfunction such as `pow`, which maps a second argument of `1` to\n`1`. Then if `f` is replaced by the corresponding multiplicative indicator\nfunction, the `finset` may be replaced by a possibly larger `finset`\nwithout changing the value of the sum. -/\n@[to_additive] lemma prod_mul_indicator_subset_of_eq_one [has_one N] (f : \u03b1 \u2192 N)\n  (g : \u03b1 \u2192 N \u2192 M) {s t : finset \u03b1} (h : s \u2286 t) (hg : \u2200 a, g a 1 = 1) :\n  \u220f i in s, g i (f i) = \u220f i in t, g i (mul_indicator \u2191s f i) :=\nbegin\n  rw \u2190 finset.prod_subset h _,\n  { apply finset.prod_congr rfl,\n    intros i hi,\n    congr,\n    symmetry,\n    exact mul_indicator_of_mem hi _ },\n  { refine \u03bb i hi hn, _,\n    convert hg i,\n    exact mul_indicator_of_not_mem hn _ }\nend\n\n/-- Consider a sum of `g i (f i)` over a `finset`.  Suppose `g` is a\nfunction such as multiplication, which maps a second argument of 0 to\n0.  (A typical use case would be a weighted sum of `f i * h i` or `f i\n\u2022 h i`, where `f` gives the weights that are multiplied by some other\nfunction `h`.)  Then if `f` is replaced by the corresponding indicator\nfunction, the `finset` may be replaced by a possibly larger `finset`\nwithout changing the value of the sum. -/\nadd_decl_doc set.sum_indicator_subset_of_eq_zero\n\n@[to_additive] lemma prod_mul_indicator_subset (f : \u03b1 \u2192 M) {s t : finset \u03b1} (h : s \u2286 t) :\n  \u220f i in s, f i = \u220f i in t, mul_indicator \u2191s f i :=\nprod_mul_indicator_subset_of_eq_one _ (\u03bb a b, b) h (\u03bb _, rfl)\n\n/-- Summing an indicator function over a possibly larger `finset` is\nthe same as summing the original function over the original\n`finset`. -/\nadd_decl_doc sum_indicator_subset\n\n@[to_additive] lemma mul_indicator_finset_prod (I : finset \u03b9) (s : set \u03b1) (f : \u03b9 \u2192 \u03b1 \u2192 M) :\n  mul_indicator s (\u220f i in I, f i) = \u220f i in I, mul_indicator s (f i) :=\n(mul_indicator_hom M s).map_prod _ _\n\n@[to_additive] lemma mul_indicator_finset_bUnion {\u03b9} (I : finset \u03b9)\n  (s : \u03b9 \u2192 set \u03b1) {f : \u03b1 \u2192 M} : (\u2200 (i \u2208 I) (j \u2208 I), i \u2260 j \u2192 disjoint (s i) (s j)) \u2192\n  mul_indicator (\u22c3 i \u2208 I, s i) f = \u03bb a, \u220f i in I, mul_indicator (s i) f a :=\nbegin\n  refine finset.induction_on I _ _,\n  { intro h, funext, simp },\n  assume a I haI ih hI,\n  funext,\n  rw [finset.prod_insert haI, finset.set_bUnion_insert, mul_indicator_union_of_not_mem_inter, ih _],\n  { assume i hi j hj hij,\n    exact hI i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij },\n  simp only [not_exists, exists_prop, mem_Union, mem_inter_eq, not_and],\n  assume hx a' ha',\n  refine disjoint_left.1 (hI a (finset.mem_insert_self _ _) a' (finset.mem_insert_of_mem ha') _) hx,\n  exact (ne_of_mem_of_not_mem ha' haI).symm\nend\n\nend comm_monoid\n\nsection mul_zero_class\n\nvariables [mul_zero_class M] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1}\n\nlemma indicator_mul (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  indicator s (\u03bba, f a * g a) = \u03bba, indicator s f a * indicator s g a :=\nby { funext, simp only [indicator], split_ifs, { refl }, rw mul_zero }\n\nlemma indicator_mul_left (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  indicator s (\u03bba, f a * g a) a = indicator s f a * g a :=\nby { simp only [indicator], split_ifs, { refl }, rw [zero_mul] }\n\nlemma indicator_mul_right (s : set \u03b1) (f g : \u03b1 \u2192 M) :\n  indicator s (\u03bba, f a * g a) a = f a * indicator s g a :=\nby { simp only [indicator], split_ifs, { refl }, rw [mul_zero] }\n\nlemma inter_indicator_mul {t1 t2 : set \u03b1} (f g : \u03b1 \u2192 M) (x : \u03b1) :\n  (t1 \u2229 t2).indicator (\u03bb x, f x * g x) x = t1.indicator f x * t2.indicator g x :=\nby { rw [\u2190 set.indicator_indicator], simp [indicator] }\n\nend mul_zero_class\n\nsection monoid_with_zero\n\nvariables [monoid_with_zero M]\n\nlemma indicator_prod_one {s : set \u03b1} {t : set \u03b2} {x : \u03b1} {y : \u03b2} :\n  (s.prod t).indicator (1 : _ \u2192 M) (x, y) = s.indicator 1 x * t.indicator 1 y :=\nby simp [indicator, \u2190 ite_and]\n\nend monoid_with_zero\n\nsection order\nvariables [has_one M] [preorder M] {s t : set \u03b1} {f g : \u03b1 \u2192 M} {a : \u03b1} {y : M}\n\n@[to_additive] lemma mul_indicator_apply_le' (hfg : a \u2208 s \u2192 f a \u2264 y) (hg : a \u2209 s \u2192 1 \u2264 y) :\n  mul_indicator s f a \u2264 y :=\nif ha : a \u2208 s then by simpa [ha] using hfg ha else by simpa [ha] using hg ha\n\n@[to_additive] lemma mul_indicator_le' (hfg : \u2200 a \u2208 s, f a \u2264 g a) (hg : \u2200 a \u2209 s, 1 \u2264 g a) :\n  mul_indicator s f \u2264 g :=\n\u03bb a, mul_indicator_apply_le' (hfg _) (hg _)\n\n@[to_additive] lemma le_mul_indicator_apply {y} (hfg : a \u2208 s \u2192 y \u2264 g a) (hf : a \u2209 s \u2192 y \u2264 1) :\n  y \u2264 mul_indicator s g a :=\n@mul_indicator_apply_le' \u03b1 (order_dual M) \u2039_\u203a _ _ _ _ _ hfg hf\n\n@[to_additive] lemma le_mul_indicator (hfg : \u2200 a \u2208 s, f a \u2264 g a) (hf : \u2200 a \u2209 s, f a \u2264 1) :\n  f \u2264 mul_indicator s g :=\n\u03bb a, le_mul_indicator_apply (hfg _) (hf _)\n\n@[to_additive indicator_apply_nonneg]\nlemma one_le_mul_indicator_apply (h : a \u2208 s \u2192 1 \u2264 f a) : 1 \u2264 mul_indicator s f a :=\nle_mul_indicator_apply h (\u03bb _, le_rfl)\n\n@[to_additive indicator_nonneg]\nlemma one_le_mul_indicator (h : \u2200 a \u2208 s, 1 \u2264 f a) (a : \u03b1) : 1 \u2264 mul_indicator s f a :=\none_le_mul_indicator_apply (h a)\n\n@[to_additive] lemma mul_indicator_apply_le_one (h : a \u2208 s \u2192 f a \u2264 1) : mul_indicator s f a \u2264 1 :=\nmul_indicator_apply_le' h (\u03bb _, le_rfl)\n\n@[to_additive] lemma mul_indicator_le_one (h : \u2200 a \u2208 s, f a \u2264 1) (a : \u03b1) :\n  mul_indicator s f a \u2264 1 :=\nmul_indicator_apply_le_one (h a)\n\n@[to_additive] lemma mul_indicator_le_mul_indicator (h : f a \u2264 g a) :\n  mul_indicator s f a \u2264 mul_indicator s g a :=\nmul_indicator_rel_mul_indicator (le_refl _) (\u03bb _, h)\n\nattribute [mono] mul_indicator_le_mul_indicator indicator_le_indicator\n\n@[to_additive] lemma mul_indicator_le_mul_indicator_of_subset (h : s \u2286 t) (hf : \u2200 a, 1 \u2264 f a)\n  (a : \u03b1) :\n  mul_indicator s f a \u2264 mul_indicator t f a :=\nmul_indicator_apply_le' (\u03bb ha, le_mul_indicator_apply (\u03bb _, le_rfl) (\u03bb hat, (hat $ h ha).elim))\n  (\u03bb ha, one_le_mul_indicator_apply (\u03bb _, hf _))\n\n@[to_additive] lemma mul_indicator_le_self' (hf : \u2200 x \u2209 s, 1 \u2264 f x) : mul_indicator s f \u2264 f :=\nmul_indicator_le' (\u03bb _ _, le_refl _) hf\n\n@[to_additive] lemma mul_indicator_Union_apply {\u03b9 M} [complete_lattice M] [has_one M]\n  (h1 : (\u22a5:M) = 1) (s : \u03b9 \u2192 set \u03b1) (f : \u03b1 \u2192 M) (x : \u03b1) :\n  mul_indicator (\u22c3 i, s i) f x = \u2a06 i, mul_indicator (s i) f x :=\nbegin\n  by_cases hx : x \u2208 \u22c3 i, s i,\n  { rw [mul_indicator_of_mem hx],\n    rw [mem_Union] at hx,\n    refine le_antisymm _ (supr_le $ \u03bb i, mul_indicator_le_self' (\u03bb x hx, h1 \u25b8 bot_le) x),\n    rcases hx with \u27e8i, hi\u27e9,\n    exact le_supr_of_le i (ge_of_eq $ mul_indicator_of_mem hi _) },\n  { rw [mul_indicator_of_not_mem hx],\n    simp only [mem_Union, not_exists] at hx,\n    simp [hx, \u2190 h1] }\nend\n\nend order\n\nsection canonically_ordered_monoid\n\nvariables [canonically_ordered_monoid M]\n\n@[to_additive] lemma mul_indicator_le_self (s : set \u03b1) (f : \u03b1 \u2192 M) :\n  mul_indicator s f \u2264 f :=\nmul_indicator_le_self' $ \u03bb _ _, one_le _\n\n@[to_additive] lemma mul_indicator_apply_le {a : \u03b1} {s : set \u03b1} {f g : \u03b1 \u2192 M}\n  (hfg : a \u2208 s \u2192 f a \u2264 g a) :\n  mul_indicator s f a \u2264 g a :=\nmul_indicator_apply_le' hfg $ \u03bb _, one_le _\n\n@[to_additive] lemma mul_indicator_le {s : set \u03b1} {f g : \u03b1 \u2192 M} (hfg : \u2200 a \u2208 s, f a \u2264 g a) :\n  mul_indicator s f \u2264 g :=\nmul_indicator_le' hfg $ \u03bb _ _, one_le _\n\nend canonically_ordered_monoid\n\nend set\n\n@[to_additive] lemma monoid_hom.map_mul_indicator {M N : Type*} [monoid M] [monoid N] (f : M \u2192* N)\n  (s : set \u03b1) (g : \u03b1 \u2192 M) (x : \u03b1) :\n  f (s.mul_indicator g x) = s.mul_indicator (f \u2218 g) x :=\ncongr_fun (set.mul_indicator_comp_of_one f.map_one).symm x\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/indicator_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8519527944504226, "lm_q1q2_score": 0.7080946422109343}}
{"text": "-- Subtraccion_en_anillos.lean\n-- Si R es un anillo y a, b \u2208 R, entonces a - b = a + -b\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 12-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si R es un anillo y a, b \u2208 R entonces\n--    a - b = a + -b\n-- ----------------------------------------------------------------------\n\nimport algebra.ring\n\nvariables {R : Type*} [ring R]\nvariables {a b : R}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a - b = a + -b :=\nbegin\n  apply sub_eq_iff_eq_add.mpr,\n  calc a\n       = a + 0        : (add_zero a).symm\n   ... = a + (-b + b) : congr_arg (\u03bb x, a + x) (neg_add_self b).symm\n   ... = a + -b + b   : (add_assoc a (-b) b).symm\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a - b = a + -b :=\nbegin\n  apply sub_eq_iff_eq_add.mpr,\n  calc a\n       = a + 0        : by rw add_zero\n   ... = a + (-b + b) : by {congr; rw neg_add_self}\n   ... = a + -b + b   : by rw add_assoc\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a - b = a + -b :=\nbegin\n  rw sub_eq_iff_eq_add,\n  rw add_assoc,\n  rw neg_add_self,\n  rw add_zero,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a - b = a + -b :=\nby rw [sub_eq_iff_eq_add, add_assoc, neg_add_self, add_zero]\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a - b = a + -b :=\nby simp [sub_eq_iff_eq_add]\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a - b = a + -b :=\n-- by library_search\nsub_eq_add_neg a b\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Subtraccion_en_anillos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7080946355233487}}
{"text": "import algebra.group\nimport data.complex.module\nimport group_theory.subgroup\nimport group_theory.quotient_group\nimport linear_algebra.basic\nimport linear_algebra.finite_dimensional\nimport linear_algebra.matrix\n\nimport data.zmod.basic\n\n\n\n\n\n-- Abstract algebra: groups, rings, fields, etc.\n\n\n-- 1. GROUPS\n-- We already saw the definition of a group in an earlier lecture.\n\n#check group\n\n\n\n\n\n\n\n-- But there's more to group theory than just groups! For example:\n\n\n\n-- group homomorphisms...\n\nvariables {G H : Type*} [group G] [group H]\n\n#check monoid_hom G H\n#check G \u2192* H\n\nvariables (f : G \u2192* H)\n#check (f : G \u2192 H)\n\nsection\nvariables (g : G)\n#check f g\nend\n\n#check f.map_one\n#check f.map_mul\n#check f.map_inv\n\nvariables {K : Type*} [group K] (f' : H \u2192* K)\n#check f'.comp f\n#check (monoid_hom.id G : G \u2192* G)\n\n\n\n\n\n-- subgroups & quotients...\n\n#check subgroup G\n\nvariables (N : subgroup G)\n#check (N : set G)\n\nsection\nvariables (g : G)\n#check (g \u2208 N)\nend\n\n#check N.inv_mem'\n\n#check N.mul_mem\n#check N.inv_mem\n\n#check N.normal\n\n\n\nsection\nopen subgroup quotient_group\n\nvariables [normal N]\n\n#check (1 : quotient_group.quotient N)\n#check (mk' N : G \u2192* quotient_group.quotient N)   -- g \u21a6 [g] \u2208 G/N.\n\nend\n\n\n\n\n-- group actions...\n\nvariables {X : Type*} [mul_action G X]\nvariables (g : G) (x : X)\n#check g \u2022 x                    -- \u2022 = \\bu\n\nvariables {Y : Type*} [mul_action G Y]\n#check X \u2192[G] Y\n\n\n\n\n\n\n-- and a bunch more, including:\n-- * constructions of groups\n--     (free groups, free abelian groups, symmetric groups, dihedral groups, ...)\n-- * theorems from an undergrad abstract algebra course\n--     (Lagrange's theorem, Sylow's theorems)\n\n\n\n\n\n\n-- THEN, the same pattern for rings (& also Lie algebras):\n-- ring homomorphisms (\u2192+*), subrings, ideals & their quotients, modules,\n-- and a fair bit of commutative algebra.\n-- This is basically parallel to the story for groups.\n\n/-\nFile organization: Roughly,\n\n* `algebra/` = basic \"universal algebra\" stuff about groups, rings etc.\n  e.g. group homomorphisms.\n\n* `group_theory/`, `ring_theory/`, `linear_algebra/`, ... = more subject-specific.\n\n-/\n\n\n-- 2. Let's focus on the setting of LINEAR ALGEBRA.\n\n\nvariables {k : Type*} [field k]\n\nvariables (V : Type*) [add_comm_group V] [vector_space k V]\nvariables (W : Type*) [add_comm_group W] [vector_space k W]\n\nsection\n\nvariables (v\u2081 v\u2082 : V)\n#check v\u2081 + v\u2082\n\nend\n\n#check V \u2192\u2097[k] W\n\n#check (show vector_space k (V \u2192\u2097[k] W), by apply_instance)\n#check (show ring (V \u2192\u2097[k] V), by apply_instance)\n\n\n\n\n\n\n-- Constructing vector spaces\n\n#check (show vector_space k (fin 37 \u2192 k), by apply_instance)\n\n\nvariables {\u03b1 : Type*} [fintype \u03b1]\n#check (show vector_space k (\u03b1 \u2192 k), by apply_instance)\n\n\nvariables {\u03b2 : Type*}\n#check (show vector_space k (\u03b2 \u2192 k), by apply_instance)\n#check (show vector_space k (\u03b2 \u2192\u2080 k), by apply_instance)\n\n\n\n\n-- Dimension\nopen finite_dimensional\n\nexample : finite_dimensional k (fin 37 \u2192 k) :=\nby apply_instance\n\n\n#check vector_space.dim\nexample : findim k (fin 37 \u2192 k) = 37 :=\nby simp\n\n\nexample : findim \u211d \u2102 = 2 :=\ncomplex.findim_real_complex\n\n-- notation `dim` := findim \u211d\n\n\n\n-- Maps between finite-dimensional vector spaces are equivalent to MATRICES.\n-- In mathlib, matrices are indexed by arbitrary finite types, not just by `fin n`.\n-- A matrix `A : matrix m n k` is really just a function `A : m \u2192 n \u2192 k`.\n\nvariables {m n l : Type*} [fintype m] [fintype n] [fintype l]\n\n#check matrix m n k\n#check (show vector_space k (matrix m n k), by apply_instance)\n\nvariables (A A' : matrix m n k) (B : matrix l m k)\n#check A + A'\n#check B.mul A    -- BA\n\n\n-- Matrix notation\nexample : fin 3 \u2192 \u211d := ![1, 2, -3]\n\nexample : matrix (fin 2) (fin 2) \u211d := ![\n  ![0, -1],\n  ![1, 0]\n]\n\n\n--open_locale classical\n--noncomputable theory\n\nvariables [decidable_eq n]\n\n-- Equivalence between matrices and linear maps\nexample : matrix m n k \u2243\u2097[k] ((n \u2192 k) \u2192\u2097[k] (m \u2192 k)) :=\nmatrix.to_lin'\n\n/-\nIf F : k^n \u2192 k^m is a linear map then the (i,j) entry of the corresponding matrix\nis the i component (i.e. value on (i : m)) of F applied to the standard basis vector e_j...\nbut we need decidable equality on the type of j to define e_j = [ 0 ... 0 1 0 ... 0 ]\u1d57.\n-/\n\n\nsection\ndef foo : fact (nat.prime 37) := show (nat.prime 37), by norm_num\nlocal attribute [instance] foo\n\n#check (show field (zmod 37), by apply_instance)\nend\n", "meta": {"author": "fpvandoorn", "repo": "Harvard-tutoring", "sha": "a8846c08e32cdc7b91a7e28adfa5d9b2810088b0", "save_path": "github-repos/lean/fpvandoorn-Harvard-tutoring", "path": "github-repos/lean/fpvandoorn-Harvard-tutoring/Harvard-tutoring-a8846c08e32cdc7b91a7e28adfa5d9b2810088b0/src/meetings/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.7080793988730306}}
{"text": "import incidence_world.level05 --hide\nopen IncidencePlane --hide\n\n/-\nWe end this world by proving the existence of triangles\nusing only incidence axioms.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\n\n/- Lemma :\nThere exist three lines that do not have a point in common.\n-/\nlemma three_distinct_lines : \u2203 (r s t: Line \u03a9), (\u2200 (P : \u03a9),\n\u00ac(P \u2208 r \u2227 P \u2208 s \u2227 P \u2208 t)) :=\nbegin\n  rcases existence \u03a9 with \u27e8A, B, C, \u27e8hAB, hAC, hBC, h\u27e9\u27e9,\n  use line_through A B,\n  use line_through A C,\n  use line_through B C,\n  intros P H,\n  have h1 : line_through A C \u2260 line_through A B, \n  {\n    exact ne_of_not_share_point (line_through_right A C) h,\n  },\n  by_cases hPA : P = A,\n  {\n    have hAlBC : A \u2208 line_through B C,\n    {\n      rw \u2190 hPA,\n      exact H.2.2,\n    },\n    have H1 : line_through A C = line_through B C,\n    {\n      exact equal_lines_of_contain_two_points hAC (line_through_left A C) hAlBC (line_through_right A C) (line_through_right B C),\n    },\n    have H2 : line_through A C = line_through A B, \n    {\n      rw H1,\n      exact equal_lines_of_contain_two_points hAB hAlBC (line_through_left A B) (line_through_left B C) (line_through_right A B),\n    },\n    exact h1 H2,\n  },\n  {\n    have h2 : line_through A C = line_through A B, \n    {\n      exact equal_lines_of_contain_two_points hPA H.2.1 H.1 (line_through_left A C) (line_through_left A B),\n    },\n    exact h1 h2,\n  }\n  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n  \nend", "meta": {"author": "mmasdeu", "repo": "hilbertgame", "sha": "0557019a1b7220bab7fe35729646c25bf73f0447", "save_path": "github-repos/lean/mmasdeu-hilbertgame", "path": "github-repos/lean/mmasdeu-hilbertgame/hilbertgame-0557019a1b7220bab7fe35729646c25bf73f0447/src/incidence_world/level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.7080793947197701}}
{"text": "import data.list.basic\n\nopen list\n\nvariables {\u03b1 : Type*} (x y z : \u03b1) (xs ys zs : list \u03b1)\n\ndef mk_symm (xs : list \u03b1) := xs ++ reverse xs\n\ntheorem reverse_mk_symm (xs : list \u03b1) :\n  reverse (mk_symm xs) = mk_symm xs :=\nby simp [mk_symm]\n\nattribute [simp] reverse_mk_symm\n\nexample (xs ys : list \u2115) (p : list \u2115 \u2192 Prop)\n    (h : p (reverse (xs ++ (mk_symm ys)))) :\n  p (mk_symm ys ++ reverse xs) :=\nby { simp at h, assumption }\n\nexample (xs ys : list \u2115) (p : list \u2115 \u2192 Prop)\n    (h : p (reverse (xs ++ (mk_symm ys)))) :\n  p (reverse (mk_symm ys) ++ reverse xs) :=\nby { simp [-reverse_mk_symm] at h, assumption }\n\nexample (xs ys : list \u2115) (p : list \u2115 \u2192 Prop)\n    (h : p (reverse (xs ++ (mk_symm ys)))) :\n  p (reverse (mk_symm ys) ++ reverse xs) :=\nby { simp only [reverse_append] at h, assumption }\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/05-Tactics/example-5.7-11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7080360384360852}}
{"text": "/-\nCopyright (c) 2020 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport data.set.intervals.basic\nimport data.set.function\n\n/-!\n# Monotone surjective functions are surjective on intervals\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA monotone surjective function sends any interval in the domain onto the interval with corresponding\nendpoints in the range.  This is expressed in this file using `set.surj_on`, and provided for all\npermutations of interval endpoints.\n-/\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} [linear_order \u03b1] [partial_order \u03b2] {f : \u03b1 \u2192 \u03b2}\n\nopen set function order_dual (to_dual)\n\nlemma surj_on_Ioo_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a b : \u03b1) :\n  surj_on f (Ioo a b) (Ioo (f a) (f b)) :=\nbegin\n  intros p hp,\n  rcases h_surj p with \u27e8x, rfl\u27e9,\n  refine \u27e8x, mem_Ioo.2 _, rfl\u27e9,\n  contrapose! hp,\n  exact \u03bb h, h.2.not_le (h_mono $ hp $ h_mono.reflect_lt h.1)\nend\n\nlemma surj_on_Ico_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a b : \u03b1) :\n  surj_on f (Ico a b) (Ico (f a) (f b)) :=\nbegin\n  obtain hab | hab := lt_or_le a b,\n  { intros p hp,\n    rcases eq_left_or_mem_Ioo_of_mem_Ico hp with rfl|hp',\n    { exact mem_image_of_mem f (left_mem_Ico.mpr hab) },\n    { have := surj_on_Ioo_of_monotone_surjective h_mono h_surj a b hp',\n      exact image_subset f Ioo_subset_Ico_self this } },\n  { rw Ico_eq_empty (h_mono hab).not_lt,\n    exact surj_on_empty f _ }\nend\n\nlemma surj_on_Ioc_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a b : \u03b1) :\n  surj_on f (Ioc a b) (Ioc (f a) (f b)) :=\nby simpa using surj_on_Ico_of_monotone_surjective h_mono.dual h_surj (to_dual b) (to_dual a)\n\n-- to see that the hypothesis `a \u2264 b` is necessary, consider a constant function\nlemma surj_on_Icc_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) {a b : \u03b1} (hab : a \u2264 b) :\n  surj_on f (Icc a b) (Icc (f a) (f b)) :=\nbegin\n  intros p hp,\n  rcases eq_endpoints_or_mem_Ioo_of_mem_Icc hp with (rfl|rfl|hp'),\n  { exact \u27e8a, left_mem_Icc.mpr hab, rfl\u27e9 },\n  { exact \u27e8b, right_mem_Icc.mpr hab, rfl\u27e9 },\n  { have := surj_on_Ioo_of_monotone_surjective h_mono h_surj a b hp',\n    exact image_subset f Ioo_subset_Icc_self this }\nend\n\nlemma surj_on_Ioi_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Ioi a) (Ioi (f a)) :=\nbegin\n  rw [\u2190 compl_Iic, \u2190 compl_compl (Ioi (f a))],\n  refine maps_to.surj_on_compl _ h_surj,\n  exact \u03bb x hx, (h_mono hx).not_lt\nend\n\nlemma surj_on_Iio_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Iio a) (Iio (f a)) :=\n@surj_on_Ioi_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a\n\nlemma surj_on_Ici_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Ici a) (Ici (f a)) :=\nbegin\n  rw [\u2190 Ioi_union_left, \u2190 Ioi_union_left],\n  exact (surj_on_Ioi_of_monotone_surjective h_mono h_surj a).union_union\n    (@image_singleton _ _ f a \u25b8 surj_on_image _ _)\nend\n\nlemma surj_on_Iic_of_monotone_surjective\n  (h_mono : monotone f) (h_surj : function.surjective f) (a : \u03b1) :\n  surj_on f (Iic a) (Iic (f a)) :=\n@surj_on_Ici_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/set/intervals/surj_on.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7080360258020997}}
{"text": "/-\nCopyright (c) 2018 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport tactic.suggest\nimport ring_theory.principal_ideal_domain\nimport ring_theory.polynomial.basic\n\nopen_locale polynomial\n/- Turn off trace messages so they don't pollute the test build: -/\nset_option trace.silence_library_search true\n\nexample {\u03b1 : Type} [euclidean_domain \u03b1] {S : ideal \u03b1} {x y : \u03b1} (hy : y \u2208 S) : x % y \u2208 S \u2194 x \u2208 S :=\nby library_search -- exact mod_mem_iff hy\n\nvariables {R : Type} [comm_ring R] [decidable_eq R]\nvariables {I : ideal R[X]}\n\nexample {m n : \u2115} (H : m \u2264 n) : I.leading_coeff_nth m \u2264 I.leading_coeff_nth n :=\nby library_search -- exact ideal.leading_coeff_nth_mono I H\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/test/library_search/ring_theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.708036021778139}}
{"text": "import SciLean.Basic\nimport SciLean.Tactic\n\nset_option synthInstance.maxHeartbeats 5000\n\nopen SciLean\n\nvariable (f df : \u211d \u27ff \u211d)\n\n-- TODO: Move this somewhere else ... \n@[simp high] theorem differential_of_hom_subtype {X Y} [Vec X] [Vec Y] : \u2202 (Subtype.val : (X \u27ff Y) \u2192 (X \u2192 Y)) = \u03bb f df => df.1 := sorry\n\nexample : \u2202 (\u03bb (f : (\u211d \u27ff \u211d)) => (mkIntegral \u03bb t => f t)) f df = mkIntegral \u03bb t => df t := by\n  simp[mkIntegral] admit\n\nexample : \u2202 (\u03bb (f : (\u211d \u27ff \u211d)) (t : \u211d) => (f t) * (f t)) f df = \u03bb t => (df t) * (f t) + (f t) * (df t) :=\nby\n  simp done\n\nexample (t b : \u211d) : \u2202 (fun (f : \u211d \u27ff \u211d) (t : \u211d) => (f t) * (f t)) f df t = (df t) * (f t) + (f t) * (df t) := by simp done\nexample (t : \u211d) : \u2202 (fun (f : \u211d \u27ff \u211d) (t : \u211d) => (f t) * (f t)) f df t = (df t) * (f t) + (f t) * (df t) := by simp done\n\n\nvariable (f : \u211d \u27ff \u211d) (x : \u211d\u00d7\u211d)\n\n-- #check \u2202 (\u222b t, f t)\n\nclass Dual (X Y : Type) where\n  dual : (X \u2192 Y) \u2192 X\n\n\nclass Integral (X Y : Type) where\n  Result : Type\n  integral : X \u2192 Result\n\nattribute [reducible] Integral.Result\n\n-- def int {X Y} [FinVec X] [SemiHilbert Y] (f : X \u2192 Y) (\u03a9 : \ud835\udcd3 (X \u27ff Y)) : Y := sorry\n\n-- instance (priority := low) {X : Type} \n\nnoncomputable\ninstance (priority := low) {X : Type} [SemiHilbert X] : Dual X (\ud835\udcd3 X \u2192 \u211d) where\n  dual := dual\n\nnoncomputable\ninstance [Hilbert X] : Dual X \u211d where\n  dual := \u03bb f => dual (\u03bb x _ => f x)\n\n#check Dual.dual (\u2202 (\u03bb x : \u211d\u00d7\u211d => \u27eax, 1\u27eb) x)\n#check Dual.dual ((\u2202 \u03bb f : \u211d \u27ff \u211d => \u03bb \u03a9 => \u27eaf, 1\u27eb[\u03a9]) f)\n\n-- example : \u2202 (\u03bb (f : (\u211d \u27ff \u211d)) => (\u222b t, (f t) * (f t) + (f t))) f df = \u222b t, (df t) * (f t) + (f t + 1) * (df t) := \n-- by\n--   simp[integral]\n--   simp[mkIntegral, integral]\n--   done\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/test/variational_calculus.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.70802682719855}}
{"text": "import game.sets.sets_level04 -- hide\n\nnamespace xena -- hide\n\nvariable X : Type --hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 5\n-/\n\n\n/-\nYou should now be able to prove the theorem below if you\nuse `split` and `cases` together with `set.subset.antisymm`.\n-/\n\n/- Lemma\nIf $A$ and $B$ are sets of any type $X$, then\n$$ A \\subseteq B \\iff A \\cap B = A.$$\n-/\ntheorem subset_iff_intersection_eq (A : set X) (B : set X) : A \u2286 B \u2194 A \u2229 B = A := \nbegin\n    split,\n    intro H, apply set.subset.antisymm,\n    intros x hx, cases hx with hA hB, exact hA,\n    intros x hx, split, exact hx, exact H hx,\n    intro H, intros x hx, \n    have G : x \u2208 A \u2229 B, rw H, exact hx,\n    cases G with hA hB, exact hB, done\nend\n\nend xena -- hide", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/kb_solns/sets_level05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7080268226004629}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_275\n  (x : \u211d)\n  (h : ((11:\u211d)^(1 / 4))^(3 * x - 3) = 1 / 5) :\n  ((11:\u211d)^(1 / 4))^(6 * x + 2) = 121 / 25 :=\nbegin\n  revert x h,\n  norm_num,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p275.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632856092016, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.7080268214603713}}
{"text": "/- Additional lemmas on modular equality. -/\n\nimport data.nat.modeq\n\nopen nat\n\nnamespace modeq\n  variables {a r n k : \u2115}\n  lemma mod_of_modeq : a \u2261 r [MOD n] \u2192 r < n \u2192 a % n = r :=\n    begin\n      rw modeq,\n      intros e l,\n      have h : r % n = r := mod_eq_of_lt l,\n      rw [e, h]\n    end\n\n  lemma rep_of_modeq : a \u2261 r [MOD n] \u2192 r < n \u2192 \u2203 q : \u2115, a = n * q + r :=\n    begin\n      intros e l,\n      existsi (a / n),\n      apply symm,\n      rw [add_comm, \u2190(mod_of_modeq e l)],\n      apply mod_add_div\n    end\n\n  lemma n_mod_n : n \u2261 0 [MOD n] :=\n    begin rw [modeq, mod_self, zero_mod] end\n\n  lemma modeq_of_rep_0 : n*k + r \u2261 0*k + r [MOD n] :=\n    modeq.modeq_add (modeq.modeq_mul_right k n_mod_n) (modeq.refl r)\n  lemma modeq_of_rep : n*k + r \u2261 r [MOD n] :=\n    begin\n      apply (modeq.trans modeq_of_rep_0 _),\n      simp\n    end\nend modeq\n", "meta": {"author": "rwbarton", "repo": "lean-elementary-number-theory", "sha": "fabef0737fd2486e3f24f9e04652db4c182d5425", "save_path": "github-repos/lean/rwbarton-lean-elementary-number-theory", "path": "github-repos/lean/rwbarton-lean-elementary-number-theory/lean-elementary-number-theory-fabef0737fd2486e3f24f9e04652db4c182d5425/src/ent/modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7080140815577108}}
{"text": "-- Inverso_derecha.lean\n-- Si G es un grupo y a \u2208 G, entonces a * a\u207b\u00b9 = 1\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 14-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, se declara que G es un grupo mediante la expresi\u00f3n\n--    variables {G : Type*} [group G]\n-- y, como consecuencia, se tiene los siguientes axiomas\n--    mul_assoc    : \u2200 a b c : G, a * b * c = a * (b * c)\n--    one_mul      : \u2200 a : G,     1 * a = a\n--    mul_left_inv : \u2200 a : G,     a\u207b\u00b9 * a = 1\n--\n-- Demostrar que si G es un grupo y a \u2208 G, entonces\n--    a * a\u207b\u00b9 = 1\n-- ---------------------------------------------------------------------\n\nimport algebra.group\nvariables {G : Type*} [group G]\nvariables a : G\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * a\u207b\u00b9 = 1 :=\ncalc a * a\u207b\u00b9\n     = 1 * (a * a\u207b\u00b9)\n       : (one_mul (a * a\u207b\u00b9)).symm\n ... = (1 * a) * a\u207b\u00b9\n       : (mul_assoc 1 a  a\u207b\u00b9).symm\n ... = (((a\u207b\u00b9)\u207b\u00b9 * a\u207b\u00b9)  * a) * a\u207b\u00b9\n       : congr_arg (\u03bb x, (x * a) * a\u207b\u00b9) (mul_left_inv a\u207b\u00b9).symm\n ... = ((a\u207b\u00b9)\u207b\u00b9 * (a\u207b\u00b9  * a)) * a\u207b\u00b9\n       : congr_fun (congr_arg has_mul.mul (mul_assoc a\u207b\u00b9\u207b\u00b9 a\u207b\u00b9 a)) a\u207b\u00b9\n ... = ((a\u207b\u00b9)\u207b\u00b9 * 1) * a\u207b\u00b9\n       : congr_arg (\u03bb x, (a\u207b\u00b9\u207b\u00b9 * x) * a\u207b\u00b9) (mul_left_inv a)\n ... = (a\u207b\u00b9)\u207b\u00b9 * (1 * a\u207b\u00b9)\n       : mul_assoc (a\u207b\u00b9)\u207b\u00b9 1 a\u207b\u00b9\n ... = (a\u207b\u00b9)\u207b\u00b9 * a\u207b\u00b9\n       : congr_arg (\u03bb x, (a\u207b\u00b9)\u207b\u00b9 * x) (one_mul a\u207b\u00b9)\n ... = 1\n       : mul_left_inv a\u207b\u00b9\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * a\u207b\u00b9 = 1 :=\ncalc\n  a * a\u207b\u00b9 = 1 * (a * a\u207b\u00b9)                : by rw one_mul\n      ... = (1 * a) * a\u207b\u00b9                : by rw mul_assoc\n      ... = (((a\u207b\u00b9)\u207b\u00b9 * a\u207b\u00b9)  * a) * a\u207b\u00b9 : by rw mul_left_inv\n      ... = ((a\u207b\u00b9)\u207b\u00b9 * (a\u207b\u00b9  * a)) * a\u207b\u00b9 : by rw \u2190 mul_assoc\n      ... = ((a\u207b\u00b9)\u207b\u00b9 * 1) * a\u207b\u00b9          : by rw mul_left_inv\n      ... = (a\u207b\u00b9)\u207b\u00b9 * (1 * a\u207b\u00b9)          : by rw mul_assoc\n      ... = (a\u207b\u00b9)\u207b\u00b9 * a\u207b\u00b9                : by rw one_mul\n      ... = 1                            : by rw mul_left_inv\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * a\u207b\u00b9 = 1 :=\ncalc\n  a * a\u207b\u00b9 = 1 * (a * a\u207b\u00b9)                : by simp\n      ... = (1 * a) * a\u207b\u00b9                : by simp\n      ... = (((a\u207b\u00b9)\u207b\u00b9 * a\u207b\u00b9)  * a) * a\u207b\u00b9 : by simp\n      ... = ((a\u207b\u00b9)\u207b\u00b9 * (a\u207b\u00b9  * a)) * a\u207b\u00b9 : by simp\n      ... = ((a\u207b\u00b9)\u207b\u00b9 * 1) * a\u207b\u00b9          : by simp\n      ... = (a\u207b\u00b9)\u207b\u00b9 * (1 * a\u207b\u00b9)          : by simp\n      ... = (a\u207b\u00b9)\u207b\u00b9 * a\u207b\u00b9                : by simp\n      ... = 1                            : by simp\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * a\u207b\u00b9 = 1 :=\nby simp\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : a * a\u207b\u00b9 = 1 :=\n-- by library_search\nmul_inv_self a\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Inverso_derecha.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7078890387646384}}
{"text": "import tactic.interactive\nimport tactic.finish\nimport data.int.parity\nimport init.function\n\n\nuniverses u1 u2 u3 u4\n\nconstant \u03b1 : Sort u1\nconstant \u03b2 : Sort u2\nconstant \u03b3 : Sort u3\n\ndef injective {\u03b1 : Sort u1} {\u03b2 : Sort u2} (f : \u03b1 \u2192 \u03b2 ) : Prop :=\n      \u2200 (x1 x2 : \u03b1 ), f x1 = f x2 \u2192 x1 = x2 \n\n\ndef surjective {\u03b1 : Sort u1} {\u03b2 : Sort u2} (f : \u03b1 \u2192 \u03b2 ) : Prop :=\n  \u2200 y : \u03b2, \u2203 x : \u03b1, f x = y\n\n\ndef bijective {\u03b1 : Sort u1} {\u03b2 : Sort u2} (f : \u03b1 \u2192 \u03b2 ) : Prop :=\n  injective f \u2227 surjective f\n\n\ndef in_bijection (A : Sort u1) (B : Sort u2): Prop := \u2203 f : A \u2192 B , bijective f \n\n\ndef comp {\u03b1 : Sort u1} {\u03b2 : Sort u2} {\u03b3 : Sort u3} (f : \u03b2 \u2192 \u03b3 ) (g : \u03b1  \u2192 \u03b2  ) := \u03bbx : \u03b1 ,  f (g x)\n\nlemma ass_comp {\u03b1 : Sort u1} {\u03b2 : Sort u2} {\u03b3 : Sort u3} {\u03b8 : Sort u4} {f : \u03b2 \u2192 \u03b3 } {g : \u03b1  \u2192 \u03b2} {h : \u03b3 \u2192 \u03b8}: \ncomp h (comp f g) = comp (comp h f) g :=\n  by rw [comp,comp,comp,comp];simp\n\n\nlemma forall_exists_unique_imp_forall_exists {\u03b1 : Sort u1} {\u03b2 : Sort u2} {f : \u03b1 \u2192 \u03b2 } :\n  (\u2200 (y : \u03b2), \u2203! (x : \u03b1), f x = y ) \u2192 \u2200 (y : \u03b2), \u2203 (x : \u03b1), f x = y :=\n  begin\n    intros a b,\n    apply (exists_of_exists_unique (a b))\n  end\n\n\nlemma injective_of_bij_equiv {\u03b1 : Sort u1} {\u03b2 : Sort u2} {f : \u03b1 \u2192 \u03b2 } {x1 x2 : \u03b1} : \n  (\u2200 (y : \u03b2), \u2203! (x : \u03b1), f x = y ) \u2192 f x1 = f x2 \u2192 x1 = x2 := \n  begin\n    intro sup,\n    assume a,\n    apply (unique_of_exists_unique (sup (f x2))),\n    exact a,\n    refl\n  end\n\n\ntheorem bijective_equiv {\u03b1 : Sort u1} {\u03b2 : Sort u2} (f : \u03b1 \u2192 \u03b2 ) :\n   bijective f \u2194 \u2200 y : \u03b2, \u2203! x : \u03b1, f x = y :=\n  begin\n    apply iff.intro,\n      intros p y,\n      cases ((and.elim_right p) y) with x hx,\n      rw exists_unique,\n      use x,\n      apply and.intro,\n        exact hx,\n        intro x1,\n        rw (eq.symm hx),\n        apply (and.elim_left p),\n      intro sup,\n        apply and.intro,\n          intros x1 x2,\n          apply (injective_of_bij_equiv sup),\n        intro a,\n        apply (exists_of_exists_unique (sup a))\n  end\n\n\ntheorem comp_of_inj_inj {\u03b1 : Sort u1} {\u03b2 : Sort u2} {\u03b3  : Sort u3}  (f : \u03b1 \u2192 \u03b2 ) (g : \u03b2 \u2192  \u03b3 ) :\n  injective f \u2227 injective g \u2192 injective (comp g f) :=\n    begin\n      intro andinj,\n      intros x1 x2,\n      exact implies.trans (and.elim_right andinj (f x1) (f x2)) (and.elim_left andinj x1 x2)\n    end\n\n\ntheorem comp_of_surj_surj {\u03b1 : Sort u1} {\u03b2 : Sort u2} {\u03b3  : Sort u3}  (f : \u03b1 \u2192 \u03b2 ) (g : \u03b2 \u2192  \u03b3 ) :\n  surjective f \u2227 surjective g \u2192 surjective (comp g f) :=\n  begin\n    intro andsurj,\n    intro y,\n    cases ((and.elim_right andsurj) y) with x1 hx1,\n    cases ((and.elim_left andsurj) x1) with x2 hx2,\n    use x2,\n    calc\n       comp g f x2 = g (f x2) : by refl\n              ...  = g x1 : by rw hx2\n              ... = y : by rw hx1\n  end\n\n\ntheorem comp_of_bij_bij {\u03b1 : Sort u1} {\u03b2 : Sort u2} {\u03b3  : Sort u3}  (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192  \u03b3) :\n  bijective f \u2227 bijective g \u2192 bijective (comp g f) :=\n  begin\n    intro hyp,\n    apply and.intro,\n      apply comp_of_inj_inj,\n        apply and.intro,\n          apply and.elim_left (and.elim_left hyp),\n          apply and.elim_left (and.elim_right hyp),\n      apply comp_of_surj_surj,\n        apply and.intro,\n          apply and.elim_right (and.elim_left hyp),\n          apply and.elim_right (and.elim_right hyp)\n  end\n\n\ndef id_bij {\u03b1 : Sort u1 } : bijective (id : \u03b1 \u2192 \u03b1 ) :=  \n  begin\n   apply and.intro,\n        intros x1 x2,\n        simp,\n        intro y,\n      apply exists.intro,\n      rw id \n  end\n\n\ntheorem bij_refl : reflexive in_bijection :=\n  begin\n    intro A,\n      apply exists.intro,\n      apply id_bij,\n  end\n\n\ntheorem bij_trans : transitive in_bijection :=\n  begin\n    intros A B C,\n    intros F G,\n    cases F with f hf,\n    cases G with g hg,\n    apply exists.intro,\n    apply comp_of_bij_bij f g,\n    apply and.intro,\n    apply hf,\n    apply hg\n  end\n\n\nlemma map_eq {A : Sort u1} {B : Sort u2} (f : A \u2192 B) {x1 x2 : A} :  x1 = x2 \u2192 f x1 = f x2 :=\n  begin\n    intro a,\n    rw a \n  end\n\n\n\ntheorem single_exists_unique {\u03b1 : Type u1} {p : \u03b1 \u2192 Prop} :\n  (\u2203! x : \u03b1, p x) \u2194 nonempty {x : \u03b1 // p x} \u2227 subsingleton {x : \u03b1 // p x} :=\n  begin\n    split,\n      intro hyp,\n      split,\n      use hyp.some,      \n      apply hyp.some_spec.left,\n      apply subsingleton.intro,\n      intros a b,\n      apply subtype.eq,\n      apply exists_unique.unique hyp a.property b.property,\n    intro hyp,\n    let sing := hyp.right,\n    apply exists_unique.intro,\n    let v : {x // p x} := (nonempty.some hyp.left),\n    exact v.property,\n    intro y,\n    intro h,\n    let u : {x // p x} := {val := y, property := h},\n    apply map_eq subtype.val  (@subsingleton.elim {x : \u03b1 // p x} sing u (nonempty.some hyp.left))\n  end\n\n\nnoncomputable def inverse {\u03b1 : Sort u1} {\u03b2 : Sort u2} (f : \u03b1 \u2192 \u03b2) (p : bijective f) : \u03b2 \u2192 \u03b1 :=\n  \u03bb y : \u03b2, (((iff.elim_left (bijective_equiv f)) p) y ).some\n\n\n\n\n\ntheorem id_inv_left {\u03b1 : Sort u1} {\u03b2 : Sort u2} (f : \u03b1 \u2192 \u03b2) (p : bijective f) : \n  \u2200 y : \u03b2  , f (inverse f p y) = y :=\n  begin\n    intro y,\n    rw inverse,\n    simp,\n    apply (Exists.some_spec (((iff.elim_left (bijective_equiv f)) p) y )).left\n  end\n\n\ntheorem inv_bij {\u03b1 : Sort u1} {\u03b2 : Sort u2} (f : \u03b1 \u2192 \u03b2) (p : bijective f) : bijective (inverse f p) :=\n  begin\n    apply iff.elim_right (bijective_equiv (inverse f p)),\n    intro y,\n    split,\n    split,\n      simp,\n      show (inverse f p (f y) = y),\n      rw inverse,\n      simp,\n      apply p.left (Exists.some _) (y) \n        ((Exists.some_spec (inverse._proof_1 f p (f y))).left),\n    intro x,\n    simp,\n    intro hyp,\n    have h := (map_eq f hyp),\n    rw eq.symm (id_inv_left f p x),\n    exact h   \n  end\n\ntheorem bij_sym : symmetric in_bijection :=\n  begin\n    intros A B,\n    intro inbij,\n    cases inbij with f hf,\n    apply exists.intro,\n    apply inv_bij f hf\n  end\n\ntheorem bij_eq : equivalence in_bijection :=\n  begin\n    apply and.intro,\n      apply bij_refl,\n    apply and.intro,\n      apply bij_sym,\n      apply bij_trans\n  end\n\n\ntheorem comp_inj_inj {\u03b1 : Sort u1} {\u03b2 : Sort u2} {\u03b3 : Sort u3 } {f : \u03b1 \u2192 \u03b2 } {g : \u03b2 \u2192 \u03b3} : \n  injective (comp g f) \u2192 injective f :=\n  begin\n    contrapose,\n    rw injective,\n    simp,\n    intros x1 x2 eq1 neq1,\n    rw injective,\n    simp,\n    use x1,\n    use x2,\n    split,\n    rw comp,\n    simp,\n    rw eq1,\n    exact neq1 \n  end\n\ntheorem comp_surj_surj  {\u03b1 : Sort u1} {\u03b2 : Sort u2} {\u03b3 : Sort u3} {f : \u03b1 \u2192 \u03b2 } {g : \u03b2 \u2192 \u03b3} :\n  surjective (comp g f) \u2192 surjective g :=\n  begin\n    intro h,\n    intro y,\n    rw comp at h,\n    let x := f (h y).some,\n    use x,\n    change x with f (h y).some,\n    exact Exists.some_spec (h y)\n  end\n\n\n\n\ntheorem comp_id_is_bij  {\u03b1 : Sort u1} {\u03b2 : Sort u2} {f : \u03b1 \u2192 \u03b2 } {g : \u03b2 \u2192 \u03b1 } {h : \u03b2 \u2192 \u03b1 } :\ncomp f g = id \u2227 comp h f = id \u2192 bijective f \u2227 g= h :=\n  begin\n    intro p,\n    have hg := p.left,\n    have hd := p.right,\n    split,\n    split,\n    have compinj : injective (comp h f) :=\n      by rw hd; exact id_bij.left,\n      exact comp_inj_inj compinj,\n    have compsurj : surjective (comp f g) :=\n      by rw hg; exact id_bij.right,\n      exact comp_surj_surj compsurj,\n    have eq1 : comp (comp h f) g = g := by rw [hd,comp];simp,\n    have eq2 : comp (comp h f) g = h := by rw [eq.symm ass_comp,hg,comp];simp,\n    finish,\n  end", "meta": {"author": "arthur-adjedj", "repo": "proof_Q_denumerable", "sha": "7a1059ea91cff929bb0c5fa3876c73b72ebee9f7", "save_path": "github-repos/lean/arthur-adjedj-proof_Q_denumerable", "path": "github-repos/lean/arthur-adjedj-proof_Q_denumerable/proof_Q_denumerable-7a1059ea91cff929bb0c5fa3876c73b72ebee9f7/src/biject.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7078890254013301}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.special_functions.exp\nimport topology.continuous_function.basic\n\n/-!\n# The circle\n\nThis file defines `circle` to be the metric sphere (`metric.sphere`) in `\u2102` centred at `0` of\nradius `1`.  We equip it with the following structure:\n\n* a submonoid of `\u2102`\n* a group\n* a topological group\n\nWe furthermore define `exp_map_circle` to be the natural map `\u03bb t, exp (t * I)` from `\u211d` to\n`circle`, and show that this map is a group homomorphism.\n\n## Implementation notes\n\nBecause later (in `geometry.manifold.instances.sphere`) one wants to equip the circle with a smooth\nmanifold structure borrowed from `metric.sphere`, the underlying set is\n`{z : \u2102 | abs (z - 0) = 1}`.  This prevents certain algebraic facts from working definitionally --\nfor example, the circle is not defeq to `{z : \u2102 | abs z = 1}`, which is the kernel of `complex.abs`\nconsidered as a homomorphism from `\u2102` to `\u211d`, nor is it defeq to `{z : \u2102 | norm_sq z = 1}`, which\nis the kernel of the homomorphism `complex.norm_sq` from `\u2102` to `\u211d`.\n\n-/\n\nnoncomputable theory\n\nopen complex metric\nopen_locale complex_conjugate\n\n/-- The unit circle in `\u2102`, here given the structure of a submonoid of `\u2102`. -/\ndef circle : submonoid \u2102 :=\n{ carrier := sphere (0:\u2102) 1,\n  one_mem' := by simp,\n  mul_mem' := \u03bb a b, begin\n    simp only [norm_eq_abs, mem_sphere_zero_iff_norm],\n    intros ha hb,\n    simp [ha, hb],\n  end }\n\n@[simp] lemma mem_circle_iff_abs {z : \u2102} : z \u2208 circle \u2194 abs z = 1 := mem_sphere_zero_iff_norm\n\nlemma circle_def : \u2191circle = {z : \u2102 | abs z = 1} := set.ext $ \u03bb z, mem_circle_iff_abs\n\n@[simp] lemma abs_coe_circle (z : circle) : abs z = 1 :=\nmem_circle_iff_abs.mp z.2\n\nlemma mem_circle_iff_norm_sq {z : \u2102} : z \u2208 circle \u2194 norm_sq z = 1 :=\nby rw [mem_circle_iff_abs, complex.abs, real.sqrt_eq_one]\n\n@[simp] lemma norm_sq_eq_of_mem_circle (z : circle) : norm_sq z = 1 := by simp [norm_sq_eq_abs]\n\nlemma ne_zero_of_mem_circle (z : circle) : (z:\u2102) \u2260 0 := ne_zero_of_mem_unit_sphere z\n\ninstance : comm_group circle :=\n{ inv := \u03bb z, \u27e8conj (z : \u2102), by simp\u27e9,\n  mul_left_inv := \u03bb z, subtype.ext $ by { simp [has_inv.inv, \u2190 norm_sq_eq_conj_mul_self,\n    \u2190 mul_self_abs] },\n  .. circle.to_comm_monoid }\n\nlemma coe_inv_circle_eq_conj (z : circle) : \u2191(z\u207b\u00b9) = conj (z : \u2102) := rfl\n\n@[simp] lemma coe_inv_circle (z : circle) : \u2191(z\u207b\u00b9) = (z : \u2102)\u207b\u00b9 :=\nbegin\n  rw coe_inv_circle_eq_conj,\n  apply eq_inv_of_mul_right_eq_one,\n  rw [mul_comm, \u2190 complex.norm_sq_eq_conj_mul_self],\n  simp,\nend\n\n@[simp] lemma coe_div_circle (z w : circle) : \u2191(z / w) = (z:\u2102) / w :=\nshow \u2191(z * w\u207b\u00b9) = (z:\u2102) * w\u207b\u00b9, by simp\n\n/-- The elements of the circle embed into the units. -/\n@[simps]\ndef circle.to_units : circle \u2192* units \u2102 :=\n{ to_fun := \u03bb x, units.mk0 x $ ne_zero_of_mem_circle _,\n  map_one' := units.ext rfl,\n  map_mul' := \u03bb x y, units.ext rfl }\n\ninstance : compact_space circle := metric.sphere.compact_space _ _\n\n-- the following result could instead be deduced from the Lie group structure on the circle using\n-- `topological_group_of_lie_group`, but that seems a little awkward since one has to first provide\n-- and then forget the model space\ninstance : topological_group circle :=\n{ continuous_mul := let h : continuous (\u03bb x : circle, (x : \u2102)) := continuous_subtype_coe in\n    continuous_induced_rng (continuous_mul.comp (h.prod_map h)),\n  continuous_inv := continuous_induced_rng $\n    complex.conj_cle.continuous.comp continuous_subtype_coe }\n\n/-- The map `\u03bb t, exp (t * I)` from `\u211d` to the unit circle in `\u2102`. -/\ndef exp_map_circle : C(\u211d, circle) :=\n{ to_fun := \u03bb t, \u27e8exp (t * I), by simp [exp_mul_I, abs_cos_add_sin_mul_I]\u27e9 }\n\n@[simp] lemma exp_map_circle_apply (t : \u211d) : \u2191(exp_map_circle t) = complex.exp (t * complex.I) :=\nrfl\n\n@[simp] lemma exp_map_circle_zero : exp_map_circle 0 = 1 :=\nsubtype.ext $ by rw [exp_map_circle_apply, of_real_zero, zero_mul, exp_zero, submonoid.coe_one]\n\n@[simp] lemma exp_map_circle_add (x y : \u211d) :\n  exp_map_circle (x + y) = exp_map_circle x * exp_map_circle y :=\nsubtype.ext $ by simp only [exp_map_circle_apply, submonoid.coe_mul, of_real_add, add_mul,\n  complex.exp_add]\n\n/-- The map `\u03bb t, exp (t * I)` from `\u211d` to the unit circle in `\u2102`, considered as a homomorphism of\ngroups. -/\n@[simps]\ndef exp_map_circle_hom : \u211d \u2192+ (additive circle) :=\n{ to_fun := additive.of_mul \u2218 exp_map_circle,\n  map_zero' := exp_map_circle_zero,\n  map_add' := exp_map_circle_add }\n\n@[simp] lemma exp_map_circle_sub (x y : \u211d) :\n  exp_map_circle (x - y) = exp_map_circle x / exp_map_circle y :=\nexp_map_circle_hom.map_sub x y\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/complex/circle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7078890243546817}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mitchell Rowett, Scott Morrison, Johan Commelin, Mario Carneiro,\n  Michael Howes\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.group_theory.subgroup\nimport Mathlib.deprecated.submonoid\nimport Mathlib.PostPort\n\nuniverses u_3 l u_1 u_2 u_4 \n\nnamespace Mathlib\n\n/-- `s` is an additive subgroup: a set containing 0 and closed under addition and negation. -/\nclass is_add_subgroup {A : Type u_3} [add_group A] (s : set A) \nextends is_add_submonoid s\nwhere\n  neg_mem : \u2200 {a : A}, a \u2208 s \u2192 -a \u2208 s\n\n/-- `s` is a subgroup: a set containing 1 and closed under multiplication and inverse. -/\nclass is_subgroup {G : Type u_1} [group G] (s : set G) \nextends is_submonoid s\nwhere\n  inv_mem : \u2200 {a : G}, a \u2208 s \u2192 a\u207b\u00b9 \u2208 s\n\ntheorem is_subgroup.div_mem {G : Type u_1} [group G] {s : set G} [is_subgroup s] {x : G} {y : G} (hx : x \u2208 s) (hy : y \u2208 s) : x / y \u2208 s := sorry\n\ntheorem additive.is_add_subgroup {G : Type u_1} [group G] (s : set G) [is_subgroup s] : is_add_subgroup s :=\n  is_add_subgroup.mk is_subgroup.inv_mem\n\ntheorem additive.is_add_subgroup_iff {G : Type u_1} [group G] {s : set G} : is_add_subgroup s \u2194 is_subgroup s := sorry\n\ntheorem multiplicative.is_subgroup {A : Type u_3} [add_group A] (s : set A) [is_add_subgroup s] : is_subgroup s :=\n  is_subgroup.mk is_add_subgroup.neg_mem\n\ntheorem multiplicative.is_subgroup_iff {A : Type u_3} [add_group A] {s : set A} : is_subgroup s \u2194 is_add_subgroup s := sorry\n\n/-- The group structure on a subgroup coerced to a type. -/\ndef subtype.group {G : Type u_1} [group G] {s : set G} [is_subgroup s] : group \u21a5s :=\n  group.mk monoid.mul sorry monoid.one sorry sorry (fun (x : \u21a5s) => { val := \u2191x\u207b\u00b9, property := sorry })\n    (fun (x y : \u21a5s) => { val := \u2191x / \u2191y, property := sorry }) sorry\n\n/-- The commutative group structure on a commutative subgroup coerced to a type. -/\ndef subtype.comm_group {G : Type u_1} [comm_group G] {s : set G} [is_subgroup s] : comm_group \u21a5s :=\n  comm_group.mk group.mul sorry group.one sorry sorry group.inv group.div sorry sorry\n\n@[simp] theorem is_subgroup.coe_inv {G : Type u_1} [group G] {s : set G} [is_subgroup s] (a : \u21a5s) : \u2191(a\u207b\u00b9) = (\u2191a\u207b\u00b9) :=\n  rfl\n\n@[simp] theorem is_subgroup.coe_gpow {G : Type u_1} [group G] {s : set G} [is_subgroup s] (a : \u21a5s) (n : \u2124) : \u2191(a ^ n) = \u2191a ^ n := sorry\n\n@[simp] theorem is_add_subgroup.gsmul_coe {A : Type u_3} [add_group A] {s : set A} [is_add_subgroup s] (a : \u21a5s) (n : \u2124) : \u2191(n \u2022\u2124 a) = n \u2022\u2124 \u2191a := sorry\n\ntheorem is_add_subgroup.of_add_neg {G : Type u_1} [add_group G] (s : set G) (one_mem : 0 \u2208 s) (div_mem : \u2200 {a b : G}, a \u2208 s \u2192 b \u2208 s \u2192 a + -b \u2208 s) : is_add_subgroup s := sorry\n\ntheorem is_add_subgroup.of_sub {A : Type u_3} [add_group A] (s : set A) (zero_mem : 0 \u2208 s) (sub_mem : \u2200 {a b : A}, a \u2208 s \u2192 b \u2208 s \u2192 a - b \u2208 s) : is_add_subgroup s := sorry\n\nprotected instance is_add_subgroup.inter {G : Type u_1} [add_group G] (s\u2081 : set G) (s\u2082 : set G) [is_add_subgroup s\u2081] [is_add_subgroup s\u2082] : is_add_subgroup (s\u2081 \u2229 s\u2082) :=\n  is_add_subgroup.mk\n    fun (x : G) (hx : x \u2208 s\u2081 \u2229 s\u2082) =>\n      { left := is_add_subgroup.neg_mem (and.left hx), right := is_add_subgroup.neg_mem (and.right hx) }\n\nprotected instance is_add_subgroup.Inter {G : Type u_1} [add_group G] {\u03b9 : Sort u_2} (s : \u03b9 \u2192 set G) [h : \u2200 (y : \u03b9), is_add_subgroup (s y)] : is_add_subgroup (set.Inter s) :=\n  is_add_subgroup.mk\n    fun (x : G) (h_1 : x \u2208 set.Inter s) =>\n      iff.mpr set.mem_Inter fun (y : \u03b9) => is_add_subgroup.neg_mem (iff.mp set.mem_Inter h_1 y)\n\ntheorem is_add_subgroup_Union_of_directed {G : Type u_1} [add_group G] {\u03b9 : Type u_2} [h\u03b9 : Nonempty \u03b9] (s : \u03b9 \u2192 set G) [\u2200 (i : \u03b9), is_add_subgroup (s i)] (directed : \u2200 (i j : \u03b9), \u2203 (k : \u03b9), s i \u2286 s k \u2227 s j \u2286 s k) : is_add_subgroup (set.Union fun (i : \u03b9) => s i) := sorry\n\ndef gpowers {G : Type u_1} [group G] (x : G) : set G :=\n  set.range (pow x)\n\ndef gmultiples {A : Type u_3} [add_group A] (x : A) : set A :=\n  set.range fun (i : \u2124) => i \u2022\u2124 x\n\nprotected instance gpowers.is_subgroup {G : Type u_1} [group G] (x : G) : is_subgroup (gpowers x) :=\n  is_subgroup.mk fun (x\u2080 : G) (_x : x\u2080 \u2208 gpowers x) => sorry\n\nprotected instance gmultiples.is_add_subgroup {A : Type u_3} [add_group A] (x : A) : is_add_subgroup (gmultiples x) :=\n  iff.mp multiplicative.is_subgroup_iff (gpowers.is_subgroup x)\n\ntheorem is_subgroup.gpow_mem {G : Type u_1} [group G] {a : G} {s : set G} [is_subgroup s] (h : a \u2208 s) {i : \u2124} : a ^ i \u2208 s :=\n  int.cases_on i (fun (i : \u2115) => idRhs (a ^ i \u2208 s) (is_submonoid.pow_mem h))\n    fun (i : \u2115) => idRhs (a ^ Nat.succ i\u207b\u00b9 \u2208 s) (is_subgroup.inv_mem (is_submonoid.pow_mem h))\n\ntheorem is_add_subgroup.gsmul_mem {A : Type u_3} [add_group A] {a : A} {s : set A} [is_add_subgroup s] : a \u2208 s \u2192 \u2200 {i : \u2124}, i \u2022\u2124 a \u2208 s :=\n  is_subgroup.gpow_mem\n\ntheorem gpowers_subset {G : Type u_1} [group G] {a : G} {s : set G} [is_subgroup s] (h : a \u2208 s) : gpowers a \u2286 s := sorry\n\ntheorem gmultiples_subset {A : Type u_3} [add_group A] {a : A} {s : set A} [is_add_subgroup s] (h : a \u2208 s) : gmultiples a \u2286 s :=\n  gpowers_subset h\n\ntheorem mem_gpowers {G : Type u_1} [group G] {a : G} : a \u2208 gpowers a := sorry\n\ntheorem mem_gmultiples {A : Type u_3} [add_group A] {a : A} : a \u2208 gmultiples a := sorry\n\nnamespace is_subgroup\n\n\ntheorem inv_mem_iff {G : Type u_1} {a : G} [group G] (s : set G) [is_subgroup s] : a\u207b\u00b9 \u2208 s \u2194 a \u2208 s := sorry\n\ntheorem Mathlib.is_add_subgroup.add_mem_cancel_right {G : Type u_1} {a : G} {b : G} [add_group G] (s : set G) [is_add_subgroup s] (h : a \u2208 s) : b + a \u2208 s \u2194 b \u2208 s := sorry\n\ntheorem Mathlib.is_add_subgroup.add_mem_cancel_left {G : Type u_1} {a : G} {b : G} [add_group G] (s : set G) [is_add_subgroup s] (h : a \u2208 s) : a + b \u2208 s \u2194 b \u2208 s := sorry\n\nend is_subgroup\n\n\nclass normal_add_subgroup {A : Type u_3} [add_group A] (s : set A) \nextends is_add_subgroup s\nwhere\n  normal : \u2200 (n : A), n \u2208 s \u2192 \u2200 (g : A), g + n + -g \u2208 s\n\nclass normal_subgroup {G : Type u_1} [group G] (s : set G) \nextends is_subgroup s\nwhere\n  normal : \u2200 (n : G), n \u2208 s \u2192 \u2200 (g : G), g * n * (g\u207b\u00b9) \u2208 s\n\ntheorem normal_add_subgroup_of_add_comm_group {G : Type u_1} [add_comm_group G] (s : set G) [hs : is_add_subgroup s] : normal_add_subgroup s := sorry\n\ntheorem additive.normal_add_subgroup {G : Type u_1} [group G] (s : set G) [normal_subgroup s] : normal_add_subgroup s :=\n  normal_add_subgroup.mk normal_subgroup.normal\n\ntheorem additive.normal_add_subgroup_iff {G : Type u_1} [group G] {s : set G} : normal_add_subgroup s \u2194 normal_subgroup s := sorry\n\ntheorem multiplicative.normal_subgroup {A : Type u_3} [add_group A] (s : set A) [normal_add_subgroup s] : normal_subgroup s :=\n  normal_subgroup.mk normal_add_subgroup.normal\n\ntheorem multiplicative.normal_subgroup_iff {A : Type u_3} [add_group A] {s : set A} : normal_subgroup s \u2194 normal_add_subgroup s := sorry\n\nnamespace is_subgroup\n\n\n-- Normal subgroup properties\n\ntheorem mem_norm_comm {G : Type u_1} [group G] {s : set G} [normal_subgroup s] {a : G} {b : G} (hab : a * b \u2208 s) : b * a \u2208 s := sorry\n\ntheorem Mathlib.is_add_subgroup.mem_norm_comm_iff {G : Type u_1} [add_group G] {s : set G} [normal_add_subgroup s] {a : G} {b : G} : a + b \u2208 s \u2194 b + a \u2208 s :=\n  { mp := is_add_subgroup.mem_norm_comm, mpr := is_add_subgroup.mem_norm_comm }\n\n/-- The trivial subgroup -/\ndef trivial (G : Type u_1) [group G] : set G :=\n  singleton 1\n\n@[simp] theorem Mathlib.is_add_subgroup.mem_trivial {G : Type u_1} [add_group G] {g : G} : g \u2208 is_add_subgroup.trivial G \u2194 g = 0 :=\n  set.mem_singleton_iff\n\nprotected instance Mathlib.is_add_subgroup.trivial_normal {G : Type u_1} [add_group G] : normal_add_subgroup (is_add_subgroup.trivial G) := sorry\n\ntheorem Mathlib.is_add_subgroup.eq_trivial_iff {G : Type u_1} [add_group G] {s : set G} [is_add_subgroup s] : s = is_add_subgroup.trivial G \u2194 \u2200 (x : G), x \u2208 s \u2192 x = 0 := sorry\n\nprotected instance univ_subgroup {G : Type u_1} [group G] : normal_subgroup set.univ :=\n  normal_subgroup.mk\n    (eq.mpr\n      (id\n        (Eq.trans\n          (forall_congr_eq\n            fun (n : G) =>\n              Eq.trans\n                (imp_congr_eq (propext ((fun {\u03b1 : Type u_1} (x : \u03b1) => iff_true_intro (set.mem_univ x)) n))\n                  (Eq.trans\n                    (forall_congr_eq\n                      fun (g : G) =>\n                        propext ((fun {\u03b1 : Type u_1} (x : \u03b1) => iff_true_intro (set.mem_univ x)) (g * n * (g\u207b\u00b9))))\n                    (propext (forall_const G))))\n                (propext (forall_prop_of_true True.intro)))\n          (propext (forall_const G))))\n      trivial)\n\ndef Mathlib.is_add_subgroup.add_center (G : Type u_1) [add_group G] : set G :=\n  set_of fun (z : G) => \u2200 (g : G), g + z = z + g\n\ntheorem mem_center {G : Type u_1} [group G] {a : G} : a \u2208 center G \u2194 \u2200 (g : G), g * a = a * g :=\n  iff.rfl\n\nprotected instance center_normal {G : Type u_1} [group G] : normal_subgroup (center G) := sorry\n\ndef Mathlib.is_add_subgroup.add_normalizer {G : Type u_1} [add_group G] (s : set G) : set G :=\n  set_of fun (g : G) => \u2200 (n : G), n \u2208 s \u2194 g + n + -g \u2208 s\n\nprotected instance Mathlib.is_add_subgroup.normalizer_is_add_subgroup {G : Type u_1} [add_group G] (s : set G) : is_add_subgroup (is_add_subgroup.add_normalizer s) := sorry\n\ntheorem Mathlib.is_add_subgroup.subset_add_normalizer {G : Type u_1} [add_group G] (s : set G) [is_add_subgroup s] : s \u2286 is_add_subgroup.add_normalizer s := sorry\n\n/-- Every subgroup is a normal subgroup of its normalizer -/\nprotected instance Mathlib.is_add_subgroup.add_normal_in_add_normalizer {G : Type u_1} [add_group G] (s : set G) [is_add_subgroup s] : normal_add_subgroup (subtype.val \u207b\u00b9' s) :=\n  normal_add_subgroup.mk\n    fun (a : \u21a5(is_add_subgroup.add_normalizer s)) (ha : a \u2208 subtype.val \u207b\u00b9' s)\n      (_x : \u21a5(is_add_subgroup.add_normalizer s)) => sorry\n\nend is_subgroup\n\n\n-- Homomorphism subgroups\n\nnamespace is_group_hom\n\n\ndef ker {G : Type u_1} {H : Type u_2} [group H] (f : G \u2192 H) : set G :=\n  f \u207b\u00b9' is_subgroup.trivial H\n\ntheorem Mathlib.is_add_group_hom.mem_ker {G : Type u_1} {H : Type u_2} [add_group H] (f : G \u2192 H) {x : G} : x \u2208 is_add_group_hom.ker f \u2194 f x = 0 :=\n  is_add_subgroup.mem_trivial\n\ntheorem Mathlib.is_add_group_hom.zero_ker_neg {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] {a : G} {b : G} (h : f (a + -b) = 0) : f a = f b := sorry\n\ntheorem one_ker_inv' {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] {a : G} {b : G} (h : f (a\u207b\u00b9 * b) = 1) : f a = f b := sorry\n\ntheorem Mathlib.is_add_group_hom.neg_ker_zero {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] {a : G} {b : G} (h : f a = f b) : f (a + -b) = 0 := sorry\n\ntheorem inv_ker_one' {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] {a : G} {b : G} (h : f a = f b) : f (a\u207b\u00b9 * b) = 1 := sorry\n\ntheorem Mathlib.is_add_group_hom.zero_iff_ker_neg {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] (a : G) (b : G) : f a = f b \u2194 f (a + -b) = 0 :=\n  { mp := is_add_group_hom.neg_ker_zero f, mpr := is_add_group_hom.zero_ker_neg f }\n\ntheorem one_iff_ker_inv' {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] (a : G) (b : G) : f a = f b \u2194 f (a\u207b\u00b9 * b) = 1 :=\n  { mp := inv_ker_one' f, mpr := one_ker_inv' f }\n\ntheorem inv_iff_ker {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [w : is_group_hom f] (a : G) (b : G) : f a = f b \u2194 a * (b\u207b\u00b9) \u2208 ker f :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (f a = f b \u2194 a * (b\u207b\u00b9) \u2208 ker f)) (propext (mem_ker f)))) (one_iff_ker_inv f a b)\n\ntheorem inv_iff_ker' {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [w : is_group_hom f] (a : G) (b : G) : f a = f b \u2194 a\u207b\u00b9 * b \u2208 ker f :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (f a = f b \u2194 a\u207b\u00b9 * b \u2208 ker f)) (propext (mem_ker f)))) (one_iff_ker_inv' f a b)\n\nprotected instance Mathlib.is_add_group_hom.image_add_subgroup {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] (s : set G) [is_add_subgroup s] : is_add_subgroup (f '' s) :=\n  is_add_subgroup.mk fun (a : H) (_x : a \u2208 f '' s) => sorry\n\nprotected instance range_subgroup {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] : is_subgroup (set.range f) :=\n  set.image_univ \u25b8 is_group_hom.image_subgroup f set.univ\n\nprotected instance preimage {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] (s : set H) [is_subgroup s] : is_subgroup (f \u207b\u00b9' s) :=\n  is_subgroup.mk\n    (eq.mpr\n      (id\n        (Eq.trans\n          (forall_congr_eq\n            fun (a : G) =>\n              Eq.trans\n                (imp_congr_ctx_eq (propext set.mem_preimage)\n                  fun (_h : f a \u2208 s) =>\n                    Eq.trans\n                      (Eq.trans (propext set.mem_preimage)\n                        ((fun (\u1fb0 \u1fb0_1 : H) (e_2 : \u1fb0 = \u1fb0_1) (\u1fb0_2 \u1fb0_3 : set H) (e_3 : \u1fb0_2 = \u1fb0_3) =>\n                            congr (congr_arg has_mem.mem e_2) e_3)\n                          (f (a\u207b\u00b9)) (f a\u207b\u00b9) (map_inv f a) s s (Eq.refl s)))\n                      (propext\n                        ((fun [c : is_subgroup s] {a : H} (\u1fb0 : a \u2208 s) => iff_true_intro (is_subgroup.inv_mem \u1fb0))\n                          (iff.mpr (iff_true_intro _h) True.intro))))\n                (propext forall_true_iff))\n          (propext (forall_const G))))\n      trivial)\n\nprotected instance preimage_normal {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] (s : set H) [normal_subgroup s] : normal_subgroup (f \u207b\u00b9' s) := sorry\n\nprotected instance normal_subgroup_ker {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] : normal_subgroup (ker f) :=\n  is_group_hom.preimage_normal f (is_subgroup.trivial H)\n\ntheorem Mathlib.is_add_group_hom.injective_of_trivial_ker {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] (h : is_add_group_hom.ker f = is_add_subgroup.trivial G) : function.injective f := sorry\n\ntheorem trivial_ker_of_injective {G : Type u_1} {H : Type u_2} [group G] [group H] (f : G \u2192 H) [is_group_hom f] (h : function.injective f) : ker f = is_subgroup.trivial G := sorry\n\ntheorem Mathlib.is_add_group_hom.injective_iff_trivial_ker {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] : function.injective f \u2194 is_add_group_hom.ker f = is_add_subgroup.trivial G :=\n  { mp := is_add_group_hom.trivial_ker_of_injective f, mpr := is_add_group_hom.injective_of_trivial_ker f }\n\ntheorem Mathlib.is_add_group_hom.trivial_ker_iff_eq_zero {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] : is_add_group_hom.ker f = is_add_subgroup.trivial G \u2194 \u2200 (x : G), f x = 0 \u2192 x = 0 := sorry\n\nend is_group_hom\n\n\nprotected instance subtype_val.is_add_group_hom {G : Type u_1} [add_group G] {s : set G} [is_add_subgroup s] : is_add_group_hom subtype.val :=\n  is_add_group_hom.mk\n\nprotected instance coe.is_add_group_hom {G : Type u_1} [add_group G] {s : set G} [is_add_subgroup s] : is_add_group_hom coe :=\n  is_add_group_hom.mk\n\nprotected instance subtype_mk.is_group_hom {G : Type u_1} {H : Type u_2} [group G] [group H] {s : set G} [is_subgroup s] (f : H \u2192 G) [is_group_hom f] (h : \u2200 (x : H), f x \u2208 s) : is_group_hom fun (x : H) => { val := f x, property := h x } :=\n  is_group_hom.mk\n\nprotected instance set_inclusion.is_group_hom {G : Type u_1} [group G] {s : set G} {t : set G} [is_subgroup s] [is_subgroup t] (h : s \u2286 t) : is_group_hom (set.inclusion h) :=\n  subtype_mk.is_group_hom (fun (x : \u21a5s) => \u2191x) fun (x : \u21a5s) => set.inclusion._proof_1 h x\n\n/-- `subtype.val : set.range f \u2192 H` as a monoid homomorphism, when `f` is a monoid homomorphism. -/\ndef monoid_hom.range_subtype_val {G : Type u_1} {H : Type u_2} [monoid G] [monoid H] (f : G \u2192* H) : \u21a5(set.range \u21d1f) \u2192* H :=\n  monoid_hom.of subtype.val\n\n/-- `set.range_factorization f : G \u2192 set.range f` as a monoid homomorphism, when `f` is a monoid\nhomomorphism. -/\ndef add_monoid_hom.range_factorization {G : Type u_1} {H : Type u_2} [add_monoid G] [add_monoid H] (f : G \u2192+ H) : G \u2192+ \u21a5(set.range \u21d1f) :=\n  add_monoid_hom.mk (set.range_factorization \u21d1f) sorry sorry\n\nnamespace add_group\n\n\ninductive in_closure {A : Type u_3} [add_group A] (s : set A) : A \u2192 Prop\nwhere\n| basic : \u2200 {a : A}, a \u2208 s \u2192 in_closure s a\n| zero : in_closure s 0\n| neg : \u2200 {a : A}, in_closure s a \u2192 in_closure s (-a)\n| add : \u2200 {a b : A}, in_closure s a \u2192 in_closure s b \u2192 in_closure s (a + b)\n\nend add_group\n\n\nnamespace group\n\n\ninductive in_closure {G : Type u_1} [group G] (s : set G) : G \u2192 Prop\nwhere\n| basic : \u2200 {a : G}, a \u2208 s \u2192 in_closure s a\n| one : in_closure s 1\n| inv : \u2200 {a : G}, in_closure s a \u2192 in_closure s (a\u207b\u00b9)\n| mul : \u2200 {a b : G}, in_closure s a \u2192 in_closure s b \u2192 in_closure s (a * b)\n\n/-- `group.closure s` is the subgroup closed over `s`, i.e. the smallest subgroup containg s. -/\ndef Mathlib.add_group.closure {G : Type u_1} [add_group G] (s : set G) : set G :=\n  set_of fun (a : G) => add_group.in_closure s a\n\ntheorem Mathlib.add_group.mem_closure {G : Type u_1} [add_group G] {s : set G} {a : G} : a \u2208 s \u2192 a \u2208 add_group.closure s :=\n  add_group.in_closure.basic\n\nprotected instance closure.is_subgroup {G : Type u_1} [group G] (s : set G) : is_subgroup (closure s) :=\n  is_subgroup.mk fun (a : G) => in_closure.inv\n\ntheorem Mathlib.add_group.subset_closure {G : Type u_1} [add_group G] {s : set G} : s \u2286 add_group.closure s :=\n  fun (a : G) => add_group.mem_closure\n\ntheorem Mathlib.add_group.closure_subset {G : Type u_1} [add_group G] {s : set G} {t : set G} [is_add_subgroup t] (h : s \u2286 t) : add_group.closure s \u2286 t := sorry\n\ntheorem Mathlib.add_group.closure_subset_iff {G : Type u_1} [add_group G] (s : set G) (t : set G) [is_add_subgroup t] : add_group.closure s \u2286 t \u2194 s \u2286 t :=\n  { mp := fun (h : add_group.closure s \u2286 t) (b : G) (ha : b \u2208 s) => h (add_group.mem_closure ha),\n    mpr := fun (h : s \u2286 t) (b : G) (ha : b \u2208 add_group.closure s) => add_group.closure_subset h ha }\n\ntheorem Mathlib.add_group.closure_mono {G : Type u_1} [add_group G] {s : set G} {t : set G} (h : s \u2286 t) : add_group.closure s \u2286 add_group.closure t :=\n  add_group.closure_subset (set.subset.trans h add_group.subset_closure)\n\n@[simp] theorem closure_subgroup {G : Type u_1} [group G] (s : set G) [is_subgroup s] : closure s = s :=\n  set.subset.antisymm (closure_subset (set.subset.refl s)) subset_closure\n\ntheorem Mathlib.add_group.exists_list_of_mem_closure {G : Type u_1} [add_group G] {s : set G} {a : G} (h : a \u2208 add_group.closure s) : \u2203 (l : List G), (\u2200 (x : G), x \u2208 l \u2192 x \u2208 s \u2228 -x \u2208 s) \u2227 list.sum l = a := sorry\n\ntheorem Mathlib.add_group.image_closure {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] (f : G \u2192 H) [is_add_group_hom f] (s : set G) : f '' add_group.closure s = add_group.closure (f '' s) := sorry\n\ntheorem Mathlib.add_group.mclosure_subset {G : Type u_1} [add_group G] {s : set G} : add_monoid.closure s \u2286 add_group.closure s :=\n  add_monoid.closure_subset add_group.subset_closure\n\ntheorem Mathlib.add_group.mclosure_neg_subset {G : Type u_1} [add_group G] {s : set G} : add_monoid.closure (Neg.neg \u207b\u00b9' s) \u2286 add_group.closure s :=\n  add_monoid.closure_subset\n    fun (x : G) (hx : x \u2208 Neg.neg \u207b\u00b9' s) => neg_neg x \u25b8 is_add_subgroup.neg_mem (add_group.subset_closure hx)\n\ntheorem Mathlib.add_group.closure_eq_mclosure {G : Type u_1} [add_group G] {s : set G} : add_group.closure s = add_monoid.closure (s \u222a Neg.neg \u207b\u00b9' s) := sorry\n\ntheorem Mathlib.add_group.mem_closure_union_iff {G : Type u_1} [add_comm_group G] {s : set G} {t : set G} {x : G} : x \u2208 add_group.closure (s \u222a t) \u2194\n  \u2203 (y : G), \u2203 (H : y \u2208 add_group.closure s), \u2203 (z : G), \u2203 (H : z \u2208 add_group.closure t), y + z = x := sorry\n\ntheorem gpowers_eq_closure {G : Type u_1} [group G] {a : G} : gpowers a = closure (singleton a) := sorry\n\nend group\n\n\nnamespace is_subgroup\n\n\ntheorem Mathlib.is_add_subgroup.trivial_eq_closure {G : Type u_1} [add_group G] : is_add_subgroup.trivial G = add_group.closure \u2205 := sorry\n\nend is_subgroup\n\n\n/-The normal closure of a set s is the subgroup closure of all the conjugates of\nelements of s. It is the smallest normal subgroup containing s. -/\n\nnamespace group\n\n\ntheorem conjugates_subset {G : Type u_1} [group G] {t : set G} [normal_subgroup t] {a : G} (h : a \u2208 t) : conjugates a \u2286 t := sorry\n\ntheorem conjugates_of_set_subset' {G : Type u_1} [group G] {s : set G} {t : set G} [normal_subgroup t] (h : s \u2286 t) : conjugates_of_set s \u2286 t :=\n  set.bUnion_subset fun (x : G) (H : x \u2208 s) => conjugates_subset (h H)\n\n/-- The normal closure of a set s is the subgroup closure of all the conjugates of\nelements of s. It is the smallest normal subgroup containing s. -/\ndef normal_closure {G : Type u_1} [group G] (s : set G) : set G :=\n  closure (conjugates_of_set s)\n\ntheorem conjugates_of_set_subset_normal_closure {G : Type u_1} {s : set G} [group G] : conjugates_of_set s \u2286 normal_closure s :=\n  subset_closure\n\ntheorem subset_normal_closure {G : Type u_1} {s : set G} [group G] : s \u2286 normal_closure s :=\n  set.subset.trans subset_conjugates_of_set conjugates_of_set_subset_normal_closure\n\n/-- The normal closure of a set is a subgroup. -/\nprotected instance normal_closure.is_subgroup {G : Type u_1} [group G] (s : set G) : is_subgroup (normal_closure s) :=\n  closure.is_subgroup (conjugates_of_set s)\n\n/-- The normal closure of s is a normal subgroup. -/\nprotected instance normal_closure.is_normal {G : Type u_1} {s : set G} [group G] : normal_subgroup (normal_closure s) := sorry\n\n/-- The normal closure of s is the smallest normal subgroup containing s. -/\ntheorem normal_closure_subset {G : Type u_1} [group G] {s : set G} {t : set G} [normal_subgroup t] (h : s \u2286 t) : normal_closure s \u2286 t := sorry\n\ntheorem normal_closure_subset_iff {G : Type u_1} [group G] {s : set G} {t : set G} [normal_subgroup t] : s \u2286 t \u2194 normal_closure s \u2286 t :=\n  { mp := normal_closure_subset, mpr := set.subset.trans subset_normal_closure }\n\ntheorem normal_closure_mono {G : Type u_1} [group G] {s : set G} {t : set G} : s \u2286 t \u2192 normal_closure s \u2286 normal_closure t :=\n  fun (h : s \u2286 t) => normal_closure_subset (set.subset.trans h subset_normal_closure)\n\nend group\n\n\nclass simple_group (G : Type u_4) [group G] \nwhere\n  simple : \u2200 (N : set G) [_inst_1_1 : normal_subgroup N], N = is_subgroup.trivial G \u2228 N = set.univ\n\nclass simple_add_group (A : Type u_4) [add_group A] \nwhere\n  simple : \u2200 (N : set A) [_inst_1_1 : normal_add_subgroup N], N = is_add_subgroup.trivial A \u2228 N = set.univ\n\ntheorem additive.simple_add_group_iff {G : Type u_1} [group G] : simple_add_group (additive G) \u2194 simple_group G := sorry\n\nprotected instance additive.simple_add_group {G : Type u_1} [group G] [simple_group G] : simple_add_group (additive G) :=\n  iff.mpr additive.simple_add_group_iff _inst_2\n\ntheorem multiplicative.simple_group_iff {A : Type u_3} [add_group A] : simple_group (multiplicative A) \u2194 simple_add_group A := sorry\n\nprotected instance multiplicative.simple_group {A : Type u_3} [add_group A] [simple_add_group A] : simple_group (multiplicative A) :=\n  iff.mpr multiplicative.simple_group_iff _inst_2\n\ntheorem simple_add_group_of_surjective {G : Type u_1} {H : Type u_2} [add_group G] [add_group H] [simple_add_group G] (f : G \u2192 H) [is_add_group_hom f] (hf : function.surjective f) : simple_add_group H := sorry\n\n/-- Create a bundled subgroup from a set `s` and `[is_subroup s]`. -/\ndef subgroup.of {G : Type u_1} [group G] (s : set G) [h : is_subgroup s] : subgroup G :=\n  subgroup.mk s sorry sorry is_subgroup.inv_mem\n\nprotected instance subgroup.is_subgroup {G : Type u_1} [group G] (K : subgroup G) : is_subgroup \u2191K :=\n  is_subgroup.mk (subgroup.inv_mem' K)\n\nprotected instance subgroup.of_normal {G : Type u_1} [group G] (s : set G) [h : is_subgroup s] [n : normal_subgroup s] : subgroup.normal (subgroup.of s) :=\n  subgroup.normal.mk normal_subgroup.normal\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/deprecated/subgroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7078431866371768}}
{"text": "import game.world10.level12 -- hide\nnamespace mynat -- hide\n/- \n\n# Inequality world. \n\n## Level 13: `not_succ_le_self`\n\nTurns out that `\u00ac P` is *by definition* `P \u2192 false`, so you can just\nstart this one with `intro h` if you like. \n\n## Pro tip:\n\n```\n  conv begin\n    to_lhs,\n    rw hc,\n  end,\n```\n\nis an incantation which rewrites `hc` only on the left hand side of the goal.\nLook carefully at the commas. You don't need to use `conv` to solve this,\nbut it's a helpful trick when `rw` is rewriting too much.\n-/\n\n/- Lemma\nFor all naturals $a$, $\\operatorname{succ}(a)$ is not at most $a$.\n-/\ntheorem not_succ_le_self (a : mynat) : \u00ac (succ a \u2264 a) :=\nbegin [nat_num_game]\n  intro h,\n  cases h with c h,\n  induction a with d hd,\n  { rw succ_add at h,\n    exact zero_ne_succ _ h,\n  },\n  { rw succ_add at h,\n    apply hd,\n    apply succ_inj,\n    exact h,\n  }\n\n\n\n\nend\n\nend mynat -- hide\n\n-- thanks to Filip Szczepa\u0144ski for this proof (nicer than the original; I was doing -- hide\n-- induction a before cases h) -- hide", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world10/level13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7078431845349389}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport ring_theory.trace\nimport ring_theory.norm\nimport number_theory.number_field.basic\n\n/-!\n# Discriminant of a family of vectors\n\nGiven an `A`-algebra `B` and `b`, an `\u03b9`-indexed family of elements of `B`, we define the\n*discriminant* of `b` as the determinant of the matrix whose `(i j)`-th element is the trace of\n`b i * b j`.\n\n## Main definition\n\n* `algebra.discr A b` : the discriminant of `b : \u03b9 \u2192 B`.\n\n## Main results\n\n* `algebra.discr_zero_of_not_linear_independent` : if `b` is not linear independent, then\n  `algebra.discr A b = 0`.\n* `algebra.discr_of_matrix_vec_mul` and `discr_of_matrix_mul_vec` : formulas relating\n  `algebra.discr A \u03b9 b` with `algebra.discr A ((P.map (algebra_map A B)).vec_mul b)` and\n  `algebra.discr A ((P.map (algebra_map A B)).mul_vec b)`.\n* `algebra.discr_not_zero_of_basis` : over a field, if `b` is a basis, then\n  `algebra.discr K b \u2260 0`.\n* `algebra.discr_eq_det_embeddings_matrix_reindex_pow_two` : if `L/K` is a field extension and\n  `b : \u03b9 \u2192 L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)`\n  coefficient is `\u03c3\u2c7c (b i)`, where `\u03c3\u2c7c : L \u2192\u2090[K] E` is the embedding in an algebraically closed\n  field `E` corresponding to `j : \u03b9` via a bijection `e : \u03b9 \u2243 (L \u2192\u2090[K] E)`.\n* `algebra.discr_of_power_basis_eq_prod` : the discriminant of a power basis.\n* `discr_is_integral` : if `K` and `L` are fields and `is_scalar_tower R K L`, is `b : \u03b9 \u2192 L`\n  satisfies ` \u2200 i, is_integral R (b i)`, then `is_integral R (discr K b)`.\n* `discr_mul_is_integral_mem_adjoin` : let `K` be the fraction field of an integrally closed domain\n  `R` and let `L` be a finite separable extension of `K`. Let `B : power_basis K L` be such that\n  `is_integral R B.gen`. Then for all, `z : L` we have\n  `(discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L)`.\n\n## Implementation details\n\nOur definition works for any `A`-algebra `B`, but note that if `B` is not free as an `A`-module,\nthen `trace A B = 0` by definition, so `discr A b = 0` for any `b`.\n-/\n\nuniverses u v w z\n\nopen_locale matrix big_operators\n\nopen matrix finite_dimensional fintype polynomial finset intermediate_field\n\nnamespace algebra\n\nvariables (A : Type u) {B : Type v} (C : Type z) {\u03b9 : Type w}\nvariables [comm_ring A] [comm_ring B] [algebra A B] [comm_ring C] [algebra A C]\n\nsection discr\n\n/-- Given an `A`-algebra `B` and `b`, an `\u03b9`-indexed family of elements of `B`, we define\n`discr A \u03b9 b` as the determinant of `trace_matrix A \u03b9 b`. -/\nnoncomputable\ndef discr (A : Type u) {B : Type v} [comm_ring A] [comm_ring B] [algebra A B] [fintype \u03b9]\n  (b : \u03b9 \u2192 B) := by { classical, exact (trace_matrix A b).det }\n\nlemma discr_def [decidable_eq \u03b9] [fintype \u03b9] (b : \u03b9 \u2192 B) :\n  discr A b = (trace_matrix A b).det := by convert rfl\n\nvariables {\u03b9' : Type*} [fintype \u03b9'] [fintype \u03b9]\n\nsection basic\n\n@[simp] lemma discr_reindex (b : basis \u03b9 A B) (f : \u03b9 \u2243 \u03b9') :\n  discr A (b \u2218 \u21d1(f.symm)) = discr A b :=\nbegin\n  classical,\n  rw [\u2190 basis.coe_reindex, discr_def, trace_matrix_reindex, det_reindex_self, \u2190 discr_def]\nend\n\n/-- If `b` is not linear independent, then `algebra.discr A b = 0`. -/\nlemma discr_zero_of_not_linear_independent [is_domain A] {b : \u03b9 \u2192 B}\n  (hli : \u00aclinear_independent A b) : discr A b = 0 :=\nbegin\n  classical,\n  obtain \u27e8g, hg, i, hi\u27e9 := fintype.not_linear_independent_iff.1 hli,\n  have : (trace_matrix A b).mul_vec g = 0,\n  { ext i,\n    have : \u2200 j, (trace A B) (b i * b j) * g j = (trace A B) (((g j) \u2022 (b j)) * b i),\n    { intro j, simp [mul_comm], },\n    simp only [mul_vec, dot_product, trace_matrix_apply, pi.zero_apply, trace_form_apply,\n      \u03bb j, this j, \u2190 linear_map.map_sum, \u2190 sum_mul, hg, zero_mul, linear_map.map_zero] },\n  by_contra h,\n  rw discr_def at h,\n  simpa [matrix.eq_zero_of_mul_vec_eq_zero h this] using hi,\nend\n\nvariable {A}\n\n/-- Relation between `algebra.discr A \u03b9 b` and\n`algebra.discr A ((P.map (algebra_map A B)).vec_mul b)`. -/\nlemma discr_of_matrix_vec_mul [decidable_eq \u03b9] (b : \u03b9 \u2192 B) (P : matrix \u03b9 \u03b9 A) :\n  discr A ((P.map (algebra_map A B)).vec_mul b) = P.det ^ 2 * discr A b :=\nby rw [discr_def, trace_matrix_of_matrix_vec_mul, det_mul, det_mul, det_transpose, mul_comm,\n    \u2190 mul_assoc, discr_def, pow_two]\n\n/-- Relation between `algebra.discr A \u03b9 b` and\n`algebra.discr A ((P.map (algebra_map A B)).mul_vec b)`. -/\nlemma discr_of_matrix_mul_vec [decidable_eq \u03b9] (b : \u03b9 \u2192 B) (P : matrix \u03b9 \u03b9 A) :\n  discr A ((P.map (algebra_map A B)).mul_vec b) = P.det ^ 2 * discr A b :=\nby rw [discr_def, trace_matrix_of_matrix_mul_vec, det_mul, det_mul, det_transpose,\n  mul_comm, \u2190 mul_assoc, discr_def, pow_two]\n\nend basic\n\nsection field\n\nvariables (K : Type u) {L : Type v} (E : Type z) [field K] [field L] [field E]\nvariables [algebra K L] [algebra K E]\nvariables [module.finite K L]  [is_alg_closed E]\n\n/-- Over a field, if `b` is a basis, then `algebra.discr K b \u2260 0`. -/\nlemma discr_not_zero_of_basis [is_separable K L] (b : basis \u03b9 K L) : discr K b \u2260 0 :=\nbegin\n  casesI is_empty_or_nonempty \u03b9,\n  { simp [discr] },\n  { have := span_eq_top_of_linear_independent_of_card_eq_finrank b.linear_independent\n      (finrank_eq_card_basis b).symm,\n    classical,\n    rw [discr_def, trace_matrix],\n    simp_rw [\u2190 basis.mk_apply b.linear_independent this.ge],\n    rw [\u2190 trace_matrix, trace_matrix_of_basis, \u2190 bilin_form.nondegenerate_iff_det_ne_zero],\n    exact trace_form_nondegenerate _ _ },\nend\n\n/-- Over a field, if `b` is a basis, then `algebra.discr K b` is a unit. -/\nlemma discr_is_unit_of_basis [is_separable K L] (b : basis \u03b9 K L) : is_unit (discr K b) :=\nis_unit.mk0 _ (discr_not_zero_of_basis _ _)\n\nvariables (b : \u03b9 \u2192 L) (pb : power_basis K L)\n\n/-- If `L/K` is a field extension and `b : \u03b9 \u2192 L`, then `discr K b` is the square of the\ndeterminant of the matrix whose `(i, j)` coefficient is `\u03c3\u2c7c (b i)`, where `\u03c3\u2c7c : L \u2192\u2090[K] E` is the\nembedding in an algebraically closed field `E` corresponding to `j : \u03b9` via a bijection\n`e : \u03b9 \u2243 (L \u2192\u2090[K] E)`. -/\nlemma discr_eq_det_embeddings_matrix_reindex_pow_two [decidable_eq \u03b9] [is_separable K L]\n  (e : \u03b9 \u2243 (L \u2192\u2090[K] E)) : algebra_map K E (discr K b) =\n  (embeddings_matrix_reindex K E b e).det ^ 2 :=\nby rw [discr_def, ring_hom.map_det, ring_hom.map_matrix_apply,\n    trace_matrix_eq_embeddings_matrix_reindex_mul_trans, det_mul, det_transpose, pow_two]\n\n/-- The discriminant of a power basis. -/\nlemma discr_power_basis_eq_prod (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) [is_separable K L] :\n  algebra_map K E (discr K pb.basis) =\n  \u220f i : fin pb.dim, \u220f j in Ioi i, (e j pb.gen- (e i pb.gen)) ^ 2 :=\nbegin\n  rw [discr_eq_det_embeddings_matrix_reindex_pow_two K E pb.basis e,\n    embeddings_matrix_reindex_eq_vandermonde, det_transpose, det_vandermonde, \u2190 prod_pow],\n  congr, ext i,\n  rw [\u2190 prod_pow]\nend\n\n/-- A variation of `of_power_basis_eq_prod`. -/\nlemma discr_power_basis_eq_prod' [is_separable K L] (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) :\n  algebra_map K E (discr K pb.basis) =\n  \u220f i : fin pb.dim, \u220f j in Ioi i, -((e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen)) :=\nbegin\n  rw [discr_power_basis_eq_prod _ _ _ e],\n  congr, ext i, congr, ext j,\n  ring\nend\n\nlocal notation `n` := finrank K L\n\n/-- A variation of `of_power_basis_eq_prod`. -/\nlemma discr_power_basis_eq_prod'' [is_separable K L] (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) :\n  algebra_map K E (discr K pb.basis) =\n  (-1) ^ (n * (n - 1) / 2) * \u220f i : fin pb.dim, \u220f j in Ioi i,\n    (e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen) :=\nbegin\n  rw [discr_power_basis_eq_prod' _ _ _ e],\n  simp_rw [\u03bb i j, neg_eq_neg_one_mul ((e j pb.gen- (e i pb.gen)) * (e i pb.gen- (e j pb.gen))),\n    prod_mul_distrib],\n  congr,\n  simp only [prod_pow_eq_pow_sum, prod_const],\n  congr,\n  rw [\u2190 @nat.cast_inj \u211a, nat.cast_sum],\n  have : \u2200 (x : fin pb.dim), (\u2191x + 1) \u2264 pb.dim := by simp [nat.succ_le_iff, fin.is_lt],\n  simp_rw [fin.card_Ioi, nat.sub_sub, add_comm 1],\n  simp only [nat.cast_sub, this, finset.card_fin, nsmul_eq_mul, sum_const, sum_sub_distrib,\n    nat.cast_add, nat.cast_one, sum_add_distrib, mul_one],\n  rw [\u2190 nat.cast_sum, \u2190 @finset.sum_range \u2115 _ pb.dim (\u03bb i, i), sum_range_id ],\n  have hn : n = pb.dim,\n  { rw [\u2190 alg_hom.card K L E, \u2190 fintype.card_fin pb.dim],\n    exact card_congr (equiv.symm e) },\n  have h\u2082 : 2 \u2223 (pb.dim * (pb.dim - 1)) := even_iff_two_dvd.1 (nat.even_mul_self_pred _),\n  have hne : ((2 : \u2115) : \u211a) \u2260 0 := by simp,\n  have hle : 1 \u2264 pb.dim,\n  { rw [\u2190 hn, nat.one_le_iff_ne_zero, \u2190 zero_lt_iff, finite_dimensional.finrank_pos_iff],\n    apply_instance },\n  rw [hn, nat.cast_div h\u2082 hne, nat.cast_mul, nat.cast_sub hle],\n  field_simp,\n  ring,\nend\n\n/-- Formula for the discriminant of a power basis using the norm of the field extension. -/\nlemma discr_power_basis_eq_norm [is_separable K L] : discr K pb.basis =\n  (-1) ^ (n * (n - 1) / 2) * (norm K (aeval pb.gen (minpoly K pb.gen).derivative)) :=\nbegin\n  let E := algebraic_closure L,\n  letI := \u03bb (a b : E), classical.prop_decidable (eq a b),\n\n  have e : fin pb.dim \u2243 (L \u2192\u2090[K] E),\n  { refine equiv_of_card_eq _,\n    rw [fintype.card_fin, alg_hom.card],\n    exact (power_basis.finrank pb).symm },\n  have hnodup : (map (algebra_map K E) (minpoly K pb.gen)).roots.nodup :=\n    nodup_roots (separable.map (is_separable.separable K pb.gen)),\n  have hroots : \u2200 \u03c3 : L \u2192\u2090[K] E, \u03c3 pb.gen \u2208 (map (algebra_map K E) (minpoly K pb.gen)).roots,\n  { intro \u03c3,\n    rw [mem_roots, is_root.def, eval_map, \u2190 aeval_def, aeval_alg_hom_apply],\n    repeat { simp [minpoly.ne_zero (is_separable.is_integral K pb.gen)] } },\n\n  apply (algebra_map K E).injective,\n  rw [ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_neg, ring_hom.map_one,\n    discr_power_basis_eq_prod'' _ _ _ e],\n  congr,\n  rw [norm_eq_prod_embeddings, prod_prod_Ioi_mul_eq_prod_prod_off_diag],\n  conv_rhs { congr, skip, funext,\n    rw [\u2190 aeval_alg_hom_apply, aeval_root_derivative_of_splits (minpoly.monic\n      (is_separable.is_integral K pb.gen)) (is_alg_closed.splits_codomain _) (hroots \u03c3),\n      \u2190 finset.prod_mk _ (hnodup.erase _)] },\n  rw [prod_sigma', prod_sigma'],\n  refine prod_bij (\u03bb i hi, \u27e8e i.2, e i.1 pb.gen\u27e9) (\u03bb i hi, _) (\u03bb i hi, by simp at hi)\n    (\u03bb i j hi hj hij, _) (\u03bb \u03c3 h\u03c3, _),\n  { simp only [true_and, finset.mem_mk, mem_univ, mem_sigma],\n    rw [multiset.mem_erase_of_ne (\u03bb h, _)],\n    { exact hroots _ },\n    { simp only [true_and, mem_univ, ne.def, mem_sigma, mem_compl, mem_singleton] at hi,\n      rw [\u2190 power_basis.lift_equiv_apply_coe, \u2190 power_basis.lift_equiv_apply_coe] at h,\n      exact hi (e.injective $ pb.lift_equiv.injective $ subtype.eq h.symm) } },\n  { simp only [equiv.apply_eq_iff_eq, heq_iff_eq] at hij,\n    have h := hij.2,\n    rw [\u2190 power_basis.lift_equiv_apply_coe, \u2190 power_basis.lift_equiv_apply_coe] at h,\n    refine sigma.eq (equiv.injective e (equiv.injective _ (subtype.eq h))) (by simp [hij.1]) },\n  { simp only [true_and, finset.mem_mk, mem_univ, mem_sigma] at \u22a2 h\u03c3,\n    simp only [sigma.exists, exists_prop, mem_compl, mem_singleton, ne.def],\n    refine \u27e8e.symm (power_basis.lift pb \u03c3.2 _), e.symm \u03c3.1, \u27e8\u03bb h, _, sigma.eq _ _\u27e9\u27e9,\n    { rw [aeval_def, eval\u2082_eq_eval_map, \u2190 is_root.def, \u2190 mem_roots],\n      { exact multiset.erase_subset _ _ h\u03c3 },\n      { simp [minpoly.ne_zero (is_separable.is_integral K pb.gen)] } },\n    { replace h := alg_hom.congr_fun (equiv.injective _ h) pb.gen,\n      rw [power_basis.lift_gen] at h,\n      rw [\u2190 h] at h\u03c3,\n      exact hnodup.not_mem_erase h\u03c3 },\n    all_goals { simp } }\nend\n\nsection integral\n\nvariables {R : Type z} [comm_ring R] [algebra R K] [algebra R L] [is_scalar_tower R K L]\n\n/-- If `K` and `L` are fields and `is_scalar_tower R K L`, and `b : \u03b9 \u2192 L` satisfies\n` \u2200 i, is_integral R (b i)`, then `is_integral R (discr K b)`. -/\nlemma discr_is_integral {b : \u03b9 \u2192 L} (h : \u2200 i, is_integral R (b i)) :\n  is_integral R (discr K b) :=\nbegin\n  classical,\n  rw [discr_def],\n  exact is_integral.det (\u03bb i j, is_integral_trace (is_integral_mul (h i) (h j)))\nend\n\n/-- If `b` and `b'` are `\u211a`-bases of a number field `K` such that\n`\u2200 i j, is_integral \u2124 (b.to_matrix b' i j)` and `\u2200 i j, is_integral \u2124 (b'.to_matrix b i j)` then\n`discr \u211a b = discr \u211a b'`. -/\nlemma discr_eq_discr_of_to_matrix_coeff_is_integral [number_field K] {b : basis \u03b9 \u211a K}\n  {b' : basis \u03b9' \u211a K} (h : \u2200 i j, is_integral \u2124 (b.to_matrix b' i j))\n  (h' : \u2200 i j, is_integral \u2124 (b'.to_matrix b i j)) :\n  discr \u211a b = discr \u211a b' :=\nbegin\n  replace h' : \u2200 i j, is_integral \u2124 (b'.to_matrix ((b.reindex (b.index_equiv b'))) i j),\n  { intros i j,\n    convert h' i ((b.index_equiv b').symm j),\n    simpa },\n  classical,\n  rw [\u2190 (b.reindex (b.index_equiv b')).to_matrix_map_vec_mul b', discr_of_matrix_vec_mul,\n    \u2190 one_mul (discr \u211a b), basis.coe_reindex, discr_reindex],\n  congr,\n  have hint : is_integral \u2124 (((b.reindex (b.index_equiv b')).to_matrix b').det) :=\n    is_integral.det (\u03bb i j, h _ _),\n  obtain \u27e8r, hr\u27e9 := is_integrally_closed.is_integral_iff.1 hint,\n  have hunit : is_unit r,\n  { have : is_integral \u2124 ((b'.to_matrix (b.reindex (b.index_equiv b'))).det) :=\n      is_integral.det (\u03bb i j, h' _ _),\n    obtain \u27e8r', hr'\u27e9 := is_integrally_closed.is_integral_iff.1 this,\n    refine is_unit_iff_exists_inv.2 \u27e8r', _\u27e9,\n    suffices : algebra_map \u2124 \u211a (r * r') = 1,\n    { rw [\u2190 ring_hom.map_one (algebra_map \u2124 \u211a)] at this,\n      exact (is_fraction_ring.injective \u2124 \u211a) this },\n    rw [ring_hom.map_mul, hr, hr', \u2190 det_mul, basis.to_matrix_mul_to_matrix_flip, det_one] },\n  rw [\u2190 ring_hom.map_one (algebra_map \u2124 \u211a), \u2190 hr],\n  cases int.is_unit_iff.1 hunit with hp hm,\n  { simp [hp] },\n  { simp [hm] }\nend\n\n/-- Let `K` be the fraction field of an integrally closed domain `R` and let `L` be a finite\nseparable extension of `K`. Let `B : power_basis K L` be such that `is_integral R B.gen`.\nThen for all, `z : L` that are integral over `R`, we have\n`(discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L)`. -/\nlemma discr_mul_is_integral_mem_adjoin [is_domain R] [is_separable K L] [is_integrally_closed R]\n  [is_fraction_ring R K] {B : power_basis K L} (hint : is_integral R B.gen) {z : L}\n  (hz : is_integral R z) : (discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L) :=\nbegin\n  have hinv : is_unit (trace_matrix K B.basis).det :=\n    by simpa [\u2190 discr_def] using discr_is_unit_of_basis _ B.basis,\n\n  have H : (trace_matrix K B.basis).det \u2022 (trace_matrix K B.basis).mul_vec (B.basis.equiv_fun z) =\n    (trace_matrix K B.basis).det \u2022 (\u03bb i, trace K L (z * B.basis i)),\n  { congr, exact trace_matrix_of_basis_mul_vec _ _ },\n  have cramer := mul_vec_cramer (trace_matrix K B.basis) (\u03bb i, trace K L (z * B.basis i)),\n\n  suffices : \u2200 i, ((trace_matrix K B.basis).det \u2022 (B.basis.equiv_fun z)) i \u2208 (\u22a5 : subalgebra R K),\n  { rw [\u2190 B.basis.sum_repr z, finset.smul_sum],\n    refine subalgebra.sum_mem _ (\u03bb i hi, _),\n    replace this := this i,\n    rw [\u2190 discr_def, pi.smul_apply, mem_bot] at this,\n    obtain \u27e8r, hr\u27e9 := this,\n    rw [basis.equiv_fun_apply] at hr,\n    rw [\u2190 smul_assoc, \u2190 hr, algebra_map_smul],\n    refine subalgebra.smul_mem _ _ _,\n    rw [B.basis_eq_pow i],\n    refine subalgebra.pow_mem _ (subset_adjoin (set.mem_singleton _)) _},\n  intro i,\n  rw [\u2190 H, \u2190 mul_vec_smul] at cramer,\n  replace cramer := congr_arg (mul_vec (trace_matrix K B.basis)\u207b\u00b9) cramer,\n  rw [mul_vec_mul_vec, nonsing_inv_mul _ hinv, mul_vec_mul_vec, nonsing_inv_mul _ hinv,\n    one_mul_vec, one_mul_vec] at cramer,\n  rw [\u2190 congr_fun cramer i, cramer_apply, det_apply],\n  refine subalgebra.sum_mem _ (\u03bb \u03c3 _, subalgebra.zsmul_mem _ (subalgebra.prod_mem _ (\u03bb j _, _)) _),\n  by_cases hji : j = i,\n  { simp only [update_column_apply, hji, eq_self_iff_true, power_basis.coe_basis],\n    exact mem_bot.2 (is_integrally_closed.is_integral_iff.1 $ is_integral_trace $\n      is_integral_mul hz $ is_integral.pow hint _) },\n  { simp only [update_column_apply, hji, power_basis.coe_basis],\n    exact mem_bot.2 (is_integrally_closed.is_integral_iff.1 $ is_integral_trace\n      $ is_integral_mul (is_integral.pow hint _) (is_integral.pow hint _)) }\nend\n\nend integral\n\nend field\n\nend discr\n\nend algebra\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/discriminant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7078431831206933}}
{"text": "import data.zmod.basic data.nat.prime \n  data.zmod.quadratic_reciprocity\n  tactic.find tactic.omega data.vector\n  list_lemma\n\nnamespace ElGamal \n/- \nA Schnorr group is a large prime-order subgroup of \u2124\u2217\ud835\udc5d, \nthe multiplicative group of integers modulo \ud835\udc5d. \nTo generate such a group, we find \ud835\udc5d=\ud835\udc5e\ud835\udc5f+1 such that \ud835\udc5d and \ud835\udc5e\nare prime. Then, we choose any \u210e\nin the range 1<\u210e<\ud835\udc5d such that \u210e^r \u2260 1 (mod\ud835\udc5d)\nThe value \ud835\udc54=\u210e^\ud835\udc5f(mod\ud835\udc5d) is a generator of a subgroup \u2124\u2217\ud835\udc5d of order \ud835\udc5e.\nBy Fermat's little theorem\ng^q = h^(rq) = h^(p-1) = 1 (mod p)\n-/\n\nvariables\n  (p : \u2115) (q : \u2115) (r : \u2115)\n  (Hr : 2 \u2264 r)\n  (Hp : nat.prime p)\n  (Hq : nat.prime q)\n  (Hdiv : p = q * r + 1)\n  (h : zmodp p Hp) \n  (Hh\u2081 : h \u2260 0)\n  (Hh\u2082 : h^r \u2260 1)\n  (g : zmodp p Hp) /- generator of a subgroup of \u2124\u22c6p of order q -/\n  (Hg : g = h^r)\n  \nsection \ninclude Hg Hdiv Hh\u2081 \ntheorem generator_proof : g ^ q = 1 := \nbegin \n  rw [Hg, <- pow_mul, mul_comm],\n  have Ht : p - 1 = q * r := nat.pred_eq_of_eq_succ Hdiv,\n  rw <- Ht, exact zmodp.fermat_little Hp Hh\u2081\nend\nend\n\n\nvariables \n  (prikey : zmodp q Hq) /- private key -/\n  (pubkey : zmodp p Hp) /- public key -/\n  (Hrel : pubkey = g^prikey.val)\n\n\ndef elgamal_enc (m : zmodp p Hp) (r : zmodp q Hq) := \n  (g^r.val, g^m.val * pubkey^r.val)\n\ndef elgamal_dec (c : zmodp p Hp \u00d7  zmodp p Hp) := \n  c.2 * (c.1^prikey.val)\u207b\u00b9 \n\ndef elgamal_reenc (c : zmodp p Hp \u00d7  zmodp p Hp) \n  (r : zmodp q Hq) :=  \n  (c.1 * g^r.val, c.2 * pubkey^r.val)\n\ndef ciphertext_mult (c : zmodp p Hp \u00d7 zmodp p Hp)\n     (d : zmodp p Hp \u00d7  zmodp p Hp) := \n     (c.1 * d.1, c.2 * d.2)\n\n\ndef vector_elegamal_enc {n : \u2115} :  \n  vector (zmodp p Hp) n -> vector (zmodp q Hq) n -> \n  vector (zmodp p Hp \u00d7 zmodp p Hp) n  \n  | \u27e8ms, Hm\u27e9  \u27e8rs, Hr\u27e9 := \n    \u27e8list.zip_with (elgamal_enc p q Hp Hq g pubkey) ms rs, \n    begin\n      have Ht : list.length ms = list.length rs :=  \n      begin rw [Hm, Hr] end,\n      rw <- Hm, apply zip_with_len_l, exact Ht\n    end \u27e9\n\ndef vector_elegamal_dec {n : \u2115} :  \n  vector (zmodp p Hp \u00d7 zmodp p Hp) n -> \n  vector (zmodp p Hp) n  \n  | \u27e8cs, Hc\u27e9  := \n    \u27e8list.map (elgamal_dec p q Hp Hq prikey) cs, \n    begin \n      rw <- Hc, apply map_with_len_l, \n    end \u27e9\n\ndef vector_elegamal_reenc {n : \u2115} :  \n  vector (zmodp p Hp \u00d7 zmodp p Hp) n -> vector (zmodp q Hq) n -> \n  vector (zmodp p Hp \u00d7 zmodp p Hp) n  \n  | \u27e8cs, Hc\u27e9  \u27e8rs, Hr\u27e9 := \n    \u27e8list.zip_with (elgamal_reenc p q Hp Hq g pubkey) cs rs, \n    begin \n      have Ht : list.length cs = list.length rs :=  \n      begin rw [Hc, Hr] end,\n      rw <- Hc, apply zip_with_len_l, exact Ht\n    end \u27e9\n\n\ndef vector_ciphertext_mult {n : \u2115} :  \n  vector (zmodp p Hp \u00d7 zmodp p Hp) n -> vector (zmodp p Hp \u00d7 zmodp p Hp) n -> \n  vector (zmodp p Hp \u00d7 zmodp p Hp) n  \n  | \u27e8cs\u2081 , Hc\u2081\u27e9  \u27e8cs\u2082, Hc\u2082\u27e9 := \n    \u27e8list.zip_with (ciphertext_mult p Hp) cs\u2081  cs\u2082, \n    begin \n      have Ht : list.length cs\u2081 = list.length cs\u2082 :=  \n      begin rw [Hc\u2081, Hc\u2082] end,\n      rw <- Hc\u2081, apply zip_with_len_l, exact Ht,\n    end \u27e9\n  \n#print vector_ciphertext_mult._main \n\n/-\ninductive count \n\n1. a ballot encrypted with [g^0, g^0, ....]\n2. a ballot is valid add it to the running margin\n3. invalid, discard it and permute it by \n    a secret permutation \n4. when no more ballot left, then honest decryption\n\nZero-Knowledge-Proof framework\n\nWikstrom Shuffle proof\nExtend it to the Coq as well, plug these \nproofs in Coq. \n\n-/\n      \n\ninclude Hrel Hg Hh\u2081 \ntheorem elgama_enc_dec_identity :  \n\u2200 m r', elgamal_dec p q Hp Hq prikey \n       (elgamal_enc p q Hp Hq g pubkey m r') = g^m.val := \nbegin\n  unfold elgamal_enc elgamal_dec,\n  intros, simp, rw [Hrel, <- pow_mul, <- pow_mul],\n  have Ht : g \u2260 0 := begin \n  rw Hg, exact pow_ne_zero r Hh\u2081 end,\n  have Ht\u2081 : g ^ (prikey.val * r'.val) \u2260 0 := \n    pow_ne_zero _ Ht,\n  have Ht\u2082 : r'.val * prikey.val = prikey.val * r'.val := \n       mul_comm r'.val prikey.val,\n  rw [Ht\u2082, mul_assoc, mul_inv_cancel Ht\u2081], ring  \nend\n\n\ntheorem additive_homomorphic_property : forall c d m\u2081 m\u2082 r\u2081 r\u2082,\n c = elgamal_enc p q Hp Hq g pubkey m\u2081 r\u2081 ->\n d = elgamal_enc p q Hp Hq g pubkey m\u2082 r\u2082 -> \n (g^(r\u2081.val + r\u2082.val), g^(m\u2081.val + m\u2082.val) * \n pubkey^(r\u2081.val + r\u2082.val)) = ciphertext_mult p Hp c d := \nbegin \n  unfold elgamal_enc ciphertext_mult, \n  intros c d m\u2081 m\u2082 r\u2081 r\u2082 Hc Hd, simp,\n  have Ht\u2081 : g ^ (r\u2081.val + r\u2082.val) = c.fst * d.fst := \n  begin \n    rw [Hc, Hd], simp, exact pow_add g r\u2081.val r\u2082.val\n  end,\n  have Ht\u2082 : g ^ (m\u2081.val + m\u2082.val) * pubkey ^ (r\u2081.val + r\u2082.val) = \n      c.snd * d.snd :=  begin\n        rw [Hc, Hd, pow_add, \n        pow_add], simp, ring\n        end,\n  exact and.intro Ht\u2081 Ht\u2082\nend\n\n\n\n\n\n\nend ElGamal\n\n#check ElGamal.elgamal_enc ", "meta": {"author": "mukeshtiwari", "repo": "formal-fptp", "sha": "883a6a245cfdce7af0fc3cc2c3769281fe60afa0", "save_path": "github-repos/lean/mukeshtiwari-formal-fptp", "path": "github-repos/lean/mukeshtiwari-formal-fptp/formal-fptp-883a6a245cfdce7af0fc3cc2c3769281fe60afa0/Leancode/fptp/src/ElGamal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.707843182432701}}
{"text": "-- Notes 10/3/2019\n\n-- example of a polymorphic function: identity function\ndef identity {\u03b1 : Type} : \u03b1 \u2192 \u03b1 \n| x := x\n\n-- explicit type arguments are denoted by ()\n-- implicit type arguments are denoted by {}\n\ndef id' (\u03b1 : Type) (a : \u03b1) : \u03b1 := a\n\n#eval id' nat 3\n#check (id' nat) -- we can partially evaluate id', making a monomorphic version of this function\n\ndef not_predicate {\u03b1 : Type} : (\u03b1 \u2192 bool) \u2192 (\u03b1 \u2192 bool)\n| f := \u03bb x, \u00ac(f x)\n\ndef is_even : nat \u2192 bool\n| 0 := tt\n| 1 := ff\n| (n' + 2) := is_even n'\n\ndef is_odd := not_predicate is_even\n\n#eval is_even 2\n#eval is_odd 1\n\n\n-- Back to our boxed example\n\ninductive boxed ( \u03b1 : Type )\n| box : \u03b1 \u2192 boxed\n\ndef unbox {\u03b1 : Type} : (boxed \u03b1) \u2192 \u03b1\n| (boxed.box x) := x\n\n#eval unbox (boxed.box 3)\n#eval unbox (boxed.box \"hello\")\n#reduce unbox (boxed.box (boxed.box (boxed.box 3)))\n\n/-\nA polymorphic ordered pair example (cartesian product)\n-/\n\ninductive mprod (\u03b1 \u03b2 : Type)\n| pair : \u03b1 \u2192 \u03b2 \u2192 mprod\n\n-- return the first element of our pair\ndef first {\u03b1 \u03b2 : Type} : (mprod \u03b1 \u03b2) \u2192 \u03b1 \n| (mprod.pair x _) := x\n\n-- return the second element of our pair\ndef second {\u03b1 \u03b2 : Type} : (mprod \u03b1 \u03b2) \u2192 \u03b2 \n| (mprod.pair _ y) := y\n\ndef ex := mprod.pair 2 3\n#check ex\n\n#eval first ex\n\ndef p1 : (mprod string nat) := (mprod.pair \"cat\" 1)\n\n#eval second p1\n\n-- Challenge time!\n\ndef swap {\u03b1 \u03b2 : Type} : (mprod \u03b1 \u03b2) \u2192 (mprod \u03b2 \u03b1)\n| (mprod.pair x y) := (mprod.pair y x)\n\n#reduce swap ex", "meta": {"author": "joek13", "repo": "cs2102-notes", "sha": "25bb18788641b20af9cf3c429afe1da9b2f5eafb", "save_path": "github-repos/lean/joek13-cs2102-notes", "path": "github-repos/lean/joek13-cs2102-notes/cs2102-notes-25bb18788641b20af9cf3c429afe1da9b2f5eafb/10-3-2019.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7078431715775141}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport order.complete_boolean_algebra\nimport order.modular_lattice\nimport data.fintype.basic\n\n/-!\n# Atoms, Coatoms, and Simple Lattices\n\nThis module defines atoms, which are minimal non-`\u22a5` elements in bounded lattices, simple lattices,\nwhich are lattices with only two elements, and related ideas.\n\n## Main definitions\n\n### Atoms and Coatoms\n  * `is_atom a` indicates that the only element below `a` is `\u22a5`.\n  * `is_coatom a` indicates that the only element above `a` is `\u22a4`.\n\n### Atomic and Atomistic Lattices\n  * `is_atomic` indicates that every element other than `\u22a5` is above an atom.\n  * `is_coatomic` indicates that every element other than `\u22a4` is below a coatom.\n  * `is_atomistic` indicates that every element is the `Sup` of a set of atoms.\n  * `is_coatomistic` indicates that every element is the `Inf` of a set of coatoms.\n\n### Simple Lattices\n  * `is_simple_lattice` indicates that a bounded lattice has only two elements, `\u22a5` and `\u22a4`.\n  * `is_simple_lattice.bounded_distrib_lattice`\n  * Given an instance of `is_simple_lattice`, we provide the following definitions. These are not\n    made global instances as they contain data :\n    * `is_simple_lattice.boolean_algebra`\n    * `is_simple_lattice.complete_lattice`\n    * `is_simple_lattice.complete_boolean_algebra`\n\n## Main results\n  * `is_atom_dual_iff_is_coatom` and `is_coatom_dual_iff_is_atom` express the (definitional) duality\n   of `is_atom` and `is_coatom`.\n  * `is_simple_lattice_iff_is_atom_top` and `is_simple_lattice_iff_is_coatom_bot` express the\n  connection between atoms, coatoms, and simple lattices\n  * `is_compl.is_atom_iff_is_coatom` and `is_compl.is_coatom_if_is_atom`: In a modular\n  bounded lattice, a complement of an atom is a coatom and vice versa.\n  * ``is_atomic_iff_is_coatomic`: A modular complemented lattice is atomic iff it is coatomic.\n\n-/\n\nvariable {\u03b1 : Type*}\n\nsection atoms\n\nsection is_atom\n\nvariable [order_bot \u03b1]\n\n/-- An atom of an `order_bot` is an element with no other element between it and `\u22a5`,\n  which is not `\u22a5`. -/\ndef is_atom (a : \u03b1) : Prop := a \u2260 \u22a5 \u2227 (\u2200 b, b < a \u2192 b = \u22a5)\n\nlemma eq_bot_or_eq_of_le_atom {a b : \u03b1} (ha : is_atom a) (hab : b \u2264 a) : b = \u22a5 \u2228 b = a :=\nhab.lt_or_eq.imp_left (ha.2 b)\n\nlemma is_atom.Iic {x a : \u03b1} (ha : is_atom a) (hax : a \u2264 x) : is_atom (\u27e8a, hax\u27e9 : set.Iic x) :=\n\u27e8\u03bb con, ha.1 (subtype.mk_eq_mk.1 con), \u03bb \u27e8b, hb\u27e9 hba, subtype.mk_eq_mk.2 (ha.2 b hba)\u27e9\n\nlemma is_atom.of_is_atom_coe_Iic {x : \u03b1} {a : set.Iic x} (ha : is_atom a) : is_atom (a : \u03b1) :=\n\u27e8\u03bb con, ha.1 (subtype.ext con), \u03bb b hba, subtype.mk_eq_mk.1 (ha.2 \u27e8b, hba.le.trans a.prop\u27e9 hba)\u27e9\n\nend is_atom\n\nsection is_coatom\n\nvariable [order_top \u03b1]\n\n/-- A coatom of an `order_top` is an element with no other element between it and `\u22a4`,\n  which is not `\u22a4`. -/\ndef is_coatom (a : \u03b1) : Prop := a \u2260 \u22a4 \u2227 (\u2200 b, a < b \u2192 b = \u22a4)\n\nlemma eq_top_or_eq_of_coatom_le {a b : \u03b1} (ha : is_coatom a) (hab : a \u2264 b) : b = \u22a4 \u2228 b = a :=\nhab.lt_or_eq.imp (ha.2 b) eq_comm.2\n\nlemma is_coatom.Ici {x a : \u03b1} (ha : is_coatom a) (hax : x \u2264 a) : is_coatom (\u27e8a, hax\u27e9 : set.Ici x) :=\n\u27e8\u03bb con, ha.1 (subtype.mk_eq_mk.1 con), \u03bb \u27e8b, hb\u27e9 hba, subtype.mk_eq_mk.2 (ha.2 b hba)\u27e9\n\nlemma is_coatom.of_is_coatom_coe_Ici {x : \u03b1} {a : set.Ici x} (ha : is_coatom a) :\n  is_coatom (a : \u03b1) :=\n\u27e8\u03bb con, ha.1 (subtype.ext con), \u03bb b hba, subtype.mk_eq_mk.1 (ha.2 \u27e8b, le_trans a.prop hba.le\u27e9 hba)\u27e9\n\nend is_coatom\n\nsection pairwise\n\nlemma is_atom.inf_eq_bot_of_ne [semilattice_inf_bot \u03b1] {a b : \u03b1}\n  (ha : is_atom a) (hb : is_atom b) (hab : a \u2260 b) : a \u2293 b = \u22a5 :=\nor.elim (eq_bot_or_eq_of_le_atom ha inf_le_left) id\n  (\u03bb h1, or.elim (eq_bot_or_eq_of_le_atom hb inf_le_right) id\n  (\u03bb h2, false.rec _ (hab (le_antisymm (inf_eq_left.mp h1) (inf_eq_right.mp h2)))))\n\nlemma is_atom.disjoint_of_ne [semilattice_inf_bot \u03b1] {a b : \u03b1}\n  (ha : is_atom a) (hb : is_atom b) (hab : a \u2260 b) : disjoint a b :=\ndisjoint_iff.mpr (is_atom.inf_eq_bot_of_ne ha hb hab)\n\nlemma is_coatom.sup_eq_top_of_ne [semilattice_sup_top \u03b1] {a b : \u03b1}\n  (ha : is_coatom a) (hb : is_coatom b) (hab : a \u2260 b) : a \u2294 b = \u22a4 :=\nor.elim (eq_top_or_eq_of_coatom_le ha le_sup_left) id\n  (\u03bb h1, or.elim (eq_top_or_eq_of_coatom_le hb le_sup_right) id\n  (\u03bb h2, false.rec _ (hab (le_antisymm (sup_eq_right.mp h2) (sup_eq_left.mp h1)))))\n\nend pairwise\n\nvariables [bounded_lattice \u03b1] {a : \u03b1}\n\n@[simp]\nlemma is_coatom_dual_iff_is_atom : is_coatom (order_dual.to_dual a) \u2194 is_atom a := iff.refl _\n\n@[simp]\nlemma is_atom_dual_iff_is_coatom : is_atom (order_dual.to_dual a) \u2194 is_coatom a := iff.refl _\n\nend atoms\n\nsection atomic\n\nvariables (\u03b1) [bounded_lattice \u03b1]\n\n/-- A lattice is atomic iff every element other than `\u22a5` has an atom below it. -/\nclass is_atomic : Prop :=\n(eq_bot_or_exists_atom_le : \u2200 (b : \u03b1), b = \u22a5 \u2228 \u2203 (a : \u03b1), is_atom a \u2227 a \u2264 b)\n\n/-- A lattice is coatomic iff every element other than `\u22a4` has a coatom above it. -/\nclass is_coatomic : Prop :=\n(eq_top_or_exists_le_coatom : \u2200 (b : \u03b1), b = \u22a4 \u2228 \u2203 (a : \u03b1), is_coatom a \u2227 b \u2264 a)\n\nexport is_atomic (eq_bot_or_exists_atom_le) is_coatomic (eq_top_or_exists_le_coatom)\n\nvariable {\u03b1}\n\n@[simp] theorem is_coatomic_dual_iff_is_atomic : is_coatomic (order_dual \u03b1) \u2194 is_atomic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_top_or_exists_le_coatom\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_bot_or_exists_atom_le\u27e9\u27e9\n\n@[simp] theorem is_atomic_dual_iff_is_coatomic : is_atomic (order_dual \u03b1) \u2194 is_coatomic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_bot_or_exists_atom_le\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_top_or_exists_le_coatom\u27e9\u27e9\n\nnamespace is_atomic\n\ninstance is_coatomic_dual [h : is_atomic \u03b1] : is_coatomic (order_dual \u03b1) :=\nis_coatomic_dual_iff_is_atomic.2 h\n\nvariables [is_atomic \u03b1]\n\ninstance {x : \u03b1} : is_atomic (set.Iic x) :=\n\u27e8\u03bb \u27e8y, hy\u27e9, (eq_bot_or_exists_atom_le y).imp subtype.mk_eq_mk.2\n  (\u03bb \u27e8a, ha, hay\u27e9, \u27e8\u27e8a, hay.trans hy\u27e9, ha.Iic (hay.trans hy), hay\u27e9)\u27e9\n\nend is_atomic\n\nnamespace is_coatomic\ninstance is_coatomic [h : is_coatomic \u03b1] : is_atomic (order_dual \u03b1) :=\nis_atomic_dual_iff_is_coatomic.2 h\n\nvariables [is_coatomic \u03b1]\n\ninstance {x : \u03b1} : is_coatomic (set.Ici x) :=\n\u27e8\u03bb \u27e8y, hy\u27e9, (eq_top_or_exists_le_coatom y).imp subtype.mk_eq_mk.2\n  (\u03bb \u27e8a, ha, hay\u27e9, \u27e8\u27e8a, le_trans hy hay\u27e9, ha.Ici (le_trans hy hay), hay\u27e9)\u27e9\n\nend is_coatomic\n\ntheorem is_atomic_iff_forall_is_atomic_Iic :\n  is_atomic \u03b1 \u2194 \u2200 (x : \u03b1), is_atomic (set.Iic x) :=\n\u27e8@is_atomic.set.Iic.is_atomic _ _, \u03bb h, \u27e8\u03bb x, ((@eq_bot_or_exists_atom_le _ _ (h x))\n  (\u22a4 : set.Iic x)).imp subtype.mk_eq_mk.1 (exists_imp_exists' coe\n  (\u03bb \u27e8a, ha\u27e9, and.imp_left (is_atom.of_is_atom_coe_Iic)))\u27e9\u27e9\n\ntheorem is_coatomic_iff_forall_is_coatomic_Ici :\n  is_coatomic \u03b1 \u2194 \u2200 (x : \u03b1), is_coatomic (set.Ici x) :=\nis_atomic_dual_iff_is_coatomic.symm.trans $ is_atomic_iff_forall_is_atomic_Iic.trans $ forall_congr\n  (\u03bb x, is_coatomic_dual_iff_is_atomic.symm.trans iff.rfl)\n\nend atomic\n\nsection atomistic\n\nvariables (\u03b1) [complete_lattice \u03b1]\n\n/-- A lattice is atomistic iff every element is a `Sup` of a set of atoms. -/\nclass is_atomistic : Prop :=\n(eq_Sup_atoms : \u2200 (b : \u03b1), \u2203 (s : set \u03b1), b = Sup s \u2227 \u2200 a, a \u2208 s \u2192 is_atom a)\n\n/-- A lattice is coatomistic iff every element is an `Inf` of a set of coatoms. -/\nclass is_coatomistic: Prop :=\n(eq_Inf_coatoms : \u2200 (b : \u03b1), \u2203 (s : set \u03b1), b = Inf s \u2227 \u2200 a, a \u2208 s \u2192 is_coatom a)\n\nexport is_atomistic (eq_Sup_atoms) is_coatomistic (eq_Inf_coatoms)\n\nvariable {\u03b1}\n\n@[simp]\ntheorem is_coatomistic_dual_iff_is_atomistic : is_coatomistic (order_dual \u03b1) \u2194 is_atomistic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_Inf_coatoms\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_Sup_atoms\u27e9\u27e9\n\n@[simp]\ntheorem is_atomistic_dual_iff_is_coatomistic : is_atomistic (order_dual \u03b1) \u2194 is_coatomistic \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb b, by apply h.eq_Sup_atoms\u27e9, \u03bb h, \u27e8\u03bb b, by apply h.eq_Inf_coatoms\u27e9\u27e9\n\nnamespace is_atomistic\n\ninstance is_coatomistic_dual [h : is_atomistic \u03b1] : is_coatomistic (order_dual \u03b1) :=\nis_coatomistic_dual_iff_is_atomistic.2 h\n\nvariable [is_atomistic \u03b1]\n\n@[priority 100]\ninstance : is_atomic \u03b1 :=\n\u27e8\u03bb b, by { rcases eq_Sup_atoms b with \u27e8s, rfl, hs\u27e9,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ \u27e8h.some, hs _ h.some_spec, le_Sup h.some_spec\u27e9 } } \u27e9\n\nend is_atomistic\n\nsection is_atomistic\nvariables [is_atomistic \u03b1]\n\n@[simp]\ntheorem Sup_atoms_le_eq (b : \u03b1) : Sup {a : \u03b1 | is_atom a \u2227 a \u2264 b} = b :=\nbegin\n  rcases eq_Sup_atoms b with \u27e8s, rfl, hs\u27e9,\n  exact le_antisymm (Sup_le (\u03bb _, and.right)) (Sup_le_Sup (\u03bb a ha, \u27e8hs a ha, le_Sup ha\u27e9)),\nend\n\n@[simp]\ntheorem Sup_atoms_eq_top : Sup {a : \u03b1 | is_atom a} = \u22a4 :=\nbegin\n  refine eq.trans (congr rfl (set.ext (\u03bb x, _))) (Sup_atoms_le_eq \u22a4),\n  exact (and_iff_left le_top).symm,\nend\n\ntheorem le_iff_atom_le_imp {a b : \u03b1} :\n  a \u2264 b \u2194 \u2200 c : \u03b1, is_atom c \u2192 c \u2264 a \u2192 c \u2264 b :=\n\u27e8\u03bb ab c hc ca, le_trans ca ab, \u03bb h, begin\n  rw [\u2190 Sup_atoms_le_eq a, \u2190 Sup_atoms_le_eq b],\n  exact Sup_le_Sup (\u03bb c hc, \u27e8hc.1, h c hc.1 hc.2\u27e9),\nend\u27e9\n\nend is_atomistic\n\nnamespace is_coatomistic\n\ninstance is_atomistic_dual [h : is_coatomistic \u03b1] : is_atomistic (order_dual \u03b1) :=\nis_atomistic_dual_iff_is_coatomistic.2 h\n\nvariable [is_coatomistic \u03b1]\n\n@[priority 100]\ninstance : is_coatomic \u03b1 :=\n\u27e8\u03bb b, by { rcases eq_Inf_coatoms b with \u27e8s, rfl, hs\u27e9,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ \u27e8h.some, hs _ h.some_spec, Inf_le h.some_spec\u27e9 } } \u27e9\n\nend is_coatomistic\nend atomistic\n\n/-- A lattice is simple iff it has only two elements, `\u22a5` and `\u22a4`. -/\nclass is_simple_lattice (\u03b1 : Type*) [bounded_lattice \u03b1] extends nontrivial \u03b1 : Prop :=\n(eq_bot_or_eq_top : \u2200 (a : \u03b1), a = \u22a5 \u2228 a = \u22a4)\n\nexport is_simple_lattice (eq_bot_or_eq_top)\n\ntheorem is_simple_lattice_iff_is_simple_lattice_order_dual [bounded_lattice \u03b1] :\n  is_simple_lattice \u03b1 \u2194 is_simple_lattice (order_dual \u03b1) :=\nbegin\n  split; intro i; haveI := i,\n  { exact { exists_pair_ne := @exists_pair_ne \u03b1 _,\n      eq_bot_or_eq_top := \u03bb a, or.symm (eq_bot_or_eq_top ((order_dual.of_dual a)) : _ \u2228 _) } },\n  { exact { exists_pair_ne := @exists_pair_ne (order_dual \u03b1) _,\n      eq_bot_or_eq_top := \u03bb a, or.symm (eq_bot_or_eq_top (order_dual.to_dual a)) } }\nend\n\nsection is_simple_lattice\n\nvariables [bounded_lattice \u03b1] [is_simple_lattice \u03b1]\n\ninstance : is_simple_lattice (order_dual \u03b1) :=\nis_simple_lattice_iff_is_simple_lattice_order_dual.1 (by apply_instance)\n\n@[simp] lemma is_atom_top : is_atom (\u22a4 : \u03b1) :=\n\u27e8top_ne_bot, \u03bb a ha, or.resolve_right (eq_bot_or_eq_top a) (ne_of_lt ha)\u27e9\n\n@[simp] lemma is_coatom_bot : is_coatom (\u22a5 : \u03b1) := is_atom_dual_iff_is_coatom.1 is_atom_top\n\nend is_simple_lattice\n\nnamespace is_simple_lattice\n\nvariables [bounded_lattice \u03b1] [is_simple_lattice \u03b1]\n\n/-- A simple `bounded_lattice` is also distributive. -/\n@[priority 100]\ninstance : bounded_distrib_lattice \u03b1 :=\n{ le_sup_inf := \u03bb x y z, by { rcases eq_bot_or_eq_top x with rfl | rfl; simp },\n  .. (infer_instance : bounded_lattice \u03b1) }\n\n@[priority 100]\ninstance : is_atomic \u03b1 :=\n\u27e8\u03bb b, (eq_bot_or_eq_top b).imp_right (\u03bb h, \u27e8\u22a4, \u27e8is_atom_top, ge_of_eq h\u27e9\u27e9)\u27e9\n\n@[priority 100]\ninstance : is_coatomic \u03b1 := is_atomic_dual_iff_is_coatomic.1 is_simple_lattice.is_atomic\n\nsection decidable_eq\nvariable [decidable_eq \u03b1]\n\n/-- Every simple lattice is order-isomorphic to `bool`. -/\ndef order_iso_bool : \u03b1 \u2243o bool :=\n{ to_fun := \u03bb x, x = \u22a4,\n  inv_fun := \u03bb x, cond x \u22a4 \u22a5,\n  left_inv := \u03bb x, by { rcases (eq_bot_or_eq_top x) with rfl | rfl; simp [bot_ne_top] },\n  right_inv := \u03bb x, by { cases x; simp [bot_ne_top] },\n  map_rel_iff' := \u03bb a b, begin\n    rcases (eq_bot_or_eq_top a) with rfl | rfl,\n    { simp [bot_ne_top] },\n    { rcases (eq_bot_or_eq_top b) with rfl | rfl,\n      { simp [bot_ne_top.symm, bot_ne_top, bool.ff_lt_tt] },\n      { simp [bot_ne_top] } }\n  end }\n\n@[priority 200]\ninstance : fintype \u03b1 := fintype.of_equiv bool (order_iso_bool.to_equiv).symm\n\n/-- A simple `bounded_lattice` is also a `boolean_algebra`. -/\nprotected def boolean_algebra : boolean_algebra \u03b1 :=\n{ compl := \u03bb x, if x = \u22a5 then \u22a4 else \u22a5,\n  sdiff := \u03bb x y, if x = \u22a4 \u2227 y = \u22a5 then \u22a4 else \u22a5,\n  sdiff_eq := \u03bb x y, by rcases eq_bot_or_eq_top x with rfl | rfl;\n      simp [bot_ne_top, has_sdiff.sdiff, compl],\n  inf_compl_le_bot := \u03bb x, by rcases eq_bot_or_eq_top x with rfl | rfl; simp,\n  top_le_sup_compl := \u03bb x, by rcases eq_bot_or_eq_top x with rfl | rfl; simp,\n  sup_inf_sdiff := \u03bb x y, by rcases eq_bot_or_eq_top x with rfl | rfl;\n      rcases eq_bot_or_eq_top y with rfl | rfl; simp [bot_ne_top],\n  inf_inf_sdiff := \u03bb x y, by rcases eq_bot_or_eq_top x with rfl | rfl;\n      rcases eq_bot_or_eq_top y with rfl | rfl; simp,\n  .. is_simple_lattice.bounded_distrib_lattice }\n\nend decidable_eq\n\nopen_locale classical\n\n/-- A simple `bounded_lattice` is also complete. -/\nprotected noncomputable def complete_lattice : complete_lattice \u03b1 :=\n{ Sup := \u03bb s, if \u22a4 \u2208 s then \u22a4 else \u22a5,\n  Inf := \u03bb s, if \u22a5 \u2208 s then \u22a5 else \u22a4,\n  le_Sup := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { exact bot_le },\n    { rw if_pos h } },\n  Sup_le := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { rw if_neg,\n      intro con,\n      exact bot_ne_top (eq_top_iff.2 (h \u22a4 con)) },\n    { exact le_top } },\n  Inf_le := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { rw if_pos h },\n    { exact le_top } },\n  le_Inf := \u03bb s x h, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { exact bot_le },\n    { rw if_neg,\n      intro con,\n      exact top_ne_bot (eq_bot_iff.2 (h \u22a5 con)) } },\n  .. (infer_instance : bounded_lattice \u03b1) }\n\n/-- A simple `bounded_lattice` is also a `complete_boolean_algebra`. -/\nprotected noncomputable def complete_boolean_algebra : complete_boolean_algebra \u03b1 :=\n{ infi_sup_le_sup_Inf := \u03bb x s, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { simp only [bot_sup_eq, \u2190 Inf_eq_infi], apply le_refl },\n    { simp only [top_sup_eq, le_top] }, },\n  inf_Sup_le_supr_inf := \u03bb x s, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { simp only [bot_inf_eq, bot_le] },\n    { simp only [top_inf_eq, \u2190 Sup_eq_supr], apply le_refl } },\n  .. is_simple_lattice.complete_lattice,\n  .. is_simple_lattice.boolean_algebra }\n\nend is_simple_lattice\n\nnamespace is_simple_lattice\nvariables [complete_lattice \u03b1] [is_simple_lattice \u03b1]\nset_option default_priority 100\n\ninstance : is_atomistic \u03b1 :=\n\u27e8\u03bb b, (eq_bot_or_eq_top b).elim\n  (\u03bb h, \u27e8\u2205, \u27e8h.trans Sup_empty.symm, \u03bb a ha, false.elim (set.not_mem_empty _ ha)\u27e9\u27e9)\n  (\u03bb h, \u27e8{\u22a4}, h.trans Sup_singleton.symm, \u03bb a ha, (set.mem_singleton_iff.1 ha).symm \u25b8 is_atom_top\u27e9)\u27e9\n\ninstance : is_coatomistic \u03b1 := is_atomistic_dual_iff_is_coatomistic.1 is_simple_lattice.is_atomistic\n\nend is_simple_lattice\nnamespace fintype\nnamespace is_simple_lattice\nvariables [bounded_lattice \u03b1] [is_simple_lattice \u03b1] [decidable_eq \u03b1]\n\nlemma univ : (finset.univ : finset \u03b1) = {\u22a4, \u22a5} :=\nbegin\n  change finset.map _ (finset.univ : finset bool) = _,\n  rw fintype.univ_bool,\n  simp only [finset.map_insert, function.embedding.coe_fn_mk, finset.map_singleton],\n  refl,\nend\n\nlemma card : fintype.card \u03b1 = 2 :=\n(fintype.of_equiv_card _).trans fintype.card_bool\n\nend is_simple_lattice\nend fintype\n\nnamespace bool\n\ninstance : is_simple_lattice bool :=\n\u27e8\u03bb a, begin\n  rw [\u2190 finset.mem_singleton, or.comm, \u2190 finset.mem_insert,\n      top_eq_tt, bot_eq_ff, \u2190 fintype.univ_bool],\n  apply finset.mem_univ,\nend\u27e9\n\nend bool\n\ntheorem is_simple_lattice_iff_is_atom_top [bounded_lattice \u03b1] :\n  is_simple_lattice \u03b1 \u2194 is_atom (\u22a4 : \u03b1) :=\n\u27e8\u03bb h, @is_atom_top _ _ h, \u03bb h, {\n  exists_pair_ne := \u27e8\u22a4, \u22a5, h.1\u27e9,\n  eq_bot_or_eq_top := \u03bb a, ((eq_or_lt_of_le (@le_top _ _ a)).imp_right (h.2 a)).symm }\u27e9\n\ntheorem is_simple_lattice_iff_is_coatom_bot [bounded_lattice \u03b1] :\n  is_simple_lattice \u03b1 \u2194 is_coatom (\u22a5 : \u03b1) :=\nis_simple_lattice_iff_is_simple_lattice_order_dual.trans is_simple_lattice_iff_is_atom_top\n\nnamespace set\n\ntheorem is_simple_lattice_Iic_iff_is_atom [bounded_lattice \u03b1] {a : \u03b1} :\n  is_simple_lattice (Iic a) \u2194 is_atom a :=\nis_simple_lattice_iff_is_atom_top.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  \u27e8\u03bb h b ab, subtype.mk_eq_mk.1 (h \u27e8b, le_of_lt ab\u27e9 ab),\n    \u03bb h \u27e8b, hab\u27e9 hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))\u27e9\n\ntheorem is_simple_lattice_Ici_iff_is_coatom [bounded_lattice \u03b1] {a : \u03b1} :\n  is_simple_lattice (Ici a) \u2194 is_coatom a :=\nis_simple_lattice_iff_is_coatom_bot.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  \u27e8\u03bb h b ab, subtype.mk_eq_mk.1 (h \u27e8b, le_of_lt ab\u27e9 ab),\n    \u03bb h \u27e8b, hab\u27e9 hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))\u27e9\n\nend set\n\nnamespace order_iso\n\nvariables [bounded_lattice \u03b1] {\u03b2 : Type*} [bounded_lattice \u03b2] (f : \u03b1 \u2243o \u03b2)\ninclude f\n\n@[simp] lemma is_atom_iff (a : \u03b1) : is_atom (f a) \u2194 is_atom a :=\nand_congr (not_congr \u27e8\u03bb h, f.injective (f.map_bot.symm \u25b8 h), \u03bb h, f.map_bot \u25b8 (congr rfl h)\u27e9)\n  \u27e8\u03bb h b hb, f.injective ((h (f b) ((f : \u03b1 \u21aao \u03b2).lt_iff_lt.2 hb)).trans f.map_bot.symm),\n  \u03bb h b hb, f.symm.injective begin\n    rw f.symm.map_bot,\n    apply h,\n    rw [\u2190 f.symm_apply_apply a],\n    exact (f.symm : \u03b2 \u21aao \u03b1).lt_iff_lt.2 hb,\n  end\u27e9\n\n@[simp] lemma is_coatom_iff (a : \u03b1) : is_coatom (f a) \u2194 is_coatom a := f.dual.is_atom_iff a\n\nlemma is_simple_lattice_iff (f : \u03b1 \u2243o \u03b2) : is_simple_lattice \u03b1 \u2194 is_simple_lattice \u03b2 :=\nby rw [is_simple_lattice_iff_is_atom_top, is_simple_lattice_iff_is_atom_top,\n  \u2190 f.is_atom_iff \u22a4, f.map_top]\n\nlemma is_simple_lattice [h : is_simple_lattice \u03b2] (f : \u03b1 \u2243o \u03b2) : is_simple_lattice \u03b1 :=\nf.is_simple_lattice_iff.mpr h\n\nlemma is_atomic_iff : is_atomic \u03b1 \u2194 is_atomic \u03b2 :=\nbegin\n  suffices : (\u2200 b : \u03b1, b = \u22a5 \u2228 \u2203 (a : \u03b1), is_atom a \u2227 a \u2264 b) \u2194\n    (\u2200 b : \u03b2, b = \u22a5 \u2228 \u2203 (a : \u03b2), is_atom a \u2227 a \u2264 b),\n  from \u27e8\u03bb \u27e8p\u27e9, \u27e8this.mp p\u27e9, \u03bb \u27e8p\u27e9, \u27e8this.mpr p\u27e9\u27e9,\n  apply f.to_equiv.forall_congr,\n  simp_rw [rel_iso.coe_fn_to_equiv],\n  intro b, apply or_congr,\n  { rw [f.apply_eq_iff_eq_symm_apply, map_bot], },\n  { split,\n    { exact \u03bb \u27e8a, ha\u27e9, \u27e8f a, \u27e8(f.is_atom_iff a).mpr ha.1, f.le_iff_le.mpr ha.2\u27e9\u27e9, },\n    { rintros \u27e8b, \u27e8hb1, hb2\u27e9\u27e9,\n      refine \u27e8f.symm b, \u27e8(f.symm.is_atom_iff b).mpr hb1, _\u27e9\u27e9,\n      rwa [\u2190f.le_iff_le, f.apply_symm_apply], }, },\nend\n\nlemma is_coatomic_iff : is_coatomic \u03b1 \u2194 is_coatomic \u03b2 :=\nby { rw [\u2190is_atomic_dual_iff_is_coatomic, \u2190is_atomic_dual_iff_is_coatomic],\n  exact f.dual.is_atomic_iff, }\n\nend order_iso\n\nsection is_modular_lattice\nvariables [bounded_lattice \u03b1] [is_modular_lattice \u03b1]\n\nnamespace is_compl\nvariables {a b : \u03b1} (hc : is_compl a b)\ninclude hc\n\nlemma is_atom_iff_is_coatom : is_atom a \u2194 is_coatom b :=\nset.is_simple_lattice_Iic_iff_is_atom.symm.trans $ hc.Iic_order_iso_Ici.is_simple_lattice_iff.trans\n  set.is_simple_lattice_Ici_iff_is_coatom\n\nlemma is_coatom_iff_is_atom : is_coatom a \u2194 is_atom b := hc.symm.is_atom_iff_is_coatom.symm\n\nend is_compl\n\nvariables [is_complemented \u03b1]\n\nlemma is_coatomic_of_is_atomic_of_is_complemented_of_is_modular [is_atomic \u03b1] : is_coatomic \u03b1 :=\n\u27e8\u03bb x, begin\n  rcases exists_is_compl x with \u27e8y, xy\u27e9,\n  apply (eq_bot_or_exists_atom_le y).imp _ _,\n  { rintro rfl,\n    exact eq_top_of_is_compl_bot xy },\n  { rintro \u27e8a, ha, ay\u27e9,\n    rcases exists_is_compl (xy.symm.Iic_order_iso_Ici \u27e8a, ay\u27e9) with \u27e8\u27e8b, xb\u27e9, hb\u27e9,\n    refine \u27e8\u2191(\u27e8b, xb\u27e9 : set.Ici x), is_coatom.of_is_coatom_coe_Ici _, xb\u27e9,\n    rw [\u2190 hb.is_atom_iff_is_coatom, order_iso.is_atom_iff],\n    apply ha.Iic }\nend\u27e9\n\nlemma is_atomic_of_is_coatomic_of_is_complemented_of_is_modular [is_coatomic \u03b1] : is_atomic \u03b1 :=\nis_coatomic_dual_iff_is_atomic.1 is_coatomic_of_is_atomic_of_is_complemented_of_is_modular\n\ntheorem is_atomic_iff_is_coatomic : is_atomic \u03b1 \u2194 is_coatomic \u03b1 :=\n\u27e8\u03bb h, @is_coatomic_of_is_atomic_of_is_complemented_of_is_modular _ _ _ _ h,\n  \u03bb h, @is_atomic_of_is_coatomic_of_is_complemented_of_is_modular _ _ _ _ h\u27e9\n\nend is_modular_lattice\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/atoms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7078431687872834}}
{"text": "/-\nCopyright (c) 2022 Stuart Presnell. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Stuart Presnell\n\n! This file was ported from Lean 3 source module data.nat.even_odd_rec\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Nat.Basic\n\n/-! # A recursion principle based on even and odd numbers. \n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.-/\n\n\nnamespace Nat\n\n#print Nat.evenOddRec /-\n/-- Recursion principle on even and odd numbers: if we have `P 0`, and for all `i : \u2115` we can\nextend from `P i` to both `P (2 * i)` and `P (2 * i + 1)`, then we have `P n` for all `n : \u2115`.\nThis is nothing more than a wrapper around `nat.binary_rec`, to avoid having to switch to\ndealing with `bit0` and `bit1`. -/\n@[elab_as_elim]\ndef evenOddRec {P : \u2115 \u2192 Sort _} (h0 : P 0) (h_even : \u2200 (n) (ih : P n), P (2 * n))\n    (h_odd : \u2200 (n) (ih : P n), P (2 * n + 1)) (n : \u2115) : P n :=\n  by\n  refine' @binary_rec P h0 (fun b i hi => _) n\n  cases b\n  \u00b7 simpa [bit, bit0_val i] using h_even i hi\n  \u00b7 simpa [bit, bit1_val i] using h_odd i hi\n#align nat.even_odd_rec Nat.evenOddRec\n-/\n\n#print Nat.evenOddRec_zero /-\n@[simp]\ntheorem evenOddRec_zero (P : \u2115 \u2192 Sort _) (h0 : P 0) (h_even : \u2200 i, P i \u2192 P (2 * i))\n    (h_odd : \u2200 i, P i \u2192 P (2 * i + 1)) : @evenOddRec _ h0 h_even h_odd 0 = h0 :=\n  binaryRec_zero _ _\n#align nat.even_odd_rec_zero Nat.evenOddRec_zero\n-/\n\n#print Nat.evenOddRec_even /-\n@[simp]\ntheorem evenOddRec_even (n : \u2115) (P : \u2115 \u2192 Sort _) (h0 : P 0) (h_even : \u2200 i, P i \u2192 P (2 * i))\n    (h_odd : \u2200 i, P i \u2192 P (2 * i + 1)) (H : h_even 0 h0 = h0) :\n    @evenOddRec _ h0 h_even h_odd (2 * n) = h_even n (evenOddRec h0 h_even h_odd n) :=\n  by\n  convert binary_rec_eq _ ff n\n  \u00b7 exact (bit0_eq_two_mul _).symm\n  \u00b7 exact (bit0_eq_two_mul _).symm\n  \u00b7 apply heq_of_cast_eq\n    rfl\n  \u00b7 exact H\n#align nat.even_odd_rec_even Nat.evenOddRec_even\n-/\n\n#print Nat.evenOddRec_odd /-\n@[simp]\ntheorem evenOddRec_odd (n : \u2115) (P : \u2115 \u2192 Sort _) (h0 : P 0) (h_even : \u2200 i, P i \u2192 P (2 * i))\n    (h_odd : \u2200 i, P i \u2192 P (2 * i + 1)) (H : h_even 0 h0 = h0) :\n    @evenOddRec _ h0 h_even h_odd (2 * n + 1) = h_odd n (evenOddRec h0 h_even h_odd n) :=\n  by\n  convert binary_rec_eq _ tt n\n  \u00b7 exact (bit0_eq_two_mul _).symm\n  \u00b7 exact (bit0_eq_two_mul _).symm\n  \u00b7 apply heq_of_cast_eq\n    rfl\n  \u00b7 exact H\n#align nat.even_odd_rec_odd Nat.evenOddRec_odd\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/EvenOddRec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7078414254789255}}
{"text": "import .lovelib\n\n\n/- # LoVe Exercise 3: Forward Proofs -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1: Connectives and Quantifiers\n\n1.1. Supply structured proofs of the following lemmas. -/\n\nlemma I (a : Prop) :\n  a \u2192 a :=\nassume ha : a,\nshow a, from\n  ha\n\nlemma K (a b : Prop) :\n  a \u2192 b \u2192 b :=\nassume ha : a,\nassume hb : b,\nshow b, from\n  hb\n\nlemma C (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 b \u2192 a \u2192 c :=\nassume hg : a \u2192 b \u2192 c,\nassume hb : b,\nassume ha : a,\nshow c, from\n  hg ha hb\n\nlemma proj_1st (a : Prop) :\n  a \u2192 a \u2192 a :=\nassume ha ha' : a,\nshow a, from\n  ha\n\n/- Please give a different answer than for `proj_1st`. -/\n\nlemma proj_2nd (a : Prop) :\n  a \u2192 a \u2192 a :=\nassume ha ha' : a,\nshow a, from\n  ha'\n\nlemma some_nonsense (a b c : Prop) :\n  (a \u2192 b \u2192 c) \u2192 a \u2192 (a \u2192 c) \u2192 b \u2192 c :=\nassume hg : a \u2192 b \u2192 c,\nassume ha : a,\nassume hf : a \u2192 c,\nassume hb : b,\nhave hc : c :=\n  hf ha,\nshow c, from\n  hc\n\n/- 1.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a \u2192 b) \u2192 \u00ac b \u2192 \u00ac a :=\nassume hab : a \u2192 b,\nassume hnb : \u00ac b,\nassume ha : a,\nhave hb : b :=\n  hab ha,\nshow false, from\n  hnb hb\n\n/- 1.3. Supply a structured proof of the distributivity of `\u2200` over `\u2227`. -/\n\nlemma forall_and {\u03b1 : Type} (p q : \u03b1 \u2192 Prop) :\n  (\u2200x, p x \u2227 q x) \u2194 (\u2200x, p x) \u2227 (\u2200x, q x) :=\niff.intro\n  (assume hpq : \u2200x, p x \u2227 q x,\n   have hp : \u2200x, p x :=\n     fix x,\n     and.elim_left (hpq x),\n   have hq : \u2200x, q x :=\n     fix x,\n     and.elim_right (hpq x),\n   show (\u2200x, p x) \u2227 (\u2200x, q x), from\n     and.intro hp hq)\n  (assume hpq : (\u2200x, p x) \u2227 (\u2200x, q x),\n   have hp : \u2200x, p x :=\n     and.elim_left hpq,\n   have hq : \u2200x, q x :=\n     and.elim_right hpq,\n   assume x : \u03b1,\n   show p x \u2227 q x, from\n     and.intro (hp x) (hq x))\n\n/- 1.4. Reuse, if possible, the lemma `forall_and` you proved above to prove\nthe following instance of the lemma. -/\n\nlemma forall_and_inst {\u03b1 : Type} (r s : \u03b1 \u2192 \u03b1 \u2192 Prop) :\n  (\u2200x, r x x \u2227 s x x) \u2194 (\u2200x, r x x) \u2227 (\u2200x, s x x) :=\nforall_and (\u03bbx, r x x) (\u03bbx, s x x)\n\n\n/- ## Question 2: Chain of Equalities\n\n2.1. Write the following proof using `calc`.\n\n      `(a + b) * (a + b)`\n    `= a * (a + b) + b * (a + b)`\n    `= a * a + a * b + b * a + b * b`\n    `= a * a + a * b + a * b + b * b`\n    `= a * a + 2 * a * b + b * b`\n\nHint: You might need the tactics `simp` and `cc` and the lemmas `mul_add`,\n`add_mul`, and `two_mul`. -/\n\nlemma binomial_square (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\ncalc  (a + b) * (a + b)\n    = a * (a + b) + b * (a + b) :\n  begin\n    simp [add_mul, mul_add],\n    cc\n  end\n... = a * a + a * b + b * a + b * b :\n  begin\n    simp [add_mul, mul_add],\n    cc\n  end\n... = a * a + a * b + a * b + b * b :\n  by cc\n... = a * a + 2 * a * b + b * b :\n  begin\n    simp [two_mul, mul_add, add_mul],\n    cc\n  end\n\n/- 2.2. Prove the same argument again, this time as a structured proof. Try to\nreuse as much of the above proof idea as possible. -/\n\nlemma binomial_square\u2082 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nhave h1 : (a + b) * (a + b) = a * (a + b) + b * (a + b) :=\n  begin\n    simp [add_mul, mul_add],\n    cc\n  end,\nhave h2 : a * (a + b) + b * (a + b) = a * a + a * b + b * a + b * b :=\n  begin\n    simp [add_mul, mul_add],\n    cc\n  end,\nhave h3 : a * a + a * b + b * a + b * b = a * a + a * b + a * b + b * b :=\n  begin\n    simp,\n    cc\n  end,\nhave h4 : a * a + a * b + a * b + b * b = a * a + 2 * a * b + b * b :=\n  begin\n    simp [two_mul, add_mul, mul_add],\n    cc\n  end,\nshow _, from\n  begin\n    rw h1,\n    rw h2,\n    rw h3,\n    rw h4\n  end\n\n/- 2.3. Prove the same lemma again, this time using tactics. -/\n\nlemma binomial_square\u2083 (a b : \u2115) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nbegin\n  simp [two_mul, add_mul, mul_add],\n  cc\nend\n\n\n/- ## Question 3 (**optional**): One-Point Rules\n\n3.1 (**optional**). Prove that the following wrong formulation of the one-point\nrule for `\u2200` is inconsistent, using a structured proof. -/\n\naxiom forall.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2200x : \u03b1, x = t \u2227 p x) \u2194 p t\n\nlemma proof_of_false :\n  false :=\nbegin\n  have wrong : (\u2200x, x = 0 \u2227 true) \u2194 true :=\n    @forall.one_point_wrong \u2115 0 (\u03bb_, true),\n  simp at wrong,\n  have one_eq_zero : 1 = 0 :=\n    wrong 1,\n  cc\nend\n\n/- 3.2 (**optional**). Prove that the following wrong formulation of the\none-point rule for `\u2203` is inconsistent, using a tactical or structured proof. -/\n\naxiom exists.one_point_wrong {\u03b1 : Type} {t : \u03b1} {p : \u03b1 \u2192 Prop} :\n  (\u2203x : \u03b1, x = t \u2192 p x) \u2194 p t\n\nlemma proof_of_false\u2082 :\n  false :=\nbegin\n  have wrong : (\u2203x, x \u2260 0) \u2194 false :=\n    @exists.one_point_wrong \u2115 0 (\u03bb_, false),\n  simp at wrong,\n  have one_eq_zero : 1 = 0 :=\n    wrong 1,\n  cc\nend\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love03_forward_proofs_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7078414116110194}}
{"text": "import logic.function\nimport data.fintype\n\ndef list.chain'' {\u03b1} (R : \u03b1 \u2192 \u03b1 \u2192 Prop) : (\u03b1 \u2192 Prop) \u2192 list \u03b1 \u2192 \u03b1 \u2192 Prop\n| P [] a := P a\n| P (a::l) b := P a \u2227 list.chain'' (R a) l b\n\ndef flip_one {\u03b1} [decidable_eq \u03b1] (f : \u03b1 \u2192 bool) (i : \u03b1) : \u03b1 \u2192 bool :=\nfunction.update f i (bnot (f i))\n\ndef admissible {\u03b1} [decidable_eq \u03b1] (f g : \u03b1 \u2192 bool) : Prop :=\n\u2203 i, g = flip_one f i\n\ndef restricted_admissible {\u03b1} [decidable_eq \u03b1] (f g : \u03b1 \u2295 \u03b1 \u2192 bool) : Prop :=\n\u2203 i, g = flip_one f (sum.inl i)\n\ndef end_state {\u03b1} : \u03b1 \u2295 \u03b1 \u2192 bool\n| (sum.inl _) := tt\n| (sum.inr _) := ff\n\ndef lamp_seq {\u03b1} (R : \u2200 (f g : \u03b1 \u2295 \u03b1 \u2192 bool), Prop) (l : list (\u03b1 \u2295 \u03b1 \u2192 bool)) : Prop :=\nlist.chain'' R (\u03bb s, end_state = s) l (\u03bb _, ff)\n\nopen_locale classical\ntheorem C4 {\u03b1} [fintype \u03b1] [decidable_eq \u03b1] (k n : \u2115)\n  (h1 : 2 \u2223 k + n) (h2 : n \u2264 k) (h3 : fintype.card \u03b1 = n) :\n  fintype.card {f : vector (\u03b1 \u2295 \u03b1 \u2192 bool) k // lamp_seq admissible f.1} =\n  2 ^ (k - n) *\n  fintype.card {f : vector (\u03b1 \u2295 \u03b1 \u2192 bool) k // lamp_seq restricted_admissible f.1} :=\nsorry\n", "meta": {"author": "mirefek", "repo": "my-lean-experiments", "sha": "1218fecbf568669ac123256d430a151a900f67b3", "save_path": "github-repos/lean/mirefek-my-lean-experiments", "path": "github-repos/lean/mirefek-my-lean-experiments/my-lean-experiments-1218fecbf568669ac123256d430a151a900f67b3/lamps_mario.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.7077536814454908}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.finset.basic\nimport Mathlib.PostPort\n\nuniverses u_1 u v \n\nnamespace Mathlib\n\n/-!\n# Languages\nThis file contains the definition and operations on formal languages over an alphabet. Note strings\nare implemented as lists over the alphabet.\nThe operations in this file define a [Kleene algebra](https://en.wikipedia.org/wiki/Kleene_algebra)\nover the languages.\n-/\n\n/-- A language is a set of strings over an alphabet. -/\ndef language (\u03b1 : Type u_1) := set (List \u03b1)\n\nnamespace language\n\n\nprotected instance has_zero {\u03b1 : Type u} : HasZero (language \u03b1) := { zero := \u2205 }\n\nprotected instance has_one {\u03b1 : Type u} : HasOne (language \u03b1) := { one := singleton [] }\n\nprotected instance inhabited {\u03b1 : Type u} : Inhabited (language \u03b1) := { default := 0 }\n\nprotected instance has_add {\u03b1 : Type u} : Add (language \u03b1) := { add := set.union }\n\nprotected instance has_mul {\u03b1 : Type u} : Mul (language \u03b1) :=\n  { mul :=\n      fun (l m : language \u03b1) =>\n        (fun (p : List \u03b1 \u00d7 List \u03b1) => prod.fst p ++ prod.snd p) '' set.prod l m }\n\ntheorem zero_def {\u03b1 : Type u} : 0 = \u2205 := rfl\n\ntheorem one_def {\u03b1 : Type u} : 1 = singleton [] := rfl\n\ntheorem add_def {\u03b1 : Type u} (l : language \u03b1) (m : language \u03b1) : l + m = l \u222a m := rfl\n\ntheorem mul_def {\u03b1 : Type u} (l : language \u03b1) (m : language \u03b1) :\n    l * m = (fun (p : List \u03b1 \u00d7 List \u03b1) => prod.fst p ++ prod.snd p) '' set.prod l m :=\n  rfl\n\n/-- The star of a language `L` is the set of all strings which can be written by concatenating\n  strings from `L`. -/\ndef star {\u03b1 : Type u} (l : language \u03b1) : language \u03b1 :=\n  set_of fun (x : List \u03b1) => \u2203 (S : List (List \u03b1)), x = list.join S \u2227 \u2200 (y : List \u03b1), y \u2208 S \u2192 y \u2208 l\n\ntheorem star_def {\u03b1 : Type u} (l : language \u03b1) :\n    star l =\n        set_of\n          fun (x : List \u03b1) =>\n            \u2203 (S : List (List \u03b1)), x = list.join S \u2227 \u2200 (y : List \u03b1), y \u2208 S \u2192 y \u2208 l :=\n  rfl\n\n@[simp] theorem mem_one {\u03b1 : Type u} (x : List \u03b1) : x \u2208 1 \u2194 x = [] := iff.refl (x \u2208 1)\n\n@[simp] theorem mem_add {\u03b1 : Type u} (l : language \u03b1) (m : language \u03b1) (x : List \u03b1) :\n    x \u2208 l + m \u2194 x \u2208 l \u2228 x \u2208 m :=\n  sorry\n\ntheorem mem_mul {\u03b1 : Type u} (l : language \u03b1) (m : language \u03b1) (x : List \u03b1) :\n    x \u2208 l * m \u2194 \u2203 (a : List \u03b1), \u2203 (b : List \u03b1), a \u2208 l \u2227 b \u2208 m \u2227 a ++ b = x :=\n  sorry\n\ntheorem mem_star {\u03b1 : Type u} (l : language \u03b1) (x : List \u03b1) :\n    x \u2208 star l \u2194 \u2203 (S : List (List \u03b1)), x = list.join S \u2227 \u2200 (y : List \u03b1), y \u2208 S \u2192 y \u2208 l :=\n  iff.refl (x \u2208 star l)\n\nprotected instance semiring {\u03b1 : Type u} : semiring (language \u03b1) :=\n  semiring.mk Add.add sorry 0 sorry sorry sorry Mul.mul mul_assoc_lang 1 one_mul_lang mul_one_lang\n    sorry sorry left_distrib_lang right_distrib_lang\n\n@[simp] theorem add_self {\u03b1 : Type u} (l : language \u03b1) : l + l = l := sup_idem\n\ntheorem star_def_nonempty {\u03b1 : Type u} (l : language \u03b1) :\n    star l =\n        set_of\n          fun (x : List \u03b1) =>\n            \u2203 (S : List (List \u03b1)), x = list.join S \u2227 \u2200 (y : List \u03b1), y \u2208 S \u2192 y \u2208 l \u2227 y \u2260 [] :=\n  sorry\n\ntheorem le_iff {\u03b1 : Type u} (l : language \u03b1) (m : language \u03b1) : l \u2264 m \u2194 l + m = m :=\n  iff.symm sup_eq_right\n\ntheorem le_mul_congr {\u03b1 : Type u} {l\u2081 : language \u03b1} {l\u2082 : language \u03b1} {m\u2081 : language \u03b1}\n    {m\u2082 : language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 * l\u2082 \u2264 m\u2081 * m\u2082 :=\n  sorry\n\ntheorem le_add_congr {\u03b1 : Type u} {l\u2081 : language \u03b1} {l\u2082 : language \u03b1} {m\u2081 : language \u03b1}\n    {m\u2082 : language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 + l\u2082 \u2264 m\u2081 + m\u2082 :=\n  sup_le_sup\n\ntheorem supr_mul {\u03b1 : Type u} {\u03b9 : Sort v} (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n    (supr fun (i : \u03b9) => l i) * m = supr fun (i : \u03b9) => l i * m :=\n  sorry\n\ntheorem mul_supr {\u03b1 : Type u} {\u03b9 : Sort v} (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n    (m * supr fun (i : \u03b9) => l i) = supr fun (i : \u03b9) => m * l i :=\n  sorry\n\ntheorem supr_add {\u03b1 : Type u} {\u03b9 : Sort v} [Nonempty \u03b9] (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n    (supr fun (i : \u03b9) => l i) + m = supr fun (i : \u03b9) => l i + m :=\n  supr_sup\n\ntheorem add_supr {\u03b1 : Type u} {\u03b9 : Sort v} [Nonempty \u03b9] (l : \u03b9 \u2192 language \u03b1) (m : language \u03b1) :\n    (m + supr fun (i : \u03b9) => l i) = supr fun (i : \u03b9) => m + l i :=\n  sup_supr\n\ntheorem star_eq_supr_pow {\u03b1 : Type u} (l : language \u03b1) : star l = supr fun (i : \u2115) => l ^ i := sorry\n\ntheorem mul_self_star_comm {\u03b1 : Type u} (l : language \u03b1) : star l * l = l * star l := sorry\n\n@[simp] theorem one_add_self_mul_star_eq_star {\u03b1 : Type u} (l : language \u03b1) :\n    1 + l * star l = star l :=\n  sorry\n\n@[simp] theorem one_add_star_mul_self_eq_star {\u03b1 : Type u} (l : language \u03b1) :\n    1 + star l * l = star l :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 + star l * l = star l)) (mul_self_star_comm l)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (1 + l * star l = star l)) (one_add_self_mul_star_eq_star l)))\n      (Eq.refl (star l)))\n\ntheorem star_mul_le_right_of_mul_le_right {\u03b1 : Type u} (l : language \u03b1) (m : language \u03b1) :\n    l * m \u2264 m \u2192 star l * m \u2264 m :=\n  sorry\n\ntheorem star_mul_le_left_of_mul_le_left {\u03b1 : Type u} (l : language \u03b1) (m : language \u03b1) :\n    m * l \u2264 m \u2192 m * star l \u2264 m :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/computability/language_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7077186560662592}}
{"text": "------------------------------------------------\n------------------------------------------------\n-- Dealing with finite, simple graphs.  From the ground up. --\n------------------------------------------------\n------------------------------------------------\nimport combinatorics.simple_graph.basic\nimport combinatorics.simple_graph.degree_sum\nimport combinatorics.simple_graph.hasse -- path graphs\nimport combinatorics.simple_graph.partition -- bipartite graphs\n.\n\nopen_locale big_operators -- enable \u2211 notation\nopen simple_graph\n\nset_option pp.implicit true\n\nuniverses u\nvariables {V : Type u}  \n          --{G : simple_graph V}  -- the graph is simple\n          --[fintype V]           -- the graph is finite (necessary for vertex set cardinality to be computed)\n          --[decidable_rel G.adj] -- whether two vertices are adjacent is decidable (necessary for vertex degree to be computed)\n          --[decidable_eq V]      -- whether two vertices are equal is decidable (necessary for edge_set cardinality to be computed)\n\n\n------------------------------------------------\n-- Setting up shorthand notations. --\n------------------------------------------------\nnotation  X `[G]` := @finset.univ X _   -- V[G]\nnotation `E[` X `]`   := X.edge_finset -- E[G]\nnotation `\u2223\u2223` X `\u2223\u2223`  := X.card         -- \u2223\u2223(V[G])\u2223\u2223 or \u2223\u2223E[G]\u2223\u2223\n\n------------------------------------------------\n-- Tag allowable graph theory theorems --\n------------------------------------------------\n@[user_attribute]\nmeta def graph_theory_attr : user_attribute :=\n{ name := `graph_theory,\n  descr := \"A tag for all allowable graph_theory theorems our machine can use.\" }\n\n------------------------------------------------\n-- The allowable theorems --\n------------------------------------------------\n\n-- In a simple graph, a vertex connects to at most (n-1) other vertices --\n@[graph_theory] \ntheorem degree_bound (G : simple_graph V) [fintype V] [decidable_rel G.adj] [decidable_eq V]: \n  \u2200 v : V, G.degree v \u2264 \u2223\u2223(V[G])\u2223\u2223 - 1 :=\nbegin\n  intros v,\n  have := simple_graph.degree_lt_card_verts G v, \n  rw finset.card_univ, apply nat.le_pred_of_lt, assumption,\nend\n\n-- The degree-sum formula: the sum of the degrees = twice the number of edges --\n@[graph_theory] \ntheorem degree_sum (G : simple_graph V) [fintype V] [decidable_rel G.adj] [decidable_eq V]: \n  \u2211v,  G.degree v = 2 * \u2223\u2223E[G]\u2223\u2223 :=\nbegin\n  apply sum_degrees_eq_twice_card_edges G,\nend\n\n-- Handshaking lemma : the sum of degrees is even --\n--@[graph_theory]  -- untagged so \"hammer\" can reason through it on its own\ntheorem degree_sum_even (G : simple_graph V) [fintype V] [decidable_rel G.adj] [decidable_eq V]: \n  even (\u2211v,  G.degree v) :=\nbegin\n  rw degree_sum, simp,\nend \n\n-- Graphs have at most (n choose 2) edges --\n--@[graph_theory]  -- untagged so \"hammer\" can reason through it on its own\ntheorem edge_bound (G : simple_graph V) [fintype V] [decidable_rel G.adj] [decidable_eq V]: \n  \u2223\u2223E[G]\u2223\u2223 \u2264 \u2223\u2223(V[G])\u2223\u2223.choose 2 :=\nbegin \n  have ds := degree_sum G, -- syntactic match to this theorem, so lets add it to hypothesis\n  have db := degree_bound G, -- syntactic match to this theorem, so lets add it to hypothesis\n  rw nat.choose_two_right, -- expand out \"choose\", since there is nothing else involving \"choose\" in hypotheses or library\n\n  -- we HAVE something to do with |E| =  something to do with degree\n  -- then we HAVE something to do with degree <= something to do with |V|\n  -- and we WANT something to do with |E| <= something to do with |V|\n  -- so the steps should be clear, abstractly, in the \"quotient graph\"\n\n  -- first isolate |E|, applying that it has something to do with degree\n  replace ds : G.edge_finset.card = (\u2211v,  G.degree v) / 2 := by {rw ds, simp},\n  rw ds, clear ds,-- rewrite the goal using that |E| \n\n -- then apply that degree can be bounded by something to do with |V|\n  replace db : \u2200 (v : V), v \u2208 (V[G]) \u2192 G.degree v \u2264 \u2223\u2223(V[G])\u2223\u2223 - 1 := by {intros v h, exact db v},\n  have h := finset.sum_le_sum db, dsimp at h, rw finset.sum_const at h, -- apply this theorem to get a closer syntactic match to the goal\n  apply nat.div_le_div_right, exact h, -- tidy to get a closer syntactic match to the goal\n\nend\n\n-- Every path is bipartite --\n-- @[graph_theory] \n-- def is_bipartite (G : simple_graph V) := G.partitionable 2\n-- theorem path_is_bipartite (n : \u2115) : \u2200n : \u2115, is_bipartite (path_graph n) :=\n-- begin \n--   intro n,\n--   rw is_bipartite,\n--   rw partitionable,\n--   -- the odd-indexed vertices go in one partition\n--   -- the even-indexed vertices go in the other\n-- end", "meta": {"author": "Human-Oriented-ATP", "repo": "lean-tactics", "sha": "8fa4c8b8efc0c6a1d408b48e999f3a36f228bd0f", "save_path": "github-repos/lean/Human-Oriented-ATP-lean-tactics", "path": "github-repos/lean/Human-Oriented-ATP-lean-tactics/lean-tactics-8fa4c8b8efc0c6a1d408b48e999f3a36f228bd0f/lean3/src/testbed/graph_theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7077186469627326}}
{"text": "/-\nCopyright (c) 2022 Alena Gusakov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alena Gusakov\n-/\nimport data.sym.sym2\nimport combinatorics.simple_graph.basic\nimport combinatorics.simple_graph.subgraph\nimport combinatorics.simple_graph.connectivity\nimport data.list\n/-!\n\n# Edge Connectivity\n\nIn a simple graph, blah blah\n\n* for edges as first-class objects, maybe we can have a nontrivial type thing on V to specify when there are at least 2 vertices?\n* I think that would make things easier.\n\n-/\n\nuniverses u v\n\nnamespace simple_graph\nvariables {V : Type u} {V' : Type v} [decidable_eq V] [fintype V] [nontrivial V]\nvariables (G : simple_graph V) (G' : simple_graph V') [decidable_rel G.adj]\n\n\n/--\nA graph G is k-edge-connected if G\u2212F is connected for every F\u2286E(G) where |F|< k.\n-/\ndef is_k_edge_connected (k : \u2115) : Prop := \u2200 (F : finset (sym2 V)), F \u2286 G.edge_finset \u2192 F.card < k \u2192 \n  connected (G.delete_edges F)\n\n/--\nA graph G that is k-edge-connected where 0 < k is connected.\n-/\nlemma k_edge_connected_is_connected (k : \u2115) (h : 0 < k) (h2 : G.is_k_edge_connected k) : G.connected :=\nbegin\n  unfold is_k_edge_connected at h2,\n  specialize h2 \u2205,\n  simp at h2,\n  specialize h2 h,\n  exact h2,\nend\n\nlemma min_deg_ne_zero_of_connected [nontrivial V] (h2 : 1 < fintype.card V) : G.connected \u2194 G.min_degree \u2260 0 :=\nbegin\n  have hv := G.exists_minimal_degree_vertex,\n  cases hv with v hv,\n  rw fintype.one_lt_card_iff at h2,\n  rcases h2 with \u27e8a, \u27e8b, hb\u27e9\u27e9,\n  \n  sorry,\nend\n\n-- exists_eq_cons_of_ne?\nlemma delete_incident_edges_disconnected (u v : V) (h : u \u2260 v) : \u00ac (G.delete_edges (G.incidence_finset u)).reachable u v :=\nbegin\n  unfold reachable,\n  simp only [not_nonempty_iff],\n  fconstructor,\n  intros p,\n  have w := p.get_vert 1,\n  have h2 := walk.adj_get_vert_succ p,\n  have h3 : 0 < p.length,\n  by_contra h4,\n  push_neg at h4,\n  simp at h4,\n  have h5 := walk.eq_of_length_eq_zero h4,\n  apply h,\n  exact h5,\n  specialize h2 h3,\n  rw walk.get_vert_zero at h2,\n  rw delete_edges_adj at h2,\n  cases h2 with h5 h6,\n  apply h6,\n  simp at *,\n  exact h5,\nend\n\nlemma delete_incident_edges_not_preconnected (u : V) (h : 0 < G.degree u) : \u00ac (G.delete_edges (G.incidence_finset u)).preconnected :=\nbegin\n  unfold preconnected,\n  push_neg,\n  use u,\n  have h3 := G.degree_pos_iff_exists_adj u,\n  cases h3 with h3 h5,\n  specialize h3 h,\n  cases h3 with w hw,\n  use w,\n  apply delete_incident_edges_disconnected,\n  apply G.ne_of_adj hw,\nend\n\nlemma edge_conn_le_min_deg (k : \u2115) (h2 : G.is_k_edge_connected k) : k \u2264 G.min_degree := \nbegin\n  have hv := G.exists_minimal_degree_vertex,\n  cases hv with v hv,\n  have h : \u00ac connected (G.delete_edges (G.incidence_finset v)),\n  -- v has no neighbors when you delete its incidence set\n  cases (G.min_degree),\n  { \n    by_contra h3,\n    sorry },\n  { -- unfold degree at hv,\n    have h3 := G.degree_pos_iff_exists_adj v,\n    cases h3 with h3 h5,\n    specialize h3 sorry,\n    cases h3 with w hw,\n    by_contra h4,\n    cases h4 with h4 h5,\n    apply G.delete_incident_edges_not_preconnected v sorry,\n    exact h4 },\n  specialize h2 (G.incidence_finset v),\n  specialize h2 sorry,\n  contrapose h2,\n  push_neg at h2,\n  push_neg,\n  rw \u2190 G.card_incidence_finset_eq_degree at hv,\n  rw hv at h2,\n  exact \u27e8h2, h\u27e9,\nend\n\n/--\nFor a set S \u2286 V(G), the cut induced by S (or just a cut) is the set of all edges with one end in S\nand one end not in S, denoted by cut G(S) or cut(S).  \n-/\ndef edge_cut (S : set V) : set (sym2 V) := {e \u2208 G.edge_set | \u2203 (v : V) (h : v \u2208 e), v \u2208 S \u2227 sym2.mem.other h \u2209 S}\n-- why did i have to specify sym2.mem in order to make it work? i can't find the namespace declaration\n\n/--\nLemma 2.6 (Cut criterion for connectivity, Math 239). A graph is connected if and only if every nontrivial cut is nonempty\n-/\nlemma cut_criterion : G.connected \u2194 \u2200 (S : set V), set.nonempty S \u2227 S \u2260 set.univ \u2192 set.nonempty (G.edge_cut S) :=\nbegin\n  split,\n  { rintros \u27e8hpre, hnon\u27e9 S \u27e8hne, hna\u27e9,\n    cases hne with v hv,\n    rw set.ne_univ_iff_exists_not_mem at hna,\n    cases hna with w hna,\n    specialize hpre v w,\n    cases hpre with w, \n    -- need to show that at some point there is an edge in w that has an endpoint in S and another endpoint not in S\n    have h : \u2203 e \u2208 w.edges, e \u2208 G.edge_cut S,\n    { unfold edge_cut,\n      simp,\n      sorry },\n    rcases h with \u27e8e, \u27e8he, he2\u27e9\u27e9,\n    use \u27e8e, he2\u27e9 },\n  { rintros h,\n    split,\n    intros v w,\n    --specialize h {v} sorry,\n    sorry },\nend\n\nend simple_graph", "meta": {"author": "agusakov", "repo": "co342", "sha": "3ae2dc50292b6aa820bbac1f5e40ef73e8560e16", "save_path": "github-repos/lean/agusakov-co342", "path": "github-repos/lean/agusakov-co342/co342-3ae2dc50292b6aa820bbac1f5e40ef73e8560e16/src/lec_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7076970824251366}}
{"text": "/-\nCopyright (c) 2014 Robert Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.ordered_ring\nimport Mathlib.algebra.field\nimport Mathlib.tactic.monotonicity.basic\nimport Mathlib.PostPort\n\nuniverses u_2 l u_1 \n\nnamespace Mathlib\n\n/-!\n  ### Linear ordered fields\n  A linear ordered field is a field equipped with a linear order such that\n  * addition respects the order: `a \u2264 b \u2192 c + a \u2264 c + b`;\n  * multiplication of positives is positive: `0 < a \u2192 0 < b \u2192 0 < a * b`;\n  * `0 < 1`.\n\n  ### Main Definitions\n  * `linear_ordered_field`: the class of linear ordered fields.\n-/\n\n/-- A linear ordered field is a field with a linear order respecting the operations. -/\nclass linear_ordered_field (\u03b1 : Type u_2) \nextends linear_ordered_comm_ring \u03b1, field \u03b1\nwhere\n\n/-!\n### Lemmas about pos, nonneg, nonpos, neg\n-/\n\n@[simp] theorem inv_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 0 < (a\u207b\u00b9) \u2194 0 < a := sorry\n\n@[simp] theorem inv_nonneg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 0 \u2264 (a\u207b\u00b9) \u2194 0 \u2264 a := sorry\n\n@[simp] theorem inv_lt_zero {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : a\u207b\u00b9 < 0 \u2194 a < 0 := sorry\n\n@[simp] theorem inv_nonpos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : a\u207b\u00b9 \u2264 0 \u2194 a \u2264 0 := sorry\n\ntheorem one_div_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 0 < 1 / a \u2194 0 < a :=\n  inv_eq_one_div a \u25b8 inv_pos\n\ntheorem one_div_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 1 / a < 0 \u2194 a < 0 :=\n  inv_eq_one_div a \u25b8 inv_lt_zero\n\ntheorem one_div_nonneg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 0 \u2264 1 / a \u2194 0 \u2264 a :=\n  inv_eq_one_div a \u25b8 inv_nonneg\n\ntheorem one_div_nonpos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 1 / a \u2264 0 \u2194 a \u2264 0 :=\n  inv_eq_one_div a \u25b8 inv_nonpos\n\ntheorem div_pos_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : 0 < a / b \u2194 0 < a \u2227 0 < b \u2228 a < 0 \u2227 b < 0 := sorry\n\ntheorem div_neg_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : a / b < 0 \u2194 0 < a \u2227 b < 0 \u2228 a < 0 \u2227 0 < b := sorry\n\ntheorem div_nonneg_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : 0 \u2264 a / b \u2194 0 \u2264 a \u2227 0 \u2264 b \u2228 a \u2264 0 \u2227 b \u2264 0 := sorry\n\ntheorem div_nonpos_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : a / b \u2264 0 \u2194 0 \u2264 a \u2227 b \u2264 0 \u2228 a \u2264 0 \u2227 0 \u2264 b := sorry\n\ntheorem div_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : 0 < a / b :=\n  mul_pos ha (iff.mpr inv_pos hb)\n\ntheorem div_pos_of_neg_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : 0 < a / b :=\n  mul_pos_of_neg_of_neg ha (iff.mpr inv_lt_zero hb)\n\ntheorem div_neg_of_neg_of_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : 0 < b) : a / b < 0 :=\n  mul_neg_of_neg_of_pos ha (iff.mpr inv_pos hb)\n\ntheorem div_neg_of_pos_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : b < 0) : a / b < 0 :=\n  mul_neg_of_pos_of_neg ha (iff.mpr inv_lt_zero hb)\n\ntheorem div_nonneg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a / b :=\n  mul_nonneg ha (iff.mpr inv_nonneg hb)\n\ntheorem div_nonneg_of_nonpos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a \u2264 0) (hb : b \u2264 0) : 0 \u2264 a / b :=\n  mul_nonneg_of_nonpos_of_nonpos ha (iff.mpr inv_nonpos hb)\n\ntheorem div_nonpos_of_nonpos_of_nonneg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a \u2264 0) (hb : 0 \u2264 b) : a / b \u2264 0 :=\n  mul_nonpos_of_nonpos_of_nonneg ha (iff.mpr inv_nonneg hb)\n\ntheorem div_nonpos_of_nonneg_of_nonpos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 \u2264 a) (hb : b \u2264 0) : a / b \u2264 0 :=\n  mul_nonpos_of_nonneg_of_nonpos ha (iff.mpr inv_nonpos hb)\n\n/-!\n### Relating one division with another term.\n-/\n\ntheorem le_div_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : a \u2264 b / c \u2194 a * c \u2264 b := sorry\n\ntheorem le_div_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : a \u2264 b / c \u2194 c * a \u2264 b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 b / c \u2194 c * a \u2264 b)) (mul_comm c a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 b / c \u2194 a * c \u2264 b)) (propext (le_div_iff hc)))) (iff.refl (a * c \u2264 b)))\n\ntheorem div_le_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hb : 0 < b) : a / b \u2264 c \u2194 a \u2264 c * b := sorry\n\ntheorem div_le_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hb : 0 < b) : a / b \u2264 c \u2194 a \u2264 b * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b \u2264 c \u2194 a \u2264 b * c)) (mul_comm b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a / b \u2264 c \u2194 a \u2264 c * b)) (propext (div_le_iff hb)))) (iff.refl (a \u2264 c * b)))\n\ntheorem lt_div_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : a < b / c \u2194 a * c < b :=\n  lt_iff_lt_of_le_iff_le (div_le_iff hc)\n\ntheorem lt_div_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : a < b / c \u2194 c * a < b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a < b / c \u2194 c * a < b)) (mul_comm c a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a < b / c \u2194 a * c < b)) (propext (lt_div_iff hc)))) (iff.refl (a * c < b)))\n\ntheorem div_lt_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : b / c < a \u2194 b < a * c :=\n  lt_iff_lt_of_le_iff_le (le_div_iff hc)\n\ntheorem div_lt_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : b / c < a \u2194 b < c * a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b / c < a \u2194 b < c * a)) (mul_comm c a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b / c < a \u2194 b < a * c)) (propext (div_lt_iff hc)))) (iff.refl (b < a * c)))\n\ntheorem inv_mul_le_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 b * c := sorry\n\ntheorem inv_mul_le_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 c * b)) (propext (inv_mul_le_iff h))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 b * c \u2194 a \u2264 c * b)) (mul_comm b c))) (iff.refl (a \u2264 c * b)))\n\ntheorem mul_inv_le_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : a * (b\u207b\u00b9) \u2264 c \u2194 a \u2264 b * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b\u207b\u00b9) \u2264 c \u2194 a \u2264 b * c)) (mul_comm a (b\u207b\u00b9))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 b * c)) (propext (inv_mul_le_iff h)))) (iff.refl (a \u2264 b * c)))\n\ntheorem mul_inv_le_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : a * (b\u207b\u00b9) \u2264 c \u2194 a \u2264 c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b\u207b\u00b9) \u2264 c \u2194 a \u2264 c * b)) (mul_comm a (b\u207b\u00b9))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 c * b)) (propext (inv_mul_le_iff' h)))) (iff.refl (a \u2264 c * b)))\n\ntheorem inv_mul_lt_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : b\u207b\u00b9 * a < c \u2194 a < b * c := sorry\n\ntheorem inv_mul_lt_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : b\u207b\u00b9 * a < c \u2194 a < c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 * a < c \u2194 a < c * b)) (propext (inv_mul_lt_iff h))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a < b * c \u2194 a < c * b)) (mul_comm b c))) (iff.refl (a < c * b)))\n\ntheorem mul_inv_lt_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : a * (b\u207b\u00b9) < c \u2194 a < b * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b\u207b\u00b9) < c \u2194 a < b * c)) (mul_comm a (b\u207b\u00b9))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 * a < c \u2194 a < b * c)) (propext (inv_mul_lt_iff h)))) (iff.refl (a < b * c)))\n\ntheorem mul_inv_lt_iff' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (h : 0 < b) : a * (b\u207b\u00b9) < c \u2194 a < c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b\u207b\u00b9) < c \u2194 a < c * b)) (mul_comm a (b\u207b\u00b9))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 * a < c \u2194 a < c * b)) (propext (inv_mul_lt_iff' h)))) (iff.refl (a < c * b)))\n\ntheorem inv_pos_le_iff_one_le_mul {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 b * a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 \u2264 b \u2194 1 \u2264 b * a)) (inv_eq_one_div a))) (div_le_iff ha)\n\ntheorem inv_pos_le_iff_one_le_mul' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 a * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 \u2264 b \u2194 1 \u2264 a * b)) (inv_eq_one_div a))) (div_le_iff' ha)\n\ntheorem inv_pos_lt_iff_one_lt_mul {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) : a\u207b\u00b9 < b \u2194 1 < b * a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 < b \u2194 1 < b * a)) (inv_eq_one_div a))) (div_lt_iff ha)\n\ntheorem inv_pos_lt_iff_one_lt_mul' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) : a\u207b\u00b9 < b \u2194 1 < a * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 < b \u2194 1 < a * b)) (inv_eq_one_div a))) (div_lt_iff' ha)\n\ntheorem div_le_iff_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : b / c \u2264 a \u2194 a * c \u2264 b := sorry\n\ntheorem div_le_iff_of_neg' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : b / c \u2264 a \u2194 c * a \u2264 b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b / c \u2264 a \u2194 c * a \u2264 b)) (mul_comm c a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b / c \u2264 a \u2194 a * c \u2264 b)) (propext (div_le_iff_of_neg hc)))) (iff.refl (a * c \u2264 b)))\n\ntheorem le_div_iff_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : a \u2264 b / c \u2194 b \u2264 a * c := sorry\n\ntheorem le_div_iff_of_neg' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : a \u2264 b / c \u2194 b \u2264 c * a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 b / c \u2194 b \u2264 c * a)) (mul_comm c a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 b / c \u2194 b \u2264 a * c)) (propext (le_div_iff_of_neg hc)))) (iff.refl (b \u2264 a * c)))\n\ntheorem div_lt_iff_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : b / c < a \u2194 a * c < b :=\n  lt_iff_lt_of_le_iff_le (le_div_iff_of_neg hc)\n\ntheorem div_lt_iff_of_neg' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : b / c < a \u2194 c * a < b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b / c < a \u2194 c * a < b)) (mul_comm c a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b / c < a \u2194 a * c < b)) (propext (div_lt_iff_of_neg hc)))) (iff.refl (a * c < b)))\n\ntheorem lt_div_iff_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : a < b / c \u2194 b < a * c :=\n  lt_iff_lt_of_le_iff_le (div_le_iff_of_neg hc)\n\ntheorem lt_div_iff_of_neg' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : a < b / c \u2194 b < c * a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a < b / c \u2194 b < c * a)) (mul_comm c a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a < b / c \u2194 b < a * c)) (propext (lt_div_iff_of_neg hc)))) (iff.refl (b < a * c)))\n\n/-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/\ntheorem div_le_of_nonneg_of_le_mul {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hb : 0 \u2264 b) (hc : 0 \u2264 c) (h : a \u2264 c * b) : a / b \u2264 c := sorry\n\ntheorem div_le_one_of_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (h : a \u2264 b) (hb : 0 \u2264 b) : a / b \u2264 1 :=\n  div_le_of_nonneg_of_le_mul hb zero_le_one (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 1 * b)) (one_mul b))) h)\n\n/-!\n### Bi-implications of inequalities using inversions\n-/\n\ntheorem inv_le_inv_of_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (h : a \u2264 b) : b\u207b\u00b9 \u2264 (a\u207b\u00b9) := sorry\n\n/-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/\ntheorem inv_le_inv {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 \u2264 (b\u207b\u00b9) \u2194 b \u2264 a := sorry\n\ntheorem inv_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a)) (Eq.symm (propext (inv_le_inv hb (iff.mpr inv_pos ha))))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 \u2264 (a\u207b\u00b9\u207b\u00b9) \u2194 b\u207b\u00b9 \u2264 a)) (inv_inv' a))) (iff.refl (b\u207b\u00b9 \u2264 a)))\n\ntheorem le_inv {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a \u2264 (b\u207b\u00b9) \u2194 b \u2264 (a\u207b\u00b9) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 (b\u207b\u00b9) \u2194 b \u2264 (a\u207b\u00b9))) (Eq.symm (propext (inv_le_inv (iff.mpr inv_pos hb) ha)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9\u207b\u00b9 \u2264 (a\u207b\u00b9) \u2194 b \u2264 (a\u207b\u00b9))) (inv_inv' b))) (iff.refl (b \u2264 (a\u207b\u00b9))))\n\ntheorem inv_lt_inv {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 < (b\u207b\u00b9) \u2194 b < a :=\n  lt_iff_lt_of_le_iff_le (inv_le_inv hb ha)\n\ntheorem inv_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a\u207b\u00b9 < b \u2194 b\u207b\u00b9 < a :=\n  lt_iff_lt_of_le_iff_le (le_inv hb ha)\n\ntheorem lt_inv {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a < (b\u207b\u00b9) \u2194 b < (a\u207b\u00b9) :=\n  lt_iff_lt_of_le_iff_le (inv_le hb ha)\n\ntheorem inv_le_inv_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 \u2264 (b\u207b\u00b9) \u2194 b \u2264 a := sorry\n\ntheorem inv_le_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a :=\n  eq.mpr\n    (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a)) (Eq.symm (propext (inv_le_inv_of_neg hb (iff.mpr inv_lt_zero ha))))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b\u207b\u00b9 \u2264 (a\u207b\u00b9\u207b\u00b9) \u2194 b\u207b\u00b9 \u2264 a)) (inv_inv' a))) (iff.refl (b\u207b\u00b9 \u2264 a)))\n\ntheorem le_inv_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a \u2264 (b\u207b\u00b9) \u2194 b \u2264 (a\u207b\u00b9) := sorry\n\ntheorem inv_lt_inv_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 < (b\u207b\u00b9) \u2194 b < a :=\n  lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)\n\ntheorem inv_lt_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a\u207b\u00b9 < b \u2194 b\u207b\u00b9 < a :=\n  lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)\n\ntheorem lt_inv_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a < (b\u207b\u00b9) \u2194 b < (a\u207b\u00b9) :=\n  lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)\n\ntheorem inv_lt_one {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (ha : 1 < a) : a\u207b\u00b9 < 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 < 1)) (propext (inv_lt (has_lt.lt.trans zero_lt_one ha) zero_lt_one))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (1\u207b\u00b9 < a)) inv_one)) ha)\n\ntheorem one_lt_inv {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h\u2081 : 0 < a) (h\u2082 : a < 1) : 1 < (a\u207b\u00b9) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 < (a\u207b\u00b9))) (propext (lt_inv zero_lt_one h\u2081))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a < (1\u207b\u00b9))) inv_one)) h\u2082)\n\ntheorem inv_le_one {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (ha : 1 \u2264 a) : a\u207b\u00b9 \u2264 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a\u207b\u00b9 \u2264 1)) (propext (inv_le (has_lt.lt.trans_le zero_lt_one ha) zero_lt_one))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (1\u207b\u00b9 \u2264 a)) inv_one)) ha)\n\ntheorem one_le_inv {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h\u2081 : 0 < a) (h\u2082 : a \u2264 1) : 1 \u2264 (a\u207b\u00b9) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 \u2264 (a\u207b\u00b9))) (propext (le_inv zero_lt_one h\u2081))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 (1\u207b\u00b9))) inv_one)) h\u2082)\n\ntheorem inv_lt_one_iff_of_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h\u2080 : 0 < a) : a\u207b\u00b9 < 1 \u2194 1 < a :=\n  { mp := fun (h\u2081 : a\u207b\u00b9 < 1) => inv_inv' a \u25b8 one_lt_inv (iff.mpr inv_pos h\u2080) h\u2081, mpr := inv_lt_one }\n\ntheorem inv_lt_one_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : a\u207b\u00b9 < 1 \u2194 a \u2264 0 \u2228 1 < a := sorry\n\ntheorem one_lt_inv_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 1 < (a\u207b\u00b9) \u2194 0 < a \u2227 a < 1 := sorry\n\ntheorem inv_le_one_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : a\u207b\u00b9 \u2264 1 \u2194 a \u2264 0 \u2228 1 \u2264 a := sorry\n\ntheorem one_le_inv_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 1 \u2264 (a\u207b\u00b9) \u2194 0 < a \u2227 a \u2264 1 := sorry\n\n/-!\n### Relating two divisions.\n-/\n\ntheorem div_le_div_of_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 \u2264 c) (h : a \u2264 b) : a / c \u2264 b / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / c \u2264 b / c)) (div_eq_mul_one_div a c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (1 / c) \u2264 b / c)) (div_eq_mul_one_div b c)))\n      (mul_le_mul_of_nonneg_right h (iff.mpr one_div_nonneg hc)))\n\ntheorem div_le_div_of_le_left {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (ha : 0 \u2264 a) (hc : 0 < c) (h : c \u2264 b) : a / b \u2264 a / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b \u2264 a / c)) (div_eq_mul_inv a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (b\u207b\u00b9) \u2264 a / c)) (div_eq_mul_inv a c)))\n      (mul_le_mul_of_nonneg_left (iff.mpr (inv_le_inv (has_lt.lt.trans_le hc h) hc) h) ha))\n\ntheorem div_le_div_of_le_of_nonneg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hab : a \u2264 b) (hc : 0 \u2264 c) : a / c \u2264 b / c :=\n  div_le_div_of_le hc hab\n\ntheorem div_le_div_of_nonpos_of_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c \u2264 0) (h : b \u2264 a) : a / c \u2264 b / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / c \u2264 b / c)) (div_eq_mul_one_div a c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (1 / c) \u2264 b / c)) (div_eq_mul_one_div b c)))\n      (mul_le_mul_of_nonpos_right h (iff.mpr one_div_nonpos hc)))\n\ntheorem div_lt_div_of_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) (h : a < b) : a / c < b / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / c < b / c)) (div_eq_mul_one_div a c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (1 / c) < b / c)) (div_eq_mul_one_div b c)))\n      (mul_lt_mul_of_pos_right h (iff.mpr one_div_pos hc)))\n\ntheorem div_lt_div_of_neg_of_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) (h : b < a) : a / c < b / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / c < b / c)) (div_eq_mul_one_div a c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (1 / c) < b / c)) (div_eq_mul_one_div b c)))\n      (mul_lt_mul_of_neg_right h (iff.mpr one_div_neg hc)))\n\ntheorem div_le_div_right {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : a / c \u2264 b / c \u2194 a \u2264 b :=\n  { mp := le_imp_le_of_lt_imp_lt (div_lt_div_of_lt hc), mpr := div_le_div_of_le (has_lt.lt.le hc) }\n\ntheorem div_le_div_right_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : a / c \u2264 b / c \u2194 b \u2264 a :=\n  { mp := le_imp_le_of_lt_imp_lt (div_lt_div_of_neg_of_lt hc), mpr := div_le_div_of_nonpos_of_le (has_lt.lt.le hc) }\n\ntheorem div_lt_div_right {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : 0 < c) : a / c < b / c \u2194 a < b :=\n  lt_iff_lt_of_le_iff_le (div_le_div_right hc)\n\ntheorem div_lt_div_right_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hc : c < 0) : a / c < b / c \u2194 b < a :=\n  lt_iff_lt_of_le_iff_le (div_le_div_right_of_neg hc)\n\ntheorem div_lt_div_left {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c \u2194 c < b :=\n  iff.trans (mul_lt_mul_left ha) (inv_lt_inv hb hc)\n\ntheorem div_le_div_left {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b \u2264 a / c \u2194 c \u2264 b :=\n  iff.mpr le_iff_le_iff_lt_iff_lt (div_lt_div_left ha hc hb)\n\ntheorem div_lt_div_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d \u2194 a * d < c * b := sorry\n\ntheorem div_le_div_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (b0 : 0 < b) (d0 : 0 < d) : a / b \u2264 c / d \u2194 a * d \u2264 c * b := sorry\n\ntheorem div_le_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hc : 0 \u2264 c) (hac : a \u2264 c) (hd : 0 < d) (hbd : d \u2264 b) : a / b \u2264 c / d :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b \u2264 c / d)) (propext (div_le_div_iff (has_lt.lt.trans_le hd hbd) hd))))\n    (mul_le_mul hac hbd (has_lt.lt.le hd) hc)\n\ntheorem div_lt_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hac : a < c) (hbd : d \u2264 b) (c0 : 0 \u2264 c) (d0 : 0 < d) : a / b < c / d :=\n  iff.mpr (div_lt_div_iff (has_lt.lt.trans_le d0 hbd) d0) (mul_lt_mul hac hbd d0 c0)\n\ntheorem div_lt_div' {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hac : a \u2264 c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=\n  iff.mpr (div_lt_div_iff (has_lt.lt.trans d0 hbd) d0) (mul_lt_mul' hac hbd (has_lt.lt.le d0) c0)\n\ntheorem div_lt_div_of_lt_left {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} (hb : 0 < b) (h : b < a) (hc : 0 < c) : c / a < c / b :=\n  iff.mpr (div_lt_div_left hc (has_lt.lt.trans hb h) hb) h\n\n/-!\n### Relating one division and involving `1`\n-/\n\ntheorem one_le_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : 1 \u2264 a / b \u2194 b \u2264 a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 \u2264 a / b \u2194 b \u2264 a)) (propext (le_div_iff hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (1 * b \u2264 a \u2194 b \u2264 a)) (one_mul b))) (iff.refl (b \u2264 a)))\n\ntheorem div_le_one {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : a / b \u2264 1 \u2194 a \u2264 b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b \u2264 1 \u2194 a \u2264 b)) (propext (div_le_iff hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 1 * b \u2194 a \u2264 b)) (one_mul b))) (iff.refl (a \u2264 b)))\n\ntheorem one_lt_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : 1 < a / b \u2194 b < a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 < a / b \u2194 b < a)) (propext (lt_div_iff hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (1 * b < a \u2194 b < a)) (one_mul b))) (iff.refl (b < a)))\n\ntheorem div_lt_one {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : 0 < b) : a / b < 1 \u2194 a < b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b < 1 \u2194 a < b)) (propext (div_lt_iff hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a < 1 * b \u2194 a < b)) (one_mul b))) (iff.refl (a < b)))\n\ntheorem one_le_div_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) : 1 \u2264 a / b \u2194 a \u2264 b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 \u2264 a / b \u2194 a \u2264 b)) (propext (le_div_iff_of_neg hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 1 * b \u2194 a \u2264 b)) (one_mul b))) (iff.refl (a \u2264 b)))\n\ntheorem div_le_one_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) : a / b \u2264 1 \u2194 b \u2264 a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b \u2264 1 \u2194 b \u2264 a)) (propext (div_le_iff_of_neg hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (1 * b \u2264 a \u2194 b \u2264 a)) (one_mul b))) (iff.refl (b \u2264 a)))\n\ntheorem one_lt_div_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) : 1 < a / b \u2194 a < b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 < a / b \u2194 a < b)) (propext (lt_div_iff_of_neg hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a < 1 * b \u2194 a < b)) (one_mul b))) (iff.refl (a < b)))\n\ntheorem div_lt_one_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) : a / b < 1 \u2194 b < a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b < 1 \u2194 b < a)) (propext (div_lt_iff_of_neg hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (1 * b < a \u2194 b < a)) (one_mul b))) (iff.refl (b < a)))\n\ntheorem one_div_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : 1 / a \u2264 b \u2194 1 / b \u2264 a := sorry\n\ntheorem one_div_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : 1 / a < b \u2194 1 / b < a := sorry\n\ntheorem le_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a \u2264 1 / b \u2194 b \u2264 1 / a := sorry\n\ntheorem lt_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : a < 1 / b \u2194 b < 1 / a := sorry\n\ntheorem one_div_le_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : 1 / a \u2264 b \u2194 1 / b \u2264 a := sorry\n\ntheorem one_div_lt_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : 1 / a < b \u2194 1 / b < a := sorry\n\ntheorem le_one_div_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a \u2264 1 / b \u2194 b \u2264 1 / a := sorry\n\ntheorem lt_one_div_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : a < 1 / b \u2194 b < 1 / a := sorry\n\ntheorem one_lt_div_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : 1 < a / b \u2194 0 < b \u2227 b < a \u2228 b < 0 \u2227 a < b := sorry\n\ntheorem one_le_div_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : 1 \u2264 a / b \u2194 0 < b \u2227 b \u2264 a \u2228 b < 0 \u2227 a \u2264 b := sorry\n\ntheorem div_lt_one_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : a / b < 1 \u2194 0 < b \u2227 a < b \u2228 b = 0 \u2228 b < 0 \u2227 b < a := sorry\n\ntheorem div_le_one_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} : a / b \u2264 1 \u2194 0 < b \u2227 a \u2264 b \u2228 b = 0 \u2228 b < 0 \u2227 b \u2264 a := sorry\n\n/-!\n### Relating two divisions, involving `1`\n-/\n\ntheorem one_div_le_one_div_of_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (h : a \u2264 b) : 1 / b \u2264 1 / a := sorry\n\ntheorem one_div_lt_one_div_of_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (h : a < b) : 1 / b < 1 / a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 / b < 1 / a)) (propext (lt_div_iff' ha))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * (1 / b) < 1)) (Eq.symm (div_eq_mul_one_div a b))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a / b < 1)) (propext (div_lt_one (has_lt.lt.trans ha h))))) h))\n\ntheorem one_div_le_one_div_of_neg_of_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) (h : a \u2264 b) : 1 / b \u2264 1 / a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 / b \u2264 1 / a)) (propext (div_le_iff_of_neg' hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * (1 / a) \u2264 1)) (Eq.symm (div_eq_mul_one_div b a))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b / a \u2264 1)) (propext (div_le_one_of_neg (has_le.le.trans_lt h hb))))) h))\n\ntheorem one_div_lt_one_div_of_neg_of_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) (h : a < b) : 1 / b < 1 / a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 / b < 1 / a)) (propext (div_lt_iff_of_neg' hb))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * (1 / a) < 1)) (Eq.symm (div_eq_mul_one_div b a))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b / a < 1)) (propext (div_lt_one_of_neg (has_lt.lt.trans h hb))))) h))\n\ntheorem le_of_one_div_le_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (h : 1 / a \u2264 1 / b) : b \u2264 a :=\n  le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h\n\ntheorem lt_of_one_div_lt_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=\n  lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h\n\ntheorem le_of_neg_of_one_div_le_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) (h : 1 / a \u2264 1 / b) : b \u2264 a :=\n  le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h\n\ntheorem lt_of_neg_of_one_div_lt_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (hb : b < 0) (h : 1 / a < 1 / b) : b < a :=\n  lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h\n\n/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and\n  `le_of_one_div_le_one_div` -/\ntheorem one_div_le_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : 1 / a \u2264 1 / b \u2194 b \u2264 a :=\n  div_le_div_left zero_lt_one ha hb\n\n/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and\n  `lt_of_one_div_lt_one_div` -/\ntheorem one_div_lt_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b \u2194 b < a :=\n  div_lt_div_left zero_lt_one ha hb\n\n/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and\n  `lt_of_one_div_lt_one_div` -/\ntheorem one_div_le_one_div_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : 1 / a \u2264 1 / b \u2194 b \u2264 a := sorry\n\n/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and\n  `lt_of_one_div_lt_one_div` -/\ntheorem one_div_lt_one_div_of_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b \u2194 b < a :=\n  lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)\n\ntheorem one_lt_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 < 1 / a)) (propext (lt_one_div zero_lt_one h1))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a < 1 / 1)) one_div_one)) h2)\n\ntheorem one_le_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h1 : 0 < a) (h2 : a \u2264 1) : 1 \u2264 1 / a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (1 \u2264 1 / a)) (propext (le_one_div zero_lt_one h1))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 1 / 1)) one_div_one)) h2)\n\ntheorem one_div_lt_neg_one {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 :=\n  (fun (this : 1 / a < 1 / -1) => eq.mp (Eq._oldrec (Eq.refl (1 / a < 1 / -1)) one_div_neg_one_eq_neg_one) this)\n    (one_div_lt_one_div_of_neg_of_lt h1 h2)\n\ntheorem one_div_le_neg_one {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h1 : a < 0) (h2 : -1 \u2264 a) : 1 / a \u2264 -1 :=\n  (fun (this : 1 / a \u2264 1 / -1) => eq.mp (Eq._oldrec (Eq.refl (1 / a \u2264 1 / -1)) one_div_neg_one_eq_neg_one) this)\n    (one_div_le_one_div_of_neg_of_le h1 h2)\n\n/-!\n### Results about halving.\n\nThe equalities also hold in fields of characteristic `0`. -/\n\ntheorem add_halves {\u03b1 : Type u_1} [linear_ordered_field \u03b1] (a : \u03b1) : a / bit0 1 + a / bit0 1 = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / bit0 1 + a / bit0 1 = a)) (div_add_div_same a a (bit0 1))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a + a) / bit0 1 = a)) (Eq.symm (two_mul a))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 1 * a / bit0 1 = a)) (mul_div_cancel_left a two_ne_zero))) (Eq.refl a)))\n\ntheorem sub_self_div_two {\u03b1 : Type u_1} [linear_ordered_field \u03b1] (a : \u03b1) : a - a / bit0 1 = a / bit0 1 := sorry\n\ntheorem div_two_sub_self {\u03b1 : Type u_1} [linear_ordered_field \u03b1] (a : \u03b1) : a / bit0 1 - a = -(a / bit0 1) := sorry\n\ntheorem add_self_div_two {\u03b1 : Type u_1} [linear_ordered_field \u03b1] (a : \u03b1) : (a + a) / bit0 1 = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + a) / bit0 1 = a)) (Eq.symm (mul_two a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * bit0 1 / bit0 1 = a)) (mul_div_cancel a two_ne_zero))) (Eq.refl a))\n\ntheorem half_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h : 0 < a) : 0 < a / bit0 1 :=\n  div_pos h zero_lt_two\n\ntheorem one_half_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] : 0 < 1 / bit0 1 :=\n  half_pos zero_lt_one\n\ntheorem div_two_lt_of_pos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} (h : 0 < a) : a / bit0 1 < a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / bit0 1 < a)) (propext (div_lt_iff zero_lt_two))))\n    (lt_mul_of_one_lt_right h one_lt_two)\n\ntheorem half_lt_self {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} : 0 < a \u2192 a / bit0 1 < a :=\n  div_two_lt_of_pos\n\ntheorem one_half_lt_one {\u03b1 : Type u_1} [linear_ordered_field \u03b1] : 1 / bit0 1 < 1 :=\n  half_lt_self zero_lt_one\n\ntheorem add_sub_div_two_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (h : a < b) : a + (b - a) / bit0 1 < b := sorry\n\n/-!\n### Miscellaneous lemmas\n-/\n\ntheorem mul_sub_mul_div_mul_neg_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hc : c \u2260 0) (hd : d \u2260 0) : (a * d - b * c) / (c * d) < 0 \u2194 a / c < b / d := sorry\n\ntheorem mul_sub_mul_div_mul_neg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hc : c \u2260 0) (hd : d \u2260 0) : a / c < b / d \u2192 (a * d - b * c) / (c * d) < 0 :=\n  iff.mpr (mul_sub_mul_div_mul_neg_iff hc hd)\n\ntheorem mul_sub_mul_div_mul_nonpos_iff {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hc : c \u2260 0) (hd : d \u2260 0) : (a * d - b * c) / (c * d) \u2264 0 \u2194 a / c \u2264 b / d := sorry\n\ntheorem mul_sub_mul_div_mul_nonpos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (hc : c \u2260 0) (hd : d \u2260 0) : a / c \u2264 b / d \u2192 (a * d - b * c) / (c * d) \u2264 0 :=\n  iff.mpr (mul_sub_mul_div_mul_nonpos_iff hc hd)\n\ntheorem mul_le_mul_of_mul_div_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} (h : a * (b / c) \u2264 d) (hc : 0 < c) : b * a \u2264 d * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b * a \u2264 d * c)) (mul_comm b a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a * b \u2264 d * c)) (Eq.symm (propext (div_le_iff hc)))))\n      (eq.mp (Eq._oldrec (Eq.refl (a * (b / c) \u2264 d)) (Eq.symm mul_div_assoc)) h))\n\ntheorem div_mul_le_div_mul_of_div_le_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1} {d : \u03b1} {e : \u03b1} (h : a / b \u2264 c / d) (he : 0 \u2264 e) : a / (b * e) \u2264 c / (d * e) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / (b * e) \u2264 c / (d * e))) (div_mul_eq_div_mul_one_div a b e)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a / b * (1 / e) \u2264 c / (d * e))) (div_mul_eq_div_mul_one_div c d e)))\n      (mul_le_mul_of_nonneg_right h (iff.mpr one_div_nonneg he)))\n\ntheorem exists_add_lt_and_pos_of_lt {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (h : b < a) : \u2203 (c : \u03b1), b + c < a \u2227 0 < c :=\n  Exists.intro ((a - b) / bit0 1) { left := add_sub_div_two_lt h, right := div_pos (sub_pos_of_lt h) zero_lt_two }\n\ntheorem le_of_forall_sub_le {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (h : \u2200 (\u03b5 : \u03b1), \u03b5 > 0 \u2192 b - \u03b5 \u2264 a) : b \u2264 a := sorry\n\ntheorem monotone.div_const {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} (hf : monotone f) {c : \u03b1} (hc : 0 \u2264 c) : monotone fun (x : \u03b2) => f x / c :=\n  monotone.mul_const hf (iff.mpr inv_nonneg hc)\n\ntheorem strict_mono.div_const {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b2 \u2192 \u03b1} (hf : strict_mono f) {c : \u03b1} (hc : 0 < c) : strict_mono fun (x : \u03b2) => f x / c :=\n  strict_mono.mul_const hf (iff.mpr inv_pos hc)\n\nprotected instance linear_ordered_field.to_densely_ordered {\u03b1 : Type u_1} [linear_ordered_field \u03b1] : densely_ordered \u03b1 :=\n  densely_ordered.mk\n    fun (a\u2081 a\u2082 : \u03b1) (h : a\u2081 < a\u2082) =>\n      Exists.intro ((a\u2081 + a\u2082) / bit0 1)\n        { left :=\n            trans_rel_right Less (Eq.symm (add_self_div_two a\u2081)) (div_lt_div_of_lt zero_lt_two (add_lt_add_left h a\u2081)),\n          right := trans_rel_left Less (div_lt_div_of_lt zero_lt_two (add_lt_add_right h a\u2082)) (add_self_div_two a\u2082) }\n\ntheorem mul_self_inj_of_nonneg {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {a : \u03b1} {b : \u03b1} (a0 : 0 \u2264 a) (b0 : 0 \u2264 b) : a * a = b * b \u2194 a = b := sorry\n\ntheorem min_div_div_right {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {c : \u03b1} (hc : 0 \u2264 c) (a : \u03b1) (b : \u03b1) : min (a / c) (b / c) = min a b / c :=\n  Eq.symm (monotone.map_min fun (x y : \u03b1) => div_le_div_of_le hc)\n\ntheorem max_div_div_right {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {c : \u03b1} (hc : 0 \u2264 c) (a : \u03b1) (b : \u03b1) : max (a / c) (b / c) = max a b / c :=\n  Eq.symm (monotone.map_max fun (x y : \u03b1) => div_le_div_of_le hc)\n\ntheorem min_div_div_right_of_nonpos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {c : \u03b1} (hc : c \u2264 0) (a : \u03b1) (b : \u03b1) : min (a / c) (b / c) = max a b / c :=\n  Eq.symm (monotone.map_max fun (x y : \u03b1) => div_le_div_of_nonpos_of_le hc)\n\ntheorem max_div_div_right_of_nonpos {\u03b1 : Type u_1} [linear_ordered_field \u03b1] {c : \u03b1} (hc : c \u2264 0) (a : \u03b1) (b : \u03b1) : max (a / c) (b / c) = min a b / c :=\n  Eq.symm (monotone.map_min fun (x y : \u03b1) => div_le_div_of_nonpos_of_le hc)\n\ntheorem abs_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] (a : \u03b1) (b : \u03b1) : abs (a / b) = abs a / abs b :=\n  monoid_with_zero_hom.map_div abs_hom a b\n\ntheorem abs_one_div {\u03b1 : Type u_1} [linear_ordered_field \u03b1] (a : \u03b1) : abs (1 / a) = 1 / abs a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (abs (1 / a) = 1 / abs a)) (abs_div 1 a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (abs 1 / abs a = 1 / abs a)) abs_one)) (Eq.refl (1 / abs a)))\n\ntheorem abs_inv {\u03b1 : Type u_1} [linear_ordered_field \u03b1] (a : \u03b1) : abs (a\u207b\u00b9) = (abs a\u207b\u00b9) :=\n  monoid_with_zero_hom.map_inv' abs_hom a\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebra/ordered_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7076947653183195}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.set.function\nimport Mathlib.logic.function.iterate\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\n\n/-!\n# Fixed points of a self-map\n\nIn this file we define\n\n* the predicate `is_fixed_pt f x := f x = x`;\n* the set `fixed_points f` of fixed points of a self-map `f`.\n\nWe also prove some simple lemmas about `is_fixed_pt` and `\u2218`, `iterate`, and `semiconj`.\n\n## Tags\n\nfixed point\n-/\n\nnamespace function\n\n\n/-- A point `x` is a fixed point of `f : \u03b1 \u2192 \u03b1` if `f x = x`. -/\ndef is_fixed_pt {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1) (x : \u03b1) := f x = x\n\n/-- Every point is a fixed point of `id`. -/\ntheorem is_fixed_pt_id {\u03b1 : Type u} (x : \u03b1) : is_fixed_pt id x := rfl\n\nnamespace is_fixed_pt\n\n\nprotected instance decidable {\u03b1 : Type u} [h : DecidableEq \u03b1] {f : \u03b1 \u2192 \u03b1} {x : \u03b1} :\n    Decidable (is_fixed_pt f x) :=\n  h (f x) x\n\n/-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`.-/\nprotected theorem eq {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x) : f x = x := hf\n\n/-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f \u2218 g`. -/\nprotected theorem comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x)\n    (hg : is_fixed_pt g x) : is_fixed_pt (f \u2218 g) x :=\n  Eq.trans (congr_arg f hg) hf\n\n/-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/\nprotected theorem iterate {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x) (n : \u2115) :\n    is_fixed_pt (nat.iterate f n) x :=\n  iterate_fixed hf n\n\n/-- If `x` is a fixed point of `f \u2218 g` and `g`, then it is a fixed point of `f`. -/\ntheorem left_of_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} {x : \u03b1} (hfg : is_fixed_pt (f \u2218 g) x)\n    (hg : is_fixed_pt g x) : is_fixed_pt f x :=\n  Eq.trans (congr_arg f (Eq.symm hg)) hfg\n\n/-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed\npoint of `g`. -/\ntheorem to_left_inverse {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} {x : \u03b1} (hf : is_fixed_pt f x)\n    (h : left_inverse g f) : is_fixed_pt g x :=\n  Eq.trans (congr_arg g (Eq.symm hf)) (h x)\n\n/-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\nprotected theorem map {\u03b1 : Type u} {\u03b2 : Type v} {fa : \u03b1 \u2192 \u03b1} {fb : \u03b2 \u2192 \u03b2} {x : \u03b1}\n    (hx : is_fixed_pt fa x) {g : \u03b1 \u2192 \u03b2} (h : semiconj g fa fb) : is_fixed_pt fb (g x) :=\n  Eq.trans (Eq.symm (semiconj.eq h x)) (congr_arg g hx)\n\nend is_fixed_pt\n\n\n/-- The set of fixed points of a map `f : \u03b1 \u2192 \u03b1`. -/\ndef fixed_points {\u03b1 : Type u} (f : \u03b1 \u2192 \u03b1) : set \u03b1 := set_of fun (x : \u03b1) => is_fixed_pt f x\n\nprotected instance fixed_points.decidable {\u03b1 : Type u} [DecidableEq \u03b1] (f : \u03b1 \u2192 \u03b1) (x : \u03b1) :\n    Decidable (x \u2208 fixed_points f) :=\n  is_fixed_pt.decidable\n\n@[simp] theorem mem_fixed_points {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {x : \u03b1} :\n    x \u2208 fixed_points f \u2194 is_fixed_pt f x :=\n  iff.rfl\n\n/-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points\nof `fb`. -/\ntheorem semiconj.maps_to_fixed_pts {\u03b1 : Type u} {\u03b2 : Type v} {fa : \u03b1 \u2192 \u03b1} {fb : \u03b2 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2}\n    (h : semiconj g fa fb) : set.maps_to g (fixed_points fa) (fixed_points fb) :=\n  fun (x : \u03b1) (hx : x \u2208 fixed_points fa) => is_fixed_pt.map hx h\n\n/-- Any two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1` are inverse of each other on the sets of fixed points\nof `f \u2218 g` and `g \u2218 f`, respectively. -/\ntheorem inv_on_fixed_pts_comp {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n    set.inv_on f g (fixed_points (f \u2218 g)) (fixed_points (g \u2218 f)) :=\n  { left := fun (x : \u03b2) => id, right := fun (x : \u03b1) => id }\n\n/-- Any map `f` sends fixed points of `g \u2218 f` to fixed points of `f \u2218 g`. -/\ntheorem maps_to_fixed_pts_comp {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n    set.maps_to f (fixed_points (g \u2218 f)) (fixed_points (f \u2218 g)) :=\n  fun (x : \u03b1) (hx : x \u2208 fixed_points (g \u2218 f)) => is_fixed_pt.map hx fun (x : \u03b1) => rfl\n\n/-- Given two maps `f : \u03b1 \u2192 \u03b2` and `g : \u03b2 \u2192 \u03b1`, `g` is a bijective map between the fixed points\nof `f \u2218 g` and the fixed points of `g \u2218 f`. The inverse map is `f`, see `inv_on_fixed_pts_comp`. -/\ntheorem bij_on_fixed_pts_comp {\u03b1 : Type u} {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n    set.bij_on g (fixed_points (f \u2218 g)) (fixed_points (g \u2218 f)) :=\n  set.inv_on.bij_on (inv_on_fixed_pts_comp f g) (maps_to_fixed_pts_comp g f)\n    (maps_to_fixed_pts_comp f g)\n\n/-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points\nof `f \u2218 g`. This is a particular case of `function.inv_on_fixed_pts_comp`. -/\ntheorem commute.inv_on_fixed_pts_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} (h : commute f g) :\n    set.inv_on f g (fixed_points (f \u2218 g)) (fixed_points (f \u2218 g)) :=\n  sorry\n\n/-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\ntheorem commute.left_bij_on_fixed_pts_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} (h : commute f g) :\n    set.bij_on f (fixed_points (f \u2218 g)) (fixed_points (f \u2218 g)) :=\n  sorry\n\n/-- If self-maps `f` and `g` commute, then `g` is bijective on the set of fixed points of `f \u2218 g`.\nThis is a particular case of `function.bij_on_fixed_pts_comp`. -/\ntheorem commute.right_bij_on_fixed_pts_comp {\u03b1 : Type u} {f : \u03b1 \u2192 \u03b1} {g : \u03b1 \u2192 \u03b1} (h : commute f g) :\n    set.bij_on g (fixed_points (f \u2218 g)) (fixed_points (f \u2218 g)) :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/dynamics/fixed_points/basic_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479467, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7076947580547577}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.monomial\n! leanprover-community/mathlib commit 220f71ba506c8958c9b41bd82226b3d06b0991e8\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.Basic\n\n/-!\n# Univariate monomials\n\nPreparatory lemmas for degree_basic.\n-/\n\n\nnoncomputable section\n\nnamespace Polynomial\n\nopen Polynomial\n\nuniverse u\n\nvariable {R : Type u} {a b : R} {m n : \u2115}\n\nvariable [Semiring R] {p q r : R[X]}\n\ntheorem monomial_one_eq_iff [Nontrivial R] {i j : \u2115} :\n    (monomial i 1 : R[X]) = monomial j 1 \u2194 i = j := by\n  -- Porting note: `ofFinsupp.injEq` is required.\n  simp_rw [\u2190 ofFinsupp_single, ofFinsupp.injEq]\n  exact AddMonoidAlgebra.of_injective.eq_iff\n#align polynomial.monomial_one_eq_iff Polynomial.monomial_one_eq_iff\n\ninstance infinite [Nontrivial R] : Infinite R[X] :=\n  Infinite.of_injective (fun i => monomial i 1) fun m n h => by simpa [monomial_one_eq_iff] using h\n#align polynomial.infinite Polynomial.infinite\n\ntheorem card_support_le_one_iff_monomial {f : R[X]} :\n    Finset.card f.support \u2264 1 \u2194 \u2203 n a, f = monomial n a := by\n  constructor\n  \u00b7 intro H\n    rw [Finset.card_le_one_iff_subset_singleton] at H\n    rcases H with \u27e8n, hn\u27e9\n    refine' \u27e8n, f.coeff n, _\u27e9\n    ext i\n    by_cases hi : i = n\n    \u00b7 simp [hi, coeff_monomial]\n    \u00b7 have : f.coeff i = 0 := by\n        rw [\u2190 not_mem_support_iff]\n        exact fun hi' => hi (Finset.mem_singleton.1 (hn hi'))\n      simp [this, Ne.symm hi, coeff_monomial]\n  \u00b7 rintro \u27e8n, a, rfl\u27e9\n    rw [\u2190 Finset.card_singleton n]\n    apply Finset.card_le_of_subset\n    exact support_monomial' _ _\n#align polynomial.card_support_le_one_iff_monomial Polynomial.card_support_le_one_iff_monomial\n\ntheorem ringHom_ext {S} [Semiring S] {f g : R[X] \u2192+* S} (h\u2081 : \u2200 a, f (C a) = g (C a))\n    (h\u2082 : f X = g X) : f = g := by\n  set f' := f.comp (toFinsuppIso R).symm.toRingHom with hf'\n  set g' := g.comp (toFinsuppIso R).symm.toRingHom with hg'\n  have A : f' = g' := by\n    -- Porting note: Was `ext; simp [..]; simpa [..] using h\u2082`.\n    ext : 1\n    \u00b7 ext\n      simp [h\u2081, RingEquiv.toRingHom_eq_coe]\n    \u00b7 refine MonoidHom.ext_mnat ?_\n      simpa [RingEquiv.toRingHom_eq_coe] using h\u2082\n  have B : f = f'.comp (toFinsuppIso R) := by\n    rw [hf', RingHom.comp_assoc]\n    ext x\n    simp only [RingEquiv.toRingHom_eq_coe, RingEquiv.symm_apply_apply, Function.comp_apply,\n      RingHom.coe_comp, RingEquiv.coe_toRingHom]\n  have C' : g = g'.comp (toFinsuppIso R) := by\n    rw [hg', RingHom.comp_assoc]\n    ext x\n    simp only [RingEquiv.toRingHom_eq_coe, RingEquiv.symm_apply_apply, Function.comp_apply,\n      RingHom.coe_comp, RingEquiv.coe_toRingHom]\n  rw [B, C', A]\n#align polynomial.ring_hom_ext Polynomial.ringHom_ext\n\n@[ext high]\ntheorem ringHom_ext' {S} [Semiring S] {f g : R[X] \u2192+* S} (h\u2081 : f.comp C = g.comp C)\n    (h\u2082 : f X = g X) : f = g :=\n  ringHom_ext (RingHom.congr_fun h\u2081) h\u2082\n#align polynomial.ring_hom_ext' Polynomial.ringHom_ext'\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Monomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7076947580547576}}
{"text": "/-\nCopyright (c) 2020 Markus Himmel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Markus Himmel\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.category_theory.abelian.pseudoelements\nimport Mathlib.PostPort\n\nuniverses v u \n\nnamespace Mathlib\n\n/-!\n# The four lemma\n\nConsider the following commutative diagram with exact rows in an abelian category:\n\nA ---f--> B ---g--> C ---h--> D\n|         |         |         |\n\u03b1         \u03b2         \u03b3         \u03b4\n|         |         |         |\nv         v         v         v\nA' --f'-> B' --g'-> C' --h'-> D'\n\nWe prove the \"mono\" version of the four lemma: if \u03b1 is an epimorphism and \u03b2 and \u03b4 are monomorphisms,\nthen \u03b3 is a monomorphism.\n\n## Future work\n\nThe \"epi\" four lemma and the five lemma, which is then an easy corollary.\n\n## Tags\n\nfour lemma, diagram lemma, diagram chase\n-/\n\nnamespace category_theory.abelian\n\n\n/-- The four lemma, mono version. For names of objects and morphisms, consider the following\n    diagram:\n\n```\nA ---f--> B ---g--> C ---h--> D\n|         |         |         |\n\u03b1         \u03b2         \u03b3         \u03b4\n|         |         |         |\nv         v         v         v\nA' --f'-> B' --g'-> C' --h'-> D'\n```\n-/\ntheorem mono_of_epi_of_mono_of_mono {V : Type u} [category V] [abelian V] {A : V} {B : V} {C : V} {D : V} {A' : V} {B' : V} {C' : V} {D' : V} {f : A \u27f6 B} {g : B \u27f6 C} {h : C \u27f6 D} {f' : A' \u27f6 B'} {g' : B' \u27f6 C'} {h' : C' \u27f6 D'} {\u03b1 : A \u27f6 A'} {\u03b2 : B \u27f6 B'} {\u03b3 : C \u27f6 C'} {\u03b4 : D \u27f6 D'} [exact f g] [exact g h] [exact f' g'] (comm\u2081 : \u03b1 \u226b f' = f \u226b \u03b2) (comm\u2082 : \u03b2 \u226b g' = g \u226b \u03b3) (comm\u2083 : \u03b3 \u226b h' = h \u226b \u03b4) (h\u03b1 : epi \u03b1) (h\u03b2 : mono \u03b2) (h\u03b4 : mono \u03b4) : mono \u03b3 := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/category_theory/abelian/diagram_lemmas/four.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.707694757222231}}
{"text": "import measure_theory.integral.interval_integral\nimport analysis.special_functions.integrals\nimport analysis.convolution\n\nopen set filter\nopen_locale topological_space filter\n\nnoncomputable theory\n\n/- TEXT:\n.. index:: integration\n\n.. _elementary_integration:\n\nElementary Integration\n----------------------\n\nWe first focus on integration of functions on finite intervals in ``\u211d``. We can integrate\nelementary functions.\nEXAMPLES: -/\n-- QUOTE:\nopen measure_theory interval_integral\nopen_locale interval  -- this introduces the notation [a, b]\n\nexample (a b : \u211d): \u222b x in a..b, x = (b ^ 2 - a ^ 2) / 2 :=\nintegral_id\n\nexample {a b : \u211d}  (h : (0:\u211d) \u2209 [a, b]) : \u222b x in a..b, 1/x = real.log (b / a) :=\nintegral_one_div h\n-- QUOTE.\n\n/- TEXT:\nThe fundamental theorem of calculus relates integration and differentiation.\nBelow we give simplified statementa of the two parts of this theorem. The first part\nsays that integration provides an inverse to differentiation and the second one\nspecifies how to compute integrals of derivatives.\n(These two parts are very closely related, but their optimal versions,\nwhich are not shown here, are not equivalent.)\nEXAMPLES: -/\n-- QUOTE:\nexample (f : \u211d \u2192 \u211d) (hf : continuous f) (a b : \u211d) :\n  deriv (\u03bb u, \u222b (x : \u211d) in a..u, f x) b = f b :=\n(integral_has_strict_deriv_at_right\n    (hf.interval_integrable _ _) (hf.strongly_measurable_at_filter _ _)\n  hf.continuous_at).has_deriv_at.deriv\n\nexample {f : \u211d \u2192 \u211d} {a b : \u211d} {f' : \u211d \u2192 \u211d}\n  (h : \u2200 x \u2208 [a, b], has_deriv_at f (f' x) x) (h' : interval_integrable f' volume a b) :\n  \u222b y in a..b, f' y = f b - f a :=\nintegral_eq_sub_of_has_deriv_at h h'\n-- QUOTE.\n\n/- TEXT:\nConvolution is also defined in mathlib and its basic properties are proved.\nEXAMPLES: -/\n\n-- QUOTE:\nopen_locale convolution\n\nexample  (f : \u211d \u2192 \u211d) (g : \u211d \u2192 \u211d) :\n  f \u22c6 g = \u03bb x, \u222b t, (f t) * (g (x - t)) :=\nrfl\n-- QUOTE.", "meta": {"author": "avigad", "repo": "mathematics_in_lean_source", "sha": "4eeb8c43762522c1acaa7f799599609d6a48f59e", "save_path": "github-repos/lean/avigad-mathematics_in_lean_source", "path": "github-repos/lean/avigad-mathematics_in_lean_source/mathematics_in_lean_source-4eeb8c43762522c1acaa7f799599609d6a48f59e/lean_source/09_Integration_and_Measure_Theory/source_01_Elementary_Integration.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7076947566264833}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport algebra.big_operators.basic\nimport data.nat.prime\nimport data.zmod.basic\nimport ring_theory.multiplicity\nimport data.nat.periodic\nimport algebra.char_p.two\n\n/-!\n# Euler's totient function\n\nThis file defines [Euler's totient function](https://en.wikipedia.org/wiki/Euler's_totient_function)\n`nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`.\nWe prove the divisor sum formula, namely that `n` equals `\u03c6` summed over the divisors of `n`. See\n`sum_totient`. We also prove two lemmas to help compute totients, namely `totient_mul` and\n`totient_prime_pow`.\n-/\n\nopen finset\nopen_locale big_operators\n\nnamespace nat\n\n/-- Euler's totient function. This counts the number of naturals strictly less than `n` which are\ncoprime with `n`. -/\ndef totient (n : \u2115) : \u2115 := ((range n).filter n.coprime).card\n\nlocalized \"notation `\u03c6` := nat.totient\" in nat\n\n@[simp] theorem totient_zero : \u03c6 0 = 0 := rfl\n\n@[simp] theorem totient_one : \u03c6 1 = 1 :=\nby simp [totient]\n\nlemma totient_eq_card_coprime (n : \u2115) : \u03c6 n = ((range n).filter n.coprime).card := rfl\n\nlemma totient_le (n : \u2115) : \u03c6 n \u2264 n :=\ncalc totient n \u2264 (range n).card : card_filter_le _ _\n           ... = n              : card_range _\n\nlemma totient_lt (n : \u2115) (hn : 1 < n) : \u03c6 n < n :=\ncalc totient n \u2264 ((range n).filter (\u2260 0)).card :\n  begin\n    apply card_le_of_subset (monotone_filter_right _ _),\n    intros n1 hn1 hn1',\n    simpa only [hn1', coprime_zero_right, hn.ne'] using hn1,\n  end\n... = n - 1\n    : by simp only [filter_ne' (range n) 0, card_erase_of_mem, card_range, pos_of_gt hn, mem_range]\n... < n : nat.sub_lt (pos_of_gt hn) zero_lt_one\n\nlemma totient_pos : \u2200 {n : \u2115}, 0 < n \u2192 0 < \u03c6 n\n| 0 := dec_trivial\n| 1 := by simp [totient]\n| (n+2) := \u03bb h, card_pos.2 \u27e81, mem_filter.2 \u27e8mem_range.2 dec_trivial, coprime_one_right _\u27e9\u27e9\n\nlemma filter_coprime_Ico_eq_totient (a n : \u2115) :\n  ((Ico n (n+a)).filter (coprime a)).card = totient a :=\nbegin\n  rw [totient, filter_Ico_card_eq_of_periodic, count_eq_card_filter_range],\n  exact periodic_coprime a,\nend\n\nlemma Ico_filter_coprime_le {a : \u2115} (k n : \u2115) (a_pos : 0 < a) :\n  ((Ico k (k + n)).filter (coprime a)).card \u2264 totient a * (n / a + 1) :=\nbegin\n  conv_lhs { rw \u2190nat.mod_add_div n a },\n  induction n / a with i ih,\n  { rw \u2190filter_coprime_Ico_eq_totient a k,\n    simp only [add_zero, mul_one, mul_zero, le_of_lt (mod_lt n a_pos)],\n    mono,\n    refine monotone_filter_left a.coprime _,\n    simp only [finset.le_eq_subset],\n    exact Ico_subset_Ico rfl.le (add_le_add_left (le_of_lt (mod_lt n a_pos)) k), },\n  simp only [mul_succ],\n  simp_rw \u2190add_assoc at ih \u22a2,\n  calc (filter a.coprime (Ico k (k + n % a + a * i + a))).card\n      = (filter a.coprime (Ico k (k + n % a + a * i)\n                            \u222a Ico (k + n % a + a * i) (k + n % a + a * i + a))).card :\n        begin\n          congr,\n          rw Ico_union_Ico_eq_Ico,\n          rw add_assoc,\n          exact le_self_add,\n          exact le_self_add,\n        end\n  ... \u2264 (filter a.coprime (Ico k (k + n % a + a * i))).card + a.totient :\n        begin\n          rw [filter_union, \u2190filter_coprime_Ico_eq_totient a (k + n % a + a * i)],\n          apply card_union_le,\n        end\n  ... \u2264 a.totient * i + a.totient + a.totient : add_le_add_right ih (totient a),\nend\n\nopen zmod\n\n/-- Note this takes an explicit `fintype ((zmod n)\u02e3)` argument to avoid trouble with instance\ndiamonds. -/\n@[simp] lemma _root_.zmod.card_units_eq_totient (n : \u2115) [fact (0 < n)] [fintype ((zmod n)\u02e3)] :\n  fintype.card ((zmod n)\u02e3) = \u03c6 n :=\ncalc fintype.card ((zmod n)\u02e3) = fintype.card {x : zmod n // x.val.coprime n} :\n  fintype.card_congr zmod.units_equiv_coprime\n... = \u03c6 n :\nbegin\n  apply finset.card_congr (\u03bb (a : {x : zmod n // x.val.coprime n}) _, a.1.val),\n  { intro a, simp [(a : zmod n).val_lt, a.prop.symm] {contextual := tt} },\n  { intros _ _ _ _ h, rw subtype.ext_iff_val, apply val_injective, exact h, },\n  { intros b hb,\n    rw [finset.mem_filter, finset.mem_range] at hb,\n    refine \u27e8\u27e8b, _\u27e9, finset.mem_univ _, _\u27e9,\n    { let u := unit_of_coprime b hb.2.symm,\n      exact val_coe_unit_coprime u },\n    { show zmod.val (b : zmod n) = b,\n      rw [val_nat_cast, nat.mod_eq_of_lt hb.1], } }\nend\n\nlemma totient_even {n : \u2115} (hn : 2 < n) : even n.totient :=\nbegin\n  haveI : fact (1 < n) := \u27e8one_lt_two.trans hn\u27e9,\n  suffices : 2 = order_of (-1 : (zmod n)\u02e3),\n  { rw [\u2190 zmod.card_units_eq_totient, even_iff_two_dvd, this], exact order_of_dvd_card_univ },\n  rw [\u2190order_of_units, units.coe_neg_one, order_of_neg_one, ring_char.eq (zmod n) n, if_neg hn.ne'],\nend\n\nlemma totient_mul {m n : \u2115} (h : m.coprime n) : \u03c6 (m * n) = \u03c6 m * \u03c6 n :=\nif hmn0 : m * n = 0\n  then by cases nat.mul_eq_zero.1 hmn0 with h h;\n    simp only [totient_zero, mul_zero, zero_mul, h]\n  else\n  begin\n    haveI : fact (0 < (m * n)) := \u27e8nat.pos_of_ne_zero hmn0\u27e9,\n    haveI : fact (0 < m) := \u27e8nat.pos_of_ne_zero $ left_ne_zero_of_mul hmn0\u27e9,\n    haveI : fact (0 < n) := \u27e8nat.pos_of_ne_zero $ right_ne_zero_of_mul hmn0\u27e9,\n    rw [\u2190 zmod.card_units_eq_totient, \u2190 zmod.card_units_eq_totient,\n      \u2190 zmod.card_units_eq_totient, fintype.card_congr\n      (units.map_equiv (zmod.chinese_remainder h).to_mul_equiv).to_equiv,\n      fintype.card_congr (@mul_equiv.prod_units (zmod m) (zmod n) _ _).to_equiv,\n      fintype.card_prod]\n  end\n\n\n\n/-- When `p` is prime, then the totient of `p ^ (n + 1)` is `p ^ n * (p - 1)` -/\nlemma totient_prime_pow_succ {p : \u2115} (hp : p.prime) (n : \u2115) :\n  \u03c6 (p ^ (n + 1)) = p ^ n * (p - 1) :=\ncalc \u03c6 (p ^ (n + 1))\n    = ((range (p ^ (n + 1))).filter (coprime (p ^ (n + 1)))).card :\n  totient_eq_card_coprime _\n... = (range (p ^ (n + 1)) \\ ((range (p ^ n)).image (* p))).card :\n  congr_arg card begin\n    rw [sdiff_eq_filter],\n    apply filter_congr,\n    simp only [mem_range, mem_filter, coprime_pow_left_iff n.succ_pos,\n      mem_image, not_exists, hp.coprime_iff_not_dvd],\n    intros a ha,\n    split,\n    { rintros hap b _ rfl,\n      exact hap (dvd_mul_left _ _) },\n    { rintros h \u27e8b, rfl\u27e9,\n      rw [pow_succ] at ha,\n      exact h b (lt_of_mul_lt_mul_left ha (zero_le _)) (mul_comm _ _) }\n  end\n... = _ :\nhave h1 : set.inj_on (* p) (range (p ^ n)),\n  from \u03bb x _ y _, (nat.mul_left_inj hp.pos).1,\nhave h2 : (range (p ^ n)).image (* p) \u2286 range (p ^ (n + 1)),\n  from \u03bb a, begin\n    simp only [mem_image, mem_range, exists_imp_distrib],\n    rintros b h rfl,\n    rw [pow_succ'],\n    exact (mul_lt_mul_right hp.pos).2 h\n  end,\nbegin\n  rw [card_sdiff h2, card_image_of_inj_on h1, card_range,\n    card_range, \u2190 one_mul (p ^ n), pow_succ, \u2190 tsub_mul,\n    one_mul, mul_comm]\nend\n\n/-- When `p` is prime, then the totient of `p ^ n` is `p ^ (n - 1) * (p - 1)` -/\nlemma totient_prime_pow {p : \u2115} (hp : p.prime) {n : \u2115} (hn : 0 < n) :\n  \u03c6 (p ^ n) = p ^ (n - 1) * (p - 1) :=\nby rcases exists_eq_succ_of_ne_zero (pos_iff_ne_zero.1 hn) with \u27e8m, rfl\u27e9;\n  exact totient_prime_pow_succ hp _\n\nlemma totient_prime {p : \u2115} (hp : p.prime) : \u03c6 p = p - 1 :=\nby rw [\u2190 pow_one p, totient_prime_pow hp]; simp\n\nlemma totient_mul_of_prime_of_dvd {p n : \u2115} (hp : p.prime) (h : p \u2223 n) :\n  (p * n).totient = p * n.totient :=\nbegin\n  by_cases hzero : n = 0,\n  { simp [hzero] },\n  { have hfin := (multiplicity.finite_nat_iff.2 \u27e8hp.ne_one, zero_lt_iff.2 hzero\u27e9),\n    have h0 : 0 < (multiplicity p n).get hfin := multiplicity.pos_of_dvd hfin h,\n    obtain \u27e8m, hm, hndiv\u27e9 := multiplicity.exists_eq_pow_mul_and_not_dvd hfin,\n    rw [hm, \u2190 mul_assoc, \u2190 pow_succ, nat.totient_mul (coprime_comm.mp (hp.coprime_pow_of_not_dvd\n      hndiv)), nat.totient_mul (coprime_comm.mp (hp.coprime_pow_of_not_dvd hndiv)), \u2190 mul_assoc],\n    congr,\n    rw [ \u2190 succ_pred_eq_of_pos h0, totient_prime_pow_succ hp, totient_prime_pow_succ hp,\n      succ_pred_eq_of_pos h0, \u2190 mul_assoc p, \u2190 pow_succ, \u2190 succ_pred_eq_of_pos h0, nat.pred_succ] }\nend\n\nlemma totient_eq_iff_prime {p : \u2115} (hp : 0 < p) : p.totient = p - 1 \u2194 p.prime :=\nbegin\n  refine \u27e8\u03bb h, _, totient_prime\u27e9,\n  replace hp : 1 < p,\n  { apply lt_of_le_of_ne,\n    { rwa succ_le_iff },\n    { rintro rfl,\n      rw [totient_one, tsub_self] at h,\n      exact one_ne_zero h } },\n  rw [totient_eq_card_coprime, range_eq_Ico, \u2190Ico_insert_succ_left hp.le, finset.filter_insert,\n      if_neg (not_coprime_of_dvd_of_dvd hp (dvd_refl p) (dvd_zero p)), \u2190nat.card_Ico 1 p] at h,\n  refine p.prime_of_coprime hp (\u03bb n hn hnz, finset.filter_card_eq h n $ finset.mem_Ico.mpr \u27e8_, hn\u27e9),\n  rwa [succ_le_iff, pos_iff_ne_zero],\nend\n\nlemma card_units_zmod_lt_sub_one {p : \u2115} (hp : 1 < p) [fintype ((zmod p)\u02e3)] :\n  fintype.card ((zmod p)\u02e3) \u2264 p - 1 :=\nbegin\n  haveI : fact (0 < p) := \u27e8zero_lt_one.trans hp\u27e9,\n  rw zmod.card_units_eq_totient p,\n  exact nat.le_pred_of_lt (nat.totient_lt p hp),\nend\n\nlemma prime_iff_card_units (p : \u2115) [fintype ((zmod p)\u02e3)] :\n  p.prime \u2194 fintype.card ((zmod p)\u02e3) = p - 1 :=\nbegin\n  by_cases hp : p = 0,\n  { substI hp,\n    simp only [zmod, not_prime_zero, false_iff, zero_tsub],\n    -- the substI created an non-defeq but subsingleton instance diamond; resolve it\n    suffices : fintype.card \u2124\u02e3 \u2260 0, { convert this },\n    simp },\n  haveI : fact (0 < p) := \u27e8nat.pos_of_ne_zero hp\u27e9,\n  rw [zmod.card_units_eq_totient, nat.totient_eq_iff_prime (fact.out (0 < p))],\nend\n\n@[simp] lemma totient_two : \u03c6 2 = 1 :=\n(totient_prime prime_two).trans (by norm_num)\n\n/-! ### Euler's product formula for the totient function\n\nWe prove several different statements of this formula. -/\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_eq_prod_factorization {n : \u2115} (hn : n \u2260 0) :\n  \u03c6 n = n.factorization.prod (\u03bb p k, p ^ (k - 1) * (p - 1)) :=\nbegin\n  rw multiplicative_factorization \u03c6 @totient_mul totient_one hn,\n  apply finsupp.prod_congr (\u03bb p hp, _),\n  have h := zero_lt_iff.mpr (finsupp.mem_support_iff.mp hp),\n  rw [totient_prime_pow (prime_of_mem_factorization hp) h],\nend\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_mul_prod_factors (n : \u2115) :\n  \u03c6 n * \u220f p in n.factors.to_finset, p = n * \u220f p in n.factors.to_finset, (p - 1) :=\nbegin\n  by_cases hn : n = 0, { simp [hn] },\n  rw totient_eq_prod_factorization hn,\n  nth_rewrite 2 \u2190factorization_prod_pow_eq_self hn,\n  simp only [\u2190prod_factorization_eq_prod_factors, \u2190finsupp.prod_mul],\n  refine finsupp.prod_congr (\u03bb p hp, _),\n  rw [finsupp.mem_support_iff, \u2190 zero_lt_iff] at hp,\n  rw [mul_comm, \u2190mul_assoc, \u2190pow_succ, nat.sub_add_cancel hp],\nend\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_eq_div_factors_mul (n : \u2115) :\n  \u03c6 n = n / (\u220f p in n.factors.to_finset, p) * (\u220f p in n.factors.to_finset, (p - 1)) :=\nbegin\n  rw [\u2190 mul_div_left n.totient, totient_mul_prod_factors, mul_comm,\n      nat.mul_div_assoc _ (prod_prime_factors_dvd n), mul_comm],\n  simpa [prod_factorization_eq_prod_factors] using prod_pos (\u03bb p, pos_of_mem_factorization),\nend\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_eq_mul_prod_factors (n : \u2115) :\n  (\u03c6 n : \u211a) = n * \u220f p in n.factors.to_finset, (1 - p\u207b\u00b9) :=\nbegin\n  by_cases hn : n = 0, { simp [hn] },\n  have hn' : (n : \u211a) \u2260 0, { simp [hn] },\n  have hpQ : \u220f p in n.factors.to_finset, (p : \u211a) \u2260 0,\n  { rw [\u2190cast_prod, cast_ne_zero, \u2190zero_lt_iff, \u2190prod_factorization_eq_prod_factors],\n    exact prod_pos (\u03bb p hp, pos_of_mem_factorization hp) },\n  simp only [totient_eq_div_factors_mul n, prod_prime_factors_dvd n, cast_mul, cast_prod,\n      cast_dvd_char_zero, mul_comm_div', mul_right_inj' hn', div_eq_iff hpQ, \u2190prod_mul_distrib],\n  refine prod_congr rfl (\u03bb p hp, _),\n  have hp := pos_of_mem_factors (list.mem_to_finset.mp hp),\n  have hp' : (p : \u211a) \u2260 0 := cast_ne_zero.mpr hp.ne.symm,\n  rw [sub_mul, one_mul, mul_comm, mul_inv_cancel hp', cast_pred hp],\nend\n\nend nat\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/nat/totient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7076947560307354}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth\n\n! This file was ported from Lean 3 source module measure_theory.integral.periodic\n! leanprover-community/mathlib commit 6a033cb3d188a12ca5c509b33e2eaac1c61916cd\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.HaarQuotient\nimport Mathbin.MeasureTheory.Integral.IntervalIntegral\nimport Mathbin.Topology.Algebra.Order.Floor\n\n/-!\n# Integrals of periodic functions\n\nIn this file we prove that the half-open interval `Ioc t (t + T)` in `\u211d` is a fundamental domain of\nthe action of the subgroup `\u2124 \u2219 T` on `\u211d`.\n\nA consequence is `add_circle.measure_preserving_mk`: the covering map from `\u211d` to the \"additive\ncircle\" `\u211d \u29f8 (\u2124 \u2219 T)` is measure-preserving, with respect to the restriction of Lebesgue measure to\n`Ioc t (t + T)` (upstairs) and with respect to Haar measure (downstairs).\n\nAnother consequence (`function.periodic.interval_integral_add_eq` and related declarations) is that\n`\u222b x in t..t + T, f x = \u222b x in s..s + T, f x` for any (not necessarily measurable) function with\nperiod `T`.\n-/\n\n\nopen Set Function MeasureTheory MeasureTheory.Measure TopologicalSpace AddSubgroup intervalIntegral\n\nopen MeasureTheory NNReal ENNReal\n\nattribute [-instance] QuotientAddGroup.measurableSpace Quotient.measurableSpace\n\ntheorem isAddFundamentalDomainIoc {T : \u211d} (hT : 0 < T) (t : \u211d)\n    (\u03bc : Measure \u211d := by exact MeasureTheory.MeasureSpace.volume) :\n    IsAddFundamentalDomain (AddSubgroup.zmultiples T) (Ioc t (t + T)) \u03bc :=\n  by\n  refine' is_add_fundamental_domain.mk' measurable_set_Ioc.null_measurable_set fun x => _\n  have : bijective (cod_restrict (fun n : \u2124 => n \u2022 T) (AddSubgroup.zmultiples T) _) :=\n    (Equiv.ofInjective (fun n : \u2124 => n \u2022 T) (zsmul_strictMono_left hT).Injective).Bijective\n  refine' this.exists_unique_iff.2 _\n  simpa only [add_comm x] using existsUnique_add_zsmul_mem_Ioc hT x t\n#align is_add_fundamental_domain_Ioc isAddFundamentalDomainIoc\n\ntheorem isAddFundamentalDomainIoc' {T : \u211d} (hT : 0 < T) (t : \u211d)\n    (\u03bc : Measure \u211d := by exact MeasureTheory.MeasureSpace.volume) :\n    IsAddFundamentalDomain (AddSubgroup.zmultiples T).opposite (Ioc t (t + T)) \u03bc :=\n  by\n  refine' is_add_fundamental_domain.mk' measurable_set_Ioc.null_measurable_set fun x => _\n  have : bijective (cod_restrict (fun n : \u2124 => n \u2022 T) (AddSubgroup.zmultiples T) _) :=\n    (Equiv.ofInjective (fun n : \u2124 => n \u2022 T) (zsmul_strictMono_left hT).Injective).Bijective\n  refine' this.exists_unique_iff.2 _\n  simpa using existsUnique_add_zsmul_mem_Ioc hT x t\n#align is_add_fundamental_domain_Ioc' isAddFundamentalDomainIoc'\n\nnamespace AddCircle\n\nvariable (T : \u211d) [hT : Fact (0 < T)]\n\ninclude hT\n\n/-- Equip the \"additive circle\" `\u211d \u29f8 (\u2124 \u2219 T)` with, as a standard measure, the Haar measure of total\nmass `T` -/\nnoncomputable instance measureSpace : MeasureSpace (AddCircle T) :=\n  { AddCircle.measurableSpace with volume := ENNReal.ofReal T \u2022 add_haar_measure \u22a4 }\n#align add_circle.measure_space AddCircle.measureSpace\n\n@[simp]\nprotected theorem measure_univ : volume (Set.univ : Set (AddCircle T)) = ENNReal.ofReal T :=\n  by\n  dsimp [volume]\n  rw [\u2190 positive_compacts.coe_top]\n  simp [add_haar_measure_self, -positive_compacts.coe_top]\n#align add_circle.measure_univ AddCircle.measure_univ\n\ninstance : IsAddHaarMeasure (volume : Measure (AddCircle T)) :=\n  IsAddHaarMeasure.smul _ (by simp [hT.out]) ENNReal.ofReal_ne_top\n\ninstance isFiniteMeasure : IsFiniteMeasure (volume : Measure (AddCircle T))\n    where measure_univ_lt_top := by simp\n#align add_circle.is_finite_measure AddCircle.isFiniteMeasure\n\n/-- The covering map from `\u211d` to the \"additive circle\" `\u211d \u29f8 (\u2124 \u2219 T)` is measure-preserving,\nconsidered with respect to the standard measure (defined to be the Haar measure of total mass `T`)\non the additive circle, and with respect to the restriction of Lebsegue measure on `\u211d` to an\ninterval (t, t + T]. -/\nprotected theorem measurePreservingMk (t : \u211d) :\n    MeasurePreserving (coe : \u211d \u2192 AddCircle T) (volume.restrict (Ioc t (t + T))) :=\n  MeasurePreservingQuotientAddGroup.mk' (isAddFundamentalDomainIoc' hT.out t)\n    (\u22a4 : PositiveCompacts (AddCircle T)) (by simp) T.toNNReal\n    (by simp [\u2190 ENNReal.ofReal_coe_nnreal, Real.coe_toNNReal T hT.out.le])\n#align add_circle.measure_preserving_mk AddCircle.measurePreservingMk\n\ntheorem volume_closedBall {x : AddCircle T} (\u03b5 : \u211d) :\n    volume (Metric.closedBall x \u03b5) = ENNReal.ofReal (min T (2 * \u03b5)) :=\n  by\n  have hT' : |T| = T := abs_eq_self.mpr hT.out.le\n  let I := Ioc (-(T / 2)) (T / 2)\n  have h\u2081 : \u03b5 < T / 2 \u2192 Metric.closedBall (0 : \u211d) \u03b5 \u2229 I = Metric.closedBall (0 : \u211d) \u03b5 :=\n    by\n    intro h\u03b5\n    rw [inter_eq_left_iff_subset, Real.closedBall_eq_Icc, zero_sub, zero_add]\n    rintro y \u27e8hy\u2081, hy\u2082\u27e9\n    constructor <;> linarith\n  have h\u2082 :\n    coe \u207b\u00b9' Metric.closedBall (0 : AddCircle T) \u03b5 \u2229 I =\n      if \u03b5 < T / 2 then Metric.closedBall (0 : \u211d) \u03b5 else I :=\n    by\n    conv_rhs => rw [\u2190 if_ctx_congr (Iff.rfl : \u03b5 < T / 2 \u2194 \u03b5 < T / 2) h\u2081 fun _ => rfl, \u2190 hT']\n    apply coe_real_preimage_closed_ball_inter_eq\n    simpa only [hT', Real.closedBall_eq_Icc, zero_add, zero_sub] using Ioc_subset_Icc_self\n  rw [add_haar_closed_ball_center]\n  simp only [restrict_apply' measurableSet_Ioc, (by linarith : -(T / 2) + T = T / 2), h\u2082, \u2190\n    (AddCircle.measurePreservingMk T (-(T / 2))).measure_preimage measurableSet_closedBall]\n  by_cases h\u03b5 : \u03b5 < T / 2\n  \u00b7 simp [h\u03b5, min_eq_right (by linarith : 2 * \u03b5 \u2264 T)]\n  \u00b7 simp [h\u03b5, min_eq_left (by linarith : T \u2264 2 * \u03b5)]\n#align add_circle.volume_closed_ball AddCircle.volume_closedBall\n\ninstance : IsDoublingMeasure (volume : Measure (AddCircle T)) :=\n  by\n  refine' \u27e8\u27e8Real.toNNReal 2, Filter.eventually_of_forall fun \u03b5 x => _\u27e9\u27e9\n  simp only [volume_closed_ball]\n  erw [\u2190 ENNReal.ofReal_mul zero_le_two]\n  apply ENNReal.ofReal_le_ofReal\n  rw [mul_min_of_nonneg _ _ (zero_le_two : (0 : \u211d) \u2264 2)]\n  exact min_le_min (by linarith [hT.out]) (le_refl _)\n\n/-- The isomorphism `add_circle T \u2243 Ioc a (a + T)` whose inverse is the natural quotient map,\n  as an equivalence of measurable spaces. -/\nnoncomputable def measurableEquivIoc (a : \u211d) : AddCircle T \u2243\u1d50 Ioc a (a + T) :=\n  {\n    equivIoc T\n      a with\n    measurable_to_fun :=\n      measurable_of_measurable_on_compl_singleton _\n        (continuousOn_iff_continuous_restrict.mp <|\n            ContinuousAt.continuousOn fun x hx => continuousAt_equivIoc T a hx).Measurable\n    measurable_inv_fun := AddCircle.measurable_mk'.comp measurable_subtype_coe }\n#align add_circle.measurable_equiv_Ioc AddCircle.measurableEquivIoc\n\n/-- The isomorphism `add_circle T \u2243 Ico a (a + T)` whose inverse is the natural quotient map,\n  as an equivalence of measurable spaces. -/\nnoncomputable def measurableEquivIco (a : \u211d) : AddCircle T \u2243\u1d50 Ico a (a + T) :=\n  {\n    equivIco T\n      a with\n    measurable_to_fun :=\n      measurable_of_measurable_on_compl_singleton _\n        (continuousOn_iff_continuous_restrict.mp <|\n            ContinuousAt.continuousOn fun x hx => continuousAt_equivIco T a hx).Measurable\n    measurable_inv_fun := AddCircle.measurable_mk'.comp measurable_subtype_coe }\n#align add_circle.measurable_equiv_Ico AddCircle.measurableEquivIco\n\n/-- The lower integral of a function over `add_circle T` is equal to the lower integral over an\ninterval (t, t + T] in `\u211d` of its lift to `\u211d`. -/\nprotected theorem lintegral_preimage (t : \u211d) (f : AddCircle T \u2192 \u211d\u22650\u221e) :\n    (\u222b\u207b a in Ioc t (t + T), f a) = \u222b\u207b b : AddCircle T, f b :=\n  by\n  have m : MeasurableSet (Ioc t (t + T)) := measurableSet_Ioc\n  have := lintegral_map_equiv f (measurable_equiv_Ioc T t).symm\n  swap; exact volume\n  simp only [measurable_equiv_Ioc, equiv_Ioc, quotientAddGroup.equivIocMod, MeasurableEquiv.symm_mk,\n    MeasurableEquiv.coe_mk, Equiv.coe_fn_symm_mk] at this\n  rw [\u2190 (AddCircle.measurePreservingMk T t).map_eq]\n  convert this.symm using 1\n  -- TODO : there is no \"set_lintegral_eq_subtype\"?\n  \u00b7 rw [\u2190 map_comap_subtype_coe m _]\n    exact MeasurableEmbedding.lintegral_map (MeasurableEmbedding.subtype_coe m) _\n  \u00b7 congr 1\n    have : (coe : Ioc t (t + T) \u2192 AddCircle T) = (coe : \u211d \u2192 AddCircle T) \u2218 (coe : _ \u2192 \u211d) :=\n      by\n      ext1 x\n      rfl\n    simp_rw [this, \u2190 map_map AddCircle.measurable_mk' measurable_subtype_coe, \u2190\n      map_comap_subtype_coe m]\n    rfl\n#align add_circle.lintegral_preimage AddCircle.lintegral_preimage\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] [CompleteSpace E]\n\n/-- The integral of an almost-everywhere strongly measurable function over `add_circle T` is equal\nto the integral over an interval (t, t + T] in `\u211d` of its lift to `\u211d`. -/\nprotected theorem integral_preimage (t : \u211d) (f : AddCircle T \u2192 E) :\n    (\u222b a in Ioc t (t + T), f a) = \u222b b : AddCircle T, f b :=\n  by\n  have m : MeasurableSet (Ioc t (t + T)) := measurableSet_Ioc\n  have := integral_map_equiv (measurable_equiv_Ioc T t).symm f\n  simp only [measurable_equiv_Ioc, equiv_Ioc, quotientAddGroup.equivIocMod, MeasurableEquiv.symm_mk,\n    MeasurableEquiv.coe_mk, Equiv.coe_fn_symm_mk, coe_coe] at this\n  rw [\u2190 (AddCircle.measurePreservingMk T t).map_eq, set_integral_eq_subtype m, \u2190 this]\n  have : (coe : Ioc t (t + T) \u2192 AddCircle T) = (coe : \u211d \u2192 AddCircle T) \u2218 (coe : _ \u2192 \u211d) :=\n    by\n    ext1 x\n    rfl\n  simp_rw [this, \u2190 map_map AddCircle.measurable_mk' measurable_subtype_coe, \u2190\n    map_comap_subtype_coe m]\n  rfl\n#align add_circle.integral_preimage AddCircle.integral_preimage\n\n/-- The integral of an almost-everywhere strongly measurable function over `add_circle T` is equal\nto the integral over an interval (t, t + T] in `\u211d` of its lift to `\u211d`. -/\nprotected theorem intervalIntegral_preimage (t : \u211d) (f : AddCircle T \u2192 E) :\n    (\u222b a in t..t + T, f a) = \u222b b : AddCircle T, f b :=\n  by\n  rw [integral_of_le, AddCircle.integral_preimage T t f]\n  linarith [hT.out]\n#align add_circle.interval_integral_preimage AddCircle.intervalIntegral_preimage\n\nend AddCircle\n\nnamespace UnitAddCircle\n\nattribute [local instance] Real.fact_zero_lt_one\n\nnoncomputable instance measureSpace : MeasureSpace UnitAddCircle :=\n  AddCircle.measureSpace 1\n#align unit_add_circle.measure_space UnitAddCircle.measureSpace\n\n@[simp]\nprotected theorem measure_univ : volume (Set.univ : Set UnitAddCircle) = 1 := by simp\n#align unit_add_circle.measure_univ UnitAddCircle.measure_univ\n\ninstance isFiniteMeasure : IsFiniteMeasure (volume : Measure UnitAddCircle) :=\n  AddCircle.isFiniteMeasure 1\n#align unit_add_circle.is_finite_measure UnitAddCircle.isFiniteMeasure\n\n/-- The covering map from `\u211d` to the \"unit additive circle\" `\u211d \u29f8 \u2124` is measure-preserving,\nconsidered with respect to the standard measure (defined to be the Haar measure of total mass 1)\non the additive circle, and with respect to the restriction of Lebsegue measure on `\u211d` to an\ninterval (t, t + 1]. -/\nprotected theorem measurePreservingMk (t : \u211d) :\n    MeasurePreserving (coe : \u211d \u2192 UnitAddCircle) (volume.restrict (Ioc t (t + 1))) :=\n  AddCircle.measurePreservingMk 1 t\n#align unit_add_circle.measure_preserving_mk UnitAddCircle.measurePreservingMk\n\n/-- The integral of a measurable function over `unit_add_circle` is equal to the integral over an\ninterval (t, t + 1] in `\u211d` of its lift to `\u211d`. -/\nprotected theorem lintegral_preimage (t : \u211d) (f : UnitAddCircle \u2192 \u211d\u22650\u221e) :\n    (\u222b\u207b a in Ioc t (t + 1), f a) = \u222b\u207b b : UnitAddCircle, f b :=\n  AddCircle.lintegral_preimage 1 t f\n#align unit_add_circle.lintegral_preimage UnitAddCircle.lintegral_preimage\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] [CompleteSpace E]\n\n/-- The integral of an almost-everywhere strongly measurable function over `unit_add_circle` is\nequal to the integral over an interval (t, t + 1] in `\u211d` of its lift to `\u211d`. -/\nprotected theorem integral_preimage (t : \u211d) (f : UnitAddCircle \u2192 E) :\n    (\u222b a in Ioc t (t + 1), f a) = \u222b b : UnitAddCircle, f b :=\n  AddCircle.integral_preimage 1 t f\n#align unit_add_circle.integral_preimage UnitAddCircle.integral_preimage\n\n/-- The integral of an almost-everywhere strongly measurable function over `unit_add_circle` is\nequal to the integral over an interval (t, t + 1] in `\u211d` of its lift to `\u211d`. -/\nprotected theorem intervalIntegral_preimage (t : \u211d) (f : UnitAddCircle \u2192 E) :\n    (\u222b a in t..t + 1, f a) = \u222b b : UnitAddCircle, f b :=\n  AddCircle.intervalIntegral_preimage 1 t f\n#align unit_add_circle.interval_integral_preimage UnitAddCircle.intervalIntegral_preimage\n\nend UnitAddCircle\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace \u211d E] [CompleteSpace E]\n\nnamespace Function\n\nnamespace Periodic\n\nvariable {f : \u211d \u2192 E} {T : \u211d}\n\n/-- An auxiliary lemma for a more general `function.periodic.interval_integral_add_eq`. -/\ntheorem intervalIntegral_add_eq_of_pos (hf : Periodic f T) (hT : 0 < T) (t s : \u211d) :\n    (\u222b x in t..t + T, f x) = \u222b x in s..s + T, f x :=\n  by\n  simp only [integral_of_le, hT.le, le_add_iff_nonneg_right]\n  haveI : vadd_invariant_measure (AddSubgroup.zmultiples T) \u211d volume :=\n    \u27e8fun c s hs => measure_preimage_add _ _ _\u27e9\n  exact\n    (isAddFundamentalDomainIoc hT t).set_integral_eq (isAddFundamentalDomainIoc hT s)\n      hf.map_vadd_zmultiples\n#align function.periodic.interval_integral_add_eq_of_pos Function.Periodic.intervalIntegral_add_eq_of_pos\n\n/-- If `f` is a periodic function with period `T`, then its integral over `[t, t + T]` does not\ndepend on `t`. -/\ntheorem intervalIntegral_add_eq (hf : Periodic f T) (t s : \u211d) :\n    (\u222b x in t..t + T, f x) = \u222b x in s..s + T, f x :=\n  by\n  rcases lt_trichotomy 0 T with (hT | rfl | hT)\n  \u00b7 exact hf.interval_integral_add_eq_of_pos hT t s\n  \u00b7 simp\n  \u00b7 rw [\u2190 neg_inj, \u2190 integral_symm, \u2190 integral_symm]\n    simpa only [\u2190 sub_eq_add_neg, add_sub_cancel] using\n      hf.neg.interval_integral_add_eq_of_pos (neg_pos.2 hT) (t + T) (s + T)\n#align function.periodic.interval_integral_add_eq Function.Periodic.intervalIntegral_add_eq\n\n/-- If `f` is an integrable periodic function with period `T`, then its integral over `[t, s + T]`\nis the sum of its integrals over the intervals `[t, s]` and `[t, t + T]`. -/\ntheorem intervalIntegral_add_eq_add (hf : Periodic f T) (t s : \u211d)\n    (h_int : \u2200 t\u2081 t\u2082, IntervalIntegrable f MeasureSpace.volume t\u2081 t\u2082) :\n    (\u222b x in t..s + T, f x) = (\u222b x in t..s, f x) + \u222b x in t..t + T, f x := by\n  rw [hf.interval_integral_add_eq t s, integral_add_adjacent_intervals (h_int t s) (h_int s _)]\n#align function.periodic.interval_integral_add_eq_add Function.Periodic.intervalIntegral_add_eq_add\n\n/-- If `f` is an integrable periodic function with period `T`, and `n` is an integer, then its\nintegral over `[t, t + n \u2022 T]` is `n` times its integral over `[t, t + T]`. -/\ntheorem intervalIntegral_add_zsmul_eq (hf : Periodic f T) (n : \u2124) (t : \u211d)\n    (h_int : \u2200 t\u2081 t\u2082, IntervalIntegrable f MeasureSpace.volume t\u2081 t\u2082) :\n    (\u222b x in t..t + n \u2022 T, f x) = n \u2022 \u222b x in t..t + T, f x :=\n  by\n  -- Reduce to the case `b = 0`\n  suffices (\u222b x in 0 ..n \u2022 T, f x) = n \u2022 \u222b x in 0 ..T, f x by\n    simp only [hf.interval_integral_add_eq t 0, (hf.zsmul n).intervalIntegral_add_eq t 0, zero_add,\n      this]\n  -- First prove it for natural numbers\n  have : \u2200 m : \u2115, (\u222b x in 0 ..m \u2022 T, f x) = m \u2022 \u222b x in 0 ..T, f x :=\n    by\n    intros\n    induction' m with m ih\n    \u00b7 simp\n    \u00b7 simp only [succ_nsmul', hf.interval_integral_add_eq_add 0 (m \u2022 T) h_int, ih, zero_add]\n  -- Then prove it for all integers\n  cases' n with n n\n  \u00b7 simp [\u2190 this n]\n  \u00b7 conv_rhs => rw [negSucc_zsmul]\n    have h\u2080 : Int.negSucc n \u2022 T + (n + 1) \u2022 T = 0 :=\n      by\n      simp\n      linarith\n    rw [integral_symm, \u2190 (hf.nsmul (n + 1)).funext, neg_inj]\n    simp_rw [integral_comp_add_right, h\u2080, zero_add, this (n + 1), add_comm T,\n      hf.interval_integral_add_eq ((n + 1) \u2022 T) 0, zero_add]\n#align function.periodic.interval_integral_add_zsmul_eq Function.Periodic.intervalIntegral_add_zsmul_eq\n\nsection RealValued\n\nopen Filter\n\nvariable {g : \u211d \u2192 \u211d}\n\nvariable (hg : Periodic g T) (h_int : \u2200 t\u2081 t\u2082, IntervalIntegrable g MeasureSpace.volume t\u2081 t\u2082)\n\ninclude hg h_int\n\n/-- If `g : \u211d \u2192 \u211d` is periodic with period `T > 0`, then for any `t : \u211d`, the function\n`t \u21a6 \u222b x in 0..t, g x` is bounded below by `t \u21a6 X + \u230at/T\u230b \u2022 Y` for appropriate constants `X` and\n`Y`. -/\ntheorem inf\u209b_add_zsmul_le_integral_of_pos (hT : 0 < T) (t : \u211d) :\n    (inf\u209b ((fun t => \u222b x in 0 ..t, g x) '' Icc 0 T) + \u230at / T\u230b \u2022 \u222b x in 0 ..T, g x) \u2264\n      \u222b x in 0 ..t, g x :=\n  by\n  let \u03b5 := Int.fract (t / T) * T\n  conv_rhs =>\n    rw [\u2190 Int.fract_div_mul_self_add_zsmul_eq T t (by linarith), \u2190\n      integral_add_adjacent_intervals (h_int 0 \u03b5) (h_int _ _)]\n  rw [hg.interval_integral_add_zsmul_eq \u230at / T\u230b \u03b5 h_int, hg.interval_integral_add_eq \u03b5 0, zero_add,\n    add_le_add_iff_right]\n  exact\n    (continuous_primitive h_int 0).ContinuousOn.inf\u209b_image_Icc_le\n      (mem_Icc_of_Ico (Int.fract_div_mul_self_mem_Ico T t hT))\n#align function.periodic.Inf_add_zsmul_le_integral_of_pos Function.Periodic.inf\u209b_add_zsmul_le_integral_of_pos\n\n/-- If `g : \u211d \u2192 \u211d` is periodic with period `T > 0`, then for any `t : \u211d`, the function\n`t \u21a6 \u222b x in 0..t, g x` is bounded above by `t \u21a6 X + \u230at/T\u230b \u2022 Y` for appropriate constants `X` and\n`Y`. -/\ntheorem integral_le_sup\u209b_add_zsmul_of_pos (hT : 0 < T) (t : \u211d) :\n    (\u222b x in 0 ..t, g x) \u2264\n      sup\u209b ((fun t => \u222b x in 0 ..t, g x) '' Icc 0 T) + \u230at / T\u230b \u2022 \u222b x in 0 ..T, g x :=\n  by\n  let \u03b5 := Int.fract (t / T) * T\n  conv_lhs =>\n    rw [\u2190 Int.fract_div_mul_self_add_zsmul_eq T t (by linarith), \u2190\n      integral_add_adjacent_intervals (h_int 0 \u03b5) (h_int _ _)]\n  rw [hg.interval_integral_add_zsmul_eq \u230at / T\u230b \u03b5 h_int, hg.interval_integral_add_eq \u03b5 0, zero_add,\n    add_le_add_iff_right]\n  exact\n    (continuous_primitive h_int 0).ContinuousOn.le_sup\u209b_image_Icc\n      (mem_Icc_of_Ico (Int.fract_div_mul_self_mem_Ico T t hT))\n#align function.periodic.integral_le_Sup_add_zsmul_of_pos Function.Periodic.integral_le_sup\u209b_add_zsmul_of_pos\n\n/-- If `g : \u211d \u2192 \u211d` is periodic with period `T > 0` and `0 < \u222b x in 0..T, g x`, then\n`t \u21a6 \u222b x in 0..t, g x` tends to `\u221e` as `t` tends to `\u221e`. -/\ntheorem tendsto_atTop_intervalIntegral_of_pos (h\u2080 : 0 < \u222b x in 0 ..T, g x) (hT : 0 < T) :\n    Tendsto (fun t => \u222b x in 0 ..t, g x) atTop atTop :=\n  by\n  apply tendsto_at_top_mono (hg.Inf_add_zsmul_le_integral_of_pos h_int hT)\n  apply at_top.tendsto_at_top_add_const_left (Inf <| (fun t => \u222b x in 0 ..t, g x) '' Icc 0 T)\n  apply tendsto.at_top_zsmul_const h\u2080\n  exact tendsto_floor_at_top.comp (tendsto_id.at_top_mul_const (inv_pos.mpr hT))\n#align function.periodic.tendsto_at_top_interval_integral_of_pos Function.Periodic.tendsto_atTop_intervalIntegral_of_pos\n\n/-- If `g : \u211d \u2192 \u211d` is periodic with period `T > 0` and `0 < \u222b x in 0..T, g x`, then\n`t \u21a6 \u222b x in 0..t, g x` tends to `-\u221e` as `t` tends to `-\u221e`. -/\ntheorem tendsto_atBot_intervalIntegral_of_pos (h\u2080 : 0 < \u222b x in 0 ..T, g x) (hT : 0 < T) :\n    Tendsto (fun t => \u222b x in 0 ..t, g x) atBot atBot :=\n  by\n  apply tendsto_at_bot_mono (hg.integral_le_Sup_add_zsmul_of_pos h_int hT)\n  apply at_bot.tendsto_at_bot_add_const_left (Sup <| (fun t => \u222b x in 0 ..t, g x) '' Icc 0 T)\n  apply tendsto.at_bot_zsmul_const h\u2080\n  exact tendsto_floor_at_bot.comp (tendsto_id.at_bot_mul_const (inv_pos.mpr hT))\n#align function.periodic.tendsto_at_bot_interval_integral_of_pos Function.Periodic.tendsto_atBot_intervalIntegral_of_pos\n\n/-- If `g : \u211d \u2192 \u211d` is periodic with period `T > 0` and `\u2200 x, 0 < g x`, then `t \u21a6 \u222b x in 0..t, g x`\ntends to `\u221e` as `t` tends to `\u221e`. -/\ntheorem tendsto_atTop_intervalIntegral_of_pos' (h\u2080 : \u2200 x, 0 < g x) (hT : 0 < T) :\n    Tendsto (fun t => \u222b x in 0 ..t, g x) atTop atTop :=\n  hg.tendsto_atTop_intervalIntegral_of_pos h_int (intervalIntegral_pos_of_pos (h_int 0 T) h\u2080 hT) hT\n#align function.periodic.tendsto_at_top_interval_integral_of_pos' Function.Periodic.tendsto_atTop_intervalIntegral_of_pos'\n\n/-- If `g : \u211d \u2192 \u211d` is periodic with period `T > 0` and `\u2200 x, 0 < g x`, then `t \u21a6 \u222b x in 0..t, g x`\ntends to `-\u221e` as `t` tends to `-\u221e`. -/\ntheorem tendsto_atBot_intervalIntegral_of_pos' (h\u2080 : \u2200 x, 0 < g x) (hT : 0 < T) :\n    Tendsto (fun t => \u222b x in 0 ..t, g x) atBot atBot :=\n  hg.tendsto_atBot_intervalIntegral_of_pos h_int (intervalIntegral_pos_of_pos (h_int 0 T) h\u2080 hT) hT\n#align function.periodic.tendsto_at_bot_interval_integral_of_pos' Function.Periodic.tendsto_atBot_intervalIntegral_of_pos'\n\nend RealValued\n\nend Periodic\n\nend Function\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Integral/Periodic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7076947554349875}}
{"text": "/-\nCopyright (c) 2022 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n\n! This file was ported from Lean 3 source module combinatorics.simple_graph.acyclic\n! leanprover-community/mathlib commit b07688016d62f81d14508ff339ea3415558d6353\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Combinatorics.SimpleGraph.Connectivity\n\n/-!\n\n# Acyclic graphs and trees\n\nThis module introduces *acyclic graphs* (a.k.a. *forests*) and *trees*.\n\n## Main definitions\n\n* `SimpleGraph.IsAcyclic` is a predicate for a graph having no cyclic walks\n* `SimpleGraph.IsTree` is a predicate for a graph being a tree (a connected acyclic graph)\n\n## Main statements\n\n* `SimpleGraph.isAcyclic_iff_path_unique` characterizes acyclicity in terms of uniqueness of\n  paths between pairs of vertices.\n* `SimpleGraph.isAcyclic_iff_forall_edge_isBridge` characterizes acyclicity in terms of every\n  edge being a bridge edge.\n* `SimpleGraph.isTree_iff_existsUnique_path` characterizes trees in terms of existence and\n  uniqueness of paths between pairs of vertices from a nonempty vertex type.\n\n## References\n\nThe structure of the proofs for `SimpleGraph.IsAcyclic` and `SimpleGraph.IsTree`, including\nsupporting lemmas about `SimpleGraph.IsBridge`, generally follows the high-level description\nfor these theorems for multigraphs from [Chou1994].\n\n## Tags\n\nacyclic graphs, trees\n-/\n\n\nuniverse u v\n\nnamespace SimpleGraph\n\nvariable {V : Type u} (G : SimpleGraph V)\n\n/-- A graph is *acyclic* (or a *forest*) if it has no cycles. -/\ndef IsAcyclic : Prop := \u2200 \u2983v : V\u2984 (c : G.Walk v v), \u00acc.IsCycle\n#align simple_graph.is_acyclic SimpleGraph.IsAcyclic\n\n/-- A *tree* is a connected acyclic graph. -/\n@[mk_iff]\nstructure IsTree : Prop where\n  /-- Graph is connected. -/\n  protected isConnected : G.Connected\n  /-- Graph is acyclic. -/\n  protected IsAcyclic : G.IsAcyclic\n#align simple_graph.is_tree SimpleGraph.IsTree\n\nvariable {G}\n\ntheorem isAcyclic_iff_forall_adj_isBridge :\n    G.IsAcyclic \u2194 \u2200 \u2983v w : V\u2984, G.Adj v w \u2192 G.IsBridge \u27e6(v, w)\u27e7 := by\n  simp_rw [isBridge_iff_adj_and_forall_cycle_not_mem]\n  constructor\n  \u00b7 intro ha v w hvw\n    apply And.intro hvw\n    intro u p hp\n    cases ha p hp\n  \u00b7 rintro hb v (_ | \u27e8ha, p\u27e9) hp\n    \u00b7 exact hp.not_of_nil\n    \u00b7 apply (hb ha).2 _ hp\n      rw [Walk.edges_cons]\n      apply List.mem_cons_self\n#align simple_graph.is_acyclic_iff_forall_adj_is_bridge SimpleGraph.isAcyclic_iff_forall_adj_isBridge\n\ntheorem isAcyclic_iff_forall_edge_isBridge :\n    G.IsAcyclic \u2194 \u2200 \u2983e\u2984, e \u2208 (G.edgeSet) \u2192 G.IsBridge e := by\n  simp [isAcyclic_iff_forall_adj_isBridge, Sym2.forall]\n#align simple_graph.is_acyclic_iff_forall_edge_is_bridge SimpleGraph.isAcyclic_iff_forall_edge_isBridge\n\ntheorem IsAcyclic.path_unique {G : SimpleGraph V} (h : G.IsAcyclic) {v w : V} (p q : G.Path v w) :\n    p = q := by\n  obtain \u27e8p, hp\u27e9 := p\n  obtain \u27e8q, hq\u27e9 := q\n  rw [Subtype.mk.injEq]\n  induction p with\n  | nil =>\n    cases (Walk.isPath_iff_eq_nil _).mp hq\n    rfl\n  | cons ph p ih =>\n    rw [isAcyclic_iff_forall_adj_isBridge] at h\n    specialize h ph\n    rw [isBridge_iff_adj_and_forall_walk_mem_edges] at h\n    replace h := h.2 (q.append p.reverse)\n    simp only [Walk.edges_append, Walk.edges_reverse, List.mem_append, List.mem_reverse'] at h\n    cases' h with h h\n    \u00b7 cases q with\n      | nil => simp [Walk.isPath_def] at hp\n      | cons _ q =>\n        rw [Walk.cons_isPath_iff] at hp hq\n        simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h\n        rcases h with (\u27e8h, rfl\u27e9 | \u27e8rfl, rfl\u27e9) | h\n        \u00b7 cases ih hp.1 q hq.1\n          rfl\n        \u00b7 simp at hq\n        \u00b7 exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2\n    \u00b7 rw [Walk.cons_isPath_iff] at hp\n      exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hp.2\n#align simple_graph.is_acyclic.path_unique SimpleGraph.IsAcyclic.path_unique\n\ntheorem isAcyclic_of_path_unique (h : \u2200 (v w : V) (p q : G.Path v w), p = q) : G.IsAcyclic := by\n  intro v c hc\n  simp only [Walk.isCycle_def, Ne.def] at hc\n  cases c with\n  | nil => cases hc.2.1 rfl\n  | cons ha c' =>\n    simp only [Walk.cons_isTrail_iff, Walk.support_cons, List.tail_cons, true_and_iff] at hc\n    specialize h _ _ \u27e8c', by simp only [Walk.isPath_def, hc.2]\u27e9 (Path.singleton ha.symm)\n    rw [Path.singleton, Subtype.mk.injEq] at h\n    simp [h] at hc\n#align simple_graph.is_acyclic_of_path_unique SimpleGraph.isAcyclic_of_path_unique\n\ntheorem isAcyclic_iff_path_unique : G.IsAcyclic \u2194 \u2200 \u2983v w : V\u2984 (p q : G.Path v w), p = q :=\n  \u27e8IsAcyclic.path_unique, isAcyclic_of_path_unique\u27e9\n#align simple_graph.is_acyclic_iff_path_unique SimpleGraph.isAcyclic_iff_path_unique\n\ntheorem isTree_iff_existsUnique_path :\n    G.IsTree \u2194 Nonempty V \u2227 \u2200 v w : V, \u2203! p : G.Walk v w, p.IsPath := by\n  classical\n  rw [IsTree_iff, isAcyclic_iff_path_unique]\n  constructor\n  \u00b7 rintro \u27e8hc, hu\u27e9\n    refine \u27e8hc.nonempty, ?_\u27e9\n    intro v w\n    let q := (hc v w).some.toPath\n    use q\n    simp only [true_and_iff, Path.isPath]\n    intro p hp\n    specialize hu \u27e8p, hp\u27e9 q\n    exact Subtype.ext_iff.mp hu\n  \u00b7 rintro \u27e8hV, h\u27e9\n    refine \u27e8Connected.mk ?_, ?_\u27e9\n    \u00b7 intro v w\n      obtain \u27e8p, _\u27e9 := h v w\n      exact p.reachable\n    \u00b7 rintro v w \u27e8p, hp\u27e9 \u27e8q, hq\u27e9\n      simp only [ExistsUnique.unique (h v w) hp hq]\n#align simple_graph.is_tree_iff_exists_unique_path SimpleGraph.isTree_iff_existsUnique_path\n\nend SimpleGraph\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/SimpleGraph/Acyclic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.707694749599699}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.finset.basic\nimport Mathlib.data.multiset.nat_antidiagonal\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# The \"antidiagonal\" {(0,n), (1,n-1), ..., (n,0)} as a finset.\n-/\n\nnamespace finset\n\n\nnamespace nat\n\n\n/-- The antidiagonal of a natural number `n` is\n    the finset of pairs `(i,j)` such that `i+j = n`. -/\ndef antidiagonal (n : \u2115) : finset (\u2115 \u00d7 \u2115) :=\n  mk (multiset.nat.antidiagonal n) (multiset.nat.nodup_antidiagonal n)\n\n/-- A pair (i,j) is contained in the antidiagonal of `n` if and only if `i+j=n`. -/\n@[simp] theorem mem_antidiagonal {n : \u2115} {x : \u2115 \u00d7 \u2115} :\n    x \u2208 antidiagonal n \u2194 prod.fst x + prod.snd x = n :=\n  sorry\n\n/-- The cardinality of the antidiagonal of `n` is `n+1`. -/\n@[simp] theorem card_antidiagonal (n : \u2115) : card (antidiagonal n) = n + 1 := sorry\n\n/-- The antidiagonal of `0` is the list `[(0,0)]` -/\n@[simp] theorem antidiagonal_zero : antidiagonal 0 = singleton (0, 0) := rfl\n\ntheorem antidiagonal_succ {n : \u2115} :\n    antidiagonal (n + 1) =\n        insert (0, n + 1)\n          (map\n            (function.embedding.prod_map (function.embedding.mk Nat.succ nat.succ_injective)\n              (function.embedding.refl \u2115))\n            (antidiagonal n)) :=\n  sorry\n\ntheorem map_swap_antidiagonal {n : \u2115} :\n    map (function.embedding.mk prod.swap (function.right_inverse.injective prod.swap_right_inverse))\n          (antidiagonal n) =\n        antidiagonal n :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/finset/nat_antidiagonal_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.707680075892885}}
{"text": "/-\nCopyright (c) 2019 Yury Kudriashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudriashov\n-/\nimport algebra.big_operators.order\nimport analysis.convex.hull\nimport linear_algebra.affine_space.basis\n\n/-!\n# Convex combinations\n\nThis file defines convex combinations of points in a vector space.\n\n## Main declarations\n\n* `finset.center_mass`: Center of mass of a finite family of points.\n\n## Implementation notes\n\nWe divide by the sum of the weights in the definition of `finset.center_mass` because of the way\nmathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few\nlemmas unconditional on the sum of the weights being `1`.\n-/\n\nopen set\nopen_locale big_operators classical\n\nuniverses u u'\nvariables {R E F \u03b9 \u03b9' : Type*} [linear_ordered_field R] [add_comm_group E] [add_comm_group F]\n  [module R E] [module R F] {s : set E}\n\n/-- Center of mass of a finite collection of points with prescribed weights.\nNote that we require neither `0 \u2264 w i` nor `\u2211 w = 1`. -/\ndef finset.center_mass (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E) : E :=\n(\u2211 i in t, w i)\u207b\u00b9 \u2022 (\u2211 i in t, w i \u2022 z i)\n\nvariables (i j : \u03b9) (c : R) (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n\nopen finset\n\nlemma finset.center_mass_empty : (\u2205 : finset \u03b9).center_mass w z = 0 :=\nby simp only [center_mass, sum_empty, smul_zero]\n\nlemma finset.center_mass_pair (hne : i \u2260 j) :\n  ({i, j} : finset \u03b9).center_mass w z = (w i / (w i + w j)) \u2022 z i + (w j / (w i + w j)) \u2022 z j :=\nby simp only [center_mass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul]\n\nvariable {w}\n\nlemma finset.center_mass_insert (ha : i \u2209 t) (hw : \u2211 j in t, w j \u2260 0) :\n  (insert i t).center_mass w z = (w i / (w i + \u2211 j in t, w j)) \u2022 z i +\n    ((\u2211 j in t, w j) / (w i + \u2211 j in t, w j)) \u2022 t.center_mass w z :=\nbegin\n  simp only [center_mass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, \u2190 div_eq_inv_mul],\n  congr' 2,\n  rw [div_mul_eq_mul_div, mul_inv_cancel hw, one_div]\nend\n\nlemma finset.center_mass_singleton (hw : w i \u2260 0) : ({i} : finset \u03b9).center_mass w z = z i :=\nby rw [center_mass, sum_singleton, sum_singleton, \u2190 mul_smul, inv_mul_cancel hw, one_smul]\n\nlemma finset.center_mass_eq_of_sum_1 (hw : \u2211 i in t, w i = 1) :\n  t.center_mass w z = \u2211 i in t, w i \u2022 z i :=\nby simp only [finset.center_mass, hw, inv_one, one_smul]\n\nlemma finset.center_mass_smul : t.center_mass w (\u03bb i, c \u2022 z i) = c \u2022 t.center_mass w z :=\nby simp only [finset.center_mass, finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc]\n\n/-- A convex combination of two centers of mass is a center of mass as well. This version\ndeals with two different index types. -/\nlemma finset.center_mass_segment'\n  (s : finset \u03b9) (t : finset \u03b9') (ws : \u03b9 \u2192 R) (zs : \u03b9 \u2192 E) (wt : \u03b9' \u2192 R) (zt : \u03b9' \u2192 E)\n  (hws : \u2211 i in s, ws i = 1) (hwt : \u2211 i in t, wt i = 1) (a b : R) (hab : a + b = 1) :\n  a \u2022 s.center_mass ws zs + b \u2022 t.center_mass wt zt =\n    (s.map function.embedding.inl \u222a t.map function.embedding.inr).center_mass\n      (sum.elim (\u03bb i, a * ws i) (\u03bb j, b * wt j))\n      (sum.elim zs zt) :=\nbegin\n  rw [s.center_mass_eq_of_sum_1 _ hws, t.center_mass_eq_of_sum_1 _ hwt,\n    smul_sum, smul_sum, \u2190 finset.sum_sum_elim, finset.center_mass_eq_of_sum_1],\n  { congr' with \u27e8\u27e9; simp only [sum.elim_inl, sum.elim_inr, mul_smul] },\n  { rw [sum_sum_elim, \u2190 mul_sum, \u2190 mul_sum, hws, hwt, mul_one, mul_one, hab] }\nend\n\n/-- A convex combination of two centers of mass is a center of mass as well. This version\nworks if two centers of mass share the set of original points. -/\nlemma finset.center_mass_segment\n  (s : finset \u03b9) (w\u2081 w\u2082 : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n  (hw\u2081 : \u2211 i in s, w\u2081 i = 1) (hw\u2082 : \u2211 i in s, w\u2082 i = 1) (a b : R) (hab : a + b = 1) :\n  a \u2022 s.center_mass w\u2081 z + b \u2022 s.center_mass w\u2082 z =\n    s.center_mass (\u03bb i, a * w\u2081 i + b * w\u2082 i) z :=\nhave hw : \u2211 i in s, (a * w\u2081 i + b * w\u2082 i) = 1,\n  by simp only [mul_sum.symm, sum_add_distrib, mul_one, *],\nby simp only [finset.center_mass_eq_of_sum_1, smul_sum, sum_add_distrib, add_smul, mul_smul, *]\n\nlemma finset.center_mass_ite_eq (hi : i \u2208 t) :\n  t.center_mass (\u03bb j, if (i = j) then (1 : R) else 0) z = z i :=\nbegin\n  rw [finset.center_mass_eq_of_sum_1],\n  transitivity \u2211 j in t, if (i = j) then z i else 0,\n  { congr' with i, split_ifs, exacts [h \u25b8 one_smul _ _, zero_smul _ _] },\n  { rw [sum_ite_eq, if_pos hi] },\n  { rw [sum_ite_eq, if_pos hi] }\nend\n\nvariables {t w}\n\nlemma finset.center_mass_subset {t' : finset \u03b9} (ht : t \u2286 t')\n  (h : \u2200 i \u2208 t', i \u2209 t \u2192 w i = 0) :\n  t.center_mass w z = t'.center_mass w z :=\nbegin\n  rw [center_mass, sum_subset ht h, smul_sum, center_mass, smul_sum],\n  apply sum_subset ht,\n  assume i hit' hit,\n  rw [h i hit' hit, zero_smul, smul_zero]\nend\n\nlemma finset.center_mass_filter_ne_zero :\n  (t.filter (\u03bb i, w i \u2260 0)).center_mass w z = t.center_mass w z :=\nfinset.center_mass_subset z (filter_subset _ _) $ \u03bb i hit hit',\n  by simpa only [hit, mem_filter, true_and, ne.def, not_not] using hit'\n\nvariable {z}\n\n/-- The center of mass of a finite subset of a convex set belongs to the set\nprovided that all weights are non-negative, and the total weight is positive. -/\nlemma convex.center_mass_mem (hs : convex R s) :\n  (\u2200 i \u2208 t, 0 \u2264 w i) \u2192 (0 < \u2211 i in t, w i) \u2192 (\u2200 i \u2208 t, z i \u2208 s) \u2192 t.center_mass w z \u2208 s :=\nbegin\n  induction t using finset.induction with i t hi ht, { simp [lt_irrefl] },\n  intros h\u2080 hpos hmem,\n  have zi : z i \u2208 s, from hmem _ (mem_insert_self _ _),\n  have hs\u2080 : \u2200 j \u2208 t, 0 \u2264 w j, from \u03bb j hj, h\u2080 j $ mem_insert_of_mem hj,\n  rw [sum_insert hi] at hpos,\n  by_cases hsum_t : \u2211 j in t, w j = 0,\n  { have ws : \u2200 j \u2208 t, w j = 0, from (sum_eq_zero_iff_of_nonneg hs\u2080).1 hsum_t,\n    have wz : \u2211 j in t, w j \u2022 z j = 0, from sum_eq_zero (\u03bb i hi, by simp [ws i hi]),\n    simp only [center_mass, sum_insert hi, wz, hsum_t, add_zero],\n    simp only [hsum_t, add_zero] at hpos,\n    rw [\u2190 mul_smul, inv_mul_cancel (ne_of_gt hpos), one_smul],\n    exact zi },\n  { rw [finset.center_mass_insert _ _ _ hi hsum_t],\n    refine convex_iff_div.1 hs zi (ht hs\u2080 _ _) _ (sum_nonneg hs\u2080) hpos,\n    { exact lt_of_le_of_ne (sum_nonneg hs\u2080) (ne.symm hsum_t) },\n    { intros j hj, exact hmem j (mem_insert_of_mem hj) },\n    { exact h\u2080 _ (mem_insert_self _ _) } }\nend\n\nlemma convex.sum_mem (hs : convex R s) (h\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (h\u2081 : \u2211 i in t, w i = 1)\n  (hz : \u2200 i \u2208 t, z i \u2208 s) :\n  \u2211 i in t, w i \u2022 z i \u2208 s :=\nby simpa only [h\u2081, center_mass, inv_one, one_smul] using\n  hs.center_mass_mem h\u2080 (h\u2081.symm \u25b8 zero_lt_one) hz\n\nlemma convex_iff_sum_mem :\n  convex R s \u2194\n    (\u2200 (t : finset E) (w : E \u2192 R),\n      (\u2200 i \u2208 t, 0 \u2264 w i) \u2192 \u2211 i in t, w i = 1 \u2192 (\u2200 x \u2208 t, x \u2208 s) \u2192 \u2211 x in t, w x \u2022 x \u2208 s ) :=\nbegin\n  refine \u27e8\u03bb hs t w hw\u2080 hw\u2081 hts, hs.sum_mem hw\u2080 hw\u2081 hts, _\u27e9,\n  intros h x y hx hy a b ha hb hab,\n  by_cases h_cases: x = y,\n  { rw [h_cases, \u2190add_smul, hab, one_smul], exact hy },\n  { convert h {x, y} (\u03bb z, if z = y then b else a) _ _ _,\n    { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl] },\n    { simp_intros i hi,\n      cases hi; subst i; simp [ha, hb, if_neg h_cases] },\n    { simp only [sum_pair h_cases, if_neg h_cases, if_pos rfl, hab] },\n    { simp_intros i hi,\n      cases hi; subst i; simp [hx, hy, if_neg h_cases] } }\nend\n\nlemma finset.center_mass_mem_convex_hull (t : finset \u03b9) {w : \u03b9 \u2192 R} (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (hws : 0 < \u2211 i in t, w i) {z : \u03b9 \u2192 E} (hz : \u2200 i \u2208 t, z i \u2208 s) :\n  t.center_mass w z \u2208 convex_hull R s :=\n(convex_convex_hull R s).center_mass_mem hw\u2080 hws (\u03bb i hi, subset_convex_hull R s $ hz i hi)\n\n/-- A refinement of `finset.center_mass_mem_convex_hull` when the indexed family is a `finset` of\nthe space. -/\nlemma finset.center_mass_id_mem_convex_hull (t : finset E) {w : E \u2192 R} (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i)\n  (hws : 0 < \u2211 i in t, w i) :\n  t.center_mass w id \u2208 convex_hull R (t : set E) :=\nt.center_mass_mem_convex_hull hw\u2080 hws (\u03bb i, mem_coe.2)\n\nlemma affine_combination_eq_center_mass {\u03b9 : Type*} {t : finset \u03b9} {p : \u03b9 \u2192 E} {w : \u03b9 \u2192 R}\n  (hw\u2082 : \u2211 i in t, w i = 1) :\n  affine_combination t p w = center_mass t w p :=\nbegin\n  rw [affine_combination_eq_weighted_vsub_of_point_vadd_of_sum_eq_one _ w _ hw\u2082 (0 : E),\n    finset.weighted_vsub_of_point_apply, vadd_eq_add, add_zero, t.center_mass_eq_of_sum_1 _ hw\u2082],\n  simp_rw [vsub_eq_sub, sub_zero],\nend\n\nlemma affine_combination_mem_convex_hull\n  {s : finset \u03b9} {v : \u03b9 \u2192 E} {w : \u03b9 \u2192 R} (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : s.sum w = 1) :\n  s.affine_combination v w \u2208 convex_hull R (range v) :=\nbegin\n  rw affine_combination_eq_center_mass hw\u2081,\n  apply s.center_mass_mem_convex_hull hw\u2080,\n  { simp [hw\u2081], },\n  { simp, },\nend\n\n/-- The centroid can be regarded as a center of mass. -/\n@[simp] lemma finset.centroid_eq_center_mass (s : finset \u03b9) (hs : s.nonempty) (p : \u03b9 \u2192 E) :\n  s.centroid R p = s.center_mass (s.centroid_weights R) p :=\naffine_combination_eq_center_mass (s.sum_centroid_weights_eq_one_of_nonempty R hs)\n\nlemma finset.centroid_mem_convex_hull (s : finset E) (hs : s.nonempty) :\n  s.centroid R id \u2208 convex_hull R (s : set E) :=\nbegin\n  rw s.centroid_eq_center_mass hs,\n  apply s.center_mass_id_mem_convex_hull,\n  { simp only [inv_nonneg, implies_true_iff, nat.cast_nonneg, finset.centroid_weights_apply], },\n  { have hs_card : (s.card : R) \u2260 0, { simp [finset.nonempty_iff_ne_empty.mp hs] },\n    simp only [hs_card, finset.sum_const, nsmul_eq_mul, mul_inv_cancel, ne.def, not_false_iff,\n      finset.centroid_weights_apply, zero_lt_one] }\nend\n\nlemma convex_hull_range_eq_exists_affine_combination (v : \u03b9 \u2192 E) :\n  convex_hull R (range v) = { x | \u2203 (s : finset \u03b9) (w : \u03b9 \u2192 R)\n    (hw\u2080 : \u2200 i \u2208 s, 0 \u2264 w i) (hw\u2081 : s.sum w = 1), s.affine_combination v w = x } :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    obtain \u27e8i, hi\u27e9 := set.mem_range.mp hx,\n    refine \u27e8{i}, function.const \u03b9 (1 : R), by simp, by simp, by simp [hi]\u27e9, },\n  { rw convex,\n    rintros x y \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9 \u27e8s', w', hw\u2080', hw\u2081', rfl\u27e9 a b ha hb hab,\n    let W : \u03b9 \u2192 R := \u03bb i, (if i \u2208 s then a * w i else 0) + (if i \u2208 s' then b * w' i else 0),\n    have hW\u2081 : (s \u222a s').sum W = 1,\n    { rw [sum_add_distrib, \u2190 sum_subset (subset_union_left s s'),\n        \u2190 sum_subset (subset_union_right s s'), sum_ite_of_true _ _ (\u03bb i hi, hi),\n        sum_ite_of_true _ _ (\u03bb i hi, hi), \u2190 mul_sum, \u2190 mul_sum, hw\u2081, hw\u2081', \u2190 add_mul, hab, mul_one];\n      intros i hi hi';\n      simp [hi'], },\n    refine \u27e8s \u222a s', W, _, hW\u2081, _\u27e9,\n    { rintros i -,\n      by_cases hi : i \u2208 s;\n      by_cases hi' : i \u2208 s';\n      simp [hi, hi', add_nonneg, mul_nonneg ha (hw\u2080 i _), mul_nonneg hb (hw\u2080' i _)], },\n    { simp_rw [affine_combination_eq_linear_combination (s \u222a s') v _ hW\u2081,\n        affine_combination_eq_linear_combination s v w hw\u2081,\n        affine_combination_eq_linear_combination s' v w' hw\u2081', add_smul, sum_add_distrib],\n      rw [\u2190 sum_subset (subset_union_left s s'), \u2190 sum_subset (subset_union_right s s')],\n      { simp only [ite_smul, sum_ite_of_true _ _ (\u03bb i hi, hi), mul_smul, \u2190 smul_sum], },\n      { intros i hi hi', simp [hi'], },\n      { intros i hi hi', simp [hi'], }, }, },\n  { rintros x \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9,\n    exact affine_combination_mem_convex_hull hw\u2080 hw\u2081, },\nend\n\n/-- Convex hull of `s` is equal to the set of all centers of masses of `finset`s `t`, `z '' t \u2286 s`.\nThis version allows finsets in any type in any universe. -/\nlemma convex_hull_eq (s : set E) :\n  convex_hull R s = {x : E | \u2203 (\u03b9 : Type u') (t : finset \u03b9) (w : \u03b9 \u2192 R) (z : \u03b9 \u2192 E)\n    (hw\u2080 : \u2200 i \u2208 t, 0 \u2264 w i) (hw\u2081 : \u2211 i in t, w i = 1) (hz : \u2200 i \u2208 t, z i \u2208 s),\n    t.center_mass w z = x} :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    use [punit, {punit.star}, \u03bb _, 1, \u03bb _, x, \u03bb _ _, zero_le_one,\n      finset.sum_singleton, \u03bb _ _, hx],\n    simp only [finset.center_mass, finset.sum_singleton, inv_one, one_smul] },\n  { rintros x y \u27e8\u03b9, sx, wx, zx, hwx\u2080, hwx\u2081, hzx, rfl\u27e9 \u27e8\u03b9', sy, wy, zy, hwy\u2080, hwy\u2081, hzy, rfl\u27e9\n      a b ha hb hab,\n    rw [finset.center_mass_segment' _ _ _ _ _ _ hwx\u2081 hwy\u2081 _ _ hab],\n    refine \u27e8_, _, _, _, _, _, _, rfl\u27e9,\n    { rintros i hi,\n      rw [finset.mem_union, finset.mem_map, finset.mem_map] at hi,\n      rcases hi with \u27e8j, hj, rfl\u27e9|\u27e8j, hj, rfl\u27e9;\n        simp only [sum.elim_inl, sum.elim_inr];\n        apply_rules [mul_nonneg, hwx\u2080, hwy\u2080] },\n    { simp [finset.sum_sum_elim, finset.mul_sum.symm, *] },\n    { intros i hi,\n      rw [finset.mem_union, finset.mem_map, finset.mem_map] at hi,\n      rcases hi with \u27e8j, hj, rfl\u27e9|\u27e8j, hj, rfl\u27e9; apply_rules [hzx, hzy] } },\n  { rintros _ \u27e8\u03b9, t, w, z, hw\u2080, hw\u2081, hz, rfl\u27e9,\n    exact t.center_mass_mem_convex_hull hw\u2080 (hw\u2081.symm \u25b8 zero_lt_one) hz }\nend\n\nlemma finset.convex_hull_eq (s : finset E) :\n  convex_hull R \u2191s = {x : E | \u2203 (w : E \u2192 R) (hw\u2080 : \u2200 y \u2208 s, 0 \u2264 w y) (hw\u2081 : \u2211 y in s, w y = 1),\n    s.center_mass w id = x} :=\nbegin\n  refine subset.antisymm (convex_hull_min _ _) _,\n  { intros x hx,\n    rw [finset.mem_coe] at hx,\n    refine \u27e8_, _, _, finset.center_mass_ite_eq _ _ _ hx\u27e9,\n    { intros, split_ifs, exacts [zero_le_one, le_refl 0] },\n    { rw [finset.sum_ite_eq, if_pos hx] } },\n  { rintros x y \u27e8wx, hwx\u2080, hwx\u2081, rfl\u27e9 \u27e8wy, hwy\u2080, hwy\u2081, rfl\u27e9\n      a b ha hb hab,\n    rw [finset.center_mass_segment _ _ _ _ hwx\u2081 hwy\u2081 _ _ hab],\n    refine \u27e8_, _, _, rfl\u27e9,\n    { rintros i hi,\n      apply_rules [add_nonneg, mul_nonneg, hwx\u2080, hwy\u2080], },\n    { simp only [finset.sum_add_distrib, finset.mul_sum.symm, mul_one, *] } },\n  { rintros _ \u27e8w, hw\u2080, hw\u2081, rfl\u27e9,\n    exact s.center_mass_mem_convex_hull (\u03bb x hx, hw\u2080 _ hx)\n      (hw\u2081.symm \u25b8 zero_lt_one) (\u03bb x hx, hx) }\nend\n\nlemma set.finite.convex_hull_eq {s : set E} (hs : finite s) :\n  convex_hull R s = {x : E | \u2203 (w : E \u2192 R) (hw\u2080 : \u2200 y \u2208 s, 0 \u2264 w y)\n    (hw\u2081 : \u2211 y in hs.to_finset, w y = 1), hs.to_finset.center_mass w id = x} :=\nby simpa only [set.finite.coe_to_finset, set.finite.mem_to_finset, exists_prop]\n  using hs.to_finset.convex_hull_eq\n\n/-- A weak version of Carath\u00e9odory's theorem. -/\nlemma convex_hull_eq_union_convex_hull_finite_subsets (s : set E) :\n  convex_hull R s = \u22c3 (t : finset E) (w : \u2191t \u2286 s), convex_hull R \u2191t :=\nbegin\n  refine subset.antisymm _ _,\n  { rw convex_hull_eq,\n    rintros x \u27e8\u03b9, t, w, z, hw\u2080, hw\u2081, hz, rfl\u27e9,\n    simp only [mem_Union],\n    refine \u27e8t.image z, _, _\u27e9,\n    { rw [coe_image, set.image_subset_iff],\n      exact hz },\n    { apply t.center_mass_mem_convex_hull hw\u2080,\n      { simp only [hw\u2081, zero_lt_one] },\n      { exact \u03bb i hi, finset.mem_coe.2 (finset.mem_image_of_mem _ hi) } } },\n  { exact Union_subset (\u03bb i, Union_subset convex_hull_mono), },\nend\n\nlemma convex_hull_prod (s : set E) (t : set F) :\n  convex_hull R (s.prod t) = (convex_hull R s).prod (convex_hull R t) :=\nbegin\n  refine set.subset.antisymm _ _,\n  { exact convex_hull_min (set.prod_mono (subset_convex_hull _ _) $ subset_convex_hull _ _)\n    ((convex_convex_hull _ _).prod $ convex_convex_hull _ _) },\n  rintro \u27e8x, y\u27e9 \u27e8hx, hy\u27e9,\n  rw convex_hull_eq at \u22a2 hx hy,\n  obtain \u27e8\u03b9, a, w, S, hw, hw', hS, hSp\u27e9 := hx,\n  obtain \u27e8\u03ba, b, v, T, hv, hv', hT, hTp\u27e9 := hy,\n  have h_sum : \u2211 (i : \u03b9 \u00d7 \u03ba) in a.product b, w i.fst * v i.snd = 1,\n  { rw [finset.sum_product, \u2190 hw'],\n    congr,\n    ext i,\n    have : \u2211 (y : \u03ba) in b, w i * v y = \u2211 (y : \u03ba) in b, v y * w i,\n    { congr, ext, simp [mul_comm] },\n    rw [this, \u2190 finset.sum_mul, hv'],\n    simp },\n  refine \u27e8\u03b9 \u00d7 \u03ba, a.product b, \u03bb p, (w p.1) * (v p.2), \u03bb p, (S p.1, T p.2),\n    \u03bb p hp, _, h_sum, \u03bb p hp, _, _\u27e9,\n  { rw mem_product at hp,\n    exact mul_nonneg (hw p.1 hp.1) (hv p.2 hp.2) },\n  { rw mem_product at hp,\n    exact \u27e8hS p.1 hp.1, hT p.2 hp.2\u27e9 },\n  ext,\n  { rw [\u2190hSp, finset.center_mass_eq_of_sum_1 _ _ hw', finset.center_mass_eq_of_sum_1 _ _ h_sum],\n    simp_rw [prod.fst_sum, prod.smul_mk],\n    rw finset.sum_product,\n    congr,\n    ext i,\n    have : \u2211 (j : \u03ba) in b, (w i * v j) \u2022 S i = \u2211 (j : \u03ba) in b, v j \u2022 w i \u2022 S i,\n    { congr, ext, rw [mul_smul, smul_comm] },\n    rw [this, \u2190finset.sum_smul, hv', one_smul] },\n  { rw [\u2190hTp, finset.center_mass_eq_of_sum_1 _ _ hv', finset.center_mass_eq_of_sum_1 _ _ h_sum],\n    simp_rw [prod.snd_sum, prod.smul_mk],\n    rw [finset.sum_product, finset.sum_comm],\n    congr,\n    ext j,\n    simp_rw mul_smul,\n    rw [\u2190finset.sum_smul, hw', one_smul] }\nend\n\n/-! ### `std_simplex` -/\n\nvariables (\u03b9) [fintype \u03b9] {f : \u03b9 \u2192 R}\n\n/-- `std_simplex \ud835\udd5c \u03b9` is the convex hull of the canonical basis in `\u03b9 \u2192 \ud835\udd5c`. -/\nlemma convex_hull_basis_eq_std_simplex :\n  convex_hull R (range $ \u03bb(i j:\u03b9), if i = j then (1:R) else 0) = std_simplex R \u03b9 :=\nbegin\n  refine subset.antisymm (convex_hull_min _ (convex_std_simplex R \u03b9)) _,\n  { rintros _ \u27e8i, rfl\u27e9,\n    exact ite_eq_mem_std_simplex R i },\n  { rintros w \u27e8hw\u2080, hw\u2081\u27e9,\n    rw [pi_eq_sum_univ w, \u2190 finset.univ.center_mass_eq_of_sum_1 _ hw\u2081],\n    exact finset.univ.center_mass_mem_convex_hull (\u03bb i hi, hw\u2080 i)\n      (hw\u2081.symm \u25b8 zero_lt_one) (\u03bb i hi, mem_range_self i) }\nend\n\nvariable {\u03b9}\n\n/-- The convex hull of a finite set is the image of the standard simplex in `s \u2192 \u211d`\nunder the linear map sending each function `w` to `\u2211 x in s, w x \u2022 x`.\n\nSince we have no sums over finite sets, we use sum over `@finset.univ _ hs.fintype`.\nThe map is defined in terms of operations on `(s \u2192 \u211d) \u2192\u2097[\u211d] \u211d` so that later we will not need\nto prove that this map is linear. -/\nlemma set.finite.convex_hull_eq_image {s : set E} (hs : finite s) :\n  convex_hull R s = by haveI := hs.fintype; exact\n    (\u21d1(\u2211 x : s, (@linear_map.proj R s _ (\u03bb i, R) _ _ x).smul_right x.1)) '' (std_simplex R s) :=\nbegin\n  rw [\u2190 convex_hull_basis_eq_std_simplex, \u2190 linear_map.convex_hull_image, \u2190 set.range_comp, (\u2218)],\n  apply congr_arg,\n  convert subtype.range_coe.symm,\n  ext x,\n  simp [linear_map.sum_apply, ite_smul, finset.filter_eq]\nend\n\n/-- All values of a function `f \u2208 std_simplex \ud835\udd5c \u03b9` belong to `[0, 1]`. -/\nlemma mem_Icc_of_mem_std_simplex (hf : f \u2208 std_simplex R \u03b9) (x) :\n  f x \u2208 Icc (0 : R) 1 :=\n\u27e8hf.1 x, hf.2 \u25b8 finset.single_le_sum (\u03bb y hy, hf.1 y) (finset.mem_univ x)\u27e9\n\n/-- The convex hull of an affine basis is the intersection of the half-spaces defined by the\ncorresponding barycentric coordinates. -/\nlemma convex_hull_affine_basis_eq_nonneg_barycentric {\u03b9 : Type*} (b : affine_basis \u03b9 R E) :\n  convex_hull R (range b.points) = { x | \u2200 i, 0 \u2264 b.coord i x } :=\nbegin\n  rw convex_hull_range_eq_exists_affine_combination,\n  ext x,\n  split,\n  { rintros \u27e8s, w, hw\u2080, hw\u2081, rfl\u27e9 i,\n    by_cases hi : i \u2208 s,\n    { rw b.coord_apply_combination_of_mem hi hw\u2081,\n      exact hw\u2080 i hi, },\n    { rw b.coord_apply_combination_of_not_mem hi hw\u2081, }, },\n  { intros hx,\n    have hx' : x \u2208 affine_span R (range b.points),\n    { rw b.tot, exact affine_subspace.mem_top R E x, },\n    obtain \u27e8s, w, hw\u2081, rfl\u27e9 := (mem_affine_span_iff_eq_affine_combination R E).mp hx',\n    refine \u27e8s, w, _, hw\u2081, rfl\u27e9,\n    intros i hi,\n    specialize hx i,\n    rw b.coord_apply_combination_of_mem hi hw\u2081 at hx,\n    exact hx, },\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/convex/combination.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7076800751370772}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\nimport combinatorics.simple_graph.basic\nimport algebra.big_operators.basic\nimport data.nat.parity\nimport data.zmod.parity\n\n/-!\n# Degree-sum formula and handshaking lemma\n\nThe degree-sum formula is that the sum of the degrees of the vertices in\na finite graph is equal to twice the number of edges.  The handshaking lemma,\na corollary, is that the number of odd-degree vertices is even.\n\n## Main definitions\n\n- `simple_graph.sum_degrees_eq_twice_card_edges` is the degree-sum formula.\n- `simple_graph.even_card_odd_degree_vertices` is the handshaking lemma.\n- `simple_graph.odd_card_odd_degree_vertices_ne` is that the number of odd-degree\n  vertices different from a given odd-degree vertex is odd.\n- `simple_graph.exists_ne_odd_degree_of_exists_odd_degree` is that the existence of an\n  odd-degree vertex implies the existence of another one.\n\n## Implementation notes\n\nWe give a combinatorial proof by using the facts that (1) the map from\ndarts to vertices is such that each fiber has cardinality the degree\nof the corresponding vertex and that (2) the map from darts to edges is 2-to-1.\n\n## Tags\n\nsimple graphs, sums, degree-sum formula, handshaking lemma\n-/\nopen finset\n\nopen_locale big_operators\n\nnamespace simple_graph\nuniverses u\nvariables {V : Type u} (G : simple_graph V)\n\nsection degree_sum\nvariables [fintype V] [decidable_rel G.adj]\n\nlemma dart_fst_fiber [decidable_eq V] (v : V) :\n  univ.filter (\u03bb d : G.dart, d.fst = v) = univ.image (G.dart_of_neighbor_set v) :=\nbegin\n  ext d,\n  simp only [mem_image, true_and, mem_filter, set_coe.exists, mem_univ, exists_prop_of_true],\n  split,\n  { rintro rfl,\n    exact \u27e8_, d.is_adj, by ext; refl\u27e9, },\n  { rintro \u27e8e, he, rfl\u27e9,\n    refl, },\nend\n\nlemma dart_fst_fiber_card_eq_degree [decidable_eq V] (v : V) :\n  (univ.filter (\u03bb d : G.dart, d.fst = v)).card = G.degree v :=\nby simpa only [dart_fst_fiber, finset.card_univ, card_neighbor_set_eq_degree]\n     using card_image_of_injective univ (G.dart_of_neighbor_set_injective v)\n\nlemma dart_card_eq_sum_degrees : fintype.card G.dart = \u2211 v, G.degree v :=\nbegin\n  haveI := classical.dec_eq V,\n  simp only [\u2190card_univ, \u2190dart_fst_fiber_card_eq_degree],\n  exact card_eq_sum_card_fiberwise (by simp),\nend\n\nvariables {G} [decidable_eq V]\n\nlemma dart.edge_fiber (d : G.dart) :\n  (univ.filter (\u03bb (d' : G.dart), d'.edge = d.edge)) = {d, d.symm} :=\nfinset.ext (\u03bb d', by simpa using dart_edge_eq_iff d' d)\n\nvariables (G)\n\nlemma dart_edge_fiber_card (e : sym2 V) (h : e \u2208 G.edge_set) :\n  (univ.filter (\u03bb (d : G.dart), d.edge = e)).card = 2 :=\nbegin\n  refine sym2.ind (\u03bb v w h, _) e h,\n  let d : G.dart := \u27e8(v, w), h\u27e9,\n  convert congr_arg card d.edge_fiber,\n  rw [card_insert_of_not_mem, card_singleton],\n  rw [mem_singleton],\n  exact d.symm_ne.symm,\nend\n\nlemma dart_card_eq_twice_card_edges : fintype.card G.dart = 2 * G.edge_finset.card :=\nbegin\n  rw \u2190card_univ,\n  rw @card_eq_sum_card_fiberwise _ _ _ dart.edge _ G.edge_finset\n    (\u03bb d h, by { rw mem_edge_finset, apply dart.edge_mem }),\n  rw [\u2190mul_comm, sum_const_nat],\n  intros e h,\n  apply G.dart_edge_fiber_card e,\n  rwa \u2190mem_edge_finset,\nend\n\n/-- The degree-sum formula.  This is also known as the handshaking lemma, which might\nmore specifically refer to `simple_graph.even_card_odd_degree_vertices`. -/\ntheorem sum_degrees_eq_twice_card_edges : \u2211 v, G.degree v = 2 * G.edge_finset.card :=\nG.dart_card_eq_sum_degrees.symm.trans G.dart_card_eq_twice_card_edges\n\nend degree_sum\n\n/-- The handshaking lemma.  See also `simple_graph.sum_degrees_eq_twice_card_edges`. -/\ntheorem even_card_odd_degree_vertices [fintype V] [decidable_rel G.adj] :\n  even (univ.filter (\u03bb v, odd (G.degree v))).card :=\nbegin\n  classical,\n  have h := congr_arg ((\u03bb n, \u2191n) : \u2115 \u2192 zmod 2) G.sum_degrees_eq_twice_card_edges,\n  simp only [zmod.nat_cast_self, zero_mul, nat.cast_mul] at h,\n  rw [nat.cast_sum, \u2190sum_filter_ne_zero] at h,\n  rw @sum_congr _ _ _ _ (\u03bb v, (G.degree v : zmod 2)) (\u03bb v, (1 : zmod 2)) _ rfl at h,\n  { simp only [filter_congr_decidable, mul_one, nsmul_eq_mul, sum_const, ne.def] at h,\n    rw \u2190zmod.eq_zero_iff_even,\n    convert h,\n    ext v,\n    rw \u2190zmod.ne_zero_iff_odd,\n    congr' },\n  { intros v,\n    simp only [true_and, mem_filter, mem_univ, ne.def],\n    rw [zmod.eq_zero_iff_even, zmod.eq_one_iff_odd, nat.odd_iff_not_even, imp_self],\n    trivial }\nend\n\nlemma odd_card_odd_degree_vertices_ne [fintype V] [decidable_eq V] [decidable_rel G.adj]\n  (v : V) (h : odd (G.degree v)) :\n  odd (univ.filter (\u03bb w, w \u2260 v \u2227 odd (G.degree w))).card :=\nbegin\n  rcases G.even_card_odd_degree_vertices with \u27e8k, hg\u27e9,\n  have hk : 0 < k,\n  { have hh : (filter (\u03bb (v : V), odd (G.degree v)) univ).nonempty,\n    { use v,\n      simp only [true_and, mem_filter, mem_univ],\n      use h, },\n    rwa [\u2190card_pos, hg, \u2190 two_mul, zero_lt_mul_left] at hh,\n    exact zero_lt_two, },\n  have hc : (\u03bb (w : V), w \u2260 v \u2227 odd (G.degree w)) = (\u03bb (w : V), odd (G.degree w) \u2227 w \u2260 v),\n  { ext w,\n    rw and_comm, },\n  simp only [hc, filter_congr_decidable],\n  rw [\u2190filter_filter, filter_ne', card_erase_of_mem],\n  { refine \u27e8k - 1, tsub_eq_of_eq_add $ hg.trans _\u27e9,\n    rw [add_assoc, one_add_one_eq_two, \u2190nat.mul_succ, \u2190 two_mul],\n    congr,\n    exact (tsub_add_cancel_of_le $ nat.succ_le_iff.2 hk).symm },\n  { simpa only [true_and, mem_filter, mem_univ] },\nend\n\nlemma exists_ne_odd_degree_of_exists_odd_degree [fintype V] [decidable_rel G.adj]\n  (v : V) (h : odd (G.degree v)) :\n  \u2203 (w : V), w \u2260 v \u2227 odd (G.degree w) :=\nbegin\n  haveI := classical.dec_eq V,\n  rcases G.odd_card_odd_degree_vertices_ne v h with \u27e8k, hg\u27e9,\n  have hg' : (filter (\u03bb (w : V), w \u2260 v \u2227 odd (G.degree w)) univ).card > 0,\n  { rw hg,\n    apply nat.succ_pos, },\n  rcases card_pos.mp hg' with \u27e8w, hw\u27e9,\n  simp only [true_and, mem_filter, mem_univ, ne.def] at hw,\n  exact \u27e8w, hw\u27e9,\nend\n\nend simple_graph\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/combinatorics/simple_graph/degree_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7076800677053763}}
{"text": "/-\nCopyright (c) 2020 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport algebra.polynomial.big_operators\nimport analysis.complex.roots_of_unity\nimport data.polynomial.lifts\nimport field_theory.separable\nimport field_theory.splitting_field\nimport number_theory.arithmetic_function\nimport ring_theory.roots_of_unity\nimport field_theory.ratfunc\n\n/-!\n# Cyclotomic polynomials.\n\nFor `n : \u2115` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic\npolynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `\u220f (X - \u03bc)`, where `\u03bc` varies\nover the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then\nthis the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R`\nwith coefficients in any ring `R`.\n\n## Main definition\n\n* `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`.\n\n## Main results\n\n* `int_coeff_of_cycl` : If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K`\ncomes from a polynomial with integer coefficients.\n* `deg_of_cyclotomic` : The degree of `cyclotomic n` is `totient n`.\n* `prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = \u220f (cyclotomic i)`, where `i` divides `n`.\n* `cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The M\u00f6bius inversion formula for\n  `cyclotomic n R` over an abstract fraction field for `polynomial R`.\n* `cyclotomic.irreducible` : `cyclotomic n \u2124` is irreducible.\n\n## Implementation details\n\nOur definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting\nresults hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is\nnot the standard one unless there is a primitive `n`th root of unity in `R`. For example,\n`cyclotomic' 3 \u2124 = 1`, since there are no primitive cube roots of unity in `\u2124`. The main example is\n`R = \u2102`, we decided to work in general since the difficulties are essentially the same.\nTo get the standard cyclotomic polynomials, we use `int_coeff_of_cycl`, with `R = \u2102`, to get a\npolynomial with integer coefficients and then we map it to `polynomial R`, for any ring `R`.\nTo prove `cyclotomic.irreducible`, the irreducibility of `cyclotomic n \u2124`, we show in\n`cyclotomic_eq_minpoly` that `cyclotomic n \u2124` is the minimal polynomial of any `n`-th primitive root\nof unity `\u03bc : K`, where `K` is a field of characteristic `0`.\n-/\n\nopen_locale classical big_operators\nnoncomputable theory\n\nuniverse u\n\nnamespace polynomial\n\nsection cyclotomic'\n\nsection is_domain\n\nvariables {R : Type*} [comm_ring R] [is_domain R]\n\n/-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic\npolynomial if there is a primitive `n`-th root of unity in `R`. -/\ndef cyclotomic' (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] : polynomial R :=\n\u220f \u03bc in primitive_roots n R, (X - C \u03bc)\n\n/-- The zeroth modified cyclotomic polyomial is `1`. -/\n@[simp] lemma cyclotomic'_zero\n  (R : Type*) [comm_ring R] [is_domain R] : cyclotomic' 0 R = 1 :=\nby simp only [cyclotomic', finset.prod_empty, is_primitive_root.primitive_roots_zero]\n\n/-- The first modified cyclotomic polyomial is `X - 1`. -/\n@[simp] lemma cyclotomic'_one\n  (R : Type*) [comm_ring R] [is_domain R] : cyclotomic' 1 R = X - 1 :=\nbegin\n  simp only [cyclotomic', finset.prod_singleton, ring_hom.map_one,\n  is_primitive_root.primitive_roots_one]\nend\n\n/-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/\n@[simp] lemma cyclotomic'_two\n  (R : Type*) [comm_ring R] [is_domain R] (p : \u2115) [char_p R p] (hp : p \u2260 2) :\n  cyclotomic' 2 R = X + 1 :=\nbegin\n  rw [cyclotomic'],\n  have prim_root_two : primitive_roots 2 R = {(-1 : R)},\n  { apply finset.eq_singleton_iff_unique_mem.2,\n    split,\n    { simp only [is_primitive_root.neg_one p hp, nat.succ_pos', mem_primitive_roots] },\n    { intros x hx,\n      rw [mem_primitive_roots zero_lt_two] at hx,\n      exact is_primitive_root.eq_neg_one_of_two_right hx } },\n  simp only [prim_root_two, finset.prod_singleton, ring_hom.map_neg, ring_hom.map_one,\n  sub_neg_eq_add]\nend\n\n/-- `cyclotomic' n R` is monic. -/\nlemma cyclotomic'.monic\n  (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] : (cyclotomic' n R).monic :=\nmonic_prod_of_monic _ _ $ \u03bb z hz, monic_X_sub_C _\n\n/-- `cyclotomic' n R` is different from `0`. -/\nlemma cyclotomic'_ne_zero\n  (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] : cyclotomic' n R \u2260 0 :=\n(cyclotomic'.monic n R).ne_zero\n\n/-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of\nunity in `R`. -/\nlemma nat_degree_cyclotomic' {\u03b6 : R} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  (cyclotomic' n R).nat_degree = nat.totient n :=\nbegin\n  cases nat.eq_zero_or_pos n with hzero hpos,\n  { simp only [hzero, cyclotomic'_zero, nat.totient_zero, nat_degree_one] },\n  rw [cyclotomic'],\n  rw nat_degree_prod (primitive_roots n R) (\u03bb (z : R), (X - C z)),\n  simp only [is_primitive_root.card_primitive_roots h hpos, mul_one,\n  nat_degree_X_sub_C,\n  nat.cast_id, finset.sum_const, nsmul_eq_mul],\n  intros z hz,\n  exact X_sub_C_ne_zero z\nend\n\n/-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/\nlemma degree_cyclotomic' {\u03b6 : R} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  (cyclotomic' n R).degree = nat.totient n :=\nby simp only [degree_eq_nat_degree (cyclotomic'_ne_zero n R), nat_degree_cyclotomic' h]\n\n/-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/\nlemma roots_of_cyclotomic (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] :\n  (cyclotomic' n R).roots = (primitive_roots n R).val :=\nby { rw cyclotomic', exact roots_prod_X_sub_C (primitive_roots n R) }\n\nend is_domain\n\nsection field\n\nvariables {K : Type*} [field K]\n\n/-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = \u220f (X - \u03bc)`, where `\u03bc`\nvaries over the `n`-th roots of unity. -/\nlemma X_pow_sub_one_eq_prod {\u03b6 : K} {n : \u2115} (hpos : 0 < n) (h : is_primitive_root \u03b6 n) :\n  X ^ n - 1 = \u220f \u03b6 in nth_roots_finset n K, (X - C \u03b6) :=\nbegin\n  rw [nth_roots_finset, \u2190 multiset.to_finset_eq (is_primitive_root.nth_roots_nodup h)],\n  simp only [finset.prod_mk, ring_hom.map_one],\n  rw [nth_roots],\n  have hmonic : (X ^ n - C (1 : K)).monic := monic_X_pow_sub_C (1 : K) (ne_of_lt hpos).symm,\n  symmetry,\n  apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic,\n  rw [@nat_degree_X_pow_sub_C K _ _ n 1, \u2190 nth_roots],\n  exact is_primitive_root.card_nth_roots h\nend\n\n/-- `cyclotomic' n K` splits. -/\nlemma cyclotomic'_splits (n : \u2115) : splits (ring_hom.id K) (cyclotomic' n K) :=\nbegin\n  apply splits_prod (ring_hom.id K),\n  intros z hz,\n  simp only [splits_X_sub_C (ring_hom.id K)]\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1`splits. -/\nlemma X_pow_sub_one_splits {\u03b6 : K} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  splits (ring_hom.id K) (X ^ n - C (1 : K)) :=\nby rw [splits_iff_card_roots, \u2190 nth_roots, is_primitive_root.card_nth_roots h,\n    nat_degree_X_pow_sub_C]\n\n/-- If there is a primitive `n`-th root of unity in `K`, then\n`\u220f i in nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/\nlemma prod_cyclotomic'_eq_X_pow_sub_one {\u03b6 : K} {n : \u2115} (hpos : 0 < n) (h : is_primitive_root \u03b6 n) :\n  \u220f i in nat.divisors n, cyclotomic' i K = X ^ n - 1 :=\nbegin\n  rw [X_pow_sub_one_eq_prod hpos h],\n  have rwcyc : \u2200 i \u2208 nat.divisors n, cyclotomic' i K = \u220f \u03bc in primitive_roots i K, (X - C \u03bc),\n  { intros i hi,\n    simp only [cyclotomic'] },\n  conv_lhs { apply_congr,\n             skip,\n             simp [rwcyc, H] },\n  rw \u2190 finset.prod_bUnion,\n  { simp only [is_primitive_root.nth_roots_one_eq_bUnion_primitive_roots hpos h] },\n  intros x hx y hy hdiff,\n  rw finset.mem_coe at hx hy,\n  exact is_primitive_root.disjoint (nat.pos_of_mem_divisors hx) (nat.pos_of_mem_divisors hy) hdiff,\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then\n`cyclotomic' n K = (X ^ k - 1) /\u2098 (\u220f i in nat.proper_divisors k, cyclotomic' i K)`. -/\nlemma cyclotomic'_eq_X_pow_sub_one_div {\u03b6 : K} {n : \u2115} (hpos: 0 < n) (h : is_primitive_root \u03b6 n) :\n  cyclotomic' n K = (X ^ n - 1) /\u2098 (\u220f i in nat.proper_divisors n, cyclotomic' i K) :=\nbegin\n  rw [\u2190prod_cyclotomic'_eq_X_pow_sub_one hpos h,\n  nat.divisors_eq_proper_divisors_insert_self_of_pos hpos,\n  finset.prod_insert nat.proper_divisors.not_self_mem],\n  have prod_monic : (\u220f i in nat.proper_divisors n, cyclotomic' i K).monic,\n  { apply monic_prod_of_monic,\n    intros i hi,\n    exact cyclotomic'.monic i K },\n  rw (div_mod_by_monic_unique (cyclotomic' n K) 0 prod_monic _).1,\n  simp only [degree_zero, zero_add],\n  refine \u27e8by rw mul_comm, _\u27e9,\n  rw [bot_lt_iff_ne_bot],\n  intro h,\n  exact monic.ne_zero prod_monic (degree_eq_bot.1 h)\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a\nmonic polynomial with integer coefficients. -/\nlemma int_coeff_of_cyclotomic' {\u03b6 : K} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  (\u2203 (P : polynomial \u2124), map (int.cast_ring_hom K) P = cyclotomic' n K \u2227\n  P.degree = (cyclotomic' n K).degree \u2227 P.monic) :=\nbegin\n  refine lifts_and_degree_eq_and_monic _ (cyclotomic'.monic n K),\n  induction n using nat.strong_induction_on with k hk generalizing \u03b6 h,\n  cases nat.eq_zero_or_pos k with hzero hpos,\n  { use 1,\n    simp only [hzero, cyclotomic'_zero, set.mem_univ, subsemiring.coe_top, eq_self_iff_true,\n    coe_map_ring_hom, map_one, and_self] },\n  let B : polynomial K := \u220f i in nat.proper_divisors k, cyclotomic' i K,\n  have Bmo : B.monic,\n  { apply monic_prod_of_monic,\n    intros i hi,\n    exact (cyclotomic'.monic i K) },\n  have Bint : B \u2208 lifts (int.cast_ring_hom K),\n  { refine subsemiring.prod_mem (lifts (int.cast_ring_hom K)) _,\n    intros x hx,\n    have xsmall := (nat.mem_proper_divisors.1 hx).2,\n    obtain \u27e8d, hd\u27e9 := (nat.mem_proper_divisors.1 hx).1,\n    rw [mul_comm] at hd,\n    exact hk x xsmall (is_primitive_root.pow hpos h hd) },\n  replace Bint := lifts_and_degree_eq_and_monic Bint Bmo,\n  obtain \u27e8B\u2081, hB\u2081, hB\u2081deg, hB\u2081mo\u27e9 := Bint,\n  let Q\u2081 : polynomial \u2124 := (X ^ k - 1) /\u2098 B\u2081,\n  have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 \u2227 (0 : polynomial K).degree < B.degree,\n  { split,\n    { rw [zero_add, mul_comm, \u2190(prod_cyclotomic'_eq_X_pow_sub_one hpos h),\n      nat.divisors_eq_proper_divisors_insert_self_of_pos hpos],\n      simp only [true_and, finset.prod_insert, not_lt, nat.mem_proper_divisors, dvd_refl] },\n    rw [degree_zero, bot_lt_iff_ne_bot],\n    intro habs,\n    exact (monic.ne_zero Bmo) (degree_eq_bot.1 habs) },\n  replace huniq := div_mod_by_monic_unique (cyclotomic' k K) (0 : polynomial K) Bmo huniq,\n  simp only [lifts, ring_hom.mem_srange],\n  use Q\u2081,\n  rw [coe_map_ring_hom, (map_div_by_monic (int.cast_ring_hom K) hB\u2081mo), hB\u2081, \u2190 huniq.1],\n  simp\nend\n\n/-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`,\nthen `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/\nlemma unique_int_coeff_of_cycl [char_zero K] {\u03b6 : K} {n : \u2115+} (h : is_primitive_root \u03b6 n) :\n  (\u2203! (P : polynomial \u2124), map (int.cast_ring_hom K) P = cyclotomic' n K) :=\nbegin\n  obtain \u27e8P, hP\u27e9 := int_coeff_of_cyclotomic' h,\n  refine \u27e8P, hP.1, \u03bb Q hQ, _\u27e9,\n  apply (map_injective (int.cast_ring_hom K) int.cast_injective),\n  rw [hP.1, hQ]\nend\n\nend field\n\nend cyclotomic'\n\nsection cyclotomic\n\n/-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/\ndef cyclotomic (n : \u2115) (R : Type*) [ring R] : polynomial R :=\nif h : n = 0 then 1 else\n  map (int.cast_ring_hom R) ((int_coeff_of_cyclotomic' (complex.is_primitive_root_exp n h)).some)\n\nlemma int_cyclotomic_rw {n : \u2115} (h : n \u2260 0) :\n  cyclotomic n \u2124 = (int_coeff_of_cyclotomic' (complex.is_primitive_root_exp n h)).some :=\nbegin\n  simp only [cyclotomic, h, dif_neg, not_false_iff],\n  ext i,\n  simp only [coeff_map, int.cast_id, ring_hom.eq_int_cast]\nend\n\n/-- `cyclotomic n R` comes from `cyclotomic n \u2124`. -/\nlemma map_cyclotomic_int (n : \u2115) (R : Type*) [ring R] :\n  map (int.cast_ring_hom R) (cyclotomic n \u2124) = cyclotomic n R :=\nbegin\n  by_cases hzero : n = 0,\n  { simp only [hzero, cyclotomic, dif_pos, map_one] },\n  simp only [cyclotomic, int_cyclotomic_rw, hzero, ne.def, dif_neg, not_false_iff]\nend\n\nlemma int_cyclotomic_spec (n : \u2115) : map (int.cast_ring_hom \u2102) (cyclotomic n \u2124) = cyclotomic' n \u2102 \u2227\n  (cyclotomic n \u2124).degree = (cyclotomic' n \u2102).degree \u2227 (cyclotomic n \u2124).monic  :=\nbegin\n  by_cases hzero : n = 0,\n  { simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos,\n  eq_self_iff_true, map_one, and_self] },\n  rw int_cyclotomic_rw hzero,\n  exact (int_coeff_of_cyclotomic' (complex.is_primitive_root_exp n hzero)).some_spec\nend\n\nlemma int_cyclotomic_unique {n : \u2115} {P : polynomial \u2124} (h : map (int.cast_ring_hom \u2102) P =\n  cyclotomic' n \u2102) : P = cyclotomic n \u2124 :=\nbegin\n  apply map_injective (int.cast_ring_hom \u2102) int.cast_injective,\n  rw [h, (int_cyclotomic_spec n).1]\nend\n\n/-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/\n@[simp] lemma map_cyclotomic (n : \u2115) {R S : Type*} [ring R] [ring S] (f : R \u2192+* S) :\n  map f (cyclotomic n R) = cyclotomic n S :=\nbegin\n  rw [\u2190map_cyclotomic_int n R, \u2190map_cyclotomic_int n S],\n  ext i,\n  simp only [coeff_map, ring_hom.eq_int_cast, ring_hom.map_int_cast]\nend\n\n/-- The zeroth cyclotomic polyomial is `1`. -/\n@[simp] lemma cyclotomic_zero (R : Type*) [ring R] : cyclotomic 0 R = 1 :=\nby simp only [cyclotomic, dif_pos]\n\n/-- The first cyclotomic polyomial is `X - 1`. -/\n@[simp] lemma cyclotomic_one (R : Type*) [ring R] : cyclotomic 1 R = X - 1 :=\nbegin\n  have hspec : map (int.cast_ring_hom \u2102) (X - 1) = cyclotomic' 1 \u2102,\n  { simp only [cyclotomic'_one, pnat.one_coe, map_X, map_one, map_sub] },\n  symmetry,\n  rw [\u2190map_cyclotomic_int, \u2190(int_cyclotomic_unique hspec)],\n  simp only [map_X, map_one, map_sub]\nend\n\n/-- The second cyclotomic polyomial is `X + 1`. -/\n@[simp] lemma cyclotomic_two (R : Type*) [ring R] : cyclotomic 2 R = X + 1 :=\nbegin\n  have hspec : map (int.cast_ring_hom \u2102) (X + 1) = cyclotomic' 2 \u2102,\n  { simp only [cyclotomic'_two \u2102 0 two_ne_zero.symm, map_add, map_X, map_one] },\n  symmetry,\n  rw [\u2190map_cyclotomic_int, \u2190(int_cyclotomic_unique hspec)],\n  simp only [map_add, map_X, map_one]\nend\n\n/-- `cyclotomic n` is monic. -/\nlemma cyclotomic.monic (n : \u2115) (R : Type*) [ring R] : (cyclotomic n R).monic :=\nbegin\n  rw \u2190map_cyclotomic_int,\n  apply monic_map,\n  exact (int_cyclotomic_spec n).2.2\nend\n\n/-- `cyclotomic n R` is different from `0`. -/\nlemma cyclotomic_ne_zero (n : \u2115) (R : Type*) [ring R] [nontrivial R] : cyclotomic n R \u2260 0 :=\nmonic.ne_zero (cyclotomic.monic n R)\n\n/-- The degree of `cyclotomic n` is `totient n`. -/\nlemma degree_cyclotomic (n : \u2115) (R : Type*) [ring R] [nontrivial R] :\n  (cyclotomic n R).degree = nat.totient n :=\nbegin\n  rw \u2190map_cyclotomic_int,\n  rw degree_map_eq_of_leading_coeff_ne_zero (int.cast_ring_hom R) _,\n  { cases n with k,\n    { simp only [cyclotomic, degree_one, dif_pos, nat.totient_zero, with_top.coe_zero]},\n      rw [\u2190degree_cyclotomic' (complex.is_primitive_root_exp k.succ (nat.succ_ne_zero k))],\n      exact (int_cyclotomic_spec k.succ).2.1 },\n  simp only [(int_cyclotomic_spec n).right.right, ring_hom.eq_int_cast, monic.leading_coeff,\n  int.cast_one, ne.def, not_false_iff, one_ne_zero]\nend\n\n/-- The natural degree of `cyclotomic n` is `totient n`. -/\nlemma nat_degree_cyclotomic (n : \u2115) (R : Type*) [ring R] [nontrivial R] :\n  (cyclotomic n R).nat_degree = nat.totient n :=\nbegin\n  have hdeg := degree_cyclotomic n R,\n  rw degree_eq_nat_degree (cyclotomic_ne_zero n R) at hdeg,\n  exact_mod_cast hdeg\nend\n\n/-- The degree of `cyclotomic n R` is positive. -/\nlemma degree_cyclotomic_pos (n : \u2115) (R : Type*) (hpos : 0 < n) [ring R] [nontrivial R] :\n  0 < (cyclotomic n R).degree := by\n{ rw degree_cyclotomic n R, exact_mod_cast (nat.totient_pos hpos) }\n\n/-- `\u220f i in nat.divisors n, cyclotomic i R = X ^ n - 1`. -/\nlemma prod_cyclotomic_eq_X_pow_sub_one {n : \u2115} (hpos : 0 < n) (R : Type*) [comm_ring R] :\n  \u220f i in nat.divisors n, cyclotomic i R = X ^ n - 1 :=\nbegin\n  have integer : \u220f i in nat.divisors n, cyclotomic i \u2124 = X ^ n - 1,\n  { apply map_injective (int.cast_ring_hom \u2102) int.cast_injective,\n    rw map_prod (int.cast_ring_hom \u2102) (\u03bb i, cyclotomic i \u2124),\n    simp only [int_cyclotomic_spec, map_pow, nat.cast_id, map_X, map_one, map_sub],\n    exact prod_cyclotomic'_eq_X_pow_sub_one hpos\n          (complex.is_primitive_root_exp n (ne_of_lt hpos).symm) },\n  have coerc : X ^ n - 1 = map (int.cast_ring_hom R) (X ^ n - 1),\n  { simp only [map_pow, map_X, map_one, map_sub] },\n  have h : \u2200 i \u2208 n.divisors, cyclotomic i R = map (int.cast_ring_hom R) (cyclotomic i \u2124),\n  { intros i hi,\n    exact (map_cyclotomic_int i R).symm },\n  rw [finset.prod_congr (refl n.divisors) h, coerc, \u2190map_prod (int.cast_ring_hom R)\n                                                    (\u03bb i, cyclotomic i \u2124), integer]\nend\n\nlemma _root_.is_root_of_unity_iff {n : \u2115} (h : 0 < n) (R : Type*) [comm_ring R] [is_domain R]\n  {\u03b6 : R} : \u03b6 ^ n = 1 \u2194 \u2203 i \u2208 n.divisors, (cyclotomic i R).is_root \u03b6 :=\nby rw [\u2190mem_nth_roots h, nth_roots, mem_roots $ X_pow_sub_C_ne_zero h _,\n       C_1, \u2190prod_cyclotomic_eq_X_pow_sub_one h, is_root_prod]; apply_instance\n\nsection arithmetic_function\nopen nat.arithmetic_function\nopen_locale arithmetic_function\n\n/-- `cyclotomic n R` can be expressed as a product in a fraction field of `polynomial R`\n  using M\u00f6bius inversion. -/\nlemma cyclotomic_eq_prod_X_pow_sub_one_pow_moebius {n : \u2115} (R : Type*) [comm_ring R] [is_domain R] :\n  algebra_map _ (ratfunc R) (cyclotomic n R) =\n    \u220f i in n.divisors_antidiagonal, (algebra_map (polynomial R) _ (X ^ i.snd - 1)) ^ \u03bc i.fst :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hpos,\n  { simp },\n  have h : \u2200 (n : \u2115), 0 < n \u2192\n    \u220f i in nat.divisors n, algebra_map _ (ratfunc R) (cyclotomic i R) = algebra_map _ _ (X ^ n - 1),\n  { intros n hn,\n    rw [\u2190 prod_cyclotomic_eq_X_pow_sub_one hn R, ring_hom.map_prod] },\n  rw (prod_eq_iff_prod_pow_moebius_eq_of_nonzero (\u03bb n hn, _) (\u03bb n hn, _)).1 h n hpos;\n  rw [ne.def, is_fraction_ring.to_map_eq_zero_iff],\n  { apply cyclotomic_ne_zero },\n  { apply monic.ne_zero,\n    apply monic_X_pow_sub_C _ (ne_of_gt hn) }\nend\n\nend arithmetic_function\n\n/-- We have\n`cyclotomic n R = (X ^ k - 1) /\u2098 (\u220f i in nat.proper_divisors k, cyclotomic i K)`. -/\nlemma cyclotomic_eq_X_pow_sub_one_div {R : Type*} [comm_ring R] {n : \u2115}\n  (hpos: 0 < n) : cyclotomic n R = (X ^ n - 1) /\u2098 (\u220f i in nat.proper_divisors n, cyclotomic i R) :=\nbegin\n  nontriviality R,\n  rw [\u2190prod_cyclotomic_eq_X_pow_sub_one hpos,\n  nat.divisors_eq_proper_divisors_insert_self_of_pos hpos,\n  finset.prod_insert nat.proper_divisors.not_self_mem],\n  have prod_monic : (\u220f i in nat.proper_divisors n, cyclotomic i R).monic,\n  { apply monic_prod_of_monic,\n    intros i hi,\n    exact cyclotomic.monic i R },\n  rw (div_mod_by_monic_unique (cyclotomic n R) 0 prod_monic _).1,\n  simp only [degree_zero, zero_add],\n  split,\n  { rw mul_comm },\n  rw [bot_lt_iff_ne_bot],\n  intro h,\n  exact monic.ne_zero prod_monic (degree_eq_bot.1 h)\nend\n\n/-- If `m` is a proper divisor of `n`, then `X ^ m - 1` divides\n`\u220f i in nat.proper_divisors n, cyclotomic i R`. -/\nlemma X_pow_sub_one_dvd_prod_cyclotomic (R : Type*) [comm_ring R] {n m : \u2115} (hpos : 0 < n)\n  (hm : m \u2223 n) (hdiff : m \u2260 n) : X ^ m - 1 \u2223 \u220f i in nat.proper_divisors n, cyclotomic i R :=\nbegin\n  replace hm := nat.mem_proper_divisors.2 \u27e8hm, lt_of_le_of_ne (nat.divisor_le (nat.mem_divisors.2\n    \u27e8hm, (ne_of_lt hpos).symm\u27e9)) hdiff\u27e9,\n  rw [\u2190 finset.sdiff_union_of_subset (nat.divisors_subset_proper_divisors (ne_of_lt hpos).symm\n    (nat.mem_proper_divisors.1 hm).1 (ne_of_lt (nat.mem_proper_divisors.1 hm).2)),\n    finset.prod_union finset.sdiff_disjoint, prod_cyclotomic_eq_X_pow_sub_one\n    (nat.pos_of_mem_proper_divisors hm)],\n  exact \u27e8(\u220f (x : \u2115) in n.proper_divisors \\ m.divisors, cyclotomic x R), by rw mul_comm\u27e9\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then\n`cyclotomic n K = \u220f \u03bc in primitive_roots n R, (X - C \u03bc)`. In particular,\n`cyclotomic n K = cyclotomic' n K` -/\nlemma cyclotomic_eq_prod_X_sub_primitive_roots {K : Type*} [field K] {\u03b6 : K} {n : \u2115}\n  (hz : is_primitive_root \u03b6 n) :\n  cyclotomic n K = \u220f \u03bc in primitive_roots n K, (X - C \u03bc) :=\nbegin\n  rw \u2190cyclotomic',\n  induction n using nat.strong_induction_on with k hk generalizing \u03b6 hz,\n  obtain hzero | hpos := k.eq_zero_or_pos,\n  { simp only [hzero, cyclotomic'_zero, cyclotomic_zero] },\n  have h : \u2200 i \u2208 k.proper_divisors, cyclotomic i K = cyclotomic' i K,\n  { intros i hi,\n    obtain \u27e8d, hd\u27e9 := (nat.mem_proper_divisors.1 hi).1,\n    rw mul_comm at hd,\n    exact hk i (nat.mem_proper_divisors.1 hi).2 (is_primitive_root.pow hpos hz hd) },\n  rw [@cyclotomic_eq_X_pow_sub_one_div _ _ _ hpos,\n      cyclotomic'_eq_X_pow_sub_one_div hpos hz, finset.prod_congr (refl k.proper_divisors) h]\nend\n\n/-- Any `n`-th primitive root of unity is a root of `cyclotomic n K`.-/\nlemma is_root_cyclotomic {n : \u2115} {K : Type*} [field K] (hpos : 0 < n) {\u03bc : K}\n  (h : is_primitive_root \u03bc n) : is_root (cyclotomic n K) \u03bc :=\nbegin\n  rw [\u2190 mem_roots (cyclotomic_ne_zero n K),\n      cyclotomic_eq_prod_X_sub_primitive_roots h, roots_prod_X_sub_C, \u2190 finset.mem_def],\n  rwa [\u2190 mem_primitive_roots hpos] at h,\nend\n\nprivate lemma is_root_cyclotomic_iff' {n : \u2115} {K : Type*} [field K] {\u03bc : K} (hn : (n : K) \u2260 0) :\n  is_root (cyclotomic n K) \u03bc \u2194 is_primitive_root \u03bc n :=\nbegin\n  -- in this proof, `o` stands for `order_of \u03bc`\n  have hnpos : 0 < n := (show n \u2260 0, by { rintro rfl, contradiction }).bot_lt,\n  refine \u27e8\u03bb h\u03bc, _, is_root_cyclotomic hnpos\u27e9,\n  have h\u03bcn : \u03bc ^ n = 1,\n  { rw is_root_of_unity_iff hnpos,\n    exact \u27e8n, n.mem_divisors_self hnpos.ne', h\u03bc\u27e9 },\n  by_contra hn\u03bc,\n  have ho : 0 < order_of \u03bc,\n  { apply order_of_pos',\n    rw is_of_fin_order_iff_pow_eq_one,\n    exact \u27e8n, hnpos, h\u03bcn\u27e9 },\n  have := pow_order_of_eq_one \u03bc,\n  rw is_root_of_unity_iff ho at this,\n  obtain \u27e8i, hio, hi\u03bc\u27e9 := this,\n  replace hio := nat.dvd_of_mem_divisors hio,\n  rw is_primitive_root.not_iff at hn\u03bc,\n  rw \u2190order_of_dvd_iff_pow_eq_one at h\u03bcn,\n  have key  : i < n := (nat.le_of_dvd ho hio).trans_lt ((nat.le_of_dvd hnpos h\u03bcn).lt_of_ne hn\u03bc),\n  have key' : i \u2223 n := hio.trans h\u03bcn,\n  rw \u2190polynomial.dvd_iff_is_root at h\u03bc hi\u03bc,\n  have hni : {i, n} \u2286 n.divisors,\n  { simpa [finset.insert_subset, key'] using hnpos.ne' },\n  obtain \u27e8k, hk\u27e9 := hi\u03bc,\n  obtain \u27e8j, hj\u27e9 := h\u03bc,\n  have := prod_cyclotomic_eq_X_pow_sub_one hnpos K,\n  rw [\u2190finset.prod_sdiff hni, finset.prod_pair key.ne, hk, hj] at this,\n  replace hn := (X_pow_sub_one_separable_iff.mpr hn).squarefree,\n  rw [\u2190this, squarefree] at hn,\n  contrapose! hn,\n  refine \u27e8X - C \u03bc, \u27e8(\u220f x in n.divisors \\ {i, n}, cyclotomic x K) * k * j, by ring\u27e9, _\u27e9,\n  simp [polynomial.is_unit_iff_degree_eq_zero]\nend\n\nlemma is_root_cyclotomic_iff {n : \u2115} {R : Type*} [comm_ring R] [is_domain R]\n  {\u03bc : R} (hn : (n : R) \u2260 0) : is_root (cyclotomic n R) \u03bc \u2194 is_primitive_root \u03bc n  :=\nbegin\n  let f := algebra_map R (fraction_ring R),\n  have hf : function.injective f := is_localization.injective _ le_rfl,\n  rw [\u2190is_root_map_iff hf, \u2190is_primitive_root.map_iff_of_injective hf, map_cyclotomic,\n      \u2190is_root_cyclotomic_iff' $ by simpa only [f.map_nat_cast, hn] using f.injective_iff.mp hf n]\nend\n\nlemma eq_cyclotomic_iff {R : Type*} [comm_ring R] {n : \u2115} (hpos: 0 < n)\n  (P : polynomial R) :\n  P = cyclotomic n R \u2194 P * (\u220f i in nat.proper_divisors n, polynomial.cyclotomic i R) = X ^ n - 1 :=\nbegin\n  nontriviality R,\n  refine \u27e8\u03bb hcycl, _, \u03bb hP, _\u27e9,\n  { rw [hcycl, \u2190 finset.prod_insert (@nat.proper_divisors.not_self_mem n),\n      \u2190 nat.divisors_eq_proper_divisors_insert_self_of_pos hpos],\n    exact prod_cyclotomic_eq_X_pow_sub_one hpos R },\n  { have prod_monic : (\u220f i in nat.proper_divisors n, cyclotomic i R).monic,\n    { apply monic_prod_of_monic,\n      intros i hi,\n      exact cyclotomic.monic i R },\n    rw [@cyclotomic_eq_X_pow_sub_one_div R _ _ hpos,\n      (div_mod_by_monic_unique P 0 prod_monic _).1],\n    refine \u27e8by rwa [zero_add, mul_comm], _\u27e9,\n    rw [degree_zero, bot_lt_iff_ne_bot],\n    intro h,\n    exact monic.ne_zero prod_monic (degree_eq_bot.1 h) },\nend\n\n/-- If `p` is prime, then `cyclotomic p R = geom_sum X p`. -/\nlemma cyclotomic_eq_geom_sum {R : Type*} [comm_ring R] {p : \u2115}\n  (hp : nat.prime p) : cyclotomic p R = geom_sum X p :=\nbegin\n  refine ((eq_cyclotomic_iff hp.pos _).mpr _).symm,\n  simp only [nat.prime.proper_divisors hp, geom_sum_mul, finset.prod_singleton, cyclotomic_one],\nend\n\n/-- If `p ^ k` is prime power, then `cyclotomic (p ^ (n + 1)) R = geom_sum (X ^ p ^ n) p`. -/\nlemma cyclotomic_prime_pow_eq_geom_sum {R : Type*} [comm_ring R] {p n : \u2115} (hp : nat.prime p) :\n  cyclotomic (p ^ (n + 1)) R = geom_sum (X ^ p ^ n) p :=\nbegin\n  have : \u2200 m, cyclotomic (p ^ (m + 1)) R = geom_sum (X ^ (p ^ m)) p \u2194\n    geom_sum (X ^ p ^ m) p * \u220f (x : \u2115) in finset.range (m + 1),\n      cyclotomic (p ^ x) R = X ^ p ^ (m + 1) - 1,\n  { intro m,\n    have := eq_cyclotomic_iff (pow_pos hp.pos (m + 1)) _,\n    rw eq_comm at this,\n    rw [this, nat.prod_proper_divisors_prime_pow hp], },\n  induction n with n_n n_ih,\n  { simp [cyclotomic_eq_geom_sum hp], },\n  rw ((eq_cyclotomic_iff (pow_pos hp.pos (n_n.succ + 1)) _).mpr _).symm,\n  rw [nat.prod_proper_divisors_prime_pow hp, finset.prod_range_succ, n_ih],\n  rw this at n_ih,\n  rw [mul_comm _ (geom_sum _ _), n_ih, geom_sum_mul, sub_left_inj, \u2190 pow_mul, pow_add, pow_one],\nend\n\n/-- The constant term of `cyclotomic n R` is `1` if `2 \u2264 n`. -/\nlemma cyclotomic_coeff_zero (R : Type*) [comm_ring R] {n : \u2115} (hn : 2 \u2264 n) :\n  (cyclotomic n R).coeff 0 = 1 :=\nbegin\n  induction n using nat.strong_induction_on with n hi,\n  have hprod : (\u220f i in nat.proper_divisors n, (polynomial.cyclotomic i R).coeff 0) = -1,\n  { rw [\u2190finset.insert_erase (nat.one_mem_proper_divisors_iff_one_lt.2\n      (lt_of_lt_of_le one_lt_two hn)), finset.prod_insert (finset.not_mem_erase 1 _),\n      cyclotomic_one R],\n    have hleq : \u2200 j \u2208 n.proper_divisors.erase 1, 2 \u2264 j,\n    { intros j hj,\n      apply nat.succ_le_of_lt,\n      exact (ne.le_iff_lt ((finset.mem_erase.1 hj).1).symm).mp\n              (nat.succ_le_of_lt (nat.pos_of_mem_proper_divisors (finset.mem_erase.1 hj).2)) },\n    have hcongr : \u2200 j \u2208 n.proper_divisors.erase 1, (cyclotomic j R).coeff 0 = 1,\n    { intros j hj,\n      exact hi j (nat.mem_proper_divisors.1 (finset.mem_erase.1 hj).2).2 (hleq j hj) },\n    have hrw : \u220f (x : \u2115) in n.proper_divisors.erase 1, (cyclotomic x R).coeff 0 = 1,\n    { rw finset.prod_congr (refl (n.proper_divisors.erase 1)) hcongr,\n      simp only [finset.prod_const_one] },\n    simp only [hrw, mul_one, zero_sub, coeff_one_zero, coeff_X_zero, coeff_sub] },\n  have heq : (X ^ n - 1).coeff 0 = -(cyclotomic n R).coeff 0,\n  { rw [\u2190prod_cyclotomic_eq_X_pow_sub_one (lt_of_lt_of_le zero_lt_two hn),\n        nat.divisors_eq_proper_divisors_insert_self_of_pos (lt_of_lt_of_le zero_lt_two hn),\n        finset.prod_insert nat.proper_divisors.not_self_mem, mul_coeff_zero, coeff_zero_prod, hprod,\n        mul_neg_eq_neg_mul_symm, mul_one] },\n  have hzero : (X ^ n - 1).coeff 0 = (-1 : R),\n  { rw coeff_zero_eq_eval_zero _,\n    simp only [zero_pow (lt_of_lt_of_le zero_lt_two hn), eval_X, eval_one, zero_sub, eval_pow,\n              eval_sub] },\n  rw hzero at heq,\n  exact neg_inj.mp (eq.symm heq)\nend\n\n/-- If `(a : \u2115)` is a root of `cyclotomic n (zmod p)`, where `p` is a prime, then `a` and `p` are\ncoprime. -/\nlemma coprime_of_root_cyclotomic {n : \u2115} (hpos : 0 < n) {p : \u2115} [hprime : fact p.prime] {a : \u2115}\n  (hroot : is_root (cyclotomic n (zmod p)) (nat.cast_ring_hom (zmod p) a)) :\n  a.coprime p :=\nbegin\n  apply nat.coprime.symm,\n  rw [hprime.1.coprime_iff_not_dvd],\n  intro h,\n  replace h := (zmod.nat_coe_zmod_eq_zero_iff_dvd a p).2 h,\n  rw [is_root.def, ring_hom.eq_nat_cast, h, \u2190 coeff_zero_eq_eval_zero] at hroot,\n  by_cases hone : n = 1,\n  { simp only [hone, cyclotomic_one, zero_sub, coeff_one_zero, coeff_X_zero, neg_eq_zero,\n    one_ne_zero, coeff_sub] at hroot,\n    exact hroot },\n  rw [cyclotomic_coeff_zero (zmod p) (nat.succ_le_of_lt (lt_of_le_of_ne\n        (nat.succ_le_of_lt hpos) (ne.symm hone)))] at hroot,\n  exact one_ne_zero hroot\nend\n\nend cyclotomic\n\nsection order\n\n/-- If `(a : \u2115)` is a root of `cyclotomic n (zmod p)`, then the multiplicative order of `a` modulo\n`p` divides `n`. -/\nlemma order_of_root_cyclotomic_dvd {n : \u2115} (hpos : 0 < n) {p : \u2115} [fact p.prime]\n  {a : \u2115} (hroot : is_root (cyclotomic n (zmod p)) (nat.cast_ring_hom (zmod p) a)) :\n  order_of (zmod.unit_of_coprime a (coprime_of_root_cyclotomic hpos hroot)) \u2223 n :=\nbegin\n  apply order_of_dvd_of_pow_eq_one,\n  suffices hpow : eval (nat.cast_ring_hom (zmod p) a) (X ^ n - 1 : polynomial (zmod p)) = 0,\n  { simp only [eval_X, eval_one, eval_pow, eval_sub, ring_hom.eq_nat_cast] at hpow,\n    apply units.coe_eq_one.1,\n    simp only [sub_eq_zero.mp hpow, zmod.coe_unit_of_coprime, units.coe_pow] },\n  rw [is_root.def] at hroot,\n  rw [\u2190 prod_cyclotomic_eq_X_pow_sub_one hpos (zmod p),\n    nat.divisors_eq_proper_divisors_insert_self_of_pos hpos,\n    finset.prod_insert nat.proper_divisors.not_self_mem, eval_mul, hroot, zero_mul]\nend\n\nend order\n\nsection minpoly\n\nopen is_primitive_root complex\n\n/-- The minimal polynomial of a primitive `n`-th root of unity `\u03bc` divides `cyclotomic n \u2124`. -/\nlemma _root_.minpoly_dvd_cyclotomic {n : \u2115} {K : Type*} [field K] {\u03bc : K}\n  (h : is_primitive_root \u03bc n) (hpos : 0 < n) [char_zero K] :\n  minpoly \u2124 \u03bc \u2223 cyclotomic n \u2124 :=\nbegin\n  apply minpoly.gcd_domain_dvd \u211a (is_integral h hpos) (cyclotomic.monic n \u2124).is_primitive,\n  simpa [aeval_def, eval\u2082_eq_eval_map, is_root.def] using is_root_cyclotomic hpos h\nend\n\n/-- `cyclotomic n \u2124` is the minimal polynomial of a primitive `n`-th root of unity `\u03bc`. -/\nlemma cyclotomic_eq_minpoly {n : \u2115} {K : Type*} [field K] {\u03bc : K}\n  (h : is_primitive_root \u03bc n) (hpos : 0 < n) [char_zero K] :\n  cyclotomic n \u2124 = minpoly \u2124 \u03bc :=\nbegin\n  refine eq_of_monic_of_dvd_of_nat_degree_le (minpoly.monic (is_integral h hpos))\n    (cyclotomic.monic n \u2124) (minpoly_dvd_cyclotomic h hpos) _,\n  simpa [nat_degree_cyclotomic n \u2124] using totient_le_degree_minpoly h hpos\nend\n\n/-- `cyclotomic n \u2124` is irreducible. -/\nlemma cyclotomic.irreducible {n : \u2115} (hpos : 0 < n) : irreducible (cyclotomic n \u2124) :=\nbegin\n  rw [cyclotomic_eq_minpoly (is_primitive_root_exp n hpos.ne') hpos],\n  apply minpoly.irreducible,\n  exact (is_primitive_root_exp n hpos.ne').is_integral hpos,\nend\n\nend minpoly\n\nsection eval_one\n\nopen finset nat\n\n@[simp]\nlemma eval_one_cyclotomic_prime {R : Type*} [comm_ring R] {n : \u2115} [hn : fact (nat.prime n)] :\n  eval 1 (cyclotomic n R) = n :=\nbegin\n  simp only [cyclotomic_eq_geom_sum hn.out, geom_sum_def, eval_X, one_pow, sum_const, eval_pow,\n    eval_finset_sum, card_range, smul_one_eq_coe],\nend\n\n@[simp]\nlemma eval\u2082_one_cyclotomic_prime {R S : Type*} [comm_ring R] [semiring S] (f : R \u2192+* S) {n : \u2115}\n  [fact n.prime] : eval\u2082 f 1 (cyclotomic n R) = n :=\nby simp\n\n@[simp]\nlemma eval_one_cyclotomic_prime_pow {R : Type*} [comm_ring R] {n : \u2115} (k : \u2115)\n  [hn : fact n.prime] : eval 1 (cyclotomic (n ^ (k + 1)) R) = n :=\nbegin\n  simp only [cyclotomic_prime_pow_eq_geom_sum hn.out, geom_sum_def, eval_X, one_pow, sum_const,\n    eval_pow, eval_finset_sum, card_range, smul_one_eq_coe]\nend\n\n@[simp]\nlemma eval\u2082_one_cyclotomic_prime_pow {R S : Type*} [comm_ring R] [semiring S] (f : R \u2192+* S)\n  {n : \u2115} (k : \u2115) [fact n.prime] :\n  eval\u2082 f 1 (cyclotomic (n ^ (k + 1)) R) = n :=\nby simp\n\n-- TODO show that `eval 1 (cyclotomic n R) = 1` when `n` is not a power of a prime\n\nend eval_one\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/polynomial/cyclotomic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.7076800645144606}}
{"text": "/-\nCopyright (c) 2022 David Loeffler. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Loeffler\n-/\nimport measure_theory.integral.exp_decay\n\n/-!\n# The Gamma function\n\nThis file treats Euler's integral for the `\u0393` function, `\u222b x in Ioi 0, exp (-x) * x ^ (s - 1)`, for\n`s` a real or complex variable.\n\nWe prove convergence of the integral for `1 \u2264 s` in the real case, and `1 \u2264 re s` in the complex\ncase (which is non-optimal, but the optimal bound of `0 < s`, resp `0 < re s`, is harder to prove\nusing the methods in the library). We also show `\u0393(1) = 1`.\n\nThe recurrence `\u0393(s + 1) = s * \u0393(s)`, holomorphy in `s`, and extension to the whole complex plane\nwill be added in future pull requests.\n\n## Tags\n\nGamma\n-/\n\nnoncomputable theory\nopen filter interval_integral set real measure_theory\nopen_locale topological_space\n\nlemma integral_exp_neg_Ioi : \u222b (x : \u211d) in Ioi 0, exp (-x) = 1 :=\nbegin\n  refine tendsto_nhds_unique (interval_integral_tendsto_integral_Ioi _ _ tendsto_id) _,\n  { simpa only [neg_mul, one_mul] using exp_neg_integrable_on_Ioi 0 zero_lt_one, },\n  { simpa using tendsto_exp_neg_at_top_nhds_0.const_sub 1, },\nend\n\nnamespace real\n\n/-- Asymptotic bound for the \u0393 function integrand. -/\nlemma Gamma_integrand_is_O (s : \u211d) : asymptotics.is_O (\u03bb x:\u211d, exp (-x) * x ^ s)\n  (\u03bb x:\u211d, exp (-(1/2) * x)) at_top :=\nbegin\n  refine asymptotics.is_o.is_O (asymptotics.is_o_of_tendsto _ _),\n  { intros x hx, exfalso, exact (exp_pos (-(1 / 2) * x)).ne' hx },\n  have : (\u03bb (x:\u211d), exp (-x) * x ^ s / exp (-(1 / 2) * x)) = (\u03bb (x:\u211d), exp ((1 / 2) * x) / x ^ s )\u207b\u00b9,\n  { ext1 x,\n    field_simp [exp_ne_zero, exp_neg, \u2190 real.exp_add],\n    left,\n    ring },\n  rw this,\n  exact (tendsto_exp_mul_div_rpow_at_top s (1 / 2) one_half_pos).inv_tendsto_at_top,\nend\n\n/-- Euler's integral for the `\u0393` function (of a real variable `s`), defined as\n`\u222b x in Ioi 0, exp (-x) * x ^ (s - 1)`.\n\nSee `Gamma_integral_convergent` for a proof of the convergence of the integral for `1 \u2264 s`. -/\ndef Gamma_integral (s : \u211d) : \u211d := \u222b x in Ioi (0:\u211d), exp (-x) * x ^ (s - 1)\n\n/-- The integral defining the \u0393 function converges for real `s` with `1 \u2264 s`.\n\nThis is not optimal, but the optimal bound (convergence for `0 < s`) is hard to establish with the\nresults currently in the library. -/\nlemma Gamma_integral_convergent {s : \u211d} (h : 1 \u2264 s) :\n  integrable_on (\u03bb x:\u211d, exp (-x) * x ^ (s - 1)) (Ioi 0) :=\nbegin\n  refine integrable_of_is_O_exp_neg one_half_pos _ (Gamma_integrand_is_O _ ),\n  refine continuous_on_id.neg.exp.mul (continuous_on_id.rpow_const _),\n  intros x hx, right, simpa only [sub_nonneg] using h,\nend\n\nlemma Gamma_integral_one : Gamma_integral 1 = 1 :=\nby simpa only [Gamma_integral, sub_self, rpow_zero, mul_one] using integral_exp_neg_Ioi\n\nend real\n\nnamespace complex\n\n/-- The integral defining the \u0393 function converges for complex `s` with `1 \u2264 re s`.\n\nThis is proved by reduction to the real case. The bound is not optimal, but the optimal bound\n(convergence for `0 < re s`) is hard to establish with the results currently in the library. -/\nlemma Gamma_integral_convergent {s : \u2102} (hs : 1 \u2264 s.re) :\n  integrable_on (\u03bb x:\u211d, real.exp (-x) * x ^ (s - 1) : \u211d \u2192 \u2102) (Ioi 0) :=\nbegin\n  -- This is slightly subtle if `s` is non-real but `s.re = 1`, as the integrand is not continuous\n  -- at the lower endpoint. However, it is continuous on the interior, and its norm is continuous\n  -- at the endpoint, which is good enough.\n  split,\n  { refine continuous_on.ae_strongly_measurable _ measurable_set_Ioi,\n    apply (continuous_of_real.comp continuous_neg.exp).continuous_on.mul,\n    apply continuous_at.continuous_on,\n    intros x hx,\n    have : continuous_at (\u03bb x:\u2102, x ^ (s - 1)) \u2191x,\n    { apply continuous_at_cpow_const, rw of_real_re, exact or.inl hx, },\n    exact continuous_at.comp this continuous_of_real.continuous_at },\n  { rw \u2190has_finite_integral_norm_iff,\n    refine has_finite_integral.congr (real.Gamma_integral_convergent hs).2 _,\n    refine (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (\u03bb x hx, _)),\n    dsimp only,\n    rw [complex.norm_eq_abs, complex.abs_mul, complex.abs_of_nonneg $ le_of_lt $ exp_pos $ -x,\n      abs_cpow_eq_rpow_re_of_pos hx _],\n    simp }\nend\n\n/-- Euler's integral for the `\u0393` function (of a complex variable `s`), defined as\n`\u222b x in Ioi 0, exp (-x) * x ^ (s - 1)`.\n\nSee `complex.Gamma_integral_convergent` for a proof of the convergence of the integral for\n`1 \u2264 re s`. -/\ndef Gamma_integral (s : \u2102) : \u2102 := \u222b x in Ioi (0:\u211d), \u2191(real.exp (-x)) * \u2191x ^ (s - 1)\n\nlemma Gamma_integral_of_real (s : \u211d) :\n  Gamma_integral \u2191s = \u2191(s.Gamma_integral) :=\nbegin\n  rw [real.Gamma_integral, \u2190integral_of_real],\n  refine set_integral_congr measurable_set_Ioi _,\n  intros x hx, dsimp only,\n  rw [of_real_mul, of_real_cpow (mem_Ioi.mp hx).le],\n  simp,\nend\n\nlemma Gamma_integral_one : Gamma_integral 1 = 1 :=\nbegin\n  rw [\u2190of_real_one, Gamma_integral_of_real, of_real_inj],\n  exact real.Gamma_integral_one,\nend\n\nend complex\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/special_functions/gamma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.707680061785291}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning, Jireh Loreaux\n-/\nimport group_theory.subsemigroup.center\nimport algebra.group_with_zero.units.lemmas\n\n/-!\n# Centralizers of magmas and semigroups\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\n* `set.centralizer`: the centralizer of a subset of a magma\n* `subsemigroup.centralizer`: the centralizer of a subset of a semigroup\n* `set.add_centralizer`: the centralizer of a subset of an additive magma\n* `add_subsemigroup.centralizer`: the centralizer of a subset of an additive semigroup\n\nWe provide `monoid.centralizer`, `add_monoid.centralizer`, `subgroup.centralizer`, and\n`add_subgroup.centralizer` in other files.\n-/\n\nvariables {M : Type*} {S T : set M}\n\nnamespace set\n\nvariables (S)\n\n/-- The centralizer of a subset of a magma. -/\n@[to_additive add_centralizer /-\" The centralizer of a subset of an additive magma. \"-/]\ndef centralizer [has_mul M] : set M := {c | \u2200 m \u2208 S, m * c = c * m}\n\nvariables {S}\n\n@[to_additive mem_add_centralizer]\nlemma mem_centralizer_iff [has_mul M] {c : M} : c \u2208 centralizer S \u2194 \u2200 m \u2208 S, m * c = c * m :=\niff.rfl\n\n@[to_additive decidable_mem_add_centralizer]\ninstance decidable_mem_centralizer [has_mul M] [\u2200 a : M, decidable $ \u2200 b \u2208 S, b * a = a * b] :\n  decidable_pred (\u2208 centralizer S) :=\n\u03bb _, decidable_of_iff' _ (mem_centralizer_iff)\n\nvariables (S)\n\n@[simp, to_additive zero_mem_add_centralizer]\nlemma one_mem_centralizer [mul_one_class M] : (1 : M) \u2208 centralizer S :=\nby simp [mem_centralizer_iff]\n\n@[simp]\nlemma zero_mem_centralizer [mul_zero_class M] : (0 : M) \u2208 centralizer S :=\nby simp [mem_centralizer_iff]\n\nvariables {S} {a b : M}\n\n@[simp, to_additive add_mem_add_centralizer]\nlemma mul_mem_centralizer [semigroup M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a * b \u2208 centralizer S :=\n\u03bb g hg, by rw [mul_assoc, \u2190hb g hg, \u2190 mul_assoc, ha g hg, mul_assoc]\n\n@[simp, to_additive neg_mem_add_centralizer]\nlemma inv_mem_centralizer [group M] (ha : a \u2208 centralizer S) : a\u207b\u00b9 \u2208 centralizer S :=\n\u03bb g hg, by rw [mul_inv_eq_iff_eq_mul, mul_assoc, eq_inv_mul_iff_mul_eq, ha g hg]\n\n@[simp]\nlemma add_mem_centralizer [distrib M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a + b \u2208 centralizer S :=\n\u03bb c hc, by rw [add_mul, mul_add, ha c hc, hb c hc]\n\n@[simp]\nlemma neg_mem_centralizer [has_mul M] [has_distrib_neg M] (ha : a \u2208 centralizer S) :\n  -a \u2208 centralizer S :=\n\u03bb c hc, by rw [mul_neg, ha c hc, neg_mul]\n\n@[simp]\nlemma inv_mem_centralizer\u2080 [group_with_zero M] (ha : a \u2208 centralizer S) : a\u207b\u00b9 \u2208 centralizer S :=\n(eq_or_ne a 0).elim (\u03bb h, by { rw [h, inv_zero], exact zero_mem_centralizer S })\n  (\u03bb ha0 c hc, by rw [mul_inv_eq_iff_eq_mul\u2080 ha0, mul_assoc, eq_inv_mul_iff_mul_eq\u2080 ha0, ha c hc])\n\n@[simp, to_additive sub_mem_add_centralizer]\nlemma div_mem_centralizer [group M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a / b \u2208 centralizer S :=\nbegin\n  rw [div_eq_mul_inv],\n  exact mul_mem_centralizer ha (inv_mem_centralizer hb),\nend\n\n@[simp]\nlemma div_mem_centralizer\u2080 [group_with_zero M] (ha : a \u2208 centralizer S) (hb : b \u2208 centralizer S) :\n  a / b \u2208 centralizer S :=\nbegin\n  rw div_eq_mul_inv,\n  exact mul_mem_centralizer ha (inv_mem_centralizer\u2080 hb),\nend\n\n@[to_additive add_centralizer_subset]\nlemma centralizer_subset [has_mul M] (h : S \u2286 T) : centralizer T \u2286 centralizer S :=\n\u03bb t ht s hs, ht s (h hs)\n\nvariables (M)\n\n@[simp, to_additive add_centralizer_univ]\nlemma centralizer_univ [has_mul M] : centralizer univ = center M :=\nsubset.antisymm (\u03bb a ha b, ha b (set.mem_univ b)) (\u03bb a ha b hb, ha b)\n\nvariables {M} (S)\n\n@[simp, to_additive add_centralizer_eq_univ]\nlemma centralizer_eq_univ [comm_semigroup M] : centralizer S = univ :=\nsubset.antisymm (subset_univ _) $ \u03bb x hx y hy, mul_comm y x\n\nend set\n\nnamespace subsemigroup\nsection\nvariables {M} [semigroup M] (S)\n\n/-- The centralizer of a subset of a semigroup `M`. -/\n@[to_additive \"The centralizer of a subset of an additive semigroup.\"]\ndef centralizer : subsemigroup M :=\n{ carrier := S.centralizer,\n  mul_mem' := \u03bb a b, set.mul_mem_centralizer }\n\n@[simp, norm_cast, to_additive] lemma coe_centralizer : \u2191(centralizer S) = S.centralizer := rfl\n\nvariables {S}\n\n@[to_additive] lemma mem_centralizer_iff {z : M} : z \u2208 centralizer S \u2194 \u2200 g \u2208 S, g * z = z * g :=\niff.rfl\n\n@[to_additive] instance decidable_mem_centralizer (a) [decidable $ \u2200 b \u2208 S, b * a = a * b] :\n  decidable (a \u2208 centralizer S) :=\ndecidable_of_iff' _ mem_centralizer_iff\n\n@[to_additive]\nlemma centralizer_le (h : S \u2286 T) : centralizer T \u2264 centralizer S :=\nset.centralizer_subset h\n\nvariables (M)\n\n@[simp, to_additive]\nlemma centralizer_univ : centralizer set.univ = center M :=\nset_like.ext' (set.centralizer_univ M)\n\nend\n\nend subsemigroup\n\n-- Guard against import creep\nassert_not_exists finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/subsemigroup/centralizer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7075422432459078}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, R\u00e9my Degenne\n-/\nimport data.set.intervals.basic\nimport data.set.pairwise.basic\nimport algebra.order.group.abs\nimport algebra.group_power.lemmas\n\n/-! ### Lemmas about arithmetic operations and intervals.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {\u03b1 : Type*}\n\nnamespace set\n\nsection ordered_comm_group\n\nvariables [ordered_comm_group \u03b1] {a b c d : \u03b1}\n\n/-! `inv_mem_Ixx_iff`, `sub_mem_Ixx_iff` -/\n@[to_additive] lemma inv_mem_Icc_iff : a\u207b\u00b9 \u2208 set.Icc c d \u2194 a \u2208 set.Icc (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_le' le_inv'\n@[to_additive] lemma inv_mem_Ico_iff : a\u207b\u00b9 \u2208 set.Ico c d \u2194 a \u2208 set.Ioc (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_lt' le_inv'\n@[to_additive] lemma inv_mem_Ioc_iff : a\u207b\u00b9 \u2208 set.Ioc c d \u2194 a \u2208 set.Ico (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_le' lt_inv'\n@[to_additive] lemma inv_mem_Ioo_iff : a\u207b\u00b9 \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_lt' lt_inv'\n\nend ordered_comm_group\n\nsection ordered_add_comm_group\n\nvariables [ordered_add_comm_group \u03b1] {a b c d : \u03b1}\n\n/-! `add_mem_Ixx_iff_left` -/\nlemma add_mem_Icc_iff_left : a + b \u2208 set.Icc c d \u2194 a \u2208 set.Icc (c - b) (d - b) :=\n(and_congr sub_le_iff_le_add le_sub_iff_add_le).symm\nlemma add_mem_Ico_iff_left : a + b \u2208 set.Ico c d \u2194 a \u2208 set.Ico (c - b) (d - b) :=\n(and_congr sub_le_iff_le_add lt_sub_iff_add_lt).symm\nlemma add_mem_Ioc_iff_left : a + b \u2208 set.Ioc c d \u2194 a \u2208 set.Ioc (c - b) (d - b) :=\n(and_congr sub_lt_iff_lt_add le_sub_iff_add_le).symm\nlemma add_mem_Ioo_iff_left : a + b \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (c - b) (d - b) :=\n(and_congr sub_lt_iff_lt_add lt_sub_iff_add_lt).symm\n\n/-! `add_mem_Ixx_iff_right` -/\nlemma add_mem_Icc_iff_right : a + b \u2208 set.Icc c d \u2194 b \u2208 set.Icc (c - a) (d - a) :=\n(and_congr sub_le_iff_le_add' le_sub_iff_add_le').symm\nlemma add_mem_Ico_iff_right : a + b \u2208 set.Ico c d \u2194 b \u2208 set.Ico (c - a) (d - a) :=\n(and_congr sub_le_iff_le_add' lt_sub_iff_add_lt').symm\nlemma add_mem_Ioc_iff_right : a + b \u2208 set.Ioc c d \u2194 b \u2208 set.Ioc (c - a) (d - a) :=\n(and_congr sub_lt_iff_lt_add' le_sub_iff_add_le').symm\nlemma add_mem_Ioo_iff_right : a + b \u2208 set.Ioo c d \u2194 b \u2208 set.Ioo (c - a) (d - a) :=\n(and_congr sub_lt_iff_lt_add' lt_sub_iff_add_lt').symm\n\n/-! `sub_mem_Ixx_iff_left` -/\nlemma sub_mem_Icc_iff_left : a - b \u2208 set.Icc c d \u2194 a \u2208 set.Icc (c + b) (d + b) :=\nand_congr le_sub_iff_add_le sub_le_iff_le_add\nlemma sub_mem_Ico_iff_left : a - b \u2208 set.Ico c d \u2194 a \u2208 set.Ico (c + b) (d + b) :=\nand_congr le_sub_iff_add_le sub_lt_iff_lt_add\nlemma sub_mem_Ioc_iff_left : a - b \u2208 set.Ioc c d \u2194 a \u2208 set.Ioc (c + b) (d + b) :=\nand_congr lt_sub_iff_add_lt sub_le_iff_le_add\nlemma sub_mem_Ioo_iff_left : a - b \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (c + b) (d + b) :=\nand_congr lt_sub_iff_add_lt sub_lt_iff_lt_add\n\n/-! `sub_mem_Ixx_iff_right` -/\nlemma sub_mem_Icc_iff_right : a - b \u2208 set.Icc c d \u2194 b \u2208 set.Icc (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_le_comm le_sub_comm\nlemma sub_mem_Ico_iff_right : a - b \u2208 set.Ico c d \u2194 b \u2208 set.Ioc (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_lt_comm le_sub_comm\nlemma sub_mem_Ioc_iff_right : a - b \u2208 set.Ioc c d \u2194 b \u2208 set.Ico (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_le_comm lt_sub_comm\nlemma sub_mem_Ioo_iff_right : a - b \u2208 set.Ioo c d \u2194 b \u2208 set.Ioo (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_lt_comm lt_sub_comm\n\n-- I think that symmetric intervals deserve attention and API: they arise all the time,\n-- for instance when considering metric balls in `\u211d`.\nlemma mem_Icc_iff_abs_le {R : Type*} [linear_ordered_add_comm_group R] {x y z : R} :\n  |x - y| \u2264 z \u2194 y \u2208 Icc (x - z) (x + z) :=\nabs_le.trans $ (and_comm _ _).trans $ and_congr sub_le_comm neg_le_sub_iff_le_add\n\nend ordered_add_comm_group\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1]\n\n/-- If we remove a smaller interval from a larger, the result is nonempty -/\nlemma nonempty_Ico_sdiff {x dx y dy : \u03b1} (h : dy < dx) (hx : 0 < dx) :\n  nonempty \u21a5(Ico x (x + dx) \\ Ico y (y + dy)) :=\nbegin\n  cases lt_or_le x y with h' h',\n  { use x, simp [*, not_le.2 h'] },\n  { use max x (x + dy), simp [*, le_refl] }\nend\n\nend linear_ordered_add_comm_group\n\n/-! ### Lemmas about disjointness of translates of intervals -/\nsection pairwise_disjoint\n\nsection ordered_comm_group\n\nvariables [ordered_comm_group \u03b1] (a b : \u03b1)\n\n@[to_additive]\nlemma pairwise_disjoint_Ioc_mul_zpow  :\n  pairwise (disjoint on \u03bb n : \u2124, Ioc (a * b ^ n) (a * b ^ (n + 1))) :=\nbegin\n  simp_rw [function.on_fun, set.disjoint_iff],\n  intros m n hmn x hx,\n  apply hmn,\n  have hb : 1 < b,\n  { have : a * b ^ m < a * b ^ (m + 1), from hx.1.1.trans_le hx.1.2,\n    rwa [mul_lt_mul_iff_left, \u2190mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this },\n  have i1 := hx.1.1.trans_le hx.2.2,\n  have i2 := hx.2.1.trans_le hx.1.2,\n  rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, int.lt_add_one_iff] at i1 i2,\n  exact le_antisymm i1 i2\nend\n\n@[to_additive]\nlemma pairwise_disjoint_Ico_mul_zpow :\n  pairwise (disjoint on \u03bb n : \u2124, Ico (a * b ^ n) (a * b ^ (n + 1))) :=\nbegin\n  simp_rw [function.on_fun, set.disjoint_iff],\n  intros m n hmn x hx,\n  apply hmn,\n  have hb : 1 < b,\n  { have : a * b ^ m < a * b ^ (m + 1), from hx.1.1.trans_lt hx.1.2,\n    rwa [mul_lt_mul_iff_left, \u2190mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this },\n  have i1 := hx.1.1.trans_lt hx.2.2,\n  have i2 := hx.2.1.trans_lt hx.1.2,\n  rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, int.lt_add_one_iff] at i1 i2,\n  exact le_antisymm i1 i2,\nend\n\n@[to_additive]\n\n\n@[to_additive]\nlemma pairwise_disjoint_Ioc_zpow :\n  pairwise (disjoint on \u03bb n : \u2124, Ioc (b ^ n) (b ^ (n + 1))) :=\nby simpa only [one_mul] using pairwise_disjoint_Ioc_mul_zpow 1 b\n\n@[to_additive]\nlemma pairwise_disjoint_Ico_zpow :\n  pairwise (disjoint on \u03bb n : \u2124, Ico (b ^ n) (b ^ (n + 1))) :=\nby simpa only [one_mul] using pairwise_disjoint_Ico_mul_zpow 1 b\n\n@[to_additive]\nlemma pairwise_disjoint_Ioo_zpow :\n  pairwise (disjoint on \u03bb n : \u2124, Ioo (b ^ n) (b ^ (n + 1))) :=\nby simpa only [one_mul] using pairwise_disjoint_Ioo_mul_zpow 1 b\n\nend ordered_comm_group\n\nsection ordered_ring\n\nvariables [ordered_ring \u03b1] (a : \u03b1)\n\nlemma pairwise_disjoint_Ioc_add_int_cast :\n  pairwise (disjoint on \u03bb n : \u2124, Ioc (a + n) (a + n + 1)) :=\nby simpa only [zsmul_one, int.cast_add, int.cast_one, \u2190add_assoc]\n  using pairwise_disjoint_Ioc_add_zsmul a (1 : \u03b1)\n\nlemma pairwise_disjoint_Ico_add_int_cast :\n  pairwise (disjoint on \u03bb n : \u2124, Ico (a + n) (a + n + 1)) :=\nby simpa only [zsmul_one, int.cast_add, int.cast_one, \u2190add_assoc]\n  using pairwise_disjoint_Ico_add_zsmul a (1 : \u03b1)\n\nlemma pairwise_disjoint_Ioo_add_int_cast :\n  pairwise (disjoint on \u03bb n : \u2124, Ioo (a + n) (a + n + 1)) :=\nby simpa only [zsmul_one, int.cast_add, int.cast_one, \u2190add_assoc]\n  using pairwise_disjoint_Ioo_add_zsmul a (1 : \u03b1)\n\nvariables (\u03b1)\n\nlemma pairwise_disjoint_Ico_int_cast : pairwise (disjoint on \u03bb n : \u2124, Ico (n : \u03b1) (n + 1)) :=\nby simpa only [zero_add] using pairwise_disjoint_Ico_add_int_cast (0 : \u03b1)\n\nlemma pairwise_disjoint_Ioo_int_cast : pairwise (disjoint on \u03bb n : \u2124, Ioo (n : \u03b1) (n + 1)) :=\nby simpa only [zero_add] using pairwise_disjoint_Ioo_add_int_cast (0 : \u03b1)\n\nlemma pairwise_disjoint_Ioc_int_cast : pairwise (disjoint on \u03bb n : \u2124, Ioc (n : \u03b1) (n + 1)) :=\nby simpa only [zero_add] using pairwise_disjoint_Ioc_add_int_cast (0 : \u03b1)\n\nend ordered_ring\n\nend pairwise_disjoint\n\nend set\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/set/intervals/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7075422377811906}}
{"text": "import analysis.topology.continuity\nuniverse u \n\nnamespace tactic\nnamespace interactive\n\nopen interactive interactive.types\n\n/-\nhttps://leanprover.zulipchat.com/#narrow/stream/113488-general/subject/cases.20eliminating.20into.20type/near/125695647\n-/\nmeta def ccases (e : parse cases_arg_p) (ids : parse with_ident_list) :=\ndo cases (e.1,``(classical.indefinite_description _ %%(e.2))) ids\n\nend interactive\nend tactic\n\nopen topological_space\n--TODO -- find out whether this stuff is now in mathlib\n-- https://github.com/leanprover-community/mathlib/blob/9d743bbb864234821c4ec881d4dc930ac3631838/analysis/topology/continuity.lean#L401\n\nstructure topological_space.open_immersion\n  {\u03b1 : Type u} [T\u03b1 : topological_space \u03b1]\n  {\u03b2 : Type u} [T\u03b2 : topological_space \u03b2]\n  (f : \u03b1 \u2192 \u03b2) : Prop :=\n(fcont : continuous f)\n(finj : function.injective f)\n(fopens : \u2200 U : set \u03b1, is_open U \u2194 is_open (f '' U))\n\ntheorem topological_space.open_immersion_id\n  (\u03b1 : Type u) [T\u03b1 : topological_space \u03b1] : topological_space.open_immersion (@id \u03b1) := \n\u27e8continuous_id,function.injective_id,\u03bb _,by rw set.image_id\u27e9\n\nlemma topological_space.open_of_open_immersion_open \n  {\u03b1 : Type*} [T\u03b1 : topological_space \u03b1]\n  {\u03b2 : Type*} [T\u03b2 : topological_space \u03b2]\n  (f : \u03b1 \u2192 \u03b2) (H : topological_space.open_immersion f) : \n\u2200 U : set \u03b1, is_open U \u2192 is_open (f '' U) := \u03bb U OU, (H.fopens U).1 OU\n\ndef topological_space.open_immersion' {X Y : Type u} [tX : topological_space X] [tY : topological_space Y] (\u03c6 : X \u2192 Y) :=\n  continuous \u03c6 \u2227\n  function.injective \u03c6 \u2227\n  \u2200 U : set X, tX.is_open U \u2192 tY.is_open (set.image \u03c6 U)\n\n--#check compact\n-- note compact_elim_finite_subcover and compact_of_finite_subcover\n\n\n-- can I use ccases for this?\nlemma topological_space.Union_basis_elements_of_open {\u03b1 : Type u} [topological_space \u03b1]\n{B : set (set \u03b1)} (HB : is_topological_basis B) {U : set \u03b1} (HU : is_open U) :\n\u2203 (\u03b2 : Type u) (f : \u03b2 \u2192 set \u03b1), U = set.Union f \u2227 \u2200 i : \u03b2, f i \u2208 B := \nbegin\n  let \u03b2 := {x : \u03b1 // x \u2208 U},\n  existsi \u03b2,\n  have f0 := \u03bb i : \u03b2, (mem_basis_subset_of_mem_open HB i.property HU),\n  let f := \u03bb i, classical.some (f0 i),\n  have f1 : \u2200 (i : \u03b2), \u2203 (H : (f i) \u2208 B), (i.val \u2208 (f i) \u2227 (f i) \u2286 U) := \u03bb i, classical.some_spec (f0 i),\n  let g := \u03bb i, classical.some (f1 i),\n  have g1 : \u2200 (i : \u03b2), (i.val \u2208 f i \u2227 f i \u2286 U) := \u03bb i, classical.some_spec (f1 i),\n  existsi f,\n  split,\n  { rw set.subset.antisymm_iff,\n    split,\n    { intros y Hy,\n      let i : \u03b2 := \u27e8y,Hy\u27e9,\n      existsi (f \u27e8y,Hy\u27e9),\n      constructor,\n        existsi i,\n        refl,\n      exact (g1 i).left,\n    },\n    { intros y Hy,\n      cases Hy with V HV,cases HV with HV Hy,cases HV with i Hi,\n      apply (g1 i).2,\n      rwa \u2190Hi,\n    },\n  },\n  { intro i,\n    exact g i\n  }\nend\n\n-- here's Mario's better proof\n/-\nlemma sUnion_basis_elements_of_open {\u03b1 : Type u} [topological_space \u03b1]\n{B : set (set \u03b1)} (HB : is_topological_basis B) {U : set \u03b1} (HU : is_open U) :\n\u2203 (S : set (set \u03b1)), U = \u22c3\u2080 S \u2227 S \u2286 B :=\n\u27e8{b \u2208 B | b \u2286 U}, set.ext (\u03bb a,\n   \u27e8\u03bb ha, let \u27e8b, hb, ab, bu\u27e9 := mem_basis_subset_of_mem_open HB _ ha HU in\n              \u27e8b, \u27e8hb, bu\u27e9, ab\u27e9,\n    \u03bb \u27e8b, \u27e8hb, bu\u27e9, ab\u27e9, bu ab\u27e9),\n \u03bb b h, h.1\u27e9\n\nlemma Union_basis_elements_of_open {\u03b1 : Type u} [topological_space \u03b1]\n{B : set (set \u03b1)} (HB : is_topological_basis B) {U : set \u03b1} (HU : is_open U) :\n\u2203 (\u03b2 : Type u) (f : \u03b2 \u2192 set \u03b1), U = (\u22c3 i, f i) \u2227 \u2200 i : \u03b2, f i \u2208 B :=\nlet \u27e8S, su, sb\u27e9 := sUnion_basis_elemnts_of_open HB HU in\n\u27e8S, subtype.val, su.trans set.sUnion_eq_Union', \u03bb \u27e8b, h\u27e9, sb h\u27e9\n-/\n\n-- this next lemma will go to mathlib one day. It's in tag00E8 currently\n\n/-\nlemma mem_subset_basis_of_mem_open {X : Type u} [T : topological_space X] {b : set (set X)}\n  (hb : topological_space.is_topological_basis b) {a:X} (u : set X) (au : a \u2208 u)\n  (ou : _root_.is_open u) : \u2203v \u2208 b, a \u2208 v \u2227 v \u2286 u :=\n(topological_space.mem_nhds_of_is_topological_basis hb).1 $ mem_nhds_sets ou au\n-/", "meta": {"author": "kbuzzard", "repo": "lean-stacks-project", "sha": "b57be17aa917f1c3a23c59db5ee37b1aa21112c2", "save_path": "github-repos/lean/kbuzzard-lean-stacks-project", "path": "github-repos/lean/kbuzzard-lean-stacks-project/lean-stacks-project-b57be17aa917f1c3a23c59db5ee37b1aa21112c2/src/mathlib_someday/topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7075422350325121}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov, Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Anne Baanen\n-/\nimport data.fintype.card\nimport data.fintype.fin\nimport logic.equiv.fin\n\n/-!\n# Big operators and `fin`\n\nSome results about products and sums over the type `fin`.\n\nThe most important results are the induction formulas `fin.prod_univ_cast_succ`\nand `fin.prod_univ_succ`, and the formula `fin.prod_const` for the product of a\nconstant function. These results have variants for sums instead of products.\n\n-/\n\nopen_locale big_operators\n\nopen finset\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n\nnamespace finset\n\n@[to_additive]\ntheorem prod_range [comm_monoid \u03b2] {n : \u2115} (f : \u2115 \u2192 \u03b2) :\n  \u220f i in finset.range n, f i = \u220f i : fin n, f i :=\nprod_bij'\n  (\u03bb k w, \u27e8k, mem_range.mp w\u27e9)\n  (\u03bb a ha, mem_univ _)\n  (\u03bb a ha, congr_arg _ (fin.coe_mk _).symm)\n  (\u03bb a m, a)\n  (\u03bb a m, mem_range.mpr a.prop)\n  (\u03bb a ha, fin.coe_mk _)\n  (\u03bb a ha, fin.eta _ _)\n\nend finset\n\nnamespace fin\n\n@[to_additive]\ntheorem prod_univ_def [comm_monoid \u03b2] {n : \u2115} (f : fin n \u2192 \u03b2) :\n  \u220f i, f i = ((list.fin_range n).map f).prod :=\nby simp [univ_def, finset.fin_range]\n\n@[to_additive]\ntheorem prod_of_fn [comm_monoid \u03b2] {n : \u2115} (f : fin n \u2192 \u03b2) :\n  (list.of_fn f).prod = \u220f i, f i :=\nby rw [list.of_fn_eq_map, prod_univ_def]\n\n/-- A product of a function `f : fin 0 \u2192 \u03b2` is `1` because `fin 0` is empty -/\n@[to_additive \"A sum of a function `f : fin 0 \u2192 \u03b2` is `0` because `fin 0` is empty\"]\ntheorem prod_univ_zero [comm_monoid \u03b2] (f : fin 0 \u2192 \u03b2) : \u220f i, f i = 1 := rfl\n\n/-- A product of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the product of `f x`, for some `x : fin (n + 1)` times the remaining product -/\n@[to_additive\n/- A sum of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the sum of `f x`, for some `x : fin (n + 1)` plus the remaining product -/]\ntheorem prod_univ_succ_above [comm_monoid \u03b2] {n : \u2115} (f : fin (n + 1) \u2192 \u03b2) (x : fin (n + 1)) :\n  \u220f i, f i = f x * \u220f i : fin n, f (x.succ_above i) :=\nby rw [univ_succ_above, prod_cons, finset.prod_map, rel_embedding.coe_fn_to_embedding]\n\n/-- A product of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the product of `f 0` plus the remaining product -/\n@[to_additive\n/- A sum of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the sum of `f 0` plus the remaining product -/]\ntheorem prod_univ_succ [comm_monoid \u03b2] {n : \u2115} (f : fin (n + 1) \u2192 \u03b2) :\n  \u220f i, f i = f 0 * \u220f i : fin n, f i.succ :=\nprod_univ_succ_above f 0\n\n/-- A product of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the product of `f (fin.last n)` plus the remaining product -/\n@[to_additive\n/- A sum of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the sum of `f (fin.last n)` plus the remaining sum -/]\ntheorem prod_univ_cast_succ [comm_monoid \u03b2] {n : \u2115} (f : fin (n + 1) \u2192 \u03b2) :\n  \u220f i, f i = (\u220f i : fin n, f i.cast_succ) * f (last n) :=\nby simpa [mul_comm] using prod_univ_succ_above f (last n)\n\n@[to_additive] lemma prod_cons [comm_monoid \u03b2] {n : \u2115} (x : \u03b2) (f : fin n \u2192 \u03b2) :\n  \u220f i : fin n.succ, (cons x f : fin n.succ \u2192 \u03b2) i = x * \u220f i : fin n, f i :=\nby simp_rw [prod_univ_succ, cons_zero, cons_succ]\n\n@[to_additive sum_univ_one] theorem prod_univ_one [comm_monoid \u03b2] (f : fin 1 \u2192 \u03b2) :\n  \u220f i, f i = f 0 :=\nby simp\n\n@[to_additive] theorem prod_univ_two [comm_monoid \u03b2] (f : fin 2 \u2192 \u03b2) :\n  \u220f i, f i = f 0 * f 1 :=\nby simp [prod_univ_succ]\n\nlemma sum_pow_mul_eq_add_pow {n : \u2115} {R : Type*} [comm_semiring R] (a b : R) :\n  \u2211 s : finset (fin n), a ^ s.card * b ^ (n - s.card) = (a + b) ^ n :=\nby simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b\n\nlemma prod_const [comm_monoid \u03b1] (n : \u2115) (x : \u03b1) : \u220f i : fin n, x = x ^ n := by simp\n\nlemma sum_const [add_comm_monoid \u03b1] (n : \u2115) (x : \u03b1) : \u2211 i : fin n, x = n \u2022 x := by simp\n\n@[to_additive] lemma prod_Ioi_zero {M : Type*} [comm_monoid M] {n : \u2115} {v : fin n.succ \u2192 M} :\n  \u220f i in Ioi 0, v i = \u220f j : fin n, v j.succ :=\nby rw [Ioi_zero_eq_map, finset.prod_map, rel_embedding.coe_fn_to_embedding, coe_succ_embedding]\n\n@[to_additive]\nlemma prod_Ioi_succ {M : Type*} [comm_monoid M] {n : \u2115} (i : fin n) (v : fin n.succ \u2192 M) :\n  \u220f j in Ioi i.succ, v j = \u220f j in Ioi i, v j.succ :=\nby rw [Ioi_succ, finset.prod_map, rel_embedding.coe_fn_to_embedding, coe_succ_embedding]\n\n@[to_additive]\nlemma prod_congr' {M : Type*} [comm_monoid M] {a b : \u2115} (f : fin b \u2192 M) (h : a = b) :\n  \u220f (i : fin a), f (cast h i) = \u220f (i : fin b), f i :=\nby { subst h, congr, ext, congr, ext, rw coe_cast, }\n\n@[to_additive]\nlemma prod_univ_add {M : Type*} [comm_monoid M] {a b : \u2115} (f : fin (a+b) \u2192 M) :\n  \u220f (i : fin (a+b)), f i =\n  (\u220f (i : fin a), f (cast_add b i)) * \u220f (i : fin b), f (nat_add a i) :=\nbegin\n  rw fintype.prod_equiv fin_sum_fin_equiv.symm f (\u03bb i, f (fin_sum_fin_equiv.to_fun i)), swap,\n  { intro x,\n    simp only [equiv.to_fun_as_coe, equiv.apply_symm_apply], },\n  apply prod_on_sum,\nend\n\n@[to_additive]\nlemma prod_trunc {M : Type*} [comm_monoid M] {a b : \u2115} (f : fin (a+b) \u2192 M)\n  (hf : \u2200 (j : fin b), f (nat_add a j) = 1) :\n  \u220f (i : fin (a+b)), f i =\n  \u220f (i : fin a), f (cast_le (nat.le.intro rfl) i) :=\nby simpa only [prod_univ_add, fintype.prod_eq_one _ hf, mul_one]\n\nend fin\n\nnamespace list\n\n@[to_additive]\nlemma prod_take_of_fn [comm_monoid \u03b1] {n : \u2115} (f : fin n \u2192 \u03b1) (i : \u2115) :\n  ((of_fn f).take i).prod = \u220f j in finset.univ.filter (\u03bb (j : fin n), j.val < i), f j :=\nbegin\n  have A : \u2200 (j : fin n), \u00ac ((j : \u2115) < 0) := \u03bb j, not_lt_bot,\n  induction i with i IH, { simp [A] },\n  by_cases h : i < n,\n  { have : i < length (of_fn f), by rwa [length_of_fn f],\n    rw prod_take_succ _ _ this,\n    have A : ((finset.univ : finset (fin n)).filter (\u03bb j, j.val < i + 1))\n      = ((finset.univ : finset (fin n)).filter (\u03bb j, j.val < i)) \u222a {(\u27e8i, h\u27e9 : fin n)},\n        by { ext j, simp [nat.lt_succ_iff_lt_or_eq, fin.ext_iff, - add_comm] },\n    have B : _root_.disjoint (finset.filter (\u03bb (j : fin n), j.val < i) finset.univ)\n      (singleton (\u27e8i, h\u27e9 : fin n)), by simp,\n    rw [A, finset.prod_union B, IH],\n    simp },\n  { have A : (of_fn f).take i = (of_fn f).take i.succ,\n    { rw \u2190 length_of_fn f at h,\n      have : length (of_fn f) \u2264 i := not_lt.mp h,\n      rw [take_all_of_le this, take_all_of_le (le_trans this (nat.le_succ _))] },\n    have B : \u2200 (j : fin n), ((j : \u2115) < i.succ) = ((j : \u2115) < i),\n    { assume j,\n      have : (j : \u2115) < i := lt_of_lt_of_le j.2 (not_lt.mp h),\n      simp [this, lt_trans this (nat.lt_succ_self _)] },\n    simp [\u2190 A, B, IH] }\nend\n\n@[to_additive]\nlemma prod_of_fn [comm_monoid \u03b1] {n : \u2115} {f : fin n \u2192 \u03b1} :\n  (of_fn f).prod = \u220f i, f i :=\nbegin\n  convert prod_take_of_fn f n,\n  { rw [take_all_of_le (le_of_eq (length_of_fn f))] },\n  { have : \u2200 (j : fin n), (j : \u2115) < n := \u03bb j, j.is_lt,\n    simp [this] }\nend\n\nlemma alternating_sum_eq_finset_sum {G : Type*} [add_comm_group G] :\n  \u2200 (L : list G), alternating_sum L = \u2211 i : fin L.length, (-1 : \u2124) ^ (i : \u2115) \u2022 L.nth_le i i.is_lt\n| [] := by { rw [alternating_sum, finset.sum_eq_zero], rintro \u27e8i, \u27e8\u27e9\u27e9 }\n| (g :: []) := by simp\n| (g :: h :: L) :=\ncalc g + -h + L.alternating_sum\n    = g + -h + \u2211 i : fin L.length, (-1 : \u2124) ^ (i : \u2115) \u2022 L.nth_le i i.2 :\n      congr_arg _ (alternating_sum_eq_finset_sum _)\n... = \u2211 i : fin (L.length + 2), (-1 : \u2124) ^ (i : \u2115) \u2022 list.nth_le (g :: h :: L) i _ :\nbegin\n  rw [fin.sum_univ_succ, fin.sum_univ_succ, add_assoc],\n  unfold_coes,\n  simp [nat.succ_eq_add_one, pow_add],\n  refl,\nend\n\n@[to_additive]\nlemma alternating_prod_eq_finset_prod {G : Type*} [comm_group G] :\n  \u2200 (L : list G), alternating_prod L = \u220f i : fin L.length, (L.nth_le i i.2) ^ ((-1 : \u2124) ^ (i : \u2115))\n| [] := by { rw [alternating_prod, finset.prod_eq_one], rintro \u27e8i, \u27e8\u27e9\u27e9 }\n| (g :: []) :=\nbegin\n  show g = \u220f i : fin 1, [g].nth_le i i.2 ^ (-1 : \u2124) ^ (i : \u2115),\n  rw [fin.prod_univ_succ], simp,\nend\n| (g :: h :: L) :=\ncalc g * h\u207b\u00b9 * L.alternating_prod\n    = g * h\u207b\u00b9 * \u220f i : fin L.length, L.nth_le i i.2 ^ (-1 : \u2124) ^ (i : \u2115) :\n      congr_arg _ (alternating_prod_eq_finset_prod _)\n... = \u220f i : fin (L.length + 2), list.nth_le (g :: h :: L) i _ ^ (-1 : \u2124) ^ (i : \u2115) :\nbegin\n  rw [fin.prod_univ_succ, fin.prod_univ_succ, mul_assoc],\n  unfold_coes,\n  simp [nat.succ_eq_add_one, pow_add],\n  refl,\nend\n\nend list\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/algebra/big_operators/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7075422335290413}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThe reflexive and transitive closure of a symmetric relation\nis still symmetric.\n-/\n\nimport logic.relation\n\nnamespace relation\n\nopen relation \n\nlemma refl_trans_gen_symm (\u03b1 : Type*) (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (r_symm : symmetric r)  \n {a b : \u03b1} (h : refl_trans_gen r a b) : (refl_trans_gen r b a) := \n  @refl_trans_gen.trans_induction_on \u03b1 r (\u03bb x y _, refl_trans_gen r y x)\n   a b h\n   (\u03bb x, refl_trans_gen.refl)\n   (\u03bb x y h,refl_trans_gen.single (r_symm h))\n   (\u03bb x y z hxy hyz hyx hzy, refl_trans_gen.trans hzy hyx)\n\nend relation", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/logic/relation_extra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783526, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.7074857117328406}}
{"text": "import algebra.geom_sum\nimport data.finset\nimport data.fintype\nimport data.list\nimport tactic\n\nopen fintype\nopen finset\n\nvariables {n : \u2115}\nlocal notation `X` := fin n\nvariables {\ud835\udc9c : finset (finset X)}\n\nlemma union_singleton_eq_insert {\u03b1 : Type*} [decidable_eq \u03b1] (a : \u03b1) (s : finset \u03b1) : finset.singleton a \u222a s = insert a s := begin ext, rw [mem_insert, mem_union, mem_singleton] end\n\nlemma mem_powerset_len_iff_card {r : \u2115} : \u2200 (x : finset X), x \u2208 powerset_len r (elems X) \u2194 card x = r :=\nby intro x; rw mem_powerset_len; exact and_iff_right (subset_univ _)\n\ndef example1 : finset (finset (fin 5)) :=\n{ {0,1,2}, {0,1,3}, {0,2,3}, {0,2,4} } \n\nsection layers\n  variables {r : \u2115}\n\n  def is_layer (\ud835\udc9c : finset (finset X)) (r : \u2115) : Prop := \u2200 A \u2208 \ud835\udc9c, card A = r\n\n  lemma union_layer {A B : finset (finset X)} : is_layer A r \u2227 is_layer B r \u2194 is_layer (A \u222a B) r :=\n  begin\n    split; intros p, \n      rw is_layer,\n      intros,\n      rw mem_union at H,\n      cases H,\n        exact (p.1 _ H),\n        exact (p.2 _ H),\n    split,\n    all_goals {rw is_layer, intros, apply p, rw mem_union, tauto}, \n  end\n\n  lemma powerset_len_iff_is_layer : is_layer \ud835\udc9c r \u2194 \ud835\udc9c \u2286 powerset_len r (elems X) :=\n  begin\n    split; intros p A h,\n      rw mem_powerset_len_iff_card,\n      exact (p _ h),\n    rw \u2190 mem_powerset_len_iff_card, \n    exact p h\n  end\n\n  lemma size_in_layer (h : is_layer \ud835\udc9c r) : card \ud835\udc9c \u2264 nat.choose (card X) r :=\n  begin\n    rw [fintype.card, \u2190 card_powerset_len],\n    apply card_le_of_subset,\n    rwa [univ, \u2190 powerset_len_iff_is_layer]\n  end\nend layers\n\nlemma bind_sub_bind_of_sub_left {\u03b1 \u03b2 : Type*} [decidable_eq \u03b2] {s\u2081 s\u2082 : finset \u03b1} {t : \u03b1 \u2192 finset \u03b2} (h : s\u2081 \u2286 s\u2082) : s\u2081.bind t \u2286 s\u2082.bind t :=\nby intro x; simp; intros y hy hty; refine \u27e8y, h hy, hty\u27e9\n\nsection shadow\n  def all_removals (A : finset X) : finset (finset X) := A.image (erase A)\n\n  lemma all_removals_size {A : finset X} {r : \u2115} (h : A.card = r) : is_layer (all_removals A) (r-1) := \n  begin\n    intros B H,\n    rw [all_removals, mem_image] at H,\n    rcases H with \u27e8i, ih, Bh\u27e9,\n    rw [\u2190 Bh, card_erase_of_mem ih, h], refl\n  end\n\n  def mem_all_removals {A : finset X} {B : finset X} : B \u2208 all_removals A \u2194 \u2203 i \u2208 A, erase A i = B :=\n  by simp only [all_removals, mem_image]\n\n  lemma card_all_removals {A : finset X} {r : \u2115} (H : card A = r) : (all_removals A).card = r :=\n  begin\n    rwa [all_removals, card_image_of_inj_on],\n    intros i ih j _ k,\n    have q: i \u2209 erase A j := k \u25b8 not_mem_erase i A,\n    rw [mem_erase, not_and] at q,\n    by_contra a, apply q a ih\n  end\n\n  def shadow (\ud835\udc9c : finset (finset X)) : finset (finset X) := \ud835\udc9c.bind all_removals\n\n  reserve prefix `\u2202`:90\n  notation \u2202\ud835\udc9c := shadow \ud835\udc9c\n\n  def mem_shadow (B : finset X) : B \u2208 shadow \ud835\udc9c \u2194 \u2203 A \u2208 \ud835\udc9c, \u2203 i \u2208 A, erase A i = B := \n  by simp only [shadow, all_removals, mem_bind, mem_image]\n\n  def mem_shadow' {B : finset X} : B \u2208 shadow \ud835\udc9c \u2194 \u2203 j \u2209 B, insert j B \u2208 \ud835\udc9c :=\n  begin\n    rw mem_shadow,\n    split,\n      rintro \u27e8A, HA, i, Hi, k\u27e9,\n      rw \u2190 k,\n      refine \u27e8i, not_mem_erase i A, _\u27e9,\n      rwa insert_erase Hi,\n    rintro \u27e8i, Hi, k\u27e9,\n      refine \u27e8insert i B, k, i, mem_insert_self _ _, _\u27e9,\n      rw erase_insert Hi\n  end\n\n  lemma shadow_layer {r : \u2115} : is_layer \ud835\udc9c r \u2192 is_layer (\u2202\ud835\udc9c) (r-1) :=\n  begin\n    intros a A H,\n    rw [shadow, mem_bind] at H,\n    rcases H with \u27e8B, _, _\u27e9,\n    exact all_removals_size (a _ \u2039_\u203a) _ \u2039A \u2208 all_removals B\u203a,\n  end\n\n  def sub_of_shadow {B : finset X} : B \u2208 \u2202\ud835\udc9c \u2192 \u2203 A \u2208 \ud835\udc9c, B \u2286 A :=\n  begin\n    intro k,\n    rw mem_shadow at k,\n    rcases k with \u27e8A, H, _, _, k\u27e9,\n    rw \u2190 k,\n    exact \u27e8A, H, erase_subset _ _\u27e9\n  end\n\n  def sub_iff_shadow_one {B : finset X} : B \u2208 shadow \ud835\udc9c \u2194 \u2203 A \u2208 \ud835\udc9c, B \u2286 A \u2227 card (A \\ B) = 1 :=\n  begin\n    rw mem_shadow', split, \n      rintro \u27e8i, ih, inA\u27e9,\n      refine \u27e8insert i B, inA, subset_insert _ _, _\u27e9, rw card_sdiff (subset_insert _ _), rw card_insert_of_not_mem ih, simp,\n    rintro \u27e8A, hA, _\u27e9,\n    rw card_eq_one at a_h_h, rcases a_h_h with \u27e8subs, j, eq\u27e9, \n    use j, refine \u27e8_, _\u27e9, \n    intro, have: j \u2208 finset.singleton j, rw mem_singleton, rw \u2190 eq at this, rw mem_sdiff at this, exact this.2 a, \n    rw \u2190 union_singleton_eq_insert, rw \u2190 eq, rwa sdiff_union_of_subset subs, \n  end\n\n  def sub_iff_shadow_iter {B : finset X} (k : \u2115) : B \u2208 nat.iterate shadow k \ud835\udc9c \u2194 \u2203 A \u2208 \ud835\udc9c, B \u2286 A \u2227 card (A \\ B) = k :=\n  begin\n    revert \ud835\udc9c B,\n    induction k with k ih,\n      simp, intros \ud835\udc9c B, \n      split,\n        intro p, refine \u27e8B, p, subset.refl _, _\u27e9, apply eq_empty_of_forall_not_mem, intro x, rw mem_sdiff, tauto,\n      rintro \u27e8A, _, _\u27e9, rw sdiff_eq_empty_iff_subset at a_h_right, have: A = B := subset.antisymm a_h_right.2 a_h_right.1,\n      rwa \u2190 this,\n    simp, intros \ud835\udc9c B, have := @ih (\u2202\ud835\udc9c) B,\n    rw this, clear this ih,\n    split, \n      rintro \u27e8A, hA, BsubA, card_AdiffB_is_k\u27e9, rw sub_iff_shadow_one at hA, rcases hA with \u27e8C, CinA, AsubC, card_CdiffA_is_1\u27e9,\n      refine \u27e8C, CinA, trans BsubA AsubC, _\u27e9,\n      rw card_sdiff (trans BsubA AsubC), rw card_sdiff BsubA at card_AdiffB_is_k, rw card_sdiff AsubC at card_CdiffA_is_1,\n      by calc card C - card B = (card C - card A + card A) - card B : begin rw nat.sub_add_cancel, apply card_le_of_subset AsubC end \n      ... = (card C - card A) + (card A - card B) : begin rw nat.add_sub_assoc, apply card_le_of_subset BsubA end\n      ... = k + 1 : begin rw [card_CdiffA_is_1, card_AdiffB_is_k, add_comm] end,\n    rintro \u27e8A, hA, _, _\u27e9, \n    have z: A \\ B \u2260 \u2205, rw \u2190 card_pos, rw a_h_right_right, exact nat.succ_pos _,\n    rw [ne, \u2190 exists_mem_iff_ne_empty] at z, \n    rcases z with \u27e8i, hi\u27e9,\n    have: i \u2208 A, rw mem_sdiff at hi, exact hi.1,\n    have: B \u2286 erase A i, { intros t th, apply mem_erase_of_ne_of_mem _ (a_h_right_left th), intro, rw mem_sdiff at hi, rw a at th, exact hi.2 th },\n    refine \u27e8erase A i, _, \u2039_\u203a, _\u27e9,\n    { rw mem_shadow, refine \u27e8A, hA, i, \u2039_\u203a, rfl\u27e9 }, \n    rw card_sdiff \u2039B \u2286 erase A i\u203a, rw card_erase_of_mem \u2039i \u2208 A\u203a, rw nat.pred_sub, rw \u2190 card_sdiff a_h_right_left, rw a_h_right_right, simp,\n  end\nend shadow\n\n#eval shadow example1\n\nsection local_lym\n  lemma multiply_out {A B n r : \u2115} (hr1 : 1 \u2264 r) (hr2 : r \u2264 n)\n    (h : A * r \u2264 B * (n - r + 1)) : (A : \u211a) / (nat.choose n r) \u2264 B / nat.choose n (r-1) :=\n  begin\n    rw div_le_div_iff; norm_cast,\n    apply le_of_mul_le_mul_right _ \u20390 < r\u203a,\n    cases r,\n      simp,\n    rw nat.succ_eq_add_one at *,\n    rw [\u2190 nat.sub_add_comm hr2, nat.add_sub_add_right] at h,\n    rw [nat.add_sub_cancel, mul_assoc B, nat.choose_succ_right_eq, mul_right_comm, \u2190 mul_assoc, mul_right_comm B], \n    exact nat.mul_le_mul_right _ h,\n    apply nat.choose_pos hr2,\n    apply nat.choose_pos (le_trans (nat.pred_le _) hr2)\n  end\n\n  def the_pairs (\ud835\udc9c : finset (finset X)) : finset (finset X \u00d7 finset X) :=\n  \ud835\udc9c.bind (\u03bb A, (all_removals A).image (prod.mk A))\n\n  lemma card_the_pairs {r : \u2115} (\ud835\udc9c : finset (finset X)) : is_layer \ud835\udc9c r \u2192 (the_pairs \ud835\udc9c).card = \ud835\udc9c.card * r :=\n  begin\n    intro, rw [the_pairs, card_bind],\n    { convert (sum_congr rfl _),\n      { rw [\u2190 nat.smul_eq_mul, \u2190 sum_const] }, \n      intros,\n      rw [card_image_of_inj_on, card_all_removals (a _ H)],\n      exact (\u03bb _ _ _ _ k, (prod.mk.inj k).2) },\n    simp only [disjoint_left, mem_image],\n    rintros _ _ _ _ k a \u27e8_, _, a\u2081\u27e9 \u27e8_, _, a\u2082\u27e9,\n    exact k (prod.mk.inj (a\u2081.trans a\u2082.symm)).1,\n  end\n\n  def from_below (\ud835\udc9c : finset (finset X)) : finset (finset X \u00d7 finset X) :=\n  (\u2202\ud835\udc9c).bind (\u03bb B, (univ \\ B).image (\u03bb x, (insert x B, B)))\n\n  lemma mem_the_pairs (A B : finset X) : (A,B) \u2208 the_pairs \ud835\udc9c \u2194 A \u2208 \ud835\udc9c \u2227 B \u2208 all_removals A :=\n  begin\n    simp only [the_pairs, mem_bind, mem_image],\n    split, \n    { rintro \u27e8a, Ha, b, Hb, h\u27e9, \n      rw [(prod.mk.inj h).1, (prod.mk.inj h).2] at *,\n      exact \u27e8Ha, Hb\u27e9 },\n    { intro h, exact \u27e8A, h.1, B, h.2, rfl\u27e9}\n  end\n\n  lemma mem_from_below (A B : finset X) : A \u2208 \ud835\udc9c \u2227 (\u2203 (i \u2209 B), insert i B = A) \u2192 (A,B) \u2208 from_below \ud835\udc9c :=\n  begin\n    rw [from_below, mem_bind],\n    rintro \u27e8Ah, i, ih, a\u27e9,\n    refine \u27e8B, _, _\u27e9,\n      rw mem_shadow',\n      refine \u27e8i, ih, a.symm \u25b8 Ah\u27e9,\n    rw mem_image,\n    refine \u27e8i, mem_sdiff.2 \u27e8complete _, ih\u27e9, by rw a\u27e9,\n  end\n\n  lemma above_sub_below (\ud835\udc9c : finset (finset X)) : the_pairs \ud835\udc9c \u2286 from_below \ud835\udc9c :=\n  begin\n    rintros \u27e8A,B\u27e9 h,\n    rw [mem_the_pairs, mem_all_removals] at h,\n    apply mem_from_below,\n    rcases h with \u27e8Ah, i, ih, AeB\u27e9,\n    refine \u27e8Ah, i, _, _\u27e9; rw \u2190 AeB,\n      apply not_mem_erase,\n    apply insert_erase ih\n  end\n\n  lemma card_from_below (r : \u2115) : is_layer \ud835\udc9c r \u2192 (from_below \ud835\udc9c).card \u2264 (\u2202\ud835\udc9c).card * (n - (r - 1)) :=\n  begin\n    intro,\n    rw [from_below],\n    convert card_bind_le,\n    rw [\u2190 nat.smul_eq_mul, \u2190 sum_const],\n    apply sum_congr rfl,\n    intros, \n    rw [card_image_of_inj_on, card_sdiff (subset_univ _), card_univ, card_fin, shadow_layer a _ H],\n    intros x1 x1h _ _ h,\n    have q := mem_insert_self x1 x, \n    rw [(prod.mk.inj h).1, mem_insert] at q,\n    apply or.resolve_right q ((mem_sdiff.1 x1h).2),\n  end\n\n  theorem local_lym {r : \u2115} (hr1 : r \u2265 1) (hr2 : r \u2264 n) (H : is_layer \ud835\udc9c r):\n    (\ud835\udc9c.card : \u211a) / nat.choose n r \u2264 (\u2202\ud835\udc9c).card / nat.choose n (r-1) :=\n  begin\n    apply multiply_out hr1 hr2,\n    rw \u2190 card_the_pairs _ H,\n    transitivity,\n      apply card_le_of_subset (above_sub_below _),\n    rw \u2190 nat.sub_sub_assoc hr2 hr1,\n    apply card_from_below _ H\n  end\nend local_lym\n\nsection slice\n  def slice (\ud835\udc9c : finset (finset X)) (r : \u2115) : finset (finset X) := \ud835\udc9c.filter (\u03bb i, card i = r)\n\n  reserve infix `#`:100\n  notation \ud835\udc9c#r := slice \ud835\udc9c r\n\n  lemma mem_slice {r : \u2115} {A : finset X} : A \u2208 \ud835\udc9c#r \u2194 A \u2208 \ud835\udc9c \u2227 A.card = r :=\n  by rw [slice, mem_filter]\n\n  lemma layered_slice {\ud835\udc9c : finset (finset X)} {r : \u2115} : is_layer (\ud835\udc9c#r) r := \u03bb _ h, (mem_slice.1 h).2\n\n  lemma ne_of_diff_slice {r\u2081 r\u2082 : \u2115} {A\u2081 A\u2082 : finset X} (h\u2081 : A\u2081 \u2208 \ud835\udc9c#r\u2081) (h\u2082 : A\u2082 \u2208 \ud835\udc9c#r\u2082) : r\u2081 \u2260 r\u2082 \u2192 A\u2081 \u2260 A\u2082 :=\n  mt (\u03bb h, (layered_slice A\u2081 h\u2081).symm.trans ((congr_arg card h).trans (layered_slice A\u2082 h\u2082)))\n\nend slice\n\nsection lym\n  def antichain (\ud835\udc9c : finset (finset X)) : Prop := \u2200 A \u2208 \ud835\udc9c, \u2200 B \u2208 \ud835\udc9c, A \u2260 B \u2192 \u00ac(A \u2286 B)\n\n  def decompose' (\ud835\udc9c : finset (finset X)) : \u03a0 (k : \u2115), finset (finset X)\n    | 0 := \ud835\udc9c#n\n    | (k+1) := \ud835\udc9c#(n - (k+1)) \u222a shadow (decompose' k)\n\n  def decompose'_layer (\ud835\udc9c : finset (finset X)) (k : \u2115) : is_layer (decompose' \ud835\udc9c k) (n-k) :=\n  begin\n    induction k with k ih;\n      rw decompose',\n      apply layered_slice,\n    rw \u2190 union_layer,\n    split,\n      apply layered_slice,\n    apply shadow_layer ih,\n  end\n\n  theorem antichain_prop {r k : \u2115} (hk : k \u2264 n) (hr : r < k) (H : antichain \ud835\udc9c) :\n  \u2200 A \u2208 \ud835\udc9c#(n - k), \u2200 B \u2208 \u2202decompose' \ud835\udc9c r, \u00ac(A \u2286 B) :=\n  begin\n    intros A HA B HB k,\n    rcases sub_of_shadow HB with \u27e8C, HC, _\u27e9,\n    replace k := trans k \u2039B \u2286 C\u203a, clear HB h_h B,\n    induction r with r ih generalizing A C;\n    rw decompose' at HC,\n    any_goals { rw mem_union at HC, cases HC },\n    any_goals { refine H A (mem_slice.1 HA).1 C (mem_slice.1 HC).1 _ \u2039A \u2286 C\u203a,\n                apply ne_of_diff_slice HA HC _,\n                apply ne_of_lt },\n    { apply nat.sub_lt_of_pos_le _ _ hr hk },\n    { mono },\n    obtain \u27e8_, HB', HB''\u27e9 := sub_of_shadow HC,\n    refine ih (nat.lt_of_succ_lt hr) _ _ HA HB' (trans k_1 HB'')\n  end\n\n  lemma disjoint_of_antichain {k : \u2115} (hk : k + 1 \u2264 n) (H : antichain \ud835\udc9c) : disjoint (\ud835\udc9c#(n - (k + 1))) (\u2202decompose' \ud835\udc9c k) := \n  disjoint_left.2 $ \u03bb A HA HB, antichain_prop hk (lt_add_one k) H A HA A HB (subset.refl _)\n\n  lemma card_decompose'_other {k : \u2115} (hk : k \u2264 n) (H : antichain \ud835\udc9c) : \n    sum (range (k+1)) (\u03bb r, ((\ud835\udc9c#(n-r)).card : \u211a) / nat.choose n (n-r)) \u2264 ((decompose' \ud835\udc9c k).card : \u211a) / nat.choose n (n-k) :=\n  begin\n    induction k with k ih,\n      rw [sum_range_one, div_le_div_iff]; norm_cast, exact nat.choose_pos (nat.sub_le _ _), exact nat.choose_pos (nat.sub_le _ _),\n    rw [sum_range_succ, decompose'],\n    have: (\ud835\udc9c#(n - (k + 1)) \u222a \u2202decompose' \ud835\udc9c k).card = (\ud835\udc9c#(n - (k + 1))).card + (\u2202decompose' \ud835\udc9c k).card,\n      apply card_disjoint_union,\n      rw disjoint_iff_ne,\n      intros A hA B hB m,\n      apply antichain_prop hk (lt_add_one k) H A hA B hB,\n      rw m, refl,\n    rw this,\n    have: \u2191((\ud835\udc9c#(n - (k + 1))).card + (\u2202decompose' \ud835\udc9c k).card) / (nat.choose n (n - nat.succ k) : \u211a) = \n          ((\ud835\udc9c#(n - (k + 1))).card : \u211a) / (nat.choose n (n - nat.succ k)) + ((\u2202decompose' \ud835\udc9c k).card : \u211a) / (nat.choose n (n - nat.succ k)),\n      rw \u2190 add_div,\n      norm_cast,\n    rw this,\n    apply add_le_add_left,\n    transitivity,\n      exact ih (le_of_lt hk),\n    apply local_lym (nat.le_sub_left_of_add_le hk) (nat.sub_le _ _) (decompose'_layer _ _)\n  end\n\n  lemma sum_flip {\u03b1 : Type*} [add_comm_monoid \u03b1] {n : \u2115} (f : \u2115 \u2192 \u03b1) : sum (range (n+1)) (\u03bb r, f (n - r)) = sum (range (n+1)) (\u03bb r, f r) :=\n  begin\n    induction n with n ih,\n      rw [sum_range_one, sum_range_one],\n    rw sum_range_succ',\n    rw sum_range_succ _ (nat.succ n),\n    simp [ih],\n  end\n\n  lemma card_decompose_other (H : antichain \ud835\udc9c) : \n    (range (n+1)).sum (\u03bb r, ((\ud835\udc9c#r).card : \u211a) / nat.choose n r) \u2264 (decompose' \ud835\udc9c n).card / nat.choose n 0 :=\n  begin\n    rw [\u2190 nat.sub_self n],\n    convert \u2190 card_decompose'_other (le_refl n) H using 1,\n    apply sum_flip (\u03bb r, ((\ud835\udc9c#r).card : \u211a) / nat.choose n r), \n  end\n\n  lemma lubell_yamamoto_meshalkin (H : antichain \ud835\udc9c) : (range (n+1)).sum (\u03bb r, ((\ud835\udc9c#r).card : \u211a) / nat.choose n r) \u2264 1 :=\n  begin\n    transitivity,\n      apply card_decompose_other H,\n    rw div_le_iff; norm_cast,\n      simpa only [card_fin, mul_one, nat.choose_zero_right, nat.sub_self] using size_in_layer (decompose'_layer \ud835\udc9c n),\n    apply nat.choose_pos (zero_le n)\n  end\nend lym\n\nlemma dominate_choose_lt {r n : \u2115} (h : r < n/2) : nat.choose n r \u2264 nat.choose n (r+1) :=\nbegin\n  refine le_of_mul_le_mul_right _ (nat.lt_sub_left_of_add_lt (lt_of_lt_of_le h (nat.div_le_self n 2))),\n  rw \u2190 nat.choose_succ_right_eq,\n  apply nat.mul_le_mul_left,\n  rw \u2190 nat.lt_iff_add_one_le,\n  apply nat.lt_sub_left_of_add_lt,\n  rw \u2190 mul_two,\n  exact lt_of_lt_of_le (mul_lt_mul_of_pos_right h zero_lt_two) (nat.div_mul_le_self n 2),\nend\n\nlemma dominate_choose_lt' {n r : \u2115} (hr : r \u2264 n/2) : nat.choose n r \u2264 nat.choose n (n/2) :=\nbegin\n  refine (@nat.decreasing_induction (\u03bb k, k \u2264 n/2 \u2192 nat.choose n k \u2264 nat.choose n (n/2)) _ r (n/2) hr (\u03bb _, by refl)) hr,\n  intros m k a,\n  cases lt_or_eq_of_le a,\n    transitivity nat.choose n (m + 1),\n      exact dominate_choose_lt h,\n    exact k h,\n  rw h,\nend \n\nlemma dominate_choose {r n : \u2115} : nat.choose n r \u2264 nat.choose n (n/2) :=\nbegin\n  cases le_or_gt r n with b b,\n    cases le_or_gt r (n/2) with a,\n      apply dominate_choose_lt' a,\n    rw \u2190 nat.choose_symm b,\n    apply dominate_choose_lt',\n    rw [gt_iff_lt, nat.div_lt_iff_lt_mul _ _ zero_lt_two] at h,\n    rw [nat.le_div_iff_mul_le _ _ zero_lt_two, nat.mul_sub_right_distrib, nat.sub_le_iff, mul_two, nat.add_sub_cancel],\n    exact le_of_lt h,\n  rw nat.choose_eq_zero_of_lt b,\n  apply zero_le\nend\n\nlemma sum_div {\u03b1 : Type*} {s : finset \u03b1} {f : \u03b1 \u2192 \u211a} {b : \u211a} : s.sum f / b = s.sum (\u03bbx, f x / b) :=\ncalc s.sum f / b = s.sum (\u03bb x, f x * (1 / b)) : by rw [div_eq_mul_one_div, sum_mul]\n     ...         = s.sum (\u03bb x, f x / b) : by congr; ext; rw \u2190 div_eq_mul_one_div\n\nlemma sperner (H : antichain \ud835\udc9c) : \ud835\udc9c.card \u2264 nat.choose n (n / 2) := \nbegin\n  have q1 := lubell_yamamoto_meshalkin H,\n  set f := (\u03bb (r : \u2115), ((\ud835\udc9c#r).card : \u211a) / nat.choose n r),\n  set g := (\u03bb (r : \u2115), ((\ud835\udc9c#r).card : \u211a) / nat.choose n (n/2)),\n  have q2 : sum (range (n + 1)) g \u2264 sum (range (n + 1)) f,\n    apply sum_le_sum,\n    intros r hr,\n    apply div_le_div_of_le_left; norm_cast,\n        apply zero_le,\n      apply nat.choose_pos,\n      rw mem_range at hr,\n      rwa \u2190 nat.lt_succ_iff,\n    apply dominate_choose,\n  \n  have := trans q2 q1,\n  rw [\u2190 sum_div, \u2190 sum_nat_cast, div_le_one_iff_le] at this,\n    swap, norm_cast, apply nat.choose_pos (nat.div_le_self _ _),\n  norm_cast at this,\n  rw \u2190 card_bind at this,\n    suffices m: finset.bind (range (n + 1)) (\u03bb (u : \u2115), \ud835\udc9c#u) = \ud835\udc9c,\n      rwa m at this,\n    ext,\n    rw mem_bind,\n    split, rintro \u27e8_,_,q\u27e9,\n      rw mem_slice at q,\n      exact q.1,\n    intro, \n    refine \u27e8a.card, _, _\u27e9,\n      rw [mem_range, nat.lt_succ_iff],\n      conv {to_rhs, rw \u2190 card_fin n},\n      apply card_le_of_subset (subset_univ a),\n    rw mem_slice,\n    tauto,\n  intros x _ y _ ne,\n  rw disjoint_left,\n  intros a Ha k,\n  exact ne_of_diff_slice Ha k ne rfl\nend\n\nlemma sdiff_union_inter {\u03b1 : Type*} [decidable_eq \u03b1] (A B : finset \u03b1) : (A \\ B) \u222a (A \u2229 B) = A :=\nby simp only [ext, mem_union, mem_sdiff, mem_inter]; tauto\n\nlemma sdiff_inter_inter {\u03b1 : Type*} [decidable_eq \u03b1] (A B : finset \u03b1) : disjoint (A \\ B) (A \u2229 B) := disjoint_of_subset_right (inter_subset_right _ _) sdiff_disjoint\n-- by simp only [ext, mem_inter, mem_sdiff, not_mem_empty]; tauto\n\nnamespace ij\nsection \n  variables (i j : X)\n  \n  def compress (i j : X) (A : finset X) : finset X := \n  if (j \u2208 A \u2227 i \u2209 A)\n    then insert i (A.erase j)\n    else A\n\n  local notation `C` := compress i j\n\n  def compressed_set {A : finset X} : \u00ac (j \u2208 C A \u2227 i \u2209 C A) :=\n  begin\n    intro,\n    rw compress at a,\n    split_ifs at a,\n      apply a.2,\n      apply mem_insert_self,\n    exact h a\n  end\n\n  lemma compress_idem (A : finset X) : C (C A) = C A :=\n  begin\n    rw compress,\n    split_ifs,\n      exfalso,\n      apply compressed_set _ _ h,\n    refl\n  end\n\n  @[reducible] def compress_motion (\ud835\udc9c : finset (finset X)) : finset (finset X) := \ud835\udc9c.filter (\u03bb A, C A \u2208 \ud835\udc9c)\n  @[reducible] def compress_remains (\ud835\udc9c : finset (finset X)) : finset (finset X) := (\ud835\udc9c.filter (\u03bb A, C A \u2209 \ud835\udc9c)).image (\u03bb A, C A)\n\n  def compress_family (i j : X) (\ud835\udc9c : finset (finset X)) : finset (finset X) :=\n  @compress_remains _ i j \ud835\udc9c \u222a @compress_motion _ i j \ud835\udc9c\n\n  local notation `CC` := compress_family i j\n\n  lemma mem_compress_motion (A : finset X) : A \u2208 compress_motion i j \ud835\udc9c \u2194 A \u2208 \ud835\udc9c \u2227 C A \u2208 \ud835\udc9c :=\n  by rw mem_filter\n\n  lemma mem_compress_remains (A : finset X) : A \u2208 compress_remains i j \ud835\udc9c \u2194 A \u2209 \ud835\udc9c \u2227 (\u2203 B \u2208 \ud835\udc9c, C B = A) :=\n  begin\n    simp [compress_remains], \n    split; rintro \u27e8p, q, r\u27e9,\n      exact \u27e8r \u25b8 q.2, p, \u27e8q.1, r\u27e9\u27e9,\n    exact \u27e8q, \u27e8r.1, r.2.symm \u25b8 p\u27e9, r.2\u27e9, \n  end\n\n  lemma mem_compress {A : finset X} : A \u2208 CC \ud835\udc9c \u2194 (A \u2209 \ud835\udc9c \u2227 (\u2203 B \u2208 \ud835\udc9c, C B = A)) \u2228 (A \u2208 \ud835\udc9c \u2227 C A \u2208 \ud835\udc9c) :=\n  by rw [compress_family, mem_union, mem_compress_motion, mem_compress_remains]\n\n  lemma compress_disjoint (i j : fin n) : disjoint (compress_remains i j \ud835\udc9c) (compress_motion i j \ud835\udc9c) :=\n  begin\n    rw disjoint_left,\n    intros A HA HB,\n    rw mem_compress_motion at HB,\n    rw mem_compress_remains at HA,\n    exact HA.1 HB.1\n  end\n\n  lemma inj_ish {i j : X} (A B : finset X) (hA : j \u2208 A \u2227 i \u2209 A) (hY : j \u2208 B \u2227 i \u2209 B) \n    (Z : insert i (erase A j) = insert i (erase B j)) : A = B := \n  begin\n    ext x, split,\n    all_goals { intro p, \n                by_cases h\u2081: (x=j), {rw h\u2081, tauto}, \n                have h\u2082: x \u2260 i, {intro, rw a at p, tauto},\n                rw ext at Z,\n                replace Z := Z x,\n                simp only [mem_insert, mem_erase] at Z,\n                tauto }\n  end\n\n  lemma compressed_size : (CC \ud835\udc9c).card = \ud835\udc9c.card :=\n  begin\n    rw [compress_family, card_disjoint_union (compress_disjoint _ _), card_image_of_inj_on],\n      rw [\u2190 card_disjoint_union, union_comm, filter_union_filter_neg_eq],\n      rw [disjoint_iff_inter_eq_empty, inter_comm],\n      apply filter_inter_filter_neg_eq,\n    intros A HX Y HY Z,\n    rw mem_filter at HX HY,\n    rw compress at HX Z,\n    split_ifs at HX Z,\n      rw compress at HY Z,\n      split_ifs at HY Z,\n        refine inj_ish A Y h h_1 Z,\n      tauto,\n    tauto\n  end\n\n  lemma insert_erase_comm {i j : fin n} {A : finset X} (h : i \u2260 j) : insert i (erase A j) = erase (insert i A) j :=\n  begin\n    simp only [ext, mem_insert, mem_erase],\n    intro x,\n    split; intro p,\n      cases p, split, rw p, \n    all_goals {tauto},\n  end\n\n  lemma compress_moved {i j : X} {A : finset X} (h\u2081 : A \u2208 compress_family i j \ud835\udc9c) (h\u2082 : A \u2209 \ud835\udc9c) : i \u2208 A \u2227 j \u2209 A \u2227 erase (insert j A) i \u2208 \ud835\udc9c :=\n  begin\n    rw mem_compress at h\u2081,\n    rcases h\u2081 with \u27e8_, B, H, HB\u27e9 | _,\n      rw compress at HB,\n      split_ifs at HB,\n        rw \u2190 HB,\n        refine \u27e8mem_insert_self _ _, _, _\u27e9,\n          rw mem_insert,\n          intro,\n          cases a,\n            safe,\n          apply not_mem_erase j B a,\n        have: erase (insert j (insert i (erase B j))) i = B,\n          rw [insert_erase_comm, insert_erase (mem_insert_of_mem h.1), erase_insert h.2], \n          safe, \n        rwa this,\n      rw HB at H, tauto,\n    tauto\n  end\n\n  lemma compress_held {i j : X} {A : finset X} (h\u2081 : j \u2208 A) (h\u2082 : A \u2208 compress_family i j \ud835\udc9c) : A \u2208 \ud835\udc9c :=\n  begin\n    rw mem_compress at h\u2082,\n    rcases h\u2082 with \u27e8_, B, H, HB\u27e9 | _,\n      rw \u2190 HB at h\u2081,\n      rw compress at HB h\u2081,\n      split_ifs at HB h\u2081,\n        rw mem_insert at h\u2081,\n        cases h\u2081,\n          safe,\n        exfalso, apply not_mem_erase _ _ h\u2081,\n      rwa \u2190 HB,\n    tauto\n  end\n\n  lemma compress_both {i j : X} {A : finset X} (h\u2081 : A \u2208 compress_family i j \ud835\udc9c) (h\u2082 : j \u2208 A) (h\u2083 : i \u2209 A) : erase (insert i A) j \u2208 \ud835\udc9c :=\n  begin\n    have: A \u2208 \ud835\udc9c, apply compress_held \u2039_\u203a \u2039_\u203a,\n    rw mem_compress at h\u2081,\n    replace h\u2081 : C A \u2208 \ud835\udc9c, tauto,\n    rw compress at h\u2081,\n    have: j \u2208 A \u2227 i \u2209 A := \u27e8h\u2082, h\u2083\u27e9,\n    split_ifs at h\u2081,\n    rwa \u2190 insert_erase_comm,\n    intro, rw a at *, tauto,\n  end\n\n  lemma compression_reduces_shadow : (\u2202 CC \ud835\udc9c).card \u2264 (\u2202\ud835\udc9c).card := \n  begin\n    set \ud835\udc9c' := CC \ud835\udc9c,\n    suffices: (\u2202\ud835\udc9c' \\ \u2202\ud835\udc9c).card \u2264 (\u2202\ud835\udc9c \\ \u2202\ud835\udc9c').card,\n      suffices z: card (\u2202\ud835\udc9c' \\ \u2202\ud835\udc9c \u222a \u2202\ud835\udc9c' \u2229 \u2202\ud835\udc9c) \u2264 card (\u2202\ud835\udc9c \\ \u2202\ud835\udc9c' \u222a \u2202\ud835\udc9c \u2229 \u2202\ud835\udc9c'),\n        rwa [sdiff_union_inter, sdiff_union_inter] at z,\n      rw [card_disjoint_union, card_disjoint_union, inter_comm],\n      apply add_le_add_right \u2039_\u203a,\n      any_goals { apply sdiff_inter_inter },\n\n    have q\u2081: \u2200 B \u2208 \u2202\ud835\udc9c' \\ \u2202\ud835\udc9c, i \u2208 B \u2227 j \u2209 B \u2227 erase (insert j B) i \u2208 \u2202\ud835\udc9c \\ \u2202\ud835\udc9c',\n      intros B HB,\n      obtain \u27e8k, k'\u27e9: B \u2208 \u2202\ud835\udc9c' \u2227 B \u2209 \u2202\ud835\udc9c := mem_sdiff.1 HB,\n      have m: \u2200 y \u2209 B, insert y B \u2209 \ud835\udc9c,\n        intros y _ _,\n        apply k',\n        rw mem_shadow',\n        exact \u27e8y, H, a\u27e9,\n      rcases mem_shadow'.1 k with \u27e8x, _, _\u27e9,\n      have q := compress_moved \u2039insert x B \u2208 \ud835\udc9c'\u203a (m _ \u2039x \u2209 B\u203a),\n      rw insert.comm at q,\n      have: j \u2209 B := q.2.1 \u2218 mem_insert_of_mem,\n      have: i \u2260 j, safe,\n      have: x \u2260 i, intro a, rw a at *, rw [erase_insert] at q, \n        exact m _ \u2039j \u2209 B\u203a q.2.2,\n        rw mem_insert, tauto,\n      have: x \u2260 j, intro a, rw a at q, exact q.2.1 (mem_insert_self _ _), \n      have: i \u2208 B := mem_of_mem_insert_of_ne q.1 \u2039x \u2260 i\u203a.symm,\n      refine \u27e8\u2039_\u203a, \u2039_\u203a, _\u27e9,\n      rw mem_sdiff,\n      split,\n        rw mem_shadow',\n        rw \u2190 insert_erase_comm \u2039x \u2260 i\u203a at q,\n        refine \u27e8x, _, q.2.2\u27e9, \n        intro a, \n        exact \u2039x \u2209 B\u203a (mem_of_mem_insert_of_ne (mem_of_mem_erase a) \u2039x \u2260 j\u203a),\n\n      intro a, rw mem_shadow' at a, \n      rcases a with \u27e8y, yH, H\u27e9,\n      have: y \u2260 i, intro b, rw [b, insert_erase (mem_insert_of_mem \u2039i \u2208 B\u203a)] at H, \n                  exact m _ \u2039j \u2209 B\u203a (compress_held (mem_insert_self _ _) H), \n      have: y \u2260 j, rw [mem_erase, mem_insert] at yH, tauto,\n      have: y \u2209 B, rw [mem_erase, mem_insert] at yH, tauto,\n      have: j \u2208 insert y (erase (insert j B) i), finish,\n      have: i \u2209 insert y (erase (insert j B) i), finish,\n      have := compress_both H \u2039_\u203a \u2039_\u203a,\n      rw [insert.comm, \u2190 insert_erase_comm \u2039y \u2260 j\u203a, insert_erase (mem_insert_of_mem \u2039i \u2208 B\u203a), erase_insert \u2039j \u2209 B\u203a] at this,\n      exact m _ \u2039y \u2209 B\u203a \u2039insert y B \u2208 \ud835\udc9c\u203a,\n    \n    set f := (\u03bb (B : finset X), erase (insert j B) i),\n    apply card_le_card_of_inj_on f,\n      intros _ HB,\n      exact (q\u2081 _ HB).2.2,\n  \n    intros B\u2081 HB\u2081 B\u2082 HB\u2082 f\u2081,\n    have := q\u2081 B\u2081 HB\u2081,\n    have := q\u2081 B\u2082 HB\u2082,\n    rw ext at f\u2081,\n    ext,\n    split,\n    all_goals { intro,\n                have p := f\u2081 a,\n                simp only [mem_erase, mem_insert] at p,\n                by_cases (a = i),\n                  rw h, tauto,\n                rw [and_iff_right h, and_iff_right h] at p,\n                have z: j \u2209 B\u2081 \u2227 j \u2209 B\u2082, tauto,\n                have: a \u2260 j, safe,\n                tauto }\n  end\nend\nend ij\n\n@[simp] lemma sdiff_empty {\u03b1 : Type*} [decidable_eq \u03b1] (s : finset \u03b1) : s \\ \u2205 = s := empty_union s\n@[simp] lemma sdiff_idem {\u03b1 : Type*} [decidable_eq \u03b1] (s t : finset \u03b1) : s \\ t \\ t = s \\ t := by simp only [ext, mem_sdiff]; tauto\nlemma union_sdiff {\u03b1 : Type*} [decidable_eq \u03b1] (s\u2081 s\u2082 t : finset \u03b1) : (s\u2081 \u222a s\u2082) \\ t = s\u2081 \\ t \u222a s\u2082 \\ t := by simp only [ext, mem_sdiff, mem_union]; tauto\nlemma inter_union_self {\u03b1 : Type*} [decidable_eq \u03b1] (s t : finset \u03b1) : s \u2229 (t \u222a s) = s := by simp only [ext, mem_inter, mem_union]; tauto\nlemma union_sdiff_self {\u03b1 : Type*} [decidable_eq \u03b1] (s t : finset \u03b1) : (s \u222a t) \\ t = s \\ t := by simp only [ext, mem_union, mem_sdiff]; tauto\nlemma sdiff_singleton_eq_erase {\u03b1 : Type*} [decidable_eq \u03b1] (a : \u03b1) (s : finset \u03b1) : s \\ finset.singleton a = erase s a := begin ext, rw [mem_erase, mem_sdiff, mem_singleton], tauto end\nlemma sdiff_union {\u03b1 : Type*} [decidable_eq \u03b1] (s t\u2081 t\u2082 : finset \u03b1) : s \\ (t\u2081 \u222a t\u2082) = (s \\ t\u2081) \u2229 (s \\ t\u2082) := by simp only [ext, mem_union, mem_sdiff, mem_inter]; tauto\nlemma not_sure {\u03b1 : Type*} [decidable_eq \u03b1] {s t : finset \u03b1} (h : t \u2286 s) : s \u222a t = s := by simp only [ext, mem_union]; tauto\nlemma new_thing {\u03b1 : Type*} [decidable_eq \u03b1] {s t : finset \u03b1} : disjoint s t \u2194 s \\ t = s := \nbegin\n  split; intro p,\n    rw disjoint_iff_inter_eq_empty at p,\n    exact union_empty (s \\ t) \u25b8 (p \u25b8 sdiff_union_inter s t), \n  rw \u2190 p, apply sdiff_disjoint\nend\nlemma disjoint_self_iff_empty {\u03b1 : Type*} [decidable_eq \u03b1] (s : finset \u03b1) : disjoint s s \u2194 s = \u2205 :=\ndisjoint_self\n\nlemma sdiff_subset_left {\u03b1 : Type*} [decidable_eq \u03b1] (s t : finset \u03b1) : s \\ t \u2286 s := by have := sdiff_subset_sdiff (le_refl s) (empty_subset t); rwa sdiff_empty at this\n\ninstance decidable_disjoint (U V : finset X) : decidable (disjoint U V) := \ndite (U \u2229 V = \u2205) (is_true \u2218 disjoint_iff_inter_eq_empty.2) (is_false \u2218 mt disjoint_iff_inter_eq_empty.1)\n\nlemma sum_lt_sum {\u03b1 \u03b2 : Type*} {s : finset \u03b1} {f g : \u03b1 \u2192 \u03b2} [decidable_eq \u03b1] [ordered_cancel_comm_monoid \u03b2] : s \u2260 \u2205 \u2192 (\u2200x\u2208s, f x < g x) \u2192 s.sum f < s.sum g := \nbegin\n  apply finset.induction_on s,\n    intro a, exfalso, apply a, refl,\n  intros x s not_mem ih _ assump,\n  rw sum_insert not_mem, rw sum_insert not_mem,\n  apply lt_of_lt_of_le,\n    rw add_lt_add_iff_right (s.sum f),\n    apply assump x (mem_insert_self _ _),\n  rw add_le_add_iff_left,\n  by_cases (s = \u2205),\n    rw h,\n    rw sum_empty,\n    rw sum_empty,\n  apply le_of_lt,\n  apply ih h,\n  intros x hx,\n  apply assump,\n  apply mem_insert_of_mem hx\nend\n\nnamespace UV\nsection \n  variables (U V : finset X)\n  \n  -- We'll only use this when |U| = |V| and U \u2229 V = \u2205\n  def compress (U V : finset X) (A : finset X) :=\n  if disjoint U A \u2227 (V \u2286 A)\n    then (A \u222a U) \\ V\n    else A\n\n  local notation `C` := compress U V\n\n  lemma compress_size (A : finset X) (h\u2081 : disjoint U V) (h\u2082 : U.card = V.card) : (C A).card = A.card :=\n  begin\n    rw compress, split_ifs, \n    rw card_sdiff (subset.trans h.2 (subset_union_left _ _)), \n    rw card_disjoint_union h.1.symm, rw h\u2082, apply nat.add_sub_cancel, \n    refl\n  end\n\n  lemma compress_idem (A : finset X) : C (C A) = C A :=\n  begin\n    rw [compress, compress],\n    split_ifs,\n        suffices: U = \u2205,\n          rw [this, union_empty, union_empty, sdiff_idem],\n        have: U \\ V = U := new_thing.1 (disjoint_of_subset_right h.2 h.1),\n        rw \u2190 disjoint_self_iff_empty,\n        apply disjoint_of_subset_right (subset_union_right (A\\V) _),\n        rw [union_sdiff, \u2039U \\ V = U\u203a] at h_1,\n        tauto,\n      refl,\n    refl,\n  end\n\n  @[reducible] def compress_motion (\ud835\udc9c : finset (finset X)) : finset (finset X) := \ud835\udc9c.filter (\u03bb A, C A \u2208 \ud835\udc9c)\n  @[reducible] def compress_remains (\ud835\udc9c : finset (finset X)) : finset (finset X) := (\ud835\udc9c.filter (\u03bb A, C A \u2209 \ud835\udc9c)).image (\u03bb A, C A)\n\n  def compress_family (U V : finset X) (\ud835\udc9c : finset (finset X)) : finset (finset X) :=\n  compress_remains U V \ud835\udc9c \u222a compress_motion U V \ud835\udc9c\n\n  local notation `CC` := compress_family U V\n\n  lemma mem_compress_motion (A : finset X) : A \u2208 compress_motion U V \ud835\udc9c \u2194 A \u2208 \ud835\udc9c \u2227 C A \u2208 \ud835\udc9c :=\n  by rw mem_filter\n\n  lemma mem_compress_remains (A : finset X) : A \u2208 compress_remains U V \ud835\udc9c \u2194 A \u2209 \ud835\udc9c \u2227 (\u2203 B \u2208 \ud835\udc9c, C B = A) :=\n  begin\n    simp [compress_remains], \n    split; rintro \u27e8p, q, r\u27e9,\n      exact \u27e8r \u25b8 q.2, p, \u27e8q.1, r\u27e9\u27e9,\n    exact \u27e8q, \u27e8r.1, r.2.symm \u25b8 p\u27e9, r.2\u27e9, \n  end\n\n  def is_compressed (\ud835\udc9c : finset (finset X)) : Prop := CC \ud835\udc9c = \ud835\udc9c\n\n  lemma is_compressed_empty (\ud835\udc9c : finset (finset X)) : is_compressed \u2205 \u2205 \ud835\udc9c := \n  begin\n    have q: \u2200 (A : finset X), compress \u2205 \u2205 A = A,\n      simp [compress],\n    rw [is_compressed, compress_family], \n    ext, rw mem_union, rw mem_compress_remains, rw mem_compress_motion,\n    repeat {conv in (compress \u2205 \u2205 _) {rw q _}},\n    safe\n  end\n\n  lemma mem_compress {A : finset X} : A \u2208 CC \ud835\udc9c \u2194 (A \u2209 \ud835\udc9c \u2227 (\u2203 B \u2208 \ud835\udc9c, C B = A)) \u2228 (A \u2208 \ud835\udc9c \u2227 C A \u2208 \ud835\udc9c) :=\n  by rw [compress_family, mem_union, mem_compress_motion, mem_compress_remains]\n\n  lemma compress_family_size (r : \u2115) (\ud835\udc9c : finset (finset X)) (h\u2081 : disjoint U V) (h\u2082 : U.card = V.card) (h\u2083 : is_layer \ud835\udc9c r) : is_layer (CC \ud835\udc9c) r :=\n  begin\n    intros A HA,\n    rw mem_compress at HA, \n    rcases HA with \u27e8_, _, z\u2081, z\u2082\u27e9 | \u27e8z\u2081, _\u27e9,\n      rw \u2190 z\u2082, rw compress_size _ _ _ h\u2081 h\u2082, \n    all_goals {apply h\u2083 _ z\u2081}\n  end\n\n  lemma compress_family_idempotent (\ud835\udc9c : finset (finset X)) : CC (CC \ud835\udc9c) = CC \ud835\udc9c :=\n  begin\n    have: \u2200 A \u2208 compress_family U V \ud835\udc9c, compress U V A \u2208 compress_family U V \ud835\udc9c,\n      intros A HA,\n      rw mem_compress at HA \u22a2,\n      rw [compress_idem, and_self],\n      rcases HA with \u27e8_, B, _, cB_eq_A\u27e9 | \u27e8_, _\u27e9,\n        left, rw \u2190 cB_eq_A, refine \u27e8_, B, \u2039_\u203a, _\u27e9; rw compress_idem,\n        rwa cB_eq_A,\n      right, assumption,\n    have: filter (\u03bb A, compress U V A \u2209 compress_family U V \ud835\udc9c) (compress_family U V \ud835\udc9c) = \u2205,\n      rw \u2190 filter_false (compress_family U V \ud835\udc9c),\n      apply filter_congr,\n      simpa,\n    rw [compress_family, compress_remains, this, image_empty, union_comm, compress_motion, \u2190 this],\n    apply filter_union_filter_neg_eq (compress_family U V \ud835\udc9c)\n  end\n\n  lemma compress_disjoint (U V : finset X) : disjoint (compress_remains U V \ud835\udc9c) (compress_motion U V \ud835\udc9c) :=\n  begin\n    rw disjoint_left,\n    intros A HA HB,\n    rw mem_compress_motion at HB,\n    rw mem_compress_remains at HA,\n    exact HA.1 HB.1\n  end\n\n  lemma inj_ish {U V : finset X} (A B : finset X) (hA : disjoint U A \u2227 V \u2286 A) (hB : disjoint U B \u2227 V \u2286 B)\n    (Z : (A \u222a U) \\ V = (B \u222a U) \\ V) : A = B :=\n  begin\n    ext x, split,\n    all_goals {\n      intro p,\n      by_cases h\u2081: (x \u2208 V), \n        { exact hB.2 h\u2081 <|> exact hA.2 h\u2081 },\n      have := mem_sdiff.2 \u27e8mem_union_left U \u2039_\u203a, h\u2081\u27e9,\n      rw Z at this <|> rw \u2190 Z at this,\n      rw [mem_sdiff, mem_union] at this,\n      suffices: x \u2209 U, tauto,\n      apply disjoint_right.1 _ p, tauto\n    }\n  end\n\n  lemma compressed_size : (CC \ud835\udc9c).card = \ud835\udc9c.card :=\n  begin\n    rw [compress_family, card_disjoint_union (compress_disjoint _ _), card_image_of_inj_on],\n      rw [\u2190 card_disjoint_union, union_comm, filter_union_filter_neg_eq],\n      rw [disjoint_iff_inter_eq_empty, inter_comm],\n      apply filter_inter_filter_neg_eq,\n    intros A HX Y HY Z,\n    rw mem_filter at HX HY,\n    rw compress at HX Z,\n    split_ifs at HX Z,\n      rw compress at HY Z,\n      split_ifs at HY Z,\n        refine inj_ish A Y h h_1 Z,\n      tauto,\n    tauto\n  end\n\n  lemma compress_held {U V : finset X} {A : finset X} (h\u2081 : A \u2208 compress_family U V \ud835\udc9c) (h\u2082 : V \u2286 A) (h\u2083 : U.card = V.card) : A \u2208 \ud835\udc9c :=\n  begin\n    rw mem_compress at h\u2081,\n    rcases h\u2081 with \u27e8_, B, H, HB\u27e9 | _,\n      rw compress at HB,\n      split_ifs at HB,\n        have: V = \u2205,\n          apply eq_empty_of_forall_not_mem,\n          intros x xV, replace h\u2082 := h\u2082 xV, \n          rw [\u2190 HB, mem_sdiff] at h\u2082, exact h\u2082.2 xV,\n        have: U = \u2205,\n          rwa [\u2190 card_eq_zero, h\u2083, card_eq_zero],\n        rw [\u2039U = \u2205\u203a, \u2039V = \u2205\u203a, union_empty, sdiff_empty] at HB,\n        rwa \u2190 HB, \n      rwa \u2190 HB,\n    tauto,\n  end\n\n  lemma compress_moved {U V : finset X} {A : finset X} (h\u2081 : A \u2208 compress_family U V \ud835\udc9c) (h\u2082 : A \u2209 \ud835\udc9c) : U \u2286 A \u2227 disjoint V A \u2227 (A \u222a V) \\ U \u2208 \ud835\udc9c :=\n  begin\n    rw mem_compress at h\u2081,\n    rcases h\u2081 with \u27e8_, B, H, HB\u27e9 | _,\n    { rw compress at HB,\n      split_ifs at HB, { \n        rw \u2190 HB at *,\n        refine \u27e8_, disjoint_sdiff, _\u27e9,\n          have: disjoint U V := disjoint_of_subset_right h.2 h.1,\n          rw union_sdiff, rw new_thing.1 this, apply subset_union_right _ _,\n        rwa [sdiff_union_of_subset, union_sdiff_self, new_thing.1 h.1.symm],\n        apply trans h.2 (subset_union_left _ _)},\n      { rw HB at *, tauto } },\n    tauto\n  end\n\n  lemma uncompressed_was_already_there {U V : finset X} {A : finset X} (h\u2081 : A \u2208 compress_family U V \ud835\udc9c) (h\u2082 : V \u2286 A) (h\u2083 : disjoint U A) : (A \u222a U) \\ V \u2208 \ud835\udc9c :=\n  begin\n    rw mem_compress at h\u2081,\n    have: disjoint U A \u2227 V \u2286 A := \u27e8h\u2083, h\u2082\u27e9,\n    rcases h\u2081 with \u27e8_, B, B_in_A, cB_eq_A\u27e9 | \u27e8_, cA_in_A\u27e9,\n    { by_cases a: (A \u222a U) \\ V = A,\n        have: U \\ V = U := new_thing.1 (disjoint_of_subset_right h\u2082 h\u2083),\n        have: U = \u2205,\n          rw \u2190 disjoint_self_iff_empty,\n          suffices: disjoint U (U \\ V), rw \u2039U \\ V = U\u203a at this, assumption,\n          apply disjoint_of_subset_right (subset_union_right (A\\V) _),\n          rwa [\u2190 union_sdiff, a],\n        have: V = \u2205,\n          rw \u2190 disjoint_self_iff_empty, apply disjoint_of_subset_right h\u2082,\n          rw \u2190 a, apply disjoint_sdiff,\n        simpa [a, cB_eq_A.symm, compress, \u2039U = \u2205\u203a, \u2039V = \u2205\u203a],\n      have: compress U V A = (A \u222a U) \\ V,\n        rw compress, split_ifs, refl,\n      exfalso,\n      apply a,\n      rw [\u2190 this, \u2190 cB_eq_A, compress_idem] },\n    { rw compress at cA_in_A,\n      split_ifs at cA_in_A,\n      assumption }\n  end\n\n  lemma compression_reduces_shadow (h\u2081 : \u2200 x \u2208 U, \u2203 y \u2208 V, is_compressed (erase U x) (erase V y) \ud835\udc9c) (h\u2082 : U.card = V.card) : \n    (\u2202 CC \ud835\udc9c).card \u2264 (\u2202\ud835\udc9c).card := \n  begin\n    set \ud835\udc9c' := CC \ud835\udc9c,\n    suffices: (\u2202\ud835\udc9c' \\ \u2202\ud835\udc9c).card \u2264 (\u2202\ud835\udc9c \\ \u2202\ud835\udc9c').card,\n      suffices z: card (\u2202\ud835\udc9c' \\ \u2202\ud835\udc9c \u222a \u2202\ud835\udc9c' \u2229 \u2202\ud835\udc9c) \u2264 card (\u2202\ud835\udc9c \\ \u2202\ud835\udc9c' \u222a \u2202\ud835\udc9c \u2229 \u2202\ud835\udc9c'),\n        rwa [sdiff_union_inter, sdiff_union_inter] at z,\n      rw [card_disjoint_union, card_disjoint_union, inter_comm],\n      apply add_le_add_right \u2039_\u203a,\n      any_goals { apply sdiff_inter_inter },\n    \n    have q\u2081: \u2200 B \u2208 \u2202\ud835\udc9c' \\ \u2202\ud835\udc9c, U \u2286 B \u2227 disjoint V B \u2227 (B \u222a V) \\ U \u2208 \u2202\ud835\udc9c \\ \u2202\ud835\udc9c',\n      intros B HB,\n      obtain \u27e8k, k'\u27e9: B \u2208 \u2202\ud835\udc9c' \u2227 B \u2209 \u2202\ud835\udc9c := mem_sdiff.1 HB,\n      have m: \u2200 y \u2209 B, insert y B \u2209 \ud835\udc9c := \u03bb y H a, k' (mem_shadow'.2 \u27e8y, H, a\u27e9),\n      rcases mem_shadow'.1 k with \u27e8x, _, _\u27e9,\n      have q := compress_moved \u2039insert x B \u2208 \ud835\udc9c'\u203a (m _ \u2039x \u2209 B\u203a),\n      have: disjoint V B := (disjoint_insert_right.1 q.2.1).2,\n      have: disjoint V U := disjoint_of_subset_right q.1 q.2.1,\n      have: V \\ U = V, rwa \u2190 new_thing,\n      have: x \u2209 U,\n        intro a, \n        rcases h\u2081 x \u2039x \u2208 U\u203a with \u27e8y, Hy, xy_comp\u27e9,\n        apply m y (disjoint_left.1 \u2039disjoint V B\u203a Hy),\n        rw is_compressed at xy_comp,\n        have: (insert x B \u222a V) \\ U \u2208 compress_family (erase U x) (erase V y) \ud835\udc9c, rw xy_comp, exact q.2.2,\n        have: ((insert x B \u222a V) \\ U \u222a erase U x) \\ erase V y \u2208 \ud835\udc9c,\n          apply uncompressed_was_already_there this _ (disjoint_of_subset_left (erase_subset _ _) disjoint_sdiff),\n            rw [union_sdiff, \u2039V \\ U = V\u203a],\n            apply subset.trans (erase_subset _ _) (subset_union_right _ _), \n        suffices: ((insert x B \u222a V) \\ U \u222a erase U x) \\ erase V y = insert y B,\n          rwa \u2190 this,\n        by calc (((insert x B \u222a V) \\ U) \u222a erase U x) \\ erase V y \n            = (((insert x B \u222a V) \\ finset.singleton x \u222a erase U x) \u2229 ((insert x B \u222a V) \\ erase U x \u222a erase U x)) \\ erase V y : \n                                  by rw [\u2190 union_distrib_right, \u2190 sdiff_union, union_singleton_eq_insert, insert_erase a]\n        ... = (erase (insert x (B \u222a V)) x \u222a erase U x) \u2229 (insert x B \u222a V) \\ erase V y : \n                                  by rw sdiff_union_of_subset (trans (erase_subset _ _) (trans q.1 (subset_union_left _ _))); rw insert_union; rw sdiff_singleton_eq_erase \n        ... = (B \u222a erase U x \u222a V) \u2229 (insert x B \u222a V) \\ erase V y : \n                                  begin rw erase_insert, rw union_right_comm, rw mem_union, exact (\u03bb a_1, disjoint_left.1 \u2039disjoint V U\u203a (or.resolve_left a_1 \u2039x \u2209 B\u203a) \u2039x \u2208 U\u203a) end\n        ... = (B \u222a V) \\ erase V y : \n                                  by rw \u2190 union_distrib_right; congr; rw [not_sure (subset_insert_iff.1 q.1), inter_insert_of_not_mem \u2039x \u2209 B\u203a, inter_self]\n        ... = (insert y B \u222a erase V y) \\ erase V y :  \n                                  by rw [\u2190 union_singleton_eq_insert, union_comm _ B, union_assoc, union_singleton_eq_insert, insert_erase \u2039y \u2208 V\u203a]\n        ... = insert y B : \n                                  begin rw [union_sdiff_self, \u2190 new_thing, disjoint_insert_left], refine \u27e8not_mem_erase _ _, disjoint_of_subset_right (erase_subset _ _) \u2039disjoint V B\u203a.symm\u27e9 end,\n      have: U \u2286 B, rw [\u2190 erase_eq_of_not_mem \u2039x \u2209 U\u203a, \u2190 subset_insert_iff], exact q.1,\n      refine \u27e8\u2039_\u203a, \u2039_\u203a, _\u27e9,\n      rw mem_sdiff,\n      have: x \u2209 V := disjoint_right.1 q.2.1 (mem_insert_self _ _),\n      split,\n        rw mem_shadow',\n        refine \u27e8x, _, _\u27e9,\n        { simp [mem_sdiff, mem_union], safe },\n        have: insert x ((B \u222a V) \\ U) = (insert x B \u222a V) \\ U,\n          simp [ext, mem_sdiff, mem_union, mem_insert], \n          intro a,\n          split; intro p,\n            cases p,\n              rw p at *, tauto,\n            tauto,\n          tauto,\n        rw this, tauto,\n      rw mem_shadow',\n      rintro \u27e8w, _, _\u27e9,\n      by_cases (w \u2208 U),\n        rcases h\u2081 w \u2039w \u2208 U\u203a with \u27e8z, Hz, xy_comp\u27e9,\n        apply m z (disjoint_left.1 \u2039disjoint V B\u203a Hz),\n        have: insert w ((B \u222a V) \\ U) \u2208 \ud835\udc9c, {\n          apply compress_held a_h_h _ h\u2082, \n          apply subset.trans _ (subset_insert _ _),\n          rw union_sdiff, rw \u2039V \\ U = V\u203a, apply subset_union_right\n        },\n        have: (insert w ((B \u222a V) \\ U) \u222a erase U w) \\ erase V z \u2208 \ud835\udc9c,\n          refine uncompressed_was_already_there _ _ _, \n              rw is_compressed at xy_comp,\n              rwa xy_comp,\n            apply subset.trans (erase_subset _ _),\n            apply subset.trans _ (subset_insert _ _),\n            rw union_sdiff,\n            rw \u2039V \\ U = V\u203a,\n            apply subset_union_right,\n          rw disjoint_insert_right,\n          split, apply not_mem_erase,\n          apply disjoint_of_subset_left (erase_subset _ _),\n          apply disjoint_sdiff,\n        have: (insert w ((B \u222a V) \\ U) \u222a erase U w) \\ erase V z = insert z B,\n        by calc (insert w ((B \u222a V) \\ U) \u222a erase U w) \\ erase V z = (finset.singleton w \u222a ((B \u222a V) \\ U) \u222a erase U w) \\ erase V z : begin congr, end\n        ... = (((B \u222a V) \\ U) \u222a (finset.singleton w \u222a erase U w)) \\ erase V z : begin rw [union_left_comm, union_assoc] end\n        ... = (((B \u222a V) \\ U) \u222a U) \\ erase V z : begin congr, rw union_singleton_eq_insert, rw insert_erase h end\n        ... = (B \u222a V) \\ erase V z : begin rw sdiff_union_of_subset, apply subset.trans \u2039U \u2286 B\u203a (subset_union_left _ _) end\n        ... = B \\ erase V z \u222a V \\ erase V z : begin rw union_sdiff end\n        ... = B \u222a V \\ erase V z : begin congr, rw \u2190 new_thing, apply disjoint_of_subset_right (erase_subset _ _) \u2039disjoint V B\u203a.symm end\n        ... = B \u222a finset.singleton z : begin congr, ext, simp, split, intro p, by_contra, exact p.2 \u2039_\u203a p.1, intro p, rw p, tauto end\n        ... = insert z B : begin rw [union_comm, union_singleton_eq_insert] end,\n        rwa \u2190 this,\n      have: w \u2209 V,\n        intro, have: w \u2208 B \u222a V := mem_union_right _ \u2039_\u203a,\n        exact a_h_w (mem_sdiff.2 \u27e8\u2039_\u203a, \u2039_\u203a\u27e9),\n      have: w \u2209 B,\n        intro, have: w \u2208 B \u222a V := mem_union_left _ \u2039_\u203a,\n        exact a_h_w (mem_sdiff.2 \u27e8\u2039_\u203a, \u2039_\u203a\u27e9),\n      apply m w this,\n      \n      have: (insert w ((B \u222a V) \\ U) \u222a U) \\ V \u2208 \ud835\udc9c, \n      refine uncompressed_was_already_there \u2039insert w ((B \u222a V) \\ U) \u2208 \ud835\udc9c'\u203a (trans _ (subset_insert _ _)) _,\n          rw union_sdiff,\n           rw \u2039V \\ U = V\u203a,\n          apply subset_union_right,\n        rw disjoint_insert_right,\n        exact \u27e8\u2039_\u203a, disjoint_sdiff\u27e9,\n      suffices: insert w B = (insert w ((B \u222a V) \\ U) \u222a U) \\ V,\n        rwa this,\n      rw insert_union,\n      rw sdiff_union_of_subset (trans \u2039U \u2286 B\u203a (subset_union_left _ _)),\n      rw \u2190 insert_union,\n      rw union_sdiff_self, \n      conv {to_lhs, rw \u2190 sdiff_union_inter (insert w B) V},\n      suffices: insert w B \u2229 V = \u2205,\n        rw this, rw union_empty, \n      rw \u2190 disjoint_iff_inter_eq_empty,\n      rw disjoint_insert_left,\n      split,\n        assumption,\n      rwa disjoint.comm,\n    set f := (\u03bb B, (B \u222a V) \\ U),\n    apply card_le_card_of_inj_on f (\u03bb B HB, (q\u2081 B HB).2.2),\n    intros B\u2081 HB\u2081 B\u2082 HB\u2082 k,\n    exact inj_ish B\u2081 B\u2082 \u27e8(q\u2081 B\u2081 HB\u2081).2.1, (q\u2081 B\u2081 HB\u2081).1\u27e9 \u27e8(q\u2081 B\u2082 HB\u2082).2.1, (q\u2081 B\u2082 HB\u2082).1\u27e9 k\n  end\n\n  def bin_measure (A : finset X) : \u2115 := A.sum (\u03bb x, pow 2 x.val)\n\n  lemma binary_sum (k : \u2115) (A : finset \u2115) (h\u2081 : \u2200 x \u2208 A, x < k) : A.sum (pow 2) < 2^k :=\n  begin\n    apply lt_of_le_of_lt (sum_le_sum_of_subset (\u03bb t th, mem_range.2 (h\u2081 t th))),\n    have z := geom_sum_mul_add 1 k, rw [geom_series, mul_one] at z, \n    simp only [nat.pow_eq_pow] at z, rw \u2190 z, apply nat.lt_succ_self\n  end\n\n  lemma binary_sum' (k : \u2115) (A : finset X) (h\u2081 : \u2200 (x : X), x \u2208 A \u2192 x.val < k) : bin_measure A < 2^k :=\n  begin\n    suffices: bin_measure A = (A.image (\u03bb (x : X), x.val)).sum (pow 2),\n      rw this, apply binary_sum, intros t th, rw mem_image at th, rcases th with \u27e8_, _, _\u27e9,\n      rw \u2190 th_h_h, apply h\u2081 _ th_h_w, \n    rw [bin_measure, sum_image], intros x _ y _, exact fin.eq_of_veq,\n  end\n\n  lemma bin_lt_of_maxdiff (A B : finset X) : (\u2203 (k : X), k \u2209 A \u2227 k \u2208 B \u2227 (\u2200 (x : X), x > k \u2192 (x \u2208 A \u2194 x \u2208 B))) \u2192 bin_measure A < bin_measure B :=\n  begin\n    rintro \u27e8k, notinA, inB, maxi\u27e9,\n    have AeqB: A.filter (\u03bb x, \u00ac(x \u2264 k)) = B.filter (\u03bb x, \u00ac(x \u2264 k)),\n    { ext t, rw [mem_filter, mem_filter], \n      by_cases h: (t > k); simp [h], \n      apply maxi, exact h },\n    { have Alt: (A.filter (\u03bb x, x \u2264 k)).sum (\u03bb x, pow 2 x.val) < pow 2 k.1,\n        rw \u2190 bin_measure, apply binary_sum', intro t, rw mem_filter, intro b, \n        cases lt_or_eq_of_le b.2, exact h, rw h at b, exfalso, exact notinA b.1,\n      have leB: pow 2 k.1 \u2264 (B.filter (\u03bb x, x \u2264 k)).sum (\u03bb x, pow 2 x.val),\n        apply @single_le_sum _ _ (B.filter (\u03bb x, x \u2264 k)) (\u03bb (x : fin n), 2 ^ x.val) _ _ (\u03bb x _, zero_le _) k,\n        rw mem_filter, exact \u27e8inB, le_refl _\u27e9, \n      have AltB: (A.filter (\u03bb x, x \u2264 k)).sum (\u03bb x, pow 2 x.val) < (B.filter (\u03bb x, x \u2264 k)).sum (\u03bb x, pow 2 x.val) := lt_of_lt_of_le Alt leB,\n      have := nat.add_lt_add_right AltB (sum (filter (\u03bb (x : fin n), \u00ac(x \u2264 k)) A) (\u03bb (x : fin n), 2 ^ x.val)), \n      rwa [\u2190 sum_union, filter_union_filter_neg_eq, AeqB, \u2190 sum_union, filter_union_filter_neg_eq, \u2190 bin_measure, \u2190 bin_measure] at this,\n      rw disjoint_iff_inter_eq_empty, apply filter_inter_filter_neg_eq,\n      rw disjoint_iff_inter_eq_empty, apply filter_inter_filter_neg_eq }\n  end\n\n  lemma bin_iff (A B : finset X) : bin_measure A < bin_measure B \u2194 \u2203 (k : X), k \u2209 A \u2227 k \u2208 B \u2227 (\u2200 (x : X), x > k \u2192 (x \u2208 A \u2194 x \u2208 B)) := \n  begin\n    split, \n      intro p,\n      set differ := (elems X).filter (\u03bb x, \u00ac (x \u2208 A \u2194 x \u2208 B)),\n      have h: differ \u2260 \u2205,\n        intro q, suffices: A = B, rw this at p, exact irrefl _ p,\n        ext a, by_contra z, have: differ \u2260 \u2205 := ne_empty_of_mem (mem_filter.2 \u27e8complete _, z\u27e9), \n        exact this q,\n      set k := max' differ h, use k,\n      have z: \u2200 (x : fin n), x > k \u2192 (x \u2208 A \u2194 x \u2208 B),\n        intros t th, by_contra, apply not_le_of_gt th, apply le_max', simpa [complete], \n      rw \u2190 and.rotate, refine \u27e8z, _\u27e9,\n      have el: (k \u2208 A \u2227 k \u2209 B) \u2228 (k \u2209 A \u2227 k \u2208 B),\n        have := max'_mem differ h, rw mem_filter at this, tauto,\n      apply or.resolve_left el,\n      intro, apply not_lt_of_gt p (bin_lt_of_maxdiff B A \u27e8k, a.2, a.1, \u03bb x xh, (z x xh).symm\u27e9), \n    exact bin_lt_of_maxdiff _ _,\n  end\n\n  -- here\n  lemma bin_measure_inj (A B : finset X) : bin_measure A = bin_measure B \u2192 A = B :=\n  begin\n    intro p, set differ := (elems X).filter (\u03bb x, \u00ac (x \u2208 A \u2194 x \u2208 B)),\n    by_cases h: (differ = \u2205),\n      ext a, by_contra z, have: differ \u2260 \u2205 := ne_empty_of_mem (mem_filter.2 \u27e8complete _, z\u27e9), \n      exact this h,\n    set k := max' differ h,\n    have el: (k \u2208 A \u2227 k \u2209 B) \u2228 (k \u2209 A \u2227 k \u2208 B),\n      have := max'_mem differ h, rw mem_filter at this, tauto,\n    exfalso,\n    cases el,\n      apply not_le_of_gt ((bin_iff B A).2 \u27e8k, el.2, el.1, _\u27e9) (le_of_eq p), swap,\n      apply not_le_of_gt ((bin_iff A B).2 \u27e8k, el.1, el.2, _\u27e9) (ge_of_eq p), \n    all_goals { intros x xh, by_contra, apply not_le_of_gt xh, apply le_max', simp only [complete, true_and, mem_filter], tauto }, \n  end\n\n  def c_measure (\ud835\udc9c : finset (finset X)) : \u2115 := \ud835\udc9c.sum bin_measure\n\n  lemma compression_reduces_bin_measure {U V : finset X} (hU : U \u2260 \u2205) (hV : V \u2260 \u2205) (A : finset X) (h : max' U hU < max' V hV) : compress U V A \u2260 A \u2192 bin_measure (compress U V A) < bin_measure A :=\n  begin\n    intro a,\n    rw compress at a \u22a2,\n    split_ifs at a \u22a2,\n    { rw bin_measure, rw bin_measure,\n      rw \u2190 add_lt_add_iff_right,\n        have q : V \u2286 (A \u222a U) := trans h_1.2 (subset_union_left _ _),\n        rw sum_sdiff q,\n      rw [sum_union h_1.1.symm, add_lt_add_iff_left],\n      set kV := (max' V hV).1,\n      set kU := (max' U hU).1,\n      have a3: 2^kV \u2264 sum V (\u03bb (x : fin n), pow 2 x.val) := @single_le_sum _ _ V (\u03bb x, pow 2 x.val) _ _ (\u03bb t _, zero_le _) _ (max'_mem V hV),\n      have a1: sum U (\u03bb (x : fin n), 2 ^ x.val) < 2^(kU+1), \n        { rw \u2190 bin_measure, apply binary_sum', intros x hx, rw nat.lt_succ_iff, apply le_max' U _ _ hx },\n      have a2: kU + 1 \u2264 kV, exact h,\n      apply lt_of_lt_of_le a1,\n      transitivity (2^kV), rwa nat.pow_le_iff_le_right (le_refl 2),\n      assumption },\n    { exfalso, apply a, refl }\n  end\n\n  def compression_reduces_measure (U V : finset X) (hU : U \u2260 \u2205) (hV : V \u2260 \u2205) (h : max' U hU < max' V hV) (\ud835\udc9c : finset (finset X)) : compress_family U V \ud835\udc9c \u2260 \ud835\udc9c \u2192 c_measure (compress_family U V \ud835\udc9c) < c_measure \ud835\udc9c :=\n  begin\n    rw [compress_family], intro, \n    rw [c_measure, c_measure, sum_union (compress_disjoint U V)],\n    conv {to_rhs, rw \u2190 @filter_union_filter_neg_eq _ (\u03bb A, C A \u2208 \ud835\udc9c) _ _ \ud835\udc9c, rw sum_union (disjoint_iff_inter_eq_empty.2 (filter_inter_filter_neg_eq _)) },\n    rw [add_comm, add_lt_add_iff_left, sum_image],\n      apply sum_lt_sum,\n      { intro a\u2081,\n        rw [compress_remains, compress_motion, a\u2081, image_empty, empty_union] at a,\n        apply a,\n        conv_rhs {rw \u2190 @filter_union_filter_neg_eq _ (\u03bb A, C A \u2208 \ud835\udc9c) _ _ \ud835\udc9c}, conv {to_lhs, rw \u2190 union_empty (filter _ \ud835\udc9c)},\n        symmetry,\n        rw \u2190 a\u2081 },\n      intros A HA,\n      apply compression_reduces_bin_measure _ _ _ h,\n      intro a\u2081, rw [mem_filter, a\u2081] at HA,\n      tauto,\n    intros x Hx y Hy k,\n    rw mem_filter at Hx Hy,\n    have cx: compress U V x \u2260 x, intro b, rw b at Hx, tauto,\n    have cy: compress U V y \u2260 y, intro b, rw b at Hy, tauto,\n    rw compress at k Hx cx, split_ifs at k Hx cx,\n      rw compress at k Hy cy, split_ifs at k Hy cy,\n        apply inj_ish x y h_1 h_2 k,\n      tauto,\n    tauto,\n  end\n\n  def gamma : rel (finset X) (finset X) := (\u03bb U V, \u2203 (HU : U \u2260 \u2205), \u2203 (HV : V \u2260 \u2205), disjoint U V \u2227 finset.card U = finset.card V \u2227 max' U HU < max' V HV)\n\n  lemma compression_improved {r : \u2115} (U V : finset X) (\ud835\udc9c : finset (finset X)) (h : is_layer \ud835\udc9c r) (h\u2081 : gamma U V) \n    (h\u2082 : \u2200 U\u2081 V\u2081, gamma U\u2081 V\u2081 \u2227 U\u2081.card < U.card \u2192 is_compressed U\u2081 V\u2081 \ud835\udc9c) (h\u2083 : \u00ac is_compressed U V \ud835\udc9c): \n    c_measure (compress_family U V \ud835\udc9c) < c_measure \ud835\udc9c \u2227 (compress_family U V \ud835\udc9c).card = \ud835\udc9c.card \u2227 is_layer (compress_family U V \ud835\udc9c) r \u2227 (\u2202 compress_family U V \ud835\udc9c).card \u2264 (\u2202\ud835\udc9c).card := \n  begin\n    rcases h\u2081 with \u27e8Uh, Vh, UVd, same_size, max_lt\u27e9,\n    refine \u27e8compression_reduces_measure U V Uh Vh max_lt _ h\u2083, compressed_size _ _, _, _\u27e9,\n    apply' compress_family_size _ _ _ _ UVd same_size h, \n    apply compression_reduces_shadow U V _ same_size,\n    intros x Hx, refine \u27e8min' V Vh, min'_mem _ _, _\u27e9,\n    by_cases p: (2 \u2264 U.card),\n    { apply h\u2082,\n      refine \u27e8\u27e8_, _, _, _, _\u27e9, card_erase_lt_of_mem Hx\u27e9,\n      { rwa [\u2190 card_pos, card_erase_of_mem Hx, nat.lt_pred_iff] },\n      { rwa [\u2190 card_pos, card_erase_of_mem (min'_mem _ _), \u2190 same_size, nat.lt_pred_iff] },\n      { apply disjoint_of_subset_left (erase_subset _ _), apply disjoint_of_subset_right (erase_subset _ _), assumption },\n      { rw [card_erase_of_mem (min'_mem _ _), card_erase_of_mem Hx, same_size] },\n      { have: max' (erase U _) _ \u2264 max' U Uh := max'_le _ _ _ (\u03bb y Hy, le_max' _ Uh _ (mem_of_mem_erase Hy)),\n        apply lt_of_le_of_lt this,\n        apply lt_of_lt_of_le max_lt,\n        apply le_max',\n        rw mem_erase,\n        refine \u27e8_, max'_mem _ _\u27e9,\n        intro,\n        rw same_size at p,\n        apply not_le_of_gt p,\n        apply le_of_eq,\n        rw card_eq_one,\n        use max' V Vh,\n        rw eq_singleton_iff_unique_mem,\n        refine \u27e8max'_mem _ _, \u03bb t Ht, _\u27e9,\n        apply le_antisymm,\n          apply le_max' _ _ _ Ht,\n        rw a, apply min'_le _ _ _ Ht } },\n    rw \u2190 card_pos at Uh,\n    replace p: card U = 1 := le_antisymm (le_of_not_gt p) Uh,\n    rw p at same_size,\n    have: erase U x = \u2205,\n      rw [\u2190 card_eq_zero, card_erase_of_mem Hx, p], refl,\n    have: erase V (min' V Vh) = \u2205,\n      rw [\u2190 card_eq_zero, card_erase_of_mem (min'_mem _ _), \u2190 same_size], refl,\n    rw [\u2039erase U x = \u2205\u203a, \u2039erase V (min' V Vh) = \u2205\u203a],\n    apply is_compressed_empty\n  end\n\n  instance thing (U V : finset X) : decidable (gamma U V) := by rw gamma; apply_instance\n  instance thing2 (U V : finset X) (A : finset (finset X)) : decidable (is_compressed U V A) := by rw is_compressed; apply_instance\n\n  lemma kruskal_katona_helper (r : \u2115) (\ud835\udc9c : finset (finset X)) (h : is_layer \ud835\udc9c r) : \n    \u2203 (\u212c : finset (finset X)), (\u2202\u212c).card \u2264 (\u2202\ud835\udc9c).card \u2227 \ud835\udc9c.card = \u212c.card \u2227 is_layer \u212c r \u2227 (\u2200 U V, gamma U V \u2192 is_compressed U V \u212c) := \n  begin\n    refine @well_founded.recursion _ _ (measure_wf c_measure) (\u03bb (A : finset (finset X)), is_layer A r \u2192 \u2203 B, (\u2202B).card \u2264 (\u2202A).card \u2227 A.card = B.card \u2227 is_layer B r \u2227 \u2200 (U V : finset X), gamma U V \u2192 is_compressed U V B) _ _ h,\n    intros A ih z,\n    set usable: finset (finset X \u00d7 finset X) := filter (\u03bb t, gamma t.1 t.2 \u2227 \u00ac is_compressed t.1 t.2 A) ((powerset (elems X)).product (powerset (elems X))), \n    by_cases (usable = \u2205),\n      refine \u27e8A, le_refl _, rfl, z, _\u27e9, intros U V k,\n      rw eq_empty_iff_forall_not_mem at h,\n      by_contra,\n      apply h \u27e8U,V\u27e9,\n      simp [a, k], exact \u27e8subset_univ _, subset_univ _\u27e9,\n    rcases exists_min usable (\u03bb t, t.1.card) ((nonempty_iff_ne_empty _).2 h) with \u27e8\u27e8U,V\u27e9, uvh, t\u27e9, rw mem_filter at uvh,\n    have h\u2082: \u2200 U\u2081 V\u2081, gamma U\u2081 V\u2081 \u2227 U\u2081.card < U.card \u2192 is_compressed U\u2081 V\u2081 A,\n      intros U\u2081 V\u2081 h, by_contra, \n      apply not_le_of_gt h.2 (t \u27e8U\u2081, V\u2081\u27e9 _),\n      simp [h, a], exact \u27e8subset_univ _, subset_univ _\u27e9,\n    obtain \u27e8small_measure, p2, layered, p1\u27e9 := compression_improved U V A z uvh.2.1 h\u2082 uvh.2.2, \n    rw [measure, inv_image] at ih, \n    rcases ih (compress_family U V A) small_measure layered with \u27e8B, q1, q2, q3, q4\u27e9,\n    exact \u27e8B, trans q1 p1, trans p2.symm q2, q3, q4\u27e9\n  end\n\n  def binary : finset X \u2192 finset X \u2192 Prop := inv_image (<) bin_measure\n  local infix ` \u227a `:50 := binary\n\n  instance : is_trichotomous (finset X) binary := \u27e8\n    begin\n      intros A B,\n      rcases lt_trichotomy (bin_measure A) (bin_measure B) with lt|eq|gt,\n      { left, exact lt },\n      { right, left, exact bin_measure_inj A B eq },\n      { right, right, exact gt }\n    end\n  \u27e9\n\n  def is_init_seg_of_colex (\ud835\udc9c : finset (finset X)) (r : \u2115) : Prop := is_layer \ud835\udc9c r \u2227 (\u2200 A \u2208 \ud835\udc9c, \u2200 B, B \u227a A \u2227 B.card = r \u2192 B \u2208 \ud835\udc9c)\n\n  lemma init_seg_total (\ud835\udc9c\u2081 \ud835\udc9c\u2082 : finset (finset X)) (r : \u2115) (h\u2081 : is_init_seg_of_colex \ud835\udc9c\u2081 r) (h\u2082 : is_init_seg_of_colex \ud835\udc9c\u2082 r) : \ud835\udc9c\u2081 \u2286 \ud835\udc9c\u2082 \u2228 \ud835\udc9c\u2082 \u2286 \ud835\udc9c\u2081 :=\n  begin\n    rw \u2190 sdiff_eq_empty_iff_subset, rw \u2190 sdiff_eq_empty_iff_subset,\n    by_contra a, rw not_or_distrib at a, simp [exists_mem_iff_ne_empty.symm, exists_mem_iff_ne_empty.symm] at a,\n    rcases a with \u27e8\u27e8A, Ah\u2081, Ah\u2082\u27e9, \u27e8B, Bh\u2081, Bh\u2082\u27e9\u27e9,\n    rcases trichotomous_of binary A B with lt | eq | gt,\n      { exact Ah\u2082 (h\u2082.2 B Bh\u2081 A \u27e8lt, h\u2081.1 A Ah\u2081\u27e9) },\n      { rw eq at Ah\u2081, exact Bh\u2082 Ah\u2081 },\n      { exact Bh\u2082 (h\u2081.2 A Ah\u2081 B \u27e8gt, h\u2082.1 B Bh\u2081\u27e9) },\n  end\n\n  lemma init_seg_of_compressed (\u212c : finset (finset X)) (r : \u2115) (h\u2081 : is_layer \u212c r) (h\u2082 : \u2200 U V, gamma U V \u2192 is_compressed U V \u212c): \n    is_init_seg_of_colex \u212c r := \n  begin\n    refine \u27e8h\u2081, _\u27e9,\n    rintros B Bh A \u27e8A_lt_B, sizeA\u27e9,\n    by_contra a,\n    set U := A \\ B,\n    set V := B \\ A,\n    have: A \u2260 B, intro t, rw t at a, exact a Bh,\n    have: disjoint U B \u2227 V \u2286 B := \u27e8sdiff_disjoint, sdiff_subset_left _ _\u27e9,\n    have: disjoint V A \u2227 U \u2286 A := \u27e8sdiff_disjoint, sdiff_subset_left _ _\u27e9,\n    have cB_eq_A: compress U V B = A,\n    { rw compress, split_ifs, rw [union_sdiff_self_eq_union, union_sdiff, new_thing.1 disjoint_sdiff, union_comm], \n      apply not_sure,\n      intro t, simp only [and_imp, not_and, mem_sdiff, not_not], exact (\u03bb x y, y x) },\n    have cA_eq_B: compress V U A = B,\n    { rw compress, split_ifs, rw [union_sdiff_self_eq_union, union_sdiff, new_thing.1 disjoint_sdiff, union_comm], \n      apply not_sure,\n      intro t, simp only [and_imp, not_and, mem_sdiff, not_not], exact (\u03bb x y, y x) },\n    have: card A = card B := trans sizeA (h\u2081 B Bh).symm,\n    have hU: U \u2260 \u2205,\n      { intro t, rw sdiff_eq_empty_iff_subset at t, have: A = B := eq_of_subset_of_card_le t (ge_of_eq \u2039_\u203a), rw this at a, exact a Bh },\n    have hV: V \u2260 \u2205,\n      { intro t, rw sdiff_eq_empty_iff_subset at t, have: B = A := eq_of_subset_of_card_le t (le_of_eq \u2039_\u203a), rw \u2190 this at a, exact a Bh },\n    have disj: disjoint U V,\n      { exact disjoint_of_subset_left (sdiff_subset_left _ _) disjoint_sdiff },\n    have smaller: max' U hU < max' V hV,\n      { rcases lt_trichotomy (max' U hU) (max' V hV) with lt | eq | gt,\n        { assumption },\n        { exfalso, have: max' U hU \u2208 U := max'_mem _ _, apply disjoint_left.1 disj this, rw eq, exact max'_mem _ _ },\n        { exfalso, have z := compression_reduces_bin_measure hV hU A gt, rw cA_eq_B at z,\n          apply irrefl (bin_measure B) (trans (z \u2039A \u2260 B\u203a.symm) A_lt_B)\n        },\n      },\n    have: gamma U V,\n    { refine \u27e8hU, hV, disj, _, smaller\u27e9,\n      have: card (A \\ B \u222a A \u2229 B) = card (B \\ A \u222a B \u2229 A),\n        rwa [sdiff_union_inter, sdiff_union_inter],\n      rwa [card_disjoint_union (sdiff_inter_inter _ _), card_disjoint_union (sdiff_inter_inter _ _), inter_comm, add_right_inj] at this\n    },\n    have Bcomp := h\u2082 U V this, rw is_compressed at Bcomp,\n    suffices: compress U V B \u2208 compress_family U V \u212c,\n      rw [Bcomp, cB_eq_A] at this, exact a this,\n    rw mem_compress, left, refine \u27e8_, B, Bh, rfl\u27e9, rwa cB_eq_A, \n  end\n\n  lemma exists_max {\u03b1 \u03b2 : Type*} [decidable_linear_order \u03b1] (s : finset \u03b2) (f : \u03b2 \u2192 \u03b1)\n    (h : s \u2260 \u2205) : \u2203 x \u2208 s, \u2200 x' \u2208 s, f x' \u2264 f x :=\n  begin\n    have : s.image f \u2260 \u2205,\n      rwa [ne, image_eq_empty, \u2190 ne.def],\n    cases max_of_ne_empty this with y hy,\n    rcases mem_image.mp (mem_of_max hy) with \u27e8x, hx, rfl\u27e9,\n    exact \u27e8x, hx, \u03bb x' hx', le_max_of_mem (mem_image_of_mem f hx') hy\u27e9,\n  end\n\n  def everything_up_to (A : finset X) : finset (finset X) := filter (\u03bb (B : finset X), A.card = B.card \u2227 bin_measure B \u2264 bin_measure A) (powerset (elems X))\n\n  lemma IS_iff_le_max (\ud835\udc9c : finset (finset X)) (r : \u2115) : \ud835\udc9c \u2260 \u2205 \u2227 is_init_seg_of_colex \ud835\udc9c r \u2194 \u2203 (A : finset X), A \u2208 \ud835\udc9c \u2227 A.card = r \u2227 \ud835\udc9c = everything_up_to A := \n  begin\n    rw is_init_seg_of_colex, split, \n    { rintro \u27e8ne, layer, IS\u27e9,\n      rcases exists_max \ud835\udc9c bin_measure ne with \u27e8A, Ah, Ap\u27e9,\n      refine \u27e8A, Ah, layer A Ah, _\u27e9,\n      ext B, rw [everything_up_to, mem_filter, mem_powerset], split; intro p,\n        refine \u27e8subset_univ _, _, _\u27e9,\n          convert layer A Ah, apply layer B p, \n        apply Ap _ p, \n      cases lt_or_eq_of_le p.2.2 with h h,\n        apply IS A Ah B \u27e8h, trans p.2.1.symm (layer A Ah)\u27e9, \n      rwa (bin_measure_inj _ _ h), \n    },\n    { rintro \u27e8A, Ah, Ac, Ap\u27e9,\n      refine \u27e8ne_empty_of_mem Ah, _, _\u27e9,\n        intros B Bh, rw [Ap, everything_up_to, mem_filter] at Bh, exact (trans Bh.2.1.symm Ac),\n      intros B\u2081 Bh\u2081 B\u2082 Bh\u2082, rw [Ap, everything_up_to, mem_filter, mem_powerset], refine \u27e8_, _, _\u27e9,\n      { apply subset_univ },\n      { exact (trans Ac Bh\u2082.2.symm) },\n      { rw [binary, inv_image] at Bh\u2082, transitivity, apply le_of_lt Bh\u2082.1, rw [Ap, everything_up_to, mem_filter] at Bh\u2081, exact Bh\u2081.2.2 }\n    }\n  end\n\n  lemma up_to_is_IS (A : finset X) {r : \u2115} (h\u2081 : A.card = r) : is_init_seg_of_colex (everything_up_to A) r := \n  and.right $ (IS_iff_le_max _ _).2 \n  (by refine \u27e8A, _, h\u2081, rfl\u27e9; rw [everything_up_to, mem_filter, mem_powerset]; refine \u27e8subset_univ _, rfl, le_refl _\u27e9)\n\n  lemma shadow_of_everything_up_to (A : finset X) (hA : A \u2260 \u2205) : \u2202 (everything_up_to A) = everything_up_to (erase A (min' A hA)) :=\n  begin\n    ext B, split, \n      rw [mem_shadow', everything_up_to, everything_up_to, mem_filter, mem_powerset], rintro \u27e8i, ih, p\u27e9,\n      rw [mem_filter, card_insert_of_not_mem ih] at p, \n      have cards: card (erase A (min' A hA)) = card B,\n        rw [card_erase_of_mem (min'_mem _ _), p.2.1], refl,\n      refine \u27e8subset_univ _, cards, _\u27e9, \n      cases lt_or_eq_of_le p.2.2 with h h,\n      { rw bin_iff at h, rcases h with \u27e8k, knotin, kin, h\u27e9,\n        have: k \u2260 i, rw mem_insert at knotin, tauto,\n        cases lt_or_gt_of_ne this with h\u2081 h\u2081,\n          have q: i \u2208 A := (h _ h\u2081).1 (mem_insert_self _ _), \n          apply le_of_lt, rw bin_iff,\n          refine \u27e8i, ih, _, _\u27e9,\n            apply mem_erase_of_ne_of_mem _ q,\n            apply ne_of_gt, apply lt_of_le_of_lt _ h\u2081, \n            apply min'_le _ _ _ kin,\n          intros x hx, have z := trans hx h\u2081, have := h _ z, simp at this \u22a2, \n          have a1: \u00acx = min' A hA := ne_of_gt (lt_of_le_of_lt (min'_le _ hA _ q) hx), \n          have a2: \u00acx = i := ne_of_gt hx, tauto, \n        cases lt_or_eq_of_le (min'_le _ hA _ kin),\n          apply le_of_lt, rw bin_iff,\n          refine \u27e8k, mt mem_insert_of_mem knotin, mem_erase_of_ne_of_mem (ne_of_gt h_1) kin, _\u27e9,\n          intros x hx, have := h _ hx, simp at this \u22a2,\n          have a1: \u00acx = min' A hA := ne_of_gt (lt_of_le_of_lt (min'_le _ hA _ kin) hx), \n          have a2: \u00acx = i := ne_of_gt (trans hx h\u2081), tauto, \n        apply le_of_eq,\n        congr, have: erase A (min' A hA) \u2286 B,\n          intros t th, rw mem_erase at th, \n          have: t > k := h_1 \u25b8 (lt_of_le_of_ne (min'_le _ _ _ th.2) th.1.symm),\n          apply mem_of_mem_insert_of_ne ((h t this).2 th.2) (ne_of_gt (trans this h\u2081)),\n          symmetry,\n          apply eq_of_subset_of_card_le this (le_of_eq cards.symm) },\n      { replace h := bin_measure_inj _ _ h,\n        have z: i \u2208 A, rw \u2190 h, exact mem_insert_self _ _,\n        rw [bin_measure, bin_measure, \u2190 sdiff_singleton_eq_erase], \n        rw \u2190 add_le_add_iff_right (sum (finset.singleton i) (\u03bb (x : fin n), 2 ^ x.val)), \n        rw [\u2190 sum_union (disjoint_singleton.2 ih), union_comm, union_singleton_eq_insert, h], \n        rw \u2190 sum_sdiff (show finset.singleton (min' A hA) \u2286 A, by intro t; simp; intro th; rw th; exact min'_mem _ _), \n        rw [add_le_add_iff_left, sum_singleton, sum_singleton], apply nat.pow_le_pow_of_le_right zero_lt_two,\n        exact min'_le _ _ _ z },\n    intro p,\n    rw [everything_up_to, mem_filter, mem_powerset] at p,\n    simp only [mem_shadow', everything_up_to, mem_filter, mem_powerset], \n    cases eq_or_lt_of_le p.2.2,\n      have: B = erase A (min' A hA) := bin_measure_inj _ _ h,\n      { rw this, refine \u27e8min' A hA, not_mem_erase _ _, _\u27e9, rw insert_erase (min'_mem _ _), simp [le_refl], apply subset_univ },\n    rw bin_iff at h, rcases h with \u27e8k, knotin, kin, h\u27e9,\n    have kincomp := mem_sdiff.2 \u27e8mem_univ _, knotin\u27e9,\n    have jex: univ \\ B \u2260 \u2205 := ne_empty_of_mem (mem_sdiff.2 \u27e8mem_univ _, knotin\u27e9),\n    set j := min' (univ \\ B) jex,\n    have jnotin: j \u2209 B,\n      have: j \u2208 univ \\ B := min'_mem _ _, rw mem_sdiff at this, \n      tauto,\n    have cards: card A = card (insert j B),\n    { rw [card_insert_of_not_mem jnotin, \u2190 p.2.1, card_erase_of_mem (min'_mem _ _), nat.pred_eq_sub_one, nat.sub_add_cancel], \n      apply nat.pos_of_ne_zero, rw ne, rw card_eq_zero, exact hA },\n    refine \u27e8j, jnotin, subset_univ _, cards, _\u27e9,\n    cases eq_or_lt_of_le (min'_le _ jex _ kincomp) with h\u2081 h_1, \n    { have: j = k, rw \u2190 h\u2081, rw this at *, clear jnotin this j,\n      suffices: insert k B = A, apply le_of_eq, rw this, symmetry, \n      apply eq_of_subset_of_card_le, \n      { intros t th, rcases lt_trichotomy t k with lt | rfl | gt,\n        { apply mem_insert_of_mem, by_contra, have: t \u2208 univ \\ B, simpa, apply not_le_of_lt lt, rw \u2190 h\u2081, apply min'_le _ _ _ this },\n        { apply mem_insert_self },\n        { apply mem_insert_of_mem, rw (h t gt), rw mem_erase, refine \u27e8_, th\u27e9, apply ne_of_gt, apply lt_of_le_of_lt _ gt, apply min'_le, apply mem_of_mem_erase kin } }, \n      { apply le_of_eq cards.symm } }, \n    { apply le_of_lt, rw bin_iff, refine \u27e8k, _, _, _\u27e9, \n      { rw [mem_insert], have: j \u2260 k := ne_of_lt h_1, tauto },\n      exact mem_of_mem_erase kin, intros x xh, have use := h x xh, \n      have: x \u2260 min' A hA := ne_of_gt (lt_of_le_of_lt (min'_le _ _ _ (mem_of_mem_erase kin)) xh),\n      have: x \u2260 j := ne_of_gt (trans xh h_1),\n      simp at use \u22a2, tauto\n    }\n  end\n\n  -- kill the condition\n  lemma shadow_of_IS {\ud835\udc9c : finset (finset X)} (r : \u2115) (h\u2081 : is_init_seg_of_colex \ud835\udc9c r) : is_init_seg_of_colex (\u2202\ud835\udc9c) (r - 1) :=\n  begin\n    cases nat.eq_zero_or_pos r with h0 hr,\n      have: \ud835\udc9c \u2286 finset.singleton \u2205,\n      intros A hA, rw mem_singleton, rw \u2190 card_eq_zero, rw \u2190 h0, apply h\u2081.1 A hA, rw h0, simp, \n      have := bind_sub_bind_of_sub_left this, rw [\u2190 shadow, singleton_bind, all_removals, image_empty, subset_empty] at this, \n      rw this, split, rw [is_layer, forall_mem_empty_iff], trivial, rw forall_mem_empty_iff, trivial, \n    by_cases h\u2082: \ud835\udc9c = \u2205,\n      rw h\u2082, rw shadow, rw bind_empty, rw is_init_seg_of_colex, rw is_layer, rw forall_mem_empty_iff, rw forall_mem_empty_iff, simp,\n    replace h\u2081 := and.intro h\u2082 h\u2081,\n    rw IS_iff_le_max at h\u2081,\n    rcases h\u2081 with \u27e8B, _, Bcard, rfl\u27e9, \n    rw shadow_of_everything_up_to, \n    apply up_to_is_IS,\n    rw card_erase_of_mem, rw Bcard, refl,\n    apply min'_mem, \n    rw \u2190 card_pos, rw Bcard, exact hr\n  end\nend\nend UV\n\nlemma killing {\u03b1 : Type*} [decidable_eq \u03b1] (A : finset \u03b1) (i k : \u2115) (h\u2081 : card A = i + k) : \u2203 (B : finset \u03b1), B \u2286 A \u2227 card B = i :=\nbegin\n  revert A, induction k with k ih,\n  simp, intros A hA, use A, exact \u27e8subset.refl _, hA\u27e9,\n  intros A hA, have: \u2203 i, i \u2208 A, rw exists_mem_iff_ne_empty, rw \u2190 ne, rw \u2190 card_pos, rw hA, rw nat.add_succ, apply nat.succ_pos,\n  rcases this with \u27e8a, ha\u27e9,\n  set A' := erase A a,\n  have z: card A' = i + k,\n    rw card_erase_of_mem ha, rw hA, rw nat.add_succ, rw nat.pred_succ, \n  rcases ih A' z with \u27e8B, hB, cardB\u27e9,\n  refine \u27e8B, _, cardB\u27e9, apply trans hB _, apply erase_subset\nend\n\nlemma killing2 {\u03b1 : Type*} [decidable_eq \u03b1] (A B : finset \u03b1) (i k : \u2115) (h\u2081 : card A = i + k + card B) (h\u2082 : B \u2286 A) : \u2203 (C : finset \u03b1), B \u2286 C \u2227 C \u2286 A \u2227 card C = i + card B :=\nbegin\n  revert A, induction k with k ih,\n  simp, intros A cards BsubA, refine \u27e8A, BsubA, subset.refl _, cards\u27e9,\n  intros A cards BsubA, have: \u2203 i, i \u2208 A \\ B, rw exists_mem_iff_ne_empty, rw [\u2190 ne, \u2190 card_pos, card_sdiff BsubA, cards, nat.add_sub_cancel, nat.add_succ], apply nat.succ_pos,\n  rcases this with \u27e8a, ha\u27e9,\n  set A' := erase A a,\n  have z: card A' = i + k + card B,\n    rw card_erase_of_mem, rw cards, rw nat.add_succ, rw nat.succ_add, rw nat.pred_succ, rw mem_sdiff at ha, exact ha.1,\n  rcases ih A' z _ with \u27e8B', hB', B'subA', cards\u27e9,\n  refine \u27e8B', hB', trans B'subA' (erase_subset _ _), cards\u27e9, \n  intros t th, apply mem_erase_of_ne_of_mem, intro, rw mem_sdiff at ha, rw a_1 at th, exact ha.2 th, exact BsubA th,\nend\n\nlemma killing2_sets {\u03b1 : Type*} [decidable_eq \u03b1] (A B : finset \u03b1) (i : \u2115) (h\u2081 : card A \u2265 i + card B) (h\u2082 : B \u2286 A) : \u2203 (C : finset \u03b1), B \u2286 C \u2227 C \u2286 A \u2227 card C = i + card B :=\nbegin\n  rcases nat.le.dest h\u2081,\n  rw add_right_comm at h, \n  apply killing2 A B i w h.symm h\u2082,\nend\n\nlemma kill_sets {\u03b1 : Type*} [decidable_eq \u03b1] (A : finset \u03b1) (i : \u2115) (h\u2081 : card A \u2265 i) : \u2203 (B : finset \u03b1), B \u2286 A \u2227 card B = i := \nbegin\n  rcases nat.le.dest h\u2081,\n  apply killing A i w h.symm, \nend\n\nsection KK\n  theorem kruskal_katona (r : \u2115) (\ud835\udc9c \ud835\udc9e : finset (finset X)) : \n    is_layer \ud835\udc9c r \u2227 is_layer \ud835\udc9e r \u2227 \ud835\udc9c.card = \ud835\udc9e.card \u2227 UV.is_init_seg_of_colex \ud835\udc9e r \n  \u2192 (\u2202\ud835\udc9e).card \u2264 (\u2202\ud835\udc9c).card :=\n  begin\n    rintros \u27e8layerA, layerC, h\u2083, h\u2084\u27e9,\n    rcases UV.kruskal_katona_helper r \ud835\udc9c layerA with \u27e8\u212c, _, t, layerB, fully_comp\u27e9,\n    have: UV.is_init_seg_of_colex \u212c r := UV.init_seg_of_compressed \u212c r layerB fully_comp,\n    suffices: \ud835\udc9e = \u212c,\n      rwa this at *,\n    have z: card \u212c = card \ud835\udc9e := t.symm.trans h\u2083,\n    cases UV.init_seg_total \u212c \ud835\udc9e r this h\u2084 with BC CB,\n      symmetry, apply eq_of_subset_of_card_le BC (ge_of_eq z),\n    apply eq_of_subset_of_card_le CB (le_of_eq z)\n  end\n\n  theorem strengthened (r : \u2115) (\ud835\udc9c \ud835\udc9e : finset (finset X)) : \n    is_layer \ud835\udc9c r \u2227 is_layer \ud835\udc9e r \u2227 \ud835\udc9e.card \u2264 \ud835\udc9c.card \u2227 UV.is_init_seg_of_colex \ud835\udc9e r \n  \u2192 (\u2202\ud835\udc9e).card \u2264 (\u2202\ud835\udc9c).card :=\n  begin\n    rintros \u27e8Ar, Cr, cards, colex\u27e9,\n    rcases kill_sets \ud835\udc9c \ud835\udc9e.card cards with \u27e8\ud835\udc9c', prop, size\u27e9,\n    have := kruskal_katona r \ud835\udc9c' \ud835\udc9e \u27e8\u03bb A hA, Ar _ (prop hA), Cr, size, colex\u27e9,\n    transitivity, exact this, apply card_le_of_subset, rw [shadow, shadow], apply bind_sub_bind_of_sub_left prop\n  end\n\n  theorem lovasz_form {r k : \u2115} {\ud835\udc9c : finset (finset X)} (hr1 : r \u2265 1) (hkn : k \u2264 n) (hrk : r \u2264 k) (h\u2081 : is_layer \ud835\udc9c r) (h\u2082 : \ud835\udc9c.card \u2265 nat.choose k r) : \n    (\u2202\ud835\udc9c).card \u2265 nat.choose k (r-1) :=\n  begin\n    set range'k : finset X := attach_fin (range k) (\u03bb m, by rw mem_range; apply forall_lt_iff_le.2 hkn),\n    set \ud835\udc9e : finset (finset X) := powerset_len r (range'k),\n    have Ccard: \ud835\udc9e.card = nat.choose k r,\n      rw [card_powerset_len, card_attach_fin, card_range], \n    have: is_layer \ud835\udc9e r, intros A HA, rw mem_powerset_len at HA, exact HA.2,\n    suffices this: (\u2202\ud835\udc9e).card = nat.choose k (r-1),\n    { rw \u2190 this, apply strengthened r _ _ \u27e8h\u2081, \u2039is_layer \ud835\udc9e r\u203a, _, _\u27e9, \n      rwa Ccard, \n      refine \u27e8\u2039_\u203a, _\u27e9, rintros A HA B \u27e8HB\u2081, HB\u2082\u27e9, \n      rw mem_powerset_len, refine \u27e8_, \u2039_\u203a\u27e9, \n      intros t th, rw mem_attach_fin, rw mem_range, \n      by_contra, simp at a, \n      rw [UV.binary, inv_image] at HB\u2081,\n      apply not_le_of_gt HB\u2081, \n      transitivity 2^k,\n        apply le_of_lt, \n        apply UV.binary_sum',\n        intros x hx, rw mem_powerset_len at HA, exact mem_range.1 ((mem_attach_fin _).1 (HA.1 hx)), \n      have: (\u03bb (x : X), 2^x.val) t \u2264 _ := single_le_sum _ th, \n        transitivity, apply nat.pow_le_pow_of_le_right zero_lt_two a, rwa UV.bin_measure,\n      intros _ _, apply zero_le },\n    suffices: \u2202\ud835\udc9e = powerset_len (r-1) (range'k),\n      rw [this, card_powerset_len, card_attach_fin, card_range], \n    ext A, rw mem_powerset_len, split,\n      rw mem_shadow, rintro \u27e8B, Bh, i, ih, BA\u27e9,\n      refine \u27e8_, _\u27e9; rw \u2190 BA; rw mem_powerset_len at Bh,\n        intro j, rw mem_erase, intro a,\n        exact Bh.1 a.2, \n      rw [card_erase_of_mem ih, Bh.2], refl,\n    rintro \u27e8_, _\u27e9,\n    rw mem_shadow', \n    suffices: \u2203 j, j \u2208 range'k \\ A,\n      rcases this with \u27e8j,jp\u27e9, rw mem_sdiff at jp,\n      use j, use jp.2, rw mem_powerset_len, split, \n        intros t th, rw mem_insert at th, cases th, \n          rw th, exact jp.1,\n        exact a_left th,\n      rw [card_insert_of_not_mem jp.2, a_right, nat.sub_add_cancel hr1],\n    apply exists_mem_of_ne_empty,\n    rw \u2190 card_pos,\n    rw card_sdiff a_left, rw card_attach_fin, apply nat.lt_sub_left_of_add_lt, \n    rw [card_range, a_right, add_zero], rw nat.sub_lt_right_iff_lt_add hr1, \n    apply nat.lt_succ_of_le hrk, \n  end\n\n  theorem iterated (r k : \u2115) (\ud835\udc9c \ud835\udc9e : finset (finset X)) : \n    is_layer \ud835\udc9c r \u2227 is_layer \ud835\udc9e r \u2227 \ud835\udc9e.card \u2264 \ud835\udc9c.card \u2227 UV.is_init_seg_of_colex \ud835\udc9e r \n  \u2192 (nat.iterate shadow k \ud835\udc9e).card \u2264 (nat.iterate shadow k \ud835\udc9c).card :=\n  begin\n    revert r \ud835\udc9c \ud835\udc9e, induction k,\n      intros, simp, exact a.2.2.1,\n    rintros r A C \u27e8z\u2081, z\u2082, z\u2083, z\u2084\u27e9, simp, apply k_ih (r-1), refine \u27e8shadow_layer z\u2081, shadow_layer z\u2082, _, _\u27e9,\n    apply strengthened r _ _ \u27e8z\u2081, z\u2082, z\u2083, z\u2084\u27e9, \n    apply UV.shadow_of_IS _ z\u2084\n  end\n\n  theorem lovasz_form_iterate {r k i : \u2115} {\ud835\udc9c : finset (finset X)} (hi1 : i \u2265 1) (hir : i < r) (hkn : k \u2264 n) (hrk : r \u2264 k) (h\u2081 : is_layer \ud835\udc9c r) (h\u2082 : \ud835\udc9c.card \u2265 nat.choose k r) : \n    (nat.iterate shadow i \ud835\udc9c).card \u2265 nat.choose k (r-i) :=\n  begin\n    set range'k : finset X := attach_fin (range k) (\u03bb m, by rw mem_range; apply forall_lt_iff_le.2 hkn),\n    set \ud835\udc9e : finset (finset X) := powerset_len r (range'k),\n    have Ccard: \ud835\udc9e.card = nat.choose k r,\n      rw [card_powerset_len, card_attach_fin, card_range], \n    have: is_layer \ud835\udc9e r, intros A HA, rw mem_powerset_len at HA, exact HA.2,\n    suffices this: (nat.iterate shadow i \ud835\udc9e).card = nat.choose k (r-i),\n    { rw \u2190 this, apply iterated r _ _ _ \u27e8h\u2081, \u2039is_layer \ud835\udc9e r\u203a, _, _\u27e9, \n      rwa Ccard, \n      refine \u27e8\u2039_\u203a, _\u27e9, rintros A HA B \u27e8HB\u2081, HB\u2082\u27e9, \n      rw mem_powerset_len, refine \u27e8_, \u2039_\u203a\u27e9, \n      intros t th, rw mem_attach_fin, rw mem_range, \n      by_contra, simp at a, \n      rw [UV.binary, inv_image] at HB\u2081,\n      apply not_le_of_gt HB\u2081, \n      transitivity 2^k,\n        apply le_of_lt, \n        apply UV.binary_sum',\n        intros x hx, rw mem_powerset_len at HA, exact mem_range.1 ((mem_attach_fin _).1 (HA.1 hx)), \n      have: (\u03bb (x : X), 2^x.val) t \u2264 _ := single_le_sum _ th, \n        transitivity, apply nat.pow_le_pow_of_le_right zero_lt_two a, rwa UV.bin_measure,\n      intros _ _, apply zero_le },\n    suffices: nat.iterate shadow i \ud835\udc9e = powerset_len (r-i) range'k, -- sub_iff_shadow_iter\n      rw [this, card_powerset_len, card_attach_fin, card_range], \n    ext B, rw mem_powerset_len, rw sub_iff_shadow_iter, \n    split, \n      rintro \u27e8A, Ah, BsubA, card_sdiff_i\u27e9,\n      rw mem_powerset_len at Ah, refine \u27e8trans BsubA Ah.1, _\u27e9, symmetry,\n      rw nat.sub_eq_iff_eq_add, \n      rw \u2190 Ah.2, rw \u2190 card_sdiff_i, rw \u2190 card_disjoint_union, rw union_sdiff_of_subset BsubA,  apply disjoint_sdiff,\n      apply le_of_lt hir,\n    rintro \u27e8_, _\u27e9,\n    rcases killing2_sets _ _ i _ a_left with \u27e8C, BsubC, Csubrange, cards\u27e9, \n    rw [a_right, \u2190 nat.add_sub_assoc (le_of_lt hir), nat.add_sub_cancel_left] at cards, \n    refine \u27e8C, _, BsubC, _\u27e9,\n    rw mem_powerset_len, exact \u27e8Csubrange, cards\u27e9, \n    rw card_sdiff BsubC, rw cards, rw a_right, rw nat.sub_sub_self (le_of_lt hir), \n    rw a_right, rw card_attach_fin, rw card_range, rw \u2190 nat.add_sub_assoc (le_of_lt hir), rwa nat.add_sub_cancel_left, \n  end\n\nend KK\n\ndef intersecting (\ud835\udc9c : finset (finset X)) : Prop := \u2200 A \u2208 \ud835\udc9c, \u2200 B \u2208 \ud835\udc9c, \u00ac disjoint A B\n\ntheorem intersecting_all (h : intersecting \ud835\udc9c) : \ud835\udc9c.card \u2264 2^(n-1) :=\nbegin\n  cases lt_or_le n 1 with b hn,\n    have: n = 0, apply nat.eq_zero_of_le_zero (nat.pred_le_pred b),\n    suffices: finset.card \ud835\udc9c = 0,\n      rw this, apply nat.zero_le,\n    rw [card_eq_zero, eq_empty_iff_forall_not_mem],\n    intros A HA, apply h A HA A HA, rw disjoint_self_iff_empty, \n    apply eq_empty_of_forall_not_mem, \n    intro x, rw this at x, exact (fin.elim0 \u2039_\u203a),\n  set f : finset X \u2192 finset (finset X) := \u03bb A, insert (univ \\ A) (finset.singleton A),\n  have disjs: \u2200 x \u2208 \ud835\udc9c, \u2200 y \u2208 \ud835\udc9c, x \u2260 y \u2192 disjoint (f x) (f y),\n    intros A hA B hB k,\n    simp [not_or_distrib, and_assoc], refine \u27e8_, _, _, _\u27e9,\n      { intro z, apply k, ext a, simp [ext] at z, replace z := z a, tauto },\n      intro a, rw \u2190 a at hA, apply h _ hB _ hA disjoint_sdiff, \n      intro a, rw \u2190 a at hB, apply h _ hB _ hA sdiff_disjoint, \n      exact k.symm, \n  have: \ud835\udc9c.bind f \u2286 powerset univ,\n    intros A hA, rw mem_powerset, apply subset_univ,\n  have q := card_le_of_subset this, rw [card_powerset, card_univ, card_fin] at q, \n  rw card_bind disjs at q, dsimp at q,\n  have: (\u03bb (u : finset X), card (f u)) =  (\u03bb _, 2),\n    funext, rw card_insert_of_not_mem, rw card_singleton, rw mem_singleton, \n    intro, simp [ext] at a, apply a, exact \u27e80, hn\u27e9,\n  rw this at q, rw sum_const at q, rw nat.smul_eq_mul at q, \n  rw \u2190 nat.le_div_iff_mul_le' zero_lt_two at q, \n  conv_rhs at q {rw \u2190 nat.sub_add_cancel hn},\n  rw nat.pow_add at q, simp at q, assumption,\nend\n\n@[reducible]\ndef extremal_intersecting (hn : n \u2265 1) : finset (finset X) :=\n(powerset univ).filter (\u03bb A, (\u27e80, hn\u27e9: X) \u2208 A)\n\nlemma thing {hn : n \u2265 1} : intersecting (extremal_intersecting hn) :=\nby intros A HA B HB k; rw [mem_filter] at HA HB; exact disjoint_left.1 k HA.2 HB.2\n\n#print thing\n", "meta": {"author": "b-mehta", "repo": "lean-experiments", "sha": "5f0aed189f724ae6f739ec75dcdddcd2687614e1", "save_path": "github-repos/lean/b-mehta-lean-experiments", "path": "github-repos/lean/b-mehta-lean-experiments/lean-experiments-5f0aed189f724ae6f739ec75dcdddcd2687614e1/src/kruskal_katona_rewrite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7074331233251838}}
{"text": "import tactic.ring\nimport data.nat.prime\n\nopen nat\n\nlemma Auxiliar\n  (n k : \u2115)\n  (h1 : k \u2223 21 * n + 4)\n  (h2 : k \u2223 14 * n + 3)\n  : k \u2223 1 :=\nbegin\n  have h3 : k \u2223 2 * (21 * n + 4),\n    from dvd_mul_of_dvd_right h1 2,\n  have h4 : k \u2223 3 * (14 * n + 3),\n    from dvd_mul_of_dvd_right h2 3,\n  have h5 : 3 * (14 * n + 3) = 2 * (21 * n + 4) + 1,\n    { ring, },\n  rw h5 at h4,\n  rw \u2190 nat.dvd_add_right h3,\n  exact h4,\nend\n\ntheorem imo1959_q1 :\n  \u2200 n : \u2115, coprime (21 * n + 4) (14 * n + 3) :=\nbegin\n  intro n,\n  apply coprime_of_dvd',\n  intros k hk h1 h2,\n  exact Auxiliar n k h1 h2,\nend\n", "meta": {"author": "saradiazr11", "repo": "IMO_en_Lean", "sha": "d8fb219af4d0c1afaecb36556ac5ecf8dd03b453", "save_path": "github-repos/lean/saradiazr11-IMO_en_Lean", "path": "github-repos/lean/saradiazr11-IMO_en_Lean/IMO_en_Lean-d8fb219af4d0c1afaecb36556ac5ecf8dd03b453/src/IMO/imo1959_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144275, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.7073943077248652}}
{"text": "import .lovelib\n\n\n/-! # LoVe Homework 11: Logical Foundations of Mathematics\n\nHomework must be done individually. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (9 points): Multisets as a Quotient Type\n\nA multiset (or bag) is a collection of elements that allows for multiple\n(but finitely many) occurrences of its elements. For example, the multiset\n`{2, 7}` is equal to the multiset `{7, 2}` but different from `{2, 7, 7}`.\n\nFinite multisets can be defined as a quotient over lists. We start with the\ntype `list \u03b1` of finite lists and consider only the number of occurrences of\nelements in the lists, ignoring the order in which elements occur. Following\nthis scheme, `[2, 7, 7]`, `[7, 2, 7]`, and `[7, 7, 2]` would be three equally\nvalid representations of the multiset `{2, 7, 7}`.\n\nThe `list.count` function returns the number of occurrences of an element in a\nlist. Since it uses equality on elements of type `\u03b1`, it requires `\u03b1` to belong\nto the `decidable_eq` type class. For this reason, the definitions and lemmas\nbelow all take `[decidable_eq \u03b1]` as type class argument.\n\n1.1 (1 point). Provide the missing proof below. -/\n\n@[instance] def multiset.rel (\u03b1 : Type) [decidable_eq \u03b1] : setoid (list \u03b1) :=\n{ r     := \u03bbas bs, \u2200x, list.count x as = list.count x bs,\n  iseqv :=\n    sorry }\n\n/-! 1.2 (1 point). Define the type of multisets as the quotient over the\nrelation `multiset.rel`. -/\n\ndef multiset (\u03b1 : Type) [decidable_eq \u03b1] : Type :=\nsorry\n\n/-! 1.3 (3 points). Now we have a type `multiset \u03b1` but no operations on it.\nBasic operations on multisets include the empty multiset (`\u2205`), the singleton\nmultiset (`{x} `for any element `x`), and the sum of two multisets (`A \u228e B` for\nany multisets `A` and `B`). The sum should be defined so that the multiplicities\nof elements are added; thus, `{2} \u228e {2, 2} = {2, 2, 2}`.\n\nFill in the `sorry` placeholders below to implement the basic multiset\noperations. -/\n\ndef multiset.empty {\u03b1 : Type} [decidable_eq \u03b1] : multiset \u03b1 :=\nsorry\n\ndef multiset.singleton {\u03b1 : Type} [decidable_eq \u03b1] (a : \u03b1) : multiset \u03b1 :=\nsorry\n\ndef multiset.union {\u03b1 : Type} [decidable_eq \u03b1] :\n  multiset \u03b1 \u2192 multiset \u03b1 \u2192 multiset \u03b1 :=\nquotient.lift\u2082\n  sorry\n  sorry\n\n/-! 1.4 (4 points). Prove that `multiset.union` is commutative and associative,\nand has `multiset.empty` as identity element. -/\n\nlemma multiset.union_comm {\u03b1 : Type} [decidable_eq \u03b1] (A B : multiset \u03b1) :\n  multiset.union A B = multiset.union B A :=\nsorry\n\nlemma multiset.union_assoc {\u03b1 : Type} [decidable_eq \u03b1] (A B C : multiset \u03b1) :\n  multiset.union (multiset.union A B) C =\n  multiset.union A (multiset.union B C) :=\nsorry\n\nlemma multiset.union_iden_left {\u03b1 : Type} [decidable_eq \u03b1] (A : multiset \u03b1) :\n  multiset.union multiset.empty A = A :=\nsorry\n\nlemma multiset.union_iden_right {\u03b1 : Type} [decidable_eq \u03b1] (A : multiset \u03b1) :\n  multiset.union A multiset.empty = A :=\nsorry\n\n\n/-! ## Question 2 (2 bonus points): Nonempty Types\n\nIn the lecture, we saw the inductive predicate `nonempty` that states that a\ntype has at least one element: -/\n\n#print nonempty\n\n/-! The purpose of this question is to think about what would happen if all\ntypes had at least one element. To investigate this, we introduce this fact as\nan axiom as follows. Introducing axioms should be generally avoided or done\nwith great care, since they can easily lead to contradictions, as we will\nsee. -/\n\naxiom Sort_nonempty (\u03b1 : Sort _) :\n  nonempty \u03b1\n\n/-! This axiom gives us a lemma `Sort_nonempty` admitted with no proof. It\nresembles a lemma proved by `sorry`, just without the warning. -/\n\n#check Sort_nonempty\n\n/-! 2.1 (1 bonus point). Prove that this axiom leads to a contradiction, i.e.,\nlets us derive `false`. -/\n\nlemma proof_of_false :\n  false :=\nsorry\n\n/-! 2.2 (1 bonus point). Prove that even the following weaker axiom leads to a\ncontradiction. Of course, you may not use the axiom or the lemma from 3.1.\n\nHint: Subtypes can help. -/\n\naxiom Type_nonempty (\u03b1 : Type _) :\n  nonempty \u03b1\n\nlemma proof_of_false\u2082 :\n  false :=\nsorry\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2022", "sha": "5aee593fbef9b63d4338288b4789d85851d258aa", "save_path": "github-repos/lean/blanchette-logical_verification_2022", "path": "github-repos/lean/blanchette-logical_verification_2022/logical_verification_2022-5aee593fbef9b63d4338288b4789d85851d258aa/lean/love11_logical_foundations_of_mathematics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7073851271075875}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam, Yury Kudryashov\n\n! This file was ported from Lean 3 source module data.mv_polynomial.pderiv\n! leanprover-community/mathlib commit 67dcdef25397eedde255db0876b9c55eab2a62a2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.MvPolynomial.Variables\nimport Mathbin.Data.MvPolynomial.Derivation\n\n/-!\n# Partial derivatives of polynomials\n\nThis file defines the notion of the formal *partial derivative* of a polynomial,\nthe derivative with respect to a single variable.\nThis derivative is not connected to the notion of derivative from analysis.\nIt is based purely on the polynomial exponents and coefficients.\n\n## Main declarations\n\n* `mv_polynomial.pderiv i p` : the partial derivative of `p` with respect to `i`, as a bundled\n  derivation of `mv_polynomial \u03c3 R`.\n\n## Notation\n\nAs in other polynomial files, we typically use the notation:\n\n+ `\u03c3 : Type*` (indexing the variables)\n\n+ `R : Type*` `[comm_ring R]` (the coefficients)\n\n+ `s : \u03c3 \u2192\u2080 \u2115`, a function from `\u03c3` to `\u2115` which is zero away from a finite set.\nThis will give rise to a monomial in `mv_polynomial \u03c3 R` which mathematicians might call `X^s`\n\n+ `a : R`\n\n+ `i : \u03c3`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians\n\n+ `p : mv_polynomial \u03c3 R`\n\n-/\n\n\nnoncomputable section\n\nuniverse u v\n\nnamespace MvPolynomial\n\nopen Set Function Finsupp AddMonoidAlgebra\n\nopen Classical BigOperators\n\nvariable {R : Type u} {\u03c3 : Type v} {a a' a\u2081 a\u2082 : R} {s : \u03c3 \u2192\u2080 \u2115}\n\nsection Pderiv\n\nvariable {R} [CommSemiring R]\n\n/-- `pderiv i p` is the partial derivative of `p` with respect to `i` -/\ndef pderiv (i : \u03c3) : Derivation R (MvPolynomial \u03c3 R) (MvPolynomial \u03c3 R) :=\n  mkDerivation R <| Pi.single i 1\n#align mv_polynomial.pderiv MvPolynomial.pderiv\n\n@[simp]\ntheorem pderiv_monomial {i : \u03c3} : pderiv i (monomial s a) = monomial (s - single i 1) (a * s i) :=\n  by\n  simp only [pderiv, mk_derivation_monomial, Finsupp.smul_sum, smul_eq_mul, \u2190 smul_mul_assoc, \u2190\n    (monomial _).map_smul]\n  refine' (Finset.sum_eq_single i (fun j hj hne => _) fun hi => _).trans _\n  \u00b7 simp [Pi.single_eq_of_ne hne]\n  \u00b7 rw [Finsupp.not_mem_support_iff] at hi\n    simp [hi]\n  \u00b7 simp\n#align mv_polynomial.pderiv_monomial MvPolynomial.pderiv_monomial\n\ntheorem pderiv_c {i : \u03c3} : pderiv i (C a) = 0 :=\n  derivation_c _ _\n#align mv_polynomial.pderiv_C MvPolynomial.pderiv_c\n\ntheorem pderiv_one {i : \u03c3} : pderiv i (1 : MvPolynomial \u03c3 R) = 0 :=\n  pderiv_c\n#align mv_polynomial.pderiv_one MvPolynomial.pderiv_one\n\n@[simp]\ntheorem pderiv_x [d : DecidableEq \u03c3] (i j : \u03c3) :\n    pderiv i (X j : MvPolynomial \u03c3 R) = @Pi.single \u03c3 _ d _ i 1 j :=\n  (mkDerivation_x _ _ _).trans (by congr )\n#align mv_polynomial.pderiv_X MvPolynomial.pderiv_x\n\n@[simp]\ntheorem pderiv_x_self (i : \u03c3) : pderiv i (X i : MvPolynomial \u03c3 R) = 1 := by simp\n#align mv_polynomial.pderiv_X_self MvPolynomial.pderiv_x_self\n\n@[simp]\ntheorem pderiv_x_of_ne {i j : \u03c3} (h : j \u2260 i) : pderiv i (X j : MvPolynomial \u03c3 R) = 0 := by simp [h]\n#align mv_polynomial.pderiv_X_of_ne MvPolynomial.pderiv_x_of_ne\n\ntheorem pderiv_eq_zero_of_not_mem_vars {i : \u03c3} {f : MvPolynomial \u03c3 R} (h : i \u2209 f.vars) :\n    pderiv i f = 0 :=\n  derivation_eq_zero_of_forall_mem_vars fun j hj => pderiv_x_of_ne <| ne_of_mem_of_not_mem hj h\n#align mv_polynomial.pderiv_eq_zero_of_not_mem_vars MvPolynomial.pderiv_eq_zero_of_not_mem_vars\n\ntheorem pderiv_monomial_single {i : \u03c3} {n : \u2115} :\n    pderiv i (monomial (single i n) a) = monomial (single i (n - 1)) (a * n) := by simp\n#align mv_polynomial.pderiv_monomial_single MvPolynomial.pderiv_monomial_single\n\ntheorem pderiv_mul {i : \u03c3} {f g : MvPolynomial \u03c3 R} :\n    pderiv i (f * g) = pderiv i f * g + f * pderiv i g := by\n  simp only [(pderiv i).leibniz f g, smul_eq_mul, mul_comm, add_comm]\n#align mv_polynomial.pderiv_mul MvPolynomial.pderiv_mul\n\n@[simp]\ntheorem pderiv_c_mul {f : MvPolynomial \u03c3 R} {i : \u03c3} : pderiv i (C a * f) = C a * pderiv i f :=\n  (derivation_c_mul _ _ _).trans C_mul'.symm\n#align mv_polynomial.pderiv_C_mul MvPolynomial.pderiv_c_mul\n\nend Pderiv\n\nend MvPolynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/MvPolynomial/Pderiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7073582039982454}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Yury Kudryashov\n-/\nimport analysis.normed_space.basic\nimport analysis.normed.group.add_torsor\nimport linear_algebra.affine_space.midpoint\nimport topology.instances.real_vector_space\n\n/-!\n# Torsors of normed space actions.\n\nThis file contains lemmas about normed additive torsors over normed spaces.\n-/\n\nnoncomputable theory\nopen_locale nnreal topological_space\nopen filter\n\nvariables {\u03b1 V P : Type*} [semi_normed_group V] [pseudo_metric_space P] [normed_add_torsor V P]\nvariables {W Q : Type*} [normed_group W] [metric_space Q] [normed_add_torsor W Q]\n\ninclude V\n\nsection normed_space\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [normed_space \ud835\udd5c V]\n\nopen affine_map\n\n@[simp] lemma dist_center_homothety (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist p\u2081 (homothety p\u2081 c p\u2082) = \u2225c\u2225 * dist p\u2081 p\u2082 :=\nby simp [homothety_def, norm_smul, \u2190 dist_eq_norm_vsub, dist_comm]\n\n@[simp] lemma dist_homothety_center (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist (homothety p\u2081 c p\u2082) p\u2081 = \u2225c\u2225 * dist p\u2081 p\u2082 :=\nby rw [dist_comm, dist_center_homothety]\n\n@[simp] lemma dist_line_map_line_map (p\u2081 p\u2082 : P) (c\u2081 c\u2082 : \ud835\udd5c) :\n  dist (line_map p\u2081 p\u2082 c\u2081) (line_map p\u2081 p\u2082 c\u2082) = dist c\u2081 c\u2082 * dist p\u2081 p\u2082 :=\nbegin\n  rw dist_comm p\u2081 p\u2082,\n  simp only [line_map_apply, dist_eq_norm_vsub, vadd_vsub_vadd_cancel_right, \u2190 sub_smul, norm_smul,\n    vsub_eq_sub],\nend\n\nlemma lipschitz_with_line_map (p\u2081 p\u2082 : P) :\n  lipschitz_with (nndist p\u2081 p\u2082) (line_map p\u2081 p\u2082 : \ud835\udd5c \u2192 P) :=\nlipschitz_with.of_dist_le_mul $ \u03bb c\u2081 c\u2082,\n  ((dist_line_map_line_map p\u2081 p\u2082 c\u2081 c\u2082).trans (mul_comm _ _)).le\n\n@[simp] lemma dist_line_map_left (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist (line_map p\u2081 p\u2082 c) p\u2081 = \u2225c\u2225 * dist p\u2081 p\u2082 :=\nby simpa only [line_map_apply_zero, dist_zero_right] using dist_line_map_line_map p\u2081 p\u2082 c 0\n\n@[simp] lemma dist_left_line_map (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist p\u2081 (line_map p\u2081 p\u2082 c) = \u2225c\u2225 * dist p\u2081 p\u2082 :=\n(dist_comm _ _).trans (dist_line_map_left _ _ _)\n\n@[simp] lemma dist_line_map_right (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist (line_map p\u2081 p\u2082 c) p\u2082 = \u22251 - c\u2225 * dist p\u2081 p\u2082 :=\nby simpa only [line_map_apply_one, dist_eq_norm'] using dist_line_map_line_map p\u2081 p\u2082 c 1\n\n@[simp] lemma dist_right_line_map (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist p\u2082 (line_map p\u2081 p\u2082 c) = \u22251 - c\u2225 * dist p\u2081 p\u2082 :=\n(dist_comm _ _).trans (dist_line_map_right _ _ _)\n\n@[simp] lemma dist_homothety_self (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist (homothety p\u2081 c p\u2082) p\u2082 = \u22251 - c\u2225 * dist p\u2081 p\u2082 :=\nby rw [homothety_eq_line_map, dist_line_map_right]\n\n@[simp] lemma dist_self_homothety (p\u2081 p\u2082 : P) (c : \ud835\udd5c) :\n  dist p\u2082 (homothety p\u2081 c p\u2082) = \u22251 - c\u2225 * dist p\u2081 p\u2082 :=\nby rw [dist_comm, dist_homothety_self]\n\nvariables [invertible (2:\ud835\udd5c)]\n\n@[simp] lemma dist_left_midpoint (p\u2081 p\u2082 : P) :\n  dist p\u2081 (midpoint \ud835\udd5c p\u2081 p\u2082) = \u2225(2:\ud835\udd5c)\u2225\u207b\u00b9 * dist p\u2081 p\u2082 :=\nby rw [midpoint, dist_comm, dist_line_map_left, inv_of_eq_inv, \u2190 norm_inv]\n\n@[simp] lemma dist_midpoint_left (p\u2081 p\u2082 : P) :\n  dist (midpoint \ud835\udd5c p\u2081 p\u2082) p\u2081 = \u2225(2:\ud835\udd5c)\u2225\u207b\u00b9 * dist p\u2081 p\u2082 :=\nby rw [dist_comm, dist_left_midpoint]\n\n@[simp] lemma dist_midpoint_right (p\u2081 p\u2082 : P) :\n  dist (midpoint \ud835\udd5c p\u2081 p\u2082) p\u2082 = \u2225(2:\ud835\udd5c)\u2225\u207b\u00b9 * dist p\u2081 p\u2082 :=\nby rw [midpoint_comm, dist_midpoint_left, dist_comm]\n\n@[simp] lemma dist_right_midpoint (p\u2081 p\u2082 : P) :\n  dist p\u2082 (midpoint \ud835\udd5c p\u2081 p\u2082) = \u2225(2:\ud835\udd5c)\u2225\u207b\u00b9 * dist p\u2081 p\u2082 :=\nby rw [dist_comm, dist_midpoint_right]\n\nlemma dist_midpoint_midpoint_le' (p\u2081 p\u2082 p\u2083 p\u2084 : P) :\n  dist (midpoint \ud835\udd5c p\u2081 p\u2082) (midpoint \ud835\udd5c p\u2083 p\u2084) \u2264 (dist p\u2081 p\u2083 + dist p\u2082 p\u2084) / \u2225(2 : \ud835\udd5c)\u2225 :=\nbegin\n  rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, midpoint_vsub_midpoint];\n    try { apply_instance },\n  rw [midpoint_eq_smul_add, norm_smul, inv_of_eq_inv, norm_inv, \u2190 div_eq_inv_mul],\n  exact div_le_div_of_le_of_nonneg (norm_add_le _ _) (norm_nonneg _),\nend\n\nend normed_space\n\nvariables [normed_space \u211d V] [normed_space \u211d W]\n\nlemma dist_midpoint_midpoint_le (p\u2081 p\u2082 p\u2083 p\u2084 : V) :\n  dist (midpoint \u211d p\u2081 p\u2082) (midpoint \u211d p\u2083 p\u2084) \u2264 (dist p\u2081 p\u2083 + dist p\u2082 p\u2084) / 2 :=\nby simpa using dist_midpoint_midpoint_le' p\u2081 p\u2082 p\u2083 p\u2084\n\ninclude W\n\n/-- A continuous map between two normed affine spaces is an affine map provided that\nit sends midpoints to midpoints. -/\ndef affine_map.of_map_midpoint (f : P \u2192 Q)\n  (h : \u2200 x y, f (midpoint \u211d x y) = midpoint \u211d (f x) (f y))\n  (hfc : continuous f) :\n  P \u2192\u1d43[\u211d] Q :=\naffine_map.mk' f\n  \u2191((add_monoid_hom.of_map_midpoint \u211d \u211d\n    ((affine_equiv.vadd_const \u211d (f $ classical.arbitrary P)).symm \u2218 f \u2218\n      (affine_equiv.vadd_const \u211d (classical.arbitrary P))) (by simp)\n      (\u03bb x y, by simp [h])).to_real_linear_map $ by apply_rules [continuous.vadd, continuous.vsub,\n        continuous_const, hfc.comp, continuous_id])\n  (classical.arbitrary P)\n  (\u03bb p, by simp)\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/normed_space/add_torsor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7073581995824325}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\nPrime numbers.\n-/\nimport data.nat.sqrt data.nat.gcd data.list.basic data.list.perm\nopen bool subtype\n\nnamespace nat\nopen decidable\n\n/-- `prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\ndef prime (p : \u2115) := p \u2265 2 \u2227 \u2200 m \u2223 p, m = 1 \u2228 m = p\n\ntheorem prime.ge_two {p : \u2115} : prime p \u2192 p \u2265 2 := and.left\n\ntheorem prime.gt_one {p : \u2115} : prime p \u2192 p > 1 := prime.ge_two\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 p \u2265 2 \u2227 \u2200 m < p, m \u2223 p \u2192 m = 1 :=\nand_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h l d, (h d).resolve_right (ne_of_lt l),\n \u03bb h d, (lt_or_eq_of_le $\n   le_of_dvd (le_of_succ_le p2) d).imp_left (\u03bb l, h l d)\u27e9\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 p \u2265 2 \u2227 \u2200 m, 2 \u2264 m \u2192 m < p \u2192 \u00ac m \u2223 p :=\nprime_def_lt.trans $ and_congr_right $ \u03bb p2, forall_congr $ \u03bb m,\n\u27e8\u03bb h m2 l d, not_lt_of_ge m2 ((h l d).symm \u25b8 dec_trivial),\n\u03bb h l d, begin\n  rcases m with _|_|m,\n  { rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },\n  { refl },\n  { exact (h dec_trivial l).elim d }\nend\u27e9\n\ntheorem prime_def_le_sqrt {p : \u2115} : prime p \u2194 p \u2265 2 \u2227\n  \u2200 m, 2 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00ac m \u2223 p :=\nprime_def_lt'.trans $ and_congr_right $ \u03bb p2,\n\u27e8\u03bb a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,\n \u03bb a, have \u2200 {m k}, m \u2264 k \u2192 1 < m \u2192 p \u2260 m * k, from\n  \u03bb m k mk m1 e, a m m1\n    (le_sqrt.2 (e.symm \u25b8 mul_le_mul_left m mk)) \u27e8k, e\u27e9,\n  \u03bb m m2 l \u27e8k, e\u27e9, begin\n    cases (le_total m k) with mk km,\n    { exact this mk m2 e },\n    { rw [mul_comm] at e,\n      refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,\n      rwa [one_mul, \u2190 e] }\n  end\u27e9\n\ndef decidable_prime_1 (p : \u2115) : decidable (prime p) :=\ndecidable_of_iff' _ prime_def_lt'\nlocal attribute [instance] decidable_prime_1\n\nlemma prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 :=\nassume hn : n = 0,\nhave h2 : \u00ac prime 0, from dec_trivial,\nh2 (hn \u25b8 h)\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : p > 0 :=\nlt_of_succ_lt pp.gt_one\n\ntheorem not_prime_zero : \u00ac prime 0 := dec_trivial\n\ntheorem not_prime_one : \u00ac prime 1 := dec_trivial\n\ntheorem prime_two : prime 2 := dec_trivial\n\ntheorem prime_three : prime 3 := dec_trivial\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : pred p > 0 :=\nlt_pred_of_succ_lt pp.gt_one\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : succ (pred p) = p :=\nsucc_pred_eq_of_pos pp.pos\n\ntheorem dvd_prime {p m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p :=\n\u27e8\u03bb d, pp.2 m d, \u03bb h, h.elim (\u03bb e, e.symm \u25b8 one_dvd _) (\u03bb e, e.symm \u25b8 dvd_refl _)\u27e9\n\ntheorem dvd_prime_ge_two {p m : \u2115} (pp : prime p) (H : m \u2265 2) : m \u2223 p \u2194 m = p :=\n(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00ac p \u2223 1\n| d := (not_le_of_gt pp.gt_one) $ le_of_dvd dec_trivial d\n\ntheorem not_prime_mul {a b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00ac prime (a * b) :=\n\u03bb h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $\nby simpa using (dvd_prime_ge_two h a1).1 (dvd_mul_right _ _)\n\nsection min_fac\n  private lemma min_fac_lemma (n k : \u2115) (h : \u00ac k * k > n) :\n    sqrt n - k < sqrt n + 2 - k :=\n  (nat.sub_lt_sub_right_iff $ le_sqrt.2 $ le_of_not_gt h).2 $\n  nat.lt_add_of_pos_right dec_trivial\n\n  def min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115 | k :=\n  if h : n < k * k then n else\n  if k \u2223 n then k else\n  have _, from min_fac_lemma n k h,\n  min_fac_aux (k + 2)\n  using_well_founded {rel_tac :=\n    \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n  /-- Returns the smallest prime factor of `n \u2260 1`. -/\n  def min_fac : \u2115 \u2192 \u2115\n  | 0 := 2\n  | 1 := 1\n  | (n+2) := if 2 \u2223 n then 2 else min_fac_aux (n + 2) 3\n\n  @[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl\n  @[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\n  theorem min_fac_eq : \u2200 n, min_fac n = if 2 \u2223 n then 2 else min_fac_aux n 3\n  | 0     := rfl\n  | 1     := by simp [show 2\u22601, from dec_trivial]; rw min_fac_aux; refl\n  | (n+2) :=\n    have 2 \u2223 n + 2 \u2194 2 \u2223 n, from\n      (nat.dvd_add_iff_left (by refl)).symm,\n    by simp [min_fac, this]; congr\n\n  private def min_fac_prop (n k : \u2115) :=\n    k \u2265 2 \u2227 k \u2223 n \u2227 \u2200 m \u2265 2, m \u2223 n \u2192 k \u2264 m\n\n  theorem min_fac_aux_has_prop {n : \u2115} (n2 : n \u2265 2) (nd2 : \u00ac 2 \u2223 n) :\n    \u2200 k i, k = 2*i+3 \u2192 (\u2200 m \u2265 2, m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k)\n  | k := \u03bb i e a, begin\n    rw min_fac_aux,\n    by_cases h : n < k*k; simp [h],\n    { have pp : prime n :=\n        prime_def_le_sqrt.2 \u27e8n2, \u03bb m m2 l d,\n          not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)\u27e9,\n      from \u27e8n2, dvd_refl _, \u03bb m m2 d, le_of_eq\n        ((dvd_prime_ge_two pp m2).1 d).symm\u27e9 },\n    have k2 : 2 \u2264 k, { subst e, exact dec_trivial },\n    by_cases dk : k \u2223 n; simp [dk],\n    { exact \u27e8k2, dk, a\u27e9 },\n    { refine have _, from min_fac_lemma n k h,\n        min_fac_aux_has_prop (k+2) (i+1)\n          (by simp [e, left_distrib]) (\u03bb m m2 d, _),\n      cases nat.eq_or_lt_of_le (a m m2 d) with me ml,\n      { subst me, contradiction },\n      apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,\n      rw [\u2190 me, e] at d, change 2 * (i + 2) \u2223 n at d,\n      have := dvd_of_mul_right_dvd d, contradiction }\n  end\n  using_well_founded {rel_tac :=\n    \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb k, sqrt n + 2 - k)\u27e9]}\n\n  theorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) :\n    min_fac_prop n (min_fac n) :=\n  begin\n    by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},\n    have n2 : 2 \u2264 n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },\n    simp [min_fac_eq],\n    by_cases d2 : 2 \u2223 n; simp [d2],\n    { exact \u27e8le_refl _, d2, \u03bb k k2 d, k2\u27e9 },\n    { refine min_fac_aux_has_prop n2 d2 3 0 rfl\n        (\u03bb m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),\n      exact \u03bb e, e.symm \u25b8 d }\n  end\n\n  theorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\n  by by_cases n1 : n = 1;\n     [exact n1.symm \u25b8 dec_trivial, exact (min_fac_has_prop n1).2.1]\n\n  theorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) :=\n  let \u27e8f2, fd, a\u27e9 := min_fac_has_prop n1 in\n  prime_def_lt'.2 \u27e8f2, \u03bb m m2 l d, not_le_of_gt l (a m m2 (dvd_trans d fd))\u27e9\n\n  theorem min_fac_le_of_dvd {n : \u2115} : \u2200 {m : \u2115}, m \u2265 2 \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\n  by by_cases n1 : n = 1;\n    [exact \u03bb m m2 d, n1.symm \u25b8 le_trans dec_trivial m2,\n     exact (min_fac_has_prop n1).2.2]\n\n  theorem min_fac_pos (n : \u2115) : min_fac n > 0 :=\n  by by_cases n1 : n = 1;\n     [exact n1.symm \u25b8 dec_trivial, exact (min_fac_prime n1).pos]\n\n  theorem min_fac_le {n : \u2115} (H : n > 0) : min_fac n \u2264 n :=\n  le_of_dvd H (min_fac_dvd n)\n\n  theorem prime_def_min_fac {p : \u2115} : prime p \u2194 p \u2265 2 \u2227 min_fac p = p :=\n  \u27e8\u03bb pp, \u27e8pp.ge_two,\n    let \u27e8f2, fd, a\u27e9 := min_fac_has_prop $ ne_of_gt pp.gt_one in\n    ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)\u27e9,\n   \u03bb \u27e8p2, e\u27e9, e \u25b8 min_fac_prime (ne_of_gt p2)\u27e9\n\n  instance decidable_prime (p : \u2115) : decidable (prime p) :=\n  decidable_of_iff' _ prime_def_min_fac\n\n  theorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : n \u2265 2) : \u00ac prime n \u2194 min_fac n < n :=\n  (not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $\n    (lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm\n\nend min_fac\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : n \u2265 2) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n\u27e8min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).gt_one,\n  ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : n \u2265 2) (np : \u00ac prime n) :\n  \u2203 m, m \u2223 n \u2227 m \u2265 2 \u2227 m < n :=\n\u27e8min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).ge_two,\n  (not_prime_iff_min_fac_lt n2).1 np\u27e9\n\ntheorem exists_prime_and_dvd {n : \u2115} (n2 : n \u2265 2) : \u2203 p, prime p \u2227 p \u2223 n :=\n\u27e8min_fac n, min_fac_prime (ne_of_gt n2), min_fac_dvd _\u27e9\n\ntheorem exists_infinite_primes (n : \u2115) : \u2203 p, p \u2265 n \u2227 prime p :=\nlet p := min_fac (fact n + 1) in\nhave f1 : fact n + 1 \u2260 1, from ne_of_gt $ succ_lt_succ $ fact_pos _,\nhave pp : prime p, from min_fac_prime f1,\nhave np : n \u2264 p, from le_of_not_ge $ \u03bb h,\n  have h\u2081 : p \u2223 fact n, from dvd_fact (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  pp.not_dvd_one h\u2082,\n\u27e8p, np, pp\u27e9\n\ntheorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=\ndiv_lt_self dec_trivial (min_fac_prime dec_trivial).gt_one\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 list \u2115\n| 0 := []\n| 1 := []\n| n@(k+2) :=\n  let m := min_fac n in have n / m < n := factors_lemma,\n  m :: factors (n / m)\n\nlemma mem_factors : \u2200 {n p}, p \u2208 factors n \u2192 prime p\n| 0       := \u03bb p, false.elim\n| 1       := \u03bb p, false.elim\n| n@(k+2) := \u03bb p h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  have h\u2081 : p = m \u2228 p \u2208 (factors (n / m)) :=\n    (list.mem_cons_iff _ _ _).1 h,\n  or.cases_on h\u2081 (\u03bb h\u2082, h\u2082.symm \u25b8 min_fac_prime dec_trivial)\n    mem_factors\n\nlemma prod_factors : \u2200 {n}, 0 < n \u2192 list.prod (factors n) = n\n| 0       := (lt_irrefl _).elim\n| 1       := \u03bb h, rfl\n| n@(k+2) := \u03bb h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  show list.prod (m :: factors (n / m)) = n, from\n  have h\u2081 : 0 < n / m :=\n    nat.pos_of_ne_zero $ \u03bb h,\n    have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,\n    by rw zero_mul at this; exact (show k + 2 \u2260 0, from dec_trivial) this,\n  by rw [list.prod_cons, prod_factors h\u2081, nat.mul_div_cancel' (min_fac_dvd _)]\n\ntheorem prime.coprime_iff_not_dvd {p n : \u2115} (pp : prime p) : coprime p n \u2194 \u00ac p \u2223 n :=\n\u27e8\u03bb co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),\n \u03bb nd, coprime_of_dvd $ \u03bb m m2 mp, ((dvd_prime_ge_two pp m2).1 mp).symm \u25b8 nd\u27e9\n\ntheorem prime.dvd_iff_not_coprime {p n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00ac coprime p n :=\niff_not_comm.2 pp.coprime_iff_not_dvd\n\ntheorem prime.dvd_mul {p m n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n :=\n\u27e8\u03bb H, or_iff_not_imp_left.2 $ \u03bb h,\n  (pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,\n or.rec (\u03bb h, dvd_mul_of_dvd_left h _) (\u03bb h, dvd_mul_of_dvd_right h _)\u27e9\n\ntheorem prime.not_dvd_mul {p m n : \u2115} (pp : prime p)\n  (Hm : \u00ac p \u2223 m) (Hn : \u00ac p \u2223 n) : \u00ac p \u2223 m * n :=\nmt pp.dvd_mul.1 $ by simp [Hm, Hn]\n\ntheorem prime.dvd_of_dvd_pow {p m n : \u2115} (pp : prime p) (h : p \u2223 m^n) : p \u2223 m :=\nby induction n with n IH;\n   [exact pp.not_dvd_one.elim h,\n    exact (pp.dvd_mul.1 h).elim IH id]\n\ntheorem prime.coprime_pow_of_not_dvd {p m a : \u2115} (pp : prime p) (h : \u00ac p \u2223 a) : coprime a (p^m) :=\n(pp.coprime_iff_not_dvd.2 h).symm.pow_right _\n\ntheorem coprime_primes {p q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\npp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_ge_two pq pp.ge_two\n\ntheorem coprime_pow_primes {p q : \u2115} (n m : \u2115) (pp : prime p) (pq : prime q) (h : p \u2260 q) :\n  coprime (p^n) (q^m) :=\n((coprime_primes pp pq).2 h).pow _ _\n\ntheorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\nby rw [pp.dvd_iff_not_coprime]; apply em\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m i : \u2115} : i \u2223 (p^m) \u2194 \u2203 k \u2264 m, i = p^k :=\nbegin\n  induction m with m IH generalizing i, {simp [pow_succ, le_zero_iff] at *},\n  by_cases p \u2223 i,\n  { cases h with a e, subst e,\n    rw [pow_succ, mul_comm (p^m) p, nat.mul_dvd_mul_iff_left pp.pos, IH],\n    split; intro h; rcases h with \u27e8k, h, e\u27e9,\n    { exact \u27e8succ k, succ_le_succ h, by rw [mul_comm, e]; refl\u27e9 },\n    cases k with k,\n    { apply pp.not_dvd_one.elim,\n      simp at e, rw \u2190 e, apply dvd_mul_right },\n    { refine \u27e8k, le_of_succ_le_succ h, _\u27e9,\n      rwa [mul_comm, pow_succ, nat.mul_right_inj pp.pos] at e } },\n  { split; intro d,\n    { rw (pp.coprime_pow_of_not_dvd h).eq_one_of_dvd d,\n      exact \u27e80, zero_le _, rfl\u27e9 },\n    { rcases d with \u27e8k, l, e\u27e9,\n      rw e, exact pow_dvd_pow _ l } }\nend\n\nsection\nopen list\n\nlemma mem_list_primes_of_dvd_prod {p : \u2115} (hp : prime p) :\n  \u2200 {l : list \u2115}, (\u2200 p \u2208 l, prime p) \u2192 p \u2223 prod l \u2192 p \u2208 l\n| []       := \u03bb h\u2081 h\u2082, absurd h\u2082 (prime.not_dvd_one hp)\n| (q :: l) := \u03bb h\u2081 h\u2082,\n  have h\u2083 : p \u2223 q * prod l := @prod_cons _ _ l q \u25b8 h\u2082,\n  have hq : prime q := h\u2081 q (mem_cons_self _ _),\n  or.cases_on ((prime.dvd_mul hp).1 h\u2083)\n    (\u03bb h, by rw [prime.dvd_iff_not_coprime hp, coprime_primes hp hq, ne.def, not_not] at h;\n      exact h \u25b8 mem_cons_self _ _)\n    (\u03bb h, have hl : \u2200 p \u2208 l, prime p := \u03bb p hlp, h\u2081 p ((mem_cons_iff _ _ _).2 (or.inr hlp)),\n    (mem_cons_iff _ _ _).2 (or.inr (mem_list_primes_of_dvd_prod hl h)))\n\nlemma mem_factors_iff_dvd {n p : \u2115} (hn : 0 < n) (hp : prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n\u27e8\u03bb h, prod_factors hn \u25b8 list.dvd_prod h,\n \u03bb h, mem_list_primes_of_dvd_prod hp (@mem_factors n) ((prod_factors hn).symm \u25b8 h)\u27e9\n\nlemma perm_of_prod_eq_prod : \u2200 {l\u2081 l\u2082 : list \u2115}, prod l\u2081 = prod l\u2082 \u2192\n  (\u2200 p \u2208 l\u2081, prime p) \u2192 (\u2200 p \u2208 l\u2082, prime p) \u2192 l\u2081 ~ l\u2082\n| []        []        _  _  _  := perm.nil\n| []        (a :: l)  h\u2081 h\u2082 h\u2083 :=\n  have ha : a \u2223 1 := @prod_nil \u2115 _ \u25b8 h\u2081.symm \u25b8 (@prod_cons _ _ l a).symm \u25b8 dvd_mul_right _ _,\n  absurd ha (prime.not_dvd_one (h\u2083 a (mem_cons_self _ _)))\n| (a :: l)  []        h\u2081 h\u2082 h\u2083 :=\n  have ha : a \u2223 1 := @prod_nil \u2115 _ \u25b8 h\u2081 \u25b8 (@prod_cons _ _ l a).symm \u25b8 dvd_mul_right _ _,\n  absurd ha (prime.not_dvd_one (h\u2082 a (mem_cons_self _ _)))\n| (a :: l\u2081) (b :: l\u2082) h hl\u2081 hl\u2082 :=\n  have hl\u2081' : \u2200 p \u2208 l\u2081, prime p := \u03bb p hp, hl\u2081 p (mem_cons_of_mem _ hp),\n  have hl\u2082' : \u2200 p \u2208 (b :: l\u2082).erase a, prime p := \u03bb p hp, hl\u2082 p (mem_of_mem_erase hp),\n  have ha : a \u2208 (b :: l\u2082) := mem_list_primes_of_dvd_prod (hl\u2081 a (mem_cons_self _ _)) hl\u2082\n    (h \u25b8 by rw prod_cons; exact dvd_mul_right _ _),\n  have hb : b :: l\u2082 ~ a :: (b :: l\u2082).erase a := perm_erase ha,\n  have hl : prod l\u2081 = prod ((b :: l\u2082).erase a) :=\n  (nat.mul_left_inj (prime.pos (hl\u2081 a (mem_cons_self _ _)))).1 $\n    by rwa [\u2190 prod_cons, \u2190 prod_cons, \u2190 prod_eq_of_perm hb],\n  perm.trans (perm.skip _ (perm_of_prod_eq_prod hl hl\u2081' hl\u2082')) hb.symm\n\nlemma factors_unique {n : \u2115} {l : list \u2115} (h\u2081 : prod l = n) (h\u2082 : \u2200 p \u2208 l, prime p) : l ~ factors n :=\nhave hn : 0 < n := nat.pos_of_ne_zero $ \u03bb h, begin\n  rw h at *, clear h,\n  induction l with a l hi,\n  { exact absurd h\u2081 dec_trivial },\n  { rw prod_cons at h\u2081,\n    exact nat.mul_ne_zero (ne_of_lt (prime.pos (h\u2082 a (mem_cons_self _ _)))).symm\n      (hi (\u03bb p hp, h\u2082 p (mem_cons_of_mem _ hp))) h\u2081 }\nend,\nperm_of_prod_eq_prod (by rwa prod_factors hn) h\u2082 (@mem_factors _)\n\nend\n\nlemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m n k l : \u2115}\n      (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k+l+1) \u2223 m*n) :\n      p ^ (k+1) \u2223 m \u2228 p ^ (l+1) \u2223 n :=\nhave hpd : p^(k+l) * p \u2223 m*n, from hpmn,\nhave hpd2 : p \u2223 (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,\nhave hpd3 : p \u2223 (m*n) / (p^k * p^l), by simpa [nat.pow_add] using hpd2,\nhave hpd4 : p \u2223 (m / p^k) * (n / p^l), by simpa [nat.div_mul_div hpm hpn] using hpd3,\nhave hpd5 : p \u2223 (m / p^k) \u2228 p \u2223 (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,\nshow p^k*p \u2223 m \u2228 p^l*p \u2223 n, from\n  hpd5.elim\n    (assume : p \u2223 m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)\n    (assume : p \u2223 n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)\n\nend nat\n", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/data/nat/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7073581995724044}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\nimport algebra.order.with_zero\nimport topology.algebra.order.field\n\n/-!\n# The topology on linearly ordered commutative groups with zero\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nLet `\u0393\u2080` be a linearly ordered commutative group to which we have adjoined a zero element.\nThen `\u0393\u2080` may naturally be endowed with a topology that turns `\u0393\u2080` into a topological monoid.\nNeighborhoods of zero are sets containing `{\u03b3 | \u03b3 < \u03b3\u2080}` for some invertible element `\u03b3\u2080`\nand every invertible element is open.\nIn particular the topology is the following:\n\"a subset `U \u2286 \u0393\u2080` is open if `0 \u2209 U` or if there is an invertible\n`\u03b3\u2080 \u2208 \u0393\u2080` such that `{\u03b3 | \u03b3 < \u03b3\u2080} \u2286 U`\", see `linear_ordered_comm_group_with_zero.is_open_iff`.\n\nWe prove this topology is ordered and T\u2083 (in addition to be compatible with the monoid\nstructure).\n\nAll this is useful to extend a valuation to a completion. This is an abstract version of how the\nabsolute value (resp. `p`-adic absolute value) on `\u211a` is extended to `\u211d` (resp. `\u211a\u209a`).\n\n## Implementation notes\n\nThis topology is not defined as a global instance since it may not be the desired topology on a\nlinearly ordered commutative group with zero. You can locally activate this topology using\n`open_locale with_zero_topology`.\n-/\n\nopen_locale topology filter\nopen topological_space filter set function\n\nnamespace with_zero_topology\n\nvariables {\u03b1 \u0393\u2080 : Type*} [linear_ordered_comm_group_with_zero \u0393\u2080] {\u03b3 \u03b3\u2081 \u03b3\u2082 : \u0393\u2080} {l : filter \u03b1}\n  {f : \u03b1 \u2192 \u0393\u2080}\n\n/-- The topology on a linearly ordered commutative group with a zero element adjoined.\nA subset U is open if 0 \u2209 U or if there is an invertible element \u03b3\u2080 such that {\u03b3 | \u03b3 < \u03b3\u2080} \u2286 U. -/\nprotected def topological_space : topological_space \u0393\u2080 :=\ntopological_space.mk_of_nhds $ update pure 0 $ \u2a05 \u03b3 \u2260 0, \ud835\udcdf (Iio \u03b3)\n\nlocalized \"attribute [instance] with_zero_topology.topological_space\" in with_zero_topology\n\nlemma nhds_eq_update : (\ud835\udcdd : \u0393\u2080 \u2192 filter \u0393\u2080) = update pure 0 (\u2a05 \u03b3 \u2260 0, \ud835\udcdf (Iio \u03b3)) :=\nfunext $ nhds_mk_of_nhds_single $ le_infi\u2082 $ \u03bb \u03b3 h\u2080, le_principal_iff.2 $ zero_lt_iff.2 h\u2080\n\n/-!\n### Neighbourhoods of zero\n-/\n\nlemma nhds_zero : \ud835\udcdd (0 : \u0393\u2080) = \u2a05 \u03b3 \u2260 0, \ud835\udcdf (Iio \u03b3) := by rw [nhds_eq_update, update_same]\n\n/-- In a linearly ordered group with zero element adjoined, `U` is a neighbourhood of `0` if and\nonly if there exists a nonzero element `\u03b3\u2080` such that `Iio \u03b3\u2080 \u2286 U`. -/\nlemma has_basis_nhds_zero : (\ud835\udcdd (0 : \u0393\u2080)).has_basis (\u03bb \u03b3 : \u0393\u2080, \u03b3 \u2260 0) Iio :=\nbegin\n  rw [nhds_zero],\n  refine has_basis_binfi_principal _ \u27e81, one_ne_zero\u27e9,\n  exact directed_on_iff_directed.2 (directed_of_inf $ \u03bb a b hab, Iio_subset_Iio hab)\nend\n\nlemma Iio_mem_nhds_zero (h\u03b3 : \u03b3 \u2260 0) : Iio \u03b3 \u2208 \ud835\udcdd (0 : \u0393\u2080) := has_basis_nhds_zero.mem_of_mem h\u03b3\n\n/-- If `\u03b3` is an invertible element of a linearly ordered group with zero element adjoined, then\n`Iio (\u03b3 : \u0393\u2080)` is a neighbourhood of `0`. -/\nlemma nhds_zero_of_units (\u03b3 : \u0393\u2080\u02e3) : Iio \u2191\u03b3 \u2208 \ud835\udcdd (0 : \u0393\u2080) := Iio_mem_nhds_zero \u03b3.ne_zero\n\nlemma tendsto_zero : tendsto f l (\ud835\udcdd (0 : \u0393\u2080)) \u2194 \u2200 \u03b3\u2080 \u2260 0, \u2200\u1da0 x in l, f x < \u03b3\u2080 := by simp [nhds_zero]\n\n/-!\n### Neighbourhoods of non-zero elements\n-/\n\n/-- The neighbourhood filter of a nonzero element consists of all sets containing that\nelement. -/\n@[simp] lemma nhds_of_ne_zero {\u03b3 : \u0393\u2080} (h\u2080 : \u03b3 \u2260 0) : \ud835\udcdd \u03b3 = pure \u03b3 :=\nby rw [nhds_eq_update, update_noteq h\u2080]\n\n/-- The neighbourhood filter of an invertible element consists of all sets containing that\nelement. -/\nlemma nhds_coe_units (\u03b3 : \u0393\u2080\u02e3) : \ud835\udcdd (\u03b3 : \u0393\u2080) = pure (\u03b3 : \u0393\u2080) := nhds_of_ne_zero \u03b3.ne_zero\n\n/-- If `\u03b3` is an invertible element of a linearly ordered group with zero element adjoined, then\n`{\u03b3}` is a neighbourhood of `\u03b3`. -/\nlemma singleton_mem_nhds_of_units (\u03b3 : \u0393\u2080\u02e3) : ({\u03b3} : set \u0393\u2080) \u2208 \ud835\udcdd (\u03b3 : \u0393\u2080) := by simp\n\n/-- If `\u03b3` is a nonzero element of a linearly ordered group with zero element adjoined, then `{\u03b3}`\nis a neighbourhood of `\u03b3`. -/\nlemma singleton_mem_nhds_of_ne_zero (h : \u03b3 \u2260 0) : ({\u03b3} : set \u0393\u2080) \u2208 \ud835\udcdd (\u03b3 : \u0393\u2080) := by simp [h]\n\nlemma has_basis_nhds_of_ne_zero {x : \u0393\u2080} (h : x \u2260 0) :\n  has_basis (\ud835\udcdd x) (\u03bb i : unit, true) (\u03bb i, {x}) :=\nby { rw [nhds_of_ne_zero h], exact has_basis_pure _ }\n\nlemma has_basis_nhds_units (\u03b3 : \u0393\u2080\u02e3) :\n  has_basis (\ud835\udcdd (\u03b3 : \u0393\u2080)) (\u03bb i : unit, true) (\u03bb i, {\u03b3}) :=\nhas_basis_nhds_of_ne_zero \u03b3.ne_zero\n\nlemma tendsto_of_ne_zero {\u03b3 : \u0393\u2080} (h : \u03b3 \u2260 0) : tendsto f l (\ud835\udcdd \u03b3) \u2194 \u2200\u1da0 x in l, f x = \u03b3 :=\nby rw [nhds_of_ne_zero h, tendsto_pure]\n\nlemma tendsto_units {\u03b3\u2080 : \u0393\u2080\u02e3} : tendsto f l (\ud835\udcdd (\u03b3\u2080 : \u0393\u2080)) \u2194 \u2200\u1da0 x in l, f x = \u03b3\u2080 :=\ntendsto_of_ne_zero \u03b3\u2080.ne_zero\n\nlemma Iio_mem_nhds (h : \u03b3\u2081 < \u03b3\u2082) : Iio \u03b3\u2082 \u2208 \ud835\udcdd \u03b3\u2081 :=\nby rcases eq_or_ne \u03b3\u2081 0 with rfl|h\u2080; simp [*, h.ne', Iio_mem_nhds_zero]\n\n/-!\n### Open/closed sets\n-/\n\nlemma is_open_iff {s : set \u0393\u2080} : is_open s \u2194 (0 : \u0393\u2080) \u2209 s \u2228 \u2203 \u03b3 \u2260 0, Iio \u03b3 \u2286 s :=\nbegin\n  rw [is_open_iff_mem_nhds, \u2190 and_forall_ne (0 : \u0393\u2080)],\n  simp [nhds_of_ne_zero, imp_iff_not_or, has_basis_nhds_zero.mem_iff] { contextual := tt }\nend\n\nlemma is_closed_iff {s : set \u0393\u2080} : is_closed s \u2194 (0 : \u0393\u2080) \u2208 s \u2228 \u2203 \u03b3 \u2260 0, s \u2286 Ici \u03b3 :=\nby simp only [\u2190 is_open_compl_iff, is_open_iff, mem_compl_iff, not_not, \u2190 compl_Ici,\n  compl_subset_compl]\n\nlemma is_open_Iio {a : \u0393\u2080} : is_open (Iio a) :=\nis_open_iff.mpr $ imp_iff_not_or.mp $ \u03bb ha, \u27e8a, ne_of_gt ha, subset.rfl\u27e9\n\n/-!\n### Instances\n-/\n\n/-- The topology on a linearly ordered group with zero element adjoined is compatible with the order\nstructure: the set `{p : \u0393\u2080 \u00d7 \u0393\u2080 | p.1 \u2264 p.2}` is closed. -/\nprotected \n\nlocalized \"attribute [instance] with_zero_topology.order_closed_topology\" in with_zero_topology\n\n/-- The topology on a linearly ordered group with zero element adjoined is T\u2083. -/\nlemma t3_space : t3_space \u0393\u2080 :=\n{ to_regular_space := regular_space.of_lift'_closure $ \u03bb \u03b3,\n    begin\n      rcases ne_or_eq \u03b3 0 with h\u2080|rfl,\n      { rw [nhds_of_ne_zero h\u2080, lift'_pure (monotone_closure \u0393\u2080), closure_singleton,\n          principal_singleton] },\n      { exact has_basis_nhds_zero.lift'_closure_eq_self\n        (\u03bb x hx, is_closed_iff.2 $ or.inl $ zero_lt_iff.2 hx) },\n    end }\n\nlocalized \"attribute [instance] with_zero_topology.t3_space\" in with_zero_topology\n\n/-- The topology on a linearly ordered group with zero element adjoined makes it a topological\nmonoid. -/\nprotected lemma has_continuous_mul : has_continuous_mul \u0393\u2080 :=\n\u27e8begin\n  rw continuous_iff_continuous_at,\n  rintros \u27e8x, y\u27e9,\n  wlog hle : x \u2264 y generalizing x y,\n  { have := tendsto.comp (this y x (le_of_not_le hle)) (continuous_swap.tendsto (x,y)),\n    simpa only [mul_comm, function.comp, prod.swap], },\n  rcases eq_or_ne x 0 with rfl|hx; [rcases eq_or_ne y 0 with rfl|hy, skip],\n  { rw [continuous_at, zero_mul],\n    refine ((has_basis_nhds_zero.prod_nhds has_basis_nhds_zero).tendsto_iff has_basis_nhds_zero).2\n      (\u03bb \u03b3 h\u03b3, \u27e8(\u03b3, 1), \u27e8h\u03b3, one_ne_zero\u27e9, _\u27e9),\n    rintro \u27e8x, y\u27e9 \u27e8hx : x < \u03b3, hy : y < 1\u27e9,\n    exact (mul_lt_mul\u2080 hx hy).trans_eq (mul_one \u03b3) },\n  { rw [continuous_at, zero_mul, nhds_prod_eq, nhds_of_ne_zero hy, prod_pure, tendsto_map'_iff],\n    refine (has_basis_nhds_zero.tendsto_iff has_basis_nhds_zero).2 (\u03bb \u03b3 h\u03b3, _),\n    refine \u27e8\u03b3 / y, div_ne_zero h\u03b3 hy, \u03bb x hx, _\u27e9,\n    calc x * y < \u03b3 / y * y : mul_lt_right\u2080 _ hx hy\n           ... = \u03b3         : div_mul_cancel _ hy },\n  { have hy : y \u2260 0, from ((zero_lt_iff.mpr hx).trans_le hle).ne',\n    rw [continuous_at, nhds_prod_eq, nhds_of_ne_zero hx, nhds_of_ne_zero hy, prod_pure_pure],\n    exact pure_le_nhds (x * y) }\nend\u27e9\n\nlocalized \"attribute [instance] with_zero_topology.has_continuous_mul\" in with_zero_topology\n\nprotected lemma has_continuous_inv\u2080 : has_continuous_inv\u2080 \u0393\u2080 :=\n\u27e8\u03bb \u03b3 h, by { rw [continuous_at, nhds_of_ne_zero h], exact pure_le_nhds \u03b3\u207b\u00b9 }\u27e9\n\nlocalized \"attribute [instance] with_zero_topology.has_continuous_inv\u2080\" in with_zero_topology\n\nend with_zero_topology\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/with_zero_topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7073581995222633}}
{"text": "/-\nCopyright (c) 2021 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 3 : \"not\" (`\u00ac`)\n\nWe learn about how to manipulate `\u00ac P` in Lean.\n\n# Important : the definition of `\u00ac P`\n\nIn Lean, `\u00ac P` is *defined* to mean `P \u2192 false`. So `\u00ac P` and `P \u2192 false`\nare *definitionally equal*. Check out the explanation of definitional\nequality in the \"equality\" section of Part B of the course notes.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following tactics:\n\n* `change`\n* `by_contra`\n* `by_cases`\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : \u00ac true \u2192 false :=\nbegin\n  sorry\nend\n\nexample : false \u2192 \u00ac true :=\nbegin\n  sorry\nend\n\nexample : \u00ac false \u2192 true :=\nbegin\n  sorry\nend\n\nexample : true \u2192 \u00ac false :=\nbegin\n  sorry\nend\n\nexample : false \u2192 \u00ac P :=\nbegin\n  sorry\nend\n\nexample : P \u2192 \u00ac P \u2192 false :=\nbegin\n  sorry\nend\n\nexample : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  sorry\nend\n\nexample : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  sorry\nend\n\nexample : \u00ac \u00ac false \u2192 false :=\nbegin\n  sorry\nend\n\nexample : \u00ac \u00ac P \u2192 P :=\nbegin\n  sorry\nend\n\nexample : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n  sorry,\nend", "meta": {"author": "Sukkrivaa", "repo": "lean2022", "sha": "f00390aafca0faab674cbaff557835bc463c8691", "save_path": "github-repos/lean/Sukkrivaa-lean2022", "path": "github-repos/lean/Sukkrivaa-lean2022/lean2022-f00390aafca0faab674cbaff557835bc463c8691/src/section01logic/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7073581928985441}}
{"text": "import irrefl\nimport diagonal\nimport data.stream\n\nuniverses u v\n\nnamespace cantor\n\nopen diagonal\n\n-- Cantor's diagonal argument generalized to types with irreflexive maps\ntheorem type_cantor {A : Sort u} {B : Sort v} [has_anot B]:\nnot exists M : A -> (A -> B), forall f : A -> B, exists a : A, f = M a \n:= begin\n  by_contradiction h,\n  exact exists.elim h begin\n    intro M,\n    assume hm,\n    have hfd := hm (dnot M),\n    exact exists.elim hfd begin \n      intro a,\n      assume hd : dnot M = M a,\n      have hnd : not (dnot M = M a) := dnot_ne_part M a,\n      exact hnd hd\n    end\n  end\nend\n\n/- Specializations of the generalized diagonal argument -/\n\n-- Diagonal Argument for Closed Binary Functions\ntheorem closed_cantor {A : Sort u} [has_anot A]:\nnot exists M : A -> (A -> A), forall f : A -> A, exists a, f = M a \n:= type_cantor\n\n-- Diagonal Argument for Relations\ntheorem relational_cantor {A : Sort u}:\nnot exists R : A -> A -> Prop, forall S : A -> Prop, exists a, S = R a \n:= type_cantor\n\n-- Diagonal Argument for Sets\ntheorem set_cantor {A : Type u}:\nnot exists R : A -> set A, forall S : set A, exists a, S = R a \n:= relational_cantor\n\n-- Diagonal Argument for Streams\ntheorem stream_cantor {a : Type u} [has_anot a]:\nnot exists M : stream (stream a), forall S : stream a, exists n, S = M n \n:= type_cantor\n\n-- Diagonal Argument for Boolean (Bit) Streams\ntheorem bool_stream_cantor:\nnot exists M : stream (stream bool), forall S : stream bool, exists n, S = M n \n:= stream_cantor\n\nend cantor\n", "meta": {"author": "tydeu", "repo": "cantor", "sha": "e804bc2a436f296233431c6320e3dd7a40ce6a27", "save_path": "github-repos/lean/tydeu-cantor", "path": "github-repos/lean/tydeu-cantor/cantor-e804bc2a436f296233431c6320e3dd7a40ce6a27/src/cantor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.7073486001508196}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport combinatorics.simple_graph.connectivity -- paths and walks etc\n\n/-\n\n# Trees\n\nA graph is a tree if it's nonempty and for every pair of vertices\nthere's a unique path between them.\n\nIn this file I show that trees have no cycles.\n\n-/\n\nuniverse u\u2080\n\nnamespace simple_graph\n\n/-- A graph is a tree if it's nonempty and for every pair of vertices\n  there's a unique path between them. -/\ndef is_tree {V : Type u\u2080} (G : simple_graph V) : Prop :=\nnonempty V \u2227 \u2200 u v : V, \u2203! p : G.walk u v, p.is_path\n\n/-- A graph is connected if it's nonempty and for every pair of vertices\n  there's a path between them. -/\ndef is_connected {V : Type u\u2080} (G : simple_graph V) : Prop :=\nnonempty V \u2227 \u2200 u v : V, \u2203 p : G.walk u v, p.is_path\n\nnamespace is_tree\n\nvariables {V : Type u\u2080} {G : simple_graph V}\n\n/-- Trees are connected. -/\nlemma is_connected {V : Type u\u2080} {G : simple_graph V} \n  (h : G.is_tree) : G.is_connected :=\nbegin\n  exact \u27e8h.1, \u03bb u v, exists_unique.exists (h.2 u v)\u27e9,\nend\n\nopen simple_graph.walk\n\n/-- A tree has no cycles. -/\nlemma no_cycles [decidable_eq V] (hG : G.is_tree) (u : V) (p : G.walk u u) :\n\u00ac p.is_cycle :=\nbegin\n  intro hp,\n  cases p with _ _ v _ huv q,\n  { exact hp.ne_nil rfl, },\n  { set w1 := cons huv nil with hw1,\n    set w2 := q.reverse with hw2,\n    have hw1path : w1.is_path,\n    { simp,\n      intro h,\n      rw h at huv,\n      exact G.loopless v huv },\n    have hw2path : w2.is_path,\n    { apply is_path.reverse,\n      rw is_path_def,\n      simpa using hp.support_nodup },\n    have hw := exists_unique.unique (hG.2 u v) hw1path hw2path,\n    rw [hw1, hw2] at hw,\n    apply_fun reverse at hw,\n    rw reverse_reverse at hw,\n    rw \u2190 hw at hp,\n    simp at hp,\n    replace hp := is_circuit.to_trail (is_cycle.to_circuit hp),\n    rw is_trail_def at hp,\n    simp at hp,\n    apply hp,\n    apply sym2.rel.swap },    \nend\n\nend is_tree\n\nend simple_graph\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section12graphtheory/examples/trees.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7073221312242189}}
{"text": "import data.stream tactic\nopen stream tactic \n\nnamespace CTL\n\nvariables AP : Type\n\nmutual inductive state_formula, path_formula\nwith state_formula : Type\n| T             : state_formula\n| atom (a : AP) : state_formula\n| conj (\u03a6\u2081 \u03a6\u2082 : state_formula ) : state_formula\n| neg (\u03a6 : state_formula) : state_formula\n| E (\u03c6 : path_formula) : state_formula\n| A (\u03c6 : path_formula) : state_formula\nwith path_formula : Type\n| next (\u03a6 : state_formula) : path_formula\n| until (\u03a6\u2081 \u03a6\u2082 : state_formula) : path_formula\nopen state_formula\nopen path_formula\n\nlocal notation  `\u223c` \u03a6 := neg \u03a6\nlocal notation \u03a6 `&` \u03a8 := conj \u03a6 \u03a8\nlocal notation `\u25cf` \u03a6 := next \u03a6\nlocal notation \u03a6 `\ud835\udcb0` \u03a8 := until \u03a6 \u03a8\n\ndef disj (\u03c6 \u03c8 : state_formula AP) : state_formula AP := \n\u223c(\u223c \u03c6 & \u223c\u03c8)\n\nlocal notation \u03c6 `\u214b` \u03c8 := disj _ \u03c6 \u03c8  \n\nstructure TS :=\n(S : Type)\n(H1 : inhabited S)\n(H2 : decidable_eq S)\n(Act : Type)\n(TR : set (S \u00d7 Act \u00d7 S))\n(L  : S \u2192 set AP)\n\ndef Post_of  {M : TS AP} (s : M.S) (\u03b1 : M.Act) : set (M.S) := {s' | (s,\u03b1,s') \u2208 M.TR}\n\ndef Post {M : TS AP} (s : M.S) : set (M.S) :=\n\u22c3 \u03b1 : M.Act, Post_of _ s \u03b1\n\n\ndef path {AP : Type} (M : TS AP) : Type := \n{s : stream M.S // \u2200 i : \u2115, s (i + 1) \u2208 Post _ (s i)}\n\n\ndef paths {AP : Type}\n{M : TS AP} (s : M.S) : set (path M) :=\n(\u03bb \u03c0, s =  \u03c0.val.head)\n\nmutual def state_sat, path_sat {M : TS AP}\nwith state_sat : state_formula AP \u2192 M.S \u2192 Prop\n| T := \u03bb _, true\n| (atom a) := \u03bb s, a \u2208 M.L s\n| (\u03a6 & \u03a8) := \u03bb s, state_sat \u03a6 s \u2227 state_sat \u03a8 s\n| (\u223c \u03a6) := \u03bb s, \u00ac (state_sat \u03a6 s)\n| (E \u03c6) := \u03bb s, \u2203 \u03c0 : path M, \u03c0 \u2208 paths s \u2227 path_sat \u03c6 \u03c0\n| (A \u03c6) := \u03bb s, \u2200 \u03c0 : path M, \u03c0 \u2208 paths s \u2192 path_sat \u03c6 \u03c0\nwith path_sat : path_formula AP \u2192 path M \u2192 Prop\n| (\u25cf \u03a6) := \u03bb \u03c0, state_sat \u03a6 (\u03c0.val 1)\n| (\u03a6 \ud835\udcb0 \u03a8) := \u03bb \u03c0, \n \u2203 j, state_sat \u03a8 (\u03c0.val j) \u2227 (\u2200 k < j, state_sat \u03a6 (\u03c0.val k))\n\nnotation s `\u22a8\u209b` \u03a6 := state_sat _ \u03a6 s\nnotation \u03c0 `\u22a8\u209a ` \u03a6 := path_sat _ \u03a6 \u03c0\n\n\nlemma disj_sat {AP : Type} {M : TS AP}  \n(\u03c6 \u03c8 : state_formula AP)(s : M.S) : \n (s \u22a8\u209b (\u03c6 \u214b \u03c8)) \u2194 (s \u22a8\u209b \u03c6) \u2228 (s \u22a8\u209b \u03c8) :=  \nby { rw disj, repeat {rw state_sat}, finish}\n\n\ndef potentially (\u03c6 : state_formula AP) : state_formula AP := \nE(T \ud835\udcb0 \u03c6)\nnotation `E\u25c6` \u03c6 := potentially _ \u03c6 \n\ndef inevitably (\u03c6 : state_formula AP) : state_formula AP := \nA(T \ud835\udcb0 \u03c6)\nnotation `A\u25c6` \u03c6 := inevitably _ \u03c6 \n\n\ndef potentially_always (\u03c6 : state_formula AP) : state_formula AP := \n\u223c (A\u25c6(\u223c\u03c6))\nnotation `E\u25fe` \u03c6 := potentially_always _ \u03c6 \n\n\ndef invariantly (\u03c6 : state_formula AP) : state_formula AP := \n\u223c (E\u25c6(\u223c\u03c6))\nnotation `A\u25fe` \u03c6 := invariantly _ \u03c6 \n\nnamespace sat \n\nlemma potentially {AP : Type} {M : TS AP} \n(\u03c6 : state_formula AP) (s : M.S): \n(s \u22a8\u209b E\u25c6\u03c6) \u2194 \u2203 \u03c0 \u2208 paths s, \u2203 j:\u2115, (subtype.val \u03c0 j) \u22a8\u209b \u03c6 := \nbegin \n    rw [potentially,state_sat,path_sat], dsimp only,\n    split,\n    { rintro \u27e8\u03c0,H,j,Hj1,Hj2\u27e9,\n      use \u03c0, exact \u27e8H, \u27e8j,Hj1\u27e9\u27e9},\n    { rintro \u27e8\u03c0,H1,j,H2\u27e9,\n      use \u03c0, \n      split, {exact H1}, \n     {use j, split, exact H2, intros, trivial}}\nend \n\nlemma inevitably {AP : Type} {M : TS AP} \n(\u03c6 : state_formula AP) (s : M.S) : \n(s \u22a8\u209b A\u25c6\u03c6) \u2194 \u2200 \u03c0 \u2208 paths s, \u2203 j : \u2115, (subtype.val \u03c0 j) \u22a8\u209b \u03c6 := \nbegin\n    rw [inevitably,state_sat,path_sat], dsimp only,\n    split,\n    { intros H1 \u03c0 H2, replace H1 := H1 \u03c0 H2,\n      cases H1 with j H1,\n      use j, exact H1.1},\n    { intros H1 \u03c0 H2, replace H1 := H1 \u03c0 H2,\n      cases H1 with j H1,\n      use j, split, {exact H1}, intros, trivial}  \nend  \n\n\nlemma potentially_always {AP : Type} {M : TS AP}\n(\u03c6 : state_formula AP) (s : M.S) : \n(s \u22a8\u209b E\u25fe\u03c6) \u2194 (\u2203 \u03c0 \u2208 paths s, \u2200 j : \u2115, (subtype.val \u03c0 j) \u22a8\u209b \u03c6) := \nbegin \n    rw potentially_always,\n    rw state_sat, dsimp only, \n    rw [inevitably,state_sat],\n    simp,\nend \n\ndef invariantly {AP : Type} {M : TS AP}\n(\u03c6 : state_formula AP) (s : M.S) : \n(s \u22a8\u209b A\u25fe\u03c6) \u2194 (\u2200 \u03c0 \u2208 paths s, \u2200 j : \u2115, (subtype.val \u03c0 j) \u22a8\u209b \u03c6) := \nbegin \n    rw invariantly,\n    rw state_sat, dsimp only, \n    rw [potentially,state_sat],\n    simp,\nend \n\nend sat\n\ndef sat_set {AP : Type} (M : TS AP) (\u03c6 : state_formula AP): set M.S := \n{s | s \u22a8\u209b \u03c6}\n\ndef equiv {AP : Type} (\u03c6 \u03c8: state_formula AP) : Prop :=  \n\u2200 M : TS AP, (sat_set M \u03c6) = (sat_set M \u03c8)\n\nnotation \u03c6 ` \u2261 ` \u03c8 := equiv \u03c6 \u03c8  \n\n\nlemma forall_until_expansion (\u03c6 \u03c8 : state_formula AP) : \n    A(\u03c6 \ud835\udcb0 \u03c8) \u2261 (\u03c8 \u214b (\u03c6 & A\u25cfA(\u03c6 \ud835\udcb0 \u03c8))) := \nbegin\n    intro M, ext, repeat {rw sat_set}, simp,\n    rw [state_sat, path_sat], simp,\n    rw disj_sat, repeat {rw state_sat},\n    rw path_sat, rw state_sat, rw path_sat,\n    simp, sorry\nend \n\n\n\n\n\n\nlemma forall_next_dual (\u03c6 : state_formula AP) : \n    (A\u25cf\u03c6) \u2261 (\u223cE(\u25cf\u223c\u03c6)) := \nbegin\n    intros M, ext, repeat {rw sat_set}, simp,\n    rw [state_sat,path_sat], \n    repeat {rw state_sat}, rw [path_sat, state_sat],\n    simp\nend \n\nlemma exists_next_dual (\u03c6 : state_formula AP) : \n    (E\u25cf\u03c6) \u2261 (\u223cA(\u25cf\u223c\u03c6)) := \nbegin\n    intros M, ext, repeat {rw sat_set}, simp,\n    rw [state_sat,path_sat],\n    repeat {rw state_sat}, rw [path_sat, state_sat],\n    simp\nend \n\n\nlemma potentially_dual (\u03c6 : state_formula AP) : \n    (E\u25c6\u03c6) \u2261 \u223c(A\u25fe\u223c\u03c6) := \nbegin \n    intros M, ext, repeat {rw sat_set}, simp,\n    rw [sat.potentially,state_sat],simp,\n    rw [sat.invariantly,state_sat],simp,\nend \n\nlemma inevitably_dual (\u03c6 : state_formula AP) : \n    (A\u25c6\u03c6) \u2261 \u223c(E\u25fe\u223c\u03c6) := \nbegin \n    intros M, ext, repeat {rw sat_set}, simp,\n    rw [sat.inevitably,state_sat],simp,\n    rw [sat.potentially_always,state_sat],simp,\nend \n\n\nlemma until_dual_fst (\u03c6 \u03c8 : state_formula AP) : \n    A(\u03c6 \ud835\udcb0 \u03c8) \u2261 ((\u223cE(\u223c \u03c8 \ud835\udcb0 (\u223c \u03c6 & \u223c \u03c8))) & \u223c E\u25fe \u223c\u03c8) := \n    begin\n        intros M, ext, repeat {rw sat_set}, simp,\n        repeat {rw [state_sat]},\n        repeat {rw [path_sat]}, simp,\n        split, {\n            intro H1, split,{\n                intros \u03c0 H2 i H3,\n                repeat {rw state_sat at H3},\n                rw state_sat, simp at *,\n                replace H1 := H1 \u03c0 H2,sorry\n                 \n            },{\n                sorry\n            }\n        },{sorry}\n    end \n\n\n\n\nend CTL", "meta": {"author": "loganrjmurphy", "repo": "lean-temporal", "sha": "40c6ad1502fc4168dffe9f34ad2d2043d53af174", "save_path": "github-repos/lean/loganrjmurphy-lean-temporal", "path": "github-repos/lean/loganrjmurphy-lean-temporal/lean-temporal-40c6ad1502fc4168dffe9f34ad2d2043d53af174/src/CTL.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952838963489, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.7073221273041914}}
{"text": "/- Tactic : exact\n\n## Summary \n\nIf the goal is `\u22a2 X` then `exact x` will close the goal if\nand only if `x` is a term of type `X`. \n\n## Details\n\nSay `P`, `Q` and `R` are types (i.e., what a mathematician\nmight think of as either sets or propositions),\nand the local context looks like this: \n\n```\np : P,\nh : P \u2192 Q,\nj : Q \u2192 R\n\u22a2 R\n```\n\nIf you can spot how to make a term of type `R`, then you\ncan just make it and say you're done using the `exact` tactic\ntogether with the formula you have spotted. For example the\nabove goal could be solved with\n\n`exact j(h(p)),`\n\nbecause `j(h(p))` is easily checked to be a term of type `R`\n(i.e., an element of the set `R`, or a proof of the proposition `R`).\n\n-/\n\n/-\nIn this level we learn the tactic `exact`, which solves a goal that is exactly one of the hypotheses.\nThe lemma is the same as in the previous level, but we will solve it in a different way.\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nBy doing a `rw` you will get the goal to look exactly like one of the hypotheses...\n-/\n\nvariables {\u03a9 : Type} -- hide\n\n/- Lemma : no-side-bar\nIf A, B and C are points with A = B and B = C, then A = C.\n-/\nlemma example_exact (A B C: \u03a9) (h1 : A = B) (h2 : B = C) : A = C :=\nbegin\n  rw h1,\n  exact h2,\n\n  \nend\n\n", "meta": {"author": "mmasdeu", "repo": "hilbertgame", "sha": "0557019a1b7220bab7fe35729646c25bf73f0447", "save_path": "github-repos/lean/mmasdeu-hilbertgame", "path": "github-repos/lean/mmasdeu-hilbertgame/hilbertgame-0557019a1b7220bab7fe35729646c25bf73f0447/src/tutorial_world/level04_exact.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7879311981328134, "lm_q1q2_score": 0.7073221249117607}}
{"text": "import plane_separation_world.level06 --hide\nopen IncidencePlane --hide\n\n/-\n# Plane Separation World\n\n## Level 7: on the way to the final level (IV).\n\nThis is the fourth of five lemmas that we need to prove before jumping into the final level of the game! You will be provided with \nits mathematical proof in paper right below. Remember that you can use all the theorem statements from the left-hand side box.\n\n## Mathematical proof in paper...\n\n**Claim:** If two points A and C are not on the same side of the line \u2113, there exists a point in the segment A\u00b7C which is incident with the line \u2113. \n\n**Proof:** \n\nLet us assume that there exists a point P, such that `P \u2208 pts (A\u2b1dC) \u2227 P \u2208 \u2113`. Then, either `P = A` or `A * P * C` or `P = C`, and `P \u2208 \u2113`. Now, we proceed with \nthe proof of by contradiction. If there does not exist such point P, we have to prove that the intersection of the segment `A\u00b7C` with the line \u2113 is empty, and `P \u2209 \u2113`.\nThat is, there exists a point X such that `x \u2208 pts (A\u2b1dC) \u2229 \u2191\u2113 \u2194 x \u2208 \u2205`. Then we have to prove (a) `x \u2208 pts (A\u2b1dC) \u2229 \u2191\u2113 \u2192 x \u2208 \u2205` and (b) `x \u2208 \u2205 \u2192 x \u2208 pts (A\u2b1dC) \u2229 \u2191\u2113`.\n\n**Proof (a):** Let us assume that `x \u2208 pts (A\u2b1dC) \u2229 \u2191\u2113`. Then, we have to prove that `x \u2208 \u2205`. That is, \n`x \u2208 U \u2192 false`, where `U` is the `universal set`. Because of this reason, we assume that `x \u2208 U` is true and then it suffices to prove `false`. At this point,\nlet the point P be `x`, such that `x = A` or `A * x * C` or `x = C`, and `x \u2209 \u2113`. If we assume that `A * x * C`, the `finish` tactic will close the goal.\nBecause the fact that `A * x * C` implies that `x \u2208 \u2113`, then we reach a contradiction with `x \u2208 \u2205`. Therefore, the first case is proved. \n\n**Proof (b):** Note that the point `x` being an element of the empty set cannot imply that `x` is an element of \nthe intersection between the segment `A\u00b7C` and the line \u2113, since this is not an empty set. Then, propositional logic proves this case. (You can use the `tauto` tactic\nto solve it in Lean.)\n\nTherefore, we have proved that there exists a point P such that P is an element of the segment `A\u00b7C` and that `P \u2208 \u2113`. \n \n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nTo solve this level, we have used high levels tactics which weren't taught in the Tutorial World.. In case you feel bewildered, do not hesitate\nto click on \"View source\" (located on the top right corner of the game screen) to see the solution.\n-/\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9] --hide\nvariables {A B C P Q R : \u03a9} --hide\nvariables {\u2113 r s t : Line \u03a9} --hide\n\n/- Lemma :\nIf two points A and C are not on the same side of the line \u2113, there exists a point in the segment A\u00b7C which is incident with the line \u2113. \n-/\nlemma not_same_side_intersection (h : \u00ac same_side \u2113 A C) : \u2203 P , P \u2208 pts (A\u2b1dC) \u2227 P \u2208 \u2113 :=\nbegin\n  simp,\n  by_contra hlAC,\n  push_neg at hlAC,\n  apply h,\n  unfold same_side,\n  ext,\n  split,\n    {\n      intro hx,\n      simp,\n      specialize hlAC x,\n      have hAxC : A*x*C,\n      {\n        finish,\n      },\n      apply hlAC,\n      {\n        tauto,\n      },\n      {\n        finish,\n      },  \n    },\n    {\n      tauto,\n    },\n  \nend \n", "meta": {"author": "luisscastillo", "repo": "lean-game", "sha": "44c454ca6f4dcb8de76401790cf3f4fa91738fc1", "save_path": "github-repos/lean/luisscastillo-lean-game", "path": "github-repos/lean/luisscastillo-lean-game/lean-game-44c454ca6f4dcb8de76401790cf3f4fa91738fc1/src/plane_separation_world/level07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.707322122597951}}
{"text": "import algebra.punit_instances\nimport algebra.category.Group\nimport group_theory.subgroup\nimport group_theory.quotient_group\nimport .subgroup .quotient_group\n\nopen subgroup monoid_hom\n\nstructure normal_embedding (G H : Type*) [group G] [group H]\n  extends \u03c6 : G \u2192* H :=\n(inj : function.injective \u03c6)\n(norm : \u03c6.range.normal)\n\nstructure add_normal_embedding (G H : Type*) [add_group G] [add_group H]\n  extends \u03c6 : G \u2192+ H :=\n(inj : function.injective \u03c6)\n(norm : \u03c6.range.normal)\n\nattribute [to_additive add_normal_embedding] normal_embedding\n\nnamespace normal_embedding\n\nvariables {G H K : Type*} [group G] [group H] [group K]\n\n@[to_additive]\ninstance normal (f : normal_embedding G H) : f.\u03c6.range.normal := f.norm\n\n/- Coerce a normal embedding to a group homomorphism -/\n@[to_additive]\ninstance : has_coe (normal_embedding G H) (G \u2192* H) := \u27e8normal_embedding.\u03c6\u27e9\n\n/- The unique normal embedding from the trivial group to any group -/\n@[to_additive]\ndef from_subsingleton (hG : subsingleton G) (H : Type*) [group H] : normal_embedding G H :=\n\u27e81, \u03bb x y _, subsingleton.elim x y, (@monoid_hom.range_one G H _ _).symm \u25b8 subgroup.bot_normal\u27e9\n\n@[simp, to_additive]\nlemma from_subsingleton_range {hG : subsingleton G} : (from_subsingleton hG H).\u03c6.range = \u22a5 :=\nle_antisymm (by { rintros x \u27e8y, rfl\u27e9, rw [subsingleton.elim y 1, map_one, mem_bot] }) bot_le\n\n/- A group isomorphism induces a normal embedding -/\n@[to_additive]\ndef of_mul_equiv (h : G \u2243* H) : normal_embedding G H :=\n\u27e8h.to_monoid_hom, h.left_inv.injective,\n  suffices heq : h.to_monoid_hom.range = \u22a4, from heq.substr subgroup.top_normal,\n  set_like.ext' (h.to_monoid_hom.coe_range.trans $ h.surjective.range_eq)\u27e9\n\n/- A normal embedding from `G` to `H` can be composed with a group isomorphism\n`H \u2243* K` to produce a normal embedding from `G` to `K` -/\n@[to_additive]\ndef comp_mul_equiv (f : normal_embedding G H) (h : H \u2243* K) : normal_embedding G K :=\n{ \u03c6 := h.to_monoid_hom.comp f,\n  inj := function.injective.comp h.left_inv.injective f.inj, \n  norm := by rw range_comp; exact normal.mul_equiv_map f.norm h }\n\nopen quotient_group\n\n@[to_additive]\ninstance group_quotient (f : normal_embedding G H) : group (quotient f.\u03c6.range) :=\nby haveI := f.norm; apply_instance\n\n@[to_additive]\ndef of_normal_subgroup (N : subgroup G) [N.normal] : normal_embedding N G :=\n\u27e8N.subtype, \u03bb x y hx, by simpa using hx, (range_subtype N).symm \u25b8 infer_instance\u27e9\n\n@[simp, to_additive]\nlemma range_of_normal_subgroup (N : subgroup G) [N.normal] :\n  (of_normal_subgroup N).\u03c6.range = N :=\nby simp only [of_normal_subgroup, range_subtype]\n\n@[to_additive]\ndef of_normal_subgroup_to_subgroup {K N : subgroup G} [N.normal] (h : N \u2264 K) :\n  normal_embedding N K :=\n\u27e8inclusion h, inclusion_injective, by { rw range_inclusion, apply_instance }\u27e9\n\n@[to_additive]\nnoncomputable def equiv_range (f : normal_embedding G H) : G \u2243* f.\u03c6.range :=\nmul_equiv.of_injective f.inj\n\n@[to_additive]\nnoncomputable def equiv_quotient_comp_mul_equiv (f : normal_embedding G H) (e : H \u2243* K) :\n  quotient (comp_mul_equiv f e).\u03c6.range \u2243* quotient f.\u03c6.range :=\nlet \u03c8 : K \u2192* quotient f.\u03c6.range := (mk' f.\u03c6.range).comp e.symm.to_monoid_hom in\nhave h\u03c8 : function.surjective \u03c8 := function.surjective.comp (surjective_quot_mk _) e.symm.surjective,\nsuffices h : \u03c8.ker = (comp_mul_equiv f e).\u03c6.range,\n  from (equiv_quotient_of_eq h.symm).trans (quotient_ker_equiv_of_surjective \u03c8 h\u03c8),\nbegin\n  simp [\u03c8, comp_mul_equiv, \u2190comap_ker],\n  have : comap e.symm.to_monoid_hom f.\u03c6.range = map e.to_monoid_hom f.\u03c6.range,\n  { symmetry, apply map_eq_comap_of_inverse, exact e.left_inv, exact e.right_inv },\n  rw this, simp [range_eq_map, \u2190map_map], refl,\nend\n\n@[to_additive]\nnoncomputable lemma fintype [fintype G] (f : normal_embedding H G)\n  [decidable_pred (\u03bb x, x \u2208 f.\u03c6.range)] : fintype H :=\nfintype.of_equiv f.\u03c6.range f.equiv_range.to_equiv.symm\n\nvariables (f : normal_embedding H G) (g : normal_embedding K G)\n\n@[to_additive]\nnoncomputable def from_inf_range_left :\n  normal_embedding \u21a5(f.\u03c6.range \u2293 g.\u03c6.range) H :=\ncomp_mul_equiv (of_normal_subgroup_to_subgroup inf_le_left) (equiv_range f).symm\n\n@[to_additive]\nnoncomputable def from_inf_range_right :\n  normal_embedding \u21a5(f.\u03c6.range \u2293 g.\u03c6.range) K :=\ncomp_mul_equiv (of_normal_subgroup_to_subgroup inf_le_right) (equiv_range g).symm\n\n@[to_additive]\nnoncomputable def quotient_from_inf_range_left (h : f.\u03c6.range \u2294 g.\u03c6.range = \u22a4) :\n  quotient (from_inf_range_left f g).\u03c6.range \u2243* quotient g.\u03c6.range :=\nhave h1 : quotient (from_inf_range_left f g).\u03c6.range \u2243*\n  quotient (comap f.\u03c6.range.subtype (f.\u03c6.range \u2293 g.\u03c6.range)),\nby { apply (equiv_quotient_of_eq _).trans (equiv_quotient_of_equiv (equiv_range f).symm).symm,\n  simp [from_inf_range_left, comp_mul_equiv, range_comp], congr,\n  rw [comap_subtype, \u2190@range_inclusion _ _ _ f.\u03c6.range inf_le_left], refl },\nsuffices h2 : quotient g.\u03c6.range \u2243* quotient (comap (f.\u03c6.range \u2294 g.\u03c6.range).subtype g.\u03c6.range),\nfrom h1.trans $ (quotient_inf_equiv_prod_normal_quotient _ _).trans h2.symm,\nby { rw h, apply (equiv_quotient_of_equiv $ equiv_top G).trans (equiv_quotient_of_eq _),\n  rw comap_subtype_top }\n\n@[to_additive]\nnoncomputable def quotient_from_inf_range_right (h : f.\u03c6.range \u2294 g.\u03c6.range = \u22a4) :\n  quotient (from_inf_range_right f g).\u03c6.range \u2243* quotient f.\u03c6.range :=\nhave h1 : quotient (from_inf_range_right f g).\u03c6.range \u2243*\n  quotient (comap g.\u03c6.range.subtype (f.\u03c6.range \u2293 g.\u03c6.range)),\nby { apply (equiv_quotient_of_eq _).trans (equiv_quotient_of_equiv (equiv_range g).symm).symm,\n  simp [from_inf_range_right, comp_mul_equiv, range_comp], congr,\n  rw comap_subtype, conv_rhs { rw inf_comm },\n  rw \u2190@range_inclusion _ _ _ g.\u03c6.range inf_le_right, refl },\nsuffices h2 : quotient f.\u03c6.range \u2243* quotient (comap (f.\u03c6.range \u2294 g.\u03c6.range).subtype f.\u03c6.range),\nby { apply h1.trans (mul_equiv.trans _ h2.symm), rw sup_comm,\n  apply (equiv_quotient_of_eq _).trans (quotient_inf_equiv_prod_normal_quotient _ _),\n  rw inf_comm },\nby { rw h, apply (equiv_quotient_of_equiv $ equiv_top G).trans (equiv_quotient_of_eq _),\n  rw comap_subtype_top }\n\nend normal_embedding\n", "meta": {"author": "AdrianDoM", "repo": "IMOinLEAN", "sha": "672faa5bc8dd42a26fb1540ad8b9a325362be361", "save_path": "github-repos/lean/AdrianDoM-IMOinLEAN", "path": "github-repos/lean/AdrianDoM-IMOinLEAN/IMOinLEAN-672faa5bc8dd42a26fb1540ad8b9a325362be361/src/jordanholder/normal_embedding.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7073221138930611}}
{"text": "import tactic.linarith\nimport data.real.basic\nimport data.complex.exponential\nimport data.polynomial\nimport data.nat.choose\n\n/-\n\nM1F May exam 2018, question 1.\n\n-/\n\nuniverse u\n\nlocal attribute [instance, priority 0] classical.prop_decidable\n\nopen nat\n\n-- Q1(a)(i)\ntheorem count (n : \u2115) (hn : n \u2265 1) : finset.sum (finset.range (nat.succ n)) (\u03bb m, choose n m) =\n  2 ^ n --answer\n  :=\nbegin\n  have H := (add_pow (1 : \u2115) 1 n).symm,\n  simpa [nat.one_pow, one_mul, one_add_one_eq_two,\n    (finset.sum_nat_cast _ _).symm, nat.cast_id] using H,\nend\n\n-- Q1(a)(ii)\ntheorem countdown (n : \u2115) (hn : n \u2265 1) :\n  finset.sum (finset.range (nat.succ n)) (\u03bb m, (-1 : \u2124) ^ m * choose n m) =\n  0 -- answer\n  := \nbegin\n  have H := (add_pow (-1 : \u2124) 1 n).symm,\n  have H2 := @_root_.zero_pow \u2124 _ _ hn,\n  simpa [nat.one_pow, one_mul, one_add_one_eq_two, nat.zero_pow hn,\n    (finset.sum_nat_cast _ _).symm, nat.cast_id, H2] using H,\nend\n\n-- Q1(b) preparation\nopen real polynomial\nnoncomputable def chebyshev : \u2115 \u2192 polynomial \u211d\n| 0 := C 1\n| 1 := X\n| (n + 2) := 2 * X * chebyshev (n + 1) - chebyshev n\n\ndef chebyshev' : \u2115 \u2192 polynomial \u2124\n| 0 := C 1\n| 1 := X\n| (n + 2) := 2 * X * chebyshev' (n + 1) - chebyshev' n\n\nlemma polycos_zero (\u03b8 : \u211d) : cos (0 * \u03b8) = polynomial.eval (cos \u03b8) (chebyshev 0) :=\nby rw [chebyshev, eval_C, zero_mul, cos_zero]\n\nlemma polycos (n : \u2115) (hn : n \u2265 1) : \u2200 \u03b8 : \u211d, cos (n * \u03b8) = polynomial.eval (cos \u03b8) (chebyshev n) :=\nbegin\n  intro \u03b8,\n  apply nat.strong_induction_on n,\n  intros k ih,\n  have ih1 : cos (\u2191(k - 1) * \u03b8) = polynomial.eval (cos \u03b8) (chebyshev (k - 1)),\n  { by_cases h : k = 0,\n    { rw [h, (show (0 - 1 = 0), by refl)], convert polycos_zero \u03b8},\n    -- h : k \u2260 0,\n    { exact ih (k - 1) (nat.sub_lt (nat.pos_of_ne_zero h) (by norm_num : 0 < 1)) }\n  },\n  have ih2 : cos (\u2191(k - 2) * \u03b8) = polynomial.eval (cos \u03b8) (chebyshev (k - 2)),\n  { by_cases h : k = 0,\n    { rw [h, (show (0 - 2 = 0), from rfl)], convert polycos_zero \u03b8},--, chebyshev, eval_one],\n    -- h : k \u2260 0,\n    { exact ih (k - 2) (nat.sub_lt (nat.pos_of_ne_zero h) (by norm_num : 0 < 2)) }\n  },\n  by_cases h1 : k = 0,\n    rw h1, exact polycos_zero \u03b8,\n  by_cases h2 : k = 1,\n  { rw [h2, chebyshev, eval_X],\n    congr', \n    convert one_mul \u03b8,\n    simp},\n  have hk : k = (k - 2) + 2, rw nat.sub_add_cancel, swap,\n   rw [hk, chebyshev, \u2190hk, nat.succ_eq_add_one, (_ : k - 2 + 1 = k - 1), two_mul,\n        polynomial.eval_sub, polynomial.eval_mul, polynomial.eval_add,\n         polynomial.eval_X, \u2190two_mul, \u2190ih1, \u2190ih2],\n        rw [\u2190complex.of_real_inj, complex.of_real_sub, complex.of_real_mul, complex.of_real_mul,\n            complex.of_real_cos, complex.of_real_cos, complex.of_real_cos, complex.of_real_cos,\n            complex.cos, complex.cos, complex.cos, complex.cos],\n        simp,\n        rw [mul_div_cancel', \u2190mul_div_assoc, \u2190neg_div, \u2190add_div, add_mul, mul_add, mul_add,\n            \u2190complex.exp_add, \u2190complex.exp_add, \u2190complex.exp_add, \u2190complex.exp_add,\n            mul_assoc, mul_assoc, mul_assoc],\n        rw [\u2190one_mul (\u2191\u03b8 * complex.I)] {occs := occurrences.pos [5, 7]},\n        rw [\u2190add_mul, \u2190sub_eq_add_neg, \u2190sub_mul, \u2190neg_one_mul (\u2191\u03b8 * complex.I),\n            \u2190add_mul, \u2190sub_eq_add_neg, \u2190sub_mul, @nat.cast_sub _ _ _ 1 k, add_sub, nat.cast_one,\n            add_sub_cancel', \u2190sub_add, sub_add_eq_add_sub, one_add_one_eq_two, add_sub,\n            \u2190sub_add_eq_add_sub, \u2190neg_add', one_add_one_eq_two, \u2190sub_add, sub_add_eq_add_sub,\n            neg_add_self, zero_sub, nat.cast_sub, neg_mul_eq_neg_mul, neg_mul_eq_neg_mul,\n            neg_sub, nat.cast_two, neg_add, sub_eq_neg_add, \u2190add_assoc, \u2190neg_add,\n            \u2190sub_eq_neg_add, add_sub_add_right_eq_sub, \u2190add_assoc, sub_add_cancel],\n        all_goals {\n            try {\n            have H : k \u2265 2,\n                apply le_of_not_gt, intro,\n                have h12 : k = 0 \u2228 k = 1,\n                    clear ih ih1 ih2 h1 h2, try { clear hk },\n                    revert k a, exact dec_trivial,\n                apply or.elim h12 (\u03bb h12, h1 h12) (\u03bb h12, h2 h12) },\n                try { exact H }, try { exact le_trans (by norm_num : 1 \u2264 2) H } },\n        apply two_ne_zero',\n        apply @eq_of_add_eq_add_right _ _ _ 1 _,\n        rw [add_assoc, one_add_one_eq_two, nat.sub_add_cancel H,\n            nat.sub_add_cancel (le_trans (by norm_num : 1 \u2264 2) H)],\n    end\n\n-- Q1(b)(i)\ntheorem exist_polycos (n : \u2115) (hn : n \u2265 1) :\n  \u2203 Pn : polynomial \u211d, \u2200 \u03b8 : \u211d, cos (n * \u03b8) = polynomial.eval (cos \u03b8) Pn := ---ans\nExists.intro (chebyshev n) (polycos n hn)\n\n\nopen polynomial\n\n-- Q1(b)(ii)\nexample : chebyshev' 4 = 8 * X ^ 4 - 8 * X ^ 2 + 1 := dec_trivial\n\n-- Q1(b)(iii) preparation\nlemma useful (k : \u2115) : polynomial.degree (chebyshev' k) = k :=\nbegin\n  apply nat.strong_induction_on k,\n  intros n ih,\n  have ih1 : polynomial.degree (chebyshev' (n - 1)) = \u2191(n - 1),\n  { by_cases h : n = 0,\n    { rw h, apply degree_C, norm_num },--simp [h, chebyshev'], },\n    { exact ih _ (nat.sub_lt (nat.pos_of_ne_zero h) (zero_lt_one)) },\n  },\n  have ih2 : polynomial.degree (chebyshev' (n - 2)) = \u2191(n - 2),\n  { by_cases h : n \u2264 1,\n    { apply or.elim ((dec_trivial : \u2200 j : \u2115, j \u2264 1 \u2192 j = 0 \u2228 j = 1) n h),\n      { intro h0, rw h0, apply degree_C, norm_num },\n      { intro h1, rw h1, apply degree_C, norm_num },\n    },\n    { apply ih _, apply nat.sub_lt (lt_of_not_ge (\u03bb w, h (le_trans w zero_le_one))),\n      norm_num },\n  },\n  by_cases h : n \u2265 2,\n  { have H : n - 2 + 2 = n := nat.sub_add_cancel h,\n    have H' : nat.succ (n - 2) = n - 1, \n    { have W : n \u2265 2,\n      { apply le_of_not_gt, intro,\n        have h12 : n = 0 \u2228 n = 1,\n        { clear ih ih1 ih2 H h,\n          revert n a, exact dec_trivial },\n        apply or.elim h12,\n          intro h1, rw h1 at h, revert h, norm_num,\n          intro h2, rw h2 at h, revert h, norm_num\n      },\n      apply @eq_of_add_eq_add_right _ _ _ 1 _,\n      show n - 2 + 1 + 1 = n - 1 + 1,\n      rw [add_assoc, one_add_one_eq_two, nat.sub_add_cancel W,\n        nat.sub_add_cancel (le_of_lt h)]\n    },\n    rw [\u2190H, chebyshev', H, sub_eq_neg_add, polynomial.degree_add_eq_of_degree_lt,\n      polynomial.degree_mul_eq, polynomial.degree_mul_eq, polynomial.degree_X, H', ih1],\n    { show (polynomial.degree (polynomial.C 2) + 1 + \u2191(n - 1) = \u2191n),\n      rw [polynomial.degree_C, zero_add, \u2190with_bot.coe_one, \u2190with_bot.coe_add,\n        add_comm, nat.sub_add_cancel (le_of_lt h)],\n      exact two_ne_zero',\n    },\n    { rw [polynomial.degree_neg, polynomial.degree_mul_eq, polynomial.degree_mul_eq, ih2, H', ih1],\n      show (\u2191(n - 2) < polynomial.degree (polynomial.C 2) + polynomial.degree polynomial.X + \u2191(n - 1)),\n      rw [polynomial.degree_C, polynomial.degree_X, zero_add, \u2190with_bot.coe_one, \u2190with_bot.coe_add,\n        add_comm, nat.sub_add_cancel (le_of_lt h), with_bot.coe_lt_coe],\n        apply nat.sub_lt (lt_trans zero_lt_one h), norm_num,\n      exact two_ne_zero'\n    }\n  },\n  { apply or.elim ((dec_trivial : \u2200 j : \u2115, j \u2264 1 \u2192 j = 0 \u2228 j = 1) n (le_of_not_gt h)),\n      intro h0, rw h0, apply degree_C, exact dec_trivial,\n      intro h1, rw h1, exact degree_X\n  }\nend \n\nlemma useful' (k : \u2115) : polynomial.degree (chebyshev' (k - 2)) < 1 + polynomial.degree (chebyshev' (k - 1)) :=\nbegin\n    rw [useful, useful, \u2190with_bot.coe_one, \u2190with_bot.coe_add, with_bot.coe_lt_coe, add_comm],\n    by_cases h : k \u2264 1,\n        apply or.elim ((dec_trivial : \u2200 (j : \u2115), j \u2264 1 \u2192 j = 0 \u2228 j = 1) k h),\n            intro h0, simp [h0], exact zero_lt_one,\n            intro h1, simp [h1], exact zero_lt_one,\n    rw [nat.sub_add_cancel (le_of_not_le h)],\n    apply nat.sub_lt (lt_of_lt_of_le zero_lt_one (le_of_not_le h)), norm_num\nend\n\n-- Q1(b)(iii)\ntheorem leading_coeff (n : \u2115) : polynomial.leading_coeff (chebyshev' n) =\n  2 ^ (n - 1) := ---ans\nbegin\n    apply nat.strong_induction_on n, intros k hk,\n    have h1 : polynomial.leading_coeff (chebyshev' (k - 1)) = 2 ^ (k - 1 - 1),\n        by_cases h : k = 0,\n          rw h, show (leading_coeff (C (1 : \u2124)) = 1),exact leading_coeff_C (1 : \u2124),\n          exact hk (k - 1) (nat.pred_lt h : k - 1 < k),\n    have h2 : polynomial.leading_coeff (chebyshev' (k - 2)) = 2 ^ (k - 2 - 1),\n        by_cases h : k \u2264 1,\n            apply or.elim ((dec_trivial : \u2200 j : \u2115, j \u2264 1 \u2192 j = 0 \u2228 j = 1) k h),\n                intro h0, rw h0, exact leading_coeff_C (1 : \u2124),\n                intro h1, rw h1, exact leading_coeff_C (1 : \u2124),\n            exact hk (k - 2) (nat.sub_lt (lt_of_not_ge (\u03bb w, h (le_trans w zero_le_one))) (by norm_num)),\n    by_cases h : k \u2265 2,\n        have H : k - 2 + 2 = k := nat.sub_add_cancel h,\n        rw [\u2190H, chebyshev', H, (_ : nat.succ (k - 2) = k - 1), sub_eq_add_neg, add_comm,\n            polynomial.leading_coeff_add_of_degree_lt, polynomial.leading_coeff_mul,\n            polynomial.leading_coeff_mul, \u2190one_add_one_eq_two,\n            polynomial.leading_coeff_add_of_degree_eq rfl, \u2190polynomial.C_1,\n            polynomial.leading_coeff_C, polynomial.leading_coeff_X, h1,\n            one_add_one_eq_two, mul_one, (_root_.pow_succ (2 : \u2124) (k - 1 - 1)).symm, nat.sub_add_cancel],\n    change 1 \u2264 k - 1,\n    rwa [nat.le_sub_left_iff_add_le (le_of_lt h), one_add_one_eq_two],\n    rw [\u2190polynomial.C_1, polynomial.leading_coeff_C, one_add_one_eq_two], exact two_ne_zero',\n    rw [polynomial.degree_neg, polynomial.degree_mul_eq, polynomial.degree_mul_eq,\n        ((one_add_one_eq_two).symm : ((2 : polynomial \u2124) = 1 + 1)), \u2190polynomial.C_1, \u2190polynomial.C_add,\n        one_add_one_eq_two, polynomial.degree_C, zero_add, polynomial.degree_X],\n    exact useful' k,\n    exact two_ne_zero',\n    rw [nat.succ_eq_add_one, eq_comm, \u2190nat.sub_eq_iff_eq_add, nat.sub_sub, one_add_one_eq_two],\n    rwa [nat.le_sub_left_iff_add_le (le_of_lt h), one_add_one_eq_two],\n    rw not_lt at h,\n    have h' : k = 0 \u2228 k = 1, clear hk h1 h2, revert k h, exact dec_trivial,\n    cases h',\n    { rw h', exact leading_coeff_C (1 : \u2124)},\n    { rw h', exact leading_coeff_C (1 : \u2124)}\nend\n\n-- Q1(b)(iv)\ntheorem cheby1 (n : \u2115) (hn : n \u2265 1) : polynomial.eval 1 (chebyshev n) = 1 := ---ans\nbegin\n    have h := (polycos n hn 0).symm,\n    rwa [mul_zero, cos_zero] at h,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1F-exam-may-2018", "sha": "8b5eca2037d4a14d6cfac3da1858b6c4119216d3", "save_path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018", "path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018/M1F-exam-may-2018-8b5eca2037d4a14d6cfac3da1858b6c4119216d3/src/Q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7073006517297517}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n\n! This file was ported from Lean 3 source module linear_algebra.affine_space.independent\n! leanprover-community/mathlib commit 2de9c37fa71dde2f1c6feff19876dd6a7b1519f0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Finset.Sort\nimport Mathbin.Data.Fin.VecNotation\nimport Mathbin.Data.Sign\nimport Mathbin.LinearAlgebra.AffineSpace.Combination\nimport Mathbin.LinearAlgebra.AffineSpace.AffineEquiv\nimport Mathbin.LinearAlgebra.Basis\n\n/-!\n# Affine independence\n\nThis file defines affinely independent families of points.\n\n## Main definitions\n\n* `affine_independent` defines affinely independent families of points\n  as those where no nontrivial weighted subtraction is `0`.  This is\n  proved equivalent to two other formulations: linear independence of\n  the results of subtracting a base point in the family from the other\n  points in the family, or any equal affine combinations having the\n  same weights.  A bundled type `simplex` is provided for finite\n  affinely independent families of points, with an abbreviation\n  `triangle` for the case of three points.\n\n## References\n\n* https://en.wikipedia.org/wiki/Affine_space\n\n-/\n\n\nnoncomputable section\n\nopen BigOperators Affine\n\nopen Function\n\nsection AffineIndependent\n\nvariable (k : Type _) {V : Type _} {P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n\nvariable [affine_space V P] {\u03b9 : Type _}\n\ninclude V\n\n/-- An indexed family is said to be affinely independent if no\nnontrivial weighted subtractions (where the sum of weights is 0) are\n0. -/\ndef AffineIndependent (p : \u03b9 \u2192 P) : Prop :=\n  \u2200 (s : Finset \u03b9) (w : \u03b9 \u2192 k),\n    (\u2211 i in s, w i) = 0 \u2192 s.weightedVsub p w = (0 : V) \u2192 \u2200 i \u2208 s, w i = 0\n#align affine_independent AffineIndependent\n\n/-- The definition of `affine_independent`. -/\ntheorem affineIndependent_def (p : \u03b9 \u2192 P) :\n    AffineIndependent k p \u2194\n      \u2200 (s : Finset \u03b9) (w : \u03b9 \u2192 k),\n        (\u2211 i in s, w i) = 0 \u2192 s.weightedVsub p w = (0 : V) \u2192 \u2200 i \u2208 s, w i = 0 :=\n  Iff.rfl\n#align affine_independent_def affineIndependent_def\n\n/-- A family with at most one point is affinely independent. -/\ntheorem affineIndependent_of_subsingleton [Subsingleton \u03b9] (p : \u03b9 \u2192 P) : AffineIndependent k p :=\n  fun s w h hs i hi => Fintype.eq_of_subsingleton_of_sum_eq h i hi\n#align affine_independent_of_subsingleton affineIndependent_of_subsingleton\n\n/-- A family indexed by a `fintype` is affinely independent if and\nonly if no nontrivial weighted subtractions over `finset.univ` (where\nthe sum of the weights is 0) are 0. -/\ntheorem affineIndependent_iff_of_fintype [Fintype \u03b9] (p : \u03b9 \u2192 P) :\n    AffineIndependent k p \u2194\n      \u2200 w : \u03b9 \u2192 k, (\u2211 i, w i) = 0 \u2192 Finset.univ.weightedVsub p w = (0 : V) \u2192 \u2200 i, w i = 0 :=\n  by\n  constructor\n  \u00b7 exact fun h w hw hs i => h Finset.univ w hw hs i (Finset.mem_univ _)\n  \u00b7 intro h s w hw hs i hi\n    rw [Finset.weightedVsub_indicator_subset _ _ (Finset.subset_univ s)] at hs\n    rw [Set.sum_indicator_subset _ (Finset.subset_univ s)] at hw\n    replace h := h ((\u2191s : Set \u03b9).indicator w) hw hs i\n    simpa [hi] using h\n#align affine_independent_iff_of_fintype affineIndependent_iff_of_fintype\n\n/-- A family is affinely independent if and only if the differences\nfrom a base point in that family are linearly independent. -/\ntheorem affineIndependent_iff_linearIndependent_vsub (p : \u03b9 \u2192 P) (i1 : \u03b9) :\n    AffineIndependent k p \u2194 LinearIndependent k fun i : { x // x \u2260 i1 } => (p i -\u1d65 p i1 : V) := by\n  classical\n    constructor\n    \u00b7 intro h\n      rw [linearIndependent_iff']\n      intro s g hg i hi\n      set f : \u03b9 \u2192 k := fun x => if hx : x = i1 then -\u2211 y in s, g y else g \u27e8x, hx\u27e9 with hfdef\n      let s2 : Finset \u03b9 := insert i1 (s.map (embedding.subtype _))\n      have hfg : \u2200 x : { x // x \u2260 i1 }, g x = f x :=\n        by\n        intro x\n        rw [hfdef]\n        dsimp only\n        erw [dif_neg x.property, Subtype.coe_eta]\n      rw [hfg]\n      have hf : (\u2211 \u03b9 in s2, f \u03b9) = 0 :=\n        by\n        rw [Finset.sum_insert\n            (Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)),\n          Finset.sum_subtype_map_embedding fun x hx => (hfg x).symm]\n        rw [hfdef]\n        dsimp only\n        rw [dif_pos rfl]\n        exact neg_add_self _\n      have hs2 : s2.weighted_vsub p f = (0 : V) :=\n        by\n        set f2 : \u03b9 \u2192 V := fun x => f x \u2022 (p x -\u1d65 p i1) with hf2def\n        set g2 : { x // x \u2260 i1 } \u2192 V := fun x => g x \u2022 (p x -\u1d65 p i1) with hg2def\n        have hf2g2 : \u2200 x : { x // x \u2260 i1 }, f2 x = g2 x :=\n          by\n          simp_rw [hf2def, hg2def, hfg]\n          exact fun x => rfl\n        rw [Finset.weightedVsub_eq_weightedVsubOfPoint_of_sum_eq_zero s2 f p hf (p i1),\n          Finset.weightedVsubOfPoint_insert, Finset.weightedVsubOfPoint_apply,\n          Finset.sum_subtype_map_embedding fun x hx => hf2g2 x]\n        exact hg\n      exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 \u27e8i, hi, rfl\u27e9))\n    \u00b7 intro h\n      rw [linearIndependent_iff'] at h\n      intro s w hw hs i hi\n      rw [Finset.weightedVsub_eq_weightedVsubOfPoint_of_sum_eq_zero s w p hw (p i1), \u2190\n        s.weighted_vsub_of_point_erase w p i1, Finset.weightedVsubOfPoint_apply] at hs\n      let f : \u03b9 \u2192 V := fun i => w i \u2022 (p i -\u1d65 p i1)\n      have hs2 : (\u2211 i in (s.erase i1).Subtype fun i => i \u2260 i1, f i) = 0 :=\n        by\n        rw [\u2190 hs]\n        convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase\n      have h2 := h ((s.erase i1).Subtype fun i => i \u2260 i1) (fun x => w x) hs2\n      simp_rw [Finset.mem_subtype] at h2\n      have h2b : \u2200 i \u2208 s, i \u2260 i1 \u2192 w i = 0 := fun i his hi =>\n        h2 \u27e8i, hi\u27e9 (Finset.mem_erase_of_ne_of_mem hi his)\n      exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi\n#align affine_independent_iff_linear_independent_vsub affineIndependent_iff_linearIndependent_vsub\n\n/-- A set is affinely independent if and only if the differences from\na base point in that set are linearly independent. -/\ntheorem affineIndependent_set_iff_linearIndependent_vsub {s : Set P} {p\u2081 : P} (hp\u2081 : p\u2081 \u2208 s) :\n    AffineIndependent k (fun p => p : s \u2192 P) \u2194\n      LinearIndependent k (fun v => v : (fun p => (p -\u1d65 p\u2081 : V)) '' (s \\ {p\u2081}) \u2192 V) :=\n  by\n  rw [affineIndependent_iff_linearIndependent_vsub k (fun p => p : s \u2192 P) \u27e8p\u2081, hp\u2081\u27e9]\n  constructor\n  \u00b7 intro h\n    have hv : \u2200 v : (fun p => (p -\u1d65 p\u2081 : V)) '' (s \\ {p\u2081}), (v : V) +\u1d65 p\u2081 \u2208 s \\ {p\u2081} := fun v =>\n      (vsub_left_injective p\u2081).mem_set_image.1 ((vadd_vsub (v : V) p\u2081).symm \u25b8 v.property)\n    let f : (fun p : P => (p -\u1d65 p\u2081 : V)) '' (s \\ {p\u2081}) \u2192 { x : s // x \u2260 \u27e8p\u2081, hp\u2081\u27e9 } := fun x =>\n      \u27e8\u27e8(x : V) +\u1d65 p\u2081, Set.mem_of_mem_diff (hv x)\u27e9, fun hx =>\n        Set.not_mem_of_mem_diff (hv x) (Subtype.ext_iff.1 hx)\u27e9\n    convert h.comp f fun x1 x2 hx =>\n        Subtype.ext (vadd_right_cancel p\u2081 (Subtype.ext_iff.1 (Subtype.ext_iff.1 hx)))\n    ext v\n    exact (vadd_vsub (v : V) p\u2081).symm\n  \u00b7 intro h\n    let f : { x : s // x \u2260 \u27e8p\u2081, hp\u2081\u27e9 } \u2192 (fun p : P => (p -\u1d65 p\u2081 : V)) '' (s \\ {p\u2081}) := fun x =>\n      \u27e8((x : s) : P) -\u1d65 p\u2081, \u27e8x, \u27e8\u27e8(x : s).property, fun hx => x.property (Subtype.ext hx)\u27e9, rfl\u27e9\u27e9\u27e9\n    convert h.comp f fun x1 x2 hx =>\n        Subtype.ext (Subtype.ext (vsub_left_cancel (Subtype.ext_iff.1 hx)))\n#align affine_independent_set_iff_linear_independent_vsub affineIndependent_set_iff_linearIndependent_vsub\n\n/-- A set of nonzero vectors is linearly independent if and only if,\ngiven a point `p\u2081`, the vectors added to `p\u2081` and `p\u2081` itself are\naffinely independent. -/\ntheorem linearIndependent_set_iff_affineIndependent_vadd_union_singleton {s : Set V}\n    (hs : \u2200 v \u2208 s, v \u2260 (0 : V)) (p\u2081 : P) :\n    LinearIndependent k (fun v => v : s \u2192 V) \u2194\n      AffineIndependent k (fun p => p : {p\u2081} \u222a (fun v => v +\u1d65 p\u2081) '' s \u2192 P) :=\n  by\n  rw [affineIndependent_set_iff_linearIndependent_vsub k\n      (Set.mem_union_left _ (Set.mem_singleton p\u2081))]\n  have h : (fun p => (p -\u1d65 p\u2081 : V)) '' (({p\u2081} \u222a (fun v => v +\u1d65 p\u2081) '' s) \\ {p\u2081}) = s :=\n    by\n    simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p\u2081), Set.image_image,\n      Set.image_singleton, vsub_self, vadd_vsub, Set.image_id']\n    exact Set.diff_singleton_eq_self fun h => hs 0 h rfl\n  rw [h]\n#align linear_independent_set_iff_affine_independent_vadd_union_singleton linearIndependent_set_iff_affineIndependent_vadd_union_singleton\n\n/-- A family is affinely independent if and only if any affine\ncombinations (with sum of weights 1) that evaluate to the same point\nhave equal `set.indicator`. -/\ntheorem affineIndependent_iff_indicator_eq_of_affineCombination_eq (p : \u03b9 \u2192 P) :\n    AffineIndependent k p \u2194\n      \u2200 (s1 s2 : Finset \u03b9) (w1 w2 : \u03b9 \u2192 k),\n        (\u2211 i in s1, w1 i) = 1 \u2192\n          (\u2211 i in s2, w2 i) = 1 \u2192\n            s1.affineCombination k p w1 = s2.affineCombination k p w2 \u2192\n              Set.indicator (\u2191s1) w1 = Set.indicator (\u2191s2) w2 :=\n  by\n  classical\n    constructor\n    \u00b7 intro ha s1 s2 w1 w2 hw1 hw2 heq\n      ext i\n      by_cases hi : i \u2208 s1 \u222a s2\n      \u00b7 rw [\u2190 sub_eq_zero]\n        rw [Set.sum_indicator_subset _ (Finset.subset_union_left s1 s2)] at hw1\n        rw [Set.sum_indicator_subset _ (Finset.subset_union_right s1 s2)] at hw2\n        have hws : (\u2211 i in s1 \u222a s2, (Set.indicator (\u2191s1) w1 - Set.indicator (\u2191s2) w2) i) = 0 := by\n          simp [hw1, hw2]\n        rw [Finset.affineCombination_indicator_subset _ _ (Finset.subset_union_left s1 s2),\n          Finset.affineCombination_indicator_subset _ _ (Finset.subset_union_right s1 s2), \u2190\n          @vsub_eq_zero_iff_eq V, Finset.affineCombination_vsub] at heq\n        exact ha (s1 \u222a s2) (Set.indicator (\u2191s1) w1 - Set.indicator (\u2191s2) w2) hws HEq i hi\n      \u00b7 rw [\u2190 Finset.mem_coe, Finset.coe_union] at hi\n        simp [mt (Set.mem_union_left \u2191s2) hi, mt (Set.mem_union_right \u2191s1) hi]\n    \u00b7 intro ha s w hw hs i0 hi0\n      let w1 : \u03b9 \u2192 k := Function.update (Function.const \u03b9 0) i0 1\n      have hw1 : (\u2211 i in s, w1 i) = 1 := by\n        rw [Finset.sum_update_of_mem hi0, Finset.sum_const_zero, add_zero]\n      have hw1s : s.affine_combination k p w1 = p i0 :=\n        s.affine_combination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_same _ _ _)\n          fun _ _ hne => Function.update_noteq hne _ _\n      let w2 := w + w1\n      have hw2 : (\u2211 i in s, w2 i) = 1 := by simp [w2, Finset.sum_add_distrib, hw, hw1]\n      have hw2s : s.affine_combination k p w2 = p i0 := by\n        simp [w2, \u2190 Finset.weightedVsub_vadd_affineCombination, hs, hw1s]\n      replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm \u25b8 hw2s)\n      have hws : w2 i0 - w1 i0 = 0 := by\n        rw [\u2190 Finset.mem_coe] at hi0\n        rw [\u2190 Set.indicator_of_mem hi0 w2, \u2190 Set.indicator_of_mem hi0 w1, ha, sub_self]\n      simpa [w2] using hws\n#align affine_independent_iff_indicator_eq_of_affine_combination_eq affineIndependent_iff_indicator_eq_of_affineCombination_eq\n\n/-- A finite family is affinely independent if and only if any affine\ncombinations (with sum of weights 1) that evaluate to the same point are equal. -/\ntheorem affineIndependent_iff_eq_of_fintype_affineCombination_eq [Fintype \u03b9] (p : \u03b9 \u2192 P) :\n    AffineIndependent k p \u2194\n      \u2200 w1 w2 : \u03b9 \u2192 k,\n        (\u2211 i, w1 i) = 1 \u2192\n          (\u2211 i, w2 i) = 1 \u2192\n            Finset.univ.affineCombination k p w1 = Finset.univ.affineCombination k p w2 \u2192 w1 = w2 :=\n  by\n  rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq]\n  constructor\n  \u00b7 intro h w1 w2 hw1 hw2 hweq\n    simpa only [Set.indicator_univ, Finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq\n  \u00b7 intro h s1 s2 w1 w2 hw1 hw2 hweq\n    have hw1' : (\u2211 i, (s1 : Set \u03b9).indicator w1 i) = 1 := by\n      rwa [Set.sum_indicator_subset _ (Finset.subset_univ s1)] at hw1\n    have hw2' : (\u2211 i, (s2 : Set \u03b9).indicator w2 i) = 1 := by\n      rwa [Set.sum_indicator_subset _ (Finset.subset_univ s2)] at hw2\n    rw [Finset.affineCombination_indicator_subset w1 p (Finset.subset_univ s1),\n      Finset.affineCombination_indicator_subset w2 p (Finset.subset_univ s2)] at hweq\n    exact h _ _ hw1' hw2' hweq\n#align affine_independent_iff_eq_of_fintype_affine_combination_eq affineIndependent_iff_eq_of_fintype_affineCombination_eq\n\nvariable {k}\n\n/-- If we single out one member of an affine-independent family of points and affinely transport\nall others along the line joining them to this member, the resulting new family of points is affine-\nindependent.\n\nThis is the affine version of `linear_independent.units_smul`. -/\ntheorem AffineIndependent.units_lineMap {p : \u03b9 \u2192 P} (hp : AffineIndependent k p) (j : \u03b9)\n    (w : \u03b9 \u2192 Units k) : AffineIndependent k fun i => AffineMap.lineMap (p j) (p i) (w i : k) :=\n  by\n  rw [affineIndependent_iff_linearIndependent_vsub k _ j] at hp\u22a2\n  simp only [AffineMap.lineMap_vsub_left, AffineMap.coe_const, AffineMap.lineMap_same]\n  exact hp.units_smul fun i => w i\n#align affine_independent.units_line_map AffineIndependent.units_lineMap\n\ntheorem AffineIndependent.indicator_eq_of_affineCombination_eq {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k p) (s\u2081 s\u2082 : Finset \u03b9) (w\u2081 w\u2082 : \u03b9 \u2192 k) (hw\u2081 : (\u2211 i in s\u2081, w\u2081 i) = 1)\n    (hw\u2082 : (\u2211 i in s\u2082, w\u2082 i) = 1) (h : s\u2081.affineCombination k p w\u2081 = s\u2082.affineCombination k p w\u2082) :\n    Set.indicator (\u2191s\u2081) w\u2081 = Set.indicator (\u2191s\u2082) w\u2082 :=\n  (affineIndependent_iff_indicator_eq_of_affineCombination_eq k p).1 ha s\u2081 s\u2082 w\u2081 w\u2082 hw\u2081 hw\u2082 h\n#align affine_independent.indicator_eq_of_affine_combination_eq AffineIndependent.indicator_eq_of_affineCombination_eq\n\n/-- An affinely independent family is injective, if the underlying\nring is nontrivial. -/\nprotected theorem AffineIndependent.injective [Nontrivial k] {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k p) : Function.Injective p :=\n  by\n  intro i j hij\n  rw [affineIndependent_iff_linearIndependent_vsub _ _ j] at ha\n  by_contra hij'\n  exact ha.ne_zero \u27e8i, hij'\u27e9 (vsub_eq_zero_iff_eq.mpr hij)\n#align affine_independent.injective AffineIndependent.injective\n\n/-- If a family is affinely independent, so is any subfamily given by\ncomposition of an embedding into index type with the original\nfamily. -/\ntheorem AffineIndependent.comp_embedding {\u03b92 : Type _} (f : \u03b92 \u21aa \u03b9) {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k p) : AffineIndependent k (p \u2218 f) := by\n  classical\n    intro fs w hw hs i0 hi0\n    let fs' := fs.map f\n    let w' i := if h : \u2203 i2, f i2 = i then w h.some else 0\n    have hw' : \u2200 i2 : \u03b92, w' (f i2) = w i2 := by\n      intro i2\n      have h : \u2203 i : \u03b92, f i = f i2 := \u27e8i2, rfl\u27e9\n      have hs : h.some = i2 := f.injective h.some_spec\n      simp_rw [w', dif_pos h, hs]\n    have hw's : (\u2211 i in fs', w' i) = 0 :=\n      by\n      rw [\u2190 hw, Finset.sum_map]\n      simp [hw']\n    have hs' : fs'.weighted_vsub p w' = (0 : V) :=\n      by\n      rw [\u2190 hs, Finset.weightedVsub_map]\n      congr with i\n      simp [hw']\n    rw [\u2190 ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw']\n#align affine_independent.comp_embedding AffineIndependent.comp_embedding\n\n/-- If a family is affinely independent, so is any subfamily indexed\nby a subtype of the index type. -/\nprotected theorem AffineIndependent.subtype {p : \u03b9 \u2192 P} (ha : AffineIndependent k p) (s : Set \u03b9) :\n    AffineIndependent k fun i : s => p i :=\n  ha.comp_embedding (Embedding.subtype _)\n#align affine_independent.subtype AffineIndependent.subtype\n\n/-- If an indexed family of points is affinely independent, so is the\ncorresponding set of points. -/\nprotected theorem AffineIndependent.range {p : \u03b9 \u2192 P} (ha : AffineIndependent k p) :\n    AffineIndependent k (fun x => x : Set.range p \u2192 P) :=\n  by\n  let f : Set.range p \u2192 \u03b9 := fun x => x.property.some\n  have hf : \u2200 x, p (f x) = x := fun x => x.property.some_spec\n  let fe : Set.range p \u21aa \u03b9 := \u27e8f, fun x\u2081 x\u2082 he => Subtype.ext (hf x\u2081 \u25b8 hf x\u2082 \u25b8 he \u25b8 rfl)\u27e9\n  convert ha.comp_embedding fe\n  ext\n  simp [hf]\n#align affine_independent.range AffineIndependent.range\n\ntheorem affineIndependent_equiv {\u03b9' : Type _} (e : \u03b9 \u2243 \u03b9') {p : \u03b9' \u2192 P} :\n    AffineIndependent k (p \u2218 e) \u2194 AffineIndependent k p :=\n  by\n  refine' \u27e8_, AffineIndependent.comp_embedding e.to_embedding\u27e9\n  intro h\n  have : p = p \u2218 e \u2218 e.symm.to_embedding := by\n    ext\n    simp\n  rw [this]\n  exact h.comp_embedding e.symm.to_embedding\n#align affine_independent_equiv affineIndependent_equiv\n\n/-- If a set of points is affinely independent, so is any subset. -/\nprotected theorem AffineIndependent.mono {s t : Set P}\n    (ha : AffineIndependent k (fun x => x : t \u2192 P)) (hs : s \u2286 t) :\n    AffineIndependent k (fun x => x : s \u2192 P) :=\n  ha.comp_embedding (s.embeddingOfSubset t hs)\n#align affine_independent.mono AffineIndependent.mono\n\n/-- If the range of an injective indexed family of points is affinely\nindependent, so is that family. -/\ntheorem AffineIndependent.of_set_of_injective {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k (fun x => x : Set.range p \u2192 P)) (hi : Function.Injective p) :\n    AffineIndependent k p :=\n  ha.comp_embedding\n    (\u27e8fun i => \u27e8p i, Set.mem_range_self _\u27e9, fun x y h => hi (Subtype.mk_eq_mk.1 h)\u27e9 :\n      \u03b9 \u21aa Set.range p)\n#align affine_independent.of_set_of_injective AffineIndependent.of_set_of_injective\n\nsection Composition\n\nvariable {V\u2082 P\u2082 : Type _} [AddCommGroup V\u2082] [Module k V\u2082] [affine_space V\u2082 P\u2082]\n\ninclude V\u2082\n\n/-- If the image of a family of points in affine space under an affine transformation is affine-\nindependent, then the original family of points is also affine-independent. -/\ntheorem AffineIndependent.of_comp {p : \u03b9 \u2192 P} (f : P \u2192\u1d43[k] P\u2082) (hai : AffineIndependent k (f \u2218 p)) :\n    AffineIndependent k p := by\n  cases' isEmpty_or_nonempty \u03b9 with h h;\n  \u00b7 haveI := h\n    apply affineIndependent_of_subsingleton\n  obtain \u27e8i\u27e9 := h\n  rw [affineIndependent_iff_linearIndependent_vsub k p i]\n  simp_rw [affineIndependent_iff_linearIndependent_vsub k (f \u2218 p) i, Function.comp_apply, \u2190\n    f.linear_map_vsub] at hai\n  exact LinearIndependent.of_comp f.linear hai\n#align affine_independent.of_comp AffineIndependent.of_comp\n\n/-- The image of a family of points in affine space, under an injective affine transformation, is\naffine-independent. -/\ntheorem AffineIndependent.map' {p : \u03b9 \u2192 P} (hai : AffineIndependent k p) (f : P \u2192\u1d43[k] P\u2082)\n    (hf : Function.Injective f) : AffineIndependent k (f \u2218 p) :=\n  by\n  cases' isEmpty_or_nonempty \u03b9 with h h\n  \u00b7 haveI := h\n    apply affineIndependent_of_subsingleton\n  obtain \u27e8i\u27e9 := h\n  rw [affineIndependent_iff_linearIndependent_vsub k p i] at hai\n  simp_rw [affineIndependent_iff_linearIndependent_vsub k (f \u2218 p) i, Function.comp_apply, \u2190\n    f.linear_map_vsub]\n  have hf' : f.linear.ker = \u22a5 := by rwa [LinearMap.ker_eq_bot, f.linear_injective_iff]\n  exact LinearIndependent.map' hai f.linear hf'\n#align affine_independent.map' AffineIndependent.map'\n\n/-- Injective affine maps preserve affine independence. -/\ntheorem AffineMap.affineIndependent_iff {p : \u03b9 \u2192 P} (f : P \u2192\u1d43[k] P\u2082) (hf : Function.Injective f) :\n    AffineIndependent k (f \u2218 p) \u2194 AffineIndependent k p :=\n  \u27e8AffineIndependent.of_comp f, fun hai => AffineIndependent.map' hai f hf\u27e9\n#align affine_map.affine_independent_iff AffineMap.affineIndependent_iff\n\n/-- Affine equivalences preserve affine independence of families of points. -/\ntheorem AffineEquiv.affineIndependent_iff {p : \u03b9 \u2192 P} (e : P \u2243\u1d43[k] P\u2082) :\n    AffineIndependent k (e \u2218 p) \u2194 AffineIndependent k p :=\n  e.toAffineMap.affineIndependent_iff e.toEquiv.Injective\n#align affine_equiv.affine_independent_iff AffineEquiv.affineIndependent_iff\n\n/-- Affine equivalences preserve affine independence of subsets. -/\ntheorem AffineEquiv.affineIndependent_set_of_eq_iff {s : Set P} (e : P \u2243\u1d43[k] P\u2082) :\n    AffineIndependent k (coe : e '' s \u2192 P\u2082) \u2194 AffineIndependent k (coe : s \u2192 P) :=\n  by\n  have : e \u2218 (coe : s \u2192 P) = (coe : e '' s \u2192 P\u2082) \u2218 (e : P \u2243 P\u2082).image s := rfl\n  rw [\u2190 e.affine_independent_iff, this, affineIndependent_equiv]\n#align affine_equiv.affine_independent_set_of_eq_iff AffineEquiv.affineIndependent_set_of_eq_iff\n\nend Composition\n\n/-- If a family is affinely independent, and the spans of points\nindexed by two subsets of the index type have a point in common, those\nsubsets of the index type have an element in common, if the underlying\nring is nontrivial. -/\ntheorem AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan [Nontrivial k] {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k p) {s1 s2 : Set \u03b9} {p0 : P} (hp0s1 : p0 \u2208 affineSpan k (p '' s1))\n    (hp0s2 : p0 \u2208 affineSpan k (p '' s2)) : \u2203 i : \u03b9, i \u2208 s1 \u2229 s2 :=\n  by\n  rw [Set.image_eq_range] at hp0s1 hp0s2\n  rw [mem_affineSpan_iff_eq_affineCombination, \u2190\n    Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype] at hp0s1 hp0s2\n  rcases hp0s1 with \u27e8fs1, hfs1, w1, hw1, hp0s1\u27e9\n  rcases hp0s2 with \u27e8fs2, hfs2, w2, hw2, hp0s2\u27e9\n  rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] at ha\n  replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 \u25b8 hp0s2)\n  have hnz : (\u2211 i in fs1, w1 i) \u2260 0 := hw1.symm \u25b8 one_ne_zero\n  rcases Finset.exists_ne_zero_of_sum_ne_zero hnz with \u27e8i, hifs1, hinz\u27e9\n  simp_rw [\u2190 Set.indicator_of_mem (Finset.mem_coe.2 hifs1) w1, ha] at hinz\n  use i, hfs1 hifs1, hfs2 (Set.mem_of_indicator_ne_zero hinz)\n#align affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan\n\n/-- If a family is affinely independent, the spans of points indexed\nby disjoint subsets of the index type are disjoint, if the underlying\nring is nontrivial. -/\ntheorem AffineIndependent.affineSpan_disjoint_of_disjoint [Nontrivial k] {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k p) {s1 s2 : Set \u03b9} (hd : Disjoint s1 s2) :\n    Disjoint (affineSpan k (p '' s1) : Set P) (affineSpan k (p '' s2)) :=\n  by\n  refine' Set.disjoint_left.2 fun p0 hp0s1 hp0s2 => _\n  cases' ha.exists_mem_inter_of_exists_mem_inter_affine_span hp0s1 hp0s2 with i hi\n  exact Set.disjoint_iff.1 hd hi\n#align affine_independent.affine_span_disjoint_of_disjoint AffineIndependent.affineSpan_disjoint_of_disjoint\n\n/-- If a family is affinely independent, a point in the family is in\nthe span of some of the points given by a subset of the index type if\nand only if that point's index is in the subset, if the underlying\nring is nontrivial. -/\n@[simp]\nprotected theorem AffineIndependent.mem_affineSpan_iff [Nontrivial k] {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k p) (i : \u03b9) (s : Set \u03b9) : p i \u2208 affineSpan k (p '' s) \u2194 i \u2208 s :=\n  by\n  constructor\n  \u00b7 intro hs\n    have h :=\n      AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan ha hs\n        (mem_affineSpan k (Set.mem_image_of_mem _ (Set.mem_singleton _)))\n    rwa [\u2190 Set.nonempty_def, Set.inter_singleton_nonempty] at h\n  \u00b7 exact fun h => mem_affineSpan k (Set.mem_image_of_mem p h)\n#align affine_independent.mem_affine_span_iff AffineIndependent.mem_affineSpan_iff\n\n/-- If a family is affinely independent, a point in the family is not\nin the affine span of the other points, if the underlying ring is\nnontrivial. -/\ntheorem AffineIndependent.not_mem_affineSpan_diff [Nontrivial k] {p : \u03b9 \u2192 P}\n    (ha : AffineIndependent k p) (i : \u03b9) (s : Set \u03b9) : p i \u2209 affineSpan k (p '' (s \\ {i})) := by\n  simp [ha]\n#align affine_independent.not_mem_affine_span_diff AffineIndependent.not_mem_affineSpan_diff\n\ntheorem exists_nontrivial_relation_sum_zero_of_not_affine_ind {t : Finset V}\n    (h : \u00acAffineIndependent k (coe : t \u2192 V)) :\n    \u2203 f : V \u2192 k, (\u2211 e in t, f e \u2022 e) = 0 \u2227 (\u2211 e in t, f e) = 0 \u2227 \u2203 x \u2208 t, f x \u2260 0 := by\n  classical\n    rw [affineIndependent_iff_of_fintype] at h\n    simp only [exists_prop, not_forall] at h\n    obtain \u27e8w, hw, hwt, i, hi\u27e9 := h\n    simp only [Finset.weightedVsub_eq_weightedVsubOfPoint_of_sum_eq_zero _ w (coe : t \u2192 V) hw 0,\n      vsub_eq_sub, Finset.weightedVsubOfPoint_apply, sub_zero] at hwt\n    let f : \u2200 x : V, x \u2208 t \u2192 k := fun x hx => w \u27e8x, hx\u27e9\n    refine'\n      \u27e8fun x => if hx : x \u2208 t then f x hx else (0 : k), _, _,\n        by\n        use i\n        simp [hi, f]\u27e9\n    suffices (\u2211 e : V in t, dite (e \u2208 t) (fun hx => f e hx \u2022 e) fun hx => 0) = 0\n      by\n      convert this\n      ext\n      by_cases hx : x \u2208 t <;> simp [hx]\n    all_goals\n      simp only [Finset.sum_dite_of_true fun x h => h, Subtype.val_eq_coe, Finset.mk_coe, f, hwt,\n        hw]\n#align exists_nontrivial_relation_sum_zero_of_not_affine_ind exists_nontrivial_relation_sum_zero_of_not_affine_ind\n\n/-- Viewing a module as an affine space modelled on itself, we can characterise affine independence\nin terms of linear combinations. -/\ntheorem affineIndependent_iff {\u03b9} {p : \u03b9 \u2192 V} :\n    AffineIndependent k p \u2194\n      \u2200 (s : Finset \u03b9) (w : \u03b9 \u2192 k), s.Sum w = 0 \u2192 (\u2211 e in s, w e \u2022 p e) = 0 \u2192 \u2200 e \u2208 s, w e = 0 :=\n  forall\u2083_congr fun s w hw => by simp [s.weighted_vsub_eq_linear_combination hw]\n#align affine_independent_iff affineIndependent_iff\n\n/-- Given an affinely independent family of points, a weighted subtraction lies in the\n`vector_span` of two points given as affine combinations if and only if it is a weighted\nsubtraction with weights a multiple of the difference between the weights of the two points. -/\ntheorem weightedVsub_mem_vectorSpan_pair {p : \u03b9 \u2192 P} (h : AffineIndependent k p) {w w\u2081 w\u2082 : \u03b9 \u2192 k}\n    {s : Finset \u03b9} (hw : (\u2211 i in s, w i) = 0) (hw\u2081 : (\u2211 i in s, w\u2081 i) = 1)\n    (hw\u2082 : (\u2211 i in s, w\u2082 i) = 1) :\n    s.weightedVsub p w \u2208\n        vectorSpan k ({s.affineCombination k p w\u2081, s.affineCombination k p w\u2082} : Set P) \u2194\n      \u2203 r : k, \u2200 i \u2208 s, w i = r * (w\u2081 i - w\u2082 i) :=\n  by\n  rw [mem_vectorSpan_pair]\n  refine' \u27e8fun h => _, fun h => _\u27e9\n  \u00b7 rcases h with \u27e8r, hr\u27e9\n    refine' \u27e8r, fun i hi => _\u27e9\n    rw [s.affine_combination_vsub, \u2190 s.weighted_vsub_const_smul, \u2190 sub_eq_zero, \u2190 map_sub] at hr\n    have hw' : (\u2211 j in s, (r \u2022 (w\u2081 - w\u2082) - w) j) = 0 := by\n      simp_rw [Pi.sub_apply, Pi.smul_apply, Pi.sub_apply, smul_sub, Finset.sum_sub_distrib, \u2190\n        Finset.smul_sum, hw, hw\u2081, hw\u2082, sub_self]\n    have hr' := h s _ hw' hr i hi\n    rw [eq_comm, \u2190 sub_eq_zero, \u2190 smul_eq_mul]\n    exact hr'\n  \u00b7 rcases h with \u27e8r, hr\u27e9\n    refine' \u27e8r, _\u27e9\n    let w' i := r * (w\u2081 i - w\u2082 i)\n    change \u2200 i \u2208 s, w i = w' i at hr\n    rw [s.weighted_vsub_congr hr fun _ _ => rfl, s.affine_combination_vsub, \u2190\n      s.weighted_vsub_const_smul]\n    congr\n#align weighted_vsub_mem_vector_span_pair weightedVsub_mem_vectorSpan_pair\n\n/-- Given an affinely independent family of points, an affine combination lies in the\nspan of two points given as affine combinations if and only if it is an affine combination\nwith weights those of one point plus a multiple of the difference between the weights of the\ntwo points. -/\ntheorem affineCombination_mem_affineSpan_pair {p : \u03b9 \u2192 P} (h : AffineIndependent k p)\n    {w w\u2081 w\u2082 : \u03b9 \u2192 k} {s : Finset \u03b9} (hw : (\u2211 i in s, w i) = 1) (hw\u2081 : (\u2211 i in s, w\u2081 i) = 1)\n    (hw\u2082 : (\u2211 i in s, w\u2082 i) = 1) :\n    s.affineCombination k p w \u2208 line[k, s.affineCombination k p w\u2081, s.affineCombination k p w\u2082] \u2194\n      \u2203 r : k, \u2200 i \u2208 s, w i = r * (w\u2082 i - w\u2081 i) + w\u2081 i :=\n  by\n  rw [\u2190 vsub_vadd (s.affine_combination k p w) (s.affine_combination k p w\u2081),\n    AffineSubspace.vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _),\n    direction_affineSpan, s.affine_combination_vsub, Set.pair_comm,\n    weightedVsub_mem_vectorSpan_pair h _ hw\u2082 hw\u2081]\n  \u00b7 simp only [Pi.sub_apply, sub_eq_iff_eq_add]\n  \u00b7 simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, hw, hw\u2081, sub_self]\n#align affine_combination_mem_affine_span_pair affineCombination_mem_affineSpan_pair\n\nend AffineIndependent\n\nsection DivisionRing\n\nvariable {k : Type _} {V : Type _} {P : Type _} [DivisionRing k] [AddCommGroup V] [Module k V]\n\nvariable [affine_space V P] {\u03b9 : Type _}\n\ninclude V\n\n/-- An affinely independent set of points can be extended to such a\nset that spans the whole space. -/\ntheorem exists_subset_affineIndependent_affineSpan_eq_top {s : Set P}\n    (h : AffineIndependent k (fun p => p : s \u2192 P)) :\n    \u2203 t : Set P, s \u2286 t \u2227 AffineIndependent k (fun p => p : t \u2192 P) \u2227 affineSpan k t = \u22a4 :=\n  by\n  rcases s.eq_empty_or_nonempty with (rfl | \u27e8p\u2081, hp\u2081\u27e9)\n  \u00b7 have p\u2081 : P := add_torsor.nonempty.some\n    let hsv := Basis.ofVectorSpace k V\n    have hsvi := hsv.linear_independent\n    have hsvt := hsv.span_eq\n    rw [Basis.coe_ofVectorSpace] at hsvi hsvt\n    have h0 : \u2200 v : V, v \u2208 Basis.ofVectorSpaceIndex _ _ \u2192 v \u2260 0 :=\n      by\n      intro v hv\n      simpa using hsv.ne_zero \u27e8v, hv\u27e9\n    rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p\u2081] at hsvi\n    exact\n      \u27e8{p\u2081} \u222a (fun v => v +\u1d65 p\u2081) '' _, Set.empty_subset _, hsvi,\n        affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p\u2081 hsvt\u27e9\n  \u00b7 rw [affineIndependent_set_iff_linearIndependent_vsub k hp\u2081] at h\n    let bsv := Basis.extend h\n    have hsvi := bsv.linear_independent\n    have hsvt := bsv.span_eq\n    rw [Basis.coe_extend] at hsvi hsvt\n    have hsv := h.subset_extend (Set.subset_univ _)\n    have h0 : \u2200 v : V, v \u2208 h.extend _ \u2192 v \u2260 0 :=\n      by\n      intro v hv\n      simpa using bsv.ne_zero \u27e8v, hv\u27e9\n    rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p\u2081] at hsvi\n    refine' \u27e8{p\u2081} \u222a (fun v => v +\u1d65 p\u2081) '' h.extend (Set.subset_univ _), _, _\u27e9\n    \u00b7 refine' Set.Subset.trans _ (Set.union_subset_union_right _ (Set.image_subset _ hsv))\n      simp [Set.image_image]\n    \u00b7 use hsvi, affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p\u2081 hsvt\n#align exists_subset_affine_independent_affine_span_eq_top exists_subset_affineIndependent_affineSpan_eq_top\n\nvariable (k V)\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (t \u00abexpr \u2286 \u00bb s) -/\ntheorem exists_affineIndependent (s : Set P) :\n    \u2203 (t : _)(_ : t \u2286 s), affineSpan k t = affineSpan k s \u2227 AffineIndependent k (coe : t \u2192 P) :=\n  by\n  rcases s.eq_empty_or_nonempty with (rfl | \u27e8p, hp\u27e9)\n  \u00b7 exact \u27e8\u2205, Set.empty_subset \u2205, rfl, affineIndependent_of_subsingleton k _\u27e9\n  obtain \u27e8b, hb\u2081, hb\u2082, hb\u2083\u27e9 := exists_linearIndependent k ((Equiv.vaddConst p).symm '' s)\n  have hb\u2080 : \u2200 v : V, v \u2208 b \u2192 v \u2260 0 := fun v hv => hb\u2083.ne_zero (\u27e8v, hv\u27e9 : b)\n  rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k hb\u2080 p] at hb\u2083\n  refine' \u27e8{p} \u222a Equiv.vaddConst p '' b, _, _, hb\u2083\u27e9\n  \u00b7 apply Set.union_subset (set.singleton_subset_iff.mpr hp)\n    rwa [\u2190 (Equiv.vaddConst p).subset_image' b s]\n  \u00b7 rw [Equiv.coe_vaddConst_symm, \u2190 vectorSpan_eq_span_vsub_set_right k hp] at hb\u2082\n    apply AffineSubspace.ext_of_direction_eq\n    \u00b7 have : Submodule.span k b = Submodule.span k (insert 0 b) := by simp\n      simp only [direction_affineSpan, \u2190 hb\u2082, Equiv.coe_vaddConst, Set.singleton_union,\n        vectorSpan_eq_span_vsub_set_right k (Set.mem_insert p _), this]\n      congr\n      change (Equiv.vaddConst p).symm '' insert p (Equiv.vaddConst p '' b) = _\n      rw [Set.image_insert_eq, \u2190 Set.image_comp]\n      simp\n    \u00b7 use p\n      simp only [Equiv.coe_vaddConst, Set.singleton_union, Set.mem_inter_iff, coe_affineSpan]\n      exact \u27e8mem_spanPoints k _ _ (Set.mem_insert p _), mem_spanPoints k _ _ hp\u27e9\n#align exists_affine_independent exists_affineIndependent\n\nvariable (k) {V P}\n\n/-- Two different points are affinely independent. -/\ntheorem affineIndependent_of_ne {p\u2081 p\u2082 : P} (h : p\u2081 \u2260 p\u2082) : AffineIndependent k ![p\u2081, p\u2082] :=\n  by\n  rw [affineIndependent_iff_linearIndependent_vsub k ![p\u2081, p\u2082] 0]\n  let i\u2081 : { x // x \u2260 (0 : Fin 2) } := \u27e81, by norm_num\u27e9\n  have he' : \u2200 i, i = i\u2081 := by\n    rintro \u27e8i, hi\u27e9\n    ext\n    fin_cases i\n    \u00b7 simpa using hi\n  haveI : Unique { x // x \u2260 (0 : Fin 2) } := \u27e8\u27e8i\u2081\u27e9, he'\u27e9\n  have hz : (![p\u2081, p\u2082] \u2191default -\u1d65 ![p\u2081, p\u2082] 0 : V) \u2260 0 :=\n    by\n    rw [he' default]\n    simpa using h.symm\n  exact linearIndependent_unique _ hz\n#align affine_independent_of_ne affineIndependent_of_ne\n\nvariable {k V P}\n\n/-- If all but one point of a family are affinely independent, and that point does not lie in\nthe affine span of that family, the family is affinely independent. -/\ntheorem AffineIndependent.affineIndependent_of_not_mem_span {p : \u03b9 \u2192 P} {i : \u03b9}\n    (ha : AffineIndependent k fun x : { y // y \u2260 i } => p x)\n    (hi : p i \u2209 affineSpan k (p '' { x | x \u2260 i })) : AffineIndependent k p := by\n  classical\n    intro s w hw hs\n    let s' : Finset { y // y \u2260 i } := s.subtype (\u00b7 \u2260 i)\n    let p' : { y // y \u2260 i } \u2192 P := fun x => p x\n    by_cases his : i \u2208 s \u2227 w i \u2260 0\n    \u00b7 refine' False.elim (hi _)\n      let wm : \u03b9 \u2192 k := -(w i)\u207b\u00b9 \u2022 w\n      have hms : s.weighted_vsub p wm = (0 : V) := by simp [wm, hs]\n      have hwm : (\u2211 i in s, wm i) = 0 := by simp [wm, \u2190 Finset.mul_sum, hw]\n      have hwmi : wm i = -1 := by simp [wm, his.2]\n      let w' : { y // y \u2260 i } \u2192 k := fun x => wm x\n      have hw' : (\u2211 x in s', w' x) = 1 :=\n        by\n        simp_rw [w', Finset.sum_subtype_eq_sum_filter]\n        rw [\u2190 s.sum_filter_add_sum_filter_not (\u00b7 \u2260 i)] at hwm\n        simp_rw [Classical.not_not, Finset.filter_eq', if_pos his.1, Finset.sum_singleton, \u2190 wm,\n          hwmi, \u2190 sub_eq_add_neg, sub_eq_zero] at hwm\n        exact hwm\n      rw [\u2190 s.affine_combination_eq_of_weighted_vsub_eq_zero_of_eq_neg_one hms his.1 hwmi, \u2190\n        (Subtype.range_coe : _ = { x | x \u2260 i }), \u2190 Set.range_comp, \u2190\n        s.affine_combination_subtype_eq_filter]\n      exact affineCombination_mem_affineSpan hw' p'\n    \u00b7 rw [not_and_or, Classical.not_not] at his\n      let w' : { y // y \u2260 i } \u2192 k := fun x => w x\n      have hw' : (\u2211 x in s', w' x) = 0 :=\n        by\n        simp_rw [Finset.sum_subtype_eq_sum_filter]\n        rw [Finset.sum_filter_of_ne, hw]\n        rintro x hxs hwx rfl\n        exact hwx (his.neg_resolve_left hxs)\n      have hs' : s'.weighted_vsub p' w' = (0 : V) :=\n        by\n        simp_rw [Finset.weightedVsub_subtype_eq_filter]\n        rw [Finset.weightedVsub_filter_of_ne, hs]\n        rintro x hxs hwx rfl\n        exact hwx (his.neg_resolve_left hxs)\n      intro j hj\n      by_cases hji : j = i\n      \u00b7 rw [hji] at hj\n        exact hji.symm \u25b8 his.neg_resolve_left hj\n      \u00b7 exact ha s' w' hw' hs' \u27e8j, hji\u27e9 (Finset.mem_subtype.2 hj)\n#align affine_independent.affine_independent_of_not_mem_span AffineIndependent.affineIndependent_of_not_mem_span\n\n/-- If distinct points `p\u2081` and `p\u2082` lie in `s` but `p\u2083` does not, the three points are affinely\nindependent. -/\ntheorem affineIndependent_of_ne_of_mem_of_mem_of_not_mem {s : AffineSubspace k P} {p\u2081 p\u2082 p\u2083 : P}\n    (hp\u2081p\u2082 : p\u2081 \u2260 p\u2082) (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2208 s) (hp\u2083 : p\u2083 \u2209 s) :\n    AffineIndependent k ![p\u2081, p\u2082, p\u2083] :=\n  by\n  have ha : AffineIndependent k fun x : { x : Fin 3 // x \u2260 2 } => ![p\u2081, p\u2082, p\u2083] x :=\n    by\n    rw [\u2190 affineIndependent_equiv (finSuccAboveEquiv (2 : Fin 3)).toEquiv]\n    convert affineIndependent_of_ne k hp\u2081p\u2082\n    ext x\n    fin_cases x <;> rfl\n  refine' ha.affine_independent_of_not_mem_span _\n  intro h\n  refine' hp\u2083 ((AffineSubspace.le_def' _ s).1 _ p\u2083 h)\n  simp_rw [affineSpan_le, Set.image_subset_iff, Set.subset_def, Set.mem_preimage]\n  intro x\n  fin_cases x <;> simp [hp\u2081, hp\u2082]\n#align affine_independent_of_ne_of_mem_of_mem_of_not_mem affineIndependent_of_ne_of_mem_of_mem_of_not_mem\n\n/-- If distinct points `p\u2081` and `p\u2083` lie in `s` but `p\u2082` does not, the three points are affinely\nindependent. -/\ntheorem affineIndependent_of_ne_of_mem_of_not_mem_of_mem {s : AffineSubspace k P} {p\u2081 p\u2082 p\u2083 : P}\n    (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : p\u2082 \u2209 s) (hp\u2083 : p\u2083 \u2208 s) :\n    AffineIndependent k ![p\u2081, p\u2082, p\u2083] :=\n  by\n  rw [\u2190 affineIndependent_equiv (Equiv.swap (1 : Fin 3) 2)]\n  convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp\u2081p\u2083 hp\u2081 hp\u2083 hp\u2082 using 1\n  ext x\n  fin_cases x <;> rfl\n#align affine_independent_of_ne_of_mem_of_not_mem_of_mem affineIndependent_of_ne_of_mem_of_not_mem_of_mem\n\n/-- If distinct points `p\u2082` and `p\u2083` lie in `s` but `p\u2081` does not, the three points are affinely\nindependent. -/\ntheorem affineIndependent_of_ne_of_not_mem_of_mem_of_mem {s : AffineSubspace k P} {p\u2081 p\u2082 p\u2083 : P}\n    (hp\u2082p\u2083 : p\u2082 \u2260 p\u2083) (hp\u2081 : p\u2081 \u2209 s) (hp\u2082 : p\u2082 \u2208 s) (hp\u2083 : p\u2083 \u2208 s) :\n    AffineIndependent k ![p\u2081, p\u2082, p\u2083] :=\n  by\n  rw [\u2190 affineIndependent_equiv (Equiv.swap (0 : Fin 3) 2)]\n  convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp\u2082p\u2083.symm hp\u2083 hp\u2082 hp\u2081 using 1\n  ext x\n  fin_cases x <;> rfl\n#align affine_independent_of_ne_of_not_mem_of_mem_of_mem affineIndependent_of_ne_of_not_mem_of_mem_of_mem\n\nend DivisionRing\n\nsection Ordered\n\nvariable {k : Type _} {V : Type _} {P : Type _} [LinearOrderedRing k] [AddCommGroup V]\n\nvariable [Module k V] [affine_space V P] {\u03b9 : Type _}\n\ninclude V\n\nattribute [local instance] LinearOrderedRing.decidableLt\n\n/-- Given an affinely independent family of points, suppose that an affine combination lies in\nthe span of two points given as affine combinations, and suppose that, for two indices, the\ncoefficients in the first point in the span are zero and those in the second point in the span\nhave the same sign. Then the coefficients in the combination lying in the span have the same\nsign. -/\ntheorem sign_eq_of_affineCombination_mem_affineSpan_pair {p : \u03b9 \u2192 P} (h : AffineIndependent k p)\n    {w w\u2081 w\u2082 : \u03b9 \u2192 k} {s : Finset \u03b9} (hw : (\u2211 i in s, w i) = 1) (hw\u2081 : (\u2211 i in s, w\u2081 i) = 1)\n    (hw\u2082 : (\u2211 i in s, w\u2082 i) = 1)\n    (hs :\n      s.affineCombination k p w \u2208 line[k, s.affineCombination k p w\u2081, s.affineCombination k p w\u2082])\n    {i j : \u03b9} (hi : i \u2208 s) (hj : j \u2208 s) (hi0 : w\u2081 i = 0) (hj0 : w\u2081 j = 0)\n    (hij : SignType.sign (w\u2082 i) = SignType.sign (w\u2082 j)) :\n    SignType.sign (w i) = SignType.sign (w j) :=\n  by\n  rw [affineCombination_mem_affineSpan_pair h hw hw\u2081 hw\u2082] at hs\n  rcases hs with \u27e8r, hr\u27e9\n  dsimp only at hr\n  rw [hr i hi, hr j hj, hi0, hj0, add_zero, add_zero, sub_zero, sub_zero, sign_mul, sign_mul, hij]\n#align sign_eq_of_affine_combination_mem_affine_span_pair sign_eq_of_affineCombination_mem_affineSpan_pair\n\n/-- Given an affinely independent family of points, suppose that an affine combination lies in\nthe span of one point of that family and a combination of another two points of that family given\nby `line_map` with coefficient between 0 and 1. Then the coefficients of those two points in the\ncombination lying in the span have the same sign. -/\ntheorem sign_eq_of_affineCombination_mem_affineSpan_single_lineMap {p : \u03b9 \u2192 P}\n    (h : AffineIndependent k p) {w : \u03b9 \u2192 k} {s : Finset \u03b9} (hw : (\u2211 i in s, w i) = 1) {i\u2081 i\u2082 i\u2083 : \u03b9}\n    (h\u2081 : i\u2081 \u2208 s) (h\u2082 : i\u2082 \u2208 s) (h\u2083 : i\u2083 \u2208 s) (h\u2081\u2082 : i\u2081 \u2260 i\u2082) (h\u2081\u2083 : i\u2081 \u2260 i\u2083) (h\u2082\u2083 : i\u2082 \u2260 i\u2083)\n    {c : k} (hc0 : 0 < c) (hc1 : c < 1)\n    (hs : s.affineCombination k p w \u2208 line[k, p i\u2081, AffineMap.lineMap (p i\u2082) (p i\u2083) c]) :\n    SignType.sign (w i\u2082) = SignType.sign (w i\u2083) := by\n  classical\n    rw [\u2190 s.affine_combination_affine_combination_single_weights k p h\u2081, \u2190\n      s.affine_combination_affine_combination_line_map_weights p h\u2082 h\u2083 c] at hs\n    refine'\n      sign_eq_of_affineCombination_mem_affineSpan_pair h hw\n        (s.sum_affine_combination_single_weights k h\u2081)\n        (s.sum_affine_combination_line_map_weights h\u2082 h\u2083 c) hs h\u2082 h\u2083\n        (Finset.affineCombinationSingleWeights_apply_of_ne k h\u2081\u2082.symm)\n        (Finset.affineCombinationSingleWeights_apply_of_ne k h\u2081\u2083.symm) _\n    rw [Finset.affineCombinationLineMapWeights_apply_left h\u2082\u2083,\n      Finset.affineCombinationLineMapWeights_apply_right h\u2082\u2083]\n    simp [hc0, sub_pos.2 hc1]\n#align sign_eq_of_affine_combination_mem_affine_span_single_line_map sign_eq_of_affineCombination_mem_affineSpan_single_lineMap\n\nend Ordered\n\nnamespace Affine\n\nvariable (k : Type _) {V : Type _} (P : Type _) [Ring k] [AddCommGroup V] [Module k V]\n\nvariable [affine_space V P]\n\ninclude V\n\n/-- A `simplex k P n` is a collection of `n + 1` affinely\nindependent points. -/\nstructure Simplex (n : \u2115) where\n  points : Fin (n + 1) \u2192 P\n  Independent : AffineIndependent k points\n#align affine.simplex Affine.Simplex\n\n/-- A `triangle k P` is a collection of three affinely independent points. -/\nabbrev Triangle :=\n  Simplex k P 2\n#align affine.triangle Affine.Triangle\n\nnamespace Simplex\n\nvariable {P}\n\n/-- Construct a 0-simplex from a point. -/\ndef mkOfPoint (p : P) : Simplex k P 0 :=\n  \u27e8fun _ => p, affineIndependent_of_subsingleton k _\u27e9\n#align affine.simplex.mk_of_point Affine.Simplex.mkOfPoint\n\n/-- The point in a simplex constructed with `mk_of_point`. -/\n@[simp]\ntheorem mkOfPoint_points (p : P) (i : Fin 1) : (mkOfPoint k p).points i = p :=\n  rfl\n#align affine.simplex.mk_of_point_points Affine.Simplex.mkOfPoint_points\n\ninstance [Inhabited P] : Inhabited (Simplex k P 0) :=\n  \u27e8mkOfPoint k default\u27e9\n\ninstance nonempty : Nonempty (Simplex k P 0) :=\n  \u27e8mkOfPoint k <| AddTorsor.nonempty.some\u27e9\n#align affine.simplex.nonempty Affine.Simplex.nonempty\n\nvariable {k V}\n\n/-- Two simplices are equal if they have the same points. -/\n@[ext]\ntheorem ext {n : \u2115} {s1 s2 : Simplex k P n} (h : \u2200 i, s1.points i = s2.points i) : s1 = s2 :=\n  by\n  cases s1\n  cases s2\n  congr with i\n  exact h i\n#align affine.simplex.ext Affine.Simplex.ext\n\n/-- Two simplices are equal if and only if they have the same points. -/\ntheorem ext_iff {n : \u2115} (s1 s2 : Simplex k P n) : s1 = s2 \u2194 \u2200 i, s1.points i = s2.points i :=\n  \u27e8fun h _ => h \u25b8 rfl, ext\u27e9\n#align affine.simplex.ext_iff Affine.Simplex.ext_iff\n\n/-- A face of a simplex is a simplex with the given subset of\npoints. -/\ndef face {n : \u2115} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : \u2115} (h : fs.card = m + 1) :\n    Simplex k P m :=\n  \u27e8s.points \u2218 fs.orderEmbOfFin h, s.Independent.comp_embedding (fs.orderEmbOfFin h).toEmbedding\u27e9\n#align affine.simplex.face Affine.Simplex.face\n\n/-- The points of a face of a simplex are given by `mono_of_fin`. -/\ntheorem face_points {n : \u2115} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : \u2115}\n    (h : fs.card = m + 1) (i : Fin (m + 1)) :\n    (s.face h).points i = s.points (fs.orderEmbOfFin h i) :=\n  rfl\n#align affine.simplex.face_points Affine.Simplex.face_points\n\n/-- The points of a face of a simplex are given by `mono_of_fin`. -/\ntheorem face_points' {n : \u2115} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : \u2115}\n    (h : fs.card = m + 1) : (s.face h).points = s.points \u2218 fs.orderEmbOfFin h :=\n  rfl\n#align affine.simplex.face_points' Affine.Simplex.face_points'\n\n/-- A single-point face equals the 0-simplex constructed with\n`mk_of_point`. -/\n@[simp]\ntheorem face_eq_mkOfPoint {n : \u2115} (s : Simplex k P n) (i : Fin (n + 1)) :\n    s.face (Finset.card_singleton i) = mkOfPoint k (s.points i) :=\n  by\n  ext\n  simp [face_points]\n#align affine.simplex.face_eq_mk_of_point Affine.Simplex.face_eq_mkOfPoint\n\n/-- The set of points of a face. -/\n@[simp]\ntheorem range_face_points {n : \u2115} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : \u2115}\n    (h : fs.card = m + 1) : Set.range (s.face h).points = s.points '' \u2191fs := by\n  rw [face_points', Set.range_comp, Finset.range_orderEmbOfFin]\n#align affine.simplex.range_face_points Affine.Simplex.range_face_points\n\n/-- Remap a simplex along an `equiv` of index types. -/\n@[simps]\ndef reindex {m n : \u2115} (s : Simplex k P m) (e : Fin (m + 1) \u2243 Fin (n + 1)) : Simplex k P n :=\n  \u27e8s.points \u2218 e.symm, (affineIndependent_equiv e.symm).2 s.Independent\u27e9\n#align affine.simplex.reindex Affine.Simplex.reindex\n\n/-- Reindexing by `equiv.refl` yields the original simplex. -/\n@[simp]\ntheorem reindex_refl {n : \u2115} (s : Simplex k P n) : s.reindex (Equiv.refl (Fin (n + 1))) = s :=\n  ext fun _ => rfl\n#align affine.simplex.reindex_refl Affine.Simplex.reindex_refl\n\n/-- Reindexing by the composition of two equivalences is the same as reindexing twice. -/\n@[simp]\ntheorem reindex_trans {n\u2081 n\u2082 n\u2083 : \u2115} (e\u2081\u2082 : Fin (n\u2081 + 1) \u2243 Fin (n\u2082 + 1))\n    (e\u2082\u2083 : Fin (n\u2082 + 1) \u2243 Fin (n\u2083 + 1)) (s : Simplex k P n\u2081) :\n    s.reindex (e\u2081\u2082.trans e\u2082\u2083) = (s.reindex e\u2081\u2082).reindex e\u2082\u2083 :=\n  rfl\n#align affine.simplex.reindex_trans Affine.Simplex.reindex_trans\n\n/-- Reindexing by an equivalence and its inverse yields the original simplex. -/\n@[simp]\ntheorem reindex_reindex_symm {m n : \u2115} (s : Simplex k P m) (e : Fin (m + 1) \u2243 Fin (n + 1)) :\n    (s.reindex e).reindex e.symm = s := by rw [\u2190 reindex_trans, Equiv.self_trans_symm, reindex_refl]\n#align affine.simplex.reindex_reindex_symm Affine.Simplex.reindex_reindex_symm\n\n/-- Reindexing by the inverse of an equivalence and that equivalence yields the original simplex. -/\n@[simp]\ntheorem reindex_symm_reindex {m n : \u2115} (s : Simplex k P m) (e : Fin (n + 1) \u2243 Fin (m + 1)) :\n    (s.reindex e.symm).reindex e = s := by rw [\u2190 reindex_trans, Equiv.symm_trans_self, reindex_refl]\n#align affine.simplex.reindex_symm_reindex Affine.Simplex.reindex_symm_reindex\n\n/-- Reindexing a simplex produces one with the same set of points. -/\n@[simp]\ntheorem reindex_range_points {m n : \u2115} (s : Simplex k P m) (e : Fin (m + 1) \u2243 Fin (n + 1)) :\n    Set.range (s.reindex e).points = Set.range s.points := by\n  rw [reindex, Set.range_comp, Equiv.range_eq_univ, Set.image_univ]\n#align affine.simplex.reindex_range_points Affine.Simplex.reindex_range_points\n\nend Simplex\n\nend Affine\n\nnamespace Affine\n\nnamespace Simplex\n\nvariable {k : Type _} {V : Type _} {P : Type _} [DivisionRing k] [AddCommGroup V] [Module k V]\n  [affine_space V P]\n\ninclude V\n\n/-- The centroid of a face of a simplex as the centroid of a subset of\nthe points. -/\n@[simp]\ntheorem face_centroid_eq_centroid {n : \u2115} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : \u2115}\n    (h : fs.card = m + 1) : Finset.univ.centroid k (s.face h).points = fs.centroid k s.points :=\n  by\n  convert(finset.univ.centroid_map k (fs.order_emb_of_fin h).toEmbedding s.points).symm\n  rw [\u2190 Finset.coe_inj, Finset.coe_map, Finset.coe_univ, Set.image_univ]\n  simp\n#align affine.simplex.face_centroid_eq_centroid Affine.Simplex.face_centroid_eq_centroid\n\n/-- Over a characteristic-zero division ring, the centroids given by\ntwo subsets of the points of a simplex are equal if and only if those\nfaces are given by the same subset of points. -/\n@[simp]\ntheorem centroid_eq_iff [CharZero k] {n : \u2115} (s : Simplex k P n) {fs\u2081 fs\u2082 : Finset (Fin (n + 1))}\n    {m\u2081 m\u2082 : \u2115} (h\u2081 : fs\u2081.card = m\u2081 + 1) (h\u2082 : fs\u2082.card = m\u2082 + 1) :\n    fs\u2081.centroid k s.points = fs\u2082.centroid k s.points \u2194 fs\u2081 = fs\u2082 :=\n  by\n  refine' \u27e8fun h => _, congr_arg _\u27e9\n  rw [Finset.centroid_eq_affineCombination_fintype, Finset.centroid_eq_affineCombination_fintype] at\n    h\n  have ha :=\n    (affineIndependent_iff_indicator_eq_of_affineCombination_eq k s.points).1 s.independent _ _ _ _\n      (fs\u2081.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h\u2081)\n      (fs\u2082.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h\u2082) h\n  simp_rw [Finset.coe_univ, Set.indicator_univ, Function.funext_iff,\n    Finset.centroidWeightsIndicator_def, Finset.centroidWeights, h\u2081, h\u2082] at ha\n  ext i\n  specialize ha i\n  have key : \u2200 n : \u2115, (n : k) + 1 \u2260 0 := fun n h => by norm_cast  at h\n  -- we should be able to golf this to `refine \u27e8\u03bb hi, decidable.by_contradiction (\u03bb hni, _), ...\u27e9`,\n      -- but for some unknown reason it doesn't work.\n      constructor <;>\n      intro hi <;>\n    by_contra hni\n  \u00b7 simpa [hni, hi, key] using ha\n  \u00b7 simpa [hni, hi, key] using ha.symm\n#align affine.simplex.centroid_eq_iff Affine.Simplex.centroid_eq_iff\n\n/-- Over a characteristic-zero division ring, the centroids of two\nfaces of a simplex are equal if and only if those faces are given by\nthe same subset of points. -/\ntheorem face_centroid_eq_iff [CharZero k] {n : \u2115} (s : Simplex k P n)\n    {fs\u2081 fs\u2082 : Finset (Fin (n + 1))} {m\u2081 m\u2082 : \u2115} (h\u2081 : fs\u2081.card = m\u2081 + 1) (h\u2082 : fs\u2082.card = m\u2082 + 1) :\n    Finset.univ.centroid k (s.face h\u2081).points = Finset.univ.centroid k (s.face h\u2082).points \u2194\n      fs\u2081 = fs\u2082 :=\n  by\n  rw [face_centroid_eq_centroid, face_centroid_eq_centroid]\n  exact s.centroid_eq_iff h\u2081 h\u2082\n#align affine.simplex.face_centroid_eq_iff Affine.Simplex.face_centroid_eq_iff\n\n/-- Two simplices with the same points have the same centroid. -/\ntheorem centroid_eq_of_range_eq {n : \u2115} {s\u2081 s\u2082 : Simplex k P n}\n    (h : Set.range s\u2081.points = Set.range s\u2082.points) :\n    Finset.univ.centroid k s\u2081.points = Finset.univ.centroid k s\u2082.points :=\n  by\n  rw [\u2190 Set.image_univ, \u2190 Set.image_univ, \u2190 Finset.coe_univ] at h\n  exact\n    finset.univ.centroid_eq_of_inj_on_of_image_eq k _\n      (fun _ _ _ _ he => AffineIndependent.injective s\u2081.independent he)\n      (fun _ _ _ _ he => AffineIndependent.injective s\u2082.independent he) h\n#align affine.simplex.centroid_eq_of_range_eq Affine.Simplex.centroid_eq_of_range_eq\n\nend Simplex\n\nend Affine\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/AffineSpace/Independent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7073006496491271}}
{"text": "/-\nCopyright \u00a9 2021 Nicol\u00f2 Cavalleri. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Nicol\u00f2 Cavalleri, Heather Macbeth\n\n! This file was ported from Lean 3 source module geometry.manifold.instances.units_of_normed_algebra\n! leanprover-community/mathlib commit ef901ea68d3bb1dd08f8bc3034ab6b32b2e6ecdf\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Geometry.Manifold.SmoothManifoldWithCorners\nimport Mathbin.Analysis.NormedSpace.Units\n\n/-!\n# Units of a normed algebra\n\nThis file is a stub, containing a construction of the charted space structure on the group of units\nof a complete normed ring `R`, and of the smooth manifold structure on the group of units of a\ncomplete normed `\ud835\udd5c`-algebra `R`.\n\nThis manifold is actually a Lie group, which eventually should be the main result of this file.\n\nAn important special case of this construction is the general linear group.  For a normed space `V`\nover a field `\ud835\udd5c`, the `\ud835\udd5c`-linear endomorphisms of `V` are a normed `\ud835\udd5c`-algebra (see\n`continuous_linear_map.to_normed_algebra`), so this construction provides a Lie group structure on\nits group of units, the general linear group GL(`\ud835\udd5c`, `V`).\n\n## TODO\n\nThe Lie group instance requires the following fields:\n```\ninstance : lie_group \ud835\udcd8(\ud835\udd5c, R) R\u02e3 :=\n{ smooth_mul := sorry,\n  smooth_inv := sorry,\n  ..units.smooth_manifold_with_corners }\n```\n\nThe ingredients needed for the construction are\n* smoothness of multiplication and inversion in the charts, i.e. as functions on the normed\n  `\ud835\udd5c`-space `R`:  see `cont_diff_at_ring_inverse` for the inversion result, and\n  `cont_diff_mul` (needs to be generalized from field to algebra) for the multiplication\n  result\n* for an open embedding `f`, whose domain is equipped with the induced manifold structure\n  `f.singleton_smooth_manifold_with_corners`, characterization of smoothness of functions to/from\n  this manifold in terms of smoothness in the target space.  See the pair of lemmas\n  `cont_mdiff_coe_sphere` and `cont_mdiff.cod_restrict_sphere` for a model.\nNone of this should be particularly difficult.\n\n-/\n\n\nnoncomputable section\n\nopen Manifold\n\nnamespace Units\n\nvariable {R : Type _} [NormedRing R] [CompleteSpace R]\n\ninstance : ChartedSpace R R\u02e3 :=\n  openEmbedding_coe.singletonChartedSpace\n\ntheorem chartAt_apply {a : R\u02e3} {b : R\u02e3} : chartAt R a b = b :=\n  rfl\n#align units.chart_at_apply Units.chartAt_apply\n\ntheorem chartAt_source {a : R\u02e3} : (chartAt R a).source = Set.univ :=\n  rfl\n#align units.chart_at_source Units.chartAt_source\n\nvariable {\ud835\udd5c : Type _} [NontriviallyNormedField \ud835\udd5c] [NormedAlgebra \ud835\udd5c R]\n\ninstance : SmoothManifoldWithCorners \ud835\udcd8(\ud835\udd5c, R) R\u02e3 :=\n  openEmbedding_coe.singleton_smoothManifoldWithCorners \ud835\udcd8(\ud835\udd5c, R)\n\nend Units\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Geometry/Manifold/Instances/UnitsOfNormedAlgebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7073006362657743}}
{"text": "theorem le_trans (a b c : mynat) (hab : a \u2264 b) (hbc : b \u2264 c) : a \u2264 c :=\nbegin\ncases hab,\ncases hbc,\nuse (hab_w + hbc_w),\nrw \u2190 add_assoc,\nrw hbc_h,\nrw hab_h,\nrefl,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world10/level05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.7634837689358858, "lm_q1q2_score": 0.7072178600776429}}
{"text": "import data.int.parity\nimport data.real.basic\nimport .limit_definition -- <=> exercises.limit_definition\n\nset_option trace.simplify.rewrite true\n\n-- Negations, proof by contradiction and contraposition.\nexample : false \u2192 0 = 1 :=\nbegin\n  intro h,\n  exfalso,\n  exact h,\nend\n\nexample {x : real} : \u00ac x < x :=\nbegin\n  intro hyp,\n  rw lt_iff_le_and_ne at hyp,\n  cases hyp with hyp_inf hyp_non,\n  clear hyp_inf, -- we won't use that one, so let's discard it\n  change x = x \u2192 false at hyp_non, -- Lean doesn't need this psychological line\n  apply hyp_non (eq.refl x),\nend\n\nopen int\n\nexample (n : \u2124) (h_pair : even n) (h_non_pair : \u00ac even n) : 0 = 1 :=\nbegin\n  have H : \u00ac (0 = 1) := zero_ne_one,\n  sorry,\nend\n\nexample (P Q : Prop) (h\u2081 : P \u2228 Q) (h\u2082 : \u00ac (P \u2227 Q)) : \u00ac P \u2194 Q :=\nbegin\n  cases h\u2081,\n  {\n    have p_true : P = true, from sorry,\n    rw p_true at h\u2082,\n    have H : (true \u2227 Q) = Q, from sorry,\n    rw H at h\u2082,\n    clear H,\n    -- we must use maximum information rules:\n    -- \u00ac Q = (Q \u2192 false) give us less information than \u00ac Q = (Q \u2194 false)\n    have H2 : \u00ac Q \u2194 (Q = false), from sorry,\n    rw H2 at h\u2082,\n    rename h\u2082 q_false,\n    rw [p_true, q_false],\n    -- simp only [iff],\n    rw not_true,\n    -- [not_true]: \u00actrue ==> false\n    -- [iff_self]: false \u2194 false ==> true\n  },\n  {\n    sorry\n  },\nend\n\nlemma ex1 (u : \u2115 \u2192 \u211d) (l l' : \u211d) : seq_limit u l \u2192 seq_limit u l' \u2192 l = l' :=\nbegin\n  intros hl hl',\n  by_contradiction H,\n  change l \u2260 l' at H, -- for human readability\n  have ineq : |l-l'| > 0,\n    begin\n    apply abs_pos_of_ne_zero, \n    -- backward proof: we need match goal to the right side of abs_pos_of_ne_zero:\n    -- abs_pos_of_ne_zero : a \u2260 0 \u2192 |a| > 0\n    --                              \u2191\u2191\u2191\u2191\u2191\u2191\u2191\n    -- then goal becomes left side: \u22a2 l - l' \u2260 0\n    apply sub_ne_zero_of_ne,\n    exact H,\n      -- exact abs_pos_of_ne_zero (sub_ne_zero_of_ne H),\n    end,\n  cases hl ( |l-l'|/4 ) (by linarith) with N hN, -- it's hard to understand this line\n  cases hl' ( |l-l'|/4 ) (by linarith) with N' hN', -- and this\n  let N\u2080 := max N N', -- this is a new tactic, whose effect should be clear\n  specialize hN N\u2080 (le_max_left _ _),\n  specialize hN' N\u2080 (le_max_right _ _),\n  have clef : |l-l'| < |l-l'|,\n    calc\n    |l - l'| = |(l - u N\u2080) + (u N\u2080 - l')| : by ring\n         ... \u2264 |l - u N\u2080| + |u N\u2080 - l'|   : by apply abs_add -- apply in forward order, not backward? answer: no, calc implicitly executed `apply eq.trans`\n         ... = |u N\u2080 - l| + |u N\u2080 - l'|   : by rw abs_sub\n         ... < |l-l'| : by linarith,\n  linarith, -- liarith can also find simple numerical contradictions\nend\n\nexample (P Q : Prop) (h : \u00ac Q \u2192 \u00ac P) : P \u2192 Q :=\nbegin\n  contrapose,\n  exact h,\nend\n", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/exercises/first_negations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.7072178435693959}}
{"text": "-- Union_con_su_interseccion.lean\n-- Uni\u00f3n con su intersecci\u00f3n\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 28-abril-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    s \u222a (s \u2229 t) = s\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    cases hx with xs xst,\n    { exact xs, },\n    { exact xst.1, }},\n  { intro xs,\n    left,\n    exact xs, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nbegin\n  ext x,\n  exact \u27e8\u03bb hx, or.dcases_on hx id and.left,\n         \u03bb xs, or.inl xs\u27e9,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nbegin\n  ext x,\n  split,\n  { rintros (xs | \u27e8xs, xt\u27e9);\n    exact xs },\n  { intro xs,\n    left,\n    exact xs },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u222a (s \u2229 t) = s :=\nsup_inf_self\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Union_con_su_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7071971516238433}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport data.equiv.encodable.basic\nimport order.atoms\n\n/-!\n# Order ideals, cofinal sets, and the Rasiowa\u2013Sikorski lemma\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections require more\nstructure, such as a bottom element, a top element, or a join-semilattice structure.\n- `order.ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.\n  Dual to the notion of a filter on a preorder.\n- `order.is_ideal P`: a predicate for when a `set P` is an ideal.\n- `order.ideal.principal p`: the principal ideal generated by `p : P`.\n- `order.ideal.is_proper P`: a predicate for proper ideals.\n  Dual to the notion of a proper filter.\n- `order.ideal.is_maximal`: a predicate for maximal ideals.\n  Dual to the notion of an ultrafilter.\n- `ideal_inter_nonempty P`: a predicate for when the intersection of any two ideals of\n  `P` is nonempty.\n- `ideal_Inter_nonempty P`: a predicate for when the intersection of all ideals of\n  `P` is nonempty.\n- `order.cofinal P`: the type of subsets of `P` containing arbitrarily large elements.\n  Dual to the notion of 'dense set' used in forcing.\n- `order.ideal_of_cofinals p \ud835\udc9f`, where `p : P`, and `\ud835\udc9f` is a countable family of cofinal\n  subsets of P: an ideal in `P` which contains `p` and intersects every set in `\ud835\udc9f`. (This a form\n  of the Rasiowa\u2013Sikorski lemma.)\n\n## References\n\n- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>\n- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>\n- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>\n\nNote that for the Rasiowa\u2013Sikorski lemma, Wikipedia uses the opposite ordering on `P`,\nin line with most presentations of forcing.\n\n## Tags\n\nideal, cofinal, dense, countable, generic\n\n-/\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- An ideal on a preorder `P` is a subset of `P` that is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\nstructure ideal (P) [preorder P] :=\n(carrier   : set P)\n(nonempty  : carrier.nonempty)\n(directed  : directed_on (\u2264) carrier)\n(mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 y \u2208 carrier \u2192 x \u2208 carrier)\n\n/-- A subset of a preorder `P` is an ideal if it is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\n@[mk_iff] structure is_ideal {P} [preorder P] (I : set P) : Prop :=\n(nonempty : I.nonempty)\n(directed : directed_on (\u2264) I)\n(mem_of_le : \u2200 {x y : P}, x \u2264 y \u2192 y \u2208 I \u2192 x \u2208 I)\n\n/-- Create an element of type `order.ideal` from a set satisfying the predicate\n`order.is_ideal`. -/\ndef is_ideal.to_ideal [preorder P] {I : set P} (h : is_ideal I) : ideal P :=\n\u27e8I, h.1, h.2, h.3\u27e9\n\nnamespace ideal\n\nsection preorder\nvariables [preorder P] {x y : P} {I J : ideal P}\n\n/-- The smallest ideal containing a given element. -/\ndef principal (p : P) : ideal P :=\n{ carrier   := { x | x \u2264 p },\n  nonempty  := \u27e8p, le_refl _\u27e9,\n  directed  := \u03bb x hx y hy, \u27e8p, le_refl _, hx, hy\u27e9,\n  mem_of_le := \u03bb x y hxy hy, le_trans hxy hy, }\n\ninstance [inhabited P] : inhabited (ideal P) :=\n\u27e8ideal.principal $ default P\u27e9\n\n/-- An ideal of `P` can be viewed as a subset of `P`. -/\ninstance : has_coe (ideal P) (set P) := \u27e8carrier\u27e9\n\n/-- For the notation `x \u2208 I`. -/\ninstance : has_mem P (ideal P) := \u27e8\u03bb x I, x \u2208 (I : set P)\u27e9\n\n@[simp] lemma mem_coe : x \u2208 (I : set P) \u2194 x \u2208 I := iff_of_eq rfl\n\n@[simp] lemma mem_principal : x \u2208 principal y \u2194 x \u2264 y := by refl\n\n/-- Two ideals are equal when their underlying sets are equal. -/\n@[ext] lemma ext : \u2200 (I J : ideal P), (I : set P) = J \u2192 I = J\n| \u27e8_, _, _, _\u27e9 \u27e8_, _, _, _\u27e9 rfl := rfl\n\n@[simp, norm_cast] lemma ext_set_eq {I J : ideal P} : (I : set P) = J \u2194 I = J :=\n\u27e8by ext, congr_arg _\u27e9\n\nlemma ext'_iff {I J : ideal P} : I = J \u2194 (I : set P) = J := ext_set_eq.symm\n\nlemma is_ideal (I : ideal P) : is_ideal (I : set P) := \u27e8I.2, I.3, I.4\u27e9\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (ideal P) := partial_order.lift coe ext\n\n@[trans] lemma mem_of_mem_of_le : x \u2208 I \u2192 I \u2264 J \u2192 x \u2208 J :=\n@set.mem_of_mem_of_subset P x I J\n\n@[simp] lemma principal_le_iff : principal x \u2264 I \u2194 x \u2208 I :=\n\u27e8\u03bb (h : \u2200 {y}, y \u2264 x \u2192 y \u2208 I), h (le_refl x),\n \u03bb h_mem y (h_le : y \u2264 x), I.mem_of_le h_le h_mem\u27e9\n\nlemma mem_compl_of_ge {x y : P} : x \u2264 y \u2192 x \u2208 (I : set P)\u1d9c \u2192 y \u2208 (I : set P)\u1d9c :=\n\u03bb h, mt (I.mem_of_le h)\n\n/-- A proper ideal is one that is not the whole set.\n    Note that the whole set might not be an ideal. -/\n@[mk_iff] class is_proper (I : ideal P) : Prop := (ne_univ : (I : set P) \u2260 set.univ)\n\nlemma is_proper_of_not_mem {I : ideal P} {p : P} (nmem : p \u2209 I) : is_proper I :=\n\u27e8\u03bb hp, begin\n  change p \u2209 \u2191I at nmem,\n  rw hp at nmem,\n  exact nmem (set.mem_univ p),\nend\u27e9\n\n/-- An ideal is maximal if it is maximal in the collection of proper ideals.\n  Note that we cannot use the `is_coatom` class because `P` might not have a `top` element.\n-/\n@[mk_iff] class is_maximal (I : ideal P) extends is_proper I : Prop :=\n(maximal_proper : \u2200 \u2983J : ideal P\u2984, I < J \u2192 (J : set P) = set.univ)\n\nvariable (P)\n\n/-- A preorder `P` has the `ideal_inter_nonempty` property if the\n    intersection of any two ideals is nonempty.\n    Most importantly, a `semilattice_sup` preorder with this property\n    satisfies that its ideal poset is a lattice.\n-/\nclass ideal_inter_nonempty : Prop :=\n(inter_nonempty : \u2200 (I J : ideal P), ((I : set P) \u2229 (J : set P)).nonempty)\n\n/-- A preorder `P` has the `ideal_Inter_nonempty` property if the\n    intersection of all ideals is nonempty.\n    Most importantly, a `semilattice_sup` preorder with this property\n    satisfies that its ideal poset is a complete lattice.\n-/\nclass ideal_Inter_nonempty : Prop :=\n(Inter_nonempty : (\u22c2 (I : ideal P), (I : set P)).nonempty)\n\nvariable {P}\n\nlemma inter_nonempty [ideal_inter_nonempty P] :\n  \u2200 (I J : ideal P), ((I : set P) \u2229 (J : set P)).nonempty :=\nideal_inter_nonempty.inter_nonempty\n\nlemma Inter_nonempty [ideal_Inter_nonempty P] :\n  (\u22c2 (I : ideal P), (I : set P)).nonempty :=\nideal_Inter_nonempty.Inter_nonempty\n\nlemma ideal_Inter_nonempty.exists_all_mem [ideal_Inter_nonempty P] :\n  \u2203 a : P, \u2200 I : ideal P, a \u2208 I :=\nbegin\n  change \u2203 (a : P), \u2200 (I : ideal P), a \u2208 (I : set P),\n  rw \u2190 set.nonempty_Inter,\n  exact Inter_nonempty,\nend\n\nlemma ideal_Inter_nonempty_of_exists_all_mem (h : \u2203 a : P, \u2200 I : ideal P, a \u2208 I) :\n  ideal_Inter_nonempty P :=\n{ Inter_nonempty := by rwa set.nonempty_Inter }\n\nlemma ideal_Inter_nonempty_iff :\n  ideal_Inter_nonempty P \u2194 \u2203 a : P, \u2200 I : ideal P, a \u2208 I :=\n\u27e8\u03bb _, by exactI ideal_Inter_nonempty.exists_all_mem, ideal_Inter_nonempty_of_exists_all_mem\u27e9\n\nend preorder\n\nsection order_bot\nvariables [preorder P] [order_bot P] {I : ideal P}\n\n/-- A specific witness of `I.nonempty` when `P` has a bottom element. -/\n@[simp] lemma bot_mem : \u22a5 \u2208 I :=\nI.mem_of_le bot_le I.nonempty.some_mem\n\n/-- There is a bottom ideal when `P` has a bottom element. -/\ninstance : order_bot (ideal P) :=\n{ bot := principal \u22a5,\n  bot_le := by simp }\n\n@[priority 100]\ninstance order_bot.ideal_Inter_nonempty : ideal_Inter_nonempty P :=\nby { rw ideal_Inter_nonempty_iff, exact \u27e8\u22a5, \u03bb I, bot_mem\u27e9 }\n\nend order_bot\n\nsection order_top\n\nvariables [preorder P] [order_top P]\n\n/-- There is a top ideal when `P` has a top element. -/\ninstance : order_top (ideal P) :=\n{ top := principal \u22a4,\n  le_top := \u03bb I x h, le_top }\n\n@[simp] lemma coe_top : ((\u22a4 : ideal P) : set P) = set.univ :=\nset.univ_subset_iff.1 (\u03bb p _, le_top)\n\nlemma top_of_mem_top {I : ideal P} (mem_top : \u22a4 \u2208 I) : I = \u22a4 :=\nbegin\n  ext,\n  change x \u2208 I \u2194 x \u2208 ((\u22a4 : ideal P) : set P),\n  split,\n  { simp [coe_top] },\n  { exact \u03bb _, I.mem_of_le le_top mem_top }\nend\n\nlemma is_proper_of_ne_top {I : ideal P} (ne_top : I \u2260 \u22a4) : is_proper I :=\nis_proper_of_not_mem (\u03bb h, ne_top (top_of_mem_top h))\n\nlemma is_proper.ne_top {I : ideal P} (hI : is_proper I) : I \u2260 \u22a4 :=\nbegin\n  intro h,\n  rw [ext'_iff, coe_top] at h,\n  apply hI.ne_univ,\n  assumption,\nend\n\nlemma is_proper.top_not_mem {I : ideal P} (hI : is_proper I) : \u22a4 \u2209 I :=\nby { by_contra, exact hI.ne_top (top_of_mem_top h) }\n\nlemma _root_.is_coatom.is_proper {I : ideal P} (hI : is_coatom I) : is_proper I :=\nis_proper_of_ne_top hI.1\n\nlemma is_proper_iff_ne_top {I : ideal P} : is_proper I \u2194 I \u2260 \u22a4 :=\n\u27e8\u03bb h, h.ne_top, \u03bb h, is_proper_of_ne_top h\u27e9\n\nlemma is_maximal.is_coatom {I : ideal P} (h : is_maximal I) : is_coatom I :=\n\u27e8is_maximal.to_is_proper.ne_top,\n \u03bb _ _, by { rw [ext'_iff, coe_top], exact is_maximal.maximal_proper \u2039_\u203a }\u27e9\n\nlemma is_maximal.is_coatom' {I : ideal P} [is_maximal I] : is_coatom I :=\nis_maximal.is_coatom \u2039_\u203a\n\nlemma _root_.is_coatom.is_maximal {I : ideal P} (hI : is_coatom I) : is_maximal I :=\n{ maximal_proper := \u03bb _ _, by simp [hI.2 _ \u2039_\u203a],\n  ..is_coatom.is_proper \u2039_\u203a }\n\nlemma is_maximal_iff_is_coatom {I : ideal P} : is_maximal I \u2194 is_coatom I :=\n\u27e8\u03bb h, h.is_coatom, \u03bb h, h.is_maximal\u27e9\n\nend order_top\n\nsection semilattice_sup\nvariables [semilattice_sup P] {x y : P} {I : ideal P}\n\n/-- A specific witness of `I.directed` when `P` has joins. -/\nlemma sup_mem (x y \u2208 I) : x \u2294 y \u2208 I :=\nlet \u27e8z, h_mem, hx, hy\u27e9 := I.directed x \u2039_\u203a y \u2039_\u203a in\nI.mem_of_le (sup_le hx hy) h_mem\n\n@[simp] lemma sup_mem_iff : x \u2294 y \u2208 I \u2194 x \u2208 I \u2227 y \u2208 I :=\n\u27e8\u03bb h, \u27e8I.mem_of_le le_sup_left h, I.mem_of_le le_sup_right h\u27e9,\n \u03bb h, sup_mem x y h.left h.right\u27e9\n\nend semilattice_sup\n\nsection semilattice_sup_ideal_inter_nonempty\n\nvariables [semilattice_sup P] [ideal_inter_nonempty P] {x : P} {I J K : ideal P}\n\n/-- The intersection of two ideals is an ideal, when it is nonempty and `P` has joins. -/\ndef inf (I J : ideal P) : ideal P :=\n{ carrier   := I \u2229 J,\n  nonempty  := inter_nonempty I J,\n  directed  := \u03bb x \u27e8_, _\u27e9 y \u27e8_, _\u27e9, \u27e8x \u2294 y, \u27e8sup_mem x y \u2039_\u203a \u2039_\u203a, sup_mem x y \u2039_\u203a \u2039_\u203a\u27e9, by simp\u27e9,\n  mem_of_le := \u03bb x y h \u27e8_, _\u27e9, \u27e8mem_of_le I h \u2039_\u203a, mem_of_le J h \u2039_\u203a\u27e9 }\n\n/-- There is a smallest ideal containing two ideals, when their intersection is nonempty and\n    `P` has joins. -/\ndef sup (I J : ideal P) : ideal P :=\n{ carrier   := {x | \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j},\n  nonempty  := by { cases inter_nonempty I J, exact \u27e8w, w, h.1, w, h.2, le_sup_left\u27e9 },\n  directed  := \u03bb x \u27e8xi, _, xj, _, _\u27e9 y \u27e8yi, _, yj, _, _\u27e9,\n    \u27e8x \u2294 y,\n     \u27e8xi \u2294 yi, sup_mem xi yi \u2039_\u203a \u2039_\u203a,\n      xj \u2294 yj, sup_mem xj yj \u2039_\u203a \u2039_\u203a,\n      sup_le\n        (calc x \u2264 xi \u2294 xj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_left le_sup_left)\n        (calc y \u2264 yi \u2294 yj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_right le_sup_right)\u27e9,\n     le_sup_left, le_sup_right\u27e9,\n  mem_of_le := \u03bb x y _ \u27e8yi, _, yj, _, _\u27e9, \u27e8yi, \u2039_\u203a, yj, \u2039_\u203a, le_trans \u2039x \u2264 y\u203a \u2039_\u203a\u27e9 }\n\nlemma sup_le : I \u2264 K \u2192 J \u2264 K \u2192 sup I J \u2264 K :=\n\u03bb hIK hJK x \u27e8i, hiI, j, hjJ, hxij\u27e9,\nK.mem_of_le hxij $ sup_mem i j (mem_of_mem_of_le hiI hIK) (mem_of_mem_of_le hjJ hJK)\n\ninstance : lattice (ideal P) :=\n{ sup          := sup,\n  le_sup_left  := \u03bb I J (i \u2208 I), by { cases nonempty J, exact \u27e8i, \u2039_\u203a, w, \u2039_\u203a, le_sup_left\u27e9 },\n  le_sup_right := \u03bb I J (j \u2208 J), by { cases nonempty I, exact \u27e8w, \u2039_\u203a, j, \u2039_\u203a, le_sup_right\u27e9 },\n  sup_le       := @sup_le _ _ _,\n  inf          := inf,\n  inf_le_left  := \u03bb I J, set.inter_subset_left I J,\n  inf_le_right := \u03bb I J, set.inter_subset_right I J,\n  le_inf       := \u03bb I J K, set.subset_inter,\n  .. ideal.partial_order }\n\n@[simp] lemma mem_inf : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J := iff_of_eq rfl\n\n@[simp] lemma mem_sup : x \u2208 I \u2294 J \u2194 \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j := iff_of_eq rfl\n\nlemma lt_sup_principal_of_not_mem (hx : x \u2209 I) : I < I \u2294 principal x :=\nbegin\n  apply lt_of_le_of_ne le_sup_left,\n  intro h,\n  simp at h,\n  exact hx h\nend\n\nend semilattice_sup_ideal_inter_nonempty\n\nsection ideal_Inter_nonempty\n\nvariables [preorder P] [ideal_Inter_nonempty P]\n\n@[priority 100]\ninstance ideal_Inter_nonempty.ideal_inter_nonempty : ideal_inter_nonempty P :=\n{ inter_nonempty := \u03bb _ _, begin\n    obtain \u27e8a, ha\u27e9 : \u2203 a : P, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n    exact \u27e8a, ha _, ha _\u27e9\n  end }\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*} {\u03b9 : Sort*}\n\nlemma ideal_Inter_nonempty.all_Inter_nonempty {f : \u03b9 \u2192 ideal P} :\n  (\u22c2 x, (f x : set P)).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 : \u2203 a : P, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n  exact \u27e8a, by simp [ha]\u27e9\nend\n\nlemma ideal_Inter_nonempty.all_bInter_nonempty {f : \u03b1 \u2192 ideal P} {s : set \u03b1} :\n  (\u22c2 x \u2208 s, (f x : set P)).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 : \u2203 a : P, \u2200 I : ideal P, a \u2208 I := ideal_Inter_nonempty.exists_all_mem,\n  exact \u27e8a, by simp [ha]\u27e9\nend\n\nend ideal_Inter_nonempty\n\nsection semilattice_sup_ideal_Inter_nonempty\n\nvariables [semilattice_sup P] [ideal_Inter_nonempty P] {x : P} {I J K : ideal P}\n\ninstance : has_Inf (ideal P) :=\n{ Inf := \u03bb s, { carrier := \u22c2 (I \u2208 s), (I : set P),\n  nonempty := ideal_Inter_nonempty.all_bInter_nonempty,\n  directed := \u03bb x hx y hy, \u27e8x \u2294 y, \u27e8\u03bb S \u27e8I, hS\u27e9,\n    begin\n      simp only [\u2190hS, sup_mem_iff, mem_coe, set.mem_Inter],\n      intro hI,\n      rw set.mem_bInter_iff at *,\n      exact \u27e8hx _ hI, hy _ hI\u27e9\n    end,\n    le_sup_left, le_sup_right\u27e9\u27e9,\n  mem_of_le := \u03bb x y hxy hy,\n    begin\n      rw set.mem_bInter_iff at *,\n      exact \u03bb I hI, mem_of_le I \u2039_\u203a (hy I hI)\n    end } }\n\nvariables {s : set (ideal P)}\n\n@[simp] lemma mem_Inf : x \u2208 Inf s \u2194 \u2200 I \u2208 s, x \u2208 I :=\nby { change x \u2208 (\u22c2 (I \u2208 s), (I : set P)) \u2194 \u2200 I \u2208 s, x \u2208 I, simp }\n\n@[simp] lemma coe_Inf : \u2191(Inf s) = \u22c2 (I \u2208 s), (I : set P) := rfl\n\nlemma Inf_le (hI : I \u2208 s) : Inf s \u2264 I :=\n\u03bb _ hx, hx I \u27e8I, by simp [hI]\u27e9\n\nlemma le_Inf (h : \u2200 J \u2208 s, I \u2264 J) : I \u2264 Inf s :=\n\u03bb _ _, by { simp only [mem_coe, coe_Inf, set.mem_Inter], tauto }\n\nlemma is_glb_Inf : is_glb s (Inf s) := \u27e8\u03bb _, Inf_le, \u03bb _, le_Inf\u27e9\n\ninstance : complete_lattice (ideal P) :=\n{ ..ideal.lattice,\n  ..complete_lattice_of_Inf (ideal P) (\u03bb _, @is_glb_Inf _ _ _ _) }\n\nend semilattice_sup_ideal_Inter_nonempty\n\nsection semilattice_inf\n\nvariable [semilattice_inf P]\n\n@[priority 100]\ninstance semilattice_inf.ideal_inter_nonempty : ideal_inter_nonempty P :=\n{ inter_nonempty := \u03bb I J, begin\n    cases I.nonempty with i _,\n    cases J.nonempty with j _,\n    exact \u27e8i \u2293 j, I.mem_of_le inf_le_left \u2039_\u203a, J.mem_of_le inf_le_right \u2039_\u203a\u27e9\n  end }\n\nend semilattice_inf\n\nsection distrib_lattice\n\nvariables [distrib_lattice P]\nvariables {I J : ideal P}\n\nlemma eq_sup_of_le_sup {x i j: P} (hi : i \u2208 I) (hj : j \u2208 J) (hx : x \u2264 i \u2294 j):\n\u2203 (i' \u2208 I) (j' \u2208 J), x = i' \u2294 j' :=\nbegin\n  refine \u27e8x \u2293 i, I.mem_of_le inf_le_right hi, x \u2293 j, J.mem_of_le inf_le_right hj, _\u27e9,\n  calc\n  x    = x \u2293 (i \u2294 j)       : left_eq_inf.mpr hx\n  ...  = (x \u2293 i) \u2294 (x \u2293 j) : inf_sup_left,\nend\n\nlemma coe_sup_eq : \u2191(I \u2294 J) = {x | \u2203 i \u2208 I, \u2203 j \u2208 J, x = i \u2294 j} :=\nbegin\n  ext,\n  rw [mem_coe, mem_sup],\n  exact \u27e8\u03bb \u27e8_, _, _, _, _\u27e9, eq_sup_of_le_sup \u2039_\u203a \u2039_\u203a \u2039_\u203a,\n  \u03bb \u27e8i, _, j, _, _\u27e9, \u27e8i, \u2039_\u203a, j, \u2039_\u203a, le_of_eq \u2039_\u203a\u27e9\u27e9\nend\n\nend distrib_lattice\n\nsection boolean_algebra\n\nvariables [boolean_algebra P] {x : P} {I : ideal P}\n\nlemma is_proper.not_mem_of_compl_mem (hI : is_proper I) (hxc : x\u1d9c \u2208 I) : x \u2209 I :=\nbegin\n  intro hx,\n  apply hI.top_not_mem,\n  have ht : x \u2294 x\u1d9c \u2208 I := sup_mem _ _ \u2039_\u203a \u2039_\u203a,\n  rwa sup_compl_eq_top at ht,\nend\n\nlemma is_proper.not_mem_or_compl_not_mem (hI : is_proper I) : x \u2209 I \u2228 x\u1d9c \u2209 I :=\nhave h : x\u1d9c \u2208 I \u2192 x \u2209 I := hI.not_mem_of_compl_mem, by tauto\n\nend boolean_algebra\n\nend ideal\n\n/-- For a preorder `P`, `cofinal P` is the type of subsets of `P`\n  containing arbitrarily large elements. They are the dense sets in\n  the topology whose open sets are terminal segments. -/\nstructure cofinal (P) [preorder P] :=\n(carrier : set P)\n(mem_gt  : \u2200 x : P, \u2203 y \u2208 carrier, x \u2264 y)\n\nnamespace cofinal\n\nvariables [preorder P]\n\ninstance : inhabited (cofinal P) :=\n\u27e8{ carrier := set.univ, mem_gt := \u03bb x, \u27e8x, trivial, le_refl _\u27e9 }\u27e9\n\ninstance : has_mem P (cofinal P) := \u27e8\u03bb x D, x \u2208 D.carrier\u27e9\n\nvariables (D : cofinal P) (x : P)\n/-- A (noncomputable) element of a cofinal set lying above a given element. -/\nnoncomputable def above : P := classical.some $ D.mem_gt x\n\nlemma above_mem : D.above x \u2208 D :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb a _, a\n\nlemma le_above : x \u2264 D.above x :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb _ b, b\n\nend cofinal\n\nsection ideal_of_cofinals\n\nvariables [preorder P] (p : P) {\u03b9 : Type*} [encodable \u03b9] (\ud835\udc9f : \u03b9 \u2192 cofinal P)\n\n/-- Given a starting point, and a countable family of cofinal sets,\n  this is an increasing sequence that intersects each cofinal set. -/\nnoncomputable def sequence_of_cofinals : \u2115 \u2192 P\n| 0 := p\n| (n+1) := match encodable.decode \u03b9 n with\n           | none   := sequence_of_cofinals n\n           | some i := (\ud835\udc9f i).above (sequence_of_cofinals n)\n           end\n\nlemma sequence_of_cofinals.monotone : monotone (sequence_of_cofinals p \ud835\udc9f) :=\nby { apply monotone_nat_of_le_succ, intros n, dunfold sequence_of_cofinals,\n  cases encodable.decode \u03b9 n, { refl }, { apply cofinal.le_above }, }\n\nlemma sequence_of_cofinals.encode_mem (i : \u03b9) :\n  sequence_of_cofinals p \ud835\udc9f (encodable.encode i + 1) \u2208 \ud835\udc9f i :=\nby { dunfold sequence_of_cofinals, rw encodable.encodek, apply cofinal.above_mem, }\n\n/-- Given an element `p : P` and a family `\ud835\udc9f` of cofinal subsets of a preorder `P`,\n  indexed by a countable type, `ideal_of_cofinals p \ud835\udc9f` is an ideal in `P` which\n  - contains `p`, according to `mem_ideal_of_cofinals p \ud835\udc9f`, and\n  - intersects every set in `\ud835\udc9f`, according to `cofinal_meets_ideal_of_cofinals p \ud835\udc9f`.\n\n  This proves the Rasiowa\u2013Sikorski lemma. -/\ndef ideal_of_cofinals : ideal P :=\n{ carrier   := { x : P | \u2203 n, x \u2264 sequence_of_cofinals p \ud835\udc9f n },\n  nonempty  := \u27e8p, 0, le_refl _\u27e9,\n  directed  := \u03bb x \u27e8n, hn\u27e9 y \u27e8m, hm\u27e9,\n               \u27e8_, \u27e8max n m, le_refl _\u27e9,\n               le_trans hn $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_left _ _),\n               le_trans hm $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_right _ _) \u27e9,\n  mem_of_le := \u03bb x y hxy \u27e8n, hn\u27e9, \u27e8n, le_trans hxy hn\u27e9, }\n\nlemma mem_ideal_of_cofinals : p \u2208 ideal_of_cofinals p \ud835\udc9f := \u27e80, le_refl _\u27e9\n\n/-- `ideal_of_cofinals p \ud835\udc9f` is `\ud835\udc9f`-generic. -/\nlemma cofinal_meets_ideal_of_cofinals (i : \u03b9) : \u2203 x : P, x \u2208 \ud835\udc9f i \u2227 x \u2208 ideal_of_cofinals p \ud835\udc9f :=\n\u27e8_, sequence_of_cofinals.encode_mem p \ud835\udc9f i, _, le_refl _\u27e9\n\nend ideal_of_cofinals\n\nend order\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/order/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541611, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7071971430766557}}
{"text": "import set_theory.cardinal\nimport tactic\n\nvariables {\u03b1 \u03b2 : Type}\n\n-- Definition 5.1 (Enumeration, set-theoretic). An enumeration of a set A is a\n-- bijection whose range is A and whose domain is either an initial set of\n-- natural numbers {0, 1, ..., n} or the entire set of natural numbers \u2115.\n--\n-- Definition 5.2. A set A is countable iff either A = \u2205 or there is an\n-- enumeration of A. We say that A is uncountable iff A is not countable.\ndef countable (\u03b1 : Type) := \u2203 f : \u03b1 \u2192 \u2115, function.injective f\n\nexample : countable \u2115 := \u27e8id, function.injective_id\u27e9\n\ndef countable' (\u03b1 : Type) := \u2203 f : \u2115 \u2192 \u03b1, function.surjective f\n\nnoncomputable example : nonempty \u03b1 \u2192 \u03b1 := nonempty.some\n\n#check @function.inv_fun\n#check @function.inv_fun_surjective\n\n-- Problem 5.1. Show that a set A is countable iff either A = \u2205 or there is a\n-- surjection f : \u2115 \u2192 A. Show that A is countable iff there is an injection\n-- g : A \u2192 \u2115.\nlemma problem_5_1_a [nonempty \u03b1] : countable \u03b1 \u2192 countable' \u03b1 :=\nbegin\n  rintro \u27e8f, hf\u27e9,\n  change \u2203 g, function.surjective g,\n  let g := function.inv_fun f,\n  have hg := function.inv_fun_surjective hf,\n  exact \u27e8g, hg\u27e9\nend\n\nlemma problem_5_1_b : countable' \u03b1 \u2192 countable \u03b1 :=\nbegin\n  rintro \u27e8f, hf\u27e9,\n  let g := \u03bb x, classical.some (hf x),\n  use g,\n  intros x y h,\n  have := classical.some_spec (hf x),\n  rw \u2190this, clear this,\n  have := classical.some_spec (hf y),\n  rw \u2190this, clear this,\n  simp only [g] at h,\n  rw h\nend\n\nlemma countable_iff_countable' [nonempty \u03b1] : countable \u03b1 \u2194 countable' \u03b1 :=\n\u27e8problem_5_1_a, problem_5_1_b\u27e9\n\n-- Theorem 5.10. \u2118(\u2115) is not countable.\ntheorem theorem_5_10 : \u00accountable (set \u2115) :=\nbegin\n  rw countable_iff_countable',\n  rintro \u27e8f, hf\u27e9,\n  unfold function.surjective at hf,\n  let s := {x | x \u2209 f x},\n  obtain \u27e8x, hx\u27e9 := hf s,\n  have : x \u2208 s,\n  { intro h,\n    sorry },\n  sorry\nend\n\nset_option pp.universes true\n#check @cardinal.mk\nset_option pp.universes false\n\nprefix # := cardinal.mk\n\n#check @function.inv_fun\n#check @function.inv_fun_surjective\n\n-- Theorem 5.16 (Cantor). A \u227a \u2118(A), for any set A.\ntheorem theorem_5_16 : #\u03b1 < #(set \u03b1) :=\nbegin\n  change _ \u2227 _,\n  split,\n  { let f : \u03b1 \u2192 set \u03b1 := \u03bb x, {x},\n    use f,\n    intros x y h,\n    simpa using h },\n  { rintro \u27e8f, hf\u27e9,\n    let g := function.inv_fun f,\n    have hg := function.inv_fun_surjective hf,\n    let s := {x | x \u2209 g x},\n    obtain \u27e8x, hx\u27e9 := hg s,\n    have : x \u2208 s \u2194 x \u2208 g x, by rw \u2190hx,\n    simp only [set.mem_set_of_eq] at this,\n    simpa }\nend\n\n#check @bit0\n#check @bit1\n\nvariables (x : \u03b1 \u2295 \u03b2) (f : \u03b1 \u2192 \u2115)\n\n#check @sum.cases_on _ _ (\u03bb _, \u2115) x f\n\n-- Problem 5.3. Show that if A and B are countable, so is A \u222a B.\nlemma problem_5_3 (h\u03b1 : countable \u03b1) (h\u03b2 : countable \u03b2) : countable (\u03b1 \u2295 \u03b2) :=\nbegin\n  obtain \u27e8f\u03b1, hf\u03b1\u27e9 := h\u03b1,\n  obtain \u27e8f\u03b2, hf\u03b2\u27e9 := h\u03b2,\n  change \u2203 f, _,\n  let encode : \u03b1 \u2295 \u03b2 \u2192 \u2115 :=\n    \u03bb x, @sum.cases_on _ _ (\u03bb _, \u2115) x (bit0 \u2218 f\u03b1) (bit1 \u2218 f\u03b2),\n  use encode,\n  intros x y h,\n  cases x; cases y,\n  { rw nat.bit0_eq_bit0 at h,\n    rw (hf\u03b1 h) },\n  { simpa [encode] using h },\n  { simpa [encode] using h },\n  { rw nat.bit1_eq_bit1 at h,\n    rw (hf\u03b2 h) }\nend\n\n-- Problem 5.16. Show that the set of all functions f : \u2115 \u2192 \u2115 is uncountable by\n-- an explicit diagonal argument. That is, show that if f_1, f_2, ..., is a\n-- list of functions and each f_i : \u2115 \u2192 \u2115, then there is some g : \u2115 \u2192 \u2115 not on\n-- this list.\nlemma problem_5_16 : \u00ac countable (\u2115 \u2192 \u2115) :=\nbegin\n  rw countable_iff_countable',\n  rintro \u27e8f, hf\u27e9,\n  unfold function.surjective at hf,\n  let g : \u2115 \u2192 \u2115 := \u03bb x, f x x + 1,\n  obtain \u27e8x, hx\u27e9 := hf g,\n  suffices : \u2203 y, f x y \u2260 g y,\n  { obtain \u27e8y, hy\u27e9 := this,\n    rw hx at hy,\n    apply hy,\n    refl },\n  use x,\n  simp\nend\n\n-- Problem 5.17. Show that if there is an injective function g : B \u2192 A, and B\n-- is uncountable, then so is A. Do this by showing how you can use g to turn\n-- an enumeration of A into one of B.\nlemma problem_5_17 {g : \u03b2 \u2192 \u03b1} (hg : function.injective g) (h : \u00ac countable \u03b2) :\n  \u00ac countable \u03b1 :=\nbegin\n  rintro \u27e8f, hf\u27e9,\n  apply h,\n  clear h,\n  change \u2203 f, _,\n  use f \u2218 g,\n  exact function.injective.comp hf hg\nend\n\n-- Problem 5.25. Show that there cannot be an injection g : \u2118(A) \u2192 A, for any\n-- set A. Hint: Suppose g : \u2118(A) \u2192 A is injective. Consider\n-- D = {g(B) : B \u2286 A and g(B) \u2209 B}. Let x = g(D). Use the fact that g is\n-- injective to derive a contradiction.\nlemma problem_5_25 : \u00ac \u2203 f : set \u03b1 \u2192 \u03b1, function.injective f :=\nbegin\n  rintro \u27e8f, hf\u27e9,\n  let s := f <$> {x | f x \u2209 x},\n  let x := f s,\n  change \u2200 \u2983x y\u2984, f x = f y \u2192 x = y at hf,\n  sorry\nend", "meta": {"author": "pedrominicz", "repo": "logic", "sha": "0945200787b9ab8ca8e8f91e2c8de7e7a75efe3a", "save_path": "github-repos/lean/pedrominicz-logic", "path": "github-repos/lean/pedrominicz-logic/logic-0945200787b9ab8ca8e8f91e2c8de7e7a75efe3a/src/set_theory_an_open_introduction/05_the_size_of_sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7071971419287899}}
{"text": "namespace sf_basics\n\ninductive day : Type \n| monday : day\n| tuesday : day\n| wednesday : day\n| thursday : day\n| friday : day\n| saturday : day\n| sunday : day.\n\ninductive day1 : Type \n| monday \n| tuesday\n| wednesday\n| thursday\n| friday\n| saturday\n| sunday.\n#check day1.monday\n\ndef next_weekday : day \u2192 day \n| day.monday := day.tuesday\n| day.tuesday := day.wednesday\n| day.wednesday := day.thursday\n| day.thursday := day.friday\n| day.friday := day.saturday\n| day.saturday := day.sunday\n| day.sunday := day.monday.\n\n#reduce next_weekday day.friday\n#reduce next_weekday day.saturday\n\nexample : (next_weekday (next_weekday day.saturday)) = day.monday\n        := by {reflexivity}\n\ninductive bool : Type \n| true \n| false\n\nnamespace bool\ndef negb : bool \u2192 bool \n| true := false\n| false := true.\n\ndef andb : bool \u2192 bool \u2192 bool\n| true b\u2082 := b\u2082 \n| false _ := false.\n\ndef orb : bool \u2192 bool \u2192 bool\n| true _ := true\n| false b\u2082 := b\u2082.\n\nexample : (orb true false) = true := \n    by { reflexivity }\n\nexample : (orb false false) = false :=\n    by { reflexivity }\n\nexample : (orb false true) = true := \n    by { reflexivity }\n\nexample : (orb true true) = true :=\n    by { reflexivity }\n\nnotation x `&&` y := (andb x y)\nnotation x `||` y := (orb x y)\n\nexample : false || false || true = true :=\n    by { reflexivity }\n\ndef nandb (x y: bool):  bool := negb (x && y)\n\nexample : (nandb true false) = true :=\n    by { reflexivity }\nexample : (nandb false false) = true :=\n    by { reflexivity }\nexample : (nandb false true) = true :=\n    by { reflexivity }\nexample : (nandb true true) = false :=\n    by { reflexivity }\n\ndef andb3 (x y z : bool) : bool := x && y && z\n\nexample : (andb3 true true true) = true :=\n    by { reflexivity }\nexample : (andb3 false true true) = false :=\n    by { reflexivity }\nexample : (andb3 true false true) = false :=\n    by { reflexivity }\nexample : (andb3 true true false) = false :=\n    by { reflexivity }.\n\n#check true\n#check (negb true)\n#check negb\n#check true\nend bool\nnamespace compound\nopen sf_basics.bool\n--Compound types\ninductive rgb : Type \n| red : rgb \n| green : rgb\n| blue : rgb.\n\ninductive color : Type \n| black : color\n| white : color\n| primary : rgb \u2192 color.\n\ndef monochrome (c:color) : color \u2192 bool \n| color.black := true\n| color.white := true\n| (color.primary p) := false.\n\ndef isred : color \u2192 bool\n| color.black := false\n| color.white := false\n| (color.primary rgb.red) := true\n| (color.primary _) := false.\nend compound\n\ninductive nat : Type\n| O\n| S : nat \u2192 nat\n\n\nnamespace nat\nopen sf_basics.bool\n#check O\n\ndef pred : nat \u2192 nat\n| O := O\n| (S n') := n'\n\n@[simp] def succn : nat \u2192 nat\n| O := S O\n| (S n') := S (S n')\n\n#reduce pred (S (S (S (S O))))\n\ndef minustwo : nat \u2192 nat \n| O := O\n| (S O) := O\n| (S (S n')) := n'\n\n#reduce minustwo (S (S (S (S O))))\n\ndef evenb : nat \u2192 bool \n| O := true\n| (S O) := false\n| (S (S n')) := evenb n'\n\n#reduce evenb (S (S (S (S O))))\n#reduce evenb (S (S (S O)))\n\ndef oddb (n:nat) : bool := negb (evenb n)\n\nexample : oddb (S O) = true := by {reflexivity}\nexample : oddb (S (S (S (S O)))) = false := by {reflexivity}\n\ndef plus : nat \u2192 nat \u2192 nat\n| O m := m\n| (S n') m := S (plus n' m)\n\n#reduce plus (S (S (S O))) (S (S O)) \n\ndef mult : nat \u2192 nat \u2192 nat\n| O _ := O\n| (S n') m := plus m (mult n' m)\n\n@[simp] def n_to_nat : \u2115 \u2192 nat \n| 0 := O\n| (nat.succ n') := S (n_to_nat n')\n\n@[simp] def nat_to_n : nat \u2192 \u2115 \n| O := 0\n| (S n') := nat.succ (nat_to_n n')\n\n#reduce nat_to_n (S (S (S O)))\n\nlemma n_to_nat_to_n : \u2200 x : \u2115, nat_to_n (n_to_nat x) = x :=\nby {intros, induction x; simp [*, n_to_nat, nat_to_n]}\n\nexample : (mult (S (S (S O))) (S (S (S O)))) = n_to_nat 9 :=\n    by { reflexivity }\n\ndef minus : nat \u2192 nat \u2192 nat \n| O _ := O\n| (S n) O := n\n| (S n') (S m') := minus n' m'\n\ndef exp : nat \u2192 nat \u2192 nat\n| _ O := S O\n| base (S p) := mult base (exp base p)\n\ndef factorial : nat \u2192 nat \n| O := (S O)\n| (S n) := mult (S n) (factorial n)\n\nexample : factorial (n_to_nat 3) = n_to_nat 6 :=\n    by {reflexivity}\n\nexample : factorial (n_to_nat 5) = n_to_nat 120 :=\n    by {reflexivity}\n\nexample : factorial (n_to_nat 5) = mult (n_to_nat 10) (n_to_nat 12) :=\n    by {reflexivity}\n\nnotation x `+` y := plus x y\nnotation x `-` y := minus x y\nnotation x `*` y := mult x y\nnotation x `!!` := factorial x\n\nexample : factorial (n_to_nat 5) = (n_to_nat 10) * (n_to_nat 12) :=\n    by {reflexivity}\n\nexample : (n_to_nat 5) !! = (n_to_nat 10) * (n_to_nat 12) :=\n    by {reflexivity}\n\ndef beq_nat : nat \u2192 nat \u2192 bool\n| O O := true\n| O m := false\n| m O := false\n| (S n') (S m') := beq_nat n' m'\n\ndef leb : nat \u2192 nat \u2192 bool\n| O _ := true\n| _ O := false\n| (S n') (S m') := leb n' m'\n\nexample : leb (n_to_nat 2) (n_to_nat 2) = true :=\n    by {reflexivity}\n\nexample : leb (n_to_nat 2) (n_to_nat 4) = true :=\n    by {reflexivity}\n\nexample : leb (n_to_nat 4) (n_to_nat 2) = false :=\n    by {reflexivity}\n\ndef blt_nat (n m : nat) : bool := (leb n m) && negb (beq_nat n m)\n\nexample : blt_nat (n_to_nat 2) (n_to_nat 2) = false :=\n    by {reflexivity}\n\nexample : blt_nat (n_to_nat 2) (n_to_nat 4) = true :=\n    by {reflexivity}\n\nexample : blt_nat (n_to_nat 4) (n_to_nat 2) = false :=\n    by {reflexivity}\n\ntheorem plus_O_n : \u2200 n : nat, O + n = n :=\nby {intros, simp [plus]}\n\nnamespace h1\ntheorem plus_O_n : \u2200 n : nat, O + n = n :=\nby {intros, reflexivity}\nend h1\n\ntheorem plus_1_n : \u2200 n : nat, (S O) + n = S n := \nby {intros, simp [plus]}\n\ntheorem mult_O_n : \u2200 n : nat, O * n = O := \nby {intros, simp [mult]}\n\ntheorem plus_id_example : \u2200 n m : nat,\n    n = m \u2192 n+n =m+m :=\nby {\n    intros n m h, \n    rw h\n}\n\ntheorem plus_id_example1 : \u2200 n m : nat,\n    n = m \u2192 n+n =m+m :=\nby {intros, simp [*]}\n\ntheorem plus_id_exercise : \u2200 n m o : nat,\n    n = m \u2192 m=o \u2192 n + m = m + o\n:= by {\n    intros n m o h\u2081 h\u2082,\n    rw h\u2081, rw h\u2082,\n}\n\ntheorem plus_id_exercise1 : \u2200 n m o : nat,\n    n = m \u2192 m=o \u2192 n + m = m + o\n:= by { intros, simp [*] }\n\ntheorem mult_O_plus : \u2200 n m : nat,\n    (O + n) * m = n * m\n:= by {intros, rw plus_O_n}\n\ntheorem mult_O_plus1 : \u2200 n m : nat,\n    (O + n) * m = n * m\n:= by {intros, simp [plus_O_n]}\n\ntheorem mult_S_1 : forall n m : nat,\n    m = S n \u2192 m * ((S O) + n) = m * m\n:= by { intros, rw plus_1_n, rw \u2190 a }\n\n\ntheorem mult_S_11 : forall n m : nat,\n    m = S n \u2192 m * ((S O) + n) = m * m\n:= by { intros, rw plus_1_n, rw a}\n\ntheorem mult_S_12 : forall n m : nat,\n    m = S n \u2192 m * ((S O) + n) = m * m\n:= by { intros, simp [*, plus_1_n]}\n\ntheorem mult_S_13 : forall n m : nat,\n    m = S n \u2192 m * ((S O) + n) = m * m\n:= by { intros, simp *, reflexivity}\n\ntheorem plus_1_neg_O : \u2200 n : nat,\n    beq_nat (n + (S O)) O = false\n:= by {\n    intros, \n    cases n, \n        { reflexivity },\n        { reflexivity }\n}\n\ntheorem plus_1_neg_O1 : \u2200 n : nat,\n    beq_nat (n + (S O)) O = false\n:= by {intros, cases n; reflexivity}\n\ntheorem negb_involutive : \u2200 b : bool,\n    negb (negb b) = b\n:= by { intros, cases b, reflexivity, reflexivity }\n\ntheorem negb_involutive1 : \u2200 b : bool,\n    negb (negb b) = b\n:= by { intros, cases b; reflexivity}\n\ntheorem andb_commutative : \u2200 b c, andb b c = andb c b\n:= by {\n    intros, \n    cases b,\n        cases c,\n            reflexivity,\n            reflexivity,\n        cases c,\n            reflexivity,\n            reflexivity\n}\n\ntheorem andb_commutative1 : \u2200 b c, andb b c = andb c b\n:= by {\n    intros, \n    cases b,\n    { cases c,\n        { reflexivity },\n        { reflexivity }},\n    { cases c,\n        { reflexivity },\n        { reflexivity }}}\n\ntheorem andb_commutative2 : \u2200 b c, andb b c = andb c b\n:= by {intros, cases b; cases c; reflexivity}\n\ntheorem andb3_exchange : \u2200 b c d,\n    andb (andb b c) d = andb (andb b d) c\n:= by {\n    intros, cases b; cases c; cases d; reflexivity\n}\n\ntheorem andb3_exchange1 : \u2200 b c d,\n    andb (andb b c) d = andb (andb b d) c\n:= by {\n    intros,\n    destruct b,\n    {   intros, rw a,\n        destruct c,\n        {\n            intros, rw a_1,\n            destruct d,\n            { intros, rw a_2 },\n            { intros, rw a_2, reflexivity }\n        },\n        {\n            intros, rw a_1,\n            destruct d,\n            { intros, rw a_2, reflexivity },\n            { intros, rw a_2 }\n        }\n    },\n    {   intros, rw a,\n        destruct c,\n        {\n            intros, rw a_1,\n            destruct d,\n            { intros, rw a_2 },\n            { intros, rw a_2, reflexivity }\n        },\n        {\n            intros, rw a_1,\n            destruct d,\n            { intros, rw a_2, reflexivity },\n            { intros, rw a_2 }\n        }\n    }\n}\n\ntheorem andb3_exchange2 : \u2200 b c d,\n    andb (andb b c) d = andb (andb b d) c\n:=  by {\n    intros, destruct b; { \n        intros, rw a, destruct c; { \n            intros, rw a_1, destruct d; {\n                intros, { rw a_2, reflexivity } <|> rw a_2 } } } \n}\n\ntheorem andb3_exchange3 : \u2200 b c d,\n    andb (andb b c) d = andb (andb b d) c\n:=  by {\n    intros, destruct b; { \n        intros, rw a, destruct c; { \n            intros, rw a_1, destruct d; {\n                intros, rw a_2, try { reflexivity } } } } \n}\n\ntheorem andb_true_elim2 : \u2200 b c : bool,\n    andb b c = true \u2192 c = true \n:= by {\n    intros b c,\n    cases b,\n        cases c, \n            { intro, reflexivity },\n            { simp [andb] },\n        cases c,\n            { simp [andb] },\n            { simp [andb] }\n}\n\ntheorem andb_true_elim21 : \u2200 b c : bool,\n    andb b c = true \u2192 c = true \n:= by {\n    intros b c, cases b; cases c; {simp [andb], try {intro, assumption}}\n}\n\ntheorem zero_nbeq_plus_1 : \u2200 n : nat,\n    beq_nat O ( n + (S O)) = false\n:= by { intros, cases n; reflexivity }\n\ndef plus' : nat \u2192 nat \u2192 nat \n| n O := n\n| n (S m') := S (plus' n m')\n\n-- def lim : \u2115 \u2192 \u2115 \n-- | 5 := 5\n-- | n := if n > 5 then lim n-1 else lim n+1\n\ntheorem identity_fn_applied_twice :\n    \u2200 f : bool \u2192 bool, (\u2200 x : bool, f x = x) \u2192 \u2200 b : bool, f (f b) = b\n:= by { intros, cases b; simp [*] }\n\ntheorem identity_fn_applied_twice1 :\n    \u2200 f : bool \u2192 bool, (\u2200 x : bool, f x = x) \u2192 \u2200 b : bool, f (f b) = b\n:= by { intros, rw a, rw a }\n\ntheorem identity_fn_applied_twice2 :\n    \u2200 f : bool \u2192 bool, (\u2200 x : bool, f x = x) \u2192 \u2200 b : bool, f (f b) = b\n:= by { intros, repeat {rw a} }\n\ntheorem negation_fn_applied_twice :\n    \u2200 f : bool \u2192 bool, (\u2200 x : bool, f x = negb x) \u2192 \u2200 b : bool, f (f b) = b\n:= by { intros, repeat { rw a }, simp [negb_involutive] }\n\ntheorem negation_fn_applied_twice1 :\n    \u2200 f : bool \u2192 bool, (\u2200 x : bool, f x = negb x) \u2192 \u2200 b : bool, f (f b) = b\n:= by { intros, repeat { rw a }, apply negb_involutive }\n\ntheorem andb_eq_orb :\n    \u2200 ( b c : bool), (andb b c = orb b c) \u2192 b = c\n:= by { intros b c, cases b; cases c; simp [andb, orb]; intro; rw a }\n\n\n\nend nat\n\ninductive bin : Type \n| zero\n| twice : bin \u2192 bin\n| twicep1 : bin \u2192 bin\n\nnamespace bin\nopen sf_basics.nat\n@[simp] def incr : bin \u2192 bin\n| zero          := twicep1 zero\n| (twice n)     := twicep1 n\n| (twicep1 n)   := twice (incr n)\n\n@[simp] def bin_to_nat : bin \u2192 nat\n| zero          := O\n| (twice n)     := (S (S O)) * (bin_to_nat n)\n| (twicep1 n)   := ((S (S O)) * (bin_to_nat n)) + (S O)\n\ndef one     : bin := (twicep1 zero)\ndef two     : bin := (twice (twicep1 zero))\ndef three   : bin := (twicep1 (twicep1 zero))\ndef four    : bin := (twice (twice (twicep1 zero)))\n\nexample : bin_to_nat zero   = O                 := by { reflexivity }\nexample : bin_to_nat one    = S O               := by { reflexivity }\nexample : bin_to_nat two    = S (S O)           := by { reflexivity }\nexample : bin_to_nat three  = S (S (S O))       := by { reflexivity }\nexample : bin_to_nat four   = S( S (S (S O)))   := by { reflexivity }\n\nexample : bin_to_nat(incr zero) = S O                   := by {reflexivity}\nexample : bin_to_nat(incr one)  = S (S O)               := by {reflexivity}\nexample : bin_to_nat(incr two)  = S (S (S O))           := by {reflexivity}\nexample : bin_to_nat(incr three)= S (S (S (S O)))       := by {reflexivity}\nexample : bin_to_nat(incr four) = S (S (S (S (S O))))   := by {reflexivity}\n\ntheorem plus_n_O : \u2200 n, n + O = n :=\nby { intros, induction n; simp[*, plus]}\n\nlemma p1_sa_left1 : \u2200 a,  S O + a = S a := by { intros, simp [plus] }\nlemma p1_sa_left2 : \u2200 a, a + S O = S a := by { intros, induction a; simp [*, plus] }\n\nlemma succ_n_n1 : \u2200 x : nat,  succn x = x + S O := \nby {intros, cases x, reflexivity, simp [succn, plus], rw p1_sa_left2 }\n\ntheorem succ_comm : \u2200 x y : nat,  S x + y = S (x + y) :=\nby {intros,\n    induction y,\n    reflexivity,\n    simp [plus] }\n\ntheorem plus_1_n : \u2200 x : nat, S O + x = S (x) := by {intros, reflexivity}\ntheorem plus_n_1 : \u2200 x : nat, x + S O = S (x) := by {intros, induction x, reflexivity, simp [*, succ_comm]}\n\ntheorem succ_com1 : \u2200 x y : nat,  x + S y = S (x + y) :=\nby {\n    intros,\n    induction x,\n        reflexivity,\n        symmetry, rw succ_comm, rw \u2190 ih_1, symmetry, rw succ_comm\n}\n\ntheorem commutativity : \u2200 x y : nat, x + y = y + x :=\nby {\n    intros,\n    induction x generalizing y,\n    {simp [plus_O_n], rw plus_n_O },\n    simp [plus], symmetry,\n        induction y, \n            simp [plus_O_n, plus_n_O],\n            simp [plus], rw ih_1_1, symmetry, simp [*, plus]\n}\n\nlemma small_assoc : \u2200 x y z : nat, x + y + z = x + (y + z) :=\nby {\n    intros,\n    induction x generalizing y z,\n    reflexivity,\n    simp [commutative, succ_comm], rw ih_1\n}\n\ntheorem associativity : \u2200 x y z : nat, (x + y) + z = x + (y + z) :=\nby {\n    intros,\n    induction z generalizing x y,\n        simp [plus_n_O],\n        simp [commutativity, succ_comm, small_assoc], \n}\n\nlemma shuffling : \u2200 x y z : nat, x + y + z = x + z + y := \nby {\n    intros, induction x, \n        simp [plus_O_n, commutativity],\n        simp [commutativity, succ_com1], \n            rw commutativity, rw associativity, rw commutativity, rw \u2190 ih_1,\n            symmetry, rw commutativity, rw associativity, rw commutativity\n}\n\ntheorem distributivity : \u2200 x y z: nat, x*(y + z) = x*y + x*z :=\nby {\n    intros, induction x generalizing z y, \n    {reflexivity}, \n    simp [*, mult], rw \u2190 small_assoc, symmetry, rw \u2190 associativity, rw shuffling, rw commutativity, rw associativity, simp [commutativity, associativity],\n}\n\nlemma mult_n_1 : \u2200 x : nat, x * S O = x := \nby {\n    intros, induction x,\n        reflexivity,\n        simp [mult], rw ih_1, simp [plus_1_n]\n}\n\nlemma plus_1_1 : S O + S O = S (S O) :=\nby {reflexivity}\n\ntheorem same_result : \u2200 b : bin, bin_to_nat (incr b) = succn (bin_to_nat b) :=\nby {\n    intros,\n    induction b,\n    reflexivity,\n    simp [*], rw \u2190 succn, generalize h : succn (S O) * bin_to_nat a = x, simp [succ_n_n1],\n    simp [*, succ_n_n1, distributivity, mult_n_1], simp [associativity], reflexivity\n}\n\n\nend bin\n\n\nend sf_basics", "meta": {"author": "teodorov", "repo": "sf_lean", "sha": "cd4832d6bee9c606014c977951f6aebc4c8d611b", "save_path": "github-repos/lean/teodorov-sf_lean", "path": "github-repos/lean/teodorov-sf_lean/sf_lean-cd4832d6bee9c606014c977951f6aebc4c8d611b/sf_basics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.7071937677194617}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.linear.yoneda\n! leanprover-community/mathlib commit 09f981f72d43749f1fa072deade828d9c1e185bb\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Category.Module.Basic\nimport Mathbin.CategoryTheory.Linear.Basic\nimport Mathbin.CategoryTheory.Preadditive.Yoneda.Basic\n\n/-!\n# The Yoneda embedding for `R`-linear categories\n\nThe Yoneda embedding for `R`-linear categories `C`,\nsends an object `X : C` to the `Module R`-valued presheaf on `C`,\nwith value on `Y : C\u1d52\u1d56` given by `Module.of R (unop Y \u27f6 X)`.\n\nTODO: `linear_yoneda R C` is `R`-linear.\nTODO: In fact, `linear_yoneda` itself is additive and `R`-linear.\n-/\n\n\nuniverse w v u\n\nopen Opposite\n\nnamespace CategoryTheory\n\nvariable (R : Type w) [Ring R] (C : Type u) [Category.{v} C] [Preadditive C] [Linear R C]\n\n/-- The Yoneda embedding for `R`-linear categories `C`,\nsending an object `X : C` to the `Module R`-valued presheaf on `C`,\nwith value on `Y : C\u1d52\u1d56` given by `Module.of R (unop Y \u27f6 X)`. -/\n@[simps]\ndef linearYoneda : C \u2964 C\u1d52\u1d56 \u2964 ModuleCat R\n    where\n  obj X :=\n    { obj := fun Y => ModuleCat.of R (unop Y \u27f6 X)\n      map := fun Y Y' f => Linear.leftComp R _ f.unop\n      map_comp' := fun _ _ _ f g => LinearMap.ext fun _ => Category.assoc _ _ _\n      map_id' := fun Y => LinearMap.ext fun _ => Category.id_comp _ }\n  map X X' f :=\n    { app := fun Y => Linear.rightComp R _ f\n      naturality' := fun X Y f =>\n        LinearMap.ext fun x => by\n          simp only [category.assoc, ModuleCat.coe_comp, Function.comp_apply,\n            linear.left_comp_apply, linear.right_comp_apply] }\n  map_id' X :=\n    NatTrans.ext _ _ <|\n      funext fun _ =>\n        LinearMap.ext fun _ => by\n          simp only [linear.right_comp_apply, category.comp_id, nat_trans.id_app,\n            ModuleCat.id_apply]\n  map_comp' _ _ _ f g :=\n    NatTrans.ext _ _ <|\n      funext fun _ =>\n        LinearMap.ext fun _ => by\n          simp only [category.assoc, linear.right_comp_apply, nat_trans.comp_app,\n            ModuleCat.coe_comp, Function.comp_apply]\n#align category_theory.linear_yoneda CategoryTheory.linearYoneda\n\n/-- The Yoneda embedding for `R`-linear categories `C`,\nsending an object `Y : C\u1d52\u1d56` to the `Module R`-valued copresheaf on `C`,\nwith value on `X : C` given by `Module.of R (unop Y \u27f6 X)`. -/\n@[simps]\ndef linearCoyoneda : C\u1d52\u1d56 \u2964 C \u2964 ModuleCat R\n    where\n  obj Y :=\n    { obj := fun X => ModuleCat.of R (unop Y \u27f6 X)\n      map := fun Y Y' => Linear.rightComp _ _\n      map_id' := fun Y => LinearMap.ext fun _ => Category.comp_id _\n      map_comp' := fun _ _ _ f g => LinearMap.ext fun _ => Eq.symm (Category.assoc _ _ _) }\n  map Y Y' f :=\n    { app := fun X => Linear.leftComp _ _ f.unop\n      naturality' := fun X Y f =>\n        LinearMap.ext fun x => by\n          simp only [category.assoc, ModuleCat.coe_comp, Function.comp_apply,\n            linear.right_comp_apply, linear.left_comp_apply] }\n  map_id' X :=\n    NatTrans.ext _ _ <|\n      funext fun _ =>\n        LinearMap.ext fun _ => by\n          simp only [linear.left_comp_apply, unop_id, category.id_comp, nat_trans.id_app,\n            ModuleCat.id_apply]\n  map_comp' _ _ _ f g :=\n    NatTrans.ext _ _ <|\n      funext fun _ =>\n        LinearMap.ext fun _ => by\n          simp only [category.assoc, ModuleCat.coe_comp, Function.comp_apply,\n            linear.left_comp_apply, unop_comp, nat_trans.comp_app]\n#align category_theory.linear_coyoneda CategoryTheory.linearCoyoneda\n\ninstance linearYoneda_obj_additive (X : C) : ((linearYoneda R C).obj X).Additive where\n#align category_theory.linear_yoneda_obj_additive CategoryTheory.linearYoneda_obj_additive\n\ninstance linearCoyoneda_obj_additive (Y : C\u1d52\u1d56) : ((linearCoyoneda R C).obj Y).Additive where\n#align category_theory.linear_coyoneda_obj_additive CategoryTheory.linearCoyoneda_obj_additive\n\n@[simp]\ntheorem whiskering_linearYoneda :\n    linearYoneda R C \u22d9 (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R)) = yoneda :=\n  rfl\n#align category_theory.whiskering_linear_yoneda CategoryTheory.whiskering_linearYoneda\n\n@[simp]\ntheorem whiskering_linear_yoneda\u2082 :\n    linearYoneda R C \u22d9 (whiskeringRight _ _ _).obj (forget\u2082 (ModuleCat.{v} R) AddCommGroupCat.{v}) =\n      preadditiveYoneda :=\n  rfl\n#align category_theory.whiskering_linear_yoneda\u2082 CategoryTheory.whiskering_linear_yoneda\u2082\n\n@[simp]\ntheorem whiskering_linearCoyoneda :\n    linearCoyoneda R C \u22d9 (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R)) = coyoneda :=\n  rfl\n#align category_theory.whiskering_linear_coyoneda CategoryTheory.whiskering_linearCoyoneda\n\n@[simp]\ntheorem whiskering_linear_coyoneda\u2082 :\n    linearCoyoneda R C \u22d9\n        (whiskeringRight _ _ _).obj (forget\u2082 (ModuleCat.{v} R) AddCommGroupCat.{v}) =\n      preadditiveCoyoneda :=\n  rfl\n#align category_theory.whiskering_linear_coyoneda\u2082 CategoryTheory.whiskering_linear_coyoneda\u2082\n\ninstance linearYonedaFull : Full (linearYoneda R C) :=\n  let yoneda_full :\n    Full (linearYoneda R C \u22d9 (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) :=\n    Yoneda.yonedaFull\n  full.of_comp_faithful (linear_yoneda R C)\n    ((whiskering_right _ _ _).obj (forget (ModuleCat.{v} R)))\n#align category_theory.linear_yoneda_full CategoryTheory.linearYonedaFull\n\ninstance linearCoyonedaFull : Full (linearCoyoneda R C) :=\n  let coyoneda_full :\n    Full (linearCoyoneda R C \u22d9 (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) :=\n    Coyoneda.coyonedaFull\n  full.of_comp_faithful (linear_coyoneda R C)\n    ((whiskering_right _ _ _).obj (forget (ModuleCat.{v} R)))\n#align category_theory.linear_coyoneda_full CategoryTheory.linearCoyonedaFull\n\ninstance linearYoneda_faithful : Faithful (linearYoneda R C) :=\n  Faithful.of_comp_eq (whiskering_linearYoneda R C)\n#align category_theory.linear_yoneda_faithful CategoryTheory.linearYoneda_faithful\n\ninstance linearCoyoneda_faithful : Faithful (linearCoyoneda R C) :=\n  Faithful.of_comp_eq (whiskering_linearCoyoneda R C)\n#align category_theory.linear_coyoneda_faithful CategoryTheory.linearCoyoneda_faithful\n\nend CategoryTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/CategoryTheory/Linear/Yoneda.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7071937530444109}}
{"text": "import tactic\nimport combinatorics.pigeonhole\nimport data.int.parity\nimport data.nat.factorization.basic\n\n\nlemma nat.ord_compl_eq_dvd {a b : \u2115} (h : ord_compl[2] a = ord_compl[2] b) (ha : 0 < a) (hab : a < b) :\n  a \u2223 b :=\nbegin\n  -- if a = 2^k1 * p, b = 2^k2 * p\n  set k1 : \u2115 := a.factorization 2,\n  set k2 : \u2115 := b.factorization 2,\n  rw dvd_iff_exists_eq_mul_left,\n  -- c = 2^ (k2 - k1)\n  use (2 ^ (k2 - k1)),\n  have h02 : 0 < 2 := by norm_num,\n  -- because of natural division is involved, we need divisibility\n  have had := nat.ord_proj_dvd a 2,\n  have hbd := nat.ord_proj_dvd b 2,\n  have haf := pow_pos h02 k1,\n  have hbf := pow_pos h02 k2,\n  have hab : k1 \u2264 k2,\n  { by_contra hc,\n    push_neg at hc,\n    have hc' : 2 ^ k2 < 2 ^ k1,\n    { rwa pow_lt_pow_iff,\n      norm_num, },\n    have hak : 0 < a / 2 ^ k1 := nat.div_pos (nat.ord_proj_le _ ha.ne') haf,\n    suffices : b < a,\n    { linarith, },\n    have hc'' :  2 ^ k2 * (b / 2 ^ k2) < 2 ^ k1 * (a / 2 ^ k1),\n    { rw \u2190 h, apply mul_lt_mul_of_pos_right hc' hak, },\n    rwa [mul_comm (2 ^ k2) (b / 2 ^ k2), nat.div_mul_cancel hbd, mul_comm (2 ^ k1) (a / 2 ^ k1), \n      nat.div_mul_cancel had] at hc'', },\n  rw \u2190 nat.pow_div hab h02,\n  -- again we need divisibility to proceed\n  have hkd := pow_dvd_pow 2 hab,\n  rw [mul_comm, \u2190 nat.mul_div_assoc _ hkd, mul_comm a (2^k2), nat.mul_div_assoc _ had,\n    h, mul_comm, nat.div_mul_cancel hbd],\nend\n\nlemma partf (T : finset \u2115) (hT : \u2200 t \u2208 T, (1 : \u2124) \u2264 t \u2227 t \u2264 200) (hTcard : T.card = 101) : \u2203 a b : \u2115,\n  a \u2208 T \u2227 b \u2208 T \u2227 a \u2260 b \u2227 a \u2223 b :=\nbegin\n  -- claim : every t can be written as 2^k * q for which q is odd, using ord_compl[2] t\n  let Q : finset \u2115 := (finset.Icc 1 200).filter odd,\n  have hQcard : Q.card = 100,\n  { -- Show that it equals (finset.Iio 100).map \\<\\la n, 2 * n + 1, proof_of_injectivity_here\\> \n    have hQ : Q = (finset.Iio 100).map \u27e8\u03bb n, 2 * n + 1 , \n                                        begin intros a b hab, \n                                        simpa [add_left_inj, mul_eq_mul_left_iff, bit0_eq_zero, nat.one_ne_zero, or_false] using hab, \n                                        end \u27e9,\n    { dsimp [Q],\n      rw le_antisymm_iff,\n      split,\n      { intros x hx,\n        simp only [finset.mem_map, finset.mem_Iio, function.embedding.coe_fn_mk, exists_prop, nat.one_le_cast, finset.mem_filter,\n          finset.mem_Icc, nat.odd_iff_not_even] at hx \u22a2,\n        refine \u27e8((x-1)/2), _, _\u27e9,\n        { rcases hx with \u27e8\u27e8h1, h2\u27e9, h3\u27e9,\n          zify at h2 \u22a2,\n          rw int.div_lt_iff_lt_mul,\n          linarith,\n          norm_num, },\n        { rcases hx with \u27e8\u27e8h1, h2\u27e9, h3\u27e9,\n          rw \u2190 nat.odd_iff_not_even at h3,\n          cases h3 with k h3,\n          rw h3,\n          simp only [nat.add_succ_sub_one, add_zero, nat.mul_div_right, nat.succ_pos'], },\n      },\n      { intros x hx,\n        simp only [finset.mem_map, finset.mem_Iio, function.embedding.coe_fn_mk, exists_prop, nat.one_le_cast, finset.mem_filter,\n          finset.mem_Icc, nat.odd_iff_not_even] at hx \u22a2,\n        rcases hx with \u27e8a, \u27e8h1, h2\u27e9\u27e9,\n        refine \u27e8\u27e8_, _\u27e9, _\u27e9,\n        { rw \u2190 h2,\n          linarith, },\n        { rw \u2190 h2,\n          linarith, },\n        { intro h,\n          rw [nat.even_iff, \u2190 h2, nat.mul_comm, nat.mul_add_mod a 2 1] at h,\n          simpa [nat.one_mod, nat.one_ne_zero] using h, }, \n      },\n    },\n    rw hQ,\n    simp only [nat.card_Iio, finset.card_map],\n  },\n  have hTO : Q.card * 1 < T.card,\n  { rw [hQcard, hTcard], norm_num, },\n  -- find a map from T to Q, by considering corresponding 'q'\n  let f : \u2115 \u2192 \u2115 := \u03bb z, ord_compl[2] z,\n  have hf : \u2200 t \u2208 T, (f t) \u2208 Q,\n  { intros t ht,\n    simp only [f, finset.mem_filter, finset.mem_Icc, nat.odd_iff_not_even],\n    have ht0 : t \u2260 0,\n    { specialize hT t ht, \n    cases hT with hT1 hT2, \n    linarith, }, \n    refine \u27e8\u27e8_,_\u27e9,_\u27e9,\n    { rw nat.one_le_div_iff,\n      {apply nat.ord_proj_le 2 ht0, },\n      {exact nat.ord_proj_pos t 2, }, },\n    { apply nat.div_le_of_le_mul,\n      have h1 := nat.ord_proj_pos t 2,\n      rw \u2190 nat.succ_le_iff at h1,\n      exact le_mul_of_one_le_of_le h1 (hT t ht).2, },\n    { simp only [even_iff_two_dvd, nat.not_dvd_ord_compl nat.prime_two ht0, not_false_iff], },\n  },\n  have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hf hTO,\n  dsimp at this,\n  rcases this with \u27e8y, hy1, hy2\u27e9,\n  rw finset.one_lt_card at hy2,\n  rcases hy2 with \u27e8a, ha, b, hb, hab\u27e9,\n  by_cases a < b,\n  { refine \u27e8a, b, _\u27e9,\n    simp only [hab, ne.def, not_false_iff, true_and],\n    rw finset.mem_filter at ha hb,\n    simp only [ha.1, hb.1, true_and],\n    have ha0 : 0 < a,\n    { specialize hT a ha.1,\n      cases hT with h1 h2,\n      linarith, },\n    suffices : f a = f b,\n    { apply nat.ord_compl_eq_dvd, \n      exact this,\n      exact ha0,\n      exact h, },\n    { rw [ha.2, hb.2], }, },\n  { have h : b < a,\n    { omega, },\n    refine \u27e8b, a, _\u27e9,\n    simp only [ne.symm hab, ne.def, not_false_iff, true_and],\n    rw finset.mem_filter at ha hb,\n    simp only [ha.1, hb.1, true_and],\n    have hb0 : 0 < b,\n    { specialize hT b hb.1,\n      cases hT with h1 h2,\n      linarith, },\n    suffices : f b = f a,\n    { apply nat.ord_compl_eq_dvd, \n      exact this,\n      exact hb0,\n      exact h, },\n    { rw [ha.2, hb.2], }, \n  },\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "m1fexplained_lean3", "sha": "570c9a3ff8cfc3805047f2796864516a49f51510", "save_path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3", "path": "github-repos/lean/ImperialCollegeLondon-m1fexplained_lean3/m1fexplained_lean3-570c9a3ff8cfc3805047f2796864516a49f51510/src/chapter19/exercises/exercise05-partf.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7071481422309576}}
{"text": "import data.pnat.basic\nimport data.nat.parity\nimport algebra.big_operators.basic\nimport tactic.positivity\nimport tactic.ring\nimport tactic.field_simp\n\n/-!\n# IMO 2013 Q1\n\nProve that for any pair of positive integers k and n, there exist k positive integers\nm\u2081, m\u2082, ..., m\u2096 (not necessarily different) such that\n\n  1 + (2\u1d4f - 1)/ n = (1 + 1/m\u2081) * (1 + 1/m\u2082) * ... * (1 + 1/m\u2096).\n\n# Solution\n\nAdaptation of the solution found in https://www.imo-official.org/problems/IMO2013SL.pdf\n\nWe prove a slightly more general version where k does not need to be strictly positive.\n-/\n\nopen_locale big_operators\n\nlemma prod_lemma (m : \u2115 \u2192 \u2115+) (k : \u2115) (nm : \u2115+):\n      \u220f (i : \u2115) in finset.range k, ((1 : \u211a) + 1 / \u2191(if i < k then m i else nm)) =\n      \u220f (i : \u2115) in finset.range k, (1 + 1 / m i) :=\nbegin\n  suffices : \u2200 i, i \u2208 finset.range k \u2192 (1 : \u211a) + 1 / \u2191(if i < k then m i else nm) = 1 + 1 / m i,\n  from finset.prod_congr rfl this,\n  intros i hi,\n  simp [finset.mem_range.mp hi]\nend\n\ntheorem imo2013_q1 (n : \u2115+) (k : \u2115) :\n    (\u2203 m : \u2115 \u2192 \u2115+, (1 : \u211a) + (2^k - 1) / n = (\u220f i in finset.range k, (1 + 1 / m i))) :=\nbegin\n  revert n,\n  induction k with pk hpk,\n  { intro n, use (\u03bb_, 1), simp }, -- For the base case, any m works.\n\n  intro n,\n  obtain \u27e8t, ht : \u2191n = t + t\u27e9 | \u27e8t, ht : \u2191n = 2 * t + 1\u27e9 := (n : \u2115).even_or_odd,\n  { -- even case\n    rw \u2190 two_mul at ht,\n    cases t, -- Eliminate the zero case to simplify later calculations.\n    { exfalso, rw mul_zero at ht, exact pnat.ne_zero n ht },\n\n    -- Now we have ht : \u2191n = 2 * (t + 1).\n    let t_succ : \u2115+ := \u27e8t + 1, t.succ_pos\u27e9,\n    obtain \u27e8pm, hpm\u27e9 := hpk t_succ,\n    let m := \u03bbi, if i < pk then pm i else \u27e82 * t + 2^pk.succ, by positivity\u27e9,\n    use m,\n\n    have hmpk : (m pk : \u211a) = 2 * t + 2^pk.succ,\n    { have : m pk = \u27e82 * t + 2^pk.succ, _\u27e9 := if_neg (irrefl pk), simp [this] },\n\n    have denom_ne_zero : (2 * (t:\u211a) + 2^pk.succ) \u2260 0 := by positivity,\n\n    calc (1 : \u211a) + (2 ^ pk.succ - 1) / \u2191n\n        = 1 + (2 * 2 ^ pk - 1) / (2 * (t + 1) : \u2115)    : by rw [coe_coe n, ht, pow_succ]\n    ... = (1 + 1 / (2 * t + 2 * 2^pk)) *\n          (1 + (2 ^ pk - 1) / (\u2191t + 1))               : by { field_simp [t.cast_add_one_ne_zero],\n                                                             ring }\n    ... = (1 + 1 / (2 * t + 2^pk.succ)) *\n          (1 + (2 ^ pk - 1) / t_succ)                 : by norm_cast\n    ... = (1 + 1 / \u2191(m pk)) *\n          \u220f (i : \u2115) in finset.range pk, (1 + 1 / m i) : by rw [hpm, prod_lemma, \u2190hmpk]\n    ... = \u220f (i : \u2115) in finset.range pk.succ,\n                                        (1 + 1 / m i) : (finset.prod_range_succ_comm _ pk).symm },\n  { -- odd case\n    let t_succ : \u2115+ := \u27e8t + 1, t.succ_pos\u27e9,\n    obtain \u27e8pm, hpm\u27e9 := hpk t_succ,\n    let m := \u03bbi, if i < pk then pm i else \u27e82 * t + 1, nat.succ_pos _\u27e9,\n    use m,\n\n    have hmpk : (m pk : \u211a) = 2 * t + 1,\n    { have : m pk = \u27e82 * t + 1, _\u27e9 := if_neg (irrefl pk), simp [this] },\n\n    have denom_ne_zero : (2 * (t : \u211a) + 1) \u2260 0 := by positivity,\n\n    calc (1 : \u211a) + (2 ^ pk.succ - 1) / \u2191n\n        = 1 + (2 * 2^pk - 1) / (2 * t + 1 : \u2115)        : by rw [coe_coe n, ht, pow_succ]\n    ... = (1 + 1 / (2 * t + 1)) *\n          (1 + (2^pk - 1) / (t + 1))                  : by { field_simp [t.cast_add_one_ne_zero],\n                                                             ring }\n    ... = (1 + 1 / (2 * t + 1)) *\n          (1 + (2^pk - 1) / t_succ)                   : by norm_cast\n    ... = (1 + 1 / \u2191(m pk)) *\n          \u220f (i : \u2115) in finset.range pk, (1 + 1 / m i) : by rw [hpm, prod_lemma, \u2190hmpk]\n    ... = \u220f (i : \u2115) in finset.range pk.succ,\n                                        (1 + 1 / m i) : (finset.prod_range_succ_comm _ pk).symm }\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/imo2013_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7071481351978472}}
{"text": "import ring_theory.matrix\nimport row_equivalence\nimport .finset_sum\n\nuniverses u\nvariables {m n : \u2115}\nvariable {\u03b1 : Type u}\nvariable [division_ring \u03b1]\nvariable [decidable_eq \u03b1]\n\n\ndef elementary.inv : (elementary \u03b1 m) \u2192 (elementary \u03b1 m) :=\nbegin\n    intros e,\n    cases e with i\u2081 s hs i\u2081 i\u2082 i\u2081 s i\u2082 h_ne,\n\n    from elementary.scale i\u2081 s\u207b\u00b9 (inv_ne_zero hs),\n    from @elementary.swap \u03b1 _ _ _ i\u2082 i\u2081,\n    from @elementary.linear_add \u03b1 _ _ m i\u2081 (-s) i\u2082 h_ne,\nend\n\ninstance elementary.has_inv : has_inv (elementary \u03b1 m) := \u27e8elementary.inv\u27e9\n\n@[simp] lemma elementary.inv_inv : \u03a0 {e : elementary \u03b1 m}, (e\u207b\u00b9)\u207b\u00b9 = e :=\nbegin\n    intros e,\n    cases e;{simp[has_inv.inv, elementary.inv],\n    try{apply division_ring.inv_inv,\n    assumption}}\nend\n\ntheorem elementary.inv_apply_implements : \u03a0 {M N : matrix (fin m) (fin n) \u03b1} {e : elementary \u03b1 m},  (elementary.apply e) M = N \u2192 M = (elementary.apply e\u207b\u00b9) N :=\nbegin\n    intros M N e h,\n    rw \u2190h,\n    cases e with i\u2081 s hs i\u2081 i\u2082 i\u2081 s i\u2082 i_ne,\n\n    -- scale case\n    {\n    simp[has_inv.inv, elementary.inv],\n    simp[elementary.apply],\n    funext i j,\n    split_ifs with h\u2081,\n    rw \u2190mul_assoc,\n    erw inv_mul_cancel hs,\n    simp,\n    },\n\n    -- swap case\n    {\n    simp[has_inv.inv, elementary.inv],\n    simp[elementary.apply],\n    funext i j,\n    split_ifs with h\u2081 h\u2082 h\u2083; {try{simp[h\u2081]}, try{simp[h\u2082], try{simp[h\u2083]}}},\n    },\n\n    -- linear_add case\n    {\n    simp[has_inv.inv, elementary.inv],\n    simp[elementary.apply],\n    funext i j,\n    split_ifs with h\u2081 h\u2082;try{try{simp[h\u2081]}, try{simp[h\u2082]}},\n    exfalso,\n    subst h\u2081,\n    from i_ne (eq.symm h\u2082)\n    }\nend\n\ntheorem elementary.inv_apply_implements_iff_apply_implements : \u03a0 {M N : matrix (fin m) (fin n) \u03b1} {e : elementary \u03b1 m},  (elementary.apply e) M = N \u2194 M = (elementary.apply e\u207b\u00b9) N  :=\nbegin\n    intros M N e,\n    split,\n    apply elementary.inv_apply_implements,\n    let e\u2081 := e\u207b\u00b9,\n    have h\u2081 : e = e\u2081\u207b\u00b9,\n    simp[e\u2081],\n    rw h\u2081,\n    simp,\n    have H\u2081, from \u03bb h\u2082, eq.symm ((@elementary.inv_apply_implements m n \u03b1 _ _ N M (e\u207b\u00b9)) (eq.symm h\u2082)),\n    rw elementary.inv_inv at H\u2081,\n    from H\u2081\nend\n\ntheorem elementary.inv_matrix_implements_iff_matrix_implements : \u03a0 {M N : matrix (fin m) (fin n) \u03b1} {e : elementary \u03b1 m}, matrix.mul (elementary.to_matrix e) M = N \u2194 M = matrix.mul (elementary.to_matrix e\u207b\u00b9) N :=\nbegin\n    intros M N e,\n    simp[elementary.mul_eq_apply],\n    apply elementary.inv_apply_implements_iff_apply_implements,\nend\n\ntheorem inv_matrix_implements : \u03a0 {M N : matrix (fin m) (fin n) \u03b1} {e : elementary \u03b1 m}, matrix.mul (elementary.to_matrix e) M = N \u2192 M = matrix.mul (elementary.to_matrix e\u207b\u00b9) N := \u03bb M N e, iff.elim_left elementary.inv_matrix_implements_iff_matrix_implements\n\n\ndef row_equivalent_step.symm : \u03a0 {M N : matrix (fin m) (fin n) \u03b1}, row_equivalent_step M N \u2192 row_equivalent_step N M := begin\n    intros M N r,\n    cases r with elem implements,\n    constructor,\n    from eq.symm (inv_matrix_implements implements),\nend\n\ndef row_equivalent.symm : \u03a0 {M N : matrix (fin m) (fin n) \u03b1}, row_equivalent M N \u2192 row_equivalent N M\n| M N (row_equivalent.nil) := row_equivalent.nil\n| M N (row_equivalent.cons r\u2081 r\u2082) := r\u2081.symm.precons r\u2082.symm\n\n", "meta": {"author": "jjcrawford", "repo": "lean-gaussian-elimination", "sha": "c473d33c07fa6f141d17d9dc42ad07956c33dd03", "save_path": "github-repos/lean/jjcrawford-lean-gaussian-elimination", "path": "github-repos/lean/jjcrawford-lean-gaussian-elimination/lean-gaussian-elimination-c473d33c07fa6f141d17d9dc42ad07956c33dd03/src/row_equivalence_fields.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7071481348155417}}
{"text": "/-\nCopyright (c) 2023 Tian Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tian Chen\n-/\n\nimport algebra.big_operators.order\nimport group_theory.perm.fin\nimport data.matrix.notation\n\nopen_locale big_operators\n\nvariables {\u03b9 \u03b1 \u03b2 : Type*} [decidable_eq \u03b9] [fintype \u03b9]\n\nsection symm_sum\n\nvariables [add_comm_monoid \u03b1]\n\n/-- Symmetric sum. -/\ndef symm_sum (f : (\u03b9 \u2192 \u03b2) \u2192 \u03b1) (z : \u03b9 \u2192 \u03b2) :=\n  \u2211 (\u03c3 : equiv.perm \u03b9), f (z \u2218 \u03c3)\n\nlemma symm_sum_fin_one (f : (fin 1 \u2192 \u03b2) \u2192 \u03b1) (a) :\n  symm_sum f ![a] = f ![a] :=\nbegin\n  simp only [symm_sum, fintype.univ_of_subsingleton, equiv.symm_symm, equiv.symm_trans_self,\n    equiv.equiv_congr_refl, equiv.coe_refl, function.embedding.coe_fn_mk, id.def,\n    finset.sum_singleton, equiv.perm.coe_one, function.comp.right_id]\nend\n\nlemma symm_sum_fin_two (f : (fin 2 \u2192 \u03b2) \u2192 \u03b1) (a b) :\n  symm_sum f ![a, b] = f ![a, b] + f ![b, a] :=\nbegin\n  simp only [symm_sum],\n  rw \u2190 equiv.sum_comp equiv.perm.decompose_fin.symm,\n  rw finset.sum_finset_product _ finset.univ (\u03bb _, finset.univ),\n  all_goals { try { apply_instance } },\n  swap,\n  { simp only [finset.mem_univ, and_self, forall_const] },\n  rw [finset.sum_fin_eq_sum_range, finset.sum_range_succ, finset.sum_range_one,\n    dif_pos (show 0 < 2, from dec_trivial),\n    dif_pos (show 1 < 2, from dec_trivial)],\n  simp only [fintype.univ_of_subsingleton, equiv.symm_symm, equiv.symm_trans_self,\n    equiv.equiv_congr_refl, equiv.coe_refl, function.embedding.coe_fn_mk, id.def,\n    fin.mk_zero, finset.sum_singleton, equiv.perm.decompose_fin_symm_of_one,\n    equiv.swap_self, function.comp.right_id, fin.mk_one],\n  congr' 2,\n  ext i,\n  fin_cases i;\n  refl\nend\n\nend symm_sum\n\nvariables [comm_semiring \u03b1] [has_pow \u03b1 \u03b2]\n\nvariables (z : \u03b9 \u2192 \u03b1) (w : \u03b9 \u2192 \u03b2)\n\n-- I don't know what else to call it\ndef symm_mean := symm_sum (\u03bb w', \u220f i, z i ^ w' i) w\n\nlemma symm_mean_def : symm_mean z w = \u2211 \u03c3 : equiv.perm \u03b9, \u220f i, z i ^ w (\u03c3 i) := rfl\n\nlemma symm_mean_def' : symm_mean z w = \u2211 \u03c3 : equiv.perm \u03b9, \u220f i, z (\u03c3 i) ^ w i :=\ncalc \u2211 \u03c3 : equiv.perm \u03b9, \u220f i, z i ^ w (\u03c3 i)\n    = \u2211 \u03c3 : equiv.perm \u03b9, \u220f i, z (\u03c3.symm (\u03c3 i)) ^ w (\u03c3 i) :\n  by simp_rw [equiv.symm_apply_apply]\n... = \u2211 \u03c3 : equiv.perm \u03b9, \u220f (i : \u03b9), z (equiv.symm \u03c3 i) ^ w i :\n  finset.sum_congr rfl $ \u03bb \u03c3 _, equiv.prod_comp \u03c3 (\u03bb i, z (\u03c3.symm i) ^ w i)\n... = \u2211 \u03c3 : equiv.perm \u03b9, \u220f (i : \u03b9), z (\u03c3 i) ^ w i :\n  function.bijective.sum_comp\n    (show function.bijective (equiv.symm : equiv.perm \u03b9 \u2192 equiv.perm \u03b9),\n      from function.bijective_iff_has_inverse.2\n        \u27e8equiv.symm, \u03bb _, equiv.symm_symm _, \u03bb _, equiv.symm_symm _\u27e9)\n    (\u03bb \u03c3 : equiv.perm \u03b9, \u220f (i : \u03b9), z (\u03c3 i) ^ w i)\n\nlemma symm_mean_fin_one (z : \u03b1) (w : \u03b2) : symm_mean ![z] ![w] = z ^ w :=\nbegin\n  rw [symm_mean, symm_sum_fin_one, finset.prod_fin_eq_prod_range, finset.prod_range_one],\n  refl\nend\n\nlemma symm_mean_fin_two (z\u2081 z\u2082 : \u03b1) (w\u2081 w\u2082 : \u03b2) :\n  symm_mean ![z\u2081, z\u2082] ![w\u2081, w\u2082] = z\u2081 ^ w\u2081 * z\u2082 ^ w\u2082 + z\u2081 ^ w\u2082 * z\u2082 ^ w\u2081 :=\nbegin\n  rw [symm_mean, symm_sum_fin_two],\n  iterate 2 { rw [finset.prod_fin_eq_prod_range, finset.prod_range_succ, finset.prod_range_one] },\n  refl\nend\n\nlemma symm_mean_equiv_left (\u03c3 : equiv.perm \u03b9) : symm_mean (z \u2218 \u03c3) w = symm_mean z w :=\nbegin\n  rw [symm_mean_def', symm_mean_def'],\n  exact function.bijective.sum_comp (group.mul_left_bijective \u03c3)\n    (\u03bb \u03c3' : equiv.perm \u03b9, \u220f i, z (\u03c3' i) ^ w i)\nend\n\nlemma symm_mean_equiv_right (\u03c3 : equiv.perm \u03b9) : symm_mean z (w \u2218 \u03c3) = symm_mean z w :=\nfunction.bijective.sum_comp (group.mul_left_bijective \u03c3)\n  (\u03bb \u03c3' : equiv.perm \u03b9, \u220f i, z i ^ w (\u03c3' i))\n", "meta": {"author": "peakpoint", "repo": "muirhead", "sha": "f6cbdafa9e9c1626d37378493fce68cc68eeea97", "save_path": "github-repos/lean/peakpoint-muirhead", "path": "github-repos/lean/peakpoint-muirhead/muirhead-f6cbdafa9e9c1626d37378493fce68cc68eeea97/src/ineq/symm_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7071481336180866}}
{"text": "import Saturn.FinSeq\nimport Saturn.Core\nopen Nat \n/-\nFunctions and theorems for working with vectors. Most of these are conversions from\nfinite sequences to vectors,  its consistency with the conversion from vectors to\nfinite sequences defined in `Core`, and the consistency of various operations with conversions\nbetween finite sequences and vectors in both directions.\n-/\nopen Vector\n\ndef countAux {\u03b1 : Type}{n : Nat}(v: Vector \u03b1 n)(pred: \u03b1 \u2192 Bool)(accum : Nat) : Nat :=\n  match n, v, accum with\n  | .(zero), nil, accum => accum\n  | m + 1, cons head tail, accum => \n      if (pred head) then countAux tail pred (accum + 1) else countAux tail pred accum\n\ndef Vector.count {\u03b1 : Type}{n : Nat}(v: Vector \u03b1 n)(pred: \u03b1 \u2192 Bool) : Nat :=\n    countAux v pred zero\n\ndef seqVecAux {\u03b1: Type}{n m l: Nat}: (s : n + m = l) \u2192   \n    (seq1 : FinSeq n \u03b1) \u2192 (accum : Vector \u03b1 m) \u2192  \n       Vector \u03b1 l:= \n    match n with\n    | zero => fun s => fun _ => fun seq2 =>\n      by\n        have ss : l = m := by \n          rw [\u2190 s]\n          apply Nat.zero_add\n        rw [ss]\n        exact seq2\n    | k + 1 => fun s seq1 seq2 => \n      let ss : k + (m + 1)  = l := \n        by\n          rw [\u2190 s]\n          rw [(Nat.add_comm m 1)]\n          rw [(Nat.add_assoc k 1 m)]\n      seqVecAux ss (seq1.init) ((seq1.last) +: seq2)\n\ndef FinSeq.vec {\u03b1 : Type}{n: Nat} : FinSeq n \u03b1  \u2192  Vector \u03b1 n := \n    fun seq => seqVecAux (Nat.add_zero n) seq Vector.nil\n\ntheorem prevsum{n m l: Nat}: n + 1 + m = l + 1 \u2192 n + m = l := \n  by\n    intro hyp\n    rw [Nat.add_assoc] at hyp\n    rw [Nat.add_comm 1 m] at hyp\n    rw [\u2190 Nat.add_assoc] at hyp    \n    have sc : succ (n + m) = succ l := hyp\n    injection sc\n    assumption\n\ntheorem seq_vec_cons_aux {\u03b1: Type}{n m l: Nat}(s : (n + 1) + m = l + 1) (seq1 : FinSeq (n + 1) \u03b1) \n        (accum : Vector \u03b1 m) : seqVecAux s seq1 accum =\n                (seq1.head) +: (seqVecAux (prevsum s) (seq1.tail)  accum) := \n            match n, l, s, seq1 with\n            |  zero, l, s'', seq1  => \n              by\n              have eql : m = l := by\n                rw [\u2190  prevsum s'']\n                rw [Nat.zero_add]\n              match m, l, eql, s'', accum with\n              | m', .(m'), rfl, s', accum =>\n                rfl\n            | succ n', l, s'', seq1  =>\n              by \n              let ss : (n' + 1) + (m + 1)  = l + 1 := \n                by\n                  rw [\u2190 s'']\n                  rw [(Nat.add_comm m 1)]\n                  rw [(Nat.add_assoc (n' + 1) 1 m)]\n              have resolve :\n                seqVecAux s'' seq1 accum =\n                  seqVecAux ss (seq1.init) ((seq1.last) +: accum) := by rfl\n              rw [resolve]\n              let base := seq_vec_cons_aux ss (seq1.init) (seq1.last+:accum)\n              rw [base]\n              rfl\n                      \n\ntheorem seq_vec_cons_eq {\u03b1: Type}{n : Nat} (seq : FinSeq (n + 1) \u03b1) : \n          seq.vec  = (seq.head) +: (seq.tail.vec) := \n                  seq_vec_cons_aux _ seq Vector.nil\n\ntheorem coords_eq_implies_vec_eq{\u03b1: Type}{n : Nat}{v1 v2 : Vector \u03b1 n}: \n    v1.coords = v2.coords \u2192 v1 = v2 := \n    match n, v1, v2 with\n    | zero, nil, nil => fun _ => rfl\n    | m + 1, cons head1 tail1, cons head2 tail2 =>\n      by\n        intro hyp\n        have h1 : head1 = (cons head1 tail1).coords zero (Nat.zero_lt_succ m) := by rfl\n        have h2 : head2 = (cons head2 tail2).coords zero (Nat.zero_lt_succ m) := by rfl\n        have hypHead : head1 = head2 :=\n          by \n            rw [h1, h2, hyp]            \n        rw [hypHead]\n        apply congrArg\n        let base := @coords_eq_implies_vec_eq _ _ tail1 tail2\n        apply base\n        apply funext\n        intro k\n        apply funext\n        intro kw\n        have t1 : tail1.coords k kw = \n          (cons head1 tail1).coords (k + 1) (Nat.succ_lt_succ kw) := by rfl\n        have t2 : tail2.coords k kw = \n          (cons head2 tail2).coords (k + 1) (Nat.succ_lt_succ kw) := by rfl\n        rw [t1, t2, hyp]\n\ntheorem seq_to_vec_coords{\u03b1 : Type}{n : Nat}: (seq: FinSeq n \u03b1) \u2192   seq.vec.coords = seq := \n  match n with\n  | zero => by\n    intro seq\n    apply funext\n    intro k\n    apply funext\n    intro kw\n    exact nomatch kw\n  | succ m => by \n    intro seq\n    apply funext\n    intro k\n    cases k with\n    | zero =>\n      apply funext\n      intro kw \n      have resolve : seq.vec = cons (seq.head) (FinSeq.vec (seq.tail)) := by apply seq_vec_cons_eq \n      rw [resolve]\n      rfl\n    | succ k' => \n      apply funext\n      intro kw\n      have tl :(FinSeq.vec seq).coords (succ k') kw = \n          (FinSeq.vec (seq.tail)).coords k' (Nat.le_of_succ_le_succ kw) := by\n              rw [(seq_vec_cons_eq seq)] \n              rfl \n      let base := seq_to_vec_coords (seq.tail)\n      rw [tl]\n      rw [base]\n      rfl\n\ntheorem cons_commutes{\u03b1 : Type}{n : Nat} (head : \u03b1) (tail : Vector \u03b1 n) :\n          (head +: tail).coords = head +| tail.coords := by\n            apply funext\n            intro k\n            induction k with\n            | zero =>\n              apply funext\n              intro kw\n              rfl\n            | succ k' =>\n              apply funext\n              intro kw\n              rfl\n\ntheorem tail_commutes{\u03b1 : Type}{n : Nat} (x : \u03b1) (ys : Vector \u03b1 n) :\n      (x +: ys).coords.tail = ys.coords := \n        by\n        apply funext\n        intro kw\n        rfl \n\ndef Vector.map {\u03b1 \u03b2 : Type}{n: Nat}(vec: Vector \u03b1 n) (f : \u03b1 \u2192 \u03b2) : Vector \u03b2 n :=\n    FinSeq.vec (fun j jw => f (vec.coords j jw))\n\ntheorem map_coords_commute{\u03b1 \u03b2 : Type}{n : Nat}(vec: Vector \u03b1 n) (f : \u03b1 \u2192 \u03b2) (j : Nat) (jw : Nat.lt j n) :\n          (Vector.map vec f).coords j jw = f (vec.coords j jw) := by\n          have resolve: (map vec f).coords j jw = \n                (FinSeq.vec (fun j jw => f (vec.coords j jw)) ).coords j jw := rfl\n          rw [resolve]\n          rw [seq_to_vec_coords]\n", "meta": {"author": "siddhartha-gadgil", "repo": "Saturn", "sha": "4e451333411dc0f381ade5aa4569e1acfea5be0b", "save_path": "github-repos/lean/siddhartha-gadgil-Saturn", "path": "github-repos/lean/siddhartha-gadgil-Saturn/Saturn-4e451333411dc0f381ade5aa4569e1acfea5be0b/Saturn/Vector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.7071481283558888}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Fabian Gl\u00f6ckle, Kyle Miller\n\n! This file was ported from Lean 3 source module linear_algebra.dual\n! leanprover-community/mathlib commit 5455cb0b5f3be8f8b22c55366fbc6e380dbff579\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.FiniteDimensional\nimport Mathbin.LinearAlgebra.Projection\nimport Mathbin.LinearAlgebra.SesquilinearForm\nimport Mathbin.RingTheory.Finiteness\nimport Mathbin.LinearAlgebra.FreeModule.Finite.Basic\n\n/-!\n# Dual vector spaces\n\nThe dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \\to R$.\n\n## Main definitions\n\n* Duals and transposes:\n  * `module.dual R M` defines the dual space of the `R`-module `M`, as `M \u2192\u2097[R] R`.\n  * `module.dual_pairing R M` is the canonical pairing between `dual R M` and `M`.\n  * `module.dual.eval R M : M \u2192\u2097[R] dual R (dual R)` is the canonical map to the double dual.\n  * `module.dual.transpose` is the linear map from `M \u2192\u2097[R] M'` to `dual R M' \u2192\u2097[R] dual R M`.\n  * `linear_map.dual_map` is `module.dual.transpose` of a given linear map, for dot notation.\n  * `linear_equiv.dual_map` is for the dual of an equivalence.\n* Bases:\n  * `basis.to_dual` produces the map `M \u2192\u2097[R] dual R M` associated to a basis for an `R`-module `M`.\n  * `basis.to_dual_equiv` is the equivalence `M \u2243\u2097[R] dual R M` associated to a finite basis.\n  * `basis.dual_basis` is a basis for `dual R M` given a finite basis for `M`.\n  * `module.dual_bases e \u03b5` is the proposition that the families `e` of vectors and `\u03b5` of dual\n    vectors have the characteristic properties of a basis and a dual.\n* Submodules:\n  * `submodule.dual_restrict W` is the transpose `dual R M \u2192\u2097[R] dual R W` of the inclusion map.\n  * `submodule.dual_annihilator W` is the kernel of `W.dual_restrict`. That is, it is the submodule\n    of `dual R M` whose elements all annihilate `W`.\n  * `submodule.dual_restrict_comap W'` is the dual annihilator of `W' : submodule R (dual R M)`,\n    pulled back along `module.dual.eval R M`.\n  * `submodule.dual_copairing W` is the canonical pairing between `W.dual_annihilator` and `M \u29f8 W`.\n    It is nondegenerate for vector spaces (`subspace.dual_copairing_nondegenerate`).\n  * `submodule.dual_pairing W` is the canonical pairing between `dual R M \u29f8 W.dual_annihilator`\n    and `W`. It is nondegenerate for vector spaces (`subspace.dual_pairing_nondegenerate`).\n* Vector spaces:\n  * `subspace.dual_lift W` is an arbitrary section (using choice) of `submodule.dual_restrict W`.\n\n## Main results\n\n* Bases:\n  * `module.dual_basis.basis` and `module.dual_basis.coe_basis`: if `e` and `\u03b5` form a dual pair,\n    then `e` is a basis.\n  * `module.dual_basis.coe_dual_basis`: if `e` and `\u03b5` form a dual pair,\n    then `\u03b5` is a basis.\n* Annihilators:\n  * `module.dual_annihilator_gc R M` is the antitone Galois correspondence between\n    `submodule.dual_annihilator` and `submodule.dual_coannihilator`.\n  * `linear_map.ker_dual_map_eq_dual_annihilator_range` says that\n    `f.dual_map.ker = f.range.dual_annihilator`\n  * `linear_map.range_dual_map_eq_dual_annihilator_ker_of_subtype_range_surjective` says that\n    `f.dual_map.range = f.ker.dual_annihilator`; this is specialized to vector spaces in\n    `linear_map.range_dual_map_eq_dual_annihilator_ker`.\n  * `submodule.dual_quot_equiv_dual_annihilator` is the equivalence\n    `dual R (M \u29f8 W) \u2243\u2097[R] W.dual_annihilator`\n* Vector spaces:\n  * `subspace.dual_annihilator_dual_coannihilator_eq` says that the double dual annihilator,\n    pulled back ground `module.dual.eval`, is the original submodule.\n  * `subspace.dual_annihilator_gci` says that `module.dual_annihilator_gc R M` is an\n    antitone Galois coinsertion.\n  * `subspace.quot_annihilator_equiv` is the equivalence\n    `dual K V \u29f8 W.dual_annihilator \u2243\u2097[K] dual K W`.\n  * `linear_map.dual_pairing_nondegenerate` says that `module.dual_pairing` is nondegenerate.\n  * `subspace.is_compl_dual_annihilator` says that the dual annihilator carries complementary\n    subspaces to complementary subspaces.\n* Finite-dimensional vector spaces:\n  * `module.eval_equiv` is the equivalence `V \u2243\u2097[K] dual K (dual K V)`\n  * `module.map_eval_equiv` is the order isomorphism between subspaces of `V` and\n    subspaces of `dual K (dual K V)`.\n  * `subspace.quot_dual_equiv_annihilator W` is the equivalence\n    `(dual K V \u29f8 W.dual_lift.range) \u2243\u2097[K] W.dual_annihilator`, where `W.dual_lift.range` is a copy\n    of `dual K W` inside `dual K V`.\n  * `subspace.quot_equiv_annihilator W` is the equivalence `(V \u29f8 W) \u2243\u2097[K] W.dual_annihilator`\n  * `subspace.dual_quot_distrib W` is an equivalence\n    `dual K (V\u2081 \u29f8 W) \u2243\u2097[K] dual K V\u2081 \u29f8 W.dual_lift.range` from an arbitrary choice of\n    splitting of `V\u2081`.\n\n## TODO\n\nErd\u00f6s-Kaplansky theorem about the dimension of a dual vector space in case of infinite dimension.\n-/\n\n\nnoncomputable section\n\nnamespace Module\n\nvariable (R : Type _) (M : Type _)\n\nvariable [CommSemiring R] [AddCommMonoid M] [Module R M]\n\n/- ./././Mathport/Syntax/Translate/Command.lean:42:9: unsupported derive handler module[module] R -/\n/-- The dual space of an R-module M is the R-module of linear maps `M \u2192 R`. -/\ndef Dual :=\n  M \u2192\u2097[R] R deriving AddCommMonoid,\n  \u00ab./././Mathport/Syntax/Translate/Command.lean:42:9: unsupported derive handler module[module] R\u00bb\n#align module.dual Module.Dual\n\ninstance {S : Type _} [CommRing S] {N : Type _} [AddCommGroup N] [Module S N] :\n    AddCommGroup (Dual S N) :=\n  LinearMap.addCommGroup\n\ninstance : LinearMapClass (Dual R M) R M R :=\n  LinearMap.semilinearMapClass\n\n/-- The canonical pairing of a vector space and its algebraic dual. -/\ndef dualPairing (R M) [CommSemiring R] [AddCommMonoid M] [Module R M] :\n    Module.Dual R M \u2192\u2097[R] M \u2192\u2097[R] R :=\n  LinearMap.id\n#align module.dual_pairing Module.dualPairing\n\n@[simp]\ntheorem dualPairing_apply (v x) : dualPairing R M v x = v x :=\n  rfl\n#align module.dual_pairing_apply Module.dualPairing_apply\n\nnamespace Dual\n\ninstance : Inhabited (Dual R M) :=\n  LinearMap.inhabited\n\ninstance : CoeFun (Dual R M) fun _ => M \u2192 R :=\n  \u27e8LinearMap.toFun\u27e9\n\n/-- Maps a module M to the dual of the dual of M. See `module.erange_coe` and\n`module.eval_equiv`. -/\ndef eval : M \u2192\u2097[R] Dual R (Dual R M) :=\n  LinearMap.flip LinearMap.id\n#align module.dual.eval Module.Dual.eval\n\n@[simp]\ntheorem eval_apply (v : M) (a : Dual R M) : eval R M v a = a v :=\n  rfl\n#align module.dual.eval_apply Module.Dual.eval_apply\n\nvariable {R M} {M' : Type _} [AddCommMonoid M'] [Module R M']\n\n/-- The transposition of linear maps, as a linear map from `M \u2192\u2097[R] M'` to\n`dual R M' \u2192\u2097[R] dual R M`. -/\ndef transpose : (M \u2192\u2097[R] M') \u2192\u2097[R] Dual R M' \u2192\u2097[R] Dual R M :=\n  (LinearMap.llcomp R M M' R).flip\n#align module.dual.transpose Module.Dual.transpose\n\ntheorem transpose_apply (u : M \u2192\u2097[R] M') (l : Dual R M') : transpose u l = l.comp u :=\n  rfl\n#align module.dual.transpose_apply Module.Dual.transpose_apply\n\nvariable {M'' : Type _} [AddCommMonoid M''] [Module R M'']\n\ntheorem transpose_comp (u : M' \u2192\u2097[R] M'') (v : M \u2192\u2097[R] M') :\n    transpose (u.comp v) = (transpose v).comp (transpose u) :=\n  rfl\n#align module.dual.transpose_comp Module.Dual.transpose_comp\n\nend Dual\n\nsection Prod\n\nvariable (M' : Type _) [AddCommMonoid M'] [Module R M']\n\n/-- Taking duals distributes over products. -/\n@[simps]\ndef dualProdDualEquivDual : (Module.Dual R M \u00d7 Module.Dual R M') \u2243\u2097[R] Module.Dual R (M \u00d7 M') :=\n  LinearMap.coprodEquiv R\n#align module.dual_prod_dual_equiv_dual Module.dualProdDualEquivDual\n\n@[simp]\ntheorem dualProdDualEquivDual_apply (\u03c6 : Module.Dual R M) (\u03c8 : Module.Dual R M') :\n    dualProdDualEquivDual R M M' (\u03c6, \u03c8) = \u03c6.coprod \u03c8 :=\n  rfl\n#align module.dual_prod_dual_equiv_dual_apply Module.dualProdDualEquivDual_apply\n\nend Prod\n\nend Module\n\nsection DualMap\n\nopen Module\n\nvariable {R : Type _} [CommSemiring R] {M\u2081 : Type _} {M\u2082 : Type _}\n\nvariable [AddCommMonoid M\u2081] [Module R M\u2081] [AddCommMonoid M\u2082] [Module R M\u2082]\n\n/-- Given a linear map `f : M\u2081 \u2192\u2097[R] M\u2082`, `f.dual_map` is the linear map between the dual of\n`M\u2082` and `M\u2081` such that it maps the functional `\u03c6` to `\u03c6 \u2218 f`. -/\ndef LinearMap.dualMap (f : M\u2081 \u2192\u2097[R] M\u2082) : Dual R M\u2082 \u2192\u2097[R] Dual R M\u2081 :=\n  Module.Dual.transpose f\n#align linear_map.dual_map LinearMap.dualMap\n\ntheorem LinearMap.dualMap_def (f : M\u2081 \u2192\u2097[R] M\u2082) : f.dualMap = Module.Dual.transpose f :=\n  rfl\n#align linear_map.dual_map_def LinearMap.dualMap_def\n\ntheorem LinearMap.dualMap_apply' (f : M\u2081 \u2192\u2097[R] M\u2082) (g : Dual R M\u2082) : f.dualMap g = g.comp f :=\n  rfl\n#align linear_map.dual_map_apply' LinearMap.dualMap_apply'\n\n@[simp]\ntheorem LinearMap.dualMap_apply (f : M\u2081 \u2192\u2097[R] M\u2082) (g : Dual R M\u2082) (x : M\u2081) :\n    f.dualMap g x = g (f x) :=\n  rfl\n#align linear_map.dual_map_apply LinearMap.dualMap_apply\n\n@[simp]\ntheorem LinearMap.dualMap_id : (LinearMap.id : M\u2081 \u2192\u2097[R] M\u2081).dualMap = LinearMap.id :=\n  by\n  ext\n  rfl\n#align linear_map.dual_map_id LinearMap.dualMap_id\n\ntheorem LinearMap.dualMap_comp_dualMap {M\u2083 : Type _} [AddCommGroup M\u2083] [Module R M\u2083]\n    (f : M\u2081 \u2192\u2097[R] M\u2082) (g : M\u2082 \u2192\u2097[R] M\u2083) : f.dualMap.comp g.dualMap = (g.comp f).dualMap :=\n  rfl\n#align linear_map.dual_map_comp_dual_map LinearMap.dualMap_comp_dualMap\n\n/-- If a linear map is surjective, then its dual is injective. -/\ntheorem LinearMap.dualMap_injective_of_surjective {f : M\u2081 \u2192\u2097[R] M\u2082} (hf : Function.Surjective f) :\n    Function.Injective f.dualMap := by\n  intro \u03c6 \u03c8 h\n  ext x\n  obtain \u27e8y, rfl\u27e9 := hf x\n  exact congr_arg (fun g : Module.Dual R M\u2081 => g y) h\n#align linear_map.dual_map_injective_of_surjective LinearMap.dualMap_injective_of_surjective\n\n/-- The `linear_equiv` version of `linear_map.dual_map`. -/\ndef LinearEquiv.dualMap (f : M\u2081 \u2243\u2097[R] M\u2082) : Dual R M\u2082 \u2243\u2097[R] Dual R M\u2081 :=\n  { f.toLinearMap.dualMap with\n    invFun := f.symm.toLinearMap.dualMap\n    left_inv := by\n      intro \u03c6; ext x\n      simp only [LinearMap.dualMap_apply, LinearEquiv.coe_toLinearMap, LinearMap.toFun_eq_coe,\n        LinearEquiv.apply_symm_apply]\n    right_inv := by\n      intro \u03c6; ext x\n      simp only [LinearMap.dualMap_apply, LinearEquiv.coe_toLinearMap, LinearMap.toFun_eq_coe,\n        LinearEquiv.symm_apply_apply] }\n#align linear_equiv.dual_map LinearEquiv.dualMap\n\n@[simp]\ntheorem LinearEquiv.dualMap_apply (f : M\u2081 \u2243\u2097[R] M\u2082) (g : Dual R M\u2082) (x : M\u2081) :\n    f.dualMap g x = g (f x) :=\n  rfl\n#align linear_equiv.dual_map_apply LinearEquiv.dualMap_apply\n\n@[simp]\ntheorem LinearEquiv.dualMap_refl :\n    (LinearEquiv.refl R M\u2081).dualMap = LinearEquiv.refl R (Dual R M\u2081) :=\n  by\n  ext\n  rfl\n#align linear_equiv.dual_map_refl LinearEquiv.dualMap_refl\n\n@[simp]\ntheorem LinearEquiv.dualMap_symm {f : M\u2081 \u2243\u2097[R] M\u2082} :\n    (LinearEquiv.dualMap f).symm = LinearEquiv.dualMap f.symm :=\n  rfl\n#align linear_equiv.dual_map_symm LinearEquiv.dualMap_symm\n\ntheorem LinearEquiv.dualMap_trans {M\u2083 : Type _} [AddCommGroup M\u2083] [Module R M\u2083] (f : M\u2081 \u2243\u2097[R] M\u2082)\n    (g : M\u2082 \u2243\u2097[R] M\u2083) : g.dualMap.trans f.dualMap = (f.trans g).dualMap :=\n  rfl\n#align linear_equiv.dual_map_trans LinearEquiv.dualMap_trans\n\nend DualMap\n\nnamespace Basis\n\nuniverse u v w\n\nopen Module Module.Dual Submodule LinearMap Cardinal Function\n\nopen BigOperators\n\nvariable {R M K V \u03b9 : Type _}\n\nsection CommSemiring\n\nvariable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq \u03b9]\n\nvariable (b : Basis \u03b9 R M)\n\n/-- The linear map from a vector space equipped with basis to its dual vector space,\ntaking basis elements to corresponding dual basis elements. -/\ndef toDual : M \u2192\u2097[R] Module.Dual R M :=\n  b.constr \u2115 fun v => b.constr \u2115 fun w => if w = v then (1 : R) else 0\n#align basis.to_dual Basis.toDual\n\ntheorem toDual_apply (i j : \u03b9) : b.toDual (b i) (b j) = if i = j then 1 else 0 :=\n  by\n  erw [constr_basis b, constr_basis b]\n  ac_rfl\n#align basis.to_dual_apply Basis.toDual_apply\n\n@[simp]\ntheorem toDual_total_left (f : \u03b9 \u2192\u2080 R) (i : \u03b9) : b.toDual (Finsupp.total \u03b9 M R b f) (b i) = f i :=\n  by\n  rw [Finsupp.total_apply, Finsupp.sum, LinearMap.map_sum, LinearMap.sum_apply]\n  simp_rw [LinearMap.map_smul, LinearMap.smul_apply, to_dual_apply, smul_eq_mul, mul_boole,\n    Finset.sum_ite_eq']\n  split_ifs with h\n  \u00b7 rfl\n  \u00b7 rw [finsupp.not_mem_support_iff.mp h]\n#align basis.to_dual_total_left Basis.toDual_total_left\n\n@[simp]\ntheorem toDual_total_right (f : \u03b9 \u2192\u2080 R) (i : \u03b9) : b.toDual (b i) (Finsupp.total \u03b9 M R b f) = f i :=\n  by\n  rw [Finsupp.total_apply, Finsupp.sum, LinearMap.map_sum]\n  simp_rw [LinearMap.map_smul, to_dual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq]\n  split_ifs with h\n  \u00b7 rfl\n  \u00b7 rw [finsupp.not_mem_support_iff.mp h]\n#align basis.to_dual_total_right Basis.toDual_total_right\n\ntheorem toDual_apply_left (m : M) (i : \u03b9) : b.toDual m (b i) = b.repr m i := by\n  rw [\u2190 b.to_dual_total_left, b.total_repr]\n#align basis.to_dual_apply_left Basis.toDual_apply_left\n\ntheorem toDual_apply_right (i : \u03b9) (m : M) : b.toDual (b i) m = b.repr m i := by\n  rw [\u2190 b.to_dual_total_right, b.total_repr]\n#align basis.to_dual_apply_right Basis.toDual_apply_right\n\ntheorem coe_toDual_self (i : \u03b9) : b.toDual (b i) = b.Coord i :=\n  by\n  ext\n  apply to_dual_apply_right\n#align basis.coe_to_dual_self Basis.coe_toDual_self\n\n/-- `h.to_dual_flip v` is the linear map sending `w` to `h.to_dual w v`. -/\ndef toDualFlip (m : M) : M \u2192\u2097[R] R :=\n  b.toDual.flip m\n#align basis.to_dual_flip Basis.toDualFlip\n\ntheorem toDualFlip_apply (m\u2081 m\u2082 : M) : b.toDualFlip m\u2081 m\u2082 = b.toDual m\u2082 m\u2081 :=\n  rfl\n#align basis.to_dual_flip_apply Basis.toDualFlip_apply\n\ntheorem toDual_eq_repr (m : M) (i : \u03b9) : b.toDual m (b i) = b.repr m i :=\n  b.toDual_apply_left m i\n#align basis.to_dual_eq_repr Basis.toDual_eq_repr\n\ntheorem toDual_eq_equivFun [Fintype \u03b9] (m : M) (i : \u03b9) : b.toDual m (b i) = b.equivFun m i := by\n  rw [b.equiv_fun_apply, to_dual_eq_repr]\n#align basis.to_dual_eq_equiv_fun Basis.toDual_eq_equivFun\n\ntheorem toDual_inj (m : M) (a : b.toDual m = 0) : m = 0 :=\n  by\n  rw [\u2190 mem_bot R, \u2190 b.repr.ker, mem_ker, LinearEquiv.coe_coe]\n  apply Finsupp.ext\n  intro b\n  rw [\u2190 to_dual_eq_repr, a]\n  rfl\n#align basis.to_dual_inj Basis.toDual_inj\n\ntheorem toDual_ker : b.toDual.ker = \u22a5 :=\n  ker_eq_bot'.mpr b.toDual_inj\n#align basis.to_dual_ker Basis.toDual_ker\n\ntheorem toDual_range [Finite \u03b9] : b.toDual.range = \u22a4 :=\n  by\n  cases nonempty_fintype \u03b9\n  refine' eq_top_iff'.2 fun f => _\n  rw [LinearMap.mem_range]\n  let lin_comb : \u03b9 \u2192\u2080 R := finsupp.equiv_fun_on_finite.symm fun i => f.to_fun (b i)\n  refine' \u27e8Finsupp.total \u03b9 M R b lin_comb, b.ext fun i => _\u27e9\n  rw [b.to_dual_eq_repr _ i, repr_total b]\n  rfl\n#align basis.to_dual_range Basis.toDual_range\n\nend CommSemiring\n\nsection\n\nvariable [CommSemiring R] [AddCommMonoid M] [Module R M] [Fintype \u03b9]\n\nvariable (b : Basis \u03b9 R M)\n\n@[simp]\ntheorem sum_dual_apply_smul_coord (f : Module.Dual R M) : (\u2211 x, f (b x) \u2022 b.Coord x) = f :=\n  by\n  ext m\n  simp_rw [LinearMap.sum_apply, LinearMap.smul_apply, smul_eq_mul, mul_comm (f _), \u2190 smul_eq_mul, \u2190\n    f.map_smul, \u2190 f.map_sum, Basis.coord_apply, Basis.sum_repr]\n#align basis.sum_dual_apply_smul_coord Basis.sum_dual_apply_smul_coord\n\nend\n\nsection CommRing\n\nvariable [CommRing R] [AddCommGroup M] [Module R M] [DecidableEq \u03b9]\n\nvariable (b : Basis \u03b9 R M)\n\nsection Finite\n\nvariable [Finite \u03b9]\n\n/-- A vector space is linearly equivalent to its dual space. -/\n@[simps]\ndef toDualEquiv : M \u2243\u2097[R] Dual R M :=\n  LinearEquiv.ofBijective b.toDual \u27e8ker_eq_bot.mp b.toDual_ker, range_eq_top.mp b.toDual_range\u27e9\n#align basis.to_dual_equiv Basis.toDualEquiv\n\n/-- Maps a basis for `V` to a basis for the dual space. -/\ndef dualBasis : Basis \u03b9 R (Dual R M) :=\n  b.map b.toDualEquiv\n#align basis.dual_basis Basis.dualBasis\n\n-- We use `j = i` to match `basis.repr_self`\ntheorem dualBasis_apply_self (i j : \u03b9) : b.dualBasis i (b j) = if j = i then 1 else 0 :=\n  by\n  convert b.to_dual_apply i j using 2\n  rw [@eq_comm _ j i]\n#align basis.dual_basis_apply_self Basis.dualBasis_apply_self\n\ntheorem total_dualBasis (f : \u03b9 \u2192\u2080 R) (i : \u03b9) :\n    Finsupp.total \u03b9 (Dual R M) R b.dualBasis f (b i) = f i :=\n  by\n  cases nonempty_fintype \u03b9\n  rw [Finsupp.total_apply, Finsupp.sum_fintype, LinearMap.sum_apply]\n  \u00b7\n    simp_rw [LinearMap.smul_apply, smul_eq_mul, dual_basis_apply_self, mul_boole, Finset.sum_ite_eq,\n      if_pos (Finset.mem_univ i)]\n  \u00b7 intro\n    rw [zero_smul]\n#align basis.total_dual_basis Basis.total_dualBasis\n\ntheorem dualBasis_repr (l : Dual R M) (i : \u03b9) : b.dualBasis.repr l i = l (b i) := by\n  rw [\u2190 total_dual_basis b, Basis.total_repr b.dual_basis l]\n#align basis.dual_basis_repr Basis.dualBasis_repr\n\ntheorem dualBasis_apply (i : \u03b9) (m : M) : b.dualBasis i m = b.repr m i :=\n  b.toDual_apply_right i m\n#align basis.dual_basis_apply Basis.dualBasis_apply\n\n@[simp]\ntheorem coe_dualBasis : \u21d1b.dualBasis = b.Coord :=\n  by\n  ext (i x)\n  apply dual_basis_apply\n#align basis.coe_dual_basis Basis.coe_dualBasis\n\n@[simp]\ntheorem toDual_toDual : b.dualBasis.toDual.comp b.toDual = Dual.eval R M :=\n  by\n  refine' b.ext fun i => b.dual_basis.ext fun j => _\n  rw [LinearMap.comp_apply, to_dual_apply_left, coe_to_dual_self, \u2190 coe_dual_basis, dual.eval_apply,\n    Basis.repr_self, Finsupp.single_apply, dual_basis_apply_self]\n#align basis.to_dual_to_dual Basis.toDual_toDual\n\nend Finite\n\ntheorem dualBasis_equivFun [Fintype \u03b9] (l : Dual R M) (i : \u03b9) :\n    b.dualBasis.equivFun l i = l (b i) := by rw [Basis.equivFun_apply, dual_basis_repr]\n#align basis.dual_basis_equiv_fun Basis.dualBasis_equivFun\n\ntheorem eval_ker {\u03b9 : Type _} (b : Basis \u03b9 R M) : (Dual.eval R M).ker = \u22a5 :=\n  by\n  rw [ker_eq_bot']\n  intro m hm\n  simp_rw [LinearMap.ext_iff, dual.eval_apply, zero_apply] at hm\n  exact (Basis.forall_coord_eq_zero_iff _).mp fun i => hm (b.coord i)\n#align basis.eval_ker Basis.eval_ker\n\ntheorem eval_range {\u03b9 : Type _} [Finite \u03b9] (b : Basis \u03b9 R M) : (eval R M).range = \u22a4 := by\n  classical\n    cases nonempty_fintype \u03b9\n    rw [\u2190 b.to_dual_to_dual, range_comp, b.to_dual_range, Submodule.map_top, to_dual_range _]\n    infer_instance\n#align basis.eval_range Basis.eval_range\n\n/-- A module with a basis is linearly equivalent to the dual of its dual space. -/\ndef evalEquiv {\u03b9 : Type _} [Finite \u03b9] (b : Basis \u03b9 R M) : M \u2243\u2097[R] Dual R (Dual R M) :=\n  LinearEquiv.ofBijective (eval R M) \u27e8ker_eq_bot.mp b.eval_ker, range_eq_top.mp b.eval_range\u27e9\n#align basis.eval_equiv Basis.evalEquiv\n\n@[simp]\ntheorem evalEquiv_toLinearMap {\u03b9 : Type _} [Finite \u03b9] (b : Basis \u03b9 R M) :\n    b.evalEquiv.toLinearMap = Dual.eval R M :=\n  rfl\n#align basis.eval_equiv_to_linear_map Basis.evalEquiv_toLinearMap\n\nsection\n\nopen Classical\n\nvariable [Finite R M] [Free R M] [Nontrivial R]\n\ninstance dual_free : Free R (Dual R M) :=\n  Free.of_basis (Free.chooseBasis R M).dualBasis\n#align basis.dual_free Basis.dual_free\n\ninstance dual_finite : Finite R (Dual R M) :=\n  Finite.of_basis (Free.chooseBasis R M).dualBasis\n#align basis.dual_finite Basis.dual_finite\n\nend\n\nend CommRing\n\n/-- `simp` normal form version of `total_dual_basis` -/\n@[simp]\ntheorem total_coord [CommRing R] [AddCommGroup M] [Module R M] [Finite \u03b9] (b : Basis \u03b9 R M)\n    (f : \u03b9 \u2192\u2080 R) (i : \u03b9) : Finsupp.total \u03b9 (Dual R M) R b.Coord f (b i) = f i :=\n  by\n  haveI := Classical.decEq \u03b9\n  rw [\u2190 coe_dual_basis, total_dual_basis]\n#align basis.total_coord Basis.total_coord\n\ntheorem dual_dim_eq [CommRing K] [AddCommGroup V] [Module K V] [Finite \u03b9] (b : Basis \u03b9 K V) :\n    Cardinal.lift (Module.rank K V) = Module.rank K (Dual K V) := by\n  classical\n    cases nonempty_fintype \u03b9\n    have := LinearEquiv.lift_dim_eq b.to_dual_equiv\n    simp only [Cardinal.lift_umax] at this\n    rw [this, \u2190 Cardinal.lift_umax]\n    apply Cardinal.lift_id\n#align basis.dual_dim_eq Basis.dual_dim_eq\n\nend Basis\n\nnamespace Module\n\nvariable {K V : Type _}\n\nvariable [Field K] [AddCommGroup V] [Module K V]\n\nopen Module Module.Dual Submodule LinearMap Cardinal Basis FiniteDimensional\n\nsection\n\nvariable (K) (V)\n\ntheorem eval_ker : (eval K V).ker = \u22a5 := by classical exact (Basis.ofVectorSpace K V).eval_ker\n#align module.eval_ker Module.eval_ker\n\ntheorem map_eval_injective : (Submodule.map (eval K V)).Injective :=\n  by\n  apply Submodule.map_injective_of_injective\n  rw [\u2190 LinearMap.ker_eq_bot]\n  apply eval_ker K V\n#align module.map_eval_injective Module.map_eval_injective\n\n-- elaborates faster than `exact`\ntheorem comap_eval_surjective : (Submodule.comap (eval K V)).Surjective :=\n  by\n  apply Submodule.comap_surjective_of_injective\n  rw [\u2190 LinearMap.ker_eq_bot]\n  apply eval_ker K V\n#align module.comap_eval_surjective Module.comap_eval_surjective\n\n-- elaborates faster than `exact`\nend\n\nsection\n\nvariable (K)\n\ntheorem eval_apply_eq_zero_iff (v : V) : (eval K V) v = 0 \u2194 v = 0 := by\n  simpa only using set_like.ext_iff.mp (eval_ker K V) v\n#align module.eval_apply_eq_zero_iff Module.eval_apply_eq_zero_iff\n\ntheorem eval_apply_injective : Function.Injective (eval K V) :=\n  (injective_iff_map_eq_zero' (eval K V)).mpr (eval_apply_eq_zero_iff K)\n#align module.eval_apply_injective Module.eval_apply_injective\n\ntheorem forall_dual_apply_eq_zero_iff (v : V) : (\u2200 \u03c6 : Module.Dual K V, \u03c6 v = 0) \u2194 v = 0 :=\n  by\n  rw [\u2190 eval_apply_eq_zero_iff K v, LinearMap.ext_iff]\n  rfl\n#align module.forall_dual_apply_eq_zero_iff Module.forall_dual_apply_eq_zero_iff\n\nend\n\n-- TODO(jmc): generalize to rings, once `module.rank` is generalized\ntheorem dual_dim_eq [FiniteDimensional K V] :\n    Cardinal.lift (Module.rank K V) = Module.rank K (Dual K V) :=\n  (Basis.ofVectorSpace K V).dual_dim_eq\n#align module.dual_dim_eq Module.dual_dim_eq\n\ntheorem erange_coe [FiniteDimensional K V] : (eval K V).range = \u22a4 :=\n  letI : IsNoetherian K V := IsNoetherian.iff_fg.2 inferInstance\n  (Basis.ofVectorSpace K V).eval_range\n#align module.erange_coe Module.erange_coe\n\nvariable (K V)\n\n/-- A vector space is linearly equivalent to the dual of its dual space. -/\ndef evalEquiv [FiniteDimensional K V] : V \u2243\u2097[K] Dual K (Dual K V) :=\n  LinearEquiv.ofBijective\n    (eval K V)-- 60x faster elaboration than using `ker_eq_bot.mp eval_ker` directly:\n    \u27e8by\n      rw [\u2190 ker_eq_bot]\n      apply eval_ker K V, range_eq_top.mp erange_coe\u27e9\n#align module.eval_equiv Module.evalEquiv\n\n/-- The isomorphism `module.eval_equiv` induces an order isomorphism on subspaces. -/\ndef mapEvalEquiv [FiniteDimensional K V] : Subspace K V \u2243o Subspace K (Dual K (Dual K V)) :=\n  Submodule.orderIsoMapComap (evalEquiv K V)\n#align module.map_eval_equiv Module.mapEvalEquiv\n\nvariable {K V}\n\n@[simp]\ntheorem evalEquiv_toLinearMap [FiniteDimensional K V] :\n    (evalEquiv K V).toLinearMap = Dual.eval K V :=\n  rfl\n#align module.eval_equiv_to_linear_map Module.evalEquiv_toLinearMap\n\n@[simp]\ntheorem mapEvalEquiv_apply [FiniteDimensional K V] (W : Subspace K V) :\n    mapEvalEquiv K V W = W.map (eval K V) :=\n  rfl\n#align module.map_eval_equiv_apply Module.mapEvalEquiv_apply\n\n@[simp]\ntheorem mapEvalEquiv_symm_apply [FiniteDimensional K V] (W'' : Subspace K (Dual K (Dual K V))) :\n    (mapEvalEquiv K V).symm W'' = W''.comap (eval K V) :=\n  rfl\n#align module.map_eval_equiv_symm_apply Module.mapEvalEquiv_symm_apply\n\nend Module\n\nsection DualBases\n\nopen Module\n\nvariable {R M \u03b9 : Type _}\n\nvariable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq \u03b9]\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/\n-- TODO: In Lean 4 we can remove this and use `by { intros; exact Set.toFinite _ }` as a default\n-- argument.\n/-- Try using `set.to_finite` to dispatch a `set.finite` goal. -/\nunsafe def use_finite_instance : tactic Unit :=\n  sorry\n#align use_finite_instance use_finite_instance\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic use_finite_instance -/\n/-- `e` and `\u03b5` have characteristic properties of a basis and its dual -/\n@[nolint has_nonempty_instance]\nstructure Module.DualBases (e : \u03b9 \u2192 M) (\u03b5 : \u03b9 \u2192 Dual R M) : Prop where\n  eval : \u2200 i j : \u03b9, \u03b5 i (e j) = if i = j then 1 else 0\n  Total : \u2200 {m : M}, (\u2200 i, \u03b5 i m = 0) \u2192 m = 0\n  Finite : \u2200 m : M, { i | \u03b5 i m \u2260 0 }.Finite := by\n    run_tac\n      use_finite_instance\n#align module.dual_bases Module.DualBases\n\nend DualBases\n\nnamespace Module.DualBases\n\nopen Module Module.Dual LinearMap Function\n\nvariable {R M \u03b9 : Type _}\n\nvariable [CommRing R] [AddCommGroup M] [Module R M]\n\nvariable {e : \u03b9 \u2192 M} {\u03b5 : \u03b9 \u2192 Dual R M}\n\n/-- The coefficients of `v` on the basis `e` -/\ndef coeffs [DecidableEq \u03b9] (h : DualBases e \u03b5) (m : M) : \u03b9 \u2192\u2080 R\n    where\n  toFun i := \u03b5 i m\n  support := (h.Finite m).toFinset\n  mem_support_toFun := by\n    intro i\n    rw [Set.Finite.mem_toFinset, Set.mem_setOf_eq]\n#align module.dual_bases.coeffs Module.DualBases.coeffs\n\n@[simp]\ntheorem coeffs_apply [DecidableEq \u03b9] (h : DualBases e \u03b5) (m : M) (i : \u03b9) : h.coeffs m i = \u03b5 i m :=\n  rfl\n#align module.dual_bases.coeffs_apply Module.DualBases.coeffs_apply\n\n/-- linear combinations of elements of `e`.\nThis is a convenient abbreviation for `finsupp.total _ M R e l` -/\ndef lc {\u03b9} (e : \u03b9 \u2192 M) (l : \u03b9 \u2192\u2080 R) : M :=\n  l.Sum fun (i : \u03b9) (a : R) => a \u2022 e i\n#align module.dual_bases.lc Module.DualBases.lc\n\ntheorem lc_def (e : \u03b9 \u2192 M) (l : \u03b9 \u2192\u2080 R) : lc e l = Finsupp.total _ _ _ e l :=\n  rfl\n#align module.dual_bases.lc_def Module.DualBases.lc_def\n\nopen Module\n\nvariable [DecidableEq \u03b9] (h : DualBases e \u03b5)\n\ninclude h\n\ntheorem dual_lc (l : \u03b9 \u2192\u2080 R) (i : \u03b9) : \u03b5 i (DualBases.lc e l) = l i :=\n  by\n  erw [LinearMap.map_sum]\n  simp only [h.eval, map_smul, smul_eq_mul]\n  rw [Finset.sum_eq_single i]\n  \u00b7 simp\n  \u00b7 intro q q_in q_ne\n    simp [q_ne.symm]\n  \u00b7 intro p_not_in\n    simp [Finsupp.not_mem_support_iff.1 p_not_in]\n#align module.dual_bases.dual_lc Module.DualBases.dual_lc\n\n@[simp]\ntheorem coeffs_lc (l : \u03b9 \u2192\u2080 R) : h.coeffs (DualBases.lc e l) = l :=\n  by\n  ext i\n  rw [h.coeffs_apply, h.dual_lc]\n#align module.dual_bases.coeffs_lc Module.DualBases.coeffs_lc\n\n/-- For any m : M n, \\sum_{p \u2208 Q n} (\u03b5 p m) \u2022 e p = m -/\n@[simp]\ntheorem lc_coeffs (m : M) : DualBases.lc e (h.coeffs m) = m :=\n  by\n  refine' eq_of_sub_eq_zero (h.total _)\n  intro i\n  simp [-sub_eq_add_neg, LinearMap.map_sub, h.dual_lc, sub_eq_zero]\n#align module.dual_bases.lc_coeffs Module.DualBases.lc_coeffs\n\n/-- `(h : dual_bases e \u03b5).basis` shows the family of vectors `e` forms a basis. -/\n@[simps]\ndef basis : Basis \u03b9 R M :=\n  Basis.ofRepr\n    { toFun := coeffs h\n      invFun := lc e\n      left_inv := lc_coeffs h\n      right_inv := coeffs_lc h\n      map_add' := fun v w => by\n        ext i\n        exact (\u03b5 i).map_add v w\n      map_smul' := fun c v => by\n        ext i\n        exact (\u03b5 i).map_smul c v }\n#align module.dual_bases.basis Module.DualBases.basis\n\n@[simp]\ntheorem coe_basis : \u21d1h.Basis = e := by\n  ext i\n  rw [Basis.apply_eq_iff]\n  ext j\n  rw [h.basis_repr_apply, coeffs_apply, h.eval, Finsupp.single_apply]\n  convert if_congr eq_comm rfl rfl\n#align module.dual_bases.coe_basis Module.DualBases.coe_basis\n\n-- `convert` to get rid of a `decidable_eq` mismatch\ntheorem mem_of_mem_span {H : Set \u03b9} {x : M} (hmem : x \u2208 Submodule.span R (e '' H)) :\n    \u2200 i : \u03b9, \u03b5 i x \u2260 0 \u2192 i \u2208 H := by\n  intro i hi\n  rcases(Finsupp.mem_span_image_iff_total _).mp hmem with \u27e8l, supp_l, rfl\u27e9\n  apply not_imp_comm.mp ((Finsupp.mem_supported' _ _).mp supp_l i)\n  rwa [\u2190 lc_def, h.dual_lc] at hi\n#align module.dual_bases.mem_of_mem_span Module.DualBases.mem_of_mem_span\n\ntheorem coe_dualBasis [Fintype \u03b9] : \u21d1h.Basis.dualBasis = \u03b5 :=\n  funext fun i =>\n    h.Basis.ext fun j => by\n      rw [h.basis.dual_basis_apply_self, h.coe_basis, h.eval, if_congr eq_comm rfl rfl]\n#align module.dual_bases.coe_dual_basis Module.DualBases.coe_dualBasis\n\nend Module.DualBases\n\nnamespace Submodule\n\nuniverse u v w\n\nvariable {R : Type u} {M : Type v} [CommSemiring R] [AddCommMonoid M] [Module R M]\n\nvariable {W : Submodule R M}\n\n/-- The `dual_restrict` of a submodule `W` of `M` is the linear map from the\n  dual of `M` to the dual of `W` such that the domain of each linear map is\n  restricted to `W`. -/\ndef dualRestrict (W : Submodule R M) : Module.Dual R M \u2192\u2097[R] Module.Dual R W :=\n  LinearMap.domRestrict' W\n#align submodule.dual_restrict Submodule.dualRestrict\n\ntheorem dualRestrict_def (W : Submodule R M) : W.dualRestrict = W.Subtype.dualMap :=\n  rfl\n#align submodule.dual_restrict_def Submodule.dualRestrict_def\n\n@[simp]\ntheorem dualRestrict_apply (W : Submodule R M) (\u03c6 : Module.Dual R M) (x : W) :\n    W.dualRestrict \u03c6 x = \u03c6 (x : M) :=\n  rfl\n#align submodule.dual_restrict_apply Submodule.dualRestrict_apply\n\n/-- The `dual_annihilator` of a submodule `W` is the set of linear maps `\u03c6` such\n  that `\u03c6 w = 0` for all `w \u2208 W`. -/\ndef dualAnnihilator {R : Type u} {M : Type v} [CommSemiring R] [AddCommMonoid M] [Module R M]\n    (W : Submodule R M) : Submodule R <| Module.Dual R M :=\n  W.dualRestrict.ker\n#align submodule.dual_annihilator Submodule.dualAnnihilator\n\n@[simp]\ntheorem mem_dualAnnihilator (\u03c6 : Module.Dual R M) : \u03c6 \u2208 W.dualAnnihilator \u2194 \u2200 w \u2208 W, \u03c6 w = 0 :=\n  by\n  refine' linear_map.mem_ker.trans _\n  simp_rw [LinearMap.ext_iff, dual_restrict_apply]\n  exact \u27e8fun h w hw => h \u27e8w, hw\u27e9, fun h w => h w.1 w.2\u27e9\n#align submodule.mem_dual_annihilator Submodule.mem_dualAnnihilator\n\n/-- That $\\operatorname{ker}(\\iota^* : V^* \\to W^*) = \\operatorname{ann}(W)$.\nThis is the definition of the dual annihilator of the submodule $W$. -/\ntheorem dualRestrict_ker_eq_dualAnnihilator (W : Submodule R M) :\n    W.dualRestrict.ker = W.dualAnnihilator :=\n  rfl\n#align submodule.dual_restrict_ker_eq_dual_annihilator Submodule.dualRestrict_ker_eq_dualAnnihilator\n\n/-- The `dual_annihilator` of a submodule of the dual space pulled back along the evaluation map\n`module.dual.eval`. -/\ndef dualCoannihilator (\u03a6 : Submodule R (Module.Dual R M)) : Submodule R M :=\n  \u03a6.dualAnnihilator.comap (Module.Dual.eval R M)\n#align submodule.dual_coannihilator Submodule.dualCoannihilator\n\ntheorem mem_dualCoannihilator {\u03a6 : Submodule R (Module.Dual R M)} (x : M) :\n    x \u2208 \u03a6.dualCoannihilator \u2194 \u2200 \u03c6 \u2208 \u03a6, (\u03c6 x : R) = 0 := by\n  simp_rw [dual_coannihilator, mem_comap, mem_dual_annihilator, Module.Dual.eval_apply]\n#align submodule.mem_dual_coannihilator Submodule.mem_dualCoannihilator\n\ntheorem dualAnnihilator_gc (R M : Type _) [CommSemiring R] [AddCommMonoid M] [Module R M] :\n    GaloisConnection\n      (OrderDual.toDual \u2218 (dualAnnihilator : Submodule R M \u2192 Submodule R (Module.Dual R M)))\n      (dualCoannihilator \u2218 OrderDual.ofDual) :=\n  by\n  intro a b\n  induction b using OrderDual.rec\n  simp only [Function.comp_apply, OrderDual.toDual_le_toDual, OrderDual.ofDual_toDual]\n  constructor <;>\n    \u00b7 intro h x hx\n      simp only [mem_dual_annihilator, mem_dual_coannihilator]\n      intro y hy\n      have := h hy\n      simp only [mem_dual_annihilator, mem_dual_coannihilator] at this\n      exact this x hx\n#align submodule.dual_annihilator_gc Submodule.dualAnnihilator_gc\n\ntheorem le_dualAnnihilator_iff_le_dualCoannihilator {U : Submodule R (Module.Dual R M)}\n    {V : Submodule R M} : U \u2264 V.dualAnnihilator \u2194 V \u2264 U.dualCoannihilator :=\n  (dualAnnihilator_gc R M).le_iff_le\n#align submodule.le_dual_annihilator_iff_le_dual_coannihilator Submodule.le_dualAnnihilator_iff_le_dualCoannihilator\n\n@[simp]\ntheorem dualAnnihilator_bot : (\u22a5 : Submodule R M).dualAnnihilator = \u22a4 :=\n  (dualAnnihilator_gc R M).l_bot\n#align submodule.dual_annihilator_bot Submodule.dualAnnihilator_bot\n\n@[simp]\ntheorem dualAnnihilator_top : (\u22a4 : Submodule R M).dualAnnihilator = \u22a5 :=\n  by\n  rw [eq_bot_iff]\n  intro v\n  simp_rw [mem_dual_annihilator, mem_bot, mem_top, forall_true_left]\n  exact fun h => LinearMap.ext h\n#align submodule.dual_annihilator_top Submodule.dualAnnihilator_top\n\n@[simp]\ntheorem dualCoannihilator_bot : (\u22a5 : Submodule R (Module.Dual R M)).dualCoannihilator = \u22a4 :=\n  (dualAnnihilator_gc R M).u_top\n#align submodule.dual_coannihilator_bot Submodule.dualCoannihilator_bot\n\n@[mono]\ntheorem dualAnnihilator_anti {U V : Submodule R M} (hUV : U \u2264 V) :\n    V.dualAnnihilator \u2264 U.dualAnnihilator :=\n  (dualAnnihilator_gc R M).monotone_l hUV\n#align submodule.dual_annihilator_anti Submodule.dualAnnihilator_anti\n\n@[mono]\ntheorem dualCoannihilator_anti {U V : Submodule R (Module.Dual R M)} (hUV : U \u2264 V) :\n    V.dualCoannihilator \u2264 U.dualCoannihilator :=\n  (dualAnnihilator_gc R M).monotone_u hUV\n#align submodule.dual_coannihilator_anti Submodule.dualCoannihilator_anti\n\ntheorem le_dualAnnihilator_dualCoannihilator (U : Submodule R M) :\n    U \u2264 U.dualAnnihilator.dualCoannihilator :=\n  (dualAnnihilator_gc R M).le_u_l U\n#align submodule.le_dual_annihilator_dual_coannihilator Submodule.le_dualAnnihilator_dualCoannihilator\n\ntheorem le_dualCoannihilator_dualAnnihilator (U : Submodule R (Module.Dual R M)) :\n    U \u2264 U.dualCoannihilator.dualAnnihilator :=\n  (dualAnnihilator_gc R M).l_u_le U\n#align submodule.le_dual_coannihilator_dual_annihilator Submodule.le_dualCoannihilator_dualAnnihilator\n\ntheorem dualAnnihilator_dualCoannihilator_dualAnnihilator (U : Submodule R M) :\n    U.dualAnnihilator.dualCoannihilator.dualAnnihilator = U.dualAnnihilator :=\n  (dualAnnihilator_gc R M).l_u_l_eq_l U\n#align submodule.dual_annihilator_dual_coannihilator_dual_annihilator Submodule.dualAnnihilator_dualCoannihilator_dualAnnihilator\n\ntheorem dualCoannihilator_dualAnnihilator_dualCoannihilator (U : Submodule R (Module.Dual R M)) :\n    U.dualCoannihilator.dualAnnihilator.dualCoannihilator = U.dualCoannihilator :=\n  (dualAnnihilator_gc R M).u_l_u_eq_u U\n#align submodule.dual_coannihilator_dual_annihilator_dual_coannihilator Submodule.dualCoannihilator_dualAnnihilator_dualCoannihilator\n\ntheorem dualAnnihilator_sup_eq (U V : Submodule R M) :\n    (U \u2294 V).dualAnnihilator = U.dualAnnihilator \u2293 V.dualAnnihilator :=\n  (dualAnnihilator_gc R M).l_sup\n#align submodule.dual_annihilator_sup_eq Submodule.dualAnnihilator_sup_eq\n\ntheorem dualCoannihilator_sup_eq (U V : Submodule R (Module.Dual R M)) :\n    (U \u2294 V).dualCoannihilator = U.dualCoannihilator \u2293 V.dualCoannihilator :=\n  (dualAnnihilator_gc R M).u_inf\n#align submodule.dual_coannihilator_sup_eq Submodule.dualCoannihilator_sup_eq\n\ntheorem dualAnnihilator_sup\u1d62_eq {\u03b9 : Type _} (U : \u03b9 \u2192 Submodule R M) :\n    (\u2a06 i : \u03b9, U i).dualAnnihilator = \u2a05 i : \u03b9, (U i).dualAnnihilator :=\n  (dualAnnihilator_gc R M).l_sup\u1d62\n#align submodule.dual_annihilator_supr_eq Submodule.dualAnnihilator_sup\u1d62_eq\n\ntheorem dualCoannihilator_sup\u1d62_eq {\u03b9 : Type _} (U : \u03b9 \u2192 Submodule R (Module.Dual R M)) :\n    (\u2a06 i : \u03b9, U i).dualCoannihilator = \u2a05 i : \u03b9, (U i).dualCoannihilator :=\n  (dualAnnihilator_gc R M).u_inf\u1d62\n#align submodule.dual_coannihilator_supr_eq Submodule.dualCoannihilator_sup\u1d62_eq\n\n/-- See also `subspace.dual_annihilator_inf_eq` for vector subspaces. -/\ntheorem sup_dualAnnihilator_le_inf (U V : Submodule R M) :\n    U.dualAnnihilator \u2294 V.dualAnnihilator \u2264 (U \u2293 V).dualAnnihilator :=\n  by\n  rw [le_dual_annihilator_iff_le_dual_coannihilator, dual_coannihilator_sup_eq]\n  apply inf_le_inf <;> exact le_dual_annihilator_dual_coannihilator _\n#align submodule.sup_dual_annihilator_le_inf Submodule.sup_dualAnnihilator_le_inf\n\n/-- See also `subspace.dual_annihilator_infi_eq` for vector subspaces when `\u03b9` is finite. -/\ntheorem sup\u1d62_dualAnnihilator_le_inf\u1d62 {\u03b9 : Type _} (U : \u03b9 \u2192 Submodule R M) :\n    (\u2a06 i : \u03b9, (U i).dualAnnihilator) \u2264 (\u2a05 i : \u03b9, U i).dualAnnihilator :=\n  by\n  rw [le_dual_annihilator_iff_le_dual_coannihilator, dual_coannihilator_supr_eq]\n  apply inf\u1d62_mono\n  exact fun i : \u03b9 => le_dual_annihilator_dual_coannihilator (U i)\n#align submodule.supr_dual_annihilator_le_infi Submodule.sup\u1d62_dualAnnihilator_le_inf\u1d62\n\nend Submodule\n\nnamespace Subspace\n\nopen Submodule LinearMap\n\nuniverse u v w\n\n-- We work in vector spaces because `exists_is_compl` only hold for vector spaces\nvariable {K : Type u} {V : Type v} [Field K] [AddCommGroup V] [Module K V]\n\n@[simp]\ntheorem dualCoannihilator_top (W : Subspace K V) :\n    (\u22a4 : Subspace K (Module.Dual K W)).dualCoannihilator = \u22a5 := by\n  rw [dual_coannihilator, dual_annihilator_top, comap_bot, Module.eval_ker]\n#align subspace.dual_coannihilator_top Subspace.dualCoannihilator_top\n\ntheorem dualAnnihilator_dualCoannihilator_eq {W : Subspace K V} :\n    W.dualAnnihilator.dualCoannihilator = W :=\n  by\n  refine' le_antisymm _ (le_dual_annihilator_dual_coannihilator _)\n  intro v\n  simp only [mem_dual_annihilator, mem_dual_coannihilator]\n  contrapose!\n  intro hv\n  obtain \u27e8W', hW\u27e9 := Submodule.exists_isCompl W\n  obtain \u27e8\u27e8w, w'\u27e9, rfl, -\u27e9 := exists_unique_add_of_is_compl_prod hW v\n  have hw'n : (w' : V) \u2209 W := by\n    contrapose! hv\n    exact Submodule.add_mem W w.2 hv\n  have hw'nz : w' \u2260 0 := by\n    rintro rfl\n    exact hw'n (Submodule.zero_mem W)\n  rw [Ne.def, \u2190 Module.forall_dual_apply_eq_zero_iff K w'] at hw'nz\n  push_neg  at hw'nz\n  obtain \u27e8\u03c6, h\u03c6\u27e9 := hw'nz\n  exists ((LinearMap.ofIsComplProd hW).comp (LinearMap.inr _ _ _)) \u03c6\n  simp only [coe_comp, coe_inr, Function.comp_apply, of_is_compl_prod_apply, map_add,\n    of_is_compl_left_apply, zero_apply, of_is_compl_right_apply, zero_add, Ne.def]\n  refine' \u27e8_, h\u03c6\u27e9\n  intro v hv\n  apply LinearMap.ofIsCompl_left_apply hW \u27e8v, hv\u27e9\n#align subspace.dual_annihilator_dual_coannihilator_eq Subspace.dualAnnihilator_dualCoannihilator_eq\n\n-- exact elaborates slowly\ntheorem forall_mem_dualAnnihilator_apply_eq_zero_iff (W : Subspace K V) (v : V) :\n    (\u2200 \u03c6 : Module.Dual K V, \u03c6 \u2208 W.dualAnnihilator \u2192 \u03c6 v = 0) \u2194 v \u2208 W := by\n  rw [\u2190 set_like.ext_iff.mp dual_annihilator_dual_coannihilator_eq v, mem_dual_coannihilator]\n#align subspace.forall_mem_dual_annihilator_apply_eq_zero_iff Subspace.forall_mem_dualAnnihilator_apply_eq_zero_iff\n\n/-- `submodule.dual_annihilator` and `submodule.dual_coannihilator` form a Galois coinsertion. -/\ndef dualAnnihilatorGci (K V : Type _) [Field K] [AddCommGroup V] [Module K V] :\n    GaloisCoinsertion\n      (OrderDual.toDual \u2218 (dualAnnihilator : Subspace K V \u2192 Subspace K (Module.Dual K V)))\n      (dualCoannihilator \u2218 OrderDual.ofDual)\n    where\n  choice W h := dualCoannihilator W\n  gc := dualAnnihilator_gc K V\n  u_l_le W := dualAnnihilator_dualCoannihilator_eq.le\n  choice_eq W h := rfl\n#align subspace.dual_annihilator_gci Subspace.dualAnnihilatorGci\n\ntheorem dualAnnihilator_le_dualAnnihilator_iff {W W' : Subspace K V} :\n    W.dualAnnihilator \u2264 W'.dualAnnihilator \u2194 W' \u2264 W :=\n  (dualAnnihilatorGci K V).l_le_l_iff\n#align subspace.dual_annihilator_le_dual_annihilator_iff Subspace.dualAnnihilator_le_dualAnnihilator_iff\n\ntheorem dualAnnihilator_inj {W W' : Subspace K V} :\n    W.dualAnnihilator = W'.dualAnnihilator \u2194 W = W' :=\n  by\n  constructor\n  \u00b7 apply (dual_annihilator_gci K V).l_injective\n  \u00b7 rintro rfl\n    rfl\n#align subspace.dual_annihilator_inj Subspace.dualAnnihilator_inj\n\n/-- Given a subspace `W` of `V` and an element of its dual `\u03c6`, `dual_lift W \u03c6` is\nan arbitrary extension of `\u03c6` to an element of the dual of `V`.\nThat is, `dual_lift W \u03c6` sends `w \u2208 W` to `\u03c6 x` and `x` in a chosen complement of `W` to `0`. -/\nnoncomputable def dualLift (W : Subspace K V) : Module.Dual K W \u2192\u2097[K] Module.Dual K V :=\n  let h := Classical.indefiniteDescription _ W.exists_isCompl\n  (LinearMap.ofIsComplProd h.2).comp (LinearMap.inl _ _ _)\n#align subspace.dual_lift Subspace.dualLift\n\nvariable {W : Subspace K V}\n\n@[simp]\ntheorem dualLift_of_subtype {\u03c6 : Module.Dual K W} (w : W) : W.dualLift \u03c6 (w : V) = \u03c6 w :=\n  by\n  erw [of_is_compl_left_apply _ w]\n  rfl\n#align subspace.dual_lift_of_subtype Subspace.dualLift_of_subtype\n\ntheorem dualLift_of_mem {\u03c6 : Module.Dual K W} {w : V} (hw : w \u2208 W) : W.dualLift \u03c6 w = \u03c6 \u27e8w, hw\u27e9 :=\n  by convert dual_lift_of_subtype \u27e8w, hw\u27e9\n#align subspace.dual_lift_of_mem Subspace.dualLift_of_mem\n\n@[simp]\ntheorem dualRestrict_comp_dualLift (W : Subspace K V) : W.dualRestrict.comp W.dualLift = 1 :=\n  by\n  ext (\u03c6 x)\n  simp\n#align subspace.dual_restrict_comp_dual_lift Subspace.dualRestrict_comp_dualLift\n\ntheorem dualRestrict_leftInverse (W : Subspace K V) :\n    Function.LeftInverse W.dualRestrict W.dualLift := fun x =>\n  show W.dualRestrict.comp W.dualLift x = x\n    by\n    rw [dual_restrict_comp_dual_lift]\n    rfl\n#align subspace.dual_restrict_left_inverse Subspace.dualRestrict_leftInverse\n\ntheorem dualLift_rightInverse (W : Subspace K V) :\n    Function.RightInverse W.dualLift W.dualRestrict :=\n  W.dualRestrict_leftInverse\n#align subspace.dual_lift_right_inverse Subspace.dualLift_rightInverse\n\ntheorem dualRestrict_surjective : Function.Surjective W.dualRestrict :=\n  W.dualLift_rightInverse.Surjective\n#align subspace.dual_restrict_surjective Subspace.dualRestrict_surjective\n\ntheorem dualLift_injective : Function.Injective W.dualLift :=\n  W.dualRestrict_leftInverse.Injective\n#align subspace.dual_lift_injective Subspace.dualLift_injective\n\n/-- The quotient by the `dual_annihilator` of a subspace is isomorphic to the\n  dual of that subspace. -/\nnoncomputable def quotAnnihilatorEquiv (W : Subspace K V) :\n    (Module.Dual K V \u29f8 W.dualAnnihilator) \u2243\u2097[K] Module.Dual K W :=\n  (quotEquivOfEq _ _ W.dualRestrict_ker_eq_dualAnnihilator).symm.trans <|\n    W.dualRestrict.quotKerEquivOfSurjective dualRestrict_surjective\n#align subspace.quot_annihilator_equiv Subspace.quotAnnihilatorEquiv\n\n@[simp]\ntheorem quotAnnihilatorEquiv_apply (W : Subspace K V) (\u03c6 : Module.Dual K V) :\n    W.quotAnnihilatorEquiv (Submodule.Quotient.mk \u03c6) = W.dualRestrict \u03c6 :=\n  by\n  ext\n  rfl\n#align subspace.quot_annihilator_equiv_apply Subspace.quotAnnihilatorEquiv_apply\n\n/-- The natural isomorphism from the dual of a subspace `W` to `W.dual_lift.range`. -/\nnoncomputable def dualEquivDual (W : Subspace K V) : Module.Dual K W \u2243\u2097[K] W.dualLift.range :=\n  LinearEquiv.ofInjective _ dualLift_injective\n#align subspace.dual_equiv_dual Subspace.dualEquivDual\n\ntheorem dualEquivDual_def (W : Subspace K V) :\n    W.dualEquivDual.toLinearMap = W.dualLift.range_restrict :=\n  rfl\n#align subspace.dual_equiv_dual_def Subspace.dualEquivDual_def\n\n@[simp]\ntheorem dualEquivDual_apply (\u03c6 : Module.Dual K W) :\n    W.dualEquivDual \u03c6 = \u27e8W.dualLift \u03c6, mem_range.2 \u27e8\u03c6, rfl\u27e9\u27e9 :=\n  rfl\n#align subspace.dual_equiv_dual_apply Subspace.dualEquivDual_apply\n\nsection\n\nopen Classical\n\nopen FiniteDimensional\n\nvariable {V\u2081 : Type _} [AddCommGroup V\u2081] [Module K V\u2081]\n\ninstance [H : FiniteDimensional K V] : FiniteDimensional K (Module.Dual K V) := by infer_instance\n\nvariable [FiniteDimensional K V] [FiniteDimensional K V\u2081]\n\ntheorem dualAnnihilator_dualAnnihilator_eq (W : Subspace K V) :\n    W.dualAnnihilator.dualAnnihilator = Module.mapEvalEquiv K V W :=\n  by\n  have : _ = W := Subspace.dualAnnihilator_dualCoannihilator_eq\n  rw [dual_coannihilator, \u2190 Module.mapEvalEquiv_symm_apply] at this\n  rwa [\u2190 OrderIso.symm_apply_eq]\n#align subspace.dual_annihilator_dual_annihilator_eq Subspace.dualAnnihilator_dualAnnihilator_eq\n\n-- TODO(kmill): https://github.com/leanprover-community/mathlib/pull/17521#discussion_r1083241963\n@[simp]\ntheorem dual_finrank_eq : finrank K (Module.Dual K V) = finrank K V :=\n  LinearEquiv.finrank_eq (Basis.ofVectorSpace K V).toDualEquiv.symm\n#align subspace.dual_finrank_eq Subspace.dual_finrank_eq\n\n/-- The quotient by the dual is isomorphic to its dual annihilator.  -/\nnoncomputable def quotDualEquivAnnihilator (W : Subspace K V) :\n    (Module.Dual K V \u29f8 W.dualLift.range) \u2243\u2097[K] W.dualAnnihilator :=\n  LinearEquiv.quotEquivOfQuotEquiv <| LinearEquiv.trans W.quotAnnihilatorEquiv W.dualEquivDual\n#align subspace.quot_dual_equiv_annihilator Subspace.quotDualEquivAnnihilator\n\n/-- The quotient by a subspace is isomorphic to its dual annihilator. -/\nnoncomputable def quotEquivAnnihilator (W : Subspace K V) : (V \u29f8 W) \u2243\u2097[K] W.dualAnnihilator :=\n  by\n  refine' _ \u226a\u226b\u2097 W.quot_dual_equiv_annihilator\n  refine' linear_equiv.quot_equiv_of_equiv _ (Basis.ofVectorSpace K V).toDualEquiv\n  exact (Basis.ofVectorSpace K W).toDualEquiv.trans W.dual_equiv_dual\n#align subspace.quot_equiv_annihilator Subspace.quotEquivAnnihilator\n\nopen FiniteDimensional\n\n@[simp]\ntheorem finrank_dualCoannihilator_eq {\u03a6 : Subspace K (Module.Dual K V)} :\n    finrank K \u03a6.dualCoannihilator = finrank K \u03a6.dualAnnihilator :=\n  by\n  rw [Submodule.dualCoannihilator, \u2190 Module.evalEquiv_toLinearMap]\n  exact LinearEquiv.finrank_eq (LinearEquiv.ofSubmodule' _ _)\n#align subspace.finrank_dual_coannihilator_eq Subspace.finrank_dualCoannihilator_eq\n\ntheorem finrank_add_finrank_dualCoannihilator_eq (W : Subspace K (Module.Dual K V)) :\n    finrank K W + finrank K W.dualCoannihilator = finrank K V := by\n  rw [finrank_dual_coannihilator_eq, W.quot_equiv_annihilator.finrank_eq.symm, add_comm,\n    Submodule.finrank_quotient_add_finrank, Subspace.dual_finrank_eq]\n#align subspace.finrank_add_finrank_dual_coannihilator_eq Subspace.finrank_add_finrank_dualCoannihilator_eq\n\nend\n\nend Subspace\n\nopen Module\n\nnamespace LinearMap\n\nvariable {R : Type _} [CommSemiring R] {M\u2081 : Type _} {M\u2082 : Type _}\n\nvariable [AddCommMonoid M\u2081] [Module R M\u2081] [AddCommMonoid M\u2082] [Module R M\u2082]\n\nvariable (f : M\u2081 \u2192\u2097[R] M\u2082)\n\ntheorem ker_dualMap_eq_dualAnnihilator_range : f.dualMap.ker = f.range.dualAnnihilator :=\n  by\n  ext \u03c6; constructor <;> intro h\u03c6\n  \u00b7 rw [mem_ker] at h\u03c6\n    rw [Submodule.mem_dualAnnihilator]\n    rintro y \u27e8x, rfl\u27e9\n    rw [\u2190 dual_map_apply, h\u03c6, zero_apply]\n  \u00b7 ext x\n    rw [dual_map_apply]\n    rw [Submodule.mem_dualAnnihilator] at h\u03c6\n    exact h\u03c6 (f x) \u27e8x, rfl\u27e9\n#align linear_map.ker_dual_map_eq_dual_annihilator_range LinearMap.ker_dualMap_eq_dualAnnihilator_range\n\ntheorem range_dualMap_le_dualAnnihilator_ker : f.dualMap.range \u2264 f.ker.dualAnnihilator :=\n  by\n  rintro _ \u27e8\u03c8, rfl\u27e9\n  simp_rw [Submodule.mem_dualAnnihilator, mem_ker]\n  rintro x hx\n  rw [dual_map_apply, hx, map_zero]\n#align linear_map.range_dual_map_le_dual_annihilator_ker LinearMap.range_dualMap_le_dualAnnihilator_ker\n\nend LinearMap\n\nsection CommRing\n\nvariable {R M M' : Type _}\n\nvariable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup M'] [Module R M']\n\nnamespace Submodule\n\n/-- Given a submodule, corestrict to the pairing on `M \u29f8 W` by\nsimultaneously restricting to `W.dual_annihilator`.\n\nSee `subspace.dual_copairing_nondegenerate`. -/\ndef dualCopairing (W : Submodule R M) : W.dualAnnihilator \u2192\u2097[R] M \u29f8 W \u2192\u2097[R] R :=\n  LinearMap.flip <|\n    W.liftQ ((Module.dualPairing R M).domRestrict W.dualAnnihilator).flip\n      (by\n        intro w hw\n        ext \u27e8\u03c6, h\u03c6\u27e9\n        exact (mem_dual_annihilator \u03c6).mp h\u03c6 w hw)\n#align submodule.dual_copairing Submodule.dualCopairing\n\n@[simp]\ntheorem dualCopairing_apply {W : Submodule R M} (\u03c6 : W.dualAnnihilator) (x : M) :\n    W.dualCopairing \u03c6 (Quotient.mk x) = \u03c6 x :=\n  rfl\n#align submodule.dual_copairing_apply Submodule.dualCopairing_apply\n\n/-- Given a submodule, restrict to the pairing on `W` by\nsimultaneously corestricting to `module.dual R M \u29f8 W.dual_annihilator`.\nThis is `submodule.dual_restrict` factored through the quotient by its kernel (which\nis `W.dual_annihilator` by definition).\n\nSee `subspace.dual_pairing_nondegenerate`. -/\ndef dualPairing (W : Submodule R M) : Module.Dual R M \u29f8 W.dualAnnihilator \u2192\u2097[R] W \u2192\u2097[R] R :=\n  W.dualAnnihilator.liftQ W.dualRestrict le_rfl\n#align submodule.dual_pairing Submodule.dualPairing\n\n@[simp]\ntheorem dualPairing_apply {W : Submodule R M} (\u03c6 : Module.Dual R M) (x : W) :\n    W.dualPairing (Quotient.mk \u03c6) x = \u03c6 x :=\n  rfl\n#align submodule.dual_pairing_apply Submodule.dualPairing_apply\n\n/-- That $\\operatorname{im}(q^* : (V/W)^* \\to V^*) = \\operatorname{ann}(W)$. -/\ntheorem range_dualMap_mkQ_eq (W : Submodule R M) : W.mkQ.dualMap.range = W.dualAnnihilator :=\n  by\n  ext \u03c6\n  rw [LinearMap.mem_range]\n  constructor\n  \u00b7 rintro \u27e8\u03c8, rfl\u27e9\n    have := LinearMap.mem_range_self W.mkq.dual_map \u03c8\n    simpa only [ker_mkq] using LinearMap.range_dualMap_le_dualAnnihilator_ker W.mkq this\n  \u00b7 intro h\u03c6\n    exists W.dual_copairing \u27e8\u03c6, h\u03c6\u27e9\n    ext\n    rfl\n#align submodule.range_dual_map_mkq_eq Submodule.range_dualMap_mkQ_eq\n\n/-- Equivalence $(M/W)^* \\approx \\operatorname{ann}(W)$. That is, there is a one-to-one\ncorrespondence between the dual of `M \u29f8 W` and those elements of the dual of `M` that\nvanish on `W`.\n\nThe inverse of this is `submodule.dual_copairing`. -/\ndef dualQuotEquivDualAnnihilator (W : Submodule R M) :\n    Module.Dual R (M \u29f8 W) \u2243\u2097[R] W.dualAnnihilator :=\n  LinearEquiv.ofLinear\n    (W.mkQ.dualMap.codRestrict W.dualAnnihilator fun \u03c6 =>\n      W.range_dualMap_mkQ_eq \u25b8 W.mkQ.dualMap.mem_range_self \u03c6)\n    W.dualCopairing\n    (by\n      ext\n      rfl)\n    (by\n      ext\n      rfl)\n#align submodule.dual_quot_equiv_dual_annihilator Submodule.dualQuotEquivDualAnnihilator\n\n@[simp]\ntheorem dualQuotEquivDualAnnihilator_apply (W : Submodule R M) (\u03c6 : Module.Dual R (M \u29f8 W)) (x : M) :\n    dualQuotEquivDualAnnihilator W \u03c6 x = \u03c6 (Quotient.mk x) :=\n  rfl\n#align submodule.dual_quot_equiv_dual_annihilator_apply Submodule.dualQuotEquivDualAnnihilator_apply\n\ntheorem dualCopairing_eq (W : Submodule R M) :\n    W.dualCopairing = (dualQuotEquivDualAnnihilator W).symm.toLinearMap :=\n  rfl\n#align submodule.dual_copairing_eq Submodule.dualCopairing_eq\n\n@[simp]\ntheorem dualQuotEquivDualAnnihilator_symm_apply_mk (W : Submodule R M) (\u03c6 : W.dualAnnihilator)\n    (x : M) : (dualQuotEquivDualAnnihilator W).symm \u03c6 (Quotient.mk x) = \u03c6 x :=\n  rfl\n#align submodule.dual_quot_equiv_dual_annihilator_symm_apply_mk Submodule.dualQuotEquivDualAnnihilator_symm_apply_mk\n\nend Submodule\n\nnamespace LinearMap\n\nopen Submodule\n\ntheorem range_dualMap_eq_dualAnnihilator_ker_of_surjective (f : M \u2192\u2097[R] M')\n    (hf : Function.Surjective f) : f.dualMap.range = f.ker.dualAnnihilator :=\n  by\n  rw [\u2190 f.ker.range_dual_map_mkq_eq]\n  let f' := LinearMap.quotKerEquivOfSurjective f hf\n  trans LinearMap.range (f.dual_map.comp f'.symm.dual_map.to_linear_map)\n  \u00b7 rw [LinearMap.range_comp_of_range_eq_top]\n    apply LinearEquiv.range\n  \u00b7 apply congr_arg\n    ext (\u03c6 x)\n    simp only [LinearMap.coe_comp, LinearEquiv.coe_toLinearMap, LinearMap.dualMap_apply,\n      LinearEquiv.dualMap_apply, mkq_apply, f', LinearMap.quotKerEquivOfSurjective,\n      LinearEquiv.trans_symm, LinearEquiv.trans_apply, LinearEquiv.ofTop_symm_apply,\n      LinearMap.quotKerEquivRange_symm_apply_image, mkq_apply]\n#align linear_map.range_dual_map_eq_dual_annihilator_ker_of_surjective LinearMap.range_dualMap_eq_dualAnnihilator_ker_of_surjective\n\n-- Note, this can be specialized to the case where `R` is an injective `R`-module, or when\n-- `f.coker` is a projective `R`-module.\ntheorem range_dualMap_eq_dualAnnihilator_ker_of_subtype_range_surjective (f : M \u2192\u2097[R] M')\n    (hf : Function.Surjective f.range.Subtype.dualMap) : f.dualMap.range = f.ker.dualAnnihilator :=\n  by\n  have rr_surj : Function.Surjective f.range_restrict := by\n    rw [\u2190 LinearMap.range_eq_top, LinearMap.range_rangeRestrict]\n  have := range_dual_map_eq_dual_annihilator_ker_of_surjective f.range_restrict rr_surj\n  convert this using 1\n  \u00b7 change ((Submodule.subtype f.range).comp f.range_restrict).dualMap.range = _\n    rw [\u2190 LinearMap.dualMap_comp_dualMap, LinearMap.range_comp_of_range_eq_top]\n    rwa [LinearMap.range_eq_top]\n  \u00b7 apply congr_arg\n    exact (LinearMap.ker_rangeRestrict f).symm\n#align linear_map.range_dual_map_eq_dual_annihilator_ker_of_subtype_range_surjective LinearMap.range_dualMap_eq_dualAnnihilator_ker_of_subtype_range_surjective\n\nend LinearMap\n\nend CommRing\n\nsection VectorSpace\n\nvariable {K : Type _} [Field K] {V\u2081 : Type _} {V\u2082 : Type _}\n\nvariable [AddCommGroup V\u2081] [Module K V\u2081] [AddCommGroup V\u2082] [Module K V\u2082]\n\nnamespace LinearMap\n\ntheorem dualPairing_nondegenerate : (dualPairing K V\u2081).Nondegenerate :=\n  \u27e8separatingLeft_iff_ker_eq_bot.mpr ker_id, fun x => (forall_dual_apply_eq_zero_iff K x).mp\u27e9\n#align linear_map.dual_pairing_nondegenerate LinearMap.dualPairing_nondegenerate\n\ntheorem dualMap_surjective_of_injective {f : V\u2081 \u2192\u2097[K] V\u2082} (hf : Function.Injective f) :\n    Function.Surjective f.dualMap := by\n  intro \u03c6\n  let f' := LinearEquiv.ofInjective f hf\n  use Subspace.dualLift (range f) (f'.symm.dual_map \u03c6)\n  ext x\n  rw [LinearMap.dualMap_apply, Subspace.dualLift_of_mem (mem_range_self f x),\n    LinearEquiv.dualMap_apply]\n  congr 1\n  exact LinearEquiv.symm_apply_apply f' x\n#align linear_map.dual_map_surjective_of_injective LinearMap.dualMap_surjective_of_injective\n\ntheorem range_dualMap_eq_dualAnnihilator_ker (f : V\u2081 \u2192\u2097[K] V\u2082) :\n    f.dualMap.range = f.ker.dualAnnihilator :=\n  range_dualMap_eq_dualAnnihilator_ker_of_subtype_range_surjective f <|\n    dualMap_surjective_of_injective (range f).injective_subtype\n#align linear_map.range_dual_map_eq_dual_annihilator_ker LinearMap.range_dualMap_eq_dualAnnihilator_ker\n\n/-- For vector spaces, `f.dual_map` is surjective if and only if `f` is injective -/\n@[simp]\ntheorem dualMap_surjective_iff {f : V\u2081 \u2192\u2097[K] V\u2082} :\n    Function.Surjective f.dualMap \u2194 Function.Injective f := by\n  rw [\u2190 LinearMap.range_eq_top, range_dual_map_eq_dual_annihilator_ker, \u2190\n    Submodule.dualAnnihilator_bot, Subspace.dualAnnihilator_inj, LinearMap.ker_eq_bot]\n#align linear_map.dual_map_surjective_iff LinearMap.dualMap_surjective_iff\n\nend LinearMap\n\nnamespace Subspace\n\nopen Submodule\n\ntheorem dualPairing_eq (W : Subspace K V\u2081) : W.dualPairing = W.quotAnnihilatorEquiv.toLinearMap :=\n  by\n  ext\n  rfl\n#align subspace.dual_pairing_eq Subspace.dualPairing_eq\n\ntheorem dualPairing_nondegenerate (W : Subspace K V\u2081) : W.dualPairing.Nondegenerate :=\n  by\n  constructor\n  \u00b7 rw [LinearMap.separatingLeft_iff_ker_eq_bot, dual_pairing_eq]\n    apply LinearEquiv.ker\n  \u00b7 intro x h\n    rw [\u2190 forall_dual_apply_eq_zero_iff K x]\n    intro \u03c6\n    simpa only [Submodule.dualPairing_apply, dual_lift_of_subtype] using\n      h (Submodule.Quotient.mk (W.dual_lift \u03c6))\n#align subspace.dual_pairing_nondegenerate Subspace.dualPairing_nondegenerate\n\ntheorem dualCopairing_nondegenerate (W : Subspace K V\u2081) : W.dualCopairing.Nondegenerate :=\n  by\n  constructor\n  \u00b7 rw [LinearMap.separatingLeft_iff_ker_eq_bot, dual_copairing_eq]\n    apply LinearEquiv.ker\n  \u00b7 rintro \u27e8x\u27e9\n    simp only [quotient.quot_mk_eq_mk, dual_copairing_apply, quotient.mk_eq_zero]\n    rw [\u2190 forall_mem_dual_annihilator_apply_eq_zero_iff, SetLike.forall]\n    exact id\n#align subspace.dual_copairing_nondegenerate Subspace.dualCopairing_nondegenerate\n\n-- Argument from https://math.stackexchange.com/a/2423263/172988\ntheorem dualAnnihilator_inf_eq (W W' : Subspace K V\u2081) :\n    (W \u2293 W').dualAnnihilator = W.dualAnnihilator \u2294 W'.dualAnnihilator :=\n  by\n  refine' le_antisymm _ (sup_dual_annihilator_le_inf W W')\n  let F : V\u2081 \u2192\u2097[K] (V\u2081 \u29f8 W) \u00d7 V\u2081 \u29f8 W' := (Submodule.mkQ W).Prod (Submodule.mkQ W')\n  have : F.ker = W \u2293 W' := by simp only [LinearMap.ker_prod, ker_mkq]\n  rw [\u2190 this, \u2190 LinearMap.range_dualMap_eq_dualAnnihilator_ker]\n  intro \u03c6\n  rw [LinearMap.mem_range]\n  rintro \u27e8x, rfl\u27e9\n  rw [Submodule.mem_sup]\n  obtain \u27e8\u27e8a, b\u27e9, rfl\u27e9 := (dual_prod_dual_equiv_dual K (V\u2081 \u29f8 W) (V\u2081 \u29f8 W')).Surjective x\n  obtain \u27e8a', rfl\u27e9 := (dual_quot_equiv_dual_annihilator W).symm.Surjective a\n  obtain \u27e8b', rfl\u27e9 := (dual_quot_equiv_dual_annihilator W').symm.Surjective b\n  use a', a'.property, b', b'.property\n  rfl\n#align subspace.dual_annihilator_inf_eq Subspace.dualAnnihilator_inf_eq\n\n-- This is also true if `V\u2081` is finite dimensional since one can restrict `\u03b9` to some subtype\n-- for which the infi and supr are the same.\n--\n-- The obstruction to the `dual_annihilator_inf_eq` argument carrying through is that we need\n-- for `module.dual R (\u03a0 (i : \u03b9), V \u29f8 W i) \u2243\u2097[K] \u03a0 (i : \u03b9), module.dual R (V \u29f8 W i)`, which is not\n-- true for infinite `\u03b9`. One would need to add additional hypothesis on `W` (for example, it might\n-- be true when the family is inf-closed).\ntheorem dualAnnihilator_inf\u1d62_eq {\u03b9 : Type _} [Finite \u03b9] (W : \u03b9 \u2192 Subspace K V\u2081) :\n    (\u2a05 i : \u03b9, W i).dualAnnihilator = \u2a06 i : \u03b9, (W i).dualAnnihilator :=\n  by\n  revert \u03b9\n  refine' Finite.induction_empty_option _ _ _\n  \u00b7 intro \u03b1 \u03b2 h hyp W\n    rw [\u2190 h.infi_comp, hyp (W \u2218 h), \u2190 h.supr_comp]\n  \u00b7 intro W\n    rw [sup\u1d62_of_empty', inf\u1d62_of_empty', inf\u209b_empty, sup\u209b_empty, dual_annihilator_top]\n  \u00b7 intro \u03b1 _ h W\n    rw [inf\u1d62_option, sup\u1d62_option, dual_annihilator_inf_eq, h]\n#align subspace.dual_annihilator_infi_eq Subspace.dualAnnihilator_inf\u1d62_eq\n\n/-- For vector spaces, dual annihilators carry direct sum decompositions\nto direct sum decompositions. -/\ntheorem isCompl_dualAnnihilator {W W' : Subspace K V\u2081} (h : IsCompl W W') :\n    IsCompl W.dualAnnihilator W'.dualAnnihilator :=\n  by\n  rw [isCompl_iff, disjoint_iff, codisjoint_iff] at h\u22a2\n  rw [\u2190 dual_annihilator_inf_eq, \u2190 dual_annihilator_sup_eq, h.1, h.2, dual_annihilator_top,\n    dual_annihilator_bot]\n  exact \u27e8rfl, rfl\u27e9\n#align subspace.is_compl_dual_annihilator Subspace.isCompl_dualAnnihilator\n\n/-- For finite-dimensional vector spaces, one can distribute duals over quotients by identifying\n`W.dual_lift.range` with `W`. Note that this depends on a choice of splitting of `V\u2081`. -/\ndef dualQuotDistrib [FiniteDimensional K V\u2081] (W : Subspace K V\u2081) :\n    Module.Dual K (V\u2081 \u29f8 W) \u2243\u2097[K] Module.Dual K V\u2081 \u29f8 W.dualLift.range :=\n  W.dualQuotEquivDualAnnihilator.trans W.quotDualEquivAnnihilator.symm\n#align subspace.dual_quot_distrib Subspace.dualQuotDistrib\n\nend Subspace\n\nsection FiniteDimensional\n\nopen FiniteDimensional LinearMap\n\nvariable [FiniteDimensional K V\u2082]\n\nnamespace LinearMap\n\n-- TODO(kmill) remove finite_dimensional if possible\n-- see https://github.com/leanprover-community/mathlib/pull/17521#discussion_r1083242551\n@[simp]\ntheorem finrank_range_dualMap_eq_finrank_range (f : V\u2081 \u2192\u2097[K] V\u2082) :\n    finrank K f.dualMap.range = finrank K f.range :=\n  by\n  have := Submodule.finrank_quotient_add_finrank f.range\n  rw [(Subspace.quotEquivAnnihilator f.range).finrank_eq, \u2190\n    ker_dual_map_eq_dual_annihilator_range] at this\n  conv_rhs at this => rw [\u2190 Subspace.dual_finrank_eq]\n  refine' add_left_injective (finrank K f.dual_map.ker) _\n  change _ + _ = _ + _\n  rw [finrank_range_add_finrank_ker f.dual_map, add_comm, this]\n#align linear_map.finrank_range_dual_map_eq_finrank_range LinearMap.finrank_range_dualMap_eq_finrank_range\n\n/-- `f.dual_map` is injective if and only if `f` is surjective -/\n@[simp]\ntheorem dualMap_injective_iff {f : V\u2081 \u2192\u2097[K] V\u2082} :\n    Function.Injective f.dualMap \u2194 Function.Surjective f :=\n  by\n  refine' \u27e8_, fun h => dual_map_injective_of_surjective h\u27e9\n  rw [\u2190 range_eq_top, \u2190 ker_eq_bot]\n  intro h\n  apply FiniteDimensional.eq_top_of_finrank_eq\n  rw [\u2190 finrank_eq_zero] at h\n  rw [\u2190 add_zero (FiniteDimensional.finrank K f.range), \u2190 h, \u2190\n    LinearMap.finrank_range_dualMap_eq_finrank_range, LinearMap.finrank_range_add_finrank_ker,\n    Subspace.dual_finrank_eq]\n#align linear_map.dual_map_injective_iff LinearMap.dualMap_injective_iff\n\n/-- `f.dual_map` is bijective if and only if `f` is -/\n@[simp]\ntheorem dualMap_bijective_iff {f : V\u2081 \u2192\u2097[K] V\u2082} :\n    Function.Bijective f.dualMap \u2194 Function.Bijective f := by\n  simp_rw [Function.Bijective, dual_map_surjective_iff, dual_map_injective_iff, and_comm]\n#align linear_map.dual_map_bijective_iff LinearMap.dualMap_bijective_iff\n\nend LinearMap\n\nend FiniteDimensional\n\nend VectorSpace\n\nnamespace TensorProduct\n\nvariable (R : Type _) (M : Type _) (N : Type _)\n\nvariable {\u03b9 \u03ba : Type _}\n\nvariable [DecidableEq \u03b9] [DecidableEq \u03ba]\n\nvariable [Fintype \u03b9] [Fintype \u03ba]\n\nopen BigOperators\n\nopen TensorProduct\n\nattribute [local ext] TensorProduct.ext\n\nopen TensorProduct\n\nopen LinearMap\n\nsection\n\nvariable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N]\n\nvariable [Module R M] [Module R N]\n\n/-- The canonical linear map from `dual M \u2297 dual N` to `dual (M \u2297 N)`,\nsending `f \u2297 g` to the composition of `tensor_product.map f g` with\nthe natural isomorphism `R \u2297 R \u2243 R`.\n-/\ndef dualDistrib : Dual R M \u2297[R] Dual R N \u2192\u2097[R] Dual R (M \u2297[R] N) :=\n  compRight \u2191(TensorProduct.lid R R) \u2218\u2097 homTensorHomMap R M N R R\n#align tensor_product.dual_distrib TensorProduct.dualDistrib\n\nvariable {R M N}\n\n@[simp]\ntheorem dualDistrib_apply (f : Dual R M) (g : Dual R N) (m : M) (n : N) :\n    dualDistrib R M N (f \u2297\u209c g) (m \u2297\u209c n) = f m * g n :=\n  rfl\n#align tensor_product.dual_distrib_apply TensorProduct.dualDistrib_apply\n\nend\n\nvariable {R M N}\n\nvariable [CommRing R] [AddCommGroup M] [AddCommGroup N]\n\nvariable [Module R M] [Module R N]\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\n/-- An inverse to `dual_tensor_dual_map` given bases.\n-/\nnoncomputable def dualDistribInvOfBasis (b : Basis \u03b9 R M) (c : Basis \u03ba R N) :\n    Dual R (M \u2297[R] N) \u2192\u2097[R] Dual R M \u2297[R] Dual R N :=\n  \u2211 (i) (j),\n    (ringLmapEquivSelf R \u2115 _).symm (b.dualBasis i \u2297\u209c c.dualBasis j) \u2218\u2097\n      apply\u2097 (c j) \u2218\u2097 apply\u2097 (b i) \u2218\u2097 lcurry R M N R\n#align tensor_product.dual_distrib_inv_of_basis TensorProduct.dualDistribInvOfBasis\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/\n@[simp]\ntheorem dualDistribInvOfBasis_apply (b : Basis \u03b9 R M) (c : Basis \u03ba R N) (f : Dual R (M \u2297[R] N)) :\n    dualDistribInvOfBasis b c f = \u2211 (i) (j), f (b i \u2297\u209c c j) \u2022 b.dualBasis i \u2297\u209c c.dualBasis j := by\n  simp [dual_distrib_inv_of_basis]\n#align tensor_product.dual_distrib_inv_of_basis_apply TensorProduct.dualDistribInvOfBasis_apply\n\n/-- A linear equivalence between `dual M \u2297 dual N` and `dual (M \u2297 N)` given bases for `M` and `N`.\nIt sends `f \u2297 g` to the composition of `tensor_product.map f g` with the natural\nisomorphism `R \u2297 R \u2243 R`.\n-/\n@[simps]\nnoncomputable def dualDistribEquivOfBasis (b : Basis \u03b9 R M) (c : Basis \u03ba R N) :\n    Dual R M \u2297[R] Dual R N \u2243\u2097[R] Dual R (M \u2297[R] N) :=\n  by\n  refine' LinearEquiv.ofLinear (dual_distrib R M N) (dual_distrib_inv_of_basis b c) _ _\n  \u00b7 ext (f m n)\n    have h : \u2200 r s : R, r \u2022 s = s \u2022 r := IsCommutative.comm\n    simp only [compr\u2082_apply, mk_apply, comp_apply, id_apply, dual_distrib_inv_of_basis_apply,\n      LinearMap.map_sum, map_smul, sum_apply, smul_apply, dual_distrib_apply, h (f _) _, \u2190\n      f.map_smul, \u2190 f.map_sum, \u2190 smul_tmul_smul, \u2190 tmul_sum, \u2190 sum_tmul, Basis.coe_dualBasis,\n      Basis.coord_apply, Basis.sum_repr]\n  \u00b7 ext (f g)\n    simp only [compr\u2082_apply, mk_apply, comp_apply, id_apply, dual_distrib_inv_of_basis_apply,\n      dual_distrib_apply, \u2190 smul_tmul_smul, \u2190 tmul_sum, \u2190 sum_tmul, Basis.coe_dualBasis,\n      Basis.sum_dual_apply_smul_coord]\n#align tensor_product.dual_distrib_equiv_of_basis TensorProduct.dualDistribEquivOfBasis\n\nvariable (R M N)\n\nvariable [Module.Finite R M] [Module.Finite R N] [Module.Free R M] [Module.Free R N]\n\nvariable [Nontrivial R]\n\nopen Classical\n\n/--\nA linear equivalence between `dual M \u2297 dual N` and `dual (M \u2297 N)` when `M` and `N` are finite free\nmodules. It sends `f \u2297 g` to the composition of `tensor_product.map f g` with the natural\nisomorphism `R \u2297 R \u2243 R`.\n-/\n@[simp]\nnoncomputable def dualDistribEquiv : Dual R M \u2297[R] Dual R N \u2243\u2097[R] Dual R (M \u2297[R] N) :=\n  dualDistribEquivOfBasis (Module.Free.chooseBasis R M) (Module.Free.chooseBasis R N)\n#align tensor_product.dual_distrib_equiv TensorProduct.dualDistribEquiv\n\nend TensorProduct\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Dual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.7071481283558888}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport combinatorics.simple_graph.basic\nimport data.finset.pairwise\n\n/-!\n# Graph cliques\n\nThis file defines cliques in simple graphs. A clique is a set of vertices that are pairwise\nadjacent.\n\n## Main declarations\n\n* `simple_graph.is_clique`: Predicate for a set of vertices to be a clique.\n* `simple_graph.is_n_clique`: Predicate for a set of vertices to be a `n`-clique.\n* `simple_graph.clique_finset`: Finset of `n`-cliques of a graph.\n* `simple_graph.clique_free`: Predicate for a graph to have no `n`-cliques.\n\n## TODO\n\n* Clique numbers\n* Going back and forth between cliques and complete subgraphs or embeddings of complete graphs.\n* Do we need `clique_set`, a version of `clique_finset` for infinite graphs?\n-/\n\nopen finset fintype\n\nnamespace simple_graph\nvariables {\u03b1 : Type*} (G H : simple_graph \u03b1)\n\n/-! ### Cliques -/\n\nsection clique\nvariables {s t : set \u03b1}\n\n/-- A clique in a graph is a set of vertices that are pairwise adjacent. -/\nabbreviation is_clique (s : set \u03b1) : Prop := s.pairwise G.adj\n\nlemma is_clique_iff : G.is_clique s \u2194 s.pairwise G.adj := iff.rfl\n\ninstance [decidable_eq \u03b1] [decidable_rel G.adj] {s : finset \u03b1} : decidable (G.is_clique s) :=\ndecidable_of_iff' _ G.is_clique_iff\n\nvariables {G H}\n\nlemma is_clique.mono (h : G \u2264 H) : G.is_clique s \u2192 H.is_clique s :=\nby { simp_rw is_clique_iff, exact set.pairwise.mono' h }\n\nlemma is_clique.subset (h : t \u2286 s) : G.is_clique s \u2192 G.is_clique t :=\nby { simp_rw is_clique_iff, exact set.pairwise.mono h }\n\n@[simp] lemma is_clique_bot_iff : (\u22a5 : simple_graph \u03b1).is_clique s \u2194 (s : set \u03b1).subsingleton :=\nset.pairwise_bot_iff\n\nalias is_clique_bot_iff \u2194 simple_graph.is_clique.subsingleton _\n\nend clique\n\n/-! ### `n`-cliques -/\n\nsection n_clique\nvariables {n : \u2115} {s : finset \u03b1}\n\n/-- A `n`-clique in a graph is a set of `n` vertices which are pairwise connected. -/\nstructure is_n_clique (n : \u2115) (s : finset \u03b1) : Prop :=\n(clique : G.is_clique s)\n(card_eq : s.card = n)\n\nlemma is_n_clique_iff : G.is_n_clique n s \u2194 G.is_clique s \u2227 s.card = n :=\n\u27e8\u03bb h, \u27e8h.1, h.2\u27e9, \u03bb h, \u27e8h.1, h.2\u27e9\u27e9\n\ninstance [decidable_eq \u03b1] [decidable_rel G.adj] {n : \u2115} {s : finset \u03b1} :\n  decidable (G.is_n_clique n s) :=\ndecidable_of_iff' _ G.is_n_clique_iff\n\nvariables {G H}\n\nlemma is_n_clique.mono (h : G \u2264 H) : G.is_n_clique n s \u2192 H.is_n_clique n s :=\nby { simp_rw is_n_clique_iff, exact and.imp_left (is_clique.mono h) }\n\n@[simp] lemma is_n_clique_bot_iff : (\u22a5 : simple_graph \u03b1).is_n_clique n s \u2194 n \u2264 1 \u2227 s.card = n :=\nbegin\n  rw [is_n_clique_iff, is_clique_bot_iff],\n  refine and_congr_left _,\n  rintro rfl,\n  exact card_le_one.symm,\nend\n\nvariables [decidable_eq \u03b1] {a b c : \u03b1}\n\nlemma is_3_clique_triple_iff : G.is_n_clique 3 {a, b, c} \u2194 G.adj a b \u2227 G.adj a c \u2227 G.adj b c :=\nbegin\n  simp only [is_n_clique_iff, is_clique_iff, set.pairwise_insert_of_symmetric G.symm, coe_insert],\n  have : \u00ac 1 + 1 = 3 := by norm_num,\n  by_cases hab : a = b; by_cases hbc : b = c; by_cases hac : a = c;\n  subst_vars; simp [G.ne_of_adj, and_rotate, *],\nend\n\nlemma is_3_clique_iff :\n  G.is_n_clique 3 s \u2194 \u2203 a b c, G.adj a b \u2227 G.adj a c \u2227 G.adj b c \u2227 s = {a, b, c} :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { obtain \u27e8a, b, c, -, -, -, rfl\u27e9 := card_eq_three.1 h.card_eq,\n    refine \u27e8a, b, c, _\u27e9,\n    rw is_3_clique_triple_iff at h,\n    tauto },\n  { rintro \u27e8a, b, c, hab, hbc, hca, rfl\u27e9,\n    exact is_3_clique_triple_iff.2 \u27e8hab, hbc, hca\u27e9 }\nend\n\nend n_clique\n\n/-! ### Graphs without cliques -/\n\nsection clique_free\nvariables {m n : \u2115}\n\n/-- `G.clique_free n` means that `G` has no `n`-cliques. -/\ndef clique_free (n : \u2115) : Prop := \u2200 t, \u00ac G.is_n_clique n t\n\nvariables {G H}\n\nlemma clique_free_bot (h : 2 \u2264 n) : (\u22a5 : simple_graph \u03b1).clique_free n :=\nbegin\n  rintro t ht,\n  rw is_n_clique_bot_iff at ht,\n  linarith,\nend\n\nlemma clique_free.mono (h : m \u2264 n) : G.clique_free m \u2192 G.clique_free n :=\nbegin\n  rintro hG s hs,\n  obtain \u27e8t, hts, ht\u27e9 := s.exists_smaller_set _ (h.trans hs.card_eq.ge),\n  exact hG _ \u27e8hs.clique.subset hts, ht\u27e9,\nend\n\nlemma clique_free.anti (h : G \u2264 H) : H.clique_free n \u2192 G.clique_free n :=\nforall_imp $ \u03bb s, mt $ is_n_clique.mono h\n\nend clique_free\n\n/-! ### Set of cliques -/\n\nsection clique_set\nvariables (G) {n : \u2115} {a b c : \u03b1} {s : finset \u03b1}\n\n/-- The `n`-cliques in a graph as a set. -/\ndef clique_set (n : \u2115) : set (finset \u03b1) := {s | G.is_n_clique n s}\n\nlemma mem_clique_set_iff : s \u2208 G.clique_set n \u2194 G.is_n_clique n s := iff.rfl\n\n@[simp] lemma clique_set_eq_empty_iff : G.clique_set n = \u2205 \u2194 G.clique_free n :=\nby simp_rw [clique_free, set.eq_empty_iff_forall_not_mem, mem_clique_set_iff]\n\nalias clique_set_eq_empty_iff \u2194 _ simple_graph.clique_free.clique_set\n\nattribute [protected] clique_free.clique_set\n\nvariables {G H}\n\n@[mono] lemma clique_set_mono (h : G \u2264 H) : G.clique_set n \u2286 H.clique_set n :=\n\u03bb _, is_n_clique.mono h\n\nlemma clique_set_mono' (h : G \u2264 H) : G.clique_set \u2264 H.clique_set := \u03bb _, clique_set_mono h\n\nend clique_set\n\n/-! ### Finset of cliques -/\n\nsection clique_finset\nvariables (G) [fintype \u03b1] [decidable_eq \u03b1] [decidable_rel G.adj] {n : \u2115} {a b c : \u03b1} {s : finset \u03b1}\n\n/-- The `n`-cliques in a graph as a finset. -/\ndef clique_finset (n : \u2115) : finset (finset \u03b1) := univ.filter $ G.is_n_clique n\n\nlemma mem_clique_finset_iff : s \u2208 G.clique_finset n \u2194 G.is_n_clique n s :=\nmem_filter.trans $ and_iff_right $ mem_univ _\n\n@[simp] lemma coe_clique_finset (n : \u2115) : (G.clique_finset n : set (finset \u03b1)) = G.clique_set n :=\nset.ext $ \u03bb _, mem_clique_finset_iff _\n\n@[simp] lemma clique_finset_eq_empty_iff : G.clique_finset n = \u2205 \u2194 G.clique_free n :=\nby simp_rw [clique_free, eq_empty_iff_forall_not_mem, mem_clique_finset_iff]\n\nalias clique_finset_eq_empty_iff \u2194 _ simple_graph.clique_free.clique_finset\n\nattribute [protected] clique_free.clique_finset\n\nvariables {G} [decidable_rel H.adj]\n\n@[mono] lemma clique_finset_mono (h : G \u2264 H) : G.clique_finset n \u2286 H.clique_finset n :=\nmonotone_filter_right _ $ \u03bb _, is_n_clique.mono h\n\nend clique_finset\nend simple_graph\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/combinatorics/simple_graph/clique.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7071481240494535}}
{"text": "import data.real.basic data.complex.exponential topology.basic data.set.intervals analysis.exponential order.filter.basic\n\nconstants (\u03be : \u211d)\nopen real\n\nnoncomputable def step_fun : \u211d \u2192 \u211d := \u03bb x, if x \u2264 \u03be then 1 else 0\n\n-- * Example 6: The function r(x) = 1 (when x \u2264 \u03be) and 0  (when x > \u03be) is discontinuous over [0,2], assuming \u03be=1.\n\nlemma discont_at_step : \u00ac (continuous_at step_fun \u03be) := begin\nunfold continuous_at,\n-- our goal:\n-- \u22a2 \u00acfilter.tendsto step_fun (nhds \u03be) (nhds (step_fun \u03be))\nrw metric.tendsto_nhds_nhds,\n-- our goal:\n-- \u22a2 \u00ac\u2200 (\u03b5 : \u211d),\n--      \u03b5 > 0 \u2192 (\u2203 (\u03b4 : \u211d) (H : \u03b4 > 0),\n--                \u2200 {x : \u211d}, dist x \u03be < \u03b4 \u2192 dist (step_fun x)\n--                                                 (step_fun \u03be) < \u03b5)\nend\n", "meta": {"author": "holtzermann17", "repo": "lean_experiments", "sha": "3ebb7048c9ca766814c10404ba217b50544d20b2", "save_path": "github-repos/lean/holtzermann17-lean_experiments", "path": "github-repos/lean/holtzermann17-lean_experiments/lean_experiments-3ebb7048c9ca766814c10404ba217b50544d20b2/src/paper_example_6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096158798115, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7070932551326315}}
{"text": "variable (t1 t2 t3 t4 : Nat)\nvariable (pf12 : t1 = t2) (pf23 : t2 = t3) (pf34 : t3 = t4)\n\ntheorem foo : t1 = t4 :=\n  calc\n    t1 = t2 := pf12\n     _ = t3 := pf23\n     _ = t4 := pf34\n\nvariable (t5 : Nat)\nvariable (pf23' : t2 < t3) (pf45' : t4 < t5)\n\ninstance [LT \u03b1] : Trans (\u03b1 := \u03b1) (\u00b7 < \u00b7) (\u00b7 < \u00b7) (\u00b7 < \u00b7) where\n  trans := sorry\n\ntheorem foo' : t1 < t5 :=\n  let p := calc\n   t1 = t2 := pf12\n    _ < t3 := pf23'\n    _ = t4 := pf34\n    _ < t5 := pf45'\n  -- dedent terminates the block\n  p\n", "meta": {"author": "Kha", "repo": "lean4-nightly", "sha": "b4c92de57090e6c47b29d3575df53d86fce52752", "save_path": "github-repos/lean/Kha-lean4-nightly", "path": "github-repos/lean/Kha-lean4-nightly/lean4-nightly-b4c92de57090e6c47b29d3575df53d86fce52752/tests/lean/run/calc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798115, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.707093245516738}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.algebra.subalgebra\nimport topology.algebra.module.basic\n\n/-!\n# Topological (sub)algebras\n\nA topological algebra over a topological semiring `R` is a topological ring with a compatible\ncontinuous scalar multiplication by elements of `R`. We reuse typeclass `has_continuous_smul` for\ntopological algebras.\n\n## Results\n\nThis is just a minimal stub for now!\n\nThe topological closure of a subalgebra is still a subalgebra,\nwhich as an algebra is a topological algebra.\n-/\n\nopen classical set topological_space algebra\nopen_locale classical\n\nuniverses u v w\n\nsection topological_algebra\nvariables (R : Type*) [topological_space R] [comm_semiring R]\nvariables (A : Type u) [topological_space A]\nvariables [semiring A]\n\nlemma continuous_algebra_map_iff_smul [algebra R A] [topological_ring A] :\n  continuous (algebra_map R A) \u2194 continuous (\u03bb p : R \u00d7 A, p.1 \u2022 p.2) :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { simp only [algebra.smul_def], exact (h.comp continuous_fst).mul continuous_snd },\n  { rw algebra_map_eq_smul_one', exact h.comp (continuous_id.prod_mk continuous_const) }\nend\n\n@[continuity]\nlemma continuous_algebra_map [algebra R A] [topological_ring A] [has_continuous_smul R A] :\n  continuous (algebra_map R A) :=\n(continuous_algebra_map_iff_smul R A).2 continuous_smul\n\nlemma has_continuous_smul_of_algebra_map [algebra R A] [topological_ring A]\n  (h : continuous (algebra_map R A)) :\n  has_continuous_smul R A :=\n\u27e8(continuous_algebra_map_iff_smul R A).1 h\u27e9\n\nend topological_algebra\n\nsection topological_algebra\nvariables {R : Type*} [comm_semiring R]\nvariables {A : Type u} [topological_space A]\nvariables [semiring A]\nvariables [algebra R A] [topological_ring A]\n\n/-- The closure of a subalgebra in a topological algebra as a subalgebra. -/\ndef subalgebra.topological_closure (s : subalgebra R A) : subalgebra R A :=\n{ carrier := closure (s : set A),\n  algebra_map_mem' := \u03bb r, s.to_subsemiring.subring_topological_closure (s.algebra_map_mem r),\n  .. s.to_subsemiring.topological_closure }\n\n@[simp] lemma subalgebra.topological_closure_coe (s : subalgebra R A) :\n  (s.topological_closure : set A) = closure (s : set A) :=\nrfl\n\ninstance subalgebra.topological_closure_topological_ring (s : subalgebra R A) :\n  topological_ring (s.topological_closure) :=\ns.to_subsemiring.topological_closure_topological_ring\n\ninstance subalgebra.topological_closure_topological_algebra\n  [topological_space R] [has_continuous_smul R A] (s : subalgebra R A) :\n  has_continuous_smul R (s.topological_closure) :=\ns.to_submodule.topological_closure_has_continuous_smul\n\nlemma subalgebra.subalgebra_topological_closure (s : subalgebra R A) :\n  s \u2264 s.topological_closure :=\nsubset_closure\n\nlemma subalgebra.is_closed_topological_closure (s : subalgebra R A) :\n  is_closed (s.topological_closure : set A) :=\nby convert is_closed_closure\n\nlemma subalgebra.topological_closure_minimal\n  (s : subalgebra R A) {t : subalgebra R A} (h : s \u2264 t) (ht : is_closed (t : set A)) :\n  s.topological_closure \u2264 t :=\nclosure_minimal h ht\n\n/--\nThis is really a statement about topological algebra isomorphisms,\nbut we don't have those, so we use the clunky approach of talking about\nan algebra homomorphism, and a separate homeomorphism,\nalong with a witness that as functions they are the same.\n-/\nlemma subalgebra.topological_closure_comap'_homeomorph\n  (s : subalgebra R A)\n  {B : Type*} [topological_space B] [ring B] [topological_ring B] [algebra R B]\n  (f : B \u2192\u2090[R] A) (f' : B \u2243\u209c A) (w : (f : B \u2192 A) = f') :\n  s.topological_closure.comap' f = (s.comap' f).topological_closure :=\nbegin\n  apply set_like.ext',\n  simp only [subalgebra.topological_closure_coe],\n  simp only [subalgebra.coe_comap, subsemiring.coe_comap, alg_hom.coe_to_ring_hom],\n  rw [w],\n  exact f'.preimage_closure _,\nend\n\nend topological_algebra\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/topology/algebra/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7070191542831676}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nWe define finite cyclic groups, in multiplicative notation.\nThe elements of `C\u2099` are denoted by `r i` for `i : zmod n`.\nWe prove that an element `g \u2208 G` with `g\u207f = 1` gives rise to\na homomorphism `C\u2099 \u2192 G`.  We also do the case n = \u221e separately.\n-/\n\nimport data.fintype.basic algebra.power_mod\n\nnamespace group_theory\n\nvariables (n : \u2115) [fact (n > 0)]\n\n@[derive decidable_eq]\ninductive cyclic\n| r : (zmod n) \u2192 cyclic\n\nnamespace cyclic\n\nvariable {n}\n\ndef log : cyclic n \u2192 zmod n := \u03bb \u27e8i\u27e9, i\n\ndef log_equiv : (cyclic n) \u2243 (zmod n) :=\n{ to_fun := log,\n  inv_fun := r,\n  left_inv := \u03bb \u27e8i\u27e9, rfl,  right_inv := \u03bb i, rfl }\n\ninstance : fintype (cyclic n) := fintype.of_equiv (zmod n) log_equiv.symm\n\nlemma card : fintype.card (cyclic n) = n :=\nby { rw [fintype.card_congr log_equiv], exact zmod.card n }\n\ndef one : cyclic n := r 0\n\ndef inv : \u2200 (g : cyclic n)  , cyclic n | (r i) := r (-i)\n\ndef mul : \u2200 (g h : cyclic n), cyclic n | (r i) (r j) := r (i + j)\n\ninstance : has_one (cyclic n) := \u27e8r 0\u27e9\nlemma one_eq : (1 : cyclic n) = r 0 := rfl\n\ninstance : has_inv (cyclic n) := \u27e8cyclic.inv\u27e9\nlemma r_inv (i : zmod n) : (r i)\u207b\u00b9 = r (- i) := rfl\n\ninstance : has_mul (cyclic n) := \u27e8cyclic.mul\u27e9\nlemma rr_mul (i j : zmod n) : (r i) * (r j) = r (i + j) := rfl\n\ninstance : group (cyclic n) :=\n{ one := 1,\n  mul := (*),\n  inv := has_inv.inv,\n  one_mul := \u03bb \u27e8i\u27e9, by rw [one_eq, rr_mul, zero_add],\n  mul_one := \u03bb \u27e8i\u27e9, by rw [one_eq, rr_mul, add_zero],\n  mul_left_inv := \u03bb \u27e8i\u27e9, by rw [r_inv, rr_mul, neg_add_self, one_eq],\n  mul_assoc := \u03bb \u27e8i\u27e9 \u27e8j\u27e9 \u27e8k\u27e9, by simp only [rr_mul, add_assoc] }\n\nsection hom_from_gens\n\nvariables {M : Type*} [monoid M] {g : M} (hg : g ^ (n : \u2115) = 1)\ninclude g hg\n\ndef hom_from_gens\u2080 : (cyclic n) \u2192 M\n| (r i) := g ^ i\n\ndef hom_from_gens : (cyclic n) \u2192* M := {\n   to_fun := hom_from_gens\u2080 hg,\n   map_one' := begin \n    change hom_from_gens\u2080 hg (r 0) = 1, rw[hom_from_gens\u2080,pow_mod_zero]\n   end,\n   map_mul' := \u03bb \u27e8i\u27e9 \u27e8j\u27e9, pow_mod_add hg i j,\n }\n\nlemma hom_from_gens_r  (i : zmod n) : \n  hom_from_gens hg (r i) = g ^ i := rfl\n\nend hom_from_gens\nend cyclic\n\n@[derive decidable_eq]\ninductive infinite_cyclic\n| r : \u2124 \u2192 infinite_cyclic\n\nnamespace infinite_cyclic\n\ndef log : infinite_cyclic \u2192 \u2124 := \u03bb \u27e8i\u27e9, i\n\ndef log_equiv : infinite_cyclic \u2243 \u2124 :=\n{ to_fun := log,\n  inv_fun := r,\n  left_inv := \u03bb \u27e8i\u27e9, rfl,  right_inv := \u03bb i, rfl }\n\ndef one : infinite_cyclic := r 0\n\ndef inv : \u2200 (g : infinite_cyclic)  , infinite_cyclic | (r i) := r (-i)\n\ndef mul : \u2200 (g h : infinite_cyclic), infinite_cyclic | (r i) (r j) := r (i + j)\n\ninstance : has_one (infinite_cyclic) := \u27e8r 0\u27e9\nlemma one_eq : (1 : infinite_cyclic) = r 0 := rfl\n\ninstance : has_inv (infinite_cyclic) := \u27e8infinite_cyclic.inv\u27e9\nlemma r_inv (i : \u2124) : (r i)\u207b\u00b9 = r (- i) := rfl\n\ninstance : has_mul (infinite_cyclic) := \u27e8infinite_cyclic.mul\u27e9\nlemma rr_mul (i j : \u2124) : (r i) * (r j) = r (i + j) := rfl\n\ninstance : group (infinite_cyclic) :=\n{ one := 1,\n  mul := (*),\n  inv := has_inv.inv,\n  one_mul := \u03bb \u27e8i\u27e9, by rw [one_eq, rr_mul, zero_add],\n  mul_one := \u03bb \u27e8i\u27e9, by rw [one_eq, rr_mul, add_zero],\n  mul_left_inv := \u03bb \u27e8i\u27e9, by rw [r_inv, rr_mul, neg_add_self, one_eq],\n  mul_assoc := \u03bb \u27e8i\u27e9 \u27e8j\u27e9 \u27e8k\u27e9, by simp only [rr_mul, add_assoc] }\n\ndef hom_from_gens\u2080 {G : Type*} [group G] (g : G) : infinite_cyclic \u2192 G\n| (r i) := g ^ i\n\ndef hom_from_gens {G : Type*} [group G] (g : G) : infinite_cyclic \u2192* G := {\n  to_fun := hom_from_gens\u2080 g,\n  map_one' := by { rw[one_eq], exact zpow_zero g, },\n  map_mul' := \u03bb \u27e8i\u27e9 \u27e8j\u27e9, by { rw[rr_mul], apply zpow_add g, } \n}\n\ndef monoid_hom_from_gens\u2080 {M : Type*} [monoid M] (g : units M) : infinite_cyclic \u2192 M\n| (r i) := ((g ^ i) : units M)\n\ndef monoid_hom_from_gens {M : Type*} [monoid M] (g : units M) : infinite_cyclic \u2192* M := {\n  to_fun := monoid_hom_from_gens\u2080 g,\n  map_one' := by { rw[one_eq], refl, },\n  map_mul' := \u03bb i j, by { rcases i, rcases j,\n   change\n    ((g ^ (i + j) : units M) : M) = (g ^ i : units M) * (g ^ j : units M) ,\n   rw [\u2190 units.coe_mul, zpow_add] \n  }\n}\n\nend infinite_cyclic\n\nend group_theory\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/group_theory/cyclic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7070191495142348}}
{"text": "/-\nCopyright (c) 2015, 2017 Ender Doe. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ender Doe, Kevin Buzzard\n-/\n\nimport data.real.irrational\n\nlocal notation `|` x `|` := abs x\nopen_locale classical\n\n/--\n  The thomae's function on reals also known as the \"Popcorn\" function.\n-/\nnoncomputable def thomaes_function (r : \u211d) : \u211d :=\nif h : \u2203 (q : \u211a), (q : \u211d) = r then (classical.some h).denom\u207b\u00b9 else 0\n\ntheorem thomaes_at_irrational_eq_zero {x : \u211d} (h: irrational x) :\n  thomaes_function x = 0 :=\ndif_neg $ h\n\n/-- The thomae function, restricted to the rationals and taking values in the rationals. -/\ndef thomae_rat (q : \u211a) : \u211a := q.denom\u207b\u00b9\n\n@[norm_cast]\nlemma coe_thomae_rat (q : \u211a) : thomaes_function q = thomae_rat q :=\nbegin\n  unfold thomaes_function,\n  rw dif_pos (\u27e8q, rfl\u27e9 : \u2203 (q_1 : \u211a), (q_1 : \u211d) = \u2191q),\n  { generalize_proofs h,\n    unfold thomae_rat,\n    norm_num,\n    congr',\n    exact_mod_cast classical.some_spec h },\nend\n\n@[norm_cast] lemma coe_thomae_rat' (q : \u211a) : (thomae_rat q : \u211d) = thomaes_function q :=\n(coe_thomae_rat q).symm\n\n@[simp]\nlemma thomae_rat_num (q : \u211a) : (thomae_rat q).num = 1 :=\n  by simp [thomae_rat, rat.inv_coe_nat_num q.pos ]\n\n@[simp]\nlemma thomae_rat_denom (q : \u211a) : (thomae_rat q).denom = q.denom :=\n  by simp [thomae_rat, rat.inv_coe_nat_denom q.pos]\n\ntheorem thomae_rat_pos (q : \u211a) : 0 < (thomae_rat q) := begin\n  apply rat.num_pos_iff_pos.mp,\n  rw thomae_rat_num,\n  exact zero_lt_one,\nend\n\n\n-- add to rat library?\ntheorem rat.add_int_denom (z: \u2124) (q : \u211a) : (q + z).denom = q.denom :=\nbegin\n  rw rat.add_num_denom,\n  simp,\n  rw rat.mk_eq_div,\n  -- I copied this trick from above\n  suffices :(((((q.num + \u2191(q.denom) * z) : \u2124) : \u211a) / ((q.denom) : \u2124)).denom : \u2124) = q.denom,\n    exact_mod_cast this,\n  apply rat.denom_div_eq_of_coprime,\n  exact_mod_cast q.pos,\n  exact int.coprime_iff_nat_coprime.mp\n    (is_coprime.add_mul_left_left\n      (int.coprime_iff_nat_coprime.mpr (by exact_mod_cast q.cop)) _),\nend\n\n@[simp]\ntheorem thomaes_is_perodic (n : \u2124) (x  : \u211d) : thomaes_function (x + n) = thomaes_function x  :=\nbegin\n  by_cases (irrational x),\n  rw [\n    thomaes_at_irrational_eq_zero (by exact_mod_cast irrational.add_rat n h),\n    thomaes_at_irrational_eq_zero h\n  ],\n  unfold irrational at h,\n  push_neg at h,\n  cases h with q q_eq_x,\n  subst q_eq_x,\n  norm_cast,\n  apply rat.eq_iff_mul_eq_mul.mpr,\n  simp [thomae_rat_num, thomae_rat_denom],\n  symmetry,\n  exact rat.add_int_denom _ _,\nend\n\n\ntheorem irrational_ne_rat {x: \u211d} (q : \u211a) (h: irrational x) : x \u2260 q :=\n\u03bb h2, h \u27e8q, h2.symm\u27e9\n\nlemma \u03b4\u1d62_pos {x : \u211d} (i : \u2115) (h : irrational x)\n: 0 < min (|x - \u230ax * i\u230b / (i :\u211d)|)  (|x - (\u230ax * i\u230b + 1) / (i :\u211d)|) :=\nbegin\n  simp only [abs_pos, gt_iff_lt, lt_min_iff],\n  split,\n  { suffices : x \u2260 ((\u230ax * \u2191i\u230b / i) : \u211a),\n    exact_mod_cast sub_ne_zero.mpr this,\n    exact irrational_ne_rat _ h },\n  { suffices : x \u2260 (((\u230ax * \u2191i\u230b + 1) / i) : \u211a),\n    exact_mod_cast sub_ne_zero.mpr this,\n    exact irrational_ne_rat _ h },\nend\n\nlemma floor_lt_irrational (x : \u211d) (h : irrational x) : \u2191\u230ax\u230b < x :=\nbegin\n  cases lt_or_eq_of_le (floor_le x) with h2 h2,\n  { exact h2 },\n  exact false.elim (irrational_ne_rat (\u230a x \u230b) h (by exact_mod_cast h2.symm)),\nend\n\nlemma irrational.floor_mul_div_lt\n{x : \u211d} (h: irrational x) {i: \u2115} (hi : 0 < i) :\n((\u230ax * i\u230b / i) : \u211d) < x :=\nbegin\n  rw div_lt_iff (show 0 < (i : \u211d), by assumption_mod_cast),\n  apply floor_lt_irrational,\n  convert irrational.mul_rat h (show (i : \u211a) \u2260 0, by exact_mod_cast (ne_of_lt hi).symm) using 2,\n  norm_cast,\nend\n\nlemma irrational.floor_mul_add_one_div_lt\n{i: \u2115} (x : \u211d) (hi : 0 < i) :\nx < ((\u230ax * i\u230b + 1) : \u211d) / (i : \u211d)\n:=\nbegin\n  rw lt_div_iff (show 0 < (i : \u211d), by assumption_mod_cast),\n  exact lt_floor_add_one _,\nend\n\ntheorem \u03b4\u1d62_between {x: \u211d} {r : \u211d}  {i : \u2115}\n(hx0 : irrational x) (hn0 : 0 < i)\n(h : |r - x| < min (|x - \u230ax * i\u230b / (i :\u211d)|)  (|x - (\u230ax * i\u230b + 1) / (i :\u211d)|)) :\n(\u230ax * i\u230b / i : \u211d) < r \u2227 r < ((\u230ax * i\u230b + 1) / i : \u211d)\n:=\nbegin\n  simp only [lt_min_iff] at h,\n  rw abs_of_pos (sub_pos_of_lt (irrational.floor_mul_div_lt hx0 hn0)) at h,\n  rw abs_of_neg (sub_neg_of_lt (irrational.floor_mul_add_one_div_lt x hn0)) at h,\n  split,\n  linarith [(abs_lt.mp h.left).left],\n  linarith [(abs_lt.mp h.right).right],\nend\n\ntheorem no_rat_between  (n : \u2124) (q : \u211a) (l: (n / q.denom : \u211a) < q) (r: q < ((n + 1) / q.denom : \u211a))\n: false :=\nbegin\n  nth_rewrite 1 \u2190rat.num_div_denom q at l,\n  nth_rewrite 0 \u2190rat.num_div_denom q at r,\n  have h : (0 : \u211a) < q.denom := by exact_mod_cast q.pos,\n  have l' := (mul_lt_mul_right h).mp ((div_lt_div_iff h h).mp l),\n  norm_cast at l',\n  have r' := (mul_lt_mul_right h).mp ((div_lt_div_iff h h).mp r),\n  norm_cast at r',\n  linarith,\nend\n\ntheorem thomaes_continous_at_irrational {x} (h : irrational x)\n: continuous_at thomaes_function x :=\nbegin\n  apply metric.continuous_at_iff.mpr,\n  simp_rw [real.dist_eq, thomaes_at_irrational_eq_zero h, sub_zero],\n  intros \u03b5 \u03b5_pos,\n\n  obtain \u27e8r, hr\u27e9 := exists_nat_one_div_lt \u03b5_pos,\n  have r_add_one_pos : 0 < r + 1 := nat.succ_pos r,\n  rw one_div at hr,\n\n  let \u03b4\u1d62 : \u211d \u2192 \u2115 \u2192 \u211d  := \u03bb x i, min\n    (|x - \u230ax * i\u230b / (i :\u211d)|)\n    (|x - (\u230ax * i\u230b + 1) / (i :\u211d)|),\n\n  obtain \u27e8i_min, \u27e8i_pos, i_le_r\u27e9, i_min_indice\u27e9 :=\n    set.exists_min_image _\n    (\u03b4\u1d62 x)\n    -- \u03b4 indices are finite and nonempty\n    (set.Ioc_\u2115_finite 0 _)\n    (\u27e81, zero_lt_one, nat.one_le_of_lt r_add_one_pos\u27e9),\n\n  refine \u27e8\u03b4\u1d62 x i_min, \u03b4\u1d62_pos i_min h, \u03bb x\u2081 h\u03b4, _\u27e9,\n\n  by_cases H : \u2203 q : \u211a, (q : \u211d) = x\u2081,\n  { obtain \u27e8q, rfl\u27e9 := H,\n    norm_cast,\n    rw abs_of_pos (thomae_rat_pos q),\n\n    have r_add_one_le_q_denom : (r + 1) \u2264 q.denom,\n    { by_contradiction H,\n      push_neg at H,\n      have lt_delta_of_q := lt_of_lt_of_le h\u03b4 (i_min_indice q.denom \u27e8q.pos, le_of_lt H\u27e9),\n      obtain \u27e8l, r\u27e9 := \u03b4\u1d62_between h q.pos lt_delta_of_q,\n      exact no_rat_between (\u230a x * q.denom\u230b) q (by exact_mod_cast l) (by exact_mod_cast r) },\n\n      rw thomae_rat,\n      exact_mod_cast (lt_of_le_of_lt (\n        (inv_le_inv\n          (show 0 < ((q.denom : \u211a) : \u211d), by exact_mod_cast q.pos)\n            (show 0 < (r + 1 :\u211d ), by exact_mod_cast r_add_one_pos)).mpr\n              (by exact_mod_cast r_add_one_le_q_denom)) hr),\n  },\n  { rw thomaes_at_irrational_eq_zero H,\n    simpa using \u03b5_pos },\nend\n\ntheorem thomaes_discontinous_at_rational (q : \u211a)\n: \u00accontinuous_at thomaes_function q :=\nbegin\n  intro h,\n  simp only [metric.continuous_at_iff] at h,\n  norm_cast at h,\n  specialize h\n    (thomae_rat q)\n    (by exact_mod_cast (thomae_rat_pos q)),\n  rcases h with \u27e8\u03b4, \u03b4_pos, h\u03b4\u27e9,\n  simp_rw real.dist_eq at h\u03b4,\n\n  rcases exists_irrational_btwn \u03b4_pos with \u27e8r, \u27e8r_irrat, r_pos, r_lt_\u03b4\u27e9\u27e9,\n\n  specialize h\u03b4 (show |(r + q) - q| < \u03b4, by simpa [abs_of_pos r_pos]),\n\n  rw [\n    thomaes_at_irrational_eq_zero (irrational.add_rat q r_irrat)\n  ] at h\u03b4,\n  simp only [zero_sub, abs_neg] at h\u03b4,\n  rw abs_of_pos (show ((thomae_rat q) : \u211d) > 0, by exact_mod_cast (thomae_rat_pos q)) at h\u03b4,\n  exact (lt_self_iff_false _).mp h\u03b4,\nend\n", "meta": {"author": "FrickHazard", "repo": "thomaes-function", "sha": "260ba849187a5a1867ec988370010e6aebc31f00", "save_path": "github-repos/lean/FrickHazard-thomaes-function", "path": "github-repos/lean/FrickHazard-thomaes-function/thomaes-function-260ba849187a5a1867ec988370010e6aebc31f00/src/thomaes_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7070191368410816}}
{"text": "def \u2124\u2080 := \u2115 \u00d7 \u2115\n\ndef eqv : \u2124\u2080 \u2192 \u2124\u2080 \u2192 Prop\n| (a, b) (c, d) := a + d = c + b\n\ninfix ` \u223d `:50 := eqv\n\n-- Definition 4.1.2.\ndef add_\u2124\u2080 : \u2124\u2080 \u2192 \u2124\u2080 \u2192 \u2124\u2080\n| (a, b) (c, d) := (a + c, b + d) \n\n-- Lemma 4.1.3 (Addition and multiplication are well-defined).\n\nprivate theorem add_\u2124\u2080.respects_eqv : \u2200 {a b a' b'}, a \u223d a' \u2192 b \u223d b' \u2192 add_\u2124\u2080 a b \u223d add_\u2124\u2080 a' b'\n| (a\u2081, a\u2082) (b\u2081, b\u2082) (a'\u2081, a'\u2082) (b'\u2081, b'\u2082) :=\n  assume a_eqv_a' b_eqv_b',\n  have h\u2081 : a\u2081 + a'\u2082 = a'\u2081 + a\u2082, from a_eqv_a',\n  have h\u2082 : b\u2081 + b'\u2082 = b'\u2081 + b\u2082, from b_eqv_b',\n  have h\u2083 : a\u2081 + b\u2081 + a'\u2082 + b'\u2082 = a'\u2081 + b'\u2081 + a\u2082 + b\u2082, from \n    calc\n      a\u2081 + b\u2081 + a'\u2082 + b'\u2082 = a\u2081 + a'\u2082 + b\u2081 + b'\u2082 : by simp [add_comm]\n                      ... = a\u2081 + a'\u2082 + b'\u2081 + b\u2082 : by simp [add_assoc, h\u2082^.symm]\n                      ... = a'\u2081 + a\u2082 + b'\u2081 + b\u2082 : by simp [add_assoc, h\u2081^.symm]\n                      ... = a'\u2081 + b'\u2081 + a\u2082 + b\u2082 : by simp [add_comm],\n  have h\u2084 : (a\u2081 + b\u2081, a\u2082 + b\u2082) \u223d (a'\u2081 + b'\u2081, a'\u2082 + b'\u2082), from h\u2083, -- Why does this fail?\n  have h\u2085 : add_\u2124\u2080 (a\u2081, a\u2082) (b\u2081, b\u2082) = (a\u2081 + b\u2081, a\u2082 + b\u2082), from rfl,\n  have h\u2086 : add_\u2124\u2080 (a'\u2081, a'\u2082) (b'\u2081, b'\u2082) = (a'\u2081 + b'\u2081, a'\u2082 + b'\u2082), from rfl,\n  show add_\u2124\u2080 (a\u2081, a\u2082) (b\u2081, b\u2082) \u223d add_\u2124\u2080 (a'\u2081, a'\u2082) (b'\u2081, b'\u2082), from sorry", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/20170714-lean-user.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7069794462284404}}
{"text": "import set_theory.cardinal.finite\n\nuniverses u u\u2081 u\u2082 u\u2083\n\nsection axiom_sets \n\nvariable {\u03b1 : Type*}\n\nsection rank \n\ndef satisfies_R0 (r : set \u03b1 \u2192 \u2115) : Prop := \n  \u2200 X, 0 \u2264 r X \n\ndef satisfies_R1 (r : set \u03b1 \u2192 \u2115) : Prop := \n  \u2200 X, r X \u2264 nat.card X\n\ndef satisfies_R2 (r : set \u03b1 \u2192 \u2115) : Prop := \n  \u2200 X Y, X \u2286 Y \u2192 r X \u2264 r Y \n\ndef satisfies_R3 (r : set \u03b1 \u2192 \u2115) : Prop := \n  \u2200 X Y, r (X \u222a Y) + r (X \u2229 Y) \u2264 r X + r Y\n\n@[ext] structure rankfun (\u03b1 : Type*) :=\n  (r : set \u03b1 \u2192 \u2115)\n  (R0 : satisfies_R0 r)\n  (R1 : satisfies_R1 r)\n  (R2 : satisfies_R2 r)\n  (R3 : satisfies_R3 r)\n\nend rank \n\nsection indep \n\ndef satisfies_I1 (indep : set \u03b1 \u2192 Prop) : Prop := \n  indep \u2205 \n\ndef satisfies_I2 (indep : set \u03b1 \u2192 Prop) : Prop := \n  \u2200 I J, I \u2286 J \u2192 indep J \u2192 indep I\n\ndef satisfies_I3 (indep : set \u03b1 \u2192 Prop) : Prop := \u2200 (I J : set \u03b1), \n  nat.card I < nat.card J \u2192 indep I \u2192 indep J \u2192 \u2203 (e : \u03b1), e \u2208 J \\ I \u2227 indep (I \u222a {e})\n\n--def satisfies_I3' : (set \u03b1 \u2192 Prop) \u2192 Prop := \n--  \u03bb indep, \u2200 X, \u2203 r, \u2200 B, (B \u2286 X \u2227 indep B \u2227 (\u2200 Y, B \u2282 Y \u2192 Y \u2286 X \u2192 \u00acindep Y) \u2192 size B = r\n\n@[ext] structure indep_family (\u03b1 : Type*) := \n  (indep : set \u03b1 \u2192 Prop)\n  (I1 : satisfies_I1 indep)\n  (I2 : satisfies_I2 indep)\n  (I3 : satisfies_I3 indep)\n\n/-@[ext] structure indep_family' (\u03b1 : Type*) := \n  (indep : set \u03b1 \u2192 Prop)\n  (I1 : satisfies_I1 indep)\n  (I2 : satisfies_I2 indep)\n  (I3' : satisfies_I3' indep)-/\n\nend indep \n\nsection cct \n\ndef satisfies_C1 (cct : set \u03b1 \u2192 Prop) : Prop := \n  \u00ac cct \u2205 \n\ndef satisfies_C2 (cct : set \u03b1 \u2192 Prop) : Prop:= \n  \u2200 C\u2081 C\u2082, cct C\u2081 \u2192 cct C\u2082 \u2192 \u00ac(C\u2081 \u2282 C\u2082)\n\ndef satisfies_C3 (cct : set \u03b1 \u2192 Prop) : Prop:= \n  \u2200 C\u2081 C\u2082 (e : \u03b1), C\u2081 \u2260 C\u2082 \u2192 cct C\u2081 \u2192 cct C\u2082 \n    \u2192 e \u2208 (C\u2081 \u2229 C\u2082) \u2192 \u2203 C\u2080 , cct C\u2080 \u2227 C\u2080 \u2286 (C\u2081 \u222a C\u2082) \\ {e}\n\n@[ext] structure cct_family (\u03b1 : Type*) :=\n  (cct : set \u03b1 \u2192 Prop)\n  (C1 : satisfies_C1 cct)\n  (C2 : satisfies_C2 cct)\n  (C3 : satisfies_C3 cct)\n\nend cct\n\nsection basis\n\ndef exists_basis (basis : set \u03b1 \u2192 Prop) : Prop :=\n  \u2203 B, basis B\n\ndef basis_exchange (basis : set \u03b1 \u2192 Prop) : Prop :=\n  \u2200 B\u2081 B\u2082, basis B\u2081 \u2192 basis B\u2082 \n    \u2192 \u2200 (b\u2081 : \u03b1), b\u2081 \u2208 B\u2081 \\ B\u2082 \u2192 \u2203 b\u2082, (b\u2082 \u2208 B\u2082 \\ B\u2081) \u2227 basis (B\u2081 \\ {b\u2081} \u222a {b\u2082}) \n\n@[ext] structure basis_family (\u03b1 : Type*) :=\n  (basis : set \u03b1 \u2192 Prop)\n  (B1 : exists_basis basis)\n  (B2 : basis_exchange basis)\n\nend basis \n\nsection cl \n\ndef satisfies_cl1 : (set \u03b1 \u2192 set \u03b1) \u2192 Prop := \n  \u03bb cl, \u2200 X, X \u2286 cl X\n\ndef satisfies_cl2 : (set \u03b1 \u2192 set \u03b1) \u2192 Prop := \n  \u03bb cl, \u2200 X, cl (cl X) = cl X\n\ndef satisfies_cl3 : (set \u03b1 \u2192 set \u03b1) \u2192 Prop := \n  \u03bb cl, \u2200 X Y : set \u03b1 , X \u2286 Y \u2192 cl X \u2286 cl Y \n\ndef satisfies_cl4 : (set \u03b1 \u2192 set \u03b1) \u2192 Prop :=\n  \u03bb cl, \u2200 X (e f : \u03b1), (e \u2208 cl (X \u222a {f}) \\ X) \u2192 (f \u2208 cl (X \u222a {e}) \\ X)\n\nstructure clfun (\u03b1 : Type*) := \n  (cl : set \u03b1 \u2192 set \u03b1)\n  (cl1 : satisfies_cl1 cl)\n  (cl2 : satisfies_cl2 cl)\n  (cl3 : satisfies_cl3 cl)\n  (cl4 : satisfies_cl4 cl)\n\nend cl \n\nend axiom_sets \n\ndef matroid (\u03b1 : Type*) := basis_family \u03b1 \n\nvariables {\u03b1\u2081 : Type* }{\u03b1\u2082 : Type* }{\u03b1\u2083 : Type*}\n\nnamespace matroid\n\nstructure isom (M\u2081 : matroid \u03b1\u2081) (M\u2082 : matroid \u03b1\u2082) := \n(equiv : \u03b1\u2081 \u2243 \u03b1\u2082)\n(on_basis : \u2200 B, M\u2081.basis B \u2194 M\u2082.basis (equiv '' B))\n-- (on_rank : \u2200 X, M\u2082.r (equiv '' X) = M\u2081.r X)\n\n-- instance coe_to_equiv {M\u2081 : matroid \u03b1\u2081} {M\u2082 : matroid \u03b1\u2082} : has_coe_to_fun (M\u2081.isom M\u2082) := \n-- { F := _,\n--   coe := \u03bb i, i.equiv } \n\n-- def isom.refl (M\u2081 : matroid \u03b1\u2081) : \n-- M\u2081.isom M\u2081 := \n-- { equiv := equiv.refl \u03b1\u2081,\n--   on_rank := by simp  }\n\n-- def isom.trans {M\u2081 : matroid \u03b1\u2081} {M\u2082 : matroid \u03b1\u2082} {M\u2083 : matroid \u03b1\u2083} \n-- (I12 : M\u2081.isom M\u2082) (I23 : M\u2082.isom M\u2083) : \n-- M\u2081.isom M\u2083 :=\n-- { equiv := I12.equiv.trans I23.equiv ,\n--   on_rank := \u03bb X, by {rw [\u2190I12.on_rank, \u2190I23.on_rank], apply congr_arg, ext, simp  }  } \n\n-- def isom.symm {M\u2081 : matroid \u03b1\u2081} {M\u2082 : matroid \u03b1\u2082} (i : M\u2081.isom M\u2082) : M\u2082.isom M\u2081 := \n-- { equiv := i.equiv.symm,\n--   on_rank := \u03bb X, by {rw \u2190i.on_rank, apply congr_arg, ext, simp,  } }\n\n-- def is_isom (M\u2081 : matroid \u03b1\u2081) (M\u2082 : matroid \u03b1\u2082) := \n--   nonempty (M\u2081.isom M\u2082)\n\n-- lemma isom.inv_on_rank {M\u2081 : matroid \u03b1\u2081} {M\u2082 : matroid \u03b1\u2082} (i : isom M\u2081 M\u2082) (X : set \u03b1\u2082) :\n--   M\u2082.r X = M\u2081.r (i.equiv.symm '' X) :=\n-- by {rw \u2190i.symm.on_rank X, refl} \n\n-- def isom_equiv {M\u2081 N\u2081 : matroid \u03b1\u2081} {M\u2082 N\u2082 : matroid \u03b1\u2082} \n-- (h\u2081 : M\u2081 = N\u2081) (h\u2082 : M\u2082 = N\u2082) (i : isom M\u2081 M\u2082) : \n--   isom N\u2081 N\u2082 := \n-- { equiv := i.equiv,\n--   on_rank := \u03bb X, by {rw [\u2190h\u2081,\u2190h\u2082], apply i.on_rank, } }\n \nend matroid \n\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_basic/axioms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.7069744779593884}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Damiano Testa, Jens Wagemaker\n-/\nimport data.nat.interval\nimport data.polynomial.degree.definitions\n\n/-!\n# Induction on polynomials\n\nThis file contains lemmas dealing with different flavours of induction on polynomials.\n-/\n\nnoncomputable theory\nopen_locale classical big_operators polynomial\n\nopen finset\n\nnamespace polynomial\nuniverses u v w z\nvariables {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : \u2115}\n\nsection semiring\nvariables [semiring R] {p q : R[X]}\n\n/-- `div_X p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`.\n  It can be used in a semiring where the usual division algorithm is not possible -/\ndef div_X (p : R[X]) : R[X] :=\n\u2211 n in Ico 0 p.nat_degree, monomial n (p.coeff (n + 1))\n\n@[simp] lemma coeff_div_X : (div_X p).coeff n = p.coeff (n+1) :=\nbegin\n  simp only [div_X, coeff_monomial, true_and, finset_sum_coeff, not_lt,\n    mem_Ico, zero_le, finset.sum_ite_eq', ite_eq_left_iff],\n  intro h,\n  rw coeff_eq_zero_of_nat_degree_lt (nat.lt_succ_of_le h)\nend\n\nlemma div_X_mul_X_add (p : R[X]) : div_X p * X + C (p.coeff 0) = p :=\next $ by rintro \u27e8_|_\u27e9; simp [coeff_C, nat.succ_ne_zero, coeff_mul_X]\n\n@[simp] lemma div_X_C (a : R) : div_X (C a) = 0 :=\next $ \u03bb n, by simp [div_X, coeff_C]; simp [coeff]\n\nlemma div_X_eq_zero_iff : div_X p = 0 \u2194 p = C (p.coeff 0) :=\n\u27e8\u03bb h, by simpa [eq_comm, h] using div_X_mul_X_add p,\n  \u03bb h, by rw [h, div_X_C]\u27e9\n\nlemma div_X_add : div_X (p + q) = div_X p + div_X q :=\next $ by simp\n\nlemma degree_div_X_lt (hp0 : p \u2260 0) : (div_X p).degree < p.degree :=\nby haveI := nontrivial.of_polynomial_ne hp0;\ncalc (div_X p).degree < (div_X p * X + C (p.coeff 0)).degree :\n  if h : degree p \u2264 0\n  then begin\n      have h' : C (p.coeff 0) \u2260 0, by rwa [\u2190 eq_C_of_degree_le_zero h],\n      rw [eq_C_of_degree_le_zero h, div_X_C, degree_zero, zero_mul, zero_add],\n      exact lt_of_le_of_ne bot_le (ne.symm (mt degree_eq_bot.1 $\n        by simp [h'])),\n    end\n  else\n    have hXp0 : div_X p \u2260 0,\n      by simpa [div_X_eq_zero_iff, -not_le, degree_le_zero_iff] using h,\n    have leading_coeff (div_X p) * leading_coeff X \u2260 0, by simpa,\n    have degree (C (p.coeff 0)) < degree (div_X p * X),\n      from calc degree (C (p.coeff 0)) \u2264 0 : degree_C_le\n         ... < 1 : dec_trivial\n         ... = degree (X : R[X]) : degree_X.symm\n         ... \u2264 degree (div_X p * X) :\n          by rw [\u2190 zero_add (degree X), degree_mul' this];\n            exact add_le_add\n              (by rw [zero_le_degree_iff, ne.def, div_X_eq_zero_iff];\n                exact \u03bb h0, h (h0.symm \u25b8 degree_C_le))\n              le_rfl,\n    by rw [degree_add_eq_left_of_degree_lt this];\n      exact degree_lt_degree_mul_X hXp0\n... = p.degree : congr_arg _ (div_X_mul_X_add _)\n\n/-- An induction principle for polynomials, valued in Sort* instead of Prop. -/\n@[elab_as_eliminator] noncomputable def rec_on_horner\n  {M : R[X] \u2192 Sort*} : \u03a0 (p : R[X]),\n  M 0 \u2192\n  (\u03a0 p a, coeff p 0 = 0 \u2192 a \u2260 0 \u2192 M p \u2192 M (p + C a)) \u2192\n  (\u03a0 p, p \u2260 0 \u2192 M p \u2192 M (p * X)) \u2192\n  M p\n| p := \u03bb M0 MC MX,\nif hp : p = 0 then eq.rec_on hp.symm M0\nelse\nhave wf : degree (div_X p) < degree p,\n  from degree_div_X_lt hp,\nby rw [\u2190 div_X_mul_X_add p] at *;\n  exact\n  if hcp0 : coeff p 0 = 0\n  then by rw [hcp0, C_0, add_zero];\n    exact MX _ (\u03bb h : div_X p = 0, by simpa [h, hcp0] using hp)\n      (rec_on_horner _ M0 MC MX)\n  else MC _ _ (coeff_mul_X_zero _) hcp0 (if hpX0 : div_X p = 0\n    then show M (div_X p * X), by rw [hpX0, zero_mul]; exact M0\n    else MX (div_X p) hpX0 (rec_on_horner _ M0 MC MX))\nusing_well_founded {dec_tac := tactic.assumption}\n\n/--  A property holds for all polynomials of positive `degree` with coefficients in a semiring `R`\nif it holds for\n* `a * X`, with `a \u2208 R`,\n* `p * X`, with `p \u2208 R[X]`,\n* `p + a`, with `a \u2208 R`, `p \u2208 R[X]`,\nwith appropriate restrictions on each term.\n\nSee `nat_degree_ne_zero_induction_on` for a similar statement involving no explicit multiplication.\n -/\n@[elab_as_eliminator] lemma degree_pos_induction_on\n  {P : R[X] \u2192 Prop} (p : R[X]) (h0 : 0 < degree p)\n  (hC : \u2200 {a}, a \u2260 0 \u2192 P (C a * X))\n  (hX : \u2200 {p}, 0 < degree p \u2192 P p \u2192 P (p * X))\n  (hadd : \u2200 {p} {a}, 0 < degree p \u2192 P p \u2192 P (p + C a)) : P p :=\nrec_on_horner p\n  (\u03bb h, by rw degree_zero at h; exact absurd h dec_trivial)\n  (\u03bb p a _ _ ih h0,\n    have 0 < degree p,\n      from lt_of_not_ge (\u03bb h, (not_lt_of_ge degree_C_le) $\n        by rwa [eq_C_of_degree_le_zero h, \u2190 C_add] at h0),\n    hadd this (ih this))\n  (\u03bb p _ ih h0',\n    if h0 : 0 < degree p\n    then hX h0 (ih h0)\n    else by rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at *;\n      exact hC (\u03bb h : coeff p 0 = 0,\n        by simpa [h, nat.not_lt_zero] using h0'))\n  h0\n\n/--  A property holds for all polynomials of non-zero `nat_degree` with coefficients in a\nsemiring `R` if it holds for\n* `p + a`, with `a \u2208 R`, `p \u2208 R[X]`,\n* `p + q`, with `p, q \u2208 R[X]`,\n* monomials with nonzero coefficient and non-zero exponent,\nwith appropriate restrictions on each term.\nNote that multiplication is \"hidden\" in the assumption on monomials, so there is no explicit\nmultiplication in the statement.\nSee `degree_pos_induction_on` for a similar statement involving more explicit multiplications.\n -/\n@[elab_as_eliminator] lemma nat_degree_ne_zero_induction_on {M : R[X] \u2192 Prop}\n  {f : R[X]} (f0 : f.nat_degree \u2260 0) (h_C_add : \u2200 {a p}, M p \u2192 M (C a + p))\n  (h_add : \u2200 {p q}, M p \u2192 M q \u2192 M (p + q))\n  (h_monomial : \u2200 {n : \u2115} {a : R}, a \u2260 0 \u2192 n \u2260 0 \u2192 M (monomial n a)) :\n  M f :=\nsuffices f.nat_degree = 0 \u2228 M f, from or.dcases_on this (\u03bb h, (f0 h).elim) id,\nbegin\n  apply f.induction_on,\n  { exact \u03bb a, or.inl (nat_degree_C _) },\n  { rintros p q (hp | hp) (hq | hq),\n    { refine or.inl _,\n      rw [eq_C_of_nat_degree_eq_zero hp, eq_C_of_nat_degree_eq_zero hq, \u2190 C_add, nat_degree_C] },\n    { refine or.inr _,\n      rw [eq_C_of_nat_degree_eq_zero hp],\n      exact h_C_add hq },\n    { refine or.inr _,\n      rw [eq_C_of_nat_degree_eq_zero hq, add_comm],\n      exact h_C_add hp },\n    { exact or.inr (h_add hp hq) } },\n  { intros n a hi,\n    by_cases a0 : a = 0,\n    { exact or.inl (by rw [a0, C_0, zero_mul, nat_degree_zero]) },\n    { refine or.inr _,\n      rw C_mul_X_pow_eq_monomial,\n      exact h_monomial a0 n.succ_ne_zero } }\nend\n\nend semiring\n\nend polynomial\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/polynomial/inductions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7069235532691028}}
{"text": "import data.set.basic -- hide\nopen set -- hide\n\n/-\n## The distributive property\n\nThe extensionality property of sets says that two sets are equal if and only if they have the same elements.\n\nOne can `apply ext, intro x` to invoke it. The `ext` tactic is a shortcut for this.\n-/\n\nvariables {X Y : Type} -- hide\n\n/- Lemma :\nThe distributive property of \u2229 with respect to \u222a.\n-/\nlemma inter_union (A B C : set X) : A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\n  ext,\n  split,\n  {\n    intro h,\n    cases h,\n    cases h_right,\n    {\n      left,\n      split;\n      assumption,\n    },\n    {\n      right,\n      split;\n      assumption,\n    }\n  },\n  {\n    intro h,\n    cases h,\n    {\n      split,\n      {\n        exact h.1,\n      },\n      {\n        left,\n        exact h.2,\n      },\n    },\n    {\n      split,\n      {\n        exact h.1,\n      },\n      {\n        right,\n        exact h.2,\n      }\n    }\n  }\nend\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/set_theory_world/distributive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7069235502418642}}
{"text": "/-\nCopyright (c) 2021 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Devon Tuma\n-/\nimport analysis.normed_space.ordered\nimport analysis.asymptotics.asymptotics\nimport topology.algebra.ordered.liminf_limsup\nimport data.polynomial.eval\n\n/-!\n# Super-Polynomial Function Decay\n\nThis file defines a predicate `asymptotics.superpolynomial_decay f` for a function satisfying\n  one of following equivalent definitions (The definition is in terms of the first condition):\n\n* `x ^ n * f` tends to `\ud835\udcdd 0` for all (or sufficiently large) naturals `n`\n* `|x ^ n * f|` tends to `\ud835\udcdd 0` for all naturals `n` (`superpolynomial_decay_iff_abs_tendsto_zero`)\n* `|x ^ n * f|` is bounded for all naturals `n` (`superpolynomial_decay_iff_abs_is_bounded_under`)\n* `f` is `o(x ^ c)` for all integers `c` (`superpolynomial_decay_iff_is_o`)\n* `f` is `O(x ^ c)` for all integers `c` (`superpolynomial_decay_iff_is_O`)\n\nThese conditions are all equivalent to conditions in terms of polynomials, replacing `x ^ c` with\n  `p(x)` or `p(x)\u207b\u00b9` as appropriate, since asymptotically `p(x)` behaves like `X ^ p.nat_degree`.\nThese further equivalences are not proven in mathlib but would be good future projects.\n\nThe definition of superpolynomial decay for `f : \u03b1 \u2192 \u03b2` is relative to a parameter `k : \u03b1 \u2192 \u03b2`.\nSuper-polynomial decay then means `f x` decays faster than `(k x) ^ c` for all integers `c`.\nEquivalently `f x` decays faster than `p.eval (k x)` for all polynomials `p : polynomial \u03b2`.\nThe definition is also relative to a filter `l : filter \u03b1` where the decay rate is compared.\n\nWhen the map `k` is given by `n \u21a6 \u2191n : \u2115 \u2192 \u211d` this defines negligible functions:\nhttps://en.wikipedia.org/wiki/Negligible_function\n\nWhen the map `k` is given by `(r\u2081,...,r\u2099) \u21a6 r\u2081*...*r\u2099 : \u211d\u207f \u2192 \u211d` this is equivalent\n  to the definition of rapidly decreasing functions given here:\nhttps://ncatlab.org/nlab/show/rapidly+decreasing+function\n\n# Main Theorems\n\n* `superpolynomial_decay.polynomial_mul` says that if `f(x)` is negligible,\n    then so is `p(x) * f(x)` for any polynomial `p`.\n* `superpolynomial_decay_iff_zpow_tendsto_zero` gives an equivalence between definitions in terms\n    of decaying faster than `k(x) ^ n` for all naturals `n` or `k(x) ^ c` for all integer `c`.\n-/\n\nnamespace asymptotics\n\nopen_locale topological_space\nopen filter\n\n/-- `f` has superpolynomial decay in parameter `k` along filter `l` if\n  `k ^ n * f` tends to zero at `l` for all naturals `n` -/\ndef superpolynomial_decay {\u03b1 \u03b2 : Type*} [topological_space \u03b2] [comm_semiring \u03b2]\n  (l : filter \u03b1) (k : \u03b1 \u2192 \u03b2) (f : \u03b1 \u2192 \u03b2) :=\n\u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), (k a) ^ n * f a) l (\ud835\udcdd 0)\n\nvariables {\u03b1 \u03b2 : Type*} {l : filter \u03b1} {k : \u03b1 \u2192 \u03b2} {f g g' : \u03b1 \u2192 \u03b2}\n\nsection comm_semiring\n\nvariables [topological_space \u03b2] [comm_semiring \u03b2]\n\nlemma superpolynomial_decay.congr' (hf : superpolynomial_decay l k f)\n  (hfg : f =\u1da0[l] g) : superpolynomial_decay l k g :=\n\u03bb z, (hf z).congr' (eventually_eq.mul (eventually_eq.refl l _) hfg)\n\nlemma superpolynomial_decay.congr (hf : superpolynomial_decay l k f)\n  (hfg : \u2200 x, f x = g x) : superpolynomial_decay l k g :=\n\u03bb z, (hf z).congr (\u03bb x, congr_arg (\u03bb a, k x ^ z * a) $ hfg x)\n\n@[simp]\nlemma superpolynomial_decay_zero (l : filter \u03b1) (k : \u03b1 \u2192 \u03b2) :\n  superpolynomial_decay l k 0 :=\n\u03bb z, by simpa only [pi.zero_apply, mul_zero] using tendsto_const_nhds\n\nlemma superpolynomial_decay.add [has_continuous_add \u03b2] (hf : superpolynomial_decay l k f)\n  (hg : superpolynomial_decay l k g) : superpolynomial_decay l k (f + g) :=\n\u03bb z, by simpa only [mul_add, add_zero, pi.add_apply] using (hf z).add (hg z)\n\nlemma superpolynomial_decay.mul [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (hg : superpolynomial_decay l k g) : superpolynomial_decay l k (f * g) :=\n\u03bb z, by simpa only [mul_assoc, one_mul, mul_zero, pow_zero] using (hf z).mul (hg 0)\n\nlemma superpolynomial_decay.mul_const [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (c : \u03b2) : superpolynomial_decay l k (\u03bb n, f n * c) :=\n\u03bb z, by simpa only [\u2190mul_assoc, zero_mul] using tendsto.mul_const c (hf z)\n\nlemma superpolynomial_decay.const_mul [has_continuous_mul \u03b2] (hf : superpolynomial_decay l k f)\n  (c : \u03b2) : superpolynomial_decay l k (\u03bb n, c * f n) :=\n(hf.mul_const c).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.param_mul (hf : superpolynomial_decay l k f) :\n  superpolynomial_decay l k (k * f) :=\n\u03bb z, tendsto_nhds.2 (\u03bb s hs hs0, l.sets_of_superset ((tendsto_nhds.1 (hf $ z + 1)) s hs hs0)\n  (\u03bb x hx, by simpa only [set.mem_preimage, pi.mul_apply, \u2190 mul_assoc, \u2190 pow_succ'] using hx))\n\nlemma superpolynomial_decay.mul_param (hf : superpolynomial_decay l k f) :\n  superpolynomial_decay l k (f * k) :=\n(hf.param_mul).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.param_pow_mul (hf : superpolynomial_decay l k f)\n  (n : \u2115) : superpolynomial_decay l k (k ^ n * f) :=\nbegin\n  induction n with n hn,\n  { simpa only [one_mul, pow_zero] using hf },\n  { simpa only [pow_succ, mul_assoc] using hn.param_mul }\nend\n\nlemma superpolynomial_decay.mul_param_pow (hf : superpolynomial_decay l k f)\n  (n : \u2115) : superpolynomial_decay l k (f * k ^ n) :=\n(hf.param_pow_mul n).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.polynomial_mul [has_continuous_add \u03b2] [has_continuous_mul \u03b2]\n  (hf : superpolynomial_decay l k f) (p : polynomial \u03b2) :\n  superpolynomial_decay l k (\u03bb x, (p.eval $ k x) * f x) :=\npolynomial.induction_on' p (\u03bb p q hp hq, by simpa [add_mul] using hp.add hq)\n  (\u03bb n c, by simpa [mul_assoc] using (hf.param_pow_mul n).const_mul c)\n\nlemma superpolynomial_decay.mul_polynomial [has_continuous_add \u03b2] [has_continuous_mul \u03b2]\n  (hf : superpolynomial_decay l k f) (p : polynomial \u03b2) :\n  superpolynomial_decay l k (\u03bb x, f x * (p.eval $ k x)) :=\n(hf.polynomial_mul p).congr (\u03bb _, mul_comm _ _)\n\nend comm_semiring\n\nsection ordered_comm_semiring\n\nvariables [topological_space \u03b2] [ordered_comm_semiring \u03b2] [order_topology \u03b2]\n\n\n\nend ordered_comm_semiring\n\nsection linear_ordered_comm_ring\n\nvariables [topological_space \u03b2] [linear_ordered_comm_ring \u03b2] [order_topology \u03b2]\n\nvariables (l k f)\n\nlemma superpolynomial_decay_iff_abs_tendsto_zero :\n  superpolynomial_decay l k f \u2194 \u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), |(k a) ^ n * f a|) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h z, (tendsto_zero_iff_abs_tendsto_zero _).1 (h z),\n  \u03bb h z, (tendsto_zero_iff_abs_tendsto_zero _).2 (h z)\u27e9\n\nlemma superpolynomial_decay_iff_superpolynomial_decay_abs :\n  superpolynomial_decay l k f \u2194 superpolynomial_decay l (\u03bb a, |k a|) (\u03bb a, |f a|) :=\n(superpolynomial_decay_iff_abs_tendsto_zero l k f).trans (by simp [superpolynomial_decay, abs_mul])\n\nvariables {l k f}\n\nlemma superpolynomial_decay.trans_eventually_abs_le (hf : superpolynomial_decay l k f)\n  (hfg : abs \u2218 g \u2264\u1da0[l] abs \u2218 f) : superpolynomial_decay l k g :=\nbegin\n  rw superpolynomial_decay_iff_abs_tendsto_zero at hf \u22a2,\n  refine \u03bb z, tendsto_of_tendsto_of_tendsto_of_le_of_le' (tendsto_const_nhds) (hf z)\n    (eventually_of_forall $ \u03bb x, abs_nonneg _) (hfg.mono $ \u03bb x hx, _),\n  calc |k x ^ z * g x| = |k x ^ z| * |g x| : abs_mul (k x ^ z) (g x)\n    ... \u2264 |k x ^ z| * |f x| : mul_le_mul le_rfl hx (abs_nonneg _) (abs_nonneg _)\n    ... = |k x ^ z * f x| : (abs_mul (k x ^ z) (f x)).symm,\nend\n\nlemma superpolynomial_decay.trans_abs_le (hf : superpolynomial_decay l k f)\n  (hfg : \u2200 x, |g x| \u2264 |f x|) : superpolynomial_decay l k g :=\nhf.trans_eventually_abs_le (eventually_of_forall hfg)\n\nend linear_ordered_comm_ring\n\nsection field\n\nvariables [topological_space \u03b2] [field \u03b2] (l k f)\n\nlemma superpolynomial_decay_mul_const_iff [has_continuous_mul \u03b2] {c : \u03b2} (hc0 : c \u2260 0) :\n  superpolynomial_decay l k (\u03bb n, f n * c) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.mul_const c\u207b\u00b9).congr (\u03bb x, by simp [mul_assoc, mul_inv_cancel hc0]), \u03bb h, h.mul_const c\u27e9\n\nlemma superpolynomial_decay_const_mul_iff [has_continuous_mul \u03b2] {c : \u03b2} (hc0 : c \u2260 0) :\n  superpolynomial_decay l k (\u03bb n, c * f n) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.const_mul c\u207b\u00b9).congr (\u03bb x, by simp [\u2190 mul_assoc, inv_mul_cancel hc0]), \u03bb h, h.const_mul c\u27e9\n\nvariables {l k f}\n\nend field\n\nsection linear_ordered_field\n\nvariables [topological_space \u03b2] [linear_ordered_field \u03b2] [order_topology \u03b2]\n\nvariable (f)\n\nlemma superpolynomial_decay_iff_abs_is_bounded_under (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2115), is_bounded_under (\u2264) l (\u03bb (a : \u03b1), |(k a) ^ z * f a|) :=\nbegin\n  refine \u27e8\u03bb h z, tendsto.is_bounded_under_le (tendsto.abs (h z)),\n    \u03bb h, (superpolynomial_decay_iff_abs_tendsto_zero l k f).2 (\u03bb z, _)\u27e9,\n  obtain \u27e8m, hm\u27e9 := h (z + 1),\n  have h1 : tendsto (\u03bb (a : \u03b1), (0 : \u03b2)) l (\ud835\udcdd 0) := tendsto_const_nhds,\n  have h2 : tendsto (\u03bb (a : \u03b1), |(k a)\u207b\u00b9| * m) l (\ud835\udcdd 0) := (zero_mul m) \u25b8 tendsto.mul_const m\n    ((tendsto_zero_iff_abs_tendsto_zero _).1 hk.inv_tendsto_at_top),\n  refine tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 h2\n    (eventually_of_forall (\u03bb x, abs_nonneg _)) ((eventually_map.1 hm).mp _),\n  refine ((eventually_ne_of_tendsto_at_top hk 0).mono $ \u03bb x hk0 hx, _),\n  refine le_trans (le_of_eq _) (mul_le_mul_of_nonneg_left hx $ abs_nonneg (k x)\u207b\u00b9),\n  rw [\u2190 abs_mul, \u2190 mul_assoc, pow_succ, \u2190 mul_assoc, inv_mul_cancel hk0, one_mul],\nend\n\nlemma superpolynomial_decay_iff_zpow_tendsto_zero (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), tendsto (\u03bb (a : \u03b1), (k a) ^ z * f a) l (\ud835\udcdd 0) :=\nbegin\n  refine \u27e8\u03bb h z, _, \u03bb h n, by simpa only [zpow_coe_nat] using h (n : \u2124)\u27e9,\n  by_cases hz : 0 \u2264 z,\n  { lift z to \u2115 using hz,\n    simpa using h z },\n  { have : tendsto (\u03bb a, (k a) ^ z) l (\ud835\udcdd 0) :=\n      tendsto.comp (tendsto_zpow_at_top_zero (not_le.1 hz)) hk,\n    have h : tendsto f l (\ud835\udcdd 0) := by simpa using h 0,\n    exact (zero_mul (0 : \u03b2)) \u25b8 this.mul h },\nend\n\nvariable {f}\n\nlemma superpolynomial_decay.param_zpow_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) (z : \u2124) : superpolynomial_decay l k (\u03bb a, k a ^ z * f a) :=\nbegin\n  rw superpolynomial_decay_iff_zpow_tendsto_zero _ hk at hf \u22a2,\n  refine \u03bb z', (hf $ z' + z).congr' ((eventually_ne_of_tendsto_at_top hk 0).mono (\u03bb x hx, _)),\n  simp [zpow_add\u2080 hx, mul_assoc, pi.mul_apply],\nend\n\nlemma superpolynomial_decay.mul_param_zpow (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) (z : \u2124) : superpolynomial_decay l k (\u03bb a, f a * k a ^ z) :=\n(hf.param_zpow_mul hk z).congr (\u03bb _, mul_comm _ _)\n\nlemma superpolynomial_decay.inv_param_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) : superpolynomial_decay l k (k\u207b\u00b9 * f) :=\nby simpa using (hf.param_zpow_mul hk (-1))\n\nlemma superpolynomial_decay.param_inv_mul (hk : tendsto k l at_top)\n  (hf : superpolynomial_decay l k f) : superpolynomial_decay l k (f * k\u207b\u00b9) :=\n(hf.inv_param_mul hk).congr (\u03bb _, mul_comm _ _)\n\nvariable (f)\n\nlemma superpolynomial_decay_param_mul_iff (hk : tendsto k l at_top) :\n  superpolynomial_decay l k (k * f) \u2194 superpolynomial_decay l k f :=\n\u27e8\u03bb h, (h.inv_param_mul hk).congr' ((eventually_ne_of_tendsto_at_top hk 0).mono\n  (\u03bb x hx, by simp [\u2190 mul_assoc, inv_mul_cancel hx])), \u03bb h, h.param_mul\u27e9\n\nlemma superpolynomial_decay_mul_param_iff (hk : tendsto k l at_top) :\n  superpolynomial_decay l k (f * k) \u2194 superpolynomial_decay l k f :=\nby simpa [mul_comm k] using superpolynomial_decay_param_mul_iff f hk\n\nlemma superpolynomial_decay_param_pow_mul_iff (hk : tendsto k l at_top) (n : \u2115) :\n  superpolynomial_decay l k (k ^ n * f) \u2194 superpolynomial_decay l k f :=\nbegin\n  induction n with n hn,\n  { simp },\n  { simpa [pow_succ, \u2190 mul_comm k, mul_assoc,\n      superpolynomial_decay_param_mul_iff (k ^ n * f) hk] using hn }\nend\n\nlemma superpolynomial_decay_mul_param_pow_iff (hk : tendsto k l at_top) (n : \u2115) :\n  superpolynomial_decay l k (f * k ^ n) \u2194 superpolynomial_decay l k f :=\nby simpa [mul_comm f] using superpolynomial_decay_param_pow_mul_iff f hk n\n\nvariable {f}\n\nend linear_ordered_field\n\nsection normed_linear_ordered_field\n\nvariable [normed_linear_ordered_field \u03b2]\n\nvariables (l k f)\n\nlemma superpolynomial_decay_iff_norm_tendsto_zero :\n  superpolynomial_decay l k f \u2194 \u2200 (n : \u2115), tendsto (\u03bb (a : \u03b1), \u2225(k a) ^ n * f a\u2225) l (\ud835\udcdd 0) :=\n\u27e8\u03bb h z, tendsto_zero_iff_norm_tendsto_zero.1 (h z),\n  \u03bb h z, tendsto_zero_iff_norm_tendsto_zero.2 (h z)\u27e9\n\nlemma superpolynomial_decay_iff_superpolynomial_decay_norm :\n  superpolynomial_decay l k f \u2194 superpolynomial_decay l (\u03bb a, \u2225k a\u2225) (\u03bb a, \u2225f a\u2225) :=\n(superpolynomial_decay_iff_norm_tendsto_zero l k f).trans (by simp [superpolynomial_decay])\n\nvariables {l k}\n\nvariable [order_topology \u03b2]\n\nlemma superpolynomial_decay_iff_is_O (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), is_O f (\u03bb (a : \u03b1), (k a) ^ z) l :=\nbegin\n  refine (superpolynomial_decay_iff_zpow_tendsto_zero f hk).trans _,\n  have hk0 : \u2200\u1da0 x in l, k x \u2260 0 := eventually_ne_of_tendsto_at_top hk 0,\n  refine \u27e8\u03bb h z, _, \u03bb h z, _\u27e9,\n  { refine is_O_of_div_tendsto_nhds (hk0.mono (\u03bb x hx hxz, absurd (zpow_eq_zero hxz) hx)) 0 _,\n    have : (\u03bb (a : \u03b1), k a ^ z)\u207b\u00b9 = (\u03bb (a : \u03b1), k a ^ (- z)) := funext (\u03bb x, by simp),\n    rw [div_eq_mul_inv, mul_comm f, this],\n    exact h (-z) },\n  { suffices : is_O (\u03bb (a : \u03b1), k a ^ z * f a) (\u03bb (a : \u03b1), (k a)\u207b\u00b9) l,\n    from is_O.trans_tendsto this hk.inv_tendsto_at_top,\n    refine ((is_O_refl (\u03bb a, (k a) ^ z) l).mul (h (- (z + 1)))).trans\n      (is_O.of_bound 1 $ hk0.mono (\u03bb a ha0, _)),\n    simp only [one_mul, neg_add z 1, zpow_add\u2080 ha0, \u2190 mul_assoc, zpow_neg\u2080,\n      mul_inv_cancel (zpow_ne_zero z ha0), zpow_one] }\nend\n\nlemma superpolynomial_decay_iff_is_o (hk : tendsto k l at_top) :\n  superpolynomial_decay l k f \u2194 \u2200 (z : \u2124), is_o f (\u03bb (a : \u03b1), (k a) ^ z) l :=\nbegin\n  refine \u27e8\u03bb h z, _, \u03bb h, (superpolynomial_decay_iff_is_O f hk).2 (\u03bb z, (h z).is_O)\u27e9,\n  have hk0 : \u2200\u1da0 x in l, k x \u2260 0 := eventually_ne_of_tendsto_at_top hk 0,\n  have : is_o (\u03bb (x : \u03b1), (1 : \u03b2)) k l := is_o_of_tendsto'\n    (hk0.mono (\u03bb x hkx hkx', absurd hkx' hkx)) (by simpa using hk.inv_tendsto_at_top),\n  have : is_o f (\u03bb (x : \u03b1), k x * k x ^ (z - 1)) l,\n  by simpa using this.mul_is_O (((superpolynomial_decay_iff_is_O f hk).1 h) $ z - 1),\n  refine this.trans_is_O (is_O.of_bound 1 (hk0.mono $ \u03bb x hkx, le_of_eq _)),\n  rw [one_mul, zpow_sub_one\u2080 hkx, mul_comm (k x), mul_assoc, inv_mul_cancel hkx, mul_one],\nend\n\nvariable {f}\n\nend normed_linear_ordered_field\n\nend asymptotics\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/asymptotics/superpolynomial_decay.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940974, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7069235487282446}}
{"text": "/-\nCopyright (c) 2020 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Yury Kudryashov\n-/\nimport analysis.calculus.deriv\nimport measure_theory.constructions.borel_space\nimport measure_theory.function.strongly_measurable.basic\nimport tactic.ring_exp\n\n/-!\n# Derivative is measurable\n\nIn this file we prove that the derivative of any function with complete codomain is a measurable\nfunction. Namely, we prove:\n\n* `measurable_set_of_differentiable_at`: the set `{x | differentiable_at \ud835\udd5c f x}` is measurable;\n* `measurable_fderiv`: the function `fderiv \ud835\udd5c f` is measurable;\n* `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `\u03bb x, fderiv \ud835\udd5c f x y`\n  is measurable;\n* `measurable_deriv`: the function `deriv f` is measurable (for `f : \ud835\udd5c \u2192 F`).\n\nWe also show the same results for the right derivative on the real line\n(see `measurable_deriv_within_Ici` and ``measurable_deriv_within_Ioi`), following the same\nproof strategy.\n\n## Implementation\n\nWe give a proof that avoids second-countability issues, by expressing the differentiability set\nas a function of open sets in the following way. Define `A (L, r, \u03b5)` to be the set of points\nwhere, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the\nlinear map `L`, up to `\u03b5 r`. It is an open set.\nLet also `B (L, r, s, \u03b5) = A (L, r, \u03b5) \u2229 A (L, s, \u03b5)`: we require that at two possibly different\nscales `r` and `s`, the function is well approximated by the linear map `L`. It is also open.\n\nWe claim that the differentiability set of `f` is exactly\n`D = \u22c2 \u03b5 > 0, \u22c3 \u03b4 > 0, \u22c2 r, s < \u03b4, \u22c3 L, B (L, r, s, \u03b5)`.\nIn other words, for any `\u03b5 > 0`, we require that there is a size `\u03b4` such that, for any two scales\nbelow this size, the function is well approximated by a linear map, common to the two scales.\n\nThe set `\u22c3 L, B (L, r, s, \u03b5)` is open, as a union of open sets. Converting the intersections and\nunions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the\ndifferentiability set is measurable.\n\nTo prove the claim, there are two inclusions. One is trivial: if the function is differentiable\nat `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the\ndifferentiability exactly says that the map is well approximated by `L`). This is proved in\n`mem_A_of_differentiable` and `differentiable_set_subset_D`.\n\nFor the other direction, the difficulty is that `L` in the union may depend on `\u03b5, r, s`. The key\npoint is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to\n`A (L, r, \u03b5)` and `A (L', r, \u03b5)`, then `L` and `L'` have to be close on a shell, and thus\n`\u2016L - L'\u2016` is bounded by `\u03b5` (see `norm_sub_le_of_mem_A`). Assume now `x \u2208 D`. If one has two maps\n`L` and `L'` such that `x` belongs to `A (L, r, \u03b5)` and to `A (L', r', \u03b5')`, one deduces that `L` is\nclose to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a\nlinear map `L\u2081` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `\u03b5` (it exists as\n`x` belongs to `D`). Take also `L\u2082` that approximates `f` around `x` both at scales `r'` and `s`\nw.r.t. `\u03b5'`. Then `L\u2081` is close to `L` (as they are close on a shell of radius `r`), and `L\u2082` is\nclose to `L\u2081` (as they are close on a shell of radius `s`), and `L'` is close to `L\u2082` (as they are\nclose on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed.\n\nIt follows that the different approximating linear maps that show up form a Cauchy sequence when\n`\u03b5` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`.\nWith the same kind of arguments, one checks that `f` is differentiable with derivative `f'`.\n\nTo show that the derivative itself is measurable, add in the definition of `B` and `D` a set\n`K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K`\nis exactly the set of points where `f` is differentiable with a derivative in `K`.\n\n## Tags\n\nderivative, measurable function, Borel \u03c3-algebra\n-/\n\nnoncomputable theory\n\nopen set metric asymptotics filter continuous_linear_map\nopen topological_space (second_countable_topology) measure_theory\nopen_locale topology\n\nnamespace continuous_linear_map\n\nvariables {\ud835\udd5c E F : Type*} [nontrivially_normed_field \ud835\udd5c]\n  [normed_add_comm_group E] [normed_space \ud835\udd5c E] [normed_add_comm_group F] [normed_space \ud835\udd5c F]\n\nlemma measurable_apply\u2082 [measurable_space E] [opens_measurable_space E]\n  [second_countable_topology E] [second_countable_topology (E \u2192L[\ud835\udd5c] F)]\n  [measurable_space F] [borel_space F] :\n  measurable (\u03bb p : (E \u2192L[\ud835\udd5c] F) \u00d7 E, p.1 p.2) :=\nis_bounded_bilinear_map_apply.continuous.measurable\n\nend continuous_linear_map\n\nsection fderiv\n\nvariables {\ud835\udd5c : Type*} [nontrivially_normed_field \ud835\udd5c]\nvariables {E : Type*} [normed_add_comm_group E] [normed_space \ud835\udd5c E]\nvariables {F : Type*} [normed_add_comm_group F] [normed_space \ud835\udd5c F]\nvariables {f : E \u2192 F} (K : set (E \u2192L[\ud835\udd5c] F))\n\nnamespace fderiv_measurable_aux\n\n/-- The set `A f L r \u03b5` is the set of points `x` around which the function `f` is well approximated\nat scale `r` by the linear map `L`, up to an error `\u03b5`. We tweak the definition to make sure that\nthis is an open set.-/\ndef A (f : E \u2192 F) (L : E \u2192L[\ud835\udd5c] F) (r \u03b5 : \u211d) : set E :=\n{x | \u2203 r' \u2208 Ioc (r/2) r, \u2200 y z \u2208 ball x r', \u2016f z - f y - L (z-y)\u2016 \u2264 \u03b5 * r}\n\n/-- The set `B f K r s \u03b5` is the set of points `x` around which there exists a continuous linear map\n`L` belonging to `K` (a given set of continuous linear maps) that approximates well the\nfunction `f` (up to an error `\u03b5`), simultaneously at scales `r` and `s`. -/\ndef B (f : E \u2192 F) (K : set (E \u2192L[\ud835\udd5c] F)) (r s \u03b5 : \u211d) : set E :=\n\u22c3 (L \u2208 K), (A f L r \u03b5) \u2229 (A f L s \u03b5)\n\n/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its\nmain use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,\nwith a derivative in `K`. -/\ndef D (f : E \u2192 F) (K : set (E \u2192L[\ud835\udd5c] F)) : set E :=\n\u22c2 (e : \u2115), \u22c3 (n : \u2115), \u22c2 (p \u2265 n) (q \u2265 n), B f K ((1/2) ^ p) ((1/2) ^ q) ((1/2) ^ e)\n\nlemma is_open_A (L : E \u2192L[\ud835\udd5c] F) (r \u03b5 : \u211d) : is_open (A f L r \u03b5) :=\nbegin\n  rw metric.is_open_iff,\n  rintros x \u27e8r', r'_mem, hr'\u27e9,\n  obtain \u27e8s, s_gt, s_lt\u27e9 : \u2203 (s : \u211d), r / 2 < s \u2227 s < r' := exists_between r'_mem.1,\n  have : s \u2208 Ioc (r/2) r := \u27e8s_gt, le_of_lt (s_lt.trans_le r'_mem.2)\u27e9,\n  refine \u27e8r' - s, by linarith, \u03bb x' hx', \u27e8s, this, _\u27e9\u27e9,\n  have B : ball x' s \u2286 ball x r' := ball_subset (le_of_lt hx'),\n  assume y hy z hz,\n  exact hr' y (B hy) z (B hz)\nend\n\nlemma is_open_B {K : set (E \u2192L[\ud835\udd5c] F)} {r s \u03b5 : \u211d} : is_open (B f K r s \u03b5) :=\nby simp [B, is_open_Union, is_open.inter, is_open_A]\n\nlemma A_mono (L : E \u2192L[\ud835\udd5c] F) (r : \u211d) {\u03b5 \u03b4 : \u211d} (h : \u03b5 \u2264 \u03b4) :\n  A f L r \u03b5 \u2286 A f L r \u03b4 :=\nbegin\n  rintros x \u27e8r', r'r, hr'\u27e9,\n  refine \u27e8r', r'r, \u03bb y hy z hz, (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h _)\u27e9,\n  linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x],\nend\n\n\n\nlemma mem_A_of_differentiable {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {x : E} (hx : differentiable_at \ud835\udd5c f x) :\n  \u2203 R > 0, \u2200 r \u2208 Ioo (0 : \u211d) R, x \u2208 A f (fderiv \ud835\udd5c f x) r \u03b5 :=\nbegin\n  have := hx.has_fderiv_at,\n  simp only [has_fderiv_at, has_fderiv_at_filter, is_o_iff] at this,\n  rcases eventually_nhds_iff_ball.1 (this (half_pos h\u03b5)) with \u27e8R, R_pos, hR\u27e9,\n  refine \u27e8R, R_pos, \u03bb r hr, _\u27e9,\n  have : r \u2208 Ioc (r/2) r := \u27e8half_lt_self hr.1, le_rfl\u27e9,\n  refine \u27e8r, this, \u03bb y hy z hz, _\u27e9,\n  calc  \u2016f z - f y - (fderiv \ud835\udd5c f x) (z - y)\u2016\n      = \u2016(f z - f x - (fderiv \ud835\udd5c f x) (z - x)) - (f y - f x - (fderiv \ud835\udd5c f x) (y - x))\u2016 :\n    by { congr' 1, simp only [continuous_linear_map.map_sub], abel }\n  ... \u2264 \u2016(f z - f x - (fderiv \ud835\udd5c f x) (z - x))\u2016 + \u2016f y - f x - (fderiv \ud835\udd5c f x) (y - x)\u2016 :\n    norm_sub_le _ _\n  ... \u2264 \u03b5 / 2 * \u2016z - x\u2016 + \u03b5 / 2 * \u2016y - x\u2016 :\n    add_le_add (hR _ (lt_trans (mem_ball.1 hz) hr.2)) (hR _ (lt_trans (mem_ball.1 hy) hr.2))\n  ... \u2264 \u03b5 / 2 * r + \u03b5 / 2 * r :\n    add_le_add\n      (mul_le_mul_of_nonneg_left (le_of_lt (mem_ball_iff_norm.1 hz)) (le_of_lt (half_pos h\u03b5)))\n      (mul_le_mul_of_nonneg_left (le_of_lt (mem_ball_iff_norm.1 hy)) (le_of_lt (half_pos h\u03b5)))\n  ... = \u03b5 * r : by ring\nend\n\nlemma norm_sub_le_of_mem_A {c : \ud835\udd5c} (hc : 1 < \u2016c\u2016)\n  {r \u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) (hr : 0 < r) {x : E} {L\u2081 L\u2082 : E \u2192L[\ud835\udd5c] F}\n  (h\u2081 : x \u2208 A f L\u2081 r \u03b5) (h\u2082 : x \u2208 A f L\u2082 r \u03b5) : \u2016L\u2081 - L\u2082\u2016 \u2264 4 * \u2016c\u2016 * \u03b5 :=\nbegin\n  have : 0 \u2264 4 * \u2016c\u2016 * \u03b5 :=\n    mul_nonneg (mul_nonneg (by norm_num : (0 : \u211d) \u2264 4) (norm_nonneg _)) h\u03b5.le,\n  refine op_norm_le_of_shell (half_pos hr) this hc _,\n  assume y ley ylt,\n  rw [div_div,\n      div_le_iff' (mul_pos (by norm_num : (0 : \u211d) < 2) (zero_lt_one.trans hc))] at ley,\n  calc \u2016(L\u2081 - L\u2082) y\u2016\n        = \u2016(f (x + y) - f x - L\u2082 ((x + y) - x)) - (f (x + y) - f x - L\u2081 ((x + y) - x))\u2016 : by simp\n    ... \u2264 \u2016(f (x + y) - f x - L\u2082 ((x + y) - x))\u2016 + \u2016(f (x + y) - f x - L\u2081 ((x + y) - x))\u2016 :\n      norm_sub_le _ _\n    ... \u2264 \u03b5 * r + \u03b5 * r :\n      begin\n        apply add_le_add,\n        { apply le_of_mem_A h\u2082,\n          { simp only [le_of_lt (half_pos hr), mem_closed_ball, dist_self] },\n          { simp only [dist_eq_norm, add_sub_cancel', mem_closed_ball, ylt.le], } },\n        { apply le_of_mem_A h\u2081,\n          { simp only [le_of_lt (half_pos hr), mem_closed_ball, dist_self] },\n          { simp only [dist_eq_norm, add_sub_cancel', mem_closed_ball, ylt.le] } },\n      end\n    ... = 2 * \u03b5 * r : by ring\n    ... \u2264 2 * \u03b5 * (2 * \u2016c\u2016 * \u2016y\u2016) : mul_le_mul_of_nonneg_left ley (mul_nonneg (by norm_num) h\u03b5.le)\n    ... = 4 * \u2016c\u2016 * \u03b5 * \u2016y\u2016 : by ring\nend\n\n/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/\nlemma differentiable_set_subset_D : {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} \u2286 D f K :=\nbegin\n  assume x hx,\n  rw [D, mem_Inter],\n  assume e,\n  have : (0 : \u211d) < (1/2) ^ e := pow_pos (by norm_num) _,\n  rcases mem_A_of_differentiable this hx.1 with \u27e8R, R_pos, hR\u27e9,\n  obtain \u27e8n, hn\u27e9 : \u2203 (n : \u2115), (1/2) ^ n < R :=\n    exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : \u211d)/2 < 1),\n  simp only [mem_Union, mem_Inter, B, mem_inter_iff],\n  refine \u27e8n, \u03bb p hp q hq, \u27e8fderiv \ud835\udd5c f x, hx.2, \u27e8_, _\u27e9\u27e9\u27e9;\n  { refine hR _ \u27e8pow_pos (by norm_num) _, lt_of_le_of_lt _ hn\u27e9,\n    exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) }\nend\n\n/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/\nlemma D_subset_differentiable_set {K : set (E \u2192L[\ud835\udd5c] F)} (hK : is_complete K) :\n  D f K \u2286 {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} :=\nbegin\n  have P : \u2200 {n : \u2115}, (0 : \u211d) < (1/2) ^ n := pow_pos (by norm_num),\n  rcases normed_field.exists_one_lt_norm \ud835\udd5c with \u27e8c, hc\u27e9,\n  have cpos : 0 < \u2016c\u2016 := lt_trans zero_lt_one hc,\n  assume x hx,\n  have : \u2200 (e : \u2115), \u2203 (n : \u2115), \u2200 p q, n \u2264 p \u2192 n \u2264 q \u2192 \u2203 L \u2208 K,\n    x \u2208 A f L ((1/2) ^ p) ((1/2) ^ e) \u2229 A f L ((1/2) ^ q) ((1/2) ^ e),\n  { assume e,\n    have := mem_Inter.1 hx e,\n    rcases mem_Union.1 this with \u27e8n, hn\u27e9,\n    refine \u27e8n, \u03bb p q hp hq, _\u27e9,\n    simp only [mem_Inter, ge_iff_le] at hn,\n    rcases mem_Union.1 (hn p hp q hq) with \u27e8L, hL\u27e9,\n    exact \u27e8L, mem_Union.1 hL\u27e9, },\n  /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`\n  such that, for `p, q \u2265 n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and\n  `2 ^ (-q)`, with an error `2 ^ (-e)`. -/\n  choose! n L hn using this,\n  /- All the operators `L e p q` that show up are close to each other. To prove this, we argue\n    that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at\n    scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale\n    `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale\n    `2 ^ (- p')`. -/\n  have M : \u2200 e p q e' p' q', n e \u2264 p \u2192 n e \u2264 q \u2192 n e' \u2264 p' \u2192 n e' \u2264 q' \u2192 e \u2264 e' \u2192\n    \u2016L e p q - L e' p' q'\u2016 \u2264 12 * \u2016c\u2016 * (1/2) ^ e,\n  { assume e p q e' p' q' hp hq hp' hq' he',\n    let r := max (n e) (n e'),\n    have I : ((1:\u211d)/2)^e' \u2264 (1/2)^e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he',\n    have J1 : \u2016L e p q - L e p r\u2016 \u2264 4 * \u2016c\u2016 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p q) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p q hp hq).2.1,\n      have I2 : x \u2208 A f (L e p r) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.1,\n      exact norm_sub_le_of_mem_A hc P P I1 I2 },\n    have J2 : \u2016L e p r - L e' p' r\u2016 \u2264 4 * \u2016c\u2016 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p r) ((1 / 2) ^ r) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.2,\n      have I2 : x \u2208 A f (L e' p' r) ((1 / 2) ^ r) ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.2,\n      exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2) },\n    have J3 : \u2016L e' p' r - L e' p' q'\u2016 \u2264 4 * \u2016c\u2016 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e' p' r) ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.1,\n      have I2 : x \u2208 A f (L e' p' q') ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' q' hp' hq').2.1,\n      exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2) },\n    calc \u2016L e p q - L e' p' q'\u2016\n          = \u2016(L e p q - L e p r) + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')\u2016 :\n        by { congr' 1, abel }\n      ... \u2264 \u2016L e p q - L e p r\u2016 + \u2016L e p r - L e' p' r\u2016 + \u2016L e' p' r - L e' p' q'\u2016 :\n        le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)\n      ... \u2264 4 * \u2016c\u2016 * (1/2)^e + 4 * \u2016c\u2016 * (1/2)^e + 4 * \u2016c\u2016 * (1/2)^e :\n        by apply_rules [add_le_add]\n      ... = 12 * \u2016c\u2016 * (1/2)^e : by ring },\n  /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this\n  is a Cauchy sequence. -/\n  let L0 : \u2115 \u2192 (E \u2192L[\ud835\udd5c] F) := \u03bb e, L e (n e) (n e),\n  have : cauchy_seq L0,\n  { rw metric.cauchy_seq_iff',\n    assume \u03b5 \u03b5pos,\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1/2) ^ e < \u03b5 / (12 * \u2016c\u2016) :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos (mul_pos (by norm_num) cpos)) (by norm_num),\n    refine \u27e8e, \u03bb e' he', _\u27e9,\n    rw [dist_comm, dist_eq_norm],\n    calc \u2016L0 e - L0 e'\u2016\n          \u2264 12 * \u2016c\u2016 * (1/2)^e : M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'\n      ... < 12 * \u2016c\u2016 * (\u03b5 / (12 * \u2016c\u2016)) :\n        mul_lt_mul' le_rfl he (le_of_lt P) (mul_pos (by norm_num) cpos)\n      ... = \u03b5 : by { field_simp [(by norm_num : (12 : \u211d) \u2260 0), ne_of_gt cpos], ring } },\n  /- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.-/\n  obtain \u27e8f', f'K, hf'\u27e9 : \u2203 f' \u2208 K, tendsto L0 at_top (\ud835\udcdd f') :=\n    cauchy_seq_tendsto_of_is_complete hK (\u03bb e, (hn e (n e) (n e) le_rfl le_rfl).1) this,\n  have Lf' : \u2200 e p, n e \u2264 p \u2192 \u2016L e (n e) p - f'\u2016 \u2264 12 * \u2016c\u2016 * (1/2)^e,\n  { assume e p hp,\n    apply le_of_tendsto (tendsto_const_nhds.sub hf').norm,\n    rw eventually_at_top,\n    exact \u27e8e, \u03bb e' he', M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'\u27e9 },\n  /- Let us show that `f` has derivative `f'` at `x`. -/\n  have : has_fderiv_at f f' x,\n  { simp only [has_fderiv_at_iff_is_o_nhds_zero, is_o_iff],\n    /- to get an approximation with a precision `\u03b5`, we will replace `f` with `L e (n e) m` for\n    some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,\n    this makes it possible to cover all scales, and thus to obtain a good linear approximation in\n    the whole ball of radius `(1/2)^(n e)`. -/\n    assume \u03b5 \u03b5pos,\n    have pos : 0 < 4 + 12 * \u2016c\u2016 :=\n      add_pos_of_pos_of_nonneg (by norm_num) (mul_nonneg (by norm_num) (norm_nonneg _)),\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1 / 2) ^ e < \u03b5 / (4 + 12 * \u2016c\u2016) :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos pos) (by norm_num),\n    rw eventually_nhds_iff_ball,\n    refine \u27e8(1/2) ^ (n e + 1), P, \u03bb y hy, _\u27e9,\n    -- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale\n    -- `k` where `k` is chosen with `\u2016y\u2016 \u223c 2 ^ (-k)`.\n    by_cases y_pos : y = 0, {simp [y_pos] },\n    have yzero : 0 < \u2016y\u2016 := norm_pos_iff.mpr y_pos,\n    have y_lt : \u2016y\u2016 < (1/2) ^ (n e + 1), by simpa using mem_ball_iff_norm.1 hy,\n    have yone : \u2016y\u2016 \u2264 1 :=\n      le_trans (y_lt.le) (pow_le_one _ (by norm_num) (by norm_num)),\n    -- define the scale `k`.\n    obtain \u27e8k, hk, h'k\u27e9 : \u2203 (k : \u2115), (1/2) ^ (k + 1) < \u2016y\u2016 \u2227 \u2016y\u2016 \u2264 (1/2) ^ k :=\n      exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : \u211d) < 1/2)\n      (by norm_num : (1 : \u211d)/2 < 1),\n    -- the scale is large enough (as `y` is small enough)\n    have k_gt : n e < k,\n    { have : ((1:\u211d)/2) ^ (k + 1) < (1/2) ^ (n e + 1) := lt_trans hk y_lt,\n      rw pow_lt_pow_iff_of_lt_one (by norm_num : (0 : \u211d) < 1/2) (by norm_num) at this,\n      linarith },\n    set m := k - 1 with hl,\n    have m_ge : n e \u2264 m := nat.le_pred_of_lt k_gt,\n    have km : k = m + 1 := (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm,\n    rw km at hk h'k,\n    -- `f` is well approximated by `L e (n e) k` at the relevant scale\n    -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).\n    have J1 : \u2016f (x + y) - f x - L e (n e) m ((x + y) - x)\u2016 \u2264 (1/2) ^ e * (1/2) ^ m,\n    { apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2,\n      { simp only [mem_closed_ball, dist_self],\n        exact div_nonneg (le_of_lt P) (zero_le_two) },\n      { simpa only [dist_eq_norm, add_sub_cancel', mem_closed_ball, pow_succ', mul_one_div]\n          using h'k } },\n    have J2 : \u2016f (x + y) - f x - L e (n e) m y\u2016 \u2264 4 * (1/2) ^ e * \u2016y\u2016 := calc\n      \u2016f (x + y) - f x - L e (n e) m y\u2016 \u2264 (1/2) ^ e * (1/2) ^ m :\n        by simpa only [add_sub_cancel'] using J1\n      ... = 4 * (1/2) ^ e * (1/2) ^ (m + 2) : by { field_simp, ring_exp }\n      ... \u2264 4 * (1/2) ^ e * \u2016y\u2016 :\n        mul_le_mul_of_nonneg_left (le_of_lt hk) (mul_nonneg (by norm_num) (le_of_lt P)),\n    -- use the previous estimates to see that `f (x + y) - f x - f' y` is small.\n    calc \u2016f (x + y) - f x - f' y\u2016\n        = \u2016(f (x + y) - f x - L e (n e) m y) + (L e (n e) m - f') y\u2016 :\n      congr_arg _ (by simp)\n    ... \u2264 4 * (1/2) ^ e * \u2016y\u2016 + 12 * \u2016c\u2016 * (1/2) ^ e * \u2016y\u2016 :\n      norm_add_le_of_le J2\n        ((le_op_norm _ _).trans (mul_le_mul_of_nonneg_right (Lf' _ _ m_ge) (norm_nonneg _)))\n    ... = (4 + 12 * \u2016c\u2016) * \u2016y\u2016 * (1/2) ^ e : by ring\n    ... \u2264 (4 + 12 * \u2016c\u2016) * \u2016y\u2016 * (\u03b5 / (4 + 12 * \u2016c\u2016)) :\n      mul_le_mul_of_nonneg_left he.le\n        (mul_nonneg (add_nonneg (by norm_num) (mul_nonneg (by norm_num) (norm_nonneg _)))\n          (norm_nonneg _))\n    ... = \u03b5 * \u2016y\u2016 : by { field_simp [ne_of_gt pos], ring } },\n  rw \u2190 this.fderiv at f'K,\n  exact \u27e8this.differentiable_at, f'K\u27e9\nend\n\ntheorem differentiable_set_eq_D (hK : is_complete K) :\n  {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} = D f K :=\nsubset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)\n\nend fderiv_measurable_aux\n\nopen fderiv_measurable_aux\n\nvariables [measurable_space E] [opens_measurable_space E]\nvariables (\ud835\udd5c f)\n\n/-- The set of differentiability points of a function, with derivative in a given complete set,\nis Borel-measurable. -/\ntheorem measurable_set_of_differentiable_at_of_is_complete\n  {K : set (E \u2192L[\ud835\udd5c] F)} (hK : is_complete K) :\n  measurable_set {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 K} :=\nby simp [differentiable_set_eq_D K hK, D, is_open_B.measurable_set, measurable_set.Inter,\n         measurable_set.Union]\n\nvariable [complete_space F]\n\n/-- The set of differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurable_set_of_differentiable_at :\n  measurable_set {x | differentiable_at \ud835\udd5c f x} :=\nbegin\n  have : is_complete (univ : set (E \u2192L[\ud835\udd5c] F)) := complete_univ,\n  convert measurable_set_of_differentiable_at_of_is_complete \ud835\udd5c f this,\n  simp\nend\n\n@[measurability] lemma measurable_fderiv : measurable (fderiv \ud835\udd5c f) :=\nbegin\n  refine measurable_of_is_closed (\u03bb s hs, _),\n  have : fderiv \ud835\udd5c f \u207b\u00b9' s = {x | differentiable_at \ud835\udd5c f x \u2227 fderiv \ud835\udd5c f x \u2208 s} \u222a\n    ({x | \u00acdifferentiable_at \ud835\udd5c f x} \u2229 {x | (0 : E \u2192L[\ud835\udd5c] F) \u2208 s}) :=\n    set.ext (\u03bb x, mem_preimage.trans fderiv_mem_iff),\n  rw this,\n  exact (measurable_set_of_differentiable_at_of_is_complete _ _ hs.is_complete).union\n    ((measurable_set_of_differentiable_at _ _).compl.inter (measurable_set.const _))\nend\n\n@[measurability] lemma measurable_fderiv_apply_const [measurable_space F] [borel_space F] (y : E) :\n  measurable (\u03bb x, fderiv \ud835\udd5c f x y) :=\n(continuous_linear_map.measurable_apply y).comp (measurable_fderiv \ud835\udd5c f)\n\nvariable {\ud835\udd5c}\n\n@[measurability] lemma measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [measurable_space F] [borel_space F] (f : \ud835\udd5c \u2192 F) : measurable (deriv f) :=\nby simpa only [fderiv_deriv] using measurable_fderiv_apply_const \ud835\udd5c f 1\n\nlemma strongly_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [second_countable_topology F] (f : \ud835\udd5c \u2192 F) :\n  strongly_measurable (deriv f) :=\nby { borelize F, exact (measurable_deriv f).strongly_measurable }\n\nlemma ae_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c] [measurable_space F]\n  [borel_space F] (f : \ud835\udd5c \u2192 F) (\u03bc : measure \ud835\udd5c) : ae_measurable (deriv f) \u03bc :=\n(measurable_deriv f).ae_measurable\n\nlemma ae_strongly_measurable_deriv [measurable_space \ud835\udd5c] [opens_measurable_space \ud835\udd5c]\n  [second_countable_topology F] (f : \ud835\udd5c \u2192 F) (\u03bc : measure \ud835\udd5c) :\n  ae_strongly_measurable (deriv f) \u03bc :=\n(strongly_measurable_deriv f).ae_strongly_measurable\n\nend fderiv\n\nsection right_deriv\n\nvariables {F : Type*} [normed_add_comm_group F] [normed_space \u211d F]\nvariables {f : \u211d \u2192 F} (K : set F)\n\nnamespace right_deriv_measurable_aux\n\n/-- The set `A f L r \u03b5` is the set of points `x` around which the function `f` is well approximated\nat scale `r` by the linear map `h \u21a6 h \u2022 L`, up to an error `\u03b5`. We tweak the definition to\nmake sure that this is open on the right. -/\ndef A (f : \u211d \u2192 F) (L : F) (r \u03b5 : \u211d) : set \u211d :=\n{x | \u2203 r' \u2208 Ioc (r/2) r, \u2200 y z \u2208 Icc x (x + r'), \u2016f z - f y - (z-y) \u2022 L\u2016 \u2264 \u03b5 * r}\n\n/-- The set `B f K r s \u03b5` is the set of points `x` around which there exists a vector\n`L` belonging to `K` (a given set of vectors) such that `h \u2022 L` approximates well `f (x + h)`\n(up to an error `\u03b5`), simultaneously at scales `r` and `s`. -/\ndef B (f : \u211d \u2192 F) (K : set F) (r s \u03b5 : \u211d) : set \u211d :=\n\u22c3 (L \u2208 K), (A f L r \u03b5) \u2229 (A f L s \u03b5)\n\n/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its\nmain use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,\nwith a derivative in `K`. -/\ndef D (f : \u211d \u2192 F) (K : set F) : set \u211d :=\n\u22c2 (e : \u2115), \u22c3 (n : \u2115), \u22c2 (p \u2265 n) (q \u2265 n), B f K ((1/2) ^ p) ((1/2) ^ q) ((1/2) ^ e)\n\nlemma A_mem_nhds_within_Ioi {L : F} {r \u03b5 x : \u211d} (hx : x \u2208 A f L r \u03b5) :\n  A f L r \u03b5 \u2208 \ud835\udcdd[>] x :=\nbegin\n  rcases hx with \u27e8r', rr', hr'\u27e9,\n  rw mem_nhds_within_Ioi_iff_exists_Ioo_subset,\n  obtain \u27e8s, s_gt, s_lt\u27e9 : \u2203 (s : \u211d), r / 2 < s \u2227 s < r' := exists_between rr'.1,\n  have : s \u2208 Ioc (r/2) r := \u27e8s_gt, le_of_lt (s_lt.trans_le rr'.2)\u27e9,\n  refine \u27e8x + r' - s, by { simp only [mem_Ioi], linarith }, \u03bb x' hx', \u27e8s, this, _\u27e9\u27e9,\n  have A : Icc x' (x' + s) \u2286 Icc x (x + r'),\n  { apply Icc_subset_Icc hx'.1.le,\n    linarith [hx'.2] },\n  assume y hy z hz,\n  exact hr' y (A hy) z (A hz)\nend\n\nlemma B_mem_nhds_within_Ioi {K : set F} {r s \u03b5 x : \u211d} (hx : x \u2208 B f K r s \u03b5) :\n  B f K r s \u03b5 \u2208 \ud835\udcdd[>] x :=\nbegin\n  obtain \u27e8L, LK, hL\u2081, hL\u2082\u27e9 : \u2203 (L : F), L \u2208 K \u2227 x \u2208 A f L r \u03b5 \u2227 x \u2208 A f L s \u03b5,\n    by simpa only [B, mem_Union, mem_inter_iff, exists_prop] using hx,\n  filter_upwards [A_mem_nhds_within_Ioi hL\u2081, A_mem_nhds_within_Ioi hL\u2082] with y hy\u2081 hy\u2082,\n  simp only [B, mem_Union, mem_inter_iff, exists_prop],\n  exact \u27e8L, LK, hy\u2081, hy\u2082\u27e9\nend\n\nlemma measurable_set_B {K : set F} {r s \u03b5 : \u211d} : measurable_set (B f K r s \u03b5) :=\nmeasurable_set_of_mem_nhds_within_Ioi (\u03bb x hx, B_mem_nhds_within_Ioi hx)\n\nlemma A_mono (L : F) (r : \u211d) {\u03b5 \u03b4 : \u211d} (h : \u03b5 \u2264 \u03b4) :\n  A f L r \u03b5 \u2286 A f L r \u03b4 :=\nbegin\n  rintros x \u27e8r', r'r, hr'\u27e9,\n  refine \u27e8r', r'r, \u03bb y hy z hz, (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h _)\u27e9,\n  linarith [hy.1, hy.2, r'r.2],\nend\n\nlemma le_of_mem_A {r \u03b5 : \u211d} {L : F} {x : \u211d} (hx : x \u2208 A f L r \u03b5)\n  {y z : \u211d} (hy : y \u2208 Icc x (x + r/2)) (hz : z \u2208 Icc x (x + r/2)) :\n  \u2016f z - f y - (z-y) \u2022 L\u2016 \u2264 \u03b5 * r :=\nbegin\n  rcases hx with \u27e8r', r'mem, hr'\u27e9,\n  have A : x + r / 2 \u2264 x + r', by linarith [r'mem.1],\n  exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz),\nend\n\nlemma mem_A_of_differentiable {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) {x : \u211d}\n  (hx : differentiable_within_at \u211d f (Ici x) x) :\n  \u2203 R > 0, \u2200 r \u2208 Ioo (0 : \u211d) R, x \u2208 A f (deriv_within f (Ici x) x) r \u03b5 :=\nbegin\n  have := hx.has_deriv_within_at,\n  simp_rw [has_deriv_within_at_iff_is_o, is_o_iff] at this,\n  rcases mem_nhds_within_Ici_iff_exists_Ico_subset.1 (this (half_pos h\u03b5)) with \u27e8m, xm, hm\u27e9,\n  refine \u27e8m - x, by linarith [show x < m, from xm], \u03bb r hr, _\u27e9,\n  have : r \u2208 Ioc (r/2) r := \u27e8half_lt_self hr.1, le_rfl\u27e9,\n  refine \u27e8r, this, \u03bb y hy z hz, _\u27e9,\n  calc  \u2016f z - f y - (z - y) \u2022 deriv_within f (Ici x) x\u2016\n      = \u2016(f z - f x - (z - x) \u2022 deriv_within f (Ici x) x)\n           - (f y - f x - (y - x) \u2022 deriv_within f (Ici x) x)\u2016 :\n    by { congr' 1, simp only [sub_smul], abel }\n  ... \u2264 \u2016f z - f x - (z - x) \u2022 deriv_within f (Ici x) x\u2016\n         + \u2016f y - f x - (y - x) \u2022 deriv_within f (Ici x) x\u2016 :\n    norm_sub_le _ _\n  ... \u2264 \u03b5 / 2 * \u2016z - x\u2016 + \u03b5 / 2 * \u2016y - x\u2016 :\n    add_le_add (hm \u27e8hz.1, hz.2.trans_lt (by linarith [hr.2])\u27e9)\n               (hm \u27e8hy.1, hy.2.trans_lt (by linarith [hr.2])\u27e9)\n  ... \u2264 \u03b5 / 2 * r + \u03b5 / 2 * r :\n  begin\n    apply add_le_add,\n    { apply mul_le_mul_of_nonneg_left _ (le_of_lt (half_pos h\u03b5)),\n      rw [real.norm_of_nonneg];\n      linarith [hz.1, hz.2] },\n    { apply mul_le_mul_of_nonneg_left _ (le_of_lt (half_pos h\u03b5)),\n      rw [real.norm_of_nonneg];\n      linarith [hy.1, hy.2] },\n   end\n  ... = \u03b5 * r : by ring\nend\n\nlemma norm_sub_le_of_mem_A\n  {r x : \u211d} (hr : 0 < r) (\u03b5 : \u211d) {L\u2081 L\u2082 : F}\n  (h\u2081 : x \u2208 A f L\u2081 r \u03b5) (h\u2082 : x \u2208 A f L\u2082 r \u03b5) : \u2016L\u2081 - L\u2082\u2016 \u2264 4 * \u03b5 :=\nbegin\n  suffices H : \u2016(r/2) \u2022 (L\u2081 - L\u2082)\u2016 \u2264 (r / 2) * (4 * \u03b5),\n    by rwa [norm_smul, real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H,\n  calc\n  \u2016(r/2) \u2022 (L\u2081 - L\u2082)\u2016\n      = \u2016(f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2082) - (f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2081)\u2016 :\n    by simp [smul_sub]\n  ... \u2264 \u2016f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2082\u2016 + \u2016f (x + r/2) - f x - (x + r/2 - x) \u2022 L\u2081\u2016 :\n    norm_sub_le _ _\n  ... \u2264 \u03b5 * r + \u03b5 * r :\n    begin\n      apply add_le_add,\n      { apply le_of_mem_A h\u2082;\n        simp [(half_pos hr).le] },\n      { apply le_of_mem_A h\u2081;\n        simp [(half_pos hr).le] },\n    end\n  ... = (r / 2) * (4 * \u03b5) : by ring\nend\n\n/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/\nlemma differentiable_set_subset_D :\n  {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} \u2286 D f K :=\nbegin\n  assume x hx,\n  rw [D, mem_Inter],\n  assume e,\n  have : (0 : \u211d) < (1/2) ^ e := pow_pos (by norm_num) _,\n  rcases mem_A_of_differentiable this hx.1 with \u27e8R, R_pos, hR\u27e9,\n  obtain \u27e8n, hn\u27e9 : \u2203 (n : \u2115), (1/2) ^ n < R :=\n    exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : \u211d)/2 < 1),\n  simp only [mem_Union, mem_Inter, B, mem_inter_iff],\n  refine \u27e8n, \u03bb p hp q hq, \u27e8deriv_within f (Ici x) x, hx.2, \u27e8_, _\u27e9\u27e9\u27e9;\n  { refine hR _ \u27e8pow_pos (by norm_num) _, lt_of_le_of_lt _ hn\u27e9,\n    exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) }\nend\n\n/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/\nlemma D_subset_differentiable_set {K : set F} (hK : is_complete K) :\n  D f K \u2286 {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} :=\nbegin\n  have P : \u2200 {n : \u2115}, (0 : \u211d) < (1/2) ^ n := pow_pos (by norm_num),\n  assume x hx,\n  have : \u2200 (e : \u2115), \u2203 (n : \u2115), \u2200 p q, n \u2264 p \u2192 n \u2264 q \u2192 \u2203 L \u2208 K,\n    x \u2208 A f L ((1/2) ^ p) ((1/2) ^ e) \u2229 A f L ((1/2) ^ q) ((1/2) ^ e),\n  { assume e,\n    have := mem_Inter.1 hx e,\n    rcases mem_Union.1 this with \u27e8n, hn\u27e9,\n    refine \u27e8n, \u03bb p q hp hq, _\u27e9,\n    simp only [mem_Inter, ge_iff_le] at hn,\n    rcases mem_Union.1 (hn p hp q hq) with \u27e8L, hL\u27e9,\n    exact \u27e8L, mem_Union.1 hL\u27e9, },\n  /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`\n  such that, for `p, q \u2265 n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and\n  `2 ^ (-q)`, with an error `2 ^ (-e)`. -/\n  choose! n L hn using this,\n  /- All the operators `L e p q` that show up are close to each other. To prove this, we argue\n    that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at\n    scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale\n    `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale\n    `2 ^ (- p')`. -/\n  have M : \u2200 e p q e' p' q', n e \u2264 p \u2192 n e \u2264 q \u2192 n e' \u2264 p' \u2192 n e' \u2264 q' \u2192 e \u2264 e' \u2192\n    \u2016L e p q - L e' p' q'\u2016 \u2264 12 * (1/2) ^ e,\n  { assume e p q e' p' q' hp hq hp' hq' he',\n    let r := max (n e) (n e'),\n    have I : ((1:\u211d)/2)^e' \u2264 (1/2)^e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he',\n    have J1 : \u2016L e p q - L e p r\u2016 \u2264 4 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p q) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p q hp hq).2.1,\n      have I2 : x \u2208 A f (L e p r) ((1 / 2) ^ p) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.1,\n      exact norm_sub_le_of_mem_A P _ I1 I2 },\n    have J2 : \u2016L e p r - L e' p' r\u2016 \u2264 4 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e p r) ((1 / 2) ^ r) ((1/2)^e) :=\n        (hn e p r hp (le_max_left _ _)).2.2,\n      have I2 : x \u2208 A f (L e' p' r) ((1 / 2) ^ r) ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.2,\n      exact norm_sub_le_of_mem_A P _ I1 (A_mono _ _ I I2) },\n    have J3 : \u2016L e' p' r - L e' p' q'\u2016 \u2264 4 * (1/2)^e,\n    { have I1 : x \u2208 A f (L e' p' r) ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' r hp' (le_max_right _ _)).2.1,\n      have I2 : x \u2208 A f (L e' p' q') ((1 / 2) ^ p') ((1/2)^e') :=\n        (hn e' p' q' hp' hq').2.1,\n      exact norm_sub_le_of_mem_A P _ (A_mono _ _ I I1) (A_mono _ _ I I2) },\n    calc \u2016L e p q - L e' p' q'\u2016\n          = \u2016(L e p q - L e p r) + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')\u2016 :\n        by { congr' 1, abel }\n      ... \u2264 \u2016L e p q - L e p r\u2016 + \u2016L e p r - L e' p' r\u2016 + \u2016L e' p' r - L e' p' q'\u2016 :\n        le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)\n      ... \u2264 4 * (1/2)^e + 4 * (1/2)^e + 4 * (1/2)^e :\n        by apply_rules [add_le_add]\n      ... = 12 * (1/2)^e : by ring },\n  /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this\n  is a Cauchy sequence. -/\n  let L0 : \u2115 \u2192 F := \u03bb e, L e (n e) (n e),\n  have : cauchy_seq L0,\n  { rw metric.cauchy_seq_iff',\n    assume \u03b5 \u03b5pos,\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1/2) ^ e < \u03b5 / 12 :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos (by norm_num)) (by norm_num),\n    refine \u27e8e, \u03bb e' he', _\u27e9,\n    rw [dist_comm, dist_eq_norm],\n    calc \u2016L0 e - L0 e'\u2016\n          \u2264 12 * (1/2)^e : M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'\n      ... < 12 * (\u03b5 / 12) :\n        mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num)\n      ... = \u03b5 : by { field_simp [(by norm_num : (12 : \u211d) \u2260 0)], ring } },\n  /- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.-/\n  obtain \u27e8f', f'K, hf'\u27e9 : \u2203 f' \u2208 K, tendsto L0 at_top (\ud835\udcdd f') :=\n    cauchy_seq_tendsto_of_is_complete hK (\u03bb e, (hn e (n e) (n e) le_rfl le_rfl).1) this,\n  have Lf' : \u2200 e p, n e \u2264 p \u2192 \u2016L e (n e) p - f'\u2016 \u2264 12 * (1/2)^e,\n  { assume e p hp,\n    apply le_of_tendsto (tendsto_const_nhds.sub hf').norm,\n    rw eventually_at_top,\n    exact \u27e8e, \u03bb e' he', M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'\u27e9 },\n  /- Let us show that `f` has right derivative `f'` at `x`. -/\n  have : has_deriv_within_at f f' (Ici x) x,\n  { simp only [has_deriv_within_at_iff_is_o, is_o_iff],\n    /- to get an approximation with a precision `\u03b5`, we will replace `f` with `L e (n e) m` for\n    some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,\n    this makes it possible to cover all scales, and thus to obtain a good linear approximation in\n    the whole interval of length `(1/2)^(n e)`. -/\n    assume \u03b5 \u03b5pos,\n    obtain \u27e8e, he\u27e9 : \u2203 (e : \u2115), (1 / 2) ^ e < \u03b5 / 16 :=\n      exists_pow_lt_of_lt_one (div_pos \u03b5pos (by norm_num)) (by norm_num),\n    have xmem : x \u2208 Ico x (x + (1/2)^(n e + 1)),\n      by simp only [one_div, left_mem_Ico, lt_add_iff_pos_right, inv_pos, pow_pos, zero_lt_bit0,\n        zero_lt_one],\n    filter_upwards [Icc_mem_nhds_within_Ici xmem] with y hy,\n    -- We need to show that `f y - f x - f' (y - x)` is small. For this, we will work at scale\n    -- `k` where `k` is chosen with `\u2016y - x\u2016 \u223c 2 ^ (-k)`.\n    rcases eq_or_lt_of_le hy.1 with rfl|xy,\n    { simp only [sub_self, zero_smul, norm_zero, mul_zero]},\n    have yzero : 0 < y - x := sub_pos.2 xy,\n    have y_le : y - x \u2264 (1/2) ^ (n e + 1), by linarith [hy.2],\n    have yone : y - x \u2264 1 := le_trans y_le (pow_le_one _ (by norm_num) (by norm_num)),\n    -- define the scale `k`.\n    obtain \u27e8k, hk, h'k\u27e9 : \u2203 (k : \u2115), (1/2) ^ (k + 1) < y - x \u2227 y - x \u2264 (1/2) ^ k :=\n      exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : \u211d) < 1/2)\n      (by norm_num : (1 : \u211d)/2 < 1),\n    -- the scale is large enough (as `y - x` is small enough)\n    have k_gt : n e < k,\n    { have : ((1:\u211d)/2) ^ (k + 1) < (1/2) ^ (n e + 1) := lt_of_lt_of_le hk y_le,\n      rw pow_lt_pow_iff_of_lt_one (by norm_num : (0 : \u211d) < 1/2) (by norm_num) at this,\n      linarith },\n    set m := k - 1 with hl,\n    have m_ge : n e \u2264 m := nat.le_pred_of_lt k_gt,\n    have km : k = m + 1 := (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm,\n    rw km at hk h'k,\n    -- `f` is well approximated by `L e (n e) k` at the relevant scale\n    -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).\n    have J : \u2016f y - f x - (y - x) \u2022 L e (n e) m\u2016 \u2264 4 * (1/2) ^ e * \u2016y - x\u2016 := calc\n      \u2016f y - f x - (y - x) \u2022 L e (n e) m\u2016 \u2264 (1/2) ^ e * (1/2) ^ m :\n        begin\n          apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2,\n          { simp only [one_div, inv_pow, left_mem_Icc, le_add_iff_nonneg_right],\n            exact div_nonneg (inv_nonneg.2 (pow_nonneg zero_le_two _)) zero_le_two },\n          { simp only [pow_add, tsub_le_iff_left] at h'k,\n            simpa only [hy.1, mem_Icc, true_and, one_div, pow_one] using h'k }\n        end\n      ... = 4 * (1/2) ^ e * (1/2) ^ (m + 2) : by { field_simp, ring_exp }\n      ... \u2264 4 * (1/2) ^ e * (y - x) :\n        mul_le_mul_of_nonneg_left (le_of_lt hk) (mul_nonneg (by norm_num) (le_of_lt P))\n      ... = 4 * (1/2) ^ e * \u2016y - x\u2016 : by rw [real.norm_of_nonneg yzero.le],\n    calc \u2016f y - f x - (y - x) \u2022 f'\u2016\n        = \u2016(f y - f x - (y - x) \u2022 L e (n e) m) + (y - x) \u2022 (L e (n e) m - f')\u2016 :\n      by simp only [smul_sub, sub_add_sub_cancel]\n    ... \u2264 4 * (1/2) ^ e * \u2016y - x\u2016 + \u2016y - x\u2016 * (12 * (1/2) ^ e) : norm_add_le_of_le J\n      (by { rw [norm_smul], exact mul_le_mul_of_nonneg_left (Lf' _ _ m_ge) (norm_nonneg _) })\n    ... = 16 * \u2016y - x\u2016 * (1/2) ^ e : by ring\n    ... \u2264 16 * \u2016y - x\u2016 * (\u03b5 / 16) :\n      mul_le_mul_of_nonneg_left he.le (mul_nonneg (by norm_num) (norm_nonneg _))\n    ... = \u03b5 * \u2016y - x\u2016 : by ring },\n  rw \u2190 this.deriv_within (unique_diff_on_Ici x x le_rfl) at f'K,\n  exact \u27e8this.differentiable_within_at, f'K\u27e9,\nend\n\ntheorem differentiable_set_eq_D (hK : is_complete K) :\n  {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} = D f K :=\nsubset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)\n\nend right_deriv_measurable_aux\n\nopen right_deriv_measurable_aux\n\nvariables (f)\n\n/-- The set of right differentiability points of a function, with derivative in a given complete\nset, is Borel-measurable. -/\ntheorem measurable_set_of_differentiable_within_at_Ici_of_is_complete\n  {K : set F} (hK : is_complete K) :\n  measurable_set {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 K} :=\nby simp [differentiable_set_eq_D K hK, D, measurable_set_B, measurable_set.Inter,\n         measurable_set.Union]\n\nvariable [complete_space F]\n\n/-- The set of right differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurable_set_of_differentiable_within_at_Ici :\n  measurable_set {x | differentiable_within_at \u211d f (Ici x) x} :=\nbegin\n  have : is_complete (univ : set F) := complete_univ,\n  convert measurable_set_of_differentiable_within_at_Ici_of_is_complete f this,\n  simp\nend\n\n@[measurability] lemma measurable_deriv_within_Ici [measurable_space F] [borel_space F] :\n  measurable (\u03bb x, deriv_within f (Ici x) x) :=\nbegin\n  refine measurable_of_is_closed (\u03bb s hs, _),\n  have : (\u03bb x, deriv_within f (Ici x) x) \u207b\u00b9' s =\n    {x | differentiable_within_at \u211d f (Ici x) x \u2227 deriv_within f (Ici x) x \u2208 s} \u222a\n    ({x | \u00acdifferentiable_within_at \u211d f (Ici x) x} \u2229 {x | (0 : F) \u2208 s}) :=\n    set.ext (\u03bb x, mem_preimage.trans deriv_within_mem_iff),\n  rw this,\n  exact (measurable_set_of_differentiable_within_at_Ici_of_is_complete _ hs.is_complete).union\n    ((measurable_set_of_differentiable_within_at_Ici _).compl.inter (measurable_set.const _))\nend\n\nlemma strongly_measurable_deriv_within_Ici [second_countable_topology F] :\n  strongly_measurable (\u03bb x, deriv_within f (Ici x) x) :=\nby { borelize F, exact (measurable_deriv_within_Ici f).strongly_measurable }\n\nlemma ae_measurable_deriv_within_Ici [measurable_space F] [borel_space F]\n  (\u03bc : measure \u211d) : ae_measurable (\u03bb x, deriv_within f (Ici x) x) \u03bc :=\n(measurable_deriv_within_Ici f).ae_measurable\n\nlemma ae_strongly_measurable_deriv_within_Ici [second_countable_topology F] (\u03bc : measure \u211d) :\n  ae_strongly_measurable (\u03bb x, deriv_within f (Ici x) x) \u03bc :=\n(strongly_measurable_deriv_within_Ici f).ae_strongly_measurable\n\n/-- The set of right differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurable_set_of_differentiable_within_at_Ioi :\n  measurable_set {x | differentiable_within_at \u211d f (Ioi x) x} :=\nby simpa [differentiable_within_at_Ioi_iff_Ici]\n  using measurable_set_of_differentiable_within_at_Ici f\n\n@[measurability] lemma measurable_deriv_within_Ioi [measurable_space F] [borel_space F] :\n  measurable (\u03bb x, deriv_within f (Ioi x) x) :=\nby simpa [deriv_within_Ioi_eq_Ici] using measurable_deriv_within_Ici f\n\nlemma strongly_measurable_deriv_within_Ioi [second_countable_topology F] :\n  strongly_measurable (\u03bb x, deriv_within f (Ioi x) x) :=\nby { borelize F, exact (measurable_deriv_within_Ioi f).strongly_measurable }\n\nlemma ae_measurable_deriv_within_Ioi [measurable_space F] [borel_space F]\n  (\u03bc : measure \u211d) : ae_measurable (\u03bb x, deriv_within f (Ioi x) x) \u03bc :=\n(measurable_deriv_within_Ioi f).ae_measurable\n\nlemma ae_strongly_measurable_deriv_within_Ioi [second_countable_topology F] (\u03bc : measure \u211d) :\n  ae_strongly_measurable (\u03bb x, deriv_within f (Ioi x) x) \u03bc :=\n(strongly_measurable_deriv_within_Ioi f).ae_strongly_measurable\n\nend right_deriv\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/calculus/fderiv_measurable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859265, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7069235435656159}}
{"text": "/-\nCopyright (c) 2020 Markus Himmel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Markus Himmel, Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.abelian.images\n! leanprover-community/mathlib commit 9e7c80f638149bfb3504ba8ff48dfdbfc949fb1a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.Limits.Shapes.Kernels\n\n/-!\n# The abelian image and coimage.\n\nIn an abelian category we usually want the image of a morphism `f` to be defined as\n`kernel (cokernel.\u03c0 f)`, and the coimage to be defined as `cokernel (kernel.\u03b9 f)`.\n\nWe make these definitions here, as `Abelian.image f` and `Abelian.coimage f`\n(without assuming the category is actually abelian),\nand later relate these to the usual categorical notions when in an abelian category.\n\nThere is a canonical morphism `coimageImageComparison : Abelian.coimage f \u27f6 Abelian.image f`.\nLater we show that this is always an isomorphism in an abelian category,\nand conversely a category with (co)kernels and finite products in which this morphism\nis always an isomorphism is an abelian category.\n-/\n\n\nnoncomputable section\n\nuniverse v u\n\nopen CategoryTheory\n\nopen CategoryTheory.Limits\n\nnamespace CategoryTheory.Abelian\n\nvariable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasKernels C] [HasCokernels C]\n\nvariable {P Q : C} (f : P \u27f6 Q)\n\nsection Image\n\n/-- The kernel of the cokernel of `f` is called the (abelian) image of `f`. -/\nprotected abbrev image : C :=\n  kernel (cokernel.\u03c0 f)\n#align category_theory.abelian.image CategoryTheory.Abelian.image\n\n/-- The inclusion of the image into the codomain. -/\nprotected abbrev image.\u03b9 : Abelian.image f \u27f6 Q :=\n  kernel.\u03b9 (cokernel.\u03c0 f)\n#align category_theory.abelian.image.\u03b9 CategoryTheory.Abelian.image.\u03b9\n\n/-- There is a canonical epimorphism `p : P \u27f6 image f` for every `f`. -/\nprotected abbrev factorThruImage : P \u27f6 Abelian.image f :=\n  kernel.lift (cokernel.\u03c0 f) f <| cokernel.condition f\n#align category_theory.abelian.factor_thru_image CategoryTheory.Abelian.factorThruImage\n\n-- Porting note: simp can prove this and reassoc version, removed tags\n/-- `f` factors through its image via the canonical morphism `p`. -/\nprotected theorem image.fac : Abelian.factorThruImage f \u226b image.\u03b9 f = f :=\n  kernel.lift_\u03b9 _ _ _\n#align category_theory.abelian.image.fac CategoryTheory.Abelian.image.fac\n\ninstance mono_factorThruImage [Mono f] : Mono (Abelian.factorThruImage f) :=\n  mono_of_mono_fac <| image.fac f\n#align category_theory.abelian.mono_factor_thru_image CategoryTheory.Abelian.mono_factorThruImage\n\nend Image\n\nsection Coimage\n\n/-- The cokernel of the kernel of `f` is called the (abelian) coimage of `f`. -/\nprotected abbrev coimage : C :=\n  cokernel (kernel.\u03b9 f)\n#align category_theory.abelian.coimage CategoryTheory.Abelian.coimage\n\n/-- The projection onto the coimage. -/\nprotected abbrev coimage.\u03c0 : P \u27f6 Abelian.coimage f :=\n  cokernel.\u03c0 (kernel.\u03b9 f)\n#align category_theory.abelian.coimage.\u03c0 CategoryTheory.Abelian.coimage.\u03c0\n\n/-- There is a canonical monomorphism `i : coimage f \u27f6 Q`. -/\nprotected abbrev factorThruCoimage : Abelian.coimage f \u27f6 Q :=\n  cokernel.desc (kernel.\u03b9 f) f <| kernel.condition f\n#align category_theory.abelian.factor_thru_coimage CategoryTheory.Abelian.factorThruCoimage\n\n/-- `f` factors through its coimage via the canonical morphism `p`. -/\nprotected theorem coimage.fac : coimage.\u03c0 f \u226b Abelian.factorThruCoimage f = f :=\n  cokernel.\u03c0_desc _ _ _\n#align category_theory.abelian.coimage.fac CategoryTheory.Abelian.coimage.fac\n\ninstance epi_factorThruCoimage [Epi f] : Epi (Abelian.factorThruCoimage f) :=\n  epi_of_epi_fac <| coimage.fac f\n#align category_theory.abelian.epi_factor_thru_coimage CategoryTheory.Abelian.epi_factorThruCoimage\n\nend Coimage\n\n/-- The canonical map from the abelian coimage to the abelian image.\nIn any abelian category this is an isomorphism.\n\nConversely, any additive category with kernels and cokernels and\nin which this is always an isomorphism, is abelian.\n\nSee <https://stacks.math.columbia.edu/tag/0107>\n-/\ndef coimageImageComparison : Abelian.coimage f \u27f6 Abelian.image f :=\n  cokernel.desc (kernel.\u03b9 f) (kernel.lift (cokernel.\u03c0 f) f (by simp)) <|\n    by apply equalizer.hom_ext; simp\n#align category_theory.abelian.coimage_image_comparison CategoryTheory.Abelian.coimageImageComparison\n\n/-- An alternative formulation of the canonical map from the abelian coimage to the abelian image.\n-/\ndef coimageImageComparison' : Abelian.coimage f \u27f6 Abelian.image f :=\n  kernel.lift (cokernel.\u03c0 f) (cokernel.desc (kernel.\u03b9 f) f (by simp))\n    (by apply coequalizer.hom_ext; simp)\n#align category_theory.abelian.coimage_image_comparison' CategoryTheory.Abelian.coimageImageComparison'\n\ntheorem coimageImageComparison_eq_coimageImageComparison' :\n    coimageImageComparison f = coimageImageComparison' f := by\n  apply coequalizer.hom_ext; apply equalizer.hom_ext\n  simp [coimageImageComparison, coimageImageComparison']\n#align category_theory.abelian.coimage_image_comparison_eq_coimage_image_comparison' CategoryTheory.Abelian.coimageImageComparison_eq_coimageImageComparison'\n\n@[reassoc (attr := simp)]\ntheorem coimage_image_factorisation : coimage.\u03c0 f \u226b coimageImageComparison f \u226b image.\u03b9 f = f := by\n  simp [coimageImageComparison]\n#align category_theory.abelian.coimage_image_factorisation CategoryTheory.Abelian.coimage_image_factorisation\n\nend CategoryTheory.Abelian\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Abelian/Images.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7069235327065095}}
{"text": "universes u\n\ndef f1 (n m : Nat) (x : Fin n) (h : n = m) : Fin m :=\nh \u25b8 x\n\ndef f2 (n m : Nat) (x : Fin n) (h : m = n) : Fin m :=\nh \u25b8 x\n\ntheorem ex1 {\u03b1 : Sort u} {a b c : \u03b1} (h\u2081 : a = b) (h\u2082 : b = c) : a = c :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex2 {\u03b1 : Sort u} {a b : \u03b1} (h : a = b) : b = a :=\nh \u25b8 rfl\n\ntheorem ex3 {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex3b {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082.symm \u25b8 h\u2081\n\ntheorem ex3c {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082.symm.symm \u25b8 h\u2081\n\ntheorem ex4 {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : a = b) (h\u2082 : r b c) : r a c :=\nh\u2081 \u25b8 h\u2082\n\ntheorem ex5 {p : Prop} (h : p = True) : p :=\nh \u25b8 trivial\n\ntheorem ex6 {p : Prop} (h : p = False) : \u00acp :=\nfun hp => h \u25b8 hp\n\ntheorem ex7 {\u03b1} {a b c d : \u03b1} (h\u2081 : a = c) (h\u2082 : b = d) (h\u2083 : c \u2260 d) : a \u2260 b :=\nh\u2081 \u25b8 h\u2082 \u25b8 h\u2083\n\ntheorem ex8 (n m k : Nat) (h : Nat.succ n + m = Nat.succ n + k) : Nat.succ (n + m) = Nat.succ (n + k) :=\nNat.succ_add .. \u25b8 Nat.succ_add .. \u25b8 h\n\ntheorem ex9 (a b : Nat) (h\u2081 : a = a + b) (h\u2082 : a = b) : a = b + a  :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex10 (a b : Nat) (h : a = b) : b = a :=\nh \u25b8 rfl\n\ndef ex11  {\u03b1 : Type u} {n : Nat} (a : Array \u03b1) (i : Nat) (h\u2081 : a.size = n) (h\u2082 : i < n) : \u03b1 :=\n  a.get \u27e8i, h\u2081 \u25b8 h\u2082\u27e9\n\ntheorem ex12 {\u03b1 : Type u} {n : Nat}\n  (a b : Array \u03b1)\n  (hsz\u2081 : a.size = n) (hsz\u2082 : b.size = n)\n  (h : \u2200 (i : Nat) (hi : i < n), a.getLit i hsz\u2081 hi = b.getLit i hsz\u2082 hi) : a = b :=\nArray.ext a b (hsz\u2081.trans hsz\u2082.symm) fun i hi\u2081 hi\u2082 => h i (hsz\u2081 \u25b8 hi\u2081)\n\ndef toArrayLit {\u03b1 : Type u} (a : Array \u03b1) (n : Nat) (hsz : a.size = n) : Array \u03b1 :=\nList.toArray $ Array.toListLitAux a n hsz n (hsz \u25b8 Nat.leRefl _) []\n\npartial def isEqvAux {\u03b1} (a b : Array \u03b1) (hsz : a.size = b.size) (p : \u03b1 \u2192 \u03b1 \u2192 Bool) (i : Nat) : Bool :=\n  if h : i < a.size then\n     let aidx : Fin a.size := \u27e8i, h\u27e9\n     let bidx : Fin b.size := \u27e8i, hsz \u25b8 h\u27e9\n     match p (a.get aidx) (b.get bidx) with\n     | true  => isEqvAux a b hsz p (i+1)\n     | false => false\n  else\n    true\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/subst.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7069096026942859}}
{"text": "/-\nCopyright (c) 2020 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton\n-/\n\nimport ..todo\nimport topology.separation\n\n/-!\nA formal roadmap for the shrinking lemma for local finite countable covers.\n\nIt contains the statement of the lemma, and an informal sketch of the proof,\nalong with references.\n\nThe lemma is now formalized as `exists_subset_Union_closure_subset` in `topology/shrinking_lemma`.\nThis file is preserved as an example of a formal roadmap.\n\nThe actual implementation differs from the roadmap in two aspects:\n\n- it uses a custom `structure` with a `partial_order` instead of a combination\n  of `sigma` and `subtype`;\n- it provides a version for coverings of a closed set in a normal space. While mathematically it's\n  almost the same (just add `s\u1d9c` to the covering), it's easier to prove a version for a closed set,\n  then apply it to `univ` than to deal with coverings indexed by `option \u03b1`.\n-/\n\nopen set\n\nuniverses u v\n\n/-- A point-finite open cover of a closed subset of a normal space can be \"shrunk\" to a new open\ncover so that the closure of each new open set is contained in the corresponding original open\nset. -/\nlemma roadmap.shrinking_lemma {X : Type u} [topological_space X] [normal_space X]\n  {s : set X} (hs : is_closed s) {\u03b1 : Type v} (u : \u03b1 \u2192 set X) (uo : \u2200 a, is_open (u a))\n  (uf : \u2200 x, {a | x \u2208 u a}.finite) (su : s \u2286 Union u) :\n  \u2203 v : \u03b1 \u2192 set X, s \u2286 Union v \u2227 \u2200 a, is_open (v a) \u2227 closure (v a) \u2286 u a :=\ntodo\n/-\nApply Zorn's lemma to\n T = \u03a3 (i : set \u03b1), {v : \u03b1 \u2192 set X // s \u2286 Union v \u2227 (\u2200 a, is_open (v a)) \u2227\n                                      (\u2200 a \u2208 i, closure (v a) \u2286 u a) \u2227 (\u2200 a \u2209 i, v a = u a)}\nwith the ordering\n \u27e8i, v, _\u27e9 \u2264 \u27e8i', v', _\u27e9 \u2194 i \u2286 i' \u2227 \u2200 a \u2208 i, v a = v' a\nThe hypothesis that `X` is normal implies that a maximal element must have `i = univ`.\nPoint-finiteness of `u` (hypothesis `uf`) implies that\nthe least upper bound of a chain in `T` again yields a covering of `s`.\n\nCompare proofs in\n* https://ncatlab.org/nlab/show/shrinking+lemma#ShrinkingLemmaForLocallyFiniteCountableCovers\n* Bourbaki, General Topology, Chapter IX, \u00a74.3\n* Dugundji, Topology, Chapter VII, Theorem 6.1\n-/\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/roadmap/topology/shrinking_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7069095926091161}}
{"text": "import tactic\nimport data.finsupp.basic -- finitely-supported functions\nimport data.polynomial.basic -- polynomials\n\n/-\n\n# Finitely-supported functions\n\nWe're used to dealing with finite-dimensional vector spaces when we begin studying\nvector spaces, but infinite-dimensional vector spaces exist everywhere (for example\nthe polynonial ring `\u211d[X]` is an infinite-dimensional real vector space) and Lean\nis happy to work with both finite and infinite-dimensional vector spaces. \n\nIf `V` is a finite-dimensional vector space, with basis `{e\u2081,e\u2082,...,e\u2099}`, then\nevery element of `V` can be uniquely expressed as \u2211 c\u1d62e\u1d62, with c\u1d62 in the ground field.\nIn the infinite-dimensional case this doesn't make sense, because in algebra you\ncannot do infinite sums in general; you need some kind of metric or topology\nto express the idea that an infinite sum converges or tends to some limit, and a general\nfield `k` may not have a metric or a topology. If `k` is a finite field, you could\ngive it the discrete topology, but then no infinite sum would converge, unless all\nbut finitely many of the terms were actually equal to zero. \n\nThe simplest example of an infinite-dimensional vector space is the ring of polynomials\n`k[X]` over a field `k`, and this vector space has a basis `{1,X,X\u00b2,X\u00b3,...}`. Hopefully\nthis enables you to see what is going on: whilst the vector space is infinite-dimensional,\nand the basis is infinite, each vector in the space (i.e. each polynomial in `k[X]`) is\na *finite* linear combination of basis elements; so we have `v = \u2211\u1d62 c\u1d62 e\u1d62` but all\nof the `c\u1d62` are zero other than finitely many of them. This makes the sum finite,\nand hence it makes in algebra without having to assume anything about existence of\nmetrics or topologies.\n\nThis example shows that an important role in the theory of vector spaces is played\nby the *finitely-supported functions*. If `X` and `Y` are types, and `Y` has a special\nelement called `0`, then a function from `X` to `Y` is *finitely-supported* if it sends\nall but finitely many elements of `X` to `0`. Just like the theory of finite sets,\nthere are two ways to set up a theory of finitely-supported functions. We could first\nconsider all functions and then have a predicate on functions saying \"I have finite support\".\nAlternatively, we could make an entirely new type of finitely-supported functions, and\nthen just have a map from that type to the type of all functions. This latter approach\nis what we do in Lean.\n\nThe type of finitely-supported functions from `X` to `Y` is denoted `X \u2192\u2080 Y`, which\nis notation for `finsupp X Y`. Note that `Y` needs to have a `zero` for this notion\nto make sense.\n\n-/\n\nexample : Type := \u2115 \u2192\u2080 \u2115 -- works because \u2115 has a zero\n\n/-\n\nThe theory of finitely supported functions is a noncomputable theory in Lean 3, so\nlet's switch `noncomputable` on.\n\n-/\n\nnoncomputable theory\n\n-- In the application to vector spaces, `Y` will be a field, so it will have a zero.\n-- If you know about free modules, then you can let `Y` be a ring.\n\n-- Lean's typeclass inference system knows that if `X` is an arbitrary type and `k` is a field, \n-- then `X \u2192\u2080 k` is a `k`-vector space.\n\nexample (X : Type) (k : Type) [field k] : module k (X \u2192\u2080 k) := infer_instance\n\n-- In particular, Lean is happy to add two finitely-supported functions and return\n-- a finitely-supported function.\n\n-- Lean will also allow you to evaluate a finitely-supported function at an input,\n-- even though a finitely-supported function is not strictly speaking a function\n-- (it's a function plus some extra data and proofs). Lean will *coerce* a finitely-supported\n-- function into a function if required though (the coercion symbol for coercion into\n-- functions is `\u21d1`).\n\nexample (X : Type) (k : Type) [field k] (f : X \u2192\u2080 k) (x : X) : k := f x -- actually `\u21d1f x`\n\n-- Because these things are a vector space, addition of two finitely-supported functions is a \n-- finitely-supported function. Similarly multiplication by a scalar is a finitely-supported\n-- function\n\nexample (X : Type) (k : Type) [field k] (f g : X \u2192\u2080 k) (c : k) : X \u2192\u2080 k := c \u2022 f + g\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section11vector_spaces/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7069095924548832}}
{"text": "import tactic.fin_cases\nimport data.nat.prime\nimport group_theory.perm.sign\nimport tactic.norm_num\n\nexample (f : \u2115 \u2192 Prop) (p : fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val :=\nbegin\n  fin_cases *,\n  simp, assumption,\n  simp, assumption,\n  simp, assumption,\nend\n\nexample (x2 : fin 2) (x3 : fin 3) (n : nat) (y : fin n) : x2.val * x3.val = x3.val * x2.val :=\nbegin\n  fin_cases x2;\n  fin_cases x3,\n  success_if_fail { fin_cases * },\n  success_if_fail { fin_cases y },\n  all_goals { simp },\nend\n\nopen finset\nexample (x : \u2115) (h : x \u2208 Ico 2 5) : x = 2 \u2228 x = 3 \u2228 x = 4 :=\nbegin\n  fin_cases h,\n  all_goals { simp }\nend\n\nopen nat\nexample (x : \u2115) (h : x \u2208 [2,3,5,7]) : x = 2 \u2228 x = 3 \u2228 x = 5 \u2228 x = 7 :=\nbegin\n  fin_cases h,\n  all_goals { simp }\nend\n\nexample (x : \u2115) (h : x \u2208 [2,3,5,7]) : true :=\nbegin\n  success_if_fail { fin_cases h with [3,3,5,7] },\n  trivial\nend\n\nexample (x : list \u2115) (h : x \u2208 [[1],[2]]) : x.length = 1 :=\nbegin\n  fin_cases h with [[1],[1+1]],\n  simp,\n  guard_target (list.length [1 + 1] = 1),\n  simp\nend\n\n -- testing that `with` arguments are elaborated with respect to the expected type:\nexample (x : \u2124) (h : x \u2208 ([2,3] : list \u2124)) : x = 2 \u2228 x = 3:=\nbegin\n  fin_cases h with [2,3],\n  all_goals { simp }\nend\n\n\ninstance (n : \u2115) : decidable (prime n) := decidable_prime_1 n\nexample (x : \u2115) (h : x \u2208 (range 10).filter prime) : x = 2 \u2228 x = 3 \u2228 x = 5 \u2228 x = 7 :=\nbegin\n  fin_cases h; exact dec_trivial\nend\n\nopen equiv.perm\nexample (x : (\u03a3 (a : fin 4), fin 4)) (h : x \u2208 fin_pairs_lt 4) : x.1.val < 4 :=\nbegin\n  fin_cases h; simp,\n  any_goals { exact dec_trivial },\nend\n\nexample (x : fin 3) : x.val < 5 :=\nbegin\n  fin_cases x; exact dec_trivial\nend\n\nexample (f : \u2115 \u2192 Prop) (p : fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val :=\nbegin\n  fin_cases *,\n  all_goals { assumption }\nend\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/test/fin_cases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7069095841901188}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n! This file was ported from Lean 3 source module order.bounds.basic\n! leanprover-community/mathlib commit 3310acfa9787aa171db6d4cba3945f6f275fe9f2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Intervals.Basic\nimport Mathlib.Data.Set.NAry\n\n/-!\n# Upper / lower bounds\n\nIn this file we define:\n* `upperBounds`, `lowerBounds` : the set of upper bounds (resp., lower bounds) of a set;\n* `BddAbove s`, `BddBelow s` : the set `s` is bounded above (resp., below), i.e., the set of upper\n  (resp., lower) bounds of `s` is nonempty;\n* `IsLeast s a`, `IsGreatest s a` : `a` is a least (resp., greatest) element of `s`;\n  for a partial order, it is unique if exists;\n* `IsLUB s a`, `IsGLB s a` : `a` is a least upper bound (resp., a greatest lower bound)\n  of `s`; for a partial order, it is unique if exists.\nWe also prove various lemmas about monotonicity, behaviour under `\u222a`, `\u2229`, `insert`, and provide\nformulas for `\u2205`, `univ`, and intervals.\n-/\n\n\nopen Function Set\n\nopen OrderDual (toDual ofDual)\n\nuniverse u v w x\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x}\n\nsection\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {s t : Set \u03b1} {a b : \u03b1}\n\n/-!\n### Definitions\n-/\n\n\n/-- The set of upper bounds of a set. -/\ndef upperBounds (s : Set \u03b1) : Set \u03b1 :=\n  { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 a \u2264 x }\n#align upper_bounds upperBounds\n\n/-- The set of lower bounds of a set. -/\ndef lowerBounds (s : Set \u03b1) : Set \u03b1 :=\n  { x | \u2200 \u2983a\u2984, a \u2208 s \u2192 x \u2264 a }\n#align lower_bounds lowerBounds\n\n/-- A set is bounded above if there exists an upper bound. -/\ndef BddAbove (s : Set \u03b1) :=\n  (upperBounds s).Nonempty\n#align bdd_above BddAbove\n\n/-- A set is bounded below if there exists a lower bound. -/\ndef BddBelow (s : Set \u03b1) :=\n  (lowerBounds s).Nonempty\n#align bdd_below BddBelow\n\n/-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/\ndef IsLeast (s : Set \u03b1) (a : \u03b1) : Prop :=\n  a \u2208 s \u2227 a \u2208 lowerBounds s\n#align is_least IsLeast\n\n/-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists -/\ndef IsGreatest (s : Set \u03b1) (a : \u03b1) : Prop :=\n  a \u2208 s \u2227 a \u2208 upperBounds s\n#align is_greatest IsGreatest\n\n/-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/\ndef IsLUB (s : Set \u03b1) : \u03b1 \u2192 Prop :=\n  IsLeast (upperBounds s)\n#align is_lub IsLUB\n\n/-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/\ndef IsGLB (s : Set \u03b1) : \u03b1 \u2192 Prop :=\n  IsGreatest (lowerBounds s)\n#align is_glb IsGLB\n\ntheorem mem_upperBounds : a \u2208 upperBounds s \u2194 \u2200 x \u2208 s, x \u2264 a :=\n  Iff.rfl\n#align mem_upper_bounds mem_upperBounds\n\ntheorem mem_lowerBounds : a \u2208 lowerBounds s \u2194 \u2200 x \u2208 s, a \u2264 x :=\n  Iff.rfl\n#align mem_lower_bounds mem_lowerBounds\n\ntheorem bddAbove_def : BddAbove s \u2194 \u2203 x, \u2200 y \u2208 s, y \u2264 x :=\n  Iff.rfl\n#align bdd_above_def bddAbove_def\n\ntheorem bddBelow_def : BddBelow s \u2194 \u2203 x, \u2200 y \u2208 s, x \u2264 y :=\n  Iff.rfl\n#align bdd_below_def bddBelow_def\n\ntheorem bot_mem_lowerBounds [OrderBot \u03b1] (s : Set \u03b1) : \u22a5 \u2208 lowerBounds s := fun _ _ => bot_le\n#align bot_mem_lower_bounds bot_mem_lowerBounds\n\ntheorem top_mem_upperBounds [OrderTop \u03b1] (s : Set \u03b1) : \u22a4 \u2208 upperBounds s := fun _ _ => le_top\n#align top_mem_upper_bounds top_mem_upperBounds\n\n@[simp]\ntheorem isLeast_bot_iff [OrderBot \u03b1] : IsLeast s \u22a5 \u2194 \u22a5 \u2208 s :=\n  and_iff_left <| bot_mem_lowerBounds _\n#align is_least_bot_iff isLeast_bot_iff\n\n@[simp]\ntheorem isGreatest_top_iff [OrderTop \u03b1] : IsGreatest s \u22a4 \u2194 \u22a4 \u2208 s :=\n  and_iff_left <| top_mem_upperBounds _\n#align is_greatest_top_iff isGreatest_top_iff\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not greater than or equal to `y`. This version only assumes `Preorder` structure and uses\n`\u00ac(y \u2264 x)`. A version for linear orders is called `not_bddAbove_iff`. -/\ntheorem not_bddAbove_iff' : \u00acBddAbove s \u2194 \u2200 x, \u2203 y \u2208 s, \u00acy \u2264 x := by\n  simp [BddAbove, upperBounds, Set.Nonempty]\n#align not_bdd_above_iff' not_bddAbove_iff'\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` such that `x`\nis not less than or equal to `y`. This version only assumes `Preorder` structure and uses\n`\u00ac(x \u2264 y)`. A version for linear orders is called `not_bddBelow_iff`. -/\ntheorem not_bddBelow_iff' : \u00acBddBelow s \u2194 \u2200 x, \u2203 y \u2208 s, \u00acx \u2264 y :=\n  @not_bddAbove_iff' \u03b1\u1d52\u1d48 _ _\n#align not_bdd_below_iff' not_bddBelow_iff'\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y \u2208 s` that is greater\nthan `x`. A version for preorders is called `not_bddAbove_iff'`. -/\ntheorem not_bddAbove_iff {\u03b1 : Type _} [LinearOrder \u03b1] {s : Set \u03b1} :\n    \u00acBddAbove s \u2194 \u2200 x, \u2203 y \u2208 s, x < y := by\n  simp only [not_bddAbove_iff', not_le]\n#align not_bdd_above_iff not_bddAbove_iff\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y \u2208 s` that is less\nthan `x`. A version for preorders is called `not_bddBelow_iff'`. -/\ntheorem not_bddBelow_iff {\u03b1 : Type _} [LinearOrder \u03b1] {s : Set \u03b1} :\n    \u00acBddBelow s \u2194 \u2200 x, \u2203 y \u2208 s, y < x :=\n  @not_bddAbove_iff \u03b1\u1d52\u1d48 _ _\n#align not_bdd_below_iff not_bddBelow_iff\n\ntheorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual \u207b\u00b9' s) :=\n  h\n#align bdd_above.dual BddAbove.dual\n\ntheorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual \u207b\u00b9' s) :=\n  h\n#align bdd_below.dual BddBelow.dual\n\ntheorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_least.dual IsLeast.dual\n\ntheorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_greatest.dual IsGreatest.dual\n\ntheorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_lub.dual IsLUB.dual\n\ntheorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual \u207b\u00b9' s) (toDual a) :=\n  h\n#align is_glb.dual IsGLB.dual\n\n/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/\n@[reducible]\ndef IsLeast.orderBot (h : IsLeast s a) :\n    OrderBot s where\n  bot := \u27e8a, h.1\u27e9\n  bot_le := Subtype.forall.2 h.2\n#align is_least.order_bot IsLeast.orderBot\n\n/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/\n@[reducible]\ndef IsGreatest.orderTop (h : IsGreatest s a) :\n    OrderTop s where\n  top := \u27e8a, h.1\u27e9\n  le_top := Subtype.forall.2 h.2\n#align is_greatest.order_top IsGreatest.orderTop\n\n/-!\n### Monotonicity\n-/\n\n\ntheorem upperBounds_mono_set \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) : upperBounds t \u2286 upperBounds s :=\n  fun _ hb _ h => hb <| hst h\n#align upper_bounds_mono_set upperBounds_mono_set\n\ntheorem lowerBounds_mono_set \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) : lowerBounds t \u2286 lowerBounds s :=\n  fun _ hb _ h => hb <| hst h\n#align lower_bounds_mono_set lowerBounds_mono_set\n\ntheorem upperBounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : a \u2208 upperBounds s \u2192 b \u2208 upperBounds s :=\n  fun ha _ h => le_trans (ha h) hab\n#align upper_bounds_mono_mem upperBounds_mono_mem\n\ntheorem lowerBounds_mono_mem \u2983a b\u2984 (hab : a \u2264 b) : b \u2208 lowerBounds s \u2192 a \u2208 lowerBounds s :=\n  fun hb _ h => le_trans hab (hb h)\n#align lower_bounds_mono_mem lowerBounds_mono_mem\n\ntheorem upperBounds_mono \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n    a \u2208 upperBounds t \u2192 b \u2208 upperBounds s := fun ha =>\n  upperBounds_mono_set hst <| upperBounds_mono_mem hab ha\n#align upper_bounds_mono upperBounds_mono\n\ntheorem lowerBounds_mono \u2983s t : Set \u03b1\u2984 (hst : s \u2286 t) \u2983a b\u2984 (hab : a \u2264 b) :\n    b \u2208 lowerBounds t \u2192 a \u2208 lowerBounds s := fun hb =>\n  lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb\n#align lower_bounds_mono lowerBounds_mono\n\n/-- If `s \u2286 t` and `t` is bounded above, then so is `s`. -/\ntheorem BddAbove.mono \u2983s t : Set \u03b1\u2984 (h : s \u2286 t) : BddAbove t \u2192 BddAbove s :=\n  Nonempty.mono <| upperBounds_mono_set h\n#align bdd_above.mono BddAbove.mono\n\n/-- If `s \u2286 t` and `t` is bounded below, then so is `s`. -/\ntheorem BddBelow.mono \u2983s t : Set \u03b1\u2984 (h : s \u2286 t) : BddBelow t \u2192 BddBelow s :=\n  Nonempty.mono <| lowerBounds_mono_set h\n#align bdd_below.mono BddBelow.mono\n\n/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\ntheorem IsLUB.of_subset_of_superset {s t p : Set \u03b1} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s \u2286 t)\n    (htp : t \u2286 p) : IsLUB t a :=\n  \u27e8upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2\u27e9\n#align is_lub.of_subset_of_superset IsLUB.of_subset_of_superset\n\n/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any\nset `t`, `s \u2286 t \u2286 p`. -/\ntheorem IsGLB.of_subset_of_superset {s t p : Set \u03b1} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s \u2286 t)\n    (htp : t \u2286 p) : IsGLB t a :=\n  hs.dual.of_subset_of_superset hp hst htp\n#align is_glb.of_subset_of_superset IsGLB.of_subset_of_superset\n\ntheorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s \u2286 t) : b \u2264 a :=\n  hb.2 (hst ha.1)\n#align is_least.mono IsLeast.mono\n\ntheorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s \u2286 t) : a \u2264 b :=\n  hb.2 (hst ha.1)\n#align is_greatest.mono IsGreatest.mono\n\ntheorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s \u2286 t) : a \u2264 b :=\n  IsLeast.mono hb ha <| upperBounds_mono_set hst\n#align is_lub.mono IsLUB.mono\n\ntheorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s \u2286 t) : b \u2264 a :=\n  IsGreatest.mono hb ha <| lowerBounds_mono_set hst\n#align is_glb.mono IsGLB.mono\n\ntheorem subset_lowerBounds_upperBounds (s : Set \u03b1) : s \u2286 lowerBounds (upperBounds s) :=\n  fun _ hx _ hy => hy hx\n#align subset_lower_bounds_upper_bounds subset_lowerBounds_upperBounds\n\ntheorem subset_upperBounds_lowerBounds (s : Set \u03b1) : s \u2286 upperBounds (lowerBounds s) :=\n  fun _ hx _ hy => hy hx\n#align subset_upper_bounds_lower_bounds subset_upperBounds_lowerBounds\n\ntheorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) :=\n  hs.mono (subset_upperBounds_lowerBounds s)\n#align set.nonempty.bdd_above_lower_bounds Set.Nonempty.bddAbove_lowerBounds\n\ntheorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) :=\n  hs.mono (subset_lowerBounds_upperBounds s)\n#align set.nonempty.bdd_below_upper_bounds Set.Nonempty.bddBelow_upperBounds\n\n/-!\n### Conversions\n-/\n\n\ntheorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a :=\n  \u27e8h.2, fun _ hb => hb h.1\u27e9\n#align is_least.is_glb IsLeast.isGLB\n\ntheorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a :=\n  \u27e8h.2, fun _ hb => hb h.1\u27e9\n#align is_greatest.is_lub IsGreatest.isLUB\n\ntheorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a :=\n  Set.ext fun _ => \u27e8fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1\u27e9\n#align is_lub.upper_bounds_eq IsLUB.upperBounds_eq\n\ntheorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a :=\n  h.dual.upperBounds_eq\n#align is_glb.lower_bounds_eq IsGLB.lowerBounds_eq\n\ntheorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a :=\n  h.isGLB.lowerBounds_eq\n#align is_least.lower_bounds_eq IsLeast.lowerBounds_eq\n\ntheorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a :=\n  h.isLUB.upperBounds_eq\n#align is_greatest.upper_bounds_eq IsGreatest.upperBounds_eq\n\n-- porting note: new lemma\ntheorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b \u2194 \u2200 x \u2208 s, x < b :=\n  \u27e8fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1\u27e9\n\n-- porting note: new lemma\ntheorem IsLeast.lt_iff (h : IsLeast s a) : b < a \u2194 \u2200 x \u2208 s, b < x :=\n  h.dual.lt_iff\n\ntheorem isLUB_le_iff (h : IsLUB s a) : a \u2264 b \u2194 b \u2208 upperBounds s := by\n  rw [h.upperBounds_eq]\n  rfl\n#align is_lub_le_iff isLUB_le_iff\n\ntheorem le_isGLB_iff (h : IsGLB s a) : b \u2264 a \u2194 b \u2208 lowerBounds s := by\n  rw [h.lowerBounds_eq]\n  rfl\n#align le_is_glb_iff le_isGLB_iff\n\ntheorem isLUB_iff_le_iff : IsLUB s a \u2194 \u2200 b, a \u2264 b \u2194 b \u2208 upperBounds s :=\n  \u27e8fun h _ => isLUB_le_iff h, fun H => \u27e8(H _).1 le_rfl, fun b hb => (H b).2 hb\u27e9\u27e9\n#align is_lub_iff_le_iff isLUB_iff_le_iff\n\ntheorem isGLB_iff_le_iff : IsGLB s a \u2194 \u2200 b, b \u2264 a \u2194 b \u2208 lowerBounds s :=\n  @isLUB_iff_le_iff \u03b1\u1d52\u1d48 _ _ _\n#align is_glb_iff_le_iff isGLB_iff_le_iff\n\n/-- If `s` has a least upper bound, then it is bounded above. -/\ntheorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s :=\n  \u27e8a, h.1\u27e9\n#align is_lub.bdd_above IsLUB.bddAbove\n\n/-- If `s` has a greatest lower bound, then it is bounded below. -/\ntheorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s :=\n  \u27e8a, h.1\u27e9\n#align is_glb.bdd_below IsGLB.bddBelow\n\n/-- If `s` has a greatest element, then it is bounded above. -/\ntheorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s :=\n  \u27e8a, h.2\u27e9\n#align is_greatest.bdd_above IsGreatest.bddAbove\n\n/-- If `s` has a least element, then it is bounded below. -/\ntheorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s :=\n  \u27e8a, h.2\u27e9\n#align is_least.bdd_below IsLeast.bddBelow\n\ntheorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty :=\n  \u27e8a, h.1\u27e9\n#align is_least.nonempty IsLeast.nonempty\n\ntheorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty :=\n  \u27e8a, h.1\u27e9\n#align is_greatest.nonempty IsGreatest.nonempty\n\n/-!\n### Union and intersection\n-/\n\n@[simp]\ntheorem upperBounds_union : upperBounds (s \u222a t) = upperBounds s \u2229 upperBounds t :=\n  Subset.antisymm (fun _ hb => \u27e8fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)\u27e9)\n    fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht\n#align upper_bounds_union upperBounds_union\n\n@[simp]\ntheorem lowerBounds_union : lowerBounds (s \u222a t) = lowerBounds s \u2229 lowerBounds t :=\n  @upperBounds_union \u03b1\u1d52\u1d48 _ s t\n#align lower_bounds_union lowerBounds_union\n\ntheorem union_upperBounds_subset_upperBounds_inter :\n    upperBounds s \u222a upperBounds t \u2286 upperBounds (s \u2229 t) :=\n  union_subset (upperBounds_mono_set <| inter_subset_left _ _)\n    (upperBounds_mono_set <| inter_subset_right _ _)\n#align union_upper_bounds_subset_upper_bounds_inter union_upperBounds_subset_upperBounds_inter\n\ntheorem union_lowerBounds_subset_lowerBounds_inter :\n    lowerBounds s \u222a lowerBounds t \u2286 lowerBounds (s \u2229 t) :=\n  @union_upperBounds_subset_upperBounds_inter \u03b1\u1d52\u1d48 _ s t\n#align union_lower_bounds_subset_lower_bounds_inter union_lowerBounds_subset_lowerBounds_inter\n\ntheorem isLeast_union_iff {a : \u03b1} {s t : Set \u03b1} :\n    IsLeast (s \u222a t) a \u2194 IsLeast s a \u2227 a \u2208 lowerBounds t \u2228 a \u2208 lowerBounds s \u2227 IsLeast t a := by\n  simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a \u2208 t), and_assoc]\n#align is_least_union_iff isLeast_union_iff\n\ntheorem isGreatest_union_iff :\n    IsGreatest (s \u222a t) a \u2194\n      IsGreatest s a \u2227 a \u2208 upperBounds t \u2228 a \u2208 upperBounds s \u2227 IsGreatest t a :=\n  @isLeast_union_iff \u03b1\u1d52\u1d48 _ a s t\n#align is_greatest_union_iff isGreatest_union_iff\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\ntheorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s \u2229 t) :=\n  h.mono <| inter_subset_left s t\n#align bdd_above.inter_of_left BddAbove.inter_of_left\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\ntheorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s \u2229 t) :=\n  h.mono <| inter_subset_right s t\n#align bdd_above.inter_of_right BddAbove.inter_of_right\n\n/-- If `s` is bounded, then so is `s \u2229 t` -/\ntheorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s \u2229 t) :=\n  h.mono <| inter_subset_left s t\n#align bdd_below.inter_of_left BddBelow.inter_of_left\n\n/-- If `t` is bounded, then so is `s \u2229 t` -/\ntheorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s \u2229 t) :=\n  h.mono <| inter_subset_right s t\n#align bdd_below.inter_of_right BddBelow.inter_of_right\n\n/-- If `s` and `t` are bounded above sets in a `semilattice_sup`, then so is `s \u222a t`. -/\ntheorem BddAbove.union [SemilatticeSup \u03b3] {s t : Set \u03b3} :\n    BddAbove s \u2192 BddAbove t \u2192 BddAbove (s \u222a t) := by\n  rintro \u27e8bs, hs\u27e9 \u27e8bt, ht\u27e9\n  use bs \u2294 bt\n  rw [upperBounds_union]\n  exact \u27e8upperBounds_mono_mem le_sup_left hs, upperBounds_mono_mem le_sup_right ht\u27e9\n#align bdd_above.union BddAbove.union\n\n/-- The union of two sets is bounded above if and only if each of the sets is. -/\ntheorem bddAbove_union [SemilatticeSup \u03b3] {s t : Set \u03b3} :\n    BddAbove (s \u222a t) \u2194 BddAbove s \u2227 BddAbove t :=\n  \u27e8fun h => \u27e8h.mono <| subset_union_left s t, h.mono <| subset_union_right s t\u27e9, fun h =>\n    h.1.union h.2\u27e9\n#align bdd_above_union bddAbove_union\n\ntheorem BddBelow.union [SemilatticeInf \u03b3] {s t : Set \u03b3} :\n    BddBelow s \u2192 BddBelow t \u2192 BddBelow (s \u222a t) :=\n  @BddAbove.union \u03b3\u1d52\u1d48 _ s t\n#align bdd_below.union BddBelow.union\n\n/-- The union of two sets is bounded above if and only if each of the sets is.-/\ntheorem bddBelow_union [SemilatticeInf \u03b3] {s t : Set \u03b3} :\n    BddBelow (s \u222a t) \u2194 BddBelow s \u2227 BddBelow t :=\n  @bddAbove_union \u03b3\u1d52\u1d48 _ s t\n#align bdd_below_union bddBelow_union\n\n/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,\nthen `a \u2294 b` is the least upper bound of `s \u222a t`. -/\ntheorem IsLUB.union [SemilatticeSup \u03b3] {a b : \u03b3} {s t : Set \u03b3} (hs : IsLUB s a) (ht : IsLUB t b) :\n    IsLUB (s \u222a t) (a \u2294 b) :=\n  \u27e8fun _ h =>\n    h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h,\n    fun _ hc =>\n    sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)\u27e9\n#align is_lub.union IsLUB.union\n\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a \u2293 b` is the greatest lower bound of `s \u222a t`. -/\ntheorem IsGLB.union [SemilatticeInf \u03b3] {a\u2081 a\u2082 : \u03b3} {s t : Set \u03b3} (hs : IsGLB s a\u2081)\n    (ht : IsGLB t a\u2082) : IsGLB (s \u222a t) (a\u2081 \u2293 a\u2082) :=\n  hs.dual.union ht\n#align is_glb.union IsGLB.union\n\n/-- If `a` is the least element of `s` and `b` is the least element of `t`,\nthen `min a b` is the least element of `s \u222a t`. -/\ntheorem IsLeast.union [LinearOrder \u03b3] {a b : \u03b3} {s t : Set \u03b3} (ha : IsLeast s a)\n    (hb : IsLeast t b) : IsLeast (s \u222a t) (min a b) :=\n  \u27e8by cases' le_total a b with h h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1\u27e9\n#align is_least.union IsLeast.union\n\n/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,\nthen `max a b` is the greatest element of `s \u222a t`. -/\ntheorem IsGreatest.union [LinearOrder \u03b3] {a b : \u03b3} {s t : Set \u03b3} (ha : IsGreatest s a)\n    (hb : IsGreatest t b) : IsGreatest (s \u222a t) (max a b) :=\n  \u27e8by cases' le_total a b with h h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1\u27e9\n#align is_greatest.union IsGreatest.union\n\ntheorem IsLUB.inter_Ici_of_mem [LinearOrder \u03b3] {s : Set \u03b3} {a b : \u03b3} (ha : IsLUB s a) (hb : b \u2208 s) :\n    IsLUB (s \u2229 Ici b) a :=\n  \u27e8fun _ hx => ha.1 hx.1, fun c hc =>\n    have hbc : b \u2264 c := hc \u27e8hb, le_rfl\u27e9\n    ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc \u27e8hx, hbx\u27e9\u27e9\n#align is_lub.inter_Ici_of_mem IsLUB.inter_Ici_of_mem\n\ntheorem IsGLB.inter_Iic_of_mem [LinearOrder \u03b3] {s : Set \u03b3} {a b : \u03b3} (ha : IsGLB s a) (hb : b \u2208 s) :\n    IsGLB (s \u2229 Iic b) a :=\n  ha.dual.inter_Ici_of_mem hb\n#align is_glb.inter_Iic_of_mem IsGLB.inter_Iic_of_mem\n\ntheorem bddAbove_iff_exists_ge [SemilatticeSup \u03b3] {s : Set \u03b3} (x\u2080 : \u03b3) :\n    BddAbove s \u2194 \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x := by\n  rw [bddAbove_def, exists_ge_and_iff_exists]\n  exact Monotone.ball fun x _ => monotone_le\n#align bdd_above_iff_exists_ge bddAbove_iff_exists_ge\n\ntheorem bddBelow_iff_exists_le [SemilatticeInf \u03b3] {s : Set \u03b3} (x\u2080 : \u03b3) :\n    BddBelow s \u2194 \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\n  bddAbove_iff_exists_ge (toDual x\u2080)\n#align bdd_below_iff_exists_le bddBelow_iff_exists_le\n\ntheorem BddAbove.exists_ge [SemilatticeSup \u03b3] {s : Set \u03b3} (hs : BddAbove s) (x\u2080 : \u03b3) :\n    \u2203 x, x\u2080 \u2264 x \u2227 \u2200 y \u2208 s, y \u2264 x :=\n  (bddAbove_iff_exists_ge x\u2080).mp hs\n#align bdd_above.exists_ge BddAbove.exists_ge\n\ntheorem BddBelow.exists_le [SemilatticeInf \u03b3] {s : Set \u03b3} (hs : BddBelow s) (x\u2080 : \u03b3) :\n    \u2203 x, x \u2264 x\u2080 \u2227 \u2200 y \u2208 s, x \u2264 y :=\n  (bddBelow_iff_exists_le x\u2080).mp hs\n#align bdd_below.exists_le BddBelow.exists_le\n\n/-!\n### Specific sets\n#### Unbounded intervals\n-/\n\n\ntheorem isLeast_Ici : IsLeast (Ici a) a :=\n  \u27e8left_mem_Ici, fun _ => id\u27e9\n#align is_least_Ici isLeast_Ici\n\ntheorem isGreatest_Iic : IsGreatest (Iic a) a :=\n  \u27e8right_mem_Iic, fun _ => id\u27e9\n#align is_greatest_Iic isGreatest_Iic\n\ntheorem isLUB_Iic : IsLUB (Iic a) a :=\n  isGreatest_Iic.isLUB\n#align is_lub_Iic isLUB_Iic\n\ntheorem isGLB_Ici : IsGLB (Ici a) a :=\n  isLeast_Ici.isGLB\n#align is_glb_Ici isGLB_Ici\n\ntheorem upperBounds_Iic : upperBounds (Iic a) = Ici a :=\n  isLUB_Iic.upperBounds_eq\n#align upper_bounds_Iic upperBounds_Iic\n\ntheorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a :=\n  isGLB_Ici.lowerBounds_eq\n#align lower_bounds_Ici lowerBounds_Ici\n\ntheorem bddAbove_Iic : BddAbove (Iic a) :=\n  isLUB_Iic.bddAbove\n#align bdd_above_Iic bddAbove_Iic\n\ntheorem bddBelow_Ici : BddBelow (Ici a) :=\n  isGLB_Ici.bddBelow\n#align bdd_below_Ici bddBelow_Ici\n\ntheorem bddAbove_Iio : BddAbove (Iio a) :=\n  \u27e8a, fun _ hx => le_of_lt hx\u27e9\n#align bdd_above_Iio bddAbove_Iio\n\ntheorem bddBelow_Ioi : BddBelow (Ioi a) :=\n  \u27e8a, fun _ hx => le_of_lt hx\u27e9\n#align bdd_below_Ioi bddBelow_Ioi\n\ntheorem lub_Iio_le (a : \u03b1) (hb : IsLUB (Iio a) b) : b \u2264 a :=\n  (isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk\n#align lub_Iio_le lub_Iio_le\n\ntheorem le_glb_Ioi (a : \u03b1) (hb : IsGLB (Ioi a) b) : a \u2264 b :=\n  @lub_Iio_le \u03b1\u1d52\u1d48 _ _ a hb\n#align le_glb_Ioi le_glb_Ioi\n\ntheorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder \u03b3] {j : \u03b3} (i : \u03b3) (hj : IsLUB (Iio i) j) :\n    j = i \u2228 Iio i = Iic j := by\n  cases' eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i\n  \u00b7 exact Or.inl hj_eq_i\n  \u00b7 right\n    exact Set.ext fun k => \u27e8fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i\u27e9\n#align lub_Iio_eq_self_or_Iio_eq_Iic lub_Iio_eq_self_or_Iio_eq_Iic\n\ntheorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder \u03b3] {j : \u03b3} (i : \u03b3) (hj : IsGLB (Ioi i) j) :\n    j = i \u2228 Ioi i = Ici j :=\n  @lub_Iio_eq_self_or_Iio_eq_Iic \u03b3\u1d52\u1d48 _ j i hj\n#align glb_Ioi_eq_self_or_Ioi_eq_Ici glb_Ioi_eq_self_or_Ioi_eq_Ici\n\nsection\n\nvariable [LinearOrder \u03b3]\n\ntheorem exists_lub_Iio (i : \u03b3) : \u2203 j, IsLUB (Iio i) j := by\n  by_cases h_exists_lt : \u2203 j, j \u2208 upperBounds (Iio i) \u2227 j < i\n  \u00b7 obtain \u27e8j, hj_ub, hj_lt_i\u27e9 := h_exists_lt\n    exact \u27e8j, hj_ub, fun k hk_ub => hk_ub hj_lt_i\u27e9\n  \u00b7 refine' \u27e8i, fun j hj => le_of_lt hj, _\u27e9\n    rw [mem_lowerBounds]\n    by_contra h\n    refine' h_exists_lt _\n    push_neg at h\n    exact h\n#align exists_lub_Iio exists_lub_Iio\n\ntheorem exists_glb_Ioi (i : \u03b3) : \u2203 j, IsGLB (Ioi i) j :=\n  @exists_lub_Iio \u03b3\u1d52\u1d48 _ i\n#align exists_glb_Ioi exists_glb_Ioi\n\nvariable [DenselyOrdered \u03b3]\n\ntheorem isLUB_Iio {a : \u03b3} : IsLUB (Iio a) a :=\n  \u27e8fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_ge_of_dense hy\u27e9\n#align is_lub_Iio isLUB_Iio\n\ntheorem isGLB_Ioi {a : \u03b3} : IsGLB (Ioi a) a :=\n  @isLUB_Iio \u03b3\u1d52\u1d48 _ _ a\n#align is_glb_Ioi isGLB_Ioi\n\ntheorem upperBounds_Iio {a : \u03b3} : upperBounds (Iio a) = Ici a :=\n  isLUB_Iio.upperBounds_eq\n#align upper_bounds_Iio upperBounds_Iio\n\ntheorem lowerBounds_Ioi {a : \u03b3} : lowerBounds (Ioi a) = Iic a :=\n  isGLB_Ioi.lowerBounds_eq\n#align lower_bounds_Ioi lowerBounds_Ioi\n\nend\n\n/-!\n#### Singleton\n-/\n\n\ntheorem isGreatest_singleton : IsGreatest {a} a :=\n  \u27e8mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx\u27e9\n#align is_greatest_singleton isGreatest_singleton\n\ntheorem isLeast_singleton : IsLeast {a} a :=\n  @isGreatest_singleton \u03b1\u1d52\u1d48 _ a\n#align is_least_singleton isLeast_singleton\n\ntheorem isLUB_singleton : IsLUB {a} a :=\n  isGreatest_singleton.isLUB\n#align is_lub_singleton isLUB_singleton\n\ntheorem isGLB_singleton : IsGLB {a} a :=\n  isLeast_singleton.isGLB\n#align is_glb_singleton isGLB_singleton\n\ntheorem bddAbove_singleton : BddAbove ({a} : Set \u03b1) :=\n  isLUB_singleton.bddAbove\n#align bdd_above_singleton bddAbove_singleton\n\ntheorem bddBelow_singleton : BddBelow ({a} : Set \u03b1) :=\n  isGLB_singleton.bddBelow\n#align bdd_below_singleton bddBelow_singleton\n\n@[simp]\ntheorem upperBounds_singleton : upperBounds {a} = Ici a :=\n  isLUB_singleton.upperBounds_eq\n#align upper_bounds_singleton upperBounds_singleton\n\n@[simp]\ntheorem lowerBounds_singleton : lowerBounds {a} = Iic a :=\n  isGLB_singleton.lowerBounds_eq\n#align lower_bounds_singleton lowerBounds_singleton\n\n/-!\n#### Bounded intervals\n-/\n\n\ntheorem bddAbove_Icc : BddAbove (Icc a b) :=\n  \u27e8b, fun _ => And.right\u27e9\n#align bdd_above_Icc bddAbove_Icc\n\ntheorem bddBelow_Icc : BddBelow (Icc a b) :=\n  \u27e8a, fun _ => And.left\u27e9\n#align bdd_below_Icc bddBelow_Icc\n\ntheorem bddAbove_Ico : BddAbove (Ico a b) :=\n  bddAbove_Icc.mono Ico_subset_Icc_self\n#align bdd_above_Ico bddAbove_Ico\n\ntheorem bddBelow_Ico : BddBelow (Ico a b) :=\n  bddBelow_Icc.mono Ico_subset_Icc_self\n#align bdd_below_Ico bddBelow_Ico\n\ntheorem bddAbove_Ioc : BddAbove (Ioc a b) :=\n  bddAbove_Icc.mono Ioc_subset_Icc_self\n#align bdd_above_Ioc bddAbove_Ioc\n\ntheorem bddBelow_Ioc : BddBelow (Ioc a b) :=\n  bddBelow_Icc.mono Ioc_subset_Icc_self\n#align bdd_below_Ioc bddBelow_Ioc\n\ntheorem bddAbove_Ioo : BddAbove (Ioo a b) :=\n  bddAbove_Icc.mono Ioo_subset_Icc_self\n#align bdd_above_Ioo bddAbove_Ioo\n\ntheorem bddBelow_Ioo : BddBelow (Ioo a b) :=\n  bddBelow_Icc.mono Ioo_subset_Icc_self\n#align bdd_below_Ioo bddBelow_Ioo\n\ntheorem isGreatest_Icc (h : a \u2264 b) : IsGreatest (Icc a b) b :=\n  \u27e8right_mem_Icc.2 h, fun _ => And.right\u27e9\n#align is_greatest_Icc isGreatest_Icc\n\ntheorem isLUB_Icc (h : a \u2264 b) : IsLUB (Icc a b) b :=\n  (isGreatest_Icc h).isLUB\n#align is_lub_Icc isLUB_Icc\n\ntheorem upperBounds_Icc (h : a \u2264 b) : upperBounds (Icc a b) = Ici b :=\n  (isLUB_Icc h).upperBounds_eq\n#align upper_bounds_Icc upperBounds_Icc\n\ntheorem isLeast_Icc (h : a \u2264 b) : IsLeast (Icc a b) a :=\n  \u27e8left_mem_Icc.2 h, fun _ => And.left\u27e9\n#align is_least_Icc isLeast_Icc\n\ntheorem isGLB_Icc (h : a \u2264 b) : IsGLB (Icc a b) a :=\n  (isLeast_Icc h).isGLB\n#align is_glb_Icc isGLB_Icc\n\ntheorem lowerBounds_Icc (h : a \u2264 b) : lowerBounds (Icc a b) = Iic a :=\n  (isGLB_Icc h).lowerBounds_eq\n#align lower_bounds_Icc lowerBounds_Icc\n\ntheorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b :=\n  \u27e8right_mem_Ioc.2 h, fun _ => And.right\u27e9\n#align is_greatest_Ioc isGreatest_Ioc\n\ntheorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b :=\n  (isGreatest_Ioc h).isLUB\n#align is_lub_Ioc isLUB_Ioc\n\ntheorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b :=\n  (isLUB_Ioc h).upperBounds_eq\n#align upper_bounds_Ioc upperBounds_Ioc\n\ntheorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a :=\n  \u27e8left_mem_Ico.2 h, fun _ => And.left\u27e9\n#align is_least_Ico isLeast_Ico\n\ntheorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a :=\n  (isLeast_Ico h).isGLB\n#align is_glb_Ico isGLB_Ico\n\ntheorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a :=\n  (isGLB_Ico h).lowerBounds_eq\n#align lower_bounds_Ico lowerBounds_Ico\n\nsection\n\nvariable [SemilatticeSup \u03b3] [DenselyOrdered \u03b3]\n\ntheorem isGLB_Ioo {a b : \u03b3} (h : a < b) : IsGLB (Ioo a b) a :=\n  \u27e8fun x hx => hx.1.le, fun x hx => by\n    cases' eq_or_lt_of_le (le_sup_right : a \u2264 x \u2294 a) with h\u2081 h\u2082\n    \u00b7 exact h\u2081.symm \u25b8 le_sup_left\n    obtain \u27e8y, lty, ylt\u27e9 := exists_between h\u2082\n    apply (not_lt_of_le (sup_le (hx \u27e8lty, ylt.trans_le (sup_le _ h.le)\u27e9) lty.le) ylt).elim\n    obtain \u27e8u, au, ub\u27e9 := exists_between h\n    apply (hx \u27e8au, ub\u27e9).trans ub.le\u27e9\n#align is_glb_Ioo isGLB_Ioo\n\ntheorem lowerBounds_Ioo {a b : \u03b3} (hab : a < b) : lowerBounds (Ioo a b) = Iic a :=\n  (isGLB_Ioo hab).lowerBounds_eq\n#align lower_bounds_Ioo lowerBounds_Ioo\n\ntheorem isGLB_Ioc {a b : \u03b3} (hab : a < b) : IsGLB (Ioc a b) a :=\n  (isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self\n#align is_glb_Ioc isGLB_Ioc\n\ntheorem lowerBounds_Ioc {a b : \u03b3} (hab : a < b) : lowerBounds (Ioc a b) = Iic a :=\n  (isGLB_Ioc hab).lowerBounds_eq\n#align lower_bound_Ioc lowerBounds_Ioc\n\nend\n\nsection\n\nvariable [SemilatticeInf \u03b3] [DenselyOrdered \u03b3]\n\ntheorem isLUB_Ioo {a b : \u03b3} (hab : a < b) : IsLUB (Ioo a b) b := by\n  simpa only [dual_Ioo] using isGLB_Ioo hab.dual\n#align is_lub_Ioo isLUB_Ioo\n\ntheorem upperBounds_Ioo {a b : \u03b3} (hab : a < b) : upperBounds (Ioo a b) = Ici b :=\n  (isLUB_Ioo hab).upperBounds_eq\n#align upper_bounds_Ioo upperBounds_Ioo\n\ntheorem isLUB_Ico {a b : \u03b3} (hab : a < b) : IsLUB (Ico a b) b := by\n  simpa only [dual_Ioc] using isGLB_Ioc hab.dual\n#align is_lub_Ico isLUB_Ico\n\ntheorem upperBounds_Ico {a b : \u03b3} (hab : a < b) : upperBounds (Ico a b) = Ici b :=\n  (isLUB_Ico hab).upperBounds_eq\n#align upper_bounds_Ico upperBounds_Ico\n\nend\n\ntheorem bddBelow_iff_subset_Ici : BddBelow s \u2194 \u2203 a, s \u2286 Ici a :=\n  Iff.rfl\n#align bdd_below_iff_subset_Ici bddBelow_iff_subset_Ici\n\ntheorem bddAbove_iff_subset_Iic : BddAbove s \u2194 \u2203 a, s \u2286 Iic a :=\n  Iff.rfl\n#align bdd_above_iff_subset_Iic bddAbove_iff_subset_Iic\n\ntheorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s \u2227 BddAbove s \u2194 \u2203 a b, s \u2286 Icc a b := by\n  simp [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici,\n    bddAbove_iff_subset_Iic, exists_and_left, exists_and_right]\n#align bdd_below_bdd_above_iff_subset_Icc bddBelow_bddAbove_iff_subset_Icc\n\n/-!\n#### Univ\n-/\n\n@[simp] theorem isGreatest_univ_iff : IsGreatest univ a \u2194 IsTop a := by\n  simp [IsGreatest, mem_upperBounds, IsTop]\n#align is_greatest_univ_iff isGreatest_univ_iff\n\ntheorem isGreatest_univ [OrderTop \u03b1] : IsGreatest (univ : Set \u03b1) \u22a4 :=\n  isGreatest_univ_iff.2 isTop_top\n#align is_greatest_univ isGreatest_univ\n\n@[simp]\ntheorem OrderTop.upperBounds_univ [PartialOrder \u03b3] [OrderTop \u03b3] :\n    upperBounds (univ : Set \u03b3) = {\u22a4} := by rw [isGreatest_univ.upperBounds_eq, Ici_top]\n#align order_top.upper_bounds_univ OrderTop.upperBounds_univ\n\ntheorem isLUB_univ [OrderTop \u03b1] : IsLUB (univ : Set \u03b1) \u22a4 :=\n  isGreatest_univ.isLUB\n#align is_lub_univ isLUB_univ\n\n@[simp]\ntheorem OrderBot.lowerBounds_univ [PartialOrder \u03b3] [OrderBot \u03b3] :\n    lowerBounds (univ : Set \u03b3) = {\u22a5} :=\n  @OrderTop.upperBounds_univ \u03b3\u1d52\u1d48 _ _\n#align order_bot.lower_bounds_univ OrderBot.lowerBounds_univ\n\n@[simp] theorem isLeast_univ_iff : IsLeast univ a \u2194 IsBot a :=\n  @isGreatest_univ_iff \u03b1\u1d52\u1d48 _ _\n#align is_least_univ_iff isLeast_univ_iff\n\ntheorem isLeast_univ [OrderBot \u03b1] : IsLeast (univ : Set \u03b1) \u22a5 :=\n  @isGreatest_univ \u03b1\u1d52\u1d48 _ _\n#align is_least_univ isLeast_univ\n\ntheorem isGLB_univ [OrderBot \u03b1] : IsGLB (univ : Set \u03b1) \u22a5 :=\n  isLeast_univ.isGLB\n#align is_glb_univ isGLB_univ\n\n@[simp]\ntheorem NoMaxOrder.upperBounds_univ [NoMaxOrder \u03b1] : upperBounds (univ : Set \u03b1) = \u2205 :=\n  eq_empty_of_subset_empty fun b hb =>\n    let \u27e8_, hx\u27e9 := exists_gt b\n    not_le_of_lt hx (hb trivial)\n#align no_max_order.upper_bounds_univ NoMaxOrder.upperBounds_univ\n\n@[simp]\ntheorem NoMinOrder.lowerBounds_univ [NoMinOrder \u03b1] : lowerBounds (univ : Set \u03b1) = \u2205 :=\n  @NoMaxOrder.upperBounds_univ \u03b1\u1d52\u1d48 _ _\n#align no_min_order.lower_bounds_univ NoMinOrder.lowerBounds_univ\n\n@[simp]\ntheorem not_bddAbove_univ [NoMaxOrder \u03b1] : \u00acBddAbove (univ : Set \u03b1) := by simp [BddAbove]\n#align not_bdd_above_univ not_bddAbove_univ\n\n@[simp]\ntheorem not_bddBelow_univ [NoMinOrder \u03b1] : \u00acBddBelow (univ : Set \u03b1) :=\n  @not_bddAbove_univ \u03b1\u1d52\u1d48 _ _\n#align not_bdd_below_univ not_bddBelow_univ\n\n/-!\n#### Empty set\n-/\n\n\n@[simp]\ntheorem upperBounds_empty : upperBounds (\u2205 : Set \u03b1) = univ := by\n  simp only [upperBounds, eq_univ_iff_forall, mem_setOf_eq, ball_empty_iff, forall_true_iff]\n#align upper_bounds_empty upperBounds_empty\n\n@[simp]\ntheorem lowerBounds_empty : lowerBounds (\u2205 : Set \u03b1) = univ :=\n  @upperBounds_empty \u03b1\u1d52\u1d48 _\n#align lower_bounds_empty lowerBounds_empty\n\n@[simp]\ntheorem bddAbove_empty [Nonempty \u03b1] : BddAbove (\u2205 : Set \u03b1) := by\n  simp only [BddAbove, upperBounds_empty, univ_nonempty]\n#align bdd_above_empty bddAbove_empty\n\n@[simp]\ntheorem bddBelow_empty [Nonempty \u03b1] : BddBelow (\u2205 : Set \u03b1) := by\n  simp only [BddBelow, lowerBounds_empty, univ_nonempty]\n#align bdd_below_empty bddBelow_empty\n\n@[simp] theorem isGLB_empty_iff : IsGLB \u2205 a \u2194 IsTop a := by\n  simp [IsGLB]\n#align is_glb_empty_iff isGLB_empty_iff\n\n@[simp] theorem isLUB_empty_iff : IsLUB \u2205 a \u2194 IsBot a :=\n  @isGLB_empty_iff \u03b1\u1d52\u1d48 _ _\n#align is_lub_empty_iff isLUB_empty_iff\n\ntheorem isGLB_empty [OrderTop \u03b1] : IsGLB \u2205 (\u22a4 : \u03b1) :=\n  isGLB_empty_iff.2 isTop_top\n#align is_glb_empty isGLB_empty\n\ntheorem isLUB_empty [OrderBot \u03b1] : IsLUB \u2205 (\u22a5 : \u03b1) :=\n  @isGLB_empty \u03b1\u1d52\u1d48 _ _\n#align is_lub_empty isLUB_empty\n\ntheorem IsLUB.nonempty [NoMinOrder \u03b1] (hs : IsLUB s a) : s.Nonempty :=\n  let \u27e8a', ha'\u27e9 := exists_lt a\n  nonempty_iff_ne_empty.2 fun h =>\n    not_le_of_lt ha' <| hs.right <| by rw [h, upperBounds_empty]; exact mem_univ _\n#align is_lub.nonempty IsLUB.nonempty\n\ntheorem IsGLB.nonempty [NoMaxOrder \u03b1] (hs : IsGLB s a) : s.Nonempty :=\n  hs.dual.nonempty\n#align is_glb.nonempty IsGLB.nonempty\n\ntheorem nonempty_of_not_bddAbove [ha : Nonempty \u03b1] (h : \u00acBddAbove s) : s.Nonempty :=\n  (Nonempty.elim ha) fun x => (not_bddAbove_iff'.1 h x).imp fun _ ha => ha.1\n#align nonempty_of_not_bdd_above nonempty_of_not_bddAbove\n\ntheorem nonempty_of_not_bddBelow [Nonempty \u03b1] (h : \u00acBddBelow s) : s.Nonempty :=\n  @nonempty_of_not_bddAbove \u03b1\u1d52\u1d48 _ _ _ h\n#align nonempty_of_not_bdd_below nonempty_of_not_bddBelow\n\n/-!\n#### insert\n-/\n\n\n/-- Adding a point to a set preserves its boundedness above. -/\n@[simp]\ntheorem bddAbove_insert [SemilatticeSup \u03b3] (a : \u03b3) {s : Set \u03b3} :\n    BddAbove (insert a s) \u2194 BddAbove s := by\n  simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and_iff]\n#align bdd_above_insert bddAbove_insert\n\ntheorem BddAbove.insert [SemilatticeSup \u03b3] (a : \u03b3) {s : Set \u03b3} (hs : BddAbove s) :\n    BddAbove (insert a s) :=\n  (bddAbove_insert a).2 hs\n#align bdd_above.insert BddAbove.insert\n\n/-- Adding a point to a set preserves its boundedness below.-/\n@[simp]\ntheorem bddBelow_insert [SemilatticeInf \u03b3] (a : \u03b3) {s : Set \u03b3} :\n    BddBelow (insert a s) \u2194 BddBelow s := by\n  simp only [insert_eq, bddBelow_union, bddBelow_singleton, true_and_iff]\n#align bdd_below_insert bddBelow_insert\n\ntheorem BddBelow.insert [SemilatticeInf \u03b3] (a : \u03b3) {s : Set \u03b3} (hs : BddBelow s) :\n    BddBelow (insert a s) :=\n  (bddBelow_insert a).2 hs\n#align bdd_below.insert BddBelow.insert\n\ntheorem IsLUB.insert [SemilatticeSup \u03b3] (a) {b} {s : Set \u03b3} (hs : IsLUB s b) :\n    IsLUB (insert a s) (a \u2294 b) := by\n  rw [insert_eq]\n  exact isLUB_singleton.union hs\n#align is_lub.insert IsLUB.insert\n\ntheorem IsGLB.insert [SemilatticeInf \u03b3] (a) {b} {s : Set \u03b3} (hs : IsGLB s b) :\n    IsGLB (insert a s) (a \u2293 b) := by\n  rw [insert_eq]\n  exact isGLB_singleton.union hs\n#align is_glb.insert IsGLB.insert\n\ntheorem IsGreatest.insert [LinearOrder \u03b3] (a) {b} {s : Set \u03b3} (hs : IsGreatest s b) :\n    IsGreatest (insert a s) (max a b) := by\n  rw [insert_eq]\n  exact isGreatest_singleton.union hs\n#align is_greatest.insert IsGreatest.insert\n\ntheorem IsLeast.insert [LinearOrder \u03b3] (a) {b} {s : Set \u03b3} (hs : IsLeast s b) :\n    IsLeast (insert a s) (min a b) := by\n  rw [insert_eq]\n  exact isLeast_singleton.union hs\n#align is_least.insert IsLeast.insert\n\n@[simp]\ntheorem upperBounds_insert (a : \u03b1) (s : Set \u03b1) :\n    upperBounds (insert a s) = Ici a \u2229 upperBounds s := by\n  rw [insert_eq, upperBounds_union, upperBounds_singleton]\n#align upper_bounds_insert upperBounds_insert\n\n@[simp]\ntheorem lowerBounds_insert (a : \u03b1) (s : Set \u03b1) :\n    lowerBounds (insert a s) = Iic a \u2229 lowerBounds s := by\n  rw [insert_eq, lowerBounds_union, lowerBounds_singleton]\n#align lower_bounds_insert lowerBounds_insert\n\n/-- When there is a global maximum, every set is bounded above. -/\n@[simp]\nprotected theorem OrderTop.bddAbove [OrderTop \u03b1] (s : Set \u03b1) : BddAbove s :=\n  \u27e8\u22a4, fun a _ => OrderTop.le_top a\u27e9\n#align order_top.bdd_above OrderTop.bddAbove\n\n/-- When there is a global minimum, every set is bounded below. -/\n@[simp]\nprotected theorem OrderBot.bddBelow [OrderBot \u03b1] (s : Set \u03b1) : BddBelow s :=\n  \u27e8\u22a5, fun a _ => OrderBot.bot_le a\u27e9\n#align order_bot.bdd_below OrderBot.bddBelow\n\n/-!\n#### Pair\n-/\n\n\ntheorem isLUB_pair [SemilatticeSup \u03b3] {a b : \u03b3} : IsLUB {a, b} (a \u2294 b) :=\n  isLUB_singleton.insert _\n#align is_lub_pair isLUB_pair\n\ntheorem isGLB_pair [SemilatticeInf \u03b3] {a b : \u03b3} : IsGLB {a, b} (a \u2293 b) :=\n  isGLB_singleton.insert _\n#align is_glb_pair isGLB_pair\n\ntheorem isLeast_pair [LinearOrder \u03b3] {a b : \u03b3} : IsLeast {a, b} (min a b) :=\n  isLeast_singleton.insert _\n#align is_least_pair isLeast_pair\n\ntheorem isGreatest_pair [LinearOrder \u03b3] {a b : \u03b3} : IsGreatest {a, b} (max a b) :=\n  isGreatest_singleton.insert _\n#align is_greatest_pair isGreatest_pair\n\n/-!\n#### Lower/upper bounds\n-/\n\n\n@[simp]\ntheorem isLUB_lowerBounds : IsLUB (lowerBounds s) a \u2194 IsGLB s a :=\n  \u27e8fun H => \u27e8fun _ hx => H.2 <| subset_upperBounds_lowerBounds s hx, H.1\u27e9, IsGreatest.isLUB\u27e9\n#align is_lub_lower_bounds isLUB_lowerBounds\n\n@[simp]\ntheorem isGLB_upperBounds : IsGLB (upperBounds s) a \u2194 IsLUB s a :=\n  @isLUB_lowerBounds \u03b1\u1d52\u1d48 _ _ _\n#align is_glb_upper_bounds isGLB_upperBounds\n\nend\n\n/-!\n### (In)equalities with the least upper bound and the greatest lower bound\n-/\n\n\nsection Preorder\n\nvariable [Preorder \u03b1] {s : Set \u03b1} {a b : \u03b1}\n\ntheorem lowerBounds_le_upperBounds (ha : a \u2208 lowerBounds s) (hb : b \u2208 upperBounds s) :\n    s.Nonempty \u2192 a \u2264 b\n  | \u27e8_, hc\u27e9 => le_trans (ha hc) (hb hc)\n#align lower_bounds_le_upper_bounds lowerBounds_le_upperBounds\n\ntheorem isGLB_le_isLUB (ha : IsGLB s a) (hb : IsLUB s b) (hs : s.Nonempty) : a \u2264 b :=\n  lowerBounds_le_upperBounds ha.1 hb.1 hs\n#align is_glb_le_is_lub isGLB_le_isLUB\n\ntheorem isLUB_lt_iff (ha : IsLUB s a) : a < b \u2194 \u2203 c \u2208 upperBounds s, c < b :=\n  \u27e8fun hb => \u27e8a, ha.1, hb\u27e9, fun \u27e8_, hcs, hcb\u27e9 => lt_of_le_of_lt (ha.2 hcs) hcb\u27e9\n#align is_lub_lt_iff isLUB_lt_iff\n\ntheorem lt_isGLB_iff (ha : IsGLB s a) : b < a \u2194 \u2203 c \u2208 lowerBounds s, b < c :=\n  isLUB_lt_iff ha.dual\n#align lt_is_glb_iff lt_isGLB_iff\n\ntheorem le_of_isLUB_le_isGLB {x y} (ha : IsGLB s a) (hb : IsLUB s b) (hab : b \u2264 a) (hx : x \u2208 s)\n    (hy : y \u2208 s) : x \u2264 y :=\n  calc\n    x \u2264 b := hb.1 hx\n    _ \u2264 a := hab\n    _ \u2264 y := ha.1 hy\n\n#align le_of_is_lub_le_is_glb le_of_isLUB_le_isGLB\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b1] {s : Set \u03b1} {a b : \u03b1}\n\ntheorem IsLeast.unique (Ha : IsLeast s a) (Hb : IsLeast s b) : a = b :=\n  le_antisymm (Ha.right Hb.left) (Hb.right Ha.left)\n#align is_least.unique IsLeast.unique\n\ntheorem IsLeast.isLeast_iff_eq (Ha : IsLeast s a) : IsLeast s b \u2194 a = b :=\n  Iff.intro Ha.unique fun h => h \u25b8 Ha\n#align is_least.is_least_iff_eq IsLeast.isLeast_iff_eq\n\ntheorem IsGreatest.unique (Ha : IsGreatest s a) (Hb : IsGreatest s b) : a = b :=\n  le_antisymm (Hb.right Ha.left) (Ha.right Hb.left)\n#align is_greatest.unique IsGreatest.unique\n\ntheorem IsGreatest.isGreatest_iff_eq (Ha : IsGreatest s a) : IsGreatest s b \u2194 a = b :=\n  Iff.intro Ha.unique fun h => h \u25b8 Ha\n#align is_greatest.is_greatest_iff_eq IsGreatest.isGreatest_iff_eq\n\ntheorem IsLUB.unique (Ha : IsLUB s a) (Hb : IsLUB s b) : a = b :=\n  IsLeast.unique Ha Hb\n#align is_lub.unique IsLUB.unique\n\ntheorem IsGLB.unique (Ha : IsGLB s a) (Hb : IsGLB s b) : a = b :=\n  IsGreatest.unique Ha Hb\n#align is_glb.unique IsGLB.unique\n\ntheorem Set.subsingleton_of_isLUB_le_isGLB (Ha : IsGLB s a) (Hb : IsLUB s b) (hab : b \u2264 a) :\n    s.Subsingleton := fun _ hx _ hy =>\n  le_antisymm (le_of_isLUB_le_isGLB Ha Hb hab hx hy) (le_of_isLUB_le_isGLB Ha Hb hab hy hx)\n#align set.subsingleton_of_is_lub_le_is_glb Set.subsingleton_of_isLUB_le_isGLB\n\ntheorem isGLB_lt_isLUB_of_ne (Ha : IsGLB s a) (Hb : IsLUB s b) {x y} (Hx : x \u2208 s) (Hy : y \u2208 s)\n    (Hxy : x \u2260 y) : a < b :=\n  lt_iff_le_not_le.2\n    \u27e8lowerBounds_le_upperBounds Ha.1 Hb.1 \u27e8x, Hx\u27e9, fun hab =>\n      Hxy <| Set.subsingleton_of_isLUB_le_isGLB Ha Hb hab Hx Hy\u27e9\n#align is_glb_lt_is_lub_of_ne isGLB_lt_isLUB_of_ne\n\nend PartialOrder\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] {s : Set \u03b1} {a b : \u03b1}\n\ntheorem lt_isLUB_iff (h : IsLUB s a) : b < a \u2194 \u2203 c \u2208 s, b < c := by\n  simp_rw [\u2190 not_le, isLUB_le_iff h, mem_upperBounds, not_forall, not_le, exists_prop]\n#align lt_is_lub_iff lt_isLUB_iff\n\ntheorem isGLB_lt_iff (h : IsGLB s a) : a < b \u2194 \u2203 c \u2208 s, c < b :=\n  lt_isLUB_iff h.dual\n#align is_glb_lt_iff isGLB_lt_iff\n\ntheorem IsLUB.exists_between (h : IsLUB s a) (hb : b < a) : \u2203 c \u2208 s, b < c \u2227 c \u2264 a :=\n  let \u27e8c, hcs, hbc\u27e9 := (lt_isLUB_iff h).1 hb\n  \u27e8c, hcs, hbc, h.1 hcs\u27e9\n#align is_lub.exists_between IsLUB.exists_between\n\ntheorem IsLUB.exists_between' (h : IsLUB s a) (h' : a \u2209 s) (hb : b < a) : \u2203 c \u2208 s, b < c \u2227 c < a :=\n  let \u27e8c, hcs, hbc, hca\u27e9 := h.exists_between hb\n  \u27e8c, hcs, hbc, hca.lt_of_ne fun hac => h' <| hac \u25b8 hcs\u27e9\n#align is_lub.exists_between' IsLUB.exists_between'\n\ntheorem IsGLB.exists_between (h : IsGLB s a) (hb : a < b) : \u2203 c \u2208 s, a \u2264 c \u2227 c < b :=\n  let \u27e8c, hcs, hbc\u27e9 := (isGLB_lt_iff h).1 hb\n  \u27e8c, hcs, h.1 hcs, hbc\u27e9\n#align is_glb.exists_between IsGLB.exists_between\n\ntheorem IsGLB.exists_between' (h : IsGLB s a) (h' : a \u2209 s) (hb : a < b) : \u2203 c \u2208 s, a < c \u2227 c < b :=\n  let \u27e8c, hcs, hac, hcb\u27e9 := h.exists_between hb\n  \u27e8c, hcs, hac.lt_of_ne fun hac => h' <| hac.symm \u25b8 hcs, hcb\u27e9\n#align is_glb.exists_between' IsGLB.exists_between'\n\nend LinearOrder\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\n\nnamespace MonotoneOn\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : Set \u03b1} (Hf : MonotoneOn f t) {a : \u03b1}\n  (Hst : s \u2286 t)\n\ntheorem mem_upperBounds_image (Has : a \u2208 upperBounds s) (Hat : a \u2208 t) :\n    f a \u2208 upperBounds (f '' s) :=\n  ball_image_of_ball fun _ H => Hf (Hst H) Hat (Has H)\n#align monotone_on.mem_upper_bounds_image MonotoneOn.mem_upperBounds_image\n\ntheorem mem_upperBounds_image_self : a \u2208 upperBounds t \u2192 a \u2208 t \u2192 f a \u2208 upperBounds (f '' t) :=\n  Hf.mem_upperBounds_image subset_rfl\n#align monotone_on.mem_upper_bounds_image_self MonotoneOn.mem_upperBounds_image_self\n\ntheorem mem_lowerBounds_image (Has : a \u2208 lowerBounds s) (Hat : a \u2208 t) :\n    f a \u2208 lowerBounds (f '' s) :=\n  ball_image_of_ball fun _ H => Hf Hat (Hst H) (Has H)\n#align monotone_on.mem_lower_bounds_image MonotoneOn.mem_lowerBounds_image\n\ntheorem mem_lowerBounds_image_self : a \u2208 lowerBounds t \u2192 a \u2208 t \u2192 f a \u2208 lowerBounds (f '' t) :=\n  Hf.mem_lowerBounds_image subset_rfl\n#align monotone_on.mem_lower_bounds_image_self MonotoneOn.mem_lowerBounds_image_self\n\ntheorem image_upperBounds_subset_upperBounds_image (Hst : s \u2286 t) :\n    f '' (upperBounds s \u2229 t) \u2286 upperBounds (f '' s) := by\n  rintro _ \u27e8a, ha, rfl\u27e9\n  exact Hf.mem_upperBounds_image Hst ha.1 ha.2\n#align monotone_on.image_upper_bounds_subset_upper_bounds_image MonotoneOn.image_upperBounds_subset_upperBounds_image\n\ntheorem image_lowerBounds_subset_lowerBounds_image :\n    f '' (lowerBounds s \u2229 t) \u2286 lowerBounds (f '' s) :=\n  Hf.dual.image_upperBounds_subset_upperBounds_image Hst\n#align monotone_on.image_lower_bounds_subset_lower_bounds_image MonotoneOn.image_lowerBounds_subset_lowerBounds_image\n\n/-- The image under a monotone function on a set `t` of a subset which has an upper bound in `t`\n  is bounded above. -/\ntheorem map_bddAbove : (upperBounds s \u2229 t).Nonempty \u2192 BddAbove (f '' s) := fun \u27e8C, hs, ht\u27e9 =>\n  \u27e8f C, Hf.mem_upperBounds_image Hst hs ht\u27e9\n#align monotone_on.map_bdd_above MonotoneOn.map_bddAbove\n\n/-- The image under a monotone function on a set `t` of a subset which has a lower bound in `t`\n  is bounded below. -/\ntheorem map_bddBelow : (lowerBounds s \u2229 t).Nonempty \u2192 BddBelow (f '' s) := fun \u27e8C, hs, ht\u27e9 =>\n  \u27e8f C, Hf.mem_lowerBounds_image Hst hs ht\u27e9\n#align monotone_on.map_bdd_below MonotoneOn.map_bddBelow\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\ntheorem map_isLeast (Ha : IsLeast t a) : IsLeast (f '' t) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image_self Ha.2 Ha.1\u27e9\n#align monotone_on.map_is_least MonotoneOn.map_isLeast\n\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\ntheorem map_isGreatest (Ha : IsGreatest t a) : IsGreatest (f '' t) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image_self Ha.2 Ha.1\u27e9\n#align monotone_on.map_is_greatest MonotoneOn.map_isGreatest\n\nend MonotoneOn\n\nnamespace AntitoneOn\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s t : Set \u03b1} (Hf : AntitoneOn f t) {a : \u03b1}\n  (Hst : s \u2286 t)\n\ntheorem mem_upperBounds_image (Has : a \u2208 lowerBounds s) : a \u2208 t \u2192 f a \u2208 upperBounds (f '' s) :=\n  Hf.dual_right.mem_lowerBounds_image Hst Has\n#align antitone_on.mem_upper_bounds_image AntitoneOn.mem_upperBounds_image\n\ntheorem mem_upperBounds_image_self : a \u2208 lowerBounds t \u2192 a \u2208 t \u2192 f a \u2208 upperBounds (f '' t) :=\n  Hf.dual_right.mem_lowerBounds_image_self\n#align antitone_on.mem_upper_bounds_image_self AntitoneOn.mem_upperBounds_image_self\n\ntheorem mem_lowerBounds_image : a \u2208 upperBounds s \u2192 a \u2208 t \u2192 f a \u2208 lowerBounds (f '' s) :=\n  Hf.dual_right.mem_upperBounds_image Hst\n#align antitone_on.mem_lower_bounds_image AntitoneOn.mem_lowerBounds_image\n\ntheorem mem_lowerBounds_image_self : a \u2208 upperBounds t \u2192 a \u2208 t \u2192 f a \u2208 lowerBounds (f '' t) :=\n  Hf.dual_right.mem_upperBounds_image_self\n#align antitone_on.mem_lower_bounds_image_self AntitoneOn.mem_lowerBounds_image_self\n\ntheorem image_lowerBounds_subset_upperBounds_image :\n    f '' (lowerBounds s \u2229 t) \u2286 upperBounds (f '' s) :=\n  Hf.dual_right.image_lowerBounds_subset_lowerBounds_image Hst\n#align antitone_on.image_lower_bounds_subset_upper_bounds_image AntitoneOn.image_lowerBounds_subset_upperBounds_image\n\ntheorem image_upperBounds_subset_lowerBounds_image :\n    f '' (upperBounds s \u2229 t) \u2286 lowerBounds (f '' s) :=\n  Hf.dual_right.image_upperBounds_subset_upperBounds_image Hst\n#align antitone_on.image_upper_bounds_subset_lower_bounds_image AntitoneOn.image_upperBounds_subset_lowerBounds_image\n\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\ntheorem map_bddAbove : (upperBounds s \u2229 t).Nonempty \u2192 BddBelow (f '' s) :=\n  Hf.dual_right.map_bddAbove Hst\n#align antitone_on.map_bdd_above AntitoneOn.map_bddAbove\n\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\ntheorem map_bddBelow : (lowerBounds s \u2229 t).Nonempty \u2192 BddAbove (f '' s) :=\n  Hf.dual_right.map_bddBelow Hst\n#align antitone_on.map_bdd_below AntitoneOn.map_bddBelow\n\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\ntheorem map_isGreatest : IsGreatest t a \u2192 IsLeast (f '' t) (f a) :=\n  Hf.dual_right.map_isGreatest\n#align antitone_on.map_is_greatest AntitoneOn.map_isGreatest\n\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\ntheorem map_isLeast : IsLeast t a \u2192 IsGreatest (f '' t) (f a) :=\n  Hf.dual_right.map_isLeast\n#align antitone_on.map_is_least AntitoneOn.map_isLeast\n\nend AntitoneOn\n\nnamespace Monotone\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (Hf : Monotone f) {a : \u03b1} {s : Set \u03b1}\n\ntheorem mem_upperBounds_image (Ha : a \u2208 upperBounds s) : f a \u2208 upperBounds (f '' s) :=\n  ball_image_of_ball fun _ H => Hf (Ha H)\n#align monotone.mem_upper_bounds_image Monotone.mem_upperBounds_image\n\ntheorem mem_lowerBounds_image (Ha : a \u2208 lowerBounds s) : f a \u2208 lowerBounds (f '' s) :=\n  ball_image_of_ball fun _ H => Hf (Ha H)\n#align monotone.mem_lower_bounds_image Monotone.mem_lowerBounds_image\n\ntheorem image_upperBounds_subset_upperBounds_image : f '' upperBounds s \u2286 upperBounds (f '' s) := by\n  rintro _ \u27e8a, ha, rfl\u27e9\n  exact Hf.mem_upperBounds_image ha\n#align monotone.image_upper_bounds_subset_upper_bounds_image Monotone.image_upperBounds_subset_upperBounds_image\n\ntheorem image_lowerBounds_subset_lowerBounds_image : f '' lowerBounds s \u2286 lowerBounds (f '' s) :=\n  Hf.dual.image_upperBounds_subset_upperBounds_image\n#align monotone.image_lower_bounds_subset_lower_bounds_image Monotone.image_lowerBounds_subset_lowerBounds_image\n\n/-- The image under a monotone function of a set which is bounded above is bounded above. See also\n`bdd_above.image2`. -/\ntheorem map_bddAbove : BddAbove s \u2192 BddAbove (f '' s)\n  | \u27e8C, hC\u27e9 => \u27e8f C, Hf.mem_upperBounds_image hC\u27e9\n#align monotone.map_bdd_above Monotone.map_bddAbove\n\n/-- The image under a monotone function of a set which is bounded below is bounded below. See also\n`bdd_below.image2`. -/\ntheorem map_bddBelow : BddBelow s \u2192 BddBelow (f '' s)\n  | \u27e8C, hC\u27e9 => \u27e8f C, Hf.mem_lowerBounds_image hC\u27e9\n#align monotone.map_bdd_below Monotone.map_bddBelow\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\ntheorem map_isLeast (Ha : IsLeast s a) : IsLeast (f '' s) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image Ha.2\u27e9\n#align monotone.map_is_least Monotone.map_isLeast\n\n/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/\ntheorem map_isGreatest (Ha : IsGreatest s a) : IsGreatest (f '' s) (f a) :=\n  \u27e8mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image Ha.2\u27e9\n#align monotone.map_is_greatest Monotone.map_isGreatest\n\nend Monotone\n\nnamespace Antitone\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Antitone f) {a : \u03b1} {s : Set \u03b1}\n\ntheorem mem_upperBounds_image : a \u2208 lowerBounds s \u2192 f a \u2208 upperBounds (f '' s) :=\n  hf.dual_right.mem_lowerBounds_image\n#align antitone.mem_upper_bounds_image Antitone.mem_upperBounds_image\n\ntheorem mem_lowerBounds_image : a \u2208 upperBounds s \u2192 f a \u2208 lowerBounds (f '' s) :=\n  hf.dual_right.mem_upperBounds_image\n#align antitone.mem_lower_bounds_image Antitone.mem_lowerBounds_image\n\ntheorem image_lowerBounds_subset_upperBounds_image : f '' lowerBounds s \u2286 upperBounds (f '' s) :=\n  hf.dual_right.image_lowerBounds_subset_lowerBounds_image\n#align antitone.image_lower_bounds_subset_upper_bounds_image Antitone.image_lowerBounds_subset_upperBounds_image\n\ntheorem image_upperBounds_subset_lowerBounds_image : f '' upperBounds s \u2286 lowerBounds (f '' s) :=\n  hf.dual_right.image_upperBounds_subset_upperBounds_image\n#align antitone.image_upper_bounds_subset_lower_bounds_image Antitone.image_upperBounds_subset_lowerBounds_image\n\n/-- The image under an antitone function of a set which is bounded above is bounded below. -/\ntheorem map_bddAbove : BddAbove s \u2192 BddBelow (f '' s) :=\n  hf.dual_right.map_bddAbove\n#align antitone.map_bdd_above Antitone.map_bddAbove\n\n/-- The image under an antitone function of a set which is bounded below is bounded above. -/\ntheorem map_bddBelow : BddBelow s \u2192 BddAbove (f '' s) :=\n  hf.dual_right.map_bddBelow\n#align antitone.map_bdd_below Antitone.map_bddBelow\n\n/-- An antitone map sends a greatest element of a set to a least element of its image. -/\ntheorem map_isGreatest : IsGreatest s a \u2192 IsLeast (f '' s) (f a) :=\n  hf.dual_right.map_isGreatest\n#align antitone.map_is_greatest Antitone.map_isGreatest\n\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\ntheorem map_isLeast : IsLeast s a \u2192 IsGreatest (f '' s) (f a) :=\n  hf.dual_right.map_isLeast\n#align antitone.map_is_least Antitone.map_isLeast\n\nend Antitone\n\nsection Image2\n\nvariable [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {s : Set \u03b1} {t : Set \u03b2} {a : \u03b1}\n  {b : \u03b2}\n\nsection MonotoneMonotone\n\nvariable (h\u2080 : \u2200 b, Monotone (swap f b)) (h\u2081 : \u2200 a, Monotone (f a))\n\ntheorem mem_upperBounds_image2 (ha : a \u2208 upperBounds s) (hb : b \u2208 upperBounds t) :\n    f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2 mem_upperBounds_image2\n\ntheorem mem_lowerBounds_image2 (ha : a \u2208 lowerBounds s) (hb : b \u2208 lowerBounds t) :\n    f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2 mem_lowerBounds_image2\n\ntheorem image2_upperBounds_upperBounds_subset :\n    image2 f (upperBounds s) (upperBounds t) \u2286 upperBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2 h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_upper_bounds_subset image2_upperBounds_upperBounds_subset\n\ntheorem image2_lowerBounds_lowerBounds_subset :\n    image2 f (lowerBounds s) (lowerBounds t) \u2286 lowerBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2 h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_lower_bounds_subset image2_lowerBounds_lowerBounds_subset\n\n/-- See also `Monotone.map_bddAbove`. -/\ntheorem BddAbove.image2 : BddAbove s \u2192 BddAbove t \u2192 BddAbove (image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2 h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.image2 BddAbove.image2\n\n/-- See also `Monotone.map_bddBelow`. -/\ntheorem BddBelow.image2 : BddBelow s \u2192 BddBelow t \u2192 BddBelow (image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2 h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.image2 BddBelow.image2\n\ntheorem IsGreatest.image2 (ha : IsGreatest s a) (hb : IsGreatest t b) :\n    IsGreatest (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.image2 IsGreatest.image2\n\ntheorem IsLeast.image2 (ha : IsLeast s a) (hb : IsLeast t b) : IsLeast (image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2 h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.image2 IsLeast.image2\n\nend MonotoneMonotone\n\nsection MonotoneAntitone\n\nvariable (h\u2080 : \u2200 b, Monotone (swap f b)) (h\u2081 : \u2200 a, Antitone (f a))\n\ntheorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds (ha : a \u2208 upperBounds s)\n    (hb : b \u2208 lowerBounds t) : f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds\n\ntheorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds (ha : a \u2208 lowerBounds s)\n    (hb : b \u2208 upperBounds t) : f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds\n\ntheorem image2_upperBounds_lowerBounds_subset_upperBounds_image2 :\n    image2 f (upperBounds s) (lowerBounds t) \u2286 upperBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_lower_bounds_subset_upper_bounds_image2 image2_upperBounds_lowerBounds_subset_upperBounds_image2\n\ntheorem image2_lowerBounds_upperBounds_subset_lowerBounds_image2 :\n    image2 f (lowerBounds s) (upperBounds t) \u2286 lowerBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_upper_bounds_subset_lower_bounds_image2 image2_lowerBounds_upperBounds_subset_lowerBounds_image2\n\ntheorem BddAbove.bddAbove_image2_of_bddBelow :\n    BddAbove s \u2192 BddBelow t \u2192 BddAbove (Set.image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.bdd_above_image2_of_bdd_below BddAbove.bddAbove_image2_of_bddBelow\n\ntheorem BddBelow.bddBelow_image2_of_bddAbove :\n    BddBelow s \u2192 BddAbove t \u2192 BddBelow (Set.image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.bdd_below_image2_of_bdd_above BddBelow.bddBelow_image2_of_bddAbove\n\ntheorem IsGreatest.isGreatest_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) :\n    IsGreatest (Set.image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.is_greatest_image2_of_is_least IsGreatest.isGreatest_image2_of_isLeast\n\ntheorem IsLeast.isLeast_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) :\n    IsLeast (Set.image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.is_least_image2_of_is_greatest IsLeast.isLeast_image2_of_isGreatest\n\nend MonotoneAntitone\n\nsection AntitoneAntitone\n\nvariable (h\u2080 : \u2200 b, Antitone (swap f b)) (h\u2081 : \u2200 a, Antitone (f a))\n\ntheorem mem_upperBounds_image2_of_mem_lowerBounds (ha : a \u2208 lowerBounds s)\n    (hb : b \u2208 lowerBounds t) : f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2_of_mem_lower_bounds mem_upperBounds_image2_of_mem_lowerBounds\n\ntheorem mem_lowerBounds_image2_of_mem_upperBounds (ha : a \u2208 upperBounds s)\n    (hb : b \u2208 upperBounds t) : f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2_of_mem_upper_bounds mem_lowerBounds_image2_of_mem_upperBounds\n\ntheorem image2_upperBounds_upperBounds_subset_upperBounds_image2 :\n    image2 f (lowerBounds s) (lowerBounds t) \u2286 upperBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2_of_mem_lowerBounds h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_upper_bounds_subset_upper_bounds_image2 image2_upperBounds_upperBounds_subset_upperBounds_image2\n\ntheorem image2_lowerBounds_lowerBounds_subset_lowerBounds_image2 :\n    image2 f (upperBounds s) (upperBounds t) \u2286 lowerBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2_of_mem_upperBounds h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_lower_bounds_subset_lower_bounds_image2 image2_lowerBounds_lowerBounds_subset_lowerBounds_image2\n\ntheorem BddBelow.image2_bddAbove : BddBelow s \u2192 BddBelow t \u2192 BddAbove (Set.image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2_of_mem_lowerBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.image2_bdd_above BddBelow.image2_bddAbove\n\ntheorem BddAbove.image2_bddBelow : BddAbove s \u2192 BddAbove t \u2192 BddBelow (Set.image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2_of_mem_upperBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.image2_bdd_below BddAbove.image2_bddBelow\n\ntheorem IsLeast.isGreatest_image2 (ha : IsLeast s a) (hb : IsLeast t b) :\n    IsGreatest (Set.image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2_of_mem_lowerBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.is_greatest_image2 IsLeast.isGreatest_image2\n\ntheorem IsGreatest.isLeast_image2 (ha : IsGreatest s a) (hb : IsGreatest t b) :\n    IsLeast (Set.image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2_of_mem_upperBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.is_least_image2 IsGreatest.isLeast_image2\n\nend AntitoneAntitone\n\nsection AntitoneMonotone\n\nvariable (h\u2080 : \u2200 b, Antitone (swap f b)) (h\u2081 : \u2200 a, Monotone (f a))\n\ntheorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds (ha : a \u2208 lowerBounds s)\n    (hb : b \u2208 upperBounds t) : f a b \u2208 upperBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds\n\ntheorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds (ha : a \u2208 upperBounds s)\n    (hb : b \u2208 lowerBounds t) : f a b \u2208 lowerBounds (image2 f s t) :=\n  forall_image2_iff.2 fun _ hx _ hy => (h\u2080 _ <| ha hx).trans <| h\u2081 _ <| hb hy\n#align mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds\n\ntheorem image2_lowerBounds_upperBounds_subset_upperBounds_image2 :\n    image2 f (lowerBounds s) (upperBounds t) \u2286 upperBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\n#align image2_lower_bounds_upper_bounds_subset_upper_bounds_image2 image2_lowerBounds_upperBounds_subset_upperBounds_image2\n\ntheorem image2_upperBounds_lowerBounds_subset_lowerBounds_image2 :\n    image2 f (upperBounds s) (lowerBounds t) \u2286 lowerBounds (image2 f s t) := by\n  rintro _ \u27e8a, b, ha, hb, rfl\u27e9\n  exact mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\n#align image2_upper_bounds_lower_bounds_subset_lower_bounds_image2 image2_upperBounds_lowerBounds_subset_lowerBounds_image2\n\ntheorem BddBelow.bddAbove_image2_of_bddAbove :\n    BddBelow s \u2192 BddAbove t \u2192 BddAbove (Set.image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_below.bdd_above_image2_of_bdd_above BddBelow.bddAbove_image2_of_bddAbove\n\ntheorem BddAbove.bddBelow_image2_of_bddAbove :\n    BddAbove s \u2192 BddBelow t \u2192 BddBelow (Set.image2 f s t) := by\n  rintro \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  exact \u27e8f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h\u2080 h\u2081 ha hb\u27e9\n#align bdd_above.bdd_below_image2_of_bdd_above BddAbove.bddBelow_image2_of_bddAbove\n\ntheorem IsLeast.isGreatest_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) :\n    IsGreatest (Set.image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_least.is_greatest_image2_of_is_greatest IsLeast.isGreatest_image2_of_isGreatest\n\ntheorem IsGreatest.isLeast_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) :\n    IsLeast (Set.image2 f s t) (f a b) :=\n  \u27e8mem_image2_of_mem ha.1 hb.1,\n    mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h\u2080 h\u2081 ha.2 hb.2\u27e9\n#align is_greatest.is_least_image2_of_is_least IsGreatest.isLeast_image2_of_isLeast\n\nend AntitoneMonotone\n\nend Image2\n\ntheorem IsGLB.of_image [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n    {s : Set \u03b1} {x : \u03b1} (hx : IsGLB (f '' s) (f x)) : IsGLB s x :=\n  \u27e8fun _ hy => hf.1 <| hx.1 <| mem_image_of_mem _ hy, fun _ hy =>\n    hf.1 <| hx.2 <| Monotone.mem_lowerBounds_image (fun _ _ => hf.2) hy\u27e9\n#align is_glb.of_image IsGLB.of_image\n\ntheorem IsLUB.of_image [Preorder \u03b1] [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : \u2200 {x y}, f x \u2264 f y \u2194 x \u2264 y)\n    {s : Set \u03b1} {x : \u03b1} (hx : IsLUB (f '' s) (f x)) : IsLUB s x :=\n  \u27e8fun _ hy => hf.1 <| hx.1 <| mem_image_of_mem _ hy, fun _ hy =>\n    hf.1 <| hx.2 <| Monotone.mem_upperBounds_image (fun _ _ => hf.2) hy\u27e9\n#align is_lub.of_image IsLUB.of_image\n\ntheorem isLUB_pi {\u03c0 : \u03b1 \u2192 Type _} [\u2200 a, Preorder (\u03c0 a)] {s : Set (\u2200 a, \u03c0 a)} {f : \u2200 a, \u03c0 a} :\n    IsLUB s f \u2194 \u2200 a, IsLUB (Function.eval a '' s) (f a) := by\n  classical\n    refine'\n      \u27e8fun H a => \u27e8(Function.monotone_eval a).mem_upperBounds_image H.1, fun b hb => _\u27e9, fun H =>\n        \u27e8_, _\u27e9\u27e9\n    \u00b7 suffices h : Function.update f a b \u2208 upperBounds s from Function.update_same a b f \u25b8 H.2 h a\n      refine' fun g hg => le_update_iff.2 \u27e8hb <| mem_image_of_mem _ hg, fun i _ => H.1 hg i\u27e9\n    \u00b7 exact fun g hg a => (H a).1 (mem_image_of_mem _ hg)\n    \u00b7 exact fun g hg a => (H a).2 ((Function.monotone_eval a).mem_upperBounds_image hg)\n#align is_lub_pi isLUB_pi\n\ntheorem isGLB_pi {\u03c0 : \u03b1 \u2192 Type _} [\u2200 a, Preorder (\u03c0 a)] {s : Set (\u2200 a, \u03c0 a)} {f : \u2200 a, \u03c0 a} :\n    IsGLB s f \u2194 \u2200 a, IsGLB (Function.eval a '' s) (f a) :=\n  @isLUB_pi \u03b1 (fun a => (\u03c0 a)\u1d52\u1d48) _ s f\n#align is_glb_pi isGLB_pi\n\ntheorem isLUB_prod [Preorder \u03b1] [Preorder \u03b2] {s : Set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n    IsLUB s p \u2194 IsLUB (Prod.fst '' s) p.1 \u2227 IsLUB (Prod.snd '' s) p.2 := by\n  refine'\n    \u27e8fun H =>\n      \u27e8\u27e8monotone_fst.mem_upperBounds_image H.1, fun a ha => _\u27e9,\n        \u27e8monotone_snd.mem_upperBounds_image H.1, fun a ha => _\u27e9\u27e9,\n      fun H => \u27e8_, _\u27e9\u27e9\n  \u00b7 suffices h : (a, p.2) \u2208 upperBounds s from (H.2 h).1\n    exact fun q hq => \u27e8ha <| mem_image_of_mem _ hq, (H.1 hq).2\u27e9\n  \u00b7 suffices h : (p.1, a) \u2208 upperBounds s from (H.2 h).2\n    exact fun q hq => \u27e8(H.1 hq).1, ha <| mem_image_of_mem _ hq\u27e9\n  \u00b7 exact fun q hq => \u27e8H.1.1 <| mem_image_of_mem _ hq, H.2.1 <| mem_image_of_mem _ hq\u27e9\n  \u00b7\n    exact fun q hq =>\n      \u27e8H.1.2 <| monotone_fst.mem_upperBounds_image hq,\n        H.2.2 <| monotone_snd.mem_upperBounds_image hq\u27e9\n#align is_lub_prod isLUB_prod\n\ntheorem isGLB_prod [Preorder \u03b1] [Preorder \u03b2] {s : Set (\u03b1 \u00d7 \u03b2)} (p : \u03b1 \u00d7 \u03b2) :\n    IsGLB s p \u2194 IsGLB (Prod.fst '' s) p.1 \u2227 IsGLB (Prod.snd '' s) p.2 :=\n  @isLUB_prod \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _\n#align is_glb_prod isGLB_prod\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/Bounds/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7069095807696401}}
{"text": "/-\nCopyright (c) 2022 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n\n! This file was ported from Lean 3 source module measure_theory.measure.doubling\n! leanprover-community/mathlib commit 57ac39bd365c2f80589a700f9fbb664d3a1a30c2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.SpecialFunctions.Log.Base\nimport Mathbin.MeasureTheory.Measure.MeasureSpaceDef\n\n/-!\n# Doubling measures\n\nA doubling measure `\u03bc` on a metric space is a measure for which there exists a constant `C` such\nthat for all sufficiently small radii `\u03b5`, and for any centre, the measure of a ball of radius\n`2 * \u03b5` is bounded by `C` times the measure of the concentric ball of radius `\u03b5`.\n\nThis file records basic files on doubling measures.\n\n## Main definitions\n\n  * `is_doubling_measure`: the definition of a doubling measure (as a typeclass).\n  * `is_doubling_measure.doubling_constant`: a function yielding the doubling constant `C` appearing\n  in the definition of a doubling measure.\n-/\n\n\nnoncomputable section\n\nopen Set Filter Metric MeasureTheory TopologicalSpace\n\nopen ENNReal NNReal Topology\n\n/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`exists_measure_closedBall_le_mul] [] -/\n/-- A measure `\u03bc` is said to be a doubling measure if there exists a constant `C` such that for\nall sufficiently small radii `\u03b5`, and for any centre, the measure of a ball of radius `2 * \u03b5` is\nbounded by `C` times the measure of the concentric ball of radius `\u03b5`.\n\nNote: it is important that this definition makes a demand only for sufficiently small `\u03b5`. For\nexample we want hyperbolic space to carry the instance `is_doubling_measure volume` but volumes grow\nexponentially in hyperbolic space. To be really explicit, consider the hyperbolic plane of\ncurvature -1, the area of a disc of radius `\u03b5` is `A(\u03b5) = 2\u03c0(cosh(\u03b5) - 1)` so `A(2\u03b5)/A(\u03b5) ~ exp(\u03b5)`.\n-/\nclass IsDoublingMeasure {\u03b1 : Type _} [MetricSpace \u03b1] [MeasurableSpace \u03b1] (\u03bc : Measure \u03b1) where\n  exists_measure_closedBall_le_mul :\n    \u2203 C : \u211d\u22650, \u2200\u1da0 \u03b5 in \ud835\udcdd[>] 0, \u2200 x, \u03bc (closedBall x (2 * \u03b5)) \u2264 C * \u03bc (closedBall x \u03b5)\n#align is_doubling_measure IsDoublingMeasure\n\nnamespace IsDoublingMeasure\n\nvariable {\u03b1 : Type _} [MetricSpace \u03b1] [MeasurableSpace \u03b1] (\u03bc : Measure \u03b1) [IsDoublingMeasure \u03bc]\n\n/-- A doubling constant for a doubling measure.\n\nSee also `is_doubling_measure.scaling_constant_of`. -/\ndef doublingConstant : \u211d\u22650 :=\n  Classical.choose <| exists_measure_closedBall_le_mul \u03bc\n#align is_doubling_measure.doubling_constant IsDoublingMeasure.doublingConstant\n\ntheorem exists_measure_closedBall_le_mul' :\n    \u2200\u1da0 \u03b5 in \ud835\udcdd[>] 0, \u2200 x, \u03bc (closedBall x (2 * \u03b5)) \u2264 doublingConstant \u03bc * \u03bc (closedBall x \u03b5) :=\n  Classical.choose_spec <| exists_measure_closedBall_le_mul \u03bc\n#align is_doubling_measure.exists_measure_closed_ball_le_mul' IsDoublingMeasure.exists_measure_closedBall_le_mul'\n\ntheorem exists_eventually_forall_measure_closedBall_le_mul (K : \u211d) :\n    \u2203 C : \u211d\u22650,\n      \u2200\u1da0 \u03b5 in \ud835\udcdd[>] 0, \u2200 (x t) (ht : t \u2264 K), \u03bc (closedBall x (t * \u03b5)) \u2264 C * \u03bc (closedBall x \u03b5) :=\n  by\n  let C := doubling_constant \u03bc\n  have h\u03bc :\n    \u2200 n : \u2115, \u2200\u1da0 \u03b5 in \ud835\udcdd[>] 0, \u2200 x, \u03bc (closed_ball x (2 ^ n * \u03b5)) \u2264 \u2191(C ^ n) * \u03bc (closed_ball x \u03b5) :=\n    by\n    intro n\n    induction' n with n ih\n    \u00b7 simp\n    replace ih := eventually_nhdsWithin_pos_mul_left (two_pos : 0 < (2 : \u211d)) ih\n    refine' (ih.and (exists_measure_closed_ball_le_mul' \u03bc)).mono fun \u03b5 h\u03b5 x => _\n    calc\n      \u03bc (closed_ball x (2 ^ (n + 1) * \u03b5)) = \u03bc (closed_ball x (2 ^ n * (2 * \u03b5))) := by\n        rw [pow_succ', mul_assoc]\n      _ \u2264 \u2191(C ^ n) * \u03bc (closed_ball x (2 * \u03b5)) := (h\u03b5.1 x)\n      _ \u2264 \u2191(C ^ n) * (C * \u03bc (closed_ball x \u03b5)) := (ENNReal.mul_left_mono (h\u03b5.2 x))\n      _ = \u2191(C ^ (n + 1)) * \u03bc (closed_ball x \u03b5) := by rw [\u2190 mul_assoc, pow_succ', ENNReal.coe_mul]\n      \n  rcases lt_or_le K 1 with (hK | hK)\n  \u00b7 refine' \u27e81, _\u27e9\n    simp only [ENNReal.coe_one, one_mul]\n    exact\n      eventually_mem_nhds_within.mono fun \u03b5 h\u03b5 x t ht =>\n        measure_mono <| closed_ball_subset_closed_ball (by nlinarith [mem_Ioi.mp h\u03b5])\n  \u00b7 refine'\n      \u27e8C ^ \u2308Real.logb 2 K\u2309\u208a,\n        ((h\u03bc \u2308Real.logb 2 K\u2309\u208a).And eventually_mem_nhdsWithin).mono fun \u03b5 h\u03b5 x t ht =>\n          le_trans (measure_mono <| closed_ball_subset_closed_ball _) (h\u03b5.1 x)\u27e9\n    refine' mul_le_mul_of_nonneg_right (ht.trans _) (mem_Ioi.mp h\u03b5.2).le\n    conv_lhs => rw [\u2190 Real.rpow_logb two_pos (by norm_num) (by linarith : 0 < K)]\n    rw [\u2190 Real.rpow_nat_cast]\n    exact Real.rpow_le_rpow_of_exponent_le one_le_two (Nat.le_ceil (Real.logb 2 K))\n#align is_doubling_measure.exists_eventually_forall_measure_closed_ball_le_mul IsDoublingMeasure.exists_eventually_forall_measure_closedBall_le_mul\n\n/-- A variant of `is_doubling_measure.doubling_constant` which allows for scaling the radius by\nvalues other than `2`. -/\ndef scalingConstantOf (K : \u211d) : \u211d\u22650 :=\n  max (Classical.choose <| exists_eventually_forall_measure_closedBall_le_mul \u03bc K) 1\n#align is_doubling_measure.scaling_constant_of IsDoublingMeasure.scalingConstantOf\n\n@[simp]\ntheorem one_le_scalingConstantOf (K : \u211d) : 1 \u2264 scalingConstantOf \u03bc K :=\n  le_max_of_le_right <| le_refl 1\n#align is_doubling_measure.one_le_scaling_constant_of IsDoublingMeasure.one_le_scalingConstantOf\n\ntheorem eventually_measure_mul_le_scalingConstantOf_mul (K : \u211d) :\n    \u2203 R : \u211d,\n      0 < R \u2227\n        \u2200 (x t r) (ht : t \u2208 Ioc 0 K) (hr : r \u2264 R),\n          \u03bc (closedBall x (t * r)) \u2264 scalingConstantOf \u03bc K * \u03bc (closedBall x r) :=\n  by\n  have h := Classical.choose_spec (exists_eventually_forall_measure_closed_ball_le_mul \u03bc K)\n  rcases mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.1 h with \u27e8R, Rpos, hR\u27e9\n  refine' \u27e8R, Rpos, fun x t r ht hr => _\u27e9\n  rcases lt_trichotomy r 0 with (rneg | rfl | rpos)\n  \u00b7 have : t * r < 0 := mul_neg_of_pos_of_neg ht.1 rneg\n    simp only [closed_ball_eq_empty.2 this, measure_empty, zero_le']\n  \u00b7 simp only [MulZeroClass.mul_zero, closed_ball_zero]\n    refine' le_mul_of_one_le_of_le _ le_rfl\n    apply ENNReal.one_le_coe_iff.2 (le_max_right _ _)\n  \u00b7 apply (hR \u27e8rpos, hr\u27e9 x t ht.2).trans _\n    exact mul_le_mul_right' (ENNReal.coe_le_coe.2 (le_max_left _ _)) _\n#align is_doubling_measure.eventually_measure_mul_le_scaling_constant_of_mul IsDoublingMeasure.eventually_measure_mul_le_scalingConstantOf_mul\n\ntheorem eventually_measure_le_scaling_constant_mul (K : \u211d) :\n    \u2200\u1da0 r in \ud835\udcdd[>] 0, \u2200 x, \u03bc (closedBall x (K * r)) \u2264 scalingConstantOf \u03bc K * \u03bc (closedBall x r) :=\n  by\n  filter_upwards [Classical.choose_spec\n      (exists_eventually_forall_measure_closed_ball_le_mul \u03bc K)]with r hr x\n  exact (hr x K le_rfl).trans (mul_le_mul_right' (ENNReal.coe_le_coe.2 (le_max_left _ _)) _)\n#align is_doubling_measure.eventually_measure_le_scaling_constant_mul IsDoublingMeasure.eventually_measure_le_scaling_constant_mul\n\ntheorem eventually_measure_le_scaling_constant_mul' (K : \u211d) (hK : 0 < K) :\n    \u2200\u1da0 r in \ud835\udcdd[>] 0, \u2200 x, \u03bc (closedBall x r) \u2264 scalingConstantOf \u03bc K\u207b\u00b9 * \u03bc (closedBall x (K * r)) :=\n  by\n  convert eventually_nhdsWithin_pos_mul_left hK (eventually_measure_le_scaling_constant_mul \u03bc K\u207b\u00b9)\n  ext\n  simp [inv_mul_cancel_left\u2080 hK.ne']\n#align is_doubling_measure.eventually_measure_le_scaling_constant_mul' IsDoublingMeasure.eventually_measure_le_scaling_constant_mul'\n\n/-- A scale below which the doubling measure `\u03bc` satisfies good rescaling properties when one\nmultiplies the radius of balls by at most `K`, as stated\nin `measure_mul_le_scaling_constant_of_mul`. -/\ndef scalingScaleOf (K : \u211d) : \u211d :=\n  (eventually_measure_mul_le_scalingConstantOf_mul \u03bc K).some\n#align is_doubling_measure.scaling_scale_of IsDoublingMeasure.scalingScaleOf\n\ntheorem scalingScaleOf_pos (K : \u211d) : 0 < scalingScaleOf \u03bc K :=\n  (eventually_measure_mul_le_scalingConstantOf_mul \u03bc K).choose_spec.1\n#align is_doubling_measure.scaling_scale_of_pos IsDoublingMeasure.scalingScaleOf_pos\n\ntheorem measure_mul_le_scalingConstantOf_mul {K : \u211d} {x : \u03b1} {t r : \u211d} (ht : t \u2208 Ioc 0 K)\n    (hr : r \u2264 scalingScaleOf \u03bc K) :\n    \u03bc (closedBall x (t * r)) \u2264 scalingConstantOf \u03bc K * \u03bc (closedBall x r) :=\n  (eventually_measure_mul_le_scalingConstantOf_mul \u03bc K).choose_spec.2 x t r ht hr\n#align is_doubling_measure.measure_mul_le_scaling_constant_of_mul IsDoublingMeasure.measure_mul_le_scalingConstantOf_mul\n\nend IsDoublingMeasure\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Measure/Doubling.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7068993317845199}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.category.Mon.limits\nimport algebra.category.Group.preadditive\nimport category_theory.over\nimport category_theory.limits.concrete_category\nimport category_theory.limits.shapes.concrete_category\nimport group_theory.subgroup.basic\n\n/-!\n# The category of (commutative) (additive) groups has all limits\n\nFurther, these limits are preserved by the forgetful functor --- that is,\nthe underlying types are just the limits in the category of types.\n\n-/\n\nopen category_theory\nopen category_theory.limits\n\nuniverses v u\n\nnoncomputable theory\n\nvariables {J : Type v} [small_category J]\n\nnamespace Group\n\n@[to_additive]\ninstance group_obj (F : J \u2964 Group.{max v u}) (j) :\n  group ((F \u22d9 forget Group).obj j) :=\nby { change group (F.obj j), apply_instance }\n\n/--\nThe flat sections of a functor into `Group` form a subgroup of all sections.\n-/\n@[to_additive\n  \"The flat sections of a functor into `AddGroup` form an additive subgroup of all sections.\"]\ndef sections_subgroup (F : J \u2964 Group) :\n  subgroup (\u03a0 j, F.obj j) :=\n{ carrier := (F \u22d9 forget Group).sections,\n  inv_mem' := \u03bb a ah j j' f,\n  begin\n    simp only [forget_map_eq_coe, functor.comp_map, pi.inv_apply, monoid_hom.map_inv, inv_inj],\n    dsimp [functor.sections] at ah,\n    rw ah f,\n  end,\n  ..(Mon.sections_submonoid (F \u22d9 forget\u2082 Group Mon)) }\n\n@[to_additive]\ninstance limit_group (F : J \u2964 Group.{max v u}) :\n  group (types.limit_cone (F \u22d9 forget Group)).X :=\nbegin\n  change group (sections_subgroup F),\n  apply_instance,\nend\n\n/-- We show that the forgetful functor `Group \u2964 Mon` creates limits.\n\nAll we need to do is notice that the limit point has a `group` instance available, and then reuse\nthe existing limit. -/\n@[to_additive \"We show that the forgetful functor `AddGroup \u2964 AddMon` creates limits.\n\nAll we need to do is notice that the limit point has an `add_group` instance available, and then\nreuse the existing limit.\"]\ninstance (F : J \u2964 Group.{max v u}) : creates_limit F (forget\u2082 Group.{max v u} Mon.{max v u}) :=\ncreates_limit_of_reflects_iso (\u03bb c' t,\n{ lifted_cone :=\n  { X := Group.of (types.limit_cone (F \u22d9 forget Group)).X,\n    \u03c0 :=\n    { app := Mon.limit_\u03c0_monoid_hom (F \u22d9 forget\u2082 Group Mon.{max v u}),\n      naturality' :=\n        (Mon.has_limits.limit_cone (F \u22d9 forget\u2082 Group Mon.{max v u})).\u03c0.naturality, } },\n  valid_lift := by apply is_limit.unique_up_to_iso (Mon.has_limits.limit_cone_is_limit _) t,\n  makes_limit := is_limit.of_faithful (forget\u2082 Group Mon.{max v u})\n    (Mon.has_limits.limit_cone_is_limit _) (\u03bb s, _) (\u03bb s, rfl) })\n\n/--\nA choice of limit cone for a functor into `Group`.\n(Generally, you'll just want to use `limit F`.)\n-/\n@[to_additive \"A choice of limit cone for a functor into `Group`.\n(Generally, you'll just want to use `limit F`.)\"]\ndef limit_cone (F : J \u2964 Group.{max v u}) : cone F :=\nlift_limit (limit.is_limit (F \u22d9 (forget\u2082 Group Mon.{max v u})))\n\n/--\nThe chosen cone is a limit cone.\n(Generally, you'll just want to use `limit.cone F`.)\n-/\n@[to_additive \"The chosen cone is a limit cone.\n(Generally, you'll just want to use `limit.cone F`.)\"]\ndef limit_cone_is_limit (F : J \u2964 Group.{max v u}) : is_limit (limit_cone F) :=\nlifted_limit_is_limit _\n\n/-- The category of groups has all limits. -/\n@[to_additive \"The category of additive groups has all limits.\"]\ninstance has_limits_of_size : has_limits_of_size.{v v} Group.{max v u} :=\n{ has_limits_of_shape := \u03bb J \ud835\udca5, by exactI\n  { has_limit := \u03bb F, has_limit_of_created F (forget\u2082 Group Mon.{max v u}) } }\n\n@[to_additive]\ninstance has_limits : has_limits Group.{u} := Group.has_limits_of_size.{u u}\n\n/-- The forgetful functor from groups to monoids preserves all limits.\n\nThis means the underlying monoid of a limit can be computed as a limit in the category of monoids.\n-/\n@[to_additive AddGroup.forget\u2082_AddMon_preserves_limits \"The forgetful functor from additive groups\nto additive monoids preserves all limits.\n\nThis means the underlying additive monoid of a limit can be computed as a limit in the category of\nadditive monoids.\"]\ninstance forget\u2082_Mon_preserves_limits_of_size :\n  preserves_limits_of_size.{v v} (forget\u2082 Group Mon.{max v u}) :=\n{ preserves_limits_of_shape := \u03bb J \ud835\udca5,\n  { preserves_limit := \u03bb F, by apply_instance } }\n\n@[to_additive]\ninstance forget\u2082_Mon_preserves_limits : preserves_limits (forget\u2082 Group Mon.{u}) :=\nGroup.forget\u2082_Mon_preserves_limits_of_size.{u u}\n\n/-- The forgetful functor from groups to types preserves all limits.\n\nThis means the underlying type of a limit can be computed as a limit in the category of types. -/\n@[to_additive \"The forgetful functor from additive groups to types preserves all limits.\n\nThis means the underlying type of a limit can be computed as a limit in the category of types.\"]\ninstance forget_preserves_limits_of_size :\n  preserves_limits_of_size.{v v} (forget Group.{max v u}) :=\n{ preserves_limits_of_shape := \u03bb J \ud835\udca5, by exactI\n  { preserves_limit := \u03bb F, limits.comp_preserves_limit (forget\u2082 Group Mon) (forget Mon) } }\n\n@[to_additive]\ninstance forget_preserves_limits : preserves_limits (forget Group.{u}) :=\nGroup.forget_preserves_limits_of_size.{u u}\n\nend Group\n\nnamespace CommGroup\n\n@[to_additive]\ninstance comm_group_obj (F : J \u2964 CommGroup.{max v u}) (j) :\n  comm_group ((F \u22d9 forget CommGroup).obj j) :=\nby { change comm_group (F.obj j), apply_instance }\n\n@[to_additive]\ninstance limit_comm_group (F : J \u2964 CommGroup.{max v u}) :\n  comm_group (types.limit_cone (F \u22d9 forget CommGroup.{max v u})).X :=\n@subgroup.to_comm_group (\u03a0 j, F.obj j) _\n  (Group.sections_subgroup (F \u22d9 forget\u2082 CommGroup Group.{max v u}))\n\n/--\nWe show that the forgetful functor `CommGroup \u2964 Group` creates limits.\n\nAll we need to do is notice that the limit point has a `comm_group` instance available,\nand then reuse the existing limit.\n-/\n@[to_additive]\ninstance (F : J \u2964 CommGroup.{max v u}) : creates_limit F (forget\u2082 CommGroup Group.{max v u}) :=\ncreates_limit_of_reflects_iso (\u03bb c' t,\n{ lifted_cone :=\n  { X := CommGroup.of (types.limit_cone (F \u22d9 forget CommGroup)).X,\n    \u03c0 :=\n    { app := Mon.limit_\u03c0_monoid_hom\n        (F \u22d9 forget\u2082 CommGroup Group.{max v u} \u22d9 forget\u2082 Group Mon.{max v u}),\n      naturality' := (Mon.has_limits.limit_cone _).\u03c0.naturality, } },\n  valid_lift := by apply is_limit.unique_up_to_iso (Group.limit_cone_is_limit _) t,\n  makes_limit := is_limit.of_faithful (forget\u2082 _ Group.{max v u} \u22d9 forget\u2082 _ Mon.{max v u})\n    (by apply Mon.has_limits.limit_cone_is_limit _) (\u03bb s, _) (\u03bb s, rfl) })\n\n/--\nA choice of limit cone for a functor into `CommGroup`.\n(Generally, you'll just want to use `limit F`.)\n-/\n@[to_additive \"A choice of limit cone for a functor into `CommGroup`.\n(Generally, you'll just want to use `limit F`.)\"]\ndef limit_cone (F : J \u2964 CommGroup.{max v u}) : cone F :=\nlift_limit (limit.is_limit (F \u22d9 (forget\u2082 CommGroup Group.{max v u})))\n\n/--\nThe chosen cone is a limit cone.\n(Generally, you'll just want to use `limit.cone F`.)\n-/\n@[to_additive \"The chosen cone is a limit cone.\n(Generally, you'll just wantto use `limit.cone F`.)\"]\ndef limit_cone_is_limit (F : J \u2964 CommGroup.{max v u}) : is_limit (limit_cone F) :=\nlifted_limit_is_limit _\n\n/-- The category of commutative groups has all limits. -/\n@[to_additive \"The category of additive commutative groups has all limits.\"]\ninstance has_limits_of_size : has_limits_of_size.{v v} CommGroup.{max v u} :=\n{ has_limits_of_shape := \u03bb J \ud835\udca5, by exactI\n  { has_limit := \u03bb F, has_limit_of_created F (forget\u2082 CommGroup Group.{max v u}) } }\n\n@[to_additive]\ninstance has_limits : has_limits CommGroup.{u} := CommGroup.has_limits_of_size.{u u}\n\n/--\nThe forgetful functor from commutative groups to groups preserves all limits.\n(That is, the underlying group could have been computed instead as limits in the category\nof groups.)\n-/\n@[to_additive AddCommGroup.forget\u2082_AddGroup_preserves_limits\n\"The forgetful functor from additive commutative groups to groups preserves all limits.\n(That is, the underlying group could have been computed instead as limits in the category\nof additive groups.)\"]\ninstance forget\u2082_Group_preserves_limits_of_size :\n  preserves_limits_of_size.{v v} (forget\u2082 CommGroup Group.{max v u}) :=\n{ preserves_limits_of_shape := \u03bb J \ud835\udca5,\n  { preserves_limit := \u03bb F, by apply_instance } }\n\n@[to_additive]\ninstance forget\u2082_Group_preserves_limits : preserves_limits (forget\u2082 CommGroup Group.{u}) :=\nCommGroup.forget\u2082_Group_preserves_limits_of_size.{u u}\n\n/--\nAn auxiliary declaration to speed up typechecking.\n-/\n@[to_additive AddCommGroup.forget\u2082_AddCommMon_preserves_limits_aux\n  \"An auxiliary declaration to speed up typechecking.\"]\ndef forget\u2082_CommMon_preserves_limits_aux (F : J \u2964 CommGroup.{max v u}) :\n  is_limit ((forget\u2082 CommGroup CommMon).map_cone (limit_cone F)) :=\nCommMon.limit_cone_is_limit (F \u22d9 forget\u2082 CommGroup CommMon)\n\n/--\nThe forgetful functor from commutative groups to commutative monoids preserves all limits.\n(That is, the underlying commutative monoids could have been computed instead as limits\nin the category of commutative monoids.)\n-/\n@[to_additive AddCommGroup.forget\u2082_AddCommMon_preserves_limits\n\"The forgetful functor from additive commutative groups to additive commutative monoids preserves\nall limits. (That is, the underlying additive commutative monoids could have been computed instead\nas limits in the category of additive commutative monoids.)\"]\ninstance forget\u2082_CommMon_preserves_limits_of_size :\n  preserves_limits_of_size.{v v} (forget\u2082 CommGroup CommMon.{max v u}) :=\n{ preserves_limits_of_shape := \u03bb J \ud835\udca5, by exactI\n  { preserves_limit := \u03bb F, preserves_limit_of_preserves_limit_cone\n    (limit_cone_is_limit F) (forget\u2082_CommMon_preserves_limits_aux F) } }\n\n/--\nThe forgetful functor from commutative groups to types preserves all limits. (That is, the\nunderlying types could have been computed instead as limits in the category of types.)\n-/\n@[to_additive AddCommGroup.forget_preserves_limits\n\"The forgetful functor from additive commutative groups to types preserves all limits. (That is,\nthe underlying types could have been computed instead as limits in the category of types.)\"]\ninstance forget_preserves_limits_of_size :\n  preserves_limits_of_size.{v v} (forget CommGroup.{max v u}) :=\n{ preserves_limits_of_shape := \u03bb J \ud835\udca5, by exactI\n  { preserves_limit := \u03bb F, limits.comp_preserves_limit (forget\u2082 CommGroup Group) (forget Group) } }\n\n-- Verify we can form limits indexed over smaller categories.\nexample (f : \u2115 \u2192 AddCommGroup) : has_product f := by apply_instance\n\nend CommGroup\n\nnamespace AddCommGroup\n\n/--\nThe categorical kernel of a morphism in `AddCommGroup`\nagrees with the usual group-theoretical kernel.\n-/\ndef kernel_iso_ker {G H : AddCommGroup.{u}} (f : G \u27f6 H) :\n  kernel f \u2245 AddCommGroup.of f.ker :=\n{ hom :=\n  { to_fun := \u03bb g, \u27e8kernel.\u03b9 f g,\n    begin\n      -- TODO where is this `has_coe_t_aux.coe` coming from? can we prevent it appearing?\n      change (kernel.\u03b9 f) g \u2208 f.ker,\n      simp [add_monoid_hom.mem_ker],\n    end\u27e9,\n    map_zero' := by { ext, simp, },\n    map_add' := \u03bb g g', by { ext, simp, }, },\n  inv := kernel.lift f (add_subgroup.subtype f.ker) (by tidy),\n  hom_inv_id' := by { apply equalizer.hom_ext _, ext, simp, },\n  inv_hom_id' :=\n  begin\n    apply AddCommGroup.ext,\n    simp only [add_monoid_hom.coe_mk, coe_id, coe_comp],\n    rintro \u27e8x, mem\u27e9,\n    simp,\n  end, }.\n\n@[simp]\nlemma kernel_iso_ker_hom_comp_subtype {G H : AddCommGroup} (f : G \u27f6 H) :\n  (kernel_iso_ker f).hom \u226b add_subgroup.subtype f.ker = kernel.\u03b9 f :=\nby ext; refl\n\n@[simp]\nlemma kernel_iso_ker_inv_comp_\u03b9 {G H : AddCommGroup} (f : G \u27f6 H) :\n  (kernel_iso_ker f).inv \u226b kernel.\u03b9 f = add_subgroup.subtype f.ker :=\nbegin\n  ext,\n  simp [kernel_iso_ker],\nend\n\n/--\nThe categorical kernel inclusion for `f : G \u27f6 H`, as an object over `G`,\nagrees with the `subtype` map.\n-/\n@[simps]\ndef kernel_iso_ker_over {G H : AddCommGroup.{u}} (f : G \u27f6 H) :\n  over.mk (kernel.\u03b9 f) \u2245 @over.mk _ _ G (AddCommGroup.of f.ker) (add_subgroup.subtype f.ker) :=\nover.iso_mk (kernel_iso_ker f) (by simp)\n\nend AddCommGroup\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/category/Group/limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7068993293750901}}
{"text": "\n--Proof: a -> a\n\n\ntheorem Ex001_1(a : Prop) : a -> a := \nassume H1 : a,\nshow a ,from H1\n \n\n--using tactics\ntheorem Ex001_2(a : Prop) : a -> a := \nbegin\n  intro H,\n  exact H \nend\n\n\n", "meta": {"author": "SvenWille", "repo": "LeanLogicExercises", "sha": "2dbc920feadd63bbc50f87e69646c0081db26eba", "save_path": "github-repos/lean/SvenWille-LeanLogicExercises", "path": "github-repos/lean/SvenWille-LeanLogicExercises/LeanLogicExercises-2dbc920feadd63bbc50f87e69646c0081db26eba/src/propLogic/Ex001.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7068993211553999}}
{"text": "import .util\n\nuniverse u\nvariable {R : Type u}\n\nclass st_order R extends has_lt R := -- strict total order\n    (lt_irrefl : forall a : R, not (a < a))\n    (lt_trans  : forall {a b c : R}, a < b -> b < c -> a < c)\n    (ne_lt     : forall {a b : R}, a != b -> a < b \\/ b < a)\n    -- Bell 1.2, but we use it as an axiom for better structure\n    (lt_far    : forall {a b : R}, a < b -> forall c : R, a < c \\/ c < b)\nattribute [trans] st_order.lt_trans -- allow use of transitivity in calc proofs\n\n-- ordered field\nclass st_ordered_field R extends field R, st_order R :=\n    (lt_zero_one        : (0: R) < 1)\n    (lt_add_left        : forall {a b : R}, a < b -> forall c : R, c + a < c + b)\n    (lt_mul_pos_left    : forall {a b c : R}, 0 < c -> a < b -> c * a < c * b)\n\n-- lemmas & theorems regarding ordering\nnamespace st_order\n    variable [st_order R]\n    variables {a b c : R}\n\n    -- intervals\n    definition lt_interval [has_lt R] (a: R) (b: R) : set R := fun r: R, a < r /\\ r < b\n    definition le_interval [has_le R] (a: R) (b: R) : set R := fun r: R, a <= r /\\ r <= b\n    notation `[` a `...` b `]` := lt_interval a b\n    notation `[[` a `...` b `]]` := le_interval a b\n\n    -- non-strict total order\n    instance has_le : has_le R := {\n        le := fun x, fun y, not (y < x)\n    }\n    attribute [reducible] has_le.le\n\n    lemma lt_ne : a < b -> a != b :=\n        assume a_lt_b,\n        assume bad_a_eq_b: a = b,\n        st_order.lt_irrefl a (calc\n            a   < b : a_lt_b\n            ... = a : by rw bad_a_eq_b\n        )\n\n    lemma le_refl : a <= a := lt_irrefl a\n\n    @[trans]\n    lemma le_trans : a <= b -> b <= c -> a <= c :=\n        assume a_le_b b_le_c,\n        assume bad_c_lt_a,\n        have bad_or: c < b \\/ b < a, from (st_order.lt_far bad_c_lt_a b),\n        or.elim bad_or b_le_c a_le_b\n\n    @[trans]\n    lemma le_lt_trans : a <= b -> b < c -> a < c :=\n        assume le,\n        assume lt,\n        have a != c, from\n            assume bad,\n            have b < a, by {rw bad, assumption},\n            le this,\n        have a < c \\/ c < a, from ne_lt this,\n        have right_bad : not (c < a), from\n            assume bad,\n            have b < a, from lt_trans lt bad,\n            le this,\n        or.resolve_right this right_bad\nend st_order\n\nnamespace st_ordered_field\n    variable [st_ordered_field R]\n    variables {a b c : R}\n\n    lemma zero_one_far : 0 < a \\/ a < 1 := st_order.lt_far (lt_zero_one R) a\n\n    lemma lt_neg_flip : a < b -> -b < -a :=\n        assume lt: a < b,\n        calc\n            -b  = -b + (-a + a) : by simp\n            ... = (-b + -a) + a : by rw add_assoc\n            ... < (-b + -a) + b : lt_add_left lt _\n            ... = -a            : by simp\n\n    lemma one_div_pos_of_pos : 0 < c -> 0 < 1 / c :=\n        assume c_pos,\n        have c_ne_zero : c != 0, from ne.symm (st_order.lt_ne c_pos),\n        have 1 / c != 0, from one_div_ne_zero c_ne_zero,\n        have disj: 1 / c < 0 \\/ 0 < 1 / c, from st_order.ne_lt this,\n        have left: 1 / c < 0 -> 0 < 1 / c, from\n            assume one_div_c_neg,\n            have (1: R) < 1, from (calc\n                1   = c * (1 / c) : by rw mul_div_cancel' _ c_ne_zero\n                ... < c * 0       : lt_mul_pos_left c_pos one_div_c_neg\n                ... = 0           : mul_zero _\n                ... < (1: R)      : (lt_zero_one R)\n            ),\n            absurd this (st_order.lt_irrefl 1),\n        or.elim disj left (fun x, x)\n\n    lemma le_add_left : a <= b -> c + a <= c + b :=\n        assume a_le_b,\n        assume almost_bad,\n        have bad: b < a, from calc\n            b   = -c + (c + b) : by simp\n            ... < -c + (c + a) : lt_add_left almost_bad (-c)\n            ... = a            : by simp,\n        a_le_b bad\n\n    lemma le_zero_one : (0: R) <= 1 :=\n        assume bad : (1: R) < 0,\n        st_order.lt_irrefl 0 (calc\n            0   < 1 : lt_zero_one R\n            ... < 0 : bad\n        )\n\n    lemma le_mul_pos_left : a <= b -> 0 <= c -> c * a <= c * b :=\n        assume a_le_b,\n        assume zero_le_c,\n        assume bc_lt_ac,\n\n        have c_ne_zero: c != 0, from\n            assume bad: c = 0,\n            have c * b = c * a, by simp [bad, mul_zero],\n            absurd this (st_order.lt_ne bc_lt_ac),\n        have c < 0 \\/ 0 < c, from st_order.ne_lt c_ne_zero,\n\n        have right : not (0 < c), from\n            assume c_pos,\n            have b < a, from (calc\n                b   = (1 / c) * c * b   : by rw [one_div_mul_cancel c_ne_zero, one_mul]\n                ... = (1 / c) * (c * b) : by simp [mul_assoc]\n                ... < (1 / c) * (c * a) : lt_mul_pos_left (one_div_pos_of_pos c_pos) bc_lt_ac\n                ... = (1 / c) * c * a   : by simp [mul_assoc]\n                ... = a                 : by rw [one_div_mul_cancel c_ne_zero, one_mul]\n            ),\n            a_le_b this,\n        or.elim this zero_le_c right\n\n    lemma le_neg_flip : a <= b -> -b <= -a :=\n        assume a_le_b,\n        assume neg_a_lt_neg_b,\n        have b < a, from (calc\n            b   = -(-b) : by rw neg_neg\n            ... < -(-a) : lt_neg_flip neg_a_lt_neg_b\n            ... = a     : by rw neg_neg\n        ),\n        absurd this a_le_b\nend st_ordered_field\n", "meta": {"author": "metalogical", "repo": "sia-lean", "sha": "f8e354dd2ff6c09c4e001c1f80f6112c62da8592", "save_path": "github-repos/lean/metalogical-sia-lean", "path": "github-repos/lean/metalogical-sia-lean/sia-lean-f8e354dd2ff6c09c4e001c1f80f6112c62da8592/src/ordered_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7068993190295759}}
{"text": "import Std\nopen Std\nopen Lean\n\ninductive BoolExpr where\n  | var (name : String)\n  | val (b : Bool)\n  | or  (p q : BoolExpr)\n  | not (p : BoolExpr)\n  deriving Repr, BEq, DecidableEq\n\ndef BoolExpr.isValue : BoolExpr \u2192 Bool\n  | val _ => true\n  | _     => false\n\ninstance : Inhabited BoolExpr where\n  default := BoolExpr.val false\n\nnamespace BoolExpr\n\nderiving instance DecidableEq for BoolExpr\n\n#eval decide (BoolExpr.val true = BoolExpr.val false)\n\n#check (a b : BoolExpr) \u2192 Decidable (a = b)\n\nabbrev Context := AssocList String Bool\n\ndef denote (ctx : Context) : BoolExpr \u2192 Bool\n  | BoolExpr.or p q => denote ctx p || denote ctx q\n  | BoolExpr.not p  => !denote ctx p\n  | BoolExpr.val b => b\n  | BoolExpr.var x => if let some b := ctx.find? x then b else false\n\ndef simplify : BoolExpr \u2192 BoolExpr\n  | or p q => mkOr (simplify p) (simplify q)\n  | not p  => mkNot (simplify p)\n  | e      => e\nwhere\n  mkOr : BoolExpr \u2192 BoolExpr \u2192 BoolExpr\n    | p, val true   => val true\n    | p, val false  => p\n    | val true, p   => val true\n    | val false, p  => p\n    | p, q          => or p q\n\n  mkNot : BoolExpr \u2192 BoolExpr\n    | val b => val (!b)\n    | p     => not p\n\n@[simp] theorem denote_not_Eq (ctx : Context) (p : BoolExpr) : denote ctx (not p) = !denote ctx p := rfl\n@[simp] theorem denote_or_Eq (ctx : Context) (p q : BoolExpr) : denote ctx (or p q) = (denote ctx p || denote ctx q) := rfl\n@[simp] theorem denote_val_Eq (ctx : Context) (b : Bool) : denote ctx (val b) = b := rfl\n\n@[simp] theorem denote_mkNot_Eq (ctx : Context) (p : BoolExpr) : denote ctx (simplify.mkNot p) = denote ctx (not p) := by\n  cases p <;> rfl\n@[simp] theorem mkOr_p_true (p : BoolExpr) : simplify.mkOr p (val true) = val true := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n@[simp] theorem mkOr_p_false (p : BoolExpr) : simplify.mkOr p (val false) = p := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n@[simp] theorem mkOr_true_p (p : BoolExpr) : simplify.mkOr (val true) p = val true := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n@[simp] theorem mkOr_false_p (p : BoolExpr) : simplify.mkOr (val false) p = p := by\n  cases p with\n  | val x => cases x <;> rfl\n  | _     => rfl\n\n@[simp] theorem denote_mkOr (ctx : Context) (p q : BoolExpr) : denote ctx (simplify.mkOr p q) = denote ctx (or p q) := by\n  cases p with\n  | val x => cases q with\n    | val y => cases x <;> cases y <;> simp\n    | _     => cases x <;> simp\n  | _ => cases q with\n    | val y => cases y <;> simp\n    | _     => rfl\n\n@[simp] theorem simplify_not (p : BoolExpr) : simplify (not p) = simplify.mkNot (simplify p) := rfl\n@[simp] theorem simplify_or (p q : BoolExpr) : simplify (or p q) = simplify.mkOr (simplify p) (simplify q) := rfl\n\ndef denote_simplify_eq (ctx : Context) (b : BoolExpr) : denote ctx (simplify b) = denote ctx b :=\n  by induction b with\n  | or p q ih\u2081 ih\u2082 => simp [ih\u2081, ih\u2082]\n  | not p ih       => simp [ih]\n  | _              => rfl\n\nsyntax \"`[BExpr|\" term \"]\" : term\n\nmacro_rules\n | `(`[BExpr| true])     => `(val true)\n | `(`[BExpr| false])    => `(val false)\n | `(`[BExpr| $x:ident]) => `(var $(quote x.getId.toString))\n | `(`[BExpr| $p \u2228 $q])  => `(or `[BExpr| $p] `[BExpr| $q])\n | `(`[BExpr| \u00ac $p])     => `(not `[BExpr| $p])\n\n#check `[BExpr| \u00ac p \u2228 q]\n\nsyntax entry := ident \" \u21a6 \" term:max\nsyntax entry,* \"\u22a2\" term : term\n\nmacro_rules\n  | `( $[$xs:ident \u21a6 $vs:term],* \u22a2 $p:term ) =>\n    let xs := xs.map fun x => quote x.getId.toString\n    `(denote (List.toAssocList [$[( $xs , $vs )],*]) `[BExpr| $p])\n\n#check b \u21a6 true \u22a2 b \u2228 b\n#eval  a \u21a6 false, b \u21a6 false \u22a2 b \u2228 a\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/doc/BoolExpr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587159, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7068634031440956}}
{"text": "import tactic --hide\n\nuniverse u --hide\n\n-- Level name : intro\n\n/-\n\n## The `intro` tactic.\n\nIf your goal is \n\n```\n\u22a2 P \u2192 Q\n```\n\nmeaning we need to prove the `P` implies `Q` then the tactic <mark style =\"background-color : #ebdef0 \">`intro hp,`</mark> \nwill take `P` as true with proof `hp` and add `hp : P` to the assumptions. In addition, \nit turn your goal into `\u22a2 Q`. \n\nIn other words the state of the lemma becomes:  \n\n```\nhp : P\n\u22a2 Q\n```\n\nLets look at an example that needs the `intro` tactic: \n\n\n-/ \n\n\n/-Hint : Hint\nStart with `intro p`.\n-/\n\n/-Hint : Tip\n `intros` can be used to introduce\nmore than one assumption at once. Don't forget\nto name your hypotheses, e.g. `intros hp hq` if your goal is `P \u2192 Q \u2192 R`.\n-/\n\n/- Lemma : no-side-bar\nIf $P$ is a logical statement then $P\\implies P$.\n-/\nlemma implies_self (P : Prop) : P \u2192 P :=\nbegin\n  intro p,\n  exact p,\n\n\nend\n\n/- Tactic : intro\n\n## The `intro` tactic.\n\nIf your goal is to prove the implication\n\n```\n\u22a2 P \u2192 Q\n```\n\nthen the tactic\n\n`intro hP,`\n\nwill add `hp : P` as an assumption (i.e. `hp` is the proof of `P`) and turn your goal into `\u22a2 Q`. \nIn other words we get: \n\n```\nhP : P\n\u22a2 Q\n```\n\nTip : `intros` can be used to introduce\nmore than one assumption at once. Don't forget\nto name your hypotheses, e.g. `intros hP hQ` if your goal is `P \u2192 Q \u2192 R`.\n\n-/", "meta": {"author": "CBirkbeck", "repo": "logic_projic", "sha": "0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2", "save_path": "github-repos/lean/CBirkbeck-logic_projic", "path": "github-repos/lean/CBirkbeck-logic_projic/logic_projic-0b029af0fbfc0ac6eafae47401d5bbf8e641d7d2/src/logic_1/logic_pt1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587159, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7068634014337328}}
{"text": "-- 10.lean\n\ndef prefix_sum : \u2115 \u2192 list \u2115 \u2192 list \u2115\n| sum []             := [sum]\n| sum (head :: tail) := sum :: (prefix_sum (sum + head) tail)\n\ndef plus_list : list \u2115 \u2192 list \u2115 \u2192 list \u2115\n| [] _ := []\n| _ [] := []\n| (h1 :: t1) (h2 :: t2) := (h1 + h2) :: (plus_list t1 t2)\n\nlemma plus_list_nil_l : \u2200l, plus_list [] l = [] :=\nbegin\n    intro l,\n    cases l;\n    simp [plus_list]\nend\n\nlemma plus_list_nil_r : \u2200l, plus_list l [] = [] :=\nbegin\n    intro l,\n    cases l;\n    simp [plus_list]\nend\n\nlemma plus_list_prefix_sum_comm : \u2200l1 l2: list \u2115, \u2200n m: \u2115, \n    prefix_sum (n + m) (plus_list l1 l2) \n    = plus_list (prefix_sum n l1) (prefix_sum m l2) :=\nbegin\n    intro l1,\n    induction l1,\n        intro l2,\n        induction l2,\n            intros n m,\n            simp [plus_list, prefix_sum, plus_list_nil_l, plus_list_nil_r],\n        intros n m,\n        simp [plus_list, prefix_sum, plus_list_nil_l, plus_list_nil_r],\n    intro l2,\n    induction l2,\n        intros n m,\n        simp [plus_list, prefix_sum, plus_list_nil_l, plus_list_nil_r],\n    intros n m,\n    simp [plus_list, prefix_sum, plus_list_nil_l, plus_list_nil_r],\n    have h : (l1_hd + (l2_hd + (n + m))) = (n + l1_hd) + (m + l2_hd) := by simp,\n    rw h,\n    simp [prefix_sum] at l2_ih,\n    have l3 : prefix_sum ((l1_hd + n) + (l2_hd + m)) (plus_list l1_tl l2_tl)\n        = plus_list (prefix_sum (l1_hd + n) l1_tl) (prefix_sum (l2_hd + m) l2_tl) := by\n            apply l1_ih,\n    have c1: n + l1_hd + (m + l2_hd) = l1_hd + n + (l2_hd + m) := by simp,\n    rw c1,\n    exact l3\nend\n\nexample : \u2200l1 l2: list \u2115, prefix_sum 0 (plus_list l1 l2) \n            = plus_list (prefix_sum 0 l1) (prefix_sum 0 l2) :=\nbegin\n    intros,\n    apply plus_list_prefix_sum_comm l1 l2 0 0\nend\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/zeptometer/topprover/10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7068633931463055}}
{"text": "variables p q r : Prop\n\nnamespace mth1001\n\nsection and_elimination\n\n/-\nIn the following examples, we have a single premise `h : p \u2227 q`.\nThis can be read as '`h` a proof (or the assumption) of `p \u2227 q`'.\nFrom this premise, we deduce `p`.\n\nNote: `\u2227` can be entered by typing `\\and`\n-/\n\n/-\nThe first example presents a 'term-style' proof, as opposed to the 'tactic-style' proofs in\nthe previous section. In standard maths, this says:\n\n  Given `h : p \u2227 q`, `p` follows by left and elimination on `h`.\n\nWe can even omit the label of the premise in standard maths and write:\n\n  Given `p \u2227 q`, `p` follows by left and elimination.\n\n-/\nexample (h : p \u2227 q) : p :=\nh.left\n\n-- The second term-style proof is similar, but with `1` in place of `left`.\nexample (h : p \u2227 q) : p :=\nh.1\n\n-- Exercise 007:\n-- Replace the `sorry` below with a proof and write out the example in standard maths.\nexample (h : p \u2227 r) : p :=\nsorry \n-- Exercise 008:\n-- Guess what to write instead of `h.left` in the next example!\nexample (h : p \u2227 q) : q :=\nsorry \n\n-- Exercise 009:\nexample (k : p \u2227 q) : p :=\nsorry \n\n-- Exercise 010:\n-- Replace each occurrence of `sorry` below with appropriate text to\n-- give a proof of `r` from the premise `k : q \u2227 r`.\nexample (k : q \u2227 r) :sorry :=\nsorry \n\n/-\nLean's 'tactic mode' admits a more relaxed proof-writing style. We'll later see that it gives\naccess to Lean's powerful proof automation features.\n\nAs an exercise, list the tactics you've seen so far.\n-/\n\n/-\nThe `exact` tactic is used to close the goal using one of the premises or statements Lean already\nknows.\n-/\n\n/-\nIn stanard maths, the following states:\n\n  Given `h\u2081 : 3 + 3 = 7` and `h\u2082 : 1 + 1 = 2`, `3 + 3 = 7` follows, by `h\u2081`.\n\nor\n\n  Given `3 + 3 = 7` and `1 + 1 = 2`, `3 + 3 = 7` follows, by the premise `3 + 3 = 7`.\n\nIn Lean, we close the goal using `exact h\u2081`.\n-/\nexample (h\u2081 : 3 + 3 = 7) (h\u2082 : 1 + 1 = 2) : 3 + 3 = 7 :=\nby exact h\u2081\n\n/-\nIn the example above, we had two premises. The set of premises and other statements proved during\nthe course of a proof is called the _context_. Usually, as we work our way through a proof, we\nadd intermediate statements to the context as we prove them.\n-/\n\n-- Exercise 011:\n-- Complete the Lean proof and translate into standard maths.\nexample (h\u2081 : 4 \u2264 0) (h\u2082 : 7 = 3 + 4) (h\u2083 : 10 \u2260 6) : 7 = 3 + 4 :=\nsorry \n\n/-\nAs used below, the `cases` tactic decomposese `h` into its consituents, introducing new assertions\n`hp : p` and `hq : q` into the context.\n\nThis is our first multi-line tactic proof. Such proofs are enclosed between `begin` and `end`,\nrather than following the word `by`.\n-/\nexample (h : p \u2227 q) : p :=\nbegin\n  cases h with hp hq,\n  exact hp,\nend\n/-\nIn standard maths, the above translates to:\n\n  Given the premise `h : p \u2227 q`, `p` follows.\n  Proof: `h` decomposes into `hp : p` and `hq : q`.\n  `p` follows from `hp`.\n\nor, without labelling the premises and assertions:\n\n  Given the premise `p \u2227 q`, `p` follows.\n  Proof: the premise `p \u2227 q` decomposes into assertions `p` and `q`.\n  `p` follows from the assertion `p`.\n\n-/\n\n\n\n-- There is nothing special about the names `h`, `hp`, or `hq`.\nexample (bob : p \u2227 q) : p :=\nbegin\n  cases bob with jane jill,\n  exact jane,\nend \n\n-- As we've seen, we can use `sorry` as a placeholder that Lean expects us to\n-- replace later with a term or tactic.\n\nexample (h : p \u2227 q) : p :=\nbegin\n  cases h with hp hq,\n  sorry  \nend\n\nexample (h : p \u2227 q) : p :=\nbegin \n  cases h with hp hq,\n  exact sorry        \nend \n\n-- Replace the `sorry` with a valid term proof or tactic proof in the following examples.\n-- As usual, also translate into standard maths.\n\n-- Exercise 012:\nexample (h : (p \u2227 q) \u2227 r ) : q :=\nbegin\n  sorry  \nend\n\n-- Exercise 013:\n-- The next example requires a proof term. It's helpful to note that applications of `.left` or\n-- `.right` can be nested.\nexample (h : (p \u2227 q) \u2227 r ) : q :=\nsorry \n-- Exercise 014:\nexample (h : p \u2227 (q \u2227 r) ) : q :=\nbegin\n  sorry  \nend\n\n-- Exercise 015:\nexample (h : p \u2227 p) : p :=\nbegin\n  sorry  \nend\n\nend and_elimination\n\n/-\nSUMMARY:\n\n* And elimination (left and right).\n* Tactic blocks using `begin` and `end`.\n* The `exact` tactic.\n* The `cases` tactic.\n\n-/\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_01_and_elimination.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7068633829502255}}
{"text": "import ..lectures.love05_inductive_predicates_demo\nimport ..lectures.love13_rational_and_real_numbers_demo\n\n\n/-! # LoVe Exercise 13: Rational and Real Numbers -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Rationals\n1.1. Prove the following lemma.\nHint: The lemma `fraction.mk.inj_eq` might be useful. -/\n\n#check fraction.mk.inj_eq\n\nlemma fraction.ext (a b : fraction) (hnum : fraction.num a = fraction.num b)\n    (hdenom : fraction.denom a = fraction.denom b) :\n  a = b :=\nbegin\n  cases' a,\n  cases' b,\n  rw fraction.mk.inj_eq,\n  exact and.intro hnum hdenom\nend\n\n/-! 1.2. Extending the `fraction.has_mul` instance from the lecture, declare\n`fraction` as an instance of `semigroup`.\nHint: Use the lemma `fraction.ext` above, and possibly `fraction.mul_num`, and\n`fraction.mul_denom`. -/\n\n#check fraction.ext\n#check fraction.mul_num\n#check fraction.mul_denom\n\n@[instance] def fraction.semigroup : semigroup fraction :=\n{ mul_assoc :=\n    begin\n      intros,\n      apply fraction.ext,\n      repeat {\n        simp [fraction.mul_num, fraction.mul_denom],\n        cc }\n    end,\n  ..fraction.has_mul }\n\n/-! 1.3. Extending the `rat.has_mul` instance from the lecture, declare `rat` as\nan instance of `semigroup`. -/\n\n@[instance] def rat.semigroup : semigroup rat :=\n{ mul_assoc :=\n    begin\n      intros x y z,\n      apply quotient.induction_on x,\n      apply quotient.induction_on y,\n      apply quotient.induction_on z,\n      intros a b c,\n      apply quotient.sound,\n      rw mul_assoc\n    end,\n  ..rat.has_mul }\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/exercises/love13_rational_and_real_numbers_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7068633748610879}}
{"text": "/-\nCopyright (c) 2021 James Arthur, Benjamin Davidson, Andrew Souther. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: James Arthur, Benjamin Davidson, Andrew Souther\n-/\nimport measure_theory.interval_integral\nimport analysis.special_functions.sqrt\n\n/-!\n# Freek \u2116 9: The Area of a Circle\n\nIn this file we show that the area of a disc with nonnegative radius `r` is `\u03c0 * r^2`. The main\ntools our proof uses are `volume_region_between_eq_integral`, which allows us to represent the area\nof the disc as an integral, and `interval_integral.integral_eq_sub_of_has_deriv_at'_of_le`, the\nsecond fundamental theorem of calculus.\n\nWe begin by defining `disc` in `\u211d \u00d7 \u211d`, then show that `disc` can be represented as the\n`region_between` two functions.\n\nThough not necessary for the main proof, we nonetheless choose to include a proof of the\nmeasurability of the disc in order to convince the reader that the set whose volume we will be\ncalculating is indeed measurable and our result is therefore meaningful.\n\nIn the main proof, `area_disc`, we use `volume_region_between_eq_integral` followed by\n`interval_integral.integral_of_le` to reduce our goal to a single `interval_integral`:\n  `\u222b (x : \u211d) in -r..r, 2 * sqrt (r ^ 2 - x ^ 2) = \u03c0 * r ^ 2`.\nAfter disposing of the trivial case `r = 0`, we show that `\u03bb x, 2 * sqrt (r ^ 2 - x ^ 2)` is equal\nto the derivative of `\u03bb x, r ^ 2 * arcsin (x / r) + x * sqrt (r ^ 2 - x ^ 2)` everywhere on\n`Ioo (-r) r` and that those two functions are continuous, then apply the second fundamental theorem\nof calculus with those facts. Some simple algebra then completes the proof.\n\nNote that we choose to define `disc` as a set of points in `\u211d \u2a2f \u211d`. This is admittedly not ideal; it\nwould be more natural to define `disc` as a `metric.ball` in `euclidean_space \u211d (fin 2)` (as well as\nto provide a more general proof in higher dimensions). However, our proof indirectly relies on a\nnumber of theorems (particularly `measure_theory.measure.prod_apply`) which do not yet exist for\nEuclidean space, thus forcing us to use this less-preferable definition. As `measure_theory.pi`\ncontinues to develop, it should eventually become possible to redefine `disc` and extend our proof\nto the n-ball.\n-/\n\nopen set real measure_theory interval_integral\nopen_locale real nnreal\n\n/-- A disc of radius `r` is defined as the collection of points `(p.1, p.2)` in `\u211d \u00d7 \u211d` such that\n  `p.1 ^ 2 + p.2 ^ 2 < r ^ 2`.\n  Note that this definition is not equivalent to `metric.ball (0 : \u211d \u00d7 \u211d) r`. This was done\n  intentionally because `dist` in `\u211d \u00d7 \u211d` is defined as the uniform norm, making the `metric.ball`\n  in `\u211d \u00d7 \u211d` a square, not a disc.\n  See the module docstring for an explanation of why we don't define the disc in Euclidean space. -/\ndef disc (r : \u211d) := {p : \u211d \u00d7 \u211d | p.1 ^ 2 + p.2 ^ 2 < r ^ 2}\n\nvariable (r : \u211d\u22650)\n\n/-- A disc of radius `r` can be represented as the region between the two curves\n  `\u03bb x, - sqrt (r ^ 2 - x ^ 2)` and `\u03bb x, sqrt (r ^ 2 - x ^ 2)`. -/\nlemma disc_eq_region_between :\n  disc r = region_between (\u03bb x, -sqrt (r^2 - x^2)) (\u03bb x, sqrt (r^2 - x^2)) (Ioc (-r) r) :=\nbegin\n  ext p,\n  simp only [disc, region_between, mem_set_of_eq, mem_Ioo, mem_Ioc, pi.neg_apply],\n  split;\n  intro h,\n  { cases abs_lt_of_sq_lt_sq' (lt_of_add_lt_of_nonneg_left h (sq_nonneg p.2)) r.2,\n    rw [add_comm, \u2190 lt_sub_iff_add_lt] at h,\n    exact \u27e8\u27e8left, right.le\u27e9, sq_lt.mp h\u27e9 },\n  { rw [add_comm, \u2190 lt_sub_iff_add_lt],\n    exact sq_lt.mpr h.2 },\nend\n\n/-- The disc is a `measurable_set`. -/\ntheorem measurable_set_disc : measurable_set (disc r) :=\nby apply measurable_set_lt; apply continuous.measurable; continuity\n\n/-- The area of a disc with radius `r` is `\u03c0 * r ^ 2`. -/\ntheorem area_disc : volume (disc r) = nnreal.pi * r ^ 2 :=\nbegin\n  let f := \u03bb x, sqrt (r ^ 2 - x ^ 2),\n  let F := \u03bb x, (r:\u211d) ^ 2 * arcsin (r\u207b\u00b9 * x) + x * sqrt (r ^ 2 - x ^ 2),\n  have hf : continuous f := by continuity,\n  suffices : \u222b x in -r..r, 2 * f x = nnreal.pi * r ^ 2,\n  { have h : integrable_on f (Ioc (-r) r) :=\n      (hf.integrable_on_compact compact_Icc).mono_set Ioc_subset_Icc_self,\n    calc  volume (disc r)\n        = volume (region_between (\u03bb x, -f x) f (Ioc (-r) r)) : by rw disc_eq_region_between\n    ... = ennreal.of_real (\u222b x in Ioc (-r:\u211d) r, (f - has_neg.neg \u2218 f) x) :\n          volume_region_between_eq_integral\n            h.neg h measurable_set_Ioc (\u03bb x hx, neg_le_self (sqrt_nonneg _))\n    ... = ennreal.of_real (\u222b x in (-r:\u211d)..r, 2 * f x) : by simp [two_mul, integral_of_le]\n    ... = nnreal.pi * r ^ 2 : by rw_mod_cast [this, \u2190 ennreal.coe_nnreal_eq], },\n  obtain \u27e8hle, (heq | hlt)\u27e9 := \u27e8nnreal.coe_nonneg r, hle.eq_or_lt\u27e9, { simp [\u2190 heq] },\n  have hderiv : \u2200 x \u2208 Ioo (-r:\u211d) r, has_deriv_at F (2 * f x) x,\n  { rintros x \u27e8hx1, hx2\u27e9,\n    convert ((has_deriv_at_const x ((r:\u211d)^2)).mul ((has_deriv_at_arcsin _ _).comp x\n      ((has_deriv_at_const x (r:\u211d)\u207b\u00b9).mul (has_deriv_at_id' x)))).add\n        ((has_deriv_at_id' x).mul (((has_deriv_at_id' x).pow.const_sub ((r:\u211d)^2)).sqrt _)),\n    { have h : sqrt (1 - x ^ 2 / r ^ 2) * r = sqrt (r ^ 2 - x ^ 2),\n      { rw [\u2190 sqrt_sq hle, \u2190 sqrt_mul, sub_mul, sqrt_sq hle, div_mul_eq_mul_div_comm,\n            div_self (pow_ne_zero 2 hlt.ne'), one_mul, mul_one],\n        simpa [sqrt_sq hle, div_le_one (pow_pos hlt 2)] using sq_le_sq' hx1.le hx2.le },\n      field_simp,\n      rw [h, mul_left_comm, \u2190 sq, neg_mul_eq_mul_neg, mul_div_mul_left (-x^2) _ two_ne_zero,\n          add_left_comm, div_add_div_same, tactic.ring.add_neg_eq_sub, div_sqrt, two_mul] },\n    { suffices : -(1:\u211d) < r\u207b\u00b9 * x, by exact this.ne',\n      calc -(1:\u211d) = r\u207b\u00b9 * -r : by simp [hlt.ne']\n              ... < r\u207b\u00b9 * x : by nlinarith [inv_pos.mpr hlt] },\n    { suffices : (r:\u211d)\u207b\u00b9 * x < 1, by exact this.ne,\n      calc (r:\u211d)\u207b\u00b9 * x < r\u207b\u00b9 * r : by nlinarith [inv_pos.mpr hlt]\n                   ... = 1 : inv_mul_cancel hlt.ne' },\n    { nlinarith } },\n  have hcont := (by continuity : continuous F).continuous_on,\n  have hcont' := (continuous_const.mul hf).continuous_on,\n  calc  \u222b x in -r..r, 2 * f x\n      = F r - F (-r) : integral_eq_sub_of_has_deriv_at'_of_le (neg_le_self r.2) hcont hderiv hcont'\n  ... = nnreal.pi * r ^ 2 : by norm_num [F, inv_mul_cancel hlt.ne', \u2190 mul_div_assoc, mul_comm \u03c0],\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/100-theorems-list/9_area_of_a_circle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.706835724476506}}
{"text": "/-\nCopyright (c) 2023 Peter Nelson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Peter Nelson\n-/\nimport data.finite.card\nimport algebra.big_operators.finprod\n\n/-!\n# Noncomputable Set Cardinality\n\nWe define the cardinality `set.ncard s` of a set `s` as a natural number. This function is\nnoncomputable (being defined in terms of `nat.card`) and takes the value `0` if `s` is infinite.\n\nThis can be seen as an API for `nat.card \u03b1` in the special case where `\u03b1` is a subtype arising from\na set. It is intended as an alternative to `finset.card` and `fintype.card`,  both of which contain\ndata in their definition that can cause awkwardness when using `set.to_finset`.  Using `set.ncard`\nallows cardinality computations to avoid `finset`/`fintype` completely, staying in `set` and letting\nfiniteness be handled explicitly, or (where a `finite \u03b1` instance is present and the sets are\nin `set \u03b1`) via `auto_param`s.\n\n## Main Definitions\n\n* `set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is finite.\n  If `s` is infinite, then `set.ncard s = 0`.\n* `to_finite_tac` is a tactic that tries to synthesize an `set.finite s` argument with\n  `set.to_finite`. This will work for `s : set \u03b1` where there is a `finite \u03b1` instance.\n\n## Implementation Notes\n\nThe lemmas in this file are very similar to those in `data.finset.card`, but with `set` operations\ninstead of `finset`; most of the proofs invoke their `finset` analogues. Nearly all the lemmas\nrequire finiteness of one or more of their arguments. We provide this assumption with an\n`auto_param` argument of the form `(hs : s.finite . to_finite_tac)`, where `to_finite_tac` will find\na `finite s` term in the cases where `s` is a set in a `finite` type.\n\nOften, where there are two set arguments `s` and `t`, the finiteness of one follows from the other\nin the context of the lemma, in which case we only include the ones that are needed, and derive the\nother inside the proof. A few of the lemmas, such as `ncard_union_le` do not require finiteness\narguments; they are are true by coincidence due to junk values.\n-/\n\nopen_locale classical\nopen_locale big_operators\n\nvariables {\u03b1 \u03b2 : Type*} {s t : set \u03b1} {a b x y : \u03b1} {f : \u03b1 \u2192 \u03b2}\n\nnamespace set\n\n\n/-- The cardinality of `s : set \u03b1` . Has the junk value `0` if `s` is infinite -/\nnoncomputable def ncard (s : set \u03b1) := nat.card s\n\n/-- A tactic that finds a `t.finite` term for a set `t` in a `finite` type. -/\nmeta def to_finite_tac : tactic unit := `[exact set.to_finite _]\n\nlemma ncard_def (s : set \u03b1) : s.ncard = nat.card s := rfl\n\nlemma ncard_eq_to_finset_card (s : set \u03b1) (hs : s.finite . to_finite_tac) :\n  s.ncard = hs.to_finset.card :=\nby rw [ncard_def, @nat.card_eq_fintype_card _ hs.fintype,\n  @finite.card_to_finset _ _ hs.fintype hs]\n\nlemma ncard_le_of_subset (hst : s \u2286 t) (ht : t.finite . to_finite_tac) :\n  s.ncard \u2264 t.ncard :=\n@finite.card_le_of_embedding _ _ (finite_coe_iff.mpr ht) (set.embedding_of_subset _ _ hst)\n\nlemma ncard_mono [finite \u03b1] :\n  @monotone (set \u03b1) _ _ _ ncard :=\n\u03bb _ _, ncard_le_of_subset\n\n@[simp] lemma ncard_eq_zero (hs : s.finite . to_finite_tac) :\n  s.ncard = 0 \u2194 s = \u2205 :=\nby simp [ncard_def, @finite.card_eq_zero_iff _ hs.to_subtype]\n\n@[simp] lemma ncard_coe_finset (s : finset \u03b1) :\n  (s : set \u03b1).ncard = s.card :=\nby rw [ncard_eq_to_finset_card, finset.finite_to_set_to_finset]\n\nlemma infinite.ncard (hs : s.infinite) :\n  s.ncard = 0 :=\n@nat.card_eq_zero_of_infinite _ hs.to_subtype\n\nlemma ncard_univ (\u03b1 : Type*):\n  (univ : set \u03b1).ncard = nat.card \u03b1 :=\nbegin\n  cases finite_or_infinite \u03b1 with h h,\n  { haveI := @fintype.of_finite \u03b1 h,\n    rw [ncard_eq_to_finset_card, finite.to_finset_univ, finset.card_univ,\n      nat.card_eq_fintype_card]},\n  rw [(@infinite_univ _ h).ncard, @nat.card_eq_zero_of_infinite _ h],\nend\n\n@[simp] lemma ncard_empty (\u03b1 : Type*) :\n  (\u2205 : set \u03b1).ncard = 0 :=\nby simp only [ncard_eq_zero]\n\nlemma ncard_pos (hs : s.finite . to_finite_tac) :\n  0 < s.ncard \u2194 s.nonempty :=\nby rw [pos_iff_ne_zero, ne.def, ncard_eq_zero hs, nonempty_iff_ne_empty]\n\nlemma ncard_ne_zero_of_mem (h : a \u2208 s) (hs : s.finite . to_finite_tac):\n  s.ncard \u2260 0 :=\n((ncard_pos hs).mpr \u27e8a,h\u27e9).ne.symm\n\nlemma finite_of_ncard_ne_zero (hs : s.ncard \u2260 0) :\n  s.finite :=\ns.finite_or_infinite.elim id (\u03bb h, (hs h.ncard).elim)\n\nlemma finite_of_ncard_pos (hs : 0 < s.ncard) :\n  s.finite :=\nfinite_of_ncard_ne_zero hs.ne.symm\n\nlemma nonempty_of_ncard_ne_zero (hs : s.ncard \u2260 0) :\n  s.nonempty :=\nby {rw nonempty_iff_ne_empty, rintro rfl, simpa using hs}\n\n@[simp] lemma ncard_singleton (a : \u03b1) :\n  ({a} : set \u03b1).ncard = 1 :=\nby simp [ncard_eq_to_finset_card]\n\nlemma ncard_singleton_inter : ({a} \u2229 s).ncard \u2264 1 :=\nbegin\n  rw [\u2190inter_self {a}, inter_assoc, ncard_eq_to_finset_card,\n    finite.to_finset_inter, finite.to_finset_singleton],\n  { apply finset.card_singleton_inter},\n  all_goals {apply to_finite},\nend\n\nsection insert_erase\n\n@[simp] lemma ncard_insert_of_not_mem (h : a \u2209 s) (hs : s.finite . to_finite_tac) :\n  (insert a s).ncard = s.ncard + 1 :=\nbegin\n  haveI := hs.fintype,\n  rw [ncard_eq_to_finset_card, ncard_eq_to_finset_card, finite.to_finset_insert,\n    finset.card_insert_of_not_mem],\n  rwa [finite.mem_to_finset],\nend\n\nlemma ncard_insert_of_mem (h : a \u2208 s) :\n  ncard (insert a s) = s.ncard :=\nby rw insert_eq_of_mem h\n\nlemma card_insert_le (a : \u03b1) (s : set \u03b1) : (insert a s).ncard \u2264 s.ncard + 1 :=\nbegin\n  obtain (hs | hs) := s.finite_or_infinite,\n  { exact (em (a \u2208 s)).elim (\u03bb h, (ncard_insert_of_mem h).trans_le (nat.le_succ _))\n      (\u03bb h, by rw ncard_insert_of_not_mem h hs)},\n  rw (hs.mono (subset_insert a s)).ncard,\n  exact nat.zero_le _,\nend\n\nlemma ncard_insert_eq_ite (hs : s.finite . to_finite_tac) :\n  ncard (insert a s) = if a \u2208 s then s.ncard else s.ncard + 1 :=\nbegin\n  by_cases h : a \u2208 s,\n  { rw [ncard_insert_of_mem h, if_pos h] },\n  { rw [ncard_insert_of_not_mem h hs, if_neg h] }\nend\n\n@[simp] lemma card_doubleton (h : a \u2260 b) : ({a, b} : set \u03b1).ncard = 2 :=\nby {rw [ncard_insert_of_not_mem, ncard_singleton], simpa}\n\n@[simp] lemma ncard_diff_singleton_add_one (h : a \u2208 s) (hs : s.finite . to_finite_tac) :\n  (s \\ {a}).ncard + 1 = s.ncard :=\nbegin\n  have h' : a \u2209 s \\ {a}, by {rw [mem_diff_singleton], tauto},\n  rw \u2190ncard_insert_of_not_mem h' (hs.diff {a}),\n  congr',\n  simpa,\nend\n\n@[simp] lemma ncard_diff_singleton_of_mem (h : a \u2208 s) (hs : s.finite . to_finite_tac) :\n  (s \\ {a}).ncard = s.ncard - 1 :=\neq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs)\n\nlemma ncard_diff_singleton_lt_of_mem (h : a \u2208 s) (hs : s.finite . to_finite_tac) :\n  (s \\ {a}).ncard < s.ncard :=\nby {rw [\u2190ncard_diff_singleton_add_one h hs], apply lt_add_one}\n\nlemma ncard_diff_singleton_le (s : set \u03b1) (a : \u03b1) :\n  (s \\ {a}).ncard \u2264 s.ncard :=\nbegin\n  obtain (hs | hs) := s.finite_or_infinite,\n  { apply ncard_le_of_subset (diff_subset _ _) hs},\n  convert zero_le _,\n  exact (hs.diff (by simp : set.finite {a})).ncard,\nend\n\nlemma pred_ncard_le_ncard_diff_singleton (s : set \u03b1) (a : \u03b1) :\n  s.ncard - 1 \u2264 (s \\ {a}).ncard :=\nbegin\n  cases s.finite_or_infinite with hs hs,\n  { by_cases h : a \u2208 s,\n    { rw ncard_diff_singleton_of_mem h hs, },\n    rw diff_singleton_eq_self h,\n    apply nat.pred_le},\n  convert nat.zero_le _,\n  rw hs.ncard,\nend\n\nlemma ncard_exchange (ha : a \u2209 s) (hb : b \u2208 s) :\n  (insert a (s \\ {b})).ncard = s.ncard :=\nbegin\n  cases s.finite_or_infinite with h h,\n  { haveI := h.to_subtype,\n    rw [ncard_insert_of_not_mem, ncard_diff_singleton_add_one hb],\n    simpa only [mem_diff, not_and] using ha},\n  rw [((h.diff (set.to_finite {b})).mono (subset_insert _ _)).ncard, h.ncard],\nend\n\nlemma ncard_exchange' (ha : a \u2209 s) (hb : b \u2208 s) :\n  ((insert a s) \\ {b}).ncard = s.ncard :=\nby rw [\u2190ncard_exchange ha hb, \u2190singleton_union, \u2190singleton_union, union_diff_distrib,\n    @diff_singleton_eq_self _ b {a} (\u03bb h, ha (by rwa \u2190 mem_singleton_iff.mp h) )]\n\nend insert_erase\n\nlemma ncard_image_le (hs : s.finite . to_finite_tac) :\n  (f '' s).ncard \u2264 s.ncard :=\nbegin\n  rw ncard_eq_to_finset_card s hs,\n  haveI := hs.fintype,\n  convert @finset.card_image_le _ _ s.to_finset f _,\n  rw [ncard_eq_to_finset_card, finite.to_finset_image _ hs],\n  { congr', rw [\u2190finset.coe_inj, finite.coe_to_finset, coe_to_finset]},\n  { apply_instance},\n  rw [\u2190finset.coe_inj, finite.coe_to_finset, coe_to_finset],\nend\n\nlemma ncard_image_of_inj_on (H : set.inj_on f s) :\n  (f '' s).ncard = s.ncard :=\nbegin\n  cases s.finite_or_infinite,\n  { haveI := @fintype.of_finite s h.to_subtype,\n    haveI := @fintype.of_finite _ (h.image f).to_subtype,\n    convert card_image_of_inj_on H; simp [ncard_def]},\n  rw [h.ncard, ((infinite_image_iff H).mpr h).ncard],\nend\n\nlemma inj_on_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.finite . to_finite_tac) :\n  set.inj_on f s :=\nbegin\n  haveI := hs.fintype,\n  haveI := ((to_finite s).image f).fintype,\n  simp_rw ncard_eq_to_finset_card at h,\n  rw \u2190 coe_to_finset s,\n  apply finset.inj_on_of_card_image_eq,\n  convert h,\n  ext,\n  simp,\nend\n\nlemma ncard_image_iff (hs : s.finite . to_finite_tac) :\n  (f '' s).ncard = s.ncard \u2194 set.inj_on f s :=\n\u27e8\u03bb h, inj_on_of_ncard_image_eq h hs, ncard_image_of_inj_on\u27e9\n\nlemma ncard_image_of_injective (s : set \u03b1) (H : f.injective) :\n  (f '' s).ncard = s.ncard :=\nncard_image_of_inj_on $ \u03bb x _ y _ h, H h\n\nlemma ncard_preimage_of_injective_subset_range {s : set \u03b2} (H : f.injective) \n(hs : s \u2286 set.range f) :\n  (f \u207b\u00b9' s).ncard = s.ncard :=\nby rw [\u2190ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]  \n\nlemma fiber_ncard_ne_zero_iff_mem_image {y : \u03b2} (hs : s.finite . to_finite_tac) :\n  {x \u2208 s | f x = y}.ncard \u2260 0 \u2194 y \u2208 f '' s :=\nbegin\n  refine \u27e8nonempty_of_ncard_ne_zero, _\u27e9,\n  rintros \u27e8z,hz,rfl\u27e9,\n  exact @ncard_ne_zero_of_mem _ {x \u2208 s | f x = f z} z (mem_sep hz rfl)\n    (hs.subset (sep_subset _ _)),\nend\n\n@[simp] lemma ncard_map (f : \u03b1 \u21aa \u03b2) :\n  (f '' s).ncard = s.ncard :=\nncard_image_of_injective _ f.injective\n\n@[simp] lemma ncard_subtype (P : \u03b1 \u2192 Prop) (s : set \u03b1) :\n  {x : subtype P | (x : \u03b1) \u2208 s}.ncard = (s \u2229 (set_of P)).ncard :=\nbegin\n  convert (ncard_image_of_injective _ (@subtype.coe_injective _ P)).symm,\n  ext, rw inter_comm, simp,\nend\n\nlemma ncard_inter_le_ncard_left (s t : set \u03b1) (hs : s.finite . to_finite_tac) :\n  (s \u2229 t).ncard \u2264 s.ncard :=\nncard_le_of_subset (inter_subset_left _ _) hs\n\nlemma ncard_inter_le_ncard_right (s t : set \u03b1) (ht : t.finite . to_finite_tac) :\n  (s \u2229 t).ncard \u2264 t.ncard :=\nncard_le_of_subset (inter_subset_right _ _) ht\n\nlemma eq_of_subset_of_ncard_le (h : s \u2286 t) (h' : t.ncard \u2264 s.ncard)\n(ht : t.finite . to_finite_tac) :\n  s = t :=\nbegin\n  haveI := ht.fintype,\n  haveI := (ht.subset h).fintype,\n  rw \u2190@to_finset_inj,\n  apply finset.eq_of_subset_of_card_le,\n  { simpa, },\n  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h)] at h',\n  convert h',\nend\n\nlemma subset_iff_eq_of_ncard_le (h : t.ncard \u2264 s.ncard) (ht : t.finite . to_finite_tac) :\n  s \u2286 t \u2194 s = t :=\n\u27e8\u03bb hst, eq_of_subset_of_ncard_le hst h ht, eq.subset'\u27e9\n\nlemma map_eq_of_subset {f : \u03b1 \u21aa \u03b1} (h : f '' s \u2286 s) (hs : s.finite . to_finite_tac) :\n  f '' s = s :=\neq_of_subset_of_ncard_le h (ncard_map _).ge hs\n\nlemma sep_of_ncard_eq {P : \u03b1 \u2192 Prop} (h : {x \u2208 s | P x}.ncard = s.ncard) (ha : a \u2208 s)\n(hs : s.finite . to_finite_tac) :\n  P a :=\nsep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha\n\nlemma ncard_lt_ncard (h : s \u2282 t) (ht : t.finite . to_finite_tac) :\n  s.ncard < t.ncard :=\nbegin\n  rw [ncard_eq_to_finset_card _ (ht.subset h.subset), ncard_eq_to_finset_card t ht],\n  refine finset.card_lt_card _,\n  rwa [finite.to_finset_ssubset_to_finset],\nend\n\nlemma ncard_strict_mono [finite \u03b1] :\n  @strict_mono (set \u03b1) _ _ _ ncard :=\n\u03bb _ _ h, ncard_lt_ncard h\n\nlemma ncard_eq_of_bijective {n : \u2115} (f : \u2200 i, i < n \u2192 \u03b1)\n  (hf : \u2200 a \u2208 s, \u2203 i, \u2203 h : i < n, f i h = a)\n  (hf' : \u2200 i (h : i < n), f i h \u2208 s)\n  (f_inj : \u2200 i j (hi : i < n) (hj : j < n), f i hi = f j hj \u2192 i = j)\n  (hs : s.finite . to_finite_tac) :\n  s.ncard = n :=\nbegin\n  rw ncard_eq_to_finset_card _ hs,\n  apply finset.card_eq_of_bijective,\n  all_goals {simpa},\nend\n\nlemma ncard_congr {t : set \u03b2} (f : \u03a0 a \u2208 s, \u03b2) (h\u2081 : \u2200 a ha, f a ha \u2208 t)\n(h\u2082 : \u2200 a b ha hb, f a ha = f b hb \u2192 a = b) (h\u2083 : \u2200 b \u2208 t, \u2203 a ha, f a ha = b)\n(hs : s.finite . to_finite_tac) :\n  s.ncard = t.ncard :=\nbegin\n  set f' : s \u2192 t := \u03bb x, \u27e8f x.1 x.2, h\u2081 _ _\u27e9 with hf',\n  have hbij : f'.bijective,\n  { split,\n    { rintros \u27e8x,hx\u27e9 \u27e8y,hy\u27e9 hxy,\n      simp only [hf', subtype.val_eq_coe, subtype.coe_mk, subtype.mk_eq_mk] at hxy \u22a2,\n      apply h\u2082 _ _ hx hy hxy},\n    rintro \u27e8y,hy\u27e9,\n    obtain \u27e8a, ha, rfl\u27e9 := h\u2083 y hy,\n    simp only [subtype.val_eq_coe, subtype.coe_mk, subtype.mk_eq_mk, set_coe.exists],\n    exact \u27e8_,ha,rfl\u27e9},\n  haveI := hs.to_subtype,\n  haveI := @fintype.of_finite _ (finite.of_bijective hbij),\n  haveI := fintype.of_finite s,\n  convert fintype.card_of_bijective hbij,\n  rw [ncard_def, nat.card_eq_fintype_card],\n  rw [ncard_def, nat.card_eq_fintype_card],\nend\n\nlemma ncard_le_ncard_of_inj_on {t : set \u03b2} (f : \u03b1 \u2192 \u03b2) (hf : \u2200 a \u2208 s, f a \u2208 t)\n(f_inj : inj_on f s) (ht : t.finite . to_finite_tac) :\n  s.ncard \u2264 t.ncard :=\nbegin\n  cases s.finite_or_infinite,\n  { haveI := h.to_subtype,\n    rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (to_finite s)],\n    exact finset.card_le_card_of_inj_on f (by simpa) (by simpa)},\n  convert nat.zero_le _,\n  rw h.ncard,\nend\n\nlemma exists_ne_map_eq_of_ncard_lt_of_maps_to {t : set \u03b2} (hc : t.ncard < s.ncard)\n{f : \u03b1 \u2192 \u03b2} (hf : \u2200 a \u2208 s, f a \u2208 t) (ht : t.finite . to_finite_tac) :\n  \u2203 (x \u2208 s) (y \u2208 s), x \u2260 y \u2227 f x = f y :=\nbegin\n  by_contra h',\n  simp only [ne.def, exists_prop, not_exists, not_and, not_imp_not] at h',\n  exact (ncard_le_ncard_of_inj_on f hf h' ht).not_lt hc,\nend\n\nlemma le_ncard_of_inj_on_range {n : \u2115} (f : \u2115 \u2192 \u03b1) (hf : \u2200 i < n, f i \u2208 s)\n  (f_inj : \u2200 (i < n) (j < n), f i = f j \u2192 i = j) (hs : s.finite . to_finite_tac):\n  n \u2264 s.ncard :=\nby {rw ncard_eq_to_finset_card _ hs, apply finset.le_card_of_inj_on_range; simpa}\n\nlemma surj_on_of_inj_on_of_ncard_le {t : set \u03b2} (f : \u03a0 a \u2208 s, \u03b2)\n(hf : \u2200 a ha, f a ha \u2208 t) (hinj : \u2200 a\u2081 a\u2082 ha\u2081 ha\u2082, f a\u2081 ha\u2081 = f a\u2082 ha\u2082 \u2192 a\u2081 = a\u2082)\n(hst : t.ncard \u2264 s.ncard) (ht : t.finite . to_finite_tac) :\n  \u2200 b \u2208 t, \u2203 a ha, b = f a ha :=\nbegin\n  intros b hb,\n  set f' : s \u2192 t := \u03bb x, \u27e8f x.1 x.2, hf _ _\u27e9 with hf',\n  have finj: f'.injective,\n  { rintros \u27e8x,hx\u27e9 \u27e8y,hy\u27e9 hxy,\n    simp only [hf', subtype.val_eq_coe, subtype.coe_mk, subtype.mk_eq_mk] at hxy \u22a2,\n    apply hinj _ _ hx hy hxy},\n  haveI := ht.fintype,\n  haveI := fintype.of_injective f' finj,\n  simp_rw [ncard_eq_to_finset_card] at hst,\n  set f'' : \u2200 a, a \u2208 s.to_finset \u2192 \u03b2 := \u03bb a h, f a (by simpa using h) with hf'',\n  convert @finset.surj_on_of_inj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)\n    (by convert hst) b (by simpa),\n  simp,\nend\n\nlemma inj_on_of_surj_on_of_ncard_le {t : set \u03b2} (f : \u03a0 a \u2208 s, \u03b2) (hf : \u2200 a ha, f a ha \u2208 t)\n(hsurj : \u2200 b \u2208 t, \u2203 a ha, b = f a ha) (hst : s.ncard \u2264 t.ncard) \u2983a\u2081 a\u2082\u2984 (ha\u2081 : a\u2081 \u2208 s)\n(ha\u2082 : a\u2082 \u2208 s) (ha\u2081a\u2082: f a\u2081 ha\u2081 = f a\u2082 ha\u2082) (hs : s.finite . to_finite_tac) :\n  a\u2081 = a\u2082 :=\nbegin\n   set f' : s \u2192 t := \u03bb x, \u27e8f x.1 x.2, hf _ _\u27e9 with hf',\n  have hsurj : f'.surjective,\n  { rintro \u27e8y,hy\u27e9,\n    obtain \u27e8a, ha, rfl\u27e9 := hsurj y hy,\n    simp only [subtype.val_eq_coe, subtype.coe_mk, subtype.mk_eq_mk, set_coe.exists],\n    exact \u27e8_,ha,rfl\u27e9},\n  haveI := hs.fintype,\n  haveI := fintype.of_surjective _ hsurj,\n  simp_rw [ncard_eq_to_finset_card] at hst,\n  set f'' : \u2200 a, a \u2208 s.to_finset \u2192 \u03b2 := \u03bb a h, f a (by simpa using h) with hf'',\n  exact @finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)\n    (by convert hst) a\u2081 a\u2082 (by simpa) (by simpa) (by simpa),\nend\n\nsection lattice\n\nlemma ncard_union_add_ncard_inter (s t : set \u03b1) (hs : s.finite . to_finite_tac)\n(ht : t.finite . to_finite_tac) :\n  (s \u222a t).ncard + (s \u2229 t).ncard = s.ncard + t.ncard :=\nbegin\n  have hu := hs.union ht,\n  have hi := (hs.subset (inter_subset_left s t)),\n  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ hu,\n    ncard_eq_to_finset_card _ hi, finite.to_finset_union, finite.to_finset_inter],\n  { exact finset.card_union_add_card_inter _ _},\nend\n\nlemma ncard_inter_add_ncard_union (s t : set \u03b1)\n(hs : s.finite . to_finite_tac) (ht : t.finite . to_finite_tac) :\n  (s \u2229 t).ncard + (s \u222a t).ncard = s.ncard + t.ncard :=\nby rw [add_comm, ncard_union_add_ncard_inter _ _ hs ht]\n\nlemma ncard_union_le (s t : set \u03b1) :\n  (s \u222a t).ncard \u2264 s.ncard + t.ncard :=\nbegin\n  cases (s \u222a t).finite_or_infinite,\n  { have hs := h.subset (subset_union_left s t),\n    have ht := h.subset (subset_union_right s t),\n    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ h,\n      finite.to_finset_union],\n    exact finset.card_union_le _ _},\n  convert nat.zero_le _,\n  rw h.ncard,\nend\n\n\n\nlemma ncard_union_eq (h : disjoint s t) (hs : s.finite . to_finite_tac)\n(ht : t.finite . to_finite_tac) :\n  (s \u222a t).ncard = s.ncard + t.ncard :=\nbegin\n  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht,\n    ncard_eq_to_finset_card _ (hs.union ht),finite.to_finset_union],\n  refine finset.card_union_eq _,\n  rwa [finite.disjoint_to_finset],\nend\n\nlemma ncard_diff_add_ncard_eq_ncard (h : s \u2286 t) (ht : t.finite . to_finite_tac) :\n  (t \\ s).ncard + s.ncard = t.ncard :=\nbegin\n  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h),\n      ncard_eq_to_finset_card _ (ht.diff s), finite.to_finset_diff],\n  refine finset.card_sdiff_add_card_eq_card _,\n  rwa finite.to_finset_subset_to_finset,\nend\n\nlemma ncard_diff (h : s \u2286 t) (ht : t.finite . to_finite_tac) :\n  (t \\ s).ncard = t.ncard - s.ncard :=\nby rw [\u2190ncard_diff_add_ncard_eq_ncard h ht, add_tsub_cancel_right]\n\nlemma ncard_le_ncard_diff_add_ncard (s t : set \u03b1) (ht : t.finite . to_finite_tac) :\n  s.ncard \u2264 (s \\ t).ncard + t.ncard :=\nbegin\n  cases s.finite_or_infinite,\n  { rw [\u2190diff_inter_self_eq_diff, \u2190ncard_diff_add_ncard_eq_ncard (inter_subset_right t s) h,\n      add_le_add_iff_left],\n    apply ncard_inter_le_ncard_left _ _ ht,},\n  convert nat.zero_le _,\n  rw h.ncard,\nend\n\nlemma le_ncard_diff (s t : set \u03b1) (hs : s.finite . to_finite_tac) :\n  t.ncard - s.ncard \u2264 (t \\ s).ncard :=\nbegin\n  refine tsub_le_iff_left.mpr _,\n  rw add_comm,\n  apply ncard_le_ncard_diff_add_ncard _ _ hs,\nend\n\nlemma ncard_diff_add_ncard (s t : set \u03b1) (hs : s.finite . to_finite_tac)\n(ht : t.finite . to_finite_tac):\n  (s \\ t).ncard + t.ncard = (s \u222a t).ncard :=\nby rw [\u2190union_diff_right,ncard_diff_add_ncard_eq_ncard (subset_union_right s t) (hs.union ht)]\n\nlemma diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.finite . to_finite_tac) :\n  (t \\ s).nonempty :=\nbegin\n  rw [set.nonempty_iff_ne_empty, ne.def, diff_eq_empty],\n  exact \u03bb h', h.not_le (ncard_le_of_subset h' hs),\nend\n\nlemma exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.finite . to_finite_tac) :\n  \u2203 e, e \u2208 t \u2227 e \u2209 s :=\ndiff_nonempty_of_ncard_lt_ncard h hs\n\n@[simp] lemma ncard_inter_add_ncard_diff_eq_ncard (s t : set \u03b1) (hs : s.finite . to_finite_tac) :\n  (s \u2229 t).ncard + (s \\ t).ncard = s.ncard :=\nby rw [\u2190ncard_diff_add_ncard_eq_ncard (diff_subset s t) hs, sdiff_sdiff_right_self, inf_eq_inter]\n\nlemma ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.finite . to_finite_tac)\n(ht : t.finite . to_finite_tac) :\n  s.ncard = t.ncard \u2194 (s \\ t).ncard = (t \\ s).ncard :=\nby rw [\u2190ncard_inter_add_ncard_diff_eq_ncard s t hs, \u2190ncard_inter_add_ncard_diff_eq_ncard t s ht,\n    inter_comm, add_right_inj]\n\nlemma ncard_le_ncard_iff_ncard_diff_le_ncard_diff (hs : s.finite . to_finite_tac)\n(ht : t.finite . to_finite_tac)  :\n  s.ncard \u2264 t.ncard \u2194 (s \\ t).ncard \u2264 (t \\ s).ncard :=\nby rw [\u2190ncard_inter_add_ncard_diff_eq_ncard s t hs, \u2190ncard_inter_add_ncard_diff_eq_ncard t s ht,\n     inter_comm, add_le_add_iff_left]\n\nlemma ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff (hs : s.finite . to_finite_tac)\n(ht : t.finite . to_finite_tac)  :\n  s.ncard < t.ncard \u2194 (s \\ t).ncard < (t \\ s).ncard :=\nby rw [\u2190ncard_inter_add_ncard_diff_eq_ncard s t hs, \u2190ncard_inter_add_ncard_diff_eq_ncard t s ht,\n     inter_comm, add_lt_add_iff_left]\n\nlemma ncard_add_ncard_compl (s : set \u03b1) (hs : s.finite . to_finite_tac) \n(hsc : s\u1d9c.finite . to_finite_tac) :\n  s.ncard + s\u1d9c.ncard = nat.card \u03b1 :=\nby rw [\u2190ncard_univ, \u2190ncard_union_eq (@disjoint_compl_right _ _ s) hs hsc, union_compl_self]\n\nend lattice\n\n/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`\n    inside it. -/\nlemma exists_intermediate_set (i : \u2115) (h\u2081 : i + s.ncard \u2264 t.ncard) (h\u2082 : s \u2286 t) :\n  \u2203 (r : set \u03b1), s \u2286 r \u2227 r \u2286 t \u2227 r.ncard = i + s.ncard :=\nbegin\n  cases t.finite_or_infinite with ht ht,\n  { haveI := ht.to_subtype,\n    haveI := (ht.subset h\u2082).to_subtype,\n    simp_rw [ncard_eq_to_finset_card] at h\u2081 \u22a2,\n    obtain \u27e8r', hsr', hr't, hr'\u27e9 := finset.exists_intermediate_set _ h\u2081 (by simpa),\n    exact \u27e8r', by simpa using hsr', by simpa using hr't, by rw [\u2190hr', ncard_coe_finset]\u27e9},\n  rw [ht.ncard] at h\u2081,\n  have h\u2081' := nat.eq_zero_of_le_zero h\u2081,\n  rw [add_eq_zero_iff] at h\u2081',\n  exact \u27e8t, h\u2082, rfl.subset, by rw [ht.ncard, h\u2081'.1, h\u2081'.2]\u27e9\nend\n\nlemma exists_intermediate_set' {m : \u2115} (hs : s.ncard \u2264 m) (ht : m \u2264 t.ncard) (h : s \u2286 t) :\n  \u2203 (r : set \u03b1), s \u2286 r \u2227 r \u2286 t \u2227 r.ncard = m :=\nbegin\n  obtain \u27e8r,hsr,hrt,hc\u27e9 := \n    exists_intermediate_set (m - s.ncard) (by rwa [tsub_add_cancel_of_le hs]) h, \n  rw tsub_add_cancel_of_le hs at hc, \n  exact \u27e8r,hsr,hrt,hc\u27e9,  \nend\n\n/-- We can shrink `s` to any smaller size. -/\nlemma exists_smaller_set (s : set \u03b1) (i : \u2115) (h\u2081 : i \u2264 s.ncard) :\n  \u2203 (t : set \u03b1), t \u2286 s \u2227 t.ncard = i :=\n(exists_intermediate_set i (by simpa) (empty_subset s)).imp\n  (\u03bb t ht, \u27e8ht.2.1,by simpa using ht.2.2\u27e9)\n\nlemma exists_subset_or_subset_of_two_mul_lt_ncard {n : \u2115} (hst : 2 * n < (s \u222a t).ncard) :\n  \u2203 (r : set \u03b1), n < r.ncard \u2227 (r \u2286 s \u2228 r \u2286 t) :=\nbegin\n  have hu := (finite_of_ncard_ne_zero ((nat.zero_le _).trans_lt hst).ne.symm),\n  rw [ncard_eq_to_finset_card _ hu, finite.to_finset_union\n    (hu.subset (subset_union_left _ _)) (hu.subset (subset_union_right _ _))] at hst,\n  obtain \u27e8r', hnr', hr'\u27e9 := finset.exists_subset_or_subset_of_two_mul_lt_card hst,\n  exact \u27e8r', by simpa , by simpa using hr'\u27e9,\nend\n\n/-! ### Explicit description of a set from its cardinality -/\n\n@[simp] lemma ncard_eq_one : s.ncard = 1 \u2194 \u2203 a, s = {a} :=\nbegin\n  refine \u27e8\u03bb h, _,by {rintro \u27e8a,rfl\u27e9, rw [ncard_singleton]}\u27e9,\n  haveI := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).to_subtype,\n  rw [ncard_eq_to_finset_card, finset.card_eq_one] at h,\n  exact h.imp (\u03bb a ha, by rwa [\u2190finite.to_finset_singleton, finite.to_finset_inj] at ha),\nend\n\nlemma exists_eq_insert_iff_ncard (hs : s.finite . to_finite_tac) :\n  (\u2203 a \u2209 s, insert a s = t) \u2194 s \u2286 t \u2227 s.ncard + 1 = t.ncard :=\nbegin\n  split,\n  { rintro \u27e8a, ha, rfl\u27e9,\n    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ (hs.insert a),\n      finite.to_finset_insert, \u2190@finite.to_finset_subset_to_finset _ _ _ hs (hs.insert a),\n      finite.to_finset_insert],\n    refine (@finset.exists_eq_insert_iff _ _ hs.to_finset (insert a hs.to_finset)).mp _,\n    exact \u27e8a, by rwa finite.mem_to_finset, rfl\u27e9},\n  rintro \u27e8hst, h\u27e9,\n  have ht := @finite_of_ncard_pos _ t (by {rw \u2190h, apply nat.zero_lt_succ}),\n\n  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h,\n  obtain \u27e8a,has, ha\u27e9 := (finset.exists_eq_insert_iff.mpr \u27e8by {simpa},h\u27e9),\n  have hsa := hs.insert a,\n  rw \u2190finite.to_finset_insert at ha,\n  exact \u27e8a, by {rwa finite.mem_to_finset at has}, by {rwa \u2190@finite.to_finset_inj _ _ _ hsa ht}\u27e9,\nend\n\nlemma ncard_le_one (hs : s.finite . to_finite_tac) :\n  s.ncard \u2264 1 \u2194 \u2200 (a \u2208 s) (b \u2208 s), a = b :=\nby simp_rw [ncard_eq_to_finset_card _ hs, finset.card_le_one, finite.mem_to_finset]\n\nlemma ncard_le_one_iff (hs : s.finite . to_finite_tac) :\n  s.ncard \u2264 1 \u2194 \u2200 {a b}, a \u2208 s \u2192 b \u2208 s \u2192 a = b :=\nby { rw ncard_le_one hs, tauto}\n\nlemma ncard_le_one_iff_subset_singleton [nonempty \u03b1] (hs : s.finite . to_finite_tac) :\n  s.ncard \u2264 1 \u2194 \u2203 (x : \u03b1), s \u2286 {x} :=\nby simp_rw [ncard_eq_to_finset_card _ hs, finset.card_le_one_iff_subset_singleton,\n  finite.to_finset_subset, finset.coe_singleton]\n\n/-- A `set` of a subsingleton type has cardinality at most one. -/\nlemma ncard_le_one_of_subsingleton [subsingleton \u03b1] (s : set \u03b1) :\n  s.ncard \u2264 1 :=\nby {rw [ncard_eq_to_finset_card], exact finset.card_le_one_of_subsingleton _}\n\nlemma one_lt_ncard (hs : s.finite . to_finite_tac) :\n  1 < s.ncard \u2194 \u2203 (a \u2208 s) (b \u2208 s), a \u2260 b :=\nby simp_rw [ncard_eq_to_finset_card _ hs, finset.one_lt_card, finite.mem_to_finset]\n\nlemma one_lt_ncard_iff (hs : s.finite . to_finite_tac) :\n  1 < s.ncard \u2194 \u2203 a b, a \u2208 s \u2227 b \u2208 s \u2227 a \u2260 b :=\nby { rw one_lt_ncard hs, simp only [exists_prop, exists_and_distrib_left] }\n\nlemma two_lt_ncard_iff (hs : s.finite . to_finite_tac) :\n  2 < s.ncard \u2194 \u2203 a b c, a \u2208 s \u2227 b \u2208 s \u2227 c \u2208 s \u2227 a \u2260 b \u2227 a \u2260 c \u2227 b \u2260 c :=\nby simp_rw [ncard_eq_to_finset_card _ hs, finset.two_lt_card_iff, finite.mem_to_finset]\n\nlemma two_lt_card (hs : s.finite . to_finite_tac) :\n  2 < s.ncard \u2194 \u2203 (a \u2208 s) (b \u2208 s) (c \u2208 s), a \u2260 b \u2227 a \u2260 c \u2227 b \u2260 c :=\nby simp only [two_lt_ncard_iff hs, exists_and_distrib_left, exists_prop]\n\nlemma exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : \u03b1) : \u2203 b, b \u2208 s \u2227 b \u2260 a :=\nbegin\n  haveI := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm).to_subtype,\n  rw [ncard_eq_to_finset_card] at hs,\n  simpa only [finite.mem_to_finset] using finset.exists_ne_of_one_lt_card hs a,\nend\n\nlemma eq_insert_of_ncard_eq_succ {n : \u2115} (h : s.ncard = n + 1) :\n  \u2203 a t, a \u2209 t \u2227 insert a t = s \u2227 t.ncard = n :=\nbegin\n  haveI := @fintype.of_finite _ (finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)).to_subtype,\n  rw [ncard_eq_to_finset_card, finset.card_eq_succ] at h,\n  obtain \u27e8a,t,hat,hts,rfl\u27e9 := h,\n  refine \u27e8a,t,hat,_,by rw ncard_coe_finset\u27e9,\n  rw [\u2190to_finset_inj],\n  convert hts,\n  simp only [to_finset_insert, finset.to_finset_coe],\nend\n\nlemma ncard_eq_succ {n : \u2115} (hs : s.finite . to_finite_tac) :\n  s.ncard = n + 1 \u2194 \u2203 a t, a \u2209 t \u2227 insert a t = s \u2227 t.ncard = n :=\nbegin\n  refine \u27e8eq_insert_of_ncard_eq_succ, _\u27e9,\n  rintro \u27e8a,t,hat,h,rfl\u27e9,\n  rw [\u2190 h, ncard_insert_of_not_mem hat (hs.subset ((subset_insert a t).trans_eq h))]\nend\n\nlemma ncard_eq_two :\n  s.ncard = 2 \u2194 \u2203 x y, x \u2260 y \u2227 s = {x, y} :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { obtain \u27e8x,t,hxt,rfl,ht\u27e9 :=  eq_insert_of_ncard_eq_succ h,\n    obtain \u27e8y,rfl\u27e9 := ncard_eq_one.mp ht,\n    rw mem_singleton_iff at hxt,\n    exact \u27e8_,_,hxt,rfl\u27e9},\n  rintro \u27e8x,y,hxy,rfl\u27e9,\n  rw [ncard_eq_to_finset_card, finset.card_eq_two],\n  exact \u27e8x,y,hxy, by {ext, simp}\u27e9,\nend\n\nlemma ncard_eq_three :\n  s.ncard = 3 \u2194 \u2203 x y z, x \u2260 y \u2227 x \u2260 z \u2227 y \u2260 z \u2227 s = {x, y, z} :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { obtain \u27e8x,t,hxt,rfl,ht\u27e9 :=  eq_insert_of_ncard_eq_succ h,\n    obtain \u27e8y,z,hyz,rfl\u27e9 := ncard_eq_two.mp ht,\n    rw [mem_insert_iff, mem_singleton_iff, not_or_distrib] at hxt,\n    exact \u27e8x,y,z,hxt.1,hxt.2,hyz,rfl\u27e9},\n  rintro \u27e8x, y, z, xy, xz, yz, rfl\u27e9,\n  rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton],\n  { rwa mem_singleton_iff},\n  rw [mem_insert_iff, mem_singleton_iff],\n  tauto,\nend\n\nend set\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/matroid/aux/ncard.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7068357225304102}}
{"text": "/-\nThis is a section.\nIt contains 00DZ, 00E0, 00E1 and 00E2 and 00E3 and 00E4 and 00E5 and 00E6 and 00E7 and 00E8 and 04PM\n\nIt also contains the following useful claim, just under Lemma 10.16.2 (tag 00E0):\n\nThe sets D(f) are open and form a basis for this topology (on Spec(R))\n\n-/\n\nimport Kenny_comm_alg.temp analysis.topology.topological_space Kenny_comm_alg.Zariski\n\nuniverse u \nvariables \u03b1 : Type u\nvariable t : topological_space \u03b1 \n#check t \n#print topological_space \n\ndef topological_space.is_topological_basis' {\u03b1 : Type u} [t : topological_space \u03b1] (s : set (set \u03b1)) :=\n(\u2200 U : set \u03b1, U \u2208 s \u2192 t.is_open U) \u2227 \n(\u2200 U : set \u03b1, t.is_open U \u2192 (\u2200 x, x \u2208 U \u2192 \u2203 V : set \u03b1, V \u2208 s \u2227 x \u2208 V \u2227 V \u2286 U))\n\n#print topological_space.generate_open\n\nlemma topological_space.generate_from_apply {\u03b1 : Type u} [t : topological_space \u03b1] (s : set (set \u03b1)) (U : set \u03b1) :\n  topological_space.is_open (topological_space.generate_from s) U \u2194 topological_space.generate_open s U := iff.rfl\n\nlemma basis_is_basis' {\u03b1 : Type u} [t : topological_space \u03b1] (s : set (set \u03b1)) : \n  topological_space.is_topological_basis s \u2194 topological_space.is_topological_basis' s :=\nbegin\n  split,\n  { intro H,\n    split,\n    { intros U HU,\n      rw H.right.right,\n      exact topological_space.generate_open.basic U HU },\n    { intros U HU x Hx,\n      unfold topological_space.is_topological_basis at H,\n      rw H.2.2 at HU,\n      have H3 : topological_space.generate_open s U := HU,\n      induction H3 with U4 H5 U6 U7 H8 H9 H10 H11 UU12 H13 H14,\n      { existsi U4,\n        split,exact H5,\n        split,exact Hx,\n        exact set.subset.refl U4\n      },\n      { have H4 := H.2.1,\n        have H5 : x \u2208 \u22c3\u2080 s,\n          rw H4,unfold set.univ,\n        cases H5 with V HV,\n        cases HV with H6 H7,\n        existsi V,\n        split,exact H6,\n        split,exact H7,\n        exact set.subset_univ V,\n      },\n      { have H12 := H10 (set.inter_subset_left U6 U7 Hx) H8,\n        have H13 := H11 (set.inter_subset_right U6 U7 Hx) H9,\n        cases H12 with V14 H14,\n        cases H13 with V15 H15,\n        have H16 := H.1 V14 H14.1 V15 H15.1 x \u27e8H14.2.1,H15.2.1\u27e9,\n        cases H16 with V H17,\n        cases H17 with H18 H19, \n        existsi V,\n        split,exact H18,\n        split,exact H19.1,\n        refine set.subset.trans H19.2 _,\n        intro z,\n        apply and.imp,\n        { intro hz, exact H14.2.2 hz },\n        { intro hz, exact H15.2.2 hz }\n      },\n      { cases Hx with V HV,\n        cases HV with H15 H16,\n        rcases H14 V H15 H16 (H13 V H15) with \u27e8W, H17, H18, H19\u27e9,\n        refine \u27e8W, H17, H18, _\u27e9,\n        intros z hz,\n        exact \u27e8V, H15, H19 hz\u27e9\n      }\n    }\n  },\n  { intro H,\n    split,\n    { intros U1 H1 U2 H2 x H3,\n      have H4 := H.1 U1 H1,\n      have H5 := H.1 U2 H2,\n      have H6 := H.2 (U1 \u2229 U2) (topological_space.is_open_inter t U1 U2 H4 H5) x H3,\n      rcases H6 with \u27e8V, H7, H8, H9\u27e9,\n      exact \u27e8V, H7, H8, H9\u27e9\n    },\n    split,\n    { apply set.ext,\n      intro x,\n      rw iff_true_right (set.mem_univ x),\n      have H1 := H.2 set.univ (topological_space.is_open_univ t) x trivial,\n      rcases H1 with \u27e8V, H2, H3, H4\u27e9,\n      existsi V,\n      existsi H2,\n      exact H3\n    },\n    { apply topological_space_eq,\n      apply funext,\n      intro U,\n      apply propext,\n      rw topological_space.generate_from_apply,\n      split,\n      { intro H1,\n        have H2 := H.2 U H1,\n        have H3 : U = \u22c3\u2080 {V | \u2203 x \u2208 U, V \u2208 s \u2227 x \u2208 V \u2227 V \u2286 U},\n        { apply set.ext,\n          intro x,\n          split,\n          { intro H3,\n            have H4 := H2 x H3,\n            rcases H4 with \u27e8V, H4\u27e9,\n            existsi V,\n            fapply exists.intro,\n            exact \u27e8x, H3, H4\u27e9,\n            exact H4.2.1\n          },\n          { intro H3,\n            rcases H3 with \u27e8U1, H3, H4\u27e9,\n            rcases H3 with \u27e8y, H3, H5, H6, H7\u27e9,\n            exact H7 H4\n          }\n        },\n        rw H3,\n        apply topological_space.generate_open.sUnion,\n        intros U1 H4,\n        rcases H4 with \u27e8U1, H4, H5, H6, H7\u27e9,\n        apply topological_space.generate_open.basic,\n        exact H5\n      },\n      { exact generate_from_le H.1 U }\n    }\n  }\nend \n\nlemma D_f_form_basis (R : Type) [comm_ring R] : \n  topological_space.is_topological_basis {U : set (X R) | \u2203 f : R, U = Spec.D'(f)} := \nbegin\n  rw basis_is_basis',\n  split,\n  { intros U H,\n    cases H with f Hf,\n    existsi ({f} : set R),\n    rw Hf,\n    unfold Spec.D',\n    unfold Spec.V,\n    unfold Spec.V',\n    rw set.compl_compl,\n    simp\n  },\n  { intros U H x H1,\n    cases H with U1 H,\n    have H2 : U = -Spec.V U1,\n    { rw [H, set.compl_compl] },\n    rw set.set_eq_def at H2,\n    have H3 := H2 x,\n    rw iff_true_left H1 at H3,\n    simp [Spec.V, has_subset.subset, set.subset] at H3,\n    rw classical.not_forall at H3,\n    cases H3 with f H3,\n    rw @@not_imp (classical.prop_decidable _) at H3,\n    cases H3 with H3 H4,\n    existsi Spec.D' f,\n    split,\n    { existsi f,\n      refl\n    },\n    split,\n    { exact H4 },\n    { intros y H5,\n      rw H2,\n      intro H6,\n      apply H5,\n      exact H6 H3\n    }\n  }\nend", "meta": {"author": "kbuzzard", "repo": "lean-stacks-project", "sha": "b57be17aa917f1c3a23c59db5ee37b1aa21112c2", "save_path": "github-repos/lean/kbuzzard-lean-stacks-project", "path": "github-repos/lean/kbuzzard-lean-stacks-project/lean-stacks-project-b57be17aa917f1c3a23c59db5ee37b1aa21112c2/scratch/basis_ramblings.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.7068357182562002}}
{"text": "/-\nCopyright (c) 2021 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport group_theory.perm.cycle_type\n\n/-!\n# Alternating Groups\n\nThe alternating group on a finite type `\u03b1` is the subgroup of the permutation group `perm \u03b1`\nconsisting of the even permutations.\n\n## Main definitions\n\n* `alternating_group \u03b1` is the alternating group on `\u03b1`, defined as a `subgroup (perm \u03b1)`.\n\n## Main results\n* `two_mul_card_alternating_group` shows that the alternating group is half as large as\n  the permutation group it is a subgroup of.\n\n* `closure_three_cycles_eq_alternating` shows that the alternating group is\n  generated by three-cycles.\n\n## Tags\nalternating group permutation\n\n\n## TODO\n* Show that `alternating_group \u03b1` is simple if and only if `fintype.card \u03b1 \u2260 4`.\n\n-/\n\nopen equiv equiv.perm subgroup fintype\nvariables (\u03b1 : Type*) [fintype \u03b1] [decidable_eq \u03b1]\n\n/-- The alternating group on a finite type, realized as a subgroup of `equiv.perm`.\n  For $A_n$, use `alternating_group (fin n)`. -/\n@[derive fintype] def alternating_group : subgroup (perm \u03b1) :=\nsign.ker\n\ninstance [subsingleton \u03b1] : unique (alternating_group \u03b1) :=\n\u27e8\u27e81\u27e9, \u03bb \u27e8p, hp\u27e9, subtype.eq (subsingleton.elim p _)\u27e9\n\nvariables {\u03b1}\n\nlemma alternating_group_eq_sign_ker : alternating_group \u03b1 = sign.ker := rfl\n\nnamespace equiv.perm\n\n@[simp]\nlemma mem_alternating_group {f : perm \u03b1} :\n  f \u2208 alternating_group \u03b1 \u2194 sign f = 1 :=\nsign.mem_ker\n\nlemma prod_list_swap_mem_alternating_group_iff_even_length {l : list (perm \u03b1)}\n  (hl : \u2200 g \u2208 l, is_swap g) :\n  l.prod \u2208 alternating_group \u03b1 \u2194 even l.length :=\nbegin\n  rw [mem_alternating_group, sign_prod_list_swap hl, \u2190 units.coe_eq_one, units.coe_pow,\n    units.coe_neg_one, nat.neg_one_pow_eq_one_iff_even],\n  dec_trivial\nend\n\nend equiv.perm\n\nlemma two_mul_card_alternating_group [nontrivial \u03b1] :\n  2 * card (alternating_group \u03b1) = card (perm \u03b1) :=\nbegin\n  let := (quotient_group.quotient_ker_equiv_of_surjective _ (sign_surjective \u03b1)).to_equiv,\n  rw [\u2190fintype.card_units_int, \u2190fintype.card_congr this],\n  exact (subgroup.card_eq_card_quotient_mul_card_subgroup _).symm,\nend\n\ninstance alternating_group_normal : (alternating_group \u03b1).normal := sign.normal_ker\n\nnamespace equiv.perm\n\n@[simp]\ntheorem closure_three_cycles_eq_alternating :\n  closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3} = alternating_group \u03b1 :=\nclosure_eq_of_le _ (\u03bb \u03c3 h\u03c3, mem_alternating_group.2 h\u03c3.sign) $ \u03bb \u03c3 h\u03c3, begin\n  suffices hind : \u2200 (n : \u2115) (l : list (perm \u03b1)) (hl : \u2200 g, g \u2208 l \u2192 is_swap g)\n    (hn : l.length = 2 * n), l.prod \u2208 closure {\u03c3 : perm \u03b1 | is_three_cycle \u03c3},\n  { obtain \u27e8l, rfl, hl\u27e9 := trunc_swap_factors \u03c3,\n    obtain \u27e8n, hn\u27e9 := (prod_list_swap_mem_alternating_group_iff_even_length hl).1 h\u03c3,\n    exact hind n l hl hn },\n  intro n,\n  induction n with n ih; intros l hl hn,\n  { simp [list.length_eq_zero.1 hn, one_mem] },\n  rw [nat.mul_succ] at hn,\n  obtain \u27e8a, l, rfl\u27e9 := l.exists_of_length_succ hn,\n  rw [list.length_cons, nat.succ_inj'] at hn,\n  obtain \u27e8b, l, rfl\u27e9 := l.exists_of_length_succ hn,\n  rw [list.prod_cons, list.prod_cons, \u2190 mul_assoc],\n  rw [list.length_cons, nat.succ_inj'] at hn,\n  exact mul_mem _ (is_swap.mul_mem_closure_three_cycles (hl a (list.mem_cons_self a _))\n    (hl b (list.mem_cons_of_mem a (l.mem_cons_self b))))\n    (ih _ (\u03bb g hg, hl g (list.mem_cons_of_mem _ (list.mem_cons_of_mem _ hg))) hn),\nend\n\nend equiv.perm\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/specific_groups/alternating.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7068061953184782}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\nThe integers, with addition, multiplication, and subtraction.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.basic\nimport Mathlib.algebra.order_functions\nimport Mathlib.PostPort\n\nuniverses u_1 u \n\nnamespace Mathlib\n\nnamespace int\n\n\nprotected instance inhabited : Inhabited \u2124 :=\n  { default := int.zero }\n\nprotected instance nontrivial : nontrivial \u2124 :=\n  nontrivial.mk (Exists.intro 0 (Exists.intro 1 int.zero_ne_one))\n\nprotected instance comm_ring : comm_ring \u2124 :=\n  comm_ring.mk int.add int.add_assoc int.zero int.zero_add int.add_zero int.neg int.sub int.add_left_neg int.add_comm\n    int.mul int.mul_assoc int.one int.one_mul int.mul_one int.distrib_left int.distrib_right int.mul_comm\n\n/-! ### Extra instances to short-circuit type class resolution -/\n\n-- instance : has_sub int           := by apply_instance -- This is in core\n\nprotected instance add_comm_monoid : add_comm_monoid \u2124 :=\n  add_comm_group.to_add_comm_monoid \u2124\n\nprotected instance add_monoid : add_monoid \u2124 :=\n  sub_neg_monoid.to_add_monoid \u2124\n\nprotected instance monoid : monoid \u2124 :=\n  ring.to_monoid \u2124\n\nprotected instance comm_monoid : comm_monoid \u2124 :=\n  comm_semiring.to_comm_monoid \u2124\n\nprotected instance comm_semigroup : comm_semigroup \u2124 :=\n  comm_ring.to_comm_semigroup \u2124\n\nprotected instance semigroup : semigroup \u2124 :=\n  monoid.to_semigroup \u2124\n\nprotected instance add_comm_semigroup : add_comm_semigroup \u2124 :=\n  add_comm_monoid.to_add_comm_semigroup \u2124\n\nprotected instance add_semigroup : add_semigroup \u2124 :=\n  add_monoid.to_add_semigroup \u2124\n\nprotected instance comm_semiring : comm_semiring \u2124 :=\n  comm_ring.to_comm_semiring\n\nprotected instance semiring : semiring \u2124 :=\n  ring.to_semiring\n\nprotected instance ring : ring \u2124 :=\n  comm_ring.to_ring \u2124\n\nprotected instance distrib : distrib \u2124 :=\n  ring.to_distrib \u2124\n\nprotected instance linear_ordered_comm_ring : linear_ordered_comm_ring \u2124 :=\n  linear_ordered_comm_ring.mk comm_ring.add comm_ring.add_assoc comm_ring.zero comm_ring.zero_add comm_ring.add_zero\n    comm_ring.neg comm_ring.sub comm_ring.add_left_neg comm_ring.add_comm comm_ring.mul comm_ring.mul_assoc comm_ring.one\n    comm_ring.one_mul comm_ring.mul_one comm_ring.left_distrib comm_ring.right_distrib linear_order.le linear_order.lt\n    linear_order.le_refl linear_order.le_trans linear_order.le_antisymm int.add_le_add_left sorry int.mul_pos\n    linear_order.le_total linear_order.decidable_le linear_order.decidable_eq linear_order.decidable_lt\n    nontrivial.exists_pair_ne comm_ring.mul_comm\n\nprotected instance linear_ordered_add_comm_group : linear_ordered_add_comm_group \u2124 :=\n  linear_ordered_ring.to_linear_ordered_add_comm_group\n\ntheorem abs_eq_nat_abs (a : \u2124) : abs a = \u2191(nat_abs a) :=\n  int.cases_on a (fun (a : \u2115) => idRhs (abs \u2191a = \u2191a) (abs_of_nonneg (coe_zero_le a)))\n    fun (a : \u2115) => idRhs (abs (Int.negSucc a) = -Int.negSucc a) (abs_of_nonpos (le_of_lt (neg_succ_lt_zero a)))\n\ntheorem nat_abs_abs (a : \u2124) : nat_abs (abs a) = nat_abs a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs (abs a) = nat_abs a)) (abs_eq_nat_abs a))) (Eq.refl (nat_abs \u2191(nat_abs a)))\n\ntheorem sign_mul_abs (a : \u2124) : sign a * abs a = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (sign a * abs a = a)) (abs_eq_nat_abs a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (sign a * \u2191(nat_abs a) = a)) (sign_mul_nat_abs a))) (Eq.refl a))\n\n@[simp] theorem default_eq_zero : Inhabited.default = 0 :=\n  rfl\n\n@[simp] theorem add_def {a : \u2124} {b : \u2124} : int.add a b = a + b :=\n  rfl\n\n@[simp] theorem mul_def {a : \u2124} {b : \u2124} : int.mul a b = a * b :=\n  rfl\n\n@[simp] theorem coe_nat_mul_neg_succ (m : \u2115) (n : \u2115) : \u2191m * Int.negSucc n = -(\u2191m * \u2191(Nat.succ n)) :=\n  rfl\n\n@[simp] theorem neg_succ_mul_coe_nat (m : \u2115) (n : \u2115) : Int.negSucc m * \u2191n = -(\u2191(Nat.succ m) * \u2191n) :=\n  rfl\n\n@[simp] theorem neg_succ_mul_neg_succ (m : \u2115) (n : \u2115) : Int.negSucc m * Int.negSucc n = \u2191(Nat.succ m) * \u2191(Nat.succ n) :=\n  rfl\n\n@[simp] theorem coe_nat_le {m : \u2115} {n : \u2115} : \u2191m \u2264 \u2191n \u2194 m \u2264 n :=\n  coe_nat_le_coe_nat_iff m n\n\n@[simp] theorem coe_nat_lt {m : \u2115} {n : \u2115} : \u2191m < \u2191n \u2194 m < n :=\n  coe_nat_lt_coe_nat_iff m n\n\n@[simp] theorem coe_nat_inj' {m : \u2115} {n : \u2115} : \u2191m = \u2191n \u2194 m = n :=\n  int.coe_nat_eq_coe_nat_iff m n\n\n@[simp] theorem coe_nat_pos {n : \u2115} : 0 < \u2191n \u2194 0 < n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 < \u2191n \u2194 0 < n)) (Eq.symm int.coe_nat_zero)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u21910 < \u2191n \u2194 0 < n)) (propext coe_nat_lt))) (iff.refl (0 < n)))\n\n@[simp] theorem coe_nat_eq_zero {n : \u2115} : \u2191n = 0 \u2194 n = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191n = 0 \u2194 n = 0)) (Eq.symm int.coe_nat_zero)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191n = \u21910 \u2194 n = 0)) (propext coe_nat_inj'))) (iff.refl (n = 0)))\n\ntheorem coe_nat_ne_zero {n : \u2115} : \u2191n \u2260 0 \u2194 n \u2260 0 :=\n  not_congr coe_nat_eq_zero\n\n@[simp] theorem coe_nat_nonneg (n : \u2115) : 0 \u2264 \u2191n :=\n  iff.mpr coe_nat_le (nat.zero_le n)\n\ntheorem coe_nat_ne_zero_iff_pos {n : \u2115} : \u2191n \u2260 0 \u2194 0 < n :=\n  { mp := fun (h : \u2191n \u2260 0) => nat.pos_of_ne_zero (iff.mp coe_nat_ne_zero h),\n    mpr := fun (h : 0 < n) => ne.symm (ne_of_lt (iff.mpr coe_nat_lt h)) }\n\ntheorem coe_nat_succ_pos (n : \u2115) : 0 < \u2191(Nat.succ n) :=\n  iff.mpr coe_nat_pos (nat.succ_pos n)\n\n@[simp] theorem coe_nat_abs (n : \u2115) : abs \u2191n = \u2191n :=\n  abs_of_nonneg (coe_nat_nonneg n)\n\n/-! ### succ and pred -/\n\n/-- Immediate successor of an integer: `succ n = n + 1` -/\ndef succ (a : \u2124) : \u2124 :=\n  a + 1\n\n/-- Immediate predecessor of an integer: `pred n = n - 1` -/\ndef pred (a : \u2124) : \u2124 :=\n  a - 1\n\ntheorem nat_succ_eq_int_succ (n : \u2115) : \u2191(Nat.succ n) = succ \u2191n :=\n  rfl\n\ntheorem pred_succ (a : \u2124) : pred (succ a) = a :=\n  add_sub_cancel a 1\n\ntheorem succ_pred (a : \u2124) : succ (pred a) = a :=\n  sub_add_cancel a 1\n\ntheorem neg_succ (a : \u2124) : -succ a = pred (-a) :=\n  neg_add a 1\n\ntheorem succ_neg_succ (a : \u2124) : succ (-succ a) = -a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (succ (-succ a) = -a)) (neg_succ a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (succ (pred (-a)) = -a)) (succ_pred (-a)))) (Eq.refl (-a)))\n\ntheorem neg_pred (a : \u2124) : -pred a = succ (-a) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-pred a = succ (-a))) (eq_neg_of_eq_neg (Eq.symm (neg_succ (-a))))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-pred a = -pred ( --a))) (neg_neg a))) (Eq.refl (-pred a)))\n\ntheorem pred_neg_pred (a : \u2124) : pred (-pred a) = -a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (pred (-pred a) = -a)) (neg_pred a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (pred (succ (-a)) = -a)) (pred_succ (-a)))) (Eq.refl (-a)))\n\ntheorem pred_nat_succ (n : \u2115) : pred \u2191(Nat.succ n) = \u2191n :=\n  pred_succ \u2191n\n\ntheorem neg_nat_succ (n : \u2115) : -\u2191(Nat.succ n) = pred (-\u2191n) :=\n  neg_succ \u2191n\n\ntheorem succ_neg_nat_succ (n : \u2115) : succ (-\u2191(Nat.succ n)) = -\u2191n :=\n  succ_neg_succ \u2191n\n\ntheorem lt_succ_self (a : \u2124) : a < succ a :=\n  lt_add_of_pos_right a zero_lt_one\n\ntheorem pred_self_lt (a : \u2124) : pred a < a :=\n  sub_lt_self a zero_lt_one\n\ntheorem add_one_le_iff {a : \u2124} {b : \u2124} : a + 1 \u2264 b \u2194 a < b :=\n  iff.rfl\n\ntheorem lt_add_one_iff {a : \u2124} {b : \u2124} : a < b + 1 \u2194 a \u2264 b :=\n  add_le_add_iff_right 1\n\ntheorem le_add_one {a : \u2124} {b : \u2124} (h : a \u2264 b) : a \u2264 b + 1 :=\n  le_of_lt (iff.mpr lt_add_one_iff h)\n\ntheorem sub_one_lt_iff {a : \u2124} {b : \u2124} : a - 1 < b \u2194 a \u2264 b :=\n  iff.trans sub_lt_iff_lt_add lt_add_one_iff\n\ntheorem le_sub_one_iff {a : \u2124} {b : \u2124} : a \u2264 b - 1 \u2194 a < b :=\n  le_sub_iff_add_le\n\nprotected theorem induction_on {p : \u2124 \u2192 Prop} (i : \u2124) (hz : p 0) (hp : \u2200 (i : \u2115), p \u2191i \u2192 p (\u2191i + 1)) (hn : \u2200 (i : \u2115), p (-\u2191i) \u2192 p (-\u2191i - 1)) : p i := sorry\n\n/-- Inductively define a function on `\u2124` by defining it at `b`, for the `succ` of a number greater\n  than `b`, and the `pred` of a number less than `b`. -/\nprotected def induction_on' {C : \u2124 \u2192 Sort u_1} (z : \u2124) (b : \u2124) : C b \u2192 ((k : \u2124) \u2192 b \u2264 k \u2192 C k \u2192 C (k + 1)) \u2192 ((k : \u2124) \u2192 k \u2264 b \u2192 C k \u2192 C (k - 1)) \u2192 C z :=\n  fun (H0 : C b) (Hs : (k : \u2124) \u2192 b \u2264 k \u2192 C k \u2192 C (k + 1)) (Hp : (k : \u2124) \u2192 k \u2264 b \u2192 C k \u2192 C (k - 1)) =>\n    eq.mpr sorry\n      (Int.rec\n        (fun (n : \u2115) =>\n          Nat.rec (eq.mpr sorry (eq.mpr sorry H0))\n            (fun (n : \u2115) (ih : C (Int.ofNat n + b)) =>\n              eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (Hs (Int.ofNat n + b) sorry ih)))))\n            n)\n        (fun (n : \u2115) =>\n          Nat.rec (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (Hp b sorry H0))))))\n            (fun (n : \u2115) (ih : C (Int.negSucc n + b)) =>\n              eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (eq.mpr sorry (Hp (Int.negSucc n + b) sorry ih)))))\n            n)\n        (z - b))\n\n/-! ### nat abs -/\n\ntheorem nat_abs_add_le (a : \u2124) (b : \u2124) : nat_abs (a + b) \u2264 nat_abs a + nat_abs b := sorry\n\ntheorem nat_abs_neg_of_nat (n : \u2115) : nat_abs (neg_of_nat n) = n :=\n  nat.cases_on n (Eq.refl (nat_abs (neg_of_nat 0))) fun (n : \u2115) => Eq.refl (nat_abs (neg_of_nat (Nat.succ n)))\n\ntheorem nat_abs_mul (a : \u2124) (b : \u2124) : nat_abs (a * b) = nat_abs a * nat_abs b := sorry\n\ntheorem nat_abs_mul_nat_abs_eq {a : \u2124} {b : \u2124} {c : \u2115} (h : a * b = \u2191c) : nat_abs a * nat_abs b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a * nat_abs b = c)) (Eq.symm (nat_abs_mul a b))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs (a * b) = c)) h))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs \u2191c = c)) (nat_abs_of_nat c))) (Eq.refl c)))\n\n@[simp] theorem nat_abs_mul_self' (a : \u2124) : \u2191(nat_abs a) * \u2191(nat_abs a) = a * a :=\n  eq.mpr\n    (id (Eq._oldrec (Eq.refl (\u2191(nat_abs a) * \u2191(nat_abs a) = a * a)) (Eq.symm (int.coe_nat_mul (nat_abs a) (nat_abs a)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(nat_abs a * nat_abs a) = a * a)) nat_abs_mul_self)) (Eq.refl (a * a)))\n\ntheorem neg_succ_of_nat_eq' (m : \u2115) : Int.negSucc m = -\u2191m - 1 := sorry\n\ntheorem nat_abs_ne_zero_of_ne_zero {z : \u2124} (hz : z \u2260 0) : nat_abs z \u2260 0 :=\n  fun (h : nat_abs z = 0) => hz (eq_zero_of_nat_abs_eq_zero h)\n\n@[simp] theorem nat_abs_eq_zero {a : \u2124} : nat_abs a = 0 \u2194 a = 0 :=\n  { mp := eq_zero_of_nat_abs_eq_zero, mpr := fun (h : a = 0) => Eq.symm h \u25b8 rfl }\n\ntheorem nat_abs_lt_nat_abs_of_nonneg_of_lt {a : \u2124} {b : \u2124} (w\u2081 : 0 \u2264 a) (w\u2082 : a < b) : nat_abs a < nat_abs b := sorry\n\ntheorem nat_abs_eq_iff_mul_self_eq {a : \u2124} {b : \u2124} : nat_abs a = nat_abs b \u2194 a * a = b * b := sorry\n\ntheorem nat_abs_lt_iff_mul_self_lt {a : \u2124} {b : \u2124} : nat_abs a < nat_abs b \u2194 a * a < b * b := sorry\n\ntheorem nat_abs_le_iff_mul_self_le {a : \u2124} {b : \u2124} : nat_abs a \u2264 nat_abs b \u2194 a * a \u2264 b * b := sorry\n\ntheorem nat_abs_eq_iff_sq_eq {a : \u2124} {b : \u2124} : nat_abs a = nat_abs b \u2194 a ^ bit0 1 = b ^ bit0 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a = nat_abs b \u2194 a ^ bit0 1 = b ^ bit0 1)) (pow_two a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a = nat_abs b \u2194 a * a = b ^ bit0 1)) (pow_two b)))\n      nat_abs_eq_iff_mul_self_eq)\n\ntheorem nat_abs_lt_iff_sq_lt {a : \u2124} {b : \u2124} : nat_abs a < nat_abs b \u2194 a ^ bit0 1 < b ^ bit0 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a < nat_abs b \u2194 a ^ bit0 1 < b ^ bit0 1)) (pow_two a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a < nat_abs b \u2194 a * a < b ^ bit0 1)) (pow_two b)))\n      nat_abs_lt_iff_mul_self_lt)\n\ntheorem nat_abs_le_iff_sq_le {a : \u2124} {b : \u2124} : nat_abs a \u2264 nat_abs b \u2194 a ^ bit0 1 \u2264 b ^ bit0 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a \u2264 nat_abs b \u2194 a ^ bit0 1 \u2264 b ^ bit0 1)) (pow_two a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_abs a \u2264 nat_abs b \u2194 a * a \u2264 b ^ bit0 1)) (pow_two b)))\n      nat_abs_le_iff_mul_self_le)\n\n/-! ### `/`  -/\n\n@[simp] theorem of_nat_div (m : \u2115) (n : \u2115) : Int.ofNat (m / n) = Int.ofNat m / Int.ofNat n :=\n  rfl\n\n@[simp] theorem coe_nat_div (m : \u2115) (n : \u2115) : \u2191(m / n) = \u2191m / \u2191n :=\n  rfl\n\ntheorem neg_succ_of_nat_div (m : \u2115) {b : \u2124} (H : 0 < b) : Int.negSucc m / b = -(\u2191m / b + 1) := sorry\n\n@[simp] protected theorem div_neg (a : \u2124) (b : \u2124) : a / -b = -(a / b) := sorry\n\ntheorem div_of_neg_of_pos {a : \u2124} {b : \u2124} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) := sorry\n\nprotected theorem div_nonneg {a : \u2124} {b : \u2124} (Ha : 0 \u2264 a) (Hb : 0 \u2264 b) : 0 \u2264 a / b := sorry\n\nprotected theorem div_nonpos {a : \u2124} {b : \u2124} (Ha : 0 \u2264 a) (Hb : b \u2264 0) : a / b \u2264 0 :=\n  nonpos_of_neg_nonneg\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 -(a / b))) (Eq.symm (int.div_neg a b))))\n      (int.div_nonneg Ha (neg_nonneg_of_nonpos Hb)))\n\ntheorem div_neg' {a : \u2124} {b : \u2124} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 := sorry\n\n-- Will be generalized to Euclidean domains.\n\nprotected theorem zero_div (b : \u2124) : 0 / b = 0 :=\n  int.cases_on b\n    (fun (b : \u2115) => nat.cases_on b (idRhs (0 / 0 = 0 / 0) rfl) fun (b : \u2115) => idRhs (0 / \u2191(b + 1) = 0 / \u2191(b + 1)) rfl)\n    fun (b : \u2115) => idRhs (0 / Int.negSucc b = 0 / Int.negSucc b) rfl\n\nprotected theorem div_zero (a : \u2124) : a / 0 = 0 :=\n  int.cases_on a\n    (fun (a : \u2115) => nat.cases_on a (idRhs (0 / 0 = 0 / 0) rfl) fun (a : \u2115) => idRhs (\u2191(a + 1) / 0 = \u2191(a + 1) / 0) rfl)\n    fun (a : \u2115) => idRhs (Int.negSucc a / 0 = Int.negSucc a / 0) rfl\n\n@[simp] protected theorem div_one (a : \u2124) : a / 1 = a := sorry\n\ntheorem div_eq_zero_of_lt {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : a < b) : a / b = 0 := sorry\n\ntheorem div_eq_zero_of_lt_abs {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : a < abs b) : a / b = 0 := sorry\n\nprotected theorem add_mul_div_right (a : \u2124) (b : \u2124) {c : \u2124} (H : c \u2260 0) : (a + b * c) / c = a / c + b := sorry\n\nprotected theorem add_mul_div_left (a : \u2124) {b : \u2124} (c : \u2124) (H : b \u2260 0) : (a + b * c) / b = a / b + c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b * c) / b = a / b + c)) (mul_comm b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a + c * b) / b = a / b + c)) (int.add_mul_div_right a c H))) (Eq.refl (a / b + c)))\n\nprotected theorem add_div_of_dvd_right {a : \u2124} {b : \u2124} {c : \u2124} (H : c \u2223 b) : (a + b) / c = a / c + b / c := sorry\n\nprotected theorem add_div_of_dvd_left {a : \u2124} {b : \u2124} {c : \u2124} (H : c \u2223 a) : (a + b) / c = a / c + b / c := sorry\n\n@[simp] protected theorem mul_div_cancel (a : \u2124) {b : \u2124} (H : b \u2260 0) : a * b / b = a :=\n  eq.mp (Eq._oldrec (Eq.refl (a * b / b = 0 + a)) (zero_add a))\n    (eq.mp (Eq._oldrec (Eq.refl (a * b / b = 0 / b + a)) (int.zero_div b))\n      (eq.mp (Eq._oldrec (Eq.refl ((0 + a * b) / b = 0 / b + a)) (zero_add (a * b))) (int.add_mul_div_right 0 a H)))\n\n@[simp] protected theorem mul_div_cancel_left {a : \u2124} (b : \u2124) (H : a \u2260 0) : a * b / a = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b / a = b)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / a = b)) (int.mul_div_cancel b H))) (Eq.refl b))\n\n@[simp] protected theorem div_self {a : \u2124} (H : a \u2260 0) : a / a = 1 :=\n  eq.mp (Eq._oldrec (Eq.refl (1 * a / a = 1)) (one_mul a)) (int.mul_div_cancel 1 H)\n\n/-! ### mod -/\n\ntheorem of_nat_mod (m : \u2115) (n : \u2115) : \u2191m % \u2191n = Int.ofNat (m % n) :=\n  rfl\n\n@[simp] theorem coe_nat_mod (m : \u2115) (n : \u2115) : \u2191(m % n) = \u2191m % \u2191n :=\n  rfl\n\ntheorem neg_succ_of_nat_mod (m : \u2115) {b : \u2124} (bpos : 0 < b) : Int.negSucc m % b = b - 1 - \u2191m % b := sorry\n\n@[simp] theorem mod_neg (a : \u2124) (b : \u2124) : a % -b = a % b := sorry\n\n@[simp] theorem mod_abs (a : \u2124) (b : \u2124) : a % abs b = a % b :=\n  abs_by_cases (fun (i : \u2124) => a % i = a % b) rfl (mod_neg a b)\n\ntheorem zero_mod (b : \u2124) : 0 % b = 0 :=\n  congr_arg Int.ofNat (nat.zero_mod (nat_abs b))\n\ntheorem mod_zero (a : \u2124) : a % 0 = a :=\n  int.cases_on a (fun (a : \u2115) => idRhs (Int.ofNat (a % 0) = Int.ofNat a) (congr_arg Int.ofNat (nat.mod_zero a)))\n    fun (a : \u2115) => idRhs (Int.negSucc (a % 0) = Int.negSucc a) (congr_arg Int.negSucc (nat.mod_zero a))\n\ntheorem mod_one (a : \u2124) : a % 1 = 0 := sorry\n\ntheorem mod_eq_of_lt {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : a < b) : a % b = a := sorry\n\ntheorem mod_nonneg (a : \u2124) {b : \u2124} : b \u2260 0 \u2192 0 \u2264 a % b := sorry\n\ntheorem mod_lt_of_pos (a : \u2124) {b : \u2124} (H : 0 < b) : a % b < b := sorry\n\ntheorem mod_lt (a : \u2124) {b : \u2124} (H : b \u2260 0) : a % b < abs b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a % b < abs b)) (Eq.symm (mod_abs a b)))) (mod_lt_of_pos a (iff.mpr abs_pos H))\n\ntheorem mod_add_div_aux (m : \u2115) (n : \u2115) : \u2191n - (\u2191m % \u2191n + 1) - (\u2191n * (\u2191m / \u2191n) + \u2191n) = Int.negSucc m := sorry\n\ntheorem mod_add_div (a : \u2124) (b : \u2124) : a % b + b * (a / b) = a := sorry\n\ntheorem div_add_mod (a : \u2124) (b : \u2124) : b * (a / b) + a % b = a :=\n  Eq.trans (add_comm (b * (a / b)) (a % b)) (mod_add_div a b)\n\ntheorem mod_def (a : \u2124) (b : \u2124) : a % b = a - b * (a / b) :=\n  eq_sub_of_add_eq (mod_add_div a b)\n\n@[simp] theorem add_mul_mod_self {a : \u2124} {b : \u2124} {c : \u2124} : (a + b * c) % c = a % c := sorry\n\n@[simp] theorem add_mul_mod_self_left (a : \u2124) (b : \u2124) (c : \u2124) : (a + b * c) % b = a % b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b * c) % b = a % b)) (mul_comm b c)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a + c * b) % b = a % b)) add_mul_mod_self)) (Eq.refl (a % b)))\n\n@[simp] theorem add_mod_self {a : \u2124} {b : \u2124} : (a + b) % b = a % b :=\n  eq.mp (Eq._oldrec (Eq.refl ((a + b * 1) % b = a % b)) (mul_one b)) (add_mul_mod_self_left a b 1)\n\n@[simp] theorem add_mod_self_left {a : \u2124} {b : \u2124} : (a + b) % a = b % a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b) % a = b % a)) (add_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((b + a) % a = b % a)) add_mod_self)) (Eq.refl (b % a)))\n\n@[simp] theorem mod_add_mod (m : \u2124) (n : \u2124) (k : \u2124) : (m % n + k) % n = (m + k) % n := sorry\n\n@[simp] theorem add_mod_mod (m : \u2124) (n : \u2124) (k : \u2124) : (m + n % k) % k = (m + n) % k :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((m + n % k) % k = (m + n) % k)) (add_comm m (n % k))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((n % k + m) % k = (m + n) % k)) (mod_add_mod n k m)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((n + m) % k = (m + n) % k)) (add_comm n m))) (Eq.refl ((m + n) % k))))\n\ntheorem add_mod (a : \u2124) (b : \u2124) (n : \u2124) : (a + b) % n = (a % n + b % n) % n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a + b) % n = (a % n + b % n) % n)) (add_mod_mod (a % n) b n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a + b) % n = (a % n + b) % n)) (mod_add_mod a n b))) (Eq.refl ((a + b) % n)))\n\ntheorem add_mod_eq_add_mod_right {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) (H : m % n = k % n) : (m + i) % n = (k + i) % n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((m + i) % n = (k + i) % n)) (Eq.symm (mod_add_mod m n i))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((m % n + i) % n = (k + i) % n)) (Eq.symm (mod_add_mod k n i))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((m % n + i) % n = (k % n + i) % n)) H)) (Eq.refl ((k % n + i) % n))))\n\ntheorem add_mod_eq_add_mod_left {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) (H : m % n = k % n) : (i + m) % n = (i + k) % n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((i + m) % n = (i + k) % n)) (add_comm i m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((m + i) % n = (i + k) % n)) (add_mod_eq_add_mod_right i H)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((k + i) % n = (i + k) % n)) (add_comm k i))) (Eq.refl ((i + k) % n))))\n\ntheorem mod_add_cancel_right {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) : (m + i) % n = (k + i) % n \u2194 m % n = k % n := sorry\n\ntheorem mod_add_cancel_left {m : \u2124} {n : \u2124} {k : \u2124} {i : \u2124} : (i + m) % n = (i + k) % n \u2194 m % n = k % n := sorry\n\ntheorem mod_sub_cancel_right {m : \u2124} {n : \u2124} {k : \u2124} (i : \u2124) : (m - i) % n = (k - i) % n \u2194 m % n = k % n :=\n  mod_add_cancel_right (-i)\n\ntheorem mod_eq_mod_iff_mod_sub_eq_zero {m : \u2124} {n : \u2124} {k : \u2124} : m % n = k % n \u2194 (m - k) % n = 0 := sorry\n\n@[simp] theorem mul_mod_left (a : \u2124) (b : \u2124) : a * b % b = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b % b = 0)) (Eq.symm (zero_add (a * b)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((0 + a * b) % b = 0)) add_mul_mod_self))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 % b = 0)) (zero_mod b))) (Eq.refl 0)))\n\n@[simp] theorem mul_mod_right (a : \u2124) (b : \u2124) : a * b % a = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b % a = 0)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a % a = 0)) (mul_mod_left b a))) (Eq.refl 0))\n\ntheorem mul_mod (a : \u2124) (b : \u2124) (n : \u2124) : a * b % n = a % n * (b % n) % n := sorry\n\n@[simp] theorem neg_mod_two (i : \u2124) : -i % bit0 1 = i % bit0 1 := sorry\n\ntheorem mod_self {a : \u2124} : a % a = 0 :=\n  eq.mp (Eq._oldrec (Eq.refl (1 * a % a = 0)) (one_mul a)) (mul_mod_left 1 a)\n\n@[simp] theorem mod_mod_of_dvd (n : \u2124) {m : \u2124} {k : \u2124} (h : m \u2223 k) : n % k % m = n % m := sorry\n\n@[simp] theorem mod_mod (a : \u2124) (b : \u2124) : a % b % b = a % b := sorry\n\ntheorem sub_mod (a : \u2124) (b : \u2124) (n : \u2124) : (a - b) % n = (a % n - b % n) % n := sorry\n\n/-! ### properties of `/` and `%` -/\n\n@[simp] theorem mul_div_mul_of_pos {a : \u2124} (b : \u2124) (c : \u2124) (H : 0 < a) : a * b / (a * c) = b / c := sorry\n\n@[simp] theorem mul_div_mul_of_pos_left (a : \u2124) {b : \u2124} (c : \u2124) (H : 0 < b) : a * b / (c * b) = a / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b / (c * b) = a / c)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / (c * b) = a / c)) (mul_comm c b)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / (b * c) = a / c)) (mul_div_mul_of_pos a c H))) (Eq.refl (a / c))))\n\n@[simp] theorem mul_mod_mul_of_pos {a : \u2124} (b : \u2124) (c : \u2124) (H : 0 < a) : a * b % (a * c) = a * (b % c) := sorry\n\ntheorem lt_div_add_one_mul_self (a : \u2124) {b : \u2124} (H : 0 < b) : a < (a / b + 1) * b := sorry\n\ntheorem abs_div_le_abs (a : \u2124) (b : \u2124) : abs (a / b) \u2264 abs a := sorry\n\ntheorem div_le_self {a : \u2124} (b : \u2124) (Ha : 0 \u2264 a) : a / b \u2264 a :=\n  eq.mp (Eq._oldrec (Eq.refl (a / b \u2264 abs a)) (abs_of_nonneg Ha)) (le_trans (le_abs_self (a / b)) (abs_div_le_abs a b))\n\ntheorem mul_div_cancel_of_mod_eq_zero {a : \u2124} {b : \u2124} (H : a % b = 0) : b * (a / b) = a :=\n  eq.mp (Eq._oldrec (Eq.refl (0 + b * (a / b) = a)) (zero_add (b * (a / b))))\n    (eq.mp (Eq._oldrec (Eq.refl (a % b + b * (a / b) = a)) H) (mod_add_div a b))\n\ntheorem div_mul_cancel_of_mod_eq_zero {a : \u2124} {b : \u2124} (H : a % b = 0) : a / b * b = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b * b = a)) (mul_comm (a / b) b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * (a / b) = a)) (mul_div_cancel_of_mod_eq_zero H))) (Eq.refl a))\n\ntheorem mod_two_eq_zero_or_one (n : \u2124) : n % bit0 1 = 0 \u2228 n % bit0 1 = 1 := sorry\n\n/-! ### dvd -/\n\ntheorem coe_nat_dvd {m : \u2115} {n : \u2115} : \u2191m \u2223 \u2191n \u2194 m \u2223 n := sorry\n\ntheorem coe_nat_dvd_left {n : \u2115} {z : \u2124} : \u2191n \u2223 z \u2194 n \u2223 nat_abs z := sorry\n\ntheorem coe_nat_dvd_right {n : \u2115} {z : \u2124} : z \u2223 \u2191n \u2194 nat_abs z \u2223 n := sorry\n\ntheorem dvd_antisymm {a : \u2124} {b : \u2124} (H1 : 0 \u2264 a) (H2 : 0 \u2264 b) : a \u2223 b \u2192 b \u2223 a \u2192 a = b := sorry\n\ntheorem dvd_of_mod_eq_zero {a : \u2124} {b : \u2124} (H : b % a = 0) : a \u2223 b :=\n  Exists.intro (b / a) (Eq.symm (mul_div_cancel_of_mod_eq_zero H))\n\ntheorem mod_eq_zero_of_dvd {a : \u2124} {b : \u2124} : a \u2223 b \u2192 b % a = 0 := sorry\n\ntheorem dvd_iff_mod_eq_zero (a : \u2124) (b : \u2124) : a \u2223 b \u2194 b % a = 0 :=\n  { mp := mod_eq_zero_of_dvd, mpr := dvd_of_mod_eq_zero }\n\n/-- If `a % b = c` then `b` divides `a - c`. -/\ntheorem dvd_sub_of_mod_eq {a : \u2124} {b : \u2124} {c : \u2124} (h : a % b = c) : b \u2223 a - c := sorry\n\ntheorem nat_abs_dvd {a : \u2124} {b : \u2124} : \u2191(nat_abs a) \u2223 b \u2194 a \u2223 b := sorry\n\ntheorem dvd_nat_abs {a : \u2124} {b : \u2124} : a \u2223 \u2191(nat_abs b) \u2194 a \u2223 b := sorry\n\nprotected instance decidable_dvd : DecidableRel has_dvd.dvd :=\n  fun (a n : \u2124) => decidable_of_decidable_of_iff (int.decidable_eq (n % a) 0) sorry\n\nprotected theorem div_mul_cancel {a : \u2124} {b : \u2124} (H : b \u2223 a) : a / b * b = a :=\n  div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H)\n\nprotected theorem mul_div_cancel' {a : \u2124} {b : \u2124} (H : a \u2223 b) : a * (b / a) = b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * (b / a) = b)) (mul_comm a (b / a))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b / a * a = b)) (int.div_mul_cancel H))) (Eq.refl b))\n\nprotected theorem mul_div_assoc (a : \u2124) {b : \u2124} {c : \u2124} : c \u2223 b \u2192 a * b / c = a * (b / c) := sorry\n\nprotected theorem mul_div_assoc' (b : \u2124) {a : \u2124} {c : \u2124} (h : c \u2223 a) : a * b / c = a / c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a * b / c = a / c * b)) (mul_comm a b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a / c = a / c * b)) (int.mul_div_assoc b h)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (b * (a / c) = a / c * b)) (mul_comm b (a / c)))) (Eq.refl (a / c * b))))\n\ntheorem div_dvd_div {a : \u2124} {b : \u2124} {c : \u2124} (H1 : a \u2223 b) (H2 : b \u2223 c) : b / a \u2223 c / a := sorry\n\nprotected theorem eq_mul_of_div_eq_right {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2223 a) (H2 : a / b = c) : a = b * c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = b * c)) (Eq.symm H2)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * (a / b))) (int.mul_div_cancel' H1))) (Eq.refl a))\n\nprotected theorem div_eq_of_eq_mul_right {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2260 0) (H2 : a = b * c) : a / b = c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b = c)) H2))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * c / b = c)) (int.mul_div_cancel_left c H1))) (Eq.refl c))\n\nprotected theorem eq_div_of_mul_eq_right {a : \u2124} {b : \u2124} {c : \u2124} (H1 : a \u2260 0) (H2 : a * b = c) : b = c / a :=\n  Eq.symm (int.div_eq_of_eq_mul_right H1 (Eq.symm H2))\n\nprotected theorem div_eq_iff_eq_mul_right {a : \u2124} {b : \u2124} {c : \u2124} (H : b \u2260 0) (H' : b \u2223 a) : a / b = c \u2194 a = b * c :=\n  { mp := int.eq_mul_of_div_eq_right H', mpr := int.div_eq_of_eq_mul_right H }\n\nprotected theorem div_eq_iff_eq_mul_left {a : \u2124} {b : \u2124} {c : \u2124} (H : b \u2260 0) (H' : b \u2223 a) : a / b = c \u2194 a = c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a / b = c \u2194 a = c * b)) (mul_comm c b))) (int.div_eq_iff_eq_mul_right H H')\n\nprotected theorem eq_mul_of_div_eq_left {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2223 a) (H2 : a / b = c) : a = c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a = c * b)) (mul_comm c b)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * c)) (int.eq_mul_of_div_eq_right H1 H2))) (Eq.refl (b * c)))\n\nprotected theorem div_eq_of_eq_mul_left {a : \u2124} {b : \u2124} {c : \u2124} (H1 : b \u2260 0) (H2 : a = c * b) : a / b = c :=\n  int.div_eq_of_eq_mul_right H1\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * c)) (mul_comm b c)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a = c * b)) H2)) (Eq.refl (c * b))))\n\ntheorem neg_div_of_dvd {a : \u2124} {b : \u2124} (H : b \u2223 a) : -a / b = -(a / b) := sorry\n\ntheorem sub_div_of_dvd {a : \u2124} {b : \u2124} {c : \u2124} (hcb : c \u2223 b) : (a - b) / c = a / c - b / c := sorry\n\ntheorem sub_div_of_dvd_sub {a : \u2124} {b : \u2124} {c : \u2124} (hcab : c \u2223 a - b) : (a - b) / c = a / c - b / c :=\n  eq.mpr (id (Eq._oldrec (Eq.refl ((a - b) / c = a / c - b / c)) (propext eq_sub_iff_add_eq)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl ((a - b) / c + b / c = a / c)) (Eq.symm (int.add_div_of_dvd_left hcab))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl ((a - b + b) / c = a / c)) (sub_add_cancel a b))) (Eq.refl (a / c))))\n\ntheorem div_sign (a : \u2124) (b : \u2124) : a / sign b = a * sign b := sorry\n\n@[simp] theorem sign_mul (a : \u2124) (b : \u2124) : sign (a * b) = sign a * sign b := sorry\n\nprotected theorem sign_eq_div_abs (a : \u2124) : sign a = a / abs a := sorry\n\ntheorem mul_sign (i : \u2124) : i * sign i = \u2191(nat_abs i) := sorry\n\ntheorem le_of_dvd {a : \u2124} {b : \u2124} (bpos : 0 < b) (H : a \u2223 b) : a \u2264 b := sorry\n\ntheorem eq_one_of_dvd_one {a : \u2124} (H : 0 \u2264 a) (H' : a \u2223 1) : a = 1 := sorry\n\ntheorem eq_one_of_mul_eq_one_right {a : \u2124} {b : \u2124} (H : 0 \u2264 a) (H' : a * b = 1) : a = 1 :=\n  eq_one_of_dvd_one H (Exists.intro b (Eq.symm H'))\n\ntheorem eq_one_of_mul_eq_one_left {a : \u2124} {b : \u2124} (H : 0 \u2264 b) (H' : a * b = 1) : b = 1 :=\n  eq_one_of_mul_eq_one_right H\n    (eq.mpr (id (Eq._oldrec (Eq.refl (b * a = 1)) (mul_comm b a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (a * b = 1)) H')) (Eq.refl 1)))\n\ntheorem of_nat_dvd_of_dvd_nat_abs {a : \u2115} {z : \u2124} (haz : a \u2223 nat_abs z) : \u2191a \u2223 z := sorry\n\ntheorem dvd_nat_abs_of_of_nat_dvd {a : \u2115} {z : \u2124} (haz : \u2191a \u2223 z) : a \u2223 nat_abs z := sorry\n\ntheorem pow_dvd_of_le_of_pow_dvd {p : \u2115} {m : \u2115} {n : \u2115} {k : \u2124} (hmn : m \u2264 n) (hdiv : \u2191(p ^ n) \u2223 k) : \u2191(p ^ m) \u2223 k := sorry\n\ntheorem dvd_of_pow_dvd {p : \u2115} {k : \u2115} {m : \u2124} (hk : 1 \u2264 k) (hpk : \u2191(p ^ k) \u2223 m) : \u2191p \u2223 m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191p \u2223 m)) (Eq.symm (pow_one p)))) (pow_dvd_of_le_of_pow_dvd hk hpk)\n\n/-- If `n > 0` then `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)`\n  for some `k`. -/\ntheorem exists_lt_and_lt_iff_not_dvd (m : \u2124) {n : \u2124} (hn : 0 < n) : (\u2203 (k : \u2124), n * k < m \u2227 m < n * (k + 1)) \u2194 \u00acn \u2223 m := sorry\n\n/-! ### `/` and ordering -/\n\nprotected theorem div_mul_le (a : \u2124) {b : \u2124} (H : b \u2260 0) : a / b * b \u2264 a :=\n  le_of_sub_nonneg\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 a - a / b * b)) (mul_comm (a / b) b)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 a - b * (a / b))) (Eq.symm (mod_def a b)))) (mod_nonneg a H)))\n\nprotected theorem div_le_of_le_mul {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H' : a \u2264 b * c) : a / c \u2264 b :=\n  le_of_mul_le_mul_right (le_trans (int.div_mul_le a (ne_of_gt H)) H') H\n\nprotected theorem mul_lt_of_lt_div {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H3 : a < b / c) : a * c < b :=\n  lt_of_not_ge (mt (int.div_le_of_le_mul H) (not_le_of_gt H3))\n\nprotected theorem mul_le_of_le_div {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 < c) (H2 : a \u2264 b / c) : a * c \u2264 b :=\n  le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le b (ne_of_gt H1))\n\nprotected theorem le_div_of_mul_le {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 < c) (H2 : a * c \u2264 b) : a \u2264 b / c :=\n  le_of_lt_add_one (lt_of_mul_lt_mul_right (lt_of_le_of_lt H2 (lt_div_add_one_mul_self b H1)) (le_of_lt H1))\n\nprotected theorem le_div_iff_mul_le {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) : a \u2264 b / c \u2194 a * c \u2264 b :=\n  { mp := int.mul_le_of_le_div H, mpr := int.le_div_of_mul_le H }\n\nprotected theorem div_le_div {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H' : a \u2264 b) : a / c \u2264 b / c :=\n  int.le_div_of_mul_le H (le_trans (int.div_mul_le a (ne_of_gt H)) H')\n\nprotected theorem div_lt_of_lt_mul {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) (H' : a < b * c) : a / c < b :=\n  lt_of_not_ge (mt (int.mul_le_of_le_div H) (not_le_of_gt H'))\n\nprotected theorem lt_mul_of_div_lt {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 < c) (H2 : a / c < b) : a < b * c :=\n  lt_of_not_ge (mt (int.le_div_of_mul_le H1) (not_le_of_gt H2))\n\nprotected theorem div_lt_iff_lt_mul {a : \u2124} {b : \u2124} {c : \u2124} (H : 0 < c) : a / c < b \u2194 a < b * c :=\n  { mp := int.lt_mul_of_div_lt H, mpr := int.div_lt_of_lt_mul H }\n\nprotected theorem le_mul_of_div_le {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 a) (H3 : a / b \u2264 c) : a \u2264 c * b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 c * b)) (Eq.symm (int.div_mul_cancel H2)))) (mul_le_mul_of_nonneg_right H3 H1)\n\nprotected theorem lt_div_of_mul_lt {a : \u2124} {b : \u2124} {c : \u2124} (H1 : 0 \u2264 b) (H2 : b \u2223 c) (H3 : a * b < c) : a < c / b :=\n  lt_of_not_ge (mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3))\n\nprotected theorem lt_div_iff_mul_lt {a : \u2124} {b : \u2124} (c : \u2124) (H : 0 < c) (H' : c \u2223 b) : a < b / c \u2194 a * c < b :=\n  { mp := int.mul_lt_of_lt_div H, mpr := int.lt_div_of_mul_lt (le_of_lt H) H' }\n\ntheorem div_pos_of_pos_of_dvd {a : \u2124} {b : \u2124} (H1 : 0 < a) (H2 : 0 \u2264 b) (H3 : b \u2223 a) : 0 < a / b :=\n  int.lt_div_of_mul_lt H2 H3 (eq.mpr (id (Eq._oldrec (Eq.refl (0 * b < a)) (zero_mul b))) H1)\n\ntheorem div_eq_div_of_mul_eq_mul {a : \u2124} {b : \u2124} {c : \u2124} {d : \u2124} (H2 : d \u2223 c) (H3 : b \u2260 0) (H4 : d \u2260 0) (H5 : a * d = b * c) : a / b = c / d :=\n  int.div_eq_of_eq_mul_right H3\n    (eq.mpr (id (Eq._oldrec (Eq.refl (a = b * (c / d))) (Eq.symm (int.mul_div_assoc b H2))))\n      (Eq.symm (int.div_eq_of_eq_mul_left H4 (Eq.symm H5))))\n\ntheorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a : \u2124} {b : \u2124} {c : \u2124} {d : \u2124} (hb : b \u2260 0) (hbc : b \u2223 c) (h : b * a = c * d) : a = c / b * d := sorry\n\n/-- If an integer with larger absolute value divides an integer, it is\nzero. -/\ntheorem eq_zero_of_dvd_of_nat_abs_lt_nat_abs {a : \u2124} {b : \u2124} (w : a \u2223 b) (h : nat_abs b < nat_abs a) : b = 0 := sorry\n\ntheorem eq_zero_of_dvd_of_nonneg_of_lt {a : \u2124} {b : \u2124} (w\u2081 : 0 \u2264 a) (w\u2082 : a < b) (h : b \u2223 a) : a = 0 :=\n  eq_zero_of_dvd_of_nat_abs_lt_nat_abs h (nat_abs_lt_nat_abs_of_nonneg_of_lt w\u2081 w\u2082)\n\n/-- If two integers are congruent to a sufficiently large modulus,\nthey are equal. -/\ntheorem eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs {a : \u2124} {b : \u2124} {c : \u2124} (h1 : a % b = c) (h2 : nat_abs (a - c) < nat_abs b) : a = c :=\n  eq_of_sub_eq_zero (eq_zero_of_dvd_of_nat_abs_lt_nat_abs (dvd_sub_of_mod_eq h1) h2)\n\ntheorem of_nat_add_neg_succ_of_nat_of_lt {m : \u2115} {n : \u2115} (h : m < Nat.succ n) : Int.ofNat m + Int.negSucc n = Int.negSucc (n - m) := sorry\n\ntheorem of_nat_add_neg_succ_of_nat_of_ge {m : \u2115} {n : \u2115} (h : Nat.succ n \u2264 m) : Int.ofNat m + Int.negSucc n = Int.ofNat (m - Nat.succ n) := sorry\n\n@[simp] theorem neg_add_neg (m : \u2115) (n : \u2115) : Int.negSucc m + Int.negSucc n = Int.negSucc (Nat.succ (m + n)) :=\n  rfl\n\n/-! ### to_nat -/\n\ntheorem to_nat_eq_max (a : \u2124) : \u2191(to_nat a) = max a 0 :=\n  int.cases_on a (fun (a : \u2115) => idRhs (\u2191a = max (\u2191a) 0) (Eq.symm (max_eq_left (coe_zero_le a))))\n    fun (a : \u2115) => idRhs (0 = max (Int.negSucc a) 0) (Eq.symm (max_eq_right (le_of_lt (neg_succ_lt_zero a))))\n\n@[simp] theorem to_nat_zero : to_nat 0 = 0 :=\n  rfl\n\n@[simp] theorem to_nat_one : to_nat 1 = 1 :=\n  rfl\n\n@[simp] theorem to_nat_of_nonneg {a : \u2124} (h : 0 \u2264 a) : \u2191(to_nat a) = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(to_nat a) = a)) (to_nat_eq_max a)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (max a 0 = a)) (max_eq_left h))) (Eq.refl a))\n\n@[simp] theorem to_nat_sub_of_le (a : \u2124) (b : \u2124) (h : b \u2264 a) : \u2191(to_nat (a + -b)) = a + -b :=\n  to_nat_of_nonneg (sub_nonneg_of_le h)\n\n@[simp] theorem to_nat_coe_nat (n : \u2115) : to_nat \u2191n = n :=\n  rfl\n\n@[simp] theorem to_nat_coe_nat_add_one {n : \u2115} : to_nat (\u2191n + 1) = n + 1 :=\n  rfl\n\ntheorem le_to_nat (a : \u2124) : a \u2264 \u2191(to_nat a) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a \u2264 \u2191(to_nat a))) (to_nat_eq_max a))) (le_max_left a 0)\n\n@[simp] theorem to_nat_le {a : \u2124} {n : \u2115} : to_nat a \u2264 n \u2194 a \u2264 \u2191n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (to_nat a \u2264 n \u2194 a \u2264 \u2191n)) (propext (iff.symm (coe_nat_le_coe_nat_iff (to_nat a) n)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(to_nat a) \u2264 \u2191n \u2194 a \u2264 \u2191n)) (to_nat_eq_max a)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (max a 0 \u2264 \u2191n \u2194 a \u2264 \u2191n)) (propext max_le_iff))) (and_iff_left (coe_zero_le n))))\n\n@[simp] theorem lt_to_nat {n : \u2115} {a : \u2124} : n < to_nat a \u2194 \u2191n < a :=\n  iff.mp le_iff_le_iff_lt_iff_lt to_nat_le\n\ntheorem to_nat_le_to_nat {a : \u2124} {b : \u2124} (h : a \u2264 b) : to_nat a \u2264 to_nat b :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (to_nat a \u2264 to_nat b)) (propext to_nat_le))) (le_trans h (le_to_nat b))\n\ntheorem to_nat_lt_to_nat {a : \u2124} {b : \u2124} (hb : 0 < b) : to_nat a < to_nat b \u2194 a < b := sorry\n\ntheorem lt_of_to_nat_lt {a : \u2124} {b : \u2124} (h : to_nat a < to_nat b) : a < b :=\n  iff.mp (to_nat_lt_to_nat (iff.mp lt_to_nat (lt_of_le_of_lt (nat.zero_le (to_nat a)) h))) h\n\ntheorem to_nat_add {a : \u2124} {b : \u2124} (ha : 0 \u2264 a) (hb : 0 \u2264 b) : to_nat (a + b) = to_nat a + to_nat b := sorry\n\ntheorem to_nat_add_one {a : \u2124} (h : 0 \u2264 a) : to_nat (a + 1) = to_nat a + 1 :=\n  to_nat_add h zero_le_one\n\n/-- If `n : \u2115`, then `int.to_nat' n = some n`, if `n : \u2124` is negative, then `int.to_nat' n = none`.\n-/\ndef to_nat' : \u2124 \u2192 Option \u2115 :=\n  sorry\n\ntheorem mem_to_nat' (a : \u2124) (n : \u2115) : n \u2208 to_nat' a \u2194 a = \u2191n := sorry\n\ntheorem to_nat_zero_of_neg {z : \u2124} : z < 0 \u2192 to_nat z = 0 := sorry\n\n/-! ### units -/\n\n@[simp] theorem units_nat_abs (u : units \u2124) : nat_abs \u2191u = 1 := sorry\n\ntheorem units_eq_one_or (u : units \u2124) : u = 1 \u2228 u = -1 := sorry\n\ntheorem units_inv_eq_self (u : units \u2124) : u\u207b\u00b9 = u :=\n  or.elim (units_eq_one_or u) (fun (h : u = 1) => Eq.symm h \u25b8 rfl) fun (h : u = -1) => Eq.symm h \u25b8 rfl\n\n@[simp] theorem units_mul_self (u : units \u2124) : u * u = 1 :=\n  or.elim (units_eq_one_or u) (fun (h : u = 1) => Eq.symm h \u25b8 rfl) fun (h : u = -1) => Eq.symm h \u25b8 rfl\n\n-- `units.coe_mul` is a \"wrong turn\" for the simplifier, this undoes it and simplifies further\n\n@[simp] theorem units_coe_mul_self (u : units \u2124) : \u2191u * \u2191u = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u2191u * \u2191u = 1)) (Eq.symm (units.coe_mul u u))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(u * u) = 1)) (units_mul_self u)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (\u21911 = 1)) units.coe_one)) (Eq.refl 1)))\n\n/-! ### bitwise ops -/\n\n@[simp] theorem bodd_zero : bodd 0 = false :=\n  rfl\n\n@[simp] theorem bodd_one : bodd 1 = tt :=\n  rfl\n\ntheorem bodd_two : bodd (bit0 1) = false :=\n  rfl\n\n@[simp] theorem bodd_coe (n : \u2115) : bodd \u2191n = nat.bodd n :=\n  rfl\n\n@[simp] theorem bodd_sub_nat_nat (m : \u2115) (n : \u2115) : bodd (sub_nat_nat m n) = bxor (nat.bodd m) (nat.bodd n) := sorry\n\n@[simp] theorem bodd_neg_of_nat (n : \u2115) : bodd (neg_of_nat n) = nat.bodd n := sorry\n\n@[simp] theorem bodd_neg (n : \u2124) : bodd (-n) = bodd n := sorry\n\n@[simp] theorem bodd_add (m : \u2124) (n : \u2124) : bodd (m + n) = bxor (bodd m) (bodd n) := sorry\n\n@[simp] theorem bodd_mul (m : \u2124) (n : \u2124) : bodd (m * n) = bodd m && bodd n := sorry\n\ntheorem bodd_add_div2 (n : \u2124) : cond (bodd n) 1 0 + bit0 1 * div2 n = n := sorry\n\ntheorem div2_val (n : \u2124) : div2 n = n / bit0 1 :=\n  int.cases_on n\n    (fun (n : \u2115) => idRhs (Int.ofNat (nat.div2 n) = Int.ofNat (n / bit0 1)) (congr_arg Int.ofNat (nat.div2_val n)))\n    fun (n : \u2115) => idRhs (Int.negSucc (nat.div2 n) = Int.negSucc (n / bit0 1)) (congr_arg Int.negSucc (nat.div2_val n))\n\ntheorem bit0_val (n : \u2124) : bit0 n = bit0 1 * n :=\n  Eq.symm (two_mul n)\n\ntheorem bit1_val (n : \u2124) : bit1 n = bit0 1 * n + 1 :=\n  congr_arg (fun (_x : \u2124) => _x + 1) (bit0_val n)\n\ntheorem bit_val (b : Bool) (n : \u2124) : bit b n = bit0 1 * n + cond b 1 0 :=\n  bool.cases_on b (Eq.trans (bit0_val n) (Eq.symm (add_zero (bit0 1 * n)))) (bit1_val n)\n\ntheorem bit_decomp (n : \u2124) : bit (bodd n) (div2 n) = n :=\n  Eq.trans (bit_val (bodd n) (div2 n)) (Eq.trans (add_comm (bit0 1 * div2 n) (cond (bodd n) 1 0)) (bodd_add_div2 n))\n\n/-- Defines a function from `\u2124` conditionally, if it is defined for odd and even integers separately\n  using `bit`. -/\ndef bit_cases_on {C : \u2124 \u2192 Sort u} (n : \u2124) (h : (b : Bool) \u2192 (n : \u2124) \u2192 C (bit b n)) : C n :=\n  eq.mpr sorry (h (bodd n) (div2 n))\n\n@[simp] theorem bit_zero : bit false 0 = 0 :=\n  rfl\n\n@[simp] theorem bit_coe_nat (b : Bool) (n : \u2115) : bit b \u2191n = \u2191(nat.bit b n) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (bit b \u2191n = \u2191(nat.bit b n))) (bit_val b \u2191n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 1 * \u2191n + cond b 1 0 = \u2191(nat.bit b n))) (nat.bit_val b n)))\n      (bool.cases_on b (Eq.refl (bit0 1 * \u2191n + cond false 1 0)) (Eq.refl (bit0 1 * \u2191n + cond tt 1 0))))\n\n@[simp] theorem bit_neg_succ (b : Bool) (n : \u2115) : bit b (Int.negSucc n) = Int.negSucc (nat.bit (!b) n) := sorry\n\n@[simp] theorem bodd_bit (b : Bool) (n : \u2124) : bodd (bit b n) = b := sorry\n\n@[simp] theorem bodd_bit0 (n : \u2124) : bodd (bit0 n) = false :=\n  bodd_bit false n\n\n@[simp] theorem bodd_bit1 (n : \u2124) : bodd (bit1 n) = tt :=\n  bodd_bit tt n\n\n@[simp] theorem div2_bit (b : Bool) (n : \u2124) : div2 (bit b n) = n := sorry\n\ntheorem bit0_ne_bit1 (m : \u2124) (n : \u2124) : bit0 m \u2260 bit1 n := sorry\n\ntheorem bit1_ne_bit0 (m : \u2124) (n : \u2124) : bit1 m \u2260 bit0 n :=\n  ne.symm (bit0_ne_bit1 n m)\n\ntheorem bit1_ne_zero (m : \u2124) : bit1 m \u2260 0 := sorry\n\n@[simp] theorem test_bit_zero (b : Bool) (n : \u2124) : test_bit (bit b n) 0 = b := sorry\n\n@[simp] theorem test_bit_succ (m : \u2115) (b : Bool) (n : \u2124) : test_bit (bit b n) (Nat.succ m) = test_bit n m := sorry\n\ntheorem bitwise_or : bitwise bor = lor := sorry\n\ntheorem bitwise_and : bitwise band = land := sorry\n\ntheorem bitwise_diff : (bitwise fun (a b : Bool) => a && !b) = ldiff := sorry\n\ntheorem bitwise_xor : bitwise bxor = lxor := sorry\n\n@[simp] theorem bitwise_bit (f : Bool \u2192 Bool \u2192 Bool) (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := sorry\n\n@[simp] theorem lor_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) := sorry\n\n@[simp] theorem land_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) : land (bit a m) (bit b n) = bit (a && b) (land m n) := sorry\n\n@[simp] theorem ldiff_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) : ldiff (bit a m) (bit b n) = bit (a && !b) (ldiff m n) := sorry\n\n@[simp] theorem lxor_bit (a : Bool) (m : \u2124) (b : Bool) (n : \u2124) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) := sorry\n\n@[simp] theorem lnot_bit (b : Bool) (n : \u2124) : lnot (bit b n) = bit (!b) (lnot n) := sorry\n\n@[simp] theorem test_bit_bitwise (f : Bool \u2192 Bool \u2192 Bool) (m : \u2124) (n : \u2124) (k : \u2115) : test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) := sorry\n\n@[simp] theorem test_bit_lor (m : \u2124) (n : \u2124) (k : \u2115) : test_bit (lor m n) k = test_bit m k || test_bit n k := sorry\n\n@[simp] theorem test_bit_land (m : \u2124) (n : \u2124) (k : \u2115) : test_bit (land m n) k = test_bit m k && test_bit n k := sorry\n\n@[simp] theorem test_bit_ldiff (m : \u2124) (n : \u2124) (k : \u2115) : test_bit (ldiff m n) k = test_bit m k && !test_bit n k := sorry\n\n@[simp] theorem test_bit_lxor (m : \u2124) (n : \u2124) (k : \u2115) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) := sorry\n\n@[simp] theorem test_bit_lnot (n : \u2124) (k : \u2115) : test_bit (lnot n) k = !test_bit n k := sorry\n\ntheorem shiftl_add (m : \u2124) (n : \u2115) (k : \u2124) : shiftl m (\u2191n + k) = shiftl (shiftl m \u2191n) k := sorry\n\ntheorem shiftl_sub (m : \u2124) (n : \u2115) (k : \u2124) : shiftl m (\u2191n - k) = shiftr (shiftl m \u2191n) k :=\n  shiftl_add m n (-k)\n\n@[simp] theorem shiftl_neg (m : \u2124) (n : \u2124) : shiftl m (-n) = shiftr m n :=\n  rfl\n\n@[simp] theorem shiftr_neg (m : \u2124) (n : \u2124) : shiftr m (-n) = shiftl m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (shiftr m (-n) = shiftl m n)) (Eq.symm (shiftl_neg m (-n)))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (shiftl m ( --n) = shiftl m n)) (neg_neg n))) (Eq.refl (shiftl m n)))\n\n@[simp] theorem shiftl_coe_nat (m : \u2115) (n : \u2115) : shiftl \u2191m \u2191n = \u2191(nat.shiftl m n) :=\n  rfl\n\n@[simp] theorem shiftr_coe_nat (m : \u2115) (n : \u2115) : shiftr \u2191m \u2191n = \u2191(nat.shiftr m n) :=\n  nat.cases_on n (Eq.refl (shiftr \u2191m \u21910)) fun (n : \u2115) => Eq.refl (shiftr \u2191m \u2191(Nat.succ n))\n\n@[simp] theorem shiftl_neg_succ (m : \u2115) (n : \u2115) : shiftl (Int.negSucc m) \u2191n = Int.negSucc (nat.shiftl' tt m n) :=\n  rfl\n\n@[simp] theorem shiftr_neg_succ (m : \u2115) (n : \u2115) : shiftr (Int.negSucc m) \u2191n = Int.negSucc (nat.shiftr m n) :=\n  nat.cases_on n (Eq.refl (shiftr (Int.negSucc m) \u21910)) fun (n : \u2115) => Eq.refl (shiftr (Int.negSucc m) \u2191(Nat.succ n))\n\ntheorem shiftr_add (m : \u2124) (n : \u2115) (k : \u2115) : shiftr m (\u2191n + \u2191k) = shiftr (shiftr m \u2191n) \u2191k := sorry\n\ntheorem shiftl_eq_mul_pow (m : \u2124) (n : \u2115) : shiftl m \u2191n = m * \u2191(bit0 1 ^ n) := sorry\n\ntheorem shiftr_eq_div_pow (m : \u2124) (n : \u2115) : shiftr m \u2191n = m / \u2191(bit0 1 ^ n) := sorry\n\ntheorem one_shiftl (n : \u2115) : shiftl 1 \u2191n = \u2191(bit0 1 ^ n) :=\n  congr_arg coe (nat.one_shiftl n)\n\n@[simp] theorem zero_shiftl (n : \u2124) : shiftl 0 n = 0 :=\n  int.cases_on n (fun (n : \u2115) => idRhs (\u2191(nat.shiftl 0 n) = \u21910) (congr_arg coe (nat.zero_shiftl n)))\n    fun (n : \u2115) => idRhs (\u2191(nat.shiftr 0 (Nat.succ n)) = \u21910) (congr_arg coe (nat.zero_shiftr (Nat.succ n)))\n\n@[simp] theorem zero_shiftr (n : \u2124) : shiftr 0 n = 0 :=\n  zero_shiftl (-n)\n\n/-! ### Least upper bound property for integers -/\n\ntheorem exists_least_of_bdd {P : \u2124 \u2192 Prop} (Hbdd : \u2203 (b : \u2124), \u2200 (z : \u2124), P z \u2192 b \u2264 z) (Hinh : \u2203 (z : \u2124), P z) : \u2203 (lb : \u2124), P lb \u2227 \u2200 (z : \u2124), P z \u2192 lb \u2264 z := sorry\n\ntheorem exists_greatest_of_bdd {P : \u2124 \u2192 Prop} (Hbdd : \u2203 (b : \u2124), \u2200 (z : \u2124), P z \u2192 z \u2264 b) (Hinh : \u2203 (z : \u2124), P z) : \u2203 (ub : \u2124), P ub \u2227 \u2200 (z : \u2124), P z \u2192 z \u2264 ub := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/int/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7068061923623702}}
{"text": "-- ignore this part: we are building the notion of a set\n-- go to line 36\n\ninductive zfc : Type\n| empty  : zfc\n| insert : zfc \u2192 zfc \u2192 zfc\n\ninstance : has_emptyc zfc := \u27e8zfc.empty\u27e9\ninstance : has_insert zfc zfc := \u27e8zfc.insert\u27e9\n\ninstance : has_zero zfc := \u27e8{}\u27e9\ninstance : has_one zfc := \u27e8{0}\u27e9\n\ndef succ (a : zfc) : zfc := has_insert.insert a a\n\ndef zfc_add : zfc \u2192 zfc \u2192 zfc\n| m 0 := m\n| m (zfc.insert n p) := succ (zfc_add m n)\n\ninstance : has_add zfc := \u27e8zfc_add\u27e9\n\ninductive member : zfc \u2192 zfc \u2192 Prop\n| left {a b c : zfc} : member a c \u2192 member a (has_insert.insert b c)\n| right {a b : zfc} : member a (has_insert.insert a b)\n\ninstance : has_mem zfc zfc := \u27e8member\u27e9\ninstance : has_subset zfc := \u27e8(\u03bb a b:zfc, (\u2200 z:zfc, z \u2208 a \u2192 z \u2208 b))\u27e9\ninfix `\u2288`:50 := (\u03bb a b, \u00ac(a \u2286 b))\ninfix `\u2289`:50 := (\u03bb a b, \u00ac(b \u2286 a))\n\naxiom member.ext (a b : zfc) : (\u2200 x, x \u2208 a \u2194 x \u2208 b) \u2194 a=b\n\nexport zfc\nexport member\n\n-- start here\n\n/-\n\nUSAGE:\n1. \u00acP is shorthand of (P \u2192 false).\n2. A \u2209 B is shorthand of \u00ac(A \u2208 B), which is shorthand of (A \u2208 B \u2192 false) per 1.\n3. A \u2286 B is shorthand of (\u2200 z, z \u2208 A \u2192 z \u2208 B).\n4. A \u2288 B is shorthand of \u00ac(A \u2286 B), and then use 1 and 3.\n5. If the current goal is x \u2208 {a,b,c,d,e}, then using \"left\" or \"apply left\"\n   will make the goal x \u2208 {a,b,c,d}.\n6. If the current goal is x \u2208 {a,b,c,d,x}, then using \"right\" or \"apply right\"\n   or \"exact right\" will prove the goal.\n7. If one wishes to disprove (i.e. derive false from) one of the current hypotheses\n   of the form h : x \u2208 {a,b,c,d,e}, using \"cases h\" will replace the current hypothesis\n   with a_1 : x \u2208 {a,b,c,d}, provided that x and e are not equal. When the set is empty,\n   \"cases h\" will directly prove false.\n\nHINT: To prove a statement of the form \"P \u2192 P\", use \"exact id\". \n\nRECAP:\n1. To prove a statement of the form \"\u2200 z, P z\", type \"intro x\" and then prove \"P x\".\n2. To prove a statement of the form \"P \u2192 Q\", type \"intro HP\" and then prove \"Q\".\n3. If the current goal is P \u2228 Q, using \"left\" will reduce the goal to P.\n\nNOTE:\nSomehow the goal will become messy. I tried to fix it but it just wouldn't work.\nTry to work with simple cases where the goal still works, and then trust in the\nforce when it doesn't.\n\n-/\n\ndefinition A : zfc := {1,2,{1,2}}\ndefinition B : zfc := {1,2,A}\n\n-- prove one and delete the other for each part.\n\ntheorem M1F_Sheet01_Q06a_is_true : (1:zfc) \u2208 A := sorry\ntheorem M1F_Sheet01_Q06a_is_false : (1:zfc) \u2208 A := sorry\n\ntheorem M1F_Sheet01_Q06b_is_true: ({1}:zfc) \u2208 A := sorry\ntheorem M1F_Sheet01_Q06b_is_false: ({1}:zfc) \u2209 A := sorry\n\ntheorem M1F_Sheet01_Q06c_is_true: ({1,2}:zfc) \u2208 A := sorry\ntheorem M1F_Sheet01_Q06c_is_false: ({1,2}:zfc) \u2209 A := sorry\n\n-- goal generator becomes messy for (d)\n\ntheorem M1F_Sheet01_Q06d_is_true: ({1,2}:zfc) \u2286 A := sorry\ntheorem M1F_Sheet01_Q06d_is_false: ({1,2}:zfc) \u2286 A := sorry\n\ntheorem M1F_Sheet01_Q06e_is_true: (1:zfc) \u2208 B := sorry\ntheorem M1F_Sheet01_Q06e_is_false: (1:zfc) \u2209 B := sorry\n\ntheorem M1F_Sheet01_Q06f_is_true: ({1}:zfc) \u2208 B := sorry\ntheorem M1F_Sheet01_Q06f_is_false: ({1}:zfc) \u2209 B := sorry\n\ntheorem M1F_Sheet01_Q06g_is_true: ({1,2}:zfc) \u2208 B \u2192 (1:zfc) \u2208 A := sorry\ntheorem M1F_Sheet01_Q06g_is_false: \u00ac(({1,2}:zfc) \u2208 B \u2192 (1:zfc) \u2208 A) := sorry\n\n-- goal generator becomes messy for (h)\n\ntheorem M1F_Sheet01_Q06h_is_true: ({1,2}:zfc) \u2286 B \u2228 (1:zfc) \u2209 A := sorry\ntheorem M1F_Sheet01_Q06h_is_false: \u00ac(({1,2}:zfc) \u2286 B \u2228 (1:zfc) \u2209 A) := sorry", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1F/problem_bank/0106/Q0106.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7068061897002419}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport analysis.normed_space.star.basic\nimport algebra.star.module\nimport analysis.special_functions.exponential\n\n/-! # The exponential map from selfadjoint to unitary\nIn this file, we establish various propreties related to the map `\u03bb a, exp \u2102 A (I \u2022 a)` between the\nsubtypes `self_adjoint A` and `unitary A`.\n\n## TODO\n\n* Show that any exponential unitary is path-connected in `unitary A` to `1 : unitary A`.\n* Prove any unitary whose distance to `1 : unitary A` is less than `1` can be expressed as an\n  exponential unitary.\n* A unitary is in the path component of `1` if and only if it is a finite product of exponential\n  unitaries.\n-/\n\nsection star\n\nvariables {A : Type*}\n[normed_ring A] [normed_algebra \u2102 A] [star_ring A] [cstar_ring A] [complete_space A]\n[star_module \u2102 A]\n\nopen complex\n\nlemma self_adjoint.exp_i_smul_unitary {a : A} (ha : a \u2208 self_adjoint A) :\n  exp \u2102 A (I \u2022 a) \u2208 unitary A :=\nbegin\n  rw [unitary.mem_iff, star_exp],\n  simp only [star_smul, is_R_or_C.star_def, self_adjoint.mem_iff.mp ha, conj_I, neg_smul],\n  rw \u2190@exp_add_of_commute \u2102 A _ _ _ _ _ _ ((commute.refl (I \u2022 a)).neg_left),\n  rw \u2190@exp_add_of_commute \u2102 A _ _ _ _ _ _ ((commute.refl (I \u2022 a)).neg_right),\n  simpa only [add_right_neg, add_left_neg, and_self] using (exp_zero : exp \u2102 A 0 = 1),\nend\n\n/-- The map from the selfadjoint real subspace to the unitary group. This map only makes sense\nover \u2102. -/\n@[simps]\nnoncomputable def self_adjoint.exp_unitary (a : self_adjoint A) : unitary A :=\n\u27e8exp \u2102 A (I \u2022 a), self_adjoint.exp_i_smul_unitary (a.property)\u27e9\n\nopen self_adjoint\n\nlemma commute.exp_unitary_add {a b : self_adjoint A} (h : commute (a : A) (b : A)) :\n  exp_unitary (a + b) = exp_unitary a * exp_unitary b :=\nbegin\n  ext,\n  have hcomm : commute (I \u2022 (a : A)) (I \u2022 (b : A)),\n  calc _ = _ : by simp only [h.eq, algebra.smul_mul_assoc, algebra.mul_smul_comm],\n  simpa only [exp_unitary_coe, add_subgroup.coe_add, smul_add] using exp_add_of_commute hcomm,\nend\n\nlemma commute.exp_unitary {a b : self_adjoint A} (h : commute (a : A) (b : A)) :\n  commute (exp_unitary a) (exp_unitary b) :=\ncalc (exp_unitary a) * (exp_unitary b) = (exp_unitary b) * (exp_unitary a)\n  : by rw [\u2190h.exp_unitary_add, \u2190h.symm.exp_unitary_add, add_comm]\n\nend star\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/normed_space/star/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7067709929086345}}
{"text": "/-\nCopyright (c) 2020 Jalex Stark. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jalex Stark, Scott Morrison, Eric Wieser, Oliver Nash\n-/\nimport data.matrix.basic\nimport linear_algebra.matrix.trace\n\n/-!\n# Matrices with a single non-zero element.\n\nThis file provides `matrix.std_basis_matrix`. The matrix `matrix.std_basis_matrix i j c` has `c`\nat position `(i, j)`, and zeroes elsewhere.\n-/\n\nvariables {l m n : Type*}\nvariables {R \u03b1 : Type*}\n\nnamespace matrix\nopen_locale matrix\nopen_locale big_operators\n\nvariables [decidable_eq l] [decidable_eq m] [decidable_eq n]\n\nvariables [semiring \u03b1]\n\n/--\n`std_basis_matrix i j a` is the matrix with `a` in the `i`-th row, `j`-th column,\nand zeroes elsewhere.\n-/\ndef std_basis_matrix (i : m) (j : n) (a : \u03b1) : matrix m n \u03b1 :=\n(\u03bb i' j', if i = i' \u2227 j = j' then a else 0)\n\n@[simp] lemma smul_std_basis_matrix (i : m) (j : n) (a b : \u03b1) :\nb \u2022 std_basis_matrix i j a = std_basis_matrix i j (b \u2022 a) :=\nby { unfold std_basis_matrix, ext, simp }\n\n@[simp] lemma std_basis_matrix_zero (i : m) (j : n) :\nstd_basis_matrix i j (0 : \u03b1) = 0 :=\nby { unfold std_basis_matrix, ext, simp }\n\nlemma std_basis_matrix_add (i : m) (j : n) (a b : \u03b1) :\nstd_basis_matrix i j (a + b) = std_basis_matrix i j a + std_basis_matrix i j b :=\nbegin\n  unfold std_basis_matrix, ext,\n  split_ifs with h; simp [h],\nend\n\nlemma matrix_eq_sum_std_basis (x : matrix n m \u03b1) [fintype n] [fintype m] :\n  x = \u2211 (i : n) (j : m), std_basis_matrix i j (x i j) :=\nbegin\n  ext, symmetry,\n  iterate 2 { rw finset.sum_apply },\n  convert fintype.sum_eq_single i _,\n  { simp [std_basis_matrix] },\n  { intros j hj,\n    simp [std_basis_matrix, hj], }\nend\n\n-- TODO: tie this up with the `basis` machinery of linear algebra\n-- this is not completely trivial because we are indexing by two types, instead of one\n\n-- TODO: add `std_basis_vec`\nlemma std_basis_eq_basis_mul_basis (i : m) (j : n) :\nstd_basis_matrix i j 1 = vec_mul_vec (\u03bb i', ite (i = i') 1 0) (\u03bb j', ite (j = j') 1 0) :=\nbegin\n  ext,\n  norm_num [std_basis_matrix, vec_mul_vec],\n  exact ite_and _ _ _ _,\nend\n\n-- todo: the old proof used fintypes, I don't know `finsupp` but this feels generalizable\n@[elab_as_eliminator] protected lemma induction_on' [fintype m] [fintype n]\n  {P : matrix m n \u03b1 \u2192 Prop} (M : matrix m n \u03b1)\n  (h_zero : P 0)\n  (h_add : \u2200 p q, P p \u2192 P q \u2192 P (p + q))\n  (h_std_basis : \u2200 (i : m) (j : n) (x : \u03b1), P (std_basis_matrix i j x)) :\n  P M :=\nbegin\n  rw [matrix_eq_sum_std_basis M, \u2190 finset.sum_product'],\n  apply finset.sum_induction _ _ h_add h_zero,\n  { intros, apply h_std_basis, }\nend\n\n@[elab_as_eliminator] protected lemma induction_on [fintype m] [fintype n]\n  [nonempty m] [nonempty n] {P : matrix m n \u03b1 \u2192 Prop} (M : matrix m n \u03b1)\n  (h_add : \u2200 p q, P p \u2192 P q \u2192 P (p + q))\n  (h_std_basis : \u2200 i j x, P (std_basis_matrix i j x)) :\n  P M :=\nmatrix.induction_on' M\nbegin\n  inhabit m,\n  inhabit n,\n  simpa using h_std_basis default default 0\nend\nh_add h_std_basis\n\nnamespace std_basis_matrix\n\nsection\n\nvariables (i : m) (j : n) (c : \u03b1) (i' : m) (j' : n)\n\n@[simp] lemma apply_same : std_basis_matrix i j c i j = c := if_pos (and.intro rfl rfl)\n\n@[simp] lemma apply_of_ne (h : \u00ac((i = i') \u2227 (j = j'))) :\n  std_basis_matrix i j c i' j' = 0 :=\nby { simp only [std_basis_matrix, and_imp, ite_eq_right_iff], tauto }\n\n@[simp] lemma apply_of_row_ne {i i' : m} (hi : i \u2260 i') (j j' : n) (a : \u03b1) :\n  std_basis_matrix i j a i' j' = 0 :=\nby simp [hi]\n\n@[simp] lemma apply_of_col_ne (i i' : m) {j j' : n} (hj : j \u2260 j') (a : \u03b1) :\n  std_basis_matrix i j a i' j' = 0 :=\nby simp [hj]\n\nend\n\nsection\n\nvariables (i j : n) (c : \u03b1) (i' j' : n)\n\n@[simp] lemma diag_zero (h : j \u2260 i) : diag n \u03b1 \u03b1 (std_basis_matrix i j c) = 0 :=\nfunext $ \u03bb k, if_neg $ \u03bb \u27e8e\u2081, e\u2082\u27e9, h (e\u2082.trans e\u2081.symm)\n\nvariable [fintype n]\n\nlemma trace_zero (h : j \u2260 i) : trace n \u03b1 \u03b1 (std_basis_matrix i j c) = 0 := by simp [h]\n\n@[simp] lemma mul_left_apply_same (b : n) (M : matrix n n \u03b1) :\n  (std_basis_matrix i j c \u2b1d M) i b = c * M j b :=\nby simp [mul_apply, std_basis_matrix]\n\n@[simp] lemma mul_right_apply_same (a : n) (M : matrix n n \u03b1) :\n  (M \u2b1d std_basis_matrix i j c) a j = M a i * c :=\nby simp [mul_apply, std_basis_matrix, mul_comm]\n\n@[simp] lemma mul_left_apply_of_ne (a b : n) (h : a \u2260 i) (M : matrix n n \u03b1) :\n  (std_basis_matrix i j c \u2b1d M) a b = 0 :=\nby simp [mul_apply, h.symm]\n\n@[simp] lemma mul_right_apply_of_ne (a b : n) (hbj : b \u2260 j) (M : matrix n n \u03b1) :\n  (M \u2b1d std_basis_matrix i j c) a b = 0 :=\nby simp [mul_apply, hbj.symm]\n\n@[simp] lemma mul_same (k : n) (d : \u03b1) :\n  std_basis_matrix i j c \u2b1d std_basis_matrix j k d = std_basis_matrix i k (c * d) :=\nbegin\n  ext a b,\n  simp only [mul_apply, std_basis_matrix, boole_mul],\n  by_cases h\u2081 : i = a; by_cases h\u2082 : k = b;\n  simp [h\u2081, h\u2082],\nend\n\n@[simp] lemma mul_of_ne {k l : n} (h : j \u2260 k) (d : \u03b1) :\n  std_basis_matrix i j c \u2b1d std_basis_matrix k l d = 0 :=\nbegin\n  ext a b,\n  simp only [mul_apply, boole_mul, std_basis_matrix],\n  by_cases h\u2081 : i = a;\n  simp [h\u2081, h, h.symm],\nend\n\nend\n\nend std_basis_matrix\n\nend matrix\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/matrix/basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924954, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7067709901042563}}
{"text": "/-\nCopyright (c) 2018 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport algebra.big_operators.ring\nimport data.real.basic\nimport algebra.indicator_function\nimport algebra.algebra.basic\nimport algebra.order.nonneg\n\n/-!\n# Nonnegative real numbers\n\nIn this file we define `nnreal` (notation: `\u211d\u22650`) to be the type of non-negative real numbers,\na.k.a. the interval `[0, \u221e)`. We also define the following operations and structures on `\u211d\u22650`:\n\n* the order on `\u211d\u22650` is the restriction of the order on `\u211d`; these relations define a conditionally\n  complete linear order with a bottom element, `conditionally_complete_linear_order_bot`;\n\n* `a + b` and `a * b` are the restrictions of addition and multiplication of real numbers to `\u211d\u22650`;\n  these operations together with `0 = \u27e80, _\u27e9` and `1 = \u27e81, _\u27e9` turn `\u211d\u22650` into a conditionally\n  complete linear ordered archimedean commutative semifield; we have no typeclass for this in\n  `mathlib` yet, so we define the following instances instead:\n\n  - `linear_ordered_semiring \u211d\u22650`;\n  - `ordered_comm_semiring \u211d\u22650`;\n  - `canonically_ordered_comm_semiring \u211d\u22650`;\n  - `linear_ordered_comm_group_with_zero \u211d\u22650`;\n  - `canonically_linear_ordered_add_monoid \u211d\u22650`;\n  - `archimedean \u211d\u22650`;\n  - `conditionally_complete_linear_order_bot \u211d\u22650`.\n\n  These instances are derived from corresponding instances about the type `{x : \u03b1 // 0 \u2264 x}` in an\n  appropriate ordered field/ring/group/monoid `\u03b1`. See `algebra/order/nonneg`.\n\n* `real.to_nnreal x` is defined as `\u27e8max x 0, _\u27e9`, i.e. `\u2191(real.to_nnreal x) = x` when `0 \u2264 x` and\n  `\u2191(real.to_nnreal x) = 0` otherwise.\n\nWe also define an instance `can_lift \u211d \u211d\u22650`. This instance can be used by the `lift` tactic to\nreplace `x : \u211d` and `hx : 0 \u2264 x` in the proof context with `x : \u211d\u22650` while replacing all occurences\nof `x` with `\u2191x`. This tactic also works for a function `f : \u03b1 \u2192 \u211d` with a hypothesis\n`hf : \u2200 x, 0 \u2264 f x`.\n\n## Notations\n\nThis file defines `\u211d\u22650` as a localized notation for `nnreal`.\n-/\n\nopen_locale classical big_operators\n\n/-- Nonnegative real numbers. -/\n@[derive [\n  ordered_semiring, comm_monoid_with_zero, -- to ensure these instance are computable\n  semilattice_inf, densely_ordered, order_bot,\n  canonically_linear_ordered_add_monoid, linear_ordered_comm_group_with_zero, archimedean,\n  linear_ordered_semiring, ordered_comm_semiring, canonically_ordered_comm_semiring,\n  has_sub, has_ordered_sub, has_div, inhabited]]\ndef nnreal := {r : \u211d // 0 \u2264 r}\nlocalized \"notation ` \u211d\u22650 ` := nnreal\" in nnreal\n\nnamespace nnreal\n\ninstance : has_coe \u211d\u22650 \u211d := \u27e8subtype.val\u27e9\n\n/- Simp lemma to put back `n.val` into the normal form given by the coercion. -/\n@[simp] lemma val_eq_coe (n : \u211d\u22650) : n.val = n := rfl\n\ninstance : can_lift \u211d \u211d\u22650 :=\n{ coe := coe,\n  cond := \u03bb r, 0 \u2264 r,\n  prf := \u03bb x hx, \u27e8\u27e8x, hx\u27e9, rfl\u27e9 }\n\nprotected lemma eq {n m : \u211d\u22650} : (n : \u211d) = (m : \u211d) \u2192 n = m := subtype.eq\n\nprotected lemma eq_iff {n m : \u211d\u22650} : (n : \u211d) = (m : \u211d) \u2194 n = m :=\niff.intro nnreal.eq (congr_arg coe)\n\nlemma ne_iff {x y : \u211d\u22650} : (x : \u211d) \u2260 (y : \u211d) \u2194 x \u2260 y :=\nnot_iff_not_of_iff $ nnreal.eq_iff\n\n/-- Reinterpret a real number `r` as a non-negative real number. Returns `0` if `r < 0`. -/\nnoncomputable def _root_.real.to_nnreal (r : \u211d) : \u211d\u22650 := \u27e8max r 0, le_max_right _ _\u27e9\n\nlemma _root_.real.coe_to_nnreal (r : \u211d) (hr : 0 \u2264 r) : (real.to_nnreal r : \u211d) = r :=\nmax_eq_left hr\n\nlemma _root_.real.le_coe_to_nnreal (r : \u211d) : r \u2264 real.to_nnreal r :=\nle_max_left r 0\n\nlemma coe_nonneg (r : \u211d\u22650) : (0 : \u211d) \u2264 r := r.2\n@[norm_cast]\ntheorem coe_mk (a : \u211d) (ha) : ((\u27e8a, ha\u27e9 : \u211d\u22650) : \u211d) = a := rfl\n\nexample : has_zero \u211d\u22650  := by apply_instance\nexample : has_one \u211d\u22650   := by apply_instance\nexample : has_add \u211d\u22650   := by apply_instance\nnoncomputable example : has_sub \u211d\u22650   := by apply_instance\nexample : has_mul \u211d\u22650   := by apply_instance\nnoncomputable example : has_inv \u211d\u22650   := by apply_instance\nnoncomputable example : has_div \u211d\u22650   := by apply_instance\nnoncomputable example : has_le \u211d\u22650    := by apply_instance\nexample : has_bot \u211d\u22650   := by apply_instance\nexample : inhabited \u211d\u22650 := by apply_instance\nexample : nontrivial \u211d\u22650 := by apply_instance\n\nprotected lemma coe_injective : function.injective (coe : \u211d\u22650 \u2192 \u211d) := subtype.coe_injective\n@[simp, norm_cast] protected lemma coe_eq {r\u2081 r\u2082 : \u211d\u22650} : (r\u2081 : \u211d) = r\u2082 \u2194 r\u2081 = r\u2082 :=\nnnreal.coe_injective.eq_iff\nprotected lemma coe_zero : ((0 : \u211d\u22650) : \u211d) = 0 := rfl\nprotected lemma coe_one  : ((1 : \u211d\u22650) : \u211d) = 1 := rfl\nprotected lemma coe_add (r\u2081 r\u2082 : \u211d\u22650) : ((r\u2081 + r\u2082 : \u211d\u22650) : \u211d) = r\u2081 + r\u2082 := rfl\nprotected lemma coe_mul (r\u2081 r\u2082 : \u211d\u22650) : ((r\u2081 * r\u2082 : \u211d\u22650) : \u211d) = r\u2081 * r\u2082 := rfl\nprotected lemma coe_inv (r : \u211d\u22650) : ((r\u207b\u00b9 : \u211d\u22650) : \u211d) = r\u207b\u00b9 := rfl\nprotected lemma coe_div (r\u2081 r\u2082 : \u211d\u22650) : ((r\u2081 / r\u2082 : \u211d\u22650) : \u211d) = r\u2081 / r\u2082 := rfl\n@[simp, norm_cast] protected \n\n@[simp, norm_cast] protected lemma coe_sub {r\u2081 r\u2082 : \u211d\u22650} (h : r\u2082 \u2264 r\u2081) :\n  ((r\u2081 - r\u2082 : \u211d\u22650) : \u211d) = r\u2081 - r\u2082 :=\nmax_eq_left $ le_sub.2 $ by simp [show (r\u2082 : \u211d) \u2264 r\u2081, from h]\n\n-- TODO: setup semifield!\n@[simp, norm_cast] protected lemma coe_eq_zero (r : \u211d\u22650) : \u2191r = (0 : \u211d) \u2194 r = 0 :=\nby rw [\u2190 nnreal.coe_zero, nnreal.coe_eq]\n\n@[simp, norm_cast] protected lemma coe_eq_one (r : \u211d\u22650) : \u2191r = (1 : \u211d) \u2194 r = 1 :=\nby rw [\u2190 nnreal.coe_one, nnreal.coe_eq]\n\nlemma coe_ne_zero {r : \u211d\u22650} : (r : \u211d) \u2260 0 \u2194 r \u2260 0 := by norm_cast\n\nexample : comm_semiring \u211d\u22650 := by apply_instance\n\n/-- Coercion `\u211d\u22650 \u2192 \u211d` as a `ring_hom`. -/\ndef to_real_hom : \u211d\u22650 \u2192+* \u211d :=\n\u27e8coe, nnreal.coe_one, nnreal.coe_mul, nnreal.coe_zero, nnreal.coe_add\u27e9\n\n@[simp] lemma coe_to_real_hom : \u21d1to_real_hom = coe := rfl\n\nsection actions\n\n/-- A `mul_action` over `\u211d` restricts to a `mul_action` over `\u211d\u22650`. -/\ninstance {M : Type*} [mul_action \u211d M] : mul_action \u211d\u22650 M :=\nmul_action.comp_hom M to_real_hom.to_monoid_hom\n\nlemma smul_def {M : Type*} [mul_action \u211d M] (c : \u211d\u22650) (x : M) :\n  c \u2022 x = (c : \u211d) \u2022 x := rfl\n\ninstance {M N : Type*} [mul_action \u211d M] [mul_action \u211d N] [has_scalar M N]\n  [is_scalar_tower \u211d M N] : is_scalar_tower \u211d\u22650 M N :=\n{ smul_assoc := \u03bb r, (smul_assoc (r : \u211d) : _)}\n\ninstance smul_comm_class_left {M N : Type*} [mul_action \u211d N] [has_scalar M N]\n  [smul_comm_class \u211d M N] : smul_comm_class \u211d\u22650 M N :=\n{ smul_comm := \u03bb r, (smul_comm (r : \u211d) : _)}\n\ninstance smul_comm_class_right {M N : Type*} [mul_action \u211d N] [has_scalar M N]\n  [smul_comm_class M \u211d N] : smul_comm_class M \u211d\u22650 N :=\n{ smul_comm := \u03bb m r, (smul_comm m (r : \u211d) : _)}\n\n/-- A `distrib_mul_action` over `\u211d` restricts to a `distrib_mul_action` over `\u211d\u22650`. -/\ninstance {M : Type*} [add_monoid M] [distrib_mul_action \u211d M] : distrib_mul_action \u211d\u22650 M :=\ndistrib_mul_action.comp_hom M to_real_hom.to_monoid_hom\n\n/-- A `module` over `\u211d` restricts to a `module` over `\u211d\u22650`. -/\ninstance {M : Type*} [add_comm_monoid M] [module \u211d M] : module \u211d\u22650 M :=\nmodule.comp_hom M to_real_hom\n\n/-- An `algebra` over `\u211d` restricts to an `algebra` over `\u211d\u22650`. -/\ninstance {A : Type*} [semiring A] [algebra \u211d A] : algebra \u211d\u22650 A :=\n{ smul := (\u2022),\n  commutes' := \u03bb r x, by simp [algebra.commutes],\n  smul_def' := \u03bb r x, by simp [\u2190algebra.smul_def (r : \u211d) x, smul_def],\n  to_ring_hom := ((algebra_map \u211d A).comp (to_real_hom : \u211d\u22650 \u2192+* \u211d)) }\n\n-- verify that the above produces instances we might care about\nexample : algebra \u211d\u22650 \u211d := by apply_instance\nexample : distrib_mul_action (units \u211d\u22650) \u211d := by apply_instance\n\nend actions\n\nexample : monoid_with_zero \u211d\u22650 := by apply_instance\nexample : comm_monoid_with_zero \u211d\u22650 := by apply_instance\nnoncomputable example : comm_group_with_zero \u211d\u22650 := by apply_instance\n\n@[simp, norm_cast] lemma coe_indicator {\u03b1} (s : set \u03b1) (f : \u03b1 \u2192 \u211d\u22650) (a : \u03b1) :\n  ((s.indicator f a : \u211d\u22650) : \u211d) = s.indicator (\u03bb x, f x) a :=\n(to_real_hom : \u211d\u22650 \u2192+ \u211d).map_indicator _ _ _\n\n@[simp, norm_cast] lemma coe_pow (r : \u211d\u22650) (n : \u2115) : ((r^n : \u211d\u22650) : \u211d) = r^n :=\nto_real_hom.map_pow r n\n\n@[simp, norm_cast] lemma coe_zpow (r : \u211d\u22650) (n : \u2124) : ((r^n : \u211d\u22650) : \u211d) = r^n :=\nby cases n; simp\n\n@[norm_cast] lemma coe_list_sum (l : list \u211d\u22650) :\n  ((l.sum : \u211d\u22650) : \u211d) = (l.map coe).sum :=\nto_real_hom.map_list_sum l\n\n@[norm_cast] lemma coe_list_prod (l : list \u211d\u22650) :\n  ((l.prod : \u211d\u22650) : \u211d) = (l.map coe).prod :=\nto_real_hom.map_list_prod l\n\n@[norm_cast] lemma coe_multiset_sum (s : multiset \u211d\u22650) :\n  ((s.sum : \u211d\u22650) : \u211d) = (s.map coe).sum :=\nto_real_hom.map_multiset_sum s\n\n@[norm_cast] lemma coe_multiset_prod (s : multiset \u211d\u22650) :\n  ((s.prod : \u211d\u22650) : \u211d) = (s.map coe).prod :=\nto_real_hom.map_multiset_prod s\n\n@[norm_cast] lemma coe_sum {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d\u22650} :\n  \u2191(\u2211 a in s, f a) = \u2211 a in s, (f a : \u211d) :=\nto_real_hom.map_sum _ _\n\nlemma _root_.real.to_nnreal_sum_of_nonneg {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d}\n  (hf : \u2200 a, a \u2208 s \u2192 0 \u2264 f a) :\n  real.to_nnreal (\u2211 a in s, f a) = \u2211 a in s, real.to_nnreal (f a) :=\nbegin\n  rw [\u2190nnreal.coe_eq, nnreal.coe_sum, real.coe_to_nnreal _ (finset.sum_nonneg hf)],\n  exact finset.sum_congr rfl (\u03bb x hxs, by rw real.coe_to_nnreal _ (hf x hxs)),\nend\n\n@[norm_cast] lemma coe_prod {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d\u22650} :\n  \u2191(\u220f a in s, f a) = \u220f a in s, (f a : \u211d) :=\nto_real_hom.map_prod _ _\n\nlemma _root_.real.to_nnreal_prod_of_nonneg {\u03b1} {s : finset \u03b1} {f : \u03b1 \u2192 \u211d}\n  (hf : \u2200 a, a \u2208 s \u2192 0 \u2264 f a) :\n  real.to_nnreal (\u220f a in s, f a) = \u220f a in s, real.to_nnreal (f a) :=\nbegin\n  rw [\u2190nnreal.coe_eq, nnreal.coe_prod, real.coe_to_nnreal _ (finset.prod_nonneg hf)],\n  exact finset.prod_congr rfl (\u03bb x hxs, by rw real.coe_to_nnreal _ (hf x hxs)),\nend\n\nlemma nsmul_coe (r : \u211d\u22650) (n : \u2115) : \u2191(n \u2022 r) = n \u2022 (r:\u211d) :=\nby norm_cast\n\n@[simp, norm_cast] protected lemma coe_nat_cast (n : \u2115) : (\u2191(\u2191n : \u211d\u22650) : \u211d) = n :=\nto_real_hom.map_nat_cast n\n\nnoncomputable example : linear_order \u211d\u22650 := by apply_instance\n\n@[simp, norm_cast] protected lemma coe_le_coe {r\u2081 r\u2082 : \u211d\u22650} : (r\u2081 : \u211d) \u2264 r\u2082 \u2194 r\u2081 \u2264 r\u2082 := iff.rfl\n@[simp, norm_cast] protected lemma coe_lt_coe {r\u2081 r\u2082 : \u211d\u22650} : (r\u2081 : \u211d) < r\u2082 \u2194 r\u2081 < r\u2082 := iff.rfl\n@[simp, norm_cast] protected lemma coe_pos {r : \u211d\u22650} : (0 : \u211d) < r \u2194 0 < r := iff.rfl\n\nprotected lemma coe_mono : monotone (coe : \u211d\u22650 \u2192 \u211d) := \u03bb _ _, nnreal.coe_le_coe.2\n\nprotected lemma _root_.real.to_nnreal_mono : monotone real.to_nnreal :=\n\u03bb x y h, max_le_max h (le_refl 0)\n\n@[simp] lemma _root_.real.to_nnreal_coe {r : \u211d\u22650} : real.to_nnreal r = r :=\nnnreal.eq $ max_eq_left r.2\n\n@[simp] lemma mk_coe_nat (n : \u2115) : @eq \u211d\u22650 (\u27e8(n : \u211d), n.cast_nonneg\u27e9 : \u211d\u22650) n :=\nnnreal.eq (nnreal.coe_nat_cast n).symm\n\n@[simp] lemma to_nnreal_coe_nat (n : \u2115) : real.to_nnreal n = n :=\nnnreal.eq $ by simp [real.coe_to_nnreal]\n\n/-- `real.to_nnreal` and `coe : \u211d\u22650 \u2192 \u211d` form a Galois insertion. -/\nnoncomputable def gi : galois_insertion real.to_nnreal coe :=\ngalois_insertion.monotone_intro nnreal.coe_mono real.to_nnreal_mono\n  real.le_coe_to_nnreal (\u03bb _, real.to_nnreal_coe)\n\n-- note that anything involving the (decidability of the) linear order, including `\u2294`/`\u2293` (min, max)\n-- will be noncomputable, everything else should not be.\nexample : order_bot \u211d\u22650 := by apply_instance\nexample : partial_order \u211d\u22650 := by apply_instance\nnoncomputable example : canonically_linear_ordered_add_monoid \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_add_comm_monoid \u211d\u22650 := by apply_instance\nnoncomputable example : distrib_lattice \u211d\u22650 := by apply_instance\nnoncomputable example : semilattice_inf \u211d\u22650 := by apply_instance\nnoncomputable example : semilattice_sup \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_semiring \u211d\u22650 := by apply_instance\nexample : ordered_comm_semiring \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_comm_monoid  \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_comm_monoid_with_zero \u211d\u22650 := by apply_instance\nnoncomputable example : linear_ordered_comm_group_with_zero \u211d\u22650 := by apply_instance\nexample : canonically_ordered_comm_semiring \u211d\u22650 := by apply_instance\nexample : densely_ordered \u211d\u22650 := by apply_instance\nexample : no_top_order \u211d\u22650 := by apply_instance\n\nlemma bdd_above_coe {s : set \u211d\u22650} : bdd_above ((coe : \u211d\u22650 \u2192 \u211d) '' s) \u2194 bdd_above s :=\niff.intro\n  (assume \u27e8b, hb\u27e9, \u27e8real.to_nnreal b, assume \u27e8y, hy\u27e9 hys, show y \u2264 max b 0, from\n    le_max_of_le_left $ hb $ set.mem_image_of_mem _ hys\u27e9)\n  (assume \u27e8b, hb\u27e9, \u27e8b, assume y \u27e8x, hx, eq\u27e9, eq \u25b8 hb hx\u27e9)\n\nlemma bdd_below_coe (s : set \u211d\u22650) : bdd_below ((coe : \u211d\u22650 \u2192 \u211d) '' s) :=\n\u27e80, assume r \u27e8q, _, eq\u27e9, eq \u25b8 q.2\u27e9\n\nnoncomputable instance : conditionally_complete_linear_order_bot \u211d\u22650 :=\nnonneg.conditionally_complete_linear_order_bot real.Sup_empty.le\n\nlemma coe_Sup (s : set \u211d\u22650) : (\u2191(Sup s) : \u211d) = Sup ((coe : \u211d\u22650 \u2192 \u211d) '' s) :=\neq.symm $ @subset_Sup_of_within \u211d (set.Ici 0) _ \u27e8(0 : \u211d\u22650)\u27e9 s $\n  real.Sup_nonneg _ $ \u03bb y \u27e8x, _, hy\u27e9, hy \u25b8 x.2\n\nlemma coe_Inf (s : set \u211d\u22650) : (\u2191(Inf s) : \u211d) = Inf ((coe : \u211d\u22650 \u2192 \u211d) '' s) :=\neq.symm $ @subset_Inf_of_within \u211d (set.Ici 0) _ \u27e8(0 : \u211d\u22650)\u27e9 s $\n  real.Inf_nonneg _ $ \u03bb y \u27e8x, _, hy\u27e9, hy \u25b8 x.2\n\nexample : archimedean \u211d\u22650 := by apply_instance\n\n-- TODO: why are these three instances necessary? why aren't they inferred?\ninstance covariant_add : covariant_class \u211d\u22650 \u211d\u22650 (+) (\u2264) :=\nordered_add_comm_monoid.to_covariant_class_left \u211d\u22650\n\ninstance contravariant_add : contravariant_class \u211d\u22650 \u211d\u22650 (+) (<) :=\nordered_cancel_add_comm_monoid.to_contravariant_class_left \u211d\u22650\n\ninstance covariant_mul : covariant_class \u211d\u22650 \u211d\u22650 (*) (\u2264) :=\nordered_comm_monoid.to_covariant_class_left \u211d\u22650\n\nlemma le_of_forall_pos_le_add {a b : \u211d\u22650} (h : \u2200\u03b5, 0 < \u03b5 \u2192 a \u2264 b + \u03b5) : a \u2264 b :=\nle_of_forall_le_of_dense $ assume x hxb,\nbegin\n  rcases le_iff_exists_add.1 (le_of_lt hxb) with \u27e8\u03b5, rfl\u27e9,\n  exact h _ ((lt_add_iff_pos_right b).1 hxb)\nend\n\n-- TODO: generalize to some ordered add_monoids, based on #6145\nlemma le_of_add_le_left {a b c : \u211d\u22650} (h : a + b \u2264 c) : a \u2264 c :=\nby { refine le_trans _ h, exact (le_add_iff_nonneg_right _).mpr zero_le' }\n\nlemma le_of_add_le_right {a b c : \u211d\u22650} (h : a + b \u2264 c) : b \u2264 c :=\nby { refine le_trans _ h, exact (le_add_iff_nonneg_left _).mpr zero_le' }\n\nlemma lt_iff_exists_rat_btwn (a b : \u211d\u22650) :\n  a < b \u2194 (\u2203q:\u211a, 0 \u2264 q \u2227 a < real.to_nnreal q \u2227 real.to_nnreal q < b) :=\niff.intro\n  (assume (h : (\u2191a:\u211d) < (\u2191b:\u211d)),\n    let \u27e8q, haq, hqb\u27e9 := exists_rat_btwn h in\n    have 0 \u2264 (q : \u211d), from le_trans a.2 $ le_of_lt haq,\n    \u27e8q, rat.cast_nonneg.1 this,\n      by simp [real.coe_to_nnreal _ this, nnreal.coe_lt_coe.symm, haq, hqb]\u27e9)\n  (assume \u27e8q, _, haq, hqb\u27e9, lt_trans haq hqb)\n\nlemma bot_eq_zero : (\u22a5 : \u211d\u22650) = 0 := rfl\n\nlemma mul_sup (a b c : \u211d\u22650) : a * (b \u2294 c) = (a * b) \u2294 (a * c) :=\nbegin\n  cases le_total b c with h h,\n  { simp [sup_eq_max, max_eq_right h, max_eq_right (mul_le_mul_of_nonneg_left h (zero_le a))] },\n  { simp [sup_eq_max, max_eq_left h, max_eq_left (mul_le_mul_of_nonneg_left h (zero_le a))] },\nend\n\nlemma mul_finset_sup {\u03b1} {f : \u03b1 \u2192 \u211d\u22650} {s : finset \u03b1} (r : \u211d\u22650) :\n  r * s.sup f = s.sup (\u03bba, r * f a) :=\nbegin\n  refine s.induction_on _ _,\n  { simp [bot_eq_zero] },\n  { assume a s has ih, simp [has, ih, mul_sup], }\nend\n\nlemma finset_sup_div {\u03b1} {f : \u03b1 \u2192 \u211d\u22650} {s : finset \u03b1} (r : \u211d\u22650) :\n  s.sup f / r = s.sup (\u03bb a, f a / r) :=\nby simp only [div_eq_inv_mul, mul_finset_sup]\n\n@[simp, norm_cast] lemma coe_max (x y : \u211d\u22650) :\n  ((max x y : \u211d\u22650) : \u211d) = max (x : \u211d) (y : \u211d) :=\nnnreal.coe_mono.map_max\n\n@[simp, norm_cast] lemma coe_min (x y : \u211d\u22650) :\n  ((min x y : \u211d\u22650) : \u211d) = min (x : \u211d) (y : \u211d) :=\nnnreal.coe_mono.map_min\n\n@[simp] lemma zero_le_coe {q : \u211d\u22650} : 0 \u2264 (q : \u211d) := q.2\n\nend nnreal\n\nnamespace real\n\nsection to_nnreal\n\n@[simp] lemma to_nnreal_zero : real.to_nnreal 0 = 0 :=\nby simp [real.to_nnreal]; refl\n\n@[simp] lemma to_nnreal_one : real.to_nnreal 1 = 1 :=\nby simp [real.to_nnreal, max_eq_left (zero_le_one : (0 :\u211d) \u2264 1)]; refl\n\n@[simp] lemma to_nnreal_pos {r : \u211d} : 0 < real.to_nnreal r \u2194 0 < r :=\nby simp [real.to_nnreal, nnreal.coe_lt_coe.symm, lt_irrefl]\n\n@[simp] lemma to_nnreal_eq_zero {r : \u211d} : real.to_nnreal r = 0 \u2194 r \u2264 0 :=\nby simpa [-to_nnreal_pos] using (not_iff_not.2 (@to_nnreal_pos r))\n\nlemma to_nnreal_of_nonpos {r : \u211d} : r \u2264 0 \u2192 real.to_nnreal r = 0 :=\nto_nnreal_eq_zero.2\n\n@[simp] lemma coe_to_nnreal' (r : \u211d) : (real.to_nnreal r : \u211d) = max r 0 := rfl\n\n@[simp] lemma to_nnreal_le_to_nnreal_iff {r p : \u211d} (hp : 0 \u2264 p) :\n  real.to_nnreal r \u2264 real.to_nnreal p \u2194 r \u2264 p :=\nby simp [nnreal.coe_le_coe.symm, real.to_nnreal, hp]\n\n@[simp] lemma to_nnreal_lt_to_nnreal_iff' {r p : \u211d} :\n  real.to_nnreal r < real.to_nnreal p \u2194 r < p \u2227 0 < p :=\nby simp [nnreal.coe_lt_coe.symm, real.to_nnreal, lt_irrefl]\n\nlemma to_nnreal_lt_to_nnreal_iff {r p : \u211d} (h : 0 < p) :\n  real.to_nnreal r < real.to_nnreal p \u2194 r < p :=\nto_nnreal_lt_to_nnreal_iff'.trans (and_iff_left h)\n\nlemma to_nnreal_lt_to_nnreal_iff_of_nonneg {r p : \u211d} (hr : 0 \u2264 r) :\n  real.to_nnreal r < real.to_nnreal p \u2194 r < p :=\nto_nnreal_lt_to_nnreal_iff'.trans \u27e8and.left, \u03bb h, \u27e8h, lt_of_le_of_lt hr h\u27e9\u27e9\n\n@[simp] lemma to_nnreal_add {r p : \u211d} (hr : 0 \u2264 r) (hp : 0 \u2264 p) :\n  real.to_nnreal (r + p) = real.to_nnreal r + real.to_nnreal p :=\nnnreal.eq $ by simp [real.to_nnreal, hr, hp, add_nonneg]\n\nlemma to_nnreal_add_to_nnreal {r p : \u211d} (hr : 0 \u2264 r) (hp : 0 \u2264 p) :\n  real.to_nnreal r + real.to_nnreal p = real.to_nnreal (r + p) :=\n(real.to_nnreal_add hr hp).symm\n\nlemma to_nnreal_le_to_nnreal {r p : \u211d} (h : r \u2264 p) :\n  real.to_nnreal r \u2264 real.to_nnreal p :=\nreal.to_nnreal_mono h\n\nlemma to_nnreal_add_le {r p : \u211d} :\n  real.to_nnreal (r + p) \u2264 real.to_nnreal r + real.to_nnreal p :=\nnnreal.coe_le_coe.1 $ max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) nnreal.zero_le_coe\n\nlemma to_nnreal_le_iff_le_coe {r : \u211d} {p : \u211d\u22650} : real.to_nnreal r \u2264 p \u2194 r \u2264 \u2191p :=\nnnreal.gi.gc r p\n\nlemma le_to_nnreal_iff_coe_le {r : \u211d\u22650} {p : \u211d} (hp : 0 \u2264 p) : r \u2264 real.to_nnreal p \u2194 \u2191r \u2264 p :=\nby rw [\u2190 nnreal.coe_le_coe, real.coe_to_nnreal p hp]\n\nlemma le_to_nnreal_iff_coe_le' {r : \u211d\u22650} {p : \u211d} (hr : 0 < r) : r \u2264 real.to_nnreal p \u2194 \u2191r \u2264 p :=\n(le_or_lt 0 p).elim le_to_nnreal_iff_coe_le $ \u03bb hp,\n  by simp only [(hp.trans_le r.coe_nonneg).not_le, to_nnreal_eq_zero.2 hp.le, hr.not_le]\n\nlemma to_nnreal_lt_iff_lt_coe {r : \u211d} {p : \u211d\u22650} (ha : 0 \u2264 r) : real.to_nnreal r < p \u2194 r < \u2191p :=\nby rw [\u2190 nnreal.coe_lt_coe, real.coe_to_nnreal r ha]\n\nlemma lt_to_nnreal_iff_coe_lt {r : \u211d\u22650} {p : \u211d} : r < real.to_nnreal p \u2194 \u2191r < p :=\nbegin\n  cases le_total 0 p,\n  { rw [\u2190 nnreal.coe_lt_coe, real.coe_to_nnreal p h] },\n  { rw [to_nnreal_eq_zero.2 h], split,\n    { intro, have := not_lt_of_le (zero_le r), contradiction },\n    { intro rp, have : \u00ac(p \u2264 0) := not_le_of_lt (lt_of_le_of_lt (nnreal.coe_nonneg _) rp),\n      contradiction } }\nend\n\n@[simp] lemma to_nnreal_bit0 {r : \u211d} (hr : 0 \u2264 r) :\n  real.to_nnreal (bit0 r) = bit0 (real.to_nnreal r) :=\nreal.to_nnreal_add hr hr\n\n@[simp] lemma to_nnreal_bit1 {r : \u211d} (hr : 0 \u2264 r) :\n  real.to_nnreal (bit1 r) = bit1 (real.to_nnreal r) :=\n(real.to_nnreal_add (by simp [hr]) zero_le_one).trans (by simp [to_nnreal_one, bit1, hr])\n\nend to_nnreal\n\nend real\n\nopen real\n\nnamespace nnreal\n\nsection mul\n\nlemma mul_eq_mul_left {a b c : \u211d\u22650} (h : a \u2260 0) : (a * b = a * c \u2194 b = c) :=\nbegin\n  rw [\u2190 nnreal.eq_iff, \u2190 nnreal.eq_iff, nnreal.coe_mul, nnreal.coe_mul], split,\n  { exact mul_left_cancel\u2080 (mt (@nnreal.eq_iff a 0).1 h) },\n  { assume h, rw [h] }\nend\n\nlemma _root_.real.to_nnreal_mul {p q : \u211d} (hp : 0 \u2264 p) :\n  real.to_nnreal (p * q) = real.to_nnreal p * real.to_nnreal q :=\nbegin\n  cases le_total 0 q with hq hq,\n  { apply nnreal.eq,\n    simp [real.to_nnreal, hp, hq, max_eq_left, mul_nonneg] },\n  { have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq,\n    rw [to_nnreal_eq_zero.2 hq, to_nnreal_eq_zero.2 hpq, mul_zero] }\nend\n\nend mul\n\nsection pow\n\nlemma pow_antitone_exp {a : \u211d\u22650} (m n : \u2115) (mn : m \u2264 n) (a1 : a \u2264 1) :\n  a ^ n \u2264 a ^ m :=\npow_le_pow_of_le_one (zero_le a) a1 mn\n\nlemma exists_pow_lt_of_lt_one {a b : \u211d\u22650} (ha : 0 < a) (hb : b < 1) : \u2203 n : \u2115, b ^ n < a :=\nby simpa only [\u2190 coe_pow, nnreal.coe_lt_coe]\n  using exists_pow_lt_of_lt_one (nnreal.coe_pos.2 ha) (nnreal.coe_lt_coe.2 hb)\n\nlemma exists_mem_Ico_zpow\n  {x : \u211d\u22650} {y : \u211d\u22650} (hx : x \u2260 0) (hy : 1 < y) :\n  \u2203 n : \u2124, x \u2208 set.Ico (y ^ n) (y ^ (n + 1)) :=\nbegin\n  obtain \u27e8n, hn, h'n\u27e9 : \u2203 n : \u2124, (y : \u211d) ^ n \u2264 x \u2227 (x : \u211d) < y ^ (n + 1) :=\n    exists_mem_Ico_zpow (bot_lt_iff_ne_bot.mpr hx) hy,\n  rw \u2190 nnreal.coe_zpow at hn h'n,\n  exact \u27e8n, hn, h'n\u27e9,\nend\n\nlemma exists_mem_Ioc_zpow\n  {x : \u211d\u22650} {y : \u211d\u22650} (hx : x \u2260 0) (hy : 1 < y) :\n  \u2203 n : \u2124, x \u2208 set.Ioc (y ^ n) (y ^ (n + 1)) :=\nbegin\n  obtain \u27e8n, hn, h'n\u27e9 : \u2203 n : \u2124, (y : \u211d) ^ n < x \u2227 (x : \u211d) \u2264 y ^ (n + 1) :=\n    exists_mem_Ioc_zpow (bot_lt_iff_ne_bot.mpr hx) hy,\n  rw \u2190 nnreal.coe_zpow at hn h'n,\n  exact \u27e8n, hn, h'n\u27e9,\nend\n\nend pow\n\nsection sub\n/-!\n### Lemmas about subtraction\n\nIn this section we provide a few lemmas about subtraction that do not fit well into any other\ntypeclass. For lemmas about subtraction and addition see lemmas\nabout `has_ordered_sub` in the file `algebra.order.sub`. See also `mul_tsub` and `tsub_mul`. -/\n\nlemma sub_def {r p : \u211d\u22650} : r - p = real.to_nnreal (r - p) := rfl\n\nlemma coe_sub_def {r p : \u211d\u22650} : \u2191(r - p) = max (r - p : \u211d) 0 := rfl\n\nnoncomputable example : has_ordered_sub \u211d\u22650 := by apply_instance\n\nlemma sub_div (a b c : \u211d\u22650) : (a - b) / c = a / c - b / c :=\nby simp only [div_eq_mul_inv, tsub_mul]\n\nend sub\n\nsection inv\n\nlemma sum_div {\u03b9} (s : finset \u03b9) (f : \u03b9 \u2192 \u211d\u22650) (b : \u211d\u22650) :\n  (\u2211 i in s, f i) / b = \u2211 i in s, (f i / b) :=\nby simp only [div_eq_mul_inv, finset.sum_mul]\n\n@[simp] lemma inv_pos {r : \u211d\u22650} : 0 < r\u207b\u00b9 \u2194 0 < r :=\nby simp [pos_iff_ne_zero]\n\nlemma div_pos {r p : \u211d\u22650} (hr : 0 < r) (hp : 0 < p) : 0 < r / p :=\nby simpa only [div_eq_mul_inv] using mul_pos hr (inv_pos.2 hp)\n\nprotected lemma mul_inv {r p : \u211d\u22650} : (r * p)\u207b\u00b9 = p\u207b\u00b9 * r\u207b\u00b9 := nnreal.eq $ mul_inv_rev\u2080 _ _\n\nlemma div_self_le (r : \u211d\u22650) : r / r \u2264 1 :=\nif h : r = 0 then by simp [h] else by rw [div_self h]\n\n@[simp] lemma inv_le {r p : \u211d\u22650} (h : r \u2260 0) : r\u207b\u00b9 \u2264 p \u2194 1 \u2264 r * p :=\nby rw [\u2190 mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h]\n\nlemma inv_le_of_le_mul {r p : \u211d\u22650} (h : 1 \u2264 r * p) : r\u207b\u00b9 \u2264 p :=\nby by_cases r = 0; simp [*, inv_le]\n\n@[simp] lemma le_inv_iff_mul_le {r p : \u211d\u22650} (h : p \u2260 0) : (r \u2264 p\u207b\u00b9 \u2194 r * p \u2264 1) :=\nby rw [\u2190 mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]\n\n@[simp] lemma lt_inv_iff_mul_lt {r p : \u211d\u22650} (h : p \u2260 0) : (r < p\u207b\u00b9 \u2194 r * p < 1) :=\nby rw [\u2190 mul_lt_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]\n\nlemma mul_le_iff_le_inv {a b r : \u211d\u22650} (hr : r \u2260 0) : r * a \u2264 b \u2194 a \u2264 r\u207b\u00b9 * b :=\nhave 0 < r, from lt_of_le_of_ne (zero_le r) hr.symm,\nby rw [\u2190 @mul_le_mul_left _ _ a _ r this, \u2190 mul_assoc, mul_inv_cancel hr, one_mul]\n\nlemma le_div_iff_mul_le {a b r : \u211d\u22650} (hr : r \u2260 0) : a \u2264 b / r \u2194 a * r \u2264 b :=\nby rw [div_eq_inv_mul, \u2190 mul_le_iff_le_inv hr, mul_comm]\n\nlemma div_le_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r \u2264 b \u2194 a \u2264 b * r :=\n@div_le_iff \u211d _ a r b $ pos_iff_ne_zero.2 hr\n\nlemma div_le_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r \u2264 b \u2194 a \u2264 r * b :=\n@div_le_iff' \u211d _ a r b $ pos_iff_ne_zero.2 hr\n\nlemma div_le_of_le_mul {a b c : \u211d\u22650} (h : a \u2264 b * c) : a / c \u2264 b :=\nif h0 : c = 0 then by simp [h0] else (div_le_iff h0).2 h\n\nlemma div_le_of_le_mul' {a b c : \u211d\u22650} (h : a \u2264 b * c) : a / b \u2264 c :=\ndiv_le_of_le_mul $ mul_comm b c \u25b8 h\n\nlemma le_div_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a \u2264 b / r \u2194 a * r \u2264 b :=\n@le_div_iff \u211d _ a b r $ pos_iff_ne_zero.2 hr\n\nlemma le_div_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a \u2264 b / r \u2194 r * a \u2264 b :=\n@le_div_iff' \u211d _ a b r $ pos_iff_ne_zero.2 hr\n\nlemma div_lt_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r < b \u2194 a < b * r :=\nlt_iff_lt_of_le_iff_le (le_div_iff hr)\n\nlemma div_lt_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a / r < b \u2194 a < r * b :=\nlt_iff_lt_of_le_iff_le (le_div_iff' hr)\n\nlemma lt_div_iff {a b r : \u211d\u22650} (hr : r \u2260 0) : a < b / r \u2194 a * r < b :=\nlt_iff_lt_of_le_iff_le (div_le_iff hr)\n\nlemma lt_div_iff' {a b r : \u211d\u22650} (hr : r \u2260 0) : a < b / r \u2194 r * a < b :=\nlt_iff_lt_of_le_iff_le (div_le_iff' hr)\n\nlemma mul_lt_of_lt_div {a b r : \u211d\u22650} (h : a < b / r) : a * r < b :=\nbegin\n  refine (lt_div_iff $ \u03bb hr, false.elim _).1 h,\n  subst r,\n  simpa using h\nend\n\nlemma div_le_div_left_of_le {a b c : \u211d\u22650} (b0 : 0 < b) (c0 : 0 < c) (cb : c \u2264 b) :\n  a / b \u2264 a / c :=\nbegin\n  by_cases a0 : a = 0,\n  { rw [a0, zero_div, zero_div] },\n  { cases a with a ha,\n    replace a0 : 0 < a := lt_of_le_of_ne ha (ne_of_lt (zero_lt_iff.mpr a0)),\n    exact (div_le_div_left a0 b0 c0).mpr cb }\nend\n\nlemma div_le_div_left {a b c : \u211d\u22650} (a0 : 0 < a) (b0 : 0 < b) (c0 : 0 < c) :\n  a / b \u2264 a / c \u2194 c \u2264 b :=\nby rw [nnreal.div_le_iff b0.ne.symm, div_mul_eq_mul_div, nnreal.le_div_iff_mul_le c0.ne.symm,\n  mul_le_mul_left a0]\n\nlemma le_of_forall_lt_one_mul_le {x y : \u211d\u22650} (h : \u2200a<1, a * x \u2264 y) : x \u2264 y :=\nle_of_forall_ge_of_dense $ assume a ha,\n  have hx : x \u2260 0 := pos_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha),\n  have hx' : x\u207b\u00b9 \u2260 0, by rwa [(\u2260), inv_eq_zero],\n  have a * x\u207b\u00b9 < 1, by rwa [\u2190 lt_inv_iff_mul_lt hx', inv_inv\u2080],\n  have (a * x\u207b\u00b9) * x \u2264 y, from h _ this,\n  by rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this\n\nlemma div_add_div_same (a b c : \u211d\u22650) : a / c + b / c = (a + b) / c :=\neq.symm $ right_distrib a b (c\u207b\u00b9)\n\nlemma half_pos {a : \u211d\u22650} (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two\n\nlemma add_halves (a : \u211d\u22650) : a / 2 + a / 2 = a := nnreal.eq (add_halves a)\n\nlemma half_lt_self {a : \u211d\u22650} (h : a \u2260 0) : a / 2 < a :=\nby rw [\u2190 nnreal.coe_lt_coe, nnreal.coe_div]; exact\nhalf_lt_self (bot_lt_iff_ne_bot.2 h)\n\nlemma two_inv_lt_one : (2\u207b\u00b9:\u211d\u22650) < 1 :=\nby simpa using half_lt_self zero_ne_one.symm\n\nlemma div_lt_one_of_lt {a b : \u211d\u22650} (h : a < b) : a / b < 1 :=\nbegin\n  rwa [div_lt_iff, one_mul],\n  exact ne_of_gt (lt_of_le_of_lt (zero_le _) h)\nend\n\n@[field_simps] lemma div_add_div (a : \u211d\u22650) {b : \u211d\u22650} (c : \u211d\u22650) {d : \u211d\u22650}\n  (hb : b \u2260 0) (hd : d \u2260 0) : a / b + c / d = (a * d + b * c) / (b * d) :=\nbegin\n  rw \u2190 nnreal.eq_iff,\n  simp only [nnreal.coe_add, nnreal.coe_div, nnreal.coe_mul],\n  exact div_add_div _ _ (coe_ne_zero.2 hb) (coe_ne_zero.2 hd)\nend\n\n@[field_simps] lemma add_div' (a b c : \u211d\u22650) (hc : c \u2260 0) :\n  b + a / c = (b * c + a) / c :=\nby simpa using div_add_div b a one_ne_zero hc\n\n@[field_simps] lemma div_add' (a b c : \u211d\u22650) (hc : c \u2260 0) :\n  a / c + b = (a + b * c) / c :=\nby rwa [add_comm, add_div', add_comm]\n\nlemma _root_.real.to_nnreal_inv {x : \u211d} :\n  real.to_nnreal x\u207b\u00b9 = (real.to_nnreal x)\u207b\u00b9 :=\nbegin\n  by_cases hx : 0 \u2264 x,\n  { nth_rewrite 0 \u2190 real.coe_to_nnreal x hx,\n    rw [\u2190nnreal.coe_inv, real.to_nnreal_coe], },\n  { have hx' := le_of_not_ge hx,\n    rw [to_nnreal_eq_zero.mpr hx', inv_zero, to_nnreal_eq_zero.mpr (inv_nonpos.mpr hx')], },\nend\n\nlemma _root_.real.to_nnreal_div {x y : \u211d} (hx : 0 \u2264 x) :\n  real.to_nnreal (x / y) = real.to_nnreal x / real.to_nnreal y :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, \u2190 real.to_nnreal_inv, \u2190 real.to_nnreal_mul hx]\n\nlemma _root_.real.to_nnreal_div' {x y : \u211d} (hy : 0 \u2264 y) :\n  real.to_nnreal (x / y) = real.to_nnreal x / real.to_nnreal y :=\nby rw [div_eq_inv_mul, div_eq_inv_mul, real.to_nnreal_mul (inv_nonneg.2 hy), real.to_nnreal_inv]\n\nlemma inv_lt_one_iff {x : \u211d\u22650} (hx : x \u2260 0) : x\u207b\u00b9 < 1 \u2194 1 < x :=\nby rwa [\u2190 one_div, div_lt_iff hx, one_mul]\n\nlemma inv_lt_one {x : \u211d\u22650} (hx : 1 < x) : x\u207b\u00b9 < 1 :=\n(inv_lt_one_iff (zero_lt_one.trans hx).ne').2 hx\n\nlemma zpow_pos {x : \u211d\u22650} (hx : x \u2260 0) (n : \u2124) : 0 < x ^ n :=\nbegin\n  cases n,\n  { exact pow_pos hx.bot_lt _ },\n  { simp [pow_pos hx.bot_lt _] }\nend\n\nend inv\n\n@[simp] lemma abs_eq (x : \u211d\u22650) : |(x : \u211d)| = x :=\nabs_of_nonneg x.property\n\nend nnreal\n\nnamespace real\n\n/-- The absolute value on `\u211d` as a map to `\u211d\u22650`. -/\n@[pp_nodot] noncomputable def nnabs : monoid_with_zero_hom \u211d \u211d\u22650 :=\n{ to_fun := \u03bb x, \u27e8|x|, abs_nonneg x\u27e9,\n  map_zero' := by { ext, simp },\n  map_one' := by { ext, simp },\n  map_mul' := \u03bb x y, by { ext, simp [abs_mul] } }\n\n@[norm_cast, simp] lemma coe_nnabs (x : \u211d) : (nnabs x : \u211d) = |x| :=\nrfl\n\n@[simp] lemma nnabs_of_nonneg {x : \u211d} (h : 0 \u2264 x) : nnabs x = to_nnreal x :=\nby { ext, simp [coe_to_nnreal x h, abs_of_nonneg h] }\n\nlemma coe_to_nnreal_le (x : \u211d) : (to_nnreal x : \u211d) \u2264 |x| :=\nmax_le (le_abs_self _) (abs_nonneg _)\n\nlemma cast_nat_abs_eq_nnabs_cast (n : \u2124) :\n  (n.nat_abs : \u211d\u22650) = nnabs n :=\nby { ext, rw [nnreal.coe_nat_cast, int.cast_nat_abs, real.coe_nnabs] }\n\nend real\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/real/nnreal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7067709827330985}}
{"text": "/-\nCopyright (c) 2022 Dagur T\u00f3mas \u00c1sgeirsson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Dagur T\u00f3mas \u00c1sgeirsson, Leonardo de Moura\n\n! This file was ported from Lean 3 source module data.set.bool_indicator\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Set.Image\n\n/-!\n# Indicator function valued in bool\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nSee also `set.indicator` and `set.piecewise`.\n-/\n\n\nopen Bool\n\nnamespace Set\n\nvariable {\u03b1 : Type _} (s : Set \u03b1)\n\n#print Set.boolIndicator /-\n/-- `bool_indicator` maps `x` to `tt` if `x \u2208 s`, else to `ff` -/\nnoncomputable def boolIndicator (x : \u03b1) :=\n  @ite _ (x \u2208 s) (Classical.propDecidable _) true false\n#align set.bool_indicator Set.boolIndicator\n-/\n\n#print Set.mem_iff_boolIndicator /-\ntheorem mem_iff_boolIndicator (x : \u03b1) : x \u2208 s \u2194 s.boolIndicator x = true :=\n  by\n  unfold bool_indicator\n  split_ifs <;> tauto\n#align set.mem_iff_bool_indicator Set.mem_iff_boolIndicator\n-/\n\n#print Set.not_mem_iff_boolIndicator /-\ntheorem not_mem_iff_boolIndicator (x : \u03b1) : x \u2209 s \u2194 s.boolIndicator x = false :=\n  by\n  unfold bool_indicator\n  split_ifs <;> tauto\n#align set.not_mem_iff_bool_indicator Set.not_mem_iff_boolIndicator\n-/\n\n/- warning: set.preimage_bool_indicator_tt clashes with set.preimage_bool_indicator_true -> Set.preimage_boolIndicator_true\nCase conversion may be inaccurate. Consider using '#align set.preimage_bool_indicator_tt Set.preimage_boolIndicator_true\u2093'. -/\n#print Set.preimage_boolIndicator_true /-\ntheorem preimage_boolIndicator_true : s.boolIndicator \u207b\u00b9' {true} = s :=\n  ext fun x => (s.mem_iff_boolIndicator x).symm\n#align set.preimage_bool_indicator_tt Set.preimage_boolIndicator_true\n-/\n\n/- warning: set.preimage_bool_indicator_ff clashes with set.preimage_bool_indicator_false -> Set.preimage_boolIndicator_false\nwarning: set.preimage_bool_indicator_ff -> Set.preimage_boolIndicator_false is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} (s : Set.{u1} \u03b1), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) (Singleton.singleton.{0, 0} Bool (Set.{0} Bool) (Set.hasSingleton.{0} Bool) Bool.false)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) s)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} (s : Set.{u1} \u03b1), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) (Singleton.singleton.{0, 0} Bool (Set.{0} Bool) (Set.instSingletonSet.{0} Bool) Bool.false)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.instBooleanAlgebraSet.{u1} \u03b1)) s)\nCase conversion may be inaccurate. Consider using '#align set.preimage_bool_indicator_ff Set.preimage_boolIndicator_false\u2093'. -/\ntheorem preimage_boolIndicator_false : s.boolIndicator \u207b\u00b9' {false} = s\u1d9c :=\n  ext fun x => (s.not_mem_iff_boolIndicator x).symm\n#align set.preimage_bool_indicator_ff Set.preimage_boolIndicator_false\n\nopen Classical\n\n/- warning: set.preimage_bool_indicator_eq_union -> Set.preimage_boolIndicator_eq_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} (s : Set.{u1} \u03b1) (t : Set.{0} Bool), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) (ite.{succ u1} (Set.{u1} \u03b1) (Membership.Mem.{0, 0} Bool (Set.{0} Bool) (Set.hasMem.{0} Bool) Bool.true t) (Classical.propDecidable (Membership.Mem.{0, 0} Bool (Set.{0} Bool) (Set.hasMem.{0} Bool) Bool.true t)) s (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))) (ite.{succ u1} (Set.{u1} \u03b1) (Membership.Mem.{0, 0} Bool (Set.{0} Bool) (Set.hasMem.{0} Bool) Bool.false t) (Classical.propDecidable (Membership.Mem.{0, 0} Bool (Set.{0} Bool) (Set.hasMem.{0} Bool) Bool.false t)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) s) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} (s : Set.{u1} \u03b1) (t : Set.{0} Bool), Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (ite.{succ u1} (Set.{u1} \u03b1) (Membership.mem.{0, 0} Bool (Set.{0} Bool) (Set.instMembershipSet.{0} Bool) Bool.true t) (Classical.propDecidable (Membership.mem.{0, 0} Bool (Set.{0} Bool) (Set.instMembershipSet.{0} Bool) Bool.true t)) s (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))) (ite.{succ u1} (Set.{u1} \u03b1) (Membership.mem.{0, 0} Bool (Set.{0} Bool) (Set.instMembershipSet.{0} Bool) Bool.false t) (Classical.propDecidable (Membership.mem.{0, 0} Bool (Set.{0} Bool) (Set.instMembershipSet.{0} Bool) Bool.false t)) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.instBooleanAlgebraSet.{u1} \u03b1)) s) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1))))\nCase conversion may be inaccurate. Consider using '#align set.preimage_bool_indicator_eq_union Set.preimage_boolIndicator_eq_union\u2093'. -/\ntheorem preimage_boolIndicator_eq_union (t : Set Bool) :\n    s.boolIndicator \u207b\u00b9' t = (if true \u2208 t then s else \u2205) \u222a if false \u2208 t then s\u1d9c else \u2205 :=\n  by\n  ext x\n  dsimp [bool_indicator]\n  split_ifs <;> tauto\n#align set.preimage_bool_indicator_eq_union Set.preimage_boolIndicator_eq_union\n\n/- warning: set.preimage_bool_indicator -> Set.preimage_boolIndicator is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} (s : Set.{u1} \u03b1) (t : Set.{0} Bool), Or (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (Set.univ.{u1} \u03b1)) (Or (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) s) (Or (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.booleanAlgebra.{u1} \u03b1)) s)) (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.hasEmptyc.{u1} \u03b1)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} (s : Set.{u1} \u03b1) (t : Set.{0} Bool), Or (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (Set.univ.{u1} \u03b1)) (Or (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) s) (Or (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (HasCompl.compl.{u1} (Set.{u1} \u03b1) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} \u03b1) (Set.instBooleanAlgebraSet.{u1} \u03b1)) s)) (Eq.{succ u1} (Set.{u1} \u03b1) (Set.preimage.{u1, 0} \u03b1 Bool (Set.boolIndicator.{u1} \u03b1 s) t) (EmptyCollection.emptyCollection.{u1} (Set.{u1} \u03b1) (Set.instEmptyCollectionSet.{u1} \u03b1)))))\nCase conversion may be inaccurate. Consider using '#align set.preimage_bool_indicator Set.preimage_boolIndicator\u2093'. -/\ntheorem preimage_boolIndicator (t : Set Bool) :\n    s.boolIndicator \u207b\u00b9' t = univ \u2228\n      s.boolIndicator \u207b\u00b9' t = s \u2228 s.boolIndicator \u207b\u00b9' t = s\u1d9c \u2228 s.boolIndicator \u207b\u00b9' t = \u2205 :=\n  by\n  simp only [preimage_bool_indicator_eq_union]\n  split_ifs <;> simp [s.union_compl_self]\n#align set.preimage_bool_indicator Set.preimage_boolIndicator\n\nend Set\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Set/BoolIndicator.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7067709762431412}}
{"text": "/-\nCopyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Adam Topaz, Bryan Gin-ge Chen\n-/\n\nimport order.boolean_algebra\n\n/-!\n# Symmetric difference\n\nThe symmetric difference or disjunctive union of sets `A` and `B` is the set of elements that are\nin either `A` or `B` but not both. Translated into propositions, the symmetric difference is `xor`.\n\nThe symmetric difference operator (`symm_diff`) is defined in this file for any type with `\u2294` and\n`\\` via the formula `(A \\ B) \u2294 (B \\ A)`, however the theorems proved about it only hold for\n`generalized_boolean_algebra`s and `boolean_algebra`s.\n\nThe symmetric difference is the addition operator in the Boolean ring structure on Boolean algebras.\n\n## Main declarations\n\n* `symm_diff`: the symmetric difference operator, defined as `(A \\ B) \u2294 (B \\ A)`\n* `equiv.symm_diff`: Symmetric difference by `a` as an `equiv`.\n\nIn generalized Boolean algebras, the symmetric difference operator is:\n\n* `symm_diff_comm`: commutative, and\n* `symm_diff_assoc`: associative.\n\n## Notations\n\n* `a \u2206 b`: `symm_diff a b`\n\n## References\n\nThe proof of associativity follows the note \"Associativity of the Symmetric Difference of Sets: A\nProof from the Book\" by John McCuan:\n\n* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>\n\n## Tags\nboolean ring, generalized boolean algebra, boolean algebra, symmetric differences\n-/\n\nopen function\n\n/-- The symmetric difference operator on a type with `\u2294` and `\\` is `(A \\ B) \u2294 (B \\ A)`. -/\ndef symm_diff {\u03b1 : Type*} [has_sup \u03b1] [has_sdiff \u03b1] (A B : \u03b1) : \u03b1 := (A \\ B) \u2294 (B \\ A)\n\n/- This notation might conflict with the Laplacian once we have it. Feel free to put it in locale\n`order` or `symm_diff` if that happens. -/\ninfix ` \u2206 `:100 := symm_diff\n\nlemma symm_diff_def {\u03b1 : Type*} [has_sup \u03b1] [has_sdiff \u03b1] (A B : \u03b1) :\n  A \u2206 B = (A \\ B) \u2294 (B \\ A) :=\nrfl\n\nlemma symm_diff_eq_xor (p q : Prop) : p \u2206 q = xor p q := rfl\n\n@[simp] lemma bool.symm_diff_eq_bxor : \u2200 p q : bool, p \u2206 q = bxor p q := dec_trivial\n\nsection generalized_boolean_algebra\nvariables {\u03b1 : Type*} [generalized_boolean_algebra \u03b1] (a b c d : \u03b1)\n\nlemma symm_diff_comm : a \u2206 b = b \u2206 a := by simp only [(\u2206), sup_comm]\n\ninstance symm_diff_is_comm : is_commutative \u03b1 (\u2206) := \u27e8symm_diff_comm\u27e9\n\n@[simp] lemma symm_diff_self : a \u2206 a = \u22a5 := by rw [(\u2206), sup_idem, sdiff_self]\n@[simp] lemma symm_diff_bot : a \u2206 \u22a5 = a := by rw [(\u2206), sdiff_bot, bot_sdiff, sup_bot_eq]\n@[simp] lemma bot_symm_diff : \u22a5 \u2206 a = a := by rw [symm_diff_comm, symm_diff_bot]\n\nlemma symm_diff_eq_sup_sdiff_inf : a \u2206 b = (a \u2294 b) \\ (a \u2293 b) :=\nby simp [sup_sdiff, sdiff_inf, sup_comm, (\u2206)]\n\n@[simp] lemma sup_sdiff_symm_diff : (a \u2294 b) \\ (a \u2206 b) = a \u2293 b :=\nsdiff_eq_symm inf_le_sup (by rw symm_diff_eq_sup_sdiff_inf)\n\nlemma disjoint_symm_diff_inf : disjoint (a \u2206 b) (a \u2293 b) :=\nbegin\n  rw [symm_diff_eq_sup_sdiff_inf],\n  exact disjoint_sdiff_self_left,\nend\n\nlemma symm_diff_le_sup : a \u2206 b \u2264 a \u2294 b := by { rw symm_diff_eq_sup_sdiff_inf, exact sdiff_le }\n\nlemma inf_symm_diff_distrib_left : a \u2293 (b \u2206 c) = (a \u2293 b) \u2206 (a \u2293 c) :=\nby rw [symm_diff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left,\n  symm_diff_eq_sup_sdiff_inf]\n\nlemma inf_symm_diff_distrib_right : (a \u2206 b) \u2293 c = (a \u2293 c) \u2206 (b \u2293 c) :=\nby simp_rw [@inf_comm _ _ _ c, inf_symm_diff_distrib_left]\n\nlemma sdiff_symm_diff : c \\ (a \u2206 b) = (c \u2293 a \u2293 b) \u2294 ((c \\ a) \u2293 (c \\ b)) :=\nby simp only [(\u2206), sdiff_sdiff_sup_sdiff']\n\nlemma sdiff_symm_diff' : c \\ (a \u2206 b) = (c \u2293 a \u2293 b) \u2294 (c \\ (a \u2294 b)) :=\nby rw [sdiff_symm_diff, sdiff_sup, sup_comm]\n\nlemma symm_diff_sdiff : (a \u2206 b) \\ c = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) :=\nby rw [symm_diff_def, sup_sdiff, sdiff_sdiff_left, sdiff_sdiff_left]\n\n@[simp] lemma symm_diff_sdiff_left : (a \u2206 b) \\ a = b \\ a :=\nby rw [symm_diff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]\n\n@[simp] lemma symm_diff_sdiff_right : (a \u2206 b) \\ b = a \\ b :=\nby rw [symm_diff_comm, symm_diff_sdiff_left]\n\n@[simp] lemma sdiff_symm_diff_self : a \\ (a \u2206 b) = a \u2293 b := by simp [sdiff_symm_diff]\n\nlemma symm_diff_eq_iff_sdiff_eq {a b c : \u03b1} (ha : a \u2264 c) :\n  a \u2206 b = c \u2194 c \\ a = b :=\nbegin\n  split; intro h,\n  { have hba : disjoint (a \u2293 b) c := begin\n      rw [\u2190h, disjoint.comm],\n      exact disjoint_symm_diff_inf _ _,\n    end,\n    have hca : _ := congr_arg (\\ a) h,\n    rw [symm_diff_sdiff_left] at hca,\n    rw [\u2190hca, sdiff_eq_self_iff_disjoint],\n    exact hba.of_disjoint_inf_of_le ha },\n  { have hd : disjoint a b := by { rw \u2190h, exact disjoint_sdiff_self_right },\n    rw [symm_diff_def, hd.sdiff_eq_left, hd.sdiff_eq_right, \u2190h, sup_sdiff_cancel_right ha] }\nend\n\nlemma disjoint.symm_diff_eq_sup {a b : \u03b1} (h : disjoint a b) : a \u2206 b = a \u2294 b :=\nby rw [(\u2206), h.sdiff_eq_left, h.sdiff_eq_right]\n\nlemma symm_diff_eq_sup : a \u2206 b = a \u2294 b \u2194 disjoint a b :=\nbegin\n  split; intro h,\n  { rw [symm_diff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h,\n    exact h.of_disjoint_inf_of_le le_sup_left, },\n  { exact h.symm_diff_eq_sup, },\nend\n\nlemma symm_diff_symm_diff_left :\n  a \u2206 b \u2206 c = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294 (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c) :=\ncalc a \u2206 b \u2206 c = ((a \u2206 b) \\ c) \u2294 (c \\ (a \u2206 b))   : symm_diff_def _ _\n           ... = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294\n                   ((c \\ (a \u2294 b)) \u2294 (c \u2293 a \u2293 b)) :\n                                by rw [sdiff_symm_diff', @sup_comm _ _ (c \u2293 a \u2293 b), symm_diff_sdiff]\n           ... = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294\n                   (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c)   : by ac_refl\n\nlemma symm_diff_symm_diff_right :\n  a \u2206 (b \u2206 c) = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294 (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c) :=\ncalc a \u2206 (b \u2206 c) = (a \\ (b \u2206 c)) \u2294 ((b \u2206 c) \\ a) : symm_diff_def _ _\n             ... = (a \\ (b \u2294 c)) \u2294 (a \u2293 b \u2293 c) \u2294\n                     (b \\ (c \u2294 a) \u2294 c \\ (b \u2294 a))   :\n                                by rw [sdiff_symm_diff', @sup_comm _ _ (a \u2293 b \u2293 c), symm_diff_sdiff]\n             ... = (a \\ (b \u2294 c)) \u2294 (b \\ (a \u2294 c)) \u2294\n                     (c \\ (a \u2294 b)) \u2294 (a \u2293 b \u2293 c)   : by ac_refl\n\n@[simp] lemma symm_diff_symm_diff_inf : a \u2206 b \u2206 (a \u2293 b) = a \u2294 b :=\nby rw [symm_diff_eq_iff_sdiff_eq (symm_diff_le_sup _ _), sup_sdiff_symm_diff]\n\n@[simp] lemma inf_symm_diff_symm_diff : (a \u2293 b) \u2206 (a \u2206 b) = a \u2294 b :=\nby rw [symm_diff_comm, symm_diff_symm_diff_inf]\n\nlemma symm_diff_assoc : a \u2206 b \u2206 c = a \u2206 (b \u2206 c) :=\nby rw [symm_diff_symm_diff_left, symm_diff_symm_diff_right]\n\ninstance symm_diff_is_assoc : is_associative \u03b1 (\u2206) := \u27e8symm_diff_assoc\u27e9\n\nlemma symm_diff_left_comm : a \u2206 (b \u2206 c) = b \u2206 (a \u2206 c) :=\nby simp_rw [\u2190symm_diff_assoc, symm_diff_comm]\n\nlemma symm_diff_right_comm : a \u2206 b \u2206 c = a \u2206 c \u2206 b := by simp_rw [symm_diff_assoc, symm_diff_comm]\n\nlemma symm_diff_symm_diff_symm_diff_comm : (a \u2206 b) \u2206 (c \u2206 d) = (a \u2206 c) \u2206 (b \u2206 d) :=\nby simp_rw [symm_diff_assoc, symm_diff_left_comm]\n\n@[simp] lemma symm_diff_symm_diff_cancel_left : a \u2206 (a \u2206 b) = b := by simp [\u2190symm_diff_assoc]\n@[simp] lemma symm_diff_symm_diff_cancel_right : b \u2206 a \u2206 a = b := by simp [symm_diff_assoc]\n\n@[simp] lemma symm_diff_symm_diff_self' : a \u2206 b \u2206 a = b :=\nby rw [symm_diff_comm,symm_diff_symm_diff_cancel_left]\n\nlemma symm_diff_left_involutive (a : \u03b1) : involutive (\u2206 a) := symm_diff_symm_diff_cancel_right _\nlemma symm_diff_right_involutive (a : \u03b1) : involutive ((\u2206) a) := symm_diff_symm_diff_cancel_left _\nlemma symm_diff_left_injective (a : \u03b1) : injective (\u2206 a) := (symm_diff_left_involutive _).injective\nlemma symm_diff_right_injective (a : \u03b1) : injective ((\u2206) a) :=\n(symm_diff_right_involutive _).injective\nlemma symm_diff_left_surjective (a : \u03b1) : surjective (\u2206 a) :=\n(symm_diff_left_involutive _).surjective\nlemma symm_diff_right_surjective (a : \u03b1) : surjective ((\u2206) a) :=\n(symm_diff_right_involutive _).surjective\n\nvariables {a b c}\n\n@[simp] lemma symm_diff_left_inj : a \u2206 b = c \u2206 b \u2194 a = c := (symm_diff_left_injective _).eq_iff\n@[simp] lemma symm_diff_right_inj : a \u2206 b = a \u2206 c \u2194 b = c := (symm_diff_right_injective _).eq_iff\n\n@[simp] lemma symm_diff_eq_left : a \u2206 b = a \u2194 b = \u22a5 :=\ncalc a \u2206 b = a \u2194 a \u2206 b = a \u2206 \u22a5 : by rw symm_diff_bot\n           ... \u2194     b = \u22a5     : by rw symm_diff_right_inj\n\n@[simp] lemma symm_diff_eq_right : a \u2206 b = b \u2194 a = \u22a5 := by rw [symm_diff_comm, symm_diff_eq_left]\n\n@[simp] lemma symm_diff_eq_bot : a \u2206 b = \u22a5 \u2194 a = b :=\ncalc a \u2206 b = \u22a5 \u2194 a \u2206 b = a \u2206 a : by rw symm_diff_self\n           ... \u2194     a = b     : by rw [symm_diff_right_inj, eq_comm]\n\nprotected lemma disjoint.symm_diff_left (ha : disjoint a c) (hb : disjoint b c) :\n  disjoint (a \u2206 b) c :=\nby { rw symm_diff_eq_sup_sdiff_inf, exact (ha.sup_left hb).disjoint_sdiff_left }\n\nprotected lemma disjoint.symm_diff_right (ha : disjoint a b) (hb : disjoint a c) :\n  disjoint a (b \u2206 c) :=\n(ha.symm.symm_diff_left hb.symm).symm\n\nend generalized_boolean_algebra\n\nsection boolean_algebra\nvariables {\u03b1 : Type*} [boolean_algebra \u03b1] (a b c : \u03b1)\n\nlemma symm_diff_eq : a \u2206 b = (a \u2293 b\u1d9c) \u2294 (b \u2293 a\u1d9c) := by simp only [(\u2206), sdiff_eq]\n\n@[simp] lemma symm_diff_top : a \u2206 \u22a4 = a\u1d9c := by simp [symm_diff_eq]\n@[simp] lemma top_symm_diff : \u22a4 \u2206 a = a\u1d9c := by rw [symm_diff_comm, symm_diff_top]\n\nlemma compl_symm_diff : (a \u2206 b)\u1d9c = (a \u2293 b) \u2294 (a\u1d9c \u2293 b\u1d9c) :=\nby simp only [\u2190top_sdiff, sdiff_symm_diff, top_inf_eq]\n\nlemma symm_diff_eq_top_iff : a \u2206 b = \u22a4 \u2194 is_compl a b :=\nby rw [symm_diff_eq_iff_sdiff_eq le_top, top_sdiff, compl_eq_iff_is_compl]\n\nlemma is_compl.symm_diff_eq_top (h : is_compl a b) : a \u2206 b = \u22a4 := (symm_diff_eq_top_iff a b).2 h\n\n@[simp] lemma compl_symm_diff_self : a\u1d9c \u2206 a = \u22a4 :=\nby simp only [symm_diff_eq, compl_compl, inf_idem, compl_sup_eq_top]\n\n@[simp] lemma symm_diff_compl_self : a \u2206 a\u1d9c = \u22a4 := by rw [symm_diff_comm, compl_symm_diff_self]\n\nlemma symm_diff_symm_diff_right' :\n  a \u2206 (b \u2206 c) = (a \u2293 b \u2293 c) \u2294 (a \u2293 b\u1d9c \u2293 c\u1d9c) \u2294 (a\u1d9c \u2293 b \u2293 c\u1d9c) \u2294 (a\u1d9c \u2293 b\u1d9c \u2293 c) :=\ncalc a \u2206 (b \u2206 c) = (a \u2293 ((b \u2293 c) \u2294 (b\u1d9c \u2293 c\u1d9c))) \u2294\n                     (((b \u2293 c\u1d9c) \u2294 (c \u2293 b\u1d9c)) \u2293 a\u1d9c)  : by rw [symm_diff_eq, compl_symm_diff,\n                                                            symm_diff_eq]\n             ... = (a \u2293 b \u2293 c) \u2294 (a \u2293 b\u1d9c \u2293 c\u1d9c) \u2294\n                     (b \u2293 c\u1d9c \u2293 a\u1d9c) \u2294 (c \u2293 b\u1d9c \u2293 a\u1d9c) : by rw [inf_sup_left, inf_sup_right,\n                                                            \u2190sup_assoc, \u2190inf_assoc, \u2190inf_assoc]\n             ... = (a \u2293 b \u2293 c) \u2294 (a \u2293 b\u1d9c \u2293 c\u1d9c) \u2294\n                     (a\u1d9c \u2293 b \u2293 c\u1d9c) \u2294 (a\u1d9c \u2293 b\u1d9c \u2293 c) : begin\n                                                       congr' 1,\n                                                       { congr' 1,\n                                                         rw [inf_comm, inf_assoc], },\n                                                       { apply inf_left_right_swap }\n                                                     end\n\nend boolean_algebra\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/symm_diff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7067709727778624}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Aaron Anderson\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.finset.gcd\nimport Mathlib.data.polynomial.default\nimport Mathlib.data.polynomial.erase_lead\nimport Mathlib.data.polynomial.cancel_leads\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# GCD structures on polynomials\n\nDefinitions and basic results about polynomials over GCD domains, particularly their contents\nand primitive polynomials.\n\n## Main Definitions\nLet `p : polynomial R`.\n - `p.content` is the `gcd` of the coefficients of `p`.\n - `p.is_primitive` indicates that `p.content = 1`.\n\n## Main Results\n - `polynomial.content_mul`:\n  If `p q : polynomial R`, then `(p * q).content = p.content * q.content`.\n - `polynomial.gcd_monoid`:\n  The polynomial ring of a GCD domain is itself a GCD domain.\n\n-/\n\nnamespace polynomial\n\n\n/-- `p.content` is the `gcd` of the coefficients of `p`. -/\ndef content {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : R :=\n  finset.gcd (finsupp.support p) (coeff p)\n\ntheorem content_dvd_coeff {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (n : \u2115) : content p \u2223 coeff p n := sorry\n\n@[simp] theorem content_C {R : Type u_1} [integral_domain R] [gcd_monoid R] {r : R} : content (coe_fn C r) = coe_fn normalize r := sorry\n\n@[simp] theorem content_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] : content 0 = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (content 0 = 0)) (Eq.symm C_0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (content (coe_fn C 0) = 0)) content_C))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn normalize 0 = 0)) normalize_zero)) (Eq.refl 0)))\n\n@[simp] theorem content_one {R : Type u_1} [integral_domain R] [gcd_monoid R] : content 1 = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (content 1 = 1)) (Eq.symm C_1)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (content (coe_fn C 1) = 1)) content_C))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn normalize 1 = 1)) normalize_one)) (Eq.refl 1)))\n\ntheorem content_X_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : content (X * p) = content p := sorry\n\n@[simp] theorem content_X_pow {R : Type u_1} [integral_domain R] [gcd_monoid R] {k : \u2115} : content (X ^ k) = 1 := sorry\n\n@[simp] theorem content_X {R : Type u_1} [integral_domain R] [gcd_monoid R] : content X = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (content X = 1)) (Eq.symm (mul_one X))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (content (X * 1) = 1)) content_X_mul))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (content 1 = 1)) content_one)) (Eq.refl 1)))\n\ntheorem content_C_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] (r : R) (p : polynomial R) : content (coe_fn C r * p) = coe_fn normalize r * content p := sorry\n\n@[simp] theorem content_monomial {R : Type u_1} [integral_domain R] [gcd_monoid R] {r : R} {k : \u2115} : content (coe_fn (monomial k) r) = coe_fn normalize r := sorry\n\ntheorem content_eq_zero_iff {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : content p = 0 \u2194 p = 0 := sorry\n\n@[simp] theorem normalize_content {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : coe_fn normalize (content p) = content p :=\n  finset.normalize_gcd\n\ntheorem content_eq_gcd_range_of_lt {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) (n : \u2115) (h : nat_degree p < n) : content p = finset.gcd (finset.range n) (coeff p) := sorry\n\ntheorem content_eq_gcd_range_succ {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : content p = finset.gcd (finset.range (Nat.succ (nat_degree p))) (coeff p) :=\n  content_eq_gcd_range_of_lt p (Nat.succ (nat_degree p)) (nat.lt_succ_self (nat_degree p))\n\ntheorem content_eq_gcd_leading_coeff_content_erase_lead {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : content p = gcd (leading_coeff p) (content (erase_lead p)) := sorry\n\ntheorem dvd_content_iff_C_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {r : R} : r \u2223 content p \u2194 coe_fn C r \u2223 p := sorry\n\ntheorem C_content_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : coe_fn C (content p) \u2223 p :=\n  iff.mp dvd_content_iff_C_dvd (dvd_refl (content p))\n\n/-- A polynomial over a GCD domain is primitive when the `gcd` of its coefficients is 1 -/\ndef is_primitive {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) :=\n  content p = 1\n\n@[simp] theorem is_primitive_one {R : Type u_1} [integral_domain R] [gcd_monoid R] : is_primitive 1 := sorry\n\ntheorem monic.is_primitive {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : monic p) : is_primitive p := sorry\n\ntheorem is_primitive.ne_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : is_primitive p) : p \u2260 0 := sorry\n\ntheorem is_primitive.content_eq_one {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : is_primitive p) : content p = 1 :=\n  hp\n\ntheorem is_primitive_iff_is_unit_of_C_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : is_primitive p \u2194 \u2200 (r : R), coe_fn C r \u2223 p \u2192 is_unit r := sorry\n\n/-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by\n  `p.content`. If `p = 0`, then `p.prim_part = 1`.  -/\ndef prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : polynomial R :=\n  ite (p = 0) 1 (classical.some (C_content_dvd p))\n\ntheorem eq_C_content_mul_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : p = coe_fn C (content p) * prim_part p := sorry\n\n@[simp] theorem prim_part_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] : prim_part 0 = 1 :=\n  if_pos rfl\n\ntheorem is_primitive_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : is_primitive (prim_part p) := sorry\n\ntheorem content_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : content (prim_part p) = 1 :=\n  is_primitive_prim_part p\n\ntheorem prim_part_ne_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : prim_part p \u2260 0 :=\n  is_primitive.ne_zero (is_primitive_prim_part p)\n\ntheorem nat_degree_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : nat_degree (prim_part p) = nat_degree p := sorry\n\n@[simp] theorem is_primitive.prim_part_eq {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : is_primitive p) : prim_part p = p := sorry\n\ntheorem is_unit_prim_part_C {R : Type u_1} [integral_domain R] [gcd_monoid R] (r : R) : is_unit (prim_part (coe_fn C r)) := sorry\n\ntheorem prim_part_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : prim_part p \u2223 p :=\n  dvd.intro_left (coe_fn C (content p)) (Eq.symm (eq_C_content_mul_prim_part p))\n\ntheorem gcd_content_eq_of_dvd_sub {R : Type u_1} [integral_domain R] [gcd_monoid R] {a : R} {p : polynomial R} {q : polynomial R} (h : coe_fn C a \u2223 p - q) : gcd a (content p) = gcd a (content q) := sorry\n\ntheorem content_mul_aux {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} : gcd (content (erase_lead (p * q))) (leading_coeff p) = gcd (content (erase_lead p * q)) (leading_coeff p) := sorry\n\n@[simp] theorem content_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} : content (p * q) = content p * content q := sorry\n\ntheorem is_primitive.mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hq : is_primitive q) : is_primitive (p * q) := sorry\n\n@[simp] theorem prim_part_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (h0 : p * q \u2260 0) : prim_part (p * q) = prim_part p * prim_part q := sorry\n\ntheorem is_primitive.is_primitive_of_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hdvd : q \u2223 p) : is_primitive q := sorry\n\ntheorem is_primitive.dvd_prim_part_iff_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hq : q \u2260 0) : p \u2223 prim_part q \u2194 p \u2223 q := sorry\n\ntheorem exists_primitive_lcm_of_is_primitive {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hq : is_primitive q) : \u2203 (r : polynomial R), is_primitive r \u2227 \u2200 (s : polynomial R), p \u2223 s \u2227 q \u2223 s \u2194 r \u2223 s := sorry\n\ntheorem dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hq : q \u2260 0) : p \u2223 q \u2194 content p \u2223 content q \u2227 prim_part p \u2223 prim_part q := sorry\n\nprotected instance gcd_monoid {R : Type u_1} [integral_domain R] [gcd_monoid R] : gcd_monoid (polynomial R) :=\n  gcd_monoid_of_exists_lcm sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/ring_theory/polynomial/content.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361628580401, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.7067578956089939}}
{"text": "import algebra.geom_sum\nimport data.rat.defs\nimport data.real.basic\n\n/-!\n# IMO 2013 Q5\n\nLet \u211a>\u2080 be the set of positive rational numbers. Let f: \u211a>\u2080 \u2192 \u211d be a function satisfying\nthe conditions\n\n  (1) f(x) * f(y) \u2265 f(x * y)\n  (2) f(x + y)    \u2265 f(x) + f(y)\n\nfor all x,y \u2208 \u211a>\u2080. Given that f(a) = a for some rational a > 1, prove that f(x) = x for\nall x \u2208 \u211a>\u2080.\n\n# Solution\n\nWe provide a direct translation of the solution found in\nhttps://www.imo-official.org/problems/IMO2013SL.pdf\n-/\n\nopen_locale big_operators\n\nlemma le_of_all_pow_lt_succ {x y : \u211d} (hx : 1 < x) (hy : 1 < y)\n  (h : \u2200 n : \u2115, 0 < n \u2192 x^n - 1 < y^n) :\n  x \u2264 y :=\nbegin\n  by_contra hxy,\n  push_neg at hxy,\n  have hxmy : 0 < x - y := sub_pos.mpr hxy,\n  have hn : \u2200 n : \u2115, 0 < n \u2192 (x - y) * (n : \u211d) \u2264 x^n - y^n,\n  { intros n hn,\n    have hterm : \u2200 i : \u2115, i \u2208 finset.range n \u2192 1 \u2264 x^i * y^(n - 1 - i),\n    { intros i hi,\n      have hx' : 1 \u2264 x ^ i := one_le_pow_of_one_le hx.le i,\n      have hy' : 1 \u2264 y ^ (n - 1 - i) := one_le_pow_of_one_le hy.le (n - 1 - i),\n      calc 1 \u2264 x^i             : hx'\n         ... = x^i * 1         : (mul_one _).symm\n         ... \u2264 x^i * y^(n-1-i) : mul_le_mul_of_nonneg_left hy' (zero_le_one.trans hx') },\n\n    calc (x - y) * (n : \u211d)\n            = (n : \u211d) * (x - y) : mul_comm _ _\n        ... = (\u2211 (i : \u2115) in finset.range n, (1 : \u211d)) * (x - y) :\n                                  by simp only [mul_one, finset.sum_const, nsmul_eq_mul,\n                                    finset.card_range]\n        ... \u2264 (\u2211 (i : \u2115) in finset.range n, x ^ i * y ^ (n - 1 - i)) * (x-y) :\n                                  (mul_le_mul_right hxmy).mpr (finset.sum_le_sum hterm)\n        ... = x^n - y^n         : geom_sum\u2082_mul x y n, },\n\n  -- Choose n larger than 1 / (x - y).\n  obtain \u27e8N, hN\u27e9 := exists_nat_gt (1 / (x - y)),\n  have hNp : 0 < N, { exact_mod_cast (one_div_pos.mpr hxmy).trans hN },\n\n  have := calc 1 = (x - y) * (1 / (x - y)) : by field_simp [ne_of_gt hxmy]\n             ... < (x - y) * N             : (mul_lt_mul_left hxmy).mpr hN\n             ... \u2264 x^N - y^N               : hn N hNp,\n  linarith [h N hNp]\nend\n\n/--\n Like le_of_all_pow_lt_succ, but with a weaker assumption for y.\n-/\nlemma le_of_all_pow_lt_succ' {x y : \u211d} (hx : 1 < x) (hy : 0 < y)\n  (h : \u2200 n : \u2115, 0 < n \u2192 x^n - 1 < y^n) :\n  x \u2264 y :=\nbegin\n  refine le_of_all_pow_lt_succ hx _ h,\n  by_contra hy'',\n  push_neg at hy'', -- hy'' : y \u2264 1.\n\n  -- Then there exists y' such that 0 < y \u2264 1 < y' < x.\n  let y' := (x + 1) / 2,\n  have h_y'_lt_x : y' < x,\n  { have hh : (x + 1)/2 < (x * 2) / 2, { linarith },\n    calc y' < (x * 2) / 2 : hh\n        ... = x           : by field_simp },\n  have h1_lt_y' : 1 < y',\n  { have hh' : 1 * 2 / 2 < (x + 1) / 2, { linarith },\n    calc 1 = 1 * 2 / 2 : by field_simp\n       ... < y'        : hh' },\n  have h_y_lt_y' : y < y' := hy''.trans_lt h1_lt_y',\n  have hh : \u2200 n, 0 < n \u2192 x^n - 1 < y'^n,\n  { intros n hn,\n    calc x^n - 1 < y^n  : h n hn\n            ...  \u2264 y'^n : pow_le_pow_of_le_left hy.le h_y_lt_y'.le n },\n  exact h_y'_lt_x.not_le (le_of_all_pow_lt_succ hx h1_lt_y' hh)\nend\n\nlemma f_pos_of_pos {f : \u211a \u2192 \u211d} {q : \u211a} (hq : 0 < q)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n  0 < f q :=\nbegin\n  have hfqn := calc f q.num = f (q * q.denom) : by rw \u2190rat.mul_denom_eq_num\n                        ... \u2264 f q * f q.denom : H1 q q.denom hq (nat.cast_pos.mpr q.pos),\n\n  -- Now we just need to show that `f q.num` and `f q.denom` are positive.\n  -- Then nlinarith will be able to close the goal.\n\n  have num_pos : 0 < q.num := rat.num_pos_iff_pos.mpr hq,\n  have hqna : (q.num.nat_abs : \u2124) = q.num := int.nat_abs_of_nonneg num_pos.le,\n  have hqfn' := calc (q.num : \u211d)\n            = ((q.num.nat_abs : \u2124) : \u211d) : congr_arg coe (eq.symm hqna)\n        ... \u2264 f q.num.nat_abs           : H4 q.num.nat_abs\n                                            (int.nat_abs_pos_of_ne_zero (ne_of_gt num_pos))\n        ... = f q.num                   : by rw [nat.cast_nat_abs, abs_of_nonneg num_pos.le],\n\n  have f_num_pos := calc (0 : \u211d) < q.num   : int.cast_pos.mpr num_pos\n                             ... \u2264 f q.num : hqfn',\n  have f_denom_pos := calc (0 : \u211d) < q.denom   : nat.cast_pos.mpr q.pos\n                               ... \u2264 f q.denom : H4 q.denom q.pos,\n  nlinarith\nend\n\nlemma fx_gt_xm1 {f : \u211a \u2192 \u211d} {x : \u211a} (hx : 1 \u2264 x)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n  (x - 1 : \u211d) < f x :=\nbegin\n  have hx0 :=\n    calc (x - 1 : \u211d)\n          < \u230ax\u230b\u208a   : by exact_mod_cast nat.sub_one_lt_floor x\n      ... \u2264 f \u230ax\u230b\u208a : H4 _ (nat.floor_pos.2 hx),\n\n  obtain h_eq | h_lt := (nat.floor_le $ zero_le_one.trans hx).eq_or_lt,\n  { rwa h_eq at hx0 },\n\n  calc (x - 1 : \u211d) < f \u230ax\u230b\u208a : hx0\n    ... < f (x - \u230ax\u230b\u208a) + f \u230ax\u230b\u208a : lt_add_of_pos_left _ (f_pos_of_pos (sub_pos.mpr h_lt) H1 H4)\n    ... \u2264 f (x - \u230ax\u230b\u208a + \u230ax\u230b\u208a)   : H2 _ _ (sub_pos.mpr h_lt) (nat.cast_pos.2 (nat.floor_pos.2 hx))\n    ... = f x                   : by rw sub_add_cancel\nend\n\nlemma pow_f_le_f_pow {f : \u211a \u2192 \u211d} {n : \u2115} (hn : 0 < n) {x : \u211a} (hx : 1 < x)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n) :\n  f (x^n) \u2264 (f x)^n :=\nbegin\n  induction n with pn hpn,\n  { exfalso, exact nat.lt_asymm hn hn },\n  cases pn,\n  { simp only [pow_one] },\n  have hpn' := hpn pn.succ_pos,\n  rw [pow_succ' x (pn + 1), pow_succ' (f x) (pn + 1)],\n  have hxp : 0 < x := zero_lt_one.trans hx,\n  calc f ((x ^ (pn+1)) * x)\n          \u2264 f (x ^ (pn+1)) * f x : H1 (x ^ (pn+1)) x (pow_pos hxp (pn+1)) hxp\n      ... \u2264 (f x) ^ (pn+1) * f x : (mul_le_mul_right (f_pos_of_pos hxp H1 H4)).mpr hpn'\nend\n\nlemma fixed_point_of_pos_nat_pow {f : \u211a \u2192 \u211d} {n : \u2115} (hn : 0 < n)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n)\n  (H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x)\n  {a : \u211a} (ha1 : 1 < a) (hae : f a = a) :\n  f (a^n) = a^n :=\nbegin\n  have hh0 : (a : \u211d) ^ n \u2264 f (a ^ n),\n  { exact_mod_cast H5 (a ^ n) (one_lt_pow ha1 hn.ne') },\n\n  have hh1 := calc f (a^n) \u2264 (f a)^n   : pow_f_le_f_pow hn ha1 H1 H4\n                       ... = (a : \u211d)^n : by rw \u2190 hae,\n\n  exact hh1.antisymm hh0\nend\n\nlemma fixed_point_of_gt_1 {f : \u211a \u2192 \u211d} {x : \u211a} (hx : 1 < x)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n  (H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n)\n  (H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x)\n  {a : \u211a} (ha1 : 1 < a) (hae : f a = a) :\n  f x = x :=\nbegin\n  -- Choose n such that 1 + x < a^n.\n  obtain \u27e8N, hN\u27e9 := pow_unbounded_of_one_lt (1 + x) ha1,\n  have h_big_enough : (1:\u211a) < a^N - x := lt_sub_iff_add_lt.mpr hN,\n\n  have h1 := calc (x : \u211d) + ((a^N - x) : \u211a)\n                        \u2264 f x + ((a^N - x) : \u211a) : add_le_add_right (H5 x hx) _\n                    ... \u2264 f x + f (a^N - x)     : add_le_add_left (H5 _ h_big_enough) _,\n\n  have hxp : 0 < x := zero_lt_one.trans hx,\n\n  have hNp : 0 < N,\n  { by_contra H, push_neg at H, rw [le_zero_iff.mp H] at hN, linarith },\n\n  have h2 := calc f x + f (a^N - x)\n                        \u2264 f (x + (a^N - x)) : H2 x (a^N - x) hxp (zero_lt_one.trans h_big_enough)\n                    ... = f (a^N)           : by ring_nf\n                    ... = a^N               : fixed_point_of_pos_nat_pow hNp H1 H4 H5 ha1 hae\n                    ... = x + (a^N - x)     : by ring,\n\n  have heq := h1.antisymm (by exact_mod_cast h2),\n  linarith [H5 x hx, H5 _ h_big_enough]\nend\n\ntheorem imo2013_q5\n  (f : \u211a \u2192 \u211d)\n  (H1 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f (x * y) \u2264 f x * f y)\n  (H2 : \u2200 x y, 0 < x \u2192 0 < y \u2192 f x + f y \u2264 f (x + y))\n  (H_fixed_point : \u2203 a, 1 < a \u2227 f a = a) :\n  \u2200 x, 0 < x \u2192 f x = x :=\nbegin\n  obtain \u27e8a, ha1, hae\u27e9 := H_fixed_point,\n  have H3 : \u2200 x : \u211a, 0 < x \u2192 \u2200 n : \u2115, 0 < n \u2192 \u2191n * f x \u2264 f (n * x),\n  { intros x hx n hn,\n    cases n,\n    { exfalso, exact nat.lt_asymm hn hn },\n    induction n with pn hpn,\n    { simp only [one_mul, nat.cast_one] },\n    calc    \u2191(pn + 2) * f x\n          = (\u2191pn + 1 + 1) * f x            : by norm_cast\n      ... = ((pn : \u211d) + 1) * f x + 1 * f x : add_mul (\u2191pn + 1) 1 (f x)\n      ... = (\u2191pn + 1) * f x + f x          : by rw one_mul\n      ... \u2264 f ((\u2191pn.succ) * x) + f x       : by exact_mod_cast add_le_add_right\n                                                  (hpn pn.succ_pos) (f x)\n      ... \u2264 f ((\u2191pn + 1) * x + x)          : by exact_mod_cast H2 _ _\n                                                  (mul_pos pn.cast_add_one_pos hx) hx\n      ... = f ((\u2191pn + 1) * x + 1 * x)      : by rw one_mul\n      ... = f ((\u2191pn + 1 + 1) * x)          : congr_arg f (add_mul (\u2191pn + 1) 1 x).symm\n      ... = f (\u2191(pn + 2) * x)              : by norm_cast },\n  have H4 : \u2200 n : \u2115, 0 < n \u2192 (n : \u211d) \u2264 f n,\n  { intros n hn,\n    have hf1 : 1 \u2264 f 1,\n    { have a_pos : (0 : \u211d) < a := rat.cast_pos.mpr (zero_lt_one.trans ha1),\n      suffices : \u2191a * 1 \u2264 \u2191a * f 1, from (mul_le_mul_left a_pos).mp this,\n      calc \u2191a * 1 = \u2191a        : mul_one \u2191a\n              ... = f a       : hae.symm\n              ... = f (a * 1) : by rw mul_one\n              ... \u2264 f a * f 1 : (H1 a 1) (zero_lt_one.trans ha1) zero_lt_one\n              ... = \u2191a * f 1  : by rw hae },\n\n    calc (n : \u211d) = (n : \u211d) * 1   : (mul_one _).symm\n             ... \u2264 (n : \u211d) * f 1 : (mul_le_mul_left (nat.cast_pos.mpr hn)).mpr hf1\n             ... \u2264 f (n * 1)     : H3 1 zero_lt_one n hn\n             ... = f n           : by rw mul_one },\n\n  have H5 : \u2200 x : \u211a, 1 < x \u2192 (x : \u211d) \u2264 f x,\n  { intros x hx,\n    have hxnm1 : \u2200 n : \u2115, 0 < n \u2192 (x : \u211d)^n - 1 < (f x)^n,\n    { intros n hn,\n      calc (x : \u211d)^n - 1 < f (x^n) : by exact_mod_cast fx_gt_xm1 (one_le_pow_of_one_le hx.le n)\n                                          H1 H2 H4\n                     ... \u2264 (f x)^n : pow_f_le_f_pow hn hx H1 H4 },\n    have hx' : 1 < (x : \u211d) := by exact_mod_cast hx,\n    have hxp : 0 < x := zero_lt_one.trans hx,\n    exact le_of_all_pow_lt_succ' hx' (f_pos_of_pos hxp H1 H4) hxnm1 },\n\n  have h_f_commutes_with_pos_nat_mul : \u2200 n : \u2115, 0 < n \u2192 \u2200 x : \u211a, 0 < x \u2192 f (n * x) = n * f x,\n  { intros n hn x hx,\n    have h2 : f (n * x) \u2264 n * f x,\n    { cases n,\n      { exfalso, exact nat.lt_asymm hn hn },\n      cases n,\n      { simp only [one_mul, nat.cast_one] },\n      have hfneq : f (n.succ.succ) = n.succ.succ,\n      { have := fixed_point_of_gt_1\n                  (nat.one_lt_cast.mpr (nat.succ_lt_succ n.succ_pos)) H1 H2 H4 H5 ha1 hae,\n        rwa (rat.cast_coe_nat n.succ.succ) at this },\n      rw \u2190 hfneq,\n      exact H1 (n.succ.succ : \u211a) x (nat.cast_pos.mpr hn) hx },\n    exact h2.antisymm (H3 x hx n hn) },\n\n  -- For the final calculation, we expand x as (2*x.num) / (2*x.denom), because\n  -- we need the top of the fraction to be strictly greater than 1 in order\n  -- to apply fixed_point_of_gt_1.\n  intros x hx,\n  let x2denom := 2 * x.denom,\n  let x2num := 2 * x.num,\n\n  have hx2pos : 0 < 2 * x.denom := by linarith[x.pos],\n  have hxcnez   : (x.denom : \u211a) \u2260 (0 : \u211a) := ne_of_gt (nat.cast_pos.mpr x.pos),\n  have hx2cnezr : (x2denom : \u211d) \u2260 (0 : \u211d) := nat.cast_ne_zero.mpr (ne_of_gt hx2pos),\n\n  have hrat_expand2 := calc x = x.num / x.denom : by exact_mod_cast rat.num_denom.symm\n                          ... = x2num / x2denom : by { field_simp[-rat.num_div_denom], ring},\n\n  have h_denom_times_fx :=\n    calc (x2denom : \u211d) * f x = f (x2denom * x)                 : (h_f_commutes_with_pos_nat_mul\n                                                                    x2denom hx2pos x hx).symm\n                         ... = f (x2denom * (x2num / x2denom)) : by rw hrat_expand2\n                         ... = f x2num                         : by { congr, field_simp, ring },\n\n  have h_fx2num_fixed : f x2num = x2num,\n  { have hx2num_gt_one : (1 : \u211a) < (2 * x.num : \u2124),\n    { norm_cast, linarith [rat.num_pos_iff_pos.mpr hx] },\n    have hh := fixed_point_of_gt_1 hx2num_gt_one H1 H2 H4 H5 ha1 hae,\n    rwa (rat.cast_coe_int x2num) at hh },\n\n  calc f x = f x * 1                                 : (mul_one (f x)).symm\n       ... = f x * (x2denom / x2denom)               : by rw \u2190(div_self hx2cnezr)\n       ... = (f x * x2denom) / x2denom               : mul_div_assoc' (f x) _ _\n       ... = (x2denom * f x) / x2denom               : by rw mul_comm\n       ... = f x2num / x2denom                       : by rw h_denom_times_fx\n       ... = x2num / x2denom                         : by rw h_fx2num_fixed\n       ... = (((x2num : \u211a) / (x2denom : \u211a) : \u211a) : \u211d) : by norm_cast\n       ... = x                                       : by rw \u2190hrat_expand2\nend\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/imo2013_q5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7067578937646344}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_478\n  (b h v : \u211d)\n  (h\u2080 : 0 < b \u2227 0 < h \u2227 0 < v)\n  (h\u2081 : v = 1 / 3 * (b * h))\n  (h\u2082 : b = 30)\n  (h\u2083 : h = 13 / 2) :\n  v = 65 :=\nbegin\n  rw [h\u2082, h\u2083] at h\u2081,\n  rw h\u2081,\n  norm_num,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p478.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7745833737577159, "lm_q1q2_score": 0.7067578776764064}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n-/\nimport tactic.ring\nimport data.pnat.prime\n\n/-!\n# Euclidean algorithm for \u2115\n\nThis file sets up a version of the Euclidean algorithm that only works with natural numbers.\nGiven `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold:\n* `a = (w + x) d`\n* `b = (y + z) d`\n* `w * z = x * y + 1`\n`d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime.\n\nThis story is closely related to the structure of SL\u2082(\u2115) (as a free monoid on two generators) and\nthe theory of continued fractions.\n\n## Main declarations\n\n* `xgcd_type`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp`\n  `zp`, `ap`, `bp` are the variables getting changed through the algorithm.\n* `is_special`: States `wp * zp = x * y + 1`\n* `is_reduced`: States `ap = a \u2227 bp = b`\n\n## Notes\n\nSee `nat.xgcd` for a very similar algorithm allowing values in `\u2124`.\n-/\n\nopen nat\n\nnamespace pnat\n\n/-- A term of xgcd_type is a system of six naturals.  They should\n be thought of as representing the matrix\n [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]\n together with the vector [a, b] = [ap + 1, bp + 1].\n-/\n@[derive inhabited]\nstructure xgcd_type :=\n(wp x y zp ap bp : \u2115)\n\nnamespace xgcd_type\n\nvariable (u : xgcd_type)\n\ninstance : has_sizeof xgcd_type := \u27e8\u03bb u, u.bp\u27e9\n\n/-- The has_repr instance converts terms to strings in a way that\n reflects the matrix/vector interpretation as above. -/\ninstance : has_repr xgcd_type :=\n\u27e8\u03bb u, \"[[[\" ++ (repr (u.wp + 1)) ++ \", \" ++ (repr u.x) ++\n      \"], [\" ++ (repr u.y) ++ \", \" ++ (repr (u.zp + 1)) ++ \"]], [\" ++\n      (repr (u.ap + 1)) ++ \", \" ++ (repr (u.bp + 1)) ++ \"]]\"\u27e9\n\ndef mk' (w : \u2115+) (x : \u2115) (y : \u2115) (z : \u2115+) (a : \u2115+) (b : \u2115+) : xgcd_type :=\nmk w.val.pred x y z.val.pred a.val.pred b.val.pred\n\ndef w : \u2115+ := succ_pnat u.wp\ndef z : \u2115+ := succ_pnat u.zp\ndef a : \u2115+ := succ_pnat u.ap\ndef b : \u2115+ := succ_pnat u.bp\ndef r : \u2115 := (u.ap + 1) % (u.bp + 1)\ndef q : \u2115 := (u.ap + 1) / (u.bp + 1)\ndef qp : \u2115 := u.q - 1\n\n/-- The map v gives the product of the matrix\n [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]\n and the vector [a, b] = [ap + 1, bp + 1].  The map\n vp gives [sp, tp] such that v = [sp + 1, tp + 1].\n-/\ndef vp : \u2115 \u00d7 \u2115 :=\n\u27e8 u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp,\n  u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp \u27e9\n\ndef v : \u2115 \u00d7 \u2115 := \u27e8u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.b\u27e9\ndef succ\u2082 (t : \u2115 \u00d7 \u2115) : \u2115 \u00d7 \u2115 := \u27e8t.1.succ, t.2.succ\u27e9\n\ntheorem v_eq_succ_vp : u.v = succ\u2082 u.vp :=\nby { ext; dsimp [v, vp, w, z, a, b, succ\u2082];\n     repeat { rw [nat.succ_eq_add_one] }; ring }\n\n/-- is_special holds if the matrix has determinant one. -/\ndef is_special : Prop := u.wp + u.zp + u.wp * u.zp = u.x * u.y\ndef is_special' : Prop := u.w * u.z = succ_pnat (u.x * u.y)\n\ntheorem is_special_iff : u.is_special \u2194 u.is_special' :=\nbegin\n  dsimp [is_special, is_special'],\n  split; intro h,\n  { apply eq, dsimp [w, z, succ_pnat], rw [\u2190 h],\n    repeat { rw [nat.succ_eq_add_one] }, ring },\n  { apply nat.succ.inj,\n    replace h := congr_arg (coe : \u2115+ \u2192 \u2115) h,\n    rw [mul_coe, w, z] at h,\n    repeat { rw [succ_pnat_coe, nat.succ_eq_add_one] at h },\n    repeat { rw [nat.succ_eq_add_one] }, rw [\u2190 h], ring }\nend\n\n/-- is_reduced holds if the two entries in the vector are the\n same.  The reduction algorithm will produce a system with this\n property, whose product vector is the same as for the original\n system. -/\ndef is_reduced : Prop := u.ap = u.bp\ndef is_reduced' : Prop := u.a = u.b\n\ntheorem is_reduced_iff : u.is_reduced \u2194 u.is_reduced' :=\n\u27e8 congr_arg succ_pnat, succ_pnat_inj \u27e9\n\ndef flip : xgcd_type :=\n{ wp := u.zp, x := u.y, y := u.x, zp := u.wp, ap := u.bp, bp := u.ap }\n\n@[simp] theorem flip_w : (flip u).w = u.z := rfl\n@[simp] theorem flip_x : (flip u).x = u.y := rfl\n@[simp] theorem flip_y : (flip u).y = u.x := rfl\n@[simp] theorem flip_z : (flip u).z = u.w := rfl\n@[simp] theorem flip_a : (flip u).a = u.b := rfl\n@[simp] theorem flip_b : (flip u).b = u.a := rfl\n\ntheorem flip_is_reduced : (flip u).is_reduced \u2194 u.is_reduced :=\nby { dsimp [is_reduced, flip], split; intro h; exact h.symm }\n\ntheorem flip_is_special : (flip u).is_special \u2194 u.is_special :=\nby { dsimp [is_special, flip], rw[mul_comm u.x, mul_comm u.zp, add_comm u.zp] }\n\ntheorem flip_v : (flip u).v = (u.v).swap :=\nby { dsimp [v], ext, { simp only, ring }, { simp only, ring } }\n\n/-- Properties of division with remainder for a / b.  -/\ntheorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 :=\nnat.mod_add_div (u.ap + 1) (u.bp + 1)\n\ntheorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 :=\nbegin\n  by_cases hq : u.q = 0,\n  { let h := u.rq_eq, rw [hr, hq, mul_zero, add_zero] at h, cases h },\n  { exact (nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero hq)).symm }\nend\n\n/-- The following function provides the starting point for\n our algorithm.  We will apply an iterative reduction process\n to it, which will produce a system satisfying is_reduced.\n The gcd can be read off from this final system.\n-/\ndef start (a b : \u2115+) : xgcd_type := \u27e80, 0, 0, 0, a - 1, b - 1\u27e9\n\ntheorem start_is_special (a b : \u2115+) : (start a b).is_special :=\nby { dsimp [start, is_special], refl }\n\ntheorem start_v (a b : \u2115+) : (start a b).v = \u27e8a, b\u27e9 :=\nbegin\n  dsimp [start, v, xgcd_type.a, xgcd_type.b, w, z],\n  rw [one_mul, one_mul, zero_mul, zero_mul, zero_add, add_zero],\n  rw [\u2190 nat.pred_eq_sub_one, \u2190 nat.pred_eq_sub_one],\n  rw [nat.succ_pred_eq_of_pos a.pos, nat.succ_pred_eq_of_pos b.pos]\nend\n\ndef finish : xgcd_type :=\nxgcd_type.mk u.wp ((u.wp + 1) * u.qp + u.x) u.y (u.y * u.qp + u.zp) u.bp u.bp\n\ntheorem finish_is_reduced : u.finish.is_reduced :=\nby { dsimp [is_reduced], refl }\n\ntheorem finish_is_special (hs : u.is_special) : u.finish.is_special :=\nbegin\n  dsimp [is_special, finish] at hs \u22a2,\n  rw [add_mul _ _ u.y, add_comm _ (u.x * u.y), \u2190 hs],\n  ring\nend\n\ntheorem finish_v (hr : u.r = 0) : u.finish.v = u.v :=\nbegin\n  let ha : u.r + u.b * u.q = u.a := u.rq_eq,\n  rw [hr, zero_add] at ha,\n  ext,\n  { change (u.wp + 1) * u.b + ((u.wp + 1) * u.qp + u.x) * u.b = u.w * u.a + u.x * u.b,\n    have : u.wp + 1 = u.w := rfl, rw [this, \u2190 ha, u.qp_eq hr], ring },\n  { change u.y * u.b + (u.y * u.qp + u.z) * u.b = u.y * u.a + u.z * u.b,\n    rw [\u2190 ha, u.qp_eq hr], ring }\nend\n\n/-- This is the main reduction step, which is used when u.r \u2260 0, or\n equivalently b does not divide a. -/\ndef step : xgcd_type :=\nxgcd_type.mk (u.y * u.q + u.zp) u.y ((u.wp + 1) * u.q + u.x) u.wp u.bp (u.r - 1)\n\n/-- We will apply the above step recursively.  The following result\n is used to ensure that the process terminates. -/\ntheorem step_wf (hr : u.r \u2260 0) : sizeof u.step < sizeof u :=\nbegin\n  change u.r - 1 < u.bp,\n  have h\u2080 : (u.r - 1) + 1 = u.r := nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero hr),\n  have h\u2081 : u.r < u.bp + 1 := nat.mod_lt (u.ap + 1) u.bp.succ_pos,\n  rw[\u2190 h\u2080] at h\u2081,\n  exact lt_of_succ_lt_succ h\u2081,\nend\n\ntheorem step_is_special (hs : u.is_special) : u.step.is_special :=\nbegin\n  dsimp [is_special, step] at hs \u22a2,\n  rw [mul_add, mul_comm u.y u.x, \u2190 hs],\n  ring\nend\n\n/-- The reduction step does not change the product vector. -/\ntheorem step_v (hr : u.r \u2260 0) : u.step.v = (u.v).swap :=\nbegin\n  let ha : u.r + u.b * u.q = u.a := u.rq_eq,\n  let hr : (u.r - 1) + 1 = u.r :=\n    (add_comm _ 1).trans (add_tsub_cancel_of_le (nat.pos_of_ne_zero hr)),\n  ext,\n  { change ((u.y * u.q + u.z) * u.b + u.y * (u.r - 1 + 1) : \u2115) = u.y * u.a + u.z * u.b,\n    rw [\u2190 ha, hr], ring },\n  { change ((u.w * u.q + u.x) * u.b + u.w * (u.r - 1 + 1) : \u2115) = u.w * u.a + u.x * u.b,\n    rw [\u2190 ha, hr], ring }\nend\n\n/-- We can now define the full reduction function, which applies\n step as long as possible, and then applies finish. Note that the\n \"have\" statement puts a fact in the local context, and the\n equation compiler uses this fact to help construct the full\n definition in terms of well-founded recursion.  The same fact\n needs to be introduced in all the inductive proofs of properties\n given below. -/\ndef reduce : xgcd_type \u2192 xgcd_type\n| u := dite (u.r = 0)\n    (\u03bb h, u.finish)\n    (\u03bb h, have sizeof u.step < sizeof u, from u.step_wf h,\n     flip (reduce u.step))\n\ntheorem reduce_a {u : xgcd_type} (h : u.r = 0) :\nu.reduce = u.finish := by { rw [reduce], simp only, rw [if_pos h] }\n\ntheorem reduce_b {u : xgcd_type} (h : u.r \u2260 0) :\nu.reduce = u.step.reduce.flip := by { rw [reduce], simp only, rw [if_neg h, step] }\n\ntheorem reduce_reduced : \u2200 (u : xgcd_type), u.reduce.is_reduced\n| u := dite (u.r = 0) (\u03bb h, by { rw [reduce_a h], exact u.finish_is_reduced })\n    (\u03bb h,  have sizeof u.step < sizeof u, from u.step_wf h,\n     by { rw [reduce_b h, flip_is_reduced], apply reduce_reduced })\n\ntheorem reduce_reduced' (u : xgcd_type) : u.reduce.is_reduced' :=\n(is_reduced_iff _).mp u.reduce_reduced\n\ntheorem reduce_special : \u2200 (u : xgcd_type), u.is_special \u2192 u.reduce.is_special\n| u := dite (u.r = 0)\n    (\u03bb h hs, by { rw [reduce_a h], exact u.finish_is_special hs })\n    (\u03bb h hs, have sizeof u.step < sizeof u, from u.step_wf h,\n     by { rw [reduce_b h],\n          exact (flip_is_special _).mpr (reduce_special _ (u.step_is_special hs)) })\n\ntheorem reduce_special' (u : xgcd_type) (hs : u.is_special) : u.reduce.is_special' :=\n(is_special_iff _).mp (u.reduce_special hs)\n\ntheorem reduce_v : \u2200 (u : xgcd_type), u.reduce.v = u.v\n| u := dite (u.r = 0)\n (\u03bb h, by {rw[reduce_a h, finish_v u h]})\n (\u03bb h, have sizeof u.step < sizeof u, from u.step_wf h,\n       by { rw[reduce_b h, flip_v, reduce_v (step u), step_v u h, prod.swap_swap] })\n\nend xgcd_type\n\nsection gcd\n\nvariables (a b : \u2115+)\n\ndef xgcd : xgcd_type := (xgcd_type.start a b).reduce\n\ndef gcd_d : \u2115+ := (xgcd a b).a\ndef gcd_w : \u2115+ := (xgcd a b).w\ndef gcd_x : \u2115  := (xgcd a b).x\ndef gcd_y : \u2115  := (xgcd a b).y\ndef gcd_z : \u2115+ := (xgcd a b).z\n\ndef gcd_a' : \u2115+ := succ_pnat ((xgcd a b).wp + (xgcd a b).x)\ndef gcd_b' : \u2115+ := succ_pnat ((xgcd a b).y + (xgcd a b).zp)\n\ntheorem gcd_a'_coe : ((gcd_a' a b) : \u2115) = (gcd_w a b) + (gcd_x a b) :=\nby { dsimp [gcd_a', gcd_x, gcd_w, xgcd_type.w],\n     rw [nat.succ_eq_add_one, nat.succ_eq_add_one, add_right_comm] }\n\ntheorem gcd_b'_coe : ((gcd_b' a b) : \u2115) = (gcd_y a b) + (gcd_z a b) :=\nby { dsimp [gcd_b', gcd_y, gcd_z, xgcd_type.z],\n     rw [nat.succ_eq_add_one, nat.succ_eq_add_one, add_assoc] }\n\ntheorem gcd_props :\n let d := gcd_d a b,\n  w := gcd_w a b, x := gcd_x a b, y := gcd_y a b, z := gcd_z a b,\n  a' := gcd_a' a b, b' := gcd_b' a b in\n (w * z = succ_pnat (x * y) \u2227\n  (a = a' * d) \u2227 (b = b' * d) \u2227\n  z * a' = succ_pnat (x * b') \u2227 w * b' = succ_pnat (y * a') \u2227\n  (z * a : \u2115) = x * b + d \u2227 (w * b : \u2115) = y * a + d\n ) :=\nbegin\n  intros,\n  let u := (xgcd_type.start a b),\n  let ur := u.reduce,\n  have ha : d = ur.a := rfl,\n  have hb : d = ur.b := u.reduce_reduced',\n  have ha' : (a' : \u2115) = w + x := gcd_a'_coe a b,\n  have hb' : (b' : \u2115) = y + z := gcd_b'_coe a b,\n  have hdet : w * z = succ_pnat (x * y) := u.reduce_special' rfl,\n  split, exact hdet,\n  have hdet' : ((w * z) : \u2115) = x * y + 1 :=\n    by { rw [\u2190 mul_coe, hdet, succ_pnat_coe] },\n  have huv : u.v = \u27e8a, b\u27e9 := (xgcd_type.start_v a b),\n  let hv : prod.mk (w * d + x * ur.b : \u2115) (y * d + z * ur.b : \u2115) = \u27e8a, b\u27e9 :=\n   u.reduce_v.trans (xgcd_type.start_v a b),\n  rw [\u2190 hb, \u2190 add_mul, \u2190 add_mul, \u2190 ha', \u2190 hb'] at hv,\n  have ha'' : (a : \u2115) = a' * d := (congr_arg prod.fst hv).symm,\n  have hb'' : (b : \u2115) = b' * d := (congr_arg prod.snd hv).symm,\n  split, exact eq ha'', split, exact eq hb'',\n  have hza' : (z * a' : \u2115) = x * b' + 1,\n  by { rw [ha', hb', mul_add, mul_add, mul_comm (z : \u2115), hdet'], ring },\n  have hwb' : (w * b' : \u2115) = y * a' + 1,\n  by { rw [ha', hb', mul_add, mul_add, hdet'], ring },\n  split,\n  { apply eq, rw [succ_pnat_coe, nat.succ_eq_add_one, mul_coe, hza'] },\n  split,\n  { apply eq, rw [succ_pnat_coe, nat.succ_eq_add_one, mul_coe, hwb'] },\n  rw [ha'', hb''], repeat { rw [\u2190 mul_assoc] }, rw [hza', hwb'],\n  split; ring,\nend\n\ntheorem gcd_eq : gcd_d a b = gcd a b :=\nbegin\n  rcases gcd_props a b with \u27e8h\u2080, h\u2081, h\u2082, h\u2083, h\u2084, h\u2085, h\u2086\u27e9,\n  apply dvd_antisymm,\n  { apply dvd_gcd,\n    exact dvd.intro (gcd_a' a b) (h\u2081.trans (mul_comm _ _)).symm,\n    exact dvd.intro (gcd_b' a b) (h\u2082.trans (mul_comm _ _)).symm},\n  { have h\u2087 : (gcd a b : \u2115) \u2223 (gcd_z a b) * a :=\n      (nat.gcd_dvd_left a b).trans (dvd_mul_left _ _),\n    have h\u2088 : (gcd a b : \u2115) \u2223 (gcd_x a b) * b :=\n      (nat.gcd_dvd_right a b).trans (dvd_mul_left _ _),\n    rw[h\u2085] at h\u2087, rw dvd_iff,\n    exact (nat.dvd_add_iff_right h\u2088).mpr h\u2087,}\nend\n\ntheorem gcd_det_eq :\n  (gcd_w a b) * (gcd_z a b) = succ_pnat ((gcd_x a b) * (gcd_y a b)) :=\n(gcd_props a b).1\n\n\n\ntheorem gcd_b_eq : b = (gcd_b' a b) * (gcd a b) :=\n(gcd_eq a b) \u25b8 (gcd_props a b).2.2.1\n\ntheorem gcd_rel_left' :\n  (gcd_z a b) * (gcd_a' a b) = succ_pnat ((gcd_x a b) * (gcd_b' a b)) :=\n(gcd_props a b).2.2.2.1\n\ntheorem gcd_rel_right' :\n  (gcd_w a b) * (gcd_b' a b) = succ_pnat ((gcd_y a b) * (gcd_a' a b)) :=\n(gcd_props a b).2.2.2.2.1\n\ntheorem gcd_rel_left :\n  ((gcd_z a b) * a : \u2115) = (gcd_x a b) * b + (gcd a b) :=\n(gcd_eq a b) \u25b8 (gcd_props a b).2.2.2.2.2.1\n\ntheorem gcd_rel_right :\n  ((gcd_w a b) * b : \u2115) = (gcd_y a b) * a + (gcd a b) :=\n(gcd_eq a b) \u25b8 (gcd_props a b).2.2.2.2.2.2\n\nend gcd\nend pnat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/pnat/xgcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.706665626295336}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\nPorted by: Scott Morrison\n-/\nimport Mathlib.Data.HashMap\nimport Mathlib.Tactic.Linarith.Verification\nimport Mathlib.Tactic.Linarith.Preprocessing\n\n/-!\n# `linarith`: solving linear arithmetic goals\n\n`linarith` is a tactic for solving goals with linear arithmetic.\n\nSuppose we have a set of hypotheses in `n` variables\n`S = {a\u2081x\u2081 + a\u2082x\u2082 + ... + a\u2099x\u2099 R b\u2081x\u2081 + b\u2082x\u2082 + ... + b\u2099x\u2099}`,\nwhere `R \u2208 {<, \u2264, =, \u2265, >}`.\nOur goal is to determine if the inequalities in `S` are jointly satisfiable, that is, if there is\nan assignment of values to `x\u2081, ..., x\u2099` such that every inequality in `S` is true.\n\nSpecifically, we aim to show that they are *not* satisfiable. This amounts to proving a\ncontradiction. If our goal is also a linear inequality, we negate it and move it to a hypothesis\nbefore trying to prove `false`.\n\nWhen the inequalities are over a dense linear order, `linarith` is a decision procedure: it will\nprove `false` if and only if the inequalities are unsatisfiable. `linarith` will also run on some\ntypes like `\u2124` that are not dense orders, but it will fail to prove `false` on some unsatisfiable\nproblems. It will run over concrete types like `\u2115`, `\u211a`, and `\u211d`, as well as abstract types that\nare instances of `LinearOrderedCommRing`.\n\n## Algorithm sketch\n\nFirst, the inequalities in the set `S` are rearranged into the form `t\u1d62 R\u1d62 0`, where\n`R\u1d62 \u2208 {<, \u2264, =}` and each `t\u1d62` is of the form `\u2211 c\u2c7cx\u2c7c`.\n\n`linarith` uses an untrusted oracle to search for a certificate of unsatisfiability.\nThe oracle searches for a list of natural number coefficients `k\u1d62` such that `\u2211 k\u1d62t\u1d62 = 0`, where for\nat least one `i`, `k\u1d62 > 0` and `R\u1d62 = <`.\n\nGiven a list of such coefficients, `linarith` verifies that `\u2211 k\u1d62t\u1d62 = 0` using a normalization\ntactic such as `ring`. It proves that `\u2211 k\u1d62t\u1d62 < 0` by transitivity, since each component of the sum\nis either equal to, less than or equal to, or less than zero by hypothesis. This produces a\ncontradiction.\n\n## Preprocessing\n\n`linarith` does some basic preprocessing before running. Most relevantly, inequalities over natural\nnumbers are cast into inequalities about integers, and rational division by numerals is canceled\ninto multiplication. We do this so that we can guarantee the coefficients in the certificate are\nnatural numbers, which allows the tactic to solve goals over types that are not fields.\n\nPreprocessors are allowed to branch, that is, to case split on disjunctions. `linarith` will succeed\noverall if it succeeds in all cases. This leads to exponential blowup in the number of `linarith`\ncalls, and should be used sparingly. The default preprocessor set does not include case splits.\n\n## Fourier-Motzkin elimination\n\nThe oracle implemented to search for certificates uses Fourier-Motzkin variable elimination.\nThis technique transorms a set of inequalities in `n` variables to an equisatisfiable set in `n - 1`\nvariables. Once all variables have been eliminated, we conclude that the original set was\nunsatisfiable iff the comparison `0 < 0` is in the resulting set.\n\nWhile performing this elimination, we track the history of each derived comparison. This allows us\nto represent any comparison at any step as a positive combination of comparisons from the original\nset. In particular, if we derive `0 < 0`, we can find our desired list of coefficients\nby counting how many copies of each original comparison appear in the history.\n\n## Implementation details\n\n`linarith` homogenizes numerical constants: the expression `1` is treated as a variable `t\u2080`.\n\nOften `linarith` is called on goals that have comparison hypotheses over multiple types. This\ncreates multiple `linarith` problems, each of which is handled separately; the goal is solved as\nsoon as one problem is found to be contradictory.\n\nDisequality hypotheses `t \u2260 0` do not fit in this pattern. `linarith` will attempt to prove equality\ngoals by splitting them into two weak inequalities and running twice. But it does not split\ndisequality hypotheses, since this would lead to a number of runs exponential in the number of\ndisequalities in the context.\n\nThe Fourier-Motzkin oracle is very modular. It can easily be replaced with another function of type\n`certificateOracle := List Comp \u2192 \u2115 \u2192 TacticM ((Std.HashMap \u2115 \u2115))`,\nwhich takes a list of comparisons and the largest variable\nindex appearing in those comparisons, and returns a map from comparison indices to coefficients.\nAn alternate oracle can be specified in the `LinarithConfig` object.\n\n-- TODO Not implemented yet\nA variant, `nlinarith`, adds an extra preprocessing step to handle some basic nonlinear goals.\nThere is a hook in the `linarith_config` configuration object to add custom preprocessing routines.\n\nThe certificate checking step is *not* by reflection. `linarith` converts the certificate into a\nproof term of type `false`.\n\nSome of the behavior of `linarith` can be inspected with the option\n`set_option trace.linarith true`.\nBecause the variable elimination happens outside the tactic monad, we cannot trace intermediate\nsteps there.\n\n## File structure\n\nThe components of `linarith` are spread between a number of files for the sake of organization.\n\n* `Lemmas.lean` contains proofs of some arithmetic lemmas that are used in preprocessing and in\n  verification.\n* `Datatypes.lean` contains data structures that are used across multiple files, along with some\n  useful auxiliary functions.\n* `Preprocessing.lean` contains functions used at the beginning of the tactic to transform\n  hypotheses into a shape suitable for the main routine.\n* `Parsing.lean` contains functions used to compute the linear structure of an expression.\n* `Elimination.lean` contains the Fourier-Motzkin elimination routine.\n* `Verification.lean` contains the certificate checking functions that produce a proof of `false`.\n* `Frontend.lean` contains the control methods and user-facing components of the tactic.\n\n## Tags\n\nlinarith, nlinarith, lra, nra, Fourier-Motzkin, linear arithmetic, linear programming\n-/\n\nopen Lean Elab Tactic Meta\nopen Std\n\n\nnamespace Linarith\n\n/-! ### Control -/\n\n/--\nIf `e` is a comparison `a R b` or the negation of a comparison `\u00ac a R b`, found in the target,\n`getContrLemma e` returns the name of a lemma that will change the goal to an\nimplication, along with the type of `a` and `b`.\n\nFor example, if `e` is `(a : \u2115) < b`, returns ``(`lt_of_not_ge, \u2115)``.\n-/\ndef getContrLemma (e : Expr) : Option (Name \u00d7 Expr) :=\n  match e.getAppFnArgs with\n  | (``LT.lt, #[t, _, _, _]) => (``lt_of_not_ge, t)\n  | (``LE.le, #[t, _, _, _]) => (``le_of_not_gt, t)\n  | (``Eq, #[t, _, _]) => (``eq_of_not_lt_of_not_gt, t)\n  | (``Ne, #[t, _, _]) => (``Not.intro, t)\n  | (``GE.ge, #[t, _, _, _]) => (``le_of_not_gt, t)\n  | (``GT.gt, #[t, _, _, _]) => (``lt_of_not_ge, t)\n  | (``Not, #[e']) => match e'.getAppFnArgs with\n    | (``LT.lt, #[t, _, _, _]) => (``Not.intro, t)\n    | (``LE.le, #[t, _, _, _]) => (``Not.intro, t)\n    | (``Eq, #[t, _, _]) => (``Not.intro, t)\n    | (``GE.ge, #[t, _, _, _]) => (``Not.intro, t)\n    | (``GT.gt, #[t, _, _, _]) => (``Not.intro, t)\n    | _ => none\n  | _ => none\n\n/--\n`applyContrLemma` inspects the target to see if it can be moved to a hypothesis by negation.\nFor example, a goal `\u22a2 a \u2264 b` can become `a > b \u22a2 false`.\nIf this is the case, it applies the appropriate lemma and introduces the new hypothesis.\nIt returns the type of the terms in the comparison (e.g. the type of `a` and `b` above) and the\nnewly introduced local constant.\nOtherwise returns `none`.\n-/\ndef applyContrLemma (g : MVarId) : MetaM (Option (Expr \u00d7 Expr) \u00d7 MVarId) := do\n  match getContrLemma (\u2190 withReducible g.getType') with\n  | some (nm, tp) => do\n      let [g] \u2190 g.apply (\u2190 mkConst' nm) | failure\n      let (f, g) \u2190 g.intro1P\n      return (some (tp, .fvar f), g)\n  | none => return (none, g)\n\n/-- A map of keys to values, where the keys are `Expr` up to defeq and one key can be\nassociated to multiple values. -/\nabbrev ExprMultiMap \u03b1 := Array (Expr \u00d7 List \u03b1)\n\n/-- Retrieves the list of values at a key, as well as the index of the key for later modification.\n(If the key is not in the map it returns `self.size` as the index.) -/\ndef ExprMultiMap.find (self : ExprMultiMap \u03b1) (k : Expr) : MetaM (Nat \u00d7 List \u03b1) := do\n  for h : i in [:self.size] do\n    let (k', vs) := self[i]'h.2\n    if \u2190 isDefEq k' k then\n      return (i, vs)\n  return (self.size, [])\n\n/-- Insert a new value into the map at key `k`. This does a defeq check with all other keys\nin the map. -/\ndef ExprMultiMap.insert (self : ExprMultiMap \u03b1) (k : Expr) (v : \u03b1) : MetaM (ExprMultiMap \u03b1) := do\n  for h : i in [:self.size] do\n    if \u2190 isDefEq (self[i]'h.2).1 k then\n      return self.modify i fun (k, vs) => (k, v::vs)\n  return self.push (k, [v])\n\n/--\n`partitionByType l` takes a list `l` of proofs of comparisons. It sorts these proofs by\nthe type of the variables in the comparison, e.g. `(a : \u211a) < 1` and `(b : \u2124) > c` will be separated.\nReturns a map from a type to a list of comparisons over that type.\n-/\ndef partitionByType (l : List Expr) : MetaM (ExprMultiMap Expr) :=\n  l.foldlM (fun m h => do m.insert (\u2190 typeOfIneqProof h) h) #[]\n\n/--\nGiven a list `ls` of lists of proofs of comparisons, `findLinarithContradiction cfg ls` will try to\nprove `false` by calling `linarith` on each list in succession. It will stop at the first proof of\n`false`, and fail if no contradiction is found with any list.\n-/\ndef findLinarithContradiction (cfg : LinarithConfig) (g : MVarId) (ls : List (List Expr)) :\n    MetaM Expr :=\n  ls.firstM (fun L => proveFalseByLinarith cfg g L)\n    <|> throwError \"linarith failed to find a contradiction\"\n\n\n/--\nGiven a list `hyps` of proofs of comparisons, `runLinarith cfg hyps pref_type`\npreprocesses `hyps` according to the list of preprocessors in `cfg`.\nThis results in a list of branches (typically only one),\neach of which must succeed in order to close the goal.\n\nIn each branch, we partition the list of hypotheses by type, and run `linarith` on each class\nin the partition; one of these must succeed in order for `linarith` to succeed on this branch.\nIf `pref_type` is given, it will first use the class of proofs of comparisons over that type.\n-/\n-- If it succeeds, the passed metavariable should have been assigned.\ndef runLinarith (cfg : LinarithConfig) (pref_type : Option Expr) (g : MVarId)\n    (hyps : List Expr) : MetaM Unit :=\nlet single_process : MVarId \u2192 List Expr \u2192 MetaM Expr :=\n  fun (g : MVarId) (hyps : List Expr) => do\n   linarithTraceProofs\n     (\"after preprocessing, linarith has \" ++ toString hyps.length ++ \" facts:\") hyps\n   let hyp_set \u2190 partitionByType hyps\n   trace[linarith] m!\"hypotheses appear in {hyp_set.size} different types\"\n    if let some t := pref_type then\n      let (i, vs) \u2190 hyp_set.find t\n      proveFalseByLinarith cfg g vs <|>\n      findLinarithContradiction cfg g ((hyp_set.eraseIdx i).toList.map (\u00b7.2))\n    else findLinarithContradiction cfg g (hyp_set.toList.map (\u00b7.2))\nlet preprocessors :=\n  (if cfg.split_hypotheses then [Linarith.splitConjunctions.globalize.branching] else []) ++\n  cfg.preprocessors.getD defaultPreprocessors\n-- TODO restore when the `removeNe` preprocessor is implemented\n-- let preprocessors := if cfg.split_ne then Linarith.removeNe::preprocessors else preprocessors\ndo\n  let branches \u2190 preprocess preprocessors g hyps\n  for (g, es) in branches do\n    let r \u2190 single_process g es\n    g.assign r\n  -- Verify that we closed the goal. Failure here should only result from a bad `Preprocessor`.\n  (Expr.mvar g).ensureHasNoMVars\n\n-- /--\n-- `filterHyps restr_type hyps` takes a list of proofs of comparisons `hyps`, and filters it\n-- to only those that are comparisons over the type `restr_type`.\n-- -/\n-- def filterHyps (restr_type : Expr) (hyps : List Expr) : MetaM (List Expr) :=\n--   hyps.filterM (fun h => do\n--     let ht \u2190 inferType h\n--     match getContrLemma ht with\n--     | some (_, htype) => isDefEq htype restr_type\n--     | none => return false)\n\n/--\n`linarith only_on hyps cfg` tries to close the goal using linear arithmetic. It fails\nif it does not succeed at doing this.\n\n* `hyps` is a list of proofs of comparisons to include in the search.\n* If `only_on` is true, the search will be restricted to `hyps`. Otherwise it will use all\n  comparisons in the local context.\n* If `cfg.transparency := semireducible`,\n  it will unfold semireducible definitions when trying to match atomic expressions.\n-/\npartial def linarith (only_on : Bool) (hyps : List Expr) (cfg : LinarithConfig := {})\n    (g : MVarId) : MetaM Unit := do\n  -- if the target is an equality, we run `linarith` twice, to prove \u2264 and \u2265.\n  if (\u2190 whnfR (\u2190 instantiateMVars (\u2190 g.getType))).isEq then do\n    trace[linarith] \"target is an equality: splitting\"\n    let [g\u2081, g\u2082] \u2190 g.apply (\u2190 mkConst' ``eq_of_not_lt_of_not_gt) | failure\n    linarith only_on hyps cfg g\u2081\n    linarith only_on hyps cfg g\u2082\n    return ()\n\n  /- If we are proving a comparison goal (and not just `false`), we consider the type of the\n    elements in the comparison to be the \"preferred\" type. That is, if we find comparison\n    hypotheses in multiple types, we will run `linarith` on the goal type first.\n    In this case we also receive a new variable from moving the goal to a hypothesis.\n    Otherwise, there is no preferred type and no new variable; we simply change the goal to `false`.\n  -/\n\n  let (g, target_type, new_var) \u2190 match \u2190 applyContrLemma g with\n  | (none, g) =>\n    if cfg.exfalso then do\n      trace[linarith] \"using exfalso\"\n      pure (\u2190 g.exfalso, none, none)\n    else\n      pure (g, none, none)\n  | (some (t, v), g) => pure (g, some t, some v)\n\n  g.withContext do\n  -- set up the list of hypotheses, considering the `only_on` and `restrict_type` options\n    let hyps \u2190 (if only_on then do return new_var.toList ++ hyps\n      else do return (\u2190 getLocalHyps).toList ++ hyps)\n\n    -- TODO in mathlib3 we could specify a restriction to a single type.\n    -- I haven't done that here because I don't know how to store a `Type` in `LinarithConfig`.\n    -- There's only one use of the `restrict_type` configuration option in mathlib3,\n    -- and it can be avoided just by using `linarith only`.\n\n    linarithTraceProofs \"linarith is running on the following hypotheses:\" hyps\n    runLinarith cfg target_type g hyps\n  return ()\n\nend Linarith\n\n/-! ### User facing functions -/\n\nopen Parser Tactic Syntax\n\n/-- Syntax for the arguments of `linarith`, after the optional `!`. -/\nsyntax linarithArgsRest := (config)? (&\" only\")? (\" [\" term,* \"]\")?\n\n/--\n`linarith` attempts to find a contradiction between hypotheses that are linear (in)equalities.\nEquivalently, it can prove a linear inequality by assuming its negation and proving `false`.\n\nIn theory, `linarith` should prove any goal that is true in the theory of linear arithmetic over\nthe rationals. While there is some special handling for non-dense orders like `nat` and `int`,\nthis tactic is not complete for these theories and will not prove every true goal. It will solve\ngoals over arbitrary types that instantiate `LinearOrderedCommRing`.\n\nAn example:\n```lean\nexample (x y z : \u211a) (h1 : 2*x  < 3*y) (h2 : -4*x + 2*z < 0)\n        (h3 : 12*y - 4* z < 0)  : false :=\nby linarith\n```\n\n`linarith` will use all appropriate hypotheses and the negation of the goal, if applicable.\n\n`linarith [t1, t2, t3]` will additionally use proof terms `t1, t2, t3`.\n\n`linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses\n`h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.\n\n`linarith!` will use a stronger reducibility setting to try to identify atoms. For example,\n```lean\nexample (x : \u211a) : id x \u2265 x :=\nby linarith\n```\nwill fail, because `linarith` will not identify `x` and `id x`. `linarith!` will.\nThis can sometimes be expensive.\n\n`linarith (config := { .. })` takes a config object with five\noptional arguments:\n* `discharger` specifies a tactic to be used for reducing an algebraic equation in the\n  proof stage. The default is `ring`. Other options include `simp` for basic\n  problems.\n* `transparency` controls how hard `linarith` will try to match atoms to each other. By default\n  it will only unfold `reducible` definitions.\n* If `split_hypotheses` is true, `linarith` will split conjunctions in the context into separate\n  hypotheses.\n* If `exfalso` is false, `linarith` will fail when the goal is neither an inequality nor `false`.\n  (True by default.)\n* `restrict_type` (not yet implemented in mathlib4)\n  will only use hypotheses that are inequalities over `tp`. This is useful\n  if you have e.g. both integer and rational valued inequalities in the local context, which can\n  sometimes confuse the tactic.\n\nA variant, `nlinarith`, does some basic preprocessing to handle some nonlinear goals.\n\nThe option `set_option trace.linarith true` will trace certain intermediate stages of the `linarith`\nroutine.\n-/\nsyntax (name := linarith) \"linarith\" \"!\"? linarithArgsRest : tactic\n\n@[inherit_doc linarith] macro \"linarith!\" rest:linarithArgsRest : tactic =>\n  `(tactic| linarith ! $rest:linarithArgsRest)\n\n/--\nAn extension of `linarith` with some preprocessing to allow it to solve some nonlinear arithmetic\nproblems. (Based on Coq's `nra` tactic.) See `linarith` for the available syntax of options,\nwhich are inherited by `nlinarith`; that is, `nlinarith!` and `nlinarith only [h1, h2]` all work as\nin `linarith`. The preprocessing is as follows:\n\n* For every subterm `a ^ 2` or `a * a` in a hypothesis or the goal,\n  the assumption `0 \u2264 a ^ 2` or `0 \u2264 a * a` is added to the context.\n* For every pair of hypotheses `a1 R1 b1`, `a2 R2 b2` in the context, `R1, R2 \u2208 {<, \u2264, =}`,\n  the assumption `0 R' (b1 - a1) * (b2 - a2)` is added to the context (non-recursively),\n  where `R \u2208 {<, \u2264, =}` is the appropriate comparison derived from `R1, R2`.\n-/\nsyntax (name := nlinarith) \"nlinarith\" \"!\"? linarithArgsRest : tactic\n@[inherit_doc nlinarith] macro \"nlinarith!\" rest:linarithArgsRest : tactic =>\n  `(tactic| nlinarith ! $rest:linarithArgsRest)\n\n/--\nAllow elaboration of `LinarithConfig` arguments to tactics.\n-/\ndeclare_config_elab elabLinarithConfig Linarith.LinarithConfig\n\nelab_rules : tactic\n  | `(tactic| linarith $[!%$bang]? $[$cfg]? $[only%$o]? $[[$args,*]]?) => withMainContext do\n    liftMetaFinishingTactic <|\n      Linarith.linarith o.isSome\n        (\u2190 ((args.map (TSepArray.getElems)).getD {}).mapM (elabTerm \u00b7.raw none)).toList\n        ((\u2190 elabLinarithConfig (mkOptionalNode cfg)).updateReducibility bang.isSome)\n\n-- TODO restore this when `hint` is ported.\n-- add_hint_tactic \"linarith\"\n\n-- TODO restore this when `add_tactic_doc` is ported\n-- add_tactic_doc\n-- { name       := \"linarith\",\n--   category   := doc_category.tactic,\n--   decl_names := [`tactic.interactive.linarith],\n--   tags       := [\"arithmetic\", \"decision procedure\", \"finishing\"] }\n\nopen Linarith\n\nelab_rules : tactic\n  | `(tactic| nlinarith $[!%$bang]? $[$cfg]? $[only%$o]? $[[$args,*]]?) => withMainContext do\n    let cfg \u2190 elabLinarithConfig (mkOptionalNode cfg)\n    let cfg :=\n    { cfg with\n      preprocessors := some (cfg.preprocessors.getD defaultPreprocessors ++\n        [(nlinarithExtras : GlobalBranchingPreprocessor)]) }\n    liftMetaFinishingTactic <|\n      Linarith.linarith o.isSome\n        (\u2190 ((args.map (TSepArray.getElems)).getD {}).mapM (elabTerm \u00b7.raw none)).toList\n        (cfg.updateReducibility bang.isSome)\n\n-- TODO restore this when `hint` is ported.\n-- add_hint_tactic \"nlinarith\"\n\n-- TODO restore this when `add_tactic_doc` is ported\n-- add_tactic_doc\n-- { name       := \"nlinarith\",\n--   category   := doc_category.tactic,\n--   decl_names := [`tactic.interactive.nlinarith],\n--   tags       := [\"arithmetic\", \"decision procedure\", \"finishing\"] }\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Tactic/Linarith/Frontend.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475691174941, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.7066496121171221}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport algebra.char_p.basic\n\n/-!\n# Lemmas about rings of characteristic two\n\nThis file contains results about `char_p R 2`, in the `char_two` namespace.\n\nThe lemmas in this file with a `_sq` suffix are just special cases of the `_pow_char` lemmas\nelsewhere, with a shorter name for ease of discovery, and no need for a `[fact (prime 2)]` argument.\n-/\n\nvariables {R \u03b9 : Type*}\n\nnamespace char_two\n\nsection semiring\nvariables [semiring R] [char_p R 2]\n\nlemma two_eq_zero : (2 : R) = 0 :=\nby rw [\u2190 nat.cast_two, char_p.cast_eq_zero]\n\n@[simp] lemma add_self_eq_zero (x : R) : x + x = 0 :=\nby rw [\u2190two_smul R x, two_eq_zero, zero_smul]\n\n@[simp] lemma bit0_eq_zero : (bit0 : R \u2192 R) = 0 :=\nby { funext, exact add_self_eq_zero _ }\n\nlemma bit0_apply_eq_zero (x : R) : (bit0 x : R) = 0 :=\nby simp\n\n@[simp] lemma bit1_eq_one : (bit1 : R \u2192 R) = 1 :=\nby { funext, simp [bit1] }\n\nlemma bit1_apply_eq_one (x : R) : (bit1 x : R) = 1 :=\nby simp\n\nend semiring\n\nsection ring\nvariables [ring R] [char_p R 2]\n\n@[simp] lemma neg_eq (x : R) : -x = x :=\nby rw [neg_eq_iff_add_eq_zero, \u2190two_smul R x, two_eq_zero, zero_smul]\n\nlemma neg_eq' : has_neg.neg = (id : R \u2192 R) :=\nfunext neg_eq\n\n@[simp] lemma sub_eq_add (x y : R) : x - y = x + y :=\nby rw [sub_eq_add_neg, neg_eq]\n\nlemma sub_eq_add' : has_sub.sub = ((+) : R \u2192 R \u2192 R) :=\nfunext $ \u03bb x, funext $ \u03bb y, sub_eq_add x y\n\nend ring\n\nsection comm_semiring\nvariables [comm_semiring R] [char_p R 2]\n\nlemma add_sq (x y : R) : (x + y) ^ 2 = x ^ 2 + y ^ 2 :=\nadd_pow_char _ _ _\n\nlemma add_mul_self (x y : R) : (x + y) * (x + y) = x * x + y * y :=\nby rw [\u2190pow_two, \u2190pow_two, \u2190pow_two, add_sq]\n\nopen_locale big_operators\n\nlemma list_sum_sq (l : list R) : l.sum ^ 2 = (l.map (^ 2)).sum :=\nlist_sum_pow_char _ _\n\nlemma list_sum_mul_self (l : list R) : l.sum * l.sum = (list.map (\u03bb x, x * x) l).sum :=\nby simp_rw [\u2190pow_two, list_sum_sq]\n\nlemma multiset_sum_sq (l : multiset R) : l.sum ^ 2 = (l.map (^ 2)).sum :=\nmultiset_sum_pow_char _ _\n\nlemma multiset_sum_mul_self (l : multiset R) : l.sum * l.sum = (multiset.map (\u03bb x, x * x) l).sum :=\nby simp_rw [\u2190pow_two, multiset_sum_sq]\n\nlemma sum_sq (s : finset \u03b9) (f : \u03b9 \u2192 R) :\n  (\u2211 i in s, f i) ^ 2 = \u2211 i in s, f i ^ 2 :=\nsum_pow_char _ _ _\n\nlemma sum_mul_self (s : finset \u03b9) (f : \u03b9 \u2192 R) :\n  (\u2211 i in s, f i) * (\u2211 i in s, f i) = \u2211 i in s, f i * f i :=\nby simp_rw [\u2190pow_two, sum_sq]\n\nend comm_semiring\n\nend char_two\n\nsection ring_char\nvariables [ring R]\n\nlemma neg_one_eq_one_iff [nontrivial R]: (-1 : R) = 1 \u2194 ring_char R = 2 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, @@char_two.neg_eq _ (ring_char.of_eq h) 1\u27e9,\n  rw [eq_comm, \u2190sub_eq_zero, sub_neg_eq_add, \u2190 nat.cast_one, \u2190 nat.cast_add] at h,\n  exact ((nat.dvd_prime nat.prime_two).mp (ring_char.dvd h)).resolve_left char_p.ring_char_ne_one\nend\n\n@[simp] lemma order_of_neg_one [nontrivial R] :\n  order_of (-1 : R) = if ring_char R = 2 then 1 else 2 :=\nbegin\n  split_ifs,\n  { rw [neg_one_eq_one_iff.2 h, order_of_one] },\n  apply order_of_eq_prime,\n  { simp },\n  simpa [neg_one_eq_one_iff] using h\nend\n\nend ring_char\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/char_p/two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7066324009105108}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Johannes H\u00f6lzl, Yury G. Kudryashov, Patrick Massot\n-/\nimport algebra.geom_sum\nimport order.filter.archimedean\nimport order.iterate\nimport topology.instances.ennreal\n\n/-!\n# A collection of specific limit computations\n\nThis file, by design, is independent of `normed_space` in the import hierarchy.  It contains\nimportant specific limit computations in metric spaces, in ordered rings/fields, and in specific\ninstances of these such as `\u211d`, `\u211d\u22650` and `\u211d\u22650\u221e`.\n-/\n\nnoncomputable theory\nopen classical set function filter finset metric\n\nopen_locale classical topological_space nat big_operators uniformity nnreal ennreal\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b9 : Type*}\n\nlemma tendsto_inverse_at_top_nhds_0_nat : tendsto (\u03bb n : \u2115, (n : \u211d)\u207b\u00b9) at_top (\ud835\udcdd 0) :=\ntendsto_inv_at_top_zero.comp tendsto_coe_nat_at_top_at_top\n\nlemma tendsto_const_div_at_top_nhds_0_nat (C : \u211d) : tendsto (\u03bb n : \u2115, C / n) at_top (\ud835\udcdd 0) :=\nby simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_at_top_nhds_0_nat\n\nlemma nnreal.tendsto_inverse_at_top_nhds_0_nat : tendsto (\u03bb n : \u2115, (n : \u211d\u22650)\u207b\u00b9) at_top (\ud835\udcdd 0) :=\nby { rw \u2190 nnreal.tendsto_coe, exact tendsto_inverse_at_top_nhds_0_nat }\n\nlemma nnreal.tendsto_const_div_at_top_nhds_0_nat (C : \u211d\u22650) :\n  tendsto (\u03bb n : \u2115, C / n) at_top (\ud835\udcdd 0) :=\nby simpa using tendsto_const_nhds.mul nnreal.tendsto_inverse_at_top_nhds_0_nat\n\nlemma tendsto_one_div_add_at_top_nhds_0_nat :\n  tendsto (\u03bb n : \u2115, 1 / ((n : \u211d) + 1)) at_top (\ud835\udcdd 0) :=\nsuffices tendsto (\u03bb n : \u2115, 1 / (\u2191(n + 1) : \u211d)) at_top (\ud835\udcdd 0), by simpa,\n(tendsto_add_at_top_iff_nat 1).2 (tendsto_const_div_at_top_nhds_0_nat 1)\n\n/-! ### Powers -/\n\nlemma tendsto_add_one_pow_at_top_at_top_of_pos [linear_ordered_semiring \u03b1] [archimedean \u03b1] {r : \u03b1}\n  (h : 0 < r) :\n  tendsto (\u03bb n:\u2115, (r + 1)^n) at_top at_top :=\ntendsto_at_top_at_top_of_monotone' (\u03bb n m, pow_le_pow (le_add_of_nonneg_left (le_of_lt h))) $\n  not_bdd_above_iff.2 $ \u03bb x, set.exists_range_iff.2 $ add_one_pow_unbounded_of_pos _ h\n\nlemma tendsto_pow_at_top_at_top_of_one_lt [linear_ordered_ring \u03b1] [archimedean \u03b1]\n  {r : \u03b1} (h : 1 < r) :\n  tendsto (\u03bbn:\u2115, r ^ n) at_top at_top :=\nsub_add_cancel r 1 \u25b8 tendsto_add_one_pow_at_top_at_top_of_pos (sub_pos.2 h)\n\nlemma nat.tendsto_pow_at_top_at_top_of_one_lt {m : \u2115} (h : 1 < m) :\n  tendsto (\u03bbn:\u2115, m ^ n) at_top at_top :=\ntsub_add_cancel_of_le (le_of_lt h) \u25b8\n  tendsto_add_one_pow_at_top_at_top_of_pos (tsub_pos_of_lt h)\n\nlemma tendsto_pow_at_top_nhds_0_of_lt_1 {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c] [archimedean \ud835\udd5c]\n  [topological_space \ud835\udd5c] [order_topology \ud835\udd5c] {r : \ud835\udd5c} (h\u2081 : 0 \u2264 r) (h\u2082 : r < 1) :\n  tendsto (\u03bbn:\u2115, r^n) at_top (\ud835\udcdd 0) :=\nh\u2081.eq_or_lt.elim\n  (assume : 0 = r,\n    (tendsto_add_at_top_iff_nat 1).mp $ by simp [pow_succ, \u2190 this, tendsto_const_nhds])\n  (assume : 0 < r,\n    have tendsto (\u03bbn, (r\u207b\u00b9 ^ n)\u207b\u00b9) at_top (\ud835\udcdd 0),\n      from tendsto_inv_at_top_zero.comp\n        (tendsto_pow_at_top_at_top_of_one_lt $ one_lt_inv this h\u2082),\n    this.congr (\u03bb n, by simp))\n\nlemma tendsto_pow_at_top_nhds_within_0_of_lt_1 {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c] [archimedean \ud835\udd5c]\n  [topological_space \ud835\udd5c] [order_topology \ud835\udd5c] {r : \ud835\udd5c} (h\u2081 : 0 < r) (h\u2082 : r < 1) :\n  tendsto (\u03bbn:\u2115, r^n) at_top (\ud835\udcdd[>] 0) :=\ntendsto_inf.2 \u27e8tendsto_pow_at_top_nhds_0_of_lt_1 h\u2081.le h\u2082,\n  tendsto_principal.2 $ eventually_of_forall $ \u03bb n, pow_pos h\u2081 _\u27e9\n\nlemma uniformity_basis_dist_pow_of_lt_1 {\u03b1 : Type*} [pseudo_metric_space \u03b1]\n  {r : \u211d} (h\u2080 : 0 < r) (h\u2081 : r < 1) :\n  (\ud835\udce4 \u03b1).has_basis (\u03bb k : \u2115, true) (\u03bb k, {p : \u03b1 \u00d7 \u03b1 | dist p.1 p.2 < r ^ k}) :=\nmetric.mk_uniformity_basis (\u03bb i _, pow_pos h\u2080 _) $ \u03bb \u03b5 \u03b50,\n  (exists_pow_lt_of_lt_one \u03b50 h\u2081).imp $ \u03bb k hk, \u27e8trivial, hk.le\u27e9\n\nlemma geom_lt {u : \u2115 \u2192 \u211d} {c : \u211d} (hc : 0 \u2264 c) {n : \u2115} (hn : 0 < n)\n  (h : \u2200 k < n, c * u k < u (k + 1)) :\n  c ^ n * u 0 < u n :=\nbegin\n  refine (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h,\n  { simp },\n  { simp [pow_succ, mul_assoc, le_refl] }\nend\n\nlemma geom_le {u : \u2115 \u2192 \u211d} {c : \u211d} (hc : 0 \u2264 c) (n : \u2115) (h : \u2200 k < n, c * u k \u2264 u (k + 1)) :\n  c ^ n * u 0 \u2264 u n :=\nby refine (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h; simp [pow_succ, mul_assoc, le_refl]\n\nlemma lt_geom {u : \u2115 \u2192 \u211d} {c : \u211d} (hc : 0 \u2264 c) {n : \u2115} (hn : 0 < n)\n  (h : \u2200 k < n, u (k + 1) < c * u k) :\n  u n < c ^ n * u 0 :=\nbegin\n  refine (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _,\n  { simp },\n  { simp [pow_succ, mul_assoc, le_refl] }\nend\n\nlemma le_geom {u : \u2115 \u2192 \u211d} {c : \u211d} (hc : 0 \u2264 c) (n : \u2115) (h : \u2200 k < n, u (k + 1) \u2264 c * u k) :\n  u n \u2264 (c ^ n) * u 0 :=\nby refine (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _; simp [pow_succ, mul_assoc, le_refl]\n\n/-- If a sequence `v` of real numbers satisfies `k * v n \u2264 v (n+1)` with `1 < k`,\nthen it goes to +\u221e. -/\nlemma tendsto_at_top_of_geom_le {v : \u2115 \u2192 \u211d} {c : \u211d} (h\u2080 : 0 < v 0) (hc : 1 < c)\n  (hu : \u2200 n, c * v n \u2264 v (n + 1)) : tendsto v at_top at_top :=\ntendsto_at_top_mono (\u03bb n, geom_le (zero_le_one.trans hc.le) n (\u03bb k hk, hu k)) $\n  (tendsto_pow_at_top_at_top_of_one_lt hc).at_top_mul_const h\u2080\n\nlemma nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : \u211d\u22650} (hr : r < 1) :\n  tendsto (\u03bb n:\u2115, r^n) at_top (\ud835\udcdd 0) :=\nnnreal.tendsto_coe.1 $ by simp only [nnreal.coe_pow, nnreal.coe_zero,\n  tendsto_pow_at_top_nhds_0_of_lt_1 r.coe_nonneg hr]\n\nlemma ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : \u211d\u22650\u221e} (hr : r < 1) :\n  tendsto (\u03bb n:\u2115, r^n) at_top (\ud835\udcdd 0) :=\nbegin\n  rcases ennreal.lt_iff_exists_coe.1 hr with \u27e8r, rfl, hr'\u27e9,\n  rw [\u2190 ennreal.coe_zero],\n  norm_cast at *,\n  apply nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 hr\nend\n\n/-! ### Geometric series-/\nsection geometric\n\nlemma has_sum_geometric_of_lt_1 {r : \u211d} (h\u2081 : 0 \u2264 r) (h\u2082 : r < 1) :\n  has_sum (\u03bbn:\u2115, r ^ n) (1 - r)\u207b\u00b9 :=\nhave r \u2260 1, from ne_of_lt h\u2082,\nhave tendsto (\u03bbn, (r ^ n - 1) * (r - 1)\u207b\u00b9) at_top (\ud835\udcdd ((0 - 1) * (r - 1)\u207b\u00b9)),\n  from ((tendsto_pow_at_top_nhds_0_of_lt_1 h\u2081 h\u2082).sub tendsto_const_nhds).mul tendsto_const_nhds,\n(has_sum_iff_tendsto_nat_of_nonneg (pow_nonneg h\u2081) _).mpr $\n  by simp [neg_inv, geom_sum_eq, div_eq_mul_inv, *] at *\n\nlemma summable_geometric_of_lt_1 {r : \u211d} (h\u2081 : 0 \u2264 r) (h\u2082 : r < 1) : summable (\u03bbn:\u2115, r ^ n) :=\n\u27e8_, has_sum_geometric_of_lt_1 h\u2081 h\u2082\u27e9\n\nlemma tsum_geometric_of_lt_1 {r : \u211d} (h\u2081 : 0 \u2264 r) (h\u2082 : r < 1) : \u2211'n:\u2115, r ^ n = (1 - r)\u207b\u00b9 :=\n(has_sum_geometric_of_lt_1 h\u2081 h\u2082).tsum_eq\n\nlemma has_sum_geometric_two : has_sum (\u03bbn:\u2115, ((1:\u211d)/2) ^ n) 2 :=\nby convert has_sum_geometric_of_lt_1 _ _; norm_num\n\nlemma summable_geometric_two : summable (\u03bbn:\u2115, ((1:\u211d)/2) ^ n) :=\n\u27e8_, has_sum_geometric_two\u27e9\n\nlemma summable_geometric_two_encode {\u03b9 : Type*} [encodable \u03b9] :\n  summable (\u03bb (i : \u03b9), (1/2 : \u211d)^(encodable.encode i)) :=\nsummable_geometric_two.comp_injective encodable.encode_injective\n\nlemma tsum_geometric_two : \u2211'n:\u2115, ((1:\u211d)/2) ^ n = 2 :=\nhas_sum_geometric_two.tsum_eq\n\nlemma sum_geometric_two_le (n : \u2115) : \u2211 (i : \u2115) in range n, (1 / (2 : \u211d)) ^ i \u2264 2 :=\nbegin\n  have : \u2200 i, 0 \u2264 (1 / (2 : \u211d)) ^ i,\n  { intro i, apply pow_nonneg, norm_num },\n  convert sum_le_tsum (range n) (\u03bb i _, this i) summable_geometric_two,\n  exact tsum_geometric_two.symm\nend\n\nlemma tsum_geometric_inv_two : \u2211' n : \u2115, (2 : \u211d)\u207b\u00b9 ^ n = 2 :=\n(inv_eq_one_div (2 : \u211d)).symm \u25b8 tsum_geometric_two\n\n/-- The sum of `2\u207b\u00b9 ^ i` for `n \u2264 i` equals `2 * 2\u207b\u00b9 ^ n`. -/\nlemma tsum_geometric_inv_two_ge (n : \u2115) :\n  \u2211' i, ite (n \u2264 i) ((2 : \u211d)\u207b\u00b9 ^ i) 0 = 2 * 2\u207b\u00b9 ^ n :=\nbegin\n  have A : summable (\u03bb (i : \u2115), ite (n \u2264 i) ((2\u207b\u00b9 : \u211d) ^ i) 0),\n  { apply summable_of_nonneg_of_le _ _ summable_geometric_two;\n    { intro i, by_cases hi : n \u2264 i; simp [hi] } },\n  have B : (finset.range n).sum (\u03bb (i : \u2115), ite (n \u2264 i) ((2\u207b\u00b9 : \u211d)^i) 0) = 0 :=\n    finset.sum_eq_zero (\u03bb i hi, ite_eq_right_iff.2 $ \u03bb h,\n      (lt_irrefl _ ((finset.mem_range.1 hi).trans_le h)).elim),\n  simp only [\u2190 sum_add_tsum_nat_add n A, B, if_true, zero_add, zero_le',\n    le_add_iff_nonneg_left, pow_add, tsum_mul_right, tsum_geometric_inv_two],\nend\n\nlemma has_sum_geometric_two' (a : \u211d) : has_sum (\u03bbn:\u2115, (a / 2) / 2 ^ n) a :=\nbegin\n  convert has_sum.mul_left (a / 2) (has_sum_geometric_of_lt_1\n    (le_of_lt one_half_pos) one_half_lt_one),\n  { funext n, simp, refl, },\n  { norm_num }\nend\n\nlemma summable_geometric_two' (a : \u211d) : summable (\u03bb n:\u2115, (a / 2) / 2 ^ n) :=\n\u27e8a, has_sum_geometric_two' a\u27e9\n\nlemma tsum_geometric_two' (a : \u211d) : \u2211' n:\u2115, (a / 2) / 2^n = a :=\n(has_sum_geometric_two' a).tsum_eq\n\n/-- **Sum of a Geometric Series** -/\nlemma nnreal.has_sum_geometric {r : \u211d\u22650} (hr : r < 1) :\n  has_sum (\u03bb n : \u2115, r ^ n) (1 - r)\u207b\u00b9 :=\nbegin\n  apply nnreal.has_sum_coe.1,\n  push_cast,\n  rw [nnreal.coe_sub (le_of_lt hr)],\n  exact has_sum_geometric_of_lt_1 r.coe_nonneg hr\nend\n\nlemma nnreal.summable_geometric {r : \u211d\u22650} (hr : r < 1) : summable (\u03bbn:\u2115, r ^ n) :=\n\u27e8_, nnreal.has_sum_geometric hr\u27e9\n\nlemma tsum_geometric_nnreal {r : \u211d\u22650} (hr : r < 1) : \u2211'n:\u2115, r ^ n = (1 - r)\u207b\u00b9 :=\n(nnreal.has_sum_geometric hr).tsum_eq\n\n/-- The series `pow r` converges to `(1-r)\u207b\u00b9`. For `r < 1` the RHS is a finite number,\nand for `1 \u2264 r` the RHS equals `\u221e`. -/\n@[simp] lemma ennreal.tsum_geometric (r : \u211d\u22650\u221e) : \u2211'n:\u2115, r ^ n = (1 - r)\u207b\u00b9 :=\nbegin\n  cases lt_or_le r 1 with hr hr,\n  { rcases ennreal.lt_iff_exists_coe.1 hr with \u27e8r, rfl, hr'\u27e9,\n    norm_cast at *,\n    convert ennreal.tsum_coe_eq (nnreal.has_sum_geometric hr),\n    rw [ennreal.coe_inv $ ne_of_gt $ tsub_pos_iff_lt.2 hr] },\n  { rw [tsub_eq_zero_iff_le.mpr hr, ennreal.inv_zero, ennreal.tsum_eq_supr_nat, supr_eq_top],\n    refine \u03bb a ha, (ennreal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp\n      (\u03bb n hn, lt_of_lt_of_le hn _),\n    calc (n:\u211d\u22650\u221e) = \u2211 i in range n, 1     : by rw [sum_const, nsmul_one, card_range]\n              ... \u2264 \u2211 i in range n, r ^ i : sum_le_sum (\u03bb k _, one_le_pow_of_one_le' hr k) }\nend\n\nend geometric\n\n/-!\n### Sequences with geometrically decaying distance in metric spaces\n\nIn this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance\nbetween two consecutive terms decays geometrically. We show that such sequences are Cauchy\nsequences, and bound their distances to the limit. We also discuss series with geometrically\ndecaying terms.\n-/\nsection edist_le_geometric\n\nvariables [pseudo_emetric_space \u03b1] (r C : \u211d\u22650\u221e) (hr : r < 1) (hC : C \u2260 \u22a4) {f : \u2115 \u2192 \u03b1}\n  (hu : \u2200n, edist (f n) (f (n+1)) \u2264 C * r^n)\n\ninclude hr hC hu\n\n/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C \u2260 \u221e`, `r < 1`,\nthen `f` is a Cauchy sequence.-/\nlemma cauchy_seq_of_edist_le_geometric : cauchy_seq f :=\nbegin\n  refine cauchy_seq_of_edist_le_of_tsum_ne_top _ hu _,\n  rw [ennreal.tsum_mul_left, ennreal.tsum_geometric],\n  refine ennreal.mul_ne_top hC (ennreal.inv_ne_top.2 _),\n  exact (tsub_pos_iff_lt.2 hr).ne'\nend\n\nomit hr hC\n\n/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from\n`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/\nlemma edist_le_of_edist_le_geometric_of_tendsto {a : \u03b1} (ha : tendsto f at_top (\ud835\udcdd a)) (n : \u2115) :\n  edist (f n) a \u2264 (C * r^n) / (1 - r) :=\nbegin\n  convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _,\n  simp only [pow_add, ennreal.tsum_mul_left, ennreal.tsum_geometric, div_eq_mul_inv, mul_assoc]\nend\n\n/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from\n`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/\nlemma edist_le_of_edist_le_geometric_of_tendsto\u2080 {a : \u03b1} (ha : tendsto f at_top (\ud835\udcdd a)) :\n  edist (f 0) a \u2264 C / (1 - r) :=\nby simpa only [pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0\n\nend edist_le_geometric\n\nsection edist_le_geometric_two\n\nvariables [pseudo_emetric_space \u03b1] (C : \u211d\u22650\u221e) (hC : C \u2260 \u22a4) {f : \u2115 \u2192 \u03b1}\n  (hu : \u2200n, edist (f n) (f (n+1)) \u2264 C / 2^n) {a : \u03b1} (ha : tendsto f at_top (\ud835\udcdd a))\n\ninclude hC hu\n\n/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence.-/\nlemma cauchy_seq_of_edist_le_geometric_two : cauchy_seq f :=\nbegin\n  simp only [div_eq_mul_inv, ennreal.inv_pow] at hu,\n  refine cauchy_seq_of_edist_le_geometric 2\u207b\u00b9 C _ hC hu,\n  simp [ennreal.one_lt_two]\nend\n\nomit hC\ninclude ha\n\n/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from\n`f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/\nlemma edist_le_of_edist_le_geometric_two_of_tendsto (n : \u2115) :\n  edist (f n) a \u2264 2 * C / 2^n :=\nbegin\n  simp only [div_eq_mul_inv, ennreal.inv_pow] at *,\n  rw [mul_assoc, mul_comm],\n  convert edist_le_of_edist_le_geometric_of_tendsto 2\u207b\u00b9 C hu ha n,\n  rw [ennreal.one_sub_inv_two, inv_inv]\nend\n\n/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from\n`f 0` to the limit of `f` is bounded above by `2 * C`. -/\nlemma edist_le_of_edist_le_geometric_two_of_tendsto\u2080: edist (f 0) a \u2264 2 * C :=\nby simpa only [pow_zero, div_eq_mul_inv, ennreal.inv_one, mul_one]\n  using edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0\n\nend edist_le_geometric_two\n\nsection le_geometric\n\nvariables [pseudo_metric_space \u03b1] {r C : \u211d} (hr : r < 1) {f : \u2115 \u2192 \u03b1}\n  (hu : \u2200n, dist (f n) (f (n+1)) \u2264 C * r^n)\n\ninclude hr hu\n\nlemma aux_has_sum_of_le_geometric : has_sum (\u03bb n : \u2115, C * r^n) (C / (1 - r)) :=\nbegin\n  rcases sign_cases_of_C_mul_pow_nonneg (\u03bb n, dist_nonneg.trans (hu n)) with rfl | \u27e8C\u2080, r\u2080\u27e9,\n  { simp [has_sum_zero] },\n  { refine has_sum.mul_left C _,\n    simpa using has_sum_geometric_of_lt_1 r\u2080 hr }\nend\n\nvariables (r C)\n\n/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence.\nNote that this lemma does not assume `0 \u2264 C` or `0 \u2264 r`. -/\nlemma cauchy_seq_of_le_geometric : cauchy_seq f :=\ncauchy_seq_of_dist_le_of_summable _ hu \u27e8_, aux_has_sum_of_le_geometric hr hu\u27e9\n\n/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from\n`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/\nlemma dist_le_of_le_geometric_of_tendsto\u2080 {a : \u03b1} (ha : tendsto f at_top (\ud835\udcdd a)) :\n  dist (f 0) a \u2264 C / (1 - r) :=\n(aux_has_sum_of_le_geometric hr hu).tsum_eq \u25b8\n  dist_le_tsum_of_dist_le_of_tendsto\u2080 _ hu \u27e8_, aux_has_sum_of_le_geometric hr hu\u27e9 ha\n\n/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from\n`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/\nlemma dist_le_of_le_geometric_of_tendsto {a : \u03b1} (ha : tendsto f at_top (\ud835\udcdd a)) (n : \u2115) :\n  dist (f n) a \u2264 (C * r^n) / (1 - r) :=\nbegin\n  have := aux_has_sum_of_le_geometric hr hu,\n  convert dist_le_tsum_of_dist_le_of_tendsto _ hu \u27e8_, this\u27e9 ha n,\n  simp only [pow_add, mul_left_comm C, mul_div_right_comm],\n  rw [mul_comm],\n  exact (this.mul_left _).tsum_eq.symm\nend\n\nomit hr hu\n\nvariable (hu\u2082 : \u2200 n, dist (f n) (f (n+1)) \u2264 (C / 2) / 2^n)\n\n/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then `f` is a Cauchy sequence. -/\nlemma cauchy_seq_of_le_geometric_two : cauchy_seq f :=\ncauchy_seq_of_dist_le_of_summable _ hu\u2082 $ \u27e8_, has_sum_geometric_two' C\u27e9\n\n/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from\n`f 0` to the limit of `f` is bounded above by `C`. -/\nlemma dist_le_of_le_geometric_two_of_tendsto\u2080 {a : \u03b1} (ha : tendsto f at_top (\ud835\udcdd a)) :\n  dist (f 0) a \u2264 C :=\n(tsum_geometric_two' C) \u25b8 dist_le_tsum_of_dist_le_of_tendsto\u2080 _ hu\u2082 (summable_geometric_two' C) ha\n\ninclude hu\u2082\n\n/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from\n`f n` to the limit of `f` is bounded above by `C / 2^n`. -/\nlemma dist_le_of_le_geometric_two_of_tendsto {a : \u03b1} (ha : tendsto f at_top (\ud835\udcdd a)) (n : \u2115) :\n  dist (f n) a \u2264 C / 2^n :=\nbegin\n  convert dist_le_tsum_of_dist_le_of_tendsto _ hu\u2082 (summable_geometric_two' C) ha n,\n  simp only [add_comm n, pow_add, \u2190 div_div],\n  symmetry,\n  exact ((has_sum_geometric_two' C).div_const _).tsum_eq\nend\n\nend le_geometric\n\n/-! ### Summability tests based on comparison with geometric series -/\n\n/-- A series whose terms are bounded by the terms of a converging geometric series converges. -/\nlemma summable_one_div_pow_of_le {m : \u211d} {f : \u2115 \u2192 \u2115} (hm : 1 < m) (fi : \u2200 i, i \u2264 f i) :\n  summable (\u03bb i, 1 / m ^ f i) :=\nbegin\n  refine summable_of_nonneg_of_le\n    (\u03bb a, one_div_nonneg.mpr (pow_nonneg (zero_le_one.trans hm.le) _)) (\u03bb a, _)\n    (summable_geometric_of_lt_1 (one_div_nonneg.mpr (zero_le_one.trans hm.le))\n      ((one_div_lt (zero_lt_one.trans hm) zero_lt_one).mpr (one_div_one.le.trans_lt hm))),\n  rw [div_pow, one_pow],\n  refine (one_div_le_one_div _ _).mpr (pow_le_pow hm.le (fi a));\n  exact pow_pos (zero_lt_one.trans hm) _\nend\n\n/-! ### Positive sequences with small sums on encodable types -/\n\n/-- For any positive `\u03b5`, define on an encodable type a positive sequence with sum less than `\u03b5` -/\ndef pos_sum_of_encodable {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5)\n  (\u03b9) [encodable \u03b9] : {\u03b5' : \u03b9 \u2192 \u211d // (\u2200 i, 0 < \u03b5' i) \u2227 \u2203 c, has_sum \u03b5' c \u2227 c \u2264 \u03b5} :=\nbegin\n  let f := \u03bb n, (\u03b5 / 2) / 2 ^ n,\n  have hf : has_sum f \u03b5 := has_sum_geometric_two' _,\n  have f0 : \u2200 n, 0 < f n := \u03bb n, div_pos (half_pos h\u03b5) (pow_pos zero_lt_two _),\n  refine \u27e8f \u2218 encodable.encode, \u03bb i, f0 _, _\u27e9,\n  rcases hf.summable.comp_injective (@encodable.encode_injective \u03b9 _) with \u27e8c, hg\u27e9,\n  refine \u27e8c, hg, has_sum_le_inj _ (@encodable.encode_injective \u03b9 _) _ _ hg hf\u27e9,\n  { assume i _, exact le_of_lt (f0 _) },\n  { assume n, exact le_rfl }\nend\n\nlemma set.countable.exists_pos_has_sum_le {\u03b9 : Type*} {s : set \u03b9} (hs : s.countable)\n  {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n  \u2203 \u03b5' : \u03b9 \u2192 \u211d, (\u2200 i, 0 < \u03b5' i) \u2227 \u2203 c, has_sum (\u03bb i : s, \u03b5' i) c \u2227 c \u2264 \u03b5 :=\nbegin\n  haveI := hs.to_encodable,\n  rcases pos_sum_of_encodable h\u03b5 s with \u27e8f, hf0, \u27e8c, hfc, hc\u03b5\u27e9\u27e9,\n  refine \u27e8\u03bb i, if h : i \u2208 s then f \u27e8i, h\u27e9 else 1, \u03bb i, _, \u27e8c, _, hc\u03b5\u27e9\u27e9,\n  { split_ifs, exacts [hf0 _, zero_lt_one] },\n  { simpa only [subtype.coe_prop, dif_pos, subtype.coe_eta] }\nend\n\nlemma set.countable.exists_pos_forall_sum_le {\u03b9 : Type*} {s : set \u03b9} (hs : s.countable)\n  {\u03b5 : \u211d} (h\u03b5 : 0 < \u03b5) :\n  \u2203 \u03b5' : \u03b9 \u2192 \u211d, (\u2200 i, 0 < \u03b5' i) \u2227 \u2200 t : finset \u03b9, \u2191t \u2286 s \u2192 \u2211 i in t, \u03b5' i \u2264 \u03b5 :=\nbegin\n  rcases hs.exists_pos_has_sum_le h\u03b5 with \u27e8\u03b5', hpos, c, h\u03b5'c, hc\u03b5\u27e9,\n  refine \u27e8\u03b5', hpos, \u03bb t ht, _\u27e9,\n  rw [\u2190 sum_subtype_of_mem _ ht],\n  refine (sum_le_has_sum _ _ h\u03b5'c).trans hc\u03b5,\n  exact \u03bb _ _, (hpos _).le\nend\n\nnamespace nnreal\n\ntheorem exists_pos_sum_of_encodable {\u03b5 : \u211d\u22650} (h\u03b5 : \u03b5 \u2260 0) (\u03b9) [encodable \u03b9] :\n  \u2203 \u03b5' : \u03b9 \u2192 \u211d\u22650, (\u2200 i, 0 < \u03b5' i) \u2227 \u2203c, has_sum \u03b5' c \u2227 c < \u03b5 :=\nlet \u27e8a, a0, a\u03b5\u27e9 := exists_between (pos_iff_ne_zero.2 h\u03b5) in\nlet \u27e8\u03b5', h\u03b5', c, hc, hc\u03b5\u27e9 := pos_sum_of_encodable a0 \u03b9 in\n\u27e8 \u03bbi, \u27e8\u03b5' i, le_of_lt $ h\u03b5' i\u27e9, assume i, nnreal.coe_lt_coe.1 $ h\u03b5' i,\n  \u27e8c, has_sum_le (assume i, le_of_lt $ h\u03b5' i) has_sum_zero hc \u27e9, nnreal.has_sum_coe.1 hc,\n   lt_of_le_of_lt (nnreal.coe_le_coe.1 hc\u03b5) a\u03b5 \u27e9\n\nend nnreal\n\nnamespace ennreal\n\ntheorem exists_pos_sum_of_encodable {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) (\u03b9) [encodable \u03b9] :\n  \u2203 \u03b5' : \u03b9 \u2192 \u211d\u22650, (\u2200 i, 0 < \u03b5' i) \u2227 \u2211' i, (\u03b5' i : \u211d\u22650\u221e) < \u03b5 :=\nbegin\n  rcases exists_between (pos_iff_ne_zero.2 h\u03b5) with \u27e8r, h0r, hr\u03b5\u27e9,\n  rcases lt_iff_exists_coe.1 hr\u03b5 with \u27e8x, rfl, hx\u27e9,\n  rcases nnreal.exists_pos_sum_of_encodable (coe_pos.1 h0r).ne' \u03b9 with \u27e8\u03b5', hp, c, hc, hcr\u27e9,\n  exact \u27e8\u03b5', hp, (ennreal.tsum_coe_eq hc).symm \u25b8 lt_trans (coe_lt_coe.2 hcr) hr\u03b5\u27e9\nend\n\ntheorem exists_pos_sum_of_encodable' {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) (\u03b9) [encodable \u03b9] :\n  \u2203 \u03b5' : \u03b9 \u2192 \u211d\u22650\u221e, (\u2200 i, 0 < \u03b5' i) \u2227 (\u2211' i, \u03b5' i) < \u03b5 :=\nlet \u27e8\u03b4, \u03b4pos, h\u03b4\u27e9 := exists_pos_sum_of_encodable h\u03b5 \u03b9 in\n  \u27e8\u03bb i, \u03b4 i, \u03bb i, ennreal.coe_pos.2 (\u03b4pos i), h\u03b4\u27e9\n\ntheorem exists_pos_tsum_mul_lt_of_encodable {\u03b5 : \u211d\u22650\u221e} (h\u03b5 : \u03b5 \u2260 0) {\u03b9} [encodable \u03b9]\n  (w : \u03b9 \u2192 \u211d\u22650\u221e) (hw : \u2200 i, w i \u2260 \u221e) :\n  \u2203 \u03b4 : \u03b9 \u2192 \u211d\u22650, (\u2200 i, 0 < \u03b4 i) \u2227 \u2211' i, (w i * \u03b4 i : \u211d\u22650\u221e) < \u03b5 :=\nbegin\n  lift w to \u03b9 \u2192 \u211d\u22650 using hw,\n  rcases exists_pos_sum_of_encodable h\u03b5 \u03b9 with \u27e8\u03b4', Hpos, Hsum\u27e9,\n  have : \u2200 i, 0 < max 1 (w i), from \u03bb i, zero_lt_one.trans_le (le_max_left _ _),\n  refine \u27e8\u03bb i, \u03b4' i / max 1 (w i), \u03bb i, nnreal.div_pos (Hpos _) (this i), _\u27e9,\n  refine lt_of_le_of_lt (ennreal.tsum_le_tsum $ \u03bb i, _) Hsum,\n  rw [coe_div (this i).ne'],\n  refine mul_le_of_le_div' (ennreal.mul_le_mul le_rfl $ ennreal.inv_le_inv.2 _),\n  exact coe_le_coe.2 (le_max_right _ _)\nend\n\nend ennreal\n\n/-!\n### Factorial\n-/\n\nlemma factorial_tendsto_at_top : tendsto nat.factorial at_top at_top :=\ntendsto_at_top_at_top_of_monotone nat.monotone_factorial (\u03bb n, \u27e8n, n.self_le_factorial\u27e9)\n\nlemma tendsto_factorial_div_pow_self_at_top : tendsto (\u03bb n, n! / n^n : \u2115 \u2192 \u211d) at_top (\ud835\udcdd 0) :=\ntendsto_of_tendsto_of_tendsto_of_le_of_le'\n  tendsto_const_nhds\n  (tendsto_const_div_at_top_nhds_0_nat 1)\n  (eventually_of_forall $ \u03bb n, div_nonneg (by exact_mod_cast n.factorial_pos.le)\n    (pow_nonneg (by exact_mod_cast n.zero_le) _))\n  begin\n    refine (eventually_gt_at_top 0).mono (\u03bb n hn, _),\n    rcases nat.exists_eq_succ_of_ne_zero hn.ne.symm with \u27e8k, rfl\u27e9,\n    rw [\u2190 prod_range_add_one_eq_factorial, pow_eq_prod_const, div_eq_mul_inv, \u2190 inv_eq_one_div,\n      prod_nat_cast, nat.cast_succ, \u2190 prod_inv_distrib, \u2190 prod_mul_distrib,\n      finset.prod_range_succ'],\n    simp only [prod_range_succ', one_mul, nat.cast_add, zero_add, nat.cast_one],\n    refine mul_le_of_le_one_left (inv_nonneg.mpr $ by exact_mod_cast hn.le) (prod_le_one _ _);\n      intros x hx; rw finset.mem_range at hx,\n    { refine mul_nonneg _ (inv_nonneg.mpr _); norm_cast; linarith },\n    { refine (div_le_one $ by exact_mod_cast hn).mpr _, norm_cast, linarith }\n  end\n\n/-!\n### Ceil and floor\n-/\n\nsection\n\nlemma tendsto_nat_floor_at_top {\u03b1 : Type*} [linear_ordered_semiring \u03b1] [floor_semiring \u03b1] :\n  tendsto (\u03bb (x : \u03b1), \u230ax\u230b\u208a) at_top at_top :=\nnat.floor_mono.tendsto_at_top_at_top (\u03bb x, \u27e8max 0 (x + 1), by simp [nat.le_floor_iff]\u27e9)\n\nvariables {R : Type*} [topological_space R] [linear_ordered_field R] [order_topology R]\n[floor_ring R]\n\nlemma tendsto_nat_floor_mul_div_at_top {a : R} (ha : 0 \u2264 a) :\n  tendsto (\u03bb x, (\u230aa * x\u230b\u208a : R) / x) at_top (\ud835\udcdd a) :=\nbegin\n  have A : tendsto (\u03bb (x : R), a - x\u207b\u00b9) at_top (\ud835\udcdd (a - 0)) :=\n    tendsto_const_nhds.sub tendsto_inv_at_top_zero,\n  rw sub_zero at A,\n  apply tendsto_of_tendsto_of_tendsto_of_le_of_le' A tendsto_const_nhds,\n  { refine eventually_at_top.2 \u27e81, \u03bb x hx, _\u27e9,\n    simp only [le_div_iff (zero_lt_one.trans_le hx), sub_mul,\n      inv_mul_cancel (zero_lt_one.trans_le hx).ne'],\n    have := nat.lt_floor_add_one (a * x),\n    linarith },\n  { refine eventually_at_top.2 \u27e81, \u03bb x hx, _\u27e9,\n    rw div_le_iff (zero_lt_one.trans_le hx),\n    simp [nat.floor_le (mul_nonneg ha (zero_le_one.trans hx))] }\nend\n\nlemma tendsto_nat_floor_div_at_top :\n  tendsto (\u03bb x, (\u230ax\u230b\u208a : R) / x) at_top (\ud835\udcdd 1) :=\nby simpa using tendsto_nat_floor_mul_div_at_top (zero_le_one' R)\n\nlemma tendsto_nat_ceil_mul_div_at_top {a : R} (ha : 0 \u2264 a) :\n  tendsto (\u03bb x, (\u2308a * x\u2309\u208a : R) / x) at_top (\ud835\udcdd a) :=\nbegin\n  have A : tendsto (\u03bb (x : R), a + x\u207b\u00b9) at_top (\ud835\udcdd (a + 0)) :=\n    tendsto_const_nhds.add tendsto_inv_at_top_zero,\n  rw add_zero at A,\n  apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds A,\n  { refine eventually_at_top.2 \u27e81, \u03bb x hx, _\u27e9,\n    rw le_div_iff (zero_lt_one.trans_le hx),\n    exact nat.le_ceil _ },\n  { refine eventually_at_top.2 \u27e81, \u03bb x hx, _\u27e9,\n    simp [div_le_iff (zero_lt_one.trans_le hx), inv_mul_cancel (zero_lt_one.trans_le hx).ne',\n      (nat.ceil_lt_add_one ((mul_nonneg ha (zero_le_one.trans hx)))).le, add_mul] }\nend\n\nlemma tendsto_nat_ceil_div_at_top :\n  tendsto (\u03bb x, (\u2308x\u2309\u208a : R) / x) at_top (\ud835\udcdd 1) :=\nby simpa using tendsto_nat_ceil_mul_div_at_top (zero_le_one' R)\n\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/specific_limits/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7066323844394966}}
{"text": "\nnamespace nat\n\nlemma succ_lt_succ_iff : \n  \u2200 {a b : \u2115}, nat.succ a < nat.succ b \u2194 a < b :=\nbegin\n  intros a b, apply iff.intro,\n  apply lt_of_succ_lt_succ,\n  apply succ_lt_succ\nend\n\nend nat", "meta": {"author": "skbaek", "repo": "clausify", "sha": "d09b071bdcce7577c3fffacd0893b776285b1590", "save_path": "github-repos/lean/skbaek-clausify", "path": "github-repos/lean/skbaek-clausify/clausify-d09b071bdcce7577c3fffacd0893b776285b1590/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.7066078558849299}}
{"text": "/-\nCopyright (c) 2020 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebra.associated\nimport Mathlib.algebra.big_operators.basic\nimport Mathlib.PostPort\n\nuniverses u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# Prime elements in rings\nThis file contains lemmas about prime elements of commutative rings.\n-/\n\n/-- If `x * y = a * \u220f i in s, p i` where `p i` is always prime, then\n  `x` and `y` can both be written as a divisor of `a` multiplied by\n  a product over a subset of `s`  -/\ntheorem mul_eq_mul_prime_prod {R : Type u_1} [comm_cancel_monoid_with_zero R] {\u03b1 : Type u_2} [DecidableEq \u03b1] {x : R} {y : R} {a : R} {s : finset \u03b1} {p : \u03b1 \u2192 R} (hp : \u2200 (i : \u03b1), i \u2208 s \u2192 prime (p i)) (hx : x * y = a * finset.prod s fun (i : \u03b1) => p i) : \u2203 (t : finset \u03b1),\n  \u2203 (u : finset \u03b1),\n    \u2203 (b : R),\n      \u2203 (c : R),\n        t \u222a u = s \u2227\n          disjoint t u \u2227\n            a = b * c \u2227 (x = b * finset.prod t fun (i : \u03b1) => p i) \u2227 y = c * finset.prod u fun (i : \u03b1) => p i := sorry\n\n/-- If ` x * y = a * p ^ n` where `p` is prime, then `x` and `y` can both be written\n  as the product of a power of `p` and a divisor of `a`. -/\ntheorem mul_eq_mul_prime_pow {R : Type u_1} [comm_cancel_monoid_with_zero R] {x : R} {y : R} {a : R} {p : R} {n : \u2115} (hp : prime p) (hx : x * y = a * p ^ n) : \u2203 (i : \u2115), \u2203 (j : \u2115), \u2203 (b : R), \u2203 (c : R), i + j = n \u2227 a = b * c \u2227 x = b * p ^ i \u2227 y = c * p ^ j := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/ring_theory/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88242786954645, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7065529375724147}}
{"text": "-- Razonamiento ecuacional sobre intercambio en pares\n-- ==================================================\n\nimport data.prod\nopen prod\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\nvariable  (x : \u03b1)\nvariable  (y : \u03b2)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la funci\u00f3n\n--    intercambia :: \u03b1 \u00d7 \u03b2 \u2192 \u03b2 \u00d7 \u03b1\n-- tal que (intercambia p) es el par obtenido\n-- intercambiando las componentes del par p. Por\n-- ejemplo,\n--    intercambia (5,7) = (7,5)\n-- ----------------------------------------------------\n\ndef intercambia : \u03b1 \u00d7 \u03b2 \u2192 \u03b2 \u00d7 \u03b1\n| (x,y) := (y, x)\n\n-- #eval intercambia (5,7)\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar el lema\n--    intercambia_simp : intercambia p = (p.2, p.1)\n-- ----------------------------------------------------\n\n@[simp]\nlemma intercambia_simp :\n  intercambia (x,y) = (y,x) :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 3. (p.6) Demostrar que\n--    intercambia (intercambia (x,y)) = (x,y)\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  intercambia (intercambia (x,y)) = (x,y) :=\ncalc intercambia (intercambia (x,y))\n         = intercambia (y,x)          : by rw intercambia_simp\n     ... = (x,y)                      : by rw intercambia_simp\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  intercambia (intercambia (x,y)) = (x,y) :=\ncalc intercambia (intercambia (x,y))\n         = intercambia (y,x)          : by simp\n     ... = (x,y)                      : by simp\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  intercambia (intercambia (x,y)) = (x,y) :=\nby simp\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  intercambia (intercambia (x,y)) = (x,y) :=\nrfl\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  intercambia (intercambia (x,y)) = (x,y) :=\nbegin\n  rw intercambia_simp,\n  rw intercambia_simp,\nend\n\n-- Comentarios sobre la funci\u00f3n swap:\n-- + Es equivalente a la funci\u00f3n intercambia.\n-- + Para usarla hay que importar la librer\u00eda data.prod\n--   y abrir espacio de nombre prod el escribiendo al\n--   principio del fichero\n--      import data.prod\n--      open prod\n-- + Se puede evaluar. Por ejemplo,\n--      #eval swap (5,7)\n-- + Se puede demostrar. Por ejemplo,\n--      example :\n--        swap (swap (x,y)) = (x,y) :=\n--      rfl\n--\n--      example :\n--        swap (swap (x,y)) = (x,y) :=\n--      -- by library_search\n--      swap_swap (x,y)\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/7_Programas/Razonamiento_ecuacional_sobre_intercambio_en_pares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8824278664544911, "lm_q1q2_score": 0.7065529350967079}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport topology.subset_properties\nimport topology.connected\nimport topology.nhds_set\n\n/-!\n# Separation properties of topological spaces.\n\nThis file defines the predicate `separated`, and common separation axioms\n(under the Kolmogorov classification).\n\n## Main definitions\n\n* `separated`: Two `set`s are separated if they are contained in disjoint open sets.\n* `t0_space`: A T\u2080/Kolmogorov space is a space where, for every two points `x \u2260 y`,\n  there is an open set that contains one, but not the other.\n* `t1_space`: A T\u2081/Fr\u00e9chet space is a space where every singleton set is closed.\n  This is equivalent to, for every pair `x \u2260 y`, there existing an open set containing `x`\n  but not `y` (`t1_space_iff_exists_open` shows that these conditions are equivalent.)\n* `t2_space`: A T\u2082/Hausdorff space is a space where, for every two points `x \u2260 y`,\n  there is two disjoint open sets, one containing `x`, and the other `y`.\n* `t2_5_space`: A T\u2082.\u2085/Urysohn space is a space where, for every two points `x \u2260 y`,\n  there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint.\n* `regular_space`: A T\u2083 space (sometimes referred to as regular, but authors vary on\n  whether this includes T\u2082; `mathlib` does), is one where given any closed `C` and `x \u2209 C`,\n  there is disjoint open sets containing `x` and `C` respectively. In `mathlib`, T\u2083 implies T\u2082.\u2085.\n* `normal_space`: A T\u2084 space (sometimes referred to as normal, but authors vary on\n  whether this includes T\u2082; `mathlib` does), is one where given two disjoint closed sets,\n  we can find two open sets that separate them. In `mathlib`, T\u2084 implies T\u2083.\n\n## Main results\n\n### T\u2080 spaces\n\n* `is_closed.exists_closed_singleton` Given a closed set `S` in a compact T\u2080 space,\n  there is some `x \u2208 S` such that `{x}` is closed.\n* `exists_open_singleton_of_open_finset` Given an open `finset` `S` in a T\u2080 space,\n  there is some `x \u2208 S` such that `{x}` is open.\n\n### T\u2081 spaces\n\n* `is_closed_map_const`: The constant map is a closed map.\n* `discrete_of_t1_of_finite`: A finite T\u2081 space must have the discrete topology.\n\n### T\u2082 spaces\n\n* `t2_iff_nhds`: A space is T\u2082 iff the neighbourhoods of distinct points generate the bottom filter.\n* `t2_iff_is_closed_diagonal`: A space is T\u2082 iff the `diagonal` of `\u03b1` (that is, the set of all\n  points of the form `(a, a) : \u03b1 \u00d7 \u03b1`) is closed under the product topology.\n* `finset_disjoint_finset_opens_of_t2`: Any two disjoint finsets are `separated`.\n* Most topological constructions preserve Hausdorffness;\n  these results are part of the typeclass inference system (e.g. `embedding.t2_space`)\n* `set.eq_on.closure`: If two functions are equal on some set `s`, they are equal on its closure.\n* `is_compact.is_closed`: All compact sets are closed.\n* `locally_compact_of_compact_nhds`: If every point has a compact neighbourhood,\n  then the space is locally compact.\n* `tot_sep_of_zero_dim`: If `\u03b1` has a clopen basis, it is a `totally_separated_space`.\n* `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T\u2082 space is totally disconnected iff\n  it is totally separated.\n\nIf the space is also compact:\n\n* `normal_of_compact_t2`: A compact T\u2082 space is a `normal_space`.\n* `connected_components_eq_Inter_clopen`: The connected component of a point\n  is the intersection of all its clopen neighbourhoods.\n* `compact_t2_tot_disc_iff_tot_sep`: Being a `totally_disconnected_space`\n  is equivalent to being a `totally_separated_space`.\n* `connected_components.t2`: `connected_components \u03b1` is T\u2082 for `\u03b1` T\u2082 and compact.\n\n### T\u2083 spaces\n\n* `disjoint_nested_nhds`: Given two points `x \u2260 y`, we can find neighbourhoods `x \u2208 V\u2081 \u2286 U\u2081` and\n  `y \u2208 V\u2082 \u2286 U\u2082`, with the `V\u2096` closed and the `U\u2096` open, such that the `U\u2096` are disjoint.\n\n### Discrete spaces\n\n* `discrete_topology_iff_nhds`: Discrete topological spaces are those whose neighbourhood\n  filters are the `pure` filter (which is the principal filter at a singleton).\n* `induced_bot`/`discrete_topology_induced`: The pullback of the discrete topology\n  under an inclusion is the discrete topology.\n\n## References\n\nhttps://en.wikipedia.org/wiki/Separation_axiom\n-/\n\nopen set filter topological_space\nopen_locale topological_space filter classical\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1]\n\nsection separation\n\n/--\n`separated` is a predicate on pairs of sub`set`s of a topological space.  It holds if the two\nsub`set`s are contained in disjoint open sets.\n-/\ndef separated : set \u03b1 \u2192 set \u03b1 \u2192 Prop :=\n  \u03bb (s t : set \u03b1), \u2203 U V : (set \u03b1), (is_open U) \u2227 is_open V \u2227\n  (s \u2286 U) \u2227 (t \u2286 V) \u2227 disjoint U V\n\nnamespace separated\n\nopen separated\n\n@[symm] lemma symm {s t : set \u03b1} : separated s t \u2192 separated t s :=\n\u03bb \u27e8U, V, oU, oV, aU, bV, UV\u27e9, \u27e8V, U, oV, oU, bV, aU, disjoint.symm UV\u27e9\n\nlemma comm (s t : set \u03b1) : separated s t \u2194 separated t s :=\n\u27e8symm, symm\u27e9\n\nlemma empty_right (a : set \u03b1) : separated a \u2205 :=\n\u27e8_, _, is_open_univ, is_open_empty, \u03bb a h, mem_univ a, \u03bb a h, by cases h, disjoint_empty _\u27e9\n\nlemma empty_left (a : set \u03b1) : separated \u2205 a :=\n(empty_right _).symm\n\nlemma union_left {a b c : set \u03b1} : separated a c \u2192 separated b c \u2192 separated (a \u222a b) c :=\n\u03bb \u27e8U, V, oU, oV, aU, bV, UV\u27e9 \u27e8W, X, oW, oX, aW, bX, WX\u27e9,\n  \u27e8U \u222a W, V \u2229 X, is_open.union oU oW, is_open.inter oV oX,\n    union_subset_union aU aW, subset_inter bV bX, set.disjoint_union_left.mpr\n    \u27e8disjoint_of_subset_right (inter_subset_left _ _) UV,\n      disjoint_of_subset_right (inter_subset_right _ _) WX\u27e9\u27e9\n\nlemma union_right {a b c : set \u03b1} (ab : separated a b) (ac : separated a c) :\n  separated a (b \u222a c) :=\n(ab.symm.union_left ac.symm).symm\n\nend separated\n\n/-- A T\u2080 space, also known as a Kolmogorov space, is a topological space\n  where for every pair `x \u2260 y`, there is an open set containing one but not the other. -/\nclass t0_space (\u03b1 : Type u) [topological_space \u03b1] : Prop :=\n(t0 : \u2200 x y, x \u2260 y \u2192 \u2203 U:set \u03b1, is_open U \u2227 (xor (x \u2208 U) (y \u2208 U)))\n\nlemma t0_space_def (\u03b1 : Type u) [topological_space \u03b1] :\n  t0_space \u03b1 \u2194 \u2200 x y, x \u2260 y \u2192 \u2203 U:set \u03b1, is_open U \u2227 (xor (x \u2208 U) (y \u2208 U)) :=\nby { split, apply @t0_space.t0, apply t0_space.mk }\n\n/-- Two points are topologically indistinguishable if no open set separates them. -/\ndef indistinguishable {\u03b1 : Type u} [topological_space \u03b1] (x y : \u03b1) : Prop :=\n\u2200 (U : set \u03b1) (hU : is_open U), x \u2208 U \u2194 y \u2208 U\n\nlemma t0_space_iff_distinguishable (\u03b1 : Type u) [topological_space \u03b1] :\n  t0_space \u03b1 \u2194 \u2200 (x y : \u03b1), x \u2260 y \u2192 \u00ac indistinguishable x y :=\nbegin\n  delta indistinguishable,\n  rw t0_space_def,\n  push_neg,\n  simp_rw xor_iff_not_iff,\nend\n\nlemma indistinguishable_iff_closed {\u03b1 : Type u} [topological_space \u03b1] (x y : \u03b1) :\n  indistinguishable x y \u2194 \u2200 (U : set \u03b1) (hU : is_closed U), x \u2208 U \u2194 y \u2208 U :=\n\u27e8\u03bb h U hU, not_iff_not.mp (h _ hU.1), \u03bb h U hU, not_iff_not.mp (h _ (is_closed_compl_iff.mpr hU))\u27e9\n\nlemma indistinguishable_iff_closure {\u03b1 : Type u} [topological_space \u03b1] (x y : \u03b1) :\n  indistinguishable x y \u2194 x \u2208 closure ({y} : set \u03b1) \u2227 y \u2208 closure ({x} : set \u03b1) :=\nbegin\n  rw indistinguishable_iff_closed,\n  exact \u27e8\u03bb h, \u27e8(h _ is_closed_closure).mpr (subset_closure $ set.mem_singleton y),\n      (h _ is_closed_closure).mp (subset_closure $ set.mem_singleton x)\u27e9,\n    \u03bb h U hU, \u27e8\u03bb hx, (is_closed.closure_subset_iff hU).mpr (set.singleton_subset_iff.mpr hx) h.2,\n      \u03bb hy, (is_closed.closure_subset_iff hU).mpr (set.singleton_subset_iff.mpr hy) h.1\u27e9\u27e9\nend\n\nlemma subtype_indistinguishable_iff {\u03b1 : Type u} [topological_space \u03b1] {U : set \u03b1} (x y : U) :\n  indistinguishable x y \u2194 indistinguishable (x : \u03b1) y :=\nby { simp_rw [indistinguishable_iff_closure, closure_subtype, image_singleton] }\n\nlemma indistinguishable.eq [h\u03b1 : t0_space \u03b1] {x y : \u03b1} (h : indistinguishable x y) : x = y :=\nnot_imp_not.mp ((t0_space_iff_distinguishable _).mp h\u03b1 x y) h\n\n/-- Given a closed set `S` in a compact T\u2080 space,\nthere is some `x \u2208 S` such that `{x}` is closed. -/\ntheorem is_closed.exists_closed_singleton {\u03b1 : Type*} [topological_space \u03b1]\n  [t0_space \u03b1] [compact_space \u03b1] {S : set \u03b1} (hS : is_closed S) (hne : S.nonempty) :\n  \u2203 (x : \u03b1), x \u2208 S \u2227 is_closed ({x} : set \u03b1) :=\nbegin\n  obtain \u27e8V, Vsub, Vne, Vcls, hV\u27e9 := hS.exists_minimal_nonempty_closed_subset hne,\n  by_cases hnt : \u2203 (x y : \u03b1) (hx : x \u2208 V) (hy : y \u2208 V), x \u2260 y,\n  { exfalso,\n    obtain \u27e8x, y, hx, hy, hne\u27e9 := hnt,\n    obtain \u27e8U, hU, hsep\u27e9 := t0_space.t0 _ _ hne,\n    have : \u2200 (z w : \u03b1) (hz : z \u2208 V) (hw : w \u2208 V) (hz' : z \u2208 U) (hw' : \u00ac w \u2208 U), false,\n    { intros z w hz hw hz' hw',\n      have uvne : (V \u2229 U\u1d9c).nonempty,\n      { use w, simp only [hw, hw', set.mem_inter_eq, not_false_iff, and_self, set.mem_compl_eq], },\n      specialize hV (V \u2229 U\u1d9c) (set.inter_subset_left _ _) uvne\n        (is_closed.inter Vcls (is_closed_compl_iff.mpr hU)),\n      have : V \u2286 U\u1d9c,\n      { rw \u2190hV, exact set.inter_subset_right _ _ },\n      exact this hz hz', },\n    cases hsep,\n    { exact this x y hx hy hsep.1 hsep.2 },\n    { exact this y x hy hx hsep.1 hsep.2 } },\n  { push_neg at hnt,\n    obtain \u27e8z, hz\u27e9 := Vne,\n    refine \u27e8z, Vsub hz, _\u27e9,\n    convert Vcls,\n    ext,\n    simp only [set.mem_singleton_iff, set.mem_compl_eq],\n    split,\n    { rintro rfl, exact hz, },\n    { exact \u03bb hx, hnt x z hx hz, }, },\nend\n\n/-- Given an open `finset` `S` in a T\u2080 space, there is some `x \u2208 S` such that `{x}` is open. -/\ntheorem exists_open_singleton_of_open_finset [t0_space \u03b1] (s : finset \u03b1) (sne : s.nonempty)\n  (hso : is_open (s : set \u03b1)) :\n  \u2203 x \u2208 s, is_open ({x} : set \u03b1):=\nbegin\n  induction s using finset.strong_induction_on with s ihs,\n  by_cases hs : set.subsingleton (s : set \u03b1),\n  { rcases sne with \u27e8x, hx\u27e9,\n    refine \u27e8x, hx, _\u27e9,\n    have : (s : set \u03b1) = {x}, from hs.eq_singleton_of_mem hx,\n    rwa this at hso },\n  { dunfold set.subsingleton at hs,\n    push_neg at hs,\n    rcases hs with \u27e8x, hx, y, hy, hxy\u27e9,\n    rcases t0_space.t0 x y hxy with \u27e8U, hU, hxyU\u27e9,\n    wlog H : x \u2208 U \u2227 y \u2209 U := hxyU using [x y, y x],\n    obtain \u27e8z, hzs, hz\u27e9 : \u2203 z \u2208 s.filter (\u03bb z, z \u2208 U), is_open ({z} : set \u03b1),\n    { refine ihs _ (finset.filter_ssubset.2 \u27e8y, hy, H.2\u27e9) \u27e8x, finset.mem_filter.2 \u27e8hx, H.1\u27e9\u27e9 _,\n      rw [finset.coe_filter],\n      exact is_open.inter hso hU },\n    exact \u27e8z, (finset.mem_filter.1 hzs).1, hz\u27e9 }\nend\n\ntheorem exists_open_singleton_of_fintype [t0_space \u03b1] [f : fintype \u03b1] [ha : nonempty \u03b1] :\n  \u2203 x:\u03b1, is_open ({x}:set \u03b1) :=\nbegin\n  refine ha.elim (\u03bb x, _),\n  have : is_open ((finset.univ : finset \u03b1) : set \u03b1), { simp },\n  rcases exists_open_singleton_of_open_finset _ \u27e8x, finset.mem_univ x\u27e9 this with \u27e8x, _, hx\u27e9,\n  exact \u27e8x, hx\u27e9\nend\n\ninstance subtype.t0_space [t0_space \u03b1] {p : \u03b1 \u2192 Prop} : t0_space (subtype p) :=\n\u27e8\u03bb x y hxy, let \u27e8U, hU, hxyU\u27e9 := t0_space.t0 (x:\u03b1) y ((not_congr subtype.ext_iff_val).1 hxy) in\n  \u27e8(coe : subtype p \u2192 \u03b1) \u207b\u00b9' U, is_open_induced hU, hxyU\u27e9\u27e9\n\ntheorem t0_space_iff_or_not_mem_closure (\u03b1 : Type u) [topological_space \u03b1] :\n  t0_space \u03b1 \u2194 (\u2200 a b : \u03b1, (a \u2260 b) \u2192 (a \u2209 closure ({b} : set \u03b1) \u2228 b \u2209 closure ({a} : set \u03b1))) :=\nbegin\n  simp only [\u2190 not_and_distrib, t0_space_def, not_and],\n  refine forall\u2083_congr (\u03bb a b _, \u27e8_, \u03bb h, _\u27e9),\n  { rintro \u27e8s, h\u2081, (\u27e8h\u2082, h\u2083 : b \u2208 s\u1d9c\u27e9|\u27e8h\u2082, h\u2083 : a \u2208 s\u1d9c\u27e9)\u27e9 ha hb; rw \u2190 is_closed_compl_iff at h\u2081,\n    { exact (is_closed.closure_subset_iff h\u2081).mpr (set.singleton_subset_iff.mpr h\u2083) ha h\u2082 },\n    { exact (is_closed.closure_subset_iff h\u2081).mpr (set.singleton_subset_iff.mpr h\u2083) hb h\u2082 } },\n  { by_cases h' : a \u2208 closure ({b} : set \u03b1),\n    { exact \u27e8(closure {a})\u1d9c, is_closed_closure.1,\n        or.inr \u27e8h h', not_not.mpr (subset_closure (set.mem_singleton a))\u27e9\u27e9 },\n    { exact \u27e8(closure {b})\u1d9c, is_closed_closure.1,\n        or.inl \u27e8h', not_not.mpr (subset_closure (set.mem_singleton b))\u27e9\u27e9 } }\nend\n\nlemma t0_space_of_injective_of_continuous {\u03b1 \u03b2 : Type u} [topological_space \u03b1] [topological_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : function.injective f) (hf' : continuous f) [t0_space \u03b2] : t0_space \u03b1 :=\nbegin\n  constructor,\n  intros x y h,\n  obtain \u27e8U, hU, e\u27e9 := t0_space.t0 _ _ (hf.ne h),\n  exact \u27e8f \u207b\u00b9' U, hf'.1 U hU, e\u27e9\nend\n\n/-- A T\u2081 space, also known as a Fr\u00e9chet space, is a topological space\n  where every singleton set is closed. Equivalently, for every pair\n  `x \u2260 y`, there is an open set containing `x` and not `y`. -/\nclass t1_space (\u03b1 : Type u) [topological_space \u03b1] : Prop :=\n(t1 : \u2200x, is_closed ({x} : set \u03b1))\n\nlemma is_closed_singleton [t1_space \u03b1] {x : \u03b1} : is_closed ({x} : set \u03b1) :=\nt1_space.t1 x\n\nlemma is_open_compl_singleton [t1_space \u03b1] {x : \u03b1} : is_open ({x}\u1d9c : set \u03b1) :=\nis_closed_singleton.is_open_compl\n\nlemma is_open_ne [t1_space \u03b1] {x : \u03b1} : is_open {y | y \u2260 x} :=\nis_open_compl_singleton\n\nlemma ne.nhds_within_compl_singleton [t1_space \u03b1] {x y : \u03b1} (h : x \u2260 y) :\n  \ud835\udcdd[{y}\u1d9c] x = \ud835\udcdd x :=\nis_open_ne.nhds_within_eq h\n\nlemma ne.nhds_within_diff_singleton [t1_space \u03b1] {x y : \u03b1} (h : x \u2260 y) (s : set \u03b1) :\n  \ud835\udcdd[s \\ {y}] x = \ud835\udcdd[s] x :=\nbegin\n  rw [diff_eq, inter_comm, nhds_within_inter_of_mem],\n  exact mem_nhds_within_of_mem_nhds (is_open_ne.mem_nhds h)\nend\n\nprotected lemma set.finite.is_closed [t1_space \u03b1] {s : set \u03b1} (hs : set.finite s) :\n  is_closed s :=\nbegin\n  rw \u2190 bUnion_of_singleton s,\n  exact is_closed_bUnion hs (\u03bb i hi, is_closed_singleton)\nend\n\nprotected lemma finset.is_closed [t1_space \u03b1] (s : finset \u03b1) : is_closed (s : set \u03b1) :=\ns.finite_to_set.is_closed\n\nlemma t1_space_tfae (\u03b1 : Type u) [t : topological_space \u03b1] :\n  tfae [t1_space \u03b1,\n    \u2200 x, is_closed ({x} : set \u03b1),\n    \u2200 x, is_open ({x}\u1d9c : set \u03b1),\n    t \u2264 cofinite_topology \u03b1,\n    \u2200 \u2983x y : \u03b1\u2984, x \u2260 y \u2192 {y}\u1d9c \u2208 \ud835\udcdd x,\n    \u2200 \u2983x y : \u03b1\u2984, x \u2260 y \u2192 \u2203 s \u2208 \ud835\udcdd x, y \u2209 s,\n    \u2200 \u2983x y : \u03b1\u2984, x \u2260 y \u2192 \u2203 (U : set \u03b1) (hU : is_open U), x \u2208 U \u2227 y \u2209 U,\n    \u2200 \u2983x y : \u03b1\u2984, x \u2260 y \u2192 disjoint (\ud835\udcdd x) (pure y),\n    \u2200 \u2983x y : \u03b1\u2984, x \u2260 y \u2192 disjoint (pure x) (\ud835\udcdd y)] :=\nbegin\n  tfae_have : 1 \u2194 2, from \u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9,\n  tfae_have : 2 \u2194 3, by simp only [is_open_compl_iff],\n  tfae_have : 5 \u2194 3,\n  { refine forall_swap.trans _,\n    simp only [is_open_iff_mem_nhds, mem_compl_iff, mem_singleton_iff] },\n  tfae_have : 5 \u2194 6,\n    by simp only [\u2190 subset_compl_singleton_iff, exists_mem_subset_iff],\n  tfae_have : 5 \u2194 7,\n    by simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and.assoc,\n      and.left_comm],\n  tfae_have : 5 \u2194 8,\n    by simp only [\u2190 principal_singleton, disjoint_principal_right],\n  tfae_have : 8 \u2194 9, from forall_swap.trans (by simp only [disjoint.comm, ne_comm]),\n  tfae_have : 1 \u2192 4,\n  { introsI H s hs,\n    simp only [cofinite_topology, \u2190 ne_empty_iff_nonempty, ne.def, \u2190 or_iff_not_imp_left] at hs,\n    rcases hs with rfl | hs,\n    exacts [is_open_empty, compl_compl s \u25b8 hs.is_closed.is_open_compl] },\n  tfae_have : 4 \u2192 3,\n  { refine \u03bb h x, h _ (\u03bb _, _), simp },\n  tfae_finish\nend\n\nlemma t1_space_iff_le_cofinite {\u03b1 : Type*} [t : topological_space \u03b1] :\n  t1_space \u03b1 \u2194 t \u2264 cofinite_topology \u03b1 :=\n(t1_space_tfae \u03b1).out 0 3\n\nlemma t1_space_iff_exists_open : t1_space \u03b1 \u2194\n  \u2200 (x y), x \u2260 y \u2192 (\u2203 (U : set \u03b1) (hU : is_open U), x \u2208 U \u2227 y \u2209 U) :=\n(t1_space_tfae \u03b1).out 0 6\n\nlemma t1_space_iff_disjoint_pure_nhds : t1_space \u03b1 \u2194 \u2200 \u2983x y : \u03b1\u2984, x \u2260 y \u2192 disjoint (pure x) (\ud835\udcdd y) :=\n(t1_space_tfae \u03b1).out 0 8\n\nlemma t1_space_iff_disjoint_nhds_pure : t1_space \u03b1 \u2194 \u2200 \u2983x y : \u03b1\u2984, x \u2260 y \u2192 disjoint (\ud835\udcdd x) (pure y) :=\n(t1_space_tfae \u03b1).out 0 7\n\nlemma disjoint_pure_nhds [t1_space \u03b1] {x y : \u03b1} (h : x \u2260 y) : disjoint (pure x) (\ud835\udcdd y) :=\nt1_space_iff_disjoint_pure_nhds.mp \u2039_\u203a h\n\nlemma disjoint_nhds_pure [t1_space \u03b1] {x y : \u03b1} (h : x \u2260 y) : disjoint (\ud835\udcdd x) (pure y) :=\nt1_space_iff_disjoint_nhds_pure.mp \u2039_\u203a h\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t1_space_cofinite {\u03b1 : Type*} : @t1_space \u03b1 (cofinite_topology \u03b1) :=\n(@t1_space_iff_le_cofinite \u03b1 (cofinite_topology \u03b1)).mpr le_rfl\n\nlemma t1_space_antitone {\u03b1 : Type*} : antitone (@t1_space \u03b1) :=\nbegin\n  simp only [antitone, t1_space_iff_le_cofinite],\n  exact \u03bb t\u2081 t\u2082 h, h.trans\nend\n\nlemma continuous_within_at_update_of_ne [t1_space \u03b1] [decidable_eq \u03b1] [topological_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {x y : \u03b1} {z : \u03b2} (hne : y \u2260 x) :\n  continuous_within_at (function.update f x z) s y \u2194 continuous_within_at f s y :=\neventually_eq.congr_continuous_within_at\n  (mem_nhds_within_of_mem_nhds $ mem_of_superset (is_open_ne.mem_nhds hne) $\n    \u03bb y' hy', function.update_noteq hy' _ _)\n  (function.update_noteq hne _ _)\n\nlemma continuous_at_update_of_ne [t1_space \u03b1] [decidable_eq \u03b1] [topological_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} {x y : \u03b1} {z : \u03b2} (hne : y \u2260 x) :\n  continuous_at (function.update f x z) y \u2194 continuous_at f y :=\nby simp only [\u2190 continuous_within_at_univ, continuous_within_at_update_of_ne hne]\n\nlemma continuous_on_update_iff [t1_space \u03b1] [decidable_eq \u03b1] [topological_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {x : \u03b1} {y : \u03b2} :\n  continuous_on (function.update f x y) s \u2194\n    continuous_on f (s \\ {x}) \u2227 (x \u2208 s \u2192 tendsto f (\ud835\udcdd[s \\ {x}] x) (\ud835\udcdd y)) :=\nbegin\n  rw [continuous_on, \u2190 and_forall_ne x, and_comm],\n  refine and_congr \u27e8\u03bb H z hz, _, \u03bb H z hzx hzs, _\u27e9 (forall_congr $ \u03bb hxs, _),\n  { specialize H z hz.2 hz.1,\n    rw continuous_within_at_update_of_ne hz.2 at H,\n    exact H.mono (diff_subset _ _) },\n  { rw continuous_within_at_update_of_ne hzx,\n    refine (H z \u27e8hzs, hzx\u27e9).mono_of_mem (inter_mem_nhds_within _ _),\n    exact is_open_ne.mem_nhds hzx },\n  { exact continuous_within_at_update_same }\nend\n\ninstance subtype.t1_space {\u03b1 : Type u} [topological_space \u03b1] [t1_space \u03b1] {p : \u03b1 \u2192 Prop} :\n  t1_space (subtype p) :=\n\u27e8\u03bb \u27e8x, hx\u27e9, is_closed_induced_iff.2 $ \u27e8{x}, is_closed_singleton, set.ext $ \u03bb y,\n  by simp [subtype.ext_iff_val]\u27e9\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t1_space.t0_space [t1_space \u03b1] : t0_space \u03b1 :=\n\u27e8\u03bb x y h, \u27e8{z | z \u2260 y}, is_open_ne, or.inl \u27e8h, not_not_intro rfl\u27e9\u27e9\u27e9\n\n@[simp] lemma compl_singleton_mem_nhds_iff [t1_space \u03b1] {x y : \u03b1} : {x}\u1d9c \u2208 \ud835\udcdd y \u2194 y \u2260 x :=\nis_open_compl_singleton.mem_nhds_iff\n\nlemma compl_singleton_mem_nhds [t1_space \u03b1] {x y : \u03b1} (h : y \u2260 x) : {x}\u1d9c \u2208 \ud835\udcdd y :=\ncompl_singleton_mem_nhds_iff.mpr h\n\n@[simp] lemma closure_singleton [t1_space \u03b1] {a : \u03b1} :\n  closure ({a} : set \u03b1) = {a} :=\nis_closed_singleton.closure_eq\n\nlemma set.subsingleton.closure [t1_space \u03b1] {s : set \u03b1} (hs : s.subsingleton) :\n  (closure s).subsingleton :=\nhs.induction_on (by simp) $ \u03bb x, by simp\n\n@[simp] lemma subsingleton_closure [t1_space \u03b1] {s : set \u03b1} :\n  (closure s).subsingleton \u2194 s.subsingleton :=\n\u27e8\u03bb h, h.mono subset_closure, \u03bb h, h.closure\u27e9\n\nlemma is_closed_map_const {\u03b1 \u03b2} [topological_space \u03b1] [topological_space \u03b2] [t1_space \u03b2] {y : \u03b2} :\n  is_closed_map (function.const \u03b1 y) :=\nbegin\n  apply is_closed_map.of_nonempty, intros s hs h2s, simp_rw [h2s.image_const, is_closed_singleton]\nend\n\nlemma bInter_basis_nhds [t1_space \u03b1] {\u03b9 : Sort*} {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 set \u03b1} {x : \u03b1}\n  (h : (\ud835\udcdd x).has_basis p s) : (\u22c2 i (h : p i), s i) = {x} :=\nbegin\n  simp only [eq_singleton_iff_unique_mem, mem_Inter],\n  refine \u27e8\u03bb i hi, mem_of_mem_nhds $ h.mem_of_mem hi, \u03bb y hy, _\u27e9,\n  contrapose! hy,\n  rcases h.mem_iff.1 (compl_singleton_mem_nhds hy.symm) with \u27e8i, hi, hsub\u27e9,\n  exact \u27e8i, hi, \u03bb h, hsub h rfl\u27e9\nend\n\n@[simp] lemma nhds_le_nhds_iff [t1_space \u03b1] {a b : \u03b1} : \ud835\udcdd a \u2264 \ud835\udcdd b \u2194 a = b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, h \u25b8 le_rfl\u27e9,\n  by_contra hab,\n  have := h (compl_singleton_mem_nhds $ ne.symm hab),\n  refine mem_of_mem_nhds this (mem_singleton a)\nend\n\n@[simp] lemma nhds_eq_nhds_iff [t1_space \u03b1] {a b : \u03b1} : \ud835\udcdd a = \ud835\udcdd b \u2194 a = b :=\n\u27e8\u03bb h, nhds_le_nhds_iff.mp h.le, \u03bb h, h \u25b8 rfl\u27e9\n\n@[simp] lemma compl_singleton_mem_nhds_set_iff [t1_space \u03b1] {x : \u03b1} {s : set \u03b1} :\n  {x}\u1d9c \u2208 \ud835\udcdd\u02e2 s \u2194 x \u2209 s :=\nby rwa [is_open_compl_singleton.mem_nhds_set, subset_compl_singleton_iff]\n\n@[simp] lemma nhds_set_le_iff [t1_space \u03b1] {s t : set \u03b1} : \ud835\udcdd\u02e2 s \u2264 \ud835\udcdd\u02e2 t \u2194 s \u2286 t :=\nbegin\n  refine \u27e8_, \u03bb h, monotone_nhds_set h\u27e9,\n  simp_rw [filter.le_def], intros h x hx,\n  specialize h {x}\u1d9c,\n  simp_rw [compl_singleton_mem_nhds_set_iff] at h,\n  by_contra hxt,\n  exact h hxt hx,\nend\n\n@[simp] lemma nhds_set_inj_iff [t1_space \u03b1] {s t : set \u03b1} : \ud835\udcdd\u02e2 s = \ud835\udcdd\u02e2 t \u2194 s = t :=\nby { simp_rw [le_antisymm_iff], exact and_congr nhds_set_le_iff nhds_set_le_iff }\n\nlemma injective_nhds_set [t1_space \u03b1] : function.injective (\ud835\udcdd\u02e2 : set \u03b1 \u2192 filter \u03b1) :=\n\u03bb s t hst, nhds_set_inj_iff.mp hst\n\nlemma strict_mono_nhds_set [t1_space \u03b1] : strict_mono (\ud835\udcdd\u02e2 : set \u03b1 \u2192 filter \u03b1) :=\nmonotone_nhds_set.strict_mono_of_injective injective_nhds_set\n\n@[simp] lemma nhds_le_nhds_set [t1_space \u03b1] {s : set \u03b1} {x : \u03b1} : \ud835\udcdd x \u2264 \ud835\udcdd\u02e2 s \u2194 x \u2208 s :=\nby rw [\u2190 nhds_set_singleton, nhds_set_le_iff, singleton_subset_iff]\n\n/-- Removing a non-isolated point from a dense set, one still obtains a dense set. -/\nlemma dense.diff_singleton [t1_space \u03b1] {s : set \u03b1} (hs : dense s) (x : \u03b1) [ne_bot (\ud835\udcdd[\u2260] x)] :\n  dense (s \\ {x}) :=\nhs.inter_of_open_right (dense_compl_singleton x) is_open_compl_singleton\n\n/-- Removing a finset from a dense set in a space without isolated points, one still\nobtains a dense set. -/\nlemma dense.diff_finset [t1_space \u03b1] [\u2200 (x : \u03b1), ne_bot (\ud835\udcdd[\u2260] x)]\n  {s : set \u03b1} (hs : dense s) (t : finset \u03b1) :\n  dense (s \\ t) :=\nbegin\n  induction t using finset.induction_on with x s hxs ih hd,\n  { simpa using hs },\n  { rw [finset.coe_insert, \u2190 union_singleton, \u2190 diff_diff],\n    exact ih.diff_singleton _, }\nend\n\n/-- Removing a finite set from a dense set in a space without isolated points, one still\nobtains a dense set. -/\nlemma dense.diff_finite [t1_space \u03b1] [\u2200 (x : \u03b1), ne_bot (\ud835\udcdd[\u2260] x)]\n  {s : set \u03b1} (hs : dense s) {t : set \u03b1} (ht : finite t) :\n  dense (s \\ t) :=\nbegin\n  convert hs.diff_finset ht.to_finset,\n  exact (finite.coe_to_finset _).symm,\nend\n\n/-- If a function to a `t1_space` tends to some limit `b` at some point `a`, then necessarily\n`b = f a`. -/\nlemma eq_of_tendsto_nhds [topological_space \u03b2] [t1_space \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {b : \u03b2}\n  (h : tendsto f (\ud835\udcdd a) (\ud835\udcdd b)) : f a = b :=\nby_contra $ assume (hfa : f a \u2260 b),\nhave fact\u2081 : {f a}\u1d9c \u2208 \ud835\udcdd b := compl_singleton_mem_nhds hfa.symm,\nhave fact\u2082 : tendsto f (pure a) (\ud835\udcdd b) := h.comp (tendsto_id' $ pure_le_nhds a),\nfact\u2082 fact\u2081 (eq.refl $ f a)\n\n/-- To prove a function to a `t1_space` is continuous at some point `a`, it suffices to prove that\n`f` admits *some* limit at `a`. -/\nlemma continuous_at_of_tendsto_nhds [topological_space \u03b2] [t1_space \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {b : \u03b2}\n  (h : tendsto f (\ud835\udcdd a) (\ud835\udcdd b)) : continuous_at f a :=\nshow tendsto f (\ud835\udcdd a) (\ud835\udcdd $ f a), by rwa eq_of_tendsto_nhds h\n\n/-- If the punctured neighborhoods of a point form a nontrivial filter, then any neighborhood is\ninfinite. -/\nlemma infinite_of_mem_nhds {\u03b1} [topological_space \u03b1] [t1_space \u03b1] (x : \u03b1) [hx : ne_bot (\ud835\udcdd[\u2260] x)]\n  {s : set \u03b1} (hs : s \u2208 \ud835\udcdd x) : set.infinite s :=\nbegin\n  intro hsf,\n  have A : {x} \u2286 s, by simp only [singleton_subset_iff, mem_of_mem_nhds hs],\n  have B : is_closed (s \\ {x}) := (hsf.subset (diff_subset _ _)).is_closed,\n  have C : (s \\ {x})\u1d9c \u2208 \ud835\udcdd x, from B.is_open_compl.mem_nhds (\u03bb h, h.2 rfl),\n  have D : {x} \u2208 \ud835\udcdd x, by simpa only [\u2190 diff_eq, diff_diff_cancel_left A] using inter_mem hs C,\n  rwa [\u2190 mem_interior_iff_mem_nhds, interior_singleton] at D\nend\n\nlemma discrete_of_t1_of_finite {X : Type*} [topological_space X] [t1_space X] [fintype X] :\n  discrete_topology X :=\nbegin\n  apply singletons_open_iff_discrete.mp,\n  intros x,\n  rw [\u2190 is_closed_compl_iff],\n  exact (finite.of_fintype _).is_closed\nend\n\nlemma singleton_mem_nhds_within_of_mem_discrete {s : set \u03b1} [discrete_topology s]\n  {x : \u03b1} (hx : x \u2208 s) :\n  {x} \u2208 \ud835\udcdd[s] x :=\nbegin\n  have : ({\u27e8x, hx\u27e9} : set s) \u2208 \ud835\udcdd (\u27e8x, hx\u27e9 : s), by simp [nhds_discrete],\n  simpa only [nhds_within_eq_map_subtype_coe hx, image_singleton]\n    using @image_mem_map _ _ _ (coe : s \u2192 \u03b1) _ this\nend\n\n/-- The neighbourhoods filter of `x` within `s`, under the discrete topology, is equal to\nthe pure `x` filter (which is the principal filter at the singleton `{x}`.) -/\nlemma nhds_within_of_mem_discrete {s : set \u03b1} [discrete_topology s] {x : \u03b1} (hx : x \u2208 s) :\n  \ud835\udcdd[s] x = pure x :=\nle_antisymm (le_pure_iff.2 $ singleton_mem_nhds_within_of_mem_discrete hx) (pure_le_nhds_within hx)\n\nlemma filter.has_basis.exists_inter_eq_singleton_of_mem_discrete\n  {\u03b9 : Type*} {p : \u03b9 \u2192 Prop} {t : \u03b9 \u2192 set \u03b1} {s : set \u03b1} [discrete_topology s] {x : \u03b1}\n  (hb : (\ud835\udcdd x).has_basis p t) (hx : x \u2208 s) :\n  \u2203 i (hi : p i), t i \u2229 s = {x} :=\nbegin\n  rcases (nhds_within_has_basis hb s).mem_iff.1 (singleton_mem_nhds_within_of_mem_discrete hx)\n    with \u27e8i, hi, hix\u27e9,\n  exact \u27e8i, hi, subset.antisymm hix $ singleton_subset_iff.2\n    \u27e8mem_of_mem_nhds $ hb.mem_of_mem hi, hx\u27e9\u27e9\nend\n\n/-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood\nthat only meets `s` at `x`.  -/\nlemma nhds_inter_eq_singleton_of_mem_discrete {s : set \u03b1} [discrete_topology s]\n  {x : \u03b1} (hx : x \u2208 s) :\n  \u2203 U \u2208 \ud835\udcdd x, U \u2229 s = {x} :=\nby simpa using (\ud835\udcdd x).basis_sets.exists_inter_eq_singleton_of_mem_discrete hx\n\n/-- For point `x` in a discrete subset `s` of a topological space, there is a set `U`\nsuch that\n1. `U` is a punctured neighborhood of `x` (ie. `U \u222a {x}` is a neighbourhood of `x`),\n2. `U` is disjoint from `s`.\n-/\nlemma disjoint_nhds_within_of_mem_discrete {s : set \u03b1} [discrete_topology s] {x : \u03b1} (hx : x \u2208 s) :\n  \u2203 U \u2208 \ud835\udcdd[\u2260] x, disjoint U s :=\nlet \u27e8V, h, h'\u27e9 := nhds_inter_eq_singleton_of_mem_discrete hx in\n  \u27e8{x}\u1d9c \u2229 V, inter_mem_nhds_within _ h,\n    (disjoint_iff_inter_eq_empty.mpr (by { rw [inter_assoc, h', compl_inter_self] }))\u27e9\n\n/-- Let `X` be a topological space and let `s, t \u2286 X` be two subsets.  If there is an inclusion\n`t \u2286 s`, then the topological space structure on `t` induced by `X` is the same as the one\nobtained by the induced topological space structure on `s`. -/\nlemma topological_space.subset_trans {X : Type*} [tX : topological_space X]\n  {s t : set X} (ts : t \u2286 s) :\n  (subtype.topological_space : topological_space t) =\n    (subtype.topological_space : topological_space s).induced (set.inclusion ts) :=\nbegin\n  change tX.induced ((coe : s \u2192 X) \u2218 (set.inclusion ts)) =\n    topological_space.induced (set.inclusion ts) (tX.induced _),\n  rw \u2190 induced_compose,\nend\n\n/-- This lemma characterizes discrete topological spaces as those whose singletons are\nneighbourhoods. -/\nlemma discrete_topology_iff_nhds {X : Type*} [topological_space X] :\n  discrete_topology X \u2194 (nhds : X \u2192 filter X) = pure :=\nbegin\n  split,\n  { introI hX,\n    exact nhds_discrete X },\n  { intro h,\n    constructor,\n    apply eq_of_nhds_eq_nhds,\n    simp [h, nhds_bot] }\nend\n\n/-- The topology pulled-back under an inclusion `f : X \u2192 Y` from the discrete topology (`\u22a5`) is the\ndiscrete topology.\nThis version does not assume the choice of a topology on either the source `X`\nnor the target `Y` of the inclusion `f`. -/\nlemma induced_bot {X Y : Type*} {f : X \u2192 Y} (hf : function.injective f) :\n  topological_space.induced f \u22a5 = \u22a5 :=\neq_of_nhds_eq_nhds (by simp [nhds_induced, \u2190 set.image_singleton, hf.preimage_image, nhds_bot])\n\n/-- The topology induced under an inclusion `f : X \u2192 Y` from the discrete topological space `Y`\nis the discrete topology on `X`. -/\nlemma discrete_topology_induced {X Y : Type*} [tY : topological_space Y] [discrete_topology Y]\n  {f : X \u2192 Y} (hf : function.injective f) : @discrete_topology X (topological_space.induced f tY) :=\nbegin\n  constructor,\n  rw discrete_topology.eq_bot Y,\n  exact induced_bot hf\nend\n\n/-- Let `s, t \u2286 X` be two subsets of a topological space `X`.  If `t \u2286 s` and the topology induced\nby `X`on `s` is discrete, then also the topology induces on `t` is discrete.  -/\nlemma discrete_topology.of_subset {X : Type*} [topological_space X] {s t : set X}\n  (ds : discrete_topology s) (ts : t \u2286 s) :\n  discrete_topology t :=\nbegin\n  rw [topological_space.subset_trans ts, ds.eq_bot],\n  exact {eq_bot := induced_bot (set.inclusion_injective ts)}\nend\n\n/-- A T\u2082 space, also known as a Hausdorff space, is one in which for every\n  `x \u2260 y` there exists disjoint open sets around `x` and `y`. This is\n  the most widely used of the separation axioms. -/\nclass t2_space (\u03b1 : Type u) [topological_space \u03b1] : Prop :=\n(t2 : \u2200x y, x \u2260 y \u2192 \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 x \u2208 u \u2227 y \u2208 v \u2227 u \u2229 v = \u2205)\n\nlemma t2_separation [t2_space \u03b1] {x y : \u03b1} (h : x \u2260 y) :\n  \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 x \u2208 u \u2227 y \u2208 v \u2227 u \u2229 v = \u2205 :=\nt2_space.t2 x y h\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t2_space.t1_space [t2_space \u03b1] : t1_space \u03b1 :=\n\u27e8\u03bb x, is_open_compl_iff.1 $ is_open_iff_forall_mem_open.2 $ \u03bb y hxy,\nlet \u27e8u, v, hu, hv, hyu, hxv, huv\u27e9 := t2_separation (mt mem_singleton_of_eq hxy) in\n\u27e8u, \u03bb z hz1 hz2, (ext_iff.1 huv x).1 \u27e8mem_singleton_iff.1 hz2 \u25b8 hz1, hxv\u27e9, hu, hyu\u27e9\u27e9\n\nlemma eq_of_nhds_ne_bot [ht : t2_space \u03b1] {x y : \u03b1} (h : ne_bot (\ud835\udcdd x \u2293 \ud835\udcdd y)) : x = y :=\nclassical.by_contradiction $ assume : x \u2260 y,\nlet \u27e8u, v, hu, hv, hx, hy, huv\u27e9 := t2_space.t2 x y this in\nabsurd huv $ (inf_ne_bot_iff.1 h (is_open.mem_nhds hu hx) (is_open.mem_nhds hv hy)).ne_empty\n\n/-- A space is T\u2082 iff the neighbourhoods of distinct points generate the bottom filter. -/\nlemma t2_iff_nhds : t2_space \u03b1 \u2194 \u2200 {x y : \u03b1}, ne_bot (\ud835\udcdd x \u2293 \ud835\udcdd y) \u2192 x = y :=\n\u27e8assume h, by exactI \u03bb x y, eq_of_nhds_ne_bot,\n assume h, \u27e8assume x y xy,\n   have \ud835\udcdd x \u2293 \ud835\udcdd y = \u22a5 := not_ne_bot.1 $ mt h xy,\n   let \u27e8u', hu', v', hv', u'v'\u27e9 := empty_mem_iff_bot.mpr this,\n       \u27e8u, uu', uo, hu\u27e9 := mem_nhds_iff.mp hu',\n       \u27e8v, vv', vo, hv\u27e9 := mem_nhds_iff.mp hv' in\n   \u27e8u, v, uo, vo, hu, hv, by { rw [\u2190 subset_empty_iff, u'v'], exact inter_subset_inter uu' vv' }\u27e9\u27e9\u27e9\n\nlemma t2_space_iff_nhds : t2_space \u03b1 \u2194 \u2200 {x y : \u03b1}, x \u2260 y \u2192 \u2203 (U \u2208 \ud835\udcdd x) (V \u2208 \ud835\udcdd y), U \u2229 V = \u2205 :=\nbegin\n  split,\n  { rintro \u27e8h\u27e9 x y hxy,\n    rcases h x y hxy with \u27e8u, v, u_op, v_op, hx, hy, H\u27e9,\n    exact \u27e8u, u_op.mem_nhds hx, v, v_op.mem_nhds hy, H\u27e9 },\n  { refine \u03bb h, \u27e8\u03bb x y hxy, _\u27e9,\n    rcases h hxy with \u27e8u, u_in, v, v_in, H\u27e9,\n    rcases mem_nhds_iff.mp u_in with \u27e8U, hUu, U_op, hxU\u27e9,\n    rcases mem_nhds_iff.mp v_in with \u27e8V, hVv, V_op, hyV\u27e9,\n    refine \u27e8U, V, U_op, V_op, hxU, hyV, set.eq_empty_of_subset_empty _\u27e9,\n    rw \u2190 H,\n    exact set.inter_subset_inter hUu hVv }\nend\n\nlemma t2_separation_nhds [t2_space \u03b1] {x y : \u03b1} (h : x \u2260 y) :\n   \u2203 u v, u \u2208 \ud835\udcdd x \u2227 v \u2208 \ud835\udcdd y \u2227 u \u2229 v = \u2205 :=\nlet \u27e8u, v, open_u, open_v, x_in, y_in, huv\u27e9 := t2_separation h in\n\u27e8u, v, open_u.mem_nhds x_in, open_v.mem_nhds y_in, huv\u27e9\n\nlemma t2_separation_compact_nhds [locally_compact_space \u03b1]\n  [t2_space \u03b1] {x y : \u03b1} (h : x \u2260 y) :\n  \u2203 u v, u \u2208 \ud835\udcdd x \u2227 v \u2208 \ud835\udcdd y \u2227 is_compact u \u2227 is_compact v \u2227 u \u2229 v = \u2205 :=\nbegin\n  obtain \u27e8u\u2080, v\u2080, u\u2080_in, v\u2080_in, hu\u2080v\u2080\u27e9 := t2_separation_nhds h,\n  obtain \u27e8K\u2080, K\u2080_in, K\u2080_u\u2080, hK\u2080\u27e9 := local_compact_nhds u\u2080_in,\n  obtain \u27e8L\u2080, L\u2080_in, L\u2080_u\u2080, hL\u2080\u27e9 := local_compact_nhds v\u2080_in,\n  use [K\u2080, L\u2080, K\u2080_in, L\u2080_in, hK\u2080, hL\u2080],\n  apply set.eq_empty_of_subset_empty,\n  rw \u2190 hu\u2080v\u2080,\n  exact set.inter_subset_inter K\u2080_u\u2080 L\u2080_u\u2080\nend\n\nlemma t2_iff_ultrafilter :\n  t2_space \u03b1 \u2194 \u2200 {x y : \u03b1} (f : ultrafilter \u03b1), \u2191f \u2264 \ud835\udcdd x \u2192 \u2191f \u2264 \ud835\udcdd y \u2192 x = y :=\nt2_iff_nhds.trans $ by simp only [\u2190exists_ultrafilter_iff, and_imp, le_inf_iff, exists_imp_distrib]\n\nlemma is_closed_diagonal [t2_space \u03b1] : is_closed (diagonal \u03b1) :=\nbegin\n  refine is_closed_iff_cluster_pt.mpr _,\n  rintro \u27e8a\u2081, a\u2082\u27e9 h,\n  refine eq_of_nhds_ne_bot \u27e8\u03bb this : \ud835\udcdd a\u2081 \u2293 \ud835\udcdd a\u2082 = \u22a5, h.ne _\u27e9,\n  obtain \u27e8t\u2081, (ht\u2081 : t\u2081 \u2208 \ud835\udcdd a\u2081), t\u2082, (ht\u2082 : t\u2082 \u2208 \ud835\udcdd a\u2082), (h' : t\u2081 \u2229 t\u2082 = \u2205)\u27e9 :=\n    inf_eq_bot_iff.1 this,\n  rw [inf_principal_eq_bot, nhds_prod_eq],\n  apply mem_of_superset (prod_mem_prod ht\u2081 ht\u2082),\n  rintro \u27e8x, y\u27e9 \u27e8x_in, y_in\u27e9 (heq : x = y),\n  rw \u2190 heq at *,\n  have : x \u2208 t\u2081 \u2229 t\u2082 := \u27e8x_in, y_in\u27e9,\n  rwa h' at this\nend\n\nlemma t2_iff_is_closed_diagonal : t2_space \u03b1 \u2194 is_closed (diagonal \u03b1) :=\nbegin\n  split,\n  { introI h,\n    exact is_closed_diagonal },\n  { intro h,\n    constructor,\n    intros x y hxy,\n    have : (x, y) \u2208 (diagonal \u03b1)\u1d9c, by rwa [mem_compl_iff],\n    obtain \u27e8t, t_sub, t_op, xyt\u27e9 : \u2203 t \u2286 (diagonal \u03b1)\u1d9c, is_open t \u2227 (x, y) \u2208 t :=\n      is_open_iff_forall_mem_open.mp h.is_open_compl _ this,\n    rcases is_open_prod_iff.mp t_op x y xyt with \u27e8U, V, U_op, V_op, xU, yV, H\u27e9,\n    use [U, V, U_op, V_op, xU, yV],\n    have := subset.trans H t_sub,\n    rw eq_empty_iff_forall_not_mem,\n    rintros z \u27e8zU, zV\u27e9,\n    have : \u00ac (z, z) \u2208 diagonal \u03b1 := this (mk_mem_prod zU zV),\n    exact this rfl },\nend\n\nsection separated\n\nopen separated finset\n\nlemma finset_disjoint_finset_opens_of_t2 [t2_space \u03b1] :\n  \u2200 (s t : finset \u03b1), disjoint s t \u2192 separated (s : set \u03b1) t :=\nbegin\n  refine induction_on_union _ (\u03bb a b hi d, (hi d.symm).symm) (\u03bb a d, empty_right a) (\u03bb a b ab, _) _,\n  { obtain \u27e8U, V, oU, oV, aU, bV, UV\u27e9 := t2_separation (finset.disjoint_singleton.1 ab),\n    refine \u27e8U, V, oU, oV, _, _, set.disjoint_iff_inter_eq_empty.mpr UV\u27e9;\n    exact singleton_subset_set_iff.mpr \u2039_\u203a },\n  { intros a b c ac bc d,\n    apply_mod_cast union_left (ac (disjoint_of_subset_left (a.subset_union_left b) d)) (bc _),\n    exact disjoint_of_subset_left (a.subset_union_right b) d },\nend\n\nlemma point_disjoint_finset_opens_of_t2 [t2_space \u03b1] {x : \u03b1} {s : finset \u03b1} (h : x \u2209 s) :\n  separated ({x} : set \u03b1) s :=\nby exact_mod_cast finset_disjoint_finset_opens_of_t2 {x} s (finset.disjoint_singleton_left.mpr h)\n\nend separated\n\nlemma tendsto_nhds_unique [t2_space \u03b1] {f : \u03b2 \u2192 \u03b1} {l : filter \u03b2} {a b : \u03b1}\n  [ne_bot l] (ha : tendsto f l (\ud835\udcdd a)) (hb : tendsto f l (\ud835\udcdd b)) : a = b :=\neq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb\n\nlemma tendsto_nhds_unique' [t2_space \u03b1] {f : \u03b2 \u2192 \u03b1} {l : filter \u03b2} {a b : \u03b1}\n  (hl : ne_bot l) (ha : tendsto f l (\ud835\udcdd a)) (hb : tendsto f l (\ud835\udcdd b)) : a = b :=\neq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb\n\nlemma tendsto_nhds_unique_of_eventually_eq [t2_space \u03b1] {f g : \u03b2 \u2192 \u03b1} {l : filter \u03b2} {a b : \u03b1}\n  [ne_bot l] (ha : tendsto f l (\ud835\udcdd a)) (hb : tendsto g l (\ud835\udcdd b)) (hfg : f =\u1da0[l] g) :\n  a = b :=\ntendsto_nhds_unique (ha.congr' hfg) hb\n\nlemma tendsto_nhds_unique_of_frequently_eq [t2_space \u03b1] {f g : \u03b2 \u2192 \u03b1} {l : filter \u03b2} {a b : \u03b1}\n  (ha : tendsto f l (\ud835\udcdd a)) (hb : tendsto g l (\ud835\udcdd b)) (hfg : \u2203\u1da0 x in l, f x = g x) :\n  a = b :=\nhave \u2203\u1da0 z : \u03b1 \u00d7 \u03b1 in \ud835\udcdd (a, b), z.1 = z.2 := (ha.prod_mk_nhds hb).frequently hfg,\nnot_not.1 $ \u03bb hne, this (is_closed_diagonal.is_open_compl.mem_nhds hne)\n\nlemma tendsto_const_nhds_iff [t2_space \u03b1] {l : filter \u03b1} [ne_bot l] {c d : \u03b1} :\n  tendsto (\u03bb x, c) l (\ud835\udcdd d) \u2194 c = d :=\n\u27e8\u03bb h, tendsto_nhds_unique (tendsto_const_nhds) h, \u03bb h, h \u25b8 tendsto_const_nhds\u27e9\n\n/-- A T\u2082.\u2085 space, also known as a Urysohn space, is a topological space\n  where for every pair `x \u2260 y`, there are two open sets, with the intersection of closures\n  empty, one containing `x` and the other `y` . -/\nclass t2_5_space (\u03b1 : Type u) [topological_space \u03b1]: Prop :=\n(t2_5 : \u2200 x y  (h : x \u2260 y), \u2203 (U V: set \u03b1), is_open U \u2227  is_open V \u2227\n                                            closure U \u2229 closure V = \u2205 \u2227 x \u2208 U \u2227 y \u2208 V)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t2_5_space.t2_space [t2_5_space \u03b1] : t2_space \u03b1 :=\n\u27e8\u03bb x y hxy,\n  let \u27e8U, V, hU, hV, hUV, hh\u27e9 := t2_5_space.t2_5 x y hxy in\n  \u27e8U, V, hU, hV, hh.1, hh.2, subset_eq_empty (powerset_mono.mpr\n    (closure_inter_subset_inter_closure U V) subset_closure) hUV\u27e9\u27e9\n\nsection lim\nvariables [t2_space \u03b1] {f : filter \u03b1}\n\n/-!\n### Properties of `Lim` and `lim`\n\nIn this section we use explicit `nonempty \u03b1` instances for `Lim` and `lim`. This way the lemmas\nare useful without a `nonempty \u03b1` instance.\n-/\n\nlemma Lim_eq {a : \u03b1} [ne_bot f] (h : f \u2264 \ud835\udcdd a) :\n  @Lim _ _ \u27e8a\u27e9 f = a :=\ntendsto_nhds_unique (le_nhds_Lim \u27e8a, h\u27e9) h\n\nlemma Lim_eq_iff [ne_bot f] (h : \u2203 (a : \u03b1), f \u2264 nhds a) {a} : @Lim _ _ \u27e8a\u27e9 f = a \u2194 f \u2264 \ud835\udcdd a :=\n\u27e8\u03bb c, c \u25b8 le_nhds_Lim h, Lim_eq\u27e9\n\nlemma ultrafilter.Lim_eq_iff_le_nhds [compact_space \u03b1] {x : \u03b1} {F : ultrafilter \u03b1} :\n  F.Lim = x \u2194 \u2191F \u2264 \ud835\udcdd x :=\n\u27e8\u03bb h, h \u25b8 F.le_nhds_Lim, Lim_eq\u27e9\n\nlemma is_open_iff_ultrafilter' [compact_space \u03b1] (U : set \u03b1) :\n  is_open U \u2194 (\u2200 F : ultrafilter \u03b1, F.Lim \u2208 U \u2192 U \u2208 F.1) :=\nbegin\n  rw is_open_iff_ultrafilter,\n  refine \u27e8\u03bb h F hF, h F.Lim hF F F.le_nhds_Lim, _\u27e9,\n  intros cond x hx f h,\n  rw [\u2190 (ultrafilter.Lim_eq_iff_le_nhds.2 h)] at hx,\n  exact cond _ hx\nend\n\nlemma filter.tendsto.lim_eq {a : \u03b1} {f : filter \u03b2} [ne_bot f] {g : \u03b2 \u2192 \u03b1} (h : tendsto g f (\ud835\udcdd a)) :\n  @lim _ _ _ \u27e8a\u27e9 f g = a :=\nLim_eq h\n\nlemma filter.lim_eq_iff {f : filter \u03b2} [ne_bot f] {g : \u03b2 \u2192 \u03b1} (h : \u2203 a, tendsto g f (\ud835\udcdd a)) {a} :\n  @lim _ _ _ \u27e8a\u27e9 f g = a \u2194 tendsto g f (\ud835\udcdd a) :=\n\u27e8\u03bb c, c \u25b8 tendsto_nhds_lim h, filter.tendsto.lim_eq\u27e9\n\nlemma continuous.lim_eq [topological_space \u03b2] {f : \u03b2 \u2192 \u03b1} (h : continuous f) (a : \u03b2) :\n  @lim _ _ _ \u27e8f a\u27e9 (\ud835\udcdd a) f = f a :=\n(h.tendsto a).lim_eq\n\n@[simp] lemma Lim_nhds (a : \u03b1) : @Lim _ _ \u27e8a\u27e9 (\ud835\udcdd a) = a :=\nLim_eq le_rfl\n\n@[simp] lemma lim_nhds_id (a : \u03b1) : @lim _ _ _ \u27e8a\u27e9 (\ud835\udcdd a) id = a :=\nLim_nhds a\n\n@[simp] lemma Lim_nhds_within {a : \u03b1} {s : set \u03b1} (h : a \u2208 closure s) :\n  @Lim _ _ \u27e8a\u27e9 (\ud835\udcdd[s] a) = a :=\nby haveI : ne_bot (\ud835\udcdd[s] a) := mem_closure_iff_cluster_pt.1 h;\nexact Lim_eq inf_le_left\n\n@[simp] lemma lim_nhds_within_id {a : \u03b1} {s : set \u03b1} (h : a \u2208 closure s) :\n  @lim _ _ _ \u27e8a\u27e9 (\ud835\udcdd[s] a) id = a :=\nLim_nhds_within h\n\nend lim\n\n/-!\n### `t2_space` constructions\n\nWe use two lemmas to prove that various standard constructions generate Hausdorff spaces from\nHausdorff spaces:\n\n* `separated_by_continuous` says that two points `x y : \u03b1` can be separated by open neighborhoods\n  provided that there exists a continuous map `f : \u03b1 \u2192 \u03b2` with a Hausdorff codomain such that\n  `f x \u2260 f y`. We use this lemma to prove that topological spaces defined using `induced` are\n  Hausdorff spaces.\n\n* `separated_by_open_embedding` says that for an open embedding `f : \u03b1 \u2192 \u03b2` of a Hausdorff space\n  `\u03b1`, the images of two distinct points `x y : \u03b1`, `x \u2260 y` can be separated by open neighborhoods.\n  We use this lemma to prove that topological spaces defined using `coinduced` are Hausdorff spaces.\n-/\n\n@[priority 100] -- see Note [lower instance priority]\ninstance t2_space_discrete {\u03b1 : Type*} [topological_space \u03b1] [discrete_topology \u03b1] : t2_space \u03b1 :=\n{ t2 := assume x y hxy, \u27e8{x}, {y}, is_open_discrete _, is_open_discrete _, rfl, rfl,\n  eq_empty_iff_forall_not_mem.2 $ by intros z hz;\n    cases eq_of_mem_singleton hz.1; cases eq_of_mem_singleton hz.2; cc\u27e9 }\n\nlemma separated_by_continuous {\u03b1 : Type*} {\u03b2 : Type*}\n  [topological_space \u03b1] [topological_space \u03b2] [t2_space \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hf : continuous f) {x y : \u03b1} (h : f x \u2260 f y) :\n  \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 x \u2208 u \u2227 y \u2208 v \u2227 u \u2229 v = \u2205 :=\nlet \u27e8u, v, uo, vo, xu, yv, uv\u27e9 := t2_separation h in\n\u27e8f \u207b\u00b9' u, f \u207b\u00b9' v, uo.preimage hf, vo.preimage hf, xu, yv,\n  by rw [\u2190preimage_inter, uv, preimage_empty]\u27e9\n\nlemma separated_by_open_embedding {\u03b1 \u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n  [t2_space \u03b1] {f : \u03b1 \u2192 \u03b2} (hf : open_embedding f) {x y : \u03b1} (h : x \u2260 y) :\n  \u2203 u v : set \u03b2, is_open u \u2227 is_open v \u2227 f x \u2208 u \u2227 f y \u2208 v \u2227 u \u2229 v = \u2205 :=\nlet \u27e8u, v, uo, vo, xu, yv, uv\u27e9 := t2_separation h in\n\u27e8f '' u, f '' v, hf.is_open_map _ uo, hf.is_open_map _ vo,\n  mem_image_of_mem _ xu, mem_image_of_mem _ yv, by rw [image_inter hf.inj, uv, image_empty]\u27e9\n\ninstance {\u03b1 : Type*} {p : \u03b1 \u2192 Prop} [t : topological_space \u03b1] [t2_space \u03b1] : t2_space (subtype p) :=\n\u27e8assume x y h, separated_by_continuous continuous_subtype_val (mt subtype.eq h)\u27e9\n\ninstance {\u03b1 : Type*} {\u03b2 : Type*} [t\u2081 : topological_space \u03b1] [t2_space \u03b1]\n  [t\u2082 : topological_space \u03b2] [t2_space \u03b2] : t2_space (\u03b1 \u00d7 \u03b2) :=\n\u27e8assume \u27e8x\u2081,x\u2082\u27e9 \u27e8y\u2081,y\u2082\u27e9 h,\n  or.elim (not_and_distrib.mp (mt prod.ext_iff.mpr h))\n    (\u03bb h\u2081, separated_by_continuous continuous_fst h\u2081)\n    (\u03bb h\u2082, separated_by_continuous continuous_snd h\u2082)\u27e9\n\nlemma embedding.t2_space [topological_space \u03b2] [t2_space \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : embedding f) :\n  t2_space \u03b1 :=\n\u27e8\u03bb x y h, separated_by_continuous hf.continuous (hf.inj.ne h)\u27e9\n\ninstance {\u03b1 : Type*} {\u03b2 : Type*} [t\u2081 : topological_space \u03b1] [t2_space \u03b1]\n  [t\u2082 : topological_space \u03b2] [t2_space \u03b2] : t2_space (\u03b1 \u2295 \u03b2) :=\nbegin\n  constructor,\n  rintros (x|x) (y|y) h,\n  { replace h : x \u2260 y := \u03bb c, (c.subst h) rfl,\n    exact separated_by_open_embedding open_embedding_inl h },\n  { exact \u27e8_, _, is_open_range_inl, is_open_range_inr, \u27e8x, rfl\u27e9, \u27e8y, rfl\u27e9,\n      range_inl_inter_range_inr\u27e9 },\n  { exact \u27e8_, _, is_open_range_inr, is_open_range_inl, \u27e8x, rfl\u27e9, \u27e8y, rfl\u27e9,\n      range_inr_inter_range_inl\u27e9 },\n  { replace h : x \u2260 y := \u03bb c, (c.subst h) rfl,\n    exact separated_by_open_embedding open_embedding_inr h }\nend\n\ninstance Pi.t2_space {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type v} [t\u2082 : \u03a0a, topological_space (\u03b2 a)]\n  [\u2200a, t2_space (\u03b2 a)] :\n  t2_space (\u03a0a, \u03b2 a) :=\n\u27e8assume x y h,\n  let \u27e8i, hi\u27e9 := not_forall.mp (mt funext h) in\n  separated_by_continuous (continuous_apply i) hi\u27e9\n\ninstance sigma.t2_space {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} [\u03a0i, topological_space (\u03b1 i)]\n  [\u2200a, t2_space (\u03b1 a)] :\n  t2_space (\u03a3i, \u03b1 i) :=\nbegin\n  constructor,\n  rintros \u27e8i, x\u27e9 \u27e8j, y\u27e9 neq,\n  rcases em (i = j) with (rfl|h),\n  { replace neq : x \u2260 y := \u03bb c, (c.subst neq) rfl,\n    exact separated_by_open_embedding open_embedding_sigma_mk neq },\n  { exact \u27e8_, _, is_open_range_sigma_mk, is_open_range_sigma_mk, \u27e8x, rfl\u27e9, \u27e8y, rfl\u27e9, by tidy\u27e9 }\nend\n\nvariables [topological_space \u03b2]\n\nlemma is_closed_eq [t2_space \u03b1] {f g : \u03b2 \u2192 \u03b1}\n  (hf : continuous f) (hg : continuous g) : is_closed {x:\u03b2 | f x = g x} :=\ncontinuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_diagonal\n\n/-- If two continuous maps are equal on `s`, then they are equal on the closure of `s`. See also\n`set.eq_on.of_subset_closure` for a more general version. -/\nlemma set.eq_on.closure [t2_space \u03b1] {s : set \u03b2} {f g : \u03b2 \u2192 \u03b1} (h : eq_on f g s)\n  (hf : continuous f) (hg : continuous g) :\n  eq_on f g (closure s) :=\nclosure_minimal h (is_closed_eq hf hg)\n\n/-- If two continuous functions are equal on a dense set, then they are equal. -/\nlemma continuous.ext_on [t2_space \u03b1] {s : set \u03b2} (hs : dense s) {f g : \u03b2 \u2192 \u03b1}\n  (hf : continuous f) (hg : continuous g) (h : eq_on f g s) :\n  f = g :=\nfunext $ \u03bb x, h.closure hf hg (hs x)\n\n/-- If `f x = g x` for all `x \u2208 s` and `f`, `g` are continuous on `t`, `s \u2286 t \u2286 closure s`, then\n`f x = g x` for all `x \u2208 t`. See also `set.eq_on.closure`. -/\nlemma set.eq_on.of_subset_closure [t2_space \u03b1] {s t : set \u03b2} {f g : \u03b2 \u2192 \u03b1} (h : eq_on f g s)\n  (hf : continuous_on f t) (hg : continuous_on g t) (hst : s \u2286 t) (hts : t \u2286 closure s) :\n  eq_on f g t :=\nbegin\n  intros x hx,\n  haveI : (\ud835\udcdd[s] x).ne_bot, from mem_closure_iff_cluster_pt.mp (hts hx),\n  exact tendsto_nhds_unique_of_eventually_eq ((hf x hx).mono_left $ nhds_within_mono _ hst)\n    ((hg x hx).mono_left $ nhds_within_mono _ hst) (h.eventually_eq_of_mem self_mem_nhds_within)\nend\n\nlemma function.left_inverse.closed_range [t2_space \u03b1] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (h : function.left_inverse f g) (hf : continuous f) (hg : continuous g) :\n  is_closed (range g) :=\nhave eq_on (g \u2218 f) id (closure $ range g),\n  from h.right_inv_on_range.eq_on.closure (hg.comp hf) continuous_id,\nis_closed_of_closure_subset $ \u03bb x hx,\ncalc x = g (f x) : (this hx).symm\n   ... \u2208 _ : mem_range_self _\n\nlemma function.left_inverse.closed_embedding [t2_space \u03b1] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (h : function.left_inverse f g) (hf : continuous f) (hg : continuous g) :\n  closed_embedding g :=\n\u27e8h.embedding hf hg, h.closed_range hf hg\u27e9\n\nlemma diagonal_eq_range_diagonal_map {\u03b1 : Type*} : {p:\u03b1\u00d7\u03b1 | p.1 = p.2} = range (\u03bbx, (x,x)) :=\next $ assume p, iff.intro\n  (assume h, \u27e8p.1, prod.ext_iff.2 \u27e8rfl, h\u27e9\u27e9)\n  (assume \u27e8x, hx\u27e9, show p.1 = p.2, by rw \u2190hx)\n\nlemma prod_subset_compl_diagonal_iff_disjoint {\u03b1 : Type*} {s t : set \u03b1} :\n  s \u00d7\u02e2 t \u2286 {p:\u03b1\u00d7\u03b1 | p.1 = p.2}\u1d9c \u2194 s \u2229 t = \u2205 :=\nby rw [eq_empty_iff_forall_not_mem, subset_compl_comm,\n       diagonal_eq_range_diagonal_map, range_subset_iff]; simp\n\nlemma compact_compact_separated [t2_space \u03b1] {s t : set \u03b1}\n  (hs : is_compact s) (ht : is_compact t) (hst : s \u2229 t = \u2205) :\n  \u2203u v : set \u03b1, is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 u \u2229 v = \u2205 :=\nby simp only [prod_subset_compl_diagonal_iff_disjoint.symm] at \u22a2 hst;\n   exact generalized_tube_lemma hs ht is_closed_diagonal.is_open_compl hst\n\n/-- In a `t2_space`, every compact set is closed. -/\nlemma is_compact.is_closed [t2_space \u03b1] {s : set \u03b1} (hs : is_compact s) : is_closed s :=\nis_open_compl_iff.1 $ is_open_iff_forall_mem_open.mpr $ assume x hx,\n  let \u27e8u, v, uo, vo, su, xv, uv\u27e9 :=\n    compact_compact_separated hs (is_compact_singleton : is_compact {x})\n      (by rwa [inter_comm, \u2190subset_compl_iff_disjoint, singleton_subset_iff]) in\n  have v \u2286 s\u1d9c, from\n    subset_compl_comm.mp (subset.trans su (subset_compl_iff_disjoint.mpr uv)),\n\u27e8v, this, vo, by simpa using xv\u27e9\n\n@[simp] lemma filter.coclosed_compact_eq_cocompact [t2_space \u03b1] :\n  coclosed_compact \u03b1 = cocompact \u03b1 :=\nby simp [coclosed_compact, cocompact, infi_and', and_iff_right_of_imp is_compact.is_closed]\n\n/-- If `V : \u03b9 \u2192 set \u03b1` is a decreasing family of compact sets then any neighborhood of\n`\u22c2 i, V i` contains some `V i`. This is a version of `exists_subset_nhd_of_compact'` where we\ndon't need to assume each `V i` closed because it follows from compactness since `\u03b1` is\nassumed to be Hausdorff. -/\nlemma exists_subset_nhd_of_compact [t2_space \u03b1] {\u03b9 : Type*} [nonempty \u03b9] {V : \u03b9 \u2192 set \u03b1}\n  (hV : directed (\u2287) V) (hV_cpct : \u2200 i, is_compact (V i)) {U : set \u03b1}\n  (hU : \u2200 x \u2208 \u22c2 i, V i, U \u2208 \ud835\udcdd x) : \u2203 i, V i \u2286 U :=\nexists_subset_nhd_of_compact' hV hV_cpct (\u03bb i, (hV_cpct i).is_closed) hU\n\nlemma compact_exhaustion.is_closed [t2_space \u03b1] (K : compact_exhaustion \u03b1) (n : \u2115) :\n  is_closed (K n) :=\n(K.is_compact n).is_closed\n\nlemma is_compact.inter [t2_space \u03b1] {s t : set \u03b1} (hs : is_compact s) (ht : is_compact t) :\n  is_compact (s \u2229 t) :=\nhs.inter_right $ ht.is_closed\n\nlemma compact_closure_of_subset_compact [t2_space \u03b1] {s t : set \u03b1} (ht : is_compact t) (h : s \u2286 t) :\n  is_compact (closure s) :=\ncompact_of_is_closed_subset ht is_closed_closure (closure_minimal h ht.is_closed)\n\nlemma image_closure_of_compact [t2_space \u03b2]\n  {s : set \u03b1} (hs : is_compact (closure s)) {f : \u03b1 \u2192 \u03b2} (hf : continuous_on f (closure s)) :\n  f '' closure s = closure (f '' s) :=\nsubset.antisymm hf.image_closure $ closure_minimal (image_subset f subset_closure)\n  (hs.image_of_continuous_on hf).is_closed\n\n/-- If a compact set is covered by two open sets, then we can cover it by two compact subsets. -/\nlemma is_compact.binary_compact_cover [t2_space \u03b1] {K U V : set \u03b1} (hK : is_compact K)\n  (hU : is_open U) (hV : is_open V) (h2K : K \u2286 U \u222a V) :\n  \u2203 K\u2081 K\u2082 : set \u03b1, is_compact K\u2081 \u2227 is_compact K\u2082 \u2227 K\u2081 \u2286 U \u2227 K\u2082 \u2286 V \u2227 K = K\u2081 \u222a K\u2082 :=\nbegin\n  rcases compact_compact_separated (hK.diff hU) (hK.diff hV)\n    (by rwa [diff_inter_diff, diff_eq_empty]) with \u27e8O\u2081, O\u2082, h1O\u2081, h1O\u2082, h2O\u2081, h2O\u2082, hO\u27e9,\n  refine \u27e8_, _, hK.diff h1O\u2081, hK.diff h1O\u2082,\n    by rwa [diff_subset_comm], by rwa [diff_subset_comm], by rw [\u2190 diff_inter, hO, diff_empty]\u27e9\nend\n\nlemma continuous.is_closed_map [compact_space \u03b1] [t2_space \u03b2] {f : \u03b1 \u2192 \u03b2} (h : continuous f) :\n  is_closed_map f :=\n\u03bb s hs, (hs.is_compact.image h).is_closed\n\nlemma continuous.closed_embedding [compact_space \u03b1] [t2_space \u03b2] {f : \u03b1 \u2192 \u03b2} (h : continuous f)\n  (hf : function.injective f) : closed_embedding f :=\nclosed_embedding_of_continuous_injective_closed h hf h.is_closed_map\n\nsection\nopen finset function\n/-- For every finite open cover `U\u1d62` of a compact set, there exists a compact cover `K\u1d62 \u2286 U\u1d62`. -/\nlemma is_compact.finite_compact_cover [t2_space \u03b1] {s : set \u03b1} (hs : is_compact s)\n  {\u03b9} (t : finset \u03b9) (U : \u03b9 \u2192 set \u03b1) (hU : \u2200 i \u2208 t, is_open (U i)) (hsC : s \u2286 \u22c3 i \u2208 t, U i) :\n  \u2203 K : \u03b9 \u2192 set \u03b1, (\u2200 i, is_compact (K i)) \u2227 (\u2200i, K i \u2286 U i) \u2227 s = \u22c3 i \u2208 t, K i :=\nbegin\n  classical,\n  induction t using finset.induction with x t hx ih generalizing U hU s hs hsC,\n  { refine \u27e8\u03bb _, \u2205, \u03bb i, is_compact_empty, \u03bb i, empty_subset _, _\u27e9,\n    simpa only [subset_empty_iff, Union_false, Union_empty] using hsC },\n  simp only [finset.set_bUnion_insert] at hsC,\n  simp only [finset.mem_insert] at hU,\n  have hU' : \u2200 i \u2208 t, is_open (U i) := \u03bb i hi, hU i (or.inr hi),\n  rcases hs.binary_compact_cover (hU x (or.inl rfl)) (is_open_bUnion hU') hsC\n    with \u27e8K\u2081, K\u2082, h1K\u2081, h1K\u2082, h2K\u2081, h2K\u2082, hK\u27e9,\n  rcases ih U hU' h1K\u2082 h2K\u2082 with \u27e8K, h1K, h2K, h3K\u27e9,\n  refine \u27e8update K x K\u2081, _, _, _\u27e9,\n  { intros i, by_cases hi : i = x,\n    { simp only [update_same, hi, h1K\u2081] },\n    { rw [\u2190 ne.def] at hi, simp only [update_noteq hi, h1K] }},\n  { intros i, by_cases hi : i = x,\n    { simp only [update_same, hi, h2K\u2081] },\n    { rw [\u2190 ne.def] at hi, simp only [update_noteq hi, h2K] }},\n  { simp only [set_bUnion_insert_update _ hx, hK, h3K] }\nend\nend\n\nlemma locally_compact_of_compact_nhds [t2_space \u03b1] (h : \u2200 x : \u03b1, \u2203 s, s \u2208 \ud835\udcdd x \u2227 is_compact s) :\n  locally_compact_space \u03b1 :=\n\u27e8assume x n hn,\n  let \u27e8u, un, uo, xu\u27e9 := mem_nhds_iff.mp hn in\n  let \u27e8k, kx, kc\u27e9 := h x in\n  -- K is compact but not necessarily contained in N.\n  -- K \\ U is again compact and doesn't contain x, so\n  -- we may find open sets V, W separating x from K \\ U.\n  -- Then K \\ W is a compact neighborhood of x contained in U.\n  let \u27e8v, w, vo, wo, xv, kuw, vw\u27e9 :=\n    compact_compact_separated is_compact_singleton (is_compact.diff kc uo)\n      (by rw [singleton_inter_eq_empty]; exact \u03bb h, h.2 xu) in\n  have wn : w\u1d9c \u2208 \ud835\udcdd x, from\n   mem_nhds_iff.mpr\n     \u27e8v, subset_compl_iff_disjoint.mpr vw, vo, singleton_subset_iff.mp xv\u27e9,\n  \u27e8k \\ w,\n   filter.inter_mem kx wn,\n   subset.trans (diff_subset_comm.mp kuw) un,\n   kc.diff wo\u27e9\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance locally_compact_of_compact [t2_space \u03b1] [compact_space \u03b1] : locally_compact_space \u03b1 :=\nlocally_compact_of_compact_nhds (assume x, \u27e8univ, is_open_univ.mem_nhds trivial, compact_univ\u27e9)\n\n/-- In a locally compact T\u2082 space, every point has an open neighborhood with compact closure -/\nlemma exists_open_with_compact_closure [locally_compact_space \u03b1] [t2_space \u03b1] (x : \u03b1) :\n  \u2203 (U : set \u03b1), is_open U \u2227 x \u2208 U \u2227 is_compact (closure U) :=\nbegin\n  rcases exists_compact_mem_nhds x with \u27e8K, hKc, hxK\u27e9,\n  rcases mem_nhds_iff.1 hxK with \u27e8t, h1t, h2t, h3t\u27e9,\n  exact \u27e8t, h2t, h3t, compact_closure_of_subset_compact hKc h1t\u27e9\nend\n\n/--\nIn a locally compact T\u2082 space, every compact set has an open neighborhood with compact closure.\n-/\nlemma exists_open_superset_and_is_compact_closure [locally_compact_space \u03b1] [t2_space \u03b1]\n  {K : set \u03b1} (hK : is_compact K) : \u2203 V, is_open V \u2227 K \u2286 V \u2227 is_compact (closure V) :=\nbegin\n  rcases exists_compact_superset hK with \u27e8K', hK', hKK'\u27e9,\n  refine \u27e8interior K', is_open_interior, hKK',\n    compact_closure_of_subset_compact hK' interior_subset\u27e9,\nend\n\nlemma is_preirreducible_iff_subsingleton [t2_space \u03b1] (S : set \u03b1) :\n  is_preirreducible S \u2194 subsingleton S :=\nbegin\n  split,\n  { intro h,\n    constructor,\n    intros x y,\n    ext,\n    by_contradiction e,\n    obtain \u27e8U, V, hU, hV, hxU, hyV, h'\u27e9 := t2_separation e,\n    have := h U V hU hV \u27e8x, x.prop, hxU\u27e9 \u27e8y, y.prop, hyV\u27e9,\n    rw [h', inter_empty] at this,\n    exact this.some_spec },\n  { exact @@is_preirreducible_of_subsingleton _ _ }\nend\n\nlemma is_irreducible_iff_singleton [t2_space \u03b1] (S : set \u03b1) :\n  is_irreducible S \u2194 \u2203 x, S = {x} :=\nbegin\n  split,\n  { intro h,\n    rw exists_eq_singleton_iff_nonempty_unique_mem,\n    use h.1,\n    intros a ha b hb,\n    injection @@subsingleton.elim ((is_preirreducible_iff_subsingleton _).mp h.2) \u27e8_, ha\u27e9 \u27e8_, hb\u27e9 },\n  { rintro \u27e8x, rfl\u27e9, exact is_irreducible_singleton }\nend\n\nend separation\n\nsection regularity\n\n/-- A T\u2083 space, also known as a regular space (although this condition sometimes\n  omits T\u2082), is one in which for every closed `C` and `x \u2209 C`, there exist\n  disjoint open sets containing `x` and `C` respectively. -/\nclass regular_space (\u03b1 : Type u) [topological_space \u03b1] extends t0_space \u03b1 : Prop :=\n(regular : \u2200{s:set \u03b1} {a}, is_closed s \u2192 a \u2209 s \u2192 \u2203t, is_open t \u2227 s \u2286 t \u2227 \ud835\udcdd[t] a = \u22a5)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance regular_space.t1_space [regular_space \u03b1] : t1_space \u03b1 :=\nbegin\n  rw t1_space_iff_exists_open,\n  intros x y hxy,\n  obtain \u27e8U, hU, h\u27e9 := t0_space.t0 x y hxy,\n  cases h,\n  { exact \u27e8U, hU, h\u27e9 },\n  { obtain \u27e8R, hR, hh\u27e9 := regular_space.regular (is_closed_compl_iff.mpr hU) (not_not.mpr h.1),\n    obtain \u27e8V, hV, hhh\u27e9 := mem_nhds_iff.1 (filter.inf_principal_eq_bot.1 hh.2),\n    exact \u27e8R, hR, hh.1 (mem_compl h.2), hV hhh.2\u27e9 }\nend\n\nlemma nhds_is_closed [regular_space \u03b1] {a : \u03b1} {s : set \u03b1} (h : s \u2208 \ud835\udcdd a) :\n  \u2203 t \u2208 \ud835\udcdd a, t \u2286 s \u2227 is_closed t :=\nlet \u27e8s', h\u2081, h\u2082, h\u2083\u27e9 := mem_nhds_iff.mp h in\nhave \u2203t, is_open t \u2227 s'\u1d9c \u2286 t \u2227 \ud835\udcdd[t] a = \u22a5,\n  from regular_space.regular h\u2082.is_closed_compl (not_not_intro h\u2083),\nlet \u27e8t, ht\u2081, ht\u2082, ht\u2083\u27e9 := this in\n\u27e8t\u1d9c,\n  mem_of_eq_bot $ by rwa [compl_compl],\n  subset.trans (compl_subset_comm.1 ht\u2082) h\u2081,\n  is_closed_compl_iff.mpr ht\u2081\u27e9\n\nlemma closed_nhds_basis [regular_space \u03b1] (a : \u03b1) :\n  (\ud835\udcdd a).has_basis (\u03bb s : set \u03b1, s \u2208 \ud835\udcdd a \u2227 is_closed s) id :=\n\u27e8\u03bb t, \u27e8\u03bb t_in, let \u27e8s, s_in, h_st, h\u27e9 := nhds_is_closed t_in in \u27e8s, \u27e8s_in, h\u27e9, h_st\u27e9,\n       \u03bb \u27e8s, \u27e8s_in, hs\u27e9, hst\u27e9, mem_of_superset s_in hst\u27e9\u27e9\n\nlemma topological_space.is_topological_basis.exists_closure_subset [regular_space \u03b1]\n  {B : set (set \u03b1)} (hB : topological_space.is_topological_basis B) {a : \u03b1} {s : set \u03b1}\n  (h : s \u2208 \ud835\udcdd a) :\n  \u2203 t \u2208 B, a \u2208 t \u2227 closure t \u2286 s :=\nbegin\n  rcases nhds_is_closed h with \u27e8t, hat, hts, htc\u27e9,\n  rcases hB.mem_nhds_iff.1 hat with \u27e8u, huB, hau, hut\u27e9,\n  exact \u27e8u, huB, hau, (closure_minimal hut htc).trans hts\u27e9\nend\n\nlemma topological_space.is_topological_basis.nhds_basis_closure [regular_space \u03b1]\n  {B : set (set \u03b1)} (hB : topological_space.is_topological_basis B) (a : \u03b1) :\n  (\ud835\udcdd a).has_basis (\u03bb s : set \u03b1, a \u2208 s \u2227 s \u2208 B) closure :=\n\u27e8\u03bb s, \u27e8\u03bb h, let \u27e8t, htB, hat, hts\u27e9 := hB.exists_closure_subset h in \u27e8t, \u27e8hat, htB\u27e9, hts\u27e9,\n  \u03bb \u27e8t, \u27e8hat, htB\u27e9, hts\u27e9, mem_of_superset (hB.mem_nhds htB hat) (subset_closure.trans hts)\u27e9\u27e9\n\ninstance subtype.regular_space [regular_space \u03b1] {p : \u03b1 \u2192 Prop} : regular_space (subtype p) :=\n\u27e8begin\n   intros s a hs ha,\n   rcases is_closed_induced_iff.1 hs with \u27e8s, hs', rfl\u27e9,\n   rcases regular_space.regular hs' ha with \u27e8t, ht, hst, hat\u27e9,\n   refine \u27e8coe \u207b\u00b9' t, is_open_induced ht, preimage_mono hst, _\u27e9,\n   rw [nhds_within, nhds_induced, \u2190 comap_principal, \u2190 comap_inf, \u2190 nhds_within, hat, comap_bot]\n end\u27e9\n\nvariable (\u03b1)\n@[priority 100] -- see Note [lower instance priority]\ninstance regular_space.t2_space [regular_space \u03b1] : t2_space \u03b1 :=\n\u27e8\u03bb x y hxy,\nlet \u27e8s, hs, hys, hxs\u27e9 := regular_space.regular is_closed_singleton\n    (mt mem_singleton_iff.1 hxy),\n  \u27e8t, hxt, u, hsu, htu\u27e9 := empty_mem_iff_bot.2 hxs,\n  \u27e8v, hvt, hv, hxv\u27e9 := mem_nhds_iff.1 hxt in\n\u27e8v, s, hv, hs, hxv, singleton_subset_iff.1 hys,\neq_empty_of_subset_empty $ \u03bb z \u27e8hzv, hzs\u27e9, by { rw htu, exact \u27e8hvt hzv, hsu hzs\u27e9 }\u27e9\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance regular_space.t2_5_space [regular_space \u03b1] : t2_5_space \u03b1 :=\n\u27e8\u03bb x y hxy,\nlet \u27e8U, V, hU, hV, hh_1, hh_2, hUV\u27e9 := t2_space.t2 x y hxy,\n  hxcV := not_not.mpr ((interior_maximal (subset_compl_iff_disjoint.mpr hUV) hU) hh_1),\n  \u27e8R, hR, hh\u27e9 := regular_space.regular is_closed_closure (by rwa closure_eq_compl_interior_compl),\n  \u27e8A, hA, hhh\u27e9 := mem_nhds_iff.1 (filter.inf_principal_eq_bot.1 hh.2) in\n\u27e8A, V, hhh.1, hV, subset_eq_empty ((closure V).inter_subset_inter_left\n  (subset.trans (closure_minimal hA (is_closed_compl_iff.mpr hR)) (compl_subset_compl.mpr hh.1)))\n  (compl_inter_self (closure V)), hhh.2, hh_2\u27e9\u27e9\n\nvariable {\u03b1}\n\n/-- Given two points `x \u2260 y`, we can find neighbourhoods `x \u2208 V\u2081 \u2286 U\u2081` and `y \u2208 V\u2082 \u2286 U\u2082`,\nwith the `V\u2096` closed and the `U\u2096` open, such that the `U\u2096` are disjoint. -/\nlemma disjoint_nested_nhds [regular_space \u03b1] {x y : \u03b1} (h : x \u2260 y) :\n  \u2203 (U\u2081 V\u2081 \u2208 \ud835\udcdd x) (U\u2082 V\u2082 \u2208 \ud835\udcdd y), is_closed V\u2081 \u2227 is_closed V\u2082 \u2227 is_open U\u2081 \u2227 is_open U\u2082 \u2227\n  V\u2081 \u2286 U\u2081 \u2227 V\u2082 \u2286 U\u2082 \u2227 U\u2081 \u2229 U\u2082 = \u2205 :=\nbegin\n  rcases t2_separation h with \u27e8U\u2081, U\u2082, U\u2081_op, U\u2082_op, x_in, y_in, H\u27e9,\n  rcases nhds_is_closed (is_open.mem_nhds U\u2081_op x_in) with \u27e8V\u2081, V\u2081_in, h\u2081, V\u2081_closed\u27e9,\n  rcases nhds_is_closed (is_open.mem_nhds U\u2082_op y_in) with \u27e8V\u2082, V\u2082_in, h\u2082, V\u2082_closed\u27e9,\n  use [U\u2081, mem_of_superset V\u2081_in h\u2081, V\u2081, V\u2081_in,\n       U\u2082, mem_of_superset V\u2082_in h\u2082, V\u2082, V\u2082_in],\n  tauto\nend\n\n/--\nIn a locally compact regular space, given a compact set `K` inside an open set `U`, we can find a\ncompact set `K'` between these sets: `K` is inside the interior of `K'` and `K' \u2286 U`.\n-/\nlemma exists_compact_between [locally_compact_space \u03b1] [regular_space \u03b1]\n  {K U : set \u03b1} (hK : is_compact K) (hU : is_open U) (hKU : K \u2286 U) :\n  \u2203 K', is_compact K' \u2227 K \u2286 interior K' \u2227 K' \u2286 U :=\nbegin\n  choose C hxC hCU hC using \u03bb x : K, nhds_is_closed (hU.mem_nhds $ hKU x.2),\n  choose L hL hxL using \u03bb x : K, exists_compact_mem_nhds (x : \u03b1),\n  have : K \u2286 \u22c3 x, interior (L x) \u2229 interior (C x), from\n  \u03bb x hx, mem_Union.mpr \u27e8\u27e8x, hx\u27e9,\n    \u27e8mem_interior_iff_mem_nhds.mpr (hxL _), mem_interior_iff_mem_nhds.mpr (hxC _)\u27e9\u27e9,\n  rcases hK.elim_finite_subcover _ _ this with \u27e8t, ht\u27e9,\n  { refine \u27e8\u22c3 x \u2208 t, L x \u2229 C x, t.compact_bUnion (\u03bb x _, (hL x).inter_right (hC x)), \u03bb x hx, _, _\u27e9,\n    { obtain \u27e8y, hyt, hy : x \u2208 interior (L y) \u2229 interior (C y)\u27e9 := mem_Union\u2082.mp (ht hx),\n      rw [\u2190 interior_inter] at hy,\n      refine interior_mono (subset_bUnion_of_mem hyt) hy },\n    { simp_rw [Union_subset_iff], rintro x -, exact (inter_subset_right _ _).trans (hCU _) } },\n  { exact \u03bb _, is_open_interior.inter is_open_interior }\nend\n\n/--\nIn a locally compact regular space, given a compact set `K` inside an open set `U`, we can find a\nopen set `V` between these sets with compact closure: `K \u2286 V` and the closure of `V` is inside `U`.\n-/\nlemma exists_open_between_and_is_compact_closure [locally_compact_space \u03b1] [regular_space \u03b1]\n  {K U : set \u03b1} (hK : is_compact K) (hU : is_open U) (hKU : K \u2286 U) :\n  \u2203 V, is_open V \u2227 K \u2286 V \u2227 closure V \u2286 U \u2227 is_compact (closure V) :=\nbegin\n  rcases exists_compact_between hK hU hKU with \u27e8V, hV, hKV, hVU\u27e9,\n  refine \u27e8interior V, is_open_interior, hKV,\n    (closure_minimal interior_subset hV.is_closed).trans hVU,\n    compact_closure_of_subset_compact hV interior_subset\u27e9,\nend\n\nend regularity\n\nsection normality\n\n/-- A T\u2084 space, also known as a normal space (although this condition sometimes\n  omits T\u2082), is one in which for every pair of disjoint closed sets `C` and `D`,\n  there exist disjoint open sets containing `C` and `D` respectively. -/\nclass normal_space (\u03b1 : Type u) [topological_space \u03b1] extends t1_space \u03b1 : Prop :=\n(normal : \u2200 s t : set \u03b1, is_closed s \u2192 is_closed t \u2192 disjoint s t \u2192\n  \u2203 u v, is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 disjoint u v)\n\ntheorem normal_separation [normal_space \u03b1] {s t : set \u03b1}\n  (H1 : is_closed s) (H2 : is_closed t) (H3 : disjoint s t) :\n  \u2203 u v, is_open u \u2227 is_open v \u2227 s \u2286 u \u2227 t \u2286 v \u2227 disjoint u v :=\nnormal_space.normal s t H1 H2 H3\n\ntheorem normal_exists_closure_subset [normal_space \u03b1] {s t : set \u03b1} (hs : is_closed s)\n  (ht : is_open t) (hst : s \u2286 t) :\n  \u2203 u, is_open u \u2227 s \u2286 u \u2227 closure u \u2286 t :=\nbegin\n  have : disjoint s t\u1d9c, from \u03bb x \u27e8hxs, hxt\u27e9, hxt (hst hxs),\n  rcases normal_separation hs (is_closed_compl_iff.2 ht) this\n    with \u27e8s', t', hs', ht', hss', htt', hs't'\u27e9,\n  refine \u27e8s', hs', hss',\n    subset.trans (closure_minimal _ (is_closed_compl_iff.2 ht')) (compl_subset_comm.1 htt')\u27e9,\n  exact \u03bb x hxs hxt, hs't' \u27e8hxs, hxt\u27e9\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance normal_space.regular_space [normal_space \u03b1] : regular_space \u03b1 :=\n{ regular := \u03bb s x hs hxs, let \u27e8u, v, hu, hv, hsu, hxv, huv\u27e9 :=\n    normal_separation hs is_closed_singleton\n      (\u03bb _ \u27e8hx, hy\u27e9, hxs $ mem_of_eq_of_mem (eq_of_mem_singleton hy).symm hx) in\n    \u27e8u, hu, hsu, filter.empty_mem_iff_bot.1 $ filter.mem_inf_iff.2\n      \u27e8v, is_open.mem_nhds hv (singleton_subset_iff.1 hxv), u, filter.mem_principal_self u,\n       by rwa [eq_comm, inter_comm, \u2190 disjoint_iff_inter_eq_empty]\u27e9\u27e9 }\n\n-- We can't make this an instance because it could cause an instance loop.\nlemma normal_of_compact_t2 [compact_space \u03b1] [t2_space \u03b1] : normal_space \u03b1 :=\nbegin\n  refine \u27e8assume s t hs ht st, _\u27e9,\n  simp only [disjoint_iff],\n  exact compact_compact_separated hs.is_compact ht.is_compact st.eq_bot\nend\n\nvariable (\u03b1)\n\n/-- A regular topological space with second countable topology is a normal space.\nThis lemma is not an instance to avoid a loop. -/\nlemma normal_space_of_regular_second_countable [second_countable_topology \u03b1] [regular_space \u03b1] :\n  normal_space \u03b1 :=\nbegin\n  have key : \u2200 {s t : set \u03b1}, is_closed t \u2192 disjoint s t \u2192\n    \u2203 U : set (countable_basis \u03b1), (s \u2286 \u22c3 u \u2208 U, \u2191u) \u2227\n      (\u2200 u \u2208 U, disjoint (closure \u2191u) t) \u2227\n      \u2200 n : \u2115, is_closed (\u22c3 (u \u2208 U) (h : encodable.encode u \u2264 n), closure (u : set \u03b1)),\n  { intros s t hc hd,\n    rw disjoint_left at hd,\n    have : \u2200 x \u2208 s, \u2203 U \u2208 countable_basis \u03b1, x \u2208 U \u2227 disjoint (closure U) t,\n    { intros x hx,\n      rcases (is_basis_countable_basis \u03b1).exists_closure_subset (hc.is_open_compl.mem_nhds (hd hx))\n        with \u27e8u, hu, hxu, hut\u27e9,\n      exact \u27e8u, hu, hxu, disjoint_left.2 hut\u27e9 },\n    choose! U hu hxu hd,\n    set V : s \u2192 countable_basis \u03b1 := maps_to.restrict _ _ _ hu,\n    refine \u27e8range V, _, forall_range_iff.2 $ subtype.forall.2 hd, \u03bb n, _\u27e9,\n    { rw bUnion_range,\n      exact \u03bb x hx, mem_Union.2 \u27e8\u27e8x, hx\u27e9, hxu x hx\u27e9 },\n    { simp only [\u2190 supr_eq_Union, supr_and'],\n      exact is_closed_bUnion (((finite_le_nat n).preimage_embedding (encodable.encode' _)).subset $\n        inter_subset_right _ _) (\u03bb u hu, is_closed_closure) } },\n  refine \u27e8\u03bb s t hs ht hd, _\u27e9,\n  rcases key ht hd with \u27e8U, hsU, hUd, hUc\u27e9,\n  rcases key hs hd.symm with \u27e8V, htV, hVd, hVc\u27e9,\n  refine \u27e8\u22c3 u \u2208 U, \u2191u \\ \u22c3 (v \u2208 V) (hv : encodable.encode v \u2264 encodable.encode u), closure \u2191v,\n    \u22c3 v \u2208 V, \u2191v \\ \u22c3 (u \u2208 U) (hu : encodable.encode u \u2264 encodable.encode v), closure \u2191u,\n    is_open_bUnion $ \u03bb u hu, (is_open_of_mem_countable_basis u.2).sdiff (hVc _),\n    is_open_bUnion $ \u03bb v hv, (is_open_of_mem_countable_basis v.2).sdiff (hUc _),\n    \u03bb x hx, _, \u03bb x hx, _, _\u27e9,\n  { rcases mem_Union\u2082.1 (hsU hx) with \u27e8u, huU, hxu\u27e9,\n    refine mem_bUnion huU \u27e8hxu, _\u27e9,\n    simp only [mem_Union],\n    rintro \u27e8v, hvV, -, hxv\u27e9,\n    exact hVd v hvV \u27e8hxv, hx\u27e9 },\n  { rcases mem_Union\u2082.1 (htV hx) with \u27e8v, hvV, hxv\u27e9,\n    refine mem_bUnion hvV \u27e8hxv, _\u27e9,\n    simp only [mem_Union],\n    rintro \u27e8u, huU, -, hxu\u27e9,\n    exact hUd u huU \u27e8hxu, hx\u27e9 },\n  { simp only [disjoint_left, mem_Union, mem_diff, not_exists, not_and, not_forall, not_not],\n    rintro a \u27e8u, huU, hau, haV\u27e9 v hvV hav,\n    cases le_total (encodable.encode u) (encodable.encode v) with hle hle,\n    exacts [\u27e8u, huU, hle, subset_closure hau\u27e9, (haV _ hvV hle $ subset_closure hav).elim] }\nend\n\nend normality\n\n/-- In a compact t2 space, the connected component of a point equals the intersection of all\nits clopen neighbourhoods. -/\nlemma connected_component_eq_Inter_clopen [t2_space \u03b1] [compact_space \u03b1] (x : \u03b1) :\n  connected_component x = \u22c2 Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, Z :=\nbegin\n  apply eq_of_subset_of_subset connected_component_subset_Inter_clopen,\n  -- Reduce to showing that the clopen intersection is connected.\n  refine is_preconnected.subset_connected_component _ (mem_Inter.2 (\u03bb Z, Z.2.2)),\n  -- We do this by showing that any disjoint cover by two closed sets implies\n  -- that one of these closed sets must contain our whole thing.\n  -- To reduce to the case where the cover is disjoint on all of `\u03b1` we need that `s` is closed\n  have hs : @is_closed _ _inst_1 (\u22c2 (Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}), Z) :=\n    is_closed_Inter (\u03bb Z, Z.2.1.2),\n  rw (is_preconnected_iff_subset_of_fully_disjoint_closed hs),\n  intros a b ha hb hab ab_empty,\n  haveI := @normal_of_compact_t2 \u03b1 _ _ _,\n  -- Since our space is normal, we get two larger disjoint open sets containing the disjoint\n  -- closed sets. If we can show that our intersection is a subset of any of these we can then\n  -- \"descend\" this to show that it is a subset of either a or b.\n  rcases normal_separation ha hb (disjoint_iff.2 ab_empty) with \u27e8u, v, hu, hv, hau, hbv, huv\u27e9,\n  -- If we can find a clopen set around x, contained in u \u222a v, we get a disjoint decomposition\n  -- Z = Z \u2229 u \u222a Z \u2229 v of clopen sets. The intersection of all clopen neighbourhoods will then lie\n  -- in whichever of u or v x lies in and hence will be a subset of either a or b.\n  suffices : \u2203 (Z : set \u03b1), is_clopen Z \u2227 x \u2208 Z \u2227 Z \u2286 u \u222a v,\n  { cases this with Z H,\n    rw [disjoint_iff_inter_eq_empty] at huv,\n    have H1 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hu hv huv,\n    rw [union_comm] at H,\n    have H2 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hv hu (inter_comm u v \u25b8 huv),\n    by_cases (x \u2208 u),\n    -- The x \u2208 u case.\n    { left,\n      suffices : (\u22c2 (Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2286 u,\n      { rw \u2190set.disjoint_iff_inter_eq_empty at huv,\n        replace hab : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 a \u222a b := hab,\n        replace this : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 u := this,\n        exact disjoint.left_le_of_le_sup_right hab (huv.mono this hbv) },\n      { apply subset.trans _ (inter_subset_right Z u),\n        apply Inter_subset (\u03bb Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, \u2191Z)\n          \u27e8Z \u2229 u, H1, mem_inter H.2.1 h\u27e9 } },\n    -- If x \u2209 u, we get x \u2208 v since x \u2208 u \u222a v. The rest is then like the x \u2208 u case.\n    have h1 : x \u2208 v,\n    { cases (mem_union x u v).1 (mem_of_subset_of_mem (subset.trans hab\n        (union_subset_union hau hbv)) (mem_Inter.2 (\u03bb i, i.2.2))) with h1 h1,\n      { exfalso, exact h h1},\n      { exact h1} },\n    right,\n    suffices : (\u22c2 (Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2286 v,\n    { rw [inter_comm, \u2190set.disjoint_iff_inter_eq_empty] at huv,\n      replace hab : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 a \u222a b := hab,\n      replace this : (\u22c2 (Z : {Z // is_clopen Z \u2227 x \u2208 Z}), \u2191Z) \u2264 v := this,\n      exact disjoint.left_le_of_le_sup_left hab (huv.mono this hau) },\n    { apply subset.trans _ (inter_subset_right Z v),\n      apply Inter_subset (\u03bb Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, \u2191Z)\n        \u27e8Z \u2229 v, H2, mem_inter H.2.1 h1\u27e9 } },\n  -- Now we find the required Z. We utilize the fact that X \\ u \u222a v will be compact,\n  -- so there must be some finite intersection of clopen neighbourhoods of X disjoint to it,\n  -- but a finite intersection of clopen sets is clopen so we let this be our Z.\n  have H1 := ((is_closed_compl_iff.2 (hu.union hv)).is_compact.inter_Inter_nonempty\n    (\u03bb Z : {Z : set \u03b1 // is_clopen Z \u2227 x \u2208 Z}, Z) (\u03bb Z, Z.2.1.2)),\n  rw [\u2190not_imp_not, not_forall, not_nonempty_iff_eq_empty, inter_comm] at H1,\n  have huv_union := subset.trans hab (union_subset_union hau hbv),\n  rw [\u2190 compl_compl (u \u222a v), subset_compl_iff_disjoint] at huv_union,\n  cases H1 huv_union with Zi H2,\n  refine \u27e8(\u22c2 (U \u2208 Zi), subtype.val U), _, _, _\u27e9,\n  { exact is_clopen_bInter (\u03bb Z hZ, Z.2.1) },\n  { exact mem_Inter\u2082.2 (\u03bb Z hZ, Z.2.2) },\n  { rwa [not_nonempty_iff_eq_empty, inter_comm, \u2190subset_compl_iff_disjoint, compl_compl] at H2 }\nend\n\nsection profinite\n\nvariables [t2_space \u03b1]\n\n/-- A Hausdorff space with a clopen basis is totally separated. -/\nlemma tot_sep_of_zero_dim (h : is_topological_basis {s : set \u03b1 | is_clopen s}) :\n  totally_separated_space \u03b1 :=\nbegin\n  constructor,\n  rintros x - y - hxy,\n  obtain \u27e8u, v, hu, hv, xu, yv, disj\u27e9 := t2_separation hxy,\n  obtain \u27e8w, hw : is_clopen w, xw, wu\u27e9 := (is_topological_basis.mem_nhds_iff h).1\n    (is_open.mem_nhds hu xu),\n  refine \u27e8w, w\u1d9c, hw.1, (is_clopen_compl_iff.2 hw).1, xw, _, _, set.inter_compl_self w\u27e9,\n  { intro h,\n    have : y \u2208 u \u2229 v := \u27e8wu h, yv\u27e9,\n    rwa disj at this },\n  rw set.union_compl_self,\nend\n\nvariables [compact_space \u03b1]\n\n/-- A compact Hausdorff space is totally disconnected if and only if it is totally separated, this\n  is also true for locally compact spaces. -/\ntheorem compact_t2_tot_disc_iff_tot_sep :\n  totally_disconnected_space \u03b1 \u2194 totally_separated_space \u03b1 :=\nbegin\n  split,\n  { intro h, constructor,\n    rintros x - y -,\n    contrapose!,\n    intros hyp,\n    suffices : x \u2208 connected_component y,\n      by simpa [totally_disconnected_space_iff_connected_component_singleton.1 h y,\n                mem_singleton_iff],\n    rw [connected_component_eq_Inter_clopen, mem_Inter],\n    rintro \u27e8w : set \u03b1, hw : is_clopen w, hy : y \u2208 w\u27e9,\n    by_contra hx,\n    simpa using hyp w\u1d9c w (is_open_compl_iff.mpr hw.2) hw.1 hx hy },\n  apply totally_separated_space.totally_disconnected_space,\nend\n\nvariables [totally_disconnected_space \u03b1]\n\nlemma nhds_basis_clopen (x : \u03b1) : (\ud835\udcdd x).has_basis (\u03bb s : set \u03b1, x \u2208 s \u2227 is_clopen s) id :=\n\u27e8\u03bb U, begin\n  split,\n  { have : connected_component x = {x},\n      from totally_disconnected_space_iff_connected_component_singleton.mp \u2039_\u203a x,\n    rw connected_component_eq_Inter_clopen at this,\n    intros hU,\n    let N := {Z // is_clopen Z \u2227 x \u2208 Z},\n    suffices : \u2203 Z : N, Z.val \u2286 U,\n    { rcases this with \u27e8\u27e8s, hs, hs'\u27e9, hs''\u27e9,\n      exact \u27e8s, \u27e8hs', hs\u27e9, hs''\u27e9 },\n    haveI : nonempty N := \u27e8\u27e8univ, is_clopen_univ, mem_univ x\u27e9\u27e9,\n    have hNcl : \u2200 Z : N, is_closed Z.val := (\u03bb Z, Z.property.1.2),\n    have hdir : directed superset (\u03bb Z : N, Z.val),\n    { rintros \u27e8s, hs, hxs\u27e9 \u27e8t, ht, hxt\u27e9,\n      exact \u27e8\u27e8s \u2229 t, hs.inter ht, \u27e8hxs, hxt\u27e9\u27e9, inter_subset_left s t, inter_subset_right s t\u27e9 },\n    have h_nhd: \u2200 y \u2208 (\u22c2 Z : N, Z.val), U \u2208 \ud835\udcdd y,\n    { intros y y_in,\n      erw [this, mem_singleton_iff] at y_in,\n      rwa y_in },\n    exact exists_subset_nhd_of_compact_space hdir hNcl h_nhd },\n  { rintro \u27e8V, \u27e8hxV, V_op, -\u27e9, hUV : V \u2286 U\u27e9,\n    rw mem_nhds_iff,\n    exact \u27e8V, hUV, V_op, hxV\u27e9 }\nend\u27e9\n\nlemma is_topological_basis_clopen : is_topological_basis {s : set \u03b1 | is_clopen s} :=\nbegin\n  apply is_topological_basis_of_open_of_nhds (\u03bb U (hU : is_clopen U), hU.1),\n  intros x U hxU U_op,\n  have : U \u2208 \ud835\udcdd x,\n  from is_open.mem_nhds U_op hxU,\n  rcases (nhds_basis_clopen x).mem_iff.mp this with \u27e8V, \u27e8hxV, hV\u27e9, hVU : V \u2286 U\u27e9,\n  use V,\n  tauto\nend\n\n/-- Every member of an open set in a compact Hausdorff totally disconnected space\n  is contained in a clopen set contained in the open set.  -/\nlemma compact_exists_clopen_in_open {x : \u03b1} {U : set \u03b1} (is_open : is_open U) (memU : x \u2208 U) :\n    \u2203 (V : set \u03b1) (hV : is_clopen V), x \u2208 V \u2227 V \u2286 U :=\n  (is_topological_basis.mem_nhds_iff is_topological_basis_clopen).1 (is_open.mem_nhds memU)\n\nend profinite\n\nsection locally_compact\n\nvariables {H : Type*} [topological_space H] [locally_compact_space H] [t2_space H]\n\n/-- A locally compact Hausdorff totally disconnected space has a basis with clopen elements. -/\nlemma loc_compact_Haus_tot_disc_of_zero_dim [totally_disconnected_space H] :\n  is_topological_basis {s : set H | is_clopen s} :=\nbegin\n  refine is_topological_basis_of_open_of_nhds (\u03bb u hu, hu.1) _,\n  rintros x U memU hU,\n  obtain \u27e8s, comp, xs, sU\u27e9 := exists_compact_subset hU memU,\n  obtain \u27e8t, h, ht, xt\u27e9 := mem_interior.1 xs,\n  let u : set s := (coe : s \u2192 H)\u207b\u00b9' (interior s),\n  have u_open_in_s : is_open u := is_open_interior.preimage continuous_subtype_coe,\n  let X : s := \u27e8x, h xt\u27e9,\n  have Xu : X \u2208 u := xs,\n  haveI : compact_space s := is_compact_iff_compact_space.1 comp,\n  obtain \u27e8V : set s, clopen_in_s, Vx, V_sub\u27e9 := compact_exists_clopen_in_open u_open_in_s Xu,\n  have V_clopen : is_clopen ((coe : s \u2192 H) '' V),\n  { refine \u27e8_, (comp.is_closed.closed_embedding_subtype_coe.closed_iff_image_closed).1\n               clopen_in_s.2\u27e9,\n    let v : set u := (coe : u \u2192 s)\u207b\u00b9' V,\n    have : (coe : u \u2192 H) = (coe : s \u2192 H) \u2218 (coe : u \u2192 s) := rfl,\n    have f0 : embedding (coe : u \u2192 H) := embedding_subtype_coe.comp embedding_subtype_coe,\n    have f1 : open_embedding (coe : u \u2192 H),\n    { refine \u27e8f0, _\u27e9,\n      { have : set.range (coe : u \u2192 H) = interior s,\n        { rw [this, set.range_comp, subtype.range_coe, subtype.image_preimage_coe],\n          apply set.inter_eq_self_of_subset_left interior_subset, },\n        rw this,\n        apply is_open_interior } },\n    have f2 : is_open v := clopen_in_s.1.preimage continuous_subtype_coe,\n    have f3 : (coe : s \u2192 H) '' V = (coe : u \u2192 H) '' v,\n    { rw [this, image_comp coe coe, subtype.image_preimage_coe,\n          inter_eq_self_of_subset_left V_sub] },\n    rw f3,\n    apply f1.is_open_map v f2 },\n  refine \u27e8coe '' V, V_clopen, by simp [Vx, h xt], _\u27e9,\n  transitivity s,\n  { simp },\n  assumption\nend\n\n/-- A locally compact Hausdorff space is totally disconnected\n  if and only if it is totally separated. -/\ntheorem loc_compact_t2_tot_disc_iff_tot_sep :\n  totally_disconnected_space H \u2194 totally_separated_space H :=\nbegin\n  split,\n  { introI h,\n    exact tot_sep_of_zero_dim loc_compact_Haus_tot_disc_of_zero_dim, },\n  apply totally_separated_space.totally_disconnected_space,\nend\n\nend locally_compact\n\n/-- `connected_components \u03b1` is Hausdorff when `\u03b1` is Hausdorff and compact -/\ninstance connected_components.t2 [t2_space \u03b1] [compact_space \u03b1] :\n  t2_space (connected_components \u03b1) :=\nbegin\n  -- Proof follows that of: https://stacks.math.columbia.edu/tag/0900\n  -- Fix 2 distinct connected components, with points a and b\n  refine \u27e8connected_components.surjective_coe.forall\u2082.2 $ \u03bb a b ne, _\u27e9,\n  rw connected_components.coe_ne_coe at ne,\n  have h := connected_component_disjoint ne,\n  -- write \u2191b as the intersection of all clopen subsets containing it\n  rw [connected_component_eq_Inter_clopen b, disjoint_iff_inter_eq_empty] at h,\n  -- Now we show that this can be reduced to some clopen containing `\u2191b` being disjoint to `\u2191a`\n  obtain \u27e8U, V, hU, ha, hb, rfl\u27e9 : \u2203 (U : set \u03b1) (V : set (connected_components \u03b1)), is_clopen U \u2227\n    connected_component a \u2229 U = \u2205 \u2227 connected_component b \u2286 U \u2227 coe \u207b\u00b9' V = U,\n  { cases is_closed_connected_component.is_compact.elim_finite_subfamily_closed _ _ h with fin_a ha,\n    swap, { exact \u03bb Z, Z.2.1.2 },\n    -- This clopen and its complement will separate the connected components of `a` and `b`\n    set U : set \u03b1 := (\u22c2 (i : {Z // is_clopen Z \u2227 b \u2208 Z}) (H : i \u2208 fin_a), i),\n    have hU : is_clopen U := is_clopen_bInter (\u03bb i j, i.2.1),\n    exact \u27e8U, coe '' U, hU, ha, subset_Inter\u2082 (\u03bb Z _, Z.2.1.connected_component_subset Z.2.2),\n      (connected_components_preimage_image U).symm \u25b8 hU.bUnion_connected_component_eq\u27e9 },\n  rw connected_components.quotient_map_coe.is_clopen_preimage at hU,\n  refine \u27e8V\u1d9c, V, hU.compl.is_open, hU.is_open, _, hb mem_connected_component, compl_inter_self _\u27e9,\n  exact \u03bb h, flip set.nonempty.ne_empty ha \u27e8a, mem_connected_component, h\u27e9,\nend\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/topology/separation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7065529347194072}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module algebra.order.positive.field\n! leanprover-community/mathlib commit bbeb185db4ccee8ed07dc48449414ebfa39cb821\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.Field.Basic\nimport Mathlib.Algebra.Order.Positive.Ring\n\n/-!\n# Algebraic structures on the set of positive numbers\n\nIn this file we prove that the set of positive elements of a linear ordered field is a linear\nordered commutative group.\n-/\n\n\nvariable {K : Type _} [LinearOrderedField K]\n\nnamespace Positive\n\ninstance Subtype.inv : Inv { x : K // 0 < x } :=\n  \u27e8fun x => \u27e8x\u207b\u00b9, inv_pos.2 x.2\u27e9\u27e9\n\n@[simp]\ntheorem coe_inv (x : { x : K // 0 < x }) : \u2191x\u207b\u00b9 = (x\u207b\u00b9 : K) :=\n  rfl\n#align positive.coe_inv Positive.coe_inv\n\ninstance : Pow { x : K // 0 < x } \u2124 :=\n  \u27e8fun x n => \u27e8(x: K) ^ n, zpow_pos_of_pos x.2 _\u27e9\u27e9\n\n@[simp]\ntheorem coe_zpow (x : { x : K // 0 < x }) (n : \u2124) : \u2191(x ^ n) = (x : K) ^ n :=\n  rfl\n#align positive.coe_zpow Positive.coe_zpow\n\n-- porting notes: required to create the instance below\nset_option maxHeartbeats 304000\ninstance : LinearOrderedCommGroup { x : K // 0 < x } :=\n  { Positive.Subtype.inv, Positive.linearOrderedCancelCommMonoid with\n    mul_left_inv := fun a => Subtype.ext <| inv_mul_cancel a.2.ne' }\n\nend Positive\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/Positive/Field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7065529343421064}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n\n! This file was ported from Lean 3 source module data.set.intervals.unordered_interval\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Bounds.Basic\nimport Mathlib.Data.Set.Intervals.Basic\nimport Mathlib.Tactic.ScopedNS\nimport Mathlib.Tactic.Tauto\n\n/-!\n# Intervals without endpoints ordering\n\nIn any lattice `\u03b1`, we define `uIcc a b` to be `Icc (a \u2293 b) (a \u2294 b)`, which in a linear order is\nthe set of elements lying between `a` and `b`.\n\n`Icc a b` requires the assumption `a \u2264 b` to be meaningful, which is sometimes inconvenient. The\ninterval as defined in this file is always the set of things lying between `a` and `b`, regardless\nof the relative order of `a` and `b`.\n\nFor real numbers, `uIcc a b` is the same as `segment \u211d a b`.\n\nIn a product or pi type, `uIcc a b` is the smallest box containing `a` and `b`. For example,\n`uIcc (1, -1) (-1, 1) = Icc (-1, -1) (1, 1)` is the square of vertices `(1, -1)`, `(-1, -1)`,\n`(-1, 1)`, `(1, 1)`.\n\nIn `Finset \u03b1` (seen as a hypercube of dimension `Fintype.card \u03b1`), `uIcc a b` is the smallest\nsubcube containing both `a` and `b`.\n\n## Notation\n\nWe use the localized notation `[[a, b]]` for `uIcc a b`. One can open the locale `interval` to\nmake the notation available.\n\n-/\n\n\nopen Function\n\nopen OrderDual (toDual ofDual)\n\nvariable {\u03b1 \u03b2 : Type _}\n\nnamespace Set\n\nsection Lattice\n\nvariable [Lattice \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c x : \u03b1}\n\n/-- `uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included.\nNote that we define it more generally in a lattice as `Set.Icc (a \u2293 b) (a \u2294 b)`. In a product type,\n`uIcc` corresponds to the bounding box of the two elements. -/\ndef uIcc (a b : \u03b1) : Set \u03b1 := Icc (a \u2293 b) (a \u2294 b)\n#align set.uIcc Set.uIcc\n\n-- Porting note: temporarily remove `scoped[uIcc]` and use `[[]]` instead of `[]` before a\n-- workaround is found.\n-- Porting note 2 : now `scoped[Interval]` works again.\n/-- `[[a, b]]` denotes the set of elements lying between `a` and `b`, inclusive. -/\nscoped[Interval] notation \"[[\" a \", \" b \"]]\" => Set.uIcc a b\n\nopen Interval\n\n@[simp] lemma dual_uIcc (a b : \u03b1) : [[toDual a, toDual b]] = ofDual \u207b\u00b9' [[a, b]] := dual_Icc\n#align set.dual_uIcc Set.dual_uIcc\n\n@[simp]\nlemma uIcc_of_le (h : a \u2264 b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h]\n#align set.uIcc_of_le Set.uIcc_of_le\n\n@[simp]\nlemma uIcc_of_ge (h : b \u2264 a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h]\n#align set.uIcc_of_ge Set.uIcc_of_ge\n\nlemma uIcc_comm (a b : \u03b1) : [[a, b]] = [[b, a]] := by simp_rw [uIcc, inf_comm, sup_comm]\n#align set.uIcc_comm Set.uIcc_comm\n\nlemma uIcc_of_lt (h : a < b) : [[a, b]] = Icc a b := uIcc_of_le h.le\n#align set.uIcc_of_lt Set.uIcc_of_lt\nlemma uIcc_of_gt (h : b < a) : [[a, b]] = Icc b a := uIcc_of_ge h.le\n#align set.uIcc_of_gt Set.uIcc_of_gt\n\n-- Porting note: `simp` can prove this\n-- @[simp]\nlemma uIcc_self : [[a, a]] = {a} := by simp [uIcc]\n#align set.uIcc_self Set.uIcc_self\n\n@[simp] lemma nonempty_uIcc : [[a, b]].Nonempty := nonempty_Icc.2 inf_le_sup\n#align set.nonempty_uIcc Set.nonempty_uIcc\n\nlemma Icc_subset_uIcc : Icc a b \u2286 [[a, b]] := Icc_subset_Icc inf_le_left le_sup_right\n#align set.Icc_subset_uIcc Set.Icc_subset_uIcc\nlemma Icc_subset_uIcc' : Icc b a \u2286 [[a, b]] := Icc_subset_Icc inf_le_right le_sup_left\n#align set.Icc_subset_uIcc' Set.Icc_subset_uIcc'\n\n@[simp] lemma left_mem_uIcc : a \u2208 [[a, b]] := \u27e8inf_le_left, le_sup_left\u27e9\n#align set.left_mem_uIcc Set.left_mem_uIcc\n@[simp] lemma right_mem_uIcc : b \u2208 [[a, b]] := \u27e8inf_le_right, le_sup_right\u27e9\n#align set.right_mem_uIcc Set.right_mem_uIcc\n\nlemma mem_uIcc_of_le (ha : a \u2264 x) (hb : x \u2264 b) : x \u2208 [[a, b]] := Icc_subset_uIcc \u27e8ha, hb\u27e9\n#align set.mem_uIcc_of_le Set.mem_uIcc_of_le\nlemma mem_uIcc_of_ge (hb : b \u2264 x) (ha : x \u2264 a) : x \u2208 [[a, b]] := Icc_subset_uIcc' \u27e8hb, ha\u27e9\n#align set.mem_uIcc_of_ge Set.mem_uIcc_of_ge\n\nlemma uIcc_subset_uIcc (h\u2081 : a\u2081 \u2208 [[a\u2082, b\u2082]]) (h\u2082 : b\u2081 \u2208 [[a\u2082, b\u2082]]) :\n  [[a\u2081, b\u2081]] \u2286 [[a\u2082, b\u2082]] :=\n  Icc_subset_Icc (le_inf h\u2081.1 h\u2082.1) (sup_le h\u2081.2 h\u2082.2)\n#align set.uIcc_subset_uIcc Set.uIcc_subset_uIcc\n\nlemma uIcc_subset_Icc (ha : a\u2081 \u2208 Icc a\u2082 b\u2082) (hb : b\u2081 \u2208 Icc a\u2082 b\u2082) :\n  [[a\u2081, b\u2081]] \u2286 Icc a\u2082 b\u2082 :=\n  Icc_subset_Icc (le_inf ha.1 hb.1) (sup_le ha.2 hb.2)\n#align set.uIcc_subset_Icc Set.uIcc_subset_Icc\n\nlemma uIcc_subset_uIcc_iff_mem :\n  [[a\u2081, b\u2081]] \u2286 [[a\u2082, b\u2082]] \u2194 a\u2081 \u2208 [[a\u2082, b\u2082]] \u2227 b\u2081 \u2208 [[a\u2082, b\u2082]] :=\n  Iff.intro (fun h => \u27e8h left_mem_uIcc, h right_mem_uIcc\u27e9) fun h =>\n    uIcc_subset_uIcc h.1 h.2\n#align set.uIcc_subset_uIcc_iff_mem Set.uIcc_subset_uIcc_iff_mem\n\nlemma uIcc_subset_uIcc_iff_le' :\n    [[a\u2081, b\u2081]] \u2286 [[a\u2082, b\u2082]] \u2194 a\u2082 \u2293 b\u2082 \u2264 a\u2081 \u2293 b\u2081 \u2227 a\u2081 \u2294 b\u2081 \u2264 a\u2082 \u2294 b\u2082 :=\n  Icc_subset_Icc_iff inf_le_sup\n#align set.uIcc_subset_uIcc_iff_le' Set.uIcc_subset_uIcc_iff_le'\n\nlemma uIcc_subset_uIcc_right (h : x \u2208 [[a, b]]) : [[x, b]] \u2286 [[a, b]] :=\n  uIcc_subset_uIcc h right_mem_uIcc\n#align set.uIcc_subset_uIcc_right Set.uIcc_subset_uIcc_right\n\nlemma uIcc_subset_uIcc_left (h : x \u2208 [[a, b]]) : [[a, x]] \u2286 [[a, b]] :=\n  uIcc_subset_uIcc left_mem_uIcc h\n#align set.uIcc_subset_uIcc_left Set.uIcc_subset_uIcc_left\n\nlemma bdd_below_bdd_above_iff_subset_uIcc (s : Set \u03b1) :\n    BddBelow s \u2227 BddAbove s \u2194 \u2203 a b, s \u2286 [[a, b]] :=\n  bddBelow_bddAbove_iff_subset_Icc.trans\n    \u27e8fun \u27e8a, b, h\u27e9 => \u27e8a, b, fun _ hx => Icc_subset_uIcc (h hx)\u27e9, fun \u27e8_, _, h\u27e9 => \u27e8_, _, h\u27e9\u27e9\n#align set.bdd_below_bdd_above_iff_subset_uIcc Set.bdd_below_bdd_above_iff_subset_uIcc\n\nend Lattice\n\nopen Interval\n\nsection DistribLattice\n\nvariable [DistribLattice \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c x : \u03b1}\n\nlemma eq_of_mem_uIcc_of_mem_uIcc (ha : a \u2208 [[b, c]]) (hb : b \u2208 [[a, c]]) : a = b :=\n  eq_of_inf_eq_sup_eq (inf_congr_right ha.1 hb.1) <| sup_congr_right ha.2 hb.2\n#align set.eq_of_mem_uIcc_of_mem_uIcc Set.eq_of_mem_uIcc_of_mem_uIcc\n\nlemma eq_of_mem_uIcc_of_mem_uIcc' : b \u2208 [[a, c]] \u2192 c \u2208 [[a, b]] \u2192 b = c := by\n  simpa only [uIcc_comm a] using eq_of_mem_uIcc_of_mem_uIcc\n#align set.eq_of_mem_uIcc_of_mem_uIcc' Set.eq_of_mem_uIcc_of_mem_uIcc'\n\nlemma uIcc_injective_right (a : \u03b1) : Injective fun b => uIcc b a := fun b c h => by\n  rw [ext_iff] at h\n  exact eq_of_mem_uIcc_of_mem_uIcc ((h _).1 left_mem_uIcc) ((h _).2 left_mem_uIcc)\n#align set.uIcc_injective_right Set.uIcc_injective_right\n\nlemma uIcc_injective_left (a : \u03b1) : Injective (uIcc a) := by\n  simpa only [uIcc_comm] using uIcc_injective_right a\n#align set.uIcc_injective_left Set.uIcc_injective_left\n\nend DistribLattice\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] [LinearOrder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1} {a a\u2081 a\u2082 b b\u2081 b\u2082 c x : \u03b1}\n\ntheorem Icc_min_max : Icc (min a b) (max a b) = [[a, b]] :=\n  rfl\n#align set.Icc_min_max Set.Icc_min_max\n\nlemma uIcc_of_not_le (h : \u00aca \u2264 b) : [[a, b]] = Icc b a := uIcc_of_gt $ lt_of_not_ge h\n#align set.uIcc_of_not_le Set.uIcc_of_not_le\nlemma uIcc_of_not_ge (h : \u00acb \u2264 a) : [[a, b]] = Icc a b := uIcc_of_lt $ lt_of_not_ge h\n#align set.uIcc_of_not_ge Set.uIcc_of_not_ge\n\nlemma uIcc_eq_union : [[a, b]] = Icc a b \u222a Icc b a := by rw [Icc_union_Icc', max_comm] <;> rfl\n#align set.uIcc_eq_union Set.uIcc_eq_union\n\nlemma mem_uIcc : a \u2208 [[b, c]] \u2194 b \u2264 a \u2227 a \u2264 c \u2228 c \u2264 a \u2227 a \u2264 b := by simp [uIcc_eq_union]\n#align set.mem_uIcc Set.mem_uIcc\n\nlemma not_mem_uIcc_of_lt (ha : c < a) (hb : c < b) : c \u2209 [[a, b]] :=\n  not_mem_Icc_of_lt <| lt_min_iff.mpr \u27e8ha, hb\u27e9\n#align set.not_mem_uIcc_of_lt Set.not_mem_uIcc_of_lt\n\nlemma not_mem_uIcc_of_gt (ha : a < c) (hb : b < c) : c \u2209 [[a, b]] :=\n  not_mem_Icc_of_gt <| max_lt_iff.mpr \u27e8ha, hb\u27e9\n#align set.not_mem_uIcc_of_gt Set.not_mem_uIcc_of_gt\n\nlemma uIcc_subset_uIcc_iff_le :\n    [[a\u2081, b\u2081]] \u2286 [[a\u2082, b\u2082]] \u2194 min a\u2082 b\u2082 \u2264 min a\u2081 b\u2081 \u2227 max a\u2081 b\u2081 \u2264 max a\u2082 b\u2082 :=\n  uIcc_subset_uIcc_iff_le'\n#align set.uIcc_subset_uIcc_iff_le Set.uIcc_subset_uIcc_iff_le\n\n/-- A sort of triangle inequality. -/\nlemma uIcc_subset_uIcc_union_uIcc : [[a, c]] \u2286 [[a, b]] \u222a [[b, c]] := fun x => by\n  simp only [mem_uIcc, mem_union]\n  cases' le_total a c with h1 h1 <;>\n  cases' le_total x b with h2 h2 <;>\n  tauto\n#align set.uIcc_subset_uIcc_union_uIcc Set.uIcc_subset_uIcc_union_uIcc\n\nlemma monotone_or_antitone_iff_uIcc :\n    Monotone f \u2228 Antitone f \u2194 \u2200 a b c, c \u2208 [[a, b]] \u2192 f c \u2208 [[f a, f b]] := by\n  constructor\n  \u00b7 rintro (hf | hf) a b c <;> simp_rw [\u2190 Icc_min_max, \u2190 hf.map_min, \u2190 hf.map_max]\n    exacts[fun hc => \u27e8hf hc.1, hf hc.2\u27e9, fun hc => \u27e8hf hc.2, hf hc.1\u27e9]\n  contrapose!\n  rw [not_monotone_not_antitone_iff_exists_le_le]\n  rintro \u27e8a, b, c, hab, hbc, \u27e8hfab, hfcb\u27e9 | \u27e8hfba, hfbc\u27e9\u27e9\n  \u00b7 exact \u27e8a, c, b, Icc_subset_uIcc \u27e8hab, hbc\u27e9, fun h => h.2.not_lt <| max_lt hfab hfcb\u27e9\n  \u00b7 exact \u27e8a, c, b, Icc_subset_uIcc \u27e8hab, hbc\u27e9, fun h => h.1.not_lt <| lt_min hfba hfbc\u27e9\n#align set.monotone_or_antitone_iff_uIcc Set.monotone_or_antitone_iff_uIcc\n\n-- Porting note: mathport expands the syntactic sugar `\u2200 a b c \u2208 s` differently than Lean3\nlemma monotoneOn_or_antitoneOn_iff_uIcc :\n    MonotoneOn f s \u2228 AntitoneOn f s \u2194\n      \u2200 (a) (_ : a \u2208 s) (b) (_ : b \u2208 s) (c) (_ : c \u2208 s), c \u2208 [[a, b]] \u2192 f c \u2208 [[f a, f b]] :=\n  by simp [monotoneOn_iff_monotone, antitoneOn_iff_antitone, monotone_or_antitone_iff_uIcc,\n    mem_uIcc]\n#align set.monotone_on_or_antitone_on_iff_uIcc Set.monotoneOn_or_antitoneOn_iff_uIcc\n\n-- Porting note: what should the naming scheme be here? This is a term, so should be `uIoc`,\n-- but we also want to match the `Ioc` convention.\n/-- The open-closed uIcc with unordered bounds. -/\ndef uIoc : \u03b1 \u2192 \u03b1 \u2192 Set \u03b1 := fun a b => Ioc (min a b) (max a b)\n#align set.uIoc Set.uIoc\n\n-- Porting note: removed `scoped[uIcc]` temporarily before a workaround is found\n-- Below is a capital iota\n/-- `\u0399 a b` denotes the open-closed interval with unordered bounds. Here, `\u0399` is a capital iota,\ndistinguished from a capital `i`. -/\nnotation \"\u0399\" => Set.uIoc\n\n@[simp] lemma uIoc_of_le (h : a \u2264 b) : \u0399 a b = Ioc a b := by simp [uIoc, h]\n#align set.uIoc_of_le Set.uIoc_of_le\n@[simp] lemma uIoc_of_lt (h : b < a) : \u0399 a b = Ioc b a := by simp [uIoc, le_of_lt h]\n#align set.uIoc_of_lt Set.uIoc_of_lt\n\nlemma uIoc_eq_union : \u0399 a b = Ioc a b \u222a Ioc b a := by\n  cases le_total a b <;> simp [uIoc, *]\n#align set.uIoc_eq_union Set.uIoc_eq_union\n\nlemma mem_uIoc : a \u2208 \u0399 b c \u2194 b < a \u2227 a \u2264 c \u2228 c < a \u2227 a \u2264 b := by\n  rw [uIoc_eq_union, mem_union, mem_Ioc, mem_Ioc]\n#align set.mem_uIoc Set.mem_uIoc\n\nlemma not_mem_uIoc : a \u2209 \u0399 b c \u2194 a \u2264 b \u2227 a \u2264 c \u2228 c < a \u2227 b < a := by\n  simp only [uIoc_eq_union, mem_union, mem_Ioc, not_lt, \u2190 not_le]\n  tauto\n#align set.not_mem_uIoc Set.not_mem_uIoc\n\n@[simp] lemma left_mem_uIoc : a \u2208 \u0399 a b \u2194 b < a := by simp [mem_uIoc]\n#align set.left_mem_uIoc Set.left_mem_uIoc\n@[simp] lemma right_mem_uIoc : b \u2208 \u0399 a b \u2194 a < b := by simp [mem_uIoc]\n#align set.right_mem_uIoc Set.right_mem_uIoc\n\nlemma forall_uIoc_iff {P : \u03b1 \u2192 Prop} :\n    (\u2200 x \u2208 \u0399 a b, P x) \u2194 (\u2200 x \u2208 Ioc a b, P x) \u2227 \u2200 x \u2208 Ioc b a, P x := by\n  simp only [uIoc_eq_union, mem_union, or_imp, forall_and]\n#align set.forall_uIoc_iff Set.forall_uIoc_iff\n\nlemma uIoc_subset_uIoc_of_uIcc_subset_uIcc {a b c d : \u03b1}\n    (h : [[a, b]] \u2286 [[c, d]]) : \u0399 a b \u2286 \u0399 c d :=\n  Ioc_subset_Ioc (uIcc_subset_uIcc_iff_le.1 h).1 (uIcc_subset_uIcc_iff_le.1 h).2\n#align set.uIoc_subset_uIoc_of_uIcc_subset_uIcc Set.uIoc_subset_uIoc_of_uIcc_subset_uIcc\n\nlemma uIoc_comm (a b : \u03b1) : \u0399 a b = \u0399 b a := by simp only [uIoc, min_comm a b, max_comm a b]\n#align set.uIoc_comm Set.uIoc_comm\n\nlemma Ioc_subset_uIoc : Ioc a b \u2286 \u0399 a b := Ioc_subset_Ioc (min_le_left _ _) (le_max_right _ _)\n#align set.Ioc_subset_uIoc Set.Ioc_subset_uIoc\nlemma Ioc_subset_uIoc' : Ioc a b \u2286 \u0399 b a := Ioc_subset_Ioc (min_le_right _ _) (le_max_left _ _)\n#align set.Ioc_subset_uIoc' Set.Ioc_subset_uIoc'\n\nlemma eq_of_mem_uIoc_of_mem_uIoc : a \u2208 \u0399 b c \u2192 b \u2208 \u0399 a c \u2192 a = b := by\n  simp_rw [mem_uIoc]; rintro (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) <;> apply le_antisymm <;>\n    first |assumption|exact le_of_lt \u2039_\u203a|exact le_trans \u2039_\u203a (le_of_lt \u2039_\u203a)\n#align set.eq_of_mem_uIoc_of_mem_uIoc Set.eq_of_mem_uIoc_of_mem_uIoc\n\nlemma eq_of_mem_uIoc_of_mem_uIoc' : b \u2208 \u0399 a c \u2192 c \u2208 \u0399 a b \u2192 b = c := by\n  simpa only [uIoc_comm a] using eq_of_mem_uIoc_of_mem_uIoc\n#align set.eq_of_mem_uIoc_of_mem_uIoc' Set.eq_of_mem_uIoc_of_mem_uIoc'\n\nlemma eq_of_not_mem_uIoc_of_not_mem_uIoc (ha : a \u2264 c) (hb : b \u2264 c) :\n    a \u2209 \u0399 b c \u2192 b \u2209 \u0399 a c \u2192 a = b := by\n  simp_rw [not_mem_uIoc]\n  rintro (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) <;>\n      apply le_antisymm <;>\n    first |assumption|exact le_of_lt \u2039_\u203a|\n    exact absurd hb (not_le_of_lt \u2039c < b\u203a)|exact absurd ha (not_le_of_lt \u2039c < a\u203a)\n#align set.eq_of_not_mem_uIoc_of_not_mem_uIoc Set.eq_of_not_mem_uIoc_of_not_mem_uIoc\n\nlemma uIoc_injective_right (a : \u03b1) : Injective fun b => \u0399 b a := by\n  rintro b c h\n  rw [ext_iff] at h\n  obtain ha | ha := le_or_lt b a\n  \u00b7 have hb := (h b).not\n    simp only [ha, left_mem_uIoc, not_lt, true_iff_iff, not_mem_uIoc, \u2190 not_le,\n      and_true_iff, not_true, false_and_iff, not_false_iff, true_iff_iff, or_false_iff] at hb\n    refine' hb.eq_of_not_lt fun hc => _\n    simpa [ha, and_iff_right hc, \u2190 @not_le _ _ _ a, iff_not_self, -not_le] using h c\n  \u00b7 refine'\n      eq_of_mem_uIoc_of_mem_uIoc ((h _).1 <| left_mem_uIoc.2 ha)\n        ((h _).2 <| left_mem_uIoc.2 <| ha.trans_le _)\n    simpa [ha, ha.not_le, mem_uIoc] using h b\n#align set.uIoc_injective_right Set.uIoc_injective_right\n\nlemma uIoc_injective_left (a : \u03b1) : Injective (\u0399 a) := by\n  simpa only [uIoc_comm] using uIoc_injective_right a\n#align set.uIoc_injective_left Set.uIoc_injective_left\n\nend LinearOrder\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Intervals/UnorderedInterval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7065529297679934}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Bhavik Mehta\n-/\nimport .mathlib\n\n/-!\n# Numerical bounds for Szemer\u00e9di Regularity Lemma\n-/\n\nopen finset fintype\n\nvariables {\u03b1 : Type*}\n\n/-- Auxiliary function to explicit the bound on the parts.card of the equipartition in the proof of\nSzemer\u00e9di's Regularity Lemma -/\ndef exp_bound (n : \u2115) : \u2115 := n * 4^n\n\nlemma le_exp_bound : id \u2264 exp_bound :=\n\u03bb n, nat.le_mul_of_pos_right (pow_pos (by norm_num) n)\n\nlemma exp_bound_mono : monotone exp_bound :=\n\u03bb a b h, nat.mul_le_mul h (nat.pow_le_pow_of_le_right (by norm_num) h)\n\nlemma exp_bound_pos {n : \u2115} : 0 < exp_bound n \u2194 0 < n :=\nzero_lt_mul_right (pow_pos (by norm_num) _)\n\nvariables [decidable_eq \u03b1] [fintype \u03b1] {G : simple_graph \u03b1} {P : finpartition (univ : finset \u03b1)}\n  {\u03b5 : \u211d}\n\nlocal notation `m` := (card \u03b1/exp_bound P.parts.card : \u2115)\nlocal notation `a` := (card \u03b1/P.parts.card - m * 4^P.parts.card : \u2115)\n\nlemma m_pos [nonempty \u03b1] (hP\u03b1 : P.parts.card * 16^P.parts.card \u2264 card \u03b1) : 0 < m :=\nnat.div_pos ((nat.mul_le_mul_left _ (nat.pow_le_pow_of_le_left (by norm_num) _)).trans hP\u03b1)\n  (exp_bound_pos.2 (P.parts_nonempty $ univ_nonempty.ne_empty).card_pos)\n\nlemma m_coe_pos [nonempty \u03b1] (hP\u03b1 : P.parts.card * 16^P.parts.card \u2264 card \u03b1) : (0 : \u211d) < m :=\nnat.cast_pos.2 $ m_pos hP\u03b1\n\nlemma coe_m_add_one_pos : 0 < (m:\u211d) + 1 :=\nnat.cast_add_one_pos _\n\nlemma one_le_m_coe [nonempty \u03b1] (hP\u03b1 : P.parts.card * 16^P.parts.card \u2264 card \u03b1) : (1 : \u211d) \u2264 m :=\nnat.one_le_cast.2 $ m_pos hP\u03b1\n\nlemma eps_pow_five_pos (hP\u03b5 : 100 \u2264 4^P.parts.card * \u03b5^5) : 0 < \u03b5^5 :=\npos_of_mul_pos_left ((by norm_num : (0 : \u211d) < 100).trans_le hP\u03b5) (pow_nonneg (by norm_num) _)\n\nlemma eps_pos (hP\u03b5 : 100 \u2264 4^P.parts.card * \u03b5^5) : 0 < \u03b5 :=\npow_bit1_pos_iff.1 $ eps_pow_five_pos hP\u03b5\n\nlemma four_pow_pos {n : \u2115} : 0 < (4 : \u211d)^n := pow_pos (by norm_num) n\n\nlemma hundred_div_\u03b5_pow_five_le_m [nonempty \u03b1] (hP\u03b1 : P.parts.card * 16^P.parts.card \u2264 card \u03b1)\n  (hP\u03b5 : 100 \u2264 4^P.parts.card * \u03b5^5) :\n  100/\u03b5^5 \u2264 m :=\n(div_le_of_nonneg_of_le_mul (eps_pow_five_pos hP\u03b5).le four_pow_pos.le hP\u03b5).trans\nbegin\n  norm_cast,\n  rwa [nat.le_div_iff_mul_le'(exp_bound_pos.2\n    (P.parts_nonempty $ univ_nonempty.ne_empty).card_pos), exp_bound, mul_left_comm, \u2190mul_pow],\nend\n\nlemma hundred_le_m [nonempty \u03b1] (hP\u03b1 : P.parts.card * 16^P.parts.card \u2264 card \u03b1)\n  (hP\u03b5 : 100 \u2264 4^P.parts.card * \u03b5^5) (h\u03b5 : \u03b5 \u2264 1) : 100 \u2264 m :=\nby exact_mod_cast\n  (le_div_self (by norm_num) (eps_pow_five_pos hP\u03b5) (pow_le_one _ (eps_pos hP\u03b5).le h\u03b5)).trans\n    (hundred_div_\u03b5_pow_five_le_m hP\u03b1 hP\u03b5)\n\nlemma a_add_one_le_four_pow_parts_card : a + 1 \u2264 4^P.parts.card :=\nbegin\n  have h : 1 \u2264 4^P.parts.card := one_le_pow_of_one_le (by norm_num) _,\n  rw [exp_bound, \u2190nat.div_div_eq_div_mul, nat.add_le_to_le_sub _ h, tsub_le_iff_left,\n    \u2190nat.add_sub_assoc h],\n  exact nat.le_pred_of_lt (nat.lt_div_mul_add h),\nend\n\nlemma card_aux\u2081 : m * 4^P.parts.card + a = (4^P.parts.card - a) * m + a * (m + 1) :=\nby rw [mul_add, mul_one, \u2190add_assoc, \u2190add_mul, nat.sub_add_cancel\n  ((nat.le_succ _).trans a_add_one_le_four_pow_parts_card), mul_comm]\n\nlemma card_aux\u2082 {U : finset \u03b1} (hUcard : U.card = m * 4^P.parts.card + a) :\n  (4^P.parts.card - a) * m + a * (m + 1) = U.card :=\nby rw [hUcard, mul_add, mul_one, \u2190add_assoc, \u2190add_mul, nat.sub_add_cancel\n  ((nat.le_succ _).trans a_add_one_le_four_pow_parts_card), mul_comm]\n\nlemma card_aux\u2083 (hP : P.is_equipartition) {U : finset \u03b1} (hU : U \u2208 P.parts)\n  (hUcard : \u00acU.card = m * 4^P.parts.card + a) :\n  (4^P.parts.card - (a + 1)) * m + (a + 1) * (m + 1) = U.card :=\nbegin\n  have : m * 4 ^ P.parts.card \u2264 card \u03b1 / P.parts.card,\n  { rw [exp_bound, \u2190nat.div_div_eq_div_mul],\n    apply nat.div_mul_le_self },\n  rw (nat.add_sub_of_le this) at hUcard,\n  rw finpartition.is_equipartition_iff_card_parts_eq_average' at hP,\n  rw [(hP U hU).resolve_left hUcard, mul_add, mul_one, \u2190add_assoc, \u2190add_mul, nat.sub_add_cancel\n    a_add_one_le_four_pow_parts_card, \u2190add_assoc, mul_comm, nat.add_sub_of_le this],\nend\n\nlemma pow_mul_m_le_card_part (hP : P.is_equipartition) {U : finset \u03b1} (hU : U \u2208 P.parts) :\n  (4 : \u211d) ^ P.parts.card * m \u2264 U.card :=\nbegin\n  norm_cast,\n  rw [exp_bound, \u2190nat.div_div_eq_div_mul],\n  exact (nat.mul_div_le _ _).trans (hP.average_le_card_part hU),\nend\n", "meta": {"author": "b-mehta", "repo": "regularity-lemma", "sha": "cf26082b0c88fa54276e6fdc3338c15e607c52c6", "save_path": "github-repos/lean/b-mehta-regularity-lemma", "path": "github-repos/lean/b-mehta-regularity-lemma/regularity-lemma-cf26082b0c88fa54276e6fdc3338c15e607c52c6/src/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7065529284241889}}
{"text": "import tactic\n\nvariable {\u03b1 : Type*}\nvariables (s t u : set \u03b1)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u)\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n  intros x hx,\n  have xs : x \u2208 s := hx.1,\n  have xtu : x \u2208 t \u222a u := hx.2,\n  cases xtu with xt xu,\n  { left,\n    show x \u2208 s \u2229 t,\n    exact \u27e8xs, xt\u27e9 },\n  { right,\n    show x \u2208 s \u2229 u,\n    exact \u27e8xs, xu\u27e9 },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1\n\u22a2 s \u2229 (t \u222a u) \u2286 s \u2229 t \u222a s \u2229 u\n  >> intros x hx,\nx : \u03b1,\nhx : x \u2208 s \u2229 (t \u222a u)\n\u22a2 x \u2208 s \u2229 t \u222a s \u2229 u\n  >> have xs : x \u2208 s := hx.1,\nxs : x \u2208 s\n\u22a2 x \u2208 s \u2229 t \u222a s \u2229 u\n  >> have xtu : x \u2208 t \u222a u := hx.2,\n\u22a2 xtu : x \u2208 t \u222a u\n  >> cases xtu with xt xu,\n| xt : x \u2208 t\n| \u22a2 x \u2208 s \u2229 t \u222a s \u2229 u\n|   >> { left,\n| \u22a2 x \u2208 s \u2229 t\n|   >>   show x \u2208 s \u2229 t,\n| \u22a2 x \u2208 s \u2229 t\n|   >>   exact \u27e8xs, xt\u27e9 },\nxu : x \u2208 u\n\u22a2 x \u2208 s \u2229 t \u222a s \u2229 u\n  >> { right,\n\u22a2 x \u2208 s \u2229 u\n  >>   show x \u2208 s \u2229 u,\n\u22a2 x \u2208 s \u2229 u\n  >>   exact \u27e8xs, xu\u27e9 },\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n  rintros x \u27e8xs, xt | xu\u27e9,\n  { left, \n    exact \u27e8xs, xt\u27e9 },\n  { right, \n    exact \u27e8xs, xu\u27e9 },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1\n\u22a2 s \u2229 (t \u222a u) \u2286 s \u2229 t \u222a s \u2229 u\n  >> rintros x \u27e8xs, xt | xu\u27e9,\n| x : \u03b1,\n| xs : x \u2208 s,\n| xt : x \u2208 t\n| \u22a2 x \u2208 s \u2229 t \u222a s \u2229 u\n|   >> { left, \n| \u22a2 x \u2208 s \u2229 t\n|   >>   exact \u27e8xs, xt\u27e9 },\nxu : x \u2208 u\n\u22a2 x \u2208 s \u2229 t \u222a s \u2229 u\n  >> { right, \n\u22a2 x \u2208 s \u2229 u\n  >>   exact \u27e8xs, xu\u27e9 },\nno goals\n-/\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \u2229 (t \u222a u) \u2286 (s \u2229 t) \u222a (s \u2229 u) :=\nbegin\n rw set.inter_distrib_left,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u)\n-- ----------------------------------------------------------------------\n\n\nexample : (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u) :=\nbegin\n  rintros x (\u27e8xs,xt\u27e9 | \u27e8xs,xu\u27e9),\n  { split,\n    { exact xs },\n    { left,\n      exact xt }},\n  { split,\n    { exact xs },\n    { right,\n      exact xu }},\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1\n\u22a2 (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u)\n  >> rintros x (\u27e8xs,xt\u27e9 | \u27e8xs,xu\u27e9),\n| x : \u03b1,\n| xs : x \u2208 s,\n| xt : x \u2208 t\n| \u22a2 x \u2208 s \u2229 (t \u222a u)\n|   >> { split,\n| | \u22a2 x \u2208 s\n| |   >>   { exact xs },\n| | \u22a2 x \u2208 t \u222a u\n| |   >>   { left,\n| | \u22a2 x \u2208 t\n| |   >>     exact xt }},\nx : \u03b1,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 s \u2229 (t \u222a u)\n  >> { split,\n| \u22a2 x \u2208 s\n|   >>   { exact xs },\n\u22a2 x \u2208 t \u222a u\n  >>   { right,\n\u22a2 x \u2208 u\n  >>     exact xu }},\nno goals\n-/\n\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Distributiva_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7065529280468881}}
{"text": "import measure_theory.measure.measure_space\nimport probability_theory.independence\n\nnamespace ennreal\n\nlemma inv_mul_eq_iff_eq_mul {x y z : ennreal} (hnz : z \u2260 0) (hnt : z \u2260 \u22a4) :\n  x = z * y \u2194 z \u207b\u00b9 * x = y :=\nby split; rintro rfl; simp [\u2190mul_assoc, inv_mul_cancel, mul_inv_cancel, hnt, hnz]\n\nlemma to_nnreal_ne_zero {a : ennreal} (hnz : a \u2260 0) (hnt : a \u2260 \u22a4) :\n  a.to_nnreal \u2260 0 :=\nbegin\n  intro haz,\n  have : \u2191(a.to_nnreal) = (0 : ennreal) := coe_eq_zero.mpr haz,\n  rw coe_to_nnreal hnt at this,\n  contradiction\nend\n\nlemma coe_to_nnreal_inv {a : ennreal} (hnz : a \u2260 0) (hnt : a \u2260 \u22a4) :\n  \u2191(a.to_nnreal)\u207b\u00b9 = a\u207b\u00b9 :=\nbegin\n  convert coe_inv _,\n    exact (coe_to_nnreal hnt).symm,\n  exact to_nnreal_ne_zero hnz hnt\nend\n\n@[simp]\nlemma ennreal.mul_inv {a b : ennreal} (ha : a \u2260 0) (hb : b \u2260 0) (hx : a \u2260 \u22a4) (hy : b \u2260 \u22a4) :\n  (a * b)\u207b\u00b9 = a\u207b\u00b9 * b\u207b\u00b9 :=\nbegin\n  rw [\u2190 coe_to_nnreal_inv (mul_ne_zero ha hb) (mul_ne_top hx hy),\n    to_nnreal_mul, mul_inv\u2080, coe_mul,\n    coe_to_nnreal_inv ha hx, coe_to_nnreal_inv hb hy],\nend\n\nend ennreal\n\nnoncomputable theory\n\nopen measure_theory measurable_space\n\nnamespace probability_theory\n\nsection\n\nvariables {\u03b1 : Type*} [m : measurable_space \u03b1] (\u03bc : measure \u03b1)\n\nsection definitions\n\ninclude \u03bc\n\n/-- The conditional probability measure of measure `\u03bc` on set `s` is `\u03bc` restricted to `s` \nand scaled by the inverse of `\u03bc s` (to make it a probability measure). -/\ndef cond_measure (s : set \u03b1) : measure \u03b1 :=\n  (\u03bc s)\u207b\u00b9 \u2022 \u03bc.restrict s\n\nend definitions\n\nlocalized \"notation  \u03bc `[` s `|` t `]` := cond_measure \u03bc t s\" in probability_theory\nlocalized \"notation  \u03bc `[|` t`]` := cond_measure \u03bc t\" in probability_theory\n\n/-- The conditional probability measure of any finite measure on any conditionable set\nis a probability measure. -/\ninstance cond_prob_meas [is_finite_measure \u03bc] {s : set \u03b1} (hcs : \u03bc s \u2260 0) :\n  is_probability_measure (\u03bc[|s]) :=\n  \u27e8by rw [cond_measure, measure.smul_apply, measure.restrict_apply measurable_set.univ,\n    set.univ_inter, ennreal.inv_mul_cancel hcs (measure_ne_top _ s)]\u27e9\n\nvariable [is_probability_measure \u03bc]\n\nsection bayes\n\n@[simp] lemma cond_univ [is_probability_measure \u03bc] : \u03bc[|set.univ] = \u03bc :=\nby simp [cond_measure, measure_univ, measure.restrict_univ]\n\n/-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/\n@[simp] lemma cond_measure_def {a : set \u03b1} (hma : measurable_set a) (b : set \u03b1) :\n  \u03bc[b|a] = (\u03bc a)\u207b\u00b9 * \u03bc (a \u2229 b) :=\nby rw [cond_measure, measure.smul_apply, measure.restrict_apply' hma, set.inter_comm]\n\nlemma cond_cond_meas_of_cond_meas_inter {s t : set \u03b1} (hms : measurable_set s)\n  (hci : \u03bc (s \u2229 t) \u2260 0) : \u03bc[|s] t \u2260 0 :=\nbegin\n  rw cond_measure_def,\n  refine mul_ne_zero _ _,\n  exact ennreal.inv_ne_zero.mpr (measure_ne_top _ _),\n  all_goals {assumption}\nend\n\nlemma cond_meas_inter_of_cond_cond_meas {s t : set \u03b1} (hms : measurable_set s)\n  (hctcs : (\u03bc[|s]) t \u2260 0) : \u03bc (s \u2229 t) \u2260 0 :=\nbegin\n  refine (right_ne_zero_of_mul _),\n  exact (\u03bc s)\u207b\u00b9,\n  convert hctcs,\n  change \u03bc (s \u2229 t) = (\u03bc.restrict s) t,\n  rw [measure.restrict_apply' hms, set.inter_comm]\nend\n\nlemma meas_subset_ne {a b : set \u03b1} (hs : a \u2286 b) (hnz : \u03bc a \u2260 0) : \u03bc b \u2260 0 :=\n  pos_iff_ne_zero.mp (gt_of_ge_of_gt (\u03bc.mono hs) (pos_iff_ne_zero.mpr hnz))\n\n/-- Conditioning first on `a` and then on `b` results in the same measure as conditioning\non `a \u2229 b`. -/\n@[simp] lemma cond_cond_eq_cond_inter {a : set \u03b1} {b : set \u03b1} (hma : measurable_set a) (hmb : measurable_set b) (hca : \u03bc a \u2260 0)\n  (hci : \u03bc (a \u2229 b) \u2260 0) :\n  \u03bc[|a][|b] = (\u03bc[|(a \u2229 b)]) :=\nbegin\n  apply measure.ext,\n  intros s hms,\n  haveI := probability_theory.cond_prob_meas \u03bc (meas_subset_ne \u03bc (set.inter_subset_left _ _) hci),\n  simp [*, measure_ne_top],\n  conv { to_lhs, rw mul_assoc, congr, skip, rw mul_comm },\n  simp_rw \u2190 mul_assoc,\n  rw [ennreal.mul_inv_cancel hca (measure_ne_top _ a), one_mul,\n    \u2190 set.inter_assoc, mul_comm]\nend\n\n@[simp] lemma cond_inter {a : set \u03b1} (hma : measurable_set a) (hca : \u03bc a \u2260 0) (b : set \u03b1) :\n  \u03bc[b|a] * \u03bc a = \u03bc (a \u2229 b) :=\nby rw [cond_measure_def \u03bc hma b, mul_comm, \u2190mul_assoc,\n  ennreal.mul_inv_cancel hca (measure_ne_top _ a), one_mul]\n\n/-- Bayes' Theorem. -/\ntheorem bayes (a : set \u03b1) (hma : measurable_set a)\n  (b : set \u03b1) (hmb : measurable_set b) (hcb : \u03bc b \u2260 0) :\n  \u03bc[b|a] = (\u03bc a)\u207b\u00b9 * \u03bc[a|b] * (\u03bc b) :=\nby rw [mul_assoc, cond_inter \u03bc hmb hcb a, set.inter_comm, cond_measure_def _ hma]; apply_instance\n\nsection indep\n\n/-- Two measurable sets are independent if and only if conditioning on one\nis irrelevant to the probability of the other. -/\ntheorem indep_set_iff_cond_irrel {a : set \u03b1} (hma : measurable_set a)\n  {b : set \u03b1} (hmb : measurable_set b) :\n  indep_set a b \u03bc \u2194 \u03bc a \u2260 0 \u2192 \u03bc[b|a] = \u03bc b :=\nbegin\n  split; intro h,\n    intro hca, \n    rw [cond_measure_def _ hma, (indep_set_iff_measure_inter_eq_mul hma hmb \u03bc).mp h,\n      \u2190 mul_assoc, ennreal.inv_mul_cancel hca (measure_ne_top _ _), one_mul], apply_instance,\n  by_cases hca : \u03bc a = 0,\n  { rw indep_set_iff_measure_inter_eq_mul hma hmb \u03bc,\n    simp [measure_inter_null_of_null_left, hca] },\n  { have hcond := h hca,\n    refine (indep_set_iff_measure_inter_eq_mul hma hmb \u03bc).mpr _,\n    rwa [ ennreal.inv_mul_eq_iff_eq_mul hca (measure_ne_top _ _), set.inter_comm,\n      \u2190 measure.restrict_apply' hma] },\nend\n\nlemma symm_iff {\u03b1} {s\u2081 s\u2082 : set (set \u03b1)} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n  indep_sets s\u2081 s\u2082 \u03bc \u2194 indep_sets s\u2082 s\u2081 \u03bc :=\n\u27e8indep_sets.symm, indep_sets.symm\u27e9\n\ntheorem indep_set_iff_cond_irrel' (a : set \u03b1) (hma : measurable_set a) (b : set \u03b1) (hmb : measurable_set b) :\n  indep_set b a \u03bc \u2194 \u03bc a \u2260 0 \u2192 \u03bc[b|a] = \u03bc b :=\niff.trans symm_iff (indep_set_iff_cond_irrel _ hma hmb)\n\ndef cond_Indep_sets {\u03b1 \u03b9} [measurable_space \u03b1] (\u03c0 : \u03b9 \u2192 set (set \u03b1))\n  (C : set (set \u03b1)) (\u03bc : measure \u03b1 . volume_tac) : Prop :=\n\u2200 (c \u2208 C), Indep_sets \u03c0 (\u03bc[|c])\n\ndef cond_indep_sets {\u03b1} [measurable_space \u03b1] (s1 s2 : set (set \u03b1)) (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) : Prop :=\n\u2200 (c \u2208 C), indep_sets s1 s2 (\u03bc[|c])\n\ndef cond_Indep {\u03b1 \u03b9} (m : \u03b9 \u2192 measurable_space \u03b1) [measurable_space \u03b1] (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) : Prop :=\ncond_Indep_sets (\u03bb x, (m x).measurable_set') C \u03bc \n\nlemma cond_Indep_def {\u03b1 \u03b9} (m : \u03b9 \u2192 measurable_space \u03b1) [measurable_space \u03b1]\n  (C : set (set \u03b1)) (\u03bc : measure \u03b1 . volume_tac) :\n  cond_Indep m C \u03bc = \u2200 c \u2208 C, Indep m (\u03bc[|c]) := rfl\n\ndef cond_indep {\u03b1} (m\u2081 m\u2082 : measurable_space \u03b1) [measurable_space \u03b1] (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) : Prop :=\ncond_indep_sets (m\u2081.measurable_set') (m\u2082.measurable_set') C \u03bc\n\nlemma cond_indep_def {\u03b1} (m\u2081 m\u2082 : measurable_space \u03b1) [measurable_space \u03b1] (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) :\n  cond_indep m\u2081 m\u2082 C \u03bc = \u2200 c \u2208 C, indep m\u2081 m\u2082 (\u03bc[|c]) := rfl\n\ndef cond_Indep_set {\u03b1 \u03b9} [measurable_space \u03b1] (s : \u03b9 \u2192 set \u03b1) (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) : Prop :=\ncond_Indep (\u03bb i, generate_from {s i}) C \u03bc\n\nlemma cond_Indep_set_def {\u03b1 \u03b9} [measurable_space \u03b1] (s : \u03b9 \u2192 set \u03b1) (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) : cond_Indep_set s C \u03bc = \u2200 c \u2208 C, Indep_set s (\u03bc[|c]) := rfl\n\ndef cond_indep_set {\u03b1} [measurable_space \u03b1] (s t : set \u03b1) (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) : Prop :=\ncond_indep (generate_from {s}) (generate_from {t}) C \u03bc\n\ndef cond_indep_set' {\u03b1} [measurable_space \u03b1] (s t : set \u03b1) (c : set \u03b1)\n  (\u03bc : measure \u03b1 . volume_tac) : Prop :=\ncond_indep_set s t {c} \u03bc\n\nlemma cond_indep_set'.symm {\u03b1} {s t c : set \u03b1} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n  (h : cond_indep_set' s t c \u03bc) : cond_indep_set' t s c \u03bc :=\nby { intros c hc a b ha hb, rw [set.inter_comm, mul_comm], exact h c hc b a hb ha }\n\nlemma cond_indep_set'.symm_iff {\u03b1} {s t c : set \u03b1} [measurable_space \u03b1] {\u03bc : measure \u03b1} :\n  cond_indep_set' s t c \u03bc \u2194 cond_indep_set' t s c \u03bc :=\n\u27e8cond_indep_set'.symm, cond_indep_set'.symm\u27e9\n\ndef cond_indep_set_def {\u03b1} [measurable_space \u03b1] (s t : set \u03b1) (C : set (set \u03b1))\n  (\u03bc : measure \u03b1 . volume_tac) :\n  cond_indep_set s t C \u03bc = \u2200 c \u2208 C, indep_set s t (\u03bc[|c]) := rfl\n\ndef cond_indep_set_def' {\u03b1} [measurable_space \u03b1] (s t : set \u03b1) (c : set \u03b1)\n  (\u03bc : measure \u03b1 . volume_tac) :\n  cond_indep_set' s t c \u03bc = indep_set s t (\u03bc[|c]) :=\nby have : cond_indep_set' s t c \u03bc = \u2200 (x \u2208 {x | x = c}), indep_set s t (\u03bc[|x]) := rfl;\n  simp [this]\n\ndef cond_Indep_fun {\u03b1 \u03b9} [measurable_space \u03b1] {\u03b2 : \u03b9 \u2192 Type*}\n  (m : \u03a0 (x : \u03b9), measurable_space (\u03b2 x))\n  (f : \u03a0 (x : \u03b9), \u03b1 \u2192 \u03b2 x) (C : set (set \u03b1)) (\u03bc : measure \u03b1 . volume_tac) : Prop :=\ncond_Indep (\u03bb x, measurable_space.comap (f x) (m x)) C \u03bc\n\ndef cond_Indep_fun_def {\u03b1 \u03b9} [measurable_space \u03b1] {\u03b2 : \u03b9 \u2192 Type*}\n  (m : \u03a0 (x : \u03b9), measurable_space (\u03b2 x))\n  (f : \u03a0 (x : \u03b9), \u03b1 \u2192 \u03b2 x) (C : set (set \u03b1)) (\u03bc : measure \u03b1 . volume_tac) :\n  cond_Indep_fun m f C \u03bc = \u2200 c \u2208 C, Indep_fun m f (\u03bc[|c]) := rfl\n\ndef cond_indep_fun {\u03b1 \u03b2 \u03b3} [measurable_space \u03b1] [m\u03b2 : measurable_space \u03b2]\n  [m\u03b3 : measurable_space \u03b3]\n  (f : \u03b1 \u2192 \u03b2) (g : \u03b1 \u2192 \u03b3) (C : set (set \u03b1)) (\u03bc : measure \u03b1 . volume_tac) : Prop :=\ncond_indep (measurable_space.comap f m\u03b2) (measurable_space.comap g m\u03b3) C \u03bc\n\ndef cond_indep_fun_def {\u03b1 \u03b9} [measurable_space \u03b1] {\u03b2 : \u03b9 \u2192 Type*}\n  (m : \u03a0 (x : \u03b9), measurable_space (\u03b2 x))\n  (f : \u03a0 (x : \u03b9), \u03b1 \u2192 \u03b2 x) (C : set (set \u03b1)) (\u03bc : measure \u03b1 . volume_tac) :\n  cond_Indep_fun m f C \u03bc = \u2200 c \u2208 C, Indep_fun m f (\u03bc[|c]) := rfl\n\ntheorem cond_meas_inter (a : set \u03b1) {b : set \u03b1} (hmb : measurable_set b) :\n  \u03bc (b \u2229 a) \u2260 0 \u2194 (\u03bc[|b] a \u2260 0) :=\nbegin\n  split; intro hc,\n    simp [*, measure_ne_top],\n  simp [*, not_or_distrib] at hc,\n  exact hc.2\nend\n\nlemma indep_set_of_cond_null_measure (a b c : set \u03b1) (hmc : measurable_set c) (h : \u03bc c = 0) : indep_set a b (\u03bc [| c]) :=\nby rw [indep_set, indep, indep_sets]; intros; simp [hmc, h, measure_inter_null_of_null_left]\n\nlemma indep_sets_of_cond_null_measure (a b : set (set \u03b1)) (c : set \u03b1) (hmc : measurable_set c) (h : \u03bc c = 0) : indep_sets a b (\u03bc [| c]) :=\nby intros _ _ _ _; simp [hmc, h, measure_inter_null_of_null_left]\n\nlemma cond_indep_sets_univ_iff_indep_sets (s1 s2 : set (set \u03b1)) :\n  cond_indep_sets s1 s2 {set.univ} \u03bc \u2194 indep_sets s1 s2 \u03bc :=\nby simp [cond_indep_sets]\n\nlemma cond_indep_univ_iff_indep_set (m\u2081 m\u2082 : measurable_space \u03b1) :\n  @cond_indep _ m\u2081 m\u2082 m {set.univ} \u03bc \u2194 @indep _ m\u2081 m\u2082 m \u03bc :=\nby apply cond_indep_sets_univ_iff_indep_sets\n\ntheorem cond_indep_set_iff_cond_inter_irrel {a : set \u03b1} (hma : measurable_set a)\n  {b : set \u03b1} (hmb : measurable_set b) {c : set \u03b1} (hmc : measurable_set c) :\n  cond_indep_set' a b c \u03bc \u2194 \u03bc (c \u2229 a) \u2260 0 \u2192 \u03bc[b|c \u2229 a] = \u03bc[b|c] :=\nbegin\n  by_cases h : \u03bc c = 0,\n  { rw [cond_indep_set_def'],\n    refine iff_of_true (indep_set_of_cond_null_measure _ _ _ _ hmc h) _,\n    { refine not.elim _,\n      intro,\n      have := measure_inter_null_of_null_left a h,\n      contradiction } },\n  { have : \u03bc (c \u2229 a) \u2260 0 \u2192 (\u03bc[b|c \u2229 a] = \u03bc[b|c] \u2194 (\u03bc[|c][|a]) b = \u03bc[b|c]),\n    { intro h, haveI := h,\n      rw \u2190 cond_cond_eq_cond_inter \u03bc hmc hma _ h,\n      exact (meas_subset_ne _ (set.inter_subset_left _ _) h) },\n    haveI := probability_theory.cond_prob_meas \u03bc h,\n    rw [cond_indep_set_def', forall_congr this, cond_meas_inter, indep_set_iff_cond_irrel];\n    assumption }\nend\n\ntheorem cond_indep_set_iff_cond_inter_irrel' {a : set \u03b1} (hma : measurable_set a)\n  {b : set \u03b1} (hmb : measurable_set b) {c : set \u03b1} (hmc : measurable_set c)\n  : cond_indep_set' b a c \u03bc \u2194 \u03bc (c \u2229 a) \u2260 0 \u2192 \u03bc[b|c \u2229 a] = \u03bc[b|c] :=\niff.trans cond_indep_set'.symm_iff (cond_indep_set_iff_cond_inter_irrel _ hma hmb hmc)\n\nend indep\n\nend bayes\n\nend\n\nend probability_theory\n", "meta": {"author": "rish987", "repo": "lean-bayes", "sha": "b334cc4f9b4d81551b8513854c44d5ed007c2373", "save_path": "github-repos/lean/rish987-lean-bayes", "path": "github-repos/lean/rish987-lean-bayes/lean-bayes-b334cc4f9b4d81551b8513854c44d5ed007c2373/src/probability_theory/conditional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7064628398276921}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module ring_theory.fintype\n! leanprover-community/mathlib commit 327c3c0d9232d80e250dc8f65e7835b82b266ea5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Fintype.Units\n\n/-!\n# Some facts about finite rings\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\n\nopen Classical\n\n/- warning: card_units_lt -> card_units_lt is a dubious translation:\nlean 3 declaration is\n  forall (M\u2080 : Type.{u1}) [_inst_1 : MonoidWithZero.{u1} M\u2080] [_inst_2 : Nontrivial.{u1} M\u2080] [_inst_3 : Fintype.{u1} M\u2080], LT.lt.{0} Nat Nat.hasLt (Fintype.card.{u1} (Units.{u1} M\u2080 (MonoidWithZero.toMonoid.{u1} M\u2080 _inst_1)) (Units.fintype.{u1} M\u2080 (MonoidWithZero.toMonoid.{u1} M\u2080 _inst_1) _inst_3 (fun (a : M\u2080) (b : M\u2080) => Classical.propDecidable (Eq.{succ u1} M\u2080 a b)))) (Fintype.card.{u1} M\u2080 _inst_3)\nbut is expected to have type\n  forall (M\u2080 : Type.{u1}) [_inst_1 : MonoidWithZero.{u1} M\u2080] [_inst_2 : Nontrivial.{u1} M\u2080] [_inst_3 : Fintype.{u1} M\u2080], LT.lt.{0} Nat instLTNat (Fintype.card.{u1} (Units.{u1} M\u2080 (MonoidWithZero.toMonoid.{u1} M\u2080 _inst_1)) (instFintypeUnits.{u1} M\u2080 (MonoidWithZero.toMonoid.{u1} M\u2080 _inst_1) _inst_3 (fun (a : M\u2080) (b : M\u2080) => Classical.propDecidable (Eq.{succ u1} M\u2080 a b)))) (Fintype.card.{u1} M\u2080 _inst_3)\nCase conversion may be inaccurate. Consider using '#align card_units_lt card_units_lt\u2093'. -/\ntheorem card_units_lt (M\u2080 : Type _) [MonoidWithZero M\u2080] [Nontrivial M\u2080] [Fintype M\u2080] :\n    Fintype.card M\u2080\u02e3 < Fintype.card M\u2080 :=\n  Fintype.card_lt_of_injective_of_not_mem (coe : M\u2080\u02e3 \u2192 M\u2080) Units.ext not_isUnit_zero\n#align card_units_lt card_units_lt\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RingTheory/Fintype.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7064476353052922}}
{"text": "/-\nCopyright (c) 2020 Fox Thomson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fox Thomson\n\n! This file was ported from Lean 3 source module computability.language\n! leanprover-community/mathlib commit a239cd3e7ac2c7cde36c913808f9d40c411344f6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Hom.Ring\nimport Mathlib.Algebra.Order.Kleene\nimport Mathlib.Data.List.Join\nimport Mathlib.Data.Set.Lattice\n\n/-!\n# Languages\n\nThis file contains the definition and operations on formal languages over an alphabet. Note strings\nare implemented as lists over the alphabet.\nThe operations in this file define a [Kleene algebra](https://en.wikipedia.org/wiki/Kleene_algebra)\nover the languages.\n-/\n\n\nopen List Set Computability\n\nuniverse v\n\nvariable {\u03b1 \u03b2 \u03b3 : Type _}\n\n/-- A language is a set of strings over an alphabet. -/\ndef Language (\u03b1) :=\n  Set (List \u03b1)\n#align language Language\n\ninstance : Membership (List \u03b1) (Language \u03b1) := \u27e8Set.Mem\u27e9\ninstance : Singleton (List \u03b1) (Language \u03b1) := \u27e8Set.singleton\u27e9\ninstance : Insert (List \u03b1) (Language \u03b1) := \u27e8Set.insert\u27e9\ninstance : CompleteBooleanAlgebra (Language \u03b1) := Set.instCompleteBooleanAlgebraSet\n\nnamespace Language\n\nvariable {l m : Language \u03b1} {a b x : List \u03b1}\n\n-- Porting note: `reducible` attribute cannot be local.\n-- attribute [local reducible] Language\n\n/-- Zero language has no elements. -/\ninstance : Zero (Language \u03b1) :=\n  \u27e8fun _ => False\u27e9\n\n/-- `1 : Language \u03b1` contains only one element `[]`. -/\ninstance : One (Language \u03b1) :=\n  \u27e8fun l => l = []\u27e9\n\ninstance : Inhabited (Language \u03b1) :=\n  \u27e8fun _ => False\u27e9\n\n/-- The sum of two languages is their union. -/\ninstance : Add (Language \u03b1) :=\n  \u27e8((\u00b7 \u222a \u00b7) : Set (List \u03b1) \u2192 Set (List \u03b1) \u2192 Set (List \u03b1))\u27e9\n\n/-- The product of two languages `l` and `m` is the language made of the strings `x ++ y` where\n`x \u2208 l` and `y \u2208 m`. -/\ninstance : Mul (Language \u03b1) :=\n  \u27e8image2 (\u00b7 ++ \u00b7)\u27e9\n\ntheorem zero_def : (0 : Language \u03b1) = (\u2205 : Set _) :=\n  rfl\n#align language.zero_def Language.zero_def\n\ntheorem one_def : (1 : Language \u03b1) = ({[]} : Set (List \u03b1)) :=\n  rfl\n#align language.one_def Language.one_def\n\ntheorem add_def (l m : Language \u03b1) : l + m = (l \u222a m : Set (List \u03b1)) :=\n  rfl\n#align language.add_def Language.add_def\n\ntheorem mul_def (l m : Language \u03b1) : l * m = image2 (\u00b7 ++ \u00b7) l m :=\n  rfl\n#align language.mul_def Language.mul_def\n\n/-- The Kleene star of a language `L` is the set of all strings which can be written by\nconcatenating strings from `L`. -/\ninstance : KStar (Language \u03b1) := \u27e8fun l \u21a6 {x | \u2203 L : List (List \u03b1), x = L.join \u2227 \u2200 y \u2208 L, y \u2208 l}\u27e9\n\nlemma kstar_def (l : Language \u03b1) : l\u2217 = {x | \u2203 L : List (List \u03b1), x = L.join \u2227 \u2200 y \u2208 L, y \u2208 l} :=\n  rfl\n#align language.kstar_def Language.kstar_def\n\n-- Porting note: `reducible` attribute cannot be local,\n--               so this new theorem is required in place of `Set.ext`.\n@[ext]\ntheorem ext {l m : Language \u03b1} (h : \u2200 (x : List \u03b1), x \u2208 l \u2194 x \u2208 m) : l = m :=\n  Set.ext h\n\n@[simp]\ntheorem not_mem_zero (x : List \u03b1) : x \u2209 (0 : Language \u03b1) :=\n  id\n#align language.not_mem_zero Language.not_mem_zero\n\n@[simp]\ntheorem mem_one (x : List \u03b1) : x \u2208 (1 : Language \u03b1) \u2194 x = [] := by rfl\n#align language.mem_one Language.mem_one\n\ntheorem nil_mem_one : [] \u2208 (1 : Language \u03b1) :=\n  Set.mem_singleton _\n#align language.nil_mem_one Language.nil_mem_one\n\ntheorem mem_add (l m : Language \u03b1) (x : List \u03b1) : x \u2208 l + m \u2194 x \u2208 l \u2228 x \u2208 m :=\n  Iff.rfl\n#align language.mem_add Language.mem_add\n\ntheorem mem_mul : x \u2208 l * m \u2194 \u2203 a b, a \u2208 l \u2227 b \u2208 m \u2227 a ++ b = x :=\n  mem_image2\n#align language.mem_mul Language.mem_mul\n\ntheorem append_mem_mul : a \u2208 l \u2192 b \u2208 m \u2192 a ++ b \u2208 l * m :=\n  mem_image2_of_mem\n#align language.append_mem_mul Language.append_mem_mul\n\ntheorem mem_kstar : x \u2208 l\u2217 \u2194 \u2203 L : List (List \u03b1), x = L.join \u2227 \u2200 y \u2208 L, y \u2208 l :=\n  Iff.rfl\n#align language.mem_kstar Language.mem_kstar\n\ntheorem join_mem_kstar {L : List (List \u03b1)} (h : \u2200 y \u2208 L, y \u2208 l) : L.join \u2208 l\u2217 :=\n  \u27e8L, rfl, h\u27e9\n#align language.join_mem_kstar Language.join_mem_kstar\n\ntheorem nil_mem_kstar (l : Language \u03b1) : [] \u2208 l\u2217 :=\n  \u27e8[], rfl, fun _ h \u21a6 by contradiction\u27e9\n#align language.nil_mem_kstar Language.nil_mem_kstar\n\ninstance : Semiring (Language \u03b1) where\n  add := (\u00b7 + \u00b7)\n  add_assoc := union_assoc\n  zero := 0\n  zero_add := empty_union\n  add_zero := union_empty\n  add_comm := union_comm\n  mul := (\u00b7 * \u00b7)\n  mul_assoc _ _ _ := image2_assoc append_assoc\n  zero_mul _ := image2_empty_left\n  mul_zero _ := image2_empty_right\n  one := 1\n  one_mul l := by simp [mul_def, one_def]\n  mul_one l := by simp [mul_def, one_def]\n  natCast n := if n = 0 then 0 else 1\n  natCast_zero := rfl\n  natCast_succ n := by cases n <;> simp [Nat.cast, add_def, zero_def]\n  left_distrib _ _ _ := image2_union_right\n  right_distrib _ _ _ := image2_union_left\n\n@[simp]\ntheorem add_self (l : Language \u03b1) : l + l = l :=\n  sup_idem\n#align language.add_self Language.add_self\n\n/-- Maps the alphabet of a language. -/\ndef map (f : \u03b1 \u2192 \u03b2) : Language \u03b1 \u2192+* Language \u03b2 where\n  toFun := image (List.map f)\n  map_zero' := image_empty _\n  map_one' := image_singleton\n  map_add' := image_union _\n  map_mul' _ _ := image_image2_distrib <| map_append _\n#align language.map Language.map\n\n@[simp]\ntheorem map_id (l : Language \u03b1) : map id l = l := by simp [map]\n#align language.map_id Language.map_id\n\n@[simp]\ntheorem map_map (g : \u03b2 \u2192 \u03b3) (f : \u03b1 \u2192 \u03b2) (l : Language \u03b1) : map g (map f l) = map (g \u2218 f) l := by\n  simp [map, image_image]\n#align language.map_map Language.map_map\n\ntheorem kstar_def_nonempty (l : Language \u03b1) :\n    l\u2217 = { x | \u2203 S : List (List \u03b1), x = S.join \u2227 \u2200 y \u2208 S, y \u2208 l \u2227 y \u2260 [] } := by\n  ext x\n  constructor\n  \u00b7 rintro \u27e8S, rfl, h\u27e9\n    refine' \u27e8S.filter fun l \u21a6 \u00acList.isEmpty l, by simp, fun y hy \u21a6 _\u27e9\n    simp [mem_filter, List.isEmpty_iff_eq_nil] at hy\n    -- Porting note: The previous code was:\n    -- exact \u27e8h y hy.1, hy.2\u27e9\n    --\n    -- The goal `y \u2260 []` for the second argument cannot be resolved\n    -- by `hy.2 : isEmpty y = false`.\n    let \u27e8hyl, hyr\u27e9 := hy\n    apply And.intro (h y hyl)\n    cases y <;> simp only [ne_eq, not_true, not_false_iff]\n    contradiction\n  \u00b7 rintro \u27e8S, hx, h\u27e9\n    exact \u27e8S, hx, fun y hy \u21a6 (h y hy).1\u27e9\n#align language.kstar_def_nonempty Language.kstar_def_nonempty\n\ntheorem le_iff (l m : Language \u03b1) : l \u2264 m \u2194 l + m = m :=\n  sup_eq_right.symm\n#align language.le_iff Language.le_iff\n\ntheorem le_mul_congr {l\u2081 l\u2082 m\u2081 m\u2082 : Language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 * l\u2082 \u2264 m\u2081 * m\u2082 := by\n  intro h\u2081 h\u2082 x hx\n  simp only [mul_def, exists_and_left, mem_image2, image_prod] at hx\u22a2\n  tauto\n#align language.le_mul_congr Language.le_mul_congr\n\ntheorem le_add_congr {l\u2081 l\u2082 m\u2081 m\u2082 : Language \u03b1} : l\u2081 \u2264 m\u2081 \u2192 l\u2082 \u2264 m\u2082 \u2192 l\u2081 + l\u2082 \u2264 m\u2081 + m\u2082 :=\n  sup_le_sup\n#align language.le_add_congr Language.le_add_congr\n\ntheorem mem_sup\u1d62 {\u03b9 : Sort v} {l : \u03b9 \u2192 Language \u03b1} {x : List \u03b1} : (x \u2208 \u2a06 i, l i) \u2194 \u2203 i, x \u2208 l i :=\n  mem_union\u1d62\n#align language.mem_supr Language.mem_sup\u1d62\n\ntheorem sup\u1d62_mul {\u03b9 : Sort v} (l : \u03b9 \u2192 Language \u03b1) (m : Language \u03b1) :\n    (\u2a06 i, l i) * m = \u2a06 i, l i * m :=\n  image2_union\u1d62_left _ _ _\n#align language.supr_mul Language.sup\u1d62_mul\n\ntheorem mul_sup\u1d62 {\u03b9 : Sort v} (l : \u03b9 \u2192 Language \u03b1) (m : Language \u03b1) :\n    (m * \u2a06 i, l i) = \u2a06 i, m * l i :=\n  image2_union\u1d62_right _ _ _\n#align language.mul_supr Language.mul_sup\u1d62\n\ntheorem sup\u1d62_add {\u03b9 : Sort v} [Nonempty \u03b9] (l : \u03b9 \u2192 Language \u03b1) (m : Language \u03b1) :\n    (\u2a06 i, l i) + m = \u2a06 i, l i + m :=\n  sup\u1d62_sup\n#align language.supr_add Language.sup\u1d62_add\n\ntheorem add_sup\u1d62 {\u03b9 : Sort v} [Nonempty \u03b9] (l : \u03b9 \u2192 Language \u03b1) (m : Language \u03b1) :\n    (m + \u2a06 i, l i) = \u2a06 i, m + l i :=\n  sup_sup\u1d62\n#align language.add_supr Language.add_sup\u1d62\n\ntheorem mem_pow {l : Language \u03b1} {x : List \u03b1} {n : \u2115} :\n    x \u2208 l ^ n \u2194 \u2203 S : List (List \u03b1), x = S.join \u2227 S.length = n \u2227 \u2200 y \u2208 S, y \u2208 l := by\n  induction' n with n ihn generalizing x\n  \u00b7 simp only [mem_one, pow_zero, length_eq_zero]\n    constructor\n    \u00b7 rintro rfl\n      exact \u27e8[], rfl, rfl, fun _ h \u21a6 by contradiction\u27e9\n    \u00b7 -- Porting note: The previous code was:\n      -- rintro \u27e8_, rfl, rfl, _\u27e9\n      -- rfl\n      --\n      -- The code reports an error for the second `rfl`.\n      rintro \u27e8_, rfl, h\u2080, _\u27e9\n      simp; intros _ h\u2081\n      rw [length_eq_zero] at h\u2080\n      rw [h\u2080] at h\u2081\n      contradiction\n  \u00b7 simp only [pow_succ, mem_mul, ihn]\n    constructor\n    \u00b7 rintro \u27e8a, b, ha, \u27e8S, rfl, rfl, hS\u27e9, rfl\u27e9\n      exact \u27e8a :: S, rfl, rfl, forall_mem_cons.2 \u27e8ha, hS\u27e9\u27e9\n    \u00b7 rintro \u27e8_ | \u27e8a, S\u27e9, rfl, hn, hS\u27e9 <;> cases hn\n      rw [forall_mem_cons] at hS\n      exact \u27e8a, _, hS.1, \u27e8S, rfl, rfl, hS.2\u27e9, rfl\u27e9\n#align language.mem_pow Language.mem_pow\n\ntheorem kstar_eq_sup\u1d62_pow (l : Language \u03b1) : l\u2217 = \u2a06 i : \u2115, l ^ i := by\n  ext x\n  simp only [mem_kstar, mem_sup\u1d62, mem_pow]\n  constructor\n  \u00b7 rintro \u27e8S, rfl, hS\u27e9\n    exact \u27e8_, S, rfl, rfl, hS\u27e9\n  \u00b7 rintro \u27e8_, S, rfl, rfl, hS\u27e9\n    exact \u27e8S, rfl, hS\u27e9\n#align language.kstar_eq_supr_pow Language.kstar_eq_sup\u1d62_pow\n\n@[simp]\ntheorem map_kstar (f : \u03b1 \u2192 \u03b2) (l : Language \u03b1) : map f l\u2217 = (map f l)\u2217 := by\n  rw [kstar_eq_sup\u1d62_pow, kstar_eq_sup\u1d62_pow]\n  simp_rw [\u2190 map_pow]\n  exact image_union\u1d62\n#align language.map_kstar Language.map_kstar\n\ntheorem mul_self_kstar_comm (l : Language \u03b1) : l\u2217 * l = l * l\u2217 := by\n  simp only [kstar_eq_sup\u1d62_pow, mul_sup\u1d62, sup\u1d62_mul, \u2190 pow_succ, \u2190 pow_succ']\n#align language.mul_self_kstar_comm Language.mul_self_kstar_comm\n\n@[simp]\ntheorem one_add_self_mul_kstar_eq_kstar (l : Language \u03b1) : 1 + l * l\u2217 = l\u2217 := by\n  simp only [kstar_eq_sup\u1d62_pow, mul_sup\u1d62, \u2190 pow_succ, \u2190 pow_zero l]\n  exact sup_sup\u1d62_nat_succ _\n#align language.one_add_self_mul_kstar_eq_kstar Language.one_add_self_mul_kstar_eq_kstar\n\n@[simp]\ntheorem one_add_kstar_mul_self_eq_kstar (l : Language \u03b1) : 1 + l\u2217 * l = l\u2217 := by\n  rw [mul_self_kstar_comm, one_add_self_mul_kstar_eq_kstar]\n#align language.one_add_kstar_mul_self_eq_kstar Language.one_add_kstar_mul_self_eq_kstar\n\n-- Porting note: `noncomputable` required.\nnoncomputable instance : KleeneAlgebra (Language \u03b1) :=\n  { Language.instSemiringLanguage, Set.instCompleteBooleanAlgebraSet,\n      Language.instKStarLanguage with\n    one_le_kstar := fun a l hl \u21a6 \u27e8[], hl, by simp\u27e9,\n    mul_kstar_le_kstar := fun a \u21a6 (one_add_self_mul_kstar_eq_kstar a).le.trans' le_sup_right,\n    kstar_mul_le_kstar := fun a \u21a6 (one_add_kstar_mul_self_eq_kstar a).le.trans' le_sup_right,\n    kstar_mul_le_self := fun l m h \u21a6 by\n      rw [kstar_eq_sup\u1d62_pow, sup\u1d62_mul]\n      refine' sup\u1d62_le (fun n \u21a6 _)\n      induction' n with n ih\n      \u00b7 simp\n      rw [pow_succ', mul_assoc (l^n) l m]\n      exact le_trans (le_mul_congr le_rfl h) ih,\n    mul_kstar_le_self := fun l m h \u21a6 by\n      rw [kstar_eq_sup\u1d62_pow, mul_sup\u1d62]\n      refine' sup\u1d62_le (fun n \u21a6 _)\n      induction' n with n ih\n      \u00b7 simp\n      rw [pow_succ, \u2190mul_assoc m l (l^n)]\n      exact le_trans (le_mul_congr h le_rfl) ih }\n\nend Language\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Computability/Language.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563824, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7064476311618858}}
{"text": "/-\nCopyright (c) 2018 Reid Barton. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Reid Barton, Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.eq_to_hom\n! leanprover-community/mathlib commit 34ee86e6a59d911a8e4f89b68793ee7577ae79c7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.CategoryTheory.Opposites\n\n/-!\n# Morphisms from equations between objects.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWhen working categorically, sometimes one encounters an equation `h : X = Y` between objects.\n\nYour initial aversion to this is natural and appropriate:\nyou're in for some trouble, and if there is another way to approach the problem that won't\nrely on this equality, it may be worth pursuing.\n\nYou have two options:\n1. Use the equality `h` as one normally would in Lean (e.g. using `rw` and `subst`).\n   This may immediately cause difficulties, because in category theory everything is dependently\n   typed, and equations between objects quickly lead to nasty goals with `eq.rec`.\n2. Promote `h` to a morphism using `eq_to_hom h : X \u27f6 Y`, or `eq_to_iso h : X \u2245 Y`.\n\nThis file introduces various `simp` lemmas which in favourable circumstances\nresult in the various `eq_to_hom` morphisms to drop out at the appropriate moment!\n-/\n\n\nuniverse v\u2081 v\u2082 v\u2083 u\u2081 u\u2082 u\u2083\n\n-- morphism levels before object levels. See note [category_theory universes].\nnamespace CategoryTheory\n\nopen Opposite\n\nvariable {C : Type u\u2081} [Category.{v\u2081} C]\n\n#print CategoryTheory.eqToHom /-\n/-- An equality `X = Y` gives us a morphism `X \u27f6 Y`.\n\nIt is typically better to use this, rather than rewriting by the equality then using `\ud835\udfd9 _`\nwhich usually leads to dependent type theory hell.\n-/\ndef eqToHom {X Y : C} (p : X = Y) : X \u27f6 Y := by rw [p] <;> exact \ud835\udfd9 _\n#align category_theory.eq_to_hom CategoryTheory.eqToHom\n-/\n\n#print CategoryTheory.eqToHom_refl /-\n@[simp]\ntheorem eqToHom_refl (X : C) (p : X = X) : eqToHom p = \ud835\udfd9 X :=\n  rfl\n#align category_theory.eq_to_hom_refl CategoryTheory.eqToHom_refl\n-/\n\n#print CategoryTheory.eqToHom_trans /-\n@[simp, reassoc.1]\ntheorem eqToHom_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :\n    eqToHom p \u226b eqToHom q = eqToHom (p.trans q) :=\n  by\n  cases p\n  cases q\n  simp\n#align category_theory.eq_to_hom_trans CategoryTheory.eqToHom_trans\n-/\n\n#print CategoryTheory.comp_eqToHom_iff /-\ntheorem comp_eqToHom_iff {X Y Y' : C} (p : Y = Y') (f : X \u27f6 Y) (g : X \u27f6 Y') :\n    f \u226b eqToHom p = g \u2194 f = g \u226b eqToHom p.symm :=\n  { mp := fun h => h \u25b8 by simp\n    mpr := fun h => by simp [eq_whisker h (eq_to_hom p)] }\n#align category_theory.comp_eq_to_hom_iff CategoryTheory.comp_eqToHom_iff\n-/\n\n#print CategoryTheory.eqToHom_comp_iff /-\ntheorem eqToHom_comp_iff {X X' Y : C} (p : X = X') (f : X \u27f6 Y) (g : X' \u27f6 Y) :\n    eqToHom p \u226b g = f \u2194 g = eqToHom p.symm \u226b f :=\n  { mp := fun h => h \u25b8 by simp\n    mpr := fun h => h \u25b8 by simp [whisker_eq _ h] }\n#align category_theory.eq_to_hom_comp_iff CategoryTheory.eqToHom_comp_iff\n-/\n\n#print CategoryTheory.congrArg_mpr_hom_left /-\n/-- If we (perhaps unintentionally) perform equational rewriting on\nthe source object of a morphism,\nwe can replace the resulting `_.mpr f` term by a composition with an `eq_to_hom`.\n\nIt may be advisable to introduce any necessary `eq_to_hom` morphisms manually,\nrather than relying on this lemma firing.\n-/\n@[simp]\ntheorem congrArg_mpr_hom_left {X Y Z : C} (p : X = Y) (q : Y \u27f6 Z) :\n    (congr_arg (fun W : C => W \u27f6 Z) p).mpr q = eqToHom p \u226b q :=\n  by\n  cases p\n  simp\n#align category_theory.congr_arg_mpr_hom_left CategoryTheory.congrArg_mpr_hom_left\n-/\n\n#print CategoryTheory.congrArg_mpr_hom_right /-\n/-- If we (perhaps unintentionally) perform equational rewriting on\nthe target object of a morphism,\nwe can replace the resulting `_.mpr f` term by a composition with an `eq_to_hom`.\n\nIt may be advisable to introduce any necessary `eq_to_hom` morphisms manually,\nrather than relying on this lemma firing.\n-/\n@[simp]\ntheorem congrArg_mpr_hom_right {X Y Z : C} (p : X \u27f6 Y) (q : Z = Y) :\n    (congr_arg (fun W : C => X \u27f6 W) q).mpr p = p \u226b eqToHom q.symm :=\n  by\n  cases q\n  simp\n#align category_theory.congr_arg_mpr_hom_right CategoryTheory.congrArg_mpr_hom_right\n-/\n\n#print CategoryTheory.eqToIso /-\n/-- An equality `X = Y` gives us an isomorphism `X \u2245 Y`.\n\nIt is typically better to use this, rather than rewriting by the equality then using `iso.refl _`\nwhich usually leads to dependent type theory hell.\n-/\ndef eqToIso {X Y : C} (p : X = Y) : X \u2245 Y :=\n  \u27e8eqToHom p, eqToHom p.symm, by simp, by simp\u27e9\n#align category_theory.eq_to_iso CategoryTheory.eqToIso\n-/\n\n#print CategoryTheory.eqToIso.hom /-\n@[simp]\ntheorem eqToIso.hom {X Y : C} (p : X = Y) : (eqToIso p).Hom = eqToHom p :=\n  rfl\n#align category_theory.eq_to_iso.hom CategoryTheory.eqToIso.hom\n-/\n\n#print CategoryTheory.eqToIso.inv /-\n@[simp]\ntheorem eqToIso.inv {X Y : C} (p : X = Y) : (eqToIso p).inv = eqToHom p.symm :=\n  rfl\n#align category_theory.eq_to_iso.inv CategoryTheory.eqToIso.inv\n-/\n\n#print CategoryTheory.eqToIso_refl /-\n@[simp]\ntheorem eqToIso_refl {X : C} (p : X = X) : eqToIso p = Iso.refl X :=\n  rfl\n#align category_theory.eq_to_iso_refl CategoryTheory.eqToIso_refl\n-/\n\n#print CategoryTheory.eqToIso_trans /-\n@[simp]\ntheorem eqToIso_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :\n    eqToIso p \u226a\u226b eqToIso q = eqToIso (p.trans q) := by ext <;> simp\n#align category_theory.eq_to_iso_trans CategoryTheory.eqToIso_trans\n-/\n\n#print CategoryTheory.eqToHom_op /-\n@[simp]\ntheorem eqToHom_op {X Y : C} (h : X = Y) : (eqToHom h).op = eqToHom (congr_arg op h.symm) :=\n  by\n  cases h\n  rfl\n#align category_theory.eq_to_hom_op CategoryTheory.eqToHom_op\n-/\n\n#print CategoryTheory.eqToHom_unop /-\n@[simp]\ntheorem eqToHom_unop {X Y : C\u1d52\u1d56} (h : X = Y) : (eqToHom h).unop = eqToHom (congr_arg unop h.symm) :=\n  by\n  cases h\n  rfl\n#align category_theory.eq_to_hom_unop CategoryTheory.eqToHom_unop\n-/\n\ninstance {X Y : C} (h : X = Y) : IsIso (eqToHom h) :=\n  IsIso.of_iso (eqToIso h)\n\n#print CategoryTheory.inv_eqToHom /-\n@[simp]\ntheorem inv_eqToHom {X Y : C} (h : X = Y) : inv (eqToHom h) = eqToHom h.symm :=\n  by\n  ext\n  simp\n#align category_theory.inv_eq_to_hom CategoryTheory.inv_eqToHom\n-/\n\nvariable {D : Type u\u2082} [Category.{v\u2082} D]\n\nnamespace Functor\n\n/- warning: category_theory.functor.ext -> CategoryTheory.Functor.ext is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (h_obj : forall (X : C), Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)), (forall (X : C) (Y : C) (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y f) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (h_obj X)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Y f) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (Eq.symm.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (h_obj Y)))))) -> (Eq.{succ (max u1 u2 u3 u4)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G)\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (h_obj : forall (X : C), Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)), (forall (X : C) (Y : C) (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y f) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (h_obj X)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Y f) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Eq.symm.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (h_obj Y)))))) -> (Eq.{max (max (max (succ u3) (succ u4)) (succ u1)) (succ u2)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G)\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.ext CategoryTheory.Functor.ext\u2093'. -/\n/-- Proving equality between functors. This isn't an extensionality lemma,\n  because usually you don't really want to do this. -/\ntheorem ext {F G : C \u2964 D} (h_obj : \u2200 X, F.obj X = G.obj X)\n    (h_map : \u2200 X Y f, F.map f = eqToHom (h_obj X) \u226b G.map f \u226b eqToHom (h_obj Y).symm) : F = G :=\n  by\n  cases' F with F_obj _ _ _\n  cases' G with G_obj _ _ _\n  obtain rfl : F_obj = G_obj := by\n    ext X\n    apply h_obj\n  congr\n  funext X Y f\n  simpa using h_map X Y f\n#align category_theory.functor.ext CategoryTheory.Functor.ext\n\n#print CategoryTheory.Functor.conj_eqToHom_iff_hEq /-\n/-- Two morphisms are conjugate via eq_to_hom if and only if they are heterogeneously equal. -/\ntheorem conj_eqToHom_iff_hEq {W X Y Z : C} (f : W \u27f6 X) (g : Y \u27f6 Z) (h : W = Y) (h' : X = Z) :\n    f = eqToHom h \u226b g \u226b eqToHom h'.symm \u2194 HEq f g :=\n  by\n  cases h\n  cases h'\n  simp\n#align category_theory.functor.conj_eq_to_hom_iff_heq CategoryTheory.Functor.conj_eqToHom_iff_hEq\n-/\n\n/- warning: category_theory.functor.hext -> CategoryTheory.Functor.hext is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2}, (forall (X : C), Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) -> (forall (X : C) (Y : C) (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Y f)) -> (Eq.{succ (max u1 u2 u3 u4)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G)\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2}, (forall (X : C), Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) -> (forall (X : C) (Y : C) (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Y f)) -> (Eq.{max (max (max (succ u3) (succ u4)) (succ u1)) (succ u2)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G)\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.hext CategoryTheory.Functor.hext\u2093'. -/\n/-- Proving equality between functors using heterogeneous equality. -/\ntheorem hext {F G : C \u2964 D} (h_obj : \u2200 X, F.obj X = G.obj X)\n    (h_map : \u2200 (X Y) (f : X \u27f6 Y), HEq (F.map f) (G.map f)) : F = G :=\n  Functor.ext h_obj fun _ _ f => (conj_eqToHom_iff_hEq _ _ (h_obj _) (h_obj _)).2 <| h_map _ _ f\n#align category_theory.functor.hext CategoryTheory.Functor.hext\n\n/- warning: category_theory.functor.congr_obj -> CategoryTheory.Functor.congr_obj is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2}, (Eq.{succ (max u1 u2 u3 u4)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) -> (forall (X : C), Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2}, (Eq.{max (max (max (succ u3) (succ u4)) (succ u1)) (succ u2)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) -> (forall (X : C), Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.congr_obj CategoryTheory.Functor.congr_obj\u2093'. -/\n-- Using equalities between functors.\ntheorem congr_obj {F G : C \u2964 D} (h : F = G) (X) : F.obj X = G.obj X := by subst h\n#align category_theory.functor.congr_obj CategoryTheory.Functor.congr_obj\n\n/- warning: category_theory.functor.congr_hom -> CategoryTheory.Functor.congr_hom is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (h : Eq.{succ (max u1 u2 u3 u4)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y f) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.congr_obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G h X)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Y f) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (Eq.symm.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.congr_obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G h Y)))))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (h : Eq.{max (max (max (succ u3) (succ u4)) (succ u1)) (succ u2)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y f) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (CategoryTheory.Functor.congr_obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G h X)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Y f) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Eq.symm.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (CategoryTheory.Functor.congr_obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G h Y)))))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.congr_hom CategoryTheory.Functor.congr_hom\u2093'. -/\ntheorem congr_hom {F G : C \u2964 D} (h : F = G) {X Y} (f : X \u27f6 Y) :\n    F.map f = eqToHom (congr_obj h X) \u226b G.map f \u226b eqToHom (congr_obj h Y).symm := by\n  subst h <;> simp\n#align category_theory.functor.congr_hom CategoryTheory.Functor.congr_hom\n\n/- warning: category_theory.functor.congr_inv_of_congr_hom -> CategoryTheory.Functor.congr_inv_of_congr_hom is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} (e : CategoryTheory.Iso.{u1, u3} C _inst_1 X Y) (hX : Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (hY : Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)), (Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y (CategoryTheory.Iso.hom.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (Eq.mpr.{0} (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X))) (Eq.ndrec.{0, succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (Eq.{succ u4} D _a (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X))) (rfl.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X))) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) hX)) (rfl.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)))) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Y (CategoryTheory.Iso.hom.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (Eq.mpr.{0} (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y))) (Eq.ndrec.{0, succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) _a)) (rfl.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y))) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) hY)) (rfl.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y))))))) -> (Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y X (CategoryTheory.Iso.inv.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (Eq.mpr.{0} (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y))) (Eq.ndrec.{0, succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (Eq.{succ u4} D _a (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y))) (rfl.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y))) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) hY)) (rfl.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)))) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y X (CategoryTheory.Iso.inv.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (Eq.mpr.{0} (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X))) (Eq.ndrec.{0, succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X)) (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) _a)) (rfl.{1} Prop (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X))) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) hX)) (rfl.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)))))))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} (e : CategoryTheory.Iso.{u1, u3} C _inst_1 X Y) (hX : Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (hY : Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)), (Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y (CategoryTheory.Iso.hom.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Eq.mpr.{0} (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (id.{0} (Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X))) (Eq.ndrec.{0, succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (Eq.{succ u4} D _a (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X))) (Eq.refl.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X))) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) hX)) (Eq.refl.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)))) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Y (CategoryTheory.Iso.hom.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Eq.mpr.{0} (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (id.{0} (Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y))) (Eq.ndrec.{0, succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) _a)) (Eq.refl.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y))) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) hY)) (Eq.refl.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y))))))) -> (Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y X (CategoryTheory.Iso.inv.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Eq.mpr.{0} (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (id.{0} (Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y))) (Eq.ndrec.{0, succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (Eq.{succ u4} D _a (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y))) (Eq.refl.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y))) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) hY)) (Eq.refl.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)))) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y X (CategoryTheory.Iso.inv.{u1, u3} C _inst_1 X Y e)) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Eq.mpr.{0} (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (id.{0} (Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X))) (Eq.ndrec.{0, succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (fun (_a : D) => Eq.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X)) (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) _a)) (Eq.refl.{1} Prop (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X))) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) hX)) (Eq.refl.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)))))))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.congr_inv_of_congr_hom CategoryTheory.Functor.congr_inv_of_congr_hom\u2093'. -/\ntheorem congr_inv_of_congr_hom (F G : C \u2964 D) {X Y : C} (e : X \u2245 Y) (hX : F.obj X = G.obj X)\n    (hY : F.obj Y = G.obj Y)\n    (h\u2082 : F.map e.Hom = eqToHom (by rw [hX]) \u226b G.map e.Hom \u226b eqToHom (by rw [hY])) :\n    F.map e.inv = eqToHom (by rw [hY]) \u226b G.map e.inv \u226b eqToHom (by rw [hX]) := by\n  simp only [\u2190 is_iso.iso.inv_hom e, functor.map_inv, h\u2082, is_iso.inv_comp, inv_eq_to_hom,\n    category.assoc]\n#align category_theory.functor.congr_inv_of_congr_hom CategoryTheory.Functor.congr_inv_of_congr_hom\n\n/- warning: category_theory.functor.congr_map -> CategoryTheory.Functor.congr_map is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} {f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y} {g : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y}, (Eq.{succ u1} (Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y) f g) -> (Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y f) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y g))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} {f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y} {g : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y}, (Eq.{succ u1} (Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y) f g) -> (Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y f) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y g))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.congr_map CategoryTheory.Functor.congr_map\u2093'. -/\ntheorem congr_map (F : C \u2964 D) {X Y : C} {f g : X \u27f6 Y} (h : f = g) : F.map f = F.map g := by rw [h]\n#align category_theory.functor.congr_map CategoryTheory.Functor.congr_map\n\nsection HEq\n\n-- Composition of functors and maps w.r.t. heq\nvariable {E : Type u\u2083} [Category.{v\u2083} E] {F G : C \u2964 D} {X Y Z : C} {f : X \u27f6 Y} {g : Y \u27f6 Z}\n\n/- warning: category_theory.functor.map_comp_heq -> CategoryTheory.Functor.map_comp_hEq is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {X : C} {Y : C} {Z : C} {f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y} {g : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) Y Z}, (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) -> (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) -> (Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Z) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Z)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Y f)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Z)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y Z g) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Z)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y Z g)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Z)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Z)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {X : C} {Y : C} {Z : C} {f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y} {g : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) Y Z}, (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) -> (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) -> (Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Z) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Z)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Y f)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Z)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y Z g) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Z)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y Z g)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Z)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Z)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.map_comp_heq CategoryTheory.Functor.map_comp_hEq\u2093'. -/\ntheorem map_comp_hEq (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y) (hz : F.obj Z = G.obj Z)\n    (hf : HEq (F.map f) (G.map f)) (hg : HEq (F.map g) (G.map g)) :\n    HEq (F.map (f \u226b g)) (G.map (f \u226b g)) :=\n  by\n  rw [F.map_comp, G.map_comp]\n  congr\n#align category_theory.functor.map_comp_heq CategoryTheory.Functor.map_comp_hEq\n\n/- warning: category_theory.functor.map_comp_heq' -> CategoryTheory.Functor.map_comp_hEq' is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {X : C} {Y : C} {Z : C} {f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y} {g : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) Y Z}, (forall (X : C), Eq.{succ u4} D (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) -> (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Y f)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Z)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Z)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {X : C} {Y : C} {Z : C} {f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y} {g : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) Y Z}, (forall (X : C), Eq.{succ u4} D (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) -> (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Y f)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Z)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Z)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Z (CategoryTheory.CategoryStruct.comp.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1) X Y Z f g)))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.map_comp_heq' CategoryTheory.Functor.map_comp_hEq'\u2093'. -/\ntheorem map_comp_hEq' (hobj : \u2200 X : C, F.obj X = G.obj X)\n    (hmap : \u2200 {X Y} (f : X \u27f6 Y), HEq (F.map f) (G.map f)) : HEq (F.map (f \u226b g)) (G.map (f \u226b g)) :=\n  by rw [functor.hext hobj fun _ _ => hmap]\n#align category_theory.functor.map_comp_heq' CategoryTheory.Functor.map_comp_hEq'\n\n/- warning: category_theory.functor.precomp_map_heq -> CategoryTheory.Functor.precomp_map_hEq is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u4}} [_inst_1 : CategoryTheory.Category.{u1, u4} C] {D : Type.{u5}} [_inst_2 : CategoryTheory.Category.{u2, u5} D] {E : Type.{u6}} [_inst_3 : CategoryTheory.Category.{u3, u6} E] {F : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} (H : CategoryTheory.Functor.{u3, u1, u6, u4} E _inst_3 C _inst_1), (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G Y)) (CategoryTheory.Functor.map.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X Y f)) -> (forall {X : E} {Y : E} (f : Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H F) X) (CategoryTheory.Functor.obj.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H F) Y)) (CategoryTheory.Functor.map.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H F) X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H G) X) (CategoryTheory.Functor.obj.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H G) Y)) (CategoryTheory.Functor.map.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H G) X Y f))\nbut is expected to have type\n  forall {C : Type.{u4}} [_inst_1 : CategoryTheory.Category.{u1, u4} C] {D : Type.{u5}} [_inst_2 : CategoryTheory.Category.{u2, u5} D] {E : Type.{u6}} [_inst_3 : CategoryTheory.Category.{u3, u6} E] {F : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} (H : CategoryTheory.Functor.{u3, u1, u6, u4} E _inst_3 C _inst_1), (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) Y)) (Prefunctor.map.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X Y f)) -> (forall {X : E} {Y : E} (f : Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u3, succ u2, u6, u5} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H F)) X) (Prefunctor.obj.{succ u3, succ u2, u6, u5} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H F)) Y)) (Prefunctor.map.{succ u3, succ u2, u6, u5} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H F)) X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u3, succ u2, u6, u5} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H G)) X) (Prefunctor.obj.{succ u3, succ u2, u6, u5} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H G)) Y)) (Prefunctor.map.{succ u3, succ u2, u6, u5} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u3, u2, u6, u5} E _inst_3 D _inst_2 (CategoryTheory.Functor.comp.{u3, u1, u2, u6, u4, u5} E _inst_3 C _inst_1 D _inst_2 H G)) X Y f))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.precomp_map_heq CategoryTheory.Functor.precomp_map_hEq\u2093'. -/\ntheorem precomp_map_hEq (H : E \u2964 C) (hmap : \u2200 {X Y} (f : X \u27f6 Y), HEq (F.map f) (G.map f)) {X Y : E}\n    (f : X \u27f6 Y) : HEq ((H \u22d9 F).map f) ((H \u22d9 G).map f) :=\n  hmap _\n#align category_theory.functor.precomp_map_heq CategoryTheory.Functor.precomp_map_hEq\n\n/- warning: category_theory.functor.postcomp_map_heq -> CategoryTheory.Functor.postcomp_map_hEq is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u4}} [_inst_1 : CategoryTheory.Category.{u1, u4} C] {D : Type.{u5}} [_inst_2 : CategoryTheory.Category.{u2, u5} D] {E : Type.{u6}} [_inst_3 : CategoryTheory.Category.{u3, u6} E] {F : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {X : C} {Y : C} {f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y} (H : CategoryTheory.Functor.{u2, u3, u5, u6} D _inst_2 E _inst_3), (Eq.{succ u5} D (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X)) -> (Eq.{succ u5} D (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G Y)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G Y)) (CategoryTheory.Functor.map.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X Y f)) -> (HEq.{succ u3} (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H) X) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H) Y)) (CategoryTheory.Functor.map.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H) X Y f) (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H) X) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H) Y)) (CategoryTheory.Functor.map.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H) X Y f))\nbut is expected to have type\n  forall {C : Type.{u4}} [_inst_1 : CategoryTheory.Category.{u1, u4} C] {D : Type.{u5}} [_inst_2 : CategoryTheory.Category.{u2, u5} D] {E : Type.{u6}} [_inst_3 : CategoryTheory.Category.{u3, u6} E] {F : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {X : C} {Y : C} {f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y} (H : CategoryTheory.Functor.{u2, u3, u5, u6} D _inst_2 E _inst_3), (Eq.{succ u5} D (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X)) -> (Eq.{succ u5} D (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) Y)) -> (HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) Y)) (Prefunctor.map.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X Y f)) -> (HEq.{succ u3} (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H)) X) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H)) Y)) (Prefunctor.map.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H)) X Y f) (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H)) X) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H)) Y)) (Prefunctor.map.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H)) X Y f))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.postcomp_map_heq CategoryTheory.Functor.postcomp_map_hEq\u2093'. -/\ntheorem postcomp_map_hEq (H : D \u2964 E) (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y)\n    (hmap : HEq (F.map f) (G.map f)) : HEq ((F \u22d9 H).map f) ((G \u22d9 H).map f) :=\n  by\n  dsimp\n  congr\n#align category_theory.functor.postcomp_map_heq CategoryTheory.Functor.postcomp_map_hEq\n\n/- warning: category_theory.functor.postcomp_map_heq' -> CategoryTheory.Functor.postcomp_map_hEq' is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u4}} [_inst_1 : CategoryTheory.Category.{u1, u4} C] {D : Type.{u5}} [_inst_2 : CategoryTheory.Category.{u2, u5} D] {E : Type.{u6}} [_inst_3 : CategoryTheory.Category.{u3, u6} E] {F : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {X : C} {Y : C} {f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y} (H : CategoryTheory.Functor.{u2, u3, u5, u6} D _inst_2 E _inst_3), (forall (X : C), Eq.{succ u5} D (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X)) -> (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u4, u5} C _inst_1 D _inst_2 F X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u4, u5} C _inst_1 D _inst_2 G Y)) (CategoryTheory.Functor.map.{u1, u2, u4, u5} C _inst_1 D _inst_2 G X Y f)) -> (HEq.{succ u3} (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H) X) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H) Y)) (CategoryTheory.Functor.map.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H) X Y f) (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H) X) (CategoryTheory.Functor.obj.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H) Y)) (CategoryTheory.Functor.map.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H) X Y f))\nbut is expected to have type\n  forall {C : Type.{u4}} [_inst_1 : CategoryTheory.Category.{u1, u4} C] {D : Type.{u5}} [_inst_2 : CategoryTheory.Category.{u2, u5} D] {E : Type.{u6}} [_inst_3 : CategoryTheory.Category.{u3, u6} E] {F : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u4, u5} C _inst_1 D _inst_2} {X : C} {Y : C} {f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y} (H : CategoryTheory.Functor.{u2, u3, u5, u6} D _inst_2 E _inst_3), (forall (X : C), Eq.{succ u5} D (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X)) -> (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 F) X Y f) (Quiver.Hom.{succ u2, u5} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) Y)) (Prefunctor.map.{succ u1, succ u2, u4, u5} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u5} D (CategoryTheory.Category.toCategoryStruct.{u2, u5} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u4, u5} C _inst_1 D _inst_2 G) X Y f)) -> (HEq.{succ u3} (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H)) X) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H)) Y)) (Prefunctor.map.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 F H)) X Y f) (Quiver.Hom.{succ u3, u6} E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H)) X) (Prefunctor.obj.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H)) Y)) (Prefunctor.map.{succ u1, succ u3, u4, u6} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u4} C (CategoryTheory.Category.toCategoryStruct.{u1, u4} C _inst_1)) E (CategoryTheory.CategoryStruct.toQuiver.{u3, u6} E (CategoryTheory.Category.toCategoryStruct.{u3, u6} E _inst_3)) (CategoryTheory.Functor.toPrefunctor.{u1, u3, u4, u6} C _inst_1 E _inst_3 (CategoryTheory.Functor.comp.{u1, u2, u3, u4, u5, u6} C _inst_1 D _inst_2 E _inst_3 G H)) X Y f))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.postcomp_map_heq' CategoryTheory.Functor.postcomp_map_hEq'\u2093'. -/\ntheorem postcomp_map_hEq' (H : D \u2964 E) (hobj : \u2200 X : C, F.obj X = G.obj X)\n    (hmap : \u2200 {X Y} (f : X \u27f6 Y), HEq (F.map f) (G.map f)) : HEq ((F \u22d9 H).map f) ((G \u22d9 H).map f) :=\n  by rw [functor.hext hobj fun _ _ => hmap]\n#align category_theory.functor.postcomp_map_heq' CategoryTheory.Functor.postcomp_map_hEq'\n\n/- warning: category_theory.functor.hcongr_hom -> CategoryTheory.Functor.hcongr_hom is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2}, (Eq.{succ (max u1 u2 u3 u4)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) -> (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X Y f))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2}, (Eq.{max (max (max (succ u3) (succ u4)) (succ u1)) (succ u2)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) -> (forall {X : C} {Y : C} (f : Quiver.Hom.{succ u1, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) X Y), HEq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y f) (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X Y f))\nCase conversion may be inaccurate. Consider using '#align category_theory.functor.hcongr_hom CategoryTheory.Functor.hcongr_hom\u2093'. -/\ntheorem hcongr_hom {F G : C \u2964 D} (h : F = G) {X Y} (f : X \u27f6 Y) : HEq (F.map f) (G.map f) := by\n  subst h\n#align category_theory.functor.hcongr_hom CategoryTheory.Functor.hcongr_hom\n\nend HEq\n\nend Functor\n\n/- warning: category_theory.eq_to_hom_map -> CategoryTheory.eqToHom_map is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} (p : Eq.{succ u3} C X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y (CategoryTheory.eqToHom.{u1, u3} C _inst_1 X Y p)) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (congr_arg.{succ u3, succ u4} C D X Y (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) p))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} (p : Eq.{succ u3} C X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y (CategoryTheory.eqToHom.{u1, u3} C _inst_1 X Y p)) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (congr_arg.{succ u3, succ u4} C D X Y (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F)) p))\nCase conversion may be inaccurate. Consider using '#align category_theory.eq_to_hom_map CategoryTheory.eqToHom_map\u2093'. -/\n/-- This is not always a good idea as a `@[simp]` lemma,\nas we lose the ability to use results that interact with `F`,\ne.g. the naturality of a natural transformation.\n\nIn some files it may be appropriate to use `local attribute [simp] eq_to_hom_map`, however.\n-/\ntheorem eqToHom_map (F : C \u2964 D) {X Y : C} (p : X = Y) :\n    F.map (eqToHom p) = eqToHom (congr_arg F.obj p) := by cases p <;> simp\n#align category_theory.eq_to_hom_map CategoryTheory.eqToHom_map\n\n/- warning: category_theory.eq_to_iso_map -> CategoryTheory.eqToIso_map is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} (p : Eq.{succ u3} C X Y), Eq.{succ u2} (CategoryTheory.Iso.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y)) (CategoryTheory.Functor.mapIso.{u1, u3, u4, u2} C _inst_1 D _inst_2 F X Y (CategoryTheory.eqToIso.{u1, u3} C _inst_1 X Y p)) (CategoryTheory.eqToIso.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (congr_arg.{succ u3, succ u4} C D X Y (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) p))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] (F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) {X : C} {Y : C} (p : Eq.{succ u3} C X Y), Eq.{succ u2} (CategoryTheory.Iso.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y)) (CategoryTheory.Functor.mapIso.{u1, u3, u4, u2} C _inst_1 D _inst_2 F X Y (CategoryTheory.eqToIso.{u1, u3} C _inst_1 X Y p)) (CategoryTheory.eqToIso.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (congr_arg.{succ u3, succ u4} C D X Y (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F)) p))\nCase conversion may be inaccurate. Consider using '#align category_theory.eq_to_iso_map CategoryTheory.eqToIso_map\u2093'. -/\n/-- See the note on `eq_to_hom_map` regarding using this as a `simp` lemma.\n-/\ntheorem eqToIso_map (F : C \u2964 D) {X Y : C} (p : X = Y) :\n    F.mapIso (eqToIso p) = eqToIso (congr_arg F.obj p) := by ext <;> cases p <;> simp\n#align category_theory.eq_to_iso_map CategoryTheory.eqToIso_map\n\n/- warning: category_theory.eq_to_hom_app -> CategoryTheory.eqToHom_app is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (h : Eq.{succ (max u1 u2 u3 u4)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) (X : C), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (CategoryTheory.NatTrans.app.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G (CategoryTheory.eqToHom.{max u3 u2, max u1 u2 u3 u4} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.Functor.category.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G h) X) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.congr_obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G h X))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (h : Eq.{max (max (max (succ u3) (succ u4)) (succ u1)) (succ u2)} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G) (X : C), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (CategoryTheory.NatTrans.app.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G (CategoryTheory.eqToHom.{max u3 u2, max (max (max u3 u4) u1) u2} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.Functor.category.{u1, u2, u3, u4} C _inst_1 D _inst_2) F G h) X) (CategoryTheory.eqToHom.{u2, u4} D _inst_2 (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (CategoryTheory.Functor.congr_obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G h X))\nCase conversion may be inaccurate. Consider using '#align category_theory.eq_to_hom_app CategoryTheory.eqToHom_app\u2093'. -/\n@[simp]\ntheorem eqToHom_app {F G : C \u2964 D} (h : F = G) (X : C) :\n    (eqToHom h : F \u27f6 G).app X = eqToHom (Functor.congr_obj h X) := by subst h <;> rfl\n#align category_theory.eq_to_hom_app CategoryTheory.eqToHom_app\n\n/- warning: category_theory.nat_trans.congr -> CategoryTheory.NatTrans.congr is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (\u03b1 : Quiver.Hom.{succ (max u3 u2), max u1 u2 u3 u4} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.CategoryStruct.toQuiver.{max u3 u2, max u1 u2 u3 u4} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.Category.toCategoryStruct.{max u3 u2, max u1 u2 u3 u4} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.Functor.category.{u1, u2, u3, u4} C _inst_1 D _inst_2))) F G) {X : C} {Y : C} (h : Eq.{succ u3} C X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X)) (CategoryTheory.NatTrans.app.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G \u03b1 X) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 F X Y (CategoryTheory.eqToHom.{u1, u3} C _inst_1 X Y h)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 F Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y) (CategoryTheory.Functor.obj.{u1, u2, u3, u4} C _inst_1 D _inst_2 G X) (CategoryTheory.NatTrans.app.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G \u03b1 Y) (CategoryTheory.Functor.map.{u1, u2, u3, u4} C _inst_1 D _inst_2 G Y X (CategoryTheory.eqToHom.{u1, u3} C _inst_1 Y X (Eq.symm.{succ u3} C X Y h)))))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u1, u3} C] {D : Type.{u4}} [_inst_2 : CategoryTheory.Category.{u2, u4} D] {F : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} {G : CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2} (\u03b1 : Quiver.Hom.{max (succ u3) (succ u2), max (max (max u3 u4) u1) u2} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.CategoryStruct.toQuiver.{max u3 u2, max (max (max u3 u4) u1) u2} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.Category.toCategoryStruct.{max u3 u2, max (max (max u3 u4) u1) u2} (CategoryTheory.Functor.{u1, u2, u3, u4} C _inst_1 D _inst_2) (CategoryTheory.Functor.category.{u1, u2, u3, u4} C _inst_1 D _inst_2))) F G) {X : C} {Y : C} (h : Eq.{succ u3} C X Y), Eq.{succ u2} (Quiver.Hom.{succ u2, u4} D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X)) (CategoryTheory.NatTrans.app.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G \u03b1 X) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) X Y (CategoryTheory.eqToHom.{u1, u3} C _inst_1 X Y h)) (CategoryTheory.CategoryStruct.comp.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 F) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y) (Prefunctor.obj.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) X) (CategoryTheory.NatTrans.app.{u1, u2, u3, u4} C _inst_1 D _inst_2 F G \u03b1 Y) (Prefunctor.map.{succ u1, succ u2, u3, u4} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u3} C (CategoryTheory.Category.toCategoryStruct.{u1, u3} C _inst_1)) D (CategoryTheory.CategoryStruct.toQuiver.{u2, u4} D (CategoryTheory.Category.toCategoryStruct.{u2, u4} D _inst_2)) (CategoryTheory.Functor.toPrefunctor.{u1, u2, u3, u4} C _inst_1 D _inst_2 G) Y X (CategoryTheory.eqToHom.{u1, u3} C _inst_1 Y X (Eq.symm.{succ u3} C X Y h)))))\nCase conversion may be inaccurate. Consider using '#align category_theory.nat_trans.congr CategoryTheory.NatTrans.congr\u2093'. -/\ntheorem NatTrans.congr {F G : C \u2964 D} (\u03b1 : F \u27f6 G) {X Y : C} (h : X = Y) :\n    \u03b1.app X = F.map (eqToHom h) \u226b \u03b1.app Y \u226b G.map (eqToHom h.symm) :=\n  by\n  rw [\u03b1.naturality_assoc]\n  simp [eq_to_hom_map]\n#align category_theory.nat_trans.congr CategoryTheory.NatTrans.congr\n\n#print CategoryTheory.eq_conj_eqToHom /-\ntheorem eq_conj_eqToHom {X Y : C} (f : X \u27f6 Y) : f = eqToHom rfl \u226b f \u226b eqToHom rfl := by\n  simp only [category.id_comp, eq_to_hom_refl, category.comp_id]\n#align category_theory.eq_conj_eq_to_hom CategoryTheory.eq_conj_eqToHom\n-/\n\n/- warning: category_theory.dcongr_arg -> CategoryTheory.dcongr_arg is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u2}} [_inst_1 : CategoryTheory.Category.{u1, u2} C] {\u03b9 : Type.{u3}} {F : \u03b9 -> C} {G : \u03b9 -> C} (\u03b1 : forall (i : \u03b9), Quiver.Hom.{succ u1, u2} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1)) (F i) (G i)) {i : \u03b9} {j : \u03b9} (h : Eq.{succ u3} \u03b9 i j), Eq.{succ u1} (Quiver.Hom.{succ u1, u2} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1)) (F i) (G i)) (\u03b1 i) (CategoryTheory.CategoryStruct.comp.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1) (F i) (F j) (G i) (CategoryTheory.eqToHom.{u1, u2} C _inst_1 (F i) (F j) (congr_arg.{succ u3, succ u2} \u03b9 C i j F h)) (CategoryTheory.CategoryStruct.comp.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1) (F j) (G j) (G i) (\u03b1 j) (CategoryTheory.eqToHom.{u1, u2} C _inst_1 (G j) (G i) (congr_arg.{succ u3, succ u2} \u03b9 C j i G (Eq.symm.{succ u3} \u03b9 i j h)))))\nbut is expected to have type\n  forall {C : Type.{u3}} [_inst_1 : CategoryTheory.Category.{u2, u3} C] {\u03b9 : Type.{u1}} {F : \u03b9 -> C} {G : \u03b9 -> C} (\u03b1 : forall (i : \u03b9), Quiver.Hom.{succ u2, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u2, u3} C (CategoryTheory.Category.toCategoryStruct.{u2, u3} C _inst_1)) (F i) (G i)) {i : \u03b9} {j : \u03b9} (h : Eq.{succ u1} \u03b9 i j), Eq.{succ u2} (Quiver.Hom.{succ u2, u3} C (CategoryTheory.CategoryStruct.toQuiver.{u2, u3} C (CategoryTheory.Category.toCategoryStruct.{u2, u3} C _inst_1)) (F i) (G i)) (\u03b1 i) (CategoryTheory.CategoryStruct.comp.{u2, u3} C (CategoryTheory.Category.toCategoryStruct.{u2, u3} C _inst_1) (F i) (F j) (G i) (CategoryTheory.eqToHom.{u2, u3} C _inst_1 (F i) (F j) (congr_arg.{succ u1, succ u3} \u03b9 C i j F h)) (CategoryTheory.CategoryStruct.comp.{u2, u3} C (CategoryTheory.Category.toCategoryStruct.{u2, u3} C _inst_1) (F j) (G j) (G i) (\u03b1 j) (CategoryTheory.eqToHom.{u2, u3} C _inst_1 (G j) (G i) (congr_arg.{succ u1, succ u3} \u03b9 C j i G (Eq.symm.{succ u1} \u03b9 i j h)))))\nCase conversion may be inaccurate. Consider using '#align category_theory.dcongr_arg CategoryTheory.dcongr_arg\u2093'. -/\ntheorem dcongr_arg {\u03b9 : Type _} {F G : \u03b9 \u2192 C} (\u03b1 : \u2200 i, F i \u27f6 G i) {i j : \u03b9} (h : i = j) :\n    \u03b1 i = eqToHom (congr_arg F h) \u226b \u03b1 j \u226b eqToHom (congr_arg G h.symm) :=\n  by\n  subst h\n  simp\n#align category_theory.dcongr_arg CategoryTheory.dcongr_arg\n\nend CategoryTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/CategoryTheory/EqToHom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7064476218777899}}
{"text": "-- Mandelbrot set\n\nimport data.real.basic\nimport data.complex.basic\nimport tactic.linarith.frontend\nimport tactics\nimport simple\nopen tactic.interactive (nlinarith)\nopen complex (abs has_zero)\nopen simple\n\ndef f (c : \u2102) : \u2115 \u2192 \u2102\n| 0 := 0\n| (n+1) := let z := f n in z^2+c\n\ndef escape (s : \u2115 \u2192 \u2102) := \u2200 r : \u211d, \u2203 n : \u2115, abs (s n) \u2265 r\n\ndef M (c : \u2102) := \u2200 n : \u2115, abs (f c n) \u2264 2\ndef Mc (c : \u2102) := escape (f c)\n\nlemma f_zero (n : \u2115) : f 0 n = 0 := begin\n  induction n,\n  exact rfl,\n  rw f, simp, exact n_ih\nend\n\nlemma f_one (c : \u2102) : f c 1 = c := begin\n  rw f, simp, rw f\nend\n\ntheorem M_zero : M 0 := begin\n  rw M, intros, rw f_zero, simp,\nend\n\ntheorem M_disk (c : \u2102) (h : M c) : abs c \u2264 2 := begin\n  specialize h 1, rw f_one at h, exact h\nend\n\ndef Mr (r : \u211d) (c : \u2102) := \u2200 n : \u2115, abs (f c n) \u2264 r\n\ntheorem Mr2 (c : \u2102) : M c \u2194 Mr 2 c := by apply iff.refl\n\nlemma f_sub_ge {z c : \u2102} : abs (z^2 + c) \u2265 (abs z)^2 - abs c := begin\n  calc abs (z^2 + c) \u2265 abs (z^2) - abs c : abs_sub_ge _ _\n   ... = (abs z)^2 - abs c : by rw complex.abs_pow\nend\n\nlemma large_escape_helper {c : \u2102} {s : \u211d} (h1 : s \u2265 0) (h2 : 2 + s \u2264 abs c) (n : \u2115)\n  : abs (f c (n+1)) \u2265 (abs c)*(1 + n*s) :=\nbegin\n   induction n with n,\n   simp, rw f_one,\n   rw f, simp,\n   let hs : n.succ = n + 1 := rfl,\n   rw hs, clear hs,\n   set z := f c (n + 1),\n   flip_ineq,\n   calc abs (z^2 + c) \u2265 (abs z)^2 - abs c : f_sub_ge\n   ... \u2265 (abs c * (1 + n*s))^2 - abs c : by bound\n   ... = abs c * (abs c * (1 + n*s)^2 - 1) : by ring\n   ... \u2265 abs c * ((2 + s) * (1 + n*s)^2 - 1) : by bound\n   ... \u2265 abs c * ((2 + s) * (1 + 2*n*s) - 1) : begin\n     have h := sq_bound (n*s), rw \u2190mul_assoc at h, bound end\n   ... = abs c * (2 + 4*n*s + s + 2*n*s^2 - 1) : by ring\n   ... \u2265 abs c * (2 + 1*n*s + s + 0 - 1) : by bound\n   ... = abs c * (1 + (n+1)*s) : by ring\nend\n\nlemma small_escape_helper {c : \u2102} {s : \u211d} {n : \u2115} (h1 : s \u2265 0) (hs : abs c \u2264 2)\n  (e : abs (f c n) \u2265 2 + s) (m : \u2115) : abs (f c (n+m)) \u2265 2 + (1+m)*s :=\nbegin\n  induction m with m,\n  simp, bound,\n  have su : n + m.succ = (n + m).succ := rfl,\n  rw [su, f], simp, flip_ineq,\n  set z := f c (n + m),\n  calc abs (z ^ 2 + c) \u2265 abs z^2 - abs c : f_sub_ge\n  ... \u2265 (2 + (1 + \u2191m) * s)^2 - 2 : by bound\n  ... = 2 + (4 + 4*\u2191m) * s + ((1 + m) * s)^2 : by ring\n  ... \u2265 2 + (2 + 1*\u2191m) * s + (0 : \u211d)^2 : by bound\n  ... = 2 + (2 + \u2191m) * s : by ring\n  ... = 2 + (1 + (\u2191m + 1)) * s : by ring\nend\n\ntheorem large_escape {c : \u2102} (h : abs c > 2) : Mc c := begin\n  rcases gap h with \u27e8s, sp, sc\u27e9,\n  intro,\n  cases large_div_nat (abs c * s) r (by nlinarith) with k hk,\n  existsi (k + 1),\n  calc abs (f c (k + 1)) \u2265 abs c * (1 + \u2191k * s) :\n    large_escape_helper (le_of_lt sp) sc k\n  ... = abs c + abs c * s * \u2191k : by ring\n  ... \u2265 abs c * s * \u2191k : by linarith\n  ... \u2265 r : by bound\nend\n\ntheorem small_escape {c : \u2102} (hs : abs c \u2264 2) {n : \u2115} (e : abs (f c n) > 2)\n    : Mc c := begin\n  rcases gap e with \u27e8s, _, sc\u27e9,\n  intro,\n  cases large_div_nat s r (by linarith) with m hm,\n  existsi (n + m),\n  have snn : s \u2265 0 := by linarith,\n  calc abs (f c (n + m)) \u2265 2 + (1+m)*s : small_escape_helper (by linarith) hs sc m\n  ... \u2265 0 + (0+m)*s : by bound\n  ... = m*s : by ring\n  ... \u2265 r : by linarith\nend\n\ntheorem M_escape {c : \u2102} : M c \u2194 \u00acMc c := begin\n  apply iff.intro, {\n    intro h,\n    by_contradiction e,\n    rw M at h,\n    rw [Mc, escape] at e,\n    cases e 3 with n,\n    have hn := h n,\n    linarith\n  }, {\n    intro e,\n    cases le_or_gt (abs c) 2 with hs hl, {\n      by_contradiction h,\n      rw M at h,\n      cases not_all h with n h,\n      revert h, simp,\n      by_contradiction q,\n      have se := small_escape hs q,\n      trivial\n    }, {\n      have he := large_escape hl,\n      trivial\n    }\n  }\nend\n\n-- If abs c \u2265 4, the iteration escapes exponentially fast\ntheorem fast_escape {c : \u2102} {h : abs c \u2265 4} {n : \u2115}\n  : abs (f c (n+1)) \u2265 2^n * abs c :=\nbegin\n  induction n with n,\n  simp, rw f_one,\n  have su : n.succ + 1 = (n+1).succ := rfl,\n  rw [su, f], simp,\n  set z := f c (n+1),\n  flip_ineq,\n  calc abs (z ^ 2 + c) \u2265 abs z^2 - abs c : f_sub_ge\n  ... \u2265 (2^n * abs c)^2 - abs c : by bound\n  ... = 2^n * 2^n * abs c * abs c - abs c : by ring\n  ... \u2265 2^n * 2^n * abs c * 4 - abs c : by bound\n  ... = (4*2^n*2^n-1) * abs c : by ring\n  ... \u2265 2^(n+1) * abs c : mul_le_mul_of_nonneg_right _ (complex.abs_nonneg _),\n  clear n_ih z su h c,\n  rw pow_succ,\n  simp,\n  set p : \u211d := 2^n,\n  have ph : p \u2265 1 := coe_pow_ge_one,\n  nlinarith\nend", "meta": {"author": "girving", "repo": "ray", "sha": "e0c501756e067711e2d3667d4b1d18045d83a313", "save_path": "github-repos/lean/girving-ray", "path": "github-repos/lean/girving-ray/ray-e0c501756e067711e2d3667d4b1d18045d83a313/src/mandelbrot.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567085, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7063850103971931}}
{"text": "/-\nCopyright (c) 2021 Jakob Scholbach. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jakob Scholbach\n-/\nimport algebra.char_p.basic\nimport data.nat.prime\n\n/-!\n# Exponential characteristic\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the exponential characteristic and establishes a few basic results relating\nit to the (ordinary characteristic).\nThe definition is stated for a semiring, but the actual results are for nontrivial rings\n(as far as exponential characteristic one is concerned), respectively a ring without zero-divisors\n(for prime characteristic).\n\n## Main results\n- `exp_char`: the definition of exponential characteristic\n- `exp_char_is_prime_or_one`: the exponential characteristic is a prime or one\n- `char_eq_exp_char_iff`: the characteristic equals the exponential characteristic iff the\n  characteristic is prime\n\n## Tags\nexponential characteristic, characteristic\n-/\n\nuniverse u\nvariables (R : Type u)\n\nsection semiring\n\nvariables [semiring R]\n\n/-- The definition of the exponential characteristic of a semiring. -/\nclass inductive exp_char (R : Type u) [semiring R] : \u2115 \u2192 Prop\n| zero [char_zero R] : exp_char 1\n| prime {q : \u2115} (hprime : q.prime) [hchar : char_p R q] : exp_char q\n\n/-- The exponential characteristic is one if the characteristic is zero. -/\nlemma exp_char_one_of_char_zero (q : \u2115) [hp : char_p R 0] [hq : exp_char R q] :\n  q = 1 :=\nbegin\n  casesI hq with q hq_one hq_prime,\n  { refl },\n  { exact false.elim (lt_irrefl _ ((hp.eq R hq_hchar).symm \u25b8 hq_prime : (0 : \u2115).prime).pos) }\nend\n\n/-- The characteristic equals the exponential characteristic iff the former is prime. -/\ntheorem char_eq_exp_char_iff (p q : \u2115) [hp : char_p R p] [hq : exp_char R q] :\n  p = q \u2194 p.prime :=\nbegin\n  casesI hq with q hq_one hq_prime,\n  { apply iff_of_false,\n    { unfreezingI {rintro rfl},\n      exact one_ne_zero (hp.eq R (char_p.of_char_zero R)) },\n    { intro pprime,\n      rw (char_p.eq R hp infer_instance : p = 0) at pprime,\n      exact nat.not_prime_zero pprime } },\n  { exact \u27e8\u03bb hpq, hpq.symm \u25b8 hq_prime, \u03bb _, char_p.eq R hp hq_hchar\u27e9 },\nend\n\nsection nontrivial\n\nvariables [nontrivial R]\n\n/-- The exponential characteristic is one if the characteristic is zero. -/\nlemma char_zero_of_exp_char_one (p : \u2115) [hp : char_p R p] [hq : exp_char R 1] :\n  p = 0 :=\nbegin\n  casesI hq,\n  { exact char_p.eq R hp infer_instance, },\n  { exact false.elim (char_p.char_ne_one R 1 rfl), }\nend\n\n/-- The characteristic is zero if the exponential characteristic is one. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance char_zero_of_exp_char_one' [hq : exp_char R 1] : char_zero R :=\nbegin\n  casesI hq,\n  { assumption, },\n  { exact false.elim (char_p.char_ne_one R 1 rfl), }\nend\n\n/-- The exponential characteristic is one iff the characteristic is zero. -/\ntheorem exp_char_one_iff_char_zero (p q : \u2115) [char_p R p] [exp_char R q] :\n  q = 1 \u2194 p = 0 :=\nbegin\n  split,\n  { unfreezingI {rintro rfl},\n    exact char_zero_of_exp_char_one R p, },\n  { unfreezingI {rintro rfl},\n    exact exp_char_one_of_char_zero R q, }\nend\n\nsection no_zero_divisors\n\nvariable [no_zero_divisors R]\n\n/-- A helper lemma: the characteristic is prime if it is non-zero. -/\nlemma char_prime_of_ne_zero {p : \u2115} [hp : char_p R p] (p_ne_zero : p \u2260 0) : nat.prime p :=\nbegin\n  cases char_p.char_is_prime_or_zero R p with h h,\n  { exact h, },\n  { contradiction, }\nend\n\n/-- The exponential characteristic is a prime number or one. -/\ntheorem exp_char_is_prime_or_one (q : \u2115) [hq : exp_char R q] : nat.prime q \u2228 q = 1 :=\nor_iff_not_imp_right.mpr $ \u03bb h,\nbegin\n  casesI char_p.exists R with p hp,\n  have p_ne_zero : p \u2260 0,\n  { intro p_zero,\n    haveI : char_p R 0, { rwa \u2190p_zero },\n    have : q = 1 := exp_char_one_of_char_zero R q,\n    contradiction, },\n  have p_eq_q : p = q := (char_eq_exp_char_iff R p q).mpr (char_prime_of_ne_zero R p_ne_zero),\n  cases char_p.char_is_prime_or_zero R p with pprime,\n  { rwa p_eq_q at pprime },\n  { contradiction },\nend\n\nend no_zero_divisors\n\nend nontrivial\n\nend semiring\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/char_p/exp_char.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.7063694499600419}}
{"text": "namespace hidden\n\nuniverse u\nvariables {\u03b1 : Type u}\n\ninductive list (\u03b1 : Type u)\n| nil  {} : list\n| cons : \u03b1 \u2192 list \u2192 list\n\nnotation h :: t  := list.cons h t\n\nnamespace list\n  def append (s t : list \u03b1) : list \u03b1 :=\n  list.rec t (\u03bb x l u, x :: u) s\n\n  instance list_has_append : has_append (list \u03b1) := \u27e8append\u27e9\n\n  lemma nil_append (t : list \u03b1) : nil ++ t = t := rfl\n\n  lemma cons_append (x : \u03b1) (s t : list \u03b1) : (x :: s) ++ t = x :: (s ++ t) := rfl\n\n  lemma append_nil (s : list \u03b1) : s ++ nil = s :=\n  begin\n    induction s with x s\u2081 ih,\n    refl, -- case nil\n    calc  -- case (x :: s\u2081)\n      (x :: s\u2081) ++ nil = x :: (s\u2081 ++ nil) : rfl\n                   ... = x :: s\u2081          : by rw ih\n  end\n\n  lemma append_assoc (s t u : list \u03b1) : s ++ (t ++ u) = (s ++ t) ++ u :=\n  begin\n    induction s with x s\u2081 ih,\n    refl, -- case nil\n    calc  -- case (x :: s\u2081)\n      (x :: s\u2081) ++ (t ++ u) = x :: (s\u2081 ++ (t ++ u)) : rfl\n                        ... = x :: ((s\u2081 ++ t) ++ u) : by rw ih\n                        ... = ((x :: s\u2081) ++ t) ++ u : rfl\n  end\n\n  def reverse (s : list \u03b1) : list \u03b1 :=\n  list.rec_on s nil (\u03bb x _ u, u ++ (x :: nil))\n\n  lemma reverse_append (s t : list \u03b1) : reverse (s ++ t) = reverse t ++ reverse s :=\n  begin\n    induction s with x s\u2081 ih,\n    calc -- case nil t\n      reverse (nil ++ t) = reverse t                : rfl\n                     ... = reverse t ++ nil         : by rw append_nil\n                     ... = reverse t ++ reverse nil : rfl,\n    calc -- case (x :: s\u2081) t\n      reverse ((x :: s\u2081) ++ t) = reverse (s\u2081 ++ t) ++ reverse (x :: nil)         : rfl\n                           ... = (reverse t ++ reverse s\u2081) ++ reverse (x :: nil) : by rw ih\n                           ... = reverse t ++ (reverse s\u2081 ++ reverse (x :: nil)) : by rw append_assoc\n                           ... = reverse t ++ reverse (x :: s\u2081)                  : rfl\n  end\n\n  lemma reverse_reverse (s : list \u03b1) : reverse (reverse s) = s :=\n  begin\n    induction s with x s\u2081 ih,\n    refl, -- case nil\n    calc  -- case (x :: s\u2081)\n      reverse (reverse (x :: s\u2081)) = reverse (reverse ((x :: nil) ++ s\u2081))                 : rfl\n                              ... = reverse (reverse s\u2081 ++ reverse (x :: nil))           : by rw reverse_append\n                              ... = reverse (reverse (x :: nil)) ++ reverse (reverse s\u2081) : by rw reverse_append\n                              ... = reverse (reverse (x :: nil)) ++ s\u2081                   : by rw ih\n                              ... = x :: s\u2081                                              : rfl\n  end\n\n  def length (s : list \u03b1) : nat :=\n  list.rec_on s 0 (\u03bb x _ u, nat.succ u)\n\n  lemma length_nil_eq_zero (s : list \u03b1) : length s = 0 \u2192 s = nil :=\n  begin\n    induction s; intros, refl, contradiction\n  end\n\n  lemma length_append (s t : list \u03b1) : length (s ++ t) = length s + length t :=\n  begin\n    induction s with x s\u2081 ih,\n    calc -- case nil\n      length (nil ++ t) = length t              : by rw nil_append\n                    ... = length t + 0          : by rw nat_add_zero\n                    ... = 0 + length t          : by rw nat.add_comm\n                    ... = length nil + length t : rfl,\n    calc -- case (x :: s\u2081)\n      length ((x :: s\u2081) ++ t) = nat.succ (length (s\u2081 ++ t))     : rfl\n                          ... = nat.succ (length s\u2081 + length t) : by rw ih\n                          ... = nat.succ (length t + length s\u2081) : by rw nat.add_comm\n                          ... = length t + nat.succ (length s\u2081) : by rw nat.add_succ\n                          ... = length t + length (x :: s\u2081)     : rfl\n                          ... = length (x :: s\u2081) + length t     : by rw nat.add_comm\n  end\n\n  lemma length_reverse (s : list \u03b1) : length (reverse s) = length s :=\n  begin\n    induction s with x s\u2081 ih,\n    refl, -- case nil\n    calc  -- case (x :: s\u2081)\n      length (reverse (x :: s\u2081)) = length (reverse ((x :: nil) ++ s\u2081))       : rfl\n                             ... = length (reverse s\u2081 ++ reverse (x :: nil)) : by rw reverse_append\n                             ... = length (reverse s\u2081 ++ (x :: nil))         : rfl\n                             ... = length (reverse s\u2081) + length (x :: nil)   : by rw length_append\n                             ... = length s\u2081 + length (x :: nil)             : by rw ih\n                             ... = length (x :: s\u2081)                          : rfl\n  end\nend list\n\nend hidden\n", "meta": {"author": "makenowjust-labs", "repo": "lean-playground", "sha": "a0ce8655776cab37ed212814eb5443667f75ecbc", "save_path": "github-repos/lean/makenowjust-labs-lean-playground", "path": "github-repos/lean/makenowjust-labs-lean-playground/lean-playground-a0ce8655776cab37ed212814eb5443667f75ecbc/list.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7063694423770291}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport data.fin.vec_notation\nimport logic.equiv.basic\nimport tactic.norm_num\n\n/-!\n# Equivalences for `fin n`\n-/\n\nuniverses u\n\nvariables {m n : \u2115}\n\n/-- Equivalence between `fin 0` and `empty`. -/\ndef fin_zero_equiv : fin 0 \u2243 empty :=\nequiv.equiv_empty _\n\n/-- Equivalence between `fin 0` and `pempty`. -/\ndef fin_zero_equiv' : fin 0 \u2243 pempty.{u} :=\nequiv.equiv_pempty _\n\n/-- Equivalence between `fin 1` and `unit`. -/\ndef fin_one_equiv : fin 1 \u2243 unit :=\nequiv.equiv_punit _\n\n/-- Equivalence between `fin 2` and `bool`. -/\ndef fin_two_equiv : fin 2 \u2243 bool :=\n\u27e8@fin.cases 1 (\u03bb_, bool) ff (\u03bb_, tt),\n  \u03bbb, cond b 1 0,\n  begin\n    refine fin.cases _ _, by norm_num,\n    refine fin.cases _ _, by norm_num,\n    exact \u03bbi, fin_zero_elim i\n  end,\n  begin\n    rintro \u27e8_|_\u27e9,\n    { refl },\n    { rw \u2190 fin.succ_zero_eq_one, refl }\n  end\u27e9\n\n/-- `\u03a0 i : fin 2, \u03b1 i` is equivalent to `\u03b1 0 \u00d7 \u03b1 1`. See also `fin_two_arrow_equiv` for a\nnon-dependent version and `prod_equiv_pi_fin_two` for a version with inputs `\u03b1 \u03b2 : Type u`. -/\n@[simps {fully_applied := ff}] def pi_fin_two_equiv (\u03b1 : fin 2 \u2192 Type u) : (\u03a0 i, \u03b1 i) \u2243 \u03b1 0 \u00d7 \u03b1 1 :=\n{ to_fun := \u03bb f, (f 0, f 1),\n  inv_fun := \u03bb p, fin.cons p.1 $ fin.cons p.2 fin_zero_elim,\n  left_inv := \u03bb f, funext $ fin.forall_fin_two.2 \u27e8rfl, rfl\u27e9,\n  right_inv := \u03bb \u27e8x, y\u27e9, rfl }\n\nlemma fin.preimage_apply_01_prod {\u03b1 : fin 2 \u2192 Type u} (s : set (\u03b1 0)) (t : set (\u03b1 1)) :\n  (\u03bb f : \u03a0 i, \u03b1 i, (f 0, f 1)) \u207b\u00b9' s \u00d7\u02e2 t =\n    set.pi set.univ (fin.cons s $ fin.cons t fin.elim0) :=\nbegin\n  ext f,\n  have : (fin.cons s (fin.cons t fin.elim0) : \u03a0 i, set (\u03b1 i)) 1 = t := rfl,\n  simp [fin.forall_fin_two, this]\nend\n\nlemma fin.preimage_apply_01_prod' {\u03b1 : Type u} (s t : set \u03b1) :\n  (\u03bb f : fin 2 \u2192 \u03b1, (f 0, f 1)) \u207b\u00b9' s \u00d7\u02e2 t = set.pi set.univ ![s, t] :=\nfin.preimage_apply_01_prod s t\n\n/-- A product space `\u03b1 \u00d7 \u03b2` is equivalent to the space `\u03a0 i : fin 2, \u03b3 i`, where\n`\u03b3 = fin.cons \u03b1 (fin.cons \u03b2 fin_zero_elim)`. See also `pi_fin_two_equiv` and\n`fin_two_arrow_equiv`. -/\n@[simps {fully_applied := ff }] def prod_equiv_pi_fin_two (\u03b1 \u03b2 : Type u) :\n  \u03b1 \u00d7 \u03b2 \u2243 \u03a0 i : fin 2, ![\u03b1, \u03b2] i :=\n(pi_fin_two_equiv (fin.cons \u03b1 (fin.cons \u03b2 fin_zero_elim))).symm\n\n/-- The space of functions `fin 2 \u2192 \u03b1` is equivalent to `\u03b1 \u00d7 \u03b1`. See also `pi_fin_two_equiv` and\n`prod_equiv_pi_fin_two`. -/\n@[simps { fully_applied := ff }] def fin_two_arrow_equiv (\u03b1 : Type*) : (fin 2 \u2192 \u03b1) \u2243 \u03b1 \u00d7 \u03b1 :=\n{ inv_fun := \u03bb x, ![x.1, x.2],\n  .. pi_fin_two_equiv (\u03bb _, \u03b1) }\n\n/-- `\u03a0 i : fin 2, \u03b1 i` is order equivalent to `\u03b1 0 \u00d7 \u03b1 1`. See also `order_iso.fin_two_arrow_equiv`\nfor a non-dependent version. -/\ndef order_iso.pi_fin_two_iso (\u03b1 : fin 2 \u2192 Type u) [\u03a0 i, preorder (\u03b1 i)] :\n  (\u03a0 i, \u03b1 i) \u2243o \u03b1 0 \u00d7 \u03b1 1 :=\n{ to_equiv := pi_fin_two_equiv \u03b1,\n  map_rel_iff' := \u03bb f g, iff.symm fin.forall_fin_two }\n\n/-- The space of functions `fin 2 \u2192 \u03b1` is order equivalent to `\u03b1 \u00d7 \u03b1`. See also\n`order_iso.pi_fin_two_iso`. -/\ndef order_iso.fin_two_arrow_iso (\u03b1 : Type*) [preorder \u03b1] : (fin 2 \u2192 \u03b1) \u2243o \u03b1 \u00d7 \u03b1 :=\n{ to_equiv := fin_two_arrow_equiv \u03b1, .. order_iso.pi_fin_two_iso (\u03bb _, \u03b1) }\n\n/-- The 'identity' equivalence between `fin n` and `fin m` when `n = m`. -/\ndef fin_congr {n m : \u2115} (h : n = m) : fin n \u2243 fin m :=\n(fin.cast h).to_equiv\n\n@[simp] lemma fin_congr_apply_mk {n m : \u2115} (h : n = m) (k : \u2115) (w : k < n) :\n  fin_congr h \u27e8k, w\u27e9 = \u27e8k, by { subst h, exact w }\u27e9 :=\nrfl\n\n@[simp] lemma fin_congr_symm {n m : \u2115} (h : n = m) :\n  (fin_congr h).symm = fin_congr h.symm := rfl\n\n@[simp] lemma fin_congr_apply_coe {n m : \u2115} (h : n = m) (k : fin n) :\n  (fin_congr h k : \u2115) = k :=\nby { cases k, refl, }\n\nlemma fin_congr_symm_apply_coe {n m : \u2115} (h : n = m) (k : fin m) :\n  ((fin_congr h).symm k : \u2115) = k :=\nby { cases k, refl, }\n\n/-- An equivalence that removes `i` and maps it to `none`.\nThis is a version of `fin.pred_above` that produces `option (fin n)` instead of\nmapping both `i.cast_succ` and `i.succ` to `i`. -/\ndef fin_succ_equiv' {n : \u2115} (i : fin (n + 1)) :\n  fin (n + 1) \u2243 option (fin n) :=\n{ to_fun := i.insert_nth none some,\n  inv_fun := \u03bb x, x.cases_on' i (fin.succ_above i),\n  left_inv := \u03bb x, fin.succ_above_cases i (by simp) (\u03bb j, by simp) x,\n  right_inv := \u03bb x, by cases x; dsimp; simp }\n\n@[simp] lemma fin_succ_equiv'_at {n : \u2115} (i : fin (n + 1)) :\n  (fin_succ_equiv' i) i = none := by simp [fin_succ_equiv']\n\n@[simp] lemma fin_succ_equiv'_succ_above {n : \u2115} (i : fin (n + 1)) (j : fin n) :\n  fin_succ_equiv' i (i.succ_above j) = some j :=\n@fin.insert_nth_apply_succ_above n (\u03bb _, option (fin n)) i _ _ _\n\nlemma fin_succ_equiv'_below {n : \u2115} {i : fin (n + 1)} {m : fin n} (h : m.cast_succ < i) :\n  (fin_succ_equiv' i) m.cast_succ = some m :=\nby rw [\u2190 fin.succ_above_below _ _ h, fin_succ_equiv'_succ_above]\n\nlemma fin_succ_equiv'_above {n : \u2115} {i : fin (n + 1)} {m : fin n} (h : i \u2264 m.cast_succ) :\n  (fin_succ_equiv' i) m.succ = some m :=\nby rw [\u2190 fin.succ_above_above _ _ h, fin_succ_equiv'_succ_above]\n\n@[simp] lemma fin_succ_equiv'_symm_none {n : \u2115} (i : fin (n + 1)) :\n  (fin_succ_equiv' i).symm none = i := rfl\n\n@[simp] lemma fin_succ_equiv'_symm_some {n : \u2115} (i : fin (n + 1)) (j : fin n) :\n  (fin_succ_equiv' i).symm (some j) = i.succ_above j :=\nrfl\n\nlemma fin_succ_equiv'_symm_some_below {n : \u2115} {i : fin (n + 1)} {m : fin n} (h : m.cast_succ < i) :\n  (fin_succ_equiv' i).symm (some m) = m.cast_succ :=\nfin.succ_above_below i m h\n\nlemma fin_succ_equiv'_symm_some_above {n : \u2115} {i : fin (n + 1)} {m : fin n} (h : i \u2264 m.cast_succ) :\n  (fin_succ_equiv' i).symm (some m) = m.succ :=\nfin.succ_above_above i m h\n\nlemma fin_succ_equiv'_symm_coe_below {n : \u2115} {i : fin (n + 1)} {m : fin n} (h : m.cast_succ < i) :\n  (fin_succ_equiv' i).symm m = m.cast_succ :=\nfin_succ_equiv'_symm_some_below h\n\nlemma fin_succ_equiv'_symm_coe_above {n : \u2115} {i : fin (n + 1)} {m : fin n} (h : i \u2264 m.cast_succ) :\n  (fin_succ_equiv' i).symm m = m.succ :=\nfin_succ_equiv'_symm_some_above h\n\n/-- Equivalence between `fin (n + 1)` and `option (fin n)`.\nThis is a version of `fin.pred` that produces `option (fin n)` instead of\nrequiring a proof that the input is not `0`. -/\ndef fin_succ_equiv (n : \u2115) : fin (n + 1) \u2243 option (fin n) :=\nfin_succ_equiv' 0\n\n@[simp] lemma fin_succ_equiv_zero {n : \u2115} :\n  (fin_succ_equiv n) 0 = none :=\nrfl\n\n@[simp] lemma fin_succ_equiv_succ {n : \u2115} (m : fin n):\n  (fin_succ_equiv n) m.succ = some m :=\nfin_succ_equiv'_above (fin.zero_le _)\n\n@[simp] lemma fin_succ_equiv_symm_none {n : \u2115} :\n  (fin_succ_equiv n).symm none = 0 :=\nfin_succ_equiv'_symm_none _\n\n@[simp] lemma fin_succ_equiv_symm_some {n : \u2115} (m : fin n) :\n  (fin_succ_equiv n).symm (some m) = m.succ :=\ncongr_fun fin.succ_above_zero m\n\n@[simp] lemma fin_succ_equiv_symm_coe {n : \u2115} (m : fin n) :\n  (fin_succ_equiv n).symm m = m.succ :=\nfin_succ_equiv_symm_some m\n\n/-- The equiv version of `fin.pred_above_zero`. -/\nlemma fin_succ_equiv'_zero {n : \u2115} :\n  fin_succ_equiv' (0 : fin (n + 1)) = fin_succ_equiv n := rfl\n\n/-- `equiv` between `fin (n + 1)` and `option (fin n)` sending `fin.last n` to `none` -/\ndef fin_succ_equiv_last {n : \u2115} : fin (n + 1) \u2243 option (fin n) :=\nfin_succ_equiv' (fin.last n)\n\n@[simp] lemma fin_succ_equiv_last_cast_succ {n : \u2115} (i : fin n) :\n  fin_succ_equiv_last i.cast_succ = some i :=\nfin_succ_equiv'_below i.2\n\n@[simp] lemma fin_succ_equiv_last_last {n : \u2115} :\n  fin_succ_equiv_last (fin.last n) = none :=\nby simp [fin_succ_equiv_last]\n\n@[simp] lemma fin_succ_equiv_last_symm_some {n : \u2115} (i : fin n) :\n  fin_succ_equiv_last.symm (some i) = i.cast_succ :=\nfin_succ_equiv'_symm_some_below i.2\n\n@[simp] lemma fin_succ_equiv_last_symm_coe {n : \u2115} (i : fin n) :\n  fin_succ_equiv_last.symm \u2191i = i.cast_succ :=\nfin_succ_equiv'_symm_some_below i.2\n\n@[simp] lemma fin_succ_equiv_last_symm_none {n : \u2115}  :\n  fin_succ_equiv_last.symm none = fin.last n :=\nfin_succ_equiv'_symm_none _\n\n/-- Equivalence between `\u03a0 j : fin (n + 1), \u03b1 j` and `\u03b1 i \u00d7 \u03a0 j : fin n, \u03b1 (fin.succ_above i j)`. -/\n@[simps { fully_applied := ff}]\ndef equiv.pi_fin_succ_above_equiv {n : \u2115} (\u03b1 : fin (n + 1) \u2192 Type u) (i : fin (n + 1)) :\n  (\u03a0 j, \u03b1 j) \u2243 \u03b1 i \u00d7 (\u03a0 j, \u03b1 (i.succ_above j)) :=\n{ to_fun := \u03bb f, (f i, \u03bb j, f (i.succ_above j)),\n  inv_fun := \u03bb f, i.insert_nth f.1 f.2,\n  left_inv := \u03bb f, by simp [fin.insert_nth_eq_iff],\n  right_inv := \u03bb f, by simp }\n\n/-- Order isomorphism between `\u03a0 j : fin (n + 1), \u03b1 j` and\n`\u03b1 i \u00d7 \u03a0 j : fin n, \u03b1 (fin.succ_above i j)`. -/\ndef order_iso.pi_fin_succ_above_iso {n : \u2115} (\u03b1 : fin (n + 1) \u2192 Type u) [\u03a0 i, has_le (\u03b1 i)]\n  (i : fin (n + 1)) :\n  (\u03a0 j, \u03b1 j) \u2243o \u03b1 i \u00d7 (\u03a0 j, \u03b1 (i.succ_above j)) :=\n{ to_equiv := equiv.pi_fin_succ_above_equiv \u03b1 i,\n  map_rel_iff' := \u03bb f g, i.forall_iff_succ_above.symm }\n\n/-- Equivalence between `fin (n + 1) \u2192 \u03b2` and `\u03b2 \u00d7 (fin n \u2192 \u03b2)`. -/\n@[simps { fully_applied := ff}]\ndef equiv.pi_fin_succ (n : \u2115) (\u03b2 : Type u) :\n  (fin (n+1) \u2192 \u03b2) \u2243 \u03b2 \u00d7 (fin n \u2192 \u03b2) :=\nequiv.pi_fin_succ_above_equiv (\u03bb _, \u03b2) 0\n\n/-- Equivalence between `fin m \u2295 fin n` and `fin (m + n)` -/\ndef fin_sum_fin_equiv : fin m \u2295 fin n \u2243 fin (m + n) :=\n{ to_fun := sum.elim (fin.cast_add n) (fin.nat_add m),\n  inv_fun := \u03bb i, @fin.add_cases m n (\u03bb _, fin m \u2295 fin n) sum.inl sum.inr i,\n  left_inv := \u03bb x, by { cases x with y y; dsimp; simp },\n  right_inv := \u03bb x, by refine fin.add_cases (\u03bb i, _) (\u03bb i, _) x; simp }\n\n@[simp] lemma fin_sum_fin_equiv_apply_left (i : fin m) :\n  (fin_sum_fin_equiv (sum.inl i) : fin (m + n)) = fin.cast_add n i := rfl\n\n@[simp] lemma fin_sum_fin_equiv_apply_right (i : fin n) :\n  (fin_sum_fin_equiv (sum.inr i) : fin (m + n)) = fin.nat_add m i := rfl\n\n@[simp] lemma fin_sum_fin_equiv_symm_apply_cast_add (x : fin m) :\n  fin_sum_fin_equiv.symm (fin.cast_add n x) = sum.inl x :=\nfin_sum_fin_equiv.symm_apply_apply (sum.inl x)\n\n@[simp] lemma fin_sum_fin_equiv_symm_apply_nat_add (x : fin n) :\n  fin_sum_fin_equiv.symm (fin.nat_add m x) = sum.inr x :=\nfin_sum_fin_equiv.symm_apply_apply (sum.inr x)\n\n@[simp] lemma fin_sum_fin_equiv_symm_last :\n  fin_sum_fin_equiv.symm (fin.last n) = sum.inr 0 :=\nfin_sum_fin_equiv_symm_apply_nat_add 0\n\n/-- The equivalence between `fin (m + n)` and `fin (n + m)` which rotates by `n`. -/\ndef fin_add_flip : fin (m + n) \u2243 fin (n + m) :=\n(fin_sum_fin_equiv.symm.trans (equiv.sum_comm _ _)).trans fin_sum_fin_equiv\n\n@[simp] lemma fin_add_flip_apply_cast_add (k : fin m) (n : \u2115) :\n  fin_add_flip (fin.cast_add n k) = fin.nat_add n k :=\nby simp [fin_add_flip]\n\n@[simp] lemma fin_add_flip_apply_nat_add (k : fin n) (m : \u2115) :\n  fin_add_flip (fin.nat_add m k) = fin.cast_add m k :=\nby simp [fin_add_flip]\n\n@[simp] lemma fin_add_flip_apply_mk_left {k : \u2115} (h : k < m)\n  (hk : k < m + n := nat.lt_add_right k m n h)\n  (hnk : n + k < n + m := add_lt_add_left h n) :\n  fin_add_flip (\u27e8k, hk\u27e9 : fin (m + n)) = \u27e8n + k, hnk\u27e9 :=\nby convert fin_add_flip_apply_cast_add \u27e8k, h\u27e9 n\n\n@[simp] lemma fin_add_flip_apply_mk_right {k : \u2115} (h\u2081 : m \u2264 k) (h\u2082 : k < m + n) :\n  fin_add_flip (\u27e8k, h\u2082\u27e9 : fin (m + n)) = \u27e8k - m, tsub_le_self.trans_lt $ add_comm m n \u25b8 h\u2082\u27e9 :=\nbegin\n  convert fin_add_flip_apply_nat_add \u27e8k - m, (tsub_lt_iff_right h\u2081).2 _\u27e9 m,\n  { simp [add_tsub_cancel_of_le h\u2081] },\n  { rwa add_comm }\nend\n\n/-- Rotate `fin n` one step to the right. -/\ndef fin_rotate : \u03a0 n, equiv.perm (fin n)\n| 0 := equiv.refl _\n| (n+1) := fin_add_flip.trans (fin_congr (add_comm _ _))\n\nlemma fin_rotate_of_lt {k : \u2115} (h : k < n) :\n  fin_rotate (n+1) \u27e8k, lt_of_lt_of_le h (nat.le_succ _)\u27e9 = \u27e8k + 1, nat.succ_lt_succ h\u27e9 :=\nbegin\n  dsimp [fin_rotate],\n  simp [h, add_comm],\nend\n\nlemma fin_rotate_last' : fin_rotate (n+1) \u27e8n, lt_add_one _\u27e9 = \u27e80, nat.zero_lt_succ _\u27e9 :=\nbegin\n  dsimp [fin_rotate],\n  rw fin_add_flip_apply_mk_right,\n  simp,\nend\n\nlemma fin_rotate_last : fin_rotate (n+1) (fin.last _) = 0 :=\nfin_rotate_last'\n\nlemma fin.snoc_eq_cons_rotate {\u03b1 : Type*} (v : fin n \u2192 \u03b1) (a : \u03b1) :\n  @fin.snoc _ (\u03bb _, \u03b1) v a = (\u03bb i, @fin.cons _ (\u03bb _, \u03b1) a v (fin_rotate _ i)) :=\nbegin\n  ext \u27e8i, h\u27e9,\n  by_cases h' : i < n,\n  { rw [fin_rotate_of_lt h', fin.snoc, fin.cons, dif_pos h'],\n    refl, },\n  { have h'' : n = i,\n    { simp only [not_lt] at h', exact (nat.eq_of_le_of_lt_succ h' h).symm, },\n    subst h'',\n    rw [fin_rotate_last', fin.snoc, fin.cons, dif_neg (lt_irrefl _)],\n    refl, }\nend\n\n@[simp] lemma fin_rotate_zero : fin_rotate 0 = equiv.refl _ := rfl\n\n@[simp] lemma fin_rotate_one : fin_rotate 1 = equiv.refl _ :=\nsubsingleton.elim _ _\n\n@[simp] lemma fin_rotate_succ_apply {n : \u2115} (i : fin n.succ) :\n  fin_rotate n.succ i = i + 1 :=\nbegin\n  cases n,\n  { simp },\n  rcases i.le_last.eq_or_lt with rfl|h,\n  { simp [fin_rotate_last] },\n  { cases i,\n    simp only [fin.lt_iff_coe_lt_coe, fin.coe_last, fin.coe_mk] at h,\n    simp [fin_rotate_of_lt h, fin.eq_iff_veq, fin.add_def, nat.mod_eq_of_lt (nat.succ_lt_succ h)] },\nend\n\n@[simp] lemma fin_rotate_apply_zero {n : \u2115} : fin_rotate n.succ 0 = 1 :=\nby rw [fin_rotate_succ_apply, zero_add]\n\nlemma coe_fin_rotate_of_ne_last {n : \u2115} {i : fin n.succ} (h : i \u2260 fin.last n) :\n  (fin_rotate n.succ i : \u2115) = i + 1 :=\nbegin\n  rw fin_rotate_succ_apply,\n  have : (i : \u2115) < n := lt_of_le_of_ne (nat.succ_le_succ_iff.mp i.2) (fin.coe_injective.ne h),\n  exact fin.coe_add_one_of_lt this\nend\n\nlemma coe_fin_rotate {n : \u2115} (i : fin n.succ) :\n  (fin_rotate n.succ i : \u2115) = if i = fin.last n then 0 else i + 1 :=\nby rw [fin_rotate_succ_apply, fin.coe_add_one i]\n\n/-- Equivalence between `fin m \u00d7 fin n` and `fin (m * n)` -/\n@[simps]\ndef fin_prod_fin_equiv : fin m \u00d7 fin n \u2243 fin (m * n) :=\n{ to_fun := \u03bb x, \u27e8x.2 + n * x.1,\n    calc x.2.1 + n * x.1.1 + 1\n        = x.1.1 * n + x.2.1 + 1 : by ac_refl\n    ... \u2264 x.1.1 * n + n : nat.add_le_add_left x.2.2 _\n    ... = (x.1.1 + 1) * n : eq.symm $ nat.succ_mul _ _\n    ... \u2264 m * n : nat.mul_le_mul_right _ x.1.2\u27e9,\n  inv_fun := \u03bb x, (x.div_nat, x.mod_nat),\n  left_inv := \u03bb \u27e8x, y\u27e9,\n    have H : 0 < n, from nat.pos_of_ne_zero $ \u03bb H, nat.not_lt_zero y.1 $ H \u25b8 y.2,\n    prod.ext\n      (fin.eq_of_veq $ calc\n              (y.1 + n * x.1) / n\n            = y.1 / n + x.1 : nat.add_mul_div_left _ _ H\n        ... = 0 + x.1 : by rw nat.div_eq_of_lt y.2\n        ... = x.1 : nat.zero_add x.1)\n      (fin.eq_of_veq $ calc\n              (y.1 + n * x.1) % n\n            = y.1 % n : nat.add_mul_mod_self_left _ _ _\n        ... = y.1 : nat.mod_eq_of_lt y.2),\n  right_inv := \u03bb x, fin.eq_of_veq $ nat.mod_add_div _ _ }\n\n/-- Promote a `fin n` into a larger `fin m`, as a subtype where the underlying\nvalues are retained. This is the `order_iso` version of `fin.cast_le`. -/\n@[simps apply symm_apply]\ndef fin.cast_le_order_iso {n m : \u2115} (h : n \u2264 m) : fin n \u2243o {i : fin m // (i : \u2115) < n} :=\n{ to_fun := \u03bb i, \u27e8fin.cast_le h i, by simpa using i.is_lt\u27e9,\n  inv_fun := \u03bb i, \u27e8i, i.prop\u27e9,\n  left_inv := \u03bb _, by simp,\n  right_inv := \u03bb _, by simp,\n  map_rel_iff' := \u03bb _ _, by simp }\n\n/-- `fin 0` is a subsingleton. -/\ninstance subsingleton_fin_zero : subsingleton (fin 0) :=\nfin_zero_equiv.subsingleton\n\n/-- `fin 1` is a subsingleton. -/\ninstance subsingleton_fin_one : subsingleton (fin 1) :=\nfin_one_equiv.subsingleton\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/logic/equiv/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7063694308601269}}
{"text": "/-\nCopyright (c) 2020 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport algebra.polynomial.big_operators\nimport analysis.complex.roots_of_unity\nimport data.polynomial.lifts\nimport field_theory.separable\nimport field_theory.splitting_field\nimport number_theory.arithmetic_function\nimport ring_theory.roots_of_unity\nimport field_theory.ratfunc\nimport algebra.ne_zero\n\n/-!\n# Cyclotomic polynomials.\n\nFor `n : \u2115` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic\npolynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `\u220f (X - \u03bc)`, where `\u03bc` varies\nover the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then\nthis the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R`\nwith coefficients in any ring `R`.\n\n## Main definition\n\n* `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`.\n\n## Main results\n\n* `int_coeff_of_cycl` : If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K`\ncomes from a polynomial with integer coefficients.\n* `deg_of_cyclotomic` : The degree of `cyclotomic n` is `totient n`.\n* `prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = \u220f (cyclotomic i)`, where `i` divides `n`.\n* `cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The M\u00f6bius inversion formula for\n  `cyclotomic n R` over an abstract fraction field for `polynomial R`.\n* `cyclotomic.irreducible` : `cyclotomic n \u2124` is irreducible.\n\n## Implementation details\n\nOur definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting\nresults hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is\nnot the standard one unless there is a primitive `n`th root of unity in `R`. For example,\n`cyclotomic' 3 \u2124 = 1`, since there are no primitive cube roots of unity in `\u2124`. The main example is\n`R = \u2102`, we decided to work in general since the difficulties are essentially the same.\nTo get the standard cyclotomic polynomials, we use `int_coeff_of_cycl`, with `R = \u2102`, to get a\npolynomial with integer coefficients and then we map it to `polynomial R`, for any ring `R`.\nTo prove `cyclotomic.irreducible`, the irreducibility of `cyclotomic n \u2124`, we show in\n`cyclotomic_eq_minpoly` that `cyclotomic n \u2124` is the minimal polynomial of any `n`-th primitive root\nof unity `\u03bc : K`, where `K` is a field of characteristic `0`.\n-/\n\nopen_locale classical big_operators\nnoncomputable theory\n\nuniverse u\n\nnamespace polynomial\n\nsection cyclotomic'\n\nsection is_domain\n\nvariables {R : Type*} [comm_ring R] [is_domain R]\n\n/-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic\npolynomial if there is a primitive `n`-th root of unity in `R`. -/\ndef cyclotomic' (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] : polynomial R :=\n\u220f \u03bc in primitive_roots n R, (X - C \u03bc)\n\n/-- The zeroth modified cyclotomic polyomial is `1`. -/\n@[simp] lemma cyclotomic'_zero\n  (R : Type*) [comm_ring R] [is_domain R] : cyclotomic' 0 R = 1 :=\nby simp only [cyclotomic', finset.prod_empty, is_primitive_root.primitive_roots_zero]\n\n/-- The first modified cyclotomic polyomial is `X - 1`. -/\n@[simp] lemma cyclotomic'_one\n  (R : Type*) [comm_ring R] [is_domain R] : cyclotomic' 1 R = X - 1 :=\nbegin\n  simp only [cyclotomic', finset.prod_singleton, ring_hom.map_one,\n  is_primitive_root.primitive_roots_one]\nend\n\n/-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/\n@[simp] lemma cyclotomic'_two\n  (R : Type*) [comm_ring R] [is_domain R] (p : \u2115) [char_p R p] (hp : p \u2260 2) :\n  cyclotomic' 2 R = X + 1 :=\nbegin\n  rw [cyclotomic'],\n  have prim_root_two : primitive_roots 2 R = {(-1 : R)},\n  { apply finset.eq_singleton_iff_unique_mem.2,\n    split,\n    { simp only [is_primitive_root.neg_one p hp, nat.succ_pos', mem_primitive_roots] },\n    { intros x hx,\n      rw [mem_primitive_roots zero_lt_two] at hx,\n      exact is_primitive_root.eq_neg_one_of_two_right hx } },\n  simp only [prim_root_two, finset.prod_singleton, ring_hom.map_neg, ring_hom.map_one,\n  sub_neg_eq_add]\nend\n\n/-- `cyclotomic' n R` is monic. -/\nlemma cyclotomic'.monic\n  (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] : (cyclotomic' n R).monic :=\nmonic_prod_of_monic _ _ $ \u03bb z hz, monic_X_sub_C _\n\n/-- `cyclotomic' n R` is different from `0`. -/\nlemma cyclotomic'_ne_zero\n  (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] : cyclotomic' n R \u2260 0 :=\n(cyclotomic'.monic n R).ne_zero\n\n/-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of\nunity in `R`. -/\nlemma nat_degree_cyclotomic' {\u03b6 : R} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  (cyclotomic' n R).nat_degree = nat.totient n :=\nbegin\n  rw [cyclotomic'],\n  rw nat_degree_prod (primitive_roots n R) (\u03bb (z : R), (X - C z)),\n  simp only [is_primitive_root.card_primitive_roots h, mul_one,\n  nat_degree_X_sub_C,\n  nat.cast_id, finset.sum_const, nsmul_eq_mul],\n  intros z hz,\n  exact X_sub_C_ne_zero z\nend\n\n/-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/\nlemma degree_cyclotomic' {\u03b6 : R} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  (cyclotomic' n R).degree = nat.totient n :=\nby simp only [degree_eq_nat_degree (cyclotomic'_ne_zero n R), nat_degree_cyclotomic' h]\n\n/-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/\nlemma roots_of_cyclotomic (n : \u2115) (R : Type*) [comm_ring R] [is_domain R] :\n  (cyclotomic' n R).roots = (primitive_roots n R).val :=\nby { rw cyclotomic', exact roots_prod_X_sub_C (primitive_roots n R) }\n\n/-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = \u220f (X - \u03bc)`, where `\u03bc`\nvaries over the `n`-th roots of unity. -/\nlemma X_pow_sub_one_eq_prod {\u03b6 : R} {n : \u2115} (hpos : 0 < n) (h : is_primitive_root \u03b6 n) :\n  X ^ n - 1 = \u220f \u03b6 in nth_roots_finset n R, (X - C \u03b6) :=\nbegin\n  rw [nth_roots_finset, \u2190 multiset.to_finset_eq (is_primitive_root.nth_roots_nodup h)],\n  simp only [finset.prod_mk, ring_hom.map_one],\n  rw [nth_roots],\n  have hmonic : (X ^ n - C (1 : R)).monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm,\n  symmetry,\n  apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic,\n  rw [@nat_degree_X_pow_sub_C R _ _ n 1, \u2190 nth_roots],\n  exact is_primitive_root.card_nth_roots h\nend\n\nend is_domain\n\nsection field\n\nvariables {K : Type*} [field K]\n\n/-- `cyclotomic' n K` splits. -/\nlemma cyclotomic'_splits (n : \u2115) : splits (ring_hom.id K) (cyclotomic' n K) :=\nbegin\n  apply splits_prod (ring_hom.id K),\n  intros z hz,\n  simp only [splits_X_sub_C (ring_hom.id K)]\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1`splits. -/\nlemma X_pow_sub_one_splits {\u03b6 : K} {n : \u2115} (h : is_primitive_root \u03b6 n) :\n  splits (ring_hom.id K) (X ^ n - C (1 : K)) :=\nby rw [splits_iff_card_roots, \u2190 nth_roots, is_primitive_root.card_nth_roots h,\n    nat_degree_X_pow_sub_C]\n\n/-- If there is a primitive `n`-th root of unity in `K`, then\n`\u220f i in nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/\nlemma prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [comm_ring K] [is_domain K] {\u03b6 : K} {n : \u2115}\n  (hpos : 0 < n) (h : is_primitive_root \u03b6 n) : \u220f i in nat.divisors n, cyclotomic' i K = X ^ n - 1 :=\nbegin\n  rw [X_pow_sub_one_eq_prod hpos h],\n  have rwcyc : \u2200 i \u2208 nat.divisors n, cyclotomic' i K = \u220f \u03bc in primitive_roots i K, (X - C \u03bc),\n  { intros i hi,\n    simp only [cyclotomic'] },\n  conv_lhs { apply_congr,\n             skip,\n             simp [rwcyc, H] },\n  rw \u2190 finset.prod_bUnion,\n  { simp only [is_primitive_root.nth_roots_one_eq_bUnion_primitive_roots h] },\n  intros x hx y hy hdiff,\n  exact is_primitive_root.disjoint hdiff,\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then\n`cyclotomic' n K = (X ^ k - 1) /\u2098 (\u220f i in nat.proper_divisors k, cyclotomic' i K)`. -/\nlemma cyclotomic'_eq_X_pow_sub_one_div {K : Type*} [comm_ring K] [is_domain K] {\u03b6 : K} {n : \u2115}\n  (hpos : 0 < n) (h : is_primitive_root \u03b6 n) :\n  cyclotomic' n K = (X ^ n - 1) /\u2098 (\u220f i in nat.proper_divisors n, cyclotomic' i K) :=\nbegin\n  rw [\u2190prod_cyclotomic'_eq_X_pow_sub_one hpos h,\n  nat.divisors_eq_proper_divisors_insert_self_of_pos hpos,\n  finset.prod_insert nat.proper_divisors.not_self_mem],\n  have prod_monic : (\u220f i in nat.proper_divisors n, cyclotomic' i K).monic,\n  { apply monic_prod_of_monic,\n    intros i hi,\n    exact cyclotomic'.monic i K },\n  rw (div_mod_by_monic_unique (cyclotomic' n K) 0 prod_monic _).1,\n  simp only [degree_zero, zero_add],\n  refine \u27e8by rw mul_comm, _\u27e9,\n  rw [bot_lt_iff_ne_bot],\n  intro h,\n  exact monic.ne_zero prod_monic (degree_eq_bot.1 h)\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a\nmonic polynomial with integer coefficients. -/\nlemma int_coeff_of_cyclotomic' {K : Type*} [comm_ring K] [is_domain K] {\u03b6 : K} {n : \u2115}\n  (h : is_primitive_root \u03b6 n) :\n  (\u2203 (P : polynomial \u2124), map (int.cast_ring_hom K) P = cyclotomic' n K \u2227\n    P.degree = (cyclotomic' n K).degree \u2227 P.monic) :=\nbegin\n  refine lifts_and_degree_eq_and_monic _ (cyclotomic'.monic n K),\n  induction n using nat.strong_induction_on with k hk generalizing \u03b6 h,\n  cases nat.eq_zero_or_pos k with hzero hpos,\n  { use 1,\n    simp only [hzero, cyclotomic'_zero, set.mem_univ, subsemiring.coe_top, eq_self_iff_true,\n    coe_map_ring_hom, map_one, and_self] },\n  let B : polynomial K := \u220f i in nat.proper_divisors k, cyclotomic' i K,\n  have Bmo : B.monic,\n  { apply monic_prod_of_monic,\n    intros i hi,\n    exact (cyclotomic'.monic i K) },\n  have Bint : B \u2208 lifts (int.cast_ring_hom K),\n  { refine subsemiring.prod_mem (lifts (int.cast_ring_hom K)) _,\n    intros x hx,\n    have xsmall := (nat.mem_proper_divisors.1 hx).2,\n    obtain \u27e8d, hd\u27e9 := (nat.mem_proper_divisors.1 hx).1,\n    rw [mul_comm] at hd,\n    exact hk x xsmall (is_primitive_root.pow hpos h hd) },\n  replace Bint := lifts_and_degree_eq_and_monic Bint Bmo,\n  obtain \u27e8B\u2081, hB\u2081, hB\u2081deg, hB\u2081mo\u27e9 := Bint,\n  let Q\u2081 : polynomial \u2124 := (X ^ k - 1) /\u2098 B\u2081,\n  have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 \u2227 (0 : polynomial K).degree < B.degree,\n  { split,\n    { rw [zero_add, mul_comm, \u2190(prod_cyclotomic'_eq_X_pow_sub_one hpos h),\n      nat.divisors_eq_proper_divisors_insert_self_of_pos hpos],\n      simp only [true_and, finset.prod_insert, not_lt, nat.mem_proper_divisors, dvd_refl] },\n    rw [degree_zero, bot_lt_iff_ne_bot],\n    intro habs,\n    exact (monic.ne_zero Bmo) (degree_eq_bot.1 habs) },\n  replace huniq := div_mod_by_monic_unique (cyclotomic' k K) (0 : polynomial K) Bmo huniq,\n  simp only [lifts, ring_hom.mem_srange],\n  use Q\u2081,\n  rw [coe_map_ring_hom, (map_div_by_monic (int.cast_ring_hom K) hB\u2081mo), hB\u2081, \u2190 huniq.1],\n  simp\nend\n\n/-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`,\nthen `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/\nlemma unique_int_coeff_of_cycl {K : Type*} [comm_ring K] [is_domain K] [char_zero K] {\u03b6 : K}\n  {n : \u2115+} (h : is_primitive_root \u03b6 n) :\n  (\u2203! (P : polynomial \u2124), map (int.cast_ring_hom K) P = cyclotomic' n K) :=\nbegin\n  obtain \u27e8P, hP\u27e9 := int_coeff_of_cyclotomic' h,\n  refine \u27e8P, hP.1, \u03bb Q hQ, _\u27e9,\n  apply (map_injective (int.cast_ring_hom K) int.cast_injective),\n  rw [hP.1, hQ]\nend\n\nend field\n\nend cyclotomic'\n\nsection cyclotomic\n\n/-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/\ndef cyclotomic (n : \u2115) (R : Type*) [ring R] : polynomial R :=\nif h : n = 0 then 1 else\n  map (int.cast_ring_hom R) ((int_coeff_of_cyclotomic' (complex.is_primitive_root_exp n h)).some)\n\nlemma int_cyclotomic_rw {n : \u2115} (h : n \u2260 0) :\n  cyclotomic n \u2124 = (int_coeff_of_cyclotomic' (complex.is_primitive_root_exp n h)).some :=\nbegin\n  simp only [cyclotomic, h, dif_neg, not_false_iff],\n  ext i,\n  simp only [coeff_map, int.cast_id, ring_hom.eq_int_cast]\nend\n\n/-- `cyclotomic n R` comes from `cyclotomic n \u2124`. -/\nlemma map_cyclotomic_int (n : \u2115) (R : Type*) [ring R] :\n  map (int.cast_ring_hom R) (cyclotomic n \u2124) = cyclotomic n R :=\nbegin\n  by_cases hzero : n = 0,\n  { simp only [hzero, cyclotomic, dif_pos, map_one] },\n  simp only [cyclotomic, int_cyclotomic_rw, hzero, ne.def, dif_neg, not_false_iff]\nend\n\nlemma int_cyclotomic_spec (n : \u2115) : map (int.cast_ring_hom \u2102) (cyclotomic n \u2124) = cyclotomic' n \u2102 \u2227\n  (cyclotomic n \u2124).degree = (cyclotomic' n \u2102).degree \u2227 (cyclotomic n \u2124).monic  :=\nbegin\n  by_cases hzero : n = 0,\n  { simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos,\n  eq_self_iff_true, map_one, and_self] },\n  rw int_cyclotomic_rw hzero,\n  exact (int_coeff_of_cyclotomic' (complex.is_primitive_root_exp n hzero)).some_spec\nend\n\nlemma int_cyclotomic_unique {n : \u2115} {P : polynomial \u2124} (h : map (int.cast_ring_hom \u2102) P =\n  cyclotomic' n \u2102) : P = cyclotomic n \u2124 :=\nbegin\n  apply map_injective (int.cast_ring_hom \u2102) int.cast_injective,\n  rw [h, (int_cyclotomic_spec n).1]\nend\n\n/-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/\n@[simp] lemma map_cyclotomic (n : \u2115) {R S : Type*} [ring R] [ring S] (f : R \u2192+* S) :\n  map f (cyclotomic n R) = cyclotomic n S :=\nbegin\n  rw [\u2190map_cyclotomic_int n R, \u2190map_cyclotomic_int n S],\n  ext i,\n  simp only [coeff_map, ring_hom.eq_int_cast, ring_hom.map_int_cast]\nend\n\n/-- The zeroth cyclotomic polyomial is `1`. -/\n@[simp] lemma cyclotomic_zero (R : Type*) [ring R] : cyclotomic 0 R = 1 :=\nby simp only [cyclotomic, dif_pos]\n\n/-- The first cyclotomic polyomial is `X - 1`. -/\n@[simp] lemma cyclotomic_one (R : Type*) [ring R] : cyclotomic 1 R = X - 1 :=\nbegin\n  have hspec : map (int.cast_ring_hom \u2102) (X - 1) = cyclotomic' 1 \u2102,\n  { simp only [cyclotomic'_one, pnat.one_coe, map_X, map_one, map_sub] },\n  symmetry,\n  rw [\u2190map_cyclotomic_int, \u2190(int_cyclotomic_unique hspec)],\n  simp only [map_X, map_one, map_sub]\nend\n\n/-- The second cyclotomic polyomial is `X + 1`. -/\n@[simp] lemma cyclotomic_two (R : Type*) [ring R] : cyclotomic 2 R = X + 1 :=\nbegin\n  have hspec : map (int.cast_ring_hom \u2102) (X + 1) = cyclotomic' 2 \u2102,\n  { simp only [cyclotomic'_two \u2102 0 two_ne_zero.symm, map_add, map_X, map_one] },\n  symmetry,\n  rw [\u2190map_cyclotomic_int, \u2190(int_cyclotomic_unique hspec)],\n  simp only [map_add, map_X, map_one]\nend\n\n/-- `cyclotomic n` is monic. -/\nlemma cyclotomic.monic (n : \u2115) (R : Type*) [ring R] : (cyclotomic n R).monic :=\nbegin\n  rw \u2190map_cyclotomic_int,\n  apply monic_map,\n  exact (int_cyclotomic_spec n).2.2\nend\n\n/-- `cyclotomic n` is primitive. -/\nlemma cyclotomic.is_primitive (n : \u2115) (R : Type*) [comm_ring R] : (cyclotomic n R).is_primitive :=\n(cyclotomic.monic n R).is_primitive\n\n/-- `cyclotomic n R` is different from `0`. -/\nlemma cyclotomic_ne_zero (n : \u2115) (R : Type*) [ring R] [nontrivial R] : cyclotomic n R \u2260 0 :=\nmonic.ne_zero (cyclotomic.monic n R)\n\n/-- The degree of `cyclotomic n` is `totient n`. -/\nlemma degree_cyclotomic (n : \u2115) (R : Type*) [ring R] [nontrivial R] :\n  (cyclotomic n R).degree = nat.totient n :=\nbegin\n  rw \u2190map_cyclotomic_int,\n  rw degree_map_eq_of_leading_coeff_ne_zero (int.cast_ring_hom R) _,\n  { cases n with k,\n    { simp only [cyclotomic, degree_one, dif_pos, nat.totient_zero, with_top.coe_zero]},\n      rw [\u2190degree_cyclotomic' (complex.is_primitive_root_exp k.succ (nat.succ_ne_zero k))],\n      exact (int_cyclotomic_spec k.succ).2.1 },\n  simp only [(int_cyclotomic_spec n).right.right, ring_hom.eq_int_cast, monic.leading_coeff,\n  int.cast_one, ne.def, not_false_iff, one_ne_zero]\nend\n\n/-- The natural degree of `cyclotomic n` is `totient n`. -/\nlemma nat_degree_cyclotomic (n : \u2115) (R : Type*) [ring R] [nontrivial R] :\n  (cyclotomic n R).nat_degree = nat.totient n :=\nbegin\n  have hdeg := degree_cyclotomic n R,\n  rw degree_eq_nat_degree (cyclotomic_ne_zero n R) at hdeg,\n  exact_mod_cast hdeg\nend\n\n/-- The degree of `cyclotomic n R` is positive. -/\nlemma degree_cyclotomic_pos (n : \u2115) (R : Type*) (hpos : 0 < n) [ring R] [nontrivial R] :\n  0 < (cyclotomic n R).degree := by\n{ rw degree_cyclotomic n R, exact_mod_cast (nat.totient_pos hpos) }\n\n/-- `\u220f i in nat.divisors n, cyclotomic i R = X ^ n - 1`. -/\nlemma prod_cyclotomic_eq_X_pow_sub_one {n : \u2115} (hpos : 0 < n) (R : Type*) [comm_ring R] :\n  \u220f i in nat.divisors n, cyclotomic i R = X ^ n - 1 :=\nbegin\n  have integer : \u220f i in nat.divisors n, cyclotomic i \u2124 = X ^ n - 1,\n  { apply map_injective (int.cast_ring_hom \u2102) int.cast_injective,\n    rw map_prod (int.cast_ring_hom \u2102) (\u03bb i, cyclotomic i \u2124),\n    simp only [int_cyclotomic_spec, polynomial.map_pow, nat.cast_id, map_X, map_one, map_sub],\n    exact prod_cyclotomic'_eq_X_pow_sub_one hpos\n          (complex.is_primitive_root_exp n (ne_of_lt hpos).symm) },\n  have coerc : X ^ n - 1 = map (int.cast_ring_hom R) (X ^ n - 1),\n  { simp only [polynomial.map_pow, polynomial.map_X, polynomial.map_one, polynomial.map_sub] },\n  have h : \u2200 i \u2208 n.divisors, cyclotomic i R = map (int.cast_ring_hom R) (cyclotomic i \u2124),\n  { intros i hi,\n    exact (map_cyclotomic_int i R).symm },\n  rw [finset.prod_congr (refl n.divisors) h, coerc, \u2190map_prod (int.cast_ring_hom R)\n                                                    (\u03bb i, cyclotomic i \u2124), integer]\nend\n\nlemma cyclotomic.dvd_X_pow_sub_one (n : \u2115) (R : Type*) [comm_ring R] :\n  (cyclotomic n R) \u2223 X ^ n - 1 :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { simp },\n  refine \u27e8\u220f i in n.proper_divisors, cyclotomic i R, _\u27e9,\n  rw [\u2190prod_cyclotomic_eq_X_pow_sub_one hn,\n      nat.divisors_eq_proper_divisors_insert_self_of_pos hn, finset.prod_insert],\n  exact nat.proper_divisors.not_self_mem\nend\n\nlemma prod_cyclotomic_eq_geom_sum {n : \u2115} (h : 0 < n) (R) [comm_ring R] [is_domain R] :\n  \u220f i in n.divisors \\ {1}, cyclotomic i R = geom_sum X n :=\nbegin\n  apply_fun (* cyclotomic 1 R) using mul_left_injective\u2080 (cyclotomic_ne_zero 1 R),\n  have : \u220f i in {1}, cyclotomic i R = cyclotomic 1 R := finset.prod_singleton,\n  simp_rw [\u2190this, finset.prod_sdiff $ show {1} \u2286 n.divisors, by simp [h.ne'], this, cyclotomic_one,\n           geom_sum_mul, prod_cyclotomic_eq_X_pow_sub_one h]\nend\n\nlemma _root_.is_root_of_unity_iff {n : \u2115} (h : 0 < n) (R : Type*) [comm_ring R] [is_domain R]\n  {\u03b6 : R} : \u03b6 ^ n = 1 \u2194 \u2203 i \u2208 n.divisors, (cyclotomic i R).is_root \u03b6 :=\nby rw [\u2190mem_nth_roots h, nth_roots, mem_roots $ X_pow_sub_C_ne_zero h _,\n       C_1, \u2190prod_cyclotomic_eq_X_pow_sub_one h, is_root_prod]; apply_instance\n\nlemma is_root_of_unity_of_root_cyclotomic {n : \u2115} {R} [comm_ring R] {\u03b6 : R} {i : \u2115}\n  (hi : i \u2208 n.divisors) (h : (cyclotomic i R).is_root \u03b6) : \u03b6 ^ n = 1 :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { exact pow_zero _ },\n  have := congr_arg (eval \u03b6) (prod_cyclotomic_eq_X_pow_sub_one hn R).symm,\n  rw [eval_sub, eval_pow, eval_X, eval_one] at this,\n  convert eq_add_of_sub_eq' this,\n  convert (add_zero _).symm,\n  apply eval_eq_zero_of_dvd_of_eval_eq_zero _ h,\n  exact finset.dvd_prod_of_mem _ hi\nend\n\nsection arithmetic_function\nopen nat.arithmetic_function\nopen_locale arithmetic_function\n\n/-- `cyclotomic n R` can be expressed as a product in a fraction field of `polynomial R`\n  using M\u00f6bius inversion. -/\nlemma cyclotomic_eq_prod_X_pow_sub_one_pow_moebius {n : \u2115} (R : Type*) [comm_ring R] [is_domain R] :\n  algebra_map _ (ratfunc R) (cyclotomic n R) =\n    \u220f i in n.divisors_antidiagonal, (algebra_map (polynomial R) _ (X ^ i.snd - 1)) ^ \u03bc i.fst :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hpos,\n  { simp },\n  have h : \u2200 (n : \u2115), 0 < n \u2192\n    \u220f i in nat.divisors n, algebra_map _ (ratfunc R) (cyclotomic i R) = algebra_map _ _ (X ^ n - 1),\n  { intros n hn,\n    rw [\u2190 prod_cyclotomic_eq_X_pow_sub_one hn R, ring_hom.map_prod] },\n  rw (prod_eq_iff_prod_pow_moebius_eq_of_nonzero (\u03bb n hn, _) (\u03bb n hn, _)).1 h n hpos;\n  rw [ne.def, is_fraction_ring.to_map_eq_zero_iff],\n  { apply cyclotomic_ne_zero },\n  { apply monic.ne_zero,\n    apply monic_X_pow_sub_C _ (ne_of_gt hn) }\nend\n\nend arithmetic_function\n\n/-- We have\n`cyclotomic n R = (X ^ k - 1) /\u2098 (\u220f i in nat.proper_divisors k, cyclotomic i K)`. -/\nlemma cyclotomic_eq_X_pow_sub_one_div {R : Type*} [comm_ring R] {n : \u2115}\n  (hpos: 0 < n) : cyclotomic n R = (X ^ n - 1) /\u2098 (\u220f i in nat.proper_divisors n, cyclotomic i R) :=\nbegin\n  nontriviality R,\n  rw [\u2190prod_cyclotomic_eq_X_pow_sub_one hpos,\n  nat.divisors_eq_proper_divisors_insert_self_of_pos hpos,\n  finset.prod_insert nat.proper_divisors.not_self_mem],\n  have prod_monic : (\u220f i in nat.proper_divisors n, cyclotomic i R).monic,\n  { apply monic_prod_of_monic,\n    intros i hi,\n    exact cyclotomic.monic i R },\n  rw (div_mod_by_monic_unique (cyclotomic n R) 0 prod_monic _).1,\n  simp only [degree_zero, zero_add],\n  split,\n  { rw mul_comm },\n  rw [bot_lt_iff_ne_bot],\n  intro h,\n  exact monic.ne_zero prod_monic (degree_eq_bot.1 h)\nend\n\n/-- If `m` is a proper divisor of `n`, then `X ^ m - 1` divides\n`\u220f i in nat.proper_divisors n, cyclotomic i R`. -/\nlemma X_pow_sub_one_dvd_prod_cyclotomic (R : Type*) [comm_ring R] {n m : \u2115} (hpos : 0 < n)\n  (hm : m \u2223 n) (hdiff : m \u2260 n) : X ^ m - 1 \u2223 \u220f i in nat.proper_divisors n, cyclotomic i R :=\nbegin\n  replace hm := nat.mem_proper_divisors.2 \u27e8hm, lt_of_le_of_ne (nat.divisor_le (nat.mem_divisors.2\n    \u27e8hm, (ne_of_lt hpos).symm\u27e9)) hdiff\u27e9,\n  rw [\u2190 finset.sdiff_union_of_subset (nat.divisors_subset_proper_divisors (ne_of_lt hpos).symm\n    (nat.mem_proper_divisors.1 hm).1 (ne_of_lt (nat.mem_proper_divisors.1 hm).2)),\n    finset.prod_union finset.sdiff_disjoint, prod_cyclotomic_eq_X_pow_sub_one\n    (nat.pos_of_mem_proper_divisors hm)],\n  exact \u27e8(\u220f (x : \u2115) in n.proper_divisors \\ m.divisors, cyclotomic x R), by rw mul_comm\u27e9\nend\n\n/-- If there is a primitive `n`-th root of unity in `K`, then\n`cyclotomic n K = \u220f \u03bc in primitive_roots n R, (X - C \u03bc)`. In particular,\n`cyclotomic n K = cyclotomic' n K` -/\nlemma cyclotomic_eq_prod_X_sub_primitive_roots {K : Type*} [comm_ring K] [is_domain K] {\u03b6 : K}\n  {n : \u2115} (hz : is_primitive_root \u03b6 n) :\n  cyclotomic n K = \u220f \u03bc in primitive_roots n K, (X - C \u03bc) :=\nbegin\n  rw \u2190cyclotomic',\n  induction n using nat.strong_induction_on with k hk generalizing \u03b6 hz,\n  obtain hzero | hpos := k.eq_zero_or_pos,\n  { simp only [hzero, cyclotomic'_zero, cyclotomic_zero] },\n  have h : \u2200 i \u2208 k.proper_divisors, cyclotomic i K = cyclotomic' i K,\n  { intros i hi,\n    obtain \u27e8d, hd\u27e9 := (nat.mem_proper_divisors.1 hi).1,\n    rw mul_comm at hd,\n    exact hk i (nat.mem_proper_divisors.1 hi).2 (is_primitive_root.pow hpos hz hd) },\n  rw [@cyclotomic_eq_X_pow_sub_one_div _ _ _ hpos,\n      cyclotomic'_eq_X_pow_sub_one_div hpos hz, finset.prod_congr (refl k.proper_divisors) h]\nend\n\nsection roots\n\nvariables {R : Type*} {n : \u2115} [comm_ring R] [is_domain R]\n\n/-- Any `n`-th primitive root of unity is a root of `cyclotomic n K`.-/\nlemma is_root_cyclotomic (hpos : 0 < n) {\u03bc : R} (h : is_primitive_root \u03bc n) :\n  is_root (cyclotomic n R) \u03bc :=\nbegin\n  rw [\u2190 mem_roots (cyclotomic_ne_zero n R),\n      cyclotomic_eq_prod_X_sub_primitive_roots h, roots_prod_X_sub_C, \u2190 finset.mem_def],\n  rwa [\u2190 mem_primitive_roots hpos] at h,\nend\n\nprivate lemma is_root_cyclotomic_iff' {n : \u2115} {K : Type*} [field K] {\u03bc : K} [ne_zero (n : K)] :\n  is_root (cyclotomic n K) \u03bc \u2194 is_primitive_root \u03bc n :=\nbegin\n  -- in this proof, `o` stands for `order_of \u03bc`\n  have hnpos : 0 < n := (ne_zero.of_ne_zero_coe K).out.bot_lt,\n  refine \u27e8\u03bb h\u03bc, _, is_root_cyclotomic hnpos\u27e9,\n  have h\u03bcn : \u03bc ^ n = 1,\n  { rw is_root_of_unity_iff hnpos,\n    exact \u27e8n, n.mem_divisors_self hnpos.ne', h\u03bc\u27e9 },\n  by_contra hn\u03bc,\n  have ho : 0 < order_of \u03bc,\n  { apply order_of_pos',\n    rw is_of_fin_order_iff_pow_eq_one,\n    exact \u27e8n, hnpos, h\u03bcn\u27e9 },\n  have := pow_order_of_eq_one \u03bc,\n  rw is_root_of_unity_iff ho at this,\n  obtain \u27e8i, hio, hi\u03bc\u27e9 := this,\n  replace hio := nat.dvd_of_mem_divisors hio,\n  rw is_primitive_root.not_iff at hn\u03bc,\n  rw \u2190order_of_dvd_iff_pow_eq_one at h\u03bcn,\n  have key  : i < n := (nat.le_of_dvd ho hio).trans_lt ((nat.le_of_dvd hnpos h\u03bcn).lt_of_ne hn\u03bc),\n  have key' : i \u2223 n := hio.trans h\u03bcn,\n  rw \u2190polynomial.dvd_iff_is_root at h\u03bc hi\u03bc,\n  have hni : {i, n} \u2286 n.divisors,\n  { simpa [finset.insert_subset, key'] using hnpos.ne' },\n  obtain \u27e8k, hk\u27e9 := hi\u03bc,\n  obtain \u27e8j, hj\u27e9 := h\u03bc,\n  have := prod_cyclotomic_eq_X_pow_sub_one hnpos K,\n  rw [\u2190finset.prod_sdiff hni, finset.prod_pair key.ne, hk, hj] at this,\n  have hn := (X_pow_sub_one_separable_iff.mpr $ ne_zero.ne' n K).squarefree,\n  rw [\u2190this, squarefree] at hn,\n  contrapose! hn,\n  refine \u27e8X - C \u03bc, \u27e8(\u220f x in n.divisors \\ {i, n}, cyclotomic x K) * k * j, by ring\u27e9, _\u27e9,\n  simp [polynomial.is_unit_iff_degree_eq_zero]\nend\n\nlemma is_root_cyclotomic_iff [ne_zero (n : R)] {\u03bc : R} :\n  is_root (cyclotomic n R) \u03bc \u2194 is_primitive_root \u03bc n :=\nbegin\n  have hf : function.injective _ := is_fraction_ring.injective R (fraction_ring R),\n  haveI : ne_zero (n : fraction_ring R) := ne_zero.nat_of_injective hf,\n  rw [\u2190is_root_map_iff hf, \u2190is_primitive_root.map_iff_of_injective hf, map_cyclotomic,\n      \u2190is_root_cyclotomic_iff']\nend\n\nlemma roots_cyclotomic_nodup [ne_zero (n : R)] : (cyclotomic n R).roots.nodup :=\nbegin\n  obtain h | \u27e8\u03b6, h\u03b6\u27e9 := (cyclotomic n R).roots.empty_or_exists_mem,\n  { exact h.symm \u25b8 multiset.nodup_zero },\n  rw [mem_roots $ cyclotomic_ne_zero n R, is_root_cyclotomic_iff] at h\u03b6,\n  refine multiset.nodup_of_le (roots.le_of_dvd (X_pow_sub_C_ne_zero\n    (ne_zero.pos_of_ne_zero_coe R) 1) $ cyclotomic.dvd_X_pow_sub_one n R) h\u03b6.nth_roots_nodup,\nend\n\nlemma cyclotomic.roots_to_finset_eq_primitive_roots [ne_zero (n : R)] :\n    (\u27e8(cyclotomic n R).roots, roots_cyclotomic_nodup\u27e9 : finset _) = primitive_roots n R :=\nby { ext, simp [cyclotomic_ne_zero n R, is_root_cyclotomic_iff,\n                mem_primitive_roots, ne_zero.pos_of_ne_zero_coe R] }\n\nlemma cyclotomic.roots_eq_primitive_roots_val [ne_zero (n : R)] :\n  (cyclotomic n R).roots = (primitive_roots n R).val :=\nby rw \u2190cyclotomic.roots_to_finset_eq_primitive_roots\n\nend roots\n\n/-- If `R` is of characteristic zero, then `\u03b6` is a root of `cyclotomic n R` if and only if it is a\nprimitive `n`-th root of unity. -/\nlemma is_root_cyclotomic_iff_char_zero {n : \u2115} {R : Type*} [comm_ring R] [is_domain R]\n  [char_zero R] {\u03bc : R} (hn : 0 < n) :\n  (polynomial.cyclotomic n R).is_root \u03bc \u2194 is_primitive_root \u03bc n :=\nby { letI := ne_zero.of_gt hn, exact is_root_cyclotomic_iff }\n\n/-- Over a ring `R` of characteristic zero, `\u03bb n, cyclotomic n R` is injective. -/\nlemma cyclotomic_injective {R : Type*} [comm_ring R] [char_zero R] :\n  function.injective (\u03bb n, cyclotomic n R) :=\nbegin\n  intros n m hnm,\n  simp only at hnm,\n  rcases eq_or_ne n 0 with rfl | hzero,\n  { rw [cyclotomic_zero] at hnm,\n    replace hnm := congr_arg nat_degree hnm,\n    rw [nat_degree_one, nat_degree_cyclotomic] at hnm,\n    by_contra,\n    exact (nat.totient_pos (zero_lt_iff.2 (ne.symm h))).ne hnm },\n  { haveI := ne_zero.mk hzero,\n    rw [\u2190 map_cyclotomic_int _ R, \u2190 map_cyclotomic_int _ R] at hnm,\n    replace hnm := map_injective (int.cast_ring_hom R) int.cast_injective hnm,\n    replace hnm := congr_arg (map (int.cast_ring_hom \u2102)) hnm,\n    rw [map_cyclotomic_int, map_cyclotomic_int] at hnm,\n    have hprim := complex.is_primitive_root_exp _ hzero,\n    have hroot := is_root_cyclotomic_iff.2 hprim,\n    rw hnm at hroot,\n    haveI hmzero : ne_zero m := \u27e8\u03bb h, by simpa [h] using hroot\u27e9,\n    rw is_root_cyclotomic_iff at hroot,\n    replace hprim := hprim.eq_order_of,\n    rwa [\u2190 is_primitive_root.eq_order_of hroot] at hprim}\nend\n\nlemma eq_cyclotomic_iff {R : Type*} [comm_ring R] {n : \u2115} (hpos: 0 < n)\n  (P : polynomial R) :\n  P = cyclotomic n R \u2194 P * (\u220f i in nat.proper_divisors n, polynomial.cyclotomic i R) = X ^ n - 1 :=\nbegin\n  nontriviality R,\n  refine \u27e8\u03bb hcycl, _, \u03bb hP, _\u27e9,\n  { rw [hcycl, \u2190 finset.prod_insert (@nat.proper_divisors.not_self_mem n),\n      \u2190 nat.divisors_eq_proper_divisors_insert_self_of_pos hpos],\n    exact prod_cyclotomic_eq_X_pow_sub_one hpos R },\n  { have prod_monic : (\u220f i in nat.proper_divisors n, cyclotomic i R).monic,\n    { apply monic_prod_of_monic,\n      intros i hi,\n      exact cyclotomic.monic i R },\n    rw [@cyclotomic_eq_X_pow_sub_one_div R _ _ hpos,\n      (div_mod_by_monic_unique P 0 prod_monic _).1],\n    refine \u27e8by rwa [zero_add, mul_comm], _\u27e9,\n    rw [degree_zero, bot_lt_iff_ne_bot],\n    intro h,\n    exact monic.ne_zero prod_monic (degree_eq_bot.1 h) },\nend\n\n/-- If `p` is prime, then `cyclotomic p R = geom_sum X p`. -/\nlemma cyclotomic_eq_geom_sum {R : Type*} [comm_ring R] {p : \u2115}\n  (hp : nat.prime p) : cyclotomic p R = geom_sum X p :=\nbegin\n  refine ((eq_cyclotomic_iff hp.pos _).mpr _).symm,\n  simp only [nat.prime.proper_divisors hp, geom_sum_mul, finset.prod_singleton, cyclotomic_one],\nend\n\nlemma cyclotomic_prime_mul_X_sub_one (R : Type*) [comm_ring R] (p : \u2115) [hn : fact (nat.prime p)] :\n  (cyclotomic p R) * (X - 1) = X ^ p - 1 :=\nby rw [cyclotomic_eq_geom_sum hn.out, geom_sum_mul]\n\n/-- If `p ^ k` is a prime power, then `cyclotomic (p ^ (n + 1)) R = geom_sum (X ^ p ^ n) p`. -/\nlemma cyclotomic_prime_pow_eq_geom_sum {R : Type*} [comm_ring R] {p n : \u2115} (hp : nat.prime p) :\n  cyclotomic (p ^ (n + 1)) R = geom_sum (X ^ p ^ n) p :=\nbegin\n  have : \u2200 m, cyclotomic (p ^ (m + 1)) R = geom_sum (X ^ (p ^ m)) p \u2194\n    geom_sum (X ^ p ^ m) p * \u220f (x : \u2115) in finset.range (m + 1),\n      cyclotomic (p ^ x) R = X ^ p ^ (m + 1) - 1,\n  { intro m,\n    have := eq_cyclotomic_iff (pow_pos hp.pos (m + 1)) _,\n    rw eq_comm at this,\n    rw [this, nat.prod_proper_divisors_prime_pow hp], },\n  induction n with n_n n_ih,\n  { simp [cyclotomic_eq_geom_sum hp], },\n  rw ((eq_cyclotomic_iff (pow_pos hp.pos (n_n.succ + 1)) _).mpr _).symm,\n  rw [nat.prod_proper_divisors_prime_pow hp, finset.prod_range_succ, n_ih],\n  rw this at n_ih,\n  rw [mul_comm _ (geom_sum _ _), n_ih, geom_sum_mul, sub_left_inj, \u2190 pow_mul, pow_add, pow_one],\nend\n\n/-- The constant term of `cyclotomic n R` is `1` if `2 \u2264 n`. -/\nlemma cyclotomic_coeff_zero (R : Type*) [comm_ring R] {n : \u2115} (hn : 2 \u2264 n) :\n  (cyclotomic n R).coeff 0 = 1 :=\nbegin\n  induction n using nat.strong_induction_on with n hi,\n  have hprod : (\u220f i in nat.proper_divisors n, (polynomial.cyclotomic i R).coeff 0) = -1,\n  { rw [\u2190finset.insert_erase (nat.one_mem_proper_divisors_iff_one_lt.2\n      (lt_of_lt_of_le one_lt_two hn)), finset.prod_insert (finset.not_mem_erase 1 _),\n      cyclotomic_one R],\n    have hleq : \u2200 j \u2208 n.proper_divisors.erase 1, 2 \u2264 j,\n    { intros j hj,\n      apply nat.succ_le_of_lt,\n      exact (ne.le_iff_lt ((finset.mem_erase.1 hj).1).symm).mp\n              (nat.succ_le_of_lt (nat.pos_of_mem_proper_divisors (finset.mem_erase.1 hj).2)) },\n    have hcongr : \u2200 j \u2208 n.proper_divisors.erase 1, (cyclotomic j R).coeff 0 = 1,\n    { intros j hj,\n      exact hi j (nat.mem_proper_divisors.1 (finset.mem_erase.1 hj).2).2 (hleq j hj) },\n    have hrw : \u220f (x : \u2115) in n.proper_divisors.erase 1, (cyclotomic x R).coeff 0 = 1,\n    { rw finset.prod_congr (refl (n.proper_divisors.erase 1)) hcongr,\n      simp only [finset.prod_const_one] },\n    simp only [hrw, mul_one, zero_sub, coeff_one_zero, coeff_X_zero, coeff_sub] },\n  have heq : (X ^ n - 1).coeff 0 = -(cyclotomic n R).coeff 0,\n  { rw [\u2190prod_cyclotomic_eq_X_pow_sub_one (lt_of_lt_of_le zero_lt_two hn),\n        nat.divisors_eq_proper_divisors_insert_self_of_pos (lt_of_lt_of_le zero_lt_two hn),\n        finset.prod_insert nat.proper_divisors.not_self_mem, mul_coeff_zero, coeff_zero_prod, hprod,\n        mul_neg_eq_neg_mul_symm, mul_one] },\n  have hzero : (X ^ n - 1).coeff 0 = (-1 : R),\n  { rw coeff_zero_eq_eval_zero _,\n    simp only [zero_pow (lt_of_lt_of_le zero_lt_two hn), eval_X, eval_one, zero_sub, eval_pow,\n              eval_sub] },\n  rw hzero at heq,\n  exact neg_inj.mp (eq.symm heq)\nend\n\n/-- If `(a : \u2115)` is a root of `cyclotomic n (zmod p)`, where `p` is a prime, then `a` and `p` are\ncoprime. -/\nlemma coprime_of_root_cyclotomic {n : \u2115} (hpos : 0 < n) {p : \u2115} [hprime : fact p.prime] {a : \u2115}\n  (hroot : is_root (cyclotomic n (zmod p)) (nat.cast_ring_hom (zmod p) a)) :\n  a.coprime p :=\nbegin\n  apply nat.coprime.symm,\n  rw [hprime.1.coprime_iff_not_dvd],\n  intro h,\n  replace h := (zmod.nat_coe_zmod_eq_zero_iff_dvd a p).2 h,\n  rw [is_root.def, eq_nat_cast, h, \u2190 coeff_zero_eq_eval_zero] at hroot,\n  by_cases hone : n = 1,\n  { simp only [hone, cyclotomic_one, zero_sub, coeff_one_zero, coeff_X_zero, neg_eq_zero,\n    one_ne_zero, coeff_sub] at hroot,\n    exact hroot },\n  rw [cyclotomic_coeff_zero (zmod p) (nat.succ_le_of_lt (lt_of_le_of_ne\n        (nat.succ_le_of_lt hpos) (ne.symm hone)))] at hroot,\n  exact one_ne_zero hroot\nend\n\nend cyclotomic\n\nsection order\n\n/-- If `(a : \u2115)` is a root of `cyclotomic n (zmod p)`, then the multiplicative order of `a` modulo\n`p` divides `n`. -/\nlemma order_of_root_cyclotomic_dvd {n : \u2115} (hpos : 0 < n) {p : \u2115} [fact p.prime]\n  {a : \u2115} (hroot : is_root (cyclotomic n (zmod p)) (nat.cast_ring_hom (zmod p) a)) :\n  order_of (zmod.unit_of_coprime a (coprime_of_root_cyclotomic hpos hroot)) \u2223 n :=\nbegin\n  apply order_of_dvd_of_pow_eq_one,\n  suffices hpow : eval (nat.cast_ring_hom (zmod p) a) (X ^ n - 1 : polynomial (zmod p)) = 0,\n  { simp only [eval_X, eval_one, eval_pow, eval_sub, eq_nat_cast] at hpow,\n    apply units.coe_eq_one.1,\n    simp only [sub_eq_zero.mp hpow, zmod.coe_unit_of_coprime, units.coe_pow] },\n  rw [is_root.def] at hroot,\n  rw [\u2190 prod_cyclotomic_eq_X_pow_sub_one hpos (zmod p),\n    nat.divisors_eq_proper_divisors_insert_self_of_pos hpos,\n    finset.prod_insert nat.proper_divisors.not_self_mem, eval_mul, hroot, zero_mul]\nend\n\nend order\n\nsection minpoly\n\nopen is_primitive_root complex\n\n/-- The minimal polynomial of a primitive `n`-th root of unity `\u03bc` divides `cyclotomic n \u2124`. -/\nlemma _root_.is_primitive_root.minpoly_dvd_cyclotomic {n : \u2115} {K : Type*} [field K] {\u03bc : K}\n  (h : is_primitive_root \u03bc n) (hpos : 0 < n) [char_zero K] :\n  minpoly \u2124 \u03bc \u2223 cyclotomic n \u2124 :=\nbegin\n  apply minpoly.gcd_domain_dvd \u211a (is_integral h hpos) (cyclotomic.monic n \u2124).is_primitive,\n  simpa [aeval_def, eval\u2082_eq_eval_map, is_root.def] using is_root_cyclotomic hpos h\nend\n\nlemma _root_.is_primitive_root.minpoly_eq_cyclotomic_of_irreducible {K : Type*} [field K]\n  {R : Type*} [comm_ring R] [is_domain R] {\u03bc : R} {n : \u2115} [algebra K R] (h\u03bc : is_primitive_root \u03bc n)\n  (h : irreducible $ cyclotomic n K) [ne_zero (n : K)] : cyclotomic n K = minpoly K \u03bc :=\nbegin\n  haveI := ne_zero.of_no_zero_smul_divisors K R n,\n  refine minpoly.eq_of_irreducible_of_monic h _ (cyclotomic.monic n K),\n  rwa [aeval_def, eval\u2082_eq_eval_map, map_cyclotomic, \u2190is_root.def, is_root_cyclotomic_iff]\nend\n\n/-- `cyclotomic n \u2124` is the minimal polynomial of a primitive `n`-th root of unity `\u03bc`. -/\nlemma cyclotomic_eq_minpoly {n : \u2115} {K : Type*} [field K] {\u03bc : K}\n  (h : is_primitive_root \u03bc n) (hpos : 0 < n) [char_zero K] :\n  cyclotomic n \u2124 = minpoly \u2124 \u03bc :=\nbegin\n  refine eq_of_monic_of_dvd_of_nat_degree_le (minpoly.monic (is_integral h hpos))\n    (cyclotomic.monic n \u2124) (h.minpoly_dvd_cyclotomic hpos) _,\n  simpa [nat_degree_cyclotomic n \u2124] using totient_le_degree_minpoly h\nend\n\n/-- `cyclotomic n \u211a` is the minimal polynomial of a primitive `n`-th root of unity `\u03bc`. -/\n\n\n/-- `cyclotomic n \u2124` is irreducible. -/\nlemma cyclotomic.irreducible {n : \u2115} (hpos : 0 < n) : irreducible (cyclotomic n \u2124) :=\nbegin\n  rw [cyclotomic_eq_minpoly (is_primitive_root_exp n hpos.ne') hpos],\n  apply minpoly.irreducible,\n  exact (is_primitive_root_exp n hpos.ne').is_integral hpos,\nend\n\n/-- `cyclotomic n \u211a` is irreducible. -/\nlemma cyclotomic.irreducible_rat {n : \u2115} (hpos : 0 < n) : irreducible (cyclotomic n \u211a) :=\nbegin\n  rw [\u2190 map_cyclotomic_int],\n  exact (is_primitive.int.irreducible_iff_irreducible_map_cast (cyclotomic.is_primitive n \u2124)).1\n    (cyclotomic.irreducible hpos),\nend\n\n/-- If `n \u2260 m`, then `(cyclotomic n \u211a)` and `(cyclotomic m \u211a)` are coprime. -/\nlemma cyclotomic.is_coprime_rat {n m : \u2115} (h : n \u2260 m) :\n  is_coprime (cyclotomic n \u211a) (cyclotomic m \u211a) :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hnzero,\n  { exact is_coprime_one_left },\n  rcases m.eq_zero_or_pos with rfl | hmzero,\n  { exact is_coprime_one_right },\n  rw (irreducible.coprime_iff_not_dvd $ cyclotomic.irreducible_rat $ hnzero),\n  exact (\u03bb hdiv, h $ cyclotomic_injective $ eq_of_monic_of_associated (cyclotomic.monic n \u211a)\n    (cyclotomic.monic m \u211a) $ irreducible.associated_of_dvd (cyclotomic.irreducible_rat\n    hnzero) (cyclotomic.irreducible_rat hmzero) hdiv),\nend\n\nend minpoly\n\nsection expand\n\n/-- If `p` is a prime such that `\u00ac p \u2223 n`, then\n`expand R p (cyclotomic n R) = (cyclotomic (n * p) R) * (cyclotomic n R)`. -/\n@[simp] lemma cyclotomic_expand_eq_cyclotomic_mul {p n : \u2115} (hp : nat.prime p) (hdiv : \u00acp \u2223 n)\n  (R : Type*) [comm_ring R] :\n  expand R p (cyclotomic n R) = (cyclotomic (n * p) R) * (cyclotomic n R) :=\nbegin\n  rcases nat.eq_zero_or_pos n with rfl | hnpos,\n  { simp },\n  haveI := ne_zero.of_pos hnpos,\n  suffices : expand \u2124 p (cyclotomic n \u2124) = (cyclotomic (n * p) \u2124) * (cyclotomic n \u2124),\n  { rw [\u2190 map_cyclotomic_int, \u2190 map_expand, this, map_mul, map_cyclotomic_int] },\n  refine eq_of_monic_of_dvd_of_nat_degree_le (monic_mul (cyclotomic.monic _ _)\n    (cyclotomic.monic _ _)) ((cyclotomic.monic n \u2124).expand hp.pos) _ _,\n  { refine (is_primitive.int.dvd_iff_map_cast_dvd_map_cast _ _ (is_primitive.mul\n      (cyclotomic.is_primitive (n * p) \u2124) (cyclotomic.is_primitive n \u2124))\n      ((cyclotomic.monic n \u2124).expand hp.pos).is_primitive).2 _,\n    rw [map_mul, map_cyclotomic_int, map_cyclotomic_int, map_expand, map_cyclotomic_int],\n    refine is_coprime.mul_dvd (cyclotomic.is_coprime_rat (\u03bb h, _)) _ _,\n    { replace h : n * p = n * 1 := by simp [h],\n      exact nat.prime.ne_one hp (nat.eq_of_mul_eq_mul_left hnpos h) },\n    { have hpos : 0 < n * p := mul_pos hnpos hp.pos,\n      have hprim := complex.is_primitive_root_exp _ hpos.ne',\n      rw [cyclotomic_eq_minpoly_rat hprim hpos],\n      refine @minpoly.dvd \u211a \u2102 _ _ algebra_rat _ _ _,\n      rw [aeval_def, \u2190 eval_map, map_expand, map_cyclotomic, expand_eval, \u2190 is_root.def,\n        is_root_cyclotomic_iff],\n      convert is_primitive_root.pow_of_dvd hprim hp.ne_zero (dvd_mul_left p n),\n      rw [nat.mul_div_cancel _ (nat.prime.pos hp)] },\n    { have hprim := complex.is_primitive_root_exp _ hnpos.ne.symm,\n      rw [cyclotomic_eq_minpoly_rat hprim hnpos],\n      refine @minpoly.dvd \u211a \u2102 _ _ algebra_rat _ _ _,\n      rw [aeval_def, \u2190 eval_map, map_expand, expand_eval, \u2190 is_root.def,\n        \u2190 cyclotomic_eq_minpoly_rat hprim hnpos, map_cyclotomic, is_root_cyclotomic_iff],\n      exact is_primitive_root.pow_of_prime hprim hp hdiv,} },\n  { rw [nat_degree_expand, nat_degree_cyclotomic, nat_degree_mul (cyclotomic_ne_zero _ \u2124)\n      (cyclotomic_ne_zero _ \u2124), nat_degree_cyclotomic, nat_degree_cyclotomic, mul_comm n,\n      nat.totient_mul ((nat.prime.coprime_iff_not_dvd hp).2 hdiv),\n      nat.totient_prime hp, mul_comm (p - 1), \u2190 nat.mul_succ, nat.sub_one,\n      nat.succ_pred_eq_of_pos hp.pos] }\nend\n\n/-- If `p` is a prime such that `p \u2223 n`, then\n`expand R p (cyclotomic n R) = cyclotomic (p * n) R`. -/\n@[simp] lemma cyclotomic_expand_eq_cyclotomic {p n : \u2115} (hp : nat.prime p) (hdiv : p \u2223 n)\n  (R : Type*) [comm_ring R] : expand R p (cyclotomic n R) = cyclotomic (n * p) R :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hzero,\n  { simp },\n  haveI := ne_zero.of_pos hzero,\n  suffices : expand \u2124 p (cyclotomic n \u2124) = cyclotomic (n * p) \u2124,\n  { rw [\u2190 map_cyclotomic_int, \u2190 map_expand, this, map_cyclotomic_int] },\n  refine eq_of_monic_of_dvd_of_nat_degree_le (cyclotomic.monic _ _)\n    ((cyclotomic.monic n \u2124).expand hp.pos) _ _,\n  { have hpos := nat.mul_pos hzero hp.pos,\n    have hprim := complex.is_primitive_root_exp _ hpos.ne.symm,\n    rw [cyclotomic_eq_minpoly hprim hpos],\n    refine @minpoly.gcd_domain_dvd \u2124 \u2102 \u211a _ _ _ _ _ _ _ _ complex.algebra (algebra_int \u2102) _ _\n      (is_primitive_root.is_integral hprim hpos) _ ((cyclotomic.monic n \u2124).expand\n      hp.pos).is_primitive _,\n    rw [aeval_def, \u2190 eval_map, map_expand, map_cyclotomic, expand_eval,\n        \u2190 is_root.def, is_root_cyclotomic_iff],\n    { convert is_primitive_root.pow_of_dvd hprim hp.ne_zero (dvd_mul_left p n),\n      rw [nat.mul_div_cancel _ hp.pos] } },\n  { rw [nat_degree_expand, nat_degree_cyclotomic, nat_degree_cyclotomic, mul_comm n,\n        nat.totient_mul_of_prime_of_dvd hp hdiv, mul_comm] }\nend\n\nend expand\n\nsection char_p\n\n/-- If `R` is of characteristic `p` and `\u00acp \u2223 n`, then\n`cyclotomic (n * p) R = (cyclotomic n R) ^ (p - 1)`. -/\nlemma cyclotomic_mul_prime_eq_pow_of_not_dvd (R : Type*) {p n : \u2115} [hp : fact (nat.prime p)]\n  [ring R] [char_p R p] (hn : \u00acp \u2223 n) : cyclotomic (n * p) R = (cyclotomic n R) ^ (p - 1) :=\nbegin\n  suffices : cyclotomic (n * p) (zmod p) = (cyclotomic n (zmod p)) ^ (p - 1),\n  { rw [\u2190 map_cyclotomic _ (algebra_map (zmod p) R), \u2190 map_cyclotomic _ (algebra_map (zmod p) R),\n      this, polynomial.map_pow] },\n  apply mul_right_injective\u2080 (cyclotomic_ne_zero n $ zmod p),\n  rw [\u2190pow_succ, tsub_add_cancel_of_le hp.out.one_lt.le, mul_comm, \u2190 zmod.expand_card],\n  nth_rewrite 2 [\u2190 map_cyclotomic_int],\n  rw [\u2190 map_expand, cyclotomic_expand_eq_cyclotomic_mul hp.out hn, polynomial.map_mul,\n    map_cyclotomic, map_cyclotomic]\nend\n\n/-- If `R` is of characteristic `p` and `p \u2223 n`, then\n`cyclotomic (n * p) R = (cyclotomic n R) ^ p`. -/\nlemma cyclotomic_mul_prime_dvd_eq_pow (R : Type*) {p n : \u2115} [hp : fact (nat.prime p)] [ring R]\n  [char_p R p] (hn : p \u2223 n) : cyclotomic (n * p) R = (cyclotomic n R) ^ p :=\nbegin\n  suffices : cyclotomic (n * p) (zmod p) = (cyclotomic n (zmod p)) ^ p,\n  { rw [\u2190 map_cyclotomic _ (algebra_map (zmod p) R), \u2190 map_cyclotomic _ (algebra_map (zmod p) R),\n      this, polynomial.map_pow] },\n  rw [\u2190 zmod.expand_card, \u2190 map_cyclotomic_int n, \u2190 map_expand, cyclotomic_expand_eq_cyclotomic\n    hp.out hn, map_cyclotomic, mul_comm]\nend\n\n/-- If `R` is of characteristic `p` and `\u00acp \u2223 m`, then\n`cyclotomic (p ^ k * m) R = (cyclotomic m R) ^ (p ^ k - p ^ (k - 1))`. -/\nlemma cyclotomic_mul_prime_pow_eq (R : Type*) {p m : \u2115} [fact (nat.prime p)]\n  [ring R] [char_p R p] (hm : \u00acp \u2223 m) :\n  \u2200 {k}, 0 < k \u2192 cyclotomic (p ^ k * m) R = (cyclotomic m R) ^ (p ^ k - p ^ (k - 1))\n| 1 _ := by rw [pow_one, nat.sub_self, pow_zero, mul_comm,\n  cyclotomic_mul_prime_eq_pow_of_not_dvd R hm]\n| (a + 2) _ :=\nbegin\n  have hdiv : p \u2223 p ^ a.succ * m := \u27e8p ^ a * m, by rw [\u2190 mul_assoc, pow_succ]\u27e9,\n  rw [pow_succ, mul_assoc, mul_comm, cyclotomic_mul_prime_dvd_eq_pow R hdiv,\n      cyclotomic_mul_prime_pow_eq a.succ_pos, \u2190 pow_mul],\n  congr' 1,\n  simp only [tsub_zero, nat.succ_sub_succ_eq_sub],\n  rw [nat.mul_sub_right_distrib, mul_comm, pow_succ']\nend\n\n/-- If `R` is of characteristic `p` and `\u00acp \u2223 m`, then `\u03b6` is a root of `cyclotomic (p ^ k * m) R`\n if and only if it is a primitive `m`-th root of unity. -/\nlemma is_root_cyclotomic_prime_pow_mul_iff_of_char_p {m k p : \u2115} {R : Type*} [comm_ring R]\n  [is_domain R] [hp : fact (nat.prime p)] [hchar : char_p R p] {\u03bc : R} [ne_zero (m : R)] :\n  (polynomial.cyclotomic (p ^ k * m) R).is_root \u03bc \u2194 is_primitive_root \u03bc m :=\nbegin\n  rcases k.eq_zero_or_pos with rfl | hk,\n  { rw [pow_zero, one_mul, is_root_cyclotomic_iff] },\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rw [is_root.def, cyclotomic_mul_prime_pow_eq R (ne_zero.not_char_dvd R p m) hk, eval_pow] at h,\n    replace h := pow_eq_zero h,\n    rwa [\u2190 is_root.def, is_root_cyclotomic_iff] at h },\n  { rw [\u2190 is_root_cyclotomic_iff, is_root.def] at h,\n    rw [cyclotomic_mul_prime_pow_eq R (ne_zero.not_char_dvd R p m) hk,\n        is_root.def, eval_pow, h, zero_pow],\n    simp only [tsub_pos_iff_lt],\n    apply strict_mono_pow hp.out.one_lt (nat.pred_lt hk.ne') }\nend\n\nend char_p\n\nend polynomial\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/ring_theory/polynomial/cyclotomic/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7063131605202941}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module topology.metric_space.pi_nat\n! leanprover-community/mathlib commit e1a7bdeb4fd826b7e71d130d34988f0a2d26a177\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Tactic.RingExp\nimport Mathbin.Topology.MetricSpace.HausdorffDistance\n\n/-!\n# Topological study of spaces `\u03a0 (n : \u2115), E n`\n\nWhen `E n` are topological spaces, the space `\u03a0 (n : \u2115), E n` is naturally a topological space\n(with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure.\nHowever, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one\ncan put a noncanonical metric space structure (or rather, several of them). This is done in this\nfile.\n\n## Main definitions and results\n\nOne can define a combinatorial distance on `\u03a0 (n : \u2115), E n`, as follows:\n\n* `pi_nat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`.\n* `pi_nat.first_diff x y` is the first index at which `x i \u2260 y i`.\n* `pi_nat.dist x y` is equal to `(1/2) ^ (first_diff x y)`. It defines a distance\n  on `\u03a0 (n : \u2115), E n`, compatible with the topology when the `E n` have the discrete topology.\n* `pi_nat.metric_space`: the metric space structure, given by this distance. Not registered as an\n  instance. This space is a complete metric space.\n* `pi_nat.metric_space_of_discrete_uniformity`: the same metric space structure, but adjusting the\n  uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an\n  instance\n* `pi_nat.metric_space_nat_nat`: the particular case of `\u2115 \u2192 \u2115`, not registered as an instance.\n\nThese results are used to construct continuous functions on `\u03a0 n, E n`:\n\n* `pi_nat.exists_retraction_of_is_closed`: given a nonempty closed subset `s` of `\u03a0 (n : \u2115), E n`,\n  there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s`\n  restricting to the identity on `s`.\n* `exists_nat_nat_continuous_surjective_of_complete_space`: given any nonempty complete metric\n  space with second-countable topology, there exists a continuous surjection from `\u2115 \u2192 \u2115` onto\n  this space.\n\nOne can also put distances on `\u03a0 (i : \u03b9), E i` when the spaces `E i` are metric spaces (not discrete\nin general), and `\u03b9` is countable.\n\n* `pi_countable.dist` is the distance on `\u03a0 i, E i` given by\n    `dist x y = \u2211' i, min (1/2)^(encode i) (dist (x i) (y i))`.\n* `pi_countable.metric_space` is the corresponding metric space structure, adjusted so that\n  the uniformity is definitionally the product uniformity. Not registered as an instance.\n-/\n\n\nnoncomputable section\n\nopen Classical Topology Filter\n\nopen TopologicalSpace Set Metric Filter Function\n\nattribute [local simp] pow_le_pow_iff one_lt_two inv_le_inv\n\nvariable {E : \u2115 \u2192 Type _}\n\nnamespace PiNat\n\n/-! ### The first_diff function -/\n\n\n/-- In a product space `\u03a0 n, E n`, then `first_diff x y` is the first index at which `x` and `y`\ndiffer. If `x = y`, then by convention we set `first_diff x x = 0`. -/\n@[pp_nodot]\nirreducible_def firstDiff (x y : \u2200 n, E n) : \u2115 :=\n  if h : x \u2260 y then Nat.find (ne_iff.1 h) else 0\n#align pi_nat.first_diff PiNat.firstDiff\n\ntheorem apply_firstDiff_ne {x y : \u2200 n, E n} (h : x \u2260 y) : x (firstDiff x y) \u2260 y (firstDiff x y) :=\n  by\n  rw [first_diff, dif_pos h]\n  exact Nat.find_spec (ne_iff.1 h)\n#align pi_nat.apply_first_diff_ne PiNat.apply_firstDiff_ne\n\ntheorem apply_eq_of_lt_firstDiff {x y : \u2200 n, E n} {n : \u2115} (hn : n < firstDiff x y) : x n = y n :=\n  by\n  rw [first_diff] at hn\n  split_ifs  at hn\n  \u00b7 convert Nat.find_min (ne_iff.1 h) hn\n    simp\n  \u00b7 exact (not_lt_zero' hn).elim\n#align pi_nat.apply_eq_of_lt_first_diff PiNat.apply_eq_of_lt_firstDiff\n\ntheorem firstDiff_comm (x y : \u2200 n, E n) : firstDiff x y = firstDiff y x :=\n  by\n  rcases eq_or_ne x y with (rfl | hxy); \u00b7 rfl\n  rcases lt_trichotomy (first_diff x y) (first_diff y x) with (h | h | h)\n  \u00b7 exact (apply_first_diff_ne hxy (apply_eq_of_lt_first_diff h).symm).elim\n  \u00b7 exact h\n  \u00b7 exact (apply_first_diff_ne hxy.symm (apply_eq_of_lt_first_diff h).symm).elim\n#align pi_nat.first_diff_comm PiNat.firstDiff_comm\n\ntheorem min_firstDiff_le (x y z : \u2200 n, E n) (h : x \u2260 z) :\n    min (firstDiff x y) (firstDiff y z) \u2264 firstDiff x z :=\n  by\n  by_contra' H\n  have : x (first_diff x z) = z (first_diff x z) :=\n    calc\n      x (first_diff x z) = y (first_diff x z) :=\n        apply_eq_of_lt_first_diff (H.trans_le (min_le_left _ _))\n      _ = z (first_diff x z) := apply_eq_of_lt_first_diff (H.trans_le (min_le_right _ _))\n      \n  exact (apply_first_diff_ne h this).elim\n#align pi_nat.min_first_diff_le PiNat.min_firstDiff_le\n\n/-! ### Cylinders -/\n\n\n/-- In a product space `\u03a0 n, E n`, the cylinder set of length `n` around `x`, denoted\n`cylinder x n`, is the set of sequences `y` that coincide with `x` on the first `n` symbols, i.e.,\nsuch that `y i = x i` for all `i < n`.\n-/\ndef cylinder (x : \u2200 n, E n) (n : \u2115) : Set (\u2200 n, E n) :=\n  { y | \u2200 i, i < n \u2192 y i = x i }\n#align pi_nat.cylinder PiNat.cylinder\n\ntheorem cylinder_eq_pi (x : \u2200 n, E n) (n : \u2115) :\n    cylinder x n = Set.pi (Finset.range n : Set \u2115) fun i : \u2115 => {x i} :=\n  by\n  ext y\n  simp [cylinder]\n#align pi_nat.cylinder_eq_pi PiNat.cylinder_eq_pi\n\n@[simp]\ntheorem cylinder_zero (x : \u2200 n, E n) : cylinder x 0 = univ := by simp [cylinder_eq_pi]\n#align pi_nat.cylinder_zero PiNat.cylinder_zero\n\ntheorem cylinder_anti (x : \u2200 n, E n) {m n : \u2115} (h : m \u2264 n) : cylinder x n \u2286 cylinder x m :=\n  fun y hy i hi => hy i (hi.trans_le h)\n#align pi_nat.cylinder_anti PiNat.cylinder_anti\n\n@[simp]\ntheorem mem_cylinder_iff {x y : \u2200 n, E n} {n : \u2115} : y \u2208 cylinder x n \u2194 \u2200 i, i < n \u2192 y i = x i :=\n  Iff.rfl\n#align pi_nat.mem_cylinder_iff PiNat.mem_cylinder_iff\n\ntheorem self_mem_cylinder (x : \u2200 n, E n) (n : \u2115) : x \u2208 cylinder x n := by simp\n#align pi_nat.self_mem_cylinder PiNat.self_mem_cylinder\n\ntheorem mem_cylinder_iff_eq {x y : \u2200 n, E n} {n : \u2115} :\n    y \u2208 cylinder x n \u2194 cylinder y n = cylinder x n :=\n  by\n  constructor\n  \u00b7 intro hy\n    apply subset.antisymm\n    \u00b7 intro z hz i hi\n      rw [\u2190 hy i hi]\n      exact hz i hi\n    \u00b7 intro z hz i hi\n      rw [hy i hi]\n      exact hz i hi\n  \u00b7 intro h\n    rw [\u2190 h]\n    exact self_mem_cylinder _ _\n#align pi_nat.mem_cylinder_iff_eq PiNat.mem_cylinder_iff_eq\n\ntheorem mem_cylinder_comm (x y : \u2200 n, E n) (n : \u2115) : y \u2208 cylinder x n \u2194 x \u2208 cylinder y n := by\n  simp [mem_cylinder_iff_eq, eq_comm]\n#align pi_nat.mem_cylinder_comm PiNat.mem_cylinder_comm\n\ntheorem mem_cylinder_iff_le_firstDiff {x y : \u2200 n, E n} (hne : x \u2260 y) (i : \u2115) :\n    x \u2208 cylinder y i \u2194 i \u2264 firstDiff x y := by\n  constructor\n  \u00b7 intro h\n    by_contra'\n    exact apply_first_diff_ne hne (h _ this)\n  \u00b7 intro hi j hj\n    exact apply_eq_of_lt_first_diff (hj.trans_le hi)\n#align pi_nat.mem_cylinder_iff_le_first_diff PiNat.mem_cylinder_iff_le_firstDiff\n\ntheorem mem_cylinder_firstDiff (x y : \u2200 n, E n) : x \u2208 cylinder y (firstDiff x y) := fun i hi =>\n  apply_eq_of_lt_firstDiff hi\n#align pi_nat.mem_cylinder_first_diff PiNat.mem_cylinder_firstDiff\n\ntheorem cylinder_eq_cylinder_of_le_firstDiff (x y : \u2200 n, E n) {n : \u2115} (hn : n \u2264 firstDiff x y) :\n    cylinder x n = cylinder y n := by\n  rw [\u2190 mem_cylinder_iff_eq]\n  intro i hi\n  exact apply_eq_of_lt_first_diff (hi.trans_le hn)\n#align pi_nat.cylinder_eq_cylinder_of_le_first_diff PiNat.cylinder_eq_cylinder_of_le_firstDiff\n\ntheorem union\u1d62_cylinder_update (x : \u2200 n, E n) (n : \u2115) :\n    (\u22c3 k, cylinder (update x n k) (n + 1)) = cylinder x n :=\n  by\n  ext y\n  simp only [mem_cylinder_iff, mem_Union]\n  constructor\n  \u00b7 rintro \u27e8k, hk\u27e9 i hi\n    simpa [hi.ne] using hk i (Nat.lt_succ_of_lt hi)\n  \u00b7 intro H\n    refine' \u27e8y n, fun i hi => _\u27e9\n    rcases Nat.lt_succ_iff_lt_or_eq.1 hi with (h'i | rfl)\n    \u00b7 simp [H i h'i, h'i.ne]\n    \u00b7 simp\n#align pi_nat.Union_cylinder_update PiNat.union\u1d62_cylinder_update\n\ntheorem update_mem_cylinder (x : \u2200 n, E n) (n : \u2115) (y : E n) : update x n y \u2208 cylinder x n :=\n  mem_cylinder_iff.2 fun i hi => by simp [hi.ne]\n#align pi_nat.update_mem_cylinder PiNat.update_mem_cylinder\n\n/-!\n### A distance function on `\u03a0 n, E n`\n\nWe define a distance function on `\u03a0 n, E n`, given by `dist x y = (1/2)^n` where `n` is the first\nindex at which `x` and `y` differ. When each `E n` has the discrete topology, this distance will\ndefine the right topology on the product space. We do not record a global `has_dist` instance nor\na `metric_space`instance, as other distances may be used on these spaces, but we register them as\nlocal instances in this section.\n-/\n\n\n/-- The distance function on a product space `\u03a0 n, E n`, given by `dist x y = (1/2)^n` where `n` is\nthe first index at which `x` and `y` differ. -/\nprotected def hasDist : Dist (\u2200 n, E n) :=\n  \u27e8fun x y => if h : x \u2260 y then (1 / 2 : \u211d) ^ firstDiff x y else 0\u27e9\n#align pi_nat.has_dist PiNat.hasDist\n\nattribute [local instance] PiNat.hasDist\n\ntheorem dist_eq_of_ne {x y : \u2200 n, E n} (h : x \u2260 y) : dist x y = (1 / 2 : \u211d) ^ firstDiff x y := by\n  simp [dist, h]\n#align pi_nat.dist_eq_of_ne PiNat.dist_eq_of_ne\n\nprotected theorem dist_self (x : \u2200 n, E n) : dist x x = 0 := by simp [dist]\n#align pi_nat.dist_self PiNat.dist_self\n\nprotected theorem dist_comm (x y : \u2200 n, E n) : dist x y = dist y x := by\n  simp [dist, @eq_comm _ x y, first_diff_comm]\n#align pi_nat.dist_comm PiNat.dist_comm\n\nprotected theorem dist_nonneg (x y : \u2200 n, E n) : 0 \u2264 dist x y :=\n  by\n  rcases eq_or_ne x y with (rfl | h)\n  \u00b7 simp [dist]\n  \u00b7 simp [dist, h]\n#align pi_nat.dist_nonneg PiNat.dist_nonneg\n\ntheorem dist_triangle_nonarch (x y z : \u2200 n, E n) : dist x z \u2264 max (dist x y) (dist y z) :=\n  by\n  rcases eq_or_ne x z with (rfl | hxz)\n  \u00b7 simp [PiNat.dist_self x, PiNat.dist_nonneg]\n  rcases eq_or_ne x y with (rfl | hxy)\n  \u00b7 simp\n  rcases eq_or_ne y z with (rfl | hyz)\n  \u00b7 simp\n  simp only [dist_eq_of_ne, hxz, hxy, hyz, inv_le_inv, one_div, inv_pow, zero_lt_bit0, Ne.def,\n    not_false_iff, le_max_iff, zero_lt_one, pow_le_pow_iff, one_lt_two, pow_pos,\n    min_le_iff.1 (min_first_diff_le x y z hxz)]\n#align pi_nat.dist_triangle_nonarch PiNat.dist_triangle_nonarch\n\nprotected theorem dist_triangle (x y z : \u2200 n, E n) : dist x z \u2264 dist x y + dist y z :=\n  calc\n    dist x z \u2264 max (dist x y) (dist y z) := dist_triangle_nonarch x y z\n    _ \u2264 dist x y + dist y z := max_le_add_of_nonneg (PiNat.dist_nonneg _ _) (PiNat.dist_nonneg _ _)\n    \n#align pi_nat.dist_triangle PiNat.dist_triangle\n\nprotected theorem eq_of_dist_eq_zero (x y : \u2200 n, E n) (hxy : dist x y = 0) : x = y :=\n  by\n  rcases eq_or_ne x y with (rfl | h); \u00b7 rfl\n  simp [dist_eq_of_ne h] at hxy\n  exact (two_ne_zero (pow_eq_zero hxy)).elim\n#align pi_nat.eq_of_dist_eq_zero PiNat.eq_of_dist_eq_zero\n\ntheorem mem_cylinder_iff_dist_le {x y : \u2200 n, E n} {n : \u2115} :\n    y \u2208 cylinder x n \u2194 dist y x \u2264 (1 / 2) ^ n :=\n  by\n  rcases eq_or_ne y x with (rfl | hne)\n  \u00b7 simp [PiNat.dist_self]\n  suffices (\u2200 i : \u2115, i < n \u2192 y i = x i) \u2194 n \u2264 first_diff y x by simpa [dist_eq_of_ne hne]\n  constructor\n  \u00b7 intro hy\n    by_contra' H\n    exact apply_first_diff_ne hne (hy _ H)\n  \u00b7 intro h i hi\n    exact apply_eq_of_lt_first_diff (hi.trans_le h)\n#align pi_nat.mem_cylinder_iff_dist_le PiNat.mem_cylinder_iff_dist_le\n\ntheorem apply_eq_of_dist_lt {x y : \u2200 n, E n} {n : \u2115} (h : dist x y < (1 / 2) ^ n) {i : \u2115}\n    (hi : i \u2264 n) : x i = y i :=\n  by\n  rcases eq_or_ne x y with (rfl | hne)\n  \u00b7 rfl\n  have : n < first_diff x y := by\n    simpa [dist_eq_of_ne hne, inv_lt_inv, pow_lt_pow_iff, one_lt_two] using h\n  exact apply_eq_of_lt_first_diff (hi.trans_lt this)\n#align pi_nat.apply_eq_of_dist_lt PiNat.apply_eq_of_dist_lt\n\n/-- A function to a pseudo-metric-space is `1`-Lipschitz if and only if points in the same cylinder\nof length `n` are sent to points within distance `(1/2)^n`.\nNot expressed using `lipschitz_with` as we don't have a metric space structure -/\ntheorem lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder {\u03b1 : Type _}\n    [PseudoMetricSpace \u03b1] {f : (\u2200 n, E n) \u2192 \u03b1} :\n    (\u2200 x y : \u2200 n, E n, dist (f x) (f y) \u2264 dist x y) \u2194\n      \u2200 x y n, y \u2208 cylinder x n \u2192 dist (f x) (f y) \u2264 (1 / 2) ^ n :=\n  by\n  constructor\n  \u00b7 intro H x y n hxy\n    apply (H x y).trans\n    rw [PiNat.dist_comm]\n    exact mem_cylinder_iff_dist_le.1 hxy\n  \u00b7 intro H x y\n    rcases eq_or_ne x y with (rfl | hne)\n    \u00b7 simp [PiNat.dist_nonneg]\n    rw [dist_eq_of_ne hne]\n    apply H x y (first_diff x y)\n    rw [first_diff_comm]\n    exact mem_cylinder_first_diff _ _\n#align pi_nat.lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder PiNat.lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder\n\nvariable (E) [\u2200 n, TopologicalSpace (E n)] [\u2200 n, DiscreteTopology (E n)]\n\ntheorem isTopologicalBasis_cylinders :\n    IsTopologicalBasis { s : Set (\u2200 n, E n) | \u2203 (x : \u2200 n, E n)(n : \u2115), s = cylinder x n } :=\n  by\n  apply is_topological_basis_of_open_of_nhds\n  \u00b7 rintro u \u27e8x, n, rfl\u27e9\n    rw [cylinder_eq_pi]\n    exact isOpen_set_pi (Finset.range n).finite_toSet fun a ha => isOpen_discrete _\n  \u00b7 intro x u hx u_open\n    obtain \u27e8v, \u27e8U, F, hUF, rfl\u27e9, xU, Uu\u27e9 :\n      \u2203 (v : Set (\u2200 i : \u2115, E i))(H :\n        v \u2208\n          { S : Set (\u2200 i : \u2115, E i) |\n            \u2203 (U : \u2200 i : \u2115, Set (E i))(F : Finset \u2115),\n              (\u2200 i : \u2115, i \u2208 F \u2192 U i \u2208 { s : Set (E i) | IsOpen s }) \u2227 S = (F : Set \u2115).pi U }),\n        x \u2208 v \u2227 v \u2286 u :=\n      (isTopologicalBasis_pi fun n : \u2115 => is_topological_basis_opens).exists_subset_of_mem_open hx\n        u_open\n    rcases Finset.bddAbove F with \u27e8n, hn\u27e9\n    refine' \u27e8cylinder x (n + 1), \u27e8x, n + 1, rfl\u27e9, self_mem_cylinder _ _, subset.trans _ Uu\u27e9\n    intro y hy\n    suffices \u2200 i : \u2115, i \u2208 F \u2192 y i \u2208 U i by simpa\n    intro i hi\n    have : y i = x i := mem_cylinder_iff.1 hy i ((hn hi).trans_lt (lt_add_one n))\n    rw [this]\n    simp only [Set.mem_pi, Finset.mem_coe] at xU\n    exact xU i hi\n#align pi_nat.is_topological_basis_cylinders PiNat.isTopologicalBasis_cylinders\n\nvariable {E}\n\ntheorem isOpen_iff_dist (s : Set (\u2200 n, E n)) :\n    IsOpen s \u2194 \u2200 x \u2208 s, \u2203 \u03b5 > 0, \u2200 y, dist x y < \u03b5 \u2192 y \u2208 s :=\n  by\n  constructor\n  \u00b7 intro hs x hx\n    obtain \u27e8v, \u27e8y, n, rfl\u27e9, h'x, h's\u27e9 :\n      \u2203 (v : Set (\u2200 n : \u2115, E n))(H : v \u2208 { s | \u2203 (x : \u2200 n : \u2115, E n)(n : \u2115), s = cylinder x n }),\n        x \u2208 v \u2227 v \u2286 s :=\n      (is_topological_basis_cylinders E).exists_subset_of_mem_open hx hs\n    rw [\u2190 mem_cylinder_iff_eq.1 h'x] at h's\n    exact\n      \u27e8(1 / 2 : \u211d) ^ n, by simp, fun y hy => h's fun i hi => (apply_eq_of_dist_lt hy hi.le).symm\u27e9\n  \u00b7 intro h\n    apply (is_topological_basis_cylinders E).isOpen_iff.2 fun x hx => _\n    rcases h x hx with \u27e8\u03b5, \u03b5pos, h\u03b5\u27e9\n    obtain \u27e8n, hn\u27e9 : \u2203 n : \u2115, (1 / 2 : \u211d) ^ n < \u03b5 := exists_pow_lt_of_lt_one \u03b5pos one_half_lt_one\n    refine' \u27e8cylinder x n, \u27e8x, n, rfl\u27e9, self_mem_cylinder x n, fun y hy => h\u03b5 y _\u27e9\n    rw [PiNat.dist_comm]\n    exact (mem_cylinder_iff_dist_le.1 hy).trans_lt hn\n#align pi_nat.is_open_iff_dist PiNat.isOpen_iff_dist\n\n/-- Metric space structure on `\u03a0 (n : \u2115), E n` when the spaces `E n` have the discrete topology,\nwhere the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and\n`y` differ. Not registered as a global instance by default.\nWarning: this definition makes sure that the topology is defeq to the original product topology,\nbut it does not take care of a possible uniformity. If the `E n` have a uniform structure, then\nthere will be two non-defeq uniform structures on `\u03a0 n, E n`, the product one and the one coming\nfrom the metric structure. In this case, use `metric_space_of_discrete_uniformity` instead. -/\nprotected def metricSpace : MetricSpace (\u2200 n, E n) :=\n  MetricSpace.ofDistTopology dist PiNat.dist_self PiNat.dist_comm PiNat.dist_triangle\n    isOpen_iff_dist PiNat.eq_of_dist_eq_zero\n#align pi_nat.metric_space PiNat.metricSpace\n\n/-- Metric space structure on `\u03a0 (n : \u2115), E n` when the spaces `E n` have the discrete uniformity,\nwhere the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and\n`y` differ. Not registered as a global instance by default. -/\nprotected def metricSpaceOfDiscreteUniformity {E : \u2115 \u2192 Type _} [\u2200 n, UniformSpace (E n)]\n    (h : \u2200 n, uniformity (E n) = \ud835\udcdf idRel) : MetricSpace (\u2200 n, E n) :=\n  haveI : \u2200 n, DiscreteTopology (E n) := fun n => discreteTopology_of_discrete_uniformity (h n)\n  { dist_triangle := PiNat.dist_triangle\n    dist_comm := PiNat.dist_comm\n    dist_self := PiNat.dist_self\n    eq_of_dist_eq_zero := PiNat.eq_of_dist_eq_zero\n    toUniformSpace := Pi.uniformSpace _\n    uniformity_dist :=\n      by\n      simp [Pi.uniformity, comap_infi, gt_iff_lt, preimage_set_of_eq, comap_principal,\n        PseudoMetricSpace.uniformity_dist, h, idRel]\n      apply le_antisymm\n      \u00b7 simp only [le_inf\u1d62_iff, le_principal_iff]\n        intro \u03b5 \u03b5pos\n        obtain \u27e8n, hn\u27e9 : \u2203 n, (1 / 2 : \u211d) ^ n < \u03b5 := exists_pow_lt_of_lt_one \u03b5pos (by norm_num)\n        apply\n          @mem_infi_of_Inter _ _ _ _ _ (Finset.range n).finite_toSet fun i =>\n            { p : (\u2200 n : \u2115, E n) \u00d7 \u2200 n : \u2115, E n | p.fst i = p.snd i }\n        \u00b7 simp only [mem_principal, set_of_subset_set_of, imp_self, imp_true_iff]\n        \u00b7 rintro \u27e8x, y\u27e9 hxy\n          simp only [Finset.mem_coe, Finset.mem_range, Inter_coe_set, mem_Inter, mem_set_of_eq] at\n            hxy\n          apply lt_of_le_of_lt _ hn\n          rw [\u2190 mem_cylinder_iff_dist_le, mem_cylinder_iff]\n          exact hxy\n      \u00b7 simp only [le_inf\u1d62_iff, le_principal_iff]\n        intro n\n        refine' mem_infi_of_mem ((1 / 2) ^ n) _\n        refine' mem_infi_of_mem (by positivity) _\n        simp only [mem_principal, set_of_subset_set_of, Prod.forall]\n        intro x y hxy\n        exact apply_eq_of_dist_lt hxy le_rfl }\n#align pi_nat.metric_space_of_discrete_uniformity PiNat.metricSpaceOfDiscreteUniformity\n\n/-- Metric space structure on `\u2115 \u2192 \u2115` where the distance is given by `dist x y = (1/2)^n`,\nwhere `n` is the smallest index where `x` and `y` differ.\nNot registered as a global instance by default. -/\ndef metricSpaceNatNat : MetricSpace (\u2115 \u2192 \u2115) :=\n  PiNat.metricSpaceOfDiscreteUniformity fun n => rfl\n#align pi_nat.metric_space_nat_nat PiNat.metricSpaceNatNat\n\nattribute [local instance] PiNat.metricSpace\n\nprotected theorem completeSpace : CompleteSpace (\u2200 n, E n) :=\n  by\n  refine' Metric.complete_of_convergent_controlled_sequences (fun n => (1 / 2) ^ n) (by simp) _\n  intro u hu\n  refine' \u27e8fun n => u n n, tendsto_pi_nhds.2 fun i => _\u27e9\n  refine' tendsto_const_nhds.congr' _\n  filter_upwards [Filter.Ici_mem_atTop i]with n hn\n  exact apply_eq_of_dist_lt (hu i i n le_rfl hn) le_rfl\n#align pi_nat.complete_space PiNat.completeSpace\n\n/-!\n### Retractions inside product spaces\n\nWe show that, in a space `\u03a0 (n : \u2115), E n` where each `E n` is discrete, there is a retraction on\nany closed nonempty subset `s`, i.e., a continuous map `f` from the whole space to `s` restricting\nto the identity on `s`. The map `f` is defined as follows. For `x \u2208 s`, let `f x = x`. Otherwise,\nconsider the longest prefix `w` that `x` shares with an element of `s`, and let `f x = z_w`\nwhere `z_w` is an element of `s` starting with `w`.\n-/\n\n\ntheorem exists_disjoint_cylinder {s : Set (\u2200 n, E n)} (hs : IsClosed s) {x : \u2200 n, E n}\n    (hx : x \u2209 s) : \u2203 n, Disjoint s (cylinder x n) :=\n  by\n  rcases eq_empty_or_nonempty s with (rfl | hne)\n  \u00b7 exact \u27e80, by simp\u27e9\n  have A : 0 < inf_dist x s := (hs.not_mem_iff_inf_dist_pos hne).1 hx\n  obtain \u27e8n, hn\u27e9 : \u2203 n, (1 / 2 : \u211d) ^ n < inf_dist x s := exists_pow_lt_of_lt_one A one_half_lt_one\n  refine' \u27e8n, _\u27e9\n  apply disjoint_left.2 fun y ys hy => _\n  apply lt_irrefl (inf_dist x s)\n  calc\n    inf_dist x s \u2264 dist x y := inf_dist_le_dist_of_mem ys\n    _ \u2264 (1 / 2) ^ n := by\n      rw [mem_cylinder_comm] at hy\n      exact mem_cylinder_iff_dist_le.1 hy\n    _ < inf_dist x s := hn\n    \n#align pi_nat.exists_disjoint_cylinder PiNat.exists_disjoint_cylinder\n\n/-- Given a point `x` in a product space `\u03a0 (n : \u2115), E n`, and `s` a subset of this space, then\n`shortest_prefix_diff x s` if the smallest `n` for which there is no element of `s` having the same\nprefix of length `n` as `x`. If there is no such `n`, then use `0` by convention. -/\ndef shortestPrefixDiff {E : \u2115 \u2192 Type _} (x : \u2200 n, E n) (s : Set (\u2200 n, E n)) : \u2115 :=\n  if h : \u2203 n, Disjoint s (cylinder x n) then Nat.find h else 0\n#align pi_nat.shortest_prefix_diff PiNat.shortestPrefixDiff\n\ntheorem firstDiff_lt_shortestPrefixDiff {s : Set (\u2200 n, E n)} (hs : IsClosed s) {x y : \u2200 n, E n}\n    (hx : x \u2209 s) (hy : y \u2208 s) : firstDiff x y < shortestPrefixDiff x s :=\n  by\n  have A := exists_disjoint_cylinder hs hx\n  rw [shortest_prefix_diff, dif_pos A]\n  have B := Nat.find_spec A\n  contrapose! B\n  rw [not_disjoint_iff_nonempty_inter]\n  refine' \u27e8y, hy, _\u27e9\n  rw [mem_cylinder_comm]\n  exact cylinder_anti y B (mem_cylinder_first_diff x y)\n#align pi_nat.first_diff_lt_shortest_prefix_diff PiNat.firstDiff_lt_shortestPrefixDiff\n\ntheorem shortestPrefixDiff_pos {s : Set (\u2200 n, E n)} (hs : IsClosed s) (hne : s.Nonempty)\n    {x : \u2200 n, E n} (hx : x \u2209 s) : 0 < shortestPrefixDiff x s :=\n  by\n  rcases hne with \u27e8y, hy\u27e9\n  exact (zero_le _).trans_lt (first_diff_lt_shortest_prefix_diff hs hx hy)\n#align pi_nat.shortest_prefix_diff_pos PiNat.shortestPrefixDiff_pos\n\n/-- Given a point `x` in a product space `\u03a0 (n : \u2115), E n`, and `s` a subset of this space, then\n`longest_prefix x s` if the largest `n` for which there is an element of `s` having the same\nprefix of length `n` as `x`. If there is no such `n`, use `0` by convention. -/\ndef longestPrefix {E : \u2115 \u2192 Type _} (x : \u2200 n, E n) (s : Set (\u2200 n, E n)) : \u2115 :=\n  shortestPrefixDiff x s - 1\n#align pi_nat.longest_prefix PiNat.longestPrefix\n\ntheorem firstDiff_le_longestPrefix {s : Set (\u2200 n, E n)} (hs : IsClosed s) {x y : \u2200 n, E n}\n    (hx : x \u2209 s) (hy : y \u2208 s) : firstDiff x y \u2264 longestPrefix x s :=\n  by\n  rw [longest_prefix, le_tsub_iff_right]\n  \u00b7 exact first_diff_lt_shortest_prefix_diff hs hx hy\n  \u00b7 exact shortest_prefix_diff_pos hs \u27e8y, hy\u27e9 hx\n#align pi_nat.first_diff_le_longest_prefix PiNat.firstDiff_le_longestPrefix\n\ntheorem inter_cylinder_longestPrefix_nonempty {s : Set (\u2200 n, E n)} (hs : IsClosed s)\n    (hne : s.Nonempty) (x : \u2200 n, E n) : (s \u2229 cylinder x (longestPrefix x s)).Nonempty :=\n  by\n  by_cases hx : x \u2208 s\n  \u00b7 exact \u27e8x, hx, self_mem_cylinder _ _\u27e9\n  have A := exists_disjoint_cylinder hs hx\n  have B : longest_prefix x s < shortest_prefix_diff x s :=\n    Nat.pred_lt (shortest_prefix_diff_pos hs hne hx).ne'\n  rw [longest_prefix, shortest_prefix_diff, dif_pos A] at B\u22a2\n  obtain \u27e8y, ys, hy\u27e9 : \u2203 y : \u2200 n : \u2115, E n, y \u2208 s \u2227 x \u2208 cylinder y (Nat.find A - 1) :=\n    by\n    have := Nat.find_min A B\n    push_neg  at this\n    simp_rw [not_disjoint_iff, mem_cylinder_comm] at this\n    exact this\n  refine' \u27e8y, ys, _\u27e9\n  rw [mem_cylinder_iff_eq] at hy\u22a2\n  rw [hy]\n#align pi_nat.inter_cylinder_longest_prefix_nonempty PiNat.inter_cylinder_longestPrefix_nonempty\n\ntheorem disjoint_cylinder_of_longestPrefix_lt {s : Set (\u2200 n, E n)} (hs : IsClosed s) {x : \u2200 n, E n}\n    (hx : x \u2209 s) {n : \u2115} (hn : longestPrefix x s < n) : Disjoint s (cylinder x n) :=\n  by\n  rcases eq_empty_or_nonempty s with (h's | hne); \u00b7 simp [h's]\n  contrapose! hn\n  rcases not_disjoint_iff_nonempty_inter.1 hn with \u27e8y, ys, hy\u27e9\n  apply le_trans _ (first_diff_le_longest_prefix hs hx ys)\n  apply (mem_cylinder_iff_le_first_diff (ne_of_mem_of_not_mem ys hx).symm _).1\n  rwa [mem_cylinder_comm]\n#align pi_nat.disjoint_cylinder_of_longest_prefix_lt PiNat.disjoint_cylinder_of_longestPrefix_lt\n\n/-- If two points `x, y` coincide up to length `n`, and the longest common prefix of `x` with `s`\nis strictly shorter than `n`, then the longest common prefix of `y` with `s` is the same, and both\ncylinders of this length based at `x` and `y` coincide. -/\ntheorem cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff {x y : \u2200 n, E n}\n    {s : Set (\u2200 n, E n)} (hs : IsClosed s) (hne : s.Nonempty)\n    (H : longestPrefix x s < firstDiff x y) (xs : x \u2209 s) (ys : y \u2209 s) :\n    cylinder x (longestPrefix x s) = cylinder y (longestPrefix y s) :=\n  by\n  have l_eq : longest_prefix y s = longest_prefix x s :=\n    by\n    rcases lt_trichotomy (longest_prefix y s) (longest_prefix x s) with (L | L | L)\n    \u00b7 have Ax : (s \u2229 cylinder x (longest_prefix x s)).Nonempty :=\n        inter_cylinder_longest_prefix_nonempty hs hne x\n      have Z := disjoint_cylinder_of_longest_prefix_lt hs ys L\n      rw [first_diff_comm] at H\n      rw [cylinder_eq_cylinder_of_le_first_diff _ _ H.le] at Z\n      exact (Ax.not_disjoint Z).elim\n    \u00b7 exact L\n    \u00b7 have Ay : (s \u2229 cylinder y (longest_prefix y s)).Nonempty :=\n        inter_cylinder_longest_prefix_nonempty hs hne y\n      have A'y : (s \u2229 cylinder y (longest_prefix x s).succ).Nonempty :=\n        Ay.mono (inter_subset_inter_right s (cylinder_anti _ L))\n      have Z := disjoint_cylinder_of_longest_prefix_lt hs xs (Nat.lt_succ_self _)\n      rw [cylinder_eq_cylinder_of_le_first_diff _ _ H] at Z\n      exact (A'y.not_disjoint Z).elim\n  rw [l_eq, \u2190 mem_cylinder_iff_eq]\n  exact cylinder_anti y H.le (mem_cylinder_first_diff x y)\n#align pi_nat.cylinder_longest_prefix_eq_of_longest_prefix_lt_first_diff PiNat.cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff\n\n/-- Given a closed nonempty subset `s` of `\u03a0 (n : \u2115), E n`, there exists a Lipschitz retraction\nonto this set, i.e., a Lipschitz map with range equal to `s`, equal to the identity on `s`. -/\ntheorem exists_lipschitz_retraction_of_isClosed {s : Set (\u2200 n, E n)} (hs : IsClosed s)\n    (hne : s.Nonempty) :\n    \u2203 f : (\u2200 n, E n) \u2192 \u2200 n, E n, (\u2200 x \u2208 s, f x = x) \u2227 range f = s \u2227 LipschitzWith 1 f :=\n  by\n  /- The map `f` is defined as follows. For `x \u2208 s`, let `f x = x`. Otherwise, consider the longest\n    prefix `w` that `x` shares with an element of `s`, and let `f x = z_w` where `z_w` is an element\n    of `s` starting with `w`. All the desired properties are clear, except the fact that `f`\n    is `1`-Lipschitz: if two points `x, y` belong to a common cylinder of length `n`, one should show\n    that their images also belong to a common cylinder of length `n`. This is a case analysis:\n    * if both `x, y \u2208 s`, then this is clear.\n    * if `x \u2208 s` but `y \u2209 s`, then the longest prefix `w` of `y` shared by an element of `s` is of\n    length at least `n` (because of `x`), and then `f y` starts with `w` and therefore stays in the\n    same length `n` cylinder.\n    * if `x \u2209 s`, `y \u2209 s`, let `w` be the longest prefix of `x` shared by an element of `s`. If its\n    length is `< n`, then it is also the longest prefix of `y`, and we get `f x = f y = z_w`.\n    Otherwise, `f x` remains in the same `n`-cylinder as `x`. Similarly for `y`. Finally, `f x` and\n    `f y` are again in the same `n`-cylinder, as desired. -/\n  set f := fun x => if x \u2208 s then x else (inter_cylinder_longest_prefix_nonempty hs hne x).some with\n    hf\n  have fs : \u2200 x \u2208 s, f x = x := fun x xs => by simp [xs]\n  refine' \u27e8f, fs, _, _\u27e9\n  -- check that the range of `f` is `s`.\n  \u00b7 apply subset.antisymm\n    \u00b7 rintro x \u27e8y, rfl\u27e9\n      by_cases hy : y \u2208 s\n      \u00b7 rwa [fs y hy]\n      simpa [hf, if_neg hy] using (inter_cylinder_longest_prefix_nonempty hs hne y).choose_spec.1\n    \u00b7 intro x hx\n      rw [\u2190 fs x hx]\n      exact mem_range_self _\n  -- check that `f` is `1`-Lipschitz, by a case analysis.\n  \u00b7 apply LipschitzWith.mk_one fun x y => _\n    -- exclude the trivial cases where `x = y`, or `f x = f y`.\n    rcases eq_or_ne x y with (rfl | hxy)\n    \u00b7 simp\n    rcases eq_or_ne (f x) (f y) with (h' | hfxfy)\n    \u00b7 simp [h', dist_nonneg]\n    have I2 : cylinder x (first_diff x y) = cylinder y (first_diff x y) :=\n      by\n      rw [\u2190 mem_cylinder_iff_eq]\n      apply mem_cylinder_first_diff\n    suffices first_diff x y \u2264 first_diff (f x) (f y) by\n      simpa [dist_eq_of_ne hxy, dist_eq_of_ne hfxfy]\n    -- case where `x \u2208 s`\n    by_cases xs : x \u2208 s\n    \u00b7 rw [fs x xs] at hfxfy\u22a2\n      -- case where `y \u2208 s`, trivial\n      by_cases ys : y \u2208 s\n      \u00b7 rw [fs y ys]\n      -- case where `y \u2209 s`\n      have A : (s \u2229 cylinder y (longest_prefix y s)).Nonempty :=\n        inter_cylinder_longest_prefix_nonempty hs hne y\n      have fy : f y = A.some := by simp_rw [hf, if_neg ys]\n      have I : cylinder A.some (first_diff x y) = cylinder y (first_diff x y) :=\n        by\n        rw [\u2190 mem_cylinder_iff_eq, first_diff_comm]\n        apply cylinder_anti y _ A.some_spec.2\n        exact first_diff_le_longest_prefix hs ys xs\n      rwa [\u2190 fy, \u2190 I2, \u2190 mem_cylinder_iff_eq, mem_cylinder_iff_le_first_diff hfxfy.symm,\n        first_diff_comm _ x] at I\n    -- case where `x \u2209 s`\n    \u00b7 by_cases ys : y \u2208 s\n      -- case where `y \u2208 s` (similar to the above)\n      \u00b7 have A : (s \u2229 cylinder x (longest_prefix x s)).Nonempty :=\n          inter_cylinder_longest_prefix_nonempty hs hne x\n        have fx : f x = A.some := by simp_rw [hf, if_neg xs]\n        have I : cylinder A.some (first_diff x y) = cylinder x (first_diff x y) :=\n          by\n          rw [\u2190 mem_cylinder_iff_eq]\n          apply cylinder_anti x _ A.some_spec.2\n          apply first_diff_le_longest_prefix hs xs ys\n        rw [fs y ys] at hfxfy\u22a2\n        rwa [\u2190 fx, I2, \u2190 mem_cylinder_iff_eq, mem_cylinder_iff_le_first_diff hfxfy] at I\n      -- case where `y \u2209 s`\n      \u00b7 have Ax : (s \u2229 cylinder x (longest_prefix x s)).Nonempty :=\n          inter_cylinder_longest_prefix_nonempty hs hne x\n        have fx : f x = Ax.some := by simp_rw [hf, if_neg xs]\n        have Ay : (s \u2229 cylinder y (longest_prefix y s)).Nonempty :=\n          inter_cylinder_longest_prefix_nonempty hs hne y\n        have fy : f y = Ay.some := by simp_rw [hf, if_neg ys]\n        -- case where the common prefix to `x` and `s`, or `y` and `s`, is shorter than the\n        -- common part to `x` and `y` -- then `f x = f y`.\n        by_cases H : longest_prefix x s < first_diff x y \u2228 longest_prefix y s < first_diff x y\n        \u00b7 have : cylinder x (longest_prefix x s) = cylinder y (longest_prefix y s) :=\n            by\n            cases H\n            \u00b7 exact cylinder_longest_prefix_eq_of_longest_prefix_lt_first_diff hs hne H xs ys\n            \u00b7 symm\n              rw [first_diff_comm] at H\n              exact cylinder_longest_prefix_eq_of_longest_prefix_lt_first_diff hs hne H ys xs\n          rw [fx, fy] at hfxfy\n          apply (hfxfy _).elim\n          congr\n        -- case where the common prefix to `x` and `s` is long, as well as the common prefix to\n        -- `y` and `s`. Then all points remain in the same cylinders.\n        \u00b7 push_neg  at H\n          have I1 : cylinder Ax.some (first_diff x y) = cylinder x (first_diff x y) :=\n            by\n            rw [\u2190 mem_cylinder_iff_eq]\n            exact cylinder_anti x H.1 Ax.some_spec.2\n          have I3 : cylinder y (first_diff x y) = cylinder Ay.some (first_diff x y) :=\n            by\n            rw [eq_comm, \u2190 mem_cylinder_iff_eq]\n            exact cylinder_anti y H.2 Ay.some_spec.2\n          have : cylinder Ax.some (first_diff x y) = cylinder Ay.some (first_diff x y) := by\n            rw [I1, I2, I3]\n          rw [\u2190 fx, \u2190 fy, \u2190 mem_cylinder_iff_eq, mem_cylinder_iff_le_first_diff hfxfy] at this\n          exact this\n#align pi_nat.exists_lipschitz_retraction_of_is_closed PiNat.exists_lipschitz_retraction_of_isClosed\n\n/-- Given a closed nonempty subset `s` of `\u03a0 (n : \u2115), E n`, there exists a retraction onto this\nset, i.e., a continuous map with range equal to `s`, equal to the identity on `s`. -/\ntheorem exists_retraction_of_isClosed {s : Set (\u2200 n, E n)} (hs : IsClosed s) (hne : s.Nonempty) :\n    \u2203 f : (\u2200 n, E n) \u2192 \u2200 n, E n, (\u2200 x \u2208 s, f x = x) \u2227 range f = s \u2227 Continuous f :=\n  by\n  rcases exists_lipschitz_retraction_of_is_closed hs hne with \u27e8f, fs, frange, hf\u27e9\n  exact \u27e8f, fs, frange, hf.continuous\u27e9\n#align pi_nat.exists_retraction_of_is_closed PiNat.exists_retraction_of_isClosed\n\ntheorem exists_retraction_subtype_of_isClosed {s : Set (\u2200 n, E n)} (hs : IsClosed s)\n    (hne : s.Nonempty) : \u2203 f : (\u2200 n, E n) \u2192 s, (\u2200 x : s, f x = x) \u2227 Surjective f \u2227 Continuous f :=\n  by\n  obtain \u27e8f, fs, f_range, f_cont\u27e9 :\n    \u2203 f : (\u2200 n, E n) \u2192 \u2200 n, E n, (\u2200 x \u2208 s, f x = x) \u2227 range f = s \u2227 Continuous f :=\n    exists_retraction_of_is_closed hs hne\n  have A : \u2200 x, f x \u2208 s := by simp [\u2190 f_range]\n  have B : \u2200 x : s, cod_restrict f s A x = x :=\n    by\n    intro x\n    apply subtype.coe_injective.eq_iff.1\n    simpa only using fs x.val x.property\n  exact \u27e8cod_restrict f s A, B, fun x => \u27e8x, B x\u27e9, f_cont.subtype_mk _\u27e9\n#align pi_nat.exists_retraction_subtype_of_is_closed PiNat.exists_retraction_subtype_of_isClosed\n\nend PiNat\n\nopen PiNat\n\n/-- Any nonempty complete second countable metric space is the continuous image of the\nfundamental space `\u2115 \u2192 \u2115`. For a version of this theorem in the context of Polish spaces, see\n`exists_nat_nat_continuous_surjective_of_polish_space`. -/\ntheorem exists_nat_nat_continuous_surjective_of_completeSpace (\u03b1 : Type _) [MetricSpace \u03b1]\n    [CompleteSpace \u03b1] [SecondCountableTopology \u03b1] [Nonempty \u03b1] :\n    \u2203 f : (\u2115 \u2192 \u2115) \u2192 \u03b1, Continuous f \u2227 Surjective f :=\n  by\n  /- First, we define a surjective map from a closed subset `s` of `\u2115 \u2192 \u2115`. Then, we compose\n    this map with a retraction of `\u2115 \u2192 \u2115` onto `s` to obtain the desired map.\n    Let us consider a dense sequence `u` in `\u03b1`. Then `s` is the set of sequences `x\u2099` such that the\n    balls `closed_ball (u x\u2099) (1/2^n)` have a nonempty intersection. This set is closed, and we define\n    `f x` there to be the unique point in the intersection. This function is continuous and surjective\n    by design. -/\n  letI : MetricSpace (\u2115 \u2192 \u2115) := PiNat.metricSpaceNatNat\n  have I0 : (0 : \u211d) < 1 / 2 := by norm_num\n  have I1 : (1 / 2 : \u211d) < 1 := by norm_num\n  rcases exists_dense_seq \u03b1 with \u27e8u, hu\u27e9\n  let s : Set (\u2115 \u2192 \u2115) := { x | (\u22c2 n : \u2115, closed_ball (u (x n)) ((1 / 2) ^ n)).Nonempty }\n  let g : s \u2192 \u03b1 := fun x => x.2.some\n  have A : \u2200 (x : s) (n : \u2115), dist (g x) (u ((x : \u2115 \u2192 \u2115) n)) \u2264 (1 / 2) ^ n := fun x n =>\n    (mem_Inter.1 x.2.some_mem n : _)\n  have g_cont : Continuous g :=\n    by\n    apply continuous_iff_continuousAt.2 fun y => _\n    apply continuousAt_of_locally_lipschitz zero_lt_one 4 fun x hxy => _\n    rcases eq_or_ne x y with (rfl | hne)\n    \u00b7 simp\n    have hne' : x.1 \u2260 y.1 := subtype.coe_injective.ne hne\n    have dist' : dist x y = dist x.1 y.1 := rfl\n    let n := first_diff x.1 y.1 - 1\n    have diff_pos : 0 < first_diff x.1 y.1 :=\n      by\n      by_contra' h\n      apply apply_first_diff_ne hne'\n      rw [le_zero_iff.1 h]\n      apply apply_eq_of_dist_lt _ le_rfl\n      rw [pow_zero]\n      exact hxy\n    have hn : first_diff x.1 y.1 = n + 1 := (Nat.succ_pred_eq_of_pos diff_pos).symm\n    rw [dist', dist_eq_of_ne hne', hn]\n    have B : x.1 n = y.1 n := mem_cylinder_first_diff x.1 y.1 n (Nat.pred_lt diff_pos.ne')\n    calc\n      dist (g x) (g y) \u2264 dist (g x) (u (x.1 n)) + dist (g y) (u (x.1 n)) :=\n        dist_triangle_right _ _ _\n      _ = dist (g x) (u (x.1 n)) + dist (g y) (u (y.1 n)) := by rw [\u2190 B]\n      _ \u2264 (1 / 2) ^ n + (1 / 2) ^ n := (add_le_add (A x n) (A y n))\n      _ = 4 * (1 / 2) ^ (n + 1) := by ring\n      \n  have g_surj : surjective g := by\n    intro y\n    have : \u2200 n : \u2115, \u2203 j, y \u2208 closed_ball (u j) ((1 / 2) ^ n) :=\n      by\n      intro n\n      rcases hu.exists_dist_lt y (by simp : (0 : \u211d) < (1 / 2) ^ n) with \u27e8j, hj\u27e9\n      exact \u27e8j, hj.le\u27e9\n    choose x hx using this\n    have I : (\u22c2 n : \u2115, closed_ball (u (x n)) ((1 / 2) ^ n)).Nonempty := \u27e8y, mem_Inter.2 hx\u27e9\n    refine' \u27e8\u27e8x, I\u27e9, _\u27e9\n    refine' dist_le_zero.1 _\n    have J : \u2200 n : \u2115, dist (g \u27e8x, I\u27e9) y \u2264 (1 / 2) ^ n + (1 / 2) ^ n := fun n =>\n      calc\n        dist (g \u27e8x, I\u27e9) y \u2264 dist (g \u27e8x, I\u27e9) (u (x n)) + dist y (u (x n)) :=\n          dist_triangle_right _ _ _\n        _ \u2264 (1 / 2) ^ n + (1 / 2) ^ n := add_le_add (A \u27e8x, I\u27e9 n) (hx n)\n        \n    have L : tendsto (fun n : \u2115 => (1 / 2 : \u211d) ^ n + (1 / 2) ^ n) at_top (\ud835\udcdd (0 + 0)) :=\n      (tendsto_pow_atTop_nhds_0_of_lt_1 I0.le I1).add (tendsto_pow_atTop_nhds_0_of_lt_1 I0.le I1)\n    rw [add_zero] at L\n    exact ge_of_tendsto' L J\n  have s_closed : IsClosed s :=\n    by\n    refine' is_closed_iff_cluster_pt.mpr _\n    intro x hx\n    have L : tendsto (fun n : \u2115 => diam (closed_ball (u (x n)) ((1 / 2) ^ n))) at_top (\ud835\udcdd 0) :=\n      by\n      have : tendsto (fun n : \u2115 => (2 : \u211d) * (1 / 2) ^ n) at_top (\ud835\udcdd (2 * 0)) :=\n        (tendsto_pow_atTop_nhds_0_of_lt_1 I0.le I1).const_mul _\n      rw [MulZeroClass.mul_zero] at this\n      exact\n        squeeze_zero (fun n => diam_nonneg) (fun n => diam_closed_ball (pow_nonneg I0.le _)) this\n    refine'\n      nonempty_Inter_of_nonempty_bInter (fun n => is_closed_ball) (fun n => bounded_closed_ball) _ L\n    intro N\n    obtain \u27e8y, hxy, ys\u27e9 : \u2203 y, y \u2208 ball x ((1 / 2) ^ N) \u2229 s :=\n      clusterPt_principal_iff.1 hx _ (ball_mem_nhds x (pow_pos I0 N))\n    have E :\n      (\u22c2 (n : \u2115) (H : n \u2264 N), closed_ball (u (x n)) ((1 / 2) ^ n)) =\n        \u22c2 (n : \u2115) (H : n \u2264 N), closed_ball (u (y n)) ((1 / 2) ^ n) :=\n      by\n      congr\n      ext1 n\n      congr\n      ext1 hn\n      have : x n = y n := apply_eq_of_dist_lt (mem_ball'.1 hxy) hn\n      rw [this]\n    rw [E]\n    apply nonempty.mono _ ys\n    apply Inter_subset_Inter\u2082\n  obtain \u27e8f, -, f_surj, f_cont\u27e9 :\n    \u2203 f : (\u2115 \u2192 \u2115) \u2192 s, (\u2200 x : s, f x = x) \u2227 surjective f \u2227 Continuous f :=\n    by\n    apply exists_retraction_subtype_of_is_closed s_closed\n    simpa only [nonempty_coe_sort] using g_surj.nonempty\n  exact \u27e8g \u2218 f, g_cont.comp f_cont, g_surj.comp f_surj\u27e9\n#align exists_nat_nat_continuous_surjective_of_complete_space exists_nat_nat_continuous_surjective_of_completeSpace\n\nnamespace PiCountable\n\n/-!\n### Products of (possibly non-discrete) metric spaces\n-/\n\n\nvariable {\u03b9 : Type _} [Encodable \u03b9] {F : \u03b9 \u2192 Type _} [\u2200 i, MetricSpace (F i)]\n\nopen Encodable\n\n/-- Given a countable family of metric spaces, one may put a distance on their product `\u03a0 i, E i`.\nIt is highly non-canonical, though, and therefore not registered as a global instance.\nThe distance we use here is `dist x y = \u2211' i, min (1/2)^(encode i) (dist (x i) (y i))`. -/\nprotected def hasDist : Dist (\u2200 i, F i) :=\n  \u27e8fun x y => \u2211' i : \u03b9, min ((1 / 2) ^ encode i) (dist (x i) (y i))\u27e9\n#align pi_countable.has_dist PiCountable.hasDist\n\nattribute [local instance] PiCountable.hasDist\n\ntheorem dist_eq_tsum (x y : \u2200 i, F i) :\n    dist x y = \u2211' i : \u03b9, min ((1 / 2) ^ encode i) (dist (x i) (y i)) :=\n  rfl\n#align pi_countable.dist_eq_tsum PiCountable.dist_eq_tsum\n\ntheorem dist_summable (x y : \u2200 i, F i) :\n    Summable fun i : \u03b9 => min ((1 / 2) ^ encode i) (dist (x i) (y i)) :=\n  by\n  refine'\n    summable_of_nonneg_of_le (fun i => _) (fun i => min_le_left _ _) summable_geometric_two_encode\n  exact le_min (pow_nonneg (by norm_num) _) dist_nonneg\n#align pi_countable.dist_summable PiCountable.dist_summable\n\ntheorem min_dist_le_dist_pi (x y : \u2200 i, F i) (i : \u03b9) :\n    min ((1 / 2) ^ encode i) (dist (x i) (y i)) \u2264 dist x y :=\n  le_tsum (dist_summable x y) i fun j hj => le_min (by simp) dist_nonneg\n#align pi_countable.min_dist_le_dist_pi PiCountable.min_dist_le_dist_pi\n\ntheorem dist_le_dist_pi_of_dist_lt {x y : \u2200 i, F i} {i : \u03b9} (h : dist x y < (1 / 2) ^ encode i) :\n    dist (x i) (y i) \u2264 dist x y := by\n  simpa only [not_le.2 h, false_or_iff] using min_le_iff.1 (min_dist_le_dist_pi x y i)\n#align pi_countable.dist_le_dist_pi_of_dist_lt PiCountable.dist_le_dist_pi_of_dist_lt\n\nopen BigOperators Topology\n\nopen Filter\n\nopen NNReal\n\nvariable (E)\n\n/-- Given a countable family of metric spaces, one may put a distance on their product `\u03a0 i, E i`,\ndefining the right topology and uniform structure. It is highly non-canonical, though, and therefore\nnot registered as a global instance.\nThe distance we use here is `dist x y = \u2211' n, min (1/2)^(encode i) (dist (x n) (y n))`. -/\nprotected def metricSpace : MetricSpace (\u2200 i, F i)\n    where\n  dist_self x := by simp [dist_eq_tsum]\n  dist_comm x y := by simp [dist_eq_tsum, dist_comm]\n  dist_triangle x y z :=\n    by\n    have I :\n      \u2200 i,\n        min ((1 / 2) ^ encode i) (dist (x i) (z i)) \u2264\n          min ((1 / 2) ^ encode i) (dist (x i) (y i)) +\n            min ((1 / 2) ^ encode i) (dist (y i) (z i)) :=\n      fun i =>\n      calc\n        min ((1 / 2) ^ encode i) (dist (x i) (z i)) \u2264\n            min ((1 / 2) ^ encode i) (dist (x i) (y i) + dist (y i) (z i)) :=\n          min_le_min le_rfl (dist_triangle _ _ _)\n        _ =\n            min ((1 / 2) ^ encode i)\n              (min ((1 / 2) ^ encode i) (dist (x i) (y i)) +\n                min ((1 / 2) ^ encode i) (dist (y i) (z i))) :=\n          by\n          convert congr_arg (coe : \u211d\u22650 \u2192 \u211d)\n                (min_add_distrib ((1 / 2 : \u211d\u22650) ^ encode i) (nndist (x i) (y i))\n                  (nndist (y i) (z i))) <;>\n            simp\n        _ \u2264\n            min ((1 / 2) ^ encode i) (dist (x i) (y i)) +\n              min ((1 / 2) ^ encode i) (dist (y i) (z i)) :=\n          min_le_right _ _\n        \n    calc\n      dist x z \u2264\n          \u2211' i,\n            min ((1 / 2) ^ encode i) (dist (x i) (y i)) +\n              min ((1 / 2) ^ encode i) (dist (y i) (z i)) :=\n        tsum_le_tsum I (dist_summable x z) ((dist_summable x y).add (dist_summable y z))\n      _ = dist x y + dist y z := tsum_add (dist_summable x y) (dist_summable y z)\n      \n  eq_of_dist_eq_zero := by\n    intro x y hxy\n    ext1 n\n    rw [\u2190 dist_le_zero, \u2190 hxy]\n    apply dist_le_dist_pi_of_dist_lt\n    rw [hxy]\n    simp\n  toUniformSpace := Pi.uniformSpace _\n  uniformity_dist := by\n    have I0 : (0 : \u211d) \u2264 1 / 2 := by norm_num\n    have I1 : (1 / 2 : \u211d) < 1 := by norm_num\n    simp only [Pi.uniformity, comap_infi, gt_iff_lt, preimage_set_of_eq, comap_principal,\n      PseudoMetricSpace.uniformity_dist]\n    apply le_antisymm\n    \u00b7 simp only [le_inf\u1d62_iff, le_principal_iff]\n      intro \u03b5 \u03b5pos\n      obtain \u27e8K, hK\u27e9 :\n        \u2203 K : Finset \u03b9, (\u2211' i : { j // j \u2209 K }, (1 / 2 : \u211d) ^ encode (i : \u03b9)) < \u03b5 / 2 :=\n        ((tendsto_order.1 (tendsto_tsum_compl_atTop_zero fun i : \u03b9 => (1 / 2 : \u211d) ^ encode i)).2 _\n            (half_pos \u03b5pos)).exists\n      obtain \u27e8\u03b4, \u03b4pos, h\u03b4\u27e9 : \u2203 (\u03b4 : \u211d)(\u03b4pos : 0 < \u03b4), (K.card : \u211d) * \u03b4 \u2264 \u03b5 / 2 :=\n        by\n        rcases Nat.eq_zero_or_pos K.card with (hK | hK)\n        \u00b7\n          exact\n            \u27e81, zero_lt_one, by\n              simpa only [hK, Nat.cast_zero, MulZeroClass.zero_mul] using (half_pos \u03b5pos).le\u27e9\n        \u00b7 have Kpos : 0 < (K.card : \u211d) := Nat.cast_pos.2 hK\n          refine' \u27e8\u03b5 / 2 / (K.card : \u211d), div_pos (half_pos \u03b5pos) Kpos, le_of_eq _\u27e9\n          field_simp [Kpos.ne']\n          ring\n      apply\n        @mem_infi_of_Inter _ _ _ _ _ K.finite_to_set fun i =>\n          { p : (\u2200 i : \u03b9, F i) \u00d7 \u2200 i : \u03b9, F i | dist (p.fst i) (p.snd i) < \u03b4 }\n      \u00b7 rintro \u27e8i, hi\u27e9\n        refine' mem_infi_of_mem \u03b4 (mem_infi_of_mem \u03b4pos _)\n        simp only [Prod.forall, imp_self, mem_principal]\n      \u00b7 rintro \u27e8x, y\u27e9 hxy\n        simp only [mem_Inter, mem_set_of_eq, SetCoe.forall, Finset.mem_range, Finset.mem_coe] at hxy\n        calc\n          dist x y = \u2211' i : \u03b9, min ((1 / 2) ^ encode i) (dist (x i) (y i)) := rfl\n          _ =\n              (\u2211 i in K, min ((1 / 2) ^ encode i) (dist (x i) (y i))) +\n                \u2211' i : (\u2191K : Set \u03b9)\u1d9c, min ((1 / 2) ^ encode (i : \u03b9)) (dist (x i) (y i)) :=\n            (sum_add_tsum_compl (dist_summable _ _)).symm\n          _ \u2264 (\u2211 i in K, dist (x i) (y i)) + \u2211' i : (\u2191K : Set \u03b9)\u1d9c, (1 / 2) ^ encode (i : \u03b9) :=\n            by\n            refine' add_le_add (Finset.sum_le_sum fun i hi => min_le_right _ _) _\n            refine' tsum_le_tsum (fun i => min_le_left _ _) _ _\n            \u00b7 apply Summable.subtype (dist_summable x y) ((\u2191K : Set \u03b9)\u1d9c)\n            \u00b7 apply Summable.subtype summable_geometric_two_encode ((\u2191K : Set \u03b9)\u1d9c)\n          _ < (\u2211 i in K, \u03b4) + \u03b5 / 2 :=\n            by\n            apply add_lt_add_of_le_of_lt _ hK\n            apply Finset.sum_le_sum fun i hi => _\n            apply (hxy i _).le\n            simpa using hi\n          _ \u2264 \u03b5 / 2 + \u03b5 / 2 :=\n            (add_le_add_right (by simpa only [Finset.sum_const, nsmul_eq_mul] using h\u03b4) _)\n          _ = \u03b5 := add_halves _\n          \n    \u00b7 simp only [le_inf\u1d62_iff, le_principal_iff]\n      intro i \u03b5 \u03b5pos\n      refine' mem_infi_of_mem (min ((1 / 2) ^ encode i) \u03b5) _\n      have : 0 < min ((1 / 2) ^ encode i) \u03b5 := lt_min (by simp) \u03b5pos\n      refine' mem_infi_of_mem this _\n      simp only [and_imp, Prod.forall, set_of_subset_set_of, lt_min_iff, mem_principal]\n      intro x y hn h\u03b5\n      calc\n        dist (x i) (y i) \u2264 dist x y := dist_le_dist_pi_of_dist_lt hn\n        _ < \u03b5 := h\u03b5\n        \n#align pi_countable.metric_space PiCountable.metricSpace\n\nend PiCountable\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/MetricSpace/PiNat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8080672181749421, "lm_q1q2_score": 0.7063131598897193}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_184\n  (a b : nnreal)\n  (h\u2080 : 0 < a \u2227 0 < b)\n  (h\u2081 : (a^2) = 6*b)\n  (h\u2082 : (a^2) = 54/b) :\n  a = 3 * nnreal.sqrt 2 :=\nbegin\n  have key\u2081 : b \u2260 0 := ne_of_gt h\u2080.2,\n  have h\u2084 : 0 \u2264 a, { exact zero_le _ },\n\n  suffices : a^2=18,\n  {\n    rw eq_comm,\n    have h\u2085 : 3 * nnreal.sqrt 2 = nnreal.sqrt 18,\n    {\n      calc 3 * nnreal.sqrt 2 = (nnreal.sqrt 9) * (nnreal.sqrt 2) : by {rw eq_comm, simp, rw nnreal.sqrt_eq_iff_sq_eq, ring}\n                          ...= nnreal.sqrt (9 * 2): by {rw \u2190 nnreal.sqrt_mul}\n                          ...= nnreal.sqrt 18: by{ring_nf},\n    },\n    rw [h\u2085, nnreal.sqrt_eq_iff_sq_eq],\n    rw \u2190 this,\n    ring,\n  },\n\n  have key\u2082 : (6 * b * b) = 54,\n  {\n    rw h\u2081 at h\u2082,\n    exact (eq_div_iff key\u2081).mp h\u2082,\n  },\n\n  have key\u2083 : b = 3,\n  {\n    have key\u2085 : (6 : nnreal) \u2260 0,\n    {\n      refine nnreal.ne_iff.mp _,\n      norm_num,\n    },\n    calc b = nnreal.sqrt (b * b) : by { rw eq_comm, apply nnreal.sqrt_mul_self}\n          ... = nnreal.sqrt ((6*b*b)/6) : by {refine congr_arg \u21d1nnreal.sqrt _, ring_nf, refine (eq_div_iff _).mpr _,\n          {exact key\u2085},\n          rw mul_comm,\n          }\n          ... = nnreal.sqrt (54/6): by {rw key\u2082}\n          ... = nnreal.sqrt(9) : by {refine congr_arg \u21d1nnreal.sqrt _, refine (div_eq_iff key\u2085).mpr _, ring,}\n          ... = 3 : by {rw nnreal.sqrt_eq_iff_sq_eq, ring},\n  },\n  rw key\u2083 at h\u2081,\n  rw h\u2081,\n  ring,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p184.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7063131550906565}}
{"text": "/-\nCopyright (c) 2022 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport computability.encoding\nimport model_theory.syntax\nimport set_theory.cardinal.ordinal\n\n/-! # Encodings and Cardinality of First-Order Syntax\n\n## Main Definitions\n* `first_order.language.term.encoding` encodes terms as lists.\n* `first_order.language.bounded_formula.encoding` encodes bounded formulas as lists.\n\n## Main Results\n* `first_order.language.term.card_le` shows that the number of terms in `L.term \u03b1` is at most\n`max \u2135\u2080 # (\u03b1 \u2295 \u03a3 i, L.functions i)`.\n* `first_order.language.bounded_formula.card_le` shows that the number of bounded formulas in\n`\u03a3 n, L.bounded_formula \u03b1 n` is at most\n`max \u2135\u2080 (cardinal.lift.{max u v} (#\u03b1) + cardinal.lift.{u'} L.card)`.\n\n## TODO\n* `primcodable` instances for terms and formulas, based on the `encoding`s\n* Computability facts about term and formula operations, to set up a computability approach to\nincompleteness\n\n-/\n\nuniverses u v w u' v'\n\nnamespace first_order\nnamespace language\n\nvariables {L : language.{u v}}\nvariables {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]\nvariables {\u03b1 : Type u'} {\u03b2 : Type v'}\nopen_locale first_order cardinal\nopen computability list Structure cardinal fin\n\nnamespace term\n\n/-- Encodes a term as a list of variables and function symbols. -/\ndef list_encode : L.term \u03b1 \u2192 list (\u03b1 \u2295 \u03a3 i, L.functions i)\n| (var i) := [sum.inl i]\n| (func f ts) := ((sum.inr (\u27e8_, f\u27e9 : \u03a3 i, L.functions i)) ::\n    ((list.fin_range _).bind (\u03bb i, (ts i).list_encode)))\n\n/-- Decodes a list of variables and function symbols as a list of terms. -/\ndef list_decode :\n  list (\u03b1 \u2295 \u03a3 i, L.functions i) \u2192 list (option (L.term \u03b1))\n| [] := []\n| ((sum.inl a) :: l) := some (var a) :: list_decode l\n| ((sum.inr \u27e8n, f\u27e9) :: l) :=\n  if h : \u2200 (i : fin n), ((list_decode l).nth i).join.is_some\n  then func f (\u03bb i, option.get (h i)) :: ((list_decode l).drop n)\n  else [none]\n\ntheorem list_decode_encode_list (l : list (L.term \u03b1)) :\n  list_decode (l.bind list_encode) = l.map option.some :=\nbegin\n  suffices h : \u2200 (t : L.term \u03b1) (l : list (\u03b1 \u2295 \u03a3 i, L.functions i)),\n    list_decode (t.list_encode ++ l) = some t :: list_decode l,\n  { induction l with t l lih,\n    { refl },\n    { rw [cons_bind, h t (l.bind list_encode), lih, list.map] } },\n  { intro t,\n    induction t with a n f ts ih; intro l,\n    { rw [list_encode, singleton_append, list_decode] },\n    { rw [list_encode, cons_append, list_decode],\n      have h : list_decode ((fin_range n).bind (\u03bb (i : fin n), (ts i).list_encode) ++ l) =\n        (fin_range n).map (option.some \u2218 ts) ++ list_decode l,\n      { induction (fin_range n) with i l' l'ih,\n        { refl },\n        { rw [cons_bind, append_assoc, ih, map_cons, l'ih, cons_append] } },\n      have h' : \u2200 i, (list_decode ((fin_range n).bind (\u03bb (i : fin n), (ts i).list_encode) ++ l)).nth\n        \u2191i = some (some (ts i)),\n      { intro i,\n        rw [h, nth_append, nth_map],\n        { simp only [option.map_eq_some', function.comp_app, nth_eq_some],\n          refine \u27e8i, \u27e8lt_of_lt_of_le i.2 (ge_of_eq (length_fin_range _)), _\u27e9, rfl\u27e9,\n          rw [nth_le_fin_range, fin.eta] },\n        { refine lt_of_lt_of_le i.2 _,\n          simp } },\n      refine (dif_pos (\u03bb i, option.is_some_iff_exists.2 \u27e8ts i, _\u27e9)).trans _,\n      { rw [option.join_eq_some, h'] },\n      refine congr (congr rfl (congr rfl (congr rfl (funext (\u03bb i, option.get_of_mem _ _))))) _,\n      { simp [h'] },\n      { rw [h, drop_left'],\n        rw [length_map, length_fin_range] } } }\nend\n\n/-- An encoding of terms as lists. -/\n@[simps] protected def encoding : encoding (L.term \u03b1) :=\n{ \u0393 := \u03b1 \u2295 \u03a3 i, L.functions i,\n  encode := list_encode,\n  decode := \u03bb l, (list_decode l).head'.join,\n  decode_encode := \u03bb t, begin\n    have h := list_decode_encode_list [t],\n    rw [bind_singleton] at h,\n    simp only [h, option.join, head', list.map, option.some_bind, id.def],\n  end }\n\nlemma list_encode_injective :\n  function.injective (list_encode : L.term \u03b1 \u2192 list (\u03b1 \u2295 \u03a3 i, L.functions i)) :=\nterm.encoding.encode_injective\n\ntheorem card_le : # (L.term \u03b1) \u2264 max \u2135\u2080 (# (\u03b1 \u2295 \u03a3 i, L.functions i)) :=\nlift_le.1 (trans term.encoding.card_le_card_list (lift_le.2 (mk_list_le_max _)))\n\ntheorem card_sigma : # (\u03a3 n, (L.term (\u03b1 \u2295 fin n))) = max \u2135\u2080 (# (\u03b1 \u2295 \u03a3 i, L.functions i)) :=\nbegin\n  refine le_antisymm _ _,\n  { rw mk_sigma,\n    refine (sum_le_supr_lift _).trans _,\n    rw [mk_nat, lift_aleph_0, mul_eq_max_of_aleph_0_le_left le_rfl, max_le_iff,\n      csupr_le_iff' (bdd_above_range _)],\n    { refine \u27e8le_max_left _ _, \u03bb i, card_le.trans _\u27e9,\n      rw max_le_iff,\n      refine \u27e8le_max_left _ _, _\u27e9,\n      rw [\u2190 add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (cardinal.lift (#\u03b1)), lift_add,\n        add_assoc, lift_lift, lift_lift],\n      refine add_le_add_right _ _,\n      rw [lift_le_aleph_0, \u2190 encodable_iff],\n      exact \u27e8infer_instance\u27e9 },\n    { rw [\u2190 one_le_iff_ne_zero],\n      refine trans _ (le_csupr (bdd_above_range _) 1),\n      rw [one_le_iff_ne_zero, mk_ne_zero_iff],\n      exact \u27e8var (sum.inr 0)\u27e9 } },\n  { rw [max_le_iff, \u2190 infinite_iff],\n    refine \u27e8infinite.of_injective (\u03bb i, \u27e8i + 1, var (sum.inr i)\u27e9) (\u03bb i j ij, _), _\u27e9,\n    { cases ij,\n      refl },\n    { rw [cardinal.le_def],\n      refine \u27e8\u27e8sum.elim (\u03bb i, \u27e80, var (sum.inl i)\u27e9)\n        (\u03bb F, \u27e81, func F.2 (\u03bb _, var (sum.inr 0))\u27e9), _\u27e9\u27e9,\n      { rintros (a | a) (b | b) h,\n        { simp only [sum.elim_inl, eq_self_iff_true, heq_iff_eq, true_and] at h,\n          rw h },\n        { simp only [sum.elim_inl, sum.elim_inr, nat.zero_ne_one, false_and] at h,\n          exact h.elim },\n        { simp only [sum.elim_inr, sum.elim_inl, nat.one_ne_zero, false_and] at h,\n          exact h.elim },\n        { simp only [sum.elim_inr, eq_self_iff_true, heq_iff_eq, true_and] at h,\n          rw sigma.ext_iff.2 \u27e8h.1, h.2.1\u27e9, } } } }\nend\n\ninstance [encodable \u03b1] [encodable ((\u03a3 i, L.functions i))] :\n  encodable (L.term \u03b1) :=\nencodable.of_left_injection list_encode (\u03bb l, (list_decode l).head'.join)\n  (\u03bb t, begin\n    rw [\u2190 bind_singleton list_encode, list_decode_encode_list],\n    simp only [option.join, head', list.map, option.some_bind, id.def],\n  end)\n\nlemma card_le_aleph_0 [h1 : nonempty (encodable \u03b1)] [h2 : L.countable_functions] :\n  # (L.term \u03b1) \u2264 \u2135\u2080 :=\nbegin\n  refine (card_le.trans _),\n  rw [max_le_iff],\n  simp only [le_refl, mk_sum, add_le_aleph_0, lift_le_aleph_0, true_and],\n  exact \u27e8encodable_iff.1 h1, L.card_functions_le_aleph_0\u27e9,\nend\n\ninstance small [small.{u} \u03b1] :\n  small.{u} (L.term \u03b1) :=\nsmall_of_injective list_encode_injective\n\nend term\n\nnamespace bounded_formula\n\n/-- Encodes a bounded formula as a list of symbols. -/\ndef list_encode : \u2200 {n : \u2115}, L.bounded_formula \u03b1 n \u2192\n  list ((\u03a3 k, L.term (\u03b1 \u2295 fin k)) \u2295 (\u03a3 n, L.relations n) \u2295 \u2115)\n| n falsum := [sum.inr (sum.inr (n + 2))]\n| n (equal t\u2081 t\u2082) := [sum.inl \u27e8_, t\u2081\u27e9, sum.inl \u27e8_, t\u2082\u27e9]\n| n (rel R ts) := [sum.inr (sum.inl \u27e8_, R\u27e9), sum.inr (sum.inr n)] ++\n  ((list.fin_range _).map (\u03bb i, sum.inl \u27e8n, (ts i)\u27e9))\n| n (imp \u03c6\u2081 \u03c6\u2082) := (sum.inr (sum.inr 0)) :: \u03c6\u2081.list_encode ++ \u03c6\u2082.list_encode\n| n (all \u03c6) := (sum.inr (sum.inr 1)) :: \u03c6.list_encode\n\n/-- Applies the `forall` quantifier to an element of `(\u03a3 n, L.bounded_formula \u03b1 n)`,\nor returns `default` if not possible. -/\ndef sigma_all : (\u03a3 n, L.bounded_formula \u03b1 n) \u2192 \u03a3 n, L.bounded_formula \u03b1 n\n| \u27e8(n + 1), \u03c6\u27e9 := \u27e8n, \u03c6.all\u27e9\n| _ := default\n\n/-- Applies `imp` to two elements of `(\u03a3 n, L.bounded_formula \u03b1 n)`,\nor returns `default` if not possible. -/\ndef sigma_imp :\n  (\u03a3 n, L.bounded_formula \u03b1 n) \u2192 (\u03a3 n, L.bounded_formula \u03b1 n) \u2192 (\u03a3 n, L.bounded_formula \u03b1 n)\n| \u27e8m, \u03c6\u27e9 \u27e8n, \u03c8\u27e9 := if h : m = n then \u27e8m, \u03c6.imp (eq.mp (by rw h) \u03c8)\u27e9 else default\n\n/-- Decodes a list of symbols as a list of formulas. -/\n@[simp] def list_decode :\n  \u03a0 (l : list ((\u03a3 k, L.term (\u03b1 \u2295 fin k)) \u2295 (\u03a3 n, L.relations n) \u2295 \u2115)),\n    (\u03a3 n, L.bounded_formula \u03b1 n) \u00d7\n    { l' : list ((\u03a3 k, L.term (\u03b1 \u2295 fin k)) \u2295 (\u03a3 n, L.relations n) \u2295 \u2115)\n    // l'.sizeof \u2264 max 1 l.sizeof }\n| ((sum.inr (sum.inr (n + 2))) :: l) := \u27e8\u27e8n, falsum\u27e9, l, le_max_of_le_right le_add_self\u27e9\n| ((sum.inl \u27e8n\u2081, t\u2081\u27e9) :: sum.inl \u27e8n\u2082, t\u2082\u27e9 :: l) :=\n    \u27e8if h : n\u2081 = n\u2082 then \u27e8n\u2081, equal t\u2081 (eq.mp (by rw h) t\u2082)\u27e9 else default, l, begin\n      simp only [list.sizeof, \u2190 add_assoc],\n      exact le_max_of_le_right le_add_self,\n    end\u27e9\n| (sum.inr (sum.inl \u27e8n, R\u27e9) :: (sum.inr (sum.inr k)) :: l) := \u27e8\n    if h : \u2200 (i : fin n), ((l.map sum.get_left).nth i).join.is_some\n    then if h' : \u2200 i, (option.get (h i)).1 = k\n      then \u27e8k, bounded_formula.rel R (\u03bb i, eq.mp (by rw h' i) (option.get (h i)).2)\u27e9\n      else default\n    else default,\n    l.drop n, le_max_of_le_right (le_add_left (le_add_left (list.drop_sizeof_le _ _)))\u27e9\n| ((sum.inr (sum.inr 0)) :: l) :=\n  have (\u2191((list_decode l).2) : list ((\u03a3 k, L.term (\u03b1 \u2295 fin k)) \u2295 (\u03a3 n, L.relations n) \u2295 \u2115)).sizeof\n    < 1 + (1 + 1) + l.sizeof, from begin\n      refine lt_of_le_of_lt (list_decode l).2.2 (max_lt _ (nat.lt_add_of_pos_left dec_trivial)),\n      rw [add_assoc, add_comm, nat.lt_succ_iff, add_assoc],\n      exact le_self_add,\n    end,\n  \u27e8sigma_imp (list_decode l).1 (list_decode (list_decode l).2).1,\n    (list_decode (list_decode l).2).2, le_max_of_le_right (trans (list_decode _).2.2 (max_le\n      (le_add_right le_self_add) (trans (list_decode _).2.2\n      (max_le (le_add_right le_self_add) le_add_self))))\u27e9\n| ((sum.inr (sum.inr 1)) :: l) := \u27e8sigma_all (list_decode l).1, (list_decode l).2,\n  (list_decode l).2.2.trans (max_le_max le_rfl le_add_self)\u27e9\n| _ := \u27e8default, [], le_max_left _ _\u27e9\n\n@[simp] theorem list_decode_encode_list (l : list (\u03a3 n, L.bounded_formula \u03b1 n)) :\n  (list_decode (l.bind (\u03bb \u03c6, \u03c6.2.list_encode))).1 = l.head :=\nbegin\n  suffices h : \u2200 (\u03c6 : (\u03a3 n, L.bounded_formula \u03b1 n)) l,\n    (list_decode (list_encode \u03c6.2 ++ l)).1 = \u03c6 \u2227 (list_decode (list_encode \u03c6.2 ++ l)).2.1 = l,\n  { induction l with \u03c6 l lih,\n    { rw [list.nil_bind],\n      simp [list_decode], },\n    { rw [cons_bind, (h \u03c6 _).1, head_cons] } },\n  { rintro \u27e8n, \u03c6\u27e9,\n    induction \u03c6 with _ _ _ _ _ _ _ ts _ _ _ ih1 ih2 _ _ ih; intro l,\n    { rw [list_encode, singleton_append, list_decode],\n      simp only [eq_self_iff_true, heq_iff_eq, and_self], },\n    { rw [list_encode, cons_append, cons_append, list_decode, dif_pos],\n      { simp only [eq_mp_eq_cast, cast_eq, eq_self_iff_true, heq_iff_eq, and_self, nil_append], },\n      { simp only [eq_self_iff_true, heq_iff_eq, and_self], } },\n    { rw [list_encode, cons_append, cons_append, singleton_append, cons_append, list_decode],\n      { have h : \u2200 (i : fin \u03c6_l), ((list.map sum.get_left (list.map (\u03bb (i : fin \u03c6_l),\n          sum.inl (\u27e8(\u27e8\u03c6_n, rel \u03c6_R ts\u27e9 : \u03a3 n, L.bounded_formula \u03b1 n).fst, ts i\u27e9 :\n            \u03a3 n, L.term (\u03b1 \u2295 fin n))) (fin_range \u03c6_l) ++ l)).nth \u2191i).join = some \u27e8_, ts i\u27e9,\n        { intro i,\n          simp only [option.join, map_append, map_map, option.bind_eq_some, id.def, exists_eq_right,\n            nth_eq_some, length_append, length_map, length_fin_range],\n          refine \u27e8lt_of_lt_of_le i.2 le_self_add, _\u27e9,\n          rw [nth_le_append, nth_le_map],\n          { simp only [sum.get_left, nth_le_fin_range, fin.eta, function.comp_app, eq_self_iff_true,\n            heq_iff_eq, and_self] },\n          { exact lt_of_lt_of_le i.is_lt (ge_of_eq (length_fin_range _)) },\n          { rw [length_map, length_fin_range],\n            exact i.2 } },\n        rw dif_pos, swap,\n        { exact \u03bb i, option.is_some_iff_exists.2 \u27e8\u27e8_, ts i\u27e9, h i\u27e9 },\n        rw dif_pos, swap,\n        { intro i,\n          obtain \u27e8h1, h2\u27e9 := option.eq_some_iff_get_eq.1 (h i),\n          rw h2 },\n        simp only [eq_self_iff_true, heq_iff_eq, true_and],\n        refine \u27e8funext (\u03bb i, _), _\u27e9,\n        { obtain \u27e8h1, h2\u27e9 := option.eq_some_iff_get_eq.1 (h i),\n          rw [eq_mp_eq_cast, cast_eq_iff_heq],\n          exact (sigma.ext_iff.1 ((sigma.eta (option.get h1)).trans h2)).2 },\n        rw [list.drop_append_eq_append_drop, length_map, length_fin_range, nat.sub_self, drop,\n          drop_eq_nil_of_le, nil_append],\n        rw [length_map, length_fin_range], }, },\n    { rw [list_encode, append_assoc, cons_append, list_decode],\n      simp only [subtype.val_eq_coe] at *,\n      rw [(ih1 _).1, (ih1 _).2, (ih2 _).1, (ih2 _).2, sigma_imp, dif_pos rfl],\n      exact \u27e8rfl, rfl\u27e9, },\n    { rw [list_encode, cons_append, list_decode],\n      simp only,\n      simp only [subtype.val_eq_coe] at *,\n      rw [(ih _).1, (ih _).2, sigma_all],\n      exact \u27e8rfl, rfl\u27e9 } }\nend\n\n/-- An encoding of bounded formulas as lists. -/\n@[simps] protected def encoding : encoding (\u03a3 n, L.bounded_formula \u03b1 n) :=\n{ \u0393 := (\u03a3 k, L.term (\u03b1 \u2295 fin k)) \u2295 (\u03a3 n, L.relations n) \u2295 \u2115,\n  encode := \u03bb \u03c6, \u03c6.2.list_encode,\n  decode := \u03bb l, (list_decode l).1,\n  decode_encode := \u03bb \u03c6, begin\n    have h := list_decode_encode_list [\u03c6],\n    rw [bind_singleton] at h,\n    rw h,\n    refl,\n  end }\n\nlemma list_encode_sigma_injective :\n  function.injective (\u03bb (\u03c6 : \u03a3 n, L.bounded_formula \u03b1 n), \u03c6.2.list_encode) :=\nbounded_formula.encoding.encode_injective\n\ntheorem card_le : # (\u03a3 n, L.bounded_formula \u03b1 n) \u2264\n  max \u2135\u2080 (cardinal.lift.{max u v} (#\u03b1) + cardinal.lift.{u'} L.card) :=\nbegin\n  refine lift_le.1 ((bounded_formula.encoding.card_le_card_list).trans _),\n  rw [encoding_\u0393, mk_list_eq_max_mk_aleph_0, lift_max, lift_aleph_0, lift_max, lift_aleph_0,\n    max_le_iff],\n  refine \u27e8_, le_max_left _ _\u27e9,\n  rw [mk_sum, term.card_sigma, mk_sum, \u2190 add_eq_max le_rfl, mk_sum, mk_nat],\n  simp only [lift_add, lift_lift, lift_aleph_0],\n  rw [\u2190 add_assoc, add_comm, \u2190 add_assoc, \u2190 add_assoc, aleph_0_add_aleph_0, add_assoc,\n    add_eq_max le_rfl, add_assoc, card, symbols, mk_sum, lift_add, lift_lift, lift_lift],\nend\n\nend bounded_formula\n\nend language\nend first_order\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/model_theory/encoding.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.706268576445161}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\n! This file was ported from Lean 3 source module number_theory.zsqrtd.to_real\n! leanprover-community/mathlib commit 97eab48559068f3d6313da387714ef25768fb730\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Real.Sqrt\nimport Mathbin.NumberTheory.Zsqrtd.Basic\n\n/-!\n# Image of `zsqrtd` in `\u211d`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines `zsqrtd.to_real` and related lemmas.\nIt is in a separate file to avoid pulling in all of `data.real` into `data.zsqrtd`.\n-/\n\n\nnamespace Zsqrtd\n\n#print Zsqrtd.toReal /-\n/-- The image of `zsqrtd` in `\u211d`, using `real.sqrt` which takes the positive root of `d`.\n\nIf the negative root is desired, use `to_real h a.conj`. -/\n@[simps]\nnoncomputable def toReal {d : \u2124} (h : 0 \u2264 d) : \u2124\u221ad \u2192+* \u211d :=\n  lift \u27e8Real.sqrt d, Real.mul_self_sqrt (Int.cast_nonneg.mpr h)\u27e9\n#align zsqrtd.to_real Zsqrtd.toReal\n-/\n\n/- warning: zsqrtd.to_real_injective -> Zsqrtd.toReal_injective is a dubious translation:\nlean 3 declaration is\n  forall {d : Int} (h0d : LE.le.{0} Int Int.hasLe (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) d), (forall (n : Int), Ne.{1} Int d (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) n n)) -> (Function.Injective.{1, 1} (Zsqrtd d) Real (coeFn.{1, 1} (RingHom.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.ring d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.ring))) (fun (_x : RingHom.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.ring d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.ring))) => (Zsqrtd d) -> Real) (RingHom.hasCoeToFun.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.ring d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.ring))) (Zsqrtd.toReal d h0d)))\nbut is expected to have type\n  forall {d : Int} (h0d : LE.le.{0} Int Int.instLEInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) d), (forall (n : Int), Ne.{1} Int d (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n n)) -> (Function.Injective.{1, 1} (Zsqrtd d) Real (FunLike.coe.{1, 1, 1} (RingHom.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal))) (Zsqrtd d) (fun (_x : Zsqrtd d) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : Zsqrtd d) => Real) _x) (MulHomClass.toFunLike.{0, 0, 0} (RingHom.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal))) (Zsqrtd d) Real (NonUnitalNonAssocSemiring.toMul.{0} (Zsqrtd d) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} (Zsqrtd d) (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d))))) (NonUnitalNonAssocSemiring.toMul.{0} Real (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} Real (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal)))) (NonUnitalRingHomClass.toMulHomClass.{0, 0, 0} (RingHom.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal))) (Zsqrtd d) Real (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} (Zsqrtd d) (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d)))) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{0} Real (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal))) (RingHomClass.toNonUnitalRingHomClass.{0, 0, 0} (RingHom.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal))) (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal)) (RingHom.instRingHomClassRingHom.{0, 0} (Zsqrtd d) Real (NonAssocRing.toNonAssocSemiring.{0} (Zsqrtd d) (Ring.toNonAssocRing.{0} (Zsqrtd d) (Zsqrtd.instRingZsqrtd d))) (NonAssocRing.toNonAssocSemiring.{0} Real (Ring.toNonAssocRing.{0} Real Real.instRingReal)))))) (Zsqrtd.toReal d h0d)))\nCase conversion may be inaccurate. Consider using '#align zsqrtd.to_real_injective Zsqrtd.toReal_injective\u2093'. -/\ntheorem toReal_injective {d : \u2124} (h0d : 0 \u2264 d) (hd : \u2200 n : \u2124, d \u2260 n * n) :\n    Function.Injective (toReal h0d) :=\n  lift_injective _ hd\n#align zsqrtd.to_real_injective Zsqrtd.toReal_injective\n\nend Zsqrtd\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/Zsqrtd/ToReal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7062685736811208}}
{"text": "import algebra.group\nimport linear_algebra.tensor_product\nimport tactic.ring\n\nuniverses v u\n\nsection canonical\n\nvariables (R : Type u) [comm_ring R]\nvariables (A : \u2115 \u2192 Type v) {m n : \u2115} (h : m = n)\ninclude h\n\ndef canonical_map : A m \u2192 A n := (congr_arg A h).mp\n\ninstance canonical_hom [\u2200 n, add_comm_group (A n)] : is_add_group_hom (canonical_map A h : A m \u2192 A n) :=\nbegin\n  subst h,\n  exact is_add_group_hom.id\nend\n\ndef canonical_R_hom [\u2200 n, add_comm_group (A n)] [\u2200 n, module R (A n)] : (A m) \u2192\u2097[R] (A n) :=\nbegin\n  subst h,\n  exact linear_map.id\nend\n\nend canonical\n\nstructure cdga (R : Type u) [comm_ring R] :=\n(A : \u2115 \u2192 Type v) -- universe polymorphism FTW\n[hA : \u2200 n, add_comm_group (A n)]\n[hRA : \u2200 n, module R (A n)]\n(mul : \u2200 i j , (A i) \u2192\u2097[R] (A j) \u2192\u2097[R] (A (i + j)))\n(one : A 0)\n(one_mul : \u2200 {j} (a : A j), canonical_R_hom R A (zero_add j) (mul 0 j one a) = a)\n(mul_one : \u2200 {j} (a : A j), canonical_R_hom R A (add_zero j) (mul j 0 a one) = a)\n(mul_assoc : \u2200 {i j k} (a : A i) (b : A j) (c : A k),\n   canonical_R_hom R A (add_assoc i j k) (mul (i+j) k (mul i j a b) c) = mul i (j + k) a (mul j k b c))\n(graded_comm : \u2200 {i j} (a : A i) (b : A j),\n  canonical_R_hom R A (add_comm j i) (mul j i b a) = (-1 : R)^(i * j) \u2022 mul i j a b)\n(d : \u2200 n, (A n) \u2192\u2097[R] (A (n + 1)))\n(d_squared : \u2200 {n} (a : A n), (d (n + 1) : A (n + 1) \u2192 A (n + 2)) (d n a) = 0)\n(Leibniz : \u2200 i j (a : A i) (b : A j), d (i + j) (mul i j a b) =\n   canonical_R_hom R A (add_right_comm i (1:\u2115) j) (mul (i+(1:\u2115)) j (d i a) b) +\n   (-1 : R) ^ i \u2022 canonical_R_hom R A (add_assoc i j (1:\u2115)).symm (mul i (j+(1:\u2115)) a (d j b)))\nattribute [instance] cdga.hA cdga.hRA\n\n/-\nIf AAA is a CDGA then its cohomology H\u2217(A)H^*(A)H\u2217(A) is a graded commutative algebra. Basically this amounts to checking that\n\n    if da=0da = 0da=0 and db=0db = 0db=0, then d(a\u22c5b)=0d(a \\cdot b) = 0d(a\u22c5b)=0\n    if da=0da = 0da=0 and b=db\u2032b = db'b=db\u2032, then a\u22c5ba \\cdot ba\u22c5b is ddd of something (namely (\u22121)ia\u22c5b\u2032(-1)^i a \\cdot b'(\u22121)ia\u22c5b\u2032 where a\u2208Aia \\in A_ia\u2208Ai\u200b),\n    similarly if a=da\u2032a = da'a=da\u2032 and db=0db = 0db=0 then a\u22c5ba \\cdot ba\u22c5b is ddd of something\n    and therefore the multiplication Ai\u00d7Aj\u2192Ai+jA_i \\times A_j \\to A_{i+j}Ai\u200b\u00d7Aj\u200b\u2192Ai+j\u200b restricts/descends to the kernel of ddd modulo the image of ddd.\n\n-/\nnamespace cdga\n\nvariables (R : Type u) [comm_ring R] (A : cdga R)\n\nlemma zero_mul {i j : \u2115} (b : A.A j) : A.mul i j (0 : A.A i) b = 0 :=\nby rw [linear_map.map_zero, linear_map.zero_apply]\n\nlemma mul_zero {i j : \u2115} (a : A.A i) : A.mul i j a (0 : A.A j) = 0 :=\nlinear_map.map_zero _\n\n--set_option pp.proofs true\nlemma ker_d_prod (A : cdga R) {i j : \u2115} (a : A.A i) (b : A.A j) (ha : A.d i a = 0) (hb : A.d j b = 0) :\n  A.d (i + j) (A.mul i j a b) = 0 :=\nby rw [A.Leibniz, ha, hb, zero_mul, mul_zero, linear_map.map_zero, linear_map.map_zero, zero_add, smul_zero]\n\nend cdga\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Examples/cdga_kenny.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7062685651467274}}
{"text": "\nnamespace prop_21\n/-\nAn example of a proof without use of classical rules.\n-/\n\nvariable A : Prop\n\ntheorem prop_21 : \u00ac (A \u2194 \u00ac A) :=\nassume h1: A \u2194 \u00ac A,\nhave h2: A \u2192 (A \u2192 false), from h1.mp,\nhave h3: (A \u2192 false) \u2192 A, from h1.mpr,\nhave h4: A \u2192 false, from (assume h5: A, (h2 h5) h5),\nhave h6: A, from h3 h4,\nshow false, from h4 h6\n\n/-\nNo classical logic used so should print `no axioms`.\n-/\n#print axioms prop_21\n\n-- end namespace\nend prop_21", "meta": {"author": "tomasz-lisowski", "repo": "lean-logic-examples", "sha": "2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d", "save_path": "github-repos/lean/tomasz-lisowski-lean-logic-examples", "path": "github-repos/lean/tomasz-lisowski-lean-logic-examples/lean-logic-examples-2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d/src/logic_propositional/prop_21.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7062685634655483}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Johan Commelin, Mario Carneiro\n-/\n\nimport data.mv_polynomial.variables\n\n/-!\n# Multivariate polynomials over a ring\n\nMany results about polynomials hold when the coefficient ring is a commutative semiring.\nSome stronger results can be derived when we assume this semiring is a ring.\n\nThis file does not define any new operations, but proves some of these stronger results.\n\n## Notation\n\nAs in other polynomial files, we typically use the notation:\n\n+ `\u03c3 : Type*` (indexing the variables)\n\n+ `R : Type*` `[comm_ring R]` (the coefficients)\n\n+ `s : \u03c3 \u2192\u2080 \u2115`, a function from `\u03c3` to `\u2115` which is zero away from a finite set.\nThis will give rise to a monomial in `mv_polynomial \u03c3 R` which mathematicians might call `X^s`\n\n+ `a : R`\n\n+ `i : \u03c3`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians\n\n+ `p : mv_polynomial \u03c3 R`\n\n-/\n\nnoncomputable theory\n\nopen_locale classical big_operators\n\nopen set function finsupp add_monoid_algebra\nopen_locale big_operators\n\nuniverses u v\nvariables {R : Type u} {S : Type v}\n\nnamespace mv_polynomial\nvariables {\u03c3 : Type*} {a a' a\u2081 a\u2082 : R} {e : \u2115} {n m : \u03c3} {s : \u03c3 \u2192\u2080 \u2115}\n\nsection comm_ring\nvariable [comm_ring R]\nvariables {p q : mv_polynomial \u03c3 R}\n\ninstance : comm_ring (mv_polynomial \u03c3 R) := add_monoid_algebra.comm_ring\n\nvariables (\u03c3 a a')\n\n@[simp] lemma C_sub : (C (a - a') : mv_polynomial \u03c3 R) = C a - C a' := ring_hom.map_sub _ _ _\n\n@[simp] lemma C_neg : (C (-a) : mv_polynomial \u03c3 R) = -C a := ring_hom.map_neg _ _\n\n@[simp] lemma coeff_neg (m : \u03c3 \u2192\u2080 \u2115) (p : mv_polynomial \u03c3 R) :\n  coeff m (-p) = -coeff m p := finsupp.neg_apply _ _\n\n@[simp] lemma coeff_sub (m : \u03c3 \u2192\u2080 \u2115) (p q : mv_polynomial \u03c3 R) :\n  coeff m (p - q) = coeff m p - coeff m q := finsupp.sub_apply _ _ _\n\n@[simp] lemma support_neg : (- p).support = p.support :=\nfinsupp.support_neg\n\nvariables {\u03c3} (p)\n\nsection degrees\n\nlemma degrees_neg (p : mv_polynomial \u03c3 R) : (- p).degrees = p.degrees :=\nby rw [degrees, support_neg]; refl\n\nlemma degrees_sub (p q : mv_polynomial \u03c3 R) :\n  (p - q).degrees \u2264 p.degrees \u2294 q.degrees :=\nby simpa only [sub_eq_add_neg] using le_trans (degrees_add p (-q)) (by rw degrees_neg)\n\nend degrees\n\nsection vars\n\nvariables (p q)\n\n@[simp] lemma vars_neg : (-p).vars = p.vars :=\nby simp [vars, degrees_neg]\n\nlemma vars_sub_subset : (p - q).vars \u2286 p.vars \u222a q.vars :=\nby convert vars_add_subset p (-q) using 2; simp [sub_eq_add_neg]\n\nvariables {p q}\n\n@[simp]\nlemma vars_sub_of_disjoint (hpq : disjoint p.vars q.vars) : (p - q).vars = p.vars \u222a q.vars :=\nbegin\n  rw \u2190vars_neg q at hpq,\n  convert vars_add_of_disjoint hpq using 2;\n    simp [sub_eq_add_neg]\nend\n\nend vars\n\nsection eval\u2082\n\nvariables [comm_ring S]\nvariables (f : R \u2192+* S) (g : \u03c3 \u2192 S)\n\n@[simp] \n\n@[simp] lemma eval\u2082_neg : (-p).eval\u2082 f g = -(p.eval\u2082 f g) := (eval\u2082_hom f g).map_neg _\n\nlemma hom_C (f : mv_polynomial \u03c3 \u2124 \u2192+* S) (n : \u2124) : f (C n) = (n : S) :=\n(f.comp C).eq_int_cast n\n\n/-- A ring homomorphism f : Z[X_1, X_2, ...] \u2192 R\nis determined by the evaluations f(X_1), f(X_2), ... -/\n@[simp] lemma eval\u2082_hom_X {R : Type u} (c : \u2124 \u2192+* S)\n  (f : mv_polynomial R \u2124 \u2192+* S) (x : mv_polynomial R \u2124) :\n  eval\u2082 c (f \u2218 X) x = f x :=\nmv_polynomial.induction_on x\n(\u03bb n, by { rw [hom_C f, eval\u2082_C], exact c.eq_int_cast n })\n(\u03bb p q hp hq, by { rw [eval\u2082_add, hp, hq], exact (f.map_add _ _).symm })\n(\u03bb p n hp, by { rw [eval\u2082_mul, eval\u2082_X, hp], exact (f.map_mul _ _).symm })\n\n/-- Ring homomorphisms out of integer polynomials on a type `\u03c3` are the same as\nfunctions out of the type `\u03c3`, -/\ndef hom_equiv : (mv_polynomial \u03c3 \u2124 \u2192+* S) \u2243 (\u03c3 \u2192 S) :=\n{ to_fun := \u03bb f, \u21d1f \u2218 X,\n  inv_fun := \u03bb f, eval\u2082_hom (int.cast_ring_hom S) f,\n  left_inv := \u03bb f, ring_hom.ext  $ eval\u2082_hom_X _ _,\n  right_inv := \u03bb f, funext $ \u03bb x, by simp only [coe_eval\u2082_hom, function.comp_app, eval\u2082_X] }\n\nend eval\u2082\n\nsection total_degree\n\n@[simp] lemma total_degree_neg (a : mv_polynomial \u03c3 R) :\n  (-a).total_degree = a.total_degree :=\nby simp only [total_degree, support_neg]\n\nlemma total_degree_sub (a b : mv_polynomial \u03c3 R) :\n  (a - b).total_degree \u2264 max a.total_degree b.total_degree :=\ncalc (a - b).total_degree = (a + -b).total_degree                : by rw sub_eq_add_neg\n                      ... \u2264 max a.total_degree (-b).total_degree : total_degree_add a (-b)\n                      ... = max a.total_degree b.total_degree    : by rw total_degree_neg\n\nend total_degree\n\nend comm_ring\n\nend mv_polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/mv_polynomial/comm_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7062409062484314}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n-/\n\nimport data.multiset.basic\nimport data.vector2\nimport tactic.tidy\n\n/-!\n# Symmetric powers\n\nThis file defines symmetric powers of a type.  The nth symmetric power\nconsists of homogeneous n-tuples modulo permutations by the symmetric\ngroup.\n\nThe special case of 2-tuples is called the symmetric square, which is\naddressed in more detail in `data.sym2`.\n\nTODO: This was created as supporting material for `data.sym2`; it\nneeds a fleshed-out interface.\n\n## Tags\n\nsymmetric powers\n\n-/\n\nuniverses u\n\n/--\nThe nth symmetric power is n-tuples up to permutation.  We define it\nas a subtype of `multiset` since these are well developed in the\nlibrary.  We also give a definition `sym.sym'` in terms of vectors, and we\nshow these are equivalent in `sym.sym_equiv_sym'`.\n-/\ndef sym (\u03b1 : Type u) (n : \u2115) := {s : multiset \u03b1 // s.card = n}\n\n/--\nThis is the `list.perm` setoid lifted to `vector`.\n-/\ndef vector.perm.is_setoid (\u03b1 : Type u) (n : \u2115) : setoid (vector \u03b1 n) :=\n{ r := \u03bb a b, list.perm a.1 b.1,\n  iseqv := by { rcases list.perm.eqv \u03b1 with \u27e8hr, hs, ht\u27e9, tidy, } }\n\nlocal attribute [instance] vector.perm.is_setoid\n\nnamespace sym\n\nvariables {\u03b1 : Type u} {n : \u2115}\n\n/--\nThis is the quotient map that takes a list of n elements as an n-tuple and produces an nth\nsymmetric power.\n-/\ndef of_vector (x : vector \u03b1 n) : sym \u03b1 n :=\n\u27e8\u2191x.val, by { rw multiset.coe_card, exact x.2 }\u27e9\n\ninstance : has_lift (vector \u03b1 n) (sym \u03b1 n) :=\n{ lift := of_vector }\n\n/--\nThe unique element in `sym \u03b1 0`.\n-/\n@[pattern] def nil : sym \u03b1 0 := \u27e80, by tidy\u27e9\n\n/--\nInserts an element into the term of `sym \u03b1 n`, increasing the length by one.\n-/\n@[pattern] def cons : \u03b1 \u2192 sym \u03b1 n \u2192 sym \u03b1 (nat.succ n)\n| a \u27e8s, h\u27e9 := \u27e8a ::\u2098 s, by rw [multiset.card_cons, h]\u27e9\n\nnotation a :: b := cons a b\n\n@[simp]\nlemma cons_inj_right (a : \u03b1) (s s' : sym \u03b1 n) : a :: s = a :: s' \u2194 s = s' :=\nby { cases s, cases s', delta cons, simp, }\n\n@[simp]\nlemma cons_inj_left (a a' : \u03b1) (s : sym \u03b1 n) : a :: s = a' :: s \u2194 a = a' :=\nby { cases s, delta cons, simp, }\n\nlemma cons_swap (a b : \u03b1) (s : sym \u03b1 n) : a :: b :: s = b :: a :: s :=\nby { cases s, ext, delta cons, rw subtype.coe_mk, dsimp, exact multiset.cons_swap a b s_val }\n\n/--\n`\u03b1 \u2208 s` means that `a` appears as one of the factors in `s`.\n-/\ndef mem (a : \u03b1) (s : sym \u03b1 n) : Prop := a \u2208 s.1\n\ninstance : has_mem \u03b1 (sym \u03b1 n) := \u27e8mem\u27e9\n\ninstance decidable_mem [decidable_eq \u03b1] (a : \u03b1) (s : sym \u03b1 n) : decidable (a \u2208 s) :=\nby { cases s, change decidable (a \u2208 s_val), apply_instance }\n\n@[simp] lemma mem_cons {a b : \u03b1} {s : sym \u03b1 n} : a \u2208 b :: s \u2194 a = b \u2228 a \u2208 s :=\nbegin cases s, change a \u2208 b ::\u2098 s_val \u2194 a = b \u2228 a \u2208 s_val, simp, end\n\nlemma mem_cons_of_mem {a b : \u03b1} {s : sym \u03b1 n} (h : a \u2208 s) : a \u2208 b :: s :=\nmem_cons.2 (or.inr h)\n\n@[simp] lemma mem_cons_self (a : \u03b1) (s : sym \u03b1 n) : a \u2208 a :: s :=\nmem_cons.2 (or.inl rfl)\n\nlemma cons_of_coe_eq (a : \u03b1) (v : vector \u03b1 n) : a :: (\u2191v : sym \u03b1 n) = \u2191(a ::\u1d65 v) :=\nby { unfold_coes, delta of_vector, delta cons, delta vector.cons, tidy }\n\nlemma sound {a b : vector \u03b1 n} (h : a.val ~ b.val) : (\u2191a : sym \u03b1 n) = \u2191b :=\nbegin\n  cases a, cases b, unfold_coes, dunfold of_vector,\n  simp only [subtype.mk_eq_mk, multiset.coe_eq_coe],\n  exact h,\nend\n\n/--\nAnother definition of the nth symmetric power, using vectors modulo permutations. (See `sym`.)\n-/\ndef sym' (\u03b1 : Type u) (n : \u2115) := quotient (vector.perm.is_setoid \u03b1 n)\n\n/--\nThis is `cons` but for the alternative `sym'` definition.\n-/\ndef cons' {\u03b1 : Type u} {n : \u2115} : \u03b1 \u2192 sym' \u03b1 n \u2192 sym' \u03b1 (nat.succ n) :=\n\u03bb a, quotient.map (vector.cons a) (\u03bb \u27e8l\u2081, h\u2081\u27e9 \u27e8l\u2082, h\u2082\u27e9 h, list.perm.cons _ h)\n\nnotation a :: b := cons' a b\n\n/--\nMultisets of cardinality n are equivalent to length-n vectors up to permutations.\n-/\ndef sym_equiv_sym' {\u03b1 : Type u} {n : \u2115} : sym \u03b1 n \u2243 sym' \u03b1 n :=\nequiv.subtype_quotient_equiv_quotient_subtype _ _ (\u03bb _, by refl) (\u03bb _ _, by refl)\n\nlemma cons_equiv_eq_equiv_cons (\u03b1 : Type u) (n : \u2115) (a : \u03b1) (s : sym \u03b1 n) :\n  a :: sym_equiv_sym' s = sym_equiv_sym' (a :: s) :=\nby tidy\n\nsection inhabited\n-- Instances to make the linter happy\n\ninstance inhabited_sym [inhabited \u03b1] (n : \u2115) : inhabited (sym \u03b1 n) :=\n\u27e8\u27e8multiset.repeat (default \u03b1) n, multiset.card_repeat _ _\u27e9\u27e9\n\ninstance inhabited_sym' [inhabited \u03b1] (n : \u2115) : inhabited (sym' \u03b1 n) :=\n\u27e8quotient.mk' (vector.repeat (default \u03b1) n)\u27e9\n\nend inhabited\n\nend sym\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/sym.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.706240904665361}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport tactic.basic\nimport logic.is_empty\n\n/-!\n# Types with a unique term\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we define a typeclass `unique`,\nwhich expresses that a type has a unique term.\nIn other words, a type that is `inhabited` and a `subsingleton`.\n\n## Main declaration\n\n* `unique`: a typeclass that expresses that a type has a unique term.\n\n## Main statements\n\n* `unique.mk'`: an inhabited subsingleton type is `unique`. This can not be an instance because it\n  would lead to loops in typeclass inference.\n\n* `function.surjective.unique`: if the domain of a surjective function is `unique`, then its\n  codomain is `unique` as well.\n\n* `function.injective.subsingleton`: if the codomain of an injective function is `subsingleton`,\n  then its domain is `subsingleton` as well.\n\n* `function.injective.unique`: if the codomain of an injective function is `subsingleton` and its\n  domain is `inhabited`, then its domain is `unique`.\n\n## Implementation details\n\nThe typeclass `unique \u03b1` is implemented as a type,\nrather than a `Prop`-valued predicate,\nfor good definitional properties of the default term.\n\n-/\n\nuniverses u v w\n\nvariables {\u03b1 : Sort u} {\u03b2 : Sort v} {\u03b3 : Sort w}\n\n/-- `unique \u03b1` expresses that `\u03b1` is a type with a unique term `default`.\n\nThis is implemented as a type, rather than a `Prop`-valued predicate,\nfor good definitional properties of the default term. -/\n@[ext]\nstructure unique (\u03b1 : Sort u) extends inhabited \u03b1 :=\n(uniq : \u2200 a : \u03b1, a = default)\n\nattribute [class] unique\n\nlemma unique_iff_exists_unique (\u03b1 : Sort u) : nonempty (unique \u03b1) \u2194 \u2203! a : \u03b1, true :=\n\u27e8\u03bb \u27e8u\u27e9, \u27e8u.default, trivial, \u03bb a _, u.uniq a\u27e9, \u03bb \u27e8a,_,h\u27e9, \u27e8\u27e8\u27e8a\u27e9, \u03bb _, h _ trivial\u27e9\u27e9\u27e9\n\nlemma unique_subtype_iff_exists_unique {\u03b1} (p : \u03b1 \u2192 Prop) :\n  nonempty (unique (subtype p)) \u2194 \u2203! a, p a :=\n\u27e8\u03bb \u27e8u\u27e9, \u27e8u.default.1, u.default.2, \u03bb a h, congr_arg subtype.val (u.uniq \u27e8a,h\u27e9)\u27e9,\n \u03bb \u27e8a,ha,he\u27e9, \u27e8\u27e8\u27e8\u27e8a,ha\u27e9\u27e9, \u03bb \u27e8b,hb\u27e9, by { congr, exact he b hb }\u27e9\u27e9\u27e9\n\n/-- Given an explicit `a : \u03b1` with `[subsingleton \u03b1]`, we can construct\na `[unique \u03b1]` instance. This is a def because the typeclass search cannot\narbitrarily invent the `a : \u03b1` term. Nevertheless, these instances are all\nequivalent by `unique.subsingleton.unique`.\n\nSee note [reducible non-instances]. -/\n@[reducible] def unique_of_subsingleton {\u03b1 : Sort*} [subsingleton \u03b1] (a : \u03b1) : unique \u03b1 :=\n{ default := a,\n  uniq := \u03bb _, subsingleton.elim _ _ }\n\ninstance punit.unique : unique punit.{u} :=\n{ default := punit.star,\n  uniq := \u03bb x, punit_eq x _ }\n\n@[simp] lemma punit.default_eq_star : (default : punit) = punit.star := rfl\n\n/-- Every provable proposition is unique, as all proofs are equal. -/\ndef unique_prop {p : Prop} (h : p) : unique p :=\n{ default := h, uniq := \u03bb x, rfl }\n\ninstance : unique true := unique_prop trivial\n\nlemma fin.eq_zero : \u2200 n : fin 1, n = 0\n| \u27e8n, hn\u27e9 := fin.eq_of_veq (nat.eq_zero_of_le_zero (nat.le_of_lt_succ hn))\n\ninstance {n : \u2115} : inhabited (fin n.succ) := \u27e80\u27e9\ninstance inhabited_fin_one_add (n : \u2115) : inhabited (fin (1 + n)) := \u27e8\u27e80, nat.zero_lt_one_add n\u27e9\u27e9\n\n@[simp] lemma fin.default_eq_zero (n : \u2115) : (default : fin n.succ) = 0 := rfl\n\ninstance fin.unique : unique (fin 1) :=\n{ uniq := fin.eq_zero, .. fin.inhabited }\n\nnamespace unique\nopen function\n\nsection\n\nvariables [unique \u03b1]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : inhabited \u03b1 := to_inhabited \u2039unique \u03b1\u203a\n\nlemma eq_default (a : \u03b1) : a = default := uniq _ a\n\nlemma default_eq (a : \u03b1) : default = a := (uniq _ a).symm\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : subsingleton \u03b1 := subsingleton_of_forall_eq _ eq_default\n\nlemma forall_iff {p : \u03b1 \u2192 Prop} : (\u2200 a, p a) \u2194 p default :=\n\u27e8\u03bb h, h _, \u03bb h x, by rwa [unique.eq_default x]\u27e9\n\nlemma exists_iff {p : \u03b1 \u2192 Prop} : Exists p \u2194 p default :=\n\u27e8\u03bb \u27e8a, ha\u27e9, eq_default a \u25b8 ha, exists.intro default\u27e9\n\nend\n\n@[ext] protected lemma subsingleton_unique' : \u2200 (h\u2081 h\u2082 : unique \u03b1), h\u2081 = h\u2082\n| \u27e8\u27e8x\u27e9, h\u27e9 \u27e8\u27e8y\u27e9, _\u27e9 := by congr; rw [h x, h y]\n\ninstance subsingleton_unique : subsingleton (unique \u03b1) :=\n\u27e8unique.subsingleton_unique'\u27e9\n\n/-- Construct `unique` from `inhabited` and `subsingleton`. Making this an instance would create\na loop in the class inheritance graph. -/\n@[reducible] def mk' (\u03b1 : Sort u) [h\u2081 : inhabited \u03b1] [subsingleton \u03b1] : unique \u03b1 :=\n{ uniq := \u03bb x, subsingleton.elim _ _, .. h\u2081 }\n\nend unique\n\nlemma unique_iff_subsingleton_and_nonempty (\u03b1 : Sort u) :\n  nonempty (unique \u03b1) \u2194 subsingleton \u03b1 \u2227 nonempty \u03b1 :=\n\u27e8\u03bb \u27e8u\u27e9, by split; exactI infer_instance,\n \u03bb \u27e8hs, hn\u27e9, \u27e8by { resetI, inhabit \u03b1, exact unique.mk' \u03b1 }\u27e9\u27e9\n\n@[simp] lemma pi.default_def {\u03b2 : \u03b1 \u2192 Sort v} [\u03a0 a, inhabited (\u03b2 a)] :\n  @default (\u03a0 a, \u03b2 a) _ = \u03bb a : \u03b1, @default (\u03b2 a) _ := rfl\n\nlemma pi.default_apply {\u03b2 : \u03b1 \u2192 Sort v} [\u03a0 a, inhabited (\u03b2 a)] (a : \u03b1) :\n  @default (\u03a0 a, \u03b2 a) _ a = default := rfl\n\ninstance pi.unique {\u03b2 : \u03b1 \u2192 Sort v} [\u03a0 a, unique (\u03b2 a)] : unique (\u03a0 a, \u03b2 a) :=\n{ uniq := \u03bb f, funext $ \u03bb x, unique.eq_default _,\n  .. pi.inhabited \u03b1 }\n\n/-- There is a unique function on an empty domain. -/\ninstance pi.unique_of_is_empty [is_empty \u03b1] (\u03b2 : \u03b1 \u2192 Sort v) :\n  unique (\u03a0 a, \u03b2 a) :=\n{ default := is_empty_elim,\n  uniq := \u03bb f, funext is_empty_elim }\n\nlemma eq_const_of_unique [unique \u03b1] (f : \u03b1 \u2192 \u03b2) : f = function.const \u03b1 (f default) :=\nby { ext x, rw subsingleton.elim x default }\n\nlemma heq_const_of_unique [unique \u03b1] {\u03b2 : \u03b1 \u2192 Sort v}\n  (f : \u03a0 a, \u03b2 a) : f == function.const \u03b1 (f default) :=\nfunction.hfunext rfl $ \u03bb i _ _, by rw subsingleton.elim i default\n\nnamespace function\n\nvariable {f : \u03b1 \u2192 \u03b2}\n\n/-- If the codomain of an injective function is a subsingleton, then the domain\nis a subsingleton as well. -/\nprotected lemma injective.subsingleton (hf : injective f) [subsingleton \u03b2] :\n  subsingleton \u03b1 :=\n\u27e8\u03bb x y, hf $ subsingleton.elim _ _\u27e9\n\n/-- If the domain of a surjective function is a subsingleton, then the codomain is a subsingleton as\nwell. -/\nprotected lemma surjective.subsingleton [subsingleton \u03b1] (hf : surjective f) :\n  subsingleton \u03b2 :=\n\u27e8hf.forall\u2082.2 $ \u03bb x y, congr_arg f $ subsingleton.elim x y\u27e9\n\n/-- If the domain of a surjective function is a singleton,\nthen the codomain is a singleton as well. -/\nprotected def surjective.unique (hf : surjective f) [unique \u03b1] : unique \u03b2 :=\n@unique.mk' _ \u27e8f default\u27e9 hf.subsingleton\n\n/-- If `\u03b1` is inhabited and admits an injective map to a subsingleton type, then `\u03b1` is `unique`. -/\nprotected def injective.unique [inhabited \u03b1] [subsingleton \u03b2] (hf : injective f) : unique \u03b1 :=\n@unique.mk' _ _ hf.subsingleton\n\n/-- If a constant function is surjective, then the codomain is a singleton. -/\ndef surjective.unique_of_surjective_const (\u03b1 : Type*) {\u03b2 : Type*} (b : \u03b2)\n  (h : function.surjective (function.const \u03b1 b)) : unique \u03b2 :=\n@unique_of_subsingleton _ (subsingleton_of_forall_eq b $ h.forall.mpr (\u03bb _, rfl)) b\n\nend function\n\nlemma unique.bijective {A B} [unique A] [unique B] {f : A \u2192 B} : function.bijective f :=\nbegin\n  rw function.bijective_iff_has_inverse,\n  refine \u27e8default, _, _\u27e9; intro x; simp\nend\n\nnamespace option\n\n/-- `option \u03b1` is a `subsingleton` if and only if `\u03b1` is empty. -/\nlemma subsingleton_iff_is_empty {\u03b1} : subsingleton (option \u03b1) \u2194 is_empty \u03b1 :=\n\u27e8\u03bb h, \u27e8\u03bb x, option.no_confusion $ @subsingleton.elim _ h x none\u27e9,\n  \u03bb h, \u27e8\u03bb x y, option.cases_on x (option.cases_on y rfl (\u03bb x, h.elim x)) (\u03bb x, h.elim x)\u27e9\u27e9\n\ninstance {\u03b1} [is_empty \u03b1] : unique (option \u03b1) := @unique.mk' _ _ (subsingleton_iff_is_empty.2 \u2039_\u203a)\n\nend option\n\nsection subtype\n\ninstance unique.subtype_eq (y : \u03b1) : unique {x // x = y} :=\n{ default := \u27e8y, rfl\u27e9,\n  uniq := \u03bb \u27e8x, hx\u27e9, by simpa using hx }\n\ninstance unique.subtype_eq' (y : \u03b1) : unique {x // y = x} :=\n{ default := \u27e8y, rfl\u27e9,\n  uniq := \u03bb \u27e8x, hx\u27e9, by simpa using hx.symm }\n\nend subtype\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/logic/unique.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276107, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7062409034875475}}
{"text": "-- import the definitions of uniform space via covers\nimport uniform_structure.covers\n\n-- import the definition of pseudometric space\nimport pseudometric_space\n\n-- In this exercise we will show that a pseudometric on a set X \n-- gives rise to a distinguished family of covers for X \n-- which make X into a \"uniform space in the sense of covers\"\n\n-- This is a question about pseudometrics so let's put it\n-- in the pseudometric namespace\n\nnamespace pseudometric\n\n-- Let X be a set (or a type), and let d be a pseudometric on X\nvariables {X : Type} (d : X \u2192 X \u2192 \u211d) [is_pseudometric d]\n\n-- let's define a closed ball\n\n/-- Closed ball centre x radius \u03b5 -/\ndef closed_ball (x : X) (\u03b5 : \u211d) := {y : X | d x y \u2264 \u03b5}\n\n-- definition of closed ball\nlemma mem_closed_ball {x y : X} {\u03b5 : \u211d} : y \u2208 closed_ball d x \u03b5 \u2194 d x y \u2264 \u03b5 :=\niff.rfl -- true by definition\n\n-- Here's an obvious lemma: if 0 \u2264 \u03b5 then x is in the closed ball centre x\n-- and radius \u03b5\n\n-- But do we need it?\n\n-- lemma self_mem_ball (x : X) (\u03b5 : \u211d) (h\u03b5 : 0 \u2264 \u03b5) : x \u2208 closed_ball d x \u03b5 :=\n-- begin\n--   rw mem_closed_ball,\n--   rw d_self d,\n--   assumption\n-- end\n\n-- Define \u0398 to be the set of covers of X with the following property:\n-- there exists \u03b5 \u2265 0 such that each set in the cover contains a closed ball\n-- of radius \u03b5 (note that \u03b5 is independent of which set in the cover)\n\ndef \u0398 : set (cover X) :=\n  {\ud835\udc9e | \u2203 \u03b5 (h\u03b5 : 0 < \u03b5), \u2200 x : X, \u2203 U \u2208 \ud835\udc9e.C, closed_ball d x \u03b5 \u2286 U}\n\n-- a cover is in \u0398 iff it's a closed ball cover, or the universal cover\n-- the proof is obvious\nlemma mem_\u0398 (\ud835\udc9e : cover X) : \ud835\udc9e \u2208 \u0398 d \u2194\n  \u2203 \u03b5 (h\u03b5 : 0 < \u03b5), \u2200 x : X, \u2203 U \u2208 \ud835\udc9e.C, closed_ball d x \u03b5 \u2286 U := iff.rfl -- true by definition\n\n-- The exerise is to show that the 3 axioms for a distinguished family are\n-- satisfied by \u0398\n\n-- Axiom 1: the universal cover is in\nlemma univ_mem : univ_cover X \u2208 \u0398 d :=\nbegin\n  sorry\nend\n\n-- Axiom 2 : anything star-bigger than a distinguished cover is distinguished\nlemma star_mem (P Q : cover X) (hP : P \u2208 \u0398 d) (hPQ : P <* Q) : Q \u2208 \u0398 d :=\nbegin\n  sorry\nend\n\n-- Axiom 3: two covers have an upper bound in the <* ordering\nlemma ub_mem (P Q : cover X) (hP : P \u2208 \u0398 d) (hQ : Q \u2208 \u0398 d) :\n  \u2203 R : cover X, R \u2208 \u0398 d \u2227 R <* P \u2227 R <* Q :=\nbegin\n  sorry\nend\n \ndefinition to_cover : dist_covers X :=\n{ \u0398 := \u0398 d,\n  univ_mem := univ_mem d,\n  star_mem := star_mem d,\n  ub_mem := ub_mem d}\n\nend pseudometric", "meta": {"author": "ImperialCollegeLondon", "repo": "uniform-structures", "sha": "a41a170ef125b36bdac1e2201f54affa958d0349", "save_path": "github-repos/lean/ImperialCollegeLondon-uniform-structures", "path": "github-repos/lean/ImperialCollegeLondon-uniform-structures/uniform-structures-a41a170ef125b36bdac1e2201f54affa958d0349/solutions/covers_from_pseudometric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7062409019044771}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Patrick Stevens\n-/\nimport data.nat.choose.basic\nimport data.nat.prime\nimport data.rat.floor\n/-!\n# Divisibility properties of binomial coefficients\n-/\n\nnamespace nat\n\nopen_locale nat\n\nnamespace prime\n\nlemma dvd_choose_add {p a b : \u2115} (hap : a < p) (hbp : b < p) (h : p \u2264 a + b)\n  (hp : prime p) : p \u2223 choose (a + b) a :=\nhave h\u2081 : p \u2223 (a + b)!, from hp.dvd_factorial.2 h,\nhave h\u2082 : \u00acp \u2223 a!, from mt hp.dvd_factorial.1 (not_le_of_gt hap),\nhave h\u2083 : \u00acp \u2223 b!, from mt hp.dvd_factorial.1 (not_le_of_gt hbp),\nby\n  rw [\u2190 choose_mul_factorial_mul_factorial (le.intro rfl), mul_assoc, hp.dvd_mul, hp.dvd_mul,\n      nat.add_sub_cancel_left a b] at h\u2081;\n  exact h\u2081.resolve_right (not_or_distrib.2 \u27e8h\u2082, h\u2083\u27e9)\n\nlemma dvd_choose_self {p k : \u2115} (hk : 0 < k) (hkp : k < p) (hp : prime p) :\n  p \u2223 choose p k :=\nbegin\n  have r : k + (p - k) = p,\n    by rw [\u2190 nat.add_sub_assoc (nat.le_of_lt hkp) k, nat.add_sub_cancel_left],\n  have e : p \u2223 choose (k + (p - k)) k,\n    by exact dvd_choose_add hkp (sub_lt (hk.trans hkp) hk) (by rw r) hp,\n  rwa r at e,\nend\n\nend prime\n\nlemma choose_eq_factorial_div_factorial' {a b : \u2115}\n  (hab : a \u2264 b) : (b.choose a : \u211a) = b! / (a! * (b - a)!) :=\nbegin\n  field_simp [mul_ne_zero, factorial_ne_zero], norm_cast,\n  rw \u2190 choose_mul_factorial_mul_factorial hab, ring,\nend\n\nlemma choose_mul {n k s : \u2115} (hn : k \u2264 n) (hs : s \u2264 k) :\n  (n.choose k : \u211a) * k.choose s = n.choose s * (n - s).choose (k - s) :=\nbegin\n  rw [choose_eq_factorial_div_factorial' hn, choose_eq_factorial_div_factorial' hs,\n      choose_eq_factorial_div_factorial' (le_trans hs hn), choose_eq_factorial_div_factorial' ],\n  swap,\n  { exact nat.sub_le_sub_right hn s, },\n  { field_simp [mul_ne_zero, factorial_ne_zero],\n    rw sub_sub_sub_cancel_right hs, ring, },\nend\n\nend nat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/choose/dvd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.706240887327501}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n-/\nimport algebra.abs\nimport algebra.order.sub\n\n/-!\n# Ordered groups\n\nThis file develops the basics of ordered groups.\n\n## Implementation details\n\nUnfortunately, the number of `'` appended to lemmas in this file\nmay differ between the multiplicative and the additive version of a lemma.\nThe reason is that we did not want to change existing names in the library.\n-/\n\nset_option old_structure_cmd true\nopen function\n\nuniverse u\nvariable {\u03b1 : Type u}\n\n/-- An ordered additive commutative group is an additive commutative group\nwith a partial order in which addition is strictly monotone. -/\n@[protect_proj, ancestor add_comm_group partial_order]\nclass ordered_add_comm_group (\u03b1 : Type u) extends add_comm_group \u03b1, partial_order \u03b1 :=\n(add_le_add_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n\n/-- An ordered commutative group is an commutative group\nwith a partial order in which multiplication is strictly monotone. -/\n@[protect_proj, ancestor comm_group partial_order]\nclass ordered_comm_group (\u03b1 : Type u) extends comm_group \u03b1, partial_order \u03b1 :=\n(mul_le_mul_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\nattribute [to_additive] ordered_comm_group\n\n@[to_additive]\ninstance ordered_comm_group.to_covariant_class_left_le (\u03b1 : Type u) [ordered_comm_group \u03b1] :\n  covariant_class \u03b1 \u03b1 (*) (\u2264) :=\n{ elim := \u03bb a b c bc, ordered_comm_group.mul_le_mul_left b c bc a }\n\n/--The units of an ordered commutative monoid form an ordered commutative group. -/\n@[to_additive \"The units of an ordered commutative additive monoid form an ordered commutative\nadditive group.\"]\ninstance units.ordered_comm_group [ordered_comm_monoid \u03b1] : ordered_comm_group \u03b1\u02e3 :=\n{ mul_le_mul_left := \u03bb a b h c, (mul_le_mul_left' (h : (a : \u03b1) \u2264 b) _ :  (c : \u03b1) * a \u2264 c * b),\n  .. units.partial_order,\n  .. units.comm_group }\n\n@[priority 100, to_additive]    -- see Note [lower instance priority]\ninstance ordered_comm_group.to_ordered_cancel_comm_monoid (\u03b1 : Type u)\n  [s : ordered_comm_group \u03b1] :\n  ordered_cancel_comm_monoid \u03b1 :=\n{ mul_left_cancel       := \u03bb a b c, (mul_right_inj a).mp,\n  le_of_mul_le_mul_left := \u03bb a b c, (mul_le_mul_iff_left a).mp,\n  ..s }\n\n@[priority 100, to_additive]\ninstance ordered_comm_group.has_exists_mul_of_le (\u03b1 : Type u)\n  [ordered_comm_group \u03b1] :\n  has_exists_mul_of_le \u03b1 :=\n\u27e8\u03bb a b hab, \u27e8b * a\u207b\u00b9, (mul_inv_cancel_comm_assoc a b).symm\u27e9\u27e9\n\n@[to_additive] instance [h : has_inv \u03b1] : has_inv \u03b1\u1d52\u1d48 := h\n@[to_additive] instance [h : has_div \u03b1] : has_div \u03b1\u1d52\u1d48 := h\n@[to_additive] instance [h : has_involutive_inv \u03b1] : has_involutive_inv \u03b1\u1d52\u1d48 := h\n@[to_additive] instance [h : div_inv_monoid \u03b1] : div_inv_monoid \u03b1\u1d52\u1d48 := h\n@[to_additive order_dual.subtraction_monoid]\ninstance [h : division_monoid \u03b1] : division_monoid \u03b1\u1d52\u1d48 := h\n@[to_additive order_dual.subtraction_comm_monoid]\ninstance [h : division_comm_monoid \u03b1] : division_comm_monoid \u03b1\u1d52\u1d48 := h\n@[to_additive] instance [h : group \u03b1] : group \u03b1\u1d52\u1d48 := h\n@[to_additive] instance [h : comm_group \u03b1] : comm_group \u03b1\u1d52\u1d48 := h\ninstance [h : group_with_zero \u03b1] : group_with_zero \u03b1\u1d52\u1d48 := h\ninstance [h : comm_group_with_zero \u03b1] : comm_group_with_zero \u03b1\u1d52\u1d48 := h\n\n@[to_additive] instance [ordered_comm_group \u03b1] : ordered_comm_group \u03b1\u1d52\u1d48 :=\n{ .. order_dual.ordered_comm_monoid, .. order_dual.group }\n\nsection group\nvariables [group \u03b1]\n\nsection typeclasses_left_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n/--  Uses `left` co(ntra)variant. -/\n@[simp, to_additive left.neg_nonpos_iff]\nlemma left.inv_le_one_iff :\n  a\u207b\u00b9 \u2264 1 \u2194 1 \u2264 a :=\nby { rw [\u2190 mul_le_mul_iff_left a], simp }\n\n/--  Uses `left` co(ntra)variant. -/\n@[simp, to_additive left.nonneg_neg_iff]\nlemma left.one_le_inv_iff :\n  1 \u2264 a\u207b\u00b9 \u2194 a \u2264 1 :=\nby { rw [\u2190 mul_le_mul_iff_left a], simp }\n\n@[simp, to_additive]\nlemma le_inv_mul_iff_mul_le : b \u2264 a\u207b\u00b9 * c \u2194 a * b \u2264 c :=\nby { rw \u2190 mul_le_mul_iff_left a, simp }\n\n@[simp, to_additive]\nlemma inv_mul_le_iff_le_mul : b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 b * c :=\nby rw [\u2190 mul_le_mul_iff_left b, mul_inv_cancel_left]\n\n@[to_additive neg_le_iff_add_nonneg']\nlemma inv_le_iff_one_le_mul' : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 a * b :=\n(mul_le_mul_iff_left a).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma le_inv_iff_mul_le_one_left : a \u2264 b\u207b\u00b9 \u2194 b * a \u2264 1 :=\n(mul_le_mul_iff_left b).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma le_inv_mul_iff_le : 1 \u2264 b\u207b\u00b9 * a \u2194 b \u2264 a :=\nby rw [\u2190 mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left]\n\n@[to_additive]\nlemma inv_mul_le_one_iff : a\u207b\u00b9 * b \u2264 1 \u2194 b \u2264 a :=\ntrans (inv_mul_le_iff_le_mul) $ by rw mul_one\n\nend typeclasses_left_le\n\nsection typeclasses_left_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c : \u03b1}\n\n/--  Uses `left` co(ntra)variant. -/\n@[simp, to_additive left.neg_pos_iff]\nlemma left.one_lt_inv_iff :\n  1 < a\u207b\u00b9 \u2194 a < 1 :=\nby rw [\u2190 mul_lt_mul_iff_left a, mul_inv_self, mul_one]\n\n/--  Uses `left` co(ntra)variant. -/\n@[simp, to_additive left.neg_neg_iff]\nlemma left.inv_lt_one_iff :\n  a\u207b\u00b9 < 1 \u2194 1 < a :=\nby rw [\u2190 mul_lt_mul_iff_left a, mul_inv_self, mul_one]\n\n@[simp, to_additive]\nlemma lt_inv_mul_iff_mul_lt : b < a\u207b\u00b9 * c \u2194 a * b < c :=\nby { rw [\u2190 mul_lt_mul_iff_left a], simp }\n\n@[simp, to_additive]\nlemma inv_mul_lt_iff_lt_mul : b\u207b\u00b9 * a < c \u2194 a < b * c :=\nby rw [\u2190 mul_lt_mul_iff_left b, mul_inv_cancel_left]\n\n@[to_additive]\nlemma inv_lt_iff_one_lt_mul' : a\u207b\u00b9 < b \u2194 1 < a * b :=\n(mul_lt_mul_iff_left a).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma lt_inv_iff_mul_lt_one' : a < b\u207b\u00b9 \u2194 b * a < 1 :=\n(mul_lt_mul_iff_left b).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma lt_inv_mul_iff_lt : 1 < b\u207b\u00b9 * a \u2194 b < a :=\nby rw [\u2190 mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left]\n\n@[to_additive]\nlemma inv_mul_lt_one_iff : a\u207b\u00b9 * b < 1 \u2194 b < a :=\ntrans (inv_mul_lt_iff_lt_mul) $ by rw mul_one\n\nend typeclasses_left_lt\n\nsection typeclasses_right_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b c : \u03b1}\n\n/--  Uses `right` co(ntra)variant. -/\n@[simp, to_additive right.neg_nonpos_iff]\nlemma right.inv_le_one_iff :\n  a\u207b\u00b9 \u2264 1 \u2194 1 \u2264 a :=\nby { rw [\u2190 mul_le_mul_iff_right a], simp }\n\n/--  Uses `right` co(ntra)variant. -/\n@[simp, to_additive right.nonneg_neg_iff]\nlemma right.one_le_inv_iff :\n  1 \u2264 a\u207b\u00b9 \u2194 a \u2264 1 :=\nby { rw [\u2190 mul_le_mul_iff_right a], simp }\n\n@[to_additive neg_le_iff_add_nonneg]\nlemma inv_le_iff_one_le_mul : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 b * a :=\n(mul_le_mul_iff_right a).symm.trans $ by rw inv_mul_self\n\n@[to_additive]\nlemma le_inv_iff_mul_le_one_right : a \u2264 b\u207b\u00b9 \u2194 a * b \u2264 1 :=\n(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_self\n\n@[simp, to_additive]\nlemma mul_inv_le_iff_le_mul : a * b\u207b\u00b9 \u2264 c \u2194 a \u2264 c * b :=\n(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right\n\n@[simp, to_additive]\nlemma le_mul_inv_iff_mul_le : c \u2264 a * b\u207b\u00b9 \u2194 c * b \u2264 a :=\n(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right\n\n@[simp, to_additive]\nlemma mul_inv_le_one_iff_le : a * b\u207b\u00b9 \u2264 1 \u2194 a \u2264 b :=\nmul_inv_le_iff_le_mul.trans $ by rw one_mul\n\n@[to_additive]\nlemma le_mul_inv_iff_le : 1 \u2264 a * b\u207b\u00b9 \u2194 b \u2264 a :=\nby rw [\u2190 mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right]\n\n@[to_additive]\nlemma mul_inv_le_one_iff : b * a\u207b\u00b9 \u2264 1 \u2194 b \u2264 a :=\ntrans (mul_inv_le_iff_le_mul) $ by rw one_mul\n\nend typeclasses_right_le\n\nsection typeclasses_right_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b c : \u03b1}\n\n/-- Uses `right` co(ntra)variant. -/\n@[simp, to_additive right.neg_neg_iff \"Uses `right` co(ntra)variant.\"]\nlemma right.inv_lt_one_iff :\n  a\u207b\u00b9 < 1 \u2194 1 < a :=\nby rw [\u2190 mul_lt_mul_iff_right a, inv_mul_self, one_mul]\n\n/-- Uses `right` co(ntra)variant. -/\n@[simp, to_additive right.neg_pos_iff \"Uses `right` co(ntra)variant.\"]\nlemma right.one_lt_inv_iff :\n  1 < a\u207b\u00b9 \u2194 a < 1 :=\nby rw [\u2190 mul_lt_mul_iff_right a, inv_mul_self, one_mul]\n\n@[to_additive]\nlemma inv_lt_iff_one_lt_mul : a\u207b\u00b9 < b \u2194 1 < b * a :=\n(mul_lt_mul_iff_right a).symm.trans $ by rw inv_mul_self\n\n@[to_additive]\nlemma lt_inv_iff_mul_lt_one : a < b\u207b\u00b9 \u2194 a * b < 1 :=\n(mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_self\n\n@[simp, to_additive]\nlemma mul_inv_lt_iff_lt_mul : a * b\u207b\u00b9 < c \u2194 a < c * b :=\nby rw [\u2190 mul_lt_mul_iff_right b, inv_mul_cancel_right]\n\n@[simp, to_additive]\nlemma lt_mul_inv_iff_mul_lt : c < a * b\u207b\u00b9 \u2194 c * b < a :=\n(mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right\n\n@[simp, to_additive]\nlemma inv_mul_lt_one_iff_lt : a * b\u207b\u00b9 < 1 \u2194 a < b :=\nby rw [\u2190 mul_lt_mul_iff_right b, inv_mul_cancel_right, one_mul]\n\n@[to_additive]\nlemma lt_mul_inv_iff_lt : 1 < a * b\u207b\u00b9 \u2194 b < a :=\nby rw [\u2190 mul_lt_mul_iff_right b, one_mul, inv_mul_cancel_right]\n\n@[to_additive]\nlemma mul_inv_lt_one_iff : b * a\u207b\u00b9 < 1 \u2194 b < a :=\ntrans (mul_inv_lt_iff_lt_mul) $ by rw one_mul\n\nend typeclasses_right_lt\n\nsection typeclasses_left_right_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma inv_le_inv_iff : a\u207b\u00b9 \u2264 b\u207b\u00b9 \u2194 b \u2264 a :=\nby { rw [\u2190 mul_le_mul_iff_left a, \u2190 mul_le_mul_iff_right b], simp }\n\nalias neg_le_neg_iff \u2194 le_of_neg_le_neg _\n\nsection\n\nvariable (\u03b1)\n\n/-- `x \u21a6 x\u207b\u00b9` as an order-reversing equivalence. -/\n@[to_additive \"`x \u21a6 -x` as an order-reversing equivalence.\", simps]\ndef order_iso.inv : \u03b1 \u2243o \u03b1\u1d52\u1d48 :=\n{ to_equiv := (equiv.inv \u03b1).trans order_dual.to_dual,\n  map_rel_iff' := \u03bb a b, @inv_le_inv_iff \u03b1 _ _ _ _ _ _ }\n\nend\n\n@[to_additive neg_le]\nlemma inv_le' : a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a :=\n(order_iso.inv \u03b1).symm_apply_le\n\nalias inv_le' \u2194 inv_le_of_inv_le' _\nattribute [to_additive neg_le_of_neg_le] inv_le_of_inv_le'\n\n@[to_additive le_neg]\nlemma le_inv' : a \u2264 b\u207b\u00b9 \u2194 b \u2264 a\u207b\u00b9 :=\n(order_iso.inv \u03b1).le_symm_apply\n\n@[to_additive]\nlemma mul_inv_le_inv_mul_iff : a * b\u207b\u00b9 \u2264 d\u207b\u00b9 * c \u2194 d * a \u2264 c * b :=\nby rw [\u2190 mul_le_mul_iff_left d, \u2190 mul_le_mul_iff_right b, mul_inv_cancel_left, mul_assoc,\n    inv_mul_cancel_right]\n\n@[simp, to_additive] lemma div_le_self_iff (a : \u03b1) {b : \u03b1} : a / b \u2264 a \u2194 1 \u2264 b :=\nby simp [div_eq_mul_inv]\n\n@[simp, to_additive] lemma le_div_self_iff (a : \u03b1) {b : \u03b1} : a \u2264 a / b \u2194 b \u2264 1 :=\nby simp [div_eq_mul_inv]\n\nalias sub_le_self_iff \u2194 _ sub_le_self\n\nend typeclasses_left_right_le\n\nsection typeclasses_left_right_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma inv_lt_inv_iff : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nby { rw [\u2190 mul_lt_mul_iff_left a, \u2190 mul_lt_mul_iff_right b], simp }\n\n@[to_additive neg_lt]\nlemma inv_lt' : a\u207b\u00b9 < b \u2194 b\u207b\u00b9 < a :=\nby rw [\u2190 inv_lt_inv_iff, inv_inv]\n\n@[to_additive lt_neg]\nlemma lt_inv' : a < b\u207b\u00b9 \u2194 b < a\u207b\u00b9 :=\nby rw [\u2190 inv_lt_inv_iff, inv_inv]\n\nalias lt_inv' \u2194 lt_inv_of_lt_inv _\nattribute [to_additive] lt_inv_of_lt_inv\n\nalias inv_lt' \u2194 inv_lt_of_inv_lt' _\nattribute [to_additive neg_lt_of_neg_lt] inv_lt_of_inv_lt'\n\n@[to_additive]\nlemma mul_inv_lt_inv_mul_iff : a * b\u207b\u00b9 < d\u207b\u00b9 * c \u2194 d * a < c * b :=\nby rw [\u2190 mul_lt_mul_iff_left d, \u2190 mul_lt_mul_iff_right b, mul_inv_cancel_left, mul_assoc,\n    inv_mul_cancel_right]\n\n@[simp, to_additive] lemma div_lt_self_iff (a : \u03b1) {b : \u03b1} : a / b < a \u2194 1 < b :=\nby simp [div_eq_mul_inv]\n\nalias sub_lt_self_iff \u2194 _ sub_lt_self\n\nend typeclasses_left_right_lt\n\nsection pre_order\nvariable [preorder \u03b1]\n\nsection left_le\nvariables [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a : \u03b1}\n\n@[to_additive]\nlemma left.inv_le_self (h : 1 \u2264 a) : a\u207b\u00b9 \u2264 a :=\nle_trans (left.inv_le_one_iff.mpr h) h\n\nalias left.neg_le_self \u2190 neg_le_self\n\n@[to_additive]\nlemma left.self_le_inv (h : a \u2264 1) : a \u2264 a\u207b\u00b9 :=\nle_trans h (left.one_le_inv_iff.mpr h)\n\nend left_le\n\nsection left_lt\nvariables [covariant_class \u03b1 \u03b1 (*) (<)] {a : \u03b1}\n\n@[to_additive]\nlemma left.inv_lt_self (h : 1 < a) : a\u207b\u00b9 < a :=\n(left.inv_lt_one_iff.mpr h).trans h\n\nalias left.neg_lt_self \u2190 neg_lt_self\n\n@[to_additive]\nlemma left.self_lt_inv (h : a < 1) : a < a\u207b\u00b9 :=\nlt_trans h (left.one_lt_inv_iff.mpr h)\n\nend left_lt\n\nsection right_le\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a : \u03b1}\n\n@[to_additive]\nlemma right.inv_le_self (h : 1 \u2264 a) : a\u207b\u00b9 \u2264 a :=\nle_trans (right.inv_le_one_iff.mpr h) h\n\n@[to_additive]\nlemma right.self_le_inv (h : a \u2264 1) : a \u2264 a\u207b\u00b9 :=\nle_trans h (right.one_le_inv_iff.mpr h)\n\nend right_le\n\nsection right_lt\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a : \u03b1}\n\n@[to_additive]\nlemma right.inv_lt_self (h : 1 < a) : a\u207b\u00b9 < a :=\n(right.inv_lt_one_iff.mpr h).trans h\n\n@[to_additive]\nlemma right.self_lt_inv (h : a < 1) : a < a\u207b\u00b9 :=\nlt_trans h (right.one_lt_inv_iff.mpr h)\n\nend right_lt\n\nend pre_order\n\nend group\n\nsection comm_group\nvariables [comm_group \u03b1]\n\nsection has_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n@[to_additive]\nlemma inv_mul_le_iff_le_mul' : c\u207b\u00b9 * a \u2264 b \u2194 a \u2264 b * c :=\nby rw [inv_mul_le_iff_le_mul, mul_comm]\n\n@[simp, to_additive]\nlemma mul_inv_le_iff_le_mul' : a * b\u207b\u00b9 \u2264 c \u2194 a \u2264 b * c :=\nby rw [\u2190 inv_mul_le_iff_le_mul, mul_comm]\n\n@[to_additive add_neg_le_add_neg_iff]\nlemma mul_inv_le_mul_inv_iff' : a * b\u207b\u00b9 \u2264 c * d\u207b\u00b9 \u2194 a * d \u2264 c * b :=\nby rw [mul_comm c, mul_inv_le_inv_mul_iff, mul_comm]\n\nend has_le\n\nsection has_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c d : \u03b1}\n\n@[to_additive]\nlemma inv_mul_lt_iff_lt_mul' : c\u207b\u00b9 * a < b \u2194 a < b * c :=\nby rw [inv_mul_lt_iff_lt_mul, mul_comm]\n\n@[simp, to_additive]\nlemma mul_inv_lt_iff_le_mul' : a * b\u207b\u00b9 < c \u2194 a < b * c :=\nby rw [\u2190 inv_mul_lt_iff_lt_mul, mul_comm]\n\n@[to_additive add_neg_lt_add_neg_iff]\nlemma mul_inv_lt_mul_inv_iff' : a * b\u207b\u00b9 < c * d\u207b\u00b9 \u2194 a * d < c * b :=\nby rw [mul_comm c, mul_inv_lt_inv_mul_iff, mul_comm]\n\nend has_lt\n\nend comm_group\n\nalias le_inv' \u2194 le_inv_of_le_inv _\nattribute [to_additive] le_inv_of_le_inv\n\nalias left.inv_le_one_iff \u2194 one_le_of_inv_le_one _\nattribute [to_additive] one_le_of_inv_le_one\n\nalias left.one_le_inv_iff \u2194 le_one_of_one_le_inv _\nattribute [to_additive nonpos_of_neg_nonneg] le_one_of_one_le_inv\n\nalias inv_lt_inv_iff \u2194 lt_of_inv_lt_inv _\nattribute [to_additive] lt_of_inv_lt_inv\n\nalias left.inv_lt_one_iff \u2194 one_lt_of_inv_lt_one _\nattribute [to_additive] one_lt_of_inv_lt_one\n\nalias left.inv_lt_one_iff \u2190 inv_lt_one_iff_one_lt\nattribute [to_additive] inv_lt_one_iff_one_lt\n\nalias left.inv_lt_one_iff \u2190 inv_lt_one'\nattribute [to_additive neg_lt_zero] inv_lt_one'\n\nalias left.one_lt_inv_iff \u2194  inv_of_one_lt_inv _\nattribute [to_additive neg_of_neg_pos] inv_of_one_lt_inv\n\nalias left.one_lt_inv_iff \u2194 _ one_lt_inv_of_inv\nattribute [to_additive neg_pos_of_neg] one_lt_inv_of_inv\n\nalias le_inv_mul_iff_mul_le \u2194 mul_le_of_le_inv_mul _\nattribute [to_additive] mul_le_of_le_inv_mul\n\nalias le_inv_mul_iff_mul_le \u2194 _ le_inv_mul_of_mul_le\nattribute [to_additive] le_inv_mul_of_mul_le\n\nalias inv_mul_le_iff_le_mul \u2194 _ inv_mul_le_of_le_mul\nattribute [to_additive] inv_mul_le_iff_le_mul\n\nalias lt_inv_mul_iff_mul_lt \u2194 mul_lt_of_lt_inv_mul _\nattribute [to_additive] mul_lt_of_lt_inv_mul\n\nalias lt_inv_mul_iff_mul_lt \u2194 _ lt_inv_mul_of_mul_lt\nattribute [to_additive] lt_inv_mul_of_mul_lt\n\nalias inv_mul_lt_iff_lt_mul \u2194 lt_mul_of_inv_mul_lt inv_mul_lt_of_lt_mul\nattribute [to_additive] lt_mul_of_inv_mul_lt\nattribute [to_additive] inv_mul_lt_of_lt_mul\n\nalias lt_mul_of_inv_mul_lt \u2190 lt_mul_of_inv_mul_lt_left\nattribute [to_additive] lt_mul_of_inv_mul_lt_left\n\nalias left.inv_le_one_iff \u2190 inv_le_one'\nattribute [to_additive neg_nonpos] inv_le_one'\n\nalias left.one_le_inv_iff \u2190 one_le_inv'\nattribute [to_additive neg_nonneg] one_le_inv'\n\nalias left.one_lt_inv_iff \u2190 one_lt_inv'\nattribute [to_additive neg_pos] one_lt_inv'\n\nalias mul_lt_mul_left' \u2190 ordered_comm_group.mul_lt_mul_left'\nattribute [to_additive ordered_add_comm_group.add_lt_add_left] ordered_comm_group.mul_lt_mul_left'\n\nalias le_of_mul_le_mul_left' \u2190 ordered_comm_group.le_of_mul_le_mul_left\nattribute [to_additive ordered_add_comm_group.le_of_add_le_add_left]\n  ordered_comm_group.le_of_mul_le_mul_left\n\nalias lt_of_mul_lt_mul_left' \u2190 ordered_comm_group.lt_of_mul_lt_mul_left\nattribute [to_additive ordered_add_comm_group.lt_of_add_lt_add_left]\n  ordered_comm_group.lt_of_mul_lt_mul_left\n\n/-- Pullback an `ordered_comm_group` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible, to_additive function.injective.ordered_add_comm_group\n\"Pullback an `ordered_add_comm_group` under an injective map.\"]\ndef function.injective.ordered_comm_group [ordered_comm_group \u03b1] {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2] [has_inv \u03b2] [has_div \u03b2] [has_pow \u03b2 \u2115] [has_pow \u03b2 \u2124]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9)\n  (div : \u2200 x y, f (x / y) = f x / f y)\n  (npow : \u2200 x (n : \u2115), f (x ^ n) = f x ^ n)\n  (zpow : \u2200 x (n : \u2124), f (x ^ n) = f x ^ n) :\n  ordered_comm_group \u03b2 :=\n{ ..partial_order.lift f hf,\n  ..hf.ordered_comm_monoid f one mul npow,\n  ..hf.comm_group f one mul inv div npow zpow }\n\n/-  Most of the lemmas that are primed in this section appear in ordered_field. -/\n/-  I (DT) did not try to minimise the assumptions. -/\nsection group\nvariables [group \u03b1] [has_le \u03b1]\n\nsection right\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma div_le_div_iff_right (c : \u03b1) : a / c \u2264 b / c \u2194 a \u2264 b :=\nby simpa only [div_eq_mul_inv] using mul_le_mul_iff_right _\n\n@[to_additive sub_le_sub_right]\nlemma div_le_div_right' (h : a \u2264 b) (c : \u03b1) : a / c \u2264 b / c :=\n(div_le_div_iff_right c).2 h\n\n@[simp, to_additive sub_nonneg]\nlemma one_le_div' : 1 \u2264 a / b \u2194 b \u2264 a :=\nby rw [\u2190 mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_nonneg \u2194 le_of_sub_nonneg sub_nonneg_of_le\n\n@[simp, to_additive sub_nonpos]\nlemma div_le_one' : a / b \u2264 1 \u2194 a \u2264 b :=\nby rw [\u2190 mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_nonpos \u2194 le_of_sub_nonpos sub_nonpos_of_le\n\n@[to_additive]\nlemma le_div_iff_mul_le : a \u2264 c / b \u2194 a * b \u2264 c :=\nby rw [\u2190 mul_le_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias le_sub_iff_add_le \u2194 add_le_of_le_sub_right le_sub_right_of_add_le\n\n@[to_additive]\nlemma div_le_iff_le_mul : a / c \u2264 b \u2194 a \u2264 b * c :=\nby rw [\u2190 mul_le_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]\n\n-- TODO: Should we get rid of `sub_le_iff_le_add` in favor of\n-- (a renamed version of) `tsub_le_iff_right`?\n@[priority 100] -- see Note [lower instance priority]\ninstance add_group.to_has_ordered_sub {\u03b1 : Type*} [add_group \u03b1] [has_le \u03b1]\n  [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)] : has_ordered_sub \u03b1 :=\n\u27e8\u03bb a b c, sub_le_iff_le_add\u27e9\n/-- `equiv.mul_right` as an `order_iso`. See also `order_embedding.mul_right`. -/\n@[to_additive \"`equiv.add_right` as an `order_iso`. See also `order_embedding.add_right`.\",\n  simps to_equiv apply {simp_rhs := tt}]\ndef order_iso.mul_right (a : \u03b1) : \u03b1 \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb _ _, mul_le_mul_iff_right a, to_equiv := equiv.mul_right a }\n\n@[simp, to_additive] lemma order_iso.mul_right_symm (a : \u03b1) :\n  (order_iso.mul_right a).symm = order_iso.mul_right a\u207b\u00b9 :=\nby { ext x, refl }\n\nend right\n\nsection left\nvariables [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n\n/-- `equiv.mul_left` as an `order_iso`. See also `order_embedding.mul_left`. -/\n@[to_additive \"`equiv.add_left` as an `order_iso`. See also `order_embedding.add_left`.\",\n  simps to_equiv apply  {simp_rhs := tt}]\ndef order_iso.mul_left (a : \u03b1) : \u03b1 \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb _ _, mul_le_mul_iff_left a, to_equiv := equiv.mul_left a }\n\n@[simp, to_additive] lemma order_iso.mul_left_symm (a : \u03b1) :\n  (order_iso.mul_left a).symm = order_iso.mul_left a\u207b\u00b9 :=\nby { ext x, refl }\n\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b c : \u03b1}\n\n@[simp, to_additive]\nlemma div_le_div_iff_left (a : \u03b1) : a / b \u2264 a / c \u2194 c \u2264 b :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, \u2190 mul_le_mul_iff_left a\u207b\u00b9, inv_mul_cancel_left,\n    inv_mul_cancel_left, inv_le_inv_iff]\n\n@[to_additive sub_le_sub_left]\nlemma div_le_div_left' (h : a \u2264 b) (c : \u03b1) : c / b \u2264 c / a :=\n(div_le_div_iff_left c).2 h\n\nend left\n\nend group\n\nsection comm_group\nvariables [comm_group \u03b1]\n\nsection has_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n@[to_additive sub_le_sub_iff]\nlemma div_le_div_iff' : a / b \u2264 c / d \u2194 a * d \u2264 c * b :=\nby simpa only [div_eq_mul_inv] using mul_inv_le_mul_inv_iff'\n\n@[to_additive]\nlemma le_div_iff_mul_le' : b \u2264 c / a \u2194 a * b \u2264 c :=\nby rw [le_div_iff_mul_le, mul_comm]\n\nalias le_sub_iff_add_le' \u2194 add_le_of_le_sub_left le_sub_left_of_add_le\n\n@[to_additive]\nlemma div_le_iff_le_mul' : a / b \u2264 c \u2194 a \u2264 b * c :=\nby rw [div_le_iff_le_mul, mul_comm]\n\nalias sub_le_iff_le_add' \u2194 le_add_of_sub_left_le sub_left_le_of_le_add\n\n@[simp, to_additive]\nlemma inv_le_div_iff_le_mul : b\u207b\u00b9 \u2264 a / c \u2194 c \u2264 a * b :=\nle_div_iff_mul_le.trans inv_mul_le_iff_le_mul'\n\n@[to_additive]\nlemma inv_le_div_iff_le_mul' : a\u207b\u00b9 \u2264 b / c \u2194 c \u2264 a * b :=\nby rw [inv_le_div_iff_le_mul, mul_comm]\n\n@[to_additive sub_le]\nlemma div_le'' : a / b \u2264 c \u2194 a / c \u2264 b :=\ndiv_le_iff_le_mul'.trans div_le_iff_le_mul.symm\n\n@[to_additive le_sub]\nlemma le_div'' : a \u2264 b / c \u2194 c \u2264 b / a :=\nle_div_iff_mul_le'.trans le_div_iff_mul_le.symm\n\nend has_le\n\nsection preorder\nvariables [preorder \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n@[to_additive sub_le_sub]\nlemma div_le_div'' (hab : a \u2264 b) (hcd : c \u2264 d) :\n  a / d \u2264 b / c :=\nbegin\n  rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_le_inv_mul_iff, mul_comm],\n  exact mul_le_mul' hab hcd\nend\n\nend preorder\n\nend comm_group\n\n/-  Most of the lemmas that are primed in this section appear in ordered_field. -/\n/-  I (DT) did not try to minimise the assumptions. -/\nsection group\nvariables [group \u03b1] [has_lt \u03b1]\n\nsection right\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma div_lt_div_iff_right (c : \u03b1) : a / c < b / c \u2194 a < b :=\nby simpa only [div_eq_mul_inv] using mul_lt_mul_iff_right _\n\n@[to_additive sub_lt_sub_right]\nlemma div_lt_div_right' (h : a < b) (c : \u03b1) : a / c < b / c :=\n(div_lt_div_iff_right c).2 h\n\n@[simp, to_additive sub_pos]\nlemma one_lt_div' : 1 < a / b \u2194 b < a :=\nby rw [\u2190 mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_pos \u2194 lt_of_sub_pos sub_pos_of_lt\n\n@[simp, to_additive sub_neg]\nlemma div_lt_one' : a / b < 1 \u2194 a < b :=\nby rw [\u2190 mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_neg \u2194 lt_of_sub_neg sub_neg_of_lt\n\nalias sub_neg \u2190 sub_lt_zero\n\n@[to_additive]\nlemma lt_div_iff_mul_lt : a < c / b \u2194 a * b < c :=\nby rw [\u2190 mul_lt_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias lt_sub_iff_add_lt \u2194 add_lt_of_lt_sub_right lt_sub_right_of_add_lt\n\n@[to_additive]\nlemma div_lt_iff_lt_mul : a / c < b \u2194 a < b * c :=\nby rw [\u2190 mul_lt_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_lt_iff_lt_add \u2194 lt_add_of_sub_right_lt sub_right_lt_of_lt_add\n\nend right\n\nsection left\nvariables [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b c : \u03b1}\n\n@[simp, to_additive]\nlemma div_lt_div_iff_left (a : \u03b1) : a / b < a / c \u2194 c < b :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, \u2190 mul_lt_mul_iff_left a\u207b\u00b9, inv_mul_cancel_left,\n    inv_mul_cancel_left, inv_lt_inv_iff]\n\n@[simp, to_additive]\nlemma inv_lt_div_iff_lt_mul : a\u207b\u00b9 < b / c \u2194 c < a * b :=\nby rw [div_eq_mul_inv, lt_mul_inv_iff_mul_lt, inv_mul_lt_iff_lt_mul]\n\n@[to_additive sub_lt_sub_left]\nlemma div_lt_div_left' (h : a < b) (c : \u03b1) : c / b < c / a :=\n(div_lt_div_iff_left c).2 h\n\nend left\n\nend group\n\nsection comm_group\nvariables [comm_group \u03b1]\n\nsection has_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c d : \u03b1}\n\n@[to_additive sub_lt_sub_iff]\nlemma div_lt_div_iff' : a / b < c / d \u2194 a * d < c * b :=\nby simpa only [div_eq_mul_inv] using mul_inv_lt_mul_inv_iff'\n\n@[to_additive]\nlemma lt_div_iff_mul_lt' : b < c / a \u2194 a * b < c :=\nby rw [lt_div_iff_mul_lt, mul_comm]\n\nalias lt_sub_iff_add_lt' \u2194 add_lt_of_lt_sub_left lt_sub_left_of_add_lt\n\n@[to_additive]\nlemma div_lt_iff_lt_mul' : a / b < c \u2194 a < b * c :=\nby rw [div_lt_iff_lt_mul, mul_comm]\n\nalias sub_lt_iff_lt_add' \u2194 lt_add_of_sub_left_lt sub_left_lt_of_lt_add\n\n@[to_additive]\nlemma inv_lt_div_iff_lt_mul' : b\u207b\u00b9 < a / c \u2194 c < a * b :=\nlt_div_iff_mul_lt.trans inv_mul_lt_iff_lt_mul'\n\n@[to_additive sub_lt]\nlemma div_lt'' : a / b < c \u2194 a / c < b :=\ndiv_lt_iff_lt_mul'.trans div_lt_iff_lt_mul.symm\n\n@[to_additive lt_sub]\nlemma lt_div'' : a < b / c \u2194 c < b / a :=\nlt_div_iff_mul_lt'.trans lt_div_iff_mul_lt.symm\n\nend has_lt\n\nsection preorder\nvariables [preorder \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c d : \u03b1}\n\n@[to_additive sub_lt_sub]\nlemma div_lt_div'' (hab : a < b) (hcd : c < d) :\n  a / d < b / c :=\nbegin\n  rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_lt_inv_mul_iff, mul_comm],\n  exact mul_lt_mul_of_lt_of_lt hab hcd\nend\n\nend preorder\n\nend comm_group\n\nsection linear_order\nvariables [group \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n\nsection variable_names\nvariables {a b c : \u03b1}\n\n@[to_additive]\nlemma le_of_forall_one_lt_lt_mul (h : \u2200 \u03b5 : \u03b1, 1 < \u03b5 \u2192 a < b * \u03b5) : a \u2264 b :=\nle_of_not_lt (\u03bb h\u2081, lt_irrefl a (by simpa using (h _ (lt_inv_mul_iff_lt.mpr h\u2081))))\n\n@[to_additive]\nlemma le_iff_forall_one_lt_lt_mul : a \u2264 b \u2194 \u2200 \u03b5, 1 < \u03b5 \u2192 a < b * \u03b5 :=\n\u27e8\u03bb h \u03b5, lt_mul_of_le_of_one_lt h, le_of_forall_one_lt_lt_mul\u27e9\n\n/-  I (DT) introduced this lemma to prove (the additive version `sub_le_sub_flip` of)\n`div_le_div_flip` below.  Now I wonder what is the point of either of these lemmas... -/\n@[to_additive]\nlemma div_le_inv_mul_iff [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] :\n  a / b \u2264 a\u207b\u00b9 * b \u2194 a \u2264 b :=\nbegin\n  rw [div_eq_mul_inv, mul_inv_le_inv_mul_iff],\n  exact \u27e8\u03bb h, not_lt.mp (\u03bb k, not_lt.mpr h (mul_lt_mul_of_lt_of_lt k k)), \u03bb h, mul_le_mul' h h\u27e9,\nend\n\n/-  What is the point of this lemma?  See comment about `div_le_inv_mul_iff` above. -/\n@[simp, to_additive]\nlemma div_le_div_flip {\u03b1 : Type*} [comm_group \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1}:\n  a / b \u2264 b / a \u2194 a \u2264 b :=\nbegin\n  rw [div_eq_mul_inv b, mul_comm],\n  exact div_le_inv_mul_iff,\nend\n\n@[simp, to_additive] lemma max_one_div_max_inv_one_eq_self (a : \u03b1) :\n  max a 1 / max a\u207b\u00b9 1 = a :=\nby { rcases le_total a 1 with h|h; simp [h] }\n\nalias max_zero_sub_max_neg_zero_eq_self \u2190 max_zero_sub_eq_self\n\nend variable_names\n\nsection densely_ordered\nvariables [densely_ordered \u03b1] {a b c : \u03b1}\n\n@[to_additive]\nlemma le_of_forall_one_lt_le_mul (h : \u2200 \u03b5 : \u03b1, 1 < \u03b5 \u2192 a \u2264 b * \u03b5) : a \u2264 b :=\nle_of_forall_le_of_dense $ \u03bb c hc,\ncalc a \u2264 b * (b\u207b\u00b9 * c) : h _ (lt_inv_mul_iff_lt.mpr hc)\n   ... = c             : mul_inv_cancel_left b c\n\n@[to_additive]\nlemma le_of_forall_lt_one_mul_le (h : \u2200 \u03b5 < 1, a * \u03b5 \u2264 b) : a \u2264 b :=\n@le_of_forall_one_lt_le_mul \u03b1\u1d52\u1d48 _ _ _ _ _ _ h\n\n@[to_additive]\nlemma le_of_forall_one_lt_div_le (h : \u2200 \u03b5 : \u03b1, 1 < \u03b5 \u2192 a / \u03b5 \u2264 b) : a \u2264 b :=\nle_of_forall_lt_one_mul_le $ \u03bb \u03b5 \u03b51,\n  by simpa only [div_eq_mul_inv, inv_inv]  using h \u03b5\u207b\u00b9 (left.one_lt_inv_iff.2 \u03b51)\n\n@[to_additive]\nlemma le_iff_forall_one_lt_le_mul : a \u2264 b \u2194 \u2200 \u03b5, 1 < \u03b5 \u2192 a \u2264 b * \u03b5 :=\n\u27e8\u03bb h \u03b5 \u03b5_pos, le_mul_of_le_of_one_le h \u03b5_pos.le, le_of_forall_one_lt_le_mul\u27e9\n\n@[to_additive]\nlemma le_iff_forall_lt_one_mul_le : a \u2264 b \u2194 \u2200 \u03b5 < 1, a * \u03b5 \u2264 b :=\n@le_iff_forall_one_lt_le_mul \u03b1\u1d52\u1d48 _ _ _ _ _ _\n\nend densely_ordered\n\nend linear_order\n\n/-!\n### Linearly ordered commutative groups\n-/\n\n/-- A linearly ordered additive commutative group is an\nadditive commutative group with a linear order in which\naddition is monotone. -/\n@[protect_proj, ancestor ordered_add_comm_group linear_order]\nclass linear_ordered_add_comm_group (\u03b1 : Type u) extends ordered_add_comm_group \u03b1, linear_order \u03b1\n\n/-- A linearly ordered commutative monoid with an additively absorbing `\u22a4` element.\n  Instances should include number systems with an infinite element adjoined.` -/\n@[protect_proj, ancestor linear_ordered_add_comm_monoid_with_top sub_neg_monoid nontrivial]\nclass linear_ordered_add_comm_group_with_top (\u03b1 : Type*)\n  extends linear_ordered_add_comm_monoid_with_top \u03b1, sub_neg_monoid \u03b1, nontrivial \u03b1 :=\n(neg_top : - (\u22a4 : \u03b1) = \u22a4)\n(add_neg_cancel : \u2200 a:\u03b1, a \u2260 \u22a4 \u2192 a + (- a) = 0)\n\n/-- A linearly ordered commutative group is a\ncommutative group with a linear order in which\nmultiplication is monotone. -/\n@[protect_proj, ancestor ordered_comm_group linear_order, to_additive]\nclass linear_ordered_comm_group (\u03b1 : Type u) extends ordered_comm_group \u03b1, linear_order \u03b1\n\n@[to_additive] instance [linear_ordered_comm_group \u03b1] :\n  linear_ordered_comm_group \u03b1\u1d52\u1d48 :=\n{ .. order_dual.ordered_comm_group, .. order_dual.linear_order \u03b1 }\n\nsection linear_ordered_comm_group\nvariables [linear_ordered_comm_group \u03b1] {a b c : \u03b1}\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_linear_ordered_cancel_comm_monoid :\n  linear_ordered_cancel_comm_monoid \u03b1 :=\n{ le_of_mul_le_mul_left := \u03bb x y z, le_of_mul_le_mul_left',\n  mul_left_cancel := \u03bb x y z, mul_left_cancel,\n  ..\u2039linear_ordered_comm_group \u03b1\u203a }\n\n/-- Pullback a `linear_ordered_comm_group` under an injective map.\nSee note [reducible non-instances]. -/\n@[reducible, to_additive function.injective.linear_ordered_add_comm_group\n\"Pullback a `linear_ordered_add_comm_group` under an injective map.\"]\ndef function.injective.linear_ordered_comm_group {\u03b2 : Type*}\n  [has_one \u03b2] [has_mul \u03b2] [has_inv \u03b2] [has_div \u03b2] [has_pow \u03b2 \u2115] [has_pow \u03b2 \u2124]\n  (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n  (mul : \u2200 x y, f (x * y) = f x * f y)\n  (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9)\n  (div : \u2200 x y, f (x / y) = f x / f y)\n  (npow : \u2200 x (n : \u2115), f (x ^ n) = f x ^ n)\n  (zpow : \u2200 x (n : \u2124), f (x ^ n) = f x ^ n) :\n  linear_ordered_comm_group \u03b2 :=\n{ ..linear_order.lift f hf,\n  ..hf.ordered_comm_group f one mul inv div npow zpow }\n\n@[to_additive linear_ordered_add_comm_group.add_lt_add_left]\nlemma linear_ordered_comm_group.mul_lt_mul_left'\n  (a b : \u03b1) (h : a < b) (c : \u03b1) : c * a < c * b :=\nmul_lt_mul_left' h c\n\n@[to_additive min_neg_neg]\nlemma min_inv_inv' (a b : \u03b1) : min (a\u207b\u00b9) (b\u207b\u00b9) = (max a b)\u207b\u00b9 :=\neq.symm $ @monotone.map_max \u03b1 \u03b1\u1d52\u1d48 _ _ has_inv.inv a b $ \u03bb a b, inv_le_inv_iff.mpr\n\n@[to_additive max_neg_neg]\nlemma max_inv_inv' (a b : \u03b1) : max (a\u207b\u00b9) (b\u207b\u00b9) = (min a b)\u207b\u00b9 :=\neq.symm $ @monotone.map_min \u03b1 \u03b1\u1d52\u1d48 _ _ has_inv.inv a b $ \u03bb a b, inv_le_inv_iff.mpr\n\n@[to_additive min_sub_sub_right]\nlemma min_div_div_right' (a b c : \u03b1) : min (a / c) (b / c) = min a b / c :=\nby simpa only [div_eq_mul_inv] using min_mul_mul_right a b (c\u207b\u00b9)\n\n@[to_additive max_sub_sub_right]\nlemma max_div_div_right' (a b c : \u03b1) : max (a / c) (b / c) = max a b / c :=\nby simpa only [div_eq_mul_inv] using max_mul_mul_right a b (c\u207b\u00b9)\n\n@[to_additive min_sub_sub_left]\nlemma min_div_div_left' (a b c : \u03b1) : min (a / b) (a / c) = a / max b c :=\nby simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv']\n\n@[to_additive max_sub_sub_left]\nlemma max_div_div_left' (a b c : \u03b1) : max (a / b) (a / c) = a / min b c :=\nby simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']\n\n@[to_additive eq_zero_of_neg_eq]\nlemma eq_one_of_inv_eq' (h : a\u207b\u00b9 = a) : a = 1 :=\nmatch lt_trichotomy a 1 with\n| or.inl h\u2081 :=\n  have 1 < a, from h \u25b8 one_lt_inv_of_inv h\u2081,\n  absurd h\u2081 this.asymm\n| or.inr (or.inl h\u2081) := h\u2081\n| or.inr (or.inr h\u2081) :=\n  have a < 1, from h \u25b8 inv_lt_one'.mpr h\u2081,\n  absurd h\u2081 this.asymm\nend\n\n@[to_additive exists_zero_lt]\nlemma exists_one_lt' [nontrivial \u03b1] : \u2203 (a:\u03b1), 1 < a :=\nbegin\n  obtain \u27e8y, hy\u27e9 := decidable.exists_ne (1 : \u03b1),\n  cases hy.lt_or_lt,\n  { exact \u27e8y\u207b\u00b9, one_lt_inv'.mpr h\u27e9 },\n  { exact \u27e8y, h\u27e9 }\nend\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_no_max_order [nontrivial \u03b1] :\n  no_max_order \u03b1 :=\n\u27e8 begin\n    obtain \u27e8y, hy\u27e9 : \u2203 (a:\u03b1), 1 < a := exists_one_lt',\n    exact \u03bb a, \u27e8a * y, lt_mul_of_one_lt_right' a hy\u27e9\n  end \u27e9\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_no_min_order [nontrivial \u03b1] : no_min_order \u03b1 :=\n\u27e8 begin\n    obtain \u27e8y, hy\u27e9 : \u2203 (a:\u03b1), 1 < a := exists_one_lt',\n    exact \u03bb a, \u27e8a / y, (div_lt_self_iff a).mpr hy\u27e9\n  end \u27e9\n\nend linear_ordered_comm_group\n\nsection covariant_add_le\n\nsection has_neg\n\n/-- `abs a` is the absolute value of `a`. -/\n@[to_additive \"`abs a` is the absolute value of `a`\",\n  priority 100] -- see Note [lower instance priority]\ninstance has_inv.to_has_abs [has_inv \u03b1] [has_sup \u03b1] : has_abs \u03b1 := \u27e8\u03bb a, a \u2294 a\u207b\u00b9\u27e9\n\n@[to_additive] lemma abs_eq_sup_inv [has_inv \u03b1] [has_sup \u03b1] (a : \u03b1) : |a| = a \u2294 a\u207b\u00b9 := rfl\n\nvariables [has_neg \u03b1] [linear_order \u03b1] {a b: \u03b1}\n\nlemma abs_eq_max_neg : abs a = max a (-a) :=\nrfl\n\nlemma abs_choice (x : \u03b1) : |x| = x \u2228 |x| = -x := max_choice _ _\n\nlemma abs_le' : |a| \u2264 b \u2194 a \u2264 b \u2227 -a \u2264 b := max_le_iff\n\nlemma le_abs : a \u2264 |b| \u2194 a \u2264 b \u2228 a \u2264 -b := le_max_iff\n\nlemma le_abs_self (a : \u03b1) : a \u2264 |a| := le_max_left _ _\n\nlemma neg_le_abs_self (a : \u03b1) : -a \u2264 |a| := le_max_right _ _\n\nlemma lt_abs : a < |b| \u2194 a < b \u2228 a < -b := lt_max_iff\n\ntheorem abs_le_abs (h\u2080 : a \u2264 b) (h\u2081 : -a \u2264 b) : |a| \u2264 |b| :=\n(abs_le'.2 \u27e8h\u2080, h\u2081\u27e9).trans (le_abs_self b)\n\nlemma abs_by_cases (P : \u03b1 \u2192 Prop) {a : \u03b1} (h1 : P a) (h2 : P (-a)) : P (|a|) :=\nsup_ind _ _ h1 h2\n\nend has_neg\n\nsection add_group\nvariables [add_group \u03b1] [linear_order \u03b1]\n\n@[simp] lemma abs_neg (a : \u03b1) : | -a| = |a| :=\nbegin\n  rw [abs_eq_max_neg, max_comm, neg_neg, abs_eq_max_neg]\nend\n\nlemma eq_or_eq_neg_of_abs_eq {a b : \u03b1} (h : |a| = b) : a = b \u2228 a = -b :=\nby simpa only [\u2190 h, eq_comm, eq_neg_iff_eq_neg] using abs_choice a\n\nlemma abs_eq_abs {a b : \u03b1} : |a| = |b| \u2194 a = b \u2228 a = -b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { obtain rfl | rfl := eq_or_eq_neg_of_abs_eq h;\n    simpa only [neg_eq_iff_neg_eq, neg_inj, or.comm, @eq_comm _ (-b)] using abs_choice b },\n  { cases h; simp only [h, abs_neg] },\nend\n\nlemma abs_sub_comm (a b : \u03b1) : |a - b| = |b - a| :=\ncalc  |a - b| = | - (b - a)| : congr_arg _ (neg_sub b a).symm\n          ... = |b - a|      : abs_neg (b - a)\n\nvariables [covariant_class \u03b1 \u03b1 (+) (\u2264)] {a b c : \u03b1}\n\nlemma abs_of_nonneg (h : 0 \u2264 a) : |a| = a :=\nmax_eq_left $ (neg_nonpos.2 h).trans h\n\nlemma abs_of_pos (h : 0 < a) : |a| = a :=\nabs_of_nonneg h.le\n\nlemma abs_of_nonpos (h : a \u2264 0) : |a| = -a :=\nmax_eq_right $ h.trans (neg_nonneg.2 h)\n\nlemma abs_of_neg (h : a < 0) : |a| = -a :=\nabs_of_nonpos h.le\n\n@[simp] lemma abs_zero : |0| = (0:\u03b1) :=\nabs_of_nonneg le_rfl\n\n@[simp] lemma abs_pos : 0 < |a| \u2194 a \u2260 0 :=\nbegin\n  rcases lt_trichotomy a 0 with (ha|rfl|ha),\n  { simp [abs_of_neg ha, neg_pos, ha.ne, ha] },\n  { simp },\n  { simp [abs_of_pos ha, ha, ha.ne.symm] }\nend\n\nlemma abs_pos_of_pos (h : 0 < a) : 0 < |a| := abs_pos.2 h.ne.symm\n\nlemma abs_pos_of_neg (h : a < 0) : 0 < |a| := abs_pos.2 h.ne\n\nlemma neg_abs_le_self (a : \u03b1) : -|a| \u2264 a :=\nbegin\n  cases le_total 0 a with h h,\n  { calc -|a| = - a   : congr_arg (has_neg.neg) (abs_of_nonneg h)\n            ... \u2264 0     : neg_nonpos.mpr h\n            ... \u2264 a     : h },\n  { calc -|a| = - - a : congr_arg (has_neg.neg) (abs_of_nonpos h)\n            ... \u2264 a     : (neg_neg a).le }\nend\n\nlemma add_abs_nonneg (a : \u03b1) : 0 \u2264 a + |a| :=\nbegin\n  rw \u2190add_right_neg a,\n  apply add_le_add_left,\n  exact (neg_le_abs_self a),\nend\n\nlemma neg_abs_le_neg (a : \u03b1) : -|a| \u2264 -a :=\nby simpa using neg_abs_le_self (-a)\n\nlemma abs_nonneg (a : \u03b1) : 0 \u2264 |a| :=\n(le_total 0 a).elim (\u03bb h, h.trans (le_abs_self a)) (\u03bb h, (neg_nonneg.2 h).trans $ neg_le_abs_self a)\n\n@[simp] lemma abs_abs (a : \u03b1) : | |a| | = |a| :=\nabs_of_nonneg $ abs_nonneg a\n\n@[simp] lemma abs_eq_zero : |a| = 0 \u2194 a = 0 :=\ndecidable.not_iff_not.1 $ ne_comm.trans $ (abs_nonneg a).lt_iff_ne.symm.trans abs_pos\n\n@[simp] lemma abs_nonpos_iff {a : \u03b1} : |a| \u2264 0 \u2194 a = 0 :=\n(abs_nonneg a).le_iff_eq.trans abs_eq_zero\n\nvariable [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n\nlemma abs_lt : |a| < b \u2194 - b < a \u2227 a < b :=\nmax_lt_iff.trans $ and.comm.trans $ by rw [neg_lt]\n\nlemma neg_lt_of_abs_lt (h : |a| < b) : -b < a := (abs_lt.mp h).1\n\nlemma lt_of_abs_lt (h : |a| < b) : a < b := (abs_lt.mp h).2\n\nlemma max_sub_min_eq_abs' (a b : \u03b1) : max a b - min a b = |a - b| :=\nbegin\n  cases le_total a b with ab ba,\n  { rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub], rwa sub_nonpos },\n  { rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg], rwa sub_nonneg }\nend\n\nlemma max_sub_min_eq_abs (a b : \u03b1) : max a b - min a b = |b - a| :=\nby { rw abs_sub_comm, exact max_sub_min_eq_abs' _ _ }\n\nend add_group\n\nend covariant_add_le\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1] {a b c d : \u03b1}\n\nlemma abs_le : |a| \u2264 b \u2194 - b \u2264 a \u2227 a \u2264 b := by rw [abs_le', and.comm, neg_le]\n\nlemma le_abs' : a \u2264 |b| \u2194 b \u2264 -a \u2228 a \u2264 b := by rw [le_abs, or.comm, le_neg]\n\nlemma neg_le_of_abs_le (h : |a| \u2264 b) : -b \u2264 a := (abs_le.mp h).1\n\nlemma le_of_abs_le (h : |a| \u2264 b) : a \u2264 b := (abs_le.mp h).2\n\n@[to_additive] lemma apply_abs_le_mul_of_one_le' {\u03b2 : Type*} [mul_one_class \u03b2] [preorder \u03b2]\n  [covariant_class \u03b2 \u03b2 (*) (\u2264)] [covariant_class \u03b2 \u03b2 (swap (*)) (\u2264)] {f : \u03b1 \u2192 \u03b2} {a : \u03b1}\n  (h\u2081 : 1 \u2264 f a) (h\u2082 : 1 \u2264 f (-a)) :\n  f (|a|) \u2264 f a * f (-a) :=\n(le_total a 0).by_cases (\u03bb ha, (abs_of_nonpos ha).symm \u25b8 le_mul_of_one_le_left' h\u2081)\n  (\u03bb ha, (abs_of_nonneg ha).symm \u25b8 le_mul_of_one_le_right' h\u2082)\n\n@[to_additive] lemma apply_abs_le_mul_of_one_le {\u03b2 : Type*} [mul_one_class \u03b2] [preorder \u03b2]\n  [covariant_class \u03b2 \u03b2 (*) (\u2264)] [covariant_class \u03b2 \u03b2 (swap (*)) (\u2264)] {f : \u03b1 \u2192 \u03b2}\n  (h : \u2200 x, 1 \u2264 f x) (a : \u03b1) :\n  f (|a|) \u2264 f a * f (-a) :=\napply_abs_le_mul_of_one_le' (h _) (h _)\n\n/--\nThe **triangle inequality** in `linear_ordered_add_comm_group`s.\n-/\nlemma abs_add (a b : \u03b1) : |a + b| \u2264 |a| + |b| :=\nabs_le.2 \u27e8(neg_add (|a|) (|b|)).symm \u25b8\n  add_le_add (neg_le.2 $ neg_le_abs_self _) (neg_le.2 $ neg_le_abs_self _),\n  add_le_add (le_abs_self _) (le_abs_self _)\u27e9\n\nlemma abs_add' (a b : \u03b1) : |a| \u2264 |b| + |b + a| :=\nby simpa using abs_add (-b) (b + a)\n\ntheorem abs_sub (a b : \u03b1) :\n  |a - b| \u2264 |a| + |b| :=\nby { rw [sub_eq_add_neg, \u2190abs_neg b], exact abs_add a _ }\n\nlemma abs_sub_le_iff : |a - b| \u2264 c \u2194 a - b \u2264 c \u2227 b - a \u2264 c :=\nby rw [abs_le, neg_le_sub_iff_le_add, sub_le_iff_le_add', and_comm, sub_le_iff_le_add']\n\nlemma abs_sub_lt_iff : |a - b| < c \u2194 a - b < c \u2227 b - a < c :=\nby rw [abs_lt, neg_lt_sub_iff_lt_add', sub_lt_iff_lt_add', and_comm, sub_lt_iff_lt_add']\n\nlemma sub_le_of_abs_sub_le_left (h : |a - b| \u2264 c) : b - c \u2264 a :=\nsub_le.1 $ (abs_sub_le_iff.1 h).2\n\nlemma sub_le_of_abs_sub_le_right (h : |a - b| \u2264 c) : a - c \u2264 b :=\nsub_le_of_abs_sub_le_left (abs_sub_comm a b \u25b8 h)\n\nlemma sub_lt_of_abs_sub_lt_left (h : |a - b| < c) : b - c < a :=\nsub_lt.1 $ (abs_sub_lt_iff.1 h).2\n\nlemma sub_lt_of_abs_sub_lt_right (h : |a - b| < c) : a - c < b :=\nsub_lt_of_abs_sub_lt_left (abs_sub_comm a b \u25b8 h)\n\nlemma abs_sub_abs_le_abs_sub (a b : \u03b1) : |a| - |b| \u2264 |a - b| :=\nsub_le_iff_le_add.2 $\ncalc |a| = |a - b + b|     : by rw [sub_add_cancel]\n       ... \u2264 |a - b| + |b| : abs_add _ _\n\nlemma abs_abs_sub_abs_le_abs_sub (a b : \u03b1) : | |a| - |b| | \u2264 |a - b| :=\nabs_sub_le_iff.2 \u27e8abs_sub_abs_le_abs_sub _ _, by rw abs_sub_comm; apply abs_sub_abs_le_abs_sub\u27e9\n\nlemma abs_eq (hb : 0 \u2264 b) : |a| = b \u2194 a = b \u2228 a = -b :=\nbegin\n  refine \u27e8eq_or_eq_neg_of_abs_eq, _\u27e9,\n  rintro (rfl|rfl); simp only [abs_neg, abs_of_nonneg hb]\nend\n\nlemma abs_le_max_abs_abs (hab : a \u2264 b)  (hbc : b \u2264 c) : |b| \u2264 max (|a|) (|c|) :=\nabs_le'.2\n  \u27e8by simp [hbc.trans (le_abs_self c)],\n   by simp [(neg_le_neg_iff.mpr hab).trans (neg_le_abs_self a)]\u27e9\n\nlemma eq_of_abs_sub_eq_zero {a b : \u03b1} (h : |a - b| = 0) : a = b :=\nsub_eq_zero.1 $ abs_eq_zero.1 h\n\nlemma abs_sub_le (a b c : \u03b1) : |a - c| \u2264 |a - b| + |b - c| :=\ncalc\n    |a - c| = |a - b + (b - c)|     : by rw [sub_add_sub_cancel]\n            ... \u2264 |a - b| + |b - c| : abs_add _ _\n\nlemma abs_add_three (a b c : \u03b1) : |a + b + c| \u2264 |a| + |b| + |c| :=\n(abs_add _ _).trans (add_le_add_right (abs_add _ _) _)\n\nlemma dist_bdd_within_interval {a b lb ub : \u03b1} (hal : lb \u2264 a) (hau : a \u2264 ub)\n      (hbl : lb \u2264 b) (hbu : b \u2264 ub) : |a - b| \u2264 ub - lb :=\nabs_sub_le_iff.2 \u27e8sub_le_sub hau hbl, sub_le_sub hbu hal\u27e9\n\nlemma eq_of_abs_sub_nonpos (h : |a - b| \u2264 0) : a = b :=\neq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b)))\n\nlemma max_sub_max_le_max (a b c d : \u03b1) : max a b - max c d \u2264 max (a - c) (b - d) :=\nbegin\n  simp only [sub_le_iff_le_add, max_le_iff], split,\n  calc a = a - c + c : (sub_add_cancel a c).symm\n  ... \u2264 max (a - c) (b - d) + max c d : add_le_add (le_max_left _ _) (le_max_left _ _),\n  calc b = b - d + d : (sub_add_cancel b d).symm\n  ... \u2264 max (a - c) (b - d) + max c d : add_le_add (le_max_right _ _) (le_max_right _ _)\nend\n\nlemma abs_max_sub_max_le_max (a b c d : \u03b1) : |max a b - max c d| \u2264 max (|a - c|) (|b - d|) :=\nbegin\n  refine abs_sub_le_iff.2 \u27e8_, _\u27e9,\n  { exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _)) },\n  { rw [abs_sub_comm a c, abs_sub_comm b d],\n    exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _)) }\nend\n\nlemma abs_min_sub_min_le_max (a b c d : \u03b1) : |min a b - min c d| \u2264 max (|a - c|) (|b - d|) :=\nby simpa only [max_neg_neg, neg_sub_neg, abs_sub_comm]\n  using abs_max_sub_max_le_max (-a) (-b) (-c) (-d)\n\nlemma abs_max_sub_max_le_abs (a b c : \u03b1) : |max a c - max b c| \u2264 |a - b| :=\nby simpa only [sub_self, abs_zero, max_eq_left (abs_nonneg _)]\n  using abs_max_sub_max_le_max a c b c\n\ninstance with_top.linear_ordered_add_comm_group_with_top :\n  linear_ordered_add_comm_group_with_top (with_top \u03b1) :=\n{ neg            := option.map (\u03bb a : \u03b1, -a),\n  neg_top        := @option.map_none _ _ (\u03bb a : \u03b1, -a),\n  add_neg_cancel := begin\n    rintro (a | a) ha,\n    { exact (ha rfl).elim },\n    { exact with_top.coe_add.symm.trans (with_top.coe_eq_coe.2 (add_neg_self a)) }\n  end,\n  .. with_top.linear_ordered_add_comm_monoid_with_top,\n  .. option.nontrivial }\n\n@[simp, norm_cast]\nlemma with_top.coe_neg (a : \u03b1) : ((-a : \u03b1) : with_top \u03b1) = -a := rfl\n\nend linear_ordered_add_comm_group\n\nnamespace add_comm_group\n\n/-- A collection of elements in an `add_comm_group` designated as \"non-negative\".\nThis is useful for constructing an `ordered_add_commm_group`\nby choosing a positive cone in an exisiting `add_comm_group`. -/\n@[nolint has_inhabited_instance]\nstructure positive_cone (\u03b1 : Type*) [add_comm_group \u03b1] :=\n(nonneg          : \u03b1 \u2192 Prop)\n(pos             : \u03b1 \u2192 Prop := \u03bb a, nonneg a \u2227 \u00ac nonneg (-a))\n(pos_iff         : \u2200 a, pos a \u2194 nonneg a \u2227 \u00ac nonneg (-a) . order_laws_tac)\n(zero_nonneg     : nonneg 0)\n(add_nonneg      : \u2200 {a b}, nonneg a \u2192 nonneg b \u2192 nonneg (a + b))\n(nonneg_antisymm : \u2200 {a}, nonneg a \u2192 nonneg (-a) \u2192 a = 0)\n\n/-- A positive cone in an `add_comm_group` induces a linear order if\nfor every `a`, either `a` or `-a` is non-negative. -/\n@[nolint has_inhabited_instance]\nstructure total_positive_cone (\u03b1 : Type*) [add_comm_group \u03b1] extends positive_cone \u03b1 :=\n(nonneg_decidable : decidable_pred nonneg)\n(nonneg_total : \u2200 a : \u03b1, nonneg a \u2228 nonneg (-a))\n\n/-- Forget that a `total_positive_cone` is total. -/\nadd_decl_doc total_positive_cone.to_positive_cone\n\nend add_comm_group\n\nnamespace ordered_add_comm_group\n\nopen add_comm_group\n\n/-- Construct an `ordered_add_comm_group` by\ndesignating a positive cone in an existing `add_comm_group`. -/\ndef mk_of_positive_cone {\u03b1 : Type*} [add_comm_group \u03b1] (C : positive_cone \u03b1) :\n  ordered_add_comm_group \u03b1 :=\n{ le               := \u03bb a b, C.nonneg (b - a),\n  lt               := \u03bb a b, C.pos (b - a),\n  lt_iff_le_not_le := \u03bb a b, by simp; rw [C.pos_iff]; simp,\n  le_refl          := \u03bb a, by simp [C.zero_nonneg],\n  le_trans         := \u03bb a b c nab nbc, by simp [-sub_eq_add_neg];\n    rw \u2190 sub_add_sub_cancel; exact C.add_nonneg nbc nab,\n  le_antisymm      := \u03bb a b nab nba, eq_of_sub_eq_zero $\n    C.nonneg_antisymm nba (by rw neg_sub; exact nab),\n  add_le_add_left  := \u03bb a b nab c, by simpa [(\u2264), preorder.le] using nab,\n  ..\u2039add_comm_group \u03b1\u203a }\n\nend ordered_add_comm_group\n\nnamespace linear_ordered_add_comm_group\n\nopen add_comm_group\n\n/-- Construct a `linear_ordered_add_comm_group` by\ndesignating a positive cone in an existing `add_comm_group`\nsuch that for every `a`, either `a` or `-a` is non-negative. -/\ndef mk_of_positive_cone {\u03b1 : Type*} [add_comm_group \u03b1] (C : total_positive_cone \u03b1) :\n  linear_ordered_add_comm_group \u03b1 :=\n{ le_total := \u03bb a b, by { convert C.nonneg_total (b - a), change C.nonneg _ = _, congr, simp, },\n  decidable_le := \u03bb a b, C.nonneg_decidable _,\n  ..ordered_add_comm_group.mk_of_positive_cone C.to_positive_cone }\n\nend linear_ordered_add_comm_group\n\nnamespace prod\n\nvariables {G H : Type*}\n\n@[to_additive]\ninstance [ordered_comm_group G] [ordered_comm_group H] :\n  ordered_comm_group (G \u00d7 H) :=\n{ .. prod.comm_group, .. prod.partial_order G H, .. prod.ordered_cancel_comm_monoid }\n\nend prod\n\nsection type_tags\n\ninstance [ordered_add_comm_group \u03b1] : ordered_comm_group (multiplicative \u03b1) :=\n{ ..multiplicative.comm_group,\n  ..multiplicative.ordered_comm_monoid }\n\ninstance [ordered_comm_group \u03b1] : ordered_add_comm_group (additive \u03b1) :=\n{ ..additive.add_comm_group,\n  ..additive.ordered_add_comm_monoid }\n\ninstance [linear_ordered_add_comm_group \u03b1] : linear_ordered_comm_group (multiplicative \u03b1) :=\n{ ..multiplicative.linear_order,\n  ..multiplicative.ordered_comm_group }\n\ninstance [linear_ordered_comm_group \u03b1] : linear_ordered_add_comm_group (additive \u03b1) :=\n{ ..additive.linear_order,\n  ..additive.ordered_add_comm_group }\n\nend type_tags\n\nsection norm_num_lemmas\n/- The following lemmas are stated so that the `norm_num` tactic can use them with the\nexpected signatures.  -/\nvariables [ordered_comm_group \u03b1] {a b : \u03b1}\n\n@[to_additive neg_le_neg]\nlemma inv_le_inv' : a \u2264 b \u2192 b\u207b\u00b9 \u2264 a\u207b\u00b9 :=\ninv_le_inv_iff.mpr\n\n@[to_additive neg_lt_neg]\nlemma inv_lt_inv' : a < b \u2192 b\u207b\u00b9 < a\u207b\u00b9 :=\ninv_lt_inv_iff.mpr\n\n/-  The additive version is also a `linarith` lemma. -/\n@[to_additive]\ntheorem inv_lt_one_of_one_lt : 1 < a \u2192 a\u207b\u00b9 < 1 :=\ninv_lt_one_iff_one_lt.mpr\n\n/-  The additive version is also a `linarith` lemma. -/\n@[to_additive]\nlemma inv_le_one_of_one_le : 1 \u2264 a \u2192 a\u207b\u00b9 \u2264 1 :=\ninv_le_one'.mpr\n\n@[to_additive neg_nonneg_of_nonpos]\nlemma one_le_inv_of_le_one :  a \u2264 1 \u2192 1 \u2264 a\u207b\u00b9 :=\none_le_inv'.mpr\n\nend norm_num_lemmas\n\nsection\n\nvariables {\u03b2 : Type*}\n[group \u03b1] [preorder \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n[preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b2}\n\n@[to_additive] lemma monotone.inv (hf : monotone f) : antitone (\u03bb x, (f x)\u207b\u00b9) :=\n\u03bb x y hxy, inv_le_inv_iff.2 (hf hxy)\n\n@[to_additive] lemma antitone.inv (hf : antitone f) : monotone (\u03bb x, (f x)\u207b\u00b9) :=\n\u03bb x y hxy, inv_le_inv_iff.2 (hf hxy)\n\n@[to_additive] lemma monotone_on.inv (hf : monotone_on f s) :\n  antitone_on (\u03bb x, (f x)\u207b\u00b9) s :=\n\u03bb x hx y hy hxy, inv_le_inv_iff.2 (hf hx hy hxy)\n\n@[to_additive] lemma antitone_on.inv (hf : antitone_on f s) :\n  monotone_on (\u03bb x, (f x)\u207b\u00b9) s :=\n\u03bb x hx y hy hxy, inv_le_inv_iff.2 (hf hx hy hxy)\n\nend\n\nsection\n\nvariables {\u03b2 : Type*}\n[group \u03b1] [preorder \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n[preorder \u03b2] {f : \u03b2 \u2192 \u03b1} {s : set \u03b2}\n\n@[to_additive] lemma strict_mono.inv (hf : strict_mono f) : strict_anti (\u03bb x, (f x)\u207b\u00b9) :=\n\u03bb x y hxy, inv_lt_inv_iff.2 (hf hxy)\n\n@[to_additive] lemma strict_anti.inv (hf : strict_anti f) : strict_mono (\u03bb x, (f x)\u207b\u00b9) :=\n\u03bb x y hxy, inv_lt_inv_iff.2 (hf hxy)\n\n@[to_additive] lemma strict_mono_on.inv (hf : strict_mono_on f s) :\n  strict_anti_on (\u03bb x, (f x)\u207b\u00b9) s :=\n\u03bb x hx y hy hxy, inv_lt_inv_iff.2 (hf hx hy hxy)\n\n@[to_additive] lemma strict_anti_on.inv (hf : strict_anti_on f s) :\n  strict_mono_on (\u03bb x, (f x)\u207b\u00b9) s :=\n\u03bb x hx y hy hxy, inv_lt_inv_iff.2 (hf hx hy hxy)\n\nend\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/order/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522813, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7062408802226618}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\n-/\nimport data.set.function\nimport logic.equiv.defs\n\n/-!\n# Equivalences and sets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we provide lemmas linking equivalences to sets.\n\nSome notable definitions are:\n\n* `equiv.of_injective`: an injective function is (noncomputably) equivalent to its range.\n* `equiv.set_congr`: two equal sets are equivalent as types.\n* `equiv.set.union`: a disjoint union of sets is equivalent to their `sum`.\n\nThis file is separate from `equiv/basic` such that we do not require the full lattice structure\non sets before defining what an equivalence is.\n-/\n\nopen function set\n\nuniverses u v w z\nvariables {\u03b1 : Sort u} {\u03b2 : Sort v} {\u03b3 : Sort w}\n\nnamespace equiv\n\n@[simp] lemma range_eq_univ {\u03b1 : Type*} {\u03b2 : Type*} (e : \u03b1 \u2243 \u03b2) : range e = univ :=\neq_univ_of_forall e.surjective\n\nprotected lemma image_eq_preimage {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) : e '' s = e.symm \u207b\u00b9' s :=\nset.ext $ \u03bb x, mem_image_iff_of_inverse e.left_inv e.right_inv\n\nlemma _root_.set.mem_image_equiv {\u03b1 \u03b2} {S : set \u03b1} {f : \u03b1 \u2243 \u03b2} {x : \u03b2} :\n  x \u2208 f '' S \u2194 f.symm x \u2208 S :=\nset.ext_iff.mp (f.image_eq_preimage S) x\n\n/-- Alias for `equiv.image_eq_preimage` -/\nlemma _root_.set.image_equiv_eq_preimage_symm {\u03b1 \u03b2} (S : set \u03b1) (f : \u03b1 \u2243 \u03b2) :\n  f '' S = f.symm \u207b\u00b9' S :=\nf.image_eq_preimage S\n\n/-- Alias for `equiv.image_eq_preimage` -/\nlemma _root_.set.preimage_equiv_eq_image_symm {\u03b1 \u03b2} (S : set \u03b1) (f : \u03b2 \u2243 \u03b1) :\n  f \u207b\u00b9' S = f.symm '' S :=\n(f.symm.image_eq_preimage S).symm\n\n@[simp] protected lemma subset_image {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) (t : set \u03b2) :\n  e.symm '' t \u2286 s \u2194 t \u2286 e '' s :=\nby rw [image_subset_iff, e.image_eq_preimage]\n\n@[simp] protected lemma subset_image' {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) (t : set \u03b2) :\n  s \u2286 e.symm '' t \u2194 e '' s \u2286 t :=\ncalc s \u2286 e.symm '' t \u2194 e.symm.symm '' s \u2286 t : by rw e.symm.subset_image\n                 ... \u2194 e '' s \u2286 t : by rw e.symm_symm\n\n@[simp] lemma symm_image_image {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) : e.symm '' (e '' s) = s :=\ne.left_inverse_symm.image_image s\n\nlemma eq_image_iff_symm_image_eq {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) (t : set \u03b2) :\n  t = e '' s \u2194 e.symm '' t = s :=\n(e.symm.injective.image_injective.eq_iff' (e.symm_image_image s)).symm\n\n@[simp] lemma image_symm_image {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b2) : e '' (e.symm '' s) = s :=\ne.symm.symm_image_image s\n\n@[simp] lemma image_preimage {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b2) : e '' (e \u207b\u00b9' s) = s :=\ne.surjective.image_preimage s\n\n@[simp] lemma preimage_image {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) : e \u207b\u00b9' (e '' s) = s :=\ne.injective.preimage_image s\n\nprotected lemma image_compl {\u03b1 \u03b2} (f : equiv \u03b1 \u03b2) (s : set \u03b1) :\n  f '' s\u1d9c = (f '' s)\u1d9c :=\nimage_compl_eq f.bijective\n\n@[simp] lemma symm_preimage_preimage {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b2) :\n  e.symm \u207b\u00b9' (e \u207b\u00b9' s) = s :=\ne.right_inverse_symm.preimage_preimage s\n\n@[simp] lemma preimage_symm_preimage {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) :\n  e \u207b\u00b9' (e.symm \u207b\u00b9' s) = s :=\ne.left_inverse_symm.preimage_preimage s\n\n@[simp] \n\n@[simp] lemma image_subset {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s t : set \u03b1) : e '' s \u2286 e '' t \u2194 s \u2286 t :=\nimage_subset_image_iff e.injective\n\n@[simp] lemma image_eq_iff_eq {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s t : set \u03b1) : e '' s = e '' t \u2194 s = t :=\nimage_eq_image e.injective\n\nlemma preimage_eq_iff_eq_image {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s t) : e \u207b\u00b9' s = t \u2194 s = e '' t :=\npreimage_eq_iff_eq_image e.bijective\n\nlemma eq_preimage_iff_image_eq {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) (s t) : s = e \u207b\u00b9' t \u2194 e '' s = t :=\neq_preimage_iff_image_eq e.bijective\n\n@[simp]\nlemma prod_assoc_preimage {\u03b1 \u03b2 \u03b3} {s : set \u03b1} {t : set \u03b2} {u : set \u03b3} :\n  equiv.prod_assoc \u03b1 \u03b2 \u03b3 \u207b\u00b9' s \u00d7\u02e2 (t \u00d7\u02e2 u) = (s \u00d7\u02e2 t) \u00d7\u02e2 u :=\nby { ext, simp [and_assoc] }\n\n@[simp]\nlemma prod_assoc_symm_preimage {\u03b1 \u03b2 \u03b3} {s : set \u03b1} {t : set \u03b2} {u : set \u03b3} :\n  (equiv.prod_assoc \u03b1 \u03b2 \u03b3).symm \u207b\u00b9' (s \u00d7\u02e2 t) \u00d7\u02e2 u = s \u00d7\u02e2 (t \u00d7\u02e2 u) :=\nby { ext, simp [and_assoc] }\n\n-- `@[simp]` doesn't like these lemmas, as it uses `set.image_congr'` to turn `equiv.prod_assoc`\n-- into a lambda expression and then unfold it.\n\nlemma prod_assoc_image {\u03b1 \u03b2 \u03b3} {s : set \u03b1} {t : set \u03b2} {u : set \u03b3} :\n  equiv.prod_assoc \u03b1 \u03b2 \u03b3 '' (s \u00d7\u02e2 t) \u00d7\u02e2 u = s \u00d7\u02e2 (t \u00d7\u02e2 u) :=\nby simpa only [equiv.image_eq_preimage] using prod_assoc_symm_preimage\n\nlemma prod_assoc_symm_image {\u03b1 \u03b2 \u03b3} {s : set \u03b1} {t : set \u03b2} {u : set \u03b3} :\n  (equiv.prod_assoc \u03b1 \u03b2 \u03b3).symm '' s \u00d7\u02e2 (t \u00d7\u02e2 u) = (s \u00d7\u02e2 t) \u00d7\u02e2 u :=\nby simpa only [equiv.image_eq_preimage] using prod_assoc_preimage\n\n/-- A set `s` in `\u03b1 \u00d7 \u03b2` is equivalent to the sigma-type `\u03a3 x, {y | (x, y) \u2208 s}`. -/\ndef set_prod_equiv_sigma {\u03b1 \u03b2 : Type*} (s : set (\u03b1 \u00d7 \u03b2)) :\n  s \u2243 \u03a3 x : \u03b1, {y | (x, y) \u2208 s} :=\n{ to_fun := \u03bb x, \u27e8x.1.1, x.1.2, by simp\u27e9,\n  inv_fun := \u03bb x, \u27e8(x.1, x.2.1), x.2.2\u27e9,\n  left_inv := \u03bb \u27e8\u27e8x, y\u27e9, h\u27e9, rfl,\n  right_inv := \u03bb \u27e8x, y, h\u27e9, rfl }\n\n/-- The subtypes corresponding to equal sets are equivalent. -/\n@[simps apply]\ndef set_congr {\u03b1 : Type*} {s t : set \u03b1} (h : s = t) : s \u2243 t :=\nsubtype_equiv_prop h\n\n/--\nA set is equivalent to its image under an equivalence.\n-/\n-- We could construct this using `equiv.set.image e s e.injective`,\n-- but this definition provides an explicit inverse.\n@[simps]\ndef image {\u03b1 \u03b2 : Type*} (e : \u03b1 \u2243 \u03b2) (s : set \u03b1) : s \u2243 e '' s :=\n{ to_fun := \u03bb x, \u27e8e x.1, by simp\u27e9,\n  inv_fun := \u03bb y, \u27e8e.symm y.1, by { rcases y with \u27e8-, \u27e8a, \u27e8m, rfl\u27e9\u27e9\u27e9, simpa using m, }\u27e9,\n  left_inv := \u03bb x, by simp,\n  right_inv := \u03bb y, by simp, }.\n\nnamespace set\n\n/-- `univ \u03b1` is equivalent to `\u03b1`. -/\n@[simps apply symm_apply]\nprotected def univ (\u03b1) : @univ \u03b1 \u2243 \u03b1 :=\n\u27e8coe, \u03bb a, \u27e8a, trivial\u27e9, \u03bb \u27e8a, _\u27e9, rfl, \u03bb a, rfl\u27e9\n\n/-- An empty set is equivalent to the `empty` type. -/\nprotected def empty (\u03b1) : (\u2205 : set \u03b1) \u2243 empty :=\nequiv_empty _\n\n/-- An empty set is equivalent to a `pempty` type. -/\nprotected def pempty (\u03b1) : (\u2205 : set \u03b1) \u2243 pempty :=\nequiv_pempty _\n\n/-- If sets `s` and `t` are separated by a decidable predicate, then `s \u222a t` is equivalent to\n`s \u2295 t`. -/\nprotected def union' {\u03b1} {s t : set \u03b1}\n  (p : \u03b1 \u2192 Prop) [decidable_pred p]\n  (hs : \u2200 x \u2208 s, p x)\n  (ht : \u2200 x \u2208 t, \u00ac p x) : (s \u222a t : set \u03b1) \u2243 s \u2295 t :=\n{ to_fun := \u03bb x, if hp : p x\n    then sum.inl \u27e8_, x.2.resolve_right (\u03bb xt, ht _ xt hp)\u27e9\n    else sum.inr \u27e8_, x.2.resolve_left (\u03bb xs, hp (hs _ xs))\u27e9,\n  inv_fun := \u03bb o, match o with\n    | (sum.inl x) := \u27e8x, or.inl x.2\u27e9\n    | (sum.inr x) := \u27e8x, or.inr x.2\u27e9\n  end,\n  left_inv := \u03bb \u27e8x, h'\u27e9, by by_cases p x; simp [union'._match_1, h]; congr,\n  right_inv := \u03bb o, begin\n    rcases o with \u27e8x, h\u27e9 | \u27e8x, h\u27e9;\n    dsimp [union'._match_1];\n    [simp [hs _ h], simp [ht _ h]]\n  end }\n\n/-- If sets `s` and `t` are disjoint, then `s \u222a t` is equivalent to `s \u2295 t`. -/\nprotected def union {\u03b1} {s t : set \u03b1} [decidable_pred (\u03bb x, x \u2208 s)] (H : s \u2229 t \u2286 \u2205) :\n  (s \u222a t : set \u03b1) \u2243 s \u2295 t :=\nset.union' (\u03bb x, x \u2208 s) (\u03bb _, id) (\u03bb x xt xs, H \u27e8xs, xt\u27e9)\n\nlemma union_apply_left {\u03b1} {s t : set \u03b1} [decidable_pred (\u03bb x, x \u2208 s)] (H : s \u2229 t \u2286 \u2205)\n  {a : (s \u222a t : set \u03b1)} (ha : \u2191a \u2208 s) : equiv.set.union H a = sum.inl \u27e8a, ha\u27e9 :=\ndif_pos ha\n\nlemma union_apply_right {\u03b1} {s t : set \u03b1} [decidable_pred (\u03bb x, x \u2208 s)] (H : s \u2229 t \u2286 \u2205)\n  {a : (s \u222a t : set \u03b1)} (ha : \u2191a \u2208 t) : equiv.set.union H a = sum.inr \u27e8a, ha\u27e9 :=\ndif_neg $ \u03bb h, H \u27e8h, ha\u27e9\n\n@[simp] lemma union_symm_apply_left {\u03b1} {s t : set \u03b1} [decidable_pred (\u03bb x, x \u2208 s)] (H : s \u2229 t \u2286 \u2205)\n  (a : s) : (equiv.set.union H).symm (sum.inl a) = \u27e8a, subset_union_left _ _ a.2\u27e9 :=\nrfl\n\n@[simp] lemma union_symm_apply_right {\u03b1} {s t : set \u03b1} [decidable_pred (\u03bb x, x \u2208 s)] (H : s \u2229 t \u2286 \u2205)\n  (a : t) : (equiv.set.union H).symm (sum.inr a) = \u27e8a, subset_union_right _ _ a.2\u27e9 :=\nrfl\n\n/-- A singleton set is equivalent to a `punit` type. -/\nprotected def singleton {\u03b1} (a : \u03b1) : ({a} : set \u03b1) \u2243 punit.{u} :=\n\u27e8\u03bb _, punit.star, \u03bb _, \u27e8a, mem_singleton _\u27e9,\n \u03bb \u27e8x, h\u27e9, by { simp at h, subst x },\n \u03bb \u27e8\u27e9, rfl\u27e9\n\n/-- Equal sets are equivalent.\n\nTODO: this is the same as `equiv.set_congr`! -/\n@[simps apply symm_apply]\nprotected def of_eq {\u03b1 : Type u} {s t : set \u03b1} (h : s = t) : s \u2243 t :=\nequiv.set_congr h\n\n/-- If `a \u2209 s`, then `insert a s` is equivalent to `s \u2295 punit`. -/\nprotected def insert {\u03b1} {s : set.{u} \u03b1} [decidable_pred (\u2208 s)] {a : \u03b1} (H : a \u2209 s) :\n  (insert a s : set \u03b1) \u2243 s \u2295 punit.{u+1} :=\ncalc (insert a s : set \u03b1) \u2243 \u21a5(s \u222a {a}) : equiv.set.of_eq (by simp)\n... \u2243 s \u2295 ({a} : set \u03b1) : equiv.set.union (\u03bb x \u27e8hx, hx'\u27e9, by simp [*] at *)\n... \u2243 s \u2295 punit.{u+1} : sum_congr (equiv.refl _) (equiv.set.singleton _)\n\n@[simp] lemma insert_symm_apply_inl {\u03b1} {s : set.{u} \u03b1} [decidable_pred (\u2208 s)] {a : \u03b1} (H : a \u2209 s)\n  (b : s) : (equiv.set.insert H).symm (sum.inl b) = \u27e8b, or.inr b.2\u27e9 :=\nrfl\n\n@[simp] lemma insert_symm_apply_inr {\u03b1} {s : set.{u} \u03b1} [decidable_pred (\u2208 s)] {a : \u03b1} (H : a \u2209 s)\n  (b : punit.{u+1}) : (equiv.set.insert H).symm (sum.inr b) = \u27e8a, or.inl rfl\u27e9 :=\nrfl\n\n@[simp] lemma insert_apply_left {\u03b1} {s : set.{u} \u03b1} [decidable_pred (\u2208 s)] {a : \u03b1} (H : a \u2209 s) :\n  equiv.set.insert H \u27e8a, or.inl rfl\u27e9 = sum.inr punit.star :=\n(equiv.set.insert H).apply_eq_iff_eq_symm_apply.2 rfl\n\n@[simp] lemma insert_apply_right {\u03b1} {s : set.{u} \u03b1} [decidable_pred (\u2208 s)] {a : \u03b1} (H : a \u2209 s)\n  (b : s) : equiv.set.insert H \u27e8b, or.inr b.2\u27e9 = sum.inl b :=\n(equiv.set.insert H).apply_eq_iff_eq_symm_apply.2 rfl\n\n/-- If `s : set \u03b1` is a set with decidable membership, then `s \u2295 s\u1d9c` is equivalent to `\u03b1`. -/\nprotected def sum_compl {\u03b1} (s : set \u03b1) [decidable_pred (\u2208 s)] : s \u2295 (s\u1d9c : set \u03b1) \u2243 \u03b1 :=\ncalc s \u2295 (s\u1d9c : set \u03b1) \u2243 \u21a5(s \u222a s\u1d9c) : (equiv.set.union (by simp [set.ext_iff])).symm\n... \u2243 @univ \u03b1 : equiv.set.of_eq (by simp)\n... \u2243 \u03b1 : equiv.set.univ _\n\n@[simp] lemma sum_compl_apply_inl {\u03b1 : Type u} (s : set \u03b1) [decidable_pred (\u2208 s)] (x : s) :\n  equiv.set.sum_compl s (sum.inl x) = x := rfl\n\n@[simp] lemma sum_compl_apply_inr {\u03b1 : Type u} (s : set \u03b1) [decidable_pred (\u2208 s)] (x : s\u1d9c) :\n  equiv.set.sum_compl s (sum.inr x) = x := rfl\n\nlemma sum_compl_symm_apply_of_mem {\u03b1 : Type u} {s : set \u03b1} [decidable_pred (\u2208 s)] {x : \u03b1}\n  (hx : x \u2208 s) : (equiv.set.sum_compl s).symm x = sum.inl \u27e8x, hx\u27e9 :=\nhave \u2191(\u27e8x, or.inl hx\u27e9 : (s \u222a s\u1d9c : set \u03b1)) \u2208 s, from hx,\nby { rw [equiv.set.sum_compl], simpa using set.union_apply_left _ this }\n\nlemma sum_compl_symm_apply_of_not_mem {\u03b1 : Type u} {s : set \u03b1} [decidable_pred (\u2208 s)] {x : \u03b1}\n  (hx : x \u2209 s) : (equiv.set.sum_compl s).symm x = sum.inr \u27e8x, hx\u27e9 :=\nhave \u2191(\u27e8x, or.inr hx\u27e9 : (s \u222a s\u1d9c : set \u03b1)) \u2208 s\u1d9c, from hx,\nby { rw [equiv.set.sum_compl], simpa using set.union_apply_right _ this }\n\n@[simp] lemma sum_compl_symm_apply {\u03b1 : Type*} {s : set \u03b1} [decidable_pred (\u2208 s)] {x : s} :\n  (equiv.set.sum_compl s).symm x = sum.inl x :=\nby cases x with x hx; exact set.sum_compl_symm_apply_of_mem hx\n\n@[simp] lemma sum_compl_symm_apply_compl {\u03b1 : Type*} {s : set \u03b1}\n  [decidable_pred (\u2208 s)] {x : s\u1d9c} : (equiv.set.sum_compl s).symm x = sum.inr x :=\nby cases x with x hx; exact set.sum_compl_symm_apply_of_not_mem hx\n\n/-- `sum_diff_subset s t` is the natural equivalence between\n`s \u2295 (t \\ s)` and `t`, where `s` and `t` are two sets. -/\nprotected def sum_diff_subset {\u03b1} {s t : set \u03b1} (h : s \u2286 t) [decidable_pred (\u2208 s)] :\n  s \u2295 (t \\ s : set \u03b1) \u2243 t :=\ncalc s \u2295 (t \\ s : set \u03b1) \u2243 (s \u222a (t \\ s) : set \u03b1) :\n  (equiv.set.union (by simp [inter_diff_self])).symm\n... \u2243 t : equiv.set.of_eq (by { simp [union_diff_self, union_eq_self_of_subset_left h] })\n\n@[simp] lemma sum_diff_subset_apply_inl\n  {\u03b1} {s t : set \u03b1} (h : s \u2286 t) [decidable_pred (\u2208 s)] (x : s) :\n  equiv.set.sum_diff_subset h (sum.inl x) = inclusion h x := rfl\n\n@[simp] lemma sum_diff_subset_apply_inr\n  {\u03b1} {s t : set \u03b1} (h : s \u2286 t) [decidable_pred (\u2208 s)] (x : t \\ s) :\n  equiv.set.sum_diff_subset h (sum.inr x) = inclusion (diff_subset t s) x := rfl\n\nlemma sum_diff_subset_symm_apply_of_mem\n  {\u03b1} {s t : set \u03b1} (h : s \u2286 t) [decidable_pred (\u2208 s)] {x : t} (hx : x.1 \u2208 s) :\n  (equiv.set.sum_diff_subset h).symm x = sum.inl \u27e8x, hx\u27e9 :=\nbegin\n  apply (equiv.set.sum_diff_subset h).injective,\n  simp only [apply_symm_apply, sum_diff_subset_apply_inl],\n  exact subtype.eq rfl,\nend\n\nlemma sum_diff_subset_symm_apply_of_not_mem\n  {\u03b1} {s t : set \u03b1} (h : s \u2286 t) [decidable_pred (\u2208 s)] {x : t} (hx : x.1 \u2209 s) :\n  (equiv.set.sum_diff_subset h).symm x = sum.inr \u27e8x, \u27e8x.2, hx\u27e9\u27e9  :=\nbegin\n  apply (equiv.set.sum_diff_subset h).injective,\n  simp only [apply_symm_apply, sum_diff_subset_apply_inr],\n  exact subtype.eq rfl,\nend\n\n/-- If `s` is a set with decidable membership, then the sum of `s \u222a t` and `s \u2229 t` is equivalent\nto `s \u2295 t`. -/\nprotected def union_sum_inter {\u03b1 : Type u} (s t : set \u03b1) [decidable_pred (\u2208 s)] :\n  (s \u222a t : set \u03b1) \u2295 (s \u2229 t : set \u03b1) \u2243 s \u2295 t :=\ncalc  (s \u222a t : set \u03b1) \u2295 (s \u2229 t : set \u03b1)\n    \u2243 (s \u222a t \\ s : set \u03b1) \u2295 (s \u2229 t : set \u03b1) : by rw [union_diff_self]\n... \u2243 (s \u2295 (t \\ s : set \u03b1)) \u2295 (s \u2229 t : set \u03b1) :\n  sum_congr (set.union $ subset_empty_iff.2 (inter_diff_self _ _)) (equiv.refl _)\n... \u2243 s \u2295 (t \\ s : set \u03b1) \u2295 (s \u2229 t : set \u03b1) : sum_assoc _ _ _\n... \u2243 s \u2295 (t \\ s \u222a s \u2229 t : set \u03b1) : sum_congr (equiv.refl _) begin\n    refine (set.union' (\u2209 s) _ _).symm,\n    exacts [\u03bb x hx, hx.2, \u03bb x hx, not_not_intro hx.1]\n  end\n... \u2243 s \u2295 t : by { rw (_ : t \\ s \u222a s \u2229 t = t), rw [union_comm, inter_comm, inter_union_diff] }\n\n/-- Given an equivalence `e\u2080` between sets `s : set \u03b1` and `t : set \u03b2`, the set of equivalences\n`e : \u03b1 \u2243 \u03b2` such that `e \u2191x = \u2191(e\u2080 x)` for each `x : s` is equivalent to the set of equivalences\nbetween `s\u1d9c` and `t\u1d9c`. -/\nprotected def compl {\u03b1 : Type u} {\u03b2 : Type v} {s : set \u03b1} {t : set \u03b2} [decidable_pred (\u2208 s)]\n  [decidable_pred (\u2208 t)] (e\u2080 : s \u2243 t) :\n  {e : \u03b1 \u2243 \u03b2 // \u2200 x : s, e x = e\u2080 x} \u2243 ((s\u1d9c : set \u03b1) \u2243 (t\u1d9c : set \u03b2)) :=\n{ to_fun := \u03bb e, subtype_equiv e\n    (\u03bb a, not_congr $ iff.symm $ maps_to.mem_iff\n      (maps_to_iff_exists_map_subtype.2 \u27e8e\u2080, e.2\u27e9)\n      (surj_on.maps_to_compl (surj_on_iff_exists_map_subtype.2\n        \u27e8t, e\u2080, subset.refl t, e\u2080.surjective, e.2\u27e9) e.1.injective)),\n  inv_fun := \u03bb e\u2081,\n    subtype.mk\n      (calc \u03b1 \u2243 s \u2295 (s\u1d9c : set \u03b1) : (set.sum_compl s).symm\n          ... \u2243 t \u2295 (t\u1d9c : set \u03b2) : e\u2080.sum_congr e\u2081\n          ... \u2243 \u03b2 : set.sum_compl t)\n      (\u03bb x, by simp only [sum.map_inl, trans_apply, sum_congr_apply,\n        set.sum_compl_apply_inl, set.sum_compl_symm_apply]),\n  left_inv := \u03bb e,\n    begin\n      ext x,\n      by_cases hx : x \u2208 s,\n      { simp only [set.sum_compl_symm_apply_of_mem hx, \u2190e.prop \u27e8x, hx\u27e9,\n          sum.map_inl, sum_congr_apply, trans_apply,\n          subtype.coe_mk, set.sum_compl_apply_inl] },\n      { simp only [set.sum_compl_symm_apply_of_not_mem hx, sum.map_inr,\n          subtype_equiv_apply, set.sum_compl_apply_inr, trans_apply,\n          sum_congr_apply, subtype.coe_mk] },\n    end,\n  right_inv := \u03bb e, equiv.ext $ \u03bb x, by simp only [sum.map_inr, subtype_equiv_apply,\n    set.sum_compl_apply_inr, function.comp_app, sum_congr_apply, equiv.coe_trans,\n    subtype.coe_eta, subtype.coe_mk, set.sum_compl_symm_apply_compl] }\n\n/-- The set product of two sets is equivalent to the type product of their coercions to types. -/\nprotected def prod {\u03b1 \u03b2} (s : set \u03b1) (t : set \u03b2) :\n  \u21a5(s \u00d7\u02e2 t) \u2243 s \u00d7 t :=\n@subtype_prod_equiv_prod \u03b1 \u03b2 s t\n\n/-- The set `set.pi set.univ s` is equivalent to `\u03a0 a, s a`. -/\n@[simps] protected def univ_pi {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type*} (s : \u03a0 a, set (\u03b2 a)) :\n  pi univ s \u2243 \u03a0 a, s a :=\n{ to_fun := \u03bb f a, \u27e8(f : \u03a0 a, \u03b2 a) a, f.2 a (mem_univ a)\u27e9,\n  inv_fun := \u03bb f, \u27e8\u03bb a, f a, \u03bb a ha, (f a).2\u27e9,\n  left_inv := \u03bb \u27e8f, hf\u27e9, by { ext a, refl },\n  right_inv := \u03bb f, by { ext a, refl } }\n\n/-- If a function `f` is injective on a set `s`, then `s` is equivalent to `f '' s`. -/\nprotected noncomputable def image_of_inj_on {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (H : inj_on f s) :\n  s \u2243 (f '' s) :=\n\u27e8\u03bb p, \u27e8f p, mem_image_of_mem f p.2\u27e9,\n \u03bb p, \u27e8classical.some p.2, (classical.some_spec p.2).1\u27e9,\n \u03bb \u27e8x, h\u27e9, subtype.eq (H (classical.some_spec (mem_image_of_mem f h)).1 h\n   (classical.some_spec (mem_image_of_mem f h)).2),\n \u03bb \u27e8y, h\u27e9, subtype.eq (classical.some_spec h).2\u27e9\n\n/-- If `f` is an injective function, then `s` is equivalent to `f '' s`. -/\n@[simps apply]\nprotected noncomputable def image {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (H : injective f) : s \u2243 (f '' s) :=\nequiv.set.image_of_inj_on f s (H.inj_on s)\n\n@[simp] protected lemma image_symm_apply {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (H : injective f)\n  (x : \u03b1) (h : x \u2208 s) :\n  (set.image f s H).symm \u27e8f x, \u27e8x, \u27e8h, rfl\u27e9\u27e9\u27e9 = \u27e8x, h\u27e9 :=\nbegin\n  apply (set.image f s H).injective,\n  simp [(set.image f s H).apply_symm_apply],\nend\n\nlemma image_symm_preimage {\u03b1 \u03b2} {f : \u03b1 \u2192 \u03b2} (hf : injective f) (u s : set \u03b1) :\n  (\u03bb x, (set.image f s hf).symm x : f '' s \u2192 \u03b1) \u207b\u00b9' u = coe \u207b\u00b9' (f '' u) :=\nbegin\n  ext \u27e8b, a, has, rfl\u27e9,\n  have : \u2200(h : \u2203a', a' \u2208 s \u2227 a' = a), classical.some h = a := \u03bb h, (classical.some_spec h).2,\n  simp [equiv.set.image, equiv.set.image_of_inj_on, hf.eq_iff, this],\nend\n\n/-- If `\u03b1` is equivalent to `\u03b2`, then `set \u03b1` is equivalent to `set \u03b2`. -/\n@[simps]\nprotected def congr {\u03b1 \u03b2 : Type*} (e : \u03b1 \u2243 \u03b2) : set \u03b1 \u2243 set \u03b2 :=\n\u27e8\u03bb s, e '' s, \u03bb t, e.symm '' t, symm_image_image e, symm_image_image e.symm\u27e9\n\n/-- The set `{x \u2208 s | t x}` is equivalent to the set of `x : s` such that `t x`. -/\nprotected def sep {\u03b1 : Type u} (s : set \u03b1) (t : \u03b1 \u2192 Prop) :\n  ({ x \u2208 s | t x } : set \u03b1) \u2243 { x : s | t x } :=\n(equiv.subtype_subtype_equiv_subtype_inter s t).symm\n\n/-- The set `\ud835\udcab S := {x | x \u2286 S}` is equivalent to the type `set S`. -/\nprotected def powerset {\u03b1} (S : set \u03b1) : \ud835\udcab S \u2243 set S :=\n{ to_fun := \u03bb x : \ud835\udcab S, coe \u207b\u00b9' (x : set \u03b1),\n  inv_fun := \u03bb x : set S, \u27e8coe '' x, by rintro _ \u27e8a : S, _, rfl\u27e9; exact a.2\u27e9,\n  left_inv := \u03bb x, by ext y; exact \u27e8\u03bb \u27e8\u27e8_, _\u27e9, h, rfl\u27e9, h, \u03bb h, \u27e8\u27e8_, x.2 h\u27e9, h, rfl\u27e9\u27e9,\n  right_inv := \u03bb x, by ext; simp }\n\n/--\nIf `s` is a set in `range f`,\nthen its image under `range_splitting f` is in bijection (via `f`) with `s`.\n-/\n@[simps]\nnoncomputable def range_splitting_image_equiv {\u03b1 \u03b2 : Type*} (f : \u03b1 \u2192 \u03b2) (s : set (range f)) :\n  range_splitting f '' s \u2243 s :=\n{ to_fun := \u03bb x, \u27e8\u27e8f x, by simp\u27e9,\n    (by { rcases x with \u27e8x, \u27e8y, \u27e8m, rfl\u27e9\u27e9\u27e9, simpa [apply_range_splitting f] using m, })\u27e9,\n  inv_fun := \u03bb x, \u27e8range_splitting f x, \u27e8x, \u27e8x.2, rfl\u27e9\u27e9\u27e9,\n  left_inv := \u03bb x, by { rcases x with \u27e8x, \u27e8y, \u27e8m, rfl\u27e9\u27e9\u27e9, simp [apply_range_splitting f] },\n  right_inv := \u03bb x, by simp [apply_range_splitting f], }\n\nend set\n\n\n/-- If `f : \u03b1 \u2192 \u03b2` has a left-inverse when `\u03b1` is nonempty, then `\u03b1` is computably equivalent to the\nrange of `f`.\n\nWhile awkward, the `nonempty \u03b1` hypothesis on `f_inv` and `hf` allows this to be used when `\u03b1` is\nempty too. This hypothesis is absent on analogous definitions on stronger `equiv`s like\n`linear_equiv.of_left_inverse` and `ring_equiv.of_left_inverse` as their typeclass assumptions\nare already sufficient to ensure non-emptiness. -/\n@[simps]\ndef of_left_inverse {\u03b1 \u03b2 : Sort*}\n  (f : \u03b1 \u2192 \u03b2) (f_inv : nonempty \u03b1 \u2192 \u03b2 \u2192 \u03b1) (hf : \u03a0 h : nonempty \u03b1, left_inverse (f_inv h) f) :\n  \u03b1 \u2243 range f :=\n{ to_fun := \u03bb a, \u27e8f a, a, rfl\u27e9,\n  inv_fun := \u03bb b, f_inv (nonempty_of_exists b.2) b,\n  left_inv := \u03bb a, hf \u27e8a\u27e9 a,\n  right_inv := \u03bb \u27e8b, a, ha\u27e9, subtype.eq $ show f (f_inv \u27e8a\u27e9 b) = b,\n    from eq.trans (congr_arg f $ by exact ha \u25b8 (hf _ a)) ha }\n\n/-- If `f : \u03b1 \u2192 \u03b2` has a left-inverse, then `\u03b1` is computably equivalent to the range of `f`.\n\nNote that if `\u03b1` is empty, no such `f_inv` exists and so this definition can't be used, unlike\nthe stronger but less convenient `of_left_inverse`. -/\nabbreviation of_left_inverse' {\u03b1 \u03b2 : Sort*}\n  (f : \u03b1 \u2192 \u03b2) (f_inv : \u03b2 \u2192 \u03b1) (hf : left_inverse f_inv f) :\n  \u03b1 \u2243 range f :=\nof_left_inverse f (\u03bb _, f_inv) (\u03bb _, hf)\n\n/-- If `f : \u03b1 \u2192 \u03b2` is an injective function, then domain `\u03b1` is equivalent to the range of `f`. -/\n@[simps apply]\nnoncomputable def of_injective {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (hf : injective f) : \u03b1 \u2243 range f :=\nequiv.of_left_inverse f\n  (\u03bb h, by exactI function.inv_fun f) (\u03bb h, by exactI function.left_inverse_inv_fun hf)\n\ntheorem apply_of_injective_symm {\u03b1 \u03b2} {f : \u03b1 \u2192 \u03b2} (hf : injective f) (b : range f) :\n  f ((of_injective f hf).symm b) = b :=\nsubtype.ext_iff.1 $ (of_injective f hf).apply_symm_apply b\n\n@[simp] theorem of_injective_symm_apply {\u03b1 \u03b2} {f : \u03b1 \u2192 \u03b2} (hf : injective f) (a : \u03b1) :\n  (of_injective f hf).symm \u27e8f a, \u27e8a, rfl\u27e9\u27e9 = a :=\nbegin\n  apply (of_injective f hf).injective,\n  simp [apply_of_injective_symm hf],\nend\n\nlemma coe_of_injective_symm {\u03b1 \u03b2} {f : \u03b1 \u2192 \u03b2} (hf : injective f) :\n  ((of_injective f hf).symm : range f \u2192 \u03b1) = range_splitting f :=\nby { ext \u27e8y, x, rfl\u27e9, apply hf, simp [apply_range_splitting f] }\n\n@[simp] lemma self_comp_of_injective_symm {\u03b1 \u03b2} {f : \u03b1 \u2192 \u03b2} (hf : injective f) :\n  f \u2218 ((of_injective f hf).symm) = coe :=\nfunext (\u03bb x, apply_of_injective_symm hf x)\n\nlemma of_left_inverse_eq_of_injective {\u03b1 \u03b2 : Type*}\n  (f : \u03b1 \u2192 \u03b2) (f_inv : nonempty \u03b1 \u2192 \u03b2 \u2192 \u03b1) (hf : \u03a0 h : nonempty \u03b1, left_inverse (f_inv h) f) :\n  of_left_inverse f f_inv hf = of_injective f\n    ((em (nonempty \u03b1)).elim (\u03bb h, (hf h).injective) (\u03bb h _ _ _, by\n    { haveI : subsingleton \u03b1 := subsingleton_of_not_nonempty h, simp })) :=\nby { ext, simp }\n\nlemma of_left_inverse'_eq_of_injective {\u03b1 \u03b2 : Type*}\n  (f : \u03b1 \u2192 \u03b2) (f_inv : \u03b2 \u2192 \u03b1) (hf : left_inverse f_inv f) :\n  of_left_inverse' f f_inv hf = of_injective f hf.injective :=\nby { ext, simp }\n\nprotected lemma set_forall_iff {\u03b1 \u03b2} (e : \u03b1 \u2243 \u03b2) {p : set \u03b1 \u2192 Prop} :\n  (\u2200 a, p a) \u2194 (\u2200 a, p (e \u207b\u00b9' a)) :=\ne.injective.preimage_surjective.forall\n\nlemma preimage_pi_equiv_pi_subtype_prod_symm_pi {\u03b1 : Type*} {\u03b2 : \u03b1 \u2192 Type*}\n  (p : \u03b1 \u2192 Prop) [decidable_pred p] (s : \u03a0 i, set (\u03b2 i)) :\n  (pi_equiv_pi_subtype_prod p \u03b2).symm \u207b\u00b9' pi univ s =\n    (pi univ (\u03bb i : {i // p i}, s i)) \u00d7\u02e2 pi univ (\u03bb i : {i // \u00acp i}, s i) :=\nbegin\n  ext \u27e8f, g\u27e9,\n  simp only [mem_preimage, mem_univ_pi, prod_mk_mem_set_prod_eq, subtype.forall,\n    \u2190 forall_and_distrib],\n  refine forall_congr (\u03bb i, _),\n  dsimp only [subtype.coe_mk],\n  by_cases hi : p i; simp [hi]\nend\n\n/-- `sigma_fiber_equiv f` for `f : \u03b1 \u2192 \u03b2` is the natural equivalence between\nthe type of all preimages of points under `f` and the total space `\u03b1`. -/\n-- See also `equiv.sigma_fiber_equiv`.\n@[simps] def sigma_preimage_equiv {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) : (\u03a3 b, f \u207b\u00b9' {b}) \u2243 \u03b1 :=\nsigma_fiber_equiv f\n\n/-- A family of equivalences between preimages of points gives an equivalence between domains. -/\n-- See also `equiv.of_fiber_equiv`.\n@[simps]\ndef of_preimage_equiv {\u03b1 \u03b2 \u03b3} {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3} (e : \u03a0 c, (f \u207b\u00b9' {c}) \u2243 (g \u207b\u00b9' {c})) :\n  \u03b1 \u2243 \u03b2 :=\nequiv.of_fiber_equiv e\n\nlemma of_preimage_equiv_map {\u03b1 \u03b2 \u03b3} {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3}\n  (e : \u03a0 c, (f \u207b\u00b9' {c}) \u2243 (g \u207b\u00b9' {c})) (a : \u03b1) : g (of_preimage_equiv e a) = f a :=\nequiv.of_fiber_equiv_map e a\n\nend equiv\n\n/-- If a function is a bijection between two sets `s` and `t`, then it induces an\nequivalence between the types `\u21a5s` and `\u21a5t`. -/\nnoncomputable def set.bij_on.equiv {\u03b1 : Type*} {\u03b2 : Type*} {s : set \u03b1} {t : set \u03b2} (f : \u03b1 \u2192 \u03b2)\n  (h : bij_on f s t) : s \u2243 t :=\nequiv.of_bijective _ h.bijective\n\n/-- The composition of an updated function with an equiv on a subset can be expressed as an\nupdated function. -/\nlemma dite_comp_equiv_update {\u03b1 : Type*} {\u03b2 : Sort*} {\u03b3 : Sort*} {s : set \u03b1} (e : \u03b2 \u2243 s)\n  (v : \u03b2 \u2192 \u03b3) (w : \u03b1 \u2192 \u03b3) (j : \u03b2) (x : \u03b3) [decidable_eq \u03b2] [decidable_eq \u03b1]\n  [\u2200 j, decidable (j \u2208 s)] :\n  (\u03bb (i : \u03b1), if h : i \u2208 s then (function.update v j x) (e.symm \u27e8i, h\u27e9) else w i) =\n  function.update (\u03bb (i : \u03b1), if h : i \u2208 s then v (e.symm \u27e8i, h\u27e9) else w i) (e j) x :=\nbegin\n  ext i,\n  by_cases h : i \u2208 s,\n  { rw [dif_pos h,\n        function.update_apply_equiv_apply, equiv.symm_symm, function.comp,\n        function.update_apply, function.update_apply,\n        dif_pos h],\n    have h_coe : (\u27e8i, h\u27e9 : s) = e j \u2194 i = e j := subtype.ext_iff.trans (by rw subtype.coe_mk),\n    simp_rw h_coe },\n  { have : i \u2260 e j,\n      by { contrapose! h, have : (e j : \u03b1) \u2208 s := (e j).2, rwa \u2190 h at this },\n    simp [h, this] }\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/logic/equiv/set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7062167538421862}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\nimport data.set.finite\nimport logic.equiv.list\n\n/-!\n# Countable sets\n-/\nnoncomputable theory\n\nopen function set encodable\n\nopen classical (hiding some)\nopen_locale classical\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nnamespace set\n\n/-- A set is countable if there exists an encoding of the set into the natural numbers.\nAn encoding is an injection with a partial inverse, which can be viewed as a\nconstructive analogue of countability. (For the most part, theorems about\n`countable` will be classical and `encodable` will be constructive.)\n-/\nprotected def countable (s : set \u03b1) : Prop := nonempty (encodable s)\n\nlemma countable_iff_exists_injective {s : set \u03b1} :\n  s.countable \u2194 \u2203f:s \u2192 \u2115, injective f :=\n\u27e8\u03bb \u27e8h\u27e9, by exactI \u27e8encode, encode_injective\u27e9,\n \u03bb \u27e8f, h\u27e9, \u27e8\u27e8f, partial_inv f, partial_inv_left h\u27e9\u27e9\u27e9\n\n/-- A set `s : set \u03b1` is countable if and only if there exists a function `\u03b1 \u2192 \u2115` injective\non `s`. -/\nlemma countable_iff_exists_inj_on {s : set \u03b1} :\n  s.countable \u2194 \u2203 f : \u03b1 \u2192 \u2115, inj_on f s :=\ncountable_iff_exists_injective.trans\n\u27e8\u03bb \u27e8f, hf\u27e9, \u27e8\u03bb a, if h : a \u2208 s then f \u27e8a, h\u27e9 else 0,\n   \u03bb a as b bs h, congr_arg subtype.val $\n     hf $ by simpa [as, bs] using h\u27e9,\n \u03bb \u27e8f, hf\u27e9, \u27e8_, inj_on_iff_injective.1 hf\u27e9\u27e9\n\nlemma countable_iff_exists_surjective [ne : nonempty \u03b1] {s : set \u03b1} :\n  s.countable \u2194 \u2203f:\u2115 \u2192 \u03b1, s \u2286 range f :=\n\u27e8\u03bb \u27e8h\u27e9, by inhabit \u03b1; exactI \u27e8\u03bb n, ((decode s n).map subtype.val).iget,\n  \u03bb a as, \u27e8encode (\u27e8a, as\u27e9 : s), by simp [encodek]\u27e9\u27e9,\n \u03bb \u27e8f, hf\u27e9, \u27e8\u27e8\n  \u03bb x, inv_fun f x.1,\n  \u03bb n, if h : f n \u2208 s then some \u27e8f n, h\u27e9 else none,\n  \u03bb \u27e8x, hx\u27e9, begin\n    have := inv_fun_eq (hf hx), dsimp at this \u22a2,\n    simp [this, hx]\n  end\u27e9\u27e9\u27e9\n\n/--\nA non-empty set is countable iff there exists a surjection from the\nnatural numbers onto the subtype induced by the set.\n-/\nlemma countable_iff_exists_surjective_to_subtype {s : set \u03b1} (hs : s.nonempty) :\n  s.countable \u2194 \u2203 f : \u2115 \u2192 s, surjective f :=\nhave inhabited s, from \u27e8classical.choice hs.to_subtype\u27e9,\nhave s.countable \u2192 \u2203 f : \u2115 \u2192 s, surjective f, from assume \u27e8h\u27e9,\n  by exactI \u27e8\u03bb n, (decode s n).iget, \u03bb a, \u27e8encode a, by simp [encodek]\u27e9\u27e9,\nhave (\u2203 f : \u2115 \u2192 s, surjective f) \u2192 s.countable, from assume \u27e8f, fsurj\u27e9,\n  \u27e8\u27e8inv_fun f, option.some \u2218 f,\n    by intro h; simp [(inv_fun_eq (fsurj h) : f (inv_fun f h) = h)]\u27e9\u27e9,\nby split; assumption\n\n/-- Convert `set.countable s` to `encodable s` (noncomputable). -/\ndef countable.to_encodable {s : set \u03b1} : s.countable \u2192 encodable s :=\nclassical.choice\n\nlemma countable_encodable' (s : set \u03b1) [H : encodable s] : s.countable :=\n\u27e8H\u27e9\n\nlemma countable_encodable [encodable \u03b1] (s : set \u03b1) : s.countable :=\n\u27e8by apply_instance\u27e9\n\n/-- If `s : set \u03b1` is a nonempty countable set, then there exists a map\n`f : \u2115 \u2192 \u03b1` such that `s = range f`. -/\nlemma countable.exists_surjective {s : set \u03b1} (hc : s.countable) (hs : s.nonempty) :\n  \u2203f:\u2115 \u2192 \u03b1, s = range f :=\nbegin\n  letI : encodable s := countable.to_encodable hc,\n  letI : nonempty s := hs.to_subtype,\n  have : (univ : set s).countable := countable_encodable _,\n  rcases countable_iff_exists_surjective.1 this with \u27e8g, hg\u27e9,\n  have : range g = univ := univ_subset_iff.1 hg,\n  use coe \u2218 g,\n  simp only [range_comp, this, image_univ, subtype.range_coe]\nend\n\n@[simp] \n\n@[simp] lemma countable_singleton (a : \u03b1) : ({a} : set \u03b1).countable :=\n\u27e8of_equiv _ (equiv.set.singleton a)\u27e9\n\nlemma countable.mono {s\u2081 s\u2082 : set \u03b1} (h : s\u2081 \u2286 s\u2082) : s\u2082.countable \u2192 s\u2081.countable\n| \u27e8H\u27e9 := \u27e8@of_inj _ _ H _ (embedding_of_subset _ _ h).2\u27e9\n\nlemma countable.image {s : set \u03b1} (hs : s.countable) (f : \u03b1 \u2192 \u03b2) : (f '' s).countable :=\nhave surjective ((maps_to_image f s).restrict _ _ _), from surjective_maps_to_image_restrict f s,\n\u27e8@encodable.of_inj _ _ hs.to_encodable (surj_inv this) (injective_surj_inv this)\u27e9\n\nlemma countable_range [encodable \u03b1] (f : \u03b1 \u2192 \u03b2) : (range f).countable :=\nby rw \u2190 image_univ; exact (countable_encodable _).image _\n\nlemma maps_to.countable_of_inj_on {s : set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (hf : maps_to f s t) (hf' : inj_on f s) (ht : t.countable) :\n  s.countable :=\nhave injective (hf.restrict f s t), from (inj_on_iff_injective.1 hf').cod_restrict _,\n\u27e8@encodable.of_inj _ _ ht.to_encodable _ this\u27e9\n\nlemma countable.preimage_of_inj_on {s : set \u03b2} (hs : s.countable) {f : \u03b1 \u2192 \u03b2}\n  (hf : inj_on f (f \u207b\u00b9' s)) : (f \u207b\u00b9' s).countable :=\n(maps_to_preimage f s).countable_of_inj_on hf hs\n\nprotected lemma countable.preimage {s : set \u03b2} (hs : s.countable) {f : \u03b1 \u2192 \u03b2} (hf : injective f) :\n  (f \u207b\u00b9' s).countable :=\nhs.preimage_of_inj_on (hf.inj_on _)\n\nlemma exists_seq_supr_eq_top_iff_countable [complete_lattice \u03b1] {p : \u03b1 \u2192 Prop} (h : \u2203 x, p x) :\n  (\u2203 s : \u2115 \u2192 \u03b1, (\u2200 n, p (s n)) \u2227 (\u2a06 n, s n) = \u22a4) \u2194\n    \u2203 S : set \u03b1, S.countable \u2227 (\u2200 s \u2208 S, p s) \u2227 Sup S = \u22a4 :=\nbegin\n  split,\n  { rintro \u27e8s, hps, hs\u27e9,\n    refine \u27e8range s, countable_range s, forall_range_iff.2 hps, _\u27e9, rwa Sup_range },\n  { rintro \u27e8S, hSc, hps, hS\u27e9,\n    rcases eq_empty_or_nonempty S with rfl|hne,\n    { rw [Sup_empty] at hS, haveI := subsingleton_of_bot_eq_top hS,\n      rcases h with \u27e8x, hx\u27e9, exact \u27e8\u03bb n, x, \u03bb n, hx, subsingleton.elim _ _\u27e9 },\n    { rcases (countable_iff_exists_surjective_to_subtype hne).1 hSc with \u27e8s, hs\u27e9,\n      refine \u27e8\u03bb n, s n, \u03bb n, hps _ (s n).coe_prop, _\u27e9,\n      rwa [hs.supr_comp, \u2190 Sup_eq_supr'] } }\nend\n\nlemma exists_seq_cover_iff_countable {p : set \u03b1 \u2192 Prop} (h : \u2203 s, p s) :\n  (\u2203 s : \u2115 \u2192 set \u03b1, (\u2200 n, p (s n)) \u2227 (\u22c3 n, s n) = univ) \u2194\n    \u2203 S : set (set \u03b1), S.countable \u2227 (\u2200 s \u2208 S, p s) \u2227 \u22c3\u2080 S = univ :=\nexists_seq_supr_eq_top_iff_countable h\n\nlemma countable_of_injective_of_countable_image {s : set \u03b1} {f : \u03b1 \u2192 \u03b2}\n  (hf : inj_on f s) (hs : (f '' s).countable) : s.countable :=\nlet \u27e8g, hg\u27e9 := countable_iff_exists_inj_on.1 hs in\ncountable_iff_exists_inj_on.2 \u27e8g \u2218 f, hg.comp hf (maps_to_image _ _)\u27e9\n\nlemma countable_Union {t : \u03b1 \u2192 set \u03b2} [encodable \u03b1] (ht : \u2200a, (t a).countable) :\n  (\u22c3a, t a).countable :=\nby haveI := (\u03bb a, (ht a).to_encodable);\n   rw Union_eq_range_sigma; apply countable_range\n\nlemma countable.bUnion\n  {s : set \u03b1} {t : \u03a0 x \u2208 s, set \u03b2} (hs : s.countable) (ht : \u2200a\u2208s, (t a \u2039_\u203a).countable) :\n  (\u22c3a\u2208s, t a \u2039_\u203a).countable :=\nbegin\n  rw bUnion_eq_Union,\n  haveI := hs.to_encodable,\n  exact countable_Union (by simpa using ht)\nend\n\nlemma countable.sUnion {s : set (set \u03b1)} (hs : s.countable) (h : \u2200a\u2208s, (a : _).countable) :\n  (\u22c3\u2080 s).countable :=\nby rw sUnion_eq_bUnion; exact hs.bUnion h\n\nlemma countable_Union_Prop {p : Prop} {t : p \u2192 set \u03b2} (ht : \u2200h:p, (t h).countable) :\n  (\u22c3h:p, t h).countable :=\nby by_cases p; simp [h, ht]\n\nlemma countable.union\n  {s\u2081 s\u2082 : set \u03b1} (h\u2081 : s\u2081.countable) (h\u2082 : s\u2082.countable) : (s\u2081 \u222a s\u2082).countable :=\nby rw union_eq_Union; exact\ncountable_Union (bool.forall_bool.2 \u27e8h\u2082, h\u2081\u27e9)\n\n@[simp] lemma countable_union {s t : set \u03b1} : (s \u222a t).countable \u2194 s.countable \u2227 t.countable :=\n\u27e8\u03bb h, \u27e8h.mono (subset_union_left s t), h.mono (subset_union_right _ _)\u27e9, \u03bb h, h.1.union h.2\u27e9\n\n@[simp] lemma countable_insert {s : set \u03b1} {a : \u03b1} : (insert a s).countable \u2194 s.countable :=\nby simp only [insert_eq, countable_union, countable_singleton, true_and]\n\nlemma countable.insert {s : set \u03b1} (a : \u03b1) (h : s.countable) : (insert a s).countable :=\ncountable_insert.2 h\n\nlemma finite.countable {s : set \u03b1} : s.finite \u2192 s.countable\n| \u27e8h\u27e9 := trunc.nonempty (by exactI fintype.trunc_encodable s)\n\n@[nontriviality] lemma countable.of_subsingleton [subsingleton \u03b1] (s : set \u03b1) :\n  s.countable :=\n(finite.of_subsingleton s).countable\n\nlemma subsingleton.countable {s : set \u03b1} (hs : s.subsingleton) : s.countable :=\nhs.finite.countable\n\nlemma countable_is_top (\u03b1 : Type*) [partial_order \u03b1] : {x : \u03b1 | is_top x}.countable :=\n(finite_is_top \u03b1).countable\n\nlemma countable_is_bot (\u03b1 : Type*) [partial_order \u03b1] : {x : \u03b1 | is_bot x}.countable :=\n(finite_is_bot \u03b1).countable\n\n/-- The set of finite subsets of a countable set is countable. -/\nlemma countable_set_of_finite_subset {s : set \u03b1} : s.countable \u2192\n  {t | set.finite t \u2227 t \u2286 s}.countable | \u27e8h\u27e9 :=\nbegin\n  resetI,\n  refine countable.mono _ (countable_range\n    (\u03bb t : finset s, {a | \u2203 h:a \u2208 s, subtype.mk a h \u2208 t})),\n  rintro t \u27e8\u27e8ht\u27e9, ts\u27e9, resetI,\n  refine \u27e8finset.univ.map (embedding_of_subset _ _ ts), set.ext $ \u03bb a, _\u27e9,\n  simpa using @ts a\nend\n\nlemma countable_pi {\u03c0 : \u03b1 \u2192 Type*} [fintype \u03b1] {s : \u03a0a, set (\u03c0 a)} (hs : \u2200a, (s a).countable) :\n  {f : \u03a0a, \u03c0 a | \u2200a, f a \u2208 s a}.countable :=\ncountable.mono\n  (show {f : \u03a0a, \u03c0 a | \u2200a, f a \u2208 s a} \u2286 range (\u03bbf : \u03a0a, s a, \u03bba, (f a).1), from\n    assume f hf, \u27e8\u03bba, \u27e8f a, hf a\u27e9, funext $ assume a, rfl\u27e9) $\nhave trunc (encodable (\u03a0 (a : \u03b1), s a)), from\n  @encodable.fintype_pi \u03b1 _ _ _ (assume a, (hs a).to_encodable),\ntrunc.induction_on this $ assume h,\n@countable_range _ _ h _\n\nprotected lemma countable.prod {s : set \u03b1} {t : set \u03b2} (hs : s.countable) (ht : t.countable) :\n  set.countable (s \u00d7\u02e2 t) :=\nbegin\n  haveI : encodable s := hs.to_encodable,\n  haveI : encodable t := ht.to_encodable,\n  exact \u27e8of_equiv (s \u00d7 t) (equiv.set.prod _ _)\u27e9\nend\n\nlemma countable.image2 {s : set \u03b1} {t : set \u03b2} (hs : s.countable) (ht : t.countable)\n  (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) : (image2 f s t).countable :=\nby { rw \u2190 image_prod, exact (hs.prod ht).image _ }\n\nsection enumerate\n\n/-- Enumerate elements in a countable set.-/\ndef enumerate_countable {s : set \u03b1} (h : s.countable) (default : \u03b1) : \u2115 \u2192 \u03b1 :=\nassume n, match @encodable.decode s h.to_encodable n with\n        | (some y) := y\n        | (none)   := default\n        end\n\nlemma subset_range_enumerate {s : set \u03b1} (h : s.countable) (default : \u03b1) :\n   s \u2286 range (enumerate_countable h default) :=\nassume x hx,\n\u27e8@encodable.encode s h.to_encodable \u27e8x, hx\u27e9,\nby simp [enumerate_countable, encodable.encodek]\u27e9\n\nend enumerate\n\nend set\n\nlemma finset.countable_to_set (s : finset \u03b1) : set.countable (\u2191s : set \u03b1) :=\ns.finite_to_set.countable\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/set/countable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7062167520420324}}
{"text": "/-\nCopyright (c) 2015 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jeremy Avigad\n\nThe notion of \"finiteness\" for sets. This approach is not computational: for example, just because\nan element  s : set A  satsifies  finite s  doesn't mean that we can compute the cardinality. For\na computational representation, use the finset type.\n-/\nimport data.finset.to_set .classical_inverse\nopen nat classical\n\nvariable {A : Type}\n\nnamespace set\n\ndefinition finite [class] (s : set A) : Prop := \u2203 (s' : finset A), s = finset.to_set s'\n\ntheorem finite_finset [instance] (s : finset A) : finite (finset.to_set s) :=\nexists.intro s rfl\n\n/- to finset: casts every set to a finite set -/\n\nnoncomputable definition to_finset (s : set A) : finset A :=\nif fins : finite s then some fins else finset.empty\n\ntheorem to_finset_of_not_finite {s : set A} (nfins : \u00ac finite s) : to_finset s = (#finset \u2205) :=\nby rewrite [\u2191to_finset, dif_neg nfins]\n\ntheorem to_set_to_finset (s : set A) [fins : finite s] : finset.to_set (to_finset s) = s :=\nby rewrite [\u2191to_finset, dif_pos fins]; exact eq.symm (some_spec fins)\n\ntheorem mem_to_finset_eq (a : A) (s : set A) [finite s] :\n  (#finset a \u2208 to_finset s) = (a \u2208 s) :=\nby rewrite [-to_set_to_finset s at {2}]\n\ntheorem to_set_to_finset_of_not_finite {s : set A} (nfins : \u00ac finite s) :\n  finset.to_set (to_finset s) = \u2205 :=\nby rewrite [to_finset_of_not_finite nfins]\n\ntheorem to_finset_to_set (s : finset A) : to_finset (finset.to_set s) = s :=\nby rewrite [finset.eq_eq_to_set_eq, to_set_to_finset (finset.to_set s)]\n\ntheorem to_finset_eq_of_to_set_eq {s : set A} {t : finset A} (H : finset.to_set t = s) :\n  to_finset s = t :=\nfinset.eq_of_to_set_eq_to_set (by subst [s]; rewrite to_finset_to_set)\n\n/- finiteness -/\n\ntheorem finite_of_to_set_to_finset_eq {s : set A} (H : finset.to_set (to_finset s) = s) :\n  finite s :=\nby rewrite -H; apply finite_finset\n\ntheorem finite_empty [instance] : finite (\u2205 : set A) :=\nby rewrite [-finset.to_set_empty]; apply finite_finset\n\ntheorem to_finset_empty : to_finset (\u2205 : set A) = (#finset \u2205) :=\nto_finset_eq_of_to_set_eq !finset.to_set_empty\n\ntheorem to_finset_eq_empty_of_eq_empty {s : set A} [fins : finite s] (H : s = \u2205) :\n  to_finset s = finset.empty := by rewrite [H, to_finset_empty]\n\ntheorem eq_empty_of_to_finset_eq_empty {s : set A} [fins : finite s]\n    (H : to_finset s = finset.empty) :\n  s = \u2205 := by rewrite [-finset.to_set_empty, -H, to_set_to_finset]\n\ntheorem to_finset_eq_empty (s : set A) [fins : finite s] :\n  (to_finset s = finset.empty) \u2194 (s = \u2205) :=\niff.intro eq_empty_of_to_finset_eq_empty to_finset_eq_empty_of_eq_empty\n\ntheorem finite_insert [instance] (a : A) (s : set A) [finite s] : finite (insert a s) :=\nexists.intro (finset.insert a (to_finset s))\n  (by rewrite [finset.to_set_insert, to_set_to_finset])\n\ntheorem to_finset_insert (a : A) (s : set A) [finite s] :\n  to_finset (insert a s) = finset.insert a (to_finset s) :=\nby apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_insert, to_set_to_finset]\n\ntheorem finite_union [instance] (s t : set A) [finite s] [finite t] :\n  finite (s \u222a t) :=\nexists.intro (#finset to_finset s \u222a to_finset t)\n  (by rewrite [finset.to_set_union, *to_set_to_finset])\n\ntheorem to_finset_union (s t : set A) [finite s] [finite t] :\n  to_finset (s \u222a t) = (#finset to_finset s \u222a to_finset t) :=\nby apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_union, *to_set_to_finset]\n\ntheorem finite_inter [instance] (s t : set A) [finite s] [finite t] :\n  finite (s \u2229 t) :=\nexists.intro (#finset to_finset s \u2229 to_finset t)\n  (by rewrite [finset.to_set_inter, *to_set_to_finset])\n\ntheorem to_finset_inter (s t : set A) [finite s] [finite t] :\n  to_finset (s \u2229 t) = (#finset to_finset s \u2229 to_finset t) :=\nby apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_inter, *to_set_to_finset]\n\ntheorem finite_sep [instance] (s : set A) (p : A \u2192 Prop) [finite s] :\n  finite {x \u2208 s | p x}  :=\nexists.intro (finset.sep p (to_finset s))\n  (by rewrite [finset.to_set_sep, *to_set_to_finset])\n\ntheorem to_finset_sep (s : set A) (p : A \u2192 Prop) [finite s] :\n  to_finset {x \u2208 s | p x} = (#finset {x \u2208 to_finset s | p x}) :=\nby apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_sep, to_set_to_finset]\n\ntheorem finite_image [instance] {B : Type} (f : A \u2192 B) (s : set A) [finite s] :\n  finite (f ' s) :=\nexists.intro (finset.image f (to_finset s))\n  (by rewrite [finset.to_set_image, *to_set_to_finset])\n\ntheorem to_finset_image {B : Type}  (f : A \u2192 B) (s : set A)\n    [fins : finite s] :\n  to_finset (f ' s) = (#finset f ' (to_finset s)) :=\nby apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_image, to_set_to_finset]\n\ntheorem finite_diff [instance] (s t : set A) [finite s] : finite (s \\ t) :=\n!finite_sep\n\ntheorem to_finset_diff (s t : set A) [finite s] [finite t] :\n        to_finset (s \\ t) = (#finset to_finset s \\ to_finset t) :=\nby apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_diff, *to_set_to_finset]\n\ntheorem finite_subset {s t : set A} [finite t] (ssubt : s \u2286 t) : finite s :=\nby rewrite (eq_sep_of_subset ssubt); apply finite_sep\n\ntheorem to_finset_subset_to_finset_eq (s t : set A) [finite s] [finite t] :\n  (#finset to_finset s \u2286 to_finset t) = (s \u2286 t) :=\nby rewrite [finset.subset_eq_to_set_subset, *to_set_to_finset]\n\ntheorem finite_of_finite_insert {s : set A} {a : A} (finias : finite (insert a s)) : finite s :=\nfinite_subset (subset_insert a s)\n\ntheorem finite_upto [instance] (n : \u2115) : finite {i | i < n} :=\nby rewrite [-finset.to_set_upto n]; apply finite_finset\n\ntheorem to_finset_upto (n : \u2115) : to_finset {i | i < n} = finset.upto n :=\nby apply (to_finset_eq_of_to_set_eq !finset.to_set_upto)\n\ntheorem finite_of_surj_on {B : Type} {f : A \u2192 B} {s : set A} [finite s] {t : set B}\n                          (H : surj_on f s t) :\n        finite t :=\nfinite_subset H\n\ntheorem finite_of_inj_on {B : Type} {f : A \u2192 B} {s : set A} {t : set B} [finite t]\n                         (mapsto : maps_to f s t) (injf : inj_on f s) :\n        finite s :=\nif H : s = \u2205 then\n  by rewrite H; apply _\nelse\n  obtain (dflt : A) (xs : dflt \u2208 s), from exists_mem_of_ne_empty H,\n  let finv := inv_fun f s dflt in\n  have surj_on finv t s, from surj_on_inv_fun_of_inj_on dflt mapsto injf,\n  finite_of_surj_on this\n\ntheorem finite_of_bij_on {B : Type} {f : A \u2192 B} {s : set A} {t : set B} [finite s]\n                         (bijf : bij_on f s t) :\n        finite t :=\nfinite_of_surj_on (surj_on_of_bij_on bijf)\n\ntheorem finite_of_bij_on' {B : Type} {f : A \u2192 B} {s : set A} {t : set B} [finite t]\n                         (bijf : bij_on f s t) :\n        finite s :=\nfinite_of_inj_on (maps_to_of_bij_on bijf) (inj_on_of_bij_on bijf)\n\ntheorem finite_iff_finite_of_bij_on {B : Type} {f : A \u2192 B} {s : set A} {t : set B}\n                                    (bijf : bij_on f s t) :\n        finite s \u2194 finite t :=\niff.intro (assume fs, finite_of_bij_on bijf) (assume ft, finite_of_bij_on' bijf)\n\ntheorem finite_powerset (s : set A) [finite s] : finite \ud835\udcab s :=\nhave H : \ud835\udcab s = finset.to_set ' (finset.to_set (#finset \ud835\udcab (to_finset s))),\n  from ext (take t, iff.intro\n    (suppose t \u2208 \ud835\udcab s,\n      have t \u2286 s, from this,\n      have finite t, from finite_subset this,\n      have (#finset to_finset t \u2208 \ud835\udcab (to_finset s)),\n        by rewrite [finset.mem_powerset_iff_subset, to_finset_subset_to_finset_eq]; apply `t \u2286 s`,\n      have to_finset t \u2208 (finset.to_set (finset.powerset (to_finset s))), from this,\n      mem_image this (by rewrite to_set_to_finset))\n    (assume H',\n      obtain t' [(tmem : (#finset t' \u2208 \ud835\udcab (to_finset s))) (teq : finset.to_set t' = t)],\n        from H',\n      show t \u2286 s,\n      begin\n        rewrite [-teq, finset.mem_powerset_iff_subset at tmem, -to_set_to_finset s],\n        rewrite -finset.subset_eq_to_set_subset, assumption\n     end)),\nby rewrite H; apply finite_image\n\n/- induction for finite sets -/\n\ntheorem induction_finite [recursor 6] {P : set A \u2192 Prop}\n    (H1 : P \u2205) (H2 : \u2200 \u2983a : A\u2984, \u2200 {s : set A} [finite s], a \u2209 s \u2192 P s \u2192 P (insert a s)) :\n  \u2200 (s : set A) [finite s], P s :=\nbegin\n  intro s fins,\n  rewrite [-to_set_to_finset s],\n  generalize to_finset s,\n  intro s',\n  induction s' using finset.induction with a s' nains ih,\n    {rewrite finset.to_set_empty, apply H1},\n  rewrite [finset.to_set_insert],\n  apply H2,\n    {rewrite -finset.mem_eq_mem_to_set, assumption},\n  exact ih\nend\n\ntheorem induction_on_finite {P : set A \u2192 Prop} (s : set A) [finite s]\n    (H1 : P \u2205) (H2 : \u2200 \u2983a : A\u2984, \u2200 {s : set A} [finite s], a \u2209 s \u2192 P s \u2192 P (insert a s)) :\n  P s :=\ninduction_finite H1 H2 s\n\nend set\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/data/set/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7062167471259443}}
{"text": "import tactic.norm_num\nimport data.real.basic\n\nopen tactic\n\n-- for avoiding ?m_1, ?m_2, etc\ninductive x : Prop | intro : x\ninductive y : Prop | intro : y\ninductive z : Prop | intro : z\nlemma hx : x := x.intro\nlemma hy : y := y.intro\nlemma hz : z := z.intro\n\n#check (eq_true_intro _).mpr\n-- (eq_true_intro ?M_2).mpr : true \u2192 ?M_1\n-- how ?M_2 related to ?M_1 ? You don't know.\n\n#check (eq_true_intro hx).mpr\n-- (eq_true_intro hx).mpr : true \u2192 x\n-- Now you know it: x is type of hx.\n\n#check @eq_true_intro\n\nexample : 1 \u2264 1 := by {\n  show_term { norm_num, },\n  trace_result,\n}\n\nexample : 1 \u2264 1 :=\n(eq_true_intro (le_refl 1)).mpr trivial\n\nexample : 1 \u2264 1 := le_refl 1\n\n/-- A predicate representing partial progress in a proof of `min_fac`. -/\ndef min_fac_helper (n k : \u2115) : Prop :=\n0 < k \u2227 bit1 k \u2264 nat.min_fac (bit1 n)\n\nexample : 6 = (bit0 $ bit1 $ bit1 0) := rfl\nexample : 16 = \n(bit0 $ bit0 $ bit0 $ bit0 $ bit1 0) := rfl\nexample : \u2200 x, bit0 x = 2 * x     := nat.bit0_val\nexample : \u2200 x, bit1 x = 2 * x + 1 := nat.bit1_val\n\n\nset_option pp.beta true\nset_option trace.simplify.rewrite true\n\nlemma helper (h : 5 \u2264 1) : false := by {\n  have H := nat.le.dest h,\n  have not_H : \u00ac \u2203 (k : \u2115), 5 + k = 1 := sorry,\n  exact absurd H not_H,\n}\n\nexample : \u00ac min_fac_helper 0 2 := by {\n  unfold min_fac_helper,\n  intro h,\n  cases h with h\u2081 h\u2082,\n  clear h\u2081, -- because h\u2081 : true\n  rw nat.min_fac_one at h\u2082,\n  exact helper h\u2082,\n}\n\nlemma test1 : (2 : \u211d) + 2 = 4 := by norm_num1\nlemma test2 : (12345.2 : \u211d) \u2260 12345.3 := by norm_num1\nlemma test3 : (73 : \u211d) < 789/2 := by norm_num1\nlemma test4 : 123456789 + 987654321 = 1111111110 := by norm_num1\nlemma test5 (R : Type*) [ring R] : (2 : R) + 2 = 4 := by norm_num1\nlemma test6 (F : Type*) [linear_ordered_field F] : (2 : F) + 2 < 5 := by norm_num1\nlemma test7 : nat.prime (2^13 - 1) := by norm_num1\nlemma test8 : \u00ac nat.prime (2^11 - 1) := by norm_num\nlemma test9 (x : \u211d) (h : x = 123 + 456) : x = 579 := by norm_num at h; assumption\n\n\n#print test1\n-- (id\n--    ((congr (congr_arg eq (norm_num.add_bit0_bit0 1 1 2 norm_num.one_succ)) (eq.refl 4)).trans\n--       (eq_true_intro (eq.refl 4)))).mpr\n--   trivial\n/-short proof for test1:-/\n\nexample : (2 : \u211d) + 2 = 4 := norm_num.add_bit0_bit0 1 1 2 norm_num.one_succ\n-- 1 + 1 = 2 from one_succ => 1 * 2 + 1 * 2 = 2 * 2 by add_bit0_bit0 => 2 + 2 = 4 Qed.\n\nexample :(2 : \u211d) + 1 = 3 := norm_num.bit0_succ 1\n\nexample :(2 : \u211d) + 3 = 5 := norm_num.add_bit0_bit1 1 1 2 norm_num.one_succ\n\nexample :(15 : \u211d) + 5 = 20 := \n  norm_num.add_bit1_bit1 7 2 10 (norm_num.adc_bit1_bit0 3 1 5 (norm_num.adc_bit1_one 1 2 norm_num.one_succ))\n\nopen norm_num\nopen tactic\nmeta def apply_step : tactic unit :=\n  do \n    -- interactive.exact add_bit0_bit0\n    trace \"hello\"\n\nexample : (15 : \u211d) + 5 = 20 := by {\n  repeat {\n    apply add_bit0_bit0 <|> apply add_bit0_bit1 <|> apply add_bit1_bit1 <|> apply add_bit1_bit0\n  <|> apply one_succ <|> apply bit0_succ <|> apply adc_bit1_one },\n  -- <|> apply first tactic in the list => it's not backtracks\n}\n\n#print test2\n\n/-short proof for test2:\n12345 = 12345 by range (1, 5)\n.2 \u2260 .3 <= 2 \u2260 3 <= dec_trivial\n-/", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/tactics/norm_num.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7062167429364158}}
{"text": "/-\nCopyright (c) 2020 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n\n! This file was ported from Lean 3 source module data.is_R_or_C.lemmas\n! leanprover-community/mathlib commit 468b141b14016d54b479eb7a0fff1e360b7e3cf6\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.NormedSpace.FiniteDimension\nimport Mathbin.FieldTheory.Tower\nimport Mathbin.Data.IsROrC.Basic\n\n/-! # Further lemmas about `is_R_or_C` -/\n\n\nvariable {K E : Type _} [IsROrC K]\n\nnamespace Polynomial\n\nopen Polynomial\n\ntheorem of_real_eval (p : \u211d[X]) (x : \u211d) : (p.eval x : K) = aeval (\u2191x) p :=\n  (@aeval_algebraMap_apply_eq_algebraMap_eval \u211d K _ _ _ x p).symm\n#align polynomial.of_real_eval Polynomial.of_real_eval\n\nend Polynomial\n\nnamespace FiniteDimensional\n\nopen Classical\n\nopen IsROrC\n\nlibrary_note \"is_R_or_C instance\"/--\nThis instance generates a type-class problem with a metavariable `?m` that should satisfy\n`is_R_or_C ?m`. Since this can only be satisfied by `\u211d` or `\u2102`, this does not cause problems. -/\n\n\n/-- An `is_R_or_C` field is finite-dimensional over `\u211d`, since it is spanned by `{1, I}`. -/\n@[nolint dangerous_instance]\ninstance isROrC_to_real : FiniteDimensional \u211d K :=\n  \u27e8\u27e8{1, i}, by\n      rw [eq_top_iff]\n      intro a _\n      rw [Finset.coe_insert, Finset.coe_singleton, Submodule.mem_span_insert]\n      refine' \u27e8re a, im a \u2022 I, _, _\u27e9\n      \u00b7 rw [Submodule.mem_span_singleton]\n        use im a\n      simp [re_add_im a, Algebra.smul_def, algebra_map_eq_of_real]\u27e9\u27e9\n#align finite_dimensional.is_R_or_C_to_real FiniteDimensional.isROrC_to_real\n\nvariable (K E) [NormedAddCommGroup E] [NormedSpace K E]\n\n/-- A finite dimensional vector space over an `is_R_or_C` is a proper metric space.\n\nThis is not an instance because it would cause a search for `finite_dimensional ?x E` before\n`is_R_or_C ?x`. -/\ntheorem proper_isROrC [FiniteDimensional K E] : ProperSpace E :=\n  by\n  letI : NormedSpace \u211d E := RestrictScalars.normedSpace \u211d K E\n  letI : FiniteDimensional \u211d E := FiniteDimensional.trans \u211d K E\n  infer_instance\n#align finite_dimensional.proper_is_R_or_C FiniteDimensional.proper_isROrC\n\nvariable {E}\n\ninstance IsROrC.properSpace_submodule (S : Submodule K E) [FiniteDimensional K \u21a5S] :\n    ProperSpace S :=\n  proper_isROrC K S\n#align finite_dimensional.is_R_or_C.proper_space_submodule FiniteDimensional.IsROrC.properSpace_submodule\n\nend FiniteDimensional\n\nnamespace IsROrC\n\n@[simp, is_R_or_C_simps]\ntheorem reClm_norm : \u2016(reClm : K \u2192L[\u211d] \u211d)\u2016 = 1 :=\n  by\n  apply le_antisymm (LinearMap.mkContinuous_norm_le _ zero_le_one _)\n  convert ContinuousLinearMap.ratio_le_op_norm _ (1 : K)\n  \u00b7 simp\n  \u00b7 infer_instance\n#align is_R_or_C.re_clm_norm IsROrC.reClm_norm\n\n@[simp, is_R_or_C_simps]\ntheorem conjCle_norm : \u2016(@conjCle K _ : K \u2192L[\u211d] K)\u2016 = 1 :=\n  (@conjLie K _).toLinearIsometry.norm_toContinuousLinearMap\n#align is_R_or_C.conj_cle_norm IsROrC.conjCle_norm\n\n@[simp, is_R_or_C_simps]\ntheorem ofRealClm_norm : \u2016(ofRealClm : \u211d \u2192L[\u211d] K)\u2016 = 1 :=\n  LinearIsometry.norm_toContinuousLinearMap ofRealLi\n#align is_R_or_C.of_real_clm_norm IsROrC.ofRealClm_norm\n\nend IsROrC\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/IsROrC/Lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325345, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7062167279459641}}
{"text": "variable f : \u2115 \u2192 \u2115\nvariable h : \u2200 x : \u2115, f x \u2264 f (x + 1)\n\nexample : f 0 \u2264 f 3 :=\n  have f 0 \u2264 f 1, from h 0,\n  have f 0 \u2264 f 2, from le_trans this (h 1),\n  show f 0 \u2264 f 3, from le_trans this (h 2)\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0501.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.7061947600938396}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Robert Y. Lewis\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.tactic.linarith.verification\nimport Mathlib.tactic.linarith.preprocessing\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# `linarith`: solving linear arithmetic goals\n\n`linarith` is a tactic for solving goals with linear arithmetic.\n\nSuppose we have a set of hypotheses in `n` variables\n`S = {a\u2081x\u2081 + a\u2082x\u2082 + ... + a\u2099x\u2099 R b\u2081x\u2081 + b\u2082x\u2082 + ... + b\u2099x\u2099}`,\nwhere `R \u2208 {<, \u2264, =, \u2265, >}`.\nOur goal is to determine if the inequalities in `S` are jointly satisfiable, that is, if there is\nan assignment of values to `x\u2081, ..., x\u2099` such that every inequality in `S` is true.\n\nSpecifically, we aim to show that they are *not* satisfiable. This amounts to proving a\ncontradiction. If our goal is also a linear inequality, we negate it and move it to a hypothesis\nbefore trying to prove `false`.\n\nWhen the inequalities are over a dense linear order, `linarith` is a decision procedure: it will\nprove `false` if and only if the inequalities are unsatisfiable. `linarith` will also run on some\ntypes like `\u2124` that are not dense orders, but it will fail to prove `false` on some unsatisfiable\nproblems. It will run over concrete types like `\u2115`, `\u211a`, and `\u211d`, as well as abstract types that\nare instances of `linear_ordered_comm_ring`.\n\n## Algorithm sketch\n\nFirst, the inequalities in the set `S` are rearranged into the form `t\u1d62 R\u1d62 0`, where\n`R\u1d62 \u2208 {<, \u2264, =}` and each `t\u1d62` is of the form `\u2211 c\u2c7cx\u2c7c`.\n\n`linarith` uses an untrusted oracle to search for a certificate of unsatisfiability.\nThe oracle searches for a list of natural number coefficients `k\u1d62` such that `\u2211 k\u1d62t\u1d62 = 0`, where for\nat least one `i`, `k\u1d62 > 0` and `R\u1d62 = <`.\n\nGiven a list of such coefficients, `linarith` verifies that `\u2211 k\u1d62t\u1d62 = 0` using a normalization\ntactic such as `ring`. It proves that `\u2211 k\u1d62t\u1d62 < 0` by transitivity, since each component of the sum\nis either equal to, less than or equal to, or less than zero by hypothesis. This produces a\ncontradiction.\n\n## Preprocessing\n\n`linarith` does some basic preprocessing before running. Most relevantly, inequalities over natural\nnumbers are cast into inequalities about integers, and rational division by numerals is canceled\ninto multiplication. We do this so that we can guarantee the coefficients in the certificate are\nnatural numbers, which allows the tactic to solve goals over types that are not fields.\n\nPreprocessors are allowed to branch, that is, to case split on disjunctions. `linarith` will succeed\noverall if it succeeds in all cases. This leads to exponential blowup in the number of `linarith`\ncalls, and should be used sparingly. The default preprocessor set does not include case splits.\n\n## Fourier-Motzkin elimination\n\nThe oracle implemented to search for certificates uses Fourier-Motzkin variable elimination.\nThis technique transorms a set of inequalities in `n` variables to an equisatisfiable set in `n - 1`\nvariables. Once all variables have been eliminated, we conclude that the original set was\nunsatisfiable iff the comparison `0 < 0` is in the resulting set.\n\nWhile performing this elimination, we track the history of each derived comparison. This allows us\nto represent any comparison at any step as a positive combination of comparisons from the original\nset. In particular, if we derive `0 < 0`, we can find our desired list of coefficients\nby counting how many copies of each original comparison appear in the history.\n\n## Implementation details\n\n`linarith` homogenizes numerical constants: the expression `1` is treated as a variable `t\u2080`.\n\nOften `linarith` is called on goals that have comparison hypotheses over multiple types. This\ncreates multiple `linarith` problems, each of which is handled separately; the goal is solved as\nsoon as one problem is found to be contradictory.\n\nDisequality hypotheses `t \u2260 0` do not fit in this pattern. `linarith` will attempt to prove equality\ngoals by splitting them into two weak inequalities and running twice. But it does not split\ndisequality hypotheses, since this would lead to a number of runs exponential in the number of\ndisequalities in the context.\n\nThe Fourier-Motzkin oracle is very modular. It can easily be replaced with another function of type\n`certificate_oracle := list comp \u2192 \u2115 \u2192 tactic (rb_map \u2115 \u2115)`,\nwhich takes a list of comparisons and the largest variable\nindex appearing in those comparisons, and returns a map from comparison indices to coefficients.\nAn alternate oracle can be specified in the `linarith_config` object.\n\nA variant, `nlinarith`, adds an extra preprocessing step to handle some basic nonlinear goals.\nThere is a hook in the `linarith_config` configuration object to add custom preprocessing routines.\n\nThe certificate checking step is *not* by reflection. `linarith` converts the certificate into a\nproof term of type `false`.\n\nSome of the behavior of `linarith` can be inspected with the option\n`set_option trace.linarith true`.\nBecause the variable elimination happens outside the tactic monad, we cannot trace intermediate\nsteps there.\n\n## File structure\n\nThe components of `linarith` are spread between a number of files for the sake of organization.\n\n* `lemmas.lean` contains proofs of some arithmetic lemmas that are used in preprocessing and in\n  verification.\n* `datatypes.lean` contains data structures that are used across multiple files, along with some\n  useful auxiliary functions.\n* `preprocessing.lean` contains functions used at the beginning of the tactic to transform\n  hypotheses into a shape suitable for the main routine.\n* `parsing.lean` contains functions used to compute the linear structure of an expression.\n* `elimination.lean` contains the Fourier-Motzkin elimination routine.\n* `verification.lean` contains the certificate checking functions that produce a proof of `false`.\n* `frontend.lean` contains the control methods and user-facing components of the tactic.\n\n## Tags\n\nlinarith, nlinarith, lra, nra, Fourier Motzkin, linear arithmetic, linear programming\n-/\n\nnamespace linarith\n\n\n/-! ### Control -/\n\n/--\nIf `e` is a comparison `a R b` or the negation of a comparison `\u00ac a R b`, found in the target,\n`get_contr_lemma_name_and_type e` returns the name of a lemma that will change the goal to an\nimplication, along with the type of `a` and `b`.\n\nFor example, if `e` is `(a : \u2115) < b`, returns ``(`lt_of_not_ge, \u2115)``.\n-/\n/--\n`apply_contr_lemma` inspects the target to see if it can be moved to a hypothesis by negation.\nFor example, a goal `\u22a2 a \u2264 b` can become `a > b \u22a2 false`.\nIf this is the case, it applies the appropriate lemma and introduces the new hypothesis.\nIt returns the type of the terms in the comparison (e.g. the type of `a` and `b` above) and the\nnewly introduced local constant.\nOtherwise returns `none`.\n-/\n/--\n`partition_by_type l` takes a list `l` of proofs of comparisons. It sorts these proofs by\nthe type of the variables in the comparison, e.g. `(a : \u211a) < 1` and `(b : \u2124) > c` will be separated.\nReturns a map from a type to a list of comparisons over that type.\n-/\n/--\nGiven a list `ls` of lists of proofs of comparisons, `try_linarith_on_lists cfg ls` will try to\nprove `false` by calling `linarith` on each list in succession. It will stop at the first proof of\n`false`, and fail if no contradiction is found with any list.\n-/\n/--\nGiven a list `hyps` of proofs of comparisons, `run_linarith_on_pfs cfg hyps pref_type`\npreprocesses `hyps` according to the list of preprocessors in `cfg`.\nThis results in a list of branches (typically only one),\neach of which must succeed in order to close the goal.\n\nIn each branch, we partition the  list of hypotheses by type, and run `linarith` on each class\nin the partition; one of these must succeed in order for `linarith` to succeed on this branch.\nIf `pref_type` is given, it will first use the class of proofs of comparisons over that type.\n-/\n/--\n`filter_hyps_to_type restr_type hyps` takes a list of proofs of comparisons `hyps`, and filters it\nto only those that are comparisons over the type `restr_type`.\n-/\n/-- A hack to allow users to write `{restr_type := \u211a}` in configuration structures. -/\nend linarith\n\n\n/-! ### User facing functions -/\n\n/--\n`linarith reduce_semi only_on hyps cfg` tries to close the goal using linear arithmetic. It fails\nif it does not succeed at doing this.\n\n* If `reduce_semi` is true, it will unfold semireducible definitions when trying to match atomic\nexpressions.\n* `hyps` is a list of proofs of comparisons to include in the search.\n* If `only_on` is true, the search will be restricted to `hyps`. Otherwise it will use all\n  comparisons in the local context.\n-/\n-- if the target is an equality, we run `linarith` twice, to prove \u2264 and \u2265.\n\n/- If we are proving a comparison goal (and not just `false`), we consider the type of the\n   elements in the comparison to be the \"preferred\" type. That is, if we find comparison\n   hypotheses in multiple types, we will run `linarith` on the goal type first.\n   In this case we also recieve a new variable from moving the goal to a hypothesis.\n   Otherwise, there is no preferred type and no new variable; we simply change the goal to `false`. -/\n\n/--\nTries to prove a goal of `false` by linear arithmetic on hypotheses.\nIf the goal is a linear (in)equality, tries to prove it by contradiction.\nIf the goal is not `false` or an inequality, applies `exfalso` and tries linarith on the\nhypotheses.\n\n* `linarith` will use all relevant hypotheses in the local context.\n* `linarith [t1, t2, t3]` will add proof terms t1, t2, t3 to the local context.\n* `linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses\n  `h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.\n* `linarith!` will use a stronger reducibility setting to identify atoms.\n\nConfig options:\n* `linarith {exfalso := ff}` will fail on a goal that is neither an inequality nor `false`\n* `linarith {restrict_type := T}` will run only on hypotheses that are inequalities over `T`\n* `linarith {discharger := tac}` will use `tac` instead of `ring` for normalization.\n  Options: `ring2`, `ring SOP`, `simp`\n* `linarith {split_hypotheses := ff}` will not destruct conjunctions in the context.\n-/\n/--\n`linarith` attempts to find a contradiction between hypotheses that are linear (in)equalities.\nEquivalently, it can prove a linear inequality by assuming its negation and proving `false`.\n\nIn theory, `linarith` should prove any goal that is true in the theory of linear arithmetic over\nthe rationals. While there is some special handling for non-dense orders like `nat` and `int`,\nthis tactic is not complete for these theories and will not prove every true goal. It will solve\ngoals over arbitrary types that instantiate `linear_ordered_comm_ring`.\n\nAn example:\n```lean\nexample (x y z : \u211a) (h1 : 2*x  < 3*y) (h2 : -4*x + 2*z < 0)\n        (h3 : 12*y - 4* z < 0)  : false :=\nby linarith\n```\n\n`linarith` will use all appropriate hypotheses and the negation of the goal, if applicable.\n\n`linarith [t1, t2, t3]` will additionally use proof terms `t1, t2, t3`.\n\n`linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses\n`h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.\n\n`linarith!` will use a stronger reducibility setting to try to identify atoms. For example,\n```lean\nexample (x : \u211a) : id x \u2265 x :=\nby linarith\n```\nwill fail, because `linarith` will not identify `x` and `id x`. `linarith!` will.\nThis can sometimes be expensive.\n\n`linarith {discharger := tac, restrict_type := tp, exfalso := ff}` takes a config object with five\noptional arguments:\n* `discharger` specifies a tactic to be used for reducing an algebraic equation in the\n  proof stage. The default is `ring`. Other options currently include `ring SOP` or `simp` for basic\n  problems.\n* `restrict_type` will only use hypotheses that are inequalities over `tp`. This is useful\n  if you have e.g. both integer and rational valued inequalities in the local context, which can\n  sometimes confuse the tactic.\n* `transparency` controls how hard `linarith` will try to match atoms to each other. By default\n  it will only unfold `reducible` definitions.\n* If `split_hypotheses` is true, `linarith` will split conjunctions in the context into separate\n  hypotheses.\n* If `exfalso` is false, `linarith` will fail when the goal is neither an inequality nor `false`.\n  (True by default.)\n\nA variant, `nlinarith`, does some basic preprocessing to handle some nonlinear goals.\n\nThe option `set_option trace.linarith true` will trace certain intermediate stages of the `linarith`\nroutine.\n-/\n/--\nAn extension of `linarith` with some preprocessing to allow it to solve some nonlinear arithmetic\nproblems. (Based on Coq's `nra` tactic.) See `linarith` for the available syntax of options,\nwhich are inherited by `nlinarith`; that is, `nlinarith!` and `nlinarith only [h1, h2]` all work as\nin `linarith`. The preprocessing is as follows:\n\n* For every subterm `a ^ 2` or `a * a` in a hypothesis or the goal,\n  the assumption `0 \u2264 a ^ 2` or `0 \u2264 a * a` is added to the context.\n* For every pair of hypotheses `a1 R1 b1`, `a2 R2 b2` in the context, `R1, R2 \u2208 {<, \u2264, =}`,\n  the assumption `0 R' (b1 - a1) * (b2 - a2)` is added to the context (non-recursively),\n  where `R \u2208 {<, \u2264, =}` is the appropriate comparison derived from `R1, R2`.\n-/\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/tactic/linarith/frontend.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7061947565631606}}
{"text": "/- Copyright (c) 2022 Sina Hazratpour. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n----------------\n# Gaussian Integers\nSina Hazratpour\nAdopted from Mathematics in Lean (by Avigad et al)\nhttps://leanprover-community.github.io/mathematics_in_lean/06_Abstract_Algebra.html#building-the-gaussian-integers\nIntroduction to Proof\nMATH 301, Johns Hopkins University, Fall 2022\n-/\n\nimport ..prooflab\nimport .lec11_type_classes\n\nimport data.int.basic\n\n\n\nnamespace PROOFS\nnamespace STR\n\nuniverse u\n\n#check has_zero\n\n\nclass with_zero_str (X : Type u) := (zero [] : X)\n\n#check with_zero_str\n#check with_zero_str \u2115\n\n\ninstance : with_zero_str \u2115 := \u27e8 nat.zero \u27e9\ninstance : with_zero_str bool := \u27e8 ff \u27e9\n\n#check @with_zero_str.zero\n\ninstance with_zero_product {A B : Type u} [with_zero_str A] [with_zero_str B] :\n  with_zero_str (A \u00d7 B) :=\n{\n  zero := (with_zero_str.zero A, with_zero_str.zero B),\n}\n\n\n#eval with_zero_str.zero (bool \u00d7 \u2115)\n\n\n/-! Gaussian Integers -/\n\n/-\nhttps://en.wikipedia.org/wiki/Gaussian_integer\n-/\n\n@[ext]\nstructure gaussian_int :=\n(re : \u2124)\n(im : \u2124)\n\n#check gaussian_int\n\nnotation ` \u2124[i] ` := gaussian_int\n\n\n\ninstance : has_repr \u2124[i] :=\n{ repr := \u03bb x,  repr x.re ++ \"+\" ++ \"i\" ++  repr x.im}\n\n\n\n/- We prove some basic facts about Gaussian integers in the following namespace\n-/\n\n\n\n\n\nnamespace gaussian_int\n\ndef zero : \u2124[i]  :=\n{\n  re := 0,\n  im := 0,\n}\n\n\n#check zero -- \u27e80,0\u27e9\n\n\ninstance : has_zero \u2124[i]  := \u27e8 \u27e80 ,0 \u27e9  \u27e9 -- we show that the Gaussian integers have zero by providing an instance of type class `has_zero`\n\n\n\n#check zero -- Lean automatically understands this as `gaussian_int.zero`. \n#check nat.zero\n \n#check mul_zero -- this takes advantage zero as an instance of has_zero \u2124[i]  rather than `zero` defined at the top of the namespace. \n\n\ninstance : has_one \u2124[i]  :=  \u27e8 \u27e81, 0\u27e9  \u27e9\n\n\ninstance : has_mul \u2124[i]  := \u27e8 \u03bb x, \u03bb y, \u27e8x.re * y.re - x.im * y.im, x.re * y.im + x.im * y.re\u27e9  \u27e9\n\n#eval zero * zero -- this works because we have instances of `has_zero` and `mul_zero`. \n#eval (\u27e81, 0\u27e9 : \u2124[i]) * \u27e80 , 1\u27e9\n#eval (\u27e81, 0\u27e9 : \u2124[i]) * \u27e80 , 2\u27e9\n#eval (\u27e81, 0\u27e9 : \u2124[i]) * \u27e80 , 3\u27e9\n\n/-\n0+i6\n-/\n#eval (\u27e82, 0\u27e9 : \u2124[i]) * \u27e80 , 3\u27e9\n\n\ninstance : has_add \u2124[i]  := \u27e8\u03bb x y, \u27e8x.re + y.re, x.im + y.im\u27e9\u27e9\n\n\n#eval (\u27e82, 0\u27e9 : \u2124[i]) + \u27e80 , 3\u27e9\n\n\ninstance : has_neg \u2124[i]  := \u27e8 \u03bb x , \u27e8 - x.re, - x.im\u27e9  \u27e9\n\n#eval - (\u27e82, 0\u27e9 : \u2124[i])\n\nlemma zero_def :\n  (0 : \u2124[i]) = \u27e80, 0\u27e9 :=\nbegin\n  refl,\nend\n\n\n#check has_zero.zero\n\n@[simp]\nlemma zero_re_def :\n  (0 :\u2124[i]).re = 0 :=\nbegin\n  refl,\nend\n\n\n@[simp]\nlemma zero_im_def :\n  (0 :\u2124[i]).im = 0 :=\nbegin\n  refl,\nend\n\n\n\n@[simp]\nlemma one_def :\n  (1 :\u2124[i]) = \u27e81, 0\u27e9 :=\nbegin\n  refl,\nend\n\n\n@[simp]\nlemma one_re_def :\n  (1 :\u2124[i]).re = 1 :=\nbegin\n  refl,\nend\n\n\n@[simp]\nlemma one_im_def :\n  (1 :\u2124[i]).im = 0 :=\nbegin\n  refl,\nend\n\n\ntheorem add_def (x y : \u2124[i]) :\n  x + y = \u27e8x.re + y.re, x.im + y.im\u27e9 :=\nbegin\n refl,\nend\n\n\ntheorem neg_def (x : \u2124[i]) :\n  -x = \u27e8-x.re, -x.im\u27e9 :=\nbegin\n  refl,\nend\n\n@[simp]\ntheorem mul_def (x y : \u2124[i]) :\n  x * y = \u27e8x.re * y.re - x.im * y.im, x.re * y.im + x.im * y.re\u27e9 :=\nbegin\n  refl,\nend\n\n\n@[simp]\ntheorem add_re_def (x y : \u2124[i]) :\n  (x + y).re = x.re + y.re :=\nbegin\n  refl,\nend\n\n@[simp]\ntheorem add_im_def (x y : \u2124[i]) :\n  (x + y).im = x.im + y.im :=\nbegin\n  refl,\nend\n\n\n@[simp]\ntheorem mul_re_def (x y : \u2124[i]) :\n  (x * y).re = x.re * y.re - x.im * y.im:=\nbegin\n  refl,\nend\n\n@[simp]\ntheorem mul_im_def (x y : \u2124[i]) :\n  (x * y).im = x.re * y.im + x.im * y.re:=\nbegin\n  refl,\nend\n\n\nlemma add_assoc (x y z : \u2124[i]) :\n  (x + y) + z = x + (y + z) :=\nbegin\n   ext, -- By extensionality, we have to prove that the real part and the imaginary part of the two sides of the goal are equal. We reduce the problem to the problem of associativity of addition of integers.\n   {repeat {rw add_re_def}, -- we took the real part of the sums separately and then we added them together,\n    rw add_assoc,\n   },\n   -- {simp, rw add_assoc},-- to this end, we use\n   --{rw add_def, unfold gaussian_int.im, rw add_assoc},\n   {\n    apply add_assoc,\n   }\nend\n\n\nlemma mul_assoc (x y z : \u2124[i]) :\n  (x * y) * z = x * (y * z) :=\nbegin\n   ext, -- we are trying to show an equality of two instances of the structure `guassian_int`.\n   repeat {rw mul_def},\n   repeat {simp},\n   {\n    ring_nf, -- we proved this by using distributivity of mult over addition of integers which are all part of `ring` tactic.\n   },\n   {\n    ring_nf, -- we proved this by using distributivity of mult over addition of integers which are all part of `ring` tactic.\n   },\nend\n\n\nlemma mul_add_distrib (a b c : \u2124[i]) :\n  a * (b + c) = a * b + a * c :=\nbegin\n  ext,\n  repeat{simp},  -- works because of the lemma `mul_re_def` and `add_def`\n  repeat{ring_nf},\n    --rw [mul_re_def, add_def],\nend\n\n\nlemma mul_add_distrib_alt (a b c : \u2124[i]) :\n  a * (b + c) = a * b + a * c :=\nbegin\n  ext,\n  repeat{simp; ring_nf}, -- works because of the lemma `mul_re_def` and `add_def`\nend\n\n\nlemma add_mul_distrib (a b c : \u2124[i]) :\n  (a + b) * c = a * c + b * c :=\nbegin\n  ext,\n  repeat{simp; ring_nf},\nend\n\n\n\nlemma add_comm (a b : \u2124[i]) :\n   a + b = b + a :=\nbegin\n  ext, --\n  {\n    repeat{rw add_re_def}, -- we want to reduce the addition of guassian integers to the addition of integers\n    rw add_comm,\n  },\n  {\n     repeat{rw add_im_def}, -- we want to reduce the addition of guassian integers to the addition of integers\n    rw add_comm,\n  },\nend\n\nlemma mul_comm (a b : \u2124[i]) :\n  a * b = b * a :=\nbegin\n  ext,\n  { simp [mul_comm], },\n  {simp [mul_comm], ring_nf, }\nend\n\n\nlemma add_zero (a : \u2124[i]) :\n  a + 0 = a :=\nbegin\n  ext,\n  {\n    simp,\n  },\n  {\n    apply add_zero,\n  },\nend\n\n\nlemma zero_add (a : \u2124[i]) :\n  0 + a = a :=\nbegin\n  ext a,\n  repeat {apply zero_add},\nend\n\n\n\nlemma mul_one (a : \u2124[i]) :\n   a * 1 = a :=\nbegin\n  ext a,\n  --repeat {apply  mul_one},\n  repeat {simp},\nend\n\n\nlemma one_mul (a : \u2124[i]) :\n  1 * a = a :=\nbegin\n  ext,\n   repeat {simp},\nend\n\n\nend gaussian_int\n\n\n\n\n-- the structure of multiplicative semigroup: A semigroup structure consists of a binary operation (called multiplication) such that the operation is __associative__. \n\n\nclass mult_semigroup_str (S : Type u) extends has_mul S :=\n(mul_assoc : \u2200 a b c : S, (a * b) * c = a * (b * c))\n\n-- the structure of additive semigroup\nclass additive_semigroup_str (S : Type u) extends has_add S :=\n(add_assoc : \u2200 a b c : S, (a + b) + c = a + (b + c))\n\n\n\n\ninstance : mult_semigroup_str \u2115 :=\n{\n  -- mul := \u03bb x, \u03bb y, x * y,\n  mul := has_mul.mul,\n  mul_assoc := nat.mul_assoc,\n}\n\n\ninstance : additive_semigroup_str \u2115 :=\n{\n  add := \u03bb x, \u03bb y, x + y,\n  add_assoc := nat.add_assoc,\n}\n\n#check 10 * 2\n#check (10 : \u2124[i]) * 2\n#eval (10 : \u2124[i]) * 2\n\n#eval 10 * 2\n#eval (\u27e81,2\u27e9 : \u2124[i] ) * \u27e83,4\u27e9\n\n\n\ninstance : mult_semigroup_str \u2124  :=\n{\n  mul := has_mul.mul, -- we retrieve the defintion of multiplication of \u2124[i] from the instance of the class `has_mul`.\n  mul_assoc := by {intros x y z, rw int.mul_assoc},\n}\n\n\n\n\ninstance : mult_semigroup_str \u2124[i]  :=\n{\n  mul := has_mul.mul, -- we retrieve the defintion of multiplication of \u2124[i] from the instance of the class `has_mul`.\n  mul_assoc := by {intros x y z, rw gaussian_int.mul_assoc},\n}\n\n\ninstance : additive_semigroup_str \u2124[i]  :=\n{\n  add := has_add.add,\n  add_assoc := by {intros x y z, rw gaussian_int.add_assoc},\n}\n\n\n\n\n\n/- A __monoid__ is a type equipped with an associative binary operation and an identity element. -/\n\n\nclass mult_monoid_str  (M : Type u) extends mult_semigroup_str M, has_one M :=\n(mul_one :  \u2200 a : M, a * 1 = a )\n(one_mul : \u2200 a : M, 1 * a = a )\n\nclass additive_monoid_str  (M : Type u) extends additive_semigroup_str M, has_zero M :=\n(add_zero :  \u2200 a : M, a + 0 = a )\n(zero_add : \u2200 a : M, 0 + a = a )\n\n\ndef npower {M : Type u} [mult_monoid_str M] : \u2115 \u2192 M \u2192 M\n  | 0 m := 1\n  | (n + 1) m := m * (npower n m)\n\n\n\ninstance : mult_monoid_str \u2115  :=\n{\n  mul_one :=  by { intro a, rw nat.mul_one, },\n  one_mul :=  by { intro a, rw nat.one_mul, },\n}\n\n\n\ninstance : mult_monoid_str \u2124  :=\n{\n  mul_one :=  by { intro a, rw int.mul_one, },\n  one_mul :=  by { intro a, rw int.one_mul, },\n}\n\n\n\n\n-- __API__ for mul_monoid_str (capturing the core properties of the structure, but specification independent-- however you define monoid structure the following statements must be true about it)\n@[simp]\nlemma mult_mon_assoc {M : Type u} [mult_monoid_str M] (x y z : M) : \n  x * y * z = x * (y * z) := \nbegin\n  apply mult_monoid_str.to_mult_semigroup_str.mul_assoc,\nend \n\n@[simp]\nlemma mult_mon_mul_one {M : Type u} [mult_monoid_str M] (x : M) : \n  x * 1 = x  := \nbegin\n  apply mult_monoid_str.mul_one,\nend \n\n\n@[simp]\nlemma mult_mon_one_mul {M : Type u} [mult_monoid_str M] (x : M) : \n  1 * x = x  := \nbegin\n  apply mult_monoid_str.one_mul,\nend \n\n\n\n@[simp]\nlemma add_mon_zero_add {M : Type u} [additive_monoid_str M] (x : M) : \n  0 + x = x  := \nbegin\n  apply additive_monoid_str.zero_add,\nend \n\n\n\n-- instance : mult_monoid_str \u2124[i] := \n-- { mul := _,\n--   mul_assoc := _,\n--   one := _,\n--   mul_one := _,\n--   one_mul := _ }\n\n/- We don't have to provide instances of `mul`, `mul_assoc` and `one` becasue they have been provided before as instances of `mult_semigroup \u2124[i]` and `has_one \u2124[i]` respectively. -/\n\ninstance : mult_monoid_str \u2124[i]  :=\n{\n  mul_one :=  by { intro a, rw gaussian_int.mul_one, },\n  one_mul :=  by { intro a, rw gaussian_int.one_mul, },\n}\n\ninstance : additive_monoid_str \u2124[i] :=\n{\n  add_zero := by { intro a, rw gaussian_int.add_zero, },\n  zero_add := by { intro a, rw gaussian_int.zero_add, },\n}\n\n/-\n0+i2\n-/\n\n#eval npower 2 (\u27e81, 1\u27e9 : \u2124[i])\n\n\n\nend STR\nend PROOFS\n", "meta": {"author": "sinhp", "repo": "ProofLab", "sha": "f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2", "save_path": "github-repos/lean/sinhp-ProofLab", "path": "github-repos/lean/sinhp-ProofLab/ProofLab-f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2/src/lectures/lec12_gaussian_integers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.706188176175008}}
{"text": "/-\nCopyright (c) 2022/09 Daniil Homza. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Daniil Homza\n-/\nimport probability.variance\n--import probability.notation ???\n/-!\n# The Weak law of Large number \n\nWe prove the `Weak Law of Large number`. The proof is well-known and\nbased on Chebyshev Inequality\n\n(meas_ge_le_variance_div_sq in probability.variance)\n\n\u2119 {\u03c9 | c \u2264 |X \u03c9 - \ud835\udd3c[X]|} \u2264 ennreal.of_real (Var[X] / c ^ 2)\n\nProof will be consist of calculating of expected value \nand variance of (\u2211 i in range m, X i) and appling Chebyshev inequality \nin that case. \n\nWe proof that for sequencese of random variable with \n\ud835\udd3c[X_i]=\ud835\udd3c[X_j], Var[X_i]=Var[X_j] we have \n\n* `exp_sum` : expected value of a sum `\ud835\udd3c[(\u2211 i in range m, X i)] = m*\ud835\udd3c[(X 0)]`\n* `var_sum`: variance of a sum of independent r.v. `Var[(\u2211 i in range m, X i)] = m*Var[(X 0)]`\n* `weak_law`: Weak Law of Large number\n`tendsto (\u03bb (n : \u2115), \u2119 {\u03c9 | c*n \u2264|(\u2211 i in range n, X i ) \u03c9 - n*\ud835\udd3c[(X 0)]|}) at_top (\ud835\udcdd 0)`\n\nNote that Weak_Law has no assumption on identical distribution of `X i`.\n\n## Implementation\n\nWe follow the proof by book \nOliver C. Ibe,\nin Fundamentals of Applied Probability and Random Processes (Second Edition), 2014\nProposition 6.1.\n\n\n### Usefull definition\n\n\n`\u2119 - \\ bp` - probability measure (probability)\n`\ud835\udd3c - \\ bbE` - Expected value \n`\u2200 = \\ forall` - for all\n`\u2203 - \\ ex` - exists\n`\u03bb = \\ la` - lambda (lambda calculus)\n`\u2115 = \\ Nat` - natural number(include 0)\n`\u03c9 = \\ om` - omega, member of probability space(event)\n`\ud835\udcdd = \\ nhds` - neighborhoods (in topological space)\n-/\n\nopen measure_theory filter finset \n\nnoncomputable theory\n\nopen_locale topological_space big_operators probability_theory\n\n-- topological space is responsible to nieghborhoods in weak_law theorem \n\n-- big operators is responsible to sum\n\n/- ennreal The extended nonnegative real numbers. This is usually denoted [0, \u221e],\n and is relevant as the codomain of a measure. -/\n\n/- nnreal In this file we define nnreal (notation: \u211d\u22650) \n to be the type of non-negative real numbers, a.k.a. the interval [0, \u221e) -/\n\nnamespace probability_theory\n\n\nvariables {\u03a9 : Type*} [measure_space \u03a9] [is_probability_measure (\u2119 : measure \u03a9)]{\u03c9:\u03a9}{c:\u211d}\n\n\n/-- Chebyshev inequality can be aplpied for sum of random variables with appropriate\nexpected value and variance  -/\n\nlemma sum_cheb {X : \u2115 \u2192 \u03a9 \u2192 \u211d} \n(hint : \u2200 i, integrable (X i)) (hindep : pairwise (\u03bb i j, indep_fun (X i) (X j)))\n(same_exp: \u2200 (m:\u2115), \ud835\udd3c[(X m)] = \ud835\udd3c[(X 0)]) (same_var: \u2200 (m:\u2115), Var[(X m)]=Var[(X 0)]) \n(hs : \u2200 i, mem_\u2112p (X i) 2) (hc : 0 < c):\n \u2200 (m:\u2115), (m>0) -> (\u2119 {\u03c9 | c*m \u2264 |(\u2211 i in range m, X i ) \u03c9 - m*\ud835\udd3c[(X 0)]|}) \u2264 ennreal.of_real (Var[(X 0)] / (c^2*m)):=\nbegin\n  have exp_sum: \u2200 (m:\u2115), \ud835\udd3c[(\u2211 i in range m, X i)] = m*\ud835\udd3c[(X 0)],\n    begin\n\n    have sum_exp: \u2200 (m:\u2115), \ud835\udd3c[(\u2211 i in range m, X i)] = \u2211 i in range m, \ud835\udd3c[(X i)],\n      begin\n      intro m,\n      simp[integral_finset_sum, hint],\n      end,\n    intro m,\n    rw sum_exp,\n    simp only[same_exp],\n    simp,\n    end,\n\n  have var_sum: \u2200 cl(m:\u2115), Var[(\u2211 i in range m, X i)] = m*Var[(X 0)],\n    begin\n\n    have sum_var: \u2200 (m:\u2115), Var[(\u2211 i in range m, X i)] = \u2211 i in range m, Var[(X i)],\n      begin\n      intro m,\n      rw indep_fun.variance_sum,\n      intros i im,\n      specialize hs i,\n      exact hs,\n      intros i j p pr prn,\n      specialize hindep i p prn,\n      exact hindep,\n      end,\n    intro m,\n    simp[sum_var,same_var],\n    end,\n\n  have simplif_eq: \u2200 (m:\u2115), (m>0) -> ennreal.of_real (Var[(X 0)] / (c^2*m))=ennreal.of_real((Var[(X 0)]* m) / (c*m) ^ 2):=\n    begin\n    intros m mp,\n    rw [\u2190 div_inv_eq_mul Var[X 0], div_div],\n    congrm ennreal.of_real (Var[X 0] / _),\n    ring_nf,\n    congrm (_*c^2),\n    rw \u2190 div_eq_inv_mul,\n    rw pow_two,\n    simp[mul_div_cancel'''],\n    end,\n  have int2: \u2200 (m:\u2115), mem_\u2112p (\u2211 i in range m, X i ) 2,\n    intro m,\n    ring_nf,\n    refine mem_\u2112p_finset_sum' (range m) _,\n    intros i ip,\n    specialize hs i,\n    exact hs,\n\n  have ineq: \u2200 (m:\u2115), (m>0) -> (\u2119 {\u03c9 | c*m \u2264 |(\u2211 i in range m, X i ) \u03c9 - m*\ud835\udd3c[(X 0)]|}) \u2264 ennreal.of_real (Var[(\u2211 i in range m, X i)] / (c*m) ^ 2),\n    begin\n    intros m mp,\n    have C: \u2200 (m:\u2115), (m>0) -> 0<c*m,\n      intros m mp,\n      simp[hc, mp],\n      exact mp,\n      specialize C m mp,\n      specialize exp_sum m,\n      rw \u2190 exp_sum,\n      specialize int2 m,\n      apply meas_ge_le_variance_div_sq,\n      exact int2,\n      exact C,\n    end,\n\n  have B: \u2200 (m:\u2115), Var[(\u2211 i in range m, X i)] = Var[(X 0)]*m,\n    begin\n    intro m,\n    specialize var_sum m,\n    rw var_sum,\n   finish,\n    end,\n  intros m mp,\n  specialize var_sum m,\n  specialize ineq m mp,\n  specialize simplif_eq m mp,\n    specialize B m,\n  rw simplif_eq,\n  rw \u2190 B,\n  exact ineq,\nend\n\n\ntheorem weak_law {X : \u2115 \u2192 \u03a9 \u2192 \u211d} \n(hint : \u2200 i, integrable (X i)) (hindep : pairwise (\u03bb i j, indep_fun (X i) (X j)))\n(same_exp: \u2200 (m:\u2115), \ud835\udd3c[(X m)] = \ud835\udd3c[(X 0)]) (same_var: \u2200 (m:\u2115), Var[(X m)]=Var[(X 0)]) \n(hs : \u2200 i, mem_\u2112p (X i) 2)(hc : 0 < c): \ntendsto (\u03bb (n : \u2115), \u2119 {\u03c9 | c*n \u2264|(\u2211 i in range n, X i ) \u03c9 - n*\ud835\udd3c[(X 0)]|}) at_top (\ud835\udcdd 0) :=\nbegin\n\nrw ennreal.tendsto_at_top_zero,\nintros e e_pos,\nlet N:= nat.ceil(Var[(X 0)]/(c^2*(ennreal.to_real(e)))),\n\nhave A: let N := \u2308Var[X 0] / (c ^ 2 * e.to_real)\u2309\u208a in \u2200 (n: \u2115) (n_pos : n \u2265 N),\n    ennreal.of_real (Var[(X 0)]/(c^2*n)) \u2264 e :=\nbegin\n  intros N n hn,\n  -- annoying special case n = 0\n  rcases nat.eq_zero_or_pos n with (rfl | hn0), { simp, },\n  -- annoying special case e    = \u221e\n  rcases eq_top_or_lt_top e with (rfl | he), { simp, },\n  -- using N just makes things more annoying. Why not just not define N at all?\n  change \u2308 _ \u2309\u208a \u2264 n at hn,\n  -- get rid of ceiling\n  rw nat.ceil_le at hn,\n  -- get rid of ennreal stuff in goal\n  apply ennreal.of_real_le_of_le_to_real,\n  -- clear denominators (will show they're positive later)\n  rw div_le_iff at hn \u22a2,\n  { -- main goal now easy\n    convert hn using 1,\n    ring, },\n  { -- positivity side goal: a bit annoying that I need to use theorems and not tactics here\n    exact mul_pos (pow_pos hc 2) (by exact_mod_cast hn0), },\n  { -- second positivity side goal: here we still have to deal with e\n    refine mul_pos (pow_pos hc 2) _,\n    rw ennreal.to_real_pos_iff,\n    exact \u27e8e_pos, he\u27e9, },\nend,\n\n\nhave sum_cheb1: \u2200 (n:\u2115), (n>0) -> (\u2119 {\u03c9 | c*n \u2264 |(\u2211 i in range n, X i ) \u03c9 - n*\ud835\udd3c[(X 0)]|}) \u2264 ennreal.of_real (Var[(X 0)] / (c^2*n)):=\nbegin\n  exact (sum_cheb hint hindep same_exp same_var hs hc),\nend,\nrcases nat.eq_zero_or_pos N with h1 | h2,\nuse 1,\nintros n n1,\nhave n0: n>0,\n  simp[n1],\n  rcases nat.eq_zero_or_pos n with q1 | q2,\n  exfalso,\n  rw q1 at n1,\n  finish using n1,\n  exact q2,\n  specialize sum_cheb1 n n0,\n  apply le_trans sum_cheb1,\n  have t0: n\u2265N,\n  rw h1,\n  simp[n0],\n  specialize A n t0,\n  exact A,\n  use N,\n  intros n nbigN,\n  have n0: n>0,\n  rcases nat.eq_zero_or_pos n with s1 | s2,\n  exfalso,\n  rw s1 at nbigN,\n  have r0: 0<0,\n  exact (lt_of_lt_of_le h2 nbigN),\n  finish using r0,\n  exact s2,\n  specialize sum_cheb1 n n0,\n  apply le_trans sum_cheb1,\n  specialize A n nbigN,\n  exact A,\n\n\nend\nend probability_theory", "meta": {"author": "epsilopoint", "repo": "Formal_verification_Weak_Law_Lean", "sha": "06de6deec50e68f31e8492f7d9d4dca321810b6c", "save_path": "github-repos/lean/epsilopoint-Formal_verification_Weak_Law_Lean", "path": "github-repos/lean/epsilopoint-Formal_verification_Weak_Law_Lean/Formal_verification_Weak_Law_Lean-06de6deec50e68f31e8492f7d9d4dca321810b6c/src/Weak-Law.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7061881739707534}}
{"text": "/-\nCopyright (c) 2022 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller, Vincent Beffara\n-/\nimport combinatorics.simple_graph.connectivity\nimport data.nat.lattice\n\n/-!\n# Graph metric\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis module defines the `simple_graph.dist` function, which takes\npairs of vertices to the length of the shortest walk between them.\n\n## Main definitions\n\n- `simple_graph.dist` is the graph metric.\n\n## Todo\n\n- Provide an additional computable version of `simple_graph.dist`\n  for when `G` is connected.\n\n- Evaluate `nat` vs `enat` for the codomain of `dist`, or potentially\n  having an additional `edist` when the objects under consideration are\n  disconnected graphs.\n\n- When directed graphs exist, a directed notion of distance,\n  likely `enat`-valued.\n\n## Tags\n\ngraph metric, distance\n\n-/\n\nnamespace simple_graph\nvariables {V : Type*} (G : simple_graph V)\n\n/-! ## Metric -/\n\n/-- The distance between two vertices is the length of the shortest walk between them.\nIf no such walk exists, this uses the junk value of `0`. -/\nnoncomputable\ndef dist (u v : V) : \u2115 := Inf (set.range (walk.length : G.walk u v \u2192 \u2115))\n\nvariables {G}\n\nprotected\nlemma reachable.exists_walk_of_dist {u v : V} (hr : G.reachable u v) :\n  \u2203 (p : G.walk u v), p.length = G.dist u v :=\nnat.Inf_mem (set.range_nonempty_iff_nonempty.mpr hr)\n\nprotected\nlemma connected.exists_walk_of_dist (hconn : G.connected) (u v : V) :\n  \u2203 (p : G.walk u v), p.length = G.dist u v :=\n(hconn u v).exists_walk_of_dist\n\nlemma dist_le {u v : V} (p : G.walk u v) : G.dist u v \u2264 p.length := nat.Inf_le \u27e8p, rfl\u27e9\n\n@[simp]\nlemma dist_eq_zero_iff_eq_or_not_reachable {u v : V} : G.dist u v = 0 \u2194 u = v \u2228 \u00ac G.reachable u v :=\nby simp [dist, nat.Inf_eq_zero, reachable]\n\nlemma dist_self {v : V} : dist G v v = 0 := by simp\n\nprotected\nlemma reachable.dist_eq_zero_iff {u v : V} (hr : G.reachable u v) :\n  G.dist u v = 0 \u2194 u = v := by simp [hr]\n\nprotected\nlemma reachable.pos_dist_of_ne {u v : V} (h : G.reachable u v) (hne : u \u2260 v) : 0 < G.dist u v :=\nnat.pos_of_ne_zero (by simp [h, hne])\n\nprotected\nlemma connected.dist_eq_zero_iff (hconn : G.connected) {u v : V} :\n  G.dist u v = 0 \u2194 u = v := by simp [hconn u v]\n\nprotected\nlemma connected.pos_dist_of_ne {u v : V} (hconn : G.connected) (hne : u \u2260 v) : 0 < G.dist u v :=\nnat.pos_of_ne_zero (by simp [hconn.dist_eq_zero_iff, hne])\n\nlemma dist_eq_zero_of_not_reachable {u v : V} (h : \u00ac G.reachable u v) : G.dist u v = 0 :=\nby simp [h]\n\nlemma nonempty_of_pos_dist {u v : V} (h : 0 < G.dist u v) :\n  (set.univ : set (G.walk u v)).nonempty :=\nby simpa [set.range_nonempty_iff_nonempty, set.nonempty_iff_univ_nonempty]\n     using nat.nonempty_of_pos_Inf h\n\nprotected\nlemma connected.dist_triangle (hconn : G.connected) {u v w : V} :\n  G.dist u w \u2264 G.dist u v + G.dist v w :=\nbegin\n  obtain \u27e8p, hp\u27e9 := hconn.exists_walk_of_dist u v,\n  obtain \u27e8q, hq\u27e9 := hconn.exists_walk_of_dist v w,\n  rw [\u2190 hp, \u2190 hq, \u2190 walk.length_append],\n  apply dist_le,\nend\n\nprivate\n\n\nlemma dist_comm {u v : V} : G.dist u v = G.dist v u :=\nbegin\n  by_cases h : G.reachable u v,\n  { apply le_antisymm (dist_comm_aux h) (dist_comm_aux h.symm), },\n  { have h' : \u00ac G.reachable v u := \u03bb h', absurd h'.symm h,\n    simp [h, h', dist_eq_zero_of_not_reachable], },\nend\n\nend simple_graph\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/simple_graph/metric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7061881716018557}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport field_theory.finite.basic\n\n/-!\n# IMO 2005 Q4\n\nProblem: Determine all positive integers relatively prime to all the terms of the infinite sequence\n`a n = 2 ^ n + 3 ^ n + 6 ^ n \u2212 1`, for `n \u2265 1`.\n\nThis is quite an easy problem, in which the key point is a modular arithmetic calculation with\nthe sequence `a n` relative to an arbitrary prime.\n-/\n\n/-- The sequence considered in the problem, `2 ^ n + 3 ^ n + 6 ^ n - 1`. -/\ndef a (n : \u2115) : \u2124 := 2 ^ n + 3 ^ n + 6 ^ n - 1\n\n/-- Key lemma (a modular arithmetic calculation):  Given a prime `p` other than `2` or `3`, the\n`p - 2`th term of the sequence has `p` as a factor. -/\nlemma find_specified_factor {p : \u2115} (hp : nat.prime p) (hp' : is_coprime (6:\u2124) p) :\n  \u2191p \u2223 a (p - 2) :=\nbegin\n  rw [\u2190 int.modeq_zero_iff_dvd],\n  -- Since `p` and `6` are coprime, `6` has an inverse mod `p`\n  obtain \u27e8b, hb\u27e9 : \u2203 (b : \u2124), 6 * b \u2261 1 [ZMOD p],\n  { refine int.mod_coprime _,\n    exact nat.is_coprime_iff_coprime.mp hp' },\n  -- Also since `p` is coprime to `6`, it's coprime to `2` and `3`\n  have hp\u2082 : is_coprime (2:\u2124) p := (id hp' : is_coprime (3 * 2 : \u2124) p).of_mul_left_right,\n  have hp\u2083 : is_coprime (3:\u2124) p := (id hp' : is_coprime (2 * 3 : \u2124) p).of_mul_left_right,\n  -- Slightly painful nat-subtraction calculation\n  have hp_sub_one : p - 1 = (p - 2) + 1,\n  { have : 1 \u2264 p - 1 := le_tsub_of_add_le_right hp.two_le,\n    conv_lhs { rw \u2190 nat.sub_add_cancel this },\n    refl },\n  -- Main calculation: `6 * a (p - 2)` is a multiple of `p`\n  have H : (6:\u2124) * a (p - 2) \u2261 0 [ZMOD p],\n  calc (6:\u2124) * a (p - 2)\n      = 3 * 2 ^ (p - 1) + 2 * 3 ^ (p - 1) + 6 ^ (p - 1) - 6 :\n  by { simp only [a, mul_add, mul_sub, hp_sub_one, pow_succ], ring, }\n  ... \u2261 3 * 1 + 2 * 1 + 1 - 6 [ZMOD p] : -- At this step we use Fermat's little theorem\n  by { apply_rules [int.modeq.sub_right, int.modeq.add, int.modeq.mul_left,\n    int.modeq.pow_card_sub_one_eq_one hp] }\n  ... = 0 : by norm_num,\n  -- Since `6` has an inverse mod `p`, `a (p - 2)` itself is a multiple of `p`\n  calc (a (p - 2) : \u2124) = 1 * a (p - 2) : by ring\n  ... \u2261 (6 * b) * a (p - 2) [ZMOD p] : int.modeq.mul_right _ hb.symm\n  ... = b * (6 * a (p - 2)) : by ring\n  ... \u2261 b * 0 [ZMOD p] : int.modeq.mul_left _ H\n  ... = 0 : by ring,\nend\n\n/-- Main statement:  The only positive integer coprime to all terms of the sequence `a` is `1`. -/\ntheorem imo2005_p4 {k : \u2115} (hk : 0 < k) : (\u2200 n : \u2115, 1 \u2264 n \u2192 is_coprime (a n) k) \u2194 k = 1 :=\nbegin\n  split, rotate,\n  { -- The property is clearly true for `k = 1`\n    rintros rfl n hn,\n    exact is_coprime_one_right },\n  intros h,\n  -- Conversely, suppose `k` is a number with the property, and let `p` be `k.min_fac` (by\n  -- definition this is the minimal prime factor of `k` if `k \u2260 1`, and otherwise `1`.\n  let p := k.min_fac,\n  -- Testing the special property of `k` for `48`, the second term of the sequence, we see that `p`\n  -- is coprime to `6`.\n  have hp\u2086 : is_coprime (6:\u2124) p,\n  { refine is_coprime.of_coprime_of_dvd_right _ (int.coe_nat_dvd.mpr k.min_fac_dvd),\n    exact (id (h 2 one_le_two) : is_coprime (8 * 6 : \u2124) k).of_mul_left_right, },\n  -- In particular `p` is coprime to `2` (we record the `nat.coprime` version since that's what's\n  -- needed later).\n  have hp\u2082 : nat.coprime 2 p,\n  { rw \u2190 nat.is_coprime_iff_coprime,\n    exact (id hp\u2086 : is_coprime (3 * 2 : \u2124) p).of_mul_left_right },\n  -- Suppose for the sake of contradiction that `k \u2260 1`.  Then `p` is genuinely a prime factor of\n  -- `k`.\n  by_contra hk',\n  have hp : nat.prime p := nat.min_fac_prime hk',\n  -- So `3 \u2264 p`\n  have hp\u2083 : 3 \u2264 p,\n  { have : 2 \u2260 p := by rwa nat.coprime_primes (by norm_num : nat.prime 2) hp at hp\u2082,\n    apply nat.lt_of_le_and_ne hp.two_le this, },\n  -- Testing the special property of `k` for the `p - 2`th term of the sequence, we see that `p` is\n  -- coprime to `a (p - 2)`.\n  have : is_coprime \u2191p (a (p - 2)),\n  { refine ((h (p - 2) _).of_coprime_of_dvd_right (int.coe_nat_dvd.mpr k.min_fac_dvd)).symm,\n    exact le_tsub_of_add_le_right hp\u2083 },\n  rw (nat.prime_iff_prime_int.mp hp).coprime_iff_not_dvd at this,\n  -- But also, by our previous lemma, `p` divides `a (p - 2)`.\n  have : \u2191p \u2223 a (p - 2) := find_specified_factor hp hp\u2086,\n  -- Contradiction!\n  contradiction,\nend\n", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/imo/2005/p4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7905303186696748, "lm_q1q2_score": 0.706188167193347}}
{"text": "import analysis.calculus.bump_function_inner\nimport measure_theory.integral.periodic\nimport loops.surrounding\nimport loops.delta_mollifier\n\nimport to_mathlib.partition2\nimport to_mathlib.analysis.cont_diff\n\n/-!\n#\u00a0The reparametrization lemma\n\nThis file contains a proof of Gromov's parametric reparametrization lemma. It concerns the behaviour\nof the average value of a loop `\u03b3 : S\u00b9 \u2192 F` when the loop is reparametrized by precomposing with a\ndiffeomorphism `S\u00b9 \u2192 S\u00b9`.\n\nGiven a loop `\u03b3 : S\u00b9 \u2192 F` for some real vector space `F`, one may integrate to obtain its average\n`\u222b x in 0..1, (\u03b3 x)` in `F`. Although this average depends on the loop's parametrization, it\nsatisfies a contraint that depends only on the image of the loop: the average is contained in the\nconvex hull of the image of `\u03b3`. The non-parametric version of the reparametrization lemma says that\nconversely, given any point `g` in the interior of the convex hull of the image of `\u03b3`, one may find\na reparametrization of `\u03b3` whose average is `g`.\n\nThe reparametrization lemma thus allows one to reduce the problem of constructing a loop whose\naverage is a given point, to the problem of constructing a loop subject to a condition that depends\nonly on its image.\n\nIn fact the reparametrization lemma holds parametrically. Given a smooth family of loops:\n`\u03b3 : E \u00d7 S\u00b9 \u2192 F`, `(x, t) \u21a6 \u03b3\u2093 t`, together with a smooth function `g : E \u2192 F`, such that `g x` is\ncontained in the interior of the convex hull of the image of `\u03b3\u2093` for all `x`, there exists a smooth\nfamily of diffeomorphism `\u03c6 : E \u00d7 S\u00b9 \u2192 S\u00b9`, `(x, t) \u21a6 \u03c6\u2093 t` such that the average of `\u03b3\u2093 \u2218 \u03c6\u2093` is\n`g x` for all `x`.\n\nThe idea of the proof is simple: since `g x` is contained in the interior of the convex hull of\nthe image of `\u03b3\u2093` one may find `t\u2080, t\u2081, ..., t\u2099` and barycentric coordinates `w\u2080, w\u2081, ..., w\u2099` such\nthat `g x = \u2211\u1d62 w\u1d62 \u2022 \u03b3\u2093(t\u1d62)`. If there were no smoothness requirement on `\u03c6\u2093` one could define\nit to be a step function which spends time `w\u1d62` at each `t\u1d62`. However because there is a smoothness\ncondition, one rounds off the corners of the would-be step function by using a \"delta mollifier\"\n(an approximation to a Dirac delta function).\n\nThe above construction works locally in the neighbourhood of any `x` in `E` and one uses a partition\nof unity to globalise all the local solutions into the required family: `\u03c6 : E \u00d7 S\u00b9 \u2192 S\u00b9`.\n\nThe key ingredients are theories of calculus, convex hulls, barycentric coordinates,\nexistence of delta mollifiers, partitions of unity, and the inverse function theorem.\n-/\n\nnoncomputable theory\n\nopen set function measure_theory interval_integral filter\nopen_locale topology unit_interval manifold big_operators\n\nvariables {E F : Type*}\nvariables [normed_add_comm_group F] [normed_space \u211d F] [finite_dimensional \u211d F]\nvariables [measurable_space F] [borel_space F]\n\nlocal notation `\u03b9` := fin (finite_dimensional.finrank \u211d F + 1)\n\nsection metric_space\n\nvariables [metric_space E] [locally_compact_space E]\n\nlemma loop.tendsto_mollify_apply\n  (\u03b3 : E \u2192 loop F) (h : continuous \u21bf\u03b3) (x : E) (t : \u211d) :\n  tendsto (\u03bb (z : E \u00d7 \u2115), (\u03b3 z.1).mollify z.2 t) ((\ud835\udcdd x).prod at_top) (\ud835\udcdd (\u03b3 x t)) :=\nbegin\n  have h\u03b3 : \u2200 x, continuous (\u03b3 x) := \u03bb x, h.comp $ continuous.prod.mk _,\n  have h2\u03b3 : \u2200 x, continuous (\u03bb z, \u03b3 z x) := \u03bb x, h.comp $ continuous.prod.mk_left _,\n  simp_rw [loop.mollify_eq_convolution _ (h\u03b3 _)],\n  rw [\u2190 add_zero (\u03b3 x t)],\n  refine tendsto.add _ _,\n  { rw [\u2190 one_smul \u211d (\u03b3 x t)],\n    refine (tendsto_self_div_add_at_top_nhds_1_nat.comp tendsto_snd).smul _,\n    refine cont_diff_bump.convolution_tendsto_right _ _ _ tendsto_const_nhds,\n    { simp_rw [bump], norm_cast,\n      exact ((tendsto_add_at_top_iff_nat 2).2 (tendsto_const_div_at_top_nhds_0_nat 1)).comp\n        tendsto_snd },\n    { exact eventually_of_forall (\u03bb x, (h\u03b3 _).ae_strongly_measurable) },\n    { have := h.tendsto (x, t),\n      rw [nhds_prod_eq] at this,\n      exact this.comp ((tendsto_fst.comp tendsto_fst).prod_mk tendsto_snd) } },\n  { rw [\u2190 zero_smul \u211d (_ : F)],\n    have : continuous (\u03bb z, interval_integral (\u03b3 z) 0 1 volume) :=\n      continuous_parametric_interval_integral_of_continuous (by apply h) continuous_const,\n    exact (tendsto_one_div_add_at_top_nhds_0_nat.comp tendsto_snd).smul\n      ((this.tendsto x).comp tendsto_fst) }\nend\n\nend metric_space\n\nvariables [normed_add_comm_group E] [normed_space \u211d E] [finite_dimensional \u211d E]\n\n/-- Given a smooth function `g : E \u2192 F` between normed vector spaces, a smooth surrounding family\nis a smooth family of loops `E \u2192 loop F`, `x \u21a6 \u03b3\u2093` such that `\u03b3\u2093` surrounds `g x` for all `x`. -/\n@[nolint has_nonempty_instance]\nstructure smooth_surrounding_family (g : E \u2192 F) :=\n(smooth_surrounded : \ud835\udc9e \u221e g)\n(to_fun : E \u2192 loop F)\n(smooth : \ud835\udc9e \u221e \u21bfto_fun)\n(surrounds : \u2200 x, (to_fun x).surrounds $ g x)\n\nnamespace smooth_surrounding_family\n\nvariables {g : E \u2192 F} (\u03b3 : smooth_surrounding_family g) (x y : E)\n\ninstance : has_coe_to_fun (smooth_surrounding_family g) (\u03bb _, E \u2192 loop F) := \u27e8to_fun\u27e9\n\nprotected lemma continuous : continuous (\u03b3 x) :=\nbegin\n  apply continuous_uncurry_left x,\n  exact \u03b3.smooth.continuous,\nend\n\ninclude \u03b3 x\n\n/-- Given `\u03b3 : smooth_surrounding_family g` and `x : E`, `\u03b3.surrounding_parameters_at x` are the\n`t\u1d62 : \u211d`, for `i = 0, 1, ..., dim F` such that `\u03b3 x t\u1d62` surround `g x`. -/\ndef surrounding_parameters_at : \u03b9 \u2192 \u211d := classical.some (\u03b3.surrounds x)\n\n/-- Given `\u03b3 : smooth_surrounding_family g` and `x : E`, `\u03b3.surrounding_points_at x` are the\npoints `\u03b3 x t\u1d62` surrounding `g x` for parameters `t\u1d62 : \u211d`, `i = 0, 1, ..., dim F` (defined\nby `\u03b3.surrounding_parameters_at x`). -/\ndef surrounding_points_at : \u03b9 \u2192 F := \u03b3 x \u2218 \u03b3.surrounding_parameters_at x\n\n/-- Given `\u03b3 : smooth_surrounding_family g` and `x : E`, `\u03b3.surrounding_weights_at x` are the\nbarycentric coordinates of `g x` wrt to the points `\u03b3 x t\u1d62`, for parameters `t\u1d62 : \u211d`,\n`i = 0, 1, ..., dim F` (defined by `\u03b3.surrounding_parameters_at x`). -/\ndef surrounding_weights_at : \u03b9 \u2192 \u211d := classical.some (classical.some_spec (\u03b3.surrounds x))\n\nlemma surround_pts_points_weights_at :\n  surrounding_pts (g x) (\u03b3.surrounding_points_at x) (\u03b3.surrounding_weights_at x) :=\nclassical.some_spec _\n\n/-- Note that we are mollifying the loop `\u03b3 y` at the surrounding parameters for `\u03b3 x`. -/\ndef approx_surrounding_points_at (n : \u2115) (i : \u03b9) : F :=\n(\u03b3 y).mollify n (\u03b3.surrounding_parameters_at x i)\n\nlemma approx_surrounding_points_at_smooth (n : \u2115) :\n  \ud835\udc9e \u221e (\u03bb y, \u03b3.approx_surrounding_points_at x y n) :=\nbegin\n  refine cont_diff_pi.mpr (\u03bb i, _),\n  suffices : \ud835\udc9e \u221e (\u03bby, \u222b s in 0..1, delta_mollifier n (\u03b3.surrounding_parameters_at x i) s \u2022 \u03b3 y s),\n  { simpa [approx_surrounding_points_at, loop.mollify], },\n  refine cont_diff_parametric_integral_of_cont_diff (cont_diff.smul _ \u03b3.smooth) 0 1,\n  exact delta_mollifier_smooth.snd',\nend\n\n/-- The key property from which it should be easy to construct `local_centering_density`,\n`local_centering_density_nhd` etc below. -/\nlemma eventually_exists_surrounding_pts_approx_surrounding_points_at :\n  \u2200\u1da0 (z : E \u00d7 \u2115) in (\ud835\udcdd x).prod at_top,\n  \u2203 w, surrounding_pts (g z.1) (\u03b3.approx_surrounding_points_at x z.1 z.2) w :=\nbegin\n  let a : \u03b9 \u2192 E \u00d7 \u2115 \u2192 F := \u03bb i z, \u03b3.approx_surrounding_points_at x z.1 z.2 i,\n  suffices : \u2200 i, tendsto (a i) ((\ud835\udcdd x).prod at_top) (\ud835\udcdd (\u03b3.surrounding_points_at x i)),\n  { have hg : tendsto (\u03bb (z : E \u00d7 \u2115), g z.fst) ((\ud835\udcdd x).prod at_top) (\ud835\udcdd (g x)) :=\n      tendsto.comp \u03b3.smooth_surrounded.continuous.continuous_at tendsto_fst,\n    exact eventually_surrounding_pts_of_tendsto_of_tendsto'\n      \u27e8_, \u03b3.surround_pts_points_weights_at x\u27e9 this hg, },\n  intros i,\n  let t := \u03b3.surrounding_parameters_at x i,\n  change tendsto (\u03bb (z : E \u00d7 \u2115), (\u03b3 z.1).mollify z.2 t) ((\ud835\udcdd x).prod at_top) (\ud835\udcdd (\u03b3 x t)),\n  exact loop.tendsto_mollify_apply \u03b3 \u03b3.smooth.continuous x t,\nend\n\n/-- This is an auxiliary definition to help construct `centering_density` below.\n\nGiven `x : E`, it represents a smooth probability distribution on the circle with the property that:\n`\u222b s in 0..1, \u03b3.local_centering_density x y s \u2022 \u03b3 y s = g y`\nfor all `y` in a neighbourhood of `x` (see `local_centering_density_average` below). -/\ndef local_centering_density [decidable_pred (\u2208 affine_bases \u03b9 \u211d F)] : E \u2192 \u211d \u2192 \u211d := \u03bb y,\nbegin\n  choose n hn\u2081 hn\u2082 using filter.eventually_iff_exists_mem.mp\n    (\u03b3.eventually_exists_surrounding_pts_approx_surrounding_points_at x),\n  choose u hu v hv huv using mem_prod_iff.mp hn\u2081,\n  choose m hmv using mem_at_top_sets.mp hv,\n  exact \u2211 i, (eval_barycentric_coords \u03b9 \u211d F (g y) (\u03b3.approx_surrounding_points_at x y m) i) \u2022\n    (delta_mollifier m (\u03b3.surrounding_parameters_at x i)),\nend\n\n/-- This is an auxiliary definition to help construct `centering_density` below. -/\ndef local_centering_density_mp : \u2115 :=\nbegin\n  choose n hn\u2081 hn\u2082 using filter.eventually_iff_exists_mem.mp\n    (\u03b3.eventually_exists_surrounding_pts_approx_surrounding_points_at x),\n  choose u hu v hv huv using mem_prod_iff.mp hn\u2081,\n  choose m hmv using mem_at_top_sets.mp hv,\n  exact m,\nend\n\nlemma local_centering_density_spec [decidable_pred (\u2208 affine_bases \u03b9 \u211d F)] :\n  \u03b3.local_centering_density x y =\n  \u2211 i, (eval_barycentric_coords \u03b9 \u211d F (g y)\n    (\u03b3.approx_surrounding_points_at x y (\u03b3.local_centering_density_mp x)) i) \u2022\n    (delta_mollifier (\u03b3.local_centering_density_mp x) (\u03b3.surrounding_parameters_at x i)) :=\nrfl\n\n/-- This is an auxiliary definition to help construct `centering_density` below. -/\ndef local_centering_density_nhd : set E :=\nbegin\n  choose n hn\u2081 hn\u2082 using filter.eventually_iff_exists_mem.mp\n    (\u03b3.eventually_exists_surrounding_pts_approx_surrounding_points_at x),\n  choose u hu v hv huv using mem_prod_iff.mp hn\u2081,\n  exact (interior u),\nend\n\nomit \u03b3 x\n\nlemma local_centering_density_nhd_is_open :\n  is_open $ \u03b3.local_centering_density_nhd x :=\nis_open_interior\n\nlemma local_centering_density_nhd_self_mem :\n  x \u2208 \u03b3.local_centering_density_nhd x :=\nbegin\n  let h := filter.eventually_iff_exists_mem.mp\n    (\u03b3.eventually_exists_surrounding_pts_approx_surrounding_points_at x),\n  exact mem_interior_iff_mem_nhds.mpr (classical.some (classical.some_spec (mem_prod_iff.mp\n    (classical.some (classical.some_spec h))))),\nend\n\n-- unused\nlemma local_centering_density_nhd_covers :\n  univ \u2286 \u22c3 x, \u03b3.local_centering_density_nhd x :=\n\u03bb x hx, mem_Union.mpr \u27e8x, \u03b3.local_centering_density_nhd_self_mem x\u27e9\n\nlemma approx_surrounding_points_at_of_local_centering_density_nhd\n  (hy : y \u2208 \u03b3.local_centering_density_nhd x) : \u2203 w,\n  surrounding_pts (g y) (\u03b3.approx_surrounding_points_at x y (\u03b3.local_centering_density_mp x)) w :=\nbegin\n  let h := filter.eventually_iff_exists_mem.mp\n    (\u03b3.eventually_exists_surrounding_pts_approx_surrounding_points_at x),\n  let nn := classical.some h,\n  let hnn := mem_prod_iff.mp (classical.some (classical.some_spec h)),\n  let n := classical.some hnn,\n  let hn := classical.some_spec hnn,\n  change y \u2208 interior n at hy,\n  let v := classical.some (classical.some_spec hn),\n  let hv : v \u2208 at_top := classical.some (classical.some_spec (classical.some_spec hn)),\n  let m := classical.some (mem_at_top_sets.mp hv),\n  let hm := classical.some_spec (mem_at_top_sets.mp hv),\n  change \u2203 w, surrounding_pts (g y) (\u03b3.approx_surrounding_points_at x y m) w,\n  suffices : (y, m) \u2208 nn,\n  { exact classical.some_spec (classical.some_spec h) _ this, },\n  apply classical.some_spec (classical.some_spec (classical.some_spec hn)),\n  change y \u2208 n \u2227 m \u2208 v,\n  exact \u27e8interior_subset hy, hm _ (le_refl _)\u27e9,\nend\n\nlemma approx_surrounding_points_at_mem_affine_bases (hy : y \u2208 \u03b3.local_centering_density_nhd x) :\n  \u03b3.approx_surrounding_points_at x y (\u03b3.local_centering_density_mp x) \u2208 affine_bases \u03b9 \u211d F :=\n(classical.some_spec\n  (\u03b3.approx_surrounding_points_at_of_local_centering_density_nhd x y hy)).mem_affine_bases\n\nvariables [decidable_pred (\u2208 affine_bases \u03b9 \u211d F)]\n\n@[simp] lemma local_centering_density_pos (hy : y \u2208 \u03b3.local_centering_density_nhd x) (t : \u211d) :\n  0 < \u03b3.local_centering_density x y t :=\nbegin\n  simp only [\u03b3.local_centering_density_spec x, fintype.sum_apply, pi.smul_apply,\n    algebra.id.smul_eq_mul],\n  refine finset.sum_pos (\u03bb i hi, _) finset.univ_nonempty,\n  refine mul_pos _ (delta_mollifier_pos _),\n  obtain \u27e8w, hw\u27e9 := \u03b3.approx_surrounding_points_at_of_local_centering_density_nhd x y hy,\n  convert hw.w_pos i,\n  rw \u2190 hw.coord_eq_w,\n  simp [eval_barycentric_coords, \u03b3.approx_surrounding_points_at_mem_affine_bases x y hy],\nend\n\nlemma local_centering_density_periodic :\n  periodic (\u03b3.local_centering_density x y) 1 :=\nfinset.univ.periodic_sum $ \u03bb i hi, periodic.smul delta_mollifier_periodic _\n\nlemma local_centering_density_smooth_on :\n  smooth_on \u21bf(\u03b3.local_centering_density x) $\n    (\u03b3.local_centering_density_nhd x) \u00d7\u02e2 (univ : set \u211d) :=\nbegin\n  let h\u2080 := (\u03bb (yt : E \u00d7 \u211d) (hyt : yt \u2208 (\u03b3.local_centering_density_nhd x) \u00d7\u02e2 (univ : set \u211d)),\n    congr_fun (\u03b3.local_centering_density_spec x yt.fst) yt.snd),\n  refine cont_diff_on.congr _ h\u2080,\n  simp only [fintype.sum_apply, pi.smul_apply, algebra.id.smul_eq_mul],\n  refine cont_diff_on.sum (\u03bb i hi, cont_diff_on.mul _ (cont_diff.cont_diff_on _)),\n  { let w : F \u00d7 (\u03b9 \u2192 F) \u2192 \u211d := \u03bb z, eval_barycentric_coords \u03b9 \u211d F z.1 z.2 i,\n    let z : E \u2192 F \u00d7 (\u03b9 \u2192 F) :=\n      (prod.map g (\u03bb y, \u03b3.approx_surrounding_points_at x y (\u03b3.local_centering_density_mp x))) \u2218\n      (\u03bb x, (x, x)),\n    change smooth_on ((w \u2218 z) \u2218 prod.fst) (\u03b3.local_centering_density_nhd x \u00d7\u02e2 univ),\n    rw prod_univ,\n    refine cont_diff_on.comp _ cont_diff_fst.cont_diff_on subset.rfl,\n    have h\u2081 := smooth_barycentric \u03b9 \u211d F (fintype.card_fin _),\n    have h\u2082 : \ud835\udc9e \u221e (eval i : (\u03b9 \u2192 \u211d) \u2192 \u211d) := cont_diff_apply _ _ i,\n    refine (h\u2082.comp_cont_diff_on h\u2081).comp _ _,\n    { have h\u2083 := (diag_preimage_prod_self (\u03b3.local_centering_density_nhd x)).symm.subset,\n      refine cont_diff_on.comp _ (cont_diff_id.prod cont_diff_id).cont_diff_on h\u2083,\n      refine (\u03b3.smooth_surrounded).cont_diff_on.prod_map (cont_diff.cont_diff_on _),\n      exact \u03b3.approx_surrounding_points_at_smooth x _, },\n    { intros y hy,\n      simp [z, \u03b3.approx_surrounding_points_at_mem_affine_bases x y hy], }, },\n  { exact delta_mollifier_smooth.comp cont_diff_snd, },\nend\n\nlemma local_centering_density_continuous (hy : y \u2208 \u03b3.local_centering_density_nhd x) :\n  continuous (\u03bb t, \u03b3.local_centering_density x y t) :=\nbegin\n  refine continuous_iff_continuous_at.mpr (\u03bb t, _),\n  have hyt : \u03b3.local_centering_density_nhd x \u00d7\u02e2 univ \u2208 \ud835\udcdd (y, t) :=\n    mem_nhds_prod_iff'.mpr \u27e8\u03b3.local_centering_density_nhd x, univ,\n      \u03b3.local_centering_density_nhd_is_open x, hy, is_open_univ, mem_univ t, rfl.subset\u27e9,\n  exact ((\u03b3.local_centering_density_smooth_on x).continuous_on.continuous_at hyt).comp\n    (continuous.prod.mk y).continuous_at,\nend\n\n@[simp] lemma local_centering_density_integral_eq_one (hy : y \u2208 \u03b3.local_centering_density_nhd x) :\n  \u222b s in 0..1, \u03b3.local_centering_density x y s = 1 :=\nbegin\n  let n := \u03b3.local_centering_density_mp x,\n  simp only [\u03b3.local_centering_density_spec x, prod.forall, exists_prop, gt_iff_lt,\n    fintype.sum_apply, pi.smul_apply, algebra.id.smul_eq_mul, finset.sum_smul],\n  rw interval_integral.integral_finset_sum,\n  { have h : \u03b3.approx_surrounding_points_at x y n \u2208 affine_bases \u03b9 \u211d F :=\n      \u03b3.approx_surrounding_points_at_mem_affine_bases x y hy,\n    simp_rw [\u2190 smul_eq_mul, interval_integral.integral_smul, delta_mollifier_integral_eq_one,\n      algebra.id.smul_eq_mul, mul_one, eval_barycentric_coords_apply_of_mem_bases \u03b9 \u211d F (g y) h,\n      affine_basis.coords_apply, affine_basis.sum_coord_apply_eq_one], },\n  { simp_rw \u2190 smul_eq_mul,\n    refine \u03bb i hi, (continuous.const_smul _ _).interval_integrable 0 1,\n    exact delta_mollifier_smooth.continuous, },\nend\n\n@[simp] lemma local_centering_density_average (hy : y \u2208 \u03b3.local_centering_density_nhd x) :\n  \u222b s in 0..1, \u03b3.local_centering_density x y s \u2022 \u03b3 y s = g y :=\nbegin\n  let n := \u03b3.local_centering_density_mp x,\n  simp only [\u03b3.local_centering_density_spec x, prod.forall, exists_prop, gt_iff_lt,\n    fintype.sum_apply, pi.smul_apply, algebra.id.smul_eq_mul, finset.sum_smul],\n  rw interval_integral.integral_finset_sum,\n  { simp_rw [mul_smul, interval_integral.integral_smul],\n    change \u2211 i, _ \u2022 (\u03b3.approx_surrounding_points_at x y n i) = _,\n    have h : \u03b3.approx_surrounding_points_at x y n \u2208 affine_bases \u03b9 \u211d F :=\n      \u03b3.approx_surrounding_points_at_mem_affine_bases x y hy,\n    erw [eval_barycentric_coords_apply_of_mem_bases \u03b9 \u211d F (g y) h],\n    simp only [affine_basis.coords_apply],\n    exact affine_basis.linear_combination_coord_eq_self _ _, },\n  { simp_rw mul_smul,\n    refine \u03bb i hi, ((continuous.smul _ (\u03b3.continuous y)).const_smul _).interval_integrable 0 1,\n    exact delta_mollifier_smooth.continuous, },\nend\n\n/-- Given `\u03b3 : smooth_surrounding_family g`, together with a point `x : E` and a map `f : \u211d \u2192 \u211d`,\n`\u03b3.is_centering_density x f` is the proposition that `f` is periodic, strictly positive, and\nhas integral one and that the average of `\u03b3\u2093` with respect to the measure that `f` defines on\nthe circle is `g x`.\n\nThe continuity assumption is just a legacy convenience and should be dropped. -/\nstructure is_centering_density (x : E) (f : \u211d \u2192 \u211d) : Prop :=\n(pos : \u2200 t, 0 < f t)\n(periodic : periodic f 1)\n(integral_one : \u222b s in 0..1, f s = 1)\n(average : \u222b s in 0..1, f s \u2022 \u03b3 x s = g x)\n(continuous : continuous f) -- Can drop if/when have `interval_integrable.smul_continuous_on`\n\nlemma is_centering_density_convex (x : E) : convex \u211d { f | \u03b3.is_centering_density x f} :=\nbegin\n  classical,\n  rintros f \u27e8hf\u2081, hf\u2082, hf\u2083, hf\u2084, hf\u2085\u27e9 k \u27e8hk\u2081, hk\u2082, hk\u2083, hk\u2084, hk\u2085\u27e9 a b ha hb hab,\n  have hf\u2086 : interval_integrable f volume 0 1,\n  { apply interval_integrable_of_integral_ne_zero, rw hf\u2083, exact one_ne_zero, },\n  have hf\u2087 : interval_integrable (f \u2022 \u03b3 x) volume 0 1 :=\n    (hf\u2085.smul (\u03b3.continuous x)).interval_integrable 0 1,\n  have hk\u2086 : interval_integrable k volume 0 1,\n  { apply interval_integrable_of_integral_ne_zero, rw hk\u2083, exact one_ne_zero, },\n  have hk\u2087 : interval_integrable (k \u2022 \u03b3 x) volume 0 1 :=\n    (hk\u2085.smul (\u03b3.continuous x)).interval_integrable 0 1,\n  exact\n  { pos := \u03bb t, convex_Ioi (0 : \u211d) (hf\u2081 t) (hk\u2081 t) ha hb hab,\n    periodic := (hf\u2082.smul a).add (hk\u2082.smul b),\n    integral_one :=\n    begin\n      simp_rw pi.add_apply,\n      rw interval_integral.integral_add (hf\u2086.smul a) (hk\u2086.smul b),\n      simp [interval_integral.integral_smul, hf\u2083, hk\u2083, hab],\n    end,\n    average :=\n    begin\n      simp_rw [pi.add_apply, pi.smul_apply, add_smul, smul_assoc],\n      erw interval_integral.integral_add (hf\u2087.smul a) (hk\u2087.smul b),\n      simp [interval_integral.integral_smul, \u2190 add_smul, hf\u2084, hk\u2084, hab],\n    end,\n    continuous := continuous.add (hf\u2085.const_smul a) (hk\u2085.const_smul b) },\nend\n\nlemma exists_smooth_is_centering_density (x : E) : \u2203 (U \u2208 \ud835\udcdd x) (f : E \u2192 \u211d \u2192 \u211d),\n    smooth_on (uncurry f) (U \u00d7\u02e2 (univ : set \u211d)) \u2227 \u2200 y \u2208 U, \u03b3.is_centering_density y (f y) :=\n\u27e8\u03b3.local_centering_density_nhd x,\n  mem_nhds_iff.mpr\n    \u27e8_,\n     subset.rfl,\n     \u03b3.local_centering_density_nhd_is_open x,\n     \u03b3.local_centering_density_nhd_self_mem x\u27e9,\n  \u03b3.local_centering_density x,\n  \u03b3.local_centering_density_smooth_on x,\n  \u03bb y hy, \u27e8\u03b3.local_centering_density_pos x y hy,\n           \u03b3.local_centering_density_periodic x y,\n           \u03b3.local_centering_density_integral_eq_one x y hy,\n           \u03b3.local_centering_density_average x y hy,\n           \u03b3.local_centering_density_continuous x y hy\u27e9\u27e9\n\n/-- This the key construction. It represents a smooth probability distribution on the circle with\nthe property that:\n`\u222b s in 0..1, \u03b3.centering_density x s \u2022 \u03b3 x s = g x`\nfor all `x : E` (see `centering_density_average` below). -/\ndef centering_density : E \u2192 \u211d \u2192 \u211d :=\nclassical.some\n  (exists_cont_diff_of_convex\u2082 \u03b3.is_centering_density_convex \u03b3.exists_smooth_is_centering_density)\n\nlemma centering_density_smooth :\n  \ud835\udc9e \u221e $ uncurry (\u03bb x t, \u03b3.centering_density x t) :=\n(classical.some_spec $\n  exists_cont_diff_of_convex\u2082 \u03b3.is_centering_density_convex \u03b3.exists_smooth_is_centering_density).1\n\nlemma is_centering_density_centering_density (x : E) :\n  \u03b3.is_centering_density x (\u03b3.centering_density x) :=\n(classical.some_spec $\n  exists_cont_diff_of_convex\u2082 \u03b3.is_centering_density_convex \u03b3.exists_smooth_is_centering_density).2 x\n\n@[simp] lemma centering_density_pos (t : \u211d) :\n  0 < \u03b3.centering_density x t :=\n(\u03b3.is_centering_density_centering_density x).pos t\n\nlemma centering_density_periodic :\n  periodic (\u03b3.centering_density x) 1 :=\n(\u03b3.is_centering_density_centering_density x).periodic\n\n@[simp] lemma centering_density_integral_eq_one :\n  \u222b s in 0..1, \u03b3.centering_density x s = 1 :=\n(\u03b3.is_centering_density_centering_density x).integral_one\n\n@[simp] lemma centering_density_average :\n  \u222b s in 0..1, \u03b3.centering_density x s \u2022 \u03b3 x s = g x :=\n(\u03b3.is_centering_density_centering_density x).average\n\nlemma centering_density_continuous :\n  continuous (\u03b3.centering_density x) :=\nbegin\n  apply continuous_uncurry_left x,\n  exact \u03b3.centering_density_smooth.continuous,\nend\n\nlemma centering_density_interval_integrable (t\u2081 t\u2082 : \u211d) :\n  interval_integrable (\u03b3.centering_density x) volume t\u2081 t\u2082 :=\n(\u03b3.centering_density_continuous x).interval_integrable t\u2081 t\u2082\n\n@[simp] lemma integral_add_one_centering_density (t : \u211d) :\n  \u222b s in 0..t+1, \u03b3.centering_density x s = (\u222b s in 0..t, \u03b3.centering_density x s) + 1 :=\nbegin\n  have h\u2081 := \u03b3.centering_density_interval_integrable x 0 t,\n  have h\u2082 := \u03b3.centering_density_interval_integrable x t (t + 1),\n  simp [\u2190 integral_add_adjacent_intervals h\u2081 h\u2082,\n    (\u03b3.centering_density_periodic x).interval_integral_add_eq t 0],\nend\n\nlemma deriv_integral_centering_density_pos (t : \u211d) :\n  0 < deriv (\u03bb t, \u222b s in 0..t, \u03b3.centering_density x s) t :=\nbegin\n  rw interval_integral.deriv_integral_right (\u03b3.centering_density_interval_integrable _ _ _)\n    ((\u03b3.centering_density_continuous x).strongly_measurable_at_filter volume (\ud835\udcdd t))\n    (centering_density_continuous \u03b3 x).continuous_at,\n  exact centering_density_pos \u03b3 x t\nend\n\nlemma strict_mono_integral_centering_density :\n  strict_mono $ \u03bb t, \u222b s in 0..t, \u03b3.centering_density x s :=\nstrict_mono_of_deriv_pos (\u03b3.deriv_integral_centering_density_pos x)\n\nlemma surjective_integral_centering_density :\n  surjective $ \u03bb t, \u222b s in 0..t, \u03b3.centering_density x s :=\nbegin\n  have : continuous (\u03bb t, \u222b s in 0..t, \u03b3.centering_density x s),\n  { exact continuous_primitive (\u03b3.centering_density_interval_integrable x) 0, },\n  exact equivariant_map.surjective\n    \u27e8\u03bb t, \u222b s in 0..t, \u03b3.centering_density x s, \u03b3.integral_add_one_centering_density x\u27e9 this\nend\n\n/-- Given `\u03b3 : smooth_surrounding_family g`, `x \u21a6 \u03b3.reparametrize x` is a smooth family of\ndiffeomorphisms of the circle such that reparametrizing `\u03b3\u2093` by `\u03b3.reparametrize x` gives a loop\nwith average `g x`.\n\nThis is the key construction and the main \"output\" of the reparametrization lemma. -/\ndef reparametrize : E \u2192 equivariant_equiv := \u03bb x,\n({ to_fun := \u03bb t, \u222b s in 0..t, \u03b3.centering_density x s,\n  inv_fun := (strict_mono.order_iso_of_surjective _\n    (\u03b3.strict_mono_integral_centering_density x)\n    (\u03b3.surjective_integral_centering_density x)).symm,\n  left_inv := strict_mono.order_iso_of_surjective_symm_apply_self _ _ _,\n  right_inv := \u03bb t, strict_mono.order_iso_of_surjective_self_symm_apply _ _ _ t,\n  map_zero' := integral_same,\n  eqv' := \u03b3.integral_add_one_centering_density x, } : equivariant_equiv).symm\n\n-- unused\nlemma coe_reparametrize_symm :\n  ((\u03b3.reparametrize x).symm : \u211d \u2192 \u211d) = \u03bb t, \u222b s in 0..t, \u03b3.centering_density x s :=\nrfl\n\n-- unused\nlemma reparametrize_symm_apply (t : \u211d) :\n  (\u03b3.reparametrize x).symm t = \u222b s in 0..t, \u03b3.centering_density x s :=\nrfl\n\n-- unused\n@[simp] lemma integral_reparametrize (t : \u211d) :\n  \u222b s in 0..(\u03b3.reparametrize x t), \u03b3.centering_density x s = t :=\nby simp [\u2190 reparametrize_symm_apply]\n\nlemma has_deriv_at_reparametrize_symm (s : \u211d) :\n  has_deriv_at (\u03b3.reparametrize x).symm (\u03b3.centering_density x s) s :=\nintegral_has_deriv_at_right\n  (\u03b3.centering_density_interval_integrable x 0 s)\n  ((\u03b3.centering_density_continuous x).strongly_measurable_at_filter _ _)\n  (\u03b3.centering_density_continuous x).continuous_at\n\nlemma reparametrize_smooth :\n  -- \ud835\udc9e \u221e \u21bf\u03b3.reparametrize :=\n  \ud835\udc9e \u221e $ uncurry (\u03bb x t, \u03b3.reparametrize x t) :=\nbegin\n  let f : E \u2192 \u211d \u2192 \u211d := \u03bb x t, \u222b s in 0..t, \u03b3.centering_density x s,\n  change \ud835\udc9e \u22a4 (\u03bb p : E \u00d7 \u211d, (strict_mono.order_iso_of_surjective (f p.1) _ _).symm p.2),\n  apply cont_diff_parametric_symm_of_deriv_pos,\n  { exact cont_diff_parametric_primitive_of_cont_diff'' \u03b3.centering_density_smooth 0 },\n  { exact \u03bb x, deriv_integral_centering_density_pos \u03b3 x }\nend\n\n@[simp] lemma reparametrize_average :\n  ((\u03b3 x).reparam $ (\u03b3.reparametrize x).equivariant_map).average = g x :=\nbegin\n  change \u222b (s : \u211d) in 0..1, \u03b3 x (\u03b3.reparametrize x s) = g x,\n  have h\u2081 : \u2200 s,\n    s \u2208 uIcc 0 (1 : \u211d) \u2192 has_deriv_at (\u03b3.reparametrize x).symm (\u03b3.centering_density x s) s :=\n    \u03bb s hs, \u03b3.has_deriv_at_reparametrize_symm x s,\n  have h\u2082 : continuous_on (\u03bb s, \u03b3.centering_density x s) (uIcc 0 1) :=\n    (\u03b3.centering_density_continuous x).continuous_on,\n  have h\u2083 : continuous (\u03bb s, \u03b3 x (\u03b3.reparametrize x s)) :=\n    (\u03b3.continuous x).comp (continuous_uncurry_left x \u03b3.reparametrize_smooth.continuous),\n  rw [\u2190 (\u03b3.reparametrize x).symm.map_zero, \u2190 (\u03b3.reparametrize x).symm.map_one,\n    \u2190 integral_comp_smul_deriv h\u2081 h\u2082 h\u2083],\n  simp,\nend\n\nend smooth_surrounding_family\n", "meta": {"author": "leanprover-community", "repo": "sphere-eversion", "sha": "324e02c1509db6177cf363618f6ac5be343ce2f5", "save_path": "github-repos/lean/leanprover-community-sphere-eversion", "path": "github-repos/lean/leanprover-community-sphere-eversion/sphere-eversion-324e02c1509db6177cf363618f6ac5be343ce2f5/src/loops/reparametrization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7061881649479315}}
{"text": "import galois.tactic\n       galois.list.take_drop_lemmas\n\nnamespace nat\n\nlemma lt_succ_ne_lt (a b : \u2115) :\n  a < nat.succ b \u2192  a \u2260 b \u2192 a < b :=\nbegin\nintros lt ne,\ncases lt with x succ_lt,\n{ contradiction, },\n{ exact succ_lt, }\nend\n\nlemma pos_subtract (n k : \u2115)\n  (Hn : 0 < n) (Hk : 0 < k)\n  : (n - k) < n\n:= begin\ncases n, exfalso, apply (@@lt_irrefl _ _), apply Hn,\ncases k, exfalso, apply (@@lt_irrefl _ _), apply Hk,\nrename a n, rename a_1 k, clear Hn Hk,\nrw nat.succ_sub_succ,\napply lt_of_le_of_lt, apply nat.sub_le_sub_left,\napply nat.zero_le, rw nat.sub_zero,\napply nat.lt_succ_self\nend\n\nlemma le_of_div_succ\n  {n k p : \u2115}\n  (H : n / k = nat.succ p)\n : k \u2264 n\n:=\nbegin\nrw nat.div_def at H,\nby_cases ((0 < k \u2227 k \u2264 n)) with h; simp [h] at H,\n{ cases h,\n  assumption,\n},\n{\n  contradiction,\n}\nend\n\nlemma drop_drops_one : forall index drop_size,\ndrop_size \u2260 0 \u2192\ndrop_size \u2264 index ->\nindex / drop_size = ((index - drop_size) / drop_size) + 1 :=\nbegin\nintros, rw nat.div_def,\nby_cases (0 < drop_size \u2227 drop_size \u2264 index) with h;\nsimp [h],\n{\n  exfalso, apply h,\n  split,\n  { destruct drop_size; intros; subst drop_size,\n    {\n      contradiction,\n    },\n    {\n      simp [nat.lt_is_succ_le], have e : (nat.succ a_2) = 1 + a_2, simp,\n        rw e, apply nat.le_add_right\n    }\n  },\n  {\n   assumption,\n  }\n}\nend\n\nlemma drops_decreases : forall drop_size index,\ndrop_size \u2260 0 \u2192\ndrop_size \u2264 index ->\n((index - drop_size) / drop_size) < index /drop_size :=\nbegin\nintros,\nrw (drop_drops_one index); try {assumption},\napply nat.lt.base,\nend\n\nlemma lt_of_div_succ_2\n  {n k p : \u2115}\n  (H : n / k = p.succ)\n : (n - k) / k = p\n:=\nbegin\ncases k with k, simp at *, contradiction,\nhave dps := drop_drops_one n (nat.succ k),\nhave neO : nat.succ k \u2260 0, {contradiction},\nspecialize dps neO,\nclear neO,\nspecialize dps (nat.le_of_div_succ H),\nrw dps at H, rw <- nat.succ_eq_add_one at H,\ninjection H\nend\n\nlemma sub_le_le (m n k : \u2115)\n (Hmn : m \u2264 n)\n (H : m \u2264 k)\n : m + (n - k) \u2264 n\n:= begin\ninduction H,\napply le_of_eq,\napply nat.add_sub_of_le, assumption,\nrw nat.sub_succ, apply le_trans,\ntactic.swap, apply ih_1,\napply nat.add_le_add_left,\napply nat.pred_le,\nend\n\n\nlemma sub_pos_le (n k : \u2115) (Hk : 0 < k) (Hn : 0 < n)\n  : n - k + 1 \u2264 n\n:= begin\ncases k, exfalso, apply nat.lt_irrefl, assumption,\nrw nat.sub_succ,\nrw nat.add_comm,\nrw nat.one_add,\ncases n, exfalso, apply nat.lt_irrefl, assumption,\nrename a k, rename a_1 n,\napply nat.succ_le_succ,\nclear Hk Hn,\napply le_trans,\napply nat.pred_le_pred,\napply nat.sub_le,\napply le_refl,\nend\n\nlemma sub_1_succ : forall (n b : \u2115),\nn - 1 - b = n - nat.succ b :=\nbegin\nintros n,\ninduction n; intros,\n{ dsimp, cases b,\n  {refl},\n  { simp }\n},\n{\n  simp,\n}\nend\n\nlemma lt_succ_both : forall a b, nat.succ a < nat.succ b -> a < b :=\nbegin\nintros,  simp [nat.lt_is_succ_le, nat.succ_le_succ_iff] at *, apply a_1,\nend\n\nlemma max_subtract : forall (a b : nat),\n(max a b) - b = a - b :=\nbegin\nintros a b, unfold max,\napply (if H : a \u2264 b then _ else _),\n{ rw (if_pos H), rw nat.sub_eq_zero_of_le,\n  rw nat.sub_eq_zero_of_le, assumption,\n  apply le_refl,\n },\n{ rw (if_neg H), }\nend\n\nlemma mul_2_add {n : nat} : n * 2 = n + n\n:= begin\ninduction n, simp,\ndsimp [has_mul.mul, nat.mul],\nsimp,\nend\n\nlemma le_add_r {x y : nat} : x \u2264 x + y\n:= begin\ninduction y, simp,\napply le_trans, assumption,\napply nat.add_le_add_left, constructor,\nconstructor,\nend\n\nlemma le_add_compat {x y x' y' : nat}\n  (Hx : x \u2264 x') (Hy : y \u2264 y') : x + y \u2264 x' + y'\n:= begin\ninduction Hx, apply nat.add_le_add_left, assumption,\napply le_trans, apply ih_1,\nsimp, apply nat.add_le_add_left, constructor,\nconstructor,\nend\n\nlemma max_same (n : \u2115) : max n n = n\n:= begin\nunfold max, rw (if_pos (le_refl n)),\nend\n\nlemma max_add {m n k : \u2115} : max (m + k) (n + k) = max m n + k\n:= begin\nunfold max,\napply (if H : m \u2264 n then _ else _),\nrw (if_pos H), rw if_pos,\napply nat.add_le_add_right, assumption,\nrw (if_neg H), rw if_neg,\nintros contra, apply H, rw \u2190 nat.add_le_add_iff_le_right,\nassumption,\nend\n\nlemma neg_le_le (x y : \u2115) (H : \u00ac x \u2264 y)\n  : y \u2264 x\n:= begin\napply (if H' : y \u2264 x then _ else _),\nassumption, exfalso,\nhave H1 := @nat.le_total x y,\ninduction H1; contradiction,\nend\n\nlemma max_mono {x y x' y' : \u2115} (Hx : x \u2264 x') (Hy : y \u2264 y')\n  : max x y \u2264 max x' y'\n:= begin\nunfold max,\napply (if H : x \u2264 y then _ else _),\n{ rw (if_pos H),\n  apply (if H' : x' \u2264 y' then _ else _),\n  rw (if_pos H'), assumption,\n  rw (if_neg H'), apply le_trans, assumption,\n  apply nat.neg_le_le, assumption,\n},\n{ rw (if_neg H),\n  apply (if H' : x' \u2264 y' then _ else _),\n  rw (if_pos H'), apply le_trans; assumption,\n  rw (if_neg H'), assumption,\n}\nend\n\nlemma max_0_r (x : \u2115) : max x 0 = x\n:= begin\nunfold max,\napply (if H : x \u2264 0 then _ else _),\nrw (if_pos H), symmetry, rw \u2190 nat.le_zero_iff,\nassumption, rw if_neg, assumption,\nend\n\nend nat", "meta": {"author": "GaloisInc", "repo": "lean-protocol-support", "sha": "cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda", "save_path": "github-repos/lean/GaloisInc-lean-protocol-support", "path": "github-repos/lean/GaloisInc-lean-protocol-support/lean-protocol-support-cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda/galois/nat/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7061881606217444}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.essentially_small\n! leanprover-community/mathlib commit f7707875544ef1f81b32cb68c79e0e24e45a0e76\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Logic.Small.Basic\nimport Mathlib.CategoryTheory.Category.ULift\nimport Mathlib.CategoryTheory.Skeletal\nimport Mathlib.Tactic.Constructor\n\n/-!\n# Essentially small categories.\n\nA category given by `(C : Type u) [Category.{v} C]` is `w`-essentially small\nif there exists a `SmallModel C : Type w` equipped with `[SmallCategory (SmallModel C)]`.\n\nA category is `w`-locally small if every hom type is `w`-small.\n\nThe main theorem here is that a category is `w`-essentially small iff\nthe type `Skeleton C` is `w`-small, and `C` is `w`-locally small.\n-/\n\n\nuniverse w v v' u u'\n\nopen CategoryTheory\n\nvariable (C : Type u) [Category.{v} C]\n\nnamespace CategoryTheory\n\n/-- A category is `EssentiallySmall.{w}` if there exists\nan equivalence to some `S : Type w` with `[SmallCategory S]`. -/\nclass EssentiallySmall (C : Type u) [Category.{v} C] : Prop where\n  /-- An essentially small category is equivalent to some small category. -/\n  equiv_smallCategory : \u2203 (S : Type w) (_ : SmallCategory S), Nonempty (C \u224c S)\n#align category_theory.essentially_small CategoryTheory.EssentiallySmall\n\n/-- Constructor for `EssentiallySmall C` from an explicit small category witness. -/\ntheorem EssentiallySmall.mk' {C : Type u} [Category.{v} C] {S : Type w} [SmallCategory S]\n    (e : C \u224c S) : EssentiallySmall.{w} C :=\n  \u27e8\u27e8S, _, \u27e8e\u27e9\u27e9\u27e9\n#align category_theory.essentially_small.mk' CategoryTheory.EssentiallySmall.mk'\n\n/-- An arbitrarily chosen small model for an essentially small category.\n-/\n--@[nolint has_nonempty_instance]\ndef SmallModel (C : Type u) [Category.{v} C] [EssentiallySmall.{w} C] : Type w :=\n  Classical.choose (@EssentiallySmall.equiv_smallCategory C _ _)\n#align category_theory.small_model CategoryTheory.SmallModel\n\nnoncomputable instance smallCategorySmallModel (C : Type u) [Category.{v} C]\n    [EssentiallySmall.{w} C] : SmallCategory (SmallModel C) :=\n  Classical.choose (Classical.choose_spec (@EssentiallySmall.equiv_smallCategory C _ _))\n#align category_theory.small_category_small_model CategoryTheory.smallCategorySmallModel\n\n/-- The (noncomputable) categorical equivalence between\nan essentially small category and its small model.\n-/\nnoncomputable def equivSmallModel (C : Type u) [Category.{v} C] [EssentiallySmall.{w} C] :\n    C \u224c SmallModel C :=\n  Nonempty.some\n    (Classical.choose_spec (Classical.choose_spec (@EssentiallySmall.equiv_smallCategory C _ _)))\n#align category_theory.equiv_small_model CategoryTheory.equivSmallModel\n\ntheorem essentiallySmall_congr {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]\n    (e : C \u224c D) : EssentiallySmall.{w} C \u2194 EssentiallySmall.{w} D := by\n  fconstructor\n  \u00b7 rintro \u27e8S, \ud835\udcae, \u27e8f\u27e9\u27e9\n    skip\n    exact EssentiallySmall.mk' (e.symm.trans f)\n  \u00b7 rintro \u27e8S, \ud835\udcae, \u27e8f\u27e9\u27e9\n    skip\n    exact EssentiallySmall.mk' (e.trans f)\n#align category_theory.essentially_small_congr CategoryTheory.essentiallySmall_congr\n\ntheorem Discrete.essentiallySmallOfSmall {\u03b1 : Type u} [Small.{w} \u03b1] :\n    EssentiallySmall.{w} (Discrete \u03b1) :=\n  \u27e8\u27e8Discrete (Shrink \u03b1), \u27e8inferInstance, \u27e8Discrete.equivalence (equivShrink _)\u27e9\u27e9\u27e9\u27e9\n#align category_theory.discrete.essentially_small_of_small CategoryTheory.Discrete.essentiallySmallOfSmall\n\ntheorem essentiallySmallSelf : EssentiallySmall.{max w v u} C :=\n  EssentiallySmall.mk' (AsSmall.equiv : C \u224c AsSmall.{w} C)\n#align category_theory.essentially_small_self CategoryTheory.essentiallySmallSelf\n\n/-- A category is `w`-locally small if every hom set is `w`-small.\n\nSee `ShrinkHoms C` for a category instance where every hom set has been replaced by a small model.\n-/\nclass LocallySmall (C : Type u) [Category.{v} C] : Prop where\n  /-- A locally small category has small hom-types. -/\n  hom_small : \u2200 X Y : C, Small.{w} (X \u27f6 Y) := by infer_instance\n#align category_theory.locally_small CategoryTheory.LocallySmall\n\ninstance (C : Type u) [Category.{v} C] [LocallySmall.{w} C] (X Y : C) : Small (X \u27f6 Y) :=\n  LocallySmall.hom_small X Y\n\ntheorem locallySmall_congr {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]\n    (e : C \u224c D) : LocallySmall.{w} C \u2194 LocallySmall.{w} D := by\n  fconstructor\n  \u00b7 rintro \u27e8L\u27e9\n    fconstructor\n    intro X Y\n    specialize L (e.inverse.obj X) (e.inverse.obj Y)\n    refine' (small_congr _).mpr L\n    exact equivOfFullyFaithful e.inverse\n  \u00b7 rintro \u27e8L\u27e9\n    fconstructor\n    intro X Y\n    specialize L (e.functor.obj X) (e.functor.obj Y)\n    refine' (small_congr _).mpr L\n    exact equivOfFullyFaithful e.functor\n#align category_theory.locally_small_congr CategoryTheory.locallySmall_congr\n\ninstance (priority := 100) locallySmall_self (C : Type u) [Category.{v} C] : LocallySmall.{v} C\n    where\n#align category_theory.locally_small_self CategoryTheory.locallySmall_self\n\ninstance (priority := 100) locallySmall_of_essentiallySmall (C : Type u) [Category.{v} C]\n    [EssentiallySmall.{w} C] : LocallySmall.{w} C :=\n  (locallySmall_congr (equivSmallModel C)).mpr (CategoryTheory.locallySmall_self _)\n#align category_theory.locally_small_of_essentially_small CategoryTheory.locallySmall_of_essentiallySmall\n\n/-- We define a type alias `ShrinkHoms C` for `C`. When we have `LocallySmall.{w} C`,\nwe'll put a `Category.{w}` instance on `ShrinkHoms C`.\n-/\n--@[nolint has_nonempty_instance]\ndef ShrinkHoms (C : Type u) :=\n  C\n#align category_theory.shrink_homs CategoryTheory.ShrinkHoms\n\nnamespace ShrinkHoms\n\nsection\n\nvariable {C' : Type _}\n\n-- a fresh variable with no category instance attached\n/-- Help the typechecker by explicitly translating from `C` to `ShrinkHoms C`. -/\ndef toShrinkHoms {C' : Type _} (X : C') : ShrinkHoms C' :=\n  X\n#align category_theory.shrink_homs.to_shrink_homs CategoryTheory.ShrinkHoms.toShrinkHoms\n\n/-- Help the typechecker by explicitly translating from `ShrinkHoms C` to `C`. -/\ndef fromShrinkHoms {C' : Type _} (X : ShrinkHoms C') : C' :=\n  X\n#align category_theory.shrink_homs.from_shrink_homs CategoryTheory.ShrinkHoms.fromShrinkHoms\n\n@[simp]\ntheorem to_from (X : C') : fromShrinkHoms (toShrinkHoms X) = X :=\n  rfl\n#align category_theory.shrink_homs.to_from CategoryTheory.ShrinkHoms.to_from\n\n@[simp]\ntheorem from_to (X : ShrinkHoms C') : toShrinkHoms (fromShrinkHoms X) = X :=\n  rfl\n#align category_theory.shrink_homs.from_to CategoryTheory.ShrinkHoms.from_to\n\nend\n\nvariable [LocallySmall.{w} C]\n\n@[simps]\nnoncomputable instance : Category.{w} (ShrinkHoms C)\n    where\n  Hom X Y := Shrink (fromShrinkHoms X \u27f6 fromShrinkHoms Y)\n  id X := equivShrink _ (\ud835\udfd9 (fromShrinkHoms X))\n  comp f g := equivShrink _ ((equivShrink _).symm f \u226b (equivShrink _).symm g)\n\n/-- Implementation of `ShrinkHoms.equivalence`. -/\n@[simps]\nnoncomputable def functor : C \u2964 ShrinkHoms C\n    where\n  obj X := toShrinkHoms X\n  map {X Y} f := equivShrink (X \u27f6 Y) f\n#align category_theory.shrink_homs.functor CategoryTheory.ShrinkHoms.functor\n\n/-- Implementation of `ShrinkHoms.equivalence`. -/\n@[simps]\nnoncomputable def inverse : ShrinkHoms C \u2964 C\n    where\n  obj X := fromShrinkHoms X\n  map {X Y} f := (equivShrink (fromShrinkHoms X \u27f6 fromShrinkHoms Y)).symm f\n#align category_theory.shrink_homs.inverse CategoryTheory.ShrinkHoms.inverse\n\n/-- The categorical equivalence between `C` and `ShrinkHoms C`, when `C` is locally small.\n-/\n@[simps!]\nnoncomputable def equivalence : C \u224c ShrinkHoms C :=\n  Equivalence.mk (functor C) (inverse C)\n    (NatIso.ofComponents (fun X => Iso.refl X) <| by simp)\n    (NatIso.ofComponents (fun X => Iso.refl X) <| by simp)\n#align category_theory.shrink_homs.equivalence CategoryTheory.ShrinkHoms.equivalence\n\nend ShrinkHoms\n\n/-- A category is essentially small if and only if\nthe underlying type of its skeleton (i.e. the \"set\" of isomorphism classes) is small,\nand it is locally small.\n-/\ntheorem essentiallySmall_iff (C : Type u) [Category.{v} C] :\n    EssentiallySmall.{w} C \u2194 Small.{w} (Skeleton C) \u2227 LocallySmall.{w} C := by\n  -- This theorem is the only bit of real work in this file.\n  fconstructor\n  \u00b7 intro h\n    fconstructor\n    \u00b7 rcases h with \u27e8S, \ud835\udcae, \u27e8e\u27e9\u27e9\n      skip\n      refine' \u27e8\u27e8Skeleton S, \u27e8_\u27e9\u27e9\u27e9\n      exact e.skeletonEquiv\n    \u00b7 skip\n      infer_instance\n  \u00b7 rintro \u27e8\u27e8S, \u27e8e\u27e9\u27e9, L\u27e9\n    skip\n    let e' := (ShrinkHoms.equivalence C).skeletonEquiv.symm\n    letI : Category S := InducedCategory.category (e'.trans e).symm\n    refine' \u27e8\u27e8S, this, \u27e8_\u27e9\u27e9\u27e9\n    refine' (ShrinkHoms.equivalence C).trans <|\n      (skeletonEquivalence (ShrinkHoms C)).symm.trans\n        ((inducedFunctor (e'.trans e).symm).asEquivalence.symm)\n#align category_theory.essentially_small_iff CategoryTheory.essentiallySmall_iff\n\n/-- Any thin category is locally small.\n-/\ninstance (priority := 100) locallySmall_of_thin {C : Type u} [Category.{v} C] [Quiver.IsThin C] :\n    LocallySmall.{w} C where\n#align category_theory.locally_small_of_thin CategoryTheory.locallySmall_of_thin\n\n/--\nA thin category is essentially small if and only if the underlying type of its skeleton is small.\n-/\ntheorem essentiallySmall_iff_of_thin {C : Type u} [Category.{v} C] [Quiver.IsThin C] :\n    EssentiallySmall.{w} C \u2194 Small.{w} (Skeleton C) := by\n  simp [essentiallySmall_iff, CategoryTheory.locallySmall_of_thin]\n#align category_theory.essentially_small_iff_of_thin CategoryTheory.essentiallySmall_iff_of_thin\n\nend CategoryTheory\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/EssentiallySmall.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7061881604571006}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.eval\n! leanprover-community/mathlib commit 728baa2f54e6062c5879a3e397ac6bac323e506f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.Degree.Definitions\nimport Mathlib.Data.Polynomial.Induction\n\n/-!\n# Theory of univariate polynomials\n\nThe main defs here are `eval\u2082`, `eval`, and `map`.\nWe give several lemmas about their interaction with each other and with module operations.\n-/\n\n\nset_option linter.uppercaseLean3 false\n\nnoncomputable section\n\nopen Finset AddMonoidAlgebra\n\nopen BigOperators Polynomial\n\nnamespace Polynomial\n\nuniverse u v w y\n\nvariable {R : Type u} {S : Type v} {T : Type w} {\u03b9 : Type y} {a b : R} {m n : \u2115}\n\nsection Semiring\n\nvariable [Semiring R] {p q r : R[X]}\n\nsection\n\nvariable [Semiring S]\n\nvariable (f : R \u2192+* S) (x : S)\n\n/-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring\n  to the target and a value `x` for the variable in the target -/\nirreducible_def eval\u2082 (p : R[X]) : S :=\n  p.sum fun e a => f a * x ^ e\n#align polynomial.eval\u2082 Polynomial.eval\u2082\n\ntheorem eval\u2082_eq_sum {f : R \u2192+* S} {x : S} : p.eval\u2082 f x = p.sum fun e a => f a * x ^ e := by\n  rw [eval\u2082_def]\n#align polynomial.eval\u2082_eq_sum Polynomial.eval\u2082_eq_sum\n\ntheorem eval\u2082_congr {R S : Type _} [Semiring R] [Semiring S] {f g : R \u2192+* S} {s t : S}\n    {\u03c6 \u03c8 : R[X]} : f = g \u2192 s = t \u2192 \u03c6 = \u03c8 \u2192 eval\u2082 f s \u03c6 = eval\u2082 g t \u03c8 := by\n  rintro rfl rfl rfl; rfl\n#align polynomial.eval\u2082_congr Polynomial.eval\u2082_congr\n\n@[simp]\ntheorem eval\u2082_at_zero : p.eval\u2082 f 0 = f (coeff p 0) := by\n  simp (config := { contextual := true }) only [eval\u2082_eq_sum, zero_pow_eq, mul_ite, mul_zero,\n    mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff,\n    RingHom.map_zero, imp_true_iff, eq_self_iff_true]\n#align polynomial.eval\u2082_at_zero Polynomial.eval\u2082_at_zero\n\n@[simp]\ntheorem eval\u2082_zero : (0 : R[X]).eval\u2082 f x = 0 := by simp [eval\u2082_eq_sum]\n#align polynomial.eval\u2082_zero Polynomial.eval\u2082_zero\n\n@[simp]\ntheorem eval\u2082_C : (C a).eval\u2082 f x = f a := by simp [eval\u2082_eq_sum]\n#align polynomial.eval\u2082_C Polynomial.eval\u2082_C\n\n@[simp]\ntheorem eval\u2082_X : X.eval\u2082 f x = x := by simp [eval\u2082_eq_sum]\n#align polynomial.eval\u2082_X Polynomial.eval\u2082_X\n\n@[simp]\ntheorem eval\u2082_monomial {n : \u2115} {r : R} : (monomial n r).eval\u2082 f x = f r * x ^ n := by\n  simp [eval\u2082_eq_sum]\n#align polynomial.eval\u2082_monomial Polynomial.eval\u2082_monomial\n\n@[simp]\ntheorem eval\u2082_X_pow {n : \u2115} : (X ^ n).eval\u2082 f x = x ^ n := by\n  rw [X_pow_eq_monomial]\n  convert eval\u2082_monomial f x (n := n) (r := 1)\n  simp\n#align polynomial.eval\u2082_X_pow Polynomial.eval\u2082_X_pow\n\n@[simp]\ntheorem eval\u2082_add : (p + q).eval\u2082 f x = p.eval\u2082 f x + q.eval\u2082 f x := by\n  simp only [eval\u2082_eq_sum]\n  apply sum_add_index <;> simp [add_mul]\n#align polynomial.eval\u2082_add Polynomial.eval\u2082_add\n\n@[simp]\ntheorem eval\u2082_one : (1 : R[X]).eval\u2082 f x = 1 := by rw [\u2190 C_1, eval\u2082_C, f.map_one]\n#align polynomial.eval\u2082_one Polynomial.eval\u2082_one\n\nset_option linter.deprecated false in\n@[simp]\ntheorem eval\u2082_bit0 : (bit0 p).eval\u2082 f x = bit0 (p.eval\u2082 f x) := by rw [bit0, eval\u2082_add, bit0]\n#align polynomial.eval\u2082_bit0 Polynomial.eval\u2082_bit0\n\nset_option linter.deprecated false in\n@[simp]\ntheorem eval\u2082_bit1 : (bit1 p).eval\u2082 f x = bit1 (p.eval\u2082 f x) := by\n  rw [bit1, eval\u2082_add, eval\u2082_bit0, eval\u2082_one, bit1]\n#align polynomial.eval\u2082_bit1 Polynomial.eval\u2082_bit1\n\n@[simp]\ntheorem eval\u2082_smul (g : R \u2192+* S) (p : R[X]) (x : S) {s : R} :\n    eval\u2082 g x (s \u2022 p) = g s * eval\u2082 g x p := by\n  have A : p.natDegree < p.natDegree.succ := Nat.lt_succ_self _\n  have B : (s \u2022 p).natDegree < p.natDegree.succ := (natDegree_smul_le _ _).trans_lt A\n  rw [eval\u2082_eq_sum, eval\u2082_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B] <;>\n    simp [mul_sum, mul_assoc]\n#align polynomial.eval\u2082_smul Polynomial.eval\u2082_smul\n\n@[simp]\ntheorem eval\u2082_C_X : eval\u2082 C X p = p :=\n  Polynomial.induction_on' p (fun p q hp hq => by simp [hp, hq]) fun n x => by\n    rw [eval\u2082_monomial, \u2190 smul_X_eq_monomial, C_mul']\n#align polynomial.eval\u2082_C_X Polynomial.eval\u2082_C_X\n\n/-- `eval\u2082AddMonoidHom (f : R \u2192+* S) (x : S)` is the `AddMonoidHom` from\n`R[X]` to `S` obtained by evaluating the pushforward of `p` along `f` at `x`. -/\n@[simps]\ndef eval\u2082AddMonoidHom : R[X] \u2192+ S where\n  toFun := eval\u2082 f x\n  map_zero' := eval\u2082_zero _ _\n  map_add' _ _ := eval\u2082_add _ _\n#align polynomial.eval\u2082_add_monoid_hom Polynomial.eval\u2082AddMonoidHom\n#align polynomial.eval\u2082_add_monoid_hom_apply Polynomial.eval\u2082AddMonoidHom_apply\n\n@[simp]\ntheorem eval\u2082_nat_cast (n : \u2115) : (n : R[X]).eval\u2082 f x = n := by\n  induction' n with n ih\n  -- Porting note: `Nat.zero_eq` is required.\n  \u00b7 simp only [eval\u2082_zero, Nat.cast_zero, Nat.zero_eq]\n  \u00b7 rw [n.cast_succ, eval\u2082_add, ih, eval\u2082_one, n.cast_succ]\n#align polynomial.eval\u2082_nat_cast Polynomial.eval\u2082_nat_cast\n\nvariable [Semiring T]\n\ntheorem eval\u2082_sum (p : T[X]) (g : \u2115 \u2192 T \u2192 R[X]) (x : S) :\n    (p.sum g).eval\u2082 f x = p.sum fun n a => (g n a).eval\u2082 f x := by\n  let T : R[X] \u2192+ S :=\n    { toFun := eval\u2082 f x\n      map_zero' := eval\u2082_zero _ _\n      map_add' := fun p q => eval\u2082_add _ _ }\n  have A : \u2200 y, eval\u2082 f x y = T y := fun y => rfl\n  simp only [A]\n  rw [sum, T.map_sum, sum]\n#align polynomial.eval\u2082_sum Polynomial.eval\u2082_sum\n\ntheorem eval\u2082_list_sum (l : List R[X]) (x : S) : eval\u2082 f x l.sum = (l.map (eval\u2082 f x)).sum :=\n  map_list_sum (eval\u2082AddMonoidHom f x) l\n#align polynomial.eval\u2082_list_sum Polynomial.eval\u2082_list_sum\n\ntheorem eval\u2082_multiset_sum (s : Multiset R[X]) (x : S) :\n    eval\u2082 f x s.sum = (s.map (eval\u2082 f x)).sum :=\n  map_multiset_sum (eval\u2082AddMonoidHom f x) s\n#align polynomial.eval\u2082_multiset_sum Polynomial.eval\u2082_multiset_sum\n\ntheorem eval\u2082_finset_sum (s : Finset \u03b9) (g : \u03b9 \u2192 R[X]) (x : S) :\n    (\u2211 i in s, g i).eval\u2082 f x = \u2211 i in s, (g i).eval\u2082 f x :=\n  map_sum (eval\u2082AddMonoidHom f x) _ _\n#align polynomial.eval\u2082_finset_sum Polynomial.eval\u2082_finset_sum\n\ntheorem eval\u2082_ofFinsupp {f : R \u2192+* S} {x : S} {p : AddMonoidAlgebra R \u2115} :\n    eval\u2082 f x (\u27e8p\u27e9 : R[X]) = liftNC (\u2191f) (powersHom S x) p := by\n  simp only [eval\u2082_eq_sum, sum, toFinsupp_sum, support, coeff]\n  rfl\n#align polynomial.eval\u2082_of_finsupp Polynomial.eval\u2082_ofFinsupp\n\ntheorem eval\u2082_mul_noncomm (hf : \u2200 k, Commute (f <| q.coeff k) x) :\n    eval\u2082 f x (p * q) = eval\u2082 f x p * eval\u2082 f x q := by\n  rcases p with \u27e8p\u27e9; rcases q with \u27e8q\u27e9\n  simp only [coeff] at hf\n  simp only [\u2190 ofFinsupp_mul, eval\u2082_ofFinsupp]\n  exact liftNC_mul _ _ p q fun {k n} _hn => (hf k).pow_right n\n#align polynomial.eval\u2082_mul_noncomm Polynomial.eval\u2082_mul_noncomm\n\n@[simp]\ntheorem eval\u2082_mul_X : eval\u2082 f x (p * X) = eval\u2082 f x p * x := by\n  refine' _root_.trans (eval\u2082_mul_noncomm _ _ fun k => _) (by rw [eval\u2082_X])\n  rcases em (k = 1) with (rfl | hk)\n  \u00b7 simp\n  \u00b7 simp [coeff_X_of_ne_one hk]\n#align polynomial.eval\u2082_mul_X Polynomial.eval\u2082_mul_X\n\n@[simp]\ntheorem eval\u2082_X_mul : eval\u2082 f x (X * p) = eval\u2082 f x p * x := by rw [X_mul, eval\u2082_mul_X]\n#align polynomial.eval\u2082_X_mul Polynomial.eval\u2082_X_mul\n\ntheorem eval\u2082_mul_C' (h : Commute (f a) x) : eval\u2082 f x (p * C a) = eval\u2082 f x p * f a := by\n  rw [eval\u2082_mul_noncomm, eval\u2082_C]\n  intro k\n  by_cases hk : k = 0\n  \u00b7 simp only [hk, h, coeff_C_zero, coeff_C_ne_zero]\n  \u00b7 simp only [coeff_C_ne_zero hk, RingHom.map_zero, Commute.zero_left]\n#align polynomial.eval\u2082_mul_C' Polynomial.eval\u2082_mul_C'\n\ntheorem eval\u2082_list_prod_noncomm (ps : List R[X])\n    (hf : \u2200 p \u2208 ps, \u2200 (k), Commute (f <| coeff p k) x) :\n    eval\u2082 f x ps.prod = (ps.map (Polynomial.eval\u2082 f x)).prod := by\n  induction' ps using List.reverseRecOn with ps p ihp\n  \u00b7 simp\n  \u00b7 simp only [List.forall_mem_append, List.forall_mem_singleton] at hf\n    simp [eval\u2082_mul_noncomm _ _ hf.2, ihp hf.1]\n#align polynomial.eval\u2082_list_prod_noncomm Polynomial.eval\u2082_list_prod_noncomm\n\n/-- `eval\u2082` as a `RingHom` for noncommutative rings -/\ndef eval\u2082RingHom' (f : R \u2192+* S) (x : S) (hf : \u2200 a, Commute (f a) x) : R[X] \u2192+* S where\n  toFun := eval\u2082 f x\n  map_add' _ _ := eval\u2082_add _ _\n  map_zero' := eval\u2082_zero _ _\n  map_mul' _p q := eval\u2082_mul_noncomm f x fun k => hf <| coeff q k\n  map_one' := eval\u2082_one _ _\n#align polynomial.eval\u2082_ring_hom' Polynomial.eval\u2082RingHom'\n\nend\n\n/-!\nWe next prove that eval\u2082 is multiplicative\nas long as target ring is commutative\n(even if the source ring is not).\n-/\n\n\nsection Eval\u2082\n\nsection\n\nvariable [Semiring S] (f : R \u2192+* S) (x : S)\n\ntheorem eval\u2082_eq_sum_range :\n    p.eval\u2082 f x = \u2211 i in Finset.range (p.natDegree + 1), f (p.coeff i) * x ^ i :=\n  _root_.trans (congr_arg _ p.as_sum_range)\n    (_root_.trans (eval\u2082_finset_sum f _ _ x) (congr_arg _ (by simp)))\n#align polynomial.eval\u2082_eq_sum_range Polynomial.eval\u2082_eq_sum_range\n\ntheorem eval\u2082_eq_sum_range' (f : R \u2192+* S) {p : R[X]} {n : \u2115} (hn : p.natDegree < n) (x : S) :\n    eval\u2082 f x p = \u2211 i in Finset.range n, f (p.coeff i) * x ^ i := by\n  rw [eval\u2082_eq_sum, p.sum_over_range' _ _ hn]\n  intro i\n  rw [f.map_zero, zero_mul]\n#align polynomial.eval\u2082_eq_sum_range' Polynomial.eval\u2082_eq_sum_range'\n\nend\n\nsection\n\nvariable [CommSemiring S] (f : R \u2192+* S) (x : S)\n\n@[simp]\ntheorem eval\u2082_mul : (p * q).eval\u2082 f x = p.eval\u2082 f x * q.eval\u2082 f x :=\n  eval\u2082_mul_noncomm _ _ fun _k => Commute.all _ _\n#align polynomial.eval\u2082_mul Polynomial.eval\u2082_mul\n\ntheorem eval\u2082_mul_eq_zero_of_left (q : R[X]) (hp : p.eval\u2082 f x = 0) : (p * q).eval\u2082 f x = 0 := by\n  rw [eval\u2082_mul f x]\n  exact mul_eq_zero_of_left hp (q.eval\u2082 f x)\n#align polynomial.eval\u2082_mul_eq_zero_of_left Polynomial.eval\u2082_mul_eq_zero_of_left\n\ntheorem eval\u2082_mul_eq_zero_of_right (p : R[X]) (hq : q.eval\u2082 f x = 0) : (p * q).eval\u2082 f x = 0 := by\n  rw [eval\u2082_mul f x]\n  exact mul_eq_zero_of_right (p.eval\u2082 f x) hq\n#align polynomial.eval\u2082_mul_eq_zero_of_right Polynomial.eval\u2082_mul_eq_zero_of_right\n\n/-- `eval\u2082` as a `RingHom` -/\ndef eval\u2082RingHom (f : R \u2192+* S) (x : S) : R[X] \u2192+* S :=\n  { eval\u2082AddMonoidHom f x with\n    map_one' := eval\u2082_one _ _\n    map_mul' := fun _ _ => eval\u2082_mul _ _ }\n#align polynomial.eval\u2082_ring_hom Polynomial.eval\u2082RingHom\n\n@[simp]\ntheorem coe_eval\u2082RingHom (f : R \u2192+* S) (x) : \u21d1(eval\u2082RingHom f x) = eval\u2082 f x :=\n  rfl\n#align polynomial.coe_eval\u2082_ring_hom Polynomial.coe_eval\u2082RingHom\n\ntheorem eval\u2082_pow (n : \u2115) : (p ^ n).eval\u2082 f x = p.eval\u2082 f x ^ n :=\n  (eval\u2082RingHom _ _).map_pow _ _\n#align polynomial.eval\u2082_pow Polynomial.eval\u2082_pow\n\ntheorem eval\u2082_dvd : p \u2223 q \u2192 eval\u2082 f x p \u2223 eval\u2082 f x q :=\n  (eval\u2082RingHom f x).map_dvd\n#align polynomial.eval\u2082_dvd Polynomial.eval\u2082_dvd\n\ntheorem eval\u2082_eq_zero_of_dvd_of_eval\u2082_eq_zero (h : p \u2223 q) (h0 : eval\u2082 f x p = 0) :\n    eval\u2082 f x q = 0 :=\n  zero_dvd_iff.mp (h0 \u25b8 eval\u2082_dvd f x h)\n#align polynomial.eval\u2082_eq_zero_of_dvd_of_eval\u2082_eq_zero Polynomial.eval\u2082_eq_zero_of_dvd_of_eval\u2082_eq_zero\n\ntheorem eval\u2082_list_prod (l : List R[X]) (x : S) : eval\u2082 f x l.prod = (l.map (eval\u2082 f x)).prod :=\n  map_list_prod (eval\u2082RingHom f x) l\n#align polynomial.eval\u2082_list_prod Polynomial.eval\u2082_list_prod\n\nend\n\nend Eval\u2082\n\nsection Eval\n\nvariable {x : R}\n\n/-- `eval x p` is the evaluation of the polynomial `p` at `x` -/\ndef eval : R \u2192 R[X] \u2192 R :=\n  eval\u2082 (RingHom.id _)\n#align polynomial.eval Polynomial.eval\n\ntheorem eval_eq_sum : p.eval x = p.sum fun e a => a * x ^ e := by\n  rw [eval, eval\u2082_eq_sum]\n  rfl\n#align polynomial.eval_eq_sum Polynomial.eval_eq_sum\n\ntheorem eval_eq_sum_range {p : R[X]} (x : R) :\n    p.eval x = \u2211 i in Finset.range (p.natDegree + 1), p.coeff i * x ^ i := by\n  rw [eval_eq_sum, sum_over_range]; simp\n#align polynomial.eval_eq_sum_range Polynomial.eval_eq_sum_range\n\ntheorem eval_eq_sum_range' {p : R[X]} {n : \u2115} (hn : p.natDegree < n) (x : R) :\n    p.eval x = \u2211 i in Finset.range n, p.coeff i * x ^ i := by\n  rw [eval_eq_sum, p.sum_over_range' _ _ hn]; simp\n#align polynomial.eval_eq_sum_range' Polynomial.eval_eq_sum_range'\n\n@[simp]\ntheorem eval\u2082_at_apply {S : Type _} [Semiring S] (f : R \u2192+* S) (r : R) :\n    p.eval\u2082 f (f r) = f (p.eval r) := by\n  rw [eval\u2082_eq_sum, eval_eq_sum, sum, sum, f.map_sum]\n  simp only [f.map_mul, f.map_pow]\n#align polynomial.eval\u2082_at_apply Polynomial.eval\u2082_at_apply\n\n@[simp]\ntheorem eval\u2082_at_one {S : Type _} [Semiring S] (f : R \u2192+* S) : p.eval\u2082 f 1 = f (p.eval 1) := by\n  convert eval\u2082_at_apply (p := p) f 1\n  simp\n#align polynomial.eval\u2082_at_one Polynomial.eval\u2082_at_one\n\n@[simp]\ntheorem eval\u2082_at_nat_cast {S : Type _} [Semiring S] (f : R \u2192+* S) (n : \u2115) :\n    p.eval\u2082 f n = f (p.eval n) := by\n  convert eval\u2082_at_apply (p := p) f n\n  simp\n#align polynomial.eval\u2082_at_nat_cast Polynomial.eval\u2082_at_nat_cast\n\n@[simp]\ntheorem eval_C : (C a).eval x = a :=\n  eval\u2082_C _ _\n#align polynomial.eval_C Polynomial.eval_C\n\n@[simp]\ntheorem eval_nat_cast {n : \u2115} : (n : R[X]).eval x = n := by simp only [\u2190 C_eq_nat_cast, eval_C]\n#align polynomial.eval_nat_cast Polynomial.eval_nat_cast\n\n@[simp]\ntheorem eval_X : X.eval x = x :=\n  eval\u2082_X _ _\n#align polynomial.eval_X Polynomial.eval_X\n\n@[simp]\ntheorem eval_monomial {n a} : (monomial n a).eval x = a * x ^ n :=\n  eval\u2082_monomial _ _\n#align polynomial.eval_monomial Polynomial.eval_monomial\n\n@[simp]\ntheorem eval_zero : (0 : R[X]).eval x = 0 :=\n  eval\u2082_zero _ _\n#align polynomial.eval_zero Polynomial.eval_zero\n\n@[simp]\ntheorem eval_add : (p + q).eval x = p.eval x + q.eval x :=\n  eval\u2082_add _ _\n#align polynomial.eval_add Polynomial.eval_add\n\n@[simp]\ntheorem eval_one : (1 : R[X]).eval x = 1 :=\n  eval\u2082_one _ _\n#align polynomial.eval_one Polynomial.eval_one\n\nset_option linter.deprecated false in\n@[simp]\ntheorem eval_bit0 : (bit0 p).eval x = bit0 (p.eval x) :=\n  eval\u2082_bit0 _ _\n#align polynomial.eval_bit0 Polynomial.eval_bit0\n\nset_option linter.deprecated false in\n@[simp]\ntheorem eval_bit1 : (bit1 p).eval x = bit1 (p.eval x) :=\n  eval\u2082_bit1 _ _\n#align polynomial.eval_bit1 Polynomial.eval_bit1\n\n@[simp]\ntheorem eval_smul [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p : R[X])\n    (x : R) : (s \u2022 p).eval x = s \u2022 p.eval x := by\n  rw [\u2190 smul_one_smul R s p, eval, eval\u2082_smul, RingHom.id_apply, smul_one_mul]\n#align polynomial.eval_smul Polynomial.eval_smul\n\n@[simp]\ntheorem eval_C_mul : (C a * p).eval x = a * p.eval x := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q ph qh =>\n    simp only [mul_add, eval_add, ph, qh]\n  | h_monomial n b =>\n    simp only [mul_assoc, C_mul_monomial, eval_monomial]\n#align polynomial.eval_C_mul Polynomial.eval_C_mul\n\n/-- A reformulation of the expansion of (1 + y)^d:\n$$(d + 1) (1 + y)^d - (d + 1)y^d = \\sum_{i = 0}^d {d + 1 \\choose i} \\cdot i \\cdot y^{i - 1}.$$\n-/\ntheorem eval_monomial_one_add_sub [CommRing S] (d : \u2115) (y : S) :\n    eval (1 + y) (monomial d (d + 1 : S)) - eval y (monomial d (d + 1 : S)) =\n      \u2211 x_1 : \u2115 in range (d + 1), \u2191((d + 1).choose x_1) * (\u2191x_1 * y ^ (x_1 - 1)) := by\n  have cast_succ : (d + 1 : S) = ((d.succ : \u2115) : S) := by simp only [Nat.cast_succ]\n  rw [cast_succ, eval_monomial, eval_monomial, add_comm, add_pow]\n  -- Porting note: `apply_congr` hadn't been ported yet, so `congr` & `ext` is used.\n  conv_lhs =>\n    congr\n    \u00b7 congr\n      \u00b7 skip\n      \u00b7 congr\n        \u00b7 skip\n        \u00b7 ext\n          rw [one_pow, mul_one, mul_comm]\n  rw [sum_range_succ, mul_add, Nat.choose_self, Nat.cast_one, one_mul, add_sub_cancel, mul_sum,\n    sum_range_succ', Nat.cast_zero, zero_mul, mul_zero, add_zero]\n  refine sum_congr rfl fun y _hy => ?_\n  rw [\u2190 mul_assoc, \u2190 mul_assoc, \u2190 Nat.cast_mul, Nat.succ_mul_choose_eq, Nat.cast_mul,\n    Nat.add_sub_cancel]\n#align polynomial.eval_monomial_one_add_sub Polynomial.eval_monomial_one_add_sub\n\n/-- `Polynomial.eval` as linear map -/\n@[simps]\ndef leval {R : Type _} [Semiring R] (r : R) : R[X] \u2192\u2097[R] R where\n  toFun f := f.eval r\n  map_add' _f _g := eval_add\n  map_smul' c f := eval_smul c f r\n#align polynomial.leval Polynomial.leval\n#align polynomial.leval_apply Polynomial.leval_apply\n\n@[simp]\ntheorem eval_nat_cast_mul {n : \u2115} : ((n : R[X]) * p).eval x = n * p.eval x := by\n  rw [\u2190 C_eq_nat_cast, eval_C_mul]\n#align polynomial.eval_nat_cast_mul Polynomial.eval_nat_cast_mul\n\n@[simp]\ntheorem eval_mul_X : (p * X).eval x = p.eval x * x := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q ph qh =>\n    simp only [add_mul, eval_add, ph, qh]\n  | h_monomial n a =>\n    simp only [\u2190 monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ',\n      mul_assoc]\n#align polynomial.eval_mul_X Polynomial.eval_mul_X\n\n@[simp]\ntheorem eval_mul_X_pow {k : \u2115} : (p * X ^ k).eval x = p.eval x * x ^ k := by\n  induction' k with k ih\n  \u00b7 simp\n  \u00b7 simp [pow_succ', \u2190 mul_assoc, ih]\n#align polynomial.eval_mul_X_pow Polynomial.eval_mul_X_pow\n\ntheorem eval_sum (p : R[X]) (f : \u2115 \u2192 R \u2192 R[X]) (x : R) :\n    (p.sum f).eval x = p.sum fun n a => (f n a).eval x :=\n  eval\u2082_sum _ _ _ _\n#align polynomial.eval_sum Polynomial.eval_sum\n\ntheorem eval_finset_sum (s : Finset \u03b9) (g : \u03b9 \u2192 R[X]) (x : R) :\n    (\u2211 i in s, g i).eval x = \u2211 i in s, (g i).eval x :=\n  eval\u2082_finset_sum _ _ _ _\n#align polynomial.eval_finset_sum Polynomial.eval_finset_sum\n\n/-- `IsRoot p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/\ndef IsRoot (p : R[X]) (a : R) : Prop :=\n  p.eval a = 0\n#align polynomial.is_root Polynomial.IsRoot\n\ninstance IsRoot.decidable [DecidableEq R] : Decidable (IsRoot p a) := by\n  unfold IsRoot; infer_instance\n#align polynomial.is_root.decidable Polynomial.IsRoot.decidable\n\n@[simp]\ntheorem IsRoot.def : IsRoot p a \u2194 p.eval a = 0 :=\n  Iff.rfl\n#align polynomial.is_root.def Polynomial.IsRoot.def\n\ntheorem IsRoot.eq_zero (h : IsRoot p x) : eval x p = 0 :=\n  h\n#align polynomial.is_root.eq_zero Polynomial.IsRoot.eq_zero\n\ntheorem coeff_zero_eq_eval_zero (p : R[X]) : coeff p 0 = p.eval 0 :=\n  calc\n    coeff p 0 = coeff p 0 * 0 ^ 0 := by simp\n    _ = p.eval 0 := by\n      symm\n      rw [eval_eq_sum]\n      exact\n        Finset.sum_eq_single _ (fun b _ hb => by simp [zero_pow (Nat.pos_of_ne_zero hb)]) (by simp)\n\n#align polynomial.coeff_zero_eq_eval_zero Polynomial.coeff_zero_eq_eval_zero\n\ntheorem zero_isRoot_of_coeff_zero_eq_zero {p : R[X]} (hp : p.coeff 0 = 0) : IsRoot p 0 := by\n  rwa [coeff_zero_eq_eval_zero] at hp\n#align polynomial.zero_is_root_of_coeff_zero_eq_zero Polynomial.zero_isRoot_of_coeff_zero_eq_zero\n\n\n\ntheorem not_isRoot_C (r a : R) (hr : r \u2260 0) : \u00acIsRoot (C r) a := by simpa using hr\n#align polynomial.not_is_root_C Polynomial.not_isRoot_C\n\ntheorem eval_surjective (x : R) : Function.Surjective <| eval x := fun y => \u27e8C y, eval_C\u27e9\n#align polynomial.eval_surjective Polynomial.eval_surjective\n\nend Eval\n\nsection Comp\n\n/-- The composition of polynomials as a polynomial. -/\ndef comp (p q : R[X]) : R[X] :=\n  p.eval\u2082 C q\n#align polynomial.comp Polynomial.comp\n\ntheorem comp_eq_sum_left : p.comp q = p.sum fun e a => C a * q ^ e := by rw [comp, eval\u2082_eq_sum]\n#align polynomial.comp_eq_sum_left Polynomial.comp_eq_sum_left\n\n@[simp]\ntheorem comp_X : p.comp X = p := by\n  simp only [comp, eval\u2082_def, C_mul_X_pow_eq_monomial]\n  exact sum_monomial_eq _\n#align polynomial.comp_X Polynomial.comp_X\n\n@[simp]\ntheorem X_comp : X.comp p = p :=\n  eval\u2082_X _ _\n#align polynomial.X_comp Polynomial.X_comp\n\n@[simp]\ntheorem comp_C : p.comp (C a) = C (p.eval a) := by simp [comp, (C : R \u2192+* _).map_sum]\n#align polynomial.comp_C Polynomial.comp_C\n\n@[simp]\ntheorem C_comp : (C a).comp p = C a :=\n  eval\u2082_C _ _\n#align polynomial.C_comp Polynomial.C_comp\n\n@[simp]\ntheorem nat_cast_comp {n : \u2115} : (n : R[X]).comp p = n := by rw [\u2190 C_eq_nat_cast, C_comp]\n#align polynomial.nat_cast_comp Polynomial.nat_cast_comp\n\n--Porting note: new theorem\n@[simp]\ntheorem ofNat_comp (n : \u2115) [n.AtLeastTwo] : (OfNat.ofNat n : R[X]).comp p = n :=\n  nat_cast_comp\n\n@[simp]\ntheorem comp_zero : p.comp (0 : R[X]) = C (p.eval 0) := by rw [\u2190 C_0, comp_C]\n#align polynomial.comp_zero Polynomial.comp_zero\n\n@[simp]\ntheorem zero_comp : comp (0 : R[X]) p = 0 := by rw [\u2190 C_0, C_comp]\n#align polynomial.zero_comp Polynomial.zero_comp\n\n@[simp]\ntheorem comp_one : p.comp 1 = C (p.eval 1) := by rw [\u2190 C_1, comp_C]\n#align polynomial.comp_one Polynomial.comp_one\n\n@[simp]\ntheorem one_comp : comp (1 : R[X]) p = 1 := by rw [\u2190 C_1, C_comp]\n#align polynomial.one_comp Polynomial.one_comp\n\n@[simp]\ntheorem add_comp : (p + q).comp r = p.comp r + q.comp r :=\n  eval\u2082_add _ _\n#align polynomial.add_comp Polynomial.add_comp\n\n@[simp]\ntheorem monomial_comp (n : \u2115) : (monomial n a).comp p = C a * p ^ n :=\n  eval\u2082_monomial _ _\n#align polynomial.monomial_comp Polynomial.monomial_comp\n\n@[simp]\ntheorem mul_X_comp : (p * X).comp r = p.comp r * r := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q hp hq =>\n    simp only [hp, hq, add_mul, add_comp]\n  | h_monomial n b =>\n    simp only [pow_succ', mul_assoc, monomial_mul_X, monomial_comp]\n#align polynomial.mul_X_comp Polynomial.mul_X_comp\n\n@[simp]\ntheorem X_pow_comp {k : \u2115} : (X ^ k).comp p = p ^ k := by\n  induction' k with k ih\n  \u00b7 simp\n  \u00b7 simp [pow_succ', mul_X_comp, ih]\n#align polynomial.X_pow_comp Polynomial.X_pow_comp\n\n@[simp]\ntheorem mul_X_pow_comp {k : \u2115} : (p * X ^ k).comp r = p.comp r * r ^ k := by\n  induction' k with k ih\n  \u00b7 simp\n  \u00b7 simp [ih, pow_succ', \u2190 mul_assoc, mul_X_comp]\n#align polynomial.mul_X_pow_comp Polynomial.mul_X_pow_comp\n\n@[simp]\ntheorem C_mul_comp : (C a * p).comp r = C a * p.comp r := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q hp hq =>\n    simp [hp, hq, mul_add]\n  | h_monomial n b =>\n    simp [mul_assoc]\n#align polynomial.C_mul_comp Polynomial.C_mul_comp\n\n@[simp]\ntheorem nat_cast_mul_comp {n : \u2115} : ((n : R[X]) * p).comp r = n * p.comp r := by\n  rw [\u2190 C_eq_nat_cast, C_mul_comp, C_eq_nat_cast]\n#align polynomial.nat_cast_mul_comp Polynomial.nat_cast_mul_comp\n\n@[simp]\ntheorem mul_comp {R : Type _} [CommSemiring R] (p q r : R[X]) :\n    (p * q).comp r = p.comp r * q.comp r :=\n  eval\u2082_mul _ _\n#align polynomial.mul_comp Polynomial.mul_comp\n\n@[simp]\ntheorem pow_comp {R : Type _} [CommSemiring R] (p q : R[X]) (n : \u2115) :\n    (p ^ n).comp q = p.comp q ^ n :=\n  (MonoidHom.mk (OneHom.mk (fun r : R[X] => r.comp q) one_comp) fun r s => mul_comp r s q).map_pow\n    p n\n#align polynomial.pow_comp Polynomial.pow_comp\n\nset_option linter.deprecated false in\n@[simp]\ntheorem bit0_comp : comp (bit0 p : R[X]) q = bit0 (p.comp q) := by simp only [bit0, add_comp]\n#align polynomial.bit0_comp Polynomial.bit0_comp\n\nset_option linter.deprecated false in\n@[simp]\ntheorem bit1_comp : comp (bit1 p : R[X]) q = bit1 (p.comp q) := by\n  simp only [bit1, add_comp, bit0_comp, one_comp]\n#align polynomial.bit1_comp Polynomial.bit1_comp\n\n@[simp]\ntheorem smul_comp [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p q : R[X]) :\n    (s \u2022 p).comp q = s \u2022 p.comp q := by\n  rw [\u2190 smul_one_smul R s p, comp, comp, eval\u2082_smul, \u2190 smul_eq_C_mul, smul_assoc, one_smul]\n#align polynomial.smul_comp Polynomial.smul_comp\n\ntheorem comp_assoc {R : Type _} [CommSemiring R] (\u03c6 \u03c8 \u03c7 : R[X]) :\n    (\u03c6.comp \u03c8).comp \u03c7 = \u03c6.comp (\u03c8.comp \u03c7) := by\n  refine Polynomial.induction_on \u03c6 ?_ ?_ ?_ <;>\n    \u00b7 intros\n      simp_all only [add_comp, mul_comp, C_comp, X_comp, pow_succ', \u2190 mul_assoc]\n#align polynomial.comp_assoc Polynomial.comp_assoc\n\ntheorem coeff_comp_degree_mul_degree (hqd0 : natDegree q \u2260 0) :\n    coeff (p.comp q) (natDegree p * natDegree q) = leadingCoeff p * leadingCoeff q ^ natDegree p :=\n  by\n  rw [comp, eval\u2082_def, coeff_sum]\n  -- Porting note: `convert` \u2192 `refine`\n  refine Eq.trans (Finset.sum_eq_single p.natDegree ?h\u2080 ?h\u2081) ?h\u2082\n  case h\u2082 =>\n    simp only [coeff_natDegree, coeff_C_mul, coeff_pow_mul_natDegree]\n  case h\u2080 =>\n    intro b hbs hbp\n    refine' coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt _)\n    rw [natDegree_C, zero_add]\n    refine' natDegree_pow_le.trans_lt ((mul_lt_mul_right (pos_iff_ne_zero.mpr hqd0)).mpr _)\n    exact lt_of_le_of_ne (le_natDegree_of_mem_supp _ hbs) hbp\n  case h\u2081 =>\n    simp (config := { contextual := true })\n#align polynomial.coeff_comp_degree_mul_degree Polynomial.coeff_comp_degree_mul_degree\n\nend Comp\n\nsection Map\n\nvariable [Semiring S]\n\nvariable (f : R \u2192+* S)\n\n/-- `map f p` maps a polynomial `p` across a ring hom `f` -/\ndef map : R[X] \u2192 S[X] :=\n  eval\u2082 (C.comp f) X\n#align polynomial.map Polynomial.map\n\n@[simp]\ntheorem map_C : (C a).map f = C (f a) :=\n  eval\u2082_C _ _\n#align polynomial.map_C Polynomial.map_C\n\n@[simp]\ntheorem map_X : X.map f = X :=\n  eval\u2082_X _ _\n#align polynomial.map_X Polynomial.map_X\n\n@[simp]\ntheorem map_monomial {n a} : (monomial n a).map f = monomial n (f a) := by\n  dsimp only [map]\n  rw [eval\u2082_monomial, \u2190 C_mul_X_pow_eq_monomial]; rfl\n#align polynomial.map_monomial Polynomial.map_monomial\n\n@[simp]\nprotected theorem map_zero : (0 : R[X]).map f = 0 :=\n  eval\u2082_zero _ _\n#align polynomial.map_zero Polynomial.map_zero\n\n@[simp]\nprotected theorem map_add : (p + q).map f = p.map f + q.map f :=\n  eval\u2082_add _ _\n#align polynomial.map_add Polynomial.map_add\n\n@[simp]\nprotected theorem map_one : (1 : R[X]).map f = 1 :=\n  eval\u2082_one _ _\n#align polynomial.map_one Polynomial.map_one\n\n@[simp]\nprotected theorem map_mul : (p * q).map f = p.map f * q.map f := by\n  rw [map, eval\u2082_mul_noncomm]\n  exact fun k => (commute_X _).symm\n#align polynomial.map_mul Polynomial.map_mul\n\n@[simp]\nprotected theorem map_smul (r : R) : (r \u2022 p).map f = f r \u2022 p.map f := by\n  rw [map, eval\u2082_smul, RingHom.comp_apply, C_mul']\n#align polynomial.map_smul Polynomial.map_smul\n\n-- `map` is a ring-hom unconditionally, and theoretically the definition could be replaced,\n-- but this turns out not to be easy because `p.map f` does not resolve to `Polynomial.map`\n-- if `map` is a `RingHom` instead of a plain function; the elaborator does not try to coerce\n-- to a function before trying field (dot) notation (this may be technically infeasible);\n-- the relevant code is (both lines): https://github.com/leanprover-community/\n-- lean/blob/487ac5d7e9b34800502e1ddf3c7c806c01cf9d51/src/frontends/lean/elaborator.cpp#L1876-L1913\n/-- `Polynomial.map` as a `RingHom`. -/\ndef mapRingHom (f : R \u2192+* S) : R[X] \u2192+* S[X] where\n  toFun := Polynomial.map f\n  map_add' _ _ := Polynomial.map_add f\n  map_zero' := Polynomial.map_zero f\n  map_mul' _ _ := Polynomial.map_mul f\n  map_one' := Polynomial.map_one f\n#align polynomial.map_ring_hom Polynomial.mapRingHom\n\n@[simp]\ntheorem coe_mapRingHom (f : R \u2192+* S) : \u21d1(mapRingHom f) = map f :=\n  rfl\n#align polynomial.coe_map_ring_hom Polynomial.coe_mapRingHom\n\n-- This is protected to not clash with the global `map_nat_cast`.\n@[simp]\nprotected theorem map_nat_cast (n : \u2115) : (n : R[X]).map f = n :=\n  map_natCast (mapRingHom f) n\n#align polynomial.map_nat_cast Polynomial.map_nat_cast\n\n--Porting note: new theorem\n@[simp]\nprotected theorem map_ofNat (n : \u2115) [n.AtLeastTwo] : (OfNat.ofNat n : R[X]).map f = OfNat.ofNat n :=\n  show (n : R[X]).map f = n by rw [Polynomial.map_nat_cast]\n\nset_option linter.deprecated false in\n@[simp]\nprotected theorem map_bit0 : (bit0 p).map f = bit0 (p.map f) :=\n  map_bit0 (mapRingHom f) p\n#align polynomial.map_bit0 Polynomial.map_bit0\n\nset_option linter.deprecated false in\n@[simp]\nprotected theorem map_bit1 : (bit1 p).map f = bit1 (p.map f) :=\n  map_bit1 (mapRingHom f) p\n#align polynomial.map_bit1 Polynomial.map_bit1\n\n--TODO rename to `map_dvd_map`\ntheorem map_dvd (f : R \u2192+* S) {x y : R[X]} : x \u2223 y \u2192 x.map f \u2223 y.map f :=\n  (mapRingHom f).map_dvd\n#align polynomial.map_dvd Polynomial.map_dvd\n\n@[simp]\ntheorem coeff_map (n : \u2115) : coeff (p.map f) n = f (coeff p n) := by\n  rw [map, eval\u2082_def, coeff_sum, sum]\n  conv_rhs => rw [\u2190 sum_C_mul_X_pow_eq p, coeff_sum, sum, map_sum]\n  refine' Finset.sum_congr rfl fun x _hx => _\n  -- Porting note: Was `simp [Function.comp, coeff_C_mul_X_pow, f.map_mul]`.\n  simp [Function.comp, coeff_C_mul_X_pow, - map_mul, - coeff_C_mul]\n  split_ifs <;> simp [f.map_zero]\n#align polynomial.coeff_map Polynomial.coeff_map\n\n/-- If `R` and `S` are isomorphic, then so are their polynomial rings. -/\n@[simps!]\ndef mapEquiv (e : R \u2243+* S) : R[X] \u2243+* S[X] :=\n  RingEquiv.ofHomInv (mapRingHom (e : R \u2192+* S)) (mapRingHom (e.symm : S \u2192+* R)) (by ext <;> simp)\n    (by ext <;> simp)\n#align polynomial.map_equiv Polynomial.mapEquiv\n#align polynomial.map_equiv_apply Polynomial.mapEquiv_apply\n#align polynomial.map_equiv_symm_apply Polynomial.mapEquiv_symm_apply\n\ntheorem map_map [Semiring T] (g : S \u2192+* T) (p : R[X]) : (p.map f).map g = p.map (g.comp f) :=\n  ext (by simp [coeff_map])\n#align polynomial.map_map Polynomial.map_map\n\n@[simp]\ntheorem map_id : p.map (RingHom.id _) = p := by simp [Polynomial.ext_iff, coeff_map]\n#align polynomial.map_id Polynomial.map_id\n\ntheorem eval\u2082_eq_eval_map {x : S} : p.eval\u2082 f x = (p.map f).eval x := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q hp hq =>\n    simp [hp, hq]\n  | h_monomial n r =>\n    simp\n#align polynomial.eval\u2082_eq_eval_map Polynomial.eval\u2082_eq_eval_map\n\ntheorem map_injective (hf : Function.Injective f) : Function.Injective (map f) := fun p q h =>\n  ext fun m => hf <| by rw [\u2190 coeff_map f, \u2190 coeff_map f, h]\n#align polynomial.map_injective Polynomial.map_injective\n\ntheorem map_surjective (hf : Function.Surjective f) : Function.Surjective (map f) := fun p =>\n  Polynomial.induction_on' p\n    (fun p q hp hq =>\n      let \u27e8p', hp'\u27e9 := hp\n      let \u27e8q', hq'\u27e9 := hq\n      \u27e8p' + q', by rw [Polynomial.map_add f, hp', hq']\u27e9)\n    fun n s =>\n    let \u27e8r, hr\u27e9 := hf s\n    \u27e8monomial n r, by rw [map_monomial f, hr]\u27e9\n#align polynomial.map_surjective Polynomial.map_surjective\n\ntheorem degree_map_le (p : R[X]) : degree (p.map f) \u2264 degree p := by\n  refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_\n  rw [degree_lt_iff_coeff_zero] at hm\n  simp [hm m le_rfl]\n#align polynomial.degree_map_le Polynomial.degree_map_le\n\ntheorem natDegree_map_le (p : R[X]) : natDegree (p.map f) \u2264 natDegree p :=\n  natDegree_le_natDegree (degree_map_le f p)\n#align polynomial.nat_degree_map_le Polynomial.natDegree_map_le\n\nvariable {f}\n\nprotected theorem map_eq_zero_iff (hf : Function.Injective f) : p.map f = 0 \u2194 p = 0 :=\n  map_eq_zero_iff (mapRingHom f) (map_injective f hf)\n#align polynomial.map_eq_zero_iff Polynomial.map_eq_zero_iff\n\nprotected theorem map_ne_zero_iff (hf : Function.Injective f) : p.map f \u2260 0 \u2194 p \u2260 0 :=\n  (Polynomial.map_eq_zero_iff hf).not\n#align polynomial.map_ne_zero_iff Polynomial.map_ne_zero_iff\n\ntheorem map_monic_eq_zero_iff (hp : p.Monic) : p.map f = 0 \u2194 \u2200 x, f x = 0 :=\n  \u27e8fun hfp x =>\n    calc\n      f x = f x * f p.leadingCoeff := by simp only [mul_one, hp.leadingCoeff, f.map_one]\n      _ = f x * (p.map f).coeff p.natDegree := (congr_arg _ (coeff_map _ _).symm)\n      _ = 0 := by simp only [hfp, mul_zero, coeff_zero]\n      ,\n    fun h => ext fun n => by simp only [h, coeff_map, coeff_zero]\u27e9\n#align polynomial.map_monic_eq_zero_iff Polynomial.map_monic_eq_zero_iff\n\ntheorem map_monic_ne_zero (hp : p.Monic) [Nontrivial S] : p.map f \u2260 0 := fun h =>\n  f.map_one_ne_zero ((map_monic_eq_zero_iff hp).mp h _)\n#align polynomial.map_monic_ne_zero Polynomial.map_monic_ne_zero\n\ntheorem degree_map_eq_of_leadingCoeff_ne_zero (f : R \u2192+* S) (hf : f (leadingCoeff p) \u2260 0) :\n    degree (p.map f) = degree p :=\n  le_antisymm (degree_map_le f _) <| by\n    have hp0 : p \u2260 0 :=\n      leadingCoeff_ne_zero.mp fun hp0 => hf (_root_.trans (congr_arg _ hp0) f.map_zero)\n    rw [degree_eq_natDegree hp0]\n    refine' le_degree_of_ne_zero _\n    rw [coeff_map]\n    exact hf\n#align polynomial.degree_map_eq_of_leading_coeff_ne_zero Polynomial.degree_map_eq_of_leadingCoeff_ne_zero\n\ntheorem natDegree_map_of_leadingCoeff_ne_zero (f : R \u2192+* S) (hf : f (leadingCoeff p) \u2260 0) :\n    natDegree (p.map f) = natDegree p :=\n  natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f hf)\n#align polynomial.nat_degree_map_of_leading_coeff_ne_zero Polynomial.natDegree_map_of_leadingCoeff_ne_zero\n\ntheorem leadingCoeff_map_of_leadingCoeff_ne_zero (f : R \u2192+* S) (hf : f (leadingCoeff p) \u2260 0) :\n    leadingCoeff (p.map f) = f (leadingCoeff p) := by\n  unfold leadingCoeff\n  rw [coeff_map, natDegree_map_of_leadingCoeff_ne_zero f hf]\n#align polynomial.leading_coeff_map_of_leading_coeff_ne_zero Polynomial.leadingCoeff_map_of_leadingCoeff_ne_zero\n\nvariable (f)\n\n@[simp]\ntheorem mapRingHom_id : mapRingHom (RingHom.id R) = RingHom.id R[X] :=\n  RingHom.ext fun _x => map_id\n#align polynomial.map_ring_hom_id Polynomial.mapRingHom_id\n\n@[simp]\ntheorem mapRingHom_comp [Semiring T] (f : S \u2192+* T) (g : R \u2192+* S) :\n    (mapRingHom f).comp (mapRingHom g) = mapRingHom (f.comp g) :=\n  RingHom.ext <| Polynomial.map_map g f\n#align polynomial.map_ring_hom_comp Polynomial.mapRingHom_comp\n\nprotected theorem map_list_prod (L : List R[X]) : L.prod.map f = (L.map <| map f).prod :=\n  Eq.symm <| List.prod_hom _ (mapRingHom f).toMonoidHom\n#align polynomial.map_list_prod Polynomial.map_list_prod\n\n@[simp]\nprotected theorem map_pow (n : \u2115) : (p ^ n).map f = p.map f ^ n :=\n  (mapRingHom f).map_pow _ _\n#align polynomial.map_pow Polynomial.map_pow\n\ntheorem mem_map_rangeS {p : S[X]} : p \u2208 (mapRingHom f).rangeS \u2194 \u2200 n, p.coeff n \u2208 f.rangeS := by\n  constructor\n  \u00b7 rintro \u27e8p, rfl\u27e9 n\n    rw [coe_mapRingHom, coeff_map]\n    exact Set.mem_range_self _\n  \u00b7 intro h\n    rw [p.as_sum_range_C_mul_X_pow]\n    refine' (mapRingHom f).rangeS.sum_mem _\n    intro i _hi\n    rcases h i with \u27e8c, hc\u27e9\n    use C c * X ^ i\n    rw [coe_mapRingHom, Polynomial.map_mul, map_C, hc, Polynomial.map_pow, map_X]\n#align polynomial.mem_map_srange Polynomial.mem_map_rangeS\n\ntheorem mem_map_range {R S : Type _} [Ring R] [Ring S] (f : R \u2192+* S) {p : S[X]} :\n    p \u2208 (mapRingHom f).range \u2194 \u2200 n, p.coeff n \u2208 f.range :=\n  mem_map_rangeS f\n#align polynomial.mem_map_range Polynomial.mem_map_range\n\ntheorem eval\u2082_map [Semiring T] (g : S \u2192+* T) (x : T) : (p.map f).eval\u2082 g x = p.eval\u2082 (g.comp f) x :=\n  by rw [eval\u2082_eq_eval_map, eval\u2082_eq_eval_map, map_map]\n#align polynomial.eval\u2082_map Polynomial.eval\u2082_map\n\ntheorem eval_map (x : S) : (p.map f).eval x = p.eval\u2082 f x :=\n  (eval\u2082_eq_eval_map f).symm\n#align polynomial.eval_map Polynomial.eval_map\n\nprotected theorem map_sum {\u03b9 : Type _} (g : \u03b9 \u2192 R[X]) (s : Finset \u03b9) :\n    (\u2211 i in s, g i).map f = \u2211 i in s, (g i).map f :=\n  (mapRingHom f).map_sum _ _\n#align polynomial.map_sum Polynomial.map_sum\n\ntheorem map_comp (p q : R[X]) : map f (p.comp q) = (map f p).comp (map f q) :=\n  Polynomial.induction_on p (by simp only [map_C, forall_const, C_comp, eq_self_iff_true])\n    (by\n      simp (config := { contextual := true }) only [Polynomial.map_add, add_comp, forall_const,\n        imp_true_iff, eq_self_iff_true])\n    (by\n      simp (config := { contextual := true }) only [pow_succ', \u2190 mul_assoc, comp, forall_const,\n        eval\u2082_mul_X, imp_true_iff, eq_self_iff_true, map_X, Polynomial.map_mul])\n#align polynomial.map_comp Polynomial.map_comp\n\n@[simp]\ntheorem eval_zero_map (f : R \u2192+* S) (p : R[X]) : (p.map f).eval 0 = f (p.eval 0) := by\n  simp [\u2190 coeff_zero_eq_eval_zero]\n#align polynomial.eval_zero_map Polynomial.eval_zero_map\n\n@[simp]\ntheorem eval_one_map (f : R \u2192+* S) (p : R[X]) : (p.map f).eval 1 = f (p.eval 1) := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q hp hq =>\n    simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]\n  | h_monomial n r =>\n    simp only [one_pow, mul_one, eval_monomial, map_monomial]\n#align polynomial.eval_one_map Polynomial.eval_one_map\n\n@[simp]\ntheorem eval_nat_cast_map (f : R \u2192+* S) (p : R[X]) (n : \u2115) :\n    (p.map f).eval (n : S) = f (p.eval n) := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q hp hq =>\n    simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]\n  | h_monomial n r =>\n    simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul]\n#align polynomial.eval_nat_cast_map Polynomial.eval_nat_cast_map\n\n@[simp]\ntheorem eval_int_cast_map {R S : Type _} [Ring R] [Ring S] (f : R \u2192+* S) (p : R[X]) (i : \u2124) :\n    (p.map f).eval (i : S) = f (p.eval i) := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add p q hp hq =>\n    simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]\n  | h_monomial n r =>\n    simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul]\n#align polynomial.eval_int_cast_map Polynomial.eval_int_cast_map\n\nend Map\n\n/-!\nwe have made `eval\u2082` irreducible from the start.\n\nPerhaps we can make also `eval`, `comp`, and `map` irreducible too?\n-/\n\n\nsection HomEval\u2082\n\nvariable [Semiring S] [Semiring T] (f : R \u2192+* S) (g : S \u2192+* T) (p)\n\ntheorem hom_eval\u2082 (x : S) : g (p.eval\u2082 f x) = p.eval\u2082 (g.comp f) (g x) := by\n  rw [\u2190 eval\u2082_map, eval\u2082_at_apply, eval_map]\n#align polynomial.hom_eval\u2082 Polynomial.hom_eval\u2082\n\nend HomEval\u2082\n\nend Semiring\n\nsection CommSemiring\n\nsection Eval\n\nsection\n\nvariable [Semiring R] {p q : R[X]} {x : R} [Semiring S] (f : R \u2192+* S)\n\ntheorem eval\u2082_hom (x : R) : p.eval\u2082 f (f x) = f (p.eval x) :=\n  RingHom.comp_id f \u25b8 (hom_eval\u2082 p (RingHom.id R) f x).symm\n#align polynomial.eval\u2082_hom Polynomial.eval\u2082_hom\n\nend\n\nsection\n\nvariable [Semiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R \u2192+* S)\n\ntheorem eval\u2082_comp {x : S} : eval\u2082 f x (p.comp q) = eval\u2082 f (eval\u2082 f x q) p := by\n  rw [comp, p.as_sum_range]; simp [eval\u2082_finset_sum, eval\u2082_pow]\n#align polynomial.eval\u2082_comp Polynomial.eval\u2082_comp\n\n@[simp]\ntheorem iterate_comp_eval\u2082 (k : \u2115) (t : S) :\n    eval\u2082 f t ((p.comp^[k]) q) = ((fun x => eval\u2082 f x p)^[k]) (eval\u2082 f t q) := by\n  induction' k with k IH\n  \u00b7 simp\n  \u00b7 rw [Function.iterate_succ_apply', Function.iterate_succ_apply', eval\u2082_comp, IH]\n#align polynomial.iterate_comp_eval\u2082 Polynomial.iterate_comp_eval\u2082\n\nend\n\nsection\n\nvariable [CommSemiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R \u2192+* S)\n\n@[simp]\ntheorem eval_mul : (p * q).eval x = p.eval x * q.eval x :=\n  eval\u2082_mul _ _\n#align polynomial.eval_mul Polynomial.eval_mul\n\n/-- `eval r`, regarded as a ring homomorphism from `R[X]` to `R`. -/\ndef evalRingHom : R \u2192 R[X] \u2192+* R :=\n  eval\u2082RingHom (RingHom.id _)\n#align polynomial.eval_ring_hom Polynomial.evalRingHom\n\n@[simp]\ntheorem coe_evalRingHom (r : R) : (evalRingHom r : R[X] \u2192 R) = eval r :=\n  rfl\n#align polynomial.coe_eval_ring_hom Polynomial.coe_evalRingHom\n\ntheorem evalRingHom_zero : evalRingHom 0 = constantCoeff :=\n  FunLike.ext _ _ fun p => p.coeff_zero_eq_eval_zero.symm\n#align polynomial.eval_ring_hom_zero Polynomial.evalRingHom_zero\n\n@[simp]\ntheorem eval_pow (n : \u2115) : (p ^ n).eval x = p.eval x ^ n :=\n  eval\u2082_pow _ _ _\n#align polynomial.eval_pow Polynomial.eval_pow\n\n@[simp]\ntheorem eval_comp : (p.comp q).eval x = p.eval (q.eval x) := by\n  -- Porting note: `apply` \u2192 `induction`\n  induction p using Polynomial.induction_on' with\n  | h_add r s hr hs =>\n    simp [add_comp, hr, hs]\n  | h_monomial n a =>\n    simp\n#align polynomial.eval_comp Polynomial.eval_comp\n\n/-- `comp p`, regarded as a ring homomorphism from `R[X]` to itself. -/\ndef compRingHom : R[X] \u2192 R[X] \u2192+* R[X] :=\n  eval\u2082RingHom C\n#align polynomial.comp_ring_hom Polynomial.compRingHom\n\n@[simp]\ntheorem coe_compRingHom (q : R[X]) : (compRingHom q : R[X] \u2192 R[X]) = fun p => comp p q :=\n  rfl\n#align polynomial.coe_comp_ring_hom Polynomial.coe_compRingHom\n\ntheorem coe_compRingHom_apply (p q : R[X]) : (compRingHom q : R[X] \u2192 R[X]) p = comp p q :=\n  rfl\n#align polynomial.coe_comp_ring_hom_apply Polynomial.coe_compRingHom_apply\n\ntheorem root_mul_left_of_isRoot (p : R[X]) {q : R[X]} : IsRoot q a \u2192 IsRoot (p * q) a := fun H => by\n  rw [IsRoot, eval_mul, IsRoot.def.1 H, mul_zero]\n#align polynomial.root_mul_left_of_is_root Polynomial.root_mul_left_of_isRoot\n\ntheorem root_mul_right_of_isRoot {p : R[X]} (q : R[X]) : IsRoot p a \u2192 IsRoot (p * q) a := fun H =>\n  by rw [IsRoot, eval_mul, IsRoot.def.1 H, zero_mul]\n#align polynomial.root_mul_right_of_is_root Polynomial.root_mul_right_of_isRoot\n\ntheorem eval\u2082_multiset_prod (s : Multiset R[X]) (x : S) :\n    eval\u2082 f x s.prod = (s.map (eval\u2082 f x)).prod :=\n  map_multiset_prod (eval\u2082RingHom f x) s\n#align polynomial.eval\u2082_multiset_prod Polynomial.eval\u2082_multiset_prod\n\ntheorem eval\u2082_finset_prod (s : Finset \u03b9) (g : \u03b9 \u2192 R[X]) (x : S) :\n    (\u220f i in s, g i).eval\u2082 f x = \u220f i in s, (g i).eval\u2082 f x :=\n  map_prod (eval\u2082RingHom f x) _ _\n#align polynomial.eval\u2082_finset_prod Polynomial.eval\u2082_finset_prod\n\n/-- Polynomial evaluation commutes with `List.prod`\n-/\ntheorem eval_list_prod (l : List R[X]) (x : R) : eval x l.prod = (l.map (eval x)).prod :=\n  (evalRingHom x).map_list_prod l\n#align polynomial.eval_list_prod Polynomial.eval_list_prod\n\n/-- Polynomial evaluation commutes with `Multiset.prod`\n-/\ntheorem eval_multiset_prod (s : Multiset R[X]) (x : R) : eval x s.prod = (s.map (eval x)).prod :=\n  (evalRingHom x).map_multiset_prod s\n#align polynomial.eval_multiset_prod Polynomial.eval_multiset_prod\n\n/-- Polynomial evaluation commutes with `Finset.prod`\n-/\ntheorem eval_prod {\u03b9 : Type _} (s : Finset \u03b9) (p : \u03b9 \u2192 R[X]) (x : R) :\n    eval x (\u220f j in s, p j) = \u220f j in s, eval x (p j) :=\n  (evalRingHom x).map_prod _ _\n#align polynomial.eval_prod Polynomial.eval_prod\n\ntheorem list_prod_comp (l : List R[X]) (q : R[X]) :\n    l.prod.comp q = (l.map fun p : R[X] => p.comp q).prod :=\n  map_list_prod (compRingHom q) _\n#align polynomial.list_prod_comp Polynomial.list_prod_comp\n\ntheorem multiset_prod_comp (s : Multiset R[X]) (q : R[X]) :\n    s.prod.comp q = (s.map fun p : R[X] => p.comp q).prod :=\n  map_multiset_prod (compRingHom q) _\n#align polynomial.multiset_prod_comp Polynomial.multiset_prod_comp\n\ntheorem prod_comp {\u03b9 : Type _} (s : Finset \u03b9) (p : \u03b9 \u2192 R[X]) (q : R[X]) :\n    (\u220f j in s, p j).comp q = \u220f j in s, (p j).comp q :=\n  map_prod (compRingHom q) _ _\n#align polynomial.prod_comp Polynomial.prod_comp\n\ntheorem isRoot_prod {R} [CommRing R] [IsDomain R] {\u03b9 : Type _} (s : Finset \u03b9) (p : \u03b9 \u2192 R[X])\n    (x : R) : IsRoot (\u220f j in s, p j) x \u2194 \u2203 i \u2208 s, IsRoot (p i) x := by\n  simp only [IsRoot, eval_prod, Finset.prod_eq_zero_iff]\n#align polynomial.is_root_prod Polynomial.isRoot_prod\n\ntheorem eval_dvd : p \u2223 q \u2192 eval x p \u2223 eval x q :=\n  eval\u2082_dvd _ _\n#align polynomial.eval_dvd Polynomial.eval_dvd\n\ntheorem eval_eq_zero_of_dvd_of_eval_eq_zero : p \u2223 q \u2192 eval x p = 0 \u2192 eval x q = 0 :=\n  eval\u2082_eq_zero_of_dvd_of_eval\u2082_eq_zero _ _\n#align polynomial.eval_eq_zero_of_dvd_of_eval_eq_zero Polynomial.eval_eq_zero_of_dvd_of_eval_eq_zero\n\n@[simp]\ntheorem eval_geom_sum {R} [CommSemiring R] {n : \u2115} {x : R} :\n    eval x (\u2211 i in range n, X ^ i) = \u2211 i in range n, x ^ i := by simp [eval_finset_sum]\n#align polynomial.eval_geom_sum Polynomial.eval_geom_sum\n\nend\n\nend Eval\n\nsection Map\n\ntheorem support_map_subset [Semiring R] [Semiring S] (f : R \u2192+* S) (p : R[X]) :\n    (map f p).support \u2286 p.support := by\n  intro x\n  contrapose!\n  simp (config := { contextual := true })\n#align polynomial.support_map_subset Polynomial.support_map_subset\n\ntheorem support_map_of_injective [Semiring R] [Semiring S] (p : R[X]) {f : R \u2192+* S}\n    (hf : Function.Injective f) : (map f p).support = p.support := by\n  simp_rw [Finset.ext_iff, mem_support_iff, coeff_map, \u2190 map_zero f, hf.ne_iff, iff_self_iff,\n    forall_const]\n#align polynomial.support_map_of_injective Polynomial.support_map_of_injective\n\nvariable [CommSemiring R] [CommSemiring S] (f : R \u2192+* S)\n\nprotected theorem map_multiset_prod (m : Multiset R[X]) : m.prod.map f = (m.map <| map f).prod :=\n  Eq.symm <| Multiset.prod_hom _ (mapRingHom f).toMonoidHom\n#align polynomial.map_multiset_prod Polynomial.map_multiset_prod\n\nprotected theorem map_prod {\u03b9 : Type _} (g : \u03b9 \u2192 R[X]) (s : Finset \u03b9) :\n    (\u220f i in s, g i).map f = \u220f i in s, (g i).map f :=\n  (mapRingHom f).map_prod _ _\n#align polynomial.map_prod Polynomial.map_prod\n\ntheorem IsRoot.map {f : R \u2192+* S} {x : R} {p : R[X]} (h : IsRoot p x) : IsRoot (p.map f) (f x) := by\n  rw [IsRoot, eval_map, eval\u2082_hom, h.eq_zero, f.map_zero]\n#align polynomial.is_root.map Polynomial.IsRoot.map\n\ntheorem IsRoot.of_map {R} [CommRing R] {f : R \u2192+* S} {x : R} {p : R[X]} (h : IsRoot (p.map f) (f x))\n    (hf : Function.Injective f) : IsRoot p x := by\n  rwa [IsRoot, \u2190 (injective_iff_map_eq_zero' f).mp hf, \u2190 eval\u2082_hom, \u2190 eval_map]\n#align polynomial.is_root.of_map Polynomial.IsRoot.of_map\n\ntheorem isRoot_map_iff {R : Type _} [CommRing R] {f : R \u2192+* S} {x : R} {p : R[X]}\n    (hf : Function.Injective f) : IsRoot (p.map f) (f x) \u2194 IsRoot p x :=\n  \u27e8fun h => h.of_map hf, fun h => h.map\u27e9\n#align polynomial.is_root_map_iff Polynomial.isRoot_map_iff\n\nend Map\n\nend CommSemiring\n\nsection Ring\n\nvariable [Ring R] {p q r : R[X]}\n\ntheorem C_neg : C (-a) = -C a :=\n  RingHom.map_neg C a\n#align polynomial.C_neg Polynomial.C_neg\n\ntheorem C_sub : C (a - b) = C a - C b :=\n  RingHom.map_sub C a b\n#align polynomial.C_sub Polynomial.C_sub\n\n@[simp]\nprotected theorem map_sub {S} [Ring S] (f : R \u2192+* S) : (p - q).map f = p.map f - q.map f :=\n  (mapRingHom f).map_sub p q\n#align polynomial.map_sub Polynomial.map_sub\n\n@[simp]\nprotected theorem map_neg {S} [Ring S] (f : R \u2192+* S) : (-p).map f = -p.map f :=\n  (mapRingHom f).map_neg p\n#align polynomial.map_neg Polynomial.map_neg\n\n@[simp]\ntheorem map_int_cast {S} [Ring S] (f : R \u2192+* S) (n : \u2124) : map f \u2191n = \u2191n :=\n  map_intCast (mapRingHom f) n\n#align polynomial.map_int_cast Polynomial.map_int_cast\n\n@[simp]\ntheorem eval_int_cast {n : \u2124} {x : R} : (n : R[X]).eval x = n := by\n  simp only [\u2190 C_eq_int_cast, eval_C]\n#align polynomial.eval_int_cast Polynomial.eval_int_cast\n\n@[simp]\ntheorem eval\u2082_neg {S} [Ring S] (f : R \u2192+* S) {x : S} : (-p).eval\u2082 f x = -p.eval\u2082 f x := by\n  rw [eq_neg_iff_add_eq_zero, \u2190 eval\u2082_add, add_left_neg, eval\u2082_zero]\n#align polynomial.eval\u2082_neg Polynomial.eval\u2082_neg\n\n@[simp]\ntheorem eval\u2082_sub {S} [Ring S] (f : R \u2192+* S) {x : S} :\n    (p - q).eval\u2082 f x = p.eval\u2082 f x - q.eval\u2082 f x := by\n  rw [sub_eq_add_neg, eval\u2082_add, eval\u2082_neg, sub_eq_add_neg]\n#align polynomial.eval\u2082_sub Polynomial.eval\u2082_sub\n\n@[simp]\ntheorem eval_neg (p : R[X]) (x : R) : (-p).eval x = -p.eval x :=\n  eval\u2082_neg _\n#align polynomial.eval_neg Polynomial.eval_neg\n\n@[simp]\ntheorem eval_sub (p q : R[X]) (x : R) : (p - q).eval x = p.eval x - q.eval x :=\n  eval\u2082_sub _\n#align polynomial.eval_sub Polynomial.eval_sub\n\ntheorem root_X_sub_C : IsRoot (X - C a) b \u2194 a = b := by\n  rw [IsRoot.def, eval_sub, eval_X, eval_C, sub_eq_zero, eq_comm]\n#align polynomial.root_X_sub_C Polynomial.root_X_sub_C\n\n@[simp]\ntheorem neg_comp : (-p).comp q = -p.comp q :=\n  eval\u2082_neg _\n#align polynomial.neg_comp Polynomial.neg_comp\n\n@[simp]\ntheorem sub_comp : (p - q).comp r = p.comp r - q.comp r :=\n  eval\u2082_sub _\n#align polynomial.sub_comp Polynomial.sub_comp\n\n@[simp]\ntheorem cast_int_comp (i : \u2124) : comp (i : R[X]) p = i := by cases i <;> simp\n#align polynomial.cast_int_comp Polynomial.cast_int_comp\n\nend Ring\n\nend Polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/Eval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7061844292268933}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Patrick Stevens\n-/\nimport data.nat.choose.basic\nimport data.nat.prime\n\n/-!\n# Divisibility properties of binomial coefficients\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nnamespace nat\n\nopen_locale nat\n\nnamespace prime\n\nlemma dvd_choose_add {p a b : \u2115} (hp : prime p) (hap : a < p) (hbp : b < p) (h : p \u2264 a + b) :\n  p \u2223 choose (a + b) a :=\nbegin\n  have h\u2081 : p \u2223 (a + b)!, from hp.dvd_factorial.2 h,\n  rw [\u2190 add_choose_mul_factorial_mul_factorial, \u2190 choose_symm_add, hp.dvd_mul, hp.dvd_mul,\n    hp.dvd_factorial, hp.dvd_factorial] at h\u2081,\n  exact (h\u2081.resolve_right hbp.not_le).resolve_right hap.not_le\nend\n\nlemma dvd_choose {p a b : \u2115} (hp : prime p) (ha : a < p) (hab : b - a < p) (h : p \u2264 b) :\n  p \u2223 choose b a :=\nhave a + (b - a) = b := nat.add_sub_of_le (ha.le.trans h),\nthis \u25b8 hp.dvd_choose_add ha hab (this.symm \u25b8 h)\n\nlemma dvd_choose_self {p k : \u2115} (hp : prime p) (hk : k \u2260 0) (hkp : k < p) : p \u2223 choose p k :=\nhp.dvd_choose hkp (nat.sub_lt ((zero_le _).trans_lt hkp) hk.bot_lt) le_rfl\n\nend prime\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/choose/dvd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7061844248599197}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n-/\n\nimport data.rat.order\nimport data.int.sqrt\n/-!\n# Square root on rational numbers\n\nThis file defines the square root function on rational numbers `rat.sqrt`\nand proves several theorems about it.\n\n-/\nnamespace rat\n\n/-- Square root function on rational numbers, defined by taking the (integer) square root of the\nnumerator and the square root (on natural numbers) of the denominator. -/\n@[pp_nodot] def sqrt (q : \u211a) : \u211a := rat.mk (int.sqrt q.num) (nat.sqrt q.denom)\n\ntheorem sqrt_eq (q : \u211a) : rat.sqrt (q*q) = |q| :=\nby rw [sqrt, mul_self_num, mul_self_denom, int.sqrt_eq, nat.sqrt_eq, abs_def]\n\ntheorem exists_mul_self (x : \u211a) : (\u2203 q, q * q = x) \u2194 rat.sqrt x * rat.sqrt x = x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, by rw [\u2190 hn, sqrt_eq, abs_mul_abs_self],\n\u03bb h, \u27e8rat.sqrt x, h\u27e9\u27e9\n\ntheorem sqrt_nonneg (q : \u211a) : 0 \u2264 rat.sqrt q :=\nnonneg_iff_zero_le.1 $ (mk_nonneg _ $ int.coe_nat_pos.2 $\nnat.pos_of_ne_zero $ \u03bb H, pos_iff_ne_zero.1 q.pos $ nat.sqrt_eq_zero.1 H).2\n$ int.coe_nat_nonneg _\n\nend rat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/rat/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7061844227245392}}
{"text": "import tactic\nimport data.real.basic\nimport data.int.gcd\nimport data.padics\n\n------------------------------------------------------------------------\n-- \u00a7 Primeros ejercicios                                              --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Calcular el tipo del 3.\n-- ----------------------------------------------------------------------\n\n#check 3\n\n-- Comentario: Al colocar el cursor sobre check se obtiene\n--    3 : \u2115\n-- que indica que 3 es un n\u00famero natural.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Calcular el tipo del (3 : \u2124).\n-- ----------------------------------------------------------------------\n\n#check (3 : \u2124)\n\n-- Comentario: Al colocar el cursor sobre check se obtiene\n--    3 : \u2124\n-- que indica que 3 es un n\u00famero entero.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el n\u00famero entero 3 es igual que el n\u00famero\n-- natural 3.\n-- ----------------------------------------------------------------------\n\nexample : (3 : \u2124) = (3 : \u2115) :=\nby norm_num\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el n\u00famero real 3 es menor que 5.\n-- ----------------------------------------------------------------------\n\nexample : (3 : \u211d) < 5 :=\nby norm_num\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que 3 es menor que 5.\n-- ----------------------------------------------------------------------\n\nexample : 3 < 5 :=\nby norm_num\n\n-- ----------------------------------------------------------------------\n-- Ejercicio. Demostrar que 3 m\u00e1s 20 es menor que 5 por 10.\n-- ----------------------------------------------------------------------\n\nexample : 3 + 20 < 5 * 10 :=\nby norm_num\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que 11 es primo.\n-- ----------------------------------------------------------------------\n\nexample : nat.prime 11 :=\nby norm_num\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Calcular el valor de las siguientes expresiones\n--    2 - 1\n--    2 - 2\n--    2 - 3\n--    (2 : \u2124) - 3\n--    6 / 3\n--    6 / 4\n--    (6 : \u211a) / 4\n-- ----------------------------------------------------------------------\n\n#eval 2 - 1\n#eval 2 - 2\n#eval 2 - 3\n#eval (2 : \u2124) - 3\n#eval 6 / 3\n#eval 6 / 4\n#eval (6 : \u211a) / 4\n\n-- Comentario: Al colocar el cursor sobre eval se obtiene\n--    2 - 1       = 1\n--    2 - 2       = 0\n--    2 - 3       = 0\n--    (2 : \u2124) - 3 = -1\n--    6 / 3       = 2\n--    6 / 4       = 1\n--    (6 : \u211a) / 4 = 3/2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si a, b y c son n\u00famero naturales y, para\n-- todo entero b se tiene que (b + a < c + a), entonces (b < c).\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (a b c : \u2115)\n  (h : (b : \u2124) + a < c + a)\n  : b < c :=\nbegin\n  rw \u2190 (sub_lt_sub_iff_right (a : \u2124)) at h,\n  rw add_sub_cancel at h,\n  rw add_sub_cancel at h,\n  norm_cast at h,\n  exact h,\nend\n\n-- Prueba\n-- ======\n\n/-\na b c : \u2115,\nh : \u2191b + \u2191a < \u2191c + \u2191a\n\u22a2 b < c\n  >> rw \u2190 (sub_lt_sub_iff_right (a : \u2124)) at h,\nh : \u2191b + \u2191a - \u2191a < \u2191c + \u2191a - \u2191a\n\u22a2 b < c\n  >> rw add_sub_cancel at h,\nh : \u2191b < \u2191c + \u2191a - \u2191a\n\u22a2 b < c\n  >> rw add_sub_cancel at h,\nh : \u2191b < \u2191c\n\u22a2 b < c\n  >> norm_cast at h,\nh : b < c\n\u22a2 b < c\n  >> exact h,\nno goals\n-/\n\n-- Comentarios:\n-- 1. Se han usado los lemas\n--    + sub_lt_sub_iff_right : a - c < b - c \u2194 a < b\n--    + add_sub_cancel : a + b - b = a\n-- 2. La t\u00e1ctica (norma_cast at h) elimina las conversiones de la\n--    hip\u00f3tesis h.\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (a b c : \u2115)\n  (h : (b : \u2124) + a < c + a)\n  : b < c :=\nbegin\n  rw \u2190 (sub_lt_sub_iff_right (a : \u2124)) at h,\n  rw add_sub_cancel at h,\n  rw add_sub_cancel at h,\n  exact_mod_cast h,\nend\n\n-- Prueba\n-- ======\n\n/-\na b c : \u2115,\nh : \u2191b + \u2191a < \u2191c + \u2191a\n\u22a2 b < c\n  >> rw \u2190 (sub_lt_sub_iff_right (a : \u2124)) at h,\nh : \u2191b + \u2191a - \u2191a < \u2191c + \u2191a - \u2191a\n\u22a2 b < c\n  >> rw add_sub_cancel at h,\nh : \u2191b < \u2191c + \u2191a - \u2191a\n\u22a2 b < c\n  >> rw add_sub_cancel at h,\nh : \u2191b < \u2191c\n\u22a2 b < c\n  >> exact_mod_cast h,\nno goals\n-/\n\n-- Comentarios:\n-- 1. La t\u00e1ctica (exact_mod_cast h) normaliza el objetivo y lo resuelve\n--    con exact.\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (a b c : \u2115)\n  (h : (b : \u2124) + a < c + a)\n  : b < c :=\nbegin\n  rw \u2190 (sub_lt_sub_iff_right (a : \u2124)) at h,\n  rw add_sub_cancel at h,\n  rw add_sub_cancel at h,\n  assumption_mod_cast,\nend\n\n-- Prueba\n-- ======\n\n/-\na b c : \u2115,\nh : \u2191b + \u2191a < \u2191c + \u2191a\n\u22a2 b < c\n  >> rw \u2190 (sub_lt_sub_iff_right (a : \u2124)) at h,\nh : \u2191b + \u2191a - \u2191a < \u2191c + \u2191a - \u2191a\n\u22a2 b < c\n  >> rw add_sub_cancel at h,\nh : \u2191b < \u2191c + \u2191a - \u2191a\n\u22a2 b < c\n  >> rw add_sub_cancel at h,\nh : \u2191b < \u2191c\n\u22a2 b < c\n  >> assumption_mod_cast,\nno goals\n-/\n\n-- Comentarios:\n-- 1. La t\u00e1ctica assumption_cast unifica el objetivo con una de las\n--    hip\u00f3tesis eliminando la conversi\u00f3n de tipos.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si n es un n\u00famero primo, entonces\n--    1 / n < 1\n-- ----------------------------------------------------------------------\n\nvariable n : \u2115\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (hn : nat.prime n)\n  : 1 / (n : \u211d) < 1 :=\nbegin\n  rw one_div_lt,\n  { norm_num,\n    norm_cast,\n    exact nat.prime.one_lt hn },\n  { norm_cast,\n    exact nat.prime.pos hn },\n  { norm_num },\nend\n\n-- Prueba\n-- ======\n\n/-\nn : \u2115,\nhn : nat.prime n\n\u22a2 1 / \u2191n < 1\n  >> rw one_div_lt,\n| | 3 goals\n| | n : \u2115,\n| | hn : nat.prime n\n| | \u22a2 1 / 1 < \u2191n\n| |   >> { norm_num,\n| | \u22a2 1 < \u2191n\n| |   >>   norm_cast,\n| | \u22a2 1 < n\n| |   >>   exact nat.prime.one_lt hn },\n| 2 goals\n| n : \u2115,\n| hn : nat.prime n\n| \u22a2 0 < \u2191n\n|   >> { norm_cast,\n| \u22a2 0 < n\n|   >>   exact nat.prime.pos hn },\nn : \u2115,\nhn : nat.prime n\n\u22a2 0 < 1\n  >> { norm_num },\nno goals\n-/\n\n-- Comentarios:\n-- 1. Se han usado los lemas\n--    + one_div_lt : 0 < a \u2192 0 < b \u2192 (1 / a < b \u2194 1 / b < a)\n--    + nat.prime.one_lt : nat.prime n \u2192 1 < n\n--    + nat.prime.pos : nat.prime n \u2192 0 < n\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (hn : nat.prime n)\n  : 1 / (n : \u211d) < 1 :=\nbegin\n  rw one_div_lt,\n  { norm_num,\n    apply_mod_cast nat.prime.one_lt,\n    assumption },\n  { norm_cast,\n    exact nat.prime.pos hn },\n  { norm_num },\nend\n\n-- Comentario: La t\u00e1ctica (apply_mod_cast h) aplica h con conversiones\n-- de tipos.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que en los cuerpos totalmente ordenados,\n--    123 + 45 < 67890/3\n-- ----------------------------------------------------------------------\n\nexample {\u03b1 : Type} [linear_ordered_field \u03b1] : 123 + 45 < 67890/3 :=\nby norm_num\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que 7/3 no es mayor que 2.\n-- ----------------------------------------------------------------------\n\nexample : \u00ac 7/3 > 2 :=\nby norm_num\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si el n\u00famero real x es menor que 50 * 50,\n-- entonces tambi\u00e9n es menor que 25 * 100.\n-- ----------------------------------------------------------------------\n\nexample\n  (x : \u211d)\n  (hx : x < 50*50)\n  : x < 25*100 :=\nbegin\n  norm_num at hx \u22a2,\n  assumption,\nend\n\n-- Prueba\n-- ======\n\n/-\nx : \u211d,\nhx : x < 50 * 50\n\u22a2 x < 25 * 100\n  >> norm_num at hx \u22a2,\nhx : x < 2500\n\u22a2 x < 2500\n  >> assumption,\nno goals\n-/\n\n-- Comentario: La t\u00e1ctica (norm_num at h \u22a2) normaliza las expresiones\n-- num\u00e9ricas en la hip\u00f3tesis h y en la conclusi\u00f3n.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sea x un n\u00famero entero. Demostrar que si x (como n\u00famero\n-- real) es menor que 25*100, entonces x es menor que 25*100.\n-- ----------------------------------------------------------------------\n\nexample\n  (x : \u2124)\n  (hx : (x : \u211d) < 25*100)\n  : x < 25*100 :=\nbegin\n  assumption_mod_cast,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sea x un n\u00famero entero. Demostrar que si x (como n\u00famero\n-- real) es menor que 2500, entonces x es menor que 25*100.\n-- ----------------------------------------------------------------------\n\nexample\n  (x : \u2124)\n  (hx : (x : \u211d) < 2500)\n  : x < 25*100 :=\nbegin\n  norm_num,\n  assumption_mod_cast,\nend\n\n-- Prueba\n-- ======\n\n/-\nx : \u2124,\nhx : \u2191x < 2500\n\u22a2 x < 25 * 100\n  >> norm_num,\nhx : \u2191x < 2500\n\u22a2 x < 2500\n  >> assumption_mod_cast,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sean p, q y r n\u00fameros naturales. Demostrar que si\n--    r < p - q\n--    q \u2264 p\n-- entonces r (como n\u00famero real) es menor que p - q.\n-- ----------------------------------------------------------------------\n\nexample\n  (p q r : \u2115)\n  (h : r < p - q)\n  (hpq : q \u2264 p)\n  : (r : \u211d) < p - q :=\nbegin\n  exact_mod_cast h,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sean p, q y r n\u00fameros naturales tales que (r < p + 2 - p).\n-- Demostrar que r (como entero) es menor que 5.\n-- ----------------------------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (p q r : \u2115)\n  (hr : r < p + 2 - p)\n  : (r : \u2124) < 5 :=\nbegin\n  have : p \u2264 p + 2, by linarith,\n  zify [this] at hr,\n  linarith,\nend\n\n-- Prueba\n-- ======\n\n/-\np q r : \u2115,\nhr : r < p + 2 - p\n\u22a2 \u2191r < 5\n  >> have : p \u2264 p + 2, by linarith,\nthis : p \u2264 p + 2\n\u22a2 \u2191r < 5\n  >> zify [this] at hr,\nhr : \u2191r < \u2191p + 2 - \u2191p\n\u22a2 \u2191r < 5\n  >> linarith,\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (p q r : \u2115)\n  (hr : r < p + 2 - p)\n  : (r : \u2124) < 5 :=\nbegin\n  norm_num at hr,\n  norm_cast,\n  linarith,\nend\n\n-- Prueba\n-- ======\n\n/-\np q r : \u2115,\nhr : r < p + 2 - p\n\u22a2 \u2191r < 5\n  >> norm_num at hr,\nhr : r < 2\n\u22a2 \u2191r < 5\n  >> norm_cast,\nhr : r < 2\n\u22a2 r < 5\n  >> linarith,\nno goals\n-/\n\n------------------------------------------------------------------------\n-- \u00a7 N\u00fameros p-\u00e1dicos                                                 --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir la teor\u00eda padic_val_rat\n-- ----------------------------------------------------------------------\n\nopen padic_val_rat\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Calcular el tipo de los siguentes lemas\n--    fpow_le_of_le\n--    fpow_nonneg_of_nonneg\n--    padic_val_rat_of_int\n-- ----------------------------------------------------------------------\n\n#check fpow_le_of_le\n#check fpow_nonneg_of_nonneg\n#check padic_val_rat_of_int\n\n-- Comentario: Al colocar el cursor sobre check se obtiene\n-- + fpow_le_of_le : 1 \u2264 x \u2192 \u2200 {a b : \u2124}, a \u2264 b \u2192 x ^ a \u2264 x ^ b\n-- + fpow_nonneg_of_nonneg : 0 \u2264 x \u2192 \u2200 (z : \u2124), 0 \u2264 x ^ z\n-- + padic_val_rat_of_int :\n--    \u2200 (z : \u2124) (hp : x \u2260 1) (hz : z \u2260 0),\n--    padic_val_rat x \u2191z = \u2191((multiplicity \u2191x z).get _)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sean p y n n\u00fameros naturales y z un n\u00famero entero.\n-- Demostrar que si p es un n\u00famero primo y p^n divide a z, entonces\n--    padic_norm p z \u2264 \u2191p ^ (-n : \u2124)\n-- ----------------------------------------------------------------------\n\nexample\n  {p n : \u2115}\n  (hp : p.prime)\n  {z : \u2124}\n  (hd : \u2191(p^n) \u2223 z)\n  : padic_norm p z \u2264 \u2191p ^ (-n : \u2124) :=\nbegin\n  have aux_lemma : \u2200 inst, (n : \u2124) \u2264 (multiplicity \u2191p z).get inst,\n  { intro,\n    norm_cast,\n    rw [\u2190 enat.coe_le_coe, enat.coe_get],\n    apply multiplicity.le_multiplicity_of_pow_dvd,\n    assumption_mod_cast },\n  unfold padic_norm,\n  split_ifs with hz hz,\n  { apply fpow_nonneg_of_nonneg,\n    exact_mod_cast le_of_lt hp.pos },\n  { apply fpow_le_of_le,\n    exact_mod_cast le_of_lt hp.one_lt,\n    apply neg_le_neg,\n    rw padic_val_rat_of_int _ hp.ne_one _,\n    { apply aux_lemma },\n    { assumption_mod_cast } }\nend\n\n------------------------------------------------------------------------\n-- \u00a7 Coprimos                                                         --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si p y q son coprimos, entonces existen\n-- enteros u y v tales que\n--    u*p+v*q = 1\n-- ----------------------------------------------------------------------\n\nexample\n  (p q : \u2115)\n  (h : nat.coprime p q)\n  : \u2203 u v : \u2124, u*p+v*q = 1 :=\nbegin\n  have := nat.gcd_eq_gcd_ab,\n  specialize this p q,\n  unfold nat.coprime at h,\n  rw h at this,\n  norm_cast at this,\n  use [p.gcd_a q, p.gcd_b q],\n  rw this,\n  ring,\nend\n\n-- Prueba\n-- ======\n\n/-\np q : \u2115,\nh : p.coprime q\n\u22a2 \u2203 (u v : \u2124), u * \u2191p + v * \u2191q = 1\n  >> have := nat.gcd_eq_gcd_ab,\nthis : \u2200 (x y : \u2115), \u2191(x.gcd y) = \u2191x * x.gcd_a y + \u2191y * x.gcd_b y\n\u22a2 \u2203 (u v : \u2124), u * \u2191p + v * \u2191q = 1\n  >> specialize this p q,\nthis : \u2191(p.gcd q) = \u2191p * p.gcd_a q + \u2191q * p.gcd_b q\n\u22a2 \u2203 (u v : \u2124), u * \u2191p + v * \u2191q = 1\n  >> unfold nat.coprime at h,\nh : p.gcd q = 1\n\u22a2 \u2203 (u v : \u2124), u * \u2191p + v * \u2191q = 1\n  >> rw h at this,\nthis : \u21911 = \u2191p * p.gcd_a q + \u2191q * p.gcd_b q\n\u22a2 \u2203 (u v : \u2124), u * \u2191p + v * \u2191q = 1\n  >> norm_cast at this,\nthis : 1 = \u2191p * p.gcd_a q + \u2191q * p.gcd_b q\n\u22a2 \u2203 (u v : \u2124), u * \u2191p + v * \u2191q = 1\n  >> use [p.gcd_a q, p.gcd_b q],\n\u22a2 p.gcd_a q * \u2191p + p.gcd_b q * \u2191q = 1\n  >> rw this,\n\u22a2 p.gcd_a q * \u2191p + p.gcd_b q * \u2191q = \u2191p * p.gcd_a q + \u2191q * p.gcd_b q\n  >> ring,\nno goals\n-/\n\n------------------------------------------------------------------------\n-- \u00a7 L\u00edmite de una sucesi\u00f3n                                           --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Representar con |x| el valor absoluto de x.\n-- ----------------------------------------------------------------------\n\nnotation `|`x`|` := abs x\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la funci\u00f3n\n--     seq_limit : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop\n-- tal que (seq_limit u l) afirma que l es el l\u00edmite de la sucesi\u00f3n u.\n-- ----------------------------------------------------------------------\n\ndef seq_limit : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n\u03bb u l, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el l\u00edmite de la sucesi\u00f3n (n+1)/n es 1.\n-- ----------------------------------------------------------------------\n\nexample : seq_limit (\u03bb n : \u2115, (n+1)/n) 1 :=\nbegin\n  intros \u03b5 \u03b5_pos,\n  dsimp,\n  use nat_ceil (1/\u03b5),\n  intros n hn,\n  have n_pos : 0 < n,\n    { calc 0 < nat_ceil (1/\u03b5) : _\n         ... \u2264 n              : _,\n      { rw lt_nat_ceil,\n        simp,\n        assumption },\n      { assumption } },\n  rw [abs_of_nonneg,\n      sub_le_iff_le_add,\n      div_le_iff,\n      add_mul,\n      one_mul,\n      add_comm _ (n : \u211d),\n      add_le_add_iff_left],\n  { calc 1 = \u03b5 * (1/\u03b5) : _\n       ... \u2264 \u03b5 * nat_ceil (1/\u03b5) : _\n       ... \u2264 \u03b5 * n : _,\n    { symmetry,\n      apply mul_one_div_cancel,\n      linarith },\n    { rw mul_le_mul_left \u03b5_pos,\n      apply le_nat_ceil },\n    { rw mul_le_mul_left \u03b5_pos,\n      exact_mod_cast hn } },\n  { assumption_mod_cast },\n  { field_simp,\n    apply one_le_div_of_le;\n    norm_cast;\n    linarith }\nend\n\n------------------------------------------------------------------------\n-- \u00a7 Referencia                                                       --\n------------------------------------------------------------------------\n\n-- Basado en la teor\u00eda numbers.lean de Robert Y. Lewis que se\n-- encuentra en https://bit.ly/39teUbt y se comenta en el v\u00eddeo\n-- \"Numbers in Lean\" que se encuentra en https://youtu.be/iEs2U_kzYy4\n", "meta": {"author": "jaalonso", "repo": "Lean_para_matematicos", "sha": "924c77b7f010604b84f82d2f79967ad8b9cddc6e", "save_path": "github-repos/lean/jaalonso-Lean_para_matematicos", "path": "github-repos/lean/jaalonso-Lean_para_matematicos/Lean_para_matematicos-924c77b7f010604b84f82d2f79967ad8b9cddc6e/src/Numeros/Numeros.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7061844138462726}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.tactic.apply_fun\nimport Mathlib.ring_theory.matrix_algebra\nimport Mathlib.ring_theory.polynomial_algebra\nimport Mathlib.linear_algebra.nonsingular_inverse\nimport Mathlib.tactic.squeeze\nimport Mathlib.PostPort\n\nuniverses u w \n\nnamespace Mathlib\n\n/-!\n# Characteristic polynomials and the Cayley-Hamilton theorem\n\nWe define characteristic polynomials of matrices and\nprove the Cayley\u2013Hamilton theorem over arbitrary commutative rings.\n\n## Main definitions\n\n* `char_poly` is the characteristic polynomial of a matrix.\n\n## Implementation details\n\nWe follow a nice proof from http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\n-/\n\n/--\nThe \"characteristic matrix\" of `M : matrix n n R` is the matrix of polynomials $t I - M$.\nThe determinant of this matrix is the characteristic polynomial.\n-/\ndef char_matrix {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n] [fintype n]\n    (M : matrix n n R) : matrix n n (polynomial R) :=\n  coe_fn (matrix.scalar n) polynomial.X - coe_fn (ring_hom.map_matrix polynomial.C) M\n\n@[simp] theorem char_matrix_apply_eq {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n]\n    [fintype n] (M : matrix n n R) (i : n) :\n    char_matrix M i i = polynomial.X - coe_fn polynomial.C (M i i) :=\n  sorry\n\n@[simp] theorem char_matrix_apply_ne {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n]\n    [fintype n] (M : matrix n n R) (i : n) (j : n) (h : i \u2260 j) :\n    char_matrix M i j = -coe_fn polynomial.C (M i j) :=\n  sorry\n\ntheorem mat_poly_equiv_char_matrix {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n]\n    [fintype n] (M : matrix n n R) :\n    coe_fn mat_poly_equiv (char_matrix M) = polynomial.X - coe_fn polynomial.C M :=\n  sorry\n\n/--\nThe characteristic polynomial of a matrix `M` is given by $\\det (t I - M)$.\n-/\ndef char_poly {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n] [fintype n]\n    (M : matrix n n R) : polynomial R :=\n  matrix.det (char_matrix M)\n\n/--\nThe Cayley-Hamilton theorem, that the characteristic polynomial of a matrix,\napplied to the matrix itself, is zero.\n\nThis holds over any commutative ring.\n-/\n-- This proof follows http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\n\ntheorem aeval_self_char_poly {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n] [fintype n]\n    (M : matrix n n R) : coe_fn (polynomial.aeval M) (char_poly M) = 0 :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/linear_algebra/char_poly/basic_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7061844116627856}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport algebra.polynomial.big_operators\nimport data.polynomial.degree.lemmas\nimport data.polynomial.eval\nimport data.polynomial.monic\nimport linear_algebra.matrix.determinant\n\n/-!\n# Matrices of polynomials and polynomials of matrices\n\nIn this file, we prove results about matrices over a polynomial ring.\nIn particular, we give results about the polynomial given by\n`det (t * I + A)`.\n\n## References\n\n  * \"The trace Cayley-Hamilton theorem\" by Darij Grinberg, Section 5.3\n\n## Tags\n\nmatrix determinant, polynomial\n-/\n\nopen_locale matrix big_operators\n\nvariables {n \u03b1 : Type*} [decidable_eq n] [fintype n] [comm_ring \u03b1]\n\nopen polynomial matrix equiv.perm\n\nnamespace polynomial\n\nlemma nat_degree_det_X_add_C_le (A B : matrix n n \u03b1) :\n  nat_degree (det ((X : polynomial \u03b1) \u2022 A.map C + B.map C)) \u2264 fintype.card n :=\nbegin\n  rw det_apply,\n  refine (nat_degree_sum_le _ _).trans _,\n  refine (multiset.max_nat_le_of_forall_le _ _ _),\n  simp only [forall_apply_eq_imp_iff', true_and, function.comp_app, multiset.map_map,\n               multiset.mem_map, exists_imp_distrib, finset.mem_univ_val],\n  intro g,\n  calc  nat_degree (sign g \u2022 \u220f (i : n), (X \u2022 A.map C + B.map C) (g i) i)\n      \u2264 nat_degree (\u220f (i : n), (X \u2022 A.map C + B.map C) (g i) i) : by\n    { cases int.units_eq_one_or (sign g) with sg sg,\n        { rw [sg, one_smul] },\n        { rw [sg, units.neg_smul, one_smul, nat_degree_neg] } }\n  ... \u2264 \u2211 (i : n), nat_degree (((X : polynomial \u03b1) \u2022 A.map C + B.map C) (g i) i) :\n    nat_degree_prod_le (finset.univ : finset n) (\u03bb (i : n), (X \u2022 A.map C + B.map C) (g i) i)\n  ... \u2264 finset.univ.card \u2022 1 : finset.sum_le_of_forall_le _ _ 1 (\u03bb (i : n) _, _)\n  ... \u2264 fintype.card n : by simpa,\n  calc  nat_degree (((X : polynomial \u03b1) \u2022 A.map C + B.map C) (g i) i)\n      = nat_degree ((X : polynomial \u03b1) * C (A (g i) i) + C (B (g i) i)) : by simp\n  ... \u2264 max (nat_degree ((X : polynomial \u03b1) * C (A (g i) i))) (nat_degree (C (B (g i) i))) :\n    nat_degree_add_le _ _\n  ... = nat_degree ((X : polynomial \u03b1) * C (A (g i) i)) :\n    max_eq_left ((nat_degree_C _).le.trans (zero_le _))\n  ... \u2264 nat_degree (X : polynomial \u03b1) : nat_degree_mul_C_le _ _\n  ... \u2264 1 : nat_degree_X_le\nend\n\nlemma coeff_det_X_add_C_zero (A B : matrix n n \u03b1) :\n  coeff (det ((X : polynomial \u03b1) \u2022 A.map C + B.map C)) 0 = det B :=\nbegin\n  rw [det_apply, finset_sum_coeff, det_apply],\n  refine finset.sum_congr rfl _,\n  intros g hg,\n  convert coeff_smul (sign g) _ 0,\n  rw coeff_zero_prod,\n  refine finset.prod_congr rfl _,\n  simp\nend\n\nlemma coeff_det_X_add_C_card (A B : matrix n n \u03b1) :\n  coeff (det ((X : polynomial \u03b1) \u2022 A.map C + B.map C)) (fintype.card n) = det A :=\nbegin\n  rw [det_apply, det_apply, finset_sum_coeff],\n  refine finset.sum_congr rfl _,\n  simp only [algebra.id.smul_eq_mul, finset.mem_univ, ring_hom.map_matrix_apply, forall_true_left,\n             map_apply, pi.smul_apply],\n  intros g,\n  convert coeff_smul (sign g) _ _,\n  rw \u2190mul_one (fintype.card n),\n  convert (coeff_prod_of_nat_degree_le _ _ _ _).symm,\n  { ext,\n    simp [coeff_C] },\n  { intros p hp,\n    refine (nat_degree_add_le _ _).trans _,\n    simpa using (nat_degree_mul_C_le _ _).trans nat_degree_X_le }\nend\n\nlemma leading_coeff_det_X_one_add_C (A : matrix n n \u03b1) :\n  leading_coeff (det ((X : polynomial \u03b1) \u2022 (1 : matrix n n (polynomial \u03b1)) + A.map C)) = 1 :=\nbegin\n  casesI (subsingleton_or_nontrivial \u03b1),\n  { simp },\n  rw [\u2190@det_one n, \u2190coeff_det_X_add_C_card _ A, leading_coeff],\n  simp only [matrix.map_one, C_eq_zero, ring_hom.map_one],\n  cases (nat_degree_det_X_add_C_le 1 A).eq_or_lt with h h,\n  { simp only [ring_hom.map_one, matrix.map_one, C_eq_zero] at h,\n    rw h },\n  { -- contradiction. we have a hypothesis that the degree is less than |n|\n    -- but we know that coeff _ n = 1\n    have H := coeff_eq_zero_of_nat_degree_lt h,\n    rw coeff_det_X_add_C_card at H,\n    simpa using H }\nend\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/matrix/polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.706184405016112}}
{"text": "import tactic\n\nvariables (x y : \u2115)\n\nopen nat\n\ntheorem Q1a : x + y = y + x :=\nbegin\n  induction y with d hd,\n  { rw [add_zero, zero_add]},\n  { rw [add_succ, succ_add, hd]}\nend\n\ntheorem Q1b : x + y = x \u2192 y = 0 :=\nbegin\n  intro h,\n  induction x with d hd,\n  { convert h, rw zero_add},\n  { apply hd,\n    rw succ_add at h,\n    rw \u2190 succ_inj',\n    assumption,  \n  }\nend\n\ntheorem Q1c : x + y = 0 \u2192 x = 0 \u2227 y = 0 :=\nbegin\n  intro h,\n  induction y with d hd,\n  { split,\n      exact h,\n    refl,\n  },\n  { rw add_succ at h,\n    exfalso,\n    apply succ_ne_zero (x + d),\n    assumption },\nend\n\ntheorem Q1d : x * y = y * x :=\nbegin\n  induction y with d hd,\n  { rw [mul_zero, zero_mul]},\n  { rw [mul_succ, succ_mul, hd]},\nend\n\ntheorem Q2a : 1 * x = x \u2227 x = x * 1 :=\nbegin\n  split,\n  { induction x with d hd,\n      refl,\n    rw [mul_succ,hd],\n  },\n  rw [mul_succ, mul_zero, zero_add],\nend\n\nvariable z : \u2115\n\ntheorem Q2b : (x + y) * z = x * z + y * z :=\nbegin\n  induction z with d hd,\n    refl,\n  rw [mul_succ, hd, mul_succ, mul_succ],\n  ac_refl,\nend\n\ntheorem Q2c : (x * y) * z = x * (y * z) :=\nbegin\n  induction z with d hd,\n  { refl },\n  { rw [mul_succ, mul_succ, hd, mul_add] }\nend\n\n-- Q3 def\ndef is_pred (x y : \u2115) := x.succ = y\n\ntheorem Q3a : \u00ac \u2203 x : \u2115, is_pred x 0 :=\nbegin\n  intro h,\n  cases h with x hx,\n  unfold is_pred at hx,\n  apply succ_ne_zero x,\n  assumption,\nend\n\ntheorem Q3b : y \u2260 0 \u2192 \u2203! x, is_pred x y :=\nbegin\n  intro hy,\n  cases y,\n    exfalso,\n    apply hy,\n    refl,\n  clear hy,\n  use y,\n  split,\n  { dsimp only,\n    unfold is_pred,\n  },\n  intro z,\n  dsimp only [is_pred],\n  exact succ_inj'.1,\nend\n\ndef aux : 0 < y \u2192 \u2203 x, is_pred x y :=\nbegin\n  intro hy,\n  cases Q3b _ (ne_of_lt hy).symm with x hx,\n  use x,\n  exact hx.1,\nend\n\n-- definition of pred' is \"choose a random d such that succ(d) = n\"\nnoncomputable def pred' : \u2115+ \u2192 \u2115 := \u03bb nhn, classical.some (aux nhn nhn.2)\n\ntheorem pred'_def : \u2200 np : \u2115+, is_pred (pred' np) np :=\n\u03bb nhn, classical.some_spec (aux nhn nhn.2)\n\ndef succ' : \u2115 \u2192 \u2115+ :=\n\u03bb n, \u27e8n.succ, zero_lt_succ n\u27e9\n\nnoncomputable definition Q3c : \u2115+ \u2243 \u2115 :=\n{ to_fun := pred',\n  inv_fun := succ',\n  left_inv := begin\n    rintro np,\n    have h := pred'_def,\n    unfold succ',\n    ext, dsimp,\n    unfold is_pred at h,\n    rw h,\n  end,\n  right_inv := begin\n    intro n,\n    unfold succ',\n    have h := pred'_def,\n    unfold is_pred at h,\n    rw \u2190 succ_inj',\n    rw h,\n    clear h,\n    refl,\n  end\n   }\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/problem_sheets/Part_II/sheet1_q3_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7061603664631539}}
{"text": "/-\nCopyright (c) 2022 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport algebra.order.floor\nimport data.nat.log\n\n/-!\n# Integer logarithms in a field with respect to a natural base\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines two `\u2124`-valued analogs of the logarithm of `r : R` with base `b : \u2115`:\n\n* `int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `\u2191b^k \u2264 r`.\n* `int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r \u2264 \u2191b^k`.\n\nNote that `int.log` gives the position of the left-most non-zero digit:\n```lean\n#eval (int.log 10 (0.09 : \u211a), int.log 10 (0.10 : \u211a), int.log 10 (0.11 : \u211a))\n--    (-2,                    -1,                    -1)\n#eval (int.log 10 (9 : \u211a),    int.log 10 (10 : \u211a),   int.log 10 (11 : \u211a))\n--    (0,                     1,                     1)\n```\nwhich means it can be used for computing digit expansions\n```lean\nimport data.fin.vec_notation\n\ndef digits (b : \u2115) (q : \u211a) (n : \u2115) : \u2115 :=\n\u230aq*b^(\u2191n - int.log b q)\u230b\u208a % b\n\n#eval digits 10 (1/7) \u2218 (coe : fin 8 \u2192 \u2115)\n-- ![1, 4, 2, 8, 5, 7, 1, 4]\n```\n\n## Main results\n\n* For `int.log`:\n  * `int.zpow_log_le_self`, `int.lt_zpow_succ_log_self`: the bounds formed by `int.log`,\n    `(b : R) ^ log b r \u2264 r < (b : R) ^ (log b r + 1)`.\n  * `int.zpow_log_gi`: the galois coinsertion between `zpow` and `int.log`.\n* For `int.clog`:\n  * `int.zpow_pred_clog_lt_self`, `int.self_le_zpow_clog`: the bounds formed by `int.clog`,\n    `(b : R) ^ (clog b r - 1) < r \u2264 (b : R) ^ clog b r`.\n  * `int.clog_zpow_gi`:  the galois insertion between `int.clog` and `zpow`.\n* `int.neg_log_inv_eq_clog`, `int.neg_clog_inv_eq_log`: the link between the two definitions.\n-/\n\nvariables {R : Type*} [linear_ordered_semifield R] [floor_semiring R]\n\nnamespace int\n\n/-- The greatest power of `b` such that `b ^ log b r \u2264 r`. -/\ndef log (b : \u2115) (r : R) : \u2124 :=\nif 1 \u2264 r then\n  nat.log b \u230ar\u230b\u208a\nelse\n  -nat.clog b \u2308r\u207b\u00b9\u2309\u208a\n\nlemma log_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : log b r = nat.log b \u230ar\u230b\u208a :=\nif_pos hr\n\nlemma log_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : log b r = -nat.clog b \u2308r\u207b\u00b9\u2309\u208a :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [log, if_pos hr, inv_one, nat.ceil_one, nat.floor_one, nat.log_one_right, nat.clog_one_right,\n        int.coe_nat_zero, neg_zero], },\n  { exact if_neg hr.not_le }\nend\n\n@[simp, norm_cast] lemma log_nat_cast (b : \u2115) (n : \u2115) : log b (n : R) = nat.log b n :=\nbegin\n  cases n,\n  { simp [log_of_right_le_one _ _, nat.log_zero_right] },\n  { have : 1 \u2264 (n.succ : R) := by simp,\n    simp [log_of_one_le_right _ this, \u2190nat.cast_succ] }\nend\n\nlemma log_of_left_le_one {b : \u2115} (hb : b \u2264 1) (r : R) : log b r = 0 :=\nbegin\n  cases le_total 1 r,\n  { rw [log_of_one_le_right _ h, nat.log_of_left_le_one hb, int.coe_nat_zero] },\n  { rw [log_of_right_le_one _ h, nat.clog_of_left_le_one hb, int.coe_nat_zero, neg_zero] },\nend\n\nlemma log_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : log b r = 0 :=\nby rw [log_of_right_le_one _ (hr.trans zero_le_one),\n    nat.clog_of_right_le_one ((nat.ceil_eq_zero.mpr $ inv_nonpos.2 hr).trans_le zero_le_one),\n    int.coe_nat_zero, neg_zero]\n\nlemma zpow_log_le_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) :\n  (b : R) ^ log b r \u2264 r :=\nbegin\n  cases le_total 1 r with hr1 hr1,\n  { rw log_of_one_le_right _ hr1,\n    rw [zpow_coe_nat, \u2190 nat.cast_pow, \u2190 nat.le_floor_iff hr.le],\n    exact nat.pow_log_le_self b (nat.floor_pos.mpr hr1).ne' },\n  { rw [log_of_right_le_one _ hr1, zpow_neg, zpow_coe_nat, \u2190 nat.cast_pow],\n    exact inv_le_of_inv_le hr (nat.ceil_le.1 $ nat.le_pow_clog hb _) },\nend\n\nlemma lt_zpow_succ_log_self {b : \u2115} (hb : 1 < b) (r : R) :\n  r < (b : R) ^ (log b r + 1) :=\nbegin\n  cases le_or_lt r 0 with hr hr,\n  { rw [log_of_right_le_zero _ hr, zero_add, zpow_one],\n    exact hr.trans_lt (zero_lt_one.trans_le $ by exact_mod_cast hb.le) },\n  cases le_or_lt 1 r with hr1 hr1,\n  { rw log_of_one_le_right _ hr1,\n    rw [int.coe_nat_add_one_out, zpow_coe_nat, \u2190nat.cast_pow],\n    apply nat.lt_of_floor_lt,\n    exact nat.lt_pow_succ_log_self hb _, },\n  { rw log_of_right_le_one _ hr1.le,\n    have hcri : 1 < r\u207b\u00b9 := one_lt_inv hr hr1,\n    have : 1 \u2264 nat.clog b \u2308r\u207b\u00b9\u2309\u208a :=\n      nat.succ_le_of_lt (nat.clog_pos hb $ nat.one_lt_cast.1 $ hcri.trans_le (nat.le_ceil _)),\n    rw [neg_add_eq_sub, \u2190neg_sub, \u2190int.coe_nat_one, \u2190 int.coe_nat_sub this,\n      zpow_neg, zpow_coe_nat, lt_inv hr (pow_pos (nat.cast_pos.mpr $ zero_lt_one.trans hb) _),\n      \u2190nat.cast_pow],\n    refine nat.lt_ceil.1 _,\n    exact (nat.pow_pred_clog_lt_self hb $ nat.one_lt_cast.1 $ hcri.trans_le $ nat.le_ceil _), }\nend\n\n@[simp] lemma log_zero_right (b : \u2115) : log b (0 : R) = 0 :=\nlog_of_right_le_zero b le_rfl\n\n@[simp] lemma log_one_right (b : \u2115) : log b (1 : R) = 0 :=\nby rw [log_of_one_le_right _ le_rfl, nat.floor_one, nat.log_one_right, int.coe_nat_zero]\n\nlemma log_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : log b (b ^ z : R) = z :=\nbegin\n  obtain \u27e8n, rfl | rfl\u27e9 := z.eq_coe_or_neg,\n  { rw [log_of_one_le_right _ (one_le_zpow_of_nonneg _ $ int.coe_nat_nonneg _),\n      zpow_coe_nat, \u2190nat.cast_pow, nat.floor_coe, nat.log_pow hb],\n    exact_mod_cast hb.le, },\n  { rw [log_of_right_le_one _ (zpow_le_one_of_nonpos _ $ neg_nonpos.mpr (int.coe_nat_nonneg _)),\n      zpow_neg, inv_inv, zpow_coe_nat, \u2190nat.cast_pow, nat.ceil_nat_cast, nat.clog_pow _ _ hb],\n    exact_mod_cast hb.le, },\nend\n\n@[mono] lemma log_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) :\n  log b r\u2081 \u2264 log b r\u2082 :=\nbegin\n  cases le_or_lt b 1 with hb hb,\n  { rw [log_of_left_le_one hb, log_of_left_le_one hb], },\n  cases le_total r\u2081 1 with h\u2081 h\u2081; cases le_total r\u2082 1 with h\u2082 h\u2082,\n  { rw [log_of_right_le_one _ h\u2081, log_of_right_le_one _ h\u2082, neg_le_neg_iff, int.coe_nat_le],\n    exact nat.clog_mono_right _ (nat.ceil_mono $ inv_le_inv_of_le h\u2080 h), },\n  { rw [log_of_right_le_one _ h\u2081, log_of_one_le_right _ h\u2082],\n    exact (neg_nonpos.mpr (int.coe_nat_nonneg _)).trans (int.coe_nat_nonneg _) },\n  { obtain rfl := le_antisymm h (h\u2082.trans h\u2081), refl, },\n  { rw [log_of_one_le_right _ h\u2081, log_of_one_le_right _ h\u2082, int.coe_nat_le],\n    exact nat.log_mono_right (nat.floor_mono h), },\nend\n\nvariables (R)\n\n/-- Over suitable subtypes, `zpow` and `int.log` form a galois coinsertion -/\ndef zpow_log_gi {b : \u2115} (hb : 1 < b) :\n  galois_coinsertion\n    (\u03bb z : \u2124, subtype.mk ((b : R) ^ z) $ zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z)\n    (\u03bb r : set.Ioi (0 : R), int.log b (r : R)) :=\ngalois_coinsertion.monotone_intro\n  (\u03bb r\u2081 r\u2082, log_mono_right r\u2081.prop)\n  (\u03bb z\u2081 z\u2082 hz, subtype.coe_le_coe.mp $ (zpow_strict_mono $ by exact_mod_cast hb).monotone hz)\n  (\u03bb r, subtype.coe_le_coe.mp $ zpow_log_le_self hb r.prop)\n  (\u03bb _, log_zpow hb _)\n\nvariables {R}\n\n/-- `zpow b` and `int.log b` (almost) form a Galois connection. -/\nlemma lt_zpow_iff_log_lt {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  r < (b : R) ^ x \u2194 log b r < x :=\n@galois_connection.lt_iff_lt _ _ _ _ _ _ (zpow_log_gi R hb).gc x \u27e8r, hr\u27e9\n\n/-- `zpow b` and `int.log b` (almost) form a Galois connection. -/\nlemma zpow_le_iff_le_log {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  (b : R) ^ x \u2264 r \u2194 x \u2264 log b r :=\n@galois_connection.le_iff_le _ _ _ _ _ _ (zpow_log_gi R hb).gc x \u27e8r, hr\u27e9\n\n/-- The least power of `b` such that `r \u2264 b ^ log b r`. -/\ndef clog (b : \u2115) (r : R) : \u2124 :=\nif 1 \u2264 r then\n  nat.clog b \u2308r\u2309\u208a\nelse\n  -nat.log b \u230ar\u207b\u00b9\u230b\u208a\n\nlemma clog_of_one_le_right (b : \u2115) {r : R} (hr : 1 \u2264 r) : clog b r = nat.clog b \u2308r\u2309\u208a :=\nif_pos hr\n\nlemma clog_of_right_le_one (b : \u2115) {r : R} (hr : r \u2264 1) : clog b r = -nat.log b \u230ar\u207b\u00b9\u230b\u208a :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [clog, if_pos hr, inv_one, nat.ceil_one, nat.floor_one, nat.log_one_right,\n        nat.clog_one_right, int.coe_nat_zero, neg_zero], },\n  { exact if_neg hr.not_le }\nend\n\nlemma clog_of_right_le_zero (b : \u2115) {r : R} (hr : r \u2264 0) : clog b r = 0 :=\nbegin\n  rw [clog, if_neg (hr.trans_lt zero_lt_one).not_le, neg_eq_zero, int.coe_nat_eq_zero,\n    nat.log_eq_zero_iff],\n  cases le_or_lt b 1 with hb hb,\n  { exact or.inr hb },\n  { refine or.inl (lt_of_le_of_lt _ hb),\n    exact nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one) },\nend\n\n@[simp] lemma clog_inv (b : \u2115) (r : R) : clog b r\u207b\u00b9 = -log b r :=\nbegin\n  cases lt_or_le 0 r with hrp hrp,\n  { obtain hr | hr := le_total 1 r,\n    { rw [clog_of_right_le_one _ (inv_le_one hr), log_of_one_le_right _ hr, inv_inv] },\n    { rw [clog_of_one_le_right _ (one_le_inv hrp hr),  log_of_right_le_one _ hr, neg_neg] }, },\n  { rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero], },\nend\n\n@[simp] lemma log_inv (b : \u2115) (r : R) : log b r\u207b\u00b9 = -clog b r :=\nby rw [\u2190inv_inv r, clog_inv, neg_neg, inv_inv]\n\n-- note this is useful for writing in reverse\nlemma neg_log_inv_eq_clog (b : \u2115) (r : R) : -log b r\u207b\u00b9 = clog b r :=\nby rw [log_inv, neg_neg]\n\nlemma neg_clog_inv_eq_log (b : \u2115) (r : R) : -clog b r\u207b\u00b9 = log b r :=\nby rw [clog_inv, neg_neg]\n\n@[simp, norm_cast] lemma clog_nat_cast (b : \u2115) (n : \u2115) : clog b (n : R) = nat.clog b n :=\nbegin\n  cases n,\n  { simp [clog_of_right_le_one _ _, nat.clog_zero_right] },\n  { have : 1 \u2264 (n.succ : R) := by simp,\n    simp [clog_of_one_le_right _ this, \u2190nat.cast_succ] }\nend\n\nlemma clog_of_left_le_one {b : \u2115} (hb : b \u2264 1) (r : R) : clog b r = 0 :=\nby rw [\u2190neg_log_inv_eq_clog, log_of_left_le_one hb, neg_zero]\n\nlemma self_le_zpow_clog {b : \u2115} (hb : 1 < b) (r : R) : r \u2264 (b : R) ^ clog b r :=\nbegin\n  cases le_or_lt r 0 with hr hr,\n  { rw [clog_of_right_le_zero _ hr, zpow_zero],\n    exact hr.trans zero_le_one },\n  rw [\u2190neg_log_inv_eq_clog, zpow_neg, le_inv hr (zpow_pos_of_pos _ _)],\n  { exact zpow_log_le_self hb (inv_pos.mpr hr), },\n  { exact nat.cast_pos.mpr (zero_le_one.trans_lt hb), },\nend\n\nlemma zpow_pred_clog_lt_self {b : \u2115} {r : R} (hb : 1 < b) (hr : 0 < r) :\n  (b : R) ^ (clog b r - 1) < r :=\nbegin\n  rw [\u2190neg_log_inv_eq_clog, \u2190neg_add', zpow_neg, inv_lt _ hr],\n  { exact lt_zpow_succ_log_self hb _, },\n  { exact zpow_pos_of_pos (nat.cast_pos.mpr $ zero_le_one.trans_lt hb) _ }\nend\n\n@[simp] lemma clog_zero_right (b : \u2115) : clog b (0 : R) = 0 :=\nclog_of_right_le_zero _ le_rfl\n\n@[simp] lemma clog_one_right (b : \u2115) : clog b (1 : R) = 0 :=\nby rw [clog_of_one_le_right _ le_rfl, nat.ceil_one, nat.clog_one_right, int.coe_nat_zero]\n\nlemma clog_zpow {b : \u2115} (hb : 1 < b) (z : \u2124) : clog b (b ^ z : R) = z :=\nby rw [\u2190neg_log_inv_eq_clog, \u2190zpow_neg, log_zpow hb, neg_neg]\n\n@[mono] lemma clog_mono_right {b : \u2115} {r\u2081 r\u2082 : R} (h\u2080 : 0 < r\u2081) (h : r\u2081 \u2264 r\u2082) :\n  clog b r\u2081 \u2264 clog b r\u2082 :=\nbegin\n  rw [\u2190neg_log_inv_eq_clog, \u2190neg_log_inv_eq_clog, neg_le_neg_iff],\n  exact log_mono_right (inv_pos.mpr $ h\u2080.trans_le h) (inv_le_inv_of_le h\u2080 h),\nend\n\nvariables (R)\n/-- Over suitable subtypes, `int.clog` and `zpow` form a galois insertion -/\ndef clog_zpow_gi {b : \u2115} (hb : 1 < b) :\n  galois_insertion\n    (\u03bb r : set.Ioi (0 : R), int.clog b (r : R))\n    (\u03bb z : \u2124, \u27e8(b : R) ^ z, zpow_pos_of_pos (by exact_mod_cast zero_lt_one.trans hb) z\u27e9) :=\ngalois_insertion.monotone_intro\n  (\u03bb z\u2081 z\u2082 hz, subtype.coe_le_coe.mp $ (zpow_strict_mono $ by exact_mod_cast hb).monotone hz)\n  (\u03bb r\u2081 r\u2082, clog_mono_right r\u2081.prop)\n  (\u03bb r, subtype.coe_le_coe.mp $ self_le_zpow_clog hb _)\n  (\u03bb _, clog_zpow hb _)\nvariables {R}\n\n/-- `int.clog b` and `zpow b` (almost) form a Galois connection. -/\n\n\n/-- `int.clog b` and `zpow b` (almost) form a Galois connection. -/\nlemma le_zpow_iff_clog_le {b : \u2115} (hb : 1 < b) {x : \u2124} {r : R} (hr : 0 < r) :\n  r \u2264 (b : R) ^ x \u2194 clog b r \u2264 x :=\n(@galois_connection.le_iff_le _ _ _ _ _ _ (clog_zpow_gi R hb).gc \u27e8r, hr\u27e9 x).symm\n\nend int\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7061603580796947}}
{"text": "import ..Intuitionism.reckless\n\nexample (P Q : Prop) : (P \u2228 Q) \u2192 \u00ac(\u00acP \u2227 \u00acQ) :=\nbegin\n    intros h\u2081 h\u2082,\n    cases h\u2081 with hp hq,\n    {\n        exact h\u2082.elim_left hp,\n    },\n    {\n        exact h\u2082.elim_right hq,\n    }\nend\n\nlemma LEM_equiv_double_not : (\u2200 P : Prop, P \u2228 \u00acP) \u2194 \u2200 Q : Prop, \u00ac\u00acQ \u2192 Q :=\nbegin\n    split,\n    {\n        intros h Q nnq,\n        cases h Q with hq nq,\n        {\n            exact hq,\n        },\n        {\n            exfalso,\n            exact nnq nq,\n        }\n    },\n    {\n        intros h P,\n        apply h (P \u2228 \u00acP),\n        exact reckless.not_not_or P,\n    }\nend\n\nexample (P Q : Prop) (lem : \u2200 P : Prop, P \u2228 \u00acP) : \u00ac(\u00acP \u2227 \u00acQ) \u2192 P \u2228 Q :=\nbegin\n    intro h,\n    cases lem P with hp np,\n    {-- case: P\n        left,\n        exact hp,\n    },\n    {-- case: \u00acP\n        right,\n        have nn := LEM_equiv_double_not.mp lem,\n        apply nn Q,\n        intro nq,\n        exact h (and.intro np nq),\n    }\nend\n\n-- For the proof that the contrapositive of this is reckless, see reckless.lean\nexample (P Q : Prop) : (\u00acP \u2228 Q) \u2192 (P \u2192 Q) :=\nbegin\n    intros h hp,\n    cases h with np hq,\n    {-- case: \u00acP\n        exfalso,\n        exact np hp,\n    },\n    {-- case: Q\n        exact hq,\n    }\nend\n\nexample (\u03b1 : Type) (P : \u03b1 \u2192 Prop) : (\u00ac\u2203 x, P x) \u2192 \u2200 x, \u00acP x :=\nbegin\n    intros h x hpx,\n    apply h,\n    use x,\n    exact hpx,\nend", "meta": {"author": "SCRK16", "repo": "Intuitionism", "sha": "a3d9920ae056b39a66e37d1d0e03d246bca1e961", "save_path": "github-repos/lean/SCRK16-Intuitionism", "path": "github-repos/lean/SCRK16-Intuitionism/Intuitionism-a3d9920ae056b39a66e37d1d0e03d246bca1e961/examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7061076611302392}}
{"text": "/-\nCopyright (c) 2018 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport order.bounds\nimport data.set.intervals.basic\nimport data.set.finite\nimport data.set.lattice\n\n/-!\n# Theory of conditionally complete lattices.\n\nA conditionally complete lattice is a lattice in which every non-empty bounded subset s\nhas a least upper bound and a greatest lower bound, denoted below by Sup s and Inf s.\nTypical examples are real, nat, int with their usual orders.\n\nThe theory is very comparable to the theory of complete lattices, except that suitable\nboundedness and nonemptiness assumptions have to be added to most statements.\nWe introduce two predicates bdd_above and bdd_below to express this boundedness, prove\ntheir basic properties, and then go on to prove most useful properties of Sup and Inf\nin conditionally complete lattices.\n\nTo differentiate the statements between complete lattices and conditionally complete\nlattices, we prefix Inf and Sup in the statements by c, giving cInf and cSup. For instance,\nInf_le is a statement in complete lattices ensuring Inf s \u2264 x, while cInf_le is the same\nstatement in conditionally complete lattices with an additional assumption that s is\nbounded below.\n-/\n\nset_option old_structure_cmd true\n\nopen set\n\nvariables {\u03b1 \u03b2 : Type*} {\u03b9 : Sort*}\n\nsection\n\n/-!\nExtension of Sup and Inf from a preorder `\u03b1` to `with_top \u03b1` and `with_bot \u03b1`\n-/\n\nopen_locale classical\n\nnoncomputable instance {\u03b1 : Type*} [preorder \u03b1] [has_Sup \u03b1] : has_Sup (with_top \u03b1) :=\n\u27e8\u03bb S, if \u22a4 \u2208 S then \u22a4 else\n  if bdd_above (coe \u207b\u00b9' S : set \u03b1) then \u2191(Sup (coe \u207b\u00b9' S : set \u03b1)) else \u22a4\u27e9\n\nnoncomputable instance {\u03b1 : Type*} [has_Inf \u03b1] : has_Inf (with_top \u03b1) :=\n\u27e8\u03bb S, if S \u2286 {\u22a4} then \u22a4 else \u2191(Inf (coe \u207b\u00b9' S : set \u03b1))\u27e9\n\nnoncomputable instance {\u03b1 : Type*} [has_Sup \u03b1] : has_Sup (with_bot \u03b1) :=\n\u27e8(@with_top.has_Inf (order_dual \u03b1) _).Inf\u27e9\n\nnoncomputable instance {\u03b1 : Type*} [preorder \u03b1] [has_Inf \u03b1] : has_Inf (with_bot \u03b1) :=\n\u27e8(@with_top.has_Sup (order_dual \u03b1) _ _).Sup\u27e9\n\n@[simp]\ntheorem with_top.cInf_empty {\u03b1 : Type*} [has_Inf \u03b1] : Inf (\u2205 : set (with_top \u03b1)) = \u22a4 :=\nif_pos $ set.empty_subset _\n\n@[simp]\ntheorem with_bot.cSup_empty {\u03b1 : Type*} [has_Sup \u03b1] : Sup (\u2205 : set (with_bot \u03b1)) = \u22a5 :=\nif_pos $ set.empty_subset _\n\nend -- section\n\n/-- A conditionally complete lattice is a lattice in which\nevery nonempty subset which is bounded above has a supremum, and\nevery nonempty subset which is bounded below has an infimum.\nTypical examples are real numbers or natural numbers.\n\nTo differentiate the statements from the corresponding statements in (unconditional)\ncomplete lattices, we prefix Inf and Sup by a c everywhere. The same statements should\nhold in both worlds, sometimes with additional assumptions of nonemptiness or\nboundedness.-/\nclass conditionally_complete_lattice (\u03b1 : Type*) extends lattice \u03b1, has_Sup \u03b1, has_Inf \u03b1 :=\n(le_cSup : \u2200s a, bdd_above s \u2192 a \u2208 s \u2192 a \u2264 Sup s)\n(cSup_le : \u2200 s a, set.nonempty s \u2192 a \u2208 upper_bounds s \u2192 Sup s \u2264 a)\n(cInf_le : \u2200s a, bdd_below s \u2192 a \u2208 s \u2192 Inf s \u2264 a)\n(le_cInf : \u2200s a, set.nonempty s \u2192 a \u2208 lower_bounds s \u2192 a \u2264 Inf s)\n\n/-- A conditionally complete linear order is a linear order in which\nevery nonempty subset which is bounded above has a supremum, and\nevery nonempty subset which is bounded below has an infimum.\nTypical examples are real numbers or natural numbers.\n\nTo differentiate the statements from the corresponding statements in (unconditional)\ncomplete linear orders, we prefix Inf and Sup by a c everywhere. The same statements should\nhold in both worlds, sometimes with additional assumptions of nonemptiness or\nboundedness.-/\nclass conditionally_complete_linear_order (\u03b1 : Type*)\n  extends conditionally_complete_lattice \u03b1, linear_order \u03b1 renaming max \u2192 sup min \u2192 inf\n\n/-- A conditionally complete linear order with `bot` is a linear order with least element, in which\nevery nonempty subset which is bounded above has a supremum, and every nonempty subset (necessarily\nbounded below) has an infimum.  A typical example is the natural numbers.\n\nTo differentiate the statements from the corresponding statements in (unconditional)\ncomplete linear orders, we prefix Inf and Sup by a c everywhere. The same statements should\nhold in both worlds, sometimes with additional assumptions of nonemptiness or\nboundedness.-/\n@[ancestor conditionally_complete_linear_order has_bot]\nclass conditionally_complete_linear_order_bot (\u03b1 : Type*)\n  extends conditionally_complete_linear_order \u03b1, has_bot \u03b1 :=\n(bot_le : \u2200 x : \u03b1, \u22a5 \u2264 x)\n(cSup_empty : Sup \u2205 = \u22a5)\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance conditionally_complete_linear_order_bot.to_order_bot\n  [h : conditionally_complete_linear_order_bot \u03b1] : order_bot \u03b1 :=\n{ ..h }\n\n/-- A complete lattice is a conditionally complete lattice, as there are no restrictions\non the properties of Inf and Sup in a complete lattice.-/\n@[priority 100] -- see Note [lower instance priority]\ninstance complete_lattice.to_conditionally_complete_lattice [complete_lattice \u03b1] :\n  conditionally_complete_lattice \u03b1 :=\n{ le_cSup := by intros; apply le_Sup; assumption,\n  cSup_le := by intros; apply Sup_le; assumption,\n  cInf_le := by intros; apply Inf_le; assumption,\n  le_cInf := by intros; apply le_Inf; assumption,\n  ..\u2039complete_lattice \u03b1\u203a }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance complete_linear_order.to_conditionally_complete_linear_order_bot {\u03b1 : Type*}\n  [complete_linear_order \u03b1] :\n  conditionally_complete_linear_order_bot \u03b1 :=\n{ cSup_empty := Sup_empty,\n  ..complete_lattice.to_conditionally_complete_lattice, .. \u2039complete_linear_order \u03b1\u203a }\n\nsection\nopen_locale classical\n\n/-- A well founded linear order is conditionally complete, with a bottom element. -/\n@[reducible] noncomputable def well_founded.conditionally_complete_linear_order_with_bot\n  {\u03b1 : Type*} [i : linear_order \u03b1] (h : well_founded ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop))\n  (c : \u03b1) (hc : c = h.min set.univ \u27e8c, mem_univ c\u27e9) :\n  conditionally_complete_linear_order_bot \u03b1 :=\n{ sup := max,\n  le_sup_left := le_max_left,\n  le_sup_right := le_max_right,\n  sup_le := \u03bb a b c, max_le,\n  inf := min,\n  inf_le_left := min_le_left,\n  inf_le_right := min_le_right,\n  le_inf := \u03bb a b c, le_min,\n  Inf := \u03bb s, if hs : s.nonempty then h.min s hs else c,\n  cInf_le := begin\n    assume s a hs has,\n    have s_ne : s.nonempty := \u27e8a, has\u27e9,\n    simpa [s_ne] using not_lt.1 (h.not_lt_min s s_ne has),\n  end,\n  le_cInf := begin\n    assume s a hs has,\n    simp only [hs, dif_pos],\n    exact has (h.min_mem s hs),\n  end,\n  Sup := \u03bb s, if hs : (upper_bounds s).nonempty then h.min _ hs else c,\n  le_cSup := begin\n    assume s a hs has,\n    have h's : (upper_bounds s).nonempty := hs,\n    simp only [h's, dif_pos],\n    exact h.min_mem _ h's has,\n  end,\n  cSup_le := begin\n    assume s a hs has,\n    have h's : (upper_bounds s).nonempty := \u27e8a, has\u27e9,\n    simp only [h's, dif_pos],\n    simpa using h.not_lt_min _ h's has,\n  end,\n  bot := c,\n  bot_le := \u03bb x, by convert not_lt.1 (h.not_lt_min set.univ \u27e8c, mem_univ c\u27e9 (mem_univ x)),\n  cSup_empty := begin\n    have : (set.univ : set \u03b1).nonempty := \u27e8c, mem_univ c\u27e9,\n    simp only [this, dif_pos, upper_bounds_empty],\n    exact hc.symm\n  end,\n  .. i }\n\nend\n\nsection order_dual\n\ninstance (\u03b1 : Type*) [conditionally_complete_lattice \u03b1] :\n  conditionally_complete_lattice (order_dual \u03b1) :=\n{ le_cSup := @conditionally_complete_lattice.cInf_le \u03b1 _,\n  cSup_le := @conditionally_complete_lattice.le_cInf \u03b1 _,\n  le_cInf := @conditionally_complete_lattice.cSup_le \u03b1 _,\n  cInf_le := @conditionally_complete_lattice.le_cSup \u03b1 _,\n  ..order_dual.has_Inf \u03b1,\n  ..order_dual.has_Sup \u03b1,\n  ..order_dual.lattice \u03b1 }\n\ninstance (\u03b1 : Type*) [conditionally_complete_linear_order \u03b1] :\n  conditionally_complete_linear_order (order_dual \u03b1) :=\n{ ..order_dual.conditionally_complete_lattice \u03b1,\n  ..order_dual.linear_order \u03b1 }\n\nend order_dual\n\nsection conditionally_complete_lattice\nvariables [conditionally_complete_lattice \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\ntheorem le_cSup (h\u2081 : bdd_above s) (h\u2082 : a \u2208 s) : a \u2264 Sup s :=\nconditionally_complete_lattice.le_cSup s a h\u2081 h\u2082\n\ntheorem cSup_le (h\u2081 : s.nonempty) (h\u2082 : \u2200b\u2208s, b \u2264 a) : Sup s \u2264 a :=\nconditionally_complete_lattice.cSup_le s a h\u2081 h\u2082\n\ntheorem cInf_le (h\u2081 : bdd_below s) (h\u2082 : a \u2208 s) : Inf s \u2264 a :=\nconditionally_complete_lattice.cInf_le s a h\u2081 h\u2082\n\ntheorem le_cInf (h\u2081 : s.nonempty) (h\u2082 : \u2200b\u2208s, a \u2264 b) : a \u2264 Inf s :=\nconditionally_complete_lattice.le_cInf s a h\u2081 h\u2082\n\ntheorem le_cSup_of_le (_ : bdd_above s) (hb : b \u2208 s) (h : a \u2264 b) : a \u2264 Sup s :=\nle_trans h (le_cSup \u2039bdd_above s\u203a hb)\n\ntheorem cInf_le_of_le (_ : bdd_below s) (hb : b \u2208 s) (h : b \u2264 a) : Inf s \u2264 a :=\nle_trans (cInf_le \u2039bdd_below s\u203a hb) h\n\ntheorem cSup_le_cSup (_ : bdd_above t) (_ : s.nonempty) (h : s \u2286 t) : Sup s \u2264 Sup t :=\ncSup_le \u2039_\u203a (assume (a) (ha : a \u2208 s), le_cSup \u2039bdd_above t\u203a (h ha))\n\ntheorem cInf_le_cInf (_ : bdd_below t) (_ : s.nonempty) (h : s \u2286 t) : Inf t \u2264 Inf s :=\nle_cInf \u2039_\u203a (assume (a) (ha : a \u2208 s), cInf_le \u2039bdd_below t\u203a (h ha))\n\nlemma is_lub_cSup (ne : s.nonempty) (H : bdd_above s) : is_lub s (Sup s) :=\n\u27e8assume x, le_cSup H, assume x, cSup_le ne\u27e9\n\nlemma is_lub_csupr [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : bdd_above (range f)) :\n  is_lub (range f) (\u2a06 i, f i) :=\nis_lub_cSup (range_nonempty f) H\n\nlemma is_lub_csupr_set {f : \u03b2 \u2192 \u03b1} {s : set \u03b2} (H : bdd_above (f '' s)) (Hne : s.nonempty) :\n  is_lub (f '' s) (\u2a06 i : s, f i) :=\nby { rw \u2190 Sup_image', exact is_lub_cSup (Hne.image _) H }\n\nlemma is_glb_cInf (ne : s.nonempty) (H : bdd_below s) : is_glb s (Inf s) :=\n\u27e8assume x, cInf_le H, assume x, le_cInf ne\u27e9\n\nlemma is_glb_cinfi [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : bdd_below (range f)) :\n  is_glb (range f) (\u2a05 i, f i) :=\nis_glb_cInf (range_nonempty f) H\n\nlemma is_glb_cinfi_set {f : \u03b2 \u2192 \u03b1} {s : set \u03b2} (H : bdd_below (f '' s)) (Hne : s.nonempty) :\n  is_glb (f '' s) (\u2a05 i : s, f i) :=\n@is_lub_csupr_set (order_dual \u03b1) _ _ _ _ H Hne\n\nlemma is_lub.cSup_eq (H : is_lub s a) (ne : s.nonempty) : Sup s = a :=\n(is_lub_cSup ne \u27e8a, H.1\u27e9).unique H\n\nlemma is_lub.csupr_eq [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : is_lub (range f) a) : (\u2a06 i, f i) = a :=\nH.cSup_eq (range_nonempty f)\n\nlemma is_lub.csupr_set_eq {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} (H : is_lub (f '' s) a) (Hne : s.nonempty) :\n  (\u2a06 i : s, f i) = a :=\nis_lub.cSup_eq (image_eq_range f s \u25b8 H) (image_eq_range f s \u25b8 Hne.image f)\n\n/-- A greatest element of a set is the supremum of this set. -/\nlemma is_greatest.cSup_eq (H : is_greatest s a) : Sup s = a :=\nH.is_lub.cSup_eq H.nonempty\n\nlemma is_greatest.Sup_mem (H : is_greatest s a) : Sup s \u2208 s :=\nH.cSup_eq.symm \u25b8 H.1\n\nlemma is_glb.cInf_eq (H : is_glb s a) (ne : s.nonempty) : Inf s = a :=\n(is_glb_cInf ne \u27e8a, H.1\u27e9).unique H\n\nlemma is_glb.cinfi_eq [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : is_glb (range f) a) : (\u2a05 i, f i) = a :=\nH.cInf_eq (range_nonempty f)\n\nlemma is_glb.cinfi_set_eq {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} (H : is_glb (f '' s) a) (Hne : s.nonempty) :\n  (\u2a05 i : s, f i) = a :=\nis_glb.cInf_eq (image_eq_range f s \u25b8 H) (image_eq_range f s \u25b8 Hne.image f)\n\n/-- A least element of a set is the infimum of this set. -/\nlemma is_least.cInf_eq (H : is_least s a) : Inf s = a :=\nH.is_glb.cInf_eq H.nonempty\n\nlemma is_least.Inf_mem (H : is_least s a) : Inf s \u2208 s :=\nH.cInf_eq.symm \u25b8 H.1\n\nlemma subset_Icc_cInf_cSup (hb : bdd_below s) (ha : bdd_above s) :\n  s \u2286 Icc (Inf s) (Sup s) :=\n\u03bb x hx, \u27e8cInf_le hb hx, le_cSup ha hx\u27e9\n\ntheorem cSup_le_iff (hb : bdd_above s) (ne : s.nonempty) : Sup s \u2264 a \u2194 (\u2200b \u2208 s, b \u2264 a) :=\nis_lub_le_iff (is_lub_cSup ne hb)\n\ntheorem le_cInf_iff (hb : bdd_below s) (ne : s.nonempty) : a \u2264 Inf s \u2194 (\u2200b \u2208 s, a \u2264 b) :=\nle_is_glb_iff (is_glb_cInf ne hb)\n\nlemma cSup_lower_bounds_eq_cInf {s : set \u03b1} (h : bdd_below s) (hs : s.nonempty) :\n  Sup (lower_bounds s) = Inf s :=\n(is_lub_cSup h $ hs.mono $ \u03bb x hx y hy, hy hx).unique (is_glb_cInf hs h).is_lub\n\nlemma cInf_upper_bounds_eq_cSup {s : set \u03b1} (h : bdd_above s) (hs : s.nonempty) :\n  Inf (upper_bounds s) = Sup s :=\n(is_glb_cInf h $ hs.mono $ \u03bb x hx y hy, hy hx).unique (is_lub_cSup hs h).is_glb\n\nlemma not_mem_of_lt_cInf {x : \u03b1} {s : set \u03b1} (h : x < Inf s) (hs : bdd_below s) : x \u2209 s :=\n\u03bb hx, lt_irrefl _ (h.trans_le (cInf_le hs hx))\n\nlemma not_mem_of_cSup_lt {x : \u03b1} {s : set \u03b1} (h : Sup s < x) (hs : bdd_above s) : x \u2209 s :=\n@not_mem_of_lt_cInf (order_dual \u03b1) _ x s h hs\n\n/--Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b`\nis larger than all elements of `s`, and that this is not the case of any `w<b`.\nSee `Sup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/\ntheorem cSup_eq_of_forall_le_of_forall_lt_exists_gt (_ : s.nonempty)\n  (_ : \u2200a\u2208s, a \u2264 b) (H : \u2200w, w < b \u2192 (\u2203a\u2208s, w < a)) : Sup s = b :=\nhave bdd_above s := \u27e8b, by assumption\u27e9,\nhave (Sup s < b) \u2228 (Sup s = b) := lt_or_eq_of_le (cSup_le \u2039_\u203a \u2039\u2200a\u2208s, a \u2264 b\u203a),\nhave h : \u00ac(Sup s < b) :=\n  assume: Sup s < b,\n  let \u27e8a, _, _\u27e9 := (H (Sup s) \u2039Sup s < b\u203a) in  /- a \u2208 s, Sup s < a-/\n  have Sup s < Sup s := lt_of_lt_of_le \u2039Sup s < a\u203a (le_cSup \u2039bdd_above s\u203a \u2039a \u2208 s\u203a),\n  show false, by { exact lt_irrefl (Sup s) this },\nshow Sup s = b, by { cases this with h1, { cases h h1 }, { assumption } }\n\n/--Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b`\nis smaller than all elements of `s`, and that this is not the case of any `w>b`.\nSee `Inf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/\ntheorem cInf_eq_of_forall_ge_of_forall_gt_exists_lt (_ : s.nonempty) (_ : \u2200a\u2208s, b \u2264 a)\n  (H : \u2200w, b < w \u2192 (\u2203a\u2208s, a < w)) : Inf s = b :=\n@cSup_eq_of_forall_le_of_forall_lt_exists_gt (order_dual \u03b1) _ _ _ \u2039_\u203a \u2039_\u203a \u2039_\u203a\n\n/--b < Sup s when there is an element a in s with b < a, when s is bounded above.\nThis is essentially an iff, except that the assumptions for the two implications are\nslightly different (one needs boundedness above for one direction, nonemptiness and linear\norder for the other one), so we formulate separately the two implications, contrary to\nthe complete_lattice case.-/\nlemma lt_cSup_of_lt (_ : bdd_above s) (_ : a \u2208 s) (_ : b < a) : b < Sup s :=\nlt_of_lt_of_le \u2039b < a\u203a (le_cSup \u2039bdd_above s\u203a \u2039a \u2208 s\u203a)\n\n/--Inf s < b when there is an element a in s with a < b, when s is bounded below.\nThis is essentially an iff, except that the assumptions for the two implications are\nslightly different (one needs boundedness below for one direction, nonemptiness and linear\norder for the other one), so we formulate separately the two implications, contrary to\nthe complete_lattice case.-/\nlemma cInf_lt_of_lt (_ : bdd_below s) (_ : a \u2208 s) (_ : a < b) : Inf s < b :=\n@lt_cSup_of_lt (order_dual \u03b1) _ _ _ _ \u2039_\u203a \u2039_\u203a \u2039_\u203a\n\n/-- If all elements of a nonempty set `s` are less than or equal to all elements\nof a nonempty set `t`, then there exists an element between these sets. -/\nlemma exists_between_of_forall_le (sne : s.nonempty) (tne : t.nonempty)\n  (hst : \u2200 (x \u2208 s) (y \u2208 t), x \u2264 y) :\n  (upper_bounds s \u2229 lower_bounds t).nonempty :=\n\u27e8Inf t, \u03bb x hx, le_cInf tne $ hst x hx, \u03bb y hy, cInf_le (sne.mono hst) hy\u27e9\n\n/--The supremum of a singleton is the element of the singleton-/\n@[simp] theorem cSup_singleton (a : \u03b1) : Sup {a} = a :=\nis_greatest_singleton.cSup_eq\n\n/--The infimum of a singleton is the element of the singleton-/\n@[simp] theorem cInf_singleton (a : \u03b1) : Inf {a} = a :=\nis_least_singleton.cInf_eq\n\n@[simp] theorem cSup_pair (a b : \u03b1) : Sup {a, b} = a \u2294 b :=\n(@is_lub_pair _ _ a b).cSup_eq (nonempty_insert _ _)\n\n@[simp] theorem cInf_pair (a b : \u03b1) : Inf {a, b} = a \u2293 b :=\n(@is_glb_pair _ _ a b).cInf_eq (nonempty_insert _ _)\n\n/--If a set is bounded below and above, and nonempty, its infimum is less than or equal to\nits supremum.-/\ntheorem cInf_le_cSup (hb : bdd_below s) (ha : bdd_above s) (ne : s.nonempty) : Inf s \u2264 Sup s :=\nis_glb_le_is_lub (is_glb_cInf ne hb) (is_lub_cSup ne ha) ne\n\n/--The sup of a union of two sets is the max of the suprema of each subset, under the assumptions\nthat all sets are bounded above and nonempty.-/\ntheorem cSup_union (hs : bdd_above s) (sne : s.nonempty) (ht : bdd_above t) (tne : t.nonempty) :\n  Sup (s \u222a t) = Sup s \u2294 Sup t :=\n((is_lub_cSup sne hs).union (is_lub_cSup tne ht)).cSup_eq sne.inl\n\n/--The inf of a union of two sets is the min of the infima of each subset, under the assumptions\nthat all sets are bounded below and nonempty.-/\ntheorem cInf_union (hs : bdd_below s) (sne : s.nonempty) (ht : bdd_below t) (tne : t.nonempty) :\n  Inf (s \u222a t) = Inf s \u2293 Inf t :=\n@cSup_union (order_dual \u03b1) _ _ _ hs sne ht tne\n\n/--The supremum of an intersection of two sets is bounded by the minimum of the suprema of each\nset, if all sets are bounded above and nonempty.-/\ntheorem cSup_inter_le (_ : bdd_above s) (_ : bdd_above t) (hst : (s \u2229 t).nonempty) :\n  Sup (s \u2229 t) \u2264 Sup s \u2293 Sup t :=\nbegin\n  apply cSup_le hst, simp only [le_inf_iff, and_imp, set.mem_inter_eq], intros b _ _, split,\n  apply le_cSup \u2039bdd_above s\u203a \u2039b \u2208 s\u203a,\n  apply le_cSup \u2039bdd_above t\u203a \u2039b \u2208 t\u203a\nend\n\n/--The infimum of an intersection of two sets is bounded below by the maximum of the\ninfima of each set, if all sets are bounded below and nonempty.-/\ntheorem le_cInf_inter (_ : bdd_below s) (_ : bdd_below t) (hst : (s \u2229 t).nonempty) :\n  Inf s \u2294 Inf t \u2264 Inf (s \u2229 t) :=\n@cSup_inter_le (order_dual \u03b1) _ _ _ \u2039_\u203a \u2039_\u203a hst\n\n/-- The supremum of insert a s is the maximum of a and the supremum of s, if s is\nnonempty and bounded above.-/\ntheorem cSup_insert (hs : bdd_above s) (sne : s.nonempty) : Sup (insert a s) = a \u2294 Sup s :=\n((is_lub_cSup sne hs).insert a).cSup_eq (insert_nonempty a s)\n\n/-- The infimum of insert a s is the minimum of a and the infimum of s, if s is\nnonempty and bounded below.-/\ntheorem cInf_insert (hs : bdd_below s) (sne : s.nonempty) : Inf (insert a s) = a \u2293 Inf s :=\n@cSup_insert (order_dual \u03b1) _ _ _ hs sne\n\n@[simp] lemma cInf_Icc (h : a \u2264 b) : Inf (Icc a b) = a :=\n(is_glb_Icc h).cInf_eq (nonempty_Icc.2 h)\n\n@[simp] lemma cInf_Ici : Inf (Ici a) = a := is_least_Ici.cInf_eq\n\n@[simp] lemma cInf_Ico (h : a < b) : Inf (Ico a b) = a :=\n(is_glb_Ico h).cInf_eq (nonempty_Ico.2 h)\n\n@[simp] lemma cInf_Ioc [densely_ordered \u03b1] (h : a < b) : Inf (Ioc a b) = a :=\n(is_glb_Ioc h).cInf_eq (nonempty_Ioc.2 h)\n\n@[simp] lemma cInf_Ioi [no_max_order \u03b1] [densely_ordered \u03b1] : Inf (Ioi a) = a :=\ncInf_eq_of_forall_ge_of_forall_gt_exists_lt nonempty_Ioi (\u03bb _, le_of_lt)\n  (\u03bb w hw, by simpa using exists_between hw)\n\n@[simp] lemma cInf_Ioo [densely_ordered \u03b1] (h : a < b) : Inf (Ioo a b) = a :=\n(is_glb_Ioo h).cInf_eq (nonempty_Ioo.2 h)\n\n@[simp] lemma cSup_Icc (h : a \u2264 b) : Sup (Icc a b) = b :=\n(is_lub_Icc h).cSup_eq (nonempty_Icc.2 h)\n\n@[simp] lemma cSup_Ico [densely_ordered \u03b1] (h : a < b) : Sup (Ico a b) = b :=\n(is_lub_Ico h).cSup_eq (nonempty_Ico.2 h)\n\n@[simp] lemma cSup_Iic : Sup (Iic a) = a := is_greatest_Iic.cSup_eq\n\n@[simp] lemma cSup_Iio [no_min_order \u03b1] [densely_ordered \u03b1] : Sup (Iio a) = a :=\ncSup_eq_of_forall_le_of_forall_lt_exists_gt nonempty_Iio (\u03bb _, le_of_lt)\n  (\u03bb w hw, by simpa [and_comm] using exists_between hw)\n\n@[simp] lemma cSup_Ioc (h : a < b) : Sup (Ioc a b) = b :=\n(is_lub_Ioc h).cSup_eq (nonempty_Ioc.2 h)\n\n@[simp] lemma cSup_Ioo [densely_ordered \u03b1] (h : a < b) : Sup (Ioo a b) = b :=\n(is_lub_Ioo h).cSup_eq (nonempty_Ioo.2 h)\n\n/--The indexed supremum of a function is bounded above by a uniform bound-/\nlemma csupr_le [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} {c : \u03b1} (H : \u2200x, f x \u2264 c) : supr f \u2264 c :=\ncSup_le (range_nonempty f) (by rwa forall_range_iff)\n\n/--The indexed supremum of a function is bounded below by the value taken at one point-/\nlemma le_csupr {f : \u03b9 \u2192 \u03b1} (H : bdd_above (range f)) (c : \u03b9) : f c \u2264 supr f :=\nle_cSup H (mem_range_self _)\n\nlemma le_csupr_of_le {f : \u03b9 \u2192 \u03b1} (H : bdd_above (range f)) (c : \u03b9) (h : a \u2264 f c) : a \u2264 supr f :=\nle_trans h (le_csupr H c)\n\n/--The indexed supremum of two functions are comparable if the functions are pointwise comparable-/\nlemma csupr_le_csupr {f g : \u03b9 \u2192 \u03b1} (B : bdd_above (range g)) (H : \u2200x, f x \u2264 g x) :\n  supr f \u2264 supr g :=\nbegin\n  casesI is_empty_or_nonempty \u03b9,\n  { rw [supr_of_empty', supr_of_empty'] },\n  { exact csupr_le (\u03bb x, le_csupr_of_le B x (H x)) },\nend\n\n/--The indexed infimum of two functions are comparable if the functions are pointwise comparable-/\nlemma cinfi_le_cinfi {f g : \u03b9 \u2192 \u03b1} (B : bdd_below (range f)) (H : \u2200x, f x \u2264 g x) :\n  infi f \u2264 infi g :=\n@csupr_le_csupr (order_dual \u03b1) _ _ _ _ B H\n\n/--The indexed minimum of a function is bounded below by a uniform lower bound-/\nlemma le_cinfi [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} {c : \u03b1} (H : \u2200x, c \u2264 f x) : c \u2264 infi f :=\n@csupr_le (order_dual \u03b1) _ _ _ _ _ H\n\n/--The indexed infimum of a function is bounded above by the value taken at one point-/\nlemma cinfi_le {f : \u03b9 \u2192 \u03b1} (H : bdd_below (range f)) (c : \u03b9) : infi f \u2264 f c :=\n@le_csupr (order_dual \u03b1) _ _ _ H c\n\nlemma cinfi_le_of_le {f : \u03b9 \u2192 \u03b1} (H : bdd_below (range f)) (c : \u03b9) (h : f c \u2264 a) : infi f \u2264 a :=\n@le_csupr_of_le (order_dual \u03b1) _ _ _ _ H c h\n\n@[simp] theorem csupr_const [h\u03b9 : nonempty \u03b9] {a : \u03b1} : (\u2a06 b:\u03b9, a) = a :=\nby rw [supr, range_const, cSup_singleton]\n\n@[simp] theorem cinfi_const [h\u03b9 : nonempty \u03b9] {a : \u03b1} : (\u2a05 b:\u03b9, a) = a :=\n@csupr_const (order_dual \u03b1) _ _ _ _\n\ntheorem supr_unique [unique \u03b9] {s : \u03b9 \u2192 \u03b1} : (\u2a06 i, s i) = s default :=\nhave \u2200 i, s i = s default := \u03bb i, congr_arg s (unique.eq_default i),\nby simp only [this, csupr_const]\n\ntheorem infi_unique [unique \u03b9] {s : \u03b9 \u2192 \u03b1} : (\u2a05 i, s i) = s default :=\n@supr_unique (order_dual \u03b1) _ _ _ _\n\n@[simp] theorem supr_unit {f : unit \u2192 \u03b1} : (\u2a06 x, f x) = f () :=\nby { convert supr_unique, apply_instance }\n\n@[simp] theorem infi_unit {f : unit \u2192 \u03b1} : (\u2a05 x, f x) = f () :=\n@supr_unit (order_dual \u03b1) _ _\n\n@[simp] lemma csupr_pos {p : Prop} {f : p \u2192 \u03b1} (hp : p) : (\u2a06 h : p, f h) = f hp :=\nby haveI := unique_prop hp; exact supr_unique\n\n@[simp] lemma cinfi_pos {p : Prop} {f : p \u2192 \u03b1} (hp : p) : (\u2a05 h : p, f h) = f hp :=\n@csupr_pos (order_dual \u03b1) _ _ _ hp\n\nlemma csupr_set {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} : (\u2a06 x : s, f x) = Sup (f '' s) :=\nbegin\n  rw supr,\n  congr,\n  ext,\n  rw [mem_image, mem_range, set_coe.exists],\n  simp_rw [subtype.coe_mk, exists_prop],\nend\n\nlemma cinfi_set {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} : (\u2a05 x : s, f x) = Inf (f '' s) :=\n@csupr_set (order_dual \u03b1) _ _ _ _\n\n/--Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b`\nis larger than `f i` for all `i`, and that this is not the case of any `w<b`.\nSee `supr_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/\ntheorem csupr_eq_of_forall_le_of_forall_lt_exists_gt [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h\u2081 : \u2200 i, f i \u2264 b)\n  (h\u2082 : \u2200 w, w < b \u2192 (\u2203 i, w < f i)) : (\u2a06 (i : \u03b9), f i) = b :=\ncSup_eq_of_forall_le_of_forall_lt_exists_gt (range_nonempty f) (forall_range_iff.mpr h\u2081)\n  (\u03bb w hw, exists_range_iff.mpr $ h\u2082 w hw)\n\n/--Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b`\nis smaller than `f i` for all `i`, and that this is not the case of any `w>b`.\nSee `infi_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/\ntheorem cinfi_eq_of_forall_ge_of_forall_gt_exists_lt [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h\u2081 : \u2200 i, b \u2264 f i)\n  (h\u2082 : \u2200 w, b < w \u2192 (\u2203 i, f i < w)) : (\u2a05 (i : \u03b9), f i) = b :=\n@csupr_eq_of_forall_le_of_forall_lt_exists_gt (order_dual \u03b1) _ _ _ _ \u2039_\u203a \u2039_\u203a \u2039_\u203a\n\n/-- Nested intervals lemma: if `f` is a monotone sequence, `g` is an antitone sequence, and\n`f n \u2264 g n` for all `n`, then `\u2a06 n, f n` belongs to all the intervals `[f n, g n]`. -/\nlemma monotone.csupr_mem_Inter_Icc_of_antitone [semilattice_sup \u03b2]\n  {f g : \u03b2 \u2192 \u03b1} (hf : monotone f) (hg : antitone g) (h : f \u2264 g) :\n  (\u2a06 n, f n) \u2208 \u22c2 n, Icc (f n) (g n) :=\nbegin\n  refine mem_Inter.2 (\u03bb n, _),\n  haveI : nonempty \u03b2 := \u27e8n\u27e9,\n  have : \u2200 m, f m \u2264 g n := \u03bb m, hf.forall_le_of_antitone hg h m n,\n  exact \u27e8le_csupr \u27e8g $ n, forall_range_iff.2 this\u27e9 _, csupr_le this\u27e9\nend\n\n/-- Nested intervals lemma: if `[f n, g n]` is an antitone sequence of nonempty\nclosed intervals, then `\u2a06 n, f n` belongs to all the intervals `[f n, g n]`. -/\nlemma csupr_mem_Inter_Icc_of_antitone_Icc [semilattice_sup \u03b2]\n  {f g : \u03b2 \u2192 \u03b1} (h : antitone (\u03bb n, Icc (f n) (g n))) (h' : \u2200 n, f n \u2264 g n) :\n  (\u2a06 n, f n) \u2208 \u22c2 n, Icc (f n) (g n) :=\nmonotone.csupr_mem_Inter_Icc_of_antitone (\u03bb m n hmn, ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).1)\n  (\u03bb m n hmn, ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).2) h'\n\nlemma finset.nonempty.sup'_eq_cSup_image {s : finset \u03b2} (hs : s.nonempty) (f : \u03b2 \u2192 \u03b1) :\n  s.sup' hs f = Sup (f '' s) :=\neq_of_forall_ge_iff $ \u03bb a,\n  by simp [cSup_le_iff (s.finite_to_set.image f).bdd_above (hs.to_set.image f)]\n\nlemma finset.nonempty.sup'_id_eq_cSup {s : finset \u03b1} (hs : s.nonempty) :\n  s.sup' hs id = Sup s :=\nby rw [hs.sup'_eq_cSup_image, image_id]\n\nend conditionally_complete_lattice\n\ninstance pi.conditionally_complete_lattice {\u03b9 : Type*} {\u03b1 : \u03a0 i : \u03b9, Type*}\n  [\u03a0 i, conditionally_complete_lattice (\u03b1 i)] :\n  conditionally_complete_lattice (\u03a0 i, \u03b1 i) :=\n{ le_cSup := \u03bb s f \u27e8g, hg\u27e9 hf i, le_cSup \u27e8g i, set.forall_range_iff.2 $ \u03bb \u27e8f', hf'\u27e9, hg hf' i\u27e9\n    \u27e8\u27e8f, hf\u27e9, rfl\u27e9,\n  cSup_le := \u03bb s f hs hf i, cSup_le (by haveI := hs.to_subtype; apply range_nonempty) $\n    \u03bb b \u27e8\u27e8g, hg\u27e9, hb\u27e9, hb \u25b8 hf hg i,\n  cInf_le := \u03bb s f \u27e8g, hg\u27e9 hf i, cInf_le \u27e8g i, set.forall_range_iff.2 $ \u03bb \u27e8f', hf'\u27e9, hg hf' i\u27e9\n    \u27e8\u27e8f, hf\u27e9, rfl\u27e9,\n  le_cInf := \u03bb s f hs hf i, le_cInf (by haveI := hs.to_subtype; apply range_nonempty) $\n    \u03bb b \u27e8\u27e8g, hg\u27e9, hb\u27e9, hb \u25b8 hf hg i,\n  .. pi.lattice, .. pi.has_Sup, .. pi.has_Inf }\n\nsection conditionally_complete_linear_order\nvariables [conditionally_complete_linear_order \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\nlemma finset.nonempty.cSup_eq_max' {s : finset \u03b1} (h : s.nonempty) : Sup \u2191s = s.max' h :=\neq_of_forall_ge_iff $ \u03bb a, (cSup_le_iff s.bdd_above h.to_set).trans (s.max'_le_iff h).symm\n\nlemma finset.nonempty.cInf_eq_min' {s : finset \u03b1} (h : s.nonempty) : Inf \u2191s = s.min' h :=\n@finset.nonempty.cSup_eq_max' (order_dual \u03b1) _ s h\n\nlemma finset.nonempty.cSup_mem {s : finset \u03b1} (h : s.nonempty) : Sup (s : set \u03b1) \u2208 s :=\nby { rw h.cSup_eq_max', exact s.max'_mem _ }\n\nlemma finset.nonempty.cInf_mem {s : finset \u03b1} (h : s.nonempty) : Inf (s : set \u03b1) \u2208 s :=\n@finset.nonempty.cSup_mem (order_dual \u03b1) _ _ h\n\nlemma set.nonempty.cSup_mem (h : s.nonempty) (hs : finite s) : Sup s \u2208 s :=\nby { lift s to finset \u03b1 using hs, exact finset.nonempty.cSup_mem h }\n\nlemma set.nonempty.cInf_mem (h : s.nonempty) (hs : finite s) : Inf s \u2208 s :=\n@set.nonempty.cSup_mem (order_dual \u03b1) _ _ h hs\n\nlemma set.finite.cSup_lt_iff (hs : finite s) (h : s.nonempty) : Sup s < a \u2194 \u2200 x \u2208 s, x < a :=\n\u27e8\u03bb h x hx, (le_cSup hs.bdd_above hx).trans_lt h, \u03bb H, H _ $ h.cSup_mem hs\u27e9\n\nlemma set.finite.lt_cInf_iff (hs : finite s) (h : s.nonempty) : a < Inf s \u2194 \u2200 x \u2208 s, a < x :=\n@set.finite.cSup_lt_iff (order_dual \u03b1) _ _ _ hs h\n\n/-- When b < Sup s, there is an element a in s with b < a, if s is nonempty and the order is\na linear order. -/\nlemma exists_lt_of_lt_cSup (hs : s.nonempty) (hb : b < Sup s) : \u2203a\u2208s, b < a :=\nbegin\n  classical, contrapose! hb,\n  exact cSup_le hs hb\nend\n\n/--\nIndexed version of the above lemma `exists_lt_of_lt_cSup`.\nWhen `b < supr f`, there is an element `i` such that `b < f i`.\n-/\nlemma exists_lt_of_lt_csupr [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h : b < supr f) :\n  \u2203i, b < f i :=\nlet \u27e8_, \u27e8i, rfl\u27e9, h\u27e9 := exists_lt_of_lt_cSup (range_nonempty f) h in \u27e8i, h\u27e9\n\n/--When Inf s < b, there is an element a in s with a < b, if s is nonempty and the order is\na linear order.-/\nlemma exists_lt_of_cInf_lt (hs : s.nonempty) (hb : Inf s < b) : \u2203a\u2208s, a < b :=\n@exists_lt_of_lt_cSup (order_dual \u03b1) _ _ _ hs hb\n\n/--\nIndexed version of the above lemma `exists_lt_of_cInf_lt`\nWhen `infi f < a`, there is an element `i` such that `f i < a`.\n-/\nlemma exists_lt_of_cinfi_lt [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h : infi f < a) :\n  (\u2203i, f i < a) :=\n@exists_lt_of_lt_csupr (order_dual \u03b1) _ _ _ _ _ h\n\n/--Introduction rule to prove that b is the supremum of s: it suffices to check that\n1) b is an upper bound\n2) every other upper bound b' satisfies b \u2264 b'.-/\ntheorem cSup_eq_of_is_forall_le_of_forall_le_imp_ge (_ : s.nonempty)\n  (h_is_ub : \u2200 a \u2208 s, a \u2264 b) (h_b_le_ub : \u2200ub, (\u2200 a \u2208 s, a \u2264 ub) \u2192 (b \u2264 ub)) : Sup s = b :=\nle_antisymm\n  (show Sup s \u2264 b, from cSup_le \u2039s.nonempty\u203a h_is_ub)\n  (show b \u2264 Sup s, from h_b_le_ub _ $ assume a, le_cSup \u27e8b, h_is_ub\u27e9)\n\nopen function\nvariables [is_well_order \u03b1 (<)]\n\nlemma Inf_eq_argmin_on (hs : s.nonempty) : Inf s = argmin_on id (@is_well_order.wf \u03b1 (<) _) s hs :=\nis_least.cInf_eq \u27e8argmin_on_mem _ _ _ _, \u03bb a ha, argmin_on_le id _ _ ha\u27e9\n\nlemma is_least_Inf (hs : s.nonempty) : is_least s (Inf s) :=\nby { rw Inf_eq_argmin_on hs, exact \u27e8argmin_on_mem _ _ _ _, \u03bb a ha, argmin_on_le id _ _ ha\u27e9 }\n\nlemma le_cInf_iff' (hs : s.nonempty) : b \u2264 Inf s \u2194 b \u2208 lower_bounds s :=\nle_is_glb_iff (is_least_Inf hs).is_glb\n\nlemma Inf_mem (hs : s.nonempty) : Inf s \u2208 s := (is_least_Inf hs).1\n\nend conditionally_complete_linear_order\n\n/-!\n### Lemmas about a conditionally complete linear order with bottom element\n\nIn this case we have `Sup \u2205 = \u22a5`, so we can drop some `nonempty`/`set.nonempty` assumptions.\n-/\n\nsection conditionally_complete_linear_order_bot\n\nvariables [conditionally_complete_linear_order_bot \u03b1]\n\nlemma cSup_empty : (Sup \u2205 : \u03b1) = \u22a5 :=\nconditionally_complete_linear_order_bot.cSup_empty\n\nlemma csupr_of_empty [is_empty \u03b9] (f : \u03b9 \u2192 \u03b1) : (\u2a06 i, f i) = \u22a5 :=\nby rw [supr_of_empty', cSup_empty]\n\n@[simp] lemma csupr_false (f : false \u2192 \u03b1) : (\u2a06 i, f i) = \u22a5 := csupr_of_empty f\n\nlemma is_lub_cSup' {s : set \u03b1} (hs : bdd_above s) : is_lub s (Sup s) :=\nbegin\n  rcases eq_empty_or_nonempty s with (rfl|hne),\n  { simp only [cSup_empty, is_lub_empty] },\n  { exact is_lub_cSup hne hs }\nend\n\nlemma cSup_le_iff' {s : set \u03b1} (hs : bdd_above s) {a : \u03b1} : Sup s \u2264 a \u2194 \u2200 x \u2208 s, x \u2264 a :=\nis_lub_le_iff (is_lub_cSup' hs)\n\nlemma cSup_le' {s : set \u03b1} {a : \u03b1} (h : a \u2208 upper_bounds s) : Sup s \u2264 a :=\n(cSup_le_iff' \u27e8a, h\u27e9).2 h\n\nlemma exists_lt_of_lt_cSup' {s : set \u03b1} {a : \u03b1} (h : a < Sup s) : \u2203 b \u2208 s, a < b :=\nby { contrapose! h, exact cSup_le' h }\n\nlemma csupr_le_iff' {f : \u03b9 \u2192 \u03b1} (h : bdd_above (range f)) {a : \u03b1} :\n  (\u2a06 i, f i) \u2264 a \u2194 \u2200 i, f i \u2264 a :=\n(cSup_le_iff' h).trans forall_range_iff\n\nlemma csupr_le' {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (h : \u2200 i, f i \u2264 a) : (\u2a06 i, f i) \u2264 a :=\ncSup_le' $ forall_range_iff.2 h\n\nlemma exists_lt_of_lt_csupr' {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (h : a < \u2a06 i, f i) : \u2203 i, a < f i :=\nby { contrapose! h, exact csupr_le' h }\n\nend conditionally_complete_linear_order_bot\n\nnamespace with_top\nopen_locale classical\n\nvariables [conditionally_complete_linear_order_bot \u03b1]\n\n/-- The Sup of a non-empty set is its least upper bound for a conditionally\ncomplete lattice with a top. -/\nlemma is_lub_Sup' {\u03b2 : Type*} [conditionally_complete_lattice \u03b2]\n  {s : set (with_top \u03b2)} (hs : s.nonempty) : is_lub s (Sup s) :=\nbegin\n  split,\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { intros _ _, exact le_top },\n    { rintro (\u27e8\u27e9|a) ha,\n      { contradiction },\n      apply some_le_some.2,\n      exact le_cSup h_1 ha },\n    { intros _ _, exact le_top } },\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { rintro (\u27e8\u27e9|a) ha,\n      { exact _root_.le_rfl },\n      { exact false.elim (not_top_le_coe a (ha h)) } },\n    { rintro (\u27e8\u27e9|b) hb,\n      { exact le_top },\n      refine some_le_some.2 (cSup_le _ _),\n      { rcases hs with \u27e8\u27e8\u27e9|b, hb\u27e9,\n        { exact absurd hb h },\n        { exact \u27e8b, hb\u27e9 } },\n      { intros a ha, exact some_le_some.1 (hb ha) } },\n    { rintro (\u27e8\u27e9|b) hb,\n      { exact _root_.le_rfl },\n      { exfalso, apply h_1, use b, intros a ha, exact some_le_some.1 (hb ha) } } }\nend\n\nlemma is_lub_Sup (s : set (with_top \u03b1)) : is_lub s (Sup s) :=\nbegin\n  cases s.eq_empty_or_nonempty with hs hs,\n  { rw hs,\n    show is_lub \u2205 (ite _ _ _),\n    split_ifs,\n    { cases h },\n    { rw [preimage_empty, cSup_empty], exact is_lub_empty },\n    { exfalso, apply h_1, use \u22a5, rintro a \u27e8\u27e9 } },\n  exact is_lub_Sup' hs,\nend\n\n/-- The Inf of a bounded-below set is its greatest lower bound for a conditionally\ncomplete lattice with a top. -/\nlemma is_glb_Inf' {\u03b2 : Type*} [conditionally_complete_lattice \u03b2]\n  {s : set (with_top \u03b2)} (hs : bdd_below s) : is_glb s (Inf s) :=\nbegin\n  split,\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { intros a ha, exact top_le_iff.2 (set.mem_singleton_iff.1 (h ha)) },\n    { rintro (\u27e8\u27e9|a) ha,\n      { exact le_top },\n      refine some_le_some.2 (cInf_le _ ha),\n      rcases hs with \u27e8\u27e8\u27e9|b, hb\u27e9,\n      { exfalso,\n        apply h,\n        intros c hc,\n        rw [mem_singleton_iff, \u2190top_le_iff],\n        exact hb hc },\n      use b,\n      intros c hc,\n      exact some_le_some.1 (hb hc) } },\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { intros _ _, exact le_top },\n    { rintro (\u27e8\u27e9|a) ha,\n      { exfalso, apply h, intros b hb, exact set.mem_singleton_iff.2 (top_le_iff.1 (ha hb)) },\n      { refine some_le_some.2 (le_cInf _ _),\n        { classical, contrapose! h,\n          rintros (\u27e8\u27e9|a) ha,\n          { exact mem_singleton \u22a4 },\n          { exact (h \u27e8a, ha\u27e9).elim }},\n        { intros b hb,\n          rw \u2190some_le_some,\n          exact ha hb } } } }\nend\n\nlemma is_glb_Inf (s : set (with_top \u03b1)) : is_glb s (Inf s) :=\nbegin\n  by_cases hs : bdd_below s,\n  { exact is_glb_Inf' hs },\n  { exfalso, apply hs, use \u22a5, intros _ _, exact bot_le },\nend\n\nnoncomputable instance : complete_linear_order (with_top \u03b1) :=\n{ Sup := Sup, le_Sup := assume s, (is_lub_Sup s).1, Sup_le := assume s, (is_lub_Sup s).2,\n  Inf := Inf, le_Inf := assume s, (is_glb_Inf s).2, Inf_le := assume s, (is_glb_Inf s).1,\n  .. with_top.linear_order, ..with_top.lattice, ..with_top.order_top, ..with_top.order_bot }\n\nlemma coe_Sup {s : set \u03b1} (hb : bdd_above s) : (\u2191(Sup s) : with_top \u03b1) = (\u2a06a\u2208s, \u2191a) :=\nbegin\n  cases s.eq_empty_or_nonempty with hs hs,\n  { rw [hs, cSup_empty], simp only [set.mem_empty_eq, supr_bot, supr_false], refl },\n  apply le_antisymm,\n  { refine (coe_le_iff.2 $ assume b hb, cSup_le hs $ assume a has, coe_le_coe.1 $ hb \u25b8 _),\n    exact (le_supr_of_le a $ le_supr_of_le has $ _root_.le_rfl) },\n  { exact (supr_le $ assume a, supr_le $ assume ha, coe_le_coe.2 $ le_cSup hb ha) }\nend\n\nlemma coe_Inf {s : set \u03b1} (hs : s.nonempty) : (\u2191(Inf s) : with_top \u03b1) = (\u2a05a\u2208s, \u2191a) :=\nlet \u27e8x, hx\u27e9 := hs in\nhave (\u2a05a\u2208s, \u2191a : with_top \u03b1) \u2264 x, from infi_le_of_le x $ infi_le_of_le hx $ _root_.le_rfl,\nlet \u27e8r, r_eq, hr\u27e9 := le_coe_iff.1 this in\nle_antisymm\n  (le_infi $ assume a, le_infi $ assume ha, coe_le_coe.2 $ cInf_le (order_bot.bdd_below s) ha)\n  begin\n    refine (r_eq.symm \u25b8 coe_le_coe.2 $ le_cInf hs $ assume a has, coe_le_coe.1 $ _),\n    refine (r_eq \u25b8 infi_le_of_le a _),\n    exact (infi_le_of_le has $ _root_.le_rfl),\n  end\n\nend with_top\n\nnamespace monotone\nvariables [preorder \u03b1] [conditionally_complete_lattice \u03b2] {f : \u03b1 \u2192 \u03b2} (h_mono : monotone f)\n\n/-! A monotone function into a conditionally complete lattice preserves the ordering properties of\n`Sup` and `Inf`. -/\n\nlemma le_cSup_image {s : set \u03b1} {c : \u03b1} (hcs : c \u2208 s) (h_bdd : bdd_above s) :\n  f c \u2264 Sup (f '' s) :=\nle_cSup (map_bdd_above h_mono h_bdd) (mem_image_of_mem f hcs)\n\nlemma cSup_image_le {s : set \u03b1} (hs : s.nonempty) {B : \u03b1} (hB: B \u2208 upper_bounds s) :\n  Sup (f '' s) \u2264 f B :=\ncSup_le (nonempty.image f hs) (h_mono.mem_upper_bounds_image hB)\n\nlemma cInf_image_le {s : set \u03b1} {c : \u03b1} (hcs : c \u2208 s) (h_bdd : bdd_below s) :\n  Inf (f '' s) \u2264 f c :=\n@le_cSup_image (order_dual \u03b1) (order_dual \u03b2) _ _ _ (\u03bb x y hxy, h_mono hxy) _ _ hcs h_bdd\n\nlemma le_cInf_image {s : set \u03b1} (hs : s.nonempty) {B : \u03b1} (hB: B \u2208 lower_bounds s) :\n  f B \u2264 Inf (f '' s) :=\n@cSup_image_le (order_dual \u03b1) (order_dual \u03b2) _ _ _ (\u03bb x y hxy, h_mono hxy) _ hs _ hB\n\nend monotone\n\nnamespace galois_connection\n\nvariables {\u03b3 : Type*} [conditionally_complete_lattice \u03b1] [conditionally_complete_lattice \u03b2]\n  [nonempty \u03b9] {l : \u03b1 \u2192 \u03b2} {u : \u03b2 \u2192 \u03b1}\n\nlemma l_cSup (gc : galois_connection l u) {s : set \u03b1} (hne : s.nonempty)\n  (hbdd : bdd_above s) :\n  l (Sup s) = \u2a06 x : s, l x :=\neq.symm $ is_lub.csupr_set_eq (gc.is_lub_l_image $ is_lub_cSup hne hbdd) hne\n\nlemma l_cSup' (gc : galois_connection l u) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_above s) :\n  l (Sup s) = Sup (l '' s) :=\nby rw [gc.l_cSup hne hbdd, csupr_set]\n\nlemma l_csupr (gc : galois_connection l u) {f : \u03b9 \u2192 \u03b1}\n  (hf : bdd_above (range f)) :\n  l (\u2a06 i, f i) = \u2a06 i, l (f i) :=\nby rw [supr, gc.l_cSup (range_nonempty _) hf, supr_range']\n\nlemma l_csupr_set (gc : galois_connection l u) {s : set \u03b3} {f : \u03b3 \u2192 \u03b1}\n  (hf : bdd_above (f '' s)) (hne : s.nonempty) :\n  l (\u2a06 i : s, f i) = \u2a06 i : s, l (f i) :=\nby { haveI := hne.to_subtype, rw image_eq_range at hf, exact gc.l_csupr hf }\n\nlemma u_cInf (gc : galois_connection l u) {s : set \u03b2} (hne : s.nonempty)\n  (hbdd : bdd_below s) :\n  u (Inf s) = \u2a05 x : s, u x :=\ngc.dual.l_cSup hne hbdd\n\nlemma u_cInf' (gc : galois_connection l u) {s : set \u03b2} (hne : s.nonempty) (hbdd : bdd_below s) :\n  u (Inf s) = Inf (u '' s) :=\ngc.dual.l_cSup' hne hbdd\n\nlemma u_cinfi (gc : galois_connection l u) {f : \u03b9 \u2192 \u03b2}\n  (hf : bdd_below (range f)) :\n  u (\u2a05 i, f i) = \u2a05 i, u (f i) :=\ngc.dual.l_csupr hf\n\nlemma u_cinfi_set (gc : galois_connection l u) {s : set \u03b3} {f : \u03b3 \u2192 \u03b2}\n  (hf : bdd_below (f '' s)) (hne : s.nonempty) :\n  u (\u2a05 i : s, f i) = \u2a05 i : s, u (f i) :=\ngc.dual.l_csupr_set hf hne\n\nend galois_connection\n\nnamespace order_iso\n\nvariables {\u03b3 : Type*} [conditionally_complete_lattice \u03b1] [conditionally_complete_lattice \u03b2]\n  [nonempty \u03b9]\n\nlemma map_cSup (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_above s) :\n  e (Sup s) = \u2a06 x : s, e x :=\ne.to_galois_connection.l_cSup hne hbdd\n\nlemma map_cSup' (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_above s) :\n  e (Sup s) = Sup (e '' s) :=\ne.to_galois_connection.l_cSup' hne hbdd\n\nlemma map_csupr (e : \u03b1 \u2243o \u03b2) {f : \u03b9 \u2192 \u03b1} (hf : bdd_above (range f)) :\n  e (\u2a06 i, f i) = \u2a06 i, e (f i) :=\ne.to_galois_connection.l_csupr hf\n\nlemma map_csupr_set (e : \u03b1 \u2243o \u03b2) {s : set \u03b3} {f : \u03b3 \u2192 \u03b1}\n  (hf : bdd_above (f '' s)) (hne : s.nonempty) :\n  e (\u2a06 i : s, f i) = \u2a06 i : s, e (f i) :=\ne.to_galois_connection.l_csupr_set hf hne\n\nlemma map_cInf (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_below s) :\n  e (Inf s) = \u2a05 x : s, e x :=\ne.dual.map_cSup hne hbdd\n\nlemma map_cInf' (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_below s) :\n  e (Inf s) = Inf (e '' s) :=\ne.dual.map_cSup' hne hbdd\n\nlemma map_cinfi (e : \u03b1 \u2243o \u03b2) {f : \u03b9 \u2192 \u03b1} (hf : bdd_below (range f)) :\n  e (\u2a05 i, f i) = \u2a05 i, e (f i) :=\ne.dual.map_csupr hf\n\nlemma map_cinfi_set (e : \u03b1 \u2243o \u03b2) {s : set \u03b3} {f : \u03b3 \u2192 \u03b1}\n  (hf : bdd_below (f '' s)) (hne : s.nonempty) :\n  e (\u2a05 i : s, f i) = \u2a05 i : s, e (f i) :=\ne.dual.map_csupr_set hf hne\n\nend order_iso\n\n/-!\n### Relation between `Sup` / `Inf` and `finset.sup'` / `finset.inf'`\n\nLike the `Sup` of a `conditionally_complete_lattice`, `finset.sup'` also requires the set to be\nnon-empty. As a result, we can translate between the two.\n-/\n\nnamespace finset\n\nlemma sup'_eq_cSup_image [conditionally_complete_lattice \u03b2] (s : finset \u03b1) (H) (f : \u03b1 \u2192 \u03b2) :\n  s.sup' H f = Sup (f '' s) :=\nbegin\n  apply le_antisymm,\n  { refine (finset.sup'_le _ _ $ \u03bb a ha, _),\n    refine le_cSup \u27e8s.sup' H f, _\u27e9 \u27e8a, ha, rfl\u27e9,\n    rintros i \u27e8j, hj, rfl\u27e9,\n    exact finset.le_sup' _ hj },\n  { apply cSup_le ((coe_nonempty.mpr H).image _),\n    rintros _ \u27e8a, ha, rfl\u27e9,\n    exact finset.le_sup' _ ha, }\nend\n\nlemma inf'_eq_cInf_image [conditionally_complete_lattice \u03b2] (s : finset \u03b1) (H) (f : \u03b1 \u2192 \u03b2) :\n  s.inf' H f = Inf (f '' s) :=\n@sup'_eq_cSup_image _ (order_dual \u03b2) _ _ _ _\n\nlemma sup'_id_eq_cSup [conditionally_complete_lattice \u03b1] (s : finset \u03b1) (H) :\n  s.sup' H id = Sup s :=\nby rw [sup'_eq_cSup_image s H, set.image_id]\n\nlemma inf'_id_eq_cInf [conditionally_complete_lattice \u03b1] (s : finset \u03b1) (H) :\n  s.inf' H id = Inf s :=\n@sup'_id_eq_cSup (order_dual \u03b1) _ _ _\n\nend finset\n\nsection with_top_bot\n\n/-!\n### Complete lattice structure on `with_top (with_bot \u03b1)`\n\nIf `\u03b1` is a `conditionally_complete_lattice`, then we show that `with_top \u03b1` and `with_bot \u03b1`\nalso inherit the structure of conditionally complete lattices. Furthermore, we show\nthat `with_top (with_bot \u03b1)` naturally inherits the structure of a complete lattice. Note that\nfor \u03b1 a conditionally complete lattice, `Sup` and `Inf` both return junk values\nfor sets which are empty or unbounded. The extension of `Sup` to `with_top \u03b1` fixes\nthe unboundedness problem and the extension to `with_bot \u03b1` fixes the problem with\nthe empty set.\n\nThis result can be used to show that the extended reals [-\u221e, \u221e] are a complete lattice.\n-/\n\nopen_locale classical\n\n/-- Adding a top element to a conditionally complete lattice\ngives a conditionally complete lattice -/\nnoncomputable instance with_top.conditionally_complete_lattice\n  {\u03b1 : Type*} [conditionally_complete_lattice \u03b1] :\n  conditionally_complete_lattice (with_top \u03b1) :=\n{ le_cSup := \u03bb S a hS haS, (with_top.is_lub_Sup' \u27e8a, haS\u27e9).1 haS,\n  cSup_le := \u03bb S a hS haS, (with_top.is_lub_Sup' hS).2 haS,\n  cInf_le := \u03bb S a hS haS, (with_top.is_glb_Inf' hS).1 haS,\n  le_cInf := \u03bb S a hS haS, (with_top.is_glb_Inf' \u27e8a, haS\u27e9).2 haS,\n  ..with_top.lattice,\n  ..with_top.has_Sup,\n  ..with_top.has_Inf }\n\n/-- Adding a bottom element to a conditionally complete lattice\ngives a conditionally complete lattice -/\nnoncomputable instance with_bot.conditionally_complete_lattice\n  {\u03b1 : Type*} [conditionally_complete_lattice \u03b1] :\n  conditionally_complete_lattice (with_bot \u03b1) :=\n{ le_cSup := (@with_top.conditionally_complete_lattice (order_dual \u03b1) _).cInf_le,\n  cSup_le := (@with_top.conditionally_complete_lattice (order_dual \u03b1) _).le_cInf,\n  cInf_le := (@with_top.conditionally_complete_lattice (order_dual \u03b1) _).le_cSup,\n  le_cInf := (@with_top.conditionally_complete_lattice (order_dual \u03b1) _).cSup_le,\n  ..with_bot.lattice,\n  ..with_bot.has_Sup,\n  ..with_bot.has_Inf }\n\nnoncomputable instance with_top.with_bot.complete_lattice {\u03b1 : Type*}\n  [conditionally_complete_lattice \u03b1] : complete_lattice (with_top (with_bot \u03b1)) :=\n{ le_Sup := \u03bb S a haS, (with_top.is_lub_Sup' \u27e8a, haS\u27e9).1 haS,\n  Sup_le := \u03bb S a ha,\n    begin\n      cases S.eq_empty_or_nonempty with h,\n      { show ite _ _ _ \u2264 a,\n        split_ifs,\n        { rw h at h_1, cases h_1 },\n        { convert bot_le, convert with_bot.cSup_empty, rw h, refl },\n        { exfalso, apply h_2, use \u22a5, rw h, rintro b \u27e8\u27e9 } },\n      { refine (with_top.is_lub_Sup' h).2 ha }\n    end,\n  Inf_le := \u03bb S a haS,\n    show ite _ _ _ \u2264 a,\n    begin\n      split_ifs,\n      { cases a with a, exact _root_.le_rfl,\n        cases (h haS); tauto },\n      { cases a,\n        { exact le_top },\n        { apply with_top.some_le_some.2, refine cInf_le _ haS, use \u22a5, intros b hb, exact bot_le } }\n    end,\n  le_Inf := \u03bb S a haS, (with_top.is_glb_Inf' \u27e8a, haS\u27e9).2 haS,\n  ..with_top.has_Inf,\n  ..with_top.has_Sup,\n  ..with_top.bounded_order,\n  ..with_top.lattice }\n\nnoncomputable instance with_top.with_bot.complete_linear_order {\u03b1 : Type*}\n  [conditionally_complete_linear_order \u03b1] : complete_linear_order (with_top (with_bot \u03b1)) :=\n{ .. with_top.with_bot.complete_lattice,\n  .. with_top.linear_order }\n\nend with_top_bot\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/conditionally_complete_lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7061076606580171}}
{"text": "import .missing\n\nopen_locale big_operators\n\nnoncomputable theory\n\n/-!\n# Darboux Integrals in Lean\n\nIn this file, we formalise the theory of Darboux integrals in Lean. Although more general integrals,\nthat is, the Lebesgue and Bochner Integrals have been formalised already, the Darboux Integral has\nnot been formalised yet.\n-/\n\n/-!\n## Dissections\n\nWe start off with the definition of a dissection (or partition) of a closed interval [a, b]. Note\nthat to make definitions simpler, we only assume strict monotonicity, and that x\u2080 = a, x\u2099 = b. This\nmeans that the behaviour outside of [0, n] is undefined.\n-/\n\n/--\nA dissection (or partition) of [a, b] is the sequence a = x\u2080 < x\u2081 < ... < x\u2099 = b\n(Note in this case, we allow x\u2096 where k > n, and this is simply undefined) \n-/\n@[ext]\nstructure dissection (a b : \u211d) :=\n(x : \u2115 \u2192 \u211d)\n(n : \u2115)\n(mono : strict_mono x)\n(hx0 : x 0 = a)\n(hxn : x n = b)\n\nnamespace dissection\n\nvariables {a b : \u211d}\n\nlemma eq_of_x_eq {D D' : dissection a b} (h : D.x = D'.x) : D = D' :=\nbegin\n  ext,\n  { rw h },\n  have h\u2081 := D.hxn,\n  have h\u2082 := D'.hxn,\n  simp_rw [\u2190h\u2082, h] at h\u2081,\n  exact D'.mono.injective h\u2081,\nend\n\n/-!\n## Darboux Sums\n\nWith Dissections defined, we can use them to define Darboux Sums. In this instance, we do not\nrequire the functions to be bounded. This means that the Sup and Inf are not guaranteed to exist,\nhowever, it makes more sense to take in the assumption that the function is bounded later on,\ninstead of passing it into the definition where it is never used.\n-/\n\n/--\nThe lower Darboux sum\n-/\ndef lower_sum (D : dissection a b) (f : \u211d \u2192 \u211d) : \u211d :=\n\u2211 i in finset.range D.n, (D.x (i+1) - D.x i) * Inf (f '' set.Icc (D.x i) (D.x (i + 1)))\n\n/--\nThe upper Darboux Sum\n-/\ndef upper_sum (D : dissection a b) (f : \u211d \u2192 \u211d) : \u211d :=\n\u2211 i in finset.range D.n, (D.x (i+1) - D.x i) * Sup (f '' set.Icc (D.x i) (D.x (i + 1)))\n\nlemma a_le_x (D : dissection a b) (n : \u2115) : a \u2264 D.x n :=\nbegin\n  simp_rw [\u2190D.hx0, D.mono.le_iff_le],\n  exact nat.zero_le _,\nend\n\nlemma x_le_b (D : dissection a b) (i : \u2115) (hi : i \u2264 D.n) : D.x i \u2264 b :=\nbegin\n  simp_rw [\u2190D.hxn, D.mono.le_iff_le],\n  exact hi\nend\n\n/--\nWe can show that for any bounded function f, the lower Darboux sum is less than or equal to the \nupper Darboux sum\n-/\nlemma lower_sum_le_upper_sum (D : dissection a b) {f : \u211d \u2192 \u211d} {k : \u211d} (hf : bounded_within f a b) :\n  D.lower_sum f \u2264 D.upper_sum f :=\nbegin\n  unfold lower_sum upper_sum,\n  apply finset.sum_le_sum,\n  rcases hf with \u27e8k, hf\u27e9,\n  intros i hi,\n  rw finset.mem_range at hi,\n  rw mul_le_mul_left,\n  { apply real.Inf_le_Sup,\n    { use [f (D.x i), D.x i],\n      exact \u27e8\u27e8le_refl _, (D.mono i.lt_succ_self).le\u27e9, rfl\u27e9 },\n    { use k,\n      rintros y \u27e8x, hx, rfl\u27e9,\n      have xab : x \u2208 set.Icc a b := set.Icc_subset_Icc (a_le_x _ _) (x_le_b _ _ hi) hx,\n      specialize hf x xab,\n      rw abs_lt at hf,\n      exact hf.2.le },\n    { use -k,\n      rintros y \u27e8x, hx, rfl\u27e9,\n      have xab : x \u2208 set.Icc a b := set.Icc_subset_Icc (a_le_x _ _) (x_le_b _ _ hi) hx,\n      specialize hf x xab,\n      rw abs_lt at hf,\n      exact hf.1.le } },\n  { rw sub_pos,\n    apply D.mono,\n    exact i.lt_succ_self }\nend\n\n/--\nAs we did not define a dissection as a set, the definition of a dissection being a refinement of\nanother is slightly different.\n\nWe can say D \u2264 D' to mean D \u2286 D', which in this case means that D' is a refinement of D, In\nparticular, every point in D is in D'.\n-/\ninstance : partial_order (dissection a b) :=\n{ le := \u03bb D D', \u2200 i, \u2203 j, D.x i = D'.x j,\n  le_refl := \n  begin\n    intros D i,\n    use i,\n  end,\n  le_trans := \n  begin\n    intros D D' D'' h\u2081 h\u2082 i,\n    cases h\u2081 i with j hj,\n    cases h\u2082 j with k hk,\n    use k,\n    rw [hj, hk]\n  end,\n  le_antisymm :=\n  begin\n    intros D D' h\u2081 h\u2082,\n    have h\u2083 : set.range D.x = set.range D'.x,\n    { apply set.subset.antisymm,\n      { rintros y \u27e8t, ht\u27e9,\n        cases h\u2081 t,\n        use w,\n        rw [\u2190ht, h] },\n      { rintros y \u27e8t, ht\u27e9,\n        cases h\u2082 t,\n        use w,\n        rw [\u2190ht, h] } },\n    have h\u2084 := eq_of_strict_mono_of_range_eq D.mono D'.mono h\u2083,\n    exact eq_of_x_eq h\u2084,\n  end }\n\n/-!\nNow, we can show that if D' is a refinement of D, then\n\nD.lower_sum \u2264 D'.lower_sum \u2264 D'.upper_sum \u2264 D.upper_sum\n\nWith this, we can take the Inf of all of the upper sums, as the set of all upper sums is bounded\nbelow. In addition, we can take the Sup of the lower sums.\n-/\nlemma upper_sum_mono {f : \u211d \u2192 \u211d} (hf : bounded_within f a b) (D D' : dissection a b) \n  (h : D \u2264 D') : D'.upper_sum \u2264 D.upper_sum :=\nbegin\n  sorry\nend\n\nlemma lower_sum_mono {f : \u211d \u2192 \u211d} (hf : bounded_within f a b) (D D' : dissection a b) \n  (h : D \u2264 D') : D.lower_sum \u2264 D'.lower_sum :=\nbegin\n  sorry\nend\n\n-- Todo: flesh out \u2264 API\n-- Todo: define the dissection D \u222a D', as it's useful for a few proofs\nend dissection\n\nsection integrals\n\nvariables (f : \u211d \u2192 \u211d) (a b : \u211d)\n\n/-!\n# Lower and Upper Integrals\n\nWe can now define the Lower and Upper Integrals, by taking the Sup/Inf as appropriate. Note here\nthat we do not require f to be bounded in the definition, instead we take the approach of totalising\nthese, and allowing for junk output for unbounded functions\n-/\ndef lower_integral : \u211d := Sup { x | \u2203 D : dissection a b, D.lower_sum f = x }\ndef upper_integral : \u211d := Inf { x | \u2203 D : dissection a b, D.upper_sum f = x }\n\n-- Todo: show Inf/Sup exists (ie bounded, nonempty)\n\n/-!\n# Integrable\n\nFinally, we can define what it means for a function to be integrable. We say that a function f is\nDarboux Integrable if the lower and upper integrals are the same.\n-/\ndef integrable : Prop := lower_integral f a b = upper_integral f a b\n\nend integrals\n\nsection integrable\n\nvariables {a b : \u211d}\n\n/-- \nAny monotone function is integrable. Note here `monotone` means monotonically increasing.\n-/\nlemma integrable_of_monotone_of_bounded {f : \u211d \u2192 \u211d} (hfm : monotone f) \n  (hfb : bounded_within f a b) : integrable f a b := sorry\n\n/--\nAny continouous function is integrable.\n-/\nlemma integrable_of_continuous_of_bounded {f : \u211d \u2192 \u211d} (hfm : monotone f) \n  (hfb : bounded_within f a b) : integrable f a b := sorry\n\nlemma integrable.const (c : \u211d) : integrable (\u03bb x, c) a b := sorry\n\nlemma integrable.add {f g : \u211d \u2192 \u211d} (hf : integrable f a b) (hg : integrable g a b) :\n  integrable (f + g) a b := sorry\n\nlemma integrable.abs {f g : \u211d \u2192 \u211d} (hf : integrable f a b) : integrable (abs \u2218 f) a b := sorry\n\nlemma integrable.mul {f g : \u211d \u2192 \u211d} (hf : integrable f a b) (hg : integrable g a b) :\n  integrable (f * g) a b := sorry\n\nend integrable\n", "meta": {"author": "shingtaklam1324", "repo": "darboux", "sha": "1db362ad8a5c36f20a5784ae8663113da8976750", "save_path": "github-repos/lean/shingtaklam1324-darboux", "path": "github-repos/lean/shingtaklam1324-darboux/darboux-1db362ad8a5c36f20a5784ae8663113da8976750/src/darboux.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7061076560438537}}
{"text": "/-\nCopyright (c) 2022 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport data.W.cardinal\nimport ring_theory.algebraic_independent\nimport field_theory.is_alg_closed.basic\nimport field_theory.intermediate_field\nimport data.polynomial.cardinal\nimport data.mv_polynomial.cardinal\nimport data.zmod.algebra\n/-!\n# Classification of Algebraically closed fields\n\nThis file contains results related to classifying algebraically closed fields.\n\n## Main statements\n\n* `is_alg_closed.equiv_of_transcendence_basis` Two fields with the same characteristic and the same\n  cardinality of transcendence basis are isomorphic.\n* `is_alg_closed.ring_equiv_of_cardinal_eq_of_char_eq` Two uncountable algebraically closed fields\n  are isomorphic if they have the same characteristic and the same cardinality.\n-/\nuniverse u\n\nopen_locale cardinal polynomial\nopen cardinal\n\nsection algebraic_closure\n\nnamespace algebra.is_algebraic\n\nvariables (R L : Type u) [comm_ring R] [comm_ring L] [is_domain L] [algebra R L]\nvariables [no_zero_smul_divisors R L] (halg : algebra.is_algebraic R L)\n\nlemma cardinal_mk_le_sigma_polynomial :\n  #L \u2264 #(\u03a3 p : R[X], { x : L // x \u2208 (p.map (algebra_map R L)).roots }) :=\n@mk_le_of_injective L (\u03a3 p : R[X], { x : L | x \u2208 (p.map (algebra_map R L)).roots })\n  (\u03bb x : L, let p := classical.indefinite_description _ (halg x) in\n    \u27e8p.1, x,\n      begin\n      dsimp,\n      have h : p.1.map (algebra_map R L) \u2260 0,\n      { rw [ne.def, \u2190 polynomial.degree_eq_bot, polynomial.degree_map_eq_of_injective\n          (no_zero_smul_divisors.algebra_map_injective R L), polynomial.degree_eq_bot],\n        exact p.2.1 },\n      erw [polynomial.mem_roots h, polynomial.is_root, polynomial.eval_map,\n        \u2190 polynomial.aeval_def, p.2.2],\n      end\u27e9) (\u03bb x y, begin\n    intro h,\n    simp only at h,\n    refine (subtype.heq_iff_coe_eq _).1 h.2,\n    simp only [h.1, iff_self, forall_true_iff]\n  end)\n\n/--The cardinality of an algebraic extension is at most the maximum of the cardinality\nof the base ring or `\u03c9` -/\nlemma cardinal_mk_le_max : #L \u2264 max (#R) \u03c9 :=\ncalc #L \u2264 #(\u03a3 p : R[X], { x : L // x \u2208 (p.map (algebra_map R L)).roots }) :\n  cardinal_mk_le_sigma_polynomial R L halg\n... = cardinal.sum (\u03bb p : R[X], #{ x : L | x \u2208 (p.map (algebra_map R L)).roots }) :\n  by rw \u2190 mk_sigma; refl\n... \u2264 cardinal.sum.{u u} (\u03bb p : R[X], \u03c9) : sum_le_sum _ _\n  (\u03bb p, le_of_lt begin\n    rw [lt_omega_iff_finite],\n    classical,\n    simp only [\u2190 @multiset.mem_to_finset _ _ _ (p.map (algebra_map R L)).roots],\n    exact set.finite_mem_finset _,\n  end)\n... = #R[X] * \u03c9 : sum_const' _ _\n... \u2264 max (max (#R[X]) \u03c9) \u03c9 : mul_le_max _ _\n... \u2264 max (max (max (#R) \u03c9) \u03c9) \u03c9 :\n  max_le_max (max_le_max polynomial.cardinal_mk_le_max le_rfl) le_rfl\n... = max (#R) \u03c9 : by simp only [max_assoc, max_comm omega.{u}, max_left_comm omega.{u}, max_self]\n\nend algebra.is_algebraic\n\nend algebraic_closure\n\nnamespace is_alg_closed\n\nsection classification\n\nnoncomputable theory\n\nvariables {R L K : Type*} [comm_ring R]\nvariables [field K] [algebra R K]\nvariables [field L] [algebra R L]\nvariables {\u03b9 : Type*} (v : \u03b9 \u2192 K)\nvariables {\u03ba : Type*} (w : \u03ba \u2192 L)\n\nvariables (hv : algebraic_independent R v)\n\nlemma is_alg_closure_of_transcendence_basis [is_alg_closed K] (hv : is_transcendence_basis R v) :\n  is_alg_closure (algebra.adjoin R (set.range v)) K :=\nby letI := ring_hom.domain_nontrivial (algebra_map R K); exact\n{ alg_closed := by apply_instance,\n  algebraic := hv.is_algebraic }\n\nvariables (hw : algebraic_independent R w)\n\n/-- setting `R` to be `zmod (ring_char R)` this result shows that if two algebraically\nclosed fields have equipotent transcendence bases and the same characteristic then they are\nisomorphic. -/\ndef equiv_of_transcendence_basis [is_alg_closed K] [is_alg_closed L] (e : \u03b9 \u2243 \u03ba)\n  (hv : is_transcendence_basis R v) (hw : is_transcendence_basis R w) : K \u2243+* L :=\nbegin\n  letI := is_alg_closure_of_transcendence_basis v hv;\n  letI := is_alg_closure_of_transcendence_basis w hw;\n  have e : algebra.adjoin R (set.range v) \u2243+* algebra.adjoin R (set.range w),\n  { refine hv.1.aeval_equiv.symm.to_ring_equiv.trans _,\n    refine (alg_equiv.of_alg_hom\n      (mv_polynomial.rename e)\n      (mv_polynomial.rename e.symm)\n      _ _).to_ring_equiv.trans _,\n    { ext, simp },\n    { ext, simp },\n    exact hw.1.aeval_equiv.to_ring_equiv },\n  exact is_alg_closure.equiv_of_equiv K L e\nend\n\nend classification\n\nsection cardinal\n\nvariables {R L K : Type u} [comm_ring R]\nvariables [field K] [algebra R K] [is_alg_closed K]\nvariables {\u03b9 : Type u} (v : \u03b9 \u2192 K)\nvariable (hv : is_transcendence_basis R v)\n\nlemma cardinal_le_max_transcendence_basis (hv : is_transcendence_basis R v) :\n  #K \u2264 max (max (#R) (#\u03b9)) \u03c9 :=\ncalc #K \u2264 max (#(algebra.adjoin R (set.range v))) \u03c9 :\n  by letI := is_alg_closure_of_transcendence_basis v hv;\n   exact algebra.is_algebraic.cardinal_mk_le_max _ _ is_alg_closure.algebraic\n... = max (#(mv_polynomial \u03b9 R)) \u03c9 : by rw [cardinal.eq.2 \u27e8(hv.1.aeval_equiv).to_equiv\u27e9]\n... \u2264 max (max (max (#R) (#\u03b9)) \u03c9) \u03c9 : max_le_max mv_polynomial.cardinal_mk_le_max le_rfl\n... = _ : by simp [max_assoc]\n\n/-- If `K` is an uncountable algebraically closed field, then its\ncardinality is the same as that of a transcendence basis. -/\nlemma cardinal_eq_cardinal_transcendence_basis_of_omega_lt [nontrivial R]\n  (hv : is_transcendence_basis R v) (hR : #R \u2264 \u03c9) (hK : \u03c9 < #K) : #K = #\u03b9 :=\nhave \u03c9 \u2264 #\u03b9,\n  from le_of_not_lt (\u03bb h,\n    not_le_of_gt hK $ calc\n      #K \u2264 max (max (#R) (#\u03b9)) \u03c9 : cardinal_le_max_transcendence_basis v hv\n     ... \u2264 _ : max_le (max_le hR (le_of_lt h)) le_rfl),\nle_antisymm\n  (calc #K \u2264 max (max (#R) (#\u03b9)) \u03c9 : cardinal_le_max_transcendence_basis v hv\n       ... = #\u03b9 : begin\n         rw [max_eq_left, max_eq_right],\n         { exact le_trans hR this },\n         { exact le_max_of_le_right this }\n       end)\n  (mk_le_of_injective (show function.injective v, from hv.1.injective))\n\nend cardinal\n\nvariables {K L : Type} [field K] [field L] [is_alg_closed K] [is_alg_closed L]\n\n/-- Two uncountable algebraically closed fields of characteristic zero are isomorphic\nif they have the same cardinality. -/\n@[nolint def_lemma] lemma ring_equiv_of_cardinal_eq_of_char_zero [char_zero K] [char_zero L]\n  (hK : \u03c9 < #K) (hKL : #K = #L) : K \u2243+* L :=\nbegin\n  apply classical.choice,\n  cases exists_is_transcendence_basis \u2124\n    (show function.injective (algebra_map \u2124 K),\n      from int.cast_injective) with s hs,\n  cases exists_is_transcendence_basis \u2124\n    (show function.injective (algebra_map \u2124 L),\n      from int.cast_injective) with t ht,\n  have : #s = #t,\n  { rw [\u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ hs (le_of_eq mk_int) hK,\n        \u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ ht (le_of_eq mk_int), hKL],\n    rwa \u2190 hKL },\n  cases cardinal.eq.1 this with e,\n  exact \u27e8equiv_of_transcendence_basis _ _ e hs ht\u27e9\nend\n\nprivate lemma ring_equiv_of_cardinal_eq_of_char_p (p : \u2115) [fact p.prime]\n  [char_p K p] [char_p L p] (hK : \u03c9 < #K) (hKL : #K = #L) : K \u2243+* L :=\nbegin\n  apply classical.choice,\n  cases exists_is_transcendence_basis (zmod p)\n    (show function.injective (algebra_map (zmod p) K),\n      from ring_hom.injective _) with s hs,\n  cases exists_is_transcendence_basis (zmod p)\n    (show function.injective (algebra_map (zmod p) L),\n      from ring_hom.injective _) with t ht,\n  have : #s = #t,\n  { rw [\u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ hs\n      (le_of_lt $ lt_omega_iff_fintype.2 \u27e8infer_instance\u27e9) hK,\n        \u2190 cardinal_eq_cardinal_transcendence_basis_of_omega_lt _ ht\n      (le_of_lt $ lt_omega_iff_fintype.2 \u27e8infer_instance\u27e9), hKL],\n    rwa \u2190 hKL },\n  cases cardinal.eq.1 this with e,\n  exact \u27e8equiv_of_transcendence_basis _ _ e hs ht\u27e9\nend\n\n/-- Two uncountable algebraically closed fields are isomorphic\nif they have the same cardinality and the same characteristic. -/\n@[nolint def_lemma] lemma ring_equiv_of_cardinal_eq_of_char_eq (p : \u2115) [char_p K p] [char_p L p]\n  (hK : \u03c9 < #K) (hKL : #K = #L) : K \u2243+* L :=\nbegin\n  apply classical.choice,\n  rcases char_p.char_is_prime_or_zero K p with hp | hp,\n  { haveI : fact p.prime := \u27e8hp\u27e9,\n    exact \u27e8ring_equiv_of_cardinal_eq_of_char_p p hK hKL\u27e9 },\n  { rw [hp] at *,\n    resetI,\n    letI : char_zero K := char_p.char_p_to_char_zero K,\n    letI : char_zero L := char_p.char_p_to_char_zero L,\n    exact \u27e8ring_equiv_of_cardinal_eq_of_char_zero hK hKL\u27e9 }\nend\n\nend is_alg_closed\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/field_theory/is_alg_closed/classification.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7061076523741346}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Morenikeji Neri\n-/\nimport ring_theory.noetherian\nimport ring_theory.unique_factorization_domain\n/-!\n# Principal ideal rings and principal ideal domains\n\nA principal ideal ring (PIR) is a commutative ring in which all ideals are principal. A\nprincipal ideal domain (PID) is an integral domain which is a principal ideal ring.\n\n# Main definitions\n\nNote that for principal ideal domains, one should use\n`[integral domain R] [is_principal_ideal_ring R]`. There is no explicit definition of a PID.\nTheorems about PID's are in the `principal_ideal_ring` namespace.\n\n- `is_principal_ideal_ring`: a predicate on commutative rings, saying that every\n  ideal is principal.\n- `generator`: a generator of a principal ideal (or more generally submodule)\n- `to_unique_factorization_monoid`: a PID is a unique factorization domain\n\n# Main results\n\n- `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.\n- `euclidean_domain.to_principal_ideal_domain` : a Euclidean domain is a PID.\n\n-/\nuniverses u v\nvariables {R : Type u} {M : Type v}\n\nopen set function\nopen submodule\nopen_locale classical\n\n/-- An `R`-submodule of `M` is principal if it is generated by one element. -/\nclass submodule.is_principal [ring R] [add_comm_group M] [module R M] (S : submodule R M) : Prop :=\n(principal [] : \u2203 a, S = span R {a})\n\n/-- A commutative ring is a principal ideal ring if all ideals are principal. -/\nclass is_principal_ideal_ring (R : Type u) [comm_ring R] : Prop :=\n(principal : \u2200 (S : ideal R), S.is_principal)\n\nattribute [instance] is_principal_ideal_ring.principal\n\nnamespace submodule.is_principal\n\nvariables [comm_ring R] [add_comm_group M] [module R M]\n\n/-- `generator I`, if `I` is a principal submodule, is an `x \u2208 M` such that `span R {x} = I` -/\nnoncomputable def generator (S : submodule R M) [S.is_principal] : M :=\nclassical.some (principal S)\n\nlemma span_singleton_generator (S : submodule R M) [S.is_principal] : span R {generator S} = S :=\neq.symm (classical.some_spec (principal S))\n\n@[simp] lemma generator_mem (S : submodule R M) [S.is_principal] : generator S \u2208 S :=\nby { conv_rhs { rw \u2190 span_singleton_generator S }, exact subset_span (mem_singleton _) }\n\nlemma mem_iff_eq_smul_generator (S : submodule R M) [S.is_principal] {x : M} :\n  x \u2208 S \u2194 \u2203 s : R, x = s \u2022 generator S :=\nby simp_rw [@eq_comm _ x, \u2190 mem_span_singleton, span_singleton_generator]\n\nlemma mem_iff_generator_dvd (S : ideal R) [S.is_principal] {x : R} : x \u2208 S \u2194 generator S \u2223 x :=\n(mem_iff_eq_smul_generator S).trans (exists_congr (\u03bb a, by simp only [mul_comm, smul_eq_mul]))\n\nlemma eq_bot_iff_generator_eq_zero (S : submodule R M) [S.is_principal] :\n  S = \u22a5 \u2194 generator S = 0 :=\nby rw [\u2190 @span_singleton_eq_bot R M, span_singleton_generator]\n\nlemma prime_generator_of_is_prime (S : ideal R) [submodule.is_principal S] [is_prime : S.is_prime]\n  (ne_bot : S \u2260 \u22a5) :\n  prime (generator S) :=\n\u27e8\u03bb h, ne_bot ((eq_bot_iff_generator_eq_zero S).2 h),\n \u03bb h, is_prime.ne_top (S.eq_top_of_is_unit_mem (generator_mem S) h),\n by simpa only [\u2190 mem_iff_generator_dvd S] using is_prime.2\u27e9\n\nend submodule.is_principal\n\nnamespace is_prime\nopen submodule.is_principal ideal\n\n-- TODO -- for a non-ID one could perhaps prove that if p < q are prime then q maximal;\n-- 0 isn't prime in a non-ID PIR but the Krull dimension is still <= 1.\n-- The below result follows from this, but we could also use the below result to\n-- prove this (quotient out by p).\nlemma to_maximal_ideal [integral_domain R] [is_principal_ideal_ring R] {S : ideal R}\n  [hpi : is_prime S] (hS : S \u2260 \u22a5) : is_maximal S :=\nis_maximal_iff.2 \u27e8(ne_top_iff_one S).1 hpi.1, begin\n  assume T x hST hxS hxT,\n  cases (mem_iff_generator_dvd _).1 (hST $ generator_mem S) with z hz,\n  cases hpi.mem_or_mem (show generator T * z \u2208 S, from hz \u25b8 generator_mem S),\n  { have hTS : T \u2264 S, rwa [\u2190 span_singleton_generator T, submodule.span_le, singleton_subset_iff],\n    exact (hxS $ hTS hxT).elim },\n  cases (mem_iff_generator_dvd _).1 h with y hy,\n  have : generator S \u2260 0 := mt (eq_bot_iff_generator_eq_zero _).2 hS,\n  rw [\u2190 mul_one (generator S), hy, mul_left_comm, mul_right_inj' this] at hz,\n  exact hz.symm \u25b8 T.mul_mem_right _ (generator_mem T)\nend\u27e9\n\nend is_prime\n\nsection\nopen euclidean_domain\nvariable [euclidean_domain R]\n\nlemma mod_mem_iff {S : ideal R} {x y : R} (hy : y \u2208 S) : x % y \u2208 S \u2194 x \u2208 S :=\n\u27e8\u03bb hxy, div_add_mod x y \u25b8 S.add_mem (S.mul_mem_right _ hy) hxy,\n  \u03bb hx, (mod_eq_sub_mul_div x y).symm \u25b8 S.sub_mem hx (S.mul_mem_right _ hy)\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance euclidean_domain.to_principal_ideal_domain : is_principal_ideal_ring R :=\n{ principal := \u03bb S, by exactI\n    \u27e8if h : {x : R | x \u2208 S \u2227 x \u2260 0}.nonempty\n    then\n    have wf : well_founded (euclidean_domain.r : R \u2192 R \u2192 Prop) := euclidean_domain.r_well_founded,\n    have hmin : well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h \u2208 S \u2227\n        well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h \u2260 0,\n      from well_founded.min_mem wf {x : R | x \u2208 S \u2227 x \u2260 0} h,\n    \u27e8well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h,\n      submodule.ext $ \u03bb x,\n      \u27e8\u03bb hx, div_add_mod x (well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h) \u25b8\n        (ideal.mem_span_singleton.2 $ dvd_add (dvd_mul_right _ _) $\n        have (x % (well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h) \u2209 {x : R | x \u2208 S \u2227 x \u2260 0}),\n          from \u03bb h\u2081, well_founded.not_lt_min wf _ h h\u2081 (mod_lt x hmin.2),\n        have x % well_founded.min wf {x : R | x \u2208 S \u2227 x \u2260 0} h = 0,\n          by finish [(mod_mem_iff hmin.1).2 hx],\n        by simp *),\n      \u03bb hx, let \u27e8y, hy\u27e9 := ideal.mem_span_singleton.1 hx in hy.symm \u25b8 S.mul_mem_right _ hmin.1\u27e9\u27e9\n    else \u27e80, submodule.ext $ \u03bb a,\n           by rw [\u2190 @submodule.bot_coe R R _ _ _, span_eq, submodule.mem_bot];\n      exact \u27e8\u03bb haS, by_contradiction $ \u03bb ha0, h \u27e8a, \u27e8haS, ha0\u27e9\u27e9, \u03bb h\u2081, h\u2081.symm \u25b8 S.zero_mem\u27e9\u27e9\u27e9 }\nend\n\nnamespace principal_ideal_ring\nopen is_principal_ideal_ring\n\nvariables [integral_domain R] [is_principal_ideal_ring R]\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_noetherian_ring : is_noetherian_ring R :=\nis_noetherian_ring_iff.2 \u27e8assume s : ideal R,\nbegin\n  rcases (is_principal_ideal_ring.principal s).principal with \u27e8a, rfl\u27e9,\n  rw [\u2190 finset.coe_singleton],\n  exact \u27e8{a}, set_like.coe_injective rfl\u27e9\nend\u27e9\n\nlemma is_maximal_of_irreducible {p : R} (hp : irreducible p) :\n  ideal.is_maximal (span R ({p} : set R)) :=\n\u27e8\u27e8mt ideal.span_singleton_eq_top.1 hp.1, \u03bb I hI, begin\n  rcases principal I with \u27e8a, rfl\u27e9,\n  erw ideal.span_singleton_eq_top,\n  unfreezingI { rcases ideal.span_singleton_le_span_singleton.1 (le_of_lt hI) with \u27e8b, rfl\u27e9 },\n  refine (of_irreducible_mul hp).resolve_right (mt (\u03bb hb, _) (not_le_of_lt hI)),\n  erw [ideal.span_singleton_le_span_singleton, is_unit.mul_right_dvd hb]\nend\u27e9\u27e9\n\nlemma irreducible_iff_prime {p : R} : irreducible p \u2194 prime p :=\n\u27e8\u03bb hp, (ideal.span_singleton_prime hp.ne_zero).1 $\n    (is_maximal_of_irreducible hp).is_prime,\n  irreducible_of_prime\u27e9\n\nlemma associates_irreducible_iff_prime : \u2200{p : associates R}, irreducible p \u2194 prime p :=\nassociates.irreducible_iff_prime_iff.1 (\u03bb _, irreducible_iff_prime)\n\nsection\nopen_locale classical\n\n/-- `factors a` is a multiset of irreducible elements whose product is `a`, up to units -/\nnoncomputable def factors (a : R) : multiset R :=\nif h : a = 0 then \u2205 else classical.some (wf_dvd_monoid.exists_factors a h)\n\nlemma factors_spec (a : R) (h : a \u2260 0) :\n  (\u2200b\u2208factors a, irreducible b) \u2227 associated (factors a).prod a :=\nbegin\n  unfold factors, rw [dif_neg h],\n  exact classical.some_spec (wf_dvd_monoid.exists_factors a h)\nend\n\nlemma ne_zero_of_mem_factors {R : Type v} [integral_domain R] [is_principal_ideal_ring R] {a b : R}\n  (ha : a \u2260 0) (hb : b \u2208 factors a) : b \u2260 0 := irreducible.ne_zero ((factors_spec a ha).1 b hb)\n\nlemma mem_submonoid_of_factors_subset_of_units_subset (s : submonoid R)\n  {a : R} (ha : a \u2260 0) (hfac : \u2200 b \u2208 factors a, b \u2208 s) (hunit : \u2200 c : units R, (c : R) \u2208 s) :\n  a \u2208 s :=\nbegin\n  rcases ((factors_spec a ha).2) with \u27e8c, hc\u27e9,\n  rw [\u2190 hc],\n  exact submonoid.mul_mem _ (submonoid.multiset_prod_mem _ _ hfac) (hunit _),\nend\n\n/-- If a `ring_hom` maps all units and all factors of an element `a` into a submonoid `s`, then it\nalso maps `a` into that submonoid. -/\nlemma ring_hom_mem_submonoid_of_factors_subset_of_units_subset {R S : Type*}\n  [integral_domain R] [is_principal_ideal_ring R] [semiring S]\n  (f : R \u2192+* S) (s : submonoid S) (a : R) (ha : a \u2260 0)\n  (h : \u2200 b \u2208 factors a, f b \u2208 s) (hf: \u2200 c : units R, f c \u2208 s) :\n  f a \u2208 s :=\nmem_submonoid_of_factors_subset_of_units_subset (s.comap f.to_monoid_hom) ha h hf\n\n/-- A principal ideal domain has unique factorization -/\n@[priority 100] -- see Note [lower instance priority]\ninstance to_unique_factorization_monoid : unique_factorization_monoid R :=\n{ irreducible_iff_prime := \u03bb _, principal_ideal_ring.irreducible_iff_prime\n  .. (is_noetherian_ring.wf_dvd_monoid : wf_dvd_monoid R) }\n\nend\n\nend principal_ideal_ring\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/principal_ideal_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7061076482321932}}
{"text": "/-\nCopyright (c) 2021 Alena Gusakov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alena Gusakov\n-/\nimport combinatorics.simple_graph.basic\nimport data.set.finite\n/-!\n# Strongly regular graphs\n\n## Main definitions\n\n* `G.is_SRG_of n k l m` (see `is_simple_graph.is_SRG_of`) is a structure for a `simple_graph`\n  satisfying the following conditions:\n  * The cardinality of the vertex set is `n`\n  * `G` is a regular graph with degree `k`\n  * The number of common neighbors between any two adjacent vertices in `G` is `l`\n  * The number of common neighbors between any two nonadjacent vertices in `G` is `m`\n\n## TODO\n- Prove that the complement of a strongly regular graph is strongly regular with parameters\n  `is_SRG_of n (n - k - 1) (n - 2 - 2k + m) (v - 2k + l)`\n- Prove that the parameters of a strongly regular graph\n  obey the relation `(n - k - 1) * m = k * (k - l - 1)`\n- Prove that if `I` is the identity matrix and `J` is the all-one matrix,\n  then the adj matrix `A` of SRG obeys relation `A^2 = kI + lA + m(J - I - A)`\n-/\n\nuniverses u\n\nnamespace simple_graph\nvariables {V : Type u}\nvariables (G : simple_graph V) [decidable_rel G.adj]\n\nvariables [fintype V] [decidable_eq V]\n\n/--\nA graph is strongly regular with parameters `n k l m` if\n * its vertex set has cardinality `n`\n * it is regular with degree `k`\n * every pair of adjacent vertices has `l` common neighbors\n * every pair of nonadjacent vertices has `m` common neighbors\n-/\nstructure is_SRG_of (n k l m : \u2115) : Prop :=\n(card : fintype.card V = n)\n(regular : G.is_regular_of_degree k)\n(adj_common : \u2200 (v w : V), G.adj v w \u2192 fintype.card (G.common_neighbors v w) = l)\n(nadj_common : \u2200 (v w : V), \u00ac G.adj v w \u2227 v \u2260 w \u2192 fintype.card (G.common_neighbors v w) = m)\n\nopen finset\n\n/-- Complete graphs are strongly regular. Note that the parameter `m` can take any value\n  for complete graphs, since there are no distinct pairs of nonadjacent vertices. -/\nlemma complete_strongly_regular (m : \u2115) :\n  (\u22a4 : simple_graph V).is_SRG_of (fintype.card V) (fintype.card V - 1) (fintype.card V - 2) m :=\n{ card := rfl,\n  regular := complete_graph_degree,\n  adj_common := \u03bb v w (h : v \u2260 w),\n    begin\n      simp only [fintype.card_of_finset, mem_common_neighbors, filter_not, \u2190not_or_distrib,\n                 filter_eq, filter_or, card_univ_diff, mem_univ, if_pos, \u2190insert_eq, top_adj],\n      rw [card_insert_of_not_mem, card_singleton],\n      simp [h]\n    end,\n  nadj_common := \u03bb v w (h : \u00ac(v \u2260 w) \u2227 _), (h.1 h.2).elim }\n\nend simple_graph\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/combinatorics/simple_graph/strongly_regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7061076463433047}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Johan Commelin\n\n! This file was ported from Lean 3 source module ring_theory.free_ring\n! leanprover-community/mathlib commit d6814c584384ddf2825ff038e868451a7c956f31\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.GroupTheory.FreeAbelianGroup\n\n/-!\n# Free rings\n\nThe theory of the free ring over a type.\n\n## Main definitions\n\n* `FreeRing \u03b1` : the free (not commutative in general) ring over a type.\n* `lift (f : \u03b1 \u2192 R)` : the ring hom `FreeRing \u03b1 \u2192+* R` induced by `f`.\n* `map (f : \u03b1 \u2192 \u03b2)` : the ring hom `FreeRing \u03b1 \u2192+* FreeRing \u03b2` induced by `f`.\n\n## Implementation details\n\n`FreeRing \u03b1` is implemented as the free abelian group over the free monoid on `\u03b1`.\n\n## Tags\n\nfree ring\n\n-/\n\n\nuniverse u v\n\n/-- The free ring over a type `\u03b1`. -/\ndef FreeRing (\u03b1 : Type u) : Type u :=\n  FreeAbelianGroup <| FreeMonoid \u03b1\n#align free_ring FreeRing\n\ninstance (\u03b1 : Type u) : Ring (FreeRing \u03b1) :=\n  FreeAbelianGroup.ring _\n\ninstance (\u03b1 : Type u) : Inhabited (FreeRing \u03b1) := by\n  dsimp only [FreeRing]\n  infer_instance\n\nnamespace FreeRing\n\nvariable {\u03b1 : Type u}\n\n/-- The canonical map from \u03b1 to `FreeRring \u03b1`. -/\ndef of (x : \u03b1) : FreeRing \u03b1 :=\n  FreeAbelianGroup.of (FreeMonoid.of x)\n#align free_ring.of FreeRing.of\n\ntheorem of_injective : Function.Injective (of : \u03b1 \u2192 FreeRing \u03b1) :=\n  FreeAbelianGroup.of_injective.comp FreeMonoid.of_injective\n#align free_ring.of_injective FreeRing.of_injective\n\n@[elab_as_elim]\nprotected theorem induction_on {C : FreeRing \u03b1 \u2192 Prop} (z : FreeRing \u03b1) (hn1 : C (-1))\n    (hb : \u2200 b, C (of b)) (ha : \u2200 x y, C x \u2192 C y \u2192 C (x + y)) (hm : \u2200 x y, C x \u2192 C y \u2192 C (x * y)) :\n    C z :=\n  have hn : \u2200 x, C x \u2192 C (-x) := fun x ih => neg_one_mul x \u25b8 hm _ _ hn1 ih\n  have h1 : C 1 := neg_neg (1 : FreeRing \u03b1) \u25b8 hn _ hn1\n  FreeAbelianGroup.induction_on z (add_left_neg (1 : FreeRing \u03b1) \u25b8 ha _ _ hn1 h1)\n    (fun m => List.recOn m h1 fun a m ih => by\n      -- porting note: in mathlib, convert was not necessary, `exact hm _ _ (hb a) ih` worked fine\n      convert hm _ _ (hb a) ih\n      rw [of, \u2190 FreeAbelianGroup.of_mul]\n      rfl)\n    (fun m ih => hn _ ih) ha\n#align free_ring.induction_on FreeRing.induction_on\n\nsection lift\n\nvariable {R : Type v} [Ring R] (f : \u03b1 \u2192 R)\n\n/-- The ring homomorphism `FreeRing \u03b1 \u2192+* R` induced from a map `\u03b1 \u2192 R`. -/\ndef lift : (\u03b1 \u2192 R) \u2243 (FreeRing \u03b1 \u2192+* R) :=\n  FreeMonoid.lift.trans FreeAbelianGroup.liftMonoid\n#align free_ring.lift FreeRing.lift\n\n@[simp]\ntheorem lift_of (x : \u03b1) : lift f (of x) = f x :=\n  congr_fun (lift.left_inv f) x\n#align free_ring.lift_of FreeRing.lift_of\n\n@[simp]\ntheorem lift_comp_of (f : FreeRing \u03b1 \u2192+* R) : lift (f \u2218 of) = f :=\n  lift.right_inv f\n#align free_ring.lift_comp_of FreeRing.lift_comp_of\n\n@[ext]\ntheorem hom_ext \u2983f g : FreeRing \u03b1 \u2192+* R\u2984 (h : \u2200 x, f (of x) = g (of x)) : f = g :=\n  lift.symm.injective (funext h)\n#align free_ring.hom_ext FreeRing.hom_ext\n\nend lift\n\nvariable {\u03b2 : Type v} (f : \u03b1 \u2192 \u03b2)\n\n/-- The canonical ring homomorphism `FreeRing \u03b1 \u2192+* FreeRing \u03b2` generated by a map `\u03b1 \u2192 \u03b2`. -/\ndef map : FreeRing \u03b1 \u2192+* FreeRing \u03b2 :=\n  lift <| of \u2218 f\n#align free_ring.map FreeRing.map\n\n@[simp]\ntheorem map_of (x : \u03b1) : map f (of x) = of (f x) :=\n  lift_of _ _\n#align free_ring.map_of FreeRing.map_of\n\nend FreeRing\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/FreeRing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7061076412569188}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_484 :\n  real.log 27 / real.log 3 = 3 :=\nbegin\n  rw real.log_div_log,\n  have three_to_three : (27 : \u211d) = (3 : \u211d)^(3 : \u211d), by norm_num,\n  rw three_to_three,\n  have trivial_ineq: (0 : \u211d) < (3 : \u211d), by norm_num,\n  have trivial_neq: (3: \u211d) \u2260 (1 : \u211d), by norm_num,\n  exact real.logb_rpow trivial_ineq trivial_neq,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p484.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.7061070941120663}}
{"text": "section\n  variables x y : \u2115\n\n  def double := x + x\n\n  #check double y\n  #check double (2 * x)\n\n  theorem t1 : double (x + y) = double x + double y :=\n    by simp [double, add_left_comm]\n\n  #check t1 y\n  #check t1 (2 * x)\n\n  theorem t2 : double (x * y) = double x * y :=\n    by simp [double, add_mul]\nend\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch6/ex0201.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7060976558362606}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n-/\n\nimport analysis.inner_product_space.projection\nimport measure_theory.function.l2_space\nimport measure_theory.function.ae_eq_of_integral\n\n/-! # Conditional expectation\n\nWe build the conditional expectation of an integrable function `f` with value in a Banach space\nwith respect to a measure `\u03bc` (defined on a measurable space structure `m0`) and a measurable space\nstructure `m` with `hm : m \u2264 m0` (a sub-sigma-algebra). This is an `m`-strongly measurable\nfunction `\u03bc[f|hm]` which is integrable and verifies `\u222b x in s, \u03bc[f|hm] x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc`\nfor all `m`-measurable sets `s`. It is unique as an element of `L\u00b9`.\n\nThe construction is done in four steps:\n* Define the conditional expectation of an `L\u00b2` function, as an element of `L\u00b2`. This is the\n  orthogonal projection on the subspace of almost everywhere `m`-measurable functions.\n* Show that the conditional expectation of the indicator of a measurable set with finite measure\n  is integrable and define a map `set \u03b1 \u2192 (E \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E))` which to a set associates a linear\n  map. That linear map sends `x \u2208 E` to the conditional expectation of the indicator of the set\n  with value `x`.\n* Extend that map to `condexp_L1_clm : (\u03b1 \u2192\u2081[\u03bc] E) \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E)`. This is done using the same\n  construction as the Bochner integral (see the file `measure_theory/integral/set_to_L1`).\n* Define the conditional expectation of a function `f : \u03b1 \u2192 E`, which is an integrable function\n  `\u03b1 \u2192 E` equal to 0 if `f` is not integrable, and equal to an `m`-measurable representative of\n  `condexp_L1_clm` applied to `[f]`, the equivalence class of `f` in `L\u00b9`.\n\n## Main results\n\nThe conditional expectation and its properties\n\n* `condexp (m : measurable_space \u03b1) (\u03bc : measure \u03b1) (f : \u03b1 \u2192 E)`: conditional expectation of `f`\n  with respect to `m`.\n* `integrable_condexp` : `condexp` is integrable.\n* `strongly_measurable_condexp` : `condexp` is `m`-strongly-measurable.\n* `set_integral_condexp (hf : integrable f \u03bc) (hs : measurable_set[m] s)` : if `m \u2264 m0` (the\n  \u03c3-algebra over which the measure is defined), then the conditional expectation verifies\n  `\u222b x in s, condexp m \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc` for any `m`-measurable set `s`.\n\nWhile `condexp` is function-valued, we also define `condexp_L1` with value in `L1` and a continuous\nlinear map `condexp_L1_clm` from `L1` to `L1`. `condexp` should be used in most cases.\n\nUniqueness of the conditional expectation\n\n* `Lp.ae_eq_of_forall_set_integral_eq'`: two `Lp` functions verifying the equality of integrals\n  defining the conditional expectation are equal.\n* `ae_eq_of_forall_set_integral_eq_of_sigma_finite'`: two functions verifying the equality of\n  integrals defining the conditional expectation are equal almost everywhere.\n  Requires `[sigma_finite (\u03bc.trim hm)]`.\n* `ae_eq_condexp_of_forall_set_integral_eq`: an a.e. `m`-measurable function which verifies the\n  equality of integrals is a.e. equal to `condexp`.\n\n## Notations\n\nFor a measure `\u03bc` defined on a measurable space structure `m0`, another measurable space structure\n`m` with `hm : m \u2264 m0` (a sub-\u03c3-algebra) and a function `f`, we define the notation\n* `\u03bc[f|m] = condexp m \u03bc f`.\n\n## Implementation notes\n\nMost of the results in this file are valid for a complete real normed space `F`.\nHowever, some lemmas also use `\ud835\udd5c : is_R_or_C`:\n* `condexp_L2` is defined only for an `inner_product_space` for now, and we use `\ud835\udd5c` for its field.\n* results about scalar multiplication are stated not only for `\u211d` but also for `\ud835\udd5c` if we happen to\n  have `normed_space \ud835\udd5c F`.\n\n## Tags\n\nconditional expectation, conditional expected value\n\n-/\n\nnoncomputable theory\nopen topological_space measure_theory.Lp filter continuous_linear_map\nopen_locale nnreal ennreal topology big_operators measure_theory\n\nnamespace measure_theory\n\n/-- A function `f` verifies `ae_strongly_measurable' m f \u03bc` if it is `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. This is similar to `ae_strongly_measurable`, but the\n`measurable_space` structures used for the measurability statement and for the measure are\ndifferent. -/\ndef ae_strongly_measurable' {\u03b1 \u03b2} [topological_space \u03b2]\n  (m : measurable_space \u03b1) {m0 : measurable_space \u03b1}\n  (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) : Prop :=\n\u2203 g : \u03b1 \u2192 \u03b2, strongly_measurable[m] g \u2227 f =\u1d50[\u03bc] g\n\nnamespace ae_strongly_measurable'\n\nvariables {\u03b1 \u03b2 \ud835\udd5c : Type*} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  [topological_space \u03b2] {f g : \u03b1 \u2192 \u03b2}\n\nlemma congr (hf : ae_strongly_measurable' m f \u03bc) (hfg : f =\u1d50[\u03bc] g) :\n  ae_strongly_measurable' m g \u03bc :=\nby { obtain \u27e8f', hf'_meas, hff'\u27e9 := hf, exact \u27e8f', hf'_meas, hfg.symm.trans hff'\u27e9, }\n\nlemma add [has_add \u03b2] [has_continuous_add \u03b2] (hf : ae_strongly_measurable' m f \u03bc)\n  (hg : ae_strongly_measurable' m g \u03bc) :\n  ae_strongly_measurable' m (f+g) \u03bc :=\nbegin\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9,\n  rcases hg with \u27e8g', h_g'_meas, hgg'\u27e9,\n  exact \u27e8f' + g', h_f'_meas.add h_g'_meas, hff'.add hgg'\u27e9,\nend\n\nlemma neg [add_group \u03b2] [topological_add_group \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (-f) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  refine \u27e8-f', hf'_meas.neg, hf_ae.mono (\u03bb x hx, _)\u27e9,\n  simp_rw pi.neg_apply,\n  rw hx,\nend\n\nlemma sub [add_group \u03b2] [topological_add_group \u03b2] {f g : \u03b1 \u2192 \u03b2}\n  (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  ae_strongly_measurable' m (f - g) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  rcases hgm with \u27e8g', hg'_meas, hg_ae\u27e9,\n  refine \u27e8f'-g', hf'_meas.sub hg'_meas, hf_ae.mp (hg_ae.mono (\u03bb x hx1 hx2, _))\u27e9,\n  simp_rw pi.sub_apply,\n  rw [hx1, hx2],\nend\n\nlemma const_smul [has_smul \ud835\udd5c \u03b2] [has_continuous_const_smul \ud835\udd5c \u03b2]\n  (c : \ud835\udd5c) (hf : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (c \u2022 f) \u03bc :=\nbegin\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9,\n  refine \u27e8c \u2022 f', h_f'_meas.const_smul c, _\u27e9,\n  exact eventually_eq.fun_comp hff' (\u03bb x, c \u2022 x),\nend\n\nlemma const_inner {\ud835\udd5c \u03b2} [is_R_or_C \ud835\udd5c] [normed_add_comm_group \u03b2] [inner_product_space \ud835\udd5c \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) (c : \u03b2) :\n  ae_strongly_measurable' m (\u03bb x, (inner c (f x) : \ud835\udd5c)) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  refine \u27e8\u03bb x, (inner c (f' x) : \ud835\udd5c), (@strongly_measurable_const _ _ m _ _).inner hf'_meas,\n    hf_ae.mono (\u03bb x hx, _)\u27e9,\n  dsimp only,\n  rw hx,\nend\n\n/-- An `m`-strongly measurable function almost everywhere equal to `f`. -/\ndef mk (f : \u03b1 \u2192 \u03b2) (hfm : ae_strongly_measurable' m f \u03bc) : \u03b1 \u2192 \u03b2 := hfm.some\n\nlemma strongly_measurable_mk {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) :\n  strongly_measurable[m] (hfm.mk f) :=\nhfm.some_spec.1\n\nlemma ae_eq_mk {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) : f =\u1d50[\u03bc] hfm.mk f :=\nhfm.some_spec.2\n\nlemma continuous_comp {\u03b3} [topological_space \u03b3] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3}\n  (hg : continuous g) (hf : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (g \u2218 f) \u03bc :=\n\u27e8\u03bb x, g (hf.mk _ x),\n  @continuous.comp_strongly_measurable _ _ _ m _ _ _ _ hg hf.strongly_measurable_mk,\n  hf.ae_eq_mk.mono (\u03bb x hx, by rw [function.comp_apply, hx])\u27e9\n\nend ae_strongly_measurable'\n\nlemma ae_strongly_measurable'_of_ae_strongly_measurable'_trim {\u03b1 \u03b2} {m m0 m0' : measurable_space \u03b1}\n  [topological_space \u03b2] (hm0 : m0 \u2264 m0') {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2}\n  (hf : ae_strongly_measurable' m f (\u03bc.trim hm0)) :\n  ae_strongly_measurable' m f \u03bc :=\nby { obtain \u27e8g, hg_meas, hfg\u27e9 := hf, exact \u27e8g, hg_meas, ae_eq_of_ae_eq_trim hfg\u27e9, }\n\nlemma strongly_measurable.ae_strongly_measurable'\n  {\u03b1 \u03b2} {m m0 : measurable_space \u03b1} [topological_space \u03b2]\n  {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : strongly_measurable[m] f) :\n  ae_strongly_measurable' m f \u03bc :=\n\u27e8f, hf, ae_eq_refl _\u27e9\n\nlemma ae_eq_trim_iff_of_ae_strongly_measurable' {\u03b1 \u03b2} [topological_space \u03b2] [metrizable_space \u03b2]\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f g : \u03b1 \u2192 \u03b2}\n  (hm : m \u2264 m0) (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  hfm.mk f =\u1d50[\u03bc.trim hm] hgm.mk g \u2194 f =\u1d50[\u03bc] g :=\n(ae_eq_trim_iff hm hfm.strongly_measurable_mk hgm.strongly_measurable_mk).trans\n\u27e8\u03bb h, hfm.ae_eq_mk.trans (h.trans hgm.ae_eq_mk.symm),\n  \u03bb h, hfm.ae_eq_mk.symm.trans (h.trans hgm.ae_eq_mk)\u27e9\n\n/-- If the restriction to a set `s` of a \u03c3-algebra `m` is included in the restriction to `s` of\nanother \u03c3-algebra `m\u2082` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` almost\neverywhere supported on `s` is `m`-ae-strongly-measurable, then `f` is also\n`m\u2082`-ae-strongly-measurable. -/\nlemma ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on\n  {\u03b1 E} {m m\u2082 m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  [topological_space E] [has_zero E] (hm : m \u2264 m0) {s : set \u03b1} {f : \u03b1 \u2192 E}\n  (hs_m : measurable_set[m] s) (hs : \u2200 t, measurable_set[m] (s \u2229 t) \u2192 measurable_set[m\u2082] (s \u2229 t))\n  (hf : ae_strongly_measurable' m f \u03bc) (hf_zero : f =\u1d50[\u03bc.restrict s\u1d9c] 0) :\n  ae_strongly_measurable' m\u2082 f \u03bc :=\nbegin\n  let f' := hf.mk f,\n  have h_ind_eq : s.indicator (hf.mk f) =\u1d50[\u03bc] f,\n  { refine filter.eventually_eq.trans _\n      (indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs_m) hf_zero),\n    filter_upwards [hf.ae_eq_mk] with x hx,\n    by_cases hxs : x \u2208 s,\n    { simp [hxs, hx], },\n    { simp [hxs], }, },\n  suffices : strongly_measurable[m\u2082] (s.indicator (hf.mk f)),\n    from ae_strongly_measurable'.congr this.ae_strongly_measurable' h_ind_eq,\n  have hf_ind : strongly_measurable[m] (s.indicator (hf.mk f)),\n    from hf.strongly_measurable_mk.indicator hs_m,\n  exact hf_ind.strongly_measurable_of_measurable_space_le_on hs_m hs\n    (\u03bb x hxs, set.indicator_of_not_mem hxs _),\nend\n\nvariables {\u03b1 \u03b2 \u03b3 E E' F F' G G' H \ud835\udd5c : Type*} {p : \u211d\u22650\u221e}\n  [is_R_or_C \ud835\udd5c] -- \ud835\udd5c for \u211d or \u2102\n  [topological_space \u03b2] -- \u03b2 for a generic topological space\n  -- E for an inner product space\n  [normed_add_comm_group E] [inner_product_space \ud835\udd5c E]\n  -- E' for an inner product space on which we compute integrals\n  [normed_add_comm_group E'] [inner_product_space \ud835\udd5c E']\n  [complete_space E'] [normed_space \u211d E']\n  -- F for a Lp submodule\n  [normed_add_comm_group F] [normed_space \ud835\udd5c F]\n  -- F' for integrals on a Lp submodule\n  [normed_add_comm_group F'] [normed_space \ud835\udd5c F'] [normed_space \u211d F'] [complete_space F']\n  -- G for a Lp add_subgroup\n  [normed_add_comm_group G]\n  -- G' for integrals on a Lp add_subgroup\n  [normed_add_comm_group G'] [normed_space \u211d G'] [complete_space G']\n  -- H for a normed group (hypotheses of mem_\u2112p)\n  [normed_add_comm_group H]\n\nsection Lp_meas\n\n/-! ## The subset `Lp_meas` of `Lp` functions a.e. measurable with respect to a sub-sigma-algebra -/\n\nvariables (F)\n\n/-- `Lp_meas_subgroup F m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef Lp_meas_subgroup (m : measurable_space \u03b1) [measurable_space \u03b1] (p : \u211d\u22650\u221e) (\u03bc : measure \u03b1) :\n  add_subgroup (Lp F p \u03bc) :=\n{ carrier   := {f : (Lp F p \u03bc) | ae_strongly_measurable' m f \u03bc} ,\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _\u27e9,\n  add_mem'  := \u03bb f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,\n  neg_mem' := \u03bb f hf, ae_strongly_measurable'.congr hf.neg (Lp.coe_fn_neg f).symm, }\n\nvariables (\ud835\udd5c)\n/-- `Lp_meas F \ud835\udd5c m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef Lp_meas (m : measurable_space \u03b1) [measurable_space \u03b1] (p : \u211d\u22650\u221e)\n  (\u03bc : measure \u03b1) :\n  submodule \ud835\udd5c (Lp F p \u03bc) :=\n{ carrier   := {f : (Lp F p \u03bc) | ae_strongly_measurable' m f \u03bc} ,\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _\u27e9,\n  add_mem'  := \u03bb f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,\n  smul_mem' := \u03bb c f hf, (hf.const_smul c).congr (Lp.coe_fn_smul c f).symm, }\nvariables {F \ud835\udd5c}\n\nvariables\n\nlemma mem_Lp_meas_subgroup_iff_ae_strongly_measurable' {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {f : Lp F p \u03bc} :\n  f \u2208 Lp_meas_subgroup F m p \u03bc \u2194 ae_strongly_measurable' m f \u03bc :=\nby rw [\u2190 add_subgroup.mem_carrier, Lp_meas_subgroup, set.mem_set_of_eq]\n\nlemma mem_Lp_meas_iff_ae_strongly_measurable'\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f : Lp F p \u03bc} :\n  f \u2208 Lp_meas F \ud835\udd5c m p \u03bc \u2194 ae_strongly_measurable' m f \u03bc :=\nby rw [\u2190 set_like.mem_coe, \u2190 submodule.mem_carrier, Lp_meas, set.mem_set_of_eq]\n\nlemma Lp_meas.ae_strongly_measurable'\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  ae_strongly_measurable' m f \u03bc :=\nmem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem\n\nlemma mem_Lp_meas_self\n  {m0 : measurable_space \u03b1} (\u03bc : measure \u03b1) (f : Lp F p \u03bc) :\n  f \u2208 Lp_meas F \ud835\udd5c m0 p \u03bc :=\nmem_Lp_meas_iff_ae_strongly_measurable'.mpr (Lp.ae_strongly_measurable f)\n\nlemma Lp_meas_subgroup_coe {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {f : Lp_meas_subgroup F m p \u03bc} :\n  \u21d1f = (f : Lp F p \u03bc) :=\ncoe_fn_coe_base f\n\nlemma Lp_meas_coe {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f : Lp_meas F \ud835\udd5c m p \u03bc} :\n  \u21d1f = (f : Lp F p \u03bc) :=\ncoe_fn_coe_base f\n\nlemma mem_Lp_meas_indicator_const_Lp {m m0 : measurable_space \u03b1} (hm : m \u2264 m0)\n  {\u03bc : measure \u03b1} {s : set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) {c : F} :\n  indicator_const_Lp p (hm s hs) h\u03bcs c \u2208 Lp_meas F \ud835\udd5c m p \u03bc :=\n\u27e8s.indicator (\u03bb x : \u03b1, c), (@strongly_measurable_const _ _ m _ _).indicator hs,\n  indicator_const_Lp_coe_fn\u27e9\n\nsection complete_subspace\n\n/-! ## The subspace `Lp_meas` is complete.\n\nWe define an `isometry_equiv` between `Lp_meas_subgroup` and the `Lp` space corresponding to the\nmeasure `\u03bc.trim hm`. As a consequence, the completeness of `Lp` implies completeness of\n`Lp_meas_subgroup` (and `Lp_meas`). -/\n\nvariables {\u03b9 : Type*} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\n/-- If `f` belongs to `Lp_meas_subgroup F m p \u03bc`, then the measurable function it is almost\neverywhere equal to (given by `ae_measurable.mk`) belongs to `\u2112p` for the measure `\u03bc.trim hm`. -/\nlemma mem_\u2112p_trim_of_mem_Lp_meas_subgroup (hm : m \u2264 m0) (f : Lp F p \u03bc)\n  (hf_meas : f \u2208 Lp_meas_subgroup F m p \u03bc) :\n  mem_\u2112p (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas).some p (\u03bc.trim hm) :=\nbegin\n  have hf : ae_strongly_measurable' m f \u03bc,\n    from (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas),\n  let g := hf.some,\n  obtain \u27e8hg, hfg\u27e9 := hf.some_spec,\n  change mem_\u2112p g p (\u03bc.trim hm),\n  refine \u27e8hg.ae_strongly_measurable, _\u27e9,\n  have h_snorm_fg : snorm g p (\u03bc.trim hm) = snorm f p \u03bc,\n    by { rw snorm_trim hm hg, exact snorm_congr_ae hfg.symm, },\n  rw h_snorm_fg,\n  exact Lp.snorm_lt_top f,\nend\n\n/-- If `f` belongs to `Lp` for the measure `\u03bc.trim hm`, then it belongs to the subgroup\n`Lp_meas_subgroup F m p \u03bc`. -/\nlemma mem_Lp_meas_subgroup_to_Lp_of_trim (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  (mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f \u2208 Lp_meas_subgroup F m p \u03bc :=\nbegin\n  let hf_mem_\u2112p := mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f),\n  rw mem_Lp_meas_subgroup_iff_ae_strongly_measurable',\n  refine ae_strongly_measurable'.congr _ (mem_\u2112p.coe_fn_to_Lp hf_mem_\u2112p).symm,\n  refine ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm _,\n  exact Lp.ae_strongly_measurable f,\nend\n\nvariables (F p \u03bc)\n/-- Map from `Lp_meas_subgroup` to `Lp F p (\u03bc.trim hm)`. -/\ndef Lp_meas_subgroup_to_Lp_trim (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) : Lp F p (\u03bc.trim hm) :=\nmem_\u2112p.to_Lp (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some\n  (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm f f.mem)\n\nvariables (\ud835\udd5c)\n/-- Map from `Lp_meas` to `Lp F p (\u03bc.trim hm)`. -/\ndef Lp_meas_to_Lp_trim (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) : Lp F p (\u03bc.trim hm) :=\nmem_\u2112p.to_Lp (mem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem).some\n  (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm f f.mem)\nvariables {\ud835\udd5c}\n\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas_subgroup`, inverse of\n`Lp_meas_subgroup_to_Lp_trim`. -/\ndef Lp_trim_to_Lp_meas_subgroup (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) : Lp_meas_subgroup F m p \u03bc :=\n\u27e8(mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f\u27e9\n\nvariables (\ud835\udd5c)\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas`, inverse of `Lp_meas_to_Lp_trim`. -/\ndef Lp_trim_to_Lp_meas (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) : Lp_meas F \ud835\udd5c m p \u03bc :=\n\u27e8(mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f\u27e9\n\nvariables {F \ud835\udd5c p \u03bc}\n\nlemma Lp_meas_subgroup_to_Lp_trim_ae_eq (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f =\u1d50[\u03bc] f :=\n(ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm \u2191f f.mem))).trans\n  (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm\n\nlemma Lp_trim_to_Lp_meas_subgroup_ae_eq (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  Lp_trim_to_Lp_meas_subgroup F p \u03bc hm f =\u1d50[\u03bc] f :=\nmem_\u2112p.coe_fn_to_Lp _\n\nlemma Lp_meas_to_Lp_trim_ae_eq (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\n(ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm \u2191f f.mem))).trans\n  (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm\n\nlemma Lp_trim_to_Lp_meas_ae_eq (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  Lp_trim_to_Lp_meas F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\nmem_\u2112p.coe_fn_to_Lp _\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a right inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\nlemma Lp_meas_subgroup_to_Lp_trim_right_inv (hm : m \u2264 m0) :\n  function.right_inverse (Lp_trim_to_Lp_meas_subgroup F p \u03bc hm)\n    (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  intro f,\n  ext1,\n  refine ae_eq_trim_of_strongly_measurable hm\n    (Lp.strongly_measurable _) (Lp.strongly_measurable _) _,\n  exact (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _),\nend\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a left inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\nlemma Lp_meas_subgroup_to_Lp_trim_left_inv (hm : m \u2264 m0) :\n  function.left_inverse (Lp_trim_to_Lp_meas_subgroup F p \u03bc hm)\n    (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  intro f,\n  ext1,\n  ext1,\n  rw \u2190 Lp_meas_subgroup_coe,\n  exact (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _).trans (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_add (hm : m \u2264 m0) (f g : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (f + g)\n    = Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f + Lp_meas_subgroup_to_Lp_trim F p \u03bc hm g :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact (Lp.strongly_measurable _).add (Lp.strongly_measurable _), },\n  refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,\n  refine eventually_eq.trans _\n    (eventually_eq.add (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm\n      (Lp_meas_subgroup_to_Lp_trim_ae_eq hm g).symm),\n  refine (Lp.coe_fn_add _ _).trans _,\n  simp_rw Lp_meas_subgroup_coe,\n  exact eventually_of_forall (\u03bb x, by refl),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_neg (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (-f)\n    = -Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_neg _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact @strongly_measurable.neg _ _ _ m _ _ _ (Lp.strongly_measurable _), },\n  refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,\n  refine eventually_eq.trans _\n    (eventually_eq.neg (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm),\n  refine (Lp.coe_fn_neg _).trans _,\n  simp_rw Lp_meas_subgroup_coe,\n  exact eventually_of_forall (\u03bb x, by refl),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_sub (hm : m \u2264 m0) (f g : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (f - g)\n    = Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f - Lp_meas_subgroup_to_Lp_trim F p \u03bc hm g :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, Lp_meas_subgroup_to_Lp_trim_add,\n  Lp_meas_subgroup_to_Lp_trim_neg]\n\nlemma Lp_meas_to_Lp_trim_smul (hm : m \u2264 m0) (c : \ud835\udd5c) (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm (c \u2022 f) = c \u2022 Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact (Lp.strongly_measurable _).const_smul c, },\n  refine (Lp_meas_to_Lp_trim_ae_eq hm _).trans _,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (Lp_meas_to_Lp_trim_ae_eq hm f).mono (\u03bb x hx, _),\n  rw [pi.smul_apply, pi.smul_apply, hx],\n  refl,\nend\n\n/-- `Lp_meas_subgroup_to_Lp_trim` preserves the norm. -/\nlemma Lp_meas_subgroup_to_Lp_trim_norm_map [hp : fact (1 \u2264 p)] (hm : m \u2264 m0)\n  (f : Lp_meas_subgroup F m p \u03bc) :\n  \u2016Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f\u2016 = \u2016f\u2016 :=\nbegin\n  rw [Lp.norm_def, snorm_trim hm (Lp.strongly_measurable _),\n    snorm_congr_ae (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _), Lp_meas_subgroup_coe, \u2190 Lp.norm_def],\n  congr,\nend\n\nlemma isometry_Lp_meas_subgroup_to_Lp_trim [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  isometry (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nisometry.of_dist_eq $ \u03bb f g, by rw [dist_eq_norm, \u2190 Lp_meas_subgroup_to_Lp_trim_sub,\n  Lp_meas_subgroup_to_Lp_trim_norm_map, dist_eq_norm]\n\nvariables (F p \u03bc)\n/-- `Lp_meas_subgroup` and `Lp F p (\u03bc.trim hm)` are isometric. -/\ndef Lp_meas_subgroup_to_Lp_trim_iso [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  Lp_meas_subgroup F m p \u03bc \u2243\u1d62 Lp F p (\u03bc.trim hm) :=\n{ to_fun    := Lp_meas_subgroup_to_Lp_trim F p \u03bc hm,\n  inv_fun   := Lp_trim_to_Lp_meas_subgroup F p \u03bc hm,\n  left_inv  := Lp_meas_subgroup_to_Lp_trim_left_inv hm,\n  right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,\n  isometry_to_fun := isometry_Lp_meas_subgroup_to_Lp_trim hm, }\n\nvariables (\ud835\udd5c)\n/-- `Lp_meas_subgroup` and `Lp_meas` are isometric. -/\ndef Lp_meas_subgroup_to_Lp_meas_iso [hp : fact (1 \u2264 p)] :\n  Lp_meas_subgroup F m p \u03bc \u2243\u1d62 Lp_meas F \ud835\udd5c m p \u03bc :=\nisometry_equiv.refl (Lp_meas_subgroup F m p \u03bc)\n\n/-- `Lp_meas` and `Lp F p (\u03bc.trim hm)` are isometric, with a linear equivalence. -/\ndef Lp_meas_to_Lp_trim_lie [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  Lp_meas F \ud835\udd5c m p \u03bc \u2243\u2097\u1d62[\ud835\udd5c] Lp F p (\u03bc.trim hm) :=\n{ to_fun    := Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm,\n  inv_fun   := Lp_trim_to_Lp_meas F \ud835\udd5c p \u03bc hm,\n  left_inv  := Lp_meas_subgroup_to_Lp_trim_left_inv hm,\n  right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,\n  map_add'  := Lp_meas_subgroup_to_Lp_trim_add hm,\n  map_smul' := Lp_meas_to_Lp_trim_smul hm,\n  norm_map' := Lp_meas_subgroup_to_Lp_trim_norm_map hm, }\nvariables {F \ud835\udd5c p \u03bc}\n\ninstance [hm : fact (m \u2264 m0)] [complete_space F] [hp : fact (1 \u2264 p)] :\n  complete_space (Lp_meas_subgroup F m p \u03bc) :=\nby { rw (Lp_meas_subgroup_to_Lp_trim_iso F p \u03bc hm.elim).complete_space_iff, apply_instance, }\n\ninstance [hm : fact (m \u2264 m0)] [complete_space F] [hp : fact (1 \u2264 p)] :\n  complete_space (Lp_meas F \ud835\udd5c m p \u03bc) :=\nby { rw (Lp_meas_subgroup_to_Lp_meas_iso F \ud835\udd5c p \u03bc).symm.complete_space_iff, apply_instance, }\n\nlemma is_complete_ae_strongly_measurable' [hp : fact (1 \u2264 p)] [complete_space F] (hm : m \u2264 m0) :\n  is_complete {f : Lp F p \u03bc | ae_strongly_measurable' m f \u03bc} :=\nbegin\n  rw \u2190 complete_space_coe_iff_is_complete,\n  haveI : fact (m \u2264 m0) := \u27e8hm\u27e9,\n  change complete_space (Lp_meas_subgroup F m p \u03bc),\n  apply_instance,\nend\n\nlemma is_closed_ae_strongly_measurable' [hp : fact (1 \u2264 p)] [complete_space F] (hm : m \u2264 m0) :\n  is_closed {f : Lp F p \u03bc | ae_strongly_measurable' m f \u03bc} :=\nis_complete.is_closed (is_complete_ae_strongly_measurable' hm)\n\nend complete_subspace\n\nsection strongly_measurable\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\n/-- We do not get `ae_fin_strongly_measurable f (\u03bc.trim hm)`, since we don't have\n`f =\u1d50[\u03bc.trim hm] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f` but only the weaker\n`f =\u1d50[\u03bc] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f`. -/\nlemma Lp_meas.ae_fin_strongly_measurable' (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) (hp_ne_zero : p \u2260 0)\n  (hp_ne_top : p \u2260 \u221e) :\n  \u2203 g, fin_strongly_measurable g (\u03bc.trim hm) \u2227 f =\u1d50[\u03bc] g :=\n\u27e8Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f, Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top,\n  (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm\u27e9\n\n/-- When applying the inverse of `Lp_meas_to_Lp_trim_lie` (which takes a function in the Lp space of\nthe sub-sigma algebra and returns its version in the larger Lp space) to an indicator of the\nsub-sigma-algebra, we obtain an indicator in the Lp space of the larger sigma-algebra. -/\nlemma Lp_meas_to_Lp_trim_lie_symm_indicator [one_le_p : fact (1 \u2264 p)] [normed_space \u211d F]\n  {hm : m \u2264 m0} {s : set \u03b1} {\u03bc : measure \u03b1}\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc.trim hm s \u2260 \u221e) (c : F) :\n  ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm\n      (indicator_const_Lp p hs h\u03bcs c) : Lp F p \u03bc)\n    = indicator_const_Lp p (hm s hs) ((le_trim hm).trans_lt h\u03bcs.lt_top).ne c :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  change Lp_trim_to_Lp_meas F \u211d p \u03bc hm (indicator_const_Lp p hs h\u03bcs c)\n    =\u1d50[\u03bc] (indicator_const_Lp p _ _ c : \u03b1 \u2192 F),\n  refine (Lp_trim_to_Lp_meas_ae_eq hm _).trans _,\n  exact (ae_eq_of_ae_eq_trim indicator_const_Lp_coe_fn).trans indicator_const_Lp_coe_fn.symm,\nend\n\nlemma Lp_meas_to_Lp_trim_lie_symm_to_Lp [one_le_p : fact (1 \u2264 p)] [normed_space \u211d F]\n  (hm : m \u2264 m0) (f : \u03b1 \u2192 F) (hf : mem_\u2112p f p (\u03bc.trim hm)) :\n  ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm (hf.to_Lp f) : Lp F p \u03bc)\n    = (mem_\u2112p_of_mem_\u2112p_trim hm hf).to_Lp f :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  refine (Lp_trim_to_Lp_meas_ae_eq hm _).trans _,\n  exact (ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp hf)).trans (mem_\u2112p.coe_fn_to_Lp _).symm,\nend\n\nend strongly_measurable\n\nend Lp_meas\n\n\nsection induction\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} [fact (1 \u2264 p)] [normed_space \u211d F]\n\n/-- Auxiliary lemma for `Lp.induction_strongly_measurable`. -/\n@[elab_as_eliminator]\nlemma Lp.induction_strongly_measurable_aux (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e) (P : Lp F p \u03bc \u2192 Prop)\n  (h_ind : \u2200 (c : F) {s : set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s < \u221e),\n      P (Lp.simple_func.indicator_const p (hm s hs) h\u03bcs.ne c))\n  (h_add : \u2200 \u2983f g\u2984, \u2200 hf : mem_\u2112p f p \u03bc, \u2200 hg : mem_\u2112p g p \u03bc,\n    \u2200 hfm : ae_strongly_measurable' m f \u03bc, \u2200 hgm : ae_strongly_measurable' m g \u03bc,\n    disjoint (function.support f) (function.support g) \u2192\n    P (hf.to_Lp f) \u2192 P (hg.to_Lp g) \u2192 P ((hf.to_Lp f) + (hg.to_Lp g)))\n  (h_closed : is_closed {f : Lp_meas F \u211d m p \u03bc | P f}) :\n  \u2200 f : Lp F p \u03bc, ae_strongly_measurable' m f \u03bc \u2192 P f :=\nbegin\n  intros f hf,\n  let f' := (\u27e8f, hf\u27e9 : Lp_meas F \u211d m p \u03bc),\n  let g := Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm f',\n  have hfg : f' = (Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm g,\n    by simp only [linear_isometry_equiv.symm_apply_apply],\n  change P \u2191f',\n  rw hfg,\n  refine @Lp.induction \u03b1 F m _ p (\u03bc.trim hm) _ hp_ne_top\n    (\u03bb g, P ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm g)) _ _ _ g,\n  { intros b t ht h\u03bct,\n    rw [Lp.simple_func.coe_indicator_const,\n      Lp_meas_to_Lp_trim_lie_symm_indicator ht h\u03bct.ne b],\n      have h\u03bct' : \u03bc t < \u221e, from (le_trim hm).trans_lt h\u03bct,\n    specialize h_ind b ht h\u03bct',\n    rwa Lp.simple_func.coe_indicator_const at h_ind, },\n  { intros f g hf hg h_disj hfP hgP,\n    rw linear_isometry_equiv.map_add,\n    push_cast,\n    have h_eq : \u2200 (f : \u03b1 \u2192 F) (hf : mem_\u2112p f p (\u03bc.trim hm)),\n      ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm (mem_\u2112p.to_Lp f hf) : Lp F p \u03bc)\n        = (mem_\u2112p_of_mem_\u2112p_trim hm hf).to_Lp f,\n      from Lp_meas_to_Lp_trim_lie_symm_to_Lp hm,\n    rw h_eq f hf at hfP \u22a2,\n    rw h_eq g hg at hgP \u22a2,\n    exact h_add (mem_\u2112p_of_mem_\u2112p_trim hm hf) (mem_\u2112p_of_mem_\u2112p_trim hm hg)\n      (ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hf.ae_strongly_measurable)\n      (ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hg.ae_strongly_measurable)\n      h_disj hfP hgP, },\n  { change is_closed ((Lp_meas_to_Lp_trim_lie F \u211d p \u03bc hm).symm \u207b\u00b9' {g : Lp_meas F \u211d m p \u03bc | P \u2191g}),\n    exact is_closed.preimage (linear_isometry_equiv.continuous _) h_closed, },\nend\n\n/-- To prove something for an `Lp` function a.e. strongly measurable with respect to a\nsub-\u03c3-algebra `m` in a normed space, it suffices to show that\n* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;\n* is closed under addition;\n* the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is\n  closed.\n-/\n@[elab_as_eliminator]\nlemma Lp.induction_strongly_measurable (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e) (P : Lp F p \u03bc \u2192 Prop)\n  (h_ind : \u2200 (c : F) {s : set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s < \u221e),\n      P (Lp.simple_func.indicator_const p (hm s hs) h\u03bcs.ne c))\n  (h_add : \u2200 \u2983f g\u2984, \u2200 hf : mem_\u2112p f p \u03bc, \u2200 hg : mem_\u2112p g p \u03bc,\n    \u2200 hfm : strongly_measurable[m] f, \u2200 hgm : strongly_measurable[m] g,\n    disjoint (function.support f) (function.support g) \u2192\n    P (hf.to_Lp f) \u2192 P (hg.to_Lp g) \u2192 P ((hf.to_Lp f) + (hg.to_Lp g)))\n  (h_closed : is_closed {f : Lp_meas F \u211d m p \u03bc | P f}) :\n  \u2200 f : Lp F p \u03bc, ae_strongly_measurable' m f \u03bc \u2192 P f :=\nbegin\n  intros f hf,\n  suffices h_add_ae : \u2200 \u2983f g\u2984, \u2200 hf : mem_\u2112p f p \u03bc, \u2200 hg : mem_\u2112p g p \u03bc,\n      \u2200 hfm : ae_strongly_measurable' m f \u03bc, \u2200 hgm : ae_strongly_measurable' m g \u03bc,\n      disjoint (function.support f) (function.support g) \u2192\n      P (hf.to_Lp f) \u2192 P (hg.to_Lp g) \u2192 P ((hf.to_Lp f) + (hg.to_Lp g)),\n    from Lp.induction_strongly_measurable_aux hm hp_ne_top P h_ind h_add_ae h_closed f hf,\n  intros f g hf hg hfm hgm h_disj hPf hPg,\n  let s_f : set \u03b1 := function.support (hfm.mk f),\n  have hs_f : measurable_set[m] s_f := hfm.strongly_measurable_mk.measurable_set_support,\n  have hs_f_eq : s_f =\u1d50[\u03bc] function.support f := hfm.ae_eq_mk.symm.support,\n  let s_g : set \u03b1 := function.support (hgm.mk g),\n  have hs_g : measurable_set[m] s_g := hgm.strongly_measurable_mk.measurable_set_support,\n  have hs_g_eq : s_g =\u1d50[\u03bc] function.support g := hgm.ae_eq_mk.symm.support,\n  have h_inter_empty : ((s_f \u2229 s_g) : set \u03b1) =\u1d50[\u03bc] (\u2205 : set \u03b1),\n  { refine (hs_f_eq.inter hs_g_eq).trans _,\n    suffices : function.support f \u2229 function.support g = \u2205, by rw this,\n    exact set.disjoint_iff_inter_eq_empty.mp h_disj, },\n  let f' := (s_f \\ s_g).indicator (hfm.mk f),\n  have hff' : f =\u1d50[\u03bc] f',\n  { have : s_f \\ s_g =\u1d50[\u03bc] s_f,\n    { rw [\u2190 set.diff_inter_self_eq_diff, set.inter_comm],\n      refine ((ae_eq_refl s_f).diff h_inter_empty).trans _,\n      rw set.diff_empty, },\n    refine ((indicator_ae_eq_of_ae_eq_set this).trans _).symm,\n    rw set.indicator_support,\n    exact hfm.ae_eq_mk.symm, },\n  have hf'_meas : strongly_measurable[m] f',\n    from hfm.strongly_measurable_mk.indicator (hs_f.diff hs_g),\n  have hf'_Lp : mem_\u2112p f' p \u03bc := hf.ae_eq hff',\n  let g' := (s_g \\ s_f).indicator (hgm.mk g),\n  have hgg' : g =\u1d50[\u03bc] g',\n  { have : s_g \\ s_f =\u1d50[\u03bc] s_g,\n    { rw [\u2190 set.diff_inter_self_eq_diff],\n      refine ((ae_eq_refl s_g).diff h_inter_empty).trans _,\n      rw set.diff_empty, },\n    refine ((indicator_ae_eq_of_ae_eq_set this).trans _).symm,\n    rw set.indicator_support,\n    exact hgm.ae_eq_mk.symm, },\n  have hg'_meas : strongly_measurable[m] g',\n    from hgm.strongly_measurable_mk.indicator (hs_g.diff hs_f),\n  have hg'_Lp : mem_\u2112p g' p \u03bc := hg.ae_eq hgg',\n  have h_disj : disjoint (function.support f') (function.support g'),\n  { have : disjoint (s_f \\ s_g) (s_g \\ s_f) := disjoint_sdiff_sdiff,\n    exact this.mono set.support_indicator_subset set.support_indicator_subset, },\n  rw \u2190 mem_\u2112p.to_Lp_congr hf'_Lp hf hff'.symm at \u22a2 hPf,\n  rw \u2190 mem_\u2112p.to_Lp_congr hg'_Lp hg hgg'.symm at \u22a2 hPg,\n  exact h_add hf'_Lp hg'_Lp hf'_meas hg'_meas h_disj hPf hPg,\nend\n\n/-- To prove something for an arbitrary `mem_\u2112p` function a.e. strongly measurable with respect\nto a sub-\u03c3-algebra `m` in a normed space, it suffices to show that\n* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;\n* is closed under addition;\n* the set of functions in the `L\u1d56` space strongly measurable w.r.t. `m` for which the property\n  holds is closed.\n* the property is closed under the almost-everywhere equal relation.\n-/\n@[elab_as_eliminator]\nlemma mem_\u2112p.induction_strongly_measurable (hm : m \u2264 m0) (hp_ne_top : p \u2260 \u221e)\n  (P : (\u03b1 \u2192 F) \u2192 Prop)\n  (h_ind : \u2200 (c : F) \u2983s\u2984, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 P (s.indicator (\u03bb _, c)))\n  (h_add : \u2200 \u2983f g : \u03b1 \u2192 F\u2984, disjoint (function.support f) (function.support g)\n    \u2192 mem_\u2112p f p \u03bc \u2192 mem_\u2112p g p \u03bc \u2192 strongly_measurable[m] f \u2192 strongly_measurable[m] g \u2192\n    P f \u2192 P g \u2192 P (f + g))\n  (h_closed : is_closed {f : Lp_meas F \u211d m p \u03bc | P f} )\n  (h_ae : \u2200 \u2983f g\u2984, f =\u1d50[\u03bc] g \u2192 mem_\u2112p f p \u03bc \u2192 P f \u2192 P g) :\n  \u2200 \u2983f : \u03b1 \u2192 F\u2984 (hf : mem_\u2112p f p \u03bc) (hfm : ae_strongly_measurable' m f \u03bc), P f :=\nbegin\n  intros f hf hfm,\n  let f_Lp := hf.to_Lp f,\n  have hfm_Lp : ae_strongly_measurable' m f_Lp \u03bc, from hfm.congr hf.coe_fn_to_Lp.symm,\n  refine h_ae (hf.coe_fn_to_Lp) (Lp.mem_\u2112p _) _,\n  change P f_Lp,\n  refine Lp.induction_strongly_measurable hm hp_ne_top (\u03bb f, P \u21d1f) _ _ h_closed f_Lp hfm_Lp,\n  { intros c s hs h\u03bcs,\n    rw Lp.simple_func.coe_indicator_const,\n    refine h_ae (indicator_const_Lp_coe_fn).symm _ (h_ind c hs h\u03bcs),\n    exact mem_\u2112p_indicator_const p (hm s hs) c (or.inr h\u03bcs.ne), },\n  { intros f g hf_mem hg_mem hfm hgm h_disj hfP hgP,\n    have hfP' : P f := h_ae (hf_mem.coe_fn_to_Lp) (Lp.mem_\u2112p _) hfP,\n    have hgP' : P g := h_ae (hg_mem.coe_fn_to_Lp) (Lp.mem_\u2112p _) hgP,\n    specialize h_add h_disj hf_mem hg_mem hfm hgm hfP' hgP',\n    refine h_ae _ (hf_mem.add hg_mem) h_add,\n    exact ((hf_mem.coe_fn_to_Lp).symm.add (hg_mem.coe_fn_to_Lp).symm).trans\n      (Lp.coe_fn_add _ _).symm, },\nend\n\nend induction\n\n\nsection uniqueness_of_conditional_expectation\n\n/-! ## Uniqueness of the conditional expectation -/\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\nlemma Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero\n  (hm : m \u2264 m0) (f : Lp_meas E' \ud835\udd5c m p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hf_zero : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = 0) :\n  f =\u1d50[\u03bc] 0 :=\nbegin\n  obtain \u27e8g, hg_sm, hfg\u27e9 := Lp_meas.ae_fin_strongly_measurable' hm f hp_ne_zero hp_ne_top,\n  refine hfg.trans _,\n  refine ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim hm _ _ hg_sm,\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g, from ae_restrict_of_ae hfg,\n    rw [integrable_on, integrable_congr hfg_restrict.symm],\n    exact hf_int_finite s hs h\u03bcs, },\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g, from ae_restrict_of_ae hfg,\n    rw integral_congr_ae hfg_restrict.symm,\n    exact hf_zero s hs h\u03bcs, },\nend\n\ninclude \ud835\udd5c\nvariables (\ud835\udd5c)\n\nlemma Lp.ae_eq_zero_of_forall_set_integral_eq_zero'\n  (hm : m \u2264 m0) (f : Lp E' p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hf_zero : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = 0)\n  (hf_meas : ae_strongly_measurable' m f \u03bc) :\n  f =\u1d50[\u03bc] 0 :=\nbegin\n  let f_meas : Lp_meas E' \ud835\udd5c m p \u03bc := \u27e8f, hf_meas\u27e9,\n  have hf_f_meas : f =\u1d50[\u03bc] f_meas, by simp only [coe_fn_coe_base', subtype.coe_mk],\n  refine hf_f_meas.trans _,\n  refine Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero hm f_meas hp_ne_zero hp_ne_top _ _,\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,\n    rw [integrable_on, integrable_congr hfg_restrict.symm],\n    exact hf_int_finite s hs h\u03bcs, },\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,\n    rw integral_congr_ae hfg_restrict.symm,\n    exact hf_zero s hs h\u03bcs, },\nend\n\n/-- **Uniqueness of the conditional expectation** -/\nlemma Lp.ae_eq_of_forall_set_integral_eq'\n  (hm : m \u2264 m0) (f g : Lp E' p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hfg : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = \u222b x in s, g x \u2202\u03bc)\n  (hf_meas : ae_strongly_measurable' m f \u03bc) (hg_meas : ae_strongly_measurable' m g \u03bc) :\n  f =\u1d50[\u03bc] g :=\nbegin\n  suffices h_sub : \u21d1(f-g) =\u1d50[\u03bc] 0,\n    by { rw \u2190 sub_ae_eq_zero, exact (Lp.coe_fn_sub f g).symm.trans h_sub, },\n  have hfg' : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, (f - g) x \u2202\u03bc = 0,\n  { intros s hs h\u03bcs,\n    rw integral_congr_ae (ae_restrict_of_ae (Lp.coe_fn_sub f g)),\n    rw integral_sub' (hf_int_finite s hs h\u03bcs) (hg_int_finite s hs h\u03bcs),\n    exact sub_eq_zero.mpr (hfg s hs h\u03bcs), },\n  have hfg_int : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on \u21d1(f-g) s \u03bc,\n  { intros s hs h\u03bcs,\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub f g))],\n    exact (hf_int_finite s hs h\u03bcs).sub (hg_int_finite s hs h\u03bcs), },\n  have hfg_meas : ae_strongly_measurable' m \u21d1(f - g) \u03bc,\n    from ae_strongly_measurable'.congr (hf_meas.sub hg_meas) (Lp.coe_fn_sub f g).symm,\n  exact Lp.ae_eq_zero_of_forall_set_integral_eq_zero' \ud835\udd5c hm (f-g) hp_ne_zero hp_ne_top hfg_int hfg'\n    hfg_meas,\nend\n\nvariables {\ud835\udd5c}\nomit \ud835\udd5c\n\nlemma ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  {f g : \u03b1 \u2192 F'}\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hfg_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = \u222b x in s, g x \u2202\u03bc)\n  (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  f =\u1d50[\u03bc] g :=\nbegin\n  rw \u2190 ae_eq_trim_iff_of_ae_strongly_measurable' hm hfm hgm,\n  have hf_mk_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    @integrable_on _ _ m _ (hfm.mk f) s (\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [integrable_on, restrict_trim hm _ hs],\n    refine integrable.trim hm _ hfm.strongly_measurable_mk,\n    exact integrable.congr (hf_int_finite s hs h\u03bcs) (ae_restrict_of_ae hfm.ae_eq_mk), },\n  have hg_mk_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    @integrable_on _ _ m _ (hgm.mk g) s (\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [integrable_on, restrict_trim hm _ hs],\n    refine integrable.trim hm _ hgm.strongly_measurable_mk,\n    exact integrable.congr (hg_int_finite s hs h\u03bcs) (ae_restrict_of_ae hgm.ae_eq_mk), },\n  have hfg_mk_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    \u222b x in s, (hfm.mk f x) \u2202(\u03bc.trim hm) = \u222b x in s, (hgm.mk g x) \u2202(\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [restrict_trim hm _ hs, \u2190 integral_trim hm hfm.strongly_measurable_mk,\n      \u2190 integral_trim hm hgm.strongly_measurable_mk,\n      integral_congr_ae (ae_restrict_of_ae hfm.ae_eq_mk.symm),\n      integral_congr_ae (ae_restrict_of_ae hgm.ae_eq_mk.symm)],\n    exact hfg_eq s hs h\u03bcs, },\n  exact ae_eq_of_forall_set_integral_eq_of_sigma_finite hf_mk_int_finite hg_mk_int_finite hfg_mk_eq,\nend\n\nend uniqueness_of_conditional_expectation\n\n\nsection integral_norm_le\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {s : set \u03b1}\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b x in s, \u2016g x\u2016 \u2202\u03bc \u2264 \u222b x in s, \u2016f x\u2016 \u2202\u03bc` on all `m`-measurable sets with finite measure. -/\nlemma integral_norm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n  (hf : strongly_measurable f) (hfi : integrable_on f s \u03bc)\n  (hg : strongly_measurable[m] g) (hgi : integrable_on g s \u03bc)\n  (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 \u222b x in t, g x \u2202\u03bc = \u222b x in t, f x \u2202\u03bc)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, \u2016g x\u2016 \u2202\u03bc \u2264 \u222b x in s, \u2016f x\u2016 \u2202\u03bc :=\nbegin\n  rw [integral_norm_eq_pos_sub_neg hgi, integral_norm_eq_pos_sub_neg hfi],\n  have h_meas_nonneg_g : measurable_set[m] {x | 0 \u2264 g x},\n    from (@strongly_measurable_const _ _ m _ _).measurable_set_le hg,\n  have h_meas_nonneg_f : measurable_set {x | 0 \u2264 f x},\n    from strongly_measurable_const.measurable_set_le hf,\n  have h_meas_nonpos_g : measurable_set[m] {x | g x \u2264 0},\n    from hg.measurable_set_le (@strongly_measurable_const _ _ m _ _),\n  have h_meas_nonpos_f : measurable_set {x | f x \u2264 0},\n    from hf.measurable_set_le strongly_measurable_const,\n  refine sub_le_sub _ _,\n  { rw [measure.restrict_restrict (hm _ h_meas_nonneg_g),\n      measure.restrict_restrict h_meas_nonneg_f,\n      hgf _ (@measurable_set.inter \u03b1 m _ _ h_meas_nonneg_g hs)\n        ((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonneg_g),\n      \u2190 measure.restrict_restrict h_meas_nonneg_f],\n    exact set_integral_le_nonneg (hm _ h_meas_nonneg_g) hf hfi, },\n  { rw [measure.restrict_restrict (hm _ h_meas_nonpos_g),\n      measure.restrict_restrict h_meas_nonpos_f,\n      hgf _ (@measurable_set.inter \u03b1 m _ _ h_meas_nonpos_g hs)\n        ((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonpos_g),\n      \u2190 measure.restrict_restrict h_meas_nonpos_f],\n    exact set_integral_nonpos_le (hm _ h_meas_nonpos_g) hf hfi, },\nend\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b\u207b x in s, \u2016g x\u2016\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2016f x\u2016\u208a \u2202\u03bc` on all `m`-measurable sets with finite\nmeasure. -/\nlemma lintegral_nnnorm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n  (hf : strongly_measurable f) (hfi : integrable_on f s \u03bc)\n  (hg : strongly_measurable[m] g) (hgi : integrable_on g s \u03bc)\n  (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 \u222b x in t, g x \u2202\u03bc = \u222b x in t, f x \u2202\u03bc)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b\u207b x in s, \u2016g x\u2016\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2016f x\u2016\u208a \u2202\u03bc :=\nbegin\n  rw [\u2190 of_real_integral_norm_eq_lintegral_nnnorm hfi,\n    \u2190 of_real_integral_norm_eq_lintegral_nnnorm hgi, ennreal.of_real_le_of_real_iff],\n  { exact integral_norm_le_of_forall_fin_meas_integral_eq hm hf hfi hg hgi hgf hs h\u03bcs, },\n  { exact integral_nonneg (\u03bb x, norm_nonneg _), },\nend\n\nend integral_norm_le\n\n/-! ## Conditional expectation in L2\n\nWe define a conditional expectation in `L2`: it is the orthogonal projection on the subspace\n`Lp_meas`. -/\n\nsection condexp_L2\n\nvariables [complete_space E] {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {s t : set \u03b1}\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c E _ x y\nlocal notation `\u27ea`x`, `y`\u27eb\u2082` := @inner \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ x y\n\nvariables (\ud835\udd5c)\n/-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/\ndef condexp_L2 (hm : m \u2264 m0) : (\u03b1 \u2192\u2082[\u03bc] E) \u2192L[\ud835\udd5c] (Lp_meas E \ud835\udd5c m 2 \u03bc) :=\n@orthogonal_projection \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ _ _ (Lp_meas E \ud835\udd5c m 2 \u03bc)\n  (by { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact infer_instance, })\nvariables {\ud835\udd5c}\n\nlemma ae_strongly_measurable'_condexp_L2 (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  ae_strongly_measurable' m (condexp_L2 \ud835\udd5c hm f) \u03bc :=\nLp_meas.ae_strongly_measurable' _\n\nlemma integrable_on_condexp_L2_of_measure_ne_top (hm : m \u2264 m0) (h\u03bcs : \u03bc s \u2260 \u221e) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  integrable_on (condexp_L2 \ud835\udd5c hm f) s \u03bc :=\nintegrable_on_Lp_of_measure_ne_top ((condexp_L2 \ud835\udd5c hm f) : \u03b1 \u2192\u2082[\u03bc] E)\n  fact_one_le_two_ennreal.elim h\u03bcs\n\nlemma integrable_condexp_L2_of_is_finite_measure (hm : m \u2264 m0) [is_finite_measure \u03bc]\n  {f : \u03b1 \u2192\u2082[\u03bc] E} :\n  integrable (condexp_L2 \ud835\udd5c hm f) \u03bc :=\nintegrable_on_univ.mp $ integrable_on_condexp_L2_of_measure_ne_top hm (measure_ne_top _ _) f\n\nlemma norm_condexp_L2_le_one (hm : m \u2264 m0) : \u2016@condexp_L2 \u03b1 E \ud835\udd5c _ _ _ _ _ _ \u03bc hm\u2016 \u2264 1 :=\nby { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact orthogonal_projection_norm_le _, }\n\nlemma norm_condexp_L2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) : \u2016condexp_L2 \ud835\udd5c hm f\u2016 \u2264 \u2016f\u2016 :=\n((@condexp_L2 _ E \ud835\udd5c _ _ _ _ _ _ \u03bc hm).le_op_norm f).trans\n  (mul_le_of_le_one_left (norm_nonneg _) (norm_condexp_L2_le_one hm))\n\nlemma snorm_condexp_L2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  snorm (condexp_L2 \ud835\udd5c hm f) 2 \u03bc \u2264 snorm f 2 \u03bc :=\nbegin\n  rw [Lp_meas_coe, \u2190 ennreal.to_real_le_to_real (Lp.snorm_ne_top _) (Lp.snorm_ne_top _),\n    \u2190 Lp.norm_def, \u2190 Lp.norm_def, submodule.norm_coe],\n  exact norm_condexp_L2_le hm f,\nend\n\nlemma norm_condexp_L2_coe_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  \u2016(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E)\u2016 \u2264 \u2016f\u2016 :=\nbegin\n  rw [Lp.norm_def, Lp.norm_def, \u2190 Lp_meas_coe],\n  refine (ennreal.to_real_le_to_real _ (Lp.snorm_ne_top _)).mpr (snorm_condexp_L2_le hm f),\n  exact Lp.snorm_ne_top _,\nend\n\nlemma inner_condexp_L2_left_eq_right (hm : m \u2264 m0) {f g : \u03b1 \u2192\u2082[\u03bc] E} :\n  \u27ea(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, (condexp_L2 \ud835\udd5c hm g : \u03b1 \u2192\u2082[\u03bc] E)\u27eb\u2082 :=\nby { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact inner_orthogonal_projection_left_eq_right _ f g, }\n\nlemma condexp_L2_indicator_of_measurable (hm : m \u2264 m0)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : E) :\n  (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 (hm s hs) h\u03bcs c) : \u03b1 \u2192\u2082[\u03bc] E)\n    = indicator_const_Lp 2 (hm s hs) h\u03bcs c :=\nbegin\n  rw condexp_L2,\n  haveI : fact (m \u2264 m0) := \u27e8hm\u27e9,\n  have h_mem : indicator_const_Lp 2 (hm s hs) h\u03bcs c \u2208 Lp_meas E \ud835\udd5c m 2 \u03bc,\n    from mem_Lp_meas_indicator_const_Lp hm hs h\u03bcs,\n  let ind := (\u27e8indicator_const_Lp 2 (hm s hs) h\u03bcs c, h_mem\u27e9 : Lp_meas E \ud835\udd5c m 2 \u03bc),\n  have h_coe_ind : (ind : \u03b1 \u2192\u2082[\u03bc] E) = indicator_const_Lp 2 (hm s hs) h\u03bcs c, by refl,\n  have h_orth_mem := orthogonal_projection_mem_subspace_eq_self ind,\n  rw [\u2190 h_coe_ind, h_orth_mem],\nend\n\nlemma inner_condexp_L2_eq_inner_fun (hm : m \u2264 m0) (f g : \u03b1 \u2192\u2082[\u03bc] E)\n  (hg : ae_strongly_measurable' m g \u03bc) :\n  \u27ea(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, g\u27eb\u2082 :=\nbegin\n  symmetry,\n  rw [\u2190 sub_eq_zero, \u2190 inner_sub_left, condexp_L2],\n  simp only [mem_Lp_meas_iff_ae_strongly_measurable'.mpr hg, orthogonal_projection_inner_eq_zero],\nend\n\nsection real\n\nvariables {hm : m \u2264 m0}\n\nlemma integral_condexp_L2_eq_of_fin_meas_real (f : Lp \ud835\udd5c 2 \u03bc) (hs : measurable_set[m] s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw \u2190 L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs,\n  have h_eq_inner : \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc\n    = inner (indicator_const_Lp 2 (hm s hs) h\u03bcs (1 : \ud835\udd5c)) (condexp_L2 \ud835\udd5c hm f),\n  { rw L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs,\n    congr, },\n  rw [h_eq_inner, \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable hm hs h\u03bcs],\nend\n\nlemma lintegral_nnnorm_condexp_L2_le (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (f : Lp \u211d 2 \u03bc) :\n  \u222b\u207b x in s, \u2016condexp_L2 \u211d hm f x\u2016\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2016f x\u2016\u208a \u2202\u03bc :=\nbegin\n  let h_meas := Lp_meas.ae_strongly_measurable' (condexp_L2 \u211d hm f),\n  let g := h_meas.some,\n  have hg_meas : strongly_measurable[m] g, from h_meas.some_spec.1,\n  have hg_eq : g =\u1d50[\u03bc] condexp_L2 \u211d hm f, from h_meas.some_spec.2.symm,\n  have hg_eq_restrict : g =\u1d50[\u03bc.restrict s] condexp_L2 \u211d hm f, from ae_restrict_of_ae hg_eq,\n  have hg_nnnorm_eq : (\u03bb x, (\u2016g x\u2016\u208a : \u211d\u22650\u221e))\n    =\u1d50[\u03bc.restrict s] (\u03bb x, (\u2016condexp_L2 \u211d hm f x\u2016\u208a : \u211d\u22650\u221e)),\n  { refine hg_eq_restrict.mono (\u03bb x hx, _),\n    dsimp only,\n    rw hx, },\n  rw lintegral_congr_ae hg_nnnorm_eq.symm,\n  refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm\n    (Lp.strongly_measurable f) _ _ _ _ hs h\u03bcs,\n  { exact integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs, },\n  { exact hg_meas, },\n  { rw [integrable_on, integrable_congr hg_eq_restrict],\n    exact integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs f, },\n  { intros t ht h\u03bct,\n    rw \u2190 integral_condexp_L2_eq_of_fin_meas_real f ht h\u03bct.ne,\n    exact set_integral_congr_ae (hm t ht) (hg_eq.mono (\u03bb x hx _, hx)), },\nend\n\nlemma condexp_L2_ae_eq_zero_of_ae_eq_zero (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  {f : Lp \u211d 2 \u03bc} (hf : f =\u1d50[\u03bc.restrict s] 0) :\n  condexp_L2 \u211d hm f =\u1d50[\u03bc.restrict s] 0 :=\nbegin\n  suffices h_nnnorm_eq_zero : \u222b\u207b x in s, \u2016condexp_L2 \u211d hm f x\u2016\u208a \u2202\u03bc = 0,\n  { rw lintegral_eq_zero_iff at h_nnnorm_eq_zero,\n    refine h_nnnorm_eq_zero.mono (\u03bb x hx, _),\n    dsimp only at hx,\n    rw pi.zero_apply at hx \u22a2,\n    { rwa [ennreal.coe_eq_zero, nnnorm_eq_zero] at hx, },\n    { refine measurable.coe_nnreal_ennreal (measurable.nnnorm _),\n      rw Lp_meas_coe,\n      exact (Lp.strongly_measurable _).measurable }, },\n  refine le_antisymm _ (zero_le _),\n  refine (lintegral_nnnorm_condexp_L2_le hs h\u03bcs f).trans (le_of_eq _),\n  rw lintegral_eq_zero_iff,\n  { refine hf.mono (\u03bb x hx, _),\n    dsimp only,\n    rw hx,\n    simp, },\n  { exact (Lp.strongly_measurable _).ennnorm, },\nend\n\nlemma lintegral_nnnorm_condexp_L2_indicator_le_real\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2016condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2016\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) :=\nbegin\n  refine (lintegral_nnnorm_condexp_L2_le ht h\u03bct _).trans (le_of_eq _),\n  have h_eq : \u222b\u207b x in t, \u2016(indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) x\u2016\u208a \u2202\u03bc\n    = \u222b\u207b x in t, s.indicator (\u03bb x, (1 : \u211d\u22650\u221e)) x \u2202\u03bc,\n  { refine lintegral_congr_ae (ae_restrict_of_ae _),\n    refine (@indicator_const_Lp_coe_fn _ _ _ 2 _ _ _ hs h\u03bcs (1 : \u211d)).mono (\u03bb x hx, _),\n    rw hx,\n    classical,\n    simp_rw set.indicator_apply,\n    split_ifs; simp, },\n  rw [h_eq, lintegral_indicator _ hs, lintegral_const, measure.restrict_restrict hs],\n  simp only [one_mul, set.univ_inter, measurable_set.univ, measure.restrict_apply],\nend\n\nend real\n\n/-- `condexp_L2` commutes with taking inner products with constants. See the lemma\n`condexp_L2_comp_continuous_linear_map` for a more general result about commuting with continuous\nlinear maps. -/\nlemma condexp_L2_const_inner (hm : m \u2264 m0) (f : Lp E 2 \u03bc) (c : E) :\n  condexp_L2 \ud835\udd5c hm (((Lp.mem_\u2112p f).const_inner c).to_Lp (\u03bb a, \u27eac, f a\u27eb))\n    =\u1d50[\u03bc] \u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb :=\nbegin\n  rw Lp_meas_coe,\n  have h_mem_Lp : mem_\u2112p (\u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb) 2 \u03bc,\n  { refine mem_\u2112p.const_inner _ _, rw Lp_meas_coe, exact Lp.mem_\u2112p _, },\n  have h_eq : h_mem_Lp.to_Lp _ =\u1d50[\u03bc] \u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb, from h_mem_Lp.coe_fn_to_Lp,\n  refine eventually_eq.trans _ h_eq,\n  refine Lp.ae_eq_of_forall_set_integral_eq' \ud835\udd5c hm _ _ two_ne_zero ennreal.coe_ne_top\n    (\u03bb s hs h\u03bcs, integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _) _ _ _ _,\n  { intros s hs h\u03bcs,\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae h_eq)],\n    exact (integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _).const_inner _, },\n  { intros s hs h\u03bcs,\n    rw [\u2190 Lp_meas_coe, integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs.ne,\n      integral_congr_ae (ae_restrict_of_ae h_eq), Lp_meas_coe,\n      \u2190 L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c \u2191(condexp_L2 \ud835\udd5c hm f) (hm s hs) c h\u03bcs.ne,\n      \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable,\n      L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c f (hm s hs) c h\u03bcs.ne,\n      set_integral_congr_ae (hm s hs)\n        ((mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).const_inner c)).mono (\u03bb x hx hxs, hx))], },\n  { rw \u2190 Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },\n  { refine ae_strongly_measurable'.congr _ h_eq.symm,\n    exact (Lp_meas.ae_strongly_measurable' _).const_inner _, },\nend\n\n/-- `condexp_L2` verifies the equality of integrals defining the conditional expectation. -/\nlemma integral_condexp_L2_eq (hm : m \u2264 m0)\n  (f : Lp E' 2 \u03bc) (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw [\u2190 sub_eq_zero, Lp_meas_coe, \u2190 integral_sub'\n      (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)\n      (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)],\n  refine integral_eq_zero_of_forall_integral_inner_eq_zero \ud835\udd5c _ _ _,\n  { rw integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub \u2191(condexp_L2 \ud835\udd5c hm f) f).symm),\n    exact integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs, },\n  intro c,\n  simp_rw [pi.sub_apply, inner_sub_right],\n  rw integral_sub\n    ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).const_inner c)\n    ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).const_inner c),\n  have h_ae_eq_f := mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).const_inner c),\n  rw [\u2190 Lp_meas_coe, sub_eq_zero,\n    \u2190 set_integral_congr_ae (hm s hs) ((condexp_L2_const_inner hm f c).mono (\u03bb x hx _, hx)),\n    \u2190 set_integral_congr_ae (hm s hs) (h_ae_eq_f.mono (\u03bb x hx _, hx))],\n  exact integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs,\nend\n\nvariables {E'' \ud835\udd5c' : Type*} [is_R_or_C \ud835\udd5c'] [normed_add_comm_group E'']\n  [inner_product_space \ud835\udd5c' E''] [complete_space E''] [normed_space \u211d E'']\n\nvariables (\ud835\udd5c \ud835\udd5c')\nlemma condexp_L2_comp_continuous_linear_map (hm : m \u2264 m0) (T : E' \u2192L[\u211d] E'') (f : \u03b1 \u2192\u2082[\u03bc] E') :\n  (condexp_L2 \ud835\udd5c' hm (T.comp_Lp f) : \u03b1 \u2192\u2082[\u03bc] E'') =\u1d50[\u03bc] T.comp_Lp (condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E') :=\nbegin\n  refine Lp.ae_eq_of_forall_set_integral_eq' \ud835\udd5c' hm _ _ two_ne_zero ennreal.coe_ne_top\n    (\u03bb s hs h\u03bcs, integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _)\n    (\u03bb s hs h\u03bcs, integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.ne)\n    _ _ _,\n  { intros s hs h\u03bcs,\n    rw [T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.ne),\n      \u2190 Lp_meas_coe, \u2190 Lp_meas_coe, integral_condexp_L2_eq hm f hs h\u03bcs.ne,\n      integral_condexp_L2_eq hm (T.comp_Lp f) hs h\u03bcs.ne, T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs.ne)], },\n  { rw \u2190 Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },\n  { have h_coe := T.coe_fn_comp_Lp (condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E'),\n    rw \u2190 eventually_eq at h_coe,\n    refine ae_strongly_measurable'.congr _ h_coe.symm,\n    exact (Lp_meas.ae_strongly_measurable' (condexp_L2 \ud835\udd5c hm f)).continuous_comp T.continuous, },\nend\nvariables {\ud835\udd5c \ud835\udd5c'}\n\nsection condexp_L2_indicator\n\nvariables (\ud835\udd5c)\nlemma condexp_L2_indicator_ae_eq_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (x : E') :\n  condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x)\n    =\u1d50[\u03bc] \u03bb a, (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x :=\nbegin\n  rw indicator_const_Lp_eq_to_span_singleton_comp_Lp hs h\u03bcs x,\n  have h_comp := condexp_L2_comp_continuous_linear_map \u211d \ud835\udd5c hm (to_span_singleton \u211d x)\n    (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)),\n  rw \u2190 Lp_meas_coe at h_comp,\n  refine h_comp.trans _,\n  exact (to_span_singleton \u211d x).coe_fn_comp_Lp _,\nend\n\nlemma condexp_L2_indicator_eq_to_span_singleton_comp (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') :\n  (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) : \u03b1 \u2192\u2082[\u03bc] E')\n    = (to_span_singleton \u211d x).comp_Lp (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  refine (condexp_L2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).trans _,\n  have h_comp := (to_span_singleton \u211d x).coe_fn_comp_Lp\n    (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) : \u03b1 \u2192\u2082[\u03bc] \u211d),\n  rw \u2190 eventually_eq at h_comp,\n  refine eventually_eq.trans _ h_comp.symm,\n  refine eventually_of_forall (\u03bb y, _),\n  refl,\nend\n\nvariables {\ud835\udd5c}\n\nlemma set_lintegral_nnnorm_condexp_L2_indicator_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') {t : set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2016condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2016\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :=\ncalc \u222b\u207b a in t, \u2016condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2016\u208a \u2202\u03bc\n    = \u222b\u207b a in t, \u2016(condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x\u2016\u208a \u2202\u03bc :\nset_lintegral_congr_fun (hm t ht)\n  ((condexp_L2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).mono (\u03bb a ha hat, by rw ha))\n... = \u222b\u207b a in t, \u2016condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2016\u208a \u2202\u03bc * \u2016x\u2016\u208a :\nbegin\n  simp_rw [nnnorm_smul, ennreal.coe_mul],\n  rw [lintegral_mul_const, Lp_meas_coe],\n  exact (Lp.strongly_measurable _).ennnorm\nend\n... \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :\n  mul_le_mul_right' (lintegral_nnnorm_condexp_L2_indicator_le_real hs h\u03bcs ht h\u03bct) _\n\nlemma lintegral_nnnorm_condexp_L2_indicator_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') [sigma_finite (\u03bc.trim hm)] :\n  \u222b\u207b a, \u2016condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2016\u208a \u2202\u03bc \u2264 \u03bc s * \u2016x\u2016\u208a :=\nbegin\n  refine lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a) _ (\u03bb t ht h\u03bct, _),\n  { rw Lp_meas_coe,\n    exact (Lp.ae_strongly_measurable _).ennnorm },\n  refine (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _,\n  exact mul_le_mul_right' (measure_mono (set.inter_subset_left _ _)) _\nend\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\nlemma integrable_condexp_L2_indicator (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') :\n  integrable (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x)) \u03bc :=\nbegin\n  refine integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a)\n    (ennreal.mul_lt_top h\u03bcs ennreal.coe_ne_top) _ _,\n  { rw Lp_meas_coe, exact Lp.ae_strongly_measurable _, },\n  { refine \u03bb t ht h\u03bct, (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _,\n    exact mul_le_mul_right' (measure_mono (set.inter_subset_left _ _)) _, },\nend\n\nend condexp_L2_indicator\n\nsection condexp_ind_smul\n\nvariables [normed_space \u211d G] {hm : m \u2264 m0}\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/\ndef condexp_ind_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : Lp G 2 \u03bc :=\n(to_span_singleton \u211d x).comp_LpL 2 \u03bc (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))\n\nlemma ae_strongly_measurable'_condexp_ind_smul\n  (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  ae_strongly_measurable' m (condexp_ind_smul hm hs h\u03bcs x) \u03bc :=\nbegin\n  have h : ae_strongly_measurable' m (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) \u03bc,\n    from ae_strongly_measurable'_condexp_L2 _ _,\n  rw condexp_ind_smul,\n  suffices : ae_strongly_measurable' m\n    ((to_span_singleton \u211d x) \u2218 (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))) \u03bc,\n  { refine ae_strongly_measurable'.congr this _,\n    refine eventually_eq.trans _ (coe_fn_comp_LpL _ _).symm,\n    rw Lp_meas_coe, },\n  exact ae_strongly_measurable'.continuous_comp (to_span_singleton \u211d x).continuous h,\nend\n\nlemma condexp_ind_smul_add (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n  condexp_ind_smul hm hs h\u03bcs (x + y)\n    = condexp_ind_smul hm hs h\u03bcs x + condexp_ind_smul hm hs h\u03bcs y :=\nby { simp_rw [condexp_ind_smul], rw [to_span_singleton_add, add_comp_LpL, add_apply], }\n\nlemma condexp_ind_smul_smul (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n  condexp_ind_smul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_smul hm hs h\u03bcs x :=\nby { simp_rw [condexp_ind_smul], rw [to_span_singleton_smul, smul_comp_LpL, smul_apply], }\n\nlemma condexp_ind_smul_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n  condexp_ind_smul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_smul hm hs h\u03bcs x :=\nby rw [condexp_ind_smul, condexp_ind_smul, to_span_singleton_smul',\n  (to_span_singleton \u211d x).smul_comp_LpL_apply c\n  \u2191(condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))]\n\nlemma condexp_ind_smul_ae_eq_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind_smul hm hs h\u03bcs x\n    =\u1d50[\u03bc] \u03bb a, (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x :=\n(to_span_singleton \u211d x).coe_fn_comp_LpL _\n\nlemma set_lintegral_nnnorm_condexp_ind_smul_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) {t : set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2016condexp_ind_smul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :=\ncalc \u222b\u207b a in t, \u2016condexp_ind_smul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc\n    = \u222b\u207b a in t, \u2016condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a \u2022 x\u2016\u208a \u2202\u03bc :\nset_lintegral_congr_fun (hm t ht)\n  ((condexp_ind_smul_ae_eq_smul hm hs h\u03bcs x).mono (\u03bb a ha hat, by rw ha ))\n... = \u222b\u207b a in t, \u2016condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2016\u208a \u2202\u03bc * \u2016x\u2016\u208a :\nbegin\n  simp_rw [nnnorm_smul, ennreal.coe_mul],\n  rw [lintegral_mul_const, Lp_meas_coe],\n  exact (Lp.strongly_measurable _).ennnorm\nend\n... \u2264 \u03bc (s \u2229 t) * \u2016x\u2016\u208a :\n  mul_le_mul_right' (lintegral_nnnorm_condexp_L2_indicator_le_real hs h\u03bcs ht h\u03bct) _\n\nlemma lintegral_nnnorm_condexp_ind_smul_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) [sigma_finite (\u03bc.trim hm)] :\n  \u222b\u207b a, \u2016condexp_ind_smul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc \u2264 \u03bc s * \u2016x\u2016\u208a :=\nbegin\n  refine lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a) _ (\u03bb t ht h\u03bct, _),\n  { exact (Lp.ae_strongly_measurable _).ennnorm },\n  refine (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _,\n  exact mul_le_mul_right' (measure_mono (set.inter_subset_left _ _)) _\nend\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\nlemma integrable_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  integrable (condexp_ind_smul hm hs h\u03bcs x) \u03bc :=\nbegin\n  refine integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2016x\u2016\u208a)\n    (ennreal.mul_lt_top h\u03bcs ennreal.coe_ne_top) _ _,\n  { exact Lp.ae_strongly_measurable _, },\n  { refine \u03bb t ht h\u03bct, (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _,\n    exact mul_le_mul_right' (measure_mono (set.inter_subset_left _ _)) _, },\nend\n\nlemma condexp_ind_smul_empty {x : G} :\n  condexp_ind_smul hm measurable_set.empty\n    ((@measure_empty _ _ \u03bc).le.trans_lt ennreal.coe_lt_top).ne x = 0 :=\nbegin\n  rw [condexp_ind_smul, indicator_const_empty],\n  simp only [coe_fn_coe_base, submodule.coe_zero, continuous_linear_map.map_zero],\nend\n\nlemma set_integral_condexp_L2_indicator (hs : measurable_set[m] s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b x in s, (condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d))) x \u2202\u03bc = (\u03bc (t \u2229 s)).to_real :=\ncalc \u222b x in s, (condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d))) x \u2202\u03bc\n    = \u222b x in s, indicator_const_Lp 2 ht h\u03bct (1 : \u211d) x \u2202\u03bc :\n      @integral_condexp_L2_eq\n        \u03b1 _ \u211d _ _ _ _ _ _ _ _ _ hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) hs h\u03bcs\n... = (\u03bc (t \u2229 s)).to_real \u2022 1 : set_integral_indicator_const_Lp (hm s hs) ht h\u03bct (1 : \u211d)\n... = (\u03bc (t \u2229 s)).to_real : by rw [smul_eq_mul, mul_one]\n\nlemma set_integral_condexp_ind_smul (hs : measurable_set[m] s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (x : G') :\n  \u222b a in s, (condexp_ind_smul hm ht h\u03bct x) a \u2202\u03bc = (\u03bc (t \u2229 s)).to_real \u2022 x :=\ncalc \u222b a in s, (condexp_ind_smul hm ht h\u03bct x) a \u2202\u03bc\n    = (\u222b a in s, (condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) a \u2022 x) \u2202\u03bc) :\n  set_integral_congr_ae (hm s hs) ((condexp_ind_smul_ae_eq_smul hm ht h\u03bct x).mono (\u03bb x hx hxs, hx))\n... = (\u222b a in s, condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) a \u2202\u03bc) \u2022 x :\n  integral_smul_const _ x\n... = (\u03bc (t \u2229 s)).to_real \u2022 x :\n  by rw set_integral_condexp_L2_indicator hs ht h\u03bcs h\u03bct\n\nlemma condexp_L2_indicator_nonneg (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  [sigma_finite (\u03bc.trim hm)] :\n  0 \u2264\u1d50[\u03bc] condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) :=\nbegin\n  have h : ae_strongly_measurable' m (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) \u03bc,\n    from ae_strongly_measurable'_condexp_L2 _ _,\n  refine eventually_le.trans_eq _ h.ae_eq_mk.symm,\n  refine @ae_le_of_ae_le_trim _ _ _ _ _ _ hm _ _ _,\n  refine ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite _ _,\n  { intros t ht h\u03bct,\n    refine @integrable.integrable_on _ _ m _ _ _ _ _,\n    refine integrable.trim hm _ _,\n    { rw integrable_congr h.ae_eq_mk.symm,\n      exact integrable_condexp_L2_indicator hm hs h\u03bcs _, },\n    { exact h.strongly_measurable_mk, }, },\n  { intros t ht h\u03bct,\n    rw \u2190 set_integral_trim hm h.strongly_measurable_mk ht,\n    have h_ae : \u2200\u1d50 x \u2202\u03bc, x \u2208 t \u2192 h.mk _ x = condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) x,\n    { filter_upwards [h.ae_eq_mk] with x hx,\n      exact \u03bb _, hx.symm, },\n    rw [set_integral_congr_ae (hm t ht) h_ae,\n      set_integral_condexp_L2_indicator ht hs ((le_trim hm).trans_lt h\u03bct).ne h\u03bcs],\n    exact ennreal.to_real_nonneg, },\nend\n\nlemma condexp_ind_smul_nonneg {E} [normed_lattice_add_comm_group E] [normed_space \u211d E]\n  [ordered_smul \u211d E] [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : E) (hx : 0 \u2264 x) :\n  0 \u2264\u1d50[\u03bc] condexp_ind_smul hm hs h\u03bcs x :=\nbegin\n  refine eventually_le.trans_eq _ (condexp_ind_smul_ae_eq_smul hm hs h\u03bcs x).symm,\n  filter_upwards [condexp_L2_indicator_nonneg hm hs h\u03bcs] with a ha,\n  exact smul_nonneg ha hx,\nend\n\nend condexp_ind_smul\n\nend condexp_L2\n\nsection condexp_ind\n\n/-! ## Conditional expectation of an indicator as a continuous linear map.\n\nThe goal of this section is to build\n`condexp_ind (hm : m \u2264 m0) (\u03bc : measure \u03b1) (s : set s) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G`, which\ntakes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`,\nseen as an element of `\u03b1 \u2192\u2081[\u03bc] G`.\n-/\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {s t : set \u03b1} [normed_space \u211d G]\n\nsection condexp_ind_L1_fin\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure,\nas a function in L1. -/\ndef condexp_ind_L1_fin (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)] (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : \u03b1 \u2192\u2081[\u03bc] G :=\n(integrable_condexp_ind_smul hm hs h\u03bcs x).to_L1 _\n\nlemma condexp_ind_L1_fin_ae_eq_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs x =\u1d50[\u03bc] condexp_ind_smul hm hs h\u03bcs x :=\n(integrable_condexp_ind_smul hm hs h\u03bcs x).coe_fn_to_L1\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma condexp_ind_L1_fin_add (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs (x + y)\n    = condexp_ind_L1_fin hm hs h\u03bcs x + condexp_ind_L1_fin hm hs h\u03bcs y :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  refine eventually_eq.trans _\n    (eventually_eq.add (mem_\u2112p.coe_fn_to_Lp _).symm (mem_\u2112p.coe_fn_to_Lp _).symm),\n  rw condexp_ind_smul_add,\n  refine (Lp.coe_fn_add _ _).trans (eventually_of_forall (\u03bb a, _)),\n  refl,\nend\n\nlemma condexp_ind_L1_fin_smul (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_L1_fin hm hs h\u03bcs x :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  rw condexp_ind_smul_smul hs h\u03bcs c x,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb y hy, _),\n  rw [pi.smul_apply, pi.smul_apply, hy],\nend\n\nlemma condexp_ind_L1_fin_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n  condexp_ind_L1_fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_L1_fin hm hs h\u03bcs x :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  rw condexp_ind_smul_smul' hs h\u03bcs c x,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb y hy, _),\n  rw [pi.smul_apply, pi.smul_apply, hy],\nend\n\nlemma norm_condexp_ind_L1_fin_le (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  \u2016condexp_ind_L1_fin hm hs h\u03bcs x\u2016 \u2264 (\u03bc s).to_real * \u2016x\u2016 :=\nbegin\n  have : 0 \u2264 \u222b (a : \u03b1), \u2016condexp_ind_L1_fin hm hs h\u03bcs x a\u2016 \u2202\u03bc,\n    from integral_nonneg (\u03bb a, norm_nonneg _),\n  rw [L1.norm_eq_integral_norm, \u2190 ennreal.to_real_of_real (norm_nonneg x), \u2190 ennreal.to_real_mul,\n    \u2190 ennreal.to_real_of_real this, ennreal.to_real_le_to_real ennreal.of_real_ne_top\n      (ennreal.mul_ne_top h\u03bcs ennreal.of_real_ne_top),\n    of_real_integral_norm_eq_lintegral_nnnorm],\n  swap, { rw [\u2190 mem_\u2112p_one_iff_integrable], exact Lp.mem_\u2112p _, },\n  have h_eq : \u222b\u207b a, \u2016condexp_ind_L1_fin hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc\n    = \u222b\u207b a, \u2016condexp_ind_smul hm hs h\u03bcs x a\u2016\u208a \u2202\u03bc,\n  { refine lintegral_congr_ae _,\n    refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb z hz, _),\n    dsimp only,\n    rw hz, },\n  rw [h_eq, of_real_norm_eq_coe_nnnorm],\n  exact lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x,\nend\n\nlemma condexp_ind_L1_fin_disjoint_union (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind_L1_fin hm (hs.union ht) ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne x\n  = condexp_ind_L1_fin hm hs h\u03bcs x + condexp_ind_L1_fin hm ht h\u03bct x :=\nbegin\n  ext1,\n  have h\u03bcst := ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm (hs.union ht) h\u03bcst x).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  have hs_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x,\n  have ht_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm ht h\u03bct x,\n  refine eventually_eq.trans _ (eventually_eq.add hs_eq.symm ht_eq.symm),\n  rw condexp_ind_smul,\n  rw indicator_const_Lp_disjoint_union hs ht h\u03bcs h\u03bct hst (1 : \u211d),\n  rw (condexp_L2 \u211d hm).map_add,\n  push_cast,\n  rw ((to_span_singleton \u211d x).comp_LpL 2 \u03bc).map_add,\n  refine (Lp.coe_fn_add _ _).trans _,\n  refine eventually_of_forall (\u03bb y, _),\n  refl,\nend\n\nend condexp_ind_L1_fin\n\nopen_locale classical\n\nsection condexp_ind_L1\n\n/-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets\nwhich are not both measurable and of finite measure is not used: we set it to 0. -/\ndef condexp_ind_L1 {m m0 : measurable_space \u03b1} (hm : m \u2264 m0) (\u03bc : measure \u03b1) (s : set \u03b1)\n  [sigma_finite (\u03bc.trim hm)] (x : G) :\n  \u03b1 \u2192\u2081[\u03bc] G :=\nif hs : measurable_set s \u2227 \u03bc s \u2260 \u221e then condexp_ind_L1_fin hm hs.1 hs.2 x else 0\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (x : G) :\n  condexp_ind_L1 hm \u03bc s x = condexp_ind_L1_fin hm hs h\u03bcs x :=\nby simp only [condexp_ind_L1, and.intro hs h\u03bcs, dif_pos, ne.def, not_false_iff, and_self]\n\nlemma condexp_ind_L1_of_measure_eq_top (h\u03bcs : \u03bc s = \u221e) (x : G) :\n  condexp_ind_L1 hm \u03bc s x = 0 :=\nby simp only [condexp_ind_L1, h\u03bcs, eq_self_iff_true, not_true, ne.def, dif_neg, not_false_iff,\n  and_false]\n\nlemma condexp_ind_L1_of_not_measurable_set (hs : \u00ac measurable_set s) (x : G) :\n  condexp_ind_L1 hm \u03bc s x = 0 :=\nby simp only [condexp_ind_L1, hs, dif_neg, not_false_iff, false_and]\n\nlemma condexp_ind_L1_add (x y : G) :\n  condexp_ind_L1 hm \u03bc s (x + y) = condexp_ind_L1 hm \u03bc s x + condexp_ind_L1 hm \u03bc s y :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw zero_add, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw zero_add, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_add hs h\u03bcs x y, },\nend\n\nlemma condexp_ind_L1_smul (c : \u211d) (x : G) :\n  condexp_ind_L1 hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind_L1 hm \u03bc s x :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw smul_zero, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_smul hs h\u03bcs c x, },\nend\n\nlemma condexp_ind_L1_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n  condexp_ind_L1 hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind_L1 hm \u03bc s x :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw smul_zero, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_smul' hs h\u03bcs c x, },\nend\n\nlemma norm_condexp_ind_L1_le (x : G) :\n  \u2016condexp_ind_L1 hm \u03bc s x\u2016 \u2264 (\u03bc s).to_real * \u2016x\u2016 :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw Lp.norm_zero,\n    exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { rw [condexp_ind_L1_of_measure_eq_top h\u03bcs x, Lp.norm_zero],\n    exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },\n  { rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x,\n    exact norm_condexp_ind_L1_fin_le hs h\u03bcs x, },\nend\n\nlemma continuous_condexp_ind_L1 : continuous (\u03bb x : G, condexp_ind_L1 hm \u03bc s x) :=\ncontinuous_of_linear_of_bound condexp_ind_L1_add condexp_ind_L1_smul norm_condexp_ind_L1_le\n\nlemma condexp_ind_L1_disjoint_union (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind_L1 hm \u03bc (s \u222a t) x = condexp_ind_L1 hm \u03bc s x + condexp_ind_L1 hm \u03bc t x :=\nbegin\n  have h\u03bcst : \u03bc (s \u222a t) \u2260 \u221e, from ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne,\n  rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top ht h\u03bct x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs.union ht) h\u03bcst x],\n  exact condexp_ind_L1_fin_disjoint_union hs ht h\u03bcs h\u03bct hst x,\nend\n\nend condexp_ind_L1\n\n/-- Conditional expectation of the indicator of a set, as a linear map from `G` to L1. -/\ndef condexp_ind {m m0 : measurable_space \u03b1} (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)]\n  (s : set \u03b1) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G :=\n{ to_fun    := condexp_ind_L1 hm \u03bc s,\n  map_add'  := condexp_ind_L1_add,\n  map_smul' := condexp_ind_L1_smul,\n  cont      := continuous_condexp_ind_L1, }\n\nlemma condexp_ind_ae_eq_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind hm \u03bc s x =\u1d50[\u03bc] condexp_ind_smul hm hs h\u03bcs x :=\nbegin\n  refine eventually_eq.trans _ (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x),\n  simp [condexp_ind, condexp_ind_L1, hs, h\u03bcs],\nend\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma ae_strongly_measurable'_condexp_ind (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  ae_strongly_measurable' m (condexp_ind hm \u03bc s x) \u03bc :=\nae_strongly_measurable'.congr (ae_strongly_measurable'_condexp_ind_smul hm hs h\u03bcs x)\n  (condexp_ind_ae_eq_condexp_ind_smul hm hs h\u03bcs x).symm\n\n@[simp] lemma condexp_ind_empty : condexp_ind hm \u03bc \u2205 = (0 : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) :=\nbegin\n  ext1,\n  ext1,\n  refine (condexp_ind_ae_eq_condexp_ind_smul hm measurable_set.empty (by simp) x).trans _,\n  rw condexp_ind_smul_empty,\n  refine (Lp.coe_fn_zero G 2 \u03bc).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_zero G 1 \u03bc).symm,\n  refl,\nend\n\nlemma condexp_ind_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n  condexp_ind hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind hm \u03bc s x :=\ncondexp_ind_L1_smul' c x\n\nlemma norm_condexp_ind_apply_le (x : G) : \u2016condexp_ind hm \u03bc s x\u2016 \u2264 (\u03bc s).to_real * \u2016x\u2016 :=\nnorm_condexp_ind_L1_le x\n\nlemma norm_condexp_ind_le : \u2016(condexp_ind hm \u03bc s : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G)\u2016 \u2264 (\u03bc s).to_real :=\ncontinuous_linear_map.op_norm_le_bound _ ennreal.to_real_nonneg norm_condexp_ind_apply_le\n\nlemma condexp_ind_disjoint_union_apply (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind hm \u03bc (s \u222a t) x = condexp_ind hm \u03bc s x + condexp_ind hm \u03bc t x :=\ncondexp_ind_L1_disjoint_union hs ht h\u03bcs h\u03bct hst x\n\nlemma condexp_ind_disjoint_union (hs : measurable_set s) (ht : measurable_set t) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) :\n  (condexp_ind hm \u03bc (s \u222a t) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) = condexp_ind hm \u03bc s + condexp_ind hm \u03bc t :=\nby { ext1, push_cast, exact condexp_ind_disjoint_union_apply hs ht h\u03bcs h\u03bct hst x, }\n\nvariables (G)\n\nlemma dominated_fin_meas_additive_condexp_ind (hm : m \u2264 m0) (\u03bc : measure \u03b1)\n  [sigma_finite (\u03bc.trim hm)] :\n  dominated_fin_meas_additive \u03bc (condexp_ind hm \u03bc : set \u03b1 \u2192 G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) 1 :=\n\u27e8\u03bb s t, condexp_ind_disjoint_union, \u03bb s _ _, norm_condexp_ind_le.trans (one_mul _).symm.le\u27e9\n\nvariables {G}\n\nlemma set_integral_condexp_ind (hs : measurable_set[m] s) (ht : measurable_set t) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (h\u03bct : \u03bc t \u2260 \u221e) (x : G') :\n  \u222b a in s, condexp_ind hm \u03bc t x a \u2202\u03bc = (\u03bc (t \u2229 s)).to_real \u2022 x :=\ncalc\n\u222b a in s, condexp_ind hm \u03bc t x a \u2202\u03bc = \u222b a in s, condexp_ind_smul hm ht h\u03bct x a \u2202\u03bc :\n  set_integral_congr_ae (hm s hs)\n    ((condexp_ind_ae_eq_condexp_ind_smul hm ht h\u03bct x).mono (\u03bb x hx hxs, hx))\n... = (\u03bc (t \u2229 s)).to_real \u2022 x : set_integral_condexp_ind_smul hs ht h\u03bcs h\u03bct x\n\nlemma condexp_ind_of_measurable (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : G) :\n  condexp_ind hm \u03bc s c = indicator_const_Lp 1 (hm s hs) h\u03bcs c :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ indicator_const_Lp_coe_fn.symm,\n  refine (condexp_ind_ae_eq_condexp_ind_smul hm (hm s hs) h\u03bcs c).trans _,\n  refine (condexp_ind_smul_ae_eq_smul hm (hm s hs) h\u03bcs c).trans _,\n  rw [Lp_meas_coe, condexp_L2_indicator_of_measurable hm hs h\u03bcs (1 : \u211d)],\n  refine (@indicator_const_Lp_coe_fn \u03b1 _ _ 2 \u03bc _ s (hm s hs) h\u03bcs (1 : \u211d)).mono (\u03bb x hx, _),\n  dsimp only,\n  rw hx,\n  by_cases hx_mem : x \u2208 s; simp [hx_mem],\nend\n\nlemma condexp_ind_nonneg {E} [normed_lattice_add_comm_group E] [normed_space \u211d E] [ordered_smul \u211d E]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : E) (hx : 0 \u2264 x) :\n  0 \u2264 condexp_ind hm \u03bc s x :=\nbegin\n  rw \u2190 coe_fn_le,\n  refine eventually_le.trans_eq _ (condexp_ind_ae_eq_condexp_ind_smul hm hs h\u03bcs x).symm,\n  exact (coe_fn_zero E 1 \u03bc).trans_le (condexp_ind_smul_nonneg hs h\u03bcs x hx),\nend\n\nend condexp_ind\n\nsection condexp_L1\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)] {f g : \u03b1 \u2192 F'} {s : set \u03b1}\n\n/-- Conditional expectation of a function as a linear map from `\u03b1 \u2192\u2081[\u03bc] F'` to itself. -/\ndef condexp_L1_clm (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)] :\n  (\u03b1 \u2192\u2081[\u03bc] F') \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] F' :=\nL1.set_to_L1 (dominated_fin_meas_additive_condexp_ind F' hm \u03bc)\n\nlemma condexp_L1_clm_smul (c : \ud835\udd5c) (f : \u03b1 \u2192\u2081[\u03bc] F') :\n  condexp_L1_clm hm \u03bc (c \u2022 f) = c \u2022 condexp_L1_clm hm \u03bc f :=\nL1.set_to_L1_smul (dominated_fin_meas_additive_condexp_ind F' hm \u03bc)\n  (\u03bb c s x, condexp_ind_smul' c x) c f\n\nlemma condexp_L1_clm_indicator_const_Lp (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n  (condexp_L1_clm hm \u03bc) (indicator_const_Lp 1 hs h\u03bcs x) = condexp_ind hm \u03bc s x :=\nL1.set_to_L1_indicator_const_Lp (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hs h\u03bcs x\n\nlemma condexp_L1_clm_indicator_const (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n  (condexp_L1_clm hm \u03bc) \u2191(simple_func.indicator_const 1 hs h\u03bcs x) = condexp_ind hm \u03bc s x :=\nby { rw Lp.simple_func.coe_indicator_const, exact condexp_L1_clm_indicator_const_Lp hs h\u03bcs x, }\n\n/-- Auxiliary lemma used in the proof of `set_integral_condexp_L1_clm`. -/\n\n\n/-- The integral of the conditional expectation `condexp_L1_clm` over an `m`-measurable set is equal\nto the integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\nlemma set_integral_condexp_L1_clm (f : \u03b1 \u2192\u2081[\u03bc] F') (hs : measurable_set[m] s) :\n  \u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  let S := spanning_sets (\u03bc.trim hm),\n  have hS_meas : \u2200 i, measurable_set[m] (S i) := measurable_spanning_sets (\u03bc.trim hm),\n  have hS_meas0 : \u2200 i, measurable_set (S i) := \u03bb i, hm _ (hS_meas i),\n  have hs_eq : s = \u22c3 i, S i \u2229 s,\n  { simp_rw set.inter_comm,\n    rw [\u2190 set.inter_Union, (Union_spanning_sets (\u03bc.trim hm)), set.inter_univ], },\n  have hS_finite : \u2200 i, \u03bc (S i \u2229 s) < \u221e,\n  { refine \u03bb i, (measure_mono (set.inter_subset_left _ _)).trans_lt _,\n    have hS_finite_trim := measure_spanning_sets_lt_top (\u03bc.trim hm) i,\n    rwa trim_measurable_set_eq hm (hS_meas i) at hS_finite_trim, },\n  have h_mono : monotone (\u03bb i, (S i) \u2229 s),\n  { intros i j hij x,\n    simp_rw set.mem_inter_iff,\n    exact \u03bb h, \u27e8monotone_spanning_sets (\u03bc.trim hm) hij h.1, h.2\u27e9, },\n  have h_eq_forall : (\u03bb i, \u222b x in (S i) \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc)\n      = \u03bb i, \u222b x in (S i) \u2229 s, f x \u2202\u03bc,\n    from funext (\u03bb i, set_integral_condexp_L1_clm_of_measure_ne_top f\n      (@measurable_set.inter \u03b1 m _ _ (hS_meas i) hs) (hS_finite i).ne),\n  have h_right : tendsto (\u03bb i, \u222b x in (S i) \u2229 s, f x \u2202\u03bc) at_top (\ud835\udcdd (\u222b x in s, f x \u2202\u03bc)),\n  { have h := tendsto_set_integral_of_monotone (\u03bb i, (hS_meas0 i).inter (hm s hs)) h_mono\n      (L1.integrable_coe_fn f).integrable_on,\n    rwa \u2190 hs_eq at h, },\n  have h_left : tendsto (\u03bb i, \u222b x in (S i) \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc) at_top\n    (\ud835\udcdd (\u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc)),\n  { have h := tendsto_set_integral_of_monotone (\u03bb i, (hS_meas0 i).inter (hm s hs))\n      h_mono (L1.integrable_coe_fn (condexp_L1_clm hm \u03bc f)).integrable_on,\n    rwa \u2190 hs_eq at h, },\n  rw h_eq_forall at h_left,\n  exact tendsto_nhds_unique h_left h_right,\nend\n\nlemma ae_strongly_measurable'_condexp_L1_clm (f : \u03b1 \u2192\u2081[\u03bc] F') :\n  ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc :=\nbegin\n  refine Lp.induction ennreal.one_ne_top\n    (\u03bb f : \u03b1 \u2192\u2081[\u03bc] F', ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc)\n    _ _ _ f,\n  { intros c s hs h\u03bcs,\n    rw condexp_L1_clm_indicator_const hs h\u03bcs.ne c,\n    exact ae_strongly_measurable'_condexp_ind hs h\u03bcs.ne c, },\n  { intros f g hf hg h_disj hfm hgm,\n    rw (condexp_L1_clm hm \u03bc).map_add,\n    refine ae_strongly_measurable'.congr _ (coe_fn_add _ _).symm,\n    exact ae_strongly_measurable'.add hfm hgm, },\n  { have : {f : Lp F' 1 \u03bc | ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc}\n        = (condexp_L1_clm hm \u03bc) \u207b\u00b9' {f | ae_strongly_measurable' m f \u03bc},\n      by refl,\n    rw this,\n    refine is_closed.preimage (condexp_L1_clm hm \u03bc).continuous _,\n    exact is_closed_ae_strongly_measurable' hm, },\nend\n\nlemma condexp_L1_clm_Lp_meas (f : Lp_meas F' \u211d m 1 \u03bc) :\n  condexp_L1_clm hm \u03bc (f : \u03b1 \u2192\u2081[\u03bc] F') = \u2191f :=\nbegin\n  let g := Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm f,\n  have hfg : f = (Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g,\n    by simp only [linear_isometry_equiv.symm_apply_apply],\n  rw hfg,\n  refine @Lp.induction \u03b1 F' m _ 1 (\u03bc.trim hm) _ ennreal.coe_ne_top\n    (\u03bb g : \u03b1 \u2192\u2081[\u03bc.trim hm] F',\n      condexp_L1_clm hm \u03bc ((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g : \u03b1 \u2192\u2081[\u03bc] F')\n        = \u2191((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g)) _ _ _ g,\n  { intros c s hs h\u03bcs,\n    rw [Lp.simple_func.coe_indicator_const, Lp_meas_to_Lp_trim_lie_symm_indicator hs h\u03bcs.ne c,\n      condexp_L1_clm_indicator_const_Lp],\n    exact condexp_ind_of_measurable hs ((le_trim hm).trans_lt h\u03bcs).ne c, },\n  { intros f g hf hg hfg_disj hf_eq hg_eq,\n    rw linear_isometry_equiv.map_add,\n    push_cast,\n    rw [map_add, hf_eq, hg_eq], },\n  { refine is_closed_eq _ _,\n    { refine (condexp_L1_clm hm \u03bc).continuous.comp (continuous_induced_dom.comp _),\n      exact linear_isometry_equiv.continuous _, },\n    { refine continuous_induced_dom.comp _,\n      exact linear_isometry_equiv.continuous _, }, },\nend\n\nlemma condexp_L1_clm_of_ae_strongly_measurable'\n  (f : \u03b1 \u2192\u2081[\u03bc] F') (hfm : ae_strongly_measurable' m f \u03bc) :\n  condexp_L1_clm hm \u03bc f = f :=\ncondexp_L1_clm_Lp_meas (\u27e8f, hfm\u27e9 : Lp_meas F' \u211d m 1 \u03bc)\n\n/-- Conditional expectation of a function, in L1. Its value is 0 if the function is not\nintegrable. The function-valued `condexp` should be used instead in most cases. -/\ndef condexp_L1 (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)] (f : \u03b1 \u2192 F') : \u03b1 \u2192\u2081[\u03bc] F' :=\nset_to_fun \u03bc (condexp_ind hm \u03bc) (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) f\n\nlemma condexp_L1_undef (hf : \u00ac integrable f \u03bc) : condexp_L1 hm \u03bc f = 0 :=\nset_to_fun_undef (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hf\n\nlemma condexp_L1_eq (hf : integrable f \u03bc) :\n  condexp_L1 hm \u03bc f = condexp_L1_clm hm \u03bc (hf.to_L1 f) :=\nset_to_fun_eq (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hf\n\n@[simp] lemma condexp_L1_zero : condexp_L1 hm \u03bc (0 : \u03b1 \u2192 F') = 0 :=\nset_to_fun_zero _\n\n@[simp] lemma condexp_L1_measure_zero (hm : m \u2264 m0) : condexp_L1 hm (0 : measure \u03b1) f = 0 :=\nset_to_fun_measure_zero _ rfl\n\nlemma ae_strongly_measurable'_condexp_L1 {f : \u03b1 \u2192 F'} :\n  ae_strongly_measurable' m (condexp_L1 hm \u03bc f) \u03bc :=\nbegin\n  by_cases hf : integrable f \u03bc,\n  { rw condexp_L1_eq hf,\n    exact ae_strongly_measurable'_condexp_L1_clm _, },\n  { rw condexp_L1_undef hf,\n    refine ae_strongly_measurable'.congr _ (coe_fn_zero _ _ _).symm,\n    exact strongly_measurable.ae_strongly_measurable' (@strongly_measurable_zero _ _ m _ _), },\nend\n\nlemma condexp_L1_congr_ae (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)] (h : f =\u1d50[\u03bc] g) :\n  condexp_L1 hm \u03bc f = condexp_L1 hm \u03bc g :=\nset_to_fun_congr_ae _ h\n\nlemma integrable_condexp_L1 (f : \u03b1 \u2192 F') : integrable (condexp_L1 hm \u03bc f) \u03bc :=\nL1.integrable_coe_fn _\n\n/-- The integral of the conditional expectation `condexp_L1` over an `m`-measurable set is equal to\nthe integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\nlemma set_integral_condexp_L1 (hf : integrable f \u03bc) (hs : measurable_set[m] s) :\n  \u222b x in s, condexp_L1 hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  simp_rw condexp_L1_eq hf,\n  rw set_integral_condexp_L1_clm (hf.to_L1 f) hs,\n  exact set_integral_congr_ae (hm s hs) ((hf.coe_fn_to_L1).mono (\u03bb x hx hxs, hx)),\nend\n\nlemma condexp_L1_add (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  condexp_L1 hm \u03bc (f + g) = condexp_L1 hm \u03bc f + condexp_L1 hm \u03bc g :=\nset_to_fun_add _ hf hg\n\nlemma condexp_L1_neg (f : \u03b1 \u2192 F') : condexp_L1 hm \u03bc (-f) = - condexp_L1 hm \u03bc f :=\nset_to_fun_neg _ f\n\nlemma condexp_L1_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : condexp_L1 hm \u03bc (c \u2022 f) = c \u2022 condexp_L1 hm \u03bc f :=\nset_to_fun_smul _ (\u03bb c _ x, condexp_ind_smul' c x) c f\n\nlemma condexp_L1_sub (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  condexp_L1 hm \u03bc (f - g) = condexp_L1 hm \u03bc f - condexp_L1 hm \u03bc g :=\nset_to_fun_sub _ hf hg\n\nlemma condexp_L1_of_ae_strongly_measurable'\n  (hfm : ae_strongly_measurable' m f \u03bc) (hfi : integrable f \u03bc) :\n  condexp_L1 hm \u03bc f =\u1d50[\u03bc] f :=\nbegin\n  rw condexp_L1_eq hfi,\n  refine eventually_eq.trans _ (integrable.coe_fn_to_L1 hfi),\n  rw condexp_L1_clm_of_ae_strongly_measurable',\n  exact ae_strongly_measurable'.congr hfm (integrable.coe_fn_to_L1 hfi).symm,\nend\n\nlemma condexp_L1_mono {E} [normed_lattice_add_comm_group E] [complete_space E] [normed_space \u211d E]\n  [ordered_smul \u211d E] {f g : \u03b1 \u2192 E}\n  (hf : integrable f \u03bc) (hg : integrable g \u03bc) (hfg : f \u2264\u1d50[\u03bc] g) :\n  condexp_L1 hm \u03bc f \u2264\u1d50[\u03bc] condexp_L1 hm \u03bc g :=\nbegin\n  rw coe_fn_le,\n  have h_nonneg : \u2200 s, measurable_set s \u2192 \u03bc s < \u221e \u2192 \u2200 x : E, 0 \u2264 x \u2192 0 \u2264 condexp_ind hm \u03bc s x,\n    from \u03bb s hs h\u03bcs x hx, condexp_ind_nonneg hs h\u03bcs.ne x hx,\n  exact set_to_fun_mono (dominated_fin_meas_additive_condexp_ind E hm \u03bc) h_nonneg hf hg hfg,\nend\n\nend condexp_L1\n\nsection condexp\n\n/-! ### Conditional expectation of a function -/\n\nopen_locale classical\n\nvariables {\ud835\udd5c} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f g : \u03b1 \u2192 F'} {s : set \u03b1}\n\n/-- Conditional expectation of a function. It is defined as 0 if any one of the following conditions\nis true:\n- `m` is not a sub-\u03c3-algebra of `m0`,\n- `\u03bc` is not \u03c3-finite with respect to `m`,\n- `f` is not integrable. -/\n@[irreducible]\ndef condexp (m : measurable_space \u03b1) {m0 : measurable_space \u03b1} (\u03bc : measure \u03b1) (f : \u03b1 \u2192 F') :\n  \u03b1 \u2192 F' :=\nif hm : m \u2264 m0\n  then if h : sigma_finite (\u03bc.trim hm) \u2227 integrable f \u03bc\n    then if strongly_measurable[m] f\n      then f\n      else (@ae_strongly_measurable'_condexp_L1 _ _ _ _ _ m m0 \u03bc hm h.1 _).mk\n        (@condexp_L1 _ _ _ _ _ _ _ hm \u03bc h.1 f)\n    else 0\n  else 0\n\n-- We define notation `\u03bc[f|m]` for the conditional expectation of `f` with respect to `m`.\nlocalized \"notation (name := measure_theory.condexp)\n  \u03bc `[` f `|` m `]` := measure_theory.condexp m \u03bc f\" in measure_theory\n\nlemma condexp_of_not_le (hm_not : \u00ac m \u2264 m0) : \u03bc[f|m] = 0 := by rw [condexp, dif_neg hm_not]\n\nlemma condexp_of_not_sigma_finite (hm : m \u2264 m0) (h\u03bcm_not : \u00ac sigma_finite (\u03bc.trim hm)) :\n  \u03bc[f|m] = 0 :=\nby { rw [condexp, dif_pos hm, dif_neg], push_neg, exact \u03bb h, absurd h h\u03bcm_not, }\n\nlemma condexp_of_sigma_finite (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)] :\n  \u03bc[f|m] =\n  if integrable f \u03bc\n    then if strongly_measurable[m] f\n      then f else ae_strongly_measurable'_condexp_L1.mk (condexp_L1 hm \u03bc f)\n    else 0 :=\nbegin\n  rw [condexp, dif_pos hm],\n  simp only [h\u03bcm, ne.def, true_and],\n  by_cases hf : integrable f \u03bc,\n  { rw [dif_pos hf, if_pos hf], },\n  { rw [dif_neg hf, if_neg hf], },\nend\n\nlemma condexp_of_strongly_measurable (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  {f : \u03b1 \u2192 F'} (hf : strongly_measurable[m] f) (hfi : integrable f \u03bc) :\n  \u03bc[f|m] = f :=\nby { rw [condexp_of_sigma_finite hm, if_pos hfi, if_pos hf], apply_instance, }\n\nlemma condexp_const (hm : m \u2264 m0) (c : F') [is_finite_measure \u03bc] : \u03bc[(\u03bb x : \u03b1, c)|m] = \u03bb _, c :=\ncondexp_of_strongly_measurable hm (@strongly_measurable_const _ _ m _ _) (integrable_const c)\n\nlemma condexp_ae_eq_condexp_L1 (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  (f : \u03b1 \u2192 F') : \u03bc[f|m] =\u1d50[\u03bc] condexp_L1 hm \u03bc f :=\nbegin\n  rw condexp_of_sigma_finite hm,\n  by_cases hfi : integrable f \u03bc,\n  { rw if_pos hfi,\n    by_cases hfm : strongly_measurable[m] f,\n    { rw if_pos hfm,\n      exact (condexp_L1_of_ae_strongly_measurable'\n        (strongly_measurable.ae_strongly_measurable' hfm) hfi).symm, },\n    { rw if_neg hfm,\n      exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm, }, },\n  rw [if_neg hfi, condexp_L1_undef hfi],\n  exact (coe_fn_zero _ _ _).symm,\nend\n\nlemma condexp_ae_eq_condexp_L1_clm (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)] (hf : integrable f \u03bc) :\n  \u03bc[f|m] =\u1d50[\u03bc] condexp_L1_clm hm \u03bc (hf.to_L1 f) :=\nbegin\n  refine (condexp_ae_eq_condexp_L1 hm f).trans (eventually_of_forall (\u03bb x, _)),\n  rw condexp_L1_eq hf,\nend\n\nlemma condexp_undef (hf : \u00ac integrable f \u03bc) : \u03bc[f|m] = 0 :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  rw [condexp_of_sigma_finite, if_neg hf],\nend\n\n@[simp] lemma condexp_zero : \u03bc[(0 : \u03b1 \u2192 F')|m] = 0 :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  exact condexp_of_strongly_measurable hm (@strongly_measurable_zero _ _ m _ _)\n    (integrable_zero _ _ _),\nend\n\nlemma strongly_measurable_condexp : strongly_measurable[m] (\u03bc[f|m]) :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, exact strongly_measurable_zero, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, exact strongly_measurable_zero, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  rw condexp_of_sigma_finite hm,\n  swap, { apply_instance, },\n  split_ifs with hfi hfm,\n  { exact hfm, },\n  { exact ae_strongly_measurable'.strongly_measurable_mk _, },\n  { exact strongly_measurable_zero, },\nend\n\nlemma condexp_congr_ae (h : f =\u1d50[\u03bc] g) : \u03bc[f | m] =\u1d50[\u03bc] \u03bc[g | m] :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  exact (condexp_ae_eq_condexp_L1 hm f).trans\n    (filter.eventually_eq.trans (by rw condexp_L1_congr_ae hm h)\n    (condexp_ae_eq_condexp_L1 hm g).symm),\nend\n\nlemma condexp_of_ae_strongly_measurable' (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  {f : \u03b1 \u2192 F'} (hf : ae_strongly_measurable' m f \u03bc) (hfi : integrable f \u03bc) :\n  \u03bc[f|m] =\u1d50[\u03bc] f :=\nbegin\n  refine ((condexp_congr_ae hf.ae_eq_mk).trans _).trans hf.ae_eq_mk.symm,\n  rw condexp_of_strongly_measurable hm hf.strongly_measurable_mk\n    ((integrable_congr hf.ae_eq_mk).mp hfi),\nend\n\nlemma integrable_condexp : integrable (\u03bc[f|m]) \u03bc :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { rw condexp_of_not_le hm, exact integrable_zero _ _ _, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { rw condexp_of_not_sigma_finite hm h\u03bcm, exact integrable_zero _ _ _, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  exact (integrable_condexp_L1 f).congr (condexp_ae_eq_condexp_L1 hm f).symm,\nend\n\n/-- The integral of the conditional expectation `\u03bc[f|hm]` over an `m`-measurable set is equal to\nthe integral of `f` on that set. -/\nlemma set_integral_condexp (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hf : integrable f \u03bc) (hs : measurable_set[m] s) :\n  \u222b x in s, \u03bc[f|m] x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw set_integral_congr_ae (hm s hs) ((condexp_ae_eq_condexp_L1 hm f).mono (\u03bb x hx _, hx)),\n  exact set_integral_condexp_L1 hf hs,\nend\n\nlemma integral_condexp (hm : m \u2264 m0) [h\u03bcm : sigma_finite (\u03bc.trim hm)]\n  (hf : integrable f \u03bc) : \u222b x, \u03bc[f|m] x \u2202\u03bc = \u222b x, f x \u2202\u03bc :=\nbegin\n  suffices : \u222b x in set.univ, \u03bc[f|m] x \u2202\u03bc = \u222b x in set.univ, f x \u2202\u03bc,\n    by { simp_rw integral_univ at this, exact this, },\n  exact set_integral_condexp hm hf (@measurable_set.univ _ m),\nend\n\n/-- **Uniqueness of the conditional expectation**\nIf a function is a.e. `m`-measurable, verifies an integrability condition and has same integral\nas `f` on all `m`-measurable sets, then it is a.e. equal to `\u03bc[f|hm]`. -/\nlemma ae_eq_condexp_of_forall_set_integral_eq (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  {f g : \u03b1 \u2192 F'} (hf : integrable f \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hg_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, g x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc)\n  (hgm : ae_strongly_measurable' m g \u03bc) :\n  g =\u1d50[\u03bc] \u03bc[f|m] :=\nbegin\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm hg_int_finite\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on) (\u03bb s hs h\u03bcs, _) hgm\n    (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),\n  rw [hg_eq s hs h\u03bcs, set_integral_condexp hm hf hs],\nend\n\nlemma condexp_bot' [h\u03bc : \u03bc.ae.ne_bot] (f : \u03b1 \u2192 F') :\n  \u03bc[f|\u22a5] = \u03bb _, (\u03bc set.univ).to_real\u207b\u00b9 \u2022 \u222b x, f x \u2202\u03bc :=\nbegin\n  by_cases h\u03bc_finite : is_finite_measure \u03bc,\n  swap,\n  { have h : \u00ac sigma_finite (\u03bc.trim bot_le),\n    { rwa sigma_finite_trim_bot_iff, },\n    rw not_is_finite_measure_iff at h\u03bc_finite,\n    rw [condexp_of_not_sigma_finite bot_le h],\n    simp only [h\u03bc_finite, ennreal.top_to_real, inv_zero, zero_smul],\n    refl, },\n  haveI : is_finite_measure \u03bc := h\u03bc_finite,\n  by_cases hf : integrable f \u03bc,\n  swap, { rw [integral_undef hf, smul_zero, condexp_undef hf], refl, },\n  have h_meas : strongly_measurable[\u22a5] (\u03bc[f|\u22a5]) := strongly_measurable_condexp,\n  obtain \u27e8c, h_eq\u27e9 := strongly_measurable_bot_iff.mp h_meas,\n  rw h_eq,\n  have h_integral : \u222b x, \u03bc[f|\u22a5] x \u2202\u03bc = \u222b x, f x \u2202\u03bc := integral_condexp bot_le hf,\n  simp_rw [h_eq, integral_const] at h_integral,\n  rw [\u2190 h_integral, \u2190 smul_assoc, smul_eq_mul, inv_mul_cancel, one_smul],\n  rw [ne.def, ennreal.to_real_eq_zero_iff, auto.not_or_eq, measure.measure_univ_eq_zero,\n    \u2190 ae_eq_bot, \u2190 ne.def, \u2190 ne_bot_iff],\n  exact \u27e8h\u03bc, measure_ne_top \u03bc set.univ\u27e9,\nend\n\nlemma condexp_bot_ae_eq (f : \u03b1 \u2192 F') :\n  \u03bc[f|\u22a5] =\u1d50[\u03bc] \u03bb _, (\u03bc set.univ).to_real\u207b\u00b9 \u2022 \u222b x, f x \u2202\u03bc :=\nbegin\n  by_cases \u03bc.ae.ne_bot,\n  { refine eventually_of_forall (\u03bb x, _),\n    rw condexp_bot' f,\n    exact h, },\n  { rw [ne_bot_iff, not_not, ae_eq_bot] at h,\n    simp only [h, ae_zero], },\nend\n\nlemma condexp_bot [is_probability_measure \u03bc] (f : \u03b1 \u2192 F') :\n  \u03bc[f|\u22a5] = \u03bb _, \u222b x, f x \u2202\u03bc :=\nby { refine (condexp_bot' f).trans _, rw [measure_univ, ennreal.one_to_real, inv_one, one_smul], }\n\nlemma condexp_add (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  \u03bc[f + g | m] =\u1d50[\u03bc] \u03bc[f|m] + \u03bc[g|m] :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, simp, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, simp, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  refine (condexp_ae_eq_condexp_L1 hm _).trans _,\n  rw condexp_L1_add hf hg,\n  exact (coe_fn_add _ _).trans\n    ((condexp_ae_eq_condexp_L1 hm _).symm.add (condexp_ae_eq_condexp_L1 hm _).symm),\nend\n\nlemma condexp_finset_sum {\u03b9 : Type*} {s : finset \u03b9} {f : \u03b9 \u2192 \u03b1 \u2192 F'}\n  (hf : \u2200 i \u2208 s, integrable (f i) \u03bc) :\n  \u03bc[\u2211 i in s, f i | m] =\u1d50[\u03bc] \u2211 i in s, \u03bc[f i | m] :=\nbegin\n  induction s using finset.induction_on with i s his heq hf,\n  { rw [finset.sum_empty, finset.sum_empty, condexp_zero] },\n  { rw [finset.sum_insert his, finset.sum_insert his],\n    exact (condexp_add (hf i $ finset.mem_insert_self i s) $ integrable_finset_sum' _\n      (\u03bb j hmem, hf j $ finset.mem_insert_of_mem hmem)).trans\n      ((eventually_eq.refl _ _).add (heq $ \u03bb j hmem, hf j $ finset.mem_insert_of_mem hmem)) }\nend\n\nlemma condexp_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : \u03bc[c \u2022 f | m] =\u1d50[\u03bc] c \u2022 \u03bc[f|m] :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, simp, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, simp, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  refine (condexp_ae_eq_condexp_L1 hm _).trans _,\n  rw condexp_L1_smul c f,\n  refine (@condexp_ae_eq_condexp_L1 _ _ _ _ _ m _ _ hm _ f).mp _,\n  refine (coe_fn_smul c (condexp_L1 hm \u03bc f)).mono (\u03bb x hx1 hx2, _),\n  rw [hx1, pi.smul_apply, pi.smul_apply, hx2],\nend\n\nlemma condexp_neg (f : \u03b1 \u2192 F') : \u03bc[-f|m] =\u1d50[\u03bc] - \u03bc[f|m] :=\nby letI : module \u211d (\u03b1 \u2192 F') := @pi.module \u03b1 (\u03bb _, F') \u211d _ _ (\u03bb _, infer_instance);\ncalc \u03bc[-f|m] = \u03bc[(-1 : \u211d) \u2022 f|m] : by rw neg_one_smul \u211d f\n... =\u1d50[\u03bc] (-1 : \u211d) \u2022 \u03bc[f|m] : condexp_smul (-1) f\n... = -\u03bc[f|m] : neg_one_smul \u211d (\u03bc[f|m])\n\nlemma condexp_sub (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  \u03bc[f - g | m] =\u1d50[\u03bc] \u03bc[f|m] - \u03bc[g|m] :=\nbegin\n  simp_rw sub_eq_add_neg,\n  exact (condexp_add hf hg.neg).trans (eventually_eq.rfl.add (condexp_neg g)),\nend\n\nlemma condexp_condexp_of_le {m\u2081 m\u2082 m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} (hm\u2081\u2082 : m\u2081 \u2264 m\u2082)\n  (hm\u2082 : m\u2082 \u2264 m0) [sigma_finite (\u03bc.trim hm\u2082)] :\n  \u03bc[ \u03bc[f|m\u2082] | m\u2081] =\u1d50[\u03bc] \u03bc[f | m\u2081] :=\nbegin\n  by_cases h\u03bcm\u2081 : sigma_finite (\u03bc.trim (hm\u2081\u2082.trans hm\u2082)),\n  swap, { simp_rw condexp_of_not_sigma_finite (hm\u2081\u2082.trans hm\u2082) h\u03bcm\u2081, },\n  haveI : sigma_finite (\u03bc.trim (hm\u2081\u2082.trans hm\u2082)) := h\u03bcm\u2081,\n  by_cases hf : integrable f \u03bc,\n  swap, { simp_rw [condexp_undef hf, condexp_zero], },\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm\u2081\u2082.trans hm\u2082)\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on) (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on)\n    _ (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp)\n      (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),\n  intros s hs h\u03bcs,\n  rw set_integral_condexp (hm\u2081\u2082.trans hm\u2082) integrable_condexp hs,\n  swap, { apply_instance, },\n  rw [set_integral_condexp (hm\u2081\u2082.trans hm\u2082) hf hs, set_integral_condexp hm\u2082 hf (hm\u2081\u2082 s hs)],\nend\n\nlemma condexp_mono {E} [normed_lattice_add_comm_group E] [complete_space E] [normed_space \u211d E]\n  [ordered_smul \u211d E] {f g : \u03b1 \u2192 E} (hf : integrable f \u03bc) (hg : integrable g \u03bc) (hfg : f \u2264\u1d50[\u03bc] g) :\n  \u03bc[f | m] \u2264\u1d50[\u03bc] \u03bc[g | m] :=\nbegin\n  by_cases hm : m \u2264 m0,\n  swap, { simp_rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm),\n  swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  exact (condexp_ae_eq_condexp_L1 hm _).trans_le\n    ((condexp_L1_mono hf hg hfg).trans_eq (condexp_ae_eq_condexp_L1 hm _).symm),\nend\n\nlemma condexp_nonneg {E} [normed_lattice_add_comm_group E] [complete_space E] [normed_space \u211d E]\n  [ordered_smul \u211d E] {f : \u03b1 \u2192 E} (hf : 0 \u2264\u1d50[\u03bc] f) :\n  0 \u2264\u1d50[\u03bc] \u03bc[f | m] :=\nbegin\n  by_cases hfint : integrable f \u03bc,\n  { rw (condexp_zero.symm : (0 : \u03b1 \u2192 E) = \u03bc[0 | m]),\n    exact condexp_mono (integrable_zero _ _ _) hfint hf },\n  { rw condexp_undef hfint, }\nend\n\nlemma condexp_nonpos {E} [normed_lattice_add_comm_group E] [complete_space E] [normed_space \u211d E]\n  [ordered_smul \u211d E] {f : \u03b1 \u2192 E} (hf : f \u2264\u1d50[\u03bc] 0) :\n  \u03bc[f | m] \u2264\u1d50[\u03bc] 0 :=\nbegin\n  by_cases hfint : integrable f \u03bc,\n  { rw (condexp_zero.symm : (0 : \u03b1 \u2192 E) = \u03bc[0 | m]),\n    exact condexp_mono hfint (integrable_zero _ _ _) hf },\n  { rw condexp_undef hfint, }\nend\n\n/-- **Lebesgue dominated convergence theorem**: sufficient conditions under which almost\n  everywhere convergence of a sequence of functions implies the convergence of their image by\n  `condexp_L1`. -/\nlemma tendsto_condexp_L1_of_dominated_convergence (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  {fs : \u2115 \u2192 \u03b1 \u2192 F'} {f : \u03b1 \u2192 F'} (bound_fs : \u03b1 \u2192 \u211d)\n  (hfs_meas : \u2200 n, ae_strongly_measurable (fs n) \u03bc) (h_int_bound_fs : integrable bound_fs \u03bc)\n  (hfs_bound : \u2200 n, \u2200\u1d50 x \u2202\u03bc, \u2016fs n x\u2016 \u2264 bound_fs x)\n  (hfs : \u2200\u1d50 x \u2202\u03bc, tendsto (\u03bb n, fs n x) at_top (\ud835\udcdd (f x))) :\n  tendsto (\u03bb n, condexp_L1 hm \u03bc (fs n)) at_top (\ud835\udcdd (condexp_L1 hm \u03bc f)) :=\ntendsto_set_to_fun_of_dominated_convergence _ bound_fs hfs_meas h_int_bound_fs hfs_bound hfs\n\n/-- If two sequences of functions have a.e. equal conditional expectations at each step, converge\nand verify dominated convergence hypotheses, then the conditional expectations of their limits are\na.e. equal. -/\nlemma tendsto_condexp_unique (fs gs : \u2115 \u2192 \u03b1 \u2192 F') (f g : \u03b1 \u2192 F')\n  (hfs_int : \u2200 n, integrable (fs n) \u03bc) (hgs_int : \u2200 n, integrable (gs n) \u03bc)\n  (hfs : \u2200\u1d50 x \u2202\u03bc, tendsto (\u03bb n, fs n x) at_top (\ud835\udcdd (f x)))\n  (hgs : \u2200\u1d50 x \u2202\u03bc, tendsto (\u03bb n, gs n x) at_top (\ud835\udcdd (g x)))\n  (bound_fs : \u03b1 \u2192 \u211d) (h_int_bound_fs : integrable bound_fs \u03bc)\n  (bound_gs : \u03b1 \u2192 \u211d) (h_int_bound_gs : integrable bound_gs \u03bc)\n  (hfs_bound : \u2200 n, \u2200\u1d50 x \u2202\u03bc, \u2016fs n x\u2016 \u2264 bound_fs x)\n  (hgs_bound : \u2200 n, \u2200\u1d50 x \u2202\u03bc, \u2016gs n x\u2016 \u2264 bound_gs x)\n  (hfg : \u2200 n, \u03bc[fs n | m] =\u1d50[\u03bc] \u03bc[gs n | m]) :\n  \u03bc[f | m] =\u1d50[\u03bc] \u03bc[g | m] :=\nbegin\n  by_cases hm : m \u2264 m0, swap, { simp_rw condexp_of_not_le hm, },\n  by_cases h\u03bcm : sigma_finite (\u03bc.trim hm), swap, { simp_rw condexp_of_not_sigma_finite hm h\u03bcm, },\n  haveI : sigma_finite (\u03bc.trim hm) := h\u03bcm,\n  refine (condexp_ae_eq_condexp_L1 hm f).trans ((condexp_ae_eq_condexp_L1 hm g).trans _).symm,\n  rw \u2190 Lp.ext_iff,\n  have hn_eq : \u2200 n, condexp_L1 hm \u03bc (gs n) = condexp_L1 hm \u03bc (fs n),\n  { intros n,\n    ext1,\n    refine (condexp_ae_eq_condexp_L1 hm (gs n)).symm.trans ((hfg n).symm.trans _),\n    exact (condexp_ae_eq_condexp_L1 hm (fs n)), },\n  have hcond_fs : tendsto (\u03bb n, condexp_L1 hm \u03bc (fs n)) at_top (\ud835\udcdd (condexp_L1 hm \u03bc f)),\n    from tendsto_condexp_L1_of_dominated_convergence hm _ (\u03bb n, (hfs_int n).1) h_int_bound_fs\n       hfs_bound hfs,\n  have hcond_gs : tendsto (\u03bb n, condexp_L1 hm \u03bc (gs n)) at_top (\ud835\udcdd (condexp_L1 hm \u03bc g)),\n    from tendsto_condexp_L1_of_dominated_convergence hm _ (\u03bb n, (hgs_int n).1) h_int_bound_gs\n       hgs_bound hgs,\n  exact tendsto_nhds_unique_of_eventually_eq hcond_gs hcond_fs (eventually_of_forall hn_eq),\nend\n\nend condexp\n\nend measure_theory\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/function/conditional_expectation/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7060976510874016}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Joseph Myers\n\n! This file was ported from Lean 3 source module data.complex.exponential_bounds\n! leanprover-community/mathlib commit 402f8982dddc1864bd703da2d6e2ee304a866973\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Complex.Exponential\nimport Mathbin.Analysis.SpecialFunctions.Log.Deriv\n\n/-!\n# Bounds on specific values of the exponential\n-/\n\n\nnamespace Real\n\nopen IsAbsoluteValue Finset CauSeq Complex\n\ntheorem exp_one_near_10 : |exp 1 - 2244083 / 825552| \u2264 1 / 10 ^ 10 :=\n  by\n  apply exp_approx_start\n  iterate 13 refine' exp_1_approx_succ_eq (by norm_num1 <;> rfl) (by norm_cast <;> rfl) _\n  norm_num1\n  refine' exp_approx_end' _ (by norm_num1 <;> rfl) _ (by norm_cast <;> rfl) (by simp) _\n  rw [_root_.abs_one, abs_of_pos] <;> norm_num1\n#align real.exp_one_near_10 Real.exp_one_near_10\n\ntheorem exp_one_near_20 : |exp 1 - 363916618873 / 133877442384| \u2264 1 / 10 ^ 20 :=\n  by\n  apply exp_approx_start\n  iterate 21 refine' exp_1_approx_succ_eq (by norm_num1 <;> rfl) (by norm_cast <;> rfl) _\n  norm_num1\n  refine' exp_approx_end' _ (by norm_num1 <;> rfl) _ (by norm_cast <;> rfl) (by simp) _\n  rw [_root_.abs_one, abs_of_pos] <;> norm_num1\n#align real.exp_one_near_20 Real.exp_one_near_20\n\ntheorem exp_one_gt_d9 : 2.7182818283 < exp 1 :=\n  lt_of_lt_of_le (by norm_num) (sub_le_comm.1 (abs_sub_le_iff.1 exp_one_near_10).2)\n#align real.exp_one_gt_d9 Real.exp_one_gt_d9\n\ntheorem exp_one_lt_d9 : exp 1 < 2.7182818286 :=\n  lt_of_le_of_lt (sub_le_iff_le_add.1 (abs_sub_le_iff.1 exp_one_near_10).1) (by norm_num)\n#align real.exp_one_lt_d9 Real.exp_one_lt_d9\n\ntheorem exp_neg_one_gt_d9 : 0.36787944116 < exp (-1) :=\n  by\n  rw [exp_neg, lt_inv _ (exp_pos _)]\n  refine' lt_of_le_of_lt (sub_le_iff_le_add.1 (abs_sub_le_iff.1 exp_one_near_10).1) _\n  all_goals norm_num\n#align real.exp_neg_one_gt_d9 Real.exp_neg_one_gt_d9\n\ntheorem exp_neg_one_lt_d9 : exp (-1) < 0.3678794412 :=\n  by\n  rw [exp_neg, inv_lt (exp_pos _)]\n  refine' lt_of_lt_of_le _ (sub_le_comm.1 (abs_sub_le_iff.1 exp_one_near_10).2)\n  all_goals norm_num\n#align real.exp_neg_one_lt_d9 Real.exp_neg_one_lt_d9\n\ntheorem log_two_near_10 : |log 2 - 287209 / 414355| \u2264 1 / 10 ^ 10 :=\n  by\n  suffices |log 2 - 287209 / 414355| \u2264 1 / 17179869184 + (1 / 10 ^ 10 - 1 / 2 ^ 34)\n    by\n    norm_num1 at *\n    assumption\n  have t : |(2\u207b\u00b9 : \u211d)| = 2\u207b\u00b9 := by\n    rw [abs_of_pos]\n    norm_num\n  have z :=\n    Real.abs_log_sub_add_sum_range_le\n      (show |(2\u207b\u00b9 : \u211d)| < 1 by\n        rw [t]\n        norm_num)\n      34\n  rw [t] at z\n  norm_num1 at z\n  rw [one_div (2 : \u211d), log_inv, \u2190 sub_eq_add_neg, _root_.abs_sub_comm] at z\n  apply le_trans (_root_.abs_sub_le _ _ _) (add_le_add z _)\n  simp_rw [sum_range_succ]\n  norm_num\n  rw [abs_of_pos] <;> norm_num\n#align real.log_two_near_10 Real.log_two_near_10\n\ntheorem log_two_gt_d9 : 0.6931471803 < log 2 :=\n  lt_of_lt_of_le (by norm_num1) (sub_le_comm.1 (abs_sub_le_iff.1 log_two_near_10).2)\n#align real.log_two_gt_d9 Real.log_two_gt_d9\n\ntheorem log_two_lt_d9 : log 2 < 0.6931471808 :=\n  lt_of_le_of_lt (sub_le_iff_le_add.1 (abs_sub_le_iff.1 log_two_near_10).1) (by norm_num)\n#align real.log_two_lt_d9 Real.log_two_lt_d9\n\nend Real\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Complex/ExponentialBounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.7060976376310546}}
{"text": "/-\nCopyright (c) 2020 Kevin Lacker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Lacker\n-/\n\nimport data.nat.digits\n\n/-!\n# IMO 1960 Q1\n\nDetermine all three-digit numbers $N$ having the property that $N$ is divisible by 11, and\n$\\dfrac{N}{11}$ is equal to the sum of the squares of the digits of $N$.\n\nSince Lean doesn't have a way to directly express problem statements of the form\n\"Determine all X satisfying Y\", we express two predicates where proving that one implies the\nother is equivalent to solving the problem. A human solver also has to discover the\nsecond predicate.\n\nThe strategy here is roughly brute force, checking the possible multiples of 11.\n-/\n\nopen nat\n\nnamespace imo1960_q1\n\ndef sum_of_squares (L : list \u2115) : \u2115 := (L.map (\u03bb x, x * x)).sum\n\ndef problem_predicate (n : \u2115) : Prop :=\n(nat.digits 10 n).length = 3 \u2227 11 \u2223 n \u2227 n / 11 = sum_of_squares (nat.digits 10 n)\n\ndef solution_predicate (n : \u2115) : Prop := n = 550 \u2228 n = 803\n\n/-\nProving that three digit numbers are the ones in [100, 1000).\n-/\n\nlemma not_zero {n : \u2115} (h1 : problem_predicate n) : n \u2260 0 :=\nhave h2 : nat.digits 10 n \u2260 list.nil, from list.ne_nil_of_length_eq_succ h1.left,\ndigits_ne_nil_iff_ne_zero.mp h2\n\nlemma ge_100 {n : \u2115} (h1 : problem_predicate n) : 100 \u2264 n :=\nhave h2 : 10^3 \u2264 10 * n, begin\n  rw \u2190 h1.left,\n  refine nat.base_pow_length_digits_le 10 n _ (not_zero h1),\n  simp,\nend,\nby linarith\n\nlemma lt_1000 {n : \u2115} (h1 : problem_predicate n) : n < 1000 :=\nhave h2 : n < 10^3, begin\n  rw \u2190 h1.left,\n  refine nat.lt_base_pow_length_digits _,\n  simp,\nend,\nby linarith\n\n/-\nWe do an exhaustive search to show that all results are covered by `solution_predicate`.\n-/\n\ndef search_up_to (c n : \u2115) : Prop :=\nn = c * 11 \u2227 \u2200 m : \u2115, m < n \u2192 problem_predicate m \u2192 solution_predicate m\n\nlemma search_up_to_start : search_up_to 9 99 := \u27e8rfl, \u03bb n h p, by linarith [ge_100 p]\u27e9\n\nlemma search_up_to_step {c n} (H : search_up_to c n)\n  {c' n'} (ec : c + 1 = c') (en : n + 11 = n')\n  {l} (el : nat.digits 10 n = l)\n  (H' : c = sum_of_squares l \u2192 c = 50 \u2228 c = 73) :\n  search_up_to c' n' :=\nbegin\n  subst ec, subst en, subst el,\n  obtain \u27e8rfl, H\u27e9 := H,\n  refine \u27e8by ring, \u03bb m l p, _\u27e9,\n  obtain \u27e8h\u2081, \u27e8m, rfl\u27e9, h\u2082\u27e9 := id p,\n  by_cases h : 11 * m < c * 11, { exact H _ h p },\n  obtain rfl : m = c := by linarith,\n  rw [nat.mul_div_cancel_left _ (by norm_num : 11 > 0), mul_comm] at h\u2082,\n  refine (H' h\u2082).imp _ _; {rintro rfl, norm_num}\nend\n\nlemma search_up_to_end {c} (H : search_up_to c 1001)\n  {n : \u2115} (ppn : problem_predicate n) : solution_predicate n :=\nH.2 _ (by linarith [lt_1000 ppn]) ppn\n\nlemma right_direction {n : \u2115} : problem_predicate n \u2192 solution_predicate n :=\nbegin\n  have := search_up_to_start,\n  iterate 82\n  { replace := search_up_to_step this (by norm_num1; refl) (by norm_num1; refl)\n      (by norm_num1; refl) dec_trivial },\n  exact search_up_to_end this\nend\n\n/-\nNow we just need to prove the equivalence, for the precise problem statement.\n-/\n\nlemma left_direction (n : \u2115) (spn : solution_predicate n) : problem_predicate n :=\nby rcases spn with (rfl | rfl); norm_num [problem_predicate, sum_of_squares]\n\nend imo1960_q1\n\nopen imo1960_q1\n\ntheorem imo1960_q1 (n : \u2115) : problem_predicate n \u2194 solution_predicate n :=\n\u27e8right_direction, left_direction n\u27e9\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo1960_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7060976355858879}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthor: Leonardo de Moura\n\nDefine propositional calculus, valuation, provability, validity, prove soundness.\n\nThis file is based on Floris van Doorn Coq files.\n-/\nimport data.nat data.list\nopen nat bool list decidable\n\ndefinition PropVar [reducible] := nat\n\ninductive PropF :=\n| Var  : PropVar \u2192 PropF\n| Bot  : PropF\n| Conj : PropF \u2192 PropF \u2192 PropF\n| Disj : PropF \u2192 PropF \u2192 PropF\n| Impl : PropF \u2192 PropF \u2192 PropF\n\nnamespace PropF\n  notation `#`:max P:max := Var P\n  notation A \u2228 B         := Disj A B\n  notation A \u2227 B         := Conj A B\n  infixr `\u21d2`:27          := Impl\n  notation `\u22a5`           := Bot\n\n  definition Neg A       := A \u21d2 \u22a5\n  notation ~ A           := Neg A\n  definition Top         := ~\u22a5\n  notation `\u22a4`           := Top\n  definition BiImpl A B  := A \u21d2 B \u2227 B \u21d2 A\n  infixr `\u21d4`:27          := BiImpl\n\n  definition valuation   := PropVar \u2192 bool\n\n  definition TrueQ (v : valuation) : PropF \u2192 bool\n  | TrueQ (# P)   := v P\n  | TrueQ \u22a5       := ff\n  | TrueQ (A \u2228 B) := TrueQ A || TrueQ B\n  | TrueQ (A \u2227 B) := TrueQ A && TrueQ B\n  | TrueQ (A \u21d2 B) := bnot (TrueQ A) || TrueQ B\n\n  definition is_true [reducible] (b : bool) := b = tt\n\n  -- the valuation v satisfies a list of PropF, if forall (A : PropF) in \u0393,\n  -- (TrueQ v A) is tt (the Boolean true)\n  definition Satisfies v \u0393 := \u2200 A, A \u2208 \u0393 \u2192 is_true (TrueQ v A)\n  definition Models \u0393 A    := \u2200 v, Satisfies v \u0393 \u2192 is_true (TrueQ v A)\n\n  infix `\u22a8`:80 := Models\n\n  definition Valid p := [] \u22a8 p\n  reserve infix `\u22a2`:26\n\n  /- Provability -/\n\n  inductive Nc : list PropF \u2192 PropF \u2192 Prop :=\n  infix \u22a2 := Nc\n  | Nax   : \u2200 \u0393 A,   A \u2208 \u0393 \u2192             \u0393 \u22a2 A\n  | ImpI  : \u2200 \u0393 A B, A::\u0393 \u22a2 B \u2192          \u0393 \u22a2 A \u21d2 B\n  | ImpE  : \u2200 \u0393 A B, \u0393 \u22a2 A \u21d2 B \u2192 \u0393 \u22a2 A \u2192 \u0393 \u22a2 B\n  | BotC  : \u2200 \u0393 A,   (~A)::\u0393 \u22a2 \u22a5 \u2192       \u0393 \u22a2 A\n  | AndI  : \u2200 \u0393 A B, \u0393 \u22a2 A \u2192 \u0393 \u22a2 B \u2192     \u0393 \u22a2 A \u2227 B\n  | AndE\u2081 : \u2200 \u0393 A B, \u0393 \u22a2 A \u2227 B \u2192         \u0393 \u22a2 A\n  | AndE\u2082 : \u2200 \u0393 A B, \u0393 \u22a2 A \u2227 B \u2192         \u0393 \u22a2 B\n  | OrI\u2081  : \u2200 \u0393 A B, \u0393 \u22a2 A \u2192             \u0393 \u22a2 A \u2228 B\n  | OrI\u2082  : \u2200 \u0393 A B, \u0393 \u22a2 B \u2192             \u0393 \u22a2 A \u2228 B\n  | OrE   : \u2200 \u0393 A B C, \u0393 \u22a2 A \u2228 B \u2192 A::\u0393 \u22a2 C \u2192 B::\u0393 \u22a2 C \u2192 \u0393 \u22a2 C\n\n  infix \u22a2 := Nc\n\n  definition Provable A := [] \u22a2 A\n\n  definition Prop_Soundness := \u2200 A, Provable A \u2192 Valid A\n\n  definition Prop_Completeness := \u2200 A, Valid A \u2192 Provable A\n\n  open Nc\n\n  lemma weakening2 : \u2200 \u0393 A, \u0393 \u22a2 A \u2192 \u2200 \u0394, \u0393 \u2286 \u0394 \u2192 \u0394 \u22a2 A :=\n  \u03bb \u0393 A H, Nc.induction_on H\n    (\u03bb \u0393 A Hin \u0394 Hs,                   !Nax  (Hs A Hin))\n    (\u03bb \u0393 A B H w \u0394 Hs,                 !ImpI (w _ (cons_sub_cons A Hs)))\n    (\u03bb \u0393 A B H\u2081 H\u2082 w\u2081 w\u2082 \u0394 Hs,         !ImpE (w\u2081 _ Hs) (w\u2082 _ Hs))\n    (\u03bb \u0393 A H w \u0394 Hs,                   !BotC (w _ (cons_sub_cons (~A) Hs)))\n    (\u03bb \u0393 A B H\u2081 H\u2082 w\u2081 w\u2082 \u0394 Hs,         !AndI (w\u2081 _ Hs) (w\u2082 _ Hs))\n    (\u03bb \u0393 A B H w \u0394 Hs,                 !AndE\u2081 (w _ Hs))\n    (\u03bb \u0393 A B H w \u0394 Hs,                 !AndE\u2082 (w _ Hs))\n    (\u03bb \u0393 A B H w \u0394 Hs,                 !OrI\u2081 (w _ Hs))\n    (\u03bb \u0393 A B H w \u0394 Hs,                 !OrI\u2082 (w _ Hs))\n    (\u03bb \u0393 A B C H\u2081 H\u2082 H\u2083 w\u2081 w\u2082 w\u2083 \u0394 Hs, !OrE (w\u2081 _ Hs) (w\u2082 _ (cons_sub_cons A Hs)) (w\u2083 _ (cons_sub_cons B Hs)))\n\n  lemma weakening : \u2200 \u0393 \u0394 A, \u0393 \u22a2 A \u2192 \u0393++\u0394 \u22a2 A :=\n  \u03bb \u0393 \u0394 A H, weakening2 \u0393 A H (\u0393++\u0394) (sub_append_left \u0393 \u0394)\n\n  lemma deduction : \u2200 \u0393 A B, \u0393 \u22a2 A \u21d2 B \u2192 A::\u0393 \u22a2 B :=\n  \u03bb \u0393 A B H, ImpE _ A _ (!weakening2 H _ (sub_cons A \u0393)) (!Nax (mem_cons A \u0393))\n\n  lemma prov_impl : \u2200 A B, Provable (A \u21d2 B) \u2192 \u2200 \u0393, \u0393 \u22a2 A \u2192 \u0393 \u22a2 B :=\n  \u03bb A B Hp \u0393 Ha,\n    have wHp : \u0393 \u22a2 (A \u21d2 B), from !weakening Hp,\n    !ImpE wHp Ha\n\n  lemma Satisfies_cons : \u2200 {A \u0393 v}, Satisfies v \u0393 \u2192 is_true (TrueQ v A) \u2192 Satisfies v (A::\u0393) :=\n  \u03bb A \u0393 v s t B BinAG,\n    or.elim BinAG\n      (\u03bb e : B = A, by rewrite e; exact t)\n      (\u03bb i : B \u2208 \u0393, s _ i)\n\n  theorem Soundness_general : \u2200 A \u0393, \u0393 \u22a2 A \u2192 \u0393 \u22a8 A :=\n  \u03bb A \u0393 H, Nc.induction_on H\n    (\u03bb \u0393 A Hin v s,   (s _ Hin))\n    (\u03bb \u0393 A B H r v s,\n      by_cases\n        (\u03bb t : is_true (TrueQ v A),\n           have aux\u2081 : Satisfies v (A::\u0393), from Satisfies_cons s t,\n           have aux\u2082 : is_true (TrueQ v B), from r v aux\u2081,\n           bor_inr aux\u2082)\n        (\u03bb f : \u00ac is_true (TrueQ v A),\n           have aux : bnot (TrueQ v A) = tt, by rewrite (eq_ff_of_ne_tt f),\n           bor_inl aux))\n    (\u03bb \u0393 A B H\u2081 H\u2082 r\u2081 r\u2082 v s,\n       have aux\u2081 : bnot (TrueQ v A) || TrueQ v B = tt, from r\u2081 v s,\n       have aux\u2082 : TrueQ v A = tt, from r\u2082 v s,\n       by rewrite [aux\u2082 at aux\u2081, bnot_true at aux\u2081, ff_bor at aux\u2081]; exact aux\u2081)\n    (\u03bb \u0393 A H r v s, by_contradiction\n       (\u03bb n : TrueQ v A \u2260 tt,\n         have aux\u2081 : TrueQ v A    = ff, from eq_ff_of_ne_tt n,\n         have aux\u2082 : TrueQ v (~A) = tt, begin change (bnot (TrueQ v A) || ff = tt), rewrite aux\u2081 end,\n         have aux\u2083 : Satisfies v ((~A)::\u0393), from Satisfies_cons s aux\u2082,\n         have aux\u2084 : TrueQ v \u22a5 = tt, from r v aux\u2083,\n         absurd aux\u2084 ff_ne_tt))\n    (\u03bb \u0393 A B H\u2081 H\u2082 r\u2081 r\u2082 v s,\n      have aux\u2081 : TrueQ v A = tt, from r\u2081 v s,\n      have aux\u2082 : TrueQ v B = tt, from r\u2082 v s,\n      band_intro aux\u2081 aux\u2082)\n    (\u03bb \u0393 A B H r v s,\n      have aux : TrueQ v (A \u2227 B) = tt, from r v s,\n      band_elim_left aux)\n    (\u03bb \u0393 A B H r v s,\n      have aux : TrueQ v (A \u2227 B) = tt, from r v s,\n      band_elim_right aux)\n    (\u03bb \u0393 A B H r v s,\n      have aux : TrueQ v A = tt, from r v s,\n      bor_inl aux)\n    (\u03bb \u0393 A B H r v s,\n      have aux : TrueQ v B = tt, from r v s,\n      bor_inr aux)\n    (\u03bb \u0393 A B C H\u2081 H\u2082 H\u2083 r\u2081 r\u2082 r\u2083 v s,\n      have aux : TrueQ v A || TrueQ v B = tt, from r\u2081 v s,\n      or.elim (or_of_bor_eq aux)\n        (\u03bb At : TrueQ v A = tt,\n          have aux : Satisfies v (A::\u0393), from Satisfies_cons s At,\n          r\u2082 v aux)\n        (\u03bb Bt : TrueQ v B = tt,\n          have aux : Satisfies v (B::\u0393), from Satisfies_cons s Bt,\n          r\u2083 v aux))\n\n  theorem Soundness : Prop_Soundness :=\n  \u03bb A, Soundness_general A []\n\nend PropF\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/logic/examples/propositional/soundness.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7060877415930575}}
{"text": "import hilbertaxioms\nopen IncidencePlane\n\nopen_locale classical\nnoncomputable theory\n\n\nvariables {\u03a9 : Type} [IncidencePlane \u03a9]\nvariables {A B C D P Q R S : \u03a9}\nvariables {\u2113 r s t : Line \u03a9}\n\nlemma distinct_lines_have_at_most_one_common_point\n\t(hrs: r \u2260 s)\n\t(hAr: A \u2208 r) (hAs: A \u2208 s) (hBr: B \u2208 r) (hBs: B \u2208 s) :\n\tA = B :=\nbegin\n    by_contradiction hc,\n    apply hrs,\n    apply equal_lines_of_contain_two_points hc; assumption,\nend\n\nlemma segments_are_symmetric' : pts (A\u2b1dB) \u2286 pts (B\u2b1dA) :=\nbegin\n    intros x hx,\n    simp at *,\n    rw between_symmetric,\n    tauto,\nend\n\nlemma segments_are_symmetric : pts (A\u2b1dB) = pts (B\u2b1dA) :=\nbegin\n    apply set.subset.antisymm; exact segments_are_symmetric',\nend\n\n@[simp] lemma no_point_between_a_point (A x : \u03a9) : (A * x * A) \u2194 false :=\nbegin\n    split,\n    {\n        intro h,\n        have H := different_of_between h,\n        tauto,\n    },\n    tauto,\nend\n\n@[simp] lemma point_is_segment (A : \u03a9) : pts (A\u2b1dA) = {A} :=\nbegin\n    unfold pts,\n    simp,\nend\n\nlemma exists_point_on_line (\u2113 : Line \u03a9): \u2203 A : \u03a9, A \u2208 \u2113 :=\nbegin\n\thave I2 := line_contains_two_points \u2113,\n\trcases I2 with \u27e8 A, B, hAB, hA\u2113, hB\u2113\u27e9,\n    use A,\n    exact line_through_left A B,\nend\n\nlemma exists_point_not_on_line (\u2113 : Line \u03a9): \u2203 A : \u03a9, A \u2209 \u2113 :=\nbegin\n    rcases (existence \u03a9) with \u27e8A, B, C, \u27e8hAB, hAC, hBC, h\u27e9\u27e9,\n    by_cases hA : A \u2208 \u2113,\n    {\n        by_cases hB : B \u2208 \u2113,\n        {\n            use C,\n            rw (incidence hAB hA hB),\n            assumption,\n        },\n        use B,\n    },\n    use A,\nend\n\n\nlemma point_in_line_difference (h : r \u2260 s) :\n\t\u2203 A, A \u2208 r \u2227 A \u2209 s :=\nbegin\n\thave AB : \u2203 A B , A \u2260 B \u2227 r = line_through A B := line_contains_two_points r,\n\trcases AB with \u27e8 A, B, \u27e8 hAB, hAr, hBr\u27e9\u27e9,\n\thave h1 : A \u2209 s \u2228 B \u2209 s,\n\t{\n\t\tby_contradiction hcontra,\n        push_neg at hcontra,\n\t\tapply hAB,\n\t\tapply distinct_lines_have_at_most_one_common_point h,\n        {\n            apply line_through_left,\n        },\n        {\n            exact hcontra.1,\n        },\n        {\n            apply line_through_right,\n        },\n        {\n            exact hcontra.2,\n        }\n\t},\n\tcases h1 with h_isA h_isB,\n\twork_on_goal 1 {use A},\n\twork_on_goal 2 {use B},\n    all_goals {simp, tauto},\nend\n\n\nlemma between_points_share_line (hAr : A \u2208 r) (hCr : C \u2208 r) : \n\t(A * B * C) \u2192 B \u2208 r :=\nbegin\n    intro H,\n\thave h := collinear_of_between H,\n    rcases h with \u27e8s, \u27e8h1,h2,h3\u27e9\u27e9,\n    have hAC : A \u2260 C,\n    {\n        intro hAC,\n        rw hAC at H,\n        exact (no_point_between_a_point C B).mp H,\n    },\n    have htmp : r = s := equal_lines_of_contain_two_points hAC hAr h1 hCr h3,\n    rw htmp,\n    exact h2,\nend\n\n\nlemma between_points_share_line_v2 (hAr : A \u2208 r) (hBr : B \u2208 r) : \n\t(A * B * C) \u2192 C \u2208 r :=\nbegin\n    intro H,\n\thave h := collinear_of_between H,\n    rcases h with \u27e8s, \u27e8h1,h2,h3\u27e9\u27e9,     \n    have htmp : r = s := equal_lines_of_contain_two_points (different_of_between H).1 hAr h1 hBr h2,\n    rw htmp,\n    exact h3,\nend\n", "meta": {"author": "mmasdeu", "repo": "biysc2022", "sha": "3bc8e765e0486d4eabf406b66357ae9799eff837", "save_path": "github-repos/lean/mmasdeu-biysc2022", "path": "github-repos/lean/mmasdeu-biysc2022/biysc2022-3bc8e765e0486d4eabf406b66357ae9799eff837/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7060877349525001}}
{"text": "import group_theory.subgroup\nimport data.set.finite\nimport group_theory.coset\nimport data.fintype.card\nimport data.set.finite\nimport tactic\n\nopen_locale classical big_operators\nnoncomputable theory\n-- set_option profiler true\n\nlemma prod_finset_distinct_inv {\u03b1 : Type*} [comm_group \u03b1] {s : finset \u03b1} :\n  (\u2200 x \u2208 s, x\u207b\u00b9 \u2208 s) \u2192 (\u2200 x \u2208 s, x\u207b\u00b9 \u2260 x) \u2192 (\u220f x in s, x) = 1 :=\nbegin\napply finset.case_strong_induction_on s,\ntauto,\nintros a s a_notin_s H h1 h2,\nspecialize H (finset.erase s a\u207b\u00b9) (finset.erase_subset (a\u207b\u00b9) s),\nhave r : (\u220f x in (finset.erase s a\u207b\u00b9), x) = 1,\n{\n  apply H,\n  {\n    intros x h,\n    suffices : \u00acx = a \u2227 x\u207b\u00b9 \u2208 s, by simpa,\n    split,\n    {\n      have x_in_s : x \u2208 s := finset.mem_of_mem_erase h,\n      by_contradiction hc,\n      subst hc,\n      exact a_notin_s x_in_s,\n    },\n    suffices : x\u207b\u00b9 \u2260 a, from finset.mem_of_mem_insert_of_ne (h1 x (finset.mem_insert_of_mem (finset.mem_of_mem_erase h))) this,  \n    by_contradiction hh,\n    push_neg at hh,\n    induction hh,\n    simpa using finset.ne_of_mem_erase h,\n  },\n  {\n    intros x h,\n    apply h2,\n    exact finset.mem_insert_of_mem (finset.mem_of_mem_erase h)\n  }\n},\n{\n  rw finset.prod_insert a_notin_s,\n  suffices hkey : (\u220f x in s, x) = a\u207b\u00b9,\n  exact mul_eq_one_iff_inv_eq.mpr (eq.symm hkey),\n  have ainv_notin_s1 : a\u207b\u00b9 \u2209 finset.erase s a\u207b\u00b9 := finset.not_mem_erase a\u207b\u00b9 s,\n  have ainv_in_s : a\u207b\u00b9 \u2208 s,\n  {\n    have ainv_in_s1 : a\u207b\u00b9 \u2208 insert a s := h1 a (finset.mem_insert_self a s),\n    suffices : a\u207b\u00b9 \u2260 a, from finset.mem_of_mem_insert_of_ne ainv_in_s1 this,\n    exact h2 a (finset.mem_insert_self a s)\n  },\n  {\n    rw [\u2190finset.insert_erase ainv_in_s,finset.prod_insert ainv_notin_s1,r],\n    exact mul_one a\u207b\u00b9\n  },\n},\nend\n\nlemma prod_eq_one_of_non_twotorsion {G : Type*} [comm_group G] [fintype G] : (\u220f g in {x : G | x \u2260 x\u207b\u00b9 }.to_finset, g) = 1 :=\nbegin\n  apply prod_finset_distinct_inv;\n  finish,\nend\n\n\ndef two_torsion_subgroup (G : Type*) [comm_group G] : subgroup G :=\n{ carrier := {z : G | z * z = 1},\n  one_mem' := by simp,\n  mul_mem' := \u03bb a b (ha : a * a = 1) (hb : b * b = 1),\n  begin\n    dsimp at *,\n    rw [mul_mul_mul_comm a b a b, ha, hb],\n    refine mul_one 1,\n  end,\n  inv_mem' := \u03bb a (ha : a * a = 1), by {tidy, rw mul_inv_eq_one, refine inv_eq_of_mul_eq_one ha}\n}\n\nlemma mem_two_torsion_iff_square_eq_one (G : Type*) [comm_group G] :\n\u2200 x : G, x \u2208 two_torsion_subgroup G \u2194 x * x = 1 :=\nbegin\n  intro x,\n  refl,\nend\n\nlemma twotorsion_disjoint_non_twotorsion {G : Type*} [comm_group G]:\ndisjoint {x : G | x \u2208 two_torsion_subgroup G} {x : G | x \u2260 x\u207b\u00b9} :=\nbegin\n    intros x hx,\n    cases hx with h1 h2,\n    have hA : x * x = 1, by assumption,\n    suffices hB : x * x \u2260 1, by exact h2 (false.rec (x = x\u207b\u00b9) (hB hA)),\n    simpa [\u2190 mul_eq_one_iff_eq_inv] using h2,\nend\n\nlemma prod_all_eq_prod_two_torsion {G : Type*} [comm_group G] [fintype G]:\n(\u220f g : G, g) = (\u220f g : two_torsion_subgroup G, g) :=\nbegin\n    have H : (\u220f (g : G), g) = (\u220f x in {x : G | x \u2208 two_torsion_subgroup G}.to_finset, x)\n            * (\u220f x in {x : G | x \u2260 x\u207b\u00b9 }.to_finset, x),\n    {\n        rw \u2190 finset.prod_union,\n        {\n            congr, ext, safe,\n            suffices hh : a \u2208 two_torsion_subgroup G, tauto,\n            have a2: a * a = 1 := eq_inv_iff_mul_eq_one.mp h,\n            tauto,\n        },\n        {\n            apply finset.disjoint_iff_disjoint_coe.2,\n            simpa using twotorsion_disjoint_non_twotorsion,\n        },\n    },\n    {\n        simp [H, prod_eq_one_of_non_twotorsion],\n        apply finset.prod_subtype,\n        finish,\n    },\nend\n\nlemma two_products_id {\u03b1: Type*} {s : set \u03b1} [fintype s] [comm_monoid \u03b1] {t : finset \u03b1}\n (h: \u2200 x, x \u2208 s \u2194 x \u2208 t) : (\u220f g : s, \u2191g) = (\u220f g in t, g) := \nbegin\nrefine finset.prod_bij (\u03bb x _, x.1) _ _ _ _,\n{\n  intros a ha,\n  specialize h a,\n  apply h.mp,\n  exact subtype.mem a,\n},\n{\n  intros a ha,\n  refl,\n},\n{\n  intros a1 a2 h1 h2,\n  exact subtype.eq,\n},\n{\n  intros b hb,\n  specialize h b,\n  use b,\n  rw h,\n  exact hb,\n  split,\n  apply finset.mem_univ,\n  exact rfl,\n}\nend\n\nlemma two_products {\u03b1 \u03b2: Type*} {s : set \u03b1} [fintype s] [comm_monoid \u03b2] {t : finset \u03b1} {f : \u03b1 \u2192 \u03b2}\n (h: \u2200 x, x \u2208 s \u2194 x \u2208 t) : (\u220f g : s, f g) = (\u220f g in t, f g) := \nbegin\nrefine finset.prod_bij (\u03bb x _, x.1) _ _ _ _,\n{\n  intros a ha,\n  specialize h a,\n  apply h.mp,\n  exact subtype.mem a,\n},\n{\n  intros a ha,\n  refl,\n},\n{\n  intros a1 a2 h1 h2,\n  exact subtype.eq,\n},\n{\n  intros b hb,\n  specialize h b,\n  use b,\n  rw h,\n  exact hb,\n  split,\n  apply finset.mem_univ,\n  exact rfl,\n}\nend\n\nlemma prod_all_eq_prod_two_torsion' {G : Type*} [comm_group G] [fintype G]:\n(\u220f g : G, g) =  (\u220f g in ((two_torsion_subgroup G) : set G).to_finset, g) :=\nbegin\n  rw prod_all_eq_prod_two_torsion,\n  have h : ((two_torsion_subgroup G) : set G).to_finset = (two_torsion_subgroup G).carrier.to_finset,\n  {\n      refl,\n  },\n  apply two_products_id,\n  finish,\nend\n\nvariables {G : Type*} [comm_group G] [fintype G]\n\n/-\nIf a is a subgroup of G[2] and x \u2208 G[2], then a \u222a x *l a is a subgroup.\n-/\ndef insert_twotors_to_twotors {x : G} {a : subgroup G}\n  (hx : x * x = 1) (ha : \u2200 g : G, g \u2208 a \u2192 g * g = 1) : subgroup G :=\n{\n  carrier := \u2191a \u222a left_coset x a,\n  one_mem' := or.inl (subgroup.one_mem a),\n  mul_mem' := \n  begin\n    intros u v hu hv,\n    --rcases? hu hv,-- with \u27e8 hu1, hu2\u27e9 | \u27e8  hv1, hv2\u27e9 ,\n    cases hv with hv1 hv2,\n    repeat {cases hu with hu1 hu2},\n    {\n      exact or.inl (subgroup.mul_mem a hu1 hv1),\n    },\n    {\n      right,\n      rw [mem_left_coset_iff, \u2190mul_assoc],\n      rw mem_left_coset_iff at hu2,\n      exact subgroup.mul_mem a hu2 hv1,\n    },\n    {\n      right,\n      rw [mul_comm, mem_left_coset_iff, \u2190mul_assoc],\n      rw mem_left_coset_iff at hv2,\n      exact subgroup.mul_mem a hv2 hu1,\n    },\n    {\n      left,\n      rw mem_left_coset_iff at hu2 hv2,\n      have H : x\u207b\u00b9 * x\u207b\u00b9 * u * v \u2208 a,\n      {\n          norm_num at hu2 hv2 \u22a2,\n          rw [mul_comm, mul_assoc, \u2190mul_assoc v _, mul_comm v _],\n          exact subgroup.mul_mem a hv2 hu2,\n      },\n      have x_eq_xinv : x = x\u207b\u00b9 := eq_inv_of_mul_eq_one hx,\n      rw [\u2190x_eq_xinv, hx, one_mul] at H,\n      exact H,\n    }\n  end,\n  inv_mem' := \n  begin\n      intros u hu,\n      cases hu with hu1 hu2, by exact or.inl (subgroup.inv_mem a hu1),\n      {\n          right,\n          rw mem_left_coset_iff at hu2 \u22a2,\n          norm_num at hu2 \u22a2,\n          rw [\u2190subgroup.inv_mem_iff, mul_inv, inv_inv, inv_inv],\n          have x_eq_xinv : x = x\u207b\u00b9 := eq_inv_of_mul_eq_one hx,\n          rw \u2190x_eq_xinv at hu2,\n          exact hu2,\n      }\n  end\n}\n/--\nIf g \u2208 G[2] and a \u2264 G[2], then a \u222a g l* a \u2286 G[2].\n--/\nlemma twotorsion_contains_a_and_ga {g : G} {a : subgroup G}\n  (h\u2081 : g * g = 1) (h\u2082 : \u2200 (x : G), x \u2208 a \u2192 x * x = 1) :\n    \u2191a \u222a left_coset g \u2191a \u2286 {x : G | x * x = 1} :=\nbegin\n  -- prove that twotorsion(G) \u2287 a u ga \n  intros x hx,\n  by_cases (x \u2208 a), tauto,\n  have H : (x \u2208 left_coset g a),\n  {\n      rw set.mem_union at hx,\n      norm_cast at hx,\n      tauto,\n  },\n  suffices x_is_twotors : x * x = 1, by tauto,\n  clear hx h,\n  have H2 : \u2200 (x : G), x \u2208 a \u2192 x * x = 1, by tauto,\n  rw mem_left_coset_iff at H,\n  specialize H2  (g\u207b\u00b9 * x) H,\n  have H3 : g = g\u207b\u00b9 := eq_inv_of_mul_eq_one h\u2081,\n  by calc\n  x * x = g * g * x * x : by simp only [h\u2081, one_mul]\n  ...   = g\u207b\u00b9 * g\u207b\u00b9 * x * x : by rw \u2190 H3\n  ...   = g\u207b\u00b9 * x * g\u207b\u00b9 * x : by rw mul_right_comm g\u207b\u00b9 g\u207b\u00b9 x\n  ...   = g\u207b\u00b9 * x * (g\u207b\u00b9 * x) : by exact mul_assoc (g\u207b\u00b9 * x) g\u207b\u00b9 x\n  ...   = 1 : by exact H2,\nend\n\n/--\nSuppose a \u2264 G[2], and g \u2209 a.\nThen if x \u2208 G[2] and x \u2209 g l* a,\nthen g \u2209 \u27e8 x, a \u27e9.\n--/\nlemma g_notin_xua {x g: G} {a : subgroup G}\n  (hg : g \u2209 a)\n  (hx : x * x = 1)\n  (ha : \u2200 y : G, y \u2208 a \u2192 y * y = 1)\n  (hgx : x \u2209 left_coset g \u2191a) :\n    (g \u2209 insert_twotors_to_twotors hx ha) :=\nbegin\n  by_contradiction cont,\n  cases cont,\n  by contradiction,\n  {\n      rw mem_left_coset_iff at *,\n      suffices : g\u207b\u00b9 * x \u2208 \u2191a, by solve_by_elim,\n      norm_num at *,\n      rw [\u2190subgroup.inv_mem_iff, mul_inv, mul_comm, inv_inv],\n      exact cont,\n  }\nend\n\n/--\nIf x \u2208 G[2] and a \u2264 G[2], then \u27e8 x, a \u27e9 \u2264 G[2].\n--/\nlemma xua_twotors {x : G} {a : subgroup G}\n  (hx : x * x = 1)\n  (ha : \u2200 y : G, y \u2208 a \u2192 y * y = 1) :\n    (\u2200 (y : G), y \u2208 (insert_twotors_to_twotors hx ha) \u2192 y * y = 1) :=\nbegin\n  intros y hy,\n  let xua := insert_twotors_to_twotors hx ha,\n  have hxinxua : \u2200 y : G, y \u2208 xua \u2194 (y \u2208 \u2191a \u2228 y \u2208 left_coset x a) := \u03bb _, iff_of_eq rfl,\n  rw hxinxua at hy,\n  cases hy, by exact ha y hy,\n  {\n    rw mem_left_coset_iff at hy,\n    have HH : \u2203 w \u2208 a, x\u207b\u00b9 * y = w, by tauto,\n    rcases HH with \u27e8 w ,\u27e8 hw1, hw2\u27e9\u27e9,\n    have hhy : y = x * w := eq_mul_of_inv_mul_eq hw2,\n    calc\n    y * y = (x * w) * (x * w): congr (congr_arg has_mul.mul hhy) hhy\n    ...   = (x * x) * (w * w): mul_mul_mul_comm x w x w\n    ...   = w * w : mul_left_eq_self.mpr hx\n    ...   = 1      : ha w hw1,\n  }\nend\n\n/--\nG[2] \u2264 \u27e8g, a\u27e9\n--/\nlemma twotorsion_containedin_a_union_ga {g : G} {a : subgroup G}\n      (h\u2081 : g * g = 1) (h\u2082 : \u2200 (x : G), x \u2208 a \u2192 x * x = 1)\n      (hga : g \u2209 a)\n      (hmax : \u2200 (a' : subgroup G), g \u2209 a' \u2192 (\u2200 (x : G), x \u2208 a' \u2192 x * x = 1) \u2192 a \u2264 a' \u2192 a = a') :\n      {x : G | x * x = 1} \u2286 \u2191a \u222a left_coset g \u2191a :=\nbegin\n  -- Prove that twotorsion(G) \u2286 a u ga\n  intros x hx,\n  dsimp at hx,\n  by_contradiction h,\n  rw set.mem_union at h,\n  push_neg at h,\n  let xua := insert_twotors_to_twotors hx h\u2082,\n  have hxinxua : \u2200 y : G, y \u2208 xua \u2194 (y \u2208 \u2191a \u2228 y \u2208 left_coset x a) := \u03bb _, iff_of_eq rfl,\n  have g_notin_xua : g \u2209 xua, by exact g_notin_xua hga hx h\u2082 h.right,\n  have h_twotors : (\u2200 (y : G), y \u2208 xua \u2192 y * y = 1), by exact xua_twotors hx h\u2082,\n  have a_eq_xua : a = xua := hmax xua g_notin_xua h_twotors (\u03bb y hy, or.inl hy),\n  have x_in_a : x \u2208 a,\n  {\n      norm_num at *,\n      rw [a_eq_xua, hxinxua, mem_left_coset_iff],\n      right,\n      simp only [mul_left_inv],\n      exact subgroup.one_mem a\n  },\n  norm_num at h,\n  have hl := h.left,\n  trivial,\nend\n\ninstance finite_sgp : fintype (subgroup G) :=\n  fintype.of_injective (coe : subgroup G \u2192 set G) set_like.coe_injective\n\n\n-- given G two torsion and 1 \u2260 g \u2208 G, there is H < G of index 2 with g \u2209 H\nlemma element_avoidance {g : G}  (h\u2081 : g \u2260 1) (h\u2082 : g * g = 1):\n \u2203 (H : subgroup G),\n  (g \u2209 H \u2227 \n  (\u2200 (x : G), x \u2208 H \u2192 x * x = 1) \u2227 \n  {x : G | x * x = 1} = H \u222a (left_coset g H)) \n  :=\nbegin\n    let s := {X : subgroup G | g \u2209 X \u2227 (\u2200 x : G, x \u2208 X \u2192 x*x = 1)},\n    have sfin : s.finite := set.finite.of_fintype _,\n    have snonempty : set.nonempty s,\n    {\n        use \u22a5,\n        split,\n        exact h\u2081,\n        intros x hx,\n        rw subgroup.mem_bot at hx,\n        rw hx,\n        exact mul_one 1,\n    },\n    let existsH := set.finite.exists_maximal_wrt id s sfin snonempty,\n    simp only [and_imp, exists_prop, id.def, set.mem_set_of_eq] at existsH,\n    cases existsH with a ha,\n    use a,\n    repeat {split},\n    exact ha.1.1,\n    exact ha.1.2,\n    -- We have defined a as the maximal subgroup of G satisfying\n    -- 1) g \u2209 a\n    -- 2) \u2200 x \u2208 a, x*x = 1\n    -- Now we must show that a \u222a ga = twotorsion(G)\n    apply set.subset.antisymm,\n    apply twotorsion_containedin_a_union_ga h\u2082 ha.1.2 ha.1.1 ha.2,\n    exact twotorsion_contains_a_and_ga h\u2082 ha.1.2,\nend\n\nlemma disjoint_cosets {g : G} {a : subgroup G} (hga : g \u2209 a) : disjoint \u2191a (left_coset g \u2191a) :=\nbegin\n    rintros x \u27e8 h1, \u27e8 w ,\u27e8 hw1, hw2\u27e9\u27e9\u27e9,\n    suffices H : g \u2208 a, by solve_by_elim,\n    rw eq_mul_inv_of_mul_eq hw2,\n    exact subgroup.mul_mem a h1 (subgroup.inv_mem a hw1),\nend\n\nlemma prod_square_eq_one {H : subgroup G} (h: \u2200 (x : G), x \u2208 H \u2192 x * x = 1) :\n    (\u220f (x : H), \u2191x) * (\u220f (x : H), \u2191x) = (1 : G) :=\nbegin\n    rw \u2190finset.prod_mul_distrib,\n    norm_cast at *,\n    simp,\n    have h' : (\u220f x : H, (1 : G)) = (1:G) := fintype.prod_eq_one (\u03bb (a : \u21a5H), 1) (congr_fun rfl),\n    rw_mod_cast \u2190h',\n    clear h',\n    apply finset.prod_congr, refl,\n    intros x hx,\n    specialize h x,\n    apply h,\n    cases x,\n    assumption\nend\n\nlemma prod_square_eq_one' {H : subgroup G} (h: \u2200 (x : G), x \u2208 H \u2192 x * x = 1) :\n    (\u220f (x : G) in (H : set G).to_finset, x) * (\u220f (x : G) in (H : set G).to_finset, x) = (1 : G) :=\nbegin\n    rw \u2190two_products_id,\n    apply prod_square_eq_one h,\n    finish,\nend\n\nlemma fintype_card_eq_finset_card : fintype.card G =\n       finset.card (((\u22a4 : subgroup G) : set G).to_finset):=\nbegin\n    unfold fintype.card,\n    congr,\n    simp [subgroup.coe_top],\n    convert set.to_finset_univ.symm,\nend\n\nlemma prod_over_left_coset {g : G} {H : subgroup G} :\n    \u220f x in (left_coset g \u2191H).to_finset, x  = \n    g^(finset.card (H : set G).to_finset) * (\u220f x in (H : set G).to_finset, x) :=\nbegin\n    have h : \u220f x in (left_coset g \u2191H).to_finset, x  = \u220f x in (H : set G).to_finset, (g * x),\n    {\n        unfold left_coset,\n        --\u03bb x : G, g * x,\n        simp [finset.prod_image],\n        unfold_coes,\n        have hinj : \u2200 (x : G), x \u2208 (H : set G).to_finset \u2192 \u2200 (y : G), y \u2208 (H : set G).to_finset \u2192 g * x = g * y \u2192 x = y,\n        {\n            intros x hx y hy hg,\n            exact (mul_right_inj g).mp hg,\n        },\n        convert finset.prod_image hinj,\n        ext1,\n        norm_num,\n        split,\n        {\n          intros,\n          use g\u207b\u00b9 * a,\n          finish,\n        },\n        {\n          intro h,\n          obtain \u27e8b,\u27e8hb1,hb2\u27e9\u27e9 := h,\n          subst hb2,\n          simp at *,\n          tauto,\n        }\n    },\n    rw [h, finset.prod_mul_distrib],\n    simp only [finset.prod_const],\nend\n\nlemma prod_identity {g : G} (h\u2081 : \u2200 x : G, x * x = 1) (h\u2082 : g \u2260 1):\n ((\u220f x : G, x) : G)= g^(fintype.card G / 2 : \u2115) :=\nbegin\n    rw_mod_cast prod_all_eq_prod_two_torsion',\n    have existsH := element_avoidance h\u2082 (h\u2081 g),\n    rcases existsH with \u27e8H, \u27e8 hgH, hHtors, h_index2\u27e9\u27e9,\n    have hdisj : disjoint (H : set G) (left_coset g \u2191H) := disjoint_cosets hgH,\n    have hdisj' : disjoint (H : set G).to_finset (left_coset g \u2191H).to_finset,\n    {\n        intros x hx,\n        simp only [finset.inf_eq_inter, set.mem_to_finset, finset.mem_inter] at hx,\n        apply hdisj hx,\n    },\n    have all_twotors : (two_torsion_subgroup G) = \u22a4,\n    {\n        unfold two_torsion_subgroup,\n        ext1,\n        tauto,\n    },\n    have dec : \u2200 x : G, x \u2208 ((H : set G) \u222a left_coset g \u2191H),\n    {\n        intro x,\n        specialize h\u2081 x,\n        rw \u2190h_index2,\n        assumption,\n    },\n    have dec' : (H : set G).to_finset \u222a ((left_coset g \u2191H).to_finset) = ((\u22a4 : subgroup G) : set G).to_finset,\n    {\n        ext1,\n        split;\n        finish,\n    },\n    have p2 : ((\u220f (x : G) in (two_torsion_subgroup G : set G).to_finset, x) : G) = ((\u220f x in (\u2191H : set G).to_finset, x) : G) * (\u220f x in (left_coset g \u2191H).to_finset, x ),\n    {\n        convert finset.prod_union hdisj',\n        rw dec',\n        congr,\n        exact all_twotors,\n    },\n    have p3 : fintype.card G = 2 * finset.card (H : set G).to_finset,\n    {\n        have h' : finset.card (H : set G).to_finset = finset.card (left_coset g H).to_finset,\n        {\n            clear hdisj hdisj' p2 h\u2081 h\u2082 hHtors all_twotors,\n            have hinj : function.injective (\u03bb (x : G), g*x),\n            {\n                unfold function.injective,\n                intros x y hxy,\n                exact (mul_right_inj g).mp hxy,\n            },\n            rw \u2190finset.card_image_of_injective ((H : set G).to_finset) hinj,\n            congr,\n            ext,\n            simp,\n            split;\n            { exact id },\n        },\n        suffices h1 : fintype.card G = finset.card (H : set G).to_finset + finset.card (left_coset g H).to_finset, by linarith,\n        have h2 : finset.card ((H : set G).to_finset \u222a (left_coset g H).to_finset)\n            = finset.card (H : set G).to_finset + finset.card (left_coset g H).to_finset, by apply finset.card_disjoint_union hdisj',\n        rw \u2190h2,\n        convert fintype_card_eq_finset_card,\n    },\n    have p3' : fintype.card G / 2 = finset.card (H : set G).to_finset, by finish,\n    rw [p3', p2, prod_over_left_coset, mul_comm, mul_assoc, mul_right_eq_self],\n    suffices p4 : (\u220f (x : G) in (H : set G).to_finset, x) * (\u220f (x : G) in (H : set G).to_finset, x) = (1 : G), by assumption,\n    solve_by_elim,\nend\n\ntheorem two_torsion_subgroup_idem (G : Type*) [comm_group G] :\n  two_torsion_subgroup (two_torsion_subgroup G) = \u22a4 :=\nbegin\n    apply eq_top_iff.2,\n    intros x hx,\n    apply subtype.eq,\n    apply x.2,\nend\n\ninstance subgroup.coe_is_monoid_hom {G : Type*} [group G] (H : subgroup G) :\n    is_monoid_hom (coe : H \u2192 G) := by refine {..}; intros; refl\n\n\nlemma prod_identity_general' {g : two_torsion_subgroup G} (h : g \u2260 1):\n (\u220f x : G, x) = g^(fintype.card (two_torsion_subgroup G) / 2) :=\n begin\n    have h1: (g : G) \u2260 1,\n    {\n        cases g,\n        finish,\n    },\n    rw prod_all_eq_prod_two_torsion,\n    let G2 := two_torsion_subgroup G,\n    have htors : \u2200 (x : G2),  x * x = 1,\n    {\n        intro x,\n        rw \u2190mem_two_torsion_iff_square_eq_one,\n        rw two_torsion_subgroup_idem,\n        solve_by_elim,\n    },\n    norm_cast,\n    rw \u2190prod_identity htors h,\n    apply finset.prod_hom,\nend\n\ntheorem prod_identity_general {g : G} (h1 : g \u2260 1) (h2 : g * g = 1) :\n (\u220f x : G, x) = g^(fintype.card (two_torsion_subgroup G) / 2) :=\n begin\n    suffices hg : (\u27e8 g, h2\u27e9  : two_torsion_subgroup G) \u2260 1, by exact prod_identity_general' hg,\n    intro h, injections_and_clear, tauto,\n end\n\n", "meta": {"author": "mmasdeu", "repo": "lean-nt", "sha": "69b1c42b0c3d57e32a6d24dc862583da664e6eb2", "save_path": "github-repos/lean/mmasdeu-lean-nt", "path": "github-repos/lean/mmasdeu-lean-nt/lean-nt-69b1c42b0c3d57e32a6d24dc862583da664e6eb2/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.706087732557531}}
{"text": "import data.set\nimport data.finset\nimport tactic\n\nattribute [instance] classical.prop_decidable\n\nopen set finset\n\nnamespace finset\n\nlemma inj_range {\u03b1} (S : finset \u03b1)\n: \u2203 (f : \u03b1 \u2192 \u2115), (\u2200 x \u2208 S, f x < card S) \u2227 (\u2200 x \u2208 S, \u2200 y \u2208 S, f x = f y \u2192 x = y) :=\nbegin\n  induction S using finset.induction with x S' hasnt ih,\n  use (\u03bb y, 0), tauto,\n  rcases ih with \u27e8f, ih1, ih2\u27e9,\n  set f' := \u03bb y, if y = x then card S' else f y with f'eq,\n  use f',\n  split, {\n    intros y yin,\n    rw finset.mem_insert at yin,\n    cases yin, {\n      rw [yin, card_insert_of_not_mem hasnt],\n      dsimp only [f'],\n      simp,\n    }, {\n      specialize ih1 y yin,\n      have neq : x \u2260 y, by_contradiction, push_neg at a, rw a at hasnt, tauto,\n      dsimp only [f'],\n      have eqfalse : y = x \u2194 false, tauto,\n      rw eqfalse, simp,\n      linarith [card_insert_of_not_mem hasnt],\n    },\n  }, {\n    intros y\u2081 yin\u2081 y\u2082 yin\u2082, contrapose, intro neq,\n    by_cases h\u2081 : y\u2081 = x, {\n      rw h\u2081 at yin\u2081,\n      by_cases h\u2082 : y\u2082 = x, {\n        rw [h\u2081, h\u2082] at neq, tauto,\n      }, {\n        rw finset.mem_insert at yin\u2081,\n        dsimp only [f'],\n        have eqfalse : y\u2082 = x \u2194 false, tauto,\n        rw [h\u2081, eqfalse],\n        simp,\n        rw finset.mem_insert at yin\u2082,\n        cases yin\u2082, tauto,\n        linarith [ih1 y\u2082 yin\u2082],\n      }\n    }, {\n      rw finset.mem_insert at yin\u2081,\n      cases yin\u2081, tauto,\n      have eqfalse : y\u2081 = x \u2194 false, tauto,\n      by_cases h\u2082 : y\u2082 = x, {\n        dsimp only [f'],\n        rw [eqfalse, h\u2082], simp,\n        linarith [ih1 y\u2081 yin\u2081],\n      }, {\n        rw finset.mem_insert at yin\u2082, cases yin\u2082, tauto,\n        have eqfalse\u2082 : y\u2082 = x \u2194 false, tauto,\n        dsimp only [f'], rw [eqfalse, eqfalse\u2082], simp,\n        have ih2' := ih2 y\u2081 yin\u2081 y\u2082 yin\u2082,\n        tauto,\n      }\n    }\n  },\nend\n\nlemma range_sup (f : \u2115 \u2192 \u2115) (n m : \u2115) (him : \u2200 (x : \u2115), x < n \u2192 f x < m)\n: (finset.image f (range n)).card \u2264 m :=\nbegin\n  have g : m = (range m).card, simp,\n  rw g,\n  have g' : image f (range n) \u2286 range m,\n    rw subset_iff, intros x xin,\n    simp, simp at xin,\n    rcases xin with \u27e8y, hlt, hfeq\u27e9,\n    specialize him y hlt, rw hfeq at him, assumption,\n  exact card_le_of_subset g',\nend\n\nend finset\n", "meta": {"author": "kmill", "repo": "lean-graphcoloring", "sha": "1bb2050ed358ff647186f89922d6a09b838444e5", "save_path": "github-repos/lean/kmill-lean-graphcoloring", "path": "github-repos/lean/kmill-lean-graphcoloring/lean-graphcoloring-1bb2050ed358ff647186f89922d6a09b838444e5/src/myfinset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7060877285841172}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que en los ret\u00edculos se verifica que\n--    (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z)\n-- ---------------------------------------------------------------------\n\nimport order.lattice\n\nvariables {\u03b1 : Type*} [lattice \u03b1]\nvariables x y z : \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nbegin\n  have h1 : (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n    { have h1a : x \u2294 y \u2264 x \u2294 (y \u2294 z), by finish,\n      have h1b : z \u2264 x \u2294 (y \u2294 z), by finish,\n      show (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n        by exact sup_le h1a h1b, },\n  have h2 : x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n    { have h2a : x \u2264 (x \u2294 y) \u2294 z, by finish,\n      have h2b : y \u2294 z \u2264 (x \u2294 y) \u2294 z, by finish,\n      show x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n        by exact sup_le h2a h2b, },\n  show (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z),\n    by exact le_antisymm h1 h2,\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nbegin\n  have h1 : (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n    { have h1a : x \u2294 y \u2264 x \u2294 (y \u2294 z),\n        { have h1a1 : x \u2264 x \u2294 (y \u2294 z) :=\n            le_sup_left,\n          have h1a2 : y \u2264 x \u2294 (y \u2294 z), calc\n            y \u2264 y \u2294 z         : le_sup_left\n            ... \u2264 x \u2294 (y \u2294 z) : le_sup_right,\n          show x \u2294 y \u2264 x \u2294 (y \u2294 z),\n            by exact sup_le h1a1 h1a2, },\n      have h1b : z \u2264 x \u2294 (y \u2294 z), calc\n        z   \u2264 y \u2294 z       : le_sup_right\n        ... \u2264 x \u2294 (y \u2294 z) : le_sup_right,\n      show (x \u2294 y) \u2294 z \u2264 x \u2294 (y \u2294 z),\n        by exact sup_le h1a h1b, },\n  have h2 : x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n    { have h2a : x \u2264 (x \u2294 y) \u2294 z, calc\n        x   \u2264 x \u2294 y       : le_sup_left\n        ... \u2264 (x \u2294 y) \u2294 z : le_sup_left,\n      have h2b : y \u2294 z \u2264 (x \u2294 y) \u2294 z,\n        { have h2b1 : y \u2264 (x \u2294 y) \u2294 z, calc\n            y   \u2264 x \u2294 y       : le_sup_right\n            ... \u2264 (x \u2294 y) \u2294 z : le_sup_left,\n          have h2b2 : z \u2264 (x \u2294 y) \u2294 z :=\n            le_sup_right,\n          show y \u2294 z \u2264 (x \u2294 y) \u2294 z,\n            by exact sup_le h2b1 h2b2, },\n      show x \u2294 (y \u2294 z) \u2264 (x \u2294 y) \u2294 z,\n        by exact sup_le h2a h2b, },\n  show (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z),\n    by exact le_antisymm h1 h2,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nbegin\n  apply le_antisymm,\n  { apply sup_le,\n    { apply sup_le le_sup_left (le_sup_of_le_right le_sup_left)},\n    { apply le_sup_of_le_right le_sup_right}},\n  { apply sup_le,\n    { apply le_sup_of_le_left le_sup_left},\n    { apply sup_le (le_sup_of_le_left le_sup_right) le_sup_right}},\nend\n\n-- Su desarrollo es\n--\n-- \u22a2 x \u2294 y \u2294 z = x \u2294 (y \u2294 z)\n--    apply le_antisymm,\n-- | \u22a2 x \u2294 y \u2294 z \u2264 x \u2294 (y \u2294 z)\n-- |    { apply sup_le,\n-- | | \u22a2 x \u2294 y \u2264 x \u2294 (y \u2294 z)\n-- | |     { apply sup_le le_sup_left (le_sup_right_of_le le_sup_left)},\n-- | | \u22a2 z \u2264 x \u2294 (y \u2294 z)\n-- | |     { apply le_sup_right_of_le le_sup_right}},\n-- | \u22a2 x \u2294 (y \u2294 z) \u2264 x \u2294 y \u2294 z\n-- |    { apply sup_le,\n-- | | \u22a2 x \u2264 x \u2294 y \u2294 z\n-- | |      { apply le_sup_left_of_le le_sup_left},\n-- | | \u22a2 y \u2294 z \u2264 x \u2294 y \u2294 z\n-- | |      { apply sup_le (le_sup_left_of_le le_sup_right) le_sup_right}},\n-- no goals\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (x \u2294 y) \u2294 z = x \u2294 (y \u2294 z) :=\nle_antisymm\n  (sup_le\n    (sup_le le_sup_left (le_sup_of_le_right le_sup_left))\n    (le_sup_of_le_right le_sup_right))\n  (sup_le\n    (le_sup_of_le_left le_sup_left)\n    (sup_le (le_sup_of_le_left le_sup_right) le_sup_right))\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 y \u2294 z = x \u2294 (y \u2294 z) :=\n-- by library_search\nsup_assoc\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : x \u2294 y \u2294 z = x \u2294 (y \u2294 z) :=\n-- by hint\nby finish\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Basicos/Asociatividad_del_supremo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7059397464737373}}
{"text": "/-\nVarious lemmas intended for mathlib. \nSome parts of this file are originally from \nhttps://github.com/johoelzl/mathlib/blob/c9507242274ac18defbceb917f30d6afb8b839a5/src/measure_theory/measurable_space.lean\n\nAuthors: Johannes Holzl, John Tristan, Koundinya Vajjha \n-/\nimport tactic.tidy \nimport measure_theory.giry_monad measure_theory.integration measure_theory.borel_space .dvector\nimport .probability_theory \nimport analysis.complex.exponential \n\nlocal attribute [instance] classical.prop_decidable\n\nnoncomputable theory \n\n-- set_option pp.implicit true \n-- set_option pp.coercions true \n-- set_option trace.class_instances true \n-- set_option class.instance_max_depth 39\n\n-- local attribute [instance] classical.prop_decidable\n\nuniverses u v\n\n\nopen nnreal measure_theory nat list measure_theory.measure set lattice ennreal measurable_space probability_measure\n\ninfixl ` >>=\u2090 `:55 :=  measure.bind \ninfixl ` <$>\u2090 `:55 := measure.map \n\nlocal notation `do\u2090` binders ` \u2190\u2090 ` m ` ; ` t:(scoped p, m >>=\u2090 p) := t\n\nlocal notation `ret` := measure.dirac  \n\nnamespace to_integration \nvariables {\u03b1 : Type u} {\u03b2 : Type u}\n\n-- Auxilary results about simple functions and characteristic functions. The results in this section should go into integration.lean in mathlib.\n\n@[simp] lemma integral_sum [measurable_space \u03b1] (m : measure \u03b1) (f g : \u03b1 \u2192 ennreal) [hf : measurable f] [hg : measurable g] : m.integral (f + g) = m.integral f + m.integral g := begin\n  rw [integral, integral, integral,\u2190lintegral_add], refl,\n  repeat{assumption},\nend\n\n@[simp] lemma integral_const_mul [measurable_space \u03b1] (m : measure \u03b1) {f : \u03b1 \u2192 ennreal} (hf : measurable f) (k:ennreal): m.integral (\u03bb x, k*f(x)) = k * m.integral f :=\nby rw [integral,lintegral_const_mul,integral] ; assumption\n\n\n/-- The characteristic function (indicator function) of a set A. -/\nnoncomputable def char_fun [measurable_space \u03b1] (A : set \u03b1) := simple_func.restrict (simple_func.const \u03b1 (1 : ennreal)) A\n\nnotation `\u03c7` `\u27e6` A `\u27e7` := char_fun A \nnotation `\u222b` f `\u00f0`m := integral m f \n\n-- variables (A : set \u03b1) (a : \u03b1) [measurable_space \u03b1]\n\n@[simp] lemma char_fun_apply [measurable_space \u03b1] {A : set \u03b1} (hA : is_measurable A)(a : \u03b1):\n(\u03c7 \u27e6A\u27e7 : simple_func \u03b1 ennreal) a = ite (a \u2208 A) 1 0 := by\nunfold_coes ; apply (simple_func.restrict_apply _ hA)\n\n@[simp] lemma integral_char_fun [measurable_space \u03b1] [ne : nonempty \u03b1] (m : measure \u03b1) {A : set \u03b1} (hA : is_measurable A) :\n(\u222b \u03c7\u27e6A\u27e7 \u00f0m) = m A := \nbegin\n   rw [char_fun, integral, simple_func.lintegral_eq_integral, simple_func.restrict_integral],\n   unfold set.preimage, dsimp, erw [simple_func.range_const \u03b1], simp, rw [\u2190set.univ_def, set.univ_inter], refl, assumption,\nend\n\nlemma dirac_char_fun [measurable_space \u03b1] {A : set \u03b1} (hA : is_measurable A) : (\u03bb (x : \u03b1), (ret x : measure \u03b1) A) = \u03c7\u27e6A\u27e7 := \nbegin\n  funext,rw [measure.dirac_apply _ hA, char_fun_apply hA],\n  by_cases x \u2208 A, split_ifs, simp [h],\n  split_ifs, simp [h],\nend\n\nlemma prob.dirac_char_fun [measurable_space \u03b1] {B: set \u03b1} (hB : is_measurable B) : (\u03bb x:\u03b1,((ret\u209a x).to_measure : measure \u03b1) B) = \u03c7\u27e6B\u27e7 := \nbegin\n  conv {congr, funext, rw ret_to_measure},\n  exact dirac_char_fun hB,  \nend\n\nlemma measurable_dirac_fun [measurable_space \u03b1] {A : set \u03b1} (hA : is_measurable A) : measurable (\u03bb (x : \u03b1), (ret x : measure \u03b1) A) := by rw dirac_char_fun hA ; apply simple_func.measurable\n\n\ninstance simple_func.add_comm_monoid [measurable_space \u03b1] [add_comm_monoid \u03b2] : add_comm_monoid (simple_func \u03b1 \u03b2) := \n{\n  add_comm := assume a b, simple_func.ext (assume a, add_comm _ _),\n  .. simple_func.add_monoid\n}\n\nlemma integral_finset_sum [measurable_space \u03b1] (m : measure \u03b1) (s : finset (set \u03b1)) \n(hX : \u2200 (A : set \u03b1) , is_measurable (A)) :\nm.integral (s.sum (\u03bb A, \u03c7 \u27e6 A \u27e7)) = s.sum (\u03bb A, m A) := \nbegin\n  rw integral,\n  refine finset.induction_on s _ _,\n  { simp, erw lintegral_zero },\n  { assume a s has ih, simp [has], erw [lintegral_add],\n  rw simple_func.lintegral_eq_integral,unfold char_fun,\n  erw simple_func.restrict_const_integral, dsimp, rw ih, ext1,cases a_1, dsimp at *, simp at *, refl, exact(hX a), \n  { intros i h, dsimp at *, solve_by_elim [hX] },\n  { intros a b, dsimp at *, solve_by_elim },\n  },\nend\n\nlemma integral_le_integral [measurable_space \u03b1] (m : measure \u03b1) (f g : \u03b1 \u2192 ennreal) (h : f \u2264 g) : \n(\u222b f \u00f0m) \u2264 (\u222b g \u00f0m) :=\nbegin\nrw integral, rw integral, apply lintegral_le_lintegral, assumption,\nend\n\n\nnoncomputable def char_prod [measurable_space \u03b1]{f : \u03b1 \u2192 ennreal}{\u03b5 : ennreal}(hf : measurable f)(eh : \u03b5 > 0): simple_func \u03b1 ennreal :=\n\u27e8\n  \u03bb x, if (f(x) \u2265 \u03b5) then \u03b5 else 0,\n  assume x, by letI : measurable_space ennreal := borel ennreal; exact\n   measurable.if (measurable_le measurable_const hf) measurable_const measurable_const _ (is_measurable_of_is_closed is_closed_singleton),\n  begin apply finite_subset (finite_union (finite_singleton \u03b5) ((finite_singleton 0))),\n  rintro _ \u27e8a, rfl\u27e9,\n  by_cases (f a \u2265 \u03b5); simp [h],\n  end\n\u27e9\n\n@[simp] lemma char_prod_apply [measurable_space \u03b1]{f : \u03b1 \u2192 ennreal}{\u03b5 : ennreal}(hf : measurable f)(eh : \u03b5 > 0) (a : \u03b1): (char_prod hf eh) a = if (f a \u2265 \u03b5) then \u03b5 else 0 := rfl\n\n\n/-- Markov's inequality. -/\ntheorem measure_fun_ge_le_integral [measurable_space \u03b1] [nonempty \u03b1] (m : measure \u03b1) {f : \u03b1 \u2192 ennreal} (hf : measurable f) : \u2200 (\u03b5 > 0),\n \u03b5*m({x | f(x) \u2265 \u03b5}) \u2264 \u222b f \u00f0m := \nbegin\n  intros \u03b5 eh,\n  let s := char_prod hf eh,\n  have hsf : \u2200 x, s x \u2264 f x, {\n  intro x, \n  by_cases g : (f(x) \u2265 \u03b5),\n  dsimp [s], split_ifs, exact g,\n  dsimp [s], split_ifs, exact zero_le (f x),\n  },\n  convert (integral_le_integral _ _ _ hsf),\n  have seq : s = (simple_func.const \u03b1 \u03b5) * (\u03c7 \u27e6{x : \u03b1 | f x \u2265 \u03b5} \u27e7),{\n  apply simple_func.ext, \n  intro a, simp * at *, \n  dunfold char_fun, \n  rw [simple_func.restrict_apply, simple_func.const_apply],\n  split_ifs, rw mul_one, rw mul_zero,\n  apply (@measurable_le ennreal \u03b1 _ _), exact measurable_const, assumption,\n  },\n  rw seq, simp, rw [integral_const_mul m, integral_char_fun], \n  apply (@measurable_le ennreal \u03b1 _ _), exact measurable_const, assumption, \n  apply simple_func.measurable,\nend\n\n\n/-- Chebyshev's inequality for a nondecreasing function `g`. -/\ntheorem measure_fun_ge_le_integral_comp [measurable_space \u03b1][nonempty \u03b1] (m : measure \u03b1) {f : \u03b1 \u2192 ennreal} {g : ennreal \u2192 ennreal}(hf : measurable f) (hg : measurable g) (nondec : \u2200 x y,x \u2264 y \u2192 g x \u2264 g y): \u2200 (t > 0),\n g(t)*m({x | f(x) \u2265 t}) \u2264 \u222b g \u2218 f \u00f0m :=\nbegin\n  intros t ht, \n  have hsf : \u2200 x, g(t) * (\u03c7 \u27e6{x : \u03b1 | f x \u2265 t} \u27e7 x) \u2264 (g (f x)), {\n  intro x, \n  dunfold char_fun,\n  rw [simple_func.restrict_apply, simple_func.const_apply],\n  split_ifs,  \n  rw [mul_one], apply (@nondec _ _ h),  \n  finish,\n  apply (@measurable_le ennreal \u03b1 _ _), exact measurable_const, assumption,\n  },\n  rw [\u2190integral_char_fun, \u2190integral_const_mul m],\n  apply (integral_le_integral m), \n  exact hsf, \n  apply simple_func.measurable,\n  apply (@measurable_le ennreal \u03b1 _ _), exact measurable_const, assumption,\nend\n\n\nend to_integration\n\nnamespace giry_pi\n-- Auxilary results about infinite products of measure spaces. \n-- This section has to go back to `constructions` in `measure_theory/measurable_space`. Originally from Johannes' fork. \n\ninstance pi.measurable_space (\u03b9 : Type*) (\u03b1 : \u03b9 \u2192 Type*) [m : \u2200i, measurable_space (\u03b1 i)] :\n  measurable_space (\u03a0i, \u03b1 i) :=\n\u2a06i, (m i).comap (\u03bbf, f i)\n\ninstance pi.measurable_space_Prop (\u03b9 : Prop) (\u03b1 : \u03b9 \u2192 Type*) [m : \u2200i, measurable_space (\u03b1 i)] :\n  measurable_space (\u03a0i, \u03b1 i) :=\n\u2a06i, (m i).comap (\u03bbf, f i)\n\nlemma measurable_pi {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} {\u03b2 : Type*}\n  [m : \u2200i, measurable_space (\u03b1 i)] [measurable_space \u03b2] {f : \u03b2 \u2192 \u03a0i, \u03b1 i} :\n  measurable f \u2194 (\u2200i, measurable (\u03bbb, f b i)):=\nbegin\n  rw [measurable, pi.measurable_space, supr_le_iff],\n  refine forall_congr (assume i, _),\n  rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp],\n  refl\nend\n\nlemma measurable_apply {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*} {\u03b2 : Type*}\n  [m : \u2200i, measurable_space (\u03b1 i)] [measurable_space \u03b2] (f : \u03b2 \u2192 \u03a0i, \u03b1 i) (i : \u03b9)\n  (hf : measurable f) :\n  measurable (\u03bbb, f b i) :=\nmeasurable_pi.1 hf _\n\nlemma measurable_pi_Prop {\u03b9 : Prop} {\u03b1 : \u03b9 \u2192 Type*} {\u03b2 : Type*}\n  [m : \u2200i, measurable_space (\u03b1 i)] [measurable_space \u03b2] {f : \u03b2 \u2192 \u03a0i, \u03b1 i} :\n  measurable f \u2194 (\u2200i, measurable (\u03bbb, f b i)):=\nbegin\n  rw [measurable, pi.measurable_space_Prop, supr_le_iff],\n  refine forall_congr (assume i, _),\n  rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp],\n  refl\nend\n\nlemma measurable_apply_Prop {p : Prop} {\u03b1 : p \u2192 Type*} {\u03b2 : Type*}\n  [m : \u2200i, measurable_space (\u03b1 i)] [measurable_space \u03b2] (f : \u03b2 \u2192 \u03a0i, \u03b1 i) (h : p)\n  (hf : measurable f) :\n  measurable (\u03bbb, f b h) :=\nmeasurable_pi_Prop.1 hf _\n\nend giry_pi\n\nsection giry_prod\n\nopen to_integration\n\nvariables {\u03b1 : Type u} {\u03b2 : Type u} {\u03b3 : Type v}\n\n/- Auxilary results about the Giry monad and binary products. The following results should go back to giry_monad.lean -/\n\n/-- Right identity monad law for the Giry monad. -/\nlemma giry.bind_return_comp [measurable_space \u03b1][measurable_space \u03b2] (D : measure \u03b1) {p : \u03b1 \u2192 \u03b2} (hp : measurable p) :\n(do\u2090 (x : \u03b1) \u2190\u2090 D ;\n ret (p x)) = p <$>\u2090 D := \nmeasure.ext $ assume s hs, begin\n  rw [measure.bind_apply hs _],\n  rw [measure.map_apply hp hs],\n  conv_lhs{congr, skip, funext, rw [measure.dirac_apply _ hs]},\n  transitivity,\n  apply lintegral_supr_const, exact hp _ hs,\n   rw one_mul, refl, \n  exact measurable.comp measurable_dirac hp,\nend\n\n/-- Left identity monad law for compositions in the Giry monad -/\nlemma giry.return_bind_comp [measurable_space \u03b1][measurable_space \u03b2] {p : \u03b1 \u2192 measure \u03b2} {f : \u03b1 \u2192 \u03b1} (hf : measurable f)(hp : measurable p) (a : \u03b1) :\n (do\u2090 x \u2190\u2090 dirac a ; p (f x))  = p (f a) :=\nmeasure.ext $ assume s hs, begin\nrw measure.bind_apply hs, rw measure.integral_dirac a,\nswap, exact measurable.comp hp hf,\nexact measurable.comp (measurable_coe hs) (measurable.comp hp hf),\nend\n\ndef prod_measure [measurable_space \u03b1][measurable_space \u03b2] (\u03bc : measure \u03b1) (\u03bd : measure \u03b2) : measure (\u03b1 \u00d7 \u03b2) := \ndo\u2090 x \u2190\u2090 \u03bc ; \ndo\u2090 y \u2190\u2090 \u03bd ;\n  ret (x, y)\n\ninfixl ` \u2297\u2090 `:55 :=  prod_measure \n\ninstance prod.measure_space [measurable_space \u03b1] [measurable_space \u03b2] (\u03bc : measure \u03b1) (\u03bd : measure \u03b2) : measure_space (\u03b1 \u00d7 \u03b2) := \u27e8 \u03bc \u2297\u2090 \u03bd \u27e9 \n\nlemma inl_measurable [measurable_space \u03b1][measurable_space \u03b2] : \u2200 y : \u03b2, measurable (\u03bb x : \u03b1, (x,y)) := assume y, begin\napply measurable.prod, dsimp, exact measurable_id, dsimp, exact measurable_const, \nend\n\nlemma inr_measurable [measurable_space \u03b1][measurable_space \u03b2] : \u2200 x : \u03b1, measurable (\u03bb y : \u03b2, (x,y)) := assume y, begin\napply measurable.prod, dsimp, exact measurable_const, dsimp, exact measurable_id, \nend\n\nlemma inl_measurable_dirac [measurable_space \u03b1][measurable_space \u03b2]  : \u2200 y : \u03b2,  measurable (\u03bb (x : \u03b1), ret (x, y)) := assume y, begin\n  apply measurable_of_measurable_coe, \n  intros s hs,\n  simp [hs, lattice.supr_eq_if, mem_prod_eq], \n  apply measurable_const.if _ measurable_const,\n  apply measurable.preimage _ hs,  \n  apply measurable.prod, dsimp, exact measurable_id, \n  dsimp, exact measurable_const, \nend\n\nlemma inr_measurable_dirac [measurable_space \u03b2][measurable_space \u03b1] : \u2200 x : \u03b1,  measurable (\u03bb (y : \u03b2), ret (x, y)) := assume x, begin\n  apply measurable_of_measurable_coe, \n  intros s hs,\n  simp [hs, lattice.supr_eq_if, mem_prod_eq], \n  apply measurable_const.if _ measurable_const, apply measurable.preimage _ hs,  \n  apply measurable.prod, dsimp, exact measurable_const, \n  dsimp, exact measurable_id, \nend\n\nlemma inr_section_is_measurable [measurable_space \u03b1] [measurable_space \u03b2]  {E : set (\u03b1 \u00d7 \u03b2)} (hE : is_measurable E) (x : \u03b1) : \nis_measurable ({ y:\u03b2 | (x,y) \u2208 E}) :=\nbegin\n  change (is_measurable ((\u03bb z:\u03b2, (x,z))\u207b\u00b9' E)),\n  apply inr_measurable, assumption,\nend\n\nlemma inl_section_is_measurable [measurable_space \u03b1] [measurable_space \u03b2]  {E : set (\u03b1 \u00d7 \u03b2)} (hE : is_measurable E) (y : \u03b2) : \nis_measurable ({ x:\u03b1 | (x,y) \u2208 E}) :=\nbegin\n  change (is_measurable ((\u03bb z:\u03b1, (z,y))\u207b\u00b9' E)),\n  apply inl_measurable, assumption,\nend\n\nlemma snd_comp_measurable [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] {f : \u03b1 \u00d7 \u03b2 \u2192 \u03b3} (hf : measurable f) (x : \u03b1) : measurable (\u03bb y:\u03b2, f (x, y)) := (measurable.comp hf (inr_measurable _))\n\nlemma fst_comp_measurable [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] {f : \u03b1 \u00d7 \u03b2 \u2192 \u03b3} (hf : measurable f) (y : \u03b2) : measurable ((\u03bb x:\u03b1, f (x, y))) := (measurable.comp hf (inl_measurable _))\n\nlemma measurable_pair_iff [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] (f : \u03b3 \u2192 \u03b1 \u00d7 \u03b2) :\nmeasurable f \u2194 (measurable (prod.fst \u2218 f) \u2227 measurable (prod.snd \u2218 f)) :=\niff.intro \n(assume h, and.intro (measurable_fst h) (measurable_snd h)) \n(assume \u27e8h\u2081, h\u2082\u27e9, measurable.prod h\u2081 h\u2082)\n\n\n@[simp] lemma dirac.prod_apply [measurable_space \u03b1][measurable_space \u03b2]{A : set \u03b1} {B : set \u03b2} (hA : is_measurable A) (hB : is_measurable B) (a : \u03b1) (b : \u03b2) :\n (ret (a,b) : measure (\u03b1 \u00d7 \u03b2)) (A.prod B) = ((ret a : measure \u03b1) A) * ((ret b : measure \u03b2) B) := \nbegin\n  rw [dirac_apply, dirac_apply, dirac_apply, mem_prod_eq], \n  dsimp,\n  by_cases Ha: (a \u2208 A); by_cases Hb: (b \u2208 B), \n  repeat {simp [Ha, Hb]},\n  repeat {assumption}, \n  exact is_measurable_set_prod hA hB, \nend\n\nlemma prod.bind_ret_comp [measurable_space \u03b1] [measurable_space \u03b2]\n(\u03bc : measure \u03b1) : \u2200 y : \u03b2,\n(do\u2090 (x : \u03b1) \u2190\u2090 \u03bc; \n ret (x,y)) = (\u03bb x, (x,y)) <$>\u2090 \u03bc := assume y, begin apply  giry.bind_return_comp, apply measurable.prod, dsimp, exact measurable_id, \ndsimp, exact measurable_const, end\n\n-- TODO(Kody) : move this back to mathlib/measurable_space.lean \nlemma measure_rect_generate_from [measurable_space \u03b1] [measurable_space \u03b2] : prod.measurable_space = generate_from {E | \u2203 (A : set \u03b1) (B : set \u03b2), E = A.prod B \u2227 is_measurable A \u2227 is_measurable B} :=\nbegin\nrw eq_iff_le_not_lt,\nsplit,\n  {\n  apply generate_from_le_generate_from, intros s hs,  \n  rcases hs with \u27e8A\u2080, hA, rfl\u27e9 | \u27e8B\u2080, hB, rfl\u27e9,\n  existsi [A\u2080, univ], \n  fsplit, ext1, cases x, simp, exact and.intro hA is_measurable.univ,\n  existsi [univ, B\u2080],\n  fsplit, ext1, cases x, simp, exact and.intro is_measurable.univ hB,\n  },\n  {\n  apply not_lt_of_le,\n  apply measurable_space.generate_from_le, \n  intros t ht, dsimp at ht, rcases ht with \u27e8A, B, rfl, hA, hB\u27e9, exact is_measurable_set_prod hA hB,\n  }\nend\n\ndef measurable_prod_bind_ret [measurable_space \u03b1] [measurable_space \u03b2] (\u03bd : probability_measure \u03b2): set(\u03b1 \u00d7 \u03b2) \u2192 Prop := \u03bb s, measurable (\u03bb (x : \u03b1), (do\u209a (y : \u03b2) \u2190\u209a \u03bd ; ret\u209a (x, y)) s)\n\nlemma measure_rect_inter [measurable_space \u03b1] [measurable_space \u03b2] : \u2200t\u2081 t\u2082, t\u2081 \u2208 {E | \u2203 (A : set \u03b1) (B : set \u03b2), E = A.prod B \u2227 is_measurable A \u2227 is_measurable B} \u2192 t\u2082 \u2208 {E | \u2203 (A : set \u03b1) (B : set \u03b2), E = A.prod B \u2227 is_measurable A \u2227 is_measurable B} \u2192 t\u2081 \u2229 t\u2082 \u2260 \u2205 \u2192 t\u2081 \u2229 t\u2082 \u2208 {E | \u2203 (A : set \u03b1) (B : set \u03b2), E = A.prod B \u2227 is_measurable A \u2227 is_measurable B} := \nbegin\n  rintros t\u2081 t\u2082 \u27e8A, B, rfl, hA, hB\u27e9 \u27e8A', B', rfl, hA', hB'\u27e9 hI,\n  rw prod_inter_prod,\n  existsi [(A \u2229 A'),(B \u2229 B')],\n  fsplit, refl, \n  exact and.intro (is_measurable.inter hA hA') (is_measurable.inter hB hB'),\nend\n\nlemma measurable_prod_bind_ret_empty [measurable_space \u03b1] [measurable_space \u03b2] (\u03bd : probability_measure \u03b2): measurable (\u03bb (x : \u03b1), (do\u209a (y : \u03b2) \u2190\u209a \u03bd ; ret\u209a (x, y)) \u2205):= \nby simp ; exact measurable_const\n\nlemma measurable_prod_bind_ret_compl [measurable_space \u03b1] [measurable_space \u03b2] (\u03bd : probability_measure \u03b2) :  \u2200 t : set (\u03b1 \u00d7 \u03b2), is_measurable t \u2192 measurable (\u03bb (x : \u03b1), (do\u209a (y : \u03b2) \u2190\u209a \u03bd ; ret\u209a (x, y)) t) \u2192 measurable (\u03bb (x : \u03b1), (do\u209a (y : \u03b2) \u2190\u209a \u03bd ; ret\u209a (x, y)) (- t)) :=\nbegin\n  intros t ht hA, \n  rw compl_eq_univ_diff,\n  conv{congr, funext, rw [probability_measure.prob_diff _ (subset_univ _) is_measurable.univ ht]}, simp, \n  refine measurable.comp _ hA,\n  refine measurable.comp _ (measurable_sub measurable_const _),\n  exact measurable_of_real,\n  exact measurable_of_continuous nnreal.continuous_coe,\nend\n\n\nlemma measurable_prod_bind_ret_basic [measurable_space \u03b1] [measurable_space \u03b2] (\u03bd : probability_measure \u03b2) : \u2200 (t : set (\u03b1 \u00d7 \u03b2)),t \u2208 {E : set (\u03b1 \u00d7 \u03b2) | \u2203 (A : set \u03b1) (B : set \u03b2), E = set.prod A B \u2227 is_measurable A \u2227 is_measurable B} \u2192 measurable (\u03bb (x : \u03b1), (do\u209a (y : \u03b2) \u2190\u209a \u03bd ; ret\u209a (x, y)) t) := \nbegin\n  rintros t \u27e8A, B, rfl, hA, hB\u27e9,\n  conv{congr,funext,rw [_root_.bind_apply (is_measurable_set_prod hA hB)  (prob_inr_measurable_dirac x)],},\n  refine measurable.comp _ _, exact measurable_to_nnreal,\n  dsimp,\n  conv{congr,funext,simp [coe_eq_to_measure]},\n  simp [prob.dirac_apply' hA hB],\n  have h : measurable (\u03bb (x : \u03b2), ((ret\u209a x).to_measure : measure \u03b2) B),{\n  conv{congr,funext,rw ret_to_measure,}, exact measurable_dirac_fun hB,\n  },\n  conv {congr, funext, rw [integral_const_mul \u03bd.to_measure h],},\n  refine measurable_mul _ _, conv{congr,funext, rw [ret_to_measure],},exact measurable_dirac_fun hA,\n  exact measurable_const, \nend\n\nlemma measurable_prod_bind_ret_union [measurable_space \u03b1] [measurable_space \u03b2] (\u03bd : probability_measure \u03b2): \u2200h:\u2115 \u2192 set (\u03b1 \u00d7 \u03b2), (\u2200i j, i \u2260 j \u2192 h i \u2229 h j \u2286 \u2205) \u2192 (\u2200i, is_measurable (h i)) \u2192 (\u2200i, measurable(\u03bb (x : \u03b1), (do\u209a (y : \u03b2) \u2190\u209a \u03bd ; ret\u209a (x, y)) (h i))) \u2192 measurable (\u03bb (x : \u03b1), (do\u209a (y : \u03b2) \u2190\u209a \u03bd ; ret\u209a (x, y)) (\u22c3i, h i)) := \nbegin\n  rintros h hI hA hB,\n  unfold_coes,\n  refine measurable.comp (measurable_of_measurable_nnreal measurable_id) _,\n  conv{congr,funext,rw [m_Union _ hA hI,ennreal.tsum_eq_supr_nat]},\n  apply measurable.supr, intro i, \n  apply measurable_finset_sum,\n  intros i, \n  have h := hB i, clear hB, \n  refine measurable_of_ne_top _ _ _, assume x, \n  refine probability_measure.to_measure_ne_top _ _, assumption,\nend\n\n-- Push this back to ennreal.lean\nlemma to_nnreal_mul (a b : ennreal) : ennreal.to_nnreal(a*b) = ennreal.to_nnreal(a) * ennreal.to_nnreal(b) :=\nbegin\n  cases a; cases b,\n  { simp [none_eq_top] },\n  { by_cases h : b = 0; simp [none_eq_top, some_eq_coe, h, top_mul] },\n  { by_cases h : a = 0; simp [none_eq_top, some_eq_coe, h, mul_top] },\n  { simp [some_eq_coe, coe_mul.symm, -coe_mul] }\nend\n\n@[simp] theorem prod.prob_measure_apply [measurable_space \u03b1] [measurable_space \u03b2][nonempty \u03b1] [nonempty \u03b2] (\u03bc : probability_measure \u03b1) (\u03bd : probability_measure \u03b2) {A : set \u03b1} {B : set \u03b2} \n(hA : is_measurable A) (hB : is_measurable B) : \n(\u03bc \u2297\u209a \u03bd) (A.prod B) = \u03bc (A) * \u03bd (B) := \nbegin\n  dunfold prod.prob_measure,\n  rw _root_.bind_apply (is_measurable_set_prod hA hB),\n  conv_lhs{congr, congr, skip, funext, erw [_root_.bind_apply ( is_measurable_set_prod hA hB) (prob_inr_measurable_dirac a)]},\n  simp[coe_eq_to_measure, prob.dirac_apply' hA hB],\n  -- move this to probability_theory \n  have h : measurable (\u03bb (x : \u03b2), ((ret\u209a x).to_measure : measure \u03b2) B),\n  {\n    conv{congr,funext,rw ret_to_measure,}, \n    exact measurable_dirac_fun hB,\n  },\n  conv {congr, funext, congr, congr, skip, funext, rw [integral_const_mul \u03bd.to_measure h,ret_to_measure,mul_comm],},\n  rw [prob.dirac_char_fun hB, integral_char_fun \u03bd.to_measure hB],\n  -- move this to measurable_space\n  have g : \u2200 a:\u03b1, ((ret a : measure \u03b1) A) < \u22a4, \n  {\n    assume a, rw dirac_apply _ hA, by_cases(a \u2208 A),\n    simp[h],exact lt_top_iff_ne_top.2 one_ne_top, \n    simp[h], exact lt_top_iff_ne_top.2 zero_ne_top,\n  },\n  conv_lhs{congr, congr, skip, funext, rw [coe_to_nnreal (lt_top_iff_ne_top.1 (mul_lt_top (to_measure_lt_top _ _) (g a)))]},\n  conv_lhs{congr, rw [integral_const_mul \u03bc.to_measure (measurable_dirac_fun hA)]},\n  rw [dirac_char_fun hA, integral_char_fun _ hA, mul_comm, to_nnreal_mul], refl,\n  apply prob.measurable_of_measurable_coe,\n  exact (\n    @induction_on_inter _ \n    (measurable_prod_bind_ret \u03bd) \n    ({E | \u2203 (A : set \u03b1) (B : set \u03b2), (E = A.prod B) \u2227 is_measurable A \u2227 is_measurable B}) \n    _ measure_rect_generate_from measure_rect_inter (measurable_prod_bind_ret_empty \u03bd) (measurable_prod_bind_ret_basic \u03bd) (measurable_prod_bind_ret_compl \u03bd) (measurable_prod_bind_ret_union \u03bd)\n    ),\nend\n\n\nend giry_prod\n\n\nsection fubini\n\nvariables {\u03b1 : Type u} {\u03b2 : Type u} [measure_space \u03b1] [measure_space \u03b2]\n\nopen to_integration \n\n\n\n\n\n\nlocal notation  `\u222b` f `\ud835\udcb9`m := integral m.to_measure f \n\n\nlemma integral_char_rect [measurable_space \u03b1] [measurable_space \u03b2] [n\u2081 : nonempty \u03b1] [n\u2082 : nonempty \u03b2](\u03bc : probability_measure \u03b1) (\u03bd : probability_measure \u03b2)  {A : set \u03b1} {B : set \u03b2} (hA : is_measurable A) (hB : is_measurable B) :\n(\u222b \u03c7 \u27e6 A.prod B \u27e7 \ud835\udcb9(\u03bc \u2297\u209a \u03bd)) = (\u03bc A) * (\u03bd B) := \nbegin\n  haveI := (nonempty_prod.2 (and.intro n\u2081 n\u2082)),\n  rw [integral_char_fun _ (is_measurable_set_prod hA hB),\u2190coe_eq_to_measure, \n  (prod.prob_measure_apply _ _ hA hB)], simp, \nend\n\nend fubini\n\n\nsection prod_measure_measurable\n\n/- \nThis section aims to prove `measurable (\u03bb x : \u03b1 , f x \u2297\u209a g x)` using Dynkin's \u03c0-\u03bb theorem. \nPush this back to giry_monad.lean  \n-/\n\nvariables {\u03b1 : Type u} {\u03b2 : Type u} {\u03b3 : Type u}\n\ndef measurable_prod_measure_pred [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] {f : \u03b1 \u2192 probability_measure \u03b2} {g : \u03b1 \u2192 probability_measure \u03b3} (hf : measurable f) (hg : measurable g) : set (\u03b2 \u00d7 \u03b3) \u2192 Prop := \u03bb s : set (\u03b2 \u00d7 \u03b3), measurable (\u03bb b:\u03b1,(f b \u2297\u209a g b) s) \n\n\nlemma measurable_rect_empty {\u03b3 : Type u} [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] {f : \u03b1 \u2192 probability_measure \u03b2} {g : \u03b1 \u2192 probability_measure \u03b3} (hf : measurable f) (hg : measurable g): measurable (\u03bb b:\u03b1,(f b \u2297\u209a g b) \u2205) := \nby simp ; exact measurable_const\n\n\nlemma measure_rect_union {\u03b3 : Type u} [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] (f : \u03b1 \u2192 probability_measure \u03b2) (g : \u03b1 \u2192 probability_measure \u03b3) : \u2200h:\u2115 \u2192 set (\u03b2 \u00d7 \u03b3), (\u2200i j, i \u2260 j \u2192 h i \u2229 h j \u2286 \u2205) \u2192 (\u2200i, is_measurable (h i)) \u2192 (\u2200i, measurable (\u03bb b:\u03b1,(f b \u2297\u209a g b) (h i))) \u2192 measurable (\u03bb b:\u03b1,(f b \u2297\u209a g b) (\u22c3i, h i)) := \nbegin\n  rintros h hI hA hB,\n  unfold_coes,\n  conv{congr,funext,rw [m_Union _ hA hI]},\n  dsimp,  \n  conv{congr,funext,rw ennreal.tsum_eq_supr_nat,},\n  refine measurable.comp measurable_to_nnreal _,\n  apply measurable.supr, intro i, \n  apply measurable_finset_sum, assume i, \n  refine measurable_of_ne_top _ _ _, assume a,\n  refine probability_measure.to_measure_ne_top _ _, solve_by_elim,\nend\n\n\nlemma measurable_rect_compl {\u03b3 : Type u} [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3](f : \u03b1 \u2192 probability_measure \u03b2) (g : \u03b1 \u2192 probability_measure \u03b3) :  \u2200 t : set (\u03b2 \u00d7 \u03b3), is_measurable t \u2192 measurable (\u03bb b:\u03b1,(f b \u2297\u209a g b) t) \u2192 measurable (\u03bb b:\u03b1,(f b \u2297\u209a g b) (- t)) :=\nbegin\n  intros t ht hA, \n  rw compl_eq_univ_diff,\n  conv{congr, funext, rw [probability_measure.prob_diff _ (subset_univ _) is_measurable.univ ht]}, simp, \n  refine measurable.comp _ hA,\n  refine measurable.comp _ (measurable_sub measurable_const _),\n  exact measurable_of_real,\n  exact measurable_of_continuous nnreal.continuous_coe,\nend\n\n-- Move back to Giry monad \nlemma measurable_measure_kernel [measurable_space \u03b1] [measurable_space \u03b2] {f : \u03b1 \u2192 measure \u03b2} {A : set \u03b2} (hf : measurable f) (hA : is_measurable A) : measurable (\u03bb a, f a A) :=\n measurable.comp (measurable_coe hA) hf\n\n\nlemma measurable_rect_basic {\u03b3 : Type u} [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] [nonempty \u03b2] [nonempty \u03b3] {f : \u03b1 \u2192 probability_measure \u03b2} {g : \u03b1 \u2192 probability_measure \u03b3} (hf : measurable f) (hg : measurable g) : \u2200 (t : set (\u03b2 \u00d7 \u03b3)),t \u2208 {E : set (\u03b2 \u00d7 \u03b3) | \u2203 (A : set \u03b2) (B : set \u03b3), E = set.prod A B \u2227 is_measurable A \u2227 is_measurable B} \u2192 measurable (\u03bb b:\u03b1,(f b \u2297\u209a g b) t) := \nbegin\n  rintros t \u27e8A, B, rfl, hA, hB\u27e9,\n  simp [prod.prob_measure_apply _ _ hA hB],\n  exact measure_theory.measurable_mul (prob.measurable_measure_kernel hf hA) (prob.measurable_measure_kernel hg hB), \nend\n\ntheorem measurable_pair_measure {\u03b3 : Type u} [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3] [nonempty \u03b2] [nonempty \u03b3]{f : \u03b1 \u2192 probability_measure \u03b2} {g : \u03b1 \u2192 probability_measure \u03b3} (hf : measurable f) (hg : measurable g) : measurable (\u03bb x : \u03b1 , f x \u2297\u209a g x) := \nbegin\n  apply prob.measurable_of_measurable_coe,\n  exact \n  @induction_on_inter _ \n  (measurable_prod_measure_pred hf hg) \n  ({E | \u2203 (A : set \u03b2) (B : set \u03b3), (E = A.prod B) \u2227 is_measurable A \u2227 is_measurable B}) _ \n  (measure_rect_generate_from)  (measure_rect_inter) (measurable_rect_empty hf hg) (measurable_rect_basic hf hg) (measurable_rect_compl f g)   (measure_rect_union f g),\nend\n\n\nend prod_measure_measurable\n\n\n\nsection giry_vec\n/- \nAuxilary lemmas about vectors as iterated binary prodcuts.\n-/\nvariable {\u03b1 : Type u}\n\ndef vec : Type u \u2192 \u2115 \u2192 Type u\n| A 0 := A\n| A (succ k) := A \u00d7 vec A k\n\n@[simp] def kth_projn : \u03a0 {n}, vec \u03b1 n \u2192 dfin (succ n) \u2192 \u03b1\n| 0 x  _             := x \n| (succ n) x dfin.fz := x.fst\n| (succ n) (x,xs) (dfin.fs k) := kth_projn xs k\n\ndef vec.set_prod {n : \u2115}(A : set \u03b1) (B : set (vec \u03b1 n)) : set (vec \u03b1 (succ n)) :=\ndo l \u2190 A, xs \u2190 B, pure $ (l,xs)\n\ninstance nonempty.vec [nonempty \u03b1] : \u2200 n, nonempty (vec \u03b1 n) :=\n\u03bb n, \nbegin\ninduction n with k ih,\nrwa vec,\nrw vec, apply nonempty_prod.2, exact (and.intro _inst_1 ih)\nend\n\ninstance vec.measurable_space (n : \u2115) [m : measurable_space \u03b1]: measurable_space (vec \u03b1 n) := \nbegin\n  induction n with k ih, exact m,\n  rw vec, \n  exact (m.comap prod.fst \u2294 ih.comap prod.snd)\nend\n\nnoncomputable def vec.prod_measure [measurable_space \u03b1] (\u03bc : probability_measure \u03b1) \n: \u03a0 n : \u2115, probability_measure (vec \u03b1 n)\n| 0 := \u03bc \n| (succ k) := do\u209a x \u2190\u209a \u03bc ;\n        do\u209a xs \u2190\u209a (vec.prod_measure k);\n        ret\u209a (x,xs)\n\n\ninstance vec.measure_space  [measurable_space \u03b1] (\u03bc : probability_measure \u03b1) : \u03a0 n:\u2115, measure_space (vec \u03b1 n) \n| 0 := \u27e8 \u03bc.to_measure \u27e9\n| (succ k) := \u27e8 (vec.prod_measure \u03bc _).to_measure \u27e9\n\n-- Why doesn't refl work here?!\n@[simp] lemma vec.prod_measure_eq (n : \u2115) [measurable_space \u03b1](\u03bc : probability_measure \u03b1) :\n(vec.prod_measure \u03bc (n+1)) = \u03bc \u2297\u209a (vec.prod_measure \u03bc n)\n:= \nby dunfold vec.prod_measure;refl\n\n\nlemma vec.inl_measurable [measurable_space \u03b1] (n : \u2115): \u2200 xs : vec \u03b1 n, measurable (\u03bb x : \u03b1, (x, xs)) := inl_measurable\n\nlemma vec.inr_measurable [measurable_space \u03b1] (n : \u2115): \u2200 x : \u03b1, measurable (\u03bb xs : vec \u03b1 n,(x,xs)) := inr_measurable\n\nlemma vec.dirac_prod_apply [measurable_space \u03b1]{A : set \u03b1} {n : \u2115} {B : set (vec \u03b1 n)} (hA : is_measurable A) (hB : is_measurable B) (a : \u03b1) (as : vec \u03b1 n) :\n(ret (a,as) : measure (vec \u03b1 (succ n))) (A.prod B) = ((ret a : measure \u03b1) A) * ((ret as : measure (vec \u03b1 n)) B) := dirac.prod_apply hA hB _ _\n\n@[simp] lemma vec.prod_measure_apply {n : \u2115} [measurable_space \u03b1][nonempty \u03b1] (\u03bc : probability_measure \u03b1) (\u03bd : probability_measure (vec \u03b1 n)) {A : set \u03b1} {B : set (vec \u03b1 n)} \n(hA : is_measurable A) (hB : is_measurable B) : \n(\u03bc \u2297\u209a \u03bd) (A.prod B) = \u03bc (A) * \u03bd (B) := prod.prob_measure_apply _ _ hA hB\n\n\ndef vec_map {\u03b1: Type} {\u03b2: Type} (f: \u03b1 \u2192 \u03b2): \u03a0 n: \u2115, vec \u03b1 n \u2192 vec \u03b2 n\n| 0 := \u03bb x, f x\n| (nat.succ n) := \u03bb v, (f v.fst,vec_map n v.snd)\n\nlemma kth_projn_map_comm {\u03b1: Type} {\u03b2: Type}:\n  \u2200 f: \u03b1 \u2192 \u03b2,\n  \u2200 n: \u2115, \u2200 v: vec \u03b1 n, \n  \u2200 i: dfin (succ n), \n  f (kth_projn v i) = kth_projn (vec_map f n v) i :=\nbegin\n  intros f n,\n  induction n; intros,\n  {\n    dunfold vec_map,\n    cases i, simp,\n    refl,\n  },\n  {\n    cases v, \n    cases i,\n    {\n      simp, dunfold vec_map, simp,\n    },\n    {\n      simp,rw n_ih, refl,\n    }\n  }\nend\n\nlemma measurable_map {\u03b1: Type} {\u03b2: Type} [measurable_space \u03b1] [measurable_space \u03b2]:\n  \u2200 n: \u2115, \n  \u2200 f: \u03b1 \u2192 \u03b2,\n  measurable f \u2192 \n  measurable (vec_map f n) :=\nbegin\n  intros,\n  induction n,\n  {\n    intros,\n    dunfold vec_map,\n    assumption,\n  },\n  {\n    intros,\n    dunfold vec_map,\n    apply measurable.prod; simp, \n    {\n      apply measurable.comp,\n      assumption,\n      apply measurable_fst,\n      apply measurable_id,\n    },\n    {\n      apply measurable.comp,\n      assumption,\n      apply measurable_snd,\n      apply measurable_id,\n    }\n  },\nend\n\nend giry_vec\n\n\nsection hoeffding_aux\nopen complex real \n\nlemma abs_le_one_iff_ge_neg_one_le_one {x : \u211d} : (complex.abs x \u2264 1) \u2194 (-1 \u2264 x \u2227 x \u2264 1) := by rw abs_of_real ; apply abs_le\n\nlemma abs_neg_exp_sub_one_le_double {x : \u211d} (h\u2081 : complex.abs x \u2264 1)(h\u2082 : x \u2265 0): complex.abs(exp(-x) - 1) \u2264 2*x := \ncalc \ncomplex.abs(exp(-x) - 1) \n  \u2264 2*complex.abs(-x) : @abs_exp_sub_one_le (-x) ((complex.abs_neg x).symm \u25b8 h\u2081)\n... = 2*complex.abs(x)  : by rw (complex.abs_neg x)\n... = 2*x               : by rw [abs_of_real,((abs_eq h\u2082).2)]; left; refl\n\n\nlemma neg_exp_ge {x : \u211d} (h\u2080 : 0 \u2264 x) (h\u2081 : x \u2264 1) : 1 - 2 * x \u2264 exp (-x)\n:=\nbegin\nhave h : -(2*x) \u2264 exp(-x) -1, {\n  apply (abs_le.1 _).left, \n  rw \u2190abs_of_real, simp [-add_comm, -sub_eq_add_neg],\n  apply abs_neg_exp_sub_one_le_double _ h\u2080, rw abs_le_one_iff_ge_neg_one_le_one, split, linarith, assumption,\n  },\n  linarith,\nend\n\nend hoeffding_aux\n\ninstance : conditionally_complete_linear_order nnreal := \n{\n Sup := Sup,\n  Inf     := Inf,\n  le_cSup := assume s a x has, le_cSup x has,\n  cSup_le := assume s a hs h,show Sup ((coe : nnreal \u2192 \u211d) '' s) \u2264 a, from\n  cSup_le (by simp [hs]) $ assume r \u27e8b, hb, eq\u27e9, eq \u25b8 h _ hb,\n  cInf_le := assume s a x has, cInf_le x has,\n  le_cInf := assume s a hs h, show (\u2191a : \u211d) \u2264 Inf ((coe : nnreal \u2192 \u211d) '' s), from\n  le_cInf (by simp [hs]) $ assume r \u27e8b, hb, eq\u27e9, eq \u25b8 h _ hb,\n decidable_le := begin assume x y, apply classical.dec end,\n .. nnreal.linear_ordered_semiring, \n .. lattice.lattice_of_decidable_linear_order,\n .. nnreal.lattice.order_bot\n}", "meta": {"author": "jtristan", "repo": "stump-learnable", "sha": "aa3c089f41602efa08d31ef6b41e549456186d57", "save_path": "github-repos/lean/jtristan-stump-learnable", "path": "github-repos/lean/jtristan-stump-learnable/stump-learnable-aa3c089f41602efa08d31ef6b41e549456186d57/src/lib/attributed/to_mathlib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7059115171053512}}
{"text": "/-\nCopyright (c) 2019 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.filter.basic\nimport Mathlib.PostPort\n\nuniverses u v w x u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# Minimum and maximum w.r.t. a filter and on a aet\n\n## Main Definitions\n\nThis file defines six predicates of the form `is_A_B`, where `A` is `min`, `max`, or `extr`,\nand `B` is `filter` or `on`.\n\n* `is_min_filter f l a` means that `f a \u2264 f x` in some `l`-neighborhood of `a`;\n* `is_max_filter f l a` means that `f x \u2264 f a` in some `l`-neighborhood of `a`;\n* `is_extr_filter f l a` means `is_min_filter f l a` or `is_max_filter f l a`.\n\nSimilar predicates with `_on` suffix are particular cases for `l = \ud835\udcdf s`.\n\n## Main statements\n\n### Change of the filter (set) argument\n\n* `is_*_filter.filter_mono` : replace the filter with a smaller one;\n* `is_*_filter.filter_inf` : replace a filter `l` with `l \u2293 l'`;\n* `is_*_on.on_subset` : restrict to a smaller set;\n* `is_*_on.inter` : replace a set `s` wtih `s \u2229 t`.\n\n### Composition\n\n* `is_*_*.comp_mono` : if `x` is an extremum for `f` and `g` is a monotone function,\n  then `x` is an extremum for `g \u2218 f`;\n* `is_*_*.comp_antimono` : similarly for the case of monotonically decreasing `g`;\n* `is_*_*.bicomp_mono` : if `x` is an extremum of the same type for `f` and `g`\n  and a binary operation `op` is monotone in both arguments, then `x` is an extremum\n  of the same type for `\u03bb x, op (f x) (g x)`.\n* `is_*_filter.comp_tendsto` : if `g x` is an extremum for `f` w.r.t. `l'` and `tendsto g l l'`,\n  then `x` is an extremum for `f \u2218 g` w.r.t. `l`.\n* `is_*_on.on_preimage` : if `g x` is an extremum for `f` on `s`, then `x` is an extremum\n  for `f \u2218 g` on `g \u207b\u00b9' s`.\n\n### Algebraic operations\n\n* `is_*_*.add` : if `x` is an extremum of the same type for two functions,\n  then it is an extremum of the same type for their sum;\n* `is_*_*.neg` : if `x` is an extremum for `f`, then it is an extremum\n  of the opposite type for `-f`;\n* `is_*_*.sub` : if `x` is an a minimum for `f` and a maximum for `g`,\n  then it is a minimum for `f - g` and a maximum for `g - f`;\n* `is_*_*.max`, `is_*_*.min`, `is_*_*.sup`, `is_*_*.inf` : similarly for `is_*_*.add`\n  for pointwise `max`, `min`, `sup`, `inf`, respectively.\n\n\n### Miscellaneous definitions\n\n* `is_*_*_const` : any point is both a minimum and maximum for a constant function;\n* `is_min/max_*.is_ext` : any minimum/maximum point is an extremum;\n* `is_*_*.dual`, `is_*_*.undual`: conversion between codomains `\u03b1` and `dual \u03b1`;\n\n## Missing features (TODO)\n\n* Multiplication and division;\n* `is_*_*.bicompl` : if `x` is a minimum for `f`, `y` is a minimum for `g`, and `op` is a monotone\n  binary operation, then `(x, y)` is a minimum for `uncurry (bicompl op f g)`. From this point of view,\n  `is_*_*.bicomp` is a composition\n* It would be nice to have a tactic that specializes `comp_(anti)mono` or `bicomp_mono`\n  based on a proof of monotonicity of a given (binary) function. The tactic should maintain a `meta`\n  list of known (anti)monotone (binary) functions with their names, as well as a list of special\n  types of filters, and define the missing lemmas once one of these two lists grows.\n-/\n\n/-! ### Definitions -/\n\n/-- `is_min_filter f l a` means that `f a \u2264 f x` in some `l`-neighborhood of `a` -/\ndef is_min_filter {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (l : filter \u03b1) (a : \u03b1) :=\n  filter.eventually (fun (x : \u03b1) => f a \u2264 f x) l\n\n/-- `is_max_filter f l a` means that `f x \u2264 f a` in some `l`-neighborhood of `a` -/\ndef is_max_filter {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (l : filter \u03b1) (a : \u03b1) :=\n  filter.eventually (fun (x : \u03b1) => f x \u2264 f a) l\n\n/-- `is_extr_filter f l a` means `is_min_filter f l a` or `is_max_filter f l a` -/\ndef is_extr_filter {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (l : filter \u03b1) (a : \u03b1) :=\n  is_min_filter f l a \u2228 is_max_filter f l a\n\n/-- `is_min_on f s a` means that `f a \u2264 f x` for all `x \u2208 a`. Note that we do not assume `a \u2208 s`. -/\ndef is_min_on {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (a : \u03b1) :=\n  is_min_filter f (filter.principal s) a\n\n/-- `is_max_on f s a` means that `f x \u2264 f a` for all `x \u2208 a`. Note that we do not assume `a \u2208 s`. -/\ndef is_max_on {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (a : \u03b1) :=\n  is_max_filter f (filter.principal s) a\n\n/-- `is_extr_on f s a` means `is_min_on f s a` or `is_max_on f s a` -/\ndef is_extr_on {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] (f : \u03b1 \u2192 \u03b2) (s : set \u03b1) (a : \u03b1) :=\n  is_extr_filter f (filter.principal s) a\n\ntheorem is_extr_on.elim {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {p : Prop} : is_extr_on f s a \u2192 (is_min_on f s a \u2192 p) \u2192 (is_max_on f s a \u2192 p) \u2192 p :=\n  or.elim\n\ntheorem is_min_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_min_on f s a \u2194 \u2200 (x : \u03b1), x \u2208 s \u2192 f a \u2264 f x :=\n  iff.rfl\n\ntheorem is_max_on_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_max_on f s a \u2194 \u2200 (x : \u03b1), x \u2208 s \u2192 f x \u2264 f a :=\n  iff.rfl\n\ntheorem is_min_on_univ_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} : is_min_on f set.univ a \u2194 \u2200 (x : \u03b1), f a \u2264 f x :=\n  iff.trans set.univ_subset_iff set.eq_univ_iff_forall\n\ntheorem is_max_on_univ_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} : is_max_on f set.univ a \u2194 \u2200 (x : \u03b1), f x \u2264 f a :=\n  iff.trans set.univ_subset_iff set.eq_univ_iff_forall\n\n/-! ### Conversion to `is_extr_*` -/\n\ntheorem is_min_filter.is_extr {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_min_filter f l a \u2192 is_extr_filter f l a :=\n  Or.inl\n\ntheorem is_max_filter.is_extr {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_max_filter f l a \u2192 is_extr_filter f l a :=\n  Or.inr\n\ntheorem is_min_on.is_extr {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (h : is_min_on f s a) : is_extr_on f s a :=\n  is_min_filter.is_extr h\n\ntheorem is_max_on.is_extr {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (h : is_max_on f s a) : is_extr_on f s a :=\n  is_max_filter.is_extr h\n\n/-! ### Constant function -/\n\ntheorem is_min_filter_const {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {l : filter \u03b1} {a : \u03b1} {b : \u03b2} : is_min_filter (fun (_x : \u03b1) => b) l a :=\n  filter.univ_mem_sets' fun (_x : \u03b1) => le_refl ((fun (_x : \u03b1) => b) a)\n\ntheorem is_max_filter_const {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {l : filter \u03b1} {a : \u03b1} {b : \u03b2} : is_max_filter (fun (_x : \u03b1) => b) l a :=\n  filter.univ_mem_sets' fun (_x : \u03b1) => le_refl ((fun (_x : \u03b1) => b) _x)\n\ntheorem is_extr_filter_const {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {l : filter \u03b1} {a : \u03b1} {b : \u03b2} : is_extr_filter (fun (_x : \u03b1) => b) l a :=\n  is_min_filter.is_extr is_min_filter_const\n\ntheorem is_min_on_const {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_min_on (fun (_x : \u03b1) => b) s a :=\n  is_min_filter_const\n\ntheorem is_max_on_const {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_max_on (fun (_x : \u03b1) => b) s a :=\n  is_max_filter_const\n\ntheorem is_extr_on_const {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {s : set \u03b1} {a : \u03b1} {b : \u03b2} : is_extr_on (fun (_x : \u03b1) => b) s a :=\n  is_extr_filter_const\n\n/-! ### Order dual -/\n\ntheorem is_min_filter_dual_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_min_filter f l a \u2194 is_max_filter f l a :=\n  iff.rfl\n\ntheorem is_max_filter_dual_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_max_filter f l a \u2194 is_min_filter f l a :=\n  iff.rfl\n\ntheorem is_extr_filter_dual_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_extr_filter f l a \u2194 is_extr_filter f l a :=\n  or_comm (is_min_filter f l a) (is_max_filter f l a)\n\ntheorem is_max_filter.dual {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_max_filter f l a \u2192 is_min_filter f l a :=\n  iff.mpr is_min_filter_dual_iff\n\ntheorem is_max_filter.undual {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_max_filter f l a \u2192 is_min_filter f l a :=\n  iff.mp is_max_filter_dual_iff\n\ntheorem is_extr_filter.dual {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} : is_extr_filter f l a \u2192 is_extr_filter f l a :=\n  iff.mpr is_extr_filter_dual_iff\n\ntheorem is_min_on_dual_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_min_on f s a \u2194 is_max_on f s a :=\n  iff.rfl\n\ntheorem is_max_on_dual_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_max_on f s a \u2194 is_min_on f s a :=\n  iff.rfl\n\ntheorem is_extr_on_dual_iff {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_extr_on f s a \u2194 is_extr_on f s a :=\n  or_comm (is_min_filter f (filter.principal s) a) (is_max_filter f (filter.principal s) a)\n\ntheorem is_max_on.dual {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_max_on f s a \u2192 is_min_on f s a :=\n  iff.mpr is_min_on_dual_iff\n\ntheorem is_min_on.dual {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_min_on f s a \u2192 is_max_on f s a :=\n  iff.mpr is_max_on_dual_iff\n\ntheorem is_extr_on.dual {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} : is_extr_on f s a \u2192 is_extr_on f s a :=\n  iff.mpr is_extr_on_dual_iff\n\n/-! ### Operations on the filter/set -/\n\ntheorem is_min_filter.filter_mono {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} {l' : filter \u03b1} (h : is_min_filter f l a) (hl : l' \u2264 l) : is_min_filter f l' a :=\n  hl h\n\ntheorem is_max_filter.filter_mono {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} {l' : filter \u03b1} (h : is_max_filter f l a) (hl : l' \u2264 l) : is_max_filter f l' a :=\n  hl h\n\ntheorem is_extr_filter.filter_mono {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} {l' : filter \u03b1} (h : is_extr_filter f l a) (hl : l' \u2264 l) : is_extr_filter f l' a :=\n  or.elim h (fun (h : is_min_filter f l a) => is_min_filter.is_extr (is_min_filter.filter_mono h hl))\n    fun (h : is_max_filter f l a) => is_max_filter.is_extr (is_max_filter.filter_mono h hl)\n\ntheorem is_min_filter.filter_inf {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (h : is_min_filter f l a) (l' : filter \u03b1) : is_min_filter f (l \u2293 l') a :=\n  is_min_filter.filter_mono h inf_le_left\n\ntheorem is_max_filter.filter_inf {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (h : is_max_filter f l a) (l' : filter \u03b1) : is_max_filter f (l \u2293 l') a :=\n  is_max_filter.filter_mono h inf_le_left\n\ntheorem is_extr_filter.filter_inf {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (h : is_extr_filter f l a) (l' : filter \u03b1) : is_extr_filter f (l \u2293 l') a :=\n  is_extr_filter.filter_mono h inf_le_left\n\ntheorem is_min_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_min_on f t a) (h : s \u2286 t) : is_min_on f s a :=\n  is_min_filter.filter_mono hf (iff.mpr filter.principal_mono h)\n\ntheorem is_max_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_max_on f t a) (h : s \u2286 t) : is_max_on f s a :=\n  is_max_filter.filter_mono hf (iff.mpr filter.principal_mono h)\n\ntheorem is_extr_on.on_subset {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} {t : set \u03b1} (hf : is_extr_on f t a) (h : s \u2286 t) : is_extr_on f s a :=\n  is_extr_filter.filter_mono hf (iff.mpr filter.principal_mono h)\n\ntheorem is_min_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_min_on f s a) (t : set \u03b1) : is_min_on f (s \u2229 t) a :=\n  is_min_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_max_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_max_on f s a) (t : set \u03b1) : is_max_on f (s \u2229 t) a :=\n  is_max_on.on_subset hf (set.inter_subset_left s t)\n\ntheorem is_extr_on.inter {\u03b1 : Type u} {\u03b2 : Type v} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_extr_on f s a) (t : set \u03b1) : is_extr_on f (s \u2229 t) a :=\n  is_extr_on.on_subset hf (set.inter_subset_left s t)\n\n/-! ### Composition with (anti)monotone functions -/\n\ntheorem is_min_filter.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (hf : is_min_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_min_filter (g \u2218 f) l a :=\n  filter.mem_sets_of_superset hf fun (x : \u03b1) (hx : x \u2208 set_of fun (x : \u03b1) => (fun (x : \u03b1) => f a \u2264 f x) x) => hg hx\n\ntheorem is_max_filter.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (hf : is_max_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_max_filter (g \u2218 f) l a :=\n  filter.mem_sets_of_superset hf fun (x : \u03b1) (hx : x \u2208 set_of fun (x : \u03b1) => (fun (x : \u03b1) => f x \u2264 f a) x) => hg hx\n\ntheorem is_extr_filter.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (hf : is_extr_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_extr_filter (g \u2218 f) l a :=\n  or.elim hf (fun (hf : is_min_filter f l a) => is_min_filter.is_extr (is_min_filter.comp_mono hf hg))\n    fun (hf : is_max_filter f l a) => is_max_filter.is_extr (is_max_filter.comp_mono hf hg)\n\ntheorem is_min_filter.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (hf : is_min_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_max_filter (g \u2218 f) l a :=\n  is_max_filter.comp_mono (is_min_filter.dual hf) fun (x y : order_dual \u03b2) (h : x \u2264 y) => hg h\n\ntheorem is_max_filter.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (hf : is_max_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_min_filter (g \u2218 f) l a :=\n  is_min_filter.comp_mono (is_max_filter.dual hf) fun (x y : order_dual \u03b2) (h : x \u2264 y) => hg h\n\ntheorem is_extr_filter.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} (hf : is_extr_filter f l a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_extr_filter (g \u2218 f) l a :=\n  is_extr_filter.comp_mono (is_extr_filter.dual hf) fun (x y : order_dual \u03b2) (h : x \u2264 y) => hg h\n\ntheorem is_min_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_min_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_min_on (g \u2218 f) s a :=\n  is_min_filter.comp_mono hf hg\n\ntheorem is_max_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_max_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_max_on (g \u2218 f) s a :=\n  is_max_filter.comp_mono hf hg\n\ntheorem is_extr_on.comp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_extr_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : monotone g) : is_extr_on (g \u2218 f) s a :=\n  is_extr_filter.comp_mono hf hg\n\ntheorem is_min_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_min_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_max_on (g \u2218 f) s a :=\n  is_min_filter.comp_antimono hf hg\n\ntheorem is_max_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_max_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_min_on (g \u2218 f) s a :=\n  is_max_filter.comp_antimono hf hg\n\ntheorem is_extr_on.comp_antimono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} (hf : is_extr_on f s a) {g : \u03b2 \u2192 \u03b3} (hg : \u2200 {x y : \u03b2}, x \u2264 y \u2192 g y \u2264 g x) : is_extr_on (g \u2218 f) s a :=\n  is_extr_filter.comp_antimono hf hg\n\ntheorem is_min_filter.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_min_filter f l a) {g : \u03b1 \u2192 \u03b3} (hg : is_min_filter g l a) : is_min_filter (fun (x : \u03b1) => op (f x) (g x)) l a := sorry\n\ntheorem is_max_filter.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_max_filter f l a) {g : \u03b1 \u2192 \u03b3} (hg : is_max_filter g l a) : is_max_filter (fun (x : \u03b1) => op (f x) (g x)) l a := sorry\n\n-- No `extr` version because we need `hf` and `hg` to be of the same kind\n\ntheorem is_min_on.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_min_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_min_on g s a) : is_min_on (fun (x : \u03b1) => op (f x) (g x)) s a :=\n  is_min_filter.bicomp_mono hop hf hg\n\ntheorem is_max_on.bicomp_mono {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x} [preorder \u03b2] [preorder \u03b3] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} {a : \u03b1} [preorder \u03b4] {op : \u03b2 \u2192 \u03b3 \u2192 \u03b4} (hop : relator.lift_fun LessEq (LessEq \u21d2 LessEq) op op) (hf : is_max_on f s a) {g : \u03b1 \u2192 \u03b3} (hg : is_max_on g s a) : is_max_on (fun (x : \u03b1) => op (f x) (g x)) s a :=\n  is_max_filter.bicomp_mono hop hf hg\n\n/-! ### Composition with `tendsto` -/\n\ntheorem is_min_filter.comp_tendsto {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {g : \u03b4 \u2192 \u03b1} {l' : filter \u03b4} {b : \u03b4} (hf : is_min_filter f l (g b)) (hg : filter.tendsto g l' l) : is_min_filter (f \u2218 g) l' b :=\n  hg hf\n\ntheorem is_max_filter.comp_tendsto {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {g : \u03b4 \u2192 \u03b1} {l' : filter \u03b4} {b : \u03b4} (hf : is_max_filter f l (g b)) (hg : filter.tendsto g l' l) : is_max_filter (f \u2218 g) l' b :=\n  hg hf\n\ntheorem is_extr_filter.comp_tendsto {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {l : filter \u03b1} {g : \u03b4 \u2192 \u03b1} {l' : filter \u03b4} {b : \u03b4} (hf : is_extr_filter f l (g b)) (hg : filter.tendsto g l' l) : is_extr_filter (f \u2218 g) l' b :=\n  or.elim hf (fun (hf : is_min_filter f l (g b)) => is_min_filter.is_extr (is_min_filter.comp_tendsto hf hg))\n    fun (hf : is_max_filter f l (g b)) => is_max_filter.is_extr (is_max_filter.comp_tendsto hf hg)\n\ntheorem is_min_on.on_preimage {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_min_on f s (g b)) : is_min_on (f \u2218 g) (g \u207b\u00b9' s) b :=\n  is_min_filter.comp_tendsto hf (iff.mpr filter.tendsto_principal_principal (set.subset.refl (g \u207b\u00b9' s)))\n\ntheorem is_max_on.on_preimage {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_max_on f s (g b)) : is_max_on (f \u2218 g) (g \u207b\u00b9' s) b :=\n  is_max_filter.comp_tendsto hf (iff.mpr filter.tendsto_principal_principal (set.subset.refl (g \u207b\u00b9' s)))\n\ntheorem is_extr_on.on_preimage {\u03b1 : Type u} {\u03b2 : Type v} {\u03b4 : Type x} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : set \u03b1} (g : \u03b4 \u2192 \u03b1) {b : \u03b4} (hf : is_extr_on f s (g b)) : is_extr_on (f \u2218 g) (g \u207b\u00b9' s) b :=\n  is_extr_on.elim hf (fun (hf : is_min_on f s (g b)) => is_min_on.is_extr (is_min_on.on_preimage g hf))\n    fun (hf : is_max_on f s (g b)) => is_max_on.is_extr (is_max_on.on_preimage g hf)\n\n/-! ### Pointwise addition -/\n\ntheorem is_min_filter.add {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (fun (x : \u03b1) => f x + g x) l a :=\n  (fun (this : is_min_filter (fun (x : \u03b1) => f x + g x) l a) => this)\n    (is_min_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => add_le_add hx hy) hf hg)\n\ntheorem is_max_filter.add {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (fun (x : \u03b1) => f x + g x) l a :=\n  (fun (this : is_max_filter (fun (x : \u03b1) => f x + g x) l a) => this)\n    (is_max_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => add_le_add hx hy) hf hg)\n\ntheorem is_min_on.add {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (fun (x : \u03b1) => f x + g x) s a :=\n  is_min_filter.add hf hg\n\ntheorem is_max_on.add {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_monoid \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (fun (x : \u03b1) => f x + g x) s a :=\n  is_max_filter.add hf hg\n\n/-! ### Pointwise negation and subtraction -/\n\ntheorem is_min_filter.neg {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_min_filter f l a) : is_max_filter (fun (x : \u03b1) => -f x) l a :=\n  is_min_filter.comp_antimono hf fun (x y : \u03b2) (hx : x \u2264 y) => neg_le_neg hx\n\ntheorem is_max_filter.neg {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_max_filter f l a) : is_min_filter (fun (x : \u03b1) => -f x) l a :=\n  is_max_filter.comp_antimono hf fun (x y : \u03b2) (hx : x \u2264 y) => neg_le_neg hx\n\ntheorem is_extr_filter.neg {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_extr_filter f l a) : is_extr_filter (fun (x : \u03b1) => -f x) l a :=\n  or.elim hf (fun (hf : is_min_filter f l a) => is_max_filter.is_extr (is_min_filter.neg hf))\n    fun (hf : is_max_filter f l a) => is_min_filter.is_extr (is_max_filter.neg hf)\n\ntheorem is_min_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_min_on f s a) : is_max_on (fun (x : \u03b1) => -f x) s a :=\n  is_min_on.comp_antimono hf fun (x y : \u03b2) (hx : x \u2264 y) => neg_le_neg hx\n\ntheorem is_max_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_max_on f s a) : is_min_on (fun (x : \u03b1) => -f x) s a :=\n  is_max_on.comp_antimono hf fun (x y : \u03b2) (hx : x \u2264 y) => neg_le_neg hx\n\ntheorem is_extr_on.neg {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_extr_on f s a) : is_extr_on (fun (x : \u03b1) => -f x) s a :=\n  is_extr_on.elim hf (fun (hf : is_min_on f s a) => is_max_on.is_extr (is_min_on.neg hf))\n    fun (hf : is_max_on f s a) => is_min_on.is_extr (is_max_on.neg hf)\n\ntheorem is_min_filter.sub {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_min_filter f l a) (hg : is_max_filter g l a) : is_min_filter (fun (x : \u03b1) => f x - g x) l a := sorry\n\ntheorem is_max_filter.sub {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_max_filter f l a) (hg : is_min_filter g l a) : is_max_filter (fun (x : \u03b1) => f x - g x) l a := sorry\n\ntheorem is_min_on.sub {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_min_on f s a) (hg : is_max_on g s a) : is_min_on (fun (x : \u03b1) => f x - g x) s a := sorry\n\ntheorem is_max_on.sub {\u03b1 : Type u} {\u03b2 : Type v} [ordered_add_comm_group \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_max_on f s a) (hg : is_min_on g s a) : is_max_on (fun (x : \u03b1) => f x - g x) s a := sorry\n\n/-! ### Pointwise `sup`/`inf` -/\n\ntheorem is_min_filter.sup {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (fun (x : \u03b1) => f x \u2294 g x) l a :=\n  (fun (this : is_min_filter (fun (x : \u03b1) => f x \u2294 g x) l a) => this)\n    (is_min_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => sup_le_sup hx hy) hf hg)\n\ntheorem is_max_filter.sup {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (fun (x : \u03b1) => f x \u2294 g x) l a :=\n  (fun (this : is_max_filter (fun (x : \u03b1) => f x \u2294 g x) l a) => this)\n    (is_max_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => sup_le_sup hx hy) hf hg)\n\ntheorem is_min_on.sup {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (fun (x : \u03b1) => f x \u2294 g x) s a :=\n  is_min_filter.sup hf hg\n\ntheorem is_max_on.sup {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_sup \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (fun (x : \u03b1) => f x \u2294 g x) s a :=\n  is_max_filter.sup hf hg\n\ntheorem is_min_filter.inf {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (fun (x : \u03b1) => f x \u2293 g x) l a :=\n  (fun (this : is_min_filter (fun (x : \u03b1) => f x \u2293 g x) l a) => this)\n    (is_min_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => inf_le_inf hx hy) hf hg)\n\ntheorem is_max_filter.inf {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (fun (x : \u03b1) => f x \u2293 g x) l a :=\n  (fun (this : is_max_filter (fun (x : \u03b1) => f x \u2293 g x) l a) => this)\n    (is_max_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => inf_le_inf hx hy) hf hg)\n\ntheorem is_min_on.inf {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (fun (x : \u03b1) => f x \u2293 g x) s a :=\n  is_min_filter.inf hf hg\n\ntheorem is_max_on.inf {\u03b1 : Type u} {\u03b2 : Type v} [semilattice_inf \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (fun (x : \u03b1) => f x \u2293 g x) s a :=\n  is_max_filter.inf hf hg\n\n/-! ### Pointwise `min`/`max` -/\n\ntheorem is_min_filter.min {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (fun (x : \u03b1) => min (f x) (g x)) l a :=\n  (fun (this : is_min_filter (fun (x : \u03b1) => min (f x) (g x)) l a) => this)\n    (is_min_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => min_le_min hx hy) hf hg)\n\ntheorem is_max_filter.min {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (fun (x : \u03b1) => min (f x) (g x)) l a :=\n  (fun (this : is_max_filter (fun (x : \u03b1) => min (f x) (g x)) l a) => this)\n    (is_max_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => min_le_min hx hy) hf hg)\n\ntheorem is_min_on.min {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (fun (x : \u03b1) => min (f x) (g x)) s a :=\n  is_min_filter.min hf hg\n\ntheorem is_max_on.min {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (fun (x : \u03b1) => min (f x) (g x)) s a :=\n  is_max_filter.min hf hg\n\ntheorem is_min_filter.max {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_min_filter f l a) (hg : is_min_filter g l a) : is_min_filter (fun (x : \u03b1) => max (f x) (g x)) l a :=\n  (fun (this : is_min_filter (fun (x : \u03b1) => max (f x) (g x)) l a) => this)\n    (is_min_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => max_le_max hx hy) hf hg)\n\ntheorem is_max_filter.max {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hf : is_max_filter f l a) (hg : is_max_filter g l a) : is_max_filter (fun (x : \u03b1) => max (f x) (g x)) l a :=\n  (fun (this : is_max_filter (fun (x : \u03b1) => max (f x) (g x)) l a) => this)\n    (is_max_filter.bicomp_mono (fun (x x' : \u03b2) (hx : x \u2264 x') (y y' : \u03b2) (hy : y \u2264 y') => max_le_max hx hy) hf hg)\n\ntheorem is_min_on.max {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_min_on f s a) (hg : is_min_on g s a) : is_min_on (fun (x : \u03b1) => max (f x) (g x)) s a :=\n  is_min_filter.max hf hg\n\ntheorem is_max_on.max {\u03b1 : Type u} {\u03b2 : Type v} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {s : set \u03b1} (hf : is_max_on f s a) (hg : is_max_on g s a) : is_max_on (fun (x : \u03b1) => max (f x) (g x)) s a :=\n  is_max_filter.max hf hg\n\n/-! ### Relation with `eventually` comparisons of two functions -/\n\ntheorem filter.eventually_le.is_max_filter {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hle : filter.eventually_le l g f) (hfga : f a = g a) (h : is_max_filter f l a) : is_max_filter g l a := sorry\n\ntheorem is_max_filter.congr {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (h : is_max_filter f l a) (heq : filter.eventually_eq l f g) (hfga : f a = g a) : is_max_filter g l a :=\n  filter.eventually_le.is_max_filter (filter.eventually_eq.le (filter.eventually_eq.symm heq)) hfga h\n\ntheorem filter.eventually_eq.is_max_filter_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (heq : filter.eventually_eq l f g) (hfga : f a = g a) : is_max_filter f l a \u2194 is_max_filter g l a :=\n  { mp := fun (h : is_max_filter f l a) => is_max_filter.congr h heq hfga,\n    mpr := fun (h : is_max_filter g l a) => is_max_filter.congr h (filter.eventually_eq.symm heq) (Eq.symm hfga) }\n\ntheorem filter.eventually_le.is_min_filter {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (hle : filter.eventually_le l f g) (hfga : f a = g a) (h : is_min_filter f l a) : is_min_filter g l a :=\n  filter.eventually_le.is_max_filter hle hfga h\n\ntheorem is_min_filter.congr {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (h : is_min_filter f l a) (heq : filter.eventually_eq l f g) (hfga : f a = g a) : is_min_filter g l a :=\n  filter.eventually_le.is_min_filter (filter.eventually_eq.le heq) hfga h\n\ntheorem filter.eventually_eq.is_min_filter_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (heq : filter.eventually_eq l f g) (hfga : f a = g a) : is_min_filter f l a \u2194 is_min_filter g l a :=\n  { mp := fun (h : is_min_filter f l a) => is_min_filter.congr h heq hfga,\n    mpr := fun (h : is_min_filter g l a) => is_min_filter.congr h (filter.eventually_eq.symm heq) (Eq.symm hfga) }\n\ntheorem is_extr_filter.congr {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (h : is_extr_filter f l a) (heq : filter.eventually_eq l f g) (hfga : f a = g a) : is_extr_filter g l a := sorry\n\ntheorem filter.eventually_eq.is_extr_filter_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [preorder \u03b2] {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b2} {a : \u03b1} {l : filter \u03b1} (heq : filter.eventually_eq l f g) (hfga : f a = g a) : is_extr_filter f l a \u2194 is_extr_filter g l a :=\n  { mp := fun (h : is_extr_filter f l a) => is_extr_filter.congr h heq hfga,\n    mpr := fun (h : is_extr_filter g l a) => is_extr_filter.congr h (filter.eventually_eq.symm heq) (Eq.symm hfga) }\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/filter/extr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7059115147323837}}
{"text": "import game.sets.L01defs -- hide\n\nnamespace xena -- hide\n\nvariable X : Type -- hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 2\n-/\n\n/- \nWorking with sets is very similar to working with propositions.\nLet's now prove that any set $A$ is included in its union with \nany other set $B$, or $A \u2286 A \u222a B$. \n\nOur goal is definitionally equivalent to `\u2200 x \u2208 A, x \u2208 (A \u222a B)`.\nThe definition of `x \u2208 (A \u222a B)` is `x \u2208 A \u2228 x \u2208 B`.\n\nYou should already know the tactics needed to prove this goal, so give \nit a try before checking the hints.\n-/\n\n/- Hint : Hint : The proof steps may become clearer if you change the goal.\nUse the `change` tactic and the definitions give above:\n\n`change \u2200 x \u2208 A, x \u2208 A \u2228 x \u2208 B,`\n\nThis will change your goal to the definitionally equivalent \n\n`\u2200 x : X, x \u2208 A \u21fe x \u2208 A \u2228 x \u2208 B`\n\nStart your proof of `\u2200 (x : X) ...` in the way you learned in the previous level.\n\nYou will then have a statement of propositional form `\u03b1 \u2192 \u03b2 \u2228 \u03b3`. See if you can use your knowledge of propositions to solve this!\n-/\n\n/- Hint : Hint : After introducing your terms, you'll need to prove the `left` side of a disjunction.\nWith or without the `change` lines, you can introduce the \nhypotheses we need by using \n\n`intros x hx,`\n\nNow the equivalence with the world of propositions will become apparent. \n\nTo prove that the union of two sets is inhabited is to prove the disjunction \n$P \u2228 Q$ of two propositions. In this case, $P$ is our statement $x \u2208 A$.\n\nChoosing `left,` will change our goal to the first disjunct. \n\nYou should now be able to easily finish the proof.\n-/\n\n\n/- Lemma\nIf $A$ and $B$ are sets of any type $X$, then\n$$ A \\subseteq A\\cup B.$$ \n-/\ntheorem subset_union_left (A B : set X) : A \u2286 A \u222a B :=\nbegin\n    --change \u2200 (x : \u03b1), x \u2208 A \u2192 x \u2208 A \u222a B,  --they may want to do this\n    intros x hx,\n    left, exact hx, done\n\nend\n\nend xena --hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/kb_solns/sets_level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7058994750204078}}
{"text": "inductive Expr : Type\n  | const (n : Nat)\n  | plus (e\u2081 e\u2082 : Expr)\n  | mul (e\u2081 e\u2082 : Expr)\n  deriving BEq, Inhabited, Repr, DecidableEq\n\ndef Expr.eval : Expr \u2192 Nat\n  | const n    => n\n  | plus e\u2081 e\u2082 => eval e\u2081 + eval e\u2082\n  | mul e\u2081 e\u2082  => eval e\u2081 * eval e\u2082\n\ndef Expr.times : Nat \u2192 Expr \u2192 Expr\n  | k, const n    => const (k*n)\n  | k, plus e\u2081 e\u2082 => plus (times k e\u2081) (times k e\u2082)\n  | k, mul e\u2081 e\u2082  => mul (times k e\u2081) e\u2082\n\ntheorem eval_times (k : Nat) (e : Expr) : (e.times k |>.eval) = k * e.eval := by\n  induction e with simp [Expr.times, Expr.eval]\n  | plus e\u2081 e\u2082 ih\u2081 ih\u2082 => simp [ih\u2081, ih\u2082, Nat.left_distrib]\n  | mul  _ _ ih\u2081 ih\u2082   => simp [ih\u2081, Nat.mul_assoc]\n\ndef Expr.reassoc : Expr \u2192 Expr\n  | const n    => const n\n  | plus e\u2081 e\u2082 =>\n    let e\u2081' := e\u2081.reassoc\n    let e\u2082' := e\u2082.reassoc\n    match e\u2082' with\n    | plus e\u2082\u2081 e\u2082\u2082 => plus (plus e\u2081' e\u2082\u2081) e\u2082\u2082\n    | _            => plus e\u2081' e\u2082'\n  | mul e\u2081 e\u2082 =>\n    let e\u2081' := e\u2081.reassoc\n    let e\u2082' := e\u2082.reassoc\n    match e\u2082' with\n    | mul e\u2082\u2081 e\u2082\u2082 => mul (mul e\u2081' e\u2082\u2081) e\u2082\u2082\n    | _           => mul e\u2081' e\u2082'\n\ntheorem eval_reassoc (e : Expr) : e.reassoc.eval = e.eval := by\n  induction e with simp [Expr.reassoc]\n  | plus e\u2081 e\u2082 ih\u2081 ih\u2082 =>\n    generalize h : Expr.reassoc e\u2082 = e\u2082'\n    cases e\u2082' <;> rw [h] at ih\u2082 <;> simp [Expr.eval] at * <;> rw [\u2190 ih\u2082, ih\u2081]; rw [Nat.add_assoc]\n  | mul e\u2081 e\u2082 ih\u2081 ih\u2082 =>\n    generalize h : Expr.reassoc e\u2082 = e\u2082'\n    cases e\u2082' <;> rw [h] at ih\u2082 <;> simp [Expr.eval] at * <;> rw [\u2190 ih\u2082, ih\u2081]; rw [Nat.mul_assoc]\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/exp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7058994679392945}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar la unicidad de los l\u00edmites de las sucesiones\n-- convergentes.\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_convergencia\n\nopen_locale classical\n\ntheorem converges_to_unique\n  {s : \u2115 \u2192 \u211d}\n  {a b : \u211d}\n  (sa : converges_to s a)\n  (sb : converges_to s b)\n  : a = b :=\nbegin\n  by_contradiction abne,\n  have : abs (a - b) > 0,\n  { apply abs_pos.mpr,\n    exact sub_ne_zero_of_ne abne,\n    exact ordered_add_comm_monoid.to_covariant_class_left \u211d, },\n  let \u03b5 := abs (a - b) / 2,\n  have \u03b5pos : \u03b5 > 0,\n  { change abs (a - b) / 2 > 0,\n    linarith },\n  cases sa \u03b5 \u03b5pos with Na hNa,\n  cases sb \u03b5 \u03b5pos with Nb hNb,\n  let N := max Na Nb,\n  have absa : abs (s N - a) < \u03b5,\n  { specialize hNa N,\n    apply hNa,\n    exact le_max_left Na Nb },\n  have absb : abs (s N - b) < \u03b5,\n  { specialize hNb N,\n    apply hNb,\n    exact le_max_right Na Nb },\n  have : abs (a - b) < abs (a - b),\n    calc abs (a - b)\n         = abs ((a - s N) + (s N - b))      : by {congr, ring_nf}\n     ... \u2264 abs (a - s N) + abs (s N - b)    : abs_add (a - s N) (s N - b)\n     ... = abs (s N - a) + abs (s N - b)    : by rw abs_sub_comm\n     ... < \u03b5 + \u03b5                            : by exact add_lt_add absa absb\n     ... = abs (a - b)                      : by exact add_halves (abs (a - b)),\n  exact lt_irrefl _ this,\nend\n\n-- Prueba\n-- ======\n\n/-\ns : \u2115 \u2192 \u211d,\na b : \u211d,\nsa : converges_to s a,\nsb : converges_to s b\n\u22a2 a = b\n  >> by_contradiction abne,\nabne : \u00aca = b\n\u22a2 false\n  >> have : abs (a - b) > 0,\n| \u22a2 abs (a - b) > 0\n|   >> { apply abs_pos_of_ne_zero,\n| \u22a2 a - b \u2260 0\n|   >>   exact sub_ne_zero_of_ne abne },\nthis : abs (a - b) > 0\n\u22a2 false\n  >> let \u03b5 := abs (a - b) / 2,\n\u03b5 : \u211d := abs (a - b) / 2\n\u22a2 false\n  >> have \u03b5pos : \u03b5 > 0,\n| \u22a2 \u03b5 > 0\n|   >> { change abs (a - b) / 2 > 0,\n| \u22a2 abs (a - b) / 2 > 0\n|   >>   linarith },\n\u03b5pos : \u03b5 > 0\n\u22a2 false\n  >> cases sa \u03b5 \u03b5pos with Na hNa,\nNa : \u2115,\nhNa : \u2200 (n : \u2115), n \u2265 Na \u2192 abs (s n - a) < \u03b5\n\u22a2 false\n  >> cases sb \u03b5 \u03b5pos with Nb hNb,\nNb : \u2115,\nhNb : \u2200 (n : \u2115), n \u2265 Nb \u2192 abs (s n - b) < \u03b5\n\u22a2 false\n  >> let N := max Na Nb,\nN : \u2115 := max Na Nb\n\u22a2 false\n  >> have absa : abs (s N - a) < \u03b5,\n| \u22a2 abs (s N - a) < \u03b5\n|   >> { specialize hNa N,\n| hNa : N \u2265 Na \u2192 abs (s N - a) < \u03b5\n| \u22a2 abs (s N - a) < \u03b5\n|   >>   apply hNa,\n| \u22a2 N \u2265 Na\n|   >>   exact le_max_left Na Nb },\nabsa : abs (s N - a) < \u03b5\n\u22a2 false\n  >> have absb : abs (s N - b) < \u03b5,\n| \u22a2 abs (s N - b) < \u03b5\n|   >> { specialize hNb N,\n| hNb : N \u2265 Nb \u2192 abs (s N - b) < \u03b5\n| \u22a2 abs (s N - b) < \u03b5\n|   >>   apply hNb,\n| hNb : N \u2265 Nb \u2192 abs (s N - b) < \u03b5\n|   >>   exact le_max_right Na Nb },\nabsb : abs (s N - b) < \u03b5\n\u22a2 false\n  >> have : abs (a - b) < abs (a - b),\n  >>   calc abs (a - b)\n  >>        = abs ((a - s N) + (s N - b))   : by {congr, ring_nf}\n  >>    ... \u2264 abs (a - s N) + abs (s N - b) : by apply abs_add_le_abs_add_abs\n  >>    ... = abs (s N - a) + abs (s N - b) : by rw abs_sub\n  >>    ... < \u03b5 + \u03b5                         : by exact add_lt_add absa absb\n  >>    ... = abs (a - b)                   : by exact add_halves (abs (a - b)),\nthis : abs (a - b) < abs (a - b)\n\u22a2 false\n  >> exact lt_irrefl _ this,\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + abs_add_le_abs_add_abs a b : abs (a + b) \u2264 abs a + abs b\n-- + abs_pos_of_ne_zero : a \u2260 0 \u2192 0 < abs a\n-- + abs_sub a b : abs (a - b) = abs (b - a)\n-- + add_halves a : a / 2 + a / 2 = a\n-- + add_lt_add : a < b \u2192 c < d \u2192 a + c < b + d\n-- + le_max_left a b : a \u2264 max a b\n-- + le_max_right a b : b \u2264 max a b\n-- + sub_ne_zero_of_ne : a \u2260 b \u2192 a - b \u2260 0\n\n-- Comprobaci\u00f3n:\n-- variables (a b c d : \u211d)\n-- #check @abs_pos_of_ne_zero _ _ a\n-- #check @sub_ne_zero_of_ne _ _ a b\n-- #check @le_max_left _ _ a b\n-- #check @le_max_right _ _ a b\n-- #check @abs_add_le_abs_add_abs _ _ a b\n-- #check @abs_sub _ _ a b\n-- #check @add_lt_add _ _ a b c d\n-- #check @add_halves _ _ a\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Logica/Unicidad_del_limite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7058869557335196}}
{"text": "/-\nCopyright (c) 2021 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport linear_algebra.basic\n\n/-!\n# Rays in modules\n\nThis file defines rays in modules.\n\n## Main definitions\n\n* `same_ray`: two vectors belong to the same ray if they are proportional with a nonnegative\n  coefficient.\n\n* `module.ray` is a type for the equivalence class of nonzero vectors in a module with some\ncommon positive multiple.\n-/\n\nnoncomputable theory\n\nopen_locale big_operators\n\nsection ordered_comm_semiring\n\nvariables (R : Type*) [ordered_comm_semiring R]\nvariables {M : Type*} [add_comm_monoid M] [module R M]\nvariables {N : Type*} [add_comm_monoid N] [module R N]\nvariables (\u03b9 : Type*) [decidable_eq \u03b9]\n\n/-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them\nare equal (in the typical case over a field, this means one of them is a nonnegative multiple of\nthe other). -/\ndef same_ray (v\u2081 v\u2082 : M) : Prop :=\nv\u2081 = 0 \u2228 v\u2082 = 0 \u2228 \u2203 (r\u2081 r\u2082 : R), 0 < r\u2081 \u2227 0 < r\u2082 \u2227 r\u2081 \u2022 v\u2081 = r\u2082 \u2022 v\u2082\n\nvariables {R}\n\nnamespace same_ray\n\nvariables {x y z : M}\n\n@[simp] lemma zero_left (y : M) : same_ray R 0 y := or.inl rfl\n\n@[simp] lemma zero_right (x : M) : same_ray R x 0 := or.inr $ or.inl rfl\n\n@[nontriviality] lemma of_subsingleton [subsingleton M] (x y : M) : same_ray R x y :=\nby { rw [subsingleton.elim x 0], exact zero_left _ }\n\n@[nontriviality] lemma of_subsingleton' [subsingleton R] (x y : M) : same_ray R x y :=\nby { haveI := module.subsingleton R M, exact of_subsingleton x y }\n\n/-- `same_ray` is reflexive. -/\n@[refl] lemma refl (x : M) : same_ray R x x :=\nbegin\n  nontriviality R,\n  exact or.inr (or.inr $ \u27e81, 1, zero_lt_one, zero_lt_one, rfl\u27e9)\nend\n\nprotected lemma rfl : same_ray R x x := refl _\n\n/-- `same_ray` is symmetric. -/\n@[symm] lemma symm (h : same_ray R x y) : same_ray R y x :=\n(or.left_comm.1 h).imp_right $ or.imp_right $ \u03bb \u27e8r\u2081, r\u2082, h\u2081, h\u2082, h\u27e9, \u27e8r\u2082, r\u2081, h\u2082, h\u2081, h.symm\u27e9\n\n/-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r\u2081 r\u2082`\nsuch that `r\u2081 \u2022 x = r\u2082 \u2022 y`. -/\nlemma exists_pos (h : same_ray R x y) (hx : x \u2260 0) (hy : y \u2260 0) :\n  \u2203 r\u2081 r\u2082 : R, 0 < r\u2081 \u2227 0 < r\u2082 \u2227 r\u2081 \u2022 x = r\u2082 \u2022 y :=\n(h.resolve_left hx).resolve_left hy\n\nlemma _root_.same_ray_comm : same_ray R x y \u2194 same_ray R y x :=\n\u27e8same_ray.symm, same_ray.symm\u27e9\n\n/-- `same_ray` is transitive unless the vector in the middle is zero and both other vectors are\nnonzero. -/\nlemma trans (hxy : same_ray R x y) (hyz : same_ray R y z) (hy : y = 0 \u2192 x = 0 \u2228 z = 0) :\n  same_ray R x z :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hx, { exact zero_left z },\n  rcases eq_or_ne z 0 with rfl|hz, { exact zero_right x },\n  rcases eq_or_ne y 0 with rfl|hy, { exact (hy rfl).elim (\u03bb h, (hx h).elim) (\u03bb h, (hz h).elim) },\n  rcases hxy.exists_pos hx hy with \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u2081\u27e9,\n  rcases hyz.exists_pos hy hz with \u27e8r\u2083, r\u2084, hr\u2083, hr\u2084, h\u2082\u27e9,\n  refine or.inr (or.inr $ \u27e8r\u2083 * r\u2081, r\u2082 * r\u2084, mul_pos hr\u2083 hr\u2081, mul_pos hr\u2082 hr\u2084, _\u27e9),\n  rw [mul_smul, mul_smul, h\u2081, \u2190 h\u2082, smul_comm]\nend\n\n/-- A vector is in the same ray as a nonnegative multiple of itself. -/\nlemma _root_.same_ray_nonneg_smul_right (v : M) {r : R} (h : 0 \u2264 r) : same_ray R v (r \u2022 v) :=\nor.inr $ h.eq_or_lt.imp (\u03bb h, h \u25b8 zero_smul R v) $\n  \u03bb h, \u27e8r, 1, h, by { nontriviality R, exact zero_lt_one }, (one_smul _ _).symm\u27e9\n\n/-- A vector is in the same ray as a positive multiple of itself. -/\nlemma _root_.same_ray_pos_smul_right (v : M) {r : R} (h : 0 < r) : same_ray R v (r \u2022 v) :=\nsame_ray_nonneg_smul_right v h.le\n\n/-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/\nlemma nonneg_smul_right {r : R} (h : same_ray R x y) (hr : 0 \u2264 r) : same_ray R x (r \u2022 y) :=\nh.trans (same_ray_nonneg_smul_right y hr) $ \u03bb hy, or.inr $ by rw [hy, smul_zero]\n\n/-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/\nlemma pos_smul_right {r : R} (h : same_ray R x y) (hr : 0 < r) : same_ray R x (r \u2022 y) :=\nh.nonneg_smul_right hr.le\n\n/-- A nonnegative multiple of a vector is in the same ray as that vector. -/\nlemma _root_.same_ray_nonneg_smul_left (v : M) {r : R} (h : 0 \u2264 r) : same_ray R (r \u2022 v) v :=\n(same_ray_nonneg_smul_right v h).symm\n\n/-- A positive multiple of a vector is in the same ray as that vector. -/\nlemma _root_.same_ray_pos_smul_left (v : M) {r : R} (h : 0 < r) : same_ray R (r \u2022 v) v :=\nsame_ray_nonneg_smul_left v h.le\n\n/-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/\nlemma nonneg_smul_left {r : R} (h : same_ray R x y) (hr : 0 \u2264 r) : same_ray R (r \u2022 x) y :=\n(h.symm.nonneg_smul_right hr).symm\n\n/-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/\nlemma pos_smul_left {r : R} (h : same_ray R x y) (hr : 0 < r) : same_ray R (r \u2022 x) y :=\nh.nonneg_smul_left hr.le\n\n/-- If two vectors are on the same ray then they remain so after applying a linear map. -/\nlemma map (f : M \u2192\u2097[R] N) (h : same_ray R x y) : same_ray R (f x) (f y) :=\nh.imp (\u03bb hx, by rw [hx, map_zero]) $ or.imp (\u03bb hy, by rw [hy, map_zero]) $\n  \u03bb \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9, \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, by rw [\u2190f.map_smul, \u2190f.map_smul, h]\u27e9\n\n/-- The images of two vectors under a linear equivalence are on the same ray if and only if the\noriginal vectors are on the same ray. -/\n@[simp] lemma _root_.same_ray_map_iff (e : M \u2243\u2097[R] N) : same_ray R (e x) (e y) \u2194 same_ray R x y :=\n\u27e8\u03bb h, by simpa using same_ray.map e.symm.to_linear_map h, same_ray.map e.to_linear_map\u27e9\n\n/-- If two vectors are on the same ray then both scaled by the same action are also on the same\nray. -/\nlemma smul {S : Type*} [monoid S] [distrib_mul_action S M] [smul_comm_class R S M]\n  (h : same_ray R x y) (s : S) : same_ray R (s \u2022 x) (s \u2022 y) :=\nh.map (s \u2022 (linear_map.id : M \u2192\u2097[R] M))\n\n/-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/\nlemma add_left (hx : same_ray R x z) (hy : same_ray R y z) : same_ray R (x + y) z :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hx\u2080, { rwa zero_add },\n  rcases eq_or_ne y 0 with rfl|hy\u2080, { rwa add_zero },\n  rcases eq_or_ne z 0 with rfl|hz\u2080, { apply zero_right },\n  rcases hx.exists_pos hx\u2080 hz\u2080 with \u27e8rx, rz\u2081, hrx, hrz\u2081, Hx\u27e9,\n  rcases hy.exists_pos hy\u2080 hz\u2080 with \u27e8ry, rz\u2082, hry, hrz\u2082, Hy\u27e9,\n  refine or.inr (or.inr \u27e8rx * ry, ry * rz\u2081 + rx * rz\u2082, mul_pos hrx hry, _, _\u27e9),\n  { apply_rules [add_pos, mul_pos] },\n  { simp only [mul_smul, smul_add, add_smul, \u2190 Hx, \u2190 Hy],\n    rw smul_comm }\nend\n\n/-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/\nlemma add_right (hy : same_ray R x y) (hz : same_ray R x z) : same_ray R x (y + z) :=\n(hy.symm.add_left hz.symm).symm\n\nend same_ray\n\n/-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that\n`ray_vector.setoid` can be an instance. -/\n@[nolint unused_arguments has_inhabited_instance]\ndef ray_vector (R M : Type*) [has_zero M] := {v : M // v \u2260 0}\n\ninstance ray_vector.has_coe {R M : Type*} [has_zero M] :\n  has_coe (ray_vector R M) M := coe_subtype\n\ninstance {R M : Type*} [has_zero M] [nontrivial M] : nonempty (ray_vector R M) :=\nlet \u27e8x, hx\u27e9 := exists_ne (0 : M) in \u27e8\u27e8x, hx\u27e9\u27e9\n\nvariables (R M)\n\n/-- The setoid of the `same_ray` relation for the subtype of nonzero vectors. -/\ninstance : setoid (ray_vector R M) :=\n{ r := \u03bb x y, same_ray R (x : M) y,\n  iseqv := \u27e8\u03bb x, same_ray.refl _, \u03bb x y h, h.symm,\n    \u03bb x y z hxy hyz, hxy.trans hyz $ \u03bb hy, (y.2 hy).elim\u27e9 }\n\n/-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/\n@[nolint has_inhabited_instance]\ndef module.ray := quotient (ray_vector.setoid R M)\n\nvariables {R M}\n\n/-- Equivalence of nonzero vectors, in terms of same_ray. -/\nlemma equiv_iff_same_ray {v\u2081 v\u2082 : ray_vector R M} :\n  v\u2081 \u2248 v\u2082 \u2194 same_ray R (v\u2081 : M) v\u2082 :=\niff.rfl\n\nvariables (R)\n\n/-- The ray given by a nonzero vector. -/\nprotected def ray_of_ne_zero (v : M) (h : v \u2260 0) : module.ray R M := \u27e6\u27e8v, h\u27e9\u27e7\n\n/-- An induction principle for `module.ray`, used as `induction x using module.ray.ind`. -/\nlemma module.ray.ind {C : module.ray R M \u2192 Prop}\n  (h : \u2200 v (hv : v \u2260 0), C (ray_of_ne_zero R v hv)) (x : module.ray R M) : C x :=\nquotient.ind (subtype.rec $ by exact h) x\n\nvariable {R}\n\ninstance [nontrivial M] : nonempty (module.ray R M) :=\nnonempty.map quotient.mk infer_instance\n\n/-- The rays given by two nonzero vectors are equal if and only if those vectors\nsatisfy `same_ray`. -/\nlemma ray_eq_iff {v\u2081 v\u2082 : M} (hv\u2081 : v\u2081 \u2260 0) (hv\u2082 : v\u2082 \u2260 0) :\n  ray_of_ne_zero R _ hv\u2081 = ray_of_ne_zero R _ hv\u2082 \u2194 same_ray R v\u2081 v\u2082 :=\nquotient.eq\n\n/-- The ray given by a positive multiple of a nonzero vector. -/\n@[simp] lemma ray_pos_smul {v : M} (h : v \u2260 0) {r : R} (hr : 0 < r)\n  (hrv : r \u2022 v \u2260 0) : ray_of_ne_zero R (r \u2022 v) hrv = ray_of_ne_zero R v h :=\n(ray_eq_iff _ _).2 $ same_ray_pos_smul_left v hr\n\n/-- An equivalence between modules implies an equivalence between ray vectors. -/\ndef ray_vector.map_linear_equiv (e : M \u2243\u2097[R] N) : ray_vector R M \u2243 ray_vector R N :=\nequiv.subtype_equiv e.to_equiv $ \u03bb _, e.map_ne_zero_iff.symm\n\n/-- An equivalence between modules implies an equivalence between rays. -/\ndef module.ray.map (e : M \u2243\u2097[R] N) : module.ray R M \u2243 module.ray R N :=\nquotient.congr (ray_vector.map_linear_equiv e) $ \u03bb \u27e8a, ha\u27e9 \u27e8b, hb\u27e9, (same_ray_map_iff _).symm\n\n@[simp] lemma module.ray.map_apply (e : M \u2243\u2097[R] N) (v : M) (hv : v \u2260 0) :\n  module.ray.map e (ray_of_ne_zero _ v hv) = ray_of_ne_zero _ (e v) (e.map_ne_zero_iff.2 hv) := rfl\n\n@[simp] lemma module.ray.map_refl : (module.ray.map $ linear_equiv.refl R M) = equiv.refl _ :=\nequiv.ext $ module.ray.ind R $ \u03bb _ _, rfl\n\n@[simp] lemma module.ray.map_symm (e : M \u2243\u2097[R] N) :\n  (module.ray.map e).symm = module.ray.map e.symm := rfl\n\nsection action\nvariables {G : Type*} [group G] [distrib_mul_action G M]\n\n/-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest\nwhen `G = R\u02e3` -/\ninstance {R : Type*} : mul_action G (ray_vector R M) :=\n{ smul := \u03bb r, (subtype.map ((\u2022) r) $ \u03bb a, (smul_ne_zero_iff_ne _).2),\n  mul_smul := \u03bb a b m, subtype.ext $ mul_smul a b _,\n  one_smul := \u03bb m, subtype.ext $ one_smul _ _ }\n\nvariables [smul_comm_class R G M]\n\n/-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when\n`G = R\u02e3` -/\ninstance : mul_action G (module.ray R M) :=\n{ smul := \u03bb r, quotient.map ((\u2022) r) (\u03bb a b h, h.smul _),\n  mul_smul := \u03bb a b, quotient.ind $ by exact(\u03bb m, congr_arg quotient.mk $ mul_smul a b _),\n  one_smul := quotient.ind $ by exact (\u03bb m, congr_arg quotient.mk $ one_smul _ _), }\n\n/-- The action via `linear_equiv.apply_distrib_mul_action` corresponds to `module.ray.map`. -/\n@[simp] lemma module.ray.linear_equiv_smul_eq_map (e : M \u2243\u2097[R] M) (v : module.ray R M) :\n  e \u2022 v = module.ray.map e v := rfl\n\n@[simp] lemma smul_ray_of_ne_zero (g : G) (v : M) (hv) :\n  g \u2022 ray_of_ne_zero R v hv = ray_of_ne_zero R (g \u2022 v) ((smul_ne_zero_iff_ne _).2 hv) := rfl\n\nend action\n\nnamespace module.ray\n\n/-- Scaling by a positive unit is a no-op. -/\nlemma units_smul_of_pos (u : R\u02e3) (hu : 0 < (u : R)) (v : module.ray R M) :\n  u \u2022 v = v :=\nbegin\n  induction v using module.ray.ind,\n  rw [smul_ray_of_ne_zero, ray_eq_iff],\n  exact same_ray_pos_smul_left _ hu\nend\n\n/-- An arbitrary `ray_vector` giving a ray. -/\ndef some_ray_vector (x : module.ray R M) : ray_vector R M := quotient.out x\n\n/-- The ray of `some_ray_vector`. -/\n@[simp] lemma some_ray_vector_ray (x : module.ray R M) :\n  (\u27e6x.some_ray_vector\u27e7 : module.ray R M) = x :=\nquotient.out_eq _\n\n/-- An arbitrary nonzero vector giving a ray. -/\ndef some_vector (x : module.ray R M) : M := x.some_ray_vector\n\n/-- `some_vector` is nonzero. -/\n@[simp] lemma some_vector_ne_zero (x : module.ray R M) : x.some_vector \u2260 0 :=\nx.some_ray_vector.property\n\n/-- The ray of `some_vector`. -/\n@[simp] lemma some_vector_ray (x : module.ray R M) :\n  ray_of_ne_zero R _ x.some_vector_ne_zero = x :=\n(congr_arg _ (subtype.coe_eta _ _) : _).trans x.out_eq\n\nend module.ray\n\nend ordered_comm_semiring\n\nsection ordered_comm_ring\n\nvariables {R : Type*} [ordered_comm_ring R]\nvariables {M N : Type*} [add_comm_group M] [add_comm_group N] [module R M] [module R N] {x y : M}\n\n/-- `same_ray.neg` as an `iff`. -/\n@[simp] lemma same_ray_neg_iff : same_ray R (-x) (-y) \u2194 same_ray R x y :=\nby simp only [same_ray, neg_eq_zero, smul_neg, neg_inj]\n\nalias same_ray_neg_iff \u2194 same_ray.of_neg same_ray.neg\n\nlemma same_ray_neg_swap : same_ray R (-x) y \u2194 same_ray R x (-y) :=\nby rw [\u2190 same_ray_neg_iff, neg_neg]\n\nlemma eq_zero_of_same_ray_neg_smul_right [no_zero_smul_divisors R M] {r : R} (hr : r < 0)\n  (h : same_ray R x (r \u2022 x)) :\n  x = 0 :=\nbegin\n  rcases h with rfl|h\u2080|\u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9,\n  { refl },\n  { simpa [hr.ne] using h\u2080 },\n  { rw [\u2190 sub_eq_zero, smul_smul, \u2190 sub_smul, smul_eq_zero] at h,\n    refine h.resolve_left (ne_of_gt $ sub_pos.2 _),\n    exact (mul_neg_of_pos_of_neg hr\u2082 hr).trans hr\u2081 }\nend\n\n/-- If a vector is in the same ray as its negation, that vector is zero. -/\nlemma eq_zero_of_same_ray_self_neg [no_zero_smul_divisors R M] (h : same_ray R x (-x)) :\n  x = 0 :=\nbegin\n  nontriviality M, haveI : nontrivial R := module.nontrivial R M,\n  refine eq_zero_of_same_ray_neg_smul_right (neg_lt_zero.2 (@one_pos R _ _)) _,\n  rwa [neg_one_smul]\nend\n\nnamespace ray_vector\n\n/-- Negating a nonzero vector. -/\ninstance {R : Type*} : has_neg (ray_vector R M) := \u27e8\u03bb v, \u27e8-v, neg_ne_zero.2 v.prop\u27e9\u27e9\n\n/-- Negating a nonzero vector commutes with coercion to the underlying module. -/\n@[simp, norm_cast] lemma coe_neg {R : Type*} (v : ray_vector R M) : \u2191(-v) = -(v : M) := rfl\n\n/-- Negating a nonzero vector twice produces the original vector. -/\ninstance {R : Type*} : has_involutive_neg (ray_vector R M) :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb v, by rw [subtype.ext_iff, coe_neg, coe_neg, neg_neg] }\n\n/-- If two nonzero vectors are equivalent, so are their negations. -/\n@[simp] lemma equiv_neg_iff {v\u2081 v\u2082 : ray_vector R M} : -v\u2081 \u2248 -v\u2082 \u2194 v\u2081 \u2248 v\u2082 :=\nsame_ray_neg_iff\n\nend ray_vector\n\nvariables (R)\n\n/-- Negating a ray. -/\ninstance : has_neg (module.ray R M) :=\n\u27e8quotient.map (\u03bb v, -v) (\u03bb v\u2081 v\u2082, ray_vector.equiv_neg_iff.2)\u27e9\n\n/-- The ray given by the negation of a nonzero vector. -/\n@[simp] lemma neg_ray_of_ne_zero (v : M) (h : v \u2260 0) :\n  -(ray_of_ne_zero R _ h) = ray_of_ne_zero R (-v) (neg_ne_zero.2 h) :=\nrfl\n\nnamespace module.ray\n\nvariables {R}\n\n/-- Negating a ray twice produces the original ray. -/\ninstance : has_involutive_neg (module.ray R M) :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb x, quotient.ind (\u03bb a, congr_arg quotient.mk $ neg_neg _) x }\n\nvariables {R M}\n\n/-- A ray does not equal its own negation. -/\nlemma ne_neg_self [no_zero_smul_divisors R M] (x : module.ray R M) : x \u2260 -x :=\nbegin\n  induction x using module.ray.ind with x hx,\n  rw [neg_ray_of_ne_zero, ne.def, ray_eq_iff],\n  exact mt eq_zero_of_same_ray_self_neg hx\nend\n\nlemma neg_units_smul (u : R\u02e3) (v : module.ray R M) : (-u) \u2022 v = - (u \u2022 v) :=\nbegin\n  induction v using module.ray.ind,\n  simp only [smul_ray_of_ne_zero, units.smul_def, units.coe_neg, neg_smul, neg_ray_of_ne_zero]\nend\n\n/-- Scaling by a negative unit is negation. -/\nlemma units_smul_of_neg (u : R\u02e3) (hu : (u : R) < 0) (v : module.ray R M) :\n  u \u2022 v = -v :=\nbegin\n  rw [\u2190 neg_inj, neg_neg, \u2190 neg_units_smul, units_smul_of_pos],\n  rwa [units.coe_neg, right.neg_pos_iff]\nend\n\nend module.ray\n\nend ordered_comm_ring\n\nsection linear_ordered_comm_ring\n\nvariables {R : Type*} [linear_ordered_comm_ring R]\nvariables {M : Type*} [add_comm_group M] [module R M]\n\n/-- `same_ray` follows from membership of `mul_action.orbit` for the `units.pos_subgroup`. -/\nlemma same_ray_of_mem_orbit {v\u2081 v\u2082 : M} (h : v\u2081 \u2208 mul_action.orbit (units.pos_subgroup R) v\u2082) :\n  same_ray R v\u2081 v\u2082 :=\nbegin\n  rcases h with \u27e8\u27e8r, hr : 0 < (r : R)\u27e9, (rfl : r \u2022 v\u2082 = v\u2081)\u27e9,\n  exact same_ray_pos_smul_left _ hr\nend\n\n/-- Scaling by an inverse unit is the same as scaling by itself. -/\n@[simp] lemma units_inv_smul (u : R\u02e3) (v : module.ray R M) :\n  u\u207b\u00b9 \u2022 v = u \u2022 v :=\ncalc u\u207b\u00b9 \u2022 v = (u * u) \u2022 u\u207b\u00b9 \u2022 v :\n  eq.symm $ (u\u207b\u00b9 \u2022 v).units_smul_of_pos _ $ mul_self_pos.2 u.ne_zero\n... = u \u2022 v : by rw [mul_smul, smul_inv_smul]\n\nsection\nvariables [no_zero_smul_divisors R M]\n\n@[simp] lemma same_ray_smul_right_iff {v : M} {r : R} :\n  same_ray R v (r \u2022 v) \u2194 0 \u2264 r \u2228 v = 0 :=\n\u27e8\u03bb hrv, or_iff_not_imp_left.2 $ \u03bb hr, eq_zero_of_same_ray_neg_smul_right (not_le.1 hr) hrv,\n  or_imp_distrib.2 \u27e8same_ray_nonneg_smul_right v, \u03bb h, h.symm \u25b8 same_ray.zero_left _\u27e9\u27e9\n\n/-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple\nis positive. -/\nlemma same_ray_smul_right_iff_of_ne {v : M} (hv : v \u2260 0) {r : R} (hr : r \u2260 0) :\n  same_ray R v (r \u2022 v) \u2194 0 < r :=\nby simp only [same_ray_smul_right_iff, hv, or_false, hr.symm.le_iff_lt]\n\n@[simp] lemma same_ray_smul_left_iff {v : M} {r : R} : same_ray R (r \u2022 v) v \u2194 0 \u2264 r \u2228 v = 0 :=\nsame_ray_comm.trans same_ray_smul_right_iff\n\n/-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple\nis positive. -/\nlemma same_ray_smul_left_iff_of_ne {v : M} (hv : v \u2260 0) {r : R} (hr : r \u2260 0) :\n  same_ray R (r \u2022 v) v \u2194 0 < r :=\nsame_ray_comm.trans (same_ray_smul_right_iff_of_ne hv hr)\n\n@[simp] lemma same_ray_neg_smul_right_iff {v : M} {r : R} :\n  same_ray R (-v) (r \u2022 v) \u2194 r \u2264 0 \u2228 v = 0 :=\nby rw [\u2190 same_ray_neg_iff, neg_neg, \u2190 neg_smul, same_ray_smul_right_iff, neg_nonneg]\n\nlemma same_ray_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v \u2260 0) (hr : r \u2260 0) :\n  same_ray R (-v) (r \u2022 v) \u2194 r < 0 :=\nby simp only [same_ray_neg_smul_right_iff, hv, or_false, hr.le_iff_lt]\n\n@[simp] lemma same_ray_neg_smul_left_iff {v : M} {r : R} :\n  same_ray R (r \u2022 v) (-v) \u2194 r \u2264 0 \u2228 v = 0 :=\nsame_ray_comm.trans same_ray_neg_smul_right_iff\n\nlemma same_ray_neg_smul_left_iff_of_ne {v : M} {r : R} (hv : v \u2260 0) (hr : r \u2260 0) :\n  same_ray R (r \u2022 v) (-v) \u2194 r < 0 :=\nsame_ray_comm.trans $ same_ray_neg_smul_right_iff_of_ne hv hr\n\n@[simp] lemma units_smul_eq_self_iff {u : R\u02e3} {v : module.ray R M} :\n  u \u2022 v = v \u2194 (0 : R) < u :=\nbegin\n  induction v using module.ray.ind with v hv,\n  simp only [smul_ray_of_ne_zero, ray_eq_iff, units.smul_def,\n    same_ray_smul_left_iff_of_ne hv u.ne_zero]\nend\n\n@[simp] lemma units_smul_eq_neg_iff {u : R\u02e3} {v : module.ray R M} :\n  u \u2022 v = -v \u2194 \u2191u < (0 : R) :=\nby rw [\u2190 neg_inj, neg_neg, \u2190 module.ray.neg_units_smul, units_smul_eq_self_iff, units.coe_neg,\n  neg_pos]\n\nend\n\nend linear_ordered_comm_ring\n\nnamespace same_ray\n\nvariables {R : Type*} [linear_ordered_field R]\nvariables {M : Type*} [add_comm_group M] [module R M] {x y v\u2081 v\u2082 : M}\n\nlemma exists_pos_left (h : same_ray R x y) (hx : x \u2260 0) (hy : y \u2260 0) :\n  \u2203 r : R, 0 < r \u2227 r \u2022 x = y :=\nlet \u27e8r\u2081, r\u2082, hr\u2081, hr\u2082, h\u27e9 := h.exists_pos hx hy in\n  \u27e8r\u2082\u207b\u00b9 * r\u2081, mul_pos (inv_pos.2 hr\u2082) hr\u2081, by rw [mul_smul, h, inv_smul_smul\u2080 hr\u2082.ne']\u27e9\n\nlemma exists_pos_right (h : same_ray R x y) (hx : x \u2260 0) (hy : y \u2260 0) :\n  \u2203 r : R, 0 < r \u2227 x = r \u2022 y :=\n(h.symm.exists_pos_left hy hx).imp $ \u03bb _, and.imp_right eq.symm\n\n/-- If a vector `v\u2082` is on the same ray as a nonzero vector `v\u2081`, then it is equal to `c \u2022 v\u2081` for\nsome nonnegative `c`. -/\nlemma exists_nonneg_left (h : same_ray R x y) (hx : x \u2260 0) : \u2203 r : R, 0 \u2264 r \u2227 r \u2022 x = y :=\nbegin\n  obtain rfl | hy := eq_or_ne y 0,\n  { exact \u27e80, le_rfl, zero_smul _ _\u27e9 },\n  { exact (h.exists_pos_left hx hy).imp (\u03bb _, and.imp_left le_of_lt) }\nend\n\n/-- If a vector `v\u2081` is on the same ray as a nonzero vector `v\u2082`, then it is equal to `c \u2022 v\u2082` for\nsome nonnegative `c`. -/\nlemma exists_nonneg_right (h : same_ray R x y) (hy : y \u2260 0) : \u2203 r : R, 0 \u2264 r \u2227 x = r \u2022 y :=\n(h.symm.exists_nonneg_left hy).imp $ \u03bb _, and.imp_right eq.symm\n\n/-- If vectors `v\u2081` and `v\u2082` are on the same ray, then for some nonnegative `a b`, `a + b = 1`, we\nhave `v\u2081 = a \u2022 (v\u2081 + v\u2082)` and `v\u2082 = b \u2022 (v\u2081 + v\u2082)`. -/\nlemma exists_eq_smul_add (h : same_ray R v\u2081 v\u2082) :\n  \u2203 a b : R, 0 \u2264 a \u2227 0 \u2264 b \u2227 a + b = 1 \u2227 v\u2081 = a \u2022 (v\u2081 + v\u2082) \u2227 v\u2082 = b \u2022 (v\u2081 + v\u2082) :=\nbegin\n  rcases h with rfl|rfl|\u27e8r\u2081, r\u2082, h\u2081, h\u2082, H\u27e9,\n  { use [0, 1], simp },\n  { use [1, 0], simp },\n  { have h\u2081\u2082 : 0 < r\u2081 + r\u2082, from add_pos h\u2081 h\u2082,\n    refine \u27e8r\u2082 / (r\u2081 + r\u2082), r\u2081 / (r\u2081 + r\u2082), div_nonneg h\u2082.le h\u2081\u2082.le, div_nonneg h\u2081.le h\u2081\u2082.le,\n      _, _, _\u27e9,\n    { rw [\u2190 add_div, add_comm, div_self h\u2081\u2082.ne'] },\n    { rw [div_eq_inv_mul, mul_smul, smul_add, \u2190 H, \u2190 add_smul, add_comm r\u2082,\n        inv_smul_smul\u2080 h\u2081\u2082.ne'] },\n    { rw [div_eq_inv_mul, mul_smul, smul_add, H, \u2190 add_smul, add_comm r\u2082,\n        inv_smul_smul\u2080 h\u2081\u2082.ne'] } }\nend\n\n/-- If vectors `v\u2081` and `v\u2082` are on the same ray, then they are nonnegative multiples of the same\nvector. Actually, this vector can be assumed to be `v\u2081 + v\u2082`, see `same_ray.exists_eq_smul_add`. -/\nlemma exists_eq_smul (h : same_ray R v\u2081 v\u2082) :\n  \u2203 (u : M) (a b : R), 0 \u2264 a \u2227 0 \u2264 b \u2227 a + b = 1 \u2227 v\u2081 = a \u2022 u \u2227 v\u2082 = b \u2022 u :=\n\u27e8v\u2081 + v\u2082, h.exists_eq_smul_add\u27e9\n\nend same_ray\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/ray.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7058869538235377}}
{"text": "def mul : \u2115\u2192\u2115\u2192\u2115 := \u03bb x y, x*y\n\n--- Dependent Types\nnamespace hidden\n\nuniverse u\n\nconstant list   : Type u \u2192 Type u\n\nconstant cons   : \u03a0 \u03b1 : Type u, \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\nconstant nil    : \u03a0 \u03b1 : Type u, list \u03b1\nconstant head   : \u03a0 \u03b1 : Type u, list \u03b1 \u2192 \u03b1\nconstant tail   : \u03a0 \u03b1 : Type u, list \u03b1 \u2192 list \u03b1\nconstant append : \u03a0 \u03b1 : Type u, list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n\nend hidden\n\n\n--------------------\n--------------------\n--------------------\n-- Ex 1\n\ndef Do_Twice : ((\u2115\u2192\u2115)\u2192 (\u2115\u2192\u2115)) \u2192 (\u2115\u2192\u2115) \u2192 \u2115 \u2192 \u2115 := \u03bb F f, F (F f)\ndef do_twice : (\u2115\u2192\u2115) \u2192 \u2115 \u2192 \u2115 := \u03bb f x, f (f x)\n\n#reduce Do_Twice do_twice (mul 2)\n\n-- Ex 2\n\ndef curry (\u03b1 \u03b2 \u03b3 : Type) (f : \u03b1 \u00d7 \u03b2 \u2192 \u03b3) : \u03b1 \u2192 \u03b2 \u2192 \u03b3 := \u03bb a b, f(a,b)\n\ndef uncurry (\u03b1 \u03b2 \u03b3 : Type) (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) : \u03b1 \u00d7 \u03b2 \u2192 \u03b3 := \u03bb x, f x.1 x.2\n\ndef curry_mul := uncurry \u2115 \u2115 \u2115 mul\n#reduce curry_mul (2,3)\ndef mul' := curry \u2115 \u2115 \u2115 curry_mul\n\nlemma lem : \u2200 a b : \u2115, mul a b = mul' a b :=\nbegin\n    intros a b,\n    refl,\nend\n\n-- Ex 3\n\nuniverse u\nconstant vec : Type u \u2192 \u2115 \u2192 Type u\n\nnamespace vec\n  constant empty : \u03a0 \u03b1 : Type u, vec \u03b1 0\n  constant cons :\n    \u03a0 (\u03b1 : Type u) (n : \u2115), \u03b1 \u2192 vec \u03b1 n \u2192 vec \u03b1 (n + 1)\n  constant append :\n    \u03a0 (\u03b1 : Type u) (n m : \u2115),  vec \u03b1 m \u2192 vec \u03b1 n \u2192 vec \u03b1 (n + m)\n  constant vec_add : \u03a0 {\u03b1 : Type u} {n : \u2115}, vec \u03b1 n \u2192 vec \u03b1 n \u2192 vec \u03b1 n\n  constant vec_reverse : \u03a0 {\u03b1 : Type u} {n : \u2115}, vec \u03b1 n \u2192 vec \u03b1 n\nend vec\n\nconstant \u03b1 : Type\nconstant a : \u03b1\nconstants m n r : \u2115\nconstants v w : vec \u03b1 n\n\n#check vec.vec_add v w \n#check vec.vec_reverse v \n\n-- Ex 4\nconstant matrix : Type u \u2192 \u2115 \u2192 \u2115 \u2192 Type u \n\nnamespace matrix\n  constant mat_mult : \u03a0 {\u03b1 : Type u} {m n r : \u2115}, matrix \u03b1 m n \u2192 matrix \u03b1 n r \u2192 matrix \u03b1 m r\n  constant mat_add : \u03a0 {\u03b1 : Type u} {m n :\u2115}, matrix \u03b1 m n \u2192 matrix \u03b1 m n \u2192 matrix \u03b1 m n\nend matrix\n\n/-\n    The question says to define matrices and then multiplication of vec and a \n    matrix. But a vec is just a (let's say column) matrix...\n-/\n\ndef vec' := \u03bb \u03b2 x, matrix \u03b2 1 x \n#check vec'\n#check vec\n\n", "meta": {"author": "NicoCourts", "repo": "learning-lean", "sha": "02aba16b52adf541f8ebce5da38309ef2b7fcdfb", "save_path": "github-repos/lean/NicoCourts-learning-lean", "path": "github-repos/lean/NicoCourts-learning-lean/learning-lean-02aba16b52adf541f8ebce5da38309ef2b7fcdfb/src/doc_examples/section2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7058869451931497}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module algebra.category.Module.biproducts\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Group.Pi\nimport Mathbin.CategoryTheory.Limits.Shapes.Biproducts\nimport Mathbin.Algebra.Category.Module.Limits\nimport Mathbin.Algebra.Category.Module.Abelian\nimport Mathbin.Algebra.Homology.ShortExact.Abelian\n\n/-!\n# The category of `R`-modules has finite biproducts\n-/\n\n\nopen CategoryTheory\n\nopen CategoryTheory.Limits\n\nopen BigOperators\n\nuniverse w v u\n\nnamespace ModuleCat\n\nvariable {R : Type u} [Ring R]\n\n-- As `Module R` is preadditive, and has all limits, it automatically has biproducts.\ninstance : HasBinaryBiproducts (ModuleCat.{v} R) :=\n  HasBinaryBiproducts.of_hasBinaryProducts\n\ninstance : HasFiniteBiproducts (ModuleCat.{v} R) :=\n  HasFiniteBiproducts.of_hasFiniteProducts\n\n-- We now construct explicit limit data,\n-- so we can compare the biproducts to the usual unbundled constructions.\n/-- Construct limit data for a binary product in `Module R`, using `Module.of R (M \u00d7 N)`.\n-/\n@[simps cone_x isLimit_lift]\ndef binaryProductLimitCone (M N : ModuleCat.{v} R) : Limits.LimitCone (pair M N)\n    where\n  Cone :=\n    { pt := ModuleCat.of R (M \u00d7 N)\n      \u03c0 :=\n        { app := fun j =>\n            Discrete.casesOn j fun j =>\n              WalkingPair.casesOn j (LinearMap.fst R M N) (LinearMap.snd R M N)\n          naturality' := by rintro \u27e8\u27e8\u27e9\u27e9 \u27e8\u27e8\u27e9\u27e9 \u27e8\u27e8\u27e8\u27e9\u27e9\u27e9 <;> rfl } }\n  IsLimit :=\n    { lift := fun s => LinearMap.prod (s.\u03c0.app \u27e8WalkingPair.left\u27e9) (s.\u03c0.app \u27e8WalkingPair.right\u27e9)\n      fac := by\n        rintro s (\u27e8\u27e9 | \u27e8\u27e9) <;>\n          \u00b7 ext x\n            simp only [binary_fan.\u03c0_app_right, binary_fan.\u03c0_app_left, ModuleCat.coe_comp,\n              Function.comp_apply, LinearMap.fst_apply, LinearMap.snd_apply, LinearMap.prod_apply,\n              Pi.prod]\n      uniq := fun s m w => by\n        ext <;> [rw [\u2190 w \u27e8walking_pair.left\u27e9], rw [\u2190 w \u27e8walking_pair.right\u27e9]] <;> rfl }\n#align Module.binary_product_limit_cone ModuleCat.binaryProductLimitCone\n\n@[simp]\ntheorem binaryProductLimitCone_cone_\u03c0_app_left (M N : ModuleCat.{v} R) :\n    (binaryProductLimitCone M N).Cone.\u03c0.app \u27e8WalkingPair.left\u27e9 = LinearMap.fst R M N :=\n  rfl\n#align Module.binary_product_limit_cone_cone_\u03c0_app_left ModuleCat.binaryProductLimitCone_cone_\u03c0_app_left\n\n@[simp]\ntheorem binaryProductLimitCone_cone_\u03c0_app_right (M N : ModuleCat.{v} R) :\n    (binaryProductLimitCone M N).Cone.\u03c0.app \u27e8WalkingPair.right\u27e9 = LinearMap.snd R M N :=\n  rfl\n#align Module.binary_product_limit_cone_cone_\u03c0_app_right ModuleCat.binaryProductLimitCone_cone_\u03c0_app_right\n\n/-- We verify that the biproduct in `Module R` is isomorphic to\nthe cartesian product of the underlying types:\n-/\n@[simps hom_apply]\nnoncomputable def biprodIsoProd (M N : ModuleCat.{v} R) :\n    (M \u229e N : ModuleCat.{v} R) \u2245 ModuleCat.of R (M \u00d7 N) :=\n  IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit M N) (binaryProductLimitCone M N).IsLimit\n#align Module.biprod_iso_prod ModuleCat.biprodIsoProd\n\n@[simp, elementwise]\ntheorem biprodIsoProd_inv_comp_fst (M N : ModuleCat.{v} R) :\n    (biprodIsoProd M N).inv \u226b biprod.fst = LinearMap.fst R M N :=\n  IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.left)\n#align Module.biprod_iso_prod_inv_comp_fst ModuleCat.biprodIsoProd_inv_comp_fst\n\n@[simp, elementwise]\ntheorem biprodIsoProd_inv_comp_snd (M N : ModuleCat.{v} R) :\n    (biprodIsoProd M N).inv \u226b biprod.snd = LinearMap.snd R M N :=\n  IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.right)\n#align Module.biprod_iso_prod_inv_comp_snd ModuleCat.biprodIsoProd_inv_comp_snd\n\nnamespace HasLimit\n\nvariable {J : Type w} (f : J \u2192 ModuleCat.{max w v} R)\n\n/-- The map from an arbitrary cone over a indexed family of abelian groups\nto the cartesian product of those groups.\n-/\n@[simps]\ndef lift (s : Fan f) : s.pt \u27f6 ModuleCat.of R (\u2200 j, f j)\n    where\n  toFun x j := s.\u03c0.app \u27e8j\u27e9 x\n  map_add' x y := by\n    ext\n    simp\n  map_smul' r x := by\n    ext\n    simp\n#align Module.has_limit.lift ModuleCat.HasLimit.lift\n\n/-- Construct limit data for a product in `Module R`, using `Module.of R (\u03a0 j, F.obj j)`.\n-/\n@[simps]\ndef productLimitCone : Limits.LimitCone (Discrete.functor f)\n    where\n  Cone :=\n    { pt := ModuleCat.of R (\u2200 j, f j)\n      \u03c0 := Discrete.natTrans fun j => (LinearMap.proj j.as : (\u2200 j, f j) \u2192\u2097[R] f j.as) }\n  IsLimit :=\n    { lift := lift f\n      fac := fun s j => by\n        cases j\n        ext\n        simp\n      uniq := fun s m w => by\n        ext (x j)\n        dsimp only [has_limit.lift]\n        simp only [LinearMap.coe_mk]\n        exact congr_arg (fun g : s.X \u27f6 f j => (g : s.X \u2192 f j) x) (w \u27e8j\u27e9) }\n#align Module.has_limit.product_limit_cone ModuleCat.HasLimit.productLimitCone\n\nend HasLimit\n\nopen HasLimit\n\nvariable {J : Type} (f : J \u2192 ModuleCat.{v} R)\n\n/-- We verify that the biproduct we've just defined is isomorphic to the `Module R` structure\non the dependent function type\n-/\n@[simps hom_apply]\nnoncomputable def biproductIsoPi [Fintype J] (f : J \u2192 ModuleCat.{v} R) :\n    (\u2a01 f : ModuleCat.{v} R) \u2245 ModuleCat.of R (\u2200 j, f j) :=\n  IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (productLimitCone f).IsLimit\n#align Module.biproduct_iso_pi ModuleCat.biproductIsoPi\n\n@[simp, elementwise]\ntheorem biproductIsoPi_inv_comp_\u03c0 [Fintype J] (f : J \u2192 ModuleCat.{v} R) (j : J) :\n    (biproductIsoPi f).inv \u226b biproduct.\u03c0 f j = (LinearMap.proj j : (\u2200 j, f j) \u2192\u2097[R] f j) :=\n  IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk j)\n#align Module.biproduct_iso_pi_inv_comp_\u03c0 ModuleCat.biproductIsoPi_inv_comp_\u03c0\n\nend ModuleCat\n\nsection SplitExact\n\nvariable {R : Type u} {A M B : Type v} [Ring R] [AddCommGroup A] [Module R A] [AddCommGroup B]\n  [Module R B] [AddCommGroup M] [Module R M]\n\nvariable {j : A \u2192\u2097[R] M} {g : M \u2192\u2097[R] B}\n\nopen ModuleCat\n\n/-- The isomorphism `A \u00d7 B \u2243\u2097[R] M` coming from a right split exact sequence `0 \u27f6 A \u27f6 M \u27f6 B \u27f6 0`\nof modules.-/\nnoncomputable def lequivProdOfRightSplitExact {f : B \u2192\u2097[R] M} (hj : Function.Injective j)\n    (exac : j.range = g.ker) (h : g.comp f = LinearMap.id) : (A \u00d7 B) \u2243\u2097[R] M :=\n  (({             RightSplit := \u27e8asHom f, h\u27e9\n                  mono := (ModuleCat.mono_iff_injective <| asHom j).mpr hj\n                  exact := (exact_iff _ _).mpr exac } : RightSplit _ _).Splitting.Iso.trans <|\n        biprodIsoProd _ _).toLinearEquiv.symm\n#align lequiv_prod_of_right_split_exact lequivProdOfRightSplitExact\n\n/-- The isomorphism `A \u00d7 B \u2243\u2097[R] M` coming from a left split exact sequence `0 \u27f6 A \u27f6 M \u27f6 B \u27f6 0`\nof modules.-/\nnoncomputable def lequivProdOfLeftSplitExact {f : M \u2192\u2097[R] A} (hg : Function.Surjective g)\n    (exac : j.range = g.ker) (h : f.comp j = LinearMap.id) : (A \u00d7 B) \u2243\u2097[R] M :=\n  (({             LeftSplit := \u27e8asHom f, h\u27e9\n                  Epi := (ModuleCat.epi_iff_surjective <| asHom g).mpr hg\n                  exact := (exact_iff _ _).mpr exac } : LeftSplit _ _).Splitting.Iso.trans <|\n        biprodIsoProd _ _).toLinearEquiv.symm\n#align lequiv_prod_of_left_split_exact lequivProdOfLeftSplitExact\n\nend SplitExact\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Category/Module/Biproducts.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7058869432654329}}
{"text": "/-\nCopyright (c) 2023 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module data.set.list\n! leanprover-community/mathlib commit 2ec920d35348cb2d13ac0e1a2ad9df0fdf1a76b4\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Image\nimport Mathlib.Data.List.Basic\nimport Mathlib.Data.Fin.Basic\n\n/-!\n# Lemmas about `List`s and `Set.range`\n\nIn this file we prove lemmas about range of some operations on lists.\n-/\n\n\nopen List\n\nvariable {\u03b1 \u03b2 : Type _} (l : List \u03b1)\n\nnamespace Set\n\ntheorem range_list_map (f : \u03b1 \u2192 \u03b2) : range (map f) = { l | \u2200 x \u2208 l, x \u2208 range f } := by\n  refine'\n    antisymm (range_subset_iff.2 fun l => forall_mem_map_iff.2 fun y _ => mem_range_self _)\n      fun l hl => _\n  induction' l with a l ihl; \u00b7 exact \u27e8[], rfl\u27e9\n  rcases ihl fun x hx => hl x <| subset_cons _ _ hx with \u27e8l, rfl\u27e9\n  rcases hl a (mem_cons_self _ _) with \u27e8a, rfl\u27e9\n  exact \u27e8a :: l, map_cons _ _ _\u27e9\n#align set.range_list_map Set.range_list_map\n\ntheorem range_list_map_coe (s : Set \u03b1) : range (map ((\u2191) : s \u2192 \u03b1)) = { l | \u2200 x \u2208 l, x \u2208 s } := by\n  rw [range_list_map, Subtype.range_coe]\n#align set.range_list_map_coe Set.range_list_map_coe\n\n@[simp]\ntheorem range_list_nthLe : (range fun k : Fin l.length => l.nthLe k k.2) = { x | x \u2208 l } := by\n  ext x\n  rw [mem_setOf_eq, mem_iff_get]\n  exact \u27e8fun \u27e8\u27e8n, h\u2081\u27e9, h\u2082\u27e9 => \u27e8\u27e8n, h\u2081\u27e9, h\u2082\u27e9, fun \u27e8\u27e8n, h\u2081\u27e9, h\u2082\u27e9 => \u27e8\u27e8n, h\u2081\u27e9, h\u2082\u27e9\u27e9\n#align set.range_list_nth_le Set.range_list_nthLe\n\ntheorem range_list_get? : range l.get? = insert none (some '' { x | x \u2208 l }) := by\n  rw [\u2190 range_list_nthLe, \u2190 range_comp]\n  refine' (range_subset_iff.2 fun n => _).antisymm (insert_subset.2 \u27e8_, _\u27e9)\n  exacts [(le_or_lt l.length n).imp get?_eq_none.2 (fun hlt => \u27e8\u27e8_, hlt\u27e9, (get?_eq_get hlt).symm\u27e9),\n    \u27e8_, get?_eq_none.2 le_rfl\u27e9, range_subset_iff.2 <| fun k => \u27e8_, get?_eq_get _\u27e9]\n#align set.range_list_nth Set.range_list_get?\n\n@[simp]\ntheorem range_list_getD (d : \u03b1) : (range fun n => l.getD n d) = insert d { x | x \u2208 l } :=\n  calc\n    (range fun n => l.getD n d) = (fun o : Option \u03b1 => o.getD d) '' range l.get? := by\n      simp only [\u2190 range_comp, (\u00b7 \u2218 \u00b7), getD_eq_getD_get?]\n    _ = insert d { x | x \u2208 l } := by\n      simp only [range_list_get?, image_insert_eq, Option.getD, image_image, image_id']\n#align set.range_list_nthd Set.range_list_getD\n\n@[simp]\ntheorem range_list_getI [Inhabited \u03b1] (l : List \u03b1) : range l.getI = insert default { x | x \u2208 l } :=\n  range_list_getD l default\n#align set.range_list_inth Set.range_list_getI\n\nend Set\n\n/-- If each element of a list can be lifted to some type, then the whole list can be\nlifted to this type. -/\ninstance List.canLift (c) (p) [CanLift \u03b1 \u03b2 c p] :\n    CanLift (List \u03b1) (List \u03b2) (List.map c) fun l => \u2200 x \u2208 l, p x where\n  prf l H := by\n    rw [\u2190 Set.mem_range, Set.range_list_map]\n    exact fun a ha => CanLift.prf a (H a ha)\n#align list.can_lift List.canLift\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/List.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7058869404093269}}
{"text": "/-\nCopyright (c) 2019 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard\n-/\nimport data.real.basic\nimport data.real.ennreal\nimport data.sign\n\n/-!\n# The extended reals [-\u221e, \u221e].\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines `ereal`, the real numbers together with a top and bottom element,\nreferred to as \u22a4 and \u22a5. It is implemented as `with_bot (with_top \u211d)`\n\nAddition and multiplication are problematic in the presence of \u00b1\u221e, but\nnegation has a natural definition and satisfies the usual properties.\n\nAn ad hoc addition is defined, for which `ereal` is an `add_comm_monoid`, and even an ordered one\n(if `a \u2264 a'` and `b \u2264 b'` then `a + b \u2264 a' + b'`).\nNote however that addition is badly behaved at `(\u22a5, \u22a4)` and `(\u22a4, \u22a5)` so this can not be upgraded\nto a group structure. Our choice is that `\u22a5 + \u22a4 = \u22a4 + \u22a5 = \u22a5`, to make sure that the exponential\nand the logarithm between `ereal` and `\u211d\u22650\u221e` respect the operations (notice that the\nconvention `0 * \u221e = 0` on `\u211d\u22650\u221e` is enforced by measure theory).\n\nAn ad hoc subtraction is then defined by `x - y = x + (-y)`. It does not have nice properties,\nbut it is sometimes convenient to have.\n\nAn ad hoc multiplication is defined, for which `ereal` is a `comm_monoid_with_zero`. We make the\nchoice that `0 * x = x * 0 = 0` for any `x` (while the other cases are defined non-ambiguously).\nThis does not distribute with addition, as `\u22a5 = \u22a5 + \u22a4 = 1*\u22a5 + (-1)*\u22a5 \u2260 (1 - 1) * \u22a5 = 0 * \u22a5 = 0`.\n\n`ereal` is a `complete_linear_order`; this is deduced by type class inference from\nthe fact that `with_bot (with_top L)` is a complete linear order if `L` is\na conditionally complete linear order.\n\nCoercions from `\u211d` and from `\u211d\u22650\u221e` are registered, and their basic properties are proved. The main\none is the real coercion, and is usually referred to just as `coe` (lemmas such as\n`ereal.coe_add` deal with this coercion). The one from `ennreal` is usually called `coe_ennreal`\nin the `ereal` namespace.\n\nWe define an absolute value `ereal.abs` from `ereal` to `\u211d\u22650\u221e`. Two elements of `ereal` coincide\nif and only if they have the same absolute value and the same sign.\n\n## Tags\n\nreal, ereal, complete lattice\n-/\n\nopen function\nopen_locale ennreal nnreal\n\nnoncomputable theory\n\n/-- ereal : The type `[-\u221e, \u221e]` -/\n@[derive [has_bot, has_zero, has_one, nontrivial, add_monoid,\n  has_Sup, has_Inf, complete_linear_order, linear_ordered_add_comm_monoid, zero_le_one_class]]\ndef ereal := with_bot (with_top \u211d)\n\n/-- The canonical inclusion froms reals to ereals. Do not use directly: as this is registered as\na coercion, use the coercion instead. -/\ndef real.to_ereal : \u211d \u2192 ereal := some \u2218 some\n\nnamespace ereal\n\n-- things unify with `with_bot.decidable_lt` later if we we don't provide this explicitly.\ninstance decidable_lt : decidable_rel ((<) : ereal \u2192 ereal \u2192 Prop) :=\nwith_bot.decidable_lt\n\n-- TODO: Provide explicitly, otherwise it is inferred noncomputably from `complete_linear_order`\ninstance : has_top ereal := \u27e8some \u22a4\u27e9\n\ninstance : has_coe \u211d ereal := \u27e8real.to_ereal\u27e9\n\nlemma coe_strict_mono : strict_mono (coe : \u211d \u2192 ereal) :=\nwith_bot.coe_strict_mono.comp with_top.coe_strict_mono\n\nlemma coe_injective : injective (coe : \u211d \u2192 ereal) := coe_strict_mono.injective\n\n@[simp, norm_cast] protected lemma coe_le_coe_iff {x y : \u211d} : (x : ereal) \u2264 (y : ereal) \u2194 x \u2264 y :=\ncoe_strict_mono.le_iff_le\n@[simp, norm_cast] protected lemma coe_lt_coe_iff {x y : \u211d} : (x : ereal) < (y : ereal) \u2194 x < y :=\ncoe_strict_mono.lt_iff_lt\n@[simp, norm_cast] protected lemma coe_eq_coe_iff {x y : \u211d} : (x : ereal) = (y : ereal) \u2194 x = y :=\ncoe_injective.eq_iff\nprotected lemma coe_ne_coe_iff {x y : \u211d} : (x : ereal) \u2260 (y : ereal) \u2194 x \u2260 y := coe_injective.ne_iff\n\n/-- The canonical map from nonnegative extended reals to extended reals -/\ndef _root_.ennreal.to_ereal : \u211d\u22650\u221e \u2192 ereal\n| \u22a4 := \u22a4\n| (some x) := x.1\n\ninstance has_coe_ennreal : has_coe \u211d\u22650\u221e ereal := \u27e8ennreal.to_ereal\u27e9\n\ninstance : inhabited ereal := \u27e80\u27e9\n\n@[simp, norm_cast] lemma coe_zero : ((0 : \u211d) : ereal) = 0 := rfl\n@[simp, norm_cast] lemma coe_one : ((1 : \u211d) : ereal) = 1 := rfl\n\n/-- A recursor for `ereal` in terms of the coercion.\n\nA typical invocation looks like `induction x using ereal.rec`. Note that using `induction`\ndirectly will unfold `ereal` to `option` which is undesirable.\n\nWhen working in term mode, note that pattern matching can be used directly. -/\n@[elab_as_eliminator]\nprotected def rec {C : ereal \u2192 Sort*} (h_bot : C \u22a5) (h_real : \u03a0 a : \u211d, C a) (h_top : C \u22a4) :\n  \u2200 a : ereal, C a\n| \u22a5 := h_bot\n| (a : \u211d) := h_real a\n| \u22a4 := h_top\n\n/-- The multiplication on `ereal`. Our definition satisfies `0 * x = x * 0 = 0` for any `x`, and\npicks the only sensible value elsewhere. -/\nprotected def mul : ereal \u2192 ereal \u2192 ereal\n| \u22a5 \u22a5 := \u22a4\n| \u22a5 \u22a4 := \u22a5\n| \u22a5 (y : \u211d) := if 0 < y then \u22a5 else if y = 0 then 0 else \u22a4\n| \u22a4 \u22a5 := \u22a5\n| \u22a4 \u22a4 := \u22a4\n| \u22a4 (y : \u211d) := if 0 < y then \u22a4 else if y = 0 then 0 else \u22a5\n| (x : \u211d) \u22a4 := if 0 < x then \u22a4 else if x = 0 then 0 else \u22a5\n| (x : \u211d) \u22a5 := if 0 < x then \u22a5 else if x = 0 then 0 else \u22a4\n| (x : \u211d) (y : \u211d) := (x * y : \u211d)\n\ninstance : has_mul ereal := \u27e8ereal.mul\u27e9\n\n/-- Induct on two ereals by performing case splits on the sign of one whenever the other is\ninfinite. -/\n@[elab_as_eliminator]\nlemma induction\u2082 {P : ereal \u2192 ereal \u2192 Prop}\n  (top_top : P \u22a4 \u22a4)\n  (top_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a4 x)\n  (top_zero : P \u22a4 0)\n  (top_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a4 x)\n  (top_bot : P \u22a4 \u22a5)\n  (pos_top : \u2200 x : \u211d, 0 < x \u2192 P x \u22a4)\n  (pos_bot : \u2200 x : \u211d, 0 < x \u2192 P x \u22a5)\n  (zero_top : P 0 \u22a4)\n  (coe_coe : \u2200 x y : \u211d, P x y)\n  (zero_bot : P 0 \u22a5)\n  (neg_top : \u2200 x : \u211d, x < 0 \u2192 P x \u22a4)\n  (neg_bot : \u2200 x : \u211d, x < 0 \u2192 P x \u22a5)\n  (bot_top : P \u22a5 \u22a4)\n  (bot_pos : \u2200 x : \u211d, 0 < x \u2192 P \u22a5 x)\n  (bot_zero : P \u22a5 0)\n  (bot_neg : \u2200 x : \u211d, x < 0 \u2192 P \u22a5 x)\n  (bot_bot : P \u22a5 \u22a5) :\n  \u2200 x y, P x y\n| \u22a5 \u22a5 := bot_bot\n| \u22a5 (y : \u211d) :=\n  by { rcases lt_trichotomy 0 y with hy|rfl|hy, exacts [bot_pos y hy, bot_zero, bot_neg y hy] }\n| \u22a5 \u22a4 := bot_top\n| (x : \u211d) \u22a5 :=\n  by { rcases lt_trichotomy 0 x with hx|rfl|hx, exacts [pos_bot x hx, zero_bot, neg_bot x hx] }\n| (x : \u211d) (y : \u211d) := coe_coe _ _\n| (x : \u211d) \u22a4 :=\n  by { rcases lt_trichotomy 0 x with hx|rfl|hx, exacts [pos_top x hx, zero_top, neg_top x hx] }\n| \u22a4 \u22a5 := top_bot\n| \u22a4 (y : \u211d) :=\n  by { rcases lt_trichotomy 0 y with hy|rfl|hy, exacts [top_pos y hy, top_zero, top_neg y hy] }\n| \u22a4 \u22a4 := top_top\n\n/-! `ereal` with its multiplication is a `comm_monoid_with_zero`. However, the proof of\nassociativity by hand is extremely painful (with 125 cases...). Instead, we will deduce it later\non from the facts that the absolute value and the sign are multiplicative functions taking value\nin associative objects, and that they characterize an extended real number. For now, we only\nrecord more basic properties of multiplication.\n-/\ninstance : mul_zero_one_class ereal :=\n{ one_mul := \u03bb x, begin\n    induction x using ereal.rec;\n    { dsimp only [(*)], simp only [ereal.mul, \u2190 ereal.coe_one, zero_lt_one, if_true, one_mul] },\n  end,\n  mul_one := \u03bb x, begin\n    induction x using ereal.rec;\n    { dsimp only [(*)], simp only [ereal.mul, \u2190 ereal.coe_one, zero_lt_one, if_true, mul_one] },\n  end,\n  zero_mul := \u03bb x, begin\n    induction x using ereal.rec;\n    { simp only [(*)], simp only [ereal.mul, \u2190 ereal.coe_zero, zero_lt_one, if_true, if_false,\n        lt_irrefl (0 : \u211d), eq_self_iff_true, zero_mul] },\n  end,\n  mul_zero := \u03bb x, begin\n    induction x using ereal.rec;\n    { simp only [(*)], simp only [ereal.mul, \u2190 ereal.coe_zero, zero_lt_one, if_true, if_false,\n        lt_irrefl (0 : \u211d), eq_self_iff_true, mul_zero] },\n  end,\n  ..ereal.has_mul, ..ereal.has_one, ..ereal.has_zero }\n\n/-! ### Real coercion -/\n\ninstance can_lift : can_lift ereal \u211d coe (\u03bb r, r \u2260 \u22a4 \u2227 r \u2260 \u22a5) :=\n{ prf := \u03bb x hx,\n  begin\n    induction x using ereal.rec,\n    { simpa using hx },\n    { simp },\n    { simpa using hx }\n  end }\n\n/-- The map from extended reals to reals sending infinities to zero. -/\ndef to_real : ereal \u2192 \u211d\n| \u22a5       := 0\n| \u22a4       := 0\n| (x : \u211d) := x\n\n@[simp] lemma to_real_top : to_real \u22a4 = 0 := rfl\n\n@[simp] lemma to_real_bot : to_real \u22a5 = 0 := rfl\n\n@[simp] lemma to_real_zero : to_real 0 = 0 := rfl\n\n@[simp] lemma to_real_one : to_real 1 = 1 := rfl\n\n@[simp] lemma to_real_coe (x : \u211d) : to_real (x : ereal) = x := rfl\n\n@[simp] lemma bot_lt_coe (x : \u211d) : (\u22a5 : ereal) < x := with_bot.bot_lt_coe _\n\n@[simp] lemma coe_ne_bot (x : \u211d) : (x : ereal) \u2260 \u22a5  := (bot_lt_coe x).ne'\n\n@[simp] lemma bot_ne_coe (x : \u211d) : (\u22a5 : ereal) \u2260 x := (bot_lt_coe x).ne\n\n@[simp] lemma coe_lt_top (x : \u211d) : (x : ereal) < \u22a4 :=\nby { apply with_bot.coe_lt_coe.2, exact with_top.coe_lt_top _ }\n\n@[simp] lemma coe_ne_top (x : \u211d) : (x : ereal) \u2260 \u22a4 := (coe_lt_top x).ne\n\n@[simp] lemma top_ne_coe (x : \u211d) : (\u22a4 : ereal) \u2260 x := (coe_lt_top x).ne'\n\n@[simp] lemma bot_lt_zero : (\u22a5 : ereal) < 0 := bot_lt_coe 0\n\n@[simp] lemma bot_ne_zero : (\u22a5 : ereal) \u2260 0 := (coe_ne_bot 0).symm\n\n@[simp] lemma zero_ne_bot : (0 : ereal) \u2260 \u22a5 := coe_ne_bot 0\n\n@[simp] lemma zero_lt_top : (0 : ereal) < \u22a4 := coe_lt_top 0\n\n@[simp] lemma zero_ne_top : (0 : ereal) \u2260 \u22a4 := coe_ne_top 0\n\n@[simp] lemma top_ne_zero : (\u22a4 : ereal) \u2260 0 := (coe_ne_top 0).symm\n\n@[simp, norm_cast] lemma coe_add (x y : \u211d) : (\u2191(x + y) : ereal) = x + y := rfl\n@[simp, norm_cast] lemma coe_mul (x y : \u211d) : (\u2191(x * y) : ereal) = x * y := rfl\n@[norm_cast] lemma coe_nsmul (n : \u2115) (x : \u211d) : (\u2191(n \u2022 x) : ereal) = n \u2022 x :=\nmap_nsmul (\u27e8coe, coe_zero, coe_add\u27e9 : \u211d \u2192+ ereal) _ _\n\n@[simp, norm_cast] lemma coe_bit0 (x : \u211d) : (\u2191(bit0 x) : ereal) = bit0 x := rfl\n@[simp, norm_cast] lemma coe_bit1 (x : \u211d) : (\u2191(bit1 x) : ereal) = bit1 x := rfl\n\n@[simp, norm_cast] lemma coe_eq_zero {x : \u211d} : (x : ereal) = 0 \u2194 x = 0 := ereal.coe_eq_coe_iff\n@[simp, norm_cast] lemma coe_eq_one {x : \u211d} : (x : ereal) = 1 \u2194 x = 1 := ereal.coe_eq_coe_iff\nlemma coe_ne_zero {x : \u211d} : (x : ereal) \u2260 0 \u2194 x \u2260 0 := ereal.coe_ne_coe_iff\nlemma coe_ne_one {x : \u211d} : (x : ereal) \u2260 1 \u2194 x \u2260 1 := ereal.coe_ne_coe_iff\n\n@[simp, norm_cast] protected lemma coe_nonneg {x : \u211d} : (0 : ereal) \u2264 x \u2194 0 \u2264 x :=\nereal.coe_le_coe_iff\n\n@[simp, norm_cast] protected lemma coe_nonpos {x : \u211d} : (x : ereal) \u2264 0 \u2194 x \u2264 0 :=\nereal.coe_le_coe_iff\n\n@[simp, norm_cast] protected lemma coe_pos {x : \u211d} : (0 : ereal) < x \u2194 0 < x :=\nereal.coe_lt_coe_iff\n\n@[simp, norm_cast] protected lemma coe_neg' {x : \u211d} : (x : ereal) < 0 \u2194 x < 0 :=\nereal.coe_lt_coe_iff\n\nlemma to_real_le_to_real {x y : ereal} (h : x \u2264 y) (hx : x \u2260 \u22a5) (hy : y \u2260 \u22a4) :\n  x.to_real \u2264 y.to_real :=\nbegin\n  lift x to \u211d,\n  { simp [hx, (h.trans_lt (lt_top_iff_ne_top.2 hy)).ne], },\n  lift y to \u211d,\n  { simp [hy, ((bot_lt_iff_ne_bot.2 hx).trans_le h).ne'] },\n  simpa using h\nend\n\nlemma coe_to_real {x : ereal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) : (x.to_real : ereal) = x :=\nbegin\n  induction x using ereal.rec,\n  { simpa using h'x },\n  { refl },\n  { simpa using hx },\nend\n\nlemma le_coe_to_real {x : ereal} (h : x \u2260 \u22a4) : x \u2264 x.to_real :=\nbegin\n  by_cases h' : x = \u22a5,\n  { simp only [h', bot_le] },\n  { simp only [le_refl, coe_to_real h h'] },\nend\n\nlemma coe_to_real_le {x : ereal} (h : x \u2260 \u22a5) : \u2191x.to_real \u2264 x :=\nbegin\n  by_cases h' : x = \u22a4,\n  { simp only [h', le_top] },\n  { simp only [le_refl, coe_to_real h' h] },\nend\n\nlemma eq_top_iff_forall_lt (x : ereal) : x = \u22a4 \u2194 \u2200 (y : \u211d), (y : ereal) < x :=\nbegin\n  split,\n  { rintro rfl, exact ereal.coe_lt_top },\n  { contrapose!,\n    intro h,\n    exact \u27e8x.to_real, le_coe_to_real h\u27e9, },\nend\n\nlemma eq_bot_iff_forall_lt (x : ereal) : x = \u22a5 \u2194 \u2200 (y : \u211d), x < (y : ereal) :=\nbegin\n  split,\n  { rintro rfl, exact bot_lt_coe },\n  { contrapose!,\n    intro h,\n    exact \u27e8x.to_real, coe_to_real_le h\u27e9, },\nend\n\n/-! ### ennreal coercion -/\n\n@[simp] lemma to_real_coe_ennreal : \u2200 {x : \u211d\u22650\u221e}, to_real (x : ereal) = ennreal.to_real x\n| \u22a4 := rfl\n| (some x) := rfl\n\n@[simp] lemma coe_ennreal_of_real {x : \u211d} :\n  (ennreal.of_real x : ereal) = max x 0 :=\nrfl\n\nlemma coe_nnreal_eq_coe_real (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : ereal) = (x : \u211d) := rfl\n\n@[simp, norm_cast] lemma coe_ennreal_zero : ((0 : \u211d\u22650\u221e) : ereal) = 0 := rfl\n@[simp, norm_cast] lemma coe_ennreal_one : ((1 : \u211d\u22650\u221e) : ereal) = 1 := rfl\n@[simp, norm_cast] lemma coe_ennreal_top : ((\u22a4 : \u211d\u22650\u221e) : ereal) = \u22a4 := rfl\n\n@[simp] lemma coe_ennreal_eq_top_iff : \u2200 {x : \u211d\u22650\u221e}, (x : ereal) = \u22a4 \u2194 x = \u22a4\n| \u22a4 := by simp\n| (some x) := by { simp only [ennreal.coe_ne_top, iff_false, ennreal.some_eq_coe], dec_trivial }\n\nlemma coe_nnreal_ne_top (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : ereal) \u2260 \u22a4 := dec_trivial\n\n@[simp] lemma coe_nnreal_lt_top (x : \u211d\u22650) : ((x : \u211d\u22650\u221e) : ereal) < \u22a4 := dec_trivial\n\nlemma coe_ennreal_strict_mono : strict_mono (coe : \u211d\u22650\u221e \u2192 ereal)\n| \u22a4 \u22a4 := by simp\n| (some x) \u22a4 := by simp\n| \u22a4 (some y) := by simp\n| (some x) (some y) := by simp [coe_nnreal_eq_coe_real]\n\nlemma coe_ennreal_injective : injective (coe : \u211d\u22650\u221e \u2192 ereal) := coe_ennreal_strict_mono.injective\n\n@[simp, norm_cast] lemma coe_ennreal_le_coe_ennreal_iff {x y : \u211d\u22650\u221e} :\n  (x : ereal) \u2264 (y : ereal) \u2194 x \u2264 y :=\ncoe_ennreal_strict_mono.le_iff_le\n\n@[simp, norm_cast] lemma coe_ennreal_lt_coe_ennreal_iff {x y : \u211d\u22650\u221e} :\n  (x : ereal) < (y : ereal) \u2194 x < y :=\ncoe_ennreal_strict_mono.lt_iff_lt\n\n@[simp, norm_cast] lemma coe_ennreal_eq_coe_ennreal_iff {x y : \u211d\u22650\u221e} :\n  (x : ereal) = (y : ereal) \u2194 x = y :=\ncoe_ennreal_injective.eq_iff\n\nlemma coe_ennreal_ne_coe_ennreal_iff {x y : \u211d\u22650\u221e} : (x : ereal) \u2260 (y : ereal) \u2194 x \u2260 y :=\ncoe_ennreal_injective.ne_iff\n\n@[simp, norm_cast] lemma coe_ennreal_eq_zero {x : \u211d\u22650\u221e} : (x : ereal) = 0 \u2194 x = 0 :=\nby rw [\u2190coe_ennreal_eq_coe_ennreal_iff, coe_ennreal_zero]\n\n@[simp, norm_cast] lemma coe_ennreal_eq_one {x : \u211d\u22650\u221e} : (x : ereal) = 1 \u2194 x = 1 :=\nby rw [\u2190coe_ennreal_eq_coe_ennreal_iff, coe_ennreal_one]\n\n@[norm_cast] lemma coe_ennreal_ne_zero {x : \u211d\u22650\u221e} : (x : ereal) \u2260 0 \u2194 x \u2260 0 :=\ncoe_ennreal_eq_zero.not\n\n@[norm_cast] lemma coe_ennreal_ne_one {x : \u211d\u22650\u221e} : (x : ereal) \u2260 1 \u2194 x \u2260 1 := coe_ennreal_eq_one.not\n\nlemma coe_ennreal_nonneg (x : \u211d\u22650\u221e) : (0 : ereal) \u2264 x :=\ncoe_ennreal_le_coe_ennreal_iff.2 (zero_le x)\n\n@[simp, norm_cast] lemma coe_ennreal_pos {x : \u211d\u22650\u221e} : (0 : ereal) < x \u2194 0 < x :=\nby rw [\u2190coe_ennreal_zero, coe_ennreal_lt_coe_ennreal_iff]\n\n@[simp] lemma bot_lt_coe_ennreal (x : \u211d\u22650\u221e) : (\u22a5 : ereal) < x :=\n(bot_lt_coe 0).trans_le (coe_ennreal_nonneg _)\n\n@[simp] lemma coe_ennreal_ne_bot (x : \u211d\u22650\u221e) : (x : ereal) \u2260 \u22a5 := (bot_lt_coe_ennreal x).ne'\n\n@[simp, norm_cast] lemma coe_ennreal_add (x y : ennreal) : ((x + y : \u211d\u22650\u221e) : ereal) = x + y :=\nby cases x; cases y; refl\n\n@[simp, norm_cast] lemma coe_ennreal_mul : \u2200 (x y : \u211d\u22650\u221e), ((x * y : \u211d\u22650\u221e) : ereal) = x * y\n| \u22a4 \u22a4 := rfl\n| \u22a4 (y : \u211d\u22650) := begin\n    rw ennreal.top_mul, split_ifs,\n    { simp only [h, coe_ennreal_zero, mul_zero] },\n    { have A : (0 : \u211d) < y,\n      { simp only [ennreal.coe_eq_zero] at h,\n        exact nnreal.coe_pos.2 (bot_lt_iff_ne_bot.2 h) },\n      simp only [coe_nnreal_eq_coe_real, coe_ennreal_top, (*), ereal.mul, A, if_true], }\n  end\n| (x : \u211d\u22650) \u22a4 := begin\n    rw ennreal.mul_top, split_ifs,\n    { simp only [h, coe_ennreal_zero, zero_mul] },\n    { have A : (0 : \u211d) < x,\n      { simp only [ennreal.coe_eq_zero] at h,\n        exact nnreal.coe_pos.2 (bot_lt_iff_ne_bot.2 h) },\n      simp only [coe_nnreal_eq_coe_real, coe_ennreal_top, (*), ereal.mul, A, if_true] }\n  end\n| (x : \u211d\u22650) (y : \u211d\u22650) := by simp only [\u2190 ennreal.coe_mul, coe_nnreal_eq_coe_real,\n    nnreal.coe_mul, ereal.coe_mul]\n\n@[norm_cast] lemma coe_ennreal_nsmul (n : \u2115) (x : \u211d\u22650\u221e) : (\u2191(n \u2022 x) : ereal) = n \u2022 x :=\nmap_nsmul (\u27e8coe, coe_ennreal_zero, coe_ennreal_add\u27e9 : \u211d\u22650\u221e \u2192+ ereal) _ _\n\n@[simp, norm_cast] lemma coe_ennreal_bit0 (x : \u211d\u22650\u221e) : (\u2191(bit0 x) : ereal) = bit0 x :=\ncoe_ennreal_add _ _\n@[simp, norm_cast] lemma coe_ennreal_bit1 (x : \u211d\u22650\u221e) : (\u2191(bit1 x) : ereal) = bit1 x :=\nby simp_rw [bit1, coe_ennreal_add, coe_ennreal_bit0, coe_ennreal_one]\n\n/-! ### Order -/\n\nlemma exists_rat_btwn_of_lt : \u03a0 {a b : ereal} (hab : a < b),\n  \u2203 (x : \u211a), a < (x : \u211d) \u2227 ((x : \u211d) : ereal) < b\n| \u22a4 b h := (not_top_lt h).elim\n| (a : \u211d) \u22a5 h := (lt_irrefl _ ((bot_lt_coe a).trans h)).elim\n| (a : \u211d) (b : \u211d) h := by simp [exists_rat_btwn (ereal.coe_lt_coe_iff.1 h)]\n| (a : \u211d) \u22a4 h := let \u27e8b, hab\u27e9 := exists_rat_gt a in \u27e8b, by simpa using hab, coe_lt_top _\u27e9\n| \u22a5 \u22a5 h := (lt_irrefl _ h).elim\n| \u22a5 (a : \u211d) h := let \u27e8b, hab\u27e9 := exists_rat_lt a in \u27e8b, bot_lt_coe _, by simpa using hab\u27e9\n| \u22a5 \u22a4 h := \u27e80, bot_lt_coe _, coe_lt_top _\u27e9\n\nlemma lt_iff_exists_rat_btwn {a b : ereal} :\n  a < b \u2194 \u2203 (x : \u211a), a < (x : \u211d) \u2227 ((x : \u211d) : ereal) < b :=\n\u27e8\u03bb hab, exists_rat_btwn_of_lt hab, \u03bb \u27e8x, ax, xb\u27e9, ax.trans xb\u27e9\n\nlemma lt_iff_exists_real_btwn {a b : ereal} :\n  a < b \u2194 \u2203 (x : \u211d), a < x \u2227 (x : ereal) < b :=\n\u27e8\u03bb hab, let \u27e8x, ax, xb\u27e9 := exists_rat_btwn_of_lt hab in \u27e8(x : \u211d), ax, xb\u27e9,\n \u03bb \u27e8x, ax, xb\u27e9, ax.trans xb\u27e9\n\n/-- The set of numbers in `ereal` that are not equal to `\u00b1\u221e` is equivalent to `\u211d`. -/\ndef ne_top_bot_equiv_real : ({\u22a5, \u22a4}\u1d9c : set ereal) \u2243 \u211d :=\n{ to_fun := \u03bb x, ereal.to_real x,\n  inv_fun := \u03bb x, \u27e8x, by simp\u27e9,\n  left_inv := \u03bb \u27e8x, hx\u27e9, subtype.eq $ begin\n    lift x to \u211d,\n    { simpa [not_or_distrib, and_comm] using hx },\n    { simp },\n  end,\n  right_inv := \u03bb x, by simp }\n\n/-! ### Addition -/\n\n@[simp] lemma add_bot (x : ereal) : x + \u22a5 = \u22a5 := with_bot.add_bot _\n@[simp] lemma bot_add (x : ereal) : \u22a5 + x = \u22a5 := with_bot.bot_add _\n\n@[simp] lemma top_add_top : (\u22a4 : ereal) + \u22a4 = \u22a4 := rfl\n@[simp] lemma top_add_coe (x : \u211d) : (\u22a4 : ereal) + x = \u22a4 := rfl\n@[simp] lemma coe_add_top (x : \u211d) : (x : ereal) + \u22a4 = \u22a4 := rfl\n\nlemma to_real_add : \u2200 {x y : ereal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) (hy : y \u2260 \u22a4) (h'y : y \u2260 \u22a5),\n  to_real (x + y) = to_real x + to_real y\n| \u22a5 y hx h'x hy h'y := (h'x rfl).elim\n| \u22a4 y hx h'x hy h'y := (hx rfl).elim\n| x \u22a4 hx h'x hy h'y := (hy rfl).elim\n| x \u22a5 hx h'x hy h'y := (h'y rfl).elim\n| (x : \u211d) (y : \u211d) hx h'x hy h'y := by simp [\u2190 ereal.coe_add]\n\nlemma add_lt_add_right_coe {x y : ereal} (h : x < y) (z : \u211d) : x + z < y + z :=\nbegin\n  induction x using ereal.rec; induction y using ereal.rec,\n  { exact (lt_irrefl _ h).elim },\n  { simp only [\u2190 coe_add, bot_add, bot_lt_coe] },\n  { simp },\n  { exact (lt_irrefl _ (h.trans (bot_lt_coe x))).elim },\n  { norm_cast at h \u22a2, exact add_lt_add_right h _ },\n  { simp only [\u2190 coe_add, top_add_coe, coe_lt_top] },\n  { exact (lt_irrefl _ (h.trans_le le_top)).elim },\n  { exact (lt_irrefl _ (h.trans_le le_top)).elim },\n  { exact (lt_irrefl _ (h.trans_le le_top)).elim },\nend\n\nlemma add_lt_add_of_lt_of_le {x y z t : ereal} (h : x < y) (h' : z \u2264 t) (hz : z \u2260 \u22a5) (ht : t \u2260 \u22a4) :\n  x + z < y + t :=\nbegin\n  induction z using ereal.rec,\n  { simpa only using hz },\n  { calc x + z < y + z : add_lt_add_right_coe h _\n           ... \u2264 y + t : add_le_add le_rfl h' },\n  { exact (ht (top_le_iff.1 h')).elim }\nend\n\nlemma add_lt_add_left_coe {x y : ereal} (h : x < y) (z : \u211d) : (z : ereal) + x < z + y :=\nby simpa [add_comm] using add_lt_add_right_coe h z\n\nlemma add_lt_add {x y z t : ereal} (h1 : x < y) (h2 : z < t) : x + z < y + t :=\nbegin\n  induction x using ereal.rec,\n  { simp [bot_lt_iff_ne_bot, h1.ne', (bot_le.trans_lt h2).ne'] },\n  { calc (x : ereal) + z < x + t : add_lt_add_left_coe h2 _\n    ... \u2264 y + t : add_le_add h1.le le_rfl },\n  { exact (lt_irrefl _ (h1.trans_le le_top)).elim }\nend\n\n@[simp] lemma add_eq_bot_iff {x y : ereal} : x + y = \u22a5 \u2194 x = \u22a5 \u2228 y = \u22a5 :=\nbegin\n  induction x using ereal.rec; induction y using ereal.rec;\n  simp [\u2190 ereal.coe_add],\nend\n\n@[simp] lemma bot_lt_add_iff {x y : ereal} : \u22a5 < x + y \u2194 \u22a5 < x \u2227 \u22a5 < y :=\nby simp [bot_lt_iff_ne_bot, not_or_distrib]\n\nlemma add_lt_top {x y : ereal} (hx : x \u2260 \u22a4) (hy : y \u2260 \u22a4) : x + y < \u22a4 :=\nby { rw \u2190 ereal.top_add_top, exact ereal.add_lt_add hx.lt_top hy.lt_top }\n\n/-! ### Negation -/\n\n/-- negation on `ereal` -/\nprotected def neg : ereal \u2192 ereal\n| \u22a5       := \u22a4\n| \u22a4       := \u22a5\n| (x : \u211d) := (-x : \u211d)\n\ninstance : has_neg ereal := \u27e8ereal.neg\u27e9\n\ninstance : sub_neg_zero_monoid ereal :=\n{ neg_zero := by { change ((-0 : \u211d) : ereal) = 0, simp },\n  ..ereal.add_monoid, ..ereal.has_neg }\n\n@[norm_cast] protected lemma neg_def (x : \u211d) : ((-x : \u211d) : ereal) = -x := rfl\n\n@[simp] lemma neg_top : - (\u22a4 : ereal) = \u22a5 := rfl\n@[simp] lemma neg_bot : - (\u22a5 : ereal) = \u22a4 := rfl\n\n@[simp, norm_cast] lemma coe_neg (x : \u211d) : (\u2191(-x) : ereal) = -x := rfl\n@[simp, norm_cast] lemma coe_sub (x y : \u211d) : (\u2191(x - y) : ereal) = x - y := rfl\n@[norm_cast] lemma coe_zsmul (n : \u2124) (x : \u211d) : (\u2191(n \u2022 x) : ereal) = n \u2022 x :=\nmap_zsmul' (\u27e8coe, coe_zero, coe_add\u27e9 : \u211d \u2192+ ereal) coe_neg _ _\n\ninstance : has_involutive_neg ereal :=\n{ neg := has_neg.neg,\n  neg_neg := \u03bb a, match a with\n    | \u22a5 := rfl\n    | \u22a4 := rfl\n    | (a : \u211d) := by { norm_cast, simp [neg_neg a] }\n    end }\n\n@[simp] lemma to_real_neg : \u2200 {a : ereal}, to_real (-a) = - to_real a\n| \u22a4 := by simp\n| \u22a5 := by simp\n| (x : \u211d) := rfl\n\n@[simp] lemma neg_eq_top_iff {x : ereal} : - x = \u22a4 \u2194 x = \u22a5 :=\nneg_eq_iff_eq_neg\n\n@[simp] lemma neg_eq_bot_iff {x : ereal} : - x = \u22a5 \u2194 x = \u22a4 :=\nneg_eq_iff_eq_neg\n\n@[simp] lemma neg_eq_zero_iff {x : ereal} : - x = 0 \u2194 x = 0 :=\nby rw [neg_eq_iff_eq_neg, neg_zero]\n\n/-- if `-a \u2264 b` then `-b \u2264 a` on `ereal`. -/\nprotected theorem neg_le_of_neg_le {a b : ereal} (h : -a \u2264 b) : -b \u2264 a :=\nbegin\n  induction a using ereal.rec; induction b using ereal.rec,\n  { exact h },\n  { simpa only [coe_ne_top, neg_bot, top_le_iff] using h },\n  { exact bot_le },\n  { simpa only [coe_ne_top, le_bot_iff] using h },\n  { norm_cast at h \u22a2, exact neg_le.1 h },\n  { exact bot_le },\n  { exact le_top },\n  { exact le_top },\n  { exact le_top },\nend\n\n/-- `-a \u2264 b \u2194 -b \u2264 a` on `ereal`. -/\nprotected theorem neg_le {a b : ereal} : -a \u2264 b \u2194 -b \u2264 a :=\n\u27e8ereal.neg_le_of_neg_le, ereal.neg_le_of_neg_le\u27e9\n\n/-- `a \u2264 -b \u2192 b \u2264 -a` on ereal -/\ntheorem le_neg_of_le_neg {a b : ereal} (h : a \u2264 -b) : b \u2264 -a :=\nby rwa [\u2190neg_neg b, ereal.neg_le, neg_neg]\n\n@[simp] lemma neg_le_neg_iff {a b : ereal} : - a \u2264 - b \u2194 b \u2264 a :=\nby conv_lhs { rw [ereal.neg_le, neg_neg] }\n\n/-- Negation as an order reversing isomorphism on `ereal`. -/\ndef neg_order_iso : ereal \u2243o ereal\u1d52\u1d48 :=\n{ to_fun := \u03bb x, order_dual.to_dual (-x),\n  inv_fun := \u03bb x, -x.of_dual,\n  map_rel_iff' := \u03bb x y, neg_le_neg_iff,\n  ..equiv.neg ereal }\n\nlemma neg_lt_of_neg_lt {a b : ereal} (h : -a < b) : -b < a :=\nbegin\n  apply lt_of_le_of_ne (ereal.neg_le_of_neg_le h.le),\n  assume H,\n  rw [\u2190 H, neg_neg] at h,\n  exact lt_irrefl _ h\nend\n\nlemma neg_lt_iff_neg_lt {a b : ereal} : -a < b \u2194 -b < a :=\n\u27e8\u03bb h, ereal.neg_lt_of_neg_lt h, \u03bb h, ereal.neg_lt_of_neg_lt h\u27e9\n\n/-!\n### Subtraction\n\nSubtraction on `ereal` is defined by `x - y = x + (-y)`. Since addition is badly behaved at some\npoints, so is subtraction. There is no standard algebraic typeclass involving subtraction that is\nregistered on `ereal`, beyond `sub_neg_zero_monoid`, because of this bad behavior.\n-/\n\n@[simp] lemma bot_sub (x : ereal) : \u22a5 - x = \u22a5 := bot_add x\n@[simp] lemma sub_top (x : ereal) : x - \u22a4 = \u22a5 := add_bot x\n\n@[simp] lemma top_sub_bot : (\u22a4 : ereal) - \u22a5 = \u22a4 := rfl\n@[simp] lemma top_sub_coe (x : \u211d) : (\u22a4 : ereal) - x = \u22a4 := rfl\n@[simp] lemma coe_sub_bot (x : \u211d) : (x : ereal) - \u22a5 = \u22a4 := rfl\n\nlemma sub_le_sub {x y z t : ereal} (h : x \u2264 y) (h' : t \u2264 z) : x - z \u2264 y - t :=\nadd_le_add h (neg_le_neg_iff.2 h')\n\nlemma sub_lt_sub_of_lt_of_le {x y z t : ereal} (h : x < y) (h' : z \u2264 t) (hz : z \u2260 \u22a5) (ht : t \u2260 \u22a4) :\n  x - t < y - z :=\nadd_lt_add_of_lt_of_le h (neg_le_neg_iff.2 h') (by simp [ht]) (by simp [hz])\n\nlemma coe_real_ereal_eq_coe_to_nnreal_sub_coe_to_nnreal (x : \u211d) :\n  (x : ereal) = real.to_nnreal x - real.to_nnreal (-x) :=\nbegin\n  rcases le_or_lt 0 x with h|h,\n  { have : real.to_nnreal x = \u27e8x, h\u27e9, by { ext, simp [h] },\n    simp only [real.to_nnreal_of_nonpos (neg_nonpos.mpr h), this, sub_zero, ennreal.coe_zero,\n      coe_ennreal_zero, coe_coe],\n    refl },\n  { have : (x : ereal) = - (- x : \u211d), by simp,\n    conv_lhs { rw this },\n    have : real.to_nnreal (-x) = \u27e8-x, neg_nonneg.mpr h.le\u27e9, by { ext, simp [neg_nonneg.mpr h.le], },\n    simp only [real.to_nnreal_of_nonpos h.le, this, zero_sub, neg_inj, coe_neg,\n      ennreal.coe_zero, coe_ennreal_zero, coe_coe],\n    refl }\nend\n\nlemma to_real_sub {x y : ereal} (hx : x \u2260 \u22a4) (h'x : x \u2260 \u22a5) (hy : y \u2260 \u22a4) (h'y : y \u2260 \u22a5) :\n  to_real (x - y) = to_real x - to_real y :=\nbegin\n  rw [sub_eq_add_neg, to_real_add hx h'x, to_real_neg],\n  { refl },\n  { simpa using hy },\n  { simpa using h'y }\nend\n\n/-! ### Multiplication -/\n\nprotected lemma mul_comm (x y : ereal) : x * y = y * x :=\nbegin\n  induction x using ereal.rec; induction y using ereal.rec; try { refl },\n  dsimp only [(*)],\n  simp only [ereal.mul, mul_comm],\nend\n\n@[simp] lemma top_mul_top : (\u22a4 : ereal) * \u22a4 = \u22a4 := rfl\n@[simp] lemma top_mul_bot : (\u22a4 : ereal) * \u22a5 = \u22a5 := rfl\n@[simp] lemma bot_mul_top : (\u22a5 : ereal) * \u22a4 = \u22a5 := rfl\n@[simp] lemma bot_mul_bot : (\u22a5 : ereal) * \u22a5 = \u22a4 := rfl\n\nlemma mul_top_of_pos {x : ereal} (h : 0 < x) : x * \u22a4 = \u22a4 :=\nbegin\n  induction x using ereal.rec,\n  { simpa only [not_lt_bot] using h },\n  { simp only [has_mul.mul, ereal.mul, ereal.coe_pos.1 h, if_true] },\n  { refl }\nend\n\nlemma mul_top_of_neg {x : ereal} (h : x < 0) : x * \u22a4 = \u22a5 :=\nbegin\n  induction x using ereal.rec,\n  { refl },\n  { simp only [ereal.coe_neg'] at h,\n    simp only [has_mul.mul, ereal.mul, not_lt.2 h.le, h.ne, if_false] },\n  { simpa only [not_top_lt] using h }\nend\n\nlemma top_mul_of_pos {x : ereal} (h : 0 < x) : \u22a4 * x = \u22a4 :=\nby { rw ereal.mul_comm, exact mul_top_of_pos h }\n\nlemma top_mul_of_neg {x : ereal} (h : x < 0) : \u22a4 * x = \u22a5 :=\nby { rw ereal.mul_comm, exact mul_top_of_neg h }\n\nlemma coe_mul_top_of_pos {x : \u211d} (h : 0 < x) : (x : ereal) * \u22a4 = \u22a4 :=\nmul_top_of_pos (ereal.coe_pos.2 h)\n\nlemma coe_mul_top_of_neg {x : \u211d} (h : x < 0) : (x : ereal) * \u22a4 = \u22a5 :=\nmul_top_of_neg (ereal.coe_neg'.2 h)\n\nlemma top_mul_coe_of_pos {x : \u211d} (h : 0 < x) : (\u22a4 : ereal) * x = \u22a4 :=\ntop_mul_of_pos (ereal.coe_pos.2 h)\n\nlemma top_mul_coe_of_neg {x : \u211d} (h : x < 0) : (\u22a4 : ereal) * x = \u22a5 :=\ntop_mul_of_neg (ereal.coe_neg'.2 h)\n\nlemma mul_bot_of_pos {x : ereal} (h : 0 < x) : x * \u22a5 = \u22a5 :=\nbegin\n  induction x using ereal.rec,\n  { simpa only [not_lt_bot] using h },\n  { simp only [has_mul.mul, ereal.mul, ereal.coe_pos.1 h, if_true] },\n  { refl }\nend\n\nlemma mul_bot_of_neg {x : ereal} (h : x < 0) : x * \u22a5 = \u22a4 :=\nbegin\n  induction x using ereal.rec,\n  { refl },\n  { simp only [ereal.coe_neg'] at h,\n    simp only [has_mul.mul, ereal.mul, not_lt.2 h.le, h.ne, if_false] },\n  { simpa only [not_top_lt] using h }\nend\n\nlemma bot_mul_of_pos {x : ereal} (h : 0 < x) : \u22a5 * x = \u22a5 :=\nby { rw ereal.mul_comm, exact mul_bot_of_pos h }\n\nlemma bot_mul_of_neg {x : ereal} (h : x < 0) : \u22a5 * x = \u22a4 :=\nby { rw ereal.mul_comm, exact mul_bot_of_neg h }\n\nlemma coe_mul_bot_of_pos {x : \u211d} (h : 0 < x) : (x : ereal) * \u22a5 = \u22a5 :=\nmul_bot_of_pos (ereal.coe_pos.2 h)\n\nlemma coe_mul_bot_of_neg {x : \u211d} (h : x < 0) : (x : ereal) * \u22a5 = \u22a4 :=\nmul_bot_of_neg (ereal.coe_neg'.2 h)\n\nlemma bot_mul_coe_of_pos {x : \u211d} (h : 0 < x) : (\u22a5 : ereal) * x = \u22a5 :=\nbot_mul_of_pos (ereal.coe_pos.2 h)\n\n\n\nlemma to_real_mul {x y : ereal} : to_real (x * y) = to_real x * to_real y :=\nbegin\n  -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n  with_cases\n  { apply @induction\u2082 (\u03bb x y, to_real (x * y) = to_real x * to_real y) };\n    propagate_tags { try { dsimp only} },\n  case [top_zero, bot_zero, zero_top, zero_bot] { all_goals { simp only [zero_mul, mul_zero,\n                                                                         to_real_zero] } },\n  case coe_coe : x y { norm_cast },\n  case top_top { rw [top_mul_top, to_real_top, mul_zero] },\n  case top_bot { rw [top_mul_bot, to_real_top, to_real_bot, zero_mul] },\n  case bot_top { rw [bot_mul_top, to_real_bot, zero_mul] },\n  case bot_bot { rw [bot_mul_bot, to_real_top, to_real_bot, zero_mul] },\n  case pos_bot : x hx\n  { rw [to_real_bot, to_real_coe, coe_mul_bot_of_pos hx, to_real_bot, mul_zero] },\n  case neg_bot : x hx\n  { rw [to_real_bot, to_real_coe, coe_mul_bot_of_neg hx, to_real_top, mul_zero] },\n  case pos_top : x hx\n  { rw [to_real_top, to_real_coe, coe_mul_top_of_pos hx, to_real_top, mul_zero] },\n  case neg_top : x hx\n  { rw [to_real_top, to_real_coe, coe_mul_top_of_neg hx, to_real_bot, mul_zero] },\n  case top_pos : y hy\n  { rw [to_real_top, to_real_coe, top_mul_coe_of_pos hy, to_real_top, zero_mul] },\n  case top_neg : y hy\n  { rw [to_real_top, to_real_coe, top_mul_coe_of_neg hy, to_real_bot, zero_mul] },\n  case bot_pos : y hy\n  { rw [to_real_bot, to_real_coe, bot_mul_coe_of_pos hy, to_real_bot, zero_mul] },\n  case bot_neg : y hy\n  { rw [to_real_bot, to_real_coe, bot_mul_coe_of_neg hy, to_real_top, zero_mul] },\nend\n\nprotected lemma neg_mul (x y : ereal) : -x * y = -(x * y) :=\nbegin\n  -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n  with_cases\n  { apply @induction\u2082 (\u03bb x y, -x * y = -(x * y)) };\n    propagate_tags { try { dsimp only} },\n  case [top_top, bot_top, top_bot, bot_bot] { all_goals { refl } },\n  case [top_zero, bot_zero, zero_top, zero_bot]\n  { all_goals { simp only [zero_mul, mul_zero, neg_zero] } },\n  case coe_coe : x y { norm_cast, exact neg_mul _ _, },\n  case pos_bot : x hx\n  { rw [coe_mul_bot_of_pos hx, neg_bot, \u2190 coe_neg, coe_mul_bot_of_neg (neg_neg_of_pos hx)] },\n  case neg_bot : x hx\n  { rw [coe_mul_bot_of_neg hx, neg_top, \u2190 coe_neg, coe_mul_bot_of_pos (neg_pos_of_neg hx)] },\n  case pos_top : x hx\n  { rw [coe_mul_top_of_pos hx, neg_top, \u2190 coe_neg, coe_mul_top_of_neg (neg_neg_of_pos hx)] },\n  case neg_top : x hx\n  { rw [coe_mul_top_of_neg hx, neg_bot, \u2190 coe_neg, coe_mul_top_of_pos (neg_pos_of_neg hx)] },\n  case top_pos : y hy { rw [top_mul_coe_of_pos hy, neg_top, bot_mul_coe_of_pos hy] },\n  case top_neg : y hy { rw [top_mul_coe_of_neg hy, neg_top, neg_bot, bot_mul_coe_of_neg hy] },\n  case bot_pos : y hy { rw [bot_mul_coe_of_pos hy, neg_bot, top_mul_coe_of_pos hy] },\n  case bot_neg : y hy { rw [bot_mul_coe_of_neg hy, neg_bot, neg_top, top_mul_coe_of_neg hy] },\nend\n\ninstance : has_distrib_neg ereal :=\n{ neg_mul := ereal.neg_mul,\n  mul_neg := \u03bb x y, by { rw [x.mul_comm, x.mul_comm], exact y.neg_mul x, },\n  ..ereal.has_involutive_neg }\n\n/-! ### Absolute value -/\n\n/-- The absolute value from `ereal` to `\u211d\u22650\u221e`, mapping `\u22a5` and `\u22a4` to `\u22a4` and\na real `x` to `|x|`. -/\nprotected def abs : ereal \u2192 \u211d\u22650\u221e\n| \u22a5 := \u22a4\n| \u22a4 := \u22a4\n| (x : \u211d) := ennreal.of_real (|x|)\n\n@[simp] lemma abs_top : (\u22a4 : ereal).abs = \u22a4 := rfl\n@[simp] lemma abs_bot : (\u22a5 : ereal).abs = \u22a4 := rfl\n\nlemma abs_def (x : \u211d) : (x : ereal).abs = ennreal.of_real (|x|) := rfl\n\nlemma abs_coe_lt_top (x : \u211d) : (x : ereal).abs < \u22a4 :=\nennreal.of_real_lt_top\n\n@[simp] lemma abs_eq_zero_iff {x : ereal} : x.abs = 0 \u2194 x = 0 :=\nbegin\n  induction x using ereal.rec,\n  { simp only [abs_bot, ennreal.top_ne_zero, bot_ne_zero] },\n  { simp only [ereal.abs, coe_eq_zero, ennreal.of_real_eq_zero, abs_nonpos_iff] },\n  { simp only [abs_top, ennreal.top_ne_zero, top_ne_zero] }\nend\n\n@[simp] lemma abs_zero : (0 : ereal).abs = 0 :=\nby rw [abs_eq_zero_iff]\n\n@[simp] lemma coe_abs (x : \u211d) : ((x : ereal).abs : ereal) = (|x| : \u211d) :=\nby rcases lt_trichotomy 0 x with hx | rfl | hx; simp [abs_def]\n\n@[simp] lemma abs_mul (x y : ereal) : (x * y).abs = x.abs * y.abs :=\nbegin\n   -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n  with_cases\n  { apply @induction\u2082 (\u03bb x y, (x * y).abs = x.abs * y.abs) };\n    propagate_tags { try { dsimp only} },\n  case [top_top, bot_top, top_bot, bot_bot] { all_goals { refl } },\n  case [top_zero, bot_zero, zero_top, zero_bot] { all_goals { simp only [zero_mul, mul_zero,\n                                                                         abs_zero] } },\n  case coe_coe : x y { simp only [\u2190 coe_mul, ereal.abs, abs_mul,\n                                  ennreal.of_real_mul (abs_nonneg _)], },\n  case pos_bot : x hx { simp only [coe_mul_bot_of_pos hx, hx.ne', abs_bot, with_top.mul_top, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff] },\n  case neg_bot : x hx { simp only [coe_mul_bot_of_neg hx, hx.ne, abs_bot, with_top.mul_top, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff, abs_top] },\n  case pos_top : x hx { simp only [coe_mul_top_of_pos hx, hx.ne', with_top.mul_top, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff, abs_top] },\n  case neg_top : x hx { simp only [coe_mul_top_of_neg hx, hx.ne, abs_bot, with_top.mul_top, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff, abs_top] },\n  case top_pos : y hy { simp only [top_mul_coe_of_pos hy, hy.ne', with_top.top_mul, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff, abs_top] },\n  case top_neg : y hy { simp only [top_mul_coe_of_neg hy, hy.ne, abs_bot, with_top.top_mul, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff, abs_top] },\n  case bot_pos : y hy { simp only [bot_mul_coe_of_pos hy, hy.ne', abs_bot, with_top.top_mul, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff] },\n  case bot_neg : y hy { simp only [bot_mul_coe_of_neg hy, hy.ne, abs_bot, with_top.top_mul, ne.def,\n                                   abs_eq_zero_iff, coe_eq_zero, not_false_iff, abs_top] },\nend\n\n/-! ### Sign -/\n\n@[simp] lemma sign_top : sign (\u22a4 : ereal) = 1 := rfl\n@[simp] lemma sign_bot : sign (\u22a5 : ereal) = -1 := rfl\n@[simp] lemma sign_coe (x : \u211d) : sign (x : ereal) = sign x :=\nby simp only [sign, order_hom.coe_fun_mk, ereal.coe_pos, ereal.coe_neg']\n\n@[simp] lemma sign_mul (x y : ereal) : sign (x * y) = sign x * sign y :=\nbegin\n   -- TODO: replace with `induction using` in Lean 4, which supports multiple premises\n  with_cases\n  { apply @induction\u2082 (\u03bb x y, sign (x * y) = sign x * sign y) };\n    propagate_tags { try { dsimp only} },\n  case [top_top, bot_top, top_bot, bot_bot] { all_goals { refl } },\n  case [top_zero, bot_zero, zero_top, zero_bot] { all_goals { simp only [zero_mul, mul_zero,\n                                                                         sign_zero] } },\n  case coe_coe : x y { simp only [\u2190 coe_mul, sign_coe, sign_mul], },\n  case pos_bot : x hx { simp_rw [coe_mul_bot_of_pos hx, sign_coe, sign_pos hx, one_mul] },\n  case neg_bot : x hx { simp_rw [coe_mul_bot_of_neg hx, sign_coe, sign_neg hx, sign_top, sign_bot,\n                                 neg_one_mul, neg_neg] },\n  case pos_top : x hx { simp_rw [coe_mul_top_of_pos hx, sign_coe, sign_pos hx, one_mul] },\n  case neg_top : x hx { simp_rw [coe_mul_top_of_neg hx, sign_coe, sign_neg hx, sign_top, sign_bot,\n                                 mul_one] },\n  case top_pos : y hy { simp_rw [top_mul_coe_of_pos hy, sign_coe, sign_pos hy, mul_one] },\n  case top_neg : y hy { simp_rw [top_mul_coe_of_neg hy, sign_coe, sign_neg hy, sign_top, sign_bot,\n                                 one_mul] },\n  case bot_pos : y hy { simp_rw [bot_mul_coe_of_pos hy, sign_coe, sign_pos hy, mul_one] },\n  case bot_neg : y hy { simp_rw [bot_mul_coe_of_neg hy, sign_coe, sign_neg hy, sign_top, sign_bot,\n                                 neg_one_mul, neg_neg] },\nend\n\nlemma sign_mul_abs (x : ereal) :\n  (sign x * x.abs : ereal) = x :=\nbegin\n  induction x using ereal.rec,\n  { simp },\n  { rcases lt_trichotomy 0 x with hx | rfl | hx,\n    { simp [sign_pos hx, abs_of_pos hx] },\n    { simp },\n    { simp [sign_neg hx, abs_of_neg hx] } },\n  { simp }\nend\n\nlemma sign_eq_and_abs_eq_iff_eq {x y : ereal} :\n  (x.abs = y.abs \u2227 sign x = sign y) \u2194 x = y :=\nbegin\n  split,\n  { rintros \u27e8habs, hsign\u27e9, rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs, habs, hsign] },\n  { rintros rfl, simp only [eq_self_iff_true, and_self] }\nend\n\nlemma le_iff_sign {x y : ereal} :\n  x \u2264 y \u2194 sign x < sign y \u2228\n    sign x = sign_type.neg \u2227 sign y = sign_type.neg \u2227 y.abs \u2264 x.abs \u2228\n    sign x = sign_type.zero \u2227 sign y = sign_type.zero \u2228\n    sign x = sign_type.pos \u2227 sign y = sign_type.pos \u2227 x.abs \u2264 y.abs :=\nbegin\n  split,\n  { intro h,\n    rcases (sign.monotone h).lt_or_eq with hs | hs,\n    { exact or.inl hs },\n    { rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs] at h,\n      cases sign y; rw [hs] at *,\n      { simp },\n      { simp at \u22a2 h, exact or.inl h },\n      { simpa using h, }, }, },\n  { rintros (h | h | h | h), { exact (sign.monotone.reflect_lt h).le, },\n    all_goals { rw [\u2190 x.sign_mul_abs, \u2190 y.sign_mul_abs], simp [h] } }\nend\n\ninstance : comm_monoid_with_zero ereal :=\n{ mul_assoc := \u03bb x y z, begin\n    rw [\u2190 sign_eq_and_abs_eq_iff_eq],\n    simp only [mul_assoc, abs_mul, eq_self_iff_true, sign_mul, and_self],\n  end,\n  mul_comm := ereal.mul_comm,\n  ..ereal.has_mul, ..ereal.has_one, ..ereal.has_zero, ..ereal.mul_zero_one_class }\n\ninstance : pos_mul_mono ereal :=\npos_mul_mono_iff_covariant_pos.2 \u27e8begin\n  rintros \u27e8x, x0\u27e9 a b h, dsimp,\n  rcases le_iff_sign.mp h with h | h | h | h,\n  { rw [le_iff_sign], left, simp [sign_pos x0, h] },\n  all_goals { rw [\u2190 x.sign_mul_abs, \u2190 a.sign_mul_abs, \u2190 b.sign_mul_abs, sign_pos x0],\n    simp only [h], dsimp,\n    simp only [neg_mul, mul_neg, ereal.neg_le_neg_iff, one_mul, le_refl, zero_mul, mul_zero] },\n  all_goals { norm_cast, exact mul_le_mul_left' h.2.2 _, },\nend\u27e9\ninstance : mul_pos_mono ereal := pos_mul_mono_iff_mul_pos_mono.1 ereal.pos_mul_mono\ninstance : pos_mul_reflect_lt ereal := pos_mul_mono.to_pos_mul_reflect_lt\ninstance : mul_pos_reflect_lt ereal := mul_pos_mono.to_mul_pos_reflect_lt\n\n@[simp, norm_cast] lemma coe_pow (x : \u211d) (n : \u2115) : (\u2191(x ^ n) : ereal) = x ^ n :=\nmap_pow (\u27e8coe, coe_one, coe_mul\u27e9 : \u211d \u2192* ereal) _ _\n\n@[simp, norm_cast] lemma coe_ennreal_pow (x : \u211d\u22650\u221e) (n : \u2115) : (\u2191(x ^ n) : ereal) = x ^ n :=\nmap_pow (\u27e8coe, coe_ennreal_one, coe_ennreal_mul\u27e9 : \u211d\u22650\u221e \u2192* ereal) _ _\n\nend ereal\n\nnamespace tactic\nopen positivity\n\nprivate lemma ereal_coe_ne_zero {r : \u211d} : r \u2260 0 \u2192 (r : ereal) \u2260 0 := ereal.coe_ne_zero.2\nprivate lemma ereal_coe_nonneg {r : \u211d} : 0 \u2264 r \u2192 0 \u2264 (r : ereal) := ereal.coe_nonneg.2\nprivate lemma ereal_coe_pos {r : \u211d} : 0 < r \u2192 0 < (r : ereal) := ereal.coe_pos.2\nprivate lemma ereal_coe_ennreal_pos {r : \u211d\u22650\u221e} : 0 < r \u2192 0 < (r : ereal) := ereal.coe_ennreal_pos.2\n\n/-- Extension for the `positivity` tactic: cast from `\u211d` to `ereal`. -/\n@[positivity]\nmeta def positivity_coe_real_ereal : expr \u2192 tactic strictness\n| `(@coe _ _ %%inst %%a) := do\n  unify inst `(@coe_to_lift _ _ $ @coe_base _ _ ereal.has_coe),\n  strictness_a \u2190 core a,\n  match strictness_a with\n  | positive p := positive <$> mk_app ``ereal_coe_pos [p]\n  | nonnegative p := nonnegative <$> mk_mapp ``ereal_coe_nonneg [a, p]\n  | nonzero p := nonzero <$> mk_mapp ``ereal_coe_ne_zero [a, p]\n  end\n| e := pp e >>= fail \u2218 format.bracket \"The expression \"\n         \" is not of the form `(r : ereal)` for `r : \u211d`\"\n\n/-- Extension for the `positivity` tactic: cast from `\u211d\u22650\u221e` to `ereal`. -/\n@[positivity]\nmeta def positivity_coe_ennreal_ereal : expr \u2192 tactic strictness\n| `(@coe _ _ %%inst %%a) := do\n  unify inst `(@coe_to_lift _ _ $ @coe_base _ _ ereal.has_coe_ennreal),\n  strictness_a \u2190 core a,\n  match strictness_a with\n  | positive p := positive <$> mk_app ``ereal_coe_ennreal_pos [p]\n  | _ := nonnegative <$> mk_mapp `ereal.coe_ennreal_nonneg [a]\n  end\n| e := pp e >>= fail \u2218 format.bracket \"The expression \"\n         \" is not of the form `(r : ereal)` for `r : \u211d\u22650\u221e`\"\n\nend tactic\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/real/ereal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7058869384727433}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module algebra.order.monoid.units\n! leanprover-community/mathlib commit f1a2caaf51ef593799107fe9a8d5e411599f3996\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Hom.Basic\nimport Mathlib.Order.MinMax\nimport Mathlib.Algebra.Group.Units\n\n/-!\n# Units in ordered monoids\n-/\n\n\nnamespace Units\n\n@[to_additive]\ninstance [Monoid \u03b1] [Preorder \u03b1] : Preorder \u03b1\u02e3 :=\n  Preorder.lift val\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem val_le_val [Monoid \u03b1] [Preorder \u03b1] {a b : \u03b1\u02e3} : (a : \u03b1) \u2264 b \u2194 a \u2264 b :=\n  Iff.rfl\n#align units.coe_le_coe Units.val_le_val\n#align add_units.coe_le_coe AddUnits.val_le_val\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem val_lt_val [Monoid \u03b1] [Preorder \u03b1] {a b : \u03b1\u02e3} : (a : \u03b1) < b \u2194 a < b :=\n  Iff.rfl\n#align units.coe_lt_coe Units.val_lt_val\n#align add_units.coe_lt_coe AddUnits.val_lt_val\n\n@[to_additive]\ninstance [Monoid \u03b1] [PartialOrder \u03b1] : PartialOrder \u03b1\u02e3 :=\n  PartialOrder.lift val Units.ext\n#align units.partial_order Units.instPartialOrderUnits\n#align add_units.partial_order AddUnits.instPartialOrderAddUnits\n\n@[to_additive]\ninstance [Monoid \u03b1] [LinearOrder \u03b1] : LinearOrder \u03b1\u02e3 :=\n  LinearOrder.lift' val Units.ext\n\n/-- `val : \u03b1\u02e3 \u2192 \u03b1` as an order embedding. -/\n@[to_additive (attr := simps (config := { fullyApplied := false }))\n  \"`val : add_units \u03b1 \u2192 \u03b1` as an order embedding.\"]\ndef orderEmbeddingVal [Monoid \u03b1] [LinearOrder \u03b1] : \u03b1\u02e3 \u21aao \u03b1 :=\n  \u27e8\u27e8val, ext\u27e9, Iff.rfl\u27e9\n#align units.order_embedding_coe Units.orderEmbeddingVal\n#align add_units.order_embedding_coe AddUnits.orderEmbeddingVal\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem max_val [Monoid \u03b1] [LinearOrder \u03b1] {a b : \u03b1\u02e3} : (max a b).val = max a.val b.val :=\n  Monotone.map_max orderEmbeddingVal.monotone\n#align units.max_coe Units.max_val\n#align add_units.max_coe AddUnits.max_val\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem min_val [Monoid \u03b1] [LinearOrder \u03b1] {a b : \u03b1\u02e3} : (min a b).val = min a.val b.val :=\n  Monotone.map_min orderEmbeddingVal.monotone\n#align units.min_coe Units.min_val\n#align add_units.min_coe AddUnits.min_val\n\nend Units\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Order/Monoid/Units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7058869355989031}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n\nFrom: https://github.com/leanprover-community/mathlib/blob/71b1be63560d43c689b2c1338ed1366619ce2940/src/linear_algebra/tensor_algebra/grading.lean\n-/\nimport linear_algebra.tensor_algebra.basic\n\nimport cicm2022.internal.graded_ring\n\n/-!\n# Results about the grading structure of the tensor algebra\n\nThe main result is `tensor_algebra.graded_algebra`, which says that the tensor algebra is a\n\u2115-graded algebra.\n-/\n\nnamespace tensor_algebra\nvariables {R M : Type*} [comm_semiring R] [add_comm_monoid M] [module R M]\n\nopen_locale direct_sum\n\nvariables (R M)\n\n/-- A version of `tensor_algebra.\u03b9` that maps directly into the graded structure. This is\nprimarily an auxiliary construction used to provide `tensor_algebra.graded_algebra`. -/\ndef graded_algebra.\u03b9 : M \u2192\u2097[R] \u2a01 i : \u2115, \u21a5((\u03b9 R : M \u2192\u2097[_] _).range ^ i) :=\ndirect_sum.lof R \u2115 (\u03bb i, \u21a5((\u03b9 R : M \u2192\u2097[_] _).range ^ i)) 1\n  \u2218\u2097 (\u03b9 R).cod_restrict _ (\u03bb m, by simpa only [pow_one] using linear_map.mem_range_self _ m)\n\nlemma graded_algebra.\u03b9_apply (m : M) :\n  graded_algebra.\u03b9 R M m =\n    direct_sum.of (\u03bb i, \u21a5((\u03b9 R : M \u2192\u2097[_] _).range ^ i)) 1\n      (\u27e8\u03b9 R m, by simpa only [pow_one] using linear_map.mem_range_self _ m\u27e9) := rfl\n\nvariables {R M}\n\n/-- The tensor algebra is graded by the powers of the submodule `(tensor_algebra.\u03b9 R).range`. -/\ninstance graded_algebra :\n  graded_algebra ((^) (\u03b9 R : M \u2192\u2097[R] tensor_algebra R M).range : \u2115 \u2192 submodule R _) :=\ngraded_algebra.of_alg_hom _\n  (lift _ $ graded_algebra.\u03b9 R M)\n  (begin\n    ext m,\n    dsimp only [linear_map.comp_apply, alg_hom.to_linear_map_apply, alg_hom.comp_apply,\n      alg_hom.id_apply],\n    rw [lift_\u03b9_apply, graded_algebra.\u03b9_apply, direct_sum.coe_alg_hom_of, subtype.coe_mk],\n  end)\n  (\u03bb i x, begin\n    cases x with x hx,\n    dsimp only [subtype.coe_mk, direct_sum.lof_eq_of],\n    refine submodule.pow_induction_on_left' _\n      (\u03bb r, _) (\u03bb x y i hx hy ihx ihy, _) (\u03bb m hm i x hx ih, _) hx,\n    { rw [alg_hom.commutes, direct_sum.algebra_map_apply], refl },\n    { rw [alg_hom.map_add, ihx, ihy, \u2190map_add], refl },\n    { obtain \u27e8_, rfl\u27e9 := hm,\n      rw [alg_hom.map_mul, ih, lift_\u03b9_apply, graded_algebra.\u03b9_apply, direct_sum.of_mul_of],\n      exact direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext (add_comm _ _) rfl) }\n  end)\n\nend tensor_algebra", "meta": {"author": "eric-wieser", "repo": "lean-graded-rings", "sha": "53bccd2553ee2052907ff9519e63f1945e6add4c", "save_path": "github-repos/lean/eric-wieser-lean-graded-rings", "path": "github-repos/lean/eric-wieser-lean-graded-rings/lean-graded-rings-53bccd2553ee2052907ff9519e63f1945e6add4c/src/cicm2022/examples/tensor_algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7058869260223908}}
{"text": "/-\nCopyright (c) 2020 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Lacker, Bryan Gin-ge Chen\n-/\nimport data.nat.prime\nimport data.int.basic\n/-!\n# Lemmas about nat.prime using `int`s\n-/\n\nopen nat\n\nnamespace int\n\nlemma not_prime_of_int_mul {a b : \u2124} {c : \u2115}\n  (ha : 1 < a.nat_abs) (hb : 1 < b.nat_abs) (hc : a*b = (c : \u2124)) : \u00ac prime c :=\nnot_prime_mul' (nat_abs_mul_nat_abs_eq hc) ha hb\n\nend int\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/int/nat_prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.7058570506007911}}
{"text": "import linear_algebra.free_module\n\nsection pid_module\n\nvariables {\u03b9 : Type*} {R : Type*} [integral_domain R] [is_principal_ideal_ring R]\nvariables {M  : Type*} [add_comm_group M] [module R M] {b : \u03b9 \u2192 M}\n\n-- Theorem 2.10 from Conrad (page 5)\ntheorem theorem_2_10\n  (n m : \u2115)\n  (bM : fin m \u2192 M)\n  (freeM : is_basis R bM) -- M is a free R-module of rank m\n  (N : submodule R M)\n  (bN : fin n \u2192 N)\n  (freeN : is_basis R bN) -- N is a submodule of M of rank n\n  (rank_le : n \u2264 m)       -- of smaller rank (that is always true)\n  (nonzero : 0 < n)       -- N is nonzero\n   : \u2203 (bM' : fin m \u2192 M)  -- there exists a basis of M\n       (bN' : fin n \u2192 N)  -- there exists a basis of N\n       (a : fin n \u2192 R),   -- and a list of coefficients\n      is_basis R bN' \u2227    -- bN' is a basis of N\n      \u2200 i : fin n, \u2191(bN' i) = a i \u2022 bM' (fin.cast_le rank_le i) \u2227 -- s.t. (bN' i) is a scalar multiple of (bN i) \n      \u2200 i : fin n.pred, a (fin.cast_le (nat.pred_le n) i) \u2223\n                       a (fin.cast (nat.succ_pred_eq_of_pos nonzero) i.succ) -- a i divides a (i+1) for all i < n\n        :=\nbegin\n  sorry,\nend\n\nend pid_module\n", "meta": {"author": "Xerz", "repo": "pid", "sha": "99f00c0a809112d02abe8582c2f7b3a70fb3840a", "save_path": "github-repos/lean/Xerz-pid", "path": "github-repos/lean/Xerz-pid/pid-99f00c0a809112d02abe8582c2f7b3a70fb3840a/src/pid_module.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7057846625000439}}
{"text": "\nvariable U : Type \nvariable A : U -> Prop \nsection\nexample : (\u00ac \u2203 x, A x) \u2192 \u2200 x, \u00ac A x :=\nassume h1: \u00ac \u2203 x, A x,\nshow \u2200 x, \u00ac A x,from \nassume t,\nassume h2: A t,\nshow false, from h1 (exists.intro t h2)\nend \nsection \nexample : (\u2200 x, \u00ac A x) \u2192 \u00ac \u2203 x, A x :=\nassume h1: \u2200 x, \u00ac A x,\nassume h2: \u2203 x, A x,\nexists.elim h2 $\nassume t (h3: A t),\nshow false, from (h1 t) h3\nend ", "meta": {"author": "ucmani", "repo": "leanexamples", "sha": "387daef46eaf61bd4a08db076f60ac237daff559", "save_path": "github-repos/lean/ucmani-leanexamples", "path": "github-repos/lean/ucmani-leanexamples/leanexamples-387daef46eaf61bd4a08db076f60ac237daff559/example.9.5.8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693716759489, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.7057638957886812}}
{"text": "import data.nat.basic\nimport data.real.basic\nimport order.basic\n\n/- IMO 2007 Problem 1\n\nGiven a sequence a\u2081, a\u2082, ... a\u2099 of real numbers. For each i (1\u2264i\u2264n) define\n\n                 d\u1d62 = max { a\u2c7c : 1\u2264j\u2264i } - min { a\u2c7c : i\u2264j\u2264n }\n\nand let\n\n                 d = max { d\u1d62 : 1\u2264i\u2264n }.\n\n(a) Prove that for arbitrary real numbers x\u2081 \u2264 x\u2082 \u2264 ... \u2264 x\u2099,\n\n                 max { |x\u1d62 - a\u1d62| : 1\u2264i\u2264n } \u2265 d/2.       (1)\n\n(b) Show that there exists a sequence x\u2081 \u2264 x\u2082 \u2264 ... \u2264 x\u2099 of real numbers\nsuch that we have equality in (1).\n\n-/\n\nlemma lemma_1 {x y z: \u211d} (h: z \u2264 x + y) : z / 2 \u2264 x \u2228 z / 2 \u2264 y :=\nbegin\n  by_contra H,\n  push_neg at H,\n  obtain \u27e8h1, h2\u27e9 := H,\n  linarith,\nend\n\nnoncomputable def xx_seq (a: \u2115 \u2192 \u211d) : \u2115 \u2192 \u211d\n | 0 := a 0\n | m@(nat.succ k) := max (xx_seq k) (a m)\n\nlemma xx_seq_monotone (a: \u2115 \u2192 \u211d) : monotone (xx_seq a) :=\nbegin\n  have h: \u2200 n, xx_seq a n \u2264 xx_seq a (nat.succ n),\n  {\n    intro n,\n    unfold xx_seq,\n    exact le_max_left (xx_seq a n) (a (nat.succ n)),\n  },\n  exact monotone_nat_of_le_succ h,\nend\n\nlemma monotone_fin_of_nat {n : \u2115} (f: \u2115 \u2192 \u211d) (h : monotone f) : monotone (\u03bb m: fin n, f m.val) :=\nbegin\n  intros m1 m2 hm,\n  exact h hm,\nend\n\nnoncomputable def x_seq' {n : \u2115} (d: \u211d) (a: fin n \u2192 \u211d) : \u2115 \u2192 \u211d :=\nxx_seq (\u03bbm, if h: m < n then (a \u27e8m, h\u27e9 - d/2) else 0)\n\nnoncomputable def x_seq {n : \u2115} (d : \u211d) (a: fin n \u2192 \u211d) : fin n \u2192 \u211d :=\n\u03bb m, x_seq' d a m.val\n\nlemma x_seq_monotone {n : \u2115} (d : \u211d) (a : fin n \u2192 \u211d) : monotone (x_seq d a) :=\nbegin\n  exact monotone_fin_of_nat (x_seq' d a) (xx_seq_monotone _),\nend\n\ntheorem imo2007_q1\n  (n : \u2115)\n  (a b c d: fin n \u2192 \u211d)\n  (hb : \u2200i: fin n, is_greatest {x : \u211d | \u2203 j : fin n, j \u2264 i \u2227 x = a j } (b i))\n  (hc : \u2200i: fin n, is_least {x : \u211d | \u2203 j : fin n, i \u2264 j \u2227 x = a j } (c i))\n  (hd : \u2200i: fin n, d i = b i - c i )\n  (dm : \u211d)\n  (hdm : is_greatest {x : \u211d | \u2203 i : fin n, x = d i} dm)\n  : (\u2200 x: fin n \u2192 \u211d, monotone x \u2192 \u2203 i : fin n, dm / 2 \u2264 abs (x i - a i) )\n    \u2227 (\u2203 x: fin n \u2192 \u211d, monotone x \u2227\n         (\u2203 i : fin n, dm / 2 = abs (x i - a i))\n        \u2227 \u2200 i : fin n, abs (x i - a i) \u2264 dm / 2) :=\nbegin\n  obtain \u27e8\u27e8q, hq\u27e9, hqq\u27e9 := hdm,\n  obtain \u27e8\u27e8p, hp, hp1\u27e9, hpp\u27e9 := hb q,\n  obtain \u27e8\u27e8r, hr, hr1\u27e9, hrr\u27e9 := hc q,\n  have hpr := le_trans hp hr,\n  have hdi := hd q,\n  split,\n  { intros x x_mono,\n\n    have h0 : 0 \u2264 x r - x p := sub_nonneg.mpr (x_mono hpr),\n\n    have h1 := calc dm\n         = a p - a r : by {sorry}\n     ... \u2264 (a p - a r) + (x r - x p) : le_add_of_nonneg_right h0\n     ... = (a p - x p) + (x r - a r) : by ring,\n\n    obtain hpm | hrm := lemma_1 h1,\n    { use p,\n      calc dm / 2 \u2264 a p - x p : hpm\n              ... \u2264 abs (a p - x p) : le_abs_self _\n              ... = abs (x p - a p) : abs_sub_comm _ _ },\n    { use r,\n      calc dm / 2 \u2264 x r - a r : hrm\n              ... \u2264 abs (x r - a r) : le_abs_self _ }\n  },\n  {\n    use x_seq dm a,\n    split,\n    { exact x_seq_monotone dm a, },\n    { split,\n      { sorry },\n      { sorry },\n    },\n  },\nend\n\n", "meta": {"author": "dwrensha", "repo": "math-puzzles-in-lean", "sha": "5f27604e4dc4ba97c346a65ce502c64566249269", "save_path": "github-repos/lean/dwrensha-math-puzzles-in-lean", "path": "github-repos/lean/dwrensha-math-puzzles-in-lean/math-puzzles-in-lean-5f27604e4dc4ba97c346a65ce502c64566249269/src/imo2007_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7056284730078567}}
{"text": "/-\nCopyright (c) S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.analysis.calculus.times_cont_diff\nimport Mathlib.analysis.complex.basic\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-! # Real differentiability of complex-differentiable functions\n\n`has_deriv_at.real_of_complex` expresses that, if a function on `\u2102` is differentiable (over `\u2102`),\nthen its restriction to `\u211d` is differentiable over `\u211d`, with derivative the real part of the\ncomplex derivative.\n-/\n\n/-! ### Differentiability of the restriction to `\u211d` of complex functions -/\n\n/-- If a complex function is differentiable at a real point, then the induced real function is also\ndifferentiable at this point, with a derivative equal to the real part of the complex derivative. -/\ntheorem has_deriv_at.real_of_complex {e : \u2102 \u2192 \u2102} {e' : \u2102} {z : \u211d} (h : has_deriv_at e e' \u2191z) : has_deriv_at (fun (x : \u211d) => complex.re (e \u2191x)) (complex.re e') z := sorry\n\ntheorem times_cont_diff_at.real_of_complex {e : \u2102 \u2192 \u2102} {z : \u211d} {n : with_top \u2115} (h : times_cont_diff_at \u2102 n e \u2191z) : times_cont_diff_at \u211d n (fun (x : \u211d) => complex.re (e \u2191x)) z := sorry\n\ntheorem times_cont_diff.real_of_complex {e : \u2102 \u2192 \u2102} {n : with_top \u2115} (h : times_cont_diff \u2102 n e) : times_cont_diff \u211d n fun (x : \u211d) => complex.re (e \u2191x) :=\n  iff.mpr times_cont_diff_iff_times_cont_diff_at\n    fun (x : \u211d) => times_cont_diff_at.real_of_complex (times_cont_diff.times_cont_diff_at h)\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/analysis/complex/real_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.798186784940666, "lm_q1q2_score": 0.7056284720581218}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Bhavik Mehta\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.basic\nimport Mathlib.order.preorder_hom\nimport Mathlib.order.galois_connection\nimport Mathlib.tactic.monotonicity.default\nimport Mathlib.PostPort\n\nuniverses u l \n\nnamespace Mathlib\n\n/-!\n# Closure operators on a partial order\n\nWe define (bundled) closure operators on a partial order as an monotone (increasing), extensive\n(inflationary) and idempotent function.\nWe define closed elements for the operator as elements which are fixed by it.\n\nNote that there is close connection to Galois connections and Galois insertions: every closure\noperator induces a Galois insertion (from the set of closed elements to the underlying type), and\nevery Galois connection induces a closure operator (namely the composition). In particular,\na Galois insertion can be seen as a general case of a closure operator, where the inclusion is given\nby coercion, see `closure_operator.gi`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets\n\n-/\n\n/--\nA closure operator on the partial order `\u03b1` is a monotone function which is extensive (every `x`\nis less than its closure) and idempotent.\n-/\nstructure closure_operator (\u03b1 : Type u) [partial_order \u03b1] \nextends \u03b1 \u2192\u2098 \u03b1\nwhere\n  le_closure' : \u2200 (x : \u03b1), x \u2264 preorder_hom.to_fun _to_preorder_hom x\n  idempotent' : \u2200 (x : \u03b1),\n  preorder_hom.to_fun _to_preorder_hom (preorder_hom.to_fun _to_preorder_hom x) = preorder_hom.to_fun _to_preorder_hom x\n\nprotected instance closure_operator.has_coe_to_fun (\u03b1 : Type u) [partial_order \u03b1] : has_coe_to_fun (closure_operator \u03b1) :=\n  has_coe_to_fun.mk (fun (c : closure_operator \u03b1) => \u03b1 \u2192 \u03b1)\n    fun (c : closure_operator \u03b1) => preorder_hom.to_fun (closure_operator.to_preorder_hom c)\n\nnamespace closure_operator\n\n\n/-- The identity function as a closure operator. -/\n@[simp] theorem id_to_preorder_hom_to_fun (\u03b1 : Type u) [partial_order \u03b1] (x : \u03b1) : coe_fn (to_preorder_hom (id \u03b1)) x = x :=\n  Eq.refl (coe_fn (to_preorder_hom (id \u03b1)) x)\n\nprotected instance inhabited (\u03b1 : Type u) [partial_order \u03b1] : Inhabited (closure_operator \u03b1) :=\n  { default := id \u03b1 }\n\ntheorem ext {\u03b1 : Type u} [partial_order \u03b1] (c\u2081 : closure_operator \u03b1) (c\u2082 : closure_operator \u03b1) : \u21d1c\u2081 = \u21d1c\u2082 \u2192 c\u2081 = c\u2082 := sorry\n\n/-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) \u2264 f x`. -/\ndef mk' {\u03b1 : Type u} [partial_order \u03b1] (f : \u03b1 \u2192 \u03b1) (hf\u2081 : monotone f) (hf\u2082 : \u2200 (x : \u03b1), x \u2264 f x) (hf\u2083 : \u2200 (x : \u03b1), f (f x) \u2264 f x) : closure_operator \u03b1 :=\n  mk (preorder_hom.mk f hf\u2081) hf\u2082 sorry\n\n/--\ntheorem monotone {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) : monotone \u21d1c :=\n  preorder_hom.monotone' (to_preorder_hom c)\n\nEvery element is less than its closure. This property is sometimes referred to as extensivity or\ninflationary.\n-/\ntheorem le_closure {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) : x \u2264 coe_fn c x :=\n  le_closure' c x\n\n@[simp] theorem idempotent {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) : coe_fn c (coe_fn c x) = coe_fn c x :=\n  idempotent' c x\n\ntheorem le_closure_iff {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) (y : \u03b1) : x \u2264 coe_fn c y \u2194 coe_fn c x \u2264 coe_fn c y :=\n  { mp := fun (h : x \u2264 coe_fn c y) => idempotent c y \u25b8 monotone c h,\n    mpr := fun (h : coe_fn c x \u2264 coe_fn c y) => le_trans (le_closure c x) h }\n\ntheorem closure_top {\u03b1 : Type u} [order_top \u03b1] (c : closure_operator \u03b1) : coe_fn c \u22a4 = \u22a4 :=\n  le_antisymm le_top (le_closure c \u22a4)\n\ntheorem closure_inter_le {\u03b1 : Type u} [semilattice_inf \u03b1] (c : closure_operator \u03b1) (x : \u03b1) (y : \u03b1) : coe_fn c (x \u2293 y) \u2264 coe_fn c x \u2293 coe_fn c y :=\n  le_inf (monotone c inf_le_left) (monotone c inf_le_right)\n\ntheorem closure_union_closure_le {\u03b1 : Type u} [semilattice_sup \u03b1] (c : closure_operator \u03b1) (x : \u03b1) (y : \u03b1) : coe_fn c x \u2294 coe_fn c y \u2264 coe_fn c (x \u2294 y) :=\n  sup_le (monotone c le_sup_left) (monotone c le_sup_right)\n\n/-- An element `x` is closed for the closure operator `c` if it is a fixed point for it. -/\ndef closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) : set \u03b1 :=\n  fun (x : \u03b1) => coe_fn c x = x\n\ntheorem mem_closed_iff {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) : x \u2208 closed c \u2194 coe_fn c x = x :=\n  iff.rfl\n\ntheorem mem_closed_iff_closure_le {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) : x \u2208 closed c \u2194 coe_fn c x \u2264 x :=\n  { mp := le_of_eq, mpr := fun (h : coe_fn c x \u2264 x) => le_antisymm h (le_closure c x) }\n\ntheorem closure_eq_self_of_mem_closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) {x : \u03b1} (h : x \u2208 closed c) : coe_fn c x = x :=\n  h\n\n@[simp] theorem closure_is_closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) : coe_fn c x \u2208 closed c :=\n  idempotent c x\n\n/-- The set of closed elements for `c` is exactly its range. -/\ntheorem closed_eq_range_close {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) : closed c = set.range \u21d1c := sorry\n\n/-- Send an `x` to an element of the set of closed elements (by taking the closure). -/\ndef to_closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) : \u21a5(closed c) :=\n  { val := coe_fn c x, property := closure_is_closed c x }\n\ntheorem top_mem_closed {\u03b1 : Type u} [order_top \u03b1] (c : closure_operator \u03b1) : \u22a4 \u2208 closed c :=\n  closure_top c\n\ntheorem closure_le_closed_iff_le {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) {x : \u03b1} {y : \u03b1} (hy : closed c y) : x \u2264 y \u2194 coe_fn c x \u2264 y :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (x \u2264 y \u2194 coe_fn c x \u2264 y)) (Eq.symm (closure_eq_self_of_mem_closed c hy))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (x \u2264 coe_fn c y \u2194 coe_fn c x \u2264 coe_fn c y)) (propext (le_closure_iff c x y))))\n      (iff.refl (coe_fn c x \u2264 coe_fn c y)))\n\n/-- The set of closed elements has a Galois insertion to the underlying type. -/\ndef gi {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) : galois_insertion (to_closed c) coe :=\n  galois_insertion.mk (fun (x : \u03b1) (hx : \u2191(to_closed c x) \u2264 x) => { val := x, property := sorry }) sorry sorry sorry\n\nend closure_operator\n\n\n/--\nEvery Galois connection induces a closure operator given by the composition. This is the partial\norder version of the statement that every adjunction induces a monad.\n-/\n@[simp] theorem galois_connection.closure_operator_to_preorder_hom_to_fun {\u03b1 : Type u} [partial_order \u03b1] {\u03b2 : Type u} [preorder \u03b2] {l : \u03b1 \u2192 \u03b2} {u : \u03b2 \u2192 \u03b1} (gc : galois_connection l u) (x : \u03b1) : coe_fn (closure_operator.to_preorder_hom (galois_connection.closure_operator gc)) x = u (l x) :=\n  Eq.refl (coe_fn (closure_operator.to_preorder_hom (galois_connection.closure_operator gc)) x)\n\n/--\nThe Galois insertion associated to a closure operator can be used to reconstruct the closure\noperator.\n\nNote that the inverse in the opposite direction does not hold in general.\n-/\n@[simp] theorem closure_operator_gi_self {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) : galois_connection.closure_operator (galois_insertion.gc (closure_operator.gi c)) = c := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/closure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7056284620812675}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport order.filter.basic\n\n/-!\n# Filtros\nLa definici\u00f3n de `filtro` en Lean es la siguiente:\n\nstructure filter (\u03b1 : Type*) :=\n(sets                   : set (set \u03b1))\n(univ_sets              : set.univ \u2208 sets)\n(sets_of_superset {x y} : x \u2208 sets \u2192 x \u2286 y \u2192 y \u2208 sets)\n(inter_sets {x y}       : x \u2208 sets \u2192 y \u2208 sets \u2192 x \u2229 y \u2208 sets)\n\n\n## Notaci\u00f3n y resultados \u00fatiles.\n\nFijamos `\u03b1 : Type`, `F : filter \u03b1` y `S : set \u03b1`.\n\nPor definici\u00f3n, la notaci\u00f3n `S \u2208 F` significa `S \u2208 F.sets`. \n(La intuici\u00f3n es `F \u2286 S`, aunque por supuesto esto no tiene\nsentido porque `F` es un filtro, no un subconjunto).\n\nDos filtros `F` y `G` son iguales si y s\u00f3lo si \n`\u2200 S, S \u2208 F \u2194 S \u2208 G`. \n\nLos lemas correspondientes a las condiciones que\naparecen en la definici\u00f3n de filtro son:\n\n`univ_mem : univ \u2208 F`\n`mem_of_superset : S \u2208 F \u2192 S \u2286 T \u2192 T \u2208 F`\n`inter_mem : S \u2208 F \u2192 T \u2208 F \u2192 S \u2229 T \u2208 F`\n\nEstos lemas est\u00e1n en el espacio de nombres `filter`.\n-/\n\n-- Abrimos los espacios de nombres `filter` y `set`.\nopen filter set \n\n--  Sea `\u03b1` un tipo, `F` un filtro sobre `\u03b1`, y `S` y `T` dos subconjuntos de `\u03b1`.\nvariables (\u03b1 : Type) (F : filter \u03b1) (S T : set \u03b1)\n\n/-\nDos subconjuntos `S` y `T` est\u00e1n en un filtro `F` si y s\u00f3lo\nsi su intersecci\u00f3n est\u00e1 en `F`.\n\nLos lemas `inter_subset_left S T : S \u2229 T \u2286 S` e `inter_subset_right S T : S \u2229 T \u2286 S`\nson \u00fatiles para esta demostraci\u00f3n.\n-/\nexample : S \u2229 T \u2208 F \u2194 S \u2208 F \u2227 T \u2208 F :=\nbegin\n  sorry\nend\n\n/-! ## Ejemplos de filtros -/\n\n/- ### Filtros principales\nDado un subconjunto `X` de `\u03b1`, el filtro principal de `X` es la \ncolecci\u00f3n de subconjuntos de `\u03b1` que contienen `X`.\nEst\u00e1 definido en mathlib, y denotado mediante `\ud835\udcdf X`, pero en \neste ejemplo vamos a demostrar nosotros mismos que es un filtro.\n\nLemas \u00fatiles:\n`mem_univ s : s \u2208 univ`\n`subset.trans : A \u2286 B \u2192 B \u2286 C \u2192 A \u2286 C`\n`subset_inter : X \u2286 S \u2192 X \u2286 T \u2192 X \u2286 S \u2229 T`\n`mem_set_of_eq : x \u2208 {a : \u03b1 | p a} = p x`\n-/\n\n-- El filtro principal de `X`.\nexample (X : set \u03b1) : filter \u03b1 :=\n{ sets := {S : set \u03b1 | X \u2286 S},\n  univ_sets := begin\n    sorry\n  end,\n  sets_of_superset := begin\n    sorry\n  end,\n  inter_sets := begin\n    sorry\n  end }\n\n/-- ### EL filtro `at_top` en un conjunto totalmente ordenado\n\nSea `L` un conjunto linearmente ordenado no vac\u00edo.\nVamos a construir un filtro `at_top` que representa un\n\"entorno infinitesimal\" de `\u221e`. En concreto, los conjuntos \npertenecientes a este filtro ser\u00e1n aquellos `X : set L`\npara los que existe un `x : L` tal que para todo `y \u2265 x`, `y \u2208 X`.\n-/\ndef at_top (L : Type) [linear_order L] (e : L) : filter L :=\n{ sets := {X : set L | \u2203 x : L, \u2200 y, x \u2264 y \u2192 y \u2208 X},\n  univ_sets := begin\n    sorry\n  end,\n  sets_of_superset := begin\n    sorry\n  end,\n  inter_sets := begin\n    sorry\n  end }\n\n/-! ### El filtro cofinito\nEl filtro cofinito en un tipo `\u03b1` es la colecci\u00f3n de subconjuntos `S : set \u03b1`\ncon la propiedad de que el complemento `S\u1d9c`de `S` es finito.\n\nLemas \u00fatiles:\n`compl_univ : univ\u1d9c = \u2205`\n`finite_empty : finite \u2205`\n`compl_subset_compl : X\u1d9c \u2286 Y\u1d9c \u2194 Y \u2286 X`\n`finite.subset : S.finite \u2192 \u2200 {T : set \u03b1}, T \u2286 S \u2192 T.finite`\n`compl_inter S T : (S \u2229 T)\u1d9c = S\u1d9c \u222a T\u1d9c`\n`finite.union : S.finite \u2192 T.finite \u2192 (S \u222a T).finite`.\n-/\ndef cofinite (\u03b1 : Type) : filter \u03b1 :=\n{ sets := { S : set \u03b1 | (S\u1d9c).finite },\n  univ_sets := begin\n    sorry\n  end,\n  sets_of_superset := begin\n    sorry\n  end,\n  inter_sets := begin\n    sorry\n  end }\n\n-- Esta instrucci\u00f3n nos permite acceder a la notaci\u00f3n `\ud835\udcdf X` para el filtro principal\nopen_locale filter\n\n/-!\n## El orden (\u2264) sobre los filtros de `\u03b1`\nLos filtros est\u00e1n parcialmente ordenados, mediante la relaci\u00f3n `\u2264`\ndefinida mediante `F \u2264 G` si y s\u00f3lo si `G.sets \u2286 F.sets`. \n(Cuanto m\u00e1s peque\u00f1o es el filtro `F`, m\u00e1s grande es la colecci\u00f3n\n`F.sets`, ya que el \"conjunto generalizado\" `F` est\u00e1 \"contenido\"\nen m\u00e1s conjuntos).\n\nEn este ejemplo vamos a demostrar que `\ud835\udcdf S \u2264 \ud835\udcdf T \u2194 S \u2286 T`.\nEsto es lo que dice el lema `principal_mono` de mathlib,\npero vamos a demostrarlo utilizando los lemas:\n`mem_principal : T \u2208 \ud835\udcdf S \u2194 S \u2286 T`\n`mem_principal_self S : S \u2208 \ud835\udcdf S`\n`le_def : F \u2264 G \u2194 \u2200 (S : set \u03b1), S \u2208 G \u2192 S \u2208 F`\n-/\n\nexample (S T : set \u03b1) : \ud835\udcdf S \u2264 \ud835\udcdf T \u2194 S \u2286 T :=\nbegin\n  sorry\nend\n\n/- Este ejemplo se llama `le_principal_iff` en mathlib, pero podemos demostrarlo a\n  partir de las definiciones y lemas anteriores. -/\nexample (F : filter \u03b1) (S : set \u03b1) : F \u2264 \ud835\udcdf S \u2194 S \u2208 F :=\nbegin\n  sorry\nend\n", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_6/filtros.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7056284562543714}}
{"text": "/-\nCopyright (c) 2023 Bruno Bentzen. All rights reserved.\nReleased under the Apache License 2.0 (see \"License\");\nAuthor: Bruno Bentzen\n-/\n\nimport ..default \n\nopen form\n\n/- Hilbert-style axiomatization of intuitionistic propositional logic -/\n\ninductive prf : set form \u2192 form \u2192 Prop\n| ax {\u0393} {p} (h : p \u2208 \u0393) : prf \u0393 p\n| k {\u0393} {p q} : prf \u0393 (p \u2283 (q \u2283 p))\n| s {\u0393} {p q r} : prf \u0393 ((p \u2283 (q \u2283 r)) \u2283 ((p \u2283 q) \u2283 (p \u2283 r)))\n| exf {\u0393} {p} : prf \u0393 (\u22a5 \u2283 p)\n| mp {\u0393} {p q} (hpq: prf \u0393 (p \u2283 q)) (hp : prf \u0393 p) : prf \u0393 q\n| pr1 {\u0393} {p q} : prf \u0393 ((p & q) \u2283 p)\n| pr2 {\u0393} {p q} : prf \u0393 ((p & q) \u2283 q)\n| pair {\u0393} {p q} : prf \u0393 (p \u2283 (q \u2283 (p & q)))\n| inr {\u0393} {p q} : prf \u0393 (p \u2283 (p \u2228 q))\n| inl {\u0393} {p q} : prf \u0393 (q \u2283 (p \u2228 q))\n| case {\u0393} {p q r} : prf \u0393 ((p \u2283 r) \u2283 ((q \u2283 r) \u2283 ((p \u2228 q) \u2283 r)))\n\nnotation \u0393 ` \u22a2\u1d62 ` p := prf \u0393 p\nnotation \u0393 ` \u22ac\u1d62 ` p := prf \u0393 p \u2192 false\n\n/- some helpful lemmas -/\n\nnamespace prf\n\nlemma id {p : form } {\u0393 :  set form } :\n  \u0393 \u22a2\u1d62 p \u2283 p :=\nmp (mp (@s  \u0393 p (p \u2283 p) p) k) k\n\ntheorem deduction {\u0393 :  set form } {p q : form } :\n  (\u0393 \u2e34 p \u22a2\u1d62 q) \u2192 (\u0393 \u22a2\u1d62 p \u2283 q) :=\nbegin\n  generalize eq : (\u0393 \u2e34 p) = \u0393',\n  intro h,\n  induction h; subst eq,\n  { repeat {cases h_h},\n    exact id,\n    { exact mp k (ax h_h) } },\n  { exact mp k k },\n  { exact mp k s },\n  { exact mp k exf },\n  { apply mp,\n    { exact (mp s (h_ih_hpq rfl)) },\n    { exact h_ih_hp rfl } },\n  { exact mp k pr1 },\n  { exact mp k pr2 },\n  { exact mp k pair },\n  { exact mp k inr },\n  { exact mp k inl },\n  { exact mp k case }\nend\n\ntheorem contradeduction {\u0393 :  set form } {p q : form } :\n  (\u0393 \u22ac\u1d62 p \u2283 q) \u2192 (\u0393 \u2e34 p \u22ac\u1d62 q) :=\nbegin\n  intros hn h,\n  exact hn (prf.deduction h)\nend\n\n-- helpful for the compl proof\n\nlemma or_intro1 {p : form } {\u0393 :  set form } (q) :\n  (\u0393 \u22a2\u1d62 p) \u2192 (\u0393 \u22a2\u1d62 p \u2228 q) :=\nbegin\n  intros hp,\n  apply prf.mp,\n  { apply prf.inr },\n  { assumption }\nend\n\nlemma or_intro2 {q : form } {\u0393 :  set form } (p) :\n  (\u0393 \u22a2\u1d62 q) \u2192 (\u0393 \u22a2\u1d62 p \u2228 q) :=\nbegin\n  intros hp,\n  apply prf.mp,\n  { apply prf.inl },\n  { assumption }\nend\n\nlemma or_elim {p q r : form } {\u0393 :  set form } :\n  (\u0393 \u22a2\u1d62 p \u2228 q) \u2192 (\u0393 \u2e34 p \u22a2\u1d62 r) \u2192 (\u0393 \u2e34 q \u22a2\u1d62 r) \u2192 (\u0393 \u22a2\u1d62 r) :=\nbegin\n  intros hpq hp hq,\n  apply prf.mp,\n  { apply prf.mp,\n    apply prf.mp,\n    { apply prf.case,\n      exact p,\n      exact q},\n    repeat {apply deduction, assumption} },\n  { assumption }\nend\n\nlemma and_elim1 {p q : form } {\u0393 :  set form } :\n  (\u0393 \u22a2\u1d62 (p & q)) \u2192 (\u0393 \u22a2\u1d62 p) :=\nbegin\n  intros hp,\n  apply prf.mp,\n  { apply prf.pr1, exact q },\n  { assumption }\nend\n\nlemma and_elim2 {p q : form } {\u0393 :  set form } :\n  (\u0393 \u22a2\u1d62 (p & q)) \u2192 (\u0393 \u22a2\u1d62 q) :=\nbegin\n  intros hp,\n  apply prf.mp,\n  { apply prf.pr2, exact p },\n  { assumption },\nend\n\n/- structural rules -/\n\nlemma sub_weak {\u0393 \u0394 :  set form } {p : form } :\n  (\u0394 \u22a2\u1d62 p) \u2192 (\u0394 \u2286 \u0393) \u2192 (\u0393 \u22a2\u1d62 p) :=\nbegin\n  intros hp h,\n  induction hp,\n  { apply ax, exact h hp_h },\n  { exact k },\n  { exact s },\n  { exact exf },\n  { apply mp,\n    { exact hp_ih_hpq h },\n    {exact hp_ih_hp h} },\n  { exact pr1 },\n  { exact pr2 },\n  { exact pair },\n  { exact inr },\n  { exact inl },\n  { exact case }\nend\n\nend prf", "meta": {"author": "bbentzen", "repo": "ipl", "sha": "a5226c554aa3d75137ef2ebd6d20aa76883cbcfc", "save_path": "github-repos/lean/bbentzen-ipl", "path": "github-repos/lean/bbentzen-ipl/ipl-a5226c554aa3d75137ef2ebd6d20aa76883cbcfc/src/completeness/theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7056284520103672}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne, Benjamin Davidson\n-/\nimport analysis.special_functions.complex.arg\nimport analysis.special_functions.log.basic\n\n/-!\n# The complex `log` function\n\nBasic properties, relationship with `exp`.\n-/\n\nnoncomputable theory\n\nnamespace complex\n\nopen set filter\n\nopen_locale real topological_space\n\n/-- Inverse of the `exp` function. Returns values such that `(log x).im > - \u03c0` and `(log x).im \u2264 \u03c0`.\n  `log 0 = 0`-/\n@[pp_nodot] noncomputable def log (x : \u2102) : \u2102 := x.abs.log + arg x * I\n\nlemma log_re (x : \u2102) : x.log.re = x.abs.log := by simp [log]\n\nlemma log_im (x : \u2102) : x.log.im = x.arg := by simp [log]\n\nlemma neg_pi_lt_log_im (x : \u2102) : -\u03c0 < (log x).im := by simp only [log_im, neg_pi_lt_arg]\nlemma log_im_le_pi (x : \u2102) : (log x).im \u2264 \u03c0 := by simp only [log_im, arg_le_pi]\n\nlemma exp_log {x : \u2102} (hx : x \u2260 0) : exp (log x) = x :=\nby rw [log, exp_add_mul_I, \u2190 of_real_sin, sin_arg, \u2190 of_real_cos, cos_arg hx,\n  \u2190 of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,\n  mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), \u2190 mul_assoc,\n  mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]\n\n@[simp] lemma range_exp : range exp = {0}\u1d9c :=\nset.ext $ \u03bb x, \u27e8by { rintro \u27e8x, rfl\u27e9, exact exp_ne_zero x }, \u03bb hx, \u27e8log x, exp_log hx\u27e9\u27e9\n\nlemma log_exp {x : \u2102} (hx\u2081 : -\u03c0 < x.im) (hx\u2082: x.im \u2264 \u03c0) : log (exp x) = x :=\nby rw [log, abs_exp, real.log_exp, exp_eq_exp_re_mul_sin_add_cos, \u2190 of_real_exp,\n  arg_mul_cos_add_sin_mul_I (real.exp_pos _) \u27e8hx\u2081, hx\u2082\u27e9, re_add_im]\n\n\n\nlemma of_real_log {x : \u211d} (hx : 0 \u2264 x) : (x.log : \u2102) = log x :=\ncomplex.ext\n  (by rw [log_re, of_real_re, abs_of_nonneg hx])\n  (by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])\n\nlemma log_of_real_re (x : \u211d) : (log (x : \u2102)).re = real.log x := by simp [log_re]\n\n@[simp] lemma log_zero : log 0 = 0 := by simp [log]\n\n@[simp] lemma log_one : log 1 = 0 := by simp [log]\n\nlemma log_neg_one : log (-1) = \u03c0 * I := by simp [log]\n\nlemma log_I : log I = \u03c0 / 2 * I := by simp [log]\n\nlemma log_neg_I : log (-I) = -(\u03c0 / 2) * I := by simp [log]\n\nlemma two_pi_I_ne_zero : (2 * \u03c0 * I : \u2102) \u2260 0 :=\nby norm_num [real.pi_ne_zero, I_ne_zero]\n\nlemma exp_eq_one_iff {x : \u2102} : exp x = 1 \u2194 \u2203 n : \u2124, x = n * ((2 * \u03c0) * I) :=\nbegin\n  split,\n  { intro h,\n    rcases exists_unique_add_zsmul_mem_Ioc real.two_pi_pos x.im (-\u03c0) with \u27e8n, hn, -\u27e9,\n    use -n,\n    rw [int.cast_neg, neg_mul, eq_neg_iff_add_eq_zero],\n    have : (x + n * (2 * \u03c0 * I)).im \u2208 Ioc (-\u03c0) \u03c0, by simpa [two_mul, mul_add] using hn,\n    rw [\u2190 log_exp this.1 this.2, exp_periodic.int_mul n, h, log_one] },\n  { rintro \u27e8n, rfl\u27e9, exact (exp_periodic.int_mul n).eq.trans exp_zero }\nend\n\nlemma exp_eq_exp_iff_exp_sub_eq_one {x y : \u2102} : exp x = exp y \u2194 exp (x - y) = 1 :=\nby rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]\n\nlemma exp_eq_exp_iff_exists_int {x y : \u2102} : exp x = exp y \u2194 \u2203 n : \u2124, x = y + n * ((2 * \u03c0) * I) :=\nby simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']\n\n@[simp] lemma countable_preimage_exp {s : set \u2102} : (exp \u207b\u00b9' s).countable \u2194 s.countable :=\nbegin\n  refine \u27e8\u03bb hs, _, \u03bb hs, _\u27e9,\n  { refine ((hs.image exp).insert 0).mono _,\n    rw [image_preimage_eq_inter_range, range_exp, \u2190 diff_eq, \u2190 union_singleton, diff_union_self],\n    exact subset_union_left _ _ },\n  { rw \u2190 bUnion_preimage_singleton,\n    refine hs.bUnion (\u03bb z hz, _),\n    rcases em (\u2203 w, exp w = z) with \u27e8w, rfl\u27e9|hne,\n    { simp only [preimage, mem_singleton_iff, exp_eq_exp_iff_exists_int, set_of_exists],\n      exact countable_Union (\u03bb m, countable_singleton _) },\n    { push_neg at hne, simp [preimage, hne] } }\nend\n\nalias countable_preimage_exp \u2194 _ set.countable.preimage_cexp\n\nlemma tendsto_log_nhds_within_im_neg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto log (\ud835\udcdd[{z : \u2102 | z.im < 0}] z) (\ud835\udcdd $ real.log (abs z) - \u03c0 * I) :=\nbegin\n  have := (continuous_of_real.continuous_at.comp_continuous_within_at\n    (continuous_abs.continuous_within_at.log _)).tendsto.add\n    (((continuous_of_real.tendsto _).comp $\n    tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),\n  convert this,\n  { simp [sub_eq_add_neg] },\n  { lift z to \u211d using him, simpa using hre.ne }\nend\n\nlemma continuous_within_at_log_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  continuous_within_at log {z : \u2102 | 0 \u2264 z.im} z :=\nbegin\n  have := (continuous_of_real.continuous_at.comp_continuous_within_at\n    (continuous_abs.continuous_within_at.log _)).tendsto.add\n    ((continuous_of_real.continuous_at.comp_continuous_within_at $\n    continuous_within_at_arg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),\n  convert this,\n  { lift z to \u211d using him, simpa using hre.ne }\nend\n\nlemma tendsto_log_nhds_within_im_nonneg_of_re_neg_of_im_zero\n  {z : \u2102} (hre : z.re < 0) (him : z.im = 0) :\n  tendsto log (\ud835\udcdd[{z : \u2102 | 0 \u2264 z.im}] z) (\ud835\udcdd $ real.log (abs z) + \u03c0 * I) :=\nby simpa only [log, arg_eq_pi_iff.2 \u27e8hre, him\u27e9]\n  using (continuous_within_at_log_of_re_neg_of_im_zero hre him).tendsto\n\n@[simp] lemma map_exp_comap_re_at_bot : map exp (comap re at_bot) = \ud835\udcdd[\u2260] 0 :=\nby rw [\u2190 comap_exp_nhds_zero, map_comap, range_exp, nhds_within]\n\n@[simp] lemma map_exp_comap_re_at_top : map exp (comap re at_top) = comap abs at_top :=\nbegin\n  rw [\u2190 comap_exp_comap_abs_at_top, map_comap, range_exp, inf_eq_left, le_principal_iff],\n  exact eventually_ne_of_tendsto_norm_at_top tendsto_comap 0\nend\n\nend complex\n\nsection log_deriv\n\nopen complex filter\nopen_locale topological_space\n\nvariables {\u03b1 : Type*}\n\nlemma continuous_at_clog {x : \u2102} (h : 0 < x.re \u2228 x.im \u2260 0) :\n  continuous_at log x :=\nbegin\n  refine continuous_at.add _ _,\n  { refine continuous_of_real.continuous_at.comp _,\n    refine (real.continuous_at_log _).comp complex.continuous_abs.continuous_at,\n    rw abs_ne_zero,\n    rintro rfl,\n    simpa using h },\n  { have h_cont_mul : continuous (\u03bb x : \u2102, x * I), from continuous_id'.mul continuous_const,\n    refine h_cont_mul.continuous_at.comp (continuous_of_real.continuous_at.comp _),\n    exact continuous_at_arg h, },\nend\n\nlemma filter.tendsto.clog {l : filter \u03b1} {f : \u03b1 \u2192 \u2102} {x : \u2102} (h : tendsto f l (\ud835\udcdd x))\n  (hx : 0 < x.re \u2228 x.im \u2260 0) :\n  tendsto (\u03bb t, log (f t)) l (\ud835\udcdd $ log x) :=\n(continuous_at_clog hx).tendsto.comp h\n\nvariables [topological_space \u03b1]\n\nlemma continuous_at.clog {f : \u03b1 \u2192 \u2102} {x : \u03b1} (h\u2081 : continuous_at f x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_at (\u03bb t, log (f t)) x :=\nh\u2081.clog h\u2082\n\nlemma continuous_within_at.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} {x : \u03b1} (h\u2081 : continuous_within_at f s x)\n  (h\u2082 : 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_within_at (\u03bb t, log (f t)) s x :=\nh\u2081.clog h\u2082\n\nlemma continuous_on.clog {f : \u03b1 \u2192 \u2102} {s : set \u03b1} (h\u2081 : continuous_on f s)\n  (h\u2082 : \u2200 x \u2208 s, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous_on (\u03bb t, log (f t)) s :=\n\u03bb x hx, (h\u2081 x hx).clog (h\u2082 x hx)\n\nlemma continuous.clog {f : \u03b1 \u2192 \u2102} (h\u2081 : continuous f) (h\u2082 : \u2200 x, 0 < (f x).re \u2228 (f x).im \u2260 0) :\n  continuous (\u03bb t, log (f t)) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, h\u2081.continuous_at.clog (h\u2082 x)\n\nend log_deriv\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/special_functions/complex/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7056166896717013}}
{"text": "import ..lectures.love03_forward_proofs_demo\n\n\n/-! # LoVe Exercise 4: Functional Programming -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Reverse of a List\n\nWe define a new accumulator-based version of `reverse`. The first argument,\n`as`, serves as the accumulator. This definition is __tail-recursive__, meaning\nthat compilers and interpreters can easily optimize the recursion away,\nresulting in more efficient code. -/\n\ndef accurev {\u03b1 : Type} : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| as []        := as\n| as (x :: xs) := accurev (x :: as) xs\n\n/-! 1.1. Our intention is that `accurev [] xs` should be equal to `reverse xs`.\nBut if we start an induction, we quickly see that the induction hypothesis is\nnot strong enough. Start by proving the following generalization (using the\n`induction'` tactic or pattern matching): -/\n\nlemma accurev_eq_reverse_append {\u03b1 : Type} :\n  \u2200as xs : list \u03b1, accurev as xs = reverse xs ++ as :=\nsorry\n\n/-! 1.2. Derive the desired equation. -/\n\nlemma accurev_eq_reverse {\u03b1 : Type} (xs : list \u03b1) :\n  accurev [] xs = reverse xs :=\nsorry\n\n/-! 1.3. Prove the following property.\n\nHint: A one-line inductionless proof is possible. -/\n\nlemma accurev_accurev {\u03b1 : Type} (xs : list \u03b1) :\n  accurev [] (accurev [] xs) = xs :=\nsorry\n\n/-! 1.4. Prove the following lemma by structural induction, as a \"paper\" proof.\nThis is a good exercise to develop a deeper understanding of how structural\ninduction works (and is good practice for the final exam).\n\n    lemma accurev_eq_reverse_append {\u03b1 : Type} :\n      \u2200as xs : list \u03b1, accurev as xs = reverse xs ++ as\n\nGuidelines for paper proofs:\n\nWe expect detailed, rigorous, mathematical proofs. You are welcome to use\nstandard mathematical notation or Lean structured commands (e.g., `assume`,\n`have`, `show`, `calc`). You can also use tactical proofs (e.g., `intro`,\n`apply`), but then please indicate some of the intermediate goals, so that we\ncan follow the chain of reasoning.\n\nMajor proof steps, including applications of induction and invocation of the\ninduction hypothesis, must be stated explicitly. For each case of a proof by\ninduction, you must list the inductive hypotheses assumed (if any) and the goal\nto be proved. Minor proof steps corresponding to `refl`, `simp`, or `cc` need\nnot be justified if you think they are obvious (to humans), but you should say\nwhich key lemmas they depend on. You should be explicit whenever you use a\nfunction definition or an introduction rule for an inductive predicate. -/\n\n-- enter your paper proof here\n\n\n/-! ## Question 2: Drop and Take\n\nThe `drop` function removes the first `n` elements from the front of a list. -/\n\ndef drop {\u03b1 : Type} : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0       xs        := xs\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := drop m xs\n\n/-! 2.1. Define the `take` function, which returns a list consisting of the the\nfirst `n` elements at the front of a list.\n\nTo avoid unpleasant surprises in the proofs, we recommend that you follow the\nsame recursion pattern as for `drop` above. -/\n\ndef take {\u03b1 : Type} : \u2115 \u2192 list \u03b1 \u2192 list \u03b1 :=\nsorry\n\n#eval take 0 [3, 7, 11]   -- expected: []\n#eval take 1 [3, 7, 11]   -- expected: [3]\n#eval take 2 [3, 7, 11]   -- expected: [3, 7]\n#eval take 3 [3, 7, 11]   -- expected: [3, 7, 11]\n#eval take 4 [3, 7, 11]   -- expected: [3, 7, 11]\n\n#eval take 2 [\"a\", \"b\", \"c\"]   -- expected: [\"a\", \"b\"]\n\n/-! 2.2. Prove the following lemmas, using `induction'` or pattern matching.\nNotice that they are registered as simplification rules thanks to the `@[simp]`\nattribute. -/\n\n@[simp] lemma drop_nil {\u03b1 : Type} :\n  \u2200n : \u2115, drop n ([] : list \u03b1) = [] :=\nsorry\n\n@[simp] lemma take_nil {\u03b1 : Type} :\n  \u2200n : \u2115, take n ([] : list \u03b1) = [] :=\nsorry\n\n/-! 2.3. Follow the recursion pattern of `drop` and `take` to prove the\nfollowing lemmas. In other words, for each lemma, there should be three cases,\nand the third case will need to invoke the induction hypothesis.\n\nHint: Note that there are three variables in the `drop_drop` lemma (but only two\narguments to `drop`). For the third case, `\u2190add_assoc` might be useful. -/\n\nlemma drop_drop {\u03b1 : Type} :\n  \u2200(m n : \u2115) (xs : list \u03b1), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n-- supply the two missing cases here\n\nlemma take_take {\u03b1 : Type} :\n  \u2200(m : \u2115) (xs : list \u03b1), take m (take m xs) = take m xs :=\nsorry\n\nlemma take_drop {\u03b1 : Type} :\n  \u2200(n : \u2115) (xs : list \u03b1), take n xs ++ drop n xs = xs :=\nsorry\n\n\n/-! ## Question 3: A Type of \u03bb-Terms\n\n3.1. Define an inductive type corresponding to the untyped \u03bb-terms, as given\nby the following context-free grammar:\n\n    term ::= 'var' string        -- variable (e.g., `x`)\n           | 'lam' string term   -- \u03bb-expression (e.g., `\u03bbx, t`)\n           | 'app' term term     -- application (e.g., `t u`) -/\n\n-- enter your definition here\n\n/-! 3.2. Register a textual representation of the type `term` as an instance of\nthe `has_repr` type class. Make sure to supply enough parentheses to guarantee\nthat the output is unambiguous. -/\n\ndef term.repr : term \u2192 string\n-- enter your answer here\n\n@[instance] def term.has_repr : has_repr term :=\n{ repr := term.repr }\n\n/-! 3.3. Test your textual representation. The following command should print\nsomething like `(\u03bbx, ((y x) x))`. -/\n\n#eval (term.lam \"x\" (term.app (term.app (term.var \"y\") (term.var \"x\"))\n    (term.var \"x\")))\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/exercises/love04_functional_programming_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619220634456, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7056166785975226}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\n\nimport algebra.algebra.basic\nimport algebra.order.smul\n\n/-!\n# Ordered algebras\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nAn ordered algebra is an ordered semiring, which is an algebra over an ordered commutative semiring,\nfor which scalar multiplication is \"compatible\" with the two orders.\n\nThe prototypical example is 2x2 matrices over the reals or complexes (or indeed any C^* algebra)\nwhere the ordering the one determined by the positive cone of positive operators,\ni.e. `A \u2264 B` iff `B - A = star R * R` for some `R`.\n(We don't yet have this example in mathlib.)\n\n## Implementation\n\nBecause the axioms for an ordered algebra are exactly the same as those for the underlying\nmodule being ordered, we don't actually introduce a new class, but just use the `ordered_smul`\nmixin.\n\n## Tags\n\nordered algebra\n-/\n\nsection ordered_algebra\n\nvariables {R A : Type*} {a b : A} {r : R}\n\nvariables [ordered_comm_ring R] [ordered_ring A] [algebra R A] [ordered_smul R A]\n\nlemma algebra_map_monotone : monotone (algebra_map R A) :=\n\u03bb a b h,\nbegin\n  rw [algebra.algebra_map_eq_smul_one, algebra.algebra_map_eq_smul_one, \u2190sub_nonneg, \u2190sub_smul],\n  transitivity (b - a) \u2022 (0 : A),\n  { simp, },\n  { exact smul_le_smul_of_nonneg zero_le_one (sub_nonneg.mpr h) }\nend\n\nend ordered_algebra\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.705600733418625}}
{"text": "/-\nCopyright (c) 2022 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.abelian.transfer\n! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.CategoryTheory.Abelian.Basic\nimport Mathbin.CategoryTheory.Limits.Preserves.Shapes.Kernels\nimport Mathbin.CategoryTheory.Adjunction.Limits\n\n/-!\n# Transferring \"abelian-ness\" across a functor\n\nIf `C` is an additive category, `D` is an abelian category,\nwe have `F : C \u2964 D` `G : D \u2964 C` (both preserving zero morphisms),\n`G` is left exact (that is, preserves finite limits),\nand further we have `adj : G \u22a3 F` and `i : F \u22d9 G \u2245 \ud835\udfed C`,\nthen `C` is also abelian.\n\nSee <https://stacks.math.columbia.edu/tag/03A3>\n\n## Notes\nThe hypotheses, following the statement from the Stacks project,\nmay appear suprising: we don't ask that the counit of the adjunction is an isomorphism,\nbut just that we have some potentially unrelated isomorphism `i : F \u22d9 G \u2245 \ud835\udfed C`.\n\nHowever Lemma A1.1.1 from [Elephant] shows that in this situation the counit itself\nmust be an isomorphism, and thus that `C` is a reflective subcategory of `D`.\n\nSomeone may like to formalize that lemma, and restate this theorem in terms of `reflective`.\n(That lemma has a nice string diagrammatic proof that holds in any bicategory.)\n-/\n\n\nnoncomputable section\n\nnamespace CategoryTheory\n\nopen CategoryTheory.Limits\n\nuniverse v u\u2081 u\u2082\n\nnamespace AbelianOfAdjunction\n\nvariable {C : Type u\u2081} [Category.{v} C] [Preadditive C]\n\nvariable {D : Type u\u2082} [Category.{v} D] [Abelian D]\n\nvariable (F : C \u2964 D)\n\nvariable (G : D \u2964 C) [Functor.PreservesZeroMorphisms G]\n\nvariable (i : F \u22d9 G \u2245 \ud835\udfed C) (adj : G \u22a3 F)\n\ninclude i\n\n/-- No point making this an instance, as it requires `i`. -/\ntheorem hasKernels [PreservesFiniteLimits G] : HasKernels C :=\n  {\n    HasLimit := fun X Y f => by\n      have := nat_iso.naturality_1 i f\n      simp at this\n      rw [\u2190 this]\n      haveI : has_kernel (G.map (F.map f) \u226b i.hom.app _) := limits.has_kernel_comp_mono _ _\n      apply limits.has_kernel_iso_comp }\n#align category_theory.abelian_of_adjunction.has_kernels CategoryTheory.AbelianOfAdjunction.hasKernels\n\ninclude adj\n\n/-- No point making this an instance, as it requires `i` and `adj`. -/\ntheorem hasCokernels : HasCokernels C :=\n  {\n    HasColimit := fun X Y f =>\n      by\n      haveI : preserves_colimits G := adj.left_adjoint_preserves_colimits\n      have := nat_iso.naturality_1 i f\n      simp at this\n      rw [\u2190 this]\n      haveI : has_cokernel (G.map (F.map f) \u226b i.hom.app _) := limits.has_cokernel_comp_iso _ _\n      apply limits.has_cokernel_epi_comp }\n#align category_theory.abelian_of_adjunction.has_cokernels CategoryTheory.AbelianOfAdjunction.hasCokernels\n\nvariable [Limits.HasCokernels C]\n\n/-- Auxiliary construction for `coimage_iso_image` -/\ndef cokernelIso {X Y : C} (f : X \u27f6 Y) : G.obj (cokernel (F.map f)) \u2245 cokernel f :=\n  by\n  -- We have to write an explicit `preserves_colimits` type here,\n  -- as `left_adjoint_preserves_colimits` has universe variables.\n  haveI : preserves_colimits G := adj.left_adjoint_preserves_colimits\n  calc\n    G.obj (cokernel (F.map f)) \u2245 cokernel (G.map (F.map f)) :=\n      (as_iso (cokernel_comparison _ G)).symm\n    _ \u2245 cokernel (_ \u226b f \u226b _) := (cokernel_iso_of_eq (nat_iso.naturality_2 i f).symm)\n    _ \u2245 cokernel (f \u226b _) := (cokernel_epi_comp _ _)\n    _ \u2245 cokernel f := cokernel_comp_is_iso _ _\n    \n#align category_theory.abelian_of_adjunction.cokernel_iso CategoryTheory.AbelianOfAdjunction.cokernelIso\n\nvariable [Limits.HasKernels C] [PreservesFiniteLimits G]\n\n/-- Auxiliary construction for `coimage_iso_image` -/\ndef coimageIsoImageAux {X Y : C} (f : X \u27f6 Y) :\n    kernel (G.map (cokernel.\u03c0 (F.map f))) \u2245 kernel (cokernel.\u03c0 f) :=\n  by\n  haveI : preserves_colimits G := adj.left_adjoint_preserves_colimits\n  calc\n    kernel (G.map (cokernel.\u03c0 (F.map f))) \u2245\n        kernel (cokernel.\u03c0 (G.map (F.map f)) \u226b cokernel_comparison (F.map f) G) :=\n      kernel_iso_of_eq (\u03c0_comp_cokernel_comparison _ _).symm\n    _ \u2245 kernel (cokernel.\u03c0 (G.map (F.map f))) := (kernel_comp_mono _ _)\n    _ \u2245 kernel (cokernel.\u03c0 (_ \u226b f \u226b _) \u226b (cokernel_iso_of_eq _).Hom) :=\n      (kernel_iso_of_eq (\u03c0_comp_cokernel_iso_of_eq_hom (nat_iso.naturality_2 i f)).symm)\n    _ \u2245 kernel (cokernel.\u03c0 (_ \u226b f \u226b _)) := (kernel_comp_mono _ _)\n    _ \u2245 kernel (cokernel.\u03c0 (f \u226b i.inv.app Y) \u226b (cokernel_epi_comp (i.hom.app X) _).inv) :=\n      (kernel_iso_of_eq (by simp only [cokernel.\u03c0_desc, cokernel_epi_comp_inv]))\n    _ \u2245 kernel (cokernel.\u03c0 (f \u226b _)) := (kernel_comp_mono _ _)\n    _ \u2245 kernel (inv (i.inv.app Y) \u226b cokernel.\u03c0 f \u226b (cokernel_comp_is_iso f (i.inv.app Y)).inv) :=\n      (kernel_iso_of_eq\n        (by\n          simp only [cokernel.\u03c0_desc, cokernel_comp_is_iso_inv, iso.hom_inv_id_app_assoc,\n            nat_iso.inv_inv_app]))\n    _ \u2245 kernel (cokernel.\u03c0 f \u226b _) := (kernel_is_iso_comp _ _)\n    _ \u2245 kernel (cokernel.\u03c0 f) := kernel_comp_mono _ _\n    \n#align category_theory.abelian_of_adjunction.coimage_iso_image_aux CategoryTheory.AbelianOfAdjunction.coimageIsoImageAux\n\nvariable [Functor.PreservesZeroMorphisms F]\n\n/-- Auxiliary definition: the abelian coimage and abelian image agree.\nWe still need to check that this agrees with the canonical morphism.\n-/\ndef coimageIsoImage {X Y : C} (f : X \u27f6 Y) : Abelian.coimage f \u2245 Abelian.image f :=\n  by\n  haveI : preserves_limits F := adj.right_adjoint_preserves_limits\n  haveI : preserves_colimits G := adj.left_adjoint_preserves_colimits\n  calc\n    abelian.coimage f \u2245 cokernel (kernel.\u03b9 f) := iso.refl _\n    _ \u2245 G.obj (cokernel (F.map (kernel.\u03b9 f))) := (cokernel_iso _ _ i adj _).symm\n    _ \u2245 G.obj (cokernel (kernel_comparison f F \u226b kernel.\u03b9 (F.map f))) :=\n      (G.map_iso (cokernel_iso_of_eq (by simp)))\n    _ \u2245 G.obj (cokernel (kernel.\u03b9 (F.map f))) := (G.map_iso (cokernel_epi_comp _ _))\n    _ \u2245 G.obj (abelian.coimage (F.map f)) := (iso.refl _)\n    _ \u2245 G.obj (abelian.image (F.map f)) := (G.map_iso (abelian.coimage_iso_image _))\n    _ \u2245 G.obj (kernel (cokernel.\u03c0 (F.map f))) := (iso.refl _)\n    _ \u2245 kernel (G.map (cokernel.\u03c0 (F.map f))) := (preserves_kernel.iso _ _)\n    _ \u2245 kernel (cokernel.\u03c0 f) := (coimage_iso_image_aux F G i adj f)\n    _ \u2245 abelian.image f := iso.refl _\n    \n#align category_theory.abelian_of_adjunction.coimage_iso_image CategoryTheory.AbelianOfAdjunction.coimageIsoImage\n\nattribute [local simp] cokernel_iso coimage_iso_image coimage_iso_image_aux\n\n-- The account of this proof in the Stacks project omits this calculation.\ntheorem coimageIsoImage_hom {X Y : C} (f : X \u27f6 Y) :\n    (coimageIsoImage F G i adj f).Hom = Abelian.coimageImageComparison f :=\n  by\n  ext\n  simpa only [\u2190 G.map_comp_assoc, coimage_iso_image, nat_iso.inv_inv_app, cokernel_iso,\n    coimage_iso_image_aux, iso.trans_symm, iso.symm_symm_eq, iso.refl_trans, iso.trans_refl,\n    iso.trans_hom, iso.symm_hom, cokernel_comp_is_iso_inv, cokernel_epi_comp_inv, as_iso_hom,\n    functor.map_iso_hom, cokernel_epi_comp_hom, preserves_kernel.iso_hom, kernel_comp_mono_hom,\n    kernel_is_iso_comp_hom, cokernel_iso_of_eq_hom_comp_desc_assoc, cokernel.\u03c0_desc_assoc,\n    category.assoc, \u03c0_comp_cokernel_iso_of_eq_inv_assoc, \u03c0_comp_cokernel_comparison_assoc,\n    kernel.lift_\u03b9, kernel.lift_\u03b9_assoc, kernel_iso_of_eq_hom_comp_\u03b9_assoc,\n    kernel_comparison_comp_\u03b9_assoc, abelian.coimage_image_factorisation] using\n    nat_iso.naturality_1 i f\n#align category_theory.abelian_of_adjunction.coimage_iso_image_hom CategoryTheory.AbelianOfAdjunction.coimageIsoImage_hom\n\nend AbelianOfAdjunction\n\nopen AbelianOfAdjunction\n\n/-- If `C` is an additive category, `D` is an abelian category,\nwe have `F : C \u2964 D` `G : D \u2964 C` (both preserving zero morphisms),\n`G` is left exact (that is, preserves finite limits),\nand further we have `adj : G \u22a3 F` and `i : F \u22d9 G \u2245 \ud835\udfed C`,\nthen `C` is also abelian.\n\nSee <https://stacks.math.columbia.edu/tag/03A3>\n-/\ndef abelianOfAdjunction {C : Type u\u2081} [Category.{v} C] [Preadditive C] [HasFiniteProducts C]\n    {D : Type u\u2082} [Category.{v} D] [Abelian D] (F : C \u2964 D) [Functor.PreservesZeroMorphisms F]\n    (G : D \u2964 C) [Functor.PreservesZeroMorphisms G] [PreservesFiniteLimits G] (i : F \u22d9 G \u2245 \ud835\udfed C)\n    (adj : G \u22a3 F) : Abelian C := by\n  haveI := has_kernels F G i\n  haveI := has_cokernels F G i adj\n  have : \u2200 {X Y : C} (f : X \u27f6 Y), is_iso (abelian.coimage_image_comparison f) :=\n    by\n    intro X Y f\n    rw [\u2190 coimage_iso_image_hom F G i adj f]\n    infer_instance\n  apply abelian.of_coimage_image_comparison_is_iso\n#align category_theory.abelian_of_adjunction CategoryTheory.abelianOfAdjunction\n\n/-- If `C` is an additive category equivalent to an abelian category `D`\nvia a functor that preserves zero morphisms,\nthen `C` is also abelian.\n-/\ndef abelianOfEquivalence {C : Type u\u2081} [Category.{v} C] [Preadditive C] [HasFiniteProducts C]\n    {D : Type u\u2082} [Category.{v} D] [Abelian D] (F : C \u2964 D) [Functor.PreservesZeroMorphisms F]\n    [IsEquivalence F] : Abelian C :=\n  abelianOfAdjunction F F.inv F.asEquivalence.unitIso.symm F.asEquivalence.symm.toAdjunction\n#align category_theory.abelian_of_equivalence CategoryTheory.abelianOfEquivalence\n\nend CategoryTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/CategoryTheory/Abelian/Transfer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.7056007178201961}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n! This file was ported from Lean 3 source module order.bounds.order_iso\n! leanprover-community/mathlib commit a59dad53320b73ef180174aae867addd707ef00e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Bounds.Basic\nimport Mathlib.Order.Hom.Set\n\n/-!\n# Order isomorphisms and bounds.\n-/\n\nopen Set\n\nnamespace OrderIso\n\nvariable [Preorder \u03b1] [Preorder \u03b2] (f : \u03b1 \u2243o \u03b2)\n\ntheorem upperBounds_image {s : Set \u03b1} : upperBounds (f '' s) = f '' upperBounds s :=\n  Subset.antisymm\n    (fun x hx =>\n      \u27e8f.symm x, fun _ hy => f.le_symm_apply.2 (hx <| mem_image_of_mem _ hy), f.apply_symm_apply x\u27e9)\n    f.monotone.image_upperBounds_subset_upperBounds_image\n#align order_iso.upper_bounds_image OrderIso.upperBounds_image\n\ntheorem lowerBounds_image {s : Set \u03b1} : lowerBounds (f '' s) = f '' lowerBounds s :=\n  @upperBounds_image \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ f.dual _\n#align order_iso.lower_bounds_image OrderIso.lowerBounds_image\n\n-- Porting note: by simps were `fun _ _ => f.le_iff_le` and `fun _ _ => f.symm.le_iff_le`\n@[simp]\n\n\ntheorem isLUB_image' {s : Set \u03b1} {x : \u03b1} : IsLUB (f '' s) (f x) \u2194 IsLUB s x := by\n  rw [isLUB_image, f.symm_apply_apply]\n#align order_iso.is_lub_image' OrderIso.isLUB_image'\n\n@[simp]\ntheorem isGLB_image {s : Set \u03b1} {x : \u03b2} : IsGLB (f '' s) x \u2194 IsGLB s (f.symm x) :=\n  f.dual.isLUB_image\n#align order_iso.is_glb_image OrderIso.isGLB_image\n\ntheorem isGLB_image' {s : Set \u03b1} {x : \u03b1} : IsGLB (f '' s) (f x) \u2194 IsGLB s x :=\n  f.dual.isLUB_image'\n#align order_iso.is_glb_image' OrderIso.isGLB_image'\n\n@[simp]\ntheorem isLUB_preimage {s : Set \u03b2} {x : \u03b1} : IsLUB (f \u207b\u00b9' s) x \u2194 IsLUB s (f x) := by\n  rw [\u2190 f.symm_symm, \u2190 image_eq_preimage, isLUB_image]\n#align order_iso.is_lub_preimage OrderIso.isLUB_preimage\n\ntheorem isLUB_preimage' {s : Set \u03b2} {x : \u03b2} : IsLUB (f \u207b\u00b9' s) (f.symm x) \u2194 IsLUB s x := by\n  rw [isLUB_preimage, f.apply_symm_apply]\n#align order_iso.is_lub_preimage' OrderIso.isLUB_preimage'\n\n@[simp]\ntheorem isGLB_preimage {s : Set \u03b2} {x : \u03b1} : IsGLB (f \u207b\u00b9' s) x \u2194 IsGLB s (f x) :=\n  f.dual.isLUB_preimage\n#align order_iso.is_glb_preimage OrderIso.isGLB_preimage\n\ntheorem isGLB_preimage' {s : Set \u03b2} {x : \u03b2} : IsGLB (f \u207b\u00b9' s) (f.symm x) \u2194 IsGLB s x :=\n  f.dual.isLUB_preimage'\n#align order_iso.is_glb_preimage' OrderIso.isGLB_preimage'\n\nend OrderIso\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/Bounds/OrderIso.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509007, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7056007172844696}}
{"text": "/-\nCopyright (c) 2020 Markus Himmel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Markus Himmel\n-/\nimport algebra.category.Module.epi_mono\nimport category_theory.limits.concrete_category\n\n/-!\n# The concrete (co)kernels in the category of modules are (co)kernels in the categorical sense.\n-/\n\nopen category_theory\nopen category_theory.limits\n\nuniverses u v\n\nnamespace Module\nvariables {R : Type u} [ring R]\n\nsection\nvariables {M N : Module.{v} R} (f : M \u27f6 N)\n\n/-- The kernel cone induced by the concrete kernel. -/\ndef kernel_cone : kernel_fork f :=\nkernel_fork.of_\u03b9 (as_hom f.ker.subtype) $ by tidy\n\n/-- The kernel of a linear map is a kernel in the categorical sense. -/\ndef kernel_is_limit : is_limit (kernel_cone f) :=\nfork.is_limit.mk _\n  (\u03bb s, linear_map.cod_restrict f.ker (fork.\u03b9 s) (\u03bb c, linear_map.mem_ker.2 $\n    by { rw [\u2190@function.comp_apply _ _ _ f (fork.\u03b9 s) c, \u2190coe_comp, fork.condition,\n      has_zero_morphisms.comp_zero (fork.\u03b9 s) N], refl }))\n  (\u03bb s, linear_map.subtype_comp_cod_restrict _ _ _)\n  (\u03bb s m h, linear_map.ext $ \u03bb x, subtype.ext_iff_val.2 (by simpa [\u2190h]))\n\n/-- The cokernel cocone induced by the projection onto the quotient. -/\ndef cokernel_cocone : cokernel_cofork f :=\ncokernel_cofork.of_\u03c0 (as_hom f.range.mkq) $ linear_map.range_mkq_comp _\n\n/-- The projection onto the quotient is a cokernel in the categorical sense. -/\ndef cokernel_is_colimit : is_colimit (cokernel_cocone f) :=\ncofork.is_colimit.mk _\n  (\u03bb s, f.range.liftq (cofork.\u03c0 s) $ linear_map.range_le_ker_iff.2 $ cokernel_cofork.condition s)\n  (\u03bb s, f.range.liftq_mkq (cofork.\u03c0 s) _)\n  (\u03bb s m h,\n  begin\n    haveI : epi (as_hom f.range.mkq) := (epi_iff_range_eq_top _).mpr (submodule.range_mkq _),\n    apply (cancel_epi (as_hom f.range.mkq)).1,\n    convert h,\n    exact submodule.liftq_mkq _ _ _\n  end)\nend\n\n/-- The category of R-modules has kernels, given by the inclusion of the kernel submodule. -/\nlemma has_kernels_Module : has_kernels (Module R) :=\n\u27e8\u03bb X Y f, has_limit.mk \u27e8_, kernel_is_limit f\u27e9\u27e9\n\n/-- The category or R-modules has cokernels, given by the projection onto the quotient. -/\nlemma has_cokernels_Module : has_cokernels (Module R) :=\n\u27e8\u03bb X Y f, has_colimit.mk \u27e8_, cokernel_is_colimit f\u27e9\u27e9\n\nopen_locale Module\n\nlocal attribute [instance] has_kernels_Module\nlocal attribute [instance] has_cokernels_Module\n\nvariables {G H : Module.{v} R} (f : G \u27f6 H)\n\n/--\nThe categorical kernel of a morphism in `Module`\nagrees with the usual module-theoretical kernel.\n-/\nnoncomputable def kernel_iso_ker {G H : Module.{v} R} (f : G \u27f6 H) :\n  kernel f \u2245 Module.of R (f.ker) :=\nlimit.iso_limit_cone \u27e8_, kernel_is_limit f\u27e9\n\n-- We now show this isomorphism commutes with the inclusion of the kernel into the source.\n\n@[simp, elementwise] lemma kernel_iso_ker_inv_kernel_\u03b9 :\n  (kernel_iso_ker f).inv \u226b kernel.\u03b9 f = f.ker.subtype :=\nlimit.iso_limit_cone_inv_\u03c0 _ _\n\n@[simp, elementwise] lemma kernel_iso_ker_hom_ker_subtype :\n  (kernel_iso_ker f).hom \u226b f.ker.subtype = kernel.\u03b9 f :=\nis_limit.cone_point_unique_up_to_iso_inv_comp _ (limit.is_limit _) walking_parallel_pair.zero\n\n/--\nThe categorical cokernel of a morphism in `Module`\nagrees with the usual module-theoretical quotient.\n-/\nnoncomputable def cokernel_iso_range_quotient {G H : Module.{v} R} (f : G \u27f6 H) :\n  cokernel f \u2245 Module.of R (H \u29f8 f.range) :=\ncolimit.iso_colimit_cocone \u27e8_, cokernel_is_colimit f\u27e9\n\n-- We now show this isomorphism commutes with the projection of target to the cokernel.\n\n@[simp, elementwise] lemma cokernel_\u03c0_cokernel_iso_range_quotient_hom :\n  cokernel.\u03c0 f \u226b (cokernel_iso_range_quotient f).hom = f.range.mkq :=\nby { convert colimit.iso_colimit_cocone_\u03b9_hom _ _; refl, }\n\n@[simp, elementwise] lemma range_mkq_cokernel_iso_range_quotient_inv :\n  \u21bff.range.mkq \u226b (cokernel_iso_range_quotient f).inv = cokernel.\u03c0 f :=\nby { convert colimit.iso_colimit_cocone_\u03b9_inv \u27e8_, cokernel_is_colimit f\u27e9 _; refl, }\n\nlemma cokernel_\u03c0_ext {M N : Module.{u} R} (f : M \u27f6 N) {x y : N} (m : M) (w : x = y + f m) :\n  cokernel.\u03c0 f x = cokernel.\u03c0 f y :=\nby { subst w, simp, }\n\nend Module\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/category/Module/kernels.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7056007158275203}}
{"text": "import algebra.ring\nimport order.boolean_algebra\n\nuniverse u\n\nvariable (\u03b1 : Type u)\n\nclass boolean_ring (\u03b1 : Type u) extends (ring \u03b1) := \n(mul_self : \u2200 a : \u03b1, a * a = a)\n\nnamespace boolean_ring\n\nvariable {\u03b1}\nvariables [boolean_ring \u03b1]\n\nlemma add_self (a : \u03b1) : a + a = 0 := \nbegin\n  have := mul_self (a + a),\n  rw [add_mul, mul_add, mul_self a] at this,\n  exact calc\n    a + a = (a + a) + (a + a) - (a + a) : (add_sub_cancel _ _).symm\n    ... = 0 : by rw [this, sub_self]\nend\n\nlemma neg_self (a : \u03b1) : - a = a := \n (eq_neg_iff_add_eq_zero.mpr (add_self a)).symm\n\ninstance : comm_ring \u03b1 := \n{ mul_comm := \u03bb a b,\n  begin\n    have h0 := mul_self (a + b),\n    rw [mul_add, add_mul, add_mul, mul_self a, mul_self b, add_assoc] at h0,\n    have h1 := congr_arg (has_add.add (b * a)) (add_left_cancel h0),\n    rw [\u2190 add_assoc, add_self (b * a), zero_add] at h1,\n    exact add_right_cancel h1\n  end,\n  .. (by {apply_instance} : ring \u03b1) }\n\nopen lattice\n\ninstance : has_le  \u03b1 := \u27e8\u03bb a b, a * b = a\u27e9\ninstance : has_bot \u03b1 := \u27e80\u27e9\ninstance : has_top \u03b1 := \u27e81\u27e9\ninstance : has_sup \u03b1 := \u27e8\u03bb a b, a + b + a * b\u27e9 \ninstance : has_inf \u03b1 := \u27e8\u03bb a b, a * b\u27e9 \n\ninstance : boolean_algebra \u03b1 := \n{ le := has_le.le,\n  bot := has_bot.bot,\n  top := has_top.top,\n  sup := has_sup.sup,\n  inf := has_inf.inf,\n  le_refl := \u03bb a, mul_self a,\n  le_antisymm := \u03bb a b (hab : a * b = a) (hba : b * a = b), \n    (hab.symm.trans (mul_comm a b)).trans hba,\n  le_trans := \u03bb a b c (hab : a * b = a) (hbc : b * c = b), \n    calc a * c = a * b * c : by {rw[hab],}\n      ... = a : by {rw[mul_assoc,hbc,hab]},\n  bot_le := \u03bb a, (zero_mul a),\n  le_top := \u03bb a, (mul_one a),\n  sup_le := \u03bb a b c (hac : a * c = a) (hbc : b * c = b), \n  show (a + b + a * b) * c = (a + b + a * b),\n  by rw [add_mul, add_mul, mul_assoc, hac, hbc],\n  le_sup_left := \u03bb a b, show a * (a + b + a * b) = a, \n  by rw [mul_add,mul_add,\u2190 mul_assoc,mul_self a,add_assoc,\n         add_self (a * b),add_zero],\n  le_sup_right := \u03bb a b, show b * (a + b + a * b) = b, \n  by rw[mul_comm a b,\n        mul_add,mul_add,\u2190 mul_assoc,mul_self b,\n        add_comm (b * a) b,add_assoc,\n        add_self (b * a),add_zero],\n  le_inf := \u03bb a b c (hab : a * b = a) (hac : a * c = a), \n  show a * (b * c) = a, by rw [\u2190 mul_assoc, hab, hac], \n  inf_le_left := \u03bb a b, show (a * b) * a = a * b, \n  by rw [mul_assoc, mul_comm b a, \u2190 mul_assoc, mul_self a], \n  inf_le_right := \u03bb a b, show (a * b) * b = a * b, \n  by rw [mul_assoc,mul_self b], \n  le_sup_inf := \u03bb a b c, show\n    (a + b + a * b) * (a + c + a * c) * (a + b * c + a * (b * c)) = \n    (a + b + a * b) * (a + c + a * c),\n  begin\n    let ha := mul_self a,\n    let hb := mul_self b,\n    let hc := mul_self c,\n    let u := (a + b + a * b),\n    let v := (a + c + a * c),\n    let w := (a + b * c + a * (b * c)),\n    change u * v * w = u * v,\n    have hua : u * a = a :=\n    by {rw [mul_comm], dsimp[u],\n        rw [mul_add, mul_add, \u2190 mul_assoc, ha,\n            add_assoc, add_self, add_zero] },\n    have huc : u * c = a * c + b * c + a * b * c := \n    by {dsimp[u],rw[add_mul,add_mul]},\n    have huv : u * v = a + b * c + b * c * a := \n    by {dsimp [v],\n       rw [mul_add, mul_add, \u2190 mul_assoc u, hua, add_assoc, add_comm (u * c)],\n       rw [huc, \u2190 add_assoc (a * c), \u2190 add_assoc (a * c), \n           add_self (a * c), zero_add],\n       rw [add_assoc,mul_assoc a,mul_comm a]},\n  have haw : a * w = a :=\n    by {dsimp [w],\n        rw [mul_add, mul_add, \u2190 mul_assoc a, \u2190 mul_assoc a, \u2190 mul_assoc a],\n        rw [ha, add_assoc, add_self, add_zero]},\n  rw [huv, add_mul, add_mul, mul_assoc (b * c), haw],\n  congr' 2,\n  dsimp [w],\n  rw [mul_add, mul_add, mul_comm a (b * c), \u2190 mul_assoc (b * c) (b * c)],\n  rw [mul_self (b * c), add_comm (b * c * a), add_assoc, add_self, add_zero], \n end,\n compl := \u03bb a, 1 + a,\n sdiff := \u03bb a b, a + a * b,\n sdiff_eq := \u03bb a b, show a + a * b = a * (1 + b), by rw[mul_add,mul_one],\n sup_inf_sdiff := \u03bb a b, show a * b + (a + a * b) + (a * b) * (a + a * b) = a,\n  by rw[mul_add,mul_comm (a * b) a,\u2190 mul_assoc,mul_self a,mul_self (a * b),\n     add_self (a * b),add_zero,add_comm a,\u2190 add_assoc,add_self (a * b),zero_add],\n  inf_inf_sdiff := \u03bb a b, show a * b * (a + a * b) = 0,\n   by rw[mul_add,mul_self (a * b),mul_comm (a * b),\u2190 mul_assoc,mul_self a,\n          add_self],\n  inf_compl_le_bot := \u03bb a, show a * (1 + a) * 0 = a * (1 + a), \n   by rw[mul_zero,mul_add,mul_one,mul_self,add_self],\n  top_le_sup_compl := \u03bb a, show 1 * (a + (1 + a) + a * (1 + a)) = 1,\n  by rw[one_mul,mul_add,mul_one,mul_self,add_self,add_zero,\n           add_comm 1 a,\u2190 add_assoc,add_self,zero_add]\n}\n\nend boolean_ring", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/commutative_algebra/boolean_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.7055672731801832}}
{"text": "import basic_defs_world.level1 --hide\nopen set --hide\nnamespace topological_space --hide\n\n\n/-\n# Level 2: Union of two open sets\n-/\n\n/- Lemma\nThe union of two open sets is open.\n-/\nlemma open_of_union {X : Type} [topological_space X] {U V : set X}\n(hU : is_open U) (hV : is_open V): is_open (U \u222a V) :=\nbegin\n  let I : set (set X) := {U, V},\n  have H : \u22c3\u2080 I = U \u222a V := sUnion_pair U V,\n  rw \u2190H,\n  apply union,\n  intros B hB,\n  replace hB : B = U \u2228 B = V, by tauto,\n  cases hB; {rw hB, assumption},\n\n\n\n\nend\n\nend topological_space --hide\n", "meta": {"author": "mmasdeu", "repo": "topologygame", "sha": "0a1b868031919a5555e7b99efca66ece2f546ec7", "save_path": "github-repos/lean/mmasdeu-topologygame", "path": "github-repos/lean/mmasdeu-topologygame/topologygame-0a1b868031919a5555e7b99efca66ece2f546ec7/src/basic_defs_world/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.7055672680188056}}
{"text": "import tactic\nimport tactic.slim_check\nimport algebra.ordered_ring\nuniverse u\n\n-- 1.3. Properties of Ordered Domains\n\n-- closest match to Birkhoff-Mac Lane \"ordered domain is\"\n#check linear_ordered_comm_ring -- Mario Carneiro\n\n-- Exercises for section 1.3\n\ntheorem ex_1_3_1_a (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] \n   (a b c : \u03b1) (h: a < b): a + c < b + c := \n  add_lt_add_right h c\n\ntheorem ex_1_3_1_b (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] \n   (a x y : \u03b1): a-x < a-y \u2194 x > y := sub_lt_sub_iff_left a\n\nlemma lt0_lt_flip (\u03b1: Type*) [linear_ordered_ring \u03b1] -- Ruben Van de Velde\n   (a x : \u03b1) (hx: a * x < 0) (ha: a < 0) : 0 < x :=\n  pos_of_mul_neg_right hx ha.le\n\ntheorem ex_1_3_1_c (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] \n   (a x y : \u03b1) (h: a < 0): a*x > a* y \u2194 x < y :=\nbegin\n  split,\n  {\n    intro h0,\n    have h1 := sub_lt_zero.mpr h0,\n    apply sub_lt_zero.1,\n    rw \u2190 mul_sub at h1,\n    have h2 := lt0_lt_flip \u03b1 a (y-x) h1 h,\n    rw (neg_sub x y).symm at h2,\n    exact neg_pos.1 h2,\n  },\n  {\n    intro h0,\n    apply sub_lt_zero.1,\n    rw \u2190 mul_sub,\n    have h1 := sub_pos.2 h0,\n    exact mul_neg_of_neg_of_pos h h1,\n  }\nend\n\ntheorem ex_1_3_1_d (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] \n   (a b c : \u03b1) (ha: 0 < c) (hacbc: a*c < b*c): a < b :=\n  (mul_lt_mul_right ha).mp hacbc\n\ntheorem ex_1_3_1_e (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] \n   (x : \u03b1) (h: x + x + x + x = 0) : x = 0 :=\nbegin\n  rw (add_assoc (x+x) x x) at h,\n  exact bit0_eq_zero.mp (bit0_eq_zero.mp h),\nend\n\nlemma together  (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (a b: \u03b1) (h: a-b = 0)  : a = b := \n  sub_eq_zero.mp h\n\nlemma factor_expr (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (a b : \u03b1) :\n  a * (b ^ 2 * -3) + (a ^ 2 * (b * 3)) = 3*a*b*(a - b) :=\nbegin\n  apply (together \u03b1 (a * (b ^ 2 * -3) + (a ^ 2 * (b * 3))) (3*a*b*(a - b))),\n  ring,\nend\n\nlemma move_cubes_left (\u03b1: Type u) [linear_ordered_comm_ring \u03b1]\n   (a b : \u03b1) (h: 0 < a * (b ^ 2 * -3) + (a ^ 2 * (b * 3) + (-a ^ 3 + b ^ 3))) :\n   a^3- b^3 < a * (b ^ 2 * -3) + (a ^ 2 * (b * 3)) :=\nbegin\n  linarith,\nend\n\nlemma negneg (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (a b : \u03b1): a - b = - (b - a):=\nbegin\n  linarith,\nend\n\nlemma this_is_negative (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (a b : \u03b1)\n      (h1: 0 < b - a)\n      (hha: a > 0)\n      (hhb: b > 0) : 3 * a * b * (a - b) < 0 :=\nbegin\n  rw negneg \u03b1 a b,\n  have h3 := zero_lt_three,\n  have h4 := mul_pos h3 hha,\n  have h5 := mul_pos h4 hhb,\n  simp,\n  have h6 := neg_lt_zero.mpr h1,\n  have h7 := neg_sub b  a,\n  rw h7 at h6,\n  exact linarith.mul_neg h6 h5,\n  exact nontrivial_of_lt 0 (b - a) h1,\nend\n\nlemma this_is_positive (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (a b : \u03b1)\n      (h1: 0 < b - a) (hb: b > 0) (alt0: a < 0) : 0 < 3 * a * b * (a - b) :=\nbegin\n  have h3 := zero_lt_three,\n  have h4 := mul_neg_of_pos_of_neg h3 alt0,\n  have h5 := mul_neg_of_neg_of_pos h4 hb,\n  have h6 := neg_lt_zero.mpr h1,\n  have h7 := mul_pos_of_neg_of_neg h5 h6,\n  have h8 := neg_sub b a,\n  rw h8 at h7,\n  exact h7,\n  exact nontrivial_of_lt 0 (b - a) h1,\nend\n\nlemma simp_pow (\u03b1: Type u) [linear_ordered_comm_ring \u03b1]: (0:\u03b1)^3 = 0 :=\n  tactic.ring_exp.pow_p_pf_zero rfl rfl\n\nlemma is_lt_0 (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (b : \u03b1)\n      (hb: \u00acb > 0) (hb0: \u00acb = 0): b < 0 :=\n  (ne.le_iff_lt hb0).mp (not_lt.mp hb)\n\nlemma odd_pos_neg_neg (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (a : \u03b1)\n        (h: a < 0) : a^3 < 0 :=\n  pow_bit1_neg_iff.mpr h\n\nlemma this_be_negative (\u03b1: Type u) [linear_ordered_comm_ring \u03b1] (a b : \u03b1)\n      (h1: a < b)\n      (halt0: a < 0)\n      (hblt0: b < 0) : \n      3 * a * b * (a - b) < 0 :=\nbegin\n  have h3 := zero_lt_three,\n  have h4 := sub_lt_zero.mpr h1,\n  have h5 := mul_pos_of_neg_of_neg  halt0 hblt0,\n  have h6 := mul_pos h3 h5,\n  have h7 := sub_lt_zero.mpr h1,\n  have h8 := linarith.mul_neg h7 h6,\n  finish,\n  exact nontrivial_of_lt a b h1,\nend\n\ntheorem ex_1_3_1_f (\u03b1: Type u) [linear_ordered_comm_ring \u03b1]\n   (a b : \u03b1) (h: a < b): a^3 < b^3 :=\nbegin\n  have h1 := sub_pos.2 h,\n  have h2 := pow_pos h1 3,\n  repeat { rw pow_succ' at h2, },\n  simp at h2,\n  rw sub_eq_neg_add at h2,\n  repeat { rw right_distrib at h2, rw left_distrib at h2, },\n  ring_exp at h2,\n  have h3 := move_cubes_left \u03b1 a b h2,\n  rw factor_expr \u03b1 a b at h3,\n  by_cases ha : a > 0,\n  {\n    by_cases hb : b > 0,\n    {\n      have h4 := this_is_negative \u03b1 a b h1 ha hb,\n      have h5 := lt_trans h3 h4,\n      exact sub_lt_zero.1 h5,\n    },\n    {\n      exfalso,\n      exact hb (lt_trans ha h),\n    },\n  },\n  by_cases ha0: a = 0,\n  {\n    rw ha0 at *,\n    simp at *,\n    assumption,\n  },\n  {\n    have halt0 := is_lt_0 \u03b1 a ha ha0,\n    have h3alt0 := odd_pos_neg_neg \u03b1 a halt0,\n    by_cases hb : b > 0,\n    {\n      have h3bgt0 := pow_pos hb 3,\n      exact lt_trans h3alt0 h3bgt0,\n    },\n    by_cases hb0 : b = 0,\n    {\n      rw hb0,\n      rw simp_pow,\n      assumption,\n    },\n    {\n      have hblt0 := is_lt_0 \u03b1 b hb hb0,\n      have hf := this_be_negative \u03b1 a b h halt0 hblt0,\n      have hf1 := lt_trans h3 hf,\n      finish,\n    }\n  }\nend\n\n-- 1.4. Well-Ordering Principle\n\n-- Exercises for section 1.4\n\n-- 1.5. Finite Induction; Laws of Exponents\n\n-- Exercises for section 1.5\n\n-- 1.6. Divisibility\n\n-- Exercises for section 1.6\n\n-- 1.7. The Euclidean Algorithm\n\n-- Exercises for section 1.7\n\n-- 1.8. Fundamental Theorem of Arithmetic\n\n-- Exercises for section 1.8\n\n-- 1.9. Congruences\n\n-- Exercises for section 1.9\n\n-- 1.10. The Rings \u2124n\n\n-- Exercises for section 1.10\n\n-- 1.11. Sets, Functions, and Relations\n\n-- Exercises for section 1.11\n\n-- 1.12. Isomorphisms and Automorphisms\n\n-- Exercises for section 1.12\n\n", "meta": {"author": "catskillsresearch", "repo": "grundbegriffe", "sha": "e8aa4fe66308d9e6e85d5bdedd9d981af99f17f7", "save_path": "github-repos/lean/catskillsresearch-grundbegriffe", "path": "github-repos/lean/catskillsresearch-grundbegriffe/grundbegriffe-e8aa4fe66308d9e6e85d5bdedd9d981af99f17f7/src/maclane_birkhoff_survey_modern_algebra_sections_1.3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.7055672616383609}}
{"text": "/-\n/-- `|{a : F // is_quad_residue a}| * 2 = |F| - 1` -/\ntheorem card_residues_mul_two_eq [decidable_eq F] (hp: p \u2260 2) :\nfintype.card {a : F // is_quad_residue a} * 2 = q - 1 :=\nby rwa [\u2190 card_units, card_units_eq_card_residues_mul_two F hp]\n-/\n\n/-\nlemma residues_setcard_eq_fintype_card [decidable_eq F] :\nset.card {a : F | is_quad_residue a} = fintype.card {a : F // is_quad_residue a} :=\nset.to_finset_card {a : F | is_quad_residue a}\n\nlemma non_residues_setcard_eq_fintype_card [decidable_eq F] :\nset.card {a : F | is_non_residue a} = fintype.card {a : F // is_non_residue a} :=\nset.to_finset_card {a : F | is_non_residue a}\n\nlemma disjoint_residues_non_residues [decidable_eq F] : \ndisjoint {a : F | is_quad_residue a} {a : F | is_non_residue a} :=\nbegin \n  simp [set.disjoint_iff_inter_eq_empty, is_non_residue, is_quad_residue], \n  ext, simp,\n  rintros h b rfl _,\n  use b,\nend\n\nlemma residues_union_non_residues [decidable_eq F] : \n{a : F | is_quad_residue a} \u222a {a : F | is_non_residue a} = {a : F | a \u2260 0} :=\nbegin\n  ext,\n  simp [is_non_residue, is_quad_residue, \u2190and_or_distrib_left],\n  intros,\n  convert or_not,\n  simp,\nend \n\nlemma univ_setcard_split [decidable_eq F] : \n(@set.univ F).card = {a : F | a \u2260 0}.card + ({0} : set F).card :=\nset.card_disjoint_union' (disjoint_units_zero F) (units_union_zero F)\n\nlemma zero_setcard_eq_one [decidable_eq F] : ({0} : set F).card = 1 := \nby simp [set.card]\n\nlemma univ_setcard_eq_units_setcard_add_one [decidable_eq F] : \n(@set.univ F).card = {a : F | a \u2260 0}.card + 1 :=\nby rw [univ_setcard_split,zero_setcard_eq_one]\n\nlemma units_setcard_split [decidable_eq F] : \n{a : F | a \u2260 0}.card = {a : F | is_quad_residue a}.card + {a : F | is_non_residue a}.card  :=\nset.card_disjoint_union' (disjoint_residues_non_residues F) (residues_union_non_residues F)\n\n@[simp] lemma in_residues_sum_one_eq [decidable_eq F] : \n\u2211 i in {a : F | is_quad_residue a}.to_finset, (1 : \u211a) = {a : F | is_quad_residue a}.card :=\nby simp only [set.card, finset.card_eq_sum_ones_\u211a]\n\n@[simp] lemma in_non_residues_sum_neg_one_eq [decidable_eq F] : \n\u2211 i in {a : F | is_non_residue a}.to_finset, (-1 : \u211a) = - {a : F | is_non_residue a}.card :=\nby simp only [set.card, finset.card_eq_sum_ones_\u211a, sum_neg_distrib]\n-/\n\n/-\nvariable {F}\n\n/-- The cardinality of quadratic residues equals that of non-residues. -/\nlemma card_residues_eq_card_non_residues_set [decidable_eq F] (hp : p \u2260 2):\n{a : F | is_quad_residue a}.card = {a : F | is_non_residue a}.card :=\nbegin\n  have h:= card_residues_mul_two_eq F hp,\n  rw [card_eq_set_card_of_univ F, \u2190residues_setcard_eq_fintype_card, \n      univ_setcard_eq_units_setcard_add_one,  units_setcard_split] at h,\n  simp [mul_two, *] at *,\nend\n\n/-- `fintype` version of `finite_field.card_residues_eq_card_non_residues_set` . -/\nlemma card_residues_eq_card_non_residues_subtpye [decidable_eq F] (hp : p \u2260 2):\nfintype.card {a : F // is_quad_residue a} = fintype.card {a : F // is_non_residue a} :=\nby rwa [\u2190residues_setcard_eq_fintype_card, \u2190non_residues_setcard_eq_fintype_card, \n        card_residues_eq_card_non_residues_set hp]\n\n-/\n\n/-\nlemma quad_char.sum_in_units_eq_zero (hp : p \u2260 2):\n\u2211 (b : F) in univ.filter (\u03bb b, b \u2260 (0 : F)), \u03c7 b = 0 :=\nbegin\n  rw [finset.sum_split _ (\u03bb b : F, is_quad_residue b)],\n  have h1 : \u2211 (j : F) in filter (\u03bb (b : F), is_quad_residue b) (filter (\u03bb (b : F), b \u2260 0) univ), \u03c7 j =\n            \u2211 (j : F) in {a : F | is_quad_residue a}.to_finset, 1,\n  { apply finset.sum_congr,\n    {ext, split, all_goals {intro h, simp* at *}, use h.1},\n    intros x hx,\n    simp* at * },\n  have h2 : \u2211 (j : F) in filter (\u03bb (x : F), \u00acis_quad_residue x) (filter (\u03bb (b : F), b \u2260 0) univ), \u03c7 j =\n            \u2211 (j : F) in {a : F | is_non_residue a}.to_finset, -1,\n  { apply finset.sum_congr,\n    {ext, split, all_goals {intro h, simp [*, is_non_residue, is_quad_residue] at *}},\n    intros x hx,\n    simp* at * },\n  simp at h1 h2,\n  simp [h1, h2],      \nend\n\n-/\n\n/-\n/-- helper of `quad_char.sum_mul'`: reindex the terms in the summation -/\nlemma quad_char.sum_mul'_aux {c : F} (hc : c \u2260 0) :\n\u2211 (b : F) in filter (\u03bb (b : F), \u00acb = 0) univ, \u03c7 (b\u207b\u00b9 * (b + c)) =\n\u2211 (z : F) in filter (\u03bb (z : F), \u00acz = 1) univ, \u03c7 (z) :=\nbegin\n  refine finset.sum_bij \n  (\u03bb b hb, b\u207b\u00b9 * (b + c)) (\u03bb b hb, _) (\u03bb b hb, rfl) (\u03bb b\u2081 b\u2082 h1 h2 h, _) (\u03bb z hz, _),\n  { simp at hb, simp [*, mul_add] at * },\n  { simp at h1 h2, rw mul_add at h, rw mul_add at h, simp* at h, assumption},\n  { use c * (z - 1)\u207b\u00b9, simp, simp at hz, push_neg, refine \u27e8\u27e8hc, sub_ne_zero.mpr hz\u27e9, _\u27e9, \n    simp [*, mul_inv_rev', mul_add, mul_assoc, sub_ne_zero.mpr hz] }\nend\n-/\n\n/-\ntheorem quad_char.sum_mul' {c : F} (hc : c \u2260 0) (hp : p \u2260 2): \n\u2211 b : F, \u03c7 (b) * \u03c7 (b + c) = -1 := \nbegin\n  rw [finset.sum_split _ (\u03bb b, b \u2260 (0 : F))],\n  simp,\n  have h: \u2211 (b : F) in filter (\u03bb (b : F), \u00acb = 0) univ, \u03c7 b * \u03c7 (b + c) = \n          \u2211 (b : F) in filter (\u03bb (b : F), \u00acb = 0) univ, \u03c7 b * \u03c7 b * \u03c7 (b\u207b\u00b9 * (b + c)),\n  { apply finset.sum_congr rfl,\n    intros b hb, simp at hb, \n    have : b * b * (b\u207b\u00b9 * (b + c)) = b * (b + c), {field_simp, ring},\n    repeat {rw \u2190(quad_char_mul hp)}, rw \u2190 this,\n    all_goals {assumption} },\n  have h': \u2211 (b : F) in filter (\u03bb (b : F), \u00acb = 0) univ, \u03c7 b * \u03c7 b * \u03c7 (b\u207b\u00b9 * (b + c)) = \n           \u2211 (b : F) in filter (\u03bb (b : F), \u00acb = 0) univ, \u03c7 (b\u207b\u00b9 * (b + c)),\n  { apply finset.sum_congr rfl, intros b hb, simp* at *},\n  rw [h, h', quad_char.sum_mul'_aux hc],\n  have g:= @finset.sum_split _ _ _ (@finset.univ F _) (\u03c7) (\u03bb b : F, b \u2260 (1 : F)) _,\n  simp [quad_char.sum_eq_zero F hp] at g,\n  rw [\u2190 sub_zero (\u2211 (z : F) in filter (\u03bb (b : F), \u00acb = 1) univ, \u03c7 z), g],\n  ring,\nend \n-/\n\n/-\nCan keep this.\n\nvariables (F)\n\n/-- The subtype of `F` containing quadratic residues. -/\ndef quad_residues := {a : F // is_quad_residue a}\n/-- The set containing quadratic residues of `F`. -/\ndef quad_residues_set [decidable_eq F] := {a : F | is_quad_residue a}\n\n/-- The subtype of `F` containing quadratic non-residues. -/\ndef non_residues := {a : F // is_non_residue a}\n/-- The set containing quadratic non-residues of `F`. -/\ndef non_residues_set [decidable_eq F] := {a : F | is_non_residue a}\n\ninstance [decidable_eq F] : fintype (quad_residues F) := \nby {unfold quad_residues, apply_instance}\n\ninstance [decidable_eq F] : fintype (non_residues F) := \nby {unfold non_residues, apply_instance}\n\n-/", "meta": {"author": "l534zhan", "repo": "my_project", "sha": "8949e149c242debd7cf932ba252cb67b10e78a43", "save_path": "github-repos/lean/l534zhan-my_project", "path": "github-repos/lean/l534zhan-my_project/my_project-8949e149c242debd7cf932ba252cb67b10e78a43/src/backup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160258, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7055622056971937}}
{"text": "/-\nCopyright (c) 2021 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n-/\nimport data.finset.locally_finite\nimport data.fintype.big_operators\n\n/-!\n# Intervals in a pi type\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file shows that (dependent) functions to locally finite orders equipped with the pointwise\norder are locally finite and calculates the cardinality of their intervals.\n-/\n\nopen finset fintype\nopen_locale big_operators\n\nvariables {\u03b9 : Type*} {\u03b1 : \u03b9 \u2192 Type*}\n\n\nnamespace pi\n\nsection locally_finite\nvariables [decidable_eq \u03b9] [fintype \u03b9] [\u03a0 i, decidable_eq (\u03b1 i)]\n  [\u03a0 i, partial_order (\u03b1 i)] [\u03a0 i, locally_finite_order (\u03b1 i)]\n\ninstance : locally_finite_order (\u03a0 i, \u03b1 i) :=\nlocally_finite_order.of_Icc _\n  (\u03bb a b, pi_finset $ \u03bb i, Icc (a i) (b i))\n  (\u03bb a b x, by simp_rw [mem_pi_finset, mem_Icc, le_def, forall_and_distrib])\n\nvariables (a b : \u03a0 i, \u03b1 i)\n\nlemma Icc_eq : Icc a b = pi_finset (\u03bb i, Icc (a i) (b i)) := rfl\n\nlemma card_Icc : (Icc a b).card = \u220f i, (Icc (a i) (b i)).card := card_pi_finset _\n\nlemma card_Ico : (Ico a b).card = (\u220f i, (Icc (a i) (b i)).card) - 1 :=\nby rw [card_Ico_eq_card_Icc_sub_one, card_Icc]\n\nlemma card_Ioc : (Ioc a b).card = (\u220f i, (Icc (a i) (b i)).card) - 1 :=\nby rw [card_Ioc_eq_card_Icc_sub_one, card_Icc]\n\nlemma card_Ioo : (Ioo a b).card = (\u220f i, (Icc (a i) (b i)).card) - 2 :=\nby rw [card_Ioo_eq_card_Icc_sub_two, card_Icc]\n\nend locally_finite\n\nsection bounded\nvariables [decidable_eq \u03b9] [fintype \u03b9] [\u03a0 i, decidable_eq (\u03b1 i)] [\u03a0 i, partial_order (\u03b1 i)]\n\nsection bot\nvariables [\u03a0 i, locally_finite_order_bot (\u03b1 i)] (b : \u03a0 i, \u03b1 i)\n\ninstance : locally_finite_order_bot (\u03a0 i, \u03b1 i) :=\nlocally_finite_order_top.of_Iic _\n  (\u03bb b, pi_finset $ \u03bb i, Iic (b i))\n  (\u03bb b x, by simp_rw [mem_pi_finset, mem_Iic, le_def])\n\nlemma card_Iic : (Iic b).card = \u220f i, (Iic (b i)).card := card_pi_finset _\n\nlemma card_Iio : (Iio b).card = (\u220f i, (Iic (b i)).card) - 1 :=\nby rw [card_Iio_eq_card_Iic_sub_one, card_Iic]\n\nend bot\n\nsection top\nvariables [\u03a0 i, locally_finite_order_top (\u03b1 i)] (a : \u03a0 i, \u03b1 i)\n\ninstance : locally_finite_order_top (\u03a0 i, \u03b1 i) :=\nlocally_finite_order_top.of_Ici _\n  (\u03bb a, pi_finset $ \u03bb i, Ici (a i))\n  (\u03bb a x, by simp_rw [mem_pi_finset, mem_Ici, le_def])\n\nlemma card_Ici : (Ici a).card = (\u220f i, (Ici (a i)).card) := card_pi_finset _\n\nlemma card_Ioi : (Ioi a).card = (\u220f i, (Ici (a i)).card) - 1 :=\nby rw [card_Ioi_eq_card_Ici_sub_one, card_Ici]\n\nend top\n\nend bounded\n\nend pi\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/pi/interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7055621896874711}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.ordinal_arithmetic\n\n/-!\n### Principal ordinals\n\nWe define principal or indecomposable ordinals, and we prove the standard properties about them.\n\n### Todo\n* Prove the characterization of additive principal ordinals.\n* Prove the characterization of multiplicative principal ordinals.\n* Refactor any related theorems from `ordinal_arithmetic` into this file.\n-/\n\nuniverse u\n\nnoncomputable theory\n\nnamespace ordinal\n\n/-! ### Principal ordinals -/\n\n/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of\nordinals less than it is closed under that operation. In standard mathematical usage, this term is\nalmost exclusively used for additive and multiplicative principal ordinals.\n\nFor simplicity, we break usual convention and regard 0 as principal. -/\ndef principal (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : Prop :=\n\u2200 \u2983a b\u2984, a < o \u2192 b < o \u2192 op a b < o\n\ntheorem principal_iff_principal_swap {op : ordinal \u2192 ordinal \u2192 ordinal} {o : ordinal} :\n  principal op o \u2194 principal (function.swap op) o :=\nby split; exact \u03bb h a b ha hb, h hb ha\n\ntheorem principal_zero {op : ordinal \u2192 ordinal \u2192 ordinal} : principal op 0 :=\n\u03bb a _ h, (ordinal.not_lt_zero a h).elim\n\n@[simp] theorem principal_one_iff {op : ordinal \u2192 ordinal \u2192 ordinal} :\n  principal op 1 \u2194 op 0 0 = 0 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h a b ha hb, _\u27e9,\n  { rwa \u2190lt_one_iff_zero,\n    exact h zero_lt_one zero_lt_one },\n  { rwa [lt_one_iff_zero, ha, hb] at * }\nend\n\ntheorem principal.iterate_lt {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal} (hao : a < o)\n  (ho : principal op o) (n : \u2115) : (op a)^[n] a < o :=\nbegin\n  induction n with n hn,\n  { rwa function.iterate_zero },\n  { rw function.iterate_succ', exact ho hao hn }\nend\n\ntheorem op_eq_self_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal} {a o : ordinal.{u}}\n  (hao : a < o) (H : is_normal (op a)) (ho : principal op o) (ho' : is_limit o) : op a o = o :=\nbegin\n  refine le_antisymm _ (H.le_self _),\n  rw [\u2190is_normal.bsup_eq.{u u} H ho', bsup_le],\n  exact \u03bb b hbo, le_of_lt (ho hao hbo)\nend\n\ntheorem nfp_le_of_principal {op : ordinal \u2192 ordinal \u2192 ordinal}\n  {a o : ordinal} (hao : a < o) (ho : principal op o) : nfp (op a) a \u2264 o :=\nnfp_le.2 $ \u03bb n, le_of_lt (ho.iterate_lt hao n)\n\n/-! ### Principal ordinals are unbounded -/\n\n/-- The least strict upper bound of `op` applied to all pairs of ordinals less than `o`. This is\nessentially a two-argument version of `ordinal.blsub`. -/\ndef blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) : ordinal :=\nlsub (\u03bb x : o.out.\u03b1 \u00d7 o.out.\u03b1, op (typein o.out.r x.1) (typein o.out.r x.2))\n\ntheorem lt_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) {o : ordinal} {a b : ordinal} (ha : a < o)\n  (hb : b < o) : op a b < blsub\u2082 op o :=\nbegin\n  convert lt_lsub _ (prod.mk (enum o.out.r a (by rwa type_out)) (enum o.out.r b (by rwa type_out))),\n  simp only [typein_enum]\nend\n\ntheorem principal_nfp_blsub\u2082 (op : ordinal \u2192 ordinal \u2192 ordinal) (o : ordinal) :\n  principal op (nfp (blsub\u2082.{u u} op) o) :=\nbegin\n  intros a b ha hb,\n  rw lt_nfp at *,\n  cases ha with m hm,\n  cases hb with n hn,\n  cases le_total ((blsub\u2082.{u u} op)^[m] o) ((blsub\u2082.{u u} op)^[n] o) with h h,\n  { use n + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op (hm.trans_le h) hn },\n  { use m + 1,\n    rw function.iterate_succ',\n    exact lt_blsub\u2082 op hm (hn.trans_le h) },\nend\n\ntheorem unbounded_principal (op : ordinal \u2192 ordinal \u2192 ordinal) :\n  set.unbounded (<) {o | principal op o} :=\n\u03bb o, \u27e8_, principal_nfp_blsub\u2082 op o, (le_nfp_self _ o).not_lt\u27e9\n\nend ordinal\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/set_theory/principal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7055621853705406}}
{"text": "import data.set.function\n\nopen set\n\nuniverses u v\nvariable {\u03b1 : Type u}\nvariable {\u03b2 : Type v}\nvariable (f : \u03b1 \u2192 \u03b2)\nvariable (s : set \u03b1)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que f es inyectiva sobre s syss\n--    \u2200 {x\u2081 x\u2082}, x\u2081 \u2208 s \u2192 x\u2082 \u2208 s \u2192 f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082\n-- ----------------------------------------------------------------------\n\nexample :\n  inj_on f s \u2194\n  \u2200 \u2983x\u2081 : \u03b1\u2984, x\u2081 \u2208 s \u2192 \u2200 \u2983x\u2082 : \u03b1\u2984, x\u2082 \u2208 s \u2192 f x\u2081 = f x\u2082 \u2192 x\u2081 = x\u2082 :=\niff.rfl\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Definicion_de_inyectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.7054793403060199}}
{"text": "\n\ntheorem tst1 (x y z : Nat) : y = z \u2192 x = x \u2192 x = y \u2192 x = z :=\nby {\n  intros h1 h2 h3;\n  revert h2;\n  intro h2;\n  exact Eq.trans h3 h1\n}\n\ntheorem tst2 (x y z : Nat) : y = z \u2192 x = x \u2192 x = y \u2192 x = z :=\nby {\n  intros h1 h2 h3;\n  revert y;\n  intros y hb ha;\n  exact Eq.trans ha hb\n}\n\ntheorem tst3 (x y z : Nat) : y = z \u2192 x = x \u2192 x = y \u2192 x = z := by\n  intros\n  revert \u2039x = y\u203a\n  intro ha\n  exact Eq.trans ha \u2039y = z\u203a\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/revert1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.7054793284961282}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.calculus.inverse\nimport analysis.normed_space.complemented\n\n/-!\n# Implicit function theorem\n\nWe prove three versions of the implicit function theorem. First we define a structure\n`implicit_function_data` that holds arguments for the most general version of the implicit function\ntheorem, see `implicit_function_data.implicit_function`\nand `implicit_function_data.to_implicit_function`. This version allows a user to choose\na specific implicit function but provides only a little convenience over the inverse function\ntheorem.\n\nThen we define `implicit_function_of_complemented`: implicit function defined by `f (g z y) = z`,\nwhere `f : E \u2192 F` is a function strictly differentiable at `a` such that its derivative `f'`\nis surjective and has a `complemented` kernel.\n\nFinally, if the codomain of `f` is a finite dimensional space, then we can automatically prove\nthat the kernel of `f'` is complemented, hence the only assumptions are `has_strict_fderiv_at`\nand `f'.range = \u22a4`. This version is named `implicit_function`.\n\n## TODO\n\n* Add a version for a function `f : E \u00d7 F \u2192 G` such that $$\\frac{\\partial f}{\\partial y}$$ is\n  invertible.\n* Add a version for `f : \ud835\udd5c \u00d7 \ud835\udd5c \u2192 \ud835\udd5c` proving `has_strict_deriv_at` and `deriv \u03c6 = ...`.\n* Prove that in a real vector space the implicit function has the same smoothness as the original\n  one.\n* If the original function is differentiable in a neighborhood, then the implicit function is\n  differentiable in a neighborhood as well. Current setup only proves differentiability at one\n  point for the implicit function constructed in this file (as opposed to an unspecified implicit\n  function). One of the ways to overcome this difficulty is to use uniqueness of the implicit\n  function in the general version of the theorem. Another way is to prove that *any* implicit\n  function satisfying some predicate is strictly differentiable.\n\n## Tags\n\nimplicit function, inverse function\n-/\n\nnoncomputable theory\n\nopen_locale topology\nopen filter\nopen continuous_linear_map (fst snd smul_right ker_prod)\nopen continuous_linear_equiv (of_bijective)\nopen linear_map (ker range)\n\n/-!\n### General version\n\nConsider two functions `f : E \u2192 F` and `g : E \u2192 G` and a point `a` such that\n\n* both functions are strictly differentiable at `a`;\n* the derivatives are surjective;\n* the kernels of the derivatives are complementary subspaces of `E`.\n\nNote that the map `x \u21a6 (f x, g x)` has a bijective derivative, hence it is a local homeomorphism\nbetween `E` and `F \u00d7 G`. We use this fact to define a function `\u03c6 : F \u2192 G \u2192 E`\n(see `implicit_function_data.implicit_function`) such that for `(y, z)` close enough to `(f a, g a)`\nwe have `f (\u03c6 y z) = y` and `g (\u03c6 y z) = z`.\n\nWe also prove a formula for $$\\frac{\\partial\\varphi}{\\partial z}.$$\n\nThough this statement is almost symmetric with respect to `F`, `G`, we interpret it in the following\nway. Consider a family of surfaces `{x | f x = y}`, `y \u2208 \ud835\udcdd (f a)`. Each of these surfaces is\nparametrized by `\u03c6 y`.\n\nThere are many ways to choose a (differentiable) function `\u03c6` such that `f (\u03c6 y z) = y` but the\nextra condition `g (\u03c6 y z) = z` allows a user to select one of these functions. If we imagine\nthat the level surfaces `f = const` form a local horizontal foliation, then the choice of\n`g` fixes a transverse foliation `g = const`, and `\u03c6` is the inverse function of the projection\nof `{x | f x = y}` along this transverse foliation.\n\nThis version of the theorem is used to prove the other versions and can be used if a user\nneeds to have a complete control over the choice of the implicit function.\n-/\n\n/-- Data for the general version of the implicit function theorem. It holds two functions\n`f : E \u2192 F` and `g : E \u2192 G` (named `left_fun` and `right_fun`) and a point `a` (named `pt`)\nsuch that\n\n* both functions are strictly differentiable at `a`;\n* the derivatives are surjective;\n* the kernels of the derivatives are complementary subspaces of `E`. -/\n@[nolint has_nonempty_instance]\nstructure implicit_function_data (\ud835\udd5c : Type*) [nontrivially_normed_field \ud835\udd5c]\n  (E : Type*) [normed_add_comm_group E] [normed_space \ud835\udd5c E] [complete_space E]\n  (F : Type*) [normed_add_comm_group F] [normed_space \ud835\udd5c F] [complete_space F]\n  (G : Type*) [normed_add_comm_group G] [normed_space \ud835\udd5c G] [complete_space G] :=\n(left_fun : E \u2192 F)\n(left_deriv : E \u2192L[\ud835\udd5c] F)\n(right_fun : E \u2192 G)\n(right_deriv : E \u2192L[\ud835\udd5c] G)\n(pt : E)\n(left_has_deriv : has_strict_fderiv_at left_fun left_deriv pt)\n(right_has_deriv : has_strict_fderiv_at right_fun right_deriv pt)\n(left_range : range left_deriv = \u22a4)\n(right_range : range right_deriv = \u22a4)\n(is_compl_ker : is_compl (ker left_deriv) (ker right_deriv))\n\nnamespace implicit_function_data\n\nvariables {\ud835\udd5c : Type*} [nontrivially_normed_field \ud835\udd5c]\n  {E : Type*} [normed_add_comm_group E] [normed_space \ud835\udd5c E] [complete_space E]\n  {F : Type*} [normed_add_comm_group F] [normed_space \ud835\udd5c F] [complete_space F]\n  {G : Type*} [normed_add_comm_group G] [normed_space \ud835\udd5c G] [complete_space G]\n  (\u03c6 : implicit_function_data \ud835\udd5c E F G)\n\n/-- The function given by `x \u21a6 (left_fun x, right_fun x)`. -/\ndef prod_fun (x : E) : F \u00d7 G := (\u03c6.left_fun x, \u03c6.right_fun x)\n\n@[simp] lemma prod_fun_apply (x : E) : \u03c6.prod_fun x = (\u03c6.left_fun x, \u03c6.right_fun x) := rfl\n\nprotected lemma has_strict_fderiv_at :\n  has_strict_fderiv_at \u03c6.prod_fun\n    (\u03c6.left_deriv.equiv_prod_of_surjective_of_is_compl \u03c6.right_deriv \u03c6.left_range \u03c6.right_range\n       \u03c6.is_compl_ker : E \u2192L[\ud835\udd5c] F \u00d7 G) \u03c6.pt :=\n\u03c6.left_has_deriv.prod \u03c6.right_has_deriv\n\n/-- Implicit function theorem. If `f : E \u2192 F` and `g : E \u2192 G` are two maps strictly differentiable\nat `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are\ncomplementary subspaces of `E`, then `x \u21a6 (f x, g x)` defines a local homeomorphism between\n`E` and `F \u00d7 G`. In particular, `{x | f x = f a}` is locally homeomorphic to `G`. -/\ndef to_local_homeomorph : local_homeomorph E (F \u00d7 G) :=\n\u03c6.has_strict_fderiv_at.to_local_homeomorph _\n\n/-- Implicit function theorem. If `f : E \u2192 F` and `g : E \u2192 G` are two maps strictly differentiable\nat `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are\ncomplementary subspaces of `E`, then `implicit_function_of_is_compl_ker` is the unique (germ of a)\nmap `\u03c6 : F \u2192 G \u2192 E` such that `f (\u03c6 y z) = y` and `g (\u03c6 y z) = z`. -/\ndef implicit_function : F \u2192 G \u2192 E := function.curry $ \u03c6.to_local_homeomorph.symm\n\n@[simp] lemma to_local_homeomorph_coe : \u21d1(\u03c6.to_local_homeomorph) = \u03c6.prod_fun := rfl\n\nlemma to_local_homeomorph_apply (x : E) :\n  \u03c6.to_local_homeomorph x = (\u03c6.left_fun x, \u03c6.right_fun x) :=\nrfl\n\nlemma pt_mem_to_local_homeomorph_source :\n  \u03c6.pt \u2208 \u03c6.to_local_homeomorph.source :=\n\u03c6.has_strict_fderiv_at.mem_to_local_homeomorph_source\n\nlemma map_pt_mem_to_local_homeomorph_target :\n  (\u03c6.left_fun \u03c6.pt, \u03c6.right_fun \u03c6.pt) \u2208 \u03c6.to_local_homeomorph.target :=\n\u03c6.to_local_homeomorph.map_source $ \u03c6.pt_mem_to_local_homeomorph_source\n\nlemma prod_map_implicit_function :\n  \u2200\u1da0 (p : F \u00d7 G) in \ud835\udcdd (\u03c6.prod_fun \u03c6.pt), \u03c6.prod_fun (\u03c6.implicit_function p.1 p.2) = p :=\n\u03c6.has_strict_fderiv_at.eventually_right_inverse.mono $ \u03bb \u27e8z, y\u27e9 h, h\n\nlemma left_map_implicit_function :\n  \u2200\u1da0 (p : F \u00d7 G) in \ud835\udcdd (\u03c6.prod_fun \u03c6.pt), \u03c6.left_fun (\u03c6.implicit_function p.1 p.2) = p.1 :=\n\u03c6.prod_map_implicit_function.mono $ \u03bb z, congr_arg prod.fst\n\nlemma right_map_implicit_function :\n  \u2200\u1da0 (p : F \u00d7 G) in \ud835\udcdd (\u03c6.prod_fun \u03c6.pt), \u03c6.right_fun (\u03c6.implicit_function p.1 p.2) = p.2 :=\n\u03c6.prod_map_implicit_function.mono $ \u03bb z, congr_arg prod.snd\n\nlemma implicit_function_apply_image :\n  \u2200\u1da0 x in \ud835\udcdd \u03c6.pt, \u03c6.implicit_function (\u03c6.left_fun x) (\u03c6.right_fun x) = x :=\n\u03c6.has_strict_fderiv_at.eventually_left_inverse\n\nlemma map_nhds_eq : map \u03c6.left_fun (\ud835\udcdd \u03c6.pt) = \ud835\udcdd (\u03c6.left_fun \u03c6.pt) :=\nshow map (prod.fst \u2218 \u03c6.prod_fun) (\ud835\udcdd \u03c6.pt) = \ud835\udcdd (\u03c6.prod_fun \u03c6.pt).1,\nby rw [\u2190 map_map, \u03c6.has_strict_fderiv_at.map_nhds_eq_of_equiv, map_fst_nhds]\n\nlemma implicit_function_has_strict_fderiv_at\n  (g'inv : G \u2192L[\ud835\udd5c] E) (hg'inv : \u03c6.right_deriv.comp g'inv = continuous_linear_map.id \ud835\udd5c G)\n  (hg'invf : \u03c6.left_deriv.comp g'inv = 0) :\n  has_strict_fderiv_at (\u03c6.implicit_function (\u03c6.left_fun \u03c6.pt)) g'inv (\u03c6.right_fun \u03c6.pt) :=\nbegin\n  have := \u03c6.has_strict_fderiv_at.to_local_inverse,\n  simp only [prod_fun] at this,\n  convert this.comp (\u03c6.right_fun \u03c6.pt)\n    ((has_strict_fderiv_at_const _ _).prod (has_strict_fderiv_at_id _)),\n  simp only [continuous_linear_map.ext_iff, continuous_linear_map.coe_comp', function.comp_app]\n    at hg'inv hg'invf \u22a2,\n  simp [continuous_linear_equiv.eq_symm_apply, *]\nend\n\nend implicit_function_data\n\nnamespace has_strict_fderiv_at\n\nsection complemented\n\n/-!\n### Case of a complemented kernel\n\nIn this section we prove the following version of the implicit function theorem. Consider a map\n`f : E \u2192 F` and a point `a : E` such that `f` is strictly differentiable at `a`, its derivative `f'`\nis surjective and the kernel of `f'` is a complemented subspace of `E` (i.e., it has a closed\ncomplementary subspace). Then there exists a function `\u03c6 : F \u2192 ker f' \u2192 E` such that for `(y, z)`\nclose to `(f a, 0)` we have `f (\u03c6 y z) = y` and the derivative of `\u03c6 (f a)` at zero is the\nembedding `ker f' \u2192 E`.\n\nNote that a map with these properties is not unique. E.g., different choices of a subspace\ncomplementary to `ker f'` lead to different maps `\u03c6`.\n-/\n\nvariables {\ud835\udd5c : Type*} [nontrivially_normed_field \ud835\udd5c]\n  {E : Type*} [normed_add_comm_group E] [normed_space \ud835\udd5c E] [complete_space E]\n  {F : Type*} [normed_add_comm_group F] [normed_space \ud835\udd5c F] [complete_space F]\n  {f : E \u2192 F} {f' : E \u2192L[\ud835\udd5c] F} {a : E}\n\nsection defs\n\nvariables (f f')\n\n/-- Data used to apply the generic implicit function theorem to the case of a strictly\ndifferentiable map such that its derivative is surjective and has a complemented kernel. -/\n@[simp] def implicit_function_data_of_complemented (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  implicit_function_data \ud835\udd5c E F (ker f') :=\n{ left_fun := f,\n  left_deriv := f',\n  right_fun := \u03bb x, classical.some hker (x - a),\n  right_deriv := classical.some hker,\n  pt := a,\n  left_has_deriv := hf,\n  right_has_deriv := (classical.some hker).has_strict_fderiv_at.comp a\n    ((has_strict_fderiv_at_id a).sub_const a),\n  left_range := hf',\n  right_range := linear_map.range_eq_of_proj (classical.some_spec hker),\n  is_compl_ker := linear_map.is_compl_of_proj (classical.some_spec hker) }\n\n/-- A local homeomorphism between `E` and `F \u00d7 f'.ker` sending level surfaces of `f`\nto vertical subspaces. -/\ndef implicit_to_local_homeomorph_of_complemented (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  local_homeomorph E (F \u00d7 (ker f')) :=\n(implicit_function_data_of_complemented f f' hf hf' hker).to_local_homeomorph\n\n/-- Implicit function `g` defined by `f (g z y) = z`. -/\ndef implicit_function_of_complemented (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  F \u2192 (ker f') \u2192 E :=\n(implicit_function_data_of_complemented f f' hf hf' hker).implicit_function\n\nend defs\n\n@[simp] lemma implicit_to_local_homeomorph_of_complemented_fst (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) (x : E) :\n  (hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker x).fst = f x :=\nrfl\n\nlemma implicit_to_local_homeomorph_of_complemented_apply\n  (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4)\n  (hker : (ker f').closed_complemented) (y : E) :\n  hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker y =\n    (f y, classical.some hker (y - a)) :=\nrfl\n\n@[simp] lemma implicit_to_local_homeomorph_of_complemented_apply_ker\n  (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4)\n  (hker : (ker f').closed_complemented) (y : ker f') :\n  hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker (y + a) = (f (y + a), y) :=\nby simp only [implicit_to_local_homeomorph_of_complemented_apply, add_sub_cancel,\n  classical.some_spec hker]\n\n@[simp] lemma implicit_to_local_homeomorph_of_complemented_self\n  (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker a = (f a, 0) :=\nby simp [hf.implicit_to_local_homeomorph_of_complemented_apply]\n\nlemma mem_implicit_to_local_homeomorph_of_complemented_source (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  a \u2208 (hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).source :=\nmem_to_local_homeomorph_source _\n\nlemma mem_implicit_to_local_homeomorph_of_complemented_target (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  (f a, (0 : ker f')) \u2208 (hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).target :=\nby simpa only [implicit_to_local_homeomorph_of_complemented_self] using\n  ((hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).map_source $\n    (hf.mem_implicit_to_local_homeomorph_of_complemented_source hf' hker))\n\n/-- `implicit_function_of_complemented` sends `(z, y)` to a point in `f \u207b\u00b9' z`. -/\nlemma map_implicit_function_of_complemented_eq (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  \u2200\u1da0 (p : F \u00d7 (ker f')) in \ud835\udcdd (f a, 0),\n    f (hf.implicit_function_of_complemented f f' hf' hker p.1 p.2) = p.1 :=\n((hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).eventually_right_inverse $\n  hf.mem_implicit_to_local_homeomorph_of_complemented_target hf' hker).mono $ \u03bb \u27e8z, y\u27e9 h,\n    congr_arg prod.fst h\n\n/-- Any point in some neighborhood of `a` can be represented as `implicit_function`\nof some point. -/\n\n\n@[simp] lemma implicit_function_of_complemented_apply_image (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  hf.implicit_function_of_complemented f f' hf' hker (f a) 0 = a :=\nbegin\n  convert (hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).left_inv\n    (hf.mem_implicit_to_local_homeomorph_of_complemented_source hf' hker),\n  exact congr_arg prod.snd (hf.implicit_to_local_homeomorph_of_complemented_self hf' hker).symm\nend\n\nlemma to_implicit_function_of_complemented (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (hker : (ker f').closed_complemented) :\n  has_strict_fderiv_at (hf.implicit_function_of_complemented f f' hf' hker (f a))\n    (ker f').subtypeL 0 :=\nbegin\n  convert (implicit_function_data_of_complemented f f' hf hf'\n    hker).implicit_function_has_strict_fderiv_at (ker f').subtypeL _ _,\n  swap,\n  { ext, simp only [classical.some_spec hker, implicit_function_data_of_complemented,\n                    continuous_linear_map.coe_comp', submodule.coe_subtypeL', submodule.coe_subtype,\n                    function.comp_app, continuous_linear_map.coe_id', id.def] },\n  swap,\n  { ext, simp only [continuous_linear_map.coe_comp', submodule.coe_subtypeL', submodule.coe_subtype,\n                    function.comp_app, linear_map.map_coe_ker, continuous_linear_map.zero_apply] },\n  simp only [implicit_function_data_of_complemented, map_sub, sub_self],\nend\n\nend complemented\n\n/-!\n### Finite dimensional case\n\nIn this section we prove the following version of the implicit function theorem. Consider a map\n`f : E \u2192 F` from a Banach normed space to a finite dimensional space.\nTake a point `a : E` such that `f` is strictly differentiable at `a` and its derivative `f'`\nis surjective. Then there exists a function `\u03c6 : F \u2192 ker f' \u2192 E` such that for `(y, z)`\nclose to `(f a, 0)` we have `f (\u03c6 y z) = y` and the derivative of `\u03c6 (f a)` at zero is the\nembedding `ker f' \u2192 E`.\n\nThis version deduces that `ker f'` is a complemented subspace from the fact that `F` is a finite\ndimensional space, then applies the previous version.\n\nNote that a map with these properties is not unique. E.g., different choices of a subspace\ncomplementary to `ker f'` lead to different maps `\u03c6`.\n-/\n\nsection finite_dimensional\n\nvariables {\ud835\udd5c : Type*} [nontrivially_normed_field \ud835\udd5c] [complete_space \ud835\udd5c]\n  {E : Type*} [normed_add_comm_group E] [normed_space \ud835\udd5c E] [complete_space E]\n  {F : Type*} [normed_add_comm_group F] [normed_space \ud835\udd5c F] [finite_dimensional \ud835\udd5c F]\n  (f : E \u2192 F) (f' : E \u2192L[\ud835\udd5c] F) {a : E}\n\n/-- Given a map `f : E \u2192 F` to a finite dimensional space with a surjective derivative `f'`,\nreturns a local homeomorphism between `E` and `F \u00d7 ker f'`. -/\ndef implicit_to_local_homeomorph (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) :\n  local_homeomorph E (F \u00d7 (ker f')) :=\nby haveI := finite_dimensional.complete \ud835\udd5c F; exact\nhf.implicit_to_local_homeomorph_of_complemented f f' hf'\n  f'.ker_closed_complemented_of_finite_dimensional_range\n\n/-- Implicit function `g` defined by `f (g z y) = z`. -/\ndef implicit_function (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) :\n  F \u2192 (ker f') \u2192 E :=\nfunction.curry $ (hf.implicit_to_local_homeomorph f f' hf').symm\n\nvariables {f f'}\n\n@[simp] lemma implicit_to_local_homeomorph_fst (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) (x : E) :\n  (hf.implicit_to_local_homeomorph f f' hf' x).fst = f x :=\nrfl\n\n@[simp] lemma implicit_to_local_homeomorph_apply_ker\n  (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) (y : ker f') :\n  hf.implicit_to_local_homeomorph f f' hf' (y + a) = (f (y + a), y) :=\nby apply implicit_to_local_homeomorph_of_complemented_apply_ker\n\n@[simp] lemma implicit_to_local_homeomorph_self\n  (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) :\n  hf.implicit_to_local_homeomorph f f' hf' a = (f a, 0) :=\nby apply implicit_to_local_homeomorph_of_complemented_self\n\nlemma mem_implicit_to_local_homeomorph_source (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) :\n  a \u2208 (hf.implicit_to_local_homeomorph f f' hf').source :=\nmem_to_local_homeomorph_source _\n\nlemma mem_implicit_to_local_homeomorph_target (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) :\n  (f a, (0 : ker f')) \u2208 (hf.implicit_to_local_homeomorph f f' hf').target :=\nby apply mem_implicit_to_local_homeomorph_of_complemented_target\n\nlemma tendsto_implicit_function (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) {\u03b1 : Type*} {l : filter \u03b1} {g\u2081 : \u03b1 \u2192 F} {g\u2082 : \u03b1 \u2192 ker f'}\n  (h\u2081 : tendsto g\u2081 l (\ud835\udcdd $ f a)) (h\u2082 : tendsto g\u2082 l (\ud835\udcdd 0)) :\n  tendsto (\u03bb t, hf.implicit_function f f' hf' (g\u2081 t) (g\u2082 t)) l (\ud835\udcdd a) :=\nbegin\n  refine ((hf.implicit_to_local_homeomorph f f' hf').tendsto_symm\n    (hf.mem_implicit_to_local_homeomorph_source hf')).comp _,\n  rw [implicit_to_local_homeomorph_self],\n  exact h\u2081.prod_mk_nhds h\u2082\nend\n\nalias tendsto_implicit_function \u2190 _root_.filter.tendsto.implicit_function\n\n/-- `implicit_function` sends `(z, y)` to a point in `f \u207b\u00b9' z`. -/\nlemma map_implicit_function_eq (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) :\n  \u2200\u1da0 (p : F \u00d7 (ker f')) in \ud835\udcdd (f a, 0), f (hf.implicit_function f f' hf' p.1 p.2) = p.1 :=\nby apply map_implicit_function_of_complemented_eq\n\n@[simp] lemma implicit_function_apply_image (hf : has_strict_fderiv_at f f' a)\n  (hf' : range f' = \u22a4) :\n  hf.implicit_function f f' hf' (f a) 0 = a :=\nby apply implicit_function_of_complemented_apply_image\n\n/-- Any point in some neighborhood of `a` can be represented as `implicit_function`\nof some point. -/\nlemma eq_implicit_function (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) :\n  \u2200\u1da0 x in \ud835\udcdd a, hf.implicit_function f f' hf' (f x)\n    (hf.implicit_to_local_homeomorph f f' hf' x).snd = x :=\nby apply eq_implicit_function_of_complemented\n\nlemma to_implicit_function (hf : has_strict_fderiv_at f f' a) (hf' : range f' = \u22a4) :\n  has_strict_fderiv_at (hf.implicit_function f f' hf' (f a))\n    (ker f').subtypeL 0 :=\nby apply to_implicit_function_of_complemented\n\nend finite_dimensional\n\nend has_strict_fderiv_at\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/calculus/implicit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.7053994961026355}}
{"text": "import algebra.group_power.order\nimport data.nat.prime\nimport tactic.field_simp\nimport tactic.linarith\nimport tactic.ring_exp\n\nimport helper\n\nopen nat\n\ntheorem rootn_not_pn_irr :\n  \u2200 e n : \u2115,\n    \u00ac (\u2203 m : \u2115, m ^ e = n) \u2194 \u2200 q : \u211a, q ^ e \u2260 n := \nbegin\n  intros e n,\n  split,\n  {\n    intros not_perfect_pow q q_to_e_eq_n,\n    \n    by_cases h : q < 0 \u2227 odd e,\n    { \n      have h\u2081 := neg_odd_pow_lemma h.1 h.2,\n      rw q_to_e_eq_n at h\u2081,\n      norm_cast at h\u2081,\n      exact nat.not_lt_zero n h\u2081,\n    },\n    {\n      have h\u2081 : q.num.nat_abs ^ e = n * q.denom ^ e :=\n        begin\n          rw rat.eq_iff_mul_eq_mul at q_to_e_eq_n,\n          norm_cast at q_to_e_eq_n,\n          rw [mul_one, cast_mul] at q_to_e_eq_n,\n          rw \u2190 int.coe_nat_eq_coe_nat_iff,\n          field_simp,\n          cases ((by tauto!) : \u00ac(q < 0) \u2228 \u00ac(odd e)) with h' h',\n          {\n            have q_num_ge_0 : q.num \u2265 0,\n            {\n              rw [ge_iff_le, rat.num_nonneg_iff_zero_le],\n              exact not_lt.1 h',\n            },\n            norm_cast,\n            rw \n              [\n                (rat_pow_lemma _ _).1, \n                (rat_pow_lemma _ _).2, \n                \u2190int.nat_abs_of_nonneg q_num_ge_0\n              ] at q_to_e_eq_n,\n            norm_cast at q_to_e_eq_n,\n            exact q_to_e_eq_n,\n          },  \n          {\n            norm_cast,\n            rw \n              [\n                (rat_pow_lemma _ _).1, \n                (rat_pow_lemma _ _).2, \n                \u2190abs_pow_eq_pow_of_even_exp (nat.even_iff_not_odd.2 h')\n              ] at q_to_e_eq_n,\n            norm_cast at q_to_e_eq_n,\n            exact q_to_e_eq_n,\n          },\n        end,\n\n      by_cases q.denom = 1,\n      {\n        rw [h, one_pow, mul_one] at h\u2081,\n        apply not_perfect_pow,\n        exact \u27e8q.num.nat_abs, h\u2081\u27e9,\n      },\n      {\n        have h\u2082 : q.denom \u2223 q.num.nat_abs :=\n          begin\n            cases e,\n            {\n              exfalso,\n              apply not_perfect_pow,\n              rw pow_zero at q_to_e_eq_n,\n              norm_cast at q_to_e_eq_n,\n              rw \u2190 q_to_e_eq_n,\n              use 0,\n              rw pow_zero,\n            },\n            {\n              apply nat.coprime.dvd_of_dvd_mul_left (coprime.pow_right e q.cop.symm),\n              use (n * q.denom ^ e),\n              conv {\n                congr,\n                rw [nat.mul_comm, \u2190pow_succ],\n                skip,\n                rw [nat.mul_comm, nat.mul_assoc],\n                congr,\n                skip,\n                rw [nat.mul_comm, \u2190pow_succ],\n              },\n              exact h\u2081,\n            },\n          end,\n    \n        have q_cop := q.cop,\n        unfold coprime at q_cop,\n        rw nat.gcd_eq_right_iff_dvd.1 h\u2082 at q_cop, \n        exact h q_cop,\n      },\n    },\n  },\n  {\n    rintros h \u27e8m, h'\u27e9,\n    have h := h m,\n    norm_cast at h,\n  },\nend\n\n\ndef floor_root' (e n : \u2115) : \u2115 \u2192 \u2115\n| 0 := 0\n| k'@(k+1) := if k' ^ e \u2264 n then k' else floor_root' k\n\ndef floor_root (e n : \u2115) : \u2115 := floor_root' e n n\n\n\nlemma floor_root_lemma (e : \u2115) (h : e \u2265 1): \u2200 n : \u2115, (floor_root e n) ^ e \u2264 n \u2227 n < ((floor_root e n) + 1) ^ e :=\n  begin\n    intro n,\n    unfold floor_root,\n    {\n      have h\u2081 : \u2200 e n m : \u2115, e \u2265 1 \u2192 (m + 1) ^ e > n \u2192 floor_root' e n m ^ e \u2264 n \u2227 n < (floor_root' e n m + 1) ^ e,\n      {\n        introv,\n        revert e_1 n_1,\n        induction m,\n        {\n          introv,\n          intros e_ge_1 h\u2081,\n          cases e_1,\n          {\n            linarith,\n          },\n          {\n            rw [one_pow, gt_iff_lt, lt_one_iff] at h\u2081,\n            unfold floor_root',\n            simp only \n              [\n                h\u2081, zero_pow', ne.def, succ_ne_zero, not_false_iff, \n                le_zero_iff, one_pow, lt_one_iff, and_self\n              ],\n          },\n        },\n        {\n          introv,\n          intros e_ge_1 h\u2081,\n          unfold floor_root',\n          split_ifs,\n          {\n            refine \u27e8h_1,h\u2081\u27e9,\n          },\n          {\n            exact m_ih _ _ e_ge_1 (by linarith),\n          },\n        },\n      },\n      apply h\u2081 e n n h,\n      {\n        cases n,\n        {\n          rw [one_pow, gt_iff_lt, lt_one_iff],\n        },\n        {\n          induction e,\n          {\n            linarith,\n          },\n          { \n            cases e_n,\n            {\n              rw [pow_one, gt_iff_lt, lt_add_iff_pos_right, lt_one_iff],\n            },\n            {\n              rw pow_succ,\n              conv {\n                to_rhs,\n                rw \u2190nat.one_mul n.succ,\n              },\n              apply sord_mul_lem,\n              {\n                exact one_lt_succ_succ n,\n              },\n              {\n                apply e_ih,\n                apply succ_le_succ,\n                exact zero_le e_n,\n              },\n            },\n          },\n        },\n      },\n    },\n  end\n\ndef is_perfect_pow (n e : \u2115) := \u2203 m : \u2115, m ^ e = n\n\nlemma is_pp_equiv_lemma (n e : \u2115) : is_perfect_pow n e \u2194 (floor_root e n) ^ e = n :=\n  begin\n    split,\n    {\n      intro h,\n      by_cases h' : e \u2265 1,\n      {\n        rcases h with \u27e8m, h\u27e9,\n        have h\u2081 : floor_root e n = m,\n        {\n          rcases floor_root_lemma e h' n with \u27e8h\u2082, h\u2083\u27e9,\n          conv at h\u2082 {\n            to_rhs,\n            rw \u2190h,\n          },\n          conv at h\u2083 {\n            to_lhs,\n            rw \u2190h,\n          },\n          by_contra,\n          cases eq_or_lt_of_le h\u2082 with h\u2082 h\u2082,\n          {\n            exact h (nat.pow_left_injective h' h\u2082),\n          },\n          {\n            have h\u2082 := pow_ord_lemma e h' h\u2082,\n            have h\u2083 := pow_ord_lemma e h' h\u2083,\n            exact ord_lemma (floor_root e n) \u27e8m, h\u2082, h\u2083\u27e9,\n          },\n        },\n        {\n          rw h\u2081,\n          exact h,\n        },\n      },\n      {\n        have h\u2081 : e = 0,\n        linarith,\n        rw h\u2081 at *,\n        rcases h with \u27e8m, h\u27e9,\n        exact h,\n      },\n    },\n    {\n      intro h,\n      use floor_root e n,\n      exact h,\n    }\n  end\n\ninstance is_perfect_pow_dec (n e : \u2115) : decidable (is_perfect_pow n e) :=\n  decidable_of_iff _ (iff.symm $ is_pp_equiv_lemma n e)\n\ninstance has_no_rational_root_dec (n e : \u2115) : decidable (\u2200 q : \u211a, q ^ e \u2260 \u2191n) :=\n  begin\n    haveI inst : decidable (\u2203 (m : \u2115), m ^ e = n) := \n      eq.rec (is_perfect_pow_dec n e) \n      (by refl : is_perfect_pow n e = (\u2203 (m : \u2115), m ^ e = n)),\n    apply decidable_of_iff _ (rootn_not_pn_irr e n), \n  end\n\ntheorem sqrt_2_irr : \u2200 q : \u211a, q ^ 2 \u2260 2 := \n  begin\n    have h : (2 : \u211a) = \u2191(2 : \u2115) := by norm_cast,\n    rw h,\n    dec_trivial,\n  end \n\nexample : \u2200 q : \u211a, q ^ 5 \u2260 \u2191101 := dec_trivial", "meta": {"author": "Julek", "repo": "lean-sqrt-2-irrational", "sha": "434de488a719932dc5760c4d199a1c780811f7cb", "save_path": "github-repos/lean/Julek-lean-sqrt-2-irrational", "path": "github-repos/lean/Julek-lean-sqrt-2-irrational/lean-sqrt-2-irrational-434de488a719932dc5760c4d199a1c780811f7cb/src/sqrt-2-irr-gen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.7053889118587621}}
{"text": "import MyNat\nimport MyNat.addition_world\nimport MyNat.multiplication_world\n\nopen MyNat\n\nlemma pow_zero (a : \u2115) : a ^ zero = 1 := rfl\nlemma pow_succ (a : \u2115) : a ^ succ b = a * (a ^ b) := rfl\n\nlemma zero_pow_zero : (zero : \u2115) ^ zero = 1 := rfl\n\nlemma zero_pow_succ (m : \u2115) : zero ^ (succ m) = zero :=\n  by rewrite [pow_succ, zero_mul] rfl\n\nlemma pow_one (a : \u2115) : a ^ 1 = a :=\n  by rewrite [one_eq_succ_zero, pow_succ, pow_zero, mul_one] rfl\n\nlemma pow_add (a m n : \u2115) : a ^ (m + n) = a ^ m * a ^ n :=\n  by induction m with\n  | zero => rewrite [zero_add, pow_zero, one_mul] rfl\n  | succ m' ih => rewrite [pow_succ, succ_add, pow_succ, ih, mul_assoc] rfl\n\nlemma mul_pow (a b n : \u2115) : (a * b) ^ n = a ^ n * b ^ n :=\n  by induction n with\n  | zero => rewrite [pow_zero, pow_zero, pow_zero, mul_one] rfl\n  | succ n' ih => rewrite [pow_succ, ih, pow_succ, pow_succ, mul_assoc, mul_comm b, mul_assoc, \u2190mul_assoc, mul_comm _ b] rfl\n\nlemma pow_pow (a m n : \u2115) : (a ^ m) ^ n = a ^ (m * n) := \n by induction n with \n | zero => rewrite [mul_zero, pow_zero, pow_zero] rfl\n | succ n' ih => rewrite [pow_succ, ih, \u2190pow_add, \u2190mul_succ] rfl\n\nlemma add_squared (a b : \u2115) : (a + b) ^ 2 = a ^ 2 + b ^ 2 + (2 * a * b) :=\n  by rewrite [two_eq_succ_one, one_eq_succ_zero, pow_succ, pow_succ, pow_succ, pow_succ, pow_succ, pow_succ, pow_zero, mul_one, pow_zero, mul_one, pow_zero, mul_one, add_mul, mul_add, mul_add, mul_comm b a, add_right_comm, add_comm (a * b), add_assoc, add_assoc, add_same, \u2190add_assoc, \u2190one_eq_succ_zero, \u2190two_eq_succ_one, \u2190mul_assoc] rfl", "meta": {"author": "alexkassil", "repo": "natural_number_game_lean4", "sha": "69b60b72139403a64508494441d6c561c24ce66d", "save_path": "github-repos/lean/alexkassil-natural_number_game_lean4", "path": "github-repos/lean/alexkassil-natural_number_game_lean4/natural_number_game_lean4-69b60b72139403a64508494441d6c561c24ce66d/MyNat/power_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.7053889091004424}}
{"text": "import data.nat.modeq -- modular arithmetic\nimport topology.basic\n\nexample : 5 \u2261 8 [MOD 3] := \nbegin\n    apply rfl,\nend\n\n#check nat.modeq.modeq_mul\n\nexample (a b c d m : \u2115) : a \u2261 b [MOD m] \u2192 c \u2261 d [MOD m] \u2192 a * c \u2261 b * d [MOD m] := \nbegin\n    apply nat.modeq.modeq_mul,\nend\n\nlemma cong_mul1 (a b c d m : \u2115) : a \u2261 b [MOD m] \u2192 a * c \u2261 b * c [MOD m] := \nbegin\n    intro h1,\n    apply nat.modeq.modeq_mul h1, apply rfl,\nend\n\ntheorem cong_product (a b c d m : \u2115) (h1: a \u2261 b * c [MOD m]) (h2: c \u2261 d [MOD m]) : a \u2261 b * d [MOD m] := \nbegin\n    have h3: b * c \u2261 b * d [MOD m], from \n    begin\n        apply nat.modeq.modeq_mul, apply rfl, assumption\n    end,\n    apply nat.modeq.trans h1 h3,\nend\n\nlemma aaa (rr R R_INV a ar aar aaa n : \u2115) :\n    R * R_INV \u2261 1 [MOD n] \u2192\n    rr \u2261 R * R [MOD n] \u2192\n    ar \u2261 a * R_INV * rr [MOD n] \u2192\n    aar \u2261 ar * ar * R_INV [MOD n] \u2192\n    aaa \u2261 aar * a * R_INV [MOD n] \u2192\n    aaa \u2261 a * a * a [MOD n] :=\nbegin\n    intros h1 h2 h3 h4 h5, \n    have h: ar \u2261 a * R_INV * R * R [MOD n], from\n    begin\n        rw [mul_assoc],\n        apply cong_product ar (a * R_INV) rr (R * R) n, \n        assumption, \n        assumption, \n    end,\n    \n    have h: ar \u2261 a * R * 1 [MOD n], from\n    begin\n        apply cong_product ar (a * R) (R_INV * R) 1 n, \n        rw [<- mul_assoc, mul_assoc a R, mul_comm R R_INV, <-mul_assoc],\n        assumption, \n        rw [mul_comm],\n        assumption, \n    end,\n    sorry\nend", "meta": {"author": "yizhou7", "repo": "learning-lean", "sha": "91fb366c624df6e56e19555b2e482ce767cd8224", "save_path": "github-repos/lean/yizhou7-learning-lean", "path": "github-repos/lean/yizhou7-learning-lean/learning-lean-91fb366c624df6e56e19555b2e482ce767cd8224/my_project/src/cong.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.7053889063421225}}
{"text": "import data.real.basic\n\nvariables a b : \u211d\n\n-- BEGIN\nexample (h : a < b) : \u00ac b < a :=\nbegin\n  intro h',\n  have : a < a,\n    from lt_trans h h',\n  apply lt_irrefl a this,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/7_have/ex3_have_this_inequal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.7053810936537249}}
{"text": "/-\nCopyright (c) 2015 Haitao Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthor : Haitao Zhang\n-/\n\nimport data algebra.group algebra.group_power .finsubg .hom .perm\n\nopen function finset\nopen eq.ops\n\nnamespace group_theory\n\nsection cyclic\nopen nat fin list\nlocal attribute madd [reducible]\n\nvariable {A : Type}\nvariable [ambG : group A]\ninclude ambG\n\nlemma pow_mod {a : A} {n m : nat} : a ^ m = 1 \u2192 a ^ n = a ^ (n % m) :=\nassume Pid,\nhave a ^ (n / m * m) = 1, from calc\n  a ^ (n / m * m) = a ^ (m * (n / m))   : by rewrite (mul.comm (n / m) m)\n                ... = (a ^ m) ^ (n / m) : by rewrite pow_mul\n                ... = 1 ^ (n / m)       : by rewrite Pid\n                ... = 1                 : one_pow (n / m),\ncalc a ^ n = a ^ (n / m * m + n % m)       : by rewrite -(eq_div_mul_add_mod n m)\n       ... = a ^ (n / m * m) * a ^ (n % m) : by rewrite pow_add\n       ... = 1 * a ^ (n % m)               : by rewrite this\n       ... = a ^ (n % m)                   : by rewrite one_mul\n\nlemma pow_sub_eq_one_of_pow_eq {a : A} {i j : nat} :\n  a^i = a^j \u2192 a^(i - j) = 1 :=\nassume Pe, or.elim (lt_or_ge i j)\n  (assume Piltj, begin rewrite [sub_eq_zero_of_le (nat.le_of_lt Piltj)] end)\n  (assume Pigej, begin rewrite [pow_sub a Pigej, Pe, mul.right_inv] end)\n\nlemma pow_dist_eq_one_of_pow_eq {a : A} {i j : nat} :\n  a^i = a^j \u2192 a^(dist i j) = 1 :=\nassume Pe, or.elim (lt_or_ge i j)\n  (suppose i < j, by rewrite [dist_eq_sub_of_lt this]; exact pow_sub_eq_one_of_pow_eq (eq.symm Pe))\n  (suppose i \u2265 j, by rewrite [dist_eq_sub_of_ge this]; exact pow_sub_eq_one_of_pow_eq Pe)\n\nlemma pow_madd {a : A} {n : nat} {i j : fin (succ n)} :\n  a^(succ n) = 1 \u2192 a^(val (i + j)) = a^i * a^j :=\nassume Pe, calc\na^(val (i + j)) = a^((i + j) % (succ n)) : rfl\n            ... = a^(val i + val j)      : by rewrite [-pow_mod Pe]\n            ... = a^i * a^j              : by rewrite pow_add\n\nlemma mk_pow_mod {a : A} {n m : nat} : a ^ (succ m) = 1 \u2192 a ^ n = a ^ (mk_mod m n) :=\nassume Pe, pow_mod Pe\n\nvariable [finA : fintype A]\ninclude finA\n\nopen fintype\n\nvariable [deceqA : decidable_eq A]\ninclude deceqA\n\nlemma exists_pow_eq_one (a : A) : \u2203 n, n < card A \u2227 a ^ (succ n) = 1 :=\nlet f := (\u03bb i : fin (succ (card A)), a ^ i) in\nhave Pninj : \u00ac(injective f), from assume Pinj,\n  absurd (card_le_of_inj _ _ (exists.intro f Pinj))\n    (begin rewrite [card_fin], apply not_succ_le_self end),\nobtain i\u2081 P\u2081, from exists_not_of_not_forall Pninj,\nobtain i\u2082 P\u2082, from exists_not_of_not_forall P\u2081,\nobtain Pfe Pne, from and_not_of_not_implies P\u2082,\nhave Pvne : val i\u2081 \u2260 val i\u2082, from assume Pveq, absurd (eq_of_veq Pveq) Pne,\nexists.intro (pred (dist i\u2081 i\u2082)) (begin\n  rewrite [succ_pred_of_pos (dist_pos_of_ne Pvne)], apply and.intro,\n    apply lt_of_succ_lt_succ,\n    rewrite [succ_pred_of_pos (dist_pos_of_ne Pvne)],\n    apply nat.lt_of_le_of_lt dist_le_max (max_lt i\u2081 i\u2082),\n    apply pow_dist_eq_one_of_pow_eq Pfe\n  end)\n\n-- Another possibility is to generate a list of powers and use find to get the first\n-- unity.\n-- The bound on bex is arbitrary as long as it is large enough (at least card A). Making\n-- it larger simplifies some proofs, such as a \u2208 cyc a.\ndefinition cyc (a : A) : finset A := {x \u2208 univ | bex (succ (card A)) (\u03bb n, a ^ n = x)}\n\ndefinition order (a : A) := card (cyc a)\n\ndefinition pow_fin (a : A) (n : nat) (i : fin (order a)) := a ^ (i + n)\n\ndefinition cyc_pow_fin (a : A) (n : nat) : finset A := image (pow_fin a n) univ\n\nlemma order_le_group_order {a : A} : order a \u2264 card A :=\ncard_le_card_of_subset !subset_univ\n\nlemma cyc_has_one (a : A) : 1 \u2208 cyc a :=\nbegin\n  apply mem_sep_of_mem !mem_univ,\n  existsi 0, apply and.intro,\n    apply zero_lt_succ,\n    apply pow_zero\nend\n\nlemma order_pos (a : A) : 0 < order a :=\nlength_pos_of_mem (cyc_has_one a)\n\nlemma cyc_mul_closed (a : A) : finset_mul_closed_on (cyc a) :=\ntake g h, assume Pgin Phin,\nobtain n Plt Pe, from exists_pow_eq_one a,\nobtain i Pilt Pig, from of_mem_sep Pgin,\nobtain j Pjlt Pjh, from of_mem_sep Phin,\nbegin\n  rewrite [-Pig, -Pjh, -pow_add, pow_mod Pe],\n  apply mem_sep_of_mem !mem_univ,\n  existsi ((i + j) % (succ n)), apply and.intro,\n    apply nat.lt_trans (mod_lt (i+j) !zero_lt_succ) (succ_lt_succ Plt),\n    apply rfl\nend\n\nlemma cyc_has_inv (a : A) : finset_has_inv (cyc a) :=\ntake g, assume Pgin,\nobtain n Plt Pe, from exists_pow_eq_one a,\nobtain i Pilt Pig, from of_mem_sep Pgin,\nlet ni := -(mk_mod n i) in\nhave Pinv : g*a^ni = 1, by\n  rewrite [-Pig, mk_pow_mod Pe, -(pow_madd Pe), add.right_inv],\nbegin\n  rewrite [inv_eq_of_mul_eq_one Pinv],\n  apply mem_sep_of_mem !mem_univ,\n  existsi ni, apply and.intro,\n    apply nat.lt_trans (is_lt ni) (succ_lt_succ Plt),\n    apply rfl\nend\n\nlemma self_mem_cyc (a : A) : a \u2208 cyc a :=\nmem_sep_of_mem !mem_univ\n  (exists.intro (1 : nat) (and.intro (succ_lt_succ card_pos) !pow_one))\n\nlemma mem_cyc (a : A) : \u2200 {n : nat}, a^n \u2208 cyc a\n| 0        := cyc_has_one a\n| (succ n) :=\n  begin rewrite pow_succ', apply cyc_mul_closed a, exact mem_cyc, apply self_mem_cyc end\n\nlemma order_le {a : A} {n : nat} : a^(succ n) = 1 \u2192 order a \u2264 succ n :=\nassume Pe, let s := image (pow_nat a) (upto (succ n)) in\nhave Psub: cyc a \u2286 s, from subset_of_forall\n  (take g, assume Pgin, obtain i Pilt Pig, from of_mem_sep Pgin, begin\n  rewrite [-Pig, pow_mod Pe],\n  apply mem_image,\n    apply mem_upto_of_lt (mod_lt i !zero_lt_succ),\n    exact rfl end),\n#nat calc order a \u2264 card s               : card_le_card_of_subset Psub\n              ... \u2264 card (upto (succ n)) : !card_image_le\n              ... = succ n               : card_upto (succ n)\n\nlemma pow_ne_of_lt_order {a : A} {n : nat} : succ n < order a \u2192 a^(succ n) \u2260 1 :=\nassume Plt, not_imp_not_of_imp order_le (not_le_of_gt Plt)\n\nlemma eq_zero_of_pow_eq_one {a : A} : \u2200 {n : nat}, a^n = 1 \u2192 n < order a \u2192 n = 0\n| 0        := assume Pe Plt, rfl\n| (succ n) := assume Pe Plt, absurd Pe (pow_ne_of_lt_order Plt)\n\nlemma pow_fin_inj (a : A) (n : nat) : injective (pow_fin a n) :=\ntake i j : fin (order a),\nsuppose a^(i + n) = a^(j + n),\nhave    a^(dist i j) = 1, begin apply !dist_add_add_right \u25b8 (pow_dist_eq_one_of_pow_eq this) end,\nhave    dist i j = 0,     from\n  eq_zero_of_pow_eq_one this (nat.lt_of_le_of_lt dist_le_max (max_lt i j)),\neq_of_veq (eq_of_dist_eq_zero this)\n\nlemma cyc_eq_cyc (a : A) (n : nat) : cyc_pow_fin a n = cyc a :=\nhave Psub : cyc_pow_fin a n \u2286 cyc a, from subset_of_forall\n  (take g, assume Pgin,\n  obtain i Pin Pig, from exists_of_mem_image Pgin, by rewrite [-Pig]; apply mem_cyc),\neq_of_card_eq_of_subset (begin apply eq.trans,\n    apply card_image_eq_of_inj_on,\n      rewrite [to_set_univ, -set.injective_iff_inj_on_univ], exact pow_fin_inj a n,\n    rewrite [card_fin] end) Psub\n\nlemma pow_order (a : A) : a^(order a) = 1 :=\nobtain i Pin Pone, from exists_of_mem_image (eq.symm (cyc_eq_cyc a 1) \u25b8 cyc_has_one a),\nor.elim (eq_or_lt_of_le (succ_le_of_lt (is_lt i)))\n  (assume P, P \u25b8 Pone) (assume P, absurd Pone (pow_ne_of_lt_order P))\n\nlemma eq_one_of_order_eq_one {a : A} : order a = 1 \u2192 a = 1 :=\nassume Porder,\ncalc a = a^1         : by rewrite (pow_one a)\n   ... = a^(order a) : by rewrite Porder\n   ... = 1           : by rewrite pow_order\n\nlemma order_of_min_pow {a : A} {n : nat}\n  (Pone : a^(succ n) = 1) (Pmin : \u2200 i, i < n \u2192 a^(succ i) \u2260 1) : order a = succ n :=\nor.elim (eq_or_lt_of_le (order_le Pone)) (\u03bb P, P)\n  (\u03bb P : order a < succ n, begin\n  have Pn : a^(order a) \u2260 1,\n  begin\n    rewrite [-(succ_pred_of_pos (order_pos a))],\n    apply Pmin, apply nat.lt_of_succ_lt_succ,\n    rewrite [succ_pred_of_pos !order_pos], assumption\n  end,\n  exact absurd (pow_order a) Pn end)\n\nlemma order_dvd_of_pow_eq_one {a : A} {n : nat} (Pone : a^n = 1) : order a \u2223 n :=\nhave Pe : a^(n % order a) = 1, from\n  begin\n    revert Pone,\n    rewrite [eq_div_mul_add_mod n (order a) at {1}, pow_add, mul.comm _ (order a), pow_mul, pow_order, one_pow, one_mul],\n    intros, assumption\n  end,\ndvd_of_mod_eq_zero (eq_zero_of_pow_eq_one Pe (mod_lt n !order_pos))\n\ndefinition cyc_is_finsubg [instance] (a : A) : is_finsubg (cyc a) :=\nis_finsubg.mk (cyc_has_one a) (cyc_mul_closed a) (cyc_has_inv a)\n\nlemma order_dvd_group_order (a : A) : order a \u2223 card A :=\ndvd.intro (eq.symm (!mul.comm \u25b8 lagrange_theorem (subset_univ (cyc a))))\n\ndefinition pow_fin' (a : A) (i : fin (succ (pred (order a)))) := pow_nat a i\n\nlocal attribute group_of_add_group [instance]\n\nlemma pow_fin_hom (a : A) : homomorphic (pow_fin' a) :=\ntake i j : fin (succ (pred (order a))),\nbegin\n  rewrite [\u2191pow_fin'],\n  apply pow_madd,\n  rewrite [succ_pred_of_pos !order_pos],\n  exact pow_order a\nend\n\ndefinition pow_fin_is_iso (a : A) : is_iso_class (pow_fin' a) :=\nis_iso_class.mk (pow_fin_hom a)\n  (have H : injective (\u03bb (i : fin (order a)), a ^ (val i + 0)), from pow_fin_inj a 0,\n    begin rewrite [\u2191pow_fin', succ_pred_of_pos !order_pos]; exact H end)\n\nend cyclic\n\nsection rot\nopen nat list\nopen fin fintype list\n\nsection\nlocal attribute group_of_add_group [instance]\nlemma pow_eq_mul {n : nat} {i : fin (succ n)} : \u2200 {k : nat}, i^k = mk_mod n (i*k)\n| 0        := by rewrite [pow_zero]\n| (succ k) := begin\n  have Psucc : i^(succ k) = madd (i^k) i, by apply pow_succ',\n  rewrite [Psucc, pow_eq_mul],\n  apply eq_of_veq,\n  rewrite [mul_succ, val_madd, \u2191mk_mod, mod_add_mod]\n  end\n\nend\n\ndefinition rotl : \u2200 {n : nat} m : nat, fin n \u2192 fin n\n| 0        := take m i, elim0 i\n| (succ n) := take m, madd (mk_mod n (n*m))\n\ndefinition rotr : \u2200 {n : nat} m : nat, fin n \u2192 fin n\n| 0        := take m i, elim0 i\n| (succ n) := take m, madd (-(mk_mod n (n*m)))\n\nlemma rotl_succ' {n m : nat} : rotl m = madd (mk_mod n (n*m)) := rfl\n\nlemma rotl_zero : \u2200 {n : nat}, @rotl n 0 = id\n| 0        := funext take i, elim0 i\n| (nat.succ n) := funext take i, begin rewrite [\u2191rotl, mul_zero, mk_mod_zero_eq, zero_madd] end\n\nlemma rotl_id : \u2200 {n : nat}, @rotl n n = id\n| 0        := funext take i, elim0 i\n| (nat.succ n) :=\n  have P : mk_mod n (n * succ n) = mk_mod n 0,\n    from eq_of_veq (by rewrite [\u2191mk_mod, mul_mod_left]),\n  begin rewrite [rotl_succ', P], apply rotl_zero end\n\nlemma rotl_to_zero {n i : nat} : rotl i (mk_mod n i) = 0 :=\neq_of_veq begin rewrite [\u2191rotl, val_madd], esimp [mk_mod], rewrite [ mod_add_mod, add_mod_mod, -succ_mul, mul_mod_right] end\n\nlemma rotl_compose : \u2200 {n : nat} {j k : nat}, (@rotl n j) \u2218 (rotl k) = rotl (j + k)\n| 0        := take j k, funext take i, elim0 i\n| (succ n) :=  take j k, funext take i, eq.symm begin\n  rewrite [*rotl_succ', left_distrib, -(@madd_mk_mod n (n*j)), madd_assoc],\n  end\n\nlemma rotr_rotl : \u2200 {n : nat} (m : nat) {i : fin n}, rotr m (rotl m i) = i\n| 0            := take m i, elim0 i\n| (nat.succ n) := take m i, calc (-(mk_mod n (n*m))) + ((mk_mod n (n*m)) + i) = i : by rewrite neg_add_cancel_left\n\nlemma rotl_rotr : \u2200 {n : nat} (m : nat), (@rotl n m) \u2218 (rotr m) = id\n| 0            := take m, funext take i, elim0 i\n| (nat.succ n) := take m, funext take i, calc (mk_mod n (n*m)) + (-(mk_mod n (n*m)) + i) = i : add_neg_cancel_left\n\nlemma rotl_succ {n : nat} : (rotl 1) \u2218 (@succ n) = lift_succ :=\nfunext (take i, eq_of_veq (begin rewrite [\u2191comp, \u2191rotl, \u2191madd, mul_one n, \u2191mk_mod, mod_add_mod, \u2191lift_succ, val_succ, -succ_add_eq_succ_add, add_mod_self_left, mod_eq_of_lt (lt.trans (is_lt i) !lt_succ_self), -val_lift] end))\n\ndefinition list.rotl {A : Type} : \u2200 l : list A, list A\n| []     := []\n| (a::l) := l++[a]\n\nlemma rotl_cons {A : Type} {a : A} {l} : list.rotl (a::l) = l++[a] := rfl\n\nlemma rotl_map {A B : Type} {f : A \u2192 B} : \u2200 {l : list A}, list.rotl (map f l) = map f (list.rotl l)\n| []     := rfl\n| (a::l) := begin rewrite [map_cons, *rotl_cons, map_append] end\n\nlemma rotl_eq_rotl : \u2200 {n : nat}, map (rotl 1) (upto n) = list.rotl (upto n)\n| 0        := rfl\n| (succ n) := begin\n  rewrite [upto_step at {1}, fin.upto_succ, rotl_cons, map_append],\n  congruence,\n    rewrite [map_map], congruence, exact rotl_succ,\n    rewrite [map_singleton], congruence, rewrite [\u2191rotl, mul_one n, \u2191mk_mod, \u2191maxi, \u2191madd],\n      congruence, rewrite [ mod_add_mod, val_zero, add_zero, mod_eq_of_lt !lt_succ_self ]\n  end\n\ndefinition seq [reducible] (A : Type) (n : nat) := fin n \u2192 A\n\nvariable {A : Type}\n\ndefinition rotl_fun {n : nat} (m : nat) (f : seq A n) : seq A n := f \u2218 (rotl m)\ndefinition rotr_fun {n : nat} (m : nat) (f : seq A n) : seq A n := f \u2218 (rotr m)\n\nlemma rotl_seq_zero {n : nat} : rotl_fun 0 = @id (seq A n) :=\nfunext take f, begin rewrite [\u2191rotl_fun, rotl_zero] end\n\nlemma rotl_seq_ne_id : \u2200 {n : nat}, (\u2203 a b : A, a \u2260 b) \u2192 \u2200 i, i < n \u2192 rotl_fun (succ i) \u2260 (@id (seq A (succ n)))\n| 0            := assume Pex, take i, assume Piltn, absurd Piltn !not_lt_zero\n| (nat.succ n) := assume Pex, obtain a b Pne, from Pex, take i, assume Pilt,\n  let f := (\u03bb j : fin (succ (succ n)), if j = 0 then a else b),\n      fi := mk_mod (succ n) (succ i) in\n  have Pfne : rotl_fun (succ i) f fi \u2260 f fi,\n    from begin rewrite [\u2191rotl_fun, rotl_to_zero, mk_mod_of_lt (succ_lt_succ Pilt), if_pos rfl, if_neg mk_succ_ne_zero], assumption end,\n  have P : rotl_fun (succ i) f \u2260 f, from\n    assume Peq, absurd (congr_fun Peq fi) Pfne,\n  assume Peq, absurd (congr_fun Peq f) P\n\nlemma rotr_rotl_fun {n : nat} (m : nat) (f : seq A n) : rotr_fun m (rotl_fun m f) = f :=\ncalc f \u2218 (rotl m) \u2218 (rotr m) = f \u2218 ((rotl m) \u2218 (rotr m)) : by rewrite -comp.assoc\n                         ... = f \u2218 id                    : by rewrite (rotl_rotr m)\n\nlemma rotl_fun_inj {n : nat} {m : nat} : @injective (seq A n) (seq A n) (rotl_fun m) :=\ninjective_of_has_left_inverse (exists.intro (rotr_fun m) (rotr_rotl_fun m))\n\nlemma seq_rotl_eq_list_rotl {n : nat} (f : seq A n) :\n  fun_to_list (rotl_fun 1 f) = list.rotl (fun_to_list f) :=\nbegin\n  rewrite [\u2191fun_to_list, \u2191rotl_fun, -map_map, rotl_map],\n  congruence, exact rotl_eq_rotl\nend\n\nend rot\n\nsection rotg\nopen nat fin fintype\n\ndefinition rotl_perm [reducible] (A : Type) [finA : fintype A] [deceqA : decidable_eq A] (n : nat) (m : nat) : perm (seq A n) :=\nperm.mk (rotl_fun m) rotl_fun_inj\n\nvariable {A : Type}\nvariable [finA : fintype A]\nvariable [deceqA : decidable_eq A]\nvariable {n : nat}\ninclude finA deceqA\n\nlemma rotl_perm_mul {i j : nat} : (rotl_perm A n i) * (rotl_perm A n j) = rotl_perm A n (j+i) :=\neq_of_feq (funext take f, calc\n  f \u2218 (rotl j) \u2218 (rotl i) = f \u2218 ((rotl j) \u2218 (rotl i)) : by rewrite -comp.assoc\n                      ... = f \u2218 (rotl (j+i))          : by rewrite rotl_compose)\n\nlemma rotl_perm_pow_eq : \u2200 {i : nat}, (rotl_perm A n 1) ^ i = rotl_perm A n i\n| 0        := begin rewrite [pow_zero, \u2191rotl_perm, perm_one, -eq_iff_feq], esimp, rewrite rotl_seq_zero  end\n| (succ i) := begin rewrite [pow_succ', rotl_perm_pow_eq, rotl_perm_mul, one_add] end\n\nlemma rotl_perm_pow_eq_one : (rotl_perm A n 1) ^ n = 1 :=\neq.trans rotl_perm_pow_eq (eq_of_feq begin esimp [rotl_perm], rewrite [\u2191rotl_fun, rotl_id] end)\n\nlemma rotl_perm_mod {i : nat} : rotl_perm A n i = rotl_perm A n (i % n) :=\ncalc rotl_perm A n i = (rotl_perm A n 1) ^ i       : by rewrite rotl_perm_pow_eq\n                 ... = (rotl_perm A n 1) ^ (i % n) : by rewrite (pow_mod rotl_perm_pow_eq_one)\n                 ... = rotl_perm A n (i % n)       : by rewrite rotl_perm_pow_eq\n\n-- needs A to have at least two elements!\nlemma rotl_perm_pow_ne_one (Pex : \u2203 a b : A, a \u2260 b) : \u2200 i, i < n \u2192 (rotl_perm A (succ n) 1)^(succ i) \u2260 1 :=\ntake i, assume Piltn, begin\n  intro P, revert P, rewrite [rotl_perm_pow_eq, -eq_iff_feq, perm_one, *perm.f_mk],\n  intro P, exact absurd P (rotl_seq_ne_id Pex i Piltn)\nend\n\nlemma rotl_perm_order (Pex : \u2203 a b : A, a \u2260 b) : order (rotl_perm A (succ n) 1) = (succ n) :=\norder_of_min_pow rotl_perm_pow_eq_one (rotl_perm_pow_ne_one Pex)\n\nend rotg\nend group_theory\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/theories/finite_group_theory/cyclic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.705358786251141}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Patrick Stevens\n-/\nimport data.nat.choose.basic\nimport tactic.linarith\nimport algebra.big_operators.ring\nimport algebra.big_operators.intervals\nimport algebra.big_operators.order\n/-!\n# Sums of binomial coefficients\n\nThis file includes variants of the binomial theorem and other results on sums of binomial\ncoefficients. Theorems whose proofs depend on such sums may also go in this file for import\nreasons.\n\n-/\nopen nat\nopen finset\n\nopen_locale big_operators\n\nvariables {R : Type*}\n\n/-- A version of the binomial theorem for noncommutative semirings. -/\ntheorem commute.add_pow [semiring R] {x y : R} (h : commute x y) (n : \u2115) :\n  (x + y) ^ n = \u2211 m in range (n + 1), x ^ m * y ^ (n - m) * choose n m :=\nbegin\n  let t : \u2115 \u2192 \u2115 \u2192 R := \u03bb n m, x ^ m * (y ^ (n - m)) * (choose n m),\n  change (x + y) ^ n = \u2211 m in range (n + 1), t n m,\n  have h_first : \u2200 n, t n 0 = y ^ n :=\n    \u03bb n, by { dsimp [t], rw [choose_zero_right, pow_zero, nat.cast_one, mul_one, one_mul] },\n  have h_last : \u2200 n, t n n.succ = 0 :=\n    \u03bb n, by { dsimp [t], rw [choose_succ_self, nat.cast_zero, mul_zero] },\n  have h_middle : \u2200 (n i : \u2115), (i \u2208 range n.succ) \u2192\n   ((t n.succ) \u2218 nat.succ) i = x * (t n i) + y * (t n i.succ) :=\n  begin\n    intros n i h_mem,\n    have h_le : i \u2264 n := nat.le_of_lt_succ (mem_range.mp h_mem),\n    dsimp [t],\n    rw [choose_succ_succ, nat.cast_add, mul_add],\n    congr' 1,\n    { rw [pow_succ x, succ_sub_succ, mul_assoc, mul_assoc, mul_assoc] },\n    { rw [\u2190 mul_assoc y, \u2190 mul_assoc y, (h.symm.pow_right i.succ).eq],\n      by_cases h_eq : i = n,\n      { rw [h_eq, choose_succ_self, nat.cast_zero, mul_zero, mul_zero] },\n      { rw [succ_sub (lt_of_le_of_ne h_le h_eq)],\n        rw [pow_succ y, mul_assoc, mul_assoc, mul_assoc, mul_assoc] } }\n  end,\n  induction n with n ih,\n  { rw [pow_zero, sum_range_succ, range_zero, sum_empty, zero_add],\n    dsimp [t], rw [pow_zero, pow_zero, choose_self, nat.cast_one, mul_one, mul_one] },\n  { rw [sum_range_succ', h_first],\n    rw [sum_congr rfl (h_middle n), sum_add_distrib, add_assoc],\n    rw [pow_succ (x + y), ih, add_mul, mul_sum, mul_sum],\n    congr' 1,\n    rw [sum_range_succ', sum_range_succ, h_first, h_last,\n       mul_zero, add_zero, pow_succ] }\nend\n\n/-- The binomial theorem -/\ntheorem add_pow [comm_semiring R] (x y : R) (n : \u2115) :\n  (x + y) ^ n = \u2211 m in range (n + 1), x ^ m * y ^ (n - m) * choose n m :=\n(commute.all x y).add_pow n\n\nnamespace nat\n\n/-- The sum of entries in a row of Pascal's triangle -/\ntheorem sum_range_choose (n : \u2115) :\n  \u2211 m in range (n + 1), choose n m = 2 ^ n :=\nby simpa using (add_pow 1 1 n).symm\n\nlemma sum_range_choose_halfway (m : nat) :\n  \u2211 i in range (m + 1), choose (2 * m + 1) i = 4 ^ m :=\nhave \u2211 i in range (m + 1), choose (2 * m + 1) (2 * m + 1 - i) =\n  \u2211 i in range (m + 1), choose (2 * m + 1) i,\nfrom sum_congr rfl $ \u03bb i hi, choose_symm $ by linarith [mem_range.1 hi],\n(nat.mul_right_inj zero_lt_two).1 $\ncalc 2 * (\u2211 i in range (m + 1), choose (2 * m + 1) i) =\n  (\u2211 i in range (m + 1), choose (2 * m + 1) i) +\n    \u2211 i in range (m + 1), choose (2 * m + 1) (2 * m + 1 - i) :\n  by rw [two_mul, this]\n... = (\u2211 i in range (m + 1), choose (2 * m + 1) i) +\n  \u2211 i in Ico (m + 1) (2 * m + 2), choose (2 * m + 1) i : begin\n    rw [range_eq_Ico, sum_Ico_reflect],\n    { congr,\n      have A : m + 1 \u2264 2 * m + 1, by linarith,\n      rw [add_comm, nat.add_sub_assoc A, \u2190 add_comm],\n      congr,\n      rw nat.sub_eq_iff_eq_add A,\n      ring, },\n   { linarith }\n  end\n... = \u2211 i in range (2 * m + 2), choose (2 * m + 1) i : sum_range_add_sum_Ico _ (by linarith)\n... = 2^(2 * m + 1) : sum_range_choose (2 * m + 1)\n... = 2 * 4^m : by { rw [pow_succ, pow_mul], refl }\n\nlemma choose_middle_le_pow (n : \u2115) : choose (2 * n + 1) n \u2264 4 ^ n :=\nbegin\n  have t : choose (2 * n + 1) n \u2264 \u2211 i in range (n + 1), choose (2 * n + 1) i :=\n    single_le_sum (\u03bb x _, by linarith) (self_mem_range_succ n),\n  simpa [sum_range_choose_halfway n] using t\nend\n\nlemma four_pow_le_two_mul_add_one_mul_central_binom (n : \u2115) :\n  4 ^ n \u2264 (2 * n + 1) * choose (2 * n) n :=\ncalc 4 ^ n = (1 + 1) ^ (2 * n) : by norm_num [pow_mul]\n...        = \u2211 m in range (2 * n + 1), choose (2 * n) m : by simp [add_pow]\n...        \u2264 \u2211 m in range (2 * n + 1), choose (2 * n) (2 * n / 2) :\n  sum_le_sum (\u03bb i hi, choose_le_middle i (2 * n))\n...        = (2 * n + 1) * choose (2 * n) n : by simp\n\nend nat\n\ntheorem int.alternating_sum_range_choose {n : \u2115} :\n  \u2211 m in range (n + 1), ((-1) ^ m * \u2191(choose n m) : \u2124) = if n = 0 then 1 else 0 :=\nbegin\n  cases n, { simp },\n  have h := add_pow (-1 : \u2124) 1 n.succ,\n  simp only [one_pow, mul_one, add_left_neg, int.nat_cast_eq_coe_nat] at h,\n  rw [\u2190 h, zero_pow (nat.succ_pos n), if_neg (nat.succ_ne_zero n)],\nend\n\ntheorem int.alternating_sum_range_choose_of_ne {n : \u2115} (h0 : n \u2260 0) :\n  \u2211 m in range (n + 1), ((-1) ^ m * \u2191(choose n m) : \u2124) = 0 :=\nby rw [int.alternating_sum_range_choose, if_neg h0]\n\nnamespace finset\n\ntheorem sum_powerset_apply_card {\u03b1 \u03b2 : Type*} [add_comm_monoid \u03b1] (f : \u2115 \u2192 \u03b1) {x : finset \u03b2} :\n  \u2211 m in x.powerset, f m.card = \u2211 m in range (x.card + 1), (x.card.choose m) \u2022 f m :=\nbegin\n  transitivity \u2211 m in range (x.card + 1), \u2211 j in x.powerset.filter (\u03bb z, z.card = m), f j.card,\n  { refine (sum_fiberwise_of_maps_to _ _).symm,\n    intros y hy,\n    rw [mem_range, nat.lt_succ_iff],\n    rw mem_powerset at hy,\n    exact card_le_of_subset hy },\n  { refine sum_congr rfl (\u03bb y hy, _),\n    rw [\u2190 card_powerset_len, \u2190 sum_const],\n    refine sum_congr powerset_len_eq_filter.symm (\u03bb z hz, _),\n    rw (mem_powerset_len.1 hz).2 }\nend\n\ntheorem sum_powerset_neg_one_pow_card {\u03b1 : Type*} [decidable_eq \u03b1] {x : finset \u03b1} :\n  \u2211 m in x.powerset, (-1 : \u2124) ^ m.card = if x = \u2205 then 1 else 0 :=\nbegin\n  rw sum_powerset_apply_card,\n  simp only [nsmul_eq_mul', \u2190 card_eq_zero],\n  convert int.alternating_sum_range_choose,\n  ext,\n  simp,\nend\n\ntheorem sum_powerset_neg_one_pow_card_of_nonempty {\u03b1 : Type*} {x : finset \u03b1}\n  (h0 : x.nonempty) :\n  \u2211 m in x.powerset, (-1 : \u2124) ^ m.card = 0 :=\nbegin\n  classical,\n  rw [sum_powerset_neg_one_pow_card, if_neg],\n  rw [\u2190 ne.def, \u2190 nonempty_iff_ne_empty],\n  apply h0,\nend\n\nend finset\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/nat/choose/sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7053587780711347}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin, Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Damiano Testa\n-/\nimport data.equiv.basic\nimport logic.nontrivial\nimport order.basic\n\n/-!\n# Initial lemmas to work with the `order_dual`\n\n## Definitions\n`to_dual` and `of_dual` the order reversing identity maps, bundled as equivalences.\n\n## Basic Lemmas to convert between an order and its dual\n\nThis file is similar to algebra/group/type_tags.lean\n-/\n\nopen function\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nnamespace order_dual\n\ninstance [nontrivial \u03b1] : nontrivial (order_dual \u03b1) := by delta order_dual; assumption\n\n/-- `to_dual` is the identity function to the `order_dual` of a linear order.  -/\ndef to_dual : \u03b1 \u2243 order_dual \u03b1 := \u27e8id, id, \u03bb h, rfl, \u03bb h, rfl\u27e9\n\n/-- `of_dual` is the identity function from the `order_dual` of a linear order.  -/\ndef of_dual : order_dual \u03b1 \u2243 \u03b1 := to_dual.symm\n\n@[simp] lemma to_dual_symm_eq : (@to_dual \u03b1).symm = of_dual := rfl\n\n@[simp] lemma of_dual_symm_eq : (@of_dual \u03b1).symm = to_dual := rfl\n\n@[simp] lemma to_dual_of_dual (a : order_dual \u03b1) : to_dual (of_dual a) = a := rfl\n@[simp] lemma of_dual_to_dual (a : \u03b1) : of_dual (to_dual a) = a := rfl\n\n@[simp] lemma to_dual_inj {a b : \u03b1} :\n  to_dual a = to_dual b \u2194 a = b := iff.rfl\n\n@[simp] lemma to_dual_le_to_dual [has_le \u03b1] {a b : \u03b1} :\n  to_dual a \u2264 to_dual b \u2194 b \u2264 a := iff.rfl\n\n@[simp] lemma to_dual_lt_to_dual [has_lt \u03b1] {a b : \u03b1} :\n  to_dual a < to_dual b \u2194 b < a := iff.rfl\n\n@[simp] lemma of_dual_inj {a b : order_dual \u03b1} :\n  of_dual a = of_dual b \u2194 a = b := iff.rfl\n\n@[simp] lemma of_dual_le_of_dual [has_le \u03b1] {a b : order_dual \u03b1} :\n  of_dual a \u2264 of_dual b \u2194 b \u2264 a := iff.rfl\n\n@[simp] lemma of_dual_lt_of_dual [has_lt \u03b1] {a b : order_dual \u03b1} :\n  of_dual a < of_dual b \u2194 b < a := iff.rfl\n\nlemma le_to_dual [has_le \u03b1] {a : order_dual \u03b1} {b : \u03b1} :\n  a \u2264 to_dual b \u2194 b \u2264 of_dual a := iff.rfl\n\nlemma lt_to_dual [has_lt \u03b1] {a : order_dual \u03b1} {b : \u03b1} :\n  a < to_dual b \u2194 b < of_dual a := iff.rfl\n\nlemma to_dual_le [has_le \u03b1] {a : \u03b1} {b : order_dual \u03b1} :\n  to_dual a \u2264 b \u2194 of_dual b \u2264 a := iff.rfl\n\nlemma to_dual_lt [has_lt \u03b1] {a : \u03b1} {b : order_dual \u03b1} :\n  to_dual a < b \u2194 of_dual b < a := iff.rfl\n\n/-- Recursor for `order_dual \u03b1`. -/\n@[elab_as_eliminator]\nprotected def rec {C : order_dual \u03b1 \u2192 Sort*} (h\u2082 : \u03a0 (a : \u03b1), C (to_dual a)) :\n  \u03a0 (a : order_dual \u03b1), C a := h\u2082\n\n@[simp] protected lemma \u00abforall\u00bb {p : order_dual \u03b1 \u2192 Prop} : (\u2200 a, p a) \u2194 \u2200 a, p (to_dual a) :=\niff.rfl\n\n@[simp] protected lemma \u00abexists\u00bb {p : order_dual \u03b1 \u2192 Prop} : (\u2203 a, p a) \u2194 \u2203 a, p (to_dual a) :=\niff.rfl\n\nend order_dual\n\nalias order_dual.to_dual_lt_to_dual \u2194 _ has_lt.lt.dual\nalias order_dual.to_dual_le_to_dual \u2194 _ has_le.le.dual\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/order/order_dual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224072151174, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7053587703030172}}
{"text": "theorem eq_zero_or_eq_zero_of_mul_eq_zero (a b : mynat) (h : a * b = 0) :\n  a = 0 \u2228 b = 0 :=\nbegin\ncases a with a,\nleft,\nrefl,\ncases b with b,\nright,\nrefl,\nexfalso,\nrw mul_succ at h,\nrw add_succ at h,\nexact succ_ne_zero _ h,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world09/level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7052536590249583}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport measure_theory.integral.interval_integral\nimport analysis.normed_space.pointwise\nimport analysis.special_functions.non_integrable\nimport analysis.analytic.basic\n\n/-!\n# Integral over a circle in `\u2102`\n\nIn this file we define `\u222e z in C(c, R), f z` to be the integral $\\oint_{|z-c|=|R|} f(z)\\,dz$ and\nprove some properties of this integral. We give definition and prove most lemmas for a function\n`f : \u2102 \u2192 E`, where `E` is a complex Banach space. For this reason,\nsome lemmas use, e.g., `(z - c)\u207b\u00b9 \u2022 f z` instead of `f z / (z - c)`.\n\n## Main definitions\n\n* `circle_map c R`: the exponential map $\u03b8 \u21a6 c + R e^{\u03b8i}$;\n\n* `circle_integrable f c R`: a function `f : \u2102 \u2192 E` is integrable on the circle with center `c` and\n  radius `R` if `f \u2218 circle_map c R` is integrable on `[0, 2\u03c0]`;\n\n* `circle_integral f c R`: the integral $\\oint_{|z-c|=|R|} f(z)\\,dz$, defined as\n  $\\int_{0}^{2\u03c0}(c + Re^{\u03b8 i})' f(c+Re^{\u03b8 i})\\,d\u03b8$;\n\n* `cauchy_power_series f c R`: the power series that is equal to\n  $\\sum_{n=0}^{\\infty} \\oint_{|z-c|=R} \\left(\\frac{w-c}{z - c}\\right)^n \\frac{1}{z-c}f(z)\\,dz$ at\n  `w - c`. The coefficients of this power series depend only on `f \u2218 circle_map c R`, and the power\n  series converges to `f w` if `f` is differentiable on the closed ball `metric.closed_ball c R`\n  and `w` belongs to the corresponding open ball.\n\n## Main statements\n\n* `has_fpower_series_on_cauchy_integral`: for any circle integrable function `f`, the power series\n  `cauchy_power_series f c R`, `R > 0`, converges to the Cauchy integral\n  `(2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z` on the open disc `metric.ball c R`;\n\n* `circle_integral.integral_sub_zpow_of_undef`, `circle_integral.integral_sub_zpow_of_ne`, and\n  `circle_integral.integral_sub_inv_of_mem_ball`: formulas for `\u222e z in C(c, R), (z - w) ^ n`,\n  `n : \u2124`. These lemmas cover the following cases:\n\n  - `circle_integral.integral_sub_zpow_of_undef`, `n < 0` and `|w - c| = |R|`: in this case the\n    function is not integrable, so the integral is equal to its default value (zero);\n\n  - `circle_integral.integral_sub_zpow_of_ne`, `n \u2260 -1`: in the cases not covered by the previous\n    lemma, we have `(z - w) ^ n = ((z - w) ^ (n + 1) / (n + 1))'`, thus the integral equals zero;\n\n  - `circle_integral.integral_sub_inv_of_mem_ball`, `n = -1`, `|w - c| < R`: in this case the\n    integral is equal to `2\u03c0i`.\n\n  The case `n = -1`, `|w -c| > R` is not covered by these lemmas. While it is possible to construct\n  an explicit primitive, it is easier to apply Cauchy theorem, so we postpone the proof till we have\n  this theorem (see #10000).\n\n## Notation\n\n- `\u222e z in C(c, R), f z`: notation for the integral $\\oint_{|z-c|=|R|} f(z)\\,dz$, defined as\n  $\\int_{0}^{2\u03c0}(c + Re^{\u03b8 i})' f(c+Re^{\u03b8 i})\\,d\u03b8$.\n\n## Tags\n\nintegral, circle, Cauchy integral\n-/\n\nvariables {E : Type*} [normed_add_comm_group E]\n\nnoncomputable theory\n\nopen_locale real nnreal interval pointwise topology\nopen complex measure_theory topological_space metric function set filter asymptotics\n\n/-!\n### `circle_map`, a parametrization of a circle\n-/\n\n/-- The exponential map $\u03b8 \u21a6 c + R e^{\u03b8i}$. The range of this map is the circle in `\u2102` with center\n`c` and radius `|R|`. -/\ndef circle_map (c : \u2102) (R : \u211d) : \u211d \u2192 \u2102 := \u03bb \u03b8, c + R * exp (\u03b8 * I)\n\n/-- `circle_map` is `2\u03c0`-periodic. -/\nlemma periodic_circle_map (c : \u2102) (R : \u211d) : periodic (circle_map c R) (2 * \u03c0) :=\n\u03bb \u03b8, by simp [circle_map, add_mul, exp_periodic _]\n\nlemma set.countable.preimage_circle_map {s : set \u2102} (hs : s.countable) (c : \u2102)\n  {R : \u211d} (hR : R \u2260 0) : (circle_map c R \u207b\u00b9' s).countable :=\nshow (coe \u207b\u00b9' ((* I) \u207b\u00b9' (exp \u207b\u00b9' ((*) R \u207b\u00b9' ((+) c \u207b\u00b9' s))))).countable,\n  from (((hs.preimage (add_right_injective _)).preimage $ mul_right_injective\u2080 $ of_real_ne_zero.2\n    hR).preimage_cexp.preimage $ mul_left_injective\u2080 I_ne_zero).preimage of_real_injective\n\n@[simp] lemma circle_map_sub_center (c : \u2102) (R : \u211d) (\u03b8 : \u211d) :\n  circle_map c R \u03b8 - c = circle_map 0 R \u03b8 :=\nby simp [circle_map]\n\nlemma circle_map_zero (R \u03b8 : \u211d) : circle_map 0 R \u03b8 = R * exp (\u03b8 * I) := zero_add _\n\n@[simp] lemma abs_circle_map_zero (R : \u211d) (\u03b8 : \u211d) : abs (circle_map 0 R \u03b8) = |R| :=\nby simp [circle_map]\n\nlemma circle_map_mem_sphere' (c : \u2102) (R : \u211d) (\u03b8 : \u211d) : circle_map c R \u03b8 \u2208 sphere c (|R|) :=\nby simp\n\nlemma circle_map_mem_sphere (c : \u2102) {R : \u211d} (hR : 0 \u2264 R) (\u03b8 : \u211d) : circle_map c R \u03b8 \u2208 sphere c R :=\nby simpa only [_root_.abs_of_nonneg hR] using circle_map_mem_sphere' c R \u03b8\n\nlemma circle_map_mem_closed_ball (c : \u2102) {R : \u211d} (hR : 0 \u2264 R) (\u03b8 : \u211d) :\n  circle_map c R \u03b8 \u2208 closed_ball c R :=\nsphere_subset_closed_ball (circle_map_mem_sphere c hR \u03b8)\n\nlemma circle_map_not_mem_ball (c : \u2102) (R : \u211d) (\u03b8 : \u211d) : circle_map c R \u03b8 \u2209 ball c R :=\nby simp [dist_eq, le_abs_self]\n\nlemma circle_map_ne_mem_ball {c : \u2102} {R : \u211d} {w : \u2102} (hw : w \u2208 ball c R) (\u03b8 : \u211d) :\n  circle_map c R \u03b8 \u2260 w :=\n(ne_of_mem_of_not_mem hw (circle_map_not_mem_ball _ _ _)).symm\n\n/-- The range of `circle_map c R` is the circle with center `c` and radius `|R|`. -/\n@[simp] lemma range_circle_map (c : \u2102) (R : \u211d) : range (circle_map c R) = sphere c (|R|) :=\ncalc range (circle_map c R) = c +\u1d65 R \u2022 range (\u03bb \u03b8 : \u211d, exp (\u03b8 * I)) :\n  by simp only [\u2190 image_vadd, \u2190 image_smul, \u2190 range_comp, vadd_eq_add, circle_map, (\u2218), real_smul]\n... = sphere c (|R|) : by simp [smul_sphere R (0 : \u2102) zero_le_one]\n\n/-- The image of `(0, 2\u03c0]` under `circle_map c R` is the circle with center `c` and radius `|R|`. -/\n@[simp] lemma image_circle_map_Ioc (c : \u2102) (R : \u211d) :\n  circle_map c R '' Ioc 0 (2 * \u03c0) = sphere c (|R|) :=\nby rw [\u2190 range_circle_map, \u2190 (periodic_circle_map c R).image_Ioc real.two_pi_pos 0, zero_add]\n\n@[simp] lemma circle_map_eq_center_iff {c : \u2102} {R : \u211d} {\u03b8 : \u211d} : circle_map c R \u03b8 = c \u2194 R = 0 :=\nby simp [circle_map, exp_ne_zero]\n\n@[simp] lemma circle_map_zero_radius (c : \u2102) : circle_map c 0 = const \u211d c :=\nfunext $ \u03bb \u03b8, circle_map_eq_center_iff.2 rfl\n\nlemma circle_map_ne_center {c : \u2102} {R : \u211d} (hR : R \u2260 0) {\u03b8 : \u211d} : circle_map c R \u03b8 \u2260 c :=\nmt circle_map_eq_center_iff.1 hR\n\nlemma has_deriv_at_circle_map (c : \u2102) (R : \u211d) (\u03b8 : \u211d) :\n  has_deriv_at (circle_map c R) (circle_map 0 R \u03b8 * I) \u03b8 :=\nby simpa only [mul_assoc, one_mul, of_real_clm_apply, circle_map, of_real_one, zero_add]\n using ((of_real_clm.has_deriv_at.mul_const I).cexp.const_mul (R : \u2102)).const_add c\n\n/- TODO: prove `cont_diff \u211d (circle_map c R)`. This needs a version of `cont_diff.mul`\nfor multiplication in a normed algebra over the base field. -/\n\nlemma differentiable_circle_map (c : \u2102) (R : \u211d) :\n  differentiable \u211d (circle_map c R) :=\n\u03bb \u03b8, (has_deriv_at_circle_map c R \u03b8).differentiable_at\n\n@[continuity] lemma continuous_circle_map (c : \u2102) (R : \u211d) : continuous (circle_map c R) :=\n(differentiable_circle_map c R).continuous\n\n@[measurability] lemma measurable_circle_map (c : \u2102) (R : \u211d) : measurable (circle_map c R) :=\n(continuous_circle_map c R).measurable\n\n@[simp] lemma deriv_circle_map (c : \u2102) (R : \u211d) (\u03b8 : \u211d) :\n  deriv (circle_map c R) \u03b8 = circle_map 0 R \u03b8 * I :=\n(has_deriv_at_circle_map _ _ _).deriv\n\nlemma deriv_circle_map_eq_zero_iff {c : \u2102} {R : \u211d} {\u03b8 : \u211d} :\n  deriv (circle_map c R) \u03b8 = 0 \u2194 R = 0 :=\nby simp [I_ne_zero]\n\nlemma deriv_circle_map_ne_zero {c : \u2102} {R : \u211d} {\u03b8 : \u211d} (hR : R \u2260 0) :\n  deriv (circle_map c R) \u03b8 \u2260 0 :=\nmt deriv_circle_map_eq_zero_iff.1 hR\n\nlemma lipschitz_with_circle_map (c : \u2102) (R : \u211d) :\n  lipschitz_with R.nnabs (circle_map c R) :=\nlipschitz_with_of_nnnorm_deriv_le (differentiable_circle_map _ _) $ \u03bb \u03b8,\n  nnreal.coe_le_coe.1 $ by simp\n\nlemma continuous_circle_map_inv {R : \u211d} {z w : \u2102} (hw : w \u2208 ball z R) :\n continuous (\u03bb \u03b8, (circle_map z R \u03b8 - w)\u207b\u00b9) :=\nbegin\n  have : \u2200 \u03b8, circle_map z R \u03b8 - w \u2260 0,\n  { simp_rw sub_ne_zero, exact \u03bb \u03b8, circle_map_ne_mem_ball hw \u03b8, },\n  continuity,\nend\n\n/-!\n### Integrability of a function on a circle\n-/\n\n/-- We say that a function `f : \u2102 \u2192 E` is integrable on the circle with center `c` and radius `R` if\nthe function `f \u2218 circle_map c R` is integrable on `[0, 2\u03c0]`.\n\nNote that the actual function used in the definition of `circle_integral` is\n`(deriv (circle_map c R) \u03b8) \u2022 f (circle_map c R \u03b8)`. Integrability of this function is equivalent\nto integrability of `f \u2218 circle_map c R` whenever `R \u2260 0`. -/\ndef circle_integrable (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d) : Prop :=\ninterval_integrable (\u03bb \u03b8 : \u211d, f (circle_map c R \u03b8)) volume 0 (2 * \u03c0)\n\n@[simp] lemma circle_integrable_const (a : E) (c : \u2102) (R : \u211d) :\n  circle_integrable (\u03bb _, a) c R :=\ninterval_integrable_const\n\nnamespace circle_integrable\n\nvariables {f g : \u2102 \u2192 E} {c : \u2102} {R : \u211d}\n\nlemma add (hf : circle_integrable f c R) (hg : circle_integrable g c R) :\n  circle_integrable (f + g) c R :=\nhf.add hg\n\nlemma neg (hf : circle_integrable f c R) : circle_integrable (-f) c R := hf.neg\n\n/-- The function we actually integrate over `[0, 2\u03c0]` in the definition of `circle_integral` is\nintegrable. -/\nlemma out [normed_space \u2102 E] (hf : circle_integrable f c R) :\n  interval_integrable (\u03bb \u03b8 : \u211d, deriv (circle_map c R) \u03b8 \u2022 f (circle_map c R \u03b8)) volume 0 (2 * \u03c0) :=\nbegin\n  simp only [circle_integrable, deriv_circle_map, interval_integrable_iff] at *,\n  refine (hf.norm.const_mul (|R|)).mono' _ _,\n  { exact ((continuous_circle_map _ _).ae_strongly_measurable.mul_const I).smul\n      hf.ae_strongly_measurable },\n  { simp [norm_smul] }\nend\n\nend circle_integrable\n\n@[simp] lemma circle_integrable_zero_radius {f : \u2102 \u2192 E} {c : \u2102} : circle_integrable f c 0 :=\nby simp [circle_integrable]\n\nlemma circle_integrable_iff [normed_space \u2102 E]\n  {f : \u2102 \u2192 E} {c : \u2102} (R : \u211d) : circle_integrable f c R \u2194\n  interval_integrable (\u03bb \u03b8 : \u211d, deriv (circle_map c R) \u03b8 \u2022 f (circle_map c R \u03b8)) volume 0 (2 * \u03c0) :=\nbegin\n  by_cases h\u2080 : R = 0,\n  { simp [h\u2080], },\n  refine \u27e8\u03bb h, h.out, \u03bb h, _\u27e9,\n  simp only [circle_integrable, interval_integrable_iff, deriv_circle_map] at h \u22a2,\n  refine (h.norm.const_mul (|R|\u207b\u00b9)).mono' _ _,\n  { have H : \u2200 {\u03b8}, circle_map 0 R \u03b8 * I \u2260 0 := \u03bb \u03b8, by simp [h\u2080, I_ne_zero],\n    simpa only [inv_smul_smul\u2080 H]\n      using (((continuous_circle_map 0 R).ae_strongly_measurable).mul_const I).ae_measurable\n        .inv.ae_strongly_measurable.smul h.ae_strongly_measurable },\n  { simp [norm_smul, h\u2080] },\nend\n\nlemma continuous_on.circle_integrable' {f : \u2102 \u2192 E} {c : \u2102} {R : \u211d}\n  (hf : continuous_on f (sphere c (|R|))) :\n  circle_integrable f c R :=\n(hf.comp_continuous (continuous_circle_map _ _)\n  (circle_map_mem_sphere' _ _)).interval_integrable _ _\n\nlemma continuous_on.circle_integrable {f : \u2102 \u2192 E} {c : \u2102} {R : \u211d} (hR : 0 \u2264 R)\n  (hf : continuous_on f (sphere c R)) :\n  circle_integrable f c R :=\ncontinuous_on.circle_integrable' $ (_root_.abs_of_nonneg hR).symm \u25b8 hf\n\n/-- The function `\u03bb z, (z - w) ^ n`, `n : \u2124`, is circle integrable on the circle with center `c` and\nradius `|R|` if and only if `R = 0` or `0 \u2264 n`, or `w` does not belong to this circle. -/\n@[simp] lemma circle_integrable_sub_zpow_iff {c w : \u2102} {R : \u211d} {n : \u2124} :\n  circle_integrable (\u03bb z, (z - w) ^ n) c R \u2194 R = 0 \u2228 0 \u2264 n \u2228 w \u2209 sphere c (|R|) :=\nbegin\n  split,\n  { intro h, contrapose! h, rcases h with \u27e8hR, hn, hw\u27e9,\n    simp only [circle_integrable_iff R, deriv_circle_map],\n    rw \u2190 image_circle_map_Ioc at hw, rcases hw with \u27e8\u03b8, h\u03b8, rfl\u27e9,\n    replace h\u03b8 : \u03b8 \u2208 [0, 2 * \u03c0], from Icc_subset_uIcc (Ioc_subset_Icc_self h\u03b8),\n    refine not_interval_integrable_of_sub_inv_is_O_punctured _ real.two_pi_pos.ne h\u03b8,\n    set f : \u211d \u2192 \u2102 := \u03bb \u03b8', circle_map c R \u03b8' - circle_map c R \u03b8,\n    have : \u2200\u1da0 \u03b8' in \ud835\udcdd[\u2260] \u03b8, f \u03b8' \u2208 ball (0 : \u2102) 1 \\ {0},\n    { suffices : \u2200\u1da0 z in \ud835\udcdd[\u2260] (circle_map c R \u03b8), z - circle_map c R \u03b8 \u2208 ball (0 : \u2102) 1 \\ {0},\n        from ((differentiable_circle_map c R \u03b8).has_deriv_at.tendsto_punctured_nhds\n          (deriv_circle_map_ne_zero hR)).eventually this,\n      filter_upwards [self_mem_nhds_within,\n        mem_nhds_within_of_mem_nhds (ball_mem_nhds _ zero_lt_one)],\n      simp only [dist_eq, sub_eq_zero, mem_compl_iff, mem_singleton_iff, mem_ball, mem_diff,\n                 mem_ball_zero_iff, norm_eq_abs, not_false_iff, and_self, implies_true_iff]\n                {contextual := tt} },\n    refine ((((has_deriv_at_circle_map c R \u03b8).is_O_sub).mono inf_le_left).inv_rev\n      (this.mono (\u03bb \u03b8' h\u2081 h\u2082, absurd h\u2082 h\u2081.2))).trans _,\n    refine is_O.of_bound (|R|)\u207b\u00b9 (this.mono $ \u03bb \u03b8' h\u03b8', _),\n    set x := abs (f \u03b8'),\n    suffices : x\u207b\u00b9 \u2264 x ^ n,\n    by simpa only [inv_mul_cancel_left\u2080, abs_eq_zero.not.2 hR, norm_eq_abs, map_inv\u2080,\n                   algebra.id.smul_eq_mul, map_mul, abs_circle_map_zero, abs_I, mul_one,\n                   abs_zpow, ne.def, not_false_iff] using this,\n    have : x \u2208 Ioo (0 : \u211d) 1, by simpa [and.comm, x] using h\u03b8',\n    rw \u2190 zpow_neg_one,\n    refine (zpow_strict_anti this.1 this.2).le_iff_le.2 (int.lt_add_one_iff.1 _), exact hn },\n  { rintro (rfl|H),\n    exacts [circle_integrable_zero_radius,\n      ((continuous_on_id.sub continuous_on_const).zpow\u2080 _ $ \u03bb z hz, H.symm.imp_left $\n        \u03bb hw, sub_ne_zero.2 $ ne_of_mem_of_not_mem hz hw).circle_integrable'] },\nend\n\n@[simp] lemma circle_integrable_sub_inv_iff {c w : \u2102} {R : \u211d} :\n  circle_integrable (\u03bb z, (z - w)\u207b\u00b9) c R \u2194 R = 0 \u2228 w \u2209 sphere c (|R|) :=\nby { simp only [\u2190 zpow_neg_one, circle_integrable_sub_zpow_iff], norm_num }\n\nvariables [normed_space \u2102 E] [complete_space E]\n\n/-- Definition for $\\oint_{|z-c|=R} f(z)\\,dz$. -/\ndef circle_integral (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d) : E :=\n\u222b (\u03b8 : \u211d) in 0..2 * \u03c0, deriv (circle_map c R) \u03b8 \u2022 f (circle_map c R \u03b8)\n\nnotation `\u222e` binders ` in ` `C(` c `, ` R `)` `, ` r:(scoped:60 f, circle_integral f c R) := r\n\nlemma circle_integral_def_Icc (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d) :\n  \u222e z in C(c, R), f z = \u222b \u03b8 in Icc 0 (2 * \u03c0), deriv (circle_map c R) \u03b8 \u2022 f (circle_map c R \u03b8) :=\nby simp only [circle_integral, interval_integral.integral_of_le real.two_pi_pos.le,\n  measure.restrict_congr_set Ioc_ae_eq_Icc]\n\nnamespace circle_integral\n\n@[simp] lemma integral_radius_zero (f : \u2102 \u2192 E) (c : \u2102) : \u222e z in C(c, 0), f z = 0 :=\nby simp [circle_integral]\n\nlemma integral_congr {f g : \u2102 \u2192 E} {c : \u2102} {R : \u211d} (hR : 0 \u2264 R) (h : eq_on f g (sphere c R)) :\n  \u222e z in C(c, R), f z = \u222e z in C(c, R), g z :=\ninterval_integral.integral_congr $ \u03bb \u03b8 h\u03b8, by simp only [h (circle_map_mem_sphere _ hR _)]\n\nlemma integral_sub_inv_smul_sub_smul (f : \u2102 \u2192 E) (c w : \u2102) (R : \u211d) :\n  \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 (z - w) \u2022 f z = \u222e z in C(c, R), f z :=\nbegin\n  rcases eq_or_ne R 0 with rfl|hR, { simp only [integral_radius_zero] },\n  have : (circle_map c R \u207b\u00b9' {w}).countable, from (countable_singleton _).preimage_circle_map c hR,\n  refine interval_integral.integral_congr_ae ((this.ae_not_mem _).mono $ \u03bb \u03b8 h\u03b8 h\u03b8', _),\n  change circle_map c R \u03b8 \u2260 w at h\u03b8,\n  simp only [inv_smul_smul\u2080 (sub_ne_zero.2 $ h\u03b8)]\nend\n\nlemma integral_undef {f : \u2102 \u2192 E} {c : \u2102} {R : \u211d} (hf : \u00accircle_integrable f c R) :\n  \u222e z in C(c, R), f z = 0 :=\ninterval_integral.integral_undef (mt (circle_integrable_iff R).mpr hf)\n\nlemma integral_sub {f g : \u2102 \u2192 E} {c : \u2102} {R : \u211d} (hf : circle_integrable f c R)\n  (hg : circle_integrable g c R) :\n  \u222e z in C(c, R), f z - g z = (\u222e z in C(c, R), f z) - \u222e z in C(c, R), g z :=\nby simp only [circle_integral, smul_sub, interval_integral.integral_sub hf.out hg.out]\n\nlemma norm_integral_le_of_norm_le_const' {f : \u2102 \u2192 E} {c : \u2102} {R C : \u211d}\n  (hf : \u2200 z \u2208 sphere c (|R|), \u2016f z\u2016 \u2264 C) :\n  \u2016\u222e z in C(c, R), f z\u2016 \u2264 2 * \u03c0 * |R| * C :=\ncalc \u2016\u222e z in C(c, R), f z\u2016 \u2264 |R| * C * |2 * \u03c0 - 0| :\n  interval_integral.norm_integral_le_of_norm_le_const $ \u03bb \u03b8 _,\n    (calc \u2016deriv (circle_map c R) \u03b8 \u2022 f (circle_map c R \u03b8)\u2016 = |R| * \u2016f (circle_map c R \u03b8)\u2016 :\n      by simp [norm_smul]\n    ... \u2264 |R| * C : mul_le_mul_of_nonneg_left (hf _ $ circle_map_mem_sphere' _ _ _)\n      (_root_.abs_nonneg _))\n... = 2 * \u03c0 * |R| * C :\n  by { rw [sub_zero, _root_.abs_of_pos real.two_pi_pos], ac_refl }\n\nlemma norm_integral_le_of_norm_le_const {f : \u2102 \u2192 E} {c : \u2102} {R C : \u211d} (hR : 0 \u2264 R)\n  (hf : \u2200 z \u2208 sphere c R, \u2016f z\u2016 \u2264 C) :\n  \u2016\u222e z in C(c, R), f z\u2016 \u2264 2 * \u03c0 * R * C :=\nhave |R| = R, from _root_.abs_of_nonneg hR,\ncalc \u2016\u222e z in C(c, R), f z\u2016 \u2264 2 * \u03c0 * |R| * C :\n  norm_integral_le_of_norm_le_const' $ by rwa this\n... = 2 * \u03c0 * R * C : by rw this\n\n\n\n/-- If `f` is continuous on the circle `|z - c| = R`, `R > 0`, the `\u2016f z\u2016` is less than or equal to\n`C : \u211d` on this circle, and this norm is strictly less than `C` at some point `z` of the circle,\nthen `\u2016\u222e z in C(c, R), f z\u2016 < 2 * \u03c0 * R * C`. -/\nlemma norm_integral_lt_of_norm_le_const_of_lt {f : \u2102 \u2192 E} {c : \u2102} {R C : \u211d} (hR : 0 < R)\n  (hc : continuous_on f (sphere c R)) (hf : \u2200 z \u2208 sphere c R, \u2016f z\u2016 \u2264 C)\n  (hlt : \u2203 z \u2208 sphere c R, \u2016f z\u2016 < C) :\n  \u2016\u222e z in C(c, R), f z\u2016 < 2 * \u03c0 * R * C :=\nbegin\n  rw [\u2190 _root_.abs_of_pos hR, \u2190 image_circle_map_Ioc] at hlt,\n  rcases hlt with \u27e8_, \u27e8\u03b8\u2080, hmem, rfl\u27e9, hlt\u27e9,\n  calc \u2016\u222e z in C(c, R), f z\u2016 \u2264 \u222b \u03b8 in 0..2 * \u03c0, \u2016deriv (circle_map c R) \u03b8 \u2022 f (circle_map c R \u03b8)\u2016 :\n    interval_integral.norm_integral_le_integral_norm real.two_pi_pos.le\n  ... < \u222b \u03b8 in 0..2 * \u03c0, R * C :\n    begin\n      simp only [norm_smul, deriv_circle_map, norm_eq_abs, map_mul, abs_I, mul_one,\n        abs_circle_map_zero, abs_of_pos hR],\n      refine interval_integral.integral_lt_integral_of_continuous_on_of_le_of_exists_lt\n        real.two_pi_pos _ continuous_on_const (\u03bb \u03b8 h\u03b8, _) \u27e8\u03b8\u2080, Ioc_subset_Icc_self hmem, _\u27e9,\n      { exact continuous_on_const.mul (hc.comp (continuous_circle_map _ _).continuous_on\n          (\u03bb \u03b8 h\u03b8, circle_map_mem_sphere _ hR.le _)).norm },\n      { exact mul_le_mul_of_nonneg_left (hf _ $ circle_map_mem_sphere _ hR.le _) hR.le },\n      { exact (mul_lt_mul_left hR).2 hlt }\n    end\n  ... = 2 * \u03c0 * R * C : by simp [mul_assoc]\nend\n\n@[simp] lemma integral_smul {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] [normed_space \ud835\udd5c E] [smul_comm_class \ud835\udd5c \u2102 E]\n  (a : \ud835\udd5c) (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d) :\n  \u222e z in C(c, R), a \u2022 f z = a \u2022 \u222e z in C(c, R), f z :=\nby simp only [circle_integral, \u2190 smul_comm a, interval_integral.integral_smul]\n\n@[simp] lemma integral_smul_const (f : \u2102 \u2192 \u2102) (a : E) (c : \u2102) (R : \u211d) :\n  \u222e z in C(c, R), (f z \u2022 a) = (\u222e z in C(c, R), f z) \u2022 a :=\nby simp only [circle_integral, interval_integral.integral_smul_const, \u2190 smul_assoc]\n\n@[simp] lemma integral_const_mul (a : \u2102) (f : \u2102 \u2192 \u2102) (c : \u2102) (R : \u211d) :\n  \u222e z in C(c, R), a * f z = a * \u222e z in C(c, R), f z :=\nintegral_smul a f c R\n\n@[simp] lemma integral_sub_center_inv (c : \u2102) {R : \u211d} (hR : R \u2260 0) :\n  \u222e z in C(c, R), (z - c)\u207b\u00b9 = 2 * \u03c0 * I :=\nby simp [circle_integral, \u2190 div_eq_mul_inv, mul_div_cancel_left _ (circle_map_ne_center hR)]\n\n/-- If `f' : \u2102 \u2192 E` is a derivative of a complex differentiable function on the circle\n`metric.sphere c |R|`, then `\u222e z in C(c, R), f' z = 0`. -/\nlemma integral_eq_zero_of_has_deriv_within_at' {f f' : \u2102 \u2192 E} {c : \u2102} {R : \u211d}\n  (h : \u2200 z \u2208 sphere c (|R|), has_deriv_within_at f (f' z) (sphere c (|R|)) z) :\n  \u222e z in C(c, R), f' z = 0 :=\nbegin\n  by_cases hi : circle_integrable f' c R,\n  { rw \u2190 sub_eq_zero.2 ((periodic_circle_map c R).comp f).eq,\n    refine interval_integral.integral_eq_sub_of_has_deriv_at (\u03bb \u03b8 h\u03b8, _) hi.out,\n    exact (h _ (circle_map_mem_sphere' _ _ _)).scomp_has_deriv_at \u03b8\n      (differentiable_circle_map _ _ _).has_deriv_at (circle_map_mem_sphere' _ _) },\n  { exact integral_undef hi }\nend\n\n/-- If `f' : \u2102 \u2192 E` is a derivative of a complex differentiable function on the circle\n`metric.sphere c R`, then `\u222e z in C(c, R), f' z = 0`. -/\nlemma integral_eq_zero_of_has_deriv_within_at {f f' : \u2102 \u2192 E} {c : \u2102} {R : \u211d} (hR : 0 \u2264 R)\n  (h : \u2200 z \u2208 sphere c R, has_deriv_within_at f (f' z) (sphere c R) z) :\n  \u222e z in C(c, R), f' z = 0 :=\nintegral_eq_zero_of_has_deriv_within_at' $ (_root_.abs_of_nonneg hR).symm.subst h\n\n/-- If `n < 0` and `|w - c| = |R|`, then `(z - w) ^ n` is not circle integrable on the circle with\ncenter `c` and radius `(|R|)`, so the integral `\u222e z in C(c, R), (z - w) ^ n` is equal to zero. -/\nlemma integral_sub_zpow_of_undef {n : \u2124} {c w : \u2102} {R : \u211d} (hn : n < 0) (hw : w \u2208 sphere c (|R|)) :\n  \u222e z in C(c, R), (z - w) ^ n = 0 :=\nbegin\n  rcases eq_or_ne R 0 with rfl|h0, { apply integral_radius_zero },\n  apply integral_undef,\n  simp [circle_integrable_sub_zpow_iff, *]\nend\n\n/-- If `n \u2260 -1` is an integer number, then the integral of `(z - w) ^ n` over the circle equals\nzero. -/\nlemma integral_sub_zpow_of_ne {n : \u2124} (hn : n \u2260 -1) (c w : \u2102) (R : \u211d) :\n  \u222e z in C(c, R), (z - w) ^ n = 0 :=\nbegin\n  rcases em (w \u2208 sphere c (|R|) \u2227 n < -1) with \u27e8hw, hn\u27e9|H,\n  { exact integral_sub_zpow_of_undef (hn.trans dec_trivial) hw },\n  push_neg at H,\n  have hd : \u2200 z, (z \u2260 w \u2228 -1 \u2264 n) \u2192 has_deriv_at (\u03bb z, (z - w) ^ (n + 1) / (n + 1)) ((z - w) ^ n) z,\n  { intros z hne,\n    convert ((has_deriv_at_zpow (n + 1) _ (hne.imp _ _)).comp z\n      ((has_deriv_at_id z).sub_const w)).div_const _ using 1,\n    { have hn' : (n + 1 : \u2102) \u2260 0,\n        by rwa [ne, \u2190 eq_neg_iff_add_eq_zero, \u2190 int.cast_one, \u2190 int.cast_neg, int.cast_inj],\n      simp [mul_assoc, mul_div_cancel_left _ hn'] },\n    exacts [sub_ne_zero.2, neg_le_iff_add_nonneg.1] },\n  refine integral_eq_zero_of_has_deriv_within_at' (\u03bb z hz, (hd z _).has_deriv_within_at),\n  exact (ne_or_eq z w).imp_right (\u03bb h, H $ h \u25b8 hz)\nend\n\nend circle_integral\n\n/-- The power series that is equal to\n$\\sum_{n=0}^{\\infty} \\oint_{|z-c|=R} \\left(\\frac{w-c}{z - c}\\right)^n \\frac{1}{z-c}f(z)\\,dz$ at\n`w - c`. The coefficients of this power series depend only on `f \u2218 circle_map c R`, and the power\nseries converges to `f w` if `f` is differentiable on the closed ball `metric.closed_ball c R` and\n`w` belongs to the corresponding open ball. For any circle integrable function `f`, this power\nseries converges to the Cauchy integral for `f`. -/\ndef cauchy_power_series (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d) :\n  formal_multilinear_series \u2102 \u2102 E :=\n\u03bb n, continuous_multilinear_map.mk_pi_field \u2102 _ $\n  (2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - c)\u207b\u00b9 ^ n \u2022 (z - c)\u207b\u00b9 \u2022 f z\n\nlemma cauchy_power_series_apply (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d) (n : \u2115) (w : \u2102) :\n  cauchy_power_series f c R n (\u03bb _, w) =\n    (2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (w / (z - c)) ^ n \u2022 (z - c)\u207b\u00b9 \u2022 f z :=\nby simp only [cauchy_power_series, continuous_multilinear_map.mk_pi_field_apply, fin.prod_const,\n  div_eq_mul_inv, mul_pow, mul_smul, circle_integral.integral_smul, \u2190 smul_comm (w ^ n)]\n\nlemma norm_cauchy_power_series_le (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d) (n : \u2115) :\n  \u2016cauchy_power_series f c R n\u2016 \u2264\n    (2 * \u03c0)\u207b\u00b9 * (\u222b \u03b8 : \u211d in 0..2*\u03c0, \u2016f (circle_map c R \u03b8)\u2016) * (|R|\u207b\u00b9) ^ n :=\ncalc \u2016cauchy_power_series f c R n\u2016\n    = (2 * \u03c0)\u207b\u00b9 * \u2016\u222e z in C(c, R), (z - c)\u207b\u00b9 ^ n \u2022 (z - c)\u207b\u00b9 \u2022 f z\u2016 :\n  by simp [cauchy_power_series, norm_smul, real.pi_pos.le]\n... \u2264 (2 * \u03c0)\u207b\u00b9 * \u222b \u03b8 in 0..2*\u03c0, \u2016deriv (circle_map c R) \u03b8 \u2022 (circle_map c R \u03b8 - c)\u207b\u00b9 ^ n \u2022\n  (circle_map c R \u03b8 - c)\u207b\u00b9 \u2022 f (circle_map c R \u03b8)\u2016 :\n  mul_le_mul_of_nonneg_left (interval_integral.norm_integral_le_integral_norm real.two_pi_pos.le)\n    (by simp [real.pi_pos.le])\n... = (2 * \u03c0)\u207b\u00b9 * (|R|\u207b\u00b9 ^ n * (|R| * (|R|\u207b\u00b9 * \u222b (x : \u211d) in 0..2 * \u03c0, \u2016f (circle_map c R x)\u2016))) :\n  by simp [norm_smul, mul_left_comm (|R|)]\n... \u2264 (2 * \u03c0)\u207b\u00b9 * (\u222b \u03b8 : \u211d in 0..2*\u03c0, \u2016f (circle_map c R \u03b8)\u2016) * |R|\u207b\u00b9 ^ n :\n  begin\n    rcases eq_or_ne R 0 with rfl|hR,\n    { cases n; simp [-mul_inv_rev, real.two_pi_pos] },\n    { rw [mul_inv_cancel_left\u2080, mul_assoc, mul_comm (|R|\u207b\u00b9 ^ n)],\n      rwa [ne.def, _root_.abs_eq_zero] }\n  end\n\nlemma le_radius_cauchy_power_series (f : \u2102 \u2192 E) (c : \u2102) (R : \u211d\u22650) :\n  \u2191R \u2264 (cauchy_power_series f c R).radius :=\nbegin\n  refine (cauchy_power_series f c R).le_radius_of_bound\n    ((2 * \u03c0)\u207b\u00b9 * (\u222b \u03b8 : \u211d in 0..2*\u03c0, \u2016f (circle_map c R \u03b8)\u2016)) (\u03bb n, _),\n  refine (mul_le_mul_of_nonneg_right (norm_cauchy_power_series_le _ _ _ _)\n    (pow_nonneg R.coe_nonneg _)).trans _,\n  rw [_root_.abs_of_nonneg R.coe_nonneg],\n  cases eq_or_ne (R ^ n : \u211d) 0 with hR hR,\n  { rw [hR, mul_zero],\n    exact mul_nonneg (inv_nonneg.2 real.two_pi_pos.le)\n      (interval_integral.integral_nonneg real.two_pi_pos.le (\u03bb _ _, norm_nonneg _)) },\n  { rw [inv_pow, inv_mul_cancel_right\u2080 hR] }\nend\n\n/-- For any circle integrable function `f`, the power series `cauchy_power_series f c R` multiplied\nby `2\u03c0I` converges to the integral `\u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z` on the open disc\n`metric.ball c R`. -/\nlemma has_sum_two_pi_I_cauchy_power_series_integral {f : \u2102 \u2192 E} {c : \u2102} {R : \u211d} {w : \u2102}\n  (hf : circle_integrable f c R) (hw : abs w < R) :\n  has_sum (\u03bb n : \u2115, \u222e z in C(c, R), (w / (z - c)) ^ n \u2022 (z - c)\u207b\u00b9 \u2022 f z)\n    (\u222e z in C(c, R), (z - (c + w))\u207b\u00b9 \u2022 f z) :=\nbegin\n  have hR : 0 < R := (complex.abs.nonneg w).trans_lt hw,\n  have hwR : abs w / R \u2208 Ico (0 : \u211d) 1,\n    from \u27e8div_nonneg (complex.abs.nonneg w) hR.le, (div_lt_one hR).2 hw\u27e9,\n  refine interval_integral.has_sum_integral_of_dominated_convergence\n    (\u03bb n \u03b8, \u2016f (circle_map c R \u03b8)\u2016 * (abs w / R) ^ n) (\u03bb n, _) (\u03bb n, _) _ _ _,\n  { simp only [deriv_circle_map],\n    apply_rules [ae_strongly_measurable.smul, hf.def.1];\n    { apply measurable.ae_strongly_measurable, measurability } },\n  { simp [norm_smul, abs_of_pos hR, mul_left_comm R, mul_inv_cancel_left\u2080 hR.ne', mul_comm (\u2016_\u2016)] },\n  { exact eventually_of_forall (\u03bb _ _, (summable_geometric_of_lt_1 hwR.1 hwR.2).mul_left _) },\n  { simpa only [tsum_mul_left, tsum_geometric_of_lt_1 hwR.1 hwR.2]\n      using hf.norm.mul_continuous_on continuous_on_const },\n  { refine eventually_of_forall (\u03bb \u03b8 h\u03b8, has_sum.const_smul _ _),\n    simp only [smul_smul],\n    refine has_sum.smul_const _ _,\n    have : \u2016w / (circle_map c R \u03b8 - c)\u2016 < 1, by simpa [abs_of_pos hR] using hwR.2,\n    convert (has_sum_geometric_of_norm_lt_1 this).mul_right _,\n    simp [\u2190 sub_sub, \u2190 mul_inv, sub_mul, div_mul_cancel _ (circle_map_ne_center hR.ne')] }\nend\n\n/-- For any circle integrable function `f`, the power series `cauchy_power_series f c R`, `R > 0`,\nconverges to the Cauchy integral `(2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z` on the open\ndisc `metric.ball c R`. -/\nlemma has_sum_cauchy_power_series_integral {f : \u2102 \u2192 E} {c : \u2102} {R : \u211d} {w : \u2102}\n  (hf : circle_integrable f c R) (hw : abs w < R) :\n  has_sum (\u03bb n, cauchy_power_series f c R n (\u03bb _, w))\n    ((2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - (c + w))\u207b\u00b9 \u2022 f z) :=\nbegin\n  simp only [cauchy_power_series_apply],\n  exact (has_sum_two_pi_I_cauchy_power_series_integral hf hw).const_smul _\nend\n\n/-- For any circle integrable function `f`, the power series `cauchy_power_series f c R`, `R > 0`,\nconverges to the Cauchy integral `(2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z` on the open\ndisc `metric.ball c R`. -/\nlemma sum_cauchy_power_series_eq_integral {f : \u2102 \u2192 E} {c : \u2102} {R : \u211d} {w : \u2102}\n  (hf : circle_integrable f c R) (hw : abs w < R) :\n  (cauchy_power_series f c R).sum w =\n    ((2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - (c + w))\u207b\u00b9 \u2022 f z) :=\n(has_sum_cauchy_power_series_integral hf hw).tsum_eq\n\n/-- For any circle integrable function `f`, the power series `cauchy_power_series f c R`, `R > 0`,\nconverges to the Cauchy integral `(2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z` on the open\ndisc `metric.ball c R`. -/\nlemma has_fpower_series_on_cauchy_integral {f : \u2102 \u2192 E} {c : \u2102} {R : \u211d\u22650}\n  (hf : circle_integrable f c R) (hR : 0 < R) :\n  has_fpower_series_on_ball\n    (\u03bb w, (2 * \u03c0 * I : \u2102)\u207b\u00b9 \u2022 \u222e z in C(c, R), (z - w)\u207b\u00b9 \u2022 f z)\n    (cauchy_power_series f c R) c R :=\n{ r_le := le_radius_cauchy_power_series _ _ _,\n  r_pos := ennreal.coe_pos.2 hR,\n  has_sum := \u03bb y hy,\n    begin\n      refine has_sum_cauchy_power_series_integral hf _,\n      rw [\u2190 norm_eq_abs, \u2190 coe_nnnorm, nnreal.coe_lt_coe, \u2190 ennreal.coe_lt_coe],\n      exact mem_emetric_ball_zero_iff.1 hy\n    end }\n\nnamespace circle_integral\n\n/-- Integral $\\oint_{|z-c|=R} \\frac{dz}{z-w}=2\u03c0i$ whenever $|w-c|<R$. -/\nlemma integral_sub_inv_of_mem_ball {c w : \u2102} {R : \u211d} (hw : w \u2208 ball c R) :\n  \u222e z in C(c, R), (z - w)\u207b\u00b9 = 2 * \u03c0 * I :=\nbegin\n  have hR : 0 < R := dist_nonneg.trans_lt hw,\n  suffices H : has_sum (\u03bb n : \u2115, \u222e z in C(c, R), ((w - c) / (z - c)) ^ n * (z - c)\u207b\u00b9) (2 * \u03c0 * I),\n  { have A : circle_integrable (\u03bb _, (1 : \u2102)) c R, from continuous_on_const.circle_integrable',\n    refine (H.unique _).symm,\n    simpa only [smul_eq_mul, mul_one, add_sub_cancel'_right]\n      using has_sum_two_pi_I_cauchy_power_series_integral A hw },\n  have H : \u2200 n : \u2115, n \u2260 0 \u2192 \u222e z in C(c, R), (z - c) ^ (-n - 1 : \u2124) = 0,\n  { refine \u03bb n hn, integral_sub_zpow_of_ne _ _ _ _, simpa },\n  have : \u222e z in C(c, R), ((w - c) / (z - c)) ^ 0 * (z - c)\u207b\u00b9 = 2 * \u03c0 * I, by simp [hR.ne'],\n  refine this \u25b8 has_sum_single _ (\u03bb n hn, _),\n  simp only [div_eq_mul_inv, mul_pow, integral_const_mul, mul_assoc],\n  rw [(integral_congr hR.le (\u03bb z hz, _)).trans (H n hn), mul_zero],\n  rw [\u2190 pow_succ', \u2190 zpow_coe_nat, inv_zpow, \u2190 zpow_neg, int.coe_nat_succ, neg_add,\n    sub_eq_add_neg _ (1 : \u2124)]\nend\n\nend circle_integral\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/integral/circle_integral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7052536543442027}}
{"text": "variables A B C D P Q R: Prop\n\nexample : A \u2227 (A \u2192 B) \u2192 B :=\nassume \u27e8 hA, hAimpB \u27e9, hAimpB hA\n\nexample : A \u2192 \u00ac (\u00ac A \u2227 B) :=\nassume : A,\n  show \u00ac (\u00ac A \u2227 B), from\n    assume \u27e8 hnotA, hB \u27e9, show false, from hnotA \u2039A\u203a \n\nexample : \u00ac (A \u2227 B) \u2192 (A \u2192 \u00ac B) :=\nassume : \u00ac (A \u2227 B),\n  show (A \u2192 \u00ac B), from\n    assume : A, show \u00ac B, from\n      assume : B, show false, from\n        \u2039\u00ac (A \u2227 B)\u203a \u27e8 \u2039A\u203a , \u2039B\u203a \u27e9 \n\nexample (h\u2081 : A \u2228 B) (h\u2082 : A \u2192 C) (h\u2083 : B \u2192 D) : C \u2228 D :=\nshow C \u2228 D, from\nor.elim h\u2081\n  (assume : A, show C \u2228 D, from or.inl (h\u2082 \u2039A\u203a))\n  (assume : B, show C \u2228 D, from or.inr (h\u2083 \u2039B\u203a))\n\nexample : \u00ac (A \u2194 \u00ac A) :=\nassume : (A \u2194 \u00ac A), show false, from\nhave \u00ac A, from assume : A, show false, from have \u00ac A, from iff.elim_left \u2039A \u2194 \u00ac A\u203a \u2039A\u203a, \u2039\u00ac A\u203a \u2039A\u203a,\nhave A, from iff.elim_right \u2039A \u2194 \u00ac A\u203a \u2039\u00ac A\u203a,\n\u2039\u00ac A\u203a \u2039A\u203a\n\nopen classical\n------------------------------------------------------------\n\nexample (h : \u00ac A \u2227 \u00ac B) : \u00ac (A \u2228 B) :=\nhave \u00ac A, from h.left,\nhave \u00ac B, from h.right,\nshow \u00ac (A \u2228 B), from \n  assume : (A \u2228 B), show false, from\n  or.elim \u2039A \u2228 B\u203a (assume : A, (\u2039\u00ac A\u203a \u2039A\u203a)) (assume : B, (\u2039\u00ac B\u203a \u2039B\u203a))\n\nexample (h: \u00ac (A \u2228 B)) : (\u00ac A \u2227 \u00ac B) :=\nhave \u00ac A, from assume : A, show false, from have (A \u2228 B), from or.inl \u2039A\u203a, \u2039\u00ac (A \u2228 B)\u203a \u2039A \u2228 B\u203a,\nhave \u00ac B, from assume : B, show false, from have (A \u2228 B), from or.inr \u2039B\u203a, \u2039\u00ac (A \u2228 B)\u203a \u2039A \u2228 B\u203a,\n\u27e8 \u2039\u00ac A\u203a , \u2039\u00ac B\u203a \u27e9 \n\n------------------------------------------------------------\n\nexample (h: \u00ac A \u2228 \u00ac B) : \u00ac (A \u2227 B) :=\nor.elim h\n  (assume : \u00ac A, show \u00ac (A \u2227 B), from assume h1: (A \u2227 B), \u2039\u00ac A\u203a h1.left)\n  (assume : \u00ac B, show \u00ac (A \u2227 B), from assume h1: (A \u2227 B), \u2039\u00ac B\u203a h1.right) \n\nexample (h: \u00ac (A \u2227 B)) : \u00ac A \u2228 \u00ac B := by_contradiction(\nassume h1: \u00ac (\u00ac A \u2228 \u00ac B),\nhave A, from by_contradiction(assume : \u00ac A, have h2: \u00ac A \u2228 \u00ac B, from or.inl \u2039\u00ac A\u203a, h1 h2),\nhave B, from by_contradiction(assume : \u00ac B, have h2: \u00ac A \u2228 \u00ac B, from or.inr \u2039\u00ac B\u203a, h1 h2),\nh \u27e8 \u2039A\u203a, \u2039B\u203a \u27e9\n)\n------------------------------------------------------------\n\n-- Also known as em A\nexample : A \u2228 \u00ac A := by_contradiction(\nassume h: \u00ac (A \u2228 \u00ac A),\nhave \u00ac A, from assume : A, show false, from have (A \u2228 \u00ac A), from or.inl \u2039A\u203a, h \u2039A \u2228 \u00ac A\u203a,\nhave \u00ac \u00ac A, from assume : \u00ac A, show false, from have (A \u2228 \u00ac A), from or.inr \u2039\u00ac A\u203a, h \u2039A \u2228 \u00ac A\u203a,\n\u2039\u00ac \u00ac A\u203a \u2039\u00ac A\u203a \n)\n\nexample (h: \u00ac \u00ac A) : A := by_contradiction(assume h1 : \u00ac A, h h1) \nexample (h: A) : \u00ac \u00ac A := show \u00ac \u00ac A, from assume : \u00ac A, \u2039\u00ac A\u203a \u2039A\u203a \n\n------------------------------------------------------------\n\nexample (h: A \u2192 B) : \u00ac A \u2228 B :=\nor.elim (em A)\n  (assume : A, show \u00ac A \u2228 B, from or.inr (h \u2039A\u203a))\n  (assume : \u00ac A, show \u00ac A \u2228 B, from or.inl \u2039\u00ac A\u203a) \n\nexample (h: \u00ac A \u2228 B) : A \u2192 B :=\nassume : A, or.elim h\n  (assume : \u00ac A, show B, from false.elim (\u2039\u00ac A\u203a \u2039A\u203a))\n  (assume : B, \u2039B\u203a)\n\n------------------------------------------------------------\n\nexample (h: A \u2192 B) : \u00ac B \u2192 \u00ac A :=\nassume : \u00ac B, show \u00ac A, from assume : A, \u2039\u00ac B\u203a (h \u2039A\u203a)\n\nexample (h: \u00ac B \u2192 \u00ac A) : A \u2192 B :=\nassume : A, or.elim (em B)\n  (assume : B, \u2039B\u203a)\n  (assume : \u00ac B, show B, from false.elim ((h \u2039\u00ac B\u203a) \u2039A\u203a))\n\n------------------------------------------------------------\n\nexample (h: \u00ac P \u2192 (Q \u2228 R)) (h1: \u00ac Q) (h2: \u00ac R) : P :=\nor.elim (em P)\n  (assume : P, \u2039P\u203a)\n  (assume : \u00ac P, show P, from false.elim\n    (or.elim (h \u2039\u00ac P\u203a) (assume : Q, h1 \u2039Q\u203a) (assume : R, h2 \u2039R\u203a)))\n\nexample : A \u2192 ((A \u2227 B) \u2228 (A \u2227 \u00ac B)) :=\nassume : A, or.elim (em B)\n  (assume : B, show ((A \u2227 B) \u2228 (A \u2227 \u00ac B)), from or.inl \u27e8\u2039A\u203a,\u2039B\u203a\u27e9)\n  (assume : \u00ac B, show ((A \u2227 B) \u2228 (A \u2227 \u00ac B)), from or.inr \u27e8\u2039A\u203a,\u2039\u00ac B\u203a\u27e9)\n\n\n\n\n\n", "meta": {"author": "na-ka-na", "repo": "lean-practice", "sha": "1617dfb0e216db1182e83d68e4371d0e3ca45580", "save_path": "github-repos/lean/na-ka-na-lean-practice", "path": "github-repos/lean/na-ka-na-lean-practice/lean-practice-1617dfb0e216db1182e83d68e4371d0e3ca45580/logic_and_proof/propositions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901036, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.705247618037122}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n-/\nimport measure_theory.constructions.borel_space\nimport order.filter.ennreal\n\n/-!\n# Essential supremum and infimum\nWe define the essential supremum and infimum of a function `f : \u03b1 \u2192 \u03b2` with respect to a measure\n`\u03bc` on `\u03b1`. The essential supremum is the infimum of the constants `c : \u03b2` such that `f x \u2264 c`\nalmost everywhere.\n\nTODO: The essential supremum of functions `\u03b1 \u2192 \u211d\u22650\u221e` is used in particular to define the norm in\nthe `L\u221e` space (see measure_theory/lp_space.lean).\n\nThere is a different quantity which is sometimes also called essential supremum: the least\nupper-bound among measurable functions of a family of measurable functions (in an almost-everywhere\nsense). We do not define that quantity here, which is simply the supremum of a map with values in\n`\u03b1 \u2192\u2098[\u03bc] \u03b2` (see measure_theory/ae_eq_fun.lean).\n\n## Main definitions\n\n* `ess_sup f \u03bc := \u03bc.ae.limsup f`\n* `ess_inf f \u03bc := \u03bc.ae.liminf f`\n-/\n\nopen measure_theory filter topological_space\nopen_locale ennreal measure_theory\n\nvariables {\u03b1 \u03b2 : Type*} {m : measurable_space \u03b1} {\u03bc \u03bd : measure \u03b1}\n\nsection conditionally_complete_lattice\nvariable [conditionally_complete_lattice \u03b2]\n\n/-- Essential supremum of `f` with respect to measure `\u03bc`: the smallest `c : \u03b2` such that\n`f x \u2264 c` a.e. -/\ndef ess_sup {m : measurable_space \u03b1} (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) := \u03bc.ae.limsup f\n\n/-- Essential infimum of `f` with respect to measure `\u03bc`: the greatest `c : \u03b2` such that\n`c \u2264 f x` a.e. -/\ndef ess_inf {m : measurable_space \u03b1} (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) := \u03bc.ae.liminf f\n\nlemma ess_sup_congr_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f =\u1d50[\u03bc] g) : ess_sup f \u03bc = ess_sup g \u03bc :=\nlimsup_congr hfg\n\nlemma ess_inf_congr_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f =\u1d50[\u03bc] g) :  ess_inf f \u03bc = ess_inf g \u03bc :=\n@ess_sup_congr_ae \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ _ hfg\n\nend conditionally_complete_lattice\n\nsection conditionally_complete_linear_order\nvariable [conditionally_complete_linear_order \u03b2]\n\nlemma ess_sup_eq_Inf {m : measurable_space \u03b1} (\u03bc : measure \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  ess_sup f \u03bc = Inf {a | \u03bc {x | a < f x} = 0} :=\nbegin\n  dsimp [ess_sup, limsup, Limsup],\n  congr,\n  ext a,\n  simp [eventually_map, ae_iff],\nend\n\nend conditionally_complete_linear_order\n\nsection complete_lattice\nvariable [complete_lattice \u03b2]\n\n@[simp] lemma ess_sup_measure_zero {m : measurable_space \u03b1} {f : \u03b1 \u2192 \u03b2} :\n  ess_sup f (0 : measure \u03b1) = \u22a5 :=\nle_bot_iff.mp (Inf_le (by simp [set.mem_set_of_eq, eventually_le, ae_iff]))\n\n@[simp] lemma ess_inf_measure_zero {m : measurable_space \u03b1} {f : \u03b1 \u2192 \u03b2} :\n  ess_inf f (0 : measure \u03b1) = \u22a4 :=\n@ess_sup_measure_zero \u03b1 \u03b2\u1d52\u1d48 _ _ _\n\nlemma ess_sup_mono_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f \u2264\u1d50[\u03bc] g) : ess_sup f \u03bc \u2264 ess_sup g \u03bc :=\nlimsup_le_limsup hfg\n\nlemma ess_inf_mono_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f \u2264\u1d50[\u03bc] g) : ess_inf f \u03bc \u2264 ess_inf g \u03bc :=\nliminf_le_liminf hfg\n\nlemma ess_sup_const (c : \u03b2) (h\u03bc : \u03bc \u2260 0) : ess_sup (\u03bb x : \u03b1, c) \u03bc = c :=\nbegin\n  haveI h\u03bc_ne_bot : \u03bc.ae.ne_bot, { rwa [ne_bot_iff, ne.def, ae_eq_bot] },\n  exact limsup_const c,\nend\n\nlemma ess_sup_le_of_ae_le {f : \u03b1 \u2192 \u03b2} (c : \u03b2) (hf : f \u2264\u1d50[\u03bc] (\u03bb _, c)) : ess_sup f \u03bc \u2264 c :=\nbegin\n  refine (ess_sup_mono_ae hf).trans _,\n  by_cases h\u03bc : \u03bc = 0,\n  { simp [h\u03bc], },\n  { rwa ess_sup_const, },\nend\n\nlemma ess_inf_const (c : \u03b2) (h\u03bc : \u03bc \u2260 0) : ess_inf (\u03bb x : \u03b1, c) \u03bc = c :=\n@ess_sup_const \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ h\u03bc\n\nlemma le_ess_inf_of_ae_le {f : \u03b1 \u2192 \u03b2} (c : \u03b2) (hf : (\u03bb _, c) \u2264\u1d50[\u03bc] f) : c \u2264 ess_inf f \u03bc :=\n@ess_sup_le_of_ae_le \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ c hf\n\nlemma ess_sup_const_bot : ess_sup (\u03bb x : \u03b1, (\u22a5 : \u03b2)) \u03bc = (\u22a5 : \u03b2) :=\nlimsup_const_bot\n\nlemma ess_inf_const_top : ess_inf (\u03bb x : \u03b1, (\u22a4 : \u03b2)) \u03bc = (\u22a4 : \u03b2) :=\nliminf_const_top\n\nlemma order_iso.ess_sup_apply {m : measurable_space \u03b1} {\u03b3} [complete_lattice \u03b3]\n  (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) (g : \u03b2 \u2243o \u03b3) :\n  g (ess_sup f \u03bc) = ess_sup (\u03bb x, g (f x)) \u03bc :=\nbegin\n  refine order_iso.limsup_apply g _ _ _ _,\n  all_goals { is_bounded_default, },\nend\n\nlemma order_iso.ess_inf_apply {m : measurable_space \u03b1} {\u03b3} [complete_lattice \u03b3]\n  (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) (g : \u03b2 \u2243o \u03b3) :\n  g (ess_inf f \u03bc) = ess_inf (\u03bb x, g (f x)) \u03bc :=\n@order_iso.ess_sup_apply \u03b1 \u03b2\u1d52\u1d48 _ _  \u03b3\u1d52\u1d48 _ _ _ g.dual\n\nlemma ess_sup_mono_measure {f : \u03b1 \u2192 \u03b2} (h\u03bc\u03bd : \u03bd \u226a \u03bc) : ess_sup f \u03bd \u2264 ess_sup f \u03bc :=\nbegin\n  refine limsup_le_limsup_of_le (measure.ae_le_iff_absolutely_continuous.mpr h\u03bc\u03bd) _ _,\n  all_goals { is_bounded_default, },\nend\n\nlemma ess_sup_mono_measure' {\u03b1 : Type*} {\u03b2 : Type*} {m : measurable_space \u03b1}\n  {\u03bc \u03bd : measure_theory.measure \u03b1} [complete_lattice \u03b2] {f : \u03b1 \u2192 \u03b2} (h\u03bc\u03bd : \u03bd \u2264 \u03bc) :\n  ess_sup f \u03bd \u2264 ess_sup f \u03bc := ess_sup_mono_measure (measure.absolutely_continuous_of_le h\u03bc\u03bd)\n\nlemma ess_inf_antitone_measure {f : \u03b1 \u2192 \u03b2} (h\u03bc\u03bd : \u03bc \u226a \u03bd) : ess_inf f \u03bd \u2264 ess_inf f \u03bc :=\nbegin\n  refine liminf_le_liminf_of_le (measure.ae_le_iff_absolutely_continuous.mpr h\u03bc\u03bd) _ _,\n  all_goals { is_bounded_default, },\nend\n\nlemma ess_sup_smul_measure {f : \u03b1 \u2192 \u03b2} {c : \u211d\u22650\u221e} (hc : c \u2260 0) :\n  ess_sup f (c \u2022 \u03bc) = ess_sup f \u03bc :=\nbegin\n  simp_rw ess_sup,\n  suffices h_smul : (c \u2022 \u03bc).ae = \u03bc.ae, by rw h_smul,\n  ext1,\n  simp_rw mem_ae_iff,\n  simp [hc],\nend\n\nsection topological_space\n\nvariables {\u03b3 : Type*} {m\u03b3 : measurable_space \u03b3} {f : \u03b1 \u2192 \u03b3} {g : \u03b3 \u2192 \u03b2}\n\ninclude m\u03b3\n\nlemma ess_sup_comp_le_ess_sup_map_measure (hf : ae_measurable f \u03bc) :\n  ess_sup (g \u2218 f) \u03bc \u2264 ess_sup g (measure.map f \u03bc) :=\nbegin\n  refine Limsup_le_Limsup_of_le (\u03bb t, _) (by is_bounded_default) (by is_bounded_default),\n  simp_rw filter.mem_map,\n  have : (g \u2218 f) \u207b\u00b9' t = f \u207b\u00b9' (g \u207b\u00b9' t), by { ext1 x, simp_rw set.mem_preimage, },\n  rw this,\n  exact \u03bb h, mem_ae_of_mem_ae_map hf h,\nend\n\nlemma _root_.measurable_embedding.ess_sup_map_measure (hf : measurable_embedding f) :\n  ess_sup g (measure.map f \u03bc) = ess_sup (g \u2218 f) \u03bc :=\nbegin\n  refine le_antisymm _ (ess_sup_comp_le_ess_sup_map_measure hf.measurable.ae_measurable),\n  refine Limsup_le_Limsup (by is_bounded_default) (by is_bounded_default) (\u03bb c h_le, _),\n  rw eventually_map at h_le \u22a2,\n  exact hf.ae_map_iff.mpr h_le,\nend\n\nvariables [measurable_space \u03b2] [topological_space \u03b2] [second_countable_topology \u03b2]\n  [order_closed_topology \u03b2] [opens_measurable_space \u03b2]\n\nlemma ess_sup_map_measure_of_measurable (hg : measurable g) (hf : ae_measurable f \u03bc) :\n  ess_sup g (measure.map f \u03bc) = ess_sup (g \u2218 f) \u03bc :=\nbegin\n  refine le_antisymm _ (ess_sup_comp_le_ess_sup_map_measure hf),\n  refine Limsup_le_Limsup (by is_bounded_default) (by is_bounded_default) (\u03bb c h_le, _),\n  rw eventually_map at h_le \u22a2,\n  rw ae_map_iff hf (measurable_set_le hg measurable_const),\n  exact h_le,\nend\n\nlemma ess_sup_map_measure (hg : ae_measurable g (measure.map f \u03bc)) (hf : ae_measurable f \u03bc) :\n  ess_sup g (measure.map f \u03bc) = ess_sup (g \u2218 f) \u03bc :=\nbegin\n  rw [ess_sup_congr_ae hg.ae_eq_mk, ess_sup_map_measure_of_measurable hg.measurable_mk hf],\n  refine ess_sup_congr_ae _,\n  have h_eq := ae_of_ae_map hf hg.ae_eq_mk,\n  rw \u2190 eventually_eq at h_eq,\n  exact h_eq.symm,\nend\n\nomit m\u03b3\n\nend topological_space\n\nend complete_lattice\n\nsection complete_linear_order\nvariable [complete_linear_order \u03b2]\n\nlemma ae_lt_of_ess_sup_lt {f : \u03b1 \u2192 \u03b2} {x : \u03b2} (hf : ess_sup f \u03bc < x) : \u2200\u1d50 y \u2202\u03bc, f y < x :=\nfilter.eventually_lt_of_limsup_lt hf\n\nlemma ae_lt_of_lt_ess_inf {f : \u03b1 \u2192 \u03b2} {x : \u03b2} (hf : x < ess_inf f \u03bc) : \u2200\u1d50 y \u2202\u03bc, x < f y :=\n@ae_lt_of_ess_sup_lt \u03b1 \u03b2\u1d52\u1d48 _ _ _ _ _ hf\n\nlemma ess_sup_indicator_eq_ess_sup_restrict [has_zero \u03b2] {s : set \u03b1}\n  {f : \u03b1 \u2192 \u03b2} (hf : 0 \u2264\u1d50[\u03bc.restrict s] f) (hs : measurable_set s) (hs_not_null : \u03bc s \u2260 0) :\n  ess_sup (s.indicator f) \u03bc = ess_sup f (\u03bc.restrict s) :=\nbegin\n  refine le_antisymm _ (Limsup_le_Limsup_of_le (map_restrict_ae_le_map_indicator_ae hs)\n    (by is_bounded_default) (by is_bounded_default)),\n  refine Limsup_le_Limsup (by is_bounded_default) (by is_bounded_default) (\u03bb c h_restrict_le, _),\n  rw eventually_map at h_restrict_le \u22a2,\n  rw ae_restrict_iff' hs at h_restrict_le,\n  have hc : 0 \u2264 c,\n  { rsuffices \u27e8x, hx\u27e9 : \u2203 x, 0 \u2264 f x \u2227 f x \u2264 c, from hx.1.trans hx.2,\n    refine frequently.exists _,\n    { exact \u03bc.ae, },\n    rw [eventually_le, ae_restrict_iff' hs] at hf,\n    have hs' : \u2203\u1d50 x \u2202\u03bc, x \u2208 s,\n    { contrapose! hs_not_null,\n      rw [not_frequently, ae_iff] at hs_not_null,\n      suffices : {a : \u03b1 | \u00aca \u2209 s} = s, by rwa \u2190 this,\n      simp, },\n    refine hs'.mp (hf.mp (h_restrict_le.mono (\u03bb x hxs_imp_c hxf_nonneg hxs, _))),\n    rw pi.zero_apply at hxf_nonneg,\n    exact \u27e8hxf_nonneg hxs, hxs_imp_c hxs\u27e9, },\n  refine h_restrict_le.mono (\u03bb x hxc, _),\n  by_cases hxs : x \u2208 s,\n  { simpa [hxs] using hxc hxs, },\n  { simpa [hxs] using hc, },\nend\n\nend complete_linear_order\n\nnamespace ennreal\n\nvariables {f : \u03b1 \u2192 \u211d\u22650\u221e}\n\nlemma ae_le_ess_sup (f : \u03b1 \u2192 \u211d\u22650\u221e) : \u2200\u1d50 y \u2202\u03bc, f y \u2264 ess_sup f \u03bc :=\neventually_le_limsup f\n\n@[simp] lemma ess_sup_eq_zero_iff : ess_sup f \u03bc = 0 \u2194 f =\u1d50[\u03bc] 0 :=\nlimsup_eq_zero_iff\n\nlemma ess_sup_const_mul {a : \u211d\u22650\u221e} : ess_sup (\u03bb (x : \u03b1), a * (f x)) \u03bc = a * ess_sup f \u03bc :=\nlimsup_const_mul\n\nlemma ess_sup_mul_le (f g : \u03b1 \u2192 \u211d\u22650\u221e) : ess_sup (f * g) \u03bc \u2264 ess_sup f \u03bc * ess_sup g \u03bc :=\nlimsup_mul_le f g\n\nlemma ess_sup_add_le (f g : \u03b1 \u2192 \u211d\u22650\u221e) : ess_sup (f + g) \u03bc \u2264 ess_sup f \u03bc + ess_sup g \u03bc :=\nlimsup_add_le f g\n\nlemma ess_sup_liminf_le {\u03b9} [countable \u03b9] [linear_order \u03b9] (f : \u03b9 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) :\n  ess_sup (\u03bb x, at_top.liminf (\u03bb n, f n x)) \u03bc \u2264 at_top.liminf (\u03bb n, ess_sup (\u03bb x, f n x) \u03bc) :=\nby { simp_rw ess_sup, exact ennreal.limsup_liminf_le_liminf_limsup (\u03bb a b, f b a), }\n\nend ennreal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/function/ess_sup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541611, "lm_q2_score": 0.8221891218080991, "lm_q1q2_score": 0.7052476019673783}}
{"text": "/-\nCopyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mathieu Guay-Paquet\n-/\nimport order.ideal\n\n/-!\n# Order filters\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections\nrequire more structure, such as a bottom element, a top element, or\na join-semilattice structure.\n\n- `order.pfilter P`: The type of nonempty, downward directed, upward closed\n               subsets of `P`. This is dual to `order.ideal`, so it\n               simply wraps `order.ideal (order_dual P)`.\n- `order.is_pfilter P`: a predicate for when a `set P` is a filter.\n\n\nNote the relation between `order/filter` and `order/pfilter`: for any\ntype `\u03b1`, `filter \u03b1` represents the same mathematical object as\n`pfilter (set \u03b1)`.\n\n## References\n\n- <https://en.wikipedia.org/wiki/Filter_(mathematics)>\n\n## Tags\n\npfilter, filter, ideal, dual\n\n-/\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- A filter on a preorder `P` is a subset of `P` that is\n  - nonempty\n  - downward directed\n  - upward closed. -/\nstructure pfilter (P) [preorder P] :=\n(dual : ideal (order_dual P))\n\n/-- A predicate for when a subset of `P` is a filter. -/\ndef is_pfilter [preorder P] (F : set P) : Prop :=\n@is_ideal (order_dual P) _ F\n\n\n\n/-- Create an element of type `order.pfilter` from a set satisfying the predicate\n`order.is_pfilter`. -/\ndef is_pfilter.to_pfilter [preorder P] {F : set P} (h : is_pfilter F) : pfilter P :=\n\u27e8h.to_ideal\u27e9\n\nnamespace pfilter\n\nsection preorder\nvariables [preorder P] {x y : P} (F : pfilter P)\n\n/-- A filter on `P` is a subset of `P`. -/\ninstance : has_coe (pfilter P) (set P) := \u27e8\u03bb F, F.dual.carrier\u27e9\n\n/-- For the notation `x \u2208 F`. -/\ninstance : has_mem P (pfilter P) := \u27e8\u03bb x F, x \u2208 (F : set P)\u27e9\n\n@[simp] lemma mem_coe : x \u2208 (F : set P) \u2194 x \u2208 F := iff_of_eq rfl\n\nlemma is_pfilter : is_pfilter (F : set P) :=\nF.dual.is_ideal\n\nlemma nonempty : (F : set P).nonempty := F.dual.nonempty\n\nlemma directed : directed_on (\u2265) (F : set P) := F.dual.directed\n\nlemma mem_of_le {F : pfilter P} : x \u2264 y \u2192 x \u2208 F \u2192 y \u2208 F := \u03bb h, F.dual.mem_of_le h\n\n/-- The smallest filter containing a given element. -/\ndef principal (p : P) : pfilter P := \u27e8ideal.principal p\u27e9\n\ninstance [inhabited P] : inhabited (pfilter P) := \u27e8\u27e8default _\u27e9\u27e9\n\n/-- Two filters are equal when their underlying sets are equal. -/\n@[ext] lemma ext : \u2200 (F G : pfilter P), (F : set P) = G \u2192 F = G\n| \u27e8\u27e8_, _, _, _\u27e9\u27e9 \u27e8\u27e8_, _, _, _\u27e9\u27e9 rfl := rfl\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (pfilter P) := partial_order.lift coe ext\n\n@[trans] lemma mem_of_mem_of_le {F G : pfilter P} : x \u2208 F \u2192 F \u2264 G \u2192 x \u2208 G :=\nideal.mem_of_mem_of_le\n\n@[simp] lemma principal_le_iff {F : pfilter P} : principal x \u2264 F \u2194 x \u2208 F :=\nideal.principal_le_iff\n\nend preorder\n\nsection order_top\nvariables [order_top P] {F : pfilter P}\n\n/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/\n@[simp] lemma top_mem : \u22a4 \u2208 F :=\nideal.bot_mem\n\n/-- There is a bottom filter when `P` has a top element. -/\ninstance : order_bot (pfilter P) :=\n{ bot := \u27e8\u22a5\u27e9,\n  bot_le := \u03bb F, (bot_le : \u22a5 \u2264 F.dual),\n  .. pfilter.partial_order }\n\nend order_top\n\n/-- There is a top filter when `P` has a bottom element. -/\ninstance {P} [order_bot P] : order_top (pfilter P) :=\n{ top := \u27e8\u22a4\u27e9,\n  le_top := \u03bb F, (le_top : F.dual \u2264 \u22a4),\n  .. pfilter.partial_order }\n\nsection semilattice_inf\nvariables [semilattice_inf P] {x y : P} {F : pfilter P}\n\n/-- A specific witness of `pfilter.directed` when `P` has meets. -/\nlemma inf_mem (x y \u2208 F) : x \u2293 y \u2208 F :=\nideal.sup_mem x y \u2039x \u2208 F\u203a \u2039y \u2208 F\u203a\n\n@[simp] lemma inf_mem_iff : x \u2293 y \u2208 F \u2194 x \u2208 F \u2227 y \u2208 F :=\nideal.sup_mem_iff\n\nend semilattice_inf\n\nend pfilter\n\nend order\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/order/pfilter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.705247180817192}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.calculus.deriv\nimport linear_algebra.affine_space.slope\n\n/-!\n# Slope of a differentiable function\n\nGiven a function `f : \ud835\udd5c \u2192 E` from a nontrivially normed field to a normed space over this field,\n`dslope f a b` is defined as `slope f a b = (b - a)\u207b\u00b9 \u2022 (f b - f a)` for `a \u2260 b` and as `deriv f a`\nfor `a = b`.\n\nIn this file we define `dslope` and prove some basic lemmas about its continuity and\ndifferentiability.\n-/\n\nopen_locale classical topology filter\nopen function set filter\n\nvariables {\ud835\udd5c E : Type*} [nontrivially_normed_field \ud835\udd5c] [normed_add_comm_group E] [normed_space \ud835\udd5c E]\n\n/-- `dslope f a b` is defined as `slope f a b = (b - a)\u207b\u00b9 \u2022 (f b - f a)` for `a \u2260 b` and\n`deriv f a` for `a = b`. -/\nnoncomputable def dslope (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : \ud835\udd5c \u2192 E := update (slope f a) a (deriv f a)\n\n@[simp] lemma dslope_same (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : dslope f a a = deriv f a := update_same _ _ _\n\nvariables {f : \ud835\udd5c \u2192 E} {a b : \ud835\udd5c} {s : set \ud835\udd5c}\n\nlemma dslope_of_ne (f : \ud835\udd5c \u2192 E) (h : b \u2260 a) : dslope f a b = slope f a b :=\nupdate_noteq h _ _\n\nlemma continuous_linear_map.dslope_comp {F : Type*} [normed_add_comm_group F] [normed_space \ud835\udd5c F]\n  (f : E \u2192L[\ud835\udd5c] F) (g : \ud835\udd5c \u2192 E) (a b : \ud835\udd5c) (H : a = b \u2192 differentiable_at \ud835\udd5c g a) :\n  dslope (f \u2218 g) a b = f (dslope g a b) :=\nbegin\n  rcases eq_or_ne b a with rfl|hne,\n  { simp only [dslope_same],\n    exact (f.has_fderiv_at.comp_has_deriv_at b (H rfl).has_deriv_at).deriv },\n  { simpa only [dslope_of_ne _ hne] using f.to_linear_map.slope_comp g a b }\nend\n\nlemma eq_on_dslope_slope (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : eq_on (dslope f a) (slope f a) {a}\u1d9c :=\n\u03bb b, dslope_of_ne f\n\nlemma dslope_eventually_eq_slope_of_ne (f : \ud835\udd5c \u2192 E) (h : b \u2260 a) : dslope f a =\u1da0[\ud835\udcdd b] slope f a :=\n(eq_on_dslope_slope f a).eventually_eq_of_mem (is_open_ne.mem_nhds h)\n\nlemma dslope_eventually_eq_slope_punctured_nhds (f : \ud835\udd5c \u2192 E) : dslope f a =\u1da0[\ud835\udcdd[\u2260] a] slope f a :=\n(eq_on_dslope_slope f a).eventually_eq_of_mem self_mem_nhds_within\n\n@[simp] lemma sub_smul_dslope (f : \ud835\udd5c \u2192 E) (a b : \ud835\udd5c) : (b - a) \u2022 dslope f a b = f b - f a :=\nby rcases eq_or_ne b a with rfl | hne; simp [dslope_of_ne, *]\n\nlemma dslope_sub_smul_of_ne (f : \ud835\udd5c \u2192 E) (h : b \u2260 a) : dslope (\u03bb x, (x - a) \u2022 f x) a b = f b :=\nby rw [dslope_of_ne _ h, slope_sub_smul _ h.symm]\n\nlemma eq_on_dslope_sub_smul (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) : eq_on (dslope (\u03bb x, (x - a) \u2022 f x) a) f {a}\u1d9c :=\n\u03bb b, dslope_sub_smul_of_ne f\n\nlemma dslope_sub_smul [decidable_eq \ud835\udd5c] (f : \ud835\udd5c \u2192 E) (a : \ud835\udd5c) :\n  dslope (\u03bb x, (x - a) \u2022 f x) a = update f a (deriv (\u03bb x, (x - a) \u2022 f x) a) :=\neq_update_iff.2 \u27e8dslope_same _ _, eq_on_dslope_sub_smul f a\u27e9\n\n@[simp] lemma continuous_at_dslope_same : continuous_at (dslope f a) a \u2194 differentiable_at \ud835\udd5c f a :=\nby simp only [dslope, continuous_at_update_same, \u2190 has_deriv_at_deriv_iff,\n  has_deriv_at_iff_tendsto_slope]\n\nlemma continuous_within_at.of_dslope (h : continuous_within_at (dslope f a) s b) :\n  continuous_within_at f s b :=\nhave continuous_within_at (\u03bb x, (x - a) \u2022 dslope f a x + f a) s b,\n  from ((continuous_within_at_id.sub continuous_within_at_const).smul h).add\n    continuous_within_at_const,\nby simpa only [sub_smul_dslope, sub_add_cancel] using this\n\nlemma continuous_at.of_dslope (h : continuous_at (dslope f a) b) : continuous_at f b :=\n(continuous_within_at_univ _ _).1 h.continuous_within_at.of_dslope\n\nlemma continuous_on.of_dslope (h : continuous_on (dslope f a) s) : continuous_on f s :=\n\u03bb x hx, (h x hx).of_dslope\n\nlemma continuous_within_at_dslope_of_ne (h : b \u2260 a) :\n  continuous_within_at (dslope f a) s b \u2194 continuous_within_at f s b :=\nbegin\n  refine \u27e8continuous_within_at.of_dslope, \u03bb hc, _\u27e9,\n  simp only [dslope, continuous_within_at_update_of_ne h],\n  exact ((continuous_within_at_id.sub continuous_within_at_const).inv\u2080\n      (sub_ne_zero.2 h)).smul (hc.sub continuous_within_at_const)\nend\n\nlemma continuous_at_dslope_of_ne (h : b \u2260 a) : continuous_at (dslope f a) b \u2194 continuous_at f b :=\nby simp only [\u2190 continuous_within_at_univ, continuous_within_at_dslope_of_ne h]\n\nlemma continuous_on_dslope (h : s \u2208 \ud835\udcdd a) :\n  continuous_on (dslope f a) s \u2194 continuous_on f s \u2227 differentiable_at \ud835\udd5c f a :=\nbegin\n  refine \u27e8\u03bb hc, \u27e8hc.of_dslope, continuous_at_dslope_same.1 $ hc.continuous_at h\u27e9, _\u27e9,\n  rintro \u27e8hc, hd\u27e9 x hx,\n  rcases eq_or_ne x a with rfl | hne,\n  exacts [(continuous_at_dslope_same.2 hd).continuous_within_at,\n    (continuous_within_at_dslope_of_ne hne).2 (hc x hx)]\nend\n\nlemma differentiable_within_at.of_dslope (h : differentiable_within_at \ud835\udd5c (dslope f a) s b) :\n  differentiable_within_at \ud835\udd5c f s b :=\nby simpa only [id, sub_smul_dslope f a, sub_add_cancel]\n  using ((differentiable_within_at_id.sub_const a).smul h).add_const (f a)\n\nlemma differentiable_at.of_dslope (h : differentiable_at \ud835\udd5c (dslope f a) b) :\n  differentiable_at \ud835\udd5c f b :=\ndifferentiable_within_at_univ.1 h.differentiable_within_at.of_dslope\n\nlemma differentiable_on.of_dslope (h : differentiable_on \ud835\udd5c (dslope f a) s) :\n  differentiable_on \ud835\udd5c f s :=\n\u03bb x hx, (h x hx).of_dslope\n\nlemma differentiable_within_at_dslope_of_ne (h : b \u2260 a) :\n  differentiable_within_at \ud835\udd5c (dslope f a) s b \u2194 differentiable_within_at \ud835\udd5c f s b :=\nbegin\n  refine \u27e8differentiable_within_at.of_dslope, \u03bb hd, _\u27e9,\n  refine (((differentiable_within_at_id.sub_const a).inv\n    (sub_ne_zero.2 h)).smul (hd.sub_const (f a))).congr_of_eventually_eq _ (dslope_of_ne _ h),\n  refine (eq_on_dslope_slope _ _).eventually_eq_of_mem _,\n  exact mem_nhds_within_of_mem_nhds (is_open_ne.mem_nhds h)\nend\n\nlemma differentiable_on_dslope_of_nmem (h : a \u2209 s) :\n  differentiable_on \ud835\udd5c (dslope f a) s \u2194 differentiable_on \ud835\udd5c f s :=\nforall_congr $ \u03bb x, forall_congr $ \u03bb hx, differentiable_within_at_dslope_of_ne $\n  ne_of_mem_of_not_mem hx h\n\nlemma differentiable_at_dslope_of_ne (h : b \u2260 a) :\n  differentiable_at \ud835\udd5c (dslope f a) b \u2194 differentiable_at \ud835\udd5c f b :=\nby simp only [\u2190 differentiable_within_at_univ,\n  differentiable_within_at_dslope_of_ne h]\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/calculus/dslope.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.7052471799954335}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport linear_algebra.quotient\nimport linear_algebra.prod\n\n/-!\n# Projection to a subspace\n\nIn this file we define\n* `linear_proj_of_is_compl (p q : submodule R E) (h : is_compl p q)`: the projection of a module `E`\n  to a submodule `p` along its complement `q`; it is the unique linear map `f : E \u2192 p` such that\n  `f x = x` for `x \u2208 p` and `f x = 0` for `x \u2208 q`.\n* `is_compl_equiv_proj p`: equivalence between submodules `q` such that `is_compl p q` and\n  projections `f : E \u2192 p`, `\u2200 x \u2208 p, f x = x`.\n\nWe also provide some lemmas justifying correctness of our definitions.\n\n## Tags\n\nprojection, complement subspace\n-/\n\nsection ring\n\nvariables {R : Type*} [ring R] {E : Type*} [add_comm_group E] [module R E]\n  {F : Type*} [add_comm_group F] [module R F]\n  {G : Type*} [add_comm_group G] [module R G] (p q : submodule R E)\nvariables {S : Type*} [semiring S] {M : Type*} [add_comm_monoid M] [module S M] (m : submodule S M)\n\n\nnoncomputable theory\n\nnamespace linear_map\n\nvariable {p}\n\nopen submodule\n\nlemma ker_id_sub_eq_of_proj {f : E \u2192\u2097[R] p} (hf : \u2200 x : p, f x = x) :\n  ker (id - p.subtype.comp f) = p :=\nbegin\n  ext x,\n  simp only [comp_apply, mem_ker, subtype_apply, sub_apply, id_apply, sub_eq_zero],\n  exact \u27e8\u03bb h, h.symm \u25b8 submodule.coe_mem _, \u03bb hx, by erw [hf \u27e8x, hx\u27e9, subtype.coe_mk]\u27e9\nend\n\nlemma range_eq_of_proj {f : E \u2192\u2097[R] p} (hf : \u2200 x : p, f x = x) :\n  range f = \u22a4 :=\nrange_eq_top.2 $ \u03bb x, \u27e8x, hf x\u27e9\n\nlemma is_compl_of_proj {f : E \u2192\u2097[R] p} (hf : \u2200 x : p, f x = x) :\n  is_compl p f.ker :=\nbegin\n  split,\n  { rintros x \u27e8hpx, hfx\u27e9,\n    erw [set_like.mem_coe, mem_ker, hf \u27e8x, hpx\u27e9, mk_eq_zero] at hfx,\n    simp only [hfx, set_like.mem_coe, zero_mem] },\n  { intros x hx,\n    rw [mem_sup'],\n    refine \u27e8f x, \u27e8x - f x, _\u27e9, add_sub_cancel'_right _ _\u27e9,\n    rw [mem_ker, linear_map.map_sub, hf, sub_self] }\nend\n\nend linear_map\n\nnamespace submodule\n\nopen linear_map\n\n/-- If `q` is a complement of `p`, then `M/p \u2243 q`. -/\ndef quotient_equiv_of_is_compl (h : is_compl p q) : (E \u29f8 p) \u2243\u2097[R] q :=\nlinear_equiv.symm $ linear_equiv.of_bijective (p.mkq.comp q.subtype)\n  (by simp only [\u2190 ker_eq_bot, ker_comp, ker_mkq, disjoint_iff_comap_eq_bot.1 h.symm.disjoint])\n  (by simp only [\u2190 range_eq_top, range_comp, range_subtype, map_mkq_eq_top, h.sup_eq_top])\n\n@[simp] lemma quotient_equiv_of_is_compl_symm_apply (h : is_compl p q) (x : q) :\n  (quotient_equiv_of_is_compl p q h).symm x = quotient.mk x := rfl\n\n@[simp] lemma quotient_equiv_of_is_compl_apply_mk_coe (h : is_compl p q) (x : q) :\n  quotient_equiv_of_is_compl p q h (quotient.mk x) = x :=\n(quotient_equiv_of_is_compl p q h).apply_symm_apply x\n\n@[simp] lemma mk_quotient_equiv_of_is_compl_apply (h : is_compl p q) (x : E \u29f8 p) :\n  (quotient.mk (quotient_equiv_of_is_compl p q h x) : E \u29f8 p) = x :=\n(quotient_equiv_of_is_compl p q h).symm_apply_apply x\n\n/-- If `q` is a complement of `p`, then `p \u00d7 q` is isomorphic to `E`. It is the unique\nlinear map `f : E \u2192 p` such that `f x = x` for `x \u2208 p` and `f x = 0` for `x \u2208 q`. -/\ndef prod_equiv_of_is_compl (h : is_compl p q) : (p \u00d7 q) \u2243\u2097[R] E :=\nbegin\n  apply linear_equiv.of_bijective (p.subtype.coprod q.subtype),\n  { simp only [\u2190ker_eq_bot, ker_eq_bot', prod.forall, subtype_apply, prod.mk_eq_zero, coprod_apply],\n    -- TODO: if I add `submodule.forall`, it unfolds the outer `\u2200` but not the inner one.\n    rintros \u27e8x, hx\u27e9 \u27e8y, hy\u27e9,\n    simp only [coe_mk, mk_eq_zero, \u2190 eq_neg_iff_add_eq_zero],\n    rintro rfl,\n    rw [neg_mem_iff] at hx,\n    simp [disjoint_def.1 h.disjoint y hx hy] },\n  { rw [\u2190 range_eq_top, \u2190 sup_eq_range, h.sup_eq_top] }\nend\n\n@[simp] lemma coe_prod_equiv_of_is_compl (h : is_compl p q) :\n  (prod_equiv_of_is_compl p q h : (p \u00d7 q) \u2192\u2097[R] E) = p.subtype.coprod q.subtype := rfl\n\n@[simp] lemma coe_prod_equiv_of_is_compl' (h : is_compl p q) (x : p \u00d7 q) :\n  prod_equiv_of_is_compl p q h x = x.1 + x.2 := rfl\n\n@[simp] lemma prod_equiv_of_is_compl_symm_apply_left (h : is_compl p q) (x : p) :\n  (prod_equiv_of_is_compl p q h).symm x = (x, 0) :=\n(prod_equiv_of_is_compl p q h).symm_apply_eq.2 $ by simp\n\n@[simp] lemma prod_equiv_of_is_compl_symm_apply_right (h : is_compl p q) (x : q) :\n  (prod_equiv_of_is_compl p q h).symm x = (0, x) :=\n(prod_equiv_of_is_compl p q h).symm_apply_eq.2 $ by simp\n\n@[simp] lemma prod_equiv_of_is_compl_symm_apply_fst_eq_zero (h : is_compl p q) {x : E} :\n  ((prod_equiv_of_is_compl p q h).symm x).1 = 0 \u2194 x \u2208 q :=\nbegin\n  conv_rhs { rw [\u2190 (prod_equiv_of_is_compl p q h).apply_symm_apply x] },\n  rw [coe_prod_equiv_of_is_compl', submodule.add_mem_iff_left _ (submodule.coe_mem _),\n    mem_right_iff_eq_zero_of_disjoint h.disjoint]\nend\n\n@[simp] lemma prod_equiv_of_is_compl_symm_apply_snd_eq_zero (h : is_compl p q) {x : E} :\n  ((prod_equiv_of_is_compl p q h).symm x).2 = 0 \u2194 x \u2208 p :=\nbegin\n  conv_rhs { rw [\u2190 (prod_equiv_of_is_compl p q h).apply_symm_apply x] },\n  rw [coe_prod_equiv_of_is_compl', submodule.add_mem_iff_right _ (submodule.coe_mem _),\n    mem_left_iff_eq_zero_of_disjoint h.disjoint]\nend\n\n@[simp]\nlemma prod_comm_trans_prod_equiv_of_is_compl (h : is_compl p q) :\n  linear_equiv.prod_comm R q p \u226a\u226b\u2097 prod_equiv_of_is_compl p q h =\n    prod_equiv_of_is_compl q p h.symm :=\nlinear_equiv.ext $ \u03bb _, add_comm _ _\n\n/-- Projection to a submodule along its complement. -/\ndef linear_proj_of_is_compl (h : is_compl p q) :\n  E \u2192\u2097[R] p :=\n(linear_map.fst R p q) \u2218\u2097 \u2191(prod_equiv_of_is_compl p q h).symm\n\nvariables {p q}\n\n@[simp] lemma linear_proj_of_is_compl_apply_left (h : is_compl p q) (x : p) :\n  linear_proj_of_is_compl p q h x = x :=\nby simp [linear_proj_of_is_compl]\n\n@[simp] lemma linear_proj_of_is_compl_range (h : is_compl p q) :\n  (linear_proj_of_is_compl p q h).range = \u22a4 :=\nrange_eq_of_proj (linear_proj_of_is_compl_apply_left h)\n\n@[simp] lemma linear_proj_of_is_compl_apply_eq_zero_iff (h : is_compl p q) {x : E} :\n  linear_proj_of_is_compl p q h x = 0 \u2194 x \u2208 q:=\nby simp [linear_proj_of_is_compl]\n\nlemma linear_proj_of_is_compl_apply_right' (h : is_compl p q) (x : E) (hx : x \u2208 q) :\n  linear_proj_of_is_compl p q h x = 0 :=\n(linear_proj_of_is_compl_apply_eq_zero_iff h).2 hx\n\n@[simp] lemma linear_proj_of_is_compl_apply_right (h : is_compl p q) (x : q) :\n  linear_proj_of_is_compl p q h x = 0 :=\nlinear_proj_of_is_compl_apply_right' h x x.2\n\n@[simp] lemma linear_proj_of_is_compl_ker (h : is_compl p q) :\n  (linear_proj_of_is_compl p q h).ker = q :=\next $ \u03bb x, mem_ker.trans (linear_proj_of_is_compl_apply_eq_zero_iff h)\n\nlemma linear_proj_of_is_compl_comp_subtype (h : is_compl p q) :\n  (linear_proj_of_is_compl p q h).comp p.subtype = id :=\nlinear_map.ext $ linear_proj_of_is_compl_apply_left h\n\nlemma linear_proj_of_is_compl_idempotent (h : is_compl p q) (x : E) :\n  linear_proj_of_is_compl p q h (linear_proj_of_is_compl p q h x) =\n    linear_proj_of_is_compl p q h x :=\nlinear_proj_of_is_compl_apply_left h _\n\nlemma exists_unique_add_of_is_compl_prod (hc : is_compl p q) (x : E) :\n  \u2203! (u : p \u00d7 q), (u.fst : E) + u.snd = x :=\n(prod_equiv_of_is_compl _ _ hc).to_equiv.bijective.exists_unique _\n\nlemma exists_unique_add_of_is_compl (hc : is_compl p q) (x : E) :\n  \u2203 (u : p) (v : q), ((u : E) + v = x \u2227 \u2200 (r : p) (s : q),\n    (r : E) + s = x \u2192 r = u \u2227 s = v) :=\nlet \u27e8u, hu\u2081, hu\u2082\u27e9 := exists_unique_add_of_is_compl_prod hc x in\n  \u27e8u.1, u.2, hu\u2081, \u03bb r s hrs, prod.eq_iff_fst_eq_snd_eq.1 (hu\u2082 \u27e8r, s\u27e9 hrs)\u27e9\n\nlemma linear_proj_add_linear_proj_of_is_compl_eq_self (hpq : is_compl p q) (x : E) :\n  (p.linear_proj_of_is_compl q hpq x + q.linear_proj_of_is_compl p hpq.symm x : E) = x :=\nbegin\n  dunfold linear_proj_of_is_compl,\n  rw \u2190prod_comm_trans_prod_equiv_of_is_compl _ _ hpq,\n  exact (prod_equiv_of_is_compl _ _ hpq).apply_symm_apply x,\nend\n\nend submodule\n\nnamespace linear_map\n\nopen submodule\n\n/-- Given linear maps `\u03c6` and `\u03c8` from complement submodules, `of_is_compl` is\nthe induced linear map over the entire module. -/\ndef of_is_compl {p q : submodule R E} (h : is_compl p q)\n  (\u03c6 : p \u2192\u2097[R] F) (\u03c8 : q \u2192\u2097[R] F) : E \u2192\u2097[R] F :=\n(linear_map.coprod \u03c6 \u03c8) \u2218\u2097 \u2191(submodule.prod_equiv_of_is_compl _ _ h).symm\n\nvariables {p q}\n\n@[simp] lemma of_is_compl_left_apply\n  (h : is_compl p q) {\u03c6 : p \u2192\u2097[R] F} {\u03c8 : q \u2192\u2097[R] F} (u : p) :\n  of_is_compl h \u03c6 \u03c8 (u : E) = \u03c6 u := by simp [of_is_compl]\n\n@[simp] lemma of_is_compl_right_apply\n  (h : is_compl p q) {\u03c6 : p \u2192\u2097[R] F} {\u03c8 : q \u2192\u2097[R] F} (v : q) :\n  of_is_compl h \u03c6 \u03c8 (v : E) = \u03c8 v := by simp [of_is_compl]\n\nlemma of_is_compl_eq (h : is_compl p q)\n  {\u03c6 : p \u2192\u2097[R] F} {\u03c8 : q \u2192\u2097[R] F} {\u03c7 : E \u2192\u2097[R] F}\n  (h\u03c6 : \u2200 u, \u03c6 u = \u03c7 u) (h\u03c8 : \u2200 u, \u03c8 u = \u03c7 u) :\n  of_is_compl h \u03c6 \u03c8 = \u03c7 :=\nbegin\n  ext x,\n  obtain \u27e8_, _, rfl, _\u27e9 := exists_unique_add_of_is_compl h x,\n  simp [of_is_compl, h\u03c6, h\u03c8]\nend\n\nlemma of_is_compl_eq' (h : is_compl p q)\n  {\u03c6 : p \u2192\u2097[R] F} {\u03c8 : q \u2192\u2097[R] F} {\u03c7 : E \u2192\u2097[R] F}\n  (h\u03c6 : \u03c6 = \u03c7.comp p.subtype) (h\u03c8 : \u03c8 = \u03c7.comp q.subtype) :\n  of_is_compl h \u03c6 \u03c8 = \u03c7 :=\nof_is_compl_eq h (\u03bb _, h\u03c6.symm \u25b8 rfl) (\u03bb _, h\u03c8.symm \u25b8 rfl)\n\n@[simp] lemma of_is_compl_zero (h : is_compl p q) :\n  (of_is_compl h 0 0 : E \u2192\u2097[R] F) = 0 :=\nof_is_compl_eq _ (\u03bb _, rfl) (\u03bb _, rfl)\n\n@[simp] lemma of_is_compl_add (h : is_compl p q)\n  {\u03c6\u2081 \u03c6\u2082 : p \u2192\u2097[R] F} {\u03c8\u2081 \u03c8\u2082 : q \u2192\u2097[R] F} :\n  of_is_compl h (\u03c6\u2081 + \u03c6\u2082) (\u03c8\u2081 + \u03c8\u2082) = of_is_compl h \u03c6\u2081 \u03c8\u2081 + of_is_compl h \u03c6\u2082 \u03c8\u2082 :=\nof_is_compl_eq _ (by simp) (by simp)\n\n@[simp] lemma of_is_compl_smul\n  {R : Type*} [comm_ring R] {E : Type*} [add_comm_group E] [module R E]\n  {F : Type*} [add_comm_group F] [module R F] {p q : submodule R E}\n  (h : is_compl p q) {\u03c6 : p \u2192\u2097[R] F} {\u03c8 : q \u2192\u2097[R] F} (c : R) :\n  of_is_compl h (c \u2022 \u03c6) (c \u2022 \u03c8) = c \u2022 of_is_compl h \u03c6 \u03c8 :=\nof_is_compl_eq _ (by simp) (by simp)\n\nsection\n\nvariables {R\u2081 : Type*} [comm_ring R\u2081] [module R\u2081 E] [module R\u2081 F]\n\n/-- The linear map from `(p \u2192\u2097[R\u2081] F) \u00d7 (q \u2192\u2097[R\u2081] F)` to `E \u2192\u2097[R\u2081] F`. -/\ndef of_is_compl_prod {p q : submodule R\u2081 E} (h : is_compl p q) :\n  ((p \u2192\u2097[R\u2081] F) \u00d7 (q \u2192\u2097[R\u2081] F)) \u2192\u2097[R\u2081] (E \u2192\u2097[R\u2081] F) :=\n{ to_fun := \u03bb \u03c6, of_is_compl h \u03c6.1 \u03c6.2,\n  map_add' := by { intros \u03c6 \u03c8, rw [prod.snd_add, prod.fst_add, of_is_compl_add] },\n  map_smul' := by { intros c \u03c6, simp [prod.smul_snd, prod.smul_fst, of_is_compl_smul] } }\n\n@[simp] lemma of_is_compl_prod_apply {p q : submodule R\u2081 E} (h : is_compl p q)\n  (\u03c6 : (p \u2192\u2097[R\u2081] F) \u00d7 (q \u2192\u2097[R\u2081] F)) : of_is_compl_prod h \u03c6 = of_is_compl h \u03c6.1 \u03c6.2 := rfl\n\n/-- The natural linear equivalence between `(p \u2192\u2097[R\u2081] F) \u00d7 (q \u2192\u2097[R\u2081] F)` and `E \u2192\u2097[R\u2081] F`. -/\ndef of_is_compl_prod_equiv {p q : submodule R\u2081 E} (h : is_compl p q) :\n  ((p \u2192\u2097[R\u2081] F) \u00d7 (q \u2192\u2097[R\u2081] F)) \u2243\u2097[R\u2081] (E \u2192\u2097[R\u2081] F) :=\n{ inv_fun := \u03bb \u03c6, \u27e8\u03c6.dom_restrict p, \u03c6.dom_restrict q\u27e9,\n  left_inv :=\n    begin\n      intros \u03c6, ext,\n      { exact of_is_compl_left_apply h x },\n      { exact of_is_compl_right_apply h x }\n    end,\n  right_inv :=\n    begin\n      intro \u03c6, ext,\n      obtain \u27e8a, b, hab, _\u27e9 := exists_unique_add_of_is_compl h x,\n      rw [\u2190 hab], simp,\n    end, .. of_is_compl_prod h }\n\nend\n\n@[simp] lemma linear_proj_of_is_compl_of_proj (f : E \u2192\u2097[R] p) (hf : \u2200 x : p, f x = x) :\n  p.linear_proj_of_is_compl f.ker (is_compl_of_proj hf) = f :=\nbegin\n  ext x,\n  have : x \u2208 p \u2294 f.ker,\n  { simp only [(is_compl_of_proj hf).sup_eq_top, mem_top] },\n  rcases mem_sup'.1 this with \u27e8x, y, rfl\u27e9,\n  simp [hf]\nend\n\n/-- If `f : E \u2192\u2097[R] F` and `g : E \u2192\u2097[R] G` are two surjective linear maps and\ntheir kernels are complement of each other, then `x \u21a6 (f x, g x)` defines\na linear equivalence `E \u2243\u2097[R] F \u00d7 G`. -/\ndef equiv_prod_of_surjective_of_is_compl (f : E \u2192\u2097[R] F) (g : E \u2192\u2097[R] G) (hf : f.range = \u22a4)\n  (hg : g.range = \u22a4) (hfg : is_compl f.ker g.ker) :\n  E \u2243\u2097[R] F \u00d7 G :=\nlinear_equiv.of_bijective (f.prod g) (by simp [\u2190 ker_eq_bot, hfg.inf_eq_bot])\n  (by simp [\u2190 range_eq_top, range_prod_eq hfg.sup_eq_top, *])\n\n@[simp] lemma coe_equiv_prod_of_surjective_of_is_compl {f : E \u2192\u2097[R] F} {g : E \u2192\u2097[R] G}\n  (hf : f.range = \u22a4) (hg : g.range = \u22a4) (hfg : is_compl f.ker g.ker) :\n  (equiv_prod_of_surjective_of_is_compl f g hf hg hfg : E \u2192\u2097[R] F \u00d7 G) = f.prod g :=\nrfl\n\n@[simp] lemma equiv_prod_of_surjective_of_is_compl_apply {f : E \u2192\u2097[R] F} {g : E \u2192\u2097[R] G}\n  (hf : f.range = \u22a4) (hg : g.range = \u22a4) (hfg : is_compl f.ker g.ker) (x : E):\n  equiv_prod_of_surjective_of_is_compl f g hf hg hfg x = (f x, g x) :=\nrfl\n\nend linear_map\n\nnamespace submodule\n\nopen linear_map\n\n/-- Equivalence between submodules `q` such that `is_compl p q` and linear maps `f : E \u2192\u2097[R] p`\nsuch that `\u2200 x : p, f x = x`. -/\ndef is_compl_equiv_proj :\n  {q // is_compl p q} \u2243 {f : E \u2192\u2097[R] p // \u2200 x : p, f x = x} :=\n{ to_fun := \u03bb q, \u27e8linear_proj_of_is_compl p q q.2, linear_proj_of_is_compl_apply_left q.2\u27e9,\n  inv_fun := \u03bb f, \u27e8(f : E \u2192\u2097[R] p).ker, is_compl_of_proj f.2\u27e9,\n  left_inv := \u03bb \u27e8q, hq\u27e9, by simp only [linear_proj_of_is_compl_ker, subtype.coe_mk],\n  right_inv := \u03bb \u27e8f, hf\u27e9, subtype.eq $ f.linear_proj_of_is_compl_of_proj hf }\n\n@[simp] lemma coe_is_compl_equiv_proj_apply (q : {q // is_compl p q}) :\n  (p.is_compl_equiv_proj q : E \u2192\u2097[R] p) = linear_proj_of_is_compl p q q.2 := rfl\n\n@[simp] lemma coe_is_compl_equiv_proj_symm_apply (f : {f : E \u2192\u2097[R] p // \u2200 x : p, f x = x}) :\n  (p.is_compl_equiv_proj.symm f : submodule R E) = (f : E \u2192\u2097[R] p).ker := rfl\n\nend submodule\n\nnamespace linear_map\n\nopen submodule\n\n/--\nA linear endomorphism of a module `E` is a projection onto a submodule `p` if it sends every element\nof `E` to `p` and fixes every element of `p`.\nThe definition allow more generally any `fun_like` type and not just linear maps, so that it can be\nused for example with `continuous_linear_map` or `matrix`.\n-/\nstructure is_proj {F : Type*} [fun_like F M (\u03bb _, M)] (f : F) : Prop :=\n(map_mem : \u2200 x, f x \u2208 m)\n(map_id : \u2200 x \u2208 m, f x = x)\n\nlemma is_proj_iff_idempotent (f : M \u2192\u2097[S] M) : (\u2203 p : submodule S M, is_proj p f) \u2194 f \u2218\u2097 f = f :=\nbegin\n  split,\n  { intro h, obtain \u27e8p, hp\u27e9 := h, ext, rw comp_apply, exact hp.map_id (f x) (hp.map_mem x), },\n  { intro h, use f.range, split,\n    { intro x, exact mem_range_self f x, },\n    { intros x hx, obtain \u27e8y, hy\u27e9 := mem_range.1 hx, rw [\u2190hy, \u2190comp_apply, h], }, },\nend\n\nnamespace is_proj\n\nvariables {p m}\n\n/--\nRestriction of the codomain of a projection of onto a subspace `p` to `p` instead of the whole\nspace.\n-/\ndef cod_restrict {f : M \u2192\u2097[S] M} (h : is_proj m f) : M \u2192\u2097[S] m :=\nf.cod_restrict m h.map_mem\n\n@[simp]\nlemma cod_restrict_apply {f : M \u2192\u2097[S] M} (h : is_proj m f) (x : M) :\n  \u2191(h.cod_restrict x) = f x := f.cod_restrict_apply m x\n\n@[simp]\nlemma cod_restrict_apply_cod {f : M \u2192\u2097[S] M} (h : is_proj m f) (x : m) :\n  h.cod_restrict x = x :=\nby {ext, rw [cod_restrict_apply], exact h.map_id x x.2}\n\nlemma cod_restrict_ker {f : M \u2192\u2097[S] M} (h : is_proj m f) :\n  h.cod_restrict.ker = f.ker := f.ker_cod_restrict m _\n\nlemma is_compl {f : E \u2192\u2097[R] E} (h : is_proj p f) : is_compl p f.ker :=\nby { rw \u2190cod_restrict_ker, exact is_compl_of_proj h.cod_restrict_apply_cod, }\n\nlemma eq_conj_prod_map' {f : E \u2192\u2097[R] E} (h : is_proj p f) :\n  f = (p.prod_equiv_of_is_compl f.ker h.is_compl).to_linear_map \u2218\u2097 prod_map id 0 \u2218\u2097\n    (p.prod_equiv_of_is_compl f.ker h.is_compl).symm.to_linear_map :=\nbegin\n  refine (linear_map.cancel_right\n    (p.prod_equiv_of_is_compl f.ker h.is_compl).surjective).1 _,\n  ext,\n  { simp only [coe_comp, linear_equiv.coe_to_linear_map, coe_inl, function.comp_app,\n  linear_equiv.of_top_apply, linear_equiv.of_injective_apply, coprod_apply, submodule.coe_subtype,\n  coe_zero, add_zero, prod_equiv_of_is_compl_symm_apply_left, prod_map_apply, id_coe, id.def,\n  zero_apply, coe_prod_equiv_of_is_compl', h.map_id x x.2], },\n  {simp only [coe_comp, linear_equiv.coe_to_linear_map, coe_inr, function.comp_app,\n  linear_equiv.of_top_apply, linear_equiv.of_injective_apply, coprod_apply, submodule.coe_subtype,\n  coe_zero, zero_add, map_coe_ker, prod_equiv_of_is_compl_symm_apply_right, prod_map_apply, id_coe,\n  id.def, zero_apply, coe_prod_equiv_of_is_compl'], }\nend\n\nend is_proj\n\nend linear_map\n\nend ring\n\nsection comm_ring\n\nnamespace linear_map\n\nvariables {R : Type*} [comm_ring R] {E : Type*} [add_comm_group E] [module R E]  {p : submodule R E}\n\nlemma is_proj.eq_conj_prod_map {f : E \u2192\u2097[R] E} (h : is_proj p f) :\n  f = (p.prod_equiv_of_is_compl f.ker h.is_compl).conj (prod_map id 0) :=\nby {rw linear_equiv.conj_apply, exact h.eq_conj_prod_map'}\n\nend linear_map\n\nend comm_ring\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/projection.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7052471753954976}}
{"text": "theorem add_le_add_right {a b : mynat} : a \u2264 b \u2192 \u2200 t, (a + t) \u2264 (b + t) :=\nbegin\nintro h,\nintro t,\ncases h with c hc,\nuse c,\nrw hc,\napply add_right_comm,\nend\n", "meta": {"author": "chanha-park", "repo": "naturalNumberGame", "sha": "4e0d7100ce4575e1add92feefa38b1250431b879", "save_path": "github-repos/lean/chanha-park-naturalNumberGame", "path": "github-repos/lean/chanha-park-naturalNumberGame/naturalNumberGame-4e0d7100ce4575e1add92feefa38b1250431b879/Inequality/11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7052152939630708}}
{"text": "/-\nCopyright (c) 2020 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.group_theory.submonoid.default\nimport Mathlib.algebra.group.conj\nimport Mathlib.order.modular_lattice\nimport Mathlib.PostPort\n\nuniverses u_3 l u_1 u_2 u_4 u_5 \n\nnamespace Mathlib\n\n/-!\n# Subgroups\n\nThis file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled\nform (unbundled subgroups are in `deprecated/subgroups.lean`).\n\nWe prove subgroups of a group form a complete lattice, and results about images and preimages of\nsubgroups under group homomorphisms. The bundled subgroups use bundled monoid homomorphisms.\n\nThere are also theorems about the subgroups generated by an element or a subset of a group,\ndefined both inductively and as the infimum of the set of subgroups containing a given\nelement/subset.\n\nSpecial thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.\n\n## Main definitions\n\nNotation used here:\n\n- `G N` are `group`s\n\n- `A` is an `add_group`\n\n- `H K` are `subgroup`s of `G` or `add_subgroup`s of `A`\n\n- `x` is an element of type `G` or type `A`\n\n- `f g : N \u2192* G` are group homomorphisms\n\n- `s k` are sets of elements of type `G`\n\nDefinitions in the file:\n\n* `subgroup G` : the type of subgroups of a group `G`\n\n* `add_subgroup A` : the type of subgroups of an additive group `A`\n\n* `complete_lattice (subgroup G)` : the subgroups of `G` form a complete lattice\n\n* `subgroup.closure k` : the minimal subgroup that includes the set `k`\n\n* `subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G`\n\n* `subgroup.gi` : `closure` forms a Galois insertion with the coercion to set\n\n* `subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a\n  subgroup\n\n* `subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a\n  subgroup\n\n* `subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H \u00d7 K`\n  is a subgroup of `G \u00d7 N`\n\n* `monoid_hom.range f` : the range of the group homomorphism `f` is a subgroup\n\n* `monoid_hom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G`\n  such that `f x = 1`\n\n* `monoid_hom.eq_locus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that\n  `f x = g x` form a subgroup of `G`\n\n## Implementation notes\n\nSubgroup inclusion is denoted `\u2264` rather than `\u2286`, although `\u2208` is defined as\nmembership of a subgroup's underlying set.\n\n## Tags\nsubgroup, subgroups\n-/\n\n/-- A subgroup of a group `G` is a subset containing 1, closed under multiplication\nand closed under multiplicative inverse. -/\nstructure subgroup (G : Type u_3) [group G] \nextends submonoid G\nwhere\n  inv_mem' : \u2200 {x : G}, x \u2208 carrier \u2192 x\u207b\u00b9 \u2208 carrier\n\n/-- An additive subgroup of an additive group `G` is a subset containing 0, closed\nunder addition and additive inverse. -/\nstructure add_subgroup (G : Type u_3) [add_group G] \nextends add_submonoid G\nwhere\n  neg_mem' : \u2200 {x : G}, x \u2208 carrier \u2192 -x \u2208 carrier\n\n/-- Reinterpret a `subgroup` as a `submonoid`. -/\n/-- Reinterpret an `add_subgroup` as an `add_submonoid`. -/\n/-- Map from subgroups of group `G` to `add_subgroup`s of `additive G`. -/\ndef subgroup.to_add_subgroup {G : Type u_1} [group G] (H : subgroup G) : add_subgroup (additive G) :=\n  add_subgroup.mk (add_submonoid.carrier (submonoid.to_add_submonoid (subgroup.to_submonoid H))) sorry sorry\n    (subgroup.inv_mem' H)\n\n/-- Map from `add_subgroup`s of `additive G` to subgroups of `G`. -/\ndef subgroup.of_add_subgroup {G : Type u_1} [group G] (H : add_subgroup (additive G)) : subgroup G :=\n  subgroup.mk (submonoid.carrier (submonoid.of_add_submonoid (add_subgroup.to_add_submonoid H))) sorry sorry sorry\n\n/-- Map from `add_subgroup`s of `add_group G` to subgroups of `multiplicative G`. -/\ndef add_subgroup.to_subgroup {G : Type u_1} [add_group G] (H : add_subgroup G) : subgroup (multiplicative G) :=\n  subgroup.mk (submonoid.carrier (add_submonoid.to_submonoid (add_subgroup.to_add_submonoid H))) sorry sorry\n    (add_subgroup.neg_mem' H)\n\n/-- Map from subgroups of `multiplicative G` to `add_subgroup`s of `add_group G`. -/\ndef add_subgroup.of_subgroup {G : Type u_1} [add_group G] (H : subgroup (multiplicative G)) : add_subgroup G :=\n  add_subgroup.mk (add_submonoid.carrier (add_submonoid.of_submonoid (subgroup.to_submonoid H))) sorry sorry sorry\n\n/-- Subgroups of group `G` are isomorphic to additive subgroups of `additive G`. -/\ndef subgroup.add_subgroup_equiv (G : Type u_1) [group G] : subgroup G \u2243 add_subgroup (additive G) :=\n  equiv.mk subgroup.to_add_subgroup subgroup.of_add_subgroup sorry sorry\n\nnamespace subgroup\n\n\nprotected instance set.has_coe {G : Type u_1} [group G] : has_coe (subgroup G) (set G) :=\n  has_coe.mk carrier\n\n@[simp] theorem coe_to_submonoid {G : Type u_1} [group G] (K : subgroup G) : \u2191(to_submonoid K) = \u2191K :=\n  rfl\n\nprotected instance has_mem {G : Type u_1} [group G] : has_mem G (subgroup G) :=\n  has_mem.mk fun (m : G) (K : subgroup G) => m \u2208 \u2191K\n\nprotected instance Mathlib.add_subgroup.has_coe_to_sort {G : Type u_1} [add_group G] : has_coe_to_sort (add_subgroup G) :=\n  has_coe_to_sort.mk (has_coe_to_sort.S (add_subgroup G)) fun (G_1 : add_subgroup G) => \u21a5G_1\n\n@[simp] theorem Mathlib.add_subgroup.mem_coe {G : Type u_1} [add_group G] {K : add_subgroup G} {g : G} : g \u2208 \u2191K \u2194 g \u2208 K :=\n  iff.rfl\n\n@[simp] theorem Mathlib.add_subgroup.coe_coe {G : Type u_1} [add_group G] (K : add_subgroup G) : \u21a5\u2191K = \u21a5K :=\n  rfl\n\n-- note that `to_additive` transfers the `simp` attribute over but not the `norm_cast` attribute\n\nprotected instance Mathlib.add_subgroup.fintype {G : Type u_1} [add_group G] (K : add_subgroup G) [d : decidable_pred (add_subgroup.carrier K)] [fintype G] : fintype \u21a5K :=\n  (fun (this : fintype (Subtype fun (g : G) => g \u2208 add_subgroup.carrier K)) => this) infer_instance\n\nend subgroup\n\n\nprotected theorem add_subgroup.exists {G : Type u_1} [add_group G] {K : add_subgroup G} {p : \u21a5K \u2192 Prop} : (\u2203 (x : \u21a5K), p x) \u2194 \u2203 (x : G), \u2203 (H : x \u2208 K), p { val := x, property := H } :=\n  set_coe.exists\n\nprotected theorem subgroup.forall {G : Type u_1} [group G] {K : subgroup G} {p : \u21a5K \u2192 Prop} : (\u2200 (x : \u21a5K), p x) \u2194 \u2200 (x : G) (H : x \u2208 K), p { val := x, property := H } :=\n  set_coe.forall\n\nnamespace subgroup\n\n\n/-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional\nequalities.-/\nprotected def Mathlib.add_subgroup.copy {G : Type u_1} [add_group G] (K : add_subgroup G) (s : set G) (hs : s = \u2191K) : add_subgroup G :=\n  add_subgroup.mk s sorry sorry sorry\n\n/- Two subgroups are equal if the underlying set are the same. -/\n\ntheorem Mathlib.add_subgroup.ext' {G : Type u_1} [add_group G] {H : add_subgroup G} {K : add_subgroup G} (h : \u2191H = \u2191K) : H = K := sorry\n\n/- Two subgroups are equal if and only if the underlying subsets are equal. -/\n\nprotected theorem Mathlib.add_subgroup.ext'_iff {G : Type u_1} [add_group G] {H : add_subgroup G} {K : add_subgroup G} : H = K \u2194 \u2191H = \u2191K :=\n  { mp := fun (h : H = K) => h \u25b8 rfl, mpr := add_subgroup.ext' }\n\n/-- Two subgroups are equal if they have the same elements. -/\ntheorem ext {G : Type u_1} [group G] {H : subgroup G} {K : subgroup G} (h : \u2200 (x : G), x \u2208 H \u2194 x \u2208 K) : H = K :=\n  ext' (set.ext h)\n\n/-- A subgroup contains the group's 1. -/\ntheorem one_mem {G : Type u_1} [group G] (H : subgroup G) : 1 \u2208 H :=\n  one_mem' H\n\n/-- A subgroup is closed under multiplication. -/\ntheorem Mathlib.add_subgroup.add_mem {G : Type u_1} [add_group G] (H : add_subgroup G) {x : G} {y : G} : x \u2208 H \u2192 y \u2208 H \u2192 x + y \u2208 H :=\n  fun (hx : x \u2208 H) (hy : y \u2208 H) => add_subgroup.add_mem' H hx hy\n\n/-- A subgroup is closed under inverse. -/\ntheorem inv_mem {G : Type u_1} [group G] (H : subgroup G) {x : G} : x \u2208 H \u2192 x\u207b\u00b9 \u2208 H :=\n  fun (hx : x \u2208 H) => inv_mem' H hx\n\n/-- A subgroup is closed under division. -/\ntheorem Mathlib.add_subgroup.sub_mem {G : Type u_1} [add_group G] (H : add_subgroup G) {x : G} {y : G} (hx : x \u2208 H) (hy : y \u2208 H) : x - y \u2208 H := sorry\n\n@[simp] theorem Mathlib.add_subgroup.neg_mem_iff {G : Type u_1} [add_group G] (H : add_subgroup G) {x : G} : -x \u2208 H \u2194 x \u2208 H :=\n  { mp := fun (h : -x \u2208 H) => neg_neg x \u25b8 add_subgroup.neg_mem H h, mpr := add_subgroup.neg_mem H }\n\ntheorem Mathlib.add_subgroup.add_mem_cancel_right {G : Type u_1} [add_group G] (H : add_subgroup G) {x : G} {y : G} (h : x \u2208 H) : y + x \u2208 H \u2194 y \u2208 H := sorry\n\ntheorem Mathlib.add_subgroup.add_mem_cancel_left {G : Type u_1} [add_group G] (H : add_subgroup G) {x : G} {y : G} (h : x \u2208 H) : x + y \u2208 H \u2194 y \u2208 H := sorry\n\n/-- Product of a list of elements in a subgroup is in the subgroup. -/\ntheorem list_prod_mem {G : Type u_1} [group G] (K : subgroup G) {l : List G} : (\u2200 (x : G), x \u2208 l \u2192 x \u2208 K) \u2192 list.prod l \u2208 K :=\n  submonoid.list_prod_mem (to_submonoid K)\n\n/-- Product of a multiset of elements in a subgroup of a `comm_group` is in the subgroup. -/\ntheorem multiset_prod_mem {G : Type u_1} [comm_group G] (K : subgroup G) (g : multiset G) : (\u2200 (a : G), a \u2208 g \u2192 a \u2208 K) \u2192 multiset.prod g \u2208 K :=\n  submonoid.multiset_prod_mem (to_submonoid K) g\n\n/-- Product of elements of a subgroup of a `comm_group` indexed by a `finset` is in the\n    subgroup. -/\ntheorem Mathlib.add_subgroup.sum_mem {G : Type u_1} [add_comm_group G] (K : add_subgroup G) {\u03b9 : Type u_2} {t : finset \u03b9} {f : \u03b9 \u2192 G} (h : \u2200 (c : \u03b9), c \u2208 t \u2192 f c \u2208 K) : (finset.sum t fun (c : \u03b9) => f c) \u2208 K :=\n  add_submonoid.sum_mem (add_subgroup.to_add_submonoid K) h\n\ntheorem pow_mem {G : Type u_1} [group G] (K : subgroup G) {x : G} (hx : x \u2208 K) (n : \u2115) : x ^ n \u2208 K :=\n  submonoid.pow_mem (to_submonoid K) hx\n\ntheorem gpow_mem {G : Type u_1} [group G] (K : subgroup G) {x : G} (hx : x \u2208 K) (n : \u2124) : x ^ n \u2208 K :=\n  int.cases_on n (fun (n : \u2115) => idRhs (x ^ n \u2208 K) (pow_mem K hx n))\n    fun (n : \u2115) => idRhs (x ^ Nat.succ n\u207b\u00b9 \u2208 K) (inv_mem K (pow_mem K hx (Nat.succ n)))\n\n/-- Construct a subgroup from a nonempty set that is closed under division. -/\ndef Mathlib.add_subgroup.of_sub {G : Type u_1} [add_group G] (s : set G) (hsn : set.nonempty s) (hs : \u2200 (x y : G), x \u2208 s \u2192 y \u2208 s \u2192 x + -y \u2208 s) : add_subgroup G :=\n  (fun (one_mem : 0 \u2208 s) => (fun (inv_mem : \u2200 (x : G), x \u2208 s \u2192 -x \u2208 s) => add_subgroup.mk s one_mem sorry inv_mem) sorry)\n    sorry\n\n/-- A subgroup of a group inherits a multiplication. -/\nprotected instance Mathlib.add_subgroup.has_add {G : Type u_1} [add_group G] (H : add_subgroup G) : Add \u21a5H :=\n  add_submonoid.has_add (add_subgroup.to_add_submonoid H)\n\n/-- A subgroup of a group inherits a 1. -/\nprotected instance Mathlib.add_subgroup.has_zero {G : Type u_1} [add_group G] (H : add_subgroup G) : HasZero \u21a5H :=\n  add_submonoid.has_zero (add_subgroup.to_add_submonoid H)\n\n/-- A subgroup of a group inherits an inverse. -/\nprotected instance Mathlib.add_subgroup.has_neg {G : Type u_1} [add_group G] (H : add_subgroup G) : Neg \u21a5H :=\n  { neg := fun (a : \u21a5H) => { val := -\u2191a, property := sorry } }\n\n/-- A subgroup of a group inherits a division -/\nprotected instance has_div {G : Type u_1} [group G] (H : subgroup G) : Div \u21a5H :=\n  { div := fun (a b : \u21a5H) => { val := \u2191a / \u2191b, property := sorry } }\n\n@[simp] theorem Mathlib.add_subgroup.coe_add {G : Type u_1} [add_group G] (H : add_subgroup G) (x : \u21a5H) (y : \u21a5H) : \u2191(x + y) = \u2191x + \u2191y :=\n  rfl\n\n@[simp] theorem Mathlib.add_subgroup.coe_zero {G : Type u_1} [add_group G] (H : add_subgroup G) : \u21910 = 0 :=\n  rfl\n\n@[simp] theorem coe_inv {G : Type u_1} [group G] (H : subgroup G) (x : \u21a5H) : \u2191(x\u207b\u00b9) = (\u2191x\u207b\u00b9) :=\n  rfl\n\n@[simp] theorem Mathlib.add_subgroup.coe_mk {G : Type u_1} [add_group G] (H : add_subgroup G) (x : G) (hx : x \u2208 H) : \u2191{ val := x, property := hx } = x :=\n  rfl\n\n/-- A subgroup of a group inherits a group structure. -/\nprotected instance Mathlib.add_subgroup.to_add_group {G : Type u_1} [add_group G] (H : add_subgroup G) : add_group \u21a5H :=\n  add_group.mk add_monoid.add sorry add_monoid.zero sorry sorry Neg.neg Sub.sub sorry\n\n/-- A subgroup of a `comm_group` is a `comm_group`. -/\nprotected instance Mathlib.add_subgroup.to_add_comm_group {G : Type u_1} [add_comm_group G] (H : add_subgroup G) : add_comm_group \u21a5H :=\n  add_comm_group.mk add_group.add sorry add_group.zero sorry sorry add_group.neg add_group.sub sorry sorry\n\n/-- The natural group hom from a subgroup of group `G` to `G`. -/\ndef subtype {G : Type u_1} [group G] (H : subgroup G) : \u21a5H \u2192* G :=\n  monoid_hom.mk coe sorry sorry\n\n@[simp] theorem coe_subtype {G : Type u_1} [group G] (H : subgroup G) : \u21d1(subtype H) = coe :=\n  rfl\n\n@[simp] theorem coe_pow {G : Type u_1} [group G] (H : subgroup G) (x : \u21a5H) (n : \u2115) : \u2191(x ^ n) = \u2191x ^ n :=\n  coe_subtype H \u25b8 monoid_hom.map_pow (subtype H) x n\n\n@[simp] theorem coe_gpow {G : Type u_1} [group G] (H : subgroup G) (x : \u21a5H) (n : \u2124) : \u2191(x ^ n) = \u2191x ^ n :=\n  coe_subtype H \u25b8 monoid_hom.map_gpow (subtype H) x n\n\nprotected instance Mathlib.add_subgroup.has_le {G : Type u_1} [add_group G] : HasLessEq (add_subgroup G) :=\n  { LessEq := fun (H K : add_subgroup G) => \u2200 {x : G}, x \u2208 H \u2192 x \u2208 K }\n\ntheorem Mathlib.add_subgroup.le_def {G : Type u_1} [add_group G] {H : add_subgroup G} {K : add_subgroup G} : H \u2264 K \u2194 \u2200 {x : G}, x \u2208 H \u2192 x \u2208 K :=\n  iff.rfl\n\n@[simp] theorem Mathlib.add_subgroup.coe_subset_coe {G : Type u_1} [add_group G] {H : add_subgroup G} {K : add_subgroup G} : \u2191H \u2286 \u2191K \u2194 H \u2264 K :=\n  iff.rfl\n\nprotected instance partial_order {G : Type u_1} [group G] : partial_order (subgroup G) :=\n  partial_order.mk LessEq partial_order.lt sorry sorry sorry\n\n/-- The subgroup `G` of the group `G`. -/\nprotected instance has_top {G : Type u_1} [group G] : has_top (subgroup G) :=\n  has_top.mk (mk (submonoid.carrier \u22a4) sorry sorry sorry)\n\n/-- The trivial subgroup `{1}` of an group `G`. -/\nprotected instance Mathlib.add_subgroup.has_bot {G : Type u_1} [add_group G] : has_bot (add_subgroup G) :=\n  has_bot.mk (add_subgroup.mk (add_submonoid.carrier \u22a5) sorry sorry sorry)\n\nprotected instance Mathlib.add_subgroup.inhabited {G : Type u_1} [add_group G] : Inhabited (add_subgroup G) :=\n  { default := \u22a5 }\n\n@[simp] theorem mem_bot {G : Type u_1} [group G] {x : G} : x \u2208 \u22a5 \u2194 x = 1 :=\n  iff.rfl\n\n@[simp] theorem Mathlib.add_subgroup.mem_top {G : Type u_1} [add_group G] (x : G) : x \u2208 \u22a4 :=\n  set.mem_univ x\n\n@[simp] theorem Mathlib.add_subgroup.coe_top {G : Type u_1} [add_group G] : \u2191\u22a4 = set.univ :=\n  rfl\n\n@[simp] theorem coe_bot {G : Type u_1} [group G] : \u2191\u22a5 = singleton 1 :=\n  rfl\n\ntheorem Mathlib.add_subgroup.eq_bot_iff_forall {G : Type u_1} [add_group G] (H : add_subgroup G) : H = \u22a5 \u2194 \u2200 (x : G), x \u2208 H \u2192 x = 0 := sorry\n\ntheorem Mathlib.add_subgroup.eq_top_of_card_eq {G : Type u_1} [add_group G] (H : add_subgroup G) [fintype \u21a5H] [fintype G] (h : fintype.card \u21a5H = fintype.card G) : H = \u22a4 := sorry\n\ntheorem nontrivial_iff_exists_ne_one {G : Type u_1} [group G] (H : subgroup G) : nontrivial \u21a5H \u2194 \u2203 (x : G), \u2203 (H : x \u2208 H), x \u2260 1 := sorry\n\n/-- A subgroup is either the trivial subgroup or nontrivial. -/\ntheorem Mathlib.add_subgroup.bot_or_nontrivial {G : Type u_1} [add_group G] (H : add_subgroup G) : H = \u22a5 \u2228 nontrivial \u21a5H := sorry\n\n/-- A subgroup is either the trivial subgroup or contains a nonzero element. -/\ntheorem bot_or_exists_ne_one {G : Type u_1} [group G] (H : subgroup G) : H = \u22a5 \u2228 \u2203 (x : G), \u2203 (H : x \u2208 H), x \u2260 1 := sorry\n\n/-- The inf of two subgroups is their intersection. -/\nprotected instance has_inf {G : Type u_1} [group G] : has_inf (subgroup G) :=\n  has_inf.mk fun (H\u2081 H\u2082 : subgroup G) => mk (submonoid.carrier (to_submonoid H\u2081 \u2293 to_submonoid H\u2082)) sorry sorry sorry\n\n@[simp] theorem coe_inf {G : Type u_1} [group G] (p : subgroup G) (p' : subgroup G) : \u2191(p \u2293 p') = \u2191p \u2229 \u2191p' :=\n  rfl\n\n@[simp] theorem Mathlib.add_subgroup.mem_inf {G : Type u_1} [add_group G] {p : add_subgroup G} {p' : add_subgroup G} {x : G} : x \u2208 p \u2293 p' \u2194 x \u2208 p \u2227 x \u2208 p' :=\n  iff.rfl\n\nprotected instance Mathlib.add_subgroup.has_Inf {G : Type u_1} [add_group G] : has_Inf (add_subgroup G) :=\n  has_Inf.mk\n    fun (s : set (add_subgroup G)) =>\n      add_subgroup.mk\n        (add_submonoid.carrier\n          (add_submonoid.copy (infi fun (S : add_subgroup G) => infi fun (H : S \u2208 s) => add_subgroup.to_add_submonoid S)\n            (set.Inter fun (S : add_subgroup G) => set.Inter fun (H : S \u2208 s) => \u2191S) sorry))\n        sorry sorry sorry\n\n@[simp] theorem Mathlib.add_subgroup.coe_Inf {G : Type u_1} [add_group G] (H : set (add_subgroup G)) : \u2191(Inf H) = set.Inter fun (s : add_subgroup G) => set.Inter fun (H : s \u2208 H) => \u2191s :=\n  rfl\n\n@[simp] theorem mem_Inf {G : Type u_1} [group G] {S : set (subgroup G)} {x : G} : x \u2208 Inf S \u2194 \u2200 (p : subgroup G), p \u2208 S \u2192 x \u2208 p :=\n  set.mem_bInter_iff\n\ntheorem Mathlib.add_subgroup.mem_infi {G : Type u_1} [add_group G] {\u03b9 : Sort u_2} {S : \u03b9 \u2192 add_subgroup G} {x : G} : (x \u2208 infi fun (i : \u03b9) => S i) \u2194 \u2200 (i : \u03b9), x \u2208 S i := sorry\n\n@[simp] theorem Mathlib.add_subgroup.coe_infi {G : Type u_1} [add_group G] {\u03b9 : Sort u_2} {S : \u03b9 \u2192 add_subgroup G} : \u2191(infi fun (i : \u03b9) => S i) = set.Inter fun (i : \u03b9) => \u2191(S i) := sorry\n\n/-- Subgroups of a group form a complete lattice. -/\nprotected instance Mathlib.add_subgroup.complete_lattice {G : Type u_1} [add_group G] : complete_lattice (add_subgroup G) :=\n  complete_lattice.mk complete_lattice.sup complete_lattice.le complete_lattice.lt sorry sorry sorry sorry sorry sorry\n    has_inf.inf sorry sorry sorry \u22a4 sorry \u22a5 sorry complete_lattice.Sup complete_lattice.Inf sorry sorry sorry sorry\n\ntheorem Mathlib.add_subgroup.mem_sup_left {G : Type u_1} [add_group G] {S : add_subgroup G} {T : add_subgroup G} {x : G} : x \u2208 S \u2192 x \u2208 S \u2294 T :=\n  (fun (this : S \u2264 S \u2294 T) => this) le_sup_left\n\ntheorem Mathlib.add_subgroup.mem_sup_right {G : Type u_1} [add_group G] {S : add_subgroup G} {T : add_subgroup G} {x : G} : x \u2208 T \u2192 x \u2208 S \u2294 T :=\n  (fun (this : T \u2264 S \u2294 T) => this) le_sup_right\n\ntheorem Mathlib.add_subgroup.mem_supr_of_mem {G : Type u_1} [add_group G] {\u03b9 : Type u_2} {S : \u03b9 \u2192 add_subgroup G} (i : \u03b9) {x : G} : x \u2208 S i \u2192 x \u2208 supr S :=\n  (fun (this : S i \u2264 supr S) => this) (le_supr S i)\n\ntheorem Mathlib.add_subgroup.mem_Sup_of_mem {G : Type u_1} [add_group G] {S : set (add_subgroup G)} {s : add_subgroup G} (hs : s \u2208 S) {x : G} : x \u2208 s \u2192 x \u2208 Sup S :=\n  (fun (this : s \u2264 Sup S) => this) (le_Sup hs)\n\ntheorem subsingleton_iff {G : Type u_1} [group G] : subsingleton G \u2194 subsingleton (subgroup G) := sorry\n\ntheorem nontrivial_iff {G : Type u_1} [group G] : nontrivial G \u2194 nontrivial (subgroup G) :=\n  iff.mp not_iff_not\n    (iff.trans (iff.trans not_nontrivial_iff_subsingleton subsingleton_iff) (iff.symm not_nontrivial_iff_subsingleton))\n\nprotected instance subsingleton {G : Type u_1} [group G] [subsingleton G] : subsingleton (subgroup G) :=\n  iff.mp subsingleton_iff _inst_3\n\nprotected instance Mathlib.add_subgroup.nontrivial {G : Type u_1} [add_group G] [nontrivial G] : nontrivial (add_subgroup G) :=\n  iff.mp add_subgroup.nontrivial_iff _inst_3\n\n/-- The `subgroup` generated by a set. -/\ndef Mathlib.add_subgroup.closure {G : Type u_1} [add_group G] (k : set G) : add_subgroup G :=\n  Inf (set_of fun (K : add_subgroup G) => k \u2286 \u2191K)\n\ntheorem Mathlib.add_subgroup.mem_closure {G : Type u_1} [add_group G] {k : set G} {x : G} : x \u2208 add_subgroup.closure k \u2194 \u2200 (K : add_subgroup G), k \u2286 \u2191K \u2192 x \u2208 K :=\n  add_subgroup.mem_Inf\n\n/-- The subgroup generated by a set includes the set. -/\n@[simp] theorem subset_closure {G : Type u_1} [group G] {k : set G} : k \u2286 \u2191(closure k) :=\n  fun (x : G) (hx : x \u2208 k) => iff.mpr mem_closure fun (K : subgroup G) (hK : k \u2286 \u2191K) => hK hx\n\n/-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/\n@[simp] theorem closure_le {G : Type u_1} [group G] (K : subgroup G) {k : set G} : closure k \u2264 K \u2194 k \u2286 \u2191K :=\n  { mp := set.subset.trans subset_closure, mpr := fun (h : k \u2286 \u2191K) => Inf_le h }\n\ntheorem Mathlib.add_subgroup.closure_eq_of_le {G : Type u_1} [add_group G] (K : add_subgroup G) {k : set G} (h\u2081 : k \u2286 \u2191K) (h\u2082 : K \u2264 add_subgroup.closure k) : add_subgroup.closure k = K :=\n  le_antisymm (iff.mpr (add_subgroup.closure_le K) h\u2081) h\u2082\n\n/-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and\nis preserved under multiplication and inverse, then `p` holds for all elements of the closure\nof `k`. -/\ntheorem Mathlib.add_subgroup.closure_induction {G : Type u_1} [add_group G] {k : set G} {p : G \u2192 Prop} {x : G} (h : x \u2208 add_subgroup.closure k) (Hk : \u2200 (x : G), x \u2208 k \u2192 p x) (H1 : p 0) (Hmul : \u2200 (x y : G), p x \u2192 p y \u2192 p (x + y)) (Hinv : \u2200 (x : G), p x \u2192 p (-x)) : p x :=\n  iff.mpr (add_subgroup.closure_le (add_subgroup.mk p H1 Hmul Hinv)) Hk x h\n\n/-- An induction principle on elements of the subtype `subgroup.closure`.\nIf `p` holds for `1` and all elements of `k`, and is preserved under multiplication and inverse,\nthen `p` holds for all elements `x : closure k`.\n\nThe difference with `subgroup.closure_induction` is that this acts on the subtype.\n-/\ntheorem closure_induction' {G : Type u_1} [group G] (k : set G) {p : \u21a5(closure k) \u2192 Prop} (Hk : \u2200 (x : G) (h : x \u2208 k), p { val := x, property := subset_closure h }) (H1 : p 1) (Hmul : \u2200 (x y : \u21a5(closure k)), p x \u2192 p y \u2192 p (x * y)) (Hinv : \u2200 (x : \u21a5(closure k)), p x \u2192 p (x\u207b\u00b9)) (x : \u21a5(closure k)) : p x := sorry\n\n/-- `closure` forms a Galois insertion with the coercion to set. -/\nprotected def Mathlib.add_subgroup.gi (G : Type u_1) [add_group G] : galois_insertion add_subgroup.closure coe :=\n  galois_insertion.mk (fun (s : set G) (_x : \u2191(add_subgroup.closure s) \u2264 s) => add_subgroup.closure s) sorry sorry sorry\n\n/-- Subgroup closure of a set is monotone in its argument: if `h \u2286 k`,\nthen `closure h \u2264 closure k`. -/\ntheorem closure_mono {G : Type u_1} [group G] {h : set G} {k : set G} (h' : h \u2286 k) : closure h \u2264 closure k :=\n  galois_connection.monotone_l (galois_insertion.gc (subgroup.gi G)) h'\n\n/-- Closure of a subgroup `K` equals `K`. -/\n@[simp] theorem closure_eq {G : Type u_1} [group G] (K : subgroup G) : closure \u2191K = K :=\n  galois_insertion.l_u_eq (subgroup.gi G) K\n\n@[simp] theorem Mathlib.add_subgroup.closure_empty {G : Type u_1} [add_group G] : add_subgroup.closure \u2205 = \u22a5 :=\n  galois_connection.l_bot (galois_insertion.gc (add_subgroup.gi G))\n\n@[simp] theorem closure_univ {G : Type u_1} [group G] : closure set.univ = \u22a4 :=\n  coe_top \u25b8 closure_eq \u22a4\n\ntheorem closure_union {G : Type u_1} [group G] (s : set G) (t : set G) : closure (s \u222a t) = closure s \u2294 closure t :=\n  galois_connection.l_sup (galois_insertion.gc (subgroup.gi G))\n\ntheorem Mathlib.add_subgroup.closure_Union {G : Type u_1} [add_group G] {\u03b9 : Sort u_2} (s : \u03b9 \u2192 set G) : add_subgroup.closure (set.Union fun (i : \u03b9) => s i) = supr fun (i : \u03b9) => add_subgroup.closure (s i) :=\n  galois_connection.l_supr (galois_insertion.gc (add_subgroup.gi G))\n\ntheorem closure_eq_bot_iff (G : Type u_1) [group G] (S : set G) : closure S = \u22a5 \u2194 S \u2286 singleton 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (closure S = \u22a5 \u2194 S \u2286 singleton 1)) (Eq.symm (propext le_bot_iff)))) (closure_le \u22a5)\n\n/-- The subgroup generated by an element of a group equals the set of integer number powers of\n    the element. -/\ntheorem mem_closure_singleton {G : Type u_1} [group G] {x : G} {y : G} : y \u2208 closure (singleton x) \u2194 \u2203 (n : \u2124), x ^ n = y := sorry\n\ntheorem closure_singleton_one {G : Type u_1} [group G] : closure (singleton 1) = \u22a5 := sorry\n\ntheorem Mathlib.add_subgroup.mem_supr_of_directed {G : Type u_1} [add_group G] {\u03b9 : Sort u_2} [h\u03b9 : Nonempty \u03b9] {K : \u03b9 \u2192 add_subgroup G} (hK : directed LessEq K) {x : G} : x \u2208 supr K \u2194 \u2203 (i : \u03b9), x \u2208 K i := sorry\n\ntheorem Mathlib.add_subgroup.coe_supr_of_directed {G : Type u_1} [add_group G] {\u03b9 : Sort u_2} [Nonempty \u03b9] {S : \u03b9 \u2192 add_subgroup G} (hS : directed LessEq S) : \u2191(supr fun (i : \u03b9) => S i) = set.Union fun (i : \u03b9) => \u2191(S i) := sorry\n\ntheorem Mathlib.add_subgroup.mem_Sup_of_directed_on {G : Type u_1} [add_group G] {K : set (add_subgroup G)} (Kne : set.nonempty K) (hK : directed_on LessEq K) {x : G} : x \u2208 Sup K \u2194 \u2203 (s : add_subgroup G), \u2203 (H : s \u2208 K), x \u2208 s := sorry\n\n/-- The preimage of a subgroup along a monoid homomorphism is a subgroup. -/\ndef Mathlib.add_subgroup.comap {G : Type u_1} [add_group G] {N : Type u_2} [add_group N] (f : G \u2192+ N) (H : add_subgroup N) : add_subgroup G :=\n  add_subgroup.mk (\u21d1f \u207b\u00b9' \u2191H) sorry sorry sorry\n\n@[simp] theorem coe_comap {G : Type u_1} [group G] {N : Type u_3} [group N] (K : subgroup N) (f : G \u2192* N) : \u2191(comap f K) = \u21d1f \u207b\u00b9' \u2191K :=\n  rfl\n\n@[simp] theorem Mathlib.add_subgroup.mem_comap {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {K : add_subgroup N} {f : G \u2192+ N} {x : G} : x \u2208 add_subgroup.comap f K \u2194 coe_fn f x \u2208 K :=\n  iff.rfl\n\ntheorem comap_comap {G : Type u_1} [group G] {N : Type u_3} [group N] {P : Type u_4} [group P] (K : subgroup P) (g : N \u2192* P) (f : G \u2192* N) : comap f (comap g K) = comap (monoid_hom.comp g f) K :=\n  rfl\n\n/-- The image of a subgroup along a monoid homomorphism is a subgroup. -/\ndef map {G : Type u_1} [group G] {N : Type u_3} [group N] (f : G \u2192* N) (H : subgroup G) : subgroup N :=\n  mk (\u21d1f '' \u2191H) sorry sorry sorry\n\n@[simp] theorem Mathlib.add_subgroup.coe_map {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) (K : add_subgroup G) : \u2191(add_subgroup.map f K) = \u21d1f '' \u2191K :=\n  rfl\n\n@[simp] theorem Mathlib.add_subgroup.mem_map {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {f : G \u2192+ N} {K : add_subgroup G} {y : N} : y \u2208 add_subgroup.map f K \u2194 \u2203 (x : G), \u2203 (H : x \u2208 K), coe_fn f x = y :=\n  set.mem_image_iff_bex\n\ntheorem map_map {G : Type u_1} [group G] (K : subgroup G) {N : Type u_3} [group N] {P : Type u_4} [group P] (g : N \u2192* P) (f : G \u2192* N) : map g (map f K) = map (monoid_hom.comp g f) K :=\n  ext' (set.image_image (fun (a : N) => coe_fn g a) (fun (a : G) => coe_fn f a) \u2191K)\n\ntheorem Mathlib.add_subgroup.map_le_iff_le_comap {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {f : G \u2192+ N} {K : add_subgroup G} {H : add_subgroup N} : add_subgroup.map f K \u2264 H \u2194 K \u2264 add_subgroup.comap f H :=\n  set.image_subset_iff\n\ntheorem Mathlib.add_subgroup.gc_map_comap {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) : galois_connection (add_subgroup.map f) (add_subgroup.comap f) :=\n  fun (_x : add_subgroup G) (_x_1 : add_subgroup N) => add_subgroup.map_le_iff_le_comap\n\ntheorem map_sup {G : Type u_1} [group G] {N : Type u_3} [group N] (H : subgroup G) (K : subgroup G) (f : G \u2192* N) : map f (H \u2294 K) = map f H \u2294 map f K :=\n  galois_connection.l_sup (gc_map_comap f)\n\ntheorem Mathlib.add_subgroup.map_supr {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {\u03b9 : Sort u_2} (f : G \u2192+ N) (s : \u03b9 \u2192 add_subgroup G) : add_subgroup.map f (supr s) = supr fun (i : \u03b9) => add_subgroup.map f (s i) :=\n  galois_connection.l_supr (add_subgroup.gc_map_comap f)\n\ntheorem comap_inf {G : Type u_1} [group G] {N : Type u_3} [group N] (H : subgroup N) (K : subgroup N) (f : G \u2192* N) : comap f (H \u2293 K) = comap f H \u2293 comap f K :=\n  galois_connection.u_inf (gc_map_comap f)\n\ntheorem comap_infi {G : Type u_1} [group G] {N : Type u_3} [group N] {\u03b9 : Sort u_2} (f : G \u2192* N) (s : \u03b9 \u2192 subgroup N) : comap f (infi s) = infi fun (i : \u03b9) => comap f (s i) :=\n  galois_connection.u_infi (gc_map_comap f)\n\n@[simp] theorem map_bot {G : Type u_1} [group G] {N : Type u_3} [group N] (f : G \u2192* N) : map f \u22a5 = \u22a5 :=\n  galois_connection.l_bot (gc_map_comap f)\n\n@[simp] theorem Mathlib.add_subgroup.comap_top {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) : add_subgroup.comap f \u22a4 = \u22a4 :=\n  galois_connection.u_top (add_subgroup.gc_map_comap f)\n\ntheorem Mathlib.add_subgroup.map_eq_bot_iff {G : Type u_1} [add_group G] {G' : Type u_2} [add_group G'] {f : G \u2192+ G'} (hf : function.injective \u21d1f) (H : add_subgroup G) : add_subgroup.map f H = \u22a5 \u2194 H = \u22a5 := sorry\n\n/-- Given `subgroup`s `H`, `K` of groups `G`, `N` respectively, `H \u00d7 K` as a subgroup of `G \u00d7 N`. -/\ndef Mathlib.add_subgroup.prod {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (H : add_subgroup G) (K : add_subgroup N) : add_subgroup (G \u00d7 N) :=\n  add_subgroup.mk\n    (add_submonoid.carrier (add_submonoid.prod (add_subgroup.to_add_submonoid H) (add_subgroup.to_add_submonoid K))) sorry\n    sorry sorry\n\ntheorem Mathlib.add_subgroup.coe_prod {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (H : add_subgroup G) (K : add_subgroup N) : \u2191(add_subgroup.prod H K) = set.prod \u2191H \u2191K :=\n  rfl\n\ntheorem Mathlib.add_subgroup.mem_prod {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {H : add_subgroup G} {K : add_subgroup N} {p : G \u00d7 N} : p \u2208 add_subgroup.prod H K \u2194 prod.fst p \u2208 H \u2227 prod.snd p \u2208 K :=\n  iff.rfl\n\ntheorem prod_mono {G : Type u_1} [group G] {N : Type u_3} [group N] : relator.lift_fun LessEq (LessEq \u21d2 LessEq) prod prod :=\n  fun (s s' : subgroup G) (hs : s \u2264 s') (t t' : subgroup N) (ht : t \u2264 t') => set.prod_mono hs ht\n\ntheorem prod_mono_right {G : Type u_1} [group G] {N : Type u_3} [group N] (K : subgroup G) : monotone fun (t : subgroup N) => prod K t :=\n  prod_mono (le_refl K)\n\ntheorem Mathlib.add_subgroup.prod_mono_left {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (H : add_subgroup N) : monotone fun (K : add_subgroup G) => add_subgroup.prod K H :=\n  fun (s\u2081 s\u2082 : add_subgroup G) (hs : s\u2081 \u2264 s\u2082) => add_subgroup.prod_mono hs (le_refl H)\n\ntheorem Mathlib.add_subgroup.prod_top {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (K : add_subgroup G) : add_subgroup.prod K \u22a4 = add_subgroup.comap (add_monoid_hom.fst G N) K := sorry\n\ntheorem Mathlib.add_subgroup.top_prod {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (H : add_subgroup N) : add_subgroup.prod \u22a4 H = add_subgroup.comap (add_monoid_hom.snd G N) H := sorry\n\n@[simp] theorem top_prod_top {G : Type u_1} [group G] {N : Type u_3} [group N] : prod \u22a4 \u22a4 = \u22a4 :=\n  Eq.trans (top_prod \u22a4) (comap_top (monoid_hom.snd G N))\n\ntheorem bot_prod_bot {G : Type u_1} [group G] {N : Type u_3} [group N] : prod \u22a5 \u22a5 = \u22a5 := sorry\n\n/-- Product of subgroups is isomorphic to their product as groups. -/\ndef prod_equiv {G : Type u_1} [group G] {N : Type u_3} [group N] (H : subgroup G) (K : subgroup N) : \u21a5(prod H K) \u2243* \u21a5H \u00d7 \u21a5K :=\n  mul_equiv.mk (equiv.to_fun (equiv.set.prod \u2191H \u2191K)) (equiv.inv_fun (equiv.set.prod \u2191H \u2191K)) sorry sorry sorry\n\n/-- A subgroup is normal if whenever `n \u2208 H`, then `g * n * g\u207b\u00b9 \u2208 H` for every `g : G` -/\nclass normal {G : Type u_1} [group G] (H : subgroup G) \nwhere\n  conj_mem : \u2200 (n : G), n \u2208 H \u2192 \u2200 (g : G), g * n * (g\u207b\u00b9) \u2208 H\n\nend subgroup\n\n\nnamespace add_subgroup\n\n\n/-- An add_subgroup is normal if whenever `n \u2208 H`, then `g + n - g \u2208 H` for every `g : G` -/\nclass normal {A : Type u_2} [add_group A] (H : add_subgroup A) \nwhere\n  conj_mem : \u2200 (n : A), n \u2208 H \u2192 \u2200 (g : A), g + n + -g \u2208 H\n\nend add_subgroup\n\n\nnamespace subgroup\n\n\nprotected instance normal_of_comm {G : Type u_1} [comm_group G] (H : subgroup G) : normal H := sorry\n\nnamespace normal\n\n\ntheorem mem_comm {G : Type u_1} [group G] {H : subgroup G} (nH : normal H) {a : G} {b : G} (h : a * b \u2208 H) : b * a \u2208 H := sorry\n\ntheorem mem_comm_iff {G : Type u_1} [group G] {H : subgroup G} (nH : normal H) {a : G} {b : G} : a * b \u2208 H \u2194 b * a \u2208 H :=\n  { mp := mem_comm nH, mpr := mem_comm nH }\n\nend normal\n\n\nprotected instance bot_normal {G : Type u_1} [group G] : normal \u22a5 :=\n  normal.mk\n    (eq.mpr\n      (id\n        (Eq.trans\n          (Eq.trans\n            (Eq.trans\n              (forall_congr_eq\n                fun (n : G) => imp_congr_eq (propext mem_bot) (forall_congr_eq fun (g : G) => propext mem_bot))\n              (propext forall_eq))\n            (forall_congr_eq\n              fun (g : G) =>\n                Eq.trans\n                  ((fun (a a_1 : G) (e_1 : a = a_1) (\u1fb0 \u1fb0_1 : G) (e_2 : \u1fb0 = \u1fb0_1) => congr (congr_arg Eq e_1) e_2)\n                    (g * 1 * (g\u207b\u00b9)) 1\n                    (Eq.trans\n                      ((fun (\u1fb0 \u1fb0_1 : G) (e_2 : \u1fb0 = \u1fb0_1) (\u1fb0_2 \u1fb0_3 : G) (e_3 : \u1fb0_2 = \u1fb0_3) =>\n                          congr (congr_arg Mul.mul e_2) e_3)\n                        (g * 1) g (mul_one g) (g\u207b\u00b9) (g\u207b\u00b9) (Eq.refl (g\u207b\u00b9)))\n                      (mul_right_inv g))\n                    1 1 (Eq.refl 1))\n                  (propext (eq_self_iff_true 1))))\n          (propext (forall_const G))))\n      trivial)\n\nprotected instance top_normal {G : Type u_1} [group G] : normal \u22a4 :=\n  normal.mk fun (_x : G) (_x : _x \u2208 \u22a4) => mem_top\n\n/-- The center of a group `G` is the set of elements that commute with everything in `G` -/\ndef center (G : Type u_1) [group G] : subgroup G :=\n  mk (set_of fun (z : G) => \u2200 (g : G), g * z = z * g) sorry sorry sorry\n\ntheorem Mathlib.add_subgroup.mem_center_iff {G : Type u_1} [add_group G] {z : G} : z \u2208 add_subgroup.center G \u2194 \u2200 (g : G), g + z = z + g :=\n  iff.rfl\n\nprotected instance Mathlib.add_subgroup.center_normal {G : Type u_1} [add_group G] : add_subgroup.normal (add_subgroup.center G) := sorry\n\n/-- The `normalizer` of `H` is the smallest subgroup of `G` inside which `H` is normal. -/\ndef normalizer {G : Type u_1} [group G] (H : subgroup G) : subgroup G :=\n  mk (set_of fun (g : G) => \u2200 (n : G), n \u2208 H \u2194 g * n * (g\u207b\u00b9) \u2208 H) sorry sorry sorry\n\n-- variant for sets.\n\n-- TODO should this replace `normalizer`?\n\n/-- The `set_normalizer` of `S` is the subgroup of `G` whose elements satisfy `g*S*g\u207b\u00b9=S` -/\ndef set_normalizer {G : Type u_1} [group G] (S : set G) : subgroup G :=\n  mk (set_of fun (g : G) => \u2200 (n : G), n \u2208 S \u2194 g * n * (g\u207b\u00b9) \u2208 S) sorry sorry sorry\n\ntheorem Mathlib.add_subgroup.mem_normalizer_iff {G : Type u_1} [add_group G] {H : add_subgroup G} {g : G} : g \u2208 add_subgroup.normalizer H \u2194 \u2200 (n : G), n \u2208 H \u2194 g + n + -g \u2208 H :=\n  iff.rfl\n\ntheorem le_normalizer {G : Type u_1} [group G] {H : subgroup G} : H \u2264 normalizer H :=\n  fun (x : G) (xH : x \u2208 H) (n : G) =>\n    eq.mpr (id (Eq._oldrec (Eq.refl (n \u2208 H \u2194 x * n * (x\u207b\u00b9) \u2208 H)) (propext (mul_mem_cancel_right H (inv_mem H xH)))))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (n \u2208 H \u2194 x * n \u2208 H)) (propext (mul_mem_cancel_left H xH)))) (iff.refl (n \u2208 H)))\n\nprotected instance normal_in_normalizer {G : Type u_1} [group G] {H : subgroup G} : normal (comap (subtype (normalizer H)) H) := sorry\n\ntheorem le_normalizer_of_normal {G : Type u_1} [group G] {H : subgroup G} {K : subgroup G} [hK : normal (comap (subtype K) H)] (HK : H \u2264 K) : K \u2264 normalizer H := sorry\n\nend subgroup\n\n\nnamespace group\n\n\n/-- Given an element `a`, `conjugates a` is the set of conjugates. -/\ndef conjugates {G : Type u_1} [group G] (a : G) : set G :=\n  set_of fun (b : G) => is_conj a b\n\ntheorem mem_conjugates_self {G : Type u_1} [group G] {a : G} : a \u2208 conjugates a :=\n  is_conj_refl a\n\n/-- Given a set `s`, `conjugates_of_set s` is the set of all conjugates of\nthe elements of `s`. -/\ndef conjugates_of_set {G : Type u_1} [group G] (s : set G) : set G :=\n  set.Union fun (a : G) => set.Union fun (H : a \u2208 s) => conjugates a\n\ntheorem mem_conjugates_of_set_iff {G : Type u_1} [group G] {s : set G} {x : G} : x \u2208 conjugates_of_set s \u2194 \u2203 (a : G), \u2203 (H : a \u2208 s), is_conj a x :=\n  set.mem_bUnion_iff\n\ntheorem subset_conjugates_of_set {G : Type u_1} [group G] {s : set G} : s \u2286 conjugates_of_set s :=\n  fun (x : G) (h : x \u2208 s) => iff.mpr mem_conjugates_of_set_iff (Exists.intro x (Exists.intro h (is_conj_refl x)))\n\ntheorem conjugates_of_set_mono {G : Type u_1} [group G] {s : set G} {t : set G} (h : s \u2286 t) : conjugates_of_set s \u2286 conjugates_of_set t :=\n  set.bUnion_subset_bUnion_left h\n\ntheorem conjugates_subset_normal {G : Type u_1} [group G] {N : subgroup G} [tn : subgroup.normal N] {a : G} (h : a \u2208 N) : conjugates a \u2286 \u2191N :=\n  id\n    fun (a_1 : G) (\u1fb0 : a_1 \u2208 conjugates a) =>\n      Exists.dcases_on \u1fb0 fun (c : G) (\u1fb0_h : c * a * (c\u207b\u00b9) = a_1) => Eq._oldrec (subgroup.normal.conj_mem tn a h c) \u1fb0_h\n\ntheorem conjugates_of_set_subset {G : Type u_1} [group G] {s : set G} {N : subgroup G} [subgroup.normal N] (h : s \u2286 \u2191N) : conjugates_of_set s \u2286 \u2191N :=\n  set.bUnion_subset fun (x : G) (H : x \u2208 s) => conjugates_subset_normal (h H)\n\n/-- The set of conjugates of `s` is closed under conjugation. -/\ntheorem conj_mem_conjugates_of_set {G : Type u_1} [group G] {s : set G} {x : G} {c : G} : x \u2208 conjugates_of_set s \u2192 c * x * (c\u207b\u00b9) \u2208 conjugates_of_set s := sorry\n\nend group\n\n\nnamespace subgroup\n\n\n/-- The normal closure of a set `s` is the subgroup closure of all the conjugates of\nelements of `s`. It is the smallest normal subgroup containing `s`. -/\ndef normal_closure {G : Type u_1} [group G] (s : set G) : subgroup G :=\n  closure (group.conjugates_of_set s)\n\ntheorem conjugates_of_set_subset_normal_closure {G : Type u_1} [group G] {s : set G} : group.conjugates_of_set s \u2286 \u2191(normal_closure s) :=\n  subset_closure\n\ntheorem subset_normal_closure {G : Type u_1} [group G] {s : set G} : s \u2286 \u2191(normal_closure s) :=\n  set.subset.trans group.subset_conjugates_of_set conjugates_of_set_subset_normal_closure\n\ntheorem le_normal_closure {G : Type u_1} [group G] {H : subgroup G} : H \u2264 normal_closure \u2191H :=\n  fun (_x : G) (h : _x \u2208 H) => subset_normal_closure h\n\n/-- The normal closure of `s` is a normal subgroup. -/\nprotected instance normal_closure_normal {G : Type u_1} [group G] {s : set G} : normal (normal_closure s) := sorry\n\n/-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/\ntheorem normal_closure_le_normal {G : Type u_1} [group G] {s : set G} {N : subgroup G} [normal N] (h : s \u2286 \u2191N) : normal_closure s \u2264 N := sorry\n\ntheorem normal_closure_subset_iff {G : Type u_1} [group G] {s : set G} {N : subgroup G} [normal N] : s \u2286 \u2191N \u2194 normal_closure s \u2264 N :=\n  { mp := normal_closure_le_normal, mpr := set.subset.trans subset_normal_closure }\n\ntheorem normal_closure_mono {G : Type u_1} [group G] {s : set G} {t : set G} (h : s \u2286 t) : normal_closure s \u2264 normal_closure t :=\n  normal_closure_le_normal (set.subset.trans h subset_normal_closure)\n\ntheorem normal_closure_eq_infi {G : Type u_1} [group G] {s : set G} : normal_closure s = infi fun (N : subgroup G) => infi (infi fun (hs : s \u2286 \u2191N) => N) :=\n  le_antisymm (le_infi fun (N : subgroup G) => le_infi fun (hN : normal N) => le_infi normal_closure_le_normal)\n    (infi_le_of_le (normal_closure s)\n      (infi_le_of_le subgroup.normal_closure_normal (infi_le_of_le subset_normal_closure (le_refl (normal_closure s)))))\n\n@[simp] theorem normal_closure_eq_self {G : Type u_1} [group G] (H : subgroup G) [normal H] : normal_closure \u2191H = H :=\n  le_antisymm (normal_closure_le_normal (eq.subset rfl)) le_normal_closure\n\n@[simp] theorem normal_closure_idempotent {G : Type u_1} [group G] {s : set G} : normal_closure \u2191(normal_closure s) = normal_closure s :=\n  normal_closure_eq_self (normal_closure s)\n\ntheorem closure_le_normal_closure {G : Type u_1} [group G] {s : set G} : closure s \u2264 normal_closure s :=\n  eq.mpr (id (Eq.trans (propext (closure_le (normal_closure s))) (propext (iff_true_intro subset_normal_closure))))\n    trivial\n\n@[simp] theorem normal_closure_closure_eq_normal_closure {G : Type u_1} [group G] {s : set G} : normal_closure \u2191(closure s) = normal_closure s :=\n  le_antisymm (normal_closure_le_normal closure_le_normal_closure) (normal_closure_mono subset_closure)\n\nend subgroup\n\n\nnamespace add_subgroup\n\n\ntheorem gsmul_mem {A : Type u_2} [add_group A] (H : add_subgroup A) {x : A} (hx : x \u2208 H) (n : \u2124) : n \u2022\u2124 x \u2208 H := sorry\n\n/-- The `add_subgroup` generated by an element of an `add_group` equals the set of\nnatural number multiples of the element. -/\ntheorem mem_closure_singleton {A : Type u_2} [add_group A] {x : A} {y : A} : y \u2208 closure (singleton x) \u2194 \u2203 (n : \u2124), n \u2022\u2124 x = y := sorry\n\ntheorem closure_singleton_zero {A : Type u_2} [add_group A] : closure (singleton 0) = \u22a5 := sorry\n\n@[simp] theorem coe_smul {A : Type u_2} [add_group A] (H : add_subgroup A) (x : \u21a5H) (n : \u2115) : \u2191(n \u2022\u2115 x) = n \u2022\u2115 \u2191x :=\n  coe_subtype H \u25b8 add_monoid_hom.map_nsmul (subtype H) x n\n\n@[simp] theorem coe_gsmul {A : Type u_2} [add_group A] (H : add_subgroup A) (x : \u21a5H) (n : \u2124) : \u2191(n \u2022\u2124 x) = n \u2022\u2124 \u2191x :=\n  coe_subtype H \u25b8 add_monoid_hom.map_gsmul (subtype H) x n\n\nend add_subgroup\n\n\nnamespace monoid_hom\n\n\n/-- The range of a monoid homomorphism from a group is a subgroup. -/\ndef Mathlib.add_monoid_hom.range {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) : add_subgroup N :=\n  add_subgroup.copy (add_subgroup.map f \u22a4) (set.range \u21d1f) sorry\n\nprotected instance decidable_mem_range {G : Type u_1} [group G] {N : Type u_3} [group N] (f : G \u2192* N) [fintype G] [DecidableEq N] : decidable_pred fun (x : N) => x \u2208 range f :=\n  fun (x : N) => fintype.decidable_exists_fintype\n\n@[simp] theorem Mathlib.add_monoid_hom.coe_range {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) : \u2191(add_monoid_hom.range f) = set.range \u21d1f :=\n  rfl\n\n@[simp] theorem Mathlib.add_monoid_hom.mem_range {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {f : G \u2192+ N} {y : N} : y \u2208 add_monoid_hom.range f \u2194 \u2203 (x : G), coe_fn f x = y :=\n  iff.rfl\n\ntheorem Mathlib.add_monoid_hom.range_eq_map {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) : add_monoid_hom.range f = add_subgroup.map f \u22a4 := sorry\n\n/-- The canonical surjective group homomorphism `G \u2192* f(G)` induced by a group\nhomomorphism `G \u2192* N`. -/\ndef Mathlib.add_monoid_hom.to_range {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) : G \u2192+ \u21a5(add_monoid_hom.range f) :=\n  add_monoid_hom.mk' (fun (g : G) => { val := coe_fn f g, property := sorry }) sorry\n\ntheorem Mathlib.add_monoid_hom.map_range {G : Type u_1} [add_group G] {N : Type u_3} {P : Type u_4} [add_group N] [add_group P] (g : N \u2192+ P) (f : G \u2192+ N) : add_subgroup.map g (add_monoid_hom.range f) = add_monoid_hom.range (add_monoid_hom.comp g f) := sorry\n\ntheorem range_top_iff_surjective {G : Type u_1} [group G] {N : Type u_2} [group N] {f : G \u2192* N} : range f = \u22a4 \u2194 function.surjective \u21d1f := sorry\n\n/-- The range of a surjective monoid homomorphism is the whole of the codomain. -/\ntheorem range_top_of_surjective {G : Type u_1} [group G] {N : Type u_2} [group N] (f : G \u2192* N) (hf : function.surjective \u21d1f) : range f = \u22a4 :=\n  iff.mpr range_top_iff_surjective hf\n\n/-- Restriction of a group hom to a subgroup of the codomain. -/\ndef Mathlib.add_monoid_hom.cod_restrict {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) (S : add_subgroup N) (h : \u2200 (x : G), coe_fn f x \u2208 S) : G \u2192+ \u21a5S :=\n  add_monoid_hom.mk (fun (n : G) => { val := coe_fn f n, property := h n }) sorry sorry\n\n/-- The multiplicative kernel of a monoid homomorphism is the subgroup of elements `x : G` such that\n`f x = 1` -/\ndef ker {G : Type u_1} [group G] {N : Type u_3} [group N] (f : G \u2192* N) : subgroup G :=\n  subgroup.comap f \u22a5\n\ntheorem Mathlib.add_monoid_hom.mem_ker {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) {x : G} : x \u2208 add_monoid_hom.ker f \u2194 coe_fn f x = 0 :=\n  iff.rfl\n\ntheorem comap_ker {G : Type u_1} [group G] {N : Type u_3} {P : Type u_4} [group N] [group P] (g : N \u2192* P) (f : G \u2192* N) : subgroup.comap f (ker g) = ker (comp g f) :=\n  rfl\n\ntheorem Mathlib.add_monoid_hom.to_range_ker {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) : add_monoid_hom.ker (add_monoid_hom.to_range f) = add_monoid_hom.ker f := sorry\n\n/-- The subgroup of elements `x : G` such that `f x = g x` -/\ndef eq_locus {G : Type u_1} [group G] {N : Type u_3} [group N] (f : G \u2192* N) (g : G \u2192* N) : subgroup G :=\n  subgroup.mk (submonoid.carrier (eq_mlocus f g)) sorry sorry sorry\n\n/-- If two monoid homomorphisms are equal on a set, then they are equal on its subgroup closure. -/\ntheorem Mathlib.add_monoid_hom.eq_on_closure {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {f : G \u2192+ N} {g : G \u2192+ N} {s : set G} (h : set.eq_on (\u21d1f) (\u21d1g) s) : set.eq_on \u21d1f \u21d1g \u2191(add_subgroup.closure s) :=\n  (fun (this : add_subgroup.closure s \u2264 add_monoid_hom.eq_locus f g) => this)\n    (iff.mpr (add_subgroup.closure_le (add_monoid_hom.eq_locus f g)) h)\n\ntheorem eq_of_eq_on_top {G : Type u_1} [group G] {N : Type u_3} [group N] {f : G \u2192* N} {g : G \u2192* N} (h : set.eq_on \u21d1f \u21d1g \u2191\u22a4) : f = g :=\n  ext fun (x : G) => h trivial\n\ntheorem Mathlib.add_monoid_hom.eq_of_eq_on_dense {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {s : set G} (hs : add_subgroup.closure s = \u22a4) {f : G \u2192+ N} {g : G \u2192+ N} (h : set.eq_on (\u21d1f) (\u21d1g) s) : f = g :=\n  add_monoid_hom.eq_of_eq_on_top (hs \u25b8 add_monoid_hom.eq_on_closure h)\n\ntheorem Mathlib.add_monoid_hom.gclosure_preimage_le {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) (s : set N) : add_subgroup.closure (\u21d1f \u207b\u00b9' s) \u2264 add_subgroup.comap f (add_subgroup.closure s) := sorry\n\n/-- The image under a monoid homomorphism of the subgroup generated by a set equals the subgroup\ngenerated by the image of the set. -/\ntheorem Mathlib.add_monoid_hom.map_closure {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] (f : G \u2192+ N) (s : set G) : add_subgroup.map f (add_subgroup.closure s) = add_subgroup.closure (\u21d1f '' s) := sorry\n\nend monoid_hom\n\n\nnamespace monoid_hom\n\n\n/-- `lift_of_surjective f hf g hg` is the unique group homomorphism `\u03c6`\n\n* such that `\u03c6.comp f = g` (`lift_of_surjective_comp`),\n* where `f : G\u2081 \u2192+* G\u2082` is surjective (`hf`),\n* and `g : G\u2082 \u2192+* G\u2083` satisfies `hg : f.ker \u2264 g.ker`.\n\nSee `lift_of_surjective_eq` for the uniqueness lemma.\n\n```\n   G\u2081.\n   |  \\\n f |   \\ g\n   |    \\\n   v     \\\u231f\n   G\u2082----> G\u2083\n      \u2203!\u03c6\n```\n -/\ndef Mathlib.add_monoid_hom.lift_of_surjective {G\u2081 : Type u_3} {G\u2082 : Type u_4} {G\u2083 : Type u_5} [add_group G\u2081] [add_group G\u2082] [add_group G\u2083] (f : G\u2081 \u2192+ G\u2082) (hf : function.surjective \u21d1f) (g : G\u2081 \u2192+ G\u2083) (hg : add_monoid_hom.ker f \u2264 add_monoid_hom.ker g) : G\u2082 \u2192+ G\u2083 :=\n  add_monoid_hom.mk (fun (b : G\u2082) => coe_fn g (classical.some (hf b))) sorry sorry\n\n@[simp] theorem lift_of_surjective_comp_apply {G\u2081 : Type u_3} {G\u2082 : Type u_4} {G\u2083 : Type u_5} [group G\u2081] [group G\u2082] [group G\u2083] (f : G\u2081 \u2192* G\u2082) (hf : function.surjective \u21d1f) (g : G\u2081 \u2192* G\u2083) (hg : ker f \u2264 ker g) (x : G\u2081) : coe_fn (lift_of_surjective f hf g hg) (coe_fn f x) = coe_fn g x := sorry\n\n@[simp] theorem Mathlib.add_monoid_hom.lift_of_surjective_comp {G\u2081 : Type u_3} {G\u2082 : Type u_4} {G\u2083 : Type u_5} [add_group G\u2081] [add_group G\u2082] [add_group G\u2083] (f : G\u2081 \u2192+ G\u2082) (hf : function.surjective \u21d1f) (g : G\u2081 \u2192+ G\u2083) (hg : add_monoid_hom.ker f \u2264 add_monoid_hom.ker g) : add_monoid_hom.comp (add_monoid_hom.lift_of_surjective f hf g hg) f = g := sorry\n\ntheorem eq_lift_of_surjective {G\u2081 : Type u_3} {G\u2082 : Type u_4} {G\u2083 : Type u_5} [group G\u2081] [group G\u2082] [group G\u2083] (f : G\u2081 \u2192* G\u2082) (hf : function.surjective \u21d1f) (g : G\u2081 \u2192* G\u2083) (hg : ker f \u2264 ker g) (h : G\u2082 \u2192* G\u2083) (hh : comp h f = g) : h = lift_of_surjective f hf g hg := sorry\n\nend monoid_hom\n\n\n-- Here `H.normal` is an explicit argument so we can use dot notation with `comap`.\n\ntheorem subgroup.normal.comap {G : Type u_1} [group G] {N : Type u_3} [group N] {H : subgroup N} (hH : subgroup.normal H) (f : G \u2192* N) : subgroup.normal (subgroup.comap f H) := sorry\n\nprotected instance add_subgroup.normal_comap {G : Type u_1} [add_group G] {N : Type u_3} [add_group N] {H : add_subgroup N} [nH : add_subgroup.normal H] (f : G \u2192+ N) : add_subgroup.normal (add_subgroup.comap f H) :=\n  add_subgroup.normal.comap nH f\n\nprotected instance monoid_hom.normal_ker {G : Type u_1} [group G] {N : Type u_3} [group N] (f : G \u2192* N) : subgroup.normal (monoid_hom.ker f) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (subgroup.normal (monoid_hom.ker f))) (monoid_hom.ker.equations._eqn_1 f)))\n    (subgroup.normal_comap f)\n\nnamespace subgroup\n\n\n/-- The subgroup generated by an element. -/\ndef gpowers {G : Type u_1} [group G] (g : G) : subgroup G :=\n  subgroup.copy (monoid_hom.range (coe_fn (gpowers_hom G) g)) (set.range (pow g)) sorry\n\n@[simp] theorem mem_gpowers {G : Type u_1} [group G] (g : G) : g \u2208 gpowers g :=\n  Exists.intro 1 (gpow_one g)\n\ntheorem gpowers_eq_closure {G : Type u_1} [group G] (g : G) : gpowers g = closure (singleton g) :=\n  ext fun (x : G) => iff.symm mem_closure_singleton\n\n@[simp] theorem range_gpowers_hom {G : Type u_1} [group G] (g : G) : monoid_hom.range (coe_fn (gpowers_hom G) g) = gpowers g :=\n  rfl\n\ntheorem gpowers_subset {G : Type u_1} [group G] {a : G} {K : subgroup G} (h : a \u2208 K) : gpowers a \u2264 K := sorry\n\nend subgroup\n\n\nnamespace add_subgroup\n\n\n/-- The subgroup generated by an element. -/\ndef gmultiples {A : Type u_2} [add_group A] (a : A) : add_subgroup A :=\n  add_subgroup.copy (add_monoid_hom.range (coe_fn (gmultiples_hom A) a)) (set.range fun (_x : \u2124) => _x \u2022\u2124 a) sorry\n\n@[simp] theorem mem_gmultiples {A : Type u_2} [add_group A] (a : A) : a \u2208 gmultiples a :=\n  Exists.intro 1 (one_gsmul a)\n\ntheorem gmultiples_eq_closure {A : Type u_2} [add_group A] (a : A) : gmultiples a = closure (singleton a) :=\n  ext fun (x : A) => iff.symm mem_closure_singleton\n\n@[simp] theorem range_gmultiples_hom {A : Type u_2} [add_group A] (a : A) : add_monoid_hom.range (coe_fn (gmultiples_hom A) a) = gmultiples a :=\n  rfl\n\ntheorem gmultiples_subset {A : Type u_2} [add_group A] {a : A} {B : add_subgroup A} (h : a \u2208 B) : gmultiples a \u2264 B :=\n  subgroup.gpowers_subset h\n\nend add_subgroup\n\n\nnamespace mul_equiv\n\n\n/-- Makes the identity isomorphism from a proof two subgroups of a multiplicative\n    group are equal. -/\ndef subgroup_congr {G : Type u_1} [group G] {H : subgroup G} {K : subgroup G} (h : H = K) : \u21a5H \u2243* \u21a5K :=\n  mk (equiv.to_fun (equiv.set_congr sorry)) (equiv.inv_fun (equiv.set_congr sorry)) sorry sorry sorry\n\nend mul_equiv\n\n\n-- TODO : \u21a5(\u22a4 : subgroup H) \u2243* H ?\n\nnamespace subgroup\n\n\ntheorem Mathlib.add_subgroup.mem_sup {C : Type u_4} [add_comm_group C] {s : add_subgroup C} {t : add_subgroup C} {x : C} : x \u2208 s \u2294 t \u2194 \u2203 (y : C), \u2203 (H : y \u2208 s), \u2203 (z : C), \u2203 (H : z \u2208 t), y + z = x := sorry\n\ntheorem Mathlib.add_subgroup.mem_sup' {C : Type u_4} [add_comm_group C] {s : add_subgroup C} {t : add_subgroup C} {x : C} : x \u2208 s \u2294 t \u2194 \u2203 (y : \u21a5s), \u2203 (z : \u21a5t), \u2191y + \u2191z = x := sorry\n\nprotected instance Mathlib.add_subgroup.is_modular_lattice {C : Type u_4} [add_comm_group C] : is_modular_lattice (add_subgroup C) := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/group_theory/subgroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7052152903345408}}
{"text": "inductive Le (m : Nat) : Nat \u2192 Prop\n  | base : Le m m\n  | succ : (n : Nat) \u2192 Le m n \u2192 Le m n.succ\n\ntheorem ex1 (m : Nat) : Le m 0 \u2192 m = 0 := by\n  intro h\n  cases h\n  rfl\n\ntheorem ex2 (m n : Nat) : Le m n \u2192 Le m.succ n.succ := by\n  intro h\n  induction h with\n  | base => apply Le.base\n  | succ n m ih =>\n    apply Le.succ\n    apply ih\n\ntheorem ex3 (m : Nat) : Le 0 m := by\n  induction m with\n  | zero => apply Le.base\n  | succ m ih =>\n    apply Le.succ\n    apply ih\n\ntheorem ex4 (m : Nat) : \u00ac Le m.succ 0 := by\n  intro h\n  cases h\n\ntheorem ex5 {m n : Nat} : Le m n.succ \u2192 m = n.succ \u2228 Le m n := by\n  intro h\n  cases h with\n  | base => apply Or.inl; rfl\n  | succ => apply Or.inr; assumption\n\ntheorem ex6 {m n : Nat} : Le m.succ n.succ \u2192 Le m n := by\n  revert m\n  induction n with\n  | zero =>\n    intros m h;\n    cases h with\n    | base => apply Le.base\n    | succ n h => exact absurd h (ex4 _)\n  | succ n ih =>\n    intros m h\n    have aux := ih (m := m)\n    cases ex5 h with\n    | inl h =>\n      injection h with h\n      subst h\n      apply Le.base\n    | inr h =>\n      apply Le.succ\n      exact ih h\n\ntheorem ex7 {m n o : Nat} : Le m n \u2192 Le n o \u2192 Le m o := by\n  intro h\n  induction h with\n  | base => intros; assumption\n  | succ n s ih =>\n    intro h\u2082\n    apply ih\n    apply ex6\n    apply Le.succ\n    assumption\n\ntheorem ex8 {m n : Nat} : Le m.succ n \u2192 Le m n := by\n  intro h\n  apply ex6\n  apply Le.succ\n  assumption\n\ntheorem ex9 {m n : Nat} : Le m n \u2192 m = n \u2228 Le m.succ n := by\n  intro h\n  cases h with\n  | base => apply Or.inl; rfl\n  | succ n s =>\n    apply Or.inr\n    apply ex2\n    assumption\n\n/-\ntheorem ex10 (n : Nat) : \u00ac Le n.succ n := by\n  intro h\n  cases h -- TODO: improve cases tactic\n  done\n-/\n\ntheorem ex10 (n : Nat) : n.succ \u2260 n := by\n  induction n with\n  | zero => intro h; injection h; done\n  | succ n ih => intro h; injection h with h; apply ih h\n\ntheorem ex11 (n : Nat) : \u00ac Le n.succ n := by\n  induction n with\n  | zero => intro h; cases h; done\n  | succ n ih =>\n    intro h\n    have aux := ex6 h\n    exact absurd aux ih\n    done\n\ntheorem ex12 (m n : Nat) : Le m n \u2192 Le n m \u2192 m = n := by\n  revert m\n  induction n with\n  | zero => intro m h1 h2; apply ex1; assumption; done\n  | succ n ih =>\n    intro m h1 h2\n    have ih := ih m\n    cases ex5 h1 with\n    | inl h => assumption\n    | inr h =>\n      have ih := ih h\n      have h3 := ex8 h2\n      have ih := ih h3\n      subst ih\n      apply absurd h2 (ex11 _)\n      done\n\ninductive Foo : Nat \u2192 Prop where\n  | foo : Foo 0\n  | bar : Foo 0\n  | baz : Foo 1\n\nexample (f : Foo 0) : True := by\n  cases f with\n  | _ => trivial\n\nexample (f : Foo n) (h : n = 0) : True := by\n  induction f with simp at h\n  | _ => trivial\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/tacticTests.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7052152885202757}}
{"text": "import tactic\nimport data.real.basic\n/-\n\nFibonacci. Harder than it looks.\n\n-/\n\ndef fib : \u2115 \u2192 \u2115\n| 0 := 0\n| 1 := 1\n| (n + 2) := fib n + fib (n + 1) -- remark that brackets needed around n+2, a common newbie error\n\n-- When making a definition like this, I find it clear\n-- to instantly restart the equation lemmas.\n\nlemma fib_0 : fib 0 = 0 := by refl -- true by definition\nlemma fib_1 : fib 1 = 1 := rfl -- term mode variant\nlemma fib_succ_succ (n : \u2115) : fib (n + 2) = fib n + fib (n + 1) := by refl\n\n-- Sample easy-looking thing which is easy:\n\nopen finset\n\nexample (n : \u2115) : 1 + (range n).sum fib = fib (n + 1) :=\nbegin\n  -- easy induction\n  induction n with d hd,\n  { refl},\n  rw sum_range_succ,\n  rw add_left_comm, -- cunning shortcut\n  rw hd,\n  symmetry,\n  exact fib_succ_succ d\nend\n\n-- But anything with subtraction in it is going to be hard.\n-- For example I wouldn't fancy fib(n+1)^2-fib(n)fib(n+2)=(-1)^n using this nat definition.\n\ndef fibZ : \u2115 \u2192 \u2124\n| 0 := 0\n| 1 := 1\n| (n + 2) := fibZ n + fibZ (n + 1)\n\n@[simp] lemma fibZ_0 : fibZ 0 = 0 := rfl\n@[simp] lemma fibZ_1 : fibZ 1 = 1 := rfl\n@[simp] lemma fibZ_succ_succ (n : \u2115) : fibZ (n + 2) = fibZ n + fibZ (n + 1) := rfl\n\n-- painless subtraction\nexample (n : \u2115) : fibZ (n+2) - fibZ(n+1) = fibZ(n) :=\nbegin\n  rw fibZ_succ_succ,\n  ring,\nend\n\n-- Binet's formula for Fibonacci numbers uses reals.\n\nopen real\n\nnoncomputable def a : \u211d := (1+sqrt(5))/2\nnoncomputable def b : \u211d := (1-sqrt(5))/2\n\n-- Binet says (a^n-b^n)/sqrt(5) = fib n\n\n-- Can't prove this by straight induction!\n-- Need P(n) and P(n+1) implies P(n+2)\n-- So let's make our own induction principle\n\nlemma induction2 (P : \u2115 \u2192 Prop) (h0 : P 0) (h1 : P 1)\n  (hind : \u2200 d : \u2115, P d \u2192 P(d+1) \u2192 P(d+2)) : \u2200 n, P n :=\nbegin\n  -- reminder of maths proof: if Q(n) := P(n) \u2227 P(n+1) then Q(n) can be\n  -- proved by normal induction\n  set Q : \u2115 \u2192 Prop := \u03bb n, P n \u2227 P(n+1) with Qdef, -- note use of `set`\n  have hQ : \u2200 n, Q n,\n  { -- prove hQ by usual induction\n    intro n,\n    induction n with d hd,\n    { -- base case\n      rw Qdef,\n      split,\n      { exact h0},\n      { exact h1}},\n    { -- inductive step for hQ\n      rw Qdef at \u22a2 hd,\n      cases hd with hPd hPd1,\n      split, exact hPd1,\n      apply hind,\n      { assumption},\n      { assumption}}},\n  -- now we know Q n is true for all n, so deducing P n is easy\n  intro n,\n  have hQn := hQ n,\n  rw Qdef at hQn,\n  cc, -- because why not\nend\n\n-- baby application: fib and fibZ coincide.\n\nlemma fibZ_eq_fib : \u2200 n, fibZ n = fib n :=\nbegin\n  apply induction2,\n  { refl},\n  { refl},\n  intros h h1 h2,\n  rw [fib_succ_succ, fibZ_succ_succ, h1, h2],\n  norm_cast,\nend\n\n\n-- Recall we're going for Binet. We're also going to need a^{d+2}=a^{d+1}+a^d\n-- so let's get this out of the way\n\nlemma a_min_pol : a^2=a+1 :=\nbegin\n  rw a, -- 2's in denominator now\n  have h2 : (2 : \u211d) \u2260 0,\n    norm_num,\n  field_simp [h2],\n  ring, -- fails; doesn't close goal.\n  -- Is using it bad style?\n  -- this now stinks\n  rw [add_mul, mul_assoc],\n  rw mul_self_sqrt,\n  { ring},\n  { norm_num}\nend\n\nlemma a_thing (d : \u2115) : a^(d+2) = a^(d+1) + a^d :=\nbegin\n  rw [pow_add, a_min_pol],\n  ring_exp,\nend\n\nlemma b_min_pol : b^2=b+1 :=\nbegin\n  rw b,\n  have h2 : (2 : \u211d) \u2260 0,\n    norm_num,\n  field_simp [h2],\n  ring, -- fails\n  rw [sub_mul, mul_assoc],\n  rw mul_self_sqrt,\n  { ring},\n  { norm_num}\nend\n\nlemma b_thing (d : \u2115) : b^(d+2) = b^(d+1) + b^d :=\nbegin\n  rw [pow_add, b_min_pol],\n  ring_exp,\nend\n\ntheorem binet : \u2200 n, (a^n-b^n)/sqrt(5) = fib n :=\nbegin\n  -- prove using this modified induction principle\n  apply induction2,\n  { -- case n=0\n    rw fib_0,\n    rw pow_zero,\n    rw pow_zero,\n    -- goal now trivial to mathematicians\n    rw [sub_self, zero_div], norm_cast,\n  },\n  { rw fib_1,\n    rw pow_one,\n    rw pow_one,\n    rw [a,b],\n    -- goal now trivial to mathematicians.\n    -- division is scary, like subtraction is.\n    -- top tip: tell Lean the denominators are non-zero.\n    have h2 : (2 : \u211d) \u2260 0, by norm_num,\n    have hs5 : sqrt 5 \u2260 0, by norm_num,\n    field_simp [h2, hs5],\n    ring},\n  { intros d h1 h2,\n    rw [a_thing, b_thing],\n    rw fib_succ_succ,\n    push_cast,\n    rw [\u2190h1, \u2190h2],\n    ring}\nend\n\nlemma sub_mul_self_eq {R : Type*} [comm_ring R] (a b : R) : (a-b)^2=a^2-2*a*b+b^2 := by ring\n\n-- Can now use Binet to prove things\nexample (n : \u2115) : fib (2*n+1)=fib(n)^2+fib(n+1)^2 :=\nbegin\n  suffices : (fib (2*n+1) : \u211d) = (fib(n) : \u211d)^2 + (fib(n+1) : \u211d)^2,\n    norm_cast at this,\n    assumption,\n  rw [\u2190binet, \u2190binet, \u2190binet],\n  have h5 : sqrt 5 \u2260 0,\n    norm_num,\n  field_simp [h5],\n  -- \u22a2 (\u221a5)^2(a^(2n+1)-b^(2n+1))=\u221a5((a^n-b^n)^2+(a^(n+1)-b^(n+1))^2)\n  -- cancel a \u221a5\n  rw [pow_two, \u2190mul_assoc], congr',\n  -- I think I am going to have to solve this by hand\n  -- first turn \u221a5's into a's or b's as appropriate\n  have ha : sqrt 5 = 2 * a - 1,\n    rw a, field_simp, ring,\n  have hb : sqrt 5 = 1 - 2 * b,\n    rw b, field_simp, ring,\n  rw [sub_mul, sub_mul_self_eq, sub_mul_self_eq],\n  conv begin\n    to_lhs, congr, rw ha, skip, rw hb,\n  end,\n  -- a^n*b^n=(-1)^n\n  rw [mul_assoc (2:\u211d), \u2190mul_pow],\n  rw [mul_assoc (2:\u211d), \u2190mul_pow],\n  have hab : a*b=-1,\n  { rw [a,b],\n    field_simp,\n    ring,\n    rw sqr_sqrt, norm_num, norm_num\n  },\n  -- perhaps this is actually tricky in real maths?\n  rw hab,\n  ring_exp,\n  rw a_min_pol,\n  rw b_min_pol,\n  ring_exp,\nend\n\n-- integer approach involves proving a more general thing first\nlemma fib_m_n (m n : \u2115) : fib(m+n+1)=fib(m+1)*fib(n+1)+fib(m)*fib(n) :=\nbegin\n  -- I really don't fancy this using \u2115\n  suffices : fibZ(m+n+1)=fibZ(m+1)*fibZ(n+1)+fibZ(m)*fibZ(n),\n  { simp only [fibZ_eq_fib] at this,\n    norm_cast at this,\n    assumption},\n  refine induction2 _ _ _ _ n,\n  { simp},\n  { show fibZ (m + 2) = fibZ (m + 1) * 1 + fibZ m * 1 ,\n    rw fibZ_succ_succ,\n    simp [add_comm]},\n  { -- inductive step\n    intros d h1 h2,\n    show fibZ (m + (d + 1) + 2) = fibZ (m + 1) * fibZ ((d + 1) + 2) + fibZ m * fibZ (d + 2),\n    rw fibZ_succ_succ d,\n    rw fibZ_succ_succ (d+1),\n    rw fibZ_succ_succ (m+(d+1)),\n    rw h2,\n    rw [\u2190add_assoc m],\n    rw h1,\n    ring,\n  }\nend\n\nexample (n : \u2115) : fib (2*n+1)=fib(n)^2+fib(n+1)^2 :=\nbegin\n  convert fib_m_n n n using 1; ring\nend\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Mathematics_In_Lean_ideas/Fibonacci.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7052152734871255}}
{"text": "import mynat.definition\nimport mynat.add\n\nnamespace mynat\n\nlemma succ_add (a b : mynat) : succ(a) + b = succ(a + b) :=\nbegin [nat_num_game]\n    induction b with d hd,\n    {\n        rw add_zero,\n        rw add_zero,\n        refl,\n    },\n    {\n        rw add_succ,\n        rw add_succ,\n        rw hd,\n        refl,\n    }\nend\n\nend mynat\n", "meta": {"author": "nomoid", "repo": "lean-proofs", "sha": "b9f03a24623d1a1d111d6c2bbf53c617e2596d6a", "save_path": "github-repos/lean/nomoid-lean-proofs", "path": "github-repos/lean/nomoid-lean-proofs/lean-proofs-b9f03a24623d1a1d111d6c2bbf53c617e2596d6a/src/world2/level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.7052049440652738}}
{"text": "import .love09_hoare_logic_demo\n\n\n/- # LoVe Exercise 9: Hoare Logic -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1: Program Verification\n\nThe following WHILE program is intended to compute the Gaussian sum up to `n`,\nleaving the result in `r`. -/\n\ndef GAUSS : stmt :=\nstmt.assign \"r\" (\u03bbs, 0) ;;\nstmt.while (\u03bbs, s \"n\" \u2260 0)\n  (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"n\") ;;\n   stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n\n/- The summation function: -/\n\ndef sum_upto : \u2115 \u2192 \u2115\n| 0       := 0\n| (n + 1) := n + 1 + sum_upto n\n\n/- 1.1. Prove the correctness of `GAUSS` using `vcg`. The main challenge is to\nfigure out which invariant to use for the while loop. The invariant should\ncapture both the work that has been done already (the intermediate result) and\nthe work that remains to be done. -/\n\nlemma GAUSS_correct (n\u2080 : \u2115) :\n  {* \u03bbs, s \"n\" = n\u2080 *} GAUSS {* \u03bbs, s \"r\" = sum_upto n\u2080 *} :=\nshow {* \u03bbs, s \"n\" = n\u2080 *}\n     stmt.assign \"r\" (\u03bbs, 0) ;;\n     stmt.while_inv (\u03bbs, s \"r\" + sum_upto (s \"n\") = sum_upto n\u2080) (\u03bbs, s \"n\" \u2260 0)\n       (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"n\") ;;\n        stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n     {* \u03bbs, s \"r\" = sum_upto n\u2080 *}, from\n  begin\n    vcg; simp [sum_upto] { contextual := tt },\n    intro s,\n    cases' s \"n\",\n    { simp },\n    { simp [nat.succ_eq_add_one, sum_upto],\n      cc }\n  end\n\n/- 1.2. The following WHILE program is intended to compute the product of `n`\nand `m`, leaving the result in `r`. Prove its correctness using `vcg`.\n\nHint: If a variable `x` does not change in a program, it might be useful to\nrecord this in the invariant, by adding a conjunct `s \"x\" = x\u2080`. -/\n\ndef MUL : stmt :=\nstmt.assign \"r\" (\u03bbs, 0) ;;\nstmt.while (\u03bbs, s \"n\" \u2260 0)\n  (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"m\") ;;\n   stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n\nlemma MUL_correct (n\u2080 m\u2080 : \u2115) :\n  {* \u03bbs, s \"n\" = n\u2080 \u2227 s \"m\" = m\u2080 *} MUL {* \u03bbs, s \"r\" = n\u2080 * m\u2080 *} :=\nshow {* \u03bbs, s \"n\" = n\u2080 \u2227 s \"m\" = m\u2080 *}\n     stmt.assign \"r\" (\u03bbs, 0) ;;\n     stmt.while_inv (\u03bbs, s \"m\" = m\u2080 \u2227 s \"r\" + s \"n\" * s \"m\" = n\u2080 * s \"m\")\n         (\u03bbs, s \"n\" \u2260 0)\n       (stmt.assign \"r\" (\u03bbs, s \"r\" + s \"m\") ;;\n        stmt.assign \"n\" (\u03bbs, s \"n\" - 1))\n     {* \u03bbs, s \"r\" = n\u2080 * m\u2080 *}, from\n  begin\n    vcg; simp { contextual := tt },\n    intro s,\n    cases' s \"n\",\n    { simp },\n    { simp [nat.succ_eq_add_one, mul_add, add_mul],\n      cc }\n  end\n\n\n/- ## Question 2: Hoare Triples for Total Correctness -/\n\ndef total_hoare (P : state \u2192 Prop) (S : stmt) (Q : state \u2192 Prop) : Prop :=\n\u2200s, P s \u2192 \u2203t, (S, s) \u27f9 t \u2227 Q t\n\nnotation `[* ` P : 1 ` *] ` S : 1 ` [* ` Q : 1 ` *]` :=\ntotal_hoare P S Q\n\nnamespace total_hoare\n\n/- 2.1. Prove the consequence rule. -/\n\nlemma consequence {P P' Q Q' : state \u2192 Prop} {S}\n    (hS : [* P *] S [* Q *]) (hP : \u2200s, P' s \u2192 P s) (hQ : \u2200s, Q s \u2192 Q' s) :\n  [* P' *] S [* Q' *] :=\nbegin\n  intros s hs,\n  cases' hS s (hP s hs) with t ht,\n  apply exists.intro t,\n  apply and.intro,\n  { exact and.elim_left ht },\n  { exact hQ t (and.elim_right ht) }\nend\n\n/- 2.2. Prove the rule for `skip`. -/\n\nlemma skip_intro {P} :\n  [* P *] stmt.skip [* P *] :=\nbegin\n  intros s hs,\n  apply exists.intro s,\n  exact and.intro big_step.skip hs\nend\n\n/- 2.3. Prove the rule for `assign`. -/\n\nlemma assign_intro {P : state \u2192 Prop} {x} {a : state \u2192 \u2115} :\n  [* \u03bbs, P (s{x \u21a6 a s}) *] stmt.assign x a [* P *] :=\nbegin\n  intros s hs,\n  apply exists.intro (s{x \u21a6 a s}),\n  exact and.intro big_step.assign hs\nend\n\n/- 2.4. Prove the rule for `seq`. -/\n\nlemma seq_intro {P Q R S T} (hS : [* P *] S [* Q *]) (hT : [* Q *] T [* R *]) :\n  [* P *] S ;; T [* R *] :=\nbegin\n  intros s hs,\n  cases' hS s hs with t hS',\n  cases' hT t (and.elim_right hS') with u hT',\n  apply exists.intro u,\n  apply and.intro,\n  { exact big_step.seq (and.elim_left hS') (and.elim_left hT') },\n  { exact and.elim_right hT' }\nend\n\n/- 2.5. Complete the proof of the rule for `ite`.\n\nHint: This requires a case distinction on the truth value of `b s`. -/\n\nlemma ite_intro {b P Q : state \u2192 Prop} {S T}\n    (hS : [* \u03bbs, P s \u2227 b s *] S [* Q *])\n    (hT : [* \u03bbs, P s \u2227 \u00ac b s *] T [* Q *]) :\n  [* P *] stmt.ite b S T [* Q *] :=\nbegin\n  intros s hs,\n  cases' classical.em (b s),\n  { cases' hS s (and.intro hs h) with t ht,\n    apply exists.intro t,\n    apply and.intro,\n    { exact big_step.ite_true h (and.elim_left ht) },\n    { exact and.elim_right ht } },\n  { cases' hT s (and.intro hs h) with t ht,\n    apply exists.intro t,\n    apply and.intro,\n    { exact big_step.ite_false h (and.elim_left ht) },\n    { exact and.elim_right ht } }\nend\n\n/- 2.6 (**optional**). Try to prove the rule for `while`.\n\nThe rule is parameterized by a loop invariant `I` and by a variant `V` that\ndecreases with each iteration of the loop body.\n\nBefore we prove the desired lemma, we introduce an auxiliary lemma. Its proof\nrequires well-founded induction. When using `while_var_intro_aux` as induction\nhypothesis we recommend to do it directly after proving that the argument is\nless than `v\u2080`:\n\n    have ih : \u2203u, (stmt.while b S, t) \u27f9 u \u2227 I u \u2227 \u00ac b u :=\n      have V t < v\u2080 :=\n        \u2026,\n      while_var_intro_aux (V t) \u2026,\n\nSimilarly to `ite`, the proof requires a case distinction on `b s \u2228 \u00ac b s`. -/\n\nlemma while_var_intro_aux {b : state \u2192 Prop} (I : state \u2192 Prop) (V : state \u2192 \u2115)\n  {S} (h_inv : \u2200v\u2080, [* \u03bbs, I s \u2227 b s \u2227 V s = v\u2080 *] S [* \u03bbs, I s \u2227 V s < v\u2080 *]) :\n  \u2200v\u2080 s, V s = v\u2080 \u2192 I s \u2192 \u2203t, (stmt.while b S, s) \u27f9 t \u2227 I t \u2227 \u00ac b t\n| v\u2080 s V_eq hs :=\n  begin\n    cases' classical.em (b s) with hcs hncs,\n    { have h_inv : \u2203t, (S, s) \u27f9 t \u2227 I t \u2227 V t < v\u2080 :=\n        h_inv v\u2080 s (and.intro hs (and.intro hcs V_eq)),\n      cases' h_inv with t ht,\n      have ih : \u2203u, (stmt.while b S, t) \u27f9 u \u2227 I u \u2227 \u00ac b u :=\n        have V t < v\u2080 :=\n          and.elim_right (and.elim_right ht),\n        while_var_intro_aux (V t) t (by refl)\n          (and.elim_left (and.elim_right ht)),\n      cases' ih with u hu,\n      apply exists.intro u,\n      apply and.intro,\n      { exact big_step.while_true hcs (and.elim_left ht) (and.elim_left hu) },\n      { exact and.elim_right hu } },\n    { apply exists.intro s,\n      apply and.intro,\n      { exact big_step.while_false hncs },\n      { exact and.intro hs hncs } }\n  end\n\nlemma while_var_intro {b : state \u2192 Prop} (I : state \u2192 Prop) (V : state \u2192 \u2115) {S}\n  (hinv : \u2200v\u2080, [* \u03bbs, I s \u2227 b s \u2227 V s = v\u2080 *] S [* \u03bbs, I s \u2227 V s < v\u2080 *]) :\n  [* I *] stmt.while b S [* \u03bbs, I s \u2227 \u00ac b s *] :=\nbegin\n  intros s hs,\n  exact while_var_intro_aux I V hinv (V s) s (by refl) hs\nend\n\nend total_hoare\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love09_hoare_logic_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7051531448826186}}
{"text": "/-\nCopyright (c) 2018 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis\n\nInteger power operation on fields.\n-/\n\nimport algebra.group_power tactic.wlog\n\nuniverse u\n\nsection field_power\nopen int nat\nvariables {\u03b1 : Type u} [division_ring \u03b1]\n\n@[simp] lemma zero_gpow : \u2200 z : \u2115, z \u2260 0 \u2192 (0 : \u03b1)^z = 0\n| 0 h := absurd rfl h\n| (k+1) h := zero_mul _\n\ndef fpow (a : \u03b1) : \u2124 \u2192 \u03b1\n| (of_nat n) := a ^ n\n| -[1+n] := 1/(a ^ (n+1))\n\nlemma unit_pow {a : \u03b1} (ha : a \u2260 0) : \u2200 n : \u2115, a ^ n = \u2191((units.mk0 a ha)^n)\n| 0 := by simp; refl\n| (k+1) := by simp [_root_.pow_add]; congr; apply unit_pow\n\nlemma fpow_eq_gpow {a : \u03b1} (h : a \u2260 0) : \u2200 (z : \u2124), fpow a z = \u2191(gpow (units.mk0 a h) z)\n| (of_nat k) := by simp only [fpow, gpow]; apply unit_pow\n| -[1+k] := by simp [fpow, gpow]; congr; apply unit_pow\n\nlemma fpow_inv (a : \u03b1) : fpow a (-1) = a\u207b\u00b9 :=\nbegin change fpow a -[1+0] = a\u207b\u00b9, simp [fpow] end\n\nlemma fpow_ne_zero_of_ne_zero {a : \u03b1} (ha : a \u2260 0) : \u2200 (z : \u2124), fpow a z \u2260 0\n| (of_nat n) := pow_ne_zero _ ha\n| -[1+n] := one_div_ne_zero $ pow_ne_zero _ ha\n\n\n@[simp] lemma fpow_zero {a : \u03b1} : fpow a 0 = 1 :=\npow_zero _\n\nlemma fpow_add {a : \u03b1} (ha : a \u2260 0) (z1 z2 : \u2124) : fpow a (z1 + z2) = fpow a z1 * fpow a z2 :=\nbegin simp only [fpow_eq_gpow ha], rw \u2190units.mul_coe, congr, apply gpow_add end\n\nend field_power\n\nsection discrete_field_power\nopen int nat\nvariables {\u03b1 : Type u} [discrete_field \u03b1]\n\nlemma zero_fpow : \u2200 z : \u2124, z \u2260 0 \u2192 fpow (0 : \u03b1) z = 0\n| (of_nat n) h :=\n  have h2 : n \u2260 0, from assume : n = 0, by simpa [this] using h,\n  by simp [h, h2, fpow]\n| -[1+n] h :=\n  have h1 : (0 : \u03b1) ^ (n+1) = 0, from zero_mul _,\n  by simp [fpow, h1]\n\nend discrete_field_power\n\nsection ordered_field_power\nopen int\n\nvariables {\u03b1 : Type u} [discrete_linear_ordered_field \u03b1]\n\nlemma fpow_nonneg_of_nonneg {a : \u03b1} (ha : a \u2265 0) : \u2200 (z : \u2124), fpow a z \u2265 0\n| (of_nat n) := pow_nonneg ha _\n| -[1+n] := div_nonneg' zero_le_one $ pow_nonneg ha _\n\n\nlemma fpow_le_of_le {x : \u03b1} (hx : 1 \u2264 x) {a b : \u2124} (h : a \u2264 b) : fpow x a \u2264 fpow x b :=\nbegin\n  induction a with a a; induction b with b b,\n  { simp only [fpow],\n    apply pow_le_pow hx,\n    apply le_of_coe_nat_le_coe_nat h },\n  { apply absurd h,\n    apply not_le_of_gt,\n    exact lt_of_lt_of_le (neg_succ_lt_zero _) (of_nat_nonneg _) },\n  { simp only [fpow, one_div_eq_inv],\n    apply le_trans (inv_le_one _); apply one_le_pow_of_one_le hx },\n  { simp only [fpow],\n    apply (one_div_le_one_div _ _).2,\n    { apply pow_le_pow hx,\n      have : -(\u2191(a+1) : \u2124) \u2264 -(\u2191(b+1) : \u2124), from h,\n      have h' := le_of_neg_le_neg this,\n      apply le_of_coe_nat_le_coe_nat h' },\n    repeat { apply pow_pos (lt_of_lt_of_le zero_lt_one hx) } }\nend\n\nlemma pow_le_max_of_min_le {x : \u03b1} (hx : x \u2265 1) {a b c : \u2124} (h : min a b \u2264 c) :\n      fpow x (-c) \u2264 max (fpow x (-a)) (fpow x (-b)) :=\nbegin\n  wlog hle : a \u2264 b,\n  have hnle : -b \u2264 -a, from neg_le_neg hle,\n  have hfle : fpow x (-b) \u2264 fpow x (-a), from fpow_le_of_le hx hnle,\n  have : fpow x (-c) \u2264 fpow x (-a),\n  { apply fpow_le_of_le hx,\n    simpa [hle] using h },\n  simpa [hfle] using this\nend\n\nend ordered_field_power", "meta": {"author": "khoek", "repo": "mathlib-tidy", "sha": "866afa6ab597c47f1b72e8fe2b82b97fff5b980f", "save_path": "github-repos/lean/khoek-mathlib-tidy", "path": "github-repos/lean/khoek-mathlib-tidy/mathlib-tidy-866afa6ab597c47f1b72e8fe2b82b97fff5b980f/algebra/field_power.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7051531415145953}}
{"text": "import util.list.pairwise\nimport util.list.nil\n\ndef ord_insert\n  {t: Type}\n  [has_le t]\n  [@decidable_rel t has_le.le]\n  (x: t)\n: list t -> list t\n| [] := [x]\n| (y :: ys) := if x \u2264 y then x :: y :: ys else y :: ord_insert ys\n\ndef insertion_sort\n  {t: Type}\n  [has_le t]\n  [@decidable_rel t has_le.le]\n: list t -> list t\n| [] := []\n| (x :: xs) := ord_insert x (insertion_sort xs)\n\ndef sorted {t: Type} [has_le t]: list t -> Prop := pairwise (\u2264)\n\ntheorem ord_insert_mem {t: Type} {xs: list t} {x y: t}\n  [has_le t] [@decidable_rel t has_le.le]:\n  x \u2208 ord_insert y xs \u2194\n  x = y \u2228 x \u2208 xs :=\nbegin\n  split,\n  intro in_ins,\n  induction xs,\n  simp [ord_insert] at in_ins,\n  left,\n  exact in_ins,\n  simp [ord_insert] at in_ins,\n  by_cases y \u2264 xs_hd,\n  simp [h] at in_ins,\n  exact in_ins,\n  simp [h] at in_ins,\n  cases in_ins,\n  right,\n  simp,\n  left,\n  exact in_ins,\n  cases xs_ih in_ins,\n  left,\n  exact h_1,\n  right,\n  simp,\n  right,\n  exact h_1,\n  intro h,\n  induction xs,\n  simp [ord_insert],\n  cases h,\n  exact h,\n  exfalso,\n  exact list.not_mem_nil x h,\n  simp [ord_insert],\n  by_cases h_1: y \u2264 xs_hd,\n  simp [h_1],\n  exact h,\n  simp [h_1],\n  cases h,\n  right,\n  exact xs_ih (or.inl h),\n  cases h,\n  left,\n  exact h,\n  right,\n  exact xs_ih (or.inr h),\nend\n\ntheorem ord_insert_spec\n  {t: Type}\n  [has_le t]\n  [@decidable_rel t has_le.le]\n  [is_trans t has_le.le]\n  [is_total t has_le.le]\n  (x: t) (xs: list t):\n  sorted xs -> sorted (ord_insert x xs) :=\nbegin\n  intro h,\n  induction h,\n  simp [ord_insert],\n  exact pairwise.cons (list.ball_nil (fun y, x \u2264 y)) (pairwise.nil (\u2264)),\n  simp [ord_insert],\n  by_cases x \u2264 h_x,\n  simp [h],\n  let a: sorted (h_x :: h_xs) := pairwise.cons h_a h_a_1,\n  let b: \u2200 (a: t), a \u2208 h_x :: h_xs -> x \u2264 a := fun a, fun b,\n    or.elim b\n    (fun b, begin rw b, exact h end)\n    (fun b, trans h (h_a a b)),\n  exact pairwise.cons b a,\n  simp [h],\n  let b: \u2200 (a: t), a \u2208 ord_insert x h_xs -> h_x \u2264 a := fun a, fun b,\n  begin\n    cases iff.elim_left ord_insert_mem b,\n    rw h_1,\n    cases is_total.total (\u2264) x h_x,\n    exfalso,\n    exact h h_2,\n    exact h_2,\n    exact h_a a h_1,\n  end,\n  exact pairwise.cons b h_ih,\nend\n\ntheorem ord_insert_pred {t: Type} {p: t -> Prop} {xs: list t} {x: t}\n  [has_le t] [@decidable_rel t has_le.le]:\n  (\u2200 (y \u2208 xs), p y) ->\n  p x ->\n  (\u2200 (y \u2208 ord_insert x xs), p y) :=\nbegin\n  intros in_xs r_xx y in_insert,\n  induction xs,\n  simp [ord_insert] at in_insert,\n  rw in_insert,\n  exact r_xx,\n  simp [ord_insert] at in_insert,\n  by_cases x \u2264 xs_hd,\n  simp [h] at in_insert,\n  cases in_insert,\n  rw in_insert,\n  exact r_xx,\n  cases in_insert,\n  rw in_insert,\n  exact in_xs xs_hd (or.inl rfl),\n  exact in_xs y (or.inr in_insert),\n  simp [h] at in_insert,\n  cases in_insert,\n  rw in_insert,\n  exact in_xs xs_hd (or.inl rfl),\n  let in_xs' := fun y, fun h, in_xs y (or.inr h),\n  exact xs_ih in_xs' in_insert,\nend\n\ntheorem ord_insert_pairwise {t: Type} {r: t -> t -> Prop} {xs: list t} {x: t}\n  [is_symm t r] [has_le t] [@decidable_rel t has_le.le]:\n  (\u2200 (y \u2208 xs), r x y) ->\n  pairwise r xs ->\n  pairwise r (ord_insert x xs) :=\nbegin\n  intros in_xs pw_xs,\n  induction pw_xs,\n  simp [ord_insert],\n  exact pairwise.cons (list.ball_nil (fun y, r x y)) (pairwise.nil r),\n  simp [ord_insert],\n  by_cases x \u2264 pw_xs_x,\n  simp [h],\n  let a := pairwise.cons pw_xs_a pw_xs_a_1,\n  exact pairwise.cons in_xs a,\n  simp [h],\n  let in_xs' := fun y, fun h, in_xs y (or.inr h),\n  let a := pw_xs_ih in_xs',\n  let b := in_xs pw_xs_x (or.inl rfl),\n  let c := ord_insert_pred pw_xs_a (symm b),\n  exact pairwise.cons c a,\nend\n\ntheorem insertion_sort_spec\n  {t: Type}\n  [has_le t]\n  [@decidable_rel t has_le.le]\n  [is_trans t has_le.le]\n  [is_total t has_le.le]\n  (xs: list t):\n  sorted (insertion_sort xs) :=\nbegin\n  induction xs,\n  simp [insertion_sort],\n  exact pairwise.nil (\u2264),\n  simp [insertion_sort],\n  exact ord_insert_spec xs_hd (insertion_sort xs_tl) xs_ih,\nend\n\ntheorem insertion_sort_pred {t: Type} {p: t -> Prop} {xs: list t}\n  [has_le t] [@decidable_rel t has_le.le]:\n  (\u2200 (y \u2208 xs), p y) ->\n  (\u2200 (y \u2208 insertion_sort xs), p y) :=\nbegin\n  intros in_xs y in_sort,\n  induction xs,\n  simp [insertion_sort] at in_sort,\n  exfalso,\n  exact in_sort,\n  simp [insertion_sort] at in_sort,\n  cases iff.elim_left ord_insert_mem in_sort,\n  rw h,\n  exact in_xs xs_hd (or.inl rfl),\n  let in_xs' := fun y, fun h, in_xs y (or.inr h),\n  exact xs_ih in_xs' h,\nend\n\ntheorem insertion_sort_pairwise {t: Type} {r: t -> t -> Prop} {xs: list t}\n  [is_symm t r] [has_le t] [@decidable_rel t has_le.le]:\n  pairwise r xs ->\n  pairwise r (insertion_sort xs) :=\nbegin\n  intro h,\n  induction h,\n  simp [insertion_sort],\n  exact pairwise.nil r,\n  simp [insertion_sort],\n  let a := insertion_sort_pred h_a,\n  simp at a,\n  exact ord_insert_pairwise a h_ih,\nend\n\ntheorem insertion_sort_mem {t: Type} {xs: list t} {x: t}\n  [has_le t] [@decidable_rel t has_le.le]:\n  x \u2208 xs \u2194 x \u2208 insertion_sort xs :=\nbegin\n  split,\n  intro x_in,\n  induction xs,\n  exfalso,\n  exact list.not_mem_nil x x_in,\n  simp [insertion_sort],\n  cases x_in,\n  exact iff.elim_right ord_insert_mem (or.inl x_in),\n  exact iff.elim_right ord_insert_mem (or.inr (xs_ih x_in)),\n  intro x_in,\n  induction xs,\n  simp [insertion_sort] at x_in,\n  exfalso,\n  exact x_in,\n  simp [insertion_sort] at x_in,\n  cases iff.elim_left ord_insert_mem x_in,\n  left,\n  exact h,\n  right,\n  exact xs_ih h,\nend\n\ntheorem sorted_ne_eq {t: Type} {xs ys: list t} [decidable_linear_order t]:\n  (\u2200 (x: t), x \u2208 xs \u2194 x \u2208 ys) ->\n  pairwise ne xs ->\n  pairwise ne ys ->\n  sorted xs ->\n  sorted ys ->\n  xs = ys :=\nbegin\n  intros x_in p_xs p_ys s_xs s_ys,\n  induction xs generalizing ys,\n  exact symm (iff.elim_left nothing_mem_nil (fun x xi,\n    list.not_mem_nil x (iff.elim_right (x_in x) xi))),\n  cases ys,\n  exfalso,\n  exact list.not_mem_nil xs_hd (iff.elim_left (x_in xs_hd) (or.inl rfl)),\n  cases p_xs,\n  cases p_ys,\n  cases s_xs,\n  cases s_ys,\n  cases iff.elim_left (x_in xs_hd) (or.inl rfl),\n  let x_in': \u2200 (x: t), x \u2208 xs_tl \u2194 x \u2208 ys_tl := begin\n    intro x,\n    split,\n    intro xi,\n    cases iff.elim_left (x_in x) (or.inr xi),\n    rw symm h_1 at h,\n    exfalso,\n    exact p_xs_a x xi h,\n    exact h_1,\n    intro xi,\n    cases iff.elim_right (x_in x) (or.inr xi),\n    rw symm h_1 at h,\n    exfalso,\n    exact p_ys_a x xi (symm h),\n    exact h_1,\n  end,\n  let a := xs_ih p_xs_a_1 s_xs_a_1 x_in' p_ys_a_1 s_ys_a_1,\n  rw h,\n  rw a,\n  cases iff.elim_right (x_in ys_hd) (or.inl rfl),\n  exfalso,\n  exact p_ys_a xs_hd h h_1,\n  let a := s_ys_a xs_hd h,\n  let b := s_xs_a ys_hd h_1,\n  exfalso,\n  exact p_ys_a xs_hd h (le_antisymm a b),\nend\n", "meta": {"author": "azdavis", "repo": "hatsugen", "sha": "a18f70f9ea4ce30c0baf0c40748aad5ccd176c60", "save_path": "github-repos/lean/azdavis-hatsugen", "path": "github-repos/lean/azdavis-hatsugen/hatsugen-a18f70f9ea4ce30c0baf0c40748aad5ccd176c60/src/util/list/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199754937771, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7051299780208916}}
{"text": "/-\nCopyright (c) 2021 Eric Rodriguez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Rodriguez\n\n! This file was ported from Lean 3 source module algebra.ne_zero\n! leanprover-community/mathlib commit f340f229b1f461aa1c8ee11e0a172d0a3b301a4a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\n\nimport Mathlib.Logic.Basic\nimport Mathlib.Init.ZeroOne\nimport Mathlib.Init.Algebra.Order\n\n/-!\n# `NeZero` typeclass\n\nWe create a typeclass `NeZero n` which carries around the fact that `(n : R) \u2260 0`.\n\n## Main declarations\n\n* `NeZero`: `n \u2260 0` as a typeclass.\n-/\n\n/-- A type-class version of `n \u2260 0`.  -/\nclass NeZero {R} [Zero R] (n : R) : Prop where\n  /-- The proposition that `n` is not zero. -/\n  out : n \u2260 0\n#align ne_zero NeZero\n\ntheorem NeZero.ne {R} [Zero R] (n : R) [h : NeZero n] : n \u2260 0 :=\n  h.out\n#align ne_zero.ne NeZero.ne\n\ntheorem NeZero.ne' {R} [Zero R] (n : R) [h : NeZero n] : 0 \u2260 n :=\n  h.out.symm\n#align ne_zero.ne' NeZero.ne'\n\ntheorem neZero_iff {R : Type _} [Zero R] {n : R} : NeZero n \u2194 n \u2260 0 :=\n  \u27e8fun h \u21a6 h.out, NeZero.mk\u27e9\n#align ne_zero_iff neZero_iff\n\ntheorem not_neZero {R : Type _} [Zero R] {n : R} : \u00acNeZero n \u2194 n = 0 := by simp [neZero_iff]\n#align not_ne_zero not_neZero\n\ntheorem eq_zero_or_neZero {\u03b1} [Zero \u03b1] (a : \u03b1) : a = 0 \u2228 NeZero a :=\n  (eq_or_ne a 0).imp_right NeZero.mk\n#align eq_zero_or_ne_zero eq_zero_or_neZero\n\nsection\nvariable {\u03b1 : Type _} [Zero \u03b1]\n\n@[simp] lemma zero_ne_one [One \u03b1] [NeZero (1 : \u03b1)] : (0 : \u03b1) \u2260 1 := NeZero.ne' (1 : \u03b1)\n@[simp] lemma one_ne_zero [One \u03b1] [NeZero (1 : \u03b1)] : (1 : \u03b1) \u2260 0 := NeZero.ne (1 : \u03b1)\n#align one_ne_zero one_ne_zero\n#align zero_ne_one zero_ne_one\n\nlemma ne_zero_of_eq_one [One \u03b1] [NeZero (1 : \u03b1)] {a : \u03b1} (h : a = 1) : a \u2260 0 := h \u25b8 one_ne_zero\n#align ne_zero_of_eq_one ne_zero_of_eq_one\n\nlemma two_ne_zero [OfNat \u03b1 2] [NeZero (2 : \u03b1)] : (2 : \u03b1) \u2260 0 := NeZero.ne (2 : \u03b1)\nlemma three_ne_zero [OfNat \u03b1 3] [NeZero (3 : \u03b1)] : (3 : \u03b1) \u2260 0 := NeZero.ne (3 : \u03b1)\nlemma four_ne_zero [OfNat \u03b1 4] [NeZero (4 : \u03b1)] : (4 : \u03b1) \u2260 0 := NeZero.ne (4 : \u03b1)\n#align four_ne_zero four_ne_zero\n#align three_ne_zero three_ne_zero\n#align two_ne_zero two_ne_zero\n\nvariable (\u03b1)\n\nlemma zero_ne_one' [One \u03b1] [NeZero (1 : \u03b1)] : (0 : \u03b1) \u2260 1 := zero_ne_one\nlemma one_ne_zero' [One \u03b1] [NeZero (1 : \u03b1)] : (1 : \u03b1) \u2260 0 := one_ne_zero\nlemma two_ne_zero' [OfNat \u03b1 2] [NeZero (2 : \u03b1)] : (2 : \u03b1) \u2260 0 := two_ne_zero\nlemma three_ne_zero' [OfNat \u03b1 3] [NeZero (3 : \u03b1)] : (3 : \u03b1) \u2260 0 := three_ne_zero\nlemma four_ne_zero' [OfNat \u03b1 4] [NeZero (4 : \u03b1)] : (4 : \u03b1) \u2260 0 := four_ne_zero\n#align four_ne_zero' four_ne_zero'\n#align three_ne_zero' three_ne_zero'\n#align two_ne_zero' two_ne_zero'\n#align one_ne_zero' one_ne_zero'\n#align zero_ne_one' zero_ne_one'\n\nend\n\nnamespace NeZero\n\nvariable {M : Type _} {x : M}\n\ninstance succ : NeZero (n + 1) := \u27e8n.succ_ne_zero\u27e9\n\ntheorem of_pos [Preorder M] [Zero M] (h : 0 < x) : NeZero x := \u27e8ne_of_gt h\u27e9\n#align ne_zero.of_pos NeZero.of_pos\n\nend NeZero\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/NeZero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7051299778441311}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, R\u00e9my Degenne\n-/\nimport algebra.order.group\nimport order.rel_iso\n\n/-!\n# Intervals\n\nIn any preorder `\u03b1`, we define intervals (which on each side can be either infinite, open, or\nclosed) using the following naming conventions:\n- `i`: infinite\n- `o`: open\n- `c`: closed\n\nEach interval has the name `I` + letter for left side + letter for right side. For instance,\n`Ioc a b` denotes the inverval `(a, b]`.\n\nThis file contains these definitions, and basic facts on inclusion, intersection, difference of\nintervals (where the precise statements may depend on the properties of the order, in particular\nfor some statements it should be `linear_order` or `densely_ordered`).\n\nTODO: This is just the beginning; a lot of rules are missing\n-/\n\nuniverse u\n\nnamespace set\n\nopen set\nopen order_dual (to_dual of_dual)\n\nsection preorder\nvariables {\u03b1 : Type u} [preorder \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c x : \u03b1}\n\n/-- Left-open right-open interval -/\ndef Ioo (a b : \u03b1) := {x | a < x \u2227 x < b}\n\n/-- Left-closed right-open interval -/\ndef Ico (a b : \u03b1) := {x | a \u2264 x \u2227 x < b}\n\n/-- Left-infinite right-open interval -/\ndef Iio (a : \u03b1) := {x | x < a}\n\n/-- Left-closed right-closed interval -/\ndef Icc (a b : \u03b1) := {x | a \u2264 x \u2227 x \u2264 b}\n\n/-- Left-infinite right-closed interval -/\ndef Iic (b : \u03b1) := {x | x \u2264 b}\n\n/-- Left-open right-closed interval -/\ndef Ioc (a b : \u03b1) := {x | a < x \u2227 x \u2264 b}\n\n/-- Left-closed right-infinite interval -/\ndef Ici (a : \u03b1) := {x | a \u2264 x}\n\n/-- Left-open right-infinite interval -/\ndef Ioi (a : \u03b1) := {x | a < x}\n\nlemma Ioo_def (a b : \u03b1) : {x | a < x \u2227 x < b} = Ioo a b := rfl\n\nlemma Ico_def (a b : \u03b1) : {x | a \u2264 x \u2227 x < b} = Ico a b := rfl\n\nlemma Iio_def (a : \u03b1) : {x | x < a} = Iio a := rfl\n\nlemma Icc_def (a b : \u03b1) : {x | a \u2264 x \u2227 x \u2264 b} = Icc a b := rfl\n\nlemma Iic_def (b : \u03b1) : {x | x \u2264 b} = Iic b := rfl\n\nlemma Ioc_def (a b : \u03b1) : {x | a < x \u2227 x \u2264 b} = Ioc a b := rfl\n\nlemma Ici_def (a : \u03b1) : {x | a \u2264 x} = Ici a := rfl\n\nlemma Ioi_def (a : \u03b1) : {x | a < x} = Ioi a := rfl\n\n@[simp] lemma mem_Ioo : x \u2208 Ioo a b \u2194 a < x \u2227 x < b := iff.rfl\n@[simp] lemma mem_Ico : x \u2208 Ico a b \u2194 a \u2264 x \u2227 x < b := iff.rfl\n@[simp] lemma mem_Iio : x \u2208 Iio b \u2194 x < b := iff.rfl\n@[simp] lemma mem_Icc : x \u2208 Icc a b \u2194 a \u2264 x \u2227 x \u2264 b := iff.rfl\n@[simp] lemma mem_Iic : x \u2208 Iic b \u2194 x \u2264 b := iff.rfl\n@[simp] lemma mem_Ioc : x \u2208 Ioc a b \u2194 a < x \u2227 x \u2264 b := iff.rfl\n@[simp] lemma mem_Ici : x \u2208 Ici a \u2194 a \u2264 x := iff.rfl\n@[simp] lemma mem_Ioi : x \u2208 Ioi a \u2194 a < x := iff.rfl\n\n@[simp] lemma left_mem_Ioo : a \u2208 Ioo a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma left_mem_Ico : a \u2208 Ico a b \u2194 a < b := by simp [le_refl]\n@[simp] lemma left_mem_Icc : a \u2208 Icc a b \u2194 a \u2264 b := by simp [le_refl]\n@[simp] lemma left_mem_Ioc : a \u2208 Ioc a b \u2194 false := by simp [lt_irrefl]\nlemma left_mem_Ici : a \u2208 Ici a := by simp\n@[simp] lemma right_mem_Ioo : b \u2208 Ioo a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma right_mem_Ico : b \u2208 Ico a b \u2194 false := by simp [lt_irrefl]\n@[simp] lemma right_mem_Icc : b \u2208 Icc a b \u2194 a \u2264 b := by simp [le_refl]\n@[simp] lemma right_mem_Ioc : b \u2208 Ioc a b \u2194 a < b := by simp [le_refl]\nlemma right_mem_Iic : a \u2208 Iic a := by simp\n\n@[simp] lemma dual_Ici : Ici (to_dual a) = of_dual \u207b\u00b9' Iic a := rfl\n@[simp] lemma dual_Iic : Iic (to_dual a) = of_dual \u207b\u00b9' Ici a := rfl\n@[simp] lemma dual_Ioi : Ioi (to_dual a) = of_dual \u207b\u00b9' Iio a := rfl\n@[simp] lemma dual_Iio : Iio (to_dual a) = of_dual \u207b\u00b9' Ioi a := rfl\n@[simp] lemma dual_Icc : Icc (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Icc b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ioc : Ioc (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ico b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ico : Ico (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ioc b a :=\nset.ext $ \u03bb x, and_comm _ _\n@[simp] lemma dual_Ioo : Ioo (to_dual a) (to_dual b) = of_dual \u207b\u00b9' Ioo b a :=\nset.ext $ \u03bb x, and_comm _ _\n\n@[simp] lemma nonempty_Icc : (Icc a b).nonempty \u2194 a \u2264 b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans hx.2, \u03bb h, \u27e8a, left_mem_Icc.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ico : (Ico a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans_lt hx.2, \u03bb h, \u27e8a, left_mem_Ico.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ioc : (Ioc a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, hx\u27e9, hx.1.trans_le hx.2, \u03bb h, \u27e8b, right_mem_Ioc.2 h\u27e9\u27e9\n\n@[simp] lemma nonempty_Ici : (Ici a).nonempty := \u27e8a, left_mem_Ici\u27e9\n\n@[simp] lemma nonempty_Iic : (Iic a).nonempty := \u27e8a, right_mem_Iic\u27e9\n\n@[simp] lemma nonempty_Ioo [densely_ordered \u03b1] : (Ioo a b).nonempty \u2194 a < b :=\n\u27e8\u03bb \u27e8x, ha, hb\u27e9, ha.trans hb, exists_between\u27e9\n\n@[simp] lemma nonempty_Ioi [no_max_order \u03b1] : (Ioi a).nonempty := exists_gt a\n@[simp] lemma nonempty_Iio [no_min_order \u03b1] : (Iio a).nonempty := exists_lt a\n\nlemma nonempty_Icc_subtype (h : a \u2264 b) : nonempty (Icc a b) :=\nnonempty.to_subtype (nonempty_Icc.mpr h)\n\nlemma nonempty_Ico_subtype (h : a < b) : nonempty (Ico a b) :=\nnonempty.to_subtype (nonempty_Ico.mpr h)\n\nlemma nonempty_Ioc_subtype (h : a < b) : nonempty (Ioc a b) :=\nnonempty.to_subtype (nonempty_Ioc.mpr h)\n\n/-- An interval `Ici a` is nonempty. -/\ninstance nonempty_Ici_subtype : nonempty (Ici a) :=\nnonempty.to_subtype nonempty_Ici\n\n/-- An interval `Iic a` is nonempty. -/\ninstance nonempty_Iic_subtype : nonempty (Iic a) :=\nnonempty.to_subtype nonempty_Iic\n\nlemma nonempty_Ioo_subtype [densely_ordered \u03b1] (h : a < b) : nonempty (Ioo a b) :=\nnonempty.to_subtype (nonempty_Ioo.mpr h)\n\n/-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/\ninstance nonempty_Ioi_subtype [no_max_order \u03b1] : nonempty (Ioi a) :=\nnonempty.to_subtype nonempty_Ioi\n\n/-- In an order without minimal elements, the intervals `Iio` are nonempty. -/\ninstance nonempty_Iio_subtype [no_min_order \u03b1] : nonempty (Iio a) :=\nnonempty.to_subtype nonempty_Iio\n\n@[simp] lemma Icc_eq_empty (h : \u00aca \u2264 b) : Icc a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans hb)\n\n@[simp] lemma Ico_eq_empty (h : \u00aca < b) : Ico a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans_lt hb)\n\n@[simp] lemma Ioc_eq_empty (h : \u00aca < b) : Ioc a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9, h (ha.trans_le hb)\n\n@[simp] lemma Ioo_eq_empty (h : \u00aca < b) : Ioo a b = \u2205 :=\neq_empty_iff_forall_not_mem.2 $ \u03bb x \u27e8ha, hb\u27e9,  h (ha.trans hb)\n\n@[simp] lemma Icc_eq_empty_of_lt (h : b < a) : Icc a b = \u2205 :=\nIcc_eq_empty h.not_le\n\n@[simp] lemma Ico_eq_empty_of_le (h : b \u2264 a) : Ico a b = \u2205 :=\nIco_eq_empty h.not_lt\n\n@[simp] lemma Ioc_eq_empty_of_le (h : b \u2264 a) : Ioc a b = \u2205 :=\nIoc_eq_empty h.not_lt\n\n@[simp] lemma Ioo_eq_empty_of_le (h : b \u2264 a) : Ioo a b = \u2205 :=\nIoo_eq_empty h.not_lt\n\n@[simp] lemma Ico_self (a : \u03b1) : Ico a a = \u2205 := Ico_eq_empty $ lt_irrefl _\n@[simp] lemma Ioc_self (a : \u03b1) : Ioc a a = \u2205 := Ioc_eq_empty $ lt_irrefl _\n@[simp] lemma Ioo_self (a : \u03b1) : Ioo a a = \u2205 := Ioo_eq_empty $ lt_irrefl _\n\nlemma Ici_subset_Ici : Ici a \u2286 Ici b \u2194 b \u2264 a :=\n\u27e8\u03bb h, h $ left_mem_Ici, \u03bb h x hx, h.trans hx\u27e9\n\nlemma Iic_subset_Iic : Iic a \u2286 Iic b \u2194 a \u2264 b :=\n@Ici_subset_Ici (order_dual \u03b1) _ _ _\n\nlemma Ici_subset_Ioi : Ici a \u2286 Ioi b \u2194 b < a :=\n\u27e8\u03bb h, h left_mem_Ici, \u03bb h x hx, h.trans_le hx\u27e9\n\nlemma Iic_subset_Iio : Iic a \u2286 Iio b \u2194 a < b :=\n\u27e8\u03bb h, h right_mem_Iic, \u03bb h x hx, lt_of_le_of_lt hx h\u27e9\n\nlemma Ioo_subset_Ioo (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ioo a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans_lt hx\u2081, hx\u2082.trans_le h\u2082\u27e9\n\nlemma Ioo_subset_Ioo_left (h : a\u2081 \u2264 a\u2082) : Ioo a\u2082 b \u2286 Ioo a\u2081 b :=\nIoo_subset_Ioo h le_rfl\n\nlemma Ioo_subset_Ioo_right (h : b\u2081 \u2264 b\u2082) : Ioo a b\u2081 \u2286 Ioo a b\u2082 :=\nIoo_subset_Ioo le_rfl h\n\nlemma Ico_subset_Ico (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ico a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans hx\u2081, hx\u2082.trans_le h\u2082\u27e9\n\nlemma Ico_subset_Ico_left (h : a\u2081 \u2264 a\u2082) : Ico a\u2082 b \u2286 Ico a\u2081 b :=\nIco_subset_Ico h le_rfl\n\nlemma Ico_subset_Ico_right (h : b\u2081 \u2264 b\u2082) : Ico a b\u2081 \u2286 Ico a b\u2082 :=\nIco_subset_Ico le_rfl h\n\nlemma Icc_subset_Icc (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Icc a\u2081 b\u2081 \u2286 Icc a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans hx\u2081, le_trans hx\u2082 h\u2082\u27e9\n\nlemma Icc_subset_Icc_left (h : a\u2081 \u2264 a\u2082) : Icc a\u2082 b \u2286 Icc a\u2081 b :=\nIcc_subset_Icc h le_rfl\n\nlemma Icc_subset_Icc_right (h : b\u2081 \u2264 b\u2082) : Icc a b\u2081 \u2286 Icc a b\u2082 :=\nIcc_subset_Icc le_rfl h\n\nlemma Icc_subset_Ioo (ha : a\u2082 < a\u2081) (hb : b\u2081 < b\u2082) :\n  Icc a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 :=\n\u03bb x hx, \u27e8ha.trans_le hx.1, hx.2.trans_lt hb\u27e9\n\nlemma Icc_subset_Ici_self : Icc a b \u2286 Ici a := \u03bb x, and.left\n\nlemma Icc_subset_Iic_self : Icc a b \u2286 Iic b := \u03bb x, and.right\n\nlemma Ioc_subset_Iic_self : Ioc a b \u2286 Iic b := \u03bb x, and.right\n\nlemma Ioc_subset_Ioc (h\u2081 : a\u2082 \u2264 a\u2081) (h\u2082 : b\u2081 \u2264 b\u2082) :\n  Ioc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 :=\n\u03bb x \u27e8hx\u2081, hx\u2082\u27e9, \u27e8h\u2081.trans_lt hx\u2081, hx\u2082.trans h\u2082\u27e9\n\nlemma Ioc_subset_Ioc_left (h : a\u2081 \u2264 a\u2082) : Ioc a\u2082 b \u2286 Ioc a\u2081 b :=\nIoc_subset_Ioc h le_rfl\n\nlemma Ioc_subset_Ioc_right (h : b\u2081 \u2264 b\u2082) : Ioc a b\u2081 \u2286 Ioc a b\u2082 :=\nIoc_subset_Ioc le_rfl h\n\nlemma Ico_subset_Ioo_left (h\u2081 : a\u2081 < a\u2082) : Ico a\u2082 b \u2286 Ioo a\u2081 b :=\n\u03bb x, and.imp_left h\u2081.trans_le\n\nlemma Ioc_subset_Ioo_right (h : b\u2081 < b\u2082) : Ioc a b\u2081 \u2286 Ioo a b\u2082 :=\n\u03bb x, and.imp_right $ \u03bb h', h'.trans_lt h\n\nlemma Icc_subset_Ico_right (h\u2081 : b\u2081 < b\u2082) : Icc a b\u2081 \u2286 Ico a b\u2082 :=\n\u03bb x, and.imp_right $ \u03bb h\u2082, h\u2082.trans_lt h\u2081\n\nlemma Ioo_subset_Ico_self : Ioo a b \u2286 Ico a b := \u03bb x, and.imp_left le_of_lt\n\nlemma Ioo_subset_Ioc_self : Ioo a b \u2286 Ioc a b := \u03bb x, and.imp_right le_of_lt\n\nlemma Ico_subset_Icc_self : Ico a b \u2286 Icc a b := \u03bb x, and.imp_right le_of_lt\n\nlemma Ioc_subset_Icc_self : Ioc a b \u2286 Icc a b := \u03bb x, and.imp_left le_of_lt\n\nlemma Ioo_subset_Icc_self : Ioo a b \u2286 Icc a b :=\nsubset.trans Ioo_subset_Ico_self Ico_subset_Icc_self\n\nlemma Ico_subset_Iio_self : Ico a b \u2286 Iio b := \u03bb x, and.right\n\nlemma Ioo_subset_Iio_self : Ioo a b \u2286 Iio b := \u03bb x, and.right\n\nlemma Ioc_subset_Ioi_self : Ioc a b \u2286 Ioi a := \u03bb x, and.left\n\nlemma Ioo_subset_Ioi_self : Ioo a b \u2286 Ioi a := \u03bb x, and.left\n\nlemma Ioi_subset_Ici_self : Ioi a \u2286 Ici a := \u03bb x hx, le_of_lt hx\n\nlemma Iio_subset_Iic_self : Iio a \u2286 Iic a := \u03bb x hx, le_of_lt hx\n\nlemma Ico_subset_Ici_self : Ico a b \u2286 Ici a := \u03bb x, and.left\n\nlemma Icc_subset_Icc_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Icc a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans hx, hx'.trans h'\u27e9\u27e9\n\nlemma Icc_subset_Ioo_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 \u2194 a\u2082 < a\u2081 \u2227 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans_le hx, hx'.trans_lt h'\u27e9\u27e9\n\nlemma Icc_subset_Ico_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans hx, hx'.trans_lt h'\u27e9\u27e9\n\nlemma Icc_subset_Ioc_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 \u2194 a\u2082 < a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, \u27e8(h \u27e8le_rfl, h\u2081\u27e9).1, (h \u27e8h\u2081, le_rfl\u27e9).2\u27e9,\n \u03bb \u27e8h, h'\u27e9 x \u27e8hx, hx'\u27e9, \u27e8h.trans_le hx, hx'.trans h'\u27e9\u27e9\n\nlemma Icc_subset_Iio_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Iio b\u2082 \u2194 b\u2081 < b\u2082 :=\n\u27e8\u03bb h, h \u27e8h\u2081, le_rfl\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, hx'.trans_lt h\u27e9\n\nlemma Icc_subset_Ioi_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ioi a\u2082 \u2194 a\u2082 < a\u2081 :=\n\u27e8\u03bb h, h \u27e8le_rfl, h\u2081\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, h.trans_le hx\u27e9\n\nlemma Icc_subset_Iic_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Iic b\u2082 \u2194 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, h \u27e8h\u2081, le_rfl\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, hx'.trans h\u27e9\n\nlemma Icc_subset_Ici_iff (h\u2081 : a\u2081 \u2264 b\u2081) :\n  Icc a\u2081 b\u2081 \u2286 Ici a\u2082 \u2194 a\u2082 \u2264 a\u2081 :=\n\u27e8\u03bb h, h \u27e8le_rfl, h\u2081\u27e9, \u03bb h x \u27e8hx, hx'\u27e9, h.trans hx\u27e9\n\nlemma Icc_ssubset_Icc_left (hI : a\u2082 \u2264 b\u2082) (ha : a\u2082 < a\u2081) (hb : b\u2081 \u2264 b\u2082) :\n  Icc a\u2081 b\u2081 \u2282 Icc a\u2082 b\u2082 :=\n(ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr\n  \u27e8a\u2082, left_mem_Icc.mpr hI, not_and.mpr (\u03bb f g, lt_irrefl a\u2082 (ha.trans_le f))\u27e9\n\nlemma Icc_ssubset_Icc_right (hI : a\u2082 \u2264 b\u2082) (ha : a\u2082 \u2264 a\u2081) (hb : b\u2081 < b\u2082) :\n  Icc a\u2081 b\u2081 \u2282 Icc a\u2082 b\u2082 :=\n(ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr\n  \u27e8b\u2082, right_mem_Icc.mpr hI, (\u03bb f, lt_irrefl b\u2081 (hb.trans_le f.2))\u27e9\n\n/-- If `a \u2264 b`, then `(b, +\u221e) \u2286 (a, +\u221e)`. In preorders, this is just an implication. If you need\nthe equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/\nlemma Ioi_subset_Ioi (h : a \u2264 b) : Ioi b \u2286 Ioi a :=\n\u03bb x hx, h.trans_lt hx\n\n/-- If `a \u2264 b`, then `(b, +\u221e) \u2286 [a, +\u221e)`. In preorders, this is just an implication. If you need\nthe equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/\nlemma Ioi_subset_Ici (h : a \u2264 b) : Ioi b \u2286 Ici a :=\nsubset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self\n\n/-- If `a \u2264 b`, then `(-\u221e, a) \u2286 (-\u221e, b)`. In preorders, this is just an implication. If you need\nthe equivalence in linear orders, use `Iio_subset_Iio_iff`. -/\nlemma Iio_subset_Iio (h : a \u2264 b) : Iio a \u2286 Iio b :=\n\u03bb x hx, lt_of_lt_of_le hx h\n\n/-- If `a \u2264 b`, then `(-\u221e, a) \u2286 (-\u221e, b]`. In preorders, this is just an implication. If you need\nthe equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/\nlemma Iio_subset_Iic (h : a \u2264 b) : Iio a \u2286 Iic b :=\nsubset.trans (Iio_subset_Iio h) Iio_subset_Iic_self\n\nlemma Ici_inter_Iic : Ici a \u2229 Iic b = Icc a b := rfl\nlemma Ici_inter_Iio : Ici a \u2229 Iio b = Ico a b := rfl\nlemma Ioi_inter_Iic : Ioi a \u2229 Iic b = Ioc a b := rfl\nlemma Ioi_inter_Iio : Ioi a \u2229 Iio b = Ioo a b := rfl\n\nlemma mem_Icc_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Icc a b := Ioo_subset_Icc_self h\nlemma mem_Ico_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Ico a b := Ioo_subset_Ico_self h\nlemma mem_Ioc_of_Ioo (h : x \u2208 Ioo a b) : x \u2208 Ioc a b := Ioo_subset_Ioc_self h\nlemma mem_Icc_of_Ico (h : x \u2208 Ico a b) : x \u2208 Icc a b := Ico_subset_Icc_self h\nlemma mem_Icc_of_Ioc (h : x \u2208 Ioc a b) : x \u2208 Icc a b := Ioc_subset_Icc_self h\nlemma mem_Ici_of_Ioi (h : x \u2208 Ioi a) : x \u2208 Ici a := Ioi_subset_Ici_self h\nlemma mem_Iic_of_Iio (h : x \u2208 Iio a) : x \u2208 Iic a := Iio_subset_Iic_self h\n\nlemma Icc_eq_empty_iff : Icc a b = \u2205 \u2194 \u00aca \u2264 b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc]\n\nlemma Ico_eq_empty_iff : Ico a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico]\n\nlemma Ioc_eq_empty_iff : Ioc a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc]\n\nlemma Ioo_eq_empty_iff [densely_ordered \u03b1] : Ioo a b = \u2205 \u2194 \u00aca < b :=\nby rw [\u2190not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo]\n\nlemma _root_.is_top.Iic_eq (h : is_top a) : Iic a = univ := eq_univ_of_forall h\nlemma _root_.is_bot.Ici_eq (h : is_bot a) : Ici a = univ := eq_univ_of_forall h\nlemma _root_.is_max.Ioi_eq (h : is_max a) : Ioi a = \u2205 := eq_empty_of_subset_empty $ \u03bb b, h.not_lt\nlemma _root_.is_min.Iio_eq (h : is_min a) : Iio a = \u2205 := eq_empty_of_subset_empty $ \u03bb b, h.not_lt\n\nlemma Iic_inter_Ioc_of_le (h : a \u2264 c) : Iic a \u2229 Ioc b c = Ioc b a :=\next $ \u03bb x, \u27e8\u03bb H, \u27e8H.2.1, H.1\u27e9, \u03bb H, \u27e8H.2, H.1, H.2.trans h\u27e9\u27e9\n\nend preorder\n\nsection partial_order\nvariables {\u03b1 : Type u} [partial_order \u03b1] {a b c : \u03b1}\n\n@[simp] lemma Icc_self (a : \u03b1) : Icc a a = {a} :=\nset.ext $ by simp [Icc, le_antisymm_iff, and_comm]\n\n@[simp] lemma Icc_eq_singleton_iff : Icc a b = {c} \u2194 a = c \u2227 b = c :=\nbegin\n  refine \u27e8\u03bb h, _, _\u27e9,\n  { have hab : a \u2264 b := nonempty_Icc.1 (h.symm.subst $ singleton_nonempty c),\n    exact \u27e8eq_of_mem_singleton $ h.subst $ left_mem_Icc.2 hab,\n      eq_of_mem_singleton $ h.subst $ right_mem_Icc.2 hab\u27e9 },\n  { rintro \u27e8rfl, rfl\u27e9,\n    exact Icc_self _ }\nend\n\n@[simp] lemma Icc_diff_left : Icc a b \\ {a} = Ioc a b :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, eq_comm, and.right_comm]\n\n@[simp] lemma Icc_diff_right : Icc a b \\ {b} = Ico a b :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, and_assoc]\n\n@[simp] lemma Ico_diff_left : Ico a b \\ {a} = Ioo a b :=\next $ \u03bb x, by simp [and.right_comm, \u2190 lt_iff_le_and_ne, eq_comm]\n\n@[simp] lemma Ioc_diff_right : Ioc a b \\ {b} = Ioo a b :=\next $ \u03bb x, by simp [and_assoc, \u2190 lt_iff_le_and_ne]\n\n@[simp] lemma Icc_diff_both : Icc a b \\ {a, b} = Ioo a b :=\nby rw [insert_eq, \u2190 diff_diff, Icc_diff_left, Ioc_diff_right]\n\n@[simp] lemma Ici_diff_left : Ici a \\ {a} = Ioi a :=\next $ \u03bb x, by simp [lt_iff_le_and_ne, eq_comm]\n\n@[simp] lemma Iic_diff_right : Iic a \\ {a} = Iio a :=\next $ \u03bb x, by simp [lt_iff_le_and_ne]\n\n@[simp] lemma Ico_diff_Ioo_same (h : a < b) : Ico a b \\ Ioo a b = {a} :=\nby rw [\u2190 Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 $ left_mem_Ico.2 h)]\n\n@[simp] lemma Ioc_diff_Ioo_same (h : a < b) : Ioc a b \\ Ioo a b = {b} :=\nby rw [\u2190 Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 $ right_mem_Ioc.2 h)]\n\n@[simp] lemma Icc_diff_Ico_same (h : a \u2264 b) : Icc a b \\ Ico a b = {b} :=\nby rw [\u2190 Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 $ right_mem_Icc.2 h)]\n\n@[simp] lemma Icc_diff_Ioc_same (h : a \u2264 b) : Icc a b \\ Ioc a b = {a} :=\nby rw [\u2190 Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 $ left_mem_Icc.2 h)]\n\n@[simp] lemma Icc_diff_Ioo_same (h : a \u2264 b) : Icc a b \\ Ioo a b = {a, b} :=\nby { rw [\u2190 Icc_diff_both, diff_diff_cancel_left], simp [insert_subset, h] }\n\n@[simp] lemma Ici_diff_Ioi_same : Ici a \\ Ioi a = {a} :=\nby rw [\u2190 Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)]\n\n@[simp] lemma Iic_diff_Iio_same : Iic a \\ Iio a = {a} :=\nby rw [\u2190 Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)]\n\n@[simp] lemma Ioi_union_left : Ioi a \u222a {a} = Ici a := ext $ \u03bb x, by simp [eq_comm, le_iff_eq_or_lt]\n\n@[simp] lemma Iio_union_right : Iio a \u222a {a} = Iic a := ext $ \u03bb x, le_iff_lt_or_eq.symm\n\nlemma Ioo_union_left (hab : a < b) : Ioo a b \u222a {a} = Ico a b :=\nby rw [\u2190 Ico_diff_left, diff_union_self,\n  union_eq_self_of_subset_right (singleton_subset_iff.2 $ left_mem_Ico.2 hab)]\n\nlemma Ioo_union_right (hab : a < b) : Ioo a b \u222a {b} = Ioc a b :=\nby simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual\n\nlemma Ioc_union_left (hab : a \u2264 b) : Ioc a b \u222a {a} = Icc a b :=\nby rw [\u2190 Icc_diff_left, diff_union_self,\n  union_eq_self_of_subset_right (singleton_subset_iff.2 $ left_mem_Icc.2 hab)]\n\nlemma Ico_union_right (hab : a \u2264 b) : Ico a b \u222a {b} = Icc a b :=\nby simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual\n\nlemma mem_Ici_Ioi_of_subset_of_subset {s : set \u03b1} (ho : Ioi a \u2286 s) (hc : s \u2286 Ici a) :\n  s \u2208 ({Ici a, Ioi a} : set (set \u03b1)) :=\nclassical.by_cases\n  (\u03bb h : a \u2208 s, or.inl $ subset.antisymm hc $ by rw [\u2190 Ioi_union_left, union_subset_iff]; simp *)\n  (\u03bb h, or.inr $ subset.antisymm (\u03bb x hx, lt_of_le_of_ne (hc hx) (\u03bb heq, h $ heq.symm \u25b8 hx)) ho)\n\nlemma mem_Iic_Iio_of_subset_of_subset {s : set \u03b1} (ho : Iio a \u2286 s) (hc : s \u2286 Iic a) :\n  s \u2208 ({Iic a, Iio a} : set (set \u03b1)) :=\n@mem_Ici_Ioi_of_subset_of_subset (order_dual \u03b1) _ a s ho hc\n\nlemma mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : set \u03b1} (ho : Ioo a b \u2286 s) (hc : s \u2286 Icc a b) :\n  s \u2208 ({Icc a b, Ico a b, Ioc a b, Ioo a b} : set (set \u03b1)) :=\nbegin\n  classical,\n  by_cases ha : a \u2208 s; by_cases hb : b \u2208 s,\n  { refine or.inl (subset.antisymm hc _),\n    rwa [\u2190 Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha,\n      \u2190 Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho },\n  { refine (or.inr $ or.inl $ subset.antisymm _ _),\n    { rw [\u2190 Icc_diff_right],\n      exact subset_diff_singleton hc hb },\n    { rwa [\u2190 Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho } },\n  { refine (or.inr $ or.inr $ or.inl $ subset.antisymm _ _),\n    { rw [\u2190 Icc_diff_left],\n      exact subset_diff_singleton hc ha },\n    { rwa [\u2190 Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho } },\n  { refine (or.inr $ or.inr $ or.inr $ subset.antisymm _ ho),\n    rw [\u2190 Ico_diff_left, \u2190 Icc_diff_right],\n    apply_rules [subset_diff_singleton] }\nend\n\nlemma eq_left_or_mem_Ioo_of_mem_Ico {x : \u03b1} (hmem : x \u2208 Ico a b) :\n  x = a \u2228 x \u2208 Ioo a b :=\nhmem.1.eq_or_gt.imp_right $ \u03bb h, \u27e8h, hmem.2\u27e9\n\nlemma eq_right_or_mem_Ioo_of_mem_Ioc {x : \u03b1} (hmem : x \u2208 Ioc a b) :\n  x = b \u2228 x \u2208 Ioo a b :=\nhmem.2.eq_or_lt.imp_right $ and.intro hmem.1\n\nlemma eq_endpoints_or_mem_Ioo_of_mem_Icc {x : \u03b1} (hmem : x \u2208 Icc a b) :\n  x = a \u2228 x = b \u2228 x \u2208 Ioo a b :=\nhmem.1.eq_or_gt.imp_right $ \u03bb h, eq_right_or_mem_Ioo_of_mem_Ioc \u27e8h, hmem.2\u27e9\n\nlemma _root_.is_max.Ici_eq (h : is_max a) : Ici a = {a} :=\neq_singleton_iff_unique_mem.2 \u27e8left_mem_Ici, \u03bb b, h.eq_of_ge\u27e9\n\nlemma _root_.is_min.Iic_eq (h : is_min a) : Iic a = {a} := h.to_dual.Ici_eq\n\nend partial_order\n\nsection order_top\n\n@[simp] lemma Ici_top {\u03b1 : Type u} [partial_order \u03b1] [order_top \u03b1] : Ici (\u22a4 : \u03b1) = {\u22a4} :=\nis_max_top.Ici_eq\n\nvariables {\u03b1 : Type u} [preorder \u03b1] [order_top \u03b1] {a : \u03b1}\n\n@[simp] lemma Ioi_top : Ioi (\u22a4 : \u03b1) = \u2205 := is_max_top.Ioi_eq\n@[simp] lemma Iic_top : Iic (\u22a4 : \u03b1) = univ := is_top_top.Iic_eq\n@[simp] lemma Icc_top : Icc a \u22a4 = Ici a := by simp [\u2190 Ici_inter_Iic]\n@[simp] lemma Ioc_top : Ioc a \u22a4 = Ioi a := by simp [\u2190 Ioi_inter_Iic]\n\nend order_top\n\nsection order_bot\n\n@[simp] lemma Iic_bot {\u03b1 : Type u} [partial_order \u03b1] [order_bot \u03b1] : Iic (\u22a5 : \u03b1) = {\u22a5} :=\nis_min_bot.Iic_eq\n\nvariables {\u03b1 : Type u} [preorder \u03b1] [order_bot \u03b1] {a : \u03b1}\n\n@[simp] lemma Iio_bot : Iio (\u22a5 : \u03b1) = \u2205 := is_min_bot.Iio_eq\n@[simp] lemma Ici_bot : Ici (\u22a5 : \u03b1) = univ := is_bot_bot.Ici_eq\n@[simp] lemma Icc_bot : Icc \u22a5 a = Iic a := by simp [\u2190 Ici_inter_Iic]\n@[simp] lemma Ico_bot : Ico \u22a5 a = Iio a := by simp [\u2190 Ici_inter_Iio]\n\nend order_bot\n\nsection linear_order\nvariables {\u03b1 : Type u} [linear_order \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c d : \u03b1}\n\nlemma not_mem_Ici : c \u2209 Ici a \u2194 c < a := not_le\n\nlemma not_mem_Iic : c \u2209 Iic b \u2194 b < c := not_le\n\nlemma not_mem_Icc_of_lt (ha : c < a) : c \u2209 Icc a b :=\nnot_mem_subset Icc_subset_Ici_self $ not_mem_Ici.mpr ha\n\nlemma not_mem_Icc_of_gt (hb : b < c) : c \u2209 Icc a b :=\nnot_mem_subset Icc_subset_Iic_self $ not_mem_Iic.mpr hb\n\nlemma not_mem_Ico_of_lt (ha : c < a) : c \u2209 Ico a b :=\nnot_mem_subset Ico_subset_Ici_self $ not_mem_Ici.mpr ha\n\nlemma not_mem_Ioc_of_gt (hb : b < c) : c \u2209 Ioc a b :=\nnot_mem_subset Ioc_subset_Iic_self $ not_mem_Iic.mpr hb\n\nlemma not_mem_Ioi : c \u2209 Ioi a \u2194 c \u2264 a := not_lt\n\nlemma not_mem_Iio : c \u2209 Iio b \u2194 b \u2264 c := not_lt\n\nlemma not_mem_Ioc_of_le (ha : c \u2264 a) : c \u2209 Ioc a b :=\nnot_mem_subset Ioc_subset_Ioi_self $ not_mem_Ioi.mpr ha\n\nlemma not_mem_Ico_of_ge (hb : b \u2264 c) : c \u2209 Ico a b :=\nnot_mem_subset Ico_subset_Iio_self $ not_mem_Iio.mpr hb\n\nlemma not_mem_Ioo_of_le (ha : c \u2264 a) : c \u2209 Ioo a b :=\nnot_mem_subset Ioo_subset_Ioi_self $ not_mem_Ioi.mpr ha\n\nlemma not_mem_Ioo_of_ge (hb : b \u2264 c) : c \u2209 Ioo a b :=\nnot_mem_subset Ioo_subset_Iio_self $ not_mem_Iio.mpr hb\n\n@[simp] lemma compl_Iic : (Iic a)\u1d9c = Ioi a := ext $ \u03bb _, not_le\n@[simp] lemma compl_Ici : (Ici a)\u1d9c = Iio a := ext $ \u03bb _, not_le\n@[simp] lemma compl_Iio : (Iio a)\u1d9c = Ici a := ext $ \u03bb _, not_lt\n@[simp] lemma compl_Ioi : (Ioi a)\u1d9c = Iic a := ext $ \u03bb _, not_lt\n\n@[simp] lemma Ici_diff_Ici : Ici a \\ Ici b = Ico a b :=\nby rw [diff_eq, compl_Ici, Ici_inter_Iio]\n\n@[simp] lemma Ici_diff_Ioi : Ici a \\ Ioi b = Icc a b :=\nby rw [diff_eq, compl_Ioi, Ici_inter_Iic]\n\n@[simp] lemma Ioi_diff_Ioi : Ioi a \\ Ioi b = Ioc a b :=\nby rw [diff_eq, compl_Ioi, Ioi_inter_Iic]\n\n@[simp] lemma Ioi_diff_Ici : Ioi a \\ Ici b = Ioo a b :=\nby rw [diff_eq, compl_Ici, Ioi_inter_Iio]\n\n@[simp] lemma Iic_diff_Iic : Iic b \\ Iic a = Ioc a b :=\nby rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic]\n\n@[simp] lemma Iio_diff_Iic : Iio b \\ Iic a = Ioo a b :=\nby rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio]\n\n@[simp] lemma Iic_diff_Iio : Iic b \\ Iio a = Icc a b :=\nby rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic]\n\n@[simp] lemma Iio_diff_Iio : Iio b \\ Iio a = Ico a b :=\nby rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio]\n\nlemma Ico_subset_Ico_iff (h\u2081 : a\u2081 < b\u2081) :\n  Ico a\u2081 b\u2081 \u2286 Ico a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, have a\u2082 \u2264 a\u2081 \u2227 a\u2081 < b\u2082 := h \u27e8le_rfl, h\u2081\u27e9,\n  \u27e8this.1, le_of_not_lt $ \u03bb h', lt_irrefl b\u2082 (h \u27e8this.2.le, h'\u27e9).2\u27e9,\n \u03bb \u27e8h\u2081, h\u2082\u27e9, Ico_subset_Ico h\u2081 h\u2082\u27e9\n\nlemma Ioc_subset_Ioc_iff (h\u2081 : a\u2081 < b\u2081) :\n  Ioc a\u2081 b\u2081 \u2286 Ioc a\u2082 b\u2082 \u2194 b\u2081 \u2264 b\u2082 \u2227 a\u2082 \u2264 a\u2081 :=\nby { convert @Ico_subset_Ico_iff (order_dual \u03b1) _ b\u2081 b\u2082 a\u2081 a\u2082 h\u2081; exact (@dual_Ico \u03b1 _ _ _).symm }\n\nlemma Ioo_subset_Ioo_iff [densely_ordered \u03b1] (h\u2081 : a\u2081 < b\u2081) :\n  Ioo a\u2081 b\u2081 \u2286 Ioo a\u2082 b\u2082 \u2194 a\u2082 \u2264 a\u2081 \u2227 b\u2081 \u2264 b\u2082 :=\n\u27e8\u03bb h, begin\n  rcases exists_between h\u2081 with \u27e8x, xa, xb\u27e9,\n  split; refine le_of_not_lt (\u03bb h', _),\n  { have ab := (h \u27e8xa, xb\u27e9).1.trans xb,\n    exact lt_irrefl _ (h \u27e8h', ab\u27e9).1 },\n  { have ab := xa.trans (h \u27e8xa, xb\u27e9).2,\n    exact lt_irrefl _ (h \u27e8ab, h'\u27e9).2 }\nend, \u03bb \u27e8h\u2081, h\u2082\u27e9, Ioo_subset_Ioo h\u2081 h\u2082\u27e9\n\nlemma Ico_eq_Ico_iff (h : a\u2081 < b\u2081 \u2228 a\u2082 < b\u2082) : Ico a\u2081 b\u2081 = Ico a\u2082 b\u2082 \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082 :=\n\u27e8\u03bb e, begin\n  simp [subset.antisymm_iff] at e, simp [le_antisymm_iff],\n  cases h; simp [Ico_subset_Ico_iff h] at e;\n    [ rcases e with \u27e8\u27e8h\u2081, h\u2082\u27e9, e'\u27e9, rcases e with \u27e8e', \u27e8h\u2081, h\u2082\u27e9\u27e9 ];\n    have := (Ico_subset_Ico_iff $ h\u2081.trans_lt $ h.trans_le h\u2082).1 e';\n    tauto\nend, \u03bb \u27e8h\u2081, h\u2082\u27e9, by rw [h\u2081, h\u2082]\u27e9\n\nopen_locale classical\n\n@[simp] lemma Ioi_subset_Ioi_iff : Ioi b \u2286 Ioi a \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Ioi_subset_Ioi h\u27e9,\n  by_contradiction ba,\n  exact lt_irrefl _ (h (not_le.mp ba))\nend\n\n@[simp] lemma Ioi_subset_Ici_iff [densely_ordered \u03b1] : Ioi b \u2286 Ici a \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Ioi_subset_Ici h\u27e9,\n  by_contradiction ba,\n  obtain \u27e8c, bc, ca\u27e9 : \u2203c, b < c \u2227 c < a := exists_between (not_le.mp ba),\n  exact lt_irrefl _ (ca.trans_le (h bc))\nend\n\n@[simp] lemma Iio_subset_Iio_iff : Iio a \u2286 Iio b \u2194 a \u2264 b :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, Iio_subset_Iio h\u27e9,\n  by_contradiction ab,\n  exact lt_irrefl _ (h (not_le.mp ab))\nend\n\n@[simp] lemma Iio_subset_Iic_iff [densely_ordered \u03b1] : Iio a \u2286 Iic b \u2194 a \u2264 b :=\nby rw [\u2190diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt]\n\n/-! ### Unions of adjacent intervals -/\n\n/-! #### Two infinite intervals -/\n\n@[simp] lemma Iic_union_Ici : Iic a \u222a Ici a = univ := eq_univ_of_forall (\u03bb x, le_total x a)\n\n@[simp] lemma Iio_union_Ici : Iio a \u222a Ici a = univ := eq_univ_of_forall (\u03bb x, lt_or_le x a)\n\n@[simp] lemma Iic_union_Ioi : Iic a \u222a Ioi a = univ := eq_univ_of_forall (\u03bb x, le_or_lt x a)\n\n/-! #### A finite and an infinite interval -/\n\nlemma Ioo_union_Ioi' (h\u2081 : c < b) :\n  Ioo a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioo, mem_Ioi, min_lt_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x < b := (le_of_not_gt hc).trans_lt h\u2081,\n    tauto },\nend\n\nlemma Ioo_union_Ioi (h : c < max a b) :\n  Ioo a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ioo_union_Ioi' h },\n  { rw min_comm,\n    simp [*, min_eq_left_of_lt] },\nend\n\nlemma Ioi_subset_Ioo_union_Ici : Ioi a \u2286 Ioo a b \u222a Ici b :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b \u222a Ici b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_le) Ioi_subset_Ioo_union_Ici\n\nlemma Ici_subset_Ico_union_Ici : Ici a \u2286 Ico a b \u222a Ici b :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ico_union_Ici_eq_Ici (h : a \u2264 b) : Ico a b \u222a Ici b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans) Ici_subset_Ico_union_Ici\n\nlemma Ico_union_Ici' (h\u2081 : c \u2264 b) :\n  Ico a b \u222a Ici c = Ici (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ico, mem_Ici, min_le_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\nend\n\nlemma Ico_union_Ici  (h : c \u2264 max a b) :\n  Ico a b \u222a Ici c = Ici (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ico_union_Ici' h },\n  { simp [*] },\nend\n\nlemma Ioi_subset_Ioc_union_Ioi : Ioi a \u2286 Ioc a b \u222a Ioi b :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Ioc_union_Ioi_eq_Ioi (h : a \u2264 b) : Ioc a b \u222a Ioi b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_lt) Ioi_subset_Ioc_union_Ioi\n\nlemma Ioc_union_Ioi' (h\u2081 : c \u2264 b) :\n  Ioc a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioc, mem_Ioi, min_lt_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081,\n    tauto },\nend\n\nlemma Ioc_union_Ioi (h : c \u2264 max a b) :\n  Ioc a b \u222a Ioi c = Ioi (min a c) :=\nbegin\n  cases le_total a b with hab hab; simp [hab] at h,\n  { exact Ioc_union_Ioi' h },\n  { simp [*] },\nend\n\nlemma Ici_subset_Icc_union_Ioi : Ici a \u2286 Icc a b \u222a Ioi b :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx, hxb\u27e9) (\u03bb hxb, or.inr hxb)\n\n@[simp] lemma Icc_union_Ioi_eq_Ici (h : a \u2264 b) : Icc a b \u222a Ioi b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left $ \u03bb hx', h.trans $ le_of_lt hx') Ici_subset_Icc_union_Ioi\n\nlemma Ioi_subset_Ioc_union_Ici : Ioi a \u2286 Ioc a b \u222a Ici b :=\nsubset.trans Ioi_subset_Ioo_union_Ici (union_subset_union_left _ Ioo_subset_Ioc_self)\n\n@[simp] lemma Ioc_union_Ici_eq_Ioi (h : a < b) : Ioc a b \u222a Ici b = Ioi a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans_le) Ioi_subset_Ioc_union_Ici\n\nlemma Ici_subset_Icc_union_Ici : Ici a \u2286 Icc a b \u222a Ici b :=\nsubset.trans Ici_subset_Ico_union_Ici (union_subset_union_left _ Ico_subset_Icc_self)\n\n@[simp] lemma Icc_union_Ici_eq_Ici (h : a \u2264 b) : Icc a b \u222a Ici b = Ici a :=\nsubset.antisymm (\u03bb x hx, hx.elim and.left h.trans) Ici_subset_Icc_union_Ici\n\nlemma Icc_union_Ici' (h\u2081 : c \u2264 b) :\n  Icc a b \u222a Ici c = Ici (min a c) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Icc, mem_Ici, min_le_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\nend\n\nlemma Icc_union_Ici (h : c \u2264 max a b) :\n  Icc a b \u222a Ici c = Ici (min a c) :=\nbegin\n  cases le_or_lt a b with hab hab; simp [hab] at h,\n  { exact Icc_union_Ici' h },\n  { cases h,\n    { simp [*] },\n    { have hca : c \u2264 a := h.trans hab.le,\n      simp [*] } },\nend\n\n/-! #### An infinite and a finite interval -/\n\nlemma Iic_subset_Iio_union_Icc : Iic b \u2286 Iio a \u222a Icc a b :=\n\u03bb x hx, (lt_or_le x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iio_union_Icc_eq_Iic (h : a \u2264 b) : Iio a \u222a Icc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx, (le_of_lt hx).trans h) and.right)\n  Iic_subset_Iio_union_Icc\n\nlemma Iio_subset_Iio_union_Ico : Iio b \u2286 Iio a \u222a Ico a b :=\n\u03bb x hx, (lt_or_le x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iio_union_Ico_eq_Iio (h : a \u2264 b) : Iio a \u222a Ico a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_lt_of_le hx' h) and.right) Iio_subset_Iio_union_Ico\n\nlemma Iio_union_Ico' (h\u2081 : c \u2264 b) :\n  Iio b \u222a Ico c d = Iio (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iio, mem_Ico, lt_max_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\nend\n\nlemma Iio_union_Ico (h : min c d \u2264 b) :\n  Iio b \u222a Ico c d = Iio (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iio_union_Ico' h },\n  { simp [*] },\nend\n\nlemma Iic_subset_Iic_union_Ioc : Iic b \u2286 Iic a \u222a Ioc a b :=\n\u03bb x hx, (le_or_lt x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iic_union_Ioc_eq_Iic (h : a \u2264 b) : Iic a \u222a Ioc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', le_trans hx' h) and.right) Iic_subset_Iic_union_Ioc\n\nlemma Iic_union_Ioc' (h\u2081 : c < b) :\n  Iic b \u222a Ioc c d = Iic (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iic, mem_Ioc, le_max_iff],\n  by_cases hc : c < x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081.le,\n    tauto },\nend\n\nlemma Iic_union_Ioc (h : min c d < b) :\n  Iic b \u222a Ioc c d = Iic (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iic_union_Ioc' h },\n  { rw max_comm,\n    simp [*, max_eq_right_of_lt h] },\nend\n\nlemma Iio_subset_Iic_union_Ioo : Iio b \u2286 Iic a \u222a Ioo a b :=\n\u03bb x hx, (le_or_lt x a).elim (\u03bb hxa, or.inl hxa) (\u03bb hxa, or.inr \u27e8hxa, hx\u27e9)\n\n@[simp] lemma Iic_union_Ioo_eq_Iio (h : a < b) : Iic a \u222a Ioo a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_le_of_lt hx' h) and.right) Iio_subset_Iic_union_Ioo\n\nlemma Iio_union_Ioo' (h\u2081 : c < b) :\n  Iio b \u222a Ioo c d = Iio (max b d) :=\nbegin\n  ext x,\n  cases lt_or_le x b with hba hba,\n  { simp [hba, h\u2081] },\n  { simp only [mem_Iio, mem_union_eq, mem_Ioo, lt_max_iff],\n    refine or_congr iff.rfl \u27e8and.right, _\u27e9,\n    exact \u03bb h\u2082, \u27e8h\u2081.trans_le hba, h\u2082\u27e9 },\nend\n\nlemma Iio_union_Ioo (h : min c d < b) :\n  Iio b \u222a Ioo c d = Iio (max b d) :=\nbegin\n  cases le_total c d with hcd hcd; simp [hcd] at h,\n  { exact Iio_union_Ioo' h },\n  { rw max_comm,\n    simp [*, max_eq_right_of_lt h] },\nend\n\nlemma Iic_subset_Iic_union_Icc : Iic b \u2286 Iic a \u222a Icc a b :=\nsubset.trans Iic_subset_Iic_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)\n\n@[simp] lemma Iic_union_Icc_eq_Iic (h : a \u2264 b) : Iic a \u222a Icc a b = Iic b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', le_trans hx' h) and.right) Iic_subset_Iic_union_Icc\n\nlemma Iic_union_Icc' (h\u2081 : c \u2264 b) :\n  Iic b \u222a Icc c d = Iic (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Iic, mem_Icc, le_max_iff],\n  by_cases hc : c \u2264 x,\n  { tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\nend\n\nlemma Iic_union_Icc (h : min c d \u2264 b) :\n  Iic b \u222a Icc c d = Iic (max b d) :=\nbegin\n  cases le_or_lt c d with hcd hcd; simp [hcd] at h,\n  { exact Iic_union_Icc' h },\n  { cases h,\n    { have hdb : d \u2264 b := hcd.le.trans h,\n      simp [*] },\n    { simp [*] } },\nend\n\nlemma Iio_subset_Iic_union_Ico : Iio b \u2286 Iic a \u222a Ico a b :=\nsubset.trans Iio_subset_Iic_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Iic_union_Ico_eq_Iio (h : a < b) : Iic a \u222a Ico a b = Iio b :=\nsubset.antisymm (\u03bb x hx, hx.elim (\u03bb hx', lt_of_le_of_lt hx' h) and.right) Iio_subset_Iic_union_Ico\n\n/-! #### Two finite intervals, `I?o` and `Ic?` -/\n\nlemma Ioo_subset_Ioo_union_Ico : Ioo a c \u2286 Ioo a b \u222a Ico b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioo_union_Ico_eq_Ioo (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioo a b \u222a Ico b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_le h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioo_subset_Ioo_union_Ico\n\nlemma Ico_subset_Ico_union_Ico : Ico a c \u2286 Ico a b \u222a Ico b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ico_union_Ico_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ico a b \u222a Ico b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_le h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Ico_subset_Ico_union_Ico\n\nlemma Ico_union_Ico' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Ico a b \u222a Ico c d = Ico (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ico, min_le_iff, lt_max_iff],\n  by_cases hc : c \u2264 x; by_cases hd : x < d,\n  { tauto },\n  { have hax : a \u2264 x := h\u2082.trans (le_of_not_gt hd),\n    tauto },\n  { have hxb : x < b := (lt_of_not_ge hc).trans_le h\u2081,\n    tauto },\n  { tauto },\nend\n\nlemma Ico_union_Ico (h\u2081 : min a b \u2264 max c d) (h\u2082 : min c d \u2264 max a b) :\n  Ico a b \u222a Ico c d = Ico (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd; simp [hab, hcd] at h\u2081 h\u2082,\n  { exact Ico_union_Ico' h\u2082 h\u2081 },\n  all_goals { simp [*] },\nend\n\nlemma Icc_subset_Ico_union_Icc : Icc a c \u2286 Ico a b \u222a Icc b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ico_union_Icc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ico a b \u222a Icc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.le.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Icc_subset_Ico_union_Icc\n\nlemma Ioc_subset_Ioo_union_Icc : Ioc a c \u2286 Ioo a b \u222a Icc b c :=\n\u03bb x hx, (lt_or_le x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioo_union_Icc_eq_Ioc (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioo a b \u222a Icc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.le.trans h\u2082\u27e9)\n    (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioc_subset_Ioo_union_Icc\n\n/-! #### Two finite intervals, `I?c` and `Io?` -/\n\nlemma Ioo_subset_Ioc_union_Ioo : Ioo a c \u2286 Ioc a b \u222a Ioo b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioc_union_Ioo_eq_Ioo (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Ioc a b \u222a Ioo b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_lt hx.1, hx.2\u27e9))\n  Ioo_subset_Ioc_union_Ioo\n\nlemma Ico_subset_Icc_union_Ioo : Ico a c \u2286 Icc a b \u222a Ioo b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Icc_union_Ioo_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Icc a b \u222a Ioo b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9)\n    (\u03bb hx, \u27e8h\u2081.trans hx.1.le, hx.2\u27e9))\n  Ico_subset_Icc_union_Ioo\n\nlemma Icc_subset_Icc_union_Ioc : Icc a c \u2286 Icc a b \u222a Ioc b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Icc_union_Ioc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Icc a b \u222a Ioc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1.le, hx.2\u27e9))\n  Icc_subset_Icc_union_Ioc\n\nlemma Ioc_subset_Ioc_union_Ioc : Ioc a c \u2286 Ioc a b \u222a Ioc b c :=\n\u03bb x hx, (le_or_lt x b).elim (\u03bb hxb, or.inl \u27e8hx.1, hxb\u27e9) (\u03bb hxb, or.inr \u27e8hxb, hx.2\u27e9)\n\n@[simp] lemma Ioc_union_Ioc_eq_Ioc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Ioc a b \u222a Ioc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_lt hx.1, hx.2\u27e9))\n  Ioc_subset_Ioc_union_Ioc\n\nlemma Ioc_union_Ioc' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Ioc a b \u222a Ioc c d = Ioc (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioc, min_lt_iff, le_max_iff],\n  by_cases hc : c < x; by_cases hd : x \u2264 d,\n  { tauto },\n  { have hax : a < x := h\u2082.trans_lt (lt_of_not_ge hd),\n    tauto },\n  { have hxb : x \u2264 b := (le_of_not_gt hc).trans h\u2081,\n    tauto },\n  { tauto },\nend\n\nlemma Ioc_union_Ioc (h\u2081 : min a b \u2264 max c d) (h\u2082 : min c d \u2264 max a b) :\n  Ioc a b \u222a Ioc c d = Ioc (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd; simp [hab, hcd] at h\u2081 h\u2082,\n  { exact Ioc_union_Ioc' h\u2082 h\u2081 },\n  all_goals { simp [*] },\nend\n\n/-! #### Two finite intervals with a common point -/\n\nlemma Ioo_subset_Ioc_union_Ico : Ioo a c \u2286 Ioc a b \u222a Ico b c :=\nsubset.trans Ioo_subset_Ioc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Ioc_union_Ico_eq_Ioo (h\u2081 : a < b) (h\u2082 : b < c) : Ioc a b \u222a Ico b c = Ioo a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx', \u27e8hx'.1, hx'.2.trans_lt h\u2082\u27e9) (\u03bb hx', \u27e8h\u2081.trans_le hx'.1, hx'.2\u27e9))\n  Ioo_subset_Ioc_union_Ico\n\nlemma Ico_subset_Icc_union_Ico : Ico a c \u2286 Icc a b \u222a Ico b c :=\nsubset.trans Ico_subset_Icc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)\n\n@[simp] lemma Icc_union_Ico_eq_Ico (h\u2081 : a \u2264 b) (h\u2082 : b < c) : Icc a b \u222a Ico b c = Ico a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans_lt h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Ico_subset_Icc_union_Ico\n\n\n\n@[simp] lemma Icc_union_Icc_eq_Icc (h\u2081 : a \u2264 b) (h\u2082 : b \u2264 c) : Icc a b \u222a Icc b c = Icc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans hx.1, hx.2\u27e9))\n  Icc_subset_Icc_union_Icc\n\nlemma Icc_union_Icc' (h\u2081 : c \u2264 b) (h\u2082 : a \u2264 d) :\n  Icc a b \u222a Icc c d = Icc (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Icc, min_le_iff, le_max_iff],\n  by_cases hc : c \u2264 x; by_cases hd : x \u2264 d,\n  { tauto },\n  { have hax : a \u2264 x := h\u2082.trans (le_of_not_ge hd),\n    tauto },\n  { have hxb : x \u2264 b := (le_of_not_ge hc).trans h\u2081,\n    tauto },\n  { tauto }\nend\n\n/--\nWe cannot replace `<` by `\u2264` in the hypotheses.\nOtherwise for `b < a = d < c` the l.h.s. is `\u2205` and the r.h.s. is `{a}`.\n-/\nlemma Icc_union_Icc (h\u2081 : min a b < max c d) (h\u2082 : min c d < max a b) :\n  Icc a b \u222a Icc c d = Icc (min a c) (max b d) :=\nbegin\n  cases le_or_lt a b with hab hab; cases le_or_lt c d with hcd hcd;\n    simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, min_eq_left_of_lt,\n    min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt, hab, hcd] at h\u2081 h\u2082,\n  { exact Icc_union_Icc' h\u2082.le h\u2081.le },\n  all_goals { simp [*, min_eq_left_of_lt, max_eq_left_of_lt, min_eq_right_of_lt,\n    max_eq_right_of_lt] },\nend\n\nlemma Ioc_subset_Ioc_union_Icc : Ioc a c \u2286 Ioc a b \u222a Icc b c :=\nsubset.trans Ioc_subset_Ioc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)\n\n@[simp] lemma Ioc_union_Icc_eq_Ioc (h\u2081 : a < b) (h\u2082 : b \u2264 c) : Ioc a b \u222a Icc b c = Ioc a c :=\nsubset.antisymm\n  (\u03bb x hx, hx.elim (\u03bb hx, \u27e8hx.1, hx.2.trans h\u2082\u27e9) (\u03bb hx, \u27e8h\u2081.trans_le hx.1, hx.2\u27e9))\n  Ioc_subset_Ioc_union_Icc\n\nlemma Ioo_union_Ioo' (h\u2081 : c < b) (h\u2082 : a < d) :\n  Ioo a b \u222a Ioo c d = Ioo (min a c) (max b d) :=\nbegin\n  ext1 x,\n  simp_rw [mem_union, mem_Ioo, min_lt_iff, lt_max_iff],\n  by_cases hc : c < x; by_cases hd : x < d,\n  { tauto },\n  { have hax : a < x := h\u2082.trans_le (le_of_not_lt hd),\n    tauto },\n  { have hxb : x < b := (le_of_not_lt hc).trans_lt h\u2081,\n    tauto },\n  { tauto }\nend\n\nlemma Ioo_union_Ioo (h\u2081 : min a b < max c d) (h\u2082 : min c d < max a b) :\n  Ioo a b \u222a Ioo c d = Ioo (min a c) (max b d) :=\nbegin\n  cases le_total a b with hab hab; cases le_total c d with hcd hcd;\n    simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, hab, hcd] at h\u2081 h\u2082,\n  { exact Ioo_union_Ioo' h\u2082 h\u2081 },\n  all_goals\n  { simp [*, min_eq_left_of_lt, min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt,\n      le_of_lt h\u2082, le_of_lt h\u2081] },\nend\n\nend linear_order\n\nsection lattice\n\nsection inf\n\nvariables {\u03b1 : Type u} [semilattice_inf \u03b1]\n\n@[simp] lemma Iic_inter_Iic {a b : \u03b1} : Iic a \u2229 Iic b = Iic (a \u2293 b) :=\nby { ext x, simp [Iic] }\n\n@[simp] lemma Iio_inter_Iio [is_total \u03b1 (\u2264)] {a b : \u03b1} : Iio a \u2229 Iio b = Iio (a \u2293 b) :=\nby { ext x, simp [Iio] }\n\n@[simp] lemma Ioc_inter_Iic (a b c : \u03b1) : Ioc a b \u2229 Iic c = Ioc a (b \u2293 c) :=\nby rw [\u2190 Ioi_inter_Iic, \u2190 Ioi_inter_Iic, inter_assoc, Iic_inter_Iic]\n\nend inf\n\nsection sup\n\nvariables {\u03b1 : Type u} [semilattice_sup \u03b1]\n\n@[simp] lemma Ici_inter_Ici {a b : \u03b1} : Ici a \u2229 Ici b = Ici (a \u2294 b) :=\nby { ext x, simp [Ici] }\n\n@[simp] lemma Ico_inter_Ici (a b c : \u03b1) : Ico a b \u2229 Ici c = Ico (a \u2294 c) b :=\nby rw [\u2190 Ici_inter_Iio, \u2190 Ici_inter_Iio, \u2190 Ici_inter_Ici, inter_right_comm]\n\n@[simp] lemma Ioi_inter_Ioi [is_total \u03b1 (\u2264)] {a b : \u03b1} : Ioi a \u2229 Ioi b = Ioi (a \u2294 b) :=\nby { ext x, simp [Ioi] }\n\n@[simp] lemma Ioc_inter_Ioi [is_total \u03b1 (\u2264)] {a b c : \u03b1} : Ioc a b \u2229 Ioi c = Ioc (a \u2294 c) b :=\nby rw [\u2190 Ioi_inter_Iic, inter_assoc, inter_comm, inter_assoc, Ioi_inter_Ioi, inter_comm,\n  Ioi_inter_Iic, sup_comm]\n\nend sup\n\nsection both\n\nvariables {\u03b1 : Type u} [lattice \u03b1] [ht : is_total \u03b1 (\u2264)] {a b c a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1}\n\nlemma Icc_inter_Icc : Icc a\u2081 b\u2081 \u2229 Icc a\u2082 b\u2082 = Icc (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_refl\n\n@[simp] lemma Icc_inter_Icc_eq_singleton (hab : a \u2264 b) (hbc : b \u2264 c) :\n  Icc a b \u2229 Icc b c = {b} :=\nby rw [Icc_inter_Icc, sup_of_le_right hab, inf_of_le_left hbc, Icc_self]\n\ninclude ht\n\nlemma Ico_inter_Ico : Ico a\u2081 b\u2081 \u2229 Ico a\u2082 b\u2082 = Ico (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ici_inter_Iio.symm, Ici_inter_Ici.symm, Iio_inter_Iio.symm]; ac_refl\n\nlemma Ioc_inter_Ioc : Ioc a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioc (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ioi_inter_Iic.symm, Ioi_inter_Ioi.symm, Iic_inter_Iic.symm]; ac_refl\n\nlemma Ioo_inter_Ioo : Ioo a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioo (a\u2081 \u2294 a\u2082) (b\u2081 \u2293 b\u2082) :=\nby simp only [Ioi_inter_Iio.symm, Ioi_inter_Ioi.symm, Iio_inter_Iio.symm]; ac_refl\n\nend both\n\nlemma Icc_bot_top {\u03b1} [partial_order \u03b1] [bounded_order \u03b1] : Icc (\u22a5 : \u03b1) \u22a4 = univ := by simp\n\nend lattice\n\nsection linear_order\nvariables {\u03b1 : Type u} [linear_order \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c d : \u03b1}\n\nlemma Ioc_inter_Ioo_of_left_lt (h : b\u2081 < b\u2082) : Ioc a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioc (max a\u2081 a\u2082) b\u2081 :=\next $ \u03bb x, by simp [and_assoc, @and.left_comm (x \u2264 _),\n  and_iff_left_iff_imp.2 (\u03bb h', lt_of_le_of_lt h' h)]\n\nlemma Ioc_inter_Ioo_of_right_le (h : b\u2082 \u2264 b\u2081) : Ioc a\u2081 b\u2081 \u2229 Ioo a\u2082 b\u2082 = Ioo (max a\u2081 a\u2082) b\u2082 :=\next $ \u03bb x, by simp [and_assoc, @and.left_comm (x \u2264 _),\n  and_iff_right_iff_imp.2 (\u03bb h', ((le_of_lt h').trans h))]\n\nlemma Ioo_inter_Ioc_of_left_le (h : b\u2081 \u2264 b\u2082) : Ioo a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioo (max a\u2081 a\u2082) b\u2081 :=\nby rw [inter_comm, Ioc_inter_Ioo_of_right_le h, max_comm]\n\nlemma Ioo_inter_Ioc_of_right_lt (h : b\u2082 < b\u2081) : Ioo a\u2081 b\u2081 \u2229 Ioc a\u2082 b\u2082 = Ioc (max a\u2081 a\u2082) b\u2082 :=\nby rw [inter_comm, Ioc_inter_Ioo_of_left_lt h, max_comm]\n\n@[simp] lemma Ico_diff_Iio : Ico a b \\ Iio c = Ico (max a c) b :=\nby rw [diff_eq, compl_Iio, Ico_inter_Ici, sup_eq_max]\n\n@[simp] lemma Ioc_diff_Ioi : Ioc a b \\ Ioi c = Ioc a (min b c) :=\next $ by simp [iff_def] {contextual:=tt}\n\n@[simp] lemma Ico_inter_Iio : Ico a b \u2229 Iio c = Ico a (min b c) :=\next $ by simp [iff_def] {contextual:=tt}\n\n@[simp] lemma Ioc_diff_Iic : Ioc a b \\ Iic c = Ioc (max a c) b :=\nby rw [diff_eq, compl_Iic, Ioc_inter_Ioi, sup_eq_max]\n\n@[simp] lemma Ioc_union_Ioc_right : Ioc a b \u222a Ioc a c = Ioc a (max b c) :=\nby rw [Ioc_union_Ioc, min_self]; exact (min_le_left _ _).trans (le_max_left _ _)\n\n@[simp] lemma Ioc_union_Ioc_left : Ioc a c \u222a Ioc b c = Ioc (min a b) c :=\nby rw [Ioc_union_Ioc, max_self]; exact (min_le_right _ _).trans (le_max_right _ _)\n\n@[simp] lemma Ioc_union_Ioc_symm : Ioc a b \u222a Ioc b a = Ioc (min a b) (max a b) :=\nby { rw max_comm, apply Ioc_union_Ioc; rw max_comm; exact min_le_max }\n\n@[simp] lemma Ioc_union_Ioc_union_Ioc_cycle :\n  Ioc a b \u222a Ioc b c \u222a Ioc c a = Ioc (min a (min b c)) (max a (max b c)) :=\nbegin\n  rw [Ioc_union_Ioc, Ioc_union_Ioc],\n  ac_refl,\n  all_goals { solve_by_elim [min_le_of_left_le, min_le_of_right_le, le_max_of_le_left,\n    le_max_of_le_right, le_refl] { max_depth := 5 }}\nend\n\nend linear_order\n\n/-!\n### Closed intervals in `\u03b1 \u00d7 \u03b2`\n-/\n\nsection prod\n\nvariables {\u03b1 \u03b2 : Type*} [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma Iic_prod_Iic (a : \u03b1) (b : \u03b2) : Iic a \u00d7\u02e2 Iic b = Iic (a, b) := rfl\n\n@[simp] lemma Ici_prod_Ici (a : \u03b1) (b : \u03b2) : Ici a \u00d7\u02e2 Ici b = Ici (a, b) := rfl\n\nlemma Ici_prod_eq (a : \u03b1 \u00d7 \u03b2) : Ici a = Ici a.1 \u00d7\u02e2 Ici a.2 := rfl\n\nlemma Iic_prod_eq (a : \u03b1 \u00d7 \u03b2) : Iic a = Iic a.1 \u00d7\u02e2 Iic a.2 := rfl\n\n@[simp] lemma Icc_prod_Icc (a\u2081 a\u2082 : \u03b1) (b\u2081 b\u2082 : \u03b2) :\n  Icc a\u2081 a\u2082 \u00d7\u02e2 Icc b\u2081 b\u2082 = Icc (a\u2081, b\u2081) (a\u2082, b\u2082) :=\nby { ext \u27e8x, y\u27e9, simp [and.assoc, and_comm, and.left_comm] }\n\nlemma Icc_prod_eq (a b : \u03b1 \u00d7 \u03b2) :\n  Icc a b = Icc a.1 b.1 \u00d7\u02e2 Icc a.2 b.2 :=\nby simp\n\nend prod\n\n/-! ### Lemmas about membership of arithmetic operations -/\n\nsection ordered_comm_group\n\nvariables {\u03b1 : Type*} [ordered_comm_group \u03b1] {a b c d : \u03b1}\n\n/-! `inv_mem_Ixx_iff`, `sub_mem_Ixx_iff` -/\n@[to_additive] lemma inv_mem_Icc_iff : a\u207b\u00b9 \u2208 set.Icc c d \u2194 a \u2208 set.Icc (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_le' le_inv'\n@[to_additive] lemma inv_mem_Ico_iff : a\u207b\u00b9 \u2208 set.Ico c d \u2194 a \u2208 set.Ioc (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_lt' le_inv'\n@[to_additive] lemma inv_mem_Ioc_iff : a\u207b\u00b9 \u2208 set.Ioc c d \u2194 a \u2208 set.Ico (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_le' lt_inv'\n@[to_additive] lemma inv_mem_Ioo_iff : a\u207b\u00b9 \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (d\u207b\u00b9) (c\u207b\u00b9) :=\n(and_comm _ _).trans $ and_congr inv_lt' lt_inv'\n\nend ordered_comm_group\n\nsection ordered_add_comm_group\n\nvariables {\u03b1 : Type*} [ordered_add_comm_group \u03b1] {a b c d : \u03b1}\n\n/-! `add_mem_Ixx_iff_left` -/\nlemma add_mem_Icc_iff_left : a + b \u2208 set.Icc c d \u2194 a \u2208 set.Icc (c - b) (d - b) :=\n(and_congr sub_le_iff_le_add le_sub_iff_add_le).symm\nlemma add_mem_Ico_iff_left : a + b \u2208 set.Ico c d \u2194 a \u2208 set.Ico (c - b) (d - b) :=\n(and_congr sub_le_iff_le_add lt_sub_iff_add_lt).symm\nlemma add_mem_Ioc_iff_left : a + b \u2208 set.Ioc c d \u2194 a \u2208 set.Ioc (c - b) (d - b) :=\n(and_congr sub_lt_iff_lt_add le_sub_iff_add_le).symm\nlemma add_mem_Ioo_iff_left : a + b \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (c - b) (d - b) :=\n(and_congr sub_lt_iff_lt_add lt_sub_iff_add_lt).symm\n\n/-! `add_mem_Ixx_iff_right` -/\nlemma add_mem_Icc_iff_right : a + b \u2208 set.Icc c d \u2194 b \u2208 set.Icc (c - a) (d - a) :=\n(and_congr sub_le_iff_le_add' le_sub_iff_add_le').symm\nlemma add_mem_Ico_iff_right : a + b \u2208 set.Ico c d \u2194 b \u2208 set.Ico (c - a) (d - a) :=\n(and_congr sub_le_iff_le_add' lt_sub_iff_add_lt').symm\nlemma add_mem_Ioc_iff_right : a + b \u2208 set.Ioc c d \u2194 b \u2208 set.Ioc (c - a) (d - a) :=\n(and_congr sub_lt_iff_lt_add' le_sub_iff_add_le').symm\nlemma add_mem_Ioo_iff_right : a + b \u2208 set.Ioo c d \u2194 b \u2208 set.Ioo (c - a) (d - a) :=\n(and_congr sub_lt_iff_lt_add' lt_sub_iff_add_lt').symm\n\n/-! `sub_mem_Ixx_iff_left` -/\nlemma sub_mem_Icc_iff_left : a - b \u2208 set.Icc c d \u2194 a \u2208 set.Icc (c + b) (d + b) :=\nand_congr le_sub_iff_add_le sub_le_iff_le_add\nlemma sub_mem_Ico_iff_left : a - b \u2208 set.Ico c d \u2194 a \u2208 set.Ico (c + b) (d + b) :=\nand_congr le_sub_iff_add_le sub_lt_iff_lt_add\nlemma sub_mem_Ioc_iff_left : a - b \u2208 set.Ioc c d \u2194 a \u2208 set.Ioc (c + b) (d + b) :=\nand_congr lt_sub_iff_add_lt sub_le_iff_le_add\nlemma sub_mem_Ioo_iff_left : a - b \u2208 set.Ioo c d \u2194 a \u2208 set.Ioo (c + b) (d + b) :=\nand_congr lt_sub_iff_add_lt sub_lt_iff_lt_add\n\n/-! `sub_mem_Ixx_iff_right` -/\nlemma sub_mem_Icc_iff_right : a - b \u2208 set.Icc c d \u2194 b \u2208 set.Icc (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_le le_sub\nlemma sub_mem_Ico_iff_right : a - b \u2208 set.Ico c d \u2194 b \u2208 set.Ioc (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_lt le_sub\nlemma sub_mem_Ioc_iff_right : a - b \u2208 set.Ioc c d \u2194 b \u2208 set.Ico (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_le lt_sub\nlemma sub_mem_Ioo_iff_right : a - b \u2208 set.Ioo c d \u2194 b \u2208 set.Ioo (a - d) (a - c) :=\n(and_comm _ _).trans $ and_congr sub_lt lt_sub\n\n-- I think that symmetric intervals deserve attention and API: they arise all the time,\n-- for instance when considering metric balls in `\u211d`.\nlemma mem_Icc_iff_abs_le {R : Type*} [linear_ordered_add_comm_group R] {x y z : R} :\n  |x - y| \u2264 z \u2194 y \u2208 Icc (x - z) (x + z) :=\nabs_le.trans $ (and_comm _ _).trans $ and_congr sub_le neg_le_sub_iff_le_add\n\nend ordered_add_comm_group\n\nsection linear_ordered_add_comm_group\n\nvariables {\u03b1 : Type u} [linear_ordered_add_comm_group \u03b1]\n\n/-- If we remove a smaller interval from a larger, the result is nonempty -/\nlemma nonempty_Ico_sdiff {x dx y dy : \u03b1} (h : dy < dx) (hx : 0 < dx) :\n  nonempty \u21a5(Ico x (x + dx) \\ Ico y (y + dy)) :=\nbegin\n  cases lt_or_le x y with h' h',\n  { use x, simp [*, not_le.2 h'] },\n  { use max x (x + dy), simp [*, le_refl] }\nend\n\nend linear_ordered_add_comm_group\n\nend set\n\nopen set\n\nnamespace order_iso\nvariables {\u03b1 \u03b2 : Type*}\n\nsection preorder\nvariables [preorder \u03b1] [preorder \u03b2]\n\n@[simp] lemma preimage_Iic (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Iic b) = Iic (e.symm b) :=\nby { ext x, simp [\u2190 e.le_iff_le] }\n\n@[simp] lemma preimage_Ici (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Ici b) = Ici (e.symm b) :=\nby { ext x, simp [\u2190 e.le_iff_le] }\n\n@[simp] lemma preimage_Iio (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Iio b) = Iio (e.symm b) :=\nby { ext x, simp [\u2190 e.lt_iff_lt] }\n\n@[simp] lemma preimage_Ioi (e : \u03b1 \u2243o \u03b2) (b : \u03b2) : e \u207b\u00b9' (Ioi b) = Ioi (e.symm b) :=\nby { ext x, simp [\u2190 e.lt_iff_lt] }\n\n@[simp] lemma preimage_Icc (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Icc a b) = Icc (e.symm a) (e.symm b) :=\nby simp [\u2190 Ici_inter_Iic]\n\n@[simp] lemma preimage_Ico (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Ico a b) = Ico (e.symm a) (e.symm b) :=\nby simp [\u2190 Ici_inter_Iio]\n\n@[simp] lemma preimage_Ioc (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Ioc a b) = Ioc (e.symm a) (e.symm b) :=\nby simp [\u2190 Ioi_inter_Iic]\n\n@[simp] lemma preimage_Ioo (e : \u03b1 \u2243o \u03b2) (a b : \u03b2) : e \u207b\u00b9' (Ioo a b) = Ioo (e.symm a) (e.symm b) :=\nby simp [\u2190 Ioi_inter_Iio]\n\n@[simp] lemma image_Iic (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Iic a) = Iic (e a) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Iic, e.symm_symm]\n\n@[simp] lemma image_Ici (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Ici a) = Ici (e a) :=\ne.dual.image_Iic a\n\n@[simp] lemma image_Iio (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Iio a) = Iio (e a) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Iio, e.symm_symm]\n\n@[simp] lemma image_Ioi (e : \u03b1 \u2243o \u03b2) (a : \u03b1) : e '' (Ioi a) = Ioi (e a) :=\ne.dual.image_Iio a\n\n@[simp] lemma image_Ioo (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Ioo a b) = Ioo (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Ioo, e.symm_symm]\n\n@[simp] lemma image_Ioc (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Ioc a b) = Ioc (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Ioc, e.symm_symm]\n\n@[simp] lemma image_Ico (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Ico a b) = Ico (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Ico, e.symm_symm]\n\n@[simp] lemma image_Icc (e : \u03b1 \u2243o \u03b2) (a b : \u03b1) : e '' (Icc a b) = Icc (e a) (e b) :=\nby rw [e.image_eq_preimage, e.symm.preimage_Icc, e.symm_symm]\n\nend preorder\n\n/-- Order isomorphism between `Iic (\u22a4 : \u03b1)` and `\u03b1` when `\u03b1` has a top element -/\ndef Iic_top [preorder \u03b1] [order_top \u03b1] : set.Iic (\u22a4 : \u03b1) \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb x y, by refl,\n  .. (@equiv.subtype_univ_equiv \u03b1 (set.Iic (\u22a4 : \u03b1)) (\u03bb x, le_top)), }\n\n/-- Order isomorphism between `Ici (\u22a5 : \u03b1)` and `\u03b1` when `\u03b1` has a bottom element -/\ndef Ici_bot [preorder \u03b1] [order_bot \u03b1] : set.Ici (\u22a5 : \u03b1) \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb x y, by refl,\n  .. (@equiv.subtype_univ_equiv \u03b1 (set.Ici (\u22a5 : \u03b1)) (\u03bb x, bot_le)) }\n\nend order_iso\n\n/-! ### Lemmas about intervals in dense orders -/\n\nsection dense\n\nvariables (\u03b1 : Type*) [preorder \u03b1] [densely_ordered \u03b1] {x y : \u03b1}\n\ninstance : no_min_order (set.Ioo x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2081 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2081, hb\u2082.trans ha\u2082\u27e9, hb\u2082\u27e9\nend\u27e9\n\ninstance : no_min_order (set.Ioc x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2081 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2081, hb\u2082.le.trans ha\u2082\u27e9, hb\u2082\u27e9\nend\u27e9\n\ninstance : no_min_order (set.Ioi x) :=\n\u27e8\u03bb \u27e8a, ha\u27e9, begin\n  rcases exists_between ha with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2081\u27e9, hb\u2082\u27e9\nend\u27e9\n\ninstance : no_max_order (set.Ioo x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2082 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, ha\u2081.trans hb\u2081, hb\u2082\u27e9, hb\u2081\u27e9\nend\u27e9\n\ninstance : no_max_order (set.Ico x y) :=\n\u27e8\u03bb \u27e8a, ha\u2081, ha\u2082\u27e9, begin\n  rcases exists_between ha\u2082 with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, ha\u2081.trans hb\u2081.le, hb\u2082\u27e9, hb\u2081\u27e9\nend\u27e9\n\ninstance : no_max_order (set.Iio x) :=\n\u27e8\u03bb \u27e8a, ha\u27e9, begin\n  rcases exists_between ha with \u27e8b, hb\u2081, hb\u2082\u27e9,\n  exact \u27e8\u27e8b, hb\u2082\u27e9, hb\u2081\u27e9\nend\u27e9\n\nend dense\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/set/intervals/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199754937772, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7051299746969351}}
{"text": "import tactic\n\n/-!\n\n# The partition challenge!\n\nProve that equivalence relations on \u03b1 are the same as partitions of \u03b1.\n\nThree sections:\n\n1) partitions\n2) equivalence classes\n3) the challenge\n\n## Overview\n\nSay `\u03b1` is a type, and `R` is a binary relation on `\u03b1`. \nThe following things are already in Lean:\n\nreflexive R := \u2200 (x : \u03b1), R x x\nsymmetric R := \u2200 \u2983x y : \u03b1\u2984, R x y \u2192 R y x\ntransitive R := \u2200 \u2983x y z : \u03b1\u2984, R x y \u2192 R y z \u2192 R x z\n\nequivalence R := reflexive R \u2227 symmetric R \u2227 transitive R\n\nIn the file below, we will define partitions of `\u03b1` and \"build some\ninterface\" (i.e. prove some propositions). We will define\nequivalence classes and do the same thing.\nFinally, we will prove that there's a bijection between\nequivalence relations on `\u03b1` and partitions of `\u03b1`.\n\n-/\n\n/-\n\n# 1) Partitions\n\nWe define a partition, and prove some easy lemmas.\n\n-/\n\n/- \n\n## Definition of a partition\n\nLet `\u03b1` be a type. A *partition* on `\u03b1` is defined to be\nthe following data:\n\n1) A set C of subsets of \u03b1, called \"blocks\".\n2) A hypothesis (i.e. a proof!) that all the blocks are non-empty.\n3) A hypothesis that every term of type \u03b1 is in one of the blocks.\n4) A hypothesis that two blocks with non-empty intersection are equal.\n-/\n\n/-- The structure of a partition on a Type \u03b1. -/ \n@[ext] structure partition (\u03b1 : Type) :=\n(C : set (set \u03b1))\n(Hnonempty : \u2200 X \u2208 C, (X : set \u03b1).nonempty)\n(Hcover : \u2200 a, \u2203 X \u2208 C, a \u2208 X)\n(Hdisjoint : \u2200 X Y \u2208 C, (X \u2229 Y : set \u03b1).nonempty \u2192 X = Y)\n\n-- docstrings\n\n/-- The set of blocks. -/\nadd_decl_doc partition.C\n\n/-- Every element of a block is nonempty. -/\nadd_decl_doc partition.Hnonempty\n\n/-- The blocks cover the type they partition -/\nadd_decl_doc partition.Hcover\n\n/-- Two blocks which share an element are equal -/\nadd_decl_doc partition.Hdisjoint\n\n/-\n\n## Basic interface for partitions\n\n-/\n\nnamespace partition\n\n-- let \u03b1 be a type, and fix a partition P on \u03b1. Let X and Y be subsets of \u03b1.\nvariables {\u03b1 : Type} {P : partition \u03b1} {X Y : set \u03b1}\n\n/-- If X and Y are blocks, and a is in X and Y, then X = Y. -/\ntheorem eq_of_mem (hX : X \u2208 P.C) (hY : Y \u2208 P.C) {a : \u03b1} (haX : a \u2208 X)\n  (haY : a \u2208 Y) : X = Y :=\n-- Proof: follows immediately from the disjointness hypothesis.\nP.Hdisjoint _ hX _ hY \u27e8a, haX, haY\u27e9\n\n/-- If a is in two blocks X and Y, and if b is in X,\n  then b is in Y (as X=Y) -/\ntheorem mem_of_mem (hX : X \u2208 P.C) (hY : Y \u2208 P.C) {a b : \u03b1}\n  (haX : a \u2208 X) (haY : a \u2208 Y) (hbX : b \u2208 X) : b \u2208 Y :=\nbegin\n  sorry,\nend\n\n/-- Every term of type `\u03b1` is in one of the blocks for a partition `P`. -/\ntheorem mem_block (a : \u03b1) : \u2203 X : set \u03b1, X \u2208 P.C \u2227 a \u2208 X :=\nbegin\n  sorry,\nend\n\n\n\nend partition\n\n/-\n\n# 2) Equivalence classes.\n\nWe define equivalence classes and prove a few basic results about them.\n\n-/\n\nsection equivalence_classes\n\n/-!\n\n## Definition of equivalence classes \n\n-/\n\n-- Notation and variables for the equivalence class section:\n\n-- let \u03b1 be a type, and let R be a binary relation on R.\nvariables {\u03b1 : Type} (R : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\n/-- The equivalence class of `a` is the set of `b` related to `a`. -/\ndef cl (a : \u03b1) :=\n{b : \u03b1 | R b a}\n\n/-!\n\n## Basic lemmas about equivalence classes\n\n-/\n\n/-- Useful for rewriting -- `b` is in the equivalence class of `a` iff\n`b` is related to `a`. True by definition. -/\ntheorem cl_def {a b : \u03b1} : b \u2208 cl R a \u2194 R b a := iff.rfl \n\n-- Assume now that R is an equivalence relation.\nvariables {R} (hR : equivalence R)\ninclude hR\n\n/-- x is in cl(x) -/\nlemma mem_cl_self (a : \u03b1) :\n  a \u2208 cl R a :=\nbegin\n  sorry,\nend\n\nlemma cl_sub_cl_of_mem_cl {a b : \u03b1} :\n  a \u2208 cl R b \u2192\n  cl R a \u2286 cl R b :=\nbegin\n  sorry,\nend\n\nlemma cl_eq_cl_of_mem_cl {a b : \u03b1} :\n  a \u2208 cl R b \u2192\n  cl R a = cl R b :=\nbegin\n  sorry\nend\n\nend equivalence_classes -- section\n\n/-!\n\n# 3) The challenge!\n\nLet `\u03b1` be a type (i.e. a collection of stucff).\n\nThere is a bijection between equivalence relations on `\u03b1` and\npartitions of `\u03b1`.\n\nWe prove this by writing down constructions in each direction\nand proving that the constructions are two-sided inverses of one another.\n-/\n\nopen partition\n\n\nexample (\u03b1 : Type) : {R : \u03b1 \u2192 \u03b1 \u2192 Prop // equivalence R} \u2243 partition \u03b1 :=\n-- We define constructions (functions!) in both directions and prove that\n-- one is a two-sided inverse of the other\n{ -- Here is the first construction, from equivalence\n  -- relations to partitions.\n  -- Let R be an equivalence relation.\n  to_fun := \u03bb R, {\n    -- Let C be the set of equivalence classes for R.\n    C := { B : set \u03b1 | \u2203 x : \u03b1, B = cl R.1 x},\n    -- I claim that C is a partition. We need to check the three\n    -- hypotheses for a partition (`Hnonempty`, `Hcover` and `Hdisjoint`),\n    -- so we need to supply three proofs.\n    Hnonempty := begin\n      cases R with R hR,\n      -- If X is an equivalence class then X is nonempty.\n      show \u2200 (X : set \u03b1), (\u2203 (a : \u03b1), X = cl R a) \u2192 X.nonempty,\n      sorry,\n    end,\n    Hcover := begin\n      cases R with R hR,\n      -- The equivalence classes cover \u03b1\n      show \u2200 (a : \u03b1), \u2203 (X : set \u03b1) (H : \u2203 (b : \u03b1), X = cl R b), a \u2208 X,\n      sorry,\n    end,\n    Hdisjoint := begin\n      cases R with R hR,\n      -- If two equivalence classes overlap, they are equal.\n      show \u2200 (X : set \u03b1), (\u2203 (a : \u03b1), X = cl R a) \u2192\n        \u2200 (Y : set \u03b1), (\u2203 (b : \u03b1), Y = cl _ b) \u2192 (X \u2229 Y).nonempty \u2192 X = Y,\n      sorry,\n    end },\n  -- Conversely, say P is an partition. \n  inv_fun := \u03bb P, \n    -- Let's define a binary relation `R` thus:\n    --  `R a b` iff *every* block containing `a` also contains `b`.\n    -- Because only one block contains a, this will work,\n    -- and it turns out to be a nice way of thinking about it. \n    \u27e8\u03bb a b, \u2200 X \u2208 P.C, a \u2208 X \u2192 b \u2208 X, begin\n      -- I claim this is an equivalence relation.\n    split,\n    { -- It's reflexive\n      show \u2200 (a : \u03b1)\n        (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 a \u2208 X,\n      sorry,\n    },\n    split,\n    { -- it's symmetric\n      show \u2200 (a b : \u03b1),\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 b \u2208 X) \u2192\n         \u2200 (X : set \u03b1), X \u2208 P.C \u2192 b \u2208 X \u2192 a \u2208 X,\n      sorry,\n    },\n    { -- it's transitive\n      unfold transitive,\n      show \u2200 (a b c : \u03b1),\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 b \u2208 X) \u2192\n        (\u2200 (X : set \u03b1), X \u2208 P.C \u2192 b \u2208 X \u2192 c \u2208 X) \u2192\n         \u2200 (X : set \u03b1), X \u2208 P.C \u2192 a \u2208 X \u2192 c \u2208 X,\n      sorry,\n    }\n  end\u27e9,\n  -- If you start with the equivalence relation, and then make the partition\n  -- and a new equivalence relation, you get back to where you started.\n  left_inv := begin\n    rintro \u27e8R, hR\u27e9,\n    -- Tidying up the mess...\n    suffices : (\u03bb (a b : \u03b1), \u2200 (c : \u03b1), a \u2208 cl R c \u2192 b \u2208 cl R c) = R,\n      simpa,\n    -- ... you have to prove two binary relations are equal.\n    ext a b,\n    -- so you have to prove an if and only if.\n    show (\u2200 (c : \u03b1), a \u2208 cl R c \u2192 b \u2208 cl R c) \u2194 R a b,\n    sorry,\n  end,\n  -- Similarly, if you start with the partition, and then make the\n  -- equivalence relation, and then construct the corresponding partition \n  -- into equivalence classes, you have the same partition you started with.  \n  right_inv := begin\n    -- Let P be a partition\n    intro P,\n    -- It suffices to prove that a subset X is in the original partition\n    -- if and only if it's in the one made from the equivalence relation.\n    ext X,\n    show (\u2203 (a : \u03b1), X = cl _ a) \u2194 X \u2208 P.C,\n    dsimp only,\n    sorry,\n  end }\n\n/-\n-- get these files with\n\nleanproject get ImperialCollegeLondon/M40001_lean\n\n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/relations/partition_challenge.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.705129966210283}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.multiset.finset_ops\nimport data.multiset.fold\n\n/-!\n# Lattice operations on multisets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nnamespace multiset\nvariables {\u03b1 : Type*}\n\n/-! ### sup -/\nsection sup\n-- can be defined with just `[has_bot \u03b1]` where some lemmas hold without requiring `[order_bot \u03b1]`\nvariables [semilattice_sup \u03b1] [order_bot \u03b1]\n\n/-- Supremum of a multiset: `sup {a, b, c} = a \u2294 b \u2294 c` -/\ndef sup (s : multiset \u03b1) : \u03b1 := s.fold (\u2294) \u22a5\n\n@[simp] lemma sup_coe (l : list \u03b1) : sup (l : multiset \u03b1) = l.foldr (\u2294) \u22a5 := rfl\n\n@[simp] lemma sup_zero : (0 : multiset \u03b1).sup = \u22a5 :=\nfold_zero _ _\n\n@[simp] lemma sup_cons (a : \u03b1) (s : multiset \u03b1) :\n  (a ::\u2098 s).sup = a \u2294 s.sup :=\nfold_cons_left _ _ _ _\n\n@[simp] lemma sup_singleton {a : \u03b1} : ({a} : multiset \u03b1).sup = a :=\nsup_bot_eq\n\n@[simp] lemma sup_add (s\u2081 s\u2082 : multiset \u03b1) : (s\u2081 + s\u2082).sup = s\u2081.sup \u2294 s\u2082.sup :=\neq.trans (by simp [sup]) (fold_add _ _ _ _ _)\n\nlemma sup_le {s : multiset \u03b1} {a : \u03b1} : s.sup \u2264 a \u2194 (\u2200b \u2208 s, b \u2264 a) :=\nmultiset.induction_on s (by simp)\n  (by simp [or_imp_distrib, forall_and_distrib] {contextual := tt})\n\nlemma le_sup {s : multiset \u03b1} {a : \u03b1} (h : a \u2208 s) : a \u2264 s.sup :=\nsup_le.1 le_rfl _ h\n\nlemma sup_mono {s\u2081 s\u2082 : multiset \u03b1} (h : s\u2081 \u2286 s\u2082) : s\u2081.sup \u2264 s\u2082.sup :=\nsup_le.2 $ assume b hb, le_sup (h hb)\n\nvariables [decidable_eq \u03b1]\n\n@[simp] lemma sup_dedup (s : multiset \u03b1) : (dedup s).sup = s.sup :=\nfold_dedup_idem _ _ _\n\n@[simp] lemma sup_ndunion (s\u2081 s\u2082 : multiset \u03b1) :\n  (ndunion s\u2081 s\u2082).sup = s\u2081.sup \u2294 s\u2082.sup :=\nby rw [\u2190 sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp\n\n@[simp] lemma sup_union (s\u2081 s\u2082 : multiset \u03b1) :\n  (s\u2081 \u222a s\u2082).sup = s\u2081.sup \u2294 s\u2082.sup :=\nby rw [\u2190 sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp\n\n@[simp] lemma sup_ndinsert (a : \u03b1) (s : multiset \u03b1) :\n  (ndinsert a s).sup = a \u2294 s.sup :=\nby rw [\u2190 sup_dedup, dedup_ext.2, sup_dedup, sup_cons]; simp\n\nlemma nodup_sup_iff {\u03b1 : Type*} [decidable_eq \u03b1] {m : multiset (multiset \u03b1) } :\n  m.sup.nodup \u2194 \u2200 (a : multiset \u03b1), a \u2208 m \u2192 a.nodup :=\nbegin\n  apply m.induction_on,\n  { simp },\n  { intros a s h,\n    simp [h] }\nend\n\nend sup\n\n/-! ### inf -/\nsection inf\n-- can be defined with just `[has_top \u03b1]` where some lemmas hold without requiring `[order_top \u03b1]`\nvariables [semilattice_inf \u03b1] [order_top \u03b1]\n\n/-- Infimum of a multiset: `inf {a, b, c} = a \u2293 b \u2293 c` -/\ndef inf (s : multiset \u03b1) : \u03b1 := s.fold (\u2293) \u22a4\n\n@[simp] lemma inf_coe (l : list \u03b1) : inf (l : multiset \u03b1) = l.foldr (\u2293) \u22a4 := rfl\n\n@[simp] lemma inf_zero : (0 : multiset \u03b1).inf = \u22a4 :=\nfold_zero _ _\n\n@[simp] \n\n@[simp] lemma inf_singleton {a : \u03b1} : ({a} : multiset \u03b1).inf = a :=\ninf_top_eq\n\n@[simp] lemma inf_add (s\u2081 s\u2082 : multiset \u03b1) : (s\u2081 + s\u2082).inf = s\u2081.inf \u2293 s\u2082.inf :=\neq.trans (by simp [inf]) (fold_add _ _ _ _ _)\n\nlemma le_inf {s : multiset \u03b1} {a : \u03b1} : a \u2264 s.inf \u2194 (\u2200b \u2208 s, a \u2264 b) :=\nmultiset.induction_on s (by simp)\n  (by simp [or_imp_distrib, forall_and_distrib] {contextual := tt})\n\nlemma inf_le {s : multiset \u03b1} {a : \u03b1} (h : a \u2208 s) : s.inf \u2264 a :=\nle_inf.1 le_rfl _ h\n\nlemma inf_mono {s\u2081 s\u2082 : multiset \u03b1} (h : s\u2081 \u2286 s\u2082) : s\u2082.inf \u2264 s\u2081.inf :=\nle_inf.2 $ assume b hb, inf_le (h hb)\n\nvariables [decidable_eq \u03b1]\n\n@[simp] lemma inf_dedup (s : multiset \u03b1) : (dedup s).inf = s.inf :=\nfold_dedup_idem _ _ _\n\n@[simp] lemma inf_ndunion (s\u2081 s\u2082 : multiset \u03b1) :\n  (ndunion s\u2081 s\u2082).inf = s\u2081.inf \u2293 s\u2082.inf :=\nby rw [\u2190 inf_dedup, dedup_ext.2, inf_dedup, inf_add]; simp\n\n@[simp] lemma inf_union (s\u2081 s\u2082 : multiset \u03b1) :\n  (s\u2081 \u222a s\u2082).inf = s\u2081.inf \u2293 s\u2082.inf :=\nby rw [\u2190 inf_dedup, dedup_ext.2, inf_dedup, inf_add]; simp\n\n@[simp] lemma inf_ndinsert (a : \u03b1) (s : multiset \u03b1) :\n  (ndinsert a s).inf = a \u2293 s.inf :=\nby rw [\u2190 inf_dedup, dedup_ext.2, inf_dedup, inf_cons]; simp\n\nend inf\n\nend multiset\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/multiset/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7051299526935054}}
{"text": "theorem T2 (a b c d : \u2115) (h1 : a = b) (h2 : b \u2264 c) (h3 : c + 1 < d) : a < d :=\n  calc\n    a     = b     : h1\n      ... < b + 1 : nat.lt_succ_self b\n      ... \u2264 c + 1 : nat.succ_le_succ h2\n      ... < d     : h3\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0306.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741254760638, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.7050709510787709}}
{"text": "import mynat.mul -- hide\nnamespace mynat -- hide\n\n/-\n# Tutorial world\n\n## level 2: The rewrite (`rw`) tactic.\n\nThe rewrite tactic is the way to \"substitute in\" the value\nof a variable. In general, if you have a hypothesis of the form `A = B`, and your\ngoal mentions the left hand side `A` somewhere, then\nthe `rewrite` tactic will replace the `A` in your goal with a `B`.\nBelow is a theorem which cannot be\nproved using `refl` -- you need a rewrite first.\n\nDelete the sorry and take a look in the top right box at what we have.\nThe variables $x$ and $y$ are natural numbers, and we have\na proof `h` that $y = x + 7$. Our goal\nis to prove that $2y=2(x+7)$. This goal is obvious -- we just\nsubstitute in $y = x+7$ and we're done. In Lean, we do\nthis substitution using the `rw` tactic. So start your proof with \n\n`rw h,`\n\nand then hit enter. **Don't forget the comma.**\nDid you see what happened to the goal? The goal doesn't close,\nbut it *changes* from `\u22a2 2 * y = 2 * (x + 7)` to `\u22a2 2 * (x + 7) = 2 * (x + 7)`.\nWe can just close this goal with\n\n`refl,`\n\nby writing it on the line after `rw h,`. Don't forget the comma, hit\nenter, and enjoy seeing the \"Proof complete!\" message in the\ntop right window. The other reason you'll know you're\ndone is that the bottom right window (the error window)\nbecomes empty. When you've finished reading the comments below\nthe proof, click \"Next Level\" in the top right to proceed to the next\nlevel in this world.\n\n-/\n\n/- Lemma : no-side-bar\nIf $x$ and $y$ are natural numbers, \nand $y=x+7$, then $2y=2(x+7)$. \n-/\nlemma example2 (x y : mynat) (h : y = x + 7) : 2 * y = 2 * (x + 7) :=\nbegin [nat_num_game]\n  rw h,\n  refl\n  \n\nend\n\n/- Tactic : rw\n\n## Summary\n\nIf `h` is a proof of `X = Y`, then `rw h,` will change\nall `X`s in the goal to `Y`s. Variants: `rw \u2190 h` (changes\n`Y` to `X`) and\n`rw h at h2` (changes `X` to `Y` in hypothesis `h2` instead\nof the goal).\n\n## Details\n\nThe `rw` tactic is a way to do \"substituting in\". There\nare two distinct situations where use this tactics.\n\n1) If `h : A = B` is a hypothesis (i.e., a proof of `A = B`)\nin your local context (the box in the top right)\nand if your goal contains one or more `A`s, then `rw h`\nwill change them all to `B`'s. \n\n2) The `rw` tactic will also work with proofs of theorems\nwhich are equalities (look for them in the drop down\nmenu on the left, within Theorem Statements).\nFor example, in world 1 level 4\nwe learn about `add_zero x : x + 0 = x`, and `rw add_zero`\nwill change `x + 0` into `x` in your goal (or fail with\nan error if Lean cannot find `x + 0` in the goal).\n\nImportant note: if `h` is not a proof of the form `A = B`\nor `A \u2194 B` (for example if `h` is a function, an implication,\nor perhaps even a proposition itself rather than its proof),\nthen `rw` is not the tactic you want to use. For example,\n`rw (P = Q)` is never correct: `P = Q` is the true-false\nstatement itself, not the proof.\nIf `h : P = Q` is its proof, then `rw h` will work.\n\nPro tip 1: If `h : A = B` and you want to change\n`B`s to `A`s instead, try `rw \u2190h` (get the arrow with `\\l` and\nnote that this is a small letter L, not a number 1).\n\n### Example:\nIf it looks like this in the top right hand box:\n```\nx y : mynat\nh : x = y + y\n\u22a2 succ (x + 0) = succ (y + y)\n```\n\nthen\n\n`rw add_zero,`\n\nwill change the goal into `\u22a2 succ x = succ (y + y)`, and then\n\n`rw h,`\n\nwill change the goal into `\u22a2 succ (y + y) = succ (y + y)`, which\ncan be solved with `refl,`.\n\n### Example: \nYou can use `rw` to change a hypothesis as well. \nFor example, if your local context looks like this:\n```\nx y : mynat\nh1 : x = y + 3\nh2 : 2 * y = x\n\u22a2 y = 3\n```\nthen `rw h1 at h2` will turn `h2` into `h2 : 2 * y = y + 3`.\n-/\n\n/-\n\n## Exploring your proof.\n\nClick on `refl,` and then use the arrow keys to move\nyour cursor around the proof. Go up and down and note that\nthe goal changes -- indeed you can inspect Lean's \"state\" at each\nline of the proof (the hypotheses, and the goal).\nTry to figure out the exact place where the goal changes.\nThe comma tells Lean \"I've finished writing this tactic now,\nplease process it.\" Lean ignores newlines, but pays great\nattention to commas.\n\n## The tactic index\n\nThe documentation for `rw` just appeared in the list of tactics\nin the box on the left. Play around with the menus on the left\nand see what is there currently. More information will appear as you progress.\n\n## Bewildered?\n\nDoesn't work? Weird error that won't go away? You can check out\nthe \n<a href=\"https://github.com/ImperialCollegeLondon/natural_number_game/blob/master/SOLUTIONS.md\"\n  target=\"blank\">solutions</a> (github.com, opens in new window).\n  Solutions to every level are here.\n-/\n\nend mynat -- hide", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world1/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7050604755972131}}
{"text": "universe u\n\ndef f1 (n m : Nat) (x : Fin n) (h : n = m) : Fin m :=\nh \u25b8 x\n\ndef f2 (n m : Nat) (x : Fin n) (h : m = n) : Fin m :=\nh \u25b8 x\n\ntheorem ex1 {\u03b1 : Sort u} {a b c : \u03b1} (h\u2081 : a = b) (h\u2082 : b = c) : a = c :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex2 {\u03b1 : Sort u} {a b : \u03b1} (h : a = b) : b = a :=\nh \u25b8 rfl\n\ntheorem ex3 {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex3b {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082.symm \u25b8 h\u2081\n\ntheorem ex3c {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : r a b) (h\u2082 : b = c) : r a c :=\nh\u2082.symm.symm \u25b8 h\u2081\n\ntheorem ex4 {\u03b1 : Sort u} {a b c : \u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (h\u2081 : a = b) (h\u2082 : r b c) : r a c :=\nh\u2081 \u25b8 h\u2082\n\ntheorem ex5 {p : Prop} (h : p = True) : p :=\nh \u25b8 trivial\n\ntheorem ex6 {p : Prop} (h : p = False) : \u00acp :=\nfun hp => h \u25b8 hp\n\ntheorem ex7 {\u03b1} {a b c d : \u03b1} (h\u2081 : a = c) (h\u2082 : b = d) (h\u2083 : c \u2260 d) : a \u2260 b :=\nh\u2081 \u25b8 h\u2082 \u25b8 h\u2083\n\ntheorem ex8 (n m k : Nat) (h : Nat.succ n + m = Nat.succ n + k) : Nat.succ (n + m) = Nat.succ (n + k) :=\nNat.succ_add .. \u25b8 Nat.succ_add .. \u25b8 h\n\ntheorem ex9 (a b : Nat) (h\u2081 : a = a + b) (h\u2082 : a = b) : a = b + a  :=\nh\u2082 \u25b8 h\u2081\n\ntheorem ex10 (a b : Nat) (h : a = b) : b = a :=\nh \u25b8 rfl\n\ndef ex11  {\u03b1 : Type u} {n : Nat} (a : Array \u03b1) (i : Nat) (h\u2081 : a.size = n) (h\u2082 : i < n) : \u03b1 :=\n  a.get \u27e8i, h\u2081 \u25b8 h\u2082\u27e9\n\ntheorem ex12 {\u03b1 : Type u} {n : Nat}\n  (a b : Array \u03b1)\n  (hsz\u2081 : a.size = n) (hsz\u2082 : b.size = n)\n  (h : \u2200 (i : Nat) (hi : i < n), a.getLit i hsz\u2081 hi = b.getLit i hsz\u2082 hi) : a = b :=\nArray.ext a b (hsz\u2081.trans hsz\u2082.symm) fun i hi\u2081 hi\u2082 => h i (hsz\u2081 \u25b8 hi\u2081)\n\ndef toArrayLit {\u03b1 : Type u} (a : Array \u03b1) (n : Nat) (hsz : a.size = n) : Array \u03b1 :=\nList.toArray $ Array.toListLitAux a n hsz n (hsz \u25b8 Nat.leRefl _) []\n\npartial def isEqvAux {\u03b1} (a b : Array \u03b1) (hsz : a.size = b.size) (p : \u03b1 \u2192 \u03b1 \u2192 Bool) (i : Nat) : Bool :=\n  if h : i < a.size then\n     let aidx : Fin a.size := \u27e8i, h\u27e9\n     let bidx : Fin b.size := \u27e8i, hsz \u25b8 h\u27e9\n     match p (a.get aidx) (b.get bidx) with\n     | true  => isEqvAux a b hsz p (i+1)\n     | false => false\n  else\n    true\n", "meta": {"author": "JLimperg", "repo": "lean4-aesop", "sha": "5c4b9a3e05c32f69a4357c3047c274f4b94f9c71", "save_path": "github-repos/lean/JLimperg-lean4-aesop", "path": "github-repos/lean/JLimperg-lean4-aesop/lean4-aesop-5c4b9a3e05c32f69a4357c3047c274f4b94f9c71/tests/lean/run/subst.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7050604599528246}}
{"text": "-- import SciLean.Core.AdjDiff\nimport SciLean.Core.Defs\nimport SciLean.Core.Attributes\n\nnamespace SciLean.AutoDiffSimp\n\n\n-- Additional simp lemmas for automatic/symbolic differentiation\n\nattribute [diff_simp] mul_one one_mul zero_add add_zero\n\nattribute [diff_simp] fun_zero_eval fun_one_eval fun_neg_eval fun_add_eval fun_sub_eval fun_mul_eval fun_div_eval fun_hmul_eval\n\nsection VecSimps\nvariable {X} [Vec X]\n@[simp,diff_simp] theorem one_smul (x : X) : (1 : \u211d) \u2022 x = x := sorry_proof\n@[simp,diff_simp] theorem zero_smul (x : X) : (0 : \u211d) \u2022 x = (0 : X) := sorry_proof\n@[simp,diff_simp] theorem smul_zero (r : \u211d) : r \u2022 (0 : X) = (0 : X) := sorry_proof\n@[simp,diff_simp] theorem neg_one_smul (x : X) : (-1 : \u211d) \u2022 x = -x := sorry_proof\n\n@[simp,diff_simp] theorem add_neg_sub (x y : X) : x + -y = x - y := sorry_proof\n@[simp,diff_simp] theorem neg_add_sub (x y : X) : -x + y = y - x := sorry_proof\n\n@[simp,diff_simp] theorem smul_smul_mul (r s: \u211d) (x : X) : r \u2022 (s \u2022 x) = ((r * s) \u2022 x) := sorry_proof\n\n@[simp,diff_simp] theorem add_same_1 (a b : \u211d) (x : X) : a\u2022x + b\u2022x = (a+b)\u2022x := sorry_proof\n@[simp,diff_simp] theorem add_same_2 (a : \u211d) (x : X) : a\u2022x + x = (a+1)\u2022x := sorry_proof\n@[simp,diff_simp] theorem add_same_3 (a : \u211d) (x : X) : x + a\u2022x = (1+a)\u2022x := sorry_proof\n@[simp,diff_simp] theorem add_same_4 (x : X) : x + x = (2:\u211d)\u2022x := sorry_proof\n\n@[simp,diff_simp] theorem inner_real (x y : \u211d) : \u27eax,y\u27eb = x*y := by rfl; done\n\nend VecSimps\n\n\ninstance : Fact ((1:\u211d) \u2260 0) := sorry_proof\ninstance : Fact ((2:\u211d) \u2260 0) := sorry_proof\ninstance : Fact ((3:\u211d) \u2260 0) := sorry_proof\n\n@[simp, diff_simp]\ntheorem mul_val_recip (x y : \u211d) [Fact (x\u22600)] : x * (y/x) = y := sorry_proof\n\n@[simp, diff_simp]\ntheorem mul_val_recip_alt (x y z : \u211d) [Fact (x\u22600)] : x * (y/(x*z)) = y/z := sorry_proof\n\n@[simp, diff_simp]\ntheorem mul_recip_val (x y : \u211d) [Fact (x\u22600)]: (y/x) * x = 1 := sorry_proof\n\n@[simp, diff_simp]\ntheorem mul_recip_val_alt (x y z : \u211d) [Fact (x\u22600)]: (y/(x*z)) * x = y/z := sorry_proof\n\n\n\n\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/SciLean/Core/AutoDiffSimps.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7050325405067704}}
{"text": "/-\nCopyright (c) 2020 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport linear_algebra.matrix.adjugate\nimport ring_theory.matrix_algebra\nimport ring_theory.polynomial_algebra\nimport tactic.apply_fun\nimport tactic.squeeze\n\n/-!\n# Characteristic polynomials and the Cayley-Hamilton theorem\n\nWe define characteristic polynomials of matrices and\nprove the Cayley\u2013Hamilton theorem over arbitrary commutative rings.\n\nSee the file `matrix/charpoly/coeff` for corollaries of this theorem.\n\n## Main definitions\n\n* `matrix.charpoly` is the characteristic polynomial of a matrix.\n\n## Implementation details\n\nWe follow a nice proof from http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\n-/\n\nnoncomputable theory\n\nuniverses u v w\n\nopen polynomial matrix\nopen_locale big_operators polynomial\n\nvariables {R : Type u} [comm_ring R]\nvariables {n : Type w} [decidable_eq n] [fintype n]\n\nopen finset\n\n\n/--\nThe \"characteristic matrix\" of `M : matrix n n R` is the matrix of polynomials $t I - M$.\nThe determinant of this matrix is the characteristic polynomial.\n-/\ndef charmatrix (M : matrix n n R) : matrix n n R[X] :=\nmatrix.scalar n (X : R[X]) - (C : R \u2192+* R[X]).map_matrix M\n\n@[simp] lemma charmatrix_apply_eq (M : matrix n n R) (i : n) :\n  charmatrix M i i = (X : R[X]) - C (M i i) :=\nby simp only [charmatrix, sub_left_inj, pi.sub_apply, scalar_apply_eq,\n  ring_hom.map_matrix_apply, map_apply, dmatrix.sub_apply]\n\n@[simp] lemma charmatrix_apply_ne (M : matrix n n R) (i j : n) (h : i \u2260 j) :\n  charmatrix M i j = - C (M i j) :=\nby simp only [charmatrix, pi.sub_apply, scalar_apply_ne _ _ _ h, zero_sub,\n  ring_hom.map_matrix_apply, map_apply, dmatrix.sub_apply]\n\nlemma mat_poly_equiv_charmatrix (M : matrix n n R) :\n  mat_poly_equiv (charmatrix M) = X - C M :=\nbegin\n  ext k i j,\n  simp only [mat_poly_equiv_coeff_apply, coeff_sub, pi.sub_apply],\n  by_cases h : i = j,\n  { subst h, rw [charmatrix_apply_eq, coeff_sub],\n    simp only [coeff_X, coeff_C],\n    split_ifs; simp, },\n  { rw [charmatrix_apply_ne _ _ _ h, coeff_X, coeff_neg, coeff_C, coeff_C],\n    split_ifs; simp [h], }\nend\n\nlemma charmatrix_reindex {m : Type v} [decidable_eq m] [fintype m] (e : n \u2243 m)\n  (M : matrix n n R) : charmatrix (reindex e e M) = reindex e e (charmatrix M) :=\nbegin\n  ext i j x,\n  by_cases h : i = j,\n  all_goals { simp [h] }\nend\n\n/--\nThe characteristic polynomial of a matrix `M` is given by $\\det (t I - M)$.\n-/\ndef matrix.charpoly (M : matrix n n R) : R[X] :=\n(charmatrix M).det\n\nlemma matrix.charpoly_reindex {m : Type v} [decidable_eq m] [fintype m] (e : n \u2243 m)\n  (M : matrix n n R) : (reindex e e M).charpoly = M.charpoly :=\nbegin\n  unfold matrix.charpoly,\n  rw [charmatrix_reindex, matrix.det_reindex_self]\nend\n\n/--\nThe **Cayley-Hamilton Theorem**, that the characteristic polynomial of a matrix,\napplied to the matrix itself, is zero.\n\nThis holds over any commutative ring.\n\nSee `linear_map.aeval_self_charpoly` for the equivalent statement about endomorphisms.\n-/\n-- This proof follows http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\ntheorem matrix.aeval_self_charpoly (M : matrix n n R) :\n  aeval M M.charpoly = 0 :=\nbegin\n  -- We begin with the fact $\u03c7_M(t) I = adjugate (t I - M) * (t I - M)$,\n  -- as an identity in `matrix n n R[X]`.\n  have h : M.charpoly \u2022 (1 : matrix n n R[X]) =\n    adjugate (charmatrix M) * (charmatrix M) :=\n    (adjugate_mul _).symm,\n  -- Using the algebra isomorphism `matrix n n R[X] \u2243\u2090[R] polynomial (matrix n n R)`,\n  -- we have the same identity in `polynomial (matrix n n R)`.\n  apply_fun mat_poly_equiv at h,\n  simp only [mat_poly_equiv.map_mul,\n    mat_poly_equiv_charmatrix] at h,\n  -- Because the coefficient ring `matrix n n R` is non-commutative,\n  -- evaluation at `M` is not multiplicative.\n  -- However, any polynomial which is a product of the form $N * (t I - M)$\n  -- is sent to zero, because the evaluation function puts the polynomial variable\n  -- to the right of any coefficients, so everything telescopes.\n  apply_fun (\u03bb p, p.eval M) at h,\n  rw eval_mul_X_sub_C at h,\n  -- Now $\u03c7_M (t) I$, when thought of as a polynomial of matrices\n  -- and evaluated at some `N` is exactly $\u03c7_M (N)$.\n  rw [mat_poly_equiv_smul_one, eval_map] at h,\n  -- Thus we have $\u03c7_M(M) = 0$, which is the desired result.\n  exact h,\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/linear_algebra/matrix/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7050325227523884}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function World\n\n## Level 7: `(P \u2192 Q) \u2192 ((Q \u2192 F) \u2192 (P \u2192 F))`\n\nHave you noticed that, in stark contrast to earlier worlds,\nwe are not amassing a large collection of useful theorems?\nWe really are just constructing abstract levels with sets and\nfunctions, and then solving them and never using the results\never again. Here's another one, which should hopefully be\nvery easy for you now. Advanced mathematician viewers will\nknow it as contravariance of \\\\(\\operatorname{Hom}(\\cdot,F)\\\\)\nfunctor.\n\n## Definition\n\nWhatever the sets  `P ` and  `Q ` and  `F ` are, we\nmake an element of \\\\(\\operatorname{Hom}(\\operatorname{Hom}(P,Q),\n\\operatorname{Hom}(\\operatorname{Hom}(Q,F),\\operatorname{Hom}(P,F)))\\\\).\n-/\nexample (P Q F : Type) : (P \u2192 Q) \u2192 ((Q \u2192 F) \u2192 (P \u2192 F)) := by\n  intros f h p\n  apply h\n  apply f\n  exact p\n\n/-!\n\nNext up [Level 8](./Level8.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/FunctionWorld/Level7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611643025387, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.7050198891775644}}
{"text": "import algebra.field\nimport algebra.module\n\nuniverses u v w x\n\n--class has_scalar (F : Type u) (\u03b1 : Type v) := (smul : F \u2192 \u03b1 \u2192 \u03b1)\n\n--infixr ` \u2022 `:73 := has_scalar.smul\n\n-- modules for a ring\nclass vec_space (F : Type u) (\u03b1 : Type v) [field F] [add_comm_group \u03b1] \nextends has_scalar F \u03b1 :=\n(smul_add : \u2200 (r : F) (x y : \u03b1), r \u2022 (x + y) = r \u2022 x + r \u2022 y)\n(add_smul : \u2200(r s : F) (x : \u03b1), (r + s) \u2022 x = r \u2022 x + s \u2022 x)\n(mul_smul : \u2200 (r s : F) (x : \u03b1), (r * s) \u2022 x = r \u2022 s \u2022 x)\n(one_smul : \u2200 x : \u03b1, (1 : F) \u2022 x = x)\n\ninstance set_functions (F : Type u) (S : Type v) [field F] : add_comm_group (S \u2192 F) :=\n{ add := \u03bb f g, \u03bb x, f x + g x, -- (f + g)(x) = f(x) + g(x)\n  add_assoc := \u03bb a b c, funext (\u03bb x, add_assoc _ _ _),\n  zero := \u03bb x, (0 : F),\n  zero_add := \u03bb a, funext (\u03bb x, zero_add (a x)),\n  add_zero := \u03bb a, funext (\u03bb x, add_zero (a x)),\n  neg := \u03bb a, \u03bb x, -(a x),\n  add_left_neg := \u03bb a, funext (\u03bb x, neg_add_self (a x)),\n  add_comm := \u03bb a b, funext (\u03bb x, add_comm (a x) (b x))}\n\ninstance vec_space_pi (F : Type u) (S : Type v) [field F] : vec_space F (S \u2192 F) :=\n{ smul := \u03bb a, \u03bb f, \u03bb x, a * (f x),\n  smul_add := \u03bb a, \u03bb f g, funext (\u03bb x, mul_add a (f x) (g x)),\n  add_smul := \u03bb a b, \u03bb f, funext (\u03bb x, add_mul a b (f x)),\n  mul_smul := \u03bb a b, \u03bb f, funext (\u03bb x, mul_assoc a b (f x)),\n  one_smul := \u03bb f, funext (\u03bb x, one_mul (f x)) \n}\n\nlemma unique_add_id (\u03b1 : Type v) [add_comm_group \u03b1] : \n    \u2200 x : \u03b1, (\u2200 b : \u03b1, x + b = b) \u2192 x = 0 :=\nbegin\n    intros x hyp,\n    specialize hyp 0,\n    rw eq_comm at hyp,\n    rw hyp,\n    symmetry,\n    exact add_zero x,\nend\n\nlemma unique_add_inv (\u03b1 : Type v) [add_comm_group \u03b1] : \n    \u2200 x y : \u03b1, x + y = 0 \u2192 y = - x :=\nbegin\n    intros x y hyp,\n    rw \u2190 neg_add_self x at hyp,\n    rw add_comm (-x) x at hyp,\n    exact add_left_cancel hyp,\nend\n\nlemma zero_smul_zero (F : Type u) (\u03b1 : Type v) [field F] [add_comm_group \u03b1] [vec_space F \u03b1] :\n    \u2200 v : \u03b1, (0 : F) \u2022 v = 0 :=\nbegin\n    intro v, -- 0 \u2022 v = 0 -> 0 \u2022 v + v = v -> 0 \u2022 v + 1 \u2022 v = v -> (0 + 1) \u2022 v = v -> 1 \u2022 v = v\n    apply @add_right_cancel _ _ _ v,\n    rw \u2190 vec_space.one_smul v,\n    rw \u2190 vec_space.mul_smul,\n    rw zero_mul,\n    rw \u2190 vec_space.add_smul,\n    rw [zero_add, zero_add],\nend\n\n#check add_comm_group.neg\n\nlemma neg_one_mul' (F : Type u) (\u03b1 : Type v) [field F] [add_comm_group \u03b1] [vec_space F \u03b1] :\n    \u2200 v : \u03b1, ((-1) : F) \u2022 v = - v :=\nbegin\n    intro v,\n    apply @add_right_cancel _ _ _ v,\n    rw \u2190 vec_space.one_smul v,\n    rw \u2190 vec_space.mul_smul,\n    rw neg_add_self,\n    rw neg_one_mul,\n    rw \u2190 vec_space.add_smul,\n    rw neg_add_self,\n    apply zero_smul_zero,\nend\n\nlemma smul_zero_zero (F : Type u) (\u03b1 : Type v) [field F] [add_comm_group \u03b1] [vec_space F \u03b1] :\n    \u2200 a : F, a \u2022 (0 : \u03b1) = 0 :=\nbegin\n    intro a,\n    have hyp : (0 : \u03b1) = (a \u2022 0) + - (a \u2022 0) := by rw add_neg_self (a \u2022 (0 : \u03b1)),\n    conv_rhs {rw hyp},\n    rw \u2190 neg_one_mul' F _ (a \u2022 (0 : \u03b1)),\n    rw \u2190 vec_space.mul_smul,\n    rw mul_comm,\n    rw vec_space.mul_smul,\n    rw \u2190 vec_space.smul_add,\n    rw neg_one_mul',\n    rw add_neg_self,\nend", "meta": {"author": "agusakov", "repo": "vector_spaces", "sha": "b23954c19b357a689e2a73e07fcf6c9e4a74713a", "save_path": "github-repos/lean/agusakov-vector_spaces", "path": "github-repos/lean/agusakov-vector_spaces/vector_spaces-b23954c19b357a689e2a73e07fcf6c9e4a74713a/src/vec_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110483133801, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7050036788179845}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis is about the ideal of nilpotent elements in a commutative ring.\n\nIt is written in a somewhat constructive style, to allow us to keep\ntrack of nilpotence exponents:\n\n* `is_nilpotent a` is the proposition that `a` is nilpotent.\n\n* `as_nilpotent a` is the type of pairs `\u27e8n,h\u27e9` where `h` is a proof\n   that `a ^ n = 0`.  This type is nonempty iff `a` is nilpotent.\n   Note that we allow `n = 0`, but `a ^ 0 = 0` only holds if the \n   whole ring is trivial.\n\n* `w_nilradical A` is the type of triples `\u27e8a,\u27e8n,h\u27e9\u27e9`, where `h` is\n  a proof that `a ^ n = 0`.  The prefix `w_` is for \"witnessed\".\n\n* `nilradical A` is the ideal of nilpotent elements in `A`.  This\n  is represented as a structure with \n  `(nilradical A).carrier = is_nilpotent : A \u2192 Prop`.  There are\n  additional fields in the structure, which contain proofs that\n  this carrier contains zero and is closed under addition and \n  scalar multiplication.\n\n* Lifting this, we can introduce a zero element and addition and\n  scalar multiplication operations for `w_nilradical A`.  These \n  satisfy most of the usual identities except that \n  `0 \u2022 \u27e8a,n,h\u27e9 = \u27e80,n,_\u27e9`, and this can be different from \n  `0 = \u27e80,1,_\u27e9`,\n-/\n\nimport algebra.ring\nimport algebra.group_power algebra.geom_sum\nimport data.nat.choose\nimport ring_theory.ideal.basic ring_theory.ideal.quotient\n\nuniverse u\nvariables {A : Type u} [comm_ring A]\n\nnamespace commutative_algebra \n\ndef as_nilpotent (a : A) := {n : \u2115 // a ^ n = 0}\n\ndef as_nilpotent_congr {a b : A} (e : a = b)\n (ha : as_nilpotent a) : as_nilpotent b := \n  \u27e8ha.val,e \u25b8 ha.property\u27e9 \n\nlemma as_nilpotent_congr_exp {a b : A} (e : a = b)\n (ha : as_nilpotent a) : \n  (as_nilpotent_congr e ha).1 = ha.1 := rfl\n\ninductive is_nilpotent (a : A) : Prop\n| mk : (as_nilpotent a) \u2192 is_nilpotent\n\ndef as_nilpotent_zero : as_nilpotent (0 : A) := \u27e81,pow_one 0\u27e9\nlemma is_nilpotent_zero : is_nilpotent (0 : A) := \u27e8as_nilpotent_zero\u27e9\n\n/-- The meaning of the mul_exp function is as follows: \n if x ^ n = y ^ m = 0, then (x + y) ^ (mul_exp n m) = 0.\n Usually we just have (mul_exp n m) = n + m - 1, but if \n n or m is zero then the whole ring is necessarily trivial\n and so it is natural to take mul_exp n m = 0.  With this \n definition, it works out that the mul_exp operation gives \n a commutative monoid structure on \u2115, with 1 as the identity \n element.  We prove the commutative monoid laws but we do \n not define a comm_monoid instance, to avoid interfering \n with the standard multiplicative monoid structure on \u2115.\n-/\n\ndef mul_exp : \u2115 \u2192 \u2115 \u2192 \u2115 \n| 0 m := 0\n| (n + 1) 0 := 0\n| (n + 1) (m + 1) := n + m + 1\n\nnamespace mul_exp\n\nlemma zero_mul (m : \u2115) : mul_exp 0 m = 0 := rfl\nlemma mul_zero (n : \u2115) : mul_exp n 0 = 0 := by { cases n; refl }\nlemma one_mul (m : \u2115) : mul_exp 1 m = m := \nby { cases m, refl, change 0 + m + 1 = m + 1, rw[nat.zero_add] }\nlemma mul_one (n : \u2115) : mul_exp n 1 = n := \nby { cases n; refl }\n\nlemma mul_comm (n m : \u2115) : mul_exp n m = mul_exp m n := \n by {cases n; cases m; dsimp[mul_exp]; try {refl}, rw[add_comm n m]}\n\nlemma mul_assoc (n m p : \u2115) :\n mul_exp (mul_exp n m) p = mul_exp n (mul_exp m p) := \nby { cases n; cases m; cases p; dsimp[mul_exp]; try {refl},\n     repeat{rw[add_assoc]},}\n\nend mul_exp\n\nlemma nilpotent_add_aux {a b : A} {n m : \u2115} \n(ea : a ^ n = 0) (eb : b ^ m = 0) : (a + b) ^ (mul_exp n m) = 0 := \nbegin \n  have hz : (1 : A) = 0 \u2192 (\u2200 (x : A), x = 0) := \n    \u03bb h x, by { rw[\u2190 mul_one x, h, mul_zero] },\n  rcases n with \u27e8_|n\u27e9,\n  { rw [pow_zero] at ea, exact hz ea _ },\n  rcases m with \u27e8_|m\u27e9,\n  { rw[pow_zero] at eb, exact hz eb _ },\n  have : mul_exp n.succ m.succ = n + m + 1 := rfl,\n  rw [this, add_pow],\n  rw[\u2190 @finset.sum_const_zero A \u2115 (finset.range (n + m + 1).succ)],\n  congr, ext i,\n  by_cases hi : i \u2265 n + 1,\n  { rw[\u2190 nat.add_sub_of_le hi,pow_add,ea],\n    repeat {rw[zero_mul]} },\n  { replace hi := nat.le_of_lt_succ (lt_of_not_ge hi),\n    have := nat.add_sub_of_le hi,\n    have : n + m + 1 - i = (m + 1) + (n - i) :=\n      by rw [\u2190 this, add_comm i, add_assoc, nat.add_sub_cancel,\n             add_assoc, add_comm i, \u2190 add_assoc, \n             nat.add_sub_cancel, add_comm],\n    rw [this, pow_add, eb, zero_mul, mul_zero, zero_mul] }\nend\n\ndef as_nilpotent_add {a b : A}\n (ha : as_nilpotent a) (hb : as_nilpotent b) : as_nilpotent (a + b) := \n\u27e8mul_exp ha.val hb.val, nilpotent_add_aux ha.property hb.property\u27e9\n\nlemma as_nilpotent_add_exp {a b : A}\n(ha : as_nilpotent a) (hb : as_nilpotent b) : \n(as_nilpotent_add ha hb).1 = mul_exp ha.1 hb.1 := rfl\n\nlemma is_nilpotent_add {a b : A} : \n  is_nilpotent a \u2192 is_nilpotent b \u2192 is_nilpotent (a + b) := \n\u03bb \u27e8ha\u27e9 \u27e8hb\u27e9, \u27e8as_nilpotent_add ha hb\u27e9\n\ndef as_nilpotent_smul (a : A) {b : A}  \n  (hb : as_nilpotent b) : as_nilpotent (a * b) := \n\u27e8hb.1,by { rw [mul_pow, hb.2, mul_zero] }\u27e9 \n\nlemma as_nilpotent_smul_exp (a : A) {b : A} (hb : as_nilpotent b) : \n  (as_nilpotent_smul a hb).1 = hb.1 := rfl\n\nlemma is_nilpotent_smul (a : A) {b : A} : \n  is_nilpotent b \u2192 is_nilpotent (a * b) :=\n\u03bb \u27e8hb\u27e9, \u27e8as_nilpotent_smul a hb\u27e9 \n\ndef as_nilpotent_neg {b : A} : \n  as_nilpotent b \u2192 as_nilpotent (-b) := \n\u03bb h, as_nilpotent_congr (neg_eq_neg_one_mul b).symm (as_nilpotent_smul (-1) h)\n\nlemma as_nilpotent_neg_exp {a : A} (ha : as_nilpotent a) : \n  (as_nilpotent_neg ha).1 = ha.1 := \nby { rw[ \u2190 as_nilpotent_smul_exp (-1) ha],\n     rw[ \u2190 as_nilpotent_congr_exp (neg_eq_neg_one_mul a).symm (as_nilpotent_smul (-1) ha)],\n     refl }\n\nlemma is_nilpotent_neg {b : A} : \n  is_nilpotent b \u2192 is_nilpotent (-b) := \n\u03bb \u27e8hb\u27e9, \u27e8as_nilpotent_neg hb\u27e9 \n\ndef as_nilpotent_sub {a b : A} \n  (ha : as_nilpotent a) (hb : as_nilpotent b) : as_nilpotent (a - b) := \nas_nilpotent_congr (sub_eq_add_neg a b).symm (as_nilpotent_add ha (as_nilpotent_neg hb))\n\nlemma as_nilpotent_sub_exp {a b : A}\n  (ha : as_nilpotent a) (hb : as_nilpotent b) : \n  (as_nilpotent_sub ha hb).1 = mul_exp ha.1 hb.1 := \nby { \n  rw [\u2190 as_nilpotent_neg_exp hb, \u2190 as_nilpotent_add_exp ha (as_nilpotent_neg hb)], \n  dsimp[as_nilpotent_sub], refl\n}\n\nlemma is_nilpotent_sub {a b : A} : \n  is_nilpotent a \u2192 is_nilpotent b \u2192 is_nilpotent (a - b) := \n\u03bb \u27e8ha\u27e9 \u27e8hb\u27e9, \u27e8as_nilpotent_sub ha hb\u27e9 \n\ndef as_nilpotent_chain {a : A} {n : \u2115} :\n  as_nilpotent (a ^ n) \u2192 as_nilpotent a\n| \u27e8m,ha\u27e9 := \u27e8n * m,(pow_mul a n m).symm \u25b8 ha\u27e9  \n\nlemma is_nilpotent_chain {a : A} {n : \u2115} : \n  is_nilpotent (a ^ n) \u2192 is_nilpotent a := \n\u03bb \u27e8ha\u27e9, \u27e8as_nilpotent_chain ha\u27e9\n\nvariable (A)\ndef w_nilradical := \u03a3 (a : A), as_nilpotent a\nvariable {A}\n\nnamespace w_nilradical\n\nvariables (a b c : w_nilradical A)\n\ninstance : has_coe (w_nilradical A) A := \u27e8\u03bb a, a.1\u27e9\n\ndef exp : \u2115 := a.2.val\n\ndef prop : (a : A) ^ a.exp = 0 := a.2.property\n\n@[ext]\nlemma ext : \u2200 {a b : w_nilradical A},\n (a : A) = (b : A) \u2192 a.exp = b.exp \u2192 a = b := \nbegin\n rintro \u27e8a,\u27e8n,ha\u27e9\u27e9 \u27e8b,\u27e8m,hb\u27e9\u27e9 hv he,\n change a = b at hv, dsimp[exp] at he, rw[hv] at ha,\n cases hv,cases he,refl,\nend\n\ninstance : has_zero (w_nilradical A) := \u27e8\u27e8(0 : A),as_nilpotent_zero\u27e9\u27e9 \n\nlemma zero_coe : ((0 : w_nilradical A) : A) = 0 := rfl\nlemma zero_exp : (0 : w_nilradical A).exp = 1 := rfl\n\ninstance : has_add (w_nilradical A) := \n\u27e8\u03bb a b, \u27e8a.1 + b.1,as_nilpotent_add a.2 b.2\u27e9\u27e9  \n\nlemma add_coe : ((a + b : w_nilradical A) : A) = a + b := rfl\nlemma exp_add : (a + b).exp = mul_exp a.exp b.exp := rfl\n\ninstance : has_scalar A (w_nilradical A) := \n\u27e8\u03bb a b, \u27e8a * b.1,as_nilpotent_smul a b.2\u27e9\u27e9 \n\nlemma smul_coe (a : A) (b : w_nilradical A) : ((a \u2022 b) : A) = a * b := rfl\nlemma exp_smul (a : A) (b : w_nilradical A) : (a \u2022 b).exp = b.exp := rfl\n\ninstance : has_neg (w_nilradical A) := \n\u27e8\u03bb a, \u27e8-a.1, as_nilpotent_neg a.2\u27e9\u27e9\n\nlemma neg_coe : ((- a : w_nilradical A) : A) = - a := rfl\nlemma exp_neg : (- a).exp = a.exp := rfl\n\ninstance : has_sub (w_nilradical A) := \n\u27e8\u03bb a b, \u27e8a.1 - b.1,as_nilpotent_sub a.2 b.2\u27e9\u27e9  \n\nlemma sub_coe : ((a - b : w_nilradical A) : A) = a - b := rfl\nlemma exp_sub (a b : w_nilradical A) : (a - b).exp = mul_exp a.exp b.exp := \n as_nilpotent_sub_exp a.2 b.2\n\ninstance : add_comm_monoid (w_nilradical A) := {\n  zero := has_zero.zero,\n  add := (+),\n  zero_add := \u03bb a,\n   by {ext, rw[add_coe,zero_coe,zero_add], \n            rw[exp_add,zero_exp,mul_exp.one_mul]},\n  add_zero := \u03bb a, \n   by {ext, rw[add_coe,zero_coe,add_zero], \n            rw[exp_add,zero_exp,mul_exp.mul_one]},\n  add_comm := \u03bb a b, \n   by {ext, rw[add_coe,add_coe,add_comm],rw[exp_add,exp_add,mul_exp.mul_comm]},\n  add_assoc := \u03bb a b c,\n   by {ext, \n       {repeat {rw[add_coe]}, rw[add_assoc]},\n       {repeat {rw[exp_add]}, rw[mul_exp.mul_assoc]}\n      }\n}\n\nlemma smul_zero (a : A) : a \u2022 (0 : w_nilradical A) = 0 := \n by {ext, change (a * 0 : A) = 0, exact mul_zero a,rw[exp_smul]}\n\nlemma smul_add (a : A) (b c : w_nilradical A) : a \u2022 (b + c) = (a \u2022 b) + (a \u2022 c) := \n by {ext,\n     change (a * (b + c) : A) = a * b + a * c, apply mul_add,\n     rw[exp_smul,exp_add,exp_add,exp_smul,exp_smul]}\n\nlemma one_smul (b : w_nilradical A) : (1 : A) \u2022 b = b := \n by {ext, change (1 * b : A) = b, apply one_mul, rw[exp_smul]}\n\nlemma mul_smul (a b : A) (c : w_nilradical A) : (a * b) \u2022 c = a \u2022 (b \u2022 c) := \n by {ext, change ((a * b) * c : A) = a * (b * c), apply mul_assoc,\n     rw[exp_smul,exp_smul,exp_smul]}\n\n/- Neither zero_smul or add_smul are satisfied in this context -/\n\nend w_nilradical\n\nvariable (A)\n\ndef is_reduced: Prop := \u2200 (x : A), (is_nilpotent x) \u2192 (x = 0)\n\ndef nilradical : ideal A := {\n  carrier := is_nilpotent,\n  zero_mem' := is_nilpotent_zero,\n  add_mem' := \u03bb _ _, is_nilpotent_add,\n  smul_mem' := \u03bb (a : A) {b : A} (hb : is_nilpotent b),is_nilpotent_smul a hb\n}\n\nlemma mem_nilradical (x : A) : x \u2208 nilradical A \u2194 is_nilpotent x := \n by {refl}\n\ndef reduced_quotient := A \u29f8 (nilradical A)\n\nnamespace reduced_quotient\n\ninstance : comm_ring (reduced_quotient A) := \n  by { dsimp[reduced_quotient]; apply_instance }\n\nvariable {A}\n\ndef mk : A \u2192+* reduced_quotient A := ideal.quotient.mk (nilradical A)\n\nlemma mk_eq_zero_iff {x : A} : mk x = 0 \u2194 (is_nilpotent x) :=\n ideal.quotient.eq_zero_iff_mem\n\nlemma is_reduced : is_reduced (reduced_quotient A) :=\nbegin\n rintros \u27e8x0\u27e9 \u27e8n,e0\u27e9,\n change (mk x0) ^ n = 0 at e0,\n rw[\u2190 (map_pow mk x0 n)] at e0,\n rcases (mk_eq_zero_iff.mp e0) with \u27e8m,e1\u27e9,\n rw[\u2190 pow_mul] at e1,\n apply mk_eq_zero_iff.mpr,\n exact \u27e8\u27e8n * m, e1\u27e9\u27e9,\nend\n\nend reduced_quotient\n\nvariable {A}\n\nlemma unit_not_nilpotent (a b : A) :\n (a * b = 1) \u2192 ((1 : A) \u2260 0) \u2192  \u00ac is_nilpotent a := \n\u03bb hab hz \u27e8\u27e8m,ha\u27e9\u27e9,\n hz (by {rw[\u2190 _root_.one_pow m,\u2190 hab,mul_pow,ha,zero_mul]})\n\nlemma one_sub_nilpotent_aux {a : A} {n : \u2115} (ha : a ^ n = 0) :\n (1 - a) * (geom_sum a n) = 1 := \nby rw[mul_neg_geom_sum, ha, sub_zero]\n \nlemma unit_add_nilpotent_aux {u v a : A} {n : \u2115}\n (hu : u * v = 1) (ha : a ^ n = 0) :\n  (u + a) * (v * (finset.range n).sum (\u03bb i, (- v * a) ^ i)) = 1 := \nbegin\n rw[\u2190 mul_assoc,add_mul,hu,mul_comm a v,\u2190 sub_neg_eq_add 1 (v * a),neg_mul_eq_neg_mul],\n let h\u2080 : (- v * a) ^ n = 0 := by {rw[mul_pow,ha,mul_zero],},\n exact one_sub_nilpotent_aux h\u2080,\nend\n\ndef unit_add_nilpotent (u : units A) (a : w_nilradical A) : units A := {\n val := u + a,\n inv := u.inv * (finset.range a.exp).sum (\u03bb i, (- u.inv * a) ^ i),\n val_inv := unit_add_nilpotent_aux u.val_inv a.prop,\n inv_val := (mul_comm _ _).trans (unit_add_nilpotent_aux u.val_inv a.prop)\n}\n\nlemma unit_add_nilpotent_coe (u : units A) (a : w_nilradical A) : \n (unit_add_nilpotent u a).val = u + a := rfl\n\nend commutative_algebra", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/commutative_algebra/nilpotent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7050036765448539}}
{"text": "import data.set.finite data.pnat.basic tactic.ring\n\n/-! # IMO 2013 N3, Generalized Version -/\n\nnamespace IMOSL\nnamespace IMO2013N3\n\nvariables {S : Type*} [linear_order S]\n\ndef good (f : \u2115+ \u2192 S) (n : \u2115+) := f (n ^ 4 + n ^ 2 + 1) = f ((n + 1) ^ 4 + (n + 1) ^ 2 + 1)\n\n\n\n/-- Proof of the identity `(n + 1)\u2074 + (n + 1)\u00b2 + 1 = (n\u00b2 + n + 1)((n + 1)\u00b2 + (n + 1) + 1)`. -/\nprivate lemma special_identity (n : \u2115+) :\n  ((n + 1) ^ 2) ^ 2 + (n + 1) ^ 2 + 1 = (n ^ 2 + n + 1) * ((n + 1) ^ 2 + (n + 1) + 1) :=\n  by apply pnat.eq; simp only [positive.coe_one, pnat.mul_coe, pnat.pow_coe, pnat.add_coe]; ring\n\n\n\n/-- Final solution -/\ntheorem final_solution_general {f : \u2115+ \u2192 S} (h : \u2200 a b : \u2115+, f (a * b) = max (f a) (f b)) :\n  set.infinite (set_of (good f)) :=\nbegin\n  ---- Set `g(n) = f(n^2 + n + 1)` and re-interpret in terms of `g` instead of `f`\n  apply set.infinite_of_not_bdd_above; rintros \u27e8N, h0\u27e9,\n  simp_rw [upper_bounds, set.mem_set_of, good] at h0,\n  let T := \u03bb n : \u2115+, n ^ 2 + n + 1,\n  replace h : \u2200 n : \u2115+, (f \u2218 T) ((n + 1) ^ 2) = max ((f \u2218 T) n) ((f \u2218 T) (n + 1)) :=\n    \u03bb n, by simp_rw [function.comp_app, T]; rw [special_identity, h],\n  replace h0 : \u2200 n : \u2115+, (f \u2218 T) (n ^ 2) = (f \u2218 T) ((n + 1) ^ 2) \u2192 n \u2264 N :=\n    \u03bb n, by simp_rw [function.comp_app, T, \u2190 pow_mul]; rw [two_mul, \u2190 bit0]; exact @h0 n,\n  generalize_hyp : f \u2218 T = g at h h0,\n  clear f T,\n\n  ---- For all `n \u2265 N`, `g(n) \u2264 g(n + 1)` implies `g(n + 1) < g(n + 2)`\n  replace h0 : \u2200 n, N \u2264 n \u2192 g n \u2264 g (n + 1) \u2192 g (n + 1) < g (n + 1 + 1) :=\n  begin\n    intros n h1 h2; contrapose! h0,\n    refine \u27e8n + 1, _, pnat.lt_add_one_iff.mpr h1\u27e9,\n    rw [h, max_eq_right h2, h, max_eq_left h0],\n  end,\n\n  ---- There exists `C \u2265 N` such that `g(C) \u2264 g(C + 1)`\n  obtain \u27e8C, h1, h2\u27e9 : \u2203 C : \u2115+, N \u2264 C \u2227 g C \u2264 g (C + 1) :=\n  begin\n    replace h : g (N + 1) \u2264 g ((N + 1) ^ 2) :=\n      by rw h; exact le_max_right (g N) (g (N + 1)),\n    contrapose! h; rw [sq, mul_add_one, add_comm _ (N + 1)],\n    generalize : (N + 1) * N = k,\n    induction k using pnat.case_strong_induction_on with k h1,\n    exact h (N + 1) (le_of_lt (N.lt_add_right 1)),\n    rw \u2190 add_assoc; refine lt_trans (h _ _) (h1 k (le_refl k)),\n    rw add_assoc; exact le_of_lt (N.lt_add_right (1 + k))\n  end,\n  \n  ---- Reduce to showing `g(C + 1) < g(C + 1 + k)` for all `k > 0`\n  replace h := h C,\n  rw [max_eq_right h2, sq, mul_add_one, add_comm _ (C + 1)] at h,\n  generalize_hyp : (C + 1) * C = k at h,\n  revert h; apply ne_of_gt; revert k,\n\n  ---- Final step via two inductions\n  replace h0 : \u2200 k : \u2115+, g (C + k) < g (C + k + 1) :=\n  begin\n    intros k; induction k using pnat.case_strong_induction_on with k h3,\n    exact h0 C h1 h2,\n    rw \u2190 add_assoc,\n    exact h0 _ (le_trans h1 (le_of_lt (C.lt_add_right k))) (le_of_lt (h3 k (le_refl k)))\n  end,\n\n  clear h1 h2 N,\n  intros k; induction k using pnat.case_strong_induction_on with k h,\n  exact h0 1,\n  rw \u2190 add_assoc; refine lt_trans (h k (le_refl k)) _,\n  rw add_assoc; exact h0 (1 + k)\nend\n\nend IMO2013N3\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2013/N3/N3_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7050036632689372}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n\n! This file was ported from Lean 3 source module number_theory.class_number.function_field\n! leanprover-community/mathlib commit d0259b01c82eed3f50390a60404c63faf9e60b1f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.NumberTheory.ClassNumber.AdmissibleCardPowDegree\nimport Mathbin.NumberTheory.ClassNumber.Finite\nimport Mathbin.NumberTheory.FunctionField\n\n/-!\n# Class numbers of function fields\n\nThis file defines the class number of a function field as the (finite) cardinality of\nthe class group of its ring of integers. It also proves some elementary results\non the class number.\n\n## Main definitions\n- `function_field.class_number`: the class number of a function field is the (finite)\ncardinality of the class group of its ring of integers\n-/\n\n\nnamespace FunctionField\n\nopen Polynomial\n\nvariable (Fq F : Type) [Field Fq] [Fintype Fq] [Field F]\n\nvariable [Algebra Fq[X] F] [Algebra (Ratfunc Fq) F]\n\nvariable [IsScalarTower Fq[X] (Ratfunc Fq) F]\n\nvariable [FunctionField Fq F] [IsSeparable (Ratfunc Fq) F]\n\nopen Classical\n\nnamespace RingOfIntegers\n\nopen FunctionField\n\nnoncomputable instance : Fintype (ClassGroup (ringOfIntegers Fq F)) :=\n  ClassGroup.fintypeOfAdmissibleOfFinite (Ratfunc Fq) F\n    (Polynomial.cardPowDegreeIsAdmissible :\n      AbsoluteValue.IsAdmissible (Polynomial.cardPowDegree : AbsoluteValue Fq[X] \u2124))\n\nend RingOfIntegers\n\n/-- The class number in a function field is the (finite) cardinality of the class group. -/\nnoncomputable def classNumber : \u2115 :=\n  Fintype.card (ClassGroup (ringOfIntegers Fq F))\n#align function_field.class_number FunctionField.classNumber\n\n/-- The class number of a function field is `1` iff the ring of integers is a PID. -/\ntheorem classNumber_eq_one_iff :\n    classNumber Fq F = 1 \u2194 IsPrincipalIdealRing (ringOfIntegers Fq F) :=\n  card_classGroup_eq_one_iff\n#align function_field.class_number_eq_one_iff FunctionField.classNumber_eq_one_iff\n\nend FunctionField\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/ClassNumber/FunctionField.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7050036631237899}}
{"text": "/-\nCopyright (c) 2022 R\u00e9mi Bottinelli. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9mi Bottinelli\n\n! This file was ported from Lean 3 source module category_theory.groupoid.vertex_group\n! leanprover-community/mathlib commit 47b51515e69f59bca5cf34ef456e6000fe205a69\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.CategoryTheory.Groupoid\nimport Mathlib.CategoryTheory.PathCategory\nimport Mathlib.Algebra.Group.Defs\nimport Mathlib.Algebra.Hom.Group\nimport Mathlib.Algebra.Hom.Equiv.Basic\nimport Mathlib.Combinatorics.Quiver.Path\n\n/-!\n# Vertex group\n\nThis file defines the vertex group (*aka* isotropy group) of a groupoid at a vertex.\n\n## Implementation notes\n\n* The instance is defined \"manually\", instead of relying on `CategoryTheory.Aut.group` or\n  using `CategoryTheory.inv`.\n* The multiplication order therefore matches the categorical one: `x * y = x \u226b y`.\n* The inverse is directly defined in terms of the groupoidal inverse: `x \u207b\u00b9 = Groupoid.inv x`.\n\n## Tags\n\nisotropy, vertex group, groupoid\n-/\n\n\nnamespace CategoryTheory\n\nnamespace Groupoid\n\nuniverse u v\n\nvariable {C : Type u} [Groupoid C]\n\n/-- The vertex group at `c`. -/\n@[simps mul one inv]\ninstance vertexGroup (c : C) : Group (c \u27f6 c) where\n  mul := fun x y : c \u27f6 c => x \u226b y\n  mul_assoc := Category.assoc\n  one := \ud835\udfd9 c\n  one_mul := Category.id_comp\n  mul_one := Category.comp_id\n  inv := Groupoid.inv\n  mul_left_inv := inv_comp\n#align category_theory.groupoid.vertex_group CategoryTheory.Groupoid.vertexGroup\n\n/-- The inverse in the group is equal to the inverse given by `CategoryTheory.inv`. -/\ntheorem vertexGroup.inv_eq_inv (c : C) (\u03b3 : c \u27f6 c) : \u03b3\u207b\u00b9 = CategoryTheory.inv \u03b3 :=\n  Groupoid.inv_eq_inv \u03b3\n#align category_theory.groupoid.vertex_group.inv_eq_inv CategoryTheory.Groupoid.vertexGroup.inv_eq_inv\n\n/-- An arrow in the groupoid defines, by conjugation, an isomorphism of groups between\nits endpoints.\n-/\n@[simps]\ndef vertexGroupIsomOfMap {c d : C} (f : c \u27f6 d) : (c \u27f6 c) \u2243* (d \u27f6 d)\n    where\n  toFun \u03b3 := inv f \u226b \u03b3 \u226b f\n  invFun \u03b4 := f \u226b \u03b4 \u226b inv f\n  left_inv \u03b3 := by\n    simp_rw [Category.assoc, comp_inv, Category.comp_id, \u2190 Category.assoc, comp_inv,\n      Category.id_comp]\n  right_inv \u03b4 := by\n    simp_rw [Category.assoc, inv_comp, \u2190 Category.assoc, inv_comp, Category.id_comp,\n      Category.comp_id]\n  map_mul' \u03b3\u2081 \u03b3\u2082 := by\n    simp only [vertexGroup_mul, inv_eq_inv, Category.assoc, IsIso.hom_inv_id_assoc]\n#align category_theory.groupoid.vertex_group_isom_of_map CategoryTheory.Groupoid.vertexGroupIsomOfMap\n\n/-- A path in the groupoid defines an isomorphism between its endpoints.\n-/\ndef vertexGroupIsomOfPath {c d : C} (p : Quiver.Path c d) : (c \u27f6 c) \u2243* (d \u27f6 d) :=\n  vertexGroupIsomOfMap (composePath p)\n#align category_theory.groupoid.vertex_group_isom_of_path CategoryTheory.Groupoid.vertexGroupIsomOfPath\n\n/-- A functor defines a morphism of vertex group. -/\n@[simps]\ndef CategoryTheory.Functor.mapVertexGroup {D : Type v} [Groupoid D] (\u03c6 : C \u2964 D) (c : C) :\n    (c \u27f6 c) \u2192* (\u03c6.obj c \u27f6 \u03c6.obj c) where\n  toFun := \u03c6.map\n  map_one' := \u03c6.map_id c\n  map_mul' := \u03c6.map_comp\n#align category_theory.functor.map_vertex_group CategoryTheory.Groupoid.CategoryTheory.Functor.mapVertexGroup\n\nend Groupoid\n\nend CategoryTheory\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Groupoid/VertexGroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7049678227862481}}
{"text": "/-\nCopyright (c) 2019 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\nimport algebra.associated\nimport algebra.regular.basic\nimport linear_algebra.matrix.mv_polynomial\nimport linear_algebra.matrix.polynomial\nimport ring_theory.polynomial.basic\nimport tactic.linarith\nimport tactic.ring_exp\n\n/-!\n# Cramer's rule and adjugate matrices\n\nThe adjugate matrix is the transpose of the cofactor matrix.\nIt is calculated with Cramer's rule, which we introduce first.\nThe vectors returned by Cramer's rule are given by the linear map `cramer`,\nwhich sends a matrix `A` and vector `b` to the vector consisting of the\ndeterminant of replacing the `i`th column of `A` with `b` at index `i`\n(written as `(A.update_column i b).det`).\nUsing Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`.\nThe entries of the adjugate are the determinants of each minor of `A`.\nInstead of defining a minor to be `A` with row `i` and column `j` deleted, we\nreplace the `i`th row of `A` with the `j`th basis vector; this has the same\ndeterminant as the minor but more importantly equals Cramer's rule applied\nto `A` and the `j`th basis vector, simplifying the subsequent proofs.\nWe prove the adjugate behaves like `det A \u2022 A\u207b\u00b9`.\n\n## Main definitions\n\n * `matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`.\n * `matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`.\n\n## References\n\n  * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix\n\n## Tags\n\ncramer, cramer's rule, adjugate\n-/\n\nnamespace matrix\nuniverses u v\nvariables {n : Type u} [decidable_eq n] [fintype n] {\u03b1 : Type v} [comm_ring \u03b1]\nopen_locale matrix big_operators polynomial\nopen equiv equiv.perm finset\n\nsection cramer\n/-!\n  ### `cramer` section\n\n  Introduce the linear map `cramer` with values defined by `cramer_map`.\n  After defining `cramer_map` and showing it is linear,\n  we will restrict our proofs to using `cramer`.\n-/\nvariables (A : matrix n n \u03b1) (b : n \u2192 \u03b1)\n\n/--\n  `cramer_map A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,\n  and thus `cramer_map A b` is the vector output by Cramer's rule on `A` and `b`.\n\n  If `A \u2b1d x = b` has a unique solution in `x`, `cramer_map A` sends the vector `b` to `A.det \u2022 x`.\n  Otherwise, the outcome of `cramer_map` is well-defined but not necessarily useful.\n-/\ndef cramer_map (i : n) : \u03b1 := (A.update_column i b).det\n\nlemma cramer_map_is_linear (i : n) : is_linear_map \u03b1 (\u03bb b, cramer_map A b i) :=\n{ map_add := det_update_column_add _ _,\n  map_smul := det_update_column_smul _ _ }\n\nlemma cramer_is_linear : is_linear_map \u03b1 (cramer_map A) :=\nbegin\n  split; intros; ext i,\n  { apply (cramer_map_is_linear A i).1 },\n  { apply (cramer_map_is_linear A i).2 }\nend\n\n/--\n  `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,\n  and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`.\n\n  If `A \u2b1d x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det \u2022 x`.\n  Otherwise, the outcome of `cramer` is well-defined but not necessarily useful.\n -/\ndef cramer (A : matrix n n \u03b1) : (n \u2192 \u03b1) \u2192\u2097[\u03b1] (n \u2192 \u03b1) :=\nis_linear_map.mk' (cramer_map A) (cramer_is_linear A)\n\nlemma cramer_apply (i : n) : cramer A b i = (A.update_column i b).det := rfl\n\nlemma cramer_transpose_apply (i : n) : cramer A\u1d40 b i = (A.update_row i b).det :=\nby rw [cramer_apply, update_column_transpose, det_transpose]\n\nlemma cramer_transpose_row_self (i : n) :\n  A\u1d40.cramer (A i) = pi.single i A.det :=\nbegin\n  ext j,\n  rw [cramer_apply, pi.single_apply],\n  split_ifs with h,\n  { -- i = j: this entry should be `A.det`\n    subst h,\n    simp only [update_column_transpose, det_transpose, update_row, function.update_eq_self] },\n  { -- i \u2260 j: this entry should be 0\n    rw [update_column_transpose, det_transpose],\n    apply det_zero_of_row_eq h,\n    rw [update_row_self, update_row_ne (ne.symm h)] }\nend\n\nlemma cramer_row_self (i : n) (h : \u2200 j, b j = A j i) :\n  A.cramer b = pi.single i A.det :=\nbegin\n  rw [\u2190 transpose_transpose A, det_transpose],\n  convert cramer_transpose_row_self A\u1d40 i,\n  exact funext h\nend\n\n@[simp] lemma cramer_one : cramer (1 : matrix n n \u03b1) = 1 :=\nbegin\n  ext i j,\n  convert congr_fun (cramer_row_self (1 : matrix n n \u03b1) (pi.single i 1) i _) j,\n  { simp },\n  { intros j, rw [matrix.one_eq_pi_single, pi.single_comm] }\nend\n\nlemma cramer_smul (r : \u03b1) (A : matrix n n \u03b1) :\n  cramer (r \u2022 A) = r ^ (fintype.card n - 1) \u2022 cramer A :=\nlinear_map.ext $ \u03bb b, funext $ \u03bb _, det_update_column_smul' _ _ _ _\n\n@[simp] lemma cramer_subsingleton_apply [subsingleton n] (A : matrix n n \u03b1) (b : n \u2192 \u03b1) (i : n) :\n  cramer A b i = b i :=\nby rw [cramer_apply, det_eq_elem_of_subsingleton _ i, update_column_self]\n\nlemma cramer_zero [nontrivial n] : cramer (0 : matrix n n \u03b1) = 0 :=\nbegin\n  ext i j,\n  obtain \u27e8j', hj'\u27e9 : \u2203 j', j' \u2260 j := exists_ne j,\n  apply det_eq_zero_of_column_eq_zero j',\n  intro j'',\n  simp [update_column_ne hj'],\nend\n\n/-- Use linearity of `cramer` to take it out of a summation. -/\nlemma sum_cramer {\u03b2} (s : finset \u03b2) (f : \u03b2 \u2192 n \u2192 \u03b1) :\n  \u2211 x in s, cramer A (f x) = cramer A (\u2211 x in s, f x) :=\n(linear_map.map_sum (cramer A)).symm\n\n/-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/\nlemma sum_cramer_apply {\u03b2} (s : finset \u03b2) (f : n \u2192 \u03b2 \u2192 \u03b1) (i : n) :\n\u2211 x in s, cramer A (\u03bb j, f j x) i = cramer A (\u03bb (j : n), \u2211 x in s, f j x) i :=\ncalc \u2211 x in s, cramer A (\u03bb j, f j x) i\n    = (\u2211 x in s, cramer A (\u03bb j, f j x)) i : (finset.sum_apply i s _).symm\n... = cramer A (\u03bb (j : n), \u2211 x in s, f j x) i :\n  by { rw [sum_cramer, cramer_apply], congr' with j, apply finset.sum_apply }\n\nend cramer\n\nsection adjugate\n/-!\n### `adjugate` section\n\nDefine the `adjugate` matrix and a few equations.\nThese will hold for any matrix over a commutative ring.\n-/\n\n/-- The adjugate matrix is the transpose of the cofactor matrix.\n\n  Typically, the cofactor matrix is defined by taking the determinant of minors,\n  i.e. the matrix with a row and column removed.\n  However, the proof of `mul_adjugate` becomes a lot easier if we define the\n  minor as replacing a column with a basis vector, since it allows us to use\n  facts about the `cramer` map.\n-/\ndef adjugate (A : matrix n n \u03b1) : matrix n n \u03b1 := \u03bb i, cramer A\u1d40 (pi.single i 1)\n\nlemma adjugate_def (A : matrix n n \u03b1) :\n  adjugate A = \u03bb i, cramer A\u1d40 (pi.single i 1) := rfl\n\nlemma adjugate_apply (A : matrix n n \u03b1) (i j : n) :\n  adjugate A i j = (A.update_row j (pi.single i 1)).det :=\nby { rw adjugate_def, simp only, rw [cramer_apply, update_column_transpose, det_transpose], }\n\nlemma adjugate_transpose (A : matrix n n \u03b1) : (adjugate A)\u1d40 = adjugate (A\u1d40) :=\nbegin\n  ext i j,\n  rw [transpose_apply, adjugate_apply, adjugate_apply, update_row_transpose, det_transpose],\n  rw [det_apply', det_apply'],\n  apply finset.sum_congr rfl,\n  intros \u03c3 _,\n  congr' 1,\n\n  by_cases i = \u03c3 j,\n  { -- Everything except `(i , j)` (= `(\u03c3 j , j)`) is given by A, and the rest is a single `1`.\n    congr; ext j',\n    subst h,\n    have : \u03c3 j' = \u03c3 j \u2194 j' = j := \u03c3.injective.eq_iff,\n    rw [update_row_apply, update_column_apply],\n    simp_rw this,\n    rw [\u2190dite_eq_ite, \u2190dite_eq_ite],\n    congr' 1 with rfl,\n    rw [pi.single_eq_same, pi.single_eq_same], },\n  { -- Otherwise, we need to show that there is a `0` somewhere in the product.\n    have : (\u220f j' : n, update_column A j (pi.single i 1) (\u03c3 j') j') = 0,\n    { apply prod_eq_zero (mem_univ j),\n      rw [update_column_self, pi.single_eq_of_ne' h], },\n    rw this,\n    apply prod_eq_zero (mem_univ (\u03c3\u207b\u00b9 i)),\n    erw [apply_symm_apply \u03c3 i, update_row_self],\n    apply pi.single_eq_of_ne,\n    intro h',\n    exact h ((symm_apply_eq \u03c3).mp h') }\nend\n\n/-- Since the map `b \u21a6 cramer A b` is linear in `b`, it must be multiplication by some matrix. This\nmatrix is `A.adjugate`. -/\nlemma cramer_eq_adjugate_mul_vec (A : matrix n n \u03b1) (b : n \u2192 \u03b1) :\n  cramer A b = A.adjugate.mul_vec b :=\nbegin\n  nth_rewrite 1 \u2190 A.transpose_transpose,\n  rw [\u2190 adjugate_transpose, adjugate_def],\n  have : b = \u2211 i, (b i) \u2022 (pi.single i 1),\n  { refine (pi_eq_sum_univ b).trans _, congr' with j, simp [pi.single_apply, eq_comm], congr, },\n  nth_rewrite 0 this, ext k,\n  simp [mul_vec, dot_product, mul_comm],\nend\n\nlemma mul_adjugate_apply (A : matrix n n \u03b1) (i j k) :\n  A i k * adjugate A k j = cramer A\u1d40 (pi.single k (A i k)) j :=\nbegin\n  erw [\u2190smul_eq_mul, \u2190pi.smul_apply, \u2190linear_map.map_smul, \u2190pi.single_smul', smul_eq_mul, mul_one],\nend\n\nlemma mul_adjugate (A : matrix n n \u03b1) : A \u2b1d adjugate A = A.det \u2022 1 :=\nbegin\n  ext i j,\n  rw [mul_apply, pi.smul_apply, pi.smul_apply, one_apply, smul_eq_mul, mul_boole],\n  simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, pi.single_apply, eq_comm]\nend\n\nlemma adjugate_mul (A : matrix n n \u03b1) : adjugate A \u2b1d A = A.det \u2022 1 :=\ncalc adjugate A \u2b1d A = (A\u1d40 \u2b1d (adjugate A\u1d40))\u1d40 :\n  by rw [\u2190adjugate_transpose, \u2190transpose_mul, transpose_transpose]\n... = A.det \u2022 1 : by rw [mul_adjugate (A\u1d40), det_transpose, transpose_smul, transpose_one]\n\nlemma adjugate_smul (r : \u03b1) (A : matrix n n \u03b1) :\n  adjugate (r \u2022 A) = r ^ (fintype.card n - 1) \u2022 adjugate A :=\nbegin\n  rw [adjugate, adjugate, transpose_smul, cramer_smul],\n  refl,\nend\n\n/-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A \u2b1d x = b` even\nif the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det`\ndivides `b`. -/\n@[simp] lemma mul_vec_cramer (A : matrix n n \u03b1) (b : n \u2192 \u03b1) :\n  A.mul_vec (cramer A b) = A.det \u2022 b :=\nby rw [cramer_eq_adjugate_mul_vec, mul_vec_mul_vec, mul_adjugate, smul_mul_vec_assoc, one_mul_vec]\n\nlemma adjugate_subsingleton [subsingleton n] (A : matrix n n \u03b1) : adjugate A = 1 :=\nbegin\n  ext i j,\n  simp [subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i]\nend\n\nlemma adjugate_eq_one_of_card_eq_one {A : matrix n n \u03b1} (h : fintype.card n = 1) : adjugate A = 1 :=\nbegin\n  haveI : subsingleton n := fintype.card_le_one_iff_subsingleton.mp h.le,\n  exact adjugate_subsingleton _\nend\n\n@[simp] lemma adjugate_zero [nontrivial n] : adjugate (0 : matrix n n \u03b1) = 0 :=\nbegin\n  ext i j,\n  obtain \u27e8j', hj'\u27e9 : \u2203 j', j' \u2260 j := exists_ne j,\n  apply det_eq_zero_of_column_eq_zero j',\n  intro j'',\n  simp [update_column_ne hj'],\nend\n\n@[simp] lemma adjugate_one : adjugate (1 : matrix n n \u03b1) = 1 :=\nby { ext, simp [adjugate_def, matrix.one_apply, pi.single_apply, eq_comm] }\n\n\nlemma _root_.ring_hom.map_adjugate {R S : Type*} [comm_ring R] [comm_ring S] (f : R \u2192+* S)\n  (M : matrix n n R) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) :=\nbegin\n  ext i k,\n  have : pi.single i (1 : S) = f \u2218 pi.single i 1,\n  { rw \u2190f.map_one,\n    exact pi.single_op (\u03bb i, f) (\u03bb i, f.map_zero) i (1 : R) },\n  rw [adjugate_apply, ring_hom.map_matrix_apply, map_apply, ring_hom.map_matrix_apply,\n      this, \u2190map_update_row, \u2190ring_hom.map_matrix_apply, \u2190ring_hom.map_det, \u2190adjugate_apply]\nend\n\nlemma _root_.alg_hom.map_adjugate {R A B : Type*} [comm_semiring R] [comm_ring A] [comm_ring B]\n  [algebra R A] [algebra R B] (f : A \u2192\u2090[R] B)\n  (M : matrix n n A) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) :=\nf.to_ring_hom.map_adjugate _\n\n\nlemma det_adjugate (A : matrix n n \u03b1) : (adjugate A).det = A.det ^ (fintype.card n - 1) :=\nbegin\n  -- get rid of the `- 1`\n  cases (fintype.card n).eq_zero_or_pos with h_card h_card,\n  { haveI : is_empty n := fintype.card_eq_zero_iff.mp h_card,\n    rw [h_card, nat.zero_sub, pow_zero, adjugate_subsingleton, det_one] },\n  replace h_card := tsub_add_cancel_of_le h_card.nat_succ_le,\n\n  -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring\n  -- where `A'.det` is non-zero.\n  let A' := mv_polynomial_X n n \u2124,\n  suffices : A'.adjugate.det = A'.det ^ (fintype.card n - 1),\n  { rw [\u2190mv_polynomial_X_map_matrix_aeval \u2124 A, \u2190alg_hom.map_adjugate, \u2190alg_hom.map_det,\n      \u2190alg_hom.map_det, \u2190alg_hom.map_pow, this] },\n\n  apply mul_left_cancel\u2080 (show A'.det \u2260 0, from det_mv_polynomial_X_ne_zero n \u2124),\n  calc  A'.det * A'.adjugate.det\n      = (A' \u2b1d adjugate A').det                 : (det_mul _ _).symm\n  ... = A'.det ^ fintype.card n                : by rw [mul_adjugate, det_smul, det_one, mul_one]\n  ... = A'.det * A'.det ^ (fintype.card n - 1) : by rw [\u2190pow_succ, h_card],\nend\n\n@[simp] lemma adjugate_fin_zero (A : matrix (fin 0) (fin 0) \u03b1) : adjugate A = 0 :=\n@subsingleton.elim _ matrix.subsingleton_of_empty_left _ _\n\n@[simp] lemma adjugate_fin_one (A : matrix (fin 1) (fin 1) \u03b1) : adjugate A = 1 :=\nadjugate_subsingleton A\n\nlemma adjugate_fin_two (A : matrix (fin 2) (fin 2) \u03b1) :\n  adjugate A = ![![A 1 1, -A 0 1], ![-A 1 0, A 0 0]] :=\nbegin\n  ext i j,\n  rw [adjugate_apply, det_fin_two],\n  fin_cases i with [0, 1]; fin_cases j with [0, 1];\n  simp only [nat.one_ne_zero, one_mul, fin.one_eq_zero_iff, pi.single_eq_same, zero_mul,\n    fin.zero_eq_one_iff, sub_zero, pi.single_eq_of_ne, ne.def, not_false_iff, update_row_self,\n    update_row_ne, cons_val_zero, mul_zero, mul_one, zero_sub, cons_val_one, head_cons],\nend\n\n@[simp] lemma adjugate_fin_two' (a b c d : \u03b1) :\n  adjugate ![![a, b], ![c, d]] = ![![d, -b], ![-c, a]] :=\nadjugate_fin_two _\n\nlemma adjugate_conj_transpose [star_ring \u03b1] (A : matrix n n \u03b1) : A.adjugate\u1d34 = adjugate (A\u1d34) :=\nbegin\n  dsimp only [conj_transpose],\n  have : A\u1d40.adjugate.map star = adjugate (A\u1d40.map star) := ((star_ring_end \u03b1).map_adjugate A\u1d40),\n  rw [A.adjugate_transpose, this],\nend\n\nlemma is_regular_of_is_left_regular_det {A : matrix n n \u03b1} (hA : is_left_regular A.det) :\n  is_regular A :=\nbegin\n  split,\n  { intros B C h,\n    refine hA.matrix _,\n    rw [\u2190matrix.one_mul B, \u2190matrix.one_mul C, \u2190matrix.smul_mul, \u2190matrix.smul_mul, \u2190adjugate_mul,\n        matrix.mul_assoc, matrix.mul_assoc, \u2190mul_eq_mul A, h, mul_eq_mul] },\n  { intros B C h,\n    simp only [mul_eq_mul] at h,\n    refine hA.matrix _,\n    rw [\u2190matrix.mul_one B, \u2190matrix.mul_one C, \u2190matrix.mul_smul, \u2190matrix.mul_smul, \u2190mul_adjugate,\n        \u2190matrix.mul_assoc, \u2190matrix.mul_assoc, h] }\nend\n\nlemma adjugate_mul_distrib_aux (A B : matrix n n \u03b1)\n  (hA : is_left_regular A.det)\n  (hB : is_left_regular B.det) :\n  adjugate (A \u2b1d B) = adjugate B \u2b1d adjugate A :=\nbegin\n  have hAB : is_left_regular (A \u2b1d B).det,\n  { rw [det_mul],\n    exact hA.mul hB },\n  refine (is_regular_of_is_left_regular_det hAB).left _,\n  rw [mul_eq_mul, mul_adjugate, mul_eq_mul, matrix.mul_assoc, \u2190matrix.mul_assoc B, mul_adjugate,\n      smul_mul, matrix.one_mul, mul_smul, mul_adjugate, smul_smul, mul_comm, \u2190det_mul]\nend\n\n/--\nProof follows from \"The trace Cayley-Hamilton theorem\" by Darij Grinberg, Section 5.3\n-/\nlemma adjugate_mul_distrib (A B : matrix n n \u03b1) : adjugate (A \u2b1d B) = adjugate B \u2b1d adjugate A :=\nbegin\n  let g : matrix n n \u03b1 \u2192 matrix n n \u03b1[X] :=\n    \u03bb M, M.map polynomial.C + (polynomial.X : \u03b1[X]) \u2022 1,\n  let f' : matrix n n \u03b1[X] \u2192+* matrix n n \u03b1 := (polynomial.eval_ring_hom 0).map_matrix,\n  have f'_inv : \u2200 M, f' (g M) = M,\n  { intro,\n    ext,\n    simp [f', g], },\n  have f'_adj : \u2200 (M : matrix n n \u03b1), f' (adjugate (g M)) = adjugate M,\n  { intro,\n    rw [ring_hom.map_adjugate, f'_inv] },\n  have f'_g_mul : \u2200 (M N : matrix n n \u03b1), f' (g M \u2b1d g N) = M \u2b1d N,\n  { intros,\n    rw [\u2190mul_eq_mul, ring_hom.map_mul, f'_inv, f'_inv, mul_eq_mul] },\n  have hu : \u2200 (M : matrix n n \u03b1), is_regular (g M).det,\n  { intros M,\n    refine polynomial.monic.is_regular _,\n    simp only [g, polynomial.monic.def, \u2190polynomial.leading_coeff_det_X_one_add_C M, add_comm] },\n  rw [\u2190f'_adj, \u2190f'_adj, \u2190f'_adj, \u2190mul_eq_mul (f' (adjugate (g B))), \u2190f'.map_mul, mul_eq_mul,\n      \u2190adjugate_mul_distrib_aux _ _ (hu A).left (hu B).left, ring_hom.map_adjugate,\n      ring_hom.map_adjugate, f'_inv, f'_g_mul]\nend\n\n@[simp] lemma adjugate_pow (A : matrix n n \u03b1) (k : \u2115) :\n  adjugate (A ^ k) = (adjugate A) ^ k :=\nbegin\n  induction k with k IH,\n  { simp },\n  { rw [pow_succ', mul_eq_mul, adjugate_mul_distrib, IH, \u2190mul_eq_mul, pow_succ] }\nend\n\nlemma det_smul_adjugate_adjugate (A : matrix n n \u03b1) :\n  det A \u2022 adjugate (adjugate A) = det A ^ (fintype.card n - 1) \u2022 A :=\nbegin\n  have : A \u2b1d (A.adjugate \u2b1d A.adjugate.adjugate) = A \u2b1d (A.det ^ (fintype.card n - 1) \u2022 1),\n  { rw [\u2190adjugate_mul_distrib, adjugate_mul, adjugate_smul, adjugate_one], },\n  rwa [\u2190matrix.mul_assoc, mul_adjugate, matrix.mul_smul, matrix.mul_one, matrix.smul_mul,\n    matrix.one_mul] at this,\nend\n\n/-- Note that this is not true for `fintype.card n = 1` since `1 - 2 = 0` and not `-1`. -/\n\n\n  -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring\n  -- where `A'.det` is non-zero.\n  let A' := mv_polynomial_X n n \u2124,\n  suffices : adjugate (adjugate A') = det A' ^ (fintype.card n - 2) \u2022 A',\n  { rw [\u2190mv_polynomial_X_map_matrix_aeval \u2124 A, \u2190alg_hom.map_adjugate, \u2190alg_hom.map_adjugate, this,\n      \u2190alg_hom.map_det, \u2190 alg_hom.map_pow, alg_hom.map_matrix_apply, alg_hom.map_matrix_apply,\n      matrix.map_smul' _ _ _ (_root_.map_mul _)] },\n  have h_card' : fintype.card n - 2 + 1 = fintype.card n - 1,\n  { simp [h_card] },\n\n  have is_reg : is_smul_regular (mv_polynomial (n \u00d7 n) \u2124) (det A') :=\n    \u03bb x y, mul_left_cancel\u2080 (det_mv_polynomial_X_ne_zero n \u2124),\n  apply is_reg.matrix,\n  rw [smul_smul, \u2190pow_succ, h_card', det_smul_adjugate_adjugate],\nend\n\n/-- A weaker version of `matrix.adjugate_adjugate` that uses `nontrivial`. -/\nlemma adjugate_adjugate' (A : matrix n n \u03b1) [nontrivial n] :\n  adjugate (adjugate A) = det A ^ (fintype.card n - 2) \u2022 A :=\nadjugate_adjugate _ $ fintype.one_lt_card.ne'\n\nend adjugate\n\nend matrix\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/linear_algebra/matrix/adjugate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7049678114038445}}
{"text": "/-\nCopyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Kontorovich, Heather Macbeth, Marc Masdeu\n-/\n\nimport analysis.complex.upper_half_plane.basic\nimport analysis.normed_space.finite_dimension\nimport linear_algebra.general_linear_group\nimport linear_algebra.matrix.general_linear_group\n\n/-!\n# The action of the modular group SL(2, \u2124) on the upper half-plane\n\nWe define the action of `SL(2,\u2124)` on `\u210d` (via restriction of the `SL(2,\u211d)` action in\n`analysis.complex.upper_half_plane`). We then define the standard fundamental domain\n(`modular_group.fd`, `\ud835\udc9f`) for this action and show\n(`modular_group.exists_smul_mem_fd`) that any point in `\u210d` can be\nmoved inside `\ud835\udc9f`.\n\n## Main definitions\n\nThe standard (closed) fundamental domain of the action of `SL(2,\u2124)` on `\u210d`, denoted `\ud835\udc9f`:\n`fd := {z | 1 \u2264 (z : \u2102).norm_sq \u2227 |z.re| \u2264 (1 : \u211d) / 2}`\n\nThe standard open fundamental domain of the action of `SL(2,\u2124)` on `\u210d`, denoted `\ud835\udc9f\u1d52`:\n`fdo := {z | 1 < (z : \u2102).norm_sq \u2227 |z.re| < (1 : \u211d) / 2}`\n\nThese notations are localized in the `modular` locale and can be enabled via `open_locale modular`.\n\n## Main results\n\nAny `z : \u210d` can be moved to `\ud835\udc9f` by an element of `SL(2,\u2124)`:\n`exists_smul_mem_fd (z : \u210d) : \u2203 g : SL(2,\u2124), g \u2022 z \u2208 \ud835\udc9f`\n\nIf both `z` and `\u03b3 \u2022 z` are in the open domain `\ud835\udc9f\u1d52` then `z = \u03b3 \u2022 z`:\n`eq_smul_self_of_mem_fdo_mem_fdo {z : \u210d} {g : SL(2,\u2124)} (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : z = g \u2022 z`\n\n# Discussion\n\nStandard proofs make use of the identity\n\n`g \u2022 z = a / c - 1 / (c (cz + d))`\n\nfor `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`.\nInstead, our proof makes use of the following perhaps novel identity (see\n`modular_group.smul_eq_lc_row0_add`):\n\n`g \u2022 z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`\n\nwhere there is no issue of division by zero.\n\nAnother feature is that we delay until the very end the consideration of special matrices\n`T=[[1,1],[0,1]]` (see `modular_group.T`) and `S=[[0,-1],[1,0]]` (see `modular_group.S`), by\ninstead using abstract theory on the properness of certain maps (phrased in terms of the filters\n`filter.cocompact`, `filter.cofinite`, etc) to deduce existence theorems, first to prove the\nexistence of `g` maximizing `(g\u2022z).im` (see `modular_group.exists_max_im`), and then among\nthose, to minimize `|(g\u2022z).re|` (see `modular_group.exists_row_one_eq_and_min_re`).\n-/\n\n/- Disable these instances as they are not the simp-normal form, and having them disabled ensures\nwe state lemmas in this file without spurious `coe_fn` terms. -/\nlocal attribute [-instance] matrix.special_linear_group.has_coe_to_fun\nlocal attribute [-instance] matrix.general_linear_group.has_coe_to_fun\n\nopen complex (hiding abs_two)\nopen matrix (hiding mul_smul) matrix.special_linear_group upper_half_plane\nnoncomputable theory\n\nlocal notation `SL(` n `, ` R `)`:= special_linear_group (fin n) R\nlocal prefix `\u2191\u2098`:1024 := @coe _ (matrix (fin 2) (fin 2) \u2124) _\n\nopen_locale upper_half_plane complex_conjugate\n\nlocal attribute [instance] fintype.card_fin_even\n\nnamespace modular_group\n\nvariables {g : SL(2, \u2124)} (z : \u210d)\n\nsection bottom_row\n\n/-- The two numbers `c`, `d` in the \"bottom_row\" of `g=[[*,*],[c,d]]` in `SL(2, \u2124)` are coprime. -/\nlemma bottom_row_coprime {R : Type*} [comm_ring R] (g : SL(2, R)) :\n  is_coprime ((\u2191g : matrix (fin 2) (fin 2) R) 1 0) ((\u2191g : matrix (fin 2) (fin 2) R) 1 1) :=\nbegin\n  use [- (\u2191g : matrix (fin 2) (fin 2) R) 0 1, (\u2191g : matrix (fin 2) (fin 2) R) 0 0],\n  rw [add_comm, neg_mul, \u2190sub_eq_add_neg, \u2190det_fin_two],\n  exact g.det_coe,\nend\n\n/-- Every pair `![c, d]` of coprime integers is the \"bottom_row\" of some element `g=[[*,*],[c,d]]`\nof `SL(2,\u2124)`. -/\nlemma bottom_row_surj {R : Type*} [comm_ring R] :\n  set.surj_on (\u03bb g : SL(2, R), @coe _ (matrix (fin 2) (fin 2) R) _ g 1) set.univ\n    {cd | is_coprime (cd 0) (cd 1)} :=\nbegin\n  rintros cd \u27e8b\u2080, a, gcd_eqn\u27e9,\n  let A := of ![![a, -b\u2080], cd],\n  have det_A_1 : det A = 1,\n  { convert gcd_eqn,\n    simp [A, det_fin_two, (by ring : a * (cd 1) + b\u2080 * (cd 0) = b\u2080 * (cd 0) + a * (cd 1))] },\n  refine \u27e8\u27e8A, det_A_1\u27e9, set.mem_univ _, _\u27e9,\n  ext; simp [A]\nend\n\nend bottom_row\n\nsection tendsto_lemmas\n\nopen filter continuous_linear_map\nlocal attribute [simp] coe_smul\n\n/-- The function `(c,d) \u2192 |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite.\n-/\nlemma tendsto_norm_sq_coprime_pair :\n  filter.tendsto (\u03bb p : fin 2 \u2192 \u2124, ((p 0 : \u2102) * z + p 1).norm_sq)\n  cofinite at_top :=\nbegin\n  -- using this instance rather than the automatic `function.module` makes unification issues in\n  -- `linear_equiv.closed_embedding_of_injective` less bad later in the proof.\n  letI : module \u211d (fin 2 \u2192 \u211d) := normed_space.to_module,\n  let \u03c0\u2080 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d := linear_map.proj 0,\n  let \u03c0\u2081 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d := linear_map.proj 1,\n  let f : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u2102 := \u03c0\u2080.smul_right (z:\u2102) + \u03c0\u2081.smul_right 1,\n  have f_def : \u21d1f = \u03bb (p : fin 2 \u2192 \u211d), (p 0 : \u2102) * \u2191z + p 1,\n  { ext1,\n    dsimp only [linear_map.coe_proj, real_smul,\n      linear_map.coe_smul_right, linear_map.add_apply],\n    rw mul_one, },\n  have : (\u03bb (p : fin 2 \u2192 \u2124), norm_sq ((p 0 : \u2102) * \u2191z + \u2191(p 1)))\n    = norm_sq \u2218 f \u2218 (\u03bb p : fin 2 \u2192 \u2124, (coe : \u2124 \u2192 \u211d) \u2218 p),\n  { ext1,\n    rw f_def,\n    dsimp only [function.comp],\n    rw [of_real_int_cast, of_real_int_cast], },\n  rw this,\n  have hf : f.ker = \u22a5,\n  { let g : \u2102 \u2192\u2097[\u211d] (fin 2 \u2192 \u211d) :=\n      linear_map.pi ![im_lm, im_lm.comp ((z:\u2102) \u2022 ((conj_ae : \u2102 \u2192\u2090[\u211d] \u2102) : \u2102 \u2192\u2097[\u211d] \u2102))],\n    suffices : ((z:\u2102).im\u207b\u00b9 \u2022 g).comp f = linear_map.id,\n    { exact linear_map.ker_eq_bot_of_inverse this },\n    apply linear_map.ext,\n    intros c,\n    have hz : (z:\u2102).im \u2260 0 := z.2.ne',\n    rw [linear_map.comp_apply, linear_map.smul_apply, linear_map.id_apply],\n    ext i,\n    dsimp only [g, pi.smul_apply, linear_map.pi_apply, smul_eq_mul],\n    fin_cases i,\n    { show ((z : \u2102).im)\u207b\u00b9 * (f c).im = c 0,\n      rw [f_def, add_im, of_real_mul_im, of_real_im, add_zero, mul_left_comm,\n        inv_mul_cancel hz, mul_one], },\n    { show ((z : \u2102).im)\u207b\u00b9 * ((z : \u2102) * conj (f c)).im = c 1,\n      rw [f_def, ring_hom.map_add, ring_hom.map_mul, mul_add, mul_left_comm, mul_conj,\n        conj_of_real, conj_of_real, \u2190 of_real_mul, add_im, of_real_im, zero_add,\n        inv_mul_eq_iff_eq_mul\u2080 hz],\n      simp only [of_real_im, of_real_re, mul_im, zero_add, mul_zero] } },\n  have hf' : closed_embedding f,\n  { -- for some reason we get a timeout if we try and apply this lemma in a more sensible way\n    have := @linear_equiv.closed_embedding_of_injective \u211d _ (fin 2 \u2192 \u211d) _ (id _) \u2102 _ _ _ _,\n    rotate 2,\n    exact f,\n    exact this hf },\n  have h\u2082 : tendsto (\u03bb p : fin 2 \u2192 \u2124, (coe : \u2124 \u2192 \u211d) \u2218 p) cofinite (cocompact _),\n  { convert tendsto.pi_map_Coprod (\u03bb i, int.tendsto_coe_cofinite),\n    { rw Coprod_cofinite },\n    { rw Coprod_cocompact } },\n  exact tendsto_norm_sq_cocompact_at_top.comp (hf'.tendsto_cocompact.comp h\u2082),\nend\n\n/-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`.\n  This is the linear map version of this operation.\n-/\ndef lc_row0 (p : fin 2 \u2192 \u2124) : (matrix (fin 2) (fin 2) \u211d) \u2192\u2097[\u211d] \u211d :=\n((p 0:\u211d) \u2022 linear_map.proj 0 + (p 1:\u211d) \u2022 linear_map.proj 1 : (fin 2 \u2192 \u211d) \u2192\u2097[\u211d] \u211d).comp\n  (linear_map.proj 0)\n\n@[simp] lemma lc_row0_apply (p : fin 2 \u2192 \u2124) (g : matrix (fin 2) (fin 2) \u211d) :\n  lc_row0 p g = p 0 * g 0 0 + p 1 * g 0 1 :=\nrfl\n\n/-- Linear map sending the matrix [a, b; c, d] to the matrix [ac\u2080 + bd\u2080, - ad\u2080 + bc\u2080; c, d], for\nsome fixed `(c\u2080, d\u2080)`. -/\n@[simps] def lc_row0_extend {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  (matrix (fin 2) (fin 2) \u211d) \u2243\u2097[\u211d] matrix (fin 2) (fin 2) \u211d :=\nlinear_equiv.Pi_congr_right\n![begin\n    refine linear_map.general_linear_group.general_linear_equiv \u211d (fin 2 \u2192 \u211d)\n      (general_linear_group.to_linear (plane_conformal_matrix (cd 0 : \u211d) (-(cd 1 : \u211d)) _)),\n    norm_cast,\n    rw neg_sq,\n    exact hcd.sq_add_sq_ne_zero\n  end,\n  linear_equiv.refl \u211d (fin 2 \u2192 \u211d)]\n\n/-- The map `lc_row0` is proper, that is, preimages of cocompact sets are finite in\n`[[* , *], [c, d]]`.-/\ntheorem tendsto_lc_row0 {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  tendsto (\u03bb g : {g : SL(2, \u2124) // \u2191\u2098g 1 = cd}, lc_row0 cd \u2191(\u2191g : SL(2, \u211d)))\n    cofinite (cocompact \u211d) :=\nbegin\n  let mB : \u211d \u2192 (matrix (fin 2) (fin 2) \u211d) := \u03bb t, of ![![t, (-(1:\u2124):\u211d)], coe \u2218 cd],\n  have hmB : continuous mB,\n  { refine continuous_matrix _,\n    simp only [fin.forall_fin_two, mB, continuous_const, continuous_id', of_apply,\n      cons_val_zero, cons_val_one, and_self ] },\n  refine filter.tendsto.of_tendsto_comp _ (comap_cocompact_le hmB),\n  let f\u2081 : SL(2, \u2124) \u2192 matrix (fin 2) (fin 2) \u211d :=\n    \u03bb g, matrix.map (\u2191g : matrix _ _ \u2124) (coe : \u2124 \u2192 \u211d),\n  have cocompact_\u211d_to_cofinite_\u2124_matrix :\n    tendsto (\u03bb m : matrix (fin 2) (fin 2) \u2124, matrix.map m (coe : \u2124 \u2192 \u211d)) cofinite (cocompact _),\n  { simpa only [Coprod_cofinite, Coprod_cocompact]\n      using tendsto.pi_map_Coprod (\u03bb i : fin 2, tendsto.pi_map_Coprod\n        (\u03bb j : fin 2, int.tendsto_coe_cofinite)) },\n  have hf\u2081 : tendsto f\u2081 cofinite (cocompact _) :=\n    cocompact_\u211d_to_cofinite_\u2124_matrix.comp subtype.coe_injective.tendsto_cofinite,\n  have hf\u2082 : closed_embedding (lc_row0_extend hcd) :=\n    (lc_row0_extend hcd).to_continuous_linear_equiv.to_homeomorph.closed_embedding,\n  convert hf\u2082.tendsto_cocompact.comp (hf\u2081.comp subtype.coe_injective.tendsto_cofinite) using 1,\n  ext \u27e8g, rfl\u27e9 i j : 3,\n  fin_cases i; [fin_cases j, skip],\n  -- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts.\n  { simp only [mB, mul_vec, dot_product, fin.sum_univ_two, _root_.coe_coe, coe_matrix_coe,\n      int.coe_cast_ring_hom, lc_row0_apply, function.comp_app, cons_val_zero, lc_row0_extend_apply,\n      linear_map.general_linear_group.coe_fn_general_linear_equiv,\n      general_linear_group.to_linear_apply, coe_plane_conformal_matrix, neg_neg, mul_vec_lin_apply,\n      cons_val_one, head_cons, of_apply] },\n  { convert congr_arg (\u03bb n : \u2124, (-n:\u211d)) g.det_coe.symm using 1,\n    simp only [f\u2081, mul_vec, dot_product, fin.sum_univ_two, matrix.det_fin_two, function.comp_app,\n      subtype.coe_mk, lc_row0_extend_apply, cons_val_zero,\n      linear_map.general_linear_group.coe_fn_general_linear_equiv,\n      general_linear_group.to_linear_apply, coe_plane_conformal_matrix, mul_vec_lin_apply,\n      cons_val_one, head_cons, map_apply, neg_mul, int.cast_sub, int.cast_mul, neg_sub, of_apply],\n    ring },\n  { refl }\nend\n\n/-- This replaces `(g\u2022z).re = a/c + *` in the standard theory with the following novel identity:\n  `g \u2022 z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`\n  which does not need to be decomposed depending on whether `c = 0`. -/\nlemma smul_eq_lc_row0_add {p : fin 2 \u2192 \u2124} (hp : is_coprime (p 0) (p 1)) (hg : \u2191\u2098g 1 = p) :\n  \u2191(g \u2022 z) = ((lc_row0 p \u2191(g : SL(2, \u211d))) : \u2102) / (p 0 ^ 2 + p 1 ^ 2)\n    + ((p 1 : \u2102) * z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1)) :=\nbegin\n  have nonZ1 : (p 0 : \u2102) ^ 2 + (p 1) ^ 2 \u2260 0 := by exact_mod_cast hp.sq_add_sq_ne_zero,\n  have : (coe : \u2124 \u2192 \u211d) \u2218 p \u2260 0 := \u03bb h, hp.ne_zero (by ext i; simpa using congr_fun h i),\n  have nonZ2 : (p 0 : \u2102) * z + p 1 \u2260 0 := by simpa using linear_ne_zero _ z this,\n  field_simp [nonZ1, nonZ2, denom_ne_zero, -upper_half_plane.denom, -denom_apply],\n  rw (by simp : (p 1 : \u2102) * z - p 0 = ((p 1) * z - p 0) * \u2191(det (\u2191g : matrix (fin 2) (fin 2) \u2124))),\n  rw [\u2190hg, det_fin_two],\n  simp only [int.coe_cast_ring_hom, coe_matrix_coe, int.cast_mul, of_real_int_cast, map_apply,\n  denom, int.cast_sub, _root_.coe_coe,coe_GL_pos_coe_GL_coe_matrix],\n  ring,\nend\n\nlemma tendsto_abs_re_smul {p : fin 2 \u2192 \u2124} (hp : is_coprime (p 0) (p 1)) :\n  tendsto (\u03bb g : {g : SL(2, \u2124) // \u2191\u2098g 1 = p}, |((g : SL(2, \u2124)) \u2022 z).re|)\n    cofinite at_top :=\nbegin\n  suffices : tendsto (\u03bb g : (\u03bb g : SL(2, \u2124), \u2191\u2098g 1) \u207b\u00b9' {p}, (((g : SL(2, \u2124)) \u2022 z).re))\n    cofinite (cocompact \u211d),\n  { exact tendsto_norm_cocompact_at_top.comp this },\n  have : ((p 0 : \u211d) ^ 2 + p 1 ^ 2)\u207b\u00b9 \u2260 0,\n  { apply inv_ne_zero,\n    exact_mod_cast hp.sq_add_sq_ne_zero },\n  let f := homeomorph.mul_right\u2080 _ this,\n  let ff := homeomorph.add_right (((p 1:\u2102)* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re,\n  convert ((f.trans ff).closed_embedding.tendsto_cocompact).comp (tendsto_lc_row0 hp),\n  ext g,\n  change ((g : SL(2, \u2124)) \u2022 z).re = (lc_row0 p \u2191(\u2191g : SL(2, \u211d))) / (p 0 ^ 2 + p 1 ^ 2)\n  + (((p 1:\u2102 )* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re,\n  exact_mod_cast (congr_arg complex.re (smul_eq_lc_row0_add z hp g.2))\nend\n\nend tendsto_lemmas\n\nsection fundamental_domain\n\nlocal attribute [simp] coe_smul re_smul\n\n/-- For `z : \u210d`, there is a `g : SL(2,\u2124)` maximizing `(g\u2022z).im` -/\nlemma exists_max_im :\n  \u2203 g : SL(2, \u2124), \u2200 g' : SL(2, \u2124), (g' \u2022 z).im \u2264 (g \u2022 z).im :=\nbegin\n  classical,\n  let s : set (fin 2 \u2192 \u2124) := {cd | is_coprime (cd 0) (cd 1)},\n  have hs : s.nonempty := \u27e8![1, 1], is_coprime_one_left\u27e9,\n  obtain \u27e8p, hp_coprime, hp\u27e9 :=\n    filter.tendsto.exists_within_forall_le hs (tendsto_norm_sq_coprime_pair z),\n  obtain \u27e8g, -, hg\u27e9 := bottom_row_surj hp_coprime,\n  refine \u27e8g, \u03bb g', _\u27e9,\n  rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq,\n    div_le_div_left],\n  { simpa [\u2190 hg] using hp (\u2191\u2098g' 1) (bottom_row_coprime g') },\n  { exact z.im_pos },\n  { exact norm_sq_denom_pos g' z },\n  { exact norm_sq_denom_pos g z },\nend\n\n/-- Given `z : \u210d` and a bottom row `(c,d)`, among the `g : SL(2,\u2124)` with this bottom row, minimize\n  `|(g\u2022z).re|`.  -/\nlemma exists_row_one_eq_and_min_re {cd : fin 2 \u2192 \u2124} (hcd : is_coprime (cd 0) (cd 1)) :\n  \u2203 g : SL(2,\u2124), \u2191\u2098g 1 = cd \u2227 (\u2200 g' : SL(2,\u2124), \u2191\u2098g 1 = \u2191\u2098g' 1 \u2192\n  |(g \u2022 z).re| \u2264 |(g' \u2022 z).re|) :=\nbegin\n  haveI : nonempty {g : SL(2, \u2124) // \u2191\u2098g 1 = cd} :=\n    let \u27e8x, hx\u27e9 := bottom_row_surj hcd in \u27e8\u27e8x, hx.2\u27e9\u27e9,\n  obtain \u27e8g, hg\u27e9 := filter.tendsto.exists_forall_le (tendsto_abs_re_smul z hcd),\n  refine \u27e8g, g.2, _\u27e9,\n  { intros g1 hg1,\n    have : g1 \u2208 ((\u03bb g : SL(2, \u2124), \u2191\u2098g 1) \u207b\u00b9' {cd}),\n    { rw [set.mem_preimage, set.mem_singleton_iff],\n      exact eq.trans hg1.symm (set.mem_singleton_iff.mp (set.mem_preimage.mp g.2)) },\n    exact hg \u27e8g1, this\u27e9 },\nend\n\nlemma coe_T_zpow_smul_eq {n : \u2124} : (\u2191((T^n) \u2022 z) : \u2102) = z + n :=\nby simp [coe_T_zpow]\n\nlemma re_T_zpow_smul (n : \u2124) : ((T^n) \u2022 z).re = z.re + n :=\nby rw [\u2190coe_re, coe_T_zpow_smul_eq, add_re, int_cast_re, coe_re]\n\nlemma im_T_zpow_smul (n : \u2124) : ((T^n) \u2022 z).im = z.im :=\nby rw [\u2190coe_im, coe_T_zpow_smul_eq, add_im, int_cast_im, add_zero, coe_im]\n\nlemma re_T_smul : (T \u2022 z).re = z.re + 1 := by simpa using re_T_zpow_smul z 1\nlemma im_T_smul : (T \u2022 z).im = z.im := by simpa using im_T_zpow_smul z 1\nlemma re_T_inv_smul : (T\u207b\u00b9 \u2022 z).re = z.re - 1 := by simpa using re_T_zpow_smul z (-1)\nlemma im_T_inv_smul : (T\u207b\u00b9 \u2022 z).im = z.im := by simpa using im_T_zpow_smul z (-1)\n\nvariables {z}\n\n-- If instead we had `g` and `T` of type `PSL(2, \u2124)`, then we could simply state `g = T^n`.\nlemma exists_eq_T_zpow_of_c_eq_zero (hc : \u2191\u2098g 1 0 = 0) :\n  \u2203 (n : \u2124), \u2200 (z : \u210d), g \u2022 z = T^n \u2022 z :=\nbegin\n  have had := g.det_coe,\n  replace had : \u2191\u2098g 0 0 * \u2191\u2098g 1 1 = 1, { rw [det_fin_two, hc] at had, linarith, },\n  rcases int.eq_one_or_neg_one_of_mul_eq_one' had with \u27e8ha, hd\u27e9 | \u27e8ha, hd\u27e9,\n  { use \u2191\u2098g 0 1,\n    suffices : g = T^(\u2191\u2098g 0 1), { intros z, conv_lhs { rw this, }, },\n    ext i j, fin_cases i; fin_cases j;\n    simp [ha, hc, hd, coe_T_zpow], },\n  { use -\u2191\u2098g 0 1,\n    suffices : g = -T^(-\u2191\u2098g 0 1), { intros z, conv_lhs { rw [this, SL_neg_smul], }, },\n    ext i j, fin_cases i; fin_cases j;\n    simp [ha, hc, hd, coe_T_zpow], },\nend\n\n/- If `c = 1`, then `g` factorises into a product terms involving only `T` and `S`. -/\nlemma g_eq_of_c_eq_one (hc : \u2191\u2098g 1 0 = 1) :\n  g = T^(\u2191\u2098g 0 0) * S * T^(\u2191\u2098g 1 1) :=\nbegin\n  have hg := g.det_coe.symm,\n  replace hg : \u2191\u2098g 0 1 = \u2191\u2098g 0 0 * \u2191\u2098g 1 1 - 1, { rw [det_fin_two, hc] at hg, linarith, },\n  refine subtype.ext _,\n  conv_lhs { rw matrix.eta_fin_two \u2191\u2098g },\n  rw [hc, hg],\n  simp only [coe_mul, coe_T_zpow, coe_S, mul_fin_two],\n  congrm !![_, _; _, _]; ring\nend\n\n/-- If `1 < |z|`, then `|S \u2022 z| < 1`. -/\nlemma norm_sq_S_smul_lt_one (h: 1 < norm_sq z) : norm_sq \u2191(S \u2022 z) < 1 :=\nby simpa [coe_S] using (inv_lt_inv z.norm_sq_pos zero_lt_one).mpr h\n\n/-- If `|z| < 1`, then applying `S` strictly decreases `im`. -/\nlemma im_lt_im_S_smul (h: norm_sq z < 1) : z.im < (S \u2022 z).im :=\nbegin\n  have : z.im < z.im / norm_sq (z:\u2102),\n  { have imz : 0 < z.im := im_pos z,\n    apply (lt_div_iff z.norm_sq_pos).mpr,\n    nlinarith },\n  convert this,\n  simp only [special_linear_group.im_smul_eq_div_norm_sq],\n  field_simp [norm_sq_denom_ne_zero, norm_sq_ne_zero, S]\nend\n\n/-- The standard (closed) fundamental domain of the action of `SL(2,\u2124)` on `\u210d`. -/\ndef fd : set \u210d :=\n{z | 1 \u2264 (z : \u2102).norm_sq \u2227 |z.re| \u2264 (1 : \u211d) / 2}\n\n/-- The standard open fundamental domain of the action of `SL(2,\u2124)` on `\u210d`. -/\ndef fdo : set \u210d :=\n{z | 1 < (z : \u2102).norm_sq \u2227 |z.re| < (1 : \u211d) / 2}\n\nlocalized \"notation (name := modular_group.fd) `\ud835\udc9f` := modular_group.fd\" in modular\n\nlocalized \"notation (name := modular_group.fdo) `\ud835\udc9f\u1d52` := modular_group.fdo\" in modular\n\nlemma abs_two_mul_re_lt_one_of_mem_fdo (h : z \u2208 \ud835\udc9f\u1d52) : |2 * z.re| < 1 :=\nbegin\n  rw [abs_mul, abs_two, \u2190 lt_div_iff' (zero_lt_two' \u211d)],\n  exact h.2,\nend\n\nlemma three_lt_four_mul_im_sq_of_mem_fdo (h : z \u2208 \ud835\udc9f\u1d52) : 3 < 4 * z.im^2 :=\nbegin\n  have : 1 < z.re * z.re + z.im * z.im := by simpa [complex.norm_sq_apply] using h.1,\n  have := h.2,\n  cases abs_cases z.re;\n  nlinarith,\nend\n\n/-- If `z \u2208 \ud835\udc9f\u1d52`, and `n : \u2124`, then `|z + n| > 1`. -/\nlemma one_lt_norm_sq_T_zpow_smul (hz : z \u2208 \ud835\udc9f\u1d52) (n : \u2124) : 1 < norm_sq (((T^n) \u2022 z) : \u210d) :=\nbegin\n  have hz\u2081 : 1 < z.re * z.re + z.im * z.im := hz.1,\n  have hzn := int.nneg_mul_add_sq_of_abs_le_one n (abs_two_mul_re_lt_one_of_mem_fdo hz).le,\n  have : 1 < (z.re + \u2191n) * (z.re + \u2191n) + z.im * z.im, { linarith, },\n  simpa [coe_T_zpow, norm_sq],\nend\n\nlemma eq_zero_of_mem_fdo_of_T_zpow_mem_fdo {n : \u2124} (hz : z \u2208 \ud835\udc9f\u1d52) (hg : (T^n) \u2022 z \u2208 \ud835\udc9f\u1d52) : n = 0 :=\nbegin\n  suffices : |(n : \u211d)| < 1,\n  { rwa [\u2190 int.cast_abs, \u2190 int.cast_one, int.cast_lt, int.abs_lt_one_iff] at this, },\n  have h\u2081 := hz.2,\n  have h\u2082 := hg.2,\n  rw [re_T_zpow_smul] at h\u2082,\n  calc |(n : \u211d)| \u2264 |z.re| + |z.re + (n : \u211d)| : abs_add' (n : \u211d) z.re\n             ... < 1/2 + 1/2 : add_lt_add h\u2081 h\u2082\n             ... = 1 : add_halves 1,\nend\n\n/-- Any `z : \u210d` can be moved to `\ud835\udc9f` by an element of `SL(2,\u2124)`  -/\nlemma exists_smul_mem_fd (z : \u210d) : \u2203 g : SL(2,\u2124), g \u2022 z \u2208 \ud835\udc9f :=\nbegin\n  -- obtain a g\u2080 which maximizes im (g \u2022 z),\n  obtain \u27e8g\u2080, hg\u2080\u27e9 := exists_max_im z,\n  -- then among those, minimize re\n  obtain \u27e8g, hg, hg'\u27e9 := exists_row_one_eq_and_min_re z (bottom_row_coprime g\u2080),\n  refine \u27e8g, _\u27e9,\n  -- `g` has same max im property as `g\u2080`\n  have hg\u2080' : \u2200 (g' : SL(2,\u2124)), (g' \u2022 z).im \u2264 (g \u2022 z).im,\n  { have hg'' : (g \u2022 z).im = (g\u2080 \u2022 z).im,\n    { rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq,\n      denom_apply, denom_apply, hg]},\n    simpa only [hg''] using hg\u2080 },\n  split,\n  { -- Claim: `1 \u2264 \u21d1norm_sq \u2191(g \u2022 z)`. If not, then `S\u2022g\u2022z` has larger imaginary part\n    contrapose! hg\u2080',\n    refine \u27e8S * g, _\u27e9,\n    rw mul_smul,\n    exact im_lt_im_S_smul hg\u2080' },\n  { show |(g \u2022 z).re| \u2264 1 / 2, -- if not, then either `T` or `T'` decrease |Re|.\n    rw abs_le,\n    split,\n    { contrapose! hg',\n      refine \u27e8T * g, (T_mul_apply_one _).symm, _\u27e9,\n      rw [mul_smul, re_T_smul],\n      cases abs_cases ((g \u2022 z).re + 1); cases abs_cases (g \u2022 z).re; linarith },\n    { contrapose! hg',\n      refine \u27e8T\u207b\u00b9 * g, (T_inv_mul_apply_one _).symm, _\u27e9,\n      rw [mul_smul, re_T_inv_smul],\n      cases abs_cases ((g \u2022 z).re - 1); cases abs_cases (g \u2022 z).re; linarith } }\nend\n\nsection unique_representative\n\nvariables {z}\n\n/-- An auxiliary result en route to `modular_group.c_eq_zero`. -/\nlemma abs_c_le_one (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : |\u2191\u2098g 1 0| \u2264 1 :=\nbegin\n  let c' : \u2124 := \u2191\u2098g 1 0,\n  let c : \u211d := (c' : \u211d),\n  suffices : 3 * c^2 < 4,\n  { rw [\u2190 int.cast_pow, \u2190 int.cast_three, \u2190 int.cast_four, \u2190 int.cast_mul, int.cast_lt] at this,\n    replace this : c' ^ 2 \u2264 1 ^ 2, { linarith, },\n    rwa [sq_le_sq, abs_one] at this },\n  suffices : c \u2260 0 \u2192 9 * c^4 < 16,\n  { rcases eq_or_ne c 0 with hc | hc,\n    { rw hc, norm_num, },\n    { refine (abs_lt_of_sq_lt_sq' _ (by norm_num)).2,\n      specialize this hc,\n      linarith, }, },\n  intros hc,\n  replace hc : 0 < c^4, { rw pow_bit0_pos_iff; trivial, },\n  have h\u2081 := mul_lt_mul_of_pos_right (mul_lt_mul'' (three_lt_four_mul_im_sq_of_mem_fdo hg)\n      (three_lt_four_mul_im_sq_of_mem_fdo hz) (by linarith) (by linarith)) hc,\n  have h\u2082 : (c * z.im) ^ 4 / norm_sq (denom \u2191g z) ^ 2 \u2264 1 :=\n    div_le_one_of_le (pow_four_le_pow_two_of_pow_two_le\n      (upper_half_plane.c_mul_im_sq_le_norm_sq_denom z g)) (sq_nonneg _),\n  let nsq := norm_sq (denom g z),\n  calc 9 * c^4 < c^4 * z.im^2 * (g \u2022 z).im^2 * 16 : by linarith\n           ... = c^4 * z.im^4 / nsq^2 * 16 : by { rw [special_linear_group.im_smul_eq_div_norm_sq,\n            div_pow], ring, }\n           ... \u2264 16 : by { rw \u2190 mul_pow, linarith, },\nend\n\n/-- An auxiliary result en route to `modular_group.eq_smul_self_of_mem_fdo_mem_fdo`. -/\nlemma c_eq_zero (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : \u2191\u2098g 1 0 = 0 :=\nbegin\n  have hp : \u2200 {g' : SL(2, \u2124)} (hg' : g' \u2022 z \u2208 \ud835\udc9f\u1d52), \u2191\u2098g' 1 0 \u2260 1,\n  { intros,\n    by_contra hc,\n    let a := \u2191\u2098g' 0 0,\n    let d := \u2191\u2098g' 1 1,\n    have had : T^(-a) * g' = S * T^d, { rw g_eq_of_c_eq_one hc, group, },\n    let w := T^(-a) \u2022 (g' \u2022 z),\n    have h\u2081 : w = S \u2022 (T^d \u2022 z), { simp only [w, \u2190 mul_smul, had], },\n    replace h\u2081 : norm_sq w < 1 := h\u2081.symm \u25b8 norm_sq_S_smul_lt_one (one_lt_norm_sq_T_zpow_smul hz d),\n    have h\u2082 : 1 < norm_sq w := one_lt_norm_sq_T_zpow_smul hg' (-a),\n    linarith, },\n  have hn : \u2191\u2098g 1 0 \u2260 -1,\n  { intros hc,\n    replace hc : \u2191\u2098(-g) 1 0 = 1, { simp [\u2190 neg_eq_iff_eq_neg.mpr hc], },\n    replace hg : (-g) \u2022 z \u2208 \ud835\udc9f\u1d52 := (SL_neg_smul g z).symm \u25b8 hg,\n    exact hp hg hc, },\n  specialize hp hg,\n  rcases (int.abs_le_one_iff.mp $ abs_c_le_one hz hg);\n  tauto,\nend\n\n/-- Second Main Fundamental Domain Lemma: if both `z` and `g \u2022 z` are in the open domain `\ud835\udc9f\u1d52`,\nwhere `z : \u210d` and `g : SL(2,\u2124)`, then `z = g \u2022 z`. -/\nlemma eq_smul_self_of_mem_fdo_mem_fdo (hz : z \u2208 \ud835\udc9f\u1d52) (hg : g \u2022 z \u2208 \ud835\udc9f\u1d52) : z = g \u2022 z :=\nbegin\n  obtain \u27e8n, hn\u27e9 := exists_eq_T_zpow_of_c_eq_zero (c_eq_zero hz hg),\n  rw hn at hg \u22a2,\n  simp [eq_zero_of_mem_fdo_of_T_zpow_mem_fdo hz hg, one_smul],\nend\n\nend unique_representative\n\nend fundamental_domain\n\nend modular_group\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/modular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7049446509530934}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Yury Kudryashov\n-/\nimport data.set.lattice\n\n/-!\n# Extra lemmas about intervals\n\nThis file contains lemmas about intervals that cannot be included into `data.set.intervals.basic`\nbecause this would create an `import` cycle. Namely, lemmas in this file can use definitions\nfrom `data.set.lattice`, including `disjoint`.\n-/\n\nuniverses u v w\n\nvariables {\u03b9 : Sort u} {\u03b1 : Type v} {\u03b2 : Type w}\n\nopen set order_dual (to_dual)\n\nnamespace set\n\nsection preorder\nvariables [preorder \u03b1] {a b c : \u03b1}\n\n@[simp] lemma Iic_disjoint_Ioi (h : a \u2264 b) : disjoint (Iic a) (Ioi b) :=\n\u03bb x \u27e8ha, hb\u27e9, not_le_of_lt (h.trans_lt hb) ha\n\n@[simp] lemma Iic_disjoint_Ioc (h : a \u2264 b) : disjoint (Iic a) (Ioc b c) :=\n(Iic_disjoint_Ioi h).mono le_rfl (\u03bb _, and.left)\n\n@[simp] lemma Ioc_disjoint_Ioc_same {a b c : \u03b1} : disjoint (Ioc a b) (Ioc b c) :=\n(Iic_disjoint_Ioc (le_refl b)).mono (\u03bb _, and.right) le_rfl\n\n@[simp] lemma Ico_disjoint_Ico_same {a b c : \u03b1} : disjoint (Ico a b) (Ico b c) :=\n\u03bb x hx, not_le_of_lt hx.1.2 hx.2.1\n\n@[simp] lemma Ici_disjoint_Iic : disjoint (Ici a) (Iic b) \u2194 \u00ac(a \u2264 b) :=\nby rw [set.disjoint_iff_inter_eq_empty, Ici_inter_Iic, Icc_eq_empty_iff]\n\n@[simp] lemma Iic_disjoint_Ici : disjoint (Iic a) (Ici b) \u2194 \u00ac(b \u2264 a) :=\ndisjoint.comm.trans Ici_disjoint_Iic\n\n@[simp] lemma Union_Iic : (\u22c3 a : \u03b1, Iic a) = univ := Union_eq_univ_iff.2 $ \u03bb x, \u27e8x, right_mem_Iic\u27e9\n@[simp] lemma Union_Ici : (\u22c3 a : \u03b1, Ici a) = univ := Union_eq_univ_iff.2 $ \u03bb x, \u27e8x, left_mem_Ici\u27e9\n\n@[simp] lemma Union_Icc_right (a : \u03b1) : (\u22c3 b, Icc a b) = Ici a :=\nby simp only [\u2190 Ici_inter_Iic, \u2190 inter_Union, Union_Iic, inter_univ]\n\n@[simp] lemma Union_Ioc_right (a : \u03b1) : (\u22c3 b, Ioc a b) = Ioi a :=\nby simp only [\u2190 Ioi_inter_Iic, \u2190 inter_Union, Union_Iic, inter_univ]\n\n@[simp] lemma Union_Icc_left (b : \u03b1) : (\u22c3 a, Icc a b) = Iic b :=\nby simp only [\u2190 Ici_inter_Iic, \u2190 Union_inter, Union_Ici, univ_inter]\n\n@[simp] lemma Union_Ico_left (b : \u03b1) : (\u22c3 a, Ico a b) = Iio b :=\nby simp only [\u2190 Ici_inter_Iio, \u2190 Union_inter, Union_Ici, univ_inter]\n\n@[simp] lemma Union_Iio [no_max_order \u03b1] : (\u22c3 a : \u03b1, Iio a) = univ :=\nUnion_eq_univ_iff.2 exists_gt\n\n@[simp] lemma Union_Ioi [no_min_order \u03b1] : (\u22c3 a : \u03b1, Ioi a) = univ :=\nUnion_eq_univ_iff.2 exists_lt\n\n@[simp] lemma Union_Ico_right [no_max_order \u03b1] (a : \u03b1) : (\u22c3 b, Ico a b) = Ici a :=\nby simp only [\u2190 Ici_inter_Iio, \u2190 inter_Union, Union_Iio, inter_univ]\n\n@[simp] lemma Union_Ioo_right [no_max_order \u03b1] (a : \u03b1) : (\u22c3 b, Ioo a b) = Ioi a :=\nby simp only [\u2190 Ioi_inter_Iio, \u2190 inter_Union, Union_Iio, inter_univ]\n\n@[simp] lemma Union_Ioc_left [no_min_order \u03b1] (b : \u03b1) : (\u22c3 a, Ioc a b) = Iic b :=\nby simp only [\u2190 Ioi_inter_Iic, \u2190 Union_inter, Union_Ioi, univ_inter]\n\n@[simp] lemma Union_Ioo_left [no_min_order \u03b1] (b : \u03b1) : (\u22c3 a, Ioo a b) = Iio b :=\nby simp only [\u2190 Ioi_inter_Iio, \u2190 Union_inter, Union_Ioi, univ_inter]\n\nend preorder\n\nsection linear_order\nvariables [linear_order \u03b1] {a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1}\n\n@[simp] lemma Ico_disjoint_Ico : disjoint (Ico a\u2081 a\u2082) (Ico b\u2081 b\u2082) \u2194 min a\u2082 b\u2082 \u2264 max a\u2081 b\u2081 :=\nby simp_rw [set.disjoint_iff_inter_eq_empty, Ico_inter_Ico, Ico_eq_empty_iff,\n  inf_eq_min, sup_eq_max, not_lt]\n\n@[simp] lemma Ioc_disjoint_Ioc : disjoint (Ioc a\u2081 a\u2082) (Ioc b\u2081 b\u2082) \u2194 min a\u2082 b\u2082 \u2264 max a\u2081 b\u2081 :=\nhave h : _ \u2194 min (to_dual a\u2081) (to_dual b\u2081) \u2264 max (to_dual a\u2082) (to_dual b\u2082) := Ico_disjoint_Ico,\nby simpa only [dual_Ico] using h\n\n/-- If two half-open intervals are disjoint and the endpoint of one lies in the other,\n  then it must be equal to the endpoint of the other. -/\nlemma eq_of_Ico_disjoint {x\u2081 x\u2082 y\u2081 y\u2082 : \u03b1}\n  (h : disjoint (Ico x\u2081 x\u2082) (Ico y\u2081 y\u2082)) (hx : x\u2081 < x\u2082) (h2 : x\u2082 \u2208 Ico y\u2081 y\u2082) :\n  y\u2081 = x\u2082 :=\nbegin\n  rw [Ico_disjoint_Ico, min_eq_left (le_of_lt h2.2), le_max_iff] at h,\n  apply le_antisymm h2.1,\n  exact h.elim (\u03bb h, absurd hx (not_lt_of_le h)) id\nend\n\n@[simp] lemma Union_Ico_eq_Iio_self_iff {f : \u03b9 \u2192 \u03b1} {a : \u03b1} :\n  (\u22c3 i, Ico (f i) a) = Iio a \u2194 \u2200 x < a, \u2203 i, f i \u2264 x :=\nby simp [\u2190 Ici_inter_Iio, \u2190 Union_inter, subset_def]\n\n@[simp] lemma Union_Ioc_eq_Ioi_self_iff {f : \u03b9 \u2192 \u03b1} {a : \u03b1} :\n  (\u22c3 i, Ioc a (f i)) = Ioi a \u2194 \u2200 x, a < x \u2192 \u2203 i, x \u2264 f i :=\nby simp [\u2190 Ioi_inter_Iic, \u2190 inter_Union, subset_def]\n\n@[simp] lemma bUnion_Ico_eq_Iio_self_iff {p : \u03b9 \u2192 Prop} {f : \u03a0 i, p i \u2192 \u03b1} {a : \u03b1} :\n  (\u22c3 i (hi : p i), Ico (f i hi) a) = Iio a \u2194 \u2200 x < a, \u2203 i hi, f i hi \u2264 x :=\nby simp [\u2190 Ici_inter_Iio, \u2190 Union_inter, subset_def]\n\n@[simp] \n\nend linear_order\n\nend set\n\nsection Union_Ixx\n\nvariables [linear_order \u03b1] {s : set \u03b1} {a : \u03b1} {f : \u03b9 \u2192 \u03b1}\n\nlemma is_glb.bUnion_Ioi_eq (h : is_glb s a) : (\u22c3 x \u2208 s, Ioi x) = Ioi a :=\nbegin\n  refine (Union\u2082_subset $ \u03bb x hx, _).antisymm (\u03bb x hx, _),\n  { exact Ioi_subset_Ioi (h.1 hx) },\n  { rcases h.exists_between hx with \u27e8y, hys, hay, hyx\u27e9,\n    exact mem_bUnion hys hyx }\nend\n\nlemma is_glb.Union_Ioi_eq (h : is_glb (range f) a) :\n  (\u22c3 x, Ioi (f x)) = Ioi a :=\nbUnion_range.symm.trans h.bUnion_Ioi_eq\n\nlemma is_lub.bUnion_Iio_eq (h : is_lub s a) :\n  (\u22c3 x \u2208 s, Iio x) = Iio a :=\nh.dual.bUnion_Ioi_eq\n\nlemma is_lub.Union_Iio_eq (h : is_lub (range f) a) :\n  (\u22c3 x, Iio (f x)) = Iio a :=\nh.dual.Union_Ioi_eq\n\nend Union_Ixx\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/data/set/intervals/disjoint.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7049446339748623}}
{"text": "/-\nCopyright (c) 2018 Johan Commelin All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Chris Hughes, Kevin Buzzard\n-/\nimport algebra.group.hom\n/-!\n# Lift monoid homomorphisms to group homomorphisms of their units subgroups.\n-/\n\nuniverses u v w\n\nnamespace units\nvariables {M : Type u} {N : Type v} {P : Type w} [monoid M] [monoid N] [monoid P]\n\n/-- The group homomorphism on units induced by a `monoid_hom`. -/\n@[to_additive \"The `add_group` homomorphism on `add_unit`s induced by an `add_monoid_hom`.\"]\ndef map (f : M \u2192* N) : units M \u2192* units N :=\nmonoid_hom.mk'\n  (\u03bb u, \u27e8f u.val, f u.inv,\n                  by rw [\u2190 f.map_mul, u.val_inv, f.map_one],\n                  by rw [\u2190 f.map_mul, u.inv_val, f.map_one]\u27e9)\n  (\u03bb x y, ext (f.map_mul x y))\n\n@[simp, to_additive] lemma coe_map (f : M \u2192* N) (x : units M) : \u2191(map f x) = f x := rfl\n\n@[simp, to_additive] lemma coe_map_inv (f : M \u2192* N) (u : units M) :\n  \u2191(map f u)\u207b\u00b9 = f \u2191u\u207b\u00b9 :=\nrfl\n\n@[simp, to_additive]\nlemma map_comp (f : M \u2192* N) (g : N \u2192* P) : map (g.comp f) = (map g).comp (map f) := rfl\n\nvariables (M)\n@[simp, to_additive] lemma map_id : map (monoid_hom.id M) = monoid_hom.id (units M) :=\nby ext; refl\n\n/-- Coercion `units M \u2192 M` as a monoid homomorphism. -/\n@[to_additive \"Coercion `add_units M \u2192 M` as an add_monoid homomorphism.\"]\ndef coe_hom : units M \u2192* M := \u27e8coe, coe_one, coe_mul\u27e9\n\nvariable {M}\n\n@[simp, to_additive] lemma coe_hom_apply (x : units M) : coe_hom M x = \u2191x := rfl\n\n/-- If a map `g : M \u2192 units N` agrees with a homomorphism `f : M \u2192* N`, then\nthis map is a monoid homomorphism too. -/\n@[to_additive \"If a map `g : M \u2192 add_units N` agrees with a homomorphism `f : M \u2192+ N`, then this map\nis an add_monoid homomorphism too.\"]\ndef lift_right (f : M \u2192* N) (g : M \u2192 units N) (h : \u2200 x, \u2191(g x) = f x) :\n  M \u2192* units N :=\n{ to_fun := g,\n  map_one' := units.ext $ (h 1).symm \u25b8 f.map_one,\n  map_mul' := \u03bb x y, units.ext $ by simp only [h, coe_mul, f.map_mul] }\n\n@[simp, to_additive] lemma coe_lift_right {f : M \u2192* N} {g : M \u2192 units N}\n  (h : \u2200 x, \u2191(g x) = f x) (x) : (lift_right f g h x : N) = f x := h x\n\n@[simp, to_additive] lemma mul_lift_right_inv {f : M \u2192* N} {g : M \u2192 units N}\n  (h : \u2200 x, \u2191(g x) = f x) (x) : f x * \u2191(lift_right f g h x)\u207b\u00b9 = 1 :=\nby rw [units.mul_inv_eq_iff_eq_mul, one_mul, coe_lift_right]\n\n@[simp, to_additive] lemma lift_right_inv_mul {f : M \u2192* N} {g : M \u2192 units N}\n  (h : \u2200 x, \u2191(g x) = f x) (x) : \u2191(lift_right f g h x)\u207b\u00b9 * f x = 1 :=\nby rw [units.inv_mul_eq_iff_eq_mul, mul_one, coe_lift_right]\n\nend units\n\nnamespace monoid_hom\n\n/-- If `f` is a homomorphism from a group `G` to a monoid `M`,\nthen its image lies in the units of `M`,\nand `f.to_hom_units` is the corresponding monoid homomorphism from `G` to `units M`. -/\n@[to_additive \"If `f` is a homomorphism from an additive group `G` to an additive monoid `M`,\nthen its image lies in the `add_units` of `M`,\nand `f.to_hom_units` is the corresponding homomorphism from `G` to `add_units M`.\"]\ndef to_hom_units {G M : Type*} [group G] [monoid M] (f : G \u2192* M) : G \u2192* units M :=\n{ to_fun := \u03bb g,\n    \u27e8f g, f (g\u207b\u00b9),\n      by rw [\u2190 f.map_mul, mul_inv_self, f.map_one],\n      by rw [\u2190 f.map_mul, inv_mul_self, f.map_one]\u27e9,\n  map_one' := units.ext (f.map_one),\n  map_mul' := \u03bb _ _, units.ext (f.map_mul _ _) }\n\n@[simp] lemma coe_to_hom_units {G M : Type*} [group G] [monoid M] (f : G \u2192* M) (g : G):\n  (f.to_hom_units g : M) = f g := rfl\n\nend monoid_hom\n\nsection is_unit\nvariables {M : Type*} {N : Type*}\n\n@[to_additive] lemma is_unit.map [monoid M] [monoid N]\n  (f : M \u2192* N) {x : M} (h : is_unit x) : is_unit (f x) :=\nby rcases h with \u27e8y, rfl\u27e9; exact (units.map f y).is_unit\n\n/-- If a homomorphism `f : M \u2192* N` sends each element to an `is_unit`, then it can be lifted\nto `f : M \u2192* units N`. See also `units.lift_right` for a computable version. -/\n@[to_additive \"If a homomorphism `f : M \u2192+ N` sends each element to an `is_add_unit`, then it can be\nlifted to `f : M \u2192+ add_units N`. See also `add_units.lift_right` for a computable version.\"]\nnoncomputable def is_unit.lift_right [monoid M] [monoid N] (f : M \u2192* N)\n  (hf : \u2200 x, is_unit (f x)) : M \u2192* units N :=\nunits.lift_right f (\u03bb x, classical.some (hf x)) $ \u03bb x, classical.some_spec (hf x)\n\n@[to_additive] lemma is_unit.coe_lift_right [monoid M] [monoid N] (f : M \u2192* N)\n  (hf : \u2200 x, is_unit (f x)) (x) :\n  (is_unit.lift_right f hf x : N) = f x :=\nunits.coe_lift_right _ x\n\n@[simp, to_additive] lemma is_unit.mul_lift_right_inv [monoid M] [monoid N] (f : M \u2192* N)\n  (h : \u2200 x, is_unit (f x)) (x) : f x * \u2191(is_unit.lift_right f h x)\u207b\u00b9 = 1 :=\nunits.mul_lift_right_inv (\u03bb y, classical.some_spec $ h y) x\n\n@[simp, to_additive] lemma is_unit.lift_right_inv_mul [monoid M] [monoid N] (f : M \u2192* N)\n  (h : \u2200 x, is_unit (f x)) (x) : \u2191(is_unit.lift_right f h x)\u207b\u00b9 * f x = 1 :=\nunits.lift_right_inv_mul (\u03bb y, classical.some_spec $ h y) x\n\nend is_unit\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/group/units_hom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7049446295176041}}
{"text": "-- Diferencia_de_diferencia_de_conjuntos_2.lean\n-- 2\u00aa diferencia de diferencia de conjuntos.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 21 de mayo de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    s \\ (t \u222a u) \u2286 (s \\ t) \\ u\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t u : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  intros x hx,\n  split,\n  { split,\n    { exact hx.1, },\n    { intro xt,\n      apply hx.2,\n      left,\n      exact xt, }},\n  { intro xu,\n    apply hx.2,\n    right,\n    exact xu, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  rintros x \u27e8xs, xntu\u27e9,\n  split,\n  { split,\n    { exact xs, },\n    { intro xt,\n      exact xntu (or.inl xt), }},\n  { intro xu,\n    exact xntu (or.inr xu), },\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  rintros x \u27e8xs, xntu\u27e9,\n  use xs,\n  { intro xt,\n    exact xntu (or.inl xt) },\n  { intro xu,\n    exact xntu (or.inr xu) },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nbegin\n  rintros x \u27e8xs, xntu\u27e9;\n  finish,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nby intro ; finish\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : s \\ (t \u222a u) \u2286 (s \\ t) \\ u :=\nby rw diff_diff\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Diferencia_de_diferencia_de_conjuntos_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544824, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7049446252206579}}
{"text": "/-\n# Proposition world. \n\n## Level 9: a big maze. \n\nLean's \"congruence closure\" tactic `cc` is good at mazes. You might want to try it now.\nPerhaps I should have mentioned it earlier.\n-/\n\n/- Lemma : no-side-bar\nThere is a way through the following maze.\n-/\nexample (A B C D E F G H I J K L : Prop)\n(f1 : A \u2192 B) (f2 : B \u2192 E) (f3 : E \u2192 D) (f4 : D \u2192 A) (f5 : E \u2192 F)\n(f6 : F \u2192 C) (f7 : B \u2192 C) (f8 : F \u2192 G) (f9 : G \u2192 J) (f10 : I \u2192 J)\n(f11 : J \u2192 I) (f12 : I \u2192 H) (f13 : E \u2192 H) (f14 : H \u2192 K) (f15 : I \u2192 L)\n : A \u2192 L :=\nbegin\n  cc,\n\n\n\nend\n\n/-\nNow move onto advanced proposition world, where you will see\nhow to prove goals such as `P \u2227 Q` ($P$ and $Q$), `P \u2228 Q` ($P$ or $Q$),\n`P \u2194 Q` ($P\\iff Q$).\nYou will need to learn five more tactics: `split`, `cases`,\n`left`, `right`, and `exfalso`,\nbut they are all straightforward, and furthermore they are\nessentially the last tactics you\nneed to learn in order to complete all the levels of the Natural Number Game,\nincluding all the 17 levels of Inequality World. \n-/\n\n/- Tactic : cc\n\n## Summary:\n\n`cc` will solve certain \"logic\" goals.\n\n## Details\n\n`cc` is a \"congruence closure tactic\". In practice this means that it is\ngood at solving certain logic goals. It's worth trying if you think\nthat the goal could be solved using truth tables.\n-/", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world6/level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530492, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7049153270653976}}
{"text": "import ..lectures.love05_inductive_predicates_demo\nimport ..lectures.love13_rational_and_real_numbers_demo\n\n\n/-! # LoVe Exercise 13: Rational and Real Numbers -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Rationals\n1.1. Prove the following lemma.\nHint: The lemma `fraction.mk.inj_eq` might be useful. -/\n\n#check fraction.mk.inj_eq\n\nlemma fraction.ext (a b : fraction) (hnum : fraction.num a = fraction.num b)\n    (hdenom : fraction.denom a = fraction.denom b) :\n  a = b := sorry\n\n/-! 1.2. Extending the `fraction.has_mul` instance from the lecture, declare\n`fraction` as an instance of `semigroup`.\nHint: Use the lemma `fraction.ext` above, and possibly `fraction.mul_num`, and\n`fraction.mul_denom`. -/\n\n#check fraction.ext\n#check fraction.mul_num\n#check fraction.mul_denom\n\n@[instance] def fraction.semigroup : semigroup fraction :=\n{ mul_assoc := sorry\n  ..fraction.has_mul }\n\n/-! 1.3. Extending the `rat.has_mul` instance from the lecture, declare `rat` as\nan instance of `semigroup`. -/\n\n@[instance] def rat.semigroup : semigroup rat :=\n{ mul_assoc :=\n sorry\n  ..rat.has_mul }\n\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/exercises/love13_rational_and_real_numbers_exercise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7049153183545074}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport topology.instances.ennreal\nimport algebra.squarefree\n\n/-!\n# Divergence of the Prime Reciprocal Series\n\nThis file proves Theorem 81 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).\nThe theorem states that the sum of the reciprocals of all prime numbers diverges.\nThe formalization follows Erd\u0151s's proof by upper and lower estimates.\n\n## Proof outline\n\n1. Assume that the sum of the reciprocals of the primes converges.\n2. Then there exists a `k : \u2115` such that, for any `x : \u2115`, the sum of the reciprocals of the primes\n   between `k` and `x + 1` is less than 1/2 (`sum_lt_half_of_not_tendsto`).\n3. For any `x : \u2115`, we can partition `range x` into two subsets (`range_sdiff_eq_bUnion`):\n    * `M x k`, the subset of those `e` for which `e + 1` is a product of powers of primes smaller\n      than or equal to `k`;\n    * `U x k`, the subset of those `e` for which there is a prime `p > k` that divides `e + 1`.\n4. Then `|U x k|` is bounded by the sum over the primes `p > k` of the number of multiples of `p`\n   in `(k, x]`, which is at most `x / p`. It follows that `|U x k|` is at most `x` times the sum of\n  the reciprocals of the primes between `k` and `x + 1`, which is less than 1/2 as noted in (2), so\n  `|U x k| < x / 2` (`card_le_mul_sum`).\n5. By factoring `e + 1 = (m + 1)\u00b2 * (r + 1)`, `r + 1` squarefree and `m + 1 \u2264 \u221ax`, and noting that\n   squarefree numbers correspond to subsets of `[1, k]`, we find that `|M x k| \u2264 2 ^ k * \u221ax`\n   (`card_le_two_pow_mul_sqrt`).\n6. Finally, setting `x := (2 ^ (k + 1))\u00b2` (`\u221ax = 2 ^ (k + 1)`), we find that\n   `|M x k| \u2264 2 ^ k * 2 ^ (k + 1) = x / 2`. Combined with the strict bound for `|U k x|` from (4),\n   `x = |M x k| + |U x k| < x / 2 + x / 2 = x`.\n\n## References\n\nhttps://en.wikipedia.org/wiki/Divergence_of_the_sum_of_the_reciprocals_of_the_primes\n-/\n\nopen_locale big_operators\nopen_locale classical\nopen filter finset\n\n/--\nThe primes in `(k, x]`.\n-/\nnoncomputable def P (x k : \u2115) := {p \u2208 range (x + 1) | k < p \u2227 nat.prime p}\n\n/--\nThe union over those primes `p \u2208 (k, x]` of the sets of `e < x` for which `e + 1` is a multiple\nof `p`, i.e., those `e < x` for which there is a prime `p \u2208 (k, x]` that divides `e + 1`.\n-/\nnoncomputable def U (x k : \u2115) := finset.bUnion (P x k) (\u03bb p, {e \u2208 range x | p \u2223 e + 1})\n\n/--\nThose `e < x` for which `e + 1` is a product of powers of primes smaller than or equal to `k`.\n-/\nnoncomputable def M (x k : \u2115) := {e \u2208 range x | \u2200 p : \u2115, (nat.prime p \u2227 p \u2223 e + 1) \u2192 p \u2264 k}\n\n/--\nIf the sum of the reciprocals of the primes converges, there exists a `k : \u2115` such that the sum of\nthe reciprocals of the primes greater than `k` is less than 1/2.\n\nMore precisely, for any `x : \u2115`, the sum of the reciprocals of the primes between `k` and `x + 1`\nis less than 1/2.\n-/\nlemma sum_lt_half_of_not_tendsto\n  (h : \u00ac tendsto (\u03bb n, \u2211 p in {p \u2208 range n | nat.prime p}, (1 / (p : \u211d))) at_top at_top) :\n  \u2203 k, \u2200 x, \u2211 p in P x k, 1 / (p : \u211d) < 1 / 2 :=\nbegin\n  have h0 : (\u03bb n, \u2211 p in {p \u2208 range n | nat.prime p}, (1 / (p : \u211d)))\n          = \u03bb n, \u2211 p in range n, ite (nat.prime p) (1 / (p : \u211d)) 0,\n  { simp only [sum_filter, filter_congr_decidable, sep_def] },\n\n  have hf : \u2200 n : \u2115, 0 \u2264 ite (nat.prime n) (1 / (n : \u211d)) 0,\n  { intro n, split_ifs,\n    { simp only [one_div, inv_nonneg, nat.cast_nonneg] },\n    { exact le_rfl } },\n\n  rw [h0, \u2190 summable_iff_not_tendsto_nat_at_top_of_nonneg hf, summable_iff_vanishing] at h,\n  obtain \u27e8s, h\u27e9 := h (set.Ioo (-1) (1/2)) (is_open_Ioo.mem_nhds (by norm_num)),\n  obtain \u27e8k, hk\u27e9 := exists_nat_subset_range s,\n  use k,\n  intro x,\n\n  rw [P, sep_def, filter_congr_decidable, \u2190filter_filter, sum_filter],\n  refine (h _ _).2,\n  rw disjoint_iff_ne,\n  simp_intros a ha b hb only [mem_filter],\n  exact ((mem_range.mp (hk hb)).trans ha.2).ne',\nend\n\n/--\nRemoving from {0, ..., x - 1} those elements `e` for which `e + 1` is a product of powers of primes\nsmaller than or equal to `k` leaves those `e` for which there is a prime `p > k` that divides\n`e + 1`, or the union over those primes `p > k` of the sets of `e`s for which `e + 1` is a multiple\nof `p`.\n-/\nlemma range_sdiff_eq_bUnion {x k : \u2115} : range x \\ M x k = U x k :=\nbegin\n  ext e,\n  simp only [mem_bUnion, not_and, mem_sdiff, sep_def, mem_filter, mem_range, U, M, P],\n  push_neg,\n  split,\n  { rintros \u27e8hex, hexh\u27e9,\n    obtain \u27e8p, \u27e8hpp, hpe1\u27e9, hpk\u27e9 := hexh hex,\n    refine \u27e8p, _, \u27e8hex, hpe1\u27e9\u27e9,\n    exact \u27e8(nat.le_of_dvd e.succ_pos hpe1).trans_lt (nat.succ_lt_succ hex), hpk, hpp\u27e9 },\n  { rintros \u27e8p, hpfilter, \u27e8hex, hpe1\u27e9\u27e9,\n    rw imp_iff_right hex,\n    exact \u27e8hex, \u27e8p, \u27e8hpfilter.2.2, hpe1\u27e9, hpfilter.2.1\u27e9\u27e9 },\nend\n\n/--\nThe number of `e < x` for which `e + 1` has a prime factor `p > k` is bounded by `x` times the sum\nof reciprocals of primes in `(k, x]`.\n-/\nlemma card_le_mul_sum {x k : \u2115} : (card (U x k) : \u211d) \u2264 x * \u2211 p in P x k, 1 / p :=\nbegin\n  let P := {p \u2208 range (x + 1) | k < p \u2227 nat.prime p},\n  let N := \u03bb p, {e \u2208 range x | p \u2223 e + 1},\n  have h : card (finset.bUnion P N) \u2264 \u2211 p in P, card (N p) := card_bUnion_le,\n\n  calc  (card (finset.bUnion P N) : \u211d)\n      \u2264 \u2211 p in P, card (N p)  : by assumption_mod_cast\n  ... \u2264 \u2211 p in P, x * (1 / p) : sum_le_sum (\u03bb p hp, _)\n  ... = x * \u2211 p in P, 1 / p   : mul_sum.symm,\n  simp only [mul_one_div, N, sep_def, filter_congr_decidable, card_multiples, nat.cast_div_le],\nend\n\n/--\nThe number of `e < x` for which `e + 1` is a squarefree product of primes smaller than or equal to\n`k` is bounded by `2 ^ k`, the number of subsets of `[1, k]`.\n-/\nlemma card_le_two_pow {x k : \u2115} : card {e \u2208 M x k | squarefree (e + 1)} \u2264 2 ^ k :=\nbegin\n  let M\u2081 := {e \u2208 M x k | squarefree (e + 1)},\n  let f := \u03bb s, finset.prod s (\u03bb a, a) - 1,\n  let K := powerset (image nat.succ (range k)),\n\n  -- Take `e` in `M x k`. If `e + 1` is squarefree, then it is the product of a subset of `[1, k]`.\n  -- It follows that `e` is one less than such a product.\n  have h : M\u2081 \u2286 image f K,\n  { intros m hm,\n    simp only [M\u2081, M, sep_def, mem_filter, mem_range, mem_powerset, mem_image, exists_prop] at hm \u22a2,\n    obtain \u27e8\u27e8-, hmp\u27e9, hms\u27e9 := hm,\n    use (m + 1).factors,\n    { rwa [multiset.coe_nodup, \u2190 nat.squarefree_iff_nodup_factors m.succ_ne_zero] },\n    refine \u27e8\u03bb p, _, _\u27e9,\n    { suffices : p \u2208 (m + 1).factors \u2192 \u2203 a : \u2115, a < k \u2227 a.succ = p, { simpa },\n      simp_intros hp only [nat.mem_factors m.succ_ne_zero],\n      exact \u27e8p.pred, (nat.pred_lt (nat.prime.ne_zero hp.1)).trans_le ((hmp p) hp),\n            nat.succ_pred_eq_of_pos (nat.prime.pos hp.1)\u27e9 },\n    { simp_rw f, simp [nat.prod_factors m.succ_ne_zero, m.succ_sub_one] } },\n\n  -- The number of elements of `M x k` with `e + 1` squarefree is bounded by the number of subsets\n  -- of `[1, k]`.\n  calc card M\u2081 \u2264 card (image f K)                    : card_le_of_subset h\n  ...          \u2264 card K                              : card_image_le\n  ...          \u2264 2 ^ card (image nat.succ (range k)) : by simp only [K, card_powerset]\n  ...          \u2264 2 ^ card (range k)                  : pow_le_pow one_le_two card_image_le\n  ...          = 2 ^ k                               : by rw card_range k,\nend\n\n/--\nThe number of `e < x` for which `e + 1` is a product of powers of primes smaller than or equal to\n`k` is bounded by `2 ^ k * nat.sqrt x`.\n-/\nlemma card_le_two_pow_mul_sqrt {x k : \u2115} : card (M x k) \u2264 2 ^ k * nat.sqrt x :=\nbegin\n  let M\u2081 := {e \u2208 M x k | squarefree (e + 1)},\n  let M\u2082 := M (nat.sqrt x) k,\n  let K := finset.product M\u2081 M\u2082,\n  let f : \u2115 \u00d7 \u2115 \u2192 \u2115 := \u03bb mn, (mn.2 + 1) ^ 2 * (mn.1 + 1) - 1,\n\n  -- Every element of `M x k` is one less than the product `(m + 1)\u00b2 * (r + 1)` with `r + 1`\n  -- squarefree and `m + 1 \u2264 \u221ax`, and both `m + 1` and `r + 1` still only have prime powers\n  -- smaller than or equal to `k`.\n  have h1 : M x k \u2286 image f K,\n  { intros m hm,\n    simp only [M, M\u2081, M\u2082, mem_image, exists_prop, prod.exists, mem_product, sep_def, mem_filter,\n               mem_range] at hm \u22a2,\n    have hm' := m.zero_lt_succ,\n    obtain \u27e8a, b, hab\u2081, hab\u2082\u27e9 := nat.sq_mul_squarefree_of_pos' hm',\n    obtain \u27e8ham, hbm\u27e9 := \u27e8dvd.intro_left _ hab\u2081, dvd.intro _ hab\u2081\u27e9,\n    refine \u27e8a, b, \u27e8\u27e8\u27e8_, \u03bb p hp, _\u27e9, hab\u2082\u27e9, \u27e8_, \u03bb p hp, _\u27e9\u27e9, by simp_rw [f, hab\u2081, m.succ_sub_one]\u27e9,\n    { exact (nat.succ_le_succ_iff.mp (nat.le_of_dvd hm' ham)).trans_lt hm.1 },\n    { exact hm.2 p \u27e8hp.1, hp.2.trans ham\u27e9 },\n    { calc b < b + 1        : lt_add_one b\n      ...    \u2264 (m + 1).sqrt : by simpa only [nat.le_sqrt, pow_two] using nat.le_of_dvd hm' hbm\n      ...    \u2264 x.sqrt       : nat.sqrt_le_sqrt (nat.succ_le_iff.mpr hm.1) },\n    { exact hm.2 p \u27e8hp.1, hp.2.trans (nat.dvd_of_pow_dvd one_le_two hbm)\u27e9 } },\n\n  have h2 : card M\u2082 \u2264 nat.sqrt x,\n  { rw \u2190 card_range (nat.sqrt x), apply card_le_of_subset, simp [M\u2082, M] },\n\n  calc card (M x k) \u2264 card (image f K)   : card_le_of_subset h1\n  ...               \u2264 card K             : card_image_le\n  ...               = card M\u2081 * card M\u2082  : card_product M\u2081 M\u2082\n  ...               \u2264 2 ^ k * x.sqrt     : mul_le_mul' card_le_two_pow h2,\nend\n\ntheorem real.tendsto_sum_one_div_prime_at_top :\n  tendsto (\u03bb n, \u2211 p in {p \u2208 range n | nat.prime p}, (1 / (p : \u211d))) at_top at_top :=\nbegin\n  -- Assume that the sum of the reciprocals of the primes converges.\n  by_contradiction h,\n\n  -- Then there is a natural number `k` such that for all `x`, the sum of the reciprocals of primes\n  -- between `k` and `x` is less than 1/2.\n  obtain \u27e8k, h1\u27e9 := sum_lt_half_of_not_tendsto h,\n\n  -- Choose `x` sufficiently large for the argument below to work, and use a perfect square so we\n  -- can easily take the square root.\n  let x := 2 ^ (k + 1) * 2 ^ (k + 1),\n\n  -- We will partition `range x` into two subsets:\n  -- * `M`, the subset of those `e` for which `e + 1` is a product of powers of primes smaller\n  --   than or equal to `k`;\n  set M := M x k with hM,\n\n  -- * `U`, the subset of those `e` for which there is a prime `p > k` that divides `e + 1`.\n  let P := {p \u2208 range (x + 1) | k < p \u2227 nat.prime p},\n  set U := U x k with hU,\n\n  -- This is indeed a partition, so `|U| + |M| = |range x| = x`.\n  have h2 : x = card U + card M,\n  { rw [\u2190 card_range x, hU, hM, \u2190 range_sdiff_eq_bUnion],\n    exact (card_sdiff_add_card_eq_card (finset.filter_subset _ _)).symm },\n\n  -- But for the `x` we have chosen above, both `|U|` and `|M|` are less than or equal to `x / 2`,\n  -- and for U, the inequality is strict.\n  have h3 :=\n    calc (card U : \u211d) \u2264 x * \u2211 p in P, 1 / p : card_le_mul_sum\n    ...               < x * (1 / 2)         : mul_lt_mul_of_pos_left (h1 x) (by norm_num)\n    ...               = x / 2               : mul_one_div x 2,\n\n  have h4 :=\n    calc (card M : \u211d) \u2264 2 ^ k * x.sqrt      : by exact_mod_cast card_le_two_pow_mul_sqrt\n    ...               = 2 ^ k * \u2191(2 ^ (k + 1)) : by rw nat.sqrt_eq\n    ...               = x / 2               : by field_simp [x, mul_right_comm, \u2190 pow_succ'],\n\n  refine lt_irrefl (x : \u211d) _,\n  calc (x : \u211d) = (card U : \u211d) + (card M : \u211d) : by assumption_mod_cast\n  ...          < x / 2 + x / 2               : add_lt_add_of_lt_of_le h3 h4\n  ...          = x                           : add_halves \u2191x,\nend\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/archive/100-theorems-list/81_sum_of_prime_reciprocals_diverges.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530492, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7049153169850331}}
{"text": "-- Regla de introducci\u00f3n del cuantificador existencial\n-- ===================================================\n\n-- Ej. 1. Demostrar\n--    \u2200x P(x) \u22a2 \u2203x P(x)\n\nimport tactic\n\nvariable U : Type \nvariable c : U\nvariable P : U -> Prop\n\n-- 1\u00aa demostraci\u00f3n\nexample \n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\nhave h2 : P c, from h1 c,\nshow \u2203x, P x,  from exists.intro c h2\n\n-- 2\u00aa demostraci\u00f3n\nexample \n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\nshow \u2203x, P x,  from exists.intro c (h1 c)\n\n-- 3\u00aa demostraci\u00f3n\nexample \n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\nexists.intro c (h1 c)\n\n-- 4\u00aa demostraci\u00f3n\nexample \n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\n\u27e8c, h1 c\u27e9\n\n-- 5\u00aa demostraci\u00f3n\nexample \n  (a : U)\n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\nbegin\n  use a,\n  apply h1,\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample \n  (a : U)\n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\nbegin\n  constructor,\n  apply h1 a,\nend\n\n-- 7\u00aa demostraci\u00f3n\nexample \n  [inhabited U]\n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\nbegin\n  constructor,\n  apply h1 (default U),\nend\n\n-- 8\u00aa demostraci\u00f3n\nexample \n  (h : nonempty U)\n  (h1 : \u2200x, P x)\n  : \u2203x, P x :=\nbegin\n  use (classical.choice h),\n  apply h1,\nend\n\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/2_LPO/Regla_de_introduccion_del_cuantificador_existencial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.7049153150070984}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.sqrt\nimport Mathlib.data.nat.gcd\nimport Mathlib.algebra.group_power.default\nimport Mathlib.tactic.wlog\nimport Mathlib.tactic.norm_num\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Prime numbers\n\nThis file deals with prime numbers: natural numbers `p \u2265 2` whose only divisors are `p` and `1`.\n\n## Important declarations\n\nAll the following declarations exist in the namespace `nat`.\n\n- `prime`: the predicate that expresses that a natural number `p` is prime\n- `primes`: the subtype of natural numbers that are prime\n- `min_fac n`: the minimal prime factor of a natural number `n \u2260 1`\n- `exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers\n- `factors n`: the prime factorization of `n`\n- `factors_unique`: uniqueness of the prime factorisation\n\n-/\n\nnamespace nat\n\n\n/-- `prime p` means that `p` is a prime number, that is, a natural number\n  at least 2 whose only divisors are `p` and `1`. -/\ndef prime (p : \u2115) := bit0 1 \u2264 p \u2227 \u2200 (m : \u2115), m \u2223 p \u2192 m = 1 \u2228 m = p\n\ntheorem prime.two_le {p : \u2115} : prime p \u2192 bit0 1 \u2264 p := and.left\n\ntheorem prime.one_lt {p : \u2115} : prime p \u2192 1 < p := prime.two_le\n\nprotected instance prime.one_lt' (p : \u2115) [hp : fact (prime p)] : fact (1 < p) := prime.one_lt hp\n\ntheorem prime.ne_one {p : \u2115} (hp : prime p) : p \u2260 1 := ne.symm (ne_of_lt (prime.one_lt hp))\n\ntheorem prime_def_lt {p : \u2115} : prime p \u2194 bit0 1 \u2264 p \u2227 \u2200 (m : \u2115), m < p \u2192 m \u2223 p \u2192 m = 1 := sorry\n\ntheorem prime_def_lt' {p : \u2115} : prime p \u2194 bit0 1 \u2264 p \u2227 \u2200 (m : \u2115), bit0 1 \u2264 m \u2192 m < p \u2192 \u00acm \u2223 p :=\n  sorry\n\ntheorem prime_def_le_sqrt {p : \u2115} :\n    prime p \u2194 bit0 1 \u2264 p \u2227 \u2200 (m : \u2115), bit0 1 \u2264 m \u2192 m \u2264 sqrt p \u2192 \u00acm \u2223 p :=\n  sorry\n\n/--\n  This instance is slower than the instance `decidable_prime` defined below,\n  but has the advantage that it works in the kernel.\n\n  If you need to prove that a particular number is prime, in any case\n  you should not use `dec_trivial`, but rather `by norm_num`, which is\n  much faster.\n  -/\ndef decidable_prime_1 (p : \u2115) : Decidable (prime p) :=\n  decidable_of_iff' (bit0 1 \u2264 p \u2227 \u2200 (m : \u2115), bit0 1 \u2264 m \u2192 m < p \u2192 \u00acm \u2223 p) prime_def_lt'\n\ntheorem prime.ne_zero {n : \u2115} (h : prime n) : n \u2260 0 :=\n  id fun (\u1fb0 : n = 0) => Eq._oldrec (fun (h : prime 0) => of_as_true trivial h) (Eq.symm \u1fb0) h\n\ntheorem prime.pos {p : \u2115} (pp : prime p) : 0 < p := lt_of_succ_lt (prime.one_lt pp)\n\ntheorem not_prime_zero : \u00acprime 0 := of_as_true trivial\n\ntheorem not_prime_one : \u00acprime 1 := of_as_true trivial\n\ntheorem prime_two : prime (bit0 1) := of_as_true trivial\n\ntheorem prime_three : prime (bit1 1) := of_as_true trivial\n\ntheorem prime.pred_pos {p : \u2115} (pp : prime p) : 0 < Nat.pred p :=\n  iff.mpr lt_pred_iff (prime.one_lt pp)\n\ntheorem succ_pred_prime {p : \u2115} (pp : prime p) : Nat.succ (Nat.pred p) = p :=\n  succ_pred_eq_of_pos (prime.pos pp)\n\ntheorem dvd_prime {p : \u2115} {m : \u2115} (pp : prime p) : m \u2223 p \u2194 m = 1 \u2228 m = p := sorry\n\ntheorem dvd_prime_two_le {p : \u2115} {m : \u2115} (pp : prime p) (H : bit0 1 \u2264 m) : m \u2223 p \u2194 m = p :=\n  iff.trans (dvd_prime pp) (or_iff_right_of_imp (not.elim (ne_of_gt H)))\n\ntheorem prime_dvd_prime_iff_eq {p : \u2115} {q : \u2115} (pp : prime p) (qp : prime q) : p \u2223 q \u2194 p = q :=\n  dvd_prime_two_le qp (prime.two_le pp)\n\ntheorem prime.not_dvd_one {p : \u2115} (pp : prime p) : \u00acp \u2223 1 :=\n  fun (\u1fb0 : p \u2223 1) => idRhs False (not_le_of_gt (prime.one_lt pp) (le_of_dvd (of_as_true trivial) \u1fb0))\n\ntheorem not_prime_mul {a : \u2115} {b : \u2115} (a1 : 1 < a) (b1 : 1 < b) : \u00acprime (a * b) := sorry\n\ntheorem not_prime_mul' {a : \u2115} {b : \u2115} {n : \u2115} (h : a * b = n) (h\u2081 : 1 < a) (h\u2082 : 1 < b) :\n    \u00acprime n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u00acprime n)) (Eq.symm h))) (not_prime_mul h\u2081 h\u2082)\n\ndef min_fac_aux (n : \u2115) : \u2115 \u2192 \u2115 := sorry\n\ndef min_fac : \u2115 \u2192 \u2115 := sorry\n\n@[simp] theorem min_fac_zero : min_fac 0 = bit0 1 := rfl\n\n@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl\n\ntheorem min_fac_eq (n : \u2115) : min_fac n = ite (bit0 1 \u2223 n) (bit0 1) (min_fac_aux n (bit1 1)) := sorry\n\ntheorem min_fac_aux_has_prop {n : \u2115} (n2 : bit0 1 \u2264 n) (nd2 : \u00acbit0 1 \u2223 n) (k : \u2115) (i : \u2115) :\n    k = bit0 1 * i + bit1 1 \u2192\n        (\u2200 (m : \u2115), bit0 1 \u2264 m \u2192 m \u2223 n \u2192 k \u2264 m) \u2192 min_fac_prop n (min_fac_aux n k) :=\n  sorry\n\ntheorem min_fac_has_prop {n : \u2115} (n1 : n \u2260 1) : min_fac_prop n (min_fac n) := sorry\n\ntheorem min_fac_dvd (n : \u2115) : min_fac n \u2223 n :=\n  dite (n = 1) (fun (n1 : n = 1) => Eq.symm n1 \u25b8 of_as_true trivial)\n    fun (n1 : \u00acn = 1) => and.left (and.right (min_fac_has_prop n1))\n\ntheorem min_fac_prime {n : \u2115} (n1 : n \u2260 1) : prime (min_fac n) := sorry\n\ntheorem min_fac_le_of_dvd {n : \u2115} {m : \u2115} : bit0 1 \u2264 m \u2192 m \u2223 n \u2192 min_fac n \u2264 m :=\n  dite (n = 1)\n    (fun (n1 : n = 1) (m : \u2115) (m2 : bit0 1 \u2264 m) (d : m \u2223 n) =>\n      Eq.symm n1 \u25b8 le_trans (of_as_true trivial) m2)\n    fun (n1 : \u00acn = 1) => and.right (and.right (min_fac_has_prop n1))\n\ntheorem min_fac_pos (n : \u2115) : 0 < min_fac n :=\n  dite (n = 1) (fun (n1 : n = 1) => Eq.symm n1 \u25b8 of_as_true trivial)\n    fun (n1 : \u00acn = 1) => prime.pos (min_fac_prime n1)\n\ntheorem min_fac_le {n : \u2115} (H : 0 < n) : min_fac n \u2264 n := le_of_dvd H (min_fac_dvd n)\n\ntheorem prime_def_min_fac {p : \u2115} : prime p \u2194 bit0 1 \u2264 p \u2227 min_fac p = p := sorry\n\nprotected instance decidable_prime (p : \u2115) : Decidable (prime p) :=\n  decidable_of_iff' (bit0 1 \u2264 p \u2227 min_fac p = p) prime_def_min_fac\n\ntheorem not_prime_iff_min_fac_lt {n : \u2115} (n2 : bit0 1 \u2264 n) : \u00acprime n \u2194 min_fac n < n :=\n  iff.trans (not_congr (iff.trans prime_def_min_fac (and_iff_right n2)))\n    (iff.symm (iff.trans lt_iff_le_and_ne (and_iff_right (min_fac_le (le_of_succ_le n2)))))\n\ntheorem min_fac_le_div {n : \u2115} (pos : 0 < n) (np : \u00acprime n) : min_fac n \u2264 n / min_fac n := sorry\n\ntheorem min_fac_sq_le_self {n : \u2115} (w : 0 < n) (h : \u00acprime n) : min_fac n ^ bit0 1 \u2264 n := sorry\n\n@[simp] theorem min_fac_eq_one_iff {n : \u2115} : min_fac n = 1 \u2194 n = 1 := sorry\n\n@[simp] theorem min_fac_eq_two_iff (n : \u2115) : min_fac n = bit0 1 \u2194 bit0 1 \u2223 n := sorry\n\ntheorem exists_dvd_of_not_prime {n : \u2115} (n2 : bit0 1 \u2264 n) (np : \u00acprime n) :\n    \u2203 (m : \u2115), m \u2223 n \u2227 m \u2260 1 \u2227 m \u2260 n :=\n  sorry\n\ntheorem exists_dvd_of_not_prime2 {n : \u2115} (n2 : bit0 1 \u2264 n) (np : \u00acprime n) :\n    \u2203 (m : \u2115), m \u2223 n \u2227 bit0 1 \u2264 m \u2227 m < n :=\n  Exists.intro (min_fac n)\n    { left := min_fac_dvd n,\n      right :=\n        { left := prime.two_le (min_fac_prime (ne_of_gt n2)),\n          right := iff.mp (not_prime_iff_min_fac_lt n2) np } }\n\ntheorem exists_prime_and_dvd {n : \u2115} (n2 : bit0 1 \u2264 n) : \u2203 (p : \u2115), prime p \u2227 p \u2223 n :=\n  Exists.intro (min_fac n) { left := min_fac_prime (ne_of_gt n2), right := min_fac_dvd n }\n\n/-- Euclid's theorem. There exist infinitely many prime numbers.\nHere given in the form: for every `n`, there exists a prime number `p \u2265 n`. -/\ntheorem exists_infinite_primes (n : \u2115) : \u2203 (p : \u2115), n \u2264 p \u2227 prime p := sorry\n\ntheorem prime.eq_two_or_odd {p : \u2115} (hp : prime p) : p = bit0 1 \u2228 p % bit0 1 = 1 := sorry\n\ntheorem coprime_of_dvd {m : \u2115} {n : \u2115} (H : \u2200 (k : \u2115), prime k \u2192 k \u2223 m \u2192 \u00ack \u2223 n) : coprime m n :=\n  sorry\n\ntheorem coprime_of_dvd' {m : \u2115} {n : \u2115} (H : \u2200 (k : \u2115), prime k \u2192 k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 1) :\n    coprime m n :=\n  coprime_of_dvd\n    fun (k : \u2115) (kp : prime k) (km : k \u2223 m) (kn : k \u2223 n) =>\n      not_le_of_gt (prime.one_lt kp) (le_of_dvd zero_lt_one (H k kp km kn))\n\ntheorem factors_lemma {k : \u2115} : (k + bit0 1) / min_fac (k + bit0 1) < k + bit0 1 :=\n  div_lt_self (of_as_true trivial) (prime.one_lt (min_fac_prime (of_as_true trivial)))\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : \u2115 \u2192 List \u2115 := sorry\n\ntheorem mem_factors {n : \u2115} {p : \u2115} : p \u2208 factors n \u2192 prime p := sorry\n\ntheorem prod_factors {n : \u2115} : 0 < n \u2192 list.prod (factors n) = n := sorry\n\ntheorem factors_prime {p : \u2115} (hp : prime p) : factors p = [p] := sorry\n\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\ntheorem factors_add_two (n : \u2115) :\n    factors (n + bit0 1) = min_fac (n + bit0 1) :: factors ((n + bit0 1) / min_fac (n + bit0 1)) :=\n  rfl\n\ntheorem prime.coprime_iff_not_dvd {p : \u2115} {n : \u2115} (pp : prime p) : coprime p n \u2194 \u00acp \u2223 n := sorry\n\ntheorem prime.dvd_iff_not_coprime {p : \u2115} {n : \u2115} (pp : prime p) : p \u2223 n \u2194 \u00accoprime p n :=\n  iff.mpr iff_not_comm (prime.coprime_iff_not_dvd pp)\n\ntheorem prime.not_coprime_iff_dvd {m : \u2115} {n : \u2115} :\n    \u00accoprime m n \u2194 \u2203 (p : \u2115), prime p \u2227 p \u2223 m \u2227 p \u2223 n :=\n  sorry\n\ntheorem prime.dvd_mul {p : \u2115} {m : \u2115} {n : \u2115} (pp : prime p) : p \u2223 m * n \u2194 p \u2223 m \u2228 p \u2223 n := sorry\n\ntheorem prime.not_dvd_mul {p : \u2115} {m : \u2115} {n : \u2115} (pp : prime p) (Hm : \u00acp \u2223 m) (Hn : \u00acp \u2223 n) :\n    \u00acp \u2223 m * n :=\n  sorry\n\ntheorem prime.dvd_of_dvd_pow {p : \u2115} {m : \u2115} {n : \u2115} (pp : prime p) (h : p \u2223 m ^ n) : p \u2223 m :=\n  Nat.rec (fun (h : p \u2223 m ^ 0) => not.elim (prime.not_dvd_one pp) h)\n    (fun (n : \u2115) (IH : p \u2223 m ^ n \u2192 p \u2223 m) (h : p \u2223 m ^ Nat.succ n) =>\n      or.elim (iff.mp (prime.dvd_mul pp) h) id IH)\n    n h\n\ntheorem prime.pow_not_prime {x : \u2115} {n : \u2115} (hn : bit0 1 \u2264 n) : \u00acprime (x ^ n) := sorry\n\ntheorem prime.mul_eq_prime_pow_two_iff {x : \u2115} {y : \u2115} {p : \u2115} (hp : prime p) (hx : x \u2260 1)\n    (hy : y \u2260 1) : x * y = p ^ bit0 1 \u2194 x = p \u2227 y = p :=\n  sorry\n\ntheorem prime.dvd_factorial {n : \u2115} {p : \u2115} (hp : prime p) : p \u2223 factorial n \u2194 p \u2264 n := sorry\n\ntheorem prime.coprime_pow_of_not_dvd {p : \u2115} {m : \u2115} {a : \u2115} (pp : prime p) (h : \u00acp \u2223 a) :\n    coprime a (p ^ m) :=\n  coprime.pow_right m (coprime.symm (iff.mpr (prime.coprime_iff_not_dvd pp) h))\n\ntheorem coprime_primes {p : \u2115} {q : \u2115} (pp : prime p) (pq : prime q) : coprime p q \u2194 p \u2260 q :=\n  iff.trans (prime.coprime_iff_not_dvd pp) (not_congr (dvd_prime_two_le pq (prime.two_le pp)))\n\ntheorem coprime_pow_primes {p : \u2115} {q : \u2115} (n : \u2115) (m : \u2115) (pp : prime p) (pq : prime q)\n    (h : p \u2260 q) : coprime (p ^ n) (q ^ m) :=\n  coprime.pow n m (iff.mpr (coprime_primes pp pq) h)\n\ntheorem coprime_or_dvd_of_prime {p : \u2115} (pp : prime p) (i : \u2115) : coprime p i \u2228 p \u2223 i :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (coprime p i \u2228 p \u2223 i)) (propext (prime.dvd_iff_not_coprime pp))))\n    (em (coprime p i))\n\ntheorem dvd_prime_pow {p : \u2115} (pp : prime p) {m : \u2115} {i : \u2115} :\n    i \u2223 p ^ m \u2194 \u2203 (k : \u2115), \u2203 (H : k \u2264 m), i = p ^ k :=\n  sorry\n\n/--\nIf `p` is prime,\nand `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`\nthen `a = p^(k+1)`.\n-/\ntheorem eq_prime_pow_of_dvd_least_prime_pow {a : \u2115} {p : \u2115} {k : \u2115} (pp : prime p) (h\u2081 : \u00aca \u2223 p ^ k)\n    (h\u2082 : a \u2223 p ^ (k + 1)) : a = p ^ (k + 1) :=\n  sorry\n\ntheorem mem_list_primes_of_dvd_prod {p : \u2115} (hp : prime p) {l : List \u2115} :\n    (\u2200 (p : \u2115), p \u2208 l \u2192 prime p) \u2192 p \u2223 list.prod l \u2192 p \u2208 l :=\n  sorry\n\ntheorem mem_factors_iff_dvd {n : \u2115} {p : \u2115} (hn : 0 < n) (hp : prime p) : p \u2208 factors n \u2194 p \u2223 n :=\n  { mp := fun (h : p \u2208 factors n) => prod_factors hn \u25b8 list.dvd_prod h,\n    mpr :=\n      fun (h : p \u2223 n) =>\n        mem_list_primes_of_dvd_prod hp mem_factors (Eq.symm (prod_factors hn) \u25b8 h) }\n\ntheorem perm_of_prod_eq_prod {l\u2081 : List \u2115} {l\u2082 : List \u2115} :\n    list.prod l\u2081 = list.prod l\u2082 \u2192\n        (\u2200 (p : \u2115), p \u2208 l\u2081 \u2192 prime p) \u2192 (\u2200 (p : \u2115), p \u2208 l\u2082 \u2192 prime p) \u2192 l\u2081 ~ l\u2082 :=\n  sorry\n\ntheorem factors_unique {n : \u2115} {l : List \u2115} (h\u2081 : list.prod l = n)\n    (h\u2082 : \u2200 (p : \u2115), p \u2208 l \u2192 prime p) : l ~ factors n :=\n  sorry\n\ntheorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : \u2115} (p_prime : prime p) {m : \u2115} {n : \u2115} {k : \u2115}\n    {l : \u2115} (hpm : p ^ k \u2223 m) (hpn : p ^ l \u2223 n) (hpmn : p ^ (k + l + 1) \u2223 m * n) :\n    p ^ (k + 1) \u2223 m \u2228 p ^ (l + 1) \u2223 n :=\n  sorry\n\n/-- The type of prime numbers -/\ndef primes := Subtype fun (p : \u2115) => prime p\n\nnamespace primes\n\n\nprotected instance has_repr : has_repr primes :=\n  has_repr.mk fun (p : primes) => repr (subtype.val p)\n\nprotected instance inhabited : Inhabited primes :=\n  { default := { val := bit0 1, property := prime_two } }\n\nprotected instance coe_nat : has_coe primes \u2115 := has_coe.mk subtype.val\n\ntheorem coe_nat_inj (p : primes) (q : primes) : \u2191p = \u2191q \u2192 p = q := fun (h : \u2191p = \u2191q) => subtype.eq h\n\nend primes\n\n\nprotected instance monoid.prime_pow {\u03b1 : Type u_1} [monoid \u03b1] : has_pow \u03b1 primes :=\n  has_pow.mk fun (x : \u03b1) (p : primes) => x ^ subtype.val p\n\nend nat\n\n\n/-! ### Primality prover -/\n\nnamespace tactic\n\n\nnamespace norm_num\n\n\ntheorem is_prime_helper (n : \u2115) (h\u2081 : 1 < n) (h\u2082 : nat.min_fac n = n) : nat.prime n :=\n  iff.mpr nat.prime_def_min_fac { left := h\u2081, right := h\u2082 }\n\ntheorem min_fac_bit0 (n : \u2115) : nat.min_fac (bit0 n) = bit0 1 := sorry\n\n/-- A predicate representing partial progress in a proof of `min_fac`. -/\ndef min_fac_helper (n : \u2115) (k : \u2115) := 0 < k \u2227 bit1 k \u2264 nat.min_fac (bit1 n)\n\ntheorem min_fac_helper.n_pos {n : \u2115} {k : \u2115} (h : min_fac_helper n k) : 0 < n := sorry\n\ntheorem min_fac_ne_bit0 {n : \u2115} {k : \u2115} : nat.min_fac (bit1 n) \u2260 bit0 k := sorry\n\ntheorem min_fac_helper_0 (n : \u2115) (h : 0 < n) : min_fac_helper n 1 := sorry\n\ntheorem min_fac_helper_1 {n : \u2115} {k : \u2115} {k' : \u2115} (e : k + 1 = k')\n    (np : nat.min_fac (bit1 n) \u2260 bit1 k) (h : min_fac_helper n k) : min_fac_helper n k' :=\n  sorry\n\ntheorem min_fac_helper_2 (n : \u2115) (k : \u2115) (k' : \u2115) (e : k + 1 = k') (np : \u00acnat.prime (bit1 k))\n    (h : min_fac_helper n k) : min_fac_helper n k' :=\n  sorry\n\ntheorem min_fac_helper_3 (n : \u2115) (k : \u2115) (k' : \u2115) (c : \u2115) (e : k + 1 = k')\n    (nc : bit1 n % bit1 k = c) (c0 : 0 < c) (h : min_fac_helper n k) : min_fac_helper n k' :=\n  sorry\n\ntheorem min_fac_helper_4 (n : \u2115) (k : \u2115) (hd : bit1 n % bit1 k = 0) (h : min_fac_helper n k) :\n    nat.min_fac (bit1 n) = bit1 k :=\n  sorry\n\ntheorem min_fac_helper_5 (n : \u2115) (k : \u2115) (k' : \u2115) (e : bit1 k * bit1 k = k') (hd : bit1 n < k')\n    (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/nat/prime_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7049153055924022}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n\n! This file was ported from Lean 3 source module data.polynomial.integral_normalization\n! leanprover-community/mathlib commit 6f401acf4faec3ab9ab13a42789c4f68064a61cd\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Polynomial.AlgebraMap\nimport Mathlib.Data.Polynomial.Degree.Lemmas\nimport Mathlib.Data.Polynomial.Monic\n\n/-!\n# Theory of monic polynomials\n\nWe define `integralNormalization`, which relate arbitrary polynomials to monic ones.\n-/\n\n\nopen BigOperators Polynomial\n\nnamespace Polynomial\n\nuniverse u v y\n\nvariable {R : Type u} {S : Type v} {a b : R} {m n : \u2115} {\u03b9 : Type y}\n\nsection IntegralNormalization\n\nsection Semiring\n\nvariable [Semiring R]\n\n/-- If `f : R[X]` is a nonzero polynomial with root `z`, `integralNormalization f` is\na monic polynomial with root `leadingCoeff f * z`.\n\nMoreover, `integralNormalization 0 = 0`.\n-/\nnoncomputable def integralNormalization (f : R[X]) : R[X] :=\n  \u2211 i in f.support,\n    monomial i (if f.degree = i then 1 else coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i))\n#align polynomial.integral_normalization Polynomial.integralNormalization\n\n@[simp]\ntheorem integralNormalization_zero : integralNormalization (0 : R[X]) = 0 := by\n  simp [integralNormalization]\n#align polynomial.integral_normalization_zero Polynomial.integralNormalization_zero\n\ntheorem integralNormalization_coeff {f : R[X]} {i : \u2115} :\n    (integralNormalization f).coeff i =\n      if f.degree = i then 1 else coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i) := by\n  have : f.coeff i = 0 \u2192 f.degree \u2260 i := fun hc hd => coeff_ne_zero_of_eq_degree hd hc\n  simp (config := { contextual := true }) [integralNormalization, coeff_monomial, this,\n    mem_support_iff]\n#align polynomial.integral_normalization_coeff Polynomial.integralNormalization_coeff\n\ntheorem integralNormalization_support {f : R[X]} : (integralNormalization f).support \u2286 f.support :=\n  by\n  intro\n  simp (config := { contextual := true }) [integralNormalization, coeff_monomial, mem_support_iff]\n#align polynomial.integral_normalization_support Polynomial.integralNormalization_support\n\ntheorem integralNormalization_coeff_degree {f : R[X]} {i : \u2115} (hi : f.degree = i) :\n    (integralNormalization f).coeff i = 1 := by rw [integralNormalization_coeff, if_pos hi]\n#align polynomial.integral_normalization_coeff_degree Polynomial.integralNormalization_coeff_degree\n\ntheorem integralNormalization_coeff_natDegree {f : R[X]} (hf : f \u2260 0) :\n    (integralNormalization f).coeff (natDegree f) = 1 :=\n  integralNormalization_coeff_degree (degree_eq_natDegree hf)\n#align polynomial.integral_normalization_coeff_nat_degree Polynomial.integralNormalization_coeff_natDegree\n\ntheorem integralNormalization_coeff_ne_degree {f : R[X]} {i : \u2115} (hi : f.degree \u2260 i) :\n    coeff (integralNormalization f) i = coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i) := by\n  rw [integralNormalization_coeff, if_neg hi]\n#align polynomial.integral_normalization_coeff_ne_degree Polynomial.integralNormalization_coeff_ne_degree\n\ntheorem integralNormalization_coeff_ne_natDegree {f : R[X]} {i : \u2115} (hi : i \u2260 natDegree f) :\n    coeff (integralNormalization f) i = coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i) :=\n  integralNormalization_coeff_ne_degree (degree_ne_of_natDegree_ne hi.symm)\n#align polynomial.integral_normalization_coeff_ne_nat_degree Polynomial.integralNormalization_coeff_ne_natDegree\n\ntheorem monic_integralNormalization {f : R[X]} (hf : f \u2260 0) : Monic (integralNormalization f) :=\n  monic_of_degree_le f.natDegree\n    (Finset.sup_le fun i h =>\n      WithBot.coe_le_coe.2 <| le_natDegree_of_mem_supp i <| integralNormalization_support h)\n    (integralNormalization_coeff_natDegree hf)\n#align polynomial.monic_integral_normalization Polynomial.monic_integralNormalization\n\nend Semiring\n\nsection IsDomain\n\nvariable [Ring R] [IsDomain R]\n\n@[simp]\ntheorem support_integralNormalization {f : R[X]} : (integralNormalization f).support = f.support :=\n  by\n  by_cases hf : f = 0; \u00b7 simp [hf]\n  ext i\n  refine' \u27e8fun h => integralNormalization_support h, _\u27e9\n  simp only [integralNormalization_coeff, mem_support_iff]\n  intro hfi\n  split_ifs with hi <;> simp [hfi, hi, pow_ne_zero _ (leadingCoeff_ne_zero.mpr hf)]\n#align polynomial.support_integral_normalization Polynomial.support_integralNormalization\n\nend IsDomain\n\nsection IsDomain\n\nvariable [CommRing R] [IsDomain R]\n\nvariable [CommSemiring S]\n\ntheorem integralNormalization_eval\u2082_eq_zero {p : R[X]} (f : R \u2192+* S) {z : S} (hz : eval\u2082 f z p = 0)\n    (inj : \u2200 x : R, f x = 0 \u2192 x = 0) :\n    eval\u2082 f (z * f p.leadingCoeff) (integralNormalization p) = 0 :=\n  calc\n    eval\u2082 f (z * f p.leadingCoeff) (integralNormalization p) =\n        p.support.attach.sum fun i =>\n          f (coeff (integralNormalization p) i.1 * p.leadingCoeff ^ i.1) * z ^ i.1 := by\n      rw [eval\u2082_eq_sum, sum_def, support_integralNormalization]\n      simp only [mul_comm z, mul_pow, mul_assoc, RingHom.map_pow, RingHom.map_mul]\n      exact Finset.sum_attach.symm\n    _ =\n        p.support.attach.sum fun i =>\n          f (coeff p i.1 * p.leadingCoeff ^ (natDegree p - 1)) * z ^ i.1 := by\n      by_cases hp : p = 0; \u00b7 simp [hp]\n      have one_le_deg : 1 \u2264 natDegree p :=\n        Nat.succ_le_of_lt (natDegree_pos_of_eval\u2082_root hp f hz inj)\n      congr with i\n      congr 2\n      by_cases hi : i.1 = natDegree p\n      \u00b7 rw [hi, integralNormalization_coeff_degree, one_mul, leadingCoeff, \u2190 pow_succ,\n          tsub_add_cancel_of_le one_le_deg]\n        exact degree_eq_natDegree hp\n      \u00b7 have : i.1 \u2264 p.natDegree - 1 :=\n          Nat.le_pred_of_lt (lt_of_le_of_ne (le_natDegree_of_ne_zero (mem_support_iff.mp i.2)) hi)\n        rw [integralNormalization_coeff_ne_natDegree hi, mul_assoc, \u2190 pow_add,\n          tsub_add_cancel_of_le this]\n    _ = f p.leadingCoeff ^ (natDegree p - 1) * eval\u2082 f z p := by\n      simp_rw [eval\u2082_eq_sum, sum_def, fun i => mul_comm (coeff p i), RingHom.map_mul,\n               RingHom.map_pow, mul_assoc, \u2190 Finset.mul_sum]\n      congr 1\n      exact @Finset.sum_attach _ _ p.support _ fun i => f (p.coeff i) * z ^ i\n    _ = 0 := by rw [hz, mul_zero]\n#align polynomial.integral_normalization_eval\u2082_eq_zero Polynomial.integralNormalization_eval\u2082_eq_zero\n\ntheorem integralNormalization_aeval_eq_zero [Algebra R S] {f : R[X]} {z : S} (hz : aeval z f = 0)\n    (inj : \u2200 x : R, algebraMap R S x = 0 \u2192 x = 0) :\n    aeval (z * algebraMap R S f.leadingCoeff) (integralNormalization f) = 0 :=\n  integralNormalization_eval\u2082_eq_zero (algebraMap R S) hz inj\n#align polynomial.integral_normalization_aeval_eq_zero Polynomial.integralNormalization_aeval_eq_zero\n\nend IsDomain\n\nend IntegralNormalization\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Polynomial/IntegralNormalization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7049153049267343}}
{"text": "section Chap4_1\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := \n  \u27e8\u03bb hpq => \u27e8\u03bb w => (hpq w).left, \u03bb w => (hpq w).right\u27e9, \n   \u03bb hphq => \u03bb w => \u27e8hphq.left w, hphq.right w\u27e9\u27e9\n\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := \u03bb hpq => \u03bb hp => \u03bb w => (hpq w) (hp w)\n\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := \n  fun h => Or.elim h\n    (\u03bb hpx => \u03bb w => Or.inl (hpx w))\n    (\u03bb hqx => \u03bb w => Or.inr (hqx w))\nend Chap4_1\n\nsection Chap4_2\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable (r : Prop)\n\nexample : \u03b1 -> ((\u2203 _ : \u03b1, r) \u2194 r) := \n  \u03bb w => Iff.intro\n    (\u03bb \u27e8_, hr\u27e9 => hr)\n    (\u03bb hr => \u27e8w, hr\u27e9)\n    \nopen Classical \nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r := \n  Iff.intro \n    (\u03bb hpxor => byCases\n      (\u03bb h' : \u2200 x, p x => Or.inl h') \n      (\u03bb h' : \u00ac \u2200 x, p x => \n        have \u27e8w, hnpw\u27e9 : \u2203 x, \u00ac p x := byContradiction \n          \u03bb hnpx =>\n            have : \u2200 x, p x := \u03bb w => byContradiction \u03bb hnpw => hnpx \u27e8w, hnpw\u27e9\n            h' this\n        have hr : r := byContradiction \u03bb hnr => \n          have : p w := False.elim ((hpxor w).elim hnpw hnr)\n          hnpw this\n        Or.inr hr))\n    (\u03bb hpxor => \u03bb w => \n      hpxor.elim \n        (\u03bb hpx => Or.inl (hpx w)) \n        (\u03bb hr => Or.inr hr))\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\n  Iff.intro\n    (\u03bb hxrpx => \u03bb hr => \u03bb w => hxrpx w hr)\n    (\u03bb hrxpx => \u03bb w => \u03bb hr => hrxpx hr w)\nend Chap4_2\n\nsection Chap4_3\nvariable (men : Type) (barber : men)\nvariable (shaves : men \u2192 men \u2192 Prop)\n\n-- Who would shave the barber?\n-- Why \u2194 instead of \u2227?\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : False :=\n  have : \u00ac ((shaves barber barber) \u2194 \u00ac shaves barber barber) := \n    \u03bb h => \n      have hn : \u00ac shaves barber barber := \u03bb h' => h.mp h' h'\n      have hnn : \u00ac \u00ac shaves barber barber := \u03bb h' => h' (h.mpr h')\n      hnn hn\n  this (h barber)\nend Chap4_3\n\nsection Chap4_4\ndef even (n : Nat) : Prop := \u2203 x : Nat, 2 * x = n\ndef prime (n : Nat) : Prop := \u00ac \u2203 x y : Nat, 1 < x \u2227 x < n \u2227 1 < y \u2227 y < n \u2227 x * y = n\ndef infinitely_many_primes : Prop := \u2200 k : Nat, \u2203 p : Nat, prime p \u2227 p > k\ndef Fermat_prime (n : Nat) : Prop := \u2203 k : Nat, 2^(2^k) + 1 = n\ndef infinitely_many_Fermat_primes : Prop := \u2200 k : Nat, \u2203 p, Fermat_prime p \u2227 p > k\ndef goldbach_conjecture : Prop := \u2200 x : Nat, x > 2 \u2227 even x -> (\u2203 p q, prime p \u2227 prime q \u2227 x = p + q)\ndef Goldbach's_weak_conjecture : Prop := \u2200 x : Nat, x > 5 \u2227 \u00ac even x -> (\u2203 p q r, prime p \u2227 prime q \u2227 prime r \u2227 x = p + q + r)\ndef Fermat's_last_theorem : Prop := \u2200 n : Nat, n > 2 -> \u00ac (\u2203 a b c, a > 0 \u2227 b > 0 \u2227 c > 0 \u2227 a^n + b^n = c^n)\n\nend Chap4_4\n\nsection Chap4_5\nopen Classical\nvariable (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable (r : Prop)\n\nexample : (\u2203 _ : \u03b1, r) \u2192 r := \n  \u03bb h => h.elim (\u03bb _ hr => hr)\n  \nexample (a : \u03b1) : r \u2192 (\u2203 _ : \u03b1, r) :=\n  \u03bb h1 => \u27e8a, h1\u27e9\n  \nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := \n  \u27e8\u03bb \u27e8w, pw, hr\u27e9 => \u27e8\u27e8w, pw\u27e9, hr\u27e9,\n   \u03bb \u27e8\u27e8w, pw\u27e9, hr\u27e9 => \u27e8w, pw, hr\u27e9\u27e9\n   \nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := \n  \u27e8\u03bb \u27e8w, hpqx\u27e9 => hpqx.elim (\u03bb hpx => Or.inl \u27e8w, hpx\u27e9) (\u03bb hqx => Or.inr \u27e8w, hqx\u27e9), \n   \u03bb hpq => hpq.elim (\u03bb \u27e8w, hpw\u27e9 => \u27e8w, Or.inl hpw\u27e9) (\u03bb \u27e8w, hqw\u27e9 => \u27e8w, Or.inr hqw\u27e9)\u27e9\n   \nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := \n  \u27e8\u03bb h => \u03bb \u27e8w, hnpx\u27e9 => hnpx (h w), \n   \u03bb h => \u03bb w => byContradiction \u03bb hnpw => h \u27e8w, hnpw\u27e9\u27e9\n   \nexample : (\u2203 x, p x ) \u2194 \u00ac (\u2200 x, \u00ac p x) := \n  \u27e8\u03bb \u27e8w, hpw\u27e9 => \u03bb hnp => (hnp w) hpw, \n   \u03bb h => byContradiction \u03bb (h1 : \u00ac \u2203 x, p x) =>\n     have (h2 : \u2200 x, \u00ac p x) := \n       \u03bb w =>\n       \u03bb h3 : p w => h1 \u27e8w, h3\u27e9\n     h h2\u27e9\n     \nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) :=\n  \u27e8\u03bb h => byContradiction \u03bb h1 =>\n       have h2 : (\u2200 x, \u00ac p x) :=\n         \u03bb w => \u03bb (h3 : p w) => h \u27e8w, h3\u27e9\n       h1 h2, \n   \u03bb h => \u03bb \u27e8w, h1\u27e9 => (h w) h1\u27e9\n\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) :=\n  \u27e8\u03bb h => byContradiction \u03bb h1 => \n     have h2 : \u2200 x, p x := \u03bb w => byContradiction \u03bb hnpw => h1 \u27e8w, hnpw\u27e9\n     h h2, \n   \u03bb \u27e8w, hnpw\u27e9 => \u03bb h1 => hnpw (h1 w)\u27e9\n   \nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r :=\n  \u27e8\u03bb h => \u03bb \u27e8w, hpw\u27e9 => (h w) hpw, \n   \u03bb h => \u03bb w => \u03bb hpw => h \u27e8w, hpw\u27e9\u27e9\n   \nexample (a : \u03b1) : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := \n  \u27e8\u03bb \u27e8w, hpwr\u27e9 => \u03bb hpx => hpwr (hpx w), \n   \u03bb h => byCases\n     (\u03bb h': \u2200 x, p x => \u27e8a, \u03bb _ => h h'\u27e9)\n     (\u03bb h': \u00ac \u2200 x, p x => \n       have \u27e8w, hnpw\u27e9 : \u2203 x, \u00ac p x := byContradiction \u03bb hnnpx => \n         have nh' : \u2200 x, p x := \u03bb w => byContradiction \u03bb hnpw => hnnpx \u27e8w, hnpw\u27e9\n         h' nh'\n       \u27e8w, \u03bb hpw => absurd hpw hnpw\u27e9)\u27e9\n       \nexample (a : \u03b1) : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) :=\n  \u27e8\u03bb \u27e8w, hrpw\u27e9 => \u03bb hr => \u27e8w, hrpw hr\u27e9, \n   \u03bb hrpx => byCases \n     (\u03bb h' : \u2203 x, p x => \n       have \u27e8w, pw\u27e9 := h'\n       \u27e8w, \u03bb _ => pw\u27e9)\n     (\u03bb h' : \u00ac \u2203 x, p x => byCases\n       (\u03bb hr : r  => absurd (hrpx hr) h')\n       (\u03bb hnr : \u00acr  => \u27e8a, \u03bb hr => absurd hr hnr\u27e9))\u27e9\n       \nend Chap4_5\n", "meta": {"author": "zhangjunphy", "repo": "lean-demo", "sha": "8f7afca56d7e4c538a32927cd5d7817ff63071a1", "save_path": "github-repos/lean/zhangjunphy-lean-demo", "path": "github-repos/lean/zhangjunphy-lean-demo/lean-demo-8f7afca56d7e4c538a32927cd5d7817ff63071a1/Exercises/Chap4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7048798909503945}}
{"text": "/-\nCopyright (c) 2020 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.ring_theory.polynomial.chebyshev.defs\nimport Mathlib.analysis.special_functions.trigonometric\nimport Mathlib.ring_theory.localization\nimport Mathlib.data.zmod.basic\nimport Mathlib.algebra.invertible\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Chebyshev polynomials\n\nThe Chebyshev polynomials are two families of polynomials indexed by `\u2115`,\nwith integral coefficients.\nIn this file, we only consider Chebyshev polynomials of the first kind.\n\n## Main declarations\n\n* `polynomial.chebyshev\u2081_mul`, the `(m * n)`-th Chebyshev polynomial is the composition\n  of the `m`-th and `n`-th Chebyshev polynomials.\n* `polynomial.lambdashev_mul`, the `(m * n)`-th lambdashev polynomial is the composition\n  of the `m`-th and `n`-th lambdashev polynomials.\n* `polynomial.lambdashev_char_p`, for a prime number `p`, the `p`-th lambdashev polynomial\n  is congruent to `X ^ p` modulo `p`.\n\n## Implementation details\n\nSince Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`,\nwe define them to have coefficients in an arbitrary commutative ring, even though\ntechnically `\u2124` would suffice.\nThe benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean,\nand do not have `map (int.cast_ring_hom R)` interfering all the time.\n\n\n-/\n\nnamespace polynomial\n\n\n/-- The `(m * n)`-th Chebyshev polynomial is the composition of the `m`-th and `n`-th -/\ntheorem chebyshev\u2081_mul (R : Type u_1) [comm_ring R] (m : \u2115) (n : \u2115) : chebyshev\u2081 R (m * n) = comp (chebyshev\u2081 R m) (chebyshev\u2081 R n) := sorry\n\n/-!\n\n### A Lambda structure on `polynomial \u2124`\n\nMathlib doesn't currently know what a Lambda ring is.\nBut once it does, we can endow `polynomial \u2124` with a Lambda structure\nin terms of the `lambdashev` polynomials defined below.\nThere is exactly one other Lambda structure on `polynomial \u2124` in terms of binomial polynomials.\n\n-/\n\ntheorem lambdashev_eval_add_inv {R : Type u_1} [comm_ring R] (x : R) (y : R) (h : x * y = 1) (n : \u2115) : eval (x + y) (lambdashev R n) = x ^ n + y ^ n := sorry\n\ntheorem lambdashev_eq_chebyshev\u2081 (R : Type u_1) [comm_ring R] [invertible (bit0 1)] (n : \u2115) : lambdashev R n = bit0 1 * comp (chebyshev\u2081 R n) (coe_fn C \u215f * X) := sorry\n\ntheorem chebyshev\u2081_eq_lambdashev (R : Type u_1) [comm_ring R] [invertible (bit0 1)] (n : \u2115) : chebyshev\u2081 R n = coe_fn C \u215f * comp (lambdashev R n) (bit0 1 * X) := sorry\n\n/-- the `(m * n)`-th lambdashev polynomial is the composition of the `m`-th and `n`-th -/\ntheorem lambdashev_mul (R : Type u_1) [comm_ring R] (m : \u2115) (n : \u2115) : lambdashev R (m * n) = comp (lambdashev R m) (lambdashev R n) := sorry\n\ntheorem lambdashev_comp_comm (R : Type u_1) [comm_ring R] (m : \u2115) (n : \u2115) : comp (lambdashev R m) (lambdashev R n) = comp (lambdashev R n) (lambdashev R m) := sorry\n\ntheorem lambdashev_zmod_p (p : \u2115) [fact (nat.prime p)] : lambdashev (zmod p) p = X ^ p := sorry\n\ntheorem lambdashev_char_p (R : Type u_1) [comm_ring R] (p : \u2115) [fact (nat.prime p)] [char_p R p] : lambdashev R p = X ^ p := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/ring_theory/polynomial/chebyshev/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.704879886276694}}
{"text": "/-\nCopyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.order.basic\n! leanprover-community/mathlib commit 26f081a2fb920140ed5bc5cc5344e84bcc7cb2b2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Order.Ring.Canonical\nimport Mathlib.Data.Nat.Basic\nimport Mathlib.Data.Nat.Bits\n\n\n/-!\n# The natural numbers as a linearly ordered commutative semiring\n\nWe also have a variety of lemmas which have been deferred from `Data.Nat.Basic` because it is\neasier to prove them with this ordered semiring instance available.\n\nYou may find that some theorems can be moved back to `Data.Nat.Basic` by modifying their proofs.\n-/\n\n\nuniverse u v\n\nnamespace Nat\n\n/-! ### instances -/\n\ninstance orderBot : OrderBot \u2115 where\n  bot := 0\n  bot_le := Nat.zero_le\n#align nat.order_bot Nat.orderBot\n\ninstance linearOrderedCommSemiring : LinearOrderedCommSemiring \u2115 :=\n  { Nat.commSemiring, Nat.linearOrder with\n    lt := Nat.lt, add_le_add_left := @Nat.add_le_add_left,\n    le_of_add_le_add_left := @Nat.le_of_add_le_add_left,\n    zero_le_one := Nat.le_of_lt (Nat.zero_lt_succ 0),\n    mul_lt_mul_of_pos_left := @Nat.mul_lt_mul_of_pos_left,\n    mul_lt_mul_of_pos_right := @Nat.mul_lt_mul_of_pos_right,\n    exists_pair_ne := \u27e80, 1, ne_of_lt Nat.zero_lt_one\u27e9 }\n\ninstance linearOrderedCommMonoidWithZero : LinearOrderedCommMonoidWithZero \u2115 :=\n  { Nat.linearOrderedCommSemiring, (inferInstance : CommMonoidWithZero \u2115) with\n    mul_le_mul_left := fun _ _ h c => Nat.mul_le_mul_left c h }\n\n/-! Extra instances to short-circuit type class resolution and ensure computability -/\n\n\n-- Not using `infer_instance` avoids `classical.choice` in the following two\ninstance linearOrderedSemiring : LinearOrderedSemiring \u2115 :=\n  inferInstance\n\ninstance strictOrderedSemiring : StrictOrderedSemiring \u2115 :=\n  inferInstance\n\ninstance strictOrderedCommSemiring : StrictOrderedCommSemiring \u2115 :=\n  inferInstance\n\ninstance orderedSemiring : OrderedSemiring \u2115 :=\n  StrictOrderedSemiring.toOrderedSemiring'\n\ninstance orderedCommSemiring : OrderedCommSemiring \u2115 :=\n  StrictOrderedCommSemiring.toOrderedCommSemiring'\n\ninstance linearOrderedCancelAddCommMonoid : LinearOrderedCancelAddCommMonoid \u2115 :=\n  inferInstance\n\ninstance canonicallyOrderedCommSemiring : CanonicallyOrderedCommSemiring \u2115 :=\n  { Nat.nontrivial, Nat.orderBot, (inferInstance : OrderedAddCommMonoid \u2115),\n    (inferInstance : LinearOrderedSemiring \u2115), (inferInstance : CommSemiring \u2115) with\n    exists_add_of_le := fun {_ _} h => (Nat.le.dest h).imp fun _ => Eq.symm,\n    le_self_add := Nat.le_add_right,\n    eq_zero_or_eq_zero_of_mul_eq_zero := Nat.eq_zero_of_mul_eq_zero }\n\ninstance canonicallyLinearOrderedAddMonoid : CanonicallyLinearOrderedAddMonoid \u2115 :=\n  { (inferInstance : CanonicallyOrderedAddMonoid \u2115), Nat.linearOrder with }\n\nvariable {m n k l : \u2115}\n\n/-! ### Equalities and inequalities involving zero and one -/\n\ntheorem one_le_iff_ne_zero : 1 \u2264 n \u2194 n \u2260 0 :=\n  Nat.add_one_le_iff.trans pos_iff_ne_zero\n#align nat.one_le_iff_ne_zero Nat.one_le_iff_ne_zero\n\ntheorem one_lt_iff_ne_zero_and_ne_one : \u2200 {n : \u2115}, 1 < n \u2194 n \u2260 0 \u2227 n \u2260 1\n  | 0 => by decide\n  | 1 => by decide\n  | n + 2 => by simp\n#align nat.one_lt_iff_ne_zero_and_ne_one Nat.one_lt_iff_ne_zero_and_ne_one\n\n#align nat.mul_ne_zero Nat.mul_ne_zero\n\n-- Porting note: already in Std\n#align nat.mul_eq_zero Nat.mul_eq_zero\n\n--Porting note: removing `simp` attribute\nprotected theorem zero_eq_mul : 0 = m * n \u2194 m = 0 \u2228 n = 0 := by rw [eq_comm, Nat.mul_eq_zero]\n#align nat.zero_eq_mul Nat.zero_eq_mul\n\ntheorem eq_zero_of_double_le (h : 2 * n \u2264 n) : n = 0 :=\n  add_right_eq_self.mp <| le_antisymm ((two_mul n).symm.trans_le h) le_add_self\n#align nat.eq_zero_of_double_le Nat.eq_zero_of_double_le\n\ntheorem eq_zero_of_mul_le (hb : 2 \u2264 n) (h : n * m \u2264 m) : m = 0 :=\n  eq_zero_of_double_le <| le_trans (Nat.mul_le_mul_right _ hb) h\n#align nat.eq_zero_of_mul_le Nat.eq_zero_of_mul_le\n\ntheorem zero_max : max 0 n = n :=\n  max_eq_right (zero_le _)\n#align nat.zero_max Nat.zero_max\n\n@[simp]\ntheorem min_eq_zero_iff : min m n = 0 \u2194 m = 0 \u2228 n = 0 := by\n  constructor\n  \u00b7 intro h\n    cases' le_total m n with H H\n    \u00b7 simpa [H] using Or.inl h\n    \u00b7 simpa [H] using Or.inr h\n  \u00b7 rintro (rfl | rfl) <;> simp\n#align nat.min_eq_zero_iff Nat.min_eq_zero_iff\n\n@[simp]\ntheorem max_eq_zero_iff : max m n = 0 \u2194 m = 0 \u2227 n = 0 := by\n  constructor\n  \u00b7 intro h\n    cases' le_total m n with H H\n    \u00b7 simp only [H, max_eq_right] at h\n      exact \u27e8le_antisymm (H.trans h.le) (zero_le _), h\u27e9\n    \u00b7 simp only [H, max_eq_left] at h\n      exact \u27e8h, le_antisymm (H.trans h.le) (zero_le _)\u27e9\n  \u00b7 rintro \u27e8rfl, rfl\u27e9\n    simp\n#align nat.max_eq_zero_iff Nat.max_eq_zero_iff\n\ntheorem add_eq_max_iff : m + n = max m n \u2194 m = 0 \u2228 n = 0 := by\n  rw [\u2190 min_eq_zero_iff]\n  cases' le_total m n with H H <;> simp [H]\n#align nat.add_eq_max_iff Nat.add_eq_max_iff\n\ntheorem add_eq_min_iff : m + n = min m n \u2194 m = 0 \u2227 n = 0 := by\n  rw [\u2190 max_eq_zero_iff]\n  cases' le_total m n with H H <;> simp [H]\n#align nat.add_eq_min_iff Nat.add_eq_min_iff\n\ntheorem one_le_of_lt (h : n < m) : 1 \u2264 m :=\n  lt_of_le_of_lt (Nat.zero_le _) h\n#align nat.one_le_of_lt Nat.one_le_of_lt\n\ntheorem eq_one_of_mul_eq_one_right (H : m * n = 1) : m = 1 :=\n  eq_one_of_dvd_one \u27e8n, H.symm\u27e9\n#align nat.eq_one_of_mul_eq_one_right Nat.eq_one_of_mul_eq_one_right\n\ntheorem eq_one_of_mul_eq_one_left (H : m * n = 1) : n = 1 :=\n  eq_one_of_mul_eq_one_right (by rwa [mul_comm])\n#align nat.eq_one_of_mul_eq_one_left Nat.eq_one_of_mul_eq_one_left\n\n/-! ### `succ` -/\n\n\ntheorem two_le_iff : \u2200 n, 2 \u2264 n \u2194 n \u2260 0 \u2227 n \u2260 1\n  | 0 => by simp\n  | 1 => by simp\n  | n + 2 => by simp\n#align nat.two_le_iff Nat.two_le_iff\n\n@[simp]\ntheorem lt_one_iff {n : \u2115} : n < 1 \u2194 n = 0 :=\n  lt_succ_iff.trans nonpos_iff_eq_zero\n#align nat.lt_one_iff Nat.lt_one_iff\n\n/-! ### `add` -/\n\n\ntheorem add_pos_left {m : \u2115} (h : 0 < m) (n : \u2115) : 0 < m + n :=\n  calc\n    m + n > 0 + n := Nat.add_lt_add_right h n\n    _ = n := Nat.zero_add n\n    _ \u2265 0 := zero_le n\n\n#align nat.add_pos_left Nat.add_pos_left\n\ntheorem add_pos_right (m : \u2115) {n : \u2115} (h : 0 < n) : 0 < m + n := by\n  rw [add_comm]\n  exact add_pos_left h m\n#align nat.add_pos_right Nat.add_pos_right\n\ntheorem add_pos_iff_pos_or_pos (m n : \u2115) : 0 < m + n \u2194 0 < m \u2228 0 < n :=\n  Iff.intro\n    (by\n      intro h\n      cases' m with m\n      \u00b7 simp [zero_add] at h\n        exact Or.inr h\n      exact Or.inl (succ_pos _))\n    (by\n      intro h; cases' h with mpos npos\n      \u00b7 apply add_pos_left mpos\n      apply add_pos_right _ npos)\n#align nat.add_pos_iff_pos_or_pos Nat.add_pos_iff_pos_or_pos\n\ntheorem add_eq_one_iff : m + n = 1 \u2194 m = 0 \u2227 n = 1 \u2228 m = 1 \u2227 n = 0 := by\n  cases n <;> simp [succ_eq_add_one, \u2190 add_assoc, succ_inj']\n#align nat.add_eq_one_iff Nat.add_eq_one_iff\n\ntheorem add_eq_two_iff : m + n = 2 \u2194 m = 0 \u2227 n = 2 \u2228 m = 1 \u2227 n = 1 \u2228 m = 2 \u2227 n = 0 := by\n  cases n <;>\n  simp [(succ_ne_zero 1).symm, (show 2 = Nat.succ 1 from rfl),\n    succ_eq_add_one, \u2190 add_assoc, succ_inj', add_eq_one_iff]\n\n#align nat.add_eq_two_iff Nat.add_eq_two_iff\n\ntheorem add_eq_three_iff :\n    m + n = 3 \u2194 m = 0 \u2227 n = 3 \u2228 m = 1 \u2227 n = 2 \u2228 m = 2 \u2227 n = 1 \u2228 m = 3 \u2227 n = 0 := by\n  cases n <;>\n  simp [(succ_ne_zero 1).symm, succ_eq_add_one, (show 3 = Nat.succ 2 from rfl),\n    \u2190 add_assoc, succ_inj', add_eq_two_iff]\n#align nat.add_eq_three_iff Nat.add_eq_three_iff\n\ntheorem le_add_one_iff : m \u2264 n + 1 \u2194 m \u2264 n \u2228 m = n + 1 :=\n  \u27e8fun h =>\n    match Nat.eq_or_lt_of_le h with\n    | Or.inl h => Or.inr h\n    | Or.inr h => Or.inl <| Nat.le_of_succ_le_succ h,\n    Or.rec (fun h => le_trans h <| Nat.le_add_right _ _) le_of_eq\u27e9\n#align nat.le_add_one_iff Nat.le_add_one_iff\n\ntheorem le_and_le_add_one_iff : n \u2264 m \u2227 m \u2264 n + 1 \u2194 m = n \u2228 m = n + 1 := by\n  rw [le_add_one_iff, and_or_left, \u2190 le_antisymm_iff, eq_comm, and_iff_right_of_imp]\n  rintro rfl\n  exact n.le_succ\n#align nat.le_and_le_add_one_iff Nat.le_and_le_add_one_iff\n\ntheorem add_succ_lt_add (hab : m < n) (hcd : k < l) : m + k + 1 < n + l := by\n  rw [add_assoc]\n  exact add_lt_add_of_lt_of_le hab (Nat.succ_le_iff.2 hcd)\n#align nat.add_succ_lt_add Nat.add_succ_lt_add\n\n/-! ### `pred` -/\n\n\ntheorem pred_le_iff : pred m \u2264 n \u2194 m \u2264 succ n :=\n  \u27e8le_succ_of_pred_le, by\n    cases m\n    \u00b7 exact fun _ => zero_le n\n    exact le_of_succ_le_succ\u27e9\n#align nat.pred_le_iff Nat.pred_le_iff\n\n/-! ### `sub`\n\nMost lemmas come from the `OrderedSub` instance on `\u2115`. -/\n\n\ninstance : OrderedSub \u2115 := by\n  constructor\n  intro m n k\n  induction' n with n ih generalizing k\n  \u00b7 simp\n  \u00b7 simp only [sub_succ, pred_le_iff, ih, succ_add, add_succ]\n\ntheorem lt_pred_iff : n < pred m \u2194 succ n < m :=\n  show n < m - 1 \u2194 n + 1 < m from lt_tsub_iff_right\n#align nat.lt_pred_iff Nat.lt_pred_iff\n\ntheorem lt_of_lt_pred (h : m < n - 1) : m < n :=\n  lt_of_succ_lt (lt_pred_iff.1 h)\n#align nat.lt_of_lt_pred Nat.lt_of_lt_pred\n\ntheorem le_or_le_of_add_eq_add_pred (h : k + l = m + n - 1) : m \u2264 k \u2228 n \u2264 l := by\n  cases' le_or_lt m k with h' h' <;> [left, right]\n  \u00b7 exact h'\n  \u00b7 replace h' := add_lt_add_right h' l\n    rw [h] at h'\n    cases' n.eq_zero_or_pos with hn hn\n    \u00b7 rw [hn]\n      exact zero_le l\n    rw [n.add_sub_assoc (Nat.succ_le_of_lt hn), add_lt_add_iff_left] at h'\n    exact Nat.le_of_pred_lt h'\n#align nat.le_or_le_of_add_eq_add_pred Nat.le_or_le_of_add_eq_add_pred\n\n/-- A version of `Nat.sub_succ` in the form `_ - 1` instead of `Nat.pred _`. -/\ntheorem sub_succ' (m n : \u2115) : m - n.succ = m - n - 1 :=\n  rfl\n#align nat.sub_succ' Nat.sub_succ'\n\n/-! ### `mul` -/\n\n\ntheorem mul_eq_one_iff : \u2200 {m n : \u2115}, m * n = 1 \u2194 m = 1 \u2227 n = 1\n  | 0, 0 => by decide\n  | 0, 1 => by decide\n  | 1, 0 => by decide\n  | m + 2, 0 => by simp\n  | 0, n + 2 => by simp\n  | m + 1, n + 1 =>\n    \u27e8fun h => by\n      simp only [succ_mul, mul_succ, add_succ, one_mul, mul_one, (add_assoc _ _ _).symm,\n          \u2190 succ_eq_add_one, add_eq_zero_iff, (show 1 = succ 0 from rfl), succ_inj'] at h\n      simp [h],\n      fun h => by simp only [h, mul_one]\u27e9\n#align nat.mul_eq_one_iff Nat.mul_eq_one_iff\n\ntheorem succ_mul_pos (m : \u2115) (hn : 0 < n) : 0 < succ m * n :=\n  mul_pos (succ_pos m) hn\n#align nat.succ_mul_pos Nat.succ_mul_pos\n\ntheorem mul_self_le_mul_self (h : m \u2264 n) : m * m \u2264 n * n :=\n  mul_le_mul h h (zero_le _) (zero_le _)\n#align nat.mul_self_le_mul_self Nat.mul_self_le_mul_self\n\ntheorem mul_self_lt_mul_self : \u2200 {m n : \u2115}, m < n \u2192 m * m < n * n\n  | 0, _, h => mul_pos h h\n  | succ _, _, h => mul_lt_mul h (le_of_lt h) (succ_pos _) (zero_le _)\n#align nat.mul_self_lt_mul_self Nat.mul_self_lt_mul_self\n\ntheorem mul_self_le_mul_self_iff : m \u2264 n \u2194 m * m \u2264 n * n :=\n  \u27e8mul_self_le_mul_self, le_imp_le_of_lt_imp_lt mul_self_lt_mul_self\u27e9\n#align nat.mul_self_le_mul_self_iff Nat.mul_self_le_mul_self_iff\n\ntheorem mul_self_lt_mul_self_iff : m < n \u2194 m * m < n * n :=\n  le_iff_le_iff_lt_iff_lt.1 mul_self_le_mul_self_iff\n#align nat.mul_self_lt_mul_self_iff Nat.mul_self_lt_mul_self_iff\n\ntheorem le_mul_self : \u2200 n : \u2115, n \u2264 n * n\n  | 0 => le_rfl\n  | n + 1 => by simp\n#align nat.le_mul_self Nat.le_mul_self\n\ntheorem le_mul_of_pos_left (h : 0 < n) : m \u2264 n * m := by\n  conv =>\n    lhs\n    rw [\u2190 one_mul m]\n  exact mul_le_mul_of_nonneg_right h.nat_succ_le (zero_le _)\n#align nat.le_mul_of_pos_left Nat.le_mul_of_pos_left\n\ntheorem le_mul_of_pos_right (h : 0 < n) : m \u2264 m * n := by\n  conv =>\n    lhs\n    rw [\u2190 mul_one m]\n  exact mul_le_mul_of_nonneg_left h.nat_succ_le (zero_le _)\n#align nat.le_mul_of_pos_right Nat.le_mul_of_pos_right\n\ntheorem mul_self_inj : m * m = n * n \u2194 m = n :=\n  le_antisymm_iff.trans\n    (le_antisymm_iff.trans (and_congr mul_self_le_mul_self_iff mul_self_le_mul_self_iff)).symm\n#align nat.mul_self_inj Nat.mul_self_inj\n\ntheorem le_add_pred_of_pos (n : \u2115) {i : \u2115} (hi : i \u2260 0) : n \u2264 i + (n - 1) := by\n  refine le_trans ?_ add_tsub_le_assoc\n  simp [add_comm, Nat.add_sub_assoc, one_le_iff_ne_zero.2 hi]\n#align nat.le_add_pred_of_pos Nat.le_add_pred_of_pos\n\n@[simp]\ntheorem lt_mul_self_iff : \u2200 {n : \u2115}, n < n * n \u2194 1 < n\n  | 0 => iff_of_false (lt_irrefl _) zero_le_one.not_lt\n  | n + 1 => lt_mul_iff_one_lt_left n.succ_pos\n#align nat.lt_mul_self_iff Nat.lt_mul_self_iff\n\n/-!\n### Recursion and induction principles\n\nThis section is here due to dependencies -- the lemmas here require some of the lemmas\nproved above, and some of the results in later sections depend on the definitions in this section.\n-/\n\n\n/-- Given a predicate on two naturals `P : \u2115 \u2192 \u2115 \u2192 Prop`, `P a b` is true for all `a < b` if\n`P (a + 1) (a + 1)` is true for all `a`, `P 0 (b + 1)` is true for all `b` and for all\n`a < b`, `P (a + 1) b` is true and `P a (b + 1)` is true implies `P (a + 1) (b + 1)` is true. -/\n@[elab_as_elim]\ntheorem diag_induction (P : \u2115 \u2192 \u2115 \u2192 Prop) (ha : \u2200 a, P (a + 1) (a + 1)) (hb : \u2200 b, P 0 (b + 1))\n    (hd : \u2200 a b, a < b \u2192 P (a + 1) b \u2192 P a (b + 1) \u2192 P (a + 1) (b + 1)) : \u2200 a b, a < b \u2192 P a b\n  | 0, b + 1, _ => hb _\n  | a + 1, b + 1, h => by\n    apply hd _ _ ((add_lt_add_iff_right _).1 h)\n    \u00b7 have this : a + 1 = b \u2228 a + 1 < b := by rwa [\u2190 le_iff_eq_or_lt, \u2190 Nat.lt_succ_iff]\n      have wf : (a + 1) + b < (a + 1) + (b + 1) := by simp\n      rcases this with (rfl | h)\n      \u00b7 exact ha _\n      apply diag_induction P ha hb hd (a + 1) b h\n    have _ : a + (b + 1) < (a + 1) + (b + 1) := by simp\n    apply diag_induction P ha hb hd a (b + 1)\n    apply lt_of_le_of_lt (Nat.le_succ _) h\n  termination_by _ a b c => a + b\n  decreasing_by { assumption }\n#align nat.diag_induction Nat.diag_induction\n\n/-- A subset of `\u2115` containing `k : \u2115` and closed under `Nat.succ` contains every `n \u2265 k`. -/\ntheorem set_induction_bounded {S : Set \u2115} (hk : k \u2208 S) (h_ind : \u2200 k : \u2115, k \u2208 S \u2192 k + 1 \u2208 S)\n    (hnk : k \u2264 n) : n \u2208 S :=\n  @leRecOn (fun n => n \u2208 S) k n hnk @h_ind hk\n#align nat.set_induction_bounded Nat.set_induction_bounded\n\n/-- A subset of `\u2115` containing zero and closed under `Nat.succ` contains all of `\u2115`. -/\ntheorem set_induction {S : Set \u2115} (hb : 0 \u2208 S) (h_ind : \u2200 k : \u2115, k \u2208 S \u2192 k + 1 \u2208 S) (n : \u2115) :\n    n \u2208 S :=\n  set_induction_bounded hb h_ind (zero_le n)\n#align nat.set_induction Nat.set_induction\n\n/-! ### `div` -/\n\n\nprotected theorem div_le_of_le_mul' (h : m \u2264 k * n) : m / k \u2264 n :=\n  (Nat.eq_zero_or_pos k).elim (fun k0 => by rw [k0, Nat.div_zero] ; apply zero_le) fun k0 =>\n    le_of_mul_le_mul_left\n      (calc\n        k * (m / k) \u2264 m % k + k * (m / k) := Nat.le_add_left _ _\n        _ = m := mod_add_div _ _\n        _ \u2264 k * n := h) k0\n\n#align nat.div_le_of_le_mul' Nat.div_le_of_le_mul'\n\nprotected theorem div_le_self' (m n : \u2115) : m / n \u2264 m :=\n  (Nat.eq_zero_or_pos n).elim (fun n0 => by rw [n0, Nat.div_zero]; apply zero_le) fun n0 =>\n    Nat.div_le_of_le_mul' <|\n      calc\n        m = 1 * m := (one_mul _).symm\n        _ \u2264 n * m := Nat.mul_le_mul_right _ n0\n\n#align nat.div_le_self' Nat.div_le_self'\n\nprotected theorem div_lt_of_lt_mul (h : m < n * k) : m / n < k :=\n  lt_of_mul_lt_mul_left\n    (calc\n      n * (m / n) \u2264 m % n + n * (m / n) := Nat.le_add_left _ _\n      _ = m := mod_add_div _ _\n      _ < n * k := h\n      )\n    (Nat.zero_le n)\n#align nat.div_lt_of_lt_mul Nat.div_lt_of_lt_mul\n\ntheorem eq_zero_of_le_div (hn : 2 \u2264 n) (h : m \u2264 m / n) : m = 0 :=\n  eq_zero_of_mul_le hn <| by\n    rw [mul_comm]; exact (Nat.le_div_iff_mul_le' (lt_of_lt_of_le (by decide) hn)).1 h\n#align nat.eq_zero_of_le_div Nat.eq_zero_of_le_div\n\ntheorem div_mul_div_le_div (m n k : \u2115) : m / k * n / m \u2264 n / k :=\n  if hm0 : m = 0 then by simp [hm0]\n  else\n    calc\n      m / k * n / m \u2264 n * m / k / m :=\n        Nat.div_le_div_right (by rw [mul_comm] ; exact mul_div_le_mul_div_assoc _ _ _)\n      _ = n / k := by\n        { rw [Nat.div_div_eq_div_mul, mul_comm n, mul_comm k,\n            Nat.mul_div_mul_left _ _ (Nat.pos_of_ne_zero hm0)] }\n\n\n#align nat.div_mul_div_le_div Nat.div_mul_div_le_div\n\ntheorem eq_zero_of_le_half (h : n \u2264 n / 2) : n = 0 :=\n  eq_zero_of_le_div le_rfl h\n#align nat.eq_zero_of_le_half Nat.eq_zero_of_le_half\n\ntheorem mul_div_mul_comm_of_dvd_dvd (hmk : k \u2223 m) (hnl : l \u2223 n) :\n    m * n / (k * l) = m / k * (n / l) := by\n  rcases k.eq_zero_or_pos with (rfl | hk0); \u00b7 simp\n  rcases l.eq_zero_or_pos with (rfl | hl0); \u00b7 simp\n  obtain \u27e8_, rfl\u27e9 := hmk\n  obtain \u27e8_, rfl\u27e9 := hnl\n  rw [mul_mul_mul_comm, Nat.mul_div_cancel_left _ hk0, Nat.mul_div_cancel_left _ hl0,\n    Nat.mul_div_cancel_left _ (mul_pos hk0 hl0)]\n#align nat.mul_div_mul_comm_of_dvd_dvd Nat.mul_div_mul_comm_of_dvd_dvd\n\ntheorem le_half_of_half_lt_sub {a b : \u2115} (h : a / 2 < a - b) : b \u2264 a / 2 := by\n  rw [Nat.le_div_iff_mul_le two_pos]\n  rw [Nat.div_lt_iff_lt_mul two_pos, Nat.mul_sub_right_distrib, lt_tsub_iff_right, mul_two a] at h\n  exact le_of_lt (Nat.lt_of_add_lt_add_left h)\n#align nat.le_half_of_half_lt_sub Nat.le_half_of_half_lt_sub\n\ntheorem half_le_of_sub_le_half {a b : \u2115} (h : a - b \u2264 a / 2) : a / 2 \u2264 b := by\n  rw [Nat.le_div_iff_mul_le two_pos, Nat.mul_sub_right_distrib, tsub_le_iff_right, mul_two,\n    add_le_add_iff_left] at h\n  rw [\u2190 Nat.mul_div_left b two_pos]\n  exact Nat.div_le_div_right h\n#align nat.half_le_of_sub_le_half Nat.half_le_of_sub_le_half\n\n/-! ### `mod`, `dvd` -/\n\n\ntheorem two_mul_odd_div_two (hn : n % 2 = 1) : 2 * (n / 2) = n - 1 := by\n  conv =>\n    rhs\n    rw [\u2190 Nat.mod_add_div n 2, hn, @add_tsub_cancel_left]\n#align nat.two_mul_odd_div_two Nat.two_mul_odd_div_two\n\ntheorem div_dvd_of_dvd (h : n \u2223 m) : m / n \u2223 m :=\n  \u27e8n, (Nat.div_mul_cancel h).symm\u27e9\n#align nat.div_dvd_of_dvd Nat.div_dvd_of_dvd\n\nprotected theorem div_div_self (h : n \u2223 m) (hm : m \u2260 0) : m / (m / n) = n := by\n  rcases h with \u27e8_, rfl\u27e9\n  rw [mul_ne_zero_iff] at hm\n  rw [mul_div_right _ (Nat.pos_of_ne_zero hm.1), mul_div_left _ (Nat.pos_of_ne_zero hm.2)]\n#align nat.div_div_self Nat.div_div_self\n\n--Porting note: later `simp [mod_zero]` can be changed to `simp` once `mod_zero` is given\n--a `simp` attribute.\ntheorem mod_mul_right_div_self (m n k : \u2115) : m % (n * k) / n = m / n % k := by\n  rcases Nat.eq_zero_or_pos n with (rfl | hn); simp [mod_zero]\n  rcases Nat.eq_zero_or_pos k with (rfl | hk); simp [mod_zero]\n  conv_rhs => rw [\u2190 mod_add_div m (n * k)]\n  rw [mul_assoc, add_mul_div_left _ _ hn, add_mul_mod_self_left,\n    mod_eq_of_lt (Nat.div_lt_of_lt_mul (mod_lt _ (mul_pos hn hk)))]\n#align nat.mod_mul_right_div_self Nat.mod_mul_right_div_self\n\ntheorem mod_mul_left_div_self (m n k : \u2115) : m % (k * n) / n = m / n % k := by\n  rw [mul_comm k, mod_mul_right_div_self]\n#align nat.mod_mul_left_div_self Nat.mod_mul_left_div_self\n\ntheorem not_dvd_of_pos_of_lt (h1 : 0 < n) (h2 : n < m) : \u00acm \u2223 n := by\n  rintro \u27e8k, rfl\u27e9\n  rcases Nat.eq_zero_or_pos k with (rfl | hk)\n  \u00b7 exact lt_irrefl 0 h1\n  \u00b7 exact not_lt.2 (le_mul_of_pos_right hk) h2\n#align nat.not_dvd_of_pos_of_lt Nat.not_dvd_of_pos_of_lt\n\n/-- If `m` and `n` are equal mod `k`, `m - n` is zero mod `k`. -/\ntheorem sub_mod_eq_zero_of_mod_eq (h : m % k = n % k) : (m - n) % k = 0 := by\n  rw [\u2190 Nat.mod_add_div m k, \u2190 Nat.mod_add_div n k, \u2190 h, tsub_add_eq_tsub_tsub,\n    @add_tsub_cancel_left, \u2190 mul_tsub k, Nat.mul_mod_right]\n#align nat.sub_mod_eq_zero_of_mod_eq Nat.sub_mod_eq_zero_of_mod_eq\n\n@[simp]\ntheorem one_mod (n : \u2115) : 1 % (n + 2) = 1 :=\n  Nat.mod_eq_of_lt (add_lt_add_right n.succ_pos 1)\n#align nat.one_mod Nat.one_mod\n\ntheorem dvd_sub_mod (k : \u2115) : n \u2223 k - k % n :=\n  \u27e8k / n, tsub_eq_of_eq_add_rev (Nat.mod_add_div k n).symm\u27e9\n#align nat.dvd_sub_mod Nat.dvd_sub_mod\n\ntheorem add_mod_eq_ite :\n    (m + n) % k = if k \u2264 m % k + n % k then m % k + n % k - k else m % k + n % k := by\n  cases k; simp [mod_zero]\n  rw [Nat.add_mod]\n  split_ifs with h\n  \u00b7 rw [Nat.mod_eq_sub_mod h, Nat.mod_eq_of_lt]\n    exact\n      (tsub_lt_iff_right h).mpr (Nat.add_lt_add (m.mod_lt (zero_lt_succ _))\n        (n.mod_lt (zero_lt_succ _)))\n  \u00b7 exact Nat.mod_eq_of_lt (lt_of_not_ge h)\n#align nat.add_mod_eq_ite Nat.add_mod_eq_ite\n\ntheorem div_mul_div_comm (hmn : n \u2223 m) (hkl : l \u2223 k) : m / n * (k / l) = m * k / (n * l) :=\n  have exi1 : \u2203 x, m = n * x := hmn\n  have exi2 : \u2203 y, k = l * y := hkl\n  if hn : n = 0 then by simp [hn]\n  else\n    have : 0 < n := Nat.pos_of_ne_zero hn\n    if hl : l = 0 then by simp [hl]\n    else by\n      have : 0 < l := Nat.pos_of_ne_zero hl\n      cases' exi1 with x hx\n      cases' exi2 with y hy\n      rw [hx, hy, Nat.mul_div_cancel_left, Nat.mul_div_cancel_left]\n      apply Eq.symm\n      apply Nat.div_eq_of_eq_mul_left\n      apply mul_pos\n      repeat' assumption\n      -- Porting note: this line was `cc` in Lean3\n      simp only [mul_comm, mul_left_comm, mul_assoc]\n\n#align nat.div_mul_div_comm Nat.div_mul_div_comm\n\ntheorem div_eq_self : m / n = m \u2194 m = 0 \u2228 n = 1 := by\n  constructor\n  \u00b7 intro\n    match n with\n    | 0 => simp_all\n    | 1 =>\n      right\n      rfl\n    | n+2 =>\n      left\n      have : m / (n + 2) \u2264 m / 2 := div_le_div_left (by simp) (by decide)\n      refine eq_zero_of_le_half ?_\n      simp_all\n  \u00b7 rintro (rfl | rfl) <;> simp\n#align nat.div_eq_self Nat.div_eq_self\n\ntheorem div_eq_sub_mod_div : m / n = (m - m % n) / n := by\n  by_cases n0 : n = 0\n  \u00b7 rw [n0, Nat.div_zero, Nat.div_zero]\n  \u00b7 have : m - m % n = n * (m / n) := by\n      rw [tsub_eq_iff_eq_add_of_le (Nat.mod_le _ _), add_comm, mod_add_div]\n    rw [this, mul_div_right _ (Nat.pos_of_ne_zero n0)]\n#align nat.div_eq_sub_mod_div Nat.div_eq_sub_mod_div\n\n/-- `m` is not divisible by `n` if it is between `n * k` and `n * (k + 1)` for some `k`. -/\ntheorem not_dvd_of_between_consec_multiples (h1 : n * k < m) (h2 : m < n * (k + 1)) : \u00acn \u2223 m := by\n  rintro \u27e8d, rfl\u27e9\n  exact Monotone.ne_of_lt_of_lt_nat (Covariant.monotone_of_const n) k h1 h2 d rfl\n#align nat.not_dvd_of_between_consec_multiples Nat.not_dvd_of_between_consec_multiples\n\n/-! ### `find` -/\n\n\nsection Find\n\nvariable {p q : \u2115 \u2192 Prop} [DecidablePred p] [DecidablePred q]\n\n--Porting note: removing `simp` attribute as `simp` can prove it\ntheorem find_pos (h : \u2203 n : \u2115, p n) : 0 < Nat.find h \u2194 \u00acp 0 := by\n  rw [pos_iff_ne_zero, Ne, Nat.find_eq_zero]\n#align nat.find_pos Nat.find_pos\n\ntheorem find_add {h\u2098 : \u2203 m, p (m + n)} {h\u2099 : \u2203 n, p n} (hn : n \u2264 Nat.find h\u2099) :\n    Nat.find h\u2098 + n = Nat.find h\u2099 := by\n  refine ((le_find_iff _ _).2 fun m hm hpm => hm.not_le ?_).antisymm ?_\n  \u00b7 have hnm : n \u2264 m := hn.trans (find_le hpm)\n    refine add_le_of_le_tsub_right_of_le hnm (find_le ?_)\n    rwa [tsub_add_cancel_of_le hnm]\n  \u00b7 rw [\u2190 tsub_le_iff_right]\n    refine (le_find_iff _ _).2 fun m hm hpm => hm.not_le ?_\n    rw [tsub_le_iff_right]\n    exact find_le hpm\n#align nat.find_add Nat.find_add\n\nend Find\n\n/-! ### `find_greatest` -/\n\n\nsection FindGreatest\n\nvariable {P Q : \u2115 \u2192 Prop} [DecidablePred P]\n\ntheorem findGreatest_eq_iff :\n    Nat.findGreatest P k = m \u2194 m \u2264 k \u2227 (m \u2260 0 \u2192 P m) \u2227 \u2200 \u2983n\u2984, m < n \u2192 n \u2264 k \u2192 \u00acP n := by\n  induction' k with k ihk generalizing m\n  \u00b7 rw [eq_comm, Iff.comm]\n    simp only [zero_eq, nonpos_iff_eq_zero, ne_eq, findGreatest_zero, and_iff_left_iff_imp]\n    rintro rfl\n    exact \u27e8fun h => (h rfl).elim, fun n hlt heq => (hlt.ne heq.symm).elim\u27e9\n  \u00b7 by_cases hk : P (k + 1)\n    \u00b7 rw [findGreatest_eq hk]\n      constructor\n      \u00b7 rintro rfl\n        exact \u27e8le_rfl, fun _ => hk, fun n hlt hle => (hlt.not_le hle).elim\u27e9\n      \u00b7 rintro \u27e8hle, h0, hm\u27e9\n        rcases Decidable.eq_or_lt_of_le hle with (rfl | hlt)\n        exacts[rfl, (hm hlt le_rfl hk).elim]\n    \u00b7 rw [findGreatest_of_not hk, ihk]\n      constructor\n      \u00b7 rintro \u27e8hle, hP, hm\u27e9\n        refine \u27e8hle.trans k.le_succ, hP, fun n hlt hle => ?_\u27e9\n        rcases Decidable.eq_or_lt_of_le hle with (rfl | hlt')\n        exacts[hk, hm hlt <| lt_succ_iff.1 hlt']\n      \u00b7 rintro \u27e8hle, hP, hm\u27e9\n        refine \u27e8lt_succ_iff.1 (hle.lt_of_ne ?_), hP, fun n hlt hle => hm hlt (hle.trans k.le_succ)\u27e9\n        rintro rfl\n        exact hk (hP k.succ_ne_zero)\n#align nat.find_greatest_eq_iff Nat.findGreatest_eq_iff\n\ntheorem findGreatest_eq_zero_iff : Nat.findGreatest P k = 0 \u2194 \u2200 \u2983n\u2984, 0 < n \u2192 n \u2264 k \u2192 \u00acP n := by\n  simp [findGreatest_eq_iff]\n#align nat.find_greatest_eq_zero_iff Nat.findGreatest_eq_zero_iff\n\ntheorem findGreatest_spec (hmb : m \u2264 n) (hm : P m) : P (Nat.findGreatest P n) := by\n  by_cases h : Nat.findGreatest P n = 0\n  \u00b7 cases m\n    \u00b7 rwa [h]\n    exact ((findGreatest_eq_zero_iff.1 h) (zero_lt_succ _) hmb hm).elim\n  \u00b7 exact (findGreatest_eq_iff.1 rfl).2.1 h\n#align nat.find_greatest_spec Nat.findGreatest_spec\n\ntheorem findGreatest_le (n : \u2115) : Nat.findGreatest P n \u2264 n :=\n  (findGreatest_eq_iff.1 rfl).1\n#align nat.find_greatest_le Nat.findGreatest_le\n\ntheorem le_findGreatest (hmb : m \u2264 n) (hm : P m) : m \u2264 Nat.findGreatest P n :=\n  le_of_not_lt fun hlt => (findGreatest_eq_iff.1 rfl).2.2 hlt hmb hm\n#align nat.le_find_greatest Nat.le_findGreatest\n\ntheorem findGreatest_mono_right (P : \u2115 \u2192 Prop) [DecidablePred P] :\n    Monotone (Nat.findGreatest P) := by\n  refine monotone_nat_of_le_succ fun n => ?_\n  rw [findGreatest_succ]\n  split_ifs\n  \u00b7 exact (findGreatest_le n).trans (le_succ _)\n  \u00b7 rfl\n#align nat.find_greatest_mono_right Nat.findGreatest_mono_right\n\n\n\ntheorem findGreatest_mono [DecidablePred Q] (hPQ : P \u2264 Q) (hmn : m \u2264 n) :\n    Nat.findGreatest P m \u2264 Nat.findGreatest Q n :=\n  (Nat.findGreatest_mono_right _ hmn).trans <| findGreatest_mono_left hPQ _\n#align nat.find_greatest_mono Nat.findGreatest_mono\n\ntheorem findGreatest_is_greatest (hk : Nat.findGreatest P n < k) (hkb : k \u2264 n) : \u00acP k :=\n  (findGreatest_eq_iff.1 rfl).2.2 hk hkb\n#align nat.find_greatest_is_greatest Nat.findGreatest_is_greatest\n\ntheorem findGreatest_of_ne_zero (h : Nat.findGreatest P n = m) (h0 : m \u2260 0) : P m :=\n  (findGreatest_eq_iff.1 h).2.1 h0\n#align nat.find_greatest_of_ne_zero Nat.findGreatest_of_ne_zero\n\nend FindGreatest\n\n/-! ### `bit0` and `bit1` -/\nsection Bit\n\nset_option linter.deprecated false\n\nprotected theorem bit0_le {n m : \u2115} (h : n \u2264 m) : bit0 n \u2264 bit0 m :=\n  add_le_add h h\n#align nat.bit0_le Nat.bit0_le\n\nprotected theorem bit1_le {n m : \u2115} (h : n \u2264 m) : bit1 n \u2264 bit1 m :=\n  succ_le_succ (add_le_add h h)\n#align nat.bit1_le Nat.bit1_le\n\ntheorem bit_le : \u2200 (b : Bool) {m n : \u2115}, m \u2264 n \u2192 bit b m \u2264 bit b n\n  | true, _, _, h => Nat.bit1_le  h\n  | false, _, _, h => Nat.bit0_le h\n#align nat.bit_le Nat.bit_le\n\ntheorem bit0_le_bit : \u2200 (b) {m n : \u2115}, m \u2264 n \u2192 bit0 m \u2264 bit b n\n  | true, _, _, h => le_of_lt <| Nat.bit0_lt_bit1 h\n  | false, _, _, h => Nat.bit0_le h\n#align nat.bit0_le_bit Nat.bit0_le_bit\n\ntheorem bit_le_bit1 : \u2200 (b) {m n : \u2115}, m \u2264 n \u2192 bit b m \u2264 bit1 n\n  | false, _, _, h => le_of_lt <| Nat.bit0_lt_bit1 h\n  | true, _, _, h => Nat.bit1_le h\n#align nat.bit_le_bit1 Nat.bit_le_bit1\n\ntheorem bit_lt_bit0 : \u2200 (b) {m n : \u2115}, m < n \u2192 bit b m < bit0 n\n  | true, _, _, h => Nat.bit1_lt_bit0 h\n  | false, _, _, h => Nat.bit0_lt h\n#align nat.bit_lt_bit0 Nat.bit_lt_bit0\n\ntheorem bit_lt_bit (a b) (h : m < n) : bit a m < bit b n :=\n  lt_of_lt_of_le (bit_lt_bit0 _ h) (bit0_le_bit _ le_rfl)\n#align nat.bit_lt_bit Nat.bit_lt_bit\n\n@[simp]\ntheorem bit0_le_bit1_iff : bit0 m \u2264 bit1 n \u2194 m \u2264 n :=\n  \u27e8fun h => by\n    rwa [\u2190 Nat.lt_succ_iff, n.bit1_eq_succ_bit0,\n    \u2190 n.bit0_succ_eq, bit0_lt_bit0, Nat.lt_succ_iff] at h,\n    fun h => le_of_lt (Nat.bit0_lt_bit1 h)\u27e9\n#align nat.bit0_le_bit1_iff Nat.bit0_le_bit1_iff\n\n@[simp]\ntheorem bit0_lt_bit1_iff : bit0 m < bit1 n \u2194 m \u2264 n :=\n  \u27e8fun h => bit0_le_bit1_iff.1 (le_of_lt h), Nat.bit0_lt_bit1\u27e9\n#align nat.bit0_lt_bit1_iff Nat.bit0_lt_bit1_iff\n\n@[simp]\ntheorem bit1_le_bit0_iff : bit1 m \u2264 bit0 n \u2194 m < n :=\n  \u27e8fun h => by rwa [m.bit1_eq_succ_bit0, succ_le_iff, bit0_lt_bit0] at h, fun h =>\n    le_of_lt (Nat.bit1_lt_bit0 h)\u27e9\n#align nat.bit1_le_bit0_iff Nat.bit1_le_bit0_iff\n\n@[simp]\ntheorem bit1_lt_bit0_iff : bit1 m < bit0 n \u2194 m < n :=\n  \u27e8fun h => bit1_le_bit0_iff.1 (le_of_lt h), Nat.bit1_lt_bit0\u27e9\n#align nat.bit1_lt_bit0_iff Nat.bit1_lt_bit0_iff\n\n-- Porting note: temporarily porting only needed portions\n/-\n@[simp]\ntheorem one_le_bit0_iff : 1 \u2264 bit0 n \u2194 0 < n := by\n  convert bit1_le_bit0_iff\n  rfl\n#align nat.one_le_bit0_iff Nat.one_le_bit0_iff\n\n@[simp]\ntheorem one_lt_bit0_iff : 1 < bit0 n \u2194 1 \u2264 n := by\n  convert bit1_lt_bit0_iff\n  rfl\n#align nat.one_lt_bit0_iff Nat.one_lt_bit0_iff\n\n@[simp]\ntheorem bit_le_bit_iff : \u2200 {b : Bool}, bit b m \u2264 bit b n \u2194 m \u2264 n\n  | false => bit0_le_bit0\n  | true => bit1_le_bit1\n#align nat.bit_le_bit_iff Nat.bit_le_bit_iff\n\n@[simp]\ntheorem bit_lt_bit_iff : \u2200 {b : Bool}, bit b m < bit b n \u2194 m < n\n  | false => bit0_lt_bit0\n  | true => bit1_lt_bit1\n#align nat.bit_lt_bit_iff Nat.bit_lt_bit_iff\n\n@[simp]\ntheorem bit_le_bit1_iff : \u2200 {b : Bool}, bit b m \u2264 bit1 n \u2194 m \u2264 n\n  | false => bit0_le_bit1_iff\n  | true => bit1_le_bit1\n#align nat.bit_le_bit1_iff Nat.bit_le_bit1_iff\n-/\n\nend Bit\n\n/-! ### decidability of predicates -/\n\n\ninstance decidableLoHi (lo hi : \u2115) (P : \u2115 \u2192 Prop) [H : DecidablePred P] :\n    Decidable (\u2200 x, lo \u2264 x \u2192 x < hi \u2192 P x) :=\n  decidable_of_iff (\u2200 x < hi - lo, P (lo + x))\n    \u27e8fun al x hl hh => by\n      have := al (x - lo) ((tsub_lt_tsub_iff_right hl).mpr hh)\n      rwa [add_tsub_cancel_of_le hl] at this, fun al x h =>\n      al _ (Nat.le_add_right _ _) (lt_tsub_iff_left.mp h)\u27e9\n#align nat.decidable_lo_hi Nat.decidableLoHi\n\ninstance decidableLoHiLe (lo hi : \u2115) (P : \u2115 \u2192 Prop) [DecidablePred P] :\n    Decidable (\u2200 x, lo \u2264 x \u2192 x \u2264 hi \u2192 P x) :=\n  decidable_of_iff (\u2200 x, lo \u2264 x \u2192 x < hi + 1 \u2192 P x) <|\n    ball_congr fun _ _ => imp_congr lt_succ_iff Iff.rfl\n#align nat.decidable_lo_hi_le Nat.decidableLoHiLe\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Order/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.859663754105328, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7048325850089997}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.fin.tuple.basic\nimport data.list.join\nimport data.list.pairwise\n\n/-!\n# Lists from functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nTheorems and lemmas for dealing with `list.of_fn`, which converts a function on `fin n` to a list\nof length `n`.\n\n## Main Statements\n\nThe main statements pertain to lists generated using `of_fn`\n\n- `list.length_of_fn`, which tells us the length of such a list\n- `list.nth_of_fn`, which tells us the nth element of such a list\n- `list.array_eq_of_fn`, which interprets the list form of an array as such a list.\n- `list.equiv_sigma_tuple`, which is an `equiv` between lists and the functions that generate them\n  via `list.of_fn`.\n-/\n\nuniverses u\n\nvariables {\u03b1 : Type u}\n\nopen nat\nnamespace list\n\nlemma length_of_fn_aux {n} (f : fin n \u2192 \u03b1) :\n  \u2200 m h l, length (of_fn_aux f m h l) = length l + m\n| 0        h l := rfl\n| (succ m) h l := (length_of_fn_aux m _ _).trans (succ_add _ _)\n\n/-- The length of a list converted from a function is the size of the domain. -/\n@[simp] theorem length_of_fn {n} (f : fin n \u2192 \u03b1) : length (of_fn f) = n :=\n(length_of_fn_aux f _ _ _).trans (zero_add _)\n\nlemma nth_of_fn_aux {n} (f : fin n \u2192 \u03b1) (i) :\n  \u2200 m h l,\n    (\u2200 i, nth l i = of_fn_nth_val f (i + m)) \u2192\n     nth (of_fn_aux f m h l) i = of_fn_nth_val f i\n| 0        h l H := H i\n| (succ m) h l H := nth_of_fn_aux m _ _ begin\n  intro j, cases j with j,\n  { simp only [nth, of_fn_nth_val, zero_add, dif_pos (show m < n, from h)] },\n  { simp only [nth, H, add_succ, succ_add] }\nend\n\n/-- The `n`th element of a list -/\n@[simp] theorem nth_of_fn {n} (f : fin n \u2192 \u03b1) (i) :\n  nth (of_fn f) i = of_fn_nth_val f i :=\nnth_of_fn_aux f _ _ _ _ $ \u03bb i,\nby simp only [of_fn_nth_val, dif_neg (not_lt.2 (nat.le_add_left n i))]; refl\n\ntheorem nth_le_of_fn {n} (f : fin n \u2192 \u03b1) (i : fin n) :\n  nth_le (of_fn f) i ((length_of_fn f).symm \u25b8 i.2) = f i :=\noption.some.inj $ by rw [\u2190 nth_le_nth];\n  simp only [list.nth_of_fn, of_fn_nth_val, fin.eta, dif_pos i.is_lt]\n\n@[simp] theorem nth_le_of_fn' {n} (f : fin n \u2192 \u03b1) {i : \u2115} (h : i < (of_fn f).length) :\n  nth_le (of_fn f) i h = f \u27e8i, ((length_of_fn f) \u25b8 h)\u27e9 :=\nnth_le_of_fn f \u27e8i, ((length_of_fn f) \u25b8 h)\u27e9\n\n@[simp] lemma map_of_fn {\u03b2 : Type*} {n : \u2115} (f : fin n \u2192 \u03b1) (g : \u03b1 \u2192 \u03b2) :\n  map g (of_fn f) = of_fn (g \u2218 f) :=\next_le (by simp) (\u03bb i h h', by simp)\n\n/-- Arrays converted to lists are the same as `of_fn` on the indexing function of the array. -/\ntheorem array_eq_of_fn {n} (a : array n \u03b1) : a.to_list = of_fn a.read :=\nsuffices \u2200 {m h l}, d_array.rev_iterate_aux a\n  (\u03bb i, cons) m h l = of_fn_aux (d_array.read a) m h l, from this,\nbegin\n  intros, induction m with m IH generalizing l, {refl},\n  simp only [d_array.rev_iterate_aux, of_fn_aux, IH]\nend\n\n@[congr]\ntheorem of_fn_congr {m n : \u2115} (h : m = n) (f : fin m \u2192 \u03b1) :\n  of_fn f = of_fn (\u03bb i : fin n, f (fin.cast h.symm i)) :=\nbegin\n  subst h,\n  simp_rw [fin.cast_refl, order_iso.refl_apply],\nend\n\n/-- `of_fn` on an empty domain is the empty list. -/\n@[simp] theorem of_fn_zero (f : fin 0 \u2192 \u03b1) : of_fn f = [] := rfl\n\n@[simp] theorem of_fn_succ {n} (f : fin (succ n) \u2192 \u03b1) :\n  of_fn f = f 0 :: of_fn (\u03bb i, f i.succ) :=\nsuffices \u2200 {m h l}, of_fn_aux f (succ m) (succ_le_succ h) l =\n  f 0 :: of_fn_aux (\u03bb i, f i.succ) m h l, from this,\nbegin\n  intros, induction m with m IH generalizing l, {refl},\n  rw [of_fn_aux, IH], refl\nend\n\ntheorem of_fn_succ' {n} (f : fin (succ n) \u2192 \u03b1) :\n  of_fn f = (of_fn (\u03bb i, f i.cast_succ)).concat (f (fin.last _)) :=\nbegin\n  induction n with n IH,\n  { rw [of_fn_zero, concat_nil, of_fn_succ, of_fn_zero], refl },\n  { rw [of_fn_succ, IH, of_fn_succ, concat_cons, fin.cast_succ_zero],\n    congr' 3,\n    simp_rw [fin.cast_succ_fin_succ], }\nend\n\n@[simp] lemma of_fn_eq_nil_iff {n : \u2115} {f : fin n \u2192 \u03b1} :\n  of_fn f = [] \u2194 n = 0 :=\nby cases n; simp only [of_fn_zero, of_fn_succ, eq_self_iff_true, nat.succ_ne_zero]\n\nlemma last_of_fn {n : \u2115} (f : fin n \u2192 \u03b1) (h : of_fn f \u2260 [])\n  (hn : n - 1 < n := nat.pred_lt $ of_fn_eq_nil_iff.not.mp h) :\n  last (of_fn f) h = f \u27e8n - 1, hn\u27e9 :=\nby simp [last_eq_nth_le]\n\nlemma last_of_fn_succ {n : \u2115} (f : fin n.succ \u2192 \u03b1)\n  (h : of_fn f \u2260 [] := mt of_fn_eq_nil_iff.mp (nat.succ_ne_zero _)) :\n  last (of_fn f) h = f (fin.last _) :=\nlast_of_fn f h\n\n/-- Note this matches the convention of `list.of_fn_succ'`, putting the `fin m` elements first. -/\ntheorem of_fn_add {m n} (f : fin (m + n) \u2192 \u03b1) :\n  list.of_fn f = list.of_fn (\u03bb i, f (fin.cast_add n i)) ++ list.of_fn (\u03bb j, f (fin.nat_add m j)) :=\nbegin\n  induction n with n IH,\n  { rw [of_fn_zero, append_nil, fin.cast_add_zero, fin.cast_refl], refl },\n  { rw [of_fn_succ', of_fn_succ', IH, append_concat], refl, },\nend\n\n@[simp] theorem of_fn_fin_append {m n} (a : fin m \u2192 \u03b1) (b : fin n \u2192 \u03b1) :\n  list.of_fn (fin.append a b) = list.of_fn a ++ list.of_fn b :=\nby simp_rw [of_fn_add, fin.append_left, fin.append_right]\n\n/-- This breaks a list of `m*n` items into `m` groups each containing `n` elements. -/\ntheorem of_fn_mul {m n} (f : fin (m * n) \u2192 \u03b1) :\n  list.of_fn f = list.join (list.of_fn $ \u03bb i : fin m, list.of_fn $ \u03bb j : fin n,\n  f \u27e8i * n + j,\n    calc \u2191i * n + j < (i + 1) *n : (add_lt_add_left j.prop _).trans_eq (add_one_mul _ _).symm\n                ... \u2264 _ : nat.mul_le_mul_right _ i.prop\u27e9) :=\nbegin\n  induction m with m IH,\n  { simp_rw [of_fn_zero, zero_mul, of_fn_zero, join], },\n  { simp_rw [of_fn_succ', succ_mul, join_concat, of_fn_add, IH], refl, },\nend\n\n/-- This breaks a list of `m*n` items into `n` groups each containing `m` elements. -/\ntheorem of_fn_mul' {m n} (f : fin (m * n) \u2192 \u03b1) :\n  list.of_fn f = list.join (list.of_fn $ \u03bb i : fin n, list.of_fn $ \u03bb j : fin m,\n  f \u27e8m * i + j,\n    calc m * i + j < m * (i + 1) : (add_lt_add_left j.prop _).trans_eq (mul_add_one _ _).symm\n               ... \u2264 _ : nat.mul_le_mul_left _ i.prop\u27e9) :=\nby simp_rw [mul_comm m n, mul_comm m, of_fn_mul, fin.cast_mk]\n\ntheorem of_fn_nth_le : \u2200 l : list \u03b1, of_fn (\u03bb i, nth_le l i i.2) = l\n| [] := rfl\n| (a::l) := by { rw of_fn_succ, congr, simp only [fin.coe_succ], exact of_fn_nth_le l }\n\n-- not registered as a simp lemma, as otherwise it fires before `forall_mem_of_fn_iff` which\n-- is much more useful\nlemma mem_of_fn {n} (f : fin n \u2192 \u03b1) (a : \u03b1) :\n  a \u2208 of_fn f \u2194 a \u2208 set.range f :=\nbegin\n  simp only [mem_iff_nth_le, set.mem_range, nth_le_of_fn'],\n  exact \u27e8\u03bb \u27e8i, hi, h\u27e9, \u27e8_, h\u27e9, \u03bb \u27e8i, hi\u27e9, \u27e8i.1, (length_of_fn f).symm \u25b8 i.2, by simpa using hi\u27e9\u27e9\nend\n\n@[simp] lemma forall_mem_of_fn_iff {n : \u2115} {f : fin n \u2192 \u03b1} {P : \u03b1 \u2192 Prop} :\n  (\u2200 i \u2208 of_fn f, P i) \u2194 \u2200 j : fin n, P (f j) :=\nby simp only [mem_of_fn, set.forall_range_iff]\n\n@[simp] lemma of_fn_const (n : \u2115) (c : \u03b1) :\n  of_fn (\u03bb i : fin n, c) = replicate n c :=\nnat.rec_on n (by simp) $ \u03bb n ihn, by simp [ihn]\n\n@[simp] theorem of_fn_fin_repeat {m} (a : fin m \u2192 \u03b1) (n : \u2115) :\n  list.of_fn (fin.repeat n a) = (list.replicate n (list.of_fn a)).join :=\nby simp_rw [of_fn_mul, \u2190of_fn_const, fin.repeat, fin.mod_nat, fin.coe_mk,\n  add_comm, nat.add_mul_mod_self_right, nat.mod_eq_of_lt (fin.is_lt _), fin.eta]\n\n@[simp] lemma pairwise_of_fn {R : \u03b1 \u2192 \u03b1 \u2192 Prop} {n} {f : fin n \u2192 \u03b1} :\n  (of_fn f).pairwise R \u2194 \u2200 \u2983i j\u2984, i < j \u2192 R (f i) (f j) :=\nby { simp only [pairwise_iff_nth_le, fin.forall_iff, length_of_fn, nth_le_of_fn', fin.mk_lt_mk],\n  exact \u27e8\u03bb h i hi j hj hij, h _ _ hj hij, \u03bb h i j hj hij, h _ (hij.trans hj) _ hj hij\u27e9 }\n\n/-- Lists are equivalent to the sigma type of tuples of a given length. -/\n@[simps]\ndef equiv_sigma_tuple : list \u03b1 \u2243 \u03a3 n, fin n \u2192 \u03b1 :=\n{ to_fun := \u03bb l, \u27e8l.length, \u03bb i, l.nth_le \u2191i i.2\u27e9,\n  inv_fun := \u03bb f, list.of_fn f.2,\n  left_inv := list.of_fn_nth_le,\n  right_inv := \u03bb \u27e8n, f\u27e9, fin.sigma_eq_of_eq_comp_cast (length_of_fn _) $ funext $ \u03bb i,\n    nth_le_of_fn' f i.prop }\n\n/-- A recursor for lists that expands a list into a function mapping to its elements.\n\nThis can be used with `induction l using list.of_fn_rec`. -/\n@[elab_as_eliminator]\ndef of_fn_rec {C : list \u03b1 \u2192 Sort*} (h : \u03a0 n (f : fin n \u2192 \u03b1), C (list.of_fn f)) (l : list \u03b1) : C l :=\ncast (congr_arg _ l.of_fn_nth_le) $ h l.length (\u03bb i, l.nth_le \u2191i i.2)\n\n@[simp]\nlemma of_fn_rec_of_fn {C : list \u03b1 \u2192 Sort*} (h : \u03a0 n (f : fin n \u2192 \u03b1), C (list.of_fn f))\n  {n : \u2115} (f : fin n \u2192 \u03b1) : @of_fn_rec _ C h (list.of_fn f) = h _ f :=\nequiv_sigma_tuple.right_inverse_symm.cast_eq (\u03bb s, h s.1 s.2) \u27e8n, f\u27e9\n\nlemma exists_iff_exists_tuple {P : list \u03b1 \u2192 Prop} :\n  (\u2203 l : list \u03b1, P l) \u2194 \u2203 n (f : fin n \u2192 \u03b1), P (list.of_fn f) :=\nequiv_sigma_tuple.symm.surjective.exists.trans sigma.exists\n\nlemma forall_iff_forall_tuple {P : list \u03b1 \u2192 Prop} :\n  (\u2200 l : list \u03b1, P l) \u2194 \u2200 n (f : fin n \u2192 \u03b1), P (list.of_fn f) :=\nequiv_sigma_tuple.symm.surjective.forall.trans sigma.forall\n\n/-- `fin.sigma_eq_iff_eq_comp_cast` may be useful to work with the RHS of this expression. -/\nlemma of_fn_inj' {m n : \u2115} {f : fin m \u2192 \u03b1} {g : fin n \u2192 \u03b1} :\n  of_fn f = of_fn g \u2194 (\u27e8m, f\u27e9 : \u03a3 n, fin n \u2192 \u03b1) = \u27e8n, g\u27e9 :=\niff.symm $ equiv_sigma_tuple.symm.injective.eq_iff.symm\n\n/-- Note we can only state this when the two functions are indexed by defeq `n`. -/\nlemma of_fn_injective {n : \u2115} : function.injective (of_fn : (fin n \u2192 \u03b1) \u2192 list \u03b1) :=\n\u03bb f g h, eq_of_heq $ by injection of_fn_inj'.mp h\n\n/-- A special case of `list.of_fn_inj'` for when the two functions are indexed by defeq `n`. -/\n@[simp] lemma of_fn_inj {n : \u2115} {f g : fin n \u2192 \u03b1} : of_fn f = of_fn g \u2194 f = g :=\nof_fn_injective.eq_iff\n\nend list\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/list/of_fn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.704832572603003}}
{"text": "/-\nCopyright (c) 2022 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Heather Macbeth\n-/\nimport geometry.euclidean.angle.oriented.basic\n\n/-!\n# Rotations by oriented angles.\n\nThis file defines rotations by oriented angles in real inner product spaces.\n\n## Main definitions\n\n* `orientation.rotation` is the rotation by an oriented angle with respect to an orientation.\n\n-/\n\nnoncomputable theory\n\nopen finite_dimensional complex\nopen_locale real real_inner_product_space complex_conjugate\n\nnamespace orientation\n\nlocal attribute [instance] fact_finite_dimensional_of_finrank_eq_succ\nlocal attribute [instance] complex.finrank_real_complex_fact\n\nvariables {V V' : Type*}\nvariables [normed_add_comm_group V] [normed_add_comm_group V']\nvariables [inner_product_space \u211d V] [inner_product_space \u211d V']\nvariables [fact (finrank \u211d V = 2)] [fact (finrank \u211d V' = 2)] (o : orientation \u211d V (fin 2))\n\nlocal notation `J` := o.right_angle_rotation\n\n/-- Auxiliary construction to build a rotation by the oriented angle `\u03b8`. -/\ndef rotation_aux (\u03b8 : real.angle) : V \u2192\u2097\u1d62[\u211d] V :=\nlinear_map.isometry_of_inner\n  (real.angle.cos \u03b8 \u2022 linear_map.id\n        + real.angle.sin \u03b8 \u2022 \u2191(linear_isometry_equiv.to_linear_equiv J))\n  begin\n    intros x y,\n    simp only [is_R_or_C.conj_to_real, id.def, linear_map.smul_apply, linear_map.add_apply,\n      linear_map.id_coe, linear_equiv.coe_coe, linear_isometry_equiv.coe_to_linear_equiv,\n      orientation.area_form_right_angle_rotation_left,\n      orientation.inner_right_angle_rotation_left,\n      orientation.inner_right_angle_rotation_right,\n      inner_add_left, inner_smul_left, inner_add_right, inner_smul_right],\n    linear_combination inner x y * \u03b8.cos_sq_add_sin_sq,\n  end\n\n@[simp] lemma rotation_aux_apply (\u03b8 : real.angle) (x : V) :\n  o.rotation_aux \u03b8 x = real.angle.cos \u03b8 \u2022 x + real.angle.sin \u03b8 \u2022 J x :=\nrfl\n\n/-- A rotation by the oriented angle `\u03b8`. -/\ndef rotation (\u03b8 : real.angle) : V \u2243\u2097\u1d62[\u211d] V :=\nlinear_isometry_equiv.of_linear_isometry\n  (o.rotation_aux \u03b8)\n  (real.angle.cos \u03b8 \u2022 linear_map.id - real.angle.sin \u03b8 \u2022 \u2191(linear_isometry_equiv.to_linear_equiv J))\n  begin\n    ext x,\n    convert congr_arg (\u03bb t : \u211d, t \u2022 x) \u03b8.cos_sq_add_sin_sq using 1,\n    { simp only [o.right_angle_rotation_right_angle_rotation, o.rotation_aux_apply,\n        function.comp_app, id.def, linear_equiv.coe_coe, linear_isometry.coe_to_linear_map,\n        linear_isometry_equiv.coe_to_linear_equiv, map_smul, map_sub, linear_map.coe_comp,\n        linear_map.id_coe, linear_map.smul_apply, linear_map.sub_apply, \u2190 mul_smul, add_smul,\n        smul_add, smul_neg, smul_sub, mul_comm, sq],\n      abel },\n    { simp },\n  end\n  begin\n    ext x,\n    convert congr_arg (\u03bb t : \u211d, t \u2022 x) \u03b8.cos_sq_add_sin_sq using 1,\n    { simp only [o.right_angle_rotation_right_angle_rotation, o.rotation_aux_apply,\n        function.comp_app, id.def, linear_equiv.coe_coe, linear_isometry.coe_to_linear_map,\n        linear_isometry_equiv.coe_to_linear_equiv, map_add, map_smul, linear_map.coe_comp,\n        linear_map.id_coe, linear_map.smul_apply, linear_map.sub_apply, add_smul, \u2190 mul_smul,\n        mul_comm, smul_add, smul_neg, sq],\n      abel },\n    { simp },\n  end\n\nlemma rotation_apply (\u03b8 : real.angle) (x : V) :\n  o.rotation \u03b8 x = real.angle.cos \u03b8 \u2022 x + real.angle.sin \u03b8 \u2022 J x :=\nrfl\n\nlemma rotation_symm_apply (\u03b8 : real.angle) (x : V) :\n  (o.rotation \u03b8).symm x = real.angle.cos \u03b8 \u2022 x - real.angle.sin \u03b8 \u2022 J x :=\nrfl\n\nattribute [irreducible] rotation\n\nlemma rotation_eq_matrix_to_lin (\u03b8 : real.angle) {x : V} (hx : x \u2260 0) :\n  (o.rotation \u03b8).to_linear_map\n  = matrix.to_lin\n      (o.basis_right_angle_rotation x hx) (o.basis_right_angle_rotation x hx)\n      !![\u03b8.cos, -\u03b8.sin; \u03b8.sin, \u03b8.cos] :=\nbegin\n  apply (o.basis_right_angle_rotation x hx).ext,\n  intros i,\n  fin_cases i,\n  { rw matrix.to_lin_self,\n    simp [rotation_apply, fin.sum_univ_succ] },\n  { rw matrix.to_lin_self,\n    simp [rotation_apply, fin.sum_univ_succ, add_comm] },\nend\n\n/-- The determinant of `rotation` (as a linear map) is equal to `1`. -/\n@[simp] lemma det_rotation (\u03b8 : real.angle) :\n  (o.rotation \u03b8).to_linear_map.det = 1 :=\nbegin\n  haveI : nontrivial V :=\n    finite_dimensional.nontrivial_of_finrank_eq_succ (fact.out (finrank \u211d V = 2)),\n  obtain \u27e8x, hx\u27e9 : \u2203 x, x \u2260 (0:V) := exists_ne (0:V),\n  rw o.rotation_eq_matrix_to_lin \u03b8 hx,\n  simpa [sq] using \u03b8.cos_sq_add_sin_sq,\nend\n\n/-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/\n@[simp] lemma linear_equiv_det_rotation (\u03b8 : real.angle) :\n  (o.rotation \u03b8).to_linear_equiv.det = 1 :=\nunits.ext $ o.det_rotation \u03b8\n\n/-- The inverse of `rotation` is rotation by the negation of the angle. -/\n@[simp] lemma rotation_symm (\u03b8 : real.angle) : (o.rotation \u03b8).symm = o.rotation (-\u03b8) :=\nby ext; simp [o.rotation_apply, o.rotation_symm_apply, sub_eq_add_neg]\n\n/-- Rotation by 0 is the identity. -/\n@[simp] lemma rotation_zero : o.rotation 0 = linear_isometry_equiv.refl \u211d V :=\nby ext; simp [rotation]\n\n/-- Rotation by \u03c0 is negation. -/\n@[simp] lemma rotation_pi : o.rotation \u03c0 = linear_isometry_equiv.neg \u211d :=\nbegin\n  ext x,\n  simp [rotation]\nend\n\n/-- Rotation by \u03c0 is negation. -/\nlemma rotation_pi_apply (x : V) : o.rotation \u03c0 x = -x :=\nby simp\n\n/-- Rotation by \u03c0 / 2 is the \"right-angle-rotation\" map `J`. -/\nlemma rotation_pi_div_two : o.rotation (\u03c0 / 2 : \u211d) = J :=\nbegin\n  ext x,\n  simp [rotation],\nend\n\n/-- Rotating twice is equivalent to rotating by the sum of the angles. -/\n@[simp] lemma rotation_rotation (\u03b8\u2081 \u03b8\u2082 : real.angle) (x : V) :\n  o.rotation \u03b8\u2081 (o.rotation \u03b8\u2082 x) = o.rotation (\u03b8\u2081 + \u03b8\u2082) x :=\nbegin\n  simp only [o.rotation_apply, \u2190mul_smul, real.angle.cos_add, real.angle.sin_add, add_smul,\n    sub_smul, linear_isometry_equiv.trans_apply, smul_add, linear_isometry_equiv.map_add,\n    linear_isometry_equiv.map_smul, right_angle_rotation_right_angle_rotation, smul_neg],\n  ring_nf,\n  abel,\nend\n\n/-- Rotating twice is equivalent to rotating by the sum of the angles. -/\n@[simp] lemma rotation_trans (\u03b8\u2081 \u03b8\u2082 : real.angle) :\n  (o.rotation \u03b8\u2081).trans (o.rotation \u03b8\u2082) = o.rotation (\u03b8\u2082 + \u03b8\u2081) :=\nlinear_isometry_equiv.ext $ \u03bb _, by rw [\u2190rotation_rotation, linear_isometry_equiv.trans_apply]\n\n/-- Rotating the first of two vectors by `\u03b8` scales their Kahler form by `cos \u03b8 - sin \u03b8 * I`. -/\n@[simp] lemma kahler_rotation_left (x y : V) (\u03b8 : real.angle) :\n  o.kahler (o.rotation \u03b8 x) y = conj (\u03b8.exp_map_circle : \u2102) * o.kahler x y :=\nbegin\n  simp only [o.rotation_apply, map_add, map_mul, linear_map.map_smul\u209b\u2097, ring_hom.id_apply,\n    linear_map.add_apply, linear_map.smul_apply, real_smul, kahler_right_angle_rotation_left,\n    real.angle.coe_exp_map_circle, is_R_or_C.conj_of_real, conj_I],\n  ring,\nend\n\n/-- Negating a rotation is equivalent to rotation by \u03c0 plus the angle. -/\nlemma neg_rotation (\u03b8 : real.angle) (x : V) : -o.rotation \u03b8 x = o.rotation (\u03c0 + \u03b8) x :=\nby rw [\u2190o.rotation_pi_apply, rotation_rotation]\n\n/-- Negating a rotation by -\u03c0 / 2 is equivalent to rotation by \u03c0 / 2. -/\n@[simp] lemma neg_rotation_neg_pi_div_two (x : V) :\n  -o.rotation (-\u03c0 / 2 : \u211d) x = o.rotation (\u03c0 / 2 : \u211d) x :=\nby rw [neg_rotation, \u2190real.angle.coe_add, neg_div, \u2190sub_eq_add_neg, sub_half]\n\n/-- Negating a rotation by \u03c0 / 2 is equivalent to rotation by -\u03c0 / 2. -/\nlemma neg_rotation_pi_div_two (x : V) : -o.rotation (\u03c0 / 2 : \u211d) x = o.rotation (-\u03c0 / 2 : \u211d) x :=\n(neg_eq_iff_eq_neg.mp $ o.neg_rotation_neg_pi_div_two _).symm\n\n/-- Rotating the first of two vectors by `\u03b8` scales their Kahler form by `cos (-\u03b8) + sin (-\u03b8) * I`.\n-/\nlemma kahler_rotation_left' (x y : V) (\u03b8 : real.angle) :\n  o.kahler (o.rotation \u03b8 x) y = (-\u03b8).exp_map_circle * o.kahler x y :=\nby simpa [coe_inv_circle_eq_conj, -kahler_rotation_left] using o.kahler_rotation_left x y \u03b8\n\n/-- Rotating the second of two vectors by `\u03b8` scales their Kahler form by `cos \u03b8 + sin \u03b8 * I`. -/\n@[simp] lemma kahler_rotation_right (x y : V) (\u03b8 : real.angle) :\n  o.kahler x (o.rotation \u03b8 y) = \u03b8.exp_map_circle * o.kahler x y :=\nbegin\n  simp only [o.rotation_apply, map_add, linear_map.map_smul\u209b\u2097, ring_hom.id_apply, real_smul,\n    kahler_right_angle_rotation_right, real.angle.coe_exp_map_circle],\n  ring,\nend\n\n/-- Rotating the first vector by `\u03b8` subtracts `\u03b8` from the angle between two vectors. -/\n@[simp] lemma oangle_rotation_left {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) (\u03b8 : real.angle) :\n  o.oangle (o.rotation \u03b8 x) y = o.oangle x y - \u03b8 :=\nbegin\n  simp only [oangle, o.kahler_rotation_left'],\n  rw [complex.arg_mul_coe_angle, real.angle.arg_exp_map_circle],\n  { abel },\n  { exact ne_zero_of_mem_circle _ },\n  { exact o.kahler_ne_zero hx hy },\nend\n\n/-- Rotating the second vector by `\u03b8` adds `\u03b8` to the angle between two vectors. -/\n@[simp] lemma oangle_rotation_right {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) (\u03b8 : real.angle) :\n  o.oangle x (o.rotation \u03b8 y) = o.oangle x y + \u03b8 :=\nbegin\n  simp only [oangle, o.kahler_rotation_right],\n  rw [complex.arg_mul_coe_angle, real.angle.arg_exp_map_circle],\n  { abel },\n  { exact ne_zero_of_mem_circle _ },\n  { exact o.kahler_ne_zero hx hy },\nend\n\n/-- The rotation of a vector by `\u03b8` has an angle of `-\u03b8` from that vector. -/\n@[simp] lemma oangle_rotation_self_left {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  o.oangle (o.rotation \u03b8 x) x = -\u03b8 :=\nby simp [hx]\n\n/-- A vector has an angle of `\u03b8` from the rotation of that vector by `\u03b8`. -/\n@[simp] lemma oangle_rotation_self_right {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  o.oangle x (o.rotation \u03b8 x) = \u03b8 :=\nby simp [hx]\n\n/-- Rotating the first vector by the angle between the two vectors results an an angle of 0. -/\n@[simp] lemma oangle_rotation_oangle_left (x y : V) :\n  o.oangle (o.rotation (o.oangle x y) x) y = 0 :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx] },\n  { by_cases hy : y = 0,\n    { simp [hy] },\n    { simp [hx, hy] } }\nend\n\n/-- Rotating the first vector by the angle between the two vectors and swapping the vectors\nresults an an angle of 0. -/\n@[simp] lemma oangle_rotation_oangle_right (x y : V) :\n  o.oangle y (o.rotation (o.oangle x y) x) = 0 :=\nbegin\n  rw [oangle_rev],\n  simp\nend\n\n/-- Rotating both vectors by the same angle does not change the angle between those vectors. -/\n@[simp] lemma oangle_rotation (x y : V) (\u03b8 : real.angle) :\n  o.oangle (o.rotation \u03b8 x) (o.rotation \u03b8 y) = o.oangle x y :=\nbegin\n  by_cases hx : x = 0; by_cases hy : y = 0;\n    simp [hx, hy]\nend\n\n/-- A rotation of a nonzero vector equals that vector if and only if the angle is zero. -/\n@[simp] lemma rotation_eq_self_iff_angle_eq_zero {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  o.rotation \u03b8 x = x \u2194 \u03b8 = 0 :=\nbegin\n  split,\n  { intro h,\n    rw eq_comm,\n    simpa [hx, h] using o.oangle_rotation_right hx hx \u03b8 },\n  { intro h,\n    simp [h] }\nend\n\n/-- A nonzero vector equals a rotation of that vector if and only if the angle is zero. -/\n@[simp] lemma eq_rotation_self_iff_angle_eq_zero {x : V} (hx : x \u2260 0) (\u03b8 : real.angle) :\n  x = o.rotation \u03b8 x \u2194 \u03b8 = 0 :=\nby rw [\u2190o.rotation_eq_self_iff_angle_eq_zero hx, eq_comm]\n\n/-- A rotation of a vector equals that vector if and only if the vector or the angle is zero. -/\nlemma rotation_eq_self_iff (x : V) (\u03b8 : real.angle) :\n  o.rotation \u03b8 x = x \u2194 x = 0 \u2228 \u03b8 = 0 :=\nbegin\n  by_cases h : x = 0;\n    simp [h]\nend\n\n/-- A vector equals a rotation of that vector if and only if the vector or the angle is zero. -/\nlemma eq_rotation_self_iff (x : V) (\u03b8 : real.angle) :\n  x = o.rotation \u03b8 x \u2194 x = 0 \u2228 \u03b8 = 0 :=\nby rw [\u2190rotation_eq_self_iff, eq_comm]\n\n/-- Rotating a vector by the angle to another vector gives the second vector if and only if the\nnorms are equal. -/\n@[simp] lemma rotation_oangle_eq_iff_norm_eq (x y : V) :\n  o.rotation (o.oangle x y) x = y \u2194 \u2016x\u2016 = \u2016y\u2016 :=\nbegin\n  split,\n  { intro h,\n    rw [\u2190h, linear_isometry_equiv.norm_map] },\n  { intro h,\n    rw o.eq_iff_oangle_eq_zero_of_norm_eq;\n      simp [h] }\nend\n\n/-- The angle between two nonzero vectors is `\u03b8` if and only if the second vector is the first\nrotated by `\u03b8` and scaled by the ratio of the norms. -/\nlemma oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0)\n  (\u03b8 : real.angle) : o.oangle x y = \u03b8 \u2194 y = (\u2016y\u2016 / \u2016x\u2016) \u2022 o.rotation \u03b8 x :=\nbegin\n  have hp := div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx),\n  split,\n  { rintro rfl,\n    rw [\u2190linear_isometry_equiv.map_smul, \u2190o.oangle_smul_left_of_pos x y hp,\n        eq_comm, rotation_oangle_eq_iff_norm_eq, norm_smul, real.norm_of_nonneg hp.le,\n        div_mul_cancel _ (norm_ne_zero_iff.2 hx)] },\n  { intro hye,\n    rw [hye, o.oangle_smul_right_of_pos _ _ hp, o.oangle_rotation_self_right hx] }\nend\n\n/-- The angle between two nonzero vectors is `\u03b8` if and only if the second vector is the first\nrotated by `\u03b8` and scaled by a positive real. -/\nlemma oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0)\n  (\u03b8 : real.angle) : o.oangle x y = \u03b8 \u2194 \u2203 r : \u211d, 0 < r \u2227 y = r \u2022 o.rotation \u03b8 x :=\nbegin\n  split,\n  { intro h,\n    rw o.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy at h,\n    exact \u27e8\u2016y\u2016 / \u2016x\u2016, div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx), h\u27e9 },\n  { rintro \u27e8r, hr, rfl\u27e9,\n    rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right hx] }\nend\n\n/-- The angle between two vectors is `\u03b8` if and only if they are nonzero and the second vector\nis the first rotated by `\u03b8` and scaled by the ratio of the norms, or `\u03b8` and at least one of the\nvectors are zero. -/\nlemma oangle_eq_iff_eq_norm_div_norm_smul_rotation_or_eq_zero {x y : V} (\u03b8 : real.angle) :\n  o.oangle x y = \u03b8 \u2194\n    (x \u2260 0 \u2227 y \u2260 0 \u2227 y = (\u2016y\u2016 / \u2016x\u2016) \u2022 o.rotation \u03b8 x) \u2228 (\u03b8 = 0 \u2227 (x = 0 \u2228 y = 0)) :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx, eq_comm] },\n  { by_cases hy : y = 0,\n    { simp [hy, eq_comm] },\n    { rw o.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy,\n      simp [hx, hy] } }\nend\n\n/-- The angle between two vectors is `\u03b8` if and only if they are nonzero and the second vector\nis the first rotated by `\u03b8` and scaled by a positive real, or `\u03b8` and at least one of the\nvectors are zero. -/\nlemma oangle_eq_iff_eq_pos_smul_rotation_or_eq_zero {x y : V} (\u03b8 : real.angle) :\n  o.oangle x y = \u03b8 \u2194\n    (x \u2260 0 \u2227 y \u2260 0 \u2227 \u2203 r : \u211d, 0 < r \u2227 y = r \u2022 o.rotation \u03b8 x) \u2228 (\u03b8 = 0 \u2227 (x = 0 \u2228 y = 0)) :=\nbegin\n  by_cases hx : x = 0,\n  { simp [hx, eq_comm] },\n  { by_cases hy : y = 0,\n    { simp [hy, eq_comm] },\n    { rw o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero hx hy,\n      simp [hx, hy] } }\nend\n\n/-- Any linear isometric equivalence in `V` with positive determinant is `rotation`. -/\nlemma exists_linear_isometry_equiv_eq_of_det_pos {f : V \u2243\u2097\u1d62[\u211d] V}\n  (hd : 0 < (f.to_linear_equiv : V \u2192\u2097[\u211d] V).det) : \u2203 \u03b8 : real.angle, f = o.rotation \u03b8 :=\nbegin\n  haveI : nontrivial V :=\n    finite_dimensional.nontrivial_of_finrank_eq_succ (fact.out (finrank \u211d V = 2)),\n  obtain \u27e8x, hx\u27e9 : \u2203 x, x \u2260 (0:V) := exists_ne (0:V),\n  use o.oangle x (f x),\n  apply linear_isometry_equiv.to_linear_equiv_injective,\n  apply linear_equiv.to_linear_map_injective,\n  apply (o.basis_right_angle_rotation x hx).ext,\n  intros i,\n  symmetry,\n  fin_cases i,\n  { simp },\n  have : o.oangle (J x) (f (J x)) = o.oangle x (f x),\n  { simp only [oangle, o.linear_isometry_equiv_comp_right_angle_rotation f hd,\n      o.kahler_comp_right_angle_rotation] },\n  simp [\u2190 this],\nend\n\nlemma rotation_map (\u03b8 : real.angle) (f : V \u2243\u2097\u1d62[\u211d] V') (x : V') :\n  (orientation.map (fin 2) f.to_linear_equiv o).rotation \u03b8 x\n  = f (o.rotation \u03b8 (f.symm x)) :=\nby simp [rotation_apply, o.right_angle_rotation_map]\n\n@[simp] protected lemma _root_.complex.rotation (\u03b8 : real.angle) (z : \u2102) :\n  complex.orientation.rotation \u03b8 z = \u03b8.exp_map_circle * z :=\nbegin\n  simp only [rotation_apply, complex.right_angle_rotation, real.angle.coe_exp_map_circle,\n    real_smul],\n  ring\nend\n\n/-- Rotation in an oriented real inner product space of dimension 2 can be evaluated in terms of a\ncomplex-number representation of the space. -/\nlemma rotation_map_complex (\u03b8 : real.angle) (f : V \u2243\u2097\u1d62[\u211d] \u2102)\n  (hf : (orientation.map (fin 2) f.to_linear_equiv o) = complex.orientation) (x : V) :\n  f (o.rotation \u03b8 x) = \u03b8.exp_map_circle * f x :=\nbegin\n  rw [\u2190 complex.rotation, \u2190 hf, o.rotation_map],\n  simp,\nend\n\n/-- Negating the orientation negates the angle in `rotation`. -/\nlemma rotation_neg_orientation_eq_neg (\u03b8 : real.angle) :\n  (-o).rotation \u03b8 = o.rotation (-\u03b8) :=\nlinear_isometry_equiv.ext $ by simp [rotation_apply]\n\n/-- The inner product between a `\u03c0 / 2` rotation of a vector and that vector is zero. -/\n@[simp] \n\n/-- The inner product between a vector and a `\u03c0 / 2` rotation of that vector is zero. -/\n@[simp] lemma inner_rotation_pi_div_two_right (x : V) : \u27eax, o.rotation (\u03c0 / 2 : \u211d) x\u27eb = 0 :=\nby rw [real_inner_comm, inner_rotation_pi_div_two_left]\n\n/-- The inner product between a multiple of a `\u03c0 / 2` rotation of a vector and that vector is\nzero. -/\n@[simp] lemma inner_smul_rotation_pi_div_two_left (x : V) (r : \u211d) :\n  \u27ear \u2022 o.rotation (\u03c0 / 2 : \u211d) x, x\u27eb = 0 :=\nby rw [inner_smul_left, inner_rotation_pi_div_two_left, mul_zero]\n\n/-- The inner product between a vector and a multiple of a `\u03c0 / 2` rotation of that vector is\nzero. -/\n@[simp] lemma inner_smul_rotation_pi_div_two_right (x : V) (r : \u211d) :\n  \u27eax, r \u2022 o.rotation (\u03c0 / 2 : \u211d) x\u27eb = 0 :=\nby rw [real_inner_comm, inner_smul_rotation_pi_div_two_left]\n\n/-- The inner product between a `\u03c0 / 2` rotation of a vector and a multiple of that vector is\nzero. -/\n@[simp] lemma inner_rotation_pi_div_two_left_smul (x : V) (r : \u211d) :\n  \u27eao.rotation (\u03c0 / 2 : \u211d) x, r \u2022 x\u27eb = 0 :=\nby rw [inner_smul_right, inner_rotation_pi_div_two_left, mul_zero]\n\n/-- The inner product between a multiple of a vector and a `\u03c0 / 2` rotation of that vector is\nzero. -/\n@[simp] lemma inner_rotation_pi_div_two_right_smul (x : V) (r : \u211d) :\n  \u27ear \u2022 x, o.rotation (\u03c0 / 2 : \u211d) x\u27eb = 0 :=\nby rw [real_inner_comm, inner_rotation_pi_div_two_left_smul]\n\n/-- The inner product between a multiple of a `\u03c0 / 2` rotation of a vector and a multiple of\nthat vector is zero. -/\n@[simp] lemma inner_smul_rotation_pi_div_two_smul_left (x : V) (r\u2081 r\u2082 : \u211d) :\n  \u27ear\u2081 \u2022 o.rotation (\u03c0 / 2 : \u211d) x, r\u2082 \u2022 x\u27eb = 0 :=\nby rw [inner_smul_right, inner_smul_rotation_pi_div_two_left, mul_zero]\n\n/-- The inner product between a multiple of a vector and a multiple of a `\u03c0 / 2` rotation of\nthat vector is zero. -/\n@[simp] lemma inner_smul_rotation_pi_div_two_smul_right (x : V) (r\u2081 r\u2082 : \u211d) :\n  \u27ear\u2082 \u2022 x, r\u2081 \u2022 o.rotation (\u03c0 / 2 : \u211d) x\u27eb = 0 :=\nby rw [real_inner_comm, inner_smul_rotation_pi_div_two_smul_left]\n\n/-- The inner product between two vectors is zero if and only if the first vector is zero or\nthe second is a multiple of a `\u03c0 / 2` rotation of that vector. -/\nlemma inner_eq_zero_iff_eq_zero_or_eq_smul_rotation_pi_div_two {x y : V} :\n  \u27eax, y\u27eb = 0 \u2194 (x = 0 \u2228 \u2203 r : \u211d, r \u2022 o.rotation (\u03c0 / 2 : \u211d) x = y) :=\nbegin\n  rw \u2190o.eq_zero_or_oangle_eq_iff_inner_eq_zero,\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rcases h with rfl | rfl | h | h,\n    { exact or.inl rfl },\n    { exact or.inr \u27e80, zero_smul _ _\u27e9 },\n    { obtain \u27e8r, hr, rfl\u27e9 := (o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero\n        (o.left_ne_zero_of_oangle_eq_pi_div_two h)\n        (o.right_ne_zero_of_oangle_eq_pi_div_two h) _).1 h,\n      exact or.inr \u27e8r, rfl\u27e9 },\n    { obtain \u27e8r, hr, rfl\u27e9 := (o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero\n        (o.left_ne_zero_of_oangle_eq_neg_pi_div_two h)\n        (o.right_ne_zero_of_oangle_eq_neg_pi_div_two h) _).1 h,\n      refine or.inr \u27e8-r, _\u27e9,\n      rw [neg_smul, \u2190smul_neg, o.neg_rotation_pi_div_two] } },\n  { rcases h with rfl | \u27e8r, rfl\u27e9,\n    { exact or.inl rfl },\n    { by_cases hx : x = 0, { exact or.inl hx },\n      rcases lt_trichotomy r 0 with hr | rfl | hr,\n      { refine or.inr (or.inr (or.inr _)),\n        rw [o.oangle_smul_right_of_neg _ _ hr, o.neg_rotation_pi_div_two,\n            o.oangle_rotation_self_right hx] },\n      { exact or.inr (or.inl (zero_smul _ _)) },\n      { refine or.inr (or.inr (or.inl _)),\n        rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right hx] } } }\nend\n\nend orientation\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/angle/oriented/rotation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.7048108835179074}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, Manuel Candales\n-/\nimport geometry.euclidean.angle.oriented.affine\nimport geometry.euclidean.angle.unoriented.affine\nimport tactic.interval_cases\n\n/-!\n# Triangles\n\nThis file proves basic geometrical results about distances and angles\nin (possibly degenerate) triangles in real inner product spaces and\nEuclidean affine spaces.  More specialized results, and results\ndeveloped for simplices in general rather than just for triangles, are\nin separate files.  Definitions and results that make sense in more\ngeneral affine spaces rather than just in the Euclidean case go under\n`linear_algebra.affine_space`.\n\n## Implementation notes\n\nResults in this file are generally given in a form with only those\nnon-degeneracy conditions needed for the particular result, rather\nthan requiring affine independence of the points of a triangle\nunnecessarily.\n\n## References\n\n* https://en.wikipedia.org/wiki/Law_of_cosines\n* https://en.wikipedia.org/wiki/Pons_asinorum\n* https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle\n\n-/\n\nnoncomputable theory\nopen_locale big_operators\nopen_locale classical\nopen_locale real\nopen_locale real_inner_product_space\n\nnamespace inner_product_geometry\n\n/-!\n### Geometrical results on triangles in real inner product spaces\n\nThis section develops some results on (possibly degenerate) triangles\nin real inner product spaces, where those definitions and results can\nmost conveniently be developed in terms of vectors and then used to\ndeduce corresponding results for Euclidean affine spaces.\n-/\n\nvariables {V : Type*} [normed_add_comm_group V] [inner_product_space \u211d V]\n\n/-- Law of cosines (cosine rule), vector angle form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle\n    (x y : V) :\n  \u2016x - y\u2016 * \u2016x - y\u2016 = \u2016x\u2016 * \u2016x\u2016 + \u2016y\u2016 * \u2016y\u2016 - 2 * \u2016x\u2016 * \u2016y\u2016 * real.cos (angle x y) :=\nby rw [(show 2 * \u2016x\u2016 * \u2016y\u2016 * real.cos (angle x y) =\n             2 * (real.cos (angle x y) * (\u2016x\u2016 * \u2016y\u2016)), by ring),\n       cos_angle_mul_norm_mul_norm, \u2190real_inner_self_eq_norm_mul_norm,\n       \u2190real_inner_self_eq_norm_mul_norm, \u2190real_inner_self_eq_norm_mul_norm,\n       real_inner_sub_sub_self, sub_add_eq_add_sub]\n\n/-- Pons asinorum, vector angle form. -/\nlemma angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : \u2016x\u2016 = \u2016y\u2016) :\n  angle x (x - y) = angle y (y - x) :=\nbegin\n  refine real.inj_on_cos \u27e8angle_nonneg _ _, angle_le_pi _ _\u27e9 \u27e8angle_nonneg _ _, angle_le_pi _ _\u27e9 _,\n  rw [cos_angle, cos_angle, h, \u2190neg_sub, norm_neg, neg_sub,\n    inner_sub_right, inner_sub_right, real_inner_self_eq_norm_mul_norm,\n    real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y]\nend\n\n/-- Converse of pons asinorum, vector angle form. -/\nlemma norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V}\n    (h : angle x (x - y) = angle y (y - x)) (hpi : angle x y \u2260 \u03c0) : \u2016x\u2016 = \u2016y\u2016 :=\nbegin\n  replace h := real.arccos_inj_on\n    (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y)))\n    (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h,\n  by_cases hxy : x = y,\n  { rw hxy },\n  { rw [\u2190norm_neg (y - x), neg_sub, mul_comm, mul_comm \u2016y\u2016, div_eq_mul_inv, div_eq_mul_inv,\n        mul_inv_rev, mul_inv_rev, \u2190mul_assoc, \u2190mul_assoc] at h,\n    replace h :=\n      mul_right_cancel\u2080 (inv_ne_zero (\u03bb hz, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz)))) h,\n    rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm,\n        real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib,\n        mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub,\n        \u2190mul_sub_left_distrib] at h,\n    by_cases hx0 : x = 0,\n    { rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h,\n      rw [hx0, norm_zero, h] },\n    { by_cases hy0 : y = 0,\n      { rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h,\n        rw [hy0, norm_zero, h] },\n      { rw [inv_sub_inv (\u03bb hz, hx0 (norm_eq_zero.1 hz)) (\u03bb hz, hy0 (norm_eq_zero.1 hz)),\n            \u2190neg_sub, \u2190mul_div_assoc, mul_comm, mul_div_assoc, \u2190mul_neg_one] at h,\n        symmetry,\n        by_contradiction hyx,\n        replace h := (mul_left_cancel\u2080 (sub_ne_zero_of_ne hyx) h).symm,\n        rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, \u2190angle_eq_pi_iff] at h,\n        exact hpi h } } }\nend\n\n/-- The cosine of the sum of two angles in a possibly degenerate\ntriangle (where two given sides are nonzero), vector angle form. -/\nlemma cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  real.cos (angle x (x - y) + angle y (y - x)) = -real.cos (angle x y) :=\nbegin\n  by_cases hxy : x = y,\n  { rw [hxy, angle_self hy],\n    simp },\n  { rw [real.cos_add, cos_angle, cos_angle, cos_angle],\n    have hxn : \u2016x\u2016 \u2260 0 := (\u03bb h, hx (norm_eq_zero.1 h)),\n    have hyn : \u2016y\u2016 \u2260 0 := (\u03bb h, hy (norm_eq_zero.1 h)),\n    have hxyn : \u2016x - y\u2016 \u2260 0 := (\u03bb h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),\n    apply mul_right_cancel\u2080 hxn,\n    apply mul_right_cancel\u2080 hyn,\n    apply mul_right_cancel\u2080 hxyn,\n    apply mul_right_cancel\u2080 hxyn,\n    have H1 : real.sin (angle x (x - y)) * real.sin (angle y (y - x)) *\n                \u2016x\u2016 * \u2016y\u2016 * \u2016x - y\u2016 * \u2016x - y\u2016 =\n              (real.sin (angle x (x - y)) * (\u2016x\u2016 * \u2016x - y\u2016)) *\n                (real.sin (angle y (y - x)) * (\u2016y\u2016 * \u2016x - y\u2016)), { ring },\n    have H2 : \u27eax, x\u27eb * (\u27eax, x\u27eb - \u27eax, y\u27eb - (\u27eax, y\u27eb - \u27eay, y\u27eb)) -\n                (\u27eax, x\u27eb - \u27eax, y\u27eb) * (\u27eax, x\u27eb - \u27eax, y\u27eb) =\n              \u27eax, x\u27eb * \u27eay, y\u27eb - \u27eax, y\u27eb * \u27eax, y\u27eb, { ring },\n    have H3 : \u27eay, y\u27eb * (\u27eay, y\u27eb - \u27eax, y\u27eb - (\u27eax, y\u27eb - \u27eax, x\u27eb)) -\n                (\u27eay, y\u27eb - \u27eax, y\u27eb) * (\u27eay, y\u27eb - \u27eax, y\u27eb) =\n              \u27eax, x\u27eb * \u27eay, y\u27eb - \u27eax, y\u27eb * \u27eax, y\u27eb, { ring },\n    rw [mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib,\n        mul_sub_right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y,\n        sin_angle_mul_norm_mul_norm, norm_sub_rev y x, inner_sub_left, inner_sub_left,\n        inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H2,\n        H3, real.mul_self_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y)),\n        real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm,\n        real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two],\n    field_simp [hxn, hyn, hxyn],\n    ring }\nend\n\n/-- The sine of the sum of two angles in a possibly degenerate\ntriangle (where two given sides are nonzero), vector angle form. -/\nlemma sin_angle_sub_add_angle_sub_rev_eq_sin_angle {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  real.sin (angle x (x - y) + angle y (y - x)) = real.sin (angle x y) :=\nbegin\n  by_cases hxy : x = y,\n  { rw [hxy, angle_self hy],\n    simp },\n  { rw [real.sin_add, cos_angle, cos_angle],\n    have hxn : \u2016x\u2016 \u2260 0 := (\u03bb h, hx (norm_eq_zero.1 h)),\n    have hyn : \u2016y\u2016 \u2260 0 := (\u03bb h, hy (norm_eq_zero.1 h)),\n    have hxyn : \u2016x - y\u2016 \u2260 0 := (\u03bb h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),\n    apply mul_right_cancel\u2080 hxn,\n    apply mul_right_cancel\u2080 hyn,\n    apply mul_right_cancel\u2080 hxyn,\n    apply mul_right_cancel\u2080 hxyn,\n    have H1 : real.sin (angle x (x - y)) * (\u27eay, y - x\u27eb / (\u2016y\u2016 * \u2016y - x\u2016)) * \u2016x\u2016 * \u2016y\u2016 * \u2016x - y\u2016 =\n                real.sin (angle x (x - y)) * (\u2016x\u2016 * \u2016x - y\u2016) *\n                  (\u27eay, y - x\u27eb / (\u2016y\u2016 * \u2016y - x\u2016)) * \u2016y\u2016, { ring },\n    have H2 : \u27eax, x - y\u27eb / (\u2016x\u2016 * \u2016y - x\u2016) * real.sin (angle y (y - x)) * \u2016x\u2016 * \u2016y\u2016 * \u2016y - x\u2016 =\n                \u27eax, x - y\u27eb / (\u2016x\u2016 * \u2016y - x\u2016) *\n                  (real.sin (angle y (y - x)) * (\u2016y\u2016 * \u2016y - x\u2016)) * \u2016x\u2016, { ring },\n    have H3 : \u27eax, x\u27eb * (\u27eax, x\u27eb - \u27eax, y\u27eb - (\u27eax, y\u27eb - \u27eay, y\u27eb)) -\n                (\u27eax, x\u27eb - \u27eax, y\u27eb) * (\u27eax, x\u27eb - \u27eax, y\u27eb) =\n              \u27eax, x\u27eb * \u27eay, y\u27eb - \u27eax, y\u27eb * \u27eax, y\u27eb, { ring },\n    have H4 : \u27eay, y\u27eb * (\u27eay, y\u27eb - \u27eax, y\u27eb - (\u27eax, y\u27eb - \u27eax, x\u27eb)) -\n                (\u27eay, y\u27eb - \u27eax, y\u27eb) * (\u27eay, y\u27eb - \u27eax, y\u27eb) =\n              \u27eax, x\u27eb * \u27eay, y\u27eb - \u27eax, y\u27eb  * \u27eax, y\u27eb, { ring },\n    rw [right_distrib, right_distrib, right_distrib, right_distrib, H1,\n        sin_angle_mul_norm_mul_norm, norm_sub_rev x y, H2, sin_angle_mul_norm_mul_norm,\n        norm_sub_rev y x, mul_assoc (real.sin (angle x y)), sin_angle_mul_norm_mul_norm,\n        inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right,\n        inner_sub_right, real_inner_comm x y, H3, H4, real_inner_self_eq_norm_mul_norm,\n        real_inner_self_eq_norm_mul_norm,\n        real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two],\n    field_simp [hxn, hyn, hxyn],\n    ring }\nend\n\n/-- The cosine of the sum of the angles of a possibly degenerate\ntriangle (where two given sides are nonzero), vector angle form. -/\nlemma cos_angle_add_angle_sub_add_angle_sub_eq_neg_one {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  real.cos (angle x y + angle x (x - y) + angle y (y - x)) = -1 :=\nby rw [add_assoc, real.cos_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy,\n       sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy, mul_neg, \u2190neg_add',\n       add_comm, \u2190sq, \u2190sq, real.sin_sq_add_cos_sq]\n\n/-- The sine of the sum of the angles of a possibly degenerate\ntriangle (where two given sides are nonzero), vector angle form. -/\nlemma sin_angle_add_angle_sub_add_angle_sub_eq_zero {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  real.sin (angle x y + angle x (x - y) + angle y (y - x)) = 0 :=\nbegin\n  rw [add_assoc, real.sin_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy,\n      sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy],\n  ring\nend\n\n/-- The sum of the angles of a possibly degenerate triangle (where the\ntwo given sides are nonzero), vector angle form. -/\nlemma angle_add_angle_sub_add_angle_sub_eq_pi {x y : V} (hx : x \u2260 0) (hy : y \u2260 0) :\n  angle x y + angle x (x - y) + angle y (y - x) = \u03c0 :=\nbegin\n  have hcos := cos_angle_add_angle_sub_add_angle_sub_eq_neg_one hx hy,\n  have hsin := sin_angle_add_angle_sub_add_angle_sub_eq_zero hx hy,\n  rw real.sin_eq_zero_iff at hsin,\n  cases hsin with n hn,\n  symmetry' at hn,\n  have h0 : 0 \u2264 angle x y + angle x (x - y) + angle y (y - x) :=\n    add_nonneg (add_nonneg (angle_nonneg _ _) (angle_nonneg _ _)) (angle_nonneg _ _),\n  have h3 : angle x y + angle x (x - y) + angle y (y - x) \u2264 \u03c0 + \u03c0 + \u03c0 :=\n    add_le_add (add_le_add (angle_le_pi _ _) (angle_le_pi _ _)) (angle_le_pi _ _),\n  have h3lt : angle x y + angle x (x - y) + angle y (y - x) < \u03c0 + \u03c0 + \u03c0,\n  { by_contradiction hnlt,\n    have hxy : angle x y = \u03c0,\n    { by_contradiction hxy,\n      exact hnlt (add_lt_add_of_lt_of_le (add_lt_add_of_lt_of_le\n                                           (lt_of_le_of_ne (angle_le_pi _ _) hxy)\n                                         (angle_le_pi _ _)) (angle_le_pi _ _)) },\n    rw hxy at hnlt,\n    rw angle_eq_pi_iff at hxy,\n    rcases hxy with \u27e8hx, \u27e8r, \u27e8hr, hxr\u27e9\u27e9\u27e9,\n    rw [hxr, \u2190one_smul \u211d x, \u2190mul_smul, mul_one, \u2190sub_smul, one_smul, sub_eq_add_neg,\n        angle_smul_right_of_pos _ _ (add_pos zero_lt_one (neg_pos_of_neg hr)), angle_self hx,\n        add_zero] at hnlt,\n    apply hnlt,\n    rw add_assoc,\n    exact add_lt_add_left (lt_of_le_of_lt (angle_le_pi _ _)\n                                          (lt_add_of_pos_right \u03c0 real.pi_pos)) _ },\n  have hn0 : 0 \u2264 n,\n  { rw [hn, mul_nonneg_iff_left_nonneg_of_pos real.pi_pos] at h0,\n    norm_cast at h0,\n    exact h0 },\n  have hn3 : n < 3,\n  { rw [hn, (show \u03c0 + \u03c0 + \u03c0 = 3 * \u03c0, by ring)] at h3lt,\n    replace h3lt := lt_of_mul_lt_mul_right h3lt (le_of_lt real.pi_pos),\n    norm_cast at h3lt,\n    exact h3lt },\n  interval_cases n,\n  { rw hn at hcos,\n    simp at hcos,\n    norm_num at hcos },\n  { rw hn,\n    norm_num },\n  { rw hn at hcos,\n    simp at hcos,\n    norm_num at hcos },\nend\n\nend inner_product_geometry\n\nnamespace euclidean_geometry\n/-!\n### Geometrical results on triangles in Euclidean affine spaces\n\nThis section develops some geometrical definitions and results on\n(possible degenerate) triangles in Euclidean affine spaces.\n-/\nopen inner_product_geometry\n\nopen_locale euclidean_geometry\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\ninclude V\n\n/-- **Law of cosines** (cosine rule), angle-at-point form. -/\nlemma dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle\n    (p1 p2 p3 : P) :\n  dist p1 p3 * dist p1 p3 =\n    dist p1 p2 * dist p1 p2 + dist p3 p2 * dist p3 p2 -\n      2 * dist p1 p2 * dist p3 p2 * real.cos (\u2220 p1 p2 p3) :=\nbegin\n  rw [dist_eq_norm_vsub V p1 p3, dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p3 p2],\n  unfold angle,\n  convert norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle\n          (p1 -\u1d65 p2 : V) (p3 -\u1d65 p2 : V),\n  { exact (vsub_sub_vsub_cancel_right p1 p3 p2).symm },\n  { exact (vsub_sub_vsub_cancel_right p1 p3 p2).symm }\nend\n\nalias dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle \u2190 law_cos\n\n/-- **Isosceles Triangle Theorem**: Pons asinorum, angle-at-point form. -/\nlemma angle_eq_angle_of_dist_eq {p1 p2 p3 : P} (h : dist p1 p2 = dist p1 p3) :\n  \u2220 p1 p2 p3 = \u2220 p1 p3 p2 :=\nbegin\n  rw [dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p1 p3] at h,\n  unfold angle,\n  convert angle_sub_eq_angle_sub_rev_of_norm_eq h,\n  { exact (vsub_sub_vsub_cancel_left p3 p2 p1).symm },\n  { exact (vsub_sub_vsub_cancel_left p2 p3 p1).symm }\nend\n\n/-- Converse of pons asinorum, angle-at-point form. -/\nlemma dist_eq_of_angle_eq_angle_of_angle_ne_pi {p1 p2 p3 : P} (h : \u2220 p1 p2 p3 = \u2220 p1 p3 p2)\n    (hpi : \u2220 p2 p1 p3 \u2260 \u03c0) : dist p1 p2 = dist p1 p3 :=\nbegin\n  unfold angle at h hpi,\n  rw [dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p1 p3],\n  rw [\u2190angle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hpi,\n  rw [\u2190vsub_sub_vsub_cancel_left p3 p2 p1, \u2190vsub_sub_vsub_cancel_left p2 p3 p1] at h,\n  exact norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi h hpi\nend\n\n/-- The **sum of the angles of a triangle** (possibly degenerate, where the\ngiven vertex is distinct from the others), angle-at-point. -/\nlemma angle_add_angle_add_angle_eq_pi {p1 p2 p3 : P} (h2 : p2 \u2260 p1) (h3 : p3 \u2260 p1) :\n  \u2220 p1 p2 p3 + \u2220 p2 p3 p1 + \u2220 p3 p1 p2 = \u03c0 :=\nbegin\n  rw [add_assoc, add_comm, add_comm (\u2220 p2 p3 p1), angle_comm p2 p3 p1],\n  unfold angle,\n  rw [\u2190angle_neg_neg (p1 -\u1d65 p3), \u2190angle_neg_neg (p1 -\u1d65 p2), neg_vsub_eq_vsub_rev,\n      neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev,\n      \u2190vsub_sub_vsub_cancel_right p3 p2 p1, \u2190vsub_sub_vsub_cancel_right p2 p3 p1],\n  exact angle_add_angle_sub_add_angle_sub_eq_pi (\u03bb he, h3 (vsub_eq_zero_iff_eq.1 he))\n                                                (\u03bb he, h2 (vsub_eq_zero_iff_eq.1 he))\nend\n\n/-- The **sum of the angles of a triangle** (possibly degenerate, where the triangle is a line),\noriented angles at point. -/\nlemma oangle_add_oangle_add_oangle_eq_pi\n  [module.oriented \u211d V (fin 2)] [fact (finite_dimensional.finrank \u211d V = 2)] {p1 p2 p3 : P}\n  (h21 : p2 \u2260 p1) (h32 : p3 \u2260 p2) (h13 : p1 \u2260 p3) : \u2221 p1 p2 p3 + \u2221 p2 p3 p1 + \u2221 p3 p1 p2 = \u03c0 :=\nby simpa only [neg_vsub_eq_vsub_rev] using\n    positive_orientation.oangle_add_cyc3_neg_left\n      (vsub_ne_zero.mpr h21) (vsub_ne_zero.mpr h32) (vsub_ne_zero.mpr h13)\n\n/-- **Stewart's Theorem**. -/\ntheorem dist_sq_mul_dist_add_dist_sq_mul_dist (a b c p : P) (h : \u2220 b p c = \u03c0) :\n  dist a b ^ 2 * dist c p + dist a c ^ 2 * dist b p =\n  dist b c * (dist a p ^ 2 + dist b p * dist c p) :=\nbegin\n  rw [pow_two, pow_two, law_cos a p b, law_cos a p c,\n      eq_sub_of_add_eq (angle_add_angle_eq_pi_of_angle_eq_pi a h), real.cos_pi_sub,\n      dist_eq_add_dist_of_angle_eq_pi h],\n  ring,\nend\n\n/-- **Apollonius's Theorem**. -/\ntheorem dist_sq_add_dist_sq_eq_two_mul_dist_midpoint_sq_add_half_dist_sq (a b c : P) :\n  dist a b ^ 2 + dist a c ^ 2 = 2 * (dist a (midpoint \u211d b c) ^ 2 + (dist b c / 2) ^ 2) :=\nbegin\n  by_cases hbc : b = c,\n  { simp [hbc, midpoint_self, dist_self, two_mul] },\n  { let m := midpoint \u211d b c,\n    have : dist b c \u2260 0 := (dist_pos.mpr hbc).ne',\n    have hm := dist_sq_mul_dist_add_dist_sq_mul_dist a b c m (angle_midpoint_eq_pi b c hbc),\n    simp only [dist_left_midpoint, dist_right_midpoint, real.norm_two] at hm,\n    calc  dist a b ^ 2 + dist a c ^ 2\n        = 2 / dist b c * (dist a b ^ 2 * (2\u207b\u00b9 * dist b c) + dist a c ^ 2 * (2\u207b\u00b9 * dist b c)) :\n          by { field_simp, ring }\n    ... = 2 * (dist a (midpoint \u211d b c) ^ 2 + (dist b c / 2) ^ 2) :\n          by { rw hm, field_simp, ring } },\nend\n\nlemma dist_mul_of_eq_angle_of_dist_mul (a b c a' b' c' : P) (r : \u211d) (h : \u2220 a' b' c' = \u2220 a b c)\n  (hab : dist a' b' = r * dist a b) (hcb : dist c' b' = r * dist c b) :\n  dist a' c' = r * dist a c :=\nbegin\n  have h' : dist a' c' ^ 2 = (r * dist a c) ^ 2,\n    calc  dist a' c' ^ 2\n        = dist a' b' ^ 2 + dist c' b' ^ 2 - 2 * dist a' b' * dist c' b' * real.cos (\u2220 a' b' c') :\n          by { simp [pow_two, law_cos a' b' c'] }\n    ... = r ^ 2 * (dist a b ^ 2 + dist c b ^ 2 - 2 * dist a b * dist c b * real.cos (\u2220 a b c)) :\n          by { rw [h, hab, hcb], ring }\n    ... = (r * dist a c) ^ 2 : by simp [pow_two, \u2190 law_cos a b c, mul_pow],\n  by_cases hab\u2081 : a = b,\n  { have hab'\u2081 : a' = b', { rw [\u2190 dist_eq_zero, hab, dist_eq_zero.mpr hab\u2081, mul_zero r] },\n    rw [hab\u2081, hab'\u2081, dist_comm b' c', dist_comm b c, hcb] },\n  { have h1 : 0 \u2264 r * dist a b, { rw \u2190 hab, exact dist_nonneg },\n    have h2 : 0 \u2264 r := nonneg_of_mul_nonneg_left h1 (dist_pos.mpr hab\u2081),\n    exact (sq_eq_sq dist_nonneg (mul_nonneg h2 dist_nonneg)).mp h' },\nend\n\nend euclidean_geometry\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/triangle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.704798841385158}}
{"text": "/-\nCopyright (c) 2022 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport data.real.basic -- imports the real numbers\nimport solutions.section02reals.sheet3 -- import the definition of `tendsto` from a previous sheet\n\n-- you can maybe do this one now\ntheorem tendsto_neg {a : \u2115 \u2192 \u211d} {t : \u211d} (ha : tendsto a t) :\n  tendsto (\u03bb n, - a n) (-t) :=\nbegin\n  rw tendsto at *,\n  have q: \u2200n, |a n -  t|=| -a n- -t|,\n  {intro,rw abs_sub_comm,ring_nf,congr' 1,ring,},\n  simpa [q] using ha,\nend\n\n/-\n`tendsto_add` is quite a challenge. In a few weeks' time I'll\nshow you a two-line proof using filters, but right now\nas you're still learning I think it's important that you\ntry and suffer and struggle through the first principles proof.\nBIG piece of advice: write down a complete maths proof first,\nwith all the details there. Then, once you know the maths\nproof, try translating it into Lean. Note that a bunch\nof the results we proved in sheet 4 will be helpful. \n-/\n\n/-- If `a(n)` tends to `t` and `b(n)` tends to `u` then `a(n) + b(n)`\ntends to `t + u`. -/\ntheorem tendsto_add {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (\u03bb n, a n + b n) (t + u) :=\nbegin\n  rw tendsto at *,intros \u03b5 \u03b51,specialize ha (\u03b5/2) (by linarith),specialize hb  (\u03b5/2) (by linarith),\n  cases ha with Ba a,\n  cases hb with Bb b,use max Ba Bb,\n  intros n m, rw max_le_iff at m,cases m,specialize a n m_left,specialize b n m_right,\n  rw abs_lt at *,\n  split;\n  linarith,\nend\n/-- If `a(n)` tends to t and `b(n)` tends to `u` then `a(n) - b(n)`\ntends to `t - u`. -/\ntheorem tendsto_sub {a b : \u2115 \u2192 \u211d} {t u : \u211d}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (\u03bb n, a n - b n) (t - u) :=\nbegin\n  simpa [sub_eq_add_neg] using tendsto_add ha (tendsto_neg hb),\nend\n\n", "meta": {"author": "yakimk", "repo": "lean2022", "sha": "145d03ca2f5a8d2508de05fe78597299051fb8e9", "save_path": "github-repos/lean/yakimk-lean2022", "path": "github-repos/lean/yakimk-lean2022/lean2022-145d03ca2f5a8d2508de05fe78597299051fb8e9/src/section02reals/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7047850428833765}}
{"text": "/- ** Propositions and truth judgments ** -/\n\n/-\nA proposition is a mathematically precise assertion that \nsome state of affairs is true in some domain of interest.\n\nFor example, in the domain of basic arithmetic, the claim\nthat 0 = 0 is a proposition. So is the claim that 0 = 1.\n\nAs another example, in the domain of some family unit, a\nperfectly good proposition is that \"Mary is the mother of\nBob.\" It might or might not be true in a given family,\nbut it's a perfectly good proposition: a claim that a\ncertain state of affairs holds in that domain.\n\nLogic, then, is about making propositions precise and\nabove precise rules for ascertaining when any given \nproposition can be judged to be true.\n\nClearly we would judge the proposition, 0 = 0, to be \ntrue, in the domain of arithmetic. Similarly, we would\nnot judge the proposition 0 = 1 to be true.\n\nLogicians will sometimes write \"0 = 0 : true\" as a\nway to assert that the proposition, 0 = 0, is (has\nbeen judged to be) true. We call this a truth\njudgment. More generally, if P is a proposition, \nthen \"P : true\" denotes the judgment that P is true.\n\nEXERCISE: Write a truth judgment (just type it\nin as part of this comment) for the proposition\nthat \"Mary is the mother of Bob.\"\n\nAnother example of a proposition is the claim that\nzero does not equal one, which we would write like\nthis: \u00ac (0 = 1). You could pronounce this as \"it is\nNOT the case that 0 = 1.\" We would naturally judge\nthis proposition to be true (albeit currently just\nbased on our intuition, not on any specific rules).\n\nEXERCISE: Write a truth judgment here (just type it\nin as part of this comment) that expresses the \njudgement that \u00ac (0 = 1) is true.\n\nPropositions, then, are claims that certain states\nof affairs hold, and logic provides us with rules\nfor determining when a given proposition is (can be\njudged to be) true.\n\nPropositions are basically declarative statements,\nasserting that \"such and such\" is true. What makes\nthem, and logic, formal is that they have a precise \nsyntax, or form, and a precise semantics, or meaning.\n-/\n\n/- * syntax * -/\n\n/-\nJust as with computer programs, there are strict\nrules that define the forms that propositions can\ntake, i.e., their syntax. For example, 0 = 0 is a\nsyntactically well-formed proposition, but 00= is\nnot.\n-/\n\n/- * semantics *-/\n\n/-\nMoreover, propositions in a given logic also have\nmeanings, in that they can be judged to be true,\nor not, in a given domain. For example \"Mary is \nthe mom of Bob\" (perhaps written more formally as\nmother_of(Mary,Bob) is a proposition that can be \njudged to be true in some domains (family units)\nand not true in others. It's true in a domain in\nwhich Mary really is the mother of Bob, and it is\nnot true otherwise. \n\nA proposition cannot generally be judged to be \ntrue or false on its own. Rather, it is judged \nin some domain: under an *interpretation* that \nexplains what each symbol in the proposition is \nmeant  to refer to. \n\nFor example, we could judge \"Mary is the mother \nof Bob\" to be true if and only if \"Mary\" refers \nto some person, \"Bob\" refers to another person, \nand under some definition of what it means to \nbe the mother of, that the person referred to \nas Mary really is the mother of that person \nreferred to as Bob. \n\nWhen we talk about the semantics of a logic, we \nare talking about rules for determining when some\ngiven proposition can be judged to be true with\nrespect to some particular interpretation that\n\"maps\" the symbols in the proposition to things\nin the domain of discourse.\n\nThe rules for determining whether a proposition \nin a particular logic is true in a given such a\ndomain and interpretation is, again, called the \nsemantics of that logic.\n\nLogics thus provide rules that define the syntax\nand the semantics of propositions: their forms,\nand their meanings (that is, whether they are,\ni.e., can be judged to be, true or not) under \nany given interpretation.\n\nWe'll dive deeper into the syntax and semantics \nof various logics as we go along. In particular,\nwe will discuss a simple logic, propositional\nlogic, and a much more useful logic, the logic \nof everyday mathematics and computer science, \ncalled predicate logic.\n\nFor purposes of this unit, we'll just assume \nthat one particular form of valid proposition \nin predicate logic is a proposition that the \nvalues of two terms are equal. For example, \n0 = 0, 1 + 1 = 2, and 1 + 1 = 3 are valid \n(syntactically well formed) propositions in \nthe predicate logic of everyday mathematics\nand computer science.\n\nIn the next section, we'll meet an inference\nrules that from proofs of two propositions,\nsuch as 0 = 0 and 1 = 1, will allow us to\nderive proofs of their conjunctions, e.g.,\nof the proposition that 0 = 0 AND 1 = 1. \n\nIn everyday logical notation, we write this\nas 0 = 0 \u2227 1 = 1. The \u2227 symbol, which is \npronounced \"and\", is the first so-called\nlogical connective that we will meet. The\nlogical connectives allow us to build bigger\npropositions out of smaller onces, and to\nto with each such connective we will have\ninference rules giving us ways to prove\nsuch bigger propositions and to derive\nproofs of other propositions from such\nproofs.\n-/\n\n", "meta": {"author": "kevinsullivan", "repo": "cs-dm", "sha": "bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c", "save_path": "github-repos/lean/kevinsullivan-cs-dm", "path": "github-repos/lean/kevinsullivan-cs-dm/cs-dm-bfd2f5fd2612472e15bd970c7870b5d0dd73bd1c/00_Foundations/01_propositions_and_truth.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7047850348151856}}
{"text": "-- Pruebas_de_length(xs_++_ys)_Ig_length_xs+length_ys.lean\n-- Pruebas de length(xs ++ ys) = length(xs) + length(ys)\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 9 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean est\u00e1n definidas las funciones\n--    length : list \u03b1 \u2192 nat\n--    (++)   : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n-- tales que\n-- + (length xs) es la longitud de xs. Por ejemplo,\n--      length [2,3,5,3] = 4\n-- + (xs ++ ys) es la lista obtenida concatenando xs e ys. Por ejemplo.\n--      [1,2] ++ [2,3,5,3] = [1,2,2,3,5,3]\n-- Dichas funciones est\u00e1n caracterizadas por los siguientes lemas:\n--    length_nil  : length [] = 0\n--    length_cons : length (x :: xs) = length xs + 1\n--    nil_append  : [] ++ ys = ys\n--    cons_append : (x :: xs) ++ y = x :: (xs ++ ys)\n--\n-- Demostrar que\n--    length (xs ++ ys) = length xs + length ys\n-- ---------------------------------------------------------------------\n\nimport tactic\nopen list\n\nvariable  {\u03b1 : Type}\nvariable  (x : \u03b1)\nvariables (xs ys zs : list \u03b1)\n\nlemma length_nil  : length ([] : list \u03b1) = 0 := rfl\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nbegin\n  induction xs with a as HI,\n  { rw nil_append,\n    rw length_nil,\n    rw zero_add, },\n  { rw cons_append,\n    rw length_cons,\n    rw HI,\n    rw length_cons,\n    rw add_assoc,\n    rw add_comm (length ys),\n    rw add_assoc, },\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nbegin\n  induction xs with a as HI,\n  { rw nil_append,\n    rw length_nil,\n    rw zero_add, },\n  { rw cons_append,\n    rw length_cons,\n    rw HI,\n    rw length_cons,\n    -- library_search,\n    exact add_right_comm (length as) (length ys) 1 },\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nbegin\n  induction xs with a as HI,\n  { rw nil_append,\n    rw length_nil,\n    rw zero_add, },\n  { rw cons_append,\n    rw length_cons,\n    rw HI,\n    rw length_cons,\n    -- by hint,\n    linarith, },\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nbegin\n  induction xs with a as HI,\n  { simp, },\n  { simp [HI],\n    linarith, },\nend\n\n-- 5\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nbegin\n  induction xs with a as HI,\n  { simp, },\n  { finish [HI],},\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nby induction xs ; finish [*]\n\n-- 7\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nbegin\n  induction xs with a as HI,\n  { calc length ([] ++ ys)\n         = length ys                    : congr_arg length (nil_append ys)\n     ... = 0 + length ys                : (zero_add (length ys)).symm\n     ... = length [] + length ys        : congr_arg2 (+) length_nil.symm rfl, },\n  { calc length ((a :: as) ++ ys)\n         = length (a :: (as ++ ys))     : congr_arg length (cons_append a as ys)\n     ... = length (as ++ ys) + 1        : length_cons a (as ++ ys)\n     ... = (length as + length ys) + 1  : congr_arg2 (+) HI rfl\n     ... = (length as + 1) + length ys  : add_right_comm (length as) (length ys) 1\n     ... = length (a :: as) + length ys : congr_arg2 (+) (length_cons a as).symm rfl, },\nend\n\n-- 8\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nbegin\n  induction xs with a as HI,\n  { calc length ([] ++ ys)\n         = length ys                    : by rw nil_append\n     ... = 0 + length ys                : (zero_add (length ys)).symm\n     ... = length [] + length ys        : by rw length_nil },\n  { calc length ((a :: as) ++ ys)\n         = length (a :: (as ++ ys))     : by rw cons_append\n     ... = length (as ++ ys) + 1        : by rw length_cons\n     ... = (length as + length ys) + 1  : by rw HI\n     ... = (length as + 1) + length ys  : add_right_comm (length as) (length ys) 1\n     ... = length (a :: as) + length ys : by rw length_cons, },\nend\n\n-- 9\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nlist.rec_on xs\n  ( show length ([] ++ ys) = length [] + length ys, from\n      calc length ([] ++ ys)\n           = length ys                    : by rw nil_append\n       ... = 0 + length ys                : (zero_add (length ys)).symm\n       ... = length [] + length ys        : by rw length_nil )\n  ( assume a as,\n    assume HI : length (as ++ ys) = length as + length ys,\n    show length ((a :: as) ++ ys) = length (a :: as) + length ys, from\n      calc length ((a :: as) ++ ys)\n           = length (a :: (as ++ ys))     : by rw cons_append\n       ... = length (as ++ ys) + 1        : by rw length_cons\n       ... = (length as + length ys) + 1  : by rw HI\n       ... = (length as + 1) + length ys  : add_right_comm (length as) (length ys) 1\n       ... = length (a :: as) + length ys : by rw length_cons)\n\n-- 10\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nlist.rec_on xs\n  ( by simp)\n  ( \u03bb a as HI, by simp [HI, add_right_comm])\n\n-- 11\u00aa demostraci\u00f3n\nlemma longitud_conc_1 :\n  \u2200 xs, length (xs ++ ys) = length xs + length ys\n| [] := by calc\n    length ([] ++ ys)\n        = length ys                    : by rw nil_append\n    ... = 0 + length ys                : by rw zero_add\n    ... = length [] + length ys        : by rw length_nil\n| (a :: as) := by calc\n    length ((a :: as) ++ ys)\n        = length (a :: (as ++ ys))     : by rw cons_append\n    ... = length (as ++ ys) + 1        : by rw length_cons\n    ... = (length as + length ys) + 1  : by rw longitud_conc_1\n    ... = (length as + 1) + length ys  : add_right_comm (length as) (length ys) 1\n    ... = length (a :: as) + length ys : by rw length_cons\n\n-- 12\u00aa demostraci\u00f3n\nlemma longitud_conc_2 :\n  \u2200 xs, length (xs ++ ys) = length xs + length ys\n| []        := by simp\n| (a :: as) := by simp [longitud_conc_2 as, add_right_comm]\n\n-- 13\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\n-- by library_search\nlength_append xs ys\n\n-- 14\u00aa demostraci\u00f3n\nexample :\n  length (xs ++ ys) = length xs + length ys :=\nby simp\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Pruebas_de_length(xs_++_ys)_Ig_length_xs+length_ys.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8670357477770337, "lm_q1q2_score": 0.7047850227648121}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Yury Kudryashov, Ya\u00ebl Dillies\n-/\nimport order.order_dual\n\n/-!\n# Minimal/maximal and bottom/top elements\n\nThis file defines predicates for elements to be minimal/maximal or bottom/top and typeclasses\nsaying that there are no such elements.\n\n## Predicates\n\n* `is_bot`: An element is *bottom* if all elements are greater than it.\n* `is_top`: An element is *top* if all elements are less than it.\n* `is_min`: An element is *minimal* if no element is strictly less than it.\n* `is_max`: An element is *maximal* if no element is strictly greater than it.\n\nSee also `is_bot_iff_is_min` and `is_top_iff_is_max` for the equivalences in a (co)directed order.\n\n## Typeclasses\n\n* `no_bot_order`: An order without bottom elements.\n* `no_top_order`: An order without top elements.\n* `no_min_order`: An order without minimal elements.\n* `no_max_order`: An order without maximal elements.\n-/\n\nopen order_dual\n\nvariables {\u03b1 : Type*}\n\n/-- Order without bottom elements. -/\nclass no_bot_order (\u03b1 : Type*) [has_le \u03b1] : Prop :=\n(exists_not_ge (a : \u03b1) : \u2203 b, \u00ac a \u2264 b)\n\n/-- Order without top elements. -/\nclass no_top_order (\u03b1 : Type*) [has_le \u03b1] : Prop :=\n(exists_not_le (a : \u03b1) : \u2203 b, \u00ac b \u2264 a)\n\n/-- Order without minimal elements. Sometimes called coinitial or dense. -/\nclass no_min_order (\u03b1 : Type*) [has_lt \u03b1] : Prop :=\n(exists_lt (a : \u03b1) : \u2203 b, b < a)\n\n/-- Order without maximal elements. Sometimes called cofinal. -/\nclass no_max_order (\u03b1 : Type*) [has_lt \u03b1] : Prop :=\n(exists_gt (a : \u03b1) : \u2203 b, a < b)\n\nexport no_bot_order (exists_not_ge)\nexport no_top_order (exists_not_le)\nexport no_min_order (exists_lt)\nexport no_max_order (exists_gt)\n\ninstance nonempty_lt [has_lt \u03b1] [no_min_order \u03b1] (a : \u03b1) : nonempty {x // x < a} :=\nnonempty_subtype.2 (exists_lt a)\n\ninstance nonempty_gt [has_lt \u03b1] [no_max_order \u03b1] (a : \u03b1) : nonempty {x // a < x} :=\nnonempty_subtype.2 (exists_gt a)\n\ninstance order_dual.no_bot_order (\u03b1 : Type*) [has_le \u03b1] [no_top_order \u03b1] :\n  no_bot_order (order_dual \u03b1) :=\n\u27e8\u03bb a, @exists_not_le \u03b1 _ _ a\u27e9\n\ninstance order_dual.no_top_order (\u03b1 : Type*) [has_le \u03b1] [no_bot_order \u03b1] :\n  no_top_order (order_dual \u03b1) :=\n\u27e8\u03bb a, @exists_not_ge \u03b1 _ _ a\u27e9\n\ninstance order_dual.no_min_order (\u03b1 : Type*) [has_lt \u03b1] [no_max_order \u03b1] :\n  no_min_order (order_dual \u03b1) :=\n\u27e8\u03bb a, @exists_gt \u03b1 _ _ a\u27e9\n\ninstance order_dual.no_max_order (\u03b1 : Type*) [has_lt \u03b1] [no_min_order \u03b1] :\n  no_max_order (order_dual \u03b1) :=\n\u27e8\u03bb a, @exists_lt \u03b1 _ _ a\u27e9\n\n@[priority 100] -- See note [lower instance priority]\ninstance no_min_order.to_no_bot_order (\u03b1 : Type*) [preorder \u03b1] [no_min_order \u03b1] : no_bot_order \u03b1 :=\n\u27e8\u03bb a, (exists_lt a).imp $ \u03bb _, not_le_of_lt\u27e9\n\n@[priority 100] -- See note [lower instance priority]\ninstance no_max_order.to_no_top_order (\u03b1 : Type*) [preorder \u03b1] [no_max_order \u03b1] : no_top_order \u03b1 :=\n\u27e8\u03bb a, (exists_gt a).imp $ \u03bb _, not_le_of_lt\u27e9\n\nsection has_le\nvariables [has_le \u03b1] {a b : \u03b1}\n\n/-- `a : \u03b1` is a bottom element of `\u03b1` if it is less than or equal to any other element of `\u03b1`.\nThis predicate is roughly an unbundled version of `order_bot`, except that a preorder may have\nseveral bottom elements. When `\u03b1` is linear, this is useful to make a case disjunction on\n`no_min_order \u03b1` within a proof. -/\ndef is_bot (a : \u03b1) : Prop := \u2200 b, a \u2264 b\n\n/-- `a : \u03b1` is a top element of `\u03b1` if it is greater than or equal to any other element of `\u03b1`.\nThis predicate is roughly an unbundled version of `order_bot`, except that a preorder may have\nseveral top elements. When `\u03b1` is linear, this is useful to make a case disjunction on\n`no_max_order \u03b1` within a proof. -/\ndef is_top (a : \u03b1) : Prop := \u2200 b, b \u2264 a\n\n/-- `a` is a minimal element of `\u03b1` if no element is strictly less than it. We spell it without `<`\nto avoid having to convert between `\u2264` and `<`. Instead, `is_min_iff_forall_not_lt` does the\nconversion. -/\ndef is_min (a : \u03b1) : Prop := \u2200 \u2983b\u2984, b \u2264 a \u2192 a \u2264 b\n\n/-- `a` is a maximal element of `\u03b1` if no element is strictly greater than it. We spell it without\n`<` to avoid having to convert between `\u2264` and `<`. Instead, `is_max_iff_forall_not_lt` does the\nconversion. -/\ndef is_max (a : \u03b1) : Prop := \u2200 \u2983b\u2984, a \u2264 b \u2192 b \u2264 a\n\n@[simp] lemma not_is_bot [no_bot_order \u03b1] (a : \u03b1) : \u00acis_bot a :=\n\u03bb h, let \u27e8b, hb\u27e9 := exists_not_ge a in hb $ h _\n\n@[simp] lemma not_is_top [no_top_order \u03b1] (a : \u03b1) : \u00acis_top a :=\n\u03bb h, let \u27e8b, hb\u27e9 := exists_not_le a in hb $ h _\n\nprotected lemma is_bot.is_min (h : is_bot a) : is_min a := \u03bb b _, h b\nprotected lemma is_top.is_max (h : is_top a) : is_max a := \u03bb b _, h b\n\n@[simp] lemma is_bot_to_dual_iff : is_bot (to_dual a) \u2194 is_top a := iff.rfl\n@[simp] lemma is_top_to_dual_iff : is_top (to_dual a) \u2194 is_bot a := iff.rfl\n@[simp] lemma is_min_to_dual_iff : is_min (to_dual a) \u2194 is_max a := iff.rfl\n@[simp] lemma is_max_to_dual_iff : is_max (to_dual a) \u2194 is_min a := iff.rfl\n@[simp] lemma is_bot_of_dual_iff {a : order_dual \u03b1} : is_bot (of_dual a) \u2194 is_top a := iff.rfl\n@[simp] lemma is_top_of_dual_iff {a : order_dual \u03b1} : is_top (of_dual a) \u2194 is_bot a := iff.rfl\n@[simp] lemma is_min_of_dual_iff {a : order_dual \u03b1} : is_min (of_dual a) \u2194 is_max a := iff.rfl\n@[simp] lemma is_max_of_dual_iff {a : order_dual \u03b1} : is_max (of_dual a) \u2194 is_min a := iff.rfl\n\nalias is_bot_to_dual_iff \u2194 _ is_top.to_dual\nalias is_top_to_dual_iff \u2194 _ is_bot.to_dual\nalias is_min_to_dual_iff \u2194 _ is_max.to_dual\nalias is_max_to_dual_iff \u2194 _ is_min.to_dual\nalias is_bot_of_dual_iff \u2194 _ is_top.of_dual\nalias is_top_of_dual_iff \u2194 _ is_bot.of_dual\nalias is_min_of_dual_iff \u2194 _ is_max.of_dual\nalias is_max_of_dual_iff \u2194 _ is_min.of_dual\n\nend has_le\n\nsection preorder\nvariables [preorder \u03b1] {a b : \u03b1}\n\nlemma is_bot.mono (ha : is_bot a) (h : b \u2264 a) : is_bot b := \u03bb c, h.trans $ ha _\nlemma is_top.mono (ha : is_top a) (h : a \u2264 b) : is_top b := \u03bb c, (ha _).trans h\nlemma is_min.mono (ha : is_min a) (h : b \u2264 a) : is_min b := \u03bb c hc, h.trans $ ha $ hc.trans h\nlemma is_max.mono (ha : is_max a) (h : a \u2264 b) : is_max b := \u03bb c hc, (ha $ h.trans hc).trans h\n\nlemma is_min.not_lt (h : is_min a) : \u00ac b < a := \u03bb hb, hb.not_le $ h hb.le\nlemma is_max.not_lt (h : is_max a) : \u00ac a < b := \u03bb hb, hb.not_le $ h hb.le\n\nlemma is_min_iff_forall_not_lt : is_min a \u2194 \u2200 b, \u00ac b < a :=\n\u27e8\u03bb h _, h.not_lt, \u03bb h b hba, of_not_not $ \u03bb hab, h _ $ hba.lt_of_not_le hab\u27e9\n\nlemma is_max_iff_forall_not_lt : is_max a \u2194 \u2200 b, \u00ac a < b :=\n\u27e8\u03bb h _, h.not_lt, \u03bb h b hba, of_not_not $ \u03bb hab, h _ $ hba.lt_of_not_le hab\u27e9\n\n@[simp] lemma not_is_min_iff : \u00ac is_min a \u2194 \u2203 b, b < a :=\nby simp_rw [lt_iff_le_not_le, is_min, not_forall, exists_prop]\n\n@[simp] lemma not_is_max_iff : \u00ac is_max a \u2194 \u2203 b, a < b :=\nby simp_rw [lt_iff_le_not_le, is_max, not_forall, exists_prop]\n\n@[simp] lemma not_is_min [no_min_order \u03b1] (a : \u03b1) : \u00ac is_min a := not_is_min_iff.2 $ exists_lt a\n@[simp] lemma not_is_max [no_max_order \u03b1] (a : \u03b1) : \u00ac is_max a := not_is_max_iff.2 $ exists_gt a\n\nnamespace subsingleton\nvariable [subsingleton \u03b1]\n\nprotected lemma is_bot (a : \u03b1) : is_bot a := \u03bb _, (subsingleton.elim _ _).le\nprotected lemma is_top (a : \u03b1) : is_top a := \u03bb _, (subsingleton.elim _ _).le\nprotected lemma is_min (a : \u03b1) : is_min a := (subsingleton.is_bot _).is_min\nprotected lemma is_max (a : \u03b1) : is_max a := (subsingleton.is_top _).is_max\n\nend subsingleton\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1] {a b : \u03b1}\n\nprotected lemma is_min.eq_of_le (ha : is_min a) (h : b \u2264 a) : b = a := h.antisymm $ ha h\nprotected lemma is_min.eq_of_ge (ha : is_min a) (h : b \u2264 a) : a = b := h.antisymm' $ ha h\nprotected lemma is_max.eq_of_le (ha : is_max a) (h : a \u2264 b) : a = b := h.antisymm $ ha h\nprotected lemma is_max.eq_of_ge (ha : is_max a) (h : a \u2264 b) : b = a := h.antisymm' $ ha h\n\nend partial_order\n\nsection linear_order\nvariables [linear_order \u03b1]\n\n--TODO: Delete in favor of the directed version\nlemma is_top_or_exists_gt (a : \u03b1) : is_top a \u2228 \u2203 b, a < b :=\nby simpa only [or_iff_not_imp_left, is_top, not_forall, not_le] using id\n\nlemma is_bot_or_exists_lt (a : \u03b1) : is_bot a \u2228 \u2203 b, b < a := @is_top_or_exists_gt (order_dual \u03b1) _ a\n\nend linear_order\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/order/max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7047850221959291}}
{"text": "theorem tst0 {p q : Prop } (h : p \u2228 q) : q \u2228 p :=\nby {\n  induction h;\n  { apply Or.inr; assumption };\n  { apply Or.inl; assumption }\n}\n\ntheorem tst0' {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\ninduction h\nfocus\n  apply Or.inr\n  assumption\nfocus\n  apply Or.inl\n  assumption\n\ntheorem tst1 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\ninduction h with\n| inr h2 => exact Or.inl h2\n| inl h1 => exact Or.inr h1\n\ntheorem tst6 {p q : Prop } (h : p \u2228 q) : q \u2228 p :=\nby {\n  cases h with\n  | inr h2 => exact Or.inl h2\n  | inl h1 => exact Or.inr h1\n}\n\ntheorem tst7 {\u03b1 : Type} (xs : List \u03b1) (h : (a : \u03b1) \u2192 (as : List \u03b1) \u2192 xs \u2260 a :: as) : xs = [] :=\nby {\n  induction xs with\n  | nil          => exact rfl\n  | cons z zs ih => exact absurd rfl (h z zs)\n}\n\ntheorem tst8 {\u03b1 : Type} (xs : List \u03b1) (h : (a : \u03b1) \u2192 (as : List \u03b1) \u2192 xs \u2260 a :: as) : xs = [] := by {\n  induction xs;\n  exact rfl;\n  exact absurd rfl $ h _ _\n}\n\ntheorem tst9 {\u03b1 : Type} (xs : List \u03b1) (h : (a : \u03b1) \u2192 (as : List \u03b1) \u2192 xs \u2260 a :: as) : xs = [] := by\n  cases xs with\n     | nil       => exact rfl\n     | cons z zs => exact absurd rfl (h z zs)\n\ntheorem tst10 {p q : Prop } (h\u2081 : p \u2194 q) (h\u2082 : p) : q := by\n  induction h\u2081 with\n  | intro h _ => exact h h\u2082\n\ndef Iff2 (m p q : Prop) := p \u2194 q\n\ntheorem tst11 {p q r : Prop } (h\u2081 : Iff2 r p q) (h\u2082 : p) : q := by\n  induction h\u2081 using Iff.rec with\n  | intro h _ => exact h h\u2082\n\ntheorem tst12 {p q : Prop } (h\u2081 : p \u2228 q) (h\u2082 : p \u2194 q) (h\u2083 : p) : q := by\n  fail_if_success induction h\u2081 using Iff.casesOn\n  induction h\u2082 using Iff.casesOn with\n  | intro h _ =>\n    exact h h\u2083\n\ninductive Tree\n  | leaf\u2081\n  | leaf\u2082\n  | node : Tree \u2192 Tree \u2192 Tree\n\ndef Tree.isLeaf\u2081 : Tree \u2192 Bool\n  | leaf\u2081 => true\n  | _     => false\n\ntheorem tst13 (x : Tree) (h : x = Tree.leaf\u2081) : x.isLeaf\u2081 = true := by\n  cases x with\n  | leaf\u2081 => rfl\n  | _     => injection h\n\ntheorem tst14 (x : Tree) (h : x = Tree.leaf\u2081) : x.isLeaf\u2081 = true := by\n  induction x with\n  | leaf\u2081 => rfl\n  | _     => injection h\n\ninductive Vec (\u03b1 : Type) : Nat \u2192 Type\n  | nil  : Vec \u03b1 0\n  | cons : (a : \u03b1) \u2192 {n : Nat} \u2192 (as : Vec \u03b1 n) \u2192 Vec \u03b1 (n+1)\n\ndef getHeads {\u03b1 \u03b2} {n} (xs : Vec \u03b1 (n+1)) (ys : Vec \u03b2 (n+1)) : \u03b1 \u00d7 \u03b2 := by\n  cases xs\n  cases ys\n  apply Prod.mk\n  repeat\n    trace_state\n    assumption\n  done\n\ntheorem ex1 (n m o : Nat) : n = m + 0 \u2192 m = o \u2192 m = o := by\n  intro (h\u2081 : n = m) h\u2082\n  rw [\u2190 h\u2081, \u2190 h\u2082]\n  assumption\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/induction1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7047825061171594}}
{"text": "import tactic.linarith\nimport tactic.induction\nimport data.nat.basic\nimport data.list.sort\nopen nat\n\n/- This lemma applies the strong induction principle on the lenght of a list. -/\n@[elab_as_eliminator]\nlemma list.strong_length_induction {\u03b1} {C : list \u03b1 \u2192 Sort*}\n  (rec : \u2200 xs : list \u03b1, (\u2200 ys : list \u03b1, ys.length < xs.length \u2192 C ys) \u2192 C xs) :\n  \u2200 xs, C xs\n| xs := rec xs (\u03bb ys len, list.strong_length_induction ys)\nusing_well_founded { rel_tac := \u03bb _ _, `[ exact \u27e8_, measure_wf list.length \u27e9]}\n\n\n/- The function split takes a list \u03b1, splits it and returns the two halves in a tuple. -/\ndef split {\u03b1 : Type} : list \u03b1 \u2192 list \u03b1 \u00d7 list \u03b1\n| xs := (list.take (xs.length/2) xs, list.drop (xs.length/2) xs)\n\n/- This lemma proves that the first split half of a list, using the function split, is smaller in length than the original list. -/\nlemma split_dec_fst {\u03b1 : Type} : \u2200 (x x' : \u03b1) (xs : list \u03b1),\n  (split (x :: x' :: xs)).fst.length < (x :: x' :: xs).length\n:=\nbegin\n  intros x x' xs,\n  simp [split],\n  ring_nf,\n  exact div_lt_self' (xs.length + 1) 0,\nend\n\nlemma split_dec_snd {\u03b1 : Type} : \u2200 (x x' : \u03b1) (xs : list \u03b1), \n  ((split (x :: x' :: xs)).snd).length < ((x :: x' :: xs).length)\n:=\nbegin\n  intros x x' xs,\n  rw split,\n  simp, \n  ring_nf,\n  apply nat.sub_lt_self,\n  linarith,\n  norm_num, \nend\n\n/- This lemma proves that concatenating the two split halves of a list produces \n   a permutation of the original list. -/\nlemma split_preserves {\u03b1 : Type} : \u2200 (xs : list \u03b1), \n  (split xs).fst ++ (split xs).snd ~ xs   \n:=\nbegin\n  intros xs,\n  simp [split]\nend\n\n\n/- The merge function takes two lists and recursively merges them into one ordered list. -/\ndef merge {\u03b1 : Type} (lt : \u03b1 \u2192 \u03b1 \u2192 bool) : list \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| [] a              := a\n| (h1::t1) []       := h1::t1\n| (h1::t1) (h2::t2) :=\n  if lt h1 h2\n    then (h1 :: (merge t1 (h2::t2)))\n    else (h2 :: (merge (h1::t1) t2))\n\n/- This lemma proves that merging two lists together produces a list that is a permutation\n   of the two input lists concatenated together. -/\nlemma merge_preserves {\u03b1 : Type} (lt : \u03b1 \u2192 \u03b1 \u2192 bool) : \u2200 (as bs : list \u03b1),  \n  merge lt as bs ~ as ++ bs   \n| [] bs :=\nbegin\n  rw merge,\n  simp,\nend\n| (a :: as) [] :=\nbegin\n  rw merge,\n  simp,\nend\n| (a :: as) (b :: bs) :=\nbegin\n  rw merge,\n  by_cases hab: (lt a b : Prop),\n  {\n    rw [if_pos hab],\n    simp,\n    apply merge_preserves as (b :: bs), \n  },\n  {\n    rw [if_neg hab],\n    transitivity, \n    swap,\n    {\n      apply list.perm_append_comm,\n    },\n    {\n      simp,\n      transitivity,\n      {\n        apply merge_preserves,\n      },\n      {\n        apply list.perm_append_comm,    \n      }\n    }\n  }\nend\n\n/- The function mergeSort -/\ndef mergeSort {\u03b1 : Type} (lt : \u03b1 -> \u03b1 -> bool) : list \u03b1 \u2192 list \u03b1\n| []             := []\n| [a]            := [a]\n| (a :: b :: xs) :=\n  let p  := split (a :: b :: xs) in\n  let as := p.fst in\n  let bs := p.snd in\n  let h1 : as.length < (a :: b :: xs).length := split_dec_fst _ _ _ in\n  let h2 : bs.length < (a :: b :: xs).length := split_dec_snd _ _ _ in\n  merge lt (mergeSort as) (mergeSort bs)\n  using_well_founded { rel_tac := \u03bb _ _, `[exact \u27e8_, measure_wf list.length\u27e9] }\n\n\n/- This lemma proves that sorting a list using mergeSort produces a permutation \n   of that list. -/\nlemma mergeSort_preserves {\u03b1 : Type} (lt : \u03b1 -> \u03b1 -> bool) : \u2200 (xs : list \u03b1),\n  mergeSort lt xs ~ xs\n:=\nbegin\n  intros unsorted,\n  induction unsorted using list.strong_length_induction with xs ih,\n  simp at ih,\n  cases xs,\n  case nil {\n    rw mergeSort\n  },\n  case cons: x xs {\n    cases xs,\n    case nil {\n      rw mergeSort,\n    },\n    case cons: x' xs {\n      simp [mergeSort],\n      transitivity,\n      {\n        apply merge_preserves,\n      },\n      {\n        transitivity,\n        {\n          apply list.perm.append _ _,\n          swap 3,\n          apply ih,\n          apply split_dec_fst,\n          swap,\n          apply ih,\n          apply split_dec_snd,\n        },\n        {\n          apply split_preserves,\n        }\n      }\n    }, \n  },\nend\n\n\n/- This function transforms function lt to a decidable Prop. -/\ndef r {\u03b1 : Type} (lt : \u03b1 \u2192 \u03b1 \u2192 bool) : \u03b1 \u2192 \u03b1 \u2192 Prop :=\n  \u03bb x y, lt x y = tt\n\n/- This lemma proves that if we merge two lists using merge, all elements of\n   the returned list belonged to either of the two original lists. -/\nlemma element_of_merge {\u03b1 : Type} (lt : \u03b1 \u2192 \u03b1 \u2192 bool): \n \u2200 (x : \u03b1) (as bs: list \u03b1), x \u2208 merge lt as bs \u2192 x \u2208 as \u2228 x \u2208 bs\n| x [] as := \nbegin\n  intros hx,\n  rw merge at hx,\n  tauto,\nend\n| x (a :: as) [] := \nbegin\n  intros has,\n  rw merge at has,\n  tauto,\nend\n| x (a :: as) (b :: bs) :=\nbegin\n  intros hab,\n  rw merge at hab,\n  by_cases hf : (lt a b : Prop), \n  { \n    rw [if_pos hf] at hab,  \n    cases hab, \n    {\n      left,\n      left,\n      exact hab,\n    },\n    {\n      have h' := element_of_merge _ _ _ hab,\n      clear element_of_merge,  \n      cases h',\n      {\n        left,\n        right,\n        exact h',\n      },\n      {\n        right,\n        exact h',\n      }\n    }\n  },\n  {\n    rw [if_neg hf] at hab,\n    cases hab, \n    {\n      right,\n      exact or.inl hab, \n    },\n    {\n      have h' := element_of_merge _ _ _ hab,\n      clear element_of_merge,\n      cases h',\n      {\n        left,\n        exact h',\n      },\n      {\n        right,\n        exact or.inr h',\n      }\n    }\n  },\nend\n\n/- This lemma proves that, given two sorted lists, the list returned by merging \n   the two lists together using merge is sorted as well. -/\nlemma merge_sorted {\u03b1 : Type} (lt : \u03b1 \u2192 \u03b1 \u2192 bool) (tr : transitive (r lt))\n(ng : \u2200 x y, \u00ac r lt y x \u2192 r lt x y) : \u2200 (as bs: list \u03b1), \n  list.sorted (r lt) as \u2192  \n  list.sorted (r lt) bs \u2192 \n  list.sorted (r lt) (merge lt as bs)\n| [] bs :=\n  begin\n    intros hn hbs,\n    rw merge,\n    exact hbs,\n  end\n| (a :: as) [] :=\n  begin\n    intros has hn,\n    rw merge,\n    exact has,\n  end\n| (a :: as) (b :: bs) :=\n  begin\n    intros has hbs,\n    have haq : \u2200 q, q \u2208 as \u2192 r lt a q,\n    {\n      intros q hq,\n      rw list.sorted at has,\n      rw list.pairwise_cons at has,\n      cases has with has_l has_r,\n      apply has_l _ hq,\n    },\n    have hbq : \u2200 q, q \u2208 bs \u2192 r lt b q,\n    {\n      intros q hq,\n      rw list.sorted at hbs,\n      rw list.pairwise_cons at hbs,\n      cases hbs with hbs_l hbs_r,\n      apply hbs_l _ hq, \n    },\n    rw merge,\n    by_cases hf : (lt a b : Prop),\n    {\n      rw [if_pos hf], \n      simp,\n      split, \n      { \n        intros d hm,\n        have had := element_of_merge lt d as (b :: bs) hm,\n        cases had,\n        {\n          rw list.sorted at has,\n          rw list.pairwise_cons at has,\n          cases has with has_l has_r,\n          apply has_l _ had, \n        },\n        {\n          simp at had,\n          cases had,\n          {\n            subst had, \n            exact hf,\n          },\n          {\n            apply tr,\n            {\n              exact hf,\n            },\n            {\n              simp at hbs,\n              cases hbs with hbs_l hbs_r,\n              apply hbs_l,\n              exact had,\n            }\n          }\n        }\n      },\n      {\n        apply merge_sorted,\n        { \n          rw list.sorted at has,\n          cases has with _ _ hpas' hpas,\n          exact hpas,\n        },\n        {\n          exact hbs,\n        }\n      }\n    },\n    {\n      rw [if_neg hf],\n      simp,\n      split,\n      {\n        intros k hk,\n        have hk' := element_of_merge _ _ _ _ hk,\n        cases hk',\n        {\n          cases hk',\n          {\n            subst hk',\n            exact ng b k hf,\n          },\n          {\n            have fak := haq _ hk',\n            have fba := ng _ _ hf,\n            apply tr fba fak,\n          }\n        },\n        {\n          apply hbq _,\n          exact hk',\n        }\n      },\n      {\n        apply merge_sorted,\n        { \n          exact has,\n        },\n        {\n          rw list.sorted at hbs,\n          cases hbs with _ _ hpbs' hpbs,\n          exact hpbs,\n        }\n      }\n    }, \n  end\n\n/- This lemma proves that mergeSort returns a sorted list. -/\nlemma mergeSort_sorts {\u03b1 : Type} (lt : \u03b1 \u2192 \u03b1 \u2192 bool) (tr : transitive (r lt)) \n  (ng : \u2200 x y, \u00ac r lt y x \u2192 r lt x y) : \u2200 (xs : list \u03b1), \n  list.sorted (r lt) (mergeSort lt xs)\n:=\nbegin\n  intros xs,\n  induction xs using list.strong_length_induction with xs ih,\n  simp at ih,\n  cases xs,\n  case nil {\n    simp [mergeSort],\n  },\n  case cons: x xs {\n    cases xs,\n    case nil {\n      simp [mergeSort],\n    },\n    case cons: x' xs {\n      simp [mergeSort],\n      apply merge_sorted lt; try { assumption },\n      {\n        apply ih,\n        apply split_dec_fst,\n      },\n      {\n        apply ih,\n        apply split_dec_snd,\n      }\n    }\n  },\nend\n", "meta": {"author": "Othmanh", "repo": "merge-Sort", "sha": "424433f71e5f87b0a2351ee434901d499d5fc675", "save_path": "github-repos/lean/Othmanh-merge-Sort", "path": "github-repos/lean/Othmanh-merge-Sort/merge-Sort-424433f71e5f87b0a2351ee434901d499d5fc675/src/mergeSort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.704782494593594}}
{"text": "/-\nCopyright (c) 2015 Robert Y. Lewis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Robert Y. Lewis, Jeremy Avigad\n\nThe square root function.\n-/\nimport .ivt\nopen analysis real classical topology\nnoncomputable theory\n\nprivate definition sqr_lb (x : \u211d) : \u211d := 0\n\nprivate theorem sqr_lb_is_lb (x : \u211d) (H : x \u2265 0) : (sqr_lb x) * (sqr_lb x) \u2264 x :=\n  by rewrite [\u2191sqr_lb, zero_mul]; assumption\n\nprivate definition sqr_ub (x : \u211d) : \u211d := x + 1\n\nprivate theorem sqr_ub_is_ub (x : \u211d) (H : x \u2265 0) : (sqr_ub x) * (sqr_ub x) \u2265 x :=\n  begin\n    rewrite [\u2191sqr_ub, left_distrib, mul_one, right_distrib, one_mul, {x + 1}add.comm, -*add.assoc],\n    apply le_add_of_nonneg_left,\n    repeat apply add_nonneg,\n    apply mul_nonneg,\n    repeat assumption,\n    apply zero_le_one\n  end\n\nprivate theorem lb_le_ub (x : \u211d) (H : x \u2265 0) : sqr_lb x \u2264 sqr_ub x :=\n  begin\n    rewrite [\u2191sqr_lb, \u2191sqr_ub],\n    apply add_nonneg,\n    assumption,\n    apply zero_le_one\n  end\n\nprivate lemma sqr_cts : continuous (\u03bb x : \u211d, x * x) := continuous_mul_of_continuous continuous_id continuous_id\n\ndefinition sqrt (x : \u211d) : \u211d :=\n  if H : x \u2265 0 then\n    some (intermediate_value_incr_weak sqr_cts (lb_le_ub x H) (sqr_lb_is_lb x H) (sqr_ub_is_ub x H))\n  else 0\n\nprivate theorem sqrt_spec {x : \u211d} (H : x \u2265 0) : sqrt x * sqrt x = x \u2227 sqrt x \u2265 0 :=\n  begin\n    rewrite [\u2191sqrt, dif_pos H],\n    note Hs := some_spec (intermediate_value_incr_weak sqr_cts (lb_le_ub x H)\n                           (sqr_lb_is_lb x H) (sqr_ub_is_ub x H)),\n    cases Hs with Hs1 Hs2,\n    cases Hs2 with Hs2a Hs2b,\n    exact and.intro Hs2b Hs1\n  end\n\ntheorem sqrt_mul_self {x : \u211d} (H : x \u2265 0) : sqrt x * sqrt x = x := and.left (sqrt_spec H)\n\ntheorem sqrt_nonneg (x : \u211d) : sqrt x \u2265 0 :=\nif H : x \u2265 0 then and.right (sqrt_spec H) else by rewrite [\u2191sqrt, dif_neg H]; exact le.refl 0\n\ntheorem sqrt_squared {x : \u211d} (H : x \u2265 0) : (sqrt x)^2 = x :=\nby krewrite [pow_two, sqrt_mul_self H]\n\ntheorem sqrt_zero : sqrt (0 : \u211d) = 0 :=\nhave sqrt 0 * sqrt 0 = 0, from sqrt_mul_self !le.refl,\nor.elim (eq_zero_or_eq_zero_of_mul_eq_zero this) (\u03bb H, H) (\u03bb H, H)\n\ntheorem sqrt_squared_of_nonneg {x : \u211d} (H : x \u2265 0) : sqrt (x^2) = x :=\nhave sqrt (x^2)^2 = x^2, from sqrt_squared (squared_nonneg x),\neq_of_squared_eq_squared_of_nonneg (sqrt_nonneg (x^2)) H this\n\ntheorem sqrt_squared' (x : \u211d) : sqrt (x^2) = abs x :=\nhave x^2 = (abs x)^2, by krewrite [+pow_two, -abs_mul, abs_mul_self],\nusing this, by rewrite [this, sqrt_squared_of_nonneg (abs_nonneg x)]\n\ntheorem sqrt_mul {x y : \u211d} (Hx : x \u2265 0) (Hy : y \u2265 0) : sqrt (x * y) = sqrt x * sqrt y :=\nhave (sqrt (x * y))^2 = (sqrt x * sqrt y)^2, from calc\n  (sqrt (x * y))^2 = x * y                   : by rewrite [sqrt_squared (mul_nonneg Hx Hy)]\n               ... = (sqrt x)^2 * (sqrt y)^2 : by rewrite [sqrt_squared Hx, sqrt_squared Hy]\n               ... = (sqrt x * sqrt y)^2     : by krewrite [*pow_two]; rewrite [*mul.assoc,\n                                                           mul.left_comm (sqrt y)],\neq_of_squared_eq_squared_of_nonneg !sqrt_nonneg (mul_nonneg !sqrt_nonneg !sqrt_nonneg) this\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/theories/analysis/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7047663744712344}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,\nNeil Strickland, Aaron Anderson\n\n! This file was ported from Lean 3 source module algebra.group_with_zero.divisibility\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.GroupWithZero.Basic\nimport Mathbin.Algebra.Divisibility.Units\n\n/-!\n# Divisibility in groups with zero.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nLemmas about divisibility in groups and monoids with zero.\n\n-/\n\n\nvariable {\u03b1 : Type _}\n\nsection SemigroupWithZero\n\nvariable [SemigroupWithZero \u03b1] {a : \u03b1}\n\n/- warning: eq_zero_of_zero_dvd -> eq_zero_of_zero_dvd is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : SemigroupWithZero.{u1} \u03b1] {a : \u03b1}, (Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 _inst_1)) (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (SemigroupWithZero.toMulZeroClass.{u1} \u03b1 _inst_1))))) a) -> (Eq.{succ u1} \u03b1 a (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (SemigroupWithZero.toMulZeroClass.{u1} \u03b1 _inst_1))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : SemigroupWithZero.{u1} \u03b1] {a : \u03b1}, (Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 _inst_1)) (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (SemigroupWithZero.toZero.{u1} \u03b1 _inst_1))) a) -> (Eq.{succ u1} \u03b1 a (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (SemigroupWithZero.toZero.{u1} \u03b1 _inst_1))))\nCase conversion may be inaccurate. Consider using '#align eq_zero_of_zero_dvd eq_zero_of_zero_dvd\u2093'. -/\ntheorem eq_zero_of_zero_dvd (h : 0 \u2223 a) : a = 0 :=\n  Dvd.elim h fun c H' => H'.trans (MulZeroClass.zero_mul c)\n#align eq_zero_of_zero_dvd eq_zero_of_zero_dvd\n\n/- warning: zero_dvd_iff -> zero_dvd_iff is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : SemigroupWithZero.{u1} \u03b1] {a : \u03b1}, Iff (Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 _inst_1)) (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (SemigroupWithZero.toMulZeroClass.{u1} \u03b1 _inst_1))))) a) (Eq.{succ u1} \u03b1 a (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (SemigroupWithZero.toMulZeroClass.{u1} \u03b1 _inst_1))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : SemigroupWithZero.{u1} \u03b1] {a : \u03b1}, Iff (Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 _inst_1)) (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (SemigroupWithZero.toZero.{u1} \u03b1 _inst_1))) a) (Eq.{succ u1} \u03b1 a (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (SemigroupWithZero.toZero.{u1} \u03b1 _inst_1))))\nCase conversion may be inaccurate. Consider using '#align zero_dvd_iff zero_dvd_iff\u2093'. -/\n/-- Given an element `a` of a commutative semigroup with zero, there exists another element whose\n    product with zero equals `a` iff `a` equals zero. -/\n@[simp]\ntheorem zero_dvd_iff : 0 \u2223 a \u2194 a = 0 :=\n  \u27e8eq_zero_of_zero_dvd, fun h => by\n    rw [h]\n    use 0\n    simp\u27e9\n#align zero_dvd_iff zero_dvd_iff\n\n/- warning: dvd_zero -> dvd_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : SemigroupWithZero.{u1} \u03b1] (a : \u03b1), Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 _inst_1)) a (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (SemigroupWithZero.toMulZeroClass.{u1} \u03b1 _inst_1)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : SemigroupWithZero.{u1} \u03b1] (a : \u03b1), Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 _inst_1)) a (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (SemigroupWithZero.toZero.{u1} \u03b1 _inst_1)))\nCase conversion may be inaccurate. Consider using '#align dvd_zero dvd_zero\u2093'. -/\n@[simp]\ntheorem dvd_zero (a : \u03b1) : a \u2223 0 :=\n  Dvd.intro 0 (by simp)\n#align dvd_zero dvd_zero\n\nend SemigroupWithZero\n\n/- warning: mul_dvd_mul_iff_left -> mul_dvd_mul_iff_left is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CancelMonoidWithZero.{u1} \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1}, (Ne.{succ u1} \u03b1 a (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1)))))))) -> (Iff (Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1)))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toHasMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1))))) a b) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toHasMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1))))) a c)) (Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1)))) b c))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CancelMonoidWithZero.{u1} \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1}, (Ne.{succ u1} \u03b1 a (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (MonoidWithZero.toZero.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1))))) -> (Iff (Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1)))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1))))) a b) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1))))) a c)) (Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CancelMonoidWithZero.toMonoidWithZero.{u1} \u03b1 _inst_1)))) b c))\nCase conversion may be inaccurate. Consider using '#align mul_dvd_mul_iff_left mul_dvd_mul_iff_left\u2093'. -/\n/-- Given two elements `b`, `c` of a `cancel_monoid_with_zero` and a nonzero element `a`,\n `a*b` divides `a*c` iff `b` divides `c`. -/\ntheorem mul_dvd_mul_iff_left [CancelMonoidWithZero \u03b1] {a b c : \u03b1} (ha : a \u2260 0) :\n    a * b \u2223 a * c \u2194 b \u2223 c :=\n  exists_congr fun d => by rw [mul_assoc, mul_right_inj' ha]\n#align mul_dvd_mul_iff_left mul_dvd_mul_iff_left\n\n/- warning: mul_dvd_mul_iff_right -> mul_dvd_mul_iff_right is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CancelCommMonoidWithZero.{u1} \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1}, (Ne.{succ u1} \u03b1 c (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1))))))))) -> (Iff (Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1))))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toHasMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1)))))) a c) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toHasMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1)))))) b c)) (Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1))))) a b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : CancelCommMonoidWithZero.{u1} \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1}, (Ne.{succ u1} \u03b1 c (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (CommMonoidWithZero.toZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1))))) -> (Iff (Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1))))) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1)))))) a c) (HMul.hMul.{u1, u1, u1} \u03b1 \u03b1 \u03b1 (instHMul.{u1} \u03b1 (MulZeroClass.toMul.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1)))))) b c)) (Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 (CommMonoidWithZero.toMonoidWithZero.{u1} \u03b1 (CancelCommMonoidWithZero.toCommMonoidWithZero.{u1} \u03b1 _inst_1))))) a b))\nCase conversion may be inaccurate. Consider using '#align mul_dvd_mul_iff_right mul_dvd_mul_iff_right\u2093'. -/\n/-- Given two elements `a`, `b` of a commutative `cancel_monoid_with_zero` and a nonzero\n  element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/\ntheorem mul_dvd_mul_iff_right [CancelCommMonoidWithZero \u03b1] {a b c : \u03b1} (hc : c \u2260 0) :\n    a * c \u2223 b * c \u2194 a \u2223 b :=\n  exists_congr fun d => by rw [mul_right_comm, mul_left_inj' hc]\n#align mul_dvd_mul_iff_right mul_dvd_mul_iff_right\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero \u03b1]\n\n#print DvdNotUnit /-\n/-- `dvd_not_unit a b` expresses that `a` divides `b` \"strictly\", i.e. that `b` divided by `a`\nis not a unit. -/\ndef DvdNotUnit (a b : \u03b1) : Prop :=\n  a \u2260 0 \u2227 \u2203 x, \u00acIsUnit x \u2227 b = a * x\n#align dvd_not_unit DvdNotUnit\n-/\n\n#print dvdNotUnit_of_dvd_of_not_dvd /-\ntheorem dvdNotUnit_of_dvd_of_not_dvd {a b : \u03b1} (hd : a \u2223 b) (hnd : \u00acb \u2223 a) : DvdNotUnit a b :=\n  by\n  constructor\n  \u00b7 rintro rfl\n    exact hnd (dvd_zero _)\n  \u00b7 rcases hd with \u27e8c, rfl\u27e9\n    refine' \u27e8c, _, rfl\u27e9\n    rintro \u27e8u, rfl\u27e9\n    simpa using hnd\n#align dvd_not_unit_of_dvd_of_not_dvd dvdNotUnit_of_dvd_of_not_dvd\n-/\n\nend CommMonoidWithZero\n\n#print dvd_and_not_dvd_iff /-\ntheorem dvd_and_not_dvd_iff [CancelCommMonoidWithZero \u03b1] {x y : \u03b1} :\n    x \u2223 y \u2227 \u00acy \u2223 x \u2194 DvdNotUnit x y :=\n  \u27e8fun \u27e8\u27e8d, hd\u27e9, hyx\u27e9 =>\n    \u27e8fun hx0 => by simpa [hx0] using hyx,\n      \u27e8d, mt isUnit_iff_dvd_one.1 fun \u27e8e, he\u27e9 => hyx \u27e8e, by rw [hd, mul_assoc, \u2190 he, mul_one]\u27e9,\n        hd\u27e9\u27e9,\n    fun \u27e8hx0, d, hdu, hdx\u27e9 =>\n    \u27e8\u27e8d, hdx\u27e9, fun \u27e8e, he\u27e9 =>\n      hdu\n        (isUnit_of_dvd_one _\n          \u27e8e,\n            mul_left_cancel\u2080 hx0 <| by\n              conv =>\n                  lhs\n                  rw [he, hdx] <;>\n                simp [mul_assoc]\u27e9)\u27e9\u27e9\n#align dvd_and_not_dvd_iff dvd_and_not_dvd_iff\n-/\n\nsection MonoidWithZero\n\nvariable [MonoidWithZero \u03b1]\n\n/- warning: ne_zero_of_dvd_ne_zero -> ne_zero_of_dvd_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : MonoidWithZero.{u1} \u03b1] {p : \u03b1} {q : \u03b1}, (Ne.{succ u1} \u03b1 q (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 _inst_1))))))) -> (Dvd.Dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 _inst_1))) p q) -> (Ne.{succ u1} \u03b1 p (OfNat.ofNat.{u1} \u03b1 0 (OfNat.mk.{u1} \u03b1 0 (Zero.zero.{u1} \u03b1 (MulZeroClass.toHasZero.{u1} \u03b1 (MulZeroOneClass.toMulZeroClass.{u1} \u03b1 (MonoidWithZero.toMulZeroOneClass.{u1} \u03b1 _inst_1)))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : MonoidWithZero.{u1} \u03b1] {p : \u03b1} {q : \u03b1}, (Ne.{succ u1} \u03b1 q (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (MonoidWithZero.toZero.{u1} \u03b1 _inst_1)))) -> (Dvd.dvd.{u1} \u03b1 (semigroupDvd.{u1} \u03b1 (SemigroupWithZero.toSemigroup.{u1} \u03b1 (MonoidWithZero.toSemigroupWithZero.{u1} \u03b1 _inst_1))) p q) -> (Ne.{succ u1} \u03b1 p (OfNat.ofNat.{u1} \u03b1 0 (Zero.toOfNat0.{u1} \u03b1 (MonoidWithZero.toZero.{u1} \u03b1 _inst_1))))\nCase conversion may be inaccurate. Consider using '#align ne_zero_of_dvd_ne_zero ne_zero_of_dvd_ne_zero\u2093'. -/\ntheorem ne_zero_of_dvd_ne_zero {p q : \u03b1} (h\u2081 : q \u2260 0) (h\u2082 : p \u2223 q) : p \u2260 0 :=\n  by\n  rcases h\u2082 with \u27e8u, rfl\u27e9\n  exact left_ne_zero_of_mul h\u2081\n#align ne_zero_of_dvd_ne_zero ne_zero_of_dvd_ne_zero\n\nend MonoidWithZero\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/GroupWithZero/Divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.704766371391396}}
{"text": "/-\nCopyright (c) 2020 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Anatole Dedecker\n-/\nimport topology.separation\n\n/-!\n# Extending a function from a subset\n\nThe main definition of this file is `extend_from A f` where `f : X \u2192 Y`\nand `A : set X`. This defines a new function `g : X \u2192 Y` which maps any\n`x\u2080 : X` to the limit of `f` as `x` tends to `x\u2080`, if such a limit exists.\n\nThis is analoguous to the way `dense_inducing.extend` \"extends\" a function\n`f : X \u2192 Z` to a function `g : Y \u2192 Z` along a dense inducing `i : X \u2192 Y`.\n\nThe main theorem we prove about this definition is `continuous_on_extend_from`\nwhich states that, for `extend_from A f` to be continuous on a set `B \u2286 closure A`,\nit suffices that `f` converges within `A` at any point of `B`, provided that\n`f` is a function to a regular space.\n\n-/\n\nnoncomputable theory\n\nopen_locale topological_space\nopen filter set\n\nvariables {X Y : Type*} [topological_space X] [topological_space Y]\n\n/-- Extend a function from a set `A`. The resulting function `g` is such that\nat any `x\u2080`, if `f` converges to some `y` as `x` tends to `x\u2080` within `A`,\nthen `g x\u2080` is defined to be one of these `y`. Else, `g x\u2080` could be anything. -/\ndef extend_from (A : set X) (f : X \u2192 Y) : X \u2192 Y :=\n\u03bb x, @@lim _ \u27e8f x\u27e9 (\ud835\udcdd[A] x) f\n\n/-- If `f` converges to some `y` as `x` tends to `x\u2080` within `A`,\nthen `f` tends to `extend_from A f x` as `x` tends to `x\u2080`. -/\nlemma tendsto_extend_from {A : set X} {f : X \u2192 Y} {x : X}\n  (h : \u2203 y, tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd $ extend_from A f x) :=\ntendsto_nhds_lim h\n\nlemma extend_from_eq [t2_space Y] {A : set X} {f : X \u2192 Y} {x : X} {y : Y} (hx : x \u2208 closure A)\n  (hf : tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : extend_from A f x = y :=\nbegin\n  haveI := mem_closure_iff_nhds_within_ne_bot.mp hx,\n  exact tendsto_nhds_unique (tendsto_nhds_lim \u27e8y, hf\u27e9) hf,\nend\n\nlemma extend_from_extends [t2_space Y] {f : X \u2192 Y} {A : set X} (hf : continuous_on f A) :\n  \u2200 x \u2208 A, extend_from A f x = f x :=\n\u03bb x x_in, extend_from_eq (subset_closure x_in) (hf x x_in)\n\n/-- If `f` is a function to a regular space `Y` which has a limit within `A` at any\npoint of a set `B \u2286 closure A`, then `extend_from A f` is continuous on `B`. -/\nlemma continuous_on_extend_from [regular_space Y] {f : X \u2192 Y} {A B : set X} (hB : B \u2286 closure A)\n  (hf : \u2200 x \u2208 B, \u2203 y, tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : continuous_on (extend_from A f) B :=\nbegin\n  set \u03c6 := extend_from A f,\n  intros x x_in,\n  suffices : \u2200 V' \u2208 \ud835\udcdd (\u03c6 x), is_closed V' \u2192 \u03c6 \u207b\u00b9' V' \u2208 \ud835\udcdd[B] x,\n    by simpa [continuous_within_at, (closed_nhds_basis _).tendsto_right_iff],\n  intros V' V'_in V'_closed,\n  obtain \u27e8V, V_in, V_op, hV\u27e9 : \u2203 V \u2208 \ud835\udcdd x, is_open V \u2227 V \u2229 A \u2286 f \u207b\u00b9' V',\n  { have := tendsto_extend_from (hf x x_in),\n    rcases (nhds_within_basis_open x A).tendsto_left_iff.mp this V' V'_in with \u27e8V, \u27e8hxV, V_op\u27e9, hV\u27e9,\n    use [V, mem_nhds_sets V_op hxV, V_op, hV] },\n  suffices : \u2200 y \u2208 V \u2229 B, \u03c6 y \u2208 V',\n    from mem_sets_of_superset (inter_mem_inf_sets V_in $ mem_principal_self B) this,\n  rintros y \u27e8hyV, hyB\u27e9,\n  haveI := mem_closure_iff_nhds_within_ne_bot.mp (hB hyB),\n  have limy : tendsto f (\ud835\udcdd[A] y) (\ud835\udcdd $ \u03c6 y) := tendsto_extend_from (hf y hyB),\n  have hVy : V \u2208 \ud835\udcdd y := mem_nhds_sets V_op hyV,\n  have : V \u2229 A \u2208 (\ud835\udcdd[A] y),\n    by simpa [inter_comm] using inter_mem_nhds_within _ hVy,\n  exact V'_closed.mem_of_tendsto limy (mem_sets_of_superset this hV)\nend\n\n/-- If a function `f` to a regular space `Y` has a limit within a\ndense set `A` for any `x`, then `extend_from A f` is continuous. -/\nlemma continuous_extend_from [regular_space Y] {f : X \u2192 Y} {A : set X} (hA : dense A)\n  (hf : \u2200 x, \u2203 y, tendsto f (\ud835\udcdd[A] x) (\ud835\udcdd y)) : continuous (extend_from A f) :=\nbegin\n  rw continuous_iff_continuous_on_univ,\n  exact continuous_on_extend_from (\u03bb x _, hA x) (by simpa using hf)\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/topology/extend_from_subset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7047663688179583}}
{"text": "/-\nCopyright (c) 2021 Yury Kudriashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudriashov, Malo Jaffr\u00e9\n-/\nimport analysis.convex.function\n\n/-!\n# Slopes of convex functions\n\nThis file relates convexity/concavity of functions in a linearly ordered field and the monotonicity\nof their slopes.\n\nThe main use is to show convexity/concavity from monotonicity of the derivative.\n-/\n\nvariables {\ud835\udd5c : Type*} [linear_ordered_field \ud835\udd5c] {s : set \ud835\udd5c} {f : \ud835\udd5c \u2192 \ud835\udd5c}\n\n/-- If `f : \ud835\udd5c \u2192 \ud835\udd5c` is convex, then for any three points `x < y < z` the slope of the secant line of\n`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/\nlemma convex_on.slope_mono_adjacent (hf : convex_on \ud835\udd5c s f)\n  {x y z : \ud835\udd5c} (hx : x \u2208 s) (hz : z \u2208 s) (hxy : x < y) (hyz : y < z) :\n  (f y - f x) / (y - x) \u2264 (f z - f y) / (z - y) :=\nbegin\n  have hxz := hxy.trans hyz,\n  rw \u2190sub_pos at hxy hxz hyz,\n  suffices : f y / (y - x) + f y / (z - y) \u2264 f x / (y - x) + f z / (z - y),\n  { ring_nf at this \u22a2, linarith },\n  set a := (z - y) / (z - x),\n  set b := (y - x) / (z - x),\n  have hy : a \u2022 x + b \u2022 z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },\n  have key, from\n    hf.2 hx hz\n      (show 0 \u2264 a, by apply div_nonneg; linarith)\n      (show 0 \u2264 b, by apply div_nonneg; linarith)\n      (show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith] }),\n  rw hy at key,\n  replace key := mul_le_mul_of_nonneg_left key hxz.le,\n  field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key \u22a2,\n  rw div_le_div_right,\n  { linarith },\n  { nlinarith }\nend\n\n/-- If `f : \ud835\udd5c \u2192 \ud835\udd5c` is concave, then for any three points `x < y < z` the slope of the secant line of\n`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/\nlemma concave_on.slope_anti_adjacent (hf : concave_on \ud835\udd5c s f) {x y z : \ud835\udd5c} (hx : x \u2208 s)\n  (hz : z \u2208 s) (hxy : x < y) (hyz : y < z) :\n  (f z - f y) / (z - y) \u2264 (f y - f x) / (y - x) :=\nbegin\n  rw [\u2190neg_le_neg_iff, \u2190neg_sub_neg (f x), \u2190neg_sub_neg (f y)],\n  simp_rw [\u2190pi.neg_apply, \u2190neg_div, neg_sub],\n  exact convex_on.slope_mono_adjacent hf.neg hx hz hxy hyz,\nend\n\n/-- If `f : \ud835\udd5c \u2192 \ud835\udd5c` is strictly convex, then for any three points `x < y < z` the slope of the\nsecant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on\n`[x, z]`. -/\nlemma strict_convex_on.slope_strict_mono_adjacent (hf : strict_convex_on \ud835\udd5c s f)\n  {x y z : \ud835\udd5c} (hx : x \u2208 s) (hz : z \u2208 s) (hxy : x < y) (hyz : y < z) :\n  (f y - f x) / (y - x) < (f z - f y) / (z - y) :=\nbegin\n  have hxz := hxy.trans hyz,\n  have hxz' := hxz.ne,\n  rw \u2190sub_pos at hxy hxz hyz,\n  suffices : f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y),\n  { ring_nf at this \u22a2, linarith },\n  set a := (z - y) / (z - x),\n  set b := (y - x) / (z - x),\n  have hy : a \u2022 x + b \u2022 z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },\n  have key, from\n    hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)\n      (show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith] }),\n  rw hy at key,\n  replace key := mul_lt_mul_of_pos_left key hxz,\n  field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key \u22a2,\n  rw div_lt_div_right,\n  { linarith },\n  { nlinarith }\nend\n\n/-- If `f : \ud835\udd5c \u2192 \ud835\udd5c` is strictly concave, then for any three points `x < y < z` the slope of the\nsecant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on\n`[x, z]`. -/\nlemma strict_concave_on.slope_anti_adjacent (hf : strict_concave_on \ud835\udd5c s f)\n  {x y z : \ud835\udd5c} (hx : x \u2208 s) (hz : z \u2208 s) (hxy : x < y) (hyz : y < z) :\n  (f z - f y) / (z - y) < (f y - f x) / (y - x) :=\nbegin\n  rw [\u2190neg_lt_neg_iff, \u2190neg_sub_neg (f x), \u2190neg_sub_neg (f y)],\n  simp_rw [\u2190pi.neg_apply, \u2190neg_div, neg_sub],\n  exact strict_convex_on.slope_strict_mono_adjacent hf.neg hx hz hxy hyz,\nend\n\n/-- If for any three points `x < y < z`, the slope of the secant line of `f : \ud835\udd5c \u2192 \ud835\udd5c` on `[x, y]` is\nless than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/\nlemma convex_on_of_slope_mono_adjacent (hs : convex \ud835\udd5c s)\n  (hf : \u2200 {x y z : \ud835\udd5c}, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n    (f y - f x) / (y - x) \u2264 (f z - f y) / (z - y)) :\n  convex_on \ud835\udd5c s f :=\nlinear_order.convex_on_of_lt hs\nbegin\n  assume x z hx hz hxz a b ha hb hab,\n  let y := a * x + b * z,\n  have hxy : x < y,\n  { rw [\u2190 one_mul x, \u2190 hab, add_mul],\n    exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },\n  have hyz : y < z,\n  { rw [\u2190 one_mul z, \u2190 hab, add_mul],\n    exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },\n  have : (f y - f x) * (z - y) \u2264 (f z - f y) * (y - x),\n    from (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),\n  have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),\n  have ha : (z - y) / (z - x) = a,\n  { rw [eq_comm, \u2190 sub_eq_iff_eq_add'] at hab,\n    simp_rw [div_eq_iff hxz.ne', y, \u2190hab], ring },\n  have hb : (y - x) / (z - x) = b,\n  { rw [eq_comm, \u2190 sub_eq_iff_eq_add] at hab,\n    simp_rw [div_eq_iff hxz.ne', y, \u2190hab], ring },\n  rwa [sub_mul, sub_mul, sub_le_iff_le_add', \u2190 add_sub_assoc, le_sub_iff_add_le, \u2190 mul_add,\n    sub_add_sub_cancel, \u2190 le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),\n    mul_comm (f z), ha, hb] at this,\nend\n\n/-- If for any three points `x < y < z`, the slope of the secant line of `f : \ud835\udd5c \u2192 \ud835\udd5c` on `[x, y]` is\ngreater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/\nlemma concave_on_of_slope_anti_adjacent (hs : convex \ud835\udd5c s)\n  (hf : \u2200 {x y z : \ud835\udd5c}, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n    (f z - f y) / (z - y) \u2264 (f y - f x) / (y - x)) : concave_on \ud835\udd5c s f :=\nbegin\n  rw \u2190neg_convex_on_iff,\n  refine convex_on_of_slope_mono_adjacent hs (\u03bb x y z hx hz hxy hyz, _),\n  rw \u2190neg_le_neg_iff,\n  simp_rw [\u2190neg_div, neg_sub, pi.neg_apply, neg_sub_neg],\n  exact hf hx hz hxy hyz,\nend\n\n/-- If for any three points `x < y < z`, the slope of the secant line of `f : \ud835\udd5c \u2192 \ud835\udd5c` on `[x, y]` is\nstrictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/\nlemma strict_convex_on_of_slope_strict_mono_adjacent (hs : convex \ud835\udd5c s)\n  (hf : \u2200 {x y z : \ud835\udd5c}, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n    (f y - f x) / (y - x) < (f z - f y) / (z - y)) :\n  strict_convex_on \ud835\udd5c s f :=\nlinear_order.strict_convex_on_of_lt hs\nbegin\n  assume x z hx hz hxz a b ha hb hab,\n  let y := a * x + b * z,\n  have hxy : x < y,\n  { rw [\u2190 one_mul x, \u2190 hab, add_mul],\n    exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },\n  have hyz : y < z,\n  { rw [\u2190 one_mul z, \u2190 hab, add_mul],\n    exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },\n  have : (f y - f x) * (z - y) < (f z - f y) * (y - x),\n    from (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),\n  have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),\n  have ha : (z - y) / (z - x) = a,\n  { rw [eq_comm, \u2190 sub_eq_iff_eq_add'] at hab,\n    simp_rw [div_eq_iff hxz.ne', y, \u2190hab], ring },\n  have hb : (y - x) / (z - x) = b,\n  { rw [eq_comm, \u2190 sub_eq_iff_eq_add] at hab,\n    simp_rw [div_eq_iff hxz.ne', y, \u2190hab], ring },\n  rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', \u2190 add_sub_assoc, lt_sub_iff_add_lt, \u2190 mul_add,\n    sub_add_sub_cancel, \u2190 lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),\n    mul_comm (f z), ha, hb] at this,\nend\n\n/-- If for any three points `x < y < z`, the slope of the secant line of `f : \ud835\udd5c \u2192 \ud835\udd5c` on `[x, y]` is\nstrictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.\n-/\nlemma strict_concave_on_of_slope_strict_anti_adjacent (hs : convex \ud835\udd5c s)\n  (hf : \u2200 {x y z : \ud835\udd5c}, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n    (f z - f y) / (z - y) < (f y - f x) / (y - x)) : strict_concave_on \ud835\udd5c s f :=\nbegin\n  rw \u2190neg_strict_convex_on_iff,\n  refine strict_convex_on_of_slope_strict_mono_adjacent hs (\u03bb x y z hx hz hxy hyz, _),\n  rw \u2190neg_lt_neg_iff,\n  simp_rw [\u2190neg_div, neg_sub, pi.neg_apply, neg_sub_neg],\n  exact hf hx hz hxy hyz,\nend\n\n/-- A function `f : \ud835\udd5c \u2192 \ud835\udd5c` is convex iff for any three points `x < y < z` the slope of the secant\nline of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/\nlemma convex_on_iff_slope_mono_adjacent :\n  convex_on \ud835\udd5c s f \u2194 convex \ud835\udd5c s \u2227\n    \u2200 \u2983x y z : \ud835\udd5c\u2984, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n      (f y - f x) / (y - x) \u2264 (f z - f y) / (z - y) :=\n\u27e8\u03bb h, \u27e8h.1, \u03bb x y z, h.slope_mono_adjacent\u27e9, \u03bb h, convex_on_of_slope_mono_adjacent h.1 h.2\u27e9\n\n/-- A function `f : \ud835\udd5c \u2192 \ud835\udd5c` is concave iff for any three points `x < y < z` the slope of the secant\nline of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/\nlemma concave_on_iff_slope_anti_adjacent :\n  concave_on \ud835\udd5c s f \u2194 convex \ud835\udd5c s \u2227\n    \u2200 \u2983x y z : \ud835\udd5c\u2984, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n      (f z - f y) / (z - y) \u2264 (f y - f x) / (y - x) :=\n\u27e8\u03bb h, \u27e8h.1, \u03bb x y z, h.slope_anti_adjacent\u27e9, \u03bb h, concave_on_of_slope_anti_adjacent h.1 h.2\u27e9\n\n/-- A function `f : \ud835\udd5c \u2192 \ud835\udd5c` is strictly convex iff for any three points `x < y < z` the slope of\nthe secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on\n`[x, z]`. -/\nlemma strict_convex_on_iff_slope_strict_mono_adjacent :\n  strict_convex_on \ud835\udd5c s f \u2194 convex \ud835\udd5c s \u2227\n    \u2200 \u2983x y z : \ud835\udd5c\u2984, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n      (f y - f x) / (y - x) < (f z - f y) / (z - y) :=\n\u27e8\u03bb h, \u27e8h.1, \u03bb x y z, h.slope_strict_mono_adjacent\u27e9,\n  \u03bb h, strict_convex_on_of_slope_strict_mono_adjacent h.1 h.2\u27e9\n\n/-- A function `f : \ud835\udd5c \u2192 \ud835\udd5c` is strictly concave iff for any three points `x < y < z` the slope of\nthe secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on\n`[x, z]`. -/\nlemma strict_concave_on_iff_slope_strict_anti_adjacent :\n  strict_concave_on \ud835\udd5c s f \u2194 convex \ud835\udd5c s \u2227\n    \u2200 \u2983x y z : \ud835\udd5c\u2984, x \u2208 s \u2192 z \u2208 s \u2192 x < y \u2192 y < z \u2192\n      (f z - f y) / (z - y) < (f y - f x) / (y - x) :=\n\u27e8\u03bb h, \u27e8h.1, \u03bb x y z, h.slope_anti_adjacent\u27e9,\n  \u03bb h, strict_concave_on_of_slope_strict_anti_adjacent h.1 h.2\u27e9\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/convex/slope.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7047663667094879}}
{"text": "import tactic -- for the tactics\nimport ring_theory.ideal.operations -- for the ideals (including product of ideals)\n\n-- universe variable\nuniverse u\n\n-- let R be a ring in universe u\nvariables (R : Type u) [comm_ring R]\n\n-- let V be a vector space over R (i.e. a module over R) (also in universe u)\nvariables (V : Type u) [add_comm_group V] [module R V]\n  \n-- the R-linear identity isomorphism `V \u2243\u2097[R] V`\n#check linear_equiv.refl R V --  V \u2243\u2097[R] V\n\n-- Note that this isn't the true-false statement \"V is isomorphic to V\",\n-- it's the actual identity isomorphism V \u2243 V.\n\nnamespace submodule\n\n-- This function is in Mathlib as of Feb 2022 but\n-- I don't want to change the version of mathlib\n-- in the project, which I made in Jan 2022\n\n/-- A dependent version of `submodule.span_induction`. -/\nlemma span_induction'' {R : Type*} [semiring R] {M : Type*} [add_comm_monoid M] [module R M] \n  {s : set M} {p : \u03a0 x, x \u2208 span R s \u2192 Prop}\n  (Hs : \u2200 x (h : x \u2208 s), p x (subset_span h))\n  (H0 : p 0 (submodule.zero_mem _))\n  (H1 : \u2200 x hx y hy, p x hx \u2192 p y hy \u2192 p (x + y) (submodule.add_mem _ \u2039_\u203a \u2039_\u203a))\n  (H2 : \u2200 (a : R) x hx, p x hx \u2192 p (a \u2022 x) (submodule.smul_mem _ _ \u2039_\u203a)) {x} (hx : x \u2208 span R s) :\n  p x hx :=\nbegin\n  refine exists.elim _ (\u03bb (hx : x \u2208 span R s) (hc : p x hx), hc),\n  refine span_induction hx (\u03bb m hm, \u27e8subset_span hm, Hs m hm\u27e9) \u27e8zero_mem _, H0\u27e9\n    (\u03bb x y hx hy, exists.elim hx $ \u03bb hx' hx, exists.elim hy $ \u03bb hy' hy,\n    \u27e8add_mem _ hx' hy', H1 _ _ _ _ hx hy\u27e9) (\u03bb r x hx, exists.elim hx $ \u03bb hx' hx,\n    \u27e8smul_mem _ _ hx', H2 r _ _ hx\u27e9)\nend\n\nend submodule\n\nnamespace ideal\n\n/-- The equivalence relation \"we're isomorphic as R-modules\" on the ideals of R. -/\ndef s (R : Type u) [comm_ring R] : setoid (ideal R) :=\n{ r := \u03bb I J, nonempty (I \u2243\u2097[R] J),\n  iseqv := begin\n    refine \u27e8_, _, _\u27e9,\n    { intro K,\n      exact nonempty.intro (linear_equiv.refl R K) },\n    { rintros I J \u27e8hIJ\u27e9,\n      exact nonempty.intro hIJ.symm },\n    { rintros I J K \u27e8hIJ\u27e9 \u27e8hJK\u27e9,\n      exact nonempty.intro (hIJ.trans hJK) },\n  end }\n\n-- The below stuff (the next 150 lines seems to be missing from mathlib; it's basic facts about\n-- how isomorphism of ideals plays with multiplication of ideals.\n-- It's quite advanced Lean I guess :-/ (I found it a pain to write)\n\nvariable {R}\n\n/-- The R-linear map `J*I \u2192 K*I` induced by a linear map `e : J \u2192 K` of ideals. -/\ndef linear_map.rmul (I : ideal R) {J K : ideal R} (e : J \u2192\u2097[R] K) :\n  (J * I : ideal R) \u2192\u2097[R] (K * I : ideal R) :=\n{ to_fun := \u03bb x, \u27e8e \u27e8x.1, mul_le_right x.2\u27e9, begin\n    cases x with x hx,\n    have h2 : x \u2208 J := mul_le_right hx,\n    rw (show mul_le_right hx = h2, from rfl),\n    dsimp,\n    rw submodule.mul_eq_span_mul_set at hx,\n    revert h2,\n    refine submodule.span_induction'' _ _ _ _ hx,\n    { rintro x_1 \u27e8r, s, hr, hs, rfl\u27e9 h2,\n      simp only [mul_comm r s, mul_comm K I],\n      convert mul_mem_mul hs (e \u27e8r, hr\u27e9).2,\n      have := e.map_smul s \u27e8r, hr\u27e9,\n      apply_fun subtype.val at this,\n      exact this },\n    { intro _,\n      convert (K * I).zero_mem, -- simp, simp doesn't give an error\n      have := e.map_zero,\n      apply_fun subtype.val at this,\n      exact this },\n    { rintros a ha b hb,\n      rw \u2190 submodule.mul_eq_span_mul_set at ha hb,\n      intros haKI hbKI,\n      have haJ := (mul_le_right ha),\n      have hbJ := (mul_le_right hb),\n      specialize haKI haJ,\n      specialize hbKI hbJ,\n      rintro _,\n      have := e.map_add \u27e8a, haJ\u27e9 \u27e8b, hbJ\u27e9,\n      apply_fun subtype.val at this,\n      convert (K * I).add_mem haKI hbKI },\n    { rintros r b hb,\n      rw \u2190 submodule.mul_eq_span_mul_set at hb,\n      intros hbKI,\n      have hbJ := (mul_le_right hb),\n      specialize hbKI hbJ,\n      rintro _,\n      have := e.map_smul r \u27e8b, hbJ\u27e9,\n      apply_fun subtype.val at this,\n      convert (K * I).smul_mem r hbKI },\n  end\u27e9,\n  map_add' := begin\n    rintros \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n    apply subtype.ext,\n    have := e.map_add \u27e8a, mul_le_right ha\u27e9 \u27e8b, mul_le_right hb\u27e9,\n    apply_fun subtype.val at this,\n    exact this,\n  end,\n  map_smul' := begin\n    rintros r \u27e8a, ha\u27e9,\n    apply subtype.ext,\n    have := e.map_smul r \u27e8a, mul_le_right ha\u27e9,\n    apply_fun subtype.val at this,\n    exact this,\n  end }\n\ndef linear_equiv.rmul (I : ideal R) {J K : ideal R} (e : J \u2243\u2097[R] K) : \n  (J * I : ideal R) \u2243\u2097[R] (K * I : ideal R) :=\n{ inv_fun := linear_map.rmul I e.symm.to_linear_map,\n  left_inv := begin\n    intro x,\n    simp [linear_map.rmul],\n  end,\n  right_inv := begin\n    rintro \u27e8x, hx\u27e9,\n    simp [linear_map.rmul],\n  end,\n  ..linear_map.rmul I e.to_linear_map }\n\ndef linear_map.lmul (I : ideal R) {J K : ideal R} (e : J \u2192\u2097[R] K) : \n  (I * J : ideal R) \u2192\u2097[R] (I * K : ideal R) :=\n{ to_fun := \u03bb x, \u27e8e \u27e8x.1, mul_le_left x.2\u27e9, begin\n    cases x with x hx,\n    have h2 : x \u2208 J := mul_le_left hx,\n    rw (show mul_le_left hx = h2, from rfl),\n    dsimp,\n    rw submodule.mul_eq_span_mul_set at hx,\n    revert h2,\n    refine submodule.span_induction'' _ _ _ _ hx,\n    { rintro x_1 \u27e8r, s, hr, hs, rfl\u27e9 h2,\n      convert mul_mem_mul hr (e \u27e8s, hs\u27e9).2,\n      have := e.map_smul r \u27e8s, hs\u27e9,\n      apply_fun subtype.val at this,\n      exact this },\n    { intro _,\n      convert (I * K).zero_mem, -- simp, simp doesn't give an error\n      have := e.map_zero,\n      apply_fun subtype.val at this,\n      exact this },\n    { rintros a ha b hb,\n      rw \u2190 submodule.mul_eq_span_mul_set at ha hb,\n      intros haKI hbKI,\n      have haJ := (mul_le_left ha),\n      have hbJ := (mul_le_left hb),\n      specialize haKI haJ,\n      specialize hbKI hbJ,\n      rintro _,\n      have := e.map_add \u27e8a, haJ\u27e9 \u27e8b, hbJ\u27e9,\n      apply_fun subtype.val at this,\n      convert (I * K).add_mem haKI hbKI },\n    { rintros r b hb,\n      rw \u2190 submodule.mul_eq_span_mul_set at hb,\n      intros hbKI,\n      have hbJ := (mul_le_left hb),\n      specialize hbKI hbJ,\n      rintro _,\n      have := e.map_smul r \u27e8b, hbJ\u27e9,\n      apply_fun subtype.val at this,\n      convert (I * K).smul_mem r hbKI },\n  end\u27e9,\n  map_add' := begin\n    rintros \u27e8a, ha\u27e9 \u27e8b, hb\u27e9,\n    apply subtype.ext,\n    have := e.map_add \u27e8a, mul_le_left ha\u27e9 \u27e8b, mul_le_left hb\u27e9,\n    apply_fun subtype.val at this,\n    exact this,\n  end,\n  map_smul' := begin\n    rintros r \u27e8a, ha\u27e9,\n    apply subtype.ext,\n    have := e.map_smul r \u27e8a, mul_le_left ha\u27e9,\n    apply_fun subtype.val at this,\n    exact this,\n  end }\n\ndef linear_equiv.lmul (I : ideal R) {J K : ideal R} (e : J \u2243\u2097[R] K) : \n  (I * J : ideal R) \u2243\u2097[R] (I * K : ideal R) :=\n{ inv_fun := linear_map.lmul I e.symm.to_linear_map,\n  left_inv := begin\n    intro x,\n    simp [linear_map.lmul],\n  end,\n  right_inv := begin\n    rintro \u27e8x, hx\u27e9,\n    simp [linear_map.lmul],\n  end,\n  ..linear_map.lmul I e.to_linear_map }\n\nvariable (R)\n\n/-- Being isomorphic is a congruence relation on ideals (i.e., it plays well with `*`) -/\ndef con : con (ideal R) :=\n{ mul' := begin\n    rintros I J K L \u27e8eIJ\u27e9 \u27e8eKL\u27e9,\n    refine \u27e8_\u27e9,\n    refine (ideal.linear_equiv.rmul K eIJ).trans (linear_equiv.lmul J eKL),\n  end,\n  ..ideal.s R }\n\n/-- The ideal-theoretic Picard monoid of a ring, defined as isomorphism classes of ideals. -/\nabbreviation Picard_monoid := (con R).quotient\n\n-- and because we used `con.quotient` the quotient\n-- gets a monoid instance automatically\ninstance : monoid (Picard_monoid R) := infer_instance\n\n/-- The ideal-theoretic definition of the Picard group -/\nabbreviation Picard_group := units (Picard_monoid R)\n\n-- the Picard group of a commutative ring is a group\ninstance : group (ideal.Picard_group R) := by apply_instance \n\nend ideal\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2022", "sha": "af5f176b3b881b7bc0ae89b55befe48c9d4ab790", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2022/formalising-mathematics-2022-af5f176b3b881b7bc0ae89b55befe48c9d4ab790/src/section13picardgroups/idealversion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7047663641360505}}
{"text": "/-\nCopyright (c) 2021 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\nimport algebra.tropical.lattice\nimport algebra.big_operators.basic\nimport data.list.min_max\n\n/-!\n\n# Tropicalization of finitary operations\n\nThis file provides the \"big-op\" or notation-based finitary operations on tropicalized types.\nThis allows easy conversion between sums to Infs and prods to sums. Results here are important\nfor expressing that evaluation of tropical polynomials are the minimum over a finite piecewise\ncollection of linear functions.\n\n## Main declarations\n\n* `untrop_sum`\n\n## Implementation notes\n\nNo concrete (semi)ring is used here, only ones with inferrable order/lattice structure, to support\nreal, rat, ereal, and others (erat is not yet defined).\n\nMinima over `list \u03b1` are defined as producing a value in `with_top \u03b1` so proofs about lists do not\ndirectly transfer to minima over multisets or finsets.\n\n-/\n\n\nopen_locale big_operators\n\nvariables {R S : Type*}\n\nopen tropical finset\n\nlemma list.trop_sum [add_monoid R] (l : list R) : trop l.sum = list.prod (l.map trop) :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simp [\u2190IH] }\nend\n\nlemma multiset.trop_sum [add_comm_monoid R] (s : multiset R) :\n  trop s.sum = multiset.prod (s.map trop) :=\nquotient.induction_on s (by simpa using list.trop_sum)\n\nlemma trop_sum [add_comm_monoid R] (s : finset S) (f : S \u2192 R) :\n  trop (\u2211 i in s, f i) = \u220f i in s, trop (f i) :=\nbegin\n  cases s,\n  convert multiset.trop_sum _,\n  simp\nend\n\nlemma list.untrop_prod [add_monoid R] (l : list (tropical R)) :\n  untrop l.prod = list.sum (l.map untrop) :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simp [\u2190IH] }\nend\n\nlemma multiset.untrop_prod [add_comm_monoid R] (s : multiset (tropical R)) :\n  untrop s.prod = multiset.sum (s.map untrop) :=\nquotient.induction_on s (by simpa using list.untrop_prod)\n\nlemma untrop_prod [add_comm_monoid R] (s : finset S) (f : S \u2192 tropical R) :\n  untrop (\u220f i in s, f i) = \u2211 i in s, untrop (f i) :=\nbegin\n  cases s,\n  convert multiset.untrop_prod _,\n  simp\nend\n\nlemma list.trop_minimum [linear_order R] (l : list R) :\n  trop l.minimum = list.sum (l.map (trop \u2218 coe)) :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simp [list.minimum_cons, \u2190IH] }\nend\n\nlemma multiset.trop_inf [linear_order R] [order_top R] (s : multiset R) :\n  trop s.inf = multiset.sum (s.map trop) :=\nbegin\n  induction s using multiset.induction with s x IH,\n  { simp },\n  { simp [\u2190IH] }\nend\n\nlemma finset.trop_inf [linear_order R] [order_top R] (s : finset S) (f : S \u2192 R) :\n  trop (s.inf f) = \u2211 i in s, trop (f i) :=\nbegin\n  cases s,\n  convert multiset.trop_inf _,\n  simp\nend\n\nlemma trop_Inf_image [conditionally_complete_linear_order R] (s : finset S)\n  (f : S \u2192 with_top R) : trop (Inf (f '' s)) = \u2211 i in s, trop (f i) :=\nbegin\n  rcases s.eq_empty_or_nonempty with rfl|h,\n  { simp only [set.image_empty, coe_empty, sum_empty, with_top.cInf_empty, trop_top] },\n  rw [\u2190inf'_eq_cInf_image _ h, inf'_eq_inf, s.trop_inf],\nend\n\nlemma trop_infi [conditionally_complete_linear_order R] [fintype S] (f : S \u2192 with_top R) :\n  trop (\u2a05 (i : S), f i) = \u2211 (i : S), trop (f i) :=\nby rw [infi, \u2190set.image_univ, \u2190coe_univ, trop_Inf_image]\n\nlemma multiset.untrop_sum [linear_order R] [order_top R] (s : multiset (tropical R)) :\n  untrop s.sum = multiset.inf (s.map untrop) :=\nbegin\n  induction s using multiset.induction with s x IH,\n  { simp },\n  { simpa [\u2190IH] }\nend\n\nlemma finset.untrop_sum' [linear_order R] [order_top R] (s : finset S)\n  (f : S \u2192 tropical R) : untrop (\u2211 i in s, f i) = s.inf (untrop \u2218 f) :=\nbegin\n  cases s,\n  convert multiset.untrop_sum _,\n  simpa\nend\n\nlemma untrop_sum_eq_Inf_image [conditionally_complete_linear_order R] (s : finset S)\n  (f : S \u2192 tropical (with_top R)) :\n  untrop (\u2211 i in s, f i) = Inf (untrop \u2218 f '' s) :=\nbegin\n  rcases s.eq_empty_or_nonempty with rfl|h,\n  { simp only [set.image_empty, coe_empty, sum_empty, with_top.cInf_empty, untrop_zero] },\n  rw [\u2190inf'_eq_cInf_image _ h, inf'_eq_inf, finset.untrop_sum'],\nend\n\nlemma untrop_sum [conditionally_complete_linear_order R] [fintype S]\n  (f : S \u2192 tropical (with_top R)) :\n  untrop (\u2211 i : S, f i) = \u2a05 i : S, untrop (f i) :=\nby rw [infi, \u2190set.image_univ, \u2190coe_univ, untrop_sum_eq_Inf_image]\n\n/-- Note we cannot use `i \u2208 s` instead of `i : s` here\nas it is simply not true on conditionally complete lattices! -/\nlemma finset.untrop_sum [conditionally_complete_linear_order R] (s : finset S)\n  (f : S \u2192 tropical (with_top R)) : untrop (\u2211 i in s, f i) = \u2a05 i : s, untrop (f i) :=\nby simpa [\u2190untrop_sum] using sum_attach.symm\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/algebra/tropical/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.704766363123249}}
{"text": "/-\nCopyright (c) 2020 Patrick Stevens. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Stevens, Yury Kudryashov\n\n! This file was ported from Lean 3 source module number_theory.primorial\n! leanprover-community/mathlib commit 3e32bc908f617039c74c06ea9a897e30c30803c2\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.BigOperators.Associated\nimport Mathbin.Data.Nat.Choose.Sum\nimport Mathbin.Data.Nat.Choose.Dvd\nimport Mathbin.Data.Nat.Parity\nimport Mathbin.Data.Nat.Prime\n\n/-!\n# Primorial\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the primorial function (the product of primes less than or equal to some bound),\nand proves that `primorial n \u2264 4 ^ n`.\n\n## Notations\n\nWe use the local notation `n#` for the primorial of `n`: that is, the product of the primes less\nthan or equal to `n`.\n-/\n\n\nopen Finset\n\nopen Nat\n\nopen BigOperators Nat\n\n#print primorial /-\n/-- The primorial `n#` of `n` is the product of the primes less than or equal to `n`.\n-/\ndef primorial (n : \u2115) : \u2115 :=\n  \u220f p in filter Nat.Prime (range (n + 1)), p\n#align primorial primorial\n-/\n\n-- mathport name: \u00abexpr #\u00bb\nlocal notation x \"#\" => primorial x\n\n#print primorial_pos /-\ntheorem primorial_pos (n : \u2115) : 0 < n# :=\n  prod_pos fun p hp => (mem_filter.1 hp).2.Pos\n#align primorial_pos primorial_pos\n-/\n\n#print primorial_succ /-\ntheorem primorial_succ {n : \u2115} (hn1 : n \u2260 1) (hn : Odd n) : (n + 1)# = n# :=\n  by\n  refine' prod_congr _ fun _ _ => rfl\n  rw [range_succ, filter_insert, if_neg fun h => odd_iff_not_even.mp hn _]\n  exact h.even_sub_one <| mt succ.inj hn1\n#align primorial_succ primorial_succ\n-/\n\n#print primorial_add /-\ntheorem primorial_add (m n : \u2115) :\n    (m + n)# = m# * \u220f p in filter Nat.Prime (Ico (m + 1) (m + n + 1)), p :=\n  by\n  rw [primorial, primorial, \u2190 Ico_zero_eq_range, \u2190 prod_union, \u2190 filter_union, Ico_union_Ico_eq_Ico]\n  exacts[zero_le _, add_le_add_right (Nat.le_add_right _ _) _,\n    disjoint_filter_filter <| Ico_disjoint_Ico_consecutive _ _ _]\n#align primorial_add primorial_add\n-/\n\n#print primorial_add_dvd /-\ntheorem primorial_add_dvd {m n : \u2115} (h : n \u2264 m) : (m + n)# \u2223 m# * choose (m + n) m :=\n  calc\n    (m + n)# = m# * \u220f p in filter Nat.Prime (Ico (m + 1) (m + n + 1)), p := primorial_add _ _\n    _ \u2223 m# * choose (m + n) m :=\n      mul_dvd_mul_left _ <|\n        prod_primes_dvd _ (fun k hk => (mem_filter.1 hk).2.Prime) fun p hp =>\n          by\n          rw [mem_filter, mem_Ico] at hp\n          exact\n            hp.2.dvd_choose_add hp.1.1 (h.trans_lt (m.lt_succ_self.trans_le hp.1.1))\n              (Nat.lt_succ_iff.1 hp.1.2)\n    \n#align primorial_add_dvd primorial_add_dvd\n-/\n\n#print primorial_add_le /-\ntheorem primorial_add_le {m n : \u2115} (h : n \u2264 m) : (m + n)# \u2264 m# * choose (m + n) m :=\n  le_of_dvd (mul_pos (primorial_pos _) (choose_pos <| Nat.le_add_right _ _)) (primorial_add_dvd h)\n#align primorial_add_le primorial_add_le\n-/\n\n#print primorial_le_4_pow /-\ntheorem primorial_le_4_pow (n : \u2115) : n# \u2264 4 ^ n :=\n  by\n  induction' n using Nat.strong_induction_on with n ihn\n  cases n; \u00b7 rfl\n  rcases n.even_or_odd with (\u27e8m, rfl\u27e9 | ho)\n  \u00b7 rcases m.eq_zero_or_pos with (rfl | hm)\n    \u00b7 decide\n    calc\n      (m + m + 1)# = (m + 1 + m)# := by rw [add_right_comm]\n      _ \u2264 (m + 1)# * choose (m + 1 + m) (m + 1) := (primorial_add_le m.le_succ)\n      _ = (m + 1)# * choose (2 * m + 1) m := by rw [choose_symm_add, two_mul, add_right_comm]\n      _ \u2264 4 ^ (m + 1) * 4 ^ m :=\n        (mul_le_mul' (ihn _ <| succ_lt_succ <| (lt_add_iff_pos_left _).2 hm)\n          (choose_middle_le_pow _))\n      _ \u2264 4 ^ (m + m + 1) := by rw [\u2190 pow_add, add_right_comm]\n      \n  \u00b7 rcases Decidable.eq_or_ne n 1 with (rfl | hn)\n    \u00b7 decide\n    \u00b7\n      calc\n        (n + 1)# = n# := primorial_succ hn ho\n        _ \u2264 4 ^ n := (ihn n n.lt_succ_self)\n        _ \u2264 4 ^ (n + 1) := pow_le_pow_of_le_right four_pos n.le_succ\n        \n#align primorial_le_4_pow primorial_le_4_pow\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/NumberTheory/Primorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7047663605498115}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nGiven a finite poset `P`, we define `upper P` to be the set of\nsubsets `U \u2286 P` that are closed upwards.  We order this by \n*reverse* inclusion, to ensure that the map \n`u : p \u21a6 {x : p \u2264 x}` is a morphism of posets.  We prove that\n`upper P` is a bounded distributive lattice with this order.\n-/\n\nimport poset.basic order.bounded order.lattice\n\nuniverses uP uQ uR uS\n\nvariables (P : Type uP) [decidable_eq P] [fintype P]\nvariables [partial_order P] [decidable_rel (has_le.le : P \u2192 P \u2192 Prop)]\n\nnamespace poset\n\nvariable {P}\ndef is_upper : finset P \u2192 Prop := \n \u03bb (U : finset P), \u2200 (p\u2080 p\u2081 : P), (p\u2080 \u2264 p\u2081) \u2192 (p\u2080 \u2208 U) \u2192 (p\u2081 \u2208 U) \nvariable (P)\n\ninstance is_upper_decidable (U : finset P) : decidable (is_upper U) := \n  by { dsimp[is_upper], apply_instance }\n\nlemma is_upper_empty : is_upper (@finset.empty P) := \n \u03bb p\u2080 p\u2081 hp hU, (finset.not_mem_empty p\u2080 hU).elim\n\nlemma is_upper_univ : is_upper (@finset.univ P _) := \n  \u03bb p\u2080 p\u2081 hp hU, (finset.mem_univ p\u2081)\n\nvariable {P}\n\nlemma is_upper_union (U V : finset P) (hU : is_upper U) (hV : is_upper V) : \n  is_upper (U \u222a V) := \n   \u03bb p\u2080 p\u2081 hp hpUV,\n  begin\n   rcases (finset.mem_union.mp hpUV) with hpU | hpV,\n   {exact finset.mem_union_left  V (hU p\u2080 p\u2081 hp hpU)},\n   {exact finset.mem_union_right U (hV p\u2080 p\u2081 hp hpV)},\n  end\n\nlemma is_upper_inter (U V : finset P) (hU : is_upper U) (hV : is_upper V) : \n  is_upper (U \u2229 V) := \n   \u03bb p\u2080 p\u2081 hp hpUV,\n  begin\n   replace hpUV := finset.mem_inter.mp  hpUV,\n   apply finset.mem_inter.mpr,\n   split,\n   {exact (hU p\u2080 p\u2081 hp hpUV.left)},\n   {exact (hV p\u2080 p\u2081 hp hpUV.right)},\n  end\n\ndef distrib (U V W : finset P) : \n U \u2229 (V \u222a W) \u2286 (U \u2229 V) \u222a (U \u2229 W) := \nbegin \n intros A h,\n rw[finset.mem_inter,finset.mem_union] at h,\n rw[finset.mem_union,finset.mem_inter,finset.mem_inter],\n rcases h with \u27e8hU,hV | hW\u27e9,\n exact or.inl \u27e8hU,hV\u27e9,\n exact or.inr \u27e8hU,hW\u27e9\nend\n\nvariable (P)\n\ndef upper := { U : finset P // is_upper U }\n\nnamespace upper \n\ninstance : fintype (upper P) := \nby {dsimp [upper], apply_instance}\n\n/-- To print an upper set, ignore the upperness property and \n  just print the underlying set.\n-/\ninstance [has_repr P] : has_repr (upper P) := \u27e8\u03bb U, repr U.val\u27e9 \n\nvariable {P}\ndef els (U : upper P) : Type* := {p // p \u2208 U.val}\nvariable (P)\n\ninstance els_order (U : upper P) : partial_order U.els := \nby { unfold els, apply_instance }\n\ninstance : has_mem P (upper P) := \u27e8\u03bb p  U, p \u2208 U.val\u27e9 \n\n/-- Two upper sets are equal iff they have the same elements. -/\n@[ext] lemma ext (U\u2080 U\u2081 : upper P) : \n  (\u2200 (p : P), p \u2208 U\u2080 \u2194 p \u2208 U\u2081) \u2192 U\u2080 = U\u2081 := \nbegin\n  intro h, \n  apply subtype.eq,\n  ext p,\n  exact h p\nend\n\n/-- upper P has a natural structure as a bounded distributive lattice. \n-/\ninstance dl : distrib_lattice (upper P) := {\n  le := \u03bb U V, V.val \u2286 U.val,\n  le_refl := \u03bb U, le_refl U.val,\n  le_antisymm := \u03bb U V (h0 : V.val \u2286 U.val) (h1 : U.val \u2286 V.val),\n                   begin apply subtype.eq, exact le_antisymm h1 h0, end,\n  le_trans := \u03bb U V W (h0 : V.val \u2286 U.val) (h1 : W.val \u2286 V.val), \n                 @le_trans (finset P) _ W.val V.val U.val h1 h0,\n  inf := \u03bb U V, \u27e8U.val \u222a V.val,\n                is_upper_union U.val V.val U.property V.property\u27e9,\n  sup := \u03bb U V, \u27e8U.val \u2229 V.val,\n                is_upper_inter U.val V.val U.property V.property\u27e9,\n  le_sup_left  := \u03bb U V,finset.inter_subset_left  U.val V.val,\n  le_sup_right := \u03bb U V,finset.inter_subset_right U.val V.val,\n  sup_le := \u03bb U V W \n             (U_le_W : W.val \u2286 U.val) \n             (V_le_W : W.val \u2286 V.val), \n             finset.subset_inter U_le_W V_le_W,\n  inf_le_left  := \u03bb U V,finset.subset_union_left  U.val V.val,\n  inf_le_right := \u03bb U V,finset.subset_union_right U.val V.val,\n  le_inf := \u03bb U V W \n             (U_le_V : V.val \u2286 U.val) \n             (U_le_W : W.val \u2286 U.val), \n             finset.union_subset U_le_V U_le_W,\n  le_sup_inf := \u03bb U V W A h,\n    distrib U.val V.val W.val h,\n}\n\ninstance bo : bounded_order (upper P) := {\n  bot := \u27e8finset.univ,is_upper_univ P\u27e9,\n  top := \u27e8finset.empty,is_upper_empty P\u27e9,\n  bot_le := \u03bb U,finset.subset_univ U.val,\n  le_top := \u03bb U,finset.empty_subset U.val\n}\n\nvariable {P}\n\nlemma mem_bot (p : P) : p \u2208 (\u22a5 : upper P) := finset.mem_univ p \n\nlemma not_mem_top (p : P) : p \u2209 (\u22a4 : upper P) := finset.not_mem_empty p\n\nlemma mem_inf {U V : upper P} (p : P) : p \u2208 U \u2293 V \u2194 (p \u2208 U \u2228 p \u2208 V) := \n  finset.mem_union\n\nlemma mem_sup {U V : upper P} (p : P) : p \u2208 U \u2294 V \u2194 (p \u2208 U \u2227 p \u2208 V) := \n  finset.mem_inter\n\n/-\n We embed `P` in `upper P` using the map `u : A \u21a6 { B : A \u2286 B }` \n-/\n\ndef u : poset.hom P (upper P) := \n \u27e8\u03bb p, \u27e8finset.univ.filter (\u03bb q, p \u2264 q),\n  begin intros q r hqr hpq,\n   replace hpq := (finset.mem_filter.mp hpq).right,\n   exact finset.mem_filter.mpr \u27e8finset.mem_univ r,le_trans hpq hqr\u27e9,\n  end\n \u27e9, \u03bb p\u2080 p\u2081 h q q_in_up\u2080, \n  begin \n   have : p\u2080 \u2264 q := le_trans h (finset.mem_filter.mp q_in_up\u2080).right, \n   exact finset.mem_filter.mpr \u27e8finset.mem_univ q, this\u27e9\n  end\u27e9\n\nlemma mem_u (p q : P) : p \u2208 (@u P _ _ _ _ q) \u2194 q \u2264 p :=\nbegin\n  change p \u2208 finset.filter _ _ \u2194 q \u2264 p, \n  simp [finset.mem_filter, finset.mem_univ]\nend\n\nend upper\n\nend poset", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/poset/upper.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7047663605498113}}
{"text": "import topology.instances.real\n\n/-!\n# Some helpful lemmas for (products of) intervals.\n-/\n\nvariables {X : Type _} [topological_space X]\n\nlemma frontier_snd_le (a : \u211d) : frontier {x : X \u00d7 \u211d | x.snd \u2264 a} = (set.univ : set X).prod {a} :=\ncalc frontier {x : X \u00d7 \u211d | x.snd \u2264 a} \n      = frontier ((set.univ : set X).prod (set.Iic a)) : \n        congr_arg _ $ by { ext, simp }\n  ... = (set.univ : set X).prod {a} : \n        by rw [frontier_univ_prod_eq, frontier_Iic]\n\nlemma mem_frontier_snd_le (a : \u211d) (y : X \u00d7 \u211d) : y \u2208 frontier {x : X \u00d7 \u211d | x.snd \u2264 a} \u2194 y.2 = a :=\nbegin\n  rw frontier_snd_le,\n  split,\n  { rintros \u27e8-, ha\u27e9,\n    rwa set.mem_singleton_iff at ha },\n  { intro ha,\n    split,\n    { simp },\n    { simp [ha] } }\nend\n\nlemma frontier_fst_le (a : \u211d) : frontier {x : \u211d \u00d7 X | x.fst \u2264 a} = ({a} : set \u211d).prod (set.univ) :=\ncalc frontier {x : \u211d \u00d7 X | x.fst \u2264 a} \n      = frontier ((set.Iic a).prod set.univ) : congr_arg _ $ by { ext, simp }\n  ... = ({a} : set \u211d).prod (set.univ) : by rw [frontier_prod_univ_eq, frontier_Iic]\n\nlemma mem_frontier_fst_le (a : \u211d) (y : \u211d \u00d7 X) : y \u2208 frontier {x : \u211d \u00d7 X | x.fst \u2264 a} \u2194 y.1 = a :=\nbegin\n  rw frontier_fst_le,\n  split,\n  { rintros \u27e8ha, -\u27e9,\n    rwa set.mem_singleton_iff at ha },\n  { intro ha,\n    split,\n    { simp [ha] },\n    { simp } }\nend\n", "meta": {"author": "shingtaklam1324", "repo": "alg-top", "sha": "4c88e28df6f0a329f26eab32bae023789193990e", "save_path": "github-repos/lean/shingtaklam1324-alg-top", "path": "github-repos/lean/shingtaklam1324-alg-top/alg-top-4c88e28df6f0a329f26eab32bae023789193990e/src/intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.704766352323097}}
{"text": "theorem le_of_succ_le_succ (a b : mynat) : succ a \u2264 succ b \u2192 a \u2264 b :=\nbegin\nintro h,\ncases h with d hd,\nuse d,\napply succ_inj,\nrw \u2190 succ_add,\nexact hd,\nend\n", "meta": {"author": "abdelq", "repo": "natural-number-game", "sha": "bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2", "save_path": "github-repos/lean/abdelq-natural-number-game", "path": "github-repos/lean/abdelq-natural-number-game/natural-number-game-bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2/world10/level12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.7047254185401833}}
{"text": "/-\nCopyright (c) 2021 Gabriel Moise. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Gabriel Moise.\n-/\n\nimport data.complex.basic\nimport data.complex.module\nimport data.fintype.basic\nimport data.real.basic\nimport linear_algebra.matrix\n\n/-!\n# Symmetric Matrices\nThis module defines symmetric matrices, together with key properties about their eigenvalues & eigenvectors.\nIt uses a more restrictive definition of eigenvalues & eigenvectors, together with helping lemmas for vector-matrix\noperations and tools for complex numbers/vectors.\nTODO : make the eigen-definitions consistent with the ones already defined in linear_algebra.eigenspace\n## Main definitions\n* `vec_conj x` - the complex conjugate of a complex vector `x`\n* `vec_re x` - the vector containing the real parts of elements from x\n* `vec_im x` - the vector containing the imaginary parts of elements from x\n* `has_eigenpair M \u03bc x` - matrix `M` has non-zero eigenvector `x` with corresponding eigenvalue `\u03bc`\n* `has_eigenvector M x` - matrix `M` has non-zero eigenvector `x`\n* `has_eigenvalue M \u03bc`  - matrix `M` has eigenvalue `\u03bc`\n* `symm_matrix M` - `M` is a symmetric matrix\n## Main statements\n1. If x is an eigenvector of matrix M, then a \u2022 x is an eigenvector of M, for any non-zero a : \u2102.\n2. If there are two eigenvectors of M that have the same correspoding eigenvalue, then any linear combination of them\nis also an eigenvector of M with the same eigenvalue \u03bc.\n3. All eigenvalues of a symmetric real matrix M are real.\n4. For every real eigenvalue of a symmetric matrix M, there exists a corresponding real-valued eigenvector.\n5. If v and w are eigenvectors of a symmetric matrix M with different eigenvalues, then v and w are orthogonal.\n## References\n<https://www.doc.ic.ac.uk/~ae/papers/lecture05.pdf>\n<https://sharmaeklavya2.github.io/theoremdep/nodes/linear-algebra/eigenvectors/real-matrix-with-real-eigenvalue-has-real-eigenvectors.html>\n-/\n\nopen_locale matrix big_operators complex_conjugate\nopen fintype finset matrix complex\n\nset_option trace.simplify.rewrite true\n\nuniverses u\nvariables {\u03b1 : Type u}\nvariables {m n : Type*} [fintype m] [fintype n]\n\nlemma name1 (f : n \u2192 \u03b1) : (\u03bb x : n, f x) = f :=\nbegin\n  ext,\n  refl,\nend\n\nlemma vec_eq_unfold (x y : n \u2192 \u03b1) : (\u03bb i : n, x i) = (\u03bb i : n, y i) \u2194 \u2200 i : n, x i = y i :=\nbegin\n  split,\n  { intros hyp i, exact congr_fun hyp i },\n  { intro hyp, ext, apply hyp }\nend\n\n-- ## Coercions\ninstance : has_coe (n \u2192 \u211d) (n \u2192 \u2102) := \u27e8\u03bb x, (\u03bb i, \u27e8x i, 0\u27e9)\u27e9\ninstance : has_coe (matrix m n \u211d) (matrix m n \u2102) := \u27e8\u03bb M, (\u03bb i j, \u27e8M i j, 0\u27e9)\u27e9\n\n-- ## Lemmas on \u2102\n\nlemma conj_of_zero_im {\u03bc : \u2102} (H_im : \u03bc.im = 0) : conj \u03bc = \u03bc :=\nby { ext; simp only [conj_re, conj_im, H_im, neg_zero] }\n\nlemma sum_complex_re {x : n \u2192 \u2102} : (\u2211 i : n, x i).re = \u2211 i : n, (x i).re := by exact complex.re_lm.map_sum\n\nlemma sum_complex_im {x : n \u2192 \u2102} : (\u2211 i : n, x i).im = \u2211 i : n, (x i).im := by exact complex.im_lm.map_sum\n\n-- The real and complex parts of a complex vector\ndef vec_re (x : n \u2192 \u2102) : n \u2192 \u211d := \u03bb i : n, (x i).re\ndef vec_im (x : n \u2192 \u2102) : n \u2192 \u211d := \u03bb i : n, (x i).im\n\n-- Defining the complex conjugate of a complex vector\nsection vec_conj\n\ndef vec_conj (x : n \u2192 \u2102) : n \u2192 \u2102 := \u03bb i : n, conj (x i)\n\n-- (\u03bc \u2022 x)* = \u03bc* \u2022 x*\nlemma vec_conj_smul (\u03bc : \u2102) (x : n \u2192 \u2102) :\n  vec_conj (\u03bc \u2022 x) = (conj \u03bc) \u2022 (vec_conj x) :=\nby {  ext i; rw vec_conj; rw vec_conj; simp }\n\n-- \u2191A i j = \u2191(A i j)\nlemma coe_matrix_coe_elem (i : m) (j : n) (A : matrix m n \u211d) : (A : matrix m n \u2102) i j = \u2191(A i j) := by exact rfl\n\n-- (A \u2b1d x)* = A \u2b1d x*\nlemma vec_conj_mul_vec [decidable_eq n] [nonempty n] (A : matrix m n \u211d) (x : n \u2192 \u2102) :\n  vec_conj ((A : matrix m n \u2102).mul_vec x) = (A : matrix m n \u2102).mul_vec (vec_conj x) :=\nbegin\n  ext,\n  simp only [vec_conj, mul_vec, dot_product, conj_re, coe_matrix_coe_elem, sum_complex_re, mul_re, of_real_im, zero_mul],\n  simp only [vec_conj, mul_vec, dot_product, conj_im, coe_matrix_coe_elem, sum_complex_im, mul_im, add_zero, of_real_im,\n    zero_mul, sum_neg_distrib, mul_neg_eq_neg_mul_symm]\nend\n\nlemma vec_norm_sq_zero {x : n \u2192 \u2102} (H_dot : dot_product (vec_conj x) x = 0) : x = 0 :=\nbegin\n  unfold dot_product at H_dot,\n  simp only [vec_conj, mul_comm, mul_conj, complex.ext_iff, sum_complex_re, zero_re, of_real_re] at H_dot,\n  cases H_dot with H_re H_im,\n  have key : \u2211 i in (univ : finset n), norm_sq (x i) = 0 \u2194 \u2200 i \u2208 (univ : finset n), norm_sq(x i) = 0,\n  { apply sum_eq_zero_iff_of_nonneg, intros i h_univ, exact norm_sq_nonneg (x i) },\n  simp only [forall_prop_of_true, mem_univ, monoid_with_zero_hom.map_eq_zero] at key,\n  rw key at H_re,\n  ext i;\n  { specialize H_re i, simp only [H_re, pi.zero_apply] }\nend\n\nlemma coe_vec_re (x : n \u2192 \u2102) {i : n} : (vec_re x : n \u2192 \u2102) i = ((x i).re : \u2102) :=\nby simpa only [vec_re]\n\nlemma vec_add_conj_eq_two_re (x : n \u2192 \u2102) : x + vec_conj x = (2 : \u2102) \u2022 (vec_re x : n \u2192 \u2102) :=\nbegin\n  ext,\n  { simp [vec_conj, coe_vec_re x], linarith },\n  { simp [vec_conj, coe_vec_re x] }\nend\n\nlemma vec_conj_add_zero {x : n \u2192 \u2102} (H : x + vec_conj x = 0) : vec_re x = 0 :=\nbegin\n  rw [vec_add_conj_eq_two_re, smul_eq_zero] at H,\n  cases H with H_20 H_x,\n  { exfalso, simp at H_20, assumption }, -- 2 = 0\n  { rw function.funext_iff at H_x,\n    ext i,\n    specialize H_x i,\n    rw coe_vec_re at H_x,\n    simp only [of_real_eq_zero, pi.zero_apply] at H_x,\n    simp only [vec_re, H_x, pi.zero_apply] }\nend\n\nend vec_conj\n\nnamespace matrix\n\nvariables (M : matrix n n \u211d)\n\ndef Coe (M : matrix m n \u211d) := (M : matrix m n \u2102)\n\n/--\n## Matrix definitions\nLet `M` be a square real matrix. An `eigenvector` of `M` is a complex vector `x` with `M \u2b1d x = \u03bc \u2022 x`\nfor some `\u03bc \u2208 \u2102`, which is called the `eigenvalue` of `M` corresponding to the `eigenvector x`.\n-/\ndef has_eigenpair (\u03bc : \u2102) (x : n \u2192 \u2102) : Prop :=\n  x \u2260 0 \u2227 (mul_vec M.Coe x = \u03bc \u2022 x)\n\ndef has_eigenvector (x : n \u2192 \u2102) : Prop :=\n  \u2203 \u03bc : \u2102, M.has_eigenpair \u03bc x\n\ndef has_eigenvalue (\u03bc : \u2102) : Prop :=\n  \u2203 x : n \u2192 \u2102, M.has_eigenpair \u03bc x\n\ndef symm_matrix : Prop := M = M\u1d40\n\n-- ## Matrix : Helping lemmas\n\n-- (\u2191M)\u1d40 = \u2191M\u1d40\nlemma coe_transpose_matrix : (M.Coe)\u1d40 = (M\u1d40).Coe := by { unfold Coe, ext, tidy }\n\n-- \u2191M i j = \u2191(M i j)\nlemma coe_matrix_coe_elem (i j : n) : (M.Coe) i j = \u2191(M i j) := by exact rfl\n\n-- (M x)* = M x*\nlemma vec_conj_mul_vec_re (x : n \u2192 \u2102) :\n  vec_conj (mul_vec M.Coe x) = mul_vec (M.Coe) (vec_conj x) :=\nbegin\n  ext ;\n  simp only [vec_conj, mul_vec, dot_product, coe_matrix_coe_elem],\n  { simp only [sum_complex_re, of_real_im, zero_mul, conj_re, mul_re] },\n  { simp only [sum_complex_im, add_zero, of_real_im, zero_mul,\n               sum_neg_distrib, conj_im, mul_neg_eq_neg_mul_symm, mul_im] },\nend\n\nlemma symm_matrix_coe (H_symm : symm_matrix M) : (M.Coe) = (M.Coe)\u1d40 :=\nbegin\n  unfold symm_matrix at H_symm,\n  rw [coe_transpose_matrix, \u2190 H_symm]\nend\n\n-- v\u1d40 (M w) = (v\u1d40 M)\u1d40 w\nlemma dot_product_mul_vec_vec_mul (v w : n \u2192 \u2102) :\n  dot_product v (mul_vec M.Coe w) = dot_product (vec_mul v M.Coe) w :=\nbegin\n  have key : vec_mul v M.Coe = \u03bb j, dot_product v (\u03bb i, M.Coe i j),\n  { ext ; unfold vec_mul },\n  rw [key, dot_product_assoc],\n  ext ; simp only [dot_product, mul_vec],\nend\n\n-- 1. If x is an eigenvector of M, then a \u2022 x is an eigenvector of M, for any non-zero a : \u2102.\ntheorem has_eigenvector_smul (a : \u2102) (x : n \u2192 \u2102) (H_na : a \u2260 0) (H_eigenvector : has_eigenvector M x) :\n  has_eigenvector M (a \u2022 x) :=\nbegin\n  rcases H_eigenvector with \u27e8\u03bc, \u27e8H_nx, H_mul\u27e9\u27e9,\n  use \u03bc, -- corresponding eigenvalue \u03bc\n  split,\n  { intro hyp, rw smul_eq_zero at hyp, tauto }, -- a \u2022 x \u2260 0\n  calc (M.Coe).mul_vec (a \u2022 x)\n      = a \u2022 M.Coe.mul_vec x : -- M \u2b1d (a \u2022 x) = a \u2022 (M \u2b1d x)\n  by { rw mul_vec_smul_assoc }\n  ... = a \u2022 (\u03bc \u2022 x) :                 -- ... = a \u2022 (\u03bc \u2022 x)\n  by { rw H_mul }\n  ... = \u03bc \u2022 (a \u2022 x) :                 -- ... = \u03bc \u2022 (a \u2022 x)\n  by { simp only [smul_smul, mul_comm] }\nend\n\n-- 2. If there are two eigenvectors that have the same correspoding eigenvalue \u03bc,\n-- then any non-zero linear combination of them is also an eigenvector with the same eigenvalue \u03bc.\ntheorem has_eigenpair_linear (a b : \u2102) (v w : n \u2192 \u2102) (\u03bc : \u2102) (H_ne : a \u2022 v + b \u2022 w \u2260 0)\n(H\u2081 : has_eigenpair M \u03bc v) (H\u2082 : has_eigenpair M \u03bc w) : has_eigenpair M \u03bc (a \u2022 v + b \u2022 w) :=\nbegin\n  rcases H\u2081 with \u27e8H\u2081\u2081, H\u2081\u2082\u27e9,\n  rcases H\u2082 with \u27e8H\u2082\u2081, H\u2082\u2082\u27e9,\n  use H_ne, -- a \u2022 v + b \u2022 w \u2260 0\n  calc M.Coe.mul_vec (a \u2022 v + b \u2022 w) -- M \u2b1d (a \u2022 v + b \u2022 w) = M \u2b1d (a \u2022 v) + M \u2b1d (b \u2022 w)\n      = M.Coe.mul_vec(a \u2022 v) + M.Coe.mul_vec(b \u2022 w) :\n  by { ext ; simp only [mul_vec, pi.add_apply, dot_product_add] }\n  ... = a \u2022 M.Coe.mul_vec v + b \u2022 M.Coe.mul_vec w :  -- ... = a \u2022 (M \u2b1d v) + b \u2022 (M \u2b1d w)\n  by { ext ; simp only [mul_vec, algebra.id.smul_eq_mul,\n                        dot_product_smul, pi.add_apply, pi.smul_apply] }\n  ... = a \u2022 (\u03bc \u2022 v) + b \u2022 (\u03bc \u2022 w) :                  -- ... = a \u2022 (\u03bc \u2022 v) + b \u2022 (\u03bc \u2022 w)\n  by { rw [H\u2081\u2082, H\u2082\u2082] }\n  ... = \u03bc \u2022 (a \u2022 v + b \u2022 w) :                        -- ... = \u03bc \u2022 (a \u2022 v + b \u2022 w)\n  by { simp only [smul_smul, mul_comm, smul_add] }\nend\n\n-- 3. All eigenvalues of a symmetric real matrix M are real.\ntheorem symm_matrix_real_eigenvalues (H_symm : symm_matrix M) :\n  \u2200 (\u03bc : \u2102), has_eigenvalue M \u03bc \u2192 \u03bc.im = 0 :=\nbegin\n  -- (1) M \u2b1d x = \u03bc \u2022 x\n  rintro \u03bc \u27e8x, \u27e8H_x, H_eq\u2081\u27e9\u27e9,\n  -- (2) M \u2b1d x* = \u03bc* \u2022 x*\n  have H_eq\u2082 : mul_vec M.Coe (vec_conj x) = (conj \u03bc) \u2022 (vec_conj x),\n  { rw [\u2190 vec_conj_smul \u03bc x, \u2190 M.vec_conj_mul_vec_re x, H_eq\u2081] },\n  -- (3) \u03bc ((x*)\u1d40 x) = \u03bc* ((x*)\u1d40 x)\n  have H_eq\u2083 : \u03bc * (dot_product (vec_conj x) x) = conj \u03bc * dot_product (vec_conj x) x,\n\n  calc \u03bc * dot_product (vec_conj x) x\n      = dot_product (vec_conj x) (\u03bc \u2022 x) :    -- \u03bc ((x*)\u1d40 x) = (x*)\u1d40 (\u03bc x)\n  by { simp [dot_product, vec_conj, \u2190 mul_assoc, mul_comm], rw mul_sum, simp [mul_assoc]}\n  ... = dot_product (vec_conj x) (M.Coe.mul_vec x) :  -- ... = (x*)\u1d40 (M x)\n  by { rw \u2190 H_eq\u2081 }\n  ... = dot_product (M.Coe.vec_mul (vec_conj x)) x :  -- ... = ((x*)\u1d40 M) x\n  by { rw dot_product_mul_vec }\n  ... = dot_product (M.Coe\u1d40.mul_vec (vec_conj x)) x : -- ... = (M\u1d40 x*)\u1d40 x\n  by { rw \u2190 mul_vec_transpose M.Coe (vec_conj x) }\n  ... = dot_product (M.Coe.mul_vec (vec_conj x)) x :  -- ... = (M x*)\u1d40 x\n  by { have H : M.Coe = M.Coe\u1d40, apply symm_matrix_coe, exact H_symm, rw \u2190 H }\n  ... = dot_product (conj \u03bc \u2022 vec_conj x) x :         -- ... = (\u03bc* x*)\u1d40 x\n  by { rw H_eq\u2082 }\n  ... = conj \u03bc * dot_product (vec_conj x) x :         -- ... = \u03bc* ((x*)\u1d40 x)\n  by { simp },\n\n  -- (4) (\u03bc - \u03bc*) ((x*)\u1d40 x) = 0\n  have H_eq\u2084 : (\u03bc - conj \u03bc) * dot_product (vec_conj x) x = 0,\n  { rw sub_mul, simp only [H_eq\u2083, sub_self] },\n  -- \u03bc - \u03bc* = 0 \u2228 (x*)\u1d40 x = 0\n  rw mul_eq_zero at H_eq\u2084,\n  cases H_eq\u2084 with H_\u03bc H_prod,\n  { rw [sub_eq_zero, eq_comm, eq_conj_iff_real] at H_\u03bc,\n    cases H_\u03bc with r H_r,\n    rw [H_r, of_real_im] }, -- \u03bc - \u03bc* = 0\n  { exfalso,\n    exact H_x (vec_norm_sq_zero H_prod) }, -- (x*)\u1d40 x = 0\nend\n\n-- 4. For every real eigenvalue of a symmetric matrix M, there exists a corresponding real-valued eigenvector.\ntheorem symm_matrix_real_eigenvectors (H_symm : symm_matrix M) (\u03bc : \u2102) (H_eigenvalue : has_eigenvalue M \u03bc) :\n  \u2203 x : n \u2192 \u2102, has_eigenpair M \u03bc x \u2227 vec_im x = 0 :=\nbegin\n  -- We know that \u03bc \u2208 \u211d from before.\n  have H_\u03bc : \u03bc.im = 0,\n  { apply M.symm_matrix_real_eigenvalues H_symm \u03bc H_eigenvalue },\n  rcases H_eigenvalue with \u27e8x, \u27e8H_nx, H_mul\u27e9\u27e9,\n  by_cases H_re : vec_re x = 0,\n  -- 1) I \u2022 x will be used\n  { use (I \u2022 x),\n    split,\n    -- 1.1) I \u2022 x is an eigenvector\n    { split,\n      -- 1.1.1) I \u2022 x \u2260 0\n      { intro hyp, rw smul_eq_zero at hyp,\n        have H_nI : I \u2260 0, { exact I_ne_zero },\n        tauto },\n      -- 1.1.2) M (I \u2022 x) = \u03bc \u2022 (I \u2022 x)\n      { simp only [mul_vec_smul_assoc, H_mul, smul_smul, mul_comm] } },\n    -- 1.2) I \u2022 x \u2208 \u211d\u207f\n    { ext i,\n      simp only [vec_re, vec_eq_unfold] at H_re,\n      simp only [vec_im, algebra.id.smul_eq_mul, I_re, one_mul,\n                 I_im, zero_mul, mul_im, zero_add, pi.smul_apply],\n      exact H_re i } },\n  -- 2) x + x* will be used\n  { use (x + vec_conj x),\n    split,\n    -- 2.1) x + x* is an eigenvector\n    { split,\n      -- 2.1.1) x + x* \u2260 0\n      { intro hyp, exact H_re (vec_conj_add_zero hyp) },\n      -- 2.1.2) M (x + x*) = \u03bc \u2022 (x + x*)\n      { calc M.Coe.mul_vec (x + vec_conj x)\n            = M.Coe.mul_vec x + M.Coe.mul_vec (vec_conj x) :\n        by { apply mul_vec_add } -- M (x + x*) = M x + M x*\n        ... = M.Coe.mul_vec x + vec_conj (M.Coe.mul_vec x) :\n        by { rw \u2190 M.vec_conj_mul_vec_re x }     -- ... = M x + (M x)*\n        ... = \u03bc \u2022 x + vec_conj (\u03bc \u2022 x) :\n        by { rw H_mul }                         -- ... = \u03bc \u2022 x + (\u03bc \u2022 x)*\n        ... = \u03bc \u2022 x + (conj \u03bc) \u2022 (vec_conj x) :\n        by { rw vec_conj_smul }                 -- ... = \u03bc \u2022 x + \u03bc* \u2022 x*\n        ... = \u03bc \u2022 x + \u03bc \u2022 (vec_conj x) :\n        by { rw conj_of_zero_im H_\u03bc }           -- ... = \u03bc \u2022 x + \u03bc \u2022 x*\n        ... = \u03bc \u2022 (x + vec_conj x) :\n        by { simp only [smul_add] } } },        -- ... = \u03bc \u2022 (x + x*)\n    -- 2.2) x + x* \u2208 \u211d\u207f\n    { ext, simp [vec_add_conj_eq_two_re, vec_im, coe_vec_re] } }\nend\n\n-- 5. If v and w are eigenvectors of a symmetric matrix M with different eigenvalues, then v and w are orthogonal.\ntheorem dot_product_neq_eigenvalue_zero (H_symm : symm_matrix M) (v w : n \u2192 \u2102) (\u03bc \u03bc' : \u2102)\n(H_ne : \u03bc \u2260 \u03bc') (H\u2081 : has_eigenpair M \u03bc v) (H\u2082 : has_eigenpair M \u03bc' w) : dot_product v w = 0 :=\nbegin\n  have key : (\u03bc - \u03bc') * dot_product v w = 0,\n  calc (\u03bc - \u03bc') * dot_product v w\n      = \u03bc * dot_product v w - \u03bc' * dot_product v w :\n  by { apply mul_sub_right_distrib }-- (\u03bc - \u03bc')v\u1d40 w = \u03bc(v\u1d40 w) - \u03bc'(v\u1d40 w)\n  ... = dot_product (\u03bc \u2022 v) w - dot_product v (\u03bc' \u2022 w) :\n  by { simp only [dot_product_smul,\n       smul_dot_product]; simp }                   -- ... = (\u03bc \u2022 v)\u1d40w - v\u1d40(\u03bc' \u2022 w)\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product v (M.Coe.mul_vec w) :\n  by { rw [H\u2081.2, H\u2082.2] }                     -- ... = (M v)\u1d40w - v\u1d40(M w)\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product (vec_mul v M.Coe) w :\n  by { rw M.dot_product_mul_vec_vec_mul v w }-- ... = (M v)\u1d40w - (v\u1d40 M)\u1d40w\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product (vec_mul v M.Coe\u1d40) w:\n  by { rw \u2190 symm_matrix_coe M H_symm }  -- ... = (M v)\u1d40w - (v\u1d40 M\u1d40)\u1d40w\n  ... = dot_product (M.Coe.mul_vec v) w - dot_product (mul_vec M.Coe v) w :\n  by { rw \u2190 vec_mul_transpose M.Coe v }       -- ... = (M v)\u1d40w - (M v)\u1d40w\n  ... = 0 :\n  by { simp only [sub_self] },               -- ... = 0\n  rw mul_eq_zero at key,\n  cases key with H_\u03bc H_dot,\n  { exfalso, rw sub_eq_zero at H_\u03bc, exact H_ne H_\u03bc }, -- \u03bc - \u03bc' = 0\n  { exact H_dot } -- v\u1d40 w = 0\nend\n\n-- TODOs :\n-- 1. positive semidefinite matrices\n-- 2. eigenvalues = roots of characteristic polynomial (char_poly)\n-- 3. eigendecomposition of a diagonalizable matrix\n\nend matrix", "meta": {"author": "RaduEu", "repo": "Lean-Project", "sha": "6cddb5ca7ffc1f878da745deb34d49e1f68ff672", "save_path": "github-repos/lean/RaduEu-Lean-Project", "path": "github-repos/lean/RaduEu-Lean-Project/Lean-Project-6cddb5ca7ffc1f878da745deb34d49e1f68ff672/symm_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.763483758172699, "lm_q1q2_score": 0.704725413336118}}
{"text": "import linear_algebra.finite_dimensional\n\nopen finite_dimensional\n\nvariables {\ud835\udd5c : Type*} [field \ud835\udd5c]\n          {E : Type*} [add_comm_group E] [module \ud835\udd5c E]\n          {E' : Type*} [add_comm_group E'] [module \ud835\udd5c E']\n\nlemma two_le_rank_of_rank_lt_rank [finite_dimensional \ud835\udd5c E] [finite_dimensional \ud835\udd5c E']\n  {\u03c0 : E \u2192\u2097[\ud835\udd5c] \ud835\udd5c} (h\u03c0 : \u03c0.ker \u2260 \u22a4) (h : finrank \ud835\udd5c E < finrank \ud835\udd5c E') (\u03c6 : E \u2192\u2097[\ud835\udd5c] E') :\n  2 \u2264 module.rank \ud835\udd5c (E' \u29f8 submodule.map \u03c6 \u03c0.ker) :=\nbegin\n  suffices : 2 \u2264 finrank \ud835\udd5c (E' \u29f8 \u03c0.ker.map \u03c6),\n  { rw \u2190 finrank_eq_dim,\n    exact_mod_cast this },\n  apply le_of_add_le_add_right,\n  rw submodule.finrank_quotient_add_finrank (\u03c0.ker.map \u03c6),\n  have := calc finrank \ud835\udd5c (\u03c0.ker.map \u03c6)\n        \u2264 finrank \ud835\udd5c \u03c0.ker : finrank_map_le \ud835\udd5c \u03c6 \u03c0.ker\n    ...  < finrank \ud835\udd5c E : submodule.finrank_lt (le_top.lt_of_ne h\u03c0),\n  linarith,\nend\n", "meta": {"author": "leanprover-community", "repo": "sphere-eversion", "sha": "324e02c1509db6177cf363618f6ac5be343ce2f5", "save_path": "github-repos/lean/leanprover-community-sphere-eversion", "path": "github-repos/lean/leanprover-community-sphere-eversion/sphere-eversion-324e02c1509db6177cf363618f6ac5be343ce2f5/src/to_mathlib/linear_algebra/finite_dimensional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7047162238653423}}
{"text": "theorem mul_eq_zero_iff (a b : \u2115): a * b = 0 \u2194 a = 0 \u2228 b = 0 :=\nbegin\n    split,\n    intro h,\n    apply nat.eq_zero_of_mul_eq_zero,\n    exact h,\n\n    intro f,\n    cases f with a b,\n    rw a,\n    rw nat.zero_mul,\n    rw b,\n    rw nat.mul_zero,\nend", "meta": {"author": "Samyak-Surti", "repo": "LeanCode", "sha": "944eac3e5f43e2614ed246083b97fbdf24181d83", "save_path": "github-repos/lean/Samyak-Surti-LeanCode", "path": "github-repos/lean/Samyak-Surti-LeanCode/LeanCode-944eac3e5f43e2614ed246083b97fbdf24181d83/nat_num_game/src/Advanced_Multiplication_World/adv_mul_wrld3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7046609094031236}}
{"text": "--- https://www.codewars.com/kata/5d64d9c0a5aad20001b2d9f8/train/lean\n\nimport data.nat.basic\nimport tactic\n\ndef fsum : (\u2115 \u2192 \u2115) \u2192 \u2115 \u2192 \u2115 :=\n  \u03bb f n, nat.rec_on n (f 0) (\u03bb n' ihn', f (nat.succ n') + ihn')\n\ndef sq_nat : \u2115 \u2192 \u2115 := \u03bb n, n ^ 2\ndef cb : \u2115 \u2192 \u2115 := \u03bb n, n ^ 3\n\ntheorem nicomachus : \u2200 n, sq_nat (fsum id n) = fsum cb n := sorry\n\n-- https://leanprover-community.github.io/extras/calc.html\nlemma example_calc_mode (a b c : \u2115) : (a + b) * c = c * b + c * a :=\nbegin \n  --ring,\n  calc (a + b) * c \n      = a * c + b * c : by exact add_mul a b c\n  ... = c * a + c * b : by simp [mul_comm]\n  ... = c * b + c * a : by simp [add_comm],\nend", "meta": {"author": "apurvanakade", "repo": "Lean-NU-2022", "sha": "8945df935736f39ed13c610d9a8e36198912f21c", "save_path": "github-repos/lean/apurvanakade-Lean-NU-2022", "path": "github-repos/lean/apurvanakade-Lean-NU-2022/Lean-NU-2022-8945df935736f39ed13c610d9a8e36198912f21c/src/Codewars/sum_of_cubes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.7046609074972227}}
{"text": "/-\nCopyright (c) 2019 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n-/\nimport measure_theory.function.lp_space\n\n\n/-!\n# Integrable functions and `L\u00b9` space\n\nIn the first part of this file, the predicate `integrable` is defined and basic properties of\nintegrable functions are proved.\n\nSuch a predicate is already available under the name `mem_\u2112p 1`. We give a direct definition which\nis easier to use, and show that it is equivalent to `mem_\u2112p 1`\n\nIn the second part, we establish an API between `integrable` and the space `L\u00b9` of equivalence\nclasses of integrable functions, already defined as a special case of `L^p` spaces for `p = 1`.\n\n## Notation\n\n* `\u03b1 \u2192\u2081[\u03bc] \u03b2` is the type of `L\u00b9` space, where `\u03b1` is a `measure_space` and `\u03b2` is a `normed_group`\n  with a `second_countable_topology`. `f : \u03b1 \u2192\u2098 \u03b2` is a \"function\" in `L\u00b9`. In comments, `[f]` is\n  also used to denote an `L\u00b9` function.\n\n  `\u2081` can be typed as `\\1`.\n\n## Main definitions\n\n* Let `f : \u03b1 \u2192 \u03b2` be a function, where `\u03b1` is a `measure_space` and `\u03b2` a `normed_group`.\n  Then `has_finite_integral f` means `(\u222b\u207b a, nnnorm (f a)) < \u221e`.\n\n* If `\u03b2` is moreover a `measurable_space` then `f` is called `integrable` if\n  `f` is `measurable` and `has_finite_integral f` holds.\n\n## Implementation notes\n\nTo prove something for an arbitrary integrable function, a useful theorem is\n`integrable.induction` in the file `set_integral`.\n\n## Tags\n\nintegrable, function space, l1\n\n-/\n\nnoncomputable theory\nopen_locale classical topological_space big_operators ennreal measure_theory nnreal\n\nopen set filter topological_space ennreal emetric measure_theory\n\nvariables {\u03b1 \u03b2 \u03b3 \u03b4 : Type*} {m : measurable_space \u03b1} {\u03bc \u03bd : measure \u03b1}\nvariables [normed_group \u03b2]\nvariables [normed_group \u03b3]\n\nnamespace measure_theory\n\n/-! ### Some results about the Lebesgue integral involving a normed group -/\n\nlemma lintegral_nnnorm_eq_lintegral_edist (f : \u03b1 \u2192 \u03b2) :\n  \u222b\u207b a, nnnorm (f a) \u2202\u03bc = \u222b\u207b a, edist (f a) 0 \u2202\u03bc :=\nby simp only [edist_eq_coe_nnnorm]\n\nlemma lintegral_norm_eq_lintegral_edist (f : \u03b1 \u2192 \u03b2) :\n  \u222b\u207b a, (ennreal.of_real \u2225f a\u2225) \u2202\u03bc = \u222b\u207b a, edist (f a) 0 \u2202\u03bc :=\nby simp only [of_real_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm]\n\nlemma lintegral_edist_triangle [second_countable_topology \u03b2] [measurable_space \u03b2]\n  [opens_measurable_space \u03b2] {f g h : \u03b1 \u2192 \u03b2}\n  (hf : ae_measurable f \u03bc) (hg : ae_measurable g \u03bc) (hh : ae_measurable h \u03bc) :\n  \u222b\u207b a, edist (f a) (g a) \u2202\u03bc \u2264 \u222b\u207b a, edist (f a) (h a) \u2202\u03bc + \u222b\u207b a, edist (g a) (h a) \u2202\u03bc :=\nbegin\n  rw \u2190 lintegral_add' (hf.edist hh) (hg.edist hh),\n  refine lintegral_mono (\u03bb a, _),\n  apply edist_triangle_right\nend\n\nlemma lintegral_nnnorm_zero : \u222b\u207b a : \u03b1, nnnorm (0 : \u03b2) \u2202\u03bc = 0 := by simp\n\nlemma lintegral_nnnorm_add [measurable_space \u03b2] [opens_measurable_space \u03b2]\n  [measurable_space \u03b3] [opens_measurable_space \u03b3]\n  {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} (hf : ae_measurable f \u03bc) (hg : ae_measurable g \u03bc) :\n  \u222b\u207b a, nnnorm (f a) + nnnorm (g a) \u2202\u03bc = \u222b\u207b a, nnnorm (f a) \u2202\u03bc + \u222b\u207b a, nnnorm (g a) \u2202\u03bc :=\nlintegral_add' hf.ennnorm hg.ennnorm\n\nlemma lintegral_nnnorm_neg {f : \u03b1 \u2192 \u03b2} :\n  \u222b\u207b a, nnnorm ((-f) a) \u2202\u03bc = \u222b\u207b a, nnnorm (f a) \u2202\u03bc :=\nby simp only [pi.neg_apply, nnnorm_neg]\n\n/-! ### The predicate `has_finite_integral` -/\n\n/-- `has_finite_integral f \u03bc` means that the integral `\u222b\u207b a, \u2225f a\u2225 \u2202\u03bc` is finite.\n  `has_finite_integral f` means `has_finite_integral f volume`. -/\ndef has_finite_integral {m : measurable_space \u03b1} (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1 . volume_tac) : Prop :=\n\u222b\u207b a, nnnorm (f a) \u2202\u03bc < \u221e\n\nlemma has_finite_integral_iff_norm (f : \u03b1 \u2192 \u03b2) :\n  has_finite_integral f \u03bc \u2194 \u222b\u207b a, (ennreal.of_real \u2225f a\u2225) \u2202\u03bc < \u221e :=\nby simp only [has_finite_integral, of_real_norm_eq_coe_nnnorm]\n\nlemma has_finite_integral_iff_edist (f : \u03b1 \u2192 \u03b2) :\n  has_finite_integral f \u03bc \u2194 \u222b\u207b a, edist (f a) 0 \u2202\u03bc < \u221e :=\nby simp only [has_finite_integral_iff_norm, edist_dist, dist_zero_right]\n\nlemma has_finite_integral_iff_of_real {f : \u03b1 \u2192 \u211d} (h : 0 \u2264\u1d50[\u03bc] f) :\n  has_finite_integral f \u03bc \u2194 \u222b\u207b a, ennreal.of_real (f a) \u2202\u03bc < \u221e :=\nhave lintegral_eq : \u222b\u207b a, (ennreal.of_real \u2225f a\u2225) \u2202\u03bc = \u222b\u207b a, ennreal.of_real (f a) \u2202\u03bc :=\nbegin\n  refine lintegral_congr_ae (h.mono $ \u03bb a h, _),\n  rwa [real.norm_eq_abs, abs_of_nonneg]\nend,\nby rw [has_finite_integral_iff_norm, lintegral_eq]\n\nlemma has_finite_integral_iff_of_nnreal {f : \u03b1 \u2192 \u211d\u22650} :\n  has_finite_integral (\u03bb x, (f x : \u211d)) \u03bc \u2194 \u222b\u207b a, f a \u2202\u03bc < \u221e :=\nby simp [has_finite_integral_iff_norm]\n\nlemma has_finite_integral.mono {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} (hg : has_finite_integral g \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 \u2264 \u2225g a\u2225) : has_finite_integral f \u03bc :=\nbegin\n  simp only [has_finite_integral_iff_norm] at *,\n  calc \u222b\u207b a, (ennreal.of_real \u2225f a\u2225) \u2202\u03bc \u2264 \u222b\u207b (a : \u03b1), (ennreal.of_real \u2225g a\u2225) \u2202\u03bc :\n    lintegral_mono_ae (h.mono $ assume a h, of_real_le_of_real h)\n    ... < \u221e : hg\nend\n\nlemma has_finite_integral.mono' {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u211d} (hg : has_finite_integral g \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 \u2264 g a) : has_finite_integral f \u03bc :=\nhg.mono $ h.mono $ \u03bb x hx, le_trans hx (le_abs_self _)\n\nlemma has_finite_integral.congr' {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} (hf : has_finite_integral f \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 = \u2225g a\u2225) :\n  has_finite_integral g \u03bc :=\nhf.mono $ eventually_eq.le $ eventually_eq.symm h\n\nlemma has_finite_integral_congr' {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 = \u2225g a\u2225) :\n  has_finite_integral f \u03bc \u2194 has_finite_integral g \u03bc :=\n\u27e8\u03bb hf, hf.congr' h, \u03bb hg, hg.congr' $ eventually_eq.symm h\u27e9\n\nlemma has_finite_integral.congr {f g : \u03b1 \u2192 \u03b2} (hf : has_finite_integral f \u03bc) (h : f =\u1d50[\u03bc] g) :\n  has_finite_integral g \u03bc :=\nhf.congr' $ h.fun_comp norm\n\nlemma has_finite_integral_congr {f g : \u03b1 \u2192 \u03b2} (h : f =\u1d50[\u03bc] g) :\n  has_finite_integral f \u03bc \u2194 has_finite_integral g \u03bc :=\nhas_finite_integral_congr' $ h.fun_comp norm\n\nlemma has_finite_integral_const_iff {c : \u03b2} :\n  has_finite_integral (\u03bb x : \u03b1, c) \u03bc \u2194 c = 0 \u2228 \u03bc univ < \u221e :=\nby simp [has_finite_integral, lintegral_const, lt_top_iff_ne_top, or_iff_not_imp_left]\n\nlemma has_finite_integral_const [is_finite_measure \u03bc] (c : \u03b2) :\n  has_finite_integral (\u03bb x : \u03b1, c) \u03bc :=\nhas_finite_integral_const_iff.2 (or.inr $ measure_lt_top _ _)\n\nlemma has_finite_integral_of_bounded [is_finite_measure \u03bc] {f : \u03b1 \u2192 \u03b2} {C : \u211d}\n  (hC : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 \u2264 C) : has_finite_integral f \u03bc :=\n(has_finite_integral_const C).mono' hC\n\nlemma has_finite_integral.mono_measure {f : \u03b1 \u2192 \u03b2} (h : has_finite_integral f \u03bd) (h\u03bc : \u03bc \u2264 \u03bd) :\n  has_finite_integral f \u03bc :=\nlt_of_le_of_lt (lintegral_mono' h\u03bc (le_refl _)) h\n\nlemma has_finite_integral.add_measure {f : \u03b1 \u2192 \u03b2} (h\u03bc : has_finite_integral f \u03bc)\n  (h\u03bd : has_finite_integral f \u03bd) : has_finite_integral f (\u03bc + \u03bd) :=\nbegin\n  simp only [has_finite_integral, lintegral_add_measure] at *,\n  exact add_lt_top.2 \u27e8h\u03bc, h\u03bd\u27e9\nend\n\nlemma has_finite_integral.left_of_add_measure {f : \u03b1 \u2192 \u03b2} (h : has_finite_integral f (\u03bc + \u03bd)) :\n  has_finite_integral f \u03bc :=\nh.mono_measure $ measure.le_add_right $ le_refl _\n\nlemma has_finite_integral.right_of_add_measure {f : \u03b1 \u2192 \u03b2} (h : has_finite_integral f (\u03bc + \u03bd)) :\n  has_finite_integral f \u03bd :=\nh.mono_measure $ measure.le_add_left $ le_refl _\n\n@[simp] lemma has_finite_integral_add_measure {f : \u03b1 \u2192 \u03b2} :\n  has_finite_integral f (\u03bc + \u03bd) \u2194 has_finite_integral f \u03bc \u2227 has_finite_integral f \u03bd :=\n\u27e8\u03bb h, \u27e8h.left_of_add_measure, h.right_of_add_measure\u27e9, \u03bb h, h.1.add_measure h.2\u27e9\n\nlemma has_finite_integral.smul_measure {f : \u03b1 \u2192 \u03b2} (h : has_finite_integral f \u03bc) {c : \u211d\u22650\u221e}\n  (hc : c \u2260 \u221e) : has_finite_integral f (c \u2022 \u03bc) :=\nbegin\n  simp only [has_finite_integral, lintegral_smul_measure] at *,\n  exact mul_lt_top hc h.ne\nend\n\n@[simp] lemma has_finite_integral_zero_measure {m : measurable_space \u03b1} (f : \u03b1 \u2192 \u03b2) :\n  has_finite_integral f (0 : measure \u03b1) :=\nby simp only [has_finite_integral, lintegral_zero_measure, with_top.zero_lt_top]\n\nvariables (\u03b1 \u03b2 \u03bc)\n@[simp] lemma has_finite_integral_zero : has_finite_integral (\u03bba:\u03b1, (0:\u03b2)) \u03bc :=\nby simp [has_finite_integral]\nvariables {\u03b1 \u03b2 \u03bc}\n\nlemma has_finite_integral.neg {f : \u03b1 \u2192 \u03b2} (hfi : has_finite_integral f \u03bc) :\n  has_finite_integral (-f) \u03bc :=\nby simpa [has_finite_integral] using hfi\n\n@[simp] lemma has_finite_integral_neg_iff {f : \u03b1 \u2192 \u03b2} :\n  has_finite_integral (-f) \u03bc \u2194 has_finite_integral f \u03bc :=\n\u27e8\u03bb h, neg_neg f \u25b8 h.neg, has_finite_integral.neg\u27e9\n\nlemma has_finite_integral.norm {f : \u03b1 \u2192 \u03b2} (hfi : has_finite_integral f \u03bc) :\n  has_finite_integral (\u03bba, \u2225f a\u2225) \u03bc :=\nhave eq : (\u03bba, (nnnorm \u2225f a\u2225 : \u211d\u22650\u221e)) = \u03bba, (nnnorm (f a) : \u211d\u22650\u221e),\n  by { funext, rw nnnorm_norm },\nby { rwa [has_finite_integral, eq] }\n\nlemma has_finite_integral_norm_iff (f : \u03b1 \u2192 \u03b2) :\n  has_finite_integral (\u03bba, \u2225f a\u2225) \u03bc \u2194 has_finite_integral f \u03bc :=\nhas_finite_integral_congr' $ eventually_of_forall $ \u03bb x, norm_norm (f x)\n\nlemma has_finite_integral_to_real_of_lintegral_ne_top\n  {f : \u03b1 \u2192 \u211d\u22650\u221e} (hf : \u222b\u207b x, f x \u2202\u03bc \u2260 \u221e) :\n  has_finite_integral (\u03bb x, (f x).to_real) \u03bc :=\nbegin\n  have : \u2200 x, (\u2225(f x).to_real\u2225\u208a : \u211d\u22650\u221e) =\n    @coe \u211d\u22650 \u211d\u22650\u221e _ (\u27e8(f x).to_real, ennreal.to_real_nonneg\u27e9 : \u211d\u22650),\n  { intro x, rw real.nnnorm_of_nonneg },\n  simp_rw [has_finite_integral, this],\n  refine lt_of_le_of_lt (lintegral_mono (\u03bb x, _)) (lt_top_iff_ne_top.2 hf),\n  by_cases hfx : f x = \u221e,\n  { simp [hfx] },\n  { lift f x to \u211d\u22650 using hfx with fx,\n    simp [\u2190 h] }\nend\n\nlemma is_finite_measure_with_density_of_real {f : \u03b1 \u2192 \u211d} (hfi : has_finite_integral f \u03bc) :\n  is_finite_measure (\u03bc.with_density (\u03bb x, ennreal.of_real $ f x)) :=\nbegin\n  refine is_finite_measure_with_density ((lintegral_mono $ \u03bb x, _).trans_lt hfi).ne,\n  exact real.of_real_le_ennnorm (f x)\nend\n\nsection dominated_convergence\n\nvariables {F : \u2115 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2} {bound : \u03b1 \u2192 \u211d}\n\nlemma all_ae_of_real_F_le_bound (h : \u2200 n, \u2200\u1d50 a \u2202\u03bc, \u2225F n a\u2225 \u2264 bound a) :\n  \u2200 n, \u2200\u1d50 a \u2202\u03bc, ennreal.of_real \u2225F n a\u2225 \u2264 ennreal.of_real (bound a) :=\n\u03bbn, (h n).mono $ \u03bb a h, ennreal.of_real_le_of_real h\n\nlemma all_ae_tendsto_of_real_norm (h : \u2200\u1d50 a \u2202\u03bc, tendsto (\u03bb n, F n a) at_top $ \ud835\udcdd $ f a) :\n  \u2200\u1d50 a \u2202\u03bc, tendsto (\u03bbn, ennreal.of_real \u2225F n a\u2225) at_top $ \ud835\udcdd $ ennreal.of_real \u2225f a\u2225 :=\nh.mono $\n  \u03bb a h, tendsto_of_real $ tendsto.comp (continuous.tendsto continuous_norm _) h\n\nlemma all_ae_of_real_f_le_bound (h_bound : \u2200 n, \u2200\u1d50 a \u2202\u03bc, \u2225F n a\u2225 \u2264 bound a)\n  (h_lim : \u2200\u1d50 a \u2202\u03bc, tendsto (\u03bb n, F n a) at_top (\ud835\udcdd (f a))) :\n  \u2200\u1d50 a \u2202\u03bc, ennreal.of_real \u2225f a\u2225 \u2264 ennreal.of_real (bound a) :=\nbegin\n  have F_le_bound := all_ae_of_real_F_le_bound h_bound,\n  rw \u2190 ae_all_iff at F_le_bound,\n  apply F_le_bound.mp ((all_ae_tendsto_of_real_norm h_lim).mono _),\n  assume a tendsto_norm F_le_bound,\n  exact le_of_tendsto' tendsto_norm (F_le_bound)\nend\n\nlemma has_finite_integral_of_dominated_convergence {F : \u2115 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2} {bound : \u03b1 \u2192 \u211d}\n  (bound_has_finite_integral : has_finite_integral bound \u03bc)\n  (h_bound : \u2200 n, \u2200\u1d50 a \u2202\u03bc, \u2225F n a\u2225 \u2264 bound a)\n  (h_lim : \u2200\u1d50 a \u2202\u03bc, tendsto (\u03bb n, F n a) at_top (\ud835\udcdd (f a))) :\n  has_finite_integral f \u03bc :=\n/- `\u2225F n a\u2225 \u2264 bound a` and `\u2225F n a\u2225 --> \u2225f a\u2225` implies `\u2225f a\u2225 \u2264 bound a`,\n  and so `\u222b \u2225f\u2225 \u2264 \u222b bound < \u221e` since `bound` is has_finite_integral -/\nbegin\n  rw has_finite_integral_iff_norm,\n  calc \u222b\u207b a, (ennreal.of_real \u2225f a\u2225) \u2202\u03bc \u2264 \u222b\u207b a, ennreal.of_real (bound a) \u2202\u03bc :\n    lintegral_mono_ae $ all_ae_of_real_f_le_bound h_bound h_lim\n    ... < \u221e :\n    begin\n      rw \u2190 has_finite_integral_iff_of_real,\n      { exact bound_has_finite_integral },\n      exact (h_bound 0).mono (\u03bb a h, le_trans (norm_nonneg _) h)\n    end\nend\n\nlemma tendsto_lintegral_norm_of_dominated_convergence [measurable_space \u03b2]\n  [borel_space \u03b2] [second_countable_topology \u03b2]\n  {F : \u2115 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2} {bound : \u03b1 \u2192 \u211d}\n  (F_measurable : \u2200 n, ae_measurable (F n) \u03bc)\n  (bound_has_finite_integral : has_finite_integral bound \u03bc)\n  (h_bound : \u2200 n, \u2200\u1d50 a \u2202\u03bc, \u2225F n a\u2225 \u2264 bound a)\n  (h_lim : \u2200\u1d50 a \u2202\u03bc, tendsto (\u03bb n, F n a) at_top (\ud835\udcdd (f a))) :\n  tendsto (\u03bbn, \u222b\u207b a, (ennreal.of_real \u2225F n a - f a\u2225) \u2202\u03bc) at_top (\ud835\udcdd 0) :=\nhave f_measurable : ae_measurable f \u03bc := ae_measurable_of_tendsto_metric_ae F_measurable h_lim,\nlet b := \u03bb a, 2 * ennreal.of_real (bound a) in\n/- `\u2225F n a\u2225 \u2264 bound a` and `F n a --> f a` implies `\u2225f a\u2225 \u2264 bound a`, and thus by the\n  triangle inequality, have `\u2225F n a - f a\u2225 \u2264 2 * (bound a). -/\nhave hb : \u2200 n, \u2200\u1d50 a \u2202\u03bc, ennreal.of_real \u2225F n a - f a\u2225 \u2264 b a,\nbegin\n  assume n,\n  filter_upwards [all_ae_of_real_F_le_bound h_bound n, all_ae_of_real_f_le_bound h_bound h_lim],\n  assume a h\u2081 h\u2082,\n  calc ennreal.of_real \u2225F n a - f a\u2225 \u2264 (ennreal.of_real \u2225F n a\u2225) + (ennreal.of_real \u2225f a\u2225) :\n  begin\n    rw [\u2190 ennreal.of_real_add],\n    apply of_real_le_of_real,\n    { apply norm_sub_le }, { exact norm_nonneg _ }, { exact norm_nonneg _ }\n  end\n    ... \u2264 (ennreal.of_real (bound a)) + (ennreal.of_real (bound a)) : add_le_add h\u2081 h\u2082\n    ... = b a : by rw \u2190 two_mul\nend,\n/- On the other hand, `F n a --> f a` implies that `\u2225F n a - f a\u2225 --> 0`  -/\nhave h : \u2200\u1d50 a \u2202\u03bc, tendsto (\u03bb n, ennreal.of_real \u2225F n a - f a\u2225) at_top (\ud835\udcdd 0),\nbegin\n  rw \u2190 ennreal.of_real_zero,\n  refine h_lim.mono (\u03bb a h, (continuous_of_real.tendsto _).comp _),\n  rwa \u2190 tendsto_iff_norm_tendsto_zero\nend,\n/- Therefore, by the dominated convergence theorem for nonnegative integration, have\n  ` \u222b \u2225f a - F n a\u2225 --> 0 ` -/\nbegin\n  suffices h : tendsto (\u03bbn, \u222b\u207b a, (ennreal.of_real \u2225F n a - f a\u2225) \u2202\u03bc) at_top (\ud835\udcdd (\u222b\u207b (a:\u03b1), 0 \u2202\u03bc)),\n  { rwa lintegral_zero at h },\n  -- Using the dominated convergence theorem.\n  refine tendsto_lintegral_of_dominated_convergence' _ _ hb _ _,\n  -- Show `\u03bba, \u2225f a - F n a\u2225` is almost everywhere measurable for all `n`\n  { exact \u03bbn, measurable_of_real.comp_ae_measurable ((F_measurable n).sub f_measurable).norm },\n  -- Show `2 * bound` is has_finite_integral\n  { rw has_finite_integral_iff_of_real at bound_has_finite_integral,\n    { calc \u222b\u207b a, b a \u2202\u03bc = 2 * \u222b\u207b a, ennreal.of_real (bound a) \u2202\u03bc :\n        by { rw lintegral_const_mul', exact coe_ne_top }\n        ... \u2260 \u221e : mul_ne_top coe_ne_top bound_has_finite_integral.ne },\n    filter_upwards [h_bound 0] \u03bb a h, le_trans (norm_nonneg _) h },\n  -- Show `\u2225f a - F n a\u2225 --> 0`\n  { exact h }\nend\n\nend dominated_convergence\n\nsection pos_part\n/-! Lemmas used for defining the positive part of a `L\u00b9` function -/\n\nlemma has_finite_integral.max_zero {f : \u03b1 \u2192 \u211d} (hf : has_finite_integral f \u03bc) :\n  has_finite_integral (\u03bba, max (f a) 0) \u03bc :=\nhf.mono $ eventually_of_forall $ \u03bb x, by simp [real.norm_eq_abs, abs_le, abs_nonneg, le_abs_self]\n\nlemma has_finite_integral.min_zero {f : \u03b1 \u2192 \u211d} (hf : has_finite_integral f \u03bc) :\n  has_finite_integral (\u03bba, min (f a) 0) \u03bc :=\nhf.mono $ eventually_of_forall $ \u03bb x,\n  by simp [real.norm_eq_abs, abs_le, abs_nonneg, neg_le, neg_le_abs_self, abs_eq_max_neg, le_total]\n\nend pos_part\n\nsection normed_space\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [normed_space \ud835\udd5c \u03b2]\n\nlemma has_finite_integral.smul (c : \ud835\udd5c) {f : \u03b1 \u2192 \u03b2} : has_finite_integral f \u03bc \u2192\n  has_finite_integral (c \u2022 f) \u03bc :=\nbegin\n  simp only [has_finite_integral], assume hfi,\n  calc\n    \u222b\u207b (a : \u03b1), nnnorm (c \u2022 f a) \u2202\u03bc = \u222b\u207b (a : \u03b1), (nnnorm c) * nnnorm (f a) \u2202\u03bc :\n      by simp only [nnnorm_smul, ennreal.coe_mul]\n    ... < \u221e :\n    begin\n      rw lintegral_const_mul',\n      exacts [mul_lt_top coe_ne_top hfi.ne, coe_ne_top]\n    end\nend\n\nlemma has_finite_integral_smul_iff {c : \ud835\udd5c} (hc : c \u2260 0) (f : \u03b1 \u2192 \u03b2) :\n  has_finite_integral (c \u2022 f) \u03bc \u2194 has_finite_integral f \u03bc :=\nbegin\n  split,\n  { assume h,\n    simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.smul c\u207b\u00b9 },\n  exact has_finite_integral.smul _\nend\n\nlemma has_finite_integral.const_mul {f : \u03b1 \u2192 \u211d} (h : has_finite_integral f \u03bc) (c : \u211d) :\n  has_finite_integral (\u03bb x, c * f x) \u03bc :=\n(has_finite_integral.smul c h : _)\n\nlemma has_finite_integral.mul_const {f : \u03b1 \u2192 \u211d} (h : has_finite_integral f \u03bc) (c : \u211d) :\n  has_finite_integral (\u03bb x, f x * c) \u03bc :=\nby simp_rw [mul_comm, h.const_mul _]\n\nend normed_space\n\n/-! ### The predicate `integrable` -/\n\nvariables [measurable_space \u03b2] [measurable_space \u03b3] [measurable_space \u03b4]\n\n/-- `integrable f \u03bc` means that `f` is measurable and that the integral `\u222b\u207b a, \u2225f a\u2225 \u2202\u03bc` is finite.\n  `integrable f` means `integrable f volume`. -/\ndef integrable {\u03b1} {m : measurable_space \u03b1} (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1 . volume_tac) : Prop :=\nae_measurable f \u03bc \u2227 has_finite_integral f \u03bc\n\nlemma integrable.ae_measurable {f : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc) : ae_measurable f \u03bc := hf.1\nlemma integrable.has_finite_integral {f : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc) : has_finite_integral f \u03bc :=\nhf.2\n\nlemma integrable.mono {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} (hg : integrable g \u03bc) (hf : ae_measurable f \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 \u2264 \u2225g a\u2225) : integrable f \u03bc :=\n\u27e8hf, hg.has_finite_integral.mono h\u27e9\n\nlemma integrable.mono' {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u211d} (hg : integrable g \u03bc) (hf : ae_measurable f \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 \u2264 g a) : integrable f \u03bc :=\n\u27e8hf, hg.has_finite_integral.mono' h\u27e9\n\nlemma integrable.congr' {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} (hf : integrable f \u03bc) (hg : ae_measurable g \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 = \u2225g a\u2225) : integrable g \u03bc :=\n\u27e8hg, hf.has_finite_integral.congr' h\u27e9\n\nlemma integrable_congr' {f : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u03b3} (hf : ae_measurable f \u03bc) (hg : ae_measurable g \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f a\u2225 = \u2225g a\u2225) : integrable f \u03bc \u2194 integrable g \u03bc :=\n\u27e8\u03bb h2f, h2f.congr' hg h, \u03bb h2g, h2g.congr' hf $ eventually_eq.symm h\u27e9\n\nlemma integrable.congr {f g : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc) (h : f =\u1d50[\u03bc] g) :\n  integrable g \u03bc :=\n\u27e8hf.1.congr h, hf.2.congr h\u27e9\n\nlemma integrable_congr {f g : \u03b1 \u2192 \u03b2} (h : f =\u1d50[\u03bc] g) :\n  integrable f \u03bc \u2194 integrable g \u03bc :=\n\u27e8\u03bb hf, hf.congr h, \u03bb hg, hg.congr h.symm\u27e9\n\nlemma integrable_const_iff {c : \u03b2} : integrable (\u03bb x : \u03b1, c) \u03bc \u2194 c = 0 \u2228 \u03bc univ < \u221e :=\nbegin\n  have : ae_measurable (\u03bb (x : \u03b1), c) \u03bc := measurable_const.ae_measurable,\n  rw [integrable, and_iff_right this, has_finite_integral_const_iff]\nend\n\nlemma integrable_const [is_finite_measure \u03bc] (c : \u03b2) : integrable (\u03bb x : \u03b1, c) \u03bc :=\nintegrable_const_iff.2 $ or.inr $ measure_lt_top _ _\n\nlemma integrable.mono_measure {f : \u03b1 \u2192 \u03b2} (h : integrable f \u03bd) (h\u03bc : \u03bc \u2264 \u03bd) : integrable f \u03bc :=\n\u27e8h.ae_measurable.mono_measure h\u03bc, h.has_finite_integral.mono_measure h\u03bc\u27e9\n\nlemma integrable.add_measure {f : \u03b1 \u2192 \u03b2} (h\u03bc : integrable f \u03bc) (h\u03bd : integrable f \u03bd) :\n  integrable f (\u03bc + \u03bd) :=\n\u27e8h\u03bc.ae_measurable.add_measure h\u03bd.ae_measurable,\n  h\u03bc.has_finite_integral.add_measure h\u03bd.has_finite_integral\u27e9\n\nlemma integrable.left_of_add_measure {f : \u03b1 \u2192 \u03b2} (h : integrable f (\u03bc + \u03bd)) : integrable f \u03bc :=\nh.mono_measure $ measure.le_add_right $ le_refl _\n\nlemma integrable.right_of_add_measure {f : \u03b1 \u2192 \u03b2} (h : integrable f (\u03bc + \u03bd)) : integrable f \u03bd :=\nh.mono_measure $ measure.le_add_left $ le_refl _\n\n@[simp] lemma integrable_add_measure {f : \u03b1 \u2192 \u03b2} :\n  integrable f (\u03bc + \u03bd) \u2194 integrable f \u03bc \u2227 integrable f \u03bd :=\n\u27e8\u03bb h, \u27e8h.left_of_add_measure, h.right_of_add_measure\u27e9, \u03bb h, h.1.add_measure h.2\u27e9\n\nlemma integrable.smul_measure {f : \u03b1 \u2192 \u03b2} (h : integrable f \u03bc) {c : \u211d\u22650\u221e} (hc : c \u2260 \u221e) :\n  integrable f (c \u2022 \u03bc) :=\n\u27e8h.ae_measurable.smul_measure c, h.has_finite_integral.smul_measure hc\u27e9\n\nlemma integrable_map_measure [opens_measurable_space \u03b2] {f : \u03b1 \u2192 \u03b4} {g : \u03b4 \u2192 \u03b2}\n  (hg : ae_measurable g (measure.map f \u03bc)) (hf : measurable f) :\n  integrable g (measure.map f \u03bc) \u2194 integrable (g \u2218 f) \u03bc :=\nby simp [integrable, hg, hg.comp_measurable hf, has_finite_integral, lintegral_map' hg.ennnorm hf]\n\nlemma _root_.measurable_embedding.integrable_map_iff {f : \u03b1 \u2192 \u03b4} (hf : measurable_embedding f)\n  {g : \u03b4 \u2192 \u03b2} :\n  integrable g (measure.map f \u03bc) \u2194 integrable (g \u2218 f) \u03bc :=\nby simp only [integrable, hf.ae_measurable_map_iff, has_finite_integral, hf.lintegral_map]\n\nlemma integrable_map_equiv (f : \u03b1 \u2243\u1d50 \u03b4) (g : \u03b4 \u2192 \u03b2) :\n  integrable g (measure.map f \u03bc) \u2194 integrable (g \u2218 f) \u03bc :=\nf.measurable_embedding.integrable_map_iff\n\nlemma measure_preserving.integrable_comp [opens_measurable_space \u03b2] {\u03bd : measure \u03b4} {g : \u03b4 \u2192 \u03b2}\n  {f : \u03b1 \u2192 \u03b4} (hf : measure_preserving f \u03bc \u03bd) (hg : ae_measurable g \u03bd) :\n  integrable (g \u2218 f) \u03bc \u2194 integrable g \u03bd :=\nby { rw \u2190 hf.map_eq at hg \u22a2, exact (integrable_map_measure hg hf.measurable).symm }\n\nlemma measure_preserving.integrable_comp_emb {f : \u03b1 \u2192 \u03b4} {\u03bd} (h\u2081 : measure_preserving f \u03bc \u03bd)\n  (h\u2082 : measurable_embedding f) {g : \u03b4 \u2192 \u03b2} :\n  integrable (g \u2218 f) \u03bc \u2194 integrable g \u03bd :=\nh\u2081.map_eq \u25b8 iff.symm h\u2082.integrable_map_iff\n\nlemma lintegral_edist_lt_top [second_countable_topology \u03b2] [opens_measurable_space \u03b2] {f g : \u03b1 \u2192 \u03b2}\n  (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  \u222b\u207b a, edist (f a) (g a) \u2202\u03bc < \u221e :=\nlt_of_le_of_lt\n  (lintegral_edist_triangle hf.ae_measurable hg.ae_measurable\n    (measurable_const.ae_measurable : ae_measurable (\u03bba, (0 : \u03b2)) \u03bc))\n  (ennreal.add_lt_top.2 $ by { simp_rw \u2190 has_finite_integral_iff_edist,\n                               exact \u27e8hf.has_finite_integral, hg.has_finite_integral\u27e9 })\n\nvariables (\u03b1 \u03b2 \u03bc)\n@[simp] lemma integrable_zero : integrable (\u03bb _, (0 : \u03b2)) \u03bc :=\nby simp [integrable, measurable_const.ae_measurable]\nvariables {\u03b1 \u03b2 \u03bc}\n\nlemma integrable.add' [opens_measurable_space \u03b2] {f g : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc)\n  (hg : integrable g \u03bc) :\n  has_finite_integral (f + g) \u03bc :=\ncalc \u222b\u207b a, nnnorm (f a + g a) \u2202\u03bc \u2264 \u222b\u207b a, nnnorm (f a) + nnnorm (g a) \u2202\u03bc :\n  lintegral_mono (\u03bb a, by exact_mod_cast nnnorm_add_le _ _)\n... = _ : lintegral_nnnorm_add hf.ae_measurable hg.ae_measurable\n... < \u221e : add_lt_top.2 \u27e8hf.has_finite_integral, hg.has_finite_integral\u27e9\n\nlemma integrable.add [borel_space \u03b2] [second_countable_topology \u03b2]\n  {f g : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc) (hg : integrable g \u03bc) : integrable (f + g) \u03bc :=\n\u27e8hf.ae_measurable.add hg.ae_measurable, hf.add' hg\u27e9\n\nlemma integrable_finset_sum {\u03b9} [borel_space \u03b2] [second_countable_topology \u03b2] (s : finset \u03b9)\n  {f : \u03b9 \u2192 \u03b1 \u2192 \u03b2} (hf : \u2200 i \u2208 s, integrable (f i) \u03bc) : integrable (\u03bb a, \u2211 i in s, f i a) \u03bc :=\nbegin\n  simp only [\u2190 finset.sum_apply],\n  exact finset.sum_induction f (\u03bb g, integrable g \u03bc) (\u03bb _ _, integrable.add)\n    (integrable_zero _ _ _) hf,\nend\n\nlemma integrable.neg [borel_space \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc) : integrable (-f) \u03bc :=\n\u27e8hf.ae_measurable.neg, hf.has_finite_integral.neg\u27e9\n\n@[simp] lemma integrable_neg_iff [borel_space \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  integrable (-f) \u03bc \u2194 integrable f \u03bc :=\n\u27e8\u03bb h, neg_neg f \u25b8 h.neg, integrable.neg\u27e9\n\nlemma integrable.sub' [opens_measurable_space \u03b2] {f g : \u03b1 \u2192 \u03b2}\n  (hf : integrable f \u03bc) (hg : integrable g \u03bc) : has_finite_integral (f - g) \u03bc :=\ncalc \u222b\u207b a, nnnorm (f a - g a) \u2202\u03bc \u2264 \u222b\u207b a, nnnorm (f a) + nnnorm (-g a) \u2202\u03bc :\n  lintegral_mono (assume a, by { simp only [sub_eq_add_neg], exact_mod_cast nnnorm_add_le _ _ } )\n... = _ :\n  by { simp only [nnnorm_neg], exact lintegral_nnnorm_add hf.ae_measurable hg.ae_measurable }\n... < \u221e : add_lt_top.2 \u27e8hf.has_finite_integral, hg.has_finite_integral\u27e9\n\nlemma integrable.sub [borel_space \u03b2] [second_countable_topology \u03b2] {f g : \u03b1 \u2192 \u03b2}\n  (hf : integrable f \u03bc) (hg : integrable g \u03bc) : integrable (f - g) \u03bc :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\nlemma integrable.norm [opens_measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc) :\n  integrable (\u03bba, \u2225f a\u2225) \u03bc :=\n\u27e8hf.ae_measurable.norm, hf.has_finite_integral.norm\u27e9\n\nlemma integrable_norm_iff [opens_measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : ae_measurable f \u03bc) :\n  integrable (\u03bba, \u2225f a\u2225) \u03bc \u2194 integrable f \u03bc :=\nby simp_rw [integrable, and_iff_right hf, and_iff_right hf.norm, has_finite_integral_norm_iff]\n\nlemma integrable_of_norm_sub_le [opens_measurable_space \u03b2] {f\u2080 f\u2081 : \u03b1 \u2192 \u03b2} {g : \u03b1 \u2192 \u211d}\n  (hf\u2081_m : ae_measurable f\u2081 \u03bc)\n  (hf\u2080_i : integrable f\u2080 \u03bc)\n  (hg_i : integrable g \u03bc)\n  (h : \u2200\u1d50 a \u2202\u03bc, \u2225f\u2080 a - f\u2081 a\u2225 \u2264 g a) :\n  integrable f\u2081 \u03bc :=\nbegin\n  have : \u2200\u1d50 a \u2202\u03bc, \u2225f\u2081 a\u2225 \u2264 \u2225f\u2080 a\u2225 + g a,\n  { apply h.mono,\n    intros a ha,\n    calc \u2225f\u2081 a\u2225 \u2264 \u2225f\u2080 a\u2225 + \u2225f\u2080 a - f\u2081 a\u2225 : norm_le_insert _ _\n    ... \u2264 \u2225f\u2080 a\u2225 + g a : add_le_add_left ha _ },\n  exact integrable.mono' (hf\u2080_i.norm.add hg_i) hf\u2081_m this\nend\n\nlemma integrable.prod_mk [opens_measurable_space \u03b2] [opens_measurable_space \u03b3] {f : \u03b1 \u2192 \u03b2}\n  {g : \u03b1 \u2192 \u03b3} (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  integrable (\u03bb x, (f x, g x)) \u03bc :=\n\u27e8hf.ae_measurable.prod_mk hg.ae_measurable,\n  (hf.norm.add' hg.norm).mono $ eventually_of_forall $ \u03bb x,\n  calc max \u2225f x\u2225 \u2225g x\u2225 \u2264 \u2225f x\u2225 + \u2225g x\u2225   : max_le_add_of_nonneg (norm_nonneg _) (norm_nonneg _)\n                 ... \u2264 \u2225(\u2225f x\u2225 + \u2225g x\u2225)\u2225 : le_abs_self _\u27e9\n\nlemma mem_\u2112p_one_iff_integrable {f : \u03b1 \u2192 \u03b2} : mem_\u2112p f 1 \u03bc \u2194 integrable f \u03bc :=\nby simp_rw [integrable, has_finite_integral, mem_\u2112p, snorm_one_eq_lintegral_nnnorm]\n\nlemma mem_\u2112p.integrable [borel_space \u03b2] {q : \u211d\u22650\u221e} (hq1 : 1 \u2264 q) {f : \u03b1 \u2192 \u03b2} [is_finite_measure \u03bc]\n  (hfq : mem_\u2112p f q \u03bc) : integrable f \u03bc :=\nmem_\u2112p_one_iff_integrable.mp (hfq.mem_\u2112p_of_exponent_le hq1)\n\nlemma lipschitz_with.integrable_comp_iff_of_antilipschitz [complete_space \u03b2] [borel_space \u03b2]\n  [borel_space \u03b3] {K K'} {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3} (hg : lipschitz_with K g)\n  (hg' : antilipschitz_with K' g) (g0 : g 0 = 0) :\n  integrable (g \u2218 f) \u03bc \u2194 integrable f \u03bc :=\nby simp [\u2190 mem_\u2112p_one_iff_integrable, hg.mem_\u2112p_comp_iff_of_antilipschitz hg' g0]\n\nlemma integrable.real_to_nnreal {f : \u03b1 \u2192 \u211d} (hf : integrable f \u03bc) :\n  integrable (\u03bb x, ((f x).to_nnreal : \u211d)) \u03bc :=\nbegin\n  refine \u27e8hf.ae_measurable.real_to_nnreal.coe_nnreal_real, _\u27e9,\n  rw has_finite_integral_iff_norm,\n  refine lt_of_le_of_lt _ ((has_finite_integral_iff_norm _).1 hf.has_finite_integral),\n  apply lintegral_mono,\n  assume x,\n  simp [real.norm_eq_abs, ennreal.of_real_le_of_real, abs_le, abs_nonneg, le_abs_self],\nend\n\nlemma of_real_to_real_ae_eq {f : \u03b1 \u2192 \u211d\u22650\u221e} (hf : \u2200\u1d50 x \u2202\u03bc, f x < \u221e) :\n  (\u03bb x, ennreal.of_real (f x).to_real) =\u1d50[\u03bc] f :=\nbegin\n  rw ae_iff at hf,\n  rw [filter.eventually_eq, ae_iff],\n  have : {x | \u00ac ennreal.of_real (f x).to_real = f x} = {x | f x = \u221e},\n  { ext x,\n    simp only [ne.def, set.mem_set_of_eq],\n    split; intro hx,\n    { by_contra hntop,\n      exact hx (ennreal.of_real_to_real hntop) },\n    { rw hx, simp } },\n  rw this,\n  simpa using hf,\nend\n\nlemma integrable_with_density_iff {f : \u03b1 \u2192 \u211d\u22650\u221e} (hf : measurable f)\n  (hflt : \u2200\u1d50 x \u2202\u03bc, f x < \u221e) {g : \u03b1 \u2192 \u211d} (hg : measurable g) :\n  integrable g (\u03bc.with_density f) \u2194 integrable (\u03bb x, g x * (f x).to_real) \u03bc :=\nbegin\n  simp only [integrable, has_finite_integral, hg.ae_measurable.mul hf.ae_measurable.ennreal_to_real,\n    hg.ae_measurable, true_and, coe_mul, normed_field.nnnorm_mul],\n  suffices h_int_eq : \u222b\u207b a, \u2225g a\u2225\u208a \u2202\u03bc.with_density f = \u222b\u207b a, \u2225g a\u2225\u208a * \u2225(f a).to_real\u2225\u208a \u2202\u03bc,\n    by rw h_int_eq,\n  rw lintegral_with_density_eq_lintegral_mul _ hf hg.nnnorm.coe_nnreal_ennreal,\n  refine lintegral_congr_ae _,\n  rw mul_comm,\n  refine filter.eventually_eq.mul (ae_eq_refl _) ((of_real_to_real_ae_eq hflt).symm.trans _),\n  convert ae_eq_refl _,\n  ext1 x,\n  exact real.ennnorm_eq_of_real ennreal.to_real_nonneg,\nend\n\nlemma mem_\u21121_to_real_of_lintegral_ne_top\n  {f : \u03b1 \u2192 \u211d\u22650\u221e} (hfm : ae_measurable f \u03bc) (hfi : \u222b\u207b x, f x \u2202\u03bc \u2260 \u221e) :\n  mem_\u2112p (\u03bb x, (f x).to_real) 1 \u03bc :=\nbegin\n  rw [mem_\u2112p, snorm_one_eq_lintegral_nnnorm],\n  exact \u27e8ae_measurable.ennreal_to_real hfm, has_finite_integral_to_real_of_lintegral_ne_top hfi\u27e9\nend\n\nlemma integrable_to_real_of_lintegral_ne_top\n  {f : \u03b1 \u2192 \u211d\u22650\u221e} (hfm : ae_measurable f \u03bc) (hfi : \u222b\u207b x, f x \u2202\u03bc \u2260 \u221e) :\n  integrable (\u03bb x, (f x).to_real) \u03bc :=\nmem_\u2112p_one_iff_integrable.1 $ mem_\u21121_to_real_of_lintegral_ne_top hfm hfi\n\nsection pos_part\n/-! ### Lemmas used for defining the positive part of a `L\u00b9` function -/\n\nlemma integrable.max_zero {f : \u03b1 \u2192 \u211d} (hf : integrable f \u03bc) : integrable (\u03bba, max (f a) 0) \u03bc :=\n\u27e8hf.ae_measurable.max measurable_const.ae_measurable, hf.has_finite_integral.max_zero\u27e9\n\nlemma integrable.min_zero {f : \u03b1 \u2192 \u211d} (hf : integrable f \u03bc) : integrable (\u03bba, min (f a) 0) \u03bc :=\n\u27e8hf.ae_measurable.min measurable_const.ae_measurable, hf.has_finite_integral.min_zero\u27e9\n\nend pos_part\n\nsection normed_space\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [normed_space \ud835\udd5c \u03b2] [measurable_space \ud835\udd5c]\n  [opens_measurable_space \ud835\udd5c]\n\nlemma integrable.smul [borel_space \u03b2] (c : \ud835\udd5c) {f : \u03b1 \u2192 \u03b2}\n  (hf : integrable f \u03bc) : integrable (c \u2022 f) \u03bc :=\n\u27e8hf.ae_measurable.const_smul c, hf.has_finite_integral.smul c\u27e9\n\nlemma integrable_smul_iff [borel_space \u03b2] {c : \ud835\udd5c} (hc : c \u2260 0) (f : \u03b1 \u2192 \u03b2) :\n  integrable (c \u2022 f) \u03bc \u2194 integrable f \u03bc :=\nand_congr (ae_measurable_const_smul_iff\u2080 hc) (has_finite_integral_smul_iff hc f)\n\nlemma integrable.const_mul {f : \u03b1 \u2192 \u211d} (h : integrable f \u03bc) (c : \u211d) :\n  integrable (\u03bb x, c * f x) \u03bc :=\nintegrable.smul c h\n\nlemma integrable.mul_const {f : \u03b1 \u2192 \u211d} (h : integrable f \u03bc) (c : \u211d) :\n  integrable (\u03bb x, f x * c) \u03bc :=\nby simp_rw [mul_comm, h.const_mul _]\n\nend normed_space\n\nsection normed_space_over_complete_field\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c] [complete_space \ud835\udd5c] [measurable_space \ud835\udd5c]\nvariables [borel_space \ud835\udd5c]\nvariables {E : Type*} [normed_group E] [normed_space \ud835\udd5c E] [measurable_space E] [borel_space E]\n\nlemma integrable_smul_const {f : \u03b1 \u2192 \ud835\udd5c} {c : E} (hc : c \u2260 0) :\n  integrable (\u03bb x, f x \u2022 c) \u03bc \u2194 integrable f \u03bc :=\nbegin\n  simp_rw [integrable, ae_measurable_smul_const hc, and.congr_right_iff, has_finite_integral,\n    nnnorm_smul, ennreal.coe_mul],\n  intro hf, rw [lintegral_mul_const' _ _ ennreal.coe_ne_top, ennreal.mul_lt_top_iff],\n  have : \u2200 x : \u211d\u22650\u221e, x = 0 \u2192 x < \u221e := by simp,\n  simp [hc, or_iff_left_of_imp (this _)]\nend\nend normed_space_over_complete_field\n\nsection is_R_or_C\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {f : \u03b1 \u2192 \ud835\udd5c}\n\n\n\nlemma integrable.re_im_iff :\n  integrable (\u03bb x, is_R_or_C.re (f x)) \u03bc \u2227 integrable (\u03bb x, is_R_or_C.im (f x)) \u03bc \u2194\n  integrable f \u03bc :=\nby { simp_rw \u2190 mem_\u2112p_one_iff_integrable, exact mem_\u2112p_re_im_iff }\n\nlemma integrable.re (hf : integrable f \u03bc) : integrable (\u03bb x, is_R_or_C.re (f x)) \u03bc :=\nby { rw \u2190 mem_\u2112p_one_iff_integrable at hf \u22a2, exact hf.re, }\n\nlemma integrable.im (hf : integrable f \u03bc) : integrable (\u03bb x, is_R_or_C.im (f x)) \u03bc :=\nby { rw \u2190 mem_\u2112p_one_iff_integrable at hf \u22a2, exact hf.im, }\n\nend is_R_or_C\n\nsection inner_product\nvariables {\ud835\udd5c E : Type*} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c E]\n  [measurable_space E] [opens_measurable_space E] [second_countable_topology E]\n  {f : \u03b1 \u2192 E}\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c E _ x y\n\nlemma integrable.const_inner (c : E) (hf : integrable f \u03bc) : integrable (\u03bb x, \u27eac, f x\u27eb) \u03bc :=\nby { rw \u2190 mem_\u2112p_one_iff_integrable at hf \u22a2, exact hf.const_inner c, }\n\nlemma integrable.inner_const (hf : integrable f \u03bc) (c : E) : integrable (\u03bb x, \u27eaf x, c\u27eb) \u03bc :=\nby { rw \u2190 mem_\u2112p_one_iff_integrable at hf \u22a2, exact hf.inner_const c, }\n\nend inner_product\n\nsection trim\n\nvariables {H : Type*} [normed_group H] [measurable_space H] [opens_measurable_space H]\n  {m0 : measurable_space \u03b1} {\u03bc' : measure \u03b1} {f : \u03b1 \u2192 H}\n\nlemma integrable.trim (hm : m \u2264 m0) (hf_int : integrable f \u03bc') (hf : @measurable _ _ m _ f) :\n  integrable f (\u03bc'.trim hm) :=\nbegin\n  refine \u27e8measurable.ae_measurable hf, _\u27e9,\n  rw [has_finite_integral, lintegral_trim hm _],\n  { exact hf_int.2, },\n  { exact @measurable.coe_nnreal_ennreal \u03b1 m _ (@measurable.nnnorm _ \u03b1 _ _ _ m _ hf), },\nend\n\nlemma integrable_of_integrable_trim (hm : m \u2264 m0) (hf_int : integrable f (\u03bc'.trim hm)) :\n  integrable f \u03bc' :=\nbegin\n  obtain \u27e8hf_meas_ae, hf\u27e9 := hf_int,\n  refine \u27e8ae_measurable_of_ae_measurable_trim hm hf_meas_ae, _\u27e9,\n  rw has_finite_integral at hf \u22a2,\n  rwa lintegral_trim_ae hm _ at hf,\n  exact @ae_measurable.coe_nnreal_ennreal \u03b1 m _ _\n    (@ae_measurable.nnnorm H \u03b1 _ _ _ m _ _ hf_meas_ae),\nend\n\nend trim\n\nsection sigma_finite\n\nvariables {E : Type*} {m0 : measurable_space \u03b1} [normed_group E] [measurable_space E]\n  [opens_measurable_space E]\n\nlemma integrable_of_forall_fin_meas_le' {\u03bc : measure \u03b1} (hm : m \u2264 m0)\n  [sigma_finite (\u03bc.trim hm)] (C : \u211d\u22650\u221e) (hC : C < \u221e) {f : \u03b1 \u2192 E} (hf_meas : ae_measurable f \u03bc)\n  (hf : \u2200 s, measurable_set[m] s \u2192 \u03bc s \u2260 \u221e \u2192 \u222b\u207b x in s, nnnorm (f x) \u2202\u03bc \u2264 C) :\n  integrable f \u03bc :=\n\u27e8hf_meas,\n  (lintegral_le_of_forall_fin_meas_le' hm C hf_meas.nnnorm.coe_nnreal_ennreal hf).trans_lt hC\u27e9\n\nlemma integrable_of_forall_fin_meas_le [sigma_finite \u03bc]\n  (C : \u211d\u22650\u221e) (hC : C < \u221e) {f : \u03b1 \u2192 E} (hf_meas : ae_measurable f \u03bc)\n  (hf : \u2200 s : set \u03b1, measurable_set s \u2192 \u03bc s \u2260 \u221e \u2192 \u222b\u207b x in s, nnnorm (f x) \u2202\u03bc \u2264 C) :\n  integrable f \u03bc :=\n@integrable_of_forall_fin_meas_le' _ _ _ _ _ _ _ _ _ (by rwa trim_eq_self) C hC _ hf_meas hf\n\nend sigma_finite\n\n/-! ### The predicate `integrable` on measurable functions modulo a.e.-equality -/\n\nnamespace ae_eq_fun\n\nsection\n\n/-- A class of almost everywhere equal functions is `integrable` if its function representative\nis integrable. -/\ndef integrable (f : \u03b1 \u2192\u2098[\u03bc] \u03b2) : Prop := integrable f \u03bc\n\nlemma integrable_mk {f : \u03b1 \u2192 \u03b2} (hf : ae_measurable f \u03bc ) :\n  (integrable (mk f hf : \u03b1 \u2192\u2098[\u03bc] \u03b2)) \u2194 measure_theory.integrable f \u03bc :=\nbegin\n  simp [integrable],\n  apply integrable_congr,\n  exact coe_fn_mk f hf\nend\n\nlemma integrable_coe_fn {f : \u03b1 \u2192\u2098[\u03bc] \u03b2} : (measure_theory.integrable f \u03bc) \u2194 integrable f :=\nby rw [\u2190 integrable_mk, mk_coe_fn]\n\nlemma integrable_zero : integrable (0 : \u03b1 \u2192\u2098[\u03bc] \u03b2) :=\n(integrable_zero \u03b1 \u03b2 \u03bc).congr (coe_fn_mk _ _).symm\n\nend\n\nsection\n\nvariables [borel_space \u03b2]\n\nlemma integrable.neg {f : \u03b1 \u2192\u2098[\u03bc] \u03b2} : integrable f \u2192 integrable (-f) :=\ninduction_on f $ \u03bb f hfm hfi, (integrable_mk _).2 ((integrable_mk hfm).1 hfi).neg\n\nsection\nvariable [second_countable_topology \u03b2]\n\nlemma integrable_iff_mem_L1 {f : \u03b1 \u2192\u2098[\u03bc] \u03b2} : integrable f \u2194 f \u2208 (\u03b1 \u2192\u2081[\u03bc] \u03b2) :=\nby rw [\u2190 integrable_coe_fn, \u2190 mem_\u2112p_one_iff_integrable, Lp.mem_Lp_iff_mem_\u2112p]\n\nlemma integrable.add {f g : \u03b1 \u2192\u2098[\u03bc] \u03b2} : integrable f \u2192 integrable g \u2192 integrable (f + g) :=\nbegin\n  refine induction_on\u2082 f g (\u03bb f hf g hg hfi hgi, _),\n  simp only [integrable_mk, mk_add_mk] at hfi hgi \u22a2,\n  exact hfi.add hgi\nend\n\nlemma integrable.sub {f g : \u03b1 \u2192\u2098[\u03bc] \u03b2} (hf : integrable f) (hg : integrable g) :\n  integrable (f - g) :=\n(sub_eq_add_neg f g).symm \u25b8 hf.add hg.neg\n\nend\n\nsection normed_space\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [normed_space \ud835\udd5c \u03b2] [measurable_space \ud835\udd5c]\n  [opens_measurable_space \ud835\udd5c]\n\nlemma integrable.smul {c : \ud835\udd5c} {f : \u03b1 \u2192\u2098[\u03bc] \u03b2} : integrable f \u2192 integrable (c \u2022 f) :=\ninduction_on f $ \u03bb f hfm hfi, (integrable_mk _).2 $ ((integrable_mk hfm).1 hfi).smul _\n\nend normed_space\n\nend\n\nend ae_eq_fun\n\nnamespace L1\nvariables [second_countable_topology \u03b2] [borel_space \u03b2]\n\nlemma integrable_coe_fn (f : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  integrable f \u03bc :=\nby { rw \u2190 mem_\u2112p_one_iff_integrable, exact Lp.mem_\u2112p f }\n\nlemma has_finite_integral_coe_fn (f : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  has_finite_integral f \u03bc :=\n(integrable_coe_fn f).has_finite_integral\n\nlemma measurable_coe_fn (f : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  measurable f := Lp.measurable f\n\nlemma ae_measurable_coe_fn (f : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  ae_measurable f \u03bc := Lp.ae_measurable f\n\nlemma edist_def (f g : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  edist f g = \u222b\u207b a, edist (f a) (g a) \u2202\u03bc :=\nby { simp [Lp.edist_def, snorm, snorm'], simp [edist_eq_coe_nnnorm_sub] }\n\nlemma dist_def (f g : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  dist f g = (\u222b\u207b a, edist (f a) (g a) \u2202\u03bc).to_real :=\nby { simp [Lp.dist_def, snorm, snorm'], simp [edist_eq_coe_nnnorm_sub] }\n\nlemma norm_def (f : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  \u2225f\u2225 = (\u222b\u207b a, nnnorm (f a) \u2202\u03bc).to_real :=\nby { simp [Lp.norm_def, snorm, snorm'] }\n\n/-- Computing the norm of a difference between two L\u00b9-functions. Note that this is not a\n  special case of `norm_def` since `(f - g) x` and `f x - g x` are not equal\n  (but only a.e.-equal). -/\nlemma norm_sub_eq_lintegral (f g : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  \u2225f - g\u2225 = (\u222b\u207b x, (nnnorm (f x - g x) : \u211d\u22650\u221e) \u2202\u03bc).to_real :=\nbegin\n  rw [norm_def],\n  congr' 1,\n  rw lintegral_congr_ae,\n  filter_upwards [Lp.coe_fn_sub f g],\n  assume a ha,\n  simp only [ha, pi.sub_apply],\nend\n\nlemma of_real_norm_eq_lintegral (f : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  ennreal.of_real \u2225f\u2225 = \u222b\u207b x, (nnnorm (f x) : \u211d\u22650\u221e) \u2202\u03bc :=\nby { rw [norm_def, ennreal.of_real_to_real], exact ne_of_lt (has_finite_integral_coe_fn f) }\n\n/-- Computing the norm of a difference between two L\u00b9-functions. Note that this is not a\n  special case of `of_real_norm_eq_lintegral` since `(f - g) x` and `f x - g x` are not equal\n  (but only a.e.-equal). -/\nlemma of_real_norm_sub_eq_lintegral (f g : \u03b1 \u2192\u2081[\u03bc] \u03b2) :\n  ennreal.of_real \u2225f - g\u2225 = \u222b\u207b x, (nnnorm (f x - g x) : \u211d\u22650\u221e) \u2202\u03bc :=\nbegin\n  simp_rw [of_real_norm_eq_lintegral, \u2190 edist_eq_coe_nnnorm],\n  apply lintegral_congr_ae,\n  filter_upwards [Lp.coe_fn_sub f g],\n  assume a ha,\n  simp only [ha, pi.sub_apply],\nend\n\nend L1\n\nnamespace integrable\n\nvariables [second_countable_topology \u03b2] [borel_space \u03b2]\n\n/-- Construct the equivalence class `[f]` of an integrable function `f`, as a member of the\nspace `L1 \u03b2 1 \u03bc`. -/\ndef to_L1 (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) : \u03b1 \u2192\u2081[\u03bc] \u03b2 :=\n(mem_\u2112p_one_iff_integrable.2 hf).to_Lp f\n\n@[simp] lemma to_L1_coe_fn (f : \u03b1 \u2192\u2081[\u03bc] \u03b2) (hf : integrable f \u03bc) : hf.to_L1 f = f :=\nby simp [integrable.to_L1]\n\nlemma coe_fn_to_L1 {f : \u03b1 \u2192 \u03b2} (hf : integrable f \u03bc) : hf.to_L1 f =\u1d50[\u03bc] f :=\nae_eq_fun.coe_fn_mk _ _\n\n@[simp] lemma to_L1_zero (h : integrable (0 : \u03b1 \u2192 \u03b2) \u03bc) : h.to_L1 0 = 0 := rfl\n\n@[simp] lemma to_L1_eq_mk (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) :\n  (hf.to_L1 f : \u03b1 \u2192\u2098[\u03bc] \u03b2) = ae_eq_fun.mk f hf.ae_measurable :=\nrfl\n\n@[simp] lemma to_L1_eq_to_L1_iff (f g : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  to_L1 f hf = to_L1 g hg \u2194 f =\u1d50[\u03bc] g :=\nmem_\u2112p.to_Lp_eq_to_Lp_iff _ _\n\nlemma to_L1_add (f g : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  to_L1 (f + g) (hf.add hg) = to_L1 f hf + to_L1 g hg := rfl\n\nlemma to_L1_neg (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) :\n  to_L1 (- f) (integrable.neg hf) = - to_L1 f hf := rfl\n\nlemma to_L1_sub (f g : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  to_L1 (f - g) (hf.sub hg) = to_L1 f hf - to_L1 g hg := rfl\n\nlemma norm_to_L1 (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) :\n  \u2225hf.to_L1 f\u2225 = ennreal.to_real (\u222b\u207b a, edist (f a) 0 \u2202\u03bc) :=\nby { simp [to_L1, snorm, snorm'], simp [edist_eq_coe_nnnorm] }\n\nlemma norm_to_L1_eq_lintegral_norm (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) :\n  \u2225hf.to_L1 f\u2225 = ennreal.to_real (\u222b\u207b a, (ennreal.of_real \u2225f a\u2225) \u2202\u03bc) :=\nby { rw [norm_to_L1, lintegral_norm_eq_lintegral_edist] }\n\n@[simp] lemma edist_to_L1_to_L1 (f g : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  edist (hf.to_L1 f) (hg.to_L1 g) = \u222b\u207b a, edist (f a) (g a) \u2202\u03bc :=\nby { simp [integrable.to_L1, snorm, snorm'], simp [edist_eq_coe_nnnorm_sub] }\n\n@[simp] lemma edist_to_L1_zero (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) :\n  edist (hf.to_L1 f) 0 = \u222b\u207b a, edist (f a) 0 \u2202\u03bc :=\nby { simp [integrable.to_L1, snorm, snorm'], simp [edist_eq_coe_nnnorm] }\n\nvariables {\ud835\udd5c : Type*} [normed_field \ud835\udd5c] [normed_space \ud835\udd5c \u03b2] [measurable_space \ud835\udd5c]\n  [opens_measurable_space \ud835\udd5c]\n\nlemma to_L1_smul (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) (k : \ud835\udd5c) :\n  to_L1 (\u03bb a, k \u2022 f a) (hf.smul k) = k \u2022 to_L1 f hf := rfl\n\nlemma to_L1_smul' (f : \u03b1 \u2192 \u03b2) (hf : integrable f \u03bc) (k : \ud835\udd5c) :\n  to_L1 (k \u2022 f) (hf.smul k) = k \u2022 to_L1 f hf := rfl\n\nend integrable\n\nend measure_theory\n\nopen measure_theory\n\nlemma integrable_zero_measure {m : measurable_space \u03b1} [measurable_space \u03b2] {f : \u03b1 \u2192 \u03b2} :\n  integrable f (0 : measure \u03b1) :=\nbegin\n  apply (integrable_zero _ _ _).congr,\n  change (0 : measure \u03b1) {x | 0 \u2260 f x} = 0,\n  refl,\nend\n\nvariables {E : Type*} [normed_group E] [measurable_space E] [borel_space E]\n          {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c] [normed_space \ud835\udd5c E]\n          {H : Type*} [normed_group H] [normed_space \ud835\udd5c H]\n\nlemma measure_theory.integrable.apply_continuous_linear_map {\u03c6 : \u03b1 \u2192 H \u2192L[\ud835\udd5c] E}\n  (\u03c6_int : integrable \u03c6 \u03bc) (v : H) : integrable (\u03bb a, \u03c6 a v) \u03bc :=\n(\u03c6_int.norm.mul_const \u2225v\u2225).mono' (\u03c6_int.ae_measurable.apply_continuous_linear_map v)\n  (eventually_of_forall $ \u03bb a, (\u03c6 a).le_op_norm v)\n\nvariables [measurable_space H] [opens_measurable_space H]\n\nlemma continuous_linear_map.integrable_comp {\u03c6 : \u03b1 \u2192 H} (L : H \u2192L[\ud835\udd5c] E)\n  (\u03c6_int : integrable \u03c6 \u03bc) : integrable (\u03bb (a : \u03b1), L (\u03c6 a)) \u03bc :=\n((integrable.norm \u03c6_int).const_mul \u2225L\u2225).mono' (L.measurable.comp_ae_measurable \u03c6_int.ae_measurable)\n  (eventually_of_forall $ \u03bb a, L.le_op_norm (\u03c6 a))\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/measure_theory/function/l1_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.704659851779183}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.fintype.basic\nimport data.finset.card\nimport data.list.nodup_equiv_fin\nimport tactic.positivity\nimport tactic.wlog\n\n/-!\n# Cardinalities of finite types\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main declarations\n\n* `fintype.card \u03b1`: Cardinality of a fintype. Equal to `finset.univ.card`.\n* `fintype.trunc_equiv_fin`: A fintype `\u03b1` is computably equivalent to `fin (card \u03b1)`. The\n  `trunc`-free, noncomputable version is `fintype.equiv_fin`.\n* `fintype.trunc_equiv_of_card_eq` `fintype.equiv_of_card_eq`: Two fintypes of same cardinality are\n  equivalent. See above.\n* `fin.equiv_iff_eq`: `fin m \u2243 fin n` iff `m = n`.\n* `infinite.nat_embedding`: An embedding of `\u2115` into an infinite type.\n\nWe also provide the following versions of the pigeonholes principle.\n* `fintype.exists_ne_map_eq_of_card_lt` and `is_empty_of_card_lt`: Finitely many pigeons and\n  pigeonholes. Weak formulation.\n* `finite.exists_ne_map_eq_of_infinite`: Infinitely many pigeons in finitely many pigeonholes.\n  Weak formulation.\n* `finite.exists_infinite_fiber`: Infinitely many pigeons in finitely many pigeonholes. Strong\n  formulation.\n\nSome more pigeonhole-like statements can be found in `data.fintype.card_embedding`.\n\nTypes which have an injection from/a surjection to an `infinite` type are themselves `infinite`.\nSee `infinite.of_injective` and `infinite.of_surjective`.\n\n## Instances\n\nWe provide `infinite` instances for\n* specific types: `\u2115`, `\u2124`\n* type constructors: `multiset \u03b1`, `list \u03b1`\n\n-/\n\nopen function\nopen_locale nat\n\nuniverses u v\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\nopen finset function\n\nnamespace fintype\n\n/-- `card \u03b1` is the number of elements in `\u03b1`, defined when `\u03b1` is a fintype. -/\ndef card (\u03b1) [fintype \u03b1] : \u2115 := (@univ \u03b1 _).card\n\n/-- There is (computably) an equivalence between `\u03b1` and `fin (card \u03b1)`.\n\nSince it is not unique and depends on which permutation\nof the universe list is used, the equivalence is wrapped in `trunc` to\npreserve computability.\n\nSee `fintype.equiv_fin` for the noncomputable version,\nand `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq`\nfor an equiv `\u03b1 \u2243 fin n` given `fintype.card \u03b1 = n`.\n\nSee `fintype.trunc_fin_bijection` for a version without `[decidable_eq \u03b1]`.\n-/\ndef trunc_equiv_fin (\u03b1) [decidable_eq \u03b1] [fintype \u03b1] : trunc (\u03b1 \u2243 fin (card \u03b1)) :=\nby { unfold card finset.card,\n     exact quot.rec_on_subsingleton (@univ \u03b1 _).1\n       (\u03bb l (h : \u2200 x : \u03b1, x \u2208 l) (nd : l.nodup),\n         trunc.mk (nd.nth_le_equiv_of_forall_mem_list _ h).symm)\n       mem_univ_val univ.2 }\n\n/-- There is (noncomputably) an equivalence between `\u03b1` and `fin (card \u03b1)`.\n\nSee `fintype.trunc_equiv_fin` for the computable version,\nand `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq`\nfor an equiv `\u03b1 \u2243 fin n` given `fintype.card \u03b1 = n`.\n-/\nnoncomputable def equiv_fin (\u03b1) [fintype \u03b1] : \u03b1 \u2243 fin (card \u03b1) :=\nby { letI := classical.dec_eq \u03b1, exact (trunc_equiv_fin \u03b1).out }\n\n/-- There is (computably) a bijection between `fin (card \u03b1)` and `\u03b1`.\n\nSince it is not unique and depends on which permutation\nof the universe list is used, the bijection is wrapped in `trunc` to\npreserve computability.\n\nSee `fintype.trunc_equiv_fin` for a version that gives an equivalence\ngiven `[decidable_eq \u03b1]`.\n-/\ndef trunc_fin_bijection (\u03b1) [fintype \u03b1] :\n  trunc {f : fin (card \u03b1) \u2192 \u03b1 // bijective f} :=\nby { dunfold card finset.card,\n     exact quot.rec_on_subsingleton (@univ \u03b1 _).1\n       (\u03bb l (h : \u2200 x : \u03b1, x \u2208 l) (nd : l.nodup),\n         trunc.mk (nd.nth_le_bijection_of_forall_mem_list _ h))\n       mem_univ_val univ.2 }\n\ntheorem subtype_card {p : \u03b1 \u2192 Prop} (s : finset \u03b1) (H : \u2200 x : \u03b1, x \u2208 s \u2194 p x) :\n  @card {x // p x} (fintype.subtype s H) = s.card :=\nmultiset.card_pmap _ _ _\n\ntheorem card_of_subtype {p : \u03b1 \u2192 Prop} (s : finset \u03b1) (H : \u2200 x : \u03b1, x \u2208 s \u2194 p x)\n  [fintype {x // p x}] :\n  card {x // p x} = s.card :=\nby { rw \u2190 subtype_card s H, congr }\n\n@[simp] theorem card_of_finset {p : set \u03b1} (s : finset \u03b1) (H : \u2200 x, x \u2208 s \u2194 x \u2208 p) :\n  @fintype.card p (of_finset s H) = s.card :=\nfintype.subtype_card s H\n\ntheorem card_of_finset' {p : set \u03b1} (s : finset \u03b1)\n  (H : \u2200 x, x \u2208 s \u2194 x \u2208 p) [fintype p] : fintype.card p = s.card :=\nby rw \u2190card_of_finset s H; congr\n\nend fintype\n\nnamespace fintype\n\ntheorem of_equiv_card [fintype \u03b1] (f : \u03b1 \u2243 \u03b2) :\n  @card \u03b2 (of_equiv \u03b1 f) = card \u03b1 :=\nmultiset.card_map _ _\n\ntheorem card_congr {\u03b1 \u03b2} [fintype \u03b1] [fintype \u03b2] (f : \u03b1 \u2243 \u03b2) : card \u03b1 = card \u03b2 :=\nby rw \u2190 of_equiv_card f; congr\n\n@[congr]\nlemma card_congr' {\u03b1 \u03b2} [fintype \u03b1] [fintype \u03b2] (h : \u03b1 = \u03b2) : card \u03b1 = card \u03b2 :=\ncard_congr (by rw h)\n\nsection\n\nvariables [fintype \u03b1] [fintype \u03b2]\n\n/-- If the cardinality of `\u03b1` is `n`, there is computably a bijection between `\u03b1` and `fin n`.\n\nSee `fintype.equiv_fin_of_card_eq` for the noncomputable definition,\nand `fintype.trunc_equiv_fin` and `fintype.equiv_fin` for the bijection `\u03b1 \u2243 fin (card \u03b1)`.\n-/\ndef trunc_equiv_fin_of_card_eq [decidable_eq \u03b1] {n : \u2115} (h : fintype.card \u03b1 = n) :\n  trunc (\u03b1 \u2243 fin n) :=\n(trunc_equiv_fin \u03b1).map (\u03bb e, e.trans (fin.cast h).to_equiv)\n\n\n/-- If the cardinality of `\u03b1` is `n`, there is noncomputably a bijection between `\u03b1` and `fin n`.\n\nSee `fintype.trunc_equiv_fin_of_card_eq` for the computable definition,\nand `fintype.trunc_equiv_fin` and `fintype.equiv_fin` for the bijection `\u03b1 \u2243 fin (card \u03b1)`.\n-/\nnoncomputable def equiv_fin_of_card_eq {n : \u2115} (h : fintype.card \u03b1 = n) :\n  \u03b1 \u2243 fin n :=\nby { letI := classical.dec_eq \u03b1, exact (trunc_equiv_fin_of_card_eq h).out }\n\n/-- Two `fintype`s with the same cardinality are (computably) in bijection.\n\nSee `fintype.equiv_of_card_eq` for the noncomputable version,\nand `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq` for\nthe specialization to `fin`.\n-/\ndef trunc_equiv_of_card_eq [decidable_eq \u03b1] [decidable_eq \u03b2] (h : card \u03b1 = card \u03b2) :\n  trunc (\u03b1 \u2243 \u03b2) :=\n(trunc_equiv_fin_of_card_eq h).bind (\u03bb e, (trunc_equiv_fin \u03b2).map (\u03bb e', e.trans e'.symm))\n\n/-- Two `fintype`s with the same cardinality are (noncomputably) in bijection.\n\nSee `fintype.trunc_equiv_of_card_eq` for the computable version,\nand `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq` for\nthe specialization to `fin`.\n-/\nnoncomputable def equiv_of_card_eq (h : card \u03b1 = card \u03b2) : \u03b1 \u2243 \u03b2 :=\nby { letI := classical.dec_eq \u03b1, letI := classical.dec_eq \u03b2,\n     exact (trunc_equiv_of_card_eq h).out }\n\nend\n\ntheorem card_eq {\u03b1 \u03b2} [F : fintype \u03b1] [G : fintype \u03b2] : card \u03b1 = card \u03b2 \u2194 nonempty (\u03b1 \u2243 \u03b2) :=\n\u27e8\u03bb h, by { haveI := classical.prop_decidable, exact (trunc_equiv_of_card_eq h).nonempty },\n \u03bb \u27e8f\u27e9, card_congr f\u27e9\n\n/-- Note: this lemma is specifically about `fintype.of_subsingleton`. For a statement about\narbitrary `fintype` instances, use either `fintype.card_le_one_iff_subsingleton` or\n`fintype.card_unique`. -/\n@[simp] theorem card_of_subsingleton (a : \u03b1) [subsingleton \u03b1] :\n  @fintype.card _ (of_subsingleton a) = 1 := rfl\n\n@[simp] theorem card_unique [unique \u03b1] [h : fintype \u03b1] :\n  fintype.card \u03b1 = 1 :=\nsubsingleton.elim (of_subsingleton default) h \u25b8 card_of_subsingleton _\n\n/-- Note: this lemma is specifically about `fintype.of_is_empty`. For a statement about\narbitrary `fintype` instances, use `fintype.card_eq_zero_iff`. -/\n@[simp] theorem card_of_is_empty [is_empty \u03b1] : fintype.card \u03b1 = 0 := rfl\n\nend fintype\n\nnamespace set\nvariables {s t : set \u03b1}\n\n-- We use an arbitrary `[fintype s]` instance here,\n-- not necessarily coming from a `[fintype \u03b1]`.\n@[simp]\nlemma to_finset_card {\u03b1 : Type*} (s : set \u03b1) [fintype s] :\n  s.to_finset.card = fintype.card s :=\nmultiset.card_map subtype.val finset.univ.val\n\nend set\n\nlemma finset.card_univ [fintype \u03b1] : (finset.univ : finset \u03b1).card = fintype.card \u03b1 :=\nrfl\n\nlemma finset.eq_univ_of_card [fintype \u03b1] (s : finset \u03b1) (hs : s.card = fintype.card \u03b1) :\n  s = univ :=\neq_of_subset_of_card_le (subset_univ _) $ by rw [hs, finset.card_univ]\n\nlemma finset.card_eq_iff_eq_univ [fintype \u03b1] (s : finset \u03b1) :\n  s.card = fintype.card \u03b1 \u2194 s = finset.univ :=\n\u27e8s.eq_univ_of_card, by { rintro rfl, exact finset.card_univ, }\u27e9\n\nlemma finset.card_le_univ [fintype \u03b1] (s : finset \u03b1) :\n  s.card \u2264 fintype.card \u03b1 :=\ncard_le_of_subset (subset_univ s)\n\nlemma finset.card_lt_univ_of_not_mem [fintype \u03b1] {s : finset \u03b1} {x : \u03b1} (hx : x \u2209 s) :\n  s.card < fintype.card \u03b1 :=\ncard_lt_card \u27e8subset_univ s, not_forall.2 \u27e8x, \u03bb hx', hx (hx' $ mem_univ x)\u27e9\u27e9\n\nlemma finset.card_lt_iff_ne_univ [fintype \u03b1] (s : finset \u03b1) :\n  s.card < fintype.card \u03b1 \u2194 s \u2260 finset.univ :=\ns.card_le_univ.lt_iff_ne.trans (not_iff_not_of_iff s.card_eq_iff_eq_univ)\n\nlemma finset.card_compl_lt_iff_nonempty [fintype \u03b1] [decidable_eq \u03b1] (s : finset \u03b1) :\n  s\u1d9c.card < fintype.card \u03b1 \u2194 s.nonempty :=\ns\u1d9c.card_lt_iff_ne_univ.trans s.compl_ne_univ_iff_nonempty\n\nlemma finset.card_univ_diff [decidable_eq \u03b1] [fintype \u03b1] (s : finset \u03b1) :\n  (finset.univ \\ s).card = fintype.card \u03b1 - s.card :=\nfinset.card_sdiff (subset_univ s)\n\nlemma finset.card_compl [decidable_eq \u03b1] [fintype \u03b1] (s : finset \u03b1) :\n  s\u1d9c.card = fintype.card \u03b1 - s.card :=\nfinset.card_univ_diff s\n\nlemma fintype.card_compl_set [fintype \u03b1] (s : set \u03b1) [fintype s] [fintype \u21a5s\u1d9c] :\n  fintype.card \u21a5s\u1d9c = fintype.card \u03b1 - fintype.card s :=\nbegin\n  classical,\n  rw [\u2190 set.to_finset_card, \u2190 set.to_finset_card, \u2190 finset.card_compl, set.to_finset_compl]\nend\n\n@[simp] theorem fintype.card_fin (n : \u2115) : fintype.card (fin n) = n :=\nlist.length_fin_range n\n\n@[simp] lemma finset.card_fin (n : \u2115) : finset.card (finset.univ : finset (fin n)) = n :=\nby rw [finset.card_univ, fintype.card_fin]\n\n/-- `fin` as a map from `\u2115` to `Type` is injective. Note that since this is a statement about\nequality of types, using it should be avoided if possible. -/\nlemma fin_injective : function.injective fin :=\n\u03bb m n h,\n  (fintype.card_fin m).symm.trans $ (fintype.card_congr $ equiv.cast h).trans (fintype.card_fin n)\n\n/-- A reversed version of `fin.cast_eq_cast` that is easier to rewrite with. -/\ntheorem fin.cast_eq_cast' {n m : \u2115} (h : fin n = fin m) :\n  cast h = \u21d1(fin.cast $ fin_injective h) :=\n(fin.cast_eq_cast _).symm\n\nlemma card_finset_fin_le {n : \u2115} (s : finset (fin n)) : s.card \u2264 n :=\nby simpa only [fintype.card_fin] using s.card_le_univ\n\nlemma fin.equiv_iff_eq {m n : \u2115} : nonempty (fin m \u2243 fin n) \u2194 m = n :=\n\u27e8\u03bb \u27e8h\u27e9, by simpa using fintype.card_congr h, \u03bb h, \u27e8equiv.cast $ h \u25b8 rfl \u27e9 \u27e9\n\n\n@[simp] lemma fintype.card_subtype_eq (y : \u03b1) [fintype {x // x = y}] :\n  fintype.card {x // x = y} = 1 :=\nfintype.card_unique\n\n@[simp] lemma fintype.card_subtype_eq' (y : \u03b1) [fintype {x // y = x}] :\n  fintype.card {x // y = x} = 1 :=\nfintype.card_unique\n\n@[simp] theorem fintype.card_empty : fintype.card empty = 0 := rfl\n\n@[simp] theorem fintype.card_pempty : fintype.card pempty = 0 := rfl\n\ntheorem fintype.card_unit : fintype.card unit = 1 := rfl\n\n@[simp] theorem fintype.card_punit : fintype.card punit = 1 := rfl\n\n@[simp] theorem fintype.card_bool : fintype.card bool = 2 := rfl\n\n@[simp] theorem fintype.card_ulift (\u03b1 : Type*) [fintype \u03b1] :\n  fintype.card (ulift \u03b1) = fintype.card \u03b1 :=\nfintype.of_equiv_card _\n\n@[simp] theorem fintype.card_plift (\u03b1 : Type*) [fintype \u03b1] :\n  fintype.card (plift \u03b1) = fintype.card \u03b1 :=\nfintype.of_equiv_card _\n\n@[simp] lemma fintype.card_order_dual (\u03b1 : Type*) [fintype \u03b1] : fintype.card \u03b1\u1d52\u1d48 = fintype.card \u03b1 :=\nrfl\n\n@[simp] lemma fintype.card_lex (\u03b1 : Type*) [fintype \u03b1] :\n  fintype.card (lex \u03b1) = fintype.card \u03b1 := rfl\n\n/-- Given that `\u03b1 \u2295 \u03b2` is a fintype, `\u03b1` is also a fintype. This is non-computable as it uses\nthat `sum.inl` is an injection, but there's no clear inverse if `\u03b1` is empty. -/\nnoncomputable def fintype.sum_left {\u03b1 \u03b2} [fintype (\u03b1 \u2295 \u03b2)] : fintype \u03b1 :=\nfintype.of_injective (sum.inl : \u03b1 \u2192 \u03b1 \u2295 \u03b2) sum.inl_injective\n\n/-- Given that `\u03b1 \u2295 \u03b2` is a fintype, `\u03b2` is also a fintype. This is non-computable as it uses\nthat `sum.inr` is an injection, but there's no clear inverse if `\u03b2` is empty. -/\nnoncomputable def fintype.sum_right {\u03b1 \u03b2} [fintype (\u03b1 \u2295 \u03b2)] : fintype \u03b2 :=\nfintype.of_injective (sum.inr : \u03b2 \u2192 \u03b1 \u2295 \u03b2) sum.inr_injective\n\n/-!\n### Relation to `finite`\n\nIn this section we prove that `\u03b1 : Type*` is `finite` if and only if `fintype \u03b1` is nonempty.\n-/\n\n@[nolint fintype_finite]\nprotected lemma fintype.finite {\u03b1 : Type*} (h : fintype \u03b1) : finite \u03b1 := \u27e8fintype.equiv_fin \u03b1\u27e9\n\n/-- For efficiency reasons, we want `finite` instances to have higher\npriority than ones coming from `fintype` instances. -/\n@[nolint fintype_finite, priority 900]\ninstance finite.of_fintype (\u03b1 : Type*) [fintype \u03b1] : finite \u03b1 := fintype.finite \u2039_\u203a\n\nlemma finite_iff_nonempty_fintype (\u03b1 : Type*) :\n  finite \u03b1 \u2194 nonempty (fintype \u03b1) :=\n\u27e8\u03bb h, let \u27e8k, \u27e8e\u27e9\u27e9 := @finite.exists_equiv_fin \u03b1 h in \u27e8fintype.of_equiv _ e.symm\u27e9,\n  \u03bb \u27e8_\u27e9, by exactI infer_instance\u27e9\n\n/-- See also `nonempty_encodable`, `nonempty_denumerable`. -/\nlemma nonempty_fintype (\u03b1 : Type*) [finite \u03b1] : nonempty (fintype \u03b1) :=\n(finite_iff_nonempty_fintype \u03b1).mp \u2039_\u203a\n\n/-- Noncomputably get a `fintype` instance from a `finite` instance. This is not an\ninstance because we want `fintype` instances to be useful for computations. -/\nnoncomputable def fintype.of_finite (\u03b1 : Type*) [finite \u03b1] : fintype \u03b1 := (nonempty_fintype \u03b1).some\n\nlemma finite.of_injective {\u03b1 \u03b2 : Sort*} [finite \u03b2] (f : \u03b1 \u2192 \u03b2) (H : injective f) : finite \u03b1 :=\nbegin\n  casesI nonempty_fintype (plift \u03b2),\n  rw [\u2190 equiv.injective_comp equiv.plift f, \u2190 equiv.comp_injective _ equiv.plift.symm] at H,\n  haveI := fintype.of_injective _ H,\n  exact finite.of_equiv _ equiv.plift,\nend\n\nlemma finite.of_surjective {\u03b1 \u03b2 : Sort*} [finite \u03b1] (f : \u03b1 \u2192 \u03b2) (H : surjective f) :\n  finite \u03b2 :=\nfinite.of_injective _ $ injective_surj_inv H\n\nlemma finite.exists_univ_list (\u03b1) [finite \u03b1] : \u2203 l : list \u03b1, l.nodup \u2227 \u2200 x : \u03b1, x \u2208 l :=\nby { casesI nonempty_fintype \u03b1, obtain \u27e8l, e\u27e9 := quotient.exists_rep (@univ \u03b1 _).1,\n  have := and.intro univ.2 mem_univ_val, exact \u27e8_, by rwa \u2190e at this\u27e9 }\n\nlemma list.nodup.length_le_card {\u03b1 : Type*} [fintype \u03b1] {l : list \u03b1} (h : l.nodup) :\n  l.length \u2264 fintype.card \u03b1 :=\nby { classical, exact list.to_finset_card_of_nodup h \u25b8 l.to_finset.card_le_univ }\n\nnamespace fintype\nvariables [fintype \u03b1] [fintype \u03b2]\n\nlemma card_le_of_injective (f : \u03b1 \u2192 \u03b2) (hf : function.injective f) : card \u03b1 \u2264 card \u03b2 :=\nfinset.card_le_card_of_inj_on f (\u03bb _ _, finset.mem_univ _) (\u03bb _ _ _ _ h, hf h)\n\nlemma card_le_of_embedding (f : \u03b1 \u21aa \u03b2) : card \u03b1 \u2264 card \u03b2 := card_le_of_injective f f.2\n\nlemma card_lt_of_injective_of_not_mem (f : \u03b1 \u2192 \u03b2) (h : function.injective f)\n  {b : \u03b2} (w : b \u2209 set.range f) : card \u03b1 < card \u03b2 :=\ncalc card \u03b1 = (univ.map \u27e8f, h\u27e9).card : (card_map _).symm\n... < card \u03b2 : finset.card_lt_univ_of_not_mem $\n                 by rwa [\u2190 mem_coe, coe_map, coe_univ, set.image_univ]\n\nlemma card_lt_of_injective_not_surjective (f : \u03b1 \u2192 \u03b2) (h : function.injective f)\n  (h' : \u00acfunction.surjective f) : card \u03b1 < card \u03b2 :=\nlet \u27e8y, hy\u27e9 := not_forall.1 h' in card_lt_of_injective_of_not_mem f h hy\n\nlemma card_le_of_surjective (f : \u03b1 \u2192 \u03b2) (h : function.surjective f) : card \u03b2 \u2264 card \u03b1 :=\ncard_le_of_injective _ (function.injective_surj_inv h)\n\nlemma card_range_le {\u03b1 \u03b2 : Type*} (f : \u03b1 \u2192 \u03b2) [fintype \u03b1] [fintype (set.range f)] :\n  fintype.card (set.range f) \u2264 fintype.card \u03b1 :=\nfintype.card_le_of_surjective (\u03bb a, \u27e8f a, by simp\u27e9) (\u03bb \u27e8_, a, ha\u27e9, \u27e8a, by simpa using ha\u27e9)\n\nlemma card_range {\u03b1 \u03b2 F : Type*} [embedding_like F \u03b1 \u03b2] (f : F) [fintype \u03b1]\n  [fintype (set.range f)] :\n  fintype.card (set.range f) = fintype.card \u03b1 :=\neq.symm $ fintype.card_congr $ equiv.of_injective _ $ embedding_like.injective f\n\n/--\nThe pigeonhole principle for finitely many pigeons and pigeonholes.\nThis is the `fintype` version of `finset.exists_ne_map_eq_of_card_lt_of_maps_to`.\n-/\nlemma exists_ne_map_eq_of_card_lt (f : \u03b1 \u2192 \u03b2) (h : fintype.card \u03b2 < fintype.card \u03b1) :\n  \u2203 x y, x \u2260 y \u2227 f x = f y :=\nlet \u27e8x, _, y, _, h\u27e9 := finset.exists_ne_map_eq_of_card_lt_of_maps_to h (\u03bb x _, mem_univ (f x))\nin \u27e8x, y, h\u27e9\n\nlemma card_eq_one_iff : card \u03b1 = 1 \u2194 (\u2203 x : \u03b1, \u2200 y, y = x) :=\nby rw [\u2190card_unit, card_eq]; exact\n\u27e8\u03bb \u27e8a\u27e9, \u27e8a.symm (), \u03bb y, a.injective (subsingleton.elim _ _)\u27e9,\n  \u03bb \u27e8x, hx\u27e9, \u27e8\u27e8\u03bb _, (), \u03bb _, x, \u03bb _, (hx _).trans (hx _).symm,\n    \u03bb _, subsingleton.elim _ _\u27e9\u27e9\u27e9\n\nlemma card_eq_zero_iff : card \u03b1 = 0 \u2194 is_empty \u03b1 :=\nby rw [card, finset.card_eq_zero, univ_eq_empty_iff]\n\nlemma card_eq_zero [is_empty \u03b1] : card \u03b1 = 0 := card_eq_zero_iff.2 \u2039_\u203a\n\nlemma card_eq_one_iff_nonempty_unique : card \u03b1 = 1 \u2194 nonempty (unique \u03b1) :=\n\u27e8\u03bb h, let \u27e8d, h\u27e9 := fintype.card_eq_one_iff.mp h in \u27e8{ default := d, uniq := h}\u27e9,\n \u03bb \u27e8h\u27e9, by exactI fintype.card_unique\u27e9\n\n/-- A `fintype` with cardinality zero is equivalent to `empty`. -/\ndef card_eq_zero_equiv_equiv_empty : card \u03b1 = 0 \u2243 (\u03b1 \u2243 empty) :=\n(equiv.of_iff card_eq_zero_iff).trans (equiv.equiv_empty_equiv \u03b1).symm\n\nlemma card_pos_iff : 0 < card \u03b1 \u2194 nonempty \u03b1 :=\npos_iff_ne_zero.trans $ not_iff_comm.mp $ not_nonempty_iff.trans card_eq_zero_iff.symm\n\nlemma card_pos [h : nonempty \u03b1] : 0 < card \u03b1 :=\ncard_pos_iff.mpr h\n\nlemma card_ne_zero [nonempty \u03b1] : card \u03b1 \u2260 0 :=\nne_of_gt card_pos\n\nlemma card_le_one_iff : card \u03b1 \u2264 1 \u2194 (\u2200 a b : \u03b1, a = b) :=\nlet n := card \u03b1 in\nhave hn : n = card \u03b1 := rfl,\nmatch n, hn with\n| 0     := \u03bb ha, \u27e8\u03bb h, \u03bb a, (card_eq_zero_iff.1 ha.symm).elim a, \u03bb _, ha \u25b8 nat.le_succ _\u27e9\n| 1     := \u03bb ha, \u27e8\u03bb h, \u03bb a b, let \u27e8x, hx\u27e9 := card_eq_one_iff.1 ha.symm in\n  by rw [hx a, hx b],\n    \u03bb _, ha \u25b8 le_rfl\u27e9\n| (n+2) := \u03bb ha, \u27e8\u03bb h, by rw \u2190 ha at h; exact absurd h dec_trivial,\n  (\u03bb h, card_unit \u25b8 card_le_of_injective (\u03bb _, ())\n    (\u03bb _ _ _, h _ _))\u27e9\nend\n\nlemma card_le_one_iff_subsingleton : card \u03b1 \u2264 1 \u2194 subsingleton \u03b1 :=\ncard_le_one_iff.trans subsingleton_iff.symm\n\nlemma one_lt_card_iff_nontrivial : 1 < card \u03b1 \u2194 nontrivial \u03b1 :=\nbegin\n  classical,\n  rw \u2190not_iff_not,\n  push_neg,\n  rw [not_nontrivial_iff_subsingleton, card_le_one_iff_subsingleton]\nend\n\nlemma exists_ne_of_one_lt_card (h : 1 < card \u03b1) (a : \u03b1) : \u2203 b : \u03b1, b \u2260 a :=\nby { haveI : nontrivial \u03b1 := one_lt_card_iff_nontrivial.1 h, exact exists_ne a }\n\nlemma exists_pair_of_one_lt_card (h : 1 < card \u03b1) : \u2203 (a b : \u03b1), a \u2260 b :=\nby { haveI : nontrivial \u03b1 := one_lt_card_iff_nontrivial.1 h, exact exists_pair_ne \u03b1 }\n\nlemma card_eq_one_of_forall_eq {i : \u03b1} (h : \u2200 j, j = i) : card \u03b1 = 1 :=\nfintype.card_eq_one_iff.2 \u27e8i,h\u27e9\n\nlemma one_lt_card [h : nontrivial \u03b1] : 1 < fintype.card \u03b1 :=\nfintype.one_lt_card_iff_nontrivial.mpr h\n\nlemma one_lt_card_iff : 1 < card \u03b1 \u2194 \u2203 a b : \u03b1, a \u2260 b :=\none_lt_card_iff_nontrivial.trans nontrivial_iff\n\nlemma two_lt_card_iff : 2 < card \u03b1 \u2194 \u2203 a b c : \u03b1, a \u2260 b \u2227 a \u2260 c \u2227 b \u2260 c :=\nby simp_rw [\u2190finset.card_univ, two_lt_card_iff, mem_univ, true_and]\n\nlemma card_of_bijective {f : \u03b1 \u2192 \u03b2} (hf : bijective f) : card \u03b1 = card \u03b2 :=\ncard_congr (equiv.of_bijective f hf)\n\nend fintype\n\nnamespace finite\nvariables [finite \u03b1]\n\nlemma injective_iff_surjective {f : \u03b1 \u2192 \u03b1} : injective f \u2194 surjective f :=\nby haveI := classical.prop_decidable; casesI nonempty_fintype \u03b1; exact\nhave \u2200 {f : \u03b1 \u2192 \u03b1}, injective f \u2192 surjective f,\nfrom \u03bb f hinj x,\n  have h\u2081 : image f univ = univ := eq_of_subset_of_card_le (subset_univ _)\n    ((card_image_of_injective univ hinj).symm \u25b8 le_rfl),\n  have h\u2082 : x \u2208 image f univ := h\u2081.symm \u25b8 mem_univ _,\n  exists_of_bex (mem_image.1 h\u2082),\n\u27e8this,\n  \u03bb hsurj, has_left_inverse.injective\n    \u27e8surj_inv hsurj, left_inverse_of_surjective_of_right_inverse\n      (this (injective_surj_inv _)) (right_inverse_surj_inv _)\u27e9\u27e9\n\nlemma injective_iff_bijective {f : \u03b1 \u2192 \u03b1} : injective f \u2194 bijective f :=\nby simp [bijective, injective_iff_surjective]\n\nlemma surjective_iff_bijective {f : \u03b1 \u2192 \u03b1} : surjective f \u2194 bijective f :=\nby simp [bijective, injective_iff_surjective]\n\nlemma injective_iff_surjective_of_equiv  {f : \u03b1 \u2192 \u03b2} (e : \u03b1 \u2243 \u03b2) : injective f \u2194 surjective f :=\nhave injective (e.symm \u2218 f) \u2194 surjective (e.symm \u2218 f), from injective_iff_surjective,\n\u27e8\u03bb hinj, by simpa [function.comp] using\n  e.surjective.comp (this.1 (e.symm.injective.comp hinj)),\n\u03bb hsurj, by simpa [function.comp] using\n  e.injective.comp (this.2 (e.symm.surjective.comp hsurj))\u27e9\n\n\nalias injective_iff_bijective \u2194 _root_.function.injective.bijective_of_finite _\nalias surjective_iff_bijective \u2194 _root_.function.surjective.bijective_of_finite _\nalias injective_iff_surjective_of_equiv \u2194 _root_.function.injective.surjective_of_fintype\n  _root_.function.surjective.injective_of_fintype\n\nend finite\n\nnamespace fintype\nvariables [fintype \u03b1] [fintype \u03b2]\n\nlemma bijective_iff_injective_and_card (f : \u03b1 \u2192 \u03b2) :\n  bijective f \u2194 injective f \u2227 card \u03b1 = card \u03b2 :=\n\u27e8\u03bb h, \u27e8h.1, card_of_bijective h\u27e9, \u03bb h, \u27e8h.1, h.1.surjective_of_fintype $ equiv_of_card_eq h.2\u27e9\u27e9\n\nlemma bijective_iff_surjective_and_card (f : \u03b1 \u2192 \u03b2) :\n  bijective f \u2194 surjective f \u2227 card \u03b1 = card \u03b2 :=\n\u27e8\u03bb h, \u27e8h.2, card_of_bijective h\u27e9, \u03bb h, \u27e8h.1.injective_of_fintype $ equiv_of_card_eq h.2, h.1\u27e9\u27e9\n\nlemma _root_.function.left_inverse.right_inverse_of_card_le {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (hfg : left_inverse f g) (hcard : card \u03b1 \u2264 card \u03b2) :\n  right_inverse f g :=\nhave hsurj : surjective f, from surjective_iff_has_right_inverse.2 \u27e8g, hfg\u27e9,\nright_inverse_of_injective_of_left_inverse\n  ((bijective_iff_surjective_and_card _).2\n    \u27e8hsurj, le_antisymm hcard (card_le_of_surjective f hsurj)\u27e9 ).1\n  hfg\n\nlemma _root_.function.right_inverse.left_inverse_of_card_le {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b1}\n  (hfg : right_inverse f g) (hcard : card \u03b2 \u2264 card \u03b1) :\n  left_inverse f g :=\nfunction.left_inverse.right_inverse_of_card_le hfg hcard\n\nend fintype\n\nnamespace equiv\nvariables [fintype \u03b1] [fintype \u03b2]\n\nopen fintype\n\n/-- Construct an equivalence from functions that are inverse to each other. -/\n@[simps] def of_left_inverse_of_card_le (h\u03b2\u03b1 : card \u03b2 \u2264 card \u03b1) (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1)\n  (h : left_inverse g f) : \u03b1 \u2243 \u03b2 :=\n{ to_fun := f,\n  inv_fun := g,\n  left_inv := h,\n  right_inv := h.right_inverse_of_card_le h\u03b2\u03b1 }\n\n/-- Construct an equivalence from functions that are inverse to each other. -/\n@[simps] def of_right_inverse_of_card_le (h\u03b1\u03b2 : card \u03b1 \u2264 card \u03b2) (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1)\n  (h : right_inverse g f) : \u03b1 \u2243 \u03b2 :=\n{ to_fun := f,\n  inv_fun := g,\n  left_inv := h.left_inverse_of_card_le h\u03b1\u03b2,\n  right_inv := h }\n\nend equiv\n\n@[simp] lemma fintype.card_coe (s : finset \u03b1) [fintype s] :\n  fintype.card s = s.card := fintype.card_of_finset' s (\u03bb _, iff.rfl)\n\n/-- Noncomputable equivalence between a finset `s` coerced to a type and `fin s.card`. -/\nnoncomputable def finset.equiv_fin (s : finset \u03b1) : s \u2243 fin s.card :=\nfintype.equiv_fin_of_card_eq (fintype.card_coe _)\n\n/-- Noncomputable equivalence between a finset `s` as a fintype and `fin n`, when there is a\nproof that `s.card = n`. -/\nnoncomputable def finset.equiv_fin_of_card_eq {s : finset \u03b1} {n : \u2115} (h : s.card = n) : s \u2243 fin n :=\nfintype.equiv_fin_of_card_eq ((fintype.card_coe _).trans h)\n\n/-- Noncomputable equivalence between two finsets `s` and `t` as fintypes when there is a proof\nthat `s.card = t.card`.-/\nnoncomputable def finset.equiv_of_card_eq {s t : finset \u03b1} (h : s.card = t.card) : s \u2243 t :=\nfintype.equiv_of_card_eq ((fintype.card_coe _).trans (h.trans (fintype.card_coe _).symm))\n\n@[simp] lemma fintype.card_Prop : fintype.card Prop = 2 := rfl\n\nlemma set_fintype_card_le_univ [fintype \u03b1] (s : set \u03b1) [fintype \u21a5s] :\n  fintype.card \u21a5s \u2264 fintype.card \u03b1 :=\nfintype.card_le_of_embedding (function.embedding.subtype s)\n\nlemma set_fintype_card_eq_univ_iff [fintype \u03b1] (s : set \u03b1) [fintype \u21a5s] :\n  fintype.card s = fintype.card \u03b1 \u2194 s = set.univ :=\nby rw [\u2190set.to_finset_card, finset.card_eq_iff_eq_univ, \u2190set.to_finset_univ, set.to_finset_inj]\n\nnamespace function.embedding\n\n/-- An embedding from a `fintype` to itself can be promoted to an equivalence. -/\nnoncomputable def equiv_of_fintype_self_embedding [finite \u03b1] (e : \u03b1 \u21aa \u03b1) : \u03b1 \u2243 \u03b1 :=\nequiv.of_bijective e e.2.bijective_of_finite\n\n@[simp]\nlemma equiv_of_fintype_self_embedding_to_embedding [finite \u03b1] (e : \u03b1 \u21aa \u03b1) :\n  e.equiv_of_fintype_self_embedding.to_embedding = e :=\nby { ext, refl, }\n\n/-- If `\u2016\u03b2\u2016 < \u2016\u03b1\u2016` there are no embeddings `\u03b1 \u21aa \u03b2`.\nThis is a formulation of the pigeonhole principle.\n\nNote this cannot be an instance as it needs `h`. -/\n@[simp] lemma is_empty_of_card_lt [fintype \u03b1] [fintype \u03b2]\n  (h : fintype.card \u03b2 < fintype.card \u03b1) : is_empty (\u03b1 \u21aa \u03b2) :=\n\u27e8\u03bb f, let \u27e8x, y, ne, feq\u27e9 := fintype.exists_ne_map_eq_of_card_lt f h in ne $ f.injective feq\u27e9\n\n/-- A constructive embedding of a fintype `\u03b1` in another fintype `\u03b2` when `card \u03b1 \u2264 card \u03b2`. -/\ndef trunc_of_card_le [fintype \u03b1] [fintype \u03b2] [decidable_eq \u03b1] [decidable_eq \u03b2]\n  (h : fintype.card \u03b1 \u2264 fintype.card \u03b2) : trunc (\u03b1 \u21aa \u03b2) :=\n(fintype.trunc_equiv_fin \u03b1).bind $ \u03bb ea,\n  (fintype.trunc_equiv_fin \u03b2).map $ \u03bb eb,\n    ea.to_embedding.trans ((fin.cast_le h).to_embedding.trans eb.symm.to_embedding)\n\nlemma nonempty_of_card_le [fintype \u03b1] [fintype \u03b2]\n  (h : fintype.card \u03b1 \u2264 fintype.card \u03b2) : nonempty (\u03b1 \u21aa \u03b2) :=\nby { classical, exact (trunc_of_card_le h).nonempty }\n\nlemma nonempty_iff_card_le [fintype \u03b1] [fintype \u03b2] :\n  nonempty (\u03b1 \u21aa \u03b2) \u2194 fintype.card \u03b1 \u2264 fintype.card \u03b2 :=\n\u27e8\u03bb \u27e8e\u27e9, fintype.card_le_of_embedding e, nonempty_of_card_le\u27e9\n\nlemma exists_of_card_le_finset [fintype \u03b1] {s : finset \u03b2} (h : fintype.card \u03b1 \u2264 s.card) :\n  \u2203 (f : \u03b1 \u21aa \u03b2), set.range f \u2286 s :=\nbegin\n  rw \u2190 fintype.card_coe at h,\n  rcases nonempty_of_card_le h with \u27e8f\u27e9,\n  exact \u27e8f.trans (embedding.subtype _), by simp [set.range_subset_iff]\u27e9\nend\n\nend function.embedding\n\n@[simp]\nlemma finset.univ_map_embedding {\u03b1 : Type*} [fintype \u03b1] (e : \u03b1 \u21aa \u03b1) :\n  univ.map e = univ :=\nby rw [\u2190e.equiv_of_fintype_self_embedding_to_embedding, univ_map_equiv_to_embedding]\n\nnamespace fintype\n\nlemma card_lt_of_surjective_not_injective [fintype \u03b1] [fintype \u03b2] (f : \u03b1 \u2192 \u03b2)\n  (h : function.surjective f) (h' : \u00acfunction.injective f) : card \u03b2 < card \u03b1 :=\ncard_lt_of_injective_not_surjective _ (function.injective_surj_inv h) $ \u03bb hg,\nhave w : function.bijective (function.surj_inv h) := \u27e8function.injective_surj_inv h, hg\u27e9,\nh' $ h.injective_of_fintype (equiv.of_bijective _ w).symm\n\nend fintype\n\ntheorem fintype.card_subtype_le [fintype \u03b1] (p : \u03b1 \u2192 Prop) [decidable_pred p] :\n  fintype.card {x // p x} \u2264 fintype.card \u03b1 :=\nfintype.card_le_of_embedding (function.embedding.subtype _)\n\ntheorem fintype.card_subtype_lt [fintype \u03b1] {p : \u03b1 \u2192 Prop} [decidable_pred p]\n  {x : \u03b1} (hx : \u00ac p x) : fintype.card {x // p x} < fintype.card \u03b1 :=\nfintype.card_lt_of_injective_of_not_mem coe subtype.coe_injective $ by rwa subtype.range_coe_subtype\n\nlemma fintype.card_subtype [fintype \u03b1] (p : \u03b1 \u2192 Prop) [decidable_pred p] :\n  fintype.card {x // p x} = ((finset.univ : finset \u03b1).filter p).card :=\nbegin\n  refine fintype.card_of_subtype _ _,\n  simp\nend\n\n@[simp]\nlemma fintype.card_subtype_compl [fintype \u03b1]\n  (p : \u03b1 \u2192 Prop) [fintype {x // p x}] [fintype {x // \u00ac p x}] :\n  fintype.card {x // \u00ac p x} = fintype.card \u03b1 - fintype.card {x // p x} :=\nbegin\n  classical,\n  rw [fintype.card_of_subtype (set.to_finset p\u1d9c), set.to_finset_compl p, finset.card_compl,\n      fintype.card_of_subtype (set.to_finset p)];\n  intro; simp only [set.mem_to_finset, set.mem_compl_iff]; refl,\nend\n\ntheorem fintype.card_subtype_mono (p q : \u03b1 \u2192 Prop) (h : p \u2264 q)\n  [fintype {x // p x}] [fintype {x // q x}] :\n  fintype.card {x // p x} \u2264 fintype.card {x // q x} :=\nfintype.card_le_of_embedding (subtype.imp_embedding _ _ h)\n\n/-- If two subtypes of a fintype have equal cardinality, so do their complements. -/\nlemma fintype.card_compl_eq_card_compl [finite \u03b1] (p q : \u03b1 \u2192 Prop)\n  [fintype {x // p x}] [fintype {x // \u00ac p x}]\n  [fintype {x // q x}] [fintype {x // \u00ac q x}]\n  (h : fintype.card {x // p x} = fintype.card {x // q x}) :\n  fintype.card {x // \u00ac p x} = fintype.card {x // \u00ac q x} :=\nby { casesI nonempty_fintype \u03b1, simp only [fintype.card_subtype_compl, h] }\n\ntheorem fintype.card_quotient_le [fintype \u03b1] (s : setoid \u03b1) [decidable_rel ((\u2248) : \u03b1 \u2192 \u03b1 \u2192 Prop)] :\n  fintype.card (quotient s) \u2264 fintype.card \u03b1 :=\nfintype.card_le_of_surjective _ (surjective_quotient_mk _)\n\ntheorem fintype.card_quotient_lt [fintype \u03b1] {s : setoid \u03b1} [decidable_rel ((\u2248) : \u03b1 \u2192 \u03b1 \u2192 Prop)]\n  {x y : \u03b1} (h1 : x \u2260 y) (h2 : x \u2248 y) : fintype.card (quotient s) < fintype.card \u03b1 :=\nfintype.card_lt_of_surjective_not_injective _ (surjective_quotient_mk _) $ \u03bb w,\nh1 (w $ quotient.eq.mpr h2)\n\nlemma univ_eq_singleton_of_card_one {\u03b1} [fintype \u03b1] (x : \u03b1) (h : fintype.card \u03b1 = 1) :\n  (univ : finset \u03b1) = {x} :=\nbegin\n  symmetry,\n  apply eq_of_subset_of_card_le (subset_univ ({x})),\n  apply le_of_eq,\n  simp [h, finset.card_univ]\nend\n\nnamespace finite\nvariables [finite \u03b1]\n\nlemma well_founded_of_trans_of_irrefl (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_trans \u03b1 r] [is_irrefl \u03b1 r] :\n  well_founded r :=\nby classical; casesI nonempty_fintype \u03b1; exact\nhave \u2200 x y, r x y \u2192 (univ.filter (\u03bb z, r z x)).card < (univ.filter (\u03bb z, r z y)).card,\n  from \u03bb x y hxy, finset.card_lt_card $\n    by simp only [finset.lt_iff_ssubset.symm, lt_iff_le_not_le,\n      finset.le_iff_subset, finset.subset_iff, mem_filter, true_and, mem_univ, hxy];\n    exact \u27e8\u03bb z hzx, trans hzx hxy, not_forall_of_exists_not \u27e8x, not_imp.2 \u27e8hxy, irrefl x\u27e9\u27e9\u27e9,\nsubrelation.wf this (measure_wf _)\n\nlemma preorder.well_founded_lt [preorder \u03b1] : well_founded ((<) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\nwell_founded_of_trans_of_irrefl _\n\nlemma preorder.well_founded_gt [preorder \u03b1] : well_founded ((>) : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\nwell_founded_of_trans_of_irrefl _\n\n@[priority 10] instance linear_order.is_well_order_lt [linear_order \u03b1] : is_well_order \u03b1 (<) :=\n{ wf := preorder.well_founded_lt }\n\n@[priority 10] instance linear_order.is_well_order_gt [linear_order \u03b1] : is_well_order \u03b1 (>) :=\n{ wf := preorder.well_founded_gt }\n\nend finite\n\n@[nolint fintype_finite]\nprotected lemma fintype.false [infinite \u03b1] (h : fintype \u03b1) : false := not_finite \u03b1\n\n@[simp] lemma is_empty_fintype {\u03b1 : Type*} : is_empty (fintype \u03b1) \u2194 infinite \u03b1 :=\n\u27e8\u03bb \u27e8h\u27e9, \u27e8\u03bb h', (@nonempty_fintype \u03b1 h').elim h\u27e9, \u03bb \u27e8h\u27e9, \u27e8\u03bb h', h h'.finite\u27e9\u27e9\n\n/-- A non-infinite type is a fintype. -/\nnoncomputable def fintype_of_not_infinite {\u03b1 : Type*} (h : \u00ac infinite \u03b1) : fintype \u03b1 :=\n@fintype.of_finite _ (not_infinite_iff_finite.mp h)\n\nsection\nopen_locale classical\n\n/--\nAny type is (classically) either a `fintype`, or `infinite`.\n\nOne can obtain the relevant typeclasses via `cases fintype_or_infinite \u03b1; resetI`.\n-/\nnoncomputable def fintype_or_infinite (\u03b1 : Type*) : psum (fintype \u03b1) (infinite \u03b1) :=\nif h : infinite \u03b1 then psum.inr h else psum.inl (fintype_of_not_infinite h)\n\nend\n\nlemma finset.exists_minimal {\u03b1 : Type*} [preorder \u03b1] (s : finset \u03b1) (h : s.nonempty) :\n  \u2203 m \u2208 s, \u2200 x \u2208 s, \u00ac (x < m) :=\nbegin\n  obtain \u27e8c, hcs : c \u2208 s\u27e9 := h,\n  have : well_founded (@has_lt.lt {x // x \u2208 s} _) := finite.well_founded_of_trans_of_irrefl _,\n  obtain \u27e8\u27e8m, hms : m \u2208 s\u27e9, -, H\u27e9 := this.has_min set.univ \u27e8\u27e8c, hcs\u27e9, trivial\u27e9,\n  exact \u27e8m, hms, \u03bb x hx hxm, H \u27e8x, hx\u27e9 trivial hxm\u27e9,\nend\n\nlemma finset.exists_maximal {\u03b1 : Type*} [preorder \u03b1] (s : finset \u03b1) (h : s.nonempty) :\n  \u2203 m \u2208 s, \u2200 x \u2208 s, \u00ac (m < x) :=\n@finset.exists_minimal \u03b1\u1d52\u1d48 _ s h\n\nnamespace infinite\n\nlemma of_not_fintype (h : fintype \u03b1 \u2192 false) : infinite \u03b1 := is_empty_fintype.mp \u27e8h\u27e9\n\n/-- If `s : set \u03b1` is a proper subset of `\u03b1` and `f : \u03b1 \u2192 s` is injective, then `\u03b1` is infinite. -/\nlemma of_injective_to_set {s : set \u03b1} (hs : s \u2260 set.univ) {f : \u03b1 \u2192 s} (hf : injective f) :\n  infinite \u03b1 :=\nof_not_fintype $ \u03bb h, begin\n  resetI, classical,\n  refine lt_irrefl (fintype.card \u03b1) _,\n  calc fintype.card \u03b1 \u2264 fintype.card s : fintype.card_le_of_injective f hf\n  ... = s.to_finset.card : s.to_finset_card.symm\n  ... < fintype.card \u03b1 : finset.card_lt_card $\n    by rwa [set.to_finset_ssubset_univ, set.ssubset_univ_iff]\nend\n\n/-- If `s : set \u03b1` is a proper subset of `\u03b1` and `f : s \u2192 \u03b1` is surjective, then `\u03b1` is infinite. -/\nlemma of_surjective_from_set {s : set \u03b1} (hs : s \u2260 set.univ) {f : s \u2192 \u03b1} (hf : surjective f) :\n  infinite \u03b1 :=\nof_injective_to_set hs (injective_surj_inv hf)\n\nlemma exists_not_mem_finset [infinite \u03b1] (s : finset \u03b1) : \u2203 x, x \u2209 s :=\nnot_forall.1 $ \u03bb h, fintype.false \u27e8s, h\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance (\u03b1 : Type*) [H : infinite \u03b1] : nontrivial \u03b1 :=\n\u27e8let \u27e8x, hx\u27e9 := exists_not_mem_finset (\u2205 : finset \u03b1) in\nlet \u27e8y, hy\u27e9 := exists_not_mem_finset ({x} : finset \u03b1) in\n\u27e8y, x, by simpa only [mem_singleton] using hy\u27e9\u27e9\n\nprotected lemma nonempty (\u03b1 : Type*) [infinite \u03b1] : nonempty \u03b1 :=\nby apply_instance\n\nlemma of_injective {\u03b1 \u03b2} [infinite \u03b2] (f : \u03b2 \u2192 \u03b1) (hf : injective f) : infinite \u03b1 :=\n\u27e8\u03bb I, by exactI (finite.of_injective f hf).false\u27e9\n\nlemma of_surjective {\u03b1 \u03b2} [infinite \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : surjective f) : infinite \u03b1 :=\n\u27e8\u03bb I, by exactI (finite.of_surjective f hf).false\u27e9\n\nend infinite\n\ninstance : infinite \u2115 :=\ninfinite.of_not_fintype $ by { introI h,\n  exact (finset.range _).card_le_univ.not_lt ((nat.lt_succ_self _).trans_eq (card_range _).symm) }\n\ninstance : infinite \u2124 :=\ninfinite.of_injective int.of_nat (\u03bb _ _, int.of_nat.inj)\n\ninstance [nonempty \u03b1] : infinite (multiset \u03b1) :=\nlet \u27e8x\u27e9 := \u2039nonempty \u03b1\u203a in\n  infinite.of_injective (\u03bb n, multiset.replicate n x) (multiset.replicate_left_injective _)\n\ninstance [nonempty \u03b1] : infinite (list \u03b1) :=\ninfinite.of_surjective (coe : list \u03b1 \u2192 multiset \u03b1) (surjective_quot_mk _)\n\ninstance infinite.set [infinite \u03b1] : infinite (set \u03b1) :=\ninfinite.of_injective singleton set.singleton_injective\n\ninstance [infinite \u03b1] : infinite (finset \u03b1) :=\ninfinite.of_injective singleton finset.singleton_injective\n\ninstance [infinite \u03b1] : infinite (option \u03b1) :=\ninfinite.of_injective some (option.some_injective \u03b1)\n\ninstance sum.infinite_of_left [infinite \u03b1] : infinite (\u03b1 \u2295 \u03b2) :=\ninfinite.of_injective sum.inl sum.inl_injective\n\ninstance sum.infinite_of_right [infinite \u03b2] : infinite (\u03b1 \u2295 \u03b2) :=\ninfinite.of_injective sum.inr sum.inr_injective\n\ninstance prod.infinite_of_right [nonempty \u03b1] [infinite \u03b2] : infinite (\u03b1 \u00d7 \u03b2) :=\ninfinite.of_surjective prod.snd prod.snd_surjective\n\ninstance prod.infinite_of_left [infinite \u03b1] [nonempty \u03b2] : infinite (\u03b1 \u00d7 \u03b2) :=\ninfinite.of_surjective prod.fst prod.fst_surjective\n\nnamespace infinite\n\nprivate noncomputable def nat_embedding_aux (\u03b1 : Type*) [infinite \u03b1] : \u2115 \u2192 \u03b1\n| n := by letI := classical.dec_eq \u03b1; exact classical.some (exists_not_mem_finset\n  ((multiset.range n).pmap (\u03bb m (hm : m < n), nat_embedding_aux m)\n    (\u03bb _, multiset.mem_range.1)).to_finset)\n\nprivate lemma nat_embedding_aux_injective (\u03b1 : Type*) [infinite \u03b1] :\n  function.injective (nat_embedding_aux \u03b1) :=\nbegin\n  rintro m n h,\n  letI := classical.dec_eq \u03b1,\n  wlog hmlen : m \u2264 n generalizing m n,\n  { exact (this h.symm $ le_of_not_le hmlen).symm },\n  by_contradiction hmn,\n  have hmn : m < n, from lt_of_le_of_ne hmlen hmn,\n  refine (classical.some_spec (exists_not_mem_finset\n    ((multiset.range n).pmap (\u03bb m (hm : m < n), nat_embedding_aux \u03b1 m)\n      (\u03bb _, multiset.mem_range.1)).to_finset)) _,\n  refine multiset.mem_to_finset.2 (multiset.mem_pmap.2\n    \u27e8m, multiset.mem_range.2 hmn, _\u27e9),\n  rw [h, nat_embedding_aux]\nend\n\n/-- Embedding of `\u2115` into an infinite type. -/\nnoncomputable def nat_embedding (\u03b1 : Type*) [infinite \u03b1] : \u2115 \u21aa \u03b1 :=\n\u27e8_, nat_embedding_aux_injective \u03b1\u27e9\n\n/-- See `infinite.exists_superset_card_eq` for a version that, for a `s : finset \u03b1`,\nprovides a superset `t : finset \u03b1`, `s \u2286 t` such that `t.card` is fixed. -/\nlemma exists_subset_card_eq (\u03b1 : Type*) [infinite \u03b1] (n : \u2115) :\n  \u2203 s : finset \u03b1, s.card = n :=\n\u27e8(range n).map (nat_embedding \u03b1), by rw [card_map, card_range]\u27e9\n\n/-- See `infinite.exists_subset_card_eq` for a version that provides an arbitrary\n`s : finset \u03b1` for any cardinality. -/\nlemma exists_superset_card_eq [infinite \u03b1] (s : finset \u03b1) (n : \u2115) (hn : s.card \u2264 n) :\n  \u2203 t : finset \u03b1, s \u2286 t \u2227 t.card = n :=\nbegin\n  induction n with n IH generalizing s,\n  { exact \u27e8s, subset_refl _, nat.eq_zero_of_le_zero hn\u27e9 },\n  { cases hn.eq_or_lt with hn' hn',\n    { exact \u27e8s, subset_refl _, hn'\u27e9 },\n    obtain \u27e8t, hs, ht\u27e9 := IH _ (nat.le_of_lt_succ hn'),\n    obtain \u27e8x, hx\u27e9 := exists_not_mem_finset t,\n    refine \u27e8finset.cons x t hx, hs.trans (finset.subset_cons _), _\u27e9,\n    simp [hx, ht] }\nend\n\nend infinite\n\n/-- If every finset in a type has bounded cardinality, that type is finite. -/\nnoncomputable def fintype_of_finset_card_le {\u03b9 : Type*} (n : \u2115)\n  (w : \u2200 s : finset \u03b9, s.card \u2264 n) : fintype \u03b9 :=\nbegin\n  apply fintype_of_not_infinite,\n  introI i,\n  obtain \u27e8s, c\u27e9 := infinite.exists_subset_card_eq \u03b9 (n+1),\n  specialize w s,\n  rw c at w,\n  exact nat.not_succ_le_self n w,\nend\n\nlemma not_injective_infinite_finite {\u03b1 \u03b2} [infinite \u03b1] [finite \u03b2] (f : \u03b1 \u2192 \u03b2) : \u00ac injective f :=\n\u03bb hf, (finite.of_injective f hf).false\n\n/--\nThe pigeonhole principle for infinitely many pigeons in finitely many pigeonholes. If there are\ninfinitely many pigeons in finitely many pigeonholes, then there are at least two pigeons in the\nsame pigeonhole.\n\nSee also: `fintype.exists_ne_map_eq_of_card_lt`, `finite.exists_infinite_fiber`.\n-/\nlemma finite.exists_ne_map_eq_of_infinite {\u03b1 \u03b2} [infinite \u03b1] [finite \u03b2] (f : \u03b1 \u2192 \u03b2) :\n  \u2203 x y : \u03b1, x \u2260 y \u2227 f x = f y :=\nby simpa only [injective, not_forall, not_imp, and.comm] using not_injective_infinite_finite f\n\ninstance function.embedding.is_empty {\u03b1 \u03b2} [infinite \u03b1] [finite \u03b2] : is_empty (\u03b1 \u21aa \u03b2) :=\n\u27e8\u03bb f, not_injective_infinite_finite f f.2\u27e9\n\n/--\nThe strong pigeonhole principle for infinitely many pigeons in\nfinitely many pigeonholes.  If there are infinitely many pigeons in\nfinitely many pigeonholes, then there is a pigeonhole with infinitely\nmany pigeons.\n\nSee also: `finite.exists_ne_map_eq_of_infinite`\n-/\nlemma finite.exists_infinite_fiber [infinite \u03b1] [finite \u03b2] (f : \u03b1 \u2192 \u03b2) :\n  \u2203 y : \u03b2, infinite (f \u207b\u00b9' {y}) :=\nbegin\n  classical,\n  by_contra' hf,\n  casesI nonempty_fintype \u03b2,\n  haveI := \u03bb y, fintype_of_not_infinite $ hf y,\n  let key : fintype \u03b1 :=\n  { elems := univ.bUnion (\u03bb (y : \u03b2), (f \u207b\u00b9' {y}).to_finset),\n    complete := by simp },\n  exact key.false,\nend\n\nlemma not_surjective_finite_infinite {\u03b1 \u03b2} [finite \u03b1] [infinite \u03b2] (f : \u03b1 \u2192 \u03b2) : \u00ac surjective f :=\n\u03bb hf, (infinite.of_surjective f hf).not_finite \u2039_\u203a\n\nsection trunc\n\n/--\nA `fintype` with positive cardinality constructively contains an element.\n-/\ndef trunc_of_card_pos {\u03b1} [fintype \u03b1] (h : 0 < fintype.card \u03b1) : trunc \u03b1 :=\nby { letI := (fintype.card_pos_iff.mp h), exact trunc_of_nonempty_fintype \u03b1 }\n\nend trunc\n\n/-- A custom induction principle for fintypes. The base case is a subsingleton type,\nand the induction step is for non-trivial types, and one can assume the hypothesis for\nsmaller types (via `fintype.card`).\n\nThe major premise is `fintype \u03b1`, so to use this with the `induction` tactic you have to give a name\nto that instance and use that name.\n-/\n@[elab_as_eliminator]\nlemma fintype.induction_subsingleton_or_nontrivial\n  {P : \u03a0 \u03b1 [fintype \u03b1], Prop} (\u03b1 : Type*) [fintype \u03b1]\n  (hbase : \u2200 \u03b1 [fintype \u03b1] [subsingleton \u03b1], by exactI P \u03b1)\n  (hstep : \u2200 \u03b1 [fintype \u03b1] [nontrivial \u03b1],\n    by exactI \u2200 (ih : \u2200 \u03b2 [fintype \u03b2], by exactI \u2200 (h : fintype.card \u03b2 < fintype.card \u03b1), P \u03b2),\n    P \u03b1) :\n  P \u03b1 :=\nbegin\n  obtain \u27e8 n, hn \u27e9 : \u2203 n, fintype.card \u03b1 = n := \u27e8fintype.card \u03b1, rfl\u27e9,\n  unfreezingI { induction n using nat.strong_induction_on with n ih generalizing \u03b1 },\n  casesI (subsingleton_or_nontrivial \u03b1) with hsing hnontriv,\n  { apply hbase, },\n  { apply hstep,\n    introsI \u03b2 _ hlt,\n    rw hn at hlt,\n    exact (ih (fintype.card \u03b2) hlt _ rfl), }\nend\n\nnamespace tactic\nopen positivity\n\nprivate lemma card_univ_pos (\u03b1 : Type*) [fintype \u03b1] [nonempty \u03b1] :\n  0 < (finset.univ : finset \u03b1).card :=\nfinset.univ_nonempty.card_pos\n\n/-- Extension for the `positivity` tactic: `finset.card s` is positive if `s` is nonempty. -/\n@[positivity]\nmeta def positivity_finset_card : expr \u2192 tactic strictness\n| `(finset.card %%s) := do -- TODO: Partial decision procedure for `finset.nonempty`\n                          p \u2190 to_expr ``(finset.nonempty %%s) >>= find_assumption,\n                          positive <$> mk_app ``finset.nonempty.card_pos [p]\n| `(@fintype.card %%\u03b1 %%i) := positive <$> mk_mapp ``fintype.card_pos [\u03b1, i, none]\n| e := pp e >>= fail \u2218 format.bracket \"The expression `\"\n    \"` isn't of the form `finset.card s` or `fintype.card \u03b1`\"\n\nend tactic\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/fintype/card.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7045741078542965}}
{"text": "/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Leonardo de Moura, Jeremy Avigad\n\n! This file was ported from Lean 3 source module init.data.subtype.basic\n! leanprover-community/mathlib commit 9af482290ef68e8aaa5ead01aa7b09b7be7019fd\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nprelude\nimport Leanbin.Init.Logic\n\nopen Decidable\n\nuniverse u\n\nnamespace Subtype\n\n#print Subtype.exists_of_subtype /-\ntheorem exists_of_subtype {\u03b1 : Type u} {p : \u03b1 \u2192 Prop} : { x // p x } \u2192 \u2203 x, p x\n  | \u27e8a, h\u27e9 => \u27e8a, h\u27e9\n#align subtype.exists_of_subtype Subtype.exists_of_subtype\n-/\n\nvariable {\u03b1 : Type u} {p : \u03b1 \u2192 Prop}\n\n#print Subtype.tag_irrelevant /-\ntheorem tag_irrelevant {a : \u03b1} (h1 h2 : p a) : mk a h1 = mk a h2 :=\n  rfl\n#align subtype.tag_irrelevant Subtype.tag_irrelevant\n-/\n\n#print Subtype.eq /-\nprotected theorem eq : \u2200 {a1 a2 : { x // p x }}, val a1 = val a2 \u2192 a1 = a2\n  | \u27e8x, h1\u27e9, \u27e8x, h2\u27e9, rfl => rfl\n#align subtype.eq Subtype.eq\n-/\n\n#print Subtype.ne_of_val_ne /-\ntheorem ne_of_val_ne {a1 a2 : { x // p x }} : val a1 \u2260 val a2 \u2192 a1 \u2260 a2 :=\n  mt <| congr_arg _\n#align subtype.ne_of_val_ne Subtype.ne_of_val_ne\n-/\n\n#print Subtype.eta /-\ntheorem eta (a : { x // p x }) (h : p (val a)) : mk (val a) h = a :=\n  Subtype.eq rfl\n#align subtype.eta Subtype.eta\n-/\n\nend Subtype\n\nopen Subtype\n\n#print Subtype.inhabited /-\ndef Subtype.inhabited {\u03b1 : Type u} {p : \u03b1 \u2192 Prop} {a : \u03b1} (h : p a) : Inhabited { x // p x } :=\n  \u27e8\u27e8a, h\u27e9\u27e9\n#align subtype.inhabited Subtype.inhabited\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "lean3port", "sha": "9ed1898f23e4379865ee93d62cb6353e5ed6c270", "save_path": "github-repos/lean/leanprover-community-lean3port", "path": "github-repos/lean/leanprover-community-lean3port/lean3port-9ed1898f23e4379865ee93d62cb6353e5ed6c270/Leanbin/Init/Data/Subtype/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7045741078542965}}
{"text": "/- This file is a tutorial for Coq users getting started\n   with Lean. They are quite similar systems, so picking\n   up Lean should not be too difficult.\n\n   I highly recommend consulting the Coq-Lean cheatsheet\n   that Joey Dodds and I made this summer:\n   https://jldodds.github.io/coq-lean-cheatsheet/\n-/\n\nimport .tactics\n\n/- I'm a big fan of using Unicode while writing Lean.\n   It's similar to Cl\u00e9ment's company-coq mode, \n   using LaTeX-like style, except one completes writing\n   a Unicode symbol with the \"space\" key, rather than\n   \"Enter\".\n   \n   To discover how to type a Unicode symbol, simply\n   hover your mouse over it in VSCode.\n-/\n\nuniverses u v w\n/- Just like there is Coq Vernacular, there are Lean\n   directives like the one above. However, unlike Coq,\n   where we need to separate Vernacular with periods,\n   we don't need to separate Lean directives with any\n   separator. -/\n/- Whereas Coq has both universe polymorphism (if you\n   turn it on) and cumulativity, Lean only has\n   universe polymorphism (but cumulativity can be\n   achieved manually: see `plift` and `ulift`)\n-/\n\n/-- Vectors are an inductive family that represents\n    lists indexed by their length -/\ninductive vector (A : Type u) : \u2115 \u2192 Type u\n| nil {} : vector 0\n| cons {} : \u2200 {n : \u2115}, A \u2192 vector n \u2192 vector n.succ\n/- The purpose of the empty braces after the constructor names\n   is to make the parametric arguments (in this case, `A : Type u`)\n   implicit. -/\n/- Because parametric variables are automatically determined,\n   we don't need to put them in when defining the types of the\n   constructors, e.g., we write `vector 0` instead of `vector A 0`.\n-/\n\nnotation x :: xs := vector.cons x xs\n\n/- The `n.succ` in the index of the result type of `cons` is\n   our first example of Lean's interesting namespacing\n   functionality, that allows one to program in Lean with a\n   sort of object-oriented style. In effect, we see that this\n   is just syntactic sugar:\n-/\nlemma nat_succ_equiv (n : \u2115) : n.succ = nat.succ n := rfl\n\n#check nat.succ\n/- Every constructor is automatically put into the\n   namespace of the name of its datatype. -/\n#check vector.cons\n/- Green underlines may show up for a few reasons:\n   - There is printing output, as in the case above.\n     To view the printing output in VSCode, either mouse over\n     the green underlined text, or put your text cursor\n     over it and read the text in the `Lean Messages` view\n     (which is opened/closed with Ctrl-Shift-Enter.)\n  - There is a use of `sorry`.\n-/\n#check sorry\n\nnamespace vector\n/- We enter the `vector` namespace with the above command, \n   and leave it with `end vector`, seen later.\n\n   Once we leave this block, every definition will be\n   in the namespace `vector`, hence prefixed with\n   `vector.`. Additionally, within this block, all\n   preexisting definitions in the namespace are\n   brought into the local namespace, so for instance,\n   we can just say `nil` rather than `vector.nil`.\n-/\n\ndef zip_with {A : Type u} {B : Type v} {C : Type w} \n  (f : A \u2192 B \u2192 C)\n  : \u2200 {n : \u2115}, vector A n \u2192 vector B n \u2192 vector C n\n| 0 nil nil := nil\n| (nat.succ n) (x :: xs) (y :: ys) := f x y :: zip_with xs ys\n/- There are two ways to create recursive definitions in Lean.\n   One is with the equations compiler, shown above, and the other\n   is by applying recursors directly. Whenever a datatype is defined,\n   recursors are automatically created. For instance:\n-/\n#check @nat.rec\n#check @nat.cases_on\n\nlemma zip_with_assoc {A : Type u} (f : A \u2192 A \u2192 A)\n  (f_assoc : \u2200 x y z, f x (f y z) = f (f x y) z)\n  {n : nat} (xs ys zs : vector A n)\n  : zip_with f xs (zip_with f ys zs) = zip_with f (zip_with f xs ys) zs\n:= begin\ninduction n; cases xs; cases ys; cases zs,\n{ reflexivity },\n{ dsimp [zip_with], f_equal,\n  { rw f_assoc }, -- could also use `simp [f_assoc]`\n  { apply ih_1 }\n  }\nend\n\nend vector\n\n/-- The reflexive-transitive closure of a relation -/\ninductive RTclosure {A : Type u} (R : A \u2192 A \u2192 Prop)\n  : A \u2192 A \u2192 Prop\n| refl {} : \u2200 x, RTclosure x x\n| extend {} : \u2200 {x y z}, R x y \u2192 RTclosure y z \u2192 RTclosure x z\n\nnamespace RTclosure\n\n/-- An example where the equations compiler cannot\n    handle primitive recursion for some reason.\n-/\ndef trans {A : Type u} {R : A \u2192 A \u2192 Prop}\n  : \u2200 {x y z : A}, \n   RTclosure R x y \u2192 RTclosure R y z \u2192 RTclosure R x z\n| x ._ z (refl ._) xz := xz\n| x y z (@extend ._ ._ ._ w ._ xw wy) yz := extend xw (trans wy yz)\n/- Red underlining indicates an error. -/\n\ndef trans' {A : Type u} {R : A \u2192 A \u2192 Prop}\n  {x y z : A} (xy : RTclosure R x y)\n  (yz : RTclosure R y z) : RTclosure R x z\n:= begin\ninduction xy,\n{ assumption },\n{ apply extend, \n  { assumption },\n  { apply ih_1, assumption }\n}\nend\n/- Above is our first look at Lean's Proof mode!\n   To see the current state of your proof in VSCode,\n   hit Ctrl-Shift-Enter (on Mac, Cmd-Shift-Enter)\n   to open up the Lean Messages view.\n\n   What the Lean Messages view tab displays depends\n   on the current position of your text cursor in the\n   buffer that you are editing. -/\n\n#print trans'\n\nend RTclosure\n\n/- We have definitional proof irrelevance-/\n#print proof_irrel\n\n/- That implies UIP -/\nlemma UIP (A : Sort u) (x y : A) (p q : x = y) : p = q := rfl\n\n/- There are quotient types in Lean as well,\n   which implies functional extensionality:\n-/\n#check @funext\n#print funext\n\n/- Universes -/\n\n/- Whereas Coq has both universe cumulativity and (in recent versions,\n   with the appropriate flag) universe polymorphism,\n   Lean has universe polymorphism, but cumulativity must be done\n   manually. -/\ndef no_cumulativity (A : Type u) : Type (u + 1) := A\n\n/- But we can do it manually, using inductive types -/\ninductive lift_succ (A : Type u) : Type (u + 1)\n  | mk : A \u2192 lift_succ\n\ndef manual_cumulativity (A : Type u) : Type (u + 1) := lift_succ A\n\nlemma prop_is_sort_0 : Prop = Sort 0 := rfl\nlemma type_is_type_0 : Type = Type 0 := rfl\nlemma type_u_is_sort_succ_u : Type u = Sort (u + 1) := rfl\nlemma universe_algebra : Sort (max (u + 1) (v + 1)) = Sort (max v u + 1) := rfl\n\n#print plift\n#print ulift", "meta": {"author": "bmsherman", "repo": "lean-tutorial", "sha": "fe58a887b32e5f1e305e1e7a94766cd3585f01e2", "save_path": "github-repos/lean/bmsherman-lean-tutorial", "path": "github-repos/lean/bmsherman-lean-tutorial/lean-tutorial-fe58a887b32e5f1e305e1e7a94766cd3585f01e2/tutorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.704574106941603}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson, Jalex Stark\n-/\nimport algebra.order.with_zero\nimport data.polynomial.monic\n/-!\n# Lemmas for the interaction between polynomials and `\u2211` and `\u220f`.\n\nRecall that `\u2211` and `\u220f` are notation for `finset.sum` and `finset.prod` respectively.\n\n## Main results\n\n- `polynomial.nat_degree_prod_of_monic` : the degree of a product of monic polynomials is the\n  product of degrees. We prove this only for `[comm_semiring R]`,\n  but it ought to be true for `[semiring R]` and `list.prod`.\n- `polynomial.nat_degree_prod` : for polynomials over an integral domain,\n  the degree of the product is the sum of degrees.\n- `polynomial.leading_coeff_prod` : for polynomials over an integral domain,\n  the leading coefficient is the product of leading coefficients.\n- `polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing\n  the second coefficient of the characteristic polynomial.\n-/\n\nopen finset\nopen multiset\n\nopen_locale big_operators polynomial\n\nuniverses u w\n\nvariables {R : Type u} {\u03b9 : Type w}\n\nnamespace polynomial\n\nvariables (s : finset \u03b9)\n\nsection semiring\n\nvariables {S : Type*} [semiring S]\n\nlemma nat_degree_list_sum_le (l : list S[X]) :\n  nat_degree l.sum \u2264 (l.map nat_degree).foldr max 0 :=\nlist.sum_le_foldr_max nat_degree (by simp) nat_degree_add_le _\n\nlemma nat_degree_multiset_sum_le (l : multiset S[X]) :\n  nat_degree l.sum \u2264 (l.map nat_degree).foldr max max_left_comm 0 :=\nquotient.induction_on l (by simpa using nat_degree_list_sum_le)\n\nlemma nat_degree_sum_le (f : \u03b9 \u2192 S[X]) :\n  nat_degree (\u2211 i in s, f i) \u2264 s.fold max 0 (nat_degree \u2218 f) :=\nby simpa using nat_degree_multiset_sum_le (s.val.map f)\n\nlemma degree_list_sum_le (l : list S[X]) :\n  degree l.sum \u2264 (l.map nat_degree).maximum :=\nbegin\n  by_cases h : l.sum = 0,\n  { simp [h] },\n  { rw degree_eq_nat_degree h,\n    suffices : (l.map nat_degree).maximum = ((l.map nat_degree).foldr max 0 : \u2115),\n    { rw this,\n      simpa [this] using nat_degree_list_sum_le l },\n    rw list.maximum_eq_coe_foldr_max_of_ne_nil,\n    { congr },\n    contrapose! h,\n    rw [list.map_eq_nil] at h,\n    simp [h] }\nend\n\n\n\nlemma degree_list_prod_le (l : list S[X]) :\n  degree l.prod \u2264 (l.map degree).sum :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { simpa using (degree_mul_le _ _).trans (add_le_add_left IH _) }\nend\n\nlemma coeff_list_prod_of_nat_degree_le (l : list S[X]) (n : \u2115)\n  (hl : \u2200 p \u2208 l, nat_degree p \u2264 n) :\n  coeff (list.prod l) (l.length * n) = (l.map (\u03bb p, coeff p n)).prod :=\nbegin\n  induction l with hd tl IH,\n  { simp },\n  { have hl' : \u2200 (p \u2208 tl), nat_degree p \u2264 n := \u03bb p hp, hl p (list.mem_cons_of_mem _ hp),\n    simp only [list.prod_cons, list.map, list.length],\n    rw [add_mul, one_mul, add_comm, \u2190IH hl', mul_comm tl.length],\n    have h : nat_degree tl.prod \u2264 n * tl.length,\n    { refine (nat_degree_list_prod_le _).trans _,\n      rw [\u2190tl.length_map nat_degree, mul_comm],\n      refine list.sum_le_card_nsmul _ _ _,\n      simpa using hl' },\n    have hdn : nat_degree hd \u2264 n := hl _ (list.mem_cons_self _ _),\n    rcases hdn.eq_or_lt with rfl|hdn',\n    { cases h.eq_or_lt with h' h',\n      { rw [\u2190h', coeff_mul_degree_add_degree, leading_coeff, leading_coeff] },\n      { rw [coeff_eq_zero_of_nat_degree_lt, coeff_eq_zero_of_nat_degree_lt h', mul_zero],\n        exact nat_degree_mul_le.trans_lt (add_lt_add_left h' _) } },\n    { rw [coeff_eq_zero_of_nat_degree_lt hdn', coeff_eq_zero_of_nat_degree_lt, zero_mul],\n      exact nat_degree_mul_le.trans_lt (add_lt_add_of_lt_of_le hdn' h) } }\nend\n\nend semiring\n\nsection comm_semiring\nvariables [comm_semiring R] (f : \u03b9 \u2192 R[X]) (t : multiset R[X])\n\nlemma nat_degree_multiset_prod_le :\n  t.prod.nat_degree \u2264 (t.map nat_degree).sum :=\nquotient.induction_on t (by simpa using nat_degree_list_prod_le)\n\nlemma nat_degree_prod_le : (\u220f i in s, f i).nat_degree \u2264 \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_le (s.1.map f)\n\n/--\nThe degree of a product of polynomials is at most the sum of the degrees,\nwhere the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_multiset_prod_le :\n  t.prod.degree \u2264 (t.map polynomial.degree).sum :=\nquotient.induction_on t (by simpa using degree_list_prod_le)\n\nlemma degree_prod_le : (\u220f i in s, f i).degree \u2264 \u2211 i in s, (f i).degree :=\nby simpa only [multiset.map_map] using degree_multiset_prod_le (s.1.map f)\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_multiset_prod' (h : (t.map leading_coeff).prod \u2260 0) :\n  t.prod.leading_coeff = (t.map leading_coeff).prod :=\nbegin\n  induction t using multiset.induction_on with a t ih, { simp },\n  simp only [map_cons, multiset.prod_cons] at h \u22a2,\n  rw polynomial.leading_coeff_mul'; { rwa ih, apply right_ne_zero_of_mul h }\nend\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients, provided that this product is nonzero.\n\nSee `polynomial.leading_coeff_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma leading_coeff_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod' (s.1.map f) (by simpa using h)\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_multiset_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_multiset_prod' (h : (t.map (\u03bb f, leading_coeff f)).prod \u2260 0) :\n  t.prod.nat_degree = (t.map (\u03bb f, nat_degree f)).sum :=\nbegin\n  revert h,\n  refine multiset.induction_on t _ (\u03bb a t ih ht, _), { simp },\n  rw [map_cons, multiset.prod_cons] at ht \u22a2,\n  rw [multiset.sum_cons, polynomial.nat_degree_mul', ih],\n  { apply right_ne_zero_of_mul ht },\n  { rwa polynomial.leading_coeff_multiset_prod', apply right_ne_zero_of_mul ht },\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, provided that the product of leading coefficients is nonzero.\n\nSee `polynomial.nat_degree_prod` (without the `'`) for a version for integral domains,\nwhere this condition is automatically satisfied.\n-/\nlemma nat_degree_prod' (h : \u220f i in s, (f i).leading_coeff \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod' (s.1.map f) (by simpa using h)\n\nlemma nat_degree_multiset_prod_of_monic [nontrivial R] (h : \u2200 f \u2208 t, monic f) :\n  t.prod.nat_degree = (t.map nat_degree).sum :=\nbegin\n  apply nat_degree_multiset_prod',\n  suffices : (t.map (\u03bb f, leading_coeff f)).prod = 1, { rw this, simp },\n  convert prod_repeat (1 : R) t.card,\n  { simp only [eq_repeat, multiset.card_map, eq_self_iff_true, true_and],\n    rintros i hi,\n    obtain \u27e8i, hi, rfl\u27e9 := multiset.mem_map.mp hi,\n    apply h, assumption },\n  { simp }\nend\n\nlemma nat_degree_prod_of_monic [nontrivial R] (h : \u2200 i \u2208 s, (f i).monic) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nby simpa using nat_degree_multiset_prod_of_monic (s.1.map f) (by simpa using h)\n\nlemma coeff_multiset_prod_of_nat_degree_le (n : \u2115)\n  (hl : \u2200 p \u2208 t, nat_degree p \u2264 n) :\n  coeff t.prod (t.card * n) = (t.map (\u03bb p, coeff p n)).prod :=\nbegin\n  induction t using quotient.induction_on,\n  simpa using coeff_list_prod_of_nat_degree_le _ _ hl\nend\n\nlemma coeff_prod_of_nat_degree_le (f : \u03b9 \u2192 R[X]) (n : \u2115)\n  (h : \u2200 p \u2208 s, nat_degree (f p) \u2264 n) :\n  coeff (\u220f i in s, f i) (s.card * n) = \u220f i in s, coeff (f i) n :=\nbegin\n  cases s with l hl,\n  convert coeff_multiset_prod_of_nat_degree_le (l.map f) _ _,\n  { simp },\n  { simp },\n  { simpa using h }\nend\n\nlemma coeff_zero_multiset_prod :\n  t.prod.coeff 0 = (t.map (\u03bb f, coeff f 0)).prod :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ht, _), { simp },\n  rw [multiset.prod_cons, map_cons, multiset.prod_cons, polynomial.mul_coeff_zero, ht]\nend\n\nlemma coeff_zero_prod :\n  (\u220f i in s, f i).coeff 0 = \u220f i in s, (f i).coeff 0 :=\nby simpa using coeff_zero_multiset_prod (s.1.map f)\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nopen monic\n-- Eventually this can be generalized with Vieta's formulas\n-- plus the connection between roots and factorization.\nlemma multiset_prod_X_sub_C_next_coeff (t : multiset R) :\n  next_coeff (t.map (\u03bb x, X - C x)).prod = -t.sum :=\nbegin\n  rw next_coeff_multiset_prod,\n  { simp only [next_coeff_X_sub_C],\n    exact t.sum_hom (-add_monoid_hom.id R) },\n  { intros, apply monic_X_sub_C }\nend\n\nlemma prod_X_sub_C_next_coeff {s : finset \u03b9} (f : \u03b9 \u2192 R) :\n  next_coeff \u220f i in s, (X - C (f i)) = -\u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_next_coeff (s.1.map f)\n\nlemma multiset_prod_X_sub_C_coeff_card_pred [nontrivial R] (t : multiset R) (ht : 0 < t.card) :\n  (t.map (\u03bb x, (X - C x))).prod.coeff (t.card - 1) = -t.sum :=\nbegin\n  convert multiset_prod_X_sub_C_next_coeff (by assumption),\n  rw next_coeff, split_ifs,\n  { rw nat_degree_multiset_prod_of_monic at h; simp only [multiset.mem_map] at *,\n    swap, { rintros _ \u27e8_, _, rfl\u27e9, apply monic_X_sub_C },\n    simp_rw [multiset.sum_eq_zero_iff, multiset.mem_map] at h,\n    contrapose! h,\n    obtain \u27e8x, hx\u27e9 := card_pos_iff_exists_mem.mp ht,\n    exact \u27e8_, \u27e8_, \u27e8x, hx, rfl\u27e9, nat_degree_X_sub_C _\u27e9, one_ne_zero\u27e9 },\n  congr, rw nat_degree_multiset_prod_of_monic; { simp [nat_degree_X_sub_C, monic_X_sub_C] },\nend\n\nlemma prod_X_sub_C_coeff_card_pred [nontrivial R] (s : finset \u03b9) (f : \u03b9 \u2192 R) (hs : 0 < s.card) :\n  (\u220f i in s, (X - C (f i))).coeff (s.card - 1) = - \u2211 i in s, f i :=\nby simpa using multiset_prod_X_sub_C_coeff_card_pred (s.1.map f) (by simpa using hs)\n\nend comm_ring\n\nsection no_zero_divisors\nvariables [comm_ring R] [no_zero_divisors R] (f : \u03b9 \u2192 R[X]) (t : multiset R[X])\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees.\n\nSee `polynomial.nat_degree_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma nat_degree_prod [nontrivial R] (h : \u2200 i \u2208 s, f i \u2260 0) :\n  (\u220f i in s, f i).nat_degree = \u2211 i in s, (f i).nat_degree :=\nbegin\n  apply nat_degree_prod',\n  rw prod_ne_zero_iff,\n  intros x hx, simp [h x hx]\nend\n\nlemma nat_degree_multiset_prod [nontrivial R] (s : multiset R[X])\n  (h : (0 : R[X]) \u2209 s) :\n  nat_degree s.prod = (s.map nat_degree).sum :=\nbegin\n  rw nat_degree_multiset_prod',\n  simp_rw [ne.def, multiset.prod_eq_zero_iff, multiset.mem_map, leading_coeff_eq_zero],\n  rintro \u27e8_, h, rfl\u27e9,\n  contradiction\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_multiset_prod [nontrivial R] :\n  t.prod.degree = (t.map (\u03bb f, degree f)).sum :=\nbegin\n  refine multiset.induction_on t _ (\u03bb a t ht, _), { simp },\n  { rw [multiset.prod_cons, degree_mul, ht, map_cons, multiset.sum_cons] }\nend\n\n/--\nThe degree of a product of polynomials is equal to\nthe sum of the degrees, where the degree of the zero polynomial is \u22a5.\n-/\nlemma degree_prod [nontrivial R] : (\u220f i in s, f i).degree = \u2211 i in s, (f i).degree :=\nby simpa using degree_multiset_prod (s.1.map f)\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_multiset_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_multiset_prod :\n  t.prod.leading_coeff = (t.map (\u03bb f, leading_coeff f)).prod :=\nby { rw [\u2190 leading_coeff_hom_apply, monoid_hom.map_multiset_prod], refl }\n\n/--\nThe leading coefficient of a product of polynomials is equal to\nthe product of the leading coefficients.\n\nSee `polynomial.leading_coeff_prod'` (with a `'`) for a version for commutative semirings,\nwhere additionally, the product of the leading coefficients must be nonzero.\n-/\nlemma leading_coeff_prod :\n  (\u220f i in s, f i).leading_coeff = \u220f i in s, (f i).leading_coeff :=\nby simpa using leading_coeff_multiset_prod (s.1.map f)\n\nend no_zero_divisors\nend polynomial\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/polynomial/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7045740993160996}}
{"text": "-- from lean4 src/doc/examples/tc.lean\n\nnamespace tc\n\n/-!\n# A Certified Type Checker\n\nIn this example, we build a certified type checker for a simple expression\nlanguage.\n\nRemark: this example is based on an example in the book [Certified Programming with Dependent Types](http://adam.chlipala.net/cpdt/) by Adam Chlipala.\n-/\ninductive Expr where\n  | nat  : Nat \u2192 Expr\n  | plus : Expr \u2192 Expr \u2192 Expr\n  | bool : Bool \u2192 Expr\n  | and  : Expr \u2192 Expr \u2192 Expr\n  deriving Repr\n\ndef e1 : Expr := .nat 42\n#eval e1\n\ndef e2 : Expr := .nat 17\n#eval e2\n\ndef e3 : Expr := .bool false\n#eval e3\n\ndef e4 : Expr := .bool true\n#eval e4\n\ndef e5 : Expr := .plus e1 e2\n#eval e5\n\ndef e6 : Expr := .plus e1 e3\n#eval e6\n\ndef e7 : Expr := .and e1 e3\n#eval e7\n\ndef e8 : Expr := .and e4 e3\n#eval e8\n\n\n/-!\nWe define a simple language of types using the inductive datatype `Ty`, and\nits typing rules using the inductive predicate `HasType`.\n-/\ninductive Ty where\n  | nat\n  | bool\n  deriving DecidableEq, Repr\n\ninductive HasType : Expr \u2192 Ty \u2192 Prop\n  | nat  : HasType (.nat v) .nat\n  | plus : HasType a .nat \u2192 HasType b .nat \u2192 HasType (.plus a b) .nat\n  | bool : HasType (.bool v) .bool\n  | and  : HasType a .bool \u2192 HasType b .bool \u2192 HasType (.and a b) .bool\n\n/-!\nWe can easily show that if `e` has type `t\u2081` and type `t\u2082`, then `t\u2081` and `t\u2082` must be equal\nby using the the `cases` tactic. This tactic creates a new subgoal for every constructor,\nand automatically discharges unreachable cases. The tactic combinator `tac\u2081 <;> tac\u2082` applies\n`tac\u2082` to each subgoal produced by `tac\u2081`. Then, the tactic `rfl` is used to close all produced\ngoals using reflexivity.\n-/\ntheorem HasType.det (h\u2081 : HasType e t\u2081) (h\u2082 : HasType e t\u2082) : t\u2081 = t\u2082 := by\n  cases h\u2081 <;> cases h\u2082 <;> rfl\n\n/-!\nThe inductive type `Maybe p` has two contructors: `found a h` and `unknown`.\nThe former contains an element `a : \u03b1` and a proof that `a` satisfies the predicate `p`.\nThe constructor `unknown` is used to encode \"failure\".\n-/\n\ninductive Maybe (p : \u03b1 \u2192 Prop) where\n  | found : (a : \u03b1) \u2192 p a \u2192 Maybe p\n  | unknown\n\n/-!\nWe define a notation for `Maybe` that is similar to the builtin notation for the Lean builtin type `Subtype`.\n-/\nnotation \"{{ \" x \" | \" p \" }}\" => Maybe (fun x => p)\n\n/-!\nThe function `Expr.typeCheck e` returns a type `ty` and a proof that `e` has type `ty`,\nor `unknown`.\nRecall that, `def Expr.typeCheck ...` in Lean is notation for `namespace Expr def typeCheck ... end Expr`.\nThe term `.found .nat .nat` is sugar for `Maybe.found Ty.nat HasType.nat`. Lean can infer the namespaces using\nthe expected types.\n-/\ndef Expr.typeCheck (e : Expr) : {{ ty | HasType e ty }} :=\n  match e with\n  | nat ..   => .found .nat .nat\n  | bool ..  => .found .bool .bool\n  | plus a b =>\n    match a.typeCheck, b.typeCheck with\n    | .found .nat h\u2081, .found .nat h\u2082 => .found .nat (.plus h\u2081 h\u2082)\n    | _, _ => .unknown\n  | and a b =>\n    match a.typeCheck, b.typeCheck with\n    | .found .bool h\u2081, .found .bool h\u2082 => .found .bool (.and h\u2081 h\u2082)\n    | _, _ => .unknown\n\n-- def h1 := e3.typeCheck = Maybe.found Ty.bool (.bool e3 Ty.bool)\n-- #eval h1\n\ntheorem Expr.typeCheck_correct (h\u2081 : HasType e ty) (h\u2082 : e.typeCheck \u2260 .unknown)\n        : e.typeCheck = .found ty h := by\n  revert h\u2082\n  cases typeCheck e with\n  | found ty' h' => intro; have := HasType.det h\u2081 h'; subst this; rfl\n  | unknown => intros; contradiction\n\n-- def c3 := e3.typeCheck_correct\n\n/-!\nNow, we prove that if `Expr.typeCheck e` returns `Maybe.unknown`, then forall `ty`, `HasType e ty` does not hold.\nThe notation `e.typeCheck` is sugar for `Expr.typeCheck e`. Lean can infer this because we explicitly said that `e` has type `Expr`.\nThe proof is by induction on `e` and case analysis. The tactic `rename_i` is used to to rename \"inaccessible\" variables.\nWe say a variable is inaccessible if it is introduced by a tactic (e.g., `cases`) or has been shadowed by another variable introduced\nby the user. Note that the tactic `simp [typeCheck]` is applied to all goal generated by the `induction` tactic, and closes\nthe cases corresponding to the constructors `Expr.nat` and `Expr.bool`.\n-/\ntheorem Expr.typeCheck_complete {e : Expr} : e.typeCheck = .unknown \u2192 \u00ac HasType e ty := by\n  induction e with simp [typeCheck]\n  | plus a b iha ihb =>\n    split\n    next => intros; contradiction\n    next ra rb hnp =>\n      -- Recall that `hnp` is a hypothesis generated by the `split` tactic\n      -- that asserts the previous case was not taken\n      intro h ht\n      cases ht with\n      | plus h\u2081 h\u2082 => exact hnp h\u2081 h\u2082 (typeCheck_correct h\u2081 (iha \u00b7 h\u2081)) (typeCheck_correct h\u2082 (ihb \u00b7 h\u2082))\n  | and a b iha ihb =>\n    split\n    next => intros; contradiction\n    next ra rb hnp =>\n      intro h ht\n      cases ht with\n      | and h\u2081 h\u2082 =>  exact hnp h\u2081 h\u2082 (typeCheck_correct h\u2081 (iha \u00b7 h\u2081)) (typeCheck_correct h\u2082 (ihb \u00b7 h\u2082))\n\n/-!\nFinally, we show that type checking for `e` can be decided using `Expr.typeCheck`.\n-/\ninstance (e : Expr) (t : Ty) : Decidable (HasType e t) :=\n  match h' : e.typeCheck with\n  | .found t' ht' =>\n    if heq : t = t' then\n      isTrue (heq \u25b8 ht')\n    else\n      isFalse fun ht => heq (HasType.det ht ht')\n  | .unknown => isFalse (Expr.typeCheck_complete h')\n\n\nend tc", "meta": {"author": "NicolasRouquette", "repo": "oml.lean4", "sha": "a60689536837a52fe21595d79877063f28ec7cfc", "save_path": "github-repos/lean/NicolasRouquette-oml.lean4", "path": "github-repos/lean/NicolasRouquette-oml.lean4/oml.lean4-a60689536837a52fe21595d79877063f28ec7cfc/src/Oml/tc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7045740948114729}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n\n! This file was ported from Lean 3 source module combinatorics.simple_graph.degree_sum\n! leanprover-community/mathlib commit 90659cbe25e59ec302e2fb92b00e9732160cc620\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Combinatorics.SimpleGraph.Basic\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Nat.Parity\nimport Mathlib.Data.ZMod.Parity\n\n/-!\n# Degree-sum formula and handshaking lemma\n\nThe degree-sum formula is that the sum of the degrees of the vertices in\na finite graph is equal to twice the number of edges.  The handshaking lemma,\na corollary, is that the number of odd-degree vertices is even.\n\n## Main definitions\n\n- `SimpleGraph.sum_degrees_eq_twice_card_edges` is the degree-sum formula.\n- `SimpleGraph.even_card_odd_degree_vertices` is the handshaking lemma.\n- `SimpleGraph.odd_card_odd_degree_vertices_ne` is that the number of odd-degree\n  vertices different from a given odd-degree vertex is odd.\n- `SimpleGraph.exists_ne_odd_degree_of_exists_odd_degree` is that the existence of an\n  odd-degree vertex implies the existence of another one.\n\n## Implementation notes\n\nWe give a combinatorial proof by using the facts that (1) the map from\ndarts to vertices is such that each fiber has cardinality the degree\nof the corresponding vertex and that (2) the map from darts to edges is 2-to-1.\n\n## Tags\n\nsimple graphs, sums, degree-sum formula, handshaking lemma\n-/\n\n\nopen Finset\n\nopen BigOperators\n\nnamespace SimpleGraph\n\nuniverse u\n\nvariable {V : Type u} (G : SimpleGraph V)\n\nsection DegreeSum\n\nvariable [Fintype V] [DecidableRel G.Adj]\n\n-- Porting note: Changed to `Fintype (Sym2 V)` to match Combinatorics.SimpleGraph.Basic\nvariable [Fintype (Sym2 V)]\n\ntheorem dart_fst_fiber [DecidableEq V] (v : V) :\n    (univ.filter fun d : G.Dart => d.fst = v) = univ.image (G.dartOfNeighborSet v) := by\n  ext d\n  simp only [mem_image, true_and_iff, mem_filter, SetCoe.exists, mem_univ, exists_prop_of_true]\n  constructor\n  \u00b7 rintro rfl\n    exact \u27e8_, d.is_adj, by ext <;> rfl\u27e9\n  \u00b7 rintro \u27e8e, he, rfl\u27e9\n    rfl\n#align simple_graph.dart_fst_fiber SimpleGraph.dart_fst_fiber\n\ntheorem dart_fst_fiber_card_eq_degree [DecidableEq V] (v : V) :\n    (univ.filter fun d : G.Dart => d.fst = v).card = G.degree v := by\n  simpa only [dart_fst_fiber, Finset.card_univ, card_neighborSet_eq_degree] using\n    card_image_of_injective univ (G.dartOfNeighborSet_injective v)\n#align simple_graph.dart_fst_fiber_card_eq_degree SimpleGraph.dart_fst_fiber_card_eq_degree\n\ntheorem dart_card_eq_sum_degrees : Fintype.card G.Dart = \u2211 v, G.degree v := by\n  haveI := Classical.decEq V\n  simp only [\u2190 card_univ, \u2190 dart_fst_fiber_card_eq_degree]\n  exact card_eq_sum_card_fiberwise (by simp)\n#align simple_graph.dart_card_eq_sum_degrees SimpleGraph.dart_card_eq_sum_degrees\n\nvariable {G} [DecidableEq V]\n\ntheorem Dart.edge_fiber (d : G.Dart) :\n    (univ.filter fun d' : G.Dart => d'.edge = d.edge) = {d, d.symm} :=\n  Finset.ext fun d' => by simpa using dart_edge_eq_iff d' d\n#align simple_graph.dart.edge_fiber SimpleGraph.Dart.edge_fiber\n\nvariable (G)\n\ntheorem dart_edge_fiber_card (e : Sym2 V) (h : e \u2208 G.edgeSet) :\n    (univ.filter fun d : G.Dart => d.edge = e).card = 2 := by\n  refine' Sym2.ind (fun v w h => _) e h\n  let d : G.Dart := \u27e8(v, w), h\u27e9\n  convert congr_arg card d.edge_fiber\n  rw [card_insert_of_not_mem, card_singleton]\n  rw [mem_singleton]\n  exact d.symm_ne.symm\n#align simple_graph.dart_edge_fiber_card SimpleGraph.dart_edge_fiber_card\n\ntheorem dart_card_eq_twice_card_edges : Fintype.card G.Dart = 2 * G.edgeFinset.card := by\n  rw [\u2190 card_univ]\n  rw [@card_eq_sum_card_fiberwise _ _ _ Dart.edge _ G.edgeFinset fun d _h =>\n      by rw [mem_edgeFinset]; apply Dart.edge_mem]\n  rw [\u2190 mul_comm, sum_const_nat]\n  intro e h\n  apply G.dart_edge_fiber_card e\n  rwa [\u2190 mem_edgeFinset]\n#align simple_graph.dart_card_eq_twice_card_edges SimpleGraph.dart_card_eq_twice_card_edges\n\n/-- The degree-sum formula.  This is also known as the handshaking lemma, which might\nmore specifically refer to `SimpleGraph.even_card_odd_degree_vertices`. -/\ntheorem sum_degrees_eq_twice_card_edges : (\u2211 v, G.degree v) = 2 * G.edgeFinset.card :=\n  G.dart_card_eq_sum_degrees.symm.trans G.dart_card_eq_twice_card_edges\n#align simple_graph.sum_degrees_eq_twice_card_edges SimpleGraph.sum_degrees_eq_twice_card_edges\n\nend DegreeSum\n\n/-- The handshaking lemma.  See also `SimpleGraph.sum_degrees_eq_twice_card_edges`. -/\ntheorem even_card_odd_degree_vertices [Fintype V] [DecidableRel G.Adj] :\n    Even (univ.filter fun v => Odd (G.degree v)).card := by\n  classical\n    have h := congr_arg (fun n => \u2191n : \u2115 \u2192 ZMod 2) G.sum_degrees_eq_twice_card_edges\n    simp only [ZMod.nat_cast_self, MulZeroClass.zero_mul, Nat.cast_mul] at h\n    rw [Nat.cast_sum, \u2190 sum_filter_ne_zero] at h\n    rw [@sum_congr _ _ _ _ (fun v => (G.degree v : ZMod 2)) (fun _v => (1 : ZMod 2)) _ rfl] at h\n    \u00b7 simp only [filter_congr, mul_one, nsmul_eq_mul, sum_const, Ne.def] at h\n      rw [\u2190 ZMod.eq_zero_iff_even]\n      convert h\n      exact ZMod.ne_zero_iff_odd.symm\n    \u00b7 intro v\n      simp only [true_and_iff, mem_filter, mem_univ, Ne.def]\n      rw [ZMod.eq_zero_iff_even, ZMod.eq_one_iff_odd, Nat.odd_iff_not_even, imp_self]\n      trivial\n#align simple_graph.even_card_odd_degree_vertices SimpleGraph.even_card_odd_degree_vertices\n\ntheorem odd_card_odd_degree_vertices_ne [Fintype V] [DecidableEq V] [DecidableRel G.Adj] (v : V)\n    (h : Odd (G.degree v)) : Odd (univ.filter fun w => w \u2260 v \u2227 Odd (G.degree w)).card := by\n  rcases G.even_card_odd_degree_vertices with \u27e8k, hg\u27e9\n  have hk : 0 < k := by\n    have hh : (filter (fun v : V => Odd (G.degree v)) univ).Nonempty := by\n      use v\n      simp only [true_and_iff, mem_filter, mem_univ]\n      exact h\n    rwa [\u2190 card_pos, hg, \u2190 two_mul, zero_lt_mul_left] at hh\n    exact zero_lt_two\n  have hc : (fun w : V => w \u2260 v \u2227 Odd (G.degree w)) = fun w : V => Odd (G.degree w) \u2227 w \u2260 v := by\n    ext w\n    rw [and_comm]\n  simp only [hc, filter_congr]\n  rw [\u2190 filter_filter, filter_ne', card_erase_of_mem]\n  \u00b7 refine' \u27e8k - 1, tsub_eq_of_eq_add <| hg.trans _\u27e9\n    rw [add_assoc, one_add_one_eq_two, \u2190 Nat.mul_succ, \u2190 two_mul]\n    congr\n    exact (tsub_add_cancel_of_le <| Nat.succ_le_iff.2 hk).symm\n  \u00b7 simpa only [true_and_iff, mem_filter, mem_univ]\n#align simple_graph.odd_card_odd_degree_vertices_ne SimpleGraph.odd_card_odd_degree_vertices_ne\n\ntheorem exists_ne_odd_degree_of_exists_odd_degree [Fintype V] [DecidableRel G.Adj] (v : V)\n    (h : Odd (G.degree v)) : \u2203 w : V, w \u2260 v \u2227 Odd (G.degree w) := by\n  haveI := Classical.decEq V\n  rcases G.odd_card_odd_degree_vertices_ne v h with \u27e8k, hg\u27e9\n  have hg' : (filter (fun w : V => w \u2260 v \u2227 Odd (G.degree w)) univ).card > 0 := by\n    rw [hg]\n    apply Nat.succ_pos\n  rcases card_pos.mp hg' with \u27e8w, hw\u27e9\n  simp only [true_and_iff, mem_filter, mem_univ, Ne.def] at hw\n  exact \u27e8w, hw\u27e9\n#align simple_graph.exists_ne_odd_degree_of_exists_odd_degree SimpleGraph.exists_ne_odd_degree_of_exists_odd_degree\n\nend SimpleGraph\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/SimpleGraph/DegreeSum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7045740799726821}}
{"text": "-- Cancelativa_de_la_suma_por_la_derecha.lean\n-- Cancelativa de la suma por la derecha.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 1-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si R es un anillo y a, b, c \u2208 R tales que\n--    a + b = c + b\n-- entonces\n--    a = c\n-- ---------------------------------------------------------------------\n\nimport algebra.ring\nimport tactic\n\nvariables {R : Type*} [ring R]\nvariables {a b c : R}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : a + b = c + b)\n  : a = c :=\ncalc a\n     = a + 0        : by rw add_zero\n ... = a + (b + -b) : by rw add_right_neg\n ... = (a + b) + -b : by rw add_assoc\n ... = (c + b) + -b : by rw h\n ... = c + (b + -b) : by rw \u2190 add_assoc\n ... = c + 0        : by rw \u2190 add_right_neg\n ... = c            : by rw add_zero\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : a + b = c + b)\n  : a = c :=\ncalc a\n     = a + 0        : by simp\n ... = a + (b + -b) : by simp\n ... = (a + b) + -b : by simp\n ... = (c + b) + -b : by rw h\n ... = c + (b + -b) : by simp\n ... = c + 0        : by simp\n ... = c            : by simp\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nlemma aux : (a + b) + -b = a :=\nby finish\n\nexample\n  (h : a + b = c + b)\n  : a = c :=\ncalc a\n     = (a + b) + -b : aux.symm\n ... = (c + b) + -b : congr_arg (\u03bb x, x + -b) h\n ... = c            : aux\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : a + b = c + b)\n  : a = c :=\nby finish\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Cancelativa_de_la_suma_por_la_derecha.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7045630767504973}}
{"text": "import group_theory.subgroup.basic\nimport analysis.normed.group.basic\nimport topology.metric_space.basic\n\nimport group_theory.free_group\nimport data.set.basic\nimport algebra.hom.group\n\nimport topology.metric_space.basic\nimport data.list.basic\nimport data.finset\nimport data.set\nimport data.real.ennreal\nimport order.complete_lattice\nimport order.bounded_order\n\nimport fg_norm\n\nnoncomputable theory\n\ntheorem nat.Inf_le_Inf {s t : set \u2115} (hs : s.nonempty) (ht : s \u2286 t) : Inf t \u2264 Inf s \n:= nat.Inf_le $ ht $ nat.Inf_mem hs\n\n@[class]\nstructure generated_group (G : Type*) extends group G :=\n(gens : set G)\n(closure_eq_top : subgroup.closure gens = \u22a4) \n\nvariables {G : Type*} [generated_group G] [decidable_eq G] \n\nnamespace generated_group\n\nopen generated_group\n\ndef of (x : free_group (gens : set G)) : G := begin\n  refine free_group.lift _ x,\n  intro g,\n  use g,\nend\n\ndef of_mul (x : free_group (gens : set G)) (y : free_group (gens : set G)) : of (x * y) = of x * of y :=\nbegin\n  unfold of,\n  simp,\nend\n\ndef words (x : G) : set (free_group (gens : set G)) := of \u207b\u00b9' { x }\n\ndef words_of {x : G} {w : free_group (gens : set G)} (h : w \u2208 words x) : of w = x :=\nbegin\n  unfold words at h,\n  simp only [set.mem_preimage, set.mem_singleton_iff] at h,\n  exact h, \nend\n\ndef words_inv (x : G) : (words x) = has_inv.inv '' (words x\u207b\u00b9) :=\nbegin\n  unfold words,\n  ext,\n  split, \n  {\n    simp only [set.mem_preimage, set.mem_singleton_iff, set.image_inv, set.mem_inv],\n    intro h,\n    rw \u2190 h,\n    simp only [map_inv, of],\n  },\n  {\n    simp only [set.image_inv, set.mem_inv, set.mem_preimage, set.mem_singleton_iff],\n    intro h,\n    have hk : (of x_1\u207b\u00b9)\u207b\u00b9 = x,\n    { exact inv_eq_iff_inv_eq.mp (eq.symm h) },\n    rw \u2190 hk,\n    simp [of],\n  },\nend\n\ndef push_inv (x : G) : (words x\u207b\u00b9) = has_inv.inv '' (words x) :=\nbegin\n  have k := words_inv x\u207b\u00b9,\n  finish,\nend\n\ndef words_nonempty (x : G) : (words x).nonempty :=\nbegin\n  have hk := @closure_eq_top G _,\n  unfold words,\n  unfold set.nonempty,\n  simp only [set.mem_preimage, set.mem_singleton_iff],\n\n  set f : (gens \u2192 G) := (\u03bb a : (gens : set G), a) with hf,\n\n  have hr : set.range f = (gens : set G),\n  {\n    ext,\n    split,\n    { finish, },\n    { intro h,\n      use x_1,\n      use h,\n      finish, },\n  },  \n\n  have h : _ = subgroup.closure (set.range f) := free_group.lift.range_eq_closure  ,\n\n  rw hr at h,\n  rw hk at h,\n\n  rw monoid_hom.range_top_iff_surjective at h,\n \n  unfold of,\n\n  rw \u2190 hf ,\n\n  exact h x,\nend\n\ndef nat_norm (x : G) : nat := Inf $ free_group.nat_norm '' (words x)\n\ndef norm (x : G) : \u211d := nat_norm x\n\ninstance : has_norm G := \u27e8norm\u27e9\n\ndef dist (x : G) (y : G) : \u211d := \u2225 x * y\u207b\u00b9 \u2225\n\ninstance : has_dist G := \u27e8dist\u27e9\n\ndef norm_eq (x : G) : \u2225 x \u2225 = nat_norm x := rfl\n\ndef norm_inv_le (x : G) : \u2225 x\u207b\u00b9 \u2225 \u2264 \u2225 x \u2225 :=\nbegin\n  rw norm_eq, rw norm_eq,\n  norm_cast,\n\n  rw nat_norm, rw nat_norm,\n  apply nat.Inf_le_Inf,\n  {\n    have hne := words_nonempty x,\n    exact set.nonempty.image free_group.nat_norm hne,\n  },\n  {  \n    rw push_inv,\n    intros nw hnw,\n    simp only [set.mem_image] at hnw,\n    simp only [set.image_inv, set.mem_image, set.mem_inv],\n    cases hnw with fw hfw,\n    use fw\u207b\u00b9,\n    simp,\n    refine \u27e8 hfw.1, _ \u27e9,\n    rw \u2190 hfw.2,\n    symmetry,\n    have k := free_group.norm_inv fw,\n    rw free_group.norm_eq at k,\n    rw free_group.norm_eq at k,\n    norm_cast at k,\n    assumption,\n  },\nend\n\ndef norm_inv (x : G) : \u2225 x \u2225 = \u2225 x\u207b\u00b9 \u2225 :=\nbegin\n  have h := norm_inv_le x,\n  have hi := norm_inv_le x\u207b\u00b9,\n  simp at hi,\n  finish,\nend\n\ndef dist_eq (x y : G) : dist x y = nat_norm (x * y\u207b\u00b9) := rfl\n\ndef dist_self (x : G) : dist x x = 0 :=\nbegin\n  rw dist_eq,\n  norm_cast,\n  \n  rw nat_norm,\n\n  suffices : Inf (free_group.nat_norm '' words (x * x\u207b\u00b9)) \u2264 0,\n  { exact le_zero_iff.mp this, },\n\n  suffices : 0 \u2208 free_group.nat_norm '' words (x * x\u207b\u00b9),\n  { apply nat.Inf_le this, },\n\n  simp only [mul_right_inv, set.mem_image],\n  use 1,\n\n  split,\n  { simp only [words, of], },\n  { unfold free_group.nat_norm,\n    rw list.length_eq_zero,\n    exact free_group.one_to_word, \n  }, \nend\n\ndef dist_comm (x y : G) : dist x y = dist y x :=\nbegin\n  rw dist_eq, rw dist_eq,\n  norm_cast,\n\n  set z := x * y\u207b\u00b9,\n  set zi := y * x\u207b\u00b9,\n\n  have h : zi = z\u207b\u00b9,\n  { simp only [mul_inv_rev, inv_inv], },\n\n  have hk := norm_inv z,\n  rw norm_eq at hk,\n  rw norm_eq at hk,\n  norm_cast at hk,\n  rwa h,\nend\n\ndef dist_triangle (x y z : G) : (dist x z) \u2264 (dist x y) + (dist y z) :=\nbegin\n  rw dist_eq,\n  rw dist_eq,\n  rw dist_eq,\n  norm_cast,\n \n  set xz := x * z\u207b\u00b9 with hxz,\n  set xy := x * y\u207b\u00b9 with hxy,\n  set yz := y * z\u207b\u00b9 with hyz,\n\n  unfold nat_norm,\n\n  have h1 := nat.Inf_mem (by simp [words_nonempty] : (free_group.nat_norm '' words xy).nonempty),\n  have h2 := nat.Inf_mem (by simp [words_nonempty] : (free_group.nat_norm '' words yz).nonempty),\n\n  cases h1 with wxy hwxy,\n  cases h2 with wyz hwyz,\n      \n  rw \u2190 hwyz.2,\n  rw \u2190 hwxy.2,\n\n  have h : wxy * wyz \u2208 words xz,\n  {\n    unfold words,\n    simp only [set.mem_preimage, set.mem_singleton_iff],\n    rw of_mul,\n    have hxyw := words_of hwxy.1,\n    have hyzw := words_of hwyz.1,\n    rw hxyw,\n    rw hyzw,\n    rw hxy,\n    rw hyz,\n    rw hxz,\n    group,\n  },\n\n  have h2 : free_group.nat_norm (wxy * wyz) \u2208 free_group.nat_norm '' (words xz), \n  { exact set.mem_image_of_mem free_group.nat_norm h, },\n\n  have h3 : Inf ( free_group.nat_norm '' words xz ) \u2264 free_group.nat_norm (wxy * wyz ),\n  {\n    exact cInf_le' h2,\n  },\n   \n  have h4 : free_group.nat_norm( wxy * wyz ) \u2264 wxy.nat_norm + wyz.nat_norm,\n  {\n     have h5 : \u2225 wxy * wyz \u2225 \u2264 \u2225 wxy \u2225 + \u2225 wyz \u2225 := free_group.norm_triangle _ _,\n     rw free_group.norm_eq at h5,\n     rw free_group.norm_eq at h5,\n     rw free_group.norm_eq at h5,\n     norm_cast at h5,\n     assumption, \n  }, \n  \n  finish,\nend\n\ndef eq_of_dist_eq_zero (x y : G) : dist x y = 0 \u2192 x = y := \nbegin\n  rw dist_eq,\n  intro h,\n  norm_cast at h,\n\n  unfold nat_norm at h,\n\n  rw nat.Inf_eq_zero at h,\n  cases h,\n  { simp only [set.mem_image] at h,\n    rcases h with \u27e8 w, hw1, hw2 \u27e9,\n    have hk := free_group.norm_zero_eq_one w,\n    have hi : w = 1, { apply hk, rw free_group.norm_eq, norm_cast, assumption, },\n  \n    rw hi at hw1,\n  \n    unfold words at hw1,\n    simp [of] at hw1,\n    group, -- this should be simpler?\n    rw hw1,\n    group, \n  },\n  {\n    exfalso, \n    have hne := words_nonempty (x * y\u207b\u00b9),\n    finish,\n  },\nend\n\ninstance : pseudo_metric_space G :=\n{ dist               := dist,\n  dist_self          := dist_self,\n  dist_comm          := dist_comm,\n  dist_triangle      := dist_triangle }\n\ninstance : metric_space G :=\n{ eq_of_dist_eq_zero := eq_of_dist_eq_zero }\n\nend generated_group\n\n", "meta": {"author": "kisonecat", "repo": "word-metric", "sha": "533a77de1a24c07b7c171d552cb208c219bd53e7", "save_path": "github-repos/lean/kisonecat-word-metric", "path": "github-repos/lean/kisonecat-word-metric/word-metric-533a77de1a24c07b7c171d552cb208c219bd53e7/src/word_metric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.704561804086609}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Tim Baanen\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.determinant\n! leanprover-community/mathlib commit c3019c79074b0619edb4b27553a91b2e82242395\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Matrix.Pequiv\nimport Mathbin.Data.Matrix.Block\nimport Mathbin.Data.Matrix.Notation\nimport Mathbin.Data.Fintype.BigOperators\nimport Mathbin.GroupTheory.Perm.Fin\nimport Mathbin.GroupTheory.Perm.Sign\nimport Mathbin.Algebra.Algebra.Basic\nimport Mathbin.Tactic.Ring\nimport Mathbin.LinearAlgebra.Alternating\nimport Mathbin.LinearAlgebra.Pi\n\n/-!\n# Determinant of a matrix\n\nThis file defines the determinant of a matrix, `matrix.det`, and its essential properties.\n\n## Main definitions\n\n - `matrix.det`: the determinant of a square matrix, as a sum over permutations\n - `matrix.det_row_alternating`: the determinant, as an `alternating_map` in the rows of the matrix\n\n## Main results\n\n - `det_mul`: the determinant of `A \u2b1d B` is the product of determinants\n - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row\n - `det_block_diagonal`: the determinant of a block diagonal matrix is a product\n   of the blocks' determinants\n\n## Implementation notes\n\nIt is possible to configure `simp` to compute determinants. See the file\n`test/matrix.lean` for some examples.\n\n-/\n\n\nuniverse u v w z\n\nopen Equiv Equiv.Perm Finset Function\n\nnamespace Matrix\n\nopen Matrix BigOperators\n\nvariable {m n : Type _} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m]\n\nvariable {R : Type v} [CommRing R]\n\n-- mathport name: \u00abexpr\u03b5 \u00bb\nlocal notation \"\u03b5 \" \u03c3:arg => ((sign \u03c3 : \u2124) : R)\n\n/-- `det` is an `alternating_map` in the rows of the matrix. -/\ndef detRowAlternating : AlternatingMap R (n \u2192 R) R n :=\n  ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj).alternatization\n#align matrix.det_row_alternating Matrix.detRowAlternating\n\n/-- The determinant of a matrix given by the Leibniz formula. -/\nabbrev det (M : Matrix n n R) : R :=\n  detRowAlternating M\n#align matrix.det Matrix.det\n\ntheorem det_apply (M : Matrix n n R) : M.det = \u2211 \u03c3 : Perm n, \u03c3.sign \u2022 \u220f i, M (\u03c3 i) i :=\n  MultilinearMap.alternatization_apply _ M\n#align matrix.det_apply Matrix.det_apply\n\n-- This is what the old definition was. We use it to avoid having to change the old proofs below\ntheorem det_apply' (M : Matrix n n R) : M.det = \u2211 \u03c3 : Perm n, \u03b5 \u03c3 * \u220f i, M (\u03c3 i) i := by\n  simp [det_apply, Units.smul_def]\n#align matrix.det_apply' Matrix.det_apply'\n\n@[simp]\ntheorem det_diagonal {d : n \u2192 R} : det (diagonal d) = \u220f i, d i :=\n  by\n  rw [det_apply']\n  refine' (Finset.sum_eq_single 1 _ _).trans _\n  \u00b7 intro \u03c3 h1 h2\n    cases' not_forall.1 (mt Equiv.ext h2) with x h3\n    convert MulZeroClass.mul_zero _\n    apply Finset.prod_eq_zero\n    \u00b7 change x \u2208 _\n      simp\n    exact if_neg h3\n  \u00b7 simp\n  \u00b7 simp\n#align matrix.det_diagonal Matrix.det_diagonal\n\n@[simp]\ntheorem det_zero (h : Nonempty n) : det (0 : Matrix n n R) = 0 :=\n  (detRowAlternating : AlternatingMap R (n \u2192 R) R n).map_zero\n#align matrix.det_zero Matrix.det_zero\n\n@[simp]\ntheorem det_one : det (1 : Matrix n n R) = 1 := by rw [\u2190 diagonal_one] <;> simp [-diagonal_one]\n#align matrix.det_one Matrix.det_one\n\ntheorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply]\n#align matrix.det_is_empty Matrix.det_isEmpty\n\n@[simp]\ntheorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R \u2192 R) = Function.const _ 1 :=\n  by\n  ext\n  exact det_is_empty\n#align matrix.coe_det_is_empty Matrix.coe_det_isEmpty\n\ntheorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 :=\n  haveI : IsEmpty n := fintype.card_eq_zero_iff.mp h\n  det_is_empty\n#align matrix.det_eq_one_of_card_eq_zero Matrix.det_eq_one_of_card_eq_zero\n\n/-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element.\nAlthough `unique` implies `decidable_eq` and `fintype`, the instances might\nnot be syntactically equal. Thus, we need to fill in the args explicitly. -/\n@[simp]\ntheorem det_unique {n : Type _} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) :\n    det A = A default default := by simp [det_apply, univ_unique]\n#align matrix.det_unique Matrix.det_unique\n\ntheorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) : det A = A k k :=\n  by\n  convert det_unique _\n  exact uniqueOfSubsingleton k\n#align matrix.det_eq_elem_of_subsingleton Matrix.det_eq_elem_of_subsingleton\n\ntheorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) :\n    det A = A k k :=\n  haveI : Subsingleton n := fintype.card_le_one_iff_subsingleton.mp h.le\n  det_eq_elem_of_subsingleton _ _\n#align matrix.det_eq_elem_of_card_eq_one Matrix.det_eq_elem_of_card_eq_one\n\ntheorem det_mul_aux {M N : Matrix n n R} {p : n \u2192 n} (H : \u00acBijective p) :\n    (\u2211 \u03c3 : Perm n, \u03b5 \u03c3 * \u220f x, M (\u03c3 x) (p x) * N (p x) x) = 0 :=\n  by\n  obtain \u27e8i, j, hpij, hij\u27e9 : \u2203 i j, p i = p j \u2227 i \u2260 j :=\n    by\n    rw [\u2190 Finite.injective_iff_bijective, injective] at H\n    push_neg  at H\n    exact H\n  exact\n    sum_involution (fun \u03c3 _ => \u03c3 * swap i j)\n      (fun \u03c3 _ =>\n        by\n        have : (\u220f x, M (\u03c3 x) (p x)) = \u220f x, M ((\u03c3 * swap i j) x) (p x) :=\n          Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij])\n        simp [this, sign_swap hij, prod_mul_distrib])\n      (fun \u03c3 _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun \u03c3 _ =>\n      mul_swap_involutive i j \u03c3\n#align matrix.det_mul_aux Matrix.det_mul_aux\n\n@[simp]\ntheorem det_mul (M N : Matrix n n R) : det (M \u2b1d N) = det M * det N :=\n  calc\n    det (M \u2b1d N) = \u2211 p : n \u2192 n, \u2211 \u03c3 : Perm n, \u03b5 \u03c3 * \u220f i, M (\u03c3 i) (p i) * N (p i) i := by\n      simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] <;>\n        rw [Finset.sum_comm]\n    _ =\n        \u2211 p in (@univ (n \u2192 n) _).filter\u2093 Bijective,\n          \u2211 \u03c3 : Perm n, \u03b5 \u03c3 * \u220f i, M (\u03c3 i) (p i) * N (p i) i :=\n      (Eq.symm <|\n        sum_subset (filter_subset _ _) fun f _ hbij =>\n          det_mul_aux <| by simpa only [true_and_iff, mem_filter, mem_univ] using hbij)\n    _ = \u2211 \u03c4 : Perm n, \u2211 \u03c3 : Perm n, \u03b5 \u03c3 * \u220f i, M (\u03c3 i) (\u03c4 i) * N (\u03c4 i) i :=\n      (sum_bij (fun p h => Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ => mem_univ _)\n        (fun _ _ => rfl) (fun _ _ _ _ h => by injection h) fun b _ =>\n        \u27e8b, mem_filter.2 \u27e8mem_univ _, b.Bijective\u27e9, coe_fn_injective rfl\u27e9)\n    _ = \u2211 \u03c3 : Perm n, \u2211 \u03c4 : Perm n, (\u220f i, N (\u03c3 i) i) * \u03b5 \u03c4 * \u220f j, M (\u03c4 j) (\u03c3 j) := by\n      simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc]\n    _ = \u2211 \u03c3 : Perm n, \u2211 \u03c4 : Perm n, (\u220f i, N (\u03c3 i) i) * (\u03b5 \u03c3 * \u03b5 \u03c4) * \u220f i, M (\u03c4 i) i :=\n      (sum_congr rfl fun \u03c3 _ =>\n        Fintype.sum_equiv (Equiv.mulRight \u03c3\u207b\u00b9) _ _ fun \u03c4 =>\n          by\n          have : (\u220f j, M (\u03c4 j) (\u03c3 j)) = \u220f j, M ((\u03c4 * \u03c3\u207b\u00b9) j) j :=\n            by\n            rw [\u2190 (\u03c3\u207b\u00b9 : _ \u2243 _).prod_comp]\n            simp only [Equiv.Perm.coe_mul, apply_inv_self]\n          have h : \u03b5 \u03c3 * \u03b5 (\u03c4 * \u03c3\u207b\u00b9) = \u03b5 \u03c4 :=\n            calc\n              \u03b5 \u03c3 * \u03b5 (\u03c4 * \u03c3\u207b\u00b9) = \u03b5 (\u03c4 * \u03c3\u207b\u00b9 * \u03c3) :=\n                by\n                rw [mul_comm, sign_mul (\u03c4 * \u03c3\u207b\u00b9)]\n                simp only [Int.cast_mul, Units.val_mul]\n              _ = \u03b5 \u03c4 := by simp only [inv_mul_cancel_right]\n              \n          simp_rw [Equiv.coe_mulRight, h]\n          simp only [this])\n    _ = det M * det N := by simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm]\n    \n#align matrix.det_mul Matrix.det_mul\n\n/-- The determinant of a matrix, as a monoid homomorphism. -/\ndef detMonoidHom : Matrix n n R \u2192* R where\n  toFun := det\n  map_one' := det_one\n  map_mul' := det_mul\n#align matrix.det_monoid_hom Matrix.detMonoidHom\n\n@[simp]\ntheorem coe_detMonoidHom : (detMonoidHom : Matrix n n R \u2192 R) = det :=\n  rfl\n#align matrix.coe_det_monoid_hom Matrix.coe_detMonoidHom\n\n/-- On square matrices, `mul_comm` applies under `det`. -/\ntheorem det_mul_comm (M N : Matrix m m R) : det (M \u2b1d N) = det (N \u2b1d M) := by\n  rw [det_mul, det_mul, mul_comm]\n#align matrix.det_mul_comm Matrix.det_mul_comm\n\n/-- On square matrices, `mul_left_comm` applies under `det`. -/\ntheorem det_mul_left_comm (M N P : Matrix m m R) : det (M \u2b1d (N \u2b1d P)) = det (N \u2b1d (M \u2b1d P)) := by\n  rw [\u2190 Matrix.mul_assoc, \u2190 Matrix.mul_assoc, det_mul, det_mul_comm M N, \u2190 det_mul]\n#align matrix.det_mul_left_comm Matrix.det_mul_left_comm\n\n/-- On square matrices, `mul_right_comm` applies under `det`. -/\ntheorem det_mul_right_comm (M N P : Matrix m m R) : det (M \u2b1d N \u2b1d P) = det (M \u2b1d P \u2b1d N) := by\n  rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, \u2190 det_mul]\n#align matrix.det_mul_right_comm Matrix.det_mul_right_comm\n\ntheorem det_units_conj (M : (Matrix m m R)\u02e3) (N : Matrix m m R) :\n    det (\u2191M \u2b1d N \u2b1d \u2191M\u207b\u00b9 : Matrix m m R) = det N := by\n  rw [det_mul_right_comm, \u2190 mul_eq_mul, \u2190 mul_eq_mul, Units.mul_inv, one_mul]\n#align matrix.det_units_conj Matrix.det_units_conj\n\ntheorem det_units_conj' (M : (Matrix m m R)\u02e3) (N : Matrix m m R) :\n    det (\u2191M\u207b\u00b9 \u2b1d N \u2b1d \u2191M : Matrix m m R) = det N :=\n  det_units_conj M\u207b\u00b9 N\n#align matrix.det_units_conj' Matrix.det_units_conj'\n\n/-- Transposing a matrix preserves the determinant. -/\n@[simp]\ntheorem det_transpose (M : Matrix n n R) : M\u1d40.det = M.det :=\n  by\n  rw [det_apply', det_apply']\n  refine' Fintype.sum_bijective _ inv_involutive.bijective _ _ _\n  intro \u03c3\n  rw [sign_inv]\n  congr 1\n  apply Fintype.prod_equiv \u03c3\n  intros\n  simp\n#align matrix.det_transpose Matrix.det_transpose\n\n/-- Permuting the columns changes the sign of the determinant. -/\ntheorem det_permute (\u03c3 : Perm n) (M : Matrix n n R) :\n    (Matrix.det fun i => M (\u03c3 i)) = \u03c3.sign * M.det :=\n  ((detRowAlternating : AlternatingMap R (n \u2192 R) R n).map_perm M \u03c3).trans (by simp [Units.smul_def])\n#align matrix.det_permute Matrix.det_permute\n\n/-- Permuting rows and columns with the same equivalence has no effect. -/\n@[simp]\ntheorem det_submatrix_equiv_self (e : n \u2243 m) (A : Matrix m m R) : det (A.submatrix e e) = det A :=\n  by\n  rw [det_apply', det_apply']\n  apply Fintype.sum_equiv (Equiv.permCongr e)\n  intro \u03c3\n  rw [Equiv.Perm.sign_permCongr e \u03c3]\n  congr 1\n  apply Fintype.prod_equiv e\n  intro i\n  rw [Equiv.permCongr_apply, Equiv.symm_apply_apply, submatrix_apply]\n#align matrix.det_submatrix_equiv_self Matrix.det_submatrix_equiv_self\n\n/-- Reindexing both indices along the same equivalence preserves the determinant.\n\nFor the `simp` version of this lemma, see `det_submatrix_equiv_self`; this one is unsuitable because\n`matrix.reindex_apply` unfolds `reindex` first.\n-/\ntheorem det_reindex_self (e : m \u2243 n) (A : Matrix m m R) : det (reindex e e A) = det A :=\n  det_submatrix_equiv_self e.symm A\n#align matrix.det_reindex_self Matrix.det_reindex_self\n\n/-- The determinant of a permutation matrix equals its sign. -/\n@[simp]\ntheorem det_permutation (\u03c3 : Perm n) : Matrix.det (\u03c3.toPEquiv.toMatrix : Matrix n n R) = \u03c3.sign :=\n  by\n  rw [\u2190 Matrix.mul_one (\u03c3.to_pequiv.to_matrix : Matrix n n R), PEquiv.toPEquiv_mul_matrix,\n    det_permute, det_one, mul_one]\n#align matrix.det_permutation Matrix.det_permutation\n\ntheorem det_smul (A : Matrix n n R) (c : R) : det (c \u2022 A) = c ^ Fintype.card n * det A :=\n  calc\n    det (c \u2022 A) = det (Matrix.mul (diagonal fun _ => c) A) := by rw [smul_eq_diagonal_mul]\n    _ = det (diagonal fun _ => c) * det A := (det_mul _ _)\n    _ = c ^ Fintype.card n * det A := by simp [card_univ]\n    \n#align matrix.det_smul Matrix.det_smul\n\n@[simp]\ntheorem det_smul_of_tower {\u03b1} [Monoid \u03b1] [DistribMulAction \u03b1 R] [IsScalarTower \u03b1 R R]\n    [SMulCommClass \u03b1 R R] (c : \u03b1) (A : Matrix n n R) : det (c \u2022 A) = c ^ Fintype.card n \u2022 det A :=\n  by rw [\u2190 smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul]\n#align matrix.det_smul_of_tower Matrix.det_smul_of_tower\n\ntheorem det_neg (A : Matrix n n R) : det (-A) = (-1) ^ Fintype.card n * det A := by\n  rw [\u2190 det_smul, neg_one_smul]\n#align matrix.det_neg Matrix.det_neg\n\n/-- A variant of `matrix.det_neg` with scalar multiplication by `units \u2124` instead of multiplication\nby `R`. -/\ntheorem det_neg_eq_smul (A : Matrix n n R) : det (-A) = (-1 : Units \u2124) ^ Fintype.card n \u2022 det A :=\n  by rw [\u2190 det_smul_of_tower, Units.neg_smul, one_smul]\n#align matrix.det_neg_eq_smul Matrix.det_neg_eq_smul\n\n/-- Multiplying each row by a fixed `v i` multiplies the determinant by\nthe product of the `v`s. -/\ntheorem det_mul_row (v : n \u2192 R) (A : Matrix n n R) :\n    det (of fun i j => v j * A i j) = (\u220f i, v i) * det A :=\n  calc\n    det (of fun i j => v j * A i j) = det (A \u2b1d diagonal v) :=\n      congr_arg det <| by\n        ext\n        simp [mul_comm]\n    _ = (\u220f i, v i) * det A := by rw [det_mul, det_diagonal, mul_comm]\n    \n#align matrix.det_mul_row Matrix.det_mul_row\n\n/-- Multiplying each column by a fixed `v j` multiplies the determinant by\nthe product of the `v`s. -/\ntheorem det_mul_column (v : n \u2192 R) (A : Matrix n n R) :\n    det (of fun i j => v i * A i j) = (\u220f i, v i) * det A :=\n  MultilinearMap.map_smul_univ _ v A\n#align matrix.det_mul_column Matrix.det_mul_column\n\n@[simp]\ntheorem det_pow (M : Matrix m m R) (n : \u2115) : det (M ^ n) = det M ^ n :=\n  (detMonoidHom : Matrix m m R \u2192* R).map_pow M n\n#align matrix.det_pow Matrix.det_pow\n\nsection HomMap\n\nvariable {S : Type w} [CommRing S]\n\ntheorem RingHom.map_det (f : R \u2192+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) :=\n  by simp [Matrix.det_apply', f.map_sum, f.map_prod]\n#align ring_hom.map_det RingHom.map_det\n\ntheorem RingEquiv.map_det (f : R \u2243+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) :=\n  f.toRingHom.map_det _\n#align ring_equiv.map_det RingEquiv.map_det\n\ntheorem AlgHom.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S \u2192\u2090[R] T)\n    (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) :=\n  f.toRingHom.map_det _\n#align alg_hom.map_det AlgHom.map_det\n\ntheorem AlgEquiv.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S \u2243\u2090[R] T)\n    (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) :=\n  f.toAlgHom.map_det _\n#align alg_equiv.map_det AlgEquiv.map_det\n\nend HomMap\n\n@[simp]\ntheorem det_conjTranspose [StarRing R] (M : Matrix m m R) : det M\u1d34 = star (det M) :=\n  ((starRingEnd R).map_det _).symm.trans <| congr_arg star M.det_transpose\n#align matrix.det_conj_transpose Matrix.det_conjTranspose\n\nsection DetZero\n\n/-!\n### `det_zero` section\n\nProve that a matrix with a repeated column has determinant equal to zero.\n-/\n\n\ntheorem det_eq_zero_of_row_eq_zero {A : Matrix n n R} (i : n) (h : \u2200 j, A i j = 0) : det A = 0 :=\n  (detRowAlternating : AlternatingMap R (n \u2192 R) R n).map_coord_zero i (funext h)\n#align matrix.det_eq_zero_of_row_eq_zero Matrix.det_eq_zero_of_row_eq_zero\n\ntheorem det_eq_zero_of_column_eq_zero {A : Matrix n n R} (j : n) (h : \u2200 i, A i j = 0) : det A = 0 :=\n  by\n  rw [\u2190 det_transpose]\n  exact det_eq_zero_of_row_eq_zero j h\n#align matrix.det_eq_zero_of_column_eq_zero Matrix.det_eq_zero_of_column_eq_zero\n\nvariable {M : Matrix n n R} {i j : n}\n\n/-- If a matrix has a repeated row, the determinant will be zero. -/\ntheorem det_zero_of_row_eq (i_ne_j : i \u2260 j) (hij : M i = M j) : M.det = 0 :=\n  (detRowAlternating : AlternatingMap R (n \u2192 R) R n).map_eq_zero_of_eq M hij i_ne_j\n#align matrix.det_zero_of_row_eq Matrix.det_zero_of_row_eq\n\n/-- If a matrix has a repeated column, the determinant will be zero. -/\ntheorem det_zero_of_column_eq (i_ne_j : i \u2260 j) (hij : \u2200 k, M k i = M k j) : M.det = 0 :=\n  by\n  rw [\u2190 det_transpose, det_zero_of_row_eq i_ne_j]\n  exact funext hij\n#align matrix.det_zero_of_column_eq Matrix.det_zero_of_column_eq\n\nend DetZero\n\ntheorem det_updateRow_add (M : Matrix n n R) (j : n) (u v : n \u2192 R) :\n    det (updateRow M j <| u + v) = det (updateRow M j u) + det (updateRow M j v) :=\n  (detRowAlternating : AlternatingMap R (n \u2192 R) R n).map_add M j u v\n#align matrix.det_update_row_add Matrix.det_updateRow_add\n\ntheorem det_updateColumn_add (M : Matrix n n R) (j : n) (u v : n \u2192 R) :\n    det (updateColumn M j <| u + v) = det (updateColumn M j u) + det (updateColumn M j v) :=\n  by\n  rw [\u2190 det_transpose, \u2190 update_row_transpose, det_update_row_add]\n  simp [update_row_transpose, det_transpose]\n#align matrix.det_update_column_add Matrix.det_updateColumn_add\n\ntheorem det_updateRow_smul (M : Matrix n n R) (j : n) (s : R) (u : n \u2192 R) :\n    det (updateRow M j <| s \u2022 u) = s * det (updateRow M j u) :=\n  (detRowAlternating : AlternatingMap R (n \u2192 R) R n).map_smul M j s u\n#align matrix.det_update_row_smul Matrix.det_updateRow_smul\n\ntheorem det_updateColumn_smul (M : Matrix n n R) (j : n) (s : R) (u : n \u2192 R) :\n    det (updateColumn M j <| s \u2022 u) = s * det (updateColumn M j u) :=\n  by\n  rw [\u2190 det_transpose, \u2190 update_row_transpose, det_update_row_smul]\n  simp [update_row_transpose, det_transpose]\n#align matrix.det_update_column_smul Matrix.det_updateColumn_smul\n\ntheorem det_updateRow_smul' (M : Matrix n n R) (j : n) (s : R) (u : n \u2192 R) :\n    det (updateRow (s \u2022 M) j u) = s ^ (Fintype.card n - 1) * det (updateRow M j u) :=\n  MultilinearMap.map_update_smul _ M j s u\n#align matrix.det_update_row_smul' Matrix.det_updateRow_smul'\n\ntheorem det_updateColumn_smul' (M : Matrix n n R) (j : n) (s : R) (u : n \u2192 R) :\n    det (updateColumn (s \u2022 M) j u) = s ^ (Fintype.card n - 1) * det (updateColumn M j u) :=\n  by\n  rw [\u2190 det_transpose, \u2190 update_row_transpose, transpose_smul, det_update_row_smul']\n  simp [update_row_transpose, det_transpose]\n#align matrix.det_update_column_smul' Matrix.det_updateColumn_smul'\n\nsection DetEq\n\n/-! ### `det_eq` section\n\nLemmas showing the determinant is invariant under a variety of operations.\n-/\n\n\ntheorem det_eq_of_eq_mul_det_one {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1)\n    (hA : A = B \u2b1d C) : det A = det B :=\n  calc\n    det A = det (B \u2b1d C) := congr_arg _ hA\n    _ = det B * det C := (det_mul _ _)\n    _ = det B := by rw [hC, mul_one]\n    \n#align matrix.det_eq_of_eq_mul_det_one Matrix.det_eq_of_eq_mul_det_one\n\ntheorem det_eq_of_eq_det_one_mul {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1)\n    (hA : A = C \u2b1d B) : det A = det B :=\n  calc\n    det A = det (C \u2b1d B) := congr_arg _ hA\n    _ = det C * det B := (det_mul _ _)\n    _ = det B := by rw [hC, one_mul]\n    \n#align matrix.det_eq_of_eq_det_one_mul Matrix.det_eq_of_eq_det_one_mul\n\ntheorem det_updateRow_add_self (A : Matrix n n R) {i j : n} (hij : i \u2260 j) :\n    det (updateRow A i (A i + A j)) = det A := by\n  simp [det_update_row_add,\n    det_zero_of_row_eq hij (update_row_self.trans (update_row_ne hij.symm).symm)]\n#align matrix.det_update_row_add_self Matrix.det_updateRow_add_self\n\ntheorem det_updateColumn_add_self (A : Matrix n n R) {i j : n} (hij : i \u2260 j) :\n    det (updateColumn A i fun k => A k i + A k j) = det A :=\n  by\n  rw [\u2190 det_transpose, \u2190 update_row_transpose, \u2190 det_transpose A]\n  exact det_update_row_add_self A\u1d40 hij\n#align matrix.det_update_column_add_self Matrix.det_updateColumn_add_self\n\ntheorem det_updateRow_add_smul_self (A : Matrix n n R) {i j : n} (hij : i \u2260 j) (c : R) :\n    det (updateRow A i (A i + c \u2022 A j)) = det A := by\n  simp [det_update_row_add, det_update_row_smul,\n    det_zero_of_row_eq hij (update_row_self.trans (update_row_ne hij.symm).symm)]\n#align matrix.det_update_row_add_smul_self Matrix.det_updateRow_add_smul_self\n\ntheorem det_updateColumn_add_smul_self (A : Matrix n n R) {i j : n} (hij : i \u2260 j) (c : R) :\n    det (updateColumn A i fun k => A k i + c \u2022 A k j) = det A :=\n  by\n  rw [\u2190 det_transpose, \u2190 update_row_transpose, \u2190 det_transpose A]\n  exact det_update_row_add_smul_self A\u1d40 hij c\n#align matrix.det_update_column_add_smul_self Matrix.det_updateColumn_add_smul_self\n\ntheorem det_eq_of_forall_row_eq_smul_add_const_aux {A B : Matrix n n R} {s : Finset n} :\n    \u2200 (c : n \u2192 R) (hs : \u2200 i, i \u2209 s \u2192 c i = 0) (k : n) (hk : k \u2209 s)\n      (A_eq : \u2200 i j, A i j = B i j + c i * B k j), det A = det B :=\n  by\n  revert B\n  refine' s.induction_on _ _\n  \u00b7 intro A c hs k hk A_eq\n    have : \u2200 i, c i = 0 := by\n      intro i\n      specialize hs i\n      contrapose! hs\n      simp [hs]\n    congr\n    ext (i j)\n    rw [A_eq, this, MulZeroClass.zero_mul, add_zero]\n  \u00b7 intro i s hi ih B c hs k hk A_eq\n    have hAi : A i = B i + c i \u2022 B k := funext (A_eq i)\n    rw [@ih (update_row B i (A i)) (Function.update c i 0), hAi, det_update_row_add_smul_self]\n    \u00b7 exact mt (fun h => show k \u2208 insert i s from h \u25b8 Finset.mem_insert_self _ _) hk\n    \u00b7 intro i' hi'\n      rw [Function.update_apply]\n      split_ifs with hi'i\n      \u00b7 rfl\n      \u00b7 exact hs i' fun h => hi' ((finset.mem_insert.mp h).resolve_left hi'i)\n    \u00b7 exact fun h => hk (Finset.mem_insert_of_mem h)\n    \u00b7 intro i' j'\n      rw [update_row_apply, Function.update_apply]\n      split_ifs with hi'i\n      \u00b7 simp [hi'i]\n      rw [A_eq, update_row_ne fun h : k = i => hk <| h \u25b8 Finset.mem_insert_self k s]\n#align matrix.det_eq_of_forall_row_eq_smul_add_const_aux Matrix.det_eq_of_forall_row_eq_smul_add_const_aux\n\n/-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/\ntheorem det_eq_of_forall_row_eq_smul_add_const {A B : Matrix n n R} (c : n \u2192 R) (k : n)\n    (hk : c k = 0) (A_eq : \u2200 i j, A i j = B i j + c i * B k j) : det A = det B :=\n  det_eq_of_forall_row_eq_smul_add_const_aux c\n    (fun i =>\n      not_imp_comm.mp fun hi =>\n        Finset.mem_erase.mpr\n          \u27e8mt (fun h : i = k => show c i = 0 from h.symm \u25b8 hk) hi, Finset.mem_univ i\u27e9)\n    k (Finset.not_mem_erase k Finset.univ) A_eq\n#align matrix.det_eq_of_forall_row_eq_smul_add_const Matrix.det_eq_of_forall_row_eq_smul_add_const\n\ntheorem det_eq_of_forall_row_eq_smul_add_pred_aux {n : \u2115} (k : Fin (n + 1)) :\n    \u2200 (c : Fin n \u2192 R) (hc : \u2200 i : Fin n, k < i.succ \u2192 c i = 0)\n      {M N : Matrix (Fin n.succ) (Fin n.succ) R} (h0 : \u2200 j, M 0 j = N 0 j)\n      (hsucc : \u2200 (i : Fin n) (j), M i.succ j = N i.succ j + c i * M i.cast_succ j), det M = det N :=\n  by\n  refine' Fin.induction _ (fun k ih => _) k <;> intro c hc M N h0 hsucc\n  \u00b7 congr\n    ext (i j)\n    refine' Fin.cases (h0 j) (fun i => _) i\n    rw [hsucc, hc i (Fin.succ_pos _), MulZeroClass.zero_mul, add_zero]\n  set M' := update_row M k.succ (N k.succ) with hM'\n  have hM : M = update_row M' k.succ (M' k.succ + c k \u2022 M k.cast_succ) :=\n    by\n    ext (i j)\n    by_cases hi : i = k.succ\n    \u00b7 simp [hi, hM', hsucc, update_row_self]\n    rw [update_row_ne hi, hM', update_row_ne hi]\n  have k_ne_succ : k.cast_succ \u2260 k.succ := (Fin.castSucc_lt_succ k).Ne\n  have M_k : M k.cast_succ = M' k.cast_succ := (update_row_ne k_ne_succ).symm\n  rw [hM, M_k, det_update_row_add_smul_self M' k_ne_succ.symm, ih (Function.update c k 0)]\n  \u00b7 intro i hi\n    rw [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff] at hi\n    rw [Function.update_apply]\n    split_ifs with hik\n    \u00b7 rfl\n    exact hc _ (fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (Ne.symm hik)))\n  \u00b7 rwa [hM', update_row_ne (Fin.succ_ne_zero _).symm]\n  intro i j\n  rw [Function.update_apply]\n  split_ifs with hik\n  \u00b7 rw [MulZeroClass.zero_mul, add_zero, hM', hik, update_row_self]\n  rw [hM', update_row_ne ((Fin.succ_injective _).Ne hik), hsucc]\n  by_cases hik2 : k < i\n  \u00b7 simp [hc i (fin.succ_lt_succ_iff.mpr hik2)]\n  rw [update_row_ne]\n  apply ne_of_lt\n  rwa [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff, \u2190 not_lt]\n#align matrix.det_eq_of_forall_row_eq_smul_add_pred_aux Matrix.det_eq_of_forall_row_eq_smul_add_pred_aux\n\n/-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/\ntheorem det_eq_of_forall_row_eq_smul_add_pred {n : \u2115} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R}\n    (c : Fin n \u2192 R) (A_zero : \u2200 j, A 0 j = B 0 j)\n    (A_succ : \u2200 (i : Fin n) (j), A i.succ j = B i.succ j + c i * A i.cast_succ j) : det A = det B :=\n  det_eq_of_forall_row_eq_smul_add_pred_aux (Fin.last _) c\n    (fun i hi => absurd hi (not_lt_of_ge (Fin.le_last _))) A_zero A_succ\n#align matrix.det_eq_of_forall_row_eq_smul_add_pred Matrix.det_eq_of_forall_row_eq_smul_add_pred\n\n/-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/\ntheorem det_eq_of_forall_col_eq_smul_add_pred {n : \u2115} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R}\n    (c : Fin n \u2192 R) (A_zero : \u2200 i, A i 0 = B i 0)\n    (A_succ : \u2200 (i) (j : Fin n), A i j.succ = B i j.succ + c j * A i j.cast_succ) : det A = det B :=\n  by\n  rw [\u2190 det_transpose A, \u2190 det_transpose B]\n  exact det_eq_of_forall_row_eq_smul_add_pred c A_zero fun i j => A_succ j i\n#align matrix.det_eq_of_forall_col_eq_smul_add_pred Matrix.det_eq_of_forall_col_eq_smul_add_pred\n\nend DetEq\n\n@[simp]\ntheorem det_blockDiagonal {o : Type _} [Fintype o] [DecidableEq o] (M : o \u2192 Matrix n n R) :\n    (blockDiagonal M).det = \u220f k, (M k).det :=\n  by\n  -- Rewrite the determinants as a sum over permutations.\n  simp_rw [det_apply']\n  -- The right hand side is a product of sums, rewrite it as a sum of products.\n  rw [Finset.prod_sum]\n  simp_rw [Finset.mem_univ, Finset.prod_attach_univ, Finset.univ_pi_univ]\n  -- We claim that the only permutations contributing to the sum are those that\n  -- preserve their second component.\n  let preserving_snd : Finset (Equiv.Perm (n \u00d7 o)) :=\n    finset.univ.filter fun \u03c3 => \u2200 x, (\u03c3 x).snd = x.snd\n  have mem_preserving_snd :\n    \u2200 {\u03c3 : Equiv.Perm (n \u00d7 o)}, \u03c3 \u2208 preserving_snd \u2194 \u2200 x, (\u03c3 x).snd = x.snd := fun \u03c3 =>\n    finset.mem_filter.trans \u27e8fun h => h.2, fun h => \u27e8Finset.mem_univ _, h\u27e9\u27e9\n  rw [\u2190 Finset.sum_subset (Finset.subset_univ preserving_snd) _]\n  -- And that these are in bijection with `o \u2192 equiv.perm m`.\n  rw [(Finset.sum_bij\n        (fun (\u03c3 : \u2200 k : o, k \u2208 Finset.univ \u2192 Equiv.Perm n) _ =>\n          prod_congr_left fun k => \u03c3 k (Finset.mem_univ k))\n        _ _ _ _).symm]\n  \u00b7 intro \u03c3 _\n    rw [mem_preserving_snd]\n    rintro \u27e8k, x\u27e9\n    simp only [prod_congr_left_apply]\n  \u00b7 intro \u03c3 _\n    rw [Finset.prod_mul_distrib, \u2190 Finset.univ_product_univ, Finset.prod_product_right]\n    simp only [sign_prod_congr_left, Units.coe_prod, Int.cast_prod, block_diagonal_apply_eq,\n      prod_congr_left_apply]\n  \u00b7 intro \u03c3 \u03c3' _ _ eq\n    ext (x hx k)\n    simp only at eq\n    have :\n      \u2200 k x,\n        prod_congr_left (fun k => \u03c3 k (Finset.mem_univ _)) (k, x) =\n          prod_congr_left (fun k => \u03c3' k (Finset.mem_univ _)) (k, x) :=\n      fun k x => by rw [Eq]\n    simp only [prod_congr_left_apply, Prod.mk.inj_iff] at this\n    exact (this k x).1\n  \u00b7 intro \u03c3 h\u03c3\n    rw [mem_preserving_snd] at h\u03c3\n    have h\u03c3' : \u2200 x, (\u03c3\u207b\u00b9 x).snd = x.snd := by\n      intro x\n      conv_rhs => rw [\u2190 perm.apply_inv_self \u03c3 x, h\u03c3]\n    have mk_apply_eq : \u2200 k x, ((\u03c3 (x, k)).fst, k) = \u03c3 (x, k) :=\n      by\n      intro k x\n      ext\n      \u00b7 simp only\n      \u00b7 simp only [h\u03c3]\n    have mk_inv_apply_eq : \u2200 k x, ((\u03c3\u207b\u00b9 (x, k)).fst, k) = \u03c3\u207b\u00b9 (x, k) :=\n      by\n      intro k x\n      conv_lhs => rw [\u2190 perm.apply_inv_self \u03c3 (x, k)]\n      ext\n      \u00b7 simp only [apply_inv_self]\n      \u00b7 simp only [h\u03c3']\n    refine' \u27e8fun k _ => \u27e8fun x => (\u03c3 (x, k)).fst, fun x => (\u03c3\u207b\u00b9 (x, k)).fst, _, _\u27e9, _, _\u27e9\n    \u00b7 intro x\n      simp only [mk_apply_eq, inv_apply_self]\n    \u00b7 intro x\n      simp only [mk_inv_apply_eq, apply_inv_self]\n    \u00b7 apply Finset.mem_univ\n    \u00b7 ext \u27e8k, x\u27e9\n      \u00b7 simp only [[anonymous], prod_congr_left_apply]\n      \u00b7 simp only [prod_congr_left_apply, h\u03c3]\n  \u00b7 intro \u03c3 _ h\u03c3\n    rw [mem_preserving_snd] at h\u03c3\n    obtain \u27e8\u27e8k, x\u27e9, hkx\u27e9 := not_forall.mp h\u03c3\n    rw [Finset.prod_eq_zero (Finset.mem_univ (k, x)), MulZeroClass.mul_zero]\n    rw [\u2190 @Prod.mk.eta _ _ (\u03c3 (k, x)), block_diagonal_apply_ne]\n    exact hkx\n#align matrix.det_block_diagonal Matrix.det_blockDiagonal\n\n/-- The determinant of a 2\u00d72 block matrix with the lower-left block equal to zero is the product of\nthe determinants of the diagonal blocks. For the generalization to any number of blocks, see\n`matrix.det_of_upper_triangular`. -/\n@[simp]\ntheorem det_fromBlocks_zero\u2082\u2081 (A : Matrix m m R) (B : Matrix m n R) (D : Matrix n n R) :\n    (Matrix.fromBlocks A B 0 D).det = A.det * D.det := by\n  classical\n    simp_rw [det_apply']\n    convert(sum_subset (subset_univ ((sum_congr_hom m n).range : Set (perm (Sum m n))).toFinset)\n          _).symm\n    rw [sum_mul_sum]\n    simp_rw [univ_product_univ]\n    rw [(sum_bij (fun (\u03c3 : perm m \u00d7 perm n) _ => Equiv.sumCongr \u03c3.fst \u03c3.snd) _ _ _ _).symm]\n    \u00b7 intro \u03c3\u2081\u2082 h\n      simp only\n      erw [Set.mem_toFinset, MonoidHom.mem_range]\n      use \u03c3\u2081\u2082\n      simp only [sum_congr_hom_apply]\n    \u00b7 simp only [forall_prop_of_true, Prod.forall, mem_univ]\n      intro \u03c3\u2081 \u03c3\u2082\n      rw [Fintype.prod_sum_type]\n      simp_rw [Equiv.sumCongr_apply, Sum.map_inr, Sum.map_inl, from_blocks_apply\u2081\u2081,\n        from_blocks_apply\u2082\u2082]\n      rw [mul_mul_mul_comm]\n      congr\n      rw [sign_sum_congr, Units.val_mul, Int.cast_mul]\n    \u00b7 intro \u03c3\u2081 \u03c3\u2082 h\u2081 h\u2082\n      dsimp only\n      intro h\n      have h2 : \u2200 x, perm.sum_congr \u03c3\u2081.fst \u03c3\u2081.snd x = perm.sum_congr \u03c3\u2082.fst \u03c3\u2082.snd x :=\n        by\n        intro x\n        exact congr_fun (congr_arg to_fun h) x\n      simp only [Sum.map_inr, Sum.map_inl, perm.sum_congr_apply, Sum.forall] at h2\n      ext\n      \u00b7 exact h2.left x\n      \u00b7 exact h2.right x\n    \u00b7 intro \u03c3 h\u03c3\n      erw [Set.mem_toFinset, MonoidHom.mem_range] at h\u03c3\n      obtain \u27e8\u03c3\u2081\u2082, h\u03c3\u2081\u2082\u27e9 := h\u03c3\n      use \u03c3\u2081\u2082\n      rw [\u2190 h\u03c3\u2081\u2082]\n      simp\n    \u00b7 intro \u03c3 h\u03c3 h\u03c3n\n      have h1 : \u00ac\u2200 x, \u2203 y, Sum.inl y = \u03c3 (Sum.inl x) :=\n        by\n        by_contra\n        rw [Set.mem_toFinset] at h\u03c3n\n        apply absurd (mem_sum_congr_hom_range_of_perm_maps_to_inl _) h\u03c3n\n        rintro x \u27e8a, ha\u27e9\n        rw [\u2190 ha]\n        exact h a\n      obtain \u27e8a, ha\u27e9 := not_forall.mp h1\n      cases' hx : \u03c3 (Sum.inl a) with a2 b\n      \u00b7 have hn := (not_exists.mp ha) a2\n        exact absurd hx.symm hn\n      \u00b7 rw [Finset.prod_eq_zero (Finset.mem_univ (Sum.inl a)), MulZeroClass.mul_zero]\n        rw [hx, from_blocks_apply\u2082\u2081]\n        rfl\n#align matrix.det_from_blocks_zero\u2082\u2081 Matrix.det_fromBlocks_zero\u2082\u2081\n\n/-- The determinant of a 2\u00d72 block matrix with the upper-right block equal to zero is the product of\nthe determinants of the diagonal blocks. For the generalization to any number of blocks, see\n`matrix.det_of_lower_triangular`. -/\n@[simp]\ntheorem det_fromBlocks_zero\u2081\u2082 (A : Matrix m m R) (C : Matrix n m R) (D : Matrix n n R) :\n    (Matrix.fromBlocks A 0 C D).det = A.det * D.det := by\n  rw [\u2190 det_transpose, from_blocks_transpose, transpose_zero, det_from_blocks_zero\u2082\u2081, det_transpose,\n    det_transpose]\n#align matrix.det_from_blocks_zero\u2081\u2082 Matrix.det_fromBlocks_zero\u2081\u2082\n\n/-- Laplacian expansion of the determinant of an `n+1 \u00d7 n+1` matrix along column 0. -/\ntheorem det_succ_column_zero {n : \u2115} (A : Matrix (Fin n.succ) (Fin n.succ) R) :\n    det A = \u2211 i : Fin n.succ, (-1) ^ (i : \u2115) * A i 0 * det (A.submatrix i.succAbove Fin.succ) :=\n  by\n  rw [Matrix.det_apply, Finset.univ_perm_fin_succ, \u2190 Finset.univ_product_univ]\n  simp only [Finset.sum_map, Equiv.toEmbedding_apply, Finset.sum_product, Matrix.submatrix]\n  refine' Finset.sum_congr rfl fun i _ => Fin.cases _ (fun i => _) i\n  \u00b7\n    simp only [Fin.prod_univ_succ, Matrix.det_apply, Finset.mul_sum,\n      Equiv.Perm.decomposeFin_symm_apply_zero, Fin.val_zero, one_mul,\n      Equiv.Perm.decomposeFin.symm_sign, Equiv.swap_self, if_true, id.def, eq_self_iff_true,\n      Equiv.Perm.decomposeFin_symm_apply_succ, Fin.succAbove_zero, Equiv.coe_refl, pow_zero,\n      mul_smul_comm, of_apply]\n  -- `univ_perm_fin_succ` gives a different embedding of `perm (fin n)` into\n  -- `perm (fin n.succ)` than the determinant of the submatrix we want,\n  -- permute `A` so that we get the correct one.\n  have : (-1 : R) ^ (i : \u2115) = i.cycle_range.sign := by simp [Fin.sign_cycleRange]\n  rw [Fin.val_succ, pow_succ, this, mul_assoc, mul_assoc, mul_left_comm \u2191(Equiv.Perm.sign _), \u2190\n    det_permute, Matrix.det_apply, Finset.mul_sum, Finset.mul_sum]\n  -- now we just need to move the corresponding parts to the same place\n  refine' Finset.sum_congr rfl fun \u03c3 _ => _\n  rw [Equiv.Perm.decomposeFin.symm_sign, if_neg (Fin.succ_ne_zero i)]\n  calc\n    ((-1 * \u03c3.sign : \u2124) \u2022 \u220f i', A (equiv.perm.decompose_fin.symm (Fin.succ i, \u03c3) i') i') =\n        (-1 * \u03c3.sign : \u2124) \u2022\n          (A (Fin.succ i) 0 * \u220f i', A ((Fin.succ i).succAbove (Fin.cycleRange i (\u03c3 i'))) i'.succ) :=\n      by\n      simp only [Fin.prod_univ_succ, Fin.succAbove_cycleRange,\n        Equiv.Perm.decomposeFin_symm_apply_zero, Equiv.Perm.decomposeFin_symm_apply_succ]\n    _ =\n        -1 *\n          (A (Fin.succ i) 0 *\n            (\u03c3.sign : \u2124) \u2022 \u220f i', A ((Fin.succ i).succAbove (Fin.cycleRange i (\u03c3 i'))) i'.succ) :=\n      by\n      simp only [mul_assoc, mul_comm, _root_.neg_mul, one_mul, zsmul_eq_mul, neg_inj, neg_smul,\n        Fin.succAbove_cycleRange]\n    \n#align matrix.det_succ_column_zero Matrix.det_succ_column_zero\n\n/-- Laplacian expansion of the determinant of an `n+1 \u00d7 n+1` matrix along row 0. -/\ntheorem det_succ_row_zero {n : \u2115} (A : Matrix (Fin n.succ) (Fin n.succ) R) :\n    det A = \u2211 j : Fin n.succ, (-1) ^ (j : \u2115) * A 0 j * det (A.submatrix Fin.succ j.succAbove) :=\n  by\n  rw [\u2190 det_transpose A, det_succ_column_zero]\n  refine' Finset.sum_congr rfl fun i _ => _\n  rw [\u2190 det_transpose]\n  simp only [transpose_apply, transpose_submatrix, transpose_transpose]\n#align matrix.det_succ_row_zero Matrix.det_succ_row_zero\n\n/-- Laplacian expansion of the determinant of an `n+1 \u00d7 n+1` matrix along row `i`. -/\ntheorem det_succ_row {n : \u2115} (A : Matrix (Fin n.succ) (Fin n.succ) R) (i : Fin n.succ) :\n    det A =\n      \u2211 j : Fin n.succ, (-1) ^ (i + j : \u2115) * A i j * det (A.submatrix i.succAbove j.succAbove) :=\n  by\n  simp_rw [pow_add, mul_assoc, \u2190 mul_sum]\n  have : det A = (-1 : R) ^ (i : \u2115) * i.cycle_range\u207b\u00b9.sign * det A := by\n    calc\n      det A = \u2191((-1 : \u2124\u02e3) ^ (i : \u2115) * (-1 : \u2124\u02e3) ^ (i : \u2115) : \u2124\u02e3) * det A := by simp\n      _ = (-1 : R) ^ (i : \u2115) * i.cycle_range\u207b\u00b9.sign * det A := by simp [-Int.units_mul_self]\n      \n  rw [this, mul_assoc]\n  congr\n  rw [\u2190 det_permute, det_succ_row_zero]\n  refine' Finset.sum_congr rfl fun j _ => _\n  rw [mul_assoc, Matrix.submatrix, Matrix.submatrix]\n  congr\n  \u00b7 rw [Equiv.Perm.inv_def, Fin.cycleRange_symm_zero]\n  \u00b7 ext (i' j')\n    rw [Equiv.Perm.inv_def, Fin.cycleRange_symm_succ]\n#align matrix.det_succ_row Matrix.det_succ_row\n\n/-- Laplacian expansion of the determinant of an `n+1 \u00d7 n+1` matrix along column `j`. -/\ntheorem det_succ_column {n : \u2115} (A : Matrix (Fin n.succ) (Fin n.succ) R) (j : Fin n.succ) :\n    det A =\n      \u2211 i : Fin n.succ, (-1) ^ (i + j : \u2115) * A i j * det (A.submatrix i.succAbove j.succAbove) :=\n  by\n  rw [\u2190 det_transpose, det_succ_row _ j]\n  refine' Finset.sum_congr rfl fun i _ => _\n  rw [add_comm, \u2190 det_transpose, transpose_apply, transpose_submatrix, transpose_transpose]\n#align matrix.det_succ_column Matrix.det_succ_column\n\n/-- Determinant of 0x0 matrix -/\n@[simp]\ntheorem det_fin_zero {A : Matrix (Fin 0) (Fin 0) R} : det A = 1 :=\n  det_isEmpty\n#align matrix.det_fin_zero Matrix.det_fin_zero\n\n/-- Determinant of 1x1 matrix -/\ntheorem det_fin_one (A : Matrix (Fin 1) (Fin 1) R) : det A = A 0 0 :=\n  det_unique A\n#align matrix.det_fin_one Matrix.det_fin_one\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:207:4: warning: unsupported notation `\u00abexpr!![ \u00bb -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:387:14: unsupported user notation matrix.notation -/\ntheorem det_fin_one_of (a : R) :\n    det\n        (\u00abexpr!![ \u00bb\n          \"./././Mathport/Syntax/Translate/Expr.lean:387:14: unsupported user notation matrix.notation\") =\n      a :=\n  det_fin_one _\n#align matrix.det_fin_one_of Matrix.det_fin_one_of\n\n/-- Determinant of 2x2 matrix -/\ntheorem det_fin_two (A : Matrix (Fin 2) (Fin 2) R) : det A = A 0 0 * A 1 1 - A 0 1 * A 1 0 :=\n  by\n  simp [Matrix.det_succ_row_zero, Fin.sum_univ_succ]\n  ring\n#align matrix.det_fin_two Matrix.det_fin_two\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:207:4: warning: unsupported notation `\u00abexpr!![ \u00bb -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:387:14: unsupported user notation matrix.notation -/\n@[simp]\ntheorem det_fin_two_of (a b c d : R) :\n    Matrix.det\n        (\u00abexpr!![ \u00bb\n          \"./././Mathport/Syntax/Translate/Expr.lean:387:14: unsupported user notation matrix.notation\") =\n      a * d - b * c :=\n  det_fin_two _\n#align matrix.det_fin_two_of Matrix.det_fin_two_of\n\n/-- Determinant of 3x3 matrix -/\ntheorem det_fin_three (A : Matrix (Fin 3) (Fin 3) R) :\n    det A =\n      A 0 0 * A 1 1 * A 2 2 - A 0 0 * A 1 2 * A 2 1 - A 0 1 * A 1 0 * A 2 2 +\n            A 0 1 * A 1 2 * A 2 0 +\n          A 0 2 * A 1 0 * A 2 1 -\n        A 0 2 * A 1 1 * A 2 0 :=\n  by\n  simp [Matrix.det_succ_row_zero, Fin.sum_univ_succ]\n  ring\n#align matrix.det_fin_three Matrix.det_fin_three\n\nend Matrix\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/Matrix/Determinant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.70456180012789}}
{"text": "\ndef f : Nat \u2192 Nat \u2192 Nat\n| 0,   b => b+1\n| a+1, b => f a (f a b)\n\ntheorem ex1 (b)   : f 0 b = b+1 := rfl\ntheorem ex2 (b)   : f 1 b = (b+1)+1 := rfl\ntheorem ex3 (b)   : f 2 b = b+1+1+1+1 := rfl\ntheorem ex4 (a b) : f (a+1) b = f a (f a b) := rfl\n\n#eval f 2 5\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/run/nestedrec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.7045617939533687}}
{"text": "structure {u v} Category :=\n  ( Obj : Type u )\n  ( Hom : Obj \u2192 Obj \u2192 Type v )\n  ( identity : \u03a0 X : Obj, Hom X X )\n  ( compose  : \u03a0 { X Y Z : Obj }, Hom X Y \u2192 Hom Y Z \u2192 Hom X Z )\n  ( left_identity  : \u2200 { X Y : Obj } (f : Hom X Y), compose (identity X) f = f )\n    \nattribute [simp] Category.left_identity\n\nstructure {u1 v1 u2 v2} Functor (C : Category.{ u1 v1 }) (D : Category.{ u2 v2 }) :=\n  (onObjects   : C.Obj \u2192 D.Obj)\n  (onMorphisms : \u03a0 { X Y : C.Obj },\n                C.Hom X Y \u2192 D.Hom (onObjects X) (onObjects Y))\n\nstructure {u1 v1 u2 v2} Full     { C : Category.{u1 v1} } { D : Category.{u2 v2} } ( F : Functor C D ) :=\n  ( preimage : \u2200 { X Y : C.Obj } ( f : D.Hom (F.onObjects X) (F.onObjects Y) ), C.Hom X Y )\n  ( witness  : \u2200 { X Y : C.Obj } ( f : D.Hom (F.onObjects X) (F.onObjects Y) ), F.onMorphisms (preimage f) = f )\n\nstructure Idempotent ( C : Category ) :=\n   ( object : C.Obj )\n   ( idempotent : C.Hom object object )\n\ndefinition IdempotentCompletion ( C: Category ) : Category :=\n{\n  Obj            := Idempotent C,\n  Hom            := \u03bb X Y, { f : C.Hom X.object Y.object // C.compose X.idempotent f = f \u2227 C.compose f Y.idempotent = f },\n  identity       := \u03bb X, \u27e8 X.idempotent, sorry \u27e9,\n  compose        := \u03bb X Y Z f g, \u27e8 C.compose f.val g.val, sorry \u27e9,\n  left_identity  := sorry\n}\n\ndefinition functor_to_IdempotentCompletion ( C : Category ) : Functor C (IdempotentCompletion C) := {\n  onObjects     := \u03bb X, \u27e8 X, C.identity X \u27e9,\n  onMorphisms   := \u03bb _ _ f, \u27e8 f, sorry \u27e9\n}\n\nopen tactic\n\n-- fsplit is just split, but we use fapply on the constructors, rather than apply.\n-- This is essential so we actually get given all the goals, rather than some of them turning into metavariables.\nmeta def fsplit : tactic unit :=\ndo [c] \u2190 target >>= get_constructors_for | tactic.fail \"fsplit tactic failed, target is not an inductive datatype with only one constructor\",\n   mk_const c >>= fapply >> skip\n\nlemma embedding_in_IdempotentCompletition ( C: Category ) : Full (functor_to_IdempotentCompletion C) :=\nbegin\nfsplit, \nintros, \ndsimp at * {md := semireducible}, \ninduction f,\nsimp at *, \n -- now, perversely, we run some tactics on the second goal, before closing the first goal\n any_goals {intros},\n any_goals {fapply subtype.eq},\n any_goals {dsimp},\n any_goals {dsimp at * {md := semireducible}},\n any_goals {induction f},\n any_goals {dsimp},\n-- finally, we actually get to business.\nexact f_val,\nrefl,\nend\n", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/20171217-refl.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.7044871837206127}}
{"text": "/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen, Kexing Ying, Eric Wieser\n-/\nimport linear_algebra.quadratic_form.basic\nimport analysis.special_functions.pow\nimport data.real.sign\n\n/-!\n# Real quadratic forms\n\nSylvester's law of inertia `equivalent_one_neg_one_weighted_sum_squared`:\nA real quadratic form is equivalent to a weighted\nsum of squares with the weights being \u00b11 or 0.\n\nWhen the real quadratic form is nondegerate we can take the weights to be \u00b11,\nas in `equivalent_one_zero_neg_one_weighted_sum_squared`.\n\n-/\n\nnamespace quadratic_form\n\nopen_locale big_operators\nopen real finset\n\nvariables {\u03b9 : Type*} [fintype \u03b9]\n\n/-- The isometry between a weighted sum of squares with weights `u` on the\n(non-zero) real numbers and the weighted sum of squares with weights `sign \u2218 u`. -/\nnoncomputable def isometry_sign_weighted_sum_squares\n  [decidable_eq \u03b9] (w : \u03b9 \u2192 \u211d) :\n  isometry (weighted_sum_squares \u211d w) (weighted_sum_squares \u211d (sign \u2218 w)) :=\nbegin\n  let u := \u03bb i, if h : w i = 0 then (1 : \u211d\u02e3) else units.mk0 (w i) h,\n  have hu' : \u2200 i : \u03b9, (sign (u i) * u i) ^ - (1 / 2 : \u211d) \u2260 0,\n  { intro i, refine (ne_of_lt (real.rpow_pos_of_pos\n      (sign_mul_pos_of_ne_zero _ $ units.ne_zero _) _)).symm},\n  convert ((weighted_sum_squares \u211d w).isometry_basis_repr\n    ((pi.basis_fun \u211d \u03b9).units_smul (\u03bb i, (is_unit_iff_ne_zero.2 $ hu' i).unit))),\n  ext1 v,\n  rw [basis_repr_apply, weighted_sum_squares_apply, weighted_sum_squares_apply],\n  refine sum_congr rfl (\u03bb j hj, _),\n  have hsum : (\u2211 (i : \u03b9), v i \u2022 ((is_unit_iff_ne_zero.2 $ hu' i).unit : \u211d) \u2022\n    (pi.basis_fun \u211d \u03b9) i) j = v j \u2022 (sign (u j) * u j) ^ - (1 / 2 : \u211d),\n  { rw [finset.sum_apply, sum_eq_single j, pi.basis_fun_apply, is_unit.unit_spec,\n        linear_map.std_basis_apply, pi.smul_apply, pi.smul_apply, function.update_same,\n        smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_one],\n    intros i _ hij,\n    rw [pi.basis_fun_apply, linear_map.std_basis_apply, pi.smul_apply, pi.smul_apply,\n        function.update_noteq hij.symm, pi.zero_apply, smul_eq_mul, smul_eq_mul,\n        mul_zero, mul_zero],\n    intro hj', exact false.elim (hj' hj) },\n  simp_rw basis.units_smul_apply,\n  erw [hsum],\n  simp only [u, function.comp, smul_eq_mul],\n  split_ifs,\n  { simp only [h, zero_smul, zero_mul, sign_zero] },\n  have hwu : w j = u j,\n  { simp only [u, dif_neg h, units.coe_mk0] },\n  simp only [hwu, units.coe_mk0],\n  suffices : (u j : \u211d).sign * v j * v j = (sign (u j) * u j) ^ - (1 / 2 : \u211d) *\n    (sign (u j) * u j) ^ - (1 / 2 : \u211d) * u j * v j * v j,\n  { erw [\u2190 mul_assoc, this], ring },\n  rw [\u2190 real.rpow_add (sign_mul_pos_of_ne_zero _ $ units.ne_zero _),\n      show - (1 / 2 : \u211d) + - (1 / 2) = -1, by ring, real.rpow_neg_one, mul_inv\u2080,\n      inv_sign, mul_assoc (sign (u j)) (u j)\u207b\u00b9,\n      inv_mul_cancel (units.ne_zero _), mul_one],\n  apply_instance\nend\n\n/-- **Sylvester's law of inertia**: A nondegenerate real quadratic form is equivalent to a weighted\nsum of squares with the weights being \u00b11. -/\ntheorem equivalent_one_neg_one_weighted_sum_squared\n  {M : Type*} [add_comm_group M] [module \u211d M] [finite_dimensional \u211d M]\n  (Q : quadratic_form \u211d M) (hQ : (associated Q).nondegenerate) :\n  \u2203 w : fin (finite_dimensional.finrank \u211d M) \u2192 \u211d,\n  (\u2200 i, w i = -1 \u2228 w i = 1) \u2227 equivalent Q (weighted_sum_squares \u211d w) :=\nlet \u27e8w, \u27e8hw\u2081\u27e9\u27e9 := Q.equivalent_weighted_sum_squares_units_of_nondegenerate' hQ in\n  \u27e8sign \u2218 coe \u2218 w,\n   \u03bb i, sign_apply_eq_of_ne_zero (w i) (w i).ne_zero,\n   \u27e8hw\u2081.trans (isometry_sign_weighted_sum_squares (coe \u2218 w))\u27e9\u27e9\n\n/-- **Sylvester's law of inertia**: A real quadratic form is equivalent to a weighted\nsum of squares with the weights being \u00b11 or 0. -/\ntheorem equivalent_one_zero_neg_one_weighted_sum_squared\n  {M : Type*} [add_comm_group M] [module \u211d M] [finite_dimensional \u211d M]\n  (Q : quadratic_form \u211d M) :\n  \u2203 w : fin (finite_dimensional.finrank \u211d M) \u2192 \u211d,\n  (\u2200 i, w i = -1 \u2228 w i = 0 \u2228 w i = 1) \u2227 equivalent Q (weighted_sum_squares \u211d w) :=\nlet \u27e8w, \u27e8hw\u2081\u27e9\u27e9 := Q.equivalent_weighted_sum_squares in\n  \u27e8sign \u2218 coe \u2218 w,\n   \u03bb i, sign_apply_eq (w i),\n   \u27e8hw\u2081.trans (isometry_sign_weighted_sum_squares w)\u27e9\u27e9\n\nend quadratic_form\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/linear_algebra/quadratic_form/real.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7043716571013909}}
{"text": "theorem e01 : P \u2192 Q \u2192 P := \nbegin\n    assume p q,                      \n    /- \n       p : P\n       q : Q\n       |- P\n    -/\n    exact p\n    /-\n        no goals\n    -/\nend\n\ntheorem e02 : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 P \u2192 R :=\nbegin\n    assume pqr pq p,\n\n    /-\n        pqr : P -> Q -> R\n        pq  : P -> Q\n        p   : P\n        |-  R\n    -/\n\n    apply pqr,\n\n    /-\n        (Case 1)\n        pqr : P -> Q -> R\n        pq  : P -> Q\n        p   : P\n        |-  P \n\n        (Case 2)\n        pqr : P -> Q -> R\n        pq  : P -> Q\n        p   : P\n        |-  Q\n    -/\n\n    exact p,\n\n    /-\n        gets rid of Case 1\n    -/\n\n    apply pq,\n\n    /-\n        pqr : P -> Q -> R\n        pq  : P -> Q\n        p   : P\n        |-  P\n    -/\n\n    exact p,\n\n    /-\n        no goals\n    -/\nend    \n \n\ntheorem e03 : (P \u2192 Q) \u2192 P \u2227 R \u2192 Q \u2227 R :=\nbegin\n\n    assume pq pnr,\n    \n    /-\n        pq : P -> Q\n        pnr : P \u2227 R\n        |-  Q \u2227 R\n    -/ \n\n    cases pnr with p r,\n    /-\n        pq : P -> Q\n        p : P\n        r : R\n        |- Q \u2227 R\n    -/ \n    constructor,\n    /-\n        (Case 1)\n        pq : P -> Q\n        p : P\n        r : R\n        |- Q\n\n        (Case 2)\n        pq : P -> Q\n        p : P\n        r : R\n        |- R\n    -/\n    apply pq,\n    /-\n        (Case 1)\n        pq : P -> Q\n        p : P\n        r : R\n        |- P\n\n        (Case 2)\n        pq : P -> Q\n        p : P\n        r : R\n        |- R\n    -/\n    exact p,\n    /-\n        gets rid of Case 1\n    -/\n    exact r,\n    /-\n        no goals (gets rid of Case 2)\n    -/\nend\n\n\n\ntheorem e04 : (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R :=\nbegin\n    assume pq por,\n    /-\n        pq : P -> Q\n        por  : P \u2228 R\n        |- Q \u2228 R\n    -/  \n    cases por with p r,\n    /-\n        (Case 1)\n        pq : P -> Q\n        p : P\n        |- Q \u2228 R\n\n        (Case 2)\n        pq : P -> Q\n        r : R\n        |- Q \u2228 R\n    -/ \n    left,\n    /-\n        (Case 1)\n        pq : P -> Q\n        p : P\n        |- Q\n    \n        (Case 2)\n        pq : P -> Q\n        r : R\n        |- Q \u2228 R\n    -/ \n    apply pq,\n    /-\n        (Case 1)\n        pq : P -> Q\n        p : P\n        |- P\n    \n        (Case 2)\n        pq : P -> Q\n        r : R\n        |- Q \u2228 R\n    -/ \n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    right,\n    /-\n        (Case 2)\n        pq : P -> Q\n        r : R\n        |- R\n    -/\n    exact r,\n    /-\n        No goals (Gets rid of Case 2)\n    -/\nend\n\n\n\ntheorem e05 : P \u2228 Q \u2192 R \u2194 (P \u2192 R) \u2227 (Q \u2192 R) :=\nbegin\n    constructor,\n    /-\n        (Case 1)\n        P \u2228 Q \u2192 R \u2192 (P \u2192 R) \u2227 (Q \u2192 R) \n        \n        (Case 2)\n        (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    assume pqr,\n    /-\n        (Case 1)\n        pqr : P \u2228 Q \u2192 R \n        := (P \u2192 R) \u2227 (Q \u2192 R) \n        \n        (Case 2)\n        (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    constructor,\n     /-\n        (Case 1)\n        pqr : P \u2228 Q \u2192 R \n        := (P \u2192 R)\n        \n        (Case 2)\n        pqr : P \u2228 Q \u2192 R \n        := (Q \u2192 R)\n\n        (Case 3)\n        (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    assume p,\n     /-\n        (Case 1)\n        pqr : P \u2228 Q \u2192 R \n        p : P\n        := R\n        \n        (Case 2)\n        pqr : P \u2228 Q \u2192 R \n        := (Q \u2192 R)\n\n        (Case 3)\n        (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    apply pqr,\n    /-\n        (Case 1)\n        pqr : P \u2228 Q \u2192 R \n        p : P\n        :=  P \u2228 Q\n        \n        (Case 2)\n        pqr : P \u2228 Q \u2192 R \n        := (Q \u2192 R)\n\n        (Case 3)\n        (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    left,\n    /-\n        (Case 1)\n        pqr : P \u2228 Q \u2192 R \n        p : P\n        :=  P\n        \n        (Case 2)\n        pqr : P \u2228 Q \u2192 R \n        := (Q \u2192 R)\n\n        (Case 3)\n        (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    assume q,\n    /-\n        (Case 2)\n        pqr : P \u2228 Q \u2192 R\n        q : Q \n        := R\n\n        (Case 3)\n        (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    apply pqr,\n    /-\n       (Case 2)\n       pqr : P \u2228 Q \u2192 R\n       q : Q \n       :=  P \u2228 Q \n\n       (Case 3)\n       (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    right,\n     /-\n       (Case 2)\n       pqr : P \u2228 Q \u2192 R\n       q : Q \n       :=  Q \n\n       (Case 3)\n       (P \u2192 R) \u2227 (Q \u2192 R) \u2192 P \u2228 Q \u2192 R\n    -/\n    exact q,\n    /-\n        Gets rid of Case 2\n    -/\n    assume prqr pq,\n    /-\n        (Case 3)\n        prqr : (P \u2192 R) \u2227 (Q \u2192 R) \n        pq :  P \u2228 Q\n        := R\n    -/\n    cases prqr with pr qr,\n    /-\n        (Case 3)\n        pr : P \u2192 R\n        qr : Q \u2192 R\n        pq : P \u2228 Q\n        := R\n    -/\n    cases pq with p q,\n    /-\n        (Case 3)\n        pr : P \u2192 R\n        qr : Q \u2192 R\n        p : P\n        := R\n\n        (Case 4)\n        pr : P \u2192 R\n        qr : Q \u2192 R\n        q : Q\n        := R\n    -/\n    apply pr,\n    /-\n        (Case 3)\n        pr : P \u2192 R\n        qr : Q \u2192 R\n        p : P\n        := P\n\n        (Case 4)\n        pr : P \u2192 R\n        qr : Q \u2192 R\n        q : Q\n        := R\n    -/\n    exact p,\n    /-\n        Gets rid of Case 3\n    -/\n    apply qr,\n    /-\n        (Case 4)\n        pr : P \u2192 R\n        qr : Q \u2192 R\n        q : Q\n        := Q\n    -/\n    exact q,\n    /-\n        No goals (Gets rid of Case 4)\n    -/\nend\n\ntheorem e06 : P \u2192 \u00ac \u00ac P :=\nbegin\n    assume p np,\n    /-\n        p : P\n        np : \u00ac P\n        |- false\n    -/\n    apply np,\n    /-\n        p : P\n        np : \u00ac P\n        |- P\n    -/\n    exact p,\n    /-\n        No goals \n    -/ \nend\n\ntheorem e07 : P \u2227 true \u2194 P :=\nbegin\n    constructor,\n    /-\n        (Case 1)\n        P \u2227 true \u2192 P\n\n        (Case 2)\n        P \u2192 P \u2227 true\n    -/\n    assume pt,\n    /-\n        (Case 1)\n        pt : P \u2227 true\n        := P\n\n        (Case 2)\n        P \u2192 P \u2227 true\n    -/\n    cases pt with p t,\n     /-\n        (Case 1)\n        p : P\n        t : true\n         := P\n\n        (Case 2)\n        P \u2192 P \u2227 true\n    -/\n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    assume p,\n    /-\n        (Case 2)\n        p : P\n        \u22a2 P \u2227 true\n    -/\n    constructor,\n    /-\n        (Case 2)\n        p : P\n        \u22a2  P\n\n        (Case 3)\n        p : P\n        \u22a2 true\n    -/\n    exact p,\n    -/\n        Gets rid of Case 2\n    -/\n    constructor,\n    -/\n        No goals (Gets rid of Case 3)\n    -/\nend\n\ntheorem e08 : P \u2228 false \u2194 P :=\nbegin\n    constructor,\n    /-\n        (Case 1)\n        P \u2228 false \u2192 P\n    \n        (Case 2)\n        P \u2192 P \u2228 false\n    -/\n    assume pf,\n    /-\n        (Case 1)\n        pf : P \u2228 false \n        \u22a2 P\n    \n        (Case 2)\n        P \u2192 P \u2228 false\n    -/\n    cases pf with p f,\n    /-\n        (Case 1)\n        p: P \n        \u22a2 P\n    \n        (Case 2)\n        f : false\n        \u22a2 P\n        \n        (Case 3)\n        P \u2192 P \u2228 false\n    -/\n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    cases f,\n    /-\n        Gets rid of Case 2\n    -/\n    assume p,\n    /-\n        (Case 3)\n        p: P \n        \u22a2 P \u2228 false\n    -/\n    left,\n    /-\n        (Case 3)\n        p: P \n        \u22a2\n    -/\n    exact p,\n    /-\n        No goals (Gets rid of Case 3)\n    -/\nend\n\ntheorem e09 : P \u2227 false \u2194 false :=\nbegin\n    constructor,\n    /-\n        (Case 1)\n        P \u2227 false \u2192 false\n\n        (Case 2)\n        false \u2192 P \u2227 false\n    -/\n    assume pf,\n    /-\n        (Case 1)\n        pf: P \u2227 false \n        \u22a2 false\n\n        (Case 2)\n        false \u2192 P \u2227 false\n    -/\n    cases pf with p f,\n    /-\n        (Case 1)\n        p : P \n        f : false \n        \u22a2 false\n\n        (Case 2)\n        false \u2192 P \u2227 false\n    -/\n    exact f,\n    /-\n        Gets rid of Case 1\n    -/\n    assume f,\n    /-\n       (Case 2)\n       f: false \n       \u22a2 P \u2227 false\n    -/\n    constructor,\n    /-\n       (Case 2)\n       f: false \n       \u22a2 P\n\n       (Case 3)\n       f: false\n       \u22a2 false    \n    -/\n    cases f,\n    -/\n        Gets rid of Case 2\n    -/\n    exact f,\n    -/\n        No goals (Gets rid of Case 3)\n    -/\nend\n\ntheorem e10 : P \u2228 true \u2194 true :=\nbegin\n    constructor,\n    /-\n        (Case 1)\n        P \u2228 true \u2192 true\n\n        (Case 2)\n        true \u2192 P \u2228 true\n    -/\n    assume pt,\n    /-\n        (Case 1)\n        pt: P \u2228 true \n        \u22a2 true\n\n        (Case 2)\n        true \u2192 P \u2228 true\n    -/\n    cases pt with p t  \n     /-\n        (Case 1)\n        p: P \n        \u22a2 true\n    \n        (Case 2)\n        t : true\n        \u22a2 true\n \n        (Case 3)\n        true \u2192 P \u2228 true\n    -/\n    constructor,\n    /-\n        Gets rid of Case 1\n    -/\n    exact t,\n    /-\n        Gets rid of Case 2\n    -/\n    assume t,\n    /-\n        (Case 3)\n        t : true \n        \u22a2 P \u2228 true\n    -/\n    right,\n    /-\n        (Case 3)\n        t : true\n        \u22a2 true\n    -/ \n    exact t,\n    /-\n        No goals (Gets rid of Case 3)\n    -/\nend\n\n/-\nPart 2 (10 points)\n(this part relies in material only covered in the lectures \nfrom 14/10/22)\n\nWe play the game of logic poker :-)\n\n    You have to classify the propositions into\n    a) provable intuitionistically (i.e. in plain lean)\n    b) provable classically (using em : P \u2228 \u00ac P or raa : \u00ac\u00ac P \u2192 P).\n    c) not provable classically.\n    and then you have to prove the propositions in a) and b) accordingly.\n\n    Here is how you score:\n    We start with 10 points :-)\n    For any proposition which you didn't classify correctly (or not at all)\n    you loose 1 point. :-(\n    For any proposition which is provable but you didn't prove you loose\n    1 point. :-(\n    We stop subtracting points at 0. :-)\n\n    Write the classification as a comment using -- after the proposition.\n\n    You are only allowed to use the tactics introduced in the lecture\n    (i.e. assume, exact, apply, constructor, cases, left, right, have, trivial)\n\n    Please only use the tactics in the way indicated in the script,\n    otherwise you may lose upto 2 style points. \n\n    For propositions classified into c) just keep \"sorry,\" as the proof.\n-/\n\nopen classical\n\ntheorem raa : \u00ac \u00ac P \u2192 P := \nbegin\n  assume nnp,\n  cases (em P) with p np,\n    exact p,\n    have f : false,\n      apply nnp,\n      exact np,\n    cases f,\nend\n\ntheorem p01 : (P \u2192 Q) \u2192 (R \u2192 P) \u2192 (R \u2192 Q) := \nbegin\n    assume pq rp r,\n    /-\n        pq : P \u2192 Q\n        rp : R \u2192 P\n        r : R\n        \u22a2 Q \n    -/\n    apply pq,\n    /-\n        pq : P \u2192 Q\n        rp : R \u2192 P\n        r : R\n        \u22a2 P\n    -/ \n    apply rp,\n     /-\n        pq : P \u2192 Q\n        rp : R \u2192 P\n        r : R\n        \u22a2 R\n    -/ \n    exact r,\n    /-\n        No goals\n    -/\nend\n\ntheorem p02 : (P \u2192 Q) \u2192 (P \u2192 R) \u2192 (Q \u2192 R) :=\nbegin\n  assume pq pr q,\n  sorry,\nend\n\ntheorem p03 : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n    assume pq qr p,\n    /-\n        pq : P \u2192 Q\n        qr : Q \u2192 R \n        p : P\n        \u22a2 R\n    -/\n    apply qr,\n    /-\n        pq : P \u2192 Q\n        qr : Q \u2192 R \n        p : P\n        \u22a2 Q\n    -/\n    apply pq,\n    /-\n        pq : P \u2192 Q\n        qr : Q \u2192 R \n        p : P\n        \u22a2 P\n    -/\n    exact p,\n    /-\n        No goals\n    -/\nend\n\ntheorem e04 : P \u2192 (P \u2192 Q) \u2192 P \u2227 Q :=\nbegin\n    assume p pq,\n    /-\n        p : P\n        pq : P \u2192 Q\n        \u22a2  P \u2227 Q\n    -/\n    constructor,\n    /-\n        (Case 1)\n        p : P\n        pq : P \u2192 Q\n        \u22a2  P\n\n        (Case 2)\n        p : P\n        pq : P \u2192 Q\n        \u22a2  Q\n    -/\n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    apply pq,\n    /-\n        (Case 2)\n        p : P\n        pq : P \u2192 Q\n        \u22a2  P\n    -/\n    exact p,\n    /-\n        No goals (Gets rid of Case 2)\n    -/\nend\n\ntheorem p05 : P \u2228 Q \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n    assume poq pq, \n    /-\n        poq : P \u2228 Q\n        pq : P \u2192 Q\n        \u22a2 Q\n    -/\n    cases poq with p q,\n    /-\n        (Case 1)\n        p : P\n        pq : P \u2192 Q\n        \u22a2 Q\n\n        (Case 2)\n        q : Q\n        pq : P \u2192 Q\n        \u22a2 Q\n    -/\n    apply pq,\n    /-\n        (Case 1)\n        p : P\n        pq : P \u2192 Q\n        \u22a2 P\n\n         (Case 2)\n        q : Q\n        pq : P \u2192 Q\n        \u22a2 Q\n    -/\n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    exact q,\n    /-\n        No goals (Gets rid of Case 2)\n    -/\nend\n\n\ntheorem p06 : (P \u2192 Q) \u2192 \u00ac P \u2228 Q :=\nbegin\n    assume pq,  \n    /-\n        pq : P \u2192 Q\n        \u22a2 \u00ac P \u2228 Q\n    -/\n    apply raa,\n    /-\n        pq : P \u2192 Q\n        \u22a2 \u00ac\u00ac (\u00ac P \u2228 Q)\n    -/ \n    assume h,\n    /-\n        pq : P \u2192 Q\n        h : \u00ac(\u00acP \u2228 Q)\n        \u22a2 false\n    -/ \n    apply h,\n    /-\n        pq : P \u2192 Q\n        h : \u00ac(\u00acP \u2228 Q)\n        \u22a2 \u00acP \u2228 Q\n    -/\n    left,\n    /-\n        pq : P \u2192 Q\n        h : \u00ac(\u00acP \u2228 Q)\n        \u22a2 \u00acP\n    -/\n    assume p,\n    /-\n        pq : P \u2192 Q\n        h : \u00ac(\u00acP \u2228 Q)\n        p : P\n        \u22a2 false\n    -/\n    apply h,\n    /-\n        pq : P \u2192 Q\n        h : \u00ac(\u00acP \u2228 Q)\n        p : P\n        \u22a2 \u00acP \u2228 Q\n    -/\n    right,\n    /-\n        pq : P \u2192 Q\n        h : \u00ac(\u00acP \u2228 Q)\n        p : P\n        \u22a2 Q\n    -/\n    apply pq,\n    /-\n        pq : P \u2192 Q\n        h : \u00ac(\u00acP \u2228 Q)\n        p : P\n        \u22a2 P\n    -/\n    exact np,\n    /-\n        No goals\n    -/\nend\n\n\ntheorem p07 : (\u00ac P \u2228 Q) \u2192 P \u2192 Q :=\nbegin\n    assume h p,\n    /-\n        h : \u00ac P \u2228 Q\n        p : P\n        \u22a2 Q\n    -/\n    cases h with np q,\n    /-\n        (Case 1)\n        np : \u00ac P\n        p : P\n        \u22a2 Q\n        (Case 2)\n        q : Q\n        p : P\n        \u22a2 Q\n    -/\n    have f : false,\n    /-\n        (Case 1)\n        np : \u00ac P\n        p : P\n        \u22a2 false\n\n        (Case 2)\n        np : \u00ac P\n        p : P\n        f : false\n        \u22a2 Q\n\n        (Case 3)\n        q : Q\n        p : P\n        \u22a2 Q\n    -/\n    apply np,\n    /-\n        (Case 1)\n        np : \u00ac P\n        p : P\n        \u22a2 P\n\n        (Case 2)\n        np : \u00ac P\n        p : P\n        f : false\n        \u22a2 Q\n\n        (Case 3)\n        q : Q\n        p : P\n        \u22a2 Q\n    -/\n    exact p,\n    /-\n        Gets rid of Case 1\n    -/\n    cases f,\n    /-\n        Gets rid of Case 2\n    -/\n    exact q,\n    /-\n        No goals (Gets rid of Case 3)\n    -/\nend\n\n\ntheorem p08 : \u00ac (P \u2194 \u00ac P) :=\nbegin\n    assume h,\n    /-\n        h : P \u2194 \u00ac P\n        \u22a2 false\n    -/\n    cases h with a b,\n    /-\n        (Case 1)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        \u22a2 false\n    -/    \n    have np : \u00ac P,\n    /-\n        (Case 1)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        \u22a2 \u00ac P\n\n        (Case 2)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 false\n    -/\n    assume npp,\n    /-\n        (Case 1)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        npp : P\n        \u22a2 false\n\n        (Case 2)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 false\n    -/\n    apply a,\n    /-\n        (Case 1)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        npp : P\n        \u22a2 P\n\n        (Case 2)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 false\n    -/\n    exact npp,\n    /-\n        (Case 1)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        npp : P\n        \u22a2 P\n\n        (Case 2)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 false\n    -/\n    exact npp,\n    /-\n        Gets rid of Case 1\n    -/\n    apply a,\n    /-\n        (Case 2)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 P\n    -/\n    apply b,\n    /-\n        (Case 2)\n        a : P \u2192 \u00ac P\n        b : \u00ac P \u2192 P\n        np : \u00ac P\n        \u22a2 \u00ac P\n    -/\n    exact np,\n    apply b,\n    exact np,\nend\n\n\ntheorem p09 : \u00ac P \u2194 \u00ac \u00ac \u00ac P :=\nbegin\n    constructor,\n    /-\n        (Case 1)\n        \u00ac P \u2192 \u00ac \u00ac \u00ac P\n        \n        (Case 2)\n        \u00ac \u00ac \u00ac P \u2192 \u00ac P \n    -/\n    assume np nnp,\n    /-\n        (Case 1)\n        np : \u00ac P \n        nnp : \u00ac \u00ac P\n        \u22a2 false\n        \n        (Case 2)\n        \u00ac \u00ac \u00ac P \u2192 \u00ac P \n    -/\n    apply nnp,\n    /-\n        (Case 1)\n        np : \u00ac P \n        nnp : \u00ac \u00ac P\n        \u22a2 \u00ac P \n        \n        (Case 2)\n        \u00ac \u00ac \u00ac P \u2192 \u00ac P \n    -/\n    exact np,\n    /-\n        Gets rid of Case 1\n    -/\n    assume nnnp p,\n    /-\n        (Case 2)\n        nnnp : \u00ac \u00ac \u00ac P\n        p : P\n        \u22a2 false\n    -/\n    apply nnnp,\n    /-\n        (Case 2)\n        nnnp : \u00ac \u00ac \u00ac P\n        p : P\n        \u22a2 \u00ac \u00ac P \n    -/\n    assume np,\n    /-\n        (Case 2)\n        nnnp : \u00ac \u00ac \u00ac P\n        p : P\n        np : \u00ac P  \n        \u22a2 false \n    -/\n    apply np,\n    /-\n        (Case 2)\n        nnnp : \u00ac \u00ac \u00ac P\n        p : P\n        np : \u00ac P  \n        \u22a2 P \n    -/\n    exact p\n    /-\n        No goals (Gets rid of Case 2)\n    -/\nend\n\n\ntheorem p10 : ((P \u2192 Q) \u2192 P) \u2192 P :=\nbegin\n  assume pqp,\n  apply raa,\n  assume nnp,\n  apply nnp,\n  apply pqp,\n  assume p,\n  have f : false,\n  apply nnp,\n  exact p,\n  cases f,\nend\n", "meta": {"author": "BraxWong", "repo": "lean_Rev", "sha": "c626bda0d38477f95ba4edaf20b9eaa034375c48", "save_path": "github-repos/lean/BraxWong-lean_Rev", "path": "github-repos/lean/BraxWong-lean_Rev/lean_Rev-c626bda0d38477f95ba4edaf20b9eaa034375c48/ex01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7043716561095437}}
{"text": "import tactic\n\nvariables (P Q R : Prop)\n\nexample : P \u2192 P :=\nbegin\n    intro hP,\n    exact hP,\nend\n\nexample : P \u2192 (Q \u2192 P) :=\nbegin\n    intro hP,\n    intro hQ,\n    exact hP,\nend\n\nexample : P \u2192 Q \u2192 P :=\nbegin\n    intro hP,\n    intro hQ,\n    exact hP,\nend\n\ntheorem modus_ponens : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin \n    intro hP,\n    intro hPQ,\n    apply hPQ,\n    exact hP,\nend\n\ntheorem transitivity : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin \n    intro hPQ,\n    intro hQR,\n    intro hP,\n    apply hQR,\n    apply hPQ,\n    exact hP,\nend\n\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin \n    intro hPQR,\n    intro hPQ,\n    intro hP,\n    apply hPQR,\n    exact hP,\n    apply hPQ,\n    exact hP,\nend\n\n-- in Lean, the definition of \u00ac P is 'P \u2192 false'\n-- one can prove it by considerind what happens if the value of P is true or false\nexample : P \u2192 \u00ac (\u00ac P) :=\nbegin \n    intro hP,\n    change(\u00ac P \u2192 false),\n    intro hnP,\n    change P \u2192 false at hnP,\n    apply hnP,\n    exact hP,\nend\n\nexample : P \u2227 Q \u2192 P :=\nbegin \n    intro hPaQ,\n    cases hPaQ with hP hQ,\n    exact hP,\nend\n\ntheorem and.elim' : P \u2227 Q \u2192 (P \u2192 Q \u2192 R) \u2192 R :=\nbegin \n    intro hPaQ,\n    intro hPQR,\n    cases hPaQ with hP hQ,\n    apply hPQR,\n    exact hP,\n    exact hQ,\nend\n\ntheorem and.intro' : P \u2192 Q \u2192 P \u2227 Q := \nbegin \n    intro hP,\n    intro hQ,\n    split,\n    exact hP,\n    exact hQ,\nend\n", "meta": {"author": "SzymonKubica", "repo": "Lean", "sha": "627bff2f001ba3f009c112c9332093e8de84863c", "save_path": "github-repos/lean/SzymonKubica-Lean", "path": "github-repos/lean/SzymonKubica-Lean/Lean-627bff2f001ba3f009c112c9332093e8de84863c/Propositions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.7043422736573385}}
{"text": "/-\nCopyright (c) 2022 Praneeth Kolichala. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Praneeth Kolichala\n-/\nimport topology.homotopy.equiv\nimport category_theory.equivalence\nimport algebraic_topology.fundamental_groupoid.product\n\n/-!\n# Homotopic maps induce naturally isomorphic functors\n\n## Main definitions\n\n  - `fundamental_groupoid_functor.homotopic_maps_nat_iso H` The natural isomorphism\n    between the induced functors `f : \u03c0(X) \u2964 \u03c0(Y)` and `g : \u03c0(X) \u2964 \u03c0(Y)`, given a homotopy\n    `H : f \u223c g`\n\n  - `fundamental_groupoid_functor.equiv_of_homotopy_equiv hequiv` The equivalence of the categories\n    `\u03c0(X)` and `\u03c0(Y)` given a homotopy equivalence `hequiv : X \u2243\u2095 Y` between them.\n\n## Implementation notes\n  - In order to be more universe polymorphic, we define `continuous_map.homotopy.ulift_map`\n  which lifts a homotopy from `I \u00d7 X \u2192 Y` to `(Top.of ((ulift I) \u00d7 X)) \u2192 Y`. This is because\n  this construction uses `fundamental_groupoid_functor.prod_to_prod_Top` to convert between\n  pairs of paths in I and X and the corresponding path after passing through a homotopy `H`.\n  But `fundamental_groupoid_functor.prod_to_prod_Top` requires two spaces in the same universe.\n-/\n\nnoncomputable theory\n\nuniverse u\n\nopen fundamental_groupoid\nopen category_theory\nopen fundamental_groupoid_functor\n\nopen_locale fundamental_groupoid\nopen_locale unit_interval\n\nnamespace unit_interval\n\n/-- The path 0 \u27f6 1 in I -/\ndef path01 : path (0 : I) 1 := { to_fun := id, source' := rfl, target' := rfl }\n\n/-- The path 0 \u27f6 1 in ulift I -/\ndef upath01 : path (ulift.up 0 : ulift.{u} I) (ulift.up 1) :=\n{ to_fun := ulift.up, source' := rfl, target' := rfl }\n\nlocal attribute [instance] path.homotopic.setoid\n/-- The homotopy path class of 0 \u2192 1 in `ulift I` -/\ndef uhpath01 : @from_top (Top.of $ ulift.{u} I) (ulift.up (0 : I)) \u27f6 from_top (ulift.up 1) :=\n\u27e6upath01\u27e7\n\nend unit_interval\n\nnamespace continuous_map.homotopy\nopen unit_interval (uhpath01)\n\nlocal attribute [instance] path.homotopic.setoid\n\nsection casts\n\n/-- Abbreviation for `eq_to_hom` that accepts points in a topological space -/\nabbreviation hcast {X : Top} {x\u2080 x\u2081 : X} (hx : x\u2080 = x\u2081) : from_top x\u2080 \u27f6 from_top x\u2081 := eq_to_hom hx\n\n@[simp] lemma hcast_def {X : Top} {x\u2080 x\u2081 : X} (hx\u2080 : x\u2080 = x\u2081) : hcast hx\u2080 = eq_to_hom hx\u2080 := rfl\n\nvariables {X\u2081 X\u2082 Y : Top.{u}} {f : C(X\u2081, Y)} {g : C(X\u2082, Y)}\n  {x\u2080 x\u2081 : X\u2081} {x\u2082 x\u2083 : X\u2082} {p : path x\u2080 x\u2081} {q : path x\u2082 x\u2083} (hfg : \u2200 t, f (p t) = g (q t))\n\ninclude hfg\n\n/-- If `f(p(t) = g(q(t))` for two paths `p` and `q`, then the induced path homotopy classes\n`f(p)` and `g(p)` are the same as well, despite having a priori different types -/\nlemma heq_path_of_eq_image : (\u03c0\u2098 f).map \u27e6p\u27e7 == (\u03c0\u2098 g).map \u27e6q\u27e7 :=\nby { simp only [map_eq, \u2190 path.homotopic.map_lift], apply path.homotopic.hpath_hext, exact hfg, }\n\nprivate lemma start_path : f x\u2080 = g x\u2082 := by { convert hfg 0; simp only [path.source], }\nprivate lemma end_path : f x\u2081 = g x\u2083 := by { convert hfg 1; simp only [path.target], }\n\nlemma eq_path_of_eq_image :\n  (\u03c0\u2098 f).map \u27e6p\u27e7 = hcast (start_path hfg) \u226b (\u03c0\u2098 g).map \u27e6q\u27e7 \u226b hcast (end_path hfg).symm :=\nby { rw functor.conj_eq_to_hom_iff_heq, exact heq_path_of_eq_image hfg }\n\nend casts\n\n/- We let `X` and `Y` be spaces, and `f` and `g` be homotopic maps between them -/\nvariables {X Y : Top.{u}} {f g : C(X, Y)} (H : continuous_map.homotopy f g)\n  {x\u2080 x\u2081 : X} (p : from_top x\u2080 \u27f6 from_top x\u2081)\n\n/-!\nThese definitions set up the following diagram, for each path `p`:\n\n            f(p)\n        *--------*\n        | \\      |\n    H\u2080  |   \\ d  |  H\u2081\n        |     \\  |\n        *--------*\n            g(p)\n\nHere, `H\u2080 = H.eval_at x\u2080` is the path from `f(x\u2080)` to `g(x\u2080)`,\nand similarly for `H\u2081`. Similarly, `f(p)` denotes the\npath in Y that the induced map `f` takes `p`, and similarly for `g(p)`.\n\nFinally, `d`, the diagonal path, is H(0 \u27f6 1, p), the result of the induced `H` on\n`path.homotopic.prod (0 \u27f6 1) p`, where `(0 \u27f6 1)` denotes the path from `0` to `1` in `I`.\n\nIt is clear that the diagram commutes (`H\u2080 \u226b g(p) = d = f(p) \u226b H\u2081`), but unfortunately,\nmany of the paths do not have defeq starting/ending points, so we end up needing some casting.\n-/\n\n/-- Interpret a homotopy `H : C(I \u00d7 X, Y) as a map C(ulift I \u00d7 X, Y) -/\ndef ulift_map : C(Top.of (ulift.{u} I \u00d7 X), Y) :=\n\u27e8\u03bb x, H (x.1.down, x.2),\n  H.continuous.comp ((continuous_induced_dom.comp continuous_fst).prod_mk continuous_snd)\u27e9\n\n@[simp] lemma ulift_apply (i : ulift.{u} I) (x : X) : H.ulift_map (i, x) = H (i.down, x) := rfl\n\n/-- An abbreviation for `prod_to_prod_Top`, with some types already in place to help the\n typechecker. In particular, the first path should be on the ulifted unit interval. -/\nabbreviation prod_to_prod_Top_I {a\u2081 a\u2082 : Top.of (ulift I)} {b\u2081 b\u2082 : X}\n  (p\u2081 : from_top a\u2081 \u27f6 from_top a\u2082) (p\u2082 : from_top b\u2081 \u27f6 from_top b\u2082) :=\n@category_theory.functor.map _ _ _ _ (prod_to_prod_Top (Top.of $ ulift I) X)\n  (a\u2081, b\u2081) (a\u2082, b\u2082) (p\u2081, p\u2082)\n\n/-- The diagonal path `d` of a homotopy `H` on a path `p` -/\ndef diagonal_path : from_top (H (0, x\u2080)) \u27f6 from_top (H (1, x\u2081)) :=\n(\u03c0\u2098 H.ulift_map).map (prod_to_prod_Top_I uhpath01 p)\n\n/-- The diagonal path, but starting from `f x\u2080` and going to `g x\u2081` -/\ndef diagonal_path' : from_top (f x\u2080) \u27f6 from_top (g x\u2081) :=\nhcast (H.apply_zero x\u2080).symm \u226b (H.diagonal_path p) \u226b hcast (H.apply_one x\u2081)\n\n/-- Proof that `f(p) = H(0 \u27f6 0, p)`, with the appropriate casts -/\nlemma apply_zero_path : (\u03c0\u2098 f).map p = hcast (H.apply_zero x\u2080).symm \u226b\n(\u03c0\u2098 H.ulift_map).map (prod_to_prod_Top_I (\ud835\udfd9 (ulift.up 0)) p) \u226b\nhcast (H.apply_zero x\u2081) :=\nbegin\n  apply quotient.induction_on p,\n  intro p',\n  apply @eq_path_of_eq_image _ _ _ _ H.ulift_map _ _ _ _ _ ((path.refl (ulift.up _)).prod p'),\n  simp,\nend\n\n/-- Proof that `g(p) = H(1 \u27f6 1, p)`, with the appropriate casts -/\nlemma apply_one_path : (\u03c0\u2098 g).map p = hcast (H.apply_one x\u2080).symm \u226b\n((\u03c0\u2098 H.ulift_map).map (prod_to_prod_Top_I (\ud835\udfd9 (ulift.up 1)) p)) \u226b\nhcast (H.apply_one x\u2081) :=\nbegin\n  apply quotient.induction_on p,\n  intro p',\n  apply @eq_path_of_eq_image _ _ _ _ H.ulift_map _ _ _ _ _ ((path.refl (ulift.up _)).prod p'),\n  simp,\nend\n\n/-- Proof that `H.eval_at x = H(0 \u27f6 1, x \u27f6 x)`, with the appropriate casts -/\nlemma eval_at_eq (x : X) : \u27e6H.eval_at x\u27e7 =\n  hcast (H.apply_zero x).symm \u226b\n(\u03c0\u2098 H.ulift_map).map (prod_to_prod_Top_I uhpath01 (\ud835\udfd9 x)) \u226b\nhcast (H.apply_one x).symm.symm :=\nbegin\n  dunfold prod_to_prod_Top_I uhpath01 hcast,\n  refine (@functor.conj_eq_to_hom_iff_heq (\u03c0\u2093 Y) _ _ _ _ _ _ _ _ _).mpr _,\n  simp only [id_eq_path_refl, prod_to_prod_Top_map, path.homotopic.prod_lift, map_eq,\n    \u2190 path.homotopic.map_lift],\n  apply path.homotopic.hpath_hext, intro, refl,\nend\n\n/- Finally, we show `d = f(p) \u226b H\u2081 = H\u2080 \u226b g(p)` -/\nlemma eq_diag_path :\n  (\u03c0\u2098 f).map p \u226b \u27e6H.eval_at x\u2081\u27e7 = H.diagonal_path' p \u2227\n  (\u27e6H.eval_at x\u2080\u27e7 \u226b (\u03c0\u2098 g).map p : from_top (f x\u2080) \u27f6 from_top (g x\u2081)) = H.diagonal_path' p :=\nbegin\n  rw [H.apply_zero_path, H.apply_one_path, H.eval_at_eq, H.eval_at_eq],\n  dunfold prod_to_prod_Top_I,\n  split; { slice_lhs 2 5 { simp [\u2190 category_theory.functor.map_comp], }, refl, },\nend\n\nend continuous_map.homotopy\n\nnamespace fundamental_groupoid_functor\nopen category_theory\nopen_locale fundamental_groupoid\nlocal attribute [instance] path.homotopic.setoid\n\nvariables {X Y : Top.{u}} {f g : C(X, Y)} (H : continuous_map.homotopy f g)\n\n/-- Given a homotopy H : f \u223c g, we have an associated natural isomorphism between the induced\nfunctors `f` and `g` -/\ndef homotopic_maps_nat_iso : \u03c0\u2098 f \u27f6 \u03c0\u2098 g :=\n{ app := \u03bb x, \u27e6H.eval_at x\u27e7,\n  naturality' := \u03bb x y p, by rw [(H.eq_diag_path p).1, (H.eq_diag_path p).2] }\n\ninstance : is_iso (homotopic_maps_nat_iso H) := by apply nat_iso.is_iso_of_is_iso_app\n\nopen_locale continuous_map\n\n/-- Homotopy equivalent topological spaces have equivalent fundamental groupoids. -/\ndef equiv_of_homotopy_equiv (hequiv : X \u2243\u2095 Y) : \u03c0\u2093 X \u224c \u03c0\u2093 Y :=\nbegin\n  apply equivalence.mk\n    (\u03c0\u2098 hequiv.to_fun : \u03c0\u2093 X \u2964 \u03c0\u2093 Y)\n    (\u03c0\u2098 hequiv.inv_fun : \u03c0\u2093 Y \u2964 \u03c0\u2093 X);\n  simp only [Groupoid.hom_to_functor, Groupoid.id_to_functor],\n  { convert (as_iso (homotopic_maps_nat_iso hequiv.left_inv.some)).symm,\n    exacts [((\u03c0).map_id X).symm, ((\u03c0).map_comp _ _).symm] },\n  { convert as_iso (homotopic_maps_nat_iso hequiv.right_inv.some),\n    exacts [((\u03c0).map_comp _ _).symm, ((\u03c0).map_id Y).symm] },\nend\n\nend fundamental_groupoid_functor\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebraic_topology/fundamental_groupoid/induced_maps.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7043422598990541}}
{"text": "/-\nCopyright (c) 2022 David Loeffler. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Loeffler\n-/\nimport measure_theory.integral.interval_integral\nimport measure_theory.integral.integral_eq_improper\n\n/-!\n# Integrals with exponential decay at \u221e\n\nAs easy special cases of general theorems in the library, we prove the following test\nfor integrability:\n\n* `integrable_of_is_O_exp_neg`: If `f` is continuous on `[a,\u221e)`, for some `a \u2208 \u211d`, and there\n  exists `b > 0` such that `f(x) = O(exp(-b x))` as `x \u2192 \u221e`, then `f` is integrable on `(a, \u221e)`.\n-/\n\nnoncomputable theory\nopen real interval_integral measure_theory set filter\n\n/-- Integral of `exp (-b * x)` over `(a, X)` is bounded as `X \u2192 \u221e`. -/\nlemma integral_exp_neg_le {b : \u211d} (a X : \u211d) (h2 : 0 < b) :\n  (\u222b x in a .. X, exp (-b * x)) \u2264 exp (-b * a) / b :=\nbegin\n  rw integral_deriv_eq_sub' (\u03bb x, -exp (-b * x) / b),\n  -- goal 1/4: F(X) - F(a) is bounded\n  { simp only [tsub_le_iff_right],\n    rw [neg_div b (exp (-b * a)), neg_div b (exp (-b * X)), add_neg_self, neg_le, neg_zero],\n    exact (div_pos (exp_pos _) h2).le, },\n  -- goal 2/4: the derivative of F is exp(-b x)\n  { ext1, simp [h2.ne'] },\n  -- goal 3/4: F is differentiable\n  { intros x hx, simp [h2.ne'], },\n  -- goal 4/4: exp(-b x) is continuous\n  { apply continuous.continuous_on, continuity }\nend\n\n/-- `exp (-b * x)` is integrable on `(a, \u221e)`. -/\nlemma exp_neg_integrable_on_Ioi (a : \u211d) {b : \u211d} (h : 0 < b) :\n  integrable_on (\u03bb x : \u211d, exp (-b * x)) (Ioi a) :=\nbegin\n  have : \u2200 (X : \u211d), integrable_on (\u03bb x : \u211d, exp (-b * x) ) (Ioc a X),\n  { intro X, exact (continuous_const.mul continuous_id).exp.integrable_on_Ioc },\n  apply (integrable_on_Ioi_of_interval_integral_norm_bounded (exp (-b * a) / b) a this tendsto_id),\n  simp only [eventually_at_top, norm_of_nonneg (exp_pos _).le],\n  exact \u27e8a, \u03bb b2 hb2, integral_exp_neg_le a b2 h\u27e9,\nend\n\n/-- If `f` is continuous on `[a, \u221e)`, and is `O (exp (-b * x))` at `\u221e` for some `b > 0`, then\n`f` is integrable on `(a, \u221e)`. -/\nlemma integrable_of_is_O_exp_neg {f : \u211d \u2192 \u211d} {a b : \u211d} (h0 : 0 < b)\n  (h1 : continuous_on f (Ici a)) (h2 : f =O[at_top] (\u03bb x, exp (-b * x))) :\n  integrable_on f (Ioi a) :=\nbegin\n  cases h2.is_O_with with c h3,\n  rw [asymptotics.is_O_with_iff, eventually_at_top] at h3,\n  cases h3 with r bdr,\n  let v := max a r,\n  -- show integrable on `(a, v]` from continuity\n  have int_left : integrable_on f (Ioc a v),\n  { rw \u2190(interval_integrable_iff_integrable_Ioc_of_le (le_max_left a r)),\n    have u : Icc a v \u2286 Ici a := Icc_subset_Ici_self,\n    exact (h1.mono u).interval_integrable_of_Icc (le_max_left a r), },\n  suffices : integrable_on f (Ioi v),\n  { have t : integrable_on f (Ioc a v \u222a Ioi v) := integrable_on_union.mpr \u27e8int_left, this\u27e9,\n    simpa only [Ioc_union_Ioi_eq_Ioi, le_max_iff, le_refl, true_or] using t },\n  -- now show integrable on `(v, \u221e)` from asymptotic\n  split,\n  { exact (h1.mono $ Ioi_subset_Ici $ le_max_left a r).ae_strongly_measurable measurable_set_Ioi },\n  have : has_finite_integral (\u03bb x : \u211d, c * exp (-b * x)) (volume.restrict (Ioi v)),\n  { exact (exp_neg_integrable_on_Ioi v h0).has_finite_integral.const_mul c },\n  apply this.mono,\n  refine (ae_restrict_iff' measurable_set_Ioi).mpr _,\n  refine ae_of_all _ (\u03bb x h1x, _),\n  rw [norm_mul, norm_eq_abs],\n  rw [mem_Ioi] at h1x,\n  specialize bdr x ((le_max_right a r).trans h1x.le),\n  exact bdr.trans (mul_le_mul_of_nonneg_right (le_abs_self c) (norm_nonneg _))\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/measure_theory/integral/exp_decay.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7043422546133058}}
{"text": "/-\nCopyright \u00a9 2020 Nicol\u00f2 Cavalleri. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Nicol\u00f2 Cavalleri\n-/\n\nimport geometry.manifold.times_cont_mdiff_map\n\n/-!\n# Smooth monoid\nA smooth monoid is a monoid that is also a smooth manifold, in which multiplication is a smooth map\nof the product manifold `G` \u00d7 `G` into `G`.\n\nIn this file we define the basic structures to talk about smooth monoids: `has_smooth_mul` and its\nadditive counterpart `has_smooth_add`. These structures are general enough to also talk about smooth\nsemigroups.\n-/\n\nopen_locale manifold\n\n/--\n1. All smooth algebraic structures on `G` are `Prop`-valued classes that extend\n`smooth_manifold_with_corners I G`. This way we save users from adding both\n`[smooth_manifold_with_corners I G]` and `[has_smooth_mul I G]` to the assumptions. While many API\nlemmas hold true without the `smooth_manifold_with_corners I G` assumption, we're not aware of a\nmathematically interesting monoid on a topological manifold such that (a) the space is not a\n`smooth_manifold_with_corners`; (b) the multiplication is smooth at `(a, b)` in the charts\n`ext_chart_at I a`, `ext_chart_at I b`, `ext_chart_at I (a * b)`.\n\n2. Because of `model_prod` we can't assume, e.g., that a `lie_group` is modelled on `\ud835\udcd8(\ud835\udd5c, E)`. So,\nwe formulate the definitions and lemmas for any model.\n\n3. While smoothness of an operation implies its continuity, lemmas like\n`has_continuous_mul_of_smooth` can't be instances becausen otherwise Lean would have to search for\n`has_smooth_mul I G` with unknown `\ud835\udd5c`, `E`, `H`, and `I : model_with_corners \ud835\udd5c E H`. If users needs\n`[has_continuous_mul G]` in a proof about a smooth monoid, then they need to either add\n`[has_continuous_mul G]` as an assumption (worse) or use `haveI` in the proof (better). -/\nlibrary_note \"Design choices about smooth algebraic structures\"\n\n/-- Basic hypothesis to talk about a smooth (Lie) additive monoid or a smooth additive\nsemigroup. A smooth additive monoid over `\u03b1`, for example, is obtained by requiring both the\ninstances `add_monoid \u03b1` and `has_smooth_add \u03b1`. -/\n-- See note [Design choices about smooth algebraic structures]\n@[ancestor smooth_manifold_with_corners]\nclass has_smooth_add {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n  {H : Type*} [topological_space H]\n  {E : Type*} [normed_group E] [normed_space \ud835\udd5c E] (I : model_with_corners \ud835\udd5c E H)\n  (G : Type*) [has_add G] [topological_space G] [charted_space H G]\n  extends smooth_manifold_with_corners I G : Prop :=\n(smooth_add : smooth (I.prod I) I (\u03bb p : G\u00d7G, p.1 + p.2))\n\n/-- Basic hypothesis to talk about a smooth (Lie) monoid or a smooth semigroup.\nA smooth monoid over `G`, for example, is obtained by requiring both the instances `monoid G`\nand `has_smooth_mul I G`. -/\n-- See note [Design choices about smooth algebraic structures]\n@[ancestor smooth_manifold_with_corners, to_additive]\nclass has_smooth_mul {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n  {H : Type*} [topological_space H]\n  {E : Type*} [normed_group E] [normed_space \ud835\udd5c E] (I : model_with_corners \ud835\udd5c E H)\n  (G : Type*) [has_mul G] [topological_space G] [charted_space H G]\n  extends smooth_manifold_with_corners I G : Prop :=\n(smooth_mul : smooth (I.prod I) I (\u03bb p : G\u00d7G, p.1 * p.2))\n\nsection has_smooth_mul\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{H : Type*} [topological_space H]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E] {I : model_with_corners \ud835\udd5c E H}\n{G : Type*} [has_mul G] [topological_space G] [charted_space H G] [has_smooth_mul I G]\n{E' : Type*} [normed_group E'] [normed_space \ud835\udd5c E']\n{H' : Type*} [topological_space H'] {I' : model_with_corners \ud835\udd5c E' H'}\n{M : Type*} [topological_space M] [charted_space H' M]\n\nsection\n\nvariables (I)\n\n@[to_additive]\nlemma smooth_mul : smooth (I.prod I) I (\u03bb p : G\u00d7G, p.1 * p.2) :=\nhas_smooth_mul.smooth_mul\n\n/-- If the multiplication is smooth, then it is continuous. This is not an instance for technical\nreasons, see note [Design choices about smooth algebraic structures]. -/\n@[to_additive\n\"If the addition is smooth, then it is continuous. This is not an instance for technical reasons,\nsee note [Design choices about smooth algebraic structures].\"]\nlemma has_continuous_mul_of_smooth : has_continuous_mul G :=\n\u27e8(smooth_mul I).continuous\u27e9\n\nend\n\n@[to_additive]\nlemma smooth.mul {f : M \u2192 G} {g : M \u2192 G} (hf : smooth I' I f) (hg : smooth I' I g) :\n  smooth I' I (f * g) :=\n(smooth_mul I).comp (hf.prod_mk hg)\n\n@[to_additive]\nlemma smooth_mul_left {a : G} : smooth I I (\u03bb b : G, a * b) :=\nsmooth_const.mul smooth_id\n\n@[to_additive]\nlemma smooth_mul_right {a : G} : smooth I I (\u03bb b : G, b * a) :=\nsmooth_id.mul smooth_const\n\n@[to_additive]\nlemma smooth_on.mul {f : M \u2192 G} {g : M \u2192 G} {s : set M}\n  (hf : smooth_on I' I f s) (hg : smooth_on I' I g s) :\n  smooth_on I' I (f * g) s :=\n((smooth_mul I).comp_smooth_on (hf.prod_mk hg) : _)\n\nvariables (I) (g h : G)\n\n/-- Left multiplication by `g`. It is meant to mimic the usual notation in Lie groups.\nLemmas involving `smooth_left_mul` with the notation `\ud835\udc73` usually use `L` instead of `\ud835\udc73` in the\nnames. -/\ndef smooth_left_mul : C^\u221e\u27eeI, G; I, G\u27ef := \u27e8(left_mul g), smooth_mul_left\u27e9\n\n/-- Right multiplication by `g`. It is meant to mimic the usual notation in Lie groups.\nLemmas involving `smooth_right_mul` with the notation `\ud835\udc79` usually use `R` instead of `\ud835\udc79` in the\nnames. -/\ndef smooth_right_mul : C^\u221e\u27eeI, G; I, G\u27ef := \u27e8(right_mul g), smooth_mul_right\u27e9\n\n/- Left multiplication. The abbreviation is `MIL`. -/\nlocalized \"notation `\ud835\udc73` := smooth_left_mul\" in lie_group\n\n/- Right multiplication. The abbreviation is `MIR`. -/\nlocalized \"notation `\ud835\udc79` := smooth_right_mul\" in lie_group\n\nopen_locale lie_group\n\n@[simp] lemma L_apply : (\ud835\udc73 I g) h = g * h := rfl\n@[simp] lemma R_apply : (\ud835\udc79 I g) h = h * g := rfl\n\n@[simp] lemma L_mul {G : Type*} [semigroup G] [topological_space G] [charted_space H G]\n  [has_smooth_mul I G] (g h : G) : \ud835\udc73 I (g * h) = (\ud835\udc73 I g).comp (\ud835\udc73 I h) :=\nby { ext, simp only [times_cont_mdiff_map.comp_apply, L_apply, mul_assoc] }\n\n@[simp] lemma R_mul {G : Type*} [semigroup G] [topological_space G] [charted_space H G]\n  [has_smooth_mul I G] (g h : G) : \ud835\udc79 I (g * h) = (\ud835\udc79 I h).comp (\ud835\udc79 I g) :=\nby { ext, simp only [times_cont_mdiff_map.comp_apply, R_apply, mul_assoc] }\n\nsection\n\nvariables {G' : Type*} [monoid G'] [topological_space G'] [charted_space H G']\n  [has_smooth_mul I G'] (g' : G')\n\nlemma smooth_left_mul_one : (\ud835\udc73 I g') 1 = g' := mul_one g'\nlemma smooth_right_mul_one : (\ud835\udc79 I g') 1 = g' := one_mul g'\n\nend\n\n/- Instance of product -/\n@[to_additive]\ninstance has_smooth_mul.prod {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n  {E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n  {H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n  (G : Type*) [topological_space G] [charted_space H G]\n  [has_mul G] [has_smooth_mul I G]\n  {E' : Type*} [normed_group E'] [normed_space \ud835\udd5c E']\n  {H' : Type*} [topological_space H'] (I' : model_with_corners \ud835\udd5c E' H')\n  (G' : Type*) [topological_space G'] [charted_space H' G']\n  [has_mul G'] [has_smooth_mul I' G'] :\n  has_smooth_mul (I.prod I') (G\u00d7G') :=\n{ smooth_mul := ((smooth_fst.comp smooth_fst).smooth.mul (smooth_fst.comp smooth_snd)).prod_mk\n    ((smooth_snd.comp smooth_fst).smooth.mul (smooth_snd.comp smooth_snd)),\n  .. smooth_manifold_with_corners.prod G G' }\n\nend has_smooth_mul\n\nsection monoid\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{H : Type*} [topological_space H]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E] {I : model_with_corners \ud835\udd5c E H}\n{G : Type*} [monoid G] [topological_space G] [charted_space H G] [has_smooth_mul I G]\n{H' : Type*} [topological_space H']\n{E' : Type*} [normed_group E'] [normed_space \ud835\udd5c E'] {I' : model_with_corners \ud835\udd5c E' H'}\n{G' : Type*} [monoid G'] [topological_space G'] [charted_space H' G'] [has_smooth_mul I' G']\n\nlemma smooth_pow : \u2200 n : \u2115, smooth I I (\u03bb a : G, a ^ n)\n| 0 := by { simp only [pow_zero], exact smooth_const }\n| (k+1) := by simpa [pow_succ] using smooth_id.mul (smooth_pow _)\n\n/-- Morphism of additive smooth monoids. -/\nstructure smooth_add_monoid_morphism\n  (I : model_with_corners \ud835\udd5c E H) (I' : model_with_corners \ud835\udd5c E' H')\n  (G : Type*) [topological_space G] [charted_space H G] [add_monoid G] [has_smooth_add I G]\n  (G' : Type*) [topological_space G'] [charted_space H' G'] [add_monoid G'] [has_smooth_add I' G']\n  extends G \u2192+ G' :=\n(smooth_to_fun : smooth I I' to_fun)\n\n/-- Morphism of smooth monoids. -/\n@[to_additive] structure smooth_monoid_morphism\n  (I : model_with_corners \ud835\udd5c E H) (I' : model_with_corners \ud835\udd5c E' H')\n  (G : Type*) [topological_space G] [charted_space H G] [monoid G] [has_smooth_mul I G]\n  (G' : Type*) [topological_space G'] [charted_space H' G'] [monoid G'] [has_smooth_mul I' G']\n  extends G \u2192* G' :=\n(smooth_to_fun : smooth I I' to_fun)\n\n@[to_additive]\ninstance : has_one (smooth_monoid_morphism I I' G G') :=\n\u27e8{ smooth_to_fun := smooth_const, to_monoid_hom := 1 }\u27e9\n\n@[to_additive]\ninstance : inhabited (smooth_monoid_morphism I I' G G') := \u27e81\u27e9\n\n@[to_additive]\ninstance : has_coe_to_fun (smooth_monoid_morphism I I' G G') (\u03bb _, G \u2192 G') := \u27e8\u03bb a, a.to_fun\u27e9\n\nend monoid\n\nsection comm_monoid\n\nopen_locale big_operators\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{H : Type*} [topological_space H]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E] {I : model_with_corners \ud835\udd5c E H}\n{G : Type*} [comm_monoid G] [topological_space G] [charted_space H G] [has_smooth_mul I G]\n{E' : Type*} [normed_group E'] [normed_space \ud835\udd5c E']\n{H' : Type*} [topological_space H'] {I' : model_with_corners \ud835\udd5c E' H'}\n{M : Type*} [topological_space M] [charted_space H' M]\n\n@[to_additive]\nlemma smooth_finset_prod' {\u03b9} {s : finset \u03b9} {f : \u03b9 \u2192 M \u2192 G} (h : \u2200 i \u2208 s, smooth I' I (f i)) :\n  smooth I' I (\u220f i in s, f i) :=\nfinset.prod_induction _ _ (\u03bb f g hf hg, hf.mul hg)\n  (@smooth_const _ _ _ _ _ _ _ I' _ _ _ _ _ _ _ _ I _ _ _ 1) h\n\n@[to_additive]\nlemma smooth_finset_prod {\u03b9} {s : finset \u03b9} {f : \u03b9 \u2192 M \u2192 G} (h : \u2200 i \u2208 s, smooth I' I (f i)) :\n  smooth I' I (\u03bb x, \u220f i in s, f i x) :=\nby { simp only [\u2190 finset.prod_apply], exact smooth_finset_prod' h }\n\nopen function filter\n\n@[to_additive]\nlemma smooth_finprod {\u03b9} {f : \u03b9 \u2192 M \u2192 G} (h : \u2200 i, smooth I' I (f i))\n  (hfin : locally_finite (\u03bb i, mul_support (f i))) :\n  smooth I' I (\u03bb x, \u220f\u1da0 i, f i x) :=\nbegin\n  intro x,\n  rcases hfin x with \u27e8U, hxU, hUf\u27e9,\n  have : smooth_at I' I (\u03bb x, \u220f i in hUf.to_finset, f i x) x,\n    from smooth_finset_prod (\u03bb i hi, h i) x,\n  refine this.congr_of_eventually_eq (mem_of_superset hxU $ \u03bb y hy, _),\n  refine finprod_eq_prod_of_mul_support_subset _ (\u03bb i hi, _),\n  rw [hUf.coe_to_finset],\n  exact \u27e8y, hi, hy\u27e9\nend\n\n@[to_additive]\nlemma smooth_finprod_cond {\u03b9} {f : \u03b9 \u2192 M \u2192 G} {p : \u03b9 \u2192 Prop} (hc : \u2200 i, p i \u2192 smooth I' I (f i))\n  (hf : locally_finite (\u03bb i, mul_support (f i))) :\n  smooth I' I (\u03bb x, \u220f\u1da0 i (hi : p i), f i x) :=\nbegin\n  simp only [\u2190 finprod_subtype_eq_finprod_cond],\n  exact smooth_finprod (\u03bb i, hc i i.2) (hf.comp_injective subtype.coe_injective)\nend\n\nend comm_monoid\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/geometry/manifold/algebra/monoid.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7043422489585563}}
{"text": "/-\nCopyright (c) 2022 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Floris van Doorn, Yury Kudryashov\n\n! This file was ported from Lean 3 source module order.filter.small_sets\n! leanprover-community/mathlib commit 8631e2d5ea77f6c13054d9151d82b83069680cb1\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Filter.Lift\nimport Mathlib.Order.Filter.AtTopBot\n\n/-!\n# The filter of small sets\n\nThis file defines the filter of small sets w.r.t. a filter `f`, which is the largest filter\ncontaining all powersets of members of `f`.\n\n`g` converges to `f.smallSets` if for all `s \u2208 f`, eventually we have `g x \u2286 s`.\n\nAn example usage is that if `f : \u03b9 \u2192 E \u2192 \u211d` is a family of nonnegative functions with integral 1,\nthen saying that `\u03bb i, support (f i)` tendsto `(\ud835\udcdd 0).smallSets` is a way of saying that\n`f` tends to the Dirac delta distribution.\n-/\n\n\nopen Filter\n\nopen Filter Set\n\nvariable {\u03b1 \u03b2 : Type _} {\u03b9 : Sort _}\n\nnamespace Filter\n\nvariable {l l' la : Filter \u03b1} {lb : Filter \u03b2}\n\n/-- The filter `l.smallSets` is the largest filter containing all powersets of members of `l`. -/\ndef smallSets (l : Filter \u03b1) : Filter (Set \u03b1) :=\n  l.lift' powerset\n#align filter.small_sets Filter.smallSets\n\ntheorem smallSets_eq_generate {f : Filter \u03b1} : f.smallSets = generate (powerset '' f.sets) := by\n  simp_rw [generate_eq_binf\u1d62, smallSets, inf\u1d62_image]\n  rfl\n#align filter.small_sets_eq_generate Filter.smallSets_eq_generate\n\ntheorem HasBasis.smallSets {p : \u03b9 \u2192 Prop} {s : \u03b9 \u2192 Set \u03b1} (h : HasBasis l p s) :\n    HasBasis l.smallSets p fun i => \ud835\udcab s i :=\n  h.lift' monotone_powerset\n#align filter.has_basis.small_sets Filter.HasBasis.smallSets\n\ntheorem hasBasis_smallSets (l : Filter \u03b1) :\n    HasBasis l.smallSets (fun t : Set \u03b1 => t \u2208 l) powerset :=\n  l.basis_sets.smallSets\n#align filter.has_basis_small_sets Filter.hasBasis_smallSets\n\n/-- `g` converges to `f.smallSets` if for all `s \u2208 f`, eventually we have `g x \u2286 s`. -/\ntheorem tendsto_smallSets_iff {f : \u03b1 \u2192 Set \u03b2} :\n    Tendsto f la lb.smallSets \u2194 \u2200 t \u2208 lb, \u2200\u1da0 x in la, f x \u2286 t :=\n  (hasBasis_smallSets lb).tendsto_right_iff\n#align filter.tendsto_small_sets_iff Filter.tendsto_smallSets_iff\n\n-- porting note: the proof was `eventually_lift'_iff monotone_powerset`\n-- but it timeouts in Lean 4\ntheorem eventually_smallSets {p : Set \u03b1 \u2192 Prop} :\n    (\u2200\u1da0 s in l.smallSets, p s) \u2194 \u2203 s \u2208 l, \u2200 t, t \u2286 s \u2192 p t := by\n  rw [smallSets, eventually_lift'_iff]; rfl\n  exact monotone_powerset\n#align filter.eventually_small_sets Filter.eventually_smallSets\n\ntheorem eventually_small_sets' {p : Set \u03b1 \u2192 Prop} (hp : \u2200 \u2983s t\u2984, s \u2286 t \u2192 p t \u2192 p s) :\n    (\u2200\u1da0 s in l.smallSets, p s) \u2194 \u2203 s \u2208 l, p s :=\n  eventually_smallSets.trans <|\n    exists_congr fun s => Iff.rfl.and \u27e8fun H => H s Subset.rfl, fun hs _t ht => hp ht hs\u27e9\n#align filter.eventually_small_sets' Filter.eventually_small_sets'\n\ntheorem frequently_smallSets {p : Set \u03b1 \u2192 Prop} :\n    (\u2203\u1da0 s in l.smallSets, p s) \u2194 \u2200 t \u2208 l, \u2203 s, s \u2286 t \u2227 p s :=\n  l.hasBasis_smallSets.frequently_iff\n#align filter.frequently_small_sets Filter.frequently_smallSets\n\ntheorem frequently_smallSets_mem (l : Filter \u03b1) : \u2203\u1da0 s in l.smallSets, s \u2208 l :=\n  frequently_smallSets.2 fun t ht => \u27e8t, Subset.rfl, ht\u27e9\n#align filter.frequently_small_sets_mem Filter.frequently_smallSets_mem\n\ntheorem HasAntitoneBasis.tendsto_smallSets {\u03b9} [Preorder \u03b9] {s : \u03b9 \u2192 Set \u03b1}\n    (hl : l.HasAntitoneBasis s) : Tendsto s atTop l.smallSets :=\n  tendsto_smallSets_iff.2 fun _t ht => hl.eventually_subset ht\n#align filter.has_antitone_basis.tendsto_small_sets Filter.HasAntitoneBasis.tendsto_smallSets\n\n@[mono]\ntheorem monotone_smallSets : Monotone (@smallSets \u03b1) :=\n  monotone_lift' monotone_id monotone_const\n#align filter.monotone_small_sets Filter.monotone_smallSets\n\n@[simp]\ntheorem smallSets_bot : (\u22a5 : Filter \u03b1).smallSets = pure \u2205 := by\n  rw [smallSets, lift'_bot, powerset_empty, principal_singleton]\n  exact monotone_powerset\n#align filter.small_sets_bot Filter.smallSets_bot\n\n@[simp]\ntheorem smallSets_top : (\u22a4 : Filter \u03b1).smallSets = \u22a4 := by\n  rw [smallSets, lift'_top, powerset_univ, principal_univ]\n#align filter.small_sets_top Filter.smallSets_top\n\n@[simp]\ntheorem smallSets_principal (s : Set \u03b1) : (\ud835\udcdf s).smallSets = \ud835\udcdf (\ud835\udcab s) :=\n  lift'_principal monotone_powerset\n#align filter.small_sets_principal Filter.smallSets_principal\n\ntheorem smallSets_comap (l : Filter \u03b2) (f : \u03b1 \u2192 \u03b2) :\n    (comap f l).smallSets = l.lift' (powerset \u2218 preimage f) :=\n  comap_lift'_eq2 monotone_powerset\n#align filter.small_sets_comap Filter.smallSets_comap\n\n\n\ntheorem smallSets_inf\u1d62 {f : \u03b9 \u2192 Filter \u03b1} : (inf\u1d62 f).smallSets = \u2a05 i, (f i).smallSets :=\n  lift'_inf\u1d62_of_map_univ (powerset_inter _ _) powerset_univ\n#align filter.small_sets_infi Filter.smallSets_inf\u1d62\n\ntheorem smallSets_inf (l\u2081 l\u2082 : Filter \u03b1) : (l\u2081 \u2293 l\u2082).smallSets = l\u2081.smallSets \u2293 l\u2082.smallSets :=\n  lift'_inf _ _ powerset_inter\n#align filter.small_sets_inf Filter.smallSets_inf\n\ninstance smallSets_neBot (l : Filter \u03b1) : NeBot l.smallSets := by\n  refine' (lift'_neBot_iff _).2 fun _ _ => powerset_nonempty\n  exact monotone_powerset\n#align filter.small_sets_ne_bot Filter.smallSets_neBot\n\ntheorem Tendsto.smallSets_mono {s t : \u03b1 \u2192 Set \u03b2} (ht : Tendsto t la lb.smallSets)\n    (hst : \u2200\u1da0 x in la, s x \u2286 t x) : Tendsto s la lb.smallSets := by\n  rw [tendsto_smallSets_iff] at ht \u22a2\n  exact fun u hu => (ht u hu).mp (hst.mono fun _ hst ht => hst.trans ht)\n#align filter.tendsto.small_sets_mono Filter.Tendsto.smallSets_mono\n\n/-- Generalized **squeeze theorem** (also known as **sandwich theorem**). If `s : \u03b1 \u2192 Set \u03b2` is a\nfamily of sets that tends to `Filter.smallSets lb` along `la` and `f : \u03b1 \u2192 \u03b2` is a function such\nthat `f x \u2208 s x` eventually along `la`, then `f` tends to `lb` along `la`.\n\nIf `s x` is the closed interval `[g x, h x]` for some functions `g`, `h` that tend to the same limit\n`\ud835\udcdd y`, then we obtain the standard squeeze theorem, see\n`tendsto_of_tendsto_of_tendsto_of_le_of_le'`. -/\ntheorem Tendsto.of_smallSets {s : \u03b1 \u2192 Set \u03b2} {f : \u03b1 \u2192 \u03b2} (hs : Tendsto s la lb.smallSets)\n    (hf : \u2200\u1da0 x in la, f x \u2208 s x) : Tendsto f la lb := fun t ht =>\n  hf.mp <| (tendsto_smallSets_iff.mp hs t ht).mono fun _ h\u2081 h\u2082 => h\u2081 h\u2082\n#align filter.tendsto.of_small_sets Filter.Tendsto.of_smallSets\n\n@[simp]\ntheorem eventually_smallSets_eventually {p : \u03b1 \u2192 Prop} :\n    (\u2200\u1da0 s in l.smallSets, \u2200\u1da0 x in l', x \u2208 s \u2192 p x) \u2194 \u2200\u1da0 x in l \u2293 l', p x :=\n  calc\n    _ \u2194 \u2203 s \u2208 l, \u2200\u1da0 x in l', x \u2208 s \u2192 p x :=\n      eventually_small_sets' fun s t hst ht => ht.mono fun x hx hs => hx (hst hs)\n    _ \u2194 \u2203 s \u2208 l, \u2203 t \u2208 l', \u2200 x, x \u2208 t \u2192 x \u2208 s \u2192 p x := by simp only [eventually_iff_exists_mem]\n    _ \u2194 \u2200\u1da0 x in l \u2293 l', p x := by simp only [eventually_inf, and_comm, mem_inter_iff, \u2190 and_imp]\n\n#align filter.eventually_small_sets_eventually Filter.eventually_smallSets_eventually\n\n@[simp]\ntheorem eventually_smallSets_forall {p : \u03b1 \u2192 Prop} :\n    (\u2200\u1da0 s in l.smallSets, \u2200 x \u2208 s, p x) \u2194 \u2200\u1da0 x in l, p x := by\n  simpa only [inf_top_eq, eventually_top] using @eventually_smallSets_eventually \u03b1 l \u22a4 p\n#align filter.eventually_small_sets_forall Filter.eventually_smallSets_forall\n\nalias eventually_smallSets_forall \u2194 Eventually.of_smallSets Eventually.smallSets\n#align filter.eventually.of_small_sets Filter.Eventually.of_smallSets\n#align filter.eventually.small_sets Filter.Eventually.smallSets\n\n@[simp]\ntheorem eventually_smallSets_subset {s : Set \u03b1} : (\u2200\u1da0 t in l.smallSets, t \u2286 s) \u2194 s \u2208 l :=\n  eventually_smallSets_forall\n#align filter.eventually_small_sets_subset Filter.eventually_smallSets_subset\n\nend Filter\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/Filter/SmallSets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504226, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7043194286197038}}
{"text": "import data.set\nopen set\n\nvariable {U : Type}\nvariables A B C : set U\nvariable x : U\n\nexample : A \u2229 A = A :=\neq_of_subset_of_subset\n(assume x,\n assume h: x \u2208 (A \u2229 A),\n show x \u2208 A, from and.left h)\n(assume x,\n assume h: x \u2208 A,\n show x \u2208 (A \u2229 A), from and.intro h h)\n\nexample : A \u222a A = A :=\neq_of_subset_of_subset\n(assume x,\n assume h: x \u2208 A \u222a A,\n have o1: x \u2208 A \u2228 x \u2208  A, from h,\n show x \u2208 A, from or.elim o1\n (assume a1: x \u2208 A,\n  show x \u2208 A, from a1)\n (assume a2: x \u2208 A,\n  show x \u2208 A, from a2)\n)\n(assume x,\n assume h: x \u2208 A,\n show x \u2208 (A \u222a A),from or.inl h) -- or.inl := or introducition left\n\n\nexample : A \u222a (\u2205: set U) = A :=\neq_of_subset_of_subset\n(assume x,\n assume h: x \u2208 A \u222a \u2205,\n have h2: x \u2208 A \u2228 x \u2208 (\u2205: set U), from h,\n show x \u2208 A, from or.elim h2\n  (assume h2_1: x \u2208 A,\n   show x \u2208 A, from h2_1)\n  (assume h2_2: x \u2208 (\u2205: set U),\n   show x \u2208 A, from false.elim h2_2 --> x \u2208 \u2205 = false, so false -> anything\n  )\n)\n(assume x,\nassume h: x \u2208 A,\nshow x \u2208 A \u222a \u2205, from or.inl h)", "meta": {"author": "kmdtty", "repo": "lean_exercise", "sha": "467cce72c5f2c218e50c1d8cac57de3b805e7356", "save_path": "github-repos/lean/kmdtty-lean_exercise", "path": "github-repos/lean/kmdtty-lean_exercise/lean_exercise-467cce72c5f2c218e50c1d8cac57de3b805e7356/set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7042579345860547}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Floris van Doorn, Violeta Hern\u00e1ndez Palacios\n\n! This file was ported from Lean 3 source module set_theory.ordinal.exponential\n! leanprover-community/mathlib commit b67044ba53af18680e1dd246861d9584e968495d\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.SetTheory.Ordinal.Arithmetic\n\n/-! # Ordinal exponential\n\nIn this file we define the power function and the logarithm function on ordinals. The two are\nrelated by the lemma `Ordinal.opow_le_iff_le_log : (b^c) \u2264 x \u2194 c \u2264 log b x` for nontrivial inputs\n`b`, `c`.\n-/\n\n\nnoncomputable section\n\nopen Function Cardinal Set Equiv Order\n\nopen Classical Cardinal Ordinal\n\nuniverse u v w\n\nnamespace Ordinal\n\n/-- The ordinal exponential, defined by transfinite recursion. -/\ninstance pow : Pow Ordinal Ordinal :=\n  \u27e8fun a b => if a = 0 then 1 - b else limitRecOn b 1 (fun _ IH => IH * a) fun b _ => bsup.{u, u} b\u27e9\n\n-- Porting note: Ambiguous notations.\n-- local infixr:0 \"^\" => @Pow.pow Ordinal Ordinal Ordinal.instPowOrdinalOrdinal\n\ntheorem opow_def (a b : Ordinal) :\n    (a^b) = if a = 0 then 1 - b else limitRecOn b 1 (fun _ IH => IH * a) fun b _ => bsup.{u, u} b :=\n  rfl\n#align ordinal.opow_def Ordinal.opow_def\n\n-- Porting note: `if_pos rfl` \u2192 `if_true`\ntheorem zero_opow' (a : Ordinal) : (0^a) = 1 - a := by simp only [opow_def, if_true]\n#align ordinal.zero_opow' Ordinal.zero_opow'\n\n@[simp]\ntheorem zero_opow {a : Ordinal} (a0 : a \u2260 0) : (0^a) = 0 := by\n  rwa [zero_opow', Ordinal.sub_eq_zero_iff_le, one_le_iff_ne_zero]\n#align ordinal.zero_opow Ordinal.zero_opow\n\n@[simp]\ntheorem opow_zero (a : Ordinal) : (a^0) = 1 := by\n  by_cases h : a = 0\n  \u00b7 simp only [opow_def, if_pos h, sub_zero]\n  \u00b7 simp only [opow_def, if_neg h, limitRecOn_zero]\n#align ordinal.opow_zero Ordinal.opow_zero\n\n@[simp]\ntheorem opow_succ (a b : Ordinal) : (a^succ b) = (a^b) * a :=\n  if h : a = 0 then by subst a; simp only [zero_opow (succ_ne_zero _), mul_zero]\n  else by simp only [opow_def, limitRecOn_succ, if_neg h]\n#align ordinal.opow_succ Ordinal.opow_succ\n\ntheorem opow_limit {a b : Ordinal} (a0 : a \u2260 0) (h : IsLimit b) :\n    (a^b) = bsup.{u, u} b fun c _ => a^c := by\n  simp only [opow_def, if_neg a0]; rw [limitRecOn_limit _ _ _ _ h]\n#align ordinal.opow_limit Ordinal.opow_limit\n\ntheorem opow_le_of_limit {a b c : Ordinal} (a0 : a \u2260 0) (h : IsLimit b) :\n    (a^b) \u2264 c \u2194 \u2200 b' < b, (a^b') \u2264 c := by rw [opow_limit a0 h, bsup_le_iff]\n#align ordinal.opow_le_of_limit Ordinal.opow_le_of_limit\n\ntheorem lt_opow_of_limit {a b c : Ordinal} (b0 : b \u2260 0) (h : IsLimit c) :\n    a < (b^c) \u2194 \u2203 c' < c, a < (b^c') := by\n  rw [\u2190 not_iff_not, not_exists]; simp only [not_lt, opow_le_of_limit b0 h, exists_prop, not_and]\n#align ordinal.lt_opow_of_limit Ordinal.lt_opow_of_limit\n\n@[simp]\ntheorem opow_one (a : Ordinal) : (a^1) = a := by\n  rw [\u2190 succ_zero, opow_succ]; simp only [opow_zero, one_mul]\n#align ordinal.opow_one Ordinal.opow_one\n\n@[simp]\ntheorem one_opow (a : Ordinal) : (1^a) = 1 := by\n  apply limitRecOn a\n  \u00b7 simp only [opow_zero]\n  \u00b7 intro _ ih\n    simp only [opow_succ, ih, mul_one]\n  refine' fun b l IH => eq_of_forall_ge_iff fun c => _\n  rw [opow_le_of_limit Ordinal.one_ne_zero l]\n  exact \u27e8fun H => by simpa only [opow_zero] using H 0 l.pos, fun H b' h => by rwa [IH _ h]\u27e9\n#align ordinal.one_opow Ordinal.one_opow\n\ntheorem opow_pos {a : Ordinal} (b) (a0 : 0 < a) : 0 < (a^b) := by\n  have h0 : 0 < (a^0) := by simp only [opow_zero, zero_lt_one]\n  apply limitRecOn b\n  \u00b7 exact h0\n  \u00b7 intro b IH\n    rw [opow_succ]\n    exact mul_pos IH a0\n  \u00b7 exact fun b l _ => (lt_opow_of_limit (Ordinal.pos_iff_ne_zero.1 a0) l).2 \u27e80, l.pos, h0\u27e9\n#align ordinal.opow_pos Ordinal.opow_pos\n\ntheorem opow_ne_zero {a : Ordinal} (b) (a0 : a \u2260 0) : (a^b) \u2260 0 :=\n  Ordinal.pos_iff_ne_zero.1 <| opow_pos b <| Ordinal.pos_iff_ne_zero.2 a0\n#align ordinal.opow_ne_zero Ordinal.opow_ne_zero\n\ntheorem opow_isNormal {a : Ordinal} (h : 1 < a) : IsNormal ((\u00b7^\u00b7) a) :=\n  have a0 : 0 < a := zero_lt_one.trans h\n  \u27e8fun b => by simpa only [mul_one, opow_succ] using (mul_lt_mul_iff_left (opow_pos b a0)).2 h,\n    fun b l c => opow_le_of_limit (ne_of_gt a0) l\u27e9\n#align ordinal.opow_is_normal Ordinal.opow_isNormal\n\ntheorem opow_lt_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : (a^b) < (a^c) \u2194 b < c :=\n  (opow_isNormal a1).lt_iff\n#align ordinal.opow_lt_opow_iff_right Ordinal.opow_lt_opow_iff_right\n\ntheorem opow_le_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : (a^b) \u2264 (a^c) \u2194 b \u2264 c :=\n  (opow_isNormal a1).le_iff\n#align ordinal.opow_le_opow_iff_right Ordinal.opow_le_opow_iff_right\n\ntheorem opow_right_inj {a b c : Ordinal} (a1 : 1 < a) : (a^b) = (a^c) \u2194 b = c :=\n  (opow_isNormal a1).inj\n#align ordinal.opow_right_inj Ordinal.opow_right_inj\n\ntheorem opow_isLimit {a b : Ordinal} (a1 : 1 < a) : IsLimit b \u2192 IsLimit (a^b) :=\n  (opow_isNormal a1).isLimit\n#align ordinal.opow_is_limit Ordinal.opow_isLimit\n\ntheorem opow_isLimit_left {a b : Ordinal} (l : IsLimit a) (hb : b \u2260 0) : IsLimit (a^b) := by\n  rcases zero_or_succ_or_limit b with (e | \u27e8b, rfl\u27e9 | l')\n  \u00b7 exact absurd e hb\n  \u00b7 rw [opow_succ]\n    exact mul_isLimit (opow_pos _ l.pos) l\n  \u00b7 exact opow_isLimit l.one_lt l'\n#align ordinal.opow_is_limit_left Ordinal.opow_isLimit_left\n\ntheorem opow_le_opow_right {a b c : Ordinal} (h\u2081 : 0 < a) (h\u2082 : b \u2264 c) : (a^b) \u2264 (a^c) := by\n  cases' lt_or_eq_of_le (one_le_iff_pos.2 h\u2081) with h\u2081 h\u2081\n  \u00b7 exact (opow_le_opow_iff_right h\u2081).2 h\u2082\n  \u00b7 subst a\n    -- Porting note: `le_refl` is required.\n    simp only [one_opow, le_refl]\n#align ordinal.opow_le_opow_right Ordinal.opow_le_opow_right\n\ntheorem opow_le_opow_left {a b : Ordinal} (c) (ab : a \u2264 b) : (a^c) \u2264 (b^c) := by\n  by_cases a0 : a = 0\n  -- Porting note: `le_refl` is required.\n  \u00b7 subst a\n    by_cases c0 : c = 0\n    \u00b7 subst c\n      simp only [opow_zero, le_refl]\n    \u00b7 simp only [zero_opow c0, Ordinal.zero_le]\n  \u00b7 apply limitRecOn c\n    \u00b7 simp only [opow_zero, le_refl]\n    \u00b7 intro c IH\n      simpa only [opow_succ] using mul_le_mul' IH ab\n    \u00b7\n      exact fun c l IH =>\n        (opow_le_of_limit a0 l).2 fun b' h =>\n          (IH _ h).trans (opow_le_opow_right ((Ordinal.pos_iff_ne_zero.2 a0).trans_le ab) h.le)\n#align ordinal.opow_le_opow_left Ordinal.opow_le_opow_left\n\ntheorem left_le_opow (a : Ordinal) {b : Ordinal} (b1 : 0 < b) : a \u2264 (a^b) := by\n  nth_rw 1 [\u2190 opow_one a]\n  cases' le_or_gt a 1 with a1 a1\n  \u00b7 cases' lt_or_eq_of_le a1 with a0 a1\n    \u00b7 rw [lt_one_iff_zero] at a0\n      rw [a0, zero_opow Ordinal.one_ne_zero]\n      exact Ordinal.zero_le _\n    rw [a1, one_opow, one_opow]\n  rwa [opow_le_opow_iff_right a1, one_le_iff_pos]\n#align ordinal.left_le_opow Ordinal.left_le_opow\n\ntheorem right_le_opow {a : Ordinal} (b) (a1 : 1 < a) : b \u2264 (a^b) :=\n  (opow_isNormal a1).self_le _\n#align ordinal.right_le_opow Ordinal.right_le_opow\n\ntheorem opow_lt_opow_left_of_succ {a b c : Ordinal} (ab : a < b) : (a^succ c) < (b^succ c) := by\n  rw [opow_succ, opow_succ]\n  exact\n    (mul_le_mul_right' (opow_le_opow_left c ab.le) a).trans_lt\n      (mul_lt_mul_of_pos_left ab (opow_pos c ((Ordinal.zero_le a).trans_lt ab)))\n#align ordinal.opow_lt_opow_left_of_succ Ordinal.opow_lt_opow_left_of_succ\n\ntheorem opow_add (a b c : Ordinal) : a^(b + c) = (a^b) * (a^c) := by\n  rcases eq_or_ne a 0 with (rfl | a0)\n  \u00b7 rcases eq_or_ne c 0 with (rfl | c0)\n    \u00b7 simp\n    have : b + c \u2260 0 := ((Ordinal.pos_iff_ne_zero.2 c0).trans_le (le_add_left _ _)).ne'\n    simp only [zero_opow c0, zero_opow this, mul_zero]\n  rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with (rfl | a1)\n  \u00b7 simp only [one_opow, mul_one]\n  apply limitRecOn c\n  \u00b7 simp\n  \u00b7 intro c IH\n    rw [add_succ, opow_succ, IH, opow_succ, mul_assoc]\n  \u00b7 intro c l IH\n    refine'\n      eq_of_forall_ge_iff fun d =>\n        (((opow_isNormal a1).trans (add_isNormal b)).limit_le l).trans _\n    dsimp only [Function.comp]\n    simp (config := { contextual := true }) only [IH]\n    exact\n      (((mul_isNormal <| opow_pos b (Ordinal.pos_iff_ne_zero.2 a0)).trans\n              (opow_isNormal a1)).limit_le\n          l).symm\n#align ordinal.opow_add Ordinal.opow_add\n\ntheorem opow_one_add (a b : Ordinal) : a^(1 + b) = a * (a^b) := by rw [opow_add, opow_one]\n#align ordinal.opow_one_add Ordinal.opow_one_add\n\ntheorem opow_dvd_opow (a) {b c : Ordinal} (h : b \u2264 c) : (a^b) \u2223 (a^c) :=\n  \u27e8a^(c - b), by rw [\u2190 opow_add, Ordinal.add_sub_cancel_of_le h]\u27e9\n#align ordinal.opow_dvd_opow Ordinal.opow_dvd_opow\n\ntheorem opow_dvd_opow_iff {a b c : Ordinal} (a1 : 1 < a) : (a^b) \u2223 (a^c) \u2194 b \u2264 c :=\n  \u27e8fun h =>\n    le_of_not_lt fun hn =>\n      not_le_of_lt ((opow_lt_opow_iff_right a1).2 hn) <|\n        le_of_dvd (opow_ne_zero _ <| one_le_iff_ne_zero.1 <| a1.le) h,\n    opow_dvd_opow _\u27e9\n#align ordinal.opow_dvd_opow_iff Ordinal.opow_dvd_opow_iff\n\ntheorem opow_mul (a b c : Ordinal) : a^(b * c) = ((a^b)^c) := by\n  by_cases b0 : b = 0; \u00b7 simp only [b0, zero_mul, opow_zero, one_opow]\n  by_cases a0 : a = 0\n  \u00b7 subst a\n    by_cases c0 : c = 0\n    \u00b7 simp only [c0, mul_zero, opow_zero]\n    simp only [zero_opow b0, zero_opow c0, zero_opow (mul_ne_zero b0 c0)]\n  cases' eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 a1\n  \u00b7 subst a1\n    simp only [one_opow]\n  apply limitRecOn c\n  \u00b7 simp only [mul_zero, opow_zero]\n  \u00b7 intro c IH\n    rw [mul_succ, opow_add, IH, opow_succ]\n  \u00b7 intro c l IH\n    refine'\n      eq_of_forall_ge_iff fun d =>\n        (((opow_isNormal a1).trans (mul_isNormal (Ordinal.pos_iff_ne_zero.2 b0))).limit_le\n              l).trans\n          _\n    dsimp only [Function.comp]\n    simp (config := { contextual := true }) only [IH]\n    exact (opow_le_of_limit (opow_ne_zero _ a0) l).symm\n#align ordinal.opow_mul Ordinal.opow_mul\n\n/-! ### Ordinal logarithm -/\n\n\n/-- The ordinal logarithm is the solution `u` to the equation `x = b ^ u * v + w` where `v < b` and\n    `w < b ^ u`. -/\n-- @[pp_nodot] -- Porting note: Unknown attribute.\ndef log (b : Ordinal) (x : Ordinal) : Ordinal :=\n  if _h : 1 < b then pred (inf\u209b { o | x < (b^o) }) else 0\n#align ordinal.log Ordinal.log\n\n/-- The set in the definition of `log` is nonempty. -/\ntheorem log_nonempty {b x : Ordinal} (h : 1 < b) : { o | x < (b^o) }.Nonempty :=\n  \u27e8_, succ_le_iff.1 (right_le_opow _ h)\u27e9\n#align ordinal.log_nonempty Ordinal.log_nonempty\n\ntheorem log_def {b : Ordinal} (h : 1 < b) (x : Ordinal) : log b x = pred (inf\u209b { o | x < (b^o) }) :=\n  by simp only [log, dif_pos h]\n#align ordinal.log_def Ordinal.log_def\n\ntheorem log_of_not_one_lt_left {b : Ordinal} (h : \u00ac1 < b) (x : Ordinal) : log b x = 0 := by\n  simp only [log, dif_neg h]\n#align ordinal.log_of_not_one_lt_left Ordinal.log_of_not_one_lt_left\n\ntheorem log_of_left_le_one {b : Ordinal} (h : b \u2264 1) : \u2200 x, log b x = 0 :=\n  log_of_not_one_lt_left h.not_lt\n#align ordinal.log_of_left_le_one Ordinal.log_of_left_le_one\n\n@[simp]\ntheorem log_zero_left : \u2200 b, log 0 b = 0 :=\n  log_of_left_le_one zero_le_one\n#align ordinal.log_zero_left Ordinal.log_zero_left\n\n@[simp]\ntheorem log_zero_right (b : Ordinal) : log b 0 = 0 :=\n  if b1 : 1 < b then by\n    rw [log_def b1, \u2190 Ordinal.le_zero, pred_le]\n    apply cinf\u209b_le'\n    dsimp\n    rw [succ_zero, opow_one]\n    exact zero_lt_one.trans b1\n  else by simp only [log_of_not_one_lt_left b1]\n#align ordinal.log_zero_right Ordinal.log_zero_right\n\n@[simp]\ntheorem log_one_left : \u2200 b, log 1 b = 0 :=\n  log_of_left_le_one le_rfl\n#align ordinal.log_one_left Ordinal.log_one_left\n\ntheorem succ_log_def {b x : Ordinal} (hb : 1 < b) (hx : x \u2260 0) :\n    succ (log b x) = inf\u209b { o | x < (b^o) } := by\n  let t := inf\u209b { o | x < (b^o) }\n  have : x < (b^t) := cinf\u209b_mem (log_nonempty hb)\n  rcases zero_or_succ_or_limit t with (h | h | h)\n  \u00b7 refine' ((one_le_iff_ne_zero.2 hx).not_lt _).elim\n    simpa only [h, opow_zero] using this\n  \u00b7 rw [show log b x = pred t from log_def hb x, succ_pred_iff_is_succ.2 h]\n  \u00b7 rcases(lt_opow_of_limit (zero_lt_one.trans hb).ne' h).1 this with \u27e8a, h\u2081, h\u2082\u27e9\n    exact h\u2081.not_le.elim ((le_cinf\u209b_iff'' (log_nonempty hb)).1 le_rfl a h\u2082)\n#align ordinal.succ_log_def Ordinal.succ_log_def\n\ntheorem lt_opow_succ_log_self {b : Ordinal} (hb : 1 < b) (x : Ordinal) : x < (b^succ (log b x)) :=\n  by\n  rcases eq_or_ne x 0 with (rfl | hx)\n  \u00b7 apply opow_pos _ (zero_lt_one.trans hb)\n  \u00b7 rw [succ_log_def hb hx]\n    exact cinf\u209b_mem (log_nonempty hb)\n#align ordinal.lt_opow_succ_log_self Ordinal.lt_opow_succ_log_self\n\ntheorem opow_log_le_self (b) {x : Ordinal} (hx : x \u2260 0) : (b^log b x) \u2264 x := by\n  rcases eq_or_ne b 0 with (rfl | b0)\n  \u00b7 rw [zero_opow']\n    refine' (sub_le_self _ _).trans (one_le_iff_ne_zero.2 hx)\n  rcases lt_or_eq_of_le (one_le_iff_ne_zero.2 b0) with (hb | rfl)\n  \u00b7 refine' le_of_not_lt fun h => (lt_succ (log b x)).not_le _\n    have := @cinf\u209b_le' _ _ { o | x < (b^o) } _ h\n    rwa [\u2190 succ_log_def hb hx] at this\n  \u00b7 rwa [one_opow, one_le_iff_ne_zero]\n#align ordinal.opow_log_le_self Ordinal.opow_log_le_self\n\n/-- `opow b` and `log b` (almost) form a Galois connection. -/\ntheorem opow_le_iff_le_log {b x c : Ordinal} (hb : 1 < b) (hx : x \u2260 0) : (b^c) \u2264 x \u2194 c \u2264 log b x :=\n  \u27e8fun h =>\n    le_of_not_lt fun hn =>\n      (lt_opow_succ_log_self hb x).not_le <|\n        ((opow_le_opow_iff_right hb).2 (succ_le_of_lt hn)).trans h,\n    fun h => ((opow_le_opow_iff_right hb).2 h).trans (opow_log_le_self b hx)\u27e9\n#align ordinal.opow_le_iff_le_log Ordinal.opow_le_iff_le_log\n\ntheorem lt_opow_iff_log_lt {b x c : Ordinal} (hb : 1 < b) (hx : x \u2260 0) : x < (b^c) \u2194 log b x < c :=\n  lt_iff_lt_of_le_iff_le (opow_le_iff_le_log hb hx)\n#align ordinal.lt_opow_iff_log_lt Ordinal.lt_opow_iff_log_lt\n\ntheorem log_pos {b o : Ordinal} (hb : 1 < b) (ho : o \u2260 0) (hbo : b \u2264 o) : 0 < log b o := by\n  rwa [\u2190 succ_le_iff, succ_zero, \u2190 opow_le_iff_le_log hb ho, opow_one]\n#align ordinal.log_pos Ordinal.log_pos\n\ntheorem log_eq_zero {b o : Ordinal} (hbo : o < b) : log b o = 0 := by\n  rcases eq_or_ne o 0 with (rfl | ho)\n  \u00b7 exact log_zero_right b\n  cases' le_or_lt b 1 with hb hb\n  \u00b7 rcases le_one_iff.1 hb with (rfl | rfl)\n    \u00b7 exact log_zero_left o\n    \u00b7 exact log_one_left o\n  \u00b7 rwa [\u2190 Ordinal.le_zero, \u2190 lt_succ_iff, succ_zero, \u2190 lt_opow_iff_log_lt hb ho, opow_one]\n#align ordinal.log_eq_zero Ordinal.log_eq_zero\n\n@[mono]\ntheorem log_mono_right (b) {x y : Ordinal} (xy : x \u2264 y) : log b x \u2264 log b y :=\n  if hx : x = 0 then by simp only [hx, log_zero_right, Ordinal.zero_le]\n  else\n    if hb : 1 < b then\n      (opow_le_iff_le_log hb (lt_of_lt_of_le (Ordinal.pos_iff_ne_zero.2 hx) xy).ne').1 <|\n        (opow_log_le_self _ hx).trans xy\n    else by simp only [log_of_not_one_lt_left hb, Ordinal.zero_le]\n#align ordinal.log_mono_right Ordinal.log_mono_right\n\ntheorem log_le_self (b x : Ordinal) : log b x \u2264 x :=\n  if hx : x = 0 then by simp only [hx, log_zero_right, Ordinal.zero_le]\n  else\n    if hb : 1 < b then (right_le_opow _ hb).trans (opow_log_le_self b hx)\n    else by simp only [log_of_not_one_lt_left hb, Ordinal.zero_le]\n#align ordinal.log_le_self Ordinal.log_le_self\n\n@[simp]\ntheorem log_one_right (b : Ordinal) : log b 1 = 0 :=\n  if hb : 1 < b then log_eq_zero hb else log_of_not_one_lt_left hb 1\n#align ordinal.log_one_right Ordinal.log_one_right\n\ntheorem mod_opow_log_lt_self (b : Ordinal) {o : Ordinal} (ho : o \u2260 0) : o % (b^log b o) < o := by\n  rcases eq_or_ne b 0 with (rfl | hb)\n  \u00b7 simpa using Ordinal.pos_iff_ne_zero.2 ho\n  \u00b7 exact (mod_lt _ <| opow_ne_zero _ hb).trans_le (opow_log_le_self _ ho)\n#align ordinal.mod_opow_log_lt_self Ordinal.mod_opow_log_lt_self\n\ntheorem log_mod_opow_log_lt_log_self {b o : Ordinal} (hb : 1 < b) (ho : o \u2260 0) (hbo : b \u2264 o) :\n    log b (o % (b^log b o)) < log b o := by\n  cases' eq_or_ne (o % (b^log b o)) 0 with h h\n  \u00b7 rw [h, log_zero_right]\n    apply log_pos hb ho hbo\n  \u00b7 rw [\u2190 succ_le_iff, succ_log_def hb h]\n    apply cinf\u209b_le'\n    apply mod_lt\n    rw [\u2190 Ordinal.pos_iff_ne_zero]\n    exact opow_pos _ (zero_lt_one.trans hb)\n#align ordinal.log_mod_opow_log_lt_log_self Ordinal.log_mod_opow_log_lt_log_self\n\ntheorem opow_mul_add_pos {b v : Ordinal} (hb : b \u2260 0) (u) (hv : v \u2260 0) (w) : 0 < (b^u) * v + w :=\n  (opow_pos u <| Ordinal.pos_iff_ne_zero.2 hb).trans_le <|\n    (le_mul_left _ <| Ordinal.pos_iff_ne_zero.2 hv).trans <| le_add_right _ _\n#align ordinal.opow_mul_add_pos Ordinal.opow_mul_add_pos\n\ntheorem opow_mul_add_lt_opow_mul_succ {b u w : Ordinal} (v : Ordinal) (hw : w < (b^u)) :\n    (b^u) * v + w < (b^u) * succ v := by rwa [mul_succ, add_lt_add_iff_left]\n#align ordinal.opow_mul_add_lt_opow_mul_succ Ordinal.opow_mul_add_lt_opow_mul_succ\n\ntheorem opow_mul_add_lt_opow_succ {b u v w : Ordinal} (hvb : v < b) (hw : w < (b^u)) :\n    (b^u) * v + w < (b^succ u) := by\n  convert (opow_mul_add_lt_opow_mul_succ v hw).trans_le (mul_le_mul_left' (succ_le_of_lt hvb) _)\n    using 1\n  exact opow_succ b u\n#align ordinal.opow_mul_add_lt_opow_succ Ordinal.opow_mul_add_lt_opow_succ\n\ntheorem log_opow_mul_add {b u v w : Ordinal} (hb : 1 < b) (hv : v \u2260 0) (hvb : v < b)\n    (hw : w < (b^u)) : log b ((b^u) * v + w) = u := by\n  have hne' := (opow_mul_add_pos (zero_lt_one.trans hb).ne' u hv w).ne'\n  by_contra' hne\n  cases' lt_or_gt_of_ne hne with h h\n  \u00b7 rw [\u2190 lt_opow_iff_log_lt hb hne'] at h\n    exact h.not_le ((le_mul_left _ (Ordinal.pos_iff_ne_zero.2 hv)).trans (le_add_right _ _))\n  \u00b7 conv at h => change u < log b (b ^ u * v + w)\n    rw [\u2190 succ_le_iff, \u2190 opow_le_iff_le_log hb hne'] at h\n    exact (not_lt_of_le h) (opow_mul_add_lt_opow_succ hvb hw)\n#align ordinal.log_opow_mul_add Ordinal.log_opow_mul_add\n\ntheorem log_opow {b : Ordinal} (hb : 1 < b) (x : Ordinal) : log b (b^x) = x := by\n  convert log_opow_mul_add hb zero_ne_one.symm hb (opow_pos x (zero_lt_one.trans hb))\n    using 1\n  rw [add_zero, mul_one]\n#align ordinal.log_opow Ordinal.log_opow\n\ntheorem div_opow_log_pos (b : Ordinal) {o : Ordinal} (ho : o \u2260 0) : 0 < o / (b^log b o) :=\n  by\n  rcases eq_zero_or_pos b with (rfl | hb)\n  \u00b7 simpa using Ordinal.pos_iff_ne_zero.2 ho\n  \u00b7 rw [div_pos (opow_ne_zero _ hb.ne')]\n    exact opow_log_le_self b ho\n#align ordinal.div_opow_log_pos Ordinal.div_opow_log_pos\n\ntheorem div_opow_log_lt {b : Ordinal} (o : Ordinal) (hb : 1 < b) : o / (b^log b o) < b := by\n  rw [div_lt (opow_pos _ (zero_lt_one.trans hb)).ne', \u2190 opow_succ]\n  exact lt_opow_succ_log_self hb o\n#align ordinal.div_opow_log_lt Ordinal.div_opow_log_lt\n\ntheorem add_log_le_log_mul {x y : Ordinal} (b : Ordinal) (hx : x \u2260 0) (hy : y \u2260 0) :\n    log b x + log b y \u2264 log b (x * y) := by\n  by_cases hb : 1 < b\n  \u00b7 rw [\u2190 opow_le_iff_le_log hb (mul_ne_zero hx hy), opow_add]\n    exact mul_le_mul' (opow_log_le_self b hx) (opow_log_le_self b hy)\n  -- Porting note: `le_refl` is required.\n  simp only [log_of_not_one_lt_left hb, zero_add, le_refl]\n#align ordinal.add_log_le_log_mul Ordinal.add_log_le_log_mul\n\n/-! ### Interaction with `nat.cast` -/\n\n@[simp, norm_cast]\ntheorem nat_cast_opow (m : \u2115) : \u2200 n : \u2115, ((m ^ n : \u2115) : Ordinal) = (m^n)\n  | 0 => by simp\n  | n + 1 => by\n    rw [pow_succ', nat_cast_mul, nat_cast_opow m n, Nat.cast_succ, add_one_eq_succ, opow_succ]\n#align ordinal.nat_cast_opow Ordinal.nat_cast_opow\n\ntheorem sup_opow_nat {o : Ordinal} (ho : 0 < o) : (sup fun n : \u2115 => o^n) = (o^\u03c9) := by\n  rcases lt_or_eq_of_le (one_le_iff_pos.2 ho) with (ho\u2081 | rfl)\n  \u00b7 exact (opow_isNormal ho\u2081).apply_omega\n  \u00b7 rw [one_opow]\n    refine' le_antisymm (sup_le fun n => by rw [one_opow]) _\n    convert le_sup (fun n : \u2115 => 1^n) 0\n    rw [Nat.cast_zero, opow_zero]\n#align ordinal.sup_opow_nat Ordinal.sup_opow_nat\n\nend Ordinal\n\n-- Porting note: TODO: Port this meta code.\n\n-- namespace Tactic\n\n-- open Ordinal Mathlib.Meta.Positivity\n\n-- /-- Extension for the `positivity` tactic: `ordinal.opow` takes positive values on positive\n-- inputs. -/\n-- @[positivity]\n-- unsafe def positivity_opow : expr \u2192 tactic strictness\n--   | q(@Pow.pow _ _ $(inst) $(a) $(b)) => do\n--     let strictness_a \u2190 core a\n--     match strictness_a with\n--       | positive p => positive <$> mk_app `` opow_pos [b, p]\n--       | _ => failed\n--   |-- We already know that `0 \u2264 x` for all `x : ordinal`\n--     _ =>\n--     failed\n-- #align tactic.positivity_opow Tactic.positivity_opow\n\n-- end Tactic\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/SetTheory/Ordinal/Exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7042579224460452}}
{"text": "/- Inductive Type \n\n    inductive Foo where\n      | constructor\u2081 : ... \u2192 Foo\n      | constructor\u2082 : ... \u2192 Foo\n      ...\n      | constructor\u2099 : ... \u2192 Foo\n-/\n\n/- Enumerated Types -/\n\nnamespace ent \n  inductive Weekday where \n  | monday :  Weekday\n  | tuesday : Weekday \n  deriving Repr \n\n  #eval Weekday.monday\n\n  #check Weekday.monday \n\n  def Weekday.numerOfDay (d : Weekday) : Nat := \n    match d with \n    | monday => 1 \n    | tuesday => 2\n  \n  #eval Weekday.monday.numerOfDay -- 1\n\n  def Weekday.next (d : Weekday) : Weekday := \n    match d with \n    | monday => tuesday\n    | tuesday => monday\n\n  def Weekday.prev (d : Weekday) : Weekday := \n    match d with \n    | monday => tuesday\n    | tuesday => monday\n\n  example (d : Weekday) : d.next.prev = d := by \n    cases d <;> rfl \n\n  namespace hidden\n    inductive Bool where\n    | True \n    | False \n    deriving Repr\n\n    def Bool.and (p q : Bool) : Bool :=\n      match p with \n      | True => q \n      | False => False \n\n    #eval Bool.and Bool.True Bool.False -- False\n    #eval Bool.and Bool.True Bool.True -- True\n\n    def Bool.or (p q : Bool) : Bool := \n      match p with \n      | True => True \n      | False => q\n\n    #eval Bool.or Bool.True Bool.False -- True\n    #eval Bool.or Bool.True Bool.True -- True\n    #eval Bool.or Bool.False Bool.False -- True\n\n    def Bool.not (p : Bool) : Bool :=\n      match p with\n      | True => False \n      | False => True\n\n    #eval Bool.not Bool.True -- False\n\n  end hidden\n\nend ent\n\n\n/- Constructors w Arguments -/\n\nnamespace cwa \n  namespace hidden\n    inductive Prod (\u03b1 : Type u) (\u03b2 : Type v) \n    | mk : \u03b1 \u2192 \u03b2 \u2192 Prod \u03b1 \u03b2 \n\n    inductive Sum (\u03b1 : Type u) (\u03b2 : Type v) where \n    | inl : \u03b1 \u2192 Sum \u03b1 \u03b2 \n    | inr : \u03b2 \u2192 Sum \u03b1 \u03b2 \n\n    def fst {\u03b1 : Type u} {\u03b2 : Type v} (p : Prod \u03b1 \u03b2) : \u03b1 := \n      match p with \n      | Prod.mk a b => a \n\n    def snd {\u03b1 : Type u} {\u03b2 : Type v} (p : Prod \u03b1 \u03b2) : \u03b2 := \n      match p with \n      | Prod.mk a b => b \n  end hidden\n\n  def prod_example (p : Bool \u00d7 Nat) : Nat := \n    Prod.casesOn (motive := fun _ => Nat) p (fun b n => cond b (2*n) (2*n+1))\n\n  #eval prod_example (true, 3) -- 6 \n  #eval prod_example (false, 1) -- 3\n\n  def sum_example (s : Sum Nat Nat) : Nat := \n    Sum.casesOn (motive := fun _ => Nat) s\n      (fun n => 2 * n)\n      (fun n => 2 * n + 1)\n\n  #eval sum_example (Sum.inl 3) -- 6 \n  #eval sum_example (Sum.inr 3) -- 7\n\n\n  structure Semigroup where \n    carrier : Type u \n    mul : carrier \u2192 carrier \u2192 carrier \n    mul_assoc : \u2200 a b c, mul (mul a b) c = mul a (mul b c)\n\n  namespace hidden \n    inductive Sigma {\u03b1 : Type u} (\u03b2 : \u03b1 \u2192 Type v) where \n    | mk : (a : \u03b1) \u2192 \u03b2 a \u2192 Sigma \u03b2 \n\n    inductive Option (\u03b1 : Type u) where \n    | none : Option \u03b1 \n    | some : \u03b1 \u2192 Option \u03b1 \n\n    inductive Inhabited (\u03b1 : Type u) where \n    | mk : \u03b1 \u2192 Inhabited \u03b1 \n  end hidden\nend cwa\n\n/- Inductively Defined Prop -/\n\nnamespace idp \n  namespace hidden \n    inductive False : Prop \n\n    inductive True : Prop where \n    | intro : True \n\n    inductive And (p q : Prop) : Prop where \n    | intro : p \u2192 q \u2192 And p q \n\n    inductive Or (p q : Prop) : Prop where \n    | inl : p \u2192 Or p q \n    | inr : q \u2192 Or p q \n\n    inductive Exists {\u03b1 : Type u} (p : \u03b1 \u2192 Prop) where \n    | intro : \u2200 (a : \u03b1), p a \u2192 Exists p \n  end hidden\nend idp \n\n\n/- Defining Natural Numbers -/\n\nnamespace dnn \n  namespace hidden \n    inductive Nat where \n    | zero : Nat \n    | succ : Nat \u2192 Nat\n    deriving Repr\n\n    /-\n    @Nat.rec : {motive : Nat \u2192 Sort u_1} \u2192\n      motive Nat.zero \u2192 ((a : Nat) \u2192 motive a \u2192 motive (Nat.succ a)) \u2192 (t : Nat) \u2192 motive t\n    -/\n    #check @Nat.rec \n\n    /-\n    @Nat.recOn :\n      {motive : Nat \u2192 Sort u}\n      \u2192 (t : Nat)\n      \u2192 motive Nat.zero\n      \u2192 ((n : Nat) \u2192 motive n \u2192 motive (Nat.succ n))\n      \u2192 motive t\n    -/\n\n    def Nat.add (m n : Nat) : Nat := \n      match n with \n      | zero => m\n      | succ n' => Nat.succ (add m n')\n\n    #eval Nat.add (Nat.succ Nat.zero) Nat.zero -- succ zero\n    #eval Nat.add (Nat.succ Nat.zero) (Nat.succ Nat.zero) -- succ (succ zero)\n  end hidden\n\n  namespace hidden2\n    open Nat \n    theorem zero_add (n: Nat) : 0 + n = n := \n      Nat.recOn (motive := fun x => 0 + x = x)\n        n \n        (show 0 + 0 = 0 from rfl)\n        (fun (n : Nat) (ih : 0 + n = n) => \n          show 0 + succ n = succ n from \n            calc\n              0 + succ n = succ (0 + n) := rfl \n              _ = succ n := by rw [ih])\n\n    theorem zero_add\u2081 (n: Nat) : 0 + n = n := \n      Nat.recOn (motive:= fun x => 0 + x = x) n\n        (by rfl)\n        (fun n ih => by simp only [add_succ, *])\n\n    theorem add_assoc (m n k : Nat) : (m + n) + k = m + (n + k) := \n      Nat.recOn (motive := fun x => (m + n) + x = m + (n + x)) k\n        (show (m + n) + 0 = m + (n + 0) by rfl)\n        (fun k ih => by \n          calc \n            (m + n) + succ k = succ ((m + n) + k) := by rfl \n            _ = succ (m + (n + k)) := by rw [ih])\n    \n    theorem succ_add (m n : Nat) : succ n + m = succ (n + m) := \n      Nat.recOn (motive := fun x => succ n + x = succ (n + x)) m \n        (by rfl)\n        (fun m ih => by simp only [add_succ, *])\n      \n    theorem add_comm (m n : Nat) : m + n = n + m := \n      Nat.recOn (motive := fun x => m + x = x + m) n \n        (by simp [zero_add])\n        (fun n ih => by calc \n          m + succ n = succ (m + n) := by rfl\n          _ = succ (n + m) := by rw [ih]\n          _ = succ n + m := by simp only [succ_add]) \n  end hidden2\nend dnn\n\n/- Other Recursive Data Types -/\n\nnamespace ordt \n  namespace hidden \n    /- List -/\n    inductive List (\u03b1 : Type u) where \n    | nil : List \u03b1 \n    | cons : \u03b1 \u2192 List \u03b1 \u2192 List \u03b1 \n\n    def List.append (as bs : List \u03b1) : List \u03b1 := \n    match as with\n    | nil => bs \n    | cons a as' => cons a (append as' bs) \n\n    theorem List.nil_append (as : List \u03b1) : List.append List.nil as = as := \n      by rfl \n\n    theorem List.cons_append (a : \u03b1) (as bs : List \u03b1) \n        : cons a (append as bs) = append (cons a as) bs :=\n      by rfl \n\n    theorem List.append_nil (as : List \u03b1) : append as nil = as := \n      List.recOn (motive := fun x => append x nil = x) as \n        (by rfl)\n        (fun a as ih => by calc \n          append (cons a as) nil = cons a (append as nil) := by simp only [cons_append]\n          _ = cons a as := by rw [ih])\n\n    theorem List.append_assoc (as bs cs : List \u03b1) \n        : append (append as bs) cs = append as (append bs cs) := \n      List.recOn (motive := fun x => append (append x bs) cs = append x (append bs cs)) as \n        (by rfl)\n        (fun a as ih => by calc \n          append (append (cons a as) bs) cs = append (cons a (append as bs)) cs := by \n            simp only [cons_append]\n          _ = cons a (append (append as bs) cs) := by simp only [cons_append]\n          _ = cons a (append as (append bs cs)) := by simp [ih]\n          _ = append (cons a as) (append bs cs) := by simp only [cons_append])\n\n\n    def List.length (as : List \u03b1) : Nat := \n      match as with \n      | nil => 0 \n      | cons a as' => Nat.succ (length as')\n\n    theorem List.length_assoc (as bs : List \u03b1) \n        : length (append as bs) = length as + length bs := \n      List.recOn\n        (motive := fun x => length (append x bs) = length x + length bs)\n        as \n        (by simp only [length, nil_append, Nat.zero_add])\n        (fun a as ih => by calc \n          length (append (cons a as) bs) = length (cons a (append as bs)) := by\n            simp only [cons_append]\n          _ = Nat.succ (length (append as bs)) := by simp only [length]\n          _ = Nat.succ (length as + length bs) := by rw [ih]\n          _ = Nat.succ (length as) + length bs := by simp_arith\n          _ = length (cons a as) + length bs := by simp only [length])\n\n    \n    /- Binary Trees -/\n    inductive BinaryTree where \n    | leaf : BinaryTree\n    | node : BinaryTree \u2192 BinaryTree \u2192 BinaryTree \n\n    inductive CBTree where \n    | leaf : CBTree\n    | sup : (Nat \u2192 CBTree) \u2192 CBTree \n\n    def CBTree.succ (t : CBTree) : CBTree := \n      sup (fun _ => t)\n    \n    def CBTree.toCBTree : Nat \u2192 CBTree\n      | 0 => leaf \n      | n + 1 => succ (toCBTree n)\n\n  end hidden\nend ordt \n\n\n/- Tactics for Inductive Types -/\n\nnamespace tfit \n  example (p : Nat \u2192 Prop) (hz : p 0) (hs : \u2200 n, p (Nat.succ n)) : \u2200 n, p n := by \n    intro n \n    cases n\n    . assumption\n    . apply hs\n\n  example (n : Nat) (h : n \u2260 0) : Nat.succ (Nat.pred n) = n := by \n    cases n with \n    | zero => contradiction\n    | succ n' => rfl \n\n  example (p : Prop) (m n : Nat) (h1 : m < n \u2192 p) (h2 : m \u2265 n \u2192 p) : p := by \n    cases Nat.lt_or_ge m n \n    . case inl => apply h1; assumption\n    . case inr => apply h2; assumption\n\n  example (m n : Nat) : m - n = 0 \u2228 m \u2260 n := by \n    cases Decidable.em (m = n) with \n    | inl heq => rw [heq]; apply Or.inl; exact Nat.sub_self n\n    | inr => apply Or.inr; assumption \n\n  namespace hidden \n    open Nat\n    theorem zero_add (n : Nat) : 0 + n = n := by \n      induction n with\n      | zero => rfl \n      | succ n' ih => rw [add_succ, ih] \n  end hidden\n\n  /-\n  theorem Nat.mod.inductionOn\n        {motive : Nat \u2192 Nat \u2192 Sort u}\n        (x y  : Nat)\n        (ind  : \u2200 x y, 0 < y \u2227 y \u2264 x \u2192 motive (x - y) y \u2192 motive x y)\n        (base : \u2200 x y, \u00ac(0 < y \u2227 y \u2264 x) \u2192 motive x y)\n        : motive x y :=\n  -/\n  #check @Nat.mod_eq_sub_mod\n  example (x : Nat) {y : Nat} (h : y > 0) : x % y < y := by \n    induction x, y using Nat.mod.inductionOn with \n    | ind x y h1 ih => \n      rw [Nat.mod_eq_sub_mod h1.right]\n      exact ih h \n    | base x y h1 =>\n      have : \u00ac 0 < y \u2228 \u00ac y \u2264 x := Iff.mp (Decidable.not_and_iff_or_not ..) h1\n      match this with \n      | Or.inl _ => contradiction\n      | Or.inr _ => \n        have : y > x := by apply Nat.gt_of_not_le; assumption \n        rw [\u2190 Nat.mod_eq_of_lt this] at this\n        assumption\n\n  example :\n      (fun (x : Nat \u00d7 Nat) (y : Nat \u00d7 Nat) => x.1 + y.2)\n      =\n      (fun (x : Nat \u00d7 Nat) (z : Nat \u00d7 Nat) => z.2 + x.1) := by\n    funext (a, b) (c, d)\n    show a + d = d + a\n    rw [Nat.add_comm]\n\n  example (m n k : Nat) (h : m.succ.succ = n.succ.succ)\n      : n + k = m + k := by \n    injection h with h' -- m.succ = n.succ\n    injection h' with h'' -- m = n\n    rw [h'']\n\n  namespace hidden \n    inductive Vector (\u03b1 : Type u) : Nat \u2192 Type u where \n    | nil : Vector \u03b1 0\n    | cons : \u03b1 \u2192 {n : Nat} \u2192 Vector \u03b1 n \u2192 Vector \u03b1 (n + 1)\n    deriving Repr\n\n    #eval Vector.cons 1 (Vector.nil)\n\n    inductive Eq {\u03b1 : Sort u} (a : \u03b1) : \u03b1 \u2192 Prop where \n    | refl {} : Eq a a\n\n    /-\n    @Eq.recOn : {\u03b1 : Sort u_2} \u2192\n      {a : \u03b1} \u2192\n        {motive : (a_1 : \u03b1) \u2192 Eq a a_1 \u2192 Sort u_1} \u2192 {a_1 : \u03b1} \u2192 (t : Eq a a_1) \u2192 motive a (_ : Eq a a) \u2192 motive a_1 t\n    -/\n    #check @Eq.recOn\n\n\n    /-\n    @Eq.rec : {\u03b1 : Sort u_2} \u2192\n      {a : \u03b1} \u2192\n        {motive : (a_1 : \u03b1) \u2192 Eq a a_1 \u2192 Sort u_1} \u2192 motive a (_ : Eq a a) \u2192 {a_1 : \u03b1} \u2192 (t : Eq a a_1) \u2192 motive a_1 t\n    -/\n    #check @Eq.rec \n\n    theorem Eq.subst {\u03b1 : Type u} {a b : \u03b1} {p : \u03b1 \u2192 Prop} \n        (h1 : Eq a b) (h2 : p a) : p b := \n      Eq.rec (motive := fun x _ => p x) h2 h1 \n\n    theorem Eq.subst\u2081 {\u03b1 : Type u} {a b : \u03b1} {p : \u03b1 \u2192 Prop} \n        (h1 : Eq a b) (h2 : p a) : p b := \n      match h1 with \n      | refl a => h2\n\n    theorem Eq.symm {\u03b1 : Type u} {a b : \u03b1} (h : Eq a b) : Eq b a := \n      match h with \n      | refl a => refl a\n\n    theorem Eq.trans {\u03b1 : Type u} {a b c : \u03b1} (h1 : Eq a b) (h2 : Eq b c)\n        : Eq a c := \n      match h1, h2 with \n      | refl a, refl a => refl a\n\n    theorem Eq.congr {\u03b1 \u03b2 : Type u} {a b : \u03b1} (f : \u03b1 \u2192 \u03b2) (h : Eq a b)\n        : Eq (f a) (f b) := \n      match h with \n      | refl a => refl (f a) \n  end hidden \nend tfit\n\n\n/- Mutual and Nested Inductive Types -/\n\nnamespace munit \n\n  mutual  \n    inductive Even : Nat \u2192 Prop where \n    | even_zero : Even 0 \n    | even_succ : (n : Nat) \u2192 Odd n \u2192 Even (n + 1)\n\n    inductive Odd : Nat \u2192 Prop where \n    | odd_succ : (n : Nat) \u2192 Even n \u2192 Odd (n + 1)\n  end \n\n  inductive Tree (\u03b1 : Type u) where \n  | mk : \u03b1 \u2192 List (Tree \u03b1) \u2192 Tree \u03b1 \nend munit ", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/TheoremProvingLean/inductive_types.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7042579202200517}}
{"text": "import combinatorics.simple_graph.coloring\n\n\n--OUTPUT 1\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  -- Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color.\n  have h1 : (G.colorable 2) \u2192 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from\n    begin\n      -- Let $G$ be a 2-colorable graph\n      assume h2 : (G.colorable 2),\n      -- which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color.\n      have h3 : \u2203 (c : V \u2192 fin 2), (\u2200 v w : V, G.E v w \u2192 c v \u2260 c w), from by auto [h2, simple_graph.colorable],\n      obtain (c : V \u2192 fin 2) (h3 : (\u2200 v w : V, G.E v w \u2192 c v \u2260 c w)), from h3,\n      -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n      -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n      have h4 : (\u2200 (v : V), (c v = 0) \u2192 (\u2200 (w : V), (c w = 0) \u2192 (G.E v w \u2192 false))) \u2227 (\u2200 (v : V), (c v = 1) \u2192 (\u2200 (w : V), (c w = 1) \u2192 (G.E v w \u2192 false))), from by auto [h3],\n      obtain (h4 : (\u2200 (v : V), (c v = 0) \u2192 (\u2200 (w : V), (c w = 0) \u2192 (G.E v w \u2192 false))) \u2227 (\u2200 (v : V), (c v = 1) \u2192 (\u2200 (w : V), (c w = 1) \u2192 (G.E v w \u2192 false)))), from h4,\n      -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n      have h5 : \u2200 (v w : V), (G.E v w \u2192 (c v \u2260 c w)), from by auto [h3],\n      have h6 : \u2200 (v w : V), (G.E v w \u2192 (c v = 0 \u2192 c w = 1)), from by auto [h5],\n      have h7 : \u2200 (v w : V), (G.E v w \u2192 (c v = 1 \u2192 c w = 0)), from by auto [h5],\n      -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n      let A := {v : V | c v = 0},\n      let B := {v : V | c v = 1},\n      -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n      have h8 : \u2200 (v w : V), (G.E v w \u2192 ((v \u2208 A) \u2227 (w \u2208 B) \u2228 (v \u2208 B) \u2227 (w \u2208 A))), from by auto [h6, h7],\n      have h9 : G \u2264 complete_bipartite_graph A B, from by auto [h8],\n      have h10 : (A \u2295 B) = V, from by auto [set.ext, sum.ext],\n      show \u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h10, h9],\n    end,\n\n  --Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$.\n  have h2 : (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) \u2192 (G.colorable 2), from\n    begin\n      -- Suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$.\n      assume h3 : (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)),\n      obtain (A B : Type*) (h : (A \u2295 B) = V) (h3 : G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from h3,\n      have h4 : \u2200 (v w : V), (G.E v w \u2192 ((v \u2208 A) \u2227 (w \u2208 B) \u2228 (v \u2208 B) \u2227 (w \u2208 A))), from by auto [h3],\n      -- Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n      let c : V \u2192 fin 2 := \u03bb (v : V), if v \u2208 A then 0 else 1,\n      have h5 : \u2200 (v w : V), (G.E v w \u2192 (c v \u2260 c w)), from by auto [h4],\n      show (G.colorable 2), from by auto [h5, simple_graph.colorable],\n    end,\n\n  show (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from by auto [h1, h2],\nend\n\n--OUTPUT 2\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  -- Suppose $G$ is 2-colorable, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  assume h1 : G.colorable 2,\n  have h2 : \u2203 A B : Type*, (A \u2295 B) = V \u2227 G \u2264 cast (congr_arg _ (decidable.by_cases (\u03bb (x : V), x \u2208 A) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 A) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3))) (\u03bb (x : V), x \u2208 B) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 B) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3))) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 A) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 B) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 A) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 B) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 A) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 B) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 A) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 B) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 A) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inl h6)) (\u03bb (h5 : V), (\u03bb (h6 : A) (h7 : B), (\u03bb (h8 : A \u2295 B), h5) (sum.inr h7)))) h3)) (\u03bb (h3 : V), \u27e8\u03bb (h4 : V), (\u03bb (x : V), x \u2208 B) (fintype.complete.1 (fintype.of_equiv_card_of_injective (equiv.decidable_eq V)\nend --Needs more than 2000 tokens!\n\n--OUTPUT 3\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  -- Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  have h1 : (G.colorable 2) \u2192 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from begin\n    assume h,\n    -- coloring every vertex of $V$ as red or blue\n    let \u03ba : V \u2192 fin 2 := \u03bb v, (if (\u2203 (w : V), G.adj v w) then 1 else 0),\n    -- coloring every vertex of $V$ as red or blue\n    have h1 : \u2200 v : V, \u03ba v = 0 \u2228 \u03ba v = 1, from by auto [nat.one_le_iff_ne_zero],\n    -- coloring every vertex of $V$ as red or blue\n    have h2 : \u2200 v : V, \u03ba v < 2, from by auto [lt_succ_self, nat.one_le_iff_ne_zero],\n    have h3 : \u2200 v : V, \u03ba v \u2208 finset.range 2, from by auto [h2],\n    have h4 : (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from begin\n      let \u03ba1 : fin 2 \u2192 V := \u03bb f, finset.choose (finset.range 2) f,\n      have h5 : \u2200 f : fin 2, \u03ba1 f \u2208 finset.range 2, from by auto [finset.choose_mem],\n      have h6 : \u2200 v : V, \u03ba v = 0 \u2227 \u03ba1 (0 : fin 2) = v \u2228 \u03ba v = 1 \u2227 \u03ba1 (1 : fin 2) = v, from by auto [h1, h5],\n      have h7 : \u2200 v : V, \u03ba v = 0 \u2192 \u03ba1 (0 : fin 2) = v, from by auto [h6],\n      have h8 : \u2200 v : V, \u03ba v = 1 \u2192 \u03ba1 (1 : fin 2) = v, from by auto [h6],\n      have h9 : \u2200 v : V, \u03ba v = 0 \u2192 \u2200 w : V, G.adj v w \u2192 \u03ba1 (0 : fin 2) \u2260 w, from begin\n        assume v : V,\n        assume h9 : \u03ba v = 0,\n        assume w : V,\n        assume h10 : G.adj v w,\n        have h11 : \u03ba w = 1, from by auto [h],\n        have h12 : \u03ba1 (1 : fin 2) = w, from by auto [h8],\n        have h13 : \u03ba1 (0 : fin 2) \u2260 \u03ba1 (1 : fin 2), from by auto [finset.choose_eq_of_mem finset.mem_range_self finset.mem_range_self],\n        show \u03ba1 (0 : fin 2) \u2260 w, from by auto [h13, h12],\n      end,\n      have h10 : \u2200 v : V, \u03ba v = 1 \u2192 \u2200 w : V, G.adj v w \u2192 \u03ba1 (1 : fin 2) \u2260 w, from begin\n        assume v : V,\n        assume h9 : \u03ba v = 1,\n        assume w : V,\n        assume h10 : G.adj v w,\n        have h11 : \u03ba w = 0, from by auto [h],\n        have h12 : \u03ba1 (0 : fin 2) = w, from by auto [h7],\n        have h13 : \u03ba1 (0 : fin 2) \u2260 \u03ba1 (1 : fin 2), from by auto [finset.choose_eq_of_mem finset.mem_range_self finset.mem_range_self],\n        show \u03ba1 (1 : fin 2) \u2260 w, from by auto [h13, h12],\n      end,\n      have h11 : \u2200 v w : V, G.adj v w \u2192 \u03ba v \u2260 \u03ba w, from by auto [h9, h10],\n      have h12 : \u2200 (v w : V) (f : fin 2), \u03ba v = f \u2192 \u03ba w = f \u2192 (v = w), from begin\n        assume v w : V,\n        assume f : fin 2,\n        assume h12 : \u03ba v = f,\n        assume h13 : \u03ba w = f,\n        have h14 : \u03ba v \u2260 \u03ba w, from by auto [h11, G.adj_symm],\n        show v = w, from by auto [h12, h13, h14],\n      end,\n      have h13 : \u2200 v : V, \u03ba v = 0 \u2192 \u03ba1 (0 : fin 2) = v, from by auto [h7],\n      have h14 : \u2200 v : V, \u03ba v = 1 \u2192 \u03ba1 (1 : fin 2) = v, from by auto [h8],\n      have h15 : \u2200 v : V, \u03ba v = 0 \u2192 \u03ba v \u2260 1, from by auto [nat.one_le_iff_ne_zero],\n      have h16 : \u2200 v : V, \u03ba v = 1 \u2192 \u03ba v \u2260 0, from by auto [nat.one_le_iff_ne_zero],\n      have h17 : \u2200 v : V, \u03ba v \u2260 1 \u2192 \u03ba v = 0, from by auto [h15],\n      have h18 : \u2200 v : V, \u03ba v \u2260 0 \u2192 \u03ba v = 1, from by auto [h16],\n      have h19 : \u2200 v : V, \u03ba v = 0 \u2192 \u03ba1 (0 : fin 2) = v \u2227 \u03ba1 (1 : fin 2) \u2260 v, from by auto [h13, h18],\n      have h20 : \u2200 v : V, \u03ba v = 1 \u2192 \u03ba1 (1 : fin 2) = v \u2227 \u03ba1 (0 : fin 2) \u2260 v, from by auto [h14, h17],\n      have h21 : \u2200 v : V, \u03ba v = 0 \u2227 \u03ba1 (1 : fin 2) \u2260 v \u2228 \u03ba v = 1 \u2227 \u03ba1 (0 : fin 2) \u2260 v, from by auto [h19, h20],\n      have h22 : \u2200 v : V, \u03ba1 (0 : fin 2) \u2260 v \u2192 \u03ba v = 1, from by auto [h21],\n      have h23 : \u2200 v : V, \u03ba1 (1 : fin 2) \u2260 v \u2192 \u03ba v = 0, from by auto [h21],\n      have h24 : \u2200 v : V, \u03ba v = 0 \u2192 \u03ba1 (0 : fin 2) = v \u2227 \u03ba1 (1 : fin 2) \u2260 v, from by auto [h19],\n      have h25 : \u2200 v : V, \u03ba v = 1 \u2192 \u03ba1 (1 : fin 2) = v \u2227 \u03ba1 (0 : fin 2) \u2260 v, from by auto [h20],\n      have h26 : \u2200 v : V, \u03ba v = 0 \u2227 \u03ba1 (1 : fin 2) \u2260 v \u2228 \u03ba v = 1 \u2227 \u03ba1 (0 : fin 2) \u2260 v, from by auto [h24, h25],\n      have h27 : \u2200 v : V, \u03ba1 (0 : fin 2) \u2260 v \u2192 \u03ba v = 1, from by auto [h26],\n      have h28 : \u2200 v : V, \u03ba1 (1 : fin 2) \u2260 v \u2192 \u03ba v = 0, from by auto [h26],\n      have h29 : \u2200 v : V, \u03ba v = 0 \u2192 \u03ba1 (0 : fin 2) = v \u2227 \u03ba1 (1 : fin 2) \u2260 v, from by auto [h19],\n      have h30\nend --Needs more than 2000 tokens!\n\n--OUTPUT 4\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  -- A simple graph G is 2-colorable if and only if G is bipartite\n  have h1 : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from by auto,\n  show (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from by auto [h1],\nend\n\n--OUTPUT 5\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  assume h1, \n  -- $G$ is 2-colorable\n  from \u27e8_, _, _, _, _\u27e9,\n  { -- Let $A$ denote the subset of vertices colored red and let $B$ denote the subset of vertices colored blue\n    let A : Type* := {v : V | (G.is_vertex v) \u2227 (G.color v = 0)},\n    let B : Type* := {v : V | (G.is_vertex v) \u2227 (G.color v = 1)},\n    -- Then $A \u2295 B = V$\n    have h2 : (A \u2295 B) = V, from by auto [subtype.eq, set.subset_def, set.ext],\n    -- Then $A$ and $B$ are disjoint\n    have h3 : \u2200 x y : V, x \u2208 A \u2192 y \u2208 B \u2192 x \u2260 y, from by auto [subtype.ext, G.color_prop, G.is_vertex_prop, G.not_adjacent, G.adj_iff_adj'],\n    -- Then $G \u2264 cast (congr_arg _ h2) (complete_bipartite_graph A B)$\n    have h4 : G \u2264 cast (congr_arg _ h2) (complete_bipartite_graph A B), from by auto [G.adj_iff_adj', complete_bipartite_graph_def, G.color_prop, G.is_vertex_prop, G.not_adjacent, G.adj_iff_adj', complete_bipartite_graph_def, G.is_vertex_prop, G.color_prop, h3, complete_bipartite_graph_def, h2, cast_congr],\n    -- Hence $G$ is a bipartite graph\n    show \u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h2, h4],\n  },\n  { -- Let $A$ and $B$ be disjoint subsets of $V$\n    assume (A : Type*) (B : Type*) (h2 : (A \u2295 B) = V), \n    assume h3 : G \u2264 cast (congr_arg _ h2) (complete_bipartite_graph A B),\n    -- Then $G$ is bipartite\n    -- Then coloring every vertex of $A$ red and every vertex of $B$ blue yields a valid coloring, so $G$ is 2-colorable\n    have h4 : \u2200 v : V, (\u2203 (c : fin 2) (h4 : G.color v = c), true), from by auto [G.color_prop, h3, complete_bipartite_graph_def, G.color_prop, G.is_vertex_prop, G.not_adjacent, G.adj_iff_adj', complete_bipartite_graph_def, G.is_vertex_prop, G.color_prop, h3, complete_bipartite_graph_def, h2, cast_congr],\n    show G.colorable 2, from by auto [G.colorable_def, h4],\n  },\nend\n\n--OUTPUT 6\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  -- Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color.\n  have h1 : (G.colorable 2) \u2192 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from sorry,\n  -- Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$. Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n  have h2 : (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) \u2192 (G.colorable 2), from sorry,\n  from iff.intro h1 h2,\nend\n\n--OUTPUT 7\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  -- Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  sorry\nend\n\n--OUTPUT 8\ntheorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nbegin\n  -- if G is 2-colorable then G is bipartite\n  have h1 : (G.colorable 2) \u2192 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from\n  begin\n    assume h,\n    -- coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable\n    have h1 : \u2203 (V1 V2 : Type*) (h : (V1 \u2295 V2) = V), (G.colorable 2), from by auto [h],\n    -- let A denote the subset of vertices colored red, and let B denote the subset of vertices colored blue\n    have h2 : \u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h1],\n    show \u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h2],\n  end,\n  -- if G is bipartite then G is 2-colorable\n  have h2 : (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) \u2192 (G.colorable 2), from\n  begin\n    assume h,\n    -- let V1, V2 denote the subsets of vertices of A, B\n    have h1 : \u2203 (V1 V2 : Type*) (h : (V1 \u2295 V2) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph V1 V2), from by auto [h],\n    -- coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable\n    have h2 : (G.colorable 2), from by auto [h1],\n    show (G.colorable 2), from by auto [h2],\n  end,\n  show (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)), from by auto [h1, h2, iff.intro],\nend\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  -- Then $A \u2286 S$ and $B \u2286 S$, by power set definition\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],\n  -- Then $(A \u2229 B) \u2286 A$, by intersection of set is a subset\n  have h2 : (A \u2229 B) \u2286 A, from by auto [set.inter_subset_left],\n  -- Then $(A \u2229 B) \u2286 S$, by subset relation is transitive \n  have h3 : (A \u2229 B) \u2286 S, from by auto [set.subset.trans],\n  -- Hence $(A \u2229 B) \u2208  \ud835\udcab S$, by power set definition\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by auto [set.mem_powerset],\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  -- expand the power\n  calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]\n  -- distributive property of multiplication over addition gives:\n  ... = x*(x+y) + y*(x+y) : by auto [add_mul]\n  -- applying the above property further gives:\n  ... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]\n  -- rearranging the terms using commutativity and adding gives:\n  ... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring]\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  -- Group has Latin Square Property\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by auto using [use (a\u207b\u00b9 * b)],\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by auto using [use b * a\u207b\u00b9], \n\n  -- Setting $b = a$, this becomes:\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from by auto [h1],\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from by auto [h2],\n\n  -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one],\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul],\n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)],\nend\n\n/--`theorem`\nBipartite Graph is two colorable\nLet $G$ be a graph. Then $G$ is 2-colorable if and only if $G$ is bipartite.\n`proof`\nLet $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n\nConversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$. Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n\nQED\n\n-/\ntheorem  bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) \u2194 (\u2203 (A B : Type*) (h : (A \u2295 B) = V), G \u2264 cast (congr_arg _ h) (complete_bipartite_graph A B)) :=\nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_auto_with_comments-Natural-Language-Proof-Translation/Correct_statement-lean_proof_auto_with_comments-3_few_shot_temperature_0.6_max_tokens_2000_n_8/clean_files/Bipartite Graph is two colorable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7042257682566996}}
{"text": "variable {p q r s: Prop}\n#check And p q\n#check Or (And p q) r\n#check p \u2192 r\n\ntheorem t1' : p \u2192 q \u2192 p := \nfun hp : p => \nfun hq : q => \nshow p from hp\n\n#print t1'\n\ntheorem t1 (p q : Prop)(hp: p) (hq : q) : p := hp\n\naxiom hp : p\n\naxiom unsound : False\n-- Everything follows from false (principle of explosion)\ntheorem ex : 1 = 0 :=\n  False.elim unsound\n\n#check t1 p q\n#check t1 (r \u2192 p) (p \u2192 q)\n\nvariable (h : r \u2192 s) \n#check t1 (r \u2192 s) (s \u2192 r) h\n\ntheorem t2 (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q) : p \u2192 r :=\n  fun h\u2083 : p =>\n  show r from h\u2081 (h\u2082 h\u2083)  \n\n\n\n\n", "meta": {"author": "daniabib", "repo": "lean-theorem-proving", "sha": "a4d5087648d526f420ea38b11ce9066ca46e672e", "save_path": "github-repos/lean/daniabib-lean-theorem-proving", "path": "github-repos/lean/daniabib-lean-theorem-proving/lean-theorem-proving-a4d5087648d526f420ea38b11ce9066ca46e672e/03-PropositionsAndProofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984213, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7042257628549219}}
{"text": "import data.nat.basic\nimport data.nat.parity\nimport tactic\n\nopen nat\n\nexample : \u2200 m n : \u2115, even n \u2192 even (m * n) := \n  assume m n \u27e8k, (hk : n = k + k)\u27e9,\n  have hmn : m * n = (m * k) + (m * k) := by \n    simp [hk, mul_left_comm, mul_add],\n  show \u2203 l, m * n = l + l,\n    from Exists.intro _ hmn \n\nexample : \u2200 m n : \u2115, even n \u2192 even (m * n) := \n  \u03bb m n \u27e8k, hk\u27e9, \u27e8m * k, by rw [hk, mul_add]\u27e9  \n\nexample : \u2200 m n : \u2115, even n \u2192 even (m * n) := \nbegin \n  rintros m n \u27e8k, hk\u27e9,\n  -- \u22a2 even (m * k)\n  use m * k,\n  -- \u22a2 m * n = m * k + m + k\n  rw hk, \n  -- \u22a2 m * (k + k) = m * k + m * k\n  ring -- conmutative (semi)rings\nend\n\nexample : \u2200 m n : \u2115, even n \u2192 even (m * n) := \n  by intros; simp * with parity_simps \n\n\n\n", "meta": {"author": "ManuelAlejandroMartinezFlores", "repo": "LEAN_projects", "sha": "e60bda4bf3d9bbf4b958dd24641c97ac90da9514", "save_path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects", "path": "github-repos/lean/ManuelAlejandroMartinezFlores-LEAN_projects/LEAN_projects-e60bda4bf3d9bbf4b958dd24641c97ac90da9514/LEAN/src/mathematics_in_lean/01_Introduction/intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7042257556905878}}
{"text": "/-\nCopyright (c) 2022 Julian Kuelshammer. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Julian Kuelshammer\n-/\n\nimport hard_mode.sheet02\n\n\n/-! Real vector spaces\n\nThis file defines the concept of a real vector space (as is discussed in the first lecture of Linear Algebra II\nand proves that \u211d\u00b2 and Mat\u2082 are instances of it.)\n\nOne further ingredient could be useful: \n\ncalc expr_1 = expr_2 : begin sorry end\n       ...  = expr_3 : begin sorry end\n       ...  = expr_4 : begin sorry end\n\nFun fact: If you only work with calc, you don't have to switch to tactic mode, i.e. you can leave out the \nbegin ... end\n\nrw : rewrite one expression by another using a lemma. \n\napply : Apply a statement to reduce the goal. In ordinary mathematics you would read this as. By this theorem, \n        it suffices to prove the following ... \n\nexact : The goal that is to show is exactly the following lemma/theorem. \n\nnth_rewrite i _ : If you use rw, it will change the every occurrence of the term. Sometimes you only want to\n                  do that on a certain occurrence, that you can use nth_rewrite i to change it on the ith \n                  occurrence (starting counting with 0). \n\nconv_lhs begin ... end \nconv_rhs begin ... end : Solve a similar problem to the one before, they allow you to only rewrite the left or \n                         the right hand side of an equation. \n\nnorm_num : Similar to ring, but only calculates explicit expressions (with actual numbers.)\n-/\n\n/-- `real_vector_space V` is the type of real vector space structures on the type `V`. -/\nclass real_vector_space (V : Type)\n  extends has_zero V, has_add V, has_neg V, has_scalar \u211d V : Type :=\n(add_assoc : \u2200 u v w : V, (u + v) + w = u + (v + w))\n(add_comm : \u2200 u v : V, u + v = v + u)\n(add_zero : \u2200 v : V, v + 0 = v)\n(zero_add : \u2200 v : V, 0 + v = v)\n(add_neg : \u2200 v : V, v + (-v) = 0)\n(neg_add : \u2200 v : V, (-v) + v = 0)\n(smul_assoc : \u2200 (a b : \u211d) (v : V), (a * b) \u2022 v = a \u2022 (b \u2022 v))\n(one_smul : \u2200 v : V, (1 : \u211d) \u2022 v = v)\n(add_smul : \u2200 (a b : \u211d) (v : V), (a + b) \u2022 v = a \u2022 v + b \u2022 v)\n(smul_add : \u2200 (a : \u211d) (v w : V), a \u2022 (v + w) = a \u2022 v + a \u2022 w)\n\nnamespace real_vector_space\n\n/- We can also add the simp attribute to statements later. -/\nattribute [simp] add_assoc add_zero zero_add add_neg neg_add smul_assoc one_smul add_smul smul_add\n\nvariables {V : Type} [real_vector_space V] {u v w : V} {a b : \u211d}\n\n/- \nLet's first let Lean know that the plane and the 2x2-matrices are real vector spaces. We have proved \neverything on the previous two sheets, we just have to package it nicely.\n-/\n\ninstance : real_vector_space \u211d\u00b2 := \n_\n\ninstance : real_vector_space Mat\u2082 :=\n_\n\n/- \nWe continue by proving some well-known properties which hold in (real) vector spaces.\n-/\n\nlemma zero_unique_right_neutral (h : v + w = v)  :  w = 0 :=\nbegin\n  sorry\nend \n\nlemma zero_unique_left_neutral (h : w + v = v) : w = 0 :=\nbegin\n  sorry\nend\n\n\nlemma zero_smul_eq_zero_vector (v : V) : (0 : \u211d) \u2022 v = 0 :=\nbegin\n  sorry\nend\n\nlemma neg_unique_right_add_inv (h : v + w = 0) :  w = -v :=\nbegin\n  sorry\nend\n\nlemma neg_unique_left_add_inv (h : w + v = 0) : w = -v :=\nbegin\n  sorry\nend\n\nlemma minus_one_smul_eq_neg : (-1 : \u211d) \u2022 v = -v :=\nbegin\n  sorry\nend\n\nend real_vector_space\n\n/- It has been realised that the vector space axioms are not minimal, you can remove some of them and still \n  get the same structure. Here is a minimal list that has been found (which is quite similar to the standard \n  list, only the second axiom seems kind of weird.)-/\nclass minimal_vector_space_axioms (V : Type)\n  extends has_add V, has_scalar \u211d V : Type :=\n(add_assoc : \u2200 u v w : V, (u + v) + w = u + (v + w))\n(zero_smul_eq : \u2200 v w : V, (0 : \u211d) \u2022 v = (0 : \u211d) \u2022 w)\n(one_smul : \u2200 v : V, (1 : \u211d) \u2022 v = v)\n(smul_assoc : \u2200 (a b : \u211d) (v : V), (a * b) \u2022 v = a \u2022 (b \u2022 v))\n(add_smul : \u2200 (a b : \u211d) (v : V), (a + b) \u2022 v = a \u2022 v + b \u2022 v)\n(smul_add : \u2200 (a : \u211d) (v w : V), a \u2022 (v + w) = a \u2022 v + a \u2022 w)\n\n/- Note that in contrast to the vector space axioms, the axiom about the zero vector is omitted from these \n  minimal vector space axioms. However this means that there is no reason for any vector at all to exist \n  in `V`. So let's prove that the empty set satisfies these axioms. -/\ninstance : minimal_vector_space_axioms empty :=\n_\n\n/- Let's prove that any real_vector_space satisfies the minimal vector space axioms, which is not too difficult, '\n  there is only one axiom which is already included in the axioms and that is immediately true. -/\ndef to_minimal_vector_space_axioms (V : Type) [real_vector_space V] : minimal_vector_space_axioms V :=\n_\n\n/- In the other direction, the difference seems larger, so let's try to prove some of the axioms which are missing. -/\n\nlemma minimal_vector_space_axioms.add_zero (V : Type) [minimal_vector_space_axioms V] (v w : V) : v + (0 : \u211d) \u2022 w = v :=\nbegin \n  sorry\nend\n\nlemma minimal_vector_space_axioms.zero_add (V : Type) [minimal_vector_space_axioms V] (v w : V) : (0 : \u211d) \u2022 w + v = v :=\nbegin \n  sorry\nend\n\nlemma minimal_vector_space_axioms.add_neg (V : Type) [minimal_vector_space_axioms V] (v : V) : v + (-1 : \u211d) \u2022 v = (0 : \u211d) \u2022 v :=\nbegin \n  sorry\nend\n\nlemma minimal_vector_space_axioms.neg_add (V : Type) [minimal_vector_space_axioms V] (v : V) : (-1 : \u211d) \u2022 v + v = (0 : \u211d) \u2022 v :=\nbegin \n  sorry\nend\n\n/- The following is probably the most challenging one. Consider trying to prove it on paper first. -/\nlemma minimal_vector_space_axioms.add_comm (V : Type) [minimal_vector_space_axioms V] (v w : V) : v + w = w + v :=\nbegin\n  sorry\nend\n\n/- However if we demand that the set V is nonempty, the axioms are in fact equivalent as we show with the \n  following two results. These are `definitions` as they transport data. Often in a maths lecture we would \n  instead say `proposition` for this, or if one is very careful `definition-proposition`. The definition is \n  marked as `noncomputable` as it relies on choosing an arbitrary element `v` from the nonempty type `V`, \n  for which there might not be an algorithm. -/\nnoncomputable def to_real_vector_space (V : Type) [minimal_vector_space_axioms V] (h : nonempty V) : real_vector_space V :=\n_\n\n\n\n \n", "meta": {"author": "Julian-Kuelshammer", "repo": "summer_maths_it_camp", "sha": "09b17b78de1c4cb3536649a6030fc14b60b08d24", "save_path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp", "path": "github-repos/lean/Julian-Kuelshammer-summer_maths_it_camp/summer_maths_it_camp-09b17b78de1c4cb3536649a6030fc14b60b08d24/src/hard_mode/sheet03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772450055544, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7041847560743912}}
{"text": "import tactic.ring\n\n\n-- intermediate lemmas, many of which probably already existed\n-- always made inputs of type k explicit for clarity\n-- naming very random\n\ntheorem mul_eq_implies_mul_mul {k : Type} [field k] (a b c : k):\na=b \u2192 a*c = b*c := begin\nintro H, rw H\nend\n\ntheorem add_eq_implies_add_add {k : Type} [field k] (a b c : k):\na=b \u2192 a+c = b+c := begin\nintro H, rw H\nend\n\ntheorem move_sides {k : Type} [field k] (a b : k) :\na + b = 0 \u2192 a = - b :=\nbegin\nintro H,\nhave H\u2081 := @eq_of_add_eq_add_left k _ b a (-b),\nrw H\u2081, simp, exact H\nend\n\ntheorem eq_implies_sq_eq {k : Type} [field k] (a b : k) :\na = b \u2228 a = -b \u2192 a^2 = b^2 := begin\n\nintro H,\nunfold pow monoid.pow, simp,\ncases H;rw H,\nsimp\n\nend\n\ntheorem factorise_a_sq_minus_b_sq {k : Type} [field k] (a b : k) :\na^2 - b^2 = (a-b) * (a+b) := begin\nring\nend\n\ntheorem add_neg_eq_sub {k : Type} [field k] (a b : k) :\na + - (b) = a - b := begin\nrefl\nend\n\ntheorem sq_eq_implies_eq_or_neg_eq {k : Type} [field k] (a b : k) :\na^2 = b^2 \u2192 a = b \u2228 a = -b := begin\n\nintro H,\nhave rearrange_H := @add_eq_of_eq_add_neg k _ (a*a) (-(b*b)) 0,\nsimp at rearrange_H,\n\nrw \u2190pow_two at rearrange_H, rw \u2190pow_two at rearrange_H,\n\nrw add_neg_eq_sub (a^2) (b^2) at rearrange_H,\nrw factorise_a_sq_minus_b_sq at rearrange_H,\n\nrw H at rearrange_H, simp at rearrange_H,\n\nhave H_zero := @mul_eq_zero k _ (a +- b) (a + b),\nrw rearrange_H at H_zero, simp at H_zero,\ncases H_zero,\n{\n    rw add_neg_eq_zero at H_zero,\n    exact or.inl H_zero,\n},\n{\n    rw add_comm at H_zero,\n    rw add_eq_zero_iff_neg_eq at H_zero,\n    right,\n    exact H_zero.symm\n}\n\nend\n\ntheorem multiply_out_divide {k : Type} [field k] (a b c: k) (H_neq : c \u2260 0) :\na * c = b \u2192 a = b / c := begin\nintro H,\nhave H\u2081 :=  @eq_of_mul_eq_mul_left k _ c a (b/c) H_neq,\nrw H\u2081,\n--rw mul_comm c (b/c),\nrw mul_div_cancel' b H_neq,\nrw \u2190H,\nexact mul_comm c a\n\nend\n\n\n\ntheorem quad (k : Type) [field k] (a b c x S : k)\n(HS : S*S = b*b - 4*a*c) (char_not_2 : (2:k) \u2260 0) (a_not_0 : a \u2260 0) :\na * x*x + b * x + c = 0 \u2194 \n(x = (-b + S ) / (2*a) \u2228 \n x = (-b - S ) / (2*a)) := begin\n\nhave H\u2081  := @eq_zero_or_eq_zero_of_mul_eq_zero _ _ 2 a,\nhave H\u2082  : 2 * a \u2260 0,\n{\n    intro H\u2083,\n    cases H\u2081 H\u2083,\n    {\n        revert h,\n        exact char_not_2\n    },\n    {\n        revert h, exact a_not_0\n    }\n},\n\nclear H\u2081, clear a_not_0,\n\nsplit,\n-- ax^2 + bx + c = 0 \u2192 x=...\n{\n    intro H_main,\n\n    have H_equate_squares : (2*a*x + b)^2 = S^2,\n    {\n        rw pow_two,\n        rw pow_two,\n\n        rw HS,\n        repeat {rw mul_add},\n        repeat {rw add_mul},\n\n        simp,\n        have H_mul_comm : b * (2 * a * x) = 2 * a * x * b,{rw mul_comm},\n        rw H_mul_comm,\n        rw \u2190add_assoc,\n        rw \u2190mul_two (2*a*x*b),\n        ring,\n        have H_neg_mul_comm : -(4 * c * a) = -(4 * c) * a,{ring},\n        rw H_neg_mul_comm, clear H_neg_mul_comm,\n\n        have H_cancel_a :=\n        mul_eq_implies_mul_mul (4 * x ^ 2 * a + 4 * x * b) (-(4 * c)) a,\n        \n        apply H_cancel_a, clear H_cancel_a,\n        \n        rw \u2190mul_neg_eq_neg_mul_symm 4 c,\n        rw mul_assoc 4 x b,\n        rw mul_assoc 4 (x^2) a,\n        rw \u2190mul_add 4 (x^2*a) (x*b),\n        congr,\n        unfold pow monoid.pow, simp,\n\n        have H_move_sides :=\n        move_sides (x * b + x * x * a) c,\n        rw H_move_sides, clear H_move_sides,\n\n        --lots of shuffling about to get the goal to look like H_main\n        \n        rw add_comm,\n        rw \u2190pow_two,\n        rw mul_comm,\n        rw mul_comm (x^2) a,\n        \n        simp at H_main,\n\n        rw pow_two,\n\n        rw mul_assoc a x x at H_main,\n        exact H_main\n    },\n\n    have H_sq_eq := sq_eq_implies_eq_or_neg_eq (2 * a * x + b) S,\n    rw H_equate_squares at H_sq_eq, simp at H_sq_eq,\n    rw add_comm at H_sq_eq,\n\n    cases H_sq_eq,\n    {\n        left,\n        have H_mul_out_1 := multiply_out_divide x (-b + S) (2*a) H\u2082,\n        rw H_mul_out_1, clear H_mul_out_1,\n        rw mul_comm,\n\n        suffices H_add_b : 2*a*x + b = S,\n        {\n            rw \u2190H_add_b,simp\n        },\n\n        exact H_sq_eq\n    },\n    {\n        right,\n        have H_mul_out_2 := multiply_out_divide x (-b - S) (2*a) H\u2082,\n        rw H_mul_out_2, clear H_mul_out_2,\n        rw mul_comm,\n\n        suffices H_add_b : 2*a*x + b = -S,\n        {\n            rw \u2190add_neg_eq_sub,\n            rw \u2190H_add_b,simp\n        },\n\n        exact H_sq_eq\n    }\n\n},\n-- x=... \u2192 ax^2 + bx + c\n{\n    intro H,\n    cases H,\n\n    repeat --works for both cases -b - S and - b + S\n    {\n        subst H,\n        \n        \n        apply eq_of_mul_eq_mul_right H\u2082,\n        simp [add_mul],\n\n        repeat {rw \u2190mul_div_assoc},\n        repeat {rw div_mul_cancel _ H\u2082},\n        \n        apply eq_of_mul_eq_mul_right H\u2082,\n        simp [add_mul],\n\n        rw \u2190add_assoc,\n\n        rw div_mul_eq_mul_div,\n\n        rw div_mul_cancel _ H\u2082,\n        ring,\n        rw pow_two S,\n        rw HS,\n        ring\n    },\n    \n}\n\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "SF-solns-zak", "sha": "7edc4424938e01a6ef4bb518fa8ec1757a2226b1", "save_path": "github-repos/lean/ImperialCollegeLondon-SF-solns-zak", "path": "github-repos/lean/ImperialCollegeLondon-SF-solns-zak/SF-solns-zak-7edc4424938e01a6ef4bb518fa8ec1757a2226b1/Quad.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7041847524556505}}
{"text": "import GMLInit.Data.Nat.Basic\nimport GMLInit.Data.Nat.IsPos\nimport GMLInit.Data.Nat.Order\nimport GMLInit.Data.Nat.Succ\n\nnamespace Nat\n\n-- assert theorem add_zero (x : Nat) : x + 0 = x\n\n-- assert theorem zero_add (x : Nat) : 0 + x = x\n\nprotected theorem add_succ' (x y : Nat) : x + (y + 1) = (x + y) + 1 := Nat.add_succ x y\n\nprotected theorem succ_add' (x y : Nat) : (x + 1) + y = (x + y) + 1 := Nat.succ_add x y\n\nprotected theorem one_add' (x : Nat) : 1 + x = x + 1 := by\n  rw [Nat.succ_add, Nat.zero_add]\n\n-- assert theorem add_comm (x y : Nat) : x + y = y + x := core\n\n-- assert theorem add_assoc (x y z : Nat) : (x + y) + z = x + (y + z)\n\n-- assert theorem add_left_comm (x y z : Nat) : x + (y + z) = y + (x + z) := rfl\n\n-- assert theorem add_right_comm (x y z : Nat) : (x + y) + z = (x + z) + y := rfl\n\nprotected theorem add_cross_comm (x\u2081 x\u2082 y\u2081 y\u2082 : Nat) : (x\u2081 + x\u2082) + (y\u2081 + y\u2082) = (x\u2081 + y\u2081) + (x\u2082 + y\u2082) :=\n  calc\n  _ = x\u2081 + (x\u2082 + (y\u2081 + y\u2082)) := by rw [Nat.add_assoc]\n  _ = x\u2081 + (y\u2081 + (x\u2082 + y\u2082)) := by rw [Nat.add_left_comm x\u2082 y\u2081 y\u2082]\n  _ = (x\u2081 + y\u2081) + (x\u2082 + y\u2082) := by rw [Nat.add_assoc]\n\nprotected theorem add_left_cancel' (x : Nat) {y z : Nat} : x + y = x + z \u2192 y = z := Nat.add_left_cancel\n\nprotected theorem add_right_cancel' (x : Nat) {y z : Nat} : y + x = z + x \u2192 y = z := Nat.add_right_cancel\n\n-- assert theorem le_add_left (x y : Nat) : x \u2264 y + x\n\n-- assert theorem le_add_right (x y : Nat) : x \u2264 x + y\n\nprotected theorem lt_add_left_of_pos (x y : Nat) (h : y > 0 := by nat_is_pos) : x < y + x :=\n  calc\n  _ = 0 + x := by rw [Nat.zero_add]\n  _ < y + x := by apply Nat.add_lt_add_right h\n\nprotected theorem lt_add_right_of_pos (x y : Nat) (h : y > 0 := by nat_is_pos) : x < x + y :=\n  calc\n  _ = x + 0 := by rw [Nat.add_zero]\n  _ < x + y := by apply Nat.add_lt_add_left h\n\ntheorem pos_add_left (x y : Nat) (h : x > 0 := by nat_is_pos) : x + y > 0 :=\n  calc\n  0 \u2264 y := by apply Nat.zero_le\n  _ < x + y := by apply Nat.lt_add_left_of_pos _ _\n\ntheorem pos_add_right (x y : Nat) (h : y > 0 := by nat_is_pos) : x + y > 0 :=\n  calc\n  0 \u2264 x := by apply Nat.zero_le\n  _ < x + y := by apply Nat.lt_add_right_of_pos _ _\n\n-- assert -- theorem eq_zero_of_add_eq_zero_right : {x y : Nat} \u2192 x + y = 0 \u2192 y = 0\n\n-- assert theorem eq_zero_of_add_eq_zero_left {x y : Nat} : x + y = 0 \u2192 x = 0\n\n-- assert theorem add_le_add {x\u2081 x\u2082 y\u2081 y\u2082 : Nat} : x\u2081 \u2264 x\u2082 \u2192 y\u2081 \u2264 y\u2082 \u2192 x\u2081 + y\u2081 \u2264 x\u2082 + y\u2082\n\n-- assert theorem add_le_add_left {x y : Nat} (h : x \u2264 y) (z : Nat) : z + x \u2264 z + y\n\n-- assert theorem add_le_add_right {x y : Nat} (h : x \u2264 y) (z : Nat) : x + z \u2264 y + z\n\n-- assert theorem add_lt_add {x\u2081 x\u2082 y\u2081 y\u2082 : Nat} : x\u2081 < x\u2082 \u2192 y\u2081 < y\u2082 \u2192 x\u2081 + y\u2081 < x\u2082 + y\u2082\n\n-- assert theorem add_lt_add_left {x y : Nat} (h : x \u2264 y) (z : Nat) : z + x \u2264 z + y\n\n-- assert theorem add_lt_add_right {x y : Nat} (h : x \u2264 y) (z : Nat) : x + z \u2264 y + z\n\nprotected theorem add_lt_add_of_le_of_lt {x\u2081 x\u2082 y\u2081 y\u2082 : Nat} : x\u2081 \u2264 x\u2082 \u2192 y\u2081 < y\u2082 \u2192 x\u2081 + y\u2081 < x\u2082 + y\u2082 := by\n  intro h\u2081 h\u2082\n  transitivity (x\u2081 + y\u2082) using LT.lt, LE.le\n  \u00b7 apply Nat.add_lt_add_left h\u2082\n  \u00b7 apply Nat.add_le_add_right h\u2081\n\nprotected theorem add_lt_add_of_lt_of_le {x\u2081 x\u2082 y\u2081 y\u2082 : Nat} : x\u2081 < x\u2082 \u2192 y\u2081 \u2264 y\u2082 \u2192 x\u2081 + y\u2081 < x\u2082 + y\u2082 := by\n  intro h\u2081 h\u2082\n  transitivity (x\u2081 + y\u2082) using LE.le, LT.lt\n  \u00b7 apply Nat.add_le_add_left h\u2082\n  \u00b7 apply Nat.add_lt_add_right h\u2081\n\nprotected theorem le_of_add_le_add_left' (x : Nat) {y z : Nat} : x + y \u2264 x + z \u2192 y \u2264 z := Nat.le_of_add_le_add_left\n\nprotected theorem le_iff_add_le_add_left (x y z : Nat) : x \u2264 y \u2194 z + x \u2264 z + y :=\n  \u27e8\u03bb h => Nat.add_le_add_left h z, Nat.le_of_add_le_add_left\u27e9\n\nprotected theorem le_of_add_le_add_right' (x : Nat) {y z : Nat} : y + x \u2264 z + x \u2192 y \u2264 z := Nat.le_of_add_le_add_right\n\nprotected theorem le_iff_add_le_add_right (x y z : Nat) : x \u2264 y \u2194 x + z \u2264 y + z :=\n  \u27e8\u03bb h => Nat.add_le_add_right h z, Nat.le_of_add_le_add_right\u27e9\n\n-- assert theorem lt_of_add_lt_add_left {x y z : Nat} : x + y < x + z \u2192 y < z\n\nprotected theorem lt_of_add_lt_add_left' (x : Nat) {y z : Nat} : x + y < x + z \u2192 y < z := Nat.lt_of_add_lt_add_left\n\nprotected theorem lt_iff_add_lt_add_left (x y z : Nat) : x < y \u2194 z + x < z + y :=\n  \u27e8\u03bb h => Nat.add_lt_add_left h z, Nat.lt_of_add_lt_add_left\u27e9\n\n-- assert theorem lt_of_add_lt_add_right {x y z : Nat} : y + x < z + x \u2192 y < z\n\nprotected theorem lt_of_add_lt_add_right' (x : Nat) {y z : Nat} : y + x < z + x \u2192 y < z := Nat.lt_of_add_lt_add_right\n\nprotected theorem lt_iff_add_lt_add_right (x y z : Nat) : x < y \u2194 x + z < y + z :=\n  \u27e8\u03bb h => Nat.add_lt_add_right h z, Nat.lt_of_add_lt_add_right\u27e9\n\nend Nat\n", "meta": {"author": "fgdorais", "repo": "GMLInit", "sha": "a295111627ac907ebc6a86f906dd9b4d69b338d8", "save_path": "github-repos/lean/fgdorais-GMLInit", "path": "github-repos/lean/fgdorais-GMLInit/GMLInit-a295111627ac907ebc6a86f906dd9b4d69b338d8/GMLInit/Data/Nat/Add.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7041847477734575}}
{"text": "/-\nCopyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Kontorovich, Heather Macbeth, Marc Masdeu\n-/\n\nimport linear_algebra.special_linear_group\nimport analysis.complex.basic\nimport group_theory.group_action.defs\n\n/-!\n# The upper half plane and its automorphisms\n\nThis file defines `upper_half_plane` to be the upper half plane in `\u2102`.\n\nWe furthermore equip it with the structure of an `SL(2,\u211d)` action by\nfractional linear transformations.\n\nWe define the notation `\u210d` for the upper half plane available in the locale\n`upper_half_plane` so as not to conflict with the quaternions.\n-/\n\nnoncomputable theory\n\nopen matrix matrix.special_linear_group\n\nopen_locale classical big_operators matrix_groups\n\nlocal attribute [instance] fintype.card_fin_even\n\n/-- The open upper half plane -/\nabbreviation upper_half_plane :=\n{point : \u2102 // 0 < point.im}\n\nlocalized \"notation `\u210d` := upper_half_plane\" in upper_half_plane\n\nnamespace upper_half_plane\n\n/-- Imaginary part -/\ndef im (z : \u210d) := (z : \u2102).im\n\n/-- Real part -/\ndef re (z : \u210d) := (z : \u2102).re\n\n@[simp] lemma coe_im (z : \u210d) : (z : \u2102).im = z.im := rfl\n\n@[simp] lemma coe_re (z : \u210d) : (z : \u2102).re = z.re := rfl\n\nlemma im_pos (z : \u210d) : 0 < z.im := z.2\n\nlemma im_ne_zero (z : \u210d) : z.im \u2260 0 := z.im_pos.ne'\n\nlemma ne_zero (z : \u210d) : (z : \u2102) \u2260 0 :=\nmt (congr_arg complex.im) z.im_ne_zero\n\nlemma norm_sq_pos (z : \u210d) : 0 < complex.norm_sq (z : \u2102) :=\nby { rw complex.norm_sq_pos, exact z.ne_zero }\n\nlemma norm_sq_ne_zero (z : \u210d) : complex.norm_sq (z : \u2102) \u2260 0 := (norm_sq_pos z).ne'\n\n/-- Numerator of the formula for a fractional linear transformation -/\n@[simp] def num (g : SL(2, \u211d)) (z : \u210d) : \u2102 := (g 0 0) * z + (g 0 1)\n\n/-- Denominator of the formula for a fractional linear transformation -/\n@[simp] def denom (g : SL(2, \u211d)) (z : \u210d) : \u2102 := (g 1 0) * z + (g 1 1)\n\nlemma linear_ne_zero (cd : fin 2 \u2192 \u211d) (z : \u210d) (h : cd \u2260 0) : (cd 0 : \u2102) * z + cd 1 \u2260 0 :=\nbegin\n  contrapose! h,\n  have : cd 0 = 0, -- we will need this twice\n  { apply_fun complex.im at h,\n    simpa only [z.im_ne_zero, complex.add_im, add_zero, coe_im, zero_mul, or_false,\n      complex.of_real_im, complex.zero_im, complex.mul_im, mul_eq_zero] using h, },\n  simp only [this, zero_mul, complex.of_real_zero, zero_add, complex.of_real_eq_zero] at h,\n  ext i,\n  fin_cases i; assumption,\nend\n\nlemma denom_ne_zero (g : SL(2, \u211d)) (z : \u210d) : denom g z \u2260 0 :=\nlinear_ne_zero (g 1) z (g.row_ne_zero 1)\n\nlemma norm_sq_denom_pos (g : SL(2, \u211d)) (z : \u210d) : 0 < complex.norm_sq (denom g z) :=\ncomplex.norm_sq_pos.mpr (denom_ne_zero g z)\n\nlemma norm_sq_denom_ne_zero (g : SL(2, \u211d)) (z : \u210d) : complex.norm_sq (denom g z) \u2260 0 :=\nne_of_gt (norm_sq_denom_pos g z)\n\n/-- Fractional linear transformation -/\ndef smul_aux' (g : SL(2, \u211d)) (z : \u210d) : \u2102 := num g z / denom g z\n\nlemma smul_aux'_im (g : SL(2, \u211d)) (z : \u210d) :\n  (smul_aux' g z).im = z.im / (denom g z).norm_sq :=\nbegin\n  rw [smul_aux', complex.div_im],\n  set NsqBot := (denom g z).norm_sq,\n  have : NsqBot \u2260 0,\n  { simp only [denom_ne_zero g z, monoid_with_zero_hom.map_eq_zero, ne.def, not_false_iff], },\n  field_simp [smul_aux'],\n  convert congr_arg (\u03bb x, x * z.im * NsqBot ^ 2) g.det_coe using 1,\n  { rw det_fin_two \u2191g,\n    ring },\n  { ring }\nend\n\n/-- Fractional linear transformation -/\ndef smul_aux (g : SL(2,\u211d)) (z : \u210d) : \u210d :=\n\u27e8smul_aux' g z,\nby { rw smul_aux'_im, exact div_pos z.im_pos (complex.norm_sq_pos.mpr (denom_ne_zero g z)) }\u27e9\n\nlemma denom_cocycle (x y : SL(2,\u211d)) (z : \u210d) :\n  denom (x * y) z = denom x (smul_aux y z) * denom y z :=\nbegin\n  change _ = (_ * (_ / _) + _) * _,\n  field_simp [denom_ne_zero, -denom, -num],\n  simp [matrix.mul, dot_product, fin.sum_univ_succ],\n  ring\nend\n\nlemma mul_smul' (x y : SL(2, \u211d)) (z : \u210d) :\n  smul_aux (x * y) z = smul_aux x (smul_aux y z) :=\nbegin\n  ext1,\n  change _ / _ = (_ * (_ / _) + _)  * _,\n  rw denom_cocycle,\n  field_simp [denom_ne_zero, -denom, -num],\n  simp [matrix.mul, dot_product, fin.sum_univ_succ],\n  ring\nend\n\n/-- The action of `SL(2, \u211d)` on the upper half-plane by fractional linear transformations. -/\ninstance : mul_action SL(2, \u211d) \u210d :=\n{ smul := smul_aux,\n  one_smul := \u03bb z, by { ext1, change _ / _ = _, simp },\n  mul_smul := mul_smul' }\n\n@[simp] lemma coe_smul (g : SL(2, \u211d)) (z : \u210d) : \u2191(g \u2022 z) = num g z / denom g z := rfl\n@[simp] lemma re_smul (g : SL(2, \u211d)) (z : \u210d) : (g \u2022 z).re = (num g z / denom g z).re := rfl\n\nlemma im_smul (g : SL(2, \u211d)) (z : \u210d) : (g \u2022 z).im = (num g z / denom g z).im := rfl\n\nlemma im_smul_eq_div_norm_sq (g : SL(2, \u211d)) (z : \u210d) :\n  (g \u2022 z).im = z.im / (complex.norm_sq (denom g z)) :=\nsmul_aux'_im g z\n\n@[simp] lemma neg_smul (g : SL(2,\u211d)) (z : \u210d) : -g \u2022 z = g \u2022 z :=\nbegin\n  ext1,\n  change _ / _ = _ / _,\n  field_simp [denom_ne_zero, -denom, -num],\n  simp,\n  ring,\nend\n\nend upper_half_plane\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/complex/upper_half_plane.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7041657804856705}}
{"text": "/-\nCopyright (c) 2020 Kevin Lacker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Lacker, Heather Macbeth\n-/\n\nimport analysis.special_functions.trigonometric.complex\n\n/-!\n# IMO 1962 Q4\n\nSolve the equation `cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1`.\n\nSince Lean does not have a concept of \"simplest form\", we just express what is\nin fact the simplest form of the set of solutions, and then prove it equals the set of solutions.\n-/\n\nopen real\nopen_locale real\nnoncomputable theory\n\ndef problem_equation (x : \u211d) : Prop := cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1\n\ndef solution_set : set \u211d :=\n{ x : \u211d | \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 4 \u2228 x = (2 * \u2191k + 1) * \u03c0 / 6 }\n\n/-\nThe key to solving this problem simply is that we can rewrite the equation as\na product of terms, shown in `alt_formula`, being equal to zero.\n-/\n\ndef alt_formula (x : \u211d) : \u211d := cos x * (cos x ^ 2 - 1/2) * cos (3 * x)\n\nlemma cos_sum_equiv {x : \u211d} :\n(cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 - 1) / 4 = alt_formula x :=\nbegin\n  simp only [real.cos_two_mul, cos_three_mul, alt_formula],\n  ring\nend\n\nlemma alt_equiv {x : \u211d} : problem_equation x \u2194 alt_formula x = 0 :=\nbegin\n  rw [ problem_equation, \u2190 cos_sum_equiv, div_eq_zero_iff, sub_eq_zero],\n  norm_num,\nend\n\nlemma finding_zeros {x : \u211d} :\nalt_formula x = 0 \u2194 cos x ^ 2 = 1/2 \u2228 cos (3 * x) = 0 :=\nbegin\n  simp only [alt_formula, mul_assoc, mul_eq_zero, sub_eq_zero],\n  split,\n  { rintro (h1|h2),\n    { right,\n      rw [cos_three_mul, h1],\n      ring },\n    { exact h2 } },\n  { exact or.inr }\nend\n\n/-\nNow we can solve for `x` using basic-ish trigonometry.\n-/\n\nlemma solve_cos2_half {x : \u211d} : cos x ^ 2 = 1/2 \u2194 \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 4 :=\nbegin\n  rw cos_sq,\n  simp only [add_right_eq_self, div_eq_zero_iff],\n  norm_num,\n  rw cos_eq_zero_iff,\n  split;\n  { rintro \u27e8k, h\u27e9,\n    use k,\n    linarith },\nend\n\nlemma solve_cos3x_0 {x : \u211d} : cos (3 * x) = 0 \u2194 \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 6 :=\nbegin\n  rw cos_eq_zero_iff,\n  refine exists_congr (\u03bb k, _),\n  split; intro; linarith\nend\n\n/-\nThe final theorem is now just gluing together our lemmas.\n-/\n\ntheorem imo1962_q4 {x : \u211d} : problem_equation x \u2194 x \u2208 solution_set :=\nbegin\n  rw [alt_equiv, finding_zeros, solve_cos3x_0, solve_cos2_half],\n  exact exists_or_distrib.symm\nend\n\n\n/-\nWe now present a second solution.  The key to this solution is that, when the identity is\nconverted to an identity which is polynomial in `a` := `cos x`, it can be rewritten as a product of\nterms, `a ^ 2 * (2 * a ^ 2 - 1) * (4 * a ^ 2 - 3)`, being equal to zero.\n-/\n\n/-- Someday, when there is a Grobner basis tactic, try to automate this proof. (A little tricky --\nthe ideals are not the same but their Jacobson radicals are.) -/\nlemma formula {R : Type*} [comm_ring R] [is_domain R] [char_zero R] (a : R) :\n  a ^ 2 + (2 * a ^ 2 - 1) ^ 2 + (4 * a ^ 3 - 3 * a) ^ 2 = 1\n  \u2194 (2 * a ^ 2 - 1) * (4 * a ^ 3 - 3 * a) = 0 :=\ncalc a ^ 2 + (2 * a ^ 2 - 1) ^ 2 + (4 * a ^ 3 - 3 * a) ^ 2 = 1\n    \u2194 a ^ 2 + (2 * a ^ 2 - 1) ^ 2 + (4 * a ^ 3 - 3 * a) ^ 2 - 1 = 0 : by rw \u2190 sub_eq_zero\n... \u2194 2 * a ^ 2 * (2 * a ^ 2 - 1) * (4 * a ^ 2 - 3) = 0 : by { split; intros h; convert h; ring }\n... \u2194 a * (2 * a ^ 2 - 1) * (4 * a ^ 2 - 3) = 0 : by simp [(by norm_num : (2:R) \u2260 0)]\n... \u2194 (2 * a ^ 2 - 1) * (4 * a ^ 3 - 3 * a) = 0 : by { split; intros h; convert h using 1; ring }\n\n/-\nAgain, we now can solve for `x` using basic-ish trigonometry.\n-/\n\nlemma solve_cos2x_0 {x : \u211d} :\n  cos (2 * x) = 0 \u2194 \u2203 k : \u2124, x = (2 * \u2191k + 1) * \u03c0 / 4 :=\nbegin\n  rw cos_eq_zero_iff,\n  refine exists_congr (\u03bb k, _),\n  split; intro; linarith\nend\n\n/-\nAgain, the final theorem is now just gluing together our lemmas.\n-/\n\ntheorem imo1962_q4' {x : \u211d} : problem_equation x \u2194 x \u2208 solution_set :=\ncalc problem_equation x\n    \u2194 cos x ^ 2 + cos (2 * x) ^ 2 + cos (3 * x) ^ 2 = 1 : by refl\n... \u2194 cos (2 * x) = 0 \u2228 cos (3 * x) = 0 : by simp [cos_two_mul, cos_three_mul, formula]\n... \u2194 x \u2208 solution_set : by { rw [solve_cos2x_0, solve_cos3x_0, \u2190 exists_or_distrib], refl }\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/archive/imo/imo1962_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7041657746763063}}
{"text": "/-\n  These logic puzzles are mainly inspired by the ones in the book \n  \"To Mock a Mockingbird\", written by Raymond Smullyan.\n-/\n\nnamespace enchantedforest\n\n  namespace introduction\n    /-\n    A certain enchanted forest in a mystical land far away \n    is inhabited by talking birds.\n    -/\n\n    -- all birds in the enchanted forest belong to the type `Bird`\n    -- a `Type` can be thought of as being similar to a `Set`\n    constant Bird : Type\n\n    /-\n    Given any birds `A` and `B`, if the name of bird `B` is called out to `A`, \n    then `A` responds with the name of another bird.\n    -/\n\n    -- `response A B` is the response of Bird `A` on hearing Bird `B`'s name\n    constant response : Bird \u2192 Bird \u2192 Bird\n\n    -- better notation for denoting response\n    -- the operator is left-associative\n    -- the ` \u25c1 ` symbol (typed as `\\lhd`) resembles an ear/beak\n    infix ` \u25c1 ` : 100 := response\n\n  end introduction\n\n  open introduction\n\n\n  namespace identitybird\n    /-\n      If the name of a bird `x` is called out to the identity bird `I`,\n      it responds with just `x`.\n\n      This bird is sometimes called the \"Ibis\", or also (rather rudely) as the\n      \"idiot bird\".\n\n      https://en.wikipedia.org/wiki/Ibis\n    -/\n\n    -- the definition of the identity bird\n    constant I : Bird\n    constant I.call : \u2200 x : Bird, (I \u25c1 x) = x\n    \n  end identitybird\n\n\n  /-\n  A bird `A` is said to be *fond* of another bird `B` if\n  the bird `A` responds to the name `B` with the same name `B`.\n  -/\n\n  -- the definition of fondness\n  notation [parsing_only] A ` is_fond_of ` B := A \u25c1 B = B\n\n  /-\n  A bird `E` is called *egocentric* if it is fond of itself.\n  -/\n\n  -- the definition of egocentricity\n  notation [parsing_only] E ` is_egocentric` := E \u25c1 E = E\n\n  section defending_the_identitybird\n    open identitybird\n\n    /-\n      Students of Combinatornithology sometimes rudely referred to the\n      identity bird as the \"idiot bird\", because of its apparent simplicity.\n\n      The theorems in this section show why the identity bird is actually quite\n      intelligent.\n    -/\n\n    -- The identity bird is fond of every bird.\n    theorem identity_fond_of_all : \u2200 x : Bird, I is_fond_of x :=\n    begin\n      sorry\n    end\n\n    -- The identity bird is egocentric.\n    theorem identity_egocentric : I is_egocentric :=\n    begin\n      sorry\n    end\n\n    /-\n      The identity bird has an unusually large heart! It is fond of every bird.\n\n      It is also egocentric, but it is fond of itself no more than it is of any\n      other bird.\n    -/\n  end defending_the_identitybird\n\n  /-\n  A bird `B` is called *hopelessly egocentric* if\n  for every bird `x`, `B \u25c1 x = B`. \n  -/\n\n  -- the definition of hopeless egocentricity\n  notation [parsing_only] B ` is_hopelessly_egocentric` := \u2200 x, B \u25c1 x = B\n\n  /-\n  More generally, a bird `A` is *fixated* on a bird `B` if\n  for every bird `x`, the response of `A` on hearing `x` is `B`.\n\n  Thus a hopelessly egocentric bird is one that is fixated on itself.\n  -/\n\n  -- the definition of fixatedness\n  notation [parsing_only] A ` is_fixated_on ` B := \u2200 x, A \u25c1 x = B\n\n\n  namespace kestrel\n    /-\n      A bird `K` is a *kestrel* if for any bird `x`,\n      the bird `K \u25c1 x` is fixated on `x`.\n\n      https://en.wikipedia.org/wiki/Kestrel\n    -/\n\n    -- the definition of a kestrel\n    constant K : Bird\n    constant K.call : \u2200 (x y : Bird), (K \u25c1 x) \u25c1 y = x\n\n  end kestrel\n\n  section kestrel_theorems\n    open kestrel\n\n    -- For any bird `x`, the bird `K \u25c1 x` is fixated on `x`.\n    theorem k_x_fixated_on_x : \u2200 x, K \u25c1 x is_fixated_on x :=\n    begin\n      sorry\n    end\n\n    -- An egocentric kestrel must be hopelessly egocentric.\n    theorem kestrel_egocentrism \n      (kestrel_egocentric : K is_egocentric) : \n      (K is_hopelessly_egocentric) :=\n    begin\n      sorry\n    end\n\n    -- The left cancellation law for kestrels.\n    theorem kestrel_left_cancellation \n      (x y : Bird) \n      (kestrel_application : (K \u25c1 x) = (K \u25c1 y)) :\n      (x = y) :=\n    begin\n      sorry\n    end\n\n    -- `*` For an arbitrary bird `x`, if `K` is fond of `K \u25c1 x`,\n    -- then `K` is fond of `x`.\n    theorem kestrel_fondness \n      (x : Bird)\n      (fond_Kx : K is_fond_of (K \u25c1 x)) :\n      K is_fond_of x :=\n    begin\n      sorry,\n    end\n  end kestrel_theorems\n\n  /-\n  Two birds `A` and `B` form an *agreeable pair* if there is another bird `x`\n  that they agree on, i.e., if their responses on hearing the name `x` are the same.\n  (or in symbols,  (A \u25c1 x) = (B \u25c1 x))\n\n  A bird `A` is *agreeable* if it forms an agreeable pair with every other bird `B`.\n  -/\n\n  -- the definition of agreeable birds\n\n  notation [parsing_only] A ` is_agreeable_with ` B := (\u2203 x : Bird, A \u25c1 x = B \u25c1 x)\n  notation [parsing_only] A ` is_agreeable` := \u2200 \u03b2 : Bird, A is_agreeable_with \u03b2\n\n  section identitybird_theorems\n    open identitybird\n\n    -- If the forest contains an identity bird `I` that is agreeable,\n    -- then every bird is fond of at least one bird.\n    -- This does not rely on the composition axiom.\n    theorem agreeable_identity_induces_fondness \n      (I_agreeable : I is_agreeable) :\n      \u2200 B, \u2203 x, B is_fond_of x :=\n    begin\n      sorry\n    end\n\n    -- `*` If every bird is fond of at least one bird, then\n    -- the identity bird must be agreeable.\n    theorem fondness_induces_agreeable_identity\n      (all_birds_fond : \u2200 B, \u2203 x, B is_fond_of x) :\n      I is_agreeable :=\n    begin\n      sorry\n    end\n  end identitybird_theorems\n\n\n  namespace mockingbird\n    /-\n      A *mockingbird* is a kind of bird whose response to any bird `x`\n      is exactly the response of `x` to itself.\n\n      https://en.wikipedia.org/wiki/Mockingbird\n    -/\n\n    -- the definition of a mockingbird\n    constant M : Bird\n    constant M.call : \u2200 x, M \u25c1 x = x \u25c1 x\n\n  end mockingbird\n\n  namespace forestcompositionlaw\n    /-\n    Given any birds `A`, `B`, `C`, the bird `C` is said to *compose* \n    `A` with `B` if for every bird `x`, the following condition holds\n                      (C \u25c1 x) = (A \u25c1 (B \u25c1 x))\n\n    This part of the forest has the property that for any two birds\n    `A` and `B`, there is a third bird `C` that composes `A` with `B`.\n    -/\n\n    -- composition of birds, implemented as a function similar to `response`\n    constant compose : Bird \u2192 Bird \u2192 Bird\n    -- notation for composition\n    infixr ` \u2218 ` := compose\n    -- the definition of composition\n    axiom composition (A B : Bird) : \u2200 {x : Bird}, (A \u2218 B) \u25c1 x = A \u25c1 (B \u25c1 x)\n\n  end forestcompositionlaw\n\n  section mockingbird_theorems\n    open mockingbird \n\n    -- The mockingbird is agreeable.\n    theorem mockingbird_agreeable : M is_agreeable :=\n    begin\n      sorry\n    end\n\n    open forestcompositionlaw\n\n    -- If a mockingbird is in the forest and the composition law holds, \n    -- then every bird is fond of at least one bird.\n    theorem mockingbird_induces_fondness : \u2200 A, \u2203 B, A is_fond_of B :=\n    begin\n      intro A,\n\n      existsi ((A \u2218 M) \u25c1 (A \u2218 M)),\n\n      conv\n      begin\n        to_rhs,\n      end,\n      sorry,\n    end\n\n    -- If the composition law holds and a mockingbird is in the forest,\n    -- then there is a bird that is egocentric.\n    theorem exists_egocentric : \u2203 E, E is_egocentric :=\n    begin\n      sorry,\n    end\n\n    -- `*` If `A` is an agreeable bird and the composition law holds,\n    -- every bird is fond of at least one bird.\n    theorem agreeability_induces_fondness \n      (\u03b1 : Bird)\n      (\u03b1_agreeable : \u03b1 is_agreeable)\n      : \u2200 A, \u2203 B, A is_fond_of B :=\n    begin\n      sorry\n    end\n\n    -- A proof of the earlier theorem as a corollary of the previous one.\n    theorem mockingbird_agreeable_fondness : \u2200 A, \u2203 B, A is_fond_of B :=\n    begin\n      exact (agreeability_induces_fondness M mockingbird_agreeable)\n    end\n\n  end mockingbird_theorems\n\n  namespace bluebird\n    /-\n      The *bluebird* `B` is a bird that can perform composition.\n\n      For birds `x`, `y`, `z`, the following property holds:\n            `(((B \u25c1 x) \u25c1 y) \u25c1 z) = x \u25c1 (y \u25c1 z)`\n\n      https://en.wikipedia.org/wiki/Bluebird\n    -/\n\n    -- the definition of a bluebird\n    constant B : Bird\n    constant B.call : \u2200 (x y z : Bird), (((B \u25c1 x) \u25c1 y) \u25c1 z) = x \u25c1 (y \u25c1 z)\n    \n  end bluebird\n\n  section bluebird_theorems\n    open bluebird\n    open forestcompositionlaw\n\n    -- The bluebird is capable of composing one bird with another.\n    theorem bluebird_composition (x y : Bird) :\n      \u2200 z : Bird, ((B \u25c1 x) \u25c1 y) \u25c1 z = (x \u2218 y) \u25c1 z :=\n    begin\n      sorry\n    end\n\n    open mockingbird\n\n    -- If a mockingbird and a bluebird are in the forest,\n    -- for every bird `A` in the forest, one can contruct a\n    -- bird `\u03b2` using bird calls such that `A` is fond of `\u03b2`.\n    theorem all_birds_fond : \u2200 A, \u2203 \u03b2, A is_fond_of \u03b2 :=\n    begin\n      sorry\n    end\n\n  end bluebird_theorems\n\n  namespace lark\n    /-\n      The *lark* `L` is a bird which, on hearing the name of an\n      arbitrary bird `x`, calls out the name of the bird that\n      composes `x` with the mockingbird `M`.\n\n      https://en.wikipedia.org/wiki/Lark\n    -/\n\n    -- the definition of a lark\n    constant L : Bird\n    constant L.call : \u2200 (x y : Bird), (L \u25c1 x) \u25c1 y = x \u25c1 (y \u25c1 y)\n\n  end lark\n\n  namespace lark_theorems\n    open lark\n\n    -- `*` Every bird is fond of a hopelessly egocentric lark.\n    theorem egocentric_lark_popular\n      (egocentric_lark : L is_egocentric) :\n      \u2200 \u03b2, \u03b2 is_fond_of L :=\n    begin\n      sorry\n    end\n    \n  end lark_theorems\n\n  namespace starling\n    /-\n      A *starling* is a bird `S` that satisfies the following condition\n          `(((S \u25c1 x) \u25c1 y) \u25c1 z) = (x \u25c1 z) \u25c1 (y \u25c1 z)`\n\n      https://en.wikipedia.org/wiki/Starling\n    -/\n\n    -- definition of the starling\n    constant S : Bird\n    constant S.call : \u2200 (x y z : Bird), (((S \u25c1 x) \u25c1 y) \u25c1 z) = (x \u25c1 z) \u25c1 (y \u25c1 z)\n  end starling\n\n  section starling_theorems\n    open starling\n    open kestrel\n\n    /-\n      The existence of a Starling and a Kestrel in the forest is\n      sufficient to imply the existence of several other birds.\n    -/\n\n    -- Derive the identity bird.\n    \n\n    -- Derive the mockingbird.\n\n\n    -- `*` Derive the bluebird.\n\n\n  end starling_theorems\n\n  section summoning_a_sagebird\n    /-\n      According to folklore, a *sagebird* or an *oracle bird* `\u0398` is\n      believed to have the property that if the name of any bird `x` is \n      called out to `\u03b8`, it responds with the name of a bird that `x` is fond of.\n    \n      Interestingly, the existence of a sagebird can be deduced from the birds\n      encountered so far.\n    -/\n  \n    -- adding all the known birds\n    open identitybird\n    open kestrel\n    open mockingbird\n    open bluebird\n    open lark\n    open starling\n\n    -- a sage bird exists in the forest\n    theorem sagebird_existence :\n      \u2203 \u03b8, \u2200 x, x \u25c1 (\u03b8 \u25c1 x) = \u03b8 \u25c1 x :=\n    begin\n      sorry,\n    end  \n  end summoning_a_sagebird\n\nend enchantedforest\n\n  /-\n    A star~t~ling fact:\n\n    All birds can be derived from just the \n    kestrel (`K`) and the\n    starling (`S`)!\n\n    # The algorithm\n\n    Define the `\u03b1-eliminate` of an expression `E` to be\n    an expression `F` such that `F \u03b1 = E`.\n    1. The \u03b1-eliminate of `\u03b1` is `I`.\n    2. If `\u03b1` does not occur in `E`, then `K E` is the\n        \u03b1-eliminate.\n    3. If `E` is of the form `F \u03b1`, then `F` is the\n        \u03b1-eliminate of `E`.\n    4. If `E = F G`, and `F'` and `G'` are the corresponding\n      \u03b1-eliminates of the expressions, then \n          `S (F') (G')` is the corresponding \u03b1-eliminate.\n\n    Repeated \u03b1-elimination of all the variables involved gives the\n    expression for the bird in terms of `S` and `K`.\n\n    For a recursive bird `U` (i.e., a bird whose call depends on itself),\n    replace every occurrence of the letter `U` in the call with an unused\n    variable name and solve as above. \n    \n    Call this modified bird `V`. It satisfies the property `V \u25c1 U = U`.\n    \n    Since the existence of the mockingbird and the bluebird is sufficient to \n    guarantee that every bird is fond of some bird, one can find a bird `F` such that\n    `V` is fond of `F`, that is, `V \u25c1 F = F`. But this is the property that `U` is required\n    to satisfy. Thus `F`, which can be derived from `S` and `K` using the sage bird,\n    is the required bird.\n  -/\n\n-- TO-DO\nnamespace ornithologic\nend ornithologic\n\nnamespace avianarithmetic\nend avianarithmetic\n\n/-\n  # References:\n\n  1. \"To Mock a Mockingbird\", by Raymond Smullyan (https://en.wikipedia.org/wiki/To_Mock_a_Mockingbird)\n  2. \"To Dissect a Mockingbird\", by David Keenan (https://dkeenan.com/Lambda/index.htm)\n  3. SKI Combinator calculus (https://en.wikipedia.org/wiki/SKI_combinator_calculus)\n  4. The Natural Number Game (https://www.ma.imperial.ac.uk/~buzzard/xena/natural_number_game/)\n-/", "meta": {"author": "0art0", "repo": "combinatornithology", "sha": "1ef3d2105c02306acdb7c4f5c752e9afdfe1a742", "save_path": "github-repos/lean/0art0-combinatornithology", "path": "github-repos/lean/0art0-combinatornithology/combinatornithology-1ef3d2105c02306acdb7c4f5c752e9afdfe1a742/src/combinatornithology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7041657706990592}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Violeta Hern\u00e1ndez Palacios, Pedro S\u00e1nchez Terraf\n-/\nimport borel_hierarchy\n\n/-!\n# Cardinal of sigma-algebras\n\nIf a sigma-algebra is generated by a set of sets `s`, then the cardinality of the sigma-algebra is\nbounded by `(max (#s) 2) ^ \u2135\u2080`.\nThis is stated in `measurable_space.cardinal_generate_measurable_le`\nand `measurable_space.cardinal_measurable_set_le`.\n\nIn particular, if `#s \u2264 \ud835\udd20`, then the generated sigma-algebra has cardinality at most `\ud835\udd20`, see\n`measurable_space.cardinal_measurable_set_le_continuum`.\n\nFor the proof, we rely on the explicit inductive construction of the sigma-algebra generated by\n`s` provided by `pointclass.gen_measurable`\n(instead of the inductive predicate `generate_measurable`).\n-/\n\nuniverse u\nvariables {\u03b1 : Type u}\n\nnamespace measurable_space\n\nopen_locale cardinal ordinal\nopen cardinal set pointclass\n\n/-- At each step of the inductive construction, the cardinality bound `\u2264 (max (#s) 2) ^ \u2135\u2080` holds.\n\nThe result holds for arbitrary `i`, but it is easier to prove this way -/\nlemma cardinal_sigma0_le (s : set (set \u03b1)) (i : ordinal.{u}) (hi : i \u2264 \u03c9\u2081) :\n  #(sigma0 s i) \u2264 (max (#s) 2) ^ aleph_0.{u} :=\nbegin\n  induction i using ordinal.induction with i IH,\n  have Upi0sub : (\u22c3 j < i, pi0 s j) \u2286 s \u222a {\u2205, univ} \u222a \u22c3 j < i, compl '' sigma0 s j,\n  { simp only [mem_singleton_iff, union_insert, union_singleton, mem_insert_iff, Union_subset_iff],\n    intros j hj x hx,\n    rcases classical.em (j=0) with rfl | hjnz,\n    { simp only [mem_singleton_iff, union_insert, union_singleton, mem_insert_iff, pi0_zero] at hx,\n      exact mem_union_left _ hx },\n    { rw pi0_eq_compl_sigma0 s j hjnz at hx,\n      exact mem_union_right _ (mem_Union.mpr \u27e8j, mem_Union.mpr \u27e8hj, hx\u27e9\u27e9) } },\n  have cardcompl : \u2200 j, #(sigma0 s j) = #(compl '' sigma0 s j) :=\n    \u03bb j, cardinal.eq.mpr (\u27e8equiv.set.image _ _  compl_injective\u27e9),\n  have A := aleph_0_le_aleph 1,\n  have B : aleph 1 \u2264 (max (#s) 2) ^ aleph_0.{u} :=\n    aleph_one_le_continuum.trans (power_le_power_right (le_max_right _ _)),\n  have C : \u2135\u2080 \u2264 (max (#s) 2) ^ aleph_0.{u} := A.trans B,\n  have L : #(\u21a5(s \u222a {\u2205, univ})) \u2264 (max (#s) 2) ^ aleph_0.{u},\n  { apply_rules [(mk_union_le _ _).trans, add_le_of_le C, mk_image_le.trans],\n    { exact (le_max_left _ _).trans (self_le_power _ one_lt_aleph_0.le) },\n    repeat { simp only [mk_fintype, fintype.card_unique, nat.cast_one, mk_singleton],\n      exact one_lt_aleph_0.le.trans C } },\n  have K : #(\u21a5\u22c3 j < i, compl '' sigma0 s j) \u2264 (max (#s) 2) ^ aleph_0.{u},\n  { apply mk_Union_ordinal_le_of_le (hi.trans $ ord_le_ord.mpr B) C,\n    intros j hj,\n    rw \u2190 cardcompl,\n    exact IH j hj (le_of_lt $ lt_of_lt_of_le hj hi) },\n  have J : #(\u21a5(s \u222a {\u2205, univ} \u222a \u22c3 j < i, compl '' sigma0 s j)) \u2264 (max (#s) 2) ^ aleph_0.{u},\n    { calc\n      #(\u21a5(s \u222a {\u2205, univ} \u222a \u22c3 j < i, compl '' sigma0 s j)) \u2264\n        #(\u21a5(s \u222a {\u2205, univ})) + #(\u21a5\u22c3 j < i, compl '' sigma0 s j) : mk_union_le _ _\n      ... \u2264 (max (#s) 2) ^ aleph_0.{u} + (max (#s) 2) ^ aleph_0.{u} :\n        (add_le_add (le_refl _) K).trans (add_le_add L (le_refl _))\n      ... = (max (#s) 2) ^ aleph_0.{u} :\n        (add_eq_max C).trans (max_eq_right (le_refl _)) },\n  -- The main calculation:\n  calc\n  #\u21a5(sigma0 s i) =\n    #\u21a5(range (\u03bb (f : \u2115 \u2192 (\u21a5\u22c3 j < i, pi0 s j)), \u22c3 n, \u2191(f n))) :\n    by { rw sigma0_eq_Union_pi0, simp }\n  ... \u2264 #(\u2115 \u2192 (\u21a5\u22c3 j < i, pi0 s j))                  : mk_range_le\n  ... = prod (\u03bb n : \u2115, #(\u21a5\u22c3 j < i, pi0 s j))        : mk_pi _\n  ... = #(\u21a5\u22c3 j < i, pi0 s j) ^ aleph_0.{u}          : by { simp [prod_const] }\n  ... \u2264 #(\u21a5(s \u222a {\u2205, univ} \u222a \u22c3 j < i, compl '' sigma0 s j)) ^ aleph_0.{u} :\n    power_le_power_right (mk_le_mk_of_subset Upi0sub)\n  ... \u2264 (max (# \u21a5s) 2 ^ aleph_0.{u}) ^ aleph_0.{u}  : power_le_power_right J\n  ... \u2264 (max (# \u21a5s) 2 ^ aleph_0.{u})                :\n    by { rwa [\u2190 power_mul, aleph_0_mul_aleph_0] }\nend\n\ntheorem cardinal_gen_measurable_le (s : set (set \u03b1)) :\n  #(gen_measurable s) \u2264 (max (#s) 2) ^ aleph_0.{u} := cardinal_sigma0_le _ _ (le_refl _)\n\n/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma-algebra has cardinality at\nmost `(max (#s) 2) ^ \u2135\u2080`. -/\ntheorem cardinal_generate_measurable_le (s : set (set \u03b1)) :\n  #{t | generate_measurable s t} \u2264 (max (#s) 2) ^ aleph_0.{u} :=\nbegin\n  rw generate_measurable_eq_gen_measurable,\n  exact cardinal_gen_measurable_le s,\nend\n\n/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma\nalgebra has cardinality at most `(max (#s) 2) ^ \u2135\u2080`. -/\ntheorem cardinal_measurable_set_le' (s : set (set \u03b1)) :\n  #{t | @measurable_set \u03b1 (generate_from s) t} \u2264 (max (#s) 2) ^ aleph_0.{u} :=\ncardinal_generate_measurable_le s\n\n/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,\nthen the sigma algebra has the same cardinality bound. -/\ntheorem cardinal_generate_measurable_le_continuum {s : set (set \u03b1)} (hs : #s \u2264 \ud835\udd20) :\n  #{t | generate_measurable s t} \u2264 \ud835\udd20 :=\n(cardinal_generate_measurable_le s).trans begin\n  rw \u2190continuum_power_aleph_0,\n  exact_mod_cast power_le_power_right (max_le hs (nat_lt_continuum 2).le)\nend\n\n/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,\nthen the sigma algebra has the same cardinality bound. -/\ntheorem cardinal_measurable_set_le_continuum {s : set (set \u03b1)} :\n  #s \u2264 \ud835\udd20 \u2192 #{t | @measurable_set \u03b1 (generate_from s) t} \u2264 \ud835\udd20 :=\ncardinal_generate_measurable_le_continuum\n\nend measurable_space\n", "meta": {"author": "sterraf", "repo": "mylearninglean", "sha": "a8911234b2a4e15a48ec2c0f05d744e58f798ca7", "save_path": "github-repos/lean/sterraf-mylearninglean", "path": "github-repos/lean/sterraf-mylearninglean/mylearninglean-a8911234b2a4e15a48ec2c0f05d744e58f798ca7/src/card_measurable_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7041657651935153}}
{"text": "import tactic\n\nimport data.real.basic\n\nexample: \u2200 x : \u211d, \u2203 y : \u211d, x + y > 0 :=\nbegin \n    intro x,\n    use 64-x,\n    simp,\n    norm_num,\nend\n\n-- \u2203 y : \u211d, \u2200  x : \u211d, x + y > 0 :=\n-- Is not true, as we can prove the opposite.\n\nexample: \u00ac (\u2203 y : \u211d, \u2200  x : \u211d, x + y > 0) :=\nbegin \n    push_neg,\n    intro y,\n    use -73 - y,\n    simp,\n    norm_num,\nend\n\nvariable (\u03b1 : Type)\n-- P is a predicate of \u03b1 so it is a function that assigns a true-false for each x : alpha.\nexample : (\u03b1 \u2192 Prop) \u2243 set \u03b1 :=\n{ to_fun := \u03bb P, {x : \u03b1 | P x},\n  inv_fun := \u03bb X, \u03bb a, a \u2208 X,\n  left_inv:= begin \n      intro P,\n      dsimp,\n      refl,\n  end\n  ,\n  right_inv  := begin\n      intro P,\n      dsimp,\n      refl,\n  end\n}", "meta": {"author": "SzymonKubica", "repo": "Lean", "sha": "627bff2f001ba3f009c112c9332093e8de84863c", "save_path": "github-repos/lean/SzymonKubica-Lean", "path": "github-repos/lean/SzymonKubica-Lean/Lean-627bff2f001ba3f009c112c9332093e8de84863c/ForAll&Exists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9591542840900507, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.7041338781015611}}
{"text": "/-\nCopyright (c) 2020 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\n\nimport data.finset.nat_antidiagonal\nimport algebra.big_operators.basic\n\n/-!\n# Big operators for `nat_antidiagonal`\n\nThis file contains theorems relevant to big operators over `finset.nat.antidiagonal`.\n-/\n\nopen_locale big_operators\n\nvariables {M N : Type*} [comm_monoid M] [add_comm_monoid N]\n\nnamespace finset\nnamespace nat\n\nlemma prod_antidiagonal_succ {n : \u2115} {f : \u2115 \u00d7 \u2115 \u2192 M} :\n  \u220f p in antidiagonal (n + 1), f p = f (0, n + 1) * \u220f p in antidiagonal n, f (p.1 + 1, p.2) :=\nbegin\n  rw [antidiagonal_succ, prod_cons, prod_map], refl,\nend\n\nlemma sum_antidiagonal_succ {n : \u2115} {f : \u2115 \u00d7 \u2115 \u2192 N} :\n  \u2211 p in antidiagonal (n + 1), f p = f (0, n + 1) + \u2211 p in antidiagonal n, f (p.1 + 1, p.2) :=\n@prod_antidiagonal_succ (multiplicative N) _ _ _\n\n@[to_additive]\nlemma prod_antidiagonal_swap {n : \u2115} {f : \u2115 \u00d7 \u2115 \u2192 M} :\n  \u220f p in antidiagonal n, f p.swap = \u220f p in antidiagonal n, f p :=\nby { nth_rewrite 1 \u2190 map_swap_antidiagonal, rw [prod_map], refl }\n\nlemma prod_antidiagonal_succ' {n : \u2115} {f : \u2115 \u00d7 \u2115 \u2192 M} :\n  \u220f p in antidiagonal (n + 1), f p = f (n + 1, 0) * \u220f p in antidiagonal n, f (p.1, p.2 + 1) :=\nbegin\n  rw [\u2190 prod_antidiagonal_swap, prod_antidiagonal_succ, \u2190 prod_antidiagonal_swap],\n  refl\nend\n\nlemma sum_antidiagonal_succ' {n : \u2115} {f : \u2115 \u00d7 \u2115 \u2192 N} :\n  \u2211 p in antidiagonal (n + 1), f p = f (n + 1, 0) + \u2211 p in antidiagonal n, f (p.1, p.2 + 1) :=\n@prod_antidiagonal_succ' (multiplicative N) _ _ _\n\n@[to_additive]\nlemma prod_antidiagonal_subst {n : \u2115} {f : \u2115 \u00d7 \u2115 \u2192 \u2115 \u2192 M} :\n  \u220f p in antidiagonal n, f p n = \u220f p in antidiagonal n, f p (p.1 + p.2) :=\nprod_congr rfl $ \u03bb p hp, by rw [nat.mem_antidiagonal.1 hp]\n\n@[to_additive]\nlemma prod_antidiagonal_eq_prod_range_succ_mk {M : Type*} [comm_monoid M] (f : \u2115 \u00d7 \u2115 \u2192 M) (n : \u2115) :\n  \u220f ij in finset.nat.antidiagonal n, f ij = \u220f k in range n.succ, f (k, n - k) :=\nbegin\n  convert prod_map _ \u27e8\u03bb i, (i, n - i), \u03bb x y h, (prod.mk.inj h).1\u27e9 _,\n  refl,\nend\n\n/-- This lemma matches more generally than `finset.nat.prod_antidiagonal_eq_prod_range_succ_mk` when\nusing `rw \u2190`. -/\n@[to_additive \"This lemma matches more generally than\n`finset.nat.sum_antidiagonal_eq_sum_range_succ_mk` when using `rw \u2190`.\"]\nlemma prod_antidiagonal_eq_prod_range_succ {M : Type*} [comm_monoid M] (f : \u2115 \u2192 \u2115 \u2192 M) (n : \u2115) :\n  \u220f ij in finset.nat.antidiagonal n, f ij.1 ij.2 = \u220f k in range n.succ, f k (n - k) :=\nprod_antidiagonal_eq_prod_range_succ_mk _ _\n\nend nat\n\nend finset\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/big_operators/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048443, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7040185550853569}}
{"text": "/-\nCopyright (c) 2021 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n\n! This file was ported from Lean 3 source module order.well_founded_set\n! leanprover-community/mathlib commit f16e7a22e11fc09c71f25446ac1db23a24e8a0bd\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.Antichain\nimport Mathbin.Order.OrderIsoNat\nimport Mathbin.Order.WellFounded\nimport Mathbin.Tactic.Tfae\n\n/-!\n# Well-founded sets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA well-founded subset of an ordered type is one on which the relation `<` is well-founded.\n\n## Main Definitions\n * `set.well_founded_on s r` indicates that the relation `r` is\n  well-founded when restricted to the set `s`.\n * `set.is_wf s` indicates that `<` is well-founded when restricted to `s`.\n * `set.partially_well_ordered_on s r` indicates that the relation `r` is\n  partially well-ordered (also known as well quasi-ordered) when restricted to the set `s`.\n * `set.is_pwo s` indicates that any infinite sequence of elements in `s` contains an infinite\n  monotone subsequence. Note that this is equivalent to containing only two comparable elements.\n\n## Main Results\n * Higman's Lemma, `set.partially_well_ordered_on.partially_well_ordered_on_sublist_forall\u2082`,\n  shows that if `r` is partially well-ordered on `s`, then `list.sublist_forall\u2082` is partially\n  well-ordered on the set of lists of elements of `s`. The result was originally published by\n  Higman, but this proof more closely follows Nash-Williams.\n * `set.well_founded_on_iff` relates `well_founded_on` to the well-foundedness of a relation on the\n original type, to avoid dealing with subtypes.\n * `set.is_wf.mono` shows that a subset of a well-founded subset is well-founded.\n * `set.is_wf.union` shows that the union of two well-founded subsets is well-founded.\n * `finset.is_wf` shows that all `finset`s are well-founded.\n\n## TODO\n\nProve that `s` is partial well ordered iff it has no infinite descending chain or antichain.\n\n## References\n * [Higman, *Ordering by Divisibility in Abstract Algebras*][Higman52]\n * [Nash-Williams, *On Well-Quasi-Ordering Finite Trees*][Nash-Williams63]\n-/\n\n\nvariable {\u03b9 \u03b1 \u03b2 : Type _}\n\nnamespace Set\n\n/-! ### Relations well-founded on sets -/\n\n\n#print Set.WellFoundedOn /-\n/-- `s.well_founded_on r` indicates that the relation `r` is well-founded when restricted to `s`. -/\ndef WellFoundedOn (s : Set \u03b1) (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop :=\n  WellFounded fun a b : s => r a b\n#align set.well_founded_on Set.WellFoundedOn\n-/\n\n#print Set.wellFoundedOn_empty /-\n@[simp]\ntheorem wellFoundedOn_empty (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : WellFoundedOn \u2205 r :=\n  wellFounded_of_isEmpty _\n#align set.well_founded_on_empty Set.wellFoundedOn_empty\n-/\n\nsection WellFoundedOn\n\nvariable {r r' : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\nsection AnyRel\n\nvariable {s t : Set \u03b1} {x y : \u03b1}\n\n#print Set.wellFoundedOn_iff /-\ntheorem wellFoundedOn_iff : s.WellFoundedOn r \u2194 WellFounded fun a b : \u03b1 => r a b \u2227 a \u2208 s \u2227 b \u2208 s :=\n  by\n  have f : RelEmbedding (fun (a : s) (b : s) => r a b) fun a b : \u03b1 => r a b \u2227 a \u2208 s \u2227 b \u2208 s :=\n    \u27e8\u27e8coe, Subtype.coe_injective\u27e9, fun a b => by simp\u27e9\n  refine' \u27e8fun h => _, f.well_founded\u27e9\n  rw [WellFounded.wellFounded_iff_has_min]\n  intro t ht\n  by_cases hst : (s \u2229 t).Nonempty\n  \u00b7 rw [\u2190 Subtype.preimage_coe_nonempty] at hst\n    rcases h.has_min (coe \u207b\u00b9' t) hst with \u27e8\u27e8m, ms\u27e9, mt, hm\u27e9\n    exact \u27e8m, mt, fun x xt \u27e8xm, xs, ms\u27e9 => hm \u27e8x, xs\u27e9 xt xm\u27e9\n  \u00b7 rcases ht with \u27e8m, mt\u27e9\n    exact \u27e8m, mt, fun x xt \u27e8xm, xs, ms\u27e9 => hst \u27e8m, \u27e8ms, mt\u27e9\u27e9\u27e9\n#align set.well_founded_on_iff Set.wellFoundedOn_iff\n-/\n\nnamespace WellFoundedOn\n\n#print Set.WellFoundedOn.induction /-\nprotected theorem induction (hs : s.WellFoundedOn r) (hx : x \u2208 s) {P : \u03b1 \u2192 Prop}\n    (hP : \u2200 y \u2208 s, (\u2200 z \u2208 s, r z y \u2192 P z) \u2192 P y) : P x :=\n  by\n  let Q : s \u2192 Prop := fun y => P y\n  change Q \u27e8x, hx\u27e9\n  refine' WellFounded.induction hs \u27e8x, hx\u27e9 _\n  simpa only [Subtype.forall]\n#align set.well_founded_on.induction Set.WellFoundedOn.induction\n-/\n\n#print Set.WellFoundedOn.mono /-\nprotected theorem mono (h : t.WellFoundedOn r') (hle : r \u2264 r') (hst : s \u2286 t) : s.WellFoundedOn r :=\n  by\n  rw [well_founded_on_iff] at *\n  refine' Subrelation.wf (fun x y xy => _) h\n  exact \u27e8hle _ _ xy.1, hst xy.2.1, hst xy.2.2\u27e9\n#align set.well_founded_on.mono Set.WellFoundedOn.mono\n-/\n\n#print Set.WellFoundedOn.subset /-\ntheorem subset (h : t.WellFoundedOn r) (hst : s \u2286 t) : s.WellFoundedOn r :=\n  h.mono le_rfl hst\n#align set.well_founded_on.subset Set.WellFoundedOn.subset\n-/\n\nopen Relation\n\n#print Set.WellFoundedOn.acc_iff_wellFoundedOn /-\n/-- `a` is accessible under the relation `r` iff `r` is well-founded on the downward transitive\n  closure of `a` under `r` (including `a` or not). -/\ntheorem acc_iff_wellFoundedOn {\u03b1} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {a : \u03b1} :\n    [Acc r a, { b | ReflTransGen r b a }.WellFoundedOn r,\n        { b | TransGen r b a }.WellFoundedOn r].TFAE :=\n  by\n  tfae_have 1 \u2192 2\n  \u00b7 refine' fun h => \u27e8fun b => _\u27e9\n    apply InvImage.accessible\n    rw [\u2190 acc_transGen_iff] at h\u22a2\n    obtain h' | h' := refl_trans_gen_iff_eq_or_trans_gen.1 b.2\n    \u00b7 rwa [h'] at h\n    \u00b7 exact h.inv h'\n  tfae_have 2 \u2192 3\n  \u00b7 exact fun h => h.Subset fun _ => trans_gen.to_refl\n  tfae_have 3 \u2192 1\n  \u00b7 refine' fun h =>\n      Acc.intro _ fun b hb => (h.apply \u27e8b, trans_gen.single hb\u27e9).of_fibration Subtype.val _\n    exact fun \u27e8c, hc\u27e9 d h => \u27e8\u27e8d, trans_gen.head h hc\u27e9, h, rfl\u27e9\n  tfae_finish\n#align set.well_founded_on.acc_iff_well_founded_on Set.WellFoundedOn.acc_iff_wellFoundedOn\n-/\n\nend WellFoundedOn\n\nend AnyRel\n\nsection IsStrictOrder\n\nvariable [IsStrictOrder \u03b1 r] {s t : Set \u03b1}\n\n#print Set.IsStrictOrder.subset /-\ninstance IsStrictOrder.subset : IsStrictOrder \u03b1 fun a b : \u03b1 => r a b \u2227 a \u2208 s \u2227 b \u2208 s\n    where\n  to_isIrrefl := \u27e8fun a con => irrefl_of r a Con.1\u27e9\n  to_isTrans := \u27e8fun a b c ab bc => \u27e8trans_of r ab.1 bc.1, ab.2.1, bc.2.2\u27e9\u27e9\n#align set.is_strict_order.subset Set.IsStrictOrder.subset\n-/\n\n/- warning: set.well_founded_on_iff_no_descending_seq -> Set.wellFoundedOn_iff_no_descending_seq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u1} \u03b1 r] {s : Set.{u1} \u03b1}, Iff (Set.WellFoundedOn.{u1} \u03b1 s r) (forall (f : RelEmbedding.{0, u1} Nat \u03b1 (GT.gt.{0} Nat Nat.hasLt) r), Not (forall (n : Nat), Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (coeFn.{succ u1, succ u1} (RelEmbedding.{0, u1} Nat \u03b1 (GT.gt.{0} Nat Nat.hasLt) r) (fun (_x : RelEmbedding.{0, u1} Nat \u03b1 (GT.gt.{0} Nat Nat.hasLt) r) => Nat -> \u03b1) (RelEmbedding.hasCoeToFun.{0, u1} Nat \u03b1 (GT.gt.{0} Nat Nat.hasLt) r) f n) s))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u1} \u03b1 r] {s : Set.{u1} \u03b1}, Iff (Set.WellFoundedOn.{u1} \u03b1 s r) (forall (f : RelEmbedding.{0, u1} Nat \u03b1 (fun (x._@.Mathlib.Order.WellFoundedSet._hyg.3266 : Nat) (x._@.Mathlib.Order.WellFoundedSet._hyg.3268 : Nat) => GT.gt.{0} Nat instLTNat x._@.Mathlib.Order.WellFoundedSet._hyg.3266 x._@.Mathlib.Order.WellFoundedSet._hyg.3268) r), Not (forall (n : Nat), Membership.mem.{u1, u1} ((fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => \u03b1) n) (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (FunLike.coe.{succ u1, 1, succ u1} (Function.Embedding.{1, succ u1} Nat \u03b1) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => \u03b1) _x) (EmbeddingLike.toFunLike.{succ u1, 1, succ u1} (Function.Embedding.{1, succ u1} Nat \u03b1) Nat \u03b1 (Function.instEmbeddingLikeEmbedding.{1, succ u1} Nat \u03b1)) (RelEmbedding.toEmbedding.{0, u1} Nat \u03b1 (fun (x._@.Mathlib.Order.WellFoundedSet._hyg.3266 : Nat) (x._@.Mathlib.Order.WellFoundedSet._hyg.3268 : Nat) => GT.gt.{0} Nat instLTNat x._@.Mathlib.Order.WellFoundedSet._hyg.3266 x._@.Mathlib.Order.WellFoundedSet._hyg.3268) r f) n) s))\nCase conversion may be inaccurate. Consider using '#align set.well_founded_on_iff_no_descending_seq Set.wellFoundedOn_iff_no_descending_seq\u2093'. -/\ntheorem wellFoundedOn_iff_no_descending_seq :\n    s.WellFoundedOn r \u2194 \u2200 f : ((\u00b7 > \u00b7) : \u2115 \u2192 \u2115 \u2192 Prop) \u21aar r, \u00ac\u2200 n, f n \u2208 s :=\n  by\n  simp only [well_founded_on_iff, RelEmbedding.wellFounded_iff_no_descending_seq, \u2190 not_exists, \u2190\n    not_nonempty_iff, not_iff_not]\n  constructor\n  \u00b7 rintro \u27e8\u27e8f, hf\u27e9\u27e9\n    have H : \u2200 n, f n \u2208 s := fun n => (hf.2 n.lt_succ_self).2.2\n    refine' \u27e8\u27e8f, _\u27e9, H\u27e9\n    simpa only [H, and_true_iff] using @hf\n  \u00b7 rintro \u27e8\u27e8f, hf\u27e9, hfs : \u2200 n, f n \u2208 s\u27e9\n    refine' \u27e8\u27e8f, _\u27e9\u27e9\n    simpa only [hfs, and_true_iff] using @hf\n#align set.well_founded_on_iff_no_descending_seq Set.wellFoundedOn_iff_no_descending_seq\n\n/- warning: set.well_founded_on.union -> Set.WellFoundedOn.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u1} \u03b1 r] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.WellFoundedOn.{u1} \u03b1 s r) -> (Set.WellFoundedOn.{u1} \u03b1 t r) -> (Set.WellFoundedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u1} \u03b1 r] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.WellFoundedOn.{u1} \u03b1 s r) -> (Set.WellFoundedOn.{u1} \u03b1 t r) -> (Set.WellFoundedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t) r)\nCase conversion may be inaccurate. Consider using '#align set.well_founded_on.union Set.WellFoundedOn.union\u2093'. -/\ntheorem WellFoundedOn.union (hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) :\n    (s \u222a t).WellFoundedOn r :=\n  by\n  rw [well_founded_on_iff_no_descending_seq] at *\n  rintro f hf\n  rcases Nat.exists_subseq_of_forall_mem_union f hf with \u27e8g, hg | hg\u27e9\n  exacts[hs (g.dual.lt_embedding.trans f) hg, ht (g.dual.lt_embedding.trans f) hg]\n#align set.well_founded_on.union Set.WellFoundedOn.union\n\n/- warning: set.well_founded_on_union -> Set.wellFoundedOn_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u1} \u03b1 r] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.WellFoundedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t) r) (And (Set.WellFoundedOn.{u1} \u03b1 s r) (Set.WellFoundedOn.{u1} \u03b1 t r))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u1} \u03b1 r] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.WellFoundedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t) r) (And (Set.WellFoundedOn.{u1} \u03b1 s r) (Set.WellFoundedOn.{u1} \u03b1 t r))\nCase conversion may be inaccurate. Consider using '#align set.well_founded_on_union Set.wellFoundedOn_union\u2093'. -/\n@[simp]\ntheorem wellFoundedOn_union : (s \u222a t).WellFoundedOn r \u2194 s.WellFoundedOn r \u2227 t.WellFoundedOn r :=\n  \u27e8fun h => \u27e8h.Subset <| subset_union_left _ _, h.Subset <| subset_union_right _ _\u27e9, fun h =>\n    h.1.union h.2\u27e9\n#align set.well_founded_on_union Set.wellFoundedOn_union\n\nend IsStrictOrder\n\nend WellFoundedOn\n\n/-! ### Sets well-founded w.r.t. the strict inequality -/\n\n\nsection LT\n\nvariable [LT \u03b1] {s t : Set \u03b1}\n\n#print Set.IsWf /-\n/-- `s.is_wf` indicates that `<` is well-founded when restricted to `s`. -/\ndef IsWf (s : Set \u03b1) : Prop :=\n  WellFoundedOn s (\u00b7 < \u00b7)\n#align set.is_wf Set.IsWf\n-/\n\n#print Set.isWf_empty /-\n@[simp]\ntheorem isWf_empty : IsWf (\u2205 : Set \u03b1) :=\n  wellFounded_of_isEmpty _\n#align set.is_wf_empty Set.isWf_empty\n-/\n\n#print Set.isWf_univ_iff /-\ntheorem isWf_univ_iff : IsWf (univ : Set \u03b1) \u2194 WellFounded ((\u00b7 < \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop) := by\n  simp [is_wf, well_founded_on_iff]\n#align set.is_wf_univ_iff Set.isWf_univ_iff\n-/\n\n#print Set.IsWf.mono /-\ntheorem IsWf.mono (h : IsWf t) (st : s \u2286 t) : IsWf s :=\n  h.Subset st\n#align set.is_wf.mono Set.IsWf.mono\n-/\n\nend LT\n\nsection Preorder\n\nvariable [Preorder \u03b1] {s t : Set \u03b1} {a : \u03b1}\n\n/- warning: set.is_wf.union -> Set.IsWf.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) s) -> (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) t) -> (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) s) -> (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) t) -> (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align set.is_wf.union Set.IsWf.union\u2093'. -/\nprotected theorem IsWf.union (hs : IsWf s) (ht : IsWf t) : IsWf (s \u222a t) :=\n  hs.union ht\n#align set.is_wf.union Set.IsWf.union\n\n/- warning: set.is_wf_union -> Set.isWf_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) (And (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) s) (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t)) (And (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) s) (Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 _inst_1) t))\nCase conversion may be inaccurate. Consider using '#align set.is_wf_union Set.isWf_union\u2093'. -/\n@[simp]\ntheorem isWf_union : IsWf (s \u222a t) \u2194 IsWf s \u2227 IsWf t :=\n  wellFoundedOn_union\n#align set.is_wf_union Set.isWf_union\n\nend Preorder\n\nsection Preorder\n\nvariable [Preorder \u03b1] {s t : Set \u03b1} {a : \u03b1}\n\n#print Set.isWf_iff_no_descending_seq /-\ntheorem isWf_iff_no_descending_seq :\n    IsWf s \u2194 \u2200 f : \u2115 \u2192 \u03b1, StrictAnti f \u2192 \u00ac\u2200 n, f (OrderDual.toDual n) \u2208 s :=\n  wellFoundedOn_iff_no_descending_seq.trans\n    \u27e8fun H f hf => H \u27e8\u27e8f, hf.Injective\u27e9, fun a b => hf.lt_iff_lt\u27e9, fun H f =>\n      H f fun _ _ => f.map_rel_iff.2\u27e9\n#align set.is_wf_iff_no_descending_seq Set.isWf_iff_no_descending_seq\n-/\n\nend Preorder\n\n/-!\n### Partially well-ordered sets\n\nA set is partially well-ordered by a relation `r` when any infinite sequence contains two elements\nwhere the first is related to the second by `r`. Equivalently, any antichain (see `is_antichain`) is\nfinite, see `set.partially_well_ordered_on_iff_finite_antichains`.\n-/\n\n\n#print Set.PartiallyWellOrderedOn /-\n/-- A subset is partially well-ordered by a relation `r` when any infinite sequence contains\n  two elements where the first is related to the second by `r`. -/\ndef PartiallyWellOrderedOn (s : Set \u03b1) (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop :=\n  \u2200 f : \u2115 \u2192 \u03b1, (\u2200 n, f n \u2208 s) \u2192 \u2203 m n : \u2115, m < n \u2227 r (f m) (f n)\n#align set.partially_well_ordered_on Set.PartiallyWellOrderedOn\n-/\n\nsection PartiallyWellOrderedOn\n\nvariable {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {r' : \u03b2 \u2192 \u03b2 \u2192 Prop} {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1} {t : Set \u03b1} {a : \u03b1}\n\n#print Set.PartiallyWellOrderedOn.mono /-\ntheorem PartiallyWellOrderedOn.mono (ht : t.PartiallyWellOrderedOn r) (h : s \u2286 t) :\n    s.PartiallyWellOrderedOn r := fun f hf => ht f fun n => h <| hf n\n#align set.partially_well_ordered_on.mono Set.PartiallyWellOrderedOn.mono\n-/\n\n#print Set.partiallyWellOrderedOn_empty /-\n@[simp]\ntheorem partiallyWellOrderedOn_empty (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : PartiallyWellOrderedOn \u2205 r := fun f hf =>\n  (hf 0).elim\n#align set.partially_well_ordered_on_empty Set.partiallyWellOrderedOn_empty\n-/\n\n/- warning: set.partially_well_ordered_on.union -> Set.PartiallyWellOrderedOn.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) -> (Set.PartiallyWellOrderedOn.{u1} \u03b1 t r) -> (Set.PartiallyWellOrderedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t) r)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) -> (Set.PartiallyWellOrderedOn.{u1} \u03b1 t r) -> (Set.PartiallyWellOrderedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t) r)\nCase conversion may be inaccurate. Consider using '#align set.partially_well_ordered_on.union Set.PartiallyWellOrderedOn.union\u2093'. -/\ntheorem PartiallyWellOrderedOn.union (hs : s.PartiallyWellOrderedOn r)\n    (ht : t.PartiallyWellOrderedOn r) : (s \u222a t).PartiallyWellOrderedOn r :=\n  by\n  rintro f hf\n  rcases Nat.exists_subseq_of_forall_mem_union f hf with \u27e8g, hgs | hgt\u27e9\n  \u00b7 rcases hs _ hgs with \u27e8m, n, hlt, hr\u27e9\n    exact \u27e8g m, g n, g.strict_mono hlt, hr\u27e9\n  \u00b7 rcases ht _ hgt with \u27e8m, n, hlt, hr\u27e9\n    exact \u27e8g m, g n, g.strict_mono hlt, hr\u27e9\n#align set.partially_well_ordered_on.union Set.PartiallyWellOrderedOn.union\n\n/- warning: set.partially_well_ordered_on_union -> Set.partiallyWellOrderedOn_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.PartiallyWellOrderedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t) r) (And (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) (Set.PartiallyWellOrderedOn.{u1} \u03b1 t r))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.PartiallyWellOrderedOn.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t) r) (And (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) (Set.PartiallyWellOrderedOn.{u1} \u03b1 t r))\nCase conversion may be inaccurate. Consider using '#align set.partially_well_ordered_on_union Set.partiallyWellOrderedOn_union\u2093'. -/\n@[simp]\ntheorem partiallyWellOrderedOn_union :\n    (s \u222a t).PartiallyWellOrderedOn r \u2194 s.PartiallyWellOrderedOn r \u2227 t.PartiallyWellOrderedOn r :=\n  \u27e8fun h => \u27e8h.mono <| subset_union_left _ _, h.mono <| subset_union_right _ _\u27e9, fun h =>\n    h.1.union h.2\u27e9\n#align set.partially_well_ordered_on_union Set.partiallyWellOrderedOn_union\n\n/- warning: set.partially_well_ordered_on.image_of_monotone_on -> Set.PartiallyWellOrderedOn.image_of_monotone_on is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} {r : \u03b1 -> \u03b1 -> Prop} {r' : \u03b2 -> \u03b2 -> Prop} {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1}, (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) -> (forall (a\u2081 : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a\u2081 s) -> (forall (a\u2082 : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a\u2082 s) -> (r a\u2081 a\u2082) -> (r' (f a\u2081) (f a\u2082)))) -> (Set.PartiallyWellOrderedOn.{u2} \u03b2 (Set.image.{u1, u2} \u03b1 \u03b2 f s) r')\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {r' : \u03b2 -> \u03b2 -> Prop} {f : \u03b1 -> \u03b2} {s : Set.{u2} \u03b1}, (Set.PartiallyWellOrderedOn.{u2} \u03b1 s r) -> (forall (a\u2081 : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a\u2081 s) -> (forall (a\u2082 : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a\u2082 s) -> (r a\u2081 a\u2082) -> (r' (f a\u2081) (f a\u2082)))) -> (Set.PartiallyWellOrderedOn.{u1} \u03b2 (Set.image.{u2, u1} \u03b1 \u03b2 f s) r')\nCase conversion may be inaccurate. Consider using '#align set.partially_well_ordered_on.image_of_monotone_on Set.PartiallyWellOrderedOn.image_of_monotone_on\u2093'. -/\ntheorem PartiallyWellOrderedOn.image_of_monotone_on (hs : s.PartiallyWellOrderedOn r)\n    (hf : \u2200 a\u2081 \u2208 s, \u2200 a\u2082 \u2208 s, r a\u2081 a\u2082 \u2192 r' (f a\u2081) (f a\u2082)) : (f '' s).PartiallyWellOrderedOn r' :=\n  by\n  intro g' hg'\n  choose g hgs heq using hg'\n  obtain rfl : f \u2218 g = g'; exact funext HEq\n  obtain \u27e8m, n, hlt, hmn\u27e9 := hs g hgs\n  exact \u27e8m, n, hlt, hf _ (hgs m) _ (hgs n) hmn\u27e9\n#align set.partially_well_ordered_on.image_of_monotone_on Set.PartiallyWellOrderedOn.image_of_monotone_on\n\n#print IsAntichain.finite_of_partiallyWellOrderedOn /-\ntheorem IsAntichain.finite_of_partiallyWellOrderedOn (ha : IsAntichain r s)\n    (hp : s.PartiallyWellOrderedOn r) : s.Finite :=\n  by\n  refine' not_infinite.1 fun hi => _\n  obtain \u27e8m, n, hmn, h\u27e9 := hp (fun n => hi.nat_embedding _ n) fun n => (hi.nat_embedding _ n).2\n  exact\n    hmn.ne\n      ((hi.nat_embedding _).Injective <|\n        Subtype.val_injective <| ha.eq (hi.nat_embedding _ m).2 (hi.nat_embedding _ n).2 h)\n#align is_antichain.finite_of_partially_well_ordered_on IsAntichain.finite_of_partiallyWellOrderedOn\n-/\n\nsection IsRefl\n\nvariable [IsRefl \u03b1 r]\n\n#print Set.Finite.partiallyWellOrderedOn /-\nprotected theorem Finite.partiallyWellOrderedOn (hs : s.Finite) : s.PartiallyWellOrderedOn r :=\n  by\n  intro f hf\n  obtain \u27e8m, n, hmn, h\u27e9 := hs.exists_lt_map_eq_of_forall_mem hf\n  exact \u27e8m, n, hmn, h.subst <| refl (f m)\u27e9\n#align set.finite.partially_well_ordered_on Set.Finite.partiallyWellOrderedOn\n-/\n\n#print IsAntichain.partiallyWellOrderedOn_iff /-\ntheorem IsAntichain.partiallyWellOrderedOn_iff (hs : IsAntichain r s) :\n    s.PartiallyWellOrderedOn r \u2194 s.Finite :=\n  \u27e8hs.finite_of_partiallyWellOrderedOn, Finite.partiallyWellOrderedOn\u27e9\n#align is_antichain.partially_well_ordered_on_iff IsAntichain.partiallyWellOrderedOn_iff\n-/\n\n#print Set.partiallyWellOrderedOn_singleton /-\n@[simp]\ntheorem partiallyWellOrderedOn_singleton (a : \u03b1) : PartiallyWellOrderedOn {a} r :=\n  (finite_singleton a).PartiallyWellOrderedOn\n#align set.partially_well_ordered_on_singleton Set.partiallyWellOrderedOn_singleton\n-/\n\n#print Set.partiallyWellOrderedOn_insert /-\n@[simp]\ntheorem partiallyWellOrderedOn_insert :\n    PartiallyWellOrderedOn (insert a s) r \u2194 PartiallyWellOrderedOn s r := by\n  simp only [\u2190 singleton_union, partially_well_ordered_on_union,\n    partially_well_ordered_on_singleton, true_and_iff]\n#align set.partially_well_ordered_on_insert Set.partiallyWellOrderedOn_insert\n-/\n\n#print Set.PartiallyWellOrderedOn.insert /-\nprotected theorem PartiallyWellOrderedOn.insert (h : PartiallyWellOrderedOn s r) (a : \u03b1) :\n    PartiallyWellOrderedOn (insert a s) r :=\n  partiallyWellOrderedOn_insert.2 h\n#align set.partially_well_ordered_on.insert Set.PartiallyWellOrderedOn.insert\n-/\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (t \u00abexpr \u2286 \u00bb s) -/\n#print Set.partiallyWellOrderedOn_iff_finite_antichains /-\ntheorem partiallyWellOrderedOn_iff_finite_antichains [IsSymm \u03b1 r] :\n    s.PartiallyWellOrderedOn r \u2194 \u2200 (t) (_ : t \u2286 s), IsAntichain r t \u2192 t.Finite :=\n  by\n  refine' \u27e8fun h t ht hrt => hrt.finite_of_partiallyWellOrderedOn (h.mono ht), _\u27e9\n  rintro hs f hf\n  by_contra' H\n  refine' infinite_range_of_injective (fun m n hmn => _) (hs _ (range_subset_iff.2 hf) _)\n  \u00b7 obtain h | h | h := lt_trichotomy m n\n    \u00b7 refine' (H _ _ h _).elim\n      rw [hmn]\n      exact refl _\n    \u00b7 exact h\n    \u00b7 refine' (H _ _ h _).elim\n      rw [hmn]\n      exact refl _\n  rintro _ \u27e8m, hm, rfl\u27e9 _ \u27e8n, hn, rfl\u27e9 hmn\n  obtain h | h := (ne_of_apply_ne _ hmn).lt_or_lt\n  \u00b7 exact H _ _ h\n  \u00b7 exact mt symm (H _ _ h)\n#align set.partially_well_ordered_on_iff_finite_antichains Set.partiallyWellOrderedOn_iff_finite_antichains\n-/\n\nvariable [IsTrans \u03b1 r]\n\n/- warning: set.partially_well_ordered_on.exists_monotone_subseq -> Set.PartiallyWellOrderedOn.exists_monotone_subseq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} [_inst_1 : IsRefl.{u1} \u03b1 r] [_inst_2 : IsTrans.{u1} \u03b1 r], (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) -> (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (g : OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) => forall (m : Nat) (n : Nat), (LE.le.{0} Nat Nat.hasLe m n) -> (r (f (coeFn.{1, 1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (_x : RelEmbedding.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) => Nat -> Nat) (RelEmbedding.hasCoeToFun.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) g m)) (f (coeFn.{1, 1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (_x : RelEmbedding.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) => Nat -> Nat) (RelEmbedding.hasCoeToFun.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) g n))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} [_inst_1 : IsRefl.{u1} \u03b1 r] [_inst_2 : IsTrans.{u1} \u03b1 r], (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) -> (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) (fun (g : OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) => forall (m : Nat) (n : Nat), (LE.le.{0} Nat instLENat m n) -> (r (f (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => Nat) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat Nat (Function.instEmbeddingLikeEmbedding.{1, 1} Nat Nat)) (RelEmbedding.toEmbedding.{0, 0} Nat Nat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) g) m)) (f (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => Nat) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat Nat (Function.instEmbeddingLikeEmbedding.{1, 1} Nat Nat)) (RelEmbedding.toEmbedding.{0, 0} Nat Nat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) g) n))))))\nCase conversion may be inaccurate. Consider using '#align set.partially_well_ordered_on.exists_monotone_subseq Set.PartiallyWellOrderedOn.exists_monotone_subseq\u2093'. -/\ntheorem PartiallyWellOrderedOn.exists_monotone_subseq (h : s.PartiallyWellOrderedOn r) (f : \u2115 \u2192 \u03b1)\n    (hf : \u2200 n, f n \u2208 s) : \u2203 g : \u2115 \u21aao \u2115, \u2200 m n : \u2115, m \u2264 n \u2192 r (f (g m)) (f (g n)) :=\n  by\n  obtain \u27e8g, h1 | h2\u27e9 := exists_increasing_or_nonincreasing_subseq r f\n  \u00b7 refine' \u27e8g, fun m n hle => _\u27e9\n    obtain hlt | rfl := hle.lt_or_eq\n    exacts[h1 m n hlt, refl_of r _]\n  \u00b7 exfalso\n    obtain \u27e8m, n, hlt, hle\u27e9 := h (f \u2218 g) fun n => hf _\n    exact h2 m n hlt hle\n#align set.partially_well_ordered_on.exists_monotone_subseq Set.PartiallyWellOrderedOn.exists_monotone_subseq\n\n/- warning: set.partially_well_ordered_on_iff_exists_monotone_subseq -> Set.partiallyWellOrderedOn_iff_exists_monotone_subseq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} [_inst_1 : IsRefl.{u1} \u03b1 r] [_inst_2 : IsTrans.{u1} \u03b1 r], Iff (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (g : OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) => forall (m : Nat) (n : Nat), (LE.le.{0} Nat Nat.hasLe m n) -> (r (f (coeFn.{1, 1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (_x : RelEmbedding.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) => Nat -> Nat) (RelEmbedding.hasCoeToFun.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) g m)) (f (coeFn.{1, 1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (_x : RelEmbedding.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) => Nat -> Nat) (RelEmbedding.hasCoeToFun.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) g n))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} {s : Set.{u1} \u03b1} [_inst_1 : IsRefl.{u1} \u03b1 r] [_inst_2 : IsTrans.{u1} \u03b1 r], Iff (Set.PartiallyWellOrderedOn.{u1} \u03b1 s r) (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) (fun (g : OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) => forall (m : Nat) (n : Nat), (LE.le.{0} Nat instLENat m n) -> (r (f (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => Nat) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat Nat (Function.instEmbeddingLikeEmbedding.{1, 1} Nat Nat)) (RelEmbedding.toEmbedding.{0, 0} Nat Nat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) g) m)) (f (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => Nat) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat Nat (Function.instEmbeddingLikeEmbedding.{1, 1} Nat Nat)) (RelEmbedding.toEmbedding.{0, 0} Nat Nat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) g) n))))))\nCase conversion may be inaccurate. Consider using '#align set.partially_well_ordered_on_iff_exists_monotone_subseq Set.partiallyWellOrderedOn_iff_exists_monotone_subseq\u2093'. -/\ntheorem partiallyWellOrderedOn_iff_exists_monotone_subseq :\n    s.PartiallyWellOrderedOn r \u2194\n      \u2200 f : \u2115 \u2192 \u03b1, (\u2200 n, f n \u2208 s) \u2192 \u2203 g : \u2115 \u21aao \u2115, \u2200 m n : \u2115, m \u2264 n \u2192 r (f (g m)) (f (g n)) :=\n  by\n  classical\n    constructor <;> intro h f hf\n    \u00b7 exact h.exists_monotone_subseq f hf\n    \u00b7 obtain \u27e8g, gmon\u27e9 := h f hf\n      exact \u27e8g 0, g 1, g.lt_iff_lt.2 zero_lt_one, gmon _ _ zero_le_one\u27e9\n#align set.partially_well_ordered_on_iff_exists_monotone_subseq Set.partiallyWellOrderedOn_iff_exists_monotone_subseq\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n#print Set.PartiallyWellOrderedOn.prod /-\nprotected theorem PartiallyWellOrderedOn.prod {t : Set \u03b2} (hs : PartiallyWellOrderedOn s r)\n    (ht : PartiallyWellOrderedOn t r') :\n    PartiallyWellOrderedOn (s \u00d7\u02e2 t) fun x y : \u03b1 \u00d7 \u03b2 => r x.1 y.1 \u2227 r' x.2 y.2 :=\n  by\n  intro f hf\n  obtain \u27e8g\u2081, h\u2081\u27e9 := hs.exists_monotone_subseq (Prod.fst \u2218 f) fun n => (hf n).1\n  obtain \u27e8m, n, hlt, hle\u27e9 := ht (Prod.snd \u2218 f \u2218 g\u2081) fun n => (hf _).2\n  exact \u27e8g\u2081 m, g\u2081 n, g\u2081.strict_mono hlt, h\u2081 _ _ hlt.le, hle\u27e9\n#align set.partially_well_ordered_on.prod Set.PartiallyWellOrderedOn.prod\n-/\n\nend IsRefl\n\n#print Set.PartiallyWellOrderedOn.wellFoundedOn /-\ntheorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder \u03b1 r] (h : s.PartiallyWellOrderedOn r) :\n    s.WellFoundedOn fun a b => r a b \u2227 \u00acr b a :=\n  by\n  letI : Preorder \u03b1 :=\n    { le := r\n      le_refl := refl_of r\n      le_trans := fun _ _ _ => trans_of r }\n  change s.well_founded_on (\u00b7 < \u00b7); change s.partially_well_ordered_on (\u00b7 \u2264 \u00b7) at h\n  rw [well_founded_on_iff_no_descending_seq]\n  intro f hf\n  obtain \u27e8m, n, hlt, hle\u27e9 := h f hf\n  exact (f.map_rel_iff.2 hlt).not_le hle\n#align set.partially_well_ordered_on.well_founded_on Set.PartiallyWellOrderedOn.wellFoundedOn\n-/\n\nend PartiallyWellOrderedOn\n\nsection IsPwo\n\nvariable [Preorder \u03b1] [Preorder \u03b2] {s t : Set \u03b1}\n\n#print Set.IsPwo /-\n/-- A subset of a preorder is partially well-ordered when any infinite sequence contains\n  a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). -/\ndef IsPwo (s : Set \u03b1) : Prop :=\n  PartiallyWellOrderedOn s (\u00b7 \u2264 \u00b7)\n#align set.is_pwo Set.IsPwo\n-/\n\n#print Set.IsPwo.mono /-\ntheorem IsPwo.mono (ht : t.IsPwo) : s \u2286 t \u2192 s.IsPwo :=\n  ht.mono\n#align set.is_pwo.mono Set.IsPwo.mono\n-/\n\n/- warning: set.is_pwo.exists_monotone_subseq -> Set.IsPwo.exists_monotone_subseq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (g : OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) => Monotone.{0, u1} Nat \u03b1 (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) _inst_1 (Function.comp.{1, 1, succ u1} Nat Nat \u03b1 f (coeFn.{1, 1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (_x : RelEmbedding.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) => Nat -> Nat) (RelEmbedding.hasCoeToFun.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) g)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) (fun (g : OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) => Monotone.{0, u1} Nat \u03b1 (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) _inst_1 (Function.comp.{1, 1, succ u1} Nat Nat \u03b1 f (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => Nat) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat Nat (Function.instEmbeddingLikeEmbedding.{1, 1} Nat Nat)) (RelEmbedding.toEmbedding.{0, 0} Nat Nat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) g))))))\nCase conversion may be inaccurate. Consider using '#align set.is_pwo.exists_monotone_subseq Set.IsPwo.exists_monotone_subseq\u2093'. -/\ntheorem IsPwo.exists_monotone_subseq (h : s.IsPwo) (f : \u2115 \u2192 \u03b1) (hf : \u2200 n, f n \u2208 s) :\n    \u2203 g : \u2115 \u21aao \u2115, Monotone (f \u2218 g) :=\n  h.exists_monotone_subseq f hf\n#align set.is_pwo.exists_monotone_subseq Set.IsPwo.exists_monotone_subseq\n\n/- warning: set.is_pwo_iff_exists_monotone_subseq -> Set.isPwo_iff_exists_monotone_subseq is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Set.IsPwo.{u1} \u03b1 _inst_1 s) (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (g : OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) => Monotone.{0, u1} Nat \u03b1 (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) _inst_1 (Function.comp.{1, 1, succ u1} Nat Nat \u03b1 f (coeFn.{1, 1} (OrderEmbedding.{0, 0} Nat Nat Nat.hasLe Nat.hasLe) (fun (_x : RelEmbedding.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) => Nat -> Nat) (RelEmbedding.hasCoeToFun.{0, 0} Nat Nat (LE.le.{0} Nat Nat.hasLe) (LE.le.{0} Nat Nat.hasLe)) g)))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1}, Iff (Set.IsPwo.{u1} \u03b1 _inst_1 s) (forall (f : Nat -> \u03b1), (forall (n : Nat), Membership.mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.instMembershipSet.{u1} \u03b1) (f n) s) -> (Exists.{1} (OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) (fun (g : OrderEmbedding.{0, 0} Nat Nat instLENat instLENat) => Monotone.{0, u1} Nat \u03b1 (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) _inst_1 (Function.comp.{1, 1, succ u1} Nat Nat \u03b1 f (FunLike.coe.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat (fun (_x : Nat) => (fun (x._@.Mathlib.Data.FunLike.Embedding._hyg.19 : Nat) => Nat) _x) (EmbeddingLike.toFunLike.{1, 1, 1} (Function.Embedding.{1, 1} Nat Nat) Nat Nat (Function.instEmbeddingLikeEmbedding.{1, 1} Nat Nat)) (RelEmbedding.toEmbedding.{0, 0} Nat Nat (fun (x._@.Mathlib.Order.Hom.Basic._hyg.680 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.682 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.680 x._@.Mathlib.Order.Hom.Basic._hyg.682) (fun (x._@.Mathlib.Order.Hom.Basic._hyg.695 : Nat) (x._@.Mathlib.Order.Hom.Basic._hyg.697 : Nat) => LE.le.{0} Nat instLENat x._@.Mathlib.Order.Hom.Basic._hyg.695 x._@.Mathlib.Order.Hom.Basic._hyg.697) g))))))\nCase conversion may be inaccurate. Consider using '#align set.is_pwo_iff_exists_monotone_subseq Set.isPwo_iff_exists_monotone_subseq\u2093'. -/\ntheorem isPwo_iff_exists_monotone_subseq :\n    s.IsPwo \u2194 \u2200 f : \u2115 \u2192 \u03b1, (\u2200 n, f n \u2208 s) \u2192 \u2203 g : \u2115 \u21aao \u2115, Monotone (f \u2218 g) :=\n  partiallyWellOrderedOn_iff_exists_monotone_subseq\n#align set.is_pwo_iff_exists_monotone_subseq Set.isPwo_iff_exists_monotone_subseq\n\n#print Set.IsPwo.isWf /-\nprotected theorem IsPwo.isWf (h : s.IsPwo) : s.IsWf := by\n  simpa only [\u2190 lt_iff_le_not_le] using h.well_founded_on\n#align set.is_pwo.is_wf Set.IsPwo.isWf\n-/\n\n/- warning: set.is_pwo.prod -> Set.IsPwo.prod is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{u1} \u03b1} {t : Set.{u2} \u03b2}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (Set.IsPwo.{u2} \u03b2 _inst_2 t) -> (Set.IsPwo.{max u1 u2} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.preorder.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (Set.prod.{u1, u2} \u03b1 \u03b2 s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{u1} \u03b1} {t : Set.{u2} \u03b2}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (Set.IsPwo.{u2} \u03b2 _inst_2 t) -> (Set.IsPwo.{max u2 u1} (Prod.{u1, u2} \u03b1 \u03b2) (Prod.instPreorderProd.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2) (Set.prod.{u1, u2} \u03b1 \u03b2 s t))\nCase conversion may be inaccurate. Consider using '#align set.is_pwo.prod Set.IsPwo.prod\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem IsPwo.prod {t : Set \u03b2} (hs : s.IsPwo) (ht : t.IsPwo) : IsPwo (s \u00d7\u02e2 t) :=\n  hs.Prod ht\n#align set.is_pwo.prod Set.IsPwo.prod\n\n/- warning: set.is_pwo.image_of_monotone_on -> Set.IsPwo.image_of_monotoneOn is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{u1} \u03b1}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (forall {f : \u03b1 -> \u03b2}, (MonotoneOn.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f s) -> (Set.IsPwo.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : Preorder.{u2} \u03b1] [_inst_2 : Preorder.{u1} \u03b2] {s : Set.{u2} \u03b1}, (Set.IsPwo.{u2} \u03b1 _inst_1 s) -> (forall {f : \u03b1 -> \u03b2}, (MonotoneOn.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f s) -> (Set.IsPwo.{u1} \u03b2 _inst_2 (Set.image.{u2, u1} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align set.is_pwo.image_of_monotone_on Set.IsPwo.image_of_monotoneOn\u2093'. -/\ntheorem IsPwo.image_of_monotoneOn (hs : s.IsPwo) {f : \u03b1 \u2192 \u03b2} (hf : MonotoneOn f s) :\n    IsPwo (f '' s) :=\n  hs.image_of_monotone_on hf\n#align set.is_pwo.image_of_monotone_on Set.IsPwo.image_of_monotoneOn\n\n/- warning: set.is_pwo.image_of_monotone -> Set.IsPwo.image_of_monotone is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} \u03b2] {s : Set.{u1} \u03b1}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (forall {f : \u03b1 -> \u03b2}, (Monotone.{u1, u2} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (Set.IsPwo.{u2} \u03b2 _inst_2 (Set.image.{u1, u2} \u03b1 \u03b2 f s)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : Preorder.{u2} \u03b1] [_inst_2 : Preorder.{u1} \u03b2] {s : Set.{u2} \u03b1}, (Set.IsPwo.{u2} \u03b1 _inst_1 s) -> (forall {f : \u03b1 -> \u03b2}, (Monotone.{u2, u1} \u03b1 \u03b2 _inst_1 _inst_2 f) -> (Set.IsPwo.{u1} \u03b2 _inst_2 (Set.image.{u2, u1} \u03b1 \u03b2 f s)))\nCase conversion may be inaccurate. Consider using '#align set.is_pwo.image_of_monotone Set.IsPwo.image_of_monotone\u2093'. -/\ntheorem IsPwo.image_of_monotone (hs : s.IsPwo) {f : \u03b1 \u2192 \u03b2} (hf : Monotone f) : IsPwo (f '' s) :=\n  hs.image_of_monotone_on (hf.MonotoneOn _)\n#align set.is_pwo.image_of_monotone Set.IsPwo.image_of_monotone\n\n/- warning: set.is_pwo.union -> Set.IsPwo.union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (Set.IsPwo.{u1} \u03b1 _inst_1 t) -> (Set.IsPwo.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, (Set.IsPwo.{u1} \u03b1 _inst_1 s) -> (Set.IsPwo.{u1} \u03b1 _inst_1 t) -> (Set.IsPwo.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t))\nCase conversion may be inaccurate. Consider using '#align set.is_pwo.union Set.IsPwo.union\u2093'. -/\nprotected theorem IsPwo.union (hs : IsPwo s) (ht : IsPwo t) : IsPwo (s \u222a t) :=\n  hs.union ht\n#align set.is_pwo.union Set.IsPwo.union\n\n/- warning: set.is_pwo_union -> Set.isPwo_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.IsPwo.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) (And (Set.IsPwo.{u1} \u03b1 _inst_1 s) (Set.IsPwo.{u1} \u03b1 _inst_1 t))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1}, Iff (Set.IsPwo.{u1} \u03b1 _inst_1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t)) (And (Set.IsPwo.{u1} \u03b1 _inst_1 s) (Set.IsPwo.{u1} \u03b1 _inst_1 t))\nCase conversion may be inaccurate. Consider using '#align set.is_pwo_union Set.isPwo_union\u2093'. -/\n@[simp]\ntheorem isPwo_union : IsPwo (s \u222a t) \u2194 IsPwo s \u2227 IsPwo t :=\n  partiallyWellOrderedOn_union\n#align set.is_pwo_union Set.isPwo_union\n\n#print Set.Finite.isPwo /-\nprotected theorem Finite.isPwo (hs : s.Finite) : IsPwo s :=\n  hs.PartiallyWellOrderedOn\n#align set.finite.is_pwo Set.Finite.isPwo\n-/\n\n#print Set.isPwo_of_finite /-\n@[simp]\ntheorem isPwo_of_finite [Finite \u03b1] : s.IsPwo :=\n  s.toFinite.IsPwo\n#align set.is_pwo_of_finite Set.isPwo_of_finite\n-/\n\n#print Set.isPwo_singleton /-\n@[simp]\ntheorem isPwo_singleton (a : \u03b1) : IsPwo ({a} : Set \u03b1) :=\n  (finite_singleton a).IsPwo\n#align set.is_pwo_singleton Set.isPwo_singleton\n-/\n\n#print Set.isPwo_empty /-\n@[simp]\ntheorem isPwo_empty : IsPwo (\u2205 : Set \u03b1) :=\n  finite_empty.IsPwo\n#align set.is_pwo_empty Set.isPwo_empty\n-/\n\n#print Set.Subsingleton.isPwo /-\nprotected theorem Subsingleton.isPwo (hs : s.Subsingleton) : IsPwo s :=\n  hs.Finite.IsPwo\n#align set.subsingleton.is_pwo Set.Subsingleton.isPwo\n-/\n\n#print Set.isPwo_insert /-\n@[simp]\ntheorem isPwo_insert {a} : IsPwo (insert a s) \u2194 IsPwo s := by\n  simp only [\u2190 singleton_union, is_pwo_union, is_pwo_singleton, true_and_iff]\n#align set.is_pwo_insert Set.isPwo_insert\n-/\n\n#print Set.IsPwo.insert /-\nprotected theorem IsPwo.insert (h : IsPwo s) (a : \u03b1) : IsPwo (insert a s) :=\n  isPwo_insert.2 h\n#align set.is_pwo.insert Set.IsPwo.insert\n-/\n\n#print Set.Finite.isWf /-\nprotected theorem Finite.isWf (hs : s.Finite) : IsWf s :=\n  hs.IsPwo.IsWf\n#align set.finite.is_wf Set.Finite.isWf\n-/\n\n#print Set.isWf_singleton /-\n@[simp]\ntheorem isWf_singleton {a : \u03b1} : IsWf ({a} : Set \u03b1) :=\n  (finite_singleton a).IsWf\n#align set.is_wf_singleton Set.isWf_singleton\n-/\n\n#print Set.Subsingleton.isWf /-\nprotected theorem Subsingleton.isWf (hs : s.Subsingleton) : IsWf s :=\n  hs.IsPwo.IsWf\n#align set.subsingleton.is_wf Set.Subsingleton.isWf\n-/\n\n#print Set.isWf_insert /-\n@[simp]\ntheorem isWf_insert {a} : IsWf (insert a s) \u2194 IsWf s := by\n  simp only [\u2190 singleton_union, is_wf_union, is_wf_singleton, true_and_iff]\n#align set.is_wf_insert Set.isWf_insert\n-/\n\n#print Set.IsWf.insert /-\ntheorem IsWf.insert (h : IsWf s) (a : \u03b1) : IsWf (insert a s) :=\n  isWf_insert.2 h\n#align set.is_wf.insert Set.IsWf.insert\n-/\n\nend IsPwo\n\nsection WellFoundedOn\n\nvariable {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [IsStrictOrder \u03b1 r] {s : Set \u03b1} {a : \u03b1}\n\n#print Set.Finite.wellFoundedOn /-\nprotected theorem Finite.wellFoundedOn (hs : s.Finite) : s.WellFoundedOn r :=\n  letI := partialOrderOfSO r\n  hs.is_wf\n#align set.finite.well_founded_on Set.Finite.wellFoundedOn\n-/\n\n#print Set.wellFoundedOn_singleton /-\n@[simp]\ntheorem wellFoundedOn_singleton : WellFoundedOn ({a} : Set \u03b1) r :=\n  (finite_singleton a).WellFoundedOn\n#align set.well_founded_on_singleton Set.wellFoundedOn_singleton\n-/\n\n#print Set.Subsingleton.wellFoundedOn /-\nprotected theorem Subsingleton.wellFoundedOn (hs : s.Subsingleton) : s.WellFoundedOn r :=\n  hs.Finite.WellFoundedOn\n#align set.subsingleton.well_founded_on Set.Subsingleton.wellFoundedOn\n-/\n\n#print Set.wellFoundedOn_insert /-\n@[simp]\ntheorem wellFoundedOn_insert : WellFoundedOn (insert a s) r \u2194 WellFoundedOn s r := by\n  simp only [\u2190 singleton_union, well_founded_on_union, well_founded_on_singleton, true_and_iff]\n#align set.well_founded_on_insert Set.wellFoundedOn_insert\n-/\n\n#print Set.WellFoundedOn.insert /-\ntheorem WellFoundedOn.insert (h : WellFoundedOn s r) (a : \u03b1) : WellFoundedOn (insert a s) r :=\n  wellFoundedOn_insert.2 h\n#align set.well_founded_on.insert Set.WellFoundedOn.insert\n-/\n\nend WellFoundedOn\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] {s : Set \u03b1}\n\n#print Set.IsWf.isPwo /-\nprotected theorem IsWf.isPwo (hs : s.IsWf) : s.IsPwo :=\n  by\n  intro f hf\n  lift f to \u2115 \u2192 s using hf\n  have hrange : (range f).Nonempty := range_nonempty _\n  rcases hs.has_min (range f) (range_nonempty _) with \u27e8_, \u27e8m, rfl\u27e9, hm\u27e9\n  simp only [forall_range_iff, not_lt] at hm\n  exact \u27e8m, m + 1, lt_add_one m, hm _\u27e9\n#align set.is_wf.is_pwo Set.IsWf.isPwo\n-/\n\n#print Set.isWf_iff_isPwo /-\n/-- In a linear order, the predicates `set.is_wf` and `set.is_pwo` are equivalent. -/\ntheorem isWf_iff_isPwo : s.IsWf \u2194 s.IsPwo :=\n  \u27e8IsWf.isPwo, IsPwo.isWf\u27e9\n#align set.is_wf_iff_is_pwo Set.isWf_iff_isPwo\n-/\n\nend LinearOrder\n\nend Set\n\nnamespace Finset\n\nvariable {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\n#print Finset.partiallyWellOrderedOn /-\n@[simp]\nprotected theorem partiallyWellOrderedOn [IsRefl \u03b1 r] (s : Finset \u03b1) :\n    (s : Set \u03b1).PartiallyWellOrderedOn r :=\n  s.finite_toSet.PartiallyWellOrderedOn\n#align finset.partially_well_ordered_on Finset.partiallyWellOrderedOn\n-/\n\n#print Finset.isPwo /-\n@[simp]\nprotected theorem isPwo [Preorder \u03b1] (s : Finset \u03b1) : Set.IsPwo (\u2191s : Set \u03b1) :=\n  s.PartiallyWellOrderedOn\n#align finset.is_pwo Finset.isPwo\n-/\n\n#print Finset.isWf /-\n@[simp]\nprotected theorem isWf [Preorder \u03b1] (s : Finset \u03b1) : Set.IsWf (\u2191s : Set \u03b1) :=\n  s.finite_toSet.IsWf\n#align finset.is_wf Finset.isWf\n-/\n\n#print Finset.wellFoundedOn /-\n@[simp]\nprotected theorem wellFoundedOn [IsStrictOrder \u03b1 r] (s : Finset \u03b1) :\n    Set.WellFoundedOn (\u2191s : Set \u03b1) r :=\n  letI := partialOrderOfSO r\n  s.is_wf\n#align finset.well_founded_on Finset.wellFoundedOn\n-/\n\n/- warning: finset.well_founded_on_sup -> Finset.wellFoundedOn_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u2} \u03b1 r] (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.WellFoundedOn.{u2} \u03b1 (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.completeBooleanAlgebra.{u2} \u03b1))))))) (GeneralizedBooleanAlgebra.toOrderBot.{u2} (Set.{u2} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} \u03b1) (Set.booleanAlgebra.{u2} \u03b1))) s f) r) (forall (i : \u03b9), (Membership.Mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.hasMem.{u1} \u03b9) i s) -> (Set.WellFoundedOn.{u2} \u03b1 (f i) r))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsStrictOrder.{u2} \u03b1 r] (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.WellFoundedOn.{u2} \u03b1 (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1))))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (SemilatticeSup.toPartialOrder.{u2} (Set.{u2} \u03b1) (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) s f) r) (forall (i : \u03b9), (Membership.mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.instMembershipFinset.{u1} \u03b9) i s) -> (Set.WellFoundedOn.{u2} \u03b1 (f i) r))\nCase conversion may be inaccurate. Consider using '#align finset.well_founded_on_sup Finset.wellFoundedOn_sup\u2093'. -/\ntheorem wellFoundedOn_sup [IsStrictOrder \u03b1 r] (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (s.sup f).WellFoundedOn r \u2194 \u2200 i \u2208 s, (f i).WellFoundedOn r :=\n  Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_bUnion, hs]\n#align finset.well_founded_on_sup Finset.wellFoundedOn_sup\n\n/- warning: finset.partially_well_ordered_on_sup -> Finset.partiallyWellOrderedOn_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {r : \u03b1 -> \u03b1 -> Prop} (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.PartiallyWellOrderedOn.{u2} \u03b1 (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.completeBooleanAlgebra.{u2} \u03b1))))))) (GeneralizedBooleanAlgebra.toOrderBot.{u2} (Set.{u2} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} \u03b1) (Set.booleanAlgebra.{u2} \u03b1))) s f) r) (forall (i : \u03b9), (Membership.Mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.hasMem.{u1} \u03b9) i s) -> (Set.PartiallyWellOrderedOn.{u2} \u03b1 (f i) r))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} (s : Finset.{u2} \u03b9) {f : \u03b9 -> (Set.{u1} \u03b1)}, Iff (Set.PartiallyWellOrderedOn.{u1} \u03b1 (Finset.sup.{u1, u2} (Set.{u1} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u1} (Set.{u1} \u03b1) (ConditionallyCompleteLattice.toLattice.{u1} (Set.{u1} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} \u03b1) (Preorder.toLE.{u1} (Set.{u1} \u03b1) (PartialOrder.toPreorder.{u1} (Set.{u1} \u03b1) (SemilatticeSup.toPartialOrder.{u1} (Set.{u1} \u03b1) (Lattice.toSemilatticeSup.{u1} (Set.{u1} \u03b1) (ConditionallyCompleteLattice.toLattice.{u1} (Set.{u1} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1)))))))))) (CompleteLattice.toBoundedOrder.{u1} (Set.{u1} \u03b1) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} \u03b1) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u1} \u03b1)))))) s f) r) (forall (i : \u03b9), (Membership.mem.{u2, u2} \u03b9 (Finset.{u2} \u03b9) (Finset.instMembershipFinset.{u2} \u03b9) i s) -> (Set.PartiallyWellOrderedOn.{u1} \u03b1 (f i) r))\nCase conversion may be inaccurate. Consider using '#align finset.partially_well_ordered_on_sup Finset.partiallyWellOrderedOn_sup\u2093'. -/\ntheorem partiallyWellOrderedOn_sup (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (s.sup f).PartiallyWellOrderedOn r \u2194 \u2200 i \u2208 s, (f i).PartiallyWellOrderedOn r :=\n  Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_bUnion, hs]\n#align finset.partially_well_ordered_on_sup Finset.partiallyWellOrderedOn_sup\n\n/- warning: finset.is_wf_sup -> Finset.isWf_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : Preorder.{u2} \u03b1] (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.IsWf.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 _inst_1) (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.completeBooleanAlgebra.{u2} \u03b1))))))) (GeneralizedBooleanAlgebra.toOrderBot.{u2} (Set.{u2} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} \u03b1) (Set.booleanAlgebra.{u2} \u03b1))) s f)) (forall (i : \u03b9), (Membership.Mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.hasMem.{u1} \u03b9) i s) -> (Set.IsWf.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 _inst_1) (f i)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : Preorder.{u2} \u03b1] (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.IsWf.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 _inst_1) (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1))))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (SemilatticeSup.toPartialOrder.{u2} (Set.{u2} \u03b1) (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) s f)) (forall (i : \u03b9), (Membership.mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.instMembershipFinset.{u1} \u03b9) i s) -> (Set.IsWf.{u2} \u03b1 (Preorder.toLT.{u2} \u03b1 _inst_1) (f i)))\nCase conversion may be inaccurate. Consider using '#align finset.is_wf_sup Finset.isWf_sup\u2093'. -/\ntheorem isWf_sup [Preorder \u03b1] (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (s.sup f).IsWf \u2194 \u2200 i \u2208 s, (f i).IsWf :=\n  s.wellFoundedOn_sup\n#align finset.is_wf_sup Finset.isWf_sup\n\n/- warning: finset.is_pwo_sup -> Finset.isPwo_sup is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : Preorder.{u2} \u03b1] (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.IsPwo.{u2} \u03b1 _inst_1 (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.completeBooleanAlgebra.{u2} \u03b1))))))) (GeneralizedBooleanAlgebra.toOrderBot.{u2} (Set.{u2} \u03b1) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} \u03b1) (Set.booleanAlgebra.{u2} \u03b1))) s f)) (forall (i : \u03b9), (Membership.Mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.hasMem.{u1} \u03b9) i s) -> (Set.IsPwo.{u2} \u03b1 _inst_1 (f i)))\nbut is expected to have type\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : Preorder.{u2} \u03b1] (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.IsPwo.{u2} \u03b1 _inst_1 (Finset.sup.{u2, u1} (Set.{u2} \u03b1) \u03b9 (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1))))))) (BoundedOrder.toOrderBot.{u2} (Set.{u2} \u03b1) (Preorder.toLE.{u2} (Set.{u2} \u03b1) (PartialOrder.toPreorder.{u2} (Set.{u2} \u03b1) (SemilatticeSup.toPartialOrder.{u2} (Set.{u2} \u03b1) (Lattice.toSemilatticeSup.{u2} (Set.{u2} \u03b1) (ConditionallyCompleteLattice.toLattice.{u2} (Set.{u2} \u03b1) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))))))) (CompleteLattice.toBoundedOrder.{u2} (Set.{u2} \u03b1) (Order.Coframe.toCompleteLattice.{u2} (Set.{u2} \u03b1) (CompleteDistribLattice.toCoframe.{u2} (Set.{u2} \u03b1) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u2} (Set.{u2} \u03b1) (Set.instCompleteBooleanAlgebraSet.{u2} \u03b1)))))) s f)) (forall (i : \u03b9), (Membership.mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.instMembershipFinset.{u1} \u03b9) i s) -> (Set.IsPwo.{u2} \u03b1 _inst_1 (f i)))\nCase conversion may be inaccurate. Consider using '#align finset.is_pwo_sup Finset.isPwo_sup\u2093'. -/\ntheorem isPwo_sup [Preorder \u03b1] (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (s.sup f).IsPwo \u2194 \u2200 i \u2208 s, (f i).IsPwo :=\n  s.partiallyWellOrderedOn_sup\n#align finset.is_pwo_sup Finset.isPwo_sup\n\n#print Finset.wellFoundedOn_bUnion /-\n@[simp]\ntheorem wellFoundedOn_bUnion [IsStrictOrder \u03b1 r] (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (\u22c3 i \u2208 s, f i).WellFoundedOn r \u2194 \u2200 i \u2208 s, (f i).WellFoundedOn r := by\n  simpa only [Finset.sup_eq_sup\u1d62] using s.well_founded_on_sup\n#align finset.well_founded_on_bUnion Finset.wellFoundedOn_bUnion\n-/\n\n/- warning: finset.partially_well_ordered_on_bUnion -> Finset.partiallyWellOrderedOn_bUnion is a dubious translation:\nlean 3 declaration is\n  forall {\u03b9 : Type.{u1}} {\u03b1 : Type.{u2}} {r : \u03b1 -> \u03b1 -> Prop} (s : Finset.{u1} \u03b9) {f : \u03b9 -> (Set.{u2} \u03b1)}, Iff (Set.PartiallyWellOrderedOn.{u2} \u03b1 (Set.union\u1d62.{u2, succ u1} \u03b1 \u03b9 (fun (i : \u03b9) => Set.union\u1d62.{u2, 0} \u03b1 (Membership.Mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.hasMem.{u1} \u03b9) i s) (fun (H : Membership.Mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.hasMem.{u1} \u03b9) i s) => f i))) r) (forall (i : \u03b9), (Membership.Mem.{u1, u1} \u03b9 (Finset.{u1} \u03b9) (Finset.hasMem.{u1} \u03b9) i s) -> (Set.PartiallyWellOrderedOn.{u2} \u03b1 (f i) r))\nbut is expected to have type\n  forall {\u03b9 : Type.{u2}} {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} (s : Finset.{u2} \u03b9) {f : \u03b9 -> (Set.{u1} \u03b1)}, Iff (Set.PartiallyWellOrderedOn.{u1} \u03b1 (Set.union\u1d62.{u1, succ u2} \u03b1 \u03b9 (fun (i : \u03b9) => Set.union\u1d62.{u1, 0} \u03b1 (Membership.mem.{u2, u2} \u03b9 (Finset.{u2} \u03b9) (Finset.instMembershipFinset.{u2} \u03b9) i s) (fun (H : Membership.mem.{u2, u2} \u03b9 (Finset.{u2} \u03b9) (Finset.instMembershipFinset.{u2} \u03b9) i s) => f i))) r) (forall (i : \u03b9), (Membership.mem.{u2, u2} \u03b9 (Finset.{u2} \u03b9) (Finset.instMembershipFinset.{u2} \u03b9) i s) -> (Set.PartiallyWellOrderedOn.{u1} \u03b1 (f i) r))\nCase conversion may be inaccurate. Consider using '#align finset.partially_well_ordered_on_bUnion Finset.partiallyWellOrderedOn_bUnion\u2093'. -/\n@[simp]\ntheorem partiallyWellOrderedOn_bUnion (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (\u22c3 i \u2208 s, f i).PartiallyWellOrderedOn r \u2194 \u2200 i \u2208 s, (f i).PartiallyWellOrderedOn r := by\n  simpa only [Finset.sup_eq_sup\u1d62] using s.partially_well_ordered_on_sup\n#align finset.partially_well_ordered_on_bUnion Finset.partiallyWellOrderedOn_bUnion\n\n#print Finset.isWf_bUnion /-\n@[simp]\ntheorem isWf_bUnion [Preorder \u03b1] (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (\u22c3 i \u2208 s, f i).IsWf \u2194 \u2200 i \u2208 s, (f i).IsWf :=\n  s.wellFoundedOn_bUnion\n#align finset.is_wf_bUnion Finset.isWf_bUnion\n-/\n\n#print Finset.isPwo_bUnion /-\n@[simp]\ntheorem isPwo_bUnion [Preorder \u03b1] (s : Finset \u03b9) {f : \u03b9 \u2192 Set \u03b1} :\n    (\u22c3 i \u2208 s, f i).IsPwo \u2194 \u2200 i \u2208 s, (f i).IsPwo :=\n  s.partiallyWellOrderedOn_bUnion\n#align finset.is_pwo_bUnion Finset.isPwo_bUnion\n-/\n\nend Finset\n\nnamespace Set\n\nsection Preorder\n\nvariable [Preorder \u03b1] {s : Set \u03b1} {a : \u03b1}\n\n#print Set.IsWf.min /-\n/-- `is_wf.min` returns a minimal element of a nonempty well-founded set. -/\nnoncomputable def IsWf.min (hs : IsWf s) (hn : s.Nonempty) : \u03b1 :=\n  hs.min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)\n#align set.is_wf.min Set.IsWf.min\n-/\n\n#print Set.IsWf.min_mem /-\ntheorem IsWf.min_mem (hs : IsWf s) (hn : s.Nonempty) : hs.min hn \u2208 s :=\n  (WellFounded.min hs univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)).2\n#align set.is_wf.min_mem Set.IsWf.min_mem\n-/\n\n#print Set.IsWf.not_lt_min /-\ntheorem IsWf.not_lt_min (hs : IsWf s) (hn : s.Nonempty) (ha : a \u2208 s) : \u00aca < hs.min hn :=\n  hs.not_lt_min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype) (mem_univ (\u27e8a, ha\u27e9 : s))\n#align set.is_wf.not_lt_min Set.IsWf.not_lt_min\n-/\n\n#print Set.isWf_min_singleton /-\n@[simp]\ntheorem isWf_min_singleton (a) {hs : IsWf ({a} : Set \u03b1)} {hn : ({a} : Set \u03b1).Nonempty} :\n    hs.min hn = a :=\n  eq_of_mem_singleton (IsWf.min_mem hs hn)\n#align set.is_wf_min_singleton Set.isWf_min_singleton\n-/\n\nend Preorder\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] {s t : Set \u03b1} {a : \u03b1}\n\n#print Set.IsWf.min_le /-\ntheorem IsWf.min_le (hs : s.IsWf) (hn : s.Nonempty) (ha : a \u2208 s) : hs.min hn \u2264 a :=\n  le_of_not_lt (hs.not_lt_min hn ha)\n#align set.is_wf.min_le Set.IsWf.min_le\n-/\n\n#print Set.IsWf.le_min_iff /-\ntheorem IsWf.le_min_iff (hs : s.IsWf) (hn : s.Nonempty) : a \u2264 hs.min hn \u2194 \u2200 b, b \u2208 s \u2192 a \u2264 b :=\n  \u27e8fun ha b hb => le_trans ha (hs.min_le hn hb), fun h => h _ (hs.min_mem _)\u27e9\n#align set.is_wf.le_min_iff Set.IsWf.le_min_iff\n-/\n\n#print Set.IsWf.min_le_min_of_subset /-\ntheorem IsWf.min_le_min_of_subset {hs : s.IsWf} {hsn : s.Nonempty} {ht : t.IsWf} {htn : t.Nonempty}\n    (hst : s \u2286 t) : ht.min htn \u2264 hs.min hsn :=\n  (IsWf.le_min_iff _ _).2 fun b hb => ht.min_le htn (hst hb)\n#align set.is_wf.min_le_min_of_subset Set.IsWf.min_le_min_of_subset\n-/\n\n/- warning: set.is_wf.min_union -> Set.IsWf.min_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1} (hs : Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) s) (hsn : Set.Nonempty.{u1} \u03b1 s) (ht : Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) t) (htn : Set.Nonempty.{u1} \u03b1 t), Eq.{succ u1} \u03b1 (Set.IsWf.min.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t) (Set.IsWf.union.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s t hs ht) (Iff.mpr (Set.Nonempty.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) s t)) (Or (Set.Nonempty.{u1} \u03b1 s) (Set.Nonempty.{u1} \u03b1 t)) (Set.union_nonempty.{u1} \u03b1 s t) (Or.intro_left (Set.Nonempty.{u1} \u03b1 s) (Set.Nonempty.{u1} \u03b1 t) hsn))) (LinearOrder.min.{u1} \u03b1 _inst_1 (Set.IsWf.min.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) s hs hsn) (Set.IsWf.min.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) t ht htn))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {s : Set.{u1} \u03b1} {t : Set.{u1} \u03b1} (hs : Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) s) (hsn : Set.Nonempty.{u1} \u03b1 s) (ht : Set.IsWf.{u1} \u03b1 (Preorder.toLT.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) t) (htn : Set.Nonempty.{u1} \u03b1 t), Eq.{succ u1} \u03b1 (Set.IsWf.min.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t) (Set.IsWf.union.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s t hs ht) (Iff.mpr (Set.Nonempty.{u1} \u03b1 (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) s t)) (Or (Set.Nonempty.{u1} \u03b1 s) (Set.Nonempty.{u1} \u03b1 t)) (Set.union_nonempty.{u1} \u03b1 s t) (Or.intro_left (Set.Nonempty.{u1} \u03b1 s) (Set.Nonempty.{u1} \u03b1 t) hsn))) (Min.min.{u1} \u03b1 (LinearOrder.toMin.{u1} \u03b1 _inst_1) (Set.IsWf.min.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) s hs hsn) (Set.IsWf.min.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) t ht htn))\nCase conversion may be inaccurate. Consider using '#align set.is_wf.min_union Set.IsWf.min_union\u2093'. -/\ntheorem IsWf.min_union (hs : s.IsWf) (hsn : s.Nonempty) (ht : t.IsWf) (htn : t.Nonempty) :\n    (hs.union ht).min (union_nonempty.2 (Or.intro_left _ hsn)) = min (hs.min hsn) (ht.min htn) :=\n  by\n  refine'\n    le_antisymm\n      (le_min (is_wf.min_le_min_of_subset (subset_union_left _ _))\n        (is_wf.min_le_min_of_subset (subset_union_right _ _)))\n      _\n  rw [min_le_iff]\n  exact\n    ((mem_union _ _ _).1 ((hs.union ht).min_mem (union_nonempty.2 (Or.intro_left _ hsn)))).imp\n      (hs.min_le _) (ht.min_le _)\n#align set.is_wf.min_union Set.IsWf.min_union\n\nend LinearOrder\n\nend Set\n\nopen Set\n\nnamespace Set.PartiallyWellOrderedOn\n\nvariable {r : \u03b1 \u2192 \u03b1 \u2192 Prop}\n\n#print Set.PartiallyWellOrderedOn.IsBadSeq /-\n/-- In the context of partial well-orderings, a bad sequence is a nonincreasing sequence\n  whose range is contained in a particular set `s`. One exists if and only if `s` is not\n  partially well-ordered. -/\ndef IsBadSeq (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : Set \u03b1) (f : \u2115 \u2192 \u03b1) : Prop :=\n  (\u2200 n, f n \u2208 s) \u2227 \u2200 m n : \u2115, m < n \u2192 \u00acr (f m) (f n)\n#align set.partially_well_ordered_on.is_bad_seq Set.PartiallyWellOrderedOn.IsBadSeq\n-/\n\n#print Set.PartiallyWellOrderedOn.iff_forall_not_isBadSeq /-\ntheorem iff_forall_not_isBadSeq (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : Set \u03b1) :\n    s.PartiallyWellOrderedOn r \u2194 \u2200 f, \u00acIsBadSeq r s f :=\n  forall_congr' fun f => by simp [is_bad_seq]\n#align set.partially_well_ordered_on.iff_forall_not_is_bad_seq Set.PartiallyWellOrderedOn.iff_forall_not_isBadSeq\n-/\n\n#print Set.PartiallyWellOrderedOn.IsMinBadSeq /-\n/-- This indicates that every bad sequence `g` that agrees with `f` on the first `n`\n  terms has `rk (f n) \u2264 rk (g n)`. -/\ndef IsMinBadSeq (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (rk : \u03b1 \u2192 \u2115) (s : Set \u03b1) (n : \u2115) (f : \u2115 \u2192 \u03b1) : Prop :=\n  \u2200 g : \u2115 \u2192 \u03b1, (\u2200 m : \u2115, m < n \u2192 f m = g m) \u2192 rk (g n) < rk (f n) \u2192 \u00acIsBadSeq r s g\n#align set.partially_well_ordered_on.is_min_bad_seq Set.PartiallyWellOrderedOn.IsMinBadSeq\n-/\n\n#print Set.PartiallyWellOrderedOn.minBadSeqOfBadSeq /-\n/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`\n  terms and is minimal at `n`.\n-/\nnoncomputable def minBadSeqOfBadSeq (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (rk : \u03b1 \u2192 \u2115) (s : Set \u03b1) (n : \u2115) (f : \u2115 \u2192 \u03b1)\n    (hf : IsBadSeq r s f) :\n    { g : \u2115 \u2192 \u03b1 // (\u2200 m : \u2115, m < n \u2192 f m = g m) \u2227 IsBadSeq r s g \u2227 IsMinBadSeq r rk s n g } := by\n  classical\n    have h : \u2203 (k : \u2115)(g : \u2115 \u2192 \u03b1), (\u2200 m, m < n \u2192 f m = g m) \u2227 is_bad_seq r s g \u2227 rk (g n) = k :=\n      \u27e8_, f, fun _ _ => rfl, hf, rfl\u27e9\n    obtain \u27e8h1, h2, h3\u27e9 := Classical.choose_spec (Nat.find_spec h)\n    refine' \u27e8Classical.choose (Nat.find_spec h), h1, by convert h2, fun g hg1 hg2 con => _\u27e9\n    refine' Nat.find_min h _ \u27e8g, fun m mn => (h1 m mn).trans (hg1 m mn), by convert Con, rfl\u27e9\n    rwa [\u2190 h3]\n#align set.partially_well_ordered_on.min_bad_seq_of_bad_seq Set.PartiallyWellOrderedOn.minBadSeqOfBadSeq\n-/\n\n#print Set.PartiallyWellOrderedOn.exists_min_bad_of_exists_bad /-\ntheorem exists_min_bad_of_exists_bad (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (rk : \u03b1 \u2192 \u2115) (s : Set \u03b1) :\n    (\u2203 f, IsBadSeq r s f) \u2192 \u2203 f, IsBadSeq r s f \u2227 \u2200 n, IsMinBadSeq r rk s n f :=\n  by\n  rintro \u27e8f0, hf0 : is_bad_seq r s f0\u27e9\n  let fs : \u2200 n : \u2115, { f : \u2115 \u2192 \u03b1 // is_bad_seq r s f \u2227 is_min_bad_seq r rk s n f } :=\n    by\n    refine' Nat.rec _ _\n    \u00b7\n      exact\n        \u27e8(min_bad_seq_of_bad_seq r rk s 0 f0 hf0).1, (min_bad_seq_of_bad_seq r rk s 0 f0 hf0).2.2\u27e9\n    \u00b7\n      exact fun n fn =>\n        \u27e8(min_bad_seq_of_bad_seq r rk s (n + 1) fn.1 fn.2.1).1,\n          (min_bad_seq_of_bad_seq r rk s (n + 1) fn.1 fn.2.1).2.2\u27e9\n  have h : \u2200 m n, m \u2264 n \u2192 (fs m).1 m = (fs n).1 m :=\n    by\n    intro m n mn\n    obtain \u27e8k, rfl\u27e9 := exists_add_of_le mn\n    clear mn\n    induction' k with k ih\n    \u00b7 rfl\n    rw [ih,\n      (min_bad_seq_of_bad_seq r rk s (m + k).succ (fs (m + k)).1 (fs (m + k)).2.1).2.1 m\n        (Nat.lt_succ_iff.2 (Nat.add_le_add_left k.zero_le m))]\n    rfl\n  refine' \u27e8fun n => (fs n).1 n, \u27e8fun n => (fs n).2.1.1 n, fun m n mn => _\u27e9, fun n g hg1 hg2 => _\u27e9\n  \u00b7 dsimp\n    rw [\u2190 Subtype.val_eq_coe, h m n (le_of_lt mn)]\n    convert(fs n).2.1.2 m n mn\n  \u00b7 convert(fs n).2.2 g (fun m mn => Eq.trans _ (hg1 m mn)) (lt_of_lt_of_le hg2 le_rfl)\n    rw [\u2190 h m n (le_of_lt mn)]\n#align set.partially_well_ordered_on.exists_min_bad_of_exists_bad Set.PartiallyWellOrderedOn.exists_min_bad_of_exists_bad\n-/\n\n#print Set.PartiallyWellOrderedOn.iff_not_exists_isMinBadSeq /-\ntheorem iff_not_exists_isMinBadSeq (rk : \u03b1 \u2192 \u2115) {s : Set \u03b1} :\n    s.PartiallyWellOrderedOn r \u2194 \u00ac\u2203 f, IsBadSeq r s f \u2227 \u2200 n, IsMinBadSeq r rk s n f :=\n  by\n  rw [iff_forall_not_is_bad_seq, \u2190 not_exists, not_congr]\n  constructor\n  \u00b7 apply exists_min_bad_of_exists_bad\n  rintro \u27e8f, hf1, hf2\u27e9\n  exact \u27e8f, hf1\u27e9\n#align set.partially_well_ordered_on.iff_not_exists_is_min_bad_seq Set.PartiallyWellOrderedOn.iff_not_exists_isMinBadSeq\n-/\n\n#print Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall\u2082 /-\n/-- Higman's Lemma, which states that for any reflexive, transitive relation `r` which is\n  partially well-ordered on a set `s`, the relation `list.sublist_forall\u2082 r` is partially\n  well-ordered on the set of lists of elements of `s`. That relation is defined so that\n  `list.sublist_forall\u2082 r l\u2081 l\u2082` whenever `l\u2081` related pointwise by `r` to a sublist of `l\u2082`.  -/\ntheorem partiallyWellOrderedOn_sublistForall\u2082 (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [IsRefl \u03b1 r] [IsTrans \u03b1 r]\n    {s : Set \u03b1} (h : s.PartiallyWellOrderedOn r) :\n    { l : List \u03b1 | \u2200 x, x \u2208 l \u2192 x \u2208 s }.PartiallyWellOrderedOn (List.SublistForall\u2082 r) :=\n  by\n  rcases s.eq_empty_or_nonempty with (rfl | \u27e8as, has\u27e9)\n  \u00b7 apply partially_well_ordered_on.mono (Finset.partiallyWellOrderedOn {List.nil})\n    \u00b7 intro l hl\n      rw [Finset.mem_coe, Finset.mem_singleton, List.eq_nil_iff_forall_not_mem]\n      exact hl\n    infer_instance\n  haveI : Inhabited \u03b1 := \u27e8as\u27e9\n  rw [iff_not_exists_is_min_bad_seq List.length]\n  rintro \u27e8f, hf1, hf2\u27e9\n  have hnil : \u2200 n, f n \u2260 List.nil := fun n con =>\n    hf1.2 n n.succ n.lt_succ_self (Con.symm \u25b8 List.SublistForall\u2082.nil)\n  obtain \u27e8g, hg\u27e9 := h.exists_monotone_subseq (List.headI \u2218 f) _\n  swap;\n  \u00b7 simp only [Set.range_subset_iff, Function.comp_apply]\n    exact fun n => hf1.1 n _ (List.head!_mem_self (hnil n))\n  have hf' :=\n    hf2 (g 0) (fun n => if n < g 0 then f n else List.tail (f (g (n - g 0))))\n      (fun m hm => (if_pos hm).symm) _\n  swap;\n  \u00b7 simp only [if_neg (lt_irrefl (g 0)), tsub_self]\n    rw [List.length_tail, \u2190 Nat.pred_eq_sub_one]\n    exact Nat.pred_lt fun con => hnil _ (List.length_eq_zero.1 Con)\n  rw [is_bad_seq] at hf'\n  push_neg  at hf'\n  obtain \u27e8m, n, mn, hmn\u27e9 := hf' _\n  swap\n  \u00b7 rintro n x hx\n    split_ifs  at hx with hn hn\n    \u00b7 exact hf1.1 _ _ hx\n    \u00b7 refine' hf1.1 _ _ (List.tail_subset _ hx)\n  by_cases hn : n < g 0\n  \u00b7 apply hf1.2 m n mn\n    rwa [if_pos hn, if_pos (mn.trans hn)] at hmn\n  \u00b7 obtain \u27e8n', rfl\u27e9 := exists_add_of_le (not_lt.1 hn)\n    rw [if_neg hn, add_comm (g 0) n', add_tsub_cancel_right] at hmn\n    split_ifs  at hmn with hm hm\n    \u00b7 apply hf1.2 m (g n') (lt_of_lt_of_le hm (g.monotone n'.zero_le))\n      exact trans hmn (List.tail_sublistForall\u2082_self _)\n    \u00b7 rw [\u2190 tsub_lt_iff_left (le_of_not_lt hm)] at mn\n      apply hf1.2 _ _ (g.lt_iff_lt.2 mn)\n      rw [\u2190 List.cons_head!_tail (hnil (g (m - g 0))), \u2190 List.cons_head!_tail (hnil (g n'))]\n      exact List.SublistForall\u2082.cons (hg _ _ (le_of_lt mn)) hmn\n#align set.partially_well_ordered_on.partially_well_ordered_on_sublist_forall\u2082 Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall\u2082\n-/\n\nend Set.PartiallyWellOrderedOn\n\n#print WellFounded.isWf /-\ntheorem WellFounded.isWf [LT \u03b1] (h : WellFounded ((\u00b7 < \u00b7) : \u03b1 \u2192 \u03b1 \u2192 Prop)) (s : Set \u03b1) : s.IsWf :=\n  (Set.isWf_univ_iff.2 h).mono s.subset_univ\n#align well_founded.is_wf WellFounded.isWf\n-/\n\n#print Pi.isPwo /-\n/-- A version of **Dickson's lemma** any subset of functions `\u03a0 s : \u03c3, \u03b1 s` is partially well\nordered, when `\u03c3` is a `fintype` and each `\u03b1 s` is a linear well order.\nThis includes the classical case of Dickson's lemma that `\u2115 ^ n` is a well partial order.\nSome generalizations would be possible based on this proof, to include cases where the target is\npartially well ordered, and also to consider the case of `set.partially_well_ordered_on` instead of\n`set.is_pwo`. -/\ntheorem Pi.isPwo {\u03b1 : \u03b9 \u2192 Type _} [\u2200 i, LinearOrder (\u03b1 i)] [\u2200 i, IsWellOrder (\u03b1 i) (\u00b7 < \u00b7)]\n    [Finite \u03b9] (s : Set (\u2200 i, \u03b1 i)) : s.IsPwo :=\n  by\n  cases nonempty_fintype \u03b9\n  suffices\n    \u2200 s : Finset \u03b9,\n      \u2200 f : \u2115 \u2192 \u2200 s, \u03b1 s,\n        \u2203 g : \u2115 \u21aao \u2115, \u2200 \u2983a b : \u2115\u2984, a \u2264 b \u2192 \u2200 (x : \u03b9) (hs : x \u2208 s), (f \u2218 g) a x \u2264 (f \u2218 g) b x\n    by\n    refine' is_pwo_iff_exists_monotone_subseq.2 fun f hf => _\n    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f\n  refine' Finset.cons_induction _ _\n  \u00b7 intro f\n    exists RelEmbedding.refl (\u00b7 \u2264 \u00b7)\n    simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]\n  \u00b7 intro x s hx ih f\n    obtain \u27e8g, hg\u27e9 :=\n      (is_well_founded.wf.is_wf univ).IsPwo.exists_monotone_subseq (fun n => f n x) mem_univ\n    obtain \u27e8g', hg'\u27e9 := ih (f \u2218 g)\n    refine' \u27e8g'.trans g, fun a b hab => (Finset.forall_mem_cons _ _).2 _\u27e9\n    exact \u27e8hg (OrderHomClass.mono g' hab), hg' hab\u27e9\n#align pi.is_pwo Pi.isPwo\n-/\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/WellFoundedSet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7040185532560828}}
{"text": "/-\nCopyright (c) 2020 Yury Kudriashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudriashov, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module analysis.convex.hull\n! leanprover-community/mathlib commit a50170a88a47570ed186b809ca754110590f9476\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Analysis.Convex.Basic\nimport Mathlib.Order.Closure\n\n/-!\n# Convex hull\n\nThis file defines the convex hull of a set `s` in a module. `convexHull \ud835\udd5c s` is the smallest convex\nset containing `s`. In order theory speak, this is a closure operator.\n\n## Implementation notes\n\n`convexHull` is defined as a closure operator. This gives access to the `ClosureOperator` API\nwhile the impact on writing code is minimal as `convexHull \ud835\udd5c s` is automatically elaborated as\n`(convexHull \ud835\udd5c) s`.\n-/\n\n\nopen Set\n\nopen Pointwise\n\nvariable {\ud835\udd5c E F : Type _}\n\nsection convexHull\n\nsection OrderedSemiring\n\nvariable [OrderedSemiring \ud835\udd5c]\n\nsection AddCommMonoid\n\nvariable (\ud835\udd5c)\nvariable [AddCommMonoid E] [AddCommMonoid F] [Module \ud835\udd5c E] [Module \ud835\udd5c F]\n\n/-- The convex hull of a set `s` is the minimal convex set that includes `s`. -/\ndef convexHull : ClosureOperator (Set E) :=\n  ClosureOperator.mk\u2083 (fun s => \u22c2 (t : Set E) (_hst : s \u2286 t) (_ht : Convex \ud835\udd5c t), t) (Convex \ud835\udd5c)\n    (fun _ =>\n      Set.subset_inter\u1d62 fun _ => Set.subset_inter\u1d62 fun hst => Set.subset_inter\u1d62 fun _ => hst)\n    (fun _ => convex_inter\u1d62 fun _ => convex_inter\u1d62 fun _ => convex_inter\u1d62 id) fun _ t hst ht =>\n    Set.inter\u1d62_subset_of_subset t <| Set.inter\u1d62_subset_of_subset hst <| Set.inter\u1d62_subset _ ht\n#align convex_hull convexHull\n\nvariable (s : Set E)\n\ntheorem subset_convexHull : s \u2286 convexHull \ud835\udd5c s :=\n  (convexHull \ud835\udd5c).le_closure s\n#align subset_convex_hull subset_convexHull\n\ntheorem convex_convexHull : Convex \ud835\udd5c (convexHull \ud835\udd5c s) :=\n  ClosureOperator.closure_mem_mk\u2083 s\n#align convex_convex_hull convex_convexHull\n\ntheorem convexHull_eq_inter\u1d62 : convexHull \ud835\udd5c s =\n    \u22c2 (t : Set E) (_hst : s \u2286 t) (_ht : Convex \ud835\udd5c t), t :=\n  rfl\n#align convex_hull_eq_Inter convexHull_eq_inter\u1d62\n\nvariable {\ud835\udd5c s} {t : Set E} {x y : E}\n\ntheorem mem_convexHull_iff : x \u2208 convexHull \ud835\udd5c s \u2194 \u2200 t, s \u2286 t \u2192 Convex \ud835\udd5c t \u2192 x \u2208 t := by\n  simp_rw [convexHull_eq_inter\u1d62, mem_inter\u1d62]\n#align mem_convex_hull_iff mem_convexHull_iff\n\ntheorem convexHull_min (hst : s \u2286 t) (ht : Convex \ud835\udd5c t) : convexHull \ud835\udd5c s \u2286 t :=\n  ClosureOperator.closure_le_mk\u2083_iff (show s \u2264 t from hst) ht\n#align convex_hull_min convexHull_min\n\ntheorem Convex.convexHull_subset_iff (ht : Convex \ud835\udd5c t) : convexHull \ud835\udd5c s \u2286 t \u2194 s \u2286 t :=\n  \u27e8(subset_convexHull _ _).trans, fun h => convexHull_min h ht\u27e9\n#align convex.convex_hull_subset_iff Convex.convexHull_subset_iff\n\n@[mono]\ntheorem convexHull_mono (hst : s \u2286 t) : convexHull \ud835\udd5c s \u2286 convexHull \ud835\udd5c t :=\n  (convexHull \ud835\udd5c).monotone hst\n#align convex_hull_mono convexHull_mono\n\ntheorem Convex.convexHull_eq (hs : Convex \ud835\udd5c s) : convexHull \ud835\udd5c s = s :=\n  ClosureOperator.mem_mk\u2083_closed hs\n#align convex.convex_hull_eq Convex.convexHull_eq\n\n@[simp]\ntheorem convexHull_univ : convexHull \ud835\udd5c (univ : Set E) = univ :=\n  ClosureOperator.closure_top (convexHull \ud835\udd5c)\n#align convex_hull_univ convexHull_univ\n\n@[simp]\ntheorem convexHull_empty : convexHull \ud835\udd5c (\u2205 : Set E) = \u2205 :=\n  convex_empty.convexHull_eq\n#align convex_hull_empty convexHull_empty\n\n@[simp]\ntheorem convexHull_empty_iff : convexHull \ud835\udd5c s = \u2205 \u2194 s = \u2205 := by\n  constructor\n  \u00b7 intro h\n    rw [\u2190 Set.subset_empty_iff, \u2190 h]\n    exact subset_convexHull \ud835\udd5c _\n  \u00b7 rintro rfl\n    exact convexHull_empty\n#align convex_hull_empty_iff convexHull_empty_iff\n\n@[simp]\ntheorem convexHull_nonempty_iff : (convexHull \ud835\udd5c s).Nonempty \u2194 s.Nonempty := by\n  rw [nonempty_iff_ne_empty, nonempty_iff_ne_empty, Ne.def, Ne.def]\n  exact not_congr convexHull_empty_iff\n#align convex_hull_nonempty_iff convexHull_nonempty_iff\n\n-- Porting note: `alias` cannot be protected.\n--alias convexHull_nonempty_iff \u2194 _ Set.Nonempty.convexHull\n--attribute [protected] Set.Nonempty.convexHull\nprotected theorem Set.Nonempty.convexHull (h : s.Nonempty) : (convexHull \ud835\udd5c s).Nonempty :=\nconvexHull_nonempty_iff.2 h\n#align set.nonempty.convex_hull Set.Nonempty.convexHull\n\ntheorem segment_subset_convexHull (hx : x \u2208 s) (hy : y \u2208 s) : segment \ud835\udd5c x y \u2286 convexHull \ud835\udd5c s :=\n  (convex_convexHull _ _).segment_subset (subset_convexHull _ _ hx) (subset_convexHull _ _ hy)\n#align segment_subset_convex_hull segment_subset_convexHull\n\n@[simp]\ntheorem convexHull_singleton (x : E) : convexHull \ud835\udd5c ({x} : Set E) = {x} :=\n  (convex_singleton x).convexHull_eq\n#align convex_hull_singleton convexHull_singleton\n\n@[simp]\ntheorem convexHull_pair (x y : E) : convexHull \ud835\udd5c {x, y} = segment \ud835\udd5c x y := by\n  refine'\n    (convexHull_min _ <| convex_segment _ _).antisymm\n      (segment_subset_convexHull (mem_insert _ _) <| mem_insert_of_mem _ <| mem_singleton _)\n  rw [insert_subset, singleton_subset_iff]\n  exact \u27e8left_mem_segment _ _ _, right_mem_segment _ _ _\u27e9\n#align convex_hull_pair convexHull_pair\n\ntheorem convexHull_convexHull_union_left (s t : Set E) :\n    convexHull \ud835\udd5c (convexHull \ud835\udd5c s \u222a t) = convexHull \ud835\udd5c (s \u222a t) :=\n  ClosureOperator.closure_sup_closure_left _ _ _\n#align convex_hull_convex_hull_union_left convexHull_convexHull_union_left\n\ntheorem convexHull_convexHull_union_right (s t : Set E) :\n    convexHull \ud835\udd5c (s \u222a convexHull \ud835\udd5c t) = convexHull \ud835\udd5c (s \u222a t) :=\n  ClosureOperator.closure_sup_closure_right _ _ _\n#align convex_hull_convex_hull_union_right convexHull_convexHull_union_right\n\ntheorem Convex.convex_remove_iff_not_mem_convexHull_remove {s : Set E} (hs : Convex \ud835\udd5c s) (x : E) :\n    Convex \ud835\udd5c (s \\ {x}) \u2194 x \u2209 convexHull \ud835\udd5c (s \\ {x}) := by\n  constructor\n  \u00b7 rintro hsx hx\n    rw [hsx.convexHull_eq] at hx\n    exact hx.2 (mem_singleton _)\n  rintro hx\n  suffices h : s \\ {x} = convexHull \ud835\udd5c (s \\ {x})\n  \u00b7 rw [h]\n    exact convex_convexHull \ud835\udd5c _\n  exact\n    Subset.antisymm (subset_convexHull \ud835\udd5c _) fun y hy =>\n      \u27e8convexHull_min (diff_subset _ _) hs hy, by\n        rintro (rfl : y = x)\n        exact hx hy\u27e9\n#align convex.convex_remove_iff_not_mem_convex_hull_remove Convex.convex_remove_iff_not_mem_convexHull_remove\n\ntheorem IsLinearMap.convexHull_image {f : E \u2192 F} (hf : IsLinearMap \ud835\udd5c f) (s : Set E) :\n    convexHull \ud835\udd5c (f '' s) = f '' convexHull \ud835\udd5c s :=\n  Set.Subset.antisymm\n    (convexHull_min (image_subset _ (subset_convexHull \ud835\udd5c s)) <|\n      (convex_convexHull \ud835\udd5c s).is_linear_image hf)\n    (image_subset_iff.2 <|\n      convexHull_min (image_subset_iff.1 <| subset_convexHull \ud835\udd5c _)\n        ((convex_convexHull \ud835\udd5c _).is_linear_preimage hf))\n#align is_linear_map.convex_hull_image IsLinearMap.convexHull_image\n\ntheorem LinearMap.convexHull_image (f : E \u2192\u2097[\ud835\udd5c] F) (s : Set E) :\n    convexHull \ud835\udd5c (f '' s) = f '' convexHull \ud835\udd5c s :=\n  f.isLinear.convexHull_image s\n#align linear_map.convex_hull_image LinearMap.convexHull_image\n\nend AddCommMonoid\n\nend OrderedSemiring\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring \ud835\udd5c] [AddCommMonoid E] [Module \ud835\udd5c E]\n\ntheorem convexHull_smul (a : \ud835\udd5c) (s : Set E) : convexHull \ud835\udd5c (a \u2022 s) = a \u2022 convexHull \ud835\udd5c s :=\n  (LinearMap.lsmul _ _ a).convexHull_image _\n#align convex_hull_smul convexHull_smul\n\nend OrderedCommSemiring\n\nsection OrderedRing\n\nvariable [OrderedRing \ud835\udd5c]\n\nsection AddCommGroup\n\nvariable [AddCommGroup E] [AddCommGroup F] [Module \ud835\udd5c E] [Module \ud835\udd5c F] (s : Set E)\n\ntheorem AffineMap.image_convexHull (f : E \u2192\u1d43[\ud835\udd5c] F) : f '' convexHull \ud835\udd5c s = convexHull \ud835\udd5c (f '' s) :=\n  by\n  apply Set.Subset.antisymm\n  \u00b7 rw [Set.image_subset_iff]\n    refine' convexHull_min _ ((convex_convexHull \ud835\udd5c (f '' s)).affine_preimage f)\n    rw [\u2190 Set.image_subset_iff]\n    exact subset_convexHull \ud835\udd5c (f '' s)\n  \u00b7\n    exact\n      convexHull_min (Set.image_subset _ (subset_convexHull \ud835\udd5c s))\n        ((convex_convexHull \ud835\udd5c s).affine_image f)\n#align affine_map.image_convex_hull AffineMap.image_convexHull\n\ntheorem convexHull_subset_affineSpan : convexHull \ud835\udd5c s \u2286 (affineSpan \ud835\udd5c s : Set E) :=\n  convexHull_min (subset_affineSpan \ud835\udd5c s) (affineSpan \ud835\udd5c s).convex\n#align convex_hull_subset_affine_span convexHull_subset_affineSpan\n\n@[simp]\ntheorem affineSpan_convexHull : affineSpan \ud835\udd5c (convexHull \ud835\udd5c s) = affineSpan \ud835\udd5c s := by\n  refine' le_antisymm _ (affineSpan_mono \ud835\udd5c (subset_convexHull \ud835\udd5c s))\n  rw [affineSpan_le]\n  exact convexHull_subset_affineSpan s\n#align affine_span_convex_hull affineSpan_convexHull\n\ntheorem convexHull_neg (s : Set E) : convexHull \ud835\udd5c (-s) = -convexHull \ud835\udd5c s := by\n  simp_rw [\u2190 image_neg]\n  exact (AffineMap.image_convexHull _ <| -1).symm\n#align convex_hull_neg convexHull_neg\n\nend AddCommGroup\n\nend OrderedRing\n\nend convexHull\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Analysis/Convex/Hull.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7040185483616941}}
{"text": "/-\nCopyright (c) 2022 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam, Fr\u00e9d\u00e9ric Dupuis\n\n! This file was ported from Lean 3 source module algebra.star.unitary\n! leanprover-community/mathlib commit 247a102b14f3cebfee126293341af5f6bed00237\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Star.Basic\nimport Mathlib.GroupTheory.Submonoid.Operations\n\n/-!\n# Unitary elements of a star monoid\n\nThis file defines `unitary R`, where `R` is a star monoid, as the submonoid made of the elements\nthat satisfy `star U * U = 1` and `U * star U = 1`, and these form a group.\nThis includes, for instance, unitary operators on Hilbert spaces.\n\nSee also `Matrix.UnitaryGroup` for specializations to `unitary (matrix n n R)`.\n\n## Tags\n\nunitary\n-/\n\n\n/-- In a *-monoid, `unitary R` is the submonoid consisting of all the elements `U` of\n`R` such that `star U * U = 1` and `U * star U = 1`.\n-/\ndef unitary (R : Type _) [Monoid R] [StarSemigroup R] : Submonoid R\n    where\n  carrier := { U | star U * U = 1 \u2227 U * star U = 1 }\n  one_mem' := by simp only [mul_one, and_self_iff, Set.mem_setOf_eq, star_one]\n  mul_mem' := @fun U B \u27e8hA\u2081, hA\u2082\u27e9 \u27e8hB\u2081, hB\u2082\u27e9 =>\n    by\n    refine' \u27e8_, _\u27e9\n    \u00b7\n      calc\n        star (U * B) * (U * B) = star B * star U * U * B := by simp only [mul_assoc, star_mul]\n        _ = star B * (star U * U) * B := by rw [\u2190 mul_assoc]\n        _ = 1 := by rw [hA\u2081, mul_one, hB\u2081]\n\n    \u00b7\n      calc\n        U * B * star (U * B) = U * B * (star B * star U) := by rw [star_mul]\n        _ = U * (B * star B) * star U := by simp_rw [\u2190 mul_assoc]\n        _ = 1 := by rw [hB\u2082, mul_one, hA\u2082]\n\n#align unitary unitary\n\nvariable {R : Type _}\n\nnamespace unitary\n\nsection Monoid\n\nvariable [Monoid R] [StarSemigroup R]\n\ntheorem mem_iff {U : R} : U \u2208 unitary R \u2194 star U * U = 1 \u2227 U * star U = 1 :=\n  Iff.rfl\n#align unitary.mem_iff unitary.mem_iff\n\n@[simp]\ntheorem star_mul_self_of_mem {U : R} (hU : U \u2208 unitary R) : star U * U = 1 :=\n  hU.1\n#align unitary.star_mul_self_of_mem unitary.star_mul_self_of_mem\n\n@[simp]\ntheorem mul_star_self_of_mem {U : R} (hU : U \u2208 unitary R) : U * star U = 1 :=\n  hU.2\n#align unitary.mul_star_self_of_mem unitary.mul_star_self_of_mem\n\ntheorem star_mem {U : R} (hU : U \u2208 unitary R) : star U \u2208 unitary R :=\n  \u27e8by rw [star_star, mul_star_self_of_mem hU], by rw [star_star, star_mul_self_of_mem hU]\u27e9\n#align unitary.star_mem unitary.star_mem\n\n@[simp]\ntheorem star_mem_iff {U : R} : star U \u2208 unitary R \u2194 U \u2208 unitary R :=\n  \u27e8fun h => star_star U \u25b8 star_mem h, star_mem\u27e9\n#align unitary.star_mem_iff unitary.star_mem_iff\n\ninstance : Star (unitary R) :=\n  \u27e8fun U => \u27e8star U, star_mem U.prop\u27e9\u27e9\n\n@[simp, norm_cast]\ntheorem coe_star {U : unitary R} : \u2191(star U) = (star U : R) :=\n  rfl\n#align unitary.coe_star unitary.coe_star\n\ntheorem coe_star_mul_self (U : unitary R) : (star U : R) * U = 1 :=\n  star_mul_self_of_mem U.prop\n#align unitary.coe_star_mul_self unitary.coe_star_mul_self\n\ntheorem coe_mul_star_self (U : unitary R) : (U : R) * star U = 1 :=\n  mul_star_self_of_mem U.prop\n#align unitary.coe_mul_star_self unitary.coe_mul_star_self\n\n@[simp]\ntheorem star_mul_self (U : unitary R) : star U * U = 1 :=\n  Subtype.ext <| coe_star_mul_self U\n#align unitary.star_mul_self unitary.star_mul_self\n\n@[simp]\ntheorem mul_star_self (U : unitary R) : U * star U = 1 :=\n  Subtype.ext <| coe_mul_star_self U\n#align unitary.mul_star_self unitary.mul_star_self\n\ninstance : Group (unitary R) :=\n  { Submonoid.toMonoid _ with\n    inv := star\n    mul_left_inv := star_mul_self }\n\ninstance : InvolutiveStar (unitary R) :=\n  \u27e8by\n    intro x\n    ext\n    rw [coe_star, coe_star, star_star]\u27e9\n\ninstance : StarSemigroup (unitary R) :=\n  \u27e8by\n    intro x y\n    ext\n    rw [coe_star, Submonoid.coe_mul, Submonoid.coe_mul, coe_star, coe_star, star_mul]\u27e9\n\ninstance : Inhabited (unitary R) :=\n  \u27e81\u27e9\n\ntheorem star_eq_inv (U : unitary R) : star U = U\u207b\u00b9 :=\n  rfl\n#align unitary.star_eq_inv unitary.star_eq_inv\n\ntheorem star_eq_inv' : (star : unitary R \u2192 unitary R) = Inv.inv :=\n  rfl\n#align unitary.star_eq_inv' unitary.star_eq_inv'\n\n/-- The unitary elements embed into the units. -/\n@[simps]\ndef toUnits : unitary R \u2192* R\u02e3\n    where\n  toFun x := \u27e8x, \u2191x\u207b\u00b9, coe_mul_star_self x, coe_star_mul_self x\u27e9\n  map_one' := Units.ext rfl\n  map_mul' _ _ := Units.ext rfl\n#align unitary.to_units unitary.toUnits\n\ntheorem to_units_injective : Function.Injective (toUnits : unitary R \u2192 R\u02e3) := fun _ _ h =>\n  Subtype.ext <| Units.ext_iff.mp h\n#align unitary.to_units_injective unitary.to_units_injective\n\nend Monoid\n\nsection CommMonoid\n\nvariable [CommMonoid R] [StarSemigroup R]\n\ninstance : CommGroup (unitary R) :=\n  { inferInstanceAs (Group (unitary R)), Submonoid.toCommMonoid _ with }\n\ntheorem mem_iff_star_mul_self {U : R} : U \u2208 unitary R \u2194 star U * U = 1 :=\n  mem_iff.trans <| and_iff_left_of_imp fun h => mul_comm (star U) U \u25b8 h\n#align unitary.mem_iff_star_mul_self unitary.mem_iff_star_mul_self\n\ntheorem mem_iff_self_mul_star {U : R} : U \u2208 unitary R \u2194 U * star U = 1 :=\n  mem_iff.trans <| and_iff_right_of_imp fun h => mul_comm U (star U) \u25b8 h\n#align unitary.mem_iff_self_mul_star unitary.mem_iff_self_mul_star\n\nend CommMonoid\n\nsection GroupWithZero\n\nvariable [GroupWithZero R] [StarSemigroup R]\n\n@[norm_cast]\n\n\n@[norm_cast]\ntheorem coe_div (U\u2081 U\u2082 : unitary R) : \u2191(U\u2081 / U\u2082) = (U\u2081 / U\u2082 : R) := by\n  simp only [div_eq_mul_inv, coe_inv, Submonoid.coe_mul]\n#align unitary.coe_div unitary.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (U : unitary R) (z : \u2124) : \u2191(U ^ z) = (U : R) ^ z := by\n  induction z\n  \u00b7 simp [SubmonoidClass.coe_pow]\n  \u00b7 simp [coe_inv]\n#align unitary.coe_zpow unitary.coe_zpow\n\nend GroupWithZero\n\nsection Ring\n\nvariable [Ring R] [StarRing R]\n\ninstance : Neg (unitary R)\n    where neg U :=\n    \u27e8-U, by simp [mem_iff, star_neg, neg_mul_neg]\u27e9\n\n@[norm_cast]\ntheorem coe_neg (U : unitary R) : \u2191(-U) = (-U : R) :=\n  rfl\n#align unitary.coe_neg unitary.coe_neg\n\ninstance : HasDistribNeg (unitary R) :=\n  Subtype.coe_injective.hasDistribNeg _ coe_neg (unitary R).coe_mul\n\nend Ring\n\nend unitary\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/Star/Unitary.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162774, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7040185452843402}}
{"text": "import topology.continuous_function.polynomial -- hide\n\n/- # Using apply\nIn this problem you will show that a specific polynomial is continuous, you can do this using\nthe basic facts in the left sidebar: that adding continuous functions is continuous,\nlikewise multiplying continuous functions remains continuous, constant functions are continuous,\nand the identity function is continuous. The way these lemmas are stated is very general, they work\nfor any continuous functions on arbitrary topological spaces, but by using `apply` we can let Lean\nwork out the details automatically.\n\nBut how do we talk about the functions themselves?\nThe basic method to speak about an unnamed function in Lean makes use of the lambda syntax.\nIn mathematics we might just write $x ^ 3 + 7$ to describe a polynomial function, leaving it\nimplicit that $x$ is the variable.\nIn Lean we use the symbol \u03bb (`\\lambda`) to describe a function by placing the name of the variable\nafter the lambda.\nSo `\u03bb x, x^3 + 7` defines the function which takes input `x` and outputs `x^3 + 7` in Lean.\n\nWatch out! Some of these lemmas have names with a dot like `continuous.add` (these ones\nprove continuity of a combination of functions) and some have an underscore like\n`continuous_const` (these ones state that some specific function is continuous).\n\n-/\n\n/- Tactic : apply\n\n## Summary\n\nIf `h : P \u2192 Q` is a hypothesis, and the goal is `\u22a2 Q` then\n`apply h` changes the goal to `\u22a2 P`.\n\n## Details\n\nIf you have a function `h : P \u2192 Q` and your goal is `\u22a2 Q`\nthen `apply h` changes the goal to `\u22a2 P`. The logic is\nsimple: if you are trying to create a term of type `Q`,\nbut `h` is a function which turns terms of type `P` into\nterms of type `Q`, then it will suffice to construct a\nterm of type `P`. A mathematician might say: \"we need\nto construct an element of $Q$, but we have a function $h:P\\to Q$\nso it suffices to construct an element of $P$\". Or alternatively\n\"we need to prove $Q$, but we have a proof $h$ that $P\\implies Q$\nso it suffices to prove $P$\".\n\n-/\n\nopen polynomial-- hide\n/- Axiom : Adding two continuous functions is continuous\ncontinuous.add : \u2200 {X M : Type} [topological_space X] [topological_space M] [has_add M]\n  [has_continuous_add M] {f g : X \u2192 M},\n  continuous f \u2192 continuous g \u2192 continuous (\u03bb (x : X), f x + g x)\n-/\n/- Axiom : Multiplying two continuous functions is continuous\ncontinuous.mul : \u2200 {X M : Type} [topological_space X] [ topological_space M]\n  [has_mul M] [has_continuous_mul M] {f g : X \u2192 M},\n  continuous f \u2192 continuous g \u2192 continuous (\u03bb (x : X), f x * g x)\n-/\n/- Axiom :\ncontinuous.pow : \u2200 {X M : Type} [topological_space X] [topological_space M] [monoid M]\n  [has_continuous_mul M] {f : X \u2192 M},\n  continuous f \u2192 \u2200 (n : \u2115), continuous (\u03bb (b : X), f b ^ n)\n-/\n/- Axiom : A constant function is continuous\ncontinuous_const : \u2200 {\u03b1 \u03b2 : Type} [topological_space \u03b1] [topological_space \u03b2] {b : \u03b2},\n  continuous (\u03bb (a : \u03b1), b)\n-/\n/- Axiom : The identity function is continuous\ncontinuous_id : \u2200 {\u03b1 : Type} [topological_space \u03b1], continuous (\u03bb x, x)\n-/\n\n/- Lemma : no-side-bar\n-/\nlemma poly_continuous : continuous (\u03bb x : \u211d, 5 * x ^ 2 + x + 6) :=\nbegin\n  apply continuous.add,\n  apply continuous.add,\n  apply continuous.mul,\n  apply continuous_const,\n  apply continuous.pow,\n  apply continuous_id,\n  apply continuous_id,\n  apply continuous_const,\n\n\n\nend\n", "meta": {"author": "alexjbest", "repo": "CAP-game", "sha": "d823def7325d7142d61e766b2e027f936685a8ff", "save_path": "github-repos/lean/alexjbest-CAP-game", "path": "github-repos/lean/alexjbest-CAP-game/CAP-game-d823def7325d7142d61e766b2e027f936685a8ff/src/inter/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.7039257791415803}}
{"text": "/-\nCopyright (c) 2021 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n\n! This file was ported from Lean 3 source module combinatorics.hindman\n! leanprover-community/mathlib commit 69c6a5a12d8a2b159f20933e60115a4f2de62b58\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.StoneCech\nimport Mathbin.Topology.Algebra.Semigroup\nimport Mathbin.Data.Stream.Init\n\n/-!\n# Hindman's theorem on finite sums\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe prove Hindman's theorem on finite sums, using idempotent ultrafilters.\n\nGiven an infinite sequence `a\u2080, a\u2081, a\u2082, \u2026` of positive integers, the set `FS(a\u2080, \u2026)` is the set\nof positive integers that can be expressed as a finite sum of `a\u1d62`'s, without repetition. Hindman's\ntheorem asserts that whenever the positive integers are finitely colored, there exists a sequence\n`a\u2080, a\u2081, a\u2082, \u2026` such that `FS(a\u2080, \u2026)` is monochromatic. There is also a stronger version, saying\nthat whenever a set of the form `FS(a\u2080, \u2026)` is finitely colored, there exists a sequence\n`b\u2080, b\u2081, b\u2082, \u2026` such that `FS(b\u2080, \u2026)` is monochromatic and contained in `FS(a\u2080, \u2026)`. We prove both\nthese versions for a general semigroup `M` instead of `\u2115+` since it is no harder, although this\nspecial case implies the general case.\n\nThe idea of the proof is to extend the addition `(+) : M \u2192 M \u2192 M` to addition `(+) : \u03b2M \u2192 \u03b2M \u2192 \u03b2M`\non the space `\u03b2M` of ultrafilters on `M`. One can prove that if `U` is an _idempotent_ ultrafilter,\ni.e. `U + U = U`, then any `U`-large subset of `M` contains some set `FS(a\u2080, \u2026)` (see\n`exists_FS_of_large`). And with the help of a general topological argument one can show that any set\nof the form `FS(a\u2080, \u2026)` is `U`-large according to some idempotent ultrafilter `U` (see\n`exists_idempotent_ultrafilter_le_FS`). This is enough to prove the theorem since in any finite\npartition of a `U`-large set, one of the parts is `U`-large.\n\n## Main results\n\n- `FS_partition_regular`: the strong form of Hindman's theorem\n- `exists_FS_of_finite_cover`: the weak form of Hindman's theorem\n\n## Tags\n\nRamsey theory, ultrafilter\n\n-/\n\n\nopen Filter\n\n#print Ultrafilter.mul /-\n/-- Multiplication of ultrafilters given by `\u2200\u1da0 m in U*V, p m \u2194 \u2200\u1da0 m in U, \u2200\u1da0 m' in V, p (m*m')`. -/\n@[to_additive\n      \"Addition of ultrafilters given by\\n`\u2200\u1da0 m in U+V, p m \u2194 \u2200\u1da0 m in U, \u2200\u1da0 m' in V, p (m+m')`.\"]\ndef Ultrafilter.mul {M} [Mul M] : Mul (Ultrafilter M) where mul U V := (\u00b7 * \u00b7) <$> U <*> V\n#align ultrafilter.has_mul Ultrafilter.mul\n#align ultrafilter.has_add Ultrafilter.add\n-/\n\nattribute [local instance] Ultrafilter.mul Ultrafilter.add\n\n#print Ultrafilter.eventually_mul /-\n/- We could have taken this as the definition of `U * V`, but then we would have to prove that it\ndefines an ultrafilter. -/\n@[to_additive]\ntheorem Ultrafilter.eventually_mul {M} [Mul M] (U V : Ultrafilter M) (p : M \u2192 Prop) :\n    (\u2200\u1da0 m in \u2191(U * V), p m) \u2194 \u2200\u1da0 m in U, \u2200\u1da0 m' in V, p (m * m') :=\n  Iff.rfl\n#align ultrafilter.eventually_mul Ultrafilter.eventually_mul\n#align ultrafilter.eventually_add Ultrafilter.eventually_add\n-/\n\n#print Ultrafilter.semigroup /-\n/-- Semigroup structure on `ultrafilter M` induced by a semigroup structure on `M`. -/\n@[to_additive\n      \"Additive semigroup structure on `ultrafilter M` induced by an additive semigroup\\nstructure on `M`.\"]\ndef Ultrafilter.semigroup {M} [Semigroup M] : Semigroup (Ultrafilter M) :=\n  { Ultrafilter.mul with\n    mul_assoc := fun U V W =>\n      Ultrafilter.coe_inj.mp <|\n        Filter.ext' fun p => by simp only [Ultrafilter.eventually_mul, mul_assoc] }\n#align ultrafilter.semigroup Ultrafilter.semigroup\n#align ultrafilter.add_semigroup Ultrafilter.addSemigroup\n-/\n\nattribute [local instance] Ultrafilter.semigroup Ultrafilter.addSemigroup\n\n/- warning: ultrafilter.continuous_mul_left -> Ultrafilter.continuous_mul_left is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (V : Ultrafilter.{u1} M), Continuous.{u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.topologicalSpace.{u1} M) (Ultrafilter.topologicalSpace.{u1} M) (fun (_x : Ultrafilter.{u1} M) => HMul.hMul.{u1, u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (instHMul.{u1} (Ultrafilter.{u1} M) (Ultrafilter.mul.{u1} M (Semigroup.toHasMul.{u1} M _inst_1))) _x V)\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (V : Ultrafilter.{u1} M), Continuous.{u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.topologicalSpace.{u1} M) (Ultrafilter.topologicalSpace.{u1} M) (fun (_x : Ultrafilter.{u1} M) => HMul.hMul.{u1, u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (instHMul.{u1} (Ultrafilter.{u1} M) (Ultrafilter.mul.{u1} M (Semigroup.toMul.{u1} M _inst_1))) _x V)\nCase conversion may be inaccurate. Consider using '#align ultrafilter.continuous_mul_left Ultrafilter.continuous_mul_left\u2093'. -/\n-- We don't prove `continuous_mul_right`, because in general it is false!\n@[to_additive]\ntheorem Ultrafilter.continuous_mul_left {M} [Semigroup M] (V : Ultrafilter M) :\n    Continuous (\u00b7 * V) :=\n  TopologicalSpace.IsTopologicalBasis.continuous ultrafilterBasis_is_basis _ <|\n    Set.forall_range_iff.mpr fun s => ultrafilter_isOpen_basic { m : M | \u2200\u1da0 m' in V, m * m' \u2208 s }\n#align ultrafilter.continuous_mul_left Ultrafilter.continuous_mul_left\n#align ultrafilter.continuous_add_left Ultrafilter.continuous_add_left\n\nnamespace Hindman\n\n#print Hindman.FS /-\n/-- `FS a` is the set of finite sums in `a`, i.e. `m \u2208 FS a` if `m` is the sum of a nonempty\nsubsequence of `a`. We give a direct inductive definition instead of talking about subsequences. -/\ninductive FS {M} [AddSemigroup M] : Stream' M \u2192 Set M\n  | head (a : Stream' M) : FS a a.headI\n  | tail (a : Stream' M) (m : M) (h : FS a.tail m) : FS a m\n  | cons (a : Stream' M) (m : M) (h : FS a.tail m) : FS a (a.headI + m)\n#align hindman.FS Hindman.FS\n-/\n\n#print Hindman.FP /-\n/-- `FP a` is the set of finite products in `a`, i.e. `m \u2208 FP a` if `m` is the product of a nonempty\nsubsequence of `a`. We give a direct inductive definition instead of talking about subsequences. -/\n@[to_additive FS]\ninductive FP {M} [Semigroup M] : Stream' M \u2192 Set M\n  | head (a : Stream' M) : FP a a.headI\n  | tail (a : Stream' M) (m : M) (h : FP a.tail m) : FP a m\n  | cons (a : Stream' M) (m : M) (h : FP a.tail m) : FP a (a.headI * m)\n#align hindman.FP Hindman.FP\n#align hindman.FS Hindman.FS\n-/\n\n/- warning: hindman.FP.mul -> Hindman.FP.mul is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] {a : Stream'.{u1} M} {m : M}, (Membership.Mem.{u1, u1} M (Set.{u1} M) (Set.hasMem.{u1} M) m (Hindman.FP.{u1} M _inst_1 a)) -> (Exists.{1} Nat (fun (n : Nat) => forall (m' : M), (Membership.Mem.{u1, u1} M (Set.{u1} M) (Set.hasMem.{u1} M) m' (Hindman.FP.{u1} M _inst_1 (Stream'.drop.{u1} M n a))) -> (Membership.Mem.{u1, u1} M (Set.{u1} M) (Set.hasMem.{u1} M) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (Semigroup.toHasMul.{u1} M _inst_1)) m m') (Hindman.FP.{u1} M _inst_1 a))))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] {a : Stream'.{u1} M} {m : M}, (Membership.mem.{u1, u1} M (Set.{u1} M) (Set.instMembershipSet.{u1} M) m (Hindman.FP.{u1} M _inst_1 a)) -> (Exists.{1} Nat (fun (n : Nat) => forall (m' : M), (Membership.mem.{u1, u1} M (Set.{u1} M) (Set.instMembershipSet.{u1} M) m' (Hindman.FP.{u1} M _inst_1 (Stream'.drop.{u1} M n a))) -> (Membership.mem.{u1, u1} M (Set.{u1} M) (Set.instMembershipSet.{u1} M) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (Semigroup.toMul.{u1} M _inst_1)) m m') (Hindman.FP.{u1} M _inst_1 a))))\nCase conversion may be inaccurate. Consider using '#align hindman.FP.mul Hindman.FP.mul\u2093'. -/\n/-- If `m` and `m'` are finite products in `M`, then so is `m * m'`, provided that `m'` is obtained\nfrom a subsequence of `M` starting sufficiently late. -/\n@[to_additive\n      \"If `m` and `m'` are finite sums in `M`, then so is `m + m'`, provided that `m'`\\nis obtained from a subsequence of `M` starting sufficiently late.\"]\ntheorem FP.mul {M} [Semigroup M] {a : Stream' M} {m : M} (hm : m \u2208 FP a) :\n    \u2203 n, \u2200 m' \u2208 FP (a.drop n), m * m' \u2208 FP a :=\n  by\n  induction' hm with a a m hm ih a m hm ih\n  \u00b7 exact \u27e81, fun m hm => FP.cons a m hm\u27e9\n  \u00b7 cases' ih with n hn\n    use n + 1\n    intro m' hm'\n    exact FP.tail _ _ (hn _ hm')\n  \u00b7 cases' ih with n hn\n    use n + 1\n    intro m' hm'\n    rw [mul_assoc]\n    exact FP.cons _ _ (hn _ hm')\n#align hindman.FP.mul Hindman.FP.mul\n#align hindman.FS.add Hindman.FS.add\n\n/- warning: hindman.exists_idempotent_ultrafilter_le_FP -> Hindman.exists_idempotent_ultrafilter_le_FP is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (a : Stream'.{u1} M), Exists.{succ u1} (Ultrafilter.{u1} M) (fun (U : Ultrafilter.{u1} M) => And (Eq.{succ u1} (Ultrafilter.{u1} M) (HMul.hMul.{u1, u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (instHMul.{u1} (Ultrafilter.{u1} M) (Ultrafilter.mul.{u1} M (Semigroup.toHasMul.{u1} M _inst_1))) U U) U) (Filter.Eventually.{u1} M (fun (m : M) => Membership.Mem.{u1, u1} M (Set.{u1} M) (Set.hasMem.{u1} M) m (Hindman.FP.{u1} M _inst_1 a)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Ultrafilter.{u1} M) (Filter.{u1} M) (HasLiftT.mk.{succ u1, succ u1} (Ultrafilter.{u1} M) (Filter.{u1} M) (CoeTC\u2093.coe.{succ u1, succ u1} (Ultrafilter.{u1} M) (Filter.{u1} M) (Ultrafilter.Filter.hasCoeT.{u1} M))) U)))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (a : Stream'.{u1} M), Exists.{succ u1} (Ultrafilter.{u1} M) (fun (U : Ultrafilter.{u1} M) => And (Eq.{succ u1} (Ultrafilter.{u1} M) (HMul.hMul.{u1, u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (instHMul.{u1} (Ultrafilter.{u1} M) (Ultrafilter.mul.{u1} M (Semigroup.toMul.{u1} M _inst_1))) U U) U) (Filter.Eventually.{u1} M (fun (m : M) => Membership.mem.{u1, u1} M (Set.{u1} M) (Set.instMembershipSet.{u1} M) m (Hindman.FP.{u1} M _inst_1 a)) (Ultrafilter.toFilter.{u1} M U)))\nCase conversion may be inaccurate. Consider using '#align hindman.exists_idempotent_ultrafilter_le_FP Hindman.exists_idempotent_ultrafilter_le_FP\u2093'. -/\n@[to_additive exists_idempotent_ultrafilter_le_FS]\ntheorem exists_idempotent_ultrafilter_le_FP {M} [Semigroup M] (a : Stream' M) :\n    \u2203 U : Ultrafilter M, U * U = U \u2227 \u2200\u1da0 m in U, m \u2208 FP a :=\n  by\n  let S : Set (Ultrafilter M) := \u22c2 n, { U | \u2200\u1da0 m in U, m \u2208 FP (a.drop n) }\n  obtain \u27e8U, hU, U_idem\u27e9 := exists_idempotent_in_compact_subsemigroup _ S _ _ _\n  \u00b7 refine' \u27e8U, U_idem, _\u27e9\n    convert set.mem_Inter.mp hU 0\n  \u00b7 exact Ultrafilter.continuous_mul_left\n  \u00b7 apply IsCompact.nonempty_inter\u1d62_of_sequence_nonempty_compact_closed\n    \u00b7 intro n U hU\n      apply eventually.mono hU\n      rw [add_comm, \u2190 Stream'.drop_drop, \u2190 Stream'.tail_eq_drop]\n      exact FP.tail _\n    \u00b7 intro n\n      exact \u27e8pure _, mem_pure.mpr <| FP.head _\u27e9\n    \u00b7 exact (ultrafilter_isClosed_basic _).IsCompact\n    \u00b7 intro n\n      apply ultrafilter_isClosed_basic\n  \u00b7 exact IsClosed.isCompact (isClosed_inter\u1d62 fun i => ultrafilter_isClosed_basic _)\n  \u00b7 intro U hU V hV\n    rw [Set.mem_inter\u1d62] at *\n    intro n\n    rw [Set.mem_setOf_eq, Ultrafilter.eventually_mul]\n    apply eventually.mono (hU n)\n    intro m hm\n    obtain \u27e8n', hn\u27e9 := FP.mul hm\n    apply eventually.mono (hV (n' + n))\n    intro m' hm'\n    apply hn\n    simpa only [Stream'.drop_drop] using hm'\n#align hindman.exists_idempotent_ultrafilter_le_FP Hindman.exists_idempotent_ultrafilter_le_FP\n#align hindman.exists_idempotent_ultrafilter_le_FS Hindman.exists_idempotent_ultrafilter_le_FS\n\n/- warning: hindman.exists_FP_of_large -> Hindman.exists_FP_of_large is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (U : Ultrafilter.{u1} M), (Eq.{succ u1} (Ultrafilter.{u1} M) (HMul.hMul.{u1, u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (instHMul.{u1} (Ultrafilter.{u1} M) (Ultrafilter.mul.{u1} M (Semigroup.toHasMul.{u1} M _inst_1))) U U) U) -> (forall (s\u2080 : Set.{u1} M), (Membership.Mem.{u1, u1} (Set.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.hasMem.{u1} M) s\u2080 U) -> (Exists.{succ u1} (Stream'.{u1} M) (fun (a : Stream'.{u1} M) => HasSubset.Subset.{u1} (Set.{u1} M) (Set.hasSubset.{u1} M) (Hindman.FP.{u1} M _inst_1 a) s\u2080)))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (U : Ultrafilter.{u1} M), (Eq.{succ u1} (Ultrafilter.{u1} M) (HMul.hMul.{u1, u1, u1} (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.{u1} M) (instHMul.{u1} (Ultrafilter.{u1} M) (Ultrafilter.mul.{u1} M (Semigroup.toMul.{u1} M _inst_1))) U U) U) -> (forall (s\u2080 : Set.{u1} M), (Membership.mem.{u1, u1} (Set.{u1} M) (Ultrafilter.{u1} M) (Ultrafilter.instMembershipSetUltrafilter.{u1} M) s\u2080 U) -> (Exists.{succ u1} (Stream'.{u1} M) (fun (a : Stream'.{u1} M) => HasSubset.Subset.{u1} (Set.{u1} M) (Set.instHasSubsetSet.{u1} M) (Hindman.FP.{u1} M _inst_1 a) s\u2080)))\nCase conversion may be inaccurate. Consider using '#align hindman.exists_FP_of_large Hindman.exists_FP_of_large\u2093'. -/\n@[to_additive exists_FS_of_large]\ntheorem exists_FP_of_large {M} [Semigroup M] (U : Ultrafilter M) (U_idem : U * U = U) (s\u2080 : Set M)\n    (sU : s\u2080 \u2208 U) : \u2203 a, FP a \u2286 s\u2080 :=\n  by\n  /- Informally: given a `U`-large set `s\u2080`, the set `s\u2080 \u2229 { m | \u2200\u1da0 m' in U, m * m' \u2208 s\u2080 }` is also\n  `U`-large (since `U` is idempotent). Thus in particular there is an `a\u2080` in this intersection. Now\n  let `s\u2081` be the intersection `s\u2080 \u2229 { m | a\u2080 * m \u2208 s\u2080 }`. By choice of `a\u2080`, this is again `U`-large,\n  so we can repeat the argument starting from `s\u2081`, obtaining `a\u2081`, `s\u2082`, etc. This gives the desired\n  infinite sequence. -/\n  have exists_elem : \u2200 {s : Set M} (hs : s \u2208 U), (s \u2229 { m | \u2200\u1da0 m' in U, m * m' \u2208 s }).Nonempty :=\n    fun s hs =>\n    Ultrafilter.nonempty_of_mem\n      (inter_mem hs <| by\n        rw [\u2190 U_idem] at hs\n        exact hs)\n  let elem : { s // s \u2208 U } \u2192 M := fun p => (exists_elem p.property).some\n  let succ : { s // s \u2208 U } \u2192 { s // s \u2208 U } := fun p =>\n    \u27e8p.val \u2229 { m | elem p * m \u2208 p.val },\n      inter_mem p.2 <| show _ from Set.inter_subset_right _ _ (exists_elem p.2).some_mem\u27e9\n  use Stream'.corec elem succ (Subtype.mk s\u2080 sU)\n  suffices \u2200 (a : Stream' M), \u2200 m \u2208 FP a, \u2200 p, a = Stream'.corec elem succ p \u2192 m \u2208 p.val\n    by\n    intro m hm\n    exact this _ m hm \u27e8s\u2080, sU\u27e9 rfl\n  clear sU s\u2080\n  intro a m h\n  induction' h with b b n h ih b n h ih\n  \u00b7 rintro p rfl\n    rw [Stream'.corec_eq, Stream'.head_cons]\n    exact Set.inter_subset_left _ _ (Set.Nonempty.some_mem _)\n  \u00b7 rintro p rfl\n    refine' Set.inter_subset_left _ _ (ih (succ p) _)\n    rw [Stream'.corec_eq, Stream'.tail_cons]\n  \u00b7 rintro p rfl\n    have := Set.inter_subset_right _ _ (ih (succ p) _)\n    \u00b7 simpa only using this\n    rw [Stream'.corec_eq, Stream'.tail_cons]\n#align hindman.exists_FP_of_large Hindman.exists_FP_of_large\n#align hindman.exists_FS_of_large Hindman.exists_FS_of_large\n\n/- warning: hindman.FP_partition_regular -> Hindman.FP_partition_regular is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (a : Stream'.{u1} M) (s : Set.{u1} (Set.{u1} M)), (Set.Finite.{u1} (Set.{u1} M) s) -> (HasSubset.Subset.{u1} (Set.{u1} M) (Set.hasSubset.{u1} M) (Hindman.FP.{u1} M _inst_1 a) (Set.union\u209b.{u1} M s)) -> (Exists.{succ u1} (Set.{u1} M) (fun (c : Set.{u1} M) => Exists.{0} (Membership.Mem.{u1, u1} (Set.{u1} M) (Set.{u1} (Set.{u1} M)) (Set.hasMem.{u1} (Set.{u1} M)) c s) (fun (H : Membership.Mem.{u1, u1} (Set.{u1} M) (Set.{u1} (Set.{u1} M)) (Set.hasMem.{u1} (Set.{u1} M)) c s) => Exists.{succ u1} (Stream'.{u1} M) (fun (b : Stream'.{u1} M) => HasSubset.Subset.{u1} (Set.{u1} M) (Set.hasSubset.{u1} M) (Hindman.FP.{u1} M _inst_1 b) c))))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (a : Stream'.{u1} M) (s : Set.{u1} (Set.{u1} M)), (Set.Finite.{u1} (Set.{u1} M) s) -> (HasSubset.Subset.{u1} (Set.{u1} M) (Set.instHasSubsetSet.{u1} M) (Hindman.FP.{u1} M _inst_1 a) (Set.union\u209b.{u1} M s)) -> (Exists.{succ u1} (Set.{u1} M) (fun (c : Set.{u1} M) => And (Membership.mem.{u1, u1} (Set.{u1} M) (Set.{u1} (Set.{u1} M)) (Set.instMembershipSet.{u1} (Set.{u1} M)) c s) (Exists.{succ u1} (Stream'.{u1} M) (fun (b : Stream'.{u1} M) => HasSubset.Subset.{u1} (Set.{u1} M) (Set.instHasSubsetSet.{u1} M) (Hindman.FP.{u1} M _inst_1 b) c))))\nCase conversion may be inaccurate. Consider using '#align hindman.FP_partition_regular Hindman.FP_partition_regular\u2093'. -/\n/-- The strong form of **Hindman's theorem**: in any finite cover of an FP-set, one the parts\ncontains an FP-set. -/\n@[to_additive FS_partition_regular\n      \"The strong form of **Hindman's theorem**: in any finite cover of\\nan FS-set, one the parts contains an FS-set.\"]\ntheorem FP_partition_regular {M} [Semigroup M] (a : Stream' M) (s : Set (Set M)) (sfin : s.Finite)\n    (scov : FP a \u2286 \u22c3\u2080 s) : \u2203 c \u2208 s, \u2203 b : Stream' M, FP b \u2286 c :=\n  let \u27e8U, idem, aU\u27e9 := exists_idempotent_ultrafilter_le_FP a\n  let \u27e8c, cs, hc\u27e9 := (Ultrafilter.finite_union\u209b_mem_iff sfin).mp (mem_of_superset aU scov)\n  \u27e8c, cs, exists_FP_of_large U idem c hc\u27e9\n#align hindman.FP_partition_regular Hindman.FP_partition_regular\n#align hindman.FS_partition_regular Hindman.FS_partition_regular\n\n/- warning: hindman.exists_FP_of_finite_cover -> Hindman.exists_FP_of_finite_cover is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] [_inst_2 : Nonempty.{succ u1} M] (s : Set.{u1} (Set.{u1} M)), (Set.Finite.{u1} (Set.{u1} M) s) -> (HasSubset.Subset.{u1} (Set.{u1} M) (Set.hasSubset.{u1} M) (Top.top.{u1} (Set.{u1} M) (CompleteLattice.toHasTop.{u1} (Set.{u1} M) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} M) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} M) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} M) (Set.completeBooleanAlgebra.{u1} M)))))) (Set.union\u209b.{u1} M s)) -> (Exists.{succ u1} (Set.{u1} M) (fun (c : Set.{u1} M) => Exists.{0} (Membership.Mem.{u1, u1} (Set.{u1} M) (Set.{u1} (Set.{u1} M)) (Set.hasMem.{u1} (Set.{u1} M)) c s) (fun (H : Membership.Mem.{u1, u1} (Set.{u1} M) (Set.{u1} (Set.{u1} M)) (Set.hasMem.{u1} (Set.{u1} M)) c s) => Exists.{succ u1} (Stream'.{u1} M) (fun (a : Stream'.{u1} M) => HasSubset.Subset.{u1} (Set.{u1} M) (Set.hasSubset.{u1} M) (Hindman.FP.{u1} M _inst_1 a) c))))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] [_inst_2 : Nonempty.{succ u1} M] (s : Set.{u1} (Set.{u1} M)), (Set.Finite.{u1} (Set.{u1} M) s) -> (HasSubset.Subset.{u1} (Set.{u1} M) (Set.instHasSubsetSet.{u1} M) (Top.top.{u1} (Set.{u1} M) (CompleteLattice.toTop.{u1} (Set.{u1} M) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} M) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} M) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} M) (Set.instCompleteBooleanAlgebraSet.{u1} M)))))) (Set.union\u209b.{u1} M s)) -> (Exists.{succ u1} (Set.{u1} M) (fun (c : Set.{u1} M) => And (Membership.mem.{u1, u1} (Set.{u1} M) (Set.{u1} (Set.{u1} M)) (Set.instMembershipSet.{u1} (Set.{u1} M)) c s) (Exists.{succ u1} (Stream'.{u1} M) (fun (a : Stream'.{u1} M) => HasSubset.Subset.{u1} (Set.{u1} M) (Set.instHasSubsetSet.{u1} M) (Hindman.FP.{u1} M _inst_1 a) c))))\nCase conversion may be inaccurate. Consider using '#align hindman.exists_FP_of_finite_cover Hindman.exists_FP_of_finite_cover\u2093'. -/\n/-- The weak form of **Hindman's theorem**: in any finite cover of a nonempty semigroup, one of the\nparts contains an FP-set. -/\n@[to_additive exists_FS_of_finite_cover\n      \"The weak form of **Hindman's theorem**: in any finite cover\\nof a nonempty additive semigroup, one of the parts contains an FS-set.\"]\ntheorem exists_FP_of_finite_cover {M} [Semigroup M] [Nonempty M] (s : Set (Set M)) (sfin : s.Finite)\n    (scov : \u22a4 \u2286 \u22c3\u2080 s) : \u2203 c \u2208 s, \u2203 a : Stream' M, FP a \u2286 c :=\n  let \u27e8U, hU\u27e9 :=\n    exists_idempotent_of_compact_t2_of_continuous_mul_left (@Ultrafilter.continuous_mul_left M _)\n  let \u27e8c, c_s, hc\u27e9 := (Ultrafilter.finite_union\u209b_mem_iff sfin).mp (mem_of_superset univ_mem scov)\n  \u27e8c, c_s, exists_FP_of_large U hU c hc\u27e9\n#align hindman.exists_FP_of_finite_cover Hindman.exists_FP_of_finite_cover\n#align hindman.exists_FS_of_finite_cover Hindman.exists_FS_of_finite_cover\n\n#print Hindman.FP_drop_subset_FP /-\n@[to_additive FS_iter_tail_sub_FS]\ntheorem FP_drop_subset_FP {M} [Semigroup M] (a : Stream' M) (n : \u2115) : FP (a.drop n) \u2286 FP a :=\n  by\n  induction' n with n ih; \u00b7 rfl\n  rw [Nat.succ_eq_one_add, \u2190 Stream'.drop_drop]\n  exact trans (FP.tail _) ih\n#align hindman.FP_drop_subset_FP Hindman.FP_drop_subset_FP\n#align hindman.FS_iter_tail_sub_FS Hindman.FS_iter_tail_sub_FS\n-/\n\n#print Hindman.FP.singleton /-\n@[to_additive]\ntheorem FP.singleton {M} [Semigroup M] (a : Stream' M) (i : \u2115) : a.get? i \u2208 FP a :=\n  by\n  induction' i with i ih generalizing a\n  \u00b7 apply FP.head\n  \u00b7 apply FP.tail\n    apply ih\n#align hindman.FP.singleton Hindman.FP.singleton\n#align hindman.FS.singleton Hindman.FS.singleton\n-/\n\n/- warning: hindman.FP.mul_two -> Hindman.FP.mul_two is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (a : Stream'.{u1} M) (i : Nat) (j : Nat), (LT.lt.{0} Nat Nat.hasLt i j) -> (Membership.Mem.{u1, u1} M (Set.{u1} M) (Set.hasMem.{u1} M) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (Semigroup.toHasMul.{u1} M _inst_1)) (Stream'.nth.{u1} M a i) (Stream'.nth.{u1} M a j)) (Hindman.FP.{u1} M _inst_1 a))\nbut is expected to have type\n  forall {M : Type.{u1}} [_inst_1 : Semigroup.{u1} M] (a : Stream'.{u1} M) (i : Nat) (j : Nat), (LT.lt.{0} Nat instLTNat i j) -> (Membership.mem.{u1, u1} M (Set.{u1} M) (Set.instMembershipSet.{u1} M) (HMul.hMul.{u1, u1, u1} M M M (instHMul.{u1} M (Semigroup.toMul.{u1} M _inst_1)) (Stream'.nth.{u1} M a i) (Stream'.nth.{u1} M a j)) (Hindman.FP.{u1} M _inst_1 a))\nCase conversion may be inaccurate. Consider using '#align hindman.FP.mul_two Hindman.FP.mul_two\u2093'. -/\n@[to_additive]\ntheorem FP.mul_two {M} [Semigroup M] (a : Stream' M) (i j : \u2115) (ij : i < j) :\n    a.get? i * a.get? j \u2208 FP a := by\n  refine' FP_drop_subset_FP _ i _\n  rw [\u2190 Stream'.head_drop]\n  apply FP.cons\n  rcases le_iff_exists_add.mp (Nat.succ_le_of_lt ij) with \u27e8d, hd\u27e9\n  have := FP.singleton (a.drop i).tail d\n  rw [Stream'.tail_eq_drop, Stream'.nth_drop, Stream'.nth_drop] at this\n  convert this\n  rw [hd, add_comm, Nat.succ_add, Nat.add_succ]\n#align hindman.FP.mul_two Hindman.FP.mul_two\n#align hindman.FS.add_two Hindman.FS.add_two\n\n#print Hindman.FP.finset_prod /-\n@[to_additive]\ntheorem FP.finset_prod {M} [CommMonoid M] (a : Stream' M) (s : Finset \u2115) (hs : s.Nonempty) :\n    (s.Prod fun i => a.get? i) \u2208 FP a :=\n  by\n  refine' FP_drop_subset_FP _ (s.min' hs) _\n  induction' s using Finset.strongInduction with s ih\n  rw [\u2190 Finset.mul_prod_erase _ _ (s.min'_mem hs), \u2190 Stream'.head_drop]\n  cases' (s.erase (s.min' hs)).eq_empty_or_nonempty with h h\n  \u00b7 rw [h, Finset.prod_empty, mul_one]\n    exact FP.head _\n  \u00b7 apply FP.cons\n    rw [Stream'.tail_eq_drop, Stream'.drop_drop, add_comm]\n    refine' Set.mem_of_subset_of_mem _ (ih _ (Finset.erase_ssubset <| s.min'_mem hs) h)\n    have : s.min' hs + 1 \u2264 (s.erase (s.min' hs)).min' h :=\n      Nat.succ_le_of_lt (Finset.min'_lt_of_mem_erase_min' _ _ <| Finset.min'_mem _ _)\n    cases' le_iff_exists_add.mp this with d hd\n    rw [hd, add_comm, \u2190 Stream'.drop_drop]\n    apply FP_drop_subset_FP\n#align hindman.FP.finset_prod Hindman.FP.finset_prod\n#align hindman.FS.finset_sum Hindman.FS.finset_sum\n-/\n\nend Hindman\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/Hindman.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7039257782521189}}
{"text": "import topologia\nimport .separacio\n\nopen topological_space\nopen set\n\nvariables (X : Type) [topological_space X]\n\n/-- A topological space is (quasi)compact if every open covering admits a finite subcovering -/\ndef is_compact :=\n  \u2200 \ud835\udcb0 : set (set X), (\u2200 U \u2208 \ud835\udcb0, is_open U) \u2192 \n  (\u22c3\u2080 \ud835\udcb0 = univ) \u2192 (\u2203 \u2131 \u2286 \ud835\udcb0, finite \u2131 \u2227 \u22c3\u2080\u2131 = univ)\n\ndef is_compact_subset {X : Type} [topological_space X] (S : set X):=\n  \u2200 \ud835\udcb0 : set (set X), (\u2200 U \u2208 \ud835\udcb0, is_open U) \u2192\n  (S \u2286 \u22c3\u2080 \ud835\udcb0) \u2192 (\u2203 \u2131 \u2286 \ud835\udcb0, finite \u2131 \u2227 S \u2286 \u22c3\u2080\u2131 )\n\nlemma is_compact_set' {A : set X} {I : Type*} (h : is_compact_subset A) (U : I \u2192 set X)\n(hU : \u2200 i, is_open (U i)) (hcov : A \u2286 \u22c3\u2080 (U '' univ)):\n  \u2203 (F : set I), F.finite \u2227 (A \u2286 \u22c3\u2080 (U '' F)) :=\nbegin\n  unfold is_compact_subset at h,\n  set \ud835\udcb0 := U '' univ with \ud835\udcb0def,\n  have exists_preimage : \u2200 Ui \u2208 \ud835\udcb0, \u2203 i : I, (U i) = Ui, by finish,\n  let map_inverse : \ud835\udcb0 \u2192 I := \u03bb Ui, classical.some (exists_preimage Ui.1 Ui.2),\n  have map_inverse_spec : \u2200 Ui, U (map_inverse Ui) = Ui :=\n    \u03bb Ui, classical.some_spec (exists_preimage Ui.1 Ui.2),\n  have hU' : \u2200 Ui \u2208 \ud835\udcb0, is_open Ui,\n  {\n    intros Ui hUi,\n    obtain \u27e8i, hi\u27e9 := exists_preimage Ui hUi,\n    rw \u2190hi,\n    tauto,\n  },\n  obtain \u27e8FF, \u27e8hFF1, \u27e8hFF2,hFF3\u27e9\u27e9\u27e9 := h \ud835\udcb0 hU' hcov,\n  clear h,\n  set F := map_inverse '' (coe \u207b\u00b9' FF) with Fdef,\n  use F,\n  have Ffin : F.finite,\n  {\n    rw Fdef,\n    refine finite.image map_inverse _,\n    refine finite.preimage _ hFF2,\n    intros x hx y hy,\n    exact subtype.eq,\n  },\n  have hcov'' : U '' F = FF,\n  {\n    rw Fdef,\n    ext V,\n    split,\n    {\n      intro hV,\n      simp at hV,\n      obtain \u27e8i, \u27e8\u27e8Ui,\u27e8hUiF, \u27e8\u27e8j, haj\u27e9, hh'\u27e9\u27e9\u27e9,h\u27e9\u27e9 := hV,\n      subst h,\n      suffices : U i = Ui, by simpa [this] using hUiF,\n      apply (congr_arg U (eq.symm hh')).trans,\n      apply map_inverse_spec,\n    },\n    {\n      intro hV,\n      simp only [mem_image, set_coe.exists, mem_univ, mem_preimage, subtype.coe_mk],\n      have VinU : V \u2208 \ud835\udcb0 := hFF1 hV,\n      set i := map_inverse \u27e8V, VinU\u27e9,\n      use i, use V,\n      { exact \u27e8VinU, \u27e8hV, rfl\u27e9\u27e9 },\n      { exact_mod_cast map_inverse_spec \u27e8V, VinU\u27e9 }\n    }\n  },\n  simp [hcov''],\n  tauto,\nend\n\n\nlemma compact_space_iff_univ_compact :  is_compact X \u2194 is_compact_subset (univ :set X) :=\nbegin\n  split; intros h I hI hIX,\n  { obtain \u27e8F, hF, hh\u27e9 := h I hI (univ_subset_iff.mp hIX),\n    exact \u27e8F, hF, hh.1, hh.2.symm.subset\u27e9},\n  { obtain \u27e8F, hF, hh\u27e9 := h I hI (eq.symm hIX).subset,\n    exact \u27e8F, hF, hh.1, univ_subset_iff.mp hh.2\u27e9},\nend\n\nlemma finite_set_is_compact (h : fintype X) : is_compact X :=\nbegin\n  intros I hI huniv,\n  exact \u27e8I, rfl.subset, finite.of_fintype I, huniv\u27e9,\nend\n\nlemma union_of_compacts_is_compact {A B : set X} (hA : is_compact_subset A) (hB : is_compact_subset B) : is_compact_subset (A \u222a B) :=\nbegin\n  intros I hI huI,\n  have hinclAB := union_subset_iff.1 huI,\n  obtain \u27e8FA, hFA, hhFA\u27e9 := hA I hI hinclAB.1,\n  obtain \u27e8FB, hFB, hhFB\u27e9 := hB I hI hinclAB.2,\n  have hunion : A \u222a B \u2286 \u22c3\u2080(FA \u222a FB),\n  { rw  (sUnion_union FA FB),\n    exact union_subset_union hhFA.right hhFB.right},\n  exact \u27e8FA \u222a FB, union_subset hFA hFB, hhFA.left.union hhFB.left, hunion\u27e9,\nend\n\nlemma empty_is_compact : is_compact_subset (\u2205 : set X) :=\nbegin\n  intros I hI hhI,\n  use \u2205,\n  exact \u27e8 empty_subset I, finite_empty, by tauto\u27e9,\nend\n\nlemma finite_union_of_compacts_is_compact {I : set(set X)} (h : \u2200 s \u2208 I, is_compact_subset s) (hI : finite I) : is_compact_subset (\u22c3\u2080I):=\nbegin\n  revert h,\n  apply finite.induction_on hI,\n  { intros I,\n    rw sUnion_empty,\n    apply empty_is_compact},\n  { intros V T hVT hT hUT hs,\n    have t : (\u22c3\u2080insert V T) = \u22c3\u2080 T \u222a V, by finish,\n    have hsT: (\u2200 (s : set X), s \u2208 T \u2192 is_compact_subset s),\n    { intros s hhs,\n      exact hs s (mem_insert_of_mem V hhs)},\n    rw t,\n    exact union_of_compacts_is_compact X (hUT hsT) (hs V (mem_insert V T))},\nend\n\nlemma singleton_is_compact (x : X) : is_compact_subset ({x} : set X) :=\nbegin\n  intros I hI hIincl,\n  cases (bex_def.mp (hIincl  rfl)) with U hU,\n  have hsingUI : {x} \u2286 \u22c3\u2080{U},\n  { rw (sUnion_singleton U),\n    exact singleton_subset_iff.mpr hU.right},\n  exact \u27e8{U}, singleton_subset_iff.mpr hU.1, finite_singleton U, hsingUI\u27e9,  \nend\n\nlemma finite_subset_is_compact (A : set X): finite A \u2192 is_compact_subset A :=\nbegin\n  intro h,\n  apply finite.induction_on h,\n  apply empty_is_compact,\n  intros a s has hsfin hscpt,\n  apply union_of_compacts_is_compact,\n  apply singleton_is_compact,\n  assumption,\nend\n\nlemma closed_subset_of_compact_is_compact {A B : set X} (hA : is_closed A) (hB : is_compact_subset B) (hAB : A \u2286 B) : \n  is_compact_subset A :=\nbegin\n  intros I hI hIA,\n  have hF : \u2200 (U : set X), U \u2208 I \u222a {A\u1d9c} \u2192 is_open U,\n  { intros U hU,\n    cases ((mem_union U I {A\u1d9c}).mp hU) with h,\n      {exact hI U h},\n      {rwa (mem_singleton_iff.mp h)}},\n  have hUnionB : B \u2286 \u22c3\u2080(I \u222a {A\u1d9c}),\n  { rw [sUnion_union I {A\u1d9c}, A\u1d9c.sUnion_singleton, (union_diff_cancel hAB).symm],\n    exact union_subset_union hIA (inter_subset_right B A\u1d9c)},\n  obtain \u27e8F, hFA, hh\u27e9  := hB (I \u222a {A\u1d9c}) hF hUnionB,\n  have hFI : F \\ {A\u1d9c} \u2286 I,\n  { intros x hx,\n    cases ((mem_union x I {A\u1d9c}).mp (hFA ((diff_subset F {A\u1d9c})  hx))) with h,\n      {exact h},\n      {exfalso,\n       exact (not_mem_of_mem_diff hx) h}},\n  have hsubsetU : A \u2286 \u22c3\u2080(F \\ {A\u1d9c}),\n  { intros x hx,\n    rcases (mem_sUnion.1 ((subset.trans hAB hh.right) hx)) with \u27e8V, \u27e8hV1, hV2\u27e9\u27e9,\n    exact (@mem_sUnion X x (F \\ {A\u1d9c})).2 \u27e8V, \u27e8hV1, by finish\u27e9, hV2\u27e9},\n  exact \u27e8F\\{A\u1d9c}, hFI, hh.left.subset (diff_subset F {A\u1d9c}), hsubsetU\u27e9,\nend\n\n/-\nlemma finite_subset_is_compact_using_choice (A : set X) (h : finite A) : is_compact_subset A :=\nbegin\n  intros I hI huniv,\n  have H : \u2200 a \u2208 A, \u2203 ia \u2208 I, a \u2208 ia, by assumption,\n  let f : A \u2192 set X := \u03bb \u27e8x, hxA\u27e9, classical.some (H x hxA),\n  have hf1 : \u2200 (x : X) (hx : x \u2208 A), x \u2208 (f \u27e8x, hx\u27e9),\n  {\n    intros x hx,\n    have hh := classical.some_spec (H x hx),\n    tauto,\n  },\n  have hf2 : \u2200 (x : X) (hx : x \u2208 A), (f \u27e8x, hx\u27e9) \u2208 I,\n  {\n    intros x hx,\n    have hh := classical.some_spec (H x hx),\n    tauto,\n  },\n  use f '' univ,\n  simp,\n  split,\n  {\n    intros i hi,\n    simp at hi,\n    obtain \u27e8x, \u27e8hx,h'\u27e9\u27e9 := hi,\n    subst h',\n    tauto,\n  },\n  split,\n  {\n    haveI : fintype {x : X // x \u2208 A} := finite.fintype h,\n    apply finite_range f,\n  },\n  {\n    unfold Union,\n    intros x hx,\n    unfold supr,\n    rw Sup_eq_supr,\n    simp,\n    use f \u27e8x,hx\u27e9,\n    use x,\n    use hx,\n    tauto,\n  }\nend\n -/\nopen hausdorff_space\n\n\n-- X : Type, i A : set X\n-- per cada a \u2208 A, triem Ua, Va oberts amb a \u2208 Ua, y \u2208 Va, Ua \u2229 Va = \u2205.\n-- A \u2286 \u22c3 Ua. A compacte -> subrecobriment finit Ua1,..., Uan.\n-- V = \u22c2 Vai. obert perqu\u00e8 intersecci\u00f3 finita. Aquest V funciona.\n-- U : {a : X // a \u2208 A} \u2192 set X, a \u21a6 Ua\nlemma for_compact_exist_open_disjont {A : set X} [hausdorff_space X] (h : is_compact_subset A)\n  (y : X) (hyA : \u00ac y \u2208 A) :  \u2203 (V : set X), is_open V \u2227 V \u2229 A = \u2205 \u2227 y \u2208 V :=\nbegin\n  have UV : \u2200 a \u2208 A, \u2203 UVa : set X \u00d7 set X,\n    is_open UVa.fst \u2227 is_open UVa.snd \u2227 UVa.fst \u2229 UVa.snd = \u2205 \u2227 a \u2208 UVa.fst \u2227 y \u2208 UVa.snd,\n  {\n    intros a ha,\n    have hya : y \u2260 a,\n    { intro h, subst h, contradiction },\n    obtain \u27e8U, V, _\u27e9 := t2 a y hya,\n    exact \u27e8\u27e8U, V\u27e9, by tauto\u27e9,\n  },\n  let U : A \u2192 set X := \u03bb a, (classical.some (UV a.1 a.2)).fst,\n  have hU : \u2200 (a : A), is_open (U \u27e8a.1, a.2\u27e9)\n   := \u03bb a, (classical.some_spec (UV a.1 a.2)).1,\n  let V : A \u2192 set X := \u03bb a, (classical.some (UV a.1 a.2)).snd,\n  have hV : \u2200 (a : A), is_open (V \u27e8a.1, a.2\u27e9)\n   := \u03bb a, (classical.some_spec (UV a.1 a.2)).2.1,\n  have hUV : \u2200 (a : A), (U \u27e8a.1, a.2\u27e9 \u2229 V \u27e8a.1, a.2\u27e9 = \u2205)\n   := \u03bb a, (classical.some_spec (UV a.1 a.2)).2.2.1,\n  have hUVa : \u2200 (a : A), (a.1 \u2208 U \u27e8a.1, a.2\u27e9)\n   := \u03bb a, (classical.some_spec (UV a.1 a.2)).2.2.2.1,\n  have hUVy : \u2200 (a : A), (y \u2208 V \u27e8a.1, a.2\u27e9)\n   := \u03bb a, (classical.some_spec (UV a.1 a.2)).2.2.2.2,\n  have hAcov : A \u2286 \u22c3\u2080 (U '' univ),\n  {\n    intros a ha,\n    specialize hUVa \u27e8a, ha\u27e9,\n    simp only [mem_Union, sUnion_range, image_univ, set_coe.exists],\n    exact \u27e8a, ha, by simp [hUVa]\u27e9,\n  },\n  have hfin : \u2203 (F : set X), F.finite \u2227 (A \u2286 \u22c3\u2080 (U '' {x : A | x.1 \u2208 F})),\n  {\n    obtain \u27e8F, \u27e8hF1,hF2\u27e9\u27e9 := is_compact_set' _ h U hU hAcov,\n    use coe '' F,\n    simpa [finite.image coe hF1] using hF2,\n  },\n  obtain \u27e8F, \u27e8hf, h'\u27e9\u27e9 := hfin,\n  have : fintype {a // a \u2208 F},\n  {\n    apply fintype.of_finset (finite.to_finset hf),\n    finish,\n  },\n  haveI: fintype {a // a \u2208 F} := this,\n  use \u22c2\u2080 (V '' {x : A | x.1 \u2208 F}),\n  repeat {split},\n  {\n    apply is_open_sInter,--open_of_finite_set_opens,\n    {\n      apply finite.image,\n      refine finite.preimage _ hf,\n      dsimp,\n      intros x2 hx2 aa haa htmp,\n      exact subtype.eq htmp,\n    },\n    intros s hs,\n    simp at hs,\n    obtain \u27e8x, \u27e8hx1, \u27e8hxA, rfl\u27e9\u27e9\u27e9 := hs,\n    finish,\n  },\n  {\n    ext,\n    simp,\n    intros hx hxA,\n    specialize h' hxA,\n    simp only [exists_prop, mem_Union, sUnion_image, set_coe.exists] at h',\n    obtain \u27e8z, \u27e8hz1, \u27e8hz2, hz3\u27e9\u27e9\u27e9 := h',\n    specialize hUV \u27e8z, hz1\u27e9,\n    suffices : (U \u27e8z, hz1\u27e9 \u2229 V \u27e8z, hz1\u27e9) \u2260 \u2205, by contradiction,\n    apply nonempty.ne_empty,\n    exact \u27e8x, \u27e8hz3, hx z hz1 hz2\u27e9\u27e9,\n  },\n  { simpa using \u03bb x hx1 hx2, hUVy \u27e8x, hx1\u27e9 }\nend\n\nlemma compact_in_T2_is_closed {A : set X} [hausdorff_space X] (h : is_compact_subset A) : is_closed A :=\nbegin\n  have hAc : interior A\u1d9c = A\u1d9c,\n  { apply subset.antisymm,\n      {exact interior_subset_self A\u1d9c},\n    { intros x hxA,\n      cases (for_compact_exist_open_disjont X h) x hxA with V hV,\n      have hVAc : V \u2286 A\u1d9c,\n      { intros y hy,\n        have hynA : y \u2209 A,\n        { intro hyA,\n          have hyVA : y \u2208 V \u2229 A, by exact \u27e8hy, hyA\u27e9,\n          have hIe : V \u2229 A \u2260 \u2205, by finish,\n          exact hIe hV.2.1},\n        exact mem_compl hynA},\n      exact \u27e8V, hV.1, hV.2.2, hVAc\u27e9}},\n  rw [is_closed, \u2190 hAc],\n  exact (interior_is_open A\u1d9c),\nend\n", "meta": {"author": "mmasdeu", "repo": "barcelonaleanseminar", "sha": "140478080f6680ea5e3ce61e6523272e7e12219f", "save_path": "github-repos/lean/mmasdeu-barcelonaleanseminar", "path": "github-repos/lean/mmasdeu-barcelonaleanseminar/barcelonaleanseminar-140478080f6680ea5e3ce61e6523272e7e12219f/src/compacitat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7039257761615152}}
{"text": "import data.real.basic\n\n-- BEGIN\nexample {x y : \u211d} : x \u2264 y \u2227 \u00ac y \u2264 x \u2194 x \u2264 y \u2227 x \u2260 y :=\nbegin\n  split,\n    intro hl,\n    cases hl with hl1 hl2,\n    split,\n    exact hl1,\n    contrapose! hl2,\n    rw hl2,\n    \n    intro hr,\n    cases hr with hr1 hr2,\n    split, \n    exact hr1,\n    contrapose! hr2,\n    exact le_antisymm hr1 hr2,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/5_split/5.3_iff & conjunc/ex1_split_inequal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.7039229759959725}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sean a y b n\u00fameros reales. Demostrar que\n--    |a| - |b| \u2264 |a - b|\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : \u211d\n\nexample : |a| - |b| \u2264 |a - b| :=\ncalc |a| - |b|\n     = |a - b + b| - |b|     : by simp\n ... \u2264 (|a - b| + |b|) - |b| : sub_le_sub_right (abs_add (a - b) b) (|b|)\n ... = |a - b|               : add_sub_cancel (|a - b|) (|b|)\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Basicos/abs_sub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7038663617921137}}
{"text": "/-\nDesign challenge: how to represent problems that require \"determining\" a set.\n------------------------------------------------------------------------------\n\nConsider the following problem:\n\n\"\"\"\n[IMO 2019, Problem 1]\nLet \u2124 be the set of integers. Determine all functions f : \u2124 \u2192 \u2124 such that, for all integers a and b,\nf(2a) + 2f(b) = f(f(a+b))\n\"\"\"\n-/\n\n-- Consider the following naive formulation:\n\nnotation `\u2124` := Int\ndef Set (X : Type) : Type := X \u2192 Prop\ndef Set.mem {X : Type} (x : X) (s : Set X) : Prop := s x\n\ndef determineNaive {X : Type} (s\u2080 : Set X) : Type :=\n{ s : Set X // \u2200 x, s.mem x \u2194 s\u2080.mem x }\n\ndef IMO_2019_Problem_1_naive : Type :=\ndetermineNaive $ \u03bb (f : \u2124 \u2192 \u2124) => \u2200 (a b : \u2124), f (2 * a) + 2 * f b = f (f (a + b))\n\n-- However, this formulation admits the following degenerate solution:\n\nexample : IMO_2019_Problem_1_naive :=\n\u27e8 \u03bb (f : \u2124 \u2192 \u2124) => \u2200 (a b : \u2124), f (2 * a) + 2 * f b = f (f (a + b)), \u03bb _ => Iff.refl _ \u27e9\n\n-- Clearly this answer should not be accepted!\n-- We could in principle require the witness to be a decidable set:\n\ndef DecidableSet (X : Type) : Type := X \u2192 Bool\ndef DecidableSet.mem {X : Type} (x : X) (s : DecidableSet X) : Bool := s x\n\ndef determineDecidable {X : Type} (s\u2080 : Set X) : Type :=\n{ s : DecidableSet X // \u2200 (x : X), s.mem x \u2194 s\u2080.mem x }\n\ndef IMO_2019_Problem_1_decidable_set : Type :=\ndetermineDecidable $ \u03bb (f : \u2124 \u2192 \u2124) => \u2200 (a b : \u2124), f (2 * a) + 2 * f b = f (f (a + b))\n\n-- Unfortunately, this formulation does not work either, since equality of functions is not decidable.\n\n-- A third attempt is to wrap different types of acceptable solutions into an inductive type:\n\ndef List.mem {X : Type} (x\u2080 : X) : List X \u2192 Prop\n| []    => false\n| x::xs => x = x\u2080 \u2228 List.mem xs\n\ninductive SolutionSet (X : Type)\n| finite            : List X \u2192 SolutionSet\n| countablyInfinite : (Nat \u2192 X) \u2192 SolutionSet\n\ndef SolutionSet.mem {X : Type} (x : X) : SolutionSet X \u2192 Prop\n| SolutionSet.finite xs            => List.mem x xs\n| SolutionSet.countablyInfinite \u03c6  => Exists $ \u03bb (n : Nat) => x = \u03c6 n\n\ndef determineSolutionSet (X : Type) (s\u2080 : Set X) : Type :=\n{ s : SolutionSet X // \u2200 (x : X), s.mem x \u2194 s\u2080.mem x }\n\n-- Unfortunately, it is not obvious how to make this approach workable for uncountable sets.\n-- (It seems reasonable for a solution to be e.g. { x : \u211d // x > 0 \u2227 x < 1 })\n\n-- Even worse, @fpvandoorn points out that choice could produce a SolutionSet that could\n-- be proved correct from only a proof that the desired set is countable.\n-- Similar issues could plague the other approaches as well.\n\n-- From @fpvandoorn: \"Even finiteness is too weak. Suppose a program\n-- proves that if (n,k) is a solution to IMO 2019-4, then the\n-- inequality n, k < 10^(10^100) holds. We can then apply the\n-- degenerate solution. A human solution like that will be rejected\n-- (you are not allowed to omit a finite but infeasible amount of\n-- work).\"\n\n/-\nTentative proposal:\n\nWe fear it may be very difficult to formalize a \"reasonable\" solution\nadequately, to simultaneously allow all acceptable solutions and to\ndisallow all degenerate ones, for all future problems. However, we\nexpect that for a given witness, there will be broad consensus on\nwhether or not it constitutes an acceptable solution.\n\nThus, in the absense of a solution to this design challenge, we\npropose that witnesses will be inspected by humans and are required to\nbe deemed 'reasonable'. Note that proofs will not be inspected by\nhumans.\n-/\n", "meta": {"author": "fredfeng", "repo": "formal-encoding", "sha": "024efcf58672ac6b817caa10dfe8cd9708b07f1b", "save_path": "github-repos/lean/fredfeng-formal-encoding", "path": "github-repos/lean/fredfeng-formal-encoding/formal-encoding-024efcf58672ac6b817caa10dfe8cd9708b07f1b/design/determine.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7038663573160485}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\n! This file was ported from Lean 3 source module data.nat.psub\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Option.Basic\nimport Mathbin.Data.Nat.Basic\n\n/-!\n# Partial predecessor and partial subtraction on the natural numbers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThe usual definition of natural number subtraction (`nat.sub`) returns 0 as a \"garbage value\" for\n`a - b` when `a < b`. Similarly, `nat.pred 0` is defined to be `0`. The functions in this file\nwrap the result in an `option` type instead:\n\n## Main definitions\n\n- `nat.ppred`: a partial predecessor operation\n- `nat.psub`: a partial subtraction operation\n\n-/\n\n\nnamespace Nat\n\n#print Nat.ppred /-\n/-- Partial predecessor operation. Returns `ppred n = some m`\n  if `n = m + 1`, otherwise `none`. -/\n@[simp]\ndef ppred : \u2115 \u2192 Option \u2115\n  | 0 => none\n  | n + 1 => some n\n#align nat.ppred Nat.ppred\n-/\n\n#print Nat.psub /-\n/-- Partial subtraction operation. Returns `psub m n = some k`\n  if `m = n + k`, otherwise `none`. -/\n@[simp]\ndef psub (m : \u2115) : \u2115 \u2192 Option \u2115\n  | 0 => some m\n  | n + 1 => psub n >>= ppred\n#align nat.psub Nat.psub\n-/\n\n#print Nat.pred_eq_ppred /-\ntheorem pred_eq_ppred (n : \u2115) : pred n = (ppred n).getD 0 := by cases n <;> rfl\n#align nat.pred_eq_ppred Nat.pred_eq_ppred\n-/\n\n#print Nat.sub_eq_psub /-\ntheorem sub_eq_psub (m : \u2115) : \u2200 n, m - n = (psub m n).getD 0\n  | 0 => rfl\n  | n + 1 => (pred_eq_ppred (m - n)).trans <| by rw [sub_eq_psub, psub] <;> cases psub m n <;> rfl\n#align nat.sub_eq_psub Nat.sub_eq_psub\n-/\n\n#print Nat.ppred_eq_some /-\n@[simp]\ntheorem ppred_eq_some {m : \u2115} : \u2200 {n}, ppred n = some m \u2194 succ m = n\n  | 0 => by constructor <;> intro h <;> contradiction\n  | n + 1 => by dsimp <;> constructor <;> intro h <;> injection h <;> subst n\n#align nat.ppred_eq_some Nat.ppred_eq_some\n-/\n\n#print Nat.ppred_eq_none /-\n@[simp]\ntheorem ppred_eq_none : \u2200 {n : \u2115}, ppred n = none \u2194 n = 0\n  | 0 => by simp\n  | n + 1 => by dsimp <;> constructor <;> contradiction\n#align nat.ppred_eq_none Nat.ppred_eq_none\n-/\n\n#print Nat.psub_eq_some /-\ntheorem psub_eq_some {m : \u2115} : \u2200 {n k}, psub m n = some k \u2194 k + n = m\n  | 0, k => by simp [eq_comm]\n  | n + 1, k => by\n    dsimp\n    apply option.bind_eq_some.trans\n    simp [psub_eq_some, add_comm, add_left_comm, Nat.succ_eq_add_one]\n#align nat.psub_eq_some Nat.psub_eq_some\n-/\n\n#print Nat.psub_eq_none /-\ntheorem psub_eq_none {m n : \u2115} : psub m n = none \u2194 m < n :=\n  by\n  cases s : psub m n <;> simp [eq_comm]\n  \u00b7 show m < n\n    refine' lt_of_not_ge fun h => _\n    cases' le.dest h with k e\n    injection s.symm.trans (psub_eq_some.2 <| (add_comm _ _).trans e)\n  \u00b7 show n \u2264 m\n    rw [\u2190 psub_eq_some.1 s]\n    apply Nat.le_add_left\n#align nat.psub_eq_none Nat.psub_eq_none\n-/\n\n#print Nat.ppred_eq_pred /-\ntheorem ppred_eq_pred {n} (h : 0 < n) : ppred n = some (pred n) :=\n  ppred_eq_some.2 <| succ_pred_eq_of_pos h\n#align nat.ppred_eq_pred Nat.ppred_eq_pred\n-/\n\n#print Nat.psub_eq_sub /-\ntheorem psub_eq_sub {m n} (h : n \u2264 m) : psub m n = some (m - n) :=\n  psub_eq_some.2 <| Nat.sub_add_cancel h\n#align nat.psub_eq_sub Nat.psub_eq_sub\n-/\n\n/- warning: nat.psub_add -> Nat.psub_add is a dubious translation:\nlean 3 declaration is\n  forall (m : Nat) (n : Nat) (k : Nat), Eq.{1} (Option.{0} Nat) (Nat.psub m (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n k)) (Bind.bind.{0, 0} Option.{0} (Monad.toHasBind.{0, 0} Option.{0} Option.monad.{0}) Nat Nat (Nat.psub m n) (fun (x : Nat) => Nat.psub x k))\nbut is expected to have type\n  forall (m : Nat) (n : Nat) (k : Nat), Eq.{1} (Option.{0} Nat) (Nat.psub m (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n k)) (Bind.bind.{0, 0} Option.{0} (Monad.toBind.{0, 0} Option.{0} instMonadOption.{0}) Nat Nat (Nat.psub m n) (fun (x : Nat) => Nat.psub x k))\nCase conversion may be inaccurate. Consider using '#align nat.psub_add Nat.psub_add\u2093'. -/\ntheorem psub_add (m n k) :\n    psub m (n + k) = do\n      let x \u2190 psub m n\n      psub x k :=\n  by induction k <;> simp [*, add_succ, bind_assoc]\n#align nat.psub_add Nat.psub_add\n\n#print Nat.psub' /-\n/-- Same as `psub`, but with a more efficient implementation. -/\n@[inline]\ndef psub' (m n : \u2115) : Option \u2115 :=\n  if n \u2264 m then some (m - n) else none\n#align nat.psub' Nat.psub'\n-/\n\n#print Nat.psub'_eq_psub /-\ntheorem psub'_eq_psub (m n) : psub' m n = psub m n := by\n  rw [psub'] <;> split_ifs <;> [exact (psub_eq_sub h).symm,\n    exact (psub_eq_none.2 (not_le.1 h)).symm]\n#align nat.psub'_eq_psub Nat.psub'_eq_psub\n-/\n\nend Nat\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Nat/Psub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543487, "lm_q2_score": 0.7879312006227323, "lm_q1q2_score": 0.7038663528399828}}
{"text": "def egJsonSentenceSim : String := \"[{'theorem': '{p : \u2115} [fact (nat.prime p)] : p % 2 = 1 \u2194 p \u2260 2', 'doc_string': 'A prime `p` satisfies `p % 2 = 1` if and only if `p \u2260 2`.'}, {'theorem': '{n : \u2115} : n % 2 = 1 \u2194 n % 4 = 1 \u2228 n % 4 = 3', 'doc_string': 'A natural number is odd iff it has residue `1` or `3` mod `4`'}, {'theorem': '{p : \u2115} (hp : nat.prime p) : p.factorization = finsupp.single p 1', 'doc_string': 'The only prime factor of prime `p` is `p` itself, with multiplicity `1`'}, {'theorem': '{m n : \u2115} : even (m ^ n) \u2194 even m \u2227 n \u2260 0', 'doc_string': ' If `m` and `n` are natural numbers, then the natural number `m^n` is even if and only if `m` is even and `n` is positive.'}]\"\n\ndef egSen : String := \"[{\\\"statement\\\": \\\"theorem nat.prime.mod_two_eq_one_iff_ne_two {p : \u2115} [fact (nat.prime p)] : p % 2 = 1 \u2194 p \u2260 2\\\", \\\"doc_string\\\": \\\"A prime `p` satisfies `p % 2 = 1` if and only if `p \u2260 2`.\\\", \\\"theorem\\\": \\\"{p : \u2115} [fact (nat.prime p)] : p % 2 = 1 \u2194 p \u2260 2\\\"}, {\\\"statement\\\": \\\"theorem nat.odd_mod_four_iff {n : \u2115} : n % 2 = 1 \u2194 n % 4 = 1 \u2228 n % 4 = 3\\\", \\\"doc_string\\\": \\\"A natural number is odd iff it has residue `1` or `3` mod `4`\\\", \\\"theorem\\\": \\\"{n : \u2115} : n % 2 = 1 \u2194 n % 4 = 1 \u2228 n % 4 = 3\\\"}, {\\\"statement\\\": \\\"theorem nat.factorization_eq_zero_iff (n : \u2115) : n.factorization = 0 \u2194 n = 0 \u2228 n = 1\\\", \\\"doc_string\\\": \\\"The only numbers with empty prime factorization are `0` and `1`\\\", \\\"theorem\\\": \\\"(n : \u2115) : n.factorization = 0 \u2194 n = 0 \u2228 n = 1\\\"}, {\\\"statement\\\": \\\"theorem nat.prime.factorization {p : \u2115} (hp : nat.prime p) : p.factorization = finsupp.single p 1\\\", \\\"doc_string\\\": \\\"The only prime factor of prime `p` is `p` itself, with multiplicity `1`\\\", \\\"theorem\\\": \\\"{p : \u2115} (hp : nat.prime p) : p.factorization = finsupp.single p 1\\\"}, {\\\"statement\\\": \\\"theorem nat.even_pow {m n : \u2115} : even (m ^ n) \u2194 even m \u2227 n \u2260 0\\\", \\\"doc_string\\\": \\\" If `m` and `n` are natural numbers, then the natural number `m^n` is even if and only if `m` is even and `n` is positive.\\\", \\\"theorem\\\": \\\"{m n : \u2115} : even (m ^ n) \u2194 even m \u2227 n \u2260 0\\\"}, {\\\"statement\\\": \\\"theorem is_prime_pow_iff_unique_prime_dvd {n : \u2115} : is_prime_pow n \u2194 \u2203! (p : \u2115), nat.prime p \u2227 p \u2223 n\\\", \\\"doc_string\\\": \\\" An equivalent definition for prime powers: `n` is a prime power iff there is a unique prime dividing it.\\\", \\\"theorem\\\": \\\"{n : \u2115} : is_prime_pow n \u2194 \u2203! (p : \u2115), nat.prime p \u2227 p \u2223 n\\\"}, {\\\"statement\\\": \\\"theorem nat.factorization_inj  : set.inj_on nat.factorization {x : \u2115 | x \u2260 0}\\\", \\\"doc_string\\\": \\\"Every nonzero natural number has a unique prime factorization\\\", \\\"theorem\\\": \\\" : set.inj_on nat.factorization {x : \u2115 | x \u2260 0}\\\"}, {\\\"statement\\\": \\\"theorem nat.mem_factors_mul_left {p a b : \u2115} (hpa : p \u2208 a.factors) (hb : b \u2260 0) : p \u2208 (a * b).factors\\\", \\\"doc_string\\\": \\\"If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0`\\\", \\\"theorem\\\": \\\"{p a b : \u2115} (hpa : p \u2208 a.factors) (hb : b \u2260 0) : p \u2208 (a * b).factors\\\"}, {\\\"statement\\\": \\\"theorem gaussian_int.prime_iff_mod_four_eq_three_of_nat_prime (p : \u2115) [hp : fact (nat.prime p)] : prime \u2191p \u2194 p % 4 = 3\\\", \\\"doc_string\\\": \\\"A prime natural number is prime in `\u2124[i]` if and only if it is `3` mod `4`\\\", \\\"theorem\\\": \\\"(p : \u2115) [hp : fact (nat.prime p)] : prime \u2191p \u2194 p % 4 = 3\\\"}]\"\n\ndef egBlob' := \"[{ \\\"text\\\" : \\\"{p : \u2115} (hp : Nat.Prime p) :  p = 2 \u2228 p % 2 = 1 \\\"},\n   { \\\"text\\\" : \\\"(p : \u2115) :  Nat.Prime p \u2194 p = 2 \u2228 p % 2 = 1 \\\"},\n   { \\\"text\\\" : \\\"{p : \u2115} (hp : Nat.Prime p) : p = 2 \u2228 p % 2 = 1 \\\"},\n   { \\\"text\\\" : \\\"(n : \u2115) (hp : Nat.Prime n) : n = 2 \u2228 n % 2 = 1 \\\"},\n   { \\\"text\\\" : \\\"{p : \u2115} (hp : Nat.Prime p) : p = 2 \u2228 p % 2 = 1 \\\"},\n   { \\\"text\\\" : \\\"Nonsense output to test filtering\\\"}]\"\n", "meta": {"author": "siddhartha-gadgil", "repo": "LeanAide", "sha": "7862af73ee2f0be08b20fd3e4148e20bf4a81054", "save_path": "github-repos/lean/siddhartha-gadgil-LeanAide", "path": "github-repos/lean/siddhartha-gadgil-LeanAide/LeanAide-7862af73ee2f0be08b20fd3e4148e20bf4a81054/LeanCodePrompts/EgsTranslate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.7038663372425774}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.finset.basic\nimport data.multiset.fold\n\n/-!\n# The fold operation for a commutative associative operation over a finset.\n-/\n\nnamespace finset\nopen multiset\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*}\n\n/-! ### fold -/\nsection fold\nvariables (op : \u03b2 \u2192 \u03b2 \u2192 \u03b2) [hc : is_commutative \u03b2 op] [ha : is_associative \u03b2 op]\nlocal notation a * b := op a b\ninclude hc ha\n\n/-- `fold op b f s` folds the commutative associative operation `op` over the\n  `f`-image of `s`, i.e. `fold (+) b f {1,2,3} = f 1 + f 2 + f 3 + b`. -/\ndef fold (b : \u03b2) (f : \u03b1 \u2192 \u03b2) (s : finset \u03b1) : \u03b2 := (s.1.map f).fold op b\n\nvariables {op} {f : \u03b1 \u2192 \u03b2} {b : \u03b2} {s : finset \u03b1} {a : \u03b1}\n\n@[simp] theorem fold_empty : (\u2205 : finset \u03b1).fold op b f = b := rfl\n\n@[simp] theorem fold_cons (h : a \u2209 s) : (cons a s h).fold op b f = f a * s.fold op b f :=\nby { dunfold fold, rw [cons_val, map_cons, fold_cons_left], }\n\n@[simp] theorem fold_insert [decidable_eq \u03b1] (h : a \u2209 s) :\n  (insert a s).fold op b f = f a * s.fold op b f :=\nby unfold fold; rw [insert_val, ndinsert_of_not_mem h, map_cons, fold_cons_left]\n\n@[simp] theorem fold_singleton : ({a} : finset \u03b1).fold op b f = f a * b := rfl\n\n@[simp] \n\n@[simp] theorem fold_image [decidable_eq \u03b1] {g : \u03b3 \u2192 \u03b1} {s : finset \u03b3}\n  (H : \u2200 (x \u2208 s) (y \u2208 s), g x = g y \u2192 x = y) : (s.image g).fold op b f = s.fold op b (f \u2218 g) :=\nby simp only [fold, image_val_of_inj_on H, multiset.map_map]\n\n@[congr] theorem fold_congr {g : \u03b1 \u2192 \u03b2} (H : \u2200 x \u2208 s, f x = g x) : s.fold op b f = s.fold op b g :=\nby rw [fold, fold, map_congr rfl H]\n\ntheorem fold_op_distrib {f g : \u03b1 \u2192 \u03b2} {b\u2081 b\u2082 : \u03b2} :\n  s.fold op (b\u2081 * b\u2082) (\u03bbx, f x * g x) = s.fold op b\u2081 f * s.fold op b\u2082 g :=\nby simp only [fold, fold_distrib]\n\nlemma fold_const [decidable (s = \u2205)] (c : \u03b2) (h : op c (op b c) = op b c) :\n  finset.fold op b (\u03bb _, c) s = if s = \u2205 then b else op b c :=\nbegin\n  classical,\n  unfreezingI { induction s using finset.induction_on with x s hx IH },\n  { simp },\n  { simp only [finset.fold_insert hx, IH, if_false, finset.insert_ne_empty],\n    split_ifs,\n    { rw hc.comm },\n    { exact h } }\nend\n\ntheorem fold_hom {op' : \u03b3 \u2192 \u03b3 \u2192 \u03b3} [is_commutative \u03b3 op'] [is_associative \u03b3 op']\n  {m : \u03b2 \u2192 \u03b3} (hm : \u2200x y, m (op x y) = op' (m x) (m y)) :\n  s.fold op' (m b) (\u03bbx, m (f x)) = m (s.fold op b f) :=\nby rw [fold, fold, \u2190 fold_hom op hm, multiset.map_map]\n\ntheorem fold_union_inter [decidable_eq \u03b1] {s\u2081 s\u2082 : finset \u03b1} {b\u2081 b\u2082 : \u03b2} :\n  (s\u2081 \u222a s\u2082).fold op b\u2081 f * (s\u2081 \u2229 s\u2082).fold op b\u2082 f = s\u2081.fold op b\u2082 f * s\u2082.fold op b\u2081 f :=\nby unfold fold; rw [\u2190 fold_add op, \u2190 multiset.map_add, union_val,\n     inter_val, union_add_inter, multiset.map_add, hc.comm, fold_add]\n\n@[simp] theorem fold_insert_idem [decidable_eq \u03b1] [hi : is_idempotent \u03b2 op] :\n  (insert a s).fold op b f = f a * s.fold op b f :=\nbegin\n  by_cases (a \u2208 s),\n  { rw [\u2190 insert_erase h], simp [\u2190 ha.assoc, hi.idempotent] },\n  { apply fold_insert h },\nend\n\ntheorem fold_image_idem [decidable_eq \u03b1] {g : \u03b3 \u2192 \u03b1} {s : finset \u03b3}\n  [hi : is_idempotent \u03b2 op] :\n  (image g s).fold op b f = s.fold op b (f \u2218 g) :=\nbegin\n  induction s using finset.cons_induction with x xs hx ih,\n  { rw [fold_empty, image_empty, fold_empty] },\n  { haveI := classical.dec_eq \u03b3,\n    rw [fold_cons, cons_eq_insert, image_insert, fold_insert_idem, ih], }\nend\n\n/-- A stronger version of `finset.fold_ite`, but relies on\nan explicit proof of idempotency on the seed element, rather\nthan relying on typeclass idempotency over the whole type. -/\nlemma fold_ite' {g : \u03b1 \u2192 \u03b2} (hb : op b b = b)\n  (p : \u03b1 \u2192 Prop) [decidable_pred p] :\n  finset.fold op b (\u03bb i, ite (p i) (f i) (g i)) s =\n  op (finset.fold op b f (s.filter p)) (finset.fold op b g (s.filter (\u03bb i, \u00ac p i))) :=\nbegin\n  classical,\n  induction s using finset.induction_on with x s hx IH,\n  { simp [hb] },\n  { simp only [finset.filter_congr_decidable, finset.fold_insert hx],\n    split_ifs with h h,\n    { have : x \u2209 finset.filter p s,\n      { simp [hx] },\n      simp [finset.filter_insert, h, finset.fold_insert this, ha.assoc, IH] },\n    { have : x \u2209 finset.filter (\u03bb i, \u00ac p i) s,\n      { simp [hx] },\n      simp [finset.filter_insert, h, finset.fold_insert this, IH, \u2190ha.assoc, hc.comm] } }\nend\n\n/-- A weaker version of `finset.fold_ite'`,\nrelying on typeclass idempotency over the whole type,\ninstead of solely on the seed element.\nHowever, this is easier to use because it does not generate side goals. -/\nlemma fold_ite [is_idempotent \u03b2 op] {g : \u03b1 \u2192 \u03b2}\n  (p : \u03b1 \u2192 Prop) [decidable_pred p] :\n  finset.fold op b (\u03bb i, ite (p i) (f i) (g i)) s =\n  op (finset.fold op b f (s.filter p)) (finset.fold op b g (s.filter (\u03bb i, \u00ac p i))) :=\nfold_ite' (is_idempotent.idempotent _) _\n\nlemma fold_op_rel_iff_and\n  {r : \u03b2 \u2192 \u03b2 \u2192 Prop} (hr : \u2200 {x y z}, r x (op y z) \u2194 (r x y \u2227 r x z)) {c : \u03b2} :\n  r c (s.fold op b f) \u2194 (r c b \u2227 \u2200 x\u2208s, r c (f x)) :=\nbegin\n  classical,\n  apply finset.induction_on s, { simp },\n  clear s, intros a s ha IH,\n  rw [finset.fold_insert ha, hr, IH, \u2190 and_assoc, and_comm (r c (f a)), and_assoc],\n  apply and_congr iff.rfl,\n  split,\n  { rintro \u27e8h\u2081, h\u2082\u27e9, intros b hb, rw finset.mem_insert at hb,\n    rcases hb with rfl|hb; solve_by_elim },\n  { intro h, split,\n    { exact h a (finset.mem_insert_self _ _), },\n    { intros b hb, apply h b, rw finset.mem_insert, right, exact hb } }\nend\n\nlemma fold_op_rel_iff_or\n  {r : \u03b2 \u2192 \u03b2 \u2192 Prop} (hr : \u2200 {x y z}, r x (op y z) \u2194 (r x y \u2228 r x z)) {c : \u03b2} :\n  r c (s.fold op b f) \u2194 (r c b \u2228 \u2203 x\u2208s, r c (f x)) :=\nbegin\n  classical,\n  apply finset.induction_on s, { simp },\n  clear s, intros a s ha IH,\n  rw [finset.fold_insert ha, hr, IH, \u2190 or_assoc, or_comm (r c (f a)), or_assoc],\n  apply or_congr iff.rfl,\n  split,\n  { rintro (h\u2081|\u27e8x, hx, h\u2082\u27e9),\n    { use a, simp [h\u2081] },\n    { refine \u27e8x, by simp [hx], h\u2082\u27e9 } },\n  { rintro \u27e8x, hx, h\u27e9,\n    rw mem_insert at hx, cases hx,\n    { left, rwa hx at h },\n    { right, exact \u27e8x, hx, h\u27e9 } }\nend\n\nomit hc ha\n\n@[simp]\nlemma fold_union_empty_singleton [decidable_eq \u03b1] (s : finset \u03b1) :\n  finset.fold (\u222a) \u2205 singleton s = s :=\nbegin\n  apply finset.induction_on s,\n  { simp only [fold_empty], },\n  { intros a s has ih, rw [fold_insert has, ih, insert_eq], }\nend\n\nlemma fold_sup_bot_singleton [decidable_eq \u03b1] (s : finset \u03b1) :\n  finset.fold (\u2294) \u22a5 singleton s = s :=\nfold_union_empty_singleton s\n\nsection order\nvariables [linear_order \u03b2] (c : \u03b2)\n\nlemma le_fold_min : c \u2264 s.fold min b f \u2194 (c \u2264 b \u2227 \u2200 x\u2208s, c \u2264 f x) :=\nfold_op_rel_iff_and $ \u03bb x y z, le_min_iff\n\nlemma fold_min_le : s.fold min b f \u2264 c \u2194 (b \u2264 c \u2228 \u2203 x\u2208s, f x \u2264 c) :=\nbegin\n  show _ \u2265 _ \u2194 _,\n  apply fold_op_rel_iff_or,\n  intros x y z,\n  show _ \u2264 _ \u2194 _,\n  exact min_le_iff\nend\n\nlemma lt_fold_min : c < s.fold min b f \u2194 (c < b \u2227 \u2200 x\u2208s, c < f x) :=\nfold_op_rel_iff_and $ \u03bb x y z, lt_min_iff\n\nlemma fold_min_lt : s.fold min b f < c \u2194 (b < c \u2228 \u2203 x\u2208s, f x < c) :=\nbegin\n  show _ > _ \u2194 _,\n  apply fold_op_rel_iff_or,\n  intros x y z,\n  show _ < _ \u2194 _,\n  exact min_lt_iff\nend\n\nlemma fold_max_le : s.fold max b f \u2264 c \u2194 (b \u2264 c \u2227 \u2200 x\u2208s, f x \u2264 c) :=\nbegin\n  show _ \u2265 _ \u2194 _,\n  apply fold_op_rel_iff_and,\n  intros x y z,\n  show _ \u2264 _ \u2194 _,\n  exact max_le_iff\nend\n\nlemma le_fold_max : c \u2264 s.fold max b f \u2194 (c \u2264 b \u2228 \u2203 x\u2208s, c \u2264 f x) :=\nfold_op_rel_iff_or $ \u03bb x y z, le_max_iff\n\nlemma fold_max_lt : s.fold max b f < c \u2194 (b < c \u2227 \u2200 x\u2208s, f x < c) :=\nbegin\n  show _ > _ \u2194 _,\n  apply fold_op_rel_iff_and,\n  intros x y z,\n  show _ < _ \u2194 _,\n  exact max_lt_iff\nend\n\nlemma lt_fold_max : c < s.fold max b f \u2194 (c < b \u2228 \u2203 x\u2208s, c < f x) :=\nfold_op_rel_iff_or $ \u03bb x y z, lt_max_iff\n\nend order\n\nend fold\n\nend finset\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/data/finset/fold.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7038649020192964}}
{"text": "import Std\n\ninductive Expr where\n  | var (i : Nat)\n  | op  (lhs rhs : Expr)\n  deriving Inhabited, Repr\n\ndef List.getIdx : List \u03b1 \u2192 Nat \u2192 \u03b1 \u2192 \u03b1\n  | [],    i,   u => u\n  | a::as, 0,   u => a\n  | a::as, i+1, u => getIdx as i u\n\nstructure Context (\u03b1 : Type u) where\n  op      : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n  assoc   : (a b c : \u03b1) \u2192 op (op a b) c = op a (op b c)\n  comm    : (a b : \u03b1) \u2192 op a b = op b a\n  vars    : List \u03b1\n  someVal : \u03b1\n\ntheorem Context.left_comm (ctx : Context \u03b1) (a b c : \u03b1) : ctx.op a (ctx.op b c) = ctx.op b (ctx.op a c) := by\n  rw [\u2190 ctx.assoc, ctx.comm a b, ctx.assoc]\n\ndef Expr.denote (ctx : Context \u03b1) : Expr \u2192 \u03b1\n  | Expr.op a b => ctx.op (denote ctx a) (denote ctx b)\n  | Expr.var i  => ctx.vars.getIdx i ctx.someVal\n\ntheorem Expr.denote_op (ctx : Context \u03b1) (a b : Expr) : denote ctx (Expr.op a b) = ctx.op (denote ctx a) (denote ctx b) :=\n  rfl\n\ndef Expr.concat : Expr \u2192 Expr \u2192 Expr\n  | Expr.op a b, c => Expr.op a (concat b c)\n  | Expr.var i, c  => Expr.op (Expr.var i) c\n\ntheorem Expr.denote_concat (ctx : Context \u03b1) (a b : Expr) : denote ctx (concat a b) = denote ctx (Expr.op a b) := by\n  induction a with\n  | var i => rfl\n  | op _ _ _ ih => simp [denote, ih, ctx.assoc]\n\ndef Expr.flat : Expr \u2192 Expr\n  | Expr.op a b => concat (flat a) (flat b)\n  | Expr.var i  => Expr.var i\n\ntheorem Expr.denote_flat (ctx : Context \u03b1) (e : Expr) : denote ctx (flat e) = denote ctx e := by\n  induction e with\n  | var i => rfl\n  | op a b ih\u2081 ih\u2082 => simp [flat, denote, denote_concat, ih\u2081, ih\u2082]\n\ntheorem Expr.eq_of_flat (ctx : Context \u03b1) (a b : Expr) (h : flat a = flat b) : denote ctx a = denote ctx b := by\n  have h := congrArg (denote ctx) h\n  simp [denote_flat] at h\n  assumption\n\ndef Expr.length : Expr \u2192 Nat\n  | op a b => 1 + b.length\n  | _      => 1\n\ndef Expr.sort (e : Expr) : Expr :=\n  loop e.length e\nwhere\n  loop : Nat \u2192 Expr \u2192 Expr\n    | fuel+1, Expr.op a e =>\n      let (e\u2081, e\u2082) := swap a e\n      Expr.op e\u2081 (loop fuel e\u2082)\n    | _, e => e\n\n  swap : Expr \u2192 Expr \u2192 Expr \u00d7 Expr\n    | Expr.var i, Expr.op (Expr.var j) e =>\n      if i > j then\n        let (e\u2081, e\u2082) := swap (Expr.var j) e\n        (e\u2081, Expr.op (Expr.var i) e\u2082)\n      else\n        let (e\u2081, e\u2082) := swap (Expr.var i) e\n        (e\u2081, Expr.op (Expr.var j) e\u2082)\n    | Expr.var i, Expr.var j =>\n      if i > j then\n        (Expr.var j, Expr.var i)\n      else\n        (Expr.var i, Expr.var j)\n    | e\u2081, e\u2082 => (e\u2081, e\u2082)\n\ntheorem Expr.denote_sort (ctx : Context \u03b1) (e : Expr) : denote ctx (sort e) = denote ctx e := by\n  apply denote_loop\nwhere\n  denote_loop (n : Nat) (e : Expr) : denote ctx (sort.loop n e) = denote ctx e := by\n    induction n generalizing e with\n    | zero => rfl\n    | succ n ih =>\n      match e with\n      | var _  => rfl\n      | op a b =>\n        simp [denote, sort.loop]\n        match h:sort.swap a b with\n        | (r\u2081, r\u2082) =>\n          have hs := denote_swap a b\n          rw [h] at hs\n          simp [denote] at hs\n          simp [denote, ih]\n          assumption\n\n  denote_swap (e\u2081 e\u2082 : Expr) : denote ctx (Expr.op (sort.swap e\u2081 e\u2082).1 (sort.swap e\u2081 e\u2082).2) = denote ctx (Expr.op e\u2081 e\u2082) := by\n    induction e\u2082 generalizing e\u2081 with\n    | op a b ih' ih =>\n      clear ih'\n      cases e\u2081 with\n      | var i =>\n        cases a with\n        | var j =>\n          byCases h : i > j\n          focus\n            simp [sort.swap, h]\n            match h:sort.swap (var j) b with\n            | (r\u2081, r\u2082) => simp; rw [denote_op (a := var i), \u2190 ih]; simp [h, denote]; rw [Context.left_comm]\n          focus\n            simp [sort.swap, h]\n            match h:sort.swap (var i) b with\n            | (r\u2081, r\u2082) =>\n              simp\n              rw [denote_op (a := var i), denote_op (a := var j), Context.left_comm, \u2190 denote_op (a := var i), \u2190 ih]\n              simp [h, denote]\n              rw [Context.left_comm]\n        | _ => rfl\n      | _ => rfl\n    | var j =>\n      cases e\u2081 with\n      | var i =>\n        byCases h : i > j\n        focus simp [sort.swap, h, denote, Context.comm]\n        focus simp [sort.swap, h]\n      | _ => rfl\n\ntheorem Expr.eq_of_sort_flat (ctx : Context \u03b1) (a b : Expr) (h : sort (flat a) = sort (flat b)) : denote ctx a = denote ctx b := by\n  have h := congrArg (denote ctx) h\n  simp [denote_flat, denote_sort] at h\n  assumption\n\ntheorem ex\u2081 (x\u2081 x\u2082 x\u2083 x\u2084 : Nat) : (x\u2081 + x\u2082) + (x\u2083 + x\u2084) = x\u2081 + x\u2082 + x\u2083 + x\u2084 :=\n  Expr.eq_of_flat\n    { op      := Nat.add\n      assoc   := Nat.add_assoc\n      comm    := Nat.add_comm\n      vars    := [x\u2081, x\u2082, x\u2083, x\u2084],\n      someVal := x\u2081 }\n    (Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.op (Expr.var 2) (Expr.var 3)))\n    (Expr.op (Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.var 2)) (Expr.var 3))\n    rfl\n\ntheorem ex\u2082 (x\u2081 x\u2082 x\u2083 x\u2084 : Nat) : (x\u2081 + x\u2082) + (x\u2083 + x\u2084) = x\u2083 + x\u2081 + x\u2082 + x\u2084 :=\n  Expr.eq_of_sort_flat\n    { op      := Nat.add\n      assoc   := Nat.add_assoc\n      comm    := Nat.add_comm\n      vars    := [x\u2081, x\u2082, x\u2083, x\u2084],\n      someVal := x\u2081 }\n    (Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.op (Expr.var 2) (Expr.var 3)))\n    (Expr.op (Expr.op (Expr.op (Expr.var 2) (Expr.var 0)) (Expr.var 1)) (Expr.var 3))\n    rfl\n\n#print ex\u2082\n", "meta": {"author": "Kha", "repo": "lean4-nightly", "sha": "b4c92de57090e6c47b29d3575df53d86fce52752", "save_path": "github-repos/lean/Kha-lean4-nightly", "path": "github-repos/lean/Kha-lean4-nightly/lean4-nightly-b4c92de57090e6c47b29d3575df53d86fce52752/tests/lean/run/ac_expr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7038648896291727}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n-/\nimport logic.encodable.basic\nimport order.atoms\nimport order.upper_lower\n\n/-!\n# Order ideals, cofinal sets, and the Rasiowa\u2013Sikorski lemma\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections require more\nstructure, such as a bottom element, a top element, or a join-semilattice structure.\n- `order.ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.\n  Dual to the notion of a filter on a preorder.\n- `order.is_ideal P`: a predicate for when a `set P` is an ideal.\n- `order.ideal.principal p`: the principal ideal generated by `p : P`.\n- `order.ideal.is_proper P`: a predicate for proper ideals.\n  Dual to the notion of a proper filter.\n- `order.ideal.is_maximal`: a predicate for maximal ideals.\n  Dual to the notion of an ultrafilter.\n- `order.cofinal P`: the type of subsets of `P` containing arbitrarily large elements.\n  Dual to the notion of 'dense set' used in forcing.\n- `order.ideal_of_cofinals p \ud835\udc9f`, where `p : P`, and `\ud835\udc9f` is a countable family of cofinal\n  subsets of P: an ideal in `P` which contains `p` and intersects every set in `\ud835\udc9f`. (This a form\n  of the Rasiowa\u2013Sikorski lemma.)\n\n## References\n\n- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>\n- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>\n- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>\n\nNote that for the Rasiowa\u2013Sikorski lemma, Wikipedia uses the opposite ordering on `P`,\nin line with most presentations of forcing.\n\n## Tags\n\nideal, cofinal, dense, countable, generic\n\n-/\n\nopen function set\n\nnamespace order\n\nvariables {P : Type*}\n\n/-- An ideal on an order `P` is a subset of `P` that is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\nstructure ideal (P) [has_le P] extends lower_set P :=\n(nonempty'  : carrier.nonempty)\n(directed'  : directed_on (\u2264) carrier)\n\n/-- A subset of a preorder `P` is an ideal if it is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\n@[mk_iff] structure is_ideal {P} [has_le P] (I : set P) : Prop :=\n(is_lower_set : is_lower_set I)\n(nonempty : I.nonempty)\n(directed : directed_on (\u2264) I)\n\n/-- Create an element of type `order.ideal` from a set satisfying the predicate\n`order.is_ideal`. -/\ndef is_ideal.to_ideal [has_le P] {I : set P} (h : is_ideal I) : ideal P :=\n\u27e8\u27e8I, h.is_lower_set\u27e9, h.nonempty, h.directed\u27e9\n\nnamespace ideal\nsection has_le\nvariables [has_le P]\n\nsection\nvariables {I J s t : ideal P} {x y : P}\n\nlemma to_lower_set_injective : injective (to_lower_set : ideal P \u2192 lower_set P) :=\n\u03bb s t h, by { cases s, cases t, congr' }\n\ninstance : set_like (ideal P) P :=\n{ coe := \u03bb s, s.carrier,\n  coe_injective' := \u03bb s t h, to_lower_set_injective $ set_like.coe_injective h }\n\n@[ext] lemma ext {s t : ideal P} : (s : set P) = t \u2192 s = t := set_like.ext'\n\n@[simp] lemma carrier_eq_coe (s : ideal P) : s.carrier = s := rfl\n@[simp] lemma coe_to_lower_set (s : ideal P) : (s.to_lower_set : set P) = s := rfl\n\nprotected lemma lower (s : ideal P) : is_lower_set (s : set P) := s.lower'\nprotected lemma nonempty (s : ideal P) : (s : set P).nonempty := s.nonempty'\nprotected lemma directed (s : ideal P) : directed_on (\u2264) (s : set P) := s.directed'\nprotected lemma is_ideal (s : ideal P) : is_ideal (s : set P) := \u27e8s.lower, s.nonempty, s.directed\u27e9\n\nlemma mem_compl_of_ge {x y : P} : x \u2264 y \u2192 x \u2208 (I : set P)\u1d9c \u2192 y \u2208 (I : set P)\u1d9c := \u03bb h, mt $ I.lower h\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : partial_order (ideal P) := partial_order.lift coe set_like.coe_injective\n\n@[simp] lemma coe_subset_coe : (s : set P) \u2286 t \u2194 s \u2264 t := iff.rfl\n@[simp] lemma coe_ssubset_coe : (s : set P) \u2282 t \u2194 s < t := iff.rfl\n\n@[trans] lemma mem_of_mem_of_le {x : P} {I J : ideal P} : x \u2208 I \u2192 I \u2264 J \u2192 x \u2208 J :=\n@set.mem_of_mem_of_subset P x I J\n\n/-- A proper ideal is one that is not the whole set.\n    Note that the whole set might not be an ideal. -/\n@[mk_iff] class is_proper (I : ideal P) : Prop := (ne_univ : (I : set P) \u2260 univ)\n\nlemma is_proper_of_not_mem {I : ideal P} {p : P} (nmem : p \u2209 I) : is_proper I :=\n\u27e8\u03bb hp, begin\n  change p \u2209 \u2191I at nmem,\n  rw hp at nmem,\n  exact nmem (mem_univ p),\nend\u27e9\n\n/-- An ideal is maximal if it is maximal in the collection of proper ideals.\n\nNote that `is_coatom` is less general because ideals only have a top element when `P` is directed\nand nonempty. -/\n@[mk_iff] class is_maximal (I : ideal P) extends is_proper I : Prop :=\n(maximal_proper : \u2200 \u2983J : ideal P\u2984, I < J \u2192 (J : set P) = univ)\n\nlemma inter_nonempty [is_directed P (\u2265)] (I J : ideal P) : (I \u2229 J : set P).nonempty :=\nbegin\n  obtain \u27e8a, ha\u27e9 := I.nonempty,\n  obtain \u27e8b, hb\u27e9 := J.nonempty,\n  obtain \u27e8c, hac, hbc\u27e9 := exists_le_le a b,\n  exact \u27e8c, I.lower hac ha, J.lower hbc hb\u27e9,\nend\n\nend\n\nsection directed\nvariables [is_directed P (\u2264)] [nonempty P] {I : ideal P}\n\n/-- In a directed and nonempty order, the top ideal of a is `univ`. -/\ninstance : order_top (ideal P) :=\n{ top := \u27e8\u22a4, univ_nonempty, directed_on_univ\u27e9,\n  le_top := \u03bb I, le_top }\n\n@[simp] lemma top_to_lower_set : (\u22a4 : ideal P).to_lower_set = \u22a4 := rfl\n@[simp] lemma coe_top : ((\u22a4 : ideal P) : set P) = univ := rfl\n\nlemma is_proper_of_ne_top (ne_top : I \u2260 \u22a4) : is_proper I := \u27e8\u03bb h, ne_top $ ext h\u27e9\n\nlemma is_proper.ne_top (hI : is_proper I) : I \u2260 \u22a4 := \u03bb h, is_proper.ne_univ $ congr_arg coe h\n\nlemma _root_.is_coatom.is_proper (hI : is_coatom I) : is_proper I := is_proper_of_ne_top hI.1\n\nlemma is_proper_iff_ne_top : is_proper I \u2194 I \u2260 \u22a4 := \u27e8\u03bb h, h.ne_top, \u03bb h, is_proper_of_ne_top h\u27e9\n\nlemma is_maximal.is_coatom (h : is_maximal I) : is_coatom I :=\n\u27e8is_maximal.to_is_proper.ne_top, \u03bb J h, ext $ is_maximal.maximal_proper h\u27e9\n\nlemma is_maximal.is_coatom' [is_maximal I] : is_coatom I := is_maximal.is_coatom \u2039_\u203a\n\nlemma _root_.is_coatom.is_maximal (hI : is_coatom I) : is_maximal I :=\n{ maximal_proper := \u03bb _ _, by simp [hI.2 _ \u2039_\u203a],\n  ..is_coatom.is_proper \u2039_\u203a }\n\nlemma is_maximal_iff_is_coatom : is_maximal I \u2194 is_coatom I := \u27e8\u03bb h, h.is_coatom, \u03bb h, h.is_maximal\u27e9\n\nend directed\n\nsection order_bot\nvariables [order_bot P]\n\n@[simp] lemma bot_mem (s : ideal P) : \u22a5 \u2208 s := s.lower bot_le s.nonempty.some_mem\n\nend order_bot\n\nsection order_top\nvariables [order_top P] {I : ideal P}\n\nlemma top_of_top_mem (h : \u22a4 \u2208 I) : I = \u22a4 := by { ext, exact iff_of_true (I.lower le_top h) trivial }\n\nlemma is_proper.top_not_mem (hI : is_proper I) : \u22a4 \u2209 I := \u03bb h, hI.ne_top $ top_of_top_mem h\n\nend order_top\nend has_le\n\nsection preorder\nvariables [preorder P]\n\nsection\nvariables {I J : ideal P} {x y : P}\n\n/-- The smallest ideal containing a given element. -/\n@[simps] def principal (p : P) : ideal P :=\n{ to_lower_set := lower_set.Iic p,\n  nonempty' := nonempty_Iic,\n  directed' := \u03bb x hx y hy, \u27e8p, le_rfl, hx, hy\u27e9 }\n\ninstance [inhabited P] : inhabited (ideal P) := \u27e8ideal.principal default\u27e9\n\n@[simp] lemma principal_le_iff : principal x \u2264 I \u2194 x \u2208 I :=\n\u27e8\u03bb h, h le_rfl, \u03bb hx y hy, I.lower hy hx\u27e9\n\n@[simp] lemma mem_principal : x \u2208 principal y \u2194 x \u2264 y := iff.rfl\n\nend\n\nsection order_bot\nvariables [order_bot P]\n\n/-- There is a bottom ideal when `P` has a bottom element. -/\ninstance : order_bot (ideal P) :=\n{ bot := principal \u22a5,\n  bot_le := by simp }\n\n@[simp] lemma principal_bot : principal (\u22a5 : P) = \u22a5 := rfl\n\nend order_bot\n\nsection order_top\nvariables [order_top P]\n\n@[simp] lemma principal_top : principal (\u22a4 : P) = \u22a4 := to_lower_set_injective $ lower_set.Iic_top\n\nend order_top\nend preorder\n\nsection semilattice_sup\nvariables [semilattice_sup P] {x y : P} {I s : ideal P}\n\n/-- A specific witness of `I.directed` when `P` has joins. -/\nlemma sup_mem (hx : x \u2208 s) (hy : y \u2208 s) : x \u2294 y \u2208 s :=\nlet \u27e8z, hz, hx, hy\u27e9 := s.directed x hx y hy in s.lower (sup_le hx hy) hz\n\n@[simp] lemma sup_mem_iff : x \u2294 y \u2208 I \u2194 x \u2208 I \u2227 y \u2208 I :=\n\u27e8\u03bb h, \u27e8I.lower le_sup_left h, I.lower le_sup_right h\u27e9, \u03bb h, sup_mem h.1 h.2\u27e9\n\nend semilattice_sup\n\nsection semilattice_sup_directed\nvariables [semilattice_sup P] [is_directed P (\u2265)] {x : P} {I J K s t : ideal P}\n\n/-- The infimum of two ideals of a co-directed order is their intersection. -/\ninstance : has_inf (ideal P) :=\n\u27e8\u03bb I J, { to_lower_set := I.to_lower_set \u2293 J.to_lower_set,\n  nonempty' := inter_nonempty I J,\n  directed' := \u03bb x hx y hy, \u27e8x \u2294 y, \u27e8sup_mem hx.1 hy.1, sup_mem hx.2 hy.2\u27e9, by simp\u27e9 }\u27e9\n\n/-- The supremum of two ideals of a co-directed order is the union of the down sets of the pointwise\nsupremum of `I` and `J`. -/\ninstance : has_sup (ideal P) :=\n\u27e8\u03bb I J, { carrier   := {x | \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j},\n  nonempty' := by { cases inter_nonempty I J, exact \u27e8w, w, h.1, w, h.2, le_sup_left\u27e9 },\n  directed' := \u03bb x \u27e8xi, _, xj, _, _\u27e9 y \u27e8yi, _, yj, _, _\u27e9,\n    \u27e8x \u2294 y,\n     \u27e8xi \u2294 yi, sup_mem \u2039_\u203a \u2039_\u203a,\n      xj \u2294 yj, sup_mem \u2039_\u203a \u2039_\u203a,\n      sup_le\n        (calc x \u2264 xi \u2294 xj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_left le_sup_left)\n        (calc y \u2264 yi \u2294 yj               : \u2039_\u203a\n         ...    \u2264 (xi \u2294 yi) \u2294 (xj \u2294 yj) : sup_le_sup le_sup_right le_sup_right)\u27e9,\n     le_sup_left, le_sup_right\u27e9,\n  lower' := \u03bb x y h \u27e8yi, _, yj, _, _\u27e9, \u27e8yi, \u2039_\u203a, yj, \u2039_\u203a, h.trans \u2039_\u203a\u27e9 }\u27e9\n\ninstance : lattice (ideal P) :=\n{ sup          := (\u2294),\n  le_sup_left  := \u03bb I J (i \u2208 I), by { cases J.nonempty, exact \u27e8i, \u2039_\u203a, w, \u2039_\u203a, le_sup_left\u27e9 },\n  le_sup_right := \u03bb I J (j \u2208 J), by { cases I.nonempty, exact \u27e8w, \u2039_\u203a, j, \u2039_\u203a, le_sup_right\u27e9 },\n  sup_le       := \u03bb I J K hIK hJK a \u27e8i, hi, j, hj, ha\u27e9,\n    K.lower ha $ sup_mem (mem_of_mem_of_le hi hIK) (mem_of_mem_of_le hj hJK),\n  inf          := (\u2293),\n  inf_le_left  := \u03bb I J, inter_subset_left I J,\n  inf_le_right := \u03bb I J, inter_subset_right I J,\n  le_inf       := \u03bb I J K, subset_inter,\n  .. ideal.partial_order }\n\n@[simp] lemma coe_sup : \u2191(s \u2294 t) = {x | \u2203 (a \u2208 s) (b \u2208 t), x \u2264 a \u2294 b} := rfl\n@[simp] lemma coe_inf : (\u2191(s \u2293 t) : set P) = s \u2229 t := rfl\n@[simp] lemma mem_inf : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J := iff.rfl\n@[simp] lemma mem_sup : x \u2208 I \u2294 J \u2194 \u2203 (i \u2208 I) (j \u2208 J), x \u2264 i \u2294 j := iff.rfl\n\nlemma lt_sup_principal_of_not_mem (hx : x \u2209 I) : I < I \u2294 principal x :=\nle_sup_left.lt_of_ne $ \u03bb h, hx $ by simpa only [left_eq_sup, principal_le_iff] using h\n\nend semilattice_sup_directed\n\nsection semilattice_sup_order_bot\nvariables [semilattice_sup P] [order_bot P] {x : P} {I J K : ideal P}\n\ninstance : has_Inf (ideal P) :=\n\u27e8\u03bb S, { to_lower_set := \u2a05 s \u2208 S, to_lower_set s,\n  nonempty' := \u27e8\u22a5, begin\n    rw [lower_set.carrier_eq_coe, lower_set.coe_infi\u2082, set.mem_Inter\u2082],\n    exact \u03bb s _, s.bot_mem,\n  end\u27e9,\n  directed' := \u03bb a ha b hb, \u27e8a \u2294 b, \u27e8\n    begin\n      rw [lower_set.carrier_eq_coe, lower_set.coe_infi\u2082, set.mem_Inter\u2082] at \u22a2 ha hb,\n      exact \u03bb s hs, sup_mem (ha _ hs) (hb _ hs),\n    end,\n    le_sup_left, le_sup_right\u27e9\u27e9 }\u27e9\n\nvariables {S : set (ideal P)}\n\n@[simp] lemma coe_Inf : (\u2191(Inf S) : set P) = \u22c2 s \u2208 S, \u2191s := lower_set.coe_infi\u2082 _\n\n@[simp] lemma mem_Inf : x \u2208 Inf S \u2194 \u2200 s \u2208 S, x \u2208 s :=\nby simp_rw [\u2190set_like.mem_coe, coe_Inf, mem_Inter\u2082]\n\ninstance : complete_lattice (ideal P) :=\n{ ..ideal.lattice,\n  ..complete_lattice_of_Inf (ideal P) (\u03bb S, begin\n    refine \u27e8\u03bb s hs, _, \u03bb s hs, by rwa [\u2190coe_subset_coe, coe_Inf, subset_Inter\u2082_iff]\u27e9,\n    rw [\u2190coe_subset_coe, coe_Inf],\n    exact bInter_subset_of_mem hs,\n  end) }\n\nend semilattice_sup_order_bot\n\nsection distrib_lattice\n\nvariables [distrib_lattice P]\nvariables {I J : ideal P}\n\nlemma eq_sup_of_le_sup {x i j: P} (hi : i \u2208 I) (hj : j \u2208 J) (hx : x \u2264 i \u2294 j) :\n  \u2203 (i' \u2208 I) (j' \u2208 J), x = i' \u2294 j' :=\nbegin\n  refine \u27e8x \u2293 i, I.lower inf_le_right hi, x \u2293 j, J.lower inf_le_right hj, _\u27e9,\n  calc\n  x    = x \u2293 (i \u2294 j)       : left_eq_inf.mpr hx\n  ...  = (x \u2293 i) \u2294 (x \u2293 j) : inf_sup_left,\nend\n\nlemma coe_sup_eq : \u2191(I \u2294 J) = {x | \u2203 i \u2208 I, \u2203 j \u2208 J, x = i \u2294 j} :=\nset.ext $ \u03bb _, \u27e8\u03bb \u27e8_, _, _, _, _\u27e9, eq_sup_of_le_sup \u2039_\u203a \u2039_\u203a \u2039_\u203a,\n  \u03bb \u27e8i, _, j, _, _\u27e9, \u27e8i, \u2039_\u203a, j, \u2039_\u203a, le_of_eq \u2039_\u203a\u27e9\u27e9\n\nend distrib_lattice\n\nsection boolean_algebra\n\nvariables [boolean_algebra P] {x : P} {I : ideal P}\n\nlemma is_proper.not_mem_of_compl_mem (hI : is_proper I) (hxc : x\u1d9c \u2208 I) : x \u2209 I :=\nbegin\n  intro hx,\n  apply hI.top_not_mem,\n  have ht : x \u2294 x\u1d9c \u2208 I := sup_mem \u2039_\u203a \u2039_\u203a,\n  rwa sup_compl_eq_top at ht,\nend\n\nlemma is_proper.not_mem_or_compl_not_mem (hI : is_proper I) : x \u2209 I \u2228 x\u1d9c \u2209 I :=\nhave h : x\u1d9c \u2208 I \u2192 x \u2209 I := hI.not_mem_of_compl_mem, by tauto\n\nend boolean_algebra\n\nend ideal\n\n/-- For a preorder `P`, `cofinal P` is the type of subsets of `P`\n  containing arbitrarily large elements. They are the dense sets in\n  the topology whose open sets are terminal segments. -/\nstructure cofinal (P) [preorder P] :=\n(carrier : set P)\n(mem_gt  : \u2200 x : P, \u2203 y \u2208 carrier, x \u2264 y)\n\nnamespace cofinal\n\nvariables [preorder P]\n\ninstance : inhabited (cofinal P) :=\n\u27e8{ carrier := univ, mem_gt := \u03bb x, \u27e8x, trivial, le_rfl\u27e9 }\u27e9\n\ninstance : has_mem P (cofinal P) := \u27e8\u03bb x D, x \u2208 D.carrier\u27e9\n\nvariables (D : cofinal P) (x : P)\n/-- A (noncomputable) element of a cofinal set lying above a given element. -/\nnoncomputable def above : P := classical.some $ D.mem_gt x\n\nlemma above_mem : D.above x \u2208 D :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb a _, a\n\nlemma le_above : x \u2264 D.above x :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ \u03bb _ b, b\n\nend cofinal\n\nsection ideal_of_cofinals\n\nvariables [preorder P] (p : P) {\u03b9 : Type*} [encodable \u03b9] (\ud835\udc9f : \u03b9 \u2192 cofinal P)\n\n/-- Given a starting point, and a countable family of cofinal sets,\n  this is an increasing sequence that intersects each cofinal set. -/\nnoncomputable def sequence_of_cofinals : \u2115 \u2192 P\n| 0 := p\n| (n+1) := match encodable.decode \u03b9 n with\n           | none   := sequence_of_cofinals n\n           | some i := (\ud835\udc9f i).above (sequence_of_cofinals n)\n           end\n\nlemma sequence_of_cofinals.monotone : monotone (sequence_of_cofinals p \ud835\udc9f) :=\nby { apply monotone_nat_of_le_succ, intros n, dunfold sequence_of_cofinals,\n  cases encodable.decode \u03b9 n, { refl }, { apply cofinal.le_above }, }\n\nlemma sequence_of_cofinals.encode_mem (i : \u03b9) :\n  sequence_of_cofinals p \ud835\udc9f (encodable.encode i + 1) \u2208 \ud835\udc9f i :=\nby { dunfold sequence_of_cofinals, rw encodable.encodek, apply cofinal.above_mem, }\n\n/-- Given an element `p : P` and a family `\ud835\udc9f` of cofinal subsets of a preorder `P`,\n  indexed by a countable type, `ideal_of_cofinals p \ud835\udc9f` is an ideal in `P` which\n  - contains `p`, according to `mem_ideal_of_cofinals p \ud835\udc9f`, and\n  - intersects every set in `\ud835\udc9f`, according to `cofinal_meets_ideal_of_cofinals p \ud835\udc9f`.\n\n  This proves the Rasiowa\u2013Sikorski lemma. -/\ndef ideal_of_cofinals : ideal P :=\n{ carrier   := { x : P | \u2203 n, x \u2264 sequence_of_cofinals p \ud835\udc9f n },\n  lower'     := \u03bb x y hxy \u27e8n, hn\u27e9, \u27e8n, le_trans hxy hn\u27e9,\n  nonempty' := \u27e8p, 0, le_rfl\u27e9,\n  directed' := \u03bb x \u27e8n, hn\u27e9 y \u27e8m, hm\u27e9,\n               \u27e8_, \u27e8max n m, le_rfl\u27e9,\n               le_trans hn $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_left _ _),\n               le_trans hm $ sequence_of_cofinals.monotone p \ud835\udc9f (le_max_right _ _) \u27e9 }\n\nlemma mem_ideal_of_cofinals : p \u2208 ideal_of_cofinals p \ud835\udc9f := \u27e80, le_rfl\u27e9\n\n/-- `ideal_of_cofinals p \ud835\udc9f` is `\ud835\udc9f`-generic. -/\nlemma cofinal_meets_ideal_of_cofinals (i : \u03b9) : \u2203 x : P, x \u2208 \ud835\udc9f i \u2227 x \u2208 ideal_of_cofinals p \ud835\udc9f :=\n\u27e8_, sequence_of_cofinals.encode_mem p \ud835\udc9f i, _, le_rfl\u27e9\n\nend ideal_of_cofinals\n\nend order\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7038648780842074}}
{"text": "/-\nCopyright (c) 2020 Ruben Van de Velde. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n-/\n\nimport data.int.parity\nimport ring_theory.int.basic\nimport ring_theory.prime\n\n/-- Being equal to `4` or odd. -/\ndef odd_prime_or_four (z : \u2124) : Prop :=\n  z = 4 \u2228 (prime z \u2227 odd z)\n\nlemma odd_prime_or_four.ne_zero {z : \u2124} (h : odd_prime_or_four z) : z \u2260 0 :=\nbegin\n  obtain rfl|\u27e8h, -\u27e9 := h,\n  { norm_num },\n  { exact h.ne_zero }\nend\n\nlemma odd_prime_or_four.ne_one {z : \u2124} (h : odd_prime_or_four z) : z \u2260 1 :=\nbegin\n  obtain rfl|\u27e8h, -\u27e9 := h,\n  { norm_num },\n  { exact h.ne_one }\nend\n\nlemma odd_prime_or_four.one_lt_abs {z : \u2124} (h : odd_prime_or_four z) : 1 < abs z :=\nbegin\n  obtain rfl|\u27e8h, -\u27e9 := h,\n  { rw int.abs_eq_nat_abs, norm_cast, norm_num },\n  { rw int.abs_eq_nat_abs,\n    rw int.prime_iff_nat_abs_prime at h,\n    norm_cast,\n    exact h.one_lt, }\nend\n\nlemma odd_prime_or_four.not_unit {z : \u2124} (h : odd_prime_or_four z) : \u00ac is_unit z :=\nbegin\n  obtain rfl|\u27e8h, -\u27e9 := h,\n  { rw is_unit_iff_dvd_one, norm_num },\n  { exact h.not_unit }\nend\n\nlemma odd_prime_or_four.abs {z : \u2124} (h : odd_prime_or_four z) : odd_prime_or_four (abs z) :=\nbegin\n  obtain rfl|\u27e8hp, ho\u27e9 := h,\n  { left, rw abs_eq_self, norm_num },\n  { right, exact \u27e8hp.abs, odd_abs.mpr ho\u27e9 }\nend\n\nlemma odd_prime_or_four.exists_and_dvd\n  {n : \u2124} (n2 : 2 < n) : \u2203 p, p \u2223 n \u2227 odd_prime_or_four p :=\nbegin\n  lift n to \u2115 using (zero_lt_two.trans n2).le,\n  norm_cast at n2,\n  obtain \u27e8k, rfl\u27e9|\u27e8p, hp, hdvd, hodd\u27e9 := n.eq_two_pow_or_exists_odd_prime_and_dvd,\n  { refine \u27e84, \u27e82 ^ (k - 2), _\u27e9, or.inl rfl\u27e9,\n    norm_cast,\n    calc 2 ^ k\n        = 2 ^ 2 * 2 ^ (k - 2) : (pow_mul_pow_sub _ _).symm\n    ... = 4 * 2 ^ (k - 2) : by norm_num,\n\n    rcases k with (_|_|_),\n    { exfalso, norm_num at n2 },\n    { exfalso, exact lt_irrefl _ n2 },\n    { exact le_add_self } },\n  { rw nat.prime_iff_prime_int at hp,\n    rw \u2190int.odd_coe_nat at hodd,\n    exact \u27e8p, int.coe_nat_dvd.mpr hdvd, or.inr \u27e8hp, hodd\u27e9\u27e9 },\nend\n\nlemma associated_of_dvd {a p : \u2124}\n  (ha : odd_prime_or_four a)\n  (hp : odd_prime_or_four p)\n  (h: p \u2223 a) : associated p a :=\nbegin\n  obtain (rfl|\u27e8ap, aodd\u27e9) := ha;\n  obtain (rfl|\u27e8pp, podd\u27e9) := hp,\n  { refl },\n  { exfalso,\n    have h0 : (4 : \u2124) = 2 ^ 2,\n    { norm_num },\n    rw h0 at h,\n    refine int.even_iff_not_odd.mp _ podd,\n    rw even_iff_two_dvd,\n    apply (associated.dvd _),\n    exact ((pp.dvd_prime_iff_associated int.prime_two).mp (pp.dvd_of_dvd_pow h)).symm },\n  { exfalso,\n    rw int.odd_iff_not_even at aodd,\n    refine aodd _,\n    rw even_iff_two_dvd,\n    refine (dvd_trans _ h),\n    norm_num },\n  { rwa prime.dvd_prime_iff_associated pp ap at h }\nend\n\nlemma dvd_or_dvd {a p x : \u2124}\n  (ha : odd_prime_or_four a)\n  (hp : odd_prime_or_four p)\n  (hdvd : p \u2223 a * x) : p \u2223 a \u2228 p \u2223 x :=\nbegin\n  obtain (rfl|\u27e8pp, podd\u27e9) := hp,\n  { obtain (rfl|\u27e8ap, aodd\u27e9) := ha,\n    { exact or.inl dvd_rfl },\n    { right,\n      have : (4 : \u2124) = 2 ^ 2,\n      { norm_num },\n      rw this at hdvd \u22a2,\n      apply int.prime_two.pow_dvd_of_dvd_mul_left _ _ hdvd,\n      rwa [\u2190even_iff_two_dvd, \u2190int.odd_iff_not_even] } },\n  { exact (pp.dvd_or_dvd hdvd) }\nend\n\nlemma exists_associated_mem_of_dvd_prod''\n  {p : \u2124} (hp : odd_prime_or_four p)\n  {s : multiset \u2124}\n  (hs : \u2200 r \u2208 s, odd_prime_or_four r)\n  (hdvd : p \u2223 s.prod) :\n  \u2203 q \u2208 s, associated p q :=\nbegin\n  induction s using multiset.induction_on with a s ih hs generalizing hs hdvd,\n  { simpa [hp.not_unit, \u2190is_unit_iff_dvd_one] using hdvd },\n  { rw [multiset.prod_cons] at hdvd,\n    have := hs a (multiset.mem_cons_self _ _),\n    obtain h|h := dvd_or_dvd this hp hdvd,\n    { exact \u27e8a, multiset.mem_cons_self _ _, associated_of_dvd this hp h\u27e9 },\n    { obtain \u27e8q, hq\u2081, hq\u2082\u27e9 := ih (\u03bb r hr, hs _ (multiset.mem_cons_of_mem hr)) h,\n      exact \u27e8q, multiset.mem_cons_of_mem hq\u2081, hq\u2082\u27e9 } }\nend\n\nlemma factors_unique_prod' : \u2200{f g : multiset \u2124},\n  (\u2200x\u2208f, odd_prime_or_four x) \u2192\n  (\u2200x\u2208g, odd_prime_or_four x) \u2192\n  (associated f.prod g.prod) \u2192\n  multiset.rel associated f g :=\nbegin\n  intros f,\n  refine multiset.induction_on f _ _,\n  { rintros g - hg h,\n    rw [multiset.prod_zero] at h,\n    rw [multiset.rel_zero_left],\n    apply multiset.eq_zero_of_forall_not_mem,\n    intros x hx,\n    apply (hg x hx).not_unit,\n    rw is_unit_iff_dvd_one,\n    exact dvd_trans (multiset.dvd_prod hx) h.symm.dvd },\n  { intros p f ih g hf hg hfg,\n    have hp := hf p (multiset.mem_cons_self _ _),\n    have hdvd : p \u2223 g.prod,\n    { rw [\u2190hfg.dvd_iff_dvd_right, multiset.prod_cons],\n      exact dvd_mul_right _ _ },\n    obtain \u27e8b, hbg, hb\u27e9 := exists_associated_mem_of_dvd_prod'' hp hg hdvd,\n    rw \u2190 multiset.cons_erase hbg,\n    apply multiset.rel.cons hb,\n    apply ih _ _ _,\n    { exact (\u03bb q hq, hf _ (multiset.mem_cons_of_mem hq)) },\n    { exact (\u03bb q (hq : q \u2208 g.erase b), hg q (multiset.mem_of_mem_erase hq)) },\n    { apply associated.of_mul_left _ hb hp.ne_zero,\n      rwa [\u2190 multiset.prod_cons, \u2190 multiset.prod_cons, multiset.cons_erase hbg] } },\nend\n\n/-- The odd factors. -/\nnoncomputable def odd_factors (x : \u2124) := multiset.filter odd (unique_factorization_monoid.normalized_factors x)\n\nlemma odd_factors.zero : odd_factors 0 = 0 := rfl\n\nlemma odd_factors.not_two_mem (x : \u2124) : (2 : \u2124) \u2209 odd_factors x :=\nbegin\n  simp only [odd_factors, even_bit0, not_true, not_false_iff, int.odd_iff_not_even, and_false,\n    multiset.mem_filter],\nend\n\nlemma odd_factors.nonneg {z a : \u2124} (ha : a \u2208 odd_factors z) : 0 \u2264 a :=\nbegin\n  simp only [odd_factors, multiset.mem_filter] at ha,\n  exact int.nonneg_of_normalize_eq_self\n    (unique_factorization_monoid.normalize_normalized_factor a ha.1)\nend\n\nlemma odd_factors.pow (z : \u2124) (n : \u2115) : odd_factors (z ^ n) = n \u2022 odd_factors z :=\nbegin\n  simp only [odd_factors],\n  rw [unique_factorization_monoid.normalized_factors_pow, multiset.filter_nsmul],\nend\n\n/-- The exponent of `2` in the factorization. -/\nnoncomputable def even_factor_exp (x : \u2124) := multiset.count 2 (unique_factorization_monoid.normalized_factors x)\n\nlemma even_factor_exp.def (x : \u2124) : even_factor_exp x = multiset.count 2 (unique_factorization_monoid.normalized_factors x) := rfl\n\nlemma even_factor_exp.zero : even_factor_exp 0 = 0 := rfl\n\nlemma even_factor_exp.pow (z : \u2124) (n : \u2115) : even_factor_exp (z ^ n) = n * even_factor_exp z :=\nbegin\n  simp only [even_factor_exp],\n  rw [unique_factorization_monoid.normalized_factors_pow, multiset.count_nsmul]\nend\n\nlemma even_and_odd_factors'' (x : \u2124) :\n  unique_factorization_monoid.normalized_factors x = (unique_factorization_monoid.normalized_factors x).filter (eq 2) + odd_factors x :=\nbegin\n  by_cases hx : x = 0,\n  { rw [hx, unique_factorization_monoid.normalized_factors_zero, odd_factors.zero, multiset.filter_zero,\n    add_zero] },\n  simp [even_factor_exp, odd_factors],\n  rw multiset.filter_add_filter,\n  convert (add_zero _).symm,\n  { rw multiset.filter_eq_self,\n    intros a ha,\n    have hprime : prime a := unique_factorization_monoid.prime_of_normalized_factor a ha,\n    have := unique_factorization_monoid.normalize_normalized_factor a ha,\n    rw [\u2190 int.abs_eq_normalize, \u2190 int.coe_nat_abs] at this,\n    rw [\u2190 this],\n    rw [int.prime_iff_nat_abs_prime] at hprime,\n    rcases nat.prime.eq_two_or_odd' hprime with (h2 | hodd),\n    { simp [h2] },\n    { right,\n      rw [this],\n      exact int.nat_abs_odd.1 hodd } },\n  { rw multiset.filter_eq_nil,\n    rintros a ha \u27e8rfl, hodd\u27e9,\n    norm_num at hodd },\nend\n\nlemma even_and_odd_factors' (x : \u2124) :\n  unique_factorization_monoid.normalized_factors x =\n  multiset.replicate (even_factor_exp x) 2 + odd_factors x :=\nbegin\n  convert even_and_odd_factors'' x,\n  simp [even_factor_exp, \u2190multiset.filter_eq],\nend\n\nlemma even_and_odd_factors (x : \u2124) (hx : x \u2260 0) : associated x (2 ^ (even_factor_exp x) * (odd_factors x).prod) :=\nbegin\n  convert (unique_factorization_monoid.normalized_factors_prod hx).symm,\n  simp [even_factor_exp],\n  rw [multiset.pow_count, \u2190multiset.prod_add, \u2190even_and_odd_factors'' x]\nend\n\nlemma factors_2_even {z : \u2124} (hz : z \u2260 0) : even_factor_exp (4 * z) = 2 + even_factor_exp z :=\nbegin\n  have h\u2080 : (4 : \u2124) \u2260 0 := four_ne_zero,\n  have h\u2081 : (2 : int) ^ 2 = 4,\n  { norm_num },\n  simp [even_factor_exp],\n  rw [unique_factorization_monoid.normalized_factors_mul h\u2080 hz, multiset.count_add, \u2190h\u2081,\n    unique_factorization_monoid.normalized_factors_pow, multiset.count_nsmul,\n    unique_factorization_monoid.normalized_factors_irreducible int.prime_two.irreducible,\n    int.normalize_of_nonneg zero_le_two, multiset.count_singleton_self, mul_one],\nend\n\n-- most useful with  (hz : even (even_factor_exp z))\n/-- Odd factors or `4`. -/\nnoncomputable def factors_odd_prime_or_four (z : \u2124) : multiset \u2124 :=\n  multiset.replicate (even_factor_exp z / 2) 4 + odd_factors z\n\nlemma factors_odd_prime_or_four.nonneg {z a : \u2124} (ha : a \u2208 factors_odd_prime_or_four z) : 0 \u2264 a :=\nbegin\n  simp only [factors_odd_prime_or_four, multiset.mem_add] at ha,\n  cases ha,\n  { rw multiset.eq_of_mem_replicate ha, norm_num },\n  { exact odd_factors.nonneg ha }\nend\n\nlemma factors_odd_prime_or_four.prod'\n  {a : \u2124}\n  (ha : 0 < a)\n  (heven : even (even_factor_exp a)) :\n  (factors_odd_prime_or_four a).prod = a :=\nbegin\n  apply int.eq_of_associated_of_nonneg,\n  { have := unique_factorization_monoid.normalized_factors_prod ha.ne',\n    apply associated.trans _ this,\n    obtain \u27e8m, hm\u27e9 := even_iff_two_dvd.mp heven,\n    rw [even_and_odd_factors' _, multiset.prod_add, factors_odd_prime_or_four, multiset.prod_add,\n      hm, nat.mul_div_right _ zero_lt_two, multiset.prod_replicate, multiset.prod_replicate,\n      pow_mul],\n    exact associated.refl _ },\n  { apply multiset.prod_nonneg,\n    apply factors_odd_prime_or_four.nonneg },\n  { exact ha.le },\nend\n\nlemma factors_odd_prime_or_four.associated'\n  {a : \u2124}\n  {f : multiset \u2124}\n  (hf : \u2200x\u2208f, odd_prime_or_four x)\n  (ha : 0 < a)\n  (heven : even (even_factor_exp a))\n  (hassoc : associated f.prod a) :\n  multiset.rel associated f (factors_odd_prime_or_four a) :=\nbegin\n  apply factors_unique_prod' hf,\n  { intros x hx,\n    simp only [factors_odd_prime_or_four, multiset.mem_add] at hx,\n    apply or.imp _ _ hx,\n    { exact multiset.eq_of_mem_replicate },\n    { simp only [odd_factors, multiset.mem_filter],\n      exact and.imp_left (unique_factorization_monoid.prime_of_normalized_factor _) } },\n  { rwa factors_odd_prime_or_four.prod' ha heven, }\nend\n\nlemma factors_odd_prime_or_four.unique'\n  {a : \u2124}\n  {f : multiset \u2124}\n  (hf : \u2200x\u2208f, odd_prime_or_four x)\n  (hf' : \u2200x\u2208f, (0 : \u2124) \u2264 x)\n  (ha : 0 < a)\n  (heven : even (even_factor_exp a))\n  (hassoc : associated f.prod a) :\n  f = (factors_odd_prime_or_four a) :=\nbegin\n  rw \u2190multiset.rel_eq,\n  apply multiset.rel.mono (factors_odd_prime_or_four.associated' hf ha heven hassoc),\n  intros x hx y hy hxy,\n  exact int.eq_of_associated_of_nonneg hxy (hf' x hx) (factors_odd_prime_or_four.nonneg hy)\nend\n\nlemma factors_odd_prime_or_four.pow\n  (z : \u2124) (n : \u2115) (hz : even (even_factor_exp z)) :\n  factors_odd_prime_or_four (z ^ n) = n \u2022 factors_odd_prime_or_four z :=\nbegin\n  simp only [factors_odd_prime_or_four, nsmul_add, multiset.nsmul_replicate, even_factor_exp.pow,\n    nat.mul_div_assoc _ (even_iff_two_dvd.mp hz), odd_factors.pow],\nend\n", "meta": {"author": "Ruben-VandeVelde", "repo": "flt", "sha": "c8712e379c65ec7beb1c4580b30c7284201a3900", "save_path": "github-repos/lean/Ruben-VandeVelde-flt", "path": "github-repos/lean/Ruben-VandeVelde-flt/flt-c8712e379c65ec7beb1c4580b30c7284201a3900/src/odd_prime_or_four.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.815232480373843, "lm_q1q2_score": 0.7038648780016746}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\n\nimport algebra.char_p.basic\nimport linear_algebra.finsupp_vector_space\n\n/-!\n# Multivariate polynomials over commutative rings\n\nThis file contains basic facts about multivariate polynomials over commutative rings, for example\nthat the monomials form a basis.\n\n## Main definitions\n\n* `restrict_total_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` of total degree at most `m`.\n* `restrict_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` such that the degree in each individual variable is at most `m`.\n\n## Main statements\n\n* The multivariate polynomial ring over a commutative ring of positive characteristic has positive\n  characteristic.\n* `basis_monomials`: shows that the monomials form a basis of the vector space of multivariate\n  polynomials.\n\n## TODO\n\nGeneralise to noncommutative (semi)rings\n-/\n\nnoncomputable theory\n\nopen_locale classical\n\nopen set linear_map submodule\nopen_locale big_operators\n\nuniverses u v\nvariables (\u03c3 : Type u) (R : Type v) [comm_ring R] (p m : \u2115)\n\nnamespace mv_polynomial\n\nsection char_p\n\ninstance [char_p R p] : char_p (mv_polynomial \u03c3 R) p :=\n{ cast_eq_zero_iff := \u03bb n, by rw [\u2190 C_eq_coe_nat, \u2190 C_0, C_inj, char_p.cast_eq_zero_iff R p] }\n\nend char_p\n\nsection homomorphism\n\nlemma map_range_eq_map {R S : Type*} [comm_ring R] [comm_ring S] (p : mv_polynomial \u03c3 R)\n  (f : R \u2192+* S) :\n  finsupp.map_range f f.map_zero p = map f p :=\nbegin\n  -- `finsupp.map_range_finset_sum` expects `f : R \u2192+ S`\n  change finsupp.map_range (f : R \u2192+ S) (f : R \u2192+ S).map_zero p = map f p,\n  rw [p.as_sum, finsupp.map_range_finset_sum, (map f).map_sum],\n  refine finset.sum_congr rfl (assume n _, _),\n  rw [map_monomial, \u2190 single_eq_monomial, finsupp.map_range_single, single_eq_monomial,\n    f.coe_add_monoid_hom],\nend\n\nend homomorphism\n\nsection degree\n\n/-- The submodule of polynomials of total degree less than or equal to `m`.-/\ndef restrict_total_degree : submodule R (mv_polynomial \u03c3 R) :=\nfinsupp.supported _ _ {n | n.sum (\u03bbn e, e) \u2264 m }\n\n/-- The submodule of polynomials such that the degree with respect to each individual variable is\nless than or equal to `m`.-/\ndef restrict_degree (m : \u2115) : submodule R (mv_polynomial \u03c3 R) :=\nfinsupp.supported _ _ {n | \u2200i, n i \u2264 m }\n\nvariable {R}\n\nlemma mem_restrict_total_degree (p : mv_polynomial \u03c3 R) :\n  p \u2208 restrict_total_degree \u03c3 R m \u2194 p.total_degree \u2264 m :=\nbegin\n  rw [total_degree, finset.sup_le_iff],\n  refl\nend\n\nlemma mem_restrict_degree (p : mv_polynomial \u03c3 R) (n : \u2115) :\n  p \u2208 restrict_degree \u03c3 R n \u2194 (\u2200s \u2208 p.support, \u2200i, (s : \u03c3 \u2192\u2080 \u2115) i \u2264 n) :=\nbegin\n  rw [restrict_degree, finsupp.mem_supported],\n  refl\nend\n\nlemma mem_restrict_degree_iff_sup (p : mv_polynomial \u03c3 R) (n : \u2115) :\n  p \u2208 restrict_degree \u03c3 R n \u2194 \u2200i, p.degrees.count i \u2264 n :=\nbegin\n  simp only [mem_restrict_degree, degrees, multiset.count_sup, finsupp.count_to_multiset,\n    finset.sup_le_iff],\n  exact \u27e8assume h n s hs, h s hs n, assume h s hs n, h n s hs\u27e9\nend\n\nvariables (\u03c3 R)\n\n/-- The monomials form a basis on `mv_polynomial \u03c3 R`. -/\ndef basis_monomials : basis (\u03c3 \u2192\u2080 \u2115) R (mv_polynomial \u03c3 R) := finsupp.basis_single_one\n\n@[simp] lemma coe_basis_monomials :\n  (basis_monomials \u03c3 R : (\u03c3 \u2192\u2080 \u2115) \u2192 mv_polynomial \u03c3 R) = \u03bb s, monomial s 1 :=\nrfl\n\nlemma linear_independent_X : linear_independent R (X : \u03c3 \u2192 mv_polynomial \u03c3 R) :=\n(basis_monomials \u03c3 R).linear_independent.comp\n  (\u03bb s : \u03c3, finsupp.single s 1) (finsupp.single_left_injective one_ne_zero)\n\nend degree\n\nend mv_polynomial\n\n\n/- this is here to avoid import cycle issues -/\nnamespace polynomial\n\n/-- The monomials form a basis on `polynomial R`. -/\nnoncomputable def basis_monomials : basis \u2115 R (polynomial R) :=\nfinsupp.basis_single_one.map (to_finsupp_iso_alg R).to_linear_equiv.symm\n\n@[simp] lemma coe_basis_monomials :\n  (basis_monomials R : \u2115 \u2192 polynomial R) = \u03bb s, monomial s 1 :=\n_root_.funext $ \u03bb n, to_finsupp_iso_symm_single\n\nend polynomial\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/ring_theory/mv_polynomial/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7038339071624867}}
{"text": "import data.real.basic\nimport tactic\n\nnamespace vilnius\n\nlocal notation `|` x `|` := abs x\n\n\n/-- `l` is the limit of the sequence `a` of reals -/\ndefinition is_limit (a : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, | a n - l | < \u03b5\n\n\n/-- The limit of a constant sequence is the constant. -/\ntheorem is_limit_const (c : \u211d) : is_limit (\u03bb n, c) c :=\nbegin\n  sorry,\nend\n\n-- We will chose \u03b5 later...\ntheorem is_limit_add {a b : \u2115 \u2192 \u211d} {l m : \u211d}\n  (h1 : is_limit a l) (h2 : is_limit b m) :\n  is_limit (a + b) (l + m) :=\nbegin\n  sorry,\nend\n\n\n-- Helpful things:\n-- `abs_pos : 0 < |a| \u2194 a \u2260 0`\n-- `div_pos : 0 < a \u2192 0 < b \u2192 0 < a / b`\n-- `abs_mul x y : |x * y| = |x| * |y|`\n-- `lt_div_iff' : 0 < c \u2192 (a < b / c \u2194 c * a < b)`\n-- I typically find these things myself with a combination of\n-- the \"guess the name of the lemma\" game (and ctrl-space).\n\n-- A hint for starting:\n-- It might be worth dealing with `c = 0` as a special case. You\n-- can start with \n-- `by_cases hc : c = 0`\n\ntheorem is_limit_mul_const_left {a : \u2115 \u2192 \u211d} {l c : \u211d} (h : is_limit a l) :\n  is_limit (\u03bb n, c * (a n)) (c * l) :=\nbegin\n  sorry,\nend\n\ntheorem sandwich (a b c : \u2115 \u2192 \u211d)\n  (l : \u211d) (ha : is_limit a l) (hc : is_limit c l) \n  (hab : \u2200 n, a n \u2264 b n) (hbc : \u2200 n, b n \u2264 c n) : is_limit b l :=\nbegin\n  sorry,\nend\n\n\nend vilnius", "meta": {"author": "faenuccio", "repo": "May22_Vilnius", "sha": "2ff937dc7568e6118473b1e7f479ccb2a5fa9767", "save_path": "github-repos/lean/faenuccio-May22_Vilnius", "path": "github-repos/lean/faenuccio-May22_Vilnius/May22_Vilnius-2ff937dc7568e6118473b1e7f479ccb2a5fa9767/src/C_Limits/Course.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7038339051371718}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.free_module.basic\nimport linear_algebra.matrix.to_lin\nimport ring_theory.finiteness\n\n/-!\n# Finite and free modules\n\nWe provide some instances for finite and free modules.\n\n## Main results\n\n* `module.free.choose_basis_index.fintype` : If a free module is finite, then any basis is\n  finite.\n* `module.free.linear_map.free ` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N` is free.\n* `module.finite.of_basis` : A free module with a basis indexed by a `fintype` is finite.\n* `module.free.linear_map.module.finite` : if `M` and `N` are finite and free, then `M \u2192\u2097[R] N`\n  is finite.\n-/\n\nuniverses u v w\n\nvariables (R : Type u) (M : Type v) (N : Type w)\n\nnamespace module.free\n\nsection ring\n\nvariables [ring R] [add_comm_group M] [module R M] [module.free R M]\n\n/-- If a free module is finite, then any basis is finite. -/\nnoncomputable\ninstance [nontrivial R] [module.finite R M] :\n  fintype (module.free.choose_basis_index R M) :=\nbegin\n  obtain \u27e8h\u27e9 := id \u2039module.finite R M\u203a,\n  choose s hs using h,\n  exact basis_fintype_of_finite_spans \u2191s hs (choose_basis _ _),\nend\n\nend ring\n\nsection comm_ring\n\nvariables [comm_ring R] [add_comm_group M] [module R M] [module.free R M]\nvariables [add_comm_group N] [module R N] [module.free R N]\n\ninstance linear_map [module.finite R M] [module.finite R N] : module.free R (M \u2192\u2097[R] N) :=\nbegin\n  casesI subsingleton_or_nontrivial R,\n  { apply module.free.of_subsingleton' },\n  classical,\n  exact of_equiv\n    (linear_map.to_matrix (module.free.choose_basis R M) (module.free.choose_basis R N)).symm,\nend\n\nvariables {R M}\n\n/-- A free module with a basis indexed by a `fintype` is finite. -/\nlemma _root_.module.finite.of_basis {R : Type*} {M : Type*} {\u03b9 : Type*} [comm_ring R]\n  [add_comm_group M] [module R M] [fintype \u03b9] (b : basis \u03b9 R M) : module.finite R M :=\nbegin\n  classical,\n  refine \u27e8\u27e8finset.univ.image b, _\u27e9\u27e9,\n  simp only [set.image_univ, finset.coe_univ, finset.coe_image, basis.span_eq],\nend\n\ninstance _root_.module.finite.matrix {\u03b9\u2081 : Type*} [fintype \u03b9\u2081] {\u03b9\u2082 : Type*} [fintype \u03b9\u2082] :\n  module.finite R (matrix \u03b9\u2081 \u03b9\u2082 R) :=\nmodule.finite.of_basis $ pi.basis $ \u03bb i, pi.basis_fun R _\n\nvariables (M)\n\ninstance _root_.module.finite.linear_map [module.finite R M] [module.finite R N] :\n  module.finite R (M \u2192\u2097[R] N) :=\nbegin\n  casesI subsingleton_or_nontrivial R,\n  { apply_instance },\n  classical,\n  have f := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)).symm,\n  exact module.finite.of_surjective f.to_linear_map (linear_equiv.surjective f),\nend\n\nend comm_ring\n\nsection integer\n\nvariables [add_comm_group M] [module.finite \u2124 M] [module.free \u2124 M]\nvariables [add_comm_group N] [module.finite \u2124 N] [module.free \u2124 N]\n\ninstance _root_.module.finite.add_monoid_hom : module.finite \u2124 (M \u2192+ N) :=\nmodule.finite.equiv (add_monoid_hom_lequiv_int \u2124).symm\n\ninstance add_monoid_hom : module.free \u2124 (M \u2192+ N) :=\nbegin\n  letI : module.free \u2124 (M \u2192\u2097[\u2124] N) := module.free.linear_map _ _ _,\n  exact module.free.of_equiv (add_monoid_hom_lequiv_int \u2124).symm\nend\n\nend integer\n\nend module.free\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/free_module/finite/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7038339006338296}}
{"text": "/-\nCopyright (c) 2021 Gabriel Moise. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gabriel Moise, Ya\u00ebl Dillies, Kyle Miller\n\n! This file was ported from Lean 3 source module combinatorics.simple_graph.inc_matrix\n! leanprover-community/mathlib commit bb168510ef455e9280a152e7f31673cabd3d7496\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Combinatorics.SimpleGraph.Basic\nimport Mathbin.Data.Matrix.Basic\n\n/-!\n# Incidence matrix of a simple graph\n\nThis file defines the unoriented incidence matrix of a simple graph.\n\n## Main definitions\n\n* `simple_graph.inc_matrix`: `G.inc_matrix R` is the incidence matrix of `G` over the ring `R`.\n\n## Main results\n\n* `simple_graph.inc_matrix_mul_transpose_diag`: The diagonal entries of the product of\n  `G.inc_matrix R` and its transpose are the degrees of the vertices.\n* `simple_graph.inc_matrix_mul_transpose`: Gives a complete description of the product of\n  `G.inc_matrix R` and its transpose; the diagonal is the degrees of each vertex, and the\n  off-diagonals are 1 or 0 depending on whether or not the vertices are adjacent.\n* `simple_graph.inc_matrix_transpose_mul_diag`: The diagonal entries of the product of the\n  transpose of `G.inc_matrix R` and `G.inc_matrix R` are `2` or `0` depending on whether or\n  not the unordered pair is an edge of `G`.\n\n## Implementation notes\n\nThe usual definition of an incidence matrix has one row per vertex and one column per edge.\nHowever, this definition has columns indexed by all of `sym2 \u03b1`, where `\u03b1` is the vertex type.\nThis appears not to change the theory, and for simple graphs it has the nice effect that every\nincidence matrix for each `simple_graph \u03b1` has the same type.\n\n## TODO\n\n* Define the oriented incidence matrices for oriented graphs.\n* Define the graph Laplacian of a simple graph using the oriented incidence matrix from an\n  arbitrary orientation of a simple graph.\n-/\n\n\nopen Finset Matrix SimpleGraph Sym2\n\nopen BigOperators Matrix\n\nnamespace SimpleGraph\n\nvariable (R : Type _) {\u03b1 : Type _} (G : SimpleGraph \u03b1)\n\n/-- `G.inc_matrix R` is the `\u03b1 \u00d7 sym2 \u03b1` matrix whose `(a, e)`-entry is `1` if `e` is incident to\n`a` and `0` otherwise. -/\nnoncomputable def incMatrix [Zero R] [One R] : Matrix \u03b1 (Sym2 \u03b1) R := fun a =>\n  (G.incidenceSet a).indicator 1\n#align simple_graph.inc_matrix SimpleGraph.incMatrix\n\nvariable {R}\n\ntheorem incMatrix_apply [Zero R] [One R] {a : \u03b1} {e : Sym2 \u03b1} :\n    G.incMatrix R a e = (G.incidenceSet a).indicator 1 e :=\n  rfl\n#align simple_graph.inc_matrix_apply SimpleGraph.incMatrix_apply\n\n/-- Entries of the incidence matrix can be computed given additional decidable instances. -/\ntheorem incMatrix_apply' [Zero R] [One R] [DecidableEq \u03b1] [DecidableRel G.Adj] {a : \u03b1}\n    {e : Sym2 \u03b1} : G.incMatrix R a e = if e \u2208 G.incidenceSet a then 1 else 0 := by convert rfl\n#align simple_graph.inc_matrix_apply' SimpleGraph.incMatrix_apply'\n\nsection MulZeroOneClass\n\nvariable [MulZeroOneClass R] {a b : \u03b1} {e : Sym2 \u03b1}\n\ntheorem incMatrix_apply_mul_incMatrix_apply :\n    G.incMatrix R a e * G.incMatrix R b e = (G.incidenceSet a \u2229 G.incidenceSet b).indicator 1 e :=\n  by\n  classical simp only [inc_matrix, Set.indicator_apply, \u2190 ite_and_mul_zero, Pi.one_apply, mul_one,\n      Set.mem_inter_iff]\n#align simple_graph.inc_matrix_apply_mul_inc_matrix_apply SimpleGraph.incMatrix_apply_mul_incMatrix_apply\n\ntheorem incMatrix_apply_mul_incMatrix_apply_of_not_adj (hab : a \u2260 b) (h : \u00acG.Adj a b) :\n    G.incMatrix R a e * G.incMatrix R b e = 0 :=\n  by\n  rw [inc_matrix_apply_mul_inc_matrix_apply, Set.indicator_of_not_mem]\n  rw [G.incidence_set_inter_incidence_set_of_not_adj h hab]\n  exact Set.not_mem_empty e\n#align simple_graph.inc_matrix_apply_mul_inc_matrix_apply_of_not_adj SimpleGraph.incMatrix_apply_mul_incMatrix_apply_of_not_adj\n\ntheorem incMatrix_of_not_mem_incidenceSet (h : e \u2209 G.incidenceSet a) : G.incMatrix R a e = 0 := by\n  rw [inc_matrix_apply, Set.indicator_of_not_mem h]\n#align simple_graph.inc_matrix_of_not_mem_incidence_set SimpleGraph.incMatrix_of_not_mem_incidenceSet\n\ntheorem incMatrix_of_mem_incidenceSet (h : e \u2208 G.incidenceSet a) : G.incMatrix R a e = 1 := by\n  rw [inc_matrix_apply, Set.indicator_of_mem h, Pi.one_apply]\n#align simple_graph.inc_matrix_of_mem_incidence_set SimpleGraph.incMatrix_of_mem_incidenceSet\n\nvariable [Nontrivial R]\n\ntheorem incMatrix_apply_eq_zero_iff : G.incMatrix R a e = 0 \u2194 e \u2209 G.incidenceSet a :=\n  by\n  simp only [inc_matrix_apply, Set.indicator_apply_eq_zero, Pi.one_apply, one_ne_zero]\n  exact Iff.rfl\n#align simple_graph.inc_matrix_apply_eq_zero_iff SimpleGraph.incMatrix_apply_eq_zero_iff\n\ntheorem incMatrix_apply_eq_one_iff : G.incMatrix R a e = 1 \u2194 e \u2208 G.incidenceSet a :=\n  by\n  convert one_ne_zero.ite_eq_left_iff\n  infer_instance\n#align simple_graph.inc_matrix_apply_eq_one_iff SimpleGraph.incMatrix_apply_eq_one_iff\n\nend MulZeroOneClass\n\nsection NonAssocSemiring\n\nvariable [Fintype \u03b1] [NonAssocSemiring R] {a b : \u03b1} {e : Sym2 \u03b1}\n\ntheorem sum_incMatrix_apply [DecidableEq \u03b1] [DecidableRel G.Adj] :\n    (\u2211 e, G.incMatrix R a e) = G.degree a := by\n  simp [inc_matrix_apply', sum_boole, Set.filter_mem_univ_eq_toFinset]\n#align simple_graph.sum_inc_matrix_apply SimpleGraph.sum_incMatrix_apply\n\ntheorem incMatrix_mul_transpose_diag [DecidableEq \u03b1] [DecidableRel G.Adj] :\n    (G.incMatrix R \u2b1d (G.incMatrix R)\u1d40) a a = G.degree a :=\n  by\n  rw [\u2190 sum_inc_matrix_apply]\n  simp [Matrix.mul_apply, inc_matrix_apply', \u2190 ite_and_mul_zero]\n#align simple_graph.inc_matrix_mul_transpose_diag SimpleGraph.incMatrix_mul_transpose_diag\n\ntheorem sum_incMatrix_apply_of_mem_edgeSetEmbedding :\n    e \u2208 G.edgeSetEmbedding \u2192 (\u2211 a, G.incMatrix R a e) = 2 := by\n  classical\n    refine' e.ind _\n    intro a b h\n    rw [mem_edge_set] at h\n    rw [\u2190 Nat.cast_two, \u2190 card_doubleton h.ne]\n    simp only [inc_matrix_apply', sum_boole, mk_mem_incidence_set_iff, h, true_and_iff]\n    congr 2\n    ext e\n    simp only [mem_filter, mem_univ, true_and_iff, mem_insert, mem_singleton]\n#align simple_graph.sum_inc_matrix_apply_of_mem_edge_set SimpleGraph.sum_incMatrix_apply_of_mem_edgeSetEmbedding\n\ntheorem sum_incMatrix_apply_of_not_mem_edgeSetEmbedding (h : e \u2209 G.edgeSetEmbedding) :\n    (\u2211 a, G.incMatrix R a e) = 0 :=\n  sum_eq_zero fun a _ => G.incMatrix_of_not_mem_incidenceSet fun he => h he.1\n#align simple_graph.sum_inc_matrix_apply_of_not_mem_edge_set SimpleGraph.sum_incMatrix_apply_of_not_mem_edgeSetEmbedding\n\ntheorem incMatrix_transpose_mul_diag [DecidableRel G.Adj] :\n    ((G.incMatrix R)\u1d40 \u2b1d G.incMatrix R) e e = if e \u2208 G.edgeSetEmbedding then 2 else 0 := by\n  classical\n    simp only [Matrix.mul_apply, inc_matrix_apply', transpose_apply, \u2190 ite_and_mul_zero, one_mul,\n      sum_boole, and_self_iff]\n    split_ifs with h\n    \u00b7 revert h\n      refine' e.ind _\n      intro v w h\n      rw [\u2190 Nat.cast_two, \u2190 card_doubleton (G.ne_of_adj h)]\n      simp [mk_mem_incidence_set_iff, G.mem_edge_set.mp h]\n      congr 2\n      ext u\n      simp\n    \u00b7 revert h\n      refine' e.ind _\n      intro v w h\n      simp [mk_mem_incidence_set_iff, G.mem_edge_set.not.mp h]\n#align simple_graph.inc_matrix_transpose_mul_diag SimpleGraph.incMatrix_transpose_mul_diag\n\nend NonAssocSemiring\n\nsection Semiring\n\nvariable [Fintype (Sym2 \u03b1)] [Semiring R] {a b : \u03b1} {e : Sym2 \u03b1}\n\ntheorem incMatrix_mul_transpose_apply_of_adj (h : G.Adj a b) :\n    (G.incMatrix R \u2b1d (G.incMatrix R)\u1d40) a b = (1 : R) := by\n  classical\n    simp_rw [Matrix.mul_apply, Matrix.transpose_apply, inc_matrix_apply_mul_inc_matrix_apply,\n      Set.indicator_apply, Pi.one_apply, sum_boole]\n    convert Nat.cast_one\n    convert card_singleton \u27e6(a, b)\u27e7\n    rw [\u2190 coe_eq_singleton, coe_filter_univ]\n    exact G.incidence_set_inter_incidence_set_of_adj h\n#align simple_graph.inc_matrix_mul_transpose_apply_of_adj SimpleGraph.incMatrix_mul_transpose_apply_of_adj\n\ntheorem incMatrix_mul_transpose [Fintype \u03b1] [DecidableEq \u03b1] [DecidableRel G.Adj] :\n    G.incMatrix R \u2b1d (G.incMatrix R)\u1d40 = fun a b =>\n      if a = b then G.degree a else if G.Adj a b then 1 else 0 :=\n  by\n  ext (a b)\n  split_ifs with h h'\n  \u00b7 subst b\n    convert G.inc_matrix_mul_transpose_diag\n  \u00b7 exact G.inc_matrix_mul_transpose_apply_of_adj h'\n  \u00b7\n    simp only [Matrix.mul_apply, Matrix.transpose_apply,\n      G.inc_matrix_apply_mul_inc_matrix_apply_of_not_adj h h', sum_const_zero]\n#align simple_graph.inc_matrix_mul_transpose SimpleGraph.incMatrix_mul_transpose\n\nend Semiring\n\nend SimpleGraph\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/SimpleGraph/IncMatrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7038339006338296}}
{"text": "\nimport tactic \nimport .num_lemmas .set .single finsum.fin_api  .induction \n\nopen_locale classical big_operators \nnoncomputable theory \n\nuniverses u v w \n\n/-!\nThis file contains an API for `size`, which is the noncomputable function assigning each finite\nset to its size as an integer, and each infinite set to zero. Also `type_size` is defined similarly \nfor types. Most lemmas are only true in a finite setting, and have two versions, one with explicit\nfiniteness assumptions, and one in which they are derived from a `fintype` instance . Lemmas of the \nformer type are usually less useful for us, and go in the `finite` namespace. \n-/\n\nsection defs \n\n/-- The size of a set, as an integer. Zero if the set is infinite -/\ndef size {\u03b1 : Type*} (s : set \u03b1) : \u2124 := (fincard s)\n\n/-- The size of a type, as an integer. Zero if the type is infinite -/\ndef type_size (\u03b1 : Type* ) : \u2124 := size (set.univ : set \u03b1)\n\nend defs \n\n/-! Basic lemmas about size.  -/\n\nsection basic \n\nvariables {\u03b1 : Type*} {s t : set \u03b1} {e f : \u03b1}\n\nlemma size_def (s : set \u03b1) : \n  size s = fincard s := \nrfl \n\nlemma type_size_eq (\u03b1 : Type*) : type_size \u03b1 = size (set.univ : set \u03b1) := rfl \n\nlemma type_size_eq_fincard_t (\u03b1 : Type*) : type_size \u03b1 = fincard_t \u03b1 := \nby {rw [type_size, size_def], norm_num, refl,  }\n\nlemma type_size_coe_set_eq_size (s : set \u03b1) :\n  type_size s = size s := \nby rw [type_size_eq_fincard_t, size, fincard_t_subtype_eq_fincard]\n\nlemma type_size_type_of_eq_size_set_of (P : \u03b1 \u2192 Prop): \n  type_size {x // P x} = size {x | P x} :=\ntype_size_coe_set_eq_size P\n\n@[simp] lemma size_empty (\u03b1 : Type*) : size (\u2205 : set \u03b1) = 0 := \nby simp [size]\n\n@[simp] lemma size_singleton (e : \u03b1) : size ({e} : set \u03b1) = 1 := \nby simp [size]\n\nlemma size_nonneg (s : set \u03b1) : 0 \u2264 size s := \nby {simp only [size], norm_cast, apply zero_le}  \n\nlemma type_size_nonneg (\u03b1 : Type*) : 0 \u2264 type_size \u03b1 := \nsize_nonneg _\n\nlemma size_zero_of_infinite (hs : s.infinite) : \n  size s = 0 := \nby rw [size, fincard_of_infinite hs, int.coe_nat_zero]\n\nlemma finite_of_size_pos (hs : 0 < size s) : \n  s.finite := \nby {rw size at hs, norm_num at hs, exact finite_of_fincard_pos hs, }\n\n/-- a positive type size gives rise to a fintype -/\ndef fintype_of_type_size_pos {\u03b1 : Type*} (h\u03b1 : 0 < type_size \u03b1) : \n  fintype \u03b1 := \nset.fintype_of_univ_finite (by {rw [type_size_eq] at h\u03b1, exact finite_of_size_pos h\u03b1,})\n\nlemma nonempty_of_size_pos (hs : 0 < size s) :\n  s.nonempty := \nby {rw \u2190 set.ne_empty_iff_nonempty, rintro rfl, linarith [size_empty \u03b1], }\n\nlemma nonempty_of_type_size_pos (h\u03b1 : 0 < type_size \u03b1): \n  nonempty \u03b1 := \nby {rw set.nonempty_iff_univ_nonempty, rw type_size_eq at h\u03b1, exact nonempty_of_size_pos h\u03b1, }\n\nlemma contains_singleton {s : set \u03b1} : s.nonempty \u2192 (\u2203 t, t \u2286 s \u2227 size t = 1) :=\n\u03bb \u27e8e,he\u27e9, \u27e8{e},\u27e8set.singleton_subset_iff.mpr he, size_singleton e\u27e9\u27e9\n\nlemma exists_mem_of_size_pos (h : 0 < size s) : \n  \u2203 e, e \u2208 s := \n(ne_empty_iff_has_mem.mp (\u03bb hs, lt_irrefl _ (by {rwa [hs, size_empty] at h})))\n\n@[simp] lemma finsum_ones_eq_size (s : set \u03b1) : \n  \u2211\u1da0 x in s, (1 : \u2124) = size s := \nby {rw [size, fincard, nat.coe_int_distrib_finsum_in], refl}\n\n@[simp] lemma finsum_ones_eq_type_size (\u03b1 : Type*) : \n  \u2211\u1da0 (x : \u03b1), (1 : \u2124) = type_size \u03b1 := \nby {rw [finsum_eq_finsum_in_univ, finsum_ones_eq_size], refl}\n\nlemma size_set_of_eq_size_subtype (P : \u03b1 \u2192 Prop):\n  size {x | P x} = type_size {x // P x} :=\nby rw [\u2190 finsum_ones_eq_size, \u2190 finsum_ones_eq_type_size, \u2190 finsum_subtype_eq_finsum_in_set_of]\n\nlemma size_set_of_push (P Q : \u03b1 \u2192 Prop) :\n  size {x : {y // P y} | Q (x : \u03b1)} = size { x | P x \u2227 Q x } := \nby {rw [\u2190 finsum_ones_eq_size, \u2190 finsum_ones_eq_size], \n    convert finsum_set_subtype_eq_finsum_set (1 : \u03b1 \u2192 \u2124) P Q,  }\n\n\nend basic \n\n/-! The lemmas in this section are true without any finiteness assumptions -/\nsection general \n\nvariables {\u03b1 : Type*} {s t : set \u03b1} {e f : \u03b1}\n\nlemma size_one_iff_eq_singleton :\n  size s = 1 \u2194 \u2203 e, s = {e} := \nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9, swap,  \n    cases h with e he, rw he, apply size_singleton, \n  \n  have hs := finite_of_size_pos (by linarith : 0 < size s), \n  obtain \u27e8e,he\u27e9 := exists_mem_of_size_pos (by linarith : 0 < size s), \n  use e, \n  ext, \n  simp only [set.mem_singleton_iff],\n  refine \u27e8\u03bb h', _, \u03bb h', by {rwa \u2190 h' at he}\u27e9, \n  rw \u2190 finsum_ones_eq_size at h,\n  have hs' := finsum_in_subset_le_finsum_in_of_nonneg hs \n    (_ : {e,x} \u2286 s) (\u03bb x hx, (by norm_num: (0 : \u2124 ) \u2264 1)), \n  { by_contra hxe, \n    rw [finsum_pair (ne.symm hxe), h, add_le_iff_nonpos_right] at hs',\n    norm_num at hs'}, \n  rw \u2190 set.singleton_subset_iff at he h', \n  convert set.union_subset he h', \nend\n\nlemma eq_of_mems_size_one (hs : size s = 1) (he : e \u2208 s) (hf : f \u2208 s):\n  e = f := \nbegin\n  obtain \u27e8x, rfl\u27e9 := size_one_iff_eq_singleton.mp hs, \n  rw set.mem_singleton_iff at he hf, \n  rw [he,hf], \nend\n\nlemma size_pair (hef : e \u2260 f) : \n  size ({e,f} : set \u03b1) = 2 :=\nby {rw [\u2190 finsum_ones_eq_size, finsum_pair hef], refl}\n\n\nend general \n\n/-! Lemmas about the relationship between size and finsumming ones -/\n\nsection sums \n\nvariables {\u03b1 : Type*}\n\n@[simp] lemma int.finsum_const_eq_mul_type_size (\u03b1 : Type*) (b : \u2124) :\n  \u2211\u1da0 (x : \u03b1), b = b * type_size \u03b1 := \nby rw [\u2190 mul_one b, \u2190 finsum_ones_eq_type_size, \u2190 mul_distrib_finsum, mul_one]\n\n@[simp] lemma int.finsum_in_const_eq_mul_size (s : set \u03b1) (b : \u2124) :\n  \u2211\u1da0 x in s, b = b * size s := \nby rw [\u2190 mul_one b, \u2190 finsum_ones_eq_size, \u2190 mul_distrib_finsum_in, mul_one]\n\nlemma finite.sum_size_fiber_eq_size {\u03b9 : Type*} {s : set \u03b1} (hs : s.finite) (f : \u03b1 \u2192 \u03b9) :\n  \u2211\u1da0 (i : \u03b9), size {a \u2208 s | f a = i} = size s := \nby simp_rw [size_def, \u2190 nat.coe_int_distrib_finsum, sum_fincard_fiber_eq_fincard f hs]\n\nlemma size_set_subtype_eq_size_set (P Q : \u03b1 \u2192 Prop) :\n  size {x : {y // P y} | Q (coe x)} = size { x | P x \u2227 Q x } := \nby {simp_rw \u2190 finsum_ones_eq_size, apply finsum_set_subtype_eq_finsum_set (1 : \u03b1 \u2192 \u2124)} \n\nend sums \n\n/-! \nThis section contains lemmas that require finiteness of sets to be true. These versions \nall have explicit set.finite assumptions; the versions that use an instance are later. \n-/\n\nsection finite\n\nvariables {\u03b1 : Type*} {s t : set \u03b1} {e f : \u03b1}\n\nopen set \n\nnamespace set.finite\n\nlemma size_modular (s t : set \u03b1) (hs : s.finite) (ht : t.finite) : \n  size (s \u222a t) + size (s \u2229 t) = size s + size t :=\nby {simp_rw size, norm_cast, apply fincard_modular; assumption} \n\nlemma size_union (s t : set \u03b1) (hs : s.finite) (ht : t.finite) : \n  size (s \u222a t) = size s + size t - size (s \u2229 t) := \nby linarith [size_modular s t hs ht]\n\nlemma size_monotone (ht : t.finite) (hst : s \u2286 t) : size s \u2264 size t := \nbegin\n  have hs := subset ht hst, \n  have := size_modular s (t \\ s) hs (ht.diff s), \n  rw [union_diff_of_subset hst, inter_diff] at this, \n  linarith [size_nonneg (t \\ s), size_empty \u03b1],\nend \n\nlemma ssubset_size (hs : s.finite) (ht : t.finite) (hst : s \u2286 t) (hst' : size s < size t) :\n  s \u2282 t := \nby {rw set.ssubset_iff_subset_ne, from \u27e8hst, \u03bb hn, by {rw hn at hst', exact lt_irrefl _ hst'}\u27e9}\n\nlemma size_subadditive (hs : s.finite) (ht : t.finite) : size (s \u222a t) \u2264 size s + size t :=\n  by linarith [size_modular s t hs ht, size_nonneg (s \u2229 t)] \n\nlemma compl_inter_size (s t : set \u03b1) (ht : t.finite) : \n  size (s \u2229 t) + size (s\u1d9c \u2229 t) = size t := \nby {rw [\u2190size_modular, \u2190inter_distrib_right, union_compl_self, univ_inter, \n  \u2190inter_distrib_inter_left, inter_compl_self, empty_inter, size_empty, add_zero];\n  exact inter_right (by assumption) _, }\n\nlemma compl_inter_size_subset (ht : t.finite) (hst : s \u2286 t) : \n  size (s\u1d9c \u2229 t) = size t - size s := \nby {have := compl_inter_size s t ht, rw subset_iff_inter_eq_left.mp hst at this, linarith} \n\nlemma diff_size (ht : t.finite) (hst : s \u2286 t) : size (t \\ s) = size t - size s :=  \nby rw [diff_eq, inter_comm, compl_inter_size_subset ht hst]\n\nlemma size_diff_le_size (s t : set \u03b1) (hs : s.finite) : size (s \\ t) \u2264 size s := \n  size_monotone hs (diff_subset _ _) \n-- the above lemma is also true if just `s \u2229 t` is finite \n\nlemma size_union_of_inter_empty (hs : s.finite) (ht : t.finite) (hst : s \u2229 t = \u2205) :\n  size (s \u222a t) = size s + size t := \nby {have := size_modular s t hs ht, rw [hst, size_empty] at this, linarith}\n\nlemma size_union_of_disjoint (hs : s.finite) (ht : t.finite) (hst : disjoint s t) :\n  size (s \u222a t) = size s + size t := \nsize_union_of_inter_empty hs ht (disjoint_iff_inter_eq_empty.mp hst)\n\nlemma size_modular_diff (s t : set \u03b1) (hs : s.finite) (ht : t.finite) : \n  size (s \u222a t) = size (s \\ t) + size (t \\ s) + size (s \u2229 t) :=\nbegin\n  rw [\u2190size_union_of_inter_empty _ _ (inter_diffs_eq_empty s t)],\n  { have := (symm_diff_alt s t), \n    unfold symm_diff at this,\n    rw this, \n    linarith [diff_size (union hs ht) (inter_subset_union s t)]}, \n  repeat {apply diff, assumption}, \nend\n\nlemma size_induced_partition (s t : set \u03b1) (hs : s.finite)  :\n  size s = size (s \u2229 t) + size (s \\ t) := \nbegin\n  nth_rewrite 0 \u2190diff_union s t, \n  refine size_union_of_inter_empty (inter_left hs _) (diff hs _) (partition_inter _ _), \nend \n\nlemma size_induced_partition_inter (s t : set \u03b1) (hs : s.finite) :\n  size s = size (s \u2229 t) + size (s \u2229 t\u1d9c) := \nby {rw \u2190diff_eq, apply size_induced_partition _ _ hs, }\n\nlemma size_mono_inter_left (s t : set \u03b1) (hs : s.finite) : size (s \u2229 t) \u2264 size s := \nsize_monotone hs (inter_subset_left _ _)\n\nlemma size_mono_inter_right (s t : set \u03b1) (ht : t.finite) : size (s \u2229 t) \u2264 size t := \nsize_monotone ht (inter_subset_right _ _)\n\nlemma size_mono_union_left (s t : set \u03b1) (ht : t.finite) : size s \u2264 size (s \u222a t)  := \nbegin\n  by_cases hs : s.finite, \n  apply size_monotone (union hs ht) (subset_union_left _ _), \n  rw [size_zero_of_infinite hs, size_zero_of_infinite], \n  exact infinite_mono (subset_union_left _ _) hs, \nend \n\nlemma size_mono_union_right (s t : set \u03b1) (hs : s.finite) : size t \u2264 size (s \u222a t) := \nby {rw union_comm, apply size_mono_union_left _ _ hs}\n\nlemma empty_of_size_zero (hs : s.finite) (hsize : size s = 0) : s = \u2205 := \nbegin\n  rw eq_empty_iff_forall_not_mem, intros x hx, \n  have h' := size_monotone hs (singleton_subset_iff.mpr hx), \n  rw [hsize, size_singleton] at h', \n  linarith, \nend  \n\nlemma size_zero_iff_empty (hs : s.finite) : (size s = 0) \u2194 (s = \u2205) := \n  by {split, apply empty_of_size_zero hs, intros h, rw h, exact size_empty \u03b1}\n\nlemma size_le_zero_iff_eq_empty (hs : s.finite) :\n  size s \u2264 0 \u2194 s = \u2205 := \nby {rw [\u2190 size_zero_iff_empty hs], exact \u27e8\u03bb h, le_antisymm h (size_nonneg _), \u03bb h, le_of_eq h\u27e9} \n\nlemma size_nonempty (hs : s.finite) (hne : s.nonempty) : 0 < size s  := \nbegin\n  suffices h' : 0 \u2260 size s, exact lt_of_le_of_ne (size_nonneg _) h', \n  rw [\u2190set.ne_empty_iff_nonempty] at hne,  \n  exact \u03bb h, hne (empty_of_size_zero hs h.symm), \nend\n\nlemma nonempty_iff_size_pos (hs : s.finite) : s.nonempty \u2194 0 < size s := \nbegin\n  refine \u27e8\u03bb h, size_nonempty hs h, \u03bb h, _\u27e9,\n  rw \u2190set.ne_empty_iff_nonempty, \n  exact \u03bb h', by {rw [h', size_empty] at h, from lt_irrefl 0 h}, \nend\n\nlemma one_le_size_iff_nonempty (hs : s.finite) : s.nonempty \u2194 1 \u2264 size s := \n  nonempty_iff_size_pos hs \n\n\nlemma one_le_size_of_nonempty (hs : s.nonempty) (hs' : s.finite) : 1 \u2264 size s := \n  (one_le_size_iff_nonempty hs').mp hs \n\nlemma size_strict_monotone (ht : t.finite) (hst : s \u2282 t) : size s < size t := \nbegin\n  rw [size_induced_partition t s ht, inter_comm, subset_iff_inter_eq_left.mp hst.1], \n  linarith [size_nonempty (diff ht _) (ssubset_diff_nonempty hst)], \nend \n\nlemma eq_of_eq_size_subset (ht : t.finite) (hst : s \u2286 t) (hsize : size s = size t) :\n  s = t :=\nbegin\n  unfreezingI {rcases subset_ssubset_or_eq hst with (hst' | rfl)},\n    swap, refl, \n  have := size_strict_monotone ht hst', rw hsize at this, \n  exact false.elim (lt_irrefl _ this),\nend \n\nlemma eq_of_eq_size_subset_iff (ht : t.finite) (hst : s \u2286 t) : \n  ((size s = size t) \u2194 s = t) :=\n\u27e8\u03bb h, eq_of_eq_size_subset ht hst h, \u03bb h, by {rw h}\u27e9\n\nlemma eq_of_le_size_subset (ht : t.finite) (hst : s \u2286 t) (hsize : size t \u2264 size s) : \n  s = t :=\nby {apply eq_of_eq_size_subset ht hst, exact le_antisymm (size_monotone ht hst) hsize}\n\nlemma size_eq_of_supset (ht : t.finite) (hst : s \u2286 t) (hsize : size t \u2264 size s) :\n  size s = size t := \nby linarith [size_monotone ht hst]\n\nlemma size_pos_iff_has_mem (hs : s.finite) : \n  0 < size s \u2194 \u2203 e, e \u2208 s := \nby rw [\u2190 nonempty_iff_size_pos hs, set.nonempty_def] \n\nlemma one_le_size_iff_has_mem (hs : s.finite) : \n  1 \u2264 size s \u2194 \u2203 e, e \u2208 s := \nby {convert size_pos_iff_has_mem hs}\n\nlemma size_zero_iff_has_no_mem (hs : s.finite) :\n  size s = 0 \u2194 \u00ac \u2203 e, e \u2208 s := \nbegin\n  rw [iff.comm, \u2190not_iff, \u2190(size_pos_iff_has_mem hs), not_iff], \n  refine \u27e8\u03bb h, _, \u03bb h, by linarith \u27e9 ,\n  linarith [size_nonneg s, not_lt.mp h], \nend\n\nlemma size_le_zero_iff_has_no_mem (hs : s.finite) :\n  size s \u2264 0 \u2194 \u00ac \u2203 e, e \u2208 s := \nby {rw \u2190(size_zero_iff_has_no_mem hs), split, { intro, linarith [size_nonneg s]}, intro h, rw h}\n\nlemma mem_diff_of_size_lt (hs : s.finite) (hst : size s < size t) :\n  \u2203 (e : \u03b1), e \u2208 t \u2227 e \u2209 s :=\nbegin  \n  suffices h' : 0 < size (t \\ s), \n    obtain \u27e8e, he\u27e9 := exists_mem_of_size_pos h', tauto, \n  have ht := finite_of_size_pos (lt_of_le_of_lt (size_nonneg _) hst), \n  linarith [size_induced_partition t s ht, size_mono_inter_right t s hs], \nend \n\nlemma size_union_singleton_compl (hs : s.finite) (hes : e \u2208 s\u1d9c) :\n  size (s \u222a {e}) = size s + 1 := \nbegin\n  have := size_modular s {e} hs (finite_singleton e), \n  rwa [inter_comm s, nonmem_disjoint (by rwa \u2190mem_compl_iff), size_singleton, \n  size_empty, add_zero] at this, \nend\n\nlemma size_union_nonmem_singleton (hs : s.finite) (he : e \u2209 s) : \n  size (s \u222a {e}) = size s + 1 := \nby {apply size_union_singleton_compl hs, rwa \u2190mem_compl_iff at he, }\n\nlemma size_insert_nonmem (hs : s.finite) (he : e \u2209 s) : \n  size (has_insert.insert e s) = size s + 1 := \nby {convert size_union_nonmem_singleton hs he, rw union_singleton}\n\nlemma size_remove_mem (hs : s.finite) (he : e \u2208 s) :\n  size (s \\ {e}) = size s - 1 := \nbegin\n  have h' : has_insert.insert e (s \\ {e}) = s, \n  { ext, simp, rintro rfl, assumption},\n  nth_rewrite 1 \u2190 h', \n  rw [size_insert_nonmem], \n    ring, \n  apply diff hs _, \n  simp,  \nend\n\nlemma has_sub_one_size_ssubset_of_ne_empty (hs : s.finite) (hne : s \u2260 \u2205) :\n  \u2203 t, t \u2282 s \u2227 size t = size s - 1 := \nby {cases ne_empty_has_mem hne with e he, \nexact \u27e8s \\ {e}, \u27e8ssubset_of_remove_mem he, size_remove_mem hs he\u27e9 \u27e9}\n\nlemma has_sub_one_size_ssubset_of_nonempty (hs : s.finite) (hne : s.nonempty) :\n  \u2203 t, t \u2282 s \u2227 size t = size s - 1 := \nhas_sub_one_size_ssubset_of_ne_empty hs (ne_empty_iff_nonempty.mpr hne)\n\nlemma ne_univ_has_add_one_size_ssupset (hs : s.finite) (hne : s \u2260 univ) :\n  \u2203 t, s \u2282 t \u2227 size t = size s + 1 := \nlet \u27e8e,he\u27e9 := ne_univ_iff_has_nonmem.mp hne in \n  \u27e8has_insert.insert e s, ssubset_insert he, size_insert_nonmem hs he\u27e9\n\nlemma ne_univ_has_add_one_size_ssupset_element (hs : s.finite) (hne : s \u2260 univ) :\n  \u2203 e, s \u2282 s \u222a {e} \u2227 size (s \u222a {e}) = size s + 1 := \nlet \u27e8e,he\u27e9 := ne_univ_iff_has_nonmem.mp hne in \n   \u27e8e, by {rw union_singleton, exact ssubset_insert he}, size_union_nonmem_singleton hs he\u27e9 \n\nlemma eq_or_exists_mem_diff_of_size_eq (ht : t.finite) (hst : size s = size t) :\n  s = t \u2228 \u2203 e, e \u2208 s \\ t :=\nbegin\n  by_contra h, rw not_or_distrib at h, cases h with h1 h2, \n  rw \u2190ne_empty_iff_has_mem at h2, push_neg at h2,  \n  rw diff_empty_iff_subset at h2, \n  refine h1 (eq_of_eq_size_subset ht h2 hst),\nend\n\nlemma size_le_one_iff_empty_or_singleton (hs : s.finite) :\n  size s \u2264 1 \u2194 s = \u2205 \u2228 \u2203 e, s = {e} :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9, swap, \n  { unfreezingI {rcases h with (rfl | \u27e8e, rfl\u27e9)}; \n  simp only [size_singleton, size_empty], norm_num,},\n  by_cases h' : size s \u2264 0, \n  { left, rw \u2190size_zero_iff_empty hs, linarith [size_nonneg s],},\n  right, rw \u2190size_one_iff_eq_singleton, \n  exact le_antisymm h (by linarith), \nend \n\nlemma two_le_size_iff_has_distinct (hs : s.finite) :\n  2 \u2264 size s \u2194 \u2203 e f \u2208 s, e \u2260 f :=\nbegin\n  split, \n  { intro h, \n    obtain \u27e8e,he\u27e9 := @exists_mem_of_size_pos _ s (by linarith),\n    obtain \u27e8f,hf\u27e9 := @exists_mem_of_size_pos _ (s \\ {e}) (by linarith [size_remove_mem hs he]), \n    refine \u27e8e,f,he,mem_of_mem_of_subset hf (diff_subset _ _), _\u27e9, \n    rintro rfl, simpa using hf,},\n  rintro \u27e8e,f,he,hf,hef\u27e9, \n  rw \u2190 size_pair hef, \n  apply size_monotone hs (pair_subset_iff.mpr \u27e8he, hf\u27e9), \nend\n\nlemma size_le_one_iff_mem_unique (hs : s.finite) : \n  size s \u2264 1 \u2194 \u2200 e f \u2208 s, e = f := \nbegin\n  split, \n  { rw [size_le_one_iff_empty_or_singleton hs], \n    unfreezingI {rintros (rfl | \u27e8e,rfl\u27e9)},\n      simp [mem_singleton_iff], \n    simp only [mem_singleton_iff], \n    unfreezingI {rintros e f rfl rfl}, \n    refl,},\n  refine \u03bb h, by_contra (\u03bb hn, _), \n  rw [not_le] at hn, replace hn := int.add_one_le_of_lt hn, norm_num at hn,\n  rw two_le_size_iff_has_distinct hs at hn, \n  obtain \u27e8e,f,he,hf,hef\u27e9 := hn, \n  exact hef (h e f he hf),   \nend\n\nvariables {k : set (set \u03b1)}\n\nlemma size_sUnion (hk : k.finite) (hk' : \u2200 s \u2208 k, set.finite s) (hdisj : pairwise_disjoint k) : \n  size (\u22c3\u2080 k) = \u2211\u1da0 s in k, size s := \nby {convert finsum_in_sUnion' (1 : \u03b1 \u2192 \u2124) hk hk' hdisj; {simp_rw \u2190 finsum_ones_eq_size, refl}}\n\nlemma size_collection_le_size_union (hk : \u2200 s \u2208 k, set.finite s) \n(hk' : \u2200 s \u2208 k, set.nonempty s) (hdisj : pairwise_disjoint k): \n  (size k \u2264 size (\u22c3\u2080 k)) := \nbegin\n  by_cases hk'' : k.finite, swap,\n  { convert size_nonneg _, rw size_zero_of_infinite hk''},\n  rw [size_sUnion hk'' hk hdisj, \u2190 finsum_ones_eq_size], \n  refine finsum_in_le_finsum_in hk'' (\u03bb x hx, _),  \n  rw \u2190 (one_le_size_iff_nonempty (hk x hx)), \n  exact hk' x hx, \nend\n\nlemma singletons_of_size_collection_eq_size_union (hk : k.finite) (hk' : \u2200 s \u2208 k, set.finite s)\n(hk'' : \u2200 s \u2208 k, set.nonempty s) (hdisj : pairwise_disjoint k) (hsize : size k = size (\u22c3\u2080 k)): \n  \u2200 s \u2208 k, size s = 1 :=\nbegin\n  rw [size_sUnion hk hk' hdisj, \u2190 finsum_ones_eq_size] at hsize,\n  conv in (_ = _) {rw eq_comm}, \n  convert (finsum_in_eq_finsum_in_iff_of_le hk (\u03bb x hx, _)).mp hsize, \n  apply one_le_size_of_nonempty (hk'' _ hx) (hk' _ hx), \nend\n\nlemma size_collection_eq_size_union_iff (hk : k.finite) (hk' : \u2200 s \u2208 k, set.finite s)\n(hk'' : \u2200 s \u2208 k, set.nonempty s) (hdisj : pairwise_disjoint k) :\n  size k = size (\u22c3\u2080 k) \u2194 \u2200 s \u2208 k, size s = 1 :=\nbegin\n  refine \u27e8\u03bb h, singletons_of_size_collection_eq_size_union hk hk' hk'' hdisj h, \u03bb h, _\u27e9, \n  rw [size_sUnion hk hk' hdisj, \u2190 finsum_ones_eq_size, eq_comm], \n  exact finsum_in_eq_of_eq h, \nend\n\n\n\nend set.finite \n\nend finite \n\n/-! Lemmas that don't need any finiteness assumptions. Some are proved by splitting into\nfinite and infinite cases, which is why these lemmas need to appear after the previous \nsection.  -/\nsection general\n\nvariables {\u03b1 : Type*} {s t : set \u03b1} {e f : \u03b1}\n\nopen set \n\nlemma compl_nonempty_of_size_lt_type_size (hs : size s < type_size \u03b1):  \n  s\u1d9c.nonempty :=\nbegin\n  rw type_size_eq at hs,\n  refine nonempty_compl.mpr (\u03bb h, lt_irrefl (size s) (by {rwa \u2190 h at hs})), \nend\n\nlemma size_union_singleton_ub :\n  size (s \u222a {e}) \u2264 size s + 1 := \nbegin\n  by_cases hs : s.finite, \n    linarith [size_nonneg (s \u2229 {e}), \n      finite.size_modular s {e} hs (finite_singleton e), \n      size_singleton e], \n  rw [size_zero_of_infinite (infinite_mono (subset_union_left s {e}) hs)], \n  linarith [size_nonneg s], \nend \n\nlemma size_insert_ub : \n  size (insert e s) \u2264 size s + 1 := \nby {rw \u2190 union_singleton, apply size_union_singleton_ub, }\n\nlemma single_subset' (hs : s.nonempty) : \n  (\u2203 t t', t \u2229 t' = \u2205 \u2227 t \u222a t' = s \u2227 size t = 1) := \nbegin\n  obtain \u27e8t,ht\u27e9 := contains_singleton hs,\n  refine \u27e8t, s \\ t, set.inter_diff _ _,  _, ht.2\u27e9, \n  rw [set.union_diff_self, set.subset_iff_union_eq_left.mp ht.1], \nend\n\nlemma single_subset (hs : s.nonempty) : \n  (\u2203 t t', disjoint t t' \u2227 t \u222a t' = s \u2227 size t = 1) := \nby {simp_rw set.disjoint_iff_inter_eq_empty, exact single_subset' hs}\n\nlemma size_remove_union_singleton (he : e \u2208 s) (hf : f \u2209 s) : \n  size ((s \\ {e}) \u222a {f}) = size s := \nbegin\n  by_cases hs : s.finite, \n  { have h1 := hs.size_remove_mem he, \n    have h2 := finite.size_union_nonmem_singleton \n      (hs.diff _) \n      (nonmem_diff_of_nonmem {e} hf), \n    linarith},\n  rw [size_zero_of_infinite hs, size_zero_of_infinite _], \n  apply infinite_of_union, \n  exact infinite_of_finite_diff (finite_singleton e) hs, \nend\n\nlemma size_union_singleton_remove (he : e \u2208 s) (hf : f \u2209 s) : \n  size ((s \u222a {f}) \\ {e}) = size s :=\nbegin\n  convert size_remove_union_singleton he hf, \n  rw [union_diff_distrib], \n  convert rfl,\n  rw remove_nonmem, \n  simp only [mem_singleton_iff], \n  rintro rfl, \n  exact hf he, \nend  \n\nlemma exchange_pair_sizes (hst : size s = size t) (he : e \u2208 s \\ t) (hf : f \u2208 t \\ s) : \n  size (s \\ {e} \u222a {f}) = size (t \\ {f} \u222a {e}) :=\nbegin\n  rw mem_diff_iff at he hf, \n  rwa [size_remove_union_singleton hf.1 he.2, size_remove_union_singleton he.1 hf.2],\nend \n\nlemma eq_of_pair_size_one (h : size ({e,f} : set \u03b1) = 1) : \n  e = f :=\nby_contra (\u03bb hn, by {rw size_pair hn at h, norm_num at h})\n\nlemma size_eq_one_iff_nonempty_unique_mem : \n  size s = 1 \u2194 s.nonempty \u2227 \u2200 x y \u2208 s, x = y := \nbegin\n  rw size_one_iff_eq_singleton, \n  split, { rintros \u27e8e,rfl\u27e9, tidy, }, rintros \u27e8\u27e8e,he\u27e9, h\u27e9, use e, tidy, \nend\n\nlemma size_eq_two_iff_pair {s : set \u03b1} :\n  size s = 2 \u2194 \u2203 (e f : \u03b1), e \u2260 f \u2227 s = {e,f} :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9, swap, \n  { rcases h with \u27e8e,f,hef,rfl\u27e9, apply size_pair hef},\n  by_cases hs : s.finite, \n  { obtain \u27e8e,he\u27e9 := exists_mem_of_size_pos (by {rw h, norm_num} : 0 < size s),\n    obtain \u27e8f,hf\u27e9 := exists_mem_of_size_pos \n      (by {rw [finite.size_remove_mem hs he,h], norm_num } : 0 < size (s \\ {e})),\n    refine \u27e8e,f,ne.symm (ne_of_mem_diff hf), _\u27e9,  \n    rw eq_comm, apply finite.eq_of_eq_size_subset hs, \n    { rw \u2190union_singletons_eq_pair, \n      apply union_subset (singleton_subset_iff.mpr he),  \n      simp only [set.mem_diff, set.mem_singleton_iff] at hf, \n      exact singleton_subset_iff.mpr hf.1, },\n    rwa [eq_comm, size_pair  (ne.symm (ne_of_mem_diff hf))]}, \n  rw size_zero_of_infinite hs at h, \n  norm_num at h, \nend \n\nlemma size_pair_lb (e f : \u03b1) : \n  1 \u2264 size ({e,f} : set \u03b1) := \nby {rcases em (e = f) with (rfl | hef), simp, rw size_pair hef, norm_num}\n\nlemma size_pair_ub (e f : \u03b1) :\n  size ({e,f} : set \u03b1) \u2264 2 := \nbegin\n  rcases em (e = f) with (rfl | hef), \n  { simp only [pair_eq_singleton, size_singleton], norm_num},\n  rw size_pair hef,\nend \n\nlemma has_distinct_of_two_le_size (hs : 2 \u2264 size s):\n  \u2203 e f \u2208 s, e \u2260 f := \n(finite.two_le_size_iff_has_distinct (finite_of_size_pos (by linarith))).mp hs \n\nlemma has_distinct_of_one_lt_size (hs : 1 < size s):\n  \u2203 e f \u2208 s, e \u2260 f := \n(finite.two_le_size_iff_has_distinct (finite_of_size_pos (by linarith))).mp hs \n  \nlemma has_subset_of_size {n : \u2124} (hn : 0 \u2264 n) (hnx : n \u2264 size t) :\n  \u2203 s \u2286 t, size s = n :=\nbegin\n  rcases eq_or_lt_of_le hn with (rfl | hn'), \n    exact \u27e8\u2205, empty_subset _, size_empty _\u27e9,  \n  have hfin := finite_of_size_pos (lt_of_lt_of_le hn' hnx), clear hn', \n  revert t, revert n, \n  refine nonneg_int_induction _ \n    (\u03bb _ _ _, \u27e8\u2205, empty_subset _, size_empty _\u27e9) \n    (\u03bb n hn ih t ht ht', _), \n  obtain \u27e8e,he\u27e9 := exists_mem_of_size_pos (by linarith : 0 < size t), \n  obtain \u27e8s, hst, hs\u27e9 := @ih (t \\ {e}) _ (finite.diff ht' _), swap,\n  { rw finite.size_remove_mem ht' he, exact le_sub_iff_add_le.mpr ht },\n  refine \u27e8has_insert.insert e s, \u03bb x, _, _\u27e9, \n  { simp only [mem_insert_iff],\n    rintros (rfl | hxs), assumption, \n    exact mem_of_mem_of_subset hxs (subset.trans hst (diff_subset _ _)),  },\n  rw finite.size_insert_nonmem (finite.subset ht' (subset.trans hst (diff_subset _ _))), \n    simpa,\n  exact nonmem_of_nonmem_supset (nonmem_removal _ _) hst,  \nend\n\nlemma has_set_of_size {n : \u2124} (h : 0 \u2264 n) (h' : n \u2264 type_size \u03b1) :\n  \u2203 (Y : set \u03b1), size Y = n :=\nby {rw type_size_eq at h', obtain \u27e8Y,-,hY\u27e9 := has_subset_of_size h h', tauto}\n \nlemma has_subset_of_size_of_infinite {n : \u2124} (hn : 0 \u2264 n) (ht : t.infinite) :\n  \u2203 s \u2286 t, size s = n :=\nbegin\n  revert n, \n  refine nonneg_int_induction _ \u27e8\u2205, empty_subset _, size_empty _\u27e9 _, \n  rintros n hn \u27e8s, hs, hs'\u27e9, \n  by_cases hf : s.finite, \n  { obtain \u27e8e, he\u27e9 := set.infinite.nonempty (set.infinite_of_finite_diff hf ht), \n    refine \u27e8s \u222a {e}, union_singleton_subset_of_subset_mem hs (mem_of_mem_diff he), _\u27e9, \n    rw \u2190 hs', refine finite.size_union_nonmem_singleton hf (not_mem_of_mem_diff he)},\n  obtain \u27e8e,he\u27e9 := set.infinite.nonempty ht, \n  refine \u27e8{e}, singleton_subset_iff.mpr he, _\u27e9, \n  rw [size_singleton, \u2190 hs', size_zero_of_infinite hf], \n  refl, \nend\n\nlemma has_distinct_mems_of_infinite (ht : t.infinite) : \n  \u2203 e f \u2208 t, e \u2260 f := \nbegin\n  obtain \u27e8s,hst, hs\u27e9 := has_subset_of_size_of_infinite (by norm_num : (0 : \u2124) \u2264 2) ht, \n  obtain \u27e8e, f, hef, rfl\u27e9 := size_eq_two_iff_pair.mp hs, \n  refine \u27e8e,f,_,_,hef\u27e9,\n  { rw [\u2190 singleton_subset_iff], apply subset.trans (singleton_subset_pair_left _ _) hst},\n  rw [\u2190 singleton_subset_iff], apply subset.trans (singleton_subset_pair_right _ _) hst,\nend\n\n\n\nend general \n\n\n/-!\nThis section (nearly) contains only copies of lemmas above, but with the finiteness assumptions\nwrapped in a `fintype` instance, as well as a couple of lemmas about type sizes which need\n`fintype` for the statement to even be sensible. All lemmas fail without finiteness, and \nnearly all are proved by just grabbing finiteness assumptions from the instance and invoking\nthe versions with explicit assumptions. \n-/\n\nsection fintype  \n\nopen set \n\nvariables {\u03b1 \u03b2 : Type*} [fintype \u03b1] [fintype \u03b2] {s t : set \u03b1} {e f : \u03b1}\n\nlemma size_monotone (hst : s \u2286 t) : \n  size s \u2264 size t :=\nby {apply finite.size_monotone _ hst, apply finite.of_fintype, }\n\nlemma size_le_type_size (s : set \u03b1):\n  size s \u2264 type_size \u03b1 :=\nsize_monotone (subset_univ _)\n\nlemma sum_size_fiber_eq_size {\u03b9 : Type*} (s : set \u03b1) (f : \u03b1 \u2192 \u03b9) :\n  \u2211\u1da0 (i : \u03b9), size {a \u2208 s | f a = i} = size s := \nby simp_rw [size_def, \u2190 nat.coe_int_distrib_finsum, fin.sum_fincard_fiber_eq_fincard s f]\n\nlemma size_modular (s t : set \u03b1) : \n  size (s \u222a t) + size (s \u2229 t) = size s + size t :=\nby {apply finite.size_modular; apply finite.of_fintype, }\n\nlemma compl_size (s : set \u03b1) :\n  size s\u1d9c = size (univ : set \u03b1) - size s := \nbegin\n  have := size_modular s s\u1d9c, \n  simp only [add_zero, size_empty, union_compl_self, inter_compl_self] at this,  \n  rw this, \n  ring, \nend\n\nlemma size_compl (s : set \u03b1) :\n  size s = size (univ : set \u03b1) - size s\u1d9c := \nby linarith [compl_size s]\n\nlemma size_union (s t : set \u03b1) : \n  size (s \u222a t) = size s + size t - size (s \u2229 t) := \nby {apply finite.size_union; apply finite.of_fintype,}\n\nlemma ssubset_size (hst : s \u2286 t) (hst' : size s < size t) :\n  s \u2282 t := \nby {apply finite.ssubset_size _ _ hst hst'; apply finite.of_fintype,  }\n\nlemma size_subadditive (s t : set \u03b1) : size (s \u222a t) \u2264 size s + size t :=\nby {apply finite.size_subadditive; apply finite.of_fintype }\n\nlemma compl_inter_size (s t : set \u03b1) : size (s \u2229 t) + size (s\u1d9c \u2229 t) = size t := \nby {apply finite.compl_inter_size, apply finite.of_fintype,}\n\nlemma compl_inter_size_subset (hst : s \u2286 t) : \n  size (s\u1d9c \u2229 t) = size t - size s := \nby {apply finite.compl_inter_size_subset _ hst, apply finite.of_fintype, }\n\nlemma diff_size (hst : s \u2286 t) : size (t \\ s) = size t - size s :=  \nby {apply finite.diff_size _ hst, apply finite.of_fintype }\n\nlemma size_diff_le_size (s t : set \u03b1) : size (s \\ t) \u2264 size s := \nby {apply finite.size_diff_le_size, apply finite.of_fintype}\n\nlemma size_union_of_inter_empty (hst : s \u2229 t = \u2205) : \n  size (s \u222a t) = size s + size t := \nby {apply finite.size_union_of_inter_empty _ _ hst ; apply finite.of_fintype}\n\nlemma size_union_of_disjoint (hst : disjoint s t) : \n  size (s \u222a t) = size s + size t := \nby {apply finite.size_union_of_disjoint _ _ hst ; apply finite.of_fintype}\n\nlemma size_modular_diff (s t : set \u03b1) : \n  size (s \u222a t) = size (s \\ t) + size (t \\ s) + size (s \u2229 t) :=\nby {apply finite.size_modular_diff; apply finite.of_fintype }\n\nlemma size_induced_partition (s t : set \u03b1) :\n  size s = size (s \u2229 t) + size (s \\ t) := \nby {apply finite.size_induced_partition, apply finite.of_fintype}\n\nlemma size_induced_partition_inter (s t : set \u03b1) :\n  size s = size (s \u2229 t) + size (s \u2229 t\u1d9c) := \nby {apply finite.size_induced_partition, apply finite.of_fintype}\n\nlemma size_mono_inter_left (s t : set \u03b1) : size (s \u2229 t) \u2264 size s := \nby {apply finite.size_mono_inter_left, apply finite.of_fintype}\n\nlemma size_mono_inter_right (s t : set \u03b1) : size (s \u2229 t) \u2264 size t := \nby {apply finite.size_mono_inter_right, apply finite.of_fintype}\n\nlemma size_mono_union_left (s t : set \u03b1) : size s \u2264 size (s \u222a t)  := \nby {apply finite.size_mono_union_left, apply finite.of_fintype}\n\nlemma size_mono_union_right (s t : set \u03b1) : size t \u2264 size (s \u222a t) := \nby {apply finite.size_mono_union_right, apply finite.of_fintype}\n\nlemma empty_of_size_zero (hsize : size s = 0) : s = \u2205 := \nby {apply finite.empty_of_size_zero _ hsize, apply finite.of_fintype, }\n\n@[simp] lemma size_zero_iff_empty : (size s = 0) \u2194 (s = \u2205) := \nby {apply finite.size_zero_iff_empty, apply finite.of_fintype, }\n\n@[simp] lemma size_le_zero_iff_eq_empty : size s \u2264 0 \u2194 s = \u2205 := \nby {apply finite.size_le_zero_iff_eq_empty, apply finite.of_fintype, }\n\nlemma size_nonempty (hne : s.nonempty) : 0 < size s  := \nby {apply finite.size_nonempty _ hne, apply finite.of_fintype, }\n\nlemma nonempty_iff_size_pos : s.nonempty \u2194 0 < size s := \nby {apply finite.nonempty_iff_size_pos, apply finite.of_fintype, }\n\nlemma one_le_size_iff_nonempty : s.nonempty \u2194 1 \u2264 size s := \nnonempty_iff_size_pos\n\nlemma one_le_size_univ_of_nonempty (h\u03b1 : nonempty \u03b1) : 1 \u2264 size (univ : set \u03b1) := \nby rwa [nonempty_iff_univ_nonempty, one_le_size_iff_nonempty] at h\u03b1\n\nlemma one_le_type_size_of_nonempty (h\u03b1: nonempty \u03b1) : 1 \u2264 type_size \u03b1  := \none_le_size_univ_of_nonempty h\u03b1\n\nlemma size_strict_monotone (hst : s \u2282 t) : size s < size t := \nby {apply finite.size_strict_monotone _ hst; apply finite.of_fintype }\n\nlemma eq_of_eq_size_subset (hst : s \u2286 t) (hsize : size s = size t) : s = t :=\nby {apply finite.eq_of_eq_size_subset _ hst hsize, apply finite.of_fintype }\n\nlemma eq_of_eq_size_subset_iff (hst : s \u2286 t) : \n  ((size s = size t) \u2194 s = t) :=\nby {apply finite.eq_of_eq_size_subset_iff _ hst; apply finite.of_fintype }\n\nlemma eq_of_le_size_subset (hst : s \u2286 t) (hsize : size t \u2264 size s) : \n  s = t :=\nby {apply finite.eq_of_le_size_subset _ hst hsize, apply finite.of_fintype }\n\nlemma size_eq_of_supset (hst : s \u2286 t) (hsize : size t \u2264 size s) :\n  size s = size t := \nby {apply finite.size_eq_of_supset _ hst hsize, apply finite.of_fintype }\n\nlemma size_pos_iff_has_mem : \n  0 < size s \u2194 \u2203 e, e \u2208 s := \nby rw [\u2190 nonempty_iff_size_pos, set.nonempty_def] \n\nlemma one_le_size_iff_has_mem : \n  1 \u2264 size s \u2194 \u2203 e, e \u2208 s := \nby {convert size_pos_iff_has_mem, apply_instance}\n\nlemma size_zero_iff_has_no_mem :\n  size s = 0 \u2194 \u00ac \u2203 e, e \u2208 s := \nby {rw finite.size_zero_iff_has_no_mem, apply finite.of_fintype}\n\nlemma size_le_zero_iff_has_no_mem :\n  size s \u2264 0 \u2194 \u00ac \u2203 e, e \u2208 s := \nby {rw finite.size_le_zero_iff_has_no_mem, apply finite.of_fintype}\n\nlemma mem_diff_of_size_lt (h : size s < size t) :\n  \u2203 (e : \u03b1), e \u2208 t \u2227 e \u2209 s :=\nby {apply finite.mem_diff_of_size_lt _ h, apply finite.of_fintype}\n\nlemma size_union_singleton_compl (he : e \u2208 s\u1d9c) :\n  size (s \u222a {e}) = size s + 1 := \nby {apply finite.size_union_singleton_compl _ he, apply finite.of_fintype}\n\nlemma size_union_nonmem_singleton (hes : e \u2209 s) : \n  size (s \u222a {e}) = size s + 1 := \nby {apply finite.size_union_singleton_compl _ hes, apply finite.of_fintype}\n\nlemma size_remove_mem (he : e \u2208 s) :\n  size (s \\ {e}) = size s - 1 := \nby {apply finite.size_remove_mem _ he, apply finite.of_fintype}\n\nlemma size_insert_nonmem (he : e \u2209 s): \n  size (has_insert.insert e s) = size s + 1 := \nby {apply finite.size_insert_nonmem _ he, apply finite.of_fintype, }\n\nlemma has_sub_one_size_ssubset_of_ne_empty (hne : s \u2260 \u2205) :\n  \u2203 t, t \u2282 s \u2227 size t = size s - 1 := \nby {apply finite.has_sub_one_size_ssubset_of_ne_empty _ hne, apply finite.of_fintype}\n\nlemma has_sub_one_size_ssubset_of_nonempty (hne : s.nonempty) :\n  \u2203 t, t \u2282 s \u2227 size t = size s - 1 := \nby {apply finite.has_sub_one_size_ssubset_of_nonempty _ hne, apply finite.of_fintype}\n\nlemma ne_univ_has_add_one_size_ssupset (hne : s \u2260 univ) :\n  \u2203 t, s \u2282 t \u2227 size t = size s + 1 := \nby {apply finite.ne_univ_has_add_one_size_ssupset _ hne, apply finite.of_fintype}\n\nlemma ne_univ_has_add_one_size_ssupset_element (hne : s \u2260 univ) :\n  \u2203 e, s \u2282 s \u222a {e} \u2227 size (s \u222a {e}) = size s + 1 := \nby {apply finite.ne_univ_has_add_one_size_ssupset_element _ hne, apply finite.of_fintype}   \n\nlemma eq_or_exists_mem_diff_of_size_eq (hst : size s = size t) :\n  s = t \u2228 \u2203 e, e \u2208 s \\ t :=\nby {apply finite.eq_or_exists_mem_diff_of_size_eq _ hst, apply finite.of_fintype}\n\nlemma size_le_one_iff_empty_or_singleton :\n  size s \u2264 1 \u2194 s = \u2205 \u2228 \u2203 e, s = {e} :=\nby {apply finite.size_le_one_iff_empty_or_singleton, apply finite.of_fintype,}\n\nlemma size_le_one_iff_mem_unique : \n  size s \u2264 1 \u2194 \u2200 e f \u2208 s, e = f := \nby {apply finite.size_le_one_iff_mem_unique, apply finite.of_fintype}\n\nlemma size_sUnion {k : set (set \u03b1)} (hdisj : pairwise_disjoint k) : \n  size (\u22c3\u2080 k) = \u2211\u1da0 s in k, size s := \nby {apply finite.size_sUnion _ (\u03bb b hb, _) hdisj; apply finite.of_fintype, } \n\nlemma size_Union {t : \u03b2 \u2192 set \u03b1} (h : \u2200 x y, x \u2260 y \u2192 disjoint (t x) (t y)) :\n  size (\u22c3 x : \u03b2, t x) = \u2211\u1da0 i, (size (t i)) :=\nby {simp_rw [\u2190 finsum_ones_eq_size], apply fin.finsum_in_Union h, }\n\nlemma size_bUnion {t : \u03b2 \u2192 set \u03b1} {b : set \u03b2} (h : \u2200 x y \u2208 b, x \u2260 y \u2192 disjoint (t x) (t y)):  \n  size (\u22c3 (x : \u03b2) (H : x \u2208 b), t x) = \u2211\u1da0 i in b, size (t i) :=\nbegin\n  rw [\u2190 finsum_subtype_eq_finsum_in, \u2190 size_Union], simp,  \n  rintros \u27e8x,hx\u27e9 \u27e8y,hy\u27e9 hxy, \n  refine h x y hx hy _,\n  simpa using hxy, \nend\n\n\nlemma eq_univ_of_size_eq_type_size (hs : size s = type_size \u03b1) : s = univ :=\nbegin\n  rw [\u2190 finsum_ones_eq_size, \u2190 finsum_ones_eq_type_size, finsum_eq_finsum_in_univ] at hs, \n  have h := fin.eq_zero_of_finsum_in_subset_eq_finsum_in_of_nonneg\n    (subset_univ s) (\u03bb _ _, int.zero_lt_one.le) hs.symm.le,\n  simp only [one_ne_zero, univ_diff, mem_compl_eq, imp_false, not_not] at h, \n  ext, \n  tauto,\nend\n\n\n\nvariables {k : set (set \u03b1)}\n\nlemma size_collection_le_size_union (hk : \u2200 s \u2208 k, set.nonempty s) (hdisj : pairwise_disjoint k): \n  (size k \u2264 size (\u22c3\u2080 k)) := \nfinite.size_collection_le_size_union (\u03bb _ _, finite.of_fintype _) hk hdisj\n\nlemma singletons_of_size_collection_eq_size_union (hk : \u2200 s \u2208 k, set.nonempty s) \n(hdisj : pairwise_disjoint k) (hsize : size k = size (\u22c3\u2080 k)): \n  \u2200 s \u2208 k, size s = 1 :=\nby apply finite.singletons_of_size_collection_eq_size_union _ (\u03bb _ _, _) hk hdisj hsize;\n   apply finite.of_fintype \n\nlemma size_collection_eq_size_union_iff \n(hk : \u2200 s \u2208 k, set.nonempty s) (hdisj : pairwise_disjoint k): \n  size k = size (\u22c3\u2080 k) \u2194 \u2200 s \u2208 k, size s = 1 := \nby apply finite.size_collection_eq_size_union_iff _ (\u03bb _ _, _) hk hdisj; apply finite.of_fintype\n\nlemma size_disjoint_collection_le_type_size {k : set (set \u03b1)} (hk' : \u2200 s \u2208 k, set.nonempty s)\n(hdisj : pairwise_disjoint k): \n  size k \u2264 type_size \u03b1 :=\nle_trans (size_collection_le_size_union hk' hdisj) (size_le_type_size _)\n\nlemma size_disjoint_collection_eq_type_size_iff (hk : \u2200 s \u2208 k, set.nonempty s)\n(hdisj : pairwise_disjoint k): \n  size k = type_size \u03b1 \u2194 \u22c3\u2080 k = univ \u2227 \u2200 s \u2208 k, size s = 1 := \nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,  \n  {  obtain \u27e8h\u2081, h\u2082\u27e9 := squeeze_le_trans \n      (size_collection_le_size_union hk hdisj) \n      (size_le_type_size _) \n      h, \n    exact \u27e8eq_univ_of_size_eq_type_size h\u2082, \n            singletons_of_size_collection_eq_size_union hk hdisj h\u2081\u27e9},\n  rw [(size_collection_eq_size_union_iff hk hdisj).mpr h.2, h.1, type_size_eq], \nend\n\n\nend fintype \n\n\n/-! This section deals with fin', an analogue of fin that is defined for all n; it is \nan empty type whenever `n \u2264 0`. -/\n\nsection fin'\n\n/-- the same as fin, but defined for all integers (empty if `n < 0`)-/\ndef fin' (n : \u2124) : Type := fin (n.to_nat)\n\nlemma fin'_eq_fin {n : \u2115} :\n  fin' n = fin n := \nrfl \n\nlemma fin'_neg_elim {n : \u2124} (hn : n < 0) (x : fin' n) : \n  false :=\nby {cases x with x hx, rw int.to_nat_zero_of_neg hn at hx, exact nat.not_lt_zero _ hx,  }\n\nlemma fin'_le_zero_elim {n : \u2124} (hn : n \u2264 0) (x : fin' n) : \n  false :=\nbegin\n  cases x with x hx,\n  rcases eq_or_lt_of_le hn with (rfl | hn), \n  { exact nat.not_lt_zero _ hx, },\n  rw int.to_nat_zero_of_neg hn at hx, \n  exact nat.not_lt_zero _ hx,\nend \n\ninstance {n : \u2124} : fintype (fin' n) := by {unfold fin', apply_instance}\n\n@[simp] lemma size_fin (n : \u2115) : \n  type_size (fin n) = n := \nby {rw [type_size_eq_fincard_t], norm_num}\n\n@[simp] lemma size_fin' (n : \u2124) (hn : 0 \u2264 n) : \n  type_size (fin' n) = n := \nby {convert size_fin (n.to_nat), exact (int.to_nat_of_nonneg hn).symm}\n\n@[simp] lemma size_fin'_univ (n : \u2124) (hn : 0 \u2264 n) : \n  size (set.univ : set (fin' n)) = n := \nby {convert size_fin (n.to_nat), exact (int.to_nat_of_nonneg hn).symm}\n\nlemma type_size_eq_iff_equiv_fin' {\u03b1 : Type*} [fintype \u03b1] {n : \u2124} (hn : 0 \u2264 n) : \n  type_size \u03b1 = n \u2194 nonempty (equiv \u03b1 (fin' n)) :=\nbegin\n  obtain \u27e8m,rfl\u27e9 := int.eq_coe_of_zero_le hn, \n  rw [fin'_eq_fin, \u2190 fincard_t_eq_iff_fin_equiv, type_size_eq_fincard_t, int.coe_nat_inj'],\nend\n\n/-- choose an equivalence between a finite type and the appropriate `fin'` -/\ndef choose_equiv_to_fin' (\u03b1 : Type*) [fintype \u03b1] :\n  equiv \u03b1 (fin' (type_size \u03b1)) :=\nclassical.choice ((type_size_eq_iff_equiv_fin' (type_size_nonneg \u03b1)).mp rfl)\n\nlemma type_size_le_zero_elim {\u03b1 : Type*} [fintype \u03b1] (h\u03b1 : type_size \u03b1 \u2264 0) (e : \u03b1): \n  false :=\nbegin\n  let bij := choose_equiv_to_fin' \u03b1, \n  apply nat.not_lt_zero (bij e).val,\n  convert (bij e).property, \n  rw int.to_nat_zero_of_nonpos h\u03b1,   \nend\n\nlemma type_size_lt_zero_elim {\u03b1 : Type*} (h\u03b1 : type_size \u03b1 < 0) (e : \u03b1): \n  false :=\nby linarith [type_size_nonneg \u03b1]\n\nend fin' \n\n\n/-! This section covers the relationship between size and functions between sets (mostly embeddings\nand bijections) . -/\n\nsection embeddings\n\nopen set \n\nvariables {\u03b1 : Type*}{\u03b2 : Type*} \n\nlemma size_image_emb (f : \u03b1 \u21aa \u03b2) (s : set \u03b1) : \n  size (f '' s) = size s := \nby {simp_rw [size], norm_cast, apply fincard_img_emb, }\n\nlemma type_size_le_type_size_inj [fintype \u03b2] (f : \u03b1 \u21aa \u03b2) : \n  type_size \u03b1 \u2264 type_size \u03b2 := \nbegin\n  rw [type_size, type_size, \u2190 size_image_emb f], \n  apply size_monotone, \n  apply subset_univ, \nend \n\nlemma size_image_inj {f : \u03b1 \u2192 \u03b2} (hf : function.injective f) (s : set \u03b1) : \n  size (f '' s) = size s := \nsize_image_emb \u27e8f , hf\u27e9 s\n\nlemma size_image_equiv (f : \u03b1 \u2243 \u03b2) (s : set \u03b1) :\n  size (f '' s) = size s :=\nsize_image_emb (f.to_embedding) s \n\nlemma size_range_emb (f : \u03b1 \u21aa \u03b2):\n  size (range f) = type_size \u03b1 :=\nby {rw [\u2190 image_univ, size_image_emb], refl,  }\n\nlemma size_range_inj (f : \u03b1 \u2192 \u03b2)(hf : function.injective f):\n  size (range f) = type_size \u03b1 :=\nby {rw [\u2190 image_univ, size_image_inj hf], refl,  }\n\nlemma type_size_eq_type_size_equiv (f : \u03b1 \u2243 \u03b2) : \n  type_size \u03b1 = type_size \u03b2 := \nby rw [type_size, type_size, \u2190 size_image_equiv f, \u2190 f.range_eq_univ, image_univ]\n\nlemma type_size_eq_iff_equiv [fintype \u03b1] [fintype \u03b2]: \n  type_size \u03b1 = type_size \u03b2 \u2194 nonempty (\u03b1 \u2243 \u03b2) :=\nbegin\n  simp_rw [type_size_eq_fincard_t],\n  norm_num, \n  simp_rw [fincard_t_eq_fintype_card, fintype.card_eq],\nend \n\n/-- Gives an equivalence between two types of equal size -/\ndef equiv_of_type_size_eq [fintype \u03b1] [fintype \u03b2] (h : type_size \u03b1 = type_size \u03b2 ): \u03b1 \u2243 \u03b2 :=\nclassical.choice (type_size_eq_iff_equiv.mp h)\n\n@[simp] lemma equiv.image_mem_image_iff_mem {f : \u03b1 \u2243 \u03b2} {x : \u03b1} {s : set \u03b1} : \n  f x \u2208 f '' s \u2194 x \u2208 s := \nbegin\n  rw mem_image, split, \n  { rintros \u27e8y, hy, hyx\u27e9, rw equiv.apply_eq_iff_eq at hyx, rwa \u2190hyx},\n  exact \u03bb hx, \u27e8x, hx, rfl\u27e9, \nend\n\n@[simp] lemma size_preimage_equiv (f : \u03b1 \u2243 \u03b2) (s : set \u03b2) :\n  size (f \u207b\u00b9' s) = size s :=\nbegin\n  unfold_coes, \n  rw \u2190set.image_eq_preimage_of_inverse f.right_inv f.left_inv, \n  convert size_image_emb (f.symm.to_embedding) s, \nend\n\nlemma size_preimage_embed_subset_range (f : \u03b1 \u21aa \u03b2) (s : set \u03b2) (hs : s \u2286 range f) : \n  size (f \u207b\u00b9' s) = size s := \nbegin\n  suffices h: f '' (f \u207b\u00b9' s) = s, \n  { rw eq_comm, nth_rewrite 0 \u2190 h, apply size_image_emb}, \n  apply image_preimage_eq_of_subset hs, \nend \n\nlemma size_subtype_image {E : set \u03b1} (s : set E) : \n  size (subtype.val '' s) = size s :=\nbegin\n  let f : E \u21aa \u03b1 := \u27e8subtype.val, \u03bb x y hxy, \n    by {cases x, cases y, simp only [subtype.mk_eq_mk], exact hxy}\u27e9, \n  apply size_image_emb f, \nend\n\n@[simp] lemma size_image_coe {E : set \u03b1} (s : set E) : \n  size (coe '' s : set \u03b1) = size s := \nsize_subtype_image s \n\n@[simp] lemma size_preimage_coe {E : set \u03b1} (s : set \u03b1) : \n  size (coe \u207b\u00b9' s : set E) = size (s \u2229 E) := \nby {rw \u2190 size_image_coe (coe \u207b\u00b9' s : set E), simp, }\n\n\nlemma nonempty_fin'_emb_of_type_size {n : \u2124} (h\u03b1 : n \u2264 type_size \u03b1 ) : \n  nonempty ((fin' n) \u21aa \u03b1) := \nbegin\n  by_cases hn : n \u2264 0, \n  { exact \u27e8\u27e8\u03bb x, false.elim (fin'_le_zero_elim hn x), \u03bb x, false.elim (fin'_le_zero_elim hn x)\u27e9\u27e9},\n  push_neg at hn, \n  obtain \u27e8m,rfl\u27e9 := int.eq_coe_of_zero_le (le_of_lt hn), \n  rw fin'_eq_fin, \n  \n  obtain \u27e8s,hs\u27e9 := has_set_of_size (le_of_lt hn) h\u03b1, \n  rw [size_def, int.coe_nat_inj'] at hs,\n  subst hs, \n  letI := fintype_of_type_size_pos (lt_of_lt_of_le hn h\u03b1), \n  have bij := (@choose_fin_bij \u21a5s _).symm, \n  exact \u27e8\u27e8 \n    \u03bb x, (bij \u27e8x, by {rw fincard_t_subtype_eq_fincard, exact x.property,}\u27e9).val ,\n    \u03bb x y hxy, by {convert subtype.val_injective hxy, tidy,}\u27e9\u27e9,\nend\n\n/-- an embedding from `fin' n` into `\u03b1`, provided that `n \u2264 type_size \u03b1` -/\ndef choose_fin'_inj_of_type_size {n : \u2124} (h\u03b1 : n \u2264 type_size \u03b1) :\n  (fin' n) \u21aa \u03b1 :=\nclassical.choice (nonempty_fin'_emb_of_type_size h\u03b1)\n\ndef emb_nonempty_of_size_le_size {\u03b1 : Type*} {\u03b2 : Type*} [fintype \u03b1]\n(hsize : type_size \u03b1 \u2264 type_size \u03b2 ) : \n  nonempty (\u03b1 \u21aa \u03b2) := \n\u27e8(choose_equiv_to_fin' \u03b1).to_embedding.trans (@choose_fin'_inj_of_type_size \u03b2 _ hsize)\u27e9 \n\n\nlemma type_size_le_iff_emb {\u03b1 \u03b2 : Type* } [fintype \u03b1] [fintype \u03b2] : \n  type_size \u03b1 \u2264 type_size \u03b2 \u2194 nonempty (\u03b1 \u21aa \u03b2) :=\n\u27e8 \u03bb h, emb_nonempty_of_size_le_size h, \n  \u03bb \u27e8emb\u27e9, eq.trans_le (size_range_emb emb).symm (size_le_type_size (range emb)), \u27e9\n\n/-- an embedding from `\u03b1` into `\u03b2`, provided that `type_size \u03b1 \u2264 type_size \u03b2` and `\u03b1` is finite.\nA little scary as this takes a `fintype` and outputs data, so could cause instance issues. Maybe \nthe `nonempty` version is safer. -/\ndef choose_emb_of_size_le_size {\u03b1 : Type*} {\u03b2 : Type*} [fintype \u03b1]\n(hsize : type_size \u03b1 \u2264 type_size \u03b2 ) : \n  (\u03b1 \u21aa \u03b2) := \n(choose_equiv_to_fin' \u03b1).to_embedding.trans (@choose_fin'_inj_of_type_size \u03b2 _ hsize) \n\nlemma exists_emb_of_type_size_le_size_set {\u03b1 : Type*} [fintype \u03b1] {\u03b2 : Type*} {s : set \u03b2} \n(hsize : type_size \u03b1 \u2264 size s ) : \n  \u2203 (emb : \u03b1 \u21aa \u03b2), set.range emb \u2286 s := \nbegin\n  rw \u2190 type_size_coe_set_eq_size at hsize, \n  let emb := choose_emb_of_size_le_size hsize, \n  exact \u27e8emb.trans \u27e8subtype.val, subtype.val_injective \u27e9, \u03bb x, by tidy\u27e9, \nend\n\nlemma set.finite.exists_emb_of_type_size_eq_size_set {\u03b1 : Type*} [fintype \u03b1] {\u03b2 : Type*} \n{s : set \u03b2} (hs : s.finite) (hsize : type_size \u03b1 = size s ) : \n  \u2203 (emb : \u03b1 \u21aa \u03b2), set.range emb = s := \nbegin\n  convert exists_emb_of_type_size_le_size_set (le_of_eq hsize), \n  ext emb, \n  split, \n  { unfreezingI {rintro rfl}, exact subset_refl _, }, \n  intros hss, \n  apply finite.eq_of_eq_size_subset hs hss,\n  rw [\u2190 image_univ, size_image_emb],  \n  convert hsize, \nend\n\nlemma exists_emb_of_type_size_eq_size_set {\u03b1 : Type*} [fintype \u03b1] {\u03b2 : Type*} [fintype \u03b2]\n{s : set \u03b2} (hsize : type_size \u03b1 = size s ) : \n  \u2203 (emb : \u03b1 \u21aa \u03b2), set.range emb = s := \nby {apply set.finite.exists_emb_of_type_size_eq_size_set _ hsize, apply finite.of_fintype }\n\nlemma type_size_lt_of_nonmem_range_emb {\u03b1 \u03b2 : Type* } [fintype \u03b2] (emb : \u03b1 \u21aa \u03b2) {b : \u03b2}\n(hb : b \u2209 range emb): \n  type_size \u03b1 < type_size \u03b2 :=\nbegin\n  refine lt_of_le_of_ne (by { rw [\u2190 size_range_emb emb], apply size_le_type_size, }) (\u03bb h, _),\n  letI : fintype \u03b1 := fintype.of_injective _ (emb.injective), \n  let eq := equiv_of_type_size_eq h.symm, \n  have h' := size_image_equiv eq (has_insert.insert b (range emb)), \n  rw [size_insert_nonmem hb, size_range_emb] at h', \n  linarith [size_le_type_size (eq '' insert b (range \u21d1emb))], \nend\n\nlemma type_size_lt_iff_exists_proper_emb {\u03b1 \u03b2 : Type*} [fintype \u03b1] [fintype \u03b2] : \n  type_size \u03b1 < type_size \u03b2 \u2194 \u2203 (emb : \u03b1 \u21aa \u03b2) (b : \u03b2), b \u2209 range emb := \nbegin\n  refine \u27e8\u03bb h, _, \u03bb \u27e8emb, b, hb\u27e9, type_size_lt_of_nonmem_range_emb emb hb\u27e9,\n  obtain \u27e8emb\u27e9 := emb_nonempty_of_size_le_size (le_of_lt h), \n  refine \u27e8emb, compl_nonempty_iff_exists_nonmem.mp (compl_nonempty_of_size_lt_type_size _)\u27e9,\n  rwa size_range_emb, \nend\n\n\n\nend embeddings \n\n", "meta": {"author": "apnelson1", "repo": "lean-matroids", "sha": "1880f5b4b9a99948368e35539672a9bf35cc09cc", "save_path": "github-repos/lean/apnelson1-lean-matroids", "path": "github-repos/lean/apnelson1-lean-matroids/lean-matroids-1880f5b4b9a99948368e35539672a9bf35cc09cc/src/old/old_aux/prelim/size.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7038338805951444}}
{"text": "import game.sets.sets_level05 -- hide\nimport tactic -- hide\n\n\nnamespace xena -- hide\n\nvariable X : Type\n\nopen_locale classical -- hide\n\n/-\n# Chapter 1 : Sets\n\n## Level 6 : `sdiff` and `neg`\n-/\n\n/-\n\nThe set-theoretic difference `A \\ B` satisfies the following property:\n\n```\nlemma mem_sdiff_iff : x \u2208 A \\ B \u2194 x \u2208 A \u2227 x \u2209 B\n```\n\nThe complement `-A` of a set `A` (often denoted $A^c$ in textbooks)\nis all the elements of `X` which are not in `A`:\n\n```\nlemma mem_neg_iff : x \u2208 -A \u2194 x \u2209 A\n```\n\nIn this lemma, you might get a shock. The `rw` tactic is aggressive\nin the Real Number Game -- if after a rewrite the goal can be\nsolved by `refl`, then Lean will close the goal automatically.\n\n-/\n\n/- Axiom : mem_sdiff_iff :\nx \u2208 A \\ B \u2194 x \u2208 A \u2227 x \u2209 B\n-/\n\n/- Axiom : mem_neg_iff :\nx \u2208 -A \u2194 x \u2209 A\n-/\n\n/- Lemma\nIf $A$ and $B$ are sets with elements of type $X$, then\n\n$$(A \\setminus B) = A \\cap B^{c}.$$\n-/\ntheorem setdiff_eq_intersect_comp (A B : set X) : A \\ B = A \u2229 B\u1d9c := \nbegin\n  rw ext_iff,\n  intro x,\n  rw mem_sdiff_iff,\n  rw mem_inter_iff,\n  rw mem_neg_iff,\nend\n\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/sets/sets_level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7038255722966139}}
{"text": "/-\nExample from \"Inductively defined types\",\nfrom Thierry Coquand and Christine Paulin,\nCOLOG-88.\n\nIt shows it is inconsistent to allow inductive datatypes such as\n\ninductive A : Type :=\n| intro : ((A \u2192 Prop) \u2192 Prop) \u2192 A\n\n-/\n\n/- Phi is a positive, but not strictly positive, operator. -/\ndefinition Phi (A : Type) := (A \u2192 Prop) \u2192 Prop\n\n/- If we were allowed to form the inductive type\n\n     inductive A: Type :=\n     | introA : Phi A -> A\n\n   we would get the following\n-/\n\nuniverse l\n-- The new type A\naxiom A : Type.{l}\n-- The constructor\naxiom introA : Phi A \u2192 A\n-- The eliminator\naxiom recA   : \u03a0 {C : A \u2192 Type}, (\u03a0 (p : Phi A), C (introA p)) \u2192 (\u03a0 (a : A), C a)\n-- The \"computational rule\"\naxiom recA_comp : \u03a0 {C : A \u2192 Type} (H : \u03a0 (p : Phi A), C (introA p)) (p : Phi A), recA H (introA p) = H p\n\n-- The recursor could be used to define matchA\nnoncomputable definition matchA (a : A) : Phi A :=\nrecA (\u03bb p, p) a\n\n-- and the computation rule would allows us to define\nlemma betaA (p : Phi A) : matchA (introA p) = p :=\n!recA_comp\n\n-- As in all inductive datatypes, we would be able to prove that constructors are injective.\nlemma introA_injective : \u2200 {p p' : Phi A}, introA p = introA p' \u2192 p = p' :=\n\u03bb p p' h,\n  have aux : matchA (introA p) = matchA (introA p'), by rewrite h,\n  by rewrite [*betaA at aux]; exact aux\n\n-- For any type T, there is an injection from T to (T \u2192 Prop)\ndefinition i {T : Type} : T \u2192 (T \u2192 Prop) :=\n\u03bb x y, x = y\n\nlemma i_injective {T : Type} {a b : T} : i a = i b \u2192 a = b :=\n\u03bb h,\n  have e\u2081 : i a a = i b a,     by rewrite [h],\n  have e\u2082 : (a = a) = (b = a), from e\u2081,\n  have e\u2083 : b = a,             from eq.subst e\u2082 rfl,\n  eq.symm e\u2083\n\n-- Hence, by composition, we get an injection f from (A \u2192 Prop) to A\nnoncomputable definition f : (A \u2192 Prop) \u2192 A :=\n\u03bb p, introA (i p)\n\nlemma f_injective : \u2200 {p p' : A \u2192 Prop}, f p = f p' \u2192 p = p':=\n\u03bb (p p' : A \u2192 Prop) (h : introA (i p) = introA (i p')),\n  i_injective (introA_injective h)\n\n/-\n  We are now back to the usual Cantor-Russel paradox.\n  We can define\n-/\nnoncomputable definition P0 (a : A) : Prop :=\n\u2203 (P : A \u2192 Prop), f P = a \u2227 \u00ac P a\n-- i.e., P0 a := codes a set P such that x\u2209P\n\nnoncomputable definition x0 : A := f P0\n\nlemma fP0_eq : f P0 = x0 :=\nrfl\n\nlemma not_P0_x0 : \u00ac P0 x0 :=\n\u03bb h : P0 x0,\n  obtain (P : A \u2192 Prop) (hp : f P = x0 \u2227 \u00ac P x0), from h,\n  have fp_eq : f P = f P0,  from and.elim_left hp,\n  have p_eq  : P = P0,      from f_injective fp_eq,\n  have nh    : \u00ac P0 x0,     by rewrite [p_eq at hp]; exact (and.elim_right hp),\n  absurd h nh\n\nlemma P0_x0 : P0 x0 :=\nexists.intro P0 (and.intro fP0_eq not_P0_x0)\n\ntheorem inconsistent : false :=\nabsurd P0_x0 not_P0_x0\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/logic/examples/colog88.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.7038255607824058}}
{"text": "import linear_algebra.matrix.ldl\nimport linear_algebra.matrix.block\nimport missing.analysis.inner_product_space.gram_schmidt_ortho\nimport missing.linear_algebra.matrix.triangular\n\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c]\nvariables {n : Type*} [linear_order n] [is_well_order n (<)] [locally_finite_order_bot n]\n\nlocal notation `\u27ea`x`, `y`\u27eb` :=\n@inner \ud835\udd5c (n \u2192 \ud835\udd5c) (pi_Lp.inner_product_space (\u03bb _, \ud835\udd5c)).to_has_inner x y\n\nopen matrix\nopen_locale matrix\n\nvariables {S : matrix n n \ud835\udd5c} [fintype n] (hS : S.pos_def)\n\n@[simp] lemma LDL.lower_inv_diagonal (i : n) :\n  LDL.lower_inv hS i i = 1 :=\nbegin\n  rw [LDL.lower_inv_eq_gram_schmidt_basis, basis.to_matrix],\n  simpa only [gram_schmidt_basis, basis.coe_mk]\n    using @repr_gram_schmidt_diagonal \ud835\udd5c (n \u2192 \ud835\udd5c) _\n      (inner_product_space.of_matrix hS.transpose) n _ _ _ i (pi.basis_fun \ud835\udd5c n)\nend\n\nlemma LDL.lower_eq_to_matrix : LDL.lower hS = ((@gram_schmidt_basis \ud835\udd5c (n \u2192 \ud835\udd5c) _\n  (inner_product_space.of_matrix hS.transpose) n _ _ _ (pi.basis_fun \ud835\udd5c n)).to_matrix\n    (pi.basis_fun \ud835\udd5c n))\u1d40 :=\nbegin\n  simp only [LDL.lower, LDL.lower_inv_eq_gram_schmidt_basis],\n  apply matrix.inv_eq_left_inv,\n  rw [\u2190transpose_mul, basis.to_matrix_mul_to_matrix_flip, transpose_one]\nend\n\nlemma LDL.lower_triangular_lower_inv : lower_triangular (LDL.lower_inv hS) :=\nby apply LDL.lower_inv_triangular\n\nlemma LDL.lower_triangular_lower : lower_triangular (LDL.lower hS) :=\nlower_triangular_inv_of_lower_triangular (LDL.lower_triangular_lower_inv hS)\n\nnoncomputable instance LDL.invertible_lower : invertible (LDL.lower hS) :=\ninvertible_of_left_inverse _ _ (matrix.mul_inv_of_invertible (LDL.lower_inv hS))\n\n@[simp] lemma inv_lower_eq_lower_inv : (LDL.lower hS)\u207b\u00b9 = LDL.lower_inv hS :=\nmatrix.inv_eq_left_inv (matrix.mul_inv_of_invertible (LDL.lower_inv hS))\n\n@[simp] lemma LDL.lower_diagonal (i : n) :\n  LDL.lower hS i i = 1 :=\nby simpa using diag_inv_mul_diag_eq_one_of_lower_triangular (LDL.lower_triangular_lower hS) i\n\n@[simp] lemma LDL.det_lower_inv :\n  (LDL.lower_inv hS).det = 1 :=\nbegin\n  rw [det_of_lower_triangular (LDL.lower_inv hS) (by apply LDL.lower_inv_triangular),\n    finset.prod_eq_one],\n  intros,\n  rw LDL.lower_inv_diagonal,\nend\n\n@[simp] lemma LDL.det_lower :\n  (LDL.lower hS).det = 1 :=\nby simp [LDL.lower]\n", "meta": {"author": "verified-optimization", "repo": "optlib", "sha": "b5d69678be5a4be8284ed15d376d6d973c64ea72", "save_path": "github-repos/lean/verified-optimization-optlib", "path": "github-repos/lean/verified-optimization-optlib/optlib-b5d69678be5a4be8284ed15d376d6d973c64ea72/src/missing/linear_algebra/matrix/ldl.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7038045872818076}}
{"text": "import algebra.group\nimport data.set.basic\nimport analysis.real\nimport tactic.norm_num\nimport .choice\n\nset_option pp.beta true\n\nexample (P Q R : Prop) : ((P \u2228 Q \u2192 R) \u2227 P) \u2192 R :=\nbegin\n  rintro \u27e8hyp1, hyp2\u27e9,\n  apply hyp1,\n  left,\n  assumption,\nend\n\nexample (P Q R : Prop) : ((P \u2228 Q \u2192 R) \u2227 P) \u2192 R :=\nby finish\n\nexample (X : Type) (A B C : set X) : A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\n  ext x,\n  split,\n  { rintro \u27e8x_1, x_B | x_C\u27e9,\n    { left,\n      apply and.intro,\n      { assumption },\n      { assumption } },\n    { right,\n      apply and.intro,\n      { assumption },\n      { assumption } } },\n  { rintro (\u27e8x_A, x_B\u27e9|\u27e8x_A, x_C\u27e9),\n    { apply and.intro,\n      { assumption },\n      { left,\n        assumption } },\n    { apply and.intro,\n      { assumption },\n      { right,\n        assumption } } }\nend\n\nexample (X : Type) (A B C : set X) : A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\nby ext x; split; finish\n\nexample (X : Type) (A B C : set X) : A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\nset.inter_distrib_left _ _ _\n\nexample (X Y : Type) (f : X \u2192 Y) :\n  (\u2200 y : Y, \u2203 x : X, f(x) = y) \u2194 (\u2203 g : Y \u2192 X, f \u2218 g = id) :=\nbegin\n  split,\n  { intro hyp,\n    choice hyp with g H,\n    existsi g,\n    exact funext H, },\n  { rintros \u27e8g, f_rond_g\u27e9 y,\n    existsi g y,\n    exact congr_fun f_rond_g y }\nend\n\nexample (G H : Type) [group G] [group H] (f : G \u2192 H)\n  (Hyp : \u2200 a b : G, f (a*b) = f a * f b) : f 1 = 1 :=\nbegin\n  have clef := calc\n   f 1 = f (1*1) : by simp\n   ... = f 1 * f 1 : Hyp 1 1,\n  exact mul_self_iff_eq_one.1 (eq.symm clef)\nend\n\nexample (u : \u2115 \u2192 \u211d) (H : \u2200 n, u (n+1) = 2*u n) (H' : u 0 > 0) :\n  \u2200 n, u n > 0 :=\nbegin\n  intro n,\n  induction n with n IH,\n  { exact H' },\n  { rw H,\n    apply mul_pos,\n    norm_num,\n    exact IH }\nend", "meta": {"author": "PatrickMassot", "repo": "lean-scratchpad", "sha": "03eec3bfabfc218b79dcbe7c7712bfa024a02625", "save_path": "github-repos/lean/PatrickMassot-lean-scratchpad", "path": "github-repos/lean/PatrickMassot-lean-scratchpad/lean-scratchpad-03eec3bfabfc218b79dcbe7c7712bfa024a02625/src/demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.8902942319436395, "lm_q1q2_score": 0.7038045828881787}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport algebra.direct_limit\nimport field_theory.is_alg_closed.basic\nimport field_theory.splitting_field\n/-!\n# Algebraic Closure\n\nIn this file we construct the algebraic closure of a field\n\n## Main Definitions\n\n- `algebraic_closure k` is an algebraic closure of `k` (in the same universe).\n  It is constructed by taking the polynomial ring generated by indeterminates `x_f`\n  corresponding to monic irreducible polynomials `f` with coefficients in `k`, and quotienting\n  out by a maximal ideal containing every `f(x_f)`, and then repeating this step countably\n  many times. See Exercise 1.13 in Atiyah--Macdonald.\n\n## Tags\n\nalgebraic closure, algebraically closed\n-/\n\nuniverses u v w\nnoncomputable theory\nopen_locale classical big_operators polynomial\nopen polynomial\n\nvariables (k : Type u) [field k]\n\nnamespace algebraic_closure\n\nopen mv_polynomial\n\n/-- The subtype of monic irreducible polynomials -/\n@[reducible] def monic_irreducible : Type u :=\n{ f : k[X] // monic f \u2227 irreducible f }\n\n/-- Sends a monic irreducible polynomial `f` to `f(x_f)` where `x_f` is a formal indeterminate. -/\ndef eval_X_self (f : monic_irreducible k) : mv_polynomial (monic_irreducible k) k :=\npolynomial.eval\u2082 mv_polynomial.C (X f) f\n\n/-- The span of `f(x_f)` across monic irreducible polynomials `f` where `x_f` is an\nindeterminate. -/\ndef span_eval : ideal (mv_polynomial (monic_irreducible k) k) :=\nideal.span $ set.range $ eval_X_self k\n\n/-- Given a finset of monic irreducible polynomials, construct an algebra homomorphism to the\nsplitting field of the product of the polynomials sending each indeterminate `x_f` represented by\nthe polynomial `f` in the finset to a root of `f`. -/\ndef to_splitting_field (s : finset (monic_irreducible k)) :\n  mv_polynomial (monic_irreducible k) k \u2192\u2090[k] splitting_field (\u220f x in s, x : k[X]) :=\nmv_polynomial.aeval $ \u03bb f,\n  if hf : f \u2208 s\n  then root_of_splits _\n    ((splits_prod_iff _ $ \u03bb (j : monic_irreducible k) _, j.2.2.ne_zero).1\n      (splitting_field.splits _) f hf)\n    (mt is_unit_iff_degree_eq_zero.2 f.2.2.not_unit)\n  else 37\n\ntheorem to_splitting_field_eval_X_self {s : finset (monic_irreducible k)} {f} (hf : f \u2208 s) :\n  to_splitting_field k s (eval_X_self k f) = 0 :=\nby { rw [to_splitting_field, eval_X_self, \u2190 alg_hom.coe_to_ring_hom, hom_eval\u2082,\n         alg_hom.coe_to_ring_hom, mv_polynomial.aeval_X, dif_pos hf,\n         \u2190 algebra_map_eq, alg_hom.comp_algebra_map],\n  exact map_root_of_splits _ _ _ }\n\ntheorem span_eval_ne_top : span_eval k \u2260 \u22a4 :=\nbegin\n  rw [ideal.ne_top_iff_one, span_eval, ideal.span, \u2190 set.image_univ,\n    finsupp.mem_span_image_iff_total],\n  rintros \u27e8v, _, hv\u27e9,\n  replace hv := congr_arg (to_splitting_field k v.support) hv,\n  rw [alg_hom.map_one, finsupp.total_apply, finsupp.sum, alg_hom.map_sum, finset.sum_eq_zero] at hv,\n  { exact zero_ne_one hv },\n  intros j hj,\n  rw [smul_eq_mul, alg_hom.map_mul, to_splitting_field_eval_X_self k hj, mul_zero]\nend\n\n/-- A random maximal ideal that contains `span_eval k` -/\ndef max_ideal : ideal (mv_polynomial (monic_irreducible k) k) :=\nclassical.some $ ideal.exists_le_maximal _ $ span_eval_ne_top k\n\ninstance max_ideal.is_maximal : (max_ideal k).is_maximal :=\n(classical.some_spec $ ideal.exists_le_maximal _ $ span_eval_ne_top k).1\n\ntheorem le_max_ideal : span_eval k \u2264 max_ideal k :=\n(classical.some_spec $ ideal.exists_le_maximal _ $ span_eval_ne_top k).2\n\n/-- The first step of constructing `algebraic_closure`: adjoin a root of all monic polynomials -/\ndef adjoin_monic : Type u :=\nmv_polynomial (monic_irreducible k) k \u29f8 max_ideal k\n\ninstance adjoin_monic.field : field (adjoin_monic k) :=\nideal.quotient.field _\n\ninstance adjoin_monic.inhabited : inhabited (adjoin_monic k) := \u27e837\u27e9\n\n/-- The canonical ring homomorphism to `adjoin_monic k`. -/\ndef to_adjoin_monic : k \u2192+* adjoin_monic k :=\n(ideal.quotient.mk _).comp C\n\ninstance adjoin_monic.algebra : algebra k (adjoin_monic k) :=\n(to_adjoin_monic k).to_algebra\n\ntheorem adjoin_monic.algebra_map : algebra_map k (adjoin_monic k) = (ideal.quotient.mk _).comp C :=\nrfl\n\ntheorem adjoin_monic.is_integral (z : adjoin_monic k) : is_integral k z :=\nlet \u27e8p, hp\u27e9 := ideal.quotient.mk_surjective z in hp \u25b8\nmv_polynomial.induction_on p (\u03bb x, is_integral_algebra_map) (\u03bb p q, is_integral_add)\n  (\u03bb p f ih, @is_integral_mul _ _ _ _ _ _ (ideal.quotient.mk _ _) ih \u27e8f, f.2.1,\n    by { erw [adjoin_monic.algebra_map, \u2190 hom_eval\u2082,\n              ideal.quotient.eq_zero_iff_mem],\n      exact le_max_ideal k (ideal.subset_span \u27e8f, rfl\u27e9) }\u27e9)\n\ntheorem adjoin_monic.exists_root {f : k[X]} (hfm : f.monic) (hfi : irreducible f) :\n  \u2203 x : adjoin_monic k, f.eval\u2082 (to_adjoin_monic k) x = 0 :=\n\u27e8ideal.quotient.mk _ $ X (\u27e8f, hfm, hfi\u27e9 : monic_irreducible k),\n by { rw [to_adjoin_monic, \u2190 hom_eval\u2082, ideal.quotient.eq_zero_iff_mem],\n      exact le_max_ideal k (ideal.subset_span $ \u27e8_, rfl\u27e9) }\u27e9\n\n/-- The `n`th step of constructing `algebraic_closure`, together with its `field` instance. -/\ndef step_aux (n : \u2115) : \u03a3 \u03b1 : Type u, field \u03b1 :=\nnat.rec_on n \u27e8k, infer_instance\u27e9 $ \u03bb n ih, \u27e8@adjoin_monic ih.1 ih.2, @adjoin_monic.field ih.1 ih.2\u27e9\n\n/-- The `n`th step of constructing `algebraic_closure`. -/\ndef step (n : \u2115) : Type u :=\n(step_aux k n).1\n\ninstance step.field (n : \u2115) : field (step k n) :=\n(step_aux k n).2\n\ninstance step.inhabited (n) : inhabited (step k n) := \u27e837\u27e9\n\n/-- The canonical inclusion to the `0`th step. -/\ndef to_step_zero : k \u2192+* step k 0 :=\nring_hom.id k\n\n/-- The canonical ring homomorphism to the next step. -/\ndef to_step_succ (n : \u2115) : step k n \u2192+* step k (n + 1) :=\n@to_adjoin_monic (step k n) (step.field k n)\n\ninstance step.algebra_succ (n) : algebra (step k n) (step k (n + 1)) :=\n(to_step_succ k n).to_algebra\n\ntheorem to_step_succ.exists_root {n} {f : polynomial (step k n)}\n  (hfm : f.monic) (hfi : irreducible f) :\n  \u2203 x : step k (n + 1), f.eval\u2082 (to_step_succ k n) x = 0 :=\n@adjoin_monic.exists_root _ (step.field k n) _ hfm hfi\n\n/-- The canonical ring homomorphism to a step with a greater index. -/\ndef to_step_of_le (m n : \u2115) (h : m \u2264 n) : step k m \u2192+* step k n :=\n{ to_fun := nat.le_rec_on h (\u03bb n, to_step_succ k n),\n  map_one' := begin\n    induction h with n h ih, { exact nat.le_rec_on_self 1 },\n    rw [nat.le_rec_on_succ h, ih, ring_hom.map_one]\n  end,\n  map_mul' := \u03bb x y, begin\n    induction h with n h ih, { simp_rw nat.le_rec_on_self },\n    simp_rw [nat.le_rec_on_succ h, ih, ring_hom.map_mul]\n  end,\n  map_zero' := begin\n    induction h with n h ih, { exact nat.le_rec_on_self 0 },\n    rw [nat.le_rec_on_succ h, ih, ring_hom.map_zero]\n  end,\n  map_add' := \u03bb x y, begin\n    induction h with n h ih, { simp_rw nat.le_rec_on_self },\n    simp_rw [nat.le_rec_on_succ h, ih, ring_hom.map_add]\n  end }\n\n@[simp] lemma coe_to_step_of_le (m n : \u2115) (h : m \u2264 n) :\n  (to_step_of_le k m n h : step k m \u2192 step k n) = nat.le_rec_on h (\u03bb n, to_step_succ k n) :=\nrfl\n\ninstance step.algebra (n) : algebra k (step k n) :=\n(to_step_of_le k 0 n n.zero_le).to_algebra\n\ninstance step.scalar_tower (n) : is_scalar_tower k (step k n) (step k (n + 1)) :=\nis_scalar_tower.of_algebra_map_eq $ \u03bb z,\n  @nat.le_rec_on_succ (step k) 0 n n.zero_le (n + 1).zero_le (\u03bb n, to_step_succ k n) z\n\ntheorem step.is_integral (n) : \u2200 z : step k n, is_integral k z :=\nnat.rec_on n (\u03bb z, is_integral_algebra_map) $ \u03bb n ih z,\n  is_integral_trans ih _ (adjoin_monic.is_integral (step k n) z : _)\n\ninstance to_step_of_le.directed_system :\n  directed_system (step k) (\u03bb i j h, to_step_of_le k i j h) :=\n\u27e8\u03bb i x h, nat.le_rec_on_self x, \u03bb i\u2081 i\u2082 i\u2083 h\u2081\u2082 h\u2082\u2083 x, (nat.le_rec_on_trans h\u2081\u2082 h\u2082\u2083 x).symm\u27e9\n\nend algebraic_closure\n\n/-- The canonical algebraic closure of a field, the direct limit of adding roots to the field for\neach polynomial over the field. -/\ndef algebraic_closure : Type u :=\nring.direct_limit (algebraic_closure.step k) (\u03bb i j h, algebraic_closure.to_step_of_le k i j h)\n\nnamespace algebraic_closure\n\ninstance : field (algebraic_closure k) :=\nfield.direct_limit.field _ _\n\ninstance : inhabited (algebraic_closure k) := \u27e837\u27e9\n\n/-- The canonical ring embedding from the `n`th step to the algebraic closure. -/\ndef of_step (n : \u2115) : step k n \u2192+* algebraic_closure k :=\nring.direct_limit.of _ _ _\n\ninstance algebra_of_step (n) : algebra (step k n) (algebraic_closure k) :=\n(of_step k n).to_algebra\n\ntheorem of_step_succ (n : \u2115) : (of_step k (n + 1)).comp (to_step_succ k n) = of_step k n :=\nring_hom.ext $ \u03bb x, show ring.direct_limit.of (step k) (\u03bb i j h, to_step_of_le k i j h) _ _ = _,\n  by { convert ring.direct_limit.of_f n.le_succ x, ext x, exact (nat.le_rec_on_succ' x).symm }\n\ntheorem exists_of_step (z : algebraic_closure k) : \u2203 n x, of_step k n x = z :=\nring.direct_limit.exists_of z\n\n-- slow\ntheorem exists_root {f : polynomial (algebraic_closure k)}\n  (hfm : f.monic) (hfi : irreducible f) :\n  \u2203 x : algebraic_closure k, f.eval x = 0 :=\nbegin\n  have : \u2203 n p, polynomial.map (of_step k n) p = f,\n  { convert ring.direct_limit.polynomial.exists_of f },\n  unfreezingI { obtain \u27e8n, p, rfl\u27e9 := this },\n  rw monic_map_iff at hfm,\n  have := hfm.irreducible_of_irreducible_map (of_step k n) p hfi,\n  obtain \u27e8x, hx\u27e9 := to_step_succ.exists_root k hfm this,\n  refine \u27e8of_step k (n + 1) x, _\u27e9,\n  rw [\u2190 of_step_succ k n, eval_map, \u2190 hom_eval\u2082, hx, ring_hom.map_zero]\nend\n\ninstance : is_alg_closed (algebraic_closure k) :=\nis_alg_closed.of_exists_root _ $ \u03bb f, exists_root k\n\ninstance {R : Type*} [comm_semiring R] [alg : algebra R k] :\n  algebra R (algebraic_closure k) :=\n((of_step k 0).comp (@algebra_map _ _ _ _ alg)).to_algebra\n\nlemma algebra_map_def {R : Type*} [comm_semiring R] [alg : algebra R k] :\n  algebra_map R (algebraic_closure k) = ((of_step k 0 : k \u2192+* _).comp (@algebra_map _ _ _ _ alg)) :=\nrfl\n\ninstance {R S : Type*} [comm_semiring R] [comm_semiring S]\n  [algebra R S] [algebra S k] [algebra R k] [is_scalar_tower R S k] :\n  is_scalar_tower R S (algebraic_closure k) :=\nis_scalar_tower.of_algebra_map_eq (\u03bb x,\n  ring_hom.congr_arg _ (is_scalar_tower.algebra_map_apply R S k x : _))\n\n/-- Canonical algebra embedding from the `n`th step to the algebraic closure. -/\ndef of_step_hom (n) : step k n \u2192\u2090[k] algebraic_closure k :=\n{ commutes' := \u03bb x, ring.direct_limit.of_f n.zero_le x,\n  .. of_step k n }\n\ntheorem is_algebraic : algebra.is_algebraic k (algebraic_closure k) :=\n\u03bb z, is_algebraic_iff_is_integral.2 $ let \u27e8n, x, hx\u27e9 := exists_of_step k z in\nhx \u25b8 map_is_integral (of_step_hom k n) (step.is_integral k n x)\n\ninstance : is_alg_closure k (algebraic_closure k) :=\n\u27e8algebraic_closure.is_alg_closed k, is_algebraic k\u27e9\n\nend algebraic_closure\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/field_theory/is_alg_closed/algebraic_closure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7038045802743026}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Eric Wieser\n-/\n\nimport algebra.char_p.basic\nimport algebra.ring_quot\n\n/-!\n# Characteristic of quotients rings\n-/\n\nuniverses u v\n\nnamespace char_p\n\ntheorem quotient (R : Type u) [comm_ring R] (p : \u2115) [hp1 : fact p.prime] (hp2 : \u2191p \u2208 nonunits R) :\n  char_p (ideal.span {p} : ideal R).quotient p :=\nhave hp0 : (p : (ideal.span {p} : ideal R).quotient) = 0,\n  from (ideal.quotient.mk (ideal.span {p} : ideal R)).map_nat_cast p \u25b8\n    ideal.quotient.eq_zero_iff_mem.2 (ideal.subset_span $ set.mem_singleton _),\nring_char.of_eq $ or.resolve_left ((nat.dvd_prime hp1.1).1 $ ring_char.dvd hp0) $ \u03bb h1,\nhp2 $ is_unit_iff_dvd_one.2 $ ideal.mem_span_singleton.1 $ ideal.quotient.eq_zero_iff_mem.1 $\n@@subsingleton.elim (@@char_p.subsingleton _ $ ring_char.of_eq h1) _ _\n\n/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient\ninherits the characteristic of the underlying ring. -/\nlemma quotient' {R : Type*} [comm_ring R] (p : \u2115) [char_p R p] (I : ideal R)\n  (h : \u2200 x : \u2115, (x : R) \u2208 I \u2192 (x : R) = 0) :\n  char_p I.quotient p :=\n\u27e8\u03bb x, begin\n  rw [\u2190cast_eq_zero_iff R p x, \u2190(ideal.quotient.mk I).map_nat_cast],\n  refine quotient.eq'.trans (_ : \u2191x - 0 \u2208 I \u2194 _),\n  rw sub_zero,\n  exact \u27e8h x, \u03bb h', h'.symm \u25b8 I.zero_mem\u27e9,\nend\u27e9\n\nend char_p\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/char_p/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7905303162021597, "lm_q1q2_score": 0.7038045783902847}}
{"text": "import tuto_lib\n/-\nThis file continues the elementary study of limits of sequences. \nIt can be skipped if the previous file was too easy, it won't introduce\nany new tactic or trick.\n\nRemember useful lemmas:\n\nabs_le (x y : \u211d) : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nabs_add (x y : \u211d) : |x + y| \u2264 |x| + |y|\n\nabs_sub (x y : \u211d) : |x - y| = |y - x|\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\nand the definition:\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\nYou can also use a property proved in the previous file:\n\nunique_limit : seq_limit u l \u2192 seq_limit u l' \u2192 l = l'\n\ndef extraction (\u03c6 : \u2115 \u2192 \u2115) := \u2200 n m, n < m \u2192 \u03c6 n < \u03c6 m\n-/\n\n\nvariable { \u03c6 : \u2115 \u2192 \u2115}\n\n/-\nThe next lemma is proved by an easy induction, but we haven't seen induction\nin this tutorial. If you did the natural number game then you can delete \nthe proof below and try to reconstruct it.\n-/\n/-- An extraction is greater than id -/\nlemma id_le_extraction' : extraction \u03c6 \u2192 \u2200 n, n \u2264 \u03c6 n :=\nbegin\n  intros hyp n,\n  induction n with n hn,\n  { exact nat.zero_le _ },\n  { exact nat.succ_le_of_lt (by linarith [hyp n (n+1) (by linarith)]) },\nend\n\n/-- Extractions take arbitrarily large values for arbitrarily large \ninputs. -/\n-- 0039\nlemma extraction_ge : extraction \u03c6 \u2192 \u2200 N N', \u2203 n \u2265 N', \u03c6 n \u2265 N :=\nbegin\n  sorry\nend\n\n/-- A real number `a` is a cluster point of a sequence `u` \nif `u` has a subsequence converging to `a`. \n\ndef cluster_point (u : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2203 \u03c6, extraction \u03c6 \u2227 seq_limit (u \u2218 \u03c6) a\n-/\n\nvariables {u : \u2115 \u2192 \u211d} {a l : \u211d}\n\n/-\nIn the exercise, we use `\u2203 n \u2265 N, ...` which is the abbreviation of\n`\u2203 n, n \u2265 N \u2227 ...`.\nLean can read this abbreviation, but displays it as the confusing:\n`\u2203 (n : \u2115) (H : n \u2265 N)`\nOne gets used to it. Alternatively, one can get rid of it using the lemma\n  exists_prop {p q : Prop} : (\u2203 (h : p), q) \u2194 p \u2227 q\n-/\n\n/-- If `a` is a cluster point of `u` then there are values of\n`u` arbitrarily close to `a` for arbitrarily large input. -/\n-- 0040\nlemma near_cluster :\n  cluster_point u a \u2192 \u2200 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |u n - a| \u2264 \u03b5 :=\nbegin\n  sorry\nend\n\n/-\nThe above exercice can be done in five lines. \nHint: you can use the anonymous constructor syntax when proving\nexistential statements.\n-/\n\n/-- If `u` tends to `l` then its subsequences tend to `l`. -/\n-- 0041\nlemma subseq_tendsto_of_tendsto' (h : seq_limit u l) (h\u03c6 : extraction \u03c6) :\nseq_limit (u \u2218 \u03c6) l :=\nbegin\n  sorry\nend\n\n/-- If `u` tends to `l` all its cluster points are equal to `l`. -/\n-- 0042\nlemma cluster_limit (hl : seq_limit u l) (ha : cluster_point u a) : a = l :=\nbegin\n  sorry\nend\n\n/-- Cauchy_sequence sequence -/\ndef cauchy_sequence (u : \u2115 \u2192 \u211d) := \u2200 \u03b5 > 0, \u2203 N, \u2200 p q, p \u2265 N \u2192 q \u2265 N \u2192 |u p - u q| \u2264 \u03b5\n\n-- 0043\nexample : (\u2203 l, seq_limit u l) \u2192 cauchy_sequence u :=\nbegin\n  sorry\nend\n\n\n/- \nIn the next exercise, you can reuse\n near_cluster : cluster_point u a \u2192 \u2200 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |u n - a| \u2264 \u03b5\n-/\n-- 0044\nexample (hu : cauchy_sequence u) (hl : cluster_point u l) : seq_limit u l :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "kris-brown", "repo": "theorem_proving_in_lean", "sha": "774460c21bf857daff158210741bd88d1c8323cd", "save_path": "github-repos/lean/kris-brown-theorem_proving_in_lean", "path": "github-repos/lean/kris-brown-theorem_proving_in_lean/theorem_proving_in_lean-774460c21bf857daff158210741bd88d1c8323cd/tutorial_src/exercises/06_sub_sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7038045780774883}}
{"text": "import data.real.basic\n\nnoncomputable theory\n\n-- Ce fichier prolonge un travail de Fr\u00e9d\u00e9ric Le Roux qui a trait\u00e9 --\n-- des propri\u00e9t\u00e9s topologiques des espaces m\u00e9triques --\n\nopen set\nopen_locale classical\n\n-- Une structure d'espace pr\u00e9-m\u00e9trique sur un type X --\nclass espace_pre_metrique (X : Type*) :=\n(d : X \u2192 X \u2192 \u211d)\n(d_pos : \u2200 x y, d x y \u2265 0)\n(presep : \u2200 x y, x=y \u2192 d x y = 0)\n(sym : \u2200 x y, d x y = d y x)\n(triangle : \u2200 x y z, d x z \u2264 d x y + d y z)\n\n-- Une structure d'espace m\u00e9trique sur un type X --\nclass espace_metrique (X : Type*) :=\n(d : X \u2192 X \u2192 \u211d)\n(d_pos : \u2200 x y, d x y \u2265 0)\n(presep : \u2200 x y, x=y \u2192 d x y = 0)\n(sep : \u2200 x y, d x y = 0 \u2192  x = y)\n(sym : \u2200 x y, d x y = d y x)\n(triangle : \u2200 x y z, d x z \u2264 d x y + d y z)\n\n\nopen espace_metrique\n-- open espace_pre_metrique --\n\n/-- Instantiation des r\u00e9els comme espace m\u00e9trique. -/\ninstance real.metric_space : espace_metrique \u211d :=\n{ d                  := \u03bbx y, abs (x - y),\n  d_pos              := by simp [abs_nonneg],\n  presep             := begin simp, apply sub_eq_zero_of_eq end,\n  sep                := begin simp, apply eq_of_sub_eq_zero end,\n  sym                := assume x y, abs_sub _ _,\n  triangle           := assume x y z, abs_sub_le _ _ _ }\n\ntheorem real.dist_eq (x y : \u211d) : d x y = abs (x - y) := rfl\n\ntheorem real.dist_0_eq_abs (x : \u211d) : d x 0 = abs x :=\nby simp [real.dist_eq]", "meta": {"author": "RaitoBezarius", "repo": "projet-maths-lean", "sha": "42356e980e021a20c3468f5ca1639fec01bb934f", "save_path": "github-repos/lean/RaitoBezarius-projet-maths-lean", "path": "github-repos/lean/RaitoBezarius-projet-maths-lean/projet-maths-lean-42356e980e021a20c3468f5ca1639fec01bb934f/src/espaces-metriques/custom/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7038003265411452}}
{"text": "\n/-\nCopyright (c) 2022 Henrik B\u00f6ving. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henrik B\u00f6ving\n-/\n\nnamespace Cpdt\nnamespace Chapter3\n\ndef Bool.toProp : Bool \u2192 Prop := fun b => if b then True else False\ntheorem Bool.toProp_false : Bool.toProp false = False := by rfl\ntheorem Bool.toProp_true : Bool.toProp true = True := by rfl\n\ntheorem true_neq_false : true \u2260 false := by\n  intro h\n  rw [\u2190Bool.toProp_false]\n  rw [\u2190h]\n  rw [Bool.toProp_true]\n  exact True.intro\n\ntheorem s_inj : Nat.succ n = Nat.succ m \u2192 n = m := by\n  intro h\n  rw [\u2190Nat.pred_succ n]\n  rw [\u2190Nat.pred_succ m]\n  rw [h]\n\nend Chapter3\nend Cpdt\n", "meta": {"author": "hargoniX", "repo": "cpdt-lean", "sha": "65896137166a8ef74e816efc187346bc8f8bbd22", "save_path": "github-repos/lean/hargoniX-cpdt-lean", "path": "github-repos/lean/hargoniX-cpdt-lean/cpdt-lean-65896137166a8ef74e816efc187346bc8f8bbd22/Cpdt/Chapter3/ManualConstructors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.703800313124042}}
{"text": "import data.nat.prime\nimport data.nat.parity\nimport tactic\n\n\nexample (P : Prop) : \u00ac \u00ac \u00ac P \u2192 \u00ac P :=\nbegin\n  intros nnnp p, apply nnnp, \n  intro np, apply np, \n  apply p,\nend\n\n\nexample (p : \u2115) : p.prime \u2192 p = 2 \u2228 p % 2 = 1 :=\nbegin\n  library_search,\nend\n\n#check @nat.prime.eq_two_or_odd\n\nlemma eq_two_of_even_prime {p : \u2115} (hp : nat.prime p) (h_even : nat.even p) : p = 2 :=\nbegin\n  cases nat.prime.eq_two_or_odd hp, {assumption},\n  rw \u2190 nat.not_even_iff at h, contradiction,\nend\n\n\nlemma even_of_odd_add_odd\n  {a b : \u2115} (ha : \u00ac nat.even a) (hb : \u00ac nat.even b) :\nnat.even (a + b) :=\nbegin\n  rw nat.even_add, tauto,\nend\n\nlemma one_lt_of_nontrivial_factor \n  {b c : \u2115} (hb : b < b * c) :\n1 < c :=\nbegin\n  \n  rw \u2190 mul_one b at hb,\n  contrapose! hb, \n  suggest,\n  interval_cases c,\n  -- \u22a2 b * 0 \u2264 b\n  simp, \n  -- \u22a2 b * 1 \u2264 b\n  simp,\nend\nexample (n : \u2115) : 0 < n \u2194 n \u2260 0 :=\nbegin\n  split,\n  {intros, linarith,},\n  contrapose!,\n  simp,\nend\n\nlemma nontrivial_product_of_not_prime\n  {k : \u2115} (hk : \u00ac k.prime) (two_le_k : 2 \u2264 k) :\n\u2203 a b < k, 1 < a \u2227 1 < b \u2227 a * b = k :=\nbegin\n  have h1 := nat.exists_dvd_of_not_prime2 two_le_k hk,\n  rcases h1 with \u27e8a, \u27e8b, hb\u27e9, ha1, ha2\u27e9,\n  use [a, b], norm_num, \n  split, assumption,\n  split, rw [hb, lt_mul_iff_one_lt_left], linarith, \n  cases b, {linarith}, {simp},\n  split, linarith,\n  split, rw hb at ha2, apply one_lt_of_nontrivial_factor ha2,\n  rw hb,\nend\n\n-- norm_num, linarith\ntheorem three_fac_of_sum_consecutive_primes \n  {p q : \u2115} (hp : p.prime) (hq : q.prime) (hpq : p < q) \n  (p_ne_2 : p \u2260 2) (q_ne_2 : q \u2260 2)\n  (consecutive : \u2200 k, p < k \u2192 k < q \u2192 \u00ac k.prime) :\n\u2203 a b c, p + q = a * b * c \u2227 a > 1 \u2227 b > 1 \u2227 c > 1 :=\nbegin\n  use 2, have h1 : nat.even (p + q), \n  { apply even_of_odd_add_odd, \n    contrapose! p_ne_2, apply eq_two_of_even_prime; assumption, \n    contrapose! q_ne_2, apply eq_two_of_even_prime; assumption, },\n\n  cases h1 with k hk, \n  have hk' : \u00ac k.prime, \n  { apply consecutive; linarith },\n\n  have h2k : 2 \u2264 k, { have := nat.prime.two_le hp, linarith, },\n  have h2 := nat.exists_dvd_of_not_prime2 _ hk',\n  swap, { exact h2k }, -- for some reason I think it's interesting to have the student remember that they've already proved this\n  rcases nontrivial_product_of_not_prime hk' h2k with \u27e8 b, c, hbk, hck, hb1, hc1, hbc\u27e9,\n  use [b,c],\n  split, { rw [hk, \u2190 hbc], ring },\n  split, { norm_num },\n  split; assumption,\nend", "meta": {"author": "jalex-stark", "repo": "lean-at-MC2020", "sha": "6d1854db40c80730118803f6007d1cc3596c3075", "save_path": "github-repos/lean/jalex-stark-lean-at-MC2020", "path": "github-repos/lean/jalex-stark-lean-at-MC2020/lean-at-MC2020-6d1854db40c80730118803f6007d1cc3596c3075/_sources/source/solutions/exercise_prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7037767625820007}}
{"text": "/-\nDefine eigenvalues and eigenspaces of matrices and prove new theorems about them. \n-/\n\nimport data.matrix.basic\nimport tactic\nimport linear_algebra.determinant\nimport .algebraically_closed\nimport linear_algebra.nonsingular_inverse\nimport linear_algebra.char_poly\n\nnoncomputable theory\nopen matrix \nopen_locale matrix\nopen_locale classical\n\n-- comm_semiring = semiring \u03b1, comm_monoid \u03b1\n-- comm_ring = ring + semigroup\n-- semiring = add_comm_monoid \u03b1, monoid_with_zero \u03b1, distrib \u03b1 \n\nuniverses u \n\nvariables {S : Type*} [semiring S]\nvariables {R : Type*} [ring R]\nvariables {k : Type*} [field k]\nvariables {l m n o : Type*} [fintype l] [fintype m] [fintype n] [fintype o]\n\nnamespace matrix\n\ndef eigenvector (M : matrix n n S) : (n \u2192 S) \u2192 Prop := \n\u03bb v, \u2203 c : S, v \u2260 0 \u2227 M.mul_vec v = (c \u2022 (1 : matrix n n S)).mul_vec v\n\ndef eigenvalue (M : matrix n n S) : S \u2192 Prop := \n\u03bb c, \u2203 v : n \u2192 S, v \u2260 0 \u2227 M.mul_vec v = (c \u2022 (1 : matrix n n S)).mul_vec v\n\ndef eigenvalue_of_eigenvector {M : matrix n n S} {v : n \u2192 S} \n(hc : eigenvector M v) : S := \nbegin \n  choose c key using hc,\n  exact c,\nend \n\ndef eigenspace (M : matrix n n S) (c : S) : set (n \u2192 S) :=\n{v | v = 0 \u2228 ((eigenvector M v) \u2227 M.mul_vec v = (c \u2022 (1 : matrix n n S)).mul_vec v) }\n\ndef spectrum (M : matrix n n S) : set S :=\n{c | eigenvalue M c}\n\n-- def generalized_eigenspace (M : matrix n n R) (c : R) : set (n \u2192 R) :=\n-- {v | \u2203 k : \u2115, (M - c \u2022 1)^k.mul_vec v = 0}\n-- end matrix\nend matrix \n\ninstance (M : matrix n n S) (c : S) : add_comm_monoid (matrix.eigenspace M c) := \n{ add := sorry,\n  add_assoc := sorry,\n  zero := sorry,\n  zero_add := sorry,\n  add_zero := sorry,\n  add_comm := sorry }\n\ninstance (M : matrix n n S) (c : S) : semimodule S (matrix.eigenspace M c) := \n{ smul := sorry,\n  one_smul := sorry,\n  mul_smul := sorry,\n  smul_add := sorry,\n  smul_zero := sorry,\n  add_smul := sorry,\n  zero_smul := sorry }\n\n#check mul_vec \n\nlemma det_zero_iff_sing {M : matrix n n k} :\n  M.det = 0 \u2194 \u2203 v : n \u2192 k, v \u2260 0 \u2227 M.mul_vec v = 0 := \nbegin \nrepeat{sorry,},\nend\n\nlemma eigenvalue_det {M : matrix n n k} {c : k} :\n  (M - c \u2022 1).det = 0 \u2194 M.eigenvalue c := \nbegin \n  sorry,\nend \n\n#check mul_nonsing_inv\n\ntheorem exists_eigenvalue (M : matrix n n \u2102) : (\u2203 c : \u2102, matrix.eigenvalue M c) :=\nbegin \n  let k:= \u2102,\n  suffices : \u2203 c : k, (M - c \u2022 1).det = 0, by sorry,\n  set f := char_poly M,\n  have hf_deg : 0 < f.degree, by sorry,\n  sorry,\nend\n\n#check exists_eigenvalue", "meta": {"author": "apurvanakade", "repo": "mc2020-lean-projects", "sha": "02466225aa629ab1232043bcc0a053a099fdb939", "save_path": "github-repos/lean/apurvanakade-mc2020-lean-projects", "path": "github-repos/lean/apurvanakade-mc2020-lean-projects/mc2020-lean-projects-02466225aa629ab1232043bcc0a053a099fdb939/src/apurva/eigenvalues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.7037767575618439}}
{"text": "-- Lucas Moschen\n-- Teorema de Cantor\n\nimport data.set\n\nvariables X Y: Type \n\ndef surjective {X: Type} {Y: Type} (f : X \u2192 Y) : Prop := \u2200 y, \u2203 x, f x = y\n\ntheorem Cantor : \u2200 (A: set X), \u00ac \u2203 (f: A \u2192 set A),  surjective f :=\n\n    begin\n        intro A,\n        intro h,\n        cases h with f h1,\n        have h2: \u2203 x, f x = {t : A | \u00ac (t \u2208 f t)}, from h1 {t : A | \u00ac (t \u2208 f t)},\n        cases h2 with x h3,\n        apply or.elim (classical.em (x \u2208 {t : A | \u00ac (t \u2208 f t)})),\n            intro h4,\n                have h5: \u00ac (x \u2208 f x), from h4,\n                rw (eq.symm h3) at h4, \n                apply h5 h4,\n            intro h4,\n                rw (eq.symm h3) at h4,\n                have h5: x \u2208 {t : A | \u00ac (t \u2208 f t)}, from h4,\n                rw (eq.symm h3) at h5,\n                apply h4 h5,                     \n    end", "meta": {"author": "lucasmoschen", "repo": "discrete-mathematics", "sha": "0f1945cc5eb094814c926cd6ae4a8b4c5c579a1e", "save_path": "github-repos/lean/lucasmoschen-discrete-mathematics", "path": "github-repos/lean/lucasmoschen-discrete-mathematics/discrete-mathematics-0f1945cc5eb094814c926cd6ae4a8b4c5c579a1e/Exercises/Lista6-LucasMoschen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474181553805, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.7037261422381326}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\n\nimport ring_theory.ideal.operations\nimport linear_algebra.finsupp_vector_space\nimport algebra.char_p.basic\n\n/-!\n# Multivariate polynomials over commutative rings\n\nThis file contains basic facts about multivariate polynomials over commutative rings, for example\nthat the monomials form a basis.\n\n## Main definitions\n\n* `restrict_total_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` of total degree at most `m`.\n* `restrict_degree \u03c3 R m`: the subspace of multivariate polynomials indexed by `\u03c3` over the\n  commutative ring `R` such that the degree in each individual variable is at most `m`.\n\n## Main statements\n\n* The multivariate polynomial ring over a commutative ring of positive characteristic has positive\n  characteristic.\n* `is_basis_monomials`: shows that the monomials form a basis of the vector space of multivariate\n  polynomials.\n\n## TODO\n\nGeneralise to noncommutative (semi)rings\n-/\n\nnoncomputable theory\n\nopen_locale classical\n\nopen set linear_map submodule\nopen_locale big_operators\n\nuniverses u v\nvariables (\u03c3 : Type u) (R : Type v) [comm_ring R] (p m : \u2115)\n\nnamespace mv_polynomial\n\nsection char_p\n\ninstance [char_p R p] : char_p (mv_polynomial \u03c3 R) p :=\n{ cast_eq_zero_iff := \u03bb n, by rw [\u2190 C_eq_coe_nat, \u2190 C_0, C_inj, char_p.cast_eq_zero_iff R p] }\n\nend char_p\n\nsection homomorphism\n\nlemma map_range_eq_map {R S : Type*} [comm_ring R] [comm_ring S] (p : mv_polynomial \u03c3 R)\n  (f : R \u2192+* S) :\n  finsupp.map_range f f.map_zero p = map f p :=\nbegin\n  rw [\u2190 finsupp.sum_single p, finsupp.sum],\n  -- It's not great that we need to use an `erw` here,\n  -- but hopefully it will become smoother when we move entirely away from `is_semiring_hom`.\n  erw [finsupp.map_range_finset_sum (f : R \u2192+ S)],\n  rw [\u2190 (finsupp.support p).sum_hom (map f)],\n  { refine finset.sum_congr rfl (assume n _, _),\n    rw [finsupp.map_range_single, \u2190 monomial, \u2190 monomial, map_monomial], refl, },\n  apply_instance\nend\n\nend homomorphism\n\nsection degree\n\n/-- The submodule of polynomials of total degree less than or equal to `m`.-/\ndef restrict_total_degree : submodule R (mv_polynomial \u03c3 R) :=\nfinsupp.supported _ _ {n | n.sum (\u03bbn e, e) \u2264 m }\n\n/-- The submodule of polynomials such that the degree with respect to each individual variable is\nless than or equal to `m`.-/\ndef restrict_degree (m : \u2115) : submodule R (mv_polynomial \u03c3 R) :=\nfinsupp.supported _ _ {n | \u2200i, n i \u2264 m }\n\nvariable {R}\n\nlemma mem_restrict_total_degree (p : mv_polynomial \u03c3 R) :\n  p \u2208 restrict_total_degree \u03c3 R m \u2194 p.total_degree \u2264 m :=\nbegin\n  rw [total_degree, finset.sup_le_iff],\n  refl\nend\n\nlemma mem_restrict_degree (p : mv_polynomial \u03c3 R) (n : \u2115) :\n  p \u2208 restrict_degree \u03c3 R n \u2194 (\u2200s \u2208 p.support, \u2200i, (s : \u03c3 \u2192\u2080 \u2115) i \u2264 n) :=\nbegin\n  rw [restrict_degree, finsupp.mem_supported],\n  refl\nend\n\nlemma mem_restrict_degree_iff_sup (p : mv_polynomial \u03c3 R) (n : \u2115) :\n  p \u2208 restrict_degree \u03c3 R n \u2194 \u2200i, p.degrees.count i \u2264 n :=\nbegin\n  simp only [mem_restrict_degree, degrees, multiset.count_sup, finsupp.count_to_multiset,\n    finset.sup_le_iff],\n  exact \u27e8assume h n s hs, h s hs n, assume h s hs n, h n s hs\u27e9\nend\n\nvariables (\u03c3 R)\n\nlemma is_basis_monomials :\n  is_basis R ((\u03bbs, (monomial s 1 : mv_polynomial \u03c3 R))) :=\nsuffices is_basis R (\u03bb (sa : \u03a3 _, unit), (monomial sa.1 1 : mv_polynomial \u03c3 R)),\nbegin\n  apply is_basis.comp this (\u03bb (s : \u03c3 \u2192\u2080 \u2115), \u27e8s, punit.star\u27e9),\n  split,\n  { intros x y hxy,\n    simpa using hxy },\n  { rintros \u27e8x\u2081, x\u2082\u27e9,\n    use x\u2081,\n    rw punit_eq punit.star x\u2082 }\nend,\nbegin\n  apply finsupp.is_basis_single (\u03bb _ _, (1 : R)),\n  intro _,\n  apply is_basis_singleton_one,\nend\n\nend degree\n\nend mv_polynomial\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/mv_polynomial/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7037085790342742}}
{"text": "import tactic\n\nopen set\n\n\nstructure topological_space (X : Type) :=\n(is_open : set X \u2192 Prop)\n(is_open_univ : is_open (univ : set X))\n(is_open_inter : \u2200(U V : set X), is_open U \u2192 is_open V \u2192 is_open (U \u2229 V))\n(is_open_union : \u2200s, (\u2200t\u2208s, is_open t) \u2192 is_open \u22c3\u2080 s)\n\nattribute [class] topological_space\ndef is_open {X : Type} [t : topological_space X] (U : set X) := topological_space.is_open t U\n\nvariables {X Y E B: Type} [topological_space X] [topological_space Y]\n[topological_space E] [topological_space B]\n\ndef is_continuous (f : X \u2192 Y) : Prop := \u2200{V : set Y} (hV : is_open V), is_open (f\u207b\u00b9' V)\ndef is_hausdorff (Z : Type) [topological_space Z] : Prop := \u2200{x y : Z}, x \u2260 y \u2192 \n\u2203(U V : set Z) (hU : is_open U) (hV : is_open V) (hUx : x \u2208 U) (hVy : y \u2208 V),\nU \u2229 V = \u2205\ndef is_dense (D : set X) : Prop := \u2200{U : set X}(U_open : is_open U) (U_nonempty : U \u2260 \u2205),\n\u2203(d \u2208 D), d \u2208 U \n\nlemma eq_of_agree_on_dense {f g : X \u2192 Y} (hY : is_hausdorff Y) (hf : is_continuous f)\n(hg : is_continuous g) {D : set X} (D_dense : is_dense D)\n(hfg : \u2200{d}, d \u2208 D \u2192 f d = g d) : f = g :=\nbegin\n\t-- Assume for contradiction that f(x) \u2260 g(x) for some x \u2208 X.\n\text,\n\tby_contra,\n\t-- Fix disjoint open neighborhoods U and V around f(x) and g(x) respectively.\n\trcases hY h with \u27e8U, V, U_open, V_open, hxU, hxV, hUV\u27e9,\n\n\t-- By continuity, f\u207b\u00b9(U) and g\u207b\u00b9(V) are both open,\n\thave U_inv_open := hf U_open,\n\thave V_inv_open := hg V_open,\n\n\t-- which means their intersection must also be open.\n\thave  UV_inv_open := _inst_1.is_open_inter (f \u207b\u00b9' U) (g \u207b\u00b9' V) U_inv_open V_inv_open,\n\t-- It is also nonempty, since it contains x.\n\thave UV_nonempty : (f \u207b\u00b9' U \u2229 g \u207b\u00b9' V) \u2260 \u2205 := \u03bbcontra,\n\teq_empty_iff_forall_not_mem.mp contra x \u27e8hxU, hxV\u27e9,\n\n\t-- Hence there is some d \u2208 D with d \u2208 f\u207b\u00b9(U) \u2229 g\u207b\u00b9(V).\n\trcases D_dense UV_inv_open UV_nonempty with \u27e8d, d_D, d_inter\u27e9,\n\n\t-- Thus f(d) \u2208 U and g(d) \u2208 V.\n\trw mem_inter_iff at d_inter,\n\thave hfd : f d \u2208 U := d_inter.1,\n\thave hgd : g d \u2208 V := d_inter.2,\n\n\t-- But f(d) = g(d),\n\trw\u2190 hfg d_D at hgd,\n\t-- so f(d) \u2208 U \u2229 V = \u2205,\n\thave contra : f d \u2208 U \u2229 V := \u27e8hfd, hgd\u27e9,\n\t-- which is a contradiction.\n\trw hUV at contra,\n\texact not_mem_empty (f d) contra,\nend\n\nvariables {f : X \u2192 Y} {hf : is_continuous f}\n\ndef converges_to (a : \u2115 \u2192 X) (L : X) : Prop := \n\u2200{U : set X} (hU : is_open U) (hUL : L \u2208 U), \u2203(N : \u2115), \u2200{n : \u2115}, n \u2265 N \u2192 a n \u2208 U \n\nlemma converges_unique_of_hausdorff {a : \u2115 \u2192 X} {L M : X} (hX : is_hausdorff X) \n(hL : converges_to a L) (hM : converges_to a M) : L = M :=\nbegin \n\tby_cases h : L = M, {exact h}, exfalso,\n\n\trcases hX h with \u27e8U, V, hU, hV, hUx, hVy, hUV\u27e9,\n\trcases hL hU hUx with \u27e8N, hN\u27e9,\n\trcases hM hV hVy with \u27e8M, hM\u27e9,\n\n\thave hcontra1 := hN (le_max_left N M),\n\thave hcontra2 := hM (le_max_right N M),\n\thave hcontra : a (max N M) \u2208 (U \u2229 V) := \u27e8hcontra1, hcontra2\u27e9,\n\t\n\tfinish,\nend\n\nlemma converges_of_continuous {a : \u2115 \u2192 X} {L : X} (hL : converges_to a L) {f : X \u2192 Y} \n(hf : is_continuous f) : converges_to (f\u2218a) (f L) :=\nbegin \n\tintros U hU hUL,\n\thave hU' := hf hU,\n\tcases hL hU' hUL with N hN,\n\tuse N,\n\tfinish,\nend\n\n\nstructure continuous_map (A : Type) (B : Type)\n[topological_space A] [topological_space B] :=\n(f : A \u2192 B)\n(f_continuous : is_continuous f)\n\nstructure homeomorphism :=\n(map : continuous_map X Y)\n(is_bijection : function.bijective map.f)\n\ndef maps_homeomorphically (p : E \u2192 B) (U : set E) := (restrict p U)", "meta": {"author": "duduFreire", "repo": "metric_spaces", "sha": "a3a489401b430f6b131771f6eb5bfd02ed649736", "save_path": "github-repos/lean/duduFreire-metric_spaces", "path": "github-repos/lean/duduFreire-metric_spaces/metric_spaces-a3a489401b430f6b131771f6eb5bfd02ed649736/src/topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7037085638980319}}
{"text": "import tactic\n\n-- Exercise 1\n\n-- (a)\nvariables p q : Prop\nvariable given1 : (p \u2227 q)\nexample : p :=\nshow p, from and.left given1\n\n-- (b)\n--example : (p \u2227 q \u2192 p) :=\n--assume h1 : (p \u2227 q),\n--show p, from and.left h1\n\n-- (c)\nexample : p \u2192 (q \u2192 p) :=\nbegin\n  assume h1,\n  assume h2,\n  exact h1, \nend\n\n-- (d)\nexample: p \u2192 (q \u2192 p \u2227 q) :=  \nbegin\n  assume h1,\n  assume h2,\n  split,\n  exact h1,\n  exact h2,\nend\n-- (f)\nvariable r : Prop\nexample : (p \u2192 (q \u2192 r)) \u2192 ((p \u2192 q) \u2192 (p \u2192 r)) :=\nbegin\n  assume h1: p \u2192 (q \u2192 r),\n  assume h2: p \u2192 q,\n  assume h3: p,\n  apply h1,\n  exact h3,\n  apply h2,\n  exact h3,\n\nend\n-- (e)\nexample : (p \u2192 (q \u2192 r)) \u2192 (p \u2227 q \u2192 r) :=\nbegin\n  assume h1,\n  assume h2: p \u2227 q,\n  cases h2 with h3 h4,\n  apply h1,\n  exact h3,\n  exact h4,\n  \nend\n\n-- (g)\nexample : ((p \u2227 q) \u2192 r) \u2192 (p \u2192 (q \u2192 r)) :=\nbegin\n  intro h1,\n  intro h2,\n  intro h3,\n  apply h1,\n  split,\n  exact h2,\n  exact h3,\n\nend\n\n-- (h)\nexample : (p \u2227 q) \u2192 (p \u2228 q) :=\nbegin\n  intro h1,\n  cases h1 with h2 h3,\n  left,\n  exact h2,\n\nend\n\n-- (i)\nexample : p \u2192 (q \u2192 p) :=\nbegin\n  intro h1,\n  intro h2,\n  exact h1,\n\nend\n\n-- (j)\nexample : p \u2227 (q \u2228 (p \u2192 q)) \u2192 p \u2227 q := \nbegin\n  intro h1,\n  cases h1 with h2 h3,\n  split,\n  exact h2,\n  cases h3 with h4 h5,\n  exact h4,\n  apply h5,\n  exact h2,\n\nend\n\n-- 2. \n-- (a)\nexample : p \u2227 (p \u2192 q) \u2192 p \u2227 q :=\nbegin\n  intro h1,\n  cases h1 with h1 h2,\n  split,\n  exact h1,\n  apply h2,\n  exact h1,\n\nend\n\n\n-- (b)\nexample : (q \u2192 r) \u2192 ((p \u2192 q) \u2192 (p \u2192 r)) :=\nbegin\n  intro h1,\n  intro h2,\n  intro h3,\n  apply h1,\n  apply h2,\n  exact h3,\n\nend\n\n-- (c)\nexample : (p \u2227 (q \u2228 r)) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  intro h1,\n  cases h1 with h1 h2,\n  cases h2 with h2 h3,\n  left,\n  split,\n  exact h1,\n  exact h2,\n  right,\n  split,\n  exact h1,\n  exact h3,\n\nend\n\n-- (d)\nexample : (\u00ac p \u2227 (p \u2228 q)) \u2192 q := \nbegin\n  intro h1,\n  cases h1 with h1 h2,\n  cases h2 with h2 h3,\n  exfalso,\n  show false, from h1 h2,\n  exact h3,\n\nend\n\n-- (f)\nexample : (\u00ac (p \u2228 q)) \u2192 (\u00ac p \u2227 \u00ac q) :=\nbegin\n  intro h1,\n  split,\n  push_neg at h1,\n  show \u00ac p, from and.left h1,\n  push_neg at h1, \n  show \u00ac q, from and.right h1,\n\nend\n\naxiom lawOfExcludedMiddle :  p \u2228 \u00ac p \u2192 true\naxiom pAndNotPImpF :  q \u2227 \u00ac q -> false\n-- (g)\nexample : (p \u2192 q) \u2192 (\u00ac q \u2192 \u00ac p) := \nbegin \n  intro h1,\n  intro h2,\n  assume (hp : p),\n  have hq : q, from h1 hp,\n  have hf : q \u2227 \u00ac q, from and.intro hq h2,\n  show false, from pAndNotPImpF hf,\n  \nend\n\n-- The following code defines useful tools that we defined in Nat. deduction.\nexample (hp : p) (hq : q) : p \u2227 q := and.intro hp hq\n\n#check assume (hp : p) (hq : q), and.intro hp hq\n\n\n\n\n\n\n\n", "meta": {"author": "SzymonKubica", "repo": "Lean", "sha": "627bff2f001ba3f009c112c9332093e8de84863c", "save_path": "github-repos/lean/SzymonKubica-Lean", "path": "github-repos/lean/SzymonKubica-Lean/Lean-627bff2f001ba3f009c112c9332093e8de84863c/NatDeduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.703671520156009}}
{"text": "import game.world10.level1 -- hide\nnamespace mynat -- hide\n/- \n\n# Inequality world. \n\nHere's a nice easy one.\n\n## Level 2: le_refl \n-/\n/- Lemma : \nThe $\\le$ relation is reflexive. In other words, if $x$ is a natural number,\nthen $x\\le x$.\n-/\nlemma le_refl (x : mynat) : x \u2264 x :=\nbegin [nat_num_game]\n  use 0,\n  rw add_zero,\n  refl,\n\n\nend \n/-\n## Upgrading the `refl` tactic \n\nNow with the following incantation (NB thanks to master wizard Reid Barton\nfor correcting my spell)...\n-/\nattribute [refl] mynat.le_refl\n/-\n...we find that the `refl` tactic will close all goals\nof the form `a \u2264 a` as well as all goals of the form `a = a`.\n-/\nexample : (0 : mynat) \u2264 0 := begin\n  refl\nend\n\n/-\n## Pro tip\n\nDid you skip `rw le_iff_exists_add` in your proof of `le_refl` above?\nInstead of `rw add_zero` or `ring` or `exact add_zero x` at the end there,\nwhat happens if you just try `refl`? The *definition* of `x + 0` is `x`,\nso you don't need to `rw add_zero` either! The proof\n\n```\nuse 0,\nrefl,\n```\n\nworks.\n\nThe same remarks are true of\n`add_succ`, `mul_zero`, `mul_succ`, `pow_zero` and `pow_succ`. All of those\ntheorems are true *by definition*. The same is *not* true however of `zero_add`; \nthe theorem `0 + x = x` was proved by induction on `x`,\nand in particular it is not true by *definition*.\n\nDefinitional equality is of great importance\nto computer scientists, but mathematicians are much more fluid with their idea\nof a definition -- a concept can simultaneously have three equivalent definitions\nin a maths talk, as long as they're all logically equivalent. In Lean, a definition\nis *one thing*, and definitional equality is a subtle concept which depends on\nexactly which definition you chose. `add_comm` is certainly not true by definition,\nwhich means that if we had decided to define `a \u2264 b` by `\u2203 c, b = c + a` (rather\nthan `a + c`) all the same theorems would be true, but `refl` would work in\ndifferent places. `refl` closes a goal of the form `X = Y` if `X` and `Y` are\ndefinitionally equal.\n-/\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world10/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7036715043353207}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.real.basic\nimport data.set.basic\nimport data.set.finite\n\n/-!\n# IMO 2008 Q2\n(a) Prove that\n          ```\n          x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 \u2265 1\n          ```\nfor all real numbers `x`,`y`, `z`, each different from 1, and satisfying `xyz = 1`.\n\n(b) Prove that equality holds above for infinitely many triples of rational numbers `x`, `y`, `z`,\neach different from 1, and satisfying `xyz = 1`.\n\n# Solution\n(a) Since `xyz = 1`, we can apply the substitution `x = a/b`, `y = b/c`, `z = c/a`.\nThen we define `m = c-b`, `n = b-a` and rewrite the inequality as `LHS - 1 \u2265 0`\nusing `c`, `m` and `n`. We factor `LHS - 1` as a square, which finishes the proof.\n\n(b) We present a set `W` of rational triples. We prove that `W` is a subset of the\nset of rational solutions to the equation, and that `W` is infinite.\n-/\n\nlemma subst_abc {x y z : \u211d} (h : x*y*z = 1) :\n  \u2203 a b c : \u211d, a \u2260 0 \u2227 b \u2260 0 \u2227 c \u2260 0 \u2227 x = a/b \u2227 y = b/c \u2227 z = c /a :=\nbegin\n  use [x, 1, 1/y],\n  have h\u2081 : x \u2260 0 := left_ne_zero_of_mul (left_ne_zero_of_mul_eq_one h),\n  have h\u2082 : (1 : \u211d) \u2260 (0 : \u211d) := one_ne_zero,\n  have hy_ne_zero : y \u2260 0 := right_ne_zero_of_mul (left_ne_zero_of_mul_eq_one h),\n  have h\u2083 : 1/y \u2260 0 := one_div_ne_zero hy_ne_zero,\n  have h\u2084 : x = x / 1 := (div_one x).symm,\n  have h\u2085 : y = 1 / (1 / y) := (one_div_one_div y).symm,\n  have h\u2086 : z = 1 / y / x, { field_simp, linarith [h] },\n  exact \u27e8h\u2081, h\u2082, h\u2083, h\u2084, h\u2085, h\u2086\u27e9,\nend\n\ntheorem imo2008_q2a (x y z : \u211d) (h : x*y*z = 1) (hx : x \u2260 1) (hy : y \u2260 1) (hz : z \u2260 1) :\n  x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 \u2265 1 :=\nbegin\n  obtain \u27e8a, b, c, ha, hb, hc, hx\u2082, hy\u2082, hz\u2082\u27e9 := subst_abc h,\n\n  set m := c-b with hm_abc,\n  set n := b-a with hn_abc,\n  have ha_cmn : a = c - m - n,      { linarith },\n  have hb_cmn : b = c - m,          { linarith },\n  have hab_mn : (a-b)^2 = n^2,      { rw [ha_cmn, hb_cmn], ring },\n  have hbc_mn : (b-c)^2 = m^2,      { rw hb_cmn, ring },\n  have hca_mn : (c-a)^2 = (m+n)^2,  { rw ha_cmn, ring },\n\n  have hm_ne_zero : m \u2260 0,\n  { rw hm_abc, rw hy\u2082 at hy, intro p, apply hy, field_simp, linarith },\n\n  have hn_ne_zero : n \u2260 0,\n  { rw hn_abc, rw hx\u2082 at hx, intro p, apply hx, field_simp, linarith },\n\n  have hmn_ne_zero : m + n \u2260 0,\n  { rw hm_abc, rw hn_abc, rw hz\u2082 at hz, intro p, apply hz, field_simp, linarith },\n\n  have key : x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 - 1 \u2265 0,\n  { calc  x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 - 1\n        = (a/b)^2 / (a/b-1)^2 + (b/c)^2 / (b/c-1)^2 + (c/a)^2 / (c/a-1)^2 - 1 :\n          by rw [hx\u2082, hy\u2082, hz\u2082]\n    ... = a^2/(a-b)^2 + b^2/(b-c)^2 + c^2/(c-a)^2 - 1 :\n          by field_simp [div_sub_one hb, div_sub_one hc, div_sub_one ha]\n    ... = (c-m-n)^2/n^2 + (c-m)^2/m^2 + c^2/(m+n)^2 - 1 :\n          by rw [hab_mn, hbc_mn, hca_mn, ha_cmn, hb_cmn]\n    ... = ( (c*(m^2+n^2+m*n) - m*(m+n)^2) / (m*n*(m+n)) )^2 :\n          by { ring_nf, field_simp, ring }\n    ... \u2265 0 :\n          sq_nonneg _ },\n\n\n  linarith [key],\nend\n\ndef rational_solutions := { s : \u211a\u00d7\u211a\u00d7\u211a | \u2203 (x y z : \u211a), s = (x, y, z) \u2227\n  x \u2260 1 \u2227 y \u2260 1 \u2227 z \u2260 1 \u2227 x*y*z = 1 \u2227 x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1 }\n\ntheorem imo2008_q2b : set.infinite rational_solutions :=\nbegin\n  let W := { s : \u211a\u00d7\u211a\u00d7\u211a | \u2203 (x y z : \u211a), s = (x, y, z) \u2227\n    \u2203 t : \u211a, t > 0 \u2227 x = -(t+1)/t^2 \u2227 y = t/(t+1)^2 \u2227 z = -t*(t+1)},\n\n  have hW_sub_S : W \u2286 rational_solutions,\n  { intros s hs_in_W,\n    rw rational_solutions,\n    simp only [set.mem_set_of_eq] at hs_in_W \u22a2,\n    rcases hs_in_W with \u27e8x, y, z, h\u2081, t, ht_gt_zero, hx_t, hy_t, hz_t\u27e9,\n    use [x, y, z],\n\n    have ht_ne_zero  : t \u2260 0,           exact ne_of_gt ht_gt_zero,\n    have ht1_ne_zero : t+1 \u2260 0,         linarith[ht_gt_zero],\n    have key_gt_zero : t^2 + t + 1 > 0, linarith[pow_pos ht_gt_zero 2, ht_gt_zero],\n    have key_ne_zero : t^2 + t + 1 \u2260 0, exact ne_of_gt key_gt_zero,\n\n    have h\u2082 : x \u2260 1,      { rw hx_t, field_simp, linarith[key_gt_zero] },\n    have h\u2083 : y \u2260 1,      { rw hy_t, field_simp, linarith[key_gt_zero] },\n    have h\u2084 : z \u2260 1,      { rw hz_t, linarith[key_gt_zero] },\n    have h\u2085 : x*y*z = 1,  { rw [hx_t, hy_t, hz_t], field_simp, ring },\n\n    have h\u2086 : x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1,\n    { have hx1 : (x - 1)^2 = (t^2 + t + 1)^2/t^4,     { field_simp, rw hx_t, field_simp, ring },\n      have hy1 : (y - 1)^2 = (t^2 + t + 1)^2/(t+1)^4, { field_simp, rw hy_t, field_simp, ring },\n      have hz1 : (z - 1)^2 = (t^2 + t + 1)^2,         { rw hz_t, ring },\n      calc  x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2\n          = (x^2*t^4 + y^2*(t+1)^4 + z^2)/(t^2 + t + 1)^2 :\n            by { rw [hx1, hy1, hz1], field_simp }\n      ... = 1 :\n            by { rw [hx_t, hy_t, hz_t], field_simp, ring } },\n\n    exact \u27e8h\u2081, h\u2082, h\u2083, h\u2084, h\u2085, h\u2086\u27e9 },\n\n  have hW_inf : set.infinite W,\n  { let g : \u211a\u00d7\u211a\u00d7\u211a \u2192 \u211a := (\u03bbs, -s.2.2),\n    let K := g '' W,\n\n    have hK_not_bdd : \u00acbdd_above K,\n    { rw not_bdd_above_iff,\n      intro q,\n      let t : \u211a := max (q+1) 1,\n      use t*(t+1),\n\n      have h\u2081 : t * (t + 1) \u2208 K,\n      { let x : \u211a := -(t + 1)/t^2,\n        let y : \u211a := t/(t+1)^2,\n        set z : \u211a := -t*(t+1) with hz_def,\n\n        simp only [set.mem_image, prod.exists],\n        use [x, y, z], split,\n        simp only [set.mem_set_of_eq],\n        { use [x, y, z], split,\n          refl,\n          { use t, split,\n            { simp only [gt_iff_lt, lt_max_iff], right, exact zero_lt_one },\n            exact \u27e8rfl, rfl, rfl\u27e9 } },\n        { have hg : g(x, y, z) = -z := rfl,\n          rw [hg, hz_def], ring } },\n\n      have h\u2082 : q < t * (t + 1),\n      { calc q < q + 1    : by linarith\n           ... \u2264 t        : le_max_left (q + 1) 1\n           ... \u2264 t+t^2    : by linarith [sq_nonneg t]\n           ... = t*(t+1)  : by ring },\n\n      exact \u27e8h\u2081, h\u2082\u27e9 },\n\n    have hK_inf : set.infinite K,\n    { intro h, apply hK_not_bdd, exact set.finite.bdd_above h },\n\n    exact set.infinite_of_infinite_image g hK_inf },\n\n  exact set.infinite_mono hW_sub_S hW_inf,\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/imo/imo2008_q2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.703671502117917}}
{"text": "/-\nCopyright (c) 2020 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Bhavik Mehta\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.order.basic\nimport Mathlib.order.preorder_hom\nimport Mathlib.order.galois_connection\nimport Mathlib.tactic.monotonicity.default\nimport Mathlib.PostPort\n\nuniverses u l \n\nnamespace Mathlib\n\n/-!\n# Closure operators on a partial order\n\nWe define (bundled) closure operators on a partial order as an monotone (increasing), extensive\n(inflationary) and idempotent function.\nWe define closed elements for the operator as elements which are fixed by it.\n\nNote that there is close connection to Galois connections and Galois insertions: every closure\noperator induces a Galois insertion (from the set of closed elements to the underlying type), and\nevery Galois connection induces a closure operator (namely the composition). In particular,\na Galois insertion can be seen as a general case of a closure operator, where the inclusion is given\nby coercion, see `closure_operator.gi`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets\n\n-/\n\n/--\nA closure operator on the partial order `\u03b1` is a monotone function which is extensive (every `x`\nis less than its closure) and idempotent.\n-/\nstructure closure_operator (\u03b1 : Type u) [partial_order \u03b1] extends \u03b1 \u2192\u2098 \u03b1 where\n  le_closure' : \u2200 (x : \u03b1), x \u2264 preorder_hom.to_fun _to_preorder_hom x\n  idempotent' :\n    \u2200 (x : \u03b1),\n      preorder_hom.to_fun _to_preorder_hom (preorder_hom.to_fun _to_preorder_hom x) =\n        preorder_hom.to_fun _to_preorder_hom x\n\nprotected instance closure_operator.has_coe_to_fun (\u03b1 : Type u) [partial_order \u03b1] :\n    has_coe_to_fun (closure_operator \u03b1) :=\n  has_coe_to_fun.mk (fun (c : closure_operator \u03b1) => \u03b1 \u2192 \u03b1)\n    fun (c : closure_operator \u03b1) => preorder_hom.to_fun (closure_operator.to_preorder_hom c)\n\nnamespace closure_operator\n\n\n/-- The identity function as a closure operator. -/\n@[simp] theorem id_to_preorder_hom_to_fun (\u03b1 : Type u) [partial_order \u03b1] (x : \u03b1) :\n    coe_fn (to_preorder_hom (id \u03b1)) x = x :=\n  Eq.refl (coe_fn (to_preorder_hom (id \u03b1)) x)\n\nprotected instance inhabited (\u03b1 : Type u) [partial_order \u03b1] : Inhabited (closure_operator \u03b1) :=\n  { default := id \u03b1 }\n\ntheorem ext {\u03b1 : Type u} [partial_order \u03b1] (c\u2081 : closure_operator \u03b1) (c\u2082 : closure_operator \u03b1) :\n    \u21d1c\u2081 = \u21d1c\u2082 \u2192 c\u2081 = c\u2082 :=\n  sorry\n\n/-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) \u2264 f x`. -/\ndef mk' {\u03b1 : Type u} [partial_order \u03b1] (f : \u03b1 \u2192 \u03b1) (hf\u2081 : monotone f) (hf\u2082 : \u2200 (x : \u03b1), x \u2264 f x)\n    (hf\u2083 : \u2200 (x : \u03b1), f (f x) \u2264 f x) : closure_operator \u03b1 :=\n  mk (preorder_hom.mk f hf\u2081) hf\u2082 sorry\n\n/--\ntheorem monotone {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) : monotone \u21d1c :=\n  preorder_hom.monotone' (to_preorder_hom c)\n\nEvery element is less than its closure. This property is sometimes referred to as extensivity or\ninflationary.\n-/\ntheorem le_closure {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) :\n    x \u2264 coe_fn c x :=\n  le_closure' c x\n\n@[simp] theorem idempotent {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) :\n    coe_fn c (coe_fn c x) = coe_fn c x :=\n  idempotent' c x\n\ntheorem le_closure_iff {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) (y : \u03b1) :\n    x \u2264 coe_fn c y \u2194 coe_fn c x \u2264 coe_fn c y :=\n  { mp := fun (h : x \u2264 coe_fn c y) => idempotent c y \u25b8 monotone c h,\n    mpr := fun (h : coe_fn c x \u2264 coe_fn c y) => le_trans (le_closure c x) h }\n\ntheorem closure_top {\u03b1 : Type u} [order_top \u03b1] (c : closure_operator \u03b1) : coe_fn c \u22a4 = \u22a4 :=\n  le_antisymm le_top (le_closure c \u22a4)\n\ntheorem closure_inter_le {\u03b1 : Type u} [semilattice_inf \u03b1] (c : closure_operator \u03b1) (x : \u03b1) (y : \u03b1) :\n    coe_fn c (x \u2293 y) \u2264 coe_fn c x \u2293 coe_fn c y :=\n  le_inf (monotone c inf_le_left) (monotone c inf_le_right)\n\ntheorem closure_union_closure_le {\u03b1 : Type u} [semilattice_sup \u03b1] (c : closure_operator \u03b1) (x : \u03b1)\n    (y : \u03b1) : coe_fn c x \u2294 coe_fn c y \u2264 coe_fn c (x \u2294 y) :=\n  sup_le (monotone c le_sup_left) (monotone c le_sup_right)\n\n/-- An element `x` is closed for the closure operator `c` if it is a fixed point for it. -/\ndef closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) : set \u03b1 :=\n  fun (x : \u03b1) => coe_fn c x = x\n\ntheorem mem_closed_iff {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) :\n    x \u2208 closed c \u2194 coe_fn c x = x :=\n  iff.rfl\n\ntheorem mem_closed_iff_closure_le {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) :\n    x \u2208 closed c \u2194 coe_fn c x \u2264 x :=\n  { mp := le_of_eq, mpr := fun (h : coe_fn c x \u2264 x) => le_antisymm h (le_closure c x) }\n\ntheorem closure_eq_self_of_mem_closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1)\n    {x : \u03b1} (h : x \u2208 closed c) : coe_fn c x = x :=\n  h\n\n@[simp] theorem closure_is_closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) :\n    coe_fn c x \u2208 closed c :=\n  idempotent c x\n\n/-- The set of closed elements for `c` is exactly its range. -/\ntheorem closed_eq_range_close {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) :\n    closed c = set.range \u21d1c :=\n  sorry\n\n/-- Send an `x` to an element of the set of closed elements (by taking the closure). -/\ndef to_closed {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) (x : \u03b1) : \u21a5(closed c) :=\n  { val := coe_fn c x, property := closure_is_closed c x }\n\ntheorem top_mem_closed {\u03b1 : Type u} [order_top \u03b1] (c : closure_operator \u03b1) : \u22a4 \u2208 closed c :=\n  closure_top c\n\ntheorem closure_le_closed_iff_le {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) {x : \u03b1}\n    {y : \u03b1} (hy : closed c y) : x \u2264 y \u2194 coe_fn c x \u2264 y :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (x \u2264 y \u2194 coe_fn c x \u2264 y))\n        (Eq.symm (closure_eq_self_of_mem_closed c hy))))\n    (eq.mpr\n      (id\n        (Eq._oldrec (Eq.refl (x \u2264 coe_fn c y \u2194 coe_fn c x \u2264 coe_fn c y))\n          (propext (le_closure_iff c x y))))\n      (iff.refl (coe_fn c x \u2264 coe_fn c y)))\n\n/-- The set of closed elements has a Galois insertion to the underlying type. -/\ndef gi {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) :\n    galois_insertion (to_closed c) coe :=\n  galois_insertion.mk (fun (x : \u03b1) (hx : \u2191(to_closed c x) \u2264 x) => { val := x, property := sorry })\n    sorry sorry sorry\n\nend closure_operator\n\n\n/--\nEvery Galois connection induces a closure operator given by the composition. This is the partial\norder version of the statement that every adjunction induces a monad.\n-/\n@[simp] theorem galois_connection.closure_operator_to_preorder_hom_to_fun {\u03b1 : Type u}\n    [partial_order \u03b1] {\u03b2 : Type u} [preorder \u03b2] {l : \u03b1 \u2192 \u03b2} {u : \u03b2 \u2192 \u03b1} (gc : galois_connection l u)\n    (x : \u03b1) :\n    coe_fn (closure_operator.to_preorder_hom (galois_connection.closure_operator gc)) x = u (l x) :=\n  Eq.refl (coe_fn (closure_operator.to_preorder_hom (galois_connection.closure_operator gc)) x)\n\n/--\nThe Galois insertion associated to a closure operator can be used to reconstruct the closure\noperator.\n\nNote that the inverse in the opposite direction does not hold in general.\n-/\n@[simp] theorem closure_operator_gi_self {\u03b1 : Type u} [partial_order \u03b1] (c : closure_operator \u03b1) :\n    galois_connection.closure_operator (galois_insertion.gc (closure_operator.gi c)) = c :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/order/closure_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.703647254237545}}
{"text": "import analysis.topology.continuity\nimport analysis.topology.topological_space\nimport analysis.topology.infinite_sum\nimport analysis.topology.topological_structures\nimport analysis.topology.uniform_space\n\nimport Topology.Material.Sutherland_Chapter_8\n\nimport data.equiv.basic\n\nlocal attribute [instance] classical.prop_decidable\n\nuniverses u v w\n\nopen set filter lattice classical\n\n-- Below is the definition of the subspace_topology\n-- I think we should actually use the subspace topology already in lean \n-- It is the one induced by the inclusion map, subspace.val\n-- It is called subtype.topological_space\ndef subspace_topology {\u03b1 : Type u} [X : topological_space \u03b1] (A : set \u03b1) : topological_space A := {\n  is_open := \u03bb I, \u2203 U : set \u03b1, X.is_open U \u2227 subtype.val '' I = U \u2229 A, \n  is_open_univ := begin existsi univ, split, exact X.is_open_univ, rw univ_inter, unfold set.image, simp, end,\n  is_open_inter := begin \n    intros s t Hs Ht,\n    cases Hs with Us HUs,\n    cases Ht with Ut HUt,\n    let Ust := Us \u2229 Ut,\n    existsi Ust,\n    split,\n      exact X.is_open_inter Us Ut HUs.1 HUt.1,\n    have H1 : Ust \u2229 A = (Us \u2229 A) \u2229 (Ut \u2229 A),\n      rw inter_right_comm Us A (Ut \u2229 A),\n      simp [inter_assoc],\n    rw H1,\n    rw [\u2190 HUs.2, \u2190 HUt.2],\n    rw set.image_inter,\n    exact subtype.val_injective,\n  end,\n  is_open_sUnion := begin\n    intros I HI,\n    let Uset := {U : set \u03b1 | topological_space.is_open X U \u2227 \u2203 t \u2208 I, subtype.val '' t = U \u2229 A},\n    let Uunion := \u22c3\u2080 Uset,\n    existsi Uunion,\n    split,\n      have H1 : (\u2200 (t : set \u03b1), t \u2208 Uset \u2192 is_open t),\n        intros t Ht,\n        exact Ht.1,\n      exact is_open_sUnion H1,\n    apply set.ext,\n    intro x,\n    split,\n      swap,\n      intro Hx,\n      cases Hx with Hx1 Hx2,\n      simp at Hx1,\n      cases Hx1 with U HU,\n      simp,\n      existsi Hx2,\n      cases HU with HU HxU,\n      cases HU with HUopen HU,\n      cases HU with t Ht,\n      existsi t,\n      apply and.intro Ht.1,\n      rw \u2190 preimage_image_eq t subtype.val_injective,\n      show x \u2208 subtype.val '' t,\n      rw Ht.2,\n      exact \u27e8HxU,Hx2\u27e9,\n    simp,\n    intros Hx HxinU0I,\n    cases HxinU0I with t Ht,\n    split,\n      swap,\n      exact Hx,\n    have Hnext := HI t Ht.1,\n    cases Hnext with Unext HUnext,\n    existsi Unext,\n    split,\n      apply and.intro HUnext.1,\n      existsi t,\n      exact \u27e8Ht.1, HUnext.2\u27e9,\n    have x_in_val_t : x \u2208 subtype.val '' t,\n      simp,\n      existsi Hx,\n      exact Ht.2,\n    rw HUnext.2 at x_in_val_t,\n    exact x_in_val_t.1,\n  end,\n}\n\n\n--Proof of equivalence of definitions\ntheorem subspace_top_eq_subtype_top {\u03b1 : Type u} [X : topological_space \u03b1] (A : set \u03b1) :\n(subspace_topology A).is_open = (subtype.topological_space).is_open :=\nbegin\n  dunfold subtype.topological_space,\n  unfold topological_space.induced,\n  simp,\n  funext V,\n  apply propext,\n  split,\n    intro HU,\n    cases HU with U HU,\n    existsi U,\n    apply and.intro HU.1,\n    have H0 : subtype.val \u207b\u00b9' (subtype.val '' V) = subtype.val \u207b\u00b9' (A \u2229 U),\n      rw HU.2,\n      simp,\n      apply inter_comm,\n    have H1 : V = subtype.val \u207b\u00b9' (A \u2229 U),\n      rw \u2190 H0,\n      rw preimage_image_eq,\n      exact subtype.val_injective,\n    rw H1,\n    simp,\n    have preimage_A_eq_univ : subtype.val \u207b\u00b9' A = @univ (subtype A),\n      apply set.ext,\n      intro x,\n      simp,\n      exact x.2,\n    rw preimage_A_eq_univ,\n    apply univ_inter,\n  intro HU,\n  cases HU with U HU,\n  existsi U,\n  apply and.intro HU.1,\n  have H0 :  subtype.val '' V = subtype.val '' (subtype.val \u207b\u00b9' U), by rw HU.2,\n  rw H0,\n  apply set.ext,\n  intro x,\n  simp,\n  split,\n    intro Hx,\n    cases Hx with a Ha,\n    rw \u2190 Ha.2.2,\n    apply and.intro Ha.2.1,\n    exact Ha.1,\n  intro Hx,\n  existsi x,\n  exact \u27e8Hx.2, Hx.1, refl x\u27e9, \nend\n\n--Prop 10.4\ntheorem inclusion_cont_subtype_top {\u03b1 : Type u} [X : topological_space \u03b1] (A : set \u03b1) : @continuous _ _ (subtype.topological_space) _ (\u03bb (a : A), (a : \u03b1)) := \nbegin\nunfold continuous,\nunfold is_open,\nintros s Hs,\nsimp,\nunfold subtype.topological_space,\nunfold topological_space.induced,\nsimp,\nexistsi s,\napply and.intro Hs,\nunfold coe,\nunfold lift_t,\nunfold has_lift_t.lift,\nunfold coe_t,\nunfold has_coe_t.coe,\nunfold coe_b,\nunfold has_coe.coe,\nend\n\n\n--Prop 10.4 but with subspace topology (I won't do any more with the subspace topology)\ntheorem inclusion_cont_subspace_top {\u03b1 : Type u} [X : topological_space \u03b1] (A : set \u03b1) : @continuous _ _ (subspace_topology A) _ (\u03bb (a : A), (a : \u03b1)) := \nbegin\nunfold continuous,\nunfold is_open,\nrw subspace_top_eq_subtype_top,\nexact inclusion_cont_subtype_top A,\nend\n\n--Corollary 10.5\ntheorem restriction_cont {\u03b1 : Type u} [X : topological_space \u03b1] {\u03b2 : Type v} [Y : topological_space \u03b2]\n(f : \u03b1 \u2192 \u03b2) (H : continuous f) (A : set \u03b1) : continuous (\u03bb (x : A), f x) := \nbegin\n  have H0 : (\u03bb (x : A), f \u2191x) = f \u2218 (\u03bb (a : A), (a : \u03b1)), by simp,\n  rw H0,\n  exact (continuous.comp (inclusion_cont_subtype_top A) H), \nend\n\n--Proposition 10.6\ntheorem inclusion_comp_cont_iff_cont {\u03b1 : Type*} [X : topological_space \u03b1] {A : set \u03b1} {\u03b3 : Type*} [Z : topological_space \u03b3]\n(g : \u03b3 \u2192 A) : continuous g \u2194 continuous ((\u03bb (a : A), (a : \u03b1)) \u2218 g) :=\nbegin\n  split,\n    intro Hg,\n    exact continuous.comp Hg (inclusion_cont_subtype_top A),\n  simp,\n  unfold continuous,\n  unfold is_open,\n  intro H_i_comp_g,\n  intros V HV,\n  unfold subtype.topological_space at HV,\n  unfold topological_space.induced at HV,\n  simp at HV,\n  cases HV with U HU,\n  have H1 := H_i_comp_g U HU.1,\n  rw HU.2,\n  exact H1,\nend\n\n\n\n--Proposition 10.8\ntheorem inclusion_comp_cont_iff_cont_to_subtype_top {\u03b1 : Type u} [X : topological_space \u03b1] {A : set \u03b1} (Trandom : topological_space A) :\n(\u2200 {\u03b3 : Type u} [Z : topological_space \u03b3]\n(g : \u03b3 \u2192 A), (@continuous \u03b3 \u21a5A Z _ g \u2194 @continuous \u03b3 \u03b1 Z _ ((\u03bb (a : A), (a : \u03b1)) \u2218 g))) \u2194 Trandom.is_open = (subtype.topological_space).is_open :=\nbegin\n  split,\n    swap,\n    { intros H _ _ _,\n      rw \u2190(@inclusion_comp_cont_iff_cont _ _ _ _ Z g),\n      unfold continuous,\n      unfold is_open,\n      rw H,\n    },\n  intro H,\n  apply set.ext, intro V, split,\n    swap,\n    have H1 := (@H (\u21a5A) Trandom (@id A)).1 id_map_continuous,\n    intro HV,\n    unfold subtype.topological_space at HV, unfold topological_space.induced at HV, simp at HV,\n    cases HV with U HU,\n    have H2 :  Trandom.is_open (subtype.val \u207b\u00b9' U),\n      simp at H1, unfold continuous at H1,\n      exact H1 U HU.1,  \n    rw \u2190 HU.2 at H2, assumption,\n  have H1 := (@H (\u21a5A) subtype.topological_space (@id A)).2,\n  simp at H1,\n  intro HV,\n  have H2 := H1 _,\n     unfold continuous at H2,\n  exact H2 V HV,\n  \n  exact continuous_subtype_val,\nend\n\n--Product Topologies\ndef product_top {\u03b1 : Type*} {\u03b2 : Type*} (X : topological_space \u03b1) (Y : topological_space \u03b2) : topological_space (\u03b1 \u00d7 \u03b2) :=\n{is_open := \u03bb (W : set (\u03b1 \u00d7 \u03b2)), \u2203 (I \u2286 { b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2),\n  is_open U \u2227 is_open V \u2227 b = set.prod U V}), W = \u22c3\u2080 I,\n  is_open_univ := begin \n    existsi {d : set (\u03b1 \u00d7 \u03b2) | d = set.prod univ univ},\n    have H : set.subset {d : set (\u03b1 \u00d7 \u03b2) | d = set.prod univ univ} {b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2), is_open U \u2227 is_open V \u2227   b = set.prod U V},\n      rw univ_prod_univ,\n      unfold set.subset,\n      intros a Ha,\n      rw mem_set_of_eq at Ha,\n      rw Ha,\n      existsi univ,\n      existsi univ, apply and.intro is_open_univ, apply and.intro is_open_univ, rw univ_prod_univ,\n    existsi H,\n    rw univ_prod_univ,\n    have H1 : {d : set (\u03b1 \u00d7 \u03b2) | d = univ} = {univ},\n      apply set.ext,\n      intro x, rw mem_set_of_eq, rw mem_singleton_iff,\n    rw H1,\n    rw sUnion_singleton,\n  end,\n\n  is_open_inter := begin \n    intros W1 W2 HW1 HW2,\n    cases HW1 with I1 HI1, cases HI1 with HI1 HWI1,\n    cases HW2 with I2 HI2, cases HI2 with HI2 HWI2,\n    existsi {e : set (\u03b1 \u00d7 \u03b2) | \u2203 (U \u2208 I1) (V \u2208 I2), e = U \u2229 V},\n    have H : set.subset\n        {e : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set (\u03b1 \u00d7 \u03b2)) (H : U \u2208 I1) (V : set (\u03b1 \u00d7 \u03b2)) (H : V \u2208 I2), e = U \u2229 V}\n        {b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2), is_open U \u2227 is_open V \u2227 b = set.prod U V},\n      unfold set.subset,\n      simp,\n      intros a w1 Hw1 w2 Hw2 Ha,\n      rw Ha,\n      have H1 := HI1 Hw1, rw mem_set_of_eq at H1,\n      have H2 := HI2 Hw2, rw mem_set_of_eq at H2,\n      rcases H1 with \u27e8U1, V1, HU1, HV1, H1UV\u27e9,\n      rcases H2 with \u27e8U2, V2, HU2, HV2, H2UV\u27e9, \n      existsi (U1 \u2229 U2), apply and.intro (X.is_open_inter U1 U2 HU1 HU2),\n      existsi (V1 \u2229 V2), apply and.intro (Y.is_open_inter V1 V2 HV1 HV2),\n      rw H1UV, rw H2UV,\n      apply prod_inter_prod,\n    existsi H,\n    rw HWI1, rw HWI2,\n    apply set.ext,\n    intro x,\n    rw mem_set_of_eq, unfold set.inter, rw mem_set_of_eq, unfold set.sUnion, rw mem_set_of_eq, rw mem_set_of_eq,\n    split,\n      intro Hx,\n      rcases Hx with \u27e8HU, V, HV1, HV2\u27e9, rcases HU with \u27e8U, HU1, HU2\u27e9,\n      existsi (U \u2229 V),\n      existsi _,\n      exact \u27e8HU2, HV2\u27e9,\n      rw mem_set_of_eq,\n      existsi [U, HU1, V, HV1],\n      trivial,\n    intro Hx,\n    rcases Hx with \u27e8a, Ha1, Ha2\u27e9, rw mem_set_of_eq at Ha1, rcases Ha1 with \u27e8U, HU, V, HV, HUV\u27e9, \n    rw HUV at Ha2,\n    split,\n      existsi [U, HU],\n      exact Ha2.1,\n    existsi [V, HV],\n    exact Ha2.2,\n  end,\n  is_open_sUnion := begin\n    intros I2 HI2,\n    let Iset := {I | set.subset I\n      {b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2), is_open U \u2227 is_open V \u2227 b = set.prod U V} \u2227 (\u2203 t \u2208 I2, t = \u22c3\u2080 I)},\n    existsi \u22c3\u2080 Iset,\n    existsi _,\n    swap,\n    intros x Hx,\n    rw mem_set_of_eq at Hx, rcases Hx with \u27e8a, Ha, Ha2\u27e9,\n    rw mem_set_of_eq at Ha,\n    exact Ha.1 Ha2,\n    apply set.ext, intro s, simp,\n    split,\n      intro HW, rcases HW with \u27e8W, HW, HW2\u27e9,\n        have H := HI2 W HW,\n        rcases H with \u27e8IW, HIW, HIIW\u27e9,\n        rw HIIW at HW2, rw mem_sUnion_eq at HW2, rcases HW2 with \u27e8square, Hsquare, Hsquare_s\u27e9,\n        existsi square, split, existsi IW, refine \u27e8_, Hsquare\u27e9, rw HIIW at HW, refine \u27e8_, HW\u27e9,\n        have Hsame : {b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2), is_open U \u2227 is_open V \u2227 b = set.prod U V} = {b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1), is_open U \u2227 \u2203 (V : set \u03b2), is_open V \u2227 b = set.prod U V},\n          apply set.ext, intro x, simp,\n        rw \u2190Hsame, exact HIW,\n      exact Hsquare_s,\n    intro HW, cases HW with W HW, cases HW with HW HsW, cases HW with I HI,\n    existsi \u22c3\u2080 I,\n    refine \u27e8HI.1.2, _\u27e9,\n    rw mem_sUnion_eq,\n    existsi W, existsi HI.2, exact HsW,\n  end\n}\n\n\n--Product Topology Basis\ndefinition product_top_basis {\u03b1 : Type*} {\u03b2 : Type*} (X : topological_space \u03b1) (Y : topological_space \u03b2) :\nset (set (\u03b1 \u00d7 \u03b2)) := { b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2),\n  is_open U \u2227 is_open V \u2227 b = set.prod U V}\n\ntheorem is_basis_product_top_basis {\u03b1 : Type*} {\u03b2 : Type*} (X : topological_space \u03b1) (Y : topological_space \u03b2) :\n@topological_space.is_topological_basis _ (product_top X Y) (product_top_basis X Y) :=\nbegin\n  unfold topological_space.is_topological_basis, split,\n    intros t1 Ht1 t2 Ht2 x Hx, unfold product_top_basis at Ht1, rw mem_set_of_eq at Ht1,\n    unfold product_top_basis at Ht2, rw mem_set_of_eq at Ht2,\n    rcases Ht1 with \u27e8U1, V1, Ht1\u27e9, rcases Ht2 with \u27e8U2, V2, Ht2\u27e9,\n    existsi (set.prod (U1 \u2229 U2) (V1 \u2229 V2)),\n    refine \u27e8_,_\u27e9, \n    unfold product_top_basis, rw mem_set_of_eq, existsi [U1 \u2229 U2, V1 \u2229 V2],\n    exact \u27e8is_open_inter Ht1.1 Ht2.1, is_open_inter Ht1.2.1 Ht2.2.1, refl (set.prod (U1 \u2229 U2) (V1 \u2229 V2))\u27e9,\n    rw mem_prod, cases Hx with Hx1 Hx2, rw Ht1.2.2 at Hx1, rw Ht2.2.2 at Hx2, rw mem_prod at Hx1, rw mem_prod at Hx2,\n    refine \u27e8\u27e8\u27e8Hx1.1,Hx2.1\u27e9,Hx1.2,Hx2.2\u27e9,_\u27e9,\n    rw Ht1.2.2, rw Ht2.2.2, intros y Hy, rw mem_prod at Hy, split,\n    exact \u27e8Hy.1.1, Hy.2.1\u27e9,\n  exact \u27e8Hy.1.2, Hy.2.2\u27e9,\n  split,\n    apply eq_univ_of_univ_subset, apply subset_sUnion_of_mem,\n    existsi [univ, univ], apply and.intro is_open_univ, apply and.intro is_open_univ,\n    rw \u2190 univ_prod_univ,\n    unfold product_top, unfold topological_space.generate_from,\n    apply topological_space_eq,\n    apply set.ext, intro W, split,\n      intro HW, rcases HW with \u27e8open_rects_set, Hopen_rects_set, HW\u27e9,\n      unfold product_top_basis, \n      rw HW,\n      exact topological_space.generate_open.sUnion open_rects_set \n      (\u03bb (s : set (\u03b1 \u00d7 \u03b2)) (H : s \u2208 open_rects_set), \n      topological_space.generate_open.basic s (Hopen_rects_set H)),\n   \n    apply topological_space.generate_open.rec,\n    --THIS IS THE CORRECT PATH\n          intros s Hs,\n          unfold product_top_basis at Hs,\n          rcases Hs with \u27e8U, V, HU, HV, HW\u27e9,\n          existsi {set.prod U V},\n          have H :  {set.prod U V} \u2286\n              {b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2), is_open U \u2227 is_open V \u2227 b = set.prod U V},\n            intros s Hs, rw mem_singleton_iff at Hs, rw Hs,\n            existsi [U, V],\n            exact \u27e8HU, HV, refl (set.prod U V)\u27e9,\n          existsi H,\n          rw sUnion_singleton,\n          exact HW,\n        existsi {univ},\n        have H :  {univ} \u2286\n              {b : set (\u03b1 \u00d7 \u03b2) | \u2203 (U : set \u03b1) (V : set \u03b2), is_open U \u2227 is_open V \u2227 b = set.prod U V},\n          intros UNI HUNI,\n          existsi [univ, univ],\n          rw mem_singleton_iff at HUNI, rw HUNI,\n          apply and.intro is_open_univ, apply and.intro is_open_univ,\n          exact eq.symm univ_prod_univ,\n        existsi H,\n        rw sUnion_singleton,\n      intros s t Hs1 Ht1 Hs Ht,\n      rcases Hs with \u27e8Is, HIs, HsUnionIs\u27e9,\n      rcases Ht with \u27e8It, HIt, HsUnionIt\u27e9,\n      apply is_open_inter,\n        existsi [Is, HIs], assumption,\n      existsi [It, HIt], assumption,\n    intros I HI_gen_prod_top_bas HI_open_sets,\n    -- WHat set do I need? The set that contains all open rectangles appearing in any element of I\n    existsi { b : set (\u03b1 \u00d7 \u03b2) | (\u2203 (U : set \u03b1) (V : set \u03b2), \n             is_open U \u2227 is_open V \u2227 b = set.prod U V) \u2227 \u2203 s \u2208 I, b \u2286 s},\n    existsi _, swap,\n      intros x Hx, rw mem_set_of_eq, rw mem_set_of_eq at Hx,\n      cases Hx with Hx1 Hx2, exact Hx1,\n    apply eq_of_subset_of_subset,\n      intros x Hx,\n      rw mem_sUnion_eq at Hx,\n      rcases Hx with \u27e8t, Ht, Hxt\u27e9,\n -- Need to existsi the open rectangle that x is in\n      have H := HI_open_sets t Ht, cases H with It HIt, cases HIt with HIt HIt2,\n      rw HIt2 at Hxt, rcases Hxt with \u27e8rect,rectIt,xrect\u27e9,\n      existsi rect, refine \u27e8\u27e8HIt rectIt,_\u27e9, _\u27e9,\n        existsi [t, Ht],\n        rw HIt2, apply subset_sUnion_of_mem rectIt,\n      exact xrect,\n    apply sUnion_subset,\n    intros t Ht,\n    cases Ht, rcases Ht_right, cases Ht_right_h,\n    apply subset.trans Ht_right_h_h (subset_sUnion_of_mem Ht_right_h_w),\nend\n\n\n\n--Proof that our definition of product top is equivalent to the instance built into mathlib.\ntheorem product_top_eq_induced_prod_top {\u03b1 : Type*} {\u03b2 : Type*} (X : topological_space \u03b1) (Y : topological_space \u03b2) :\nproduct_top X Y = topological_space.induced prod.fst X \u2294 topological_space.induced prod.snd Y :=\nbegin\n  apply topological_space_eq,\n  unfold product_top, unfold lattice.has_sup.sup, unfold semilattice_sup.sup, unfold semilattice_sup_bot.sup,\n  unfold bounded_lattice.sup, unfold complete_lattice.sup, unfold Inf, unfold has_Inf.Inf,\n  simp only [exists_prop, mem_set_of_eq, not_and, and_imp],\n  apply set.ext,\n  intro U, split,\n    intro HU, rcases HU with \u27e8I_U,HI_U,HI_U2\u27e9,\n    intros T HXT HYT,\n    unfold has_le.le at HXT, unfold preorder.le at HXT, unfold partial_order.le at HXT, unfold has_le.le at HXT, unfold preorder.le at HXT, unfold has_le.le at HXT, unfold preorder.le at HXT, unfold partial_order.le at HXT, unfold order_bot.le at HXT, unfold bounded_lattice.le at HXT, unfold complete_lattice.le at HXT, unfold bounded_lattice.le at HXT,\n    --THe following should be each prod U1 univ, prod univ V1 for all rectangles prod U1 V1 \n    --in U. Then intersect each pair and union them.\n    rw HI_U2,\n    apply is_open_sUnion,\n    intros rect Hrect,\n    --Split rect into the intersection of prod U1 univ and prod univ V1\n    have Hrect2 := HI_U Hrect,\n    rcases Hrect2 with \u27e8Urect,Vrect,HUrect,HVrect,HUrectVrect\u27e9,\n    have HUrectuniv : topological_space.is_open T (set.prod Urect univ),\n      apply HXT, existsi Urect, split,\n        exact HUrect,\n      unfold preimage,\n      apply set.ext, intro x,\n      rw mem_set_of_eq, rw mem_prod,\n      rw and_iff_left, exact mem_univ _,\n    have HunivVrect : topological_space.is_open T (set.prod univ Vrect),\n      apply HYT, existsi Vrect, split,\n        exact HVrect,\n      unfold preimage,\n      apply set.ext, intro x,\n      rw mem_set_of_eq, rw mem_prod,\n      rw and_iff_right, exact mem_univ _,\n    have H_open_rect := T.is_open_inter _ _ HUrectuniv HunivVrect,\n    have Hrect_prod : set.prod Urect univ \u2229 set.prod univ Vrect = rect,\n      rw prod_inter_prod,\n      rw inter_univ, rw univ_inter, rw HUrectVrect,\n    rw Hrect_prod at H_open_rect,\n    exact H_open_rect,\n  intro HU,\n  have H := HU (product_top X Y),\n  have HX : topological_space.induced prod.fst X \u2264 product_top X Y,\n    intros V HV, unfold topological_space.induced at HV, cases HV with S HS, cases HS with HS HV,\n    unfold preimage at HV, rw HV,\n    existsi {set.prod S univ}, existsi _, \n      rw sUnion_singleton, apply set.ext, intro x, rw mem_set_of_eq,rw mem_prod, rw and_iff_left, exact mem_univ _,\n    intros x Hx, existsi S, existsi univ, exact \u27e8HS, is_open_univ, mem_singleton_iff.1 Hx\u27e9,\n  have HY :  topological_space.induced prod.snd Y \u2264 product_top X Y,\n    intros V HV, cases HV with S HS, cases HS with HS HV, unfold preimage at HV, rw HV,\n    existsi {set.prod univ S}, existsi _,\n      rw sUnion_singleton, apply set.ext, intro x, rw mem_set_of_eq, rw mem_prod, rw and_iff_right, exact mem_univ _,\n    intros x Hx, existsi univ, existsi S, exact \u27e8is_open_univ, HS, mem_singleton_iff.1 Hx\u27e9,\n  have H1 := H HX HY, \n  unfold product_top at H1,\n   simp only [exists_prop, mem_set_of_eq, not_and, and_imp] at H1,\n  exact H1,\nend\n\n#print prefix set\n--Proposition 10.10\ntheorem left_proj_cont {\u03b1 : Type*} {\u03b2 : Type*} (X : topological_space \u03b1) (Y : topological_space \u03b2) \n: @continuous (\u03b1 \u00d7 \u03b2) \u03b1 (product_top X Y) X (\u03bb p, p.1) :=\nbegin\n  unfold continuous,\n  unfold is_open,\n  intros s Hs,\n  unfold product_top,\n  existsi {set.prod s (univ : set \u03b2)}, split,\n    intros pre Hpre, rw mem_singleton_iff at Hpre, rw Hpre,\n    rw mem_set_of_eq, existsi [s, univ], exact \u27e8Hs, Y.is_open_univ, rfl\u27e9,\n  apply set.ext, intro x, rw mem_preimage_eq, rw sUnion_singleton, rw mem_prod, \n  rw and_iff_left, exact mem_univ x.snd,\nend\n\ntheorem right_proj_cont {\u03b1 : Type*} {\u03b2 : Type*} (X : topological_space \u03b1) (Y : topological_space \u03b2) \n: @continuous (\u03b1 \u00d7 \u03b2) \u03b2 (product_top X Y) Y (\u03bb p, p.2) :=\nbegin\n  unfold continuous,\n  unfold is_open,\n  intros s Hs,\n  unfold product_top,\n  existsi {set.prod (univ : set \u03b1) s}, split,\n    intros pre Hpre, rw @mem_singleton_iff at Hpre, rw Hpre,\n    rw mem_set_of_eq, existsi [univ, s], exact \u27e8X.is_open_univ, Hs, rfl\u27e9,\n  apply set.ext, intro x, rw mem_preimage_eq, rw sUnion_singleton, rw mem_prod, \n  rw and_iff_right, exact mem_univ x.fst,\nend\n\n--set_option pp.implicit true\nset_option trace.simplify.rewrite true \n\n\ntheorem cont_iff_proj_cont {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*} (X : topological_space \u03b1) \n(Y : topological_space \u03b2) (Z : topological_space \u03b3) (f : \u03b3 \u2192 (\u03b1 \u00d7 \u03b2)) :\n@continuous _ _ Z (product_top X Y) f \u2194 (continuous ((\u03bb (p : \u03b1 \u00d7 \u03b2), p.2) \u2218 f) \u2227 continuous ((\u03bb (p : \u03b1 \u00d7 \u03b2), p.1) \u2218 f)) :=\nbegin\n    split,\n    intro Hf, split,\n      exact @continuous.comp _ _ _ _ (product_top X Y) _ _ _ Hf (right_proj_cont X Y),\n    exact @continuous.comp _ _ _ _ (product_top X Y) _ _ _ Hf (left_proj_cont X Y),\n  intro Hf,\n  apply continuous_basis_to_continuous,\n  apply is_basis_product_top_basis,\n  intro b,\n  unfold product_top_basis at b, rename b b1,\n  rcases b.property with \u27e8U, V, HU, HV,HB\u27e9,\n  cases Hf with Hfsnd Hffst,\n  have Hsnd := Hfsnd V HV,\n  have Hfst := Hffst U HU,\n  have H1 := is_open_inter Hfst Hsnd,\n  have EQ : (\u03bb (p : \u03b1 \u00d7 \u03b2), p.fst) \u2218 f \u207b\u00b9' U \u2229 (\u03bb (p : \u03b1 \u00d7 \u03b2), p.snd) \u2218 f \u207b\u00b9' V = (f \u207b\u00b9' \u2191b),\n    rw preimage_comp, rw @preimage_comp _ _ _  f (\u03bb (p : \u03b1 \u00d7 \u03b2), p.snd) _,\n    rw \u2190 preimage_inter,\n    have H2 : prod.fst \u207b\u00b9' U = set.prod U univ,\n      apply set.ext, intro x, split,\n        intro Hx, rw mem_preimage_eq at Hx, split, exact Hx, exact @mem_univ \u03b2 x.snd,\n      intro Hx, rw mem_preimage_eq, exact Hx.1,\n    rw H2,\n    have H3 : prod.snd \u207b\u00b9' V = set.prod univ V,\n      apply set.ext, intro x, split,\n        intro Hx, rw mem_preimage_eq at Hx, split, exact @mem_univ \u03b1 x.fst, exact Hx,\n      intro Hx, rw mem_preimage_eq, exact Hx.2,\n    rw H3,\n    rw prod_inter_prod,\n    rw inter_univ, rw univ_inter, rw \u2190 HB, \n    have H4 : b.val = \u2191b,\n      trivial,\n    rw H4,\n  rw \u2190 EQ,\n  exact H1,\nend\n\n\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/Topology/Material/Sutherland_Chapter_10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.7036472439790731}}
{"text": "/-\nCopyright (c) 2022 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module probability.martingale.centering\n! leanprover-community/mathlib commit bea6c853b6edbd15e9d0941825abd04d77933ed0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Probability.Martingale.Basic\n\n/-!\n# Centering lemma for stochastic processes\n\nAny `\u2115`-indexed stochastic process which is adapted and integrable can be written as the sum of a\nmartingale and a predictable process. This result is also known as **Doob's decomposition theorem**.\nFrom a process `f`, a filtration `\u2131` and a measure `\u03bc`, we define two processes\n`martingale_part f \u2131 \u03bc` and `predictable_part f \u2131 \u03bc`.\n\n## Main definitions\n\n* `measure_theory.predictable_part f \u2131 \u03bc`: a predictable process such that\n  `f = predictable_part f \u2131 \u03bc + martingale_part f \u2131 \u03bc`\n* `measure_theory.martingale_part f \u2131 \u03bc`: a martingale such that\n  `f = predictable_part f \u2131 \u03bc + martingale_part f \u2131 \u03bc`\n\n## Main statements\n\n* `measure_theory.adapted_predictable_part`: `(\u03bb n, predictable_part f \u2131 \u03bc (n+1))` is adapted. That\n  is, `predictable_part` is predictable.\n* `measure_theory.martingale_martingale_part`: `martingale_part f \u2131 \u03bc` is a martingale.\n\n-/\n\n\nopen TopologicalSpace Filter\n\nopen NNReal ENNReal MeasureTheory ProbabilityTheory BigOperators\n\nnamespace MeasureTheory\n\nvariable {\u03a9 E : Type _} {m0 : MeasurableSpace \u03a9} {\u03bc : Measure \u03a9} [NormedAddCommGroup E]\n  [NormedSpace \u211d E] [CompleteSpace E] {f : \u2115 \u2192 \u03a9 \u2192 E} {\u2131 : Filtration \u2115 m0} {n : \u2115}\n\n/-- Any `\u2115`-indexed stochastic process can be written as the sum of a martingale and a predictable\nprocess. This is the predictable process. See `martingale_part` for the martingale. -/\nnoncomputable def predictablePart {m0 : MeasurableSpace \u03a9} (f : \u2115 \u2192 \u03a9 \u2192 E) (\u2131 : Filtration \u2115 m0)\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : \u2115 \u2192 \u03a9 \u2192 E := fun n =>\n  \u2211 i in Finset.range n, \u03bc[f (i + 1) - f i|\u2131 i]\n#align measure_theory.predictable_part MeasureTheory.predictablePart\n\n@[simp]\ntheorem predictablePart_zero : predictablePart f \u2131 \u03bc 0 = 0 := by\n  simp_rw [predictable_part, Finset.range_zero, Finset.sum_empty]\n#align measure_theory.predictable_part_zero MeasureTheory.predictablePart_zero\n\ntheorem adapted_predictablePart : Adapted \u2131 fun n => predictablePart f \u2131 \u03bc (n + 1) := fun n =>\n  Finset.stronglyMeasurable_sum' _ fun i hin =>\n    stronglyMeasurable_condexp.mono (\u2131.mono (Finset.mem_range_succ_iff.mp hin))\n#align measure_theory.adapted_predictable_part MeasureTheory.adapted_predictablePart\n\ntheorem adapted_predictable_part' : Adapted \u2131 fun n => predictablePart f \u2131 \u03bc n := fun n =>\n  Finset.stronglyMeasurable_sum' _ fun i hin =>\n    stronglyMeasurable_condexp.mono (\u2131.mono (Finset.mem_range_le hin))\n#align measure_theory.adapted_predictable_part' MeasureTheory.adapted_predictable_part'\n\n/-- Any `\u2115`-indexed stochastic process can be written as the sum of a martingale and a predictable\nprocess. This is the martingale. See `predictable_part` for the predictable process. -/\nnoncomputable def martingalePart {m0 : MeasurableSpace \u03a9} (f : \u2115 \u2192 \u03a9 \u2192 E) (\u2131 : Filtration \u2115 m0)\n    (\u03bc : Measure \u03a9 := by exact MeasureTheory.MeasureSpace.volume) : \u2115 \u2192 \u03a9 \u2192 E := fun n =>\n  f n - predictablePart f \u2131 \u03bc n\n#align measure_theory.martingale_part MeasureTheory.martingalePart\n\ntheorem martingalePart_add_predictablePart (\u2131 : Filtration \u2115 m0) (\u03bc : Measure \u03a9) (f : \u2115 \u2192 \u03a9 \u2192 E) :\n    martingalePart f \u2131 \u03bc + predictablePart f \u2131 \u03bc = f :=\n  sub_add_cancel _ _\n#align measure_theory.martingale_part_add_predictable_part MeasureTheory.martingalePart_add_predictablePart\n\ntheorem martingalePart_eq_sum :\n    martingalePart f \u2131 \u03bc = fun n =>\n      f 0 + \u2211 i in Finset.range n, f (i + 1) - f i - \u03bc[f (i + 1) - f i|\u2131 i] :=\n  by\n  rw [martingale_part, predictable_part]\n  ext1 n\n  rw [Finset.eq_sum_range_sub f n, \u2190 add_sub, \u2190 Finset.sum_sub_distrib]\n#align measure_theory.martingale_part_eq_sum MeasureTheory.martingalePart_eq_sum\n\ntheorem adapted_martingalePart (hf : Adapted \u2131 f) : Adapted \u2131 (martingalePart f \u2131 \u03bc) :=\n  Adapted.sub hf adapted_predictable_part'\n#align measure_theory.adapted_martingale_part MeasureTheory.adapted_martingalePart\n\ntheorem integrableMartingalePart (hf_int : \u2200 n, Integrable (f n) \u03bc) (n : \u2115) :\n    Integrable (martingalePart f \u2131 \u03bc n) \u03bc :=\n  by\n  rw [martingale_part_eq_sum]\n  exact\n    (hf_int 0).add\n      (integrable_finset_sum' _ fun i hi => ((hf_int _).sub (hf_int _)).sub integrable_condexp)\n#align measure_theory.integrable_martingale_part MeasureTheory.integrableMartingalePart\n\ntheorem martingaleMartingalePart (hf : Adapted \u2131 f) (hf_int : \u2200 n, Integrable (f n) \u03bc)\n    [SigmaFiniteFiltration \u03bc \u2131] : Martingale (martingalePart f \u2131 \u03bc) \u2131 \u03bc :=\n  by\n  refine' \u27e8adapted_martingale_part hf, fun i j hij => _\u27e9\n  -- \u22a2 \u03bc[martingale_part f \u2131 \u03bc j | \u2131 i] =\u1d50[\u03bc] martingale_part f \u2131 \u03bc i\n  have h_eq_sum :\n    \u03bc[martingale_part f \u2131 \u03bc j|\u2131 i] =\u1d50[\u03bc]\n      f 0 + \u2211 k in Finset.range j, \u03bc[f (k + 1) - f k|\u2131 i] - \u03bc[\u03bc[f (k + 1) - f k|\u2131 k]|\u2131 i] :=\n    by\n    rw [martingale_part_eq_sum]\n    refine' (condexp_add (hf_int 0) _).trans _\n    \u00b7 exact integrable_finset_sum' _ fun i hij => ((hf_int _).sub (hf_int _)).sub integrable_condexp\n    refine' (eventually_eq.add eventually_eq.rfl (condexp_finset_sum fun i hij => _)).trans _\n    \u00b7 exact ((hf_int _).sub (hf_int _)).sub integrable_condexp\n    refine' eventually_eq.add _ _\n    \u00b7 rw [condexp_of_strongly_measurable (\u2131.le _) _ (hf_int 0)]\n      \u00b7 infer_instance\n      \u00b7 exact (hf 0).mono (\u2131.mono (zero_le i))\n    \u00b7 exact eventuallyEq_sum fun k hkj => condexp_sub ((hf_int _).sub (hf_int _)) integrable_condexp\n  refine' h_eq_sum.trans _\n  have h_ge : \u2200 k, i \u2264 k \u2192 \u03bc[f (k + 1) - f k|\u2131 i] - \u03bc[\u03bc[f (k + 1) - f k|\u2131 k]|\u2131 i] =\u1d50[\u03bc] 0 :=\n    by\n    intro k hk\n    have : \u03bc[\u03bc[f (k + 1) - f k|\u2131 k]|\u2131 i] =\u1d50[\u03bc] \u03bc[f (k + 1) - f k|\u2131 i] :=\n      condexp_condexp_of_le (\u2131.mono hk) (\u2131.le k)\n    filter_upwards [this]with x hx\n    rw [Pi.sub_apply, Pi.zero_apply, hx, sub_self]\n  have h_lt :\n    \u2200 k,\n      k < i \u2192\n        \u03bc[f (k + 1) - f k|\u2131 i] - \u03bc[\u03bc[f (k + 1) - f k|\u2131 k]|\u2131 i] =\u1d50[\u03bc]\n          f (k + 1) - f k - \u03bc[f (k + 1) - f k|\u2131 k] :=\n    by\n    refine' fun k hk => eventually_eq.sub _ _\n    \u00b7 rw [condexp_of_strongly_measurable]\n      \u00b7 exact ((hf (k + 1)).mono (\u2131.mono (Nat.succ_le_of_lt hk))).sub ((hf k).mono (\u2131.mono hk.le))\n      \u00b7 exact (hf_int _).sub (hf_int _)\n    \u00b7 rw [condexp_of_strongly_measurable]\n      \u00b7 exact strongly_measurable_condexp.mono (\u2131.mono hk.le)\n      \u00b7 exact integrable_condexp\n  rw [martingale_part_eq_sum]\n  refine' eventually_eq.add eventually_eq.rfl _\n  rw [\u2190 Finset.sum_range_add_sum_Ico _ hij, \u2190\n    add_zero (\u2211 i in Finset.range i, f (i + 1) - f i - \u03bc[f (i + 1) - f i|\u2131 i])]\n  refine' (eventuallyEq_sum fun k hk => h_lt k (finset.mem_range.mp hk)).add _\n  refine' (eventuallyEq_sum fun k hk => h_ge k (finset.mem_Ico.mp hk).1).trans _\n  simp only [Finset.sum_const_zero, Pi.zero_apply]\n  rfl\n#align measure_theory.martingale_martingale_part MeasureTheory.martingaleMartingalePart\n\n-- The following two lemmas demonstrate the essential uniqueness of the decomposition\ntheorem martingalePart_add_ae_eq [SigmaFiniteFiltration \u03bc \u2131] {f g : \u2115 \u2192 \u03a9 \u2192 E}\n    (hf : Martingale f \u2131 \u03bc) (hg : Adapted \u2131 fun n => g (n + 1)) (hg0 : g 0 = 0)\n    (hgint : \u2200 n, Integrable (g n) \u03bc) (n : \u2115) : martingalePart (f + g) \u2131 \u03bc n =\u1d50[\u03bc] f n :=\n  by\n  set h := f - martingale_part (f + g) \u2131 \u03bc with hhdef\n  have hh : h = predictable_part (f + g) \u2131 \u03bc - g := by\n    rw [hhdef, sub_eq_sub_iff_add_eq_add, add_comm (predictable_part (f + g) \u2131 \u03bc),\n      martingale_part_add_predictable_part]\n  have hhpred : adapted \u2131 fun n => h (n + 1) :=\n    by\n    rw [hh]\n    exact adapted_predictable_part.sub hg\n  have hhmgle : martingale h \u2131 \u03bc :=\n    hf.sub\n      (martingale_martingale_part\n        (hf.adapted.add <| predictable.adapted hg <| hg0.symm \u25b8 strongly_measurable_zero) fun n =>\n        (hf.integrable n).add <| hgint n)\n  refine' (eventually_eq_iff_sub.2 _).symm\n  filter_upwards [hhmgle.eq_zero_of_predictable hhpred n]with \u03c9 h\u03c9\n  rw [hhdef, Pi.sub_apply] at h\u03c9\n  rw [h\u03c9, Pi.sub_apply, martingale_part]\n  simp [hg0]\n#align measure_theory.martingale_part_add_ae_eq MeasureTheory.martingalePart_add_ae_eq\n\ntheorem predictablePart_add_ae_eq [SigmaFiniteFiltration \u03bc \u2131] {f g : \u2115 \u2192 \u03a9 \u2192 E}\n    (hf : Martingale f \u2131 \u03bc) (hg : Adapted \u2131 fun n => g (n + 1)) (hg0 : g 0 = 0)\n    (hgint : \u2200 n, Integrable (g n) \u03bc) (n : \u2115) : predictablePart (f + g) \u2131 \u03bc n =\u1d50[\u03bc] g n :=\n  by\n  filter_upwards [martingale_part_add_ae_eq hf hg hg0 hgint n]with \u03c9 h\u03c9\n  rw [\u2190 add_right_inj (f n \u03c9)]\n  conv_rhs =>\n    rw [\u2190 Pi.add_apply, \u2190 Pi.add_apply, \u2190 martingale_part_add_predictable_part \u2131 \u03bc (f + g)]\n  rw [Pi.add_apply, Pi.add_apply, h\u03c9]\n#align measure_theory.predictable_part_add_ae_eq MeasureTheory.predictablePart_add_ae_eq\n\nsection Difference\n\ntheorem predictablePart_bdd_difference {R : \u211d\u22650} {f : \u2115 \u2192 \u03a9 \u2192 \u211d} (\u2131 : Filtration \u2115 m0)\n    (hbdd : \u2200\u1d50 \u03c9 \u2202\u03bc, \u2200 i, |f (i + 1) \u03c9 - f i \u03c9| \u2264 R) :\n    \u2200\u1d50 \u03c9 \u2202\u03bc, \u2200 i, |predictablePart f \u2131 \u03bc (i + 1) \u03c9 - predictablePart f \u2131 \u03bc i \u03c9| \u2264 R :=\n  by\n  simp_rw [predictable_part, Finset.sum_apply, Finset.sum_range_succ_sub_sum]\n  exact ae_all_iff.2 fun i => ae_bdd_condexp_of_ae_bdd <| ae_all_iff.1 hbdd i\n#align measure_theory.predictable_part_bdd_difference MeasureTheory.predictablePart_bdd_difference\n\ntheorem martingalePart_bdd_difference {R : \u211d\u22650} {f : \u2115 \u2192 \u03a9 \u2192 \u211d} (\u2131 : Filtration \u2115 m0)\n    (hbdd : \u2200\u1d50 \u03c9 \u2202\u03bc, \u2200 i, |f (i + 1) \u03c9 - f i \u03c9| \u2264 R) :\n    \u2200\u1d50 \u03c9 \u2202\u03bc, \u2200 i, |martingalePart f \u2131 \u03bc (i + 1) \u03c9 - martingalePart f \u2131 \u03bc i \u03c9| \u2264 \u2191(2 * R) :=\n  by\n  filter_upwards [hbdd, predictable_part_bdd_difference \u2131 hbdd]with \u03c9 h\u03c9\u2081 h\u03c9\u2082 i\n  simp only [two_mul, martingale_part, Pi.sub_apply]\n  have :\n    |f (i + 1) \u03c9 - predictable_part f \u2131 \u03bc (i + 1) \u03c9 - (f i \u03c9 - predictable_part f \u2131 \u03bc i \u03c9)| =\n      |f (i + 1) \u03c9 - f i \u03c9 - (predictable_part f \u2131 \u03bc (i + 1) \u03c9 - predictable_part f \u2131 \u03bc i \u03c9)| :=\n    by ring_nf\n  -- `ring` suggests `ring_nf` despite proving the goal\n  rw [this]\n  exact (abs_sub _ _).trans (add_le_add (h\u03c9\u2081 i) (h\u03c9\u2082 i))\n#align measure_theory.martingale_part_bdd_difference MeasureTheory.martingalePart_bdd_difference\n\nend Difference\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Probability/Martingale/Centering.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7931059438487662, "lm_q1q2_score": 0.7036472390523231}}
{"text": "-- CS menor o igual que cero\n-- =========================\n\nimport data.real.basic\nvariable (x : \u211d)\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, x \u2264 \u03b5) \u2192 x \u2264 0 :=\nbegin\n  contrapose,\n  push_neg,\n  intro h,\n  use x/2,\n  split ; linarith,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  (\u2200 \u03b5 > 0, x \u2264 \u03b5) \u2192 x \u2264 0 :=\nbegin\n  contrapose!,\n  intro h,\n  use x/2,\n  split ; linarith,\nend\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/4_Contradiccion_y_negacion/CS_menor_o_igual_que_cero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7036472366869673}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison, Heather Macbeth\n\n! This file was ported from Lean 3 source module topology.continuous_function.stone_weierstrass\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.ContinuousFunction.Weierstrass\nimport Mathbin.Data.IsROrC.Basic\n\n/-!\n# The Stone-Weierstrass theorem\n\nIf a subalgebra `A` of `C(X, \u211d)`, where `X` is a compact topological space,\nseparates points, then it is dense.\n\nWe argue as follows.\n\n* In any subalgebra `A` of `C(X, \u211d)`, if `f \u2208 A`, then `abs f \u2208 A.topological_closure`.\n  This follows from the Weierstrass approximation theorem on `[-\u2016f\u2016, \u2016f\u2016]` by\n  approximating `abs` uniformly thereon by polynomials.\n* This ensures that `A.topological_closure` is actually a sublattice:\n  if it contains `f` and `g`, then it contains the pointwise supremum `f \u2294 g`\n  and the pointwise infimum `f \u2293 g`.\n* Any nonempty sublattice `L` of `C(X, \u211d)` which separates points is dense,\n  by a nice argument approximating a given `f` above and below using separating functions.\n  For each `x y : X`, we pick a function `g x y \u2208 L` so `g x y x = f x` and `g x y y = f y`.\n  By continuity these functions remain close to `f` on small patches around `x` and `y`.\n  We use compactness to identify a certain finitely indexed infimum of finitely indexed supremums\n  which is then close to `f` everywhere, obtaining the desired approximation.\n* Finally we put these pieces together. `L = A.topological_closure` is a nonempty sublattice\n  which separates points since `A` does, and so is dense (in fact equal to `\u22a4`).\n\nWe then prove the complex version for self-adjoint subalgebras `A`, by separately approximating\nthe real and imaginary parts using the real subalgebra of real-valued functions in `A`\n(which still separates points, by taking the norm-square of a separating function).\n\n## Future work\n\nExtend to cover the case of subalgebras of the continuous functions vanishing at infinity,\non non-compact spaces.\n\n-/\n\n\nnoncomputable section\n\nnamespace ContinuousMap\n\nvariable {X : Type _} [TopologicalSpace X] [CompactSpace X]\n\nopen Polynomial\n\n/-- Turn a function `f : C(X, \u211d)` into a continuous map into `set.Icc (-\u2016f\u2016) (\u2016f\u2016)`,\nthereby explicitly attaching bounds.\n-/\ndef attachBound (f : C(X, \u211d)) : C(X, Set.Icc (-\u2016f\u2016) \u2016f\u2016)\n    where toFun x := \u27e8f x, \u27e8neg_norm_le_apply f x, apply_le_norm f x\u27e9\u27e9\n#align continuous_map.attach_bound ContinuousMap.attachBound\n\n@[simp]\ntheorem attachBound_apply_coe (f : C(X, \u211d)) (x : X) : ((attachBound f) x : \u211d) = f x :=\n  rfl\n#align continuous_map.attach_bound_apply_coe ContinuousMap.attachBound_apply_coe\n\ntheorem polynomial_comp_attachBound (A : Subalgebra \u211d C(X, \u211d)) (f : A) (g : \u211d[X]) :\n    (g.toContinuousMapOn (Set.Icc (-\u2016f\u2016) \u2016f\u2016)).comp (f : C(X, \u211d)).attachBound =\n      Polynomial.aeval f g :=\n  by\n  ext\n  simp only [ContinuousMap.coe_comp, Function.comp_apply, ContinuousMap.attachBound_apply_coe,\n    Polynomial.toContinuousMapOn_apply, Polynomial.aeval_subalgebra_coe,\n    Polynomial.aeval_continuousMap_apply, Polynomial.toContinuousMap_apply]\n#align continuous_map.polynomial_comp_attach_bound ContinuousMap.polynomial_comp_attachBound\n\n/-- Given a continuous function `f` in a subalgebra of `C(X, \u211d)`, postcomposing by a polynomial\ngives another function in `A`.\n\nThis lemma proves something slightly more subtle than this:\nwe take `f`, and think of it as a function into the restricted target `set.Icc (-\u2016f\u2016) \u2016f\u2016)`,\nand then postcompose with a polynomial function on that interval.\nThis is in fact the same situation as above, and so also gives a function in `A`.\n-/\ntheorem polynomial_comp_attachBound_mem (A : Subalgebra \u211d C(X, \u211d)) (f : A) (g : \u211d[X]) :\n    (g.toContinuousMapOn (Set.Icc (-\u2016f\u2016) \u2016f\u2016)).comp (f : C(X, \u211d)).attachBound \u2208 A :=\n  by\n  rw [polynomial_comp_attach_bound]\n  apply SetLike.coe_mem\n#align continuous_map.polynomial_comp_attach_bound_mem ContinuousMap.polynomial_comp_attachBound_mem\n\ntheorem comp_attachBound_mem_closure (A : Subalgebra \u211d C(X, \u211d)) (f : A)\n    (p : C(Set.Icc (-\u2016f\u2016) \u2016f\u2016, \u211d)) : p.comp (attachBound f) \u2208 A.topologicalClosure :=\n  by\n  -- `p` itself is in the closure of polynomials, by the Weierstrass theorem,\n  have mem_closure : p \u2208 (polynomialFunctions (Set.Icc (-\u2016f\u2016) \u2016f\u2016)).topologicalClosure :=\n    continuousMap_mem_polynomialFunctions_closure _ _ p\n  -- and so there are polynomials arbitrarily close.\n  have frequently_mem_polynomials := mem_closure_iff_frequently.mp mem_closure\n  -- To prove `p.comp (attached_bound f)` is in the closure of `A`,\n  -- we show there are elements of `A` arbitrarily close.\n  apply mem_closure_iff_frequently.mpr\n  -- To show that, we pull back the polynomials close to `p`,\n  refine'\n    ((comp_right_continuous_map \u211d (attach_bound (f : C(X, \u211d)))).ContinuousAt\n            p).Tendsto.frequently_map\n      _ _ frequently_mem_polynomials\n  -- but need to show that those pullbacks are actually in `A`.\n  rintro _ \u27e8g, \u27e8-, rfl\u27e9\u27e9\n  simp only [SetLike.mem_coe, AlgHom.coe_toRingHom, comp_right_continuous_map_apply,\n    Polynomial.toContinuousMapOnAlgHom_apply]\n  apply polynomial_comp_attach_bound_mem\n#align continuous_map.comp_attach_bound_mem_closure ContinuousMap.comp_attachBound_mem_closure\n\ntheorem abs_mem_subalgebra_closure (A : Subalgebra \u211d C(X, \u211d)) (f : A) :\n    (f : C(X, \u211d)).abs \u2208 A.topologicalClosure :=\n  by\n  let M := \u2016f\u2016\n  let f' := attach_bound (f : C(X, \u211d))\n  let abs : C(Set.Icc (-\u2016f\u2016) \u2016f\u2016, \u211d) := { toFun := fun x : Set.Icc (-\u2016f\u2016) \u2016f\u2016 => |(x : \u211d)| }\n  change abs.comp f' \u2208 A.topological_closure\n  apply comp_attach_bound_mem_closure\n#align continuous_map.abs_mem_subalgebra_closure ContinuousMap.abs_mem_subalgebra_closure\n\ntheorem inf_mem_subalgebra_closure (A : Subalgebra \u211d C(X, \u211d)) (f g : A) :\n    (f : C(X, \u211d)) \u2293 (g : C(X, \u211d)) \u2208 A.topologicalClosure :=\n  by\n  rw [inf_eq]\n  refine'\n    A.topological_closure.smul_mem\n      (A.topological_closure.sub_mem\n        (A.topological_closure.add_mem (A.le_topological_closure f.property)\n          (A.le_topological_closure g.property))\n        _)\n      _\n  exact_mod_cast abs_mem_subalgebra_closure A _\n#align continuous_map.inf_mem_subalgebra_closure ContinuousMap.inf_mem_subalgebra_closure\n\ntheorem inf_mem_closed_subalgebra (A : Subalgebra \u211d C(X, \u211d)) (h : IsClosed (A : Set C(X, \u211d)))\n    (f g : A) : (f : C(X, \u211d)) \u2293 (g : C(X, \u211d)) \u2208 A :=\n  by\n  convert inf_mem_subalgebra_closure A f g\n  apply SetLike.ext'\n  symm\n  erw [closure_eq_iff_isClosed]\n  exact h\n#align continuous_map.inf_mem_closed_subalgebra ContinuousMap.inf_mem_closed_subalgebra\n\ntheorem sup_mem_subalgebra_closure (A : Subalgebra \u211d C(X, \u211d)) (f g : A) :\n    (f : C(X, \u211d)) \u2294 (g : C(X, \u211d)) \u2208 A.topologicalClosure :=\n  by\n  rw [sup_eq]\n  refine'\n    A.topological_closure.smul_mem\n      (A.topological_closure.add_mem\n        (A.topological_closure.add_mem (A.le_topological_closure f.property)\n          (A.le_topological_closure g.property))\n        _)\n      _\n  exact_mod_cast abs_mem_subalgebra_closure A _\n#align continuous_map.sup_mem_subalgebra_closure ContinuousMap.sup_mem_subalgebra_closure\n\ntheorem sup_mem_closed_subalgebra (A : Subalgebra \u211d C(X, \u211d)) (h : IsClosed (A : Set C(X, \u211d)))\n    (f g : A) : (f : C(X, \u211d)) \u2294 (g : C(X, \u211d)) \u2208 A :=\n  by\n  convert sup_mem_subalgebra_closure A f g\n  apply SetLike.ext'\n  symm\n  erw [closure_eq_iff_isClosed]\n  exact h\n#align continuous_map.sup_mem_closed_subalgebra ContinuousMap.sup_mem_closed_subalgebra\n\nopen Topology\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (f g \u00abexpr \u2208 \u00bb L) -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (f g \u00abexpr \u2208 \u00bb L) -/\n-- Here's the fun part of Stone-Weierstrass!\ntheorem sublattice_closure_eq_top (L : Set C(X, \u211d)) (nA : L.Nonempty)\n    (inf_mem : \u2200 (f) (_ : f \u2208 L) (g) (_ : g \u2208 L), f \u2293 g \u2208 L)\n    (sup_mem : \u2200 (f) (_ : f \u2208 L) (g) (_ : g \u2208 L), f \u2294 g \u2208 L) (sep : L.SeparatesPointsStrongly) :\n    closure L = \u22a4 :=\n  by\n  -- We start by boiling down to a statement about close approximation.\n  apply eq_top_iff.mpr\n  rintro f -\n  refine'\n    Filter.Frequently.mem_closure\n      ((Filter.HasBasis.frequently_iff Metric.nhds_basis_ball).mpr fun \u03b5 pos => _)\n  simp only [exists_prop, Metric.mem_ball]\n  -- It will be helpful to assume `X` is nonempty later,\n  -- so we get that out of the way here.\n  by_cases nX : Nonempty X\n  swap\n  exact \u27e8nA.some, (dist_lt_iff Pos).mpr fun x => False.elim (nX \u27e8x\u27e9), nA.some_spec\u27e9\n  /-\n    The strategy now is to pick a family of continuous functions `g x y` in `A`\n    with the property that `g x y x = f x` and `g x y y = f y`\n    (this is immediate from `h : separates_points_strongly`)\n    then use continuity to see that `g x y` is close to `f` near both `x` and `y`,\n    and finally using compactness to produce the desired function `h`\n    as a maximum over finitely many `x` of a minimum over finitely many `y` of the `g x y`.\n    -/\n  dsimp [Set.SeparatesPointsStrongly] at sep\n  let g : X \u2192 X \u2192 L := fun x y => (sep f x y).some\n  have w\u2081 : \u2200 x y, g x y x = f x := fun x y => (sep f x y).choose_spec.1\n  have w\u2082 : \u2200 x y, g x y y = f y := fun x y => (sep f x y).choose_spec.2\n  -- For each `x y`, we define `U x y` to be `{z | f z - \u03b5 < g x y z}`,\n  -- and observe this is a neighbourhood of `y`.\n  let U : X \u2192 X \u2192 Set X := fun x y => { z | f z - \u03b5 < g x y z }\n  have U_nhd_y : \u2200 x y, U x y \u2208 \ud835\udcdd y := by\n    intro x y\n    refine' IsOpen.mem_nhds _ _\n    \u00b7 apply isOpen_lt <;> continuity\n    \u00b7 rw [Set.mem_setOf_eq, w\u2082]\n      exact sub_lt_self _ Pos\n  -- Fixing `x` for a moment, we have a family of functions `\u03bb y, g x y`\n  -- which on different patches (the `U x y`) are greater than `f z - \u03b5`.\n  -- Taking the supremum of these functions\n  -- indexed by a finite collection of patches which cover `X`\n  -- will give us an element of `A` that is globally greater than `f z - \u03b5`\n  -- and still equal to `f x` at `x`.\n  -- Since `X` is compact, for every `x` there is some finset `ys t`\n  -- so the union of the `U x y` for `y \u2208 ys x` still covers everything.\n  let ys : \u2200 x, Finset X := fun x => (CompactSpace.elim_nhds_subcover (U x) (U_nhd_y x)).some\n  let ys_w : \u2200 x, (\u22c3 y \u2208 ys x, U x y) = \u22a4 := fun x =>\n    (CompactSpace.elim_nhds_subcover (U x) (U_nhd_y x)).choose_spec\n  have ys_nonempty : \u2200 x, (ys x).Nonempty := fun x =>\n    Set.nonempty_of_union_eq_top_of_nonempty _ _ nX (ys_w x)\n  -- Thus for each `x` we have the desired `h x : A` so `f z - \u03b5 < h x z` everywhere\n  -- and `h x x = f x`.\n  let h : \u2200 x, L := fun x =>\n    \u27e8(ys x).sup' (ys_nonempty x) fun y => (g x y : C(X, \u211d)),\n      Finset.sup'_mem _ sup_mem _ _ _ fun y _ => (g x y).2\u27e9\n  have lt_h : \u2200 x z, f z - \u03b5 < h x z := by\n    intro x z\n    obtain \u27e8y, ym, zm\u27e9 := Set.exists_set_mem_of_union_eq_top _ _ (ys_w x) z\n    dsimp [h]\n    simp only [coeFn_coe_base', Subtype.coe_mk, sup'_coe, Finset.sup'_apply, Finset.lt_sup'_iff]\n    exact \u27e8y, ym, zm\u27e9\n  have h_eq : \u2200 x, h x x = f x := by\n    intro x\n    simp only [coeFn_coe_base'] at w\u2081\n    simp [coeFn_coe_base', w\u2081]\n  -- For each `x`, we define `W x` to be `{z | h x z < f z + \u03b5}`,\n  let W : \u2200 x, Set X := fun x => { z | h x z < f z + \u03b5 }\n  -- This is still a neighbourhood of `x`.\n  have W_nhd : \u2200 x, W x \u2208 \ud835\udcdd x := by\n    intro x\n    refine' IsOpen.mem_nhds _ _\n    \u00b7 apply isOpen_lt <;> continuity\n    \u00b7 dsimp only [W, Set.mem_setOf_eq]\n      rw [h_eq]\n      exact lt_add_of_pos_right _ Pos\n  -- Since `X` is compact, there is some finset `ys t`\n  -- so the union of the `W x` for `x \u2208 xs` still covers everything.\n  let xs : Finset X := (CompactSpace.elim_nhds_subcover W W_nhd).some\n  let xs_w : (\u22c3 x \u2208 xs, W x) = \u22a4 := (CompactSpace.elim_nhds_subcover W W_nhd).choose_spec\n  have xs_nonempty : xs.nonempty := Set.nonempty_of_union_eq_top_of_nonempty _ _ nX xs_w\n  -- Finally our candidate function is the infimum over `x \u2208 xs` of the `h x`.\n  -- This function is then globally less than `f z + \u03b5`.\n  let k : (L : Type _) :=\n    \u27e8xs.inf' xs_nonempty fun x => (h x : C(X, \u211d)),\n      Finset.inf'_mem _ inf_mem _ _ _ fun x _ => (h x).2\u27e9\n  refine' \u27e8k.1, _, k.2\u27e9\n  -- We just need to verify the bound, which we do pointwise.\n  rw [dist_lt_iff Pos]\n  intro z\n  -- We rewrite into this particular form,\n  -- so that simp lemmas about inequalities involving `finset.inf'` can fire.\n  rw [show \u2200 a b \u03b5 : \u211d, dist a b < \u03b5 \u2194 a < b + \u03b5 \u2227 b - \u03b5 < a\n      by\n      intros\n      simp only [\u2190 Metric.mem_ball, Real.ball_eq_Ioo, Set.mem_Ioo, and_comm']]\n  fconstructor\n  \u00b7 dsimp [k]\n    simp only [Finset.inf'_lt_iff, ContinuousMap.inf'_apply]\n    exact Set.exists_set_mem_of_union_eq_top _ _ xs_w z\n  \u00b7 dsimp [k]\n    simp only [Finset.lt_inf'_iff, ContinuousMap.inf'_apply]\n    intro x xm\n    apply lt_h\n#align continuous_map.sublattice_closure_eq_top ContinuousMap.sublattice_closure_eq_top\n\n/-- The **Stone-Weierstrass Approximation Theorem**,\nthat a subalgebra `A` of `C(X, \u211d)`, where `X` is a compact topological space,\nis dense if it separates points.\n-/\ntheorem subalgebra_topologicalClosure_eq_top_of_separatesPoints (A : Subalgebra \u211d C(X, \u211d))\n    (w : A.SeparatesPoints) : A.topologicalClosure = \u22a4 :=\n  by\n  -- The closure of `A` is closed under taking `sup` and `inf`,\n  -- and separates points strongly (since `A` does),\n  -- so we can apply `sublattice_closure_eq_top`.\n  apply SetLike.ext'\n  let L := A.topological_closure\n  have n : Set.Nonempty (L : Set C(X, \u211d)) := \u27e8(1 : C(X, \u211d)), A.le_topological_closure A.one_mem\u27e9\n  convert sublattice_closure_eq_top (L : Set C(X, \u211d)) n\n      (fun f fm g gm => inf_mem_closed_subalgebra L A.is_closed_topological_closure \u27e8f, fm\u27e9 \u27e8g, gm\u27e9)\n      (fun f fm g gm => sup_mem_closed_subalgebra L A.is_closed_topological_closure \u27e8f, fm\u27e9 \u27e8g, gm\u27e9)\n      (Subalgebra.SeparatesPoints.strongly\n        (Subalgebra.separatesPoints_monotone A.le_topological_closure w))\n  \u00b7 simp\n#align continuous_map.subalgebra_topological_closure_eq_top_of_separates_points ContinuousMap.subalgebra_topologicalClosure_eq_top_of_separatesPoints\n\n/-- An alternative statement of the Stone-Weierstrass theorem.\n\nIf `A` is a subalgebra of `C(X, \u211d)` which separates points (and `X` is compact),\nevery real-valued continuous function on `X` is a uniform limit of elements of `A`.\n-/\ntheorem continuousMap_mem_subalgebra_closure_of_separatesPoints (A : Subalgebra \u211d C(X, \u211d))\n    (w : A.SeparatesPoints) (f : C(X, \u211d)) : f \u2208 A.topologicalClosure :=\n  by\n  rw [subalgebra_topological_closure_eq_top_of_separates_points A w]\n  simp\n#align continuous_map.continuous_map_mem_subalgebra_closure_of_separates_points ContinuousMap.continuousMap_mem_subalgebra_closure_of_separatesPoints\n\n/-- An alternative statement of the Stone-Weierstrass theorem,\nfor those who like their epsilons.\n\nIf `A` is a subalgebra of `C(X, \u211d)` which separates points (and `X` is compact),\nevery real-valued continuous function on `X` is within any `\u03b5 > 0` of some element of `A`.\n-/\ntheorem exists_mem_subalgebra_near_continuousMap_of_separatesPoints (A : Subalgebra \u211d C(X, \u211d))\n    (w : A.SeparatesPoints) (f : C(X, \u211d)) (\u03b5 : \u211d) (pos : 0 < \u03b5) :\n    \u2203 g : A, \u2016(g : C(X, \u211d)) - f\u2016 < \u03b5 :=\n  by\n  have w :=\n    mem_closure_iff_frequently.mp (continuous_map_mem_subalgebra_closure_of_separates_points A w f)\n  rw [metric.nhds_basis_ball.frequently_iff] at w\n  obtain \u27e8g, H, m\u27e9 := w \u03b5 Pos\n  rw [Metric.mem_ball, dist_eq_norm] at H\n  exact \u27e8\u27e8g, m\u27e9, H\u27e9\n#align continuous_map.exists_mem_subalgebra_near_continuous_map_of_separates_points ContinuousMap.exists_mem_subalgebra_near_continuousMap_of_separatesPoints\n\n/-- An alternative statement of the Stone-Weierstrass theorem,\nfor those who like their epsilons and don't like bundled continuous functions.\n\nIf `A` is a subalgebra of `C(X, \u211d)` which separates points (and `X` is compact),\nevery real-valued continuous function on `X` is within any `\u03b5 > 0` of some element of `A`.\n-/\ntheorem exists_mem_subalgebra_near_continuous_of_separatesPoints (A : Subalgebra \u211d C(X, \u211d))\n    (w : A.SeparatesPoints) (f : X \u2192 \u211d) (c : Continuous f) (\u03b5 : \u211d) (pos : 0 < \u03b5) :\n    \u2203 g : A, \u2200 x, \u2016g x - f x\u2016 < \u03b5 :=\n  by\n  obtain \u27e8g, b\u27e9 := exists_mem_subalgebra_near_continuous_map_of_separates_points A w \u27e8f, c\u27e9 \u03b5 Pos\n  use g\n  rwa [norm_lt_iff _ Pos] at b\n#align continuous_map.exists_mem_subalgebra_near_continuous_of_separates_points ContinuousMap.exists_mem_subalgebra_near_continuous_of_separatesPoints\n\nend ContinuousMap\n\nsection IsROrC\n\nopen IsROrC\n\n-- Redefine `X`, since for the next few lemmas it need not be compact\nvariable {\ud835\udd5c : Type _} {X : Type _} [IsROrC \ud835\udd5c] [TopologicalSpace X]\n\nnamespace ContinuousMap\n\n/-- A real subalgebra of `C(X, \ud835\udd5c)` is `conj_invariant`, if it contains all its conjugates. -/\ndef ConjInvariantSubalgebra (A : Subalgebra \u211d C(X, \ud835\udd5c)) : Prop :=\n  A.map (conjAe.toAlgHom.compLeftContinuous \u211d conjCle.Continuous) \u2264 A\n#align continuous_map.conj_invariant_subalgebra ContinuousMap.ConjInvariantSubalgebra\n\ntheorem mem_conjInvariantSubalgebra {A : Subalgebra \u211d C(X, \ud835\udd5c)} (hA : ConjInvariantSubalgebra A)\n    {f : C(X, \ud835\udd5c)} (hf : f \u2208 A) : (conjAe.toAlgHom.compLeftContinuous \u211d conjCle.Continuous) f \u2208 A :=\n  hA \u27e8f, hf, rfl\u27e9\n#align continuous_map.mem_conj_invariant_subalgebra ContinuousMap.mem_conjInvariantSubalgebra\n\n/-- If a set `S` is conjugation-invariant, then its `\ud835\udd5c`-span is conjugation-invariant. -/\ntheorem subalgebra_conj_invariant {S : Set C(X, \ud835\udd5c)}\n    (hS : \u2200 f, f \u2208 S \u2192 (conjAe.toAlgHom.compLeftContinuous \u211d conjCle.Continuous) f \u2208 S) :\n    ConjInvariantSubalgebra ((Algebra.adjoin \ud835\udd5c S).restrictScalars \u211d) :=\n  by\n  rintro _ \u27e8f, hf, rfl\u27e9\n  change _ \u2208 (Algebra.adjoin \ud835\udd5c S).restrictScalars \u211d\n  change _ \u2208 (Algebra.adjoin \ud835\udd5c S).restrictScalars \u211d at hf\n  rw [Subalgebra.mem_restrictScalars] at hf\u22a2\n  apply Algebra.adjoin_induction hf\n  \u00b7 exact fun g hg => Algebra.subset_adjoin (hS g hg)\n  \u00b7 exact fun c => Subalgebra.algebraMap_mem _ (starRingEnd \ud835\udd5c c)\n  \u00b7 intro f g hf hg\n    convert Subalgebra.add_mem _ hf hg\n    exact AlgHom.map_add _ f g\n  \u00b7 intro f g hf hg\n    convert Subalgebra.mul_mem _ hf hg\n    exact AlgHom.map_mul _ f g\n#align continuous_map.subalgebra_conj_invariant ContinuousMap.subalgebra_conj_invariant\n\nend ContinuousMap\n\nopen ContinuousMap\n\n/-- If a conjugation-invariant subalgebra of `C(X, \ud835\udd5c)` separates points, then the real subalgebra\nof its purely real-valued elements also separates points. -/\ntheorem Subalgebra.SeparatesPoints.isROrC_to_real {A : Subalgebra \ud835\udd5c C(X, \ud835\udd5c)}\n    (hA : A.SeparatesPoints) (hA' : ConjInvariantSubalgebra (A.restrictScalars \u211d)) :\n    ((A.restrictScalars \u211d).comap\n        (ofRealAm.compLeftContinuous \u211d continuous_of_real)).SeparatesPoints :=\n  by\n  intro x\u2081 x\u2082 hx\n  -- Let `f` in the subalgebra `A` separate the points `x\u2081`, `x\u2082`\n  obtain \u27e8_, \u27e8f, hfA, rfl\u27e9, hf\u27e9 := hA hx\n  let F : C(X, \ud835\udd5c) := f - const _ (f x\u2082)\n  -- Subtract the constant `f x\u2082` from `f`; this is still an element of the subalgebra\n  have hFA : F \u2208 A :=\n    by\n    refine' A.sub_mem hfA (@Eq.subst _ (\u00b7 \u2208 A) _ _ _ <| A.smul_mem A.one_mem <| f x\u2082)\n    ext1\n    simp only [coe_smul, coe_one, Pi.smul_apply, Pi.one_apply, Algebra.id.smul_eq_mul, mul_one,\n      const_apply]\n  -- Consider now the function `\u03bb x, |f x - f x\u2082| ^ 2`\n  refine' \u27e8_, \u27e8(\u27e8IsROrC.normSq, continuous_norm_sq\u27e9 : C(\ud835\udd5c, \u211d)).comp F, _, rfl\u27e9, _\u27e9\n  \u00b7 -- This is also an element of the subalgebra, and takes only real values\n    rw [SetLike.mem_coe, Subalgebra.mem_comap]\n    convert(A.restrict_scalars \u211d).mul_mem (mem_conj_invariant_subalgebra hA' hFA) hFA\n    ext1\n    rw [mul_comm]\n    exact (IsROrC.mul_conj _).symm\n  \u00b7 -- And it also separates the points `x\u2081`, `x\u2082`\n    have : f x\u2081 - f x\u2082 \u2260 0 := sub_ne_zero.mpr hf\n    simpa only [comp_apply, coe_sub, coe_const, Pi.sub_apply, coe_mk, sub_self, map_zero, Ne.def,\n      norm_sq_eq_zero] using this\n#align subalgebra.separates_points.is_R_or_C_to_real Subalgebra.SeparatesPoints.isROrC_to_real\n\nvariable [CompactSpace X]\n\n/-- The Stone-Weierstrass approximation theorem, `is_R_or_C` version,\nthat a subalgebra `A` of `C(X, \ud835\udd5c)`, where `X` is a compact topological space and `is_R_or_C \ud835\udd5c`,\nis dense if it is conjugation-invariant and separates points.\n-/\ntheorem ContinuousMap.subalgebra_isROrC_topologicalClosure_eq_top_of_separatesPoints\n    (A : Subalgebra \ud835\udd5c C(X, \ud835\udd5c)) (hA : A.SeparatesPoints)\n    (hA' : ConjInvariantSubalgebra (A.restrictScalars \u211d)) : A.topologicalClosure = \u22a4 :=\n  by\n  rw [Algebra.eq_top_iff]\n  -- Let `I` be the natural inclusion of `C(X, \u211d)` into `C(X, \ud835\udd5c)`\n  let I : C(X, \u211d) \u2192\u2097[\u211d] C(X, \ud835\udd5c) := of_real_clm.comp_left_continuous \u211d X\n  -- The main point of the proof is that its range (i.e., every real-valued function) is contained\n  -- in the closure of `A`\n  have key : I.range \u2264 (A.to_submodule.restrict_scalars \u211d).topologicalClosure :=\n    by\n    -- Let `A\u2080` be the subalgebra of `C(X, \u211d)` consisting of `A`'s purely real elements; it is the\n    -- preimage of `A` under `I`.  In this argument we only need its submodule structure.\n    let A\u2080 : Submodule \u211d C(X, \u211d) := (A.to_submodule.restrict_scalars \u211d).comap I\n    -- By `subalgebra.separates_points.complex_to_real`, this subalgebra also separates points, so\n    -- we may apply the real Stone-Weierstrass result to it.\n    have SW : A\u2080.topological_closure = \u22a4 :=\n      haveI :=\n        subalgebra_topological_closure_eq_top_of_separates_points _ (hA.is_R_or_C_to_real hA')\n      congr_arg Subalgebra.toSubmodule this\n    rw [\u2190 Submodule.map_top, \u2190 SW]\n    -- So it suffices to prove that the image under `I` of the closure of `A\u2080` is contained in the\n    -- closure of `A`, which follows by abstract nonsense\n    have h\u2081 := A\u2080.topological_closure_map ((@of_real_clm \ud835\udd5c _).compLeftContinuousCompact X)\n    have h\u2082 := (A.to_submodule.restrict_scalars \u211d).map_comap_le I\n    exact h\u2081.trans (Submodule.topologicalClosure_mono h\u2082)\n  -- In particular, for a function `f` in `C(X, \ud835\udd5c)`, the real and imaginary parts of `f` are in the\n  -- closure of `A`\n  intro f\n  let f_re : C(X, \u211d) := (\u27e8IsROrC.re, is_R_or_C.re_clm.continuous\u27e9 : C(\ud835\udd5c, \u211d)).comp f\n  let f_im : C(X, \u211d) := (\u27e8IsROrC.im, is_R_or_C.im_clm.continuous\u27e9 : C(\ud835\udd5c, \u211d)).comp f\n  have h_f_re : I f_re \u2208 A.topological_closure := key \u27e8f_re, rfl\u27e9\n  have h_f_im : I f_im \u2208 A.topological_closure := key \u27e8f_im, rfl\u27e9\n  -- So `f_re + I \u2022 f_im` is in the closure of `A`\n  convert A.topological_closure.add_mem h_f_re (A.topological_closure.smul_mem h_f_im IsROrC.i)\n  -- And this, of course, is just `f`\n  ext\n  apply Eq.symm\n  simp [I, mul_comm IsROrC.i _]\n#align continuous_map.subalgebra_is_R_or_C_topological_closure_eq_top_of_separates_points ContinuousMap.subalgebra_isROrC_topologicalClosure_eq_top_of_separatesPoints\n\nend IsROrC\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Topology/ContinuousFunction/StoneWeierstrass.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.7036472337334952}}
{"text": "import libs.tuto_lib\n\n\nsection\n/-\nThe first part of this file makes sure you can negate quantified statements\nin your head without the help of `push_neg`.\n\nYou need to complete the statement and then use the `check_me` tactic\nto check your answer. This tactic exists only for those exercises,\nit mostly calls `push_neg` and then cleans up a bit.\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from \u211d to \u211d\n-- x\u2080 and l are real numbers\nvariables (u : \u2115 \u2192 \u211d) (f : \u211d \u2192 \u211d) (x\u2080 l : \u211d)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/- Negation of \"f is continuous at x\u2080\" -/\n-- 0063\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x, |x - x\u2080| \u2264 \u03b4 \u2192  |f x - f x\u2080| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`\u2200 x x', ...` is the abbreviation of\n`\u2200 x, \u2200 x', ... `. \n\nAlso, `\u2203 x x', ...` is the abbreviation of `\u2203 x, \u2203 x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on \u211d\" -/\n-- 0064\nexample : \u00ac (\u2200 \u03b5 > 0, \u2203 \u03b4 > 0, \u2200 x x', |x' - x| \u2264 \u03b4 \u2192  |f x' - f x| \u2264 \u03b5) \u2194\nsorry\n:=\nbegin\n  sorry\nend\n\n/- Negation of \"f is sequentially continuous at x\u2080\" -/\n-- 0065\nexample : \u00ac (\u2200 u : \u2115 \u2192 \u211d, (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - x\u2080| \u2264 \u03b5) \u2192 (\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |(f \u2218 u) n - f x\u2080| \u2264 \u03b5))  \u2194\nsorry\n:=\nbegin\n  sorry\nend\nend\n\n/-\nWe now turn to elementary applications of negations to limits of sequences.\nRemember that `linarith` can find easy numerical contradictions.\n\nAlso recall the following lemmas:\n\nabs_le {x y : \u211d} : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\n/-- The sequence `u` tends to `+\u221e`. -/\ndef tendsto_infinity (u : \u2115 \u2192 \u211d) := \u2200 A, \u2203 N, \u2200 n \u2265 N, u n \u2265 A\n-/\n\n-- 0066\nexample {u : \u2115 \u2192 \u211d} : tendsto_infinity u \u2192 \u2200 l, \u00ac seq_limit u l :=\nbegin\n  intros u_inf l,\n  unfold seq_limit,\n  push_neg,\n  use (1:\u211d),\n  norm_num, -- I don't need to split! Before, I had `split,linarith`\n  intro N,\n  specialize u_inf (l+2),\n  cases u_inf with M HM,\n  let Max := max M N,\n  use Max,\n  specialize HM Max (by norm_num),\n  norm_num,\n  calc\n  1   < 2           : by linarith\n  ... \u2264 u Max - l   : by linarith\n  ... = |u Max - l| : by { rw abs_eq_self.2, linarith },\n  -- `rw` will put assumptions in as the new targets\nend\n\ndef nondecreasing_seq (u : \u2115 \u2192 \u211d) := \u2200 n m, n \u2264 m \u2192 u n \u2264 u m\n\n-- 0067\nexample (u : \u2115 \u2192 \u211d) (l : \u211d) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  \u2200 n, u n \u2264 l :=\nbegin\n  sorry\nend\n\n/-\nIn the following exercises, `A : set \u211d` means that A is a set of real numbers.\nWe can use the usual notation x \u2208 A.\n\nThe notation `\u2200 x \u2208 A, ...` is the abbreviation of `\u2200 x, x \u2208 A \u2192 ... `\n\nThe notation `\u2203 x \u2208 A, ...` is the abbreviation of `\u2203 x, x \u2208 A \u2227 ... `.\nMore precisely it is the abbreviation of `\u2203 x (H : x \u2208 A), ...`\nwhich is Lean's strange way of saying `\u2203 x, x \u2208 A \u2227 ... `. \nYou can convert between these forms using the lemma \n  exists_prop {p q : Prop} : (\u2203 (h : p), q) \u2194 p \u2227 q\n\nWe'll work with upper bounds and supremums.\nAgain we'll introduce specialized definitions for the sake of exercises, but mathlib\nhas more general versions.\n\n\ndef upper_bound (A : set \u211d) (x : \u211d) := \u2200 a \u2208 A, a \u2264 x\n\ndef is_sup (A : set \u211d) (x : \u211d) := upper_bound A x \u2227 \u2200 y, upper_bound A y \u2192 x \u2264 y\n\n\nRemark: one can easily show that a set of real numbers has at most one sup,\nbut we won't need this.\n-/\n\n-- 0068\nexample {A : set \u211d} {x : \u211d} (hx : is_sup A x) :\n\u2200 y, y < x \u2192 \u2203 a \u2208 A, y < a :=\nbegin\n  sorry\nend\n\n/-\nLet's do a variation on an example from file 07 that will be useful in the last\nexercise below.\n-/\n\n-- 0069\nlemma le_of_le_add_all' {x y : \u211d} :\n  (\u2200 \u03b5 > 0, y \u2264 x + \u03b5) \u2192  y \u2264 x :=\nbegin\n  sorry\nend\n\n-- 0070\nexample {x y : \u211d} {u : \u2115 \u2192 \u211d} (hu : seq_limit u x)\n  (ineg : \u2200 n, u n \u2264 y) : x \u2264 y :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "sterraf", "repo": "mylearninglean", "sha": "a8911234b2a4e15a48ec2c0f05d744e58f798ca7", "save_path": "github-repos/lean/sterraf-mylearninglean", "path": "github-repos/lean/sterraf-mylearninglean/mylearninglean-a8911234b2a4e15a48ec2c0f05d744e58f798ca7/src/tutorials_exercises/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.7036322415777202}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# Constructive bijections\n\nI'm generally quite anti-constructive mathematics; it makes stuff harder\nto do in Lean whilst only providing benefits such as computational content\nwhich I am typically not interested in (I never `#eval` stuff, I just\nwant to prove theorems and I don't care if the proof isn't `refl`).\n\nBut one example of where I love constructivism is `X \u2243 Y`, the class\nof constructive bijections from `X` to `Y`. What is a constructive\nbijection? It is a function `f : X \u2192 Y` plus some more data, but here\nthe data is *not* just the propositional claim that `f` is bijective\n(i.e. the *existence* of a two-sided inverse) -- it is the actual\ndata of the two-sided inverse too. \n\n`X \u2243 Y` is notation for `equiv X Y`. This is the type of constructive\nbijections from `X` to `Y`. To make a term of type `X \u2243 Y` you need\nto give a 4-tuple consisting of two functions `f : X \u2192 Y` and `g : Y \u2192 X`,\nplus also two proofs: firstly a proof of `\u2200 y, f (g y) = y`, and secondly\na proof of `\u2200 x, g (f x) = x`.\n\nNote that `X \u2243 Y` has type `Type`, not `Prop`. It does *not* mean \"there exists\na bijection from `X` to `Y`\", it is the actual data of a bijection\nfrom `X` to `Y`. \n\nLet's build two different bijections from \u211a to \u211a. \n\nThe first one is easy; I'll do it for you, to show you the syntax.\n\n-/\n\ndef bijection1 : \u211a \u2243 \u211a :=\n{ to_fun := id, -- use the identity function from \u211a to \u211a\n  inv_fun := id, -- its inverse is also the identity function\n  left_inv := begin -- we have to prove \u2200 q, id (id q) = q\n    intro q,\n    refl, \n  end,\n  right_inv := \u03bb q, rfl } -- same proof but in term mode\n\n-- Now see if you can do a harder one.\ndef bijection2 : \u211a \u2243 \u211a :=\n{ to_fun := \u03bb q, 3 * q + 4,\n  inv_fun := \u03bb r, (r - 4) / 3,\n  left_inv := begin -- start with `intro r`, then use `dsimp` to tidy up the mess\n    sorry,\n  end,\n  right_inv := begin\n    sorry,\n  end }  ", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section09bijections_and_isomorphisms/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.7036322362241709}}
{"text": "import algebra.big_operators.intervals algebra.big_operators.order algebra.big_operators.ring\n\n/-! # IMO 2021 A5 -/\n\nnamespace IMOSL\nnamespace IMO2021A5\n\nopen finset\n\nvariables {F : Type*} [linear_ordered_field F]\n\nprivate lemma bound1 {a : \u2115 \u2192 F} (h : \u2200 n : \u2115, 0 < a n) {n : \u2115} (h0 : (range n.succ).sum a \u2264 1) :\n  a n / (1 - a n) * ((range n).sum a) ^ 2 \u2264 (((range n.succ).sum a) ^ 3 - ((range n).sum a) ^ 3) / 3 :=\nbegin\n  rcases nat.eq_zero_or_pos n with rfl | h1,\n  rw [sum_range_zero, sum_range_one, zero_pow two_pos, mul_zero, zero_pow three_pos, sub_zero],\n  exact div_nonneg (pow_nonneg (le_of_lt (h 0)) 3) zero_le_three,\n  rw [sum_range_succ, add_comm] at h0 \u22a2,\n  have h2 : 0 \u2264 (range n).sum a := sum_nonneg (\u03bb i _, le_of_lt (h i)),\n  replace h := h n,\n  generalizes [hx : a n = x, hy : (range n).sum a = y],\n  rw \u2190 hx at h0 h; rw \u2190 hy at h0 h2,\n  clear h1 hx hy a n,\n  suffices : x / (1 - x) * y ^ 2 \u2264 x ^ 2 * y + x * y ^ 2,\n  { apply le_trans this,\n    rw \u2190 sub_nonneg; ring_nf,\n    exact mul_nonneg (div_nonneg zero_le_one zero_le_three) (pow_nonneg (le_of_lt h) 3) },\n  rw [\u2190 le_sub_iff_add_le', le_iff_eq_or_lt] at h0,\n  rcases h0 with rfl | h0,\n  { rw le_iff_eq_or_lt at h2,\n    rcases h2 with h2 | h2,\n    rw [\u2190 h2, sq, mul_zero, mul_zero, \u2190 add_mul, mul_zero],\n    rw [sq, \u2190 mul_assoc, div_mul_cancel x (ne_of_gt h2), sq, mul_assoc,\n        \u2190 mul_add, \u2190 add_mul, add_sub_cancel'_right, one_mul] },\n  { have h1 := ne_of_gt (lt_of_le_of_lt h2 h0),\n    rw [div_eq_mul_inv, mul_right_comm, \u2190 sub_le_iff_le_add, \u2190 mul_sub_one, inv_eq_one_div,\n        div_sub_one h1, sub_sub_cancel, \u2190 mul_div_assoc, mul_right_comm, \u2190 sq, sq y,\n        \u2190 mul_assoc, mul_div_assoc, \u2190 sub_nonpos, \u2190 mul_sub_one, div_sub_one h1],\n    refine mul_nonpos_of_nonneg_of_nonpos (mul_nonneg _ h2) (div_nonpos_of_nonpos_of_nonneg _ _),\n    exacts [sq_nonneg x, le_of_lt (by rwa sub_neg), le_trans h2 (le_of_lt h0)] }\nend\n\n\n\n/-- Final solution -/\ntheorem final_solution {a : \u2115 \u2192 F} (h : \u2200 n : \u2115, 0 < a n) {n : \u2115} (h0 : (range n).sum a \u2264 1) :\n  (range n).sum (\u03bb k, a k / (1 - a k) * ((range k).sum a) ^ 2) < 1 / 3 :=\nbegin\n  rcases nat.eq_zero_or_pos n with rfl | h1,\n  rw [sum_range_zero, one_div, inv_pos]; exact three_pos,\n  refine lt_of_lt_of_le (sum_lt_sum (\u03bb i h2, bound1 h _) _) _,\n  { rw [mem_range, \u2190 nat.succ_le_iff] at h2,\n    refine le_trans _ h0,\n    rw [\u2190 sum_range_add_sum_Ico a h2, le_add_iff_nonneg_right],\n    exact sum_nonneg (\u03bb i _, (le_of_lt (h i))) },\n  { use 0; split,\n    rwa mem_range,\n    rw [sum_range_zero, zero_pow two_pos, mul_zero, zero_pow three_pos, sub_zero, sum_range_one],\n    exact div_pos (pow_pos (h 0) 3) three_pos },\n  { rw [\u2190 sum_div, sum_range_sub (\u03bb i, (range i).sum a ^ 3)],\n    simp only [sub_zero, sum_range_zero, zero_pow three_pos],\n    exact div_le_div_of_le zero_le_three (pow_le_one 3 (sum_nonneg (\u03bb i _, le_of_lt (h i))) h0) }\nend\n\nend IMO2021A5\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2021/A5/A5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.7036322331663287}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport measure_theory.prod\n\n/-!\n# Measure preserving maps\n\nWe say that `f : \u03b1 \u2192 \u03b2` is a measure preserving map w.r.t. measures `\u03bc : measure \u03b1` and\n`\u03bd : measure \u03b2` if `f` is measurable and `map f \u03bc = \u03bd`. In this file we define the predicate\n`measure_theory.measure_preserving` and prove its basic properties.\n\nWe use the term \"measure preserving\" because in many applications `\u03b1 = \u03b2` and `\u03bc = \u03bd`.\n\n## References\n\nPartially based on\n[this](https://www.isa-afp.org/browser_info/current/AFP/Ergodic_Theory/Measure_Preserving_Transformations.html)\nIsabelle formalization.\n\n## Tags\n\nmeasure preserving map, measure\n-/\n\nvariables {\u03b1 \u03b2 \u03b3 \u03b4 : Type*} [measurable_space \u03b1] [measurable_space \u03b2] [measurable_space \u03b3]\n  [measurable_space \u03b4]\n\nnamespace measure_theory\n\nopen measure function set\n\nvariables {\u03bca : measure \u03b1} {\u03bcb : measure \u03b2} {\u03bcc : measure \u03b3} {\u03bcd : measure \u03b4}\n\n/-- `f` is a measure preserving map w.r.t. measures `\u03bca` and `\u03bcb` if `f` is measurable\nand `map f \u03bca = \u03bcb`. -/\n@[protect_proj]\nstructure measure_preserving (f : \u03b1 \u2192 \u03b2) (\u03bca : measure \u03b1 . volume_tac)\n  (\u03bcb : measure \u03b2 . volume_tac) : Prop :=\n(measurable : measurable f)\n(map_eq : map f \u03bca = \u03bcb)\n\nnamespace measure_preserving\n\nprotected lemma id (\u03bc : measure \u03b1) : measure_preserving id \u03bc \u03bc :=\n\u27e8measurable_id, map_id\u27e9\n\nprotected lemma quasi_measure_preserving {f : \u03b1 \u2192 \u03b2} (hf : measure_preserving f \u03bca \u03bcb) :\n  quasi_measure_preserving f \u03bca \u03bcb :=\n\u27e8hf.1, hf.2.absolutely_continuous\u27e9\n\nlemma comp {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2} (hg : measure_preserving g \u03bcb \u03bcc)\n  (hf : measure_preserving f \u03bca \u03bcb) :\n  measure_preserving (g \u2218 f) \u03bca \u03bcc :=\n\u27e8hg.1.comp hf.1, by rw [\u2190 map_map hg.1 hf.1, hf.2, hg.2]\u27e9\n\nprotected lemma sigma_finite {f : \u03b1 \u2192 \u03b2} (hf : measure_preserving f \u03bca \u03bcb) [sigma_finite \u03bcb] :\n  sigma_finite \u03bca :=\nsigma_finite.of_map \u03bca hf.1 (by rwa hf.map_eq)\n\nlemma measure_preimage {f : \u03b1 \u2192 \u03b2} (hf : measure_preserving f \u03bca \u03bcb)\n  {s : set \u03b2} (hs : measurable_set s) :\n  \u03bca (f \u207b\u00b9' s) = \u03bcb s :=\nby rw [\u2190 hf.map_eq, map_apply hf.1 hs]\n\nprotected lemma iterate {f : \u03b1 \u2192 \u03b1} (hf : measure_preserving f \u03bca \u03bca) :\n  \u2200 n, measure_preserving (f^[n]) \u03bca \u03bca\n| 0 := measure_preserving.id \u03bca\n| (n + 1) := (iterate n).comp hf\n\nlemma skew_product [sigma_finite \u03bcb] [sigma_finite \u03bcd]\n  {f : \u03b1 \u2192 \u03b2} (hf : measure_preserving f \u03bca \u03bcb) {g : \u03b1 \u2192 \u03b3 \u2192 \u03b4}\n  (hgm : measurable (uncurry g)) (hg : \u2200\u1d50 x \u2202\u03bca, map (g x) \u03bcc = \u03bcd) :\n  measure_preserving (\u03bb p : \u03b1 \u00d7 \u03b3, (f p.1, g p.1 p.2)) (\u03bca.prod \u03bcc) (\u03bcb.prod \u03bcd) :=\nbegin\n  classical,\n  have : measurable (\u03bb p : \u03b1 \u00d7 \u03b3, (f p.1, g p.1 p.2)) := (hf.1.comp measurable_fst).prod_mk hgm,\n  /- if `\u03bca = 0`, then the lemma is trivial, otherwise we can use `hg`\n  to deduce `sigma_finite \u03bcc`. -/\n  by_cases ha : \u03bca = 0,\n  { rw [\u2190 hf.map_eq, ha, zero_prod, (map f).map_zero, zero_prod],\n    exact \u27e8this, (map _).map_zero\u27e9 },\n  haveI : \u03bca.ae.ne_bot := ae_ne_bot.2 ha,\n  rcases hg.exists with \u27e8x, hx\u27e9,\n  haveI : sigma_finite \u03bcc := sigma_finite.of_map _ hgm.of_uncurry_left (by rwa hx),\n  clear hx x,\n  refine \u27e8this, (prod_eq $ \u03bb s t hs ht, _).symm\u27e9,\n  rw [map_apply this (hs.prod ht)],\n  refine (prod_apply (this $ hs.prod ht)).trans _,\n  have : \u2200\u1d50 x \u2202\u03bca, \u03bcc ((\u03bb y, (f x, g x y)) \u207b\u00b9' s.prod t) = indicator (f \u207b\u00b9' s) (\u03bb y, \u03bcd t) x,\n  { refine hg.mono (\u03bb x hx, _),\n    simp only [mk_preimage_prod_right_fn_eq_if, indicator_apply, mem_preimage],\n    split_ifs,\n    { rw [\u2190 map_apply hgm.of_uncurry_left ht, hx] },\n    { exact measure_empty } },\n  simp only [preimage_preimage],\n  rw [lintegral_congr_ae this, lintegral_indicator _ (hf.1 hs),\n    set_lintegral_const, hf.measure_preimage hs, mul_comm]\nend\n\n/-- If `f : \u03b1 \u2192 \u03b2` sends the measure `\u03bca` to `\u03bcb` and `g : \u03b3 \u2192 \u03b4` sends the measure `\u03bcc` to `\u03bcd`,\nthen `prod.map f g` sends `\u03bca.prod \u03bcc` to `\u03bcb.prod \u03bcd`. -/\nlemma prod [sigma_finite \u03bcb] [sigma_finite \u03bcd] {f : \u03b1 \u2192 \u03b2} {g : \u03b3 \u2192 \u03b4}\n  (hf : measure_preserving f \u03bca \u03bcb) (hg : measure_preserving g \u03bcc \u03bcd) :\n  measure_preserving (prod.map f g) (\u03bca.prod \u03bcc) (\u03bcb.prod \u03bcd) :=\nhave measurable (uncurry $ \u03bb _ : \u03b1, g), from (hg.1.comp measurable_snd),\nhf.skew_product this $ filter.eventually_of_forall $ \u03bb _, hg.map_eq\n\nvariables {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b1} {s : set \u03b1}\n\n/-- If `\u03bc univ < n * \u03bc s` and `f` is a map preserving measure `\u03bc`,\nthen for some `x \u2208 s` and `0 < m < n`, `f^[m] x \u2208 s`. -/\nlemma exists_mem_image_mem_of_volume_lt_mul_volume (hf : measure_preserving f \u03bc \u03bc)\n  (hs : measurable_set s) {n : \u2115} (hvol : \u03bc (univ : set \u03b1) < n * \u03bc s) :\n  \u2203 (x \u2208 s) (m \u2208 Ioo 0 n), f^[m] x \u2208 s :=\nbegin\n  have A : \u2200 m, measurable_set (f^[m] \u207b\u00b9' s) := \u03bb m, (hf.iterate m).measurable hs,\n  have B : \u2200 m, \u03bc (f^[m] \u207b\u00b9' s) = \u03bc s, from \u03bb m, (hf.iterate m).measure_preimage hs,\n  have : \u03bc (univ : set \u03b1) < (finset.range n).sum (\u03bb m, \u03bc (f^[m] \u207b\u00b9' s)),\n    by simpa only [B, nsmul_eq_mul, finset.sum_const, finset.card_range],\n  rcases exists_nonempty_inter_of_measure_univ_lt_sum_measure \u03bc (\u03bb m hm, A m) this\n    with \u27e8i, hi, j, hj, hij, x, hxi, hxj\u27e9,\n  -- without `tactic.skip` Lean closes the extra goal but it takes a long time; not sure why\n  wlog hlt : i < j := hij.lt_or_lt using [i j, j i] tactic.skip,\n  { simp only [set.mem_preimage, finset.mem_range] at hi hj hxi hxj,\n    refine \u27e8f^[i] x, hxi, j - i, \u27e8nat.sub_pos_of_lt hlt, lt_of_le_of_lt (j.sub_le i) hj\u27e9, _\u27e9,\n    rwa [\u2190 iterate_add_apply, nat.sub_add_cancel hlt.le] },\n  { exact \u03bb hi hj hij hxi hxj, this hj hi hij.symm hxj hxi }\nend\n\n/-- A self-map preserving a finite measure is conservative: if `\u03bc s \u2260 0`, then at least one point\n`x \u2208 s` comes back to `s` under iterations of `f`. Actually, a.e. point of `s` comes back to `s`\ninfinitely many times, see `measure_theory.measure_preserving.conservative` and theorems about\n`measure_theory.conservative`. -/\nlemma exists_mem_image_mem [finite_measure \u03bc] (hf : measure_preserving f \u03bc \u03bc)\n  (hs : measurable_set s) (hs' : \u03bc s \u2260 0) :\n  \u2203 (x \u2208 s) (m \u2260 0), f^[m] x \u2208 s :=\nbegin\n  rcases ennreal.exists_nat_mul_gt hs' (measure_ne_top \u03bc (univ : set \u03b1)) with \u27e8N, hN\u27e9,\n  rcases hf.exists_mem_image_mem_of_volume_lt_mul_volume hs hN with \u27e8x, hx, m, hm, hmx\u27e9,\n  exact \u27e8x, hx, m, hm.1.ne', hmx\u27e9\nend\n\nend measure_preserving\n\nend measure_theory\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/dynamics/ergodic/measure_preserving.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7035011033832844}}
{"text": "/-\nCopyright (c) 2020 David W\u00e4rn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David W\u00e4rn\n\n! This file was ported from Lean 3 source module order.ideal\n! leanprover-community/mathlib commit 0ebfdb71919ac6ca5d7fbc61a082fa2519556818\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Logic.Encodable.Basic\nimport Mathbin.Order.Atoms\nimport Mathbin.Order.UpperLower.Basic\n\n/-!\n# Order ideals, cofinal sets, and the Rasiowa\u2013Sikorski lemma\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Main definitions\n\nThroughout this file, `P` is at least a preorder, but some sections require more\nstructure, such as a bottom element, a top element, or a join-semilattice structure.\n- `order.ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.\n  Dual to the notion of a filter on a preorder.\n- `order.is_ideal P`: a predicate for when a `set P` is an ideal.\n- `order.ideal.principal p`: the principal ideal generated by `p : P`.\n- `order.ideal.is_proper P`: a predicate for proper ideals.\n  Dual to the notion of a proper filter.\n- `order.ideal.is_maximal`: a predicate for maximal ideals.\n  Dual to the notion of an ultrafilter.\n- `order.cofinal P`: the type of subsets of `P` containing arbitrarily large elements.\n  Dual to the notion of 'dense set' used in forcing.\n- `order.ideal_of_cofinals p \ud835\udc9f`, where `p : P`, and `\ud835\udc9f` is a countable family of cofinal\n  subsets of P: an ideal in `P` which contains `p` and intersects every set in `\ud835\udc9f`. (This a form\n  of the Rasiowa\u2013Sikorski lemma.)\n\n## References\n\n- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>\n- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>\n- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>\n\nNote that for the Rasiowa\u2013Sikorski lemma, Wikipedia uses the opposite ordering on `P`,\nin line with most presentations of forcing.\n\n## Tags\n\nideal, cofinal, dense, countable, generic\n\n-/\n\n\nopen Function Set\n\nnamespace Order\n\nvariable {P : Type _}\n\n#print Order.Ideal /-\n/-- An ideal on an order `P` is a subset of `P` that is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\nstructure Ideal (P) [LE P] extends LowerSet P where\n  nonempty' : carrier.Nonempty\n  directed' : DirectedOn (\u00b7 \u2264 \u00b7) carrier\n#align order.ideal Order.Ideal\n-/\n\n#print Order.IsIdeal /-\n/-- A subset of a preorder `P` is an ideal if it is\n  - nonempty\n  - upward directed (any pair of elements in the ideal has an upper bound in the ideal)\n  - downward closed (any element less than an element of the ideal is in the ideal). -/\n@[mk_iff]\nstructure IsIdeal {P} [LE P] (I : Set P) : Prop where\n  IsLowerSet : IsLowerSet I\n  Nonempty : I.Nonempty\n  Directed : DirectedOn (\u00b7 \u2264 \u00b7) I\n#align order.is_ideal Order.IsIdeal\n-/\n\n#print Order.IsIdeal.toIdeal /-\n/-- Create an element of type `order.ideal` from a set satisfying the predicate\n`order.is_ideal`. -/\ndef IsIdeal.toIdeal [LE P] {I : Set P} (h : IsIdeal I) : Ideal P :=\n  \u27e8\u27e8I, h.IsLowerSet\u27e9, h.Nonempty, h.Directed\u27e9\n#align order.is_ideal.to_ideal Order.IsIdeal.toIdeal\n-/\n\nnamespace Ideal\n\nsection LE\n\nvariable [LE P]\n\nsection\n\nvariable {I J s t : Ideal P} {x y : P}\n\n#print Order.Ideal.toLowerSet_injective /-\ntheorem toLowerSet_injective : Injective (toLowerSet : Ideal P \u2192 LowerSet P) := fun s t h =>\n  by\n  cases s\n  cases t\n  congr\n#align order.ideal.to_lower_set_injective Order.Ideal.toLowerSet_injective\n-/\n\ninstance : SetLike (Ideal P) P where\n  coe s := s.carrier\n  coe_injective' s t h := toLowerSet_injective <| SetLike.coe_injective h\n\n#print Order.Ideal.ext /-\n@[ext]\ntheorem ext {s t : Ideal P} : (s : Set P) = t \u2192 s = t :=\n  SetLike.ext'\n#align order.ideal.ext Order.Ideal.ext\n-/\n\n#print Order.Ideal.carrier_eq_coe /-\n@[simp]\ntheorem carrier_eq_coe (s : Ideal P) : s.carrier = s :=\n  rfl\n#align order.ideal.carrier_eq_coe Order.Ideal.carrier_eq_coe\n-/\n\n#print Order.Ideal.coe_toLowerSet /-\n@[simp]\ntheorem coe_toLowerSet (s : Ideal P) : (s.toLowerSet : Set P) = s :=\n  rfl\n#align order.ideal.coe_to_lower_set Order.Ideal.coe_toLowerSet\n-/\n\n#print Order.Ideal.lower /-\nprotected theorem lower (s : Ideal P) : IsLowerSet (s : Set P) :=\n  s.lower'\n#align order.ideal.lower Order.Ideal.lower\n-/\n\n#print Order.Ideal.nonempty /-\nprotected theorem nonempty (s : Ideal P) : (s : Set P).Nonempty :=\n  s.nonempty'\n#align order.ideal.nonempty Order.Ideal.nonempty\n-/\n\n#print Order.Ideal.directed /-\nprotected theorem directed (s : Ideal P) : DirectedOn (\u00b7 \u2264 \u00b7) (s : Set P) :=\n  s.directed'\n#align order.ideal.directed Order.Ideal.directed\n-/\n\n#print Order.Ideal.isIdeal /-\nprotected theorem isIdeal (s : Ideal P) : IsIdeal (s : Set P) :=\n  \u27e8s.lower, s.Nonempty, s.Directed\u27e9\n#align order.ideal.is_ideal Order.Ideal.isIdeal\n-/\n\n/- warning: order.ideal.mem_compl_of_ge -> Order.Ideal.mem_compl_of_ge is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {I : Order.Ideal.{u1} P _inst_1} {x : P} {y : P}, (LE.le.{u1} P _inst_1 x y) -> (Membership.Mem.{u1, u1} P (Set.{u1} P) (Set.hasMem.{u1} P) x (HasCompl.compl.{u1} (Set.{u1} P) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} P) (Set.booleanAlgebra.{u1} P)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) I))) -> (Membership.Mem.{u1, u1} P (Set.{u1} P) (Set.hasMem.{u1} P) y (HasCompl.compl.{u1} (Set.{u1} P) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} P) (Set.booleanAlgebra.{u1} P)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) I)))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {I : Order.Ideal.{u1} P _inst_1} {x : P} {y : P}, (LE.le.{u1} P _inst_1 x y) -> (Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) x (HasCompl.compl.{u1} (Set.{u1} P) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} P) (Set.instBooleanAlgebraSet.{u1} P)) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) I))) -> (Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) y (HasCompl.compl.{u1} (Set.{u1} P) (BooleanAlgebra.toHasCompl.{u1} (Set.{u1} P) (Set.instBooleanAlgebraSet.{u1} P)) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) I)))\nCase conversion may be inaccurate. Consider using '#align order.ideal.mem_compl_of_ge Order.Ideal.mem_compl_of_ge\u2093'. -/\ntheorem mem_compl_of_ge {x y : P} : x \u2264 y \u2192 x \u2208 (I : Set P)\u1d9c \u2192 y \u2208 (I : Set P)\u1d9c := fun h =>\n  mt <| I.lower h\n#align order.ideal.mem_compl_of_ge Order.Ideal.mem_compl_of_ge\n\n/-- The partial ordering by subset inclusion, inherited from `set P`. -/\ninstance : PartialOrder (Ideal P) :=\n  PartialOrder.lift coe SetLike.coe_injective\n\n/- warning: order.ideal.coe_subset_coe -> Order.Ideal.coe_subset_coe is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {s : Order.Ideal.{u1} P _inst_1} {t : Order.Ideal.{u1} P _inst_1}, Iff (HasSubset.Subset.{u1} (Set.{u1} P) (Set.hasSubset.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) t)) (LE.le.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) s t)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {s : Order.Ideal.{u1} P _inst_1} {t : Order.Ideal.{u1} P _inst_1}, Iff (HasSubset.Subset.{u1} (Set.{u1} P) (Set.instHasSubsetSet.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) s) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) t)) (LE.le.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) s t)\nCase conversion may be inaccurate. Consider using '#align order.ideal.coe_subset_coe Order.Ideal.coe_subset_coe\u2093'. -/\n@[simp]\ntheorem coe_subset_coe : (s : Set P) \u2286 t \u2194 s \u2264 t :=\n  Iff.rfl\n#align order.ideal.coe_subset_coe Order.Ideal.coe_subset_coe\n\n/- warning: order.ideal.coe_ssubset_coe -> Order.Ideal.coe_ssubset_coe is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {s : Order.Ideal.{u1} P _inst_1} {t : Order.Ideal.{u1} P _inst_1}, Iff (HasSSubset.SSubset.{u1} (Set.{u1} P) (Set.hasSsubset.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) t)) (LT.lt.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLT.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) s t)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {s : Order.Ideal.{u1} P _inst_1} {t : Order.Ideal.{u1} P _inst_1}, Iff (HasSSubset.SSubset.{u1} (Set.{u1} P) (Set.instHasSSubsetSet.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) s) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) t)) (LT.lt.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLT.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) s t)\nCase conversion may be inaccurate. Consider using '#align order.ideal.coe_ssubset_coe Order.Ideal.coe_ssubset_coe\u2093'. -/\n@[simp]\ntheorem coe_ssubset_coe : (s : Set P) \u2282 t \u2194 s < t :=\n  Iff.rfl\n#align order.ideal.coe_ssubset_coe Order.Ideal.coe_ssubset_coe\n\n/- warning: order.ideal.mem_of_mem_of_le -> Order.Ideal.mem_of_mem_of_le is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {x : P} {I : Order.Ideal.{u1} P _inst_1} {J : Order.Ideal.{u1} P _inst_1}, (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)) x I) -> (LE.le.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) I J) -> (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)) x J)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] {x : P} {I : Order.Ideal.{u1} P _inst_1} {J : Order.Ideal.{u1} P _inst_1}, (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1)) x I) -> (LE.le.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) I J) -> (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1)) x J)\nCase conversion may be inaccurate. Consider using '#align order.ideal.mem_of_mem_of_le Order.Ideal.mem_of_mem_of_le\u2093'. -/\n@[trans]\ntheorem mem_of_mem_of_le {x : P} {I J : Ideal P} : x \u2208 I \u2192 I \u2264 J \u2192 x \u2208 J :=\n  @Set.mem_of_mem_of_subset P x I J\n#align order.ideal.mem_of_mem_of_le Order.Ideal.mem_of_mem_of_le\n\n#print Order.Ideal.IsProper /-\n/-- A proper ideal is one that is not the whole set.\n    Note that the whole set might not be an ideal. -/\n@[mk_iff]\nclass IsProper (I : Ideal P) : Prop where\n  ne_univ : (I : Set P) \u2260 univ\n#align order.ideal.is_proper Order.Ideal.IsProper\n-/\n\n#print Order.Ideal.isProper_of_not_mem /-\ntheorem isProper_of_not_mem {I : Ideal P} {p : P} (nmem : p \u2209 I) : IsProper I :=\n  \u27e8fun hp => by\n    change p \u2209 \u2191I at nmem\n    rw [hp] at nmem\n    exact nmem (mem_univ p)\u27e9\n#align order.ideal.is_proper_of_not_mem Order.Ideal.isProper_of_not_mem\n-/\n\n#print Order.Ideal.IsMaximal /-\n/-- An ideal is maximal if it is maximal in the collection of proper ideals.\n\nNote that `is_coatom` is less general because ideals only have a top element when `P` is directed\nand nonempty. -/\n@[mk_iff]\nclass IsMaximal (I : Ideal P) extends IsProper I : Prop where\n  maximal_proper : \u2200 \u2983J : Ideal P\u2984, I < J \u2192 (J : Set P) = univ\n#align order.ideal.is_maximal Order.Ideal.IsMaximal\n-/\n\n/- warning: order.ideal.inter_nonempty -> Order.Ideal.inter_nonempty is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (GE.ge.{u1} P _inst_1)] (I : Order.Ideal.{u1} P _inst_1) (J : Order.Ideal.{u1} P _inst_1), Set.Nonempty.{u1} P (Inter.inter.{u1} (Set.{u1} P) (Set.hasInter.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) I) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) J))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.883 : P) (x._@.Mathlib.Order.Ideal._hyg.885 : P) => GE.ge.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.883 x._@.Mathlib.Order.Ideal._hyg.885)] (I : Order.Ideal.{u1} P _inst_1) (J : Order.Ideal.{u1} P _inst_1), Set.Nonempty.{u1} P (Inter.inter.{u1} (Set.{u1} P) (Set.instInterSet.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) I) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) J))\nCase conversion may be inaccurate. Consider using '#align order.ideal.inter_nonempty Order.Ideal.inter_nonempty\u2093'. -/\ntheorem inter_nonempty [IsDirected P (\u00b7 \u2265 \u00b7)] (I J : Ideal P) : (I \u2229 J : Set P).Nonempty :=\n  by\n  obtain \u27e8a, ha\u27e9 := I.nonempty\n  obtain \u27e8b, hb\u27e9 := J.nonempty\n  obtain \u27e8c, hac, hbc\u27e9 := exists_le_le a b\n  exact \u27e8c, I.lower hac ha, J.lower hbc hb\u27e9\n#align order.ideal.inter_nonempty Order.Ideal.inter_nonempty\n\nend\n\nsection Directed\n\nvariable [IsDirected P (\u00b7 \u2264 \u00b7)] [Nonempty P] {I : Ideal P}\n\n/-- In a directed and nonempty order, the top ideal of a is `univ`. -/\ninstance : OrderTop (Ideal P)\n    where\n  top := \u27e8\u22a4, univ_nonempty, directedOn_univ\u27e9\n  le_top I := le_top\n\n/- warning: order.ideal.top_to_lower_set -> Order.Ideal.top_toLowerSet is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P], Eq.{succ u1} (LowerSet.{u1} P _inst_1) (Order.Ideal.toLowerSet.{u1} P _inst_1 (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toHasTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3)))) (Top.top.{u1} (LowerSet.{u1} P _inst_1) (LowerSet.hasTop.{u1} P _inst_1))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1034 : P) (x._@.Mathlib.Order.Ideal._hyg.1036 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1034 x._@.Mathlib.Order.Ideal._hyg.1036)] [_inst_3 : Nonempty.{succ u1} P], Eq.{succ u1} (LowerSet.{u1} P _inst_1) (Order.Ideal.toLowerSet.{u1} P _inst_1 (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3)))) (Top.top.{u1} (LowerSet.{u1} P _inst_1) (LowerSet.instTopLowerSet.{u1} P _inst_1))\nCase conversion may be inaccurate. Consider using '#align order.ideal.top_to_lower_set Order.Ideal.top_toLowerSet\u2093'. -/\n@[simp]\ntheorem top_toLowerSet : (\u22a4 : Ideal P).toLowerSet = \u22a4 :=\n  rfl\n#align order.ideal.top_to_lower_set Order.Ideal.top_toLowerSet\n\n/- warning: order.ideal.coe_top -> Order.Ideal.coe_top is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P], Eq.{succ u1} (Set.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P _inst_1) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)))) (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toHasTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3)))) (Set.univ.{u1} P)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1077 : P) (x._@.Mathlib.Order.Ideal._hyg.1079 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1077 x._@.Mathlib.Order.Ideal._hyg.1079)] [_inst_3 : Nonempty.{succ u1} P], Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1) (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3)))) (Set.univ.{u1} P)\nCase conversion may be inaccurate. Consider using '#align order.ideal.coe_top Order.Ideal.coe_top\u2093'. -/\n@[simp]\ntheorem coe_top : ((\u22a4 : Ideal P) : Set P) = univ :=\n  rfl\n#align order.ideal.coe_top Order.Ideal.coe_top\n\n/- warning: order.ideal.is_proper_of_ne_top -> Order.Ideal.isProper_of_ne_top is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (Ne.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toHasTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3)))) -> (Order.Ideal.IsProper.{u1} P _inst_1 I)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1123 : P) (x._@.Mathlib.Order.Ideal._hyg.1125 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1123 x._@.Mathlib.Order.Ideal._hyg.1125)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (Ne.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3)))) -> (Order.Ideal.IsProper.{u1} P _inst_1 I)\nCase conversion may be inaccurate. Consider using '#align order.ideal.is_proper_of_ne_top Order.Ideal.isProper_of_ne_top\u2093'. -/\ntheorem isProper_of_ne_top (ne_top : I \u2260 \u22a4) : IsProper I :=\n  \u27e8fun h => ne_top <| ext h\u27e9\n#align order.ideal.is_proper_of_ne_top Order.Ideal.isProper_of_ne_top\n\n/- warning: order.ideal.is_proper.ne_top -> Order.Ideal.IsProper.ne_top is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (Order.Ideal.IsProper.{u1} P _inst_1 I) -> (Ne.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toHasTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1174 : P) (x._@.Mathlib.Order.Ideal._hyg.1176 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1174 x._@.Mathlib.Order.Ideal._hyg.1176)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (Order.Ideal.IsProper.{u1} P _inst_1 I) -> (Ne.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.is_proper.ne_top Order.Ideal.IsProper.ne_top\u2093'. -/\ntheorem IsProper.ne_top (hI : IsProper I) : I \u2260 \u22a4 := fun h => IsProper.ne_univ <| congr_arg coe h\n#align order.ideal.is_proper.ne_top Order.Ideal.IsProper.ne_top\n\n/- warning: is_coatom.is_proper -> Order.Ideal.IsCoatom.isProper is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1)) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3) I) -> (Order.Ideal.IsProper.{u1} P _inst_1 I)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1226 : P) (x._@.Mathlib.Order.Ideal._hyg.1228 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1226 x._@.Mathlib.Order.Ideal._hyg.1228)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1)) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3) I) -> (Order.Ideal.IsProper.{u1} P _inst_1 I)\nCase conversion may be inaccurate. Consider using '#align is_coatom.is_proper Order.Ideal.IsCoatom.isProper\u2093'. -/\ntheorem Order.Ideal.IsCoatom.isProper (hI : IsCoatom I) : IsProper I :=\n  isProper_of_ne_top hI.1\n#align is_coatom.is_proper Order.Ideal.IsCoatom.isProper\n\n/- warning: order.ideal.is_proper_iff_ne_top -> Order.Ideal.isProper_iff_ne_top is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, Iff (Order.Ideal.IsProper.{u1} P _inst_1 I) (Ne.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toHasTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1262 : P) (x._@.Mathlib.Order.Ideal._hyg.1264 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1262 x._@.Mathlib.Order.Ideal._hyg.1264)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, Iff (Order.Ideal.IsProper.{u1} P _inst_1 I) (Ne.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.is_proper_iff_ne_top Order.Ideal.isProper_iff_ne_top\u2093'. -/\ntheorem isProper_iff_ne_top : IsProper I \u2194 I \u2260 \u22a4 :=\n  \u27e8fun h => h.ne_top, fun h => isProper_of_ne_top h\u27e9\n#align order.ideal.is_proper_iff_ne_top Order.Ideal.isProper_iff_ne_top\n\n/- warning: order.ideal.is_maximal.is_coatom -> Order.Ideal.IsMaximal.isCoatom is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (Order.Ideal.IsMaximal.{u1} P _inst_1 I) -> (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1)) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3) I)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1317 : P) (x._@.Mathlib.Order.Ideal._hyg.1319 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1317 x._@.Mathlib.Order.Ideal._hyg.1319)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (Order.Ideal.IsMaximal.{u1} P _inst_1 I) -> (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1)) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3) I)\nCase conversion may be inaccurate. Consider using '#align order.ideal.is_maximal.is_coatom Order.Ideal.IsMaximal.isCoatom\u2093'. -/\ntheorem IsMaximal.isCoatom (h : IsMaximal I) : IsCoatom I :=\n  \u27e8IsMaximal.to_isProper.ne_top, fun J h => ext <| IsMaximal.maximal_proper h\u27e9\n#align order.ideal.is_maximal.is_coatom Order.Ideal.IsMaximal.isCoatom\n\n/- warning: order.ideal.is_maximal.is_coatom' -> Order.Ideal.IsMaximal.isCoatom' is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1} [_inst_4 : Order.Ideal.IsMaximal.{u1} P _inst_1 I], IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1)) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3) I\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1368 : P) (x._@.Mathlib.Order.Ideal._hyg.1370 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1368 x._@.Mathlib.Order.Ideal._hyg.1370)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1} [_inst_4 : Order.Ideal.IsMaximal.{u1} P _inst_1 I], IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1)) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3) I\nCase conversion may be inaccurate. Consider using '#align order.ideal.is_maximal.is_coatom' Order.Ideal.IsMaximal.isCoatom'\u2093'. -/\ntheorem IsMaximal.isCoatom' [IsMaximal I] : IsCoatom I :=\n  IsMaximal.isCoatom \u2039_\u203a\n#align order.ideal.is_maximal.is_coatom' Order.Ideal.IsMaximal.isCoatom'\n\n/- warning: is_coatom.is_maximal -> Order.Ideal.IsCoatom.isMaximal is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1)) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3) I) -> (Order.Ideal.IsMaximal.{u1} P _inst_1 I)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1416 : P) (x._@.Mathlib.Order.Ideal._hyg.1418 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1416 x._@.Mathlib.Order.Ideal._hyg.1418)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1)) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3) I) -> (Order.Ideal.IsMaximal.{u1} P _inst_1 I)\nCase conversion may be inaccurate. Consider using '#align is_coatom.is_maximal Order.Ideal.IsCoatom.isMaximal\u2093'. -/\ntheorem Order.Ideal.IsCoatom.isMaximal (hI : IsCoatom I) : IsMaximal I :=\n  { Order.Ideal.IsCoatom.isProper \u2039_\u203a with maximal_proper := fun _ _ => by simp [hI.2 _ \u2039_\u203a] }\n#align is_coatom.is_maximal Order.Ideal.IsCoatom.isMaximal\n\n/- warning: order.ideal.is_maximal_iff_is_coatom -> Order.Ideal.isMaximal_iff_isCoatom is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (LE.le.{u1} P _inst_1)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, Iff (Order.Ideal.IsMaximal.{u1} P _inst_1 I) (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1)) (Order.Ideal.orderTop.{u1} P _inst_1 _inst_2 _inst_3) I)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.1476 : P) (x._@.Mathlib.Order.Ideal._hyg.1478 : P) => LE.le.{u1} P _inst_1 x._@.Mathlib.Order.Ideal._hyg.1476 x._@.Mathlib.Order.Ideal._hyg.1478)] [_inst_3 : Nonempty.{succ u1} P] {I : Order.Ideal.{u1} P _inst_1}, Iff (Order.Ideal.IsMaximal.{u1} P _inst_1 I) (IsCoatom.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1)) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2 _inst_3) I)\nCase conversion may be inaccurate. Consider using '#align order.ideal.is_maximal_iff_is_coatom Order.Ideal.isMaximal_iff_isCoatom\u2093'. -/\ntheorem isMaximal_iff_isCoatom : IsMaximal I \u2194 IsCoatom I :=\n  \u27e8fun h => h.IsCoatom, fun h => h.IsMaximal\u27e9\n#align order.ideal.is_maximal_iff_is_coatom Order.Ideal.isMaximal_iff_isCoatom\n\nend Directed\n\nsection OrderBot\n\nvariable [OrderBot P]\n\n/- warning: order.ideal.bot_mem -> Order.Ideal.bot_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : OrderBot.{u1} P _inst_1] (s : Order.Ideal.{u1} P _inst_1), Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)) (Bot.bot.{u1} P (OrderBot.toHasBot.{u1} P _inst_1 _inst_2)) s\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : OrderBot.{u1} P _inst_1] (s : Order.Ideal.{u1} P _inst_1), Membership.mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1)) (Bot.bot.{u1} P (OrderBot.toBot.{u1} P _inst_1 _inst_2)) s\nCase conversion may be inaccurate. Consider using '#align order.ideal.bot_mem Order.Ideal.bot_mem\u2093'. -/\n@[simp]\ntheorem bot_mem (s : Ideal P) : \u22a5 \u2208 s :=\n  s.lower bot_le s.Nonempty.some_mem\n#align order.ideal.bot_mem Order.Ideal.bot_mem\n\nend OrderBot\n\nsection OrderTop\n\nvariable [OrderTop P] {I : Ideal P}\n\n/- warning: order.ideal.top_of_top_mem -> Order.Ideal.top_of_top_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : OrderTop.{u1} P _inst_1] {I : Order.Ideal.{u1} P _inst_1}, (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)) (Top.top.{u1} P (OrderTop.toHasTop.{u1} P _inst_1 _inst_2)) I) -> (Eq.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toHasTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.partialOrder.{u1} P _inst_1))) (Order.Ideal.orderTop.{u1} P _inst_1 (OrderTop.to_isDirected_le.{u1} P _inst_1 _inst_2) (top_nonempty.{u1} P (OrderTop.toHasTop.{u1} P _inst_1 _inst_2))))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : OrderTop.{u1} P _inst_1] {I : Order.Ideal.{u1} P _inst_1}, (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1)) (Top.top.{u1} P (OrderTop.toTop.{u1} P _inst_1 _inst_2)) I) -> (Eq.{succ u1} (Order.Ideal.{u1} P _inst_1) I (Top.top.{u1} (Order.Ideal.{u1} P _inst_1) (OrderTop.toTop.{u1} (Order.Ideal.{u1} P _inst_1) (Preorder.toLE.{u1} (Order.Ideal.{u1} P _inst_1) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P _inst_1) (Order.Ideal.instPartialOrderIdeal.{u1} P _inst_1))) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 (OrderTop.to_isDirected_le.{u1} P _inst_1 _inst_2) (top_nonempty.{u1} P (OrderTop.toTop.{u1} P _inst_1 _inst_2))))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.top_of_top_mem Order.Ideal.top_of_top_mem\u2093'. -/\ntheorem top_of_top_mem (h : \u22a4 \u2208 I) : I = \u22a4 := by\n  ext\n  exact iff_of_true (I.lower le_top h) trivial\n#align order.ideal.top_of_top_mem Order.Ideal.top_of_top_mem\n\n/- warning: order.ideal.is_proper.top_not_mem -> Order.Ideal.IsProper.top_not_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : OrderTop.{u1} P _inst_1] {I : Order.Ideal.{u1} P _inst_1}, (Order.Ideal.IsProper.{u1} P _inst_1 I) -> (Not (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.setLike.{u1} P _inst_1)) (Top.top.{u1} P (OrderTop.toHasTop.{u1} P _inst_1 _inst_2)) I))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : LE.{u1} P] [_inst_2 : OrderTop.{u1} P _inst_1] {I : Order.Ideal.{u1} P _inst_1}, (Order.Ideal.IsProper.{u1} P _inst_1 I) -> (Not (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P _inst_1) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P _inst_1) P (Order.Ideal.instSetLikeIdeal.{u1} P _inst_1)) (Top.top.{u1} P (OrderTop.toTop.{u1} P _inst_1 _inst_2)) I))\nCase conversion may be inaccurate. Consider using '#align order.ideal.is_proper.top_not_mem Order.Ideal.IsProper.top_not_mem\u2093'. -/\ntheorem IsProper.top_not_mem (hI : IsProper I) : \u22a4 \u2209 I := fun h => hI.ne_top <| top_of_top_mem h\n#align order.ideal.is_proper.top_not_mem Order.Ideal.IsProper.top_not_mem\n\nend OrderTop\n\nend LE\n\nsection Preorder\n\nvariable [Preorder P]\n\nsection\n\nvariable {I J : Ideal P} {x y : P}\n\n#print Order.Ideal.principal /-\n/-- The smallest ideal containing a given element. -/\n@[simps]\ndef principal (p : P) : Ideal P where\n  toLowerSet := LowerSet.Iic p\n  nonempty' := nonempty_Iic\n  directed' x hx y hy := \u27e8p, le_rfl, hx, hy\u27e9\n#align order.ideal.principal Order.Ideal.principal\n-/\n\ninstance [Inhabited P] : Inhabited (Ideal P) :=\n  \u27e8Ideal.principal default\u27e9\n\n/- warning: order.ideal.principal_le_iff -> Order.Ideal.principal_le_iff is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)} {x : P}, Iff (LE.le.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Preorder.toLE.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.partialOrder.{u1} P (Preorder.toLE.{u1} P _inst_1)))) (Order.Ideal.principal.{u1} P _inst_1 x) I) (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P _inst_1))) x I)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)} {x : P}, Iff (LE.le.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Preorder.toLE.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.instPartialOrderIdeal.{u1} P (Preorder.toLE.{u1} P _inst_1)))) (Order.Ideal.principal.{u1} P _inst_1 x) I) (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P _inst_1))) x I)\nCase conversion may be inaccurate. Consider using '#align order.ideal.principal_le_iff Order.Ideal.principal_le_iff\u2093'. -/\n@[simp]\ntheorem principal_le_iff : principal x \u2264 I \u2194 x \u2208 I :=\n  \u27e8fun h => h le_rfl, fun hx y hy => I.lower hy hx\u27e9\n#align order.ideal.principal_le_iff Order.Ideal.principal_le_iff\n\n#print Order.Ideal.mem_principal /-\n@[simp]\ntheorem mem_principal : x \u2208 principal y \u2194 x \u2264 y :=\n  Iff.rfl\n#align order.ideal.mem_principal Order.Ideal.mem_principal\n-/\n\nend\n\nsection OrderBot\n\nvariable [OrderBot P]\n\n/-- There is a bottom ideal when `P` has a bottom element. -/\ninstance : OrderBot (Ideal P) where\n  bot := principal \u22a5\n  bot_le := by simp\n\n/- warning: order.ideal.principal_bot -> Order.Ideal.principal_bot is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] [_inst_2 : OrderBot.{u1} P (Preorder.toLE.{u1} P _inst_1)], Eq.{succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.principal.{u1} P _inst_1 (Bot.bot.{u1} P (OrderBot.toHasBot.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2))) (Bot.bot.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (OrderBot.toHasBot.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Preorder.toLE.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.partialOrder.{u1} P (Preorder.toLE.{u1} P _inst_1)))) (Order.Ideal.orderBot.{u1} P _inst_1 _inst_2)))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] [_inst_2 : OrderBot.{u1} P (Preorder.toLE.{u1} P _inst_1)], Eq.{succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.principal.{u1} P _inst_1 (Bot.bot.{u1} P (OrderBot.toBot.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2))) (Bot.bot.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (OrderBot.toBot.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Preorder.toLE.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.instPartialOrderIdeal.{u1} P (Preorder.toLE.{u1} P _inst_1)))) (Order.Ideal.instOrderBotIdealToLEToPreorderInstPartialOrderIdeal.{u1} P _inst_1 _inst_2)))\nCase conversion may be inaccurate. Consider using '#align order.ideal.principal_bot Order.Ideal.principal_bot\u2093'. -/\n@[simp]\ntheorem principal_bot : principal (\u22a5 : P) = \u22a5 :=\n  rfl\n#align order.ideal.principal_bot Order.Ideal.principal_bot\n\nend OrderBot\n\nsection OrderTop\n\nvariable [OrderTop P]\n\n/- warning: order.ideal.principal_top -> Order.Ideal.principal_top is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] [_inst_2 : OrderTop.{u1} P (Preorder.toLE.{u1} P _inst_1)], Eq.{succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.principal.{u1} P _inst_1 (Top.top.{u1} P (OrderTop.toHasTop.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2))) (Top.top.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (OrderTop.toHasTop.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Preorder.toLE.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.partialOrder.{u1} P (Preorder.toLE.{u1} P _inst_1)))) (Order.Ideal.orderTop.{u1} P (Preorder.toLE.{u1} P _inst_1) (OrderTop.to_isDirected_le.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2) (top_nonempty.{u1} P (OrderTop.toHasTop.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2)))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] [_inst_2 : OrderTop.{u1} P (Preorder.toLE.{u1} P _inst_1)], Eq.{succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.principal.{u1} P _inst_1 (Top.top.{u1} P (OrderTop.toTop.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2))) (Top.top.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (OrderTop.toTop.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Preorder.toLE.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (Order.Ideal.instPartialOrderIdeal.{u1} P (Preorder.toLE.{u1} P _inst_1)))) (Order.Ideal.instOrderTopIdealToLEToPreorderInstPartialOrderIdeal.{u1} P (Preorder.toLE.{u1} P _inst_1) (OrderTop.to_isDirected_le.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2) (top_nonempty.{u1} P (OrderTop.toTop.{u1} P (Preorder.toLE.{u1} P _inst_1) _inst_2)))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.principal_top Order.Ideal.principal_top\u2093'. -/\n@[simp]\ntheorem principal_top : principal (\u22a4 : P) = \u22a4 :=\n  toLowerSet_injective <| LowerSet.Iic_top\n#align order.ideal.principal_top Order.Ideal.principal_top\n\nend OrderTop\n\nend Preorder\n\nsection SemilatticeSup\n\nvariable [SemilatticeSup P] {x y : P} {I s : Ideal P}\n\n/- warning: order.ideal.sup_mem -> Order.Ideal.sup_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] {x : P} {y : P} {s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x s) -> (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) y s) -> (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Sup.sup.{u1} P (SemilatticeSup.toHasSup.{u1} P _inst_1) x y) s)\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] {x : P} {y : P} {s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x s) -> (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) y s) -> (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Sup.sup.{u1} P (SemilatticeSup.toSup.{u1} P _inst_1) x y) s)\nCase conversion may be inaccurate. Consider using '#align order.ideal.sup_mem Order.Ideal.sup_mem\u2093'. -/\n/-- A specific witness of `I.directed` when `P` has joins. -/\ntheorem sup_mem (hx : x \u2208 s) (hy : y \u2208 s) : x \u2294 y \u2208 s :=\n  let \u27e8z, hz, hx, hy\u27e9 := s.Directed x hx y hy\n  s.lower (sup_le hx hy) hz\n#align order.ideal.sup_mem Order.Ideal.sup_mem\n\n/- warning: order.ideal.sup_mem_iff -> Order.Ideal.sup_mem_iff is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] {x : P} {y : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Iff (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Sup.sup.{u1} P (SemilatticeSup.toHasSup.{u1} P _inst_1) x y) I) (And (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x I) (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) y I))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] {x : P} {y : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Iff (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Sup.sup.{u1} P (SemilatticeSup.toSup.{u1} P _inst_1) x y) I) (And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x I) (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) y I))\nCase conversion may be inaccurate. Consider using '#align order.ideal.sup_mem_iff Order.Ideal.sup_mem_iff\u2093'. -/\n@[simp]\ntheorem sup_mem_iff : x \u2294 y \u2208 I \u2194 x \u2208 I \u2227 y \u2208 I :=\n  \u27e8fun h => \u27e8I.lower le_sup_left h, I.lower le_sup_right h\u27e9, fun h => sup_mem h.1 h.2\u27e9\n#align order.ideal.sup_mem_iff Order.Ideal.sup_mem_iff\n\nend SemilatticeSup\n\nsection SemilatticeSupDirected\n\nvariable [SemilatticeSup P] [IsDirected P (\u00b7 \u2265 \u00b7)] {x : P} {I J K s t : Ideal P}\n\n/-- The infimum of two ideals of a co-directed order is their intersection. -/\ninstance : Inf (Ideal P) :=\n  \u27e8fun I J =>\n    { toLowerSet := I.toLowerSet \u2293 J.toLowerSet\n      nonempty' := inter_nonempty I J\n      directed' := fun x hx y hy => \u27e8x \u2294 y, \u27e8sup_mem hx.1 hy.1, sup_mem hx.2 hy.2\u27e9, by simp\u27e9 }\u27e9\n\n/-- The supremum of two ideals of a co-directed order is the union of the down sets of the pointwise\nsupremum of `I` and `J`. -/\ninstance : Sup (Ideal P) :=\n  \u27e8fun I J =>\n    { carrier := { x | \u2203 i \u2208 I, \u2203 j \u2208 J, x \u2264 i \u2294 j }\n      nonempty' := by\n        cases inter_nonempty I J\n        exact \u27e8w, w, h.1, w, h.2, le_sup_left\u27e9\n      directed' := fun x \u27e8xi, _, xj, _, _\u27e9 y \u27e8yi, _, yj, _, _\u27e9 =>\n        \u27e8x \u2294 y,\n          \u27e8xi \u2294 yi, sup_mem \u2039_\u203a \u2039_\u203a, xj \u2294 yj, sup_mem \u2039_\u203a \u2039_\u203a,\n            sup_le\n              (calc\n                x \u2264 xi \u2294 xj := \u2039_\u203a\n                _ \u2264 xi \u2294 yi \u2294 (xj \u2294 yj) := sup_le_sup le_sup_left le_sup_left\n                )\n              (calc\n                y \u2264 yi \u2294 yj := \u2039_\u203a\n                _ \u2264 xi \u2294 yi \u2294 (xj \u2294 yj) := sup_le_sup le_sup_right le_sup_right\n                )\u27e9,\n          le_sup_left, le_sup_right\u27e9\n      lower' := fun x y h \u27e8yi, _, yj, _, _\u27e9 => \u27e8yi, \u2039_\u203a, yj, \u2039_\u203a, h.trans \u2039_\u203a\u27e9 }\u27e9\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (i \u00abexpr \u2208 \u00bb I) -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (j \u00abexpr \u2208 \u00bb J) -/\ninstance : Lattice (Ideal P) :=\n  { Ideal.partialOrder with\n    sup := (\u00b7 \u2294 \u00b7)\n    le_sup_left := fun I J i (_ : i \u2208 I) =>\n      by\n      cases J.nonempty\n      exact \u27e8i, \u2039_\u203a, w, \u2039_\u203a, le_sup_left\u27e9\n    le_sup_right := fun I J j (_ : j \u2208 J) =>\n      by\n      cases I.nonempty\n      exact \u27e8w, \u2039_\u203a, j, \u2039_\u203a, le_sup_right\u27e9\n    sup_le := fun I J K hIK hJK a \u27e8i, hi, j, hj, ha\u27e9 =>\n      K.lower ha <| sup_mem (mem_of_mem_of_le hi hIK) (mem_of_mem_of_le hj hJK)\n    inf := (\u00b7 \u2293 \u00b7)\n    inf_le_left := fun I J => inter_subset_left I J\n    inf_le_right := fun I J => inter_subset_right I J\n    le_inf := fun I J K => subset_inter }\n\n/- warning: order.ideal.coe_sup -> Order.Ideal.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))] {s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {t : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Eq.{succ u1} (Set.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))))) (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.hasSup.{u1} P _inst_1 _inst_2) s t)) (setOf.{u1} P (fun (x : P) => Exists.{succ u1} P (fun (a : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) a s) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) a s) => Exists.{succ u1} P (fun (b : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) b t) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) b t) => LE.le.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x (Sup.sup.{u1} P (SemilatticeSup.toHasSup.{u1} P _inst_1) a b)))))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.2878 : P) (x._@.Mathlib.Order.Ideal._hyg.2880 : P) => GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x._@.Mathlib.Order.Ideal._hyg.2878 x._@.Mathlib.Order.Ideal._hyg.2880)] {s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {t : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instSupIdealToLEToPreorderToPartialOrder.{u1} P _inst_1 _inst_2) s t)) (setOf.{u1} P (fun (x : P) => Exists.{succ u1} P (fun (a : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) a s) (Exists.{succ u1} P (fun (b : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) b t) (LE.le.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x (Sup.sup.{u1} P (SemilatticeSup.toSup.{u1} P _inst_1) a b)))))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.coe_sup Order.Ideal.coe_sup\u2093'. -/\n@[simp]\ntheorem coe_sup : \u2191(s \u2294 t) = { x | \u2203 a \u2208 s, \u2203 b \u2208 t, x \u2264 a \u2294 b } :=\n  rfl\n#align order.ideal.coe_sup Order.Ideal.coe_sup\n\n/- warning: order.ideal.coe_inf -> Order.Ideal.coe_inf is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))] {s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {t : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Eq.{succ u1} (Set.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))))) (Inf.inf.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.hasInf.{u1} P _inst_1 _inst_2) s t)) (Inter.inter.{u1} (Set.{u1} P) (Set.hasInter.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))))) s) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))))) t))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.2977 : P) (x._@.Mathlib.Order.Ideal._hyg.2979 : P) => GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x._@.Mathlib.Order.Ideal._hyg.2977 x._@.Mathlib.Order.Ideal._hyg.2979)] {s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {t : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Inf.inf.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instInfIdealToLEToPreorderToPartialOrder.{u1} P _inst_1 _inst_2) s t)) (Inter.inter.{u1} (Set.{u1} P) (Set.instInterSet.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) s) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) t))\nCase conversion may be inaccurate. Consider using '#align order.ideal.coe_inf Order.Ideal.coe_inf\u2093'. -/\n@[simp]\ntheorem coe_inf : (\u2191(s \u2293 t) : Set P) = s \u2229 t :=\n  rfl\n#align order.ideal.coe_inf Order.Ideal.coe_inf\n\n/- warning: order.ideal.mem_inf -> Order.Ideal.mem_inf is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))] {x : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Iff (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x (Inf.inf.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.hasInf.{u1} P _inst_1 _inst_2) I J)) (And (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x I) (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x J))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.3039 : P) (x._@.Mathlib.Order.Ideal._hyg.3041 : P) => GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x._@.Mathlib.Order.Ideal._hyg.3039 x._@.Mathlib.Order.Ideal._hyg.3041)] {x : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Iff (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x (Inf.inf.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instInfIdealToLEToPreorderToPartialOrder.{u1} P _inst_1 _inst_2) I J)) (And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x I) (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x J))\nCase conversion may be inaccurate. Consider using '#align order.ideal.mem_inf Order.Ideal.mem_inf\u2093'. -/\n@[simp]\ntheorem mem_inf : x \u2208 I \u2293 J \u2194 x \u2208 I \u2227 x \u2208 J :=\n  Iff.rfl\n#align order.ideal.mem_inf Order.Ideal.mem_inf\n\n/- warning: order.ideal.mem_sup -> Order.Ideal.mem_sup is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))] {x : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Iff (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.hasSup.{u1} P _inst_1 _inst_2) I J)) (Exists.{succ u1} P (fun (i : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) i I) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) i I) => Exists.{succ u1} P (fun (j : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) j J) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) j J) => LE.le.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x (Sup.sup.{u1} P (SemilatticeSup.toHasSup.{u1} P _inst_1) i j))))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.3100 : P) (x._@.Mathlib.Order.Ideal._hyg.3102 : P) => GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x._@.Mathlib.Order.Ideal._hyg.3100 x._@.Mathlib.Order.Ideal._hyg.3102)] {x : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, Iff (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instSupIdealToLEToPreorderToPartialOrder.{u1} P _inst_1 _inst_2) I J)) (Exists.{succ u1} P (fun (i : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) i I) (Exists.{succ u1} P (fun (j : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) j J) (LE.le.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x (Sup.sup.{u1} P (SemilatticeSup.toSup.{u1} P _inst_1) i j))))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.mem_sup Order.Ideal.mem_sup\u2093'. -/\n@[simp]\ntheorem mem_sup : x \u2208 I \u2294 J \u2194 \u2203 i \u2208 I, \u2203 j \u2208 J, x \u2264 i \u2294 j :=\n  Iff.rfl\n#align order.ideal.mem_sup Order.Ideal.mem_sup\n\n/- warning: order.ideal.lt_sup_principal_of_not_mem -> Order.Ideal.lt_sup_principal_of_not_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))] {x : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, (Not (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x I)) -> (LT.lt.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Preorder.toLT.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.partialOrder.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))))) I (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.hasSup.{u1} P _inst_1 _inst_2) I (Order.Ideal.principal.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)) x)))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : IsDirected.{u1} P (fun (x._@.Mathlib.Order.Ideal._hyg.3192 : P) (x._@.Mathlib.Order.Ideal._hyg.3194 : P) => GE.ge.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))) x._@.Mathlib.Order.Ideal._hyg.3192 x._@.Mathlib.Order.Ideal._hyg.3194)] {x : P} {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))}, (Not (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x I)) -> (LT.lt.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Preorder.toLT.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (PartialOrder.toPreorder.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instPartialOrderIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))))) I (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instSupIdealToLEToPreorderToPartialOrder.{u1} P _inst_1 _inst_2) I (Order.Ideal.principal.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)) x)))\nCase conversion may be inaccurate. Consider using '#align order.ideal.lt_sup_principal_of_not_mem Order.Ideal.lt_sup_principal_of_not_mem\u2093'. -/\ntheorem lt_sup_principal_of_not_mem (hx : x \u2209 I) : I < I \u2294 principal x :=\n  le_sup_left.lt_of_ne fun h => hx <| by simpa only [left_eq_sup, principal_le_iff] using h\n#align order.ideal.lt_sup_principal_of_not_mem Order.Ideal.lt_sup_principal_of_not_mem\n\nend SemilatticeSupDirected\n\nsection SemilatticeSupOrderBot\n\nvariable [SemilatticeSup P] [OrderBot P] {x : P} {I J K : Ideal P}\n\ninstance : InfSet (Ideal P) :=\n  \u27e8fun S =>\n    { toLowerSet := \u2a05 s \u2208 S, toLowerSet s\n      nonempty' :=\n        \u27e8\u22a5, by\n          rw [LowerSet.carrier_eq_coe, LowerSet.coe_inf\u1d62\u2082, Set.mem_inter\u1d62\u2082]\n          exact fun s _ => s.bot_mem\u27e9\n      directed' := fun a ha b hb =>\n        \u27e8a \u2294 b,\n          \u27e8by\n            rw [LowerSet.carrier_eq_coe, LowerSet.coe_inf\u1d62\u2082, Set.mem_inter\u1d62\u2082] at ha hb\u22a2\n            exact fun s hs => sup_mem (ha _ hs) (hb _ hs), le_sup_left, le_sup_right\u27e9\u27e9 }\u27e9\n\nvariable {S : Set (Ideal P)}\n\n/- warning: order.ideal.coe_Inf -> Order.Ideal.coe_inf\u209b is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : OrderBot.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))] {S : Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))}, Eq.{succ u1} (Set.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))))) (InfSet.inf\u209b.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.hasInf.{u1} P _inst_1 _inst_2) S)) (Set.inter\u1d62.{u1, succ u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (fun (s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) => Set.inter\u1d62.{u1, 0} P (Membership.Mem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Set.hasMem.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) s S) (fun (H : Membership.Mem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Set.hasMem.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) s S) => (fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))))) s)))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : OrderBot.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))] {S : Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))}, Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (InfSet.inf\u209b.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instInfSetIdealToLEToPreorderToPartialOrder.{u1} P _inst_1 _inst_2) S)) (Set.inter\u1d62.{u1, succ u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (fun (s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) => Set.inter\u1d62.{u1, 0} P (Membership.mem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Set.instMembershipSet.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) s S) (fun (H : Membership.mem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Set.instMembershipSet.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) s S) => SetLike.coe.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) s)))\nCase conversion may be inaccurate. Consider using '#align order.ideal.coe_Inf Order.Ideal.coe_inf\u209b\u2093'. -/\n@[simp]\ntheorem coe_inf\u209b : (\u2191(inf\u209b S) : Set P) = \u22c2 s \u2208 S, \u2191s :=\n  LowerSet.coe_inf\u1d62\u2082 _\n#align order.ideal.coe_Inf Order.Ideal.coe_inf\u209b\n\n/- warning: order.ideal.mem_Inf -> Order.Ideal.mem_inf\u209b is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : OrderBot.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))] {x : P} {S : Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))}, Iff (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x (InfSet.inf\u209b.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.hasInf.{u1} P _inst_1 _inst_2) S)) (forall (s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))), (Membership.Mem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Set.hasMem.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) s S) -> (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x s))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : SemilatticeSup.{u1} P] [_inst_2 : OrderBot.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))] {x : P} {S : Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))}, Iff (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x (InfSet.inf\u209b.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Order.Ideal.instInfSetIdealToLEToPreorderToPartialOrder.{u1} P _inst_1 _inst_2) S)) (forall (s : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))), (Membership.mem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (Set.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) (Set.instMembershipSet.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) s S) -> (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1)))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeSup.toPartialOrder.{u1} P _inst_1))))) x s))\nCase conversion may be inaccurate. Consider using '#align order.ideal.mem_Inf Order.Ideal.mem_inf\u209b\u2093'. -/\n@[simp]\ntheorem mem_inf\u209b : x \u2208 inf\u209b S \u2194 \u2200 s \u2208 S, x \u2208 s := by\n  simp_rw [\u2190 SetLike.mem_coe, coe_Inf, mem_Inter\u2082]\n#align order.ideal.mem_Inf Order.Ideal.mem_inf\u209b\n\ninstance : CompleteLattice (Ideal P) :=\n  { Ideal.lattice,\n    completeLatticeOfInf (Ideal P) fun S =>\n      by\n      refine' \u27e8fun s hs => _, fun s hs => by rwa [\u2190 coe_subset_coe, coe_Inf, subset_Inter\u2082_iff]\u27e9\n      rw [\u2190 coe_subset_coe, coe_Inf]\n      exact bInter_subset_of_mem hs with }\n\nend SemilatticeSupOrderBot\n\nsection DistribLattice\n\nvariable [DistribLattice P]\n\nvariable {I J : Ideal P}\n\n/- warning: order.ideal.eq_sup_of_le_sup -> Order.Ideal.eq_sup_of_le_sup is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : DistribLattice.{u1} P] {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))} {x : P} {i : P} {j : P}, (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i I) -> (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j J) -> (LE.le.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))) x (Sup.sup.{u1} P (SemilatticeSup.toHasSup.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))) i j)) -> (Exists.{succ u1} P (fun (i' : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i' I) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i' I) => Exists.{succ u1} P (fun (j' : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j' J) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j' J) => Eq.{succ u1} P x (Sup.sup.{u1} P (SemilatticeSup.toHasSup.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))) i' j'))))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : DistribLattice.{u1} P] {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))} {x : P} {i : P} {j : P}, (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i I) -> (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j J) -> (LE.le.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))) x (Sup.sup.{u1} P (SemilatticeSup.toSup.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))) i j)) -> (Exists.{succ u1} P (fun (i' : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i' I) (Exists.{succ u1} P (fun (j' : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j' J) (Eq.{succ u1} P x (Sup.sup.{u1} P (SemilatticeSup.toSup.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))) i' j'))))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.eq_sup_of_le_sup Order.Ideal.eq_sup_of_le_sup\u2093'. -/\ntheorem eq_sup_of_le_sup {x i j : P} (hi : i \u2208 I) (hj : j \u2208 J) (hx : x \u2264 i \u2294 j) :\n    \u2203 i' \u2208 I, \u2203 j' \u2208 J, x = i' \u2294 j' :=\n  by\n  refine' \u27e8x \u2293 i, I.lower inf_le_right hi, x \u2293 j, J.lower inf_le_right hj, _\u27e9\n  calc\n    x = x \u2293 (i \u2294 j) := left_eq_inf.mpr hx\n    _ = x \u2293 i \u2294 x \u2293 j := inf_sup_left\n    \n#align order.ideal.eq_sup_of_le_sup Order.Ideal.eq_sup_of_le_sup\n\n/- warning: order.ideal.coe_sup_eq -> Order.Ideal.coe_sup_eq is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : DistribLattice.{u1} P] {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))}, Eq.{succ u1} (Set.{u1} P) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (Set.{u1} P) (HasLiftT.mk.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (Set.{u1} P) (CoeTC\u2093.coe.{succ u1, succ u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (Set.{u1} P) (SetLike.Set.hasCoeT.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))))) (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (Order.Ideal.hasSup.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)) (SemilatticeInf.to_isDirected_ge.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))) I J)) (setOf.{u1} P (fun (x : P) => Exists.{succ u1} P (fun (i : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i I) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i I) => Exists.{succ u1} P (fun (j : P) => Exists.{0} (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j J) (fun (H : Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j J) => Eq.{succ u1} P x (Sup.sup.{u1} P (SemilatticeSup.toHasSup.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))) i j)))))))\nbut is expected to have type\n  forall {P : Type.{u1}} [_inst_1 : DistribLattice.{u1} P] {I : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))} {J : Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))}, Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (Sup.sup.{u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (Order.Ideal.instSupIdealToLEToPreorderToPartialOrder.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)) (SemilatticeInf.to_isDirected_ge.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))) I J)) (setOf.{u1} P (fun (x : P) => Exists.{succ u1} P (fun (i : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) i I) (Exists.{succ u1} P (fun (j : P) => And (Membership.mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) (SetLike.instMembership.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1)))))) P (Order.Ideal.instSetLikeIdeal.{u1} P (Preorder.toLE.{u1} P (PartialOrder.toPreorder.{u1} P (SemilatticeInf.toPartialOrder.{u1} P (Lattice.toSemilatticeInf.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))))))) j J) (Eq.{succ u1} P x (Sup.sup.{u1} P (SemilatticeSup.toSup.{u1} P (Lattice.toSemilatticeSup.{u1} P (DistribLattice.toLattice.{u1} P _inst_1))) i j)))))))\nCase conversion may be inaccurate. Consider using '#align order.ideal.coe_sup_eq Order.Ideal.coe_sup_eq\u2093'. -/\ntheorem coe_sup_eq : \u2191(I \u2294 J) = { x | \u2203 i \u2208 I, \u2203 j \u2208 J, x = i \u2294 j } :=\n  Set.ext fun _ =>\n    \u27e8fun \u27e8_, _, _, _, _\u27e9 => eq_sup_of_le_sup \u2039_\u203a \u2039_\u203a \u2039_\u203a, fun \u27e8i, _, j, _, _\u27e9 =>\n      \u27e8i, \u2039_\u203a, j, \u2039_\u203a, le_of_eq \u2039_\u203a\u27e9\u27e9\n#align order.ideal.coe_sup_eq Order.Ideal.coe_sup_eq\n\nend DistribLattice\n\nsection BooleanAlgebra\n\nvariable [BooleanAlgebra P] {x : P} {I : Ideal P}\n\n#print Order.Ideal.IsProper.not_mem_of_compl_mem /-\ntheorem IsProper.not_mem_of_compl_mem (hI : IsProper I) (hxc : x\u1d9c \u2208 I) : x \u2209 I :=\n  by\n  intro hx\n  apply hI.top_not_mem\n  have ht : x \u2294 x\u1d9c \u2208 I := sup_mem \u2039_\u203a \u2039_\u203a\n  rwa [sup_compl_eq_top] at ht\n#align order.ideal.is_proper.not_mem_of_compl_mem Order.Ideal.IsProper.not_mem_of_compl_mem\n-/\n\n#print Order.Ideal.IsProper.not_mem_or_compl_not_mem /-\ntheorem IsProper.not_mem_or_compl_not_mem (hI : IsProper I) : x \u2209 I \u2228 x\u1d9c \u2209 I :=\n  by\n  have h : x\u1d9c \u2208 I \u2192 x \u2209 I := hI.not_mem_of_compl_mem\n  tauto\n#align order.ideal.is_proper.not_mem_or_compl_not_mem Order.Ideal.IsProper.not_mem_or_compl_not_mem\n-/\n\nend BooleanAlgebra\n\nend Ideal\n\n#print Order.Cofinal /-\n/-- For a preorder `P`, `cofinal P` is the type of subsets of `P`\n  containing arbitrarily large elements. They are the dense sets in\n  the topology whose open sets are terminal segments. -/\nstructure Cofinal (P) [Preorder P] where\n  carrier : Set P\n  mem_gt : \u2200 x : P, \u2203 y \u2208 carrier, x \u2264 y\n#align order.cofinal Order.Cofinal\n-/\n\nnamespace Cofinal\n\nvariable [Preorder P]\n\ninstance : Inhabited (Cofinal P) :=\n  \u27e8{  carrier := univ\n      mem_gt := fun x => \u27e8x, trivial, le_rfl\u27e9 }\u27e9\n\ninstance : Membership P (Cofinal P) :=\n  \u27e8fun x D => x \u2208 D.carrier\u27e9\n\nvariable (D : Cofinal P) (x : P)\n\n#print Order.Cofinal.above /-\n/-- A (noncomputable) element of a cofinal set lying above a given element. -/\nnoncomputable def above : P :=\n  Classical.choose <| D.mem_gt x\n#align order.cofinal.above Order.Cofinal.above\n-/\n\n#print Order.Cofinal.above_mem /-\ntheorem above_mem : D.above x \u2208 D :=\n  Exists.elim (Classical.choose_spec <| D.mem_gt x) fun a _ => a\n#align order.cofinal.above_mem Order.Cofinal.above_mem\n-/\n\n#print Order.Cofinal.le_above /-\ntheorem le_above : x \u2264 D.above x :=\n  Exists.elim (Classical.choose_spec <| D.mem_gt x) fun _ b => b\n#align order.cofinal.le_above Order.Cofinal.le_above\n-/\n\nend Cofinal\n\nsection IdealOfCofinals\n\nvariable [Preorder P] (p : P) {\u03b9 : Type _} [Encodable \u03b9] (\ud835\udc9f : \u03b9 \u2192 Cofinal P)\n\n#print Order.sequenceOfCofinals /-\n/-- Given a starting point, and a countable family of cofinal sets,\n  this is an increasing sequence that intersects each cofinal set. -/\nnoncomputable def sequenceOfCofinals : \u2115 \u2192 P\n  | 0 => p\n  | n + 1 =>\n    match Encodable.decode \u03b9 n with\n    | none => sequence_of_cofinals n\n    | some i => (\ud835\udc9f i).above (sequence_of_cofinals n)\n#align order.sequence_of_cofinals Order.sequenceOfCofinals\n-/\n\n/- warning: order.sequence_of_cofinals.monotone -> Order.sequenceOfCofinals.monotone is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] (p : P) {\u03b9 : Type.{u2}} [_inst_2 : Encodable.{u2} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u1} P _inst_1)), Monotone.{0, u1} Nat P (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) _inst_1 (Order.sequenceOfCofinals.{u1, u2} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f)\nbut is expected to have type\n  forall {P : Type.{u2}} [_inst_1 : Preorder.{u2} P] (p : P) {\u03b9 : Type.{u1}} [_inst_2 : Encodable.{u1} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u2} P _inst_1)), Monotone.{0, u2} Nat P (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) _inst_1 (Order.sequenceOfCofinals.{u2, u1} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f)\nCase conversion may be inaccurate. Consider using '#align order.sequence_of_cofinals.monotone Order.sequenceOfCofinals.monotone\u2093'. -/\ntheorem sequenceOfCofinals.monotone : Monotone (sequenceOfCofinals p \ud835\udc9f) :=\n  by\n  apply monotone_nat_of_le_succ\n  intro n\n  dsimp only [sequence_of_cofinals]\n  cases Encodable.decode \u03b9 n\n  \u00b7 rfl\n  \u00b7 apply cofinal.le_above\n#align order.sequence_of_cofinals.monotone Order.sequenceOfCofinals.monotone\n\n/- warning: order.sequence_of_cofinals.encode_mem -> Order.sequenceOfCofinals.encode_mem is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] (p : P) {\u03b9 : Type.{u2}} [_inst_2 : Encodable.{u2} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u1} P _inst_1)) (i : \u03b9), Membership.Mem.{u1, u1} P (Order.Cofinal.{u1} P _inst_1) (Order.Cofinal.hasMem.{u1} P _inst_1) (Order.sequenceOfCofinals.{u1, u2} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Encodable.encode.{u2} \u03b9 _inst_2 i) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (\ud835\udc9f i)\nbut is expected to have type\n  forall {P : Type.{u2}} [_inst_1 : Preorder.{u2} P] (p : P) {\u03b9 : Type.{u1}} [_inst_2 : Encodable.{u1} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u2} P _inst_1)) (i : \u03b9), Membership.mem.{u2, u2} P (Order.Cofinal.{u2} P _inst_1) (Order.Cofinal.instMembershipCofinal.{u2} P _inst_1) (Order.sequenceOfCofinals.{u2, u1} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Encodable.encode.{u1} \u03b9 _inst_2 i) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (\ud835\udc9f i)\nCase conversion may be inaccurate. Consider using '#align order.sequence_of_cofinals.encode_mem Order.sequenceOfCofinals.encode_mem\u2093'. -/\ntheorem sequenceOfCofinals.encode_mem (i : \u03b9) :\n    sequenceOfCofinals p \ud835\udc9f (Encodable.encode i + 1) \u2208 \ud835\udc9f i :=\n  by\n  dsimp only [sequence_of_cofinals]\n  rw [Encodable.encodek]\n  apply cofinal.above_mem\n#align order.sequence_of_cofinals.encode_mem Order.sequenceOfCofinals.encode_mem\n\n#print Order.idealOfCofinals /-\n/-- Given an element `p : P` and a family `\ud835\udc9f` of cofinal subsets of a preorder `P`,\n  indexed by a countable type, `ideal_of_cofinals p \ud835\udc9f` is an ideal in `P` which\n  - contains `p`, according to `mem_ideal_of_cofinals p \ud835\udc9f`, and\n  - intersects every set in `\ud835\udc9f`, according to `cofinal_meets_ideal_of_cofinals p \ud835\udc9f`.\n\n  This proves the Rasiowa\u2013Sikorski lemma. -/\ndef idealOfCofinals : Ideal P\n    where\n  carrier := { x : P | \u2203 n, x \u2264 sequenceOfCofinals p \ud835\udc9f n }\n  lower' := fun x y hxy \u27e8n, hn\u27e9 => \u27e8n, le_trans hxy hn\u27e9\n  nonempty' := \u27e8p, 0, le_rfl\u27e9\n  directed' := fun x \u27e8n, hn\u27e9 y \u27e8m, hm\u27e9 =>\n    \u27e8_, \u27e8max n m, le_rfl\u27e9, le_trans hn <| sequenceOfCofinals.monotone p \ud835\udc9f (le_max_left _ _),\n      le_trans hm <| sequenceOfCofinals.monotone p \ud835\udc9f (le_max_right _ _)\u27e9\n#align order.ideal_of_cofinals Order.idealOfCofinals\n-/\n\n/- warning: order.mem_ideal_of_cofinals -> Order.mem_idealOfCofinals is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] (p : P) {\u03b9 : Type.{u2}} [_inst_2 : Encodable.{u2} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u1} P _inst_1)), Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P _inst_1))) p (Order.idealOfCofinals.{u1, u2} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f)\nbut is expected to have type\n  forall {P : Type.{u2}} [_inst_1 : Preorder.{u2} P] (p : P) {\u03b9 : Type.{u1}} [_inst_2 : Encodable.{u1} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u2} P _inst_1)), Membership.mem.{u2, u2} P (Order.Ideal.{u2} P (Preorder.toLE.{u2} P _inst_1)) (SetLike.instMembership.{u2, u2} (Order.Ideal.{u2} P (Preorder.toLE.{u2} P _inst_1)) P (Order.Ideal.instSetLikeIdeal.{u2} P (Preorder.toLE.{u2} P _inst_1))) p (Order.idealOfCofinals.{u2, u1} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f)\nCase conversion may be inaccurate. Consider using '#align order.mem_ideal_of_cofinals Order.mem_idealOfCofinals\u2093'. -/\ntheorem mem_idealOfCofinals : p \u2208 idealOfCofinals p \ud835\udc9f :=\n  \u27e80, le_rfl\u27e9\n#align order.mem_ideal_of_cofinals Order.mem_idealOfCofinals\n\n/- warning: order.cofinal_meets_ideal_of_cofinals -> Order.cofinal_meets_idealOfCofinals is a dubious translation:\nlean 3 declaration is\n  forall {P : Type.{u1}} [_inst_1 : Preorder.{u1} P] (p : P) {\u03b9 : Type.{u2}} [_inst_2 : Encodable.{u2} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u1} P _inst_1)) (i : \u03b9), Exists.{succ u1} P (fun (x : P) => And (Membership.Mem.{u1, u1} P (Order.Cofinal.{u1} P _inst_1) (Order.Cofinal.hasMem.{u1} P _inst_1) x (\ud835\udc9f i)) (Membership.Mem.{u1, u1} P (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) (SetLike.hasMem.{u1, u1} (Order.Ideal.{u1} P (Preorder.toLE.{u1} P _inst_1)) P (Order.Ideal.setLike.{u1} P (Preorder.toLE.{u1} P _inst_1))) x (Order.idealOfCofinals.{u1, u2} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f)))\nbut is expected to have type\n  forall {P : Type.{u2}} [_inst_1 : Preorder.{u2} P] (p : P) {\u03b9 : Type.{u1}} [_inst_2 : Encodable.{u1} \u03b9] (\ud835\udc9f : \u03b9 -> (Order.Cofinal.{u2} P _inst_1)) (i : \u03b9), Exists.{succ u2} P (fun (x : P) => And (Membership.mem.{u2, u2} P (Order.Cofinal.{u2} P _inst_1) (Order.Cofinal.instMembershipCofinal.{u2} P _inst_1) x (\ud835\udc9f i)) (Membership.mem.{u2, u2} P (Order.Ideal.{u2} P (Preorder.toLE.{u2} P _inst_1)) (SetLike.instMembership.{u2, u2} (Order.Ideal.{u2} P (Preorder.toLE.{u2} P _inst_1)) P (Order.Ideal.instSetLikeIdeal.{u2} P (Preorder.toLE.{u2} P _inst_1))) x (Order.idealOfCofinals.{u2, u1} P _inst_1 p \u03b9 _inst_2 \ud835\udc9f)))\nCase conversion may be inaccurate. Consider using '#align order.cofinal_meets_ideal_of_cofinals Order.cofinal_meets_idealOfCofinals\u2093'. -/\n/-- `ideal_of_cofinals p \ud835\udc9f` is `\ud835\udc9f`-generic. -/\ntheorem cofinal_meets_idealOfCofinals (i : \u03b9) : \u2203 x : P, x \u2208 \ud835\udc9f i \u2227 x \u2208 idealOfCofinals p \ud835\udc9f :=\n  \u27e8_, sequenceOfCofinals.encode_mem p \ud835\udc9f i, _, le_rfl\u27e9\n#align order.cofinal_meets_ideal_of_cofinals Order.cofinal_meets_idealOfCofinals\n\nend IdealOfCofinals\n\nend Order\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Order/Ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7035011006702309}}
{"text": "import .myRing\nimport tactic.basic\n\n-- import tactic\nopen myRing\nvariables {R : Type} [myRing R]\nvariables {O : Type} [ordered_ring O ]\n\n--  variable is_positive : O \u2192 Prop\n/-\nP1. Suppose a, z \u2208 \u2124. If a+z=a then z=0. So \"zero\"\n  is uniquely defined. Similarly, \"one\" is uniquely\n  defined. \n-/\ntheorem zero_is_unique: \u2200( z : R), (\u2200 (a : R), a + z = a) \u2192 (z = 0)  := begin\n  intros z a,\n  have x:  z + 0 = z := add_zero z,\n  have y:  z + 0 = 0 := begin \n  rw add_comm,\n  rw a,\n  end, \n  rw \u2190 x,\n  rw y,\nend\n\ntheorem one_is_unique: \u2200( o : R), (\u2200(a : R), a*o = a) \u2192 o = 1  := begin\n  intros o a,\n  have q : o * 1 = o := mul_one o,\n  have r : 1 * o = 1 := a 1,\n  rw mul_comm at r,\n  rw q at r,\n  exact r, \nend\n\n/-\nP3. Suppose a,b, b' \u2208 \u2124. The a+b=a+b' \u2192 b=b'\n-/\ntheorem left_cancel: \u2200 {a b c : R}, a+b=a+c \u2192 b=c := begin\n  intros a b c eq,\n  rw [ \u2190 add_zero  b],\n  cases has_inv a  ,\n  rw [\u2190  h,\u2190  add_assoc,add_comm b a,eq,add_comm a c,add_assoc,h,add_zero],\nend\n\n/- similarly, you can cancel on the right-/\n-- @[simp]\nlemma right_cancel: \u2200 {a b c : R}, b+a=c+a \u2192 b=c := begin\n  intros a b c eq,\n  rw add_comm at eq,\n  have : c + a = a+c := begin\n    rw add_comm,\n  end,\n  rw this at eq,\n  have : b=c := begin\n    exact left_cancel eq,\n  end,\n  exact this,\nend\n@[simp]\nlemma right_cancel_simp: \u2200 {a b c : R}, b+a=c+a \u2194 b=c := begin\n  intros a b c,\n  split,{\n    exact right_cancel,\n  },\n  intro bc,\n  rw bc,\nend\n\n/- anything times zero is zero -/\n\n@[simp]\nlemma mul_zero : \u2200{a : R}, a * 0 = 0 :=\nbegin \n  intro a,\n  have : a * (1 + 0) = a + 0,\n  {\n    rw add_zero,\n    rw mul_one,\n    rw add_zero,\n  },\n  rw mul_add at this,\n  rw mul_one at this,\n  exact left_cancel this,\nend\n\n/-\nP2. Use P1 to deduce that 0 \u2260 1\nFalse. 0 = 1 in the trivial myRing.`\nP2 SALVAGE. Zero is only one in the trivial myRing.\n-/\ntheorem zero_is_one_implies_trivial : ((0: R) = 1) \u2192 (\u2200(a : R), a = 0) := \nbegin \n  intros h a,\n  have q : a * 1 = a := mul_one a,\n  rw \u2190 h at q,\n  rw mul_zero at q,\n  symmetry,\n  exact q,\nend\n\n/-\n  P4. Gvien a \u2208 \u2124, let -a be the unique solution \n  x to a+x=0 (why is it unique?)\n  Then : -(-a)  = a and\n  -(ab)=(-a)b = a(-b).\n  Moreover (-a)(-b) = ab \n  and\n  -a = (-1)*a\n-/\n@[simp]\ntheorem neg_neg_a : \u2200 {a : R}, -(-a)=a := begin \n  intro a,\n  have na := add_neg a,\n  have nna := add_neg (-a),\n  rw add_comm at nna,\n  rw \u2190 na at nna,\n  exact right_cancel nna,\nend\n\n@[simp]\ntheorem dist_neg_right : \u2200 (a b : R), (a)*(-b)=-(a*b) := begin \n  intros a b,\n  have x: 0 = a*0 := begin\n  rw mul_zero,\n  end,\n  rw \u2190 add_neg b at x,\n  rw mul_add at x,\n  rw add_neg b at x,\n  have y: a*b + (-(a*b)) = 0 := begin\n  rw add_neg (a*b),\n  end,\n  rw \u2190  y at x,\n  have := left_cancel x,\n  symmetry,\n  exact this,\nend\n\n@[simp]\ntheorem mul_neg_one : \u2200 (a : R), (-1)*a=-a := begin \n  intro a,\n  have x: a*0=0 := begin\n  exact mul_zero,\n  end,\n  rw \u2190  add_neg (1:R) at x,\n  rw mul_add at x,\n  rw mul_one at x,\n  rw add_neg at x,\n  have z: a + -a = 0 := begin\n  rw add_neg,\n  end,\n  rw \u2190 z at x,\n  have z : a*(-1) = -a := begin\n  exact left_cancel x,\n  end,\n  rw mul_comm,\n  exact z,\n  end\n@[simp]\ntheorem dist_neg_left : \u2200 (a b : R), (-a)*(b)=-(a*b) := begin \n  intros a b,\n  rw \u2190 mul_neg_one a,\n  rw mul_comm (-1:R) a,\n  rw mul_assoc,\n  rw  mul_neg_one b,\n  exact dist_neg_right a b,\nend\n@[simp]\ntheorem dist_neg_both : \u2200 (a b : R), (-a)*(-b)=(a*b) := begin \n  intros a b,\n  rw dist_neg_left (a) (-b),\n  rw dist_neg_right (a) (b),\n  rw neg_neg_a,\nend\ntheorem neg1_times_neg1 : (-(1 :R))*(-1) = 1 := begin\n  have x: (-1:R)*(0:R)=0 := begin\n    exact mul_zero,\n  end,\n  rw \u2190  add_neg (1 :R ) at x,\n  rw mul_add at x,\n  rw mul_one at x,\n  rw add_comm at x,\n  have : (-1 :R)* (-1)  = 1 := begin\n    rw right_cancel x,\n  end,\n  exact this,\nend\n/-\n  P7\n  1 \u2208 P and -1 \u2209 P\n-/\n\n/-\n  lemma: if a is positive and b is not positive then a is not b\n-/\nlemma pos_diff : \u2200 (a b : O), is_positive (a) \u2227 \u00ac is_positive (b) \u2192 \u00ac a=b :=\nbegin\n  intros a b c,\n  cases c with d e,\n  by_contradiction,\n  rw h at d,\n  apply e,\n  exact d,\nend\n/-\n  lemma: if a is positive then a is not 0\n-/\nlemma pos_not_z : \u2200 (a : O), is_positive (a) \u2192 \u00ac a=0 :=\nbegin\n  intros a b c,\n  have nontriv := nontriviality,\n  apply nontriv,\n  rw c at b,\n  exact b,\nend\n\n/-\n  -1 \u2209 P : in other words, -1 is not positive \n-/\ntheorem not_neg_one_pos : \u00ac is_positive(-1:O) := begin\n  intros a,\n  have notz := pos_not_z (-1:O),\n  have xf := notz a,\n  have trich := trichotomy (-1:O),\n  have ewf := pos_times_pos a a,\n  rw neg1_times_neg1 at ewf,\n  cases trich with f g, {\n    cases f with d n, \n    cases n with d s,\n    rw neg_neg_a at s,\n    apply s,\n    exact ewf,\n  },\n  cases g with fn dw,{\n    cases fn with dj dw,\n    cases dw with dn fh,\n    rw neg_neg_a at fh,\n    apply fh,\n    exact ewf,\n  },\n  cases dw with fs wh,\n  cases wh with od wx,\n  apply fs,\n  exact a,\nend\n/-\n  1 \u2208 P : in other words 1 is positive\n-/\ntheorem one_pos : is_positive(1:O) := begin\n  have ed : \u00acis_positive(-1:O) := not_neg_one_pos,\n  cases trichotomy (1:O),\n  {\n    cases h with h1 h2,\n    exact h1,\n  },\n  {\n    cases h,\n    cases h with h1 h2,\n    cases h2 with h2 h3,\n    have h4 : 0 = (1 : O),\n    {\n      symmetry,\n      exact h2,\n    },\n    {\n      have allzero := zero_is_one_implies_trivial h4,\n      have zeronotpos : \u2203(a : O), is_positive a := nonempty_pos,\n      rw h2 at h1,\n      cases zeronotpos with a q,\n      have azero := allzero a,\n      rw \u2190 h2 at azero,\n      rw azero at q,\n      exact q,\n    },\n    {\n      cases h with h1 h2,\n      cases h2 with h2 h3,\n      exfalso,\n      apply ed,\n      exact h3,\n    },\n  }\nend\n\ntheorem trans_lt : \u2200{a b c : O}, a < b \u2192 b <  c \u2192 a < c := begin\nintros a b c a_le_b b_le_c,\nrw less_than at a_le_b,\nrw less_than at b_le_c,\nrcases a_le_b with \u27e8p1, p1pos, eq1\u27e9 , \nrcases b_le_c with \u27e8p2, p2pos, eq2\u27e9 , \n\nrw less_than,\nuse p1 + p2,\nsplit,\nexact pos_plus_pos p1pos p2pos,\nrw \u2190 eq1 at eq2,\nrw add_assoc at eq2,\nexact eq2,\nend\n/-\n  P8 Prove the transitivity of \u2264 \n-/\ntheorem trans_le : \u2200{a b c : O}, a \u2264 b \u2192 b \u2264 c \u2192 a \u2264 c :=\nbegin \n  intros a b c ab bc,\n  rw less_eq at ab,\n  rw less_eq at bc,\n  rw less_eq,\n  cases ab,\n  {\n    cases bc,\n    {\n      rw less_than at ab,\n      rw less_than at bc,\n      cases bc with Pbc bc,\n      cases ab with Pab ab,\n      cases bc with Pbc bc,\n      cases ab with Pab ab,\n      rw \u2190 ab at bc,\n      rw add_assoc at bc,\n      have := pos_plus_pos Pab Pbc,\n      have alc : a < c,\n      {\n        rw less_than,\n        split,\n        exact \u27e8this, bc\u27e9,\n      },\n      left,\n      exact alc,\n    },\n    {\n      left,\n      rw \u2190 bc,\n      exact ab,\n    },\n  },\n  {\n    cases bc,\n    {\n      left,\n      rw ab,\n      exact bc,\n    },\n    {\n      right,\n      rw ab,\n      exact bc,\n    }\n  },\nend\n@[simp]\n/- 0 + something = something -/\nlemma zero_add : \u2200{a : R}, 0 + a = a :=\nbegin \n  intro a,\n  rw add_comm,\n  rw add_zero,\nend\n/- move stuff across the equal sign-/\nlemma move : \u2200{a b c: R}, a + b = c \u2192 a = c + (-b) :=\nbegin \n  intros a b c h,\n  rw \u2190 h,\n  rw add_assoc,\n  rw add_neg,\n  rw add_zero,\nend\n/- you can multiply by stuff on the right-/\nlemma mul_right : \u2200{a b : R}, \u2200(c : R), a = b \u2192 a * c = b * c :=\nbegin \n  intros a b c h,\n  rw h,\nend\nlemma mul_left : \u2200{a b : R}, \u2200(c : R), a = b \u2192 c*a = c*b :=\nbegin \n  intros a b c h,\n  rw h,\nend\n\n/-\n  P9 \u2200a, b \u2208 \u2124, exactly one of the following is true: a < b or a = b or a > b\n  in other words, the integers are a total order.\n-/\ntheorem trichotomy_lt : \u2200(a b : O), \n  (a < b \u2227 a \u2260 b \u2227 \u00ac(b < a)) \u2228 \n  (\u00ac(a < b) \u2227 a = b \u2227 \u00ac(b < a)) \u2228\n  (\u00ac(a < b) \u2227 a \u2260 b \u2227 (b < a)) :=\nbegin \n  intros a b,\n  have : a + (b + (-a)) = b,\n  {\n    rw add_comm,\n    rw add_assoc,\n    rw add_comm (-a) a,\n    rw add_neg,\n    rw add_zero,\n  },\n  cases trichotomy (b + (-a)),\n  {\n    cases h with h1 h2,\n    cases h2 with h2 h3,\n    left,\n    split,\n    {\n      rw less_than,\n      split,\n      exact \u27e8h1, this\u27e9,\n    },\n    split,\n    {\n      by_contra,\n      rw h at h1,\n      rw add_neg at h1,\n      exact nontriviality h1,\n    },\n    {\n      by_contra,\n      rw less_than at h,\n      cases h with P h,\n      cases h with h4 h5,\n      rw \u2190 this at h5,\n      rw \u2190 add_zero a at h5,\n      rw add_assoc a 0 at h5,\n      rw zero_add at h5,\n      rw add_assoc at h5,\n      have q := left_cancel h5,\n      rw add_zero at q, \n      rw add_comm at q,\n      have q2 := move q,\n      rw zero_add at q2,\n      rw q2 at h4,\n      apply h3,\n      exact h4,\n    },\n  },\n  cases h,\n  {\n    right,\n    left,\n    cases h with h1 h2,\n    cases h2 with h2 h3,\n    have h4 := move h2,\n    rw neg_neg_a at h4,\n    rw zero_add at h4,\n    split,\n    {\n      by_contra,\n      rw less_than at h,\n      cases h with P h,\n      cases h with h5 h6,\n      rw h4 at h6,\n      rw \u2190 add_zero a at h6,\n      rw add_assoc at h6,\n      have q := left_cancel h6,\n      rw zero_add at q,\n      rw q at h5,\n      exact nontriviality h5,\n    },\n    split,\n    {\n      symmetry,\n      exact h4,\n    },\n    {\n      by_contra,\n      rw less_than at h,\n      cases h with P h,\n      cases h with h5 h6,\n      rw h4 at h6,\n      rw \u2190 add_zero a at h6,\n      rw add_assoc at h6,\n      have q := left_cancel h6,\n      rw zero_add at q,\n      rw q at h5,\n      exact nontriviality h5,\n    },\n  },\n  {\n    right,\n    right,\n    cases h with h1 h2,\n    cases h2 with h2 h3,\n    split,\n    {\n      by_contra,\n      rw less_than at h,\n      cases h with P h4,\n      cases h4 with h4 h5,\n      rw \u2190 this at h5,\n      have q := left_cancel h5,\n      rw \u2190 q at h1,\n      apply h1,\n      exact h4,\n    },\n    split,\n    {\n      by_contra,\n      apply h2,\n      rw h,\n      rw add_neg,\n    },\n    {\n      rw less_than,\n      have that := move this,\n      split,\n      split,\n      exact h3,\n      symmetry,\n      exact that,\n    },\n  },\nend\n/-\n  P10\n  \u2200a, b, x, y \u2208 \u2124, a \u2264 b and x \u2264 y \u2192 a + x \u2264 b + y\n  and SALVAGE a \u2264 b and x \u2264 y and a, x \u2208 P implies a * x \u2264 b * y\n-/\ntheorem add_le_add: \u2200{a b x y : O}, a \u2264 b \u2192 x \u2264 y \u2192 a + x \u2264 b + y :=\nbegin \n  intros a b x y ab xy,\n  rw less_eq,\n  rw less_eq at ab,\n  rw less_eq at xy,\n  rw less_than at ab,\n  rw less_than at xy,\n  rw less_than,\n  cases ab,\n  {\n    cases xy,\n    {\n      left,\n      cases ab with P1 ab,\n      cases xy with P2 xy,\n      cases ab with P1pos ab,\n      cases xy with P2pos xy,\n      have : a + x + (P1 + P2) = b + y,\n      {\n        rw add_assoc,\n        rw \u2190 add_assoc x,\n        rw add_comm x,\n        rw add_assoc,\n        rw xy,\n        rw \u2190 add_assoc,\n        rw ab,\n      },\n      have that := pos_plus_pos P1pos P2pos,\n      split,\n      split,\n      exact that,\n      exact this,\n    },\n    {\n      left,\n      cases ab with P ab,\n      cases ab with Ppos ab,\n      split,\n      split,\n      exact Ppos,\n      rw xy,\n      rw add_assoc,\n      rw add_comm y,\n      rw \u2190 add_assoc,\n      rw ab,\n    },\n  },\n  {\n    cases xy,\n    {\n      left,\n      cases xy with P xy,\n      cases xy with Ppos xy,\n      split,\n      split,\n      exact Ppos,\n      rw add_assoc,\n      rw xy,\n      rw ab,\n    },\n    {\n      right,\n      rw xy,\n      rw ab,\n    },\n  },\nend\n@[simp]\ntheorem one_mul: \u2200 (a :R), 1*a=a := begin\nintro a,\nrw mul_comm,\nexact mul_one a,\nend\ntheorem no_lt_self: \u2200 (a:O), \u00ac  (a  <a) := begin\nintros a b,\nrw less_than at b,\ncases b, \ncases b_h,\nrw \u2190 add_zero (a)  at b_h_right,\nrw add_assoc at b_h_right,\nhave := left_cancel b_h_right,\nrw zero_add at this,\nrw this at b_h_left,\nhave := nontriviality,\napply this,\nexact b_h_left,\nend\ntheorem mul_le :\u2200 (a b c :O), is_positive c \u2192 a < b \u2192 a*c < b*c := begin\nintros a b c pc alb ,\nrw less_than,\nrw less_than at alb,\ncases alb, \n cases alb_h,\n  have := mul_right c alb_h_right,\n    rw mul_comm at this,\n    rw mul_add at this,\n\nsplit, {\n  split, {\n\n--  cases alb_h,\n\n--   \n--     -- split, {\n      exact pos_times_pos pc alb_h_left,\n--     -- },\n-- sorry,\n  },\n  rw mul_comm at this,\n  exact this,\n  --  cases alb_h,\n\n\n \n},\n-- sorry,\nend \ntheorem mul_le_mul : \u2200{a b x y : O}, is_positive a \u2192 is_positive x \u2192 a \u2264 b \u2192 x \u2264 y \u2192 a * x \u2264 b * y :=\nbegin \n  intros a b x y ap xp ab xy,\n  rw less_eq,\n  rw less_eq at ab,\n  rw less_eq at xy,\n  rw less_than at ab,\n  rw less_than at xy,\n  rw less_than,\n  cases ab,\n  {\n    cases xy,\n    {\n      left,\n      cases ab with P1 ab,\n      cases xy with P2 xy,\n      cases ab with P1pos ab,\n      cases xy with P2pos xy,\n      have : x*a + x*P1+ (P2*a + P2*P1) = b*y,\n      {\n        rw \u2190 ab,\n        rw \u2190 xy,\n        rw mul_add,\n        rw mul_comm (a + P1) x,\n        rw mul_add,\n        rw mul_comm (a + P1) P2,\n        rw mul_add,\n      },\n      have pp: is_positive (x*P1+ (P2*a + P2*P1)),\n      {\n        have q := pos_times_pos P2pos P1pos,\n        have q2 := pos_times_pos P2pos ap,\n        have q3 := pos_times_pos xp P1pos,\n        have q4 := pos_plus_pos q2 q,\n        exact pos_plus_pos q3 q4,\n      },\n      split,\n      split,\n      exact pp,\n      rw \u2190 add_assoc,\n      rw mul_comm a x,\n      exact this,\n    },\n    {\n      left,\n      cases ab with P ab,\n      cases ab with Ppos ab,\n      have := mul_right x ab,\n      rw mul_comm at this,\n      rw mul_add at this,\n      have xppos := pos_times_pos xp Ppos,\n      split,\n      split,\n      exact xppos,\n      rw xy,\n      rw xy at this,\n      rw mul_comm,\n      exact this,\n    },\n  },\n  {\n    cases xy,\n    {\n      left,\n      cases xy with P xy,\n      cases xy with Ppos xy,\n      have := mul_right a xy,\n      rw mul_comm at this,\n      rw mul_add at this,\n      have appos := pos_times_pos ap Ppos,\n      split,\n      split,\n      exact appos,\n      rw \u2190 ab,\n      rw mul_comm a y,\n      exact this,\n    },\n    {\n      right,\n      rw ab,\n      rw xy,\n    },\n  },\nend \n\ntheorem le_all: \u2200(a :O), a \u2264 a := begin\nintro a,\nrw less_eq,\nright,\nrefl,\nend\ntheorem mul_lt_mul : \u2200{a b x y : O}, \n  is_positive a \u2192 \n  is_positive x \u2192 \n  a < b \u2192 \n  x < y \u2192 \n  a * x < b * y :=\nbegin\n intros a b x y a_pos x_pos aleb xley,\n rw less_than at aleb,\n rw less_than at xley,\n rw less_than,\n rcases aleb with \u27e8p1,p1pos, eq1 \u27e9, \nrcases xley with \u27e8p2,p2pos, eq2 \u27e9, \nhave eq3 : (a + p1)*(x+p2) = b*y := begin\nrw eq2,\nrw eq1,\nend,\nrw mul_add at eq3,\nrw mul_comm at eq3,\nrw mul_comm (a+p1) p2 at eq3,\nrw mul_add at eq3,\nrw mul_add at eq3,\nrw  add_assoc at eq3,\nuse x * p1 + p2 * a + p2 * p1,\nsplit, \nexact (pos_plus_pos (pos_plus_pos (pos_times_pos x_pos p1pos) (pos_times_pos p2pos a_pos)) (pos_times_pos p2pos p1pos)),\nrw mul_comm a x,\nrw add_assoc,\nexact eq3,\nend\n@[simp]\ntheorem add_lt_add : \u2200(a b x : O), \n  a+x < b+x \u2194\n  a  < b :=\nbegin\nintros a b c,\nsplit,{\n  intro eq,\n  rw less_than at eq,\n  rcases eq with \u27e8 w,x,y\u27e9,\n  rw add_comm at y,\n  rw \u2190  add_assoc  at y,\n  simp at y,\n  rw less_than,\n  use w,\n  rw add_comm,\n  rw y,\n  exact \u27e8 x,refl b\u27e9, \n},\nintro x,\nrw less_than,\nrw less_than at x,\nrcases x with \u27e8f,g,h \u27e9,\nuse f,\nrw \u2190 h, \nrw add_assoc a f c,\nrw add_comm f c,\nrw \u2190 add_assoc,\nexact \u27e8g, refl (a+c+f) \u27e9, \nend\n/- If a is positive then it isn't zero -/\nlemma pos_not_zero: \u2200 {a : O}, is_positive a \u2192 a \u2260 0 := begin\n  intros a b,\n  by_contradiction,\n  rw h at b,\n  have := nontriviality,\n  apply this,\n  exact b,\nend\n/- modus tollens + demorgans law-/\nlemma thing : \u2200 {P Q R : Prop}, (\u00ac P \u2227  \u00ac Q \u2192 \u00ac R) \u2192 (R \u2192  P \u2228  Q) := begin \n  intros P Q R pqr r,\n  by_cases P, --classical logic\n  left,\n  exact h,\n  by_cases Q,\n  right,\n  exact h,\n  have : \u00acP \u2227 \u00acQ,\n  split ; assumption,\n  have that := pqr this,\n  exfalso,\n  apply that,\n  exact r,\nend\n@[simp]\n/- -0 = 0-/\nlemma neg_zero : -(0 : R) = 0 := \nbegin \n  rw \u2190 mul_neg_one,\n  rw mul_zero,\nend\n@[simp] lemma sub_zero: \u2200{a:R}, a-0=a := begin\nintros a,\nrw subtr a (0:R),\nrw neg_zero,\nrw add_zero,\nend\n@[simp] lemma sub_self: \u2200{a:R}, a-a=0 := begin\nintros a,\nrw subtr a (a),\nexact add_neg a,\nend\n/- \n\n  P6: SALVAGE: In an ordered myRing:  ab = 0 \u2192 a = 0 or b = 0\n  we proved the contrapositive because it was easier and a constructive proof\n  the lemma \"thing\" was used to recover the original version\n-/\nlemma zero_or' : \u2200(a b : O),   a \u2260 0 \u2227  b \u2260 0 \u2192 a *b \u2260  (0:O) :=\nbegin\n  intros a b c,\n  cases c with d e,\n  have ta := trichotomy a,\n  have tb := trichotomy b,\n  cases ta with s f, {\n    cases tb with d g, {\n      cases s with asd fsa, \n      cases d with sdd asd,\n      cases asd with fds awe,\n      cases fsa with sdad qwe,\n      exact pos_not_zero (pos_times_pos asd sdd),\n    },\n    cases s with asd fdj,\n    cases g with daskd weq, {\n      cases daskd with das qwem,\n      cases fdj with as xz,\n      cases qwem with oasd we,\n      exfalso,\n      rw oasd at e,\n      apply e,\n      refl,\n    },\n    {\n      cases fdj with asds wqer,\n      cases weq with asdd tewoirm,\n      cases tewoirm with  gfs qowi,\n      have := pos_not_zero (pos_times_pos asd qowi),\n      rw dist_neg_right at this,\n      intro h,\n      apply this,\n      have that := mul_right (-1 : O) h,\n      rw mul_comm at that,\n      rw mul_neg_one at that,\n      rw mul_comm (0 : O) (-1) at that,\n      rw mul_zero at that,\n      exact that,\n    },\n  },\n  {\n    cases f with w q,\n    {\n      cases w with junk w,\n      cases w with w junk2,\n      exfalso,\n      apply d,\n      exact w,\n    },\n    {\n      cases tb with tb1 tb2,\n      {\n        cases q with junk q,\n        cases q with junk2 negapos,\n        cases tb1 with bpos junk3,\n        have := pos_not_zero (pos_times_pos negapos bpos),\n        intro h,\n        apply this,\n        rw dist_neg_left,\n        rw h,\n        simp,\n      },\n      cases tb2 with tb2 tb3,\n      {\n        cases tb2 with junk3 tb2,\n        cases tb2 with tb2 junk4,\n        exfalso,\n        apply e,\n        exact tb2,\n      },\n      {\n        cases q with junk q,\n        cases q with junk2 negapos,\n        cases tb3 with junk3 tb3,\n        cases tb3 with junk4 negbpos,\n        have := pos_not_zero (pos_times_pos negapos negbpos),\n        rw dist_neg_both at this,\n        exact this, \n      },\n    },\n  },\nend\n/- The actually useful version of the lemma -/\nlemma zero_or : \u2200{a b : O},  a *b= (0:O) \u2192 a=0 \u2228 b=0:=\nbegin \n  intros a b,\n  have  x1:= zero_or' a b,\n  have  x2 := thing x1,\n  exact x2,\nend\n/-\n  P6: SALVAGE : In an ordered myRing you can cancel multiplication,\n  in other words: if c \u2260 0 and a * c = b * c, then a = b\n-/\ntheorem mul_cancel : \u2200{a b c : O},  a * c = b * c  \u2192 c \u2260 0 \u2192 a = b:=\nbegin \n  intros a b c d cnotzero,\n  have start : a * 0 = 0 := by exact mul_zero,\n  rw \u2190 add_neg c at start,\n  rw mul_add at start,\n  rw d at start,\n  rw add_neg at start,\n  rw dist_neg_right at start,\n  rw \u2190 dist_neg_left at start,\n  rw mul_comm at start,\n  rw mul_comm (-a) c at start,\n  rw \u2190 mul_add at start,\n  have := zero_or start,\n  cases this, {\n    exfalso,\n    apply cnotzero,\n    exact this,\n  },\n  {\n    have that := move this,\n    simp at that,\n    symmetry,\n    exact that,\n  }\nend\ntheorem pos_div_pos: \u2200 (a b p: O ), is_positive a  \u2192 is_positive b \u2192 a*p=b \u2192 is_positive p := begin\nintros a b p a_pos b_pos equ,\n-- rw divs at a_divs_b,\n-- cases a_divs_b with p equ,\nhave p_pos : is_positive p, {\nby_contradiction,\nhave trich := trichotomy p,\ncases trich, {\ncases trich,{\napply h,\nexact trich_left,\n},\n\n},\ncases trich, {\ncases trich, {\ncases  trich_right, {\nrw trich_right_left at equ,\nrw mul_zero at equ,\nhave x:=pos_not_zero b_pos,\napply x,\nsymmetry,\nexact equ,\n},\n},\n},\ncases trich,{\ncases trich_right,{\nhave pp := pos_times_pos a_pos trich_right_right,\nrw dist_neg_right at pp,\nrw equ at pp,\nhave trichb := trichotomy b,\ncases trichb, {\ncases trichb, {\ncases trichb_right, {\napply trichb_right_right,\nexact pp,\n},\n},\n},\ncases trichb, {\ncases trichb, {\napply trichb_left,\nexact b_pos,\n},\n},\ncases trichb ,{\napply trichb_left,\nexact b_pos,\n},\n},\n},\n},\nexact p_pos,\nend\n/- P5: Subtraction is associative: WRONG and UNSALVAGEABLE -/", "meta": {"author": "AtticusKuhn", "repo": "axioms", "sha": "671c3f0e4b32207b556b17652719255336a88a37", "save_path": "github-repos/lean/AtticusKuhn-axioms", "path": "github-repos/lean/AtticusKuhn-axioms/axioms-671c3f0e4b32207b556b17652719255336a88a37/src/axiom_set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7799929053683039, "lm_q1q2_score": 0.7034917309543225}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.measure_theory.pi\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Lebesgue measure on the real line and on `\u211d\u207f`\n-/\n\nnamespace measure_theory\n\n\n/-!\n### Preliminary definitions\n-/\n\n/-- Length of an interval. This is the largest monotonic function which correctly\n  measures all intervals. -/\ndef lebesgue_length (s : set \u211d) : ennreal :=\n  infi fun (a : \u211d) => infi fun (b : \u211d) => infi fun (h : s \u2286 set.Ico a b) => ennreal.of_real (b - a)\n\n@[simp] theorem lebesgue_length_empty : lebesgue_length \u2205 = 0 := sorry\n\n@[simp] theorem lebesgue_length_Ico (a : \u211d) (b : \u211d) :\n    lebesgue_length (set.Ico a b) = ennreal.of_real (b - a) :=\n  sorry\n\ntheorem lebesgue_length_mono {s\u2081 : set \u211d} {s\u2082 : set \u211d} (h : s\u2081 \u2286 s\u2082) :\n    lebesgue_length s\u2081 \u2264 lebesgue_length s\u2082 :=\n  sorry\n\ntheorem lebesgue_length_eq_infi_Ioo (s : set \u211d) :\n    lebesgue_length s =\n        infi\n          fun (a : \u211d) =>\n            infi fun (b : \u211d) => infi fun (h : s \u2286 set.Ioo a b) => ennreal.of_real (b - a) :=\n  sorry\n\n@[simp] theorem lebesgue_length_Ioo (a : \u211d) (b : \u211d) :\n    lebesgue_length (set.Ioo a b) = ennreal.of_real (b - a) :=\n  sorry\n\ntheorem lebesgue_length_eq_infi_Icc (s : set \u211d) :\n    lebesgue_length s =\n        infi\n          fun (a : \u211d) =>\n            infi fun (b : \u211d) => infi fun (h : s \u2286 set.Icc a b) => ennreal.of_real (b - a) :=\n  sorry\n\n@[simp] theorem lebesgue_length_Icc (a : \u211d) (b : \u211d) :\n    lebesgue_length (set.Icc a b) = ennreal.of_real (b - a) :=\n  sorry\n\n/-- The Lebesgue outer measure, as an outer measure of \u211d. -/\ndef lebesgue_outer : outer_measure \u211d :=\n  outer_measure.of_function lebesgue_length lebesgue_length_empty\n\ntheorem lebesgue_outer_le_length (s : set \u211d) : coe_fn lebesgue_outer s \u2264 lebesgue_length s :=\n  outer_measure.of_function_le s\n\ntheorem lebesgue_length_subadditive {a : \u211d} {b : \u211d} {c : \u2115 \u2192 \u211d} {d : \u2115 \u2192 \u211d}\n    (ss : set.Icc a b \u2286 set.Union fun (i : \u2115) => set.Ioo (c i) (d i)) :\n    ennreal.of_real (b - a) \u2264 tsum fun (i : \u2115) => ennreal.of_real (d i - c i) :=\n  sorry\n\n@[simp] theorem lebesgue_outer_Icc (a : \u211d) (b : \u211d) :\n    coe_fn lebesgue_outer (set.Icc a b) = ennreal.of_real (b - a) :=\n  sorry\n\n@[simp] theorem lebesgue_outer_singleton (a : \u211d) : coe_fn lebesgue_outer (singleton a) = 0 := sorry\n\n@[simp] theorem lebesgue_outer_Ico (a : \u211d) (b : \u211d) :\n    coe_fn lebesgue_outer (set.Ico a b) = ennreal.of_real (b - a) :=\n  sorry\n\n@[simp] theorem lebesgue_outer_Ioo (a : \u211d) (b : \u211d) :\n    coe_fn lebesgue_outer (set.Ioo a b) = ennreal.of_real (b - a) :=\n  sorry\n\n@[simp] theorem lebesgue_outer_Ioc (a : \u211d) (b : \u211d) :\n    coe_fn lebesgue_outer (set.Ioc a b) = ennreal.of_real (b - a) :=\n  sorry\n\ntheorem is_lebesgue_measurable_Iio {c : \u211d} :\n    measurable_space.is_measurable' (outer_measure.caratheodory lebesgue_outer) (set.Iio c) :=\n  sorry\n\ntheorem lebesgue_outer_trim : outer_measure.trim lebesgue_outer = lebesgue_outer := sorry\n\ntheorem borel_le_lebesgue_measurable : borel \u211d \u2264 outer_measure.caratheodory lebesgue_outer := sorry\n\n/-!\n### Definition of the Lebesgue measure and lengths of intervals\n-/\n\n/-- Lebesgue measure on the Borel sets\n\nThe outer Lebesgue measure is the completion of this measure. (TODO: proof this)\n-/\nprotected instance real.measure_space : measure_space \u211d :=\n  measure_space.mk (measure.mk lebesgue_outer sorry lebesgue_outer_trim)\n\n@[simp] theorem lebesgue_to_outer_measure : measure.to_outer_measure volume = lebesgue_outer := rfl\n\nend measure_theory\n\n\nnamespace real\n\n\ntheorem volume_val (s : set \u211d) : coe_fn volume s = coe_fn measure_theory.lebesgue_outer s := rfl\n\nprotected instance has_no_atoms_volume : measure_theory.has_no_atoms volume :=\n  measure_theory.has_no_atoms.mk measure_theory.lebesgue_outer_singleton\n\n@[simp] theorem volume_Ico {a : \u211d} {b : \u211d} :\n    coe_fn volume (set.Ico a b) = ennreal.of_real (b - a) :=\n  measure_theory.lebesgue_outer_Ico a b\n\n@[simp] theorem volume_Icc {a : \u211d} {b : \u211d} :\n    coe_fn volume (set.Icc a b) = ennreal.of_real (b - a) :=\n  measure_theory.lebesgue_outer_Icc a b\n\n@[simp] theorem volume_Ioo {a : \u211d} {b : \u211d} :\n    coe_fn volume (set.Ioo a b) = ennreal.of_real (b - a) :=\n  measure_theory.lebesgue_outer_Ioo a b\n\n@[simp] theorem volume_Ioc {a : \u211d} {b : \u211d} :\n    coe_fn volume (set.Ioc a b) = ennreal.of_real (b - a) :=\n  measure_theory.lebesgue_outer_Ioc a b\n\n@[simp] theorem volume_singleton {a : \u211d} : coe_fn volume (singleton a) = 0 :=\n  measure_theory.lebesgue_outer_singleton a\n\n@[simp] theorem volume_interval {a : \u211d} {b : \u211d} :\n    coe_fn volume (set.interval a b) = ennreal.of_real (abs (b - a)) :=\n  sorry\n\n@[simp] theorem volume_Ioi {a : \u211d} : coe_fn volume (set.Ioi a) = \u22a4 := sorry\n\n@[simp] theorem volume_Ici {a : \u211d} : coe_fn volume (set.Ici a) = \u22a4 := sorry\n\n@[simp] theorem volume_Iio {a : \u211d} : coe_fn volume (set.Iio a) = \u22a4 := sorry\n\n@[simp] theorem volume_Iic {a : \u211d} : coe_fn volume (set.Iic a) = \u22a4 := sorry\n\nprotected instance locally_finite_volume : measure_theory.locally_finite_measure volume :=\n  measure_theory.locally_finite_measure.mk\n    fun (x : \u211d) =>\n      Exists.intro (set.Ioo (x - 1) (x + 1))\n        (Exists.intro\n          (mem_nhds_sets is_open_Ioo\n            { left := sub_lt_self x zero_lt_one, right := lt_add_of_pos_right x zero_lt_one })\n          (eq.mpr\n            (id\n              (Eq.trans\n                ((fun (\u1fb0 \u1fb0_1 : ennreal) (e_2 : \u1fb0 = \u1fb0_1) (\u1fb0_2 \u1fb0_3 : ennreal) (e_3 : \u1fb0_2 = \u1fb0_3) =>\n                    congr (congr_arg Less e_2) e_3)\n                  (coe_fn volume (set.Ioo (x - 1) (x + 1))) (ennreal.of_real (x + 1 - (x - 1)))\n                  volume_Ioo \u22a4 \u22a4 (Eq.refl \u22a4))\n                (propext (iff_true_intro ennreal.of_real_lt_top))))\n            trivial))\n\n/-!\n### Volume of a box in `\u211d\u207f`\n-/\n\ntheorem volume_Icc_pi {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d} :\n    coe_fn volume (set.Icc a b) =\n        finset.prod finset.univ fun (i : \u03b9) => ennreal.of_real (b i - a i) :=\n  sorry\n\n@[simp] theorem volume_Icc_pi_to_real {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d}\n    (h : a \u2264 b) :\n    ennreal.to_real (coe_fn volume (set.Icc a b)) =\n        finset.prod finset.univ fun (i : \u03b9) => b i - a i :=\n  sorry\n\ntheorem volume_pi_Ioo {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d} :\n    coe_fn volume (set.pi set.univ fun (i : \u03b9) => set.Ioo (a i) (b i)) =\n        finset.prod finset.univ fun (i : \u03b9) => ennreal.of_real (b i - a i) :=\n  Eq.trans (measure_theory.measure_congr measure_theory.measure.univ_pi_Ioo_ae_eq_Icc) volume_Icc_pi\n\n@[simp] theorem volume_pi_Ioo_to_real {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d}\n    (h : a \u2264 b) :\n    ennreal.to_real (coe_fn volume (set.pi set.univ fun (i : \u03b9) => set.Ioo (a i) (b i))) =\n        finset.prod finset.univ fun (i : \u03b9) => b i - a i :=\n  sorry\n\ntheorem volume_pi_Ioc {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d} :\n    coe_fn volume (set.pi set.univ fun (i : \u03b9) => set.Ioc (a i) (b i)) =\n        finset.prod finset.univ fun (i : \u03b9) => ennreal.of_real (b i - a i) :=\n  Eq.trans (measure_theory.measure_congr measure_theory.measure.univ_pi_Ioc_ae_eq_Icc) volume_Icc_pi\n\n@[simp] theorem volume_pi_Ioc_to_real {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d}\n    (h : a \u2264 b) :\n    ennreal.to_real (coe_fn volume (set.pi set.univ fun (i : \u03b9) => set.Ioc (a i) (b i))) =\n        finset.prod finset.univ fun (i : \u03b9) => b i - a i :=\n  sorry\n\ntheorem volume_pi_Ico {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d} :\n    coe_fn volume (set.pi set.univ fun (i : \u03b9) => set.Ico (a i) (b i)) =\n        finset.prod finset.univ fun (i : \u03b9) => ennreal.of_real (b i - a i) :=\n  Eq.trans (measure_theory.measure_congr measure_theory.measure.univ_pi_Ico_ae_eq_Icc) volume_Icc_pi\n\n@[simp] theorem volume_pi_Ico_to_real {\u03b9 : Type u_1} [fintype \u03b9] {a : \u03b9 \u2192 \u211d} {b : \u03b9 \u2192 \u211d}\n    (h : a \u2264 b) :\n    ennreal.to_real (coe_fn volume (set.pi set.univ fun (i : \u03b9) => set.Ico (a i) (b i))) =\n        finset.prod finset.univ fun (i : \u03b9) => b i - a i :=\n  sorry\n\n/-!\n### Images of the Lebesgue measure under translation/multiplication/...\n-/\n\ntheorem map_volume_add_left (a : \u211d) :\n    coe_fn (measure_theory.measure.map (Add.add a)) volume = volume :=\n  sorry\n\ntheorem map_volume_add_right (a : \u211d) :\n    coe_fn (measure_theory.measure.map fun (_x : \u211d) => _x + a) volume = volume :=\n  sorry\n\ntheorem smul_map_volume_mul_left {a : \u211d} (h : a \u2260 0) :\n    ennreal.of_real (abs a) \u2022 coe_fn (measure_theory.measure.map (Mul.mul a)) volume = volume :=\n  sorry\n\ntheorem map_volume_mul_left {a : \u211d} (h : a \u2260 0) :\n    coe_fn (measure_theory.measure.map (Mul.mul a)) volume = ennreal.of_real (abs (a\u207b\u00b9)) \u2022 volume :=\n  sorry\n\ntheorem smul_map_volume_mul_right {a : \u211d} (h : a \u2260 0) :\n    ennreal.of_real (abs a) \u2022 coe_fn (measure_theory.measure.map fun (_x : \u211d) => _x * a) volume =\n        volume :=\n  sorry\n\ntheorem map_volume_mul_right {a : \u211d} (h : a \u2260 0) :\n    coe_fn (measure_theory.measure.map fun (_x : \u211d) => _x * a) volume =\n        ennreal.of_real (abs (a\u207b\u00b9)) \u2022 volume :=\n  sorry\n\n@[simp] theorem map_volume_neg : coe_fn (measure_theory.measure.map Neg.neg) volume = volume :=\n  sorry\n\nend real\n\n\ntheorem filter.eventually.volume_pos_of_nhds_real {p : \u211d \u2192 Prop} {a : \u211d}\n    (h : filter.eventually (fun (x : \u211d) => p x) (nhds a)) :\n    0 < coe_fn volume (set_of fun (x : \u211d) => p x) :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/measure_theory/lebesgue_measure_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7034917283980228}}
{"text": "\n\ntheorem tst0 (x : Nat) : x + 0 = x + 0 :=\nby {\n  generalize x + 0 = y;\n  exact (Eq.refl y)\n}\n\ntheorem tst1 (x : Nat) : x + 0 = x + 0 :=\nby {\n  generalize h : x + 0 = y;\n  exact (Eq.refl y)\n}\n\ntheorem tst2 (x y w : Nat) (h : y = w) : (x + x) + w  = (x + x) + y :=\nby {\n  generalize h' : x + x = z;\n  subst y;\n  exact Eq.refl $ z + w\n}\n\ntheorem tst3 (x y w : Nat) (h : x + x = y) : (x + x) + (x+x)  = (x + x) + y :=\nby {\n  generalize h' : x + x = z;\n  subst z;\n  subst y;\n  exact rfl\n}\n\ntheorem tst4 (x y w : Nat) (h : y = w) : (x + x) + w  = (x + x) + y :=\nby {\n  generalize h' : x + y = z; -- just add equality\n  subst h;\n  exact rfl\n}\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/generalize.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569268, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7034917201728211}}
{"text": "/-\nCopyright (c) 2021 Ashvni Narayanan. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ashvni Narayanan, David Loeffler\n-/\nimport data.polynomial.algebra_map\nimport data.polynomial.derivative\nimport data.nat.choose.cast\nimport number_theory.bernoulli\n\n/-!\n# Bernoulli polynomials\n\nThe [Bernoulli polynomials](https://en.wikipedia.org/wiki/Bernoulli_polynomials)\nare an important tool obtained from Bernoulli numbers.\n\n## Mathematical overview\n\nThe $n$-th Bernoulli polynomial is defined as\n$$ B_n(X) = \u2211_{k = 0}^n {n \\choose k} (-1)^k  B_k  X^{n - k} $$\nwhere $B_k$ is the $k$-th Bernoulli number. The Bernoulli polynomials are generating functions,\n$$ \\frac{t  e^{tX} }{ e^t - 1} = \u2211_{n = 0}^{\\infty} B_n(X)  \\frac{t^n}{n!} $$\n\n## Implementation detail\n\nBernoulli polynomials are defined using `bernoulli`, the Bernoulli numbers.\n\n## Main theorems\n\n- `sum_bernoulli`: The sum of the $k^\\mathrm{th}$ Bernoulli polynomial with binomial\n  coefficients up to `n` is `(n + 1) * X^n`.\n- `polynomial.bernoulli_generating_function`: The Bernoulli polynomials act as generating functions\n  for the exponential.\n\n## TODO\n\n- `bernoulli_eval_one_neg` : $$ B_n(1 - x) = (-1)^n B_n(x) $$\n\n-/\n\nnoncomputable theory\nopen_locale big_operators\nopen_locale nat polynomial\n\nopen nat finset\n\nnamespace polynomial\n\n/-- The Bernoulli polynomials are defined in terms of the negative Bernoulli numbers. -/\ndef bernoulli (n : \u2115) : \u211a[X] :=\n  \u2211 i in range (n + 1), polynomial.monomial (n - i) ((_root_.bernoulli i) * (choose n i))\n\nlemma bernoulli_def (n : \u2115) : bernoulli n =\n  \u2211 i in range (n + 1), polynomial.monomial i ((_root_.bernoulli (n - i)) * (choose n i)) :=\nbegin\n  rw [\u2190sum_range_reflect, add_succ_sub_one, add_zero, bernoulli],\n  apply sum_congr rfl,\n  rintros x hx,\n  rw mem_range_succ_iff at hx, rw [choose_symm hx, tsub_tsub_cancel_of_le hx],\nend\n\n/-\n### examples\n-/\n\nsection examples\n\n@[simp] lemma bernoulli_zero : bernoulli 0 = 1 :=\nby simp [bernoulli]\n\n@[simp] lemma bernoulli_eval_zero (n : \u2115) : (bernoulli n).eval 0 = _root_.bernoulli n :=\nbegin\n rw [bernoulli, eval_finset_sum, sum_range_succ],\n  have : \u2211 (x : \u2115) in range n, _root_.bernoulli x * (n.choose x) * 0 ^ (n - x) = 0,\n  { apply sum_eq_zero (\u03bb x hx, _),\n    have h : 0 < n - x := tsub_pos_of_lt (mem_range.1 hx),\n    simp [h] },\n  simp [this],\nend\n\n@[simp] lemma bernoulli_eval_one (n : \u2115) : (bernoulli n).eval 1 = _root_.bernoulli' n :=\nbegin\n  simp only [bernoulli, eval_finset_sum],\n  simp only [\u2190succ_eq_add_one, sum_range_succ, mul_one, cast_one, choose_self,\n    (_root_.bernoulli _).mul_comm, sum_bernoulli, one_pow, mul_one, eval_C, eval_monomial],\n  by_cases h : n = 1,\n  { norm_num [h], },\n  { simp [h],\n    exact bernoulli_eq_bernoulli'_of_ne_one h, }\nend\n\nend examples\n\nlemma derivative_bernoulli_add_one (k : \u2115) :\n  (bernoulli (k + 1)).derivative = (k + 1) * bernoulli k :=\nbegin\n  simp_rw [bernoulli, derivative_sum, derivative_monomial, nat.sub_sub, nat.add_sub_add_right],\n  -- LHS sum has an extra term, but the coefficient is zero:\n  rw [range_add_one, sum_insert not_mem_range_self, tsub_self, cast_zero, mul_zero, map_zero,\n    zero_add, mul_sum],\n  -- the rest of the sum is termwise equal:\n  refine sum_congr (by refl) (\u03bb m hm, _),\n  conv_rhs { rw [\u2190nat.cast_one, \u2190nat.cast_add, \u2190C_eq_nat_cast, C_mul_monomial, mul_comm], },\n  rw [mul_assoc, mul_assoc, \u2190nat.cast_mul, \u2190nat.cast_mul],\n  congr' 3,\n  rw [(choose_mul_succ_eq k m).symm, mul_comm],\nend\n\nlemma derivative_bernoulli (k : \u2115) : (bernoulli k).derivative = k * bernoulli (k - 1) :=\nbegin\n  cases k,\n  { rw [nat.cast_zero, zero_mul, bernoulli_zero, derivative_one], },\n  { exact_mod_cast derivative_bernoulli_add_one k, }\nend\n\n@[simp] theorem sum_bernoulli (n : \u2115) :\n  \u2211 k in range (n + 1), ((n + 1).choose k : \u211a) \u2022 bernoulli k = monomial n (n + 1 : \u211a) :=\nbegin\n simp_rw [bernoulli_def, finset.smul_sum, finset.range_eq_Ico, \u2190finset.sum_Ico_Ico_comm,\n    finset.sum_Ico_eq_sum_range],\n  simp only [add_tsub_cancel_left, tsub_zero, zero_add, linear_map.map_add],\n  simp_rw [smul_monomial, mul_comm (_root_.bernoulli _) _, smul_eq_mul, \u2190mul_assoc],\n  conv_lhs { apply_congr, skip, conv\n    { apply_congr, skip,\n      rw [\u2190 nat.cast_mul, choose_mul ((le_tsub_iff_left $ mem_range_le H).1\n        $ mem_range_le H_1) (le.intro rfl), nat.cast_mul, add_comm x x_1, add_tsub_cancel_right,\n        mul_assoc, mul_comm, \u2190smul_eq_mul, \u2190smul_monomial] },\n    rw [\u2190sum_smul], },\n  rw [sum_range_succ_comm],\n  simp only [add_right_eq_self, mul_one, cast_one, cast_add, add_tsub_cancel_left,\n    choose_succ_self_right, one_smul, _root_.bernoulli_zero, sum_singleton, zero_add,\n    linear_map.map_add, range_one],\n  apply sum_eq_zero (\u03bb x hx, _),\n  have f : \u2200 x \u2208 range n, \u00ac n + 1 - x = 1,\n  { rintros x H, rw [mem_range] at H,\n    rw [eq_comm],\n    exact ne_of_lt (nat.lt_of_lt_of_le one_lt_two (le_tsub_of_add_le_left (succ_le_succ H))) },\n  rw [sum_bernoulli],\n  have g : (ite (n + 1 - x = 1) (1 : \u211a) 0) = 0,\n  { simp only [ite_eq_right_iff, one_ne_zero],\n    intro h\u2081,\n    exact (f x hx) h\u2081, },\n  rw [g, zero_smul],\nend\n\n/-- Another version of `polynomial.sum_bernoulli`. -/\nlemma bernoulli_eq_sub_sum (n : \u2115) : (n.succ : \u211a) \u2022 bernoulli n = monomial n (n.succ : \u211a) -\n  \u2211 k in finset.range n, ((n + 1).choose k : \u211a) \u2022 bernoulli k :=\nby rw [nat.cast_succ, \u2190 sum_bernoulli n, sum_range_succ, add_sub_cancel',\n  choose_succ_self_right, nat.cast_succ]\n\n/-- Another version of `bernoulli.sum_range_pow`. -/\nlemma sum_range_pow_eq_bernoulli_sub (n p : \u2115) :\n  (p + 1 : \u211a) * \u2211 k in range n, (k : \u211a) ^ p = (bernoulli p.succ).eval n -\n  (_root_.bernoulli p.succ) :=\nbegin\n  rw [sum_range_pow, bernoulli_def, eval_finset_sum, \u2190sum_div, mul_div_cancel' _ _],\n  { simp_rw [eval_monomial],\n    symmetry,\n    rw [\u2190sum_flip _, sum_range_succ],\n    simp only [tsub_self, tsub_zero, choose_zero_right, cast_one, mul_one, pow_zero,\n      add_tsub_cancel_right],\n    apply sum_congr rfl (\u03bb x hx, _),\n    apply congr_arg2 _ (congr_arg2 _ _ _) rfl,\n    { rw nat.sub_sub_self (mem_range_le hx), },\n    { rw \u2190choose_symm (mem_range_le hx), }, },\n  { norm_cast, apply succ_ne_zero _, },\nend\n\n/-- Rearrangement of `polynomial.sum_range_pow_eq_bernoulli_sub`. -/\nlemma bernoulli_succ_eval (n p : \u2115) : (bernoulli p.succ).eval n =\n  _root_.bernoulli (p.succ) + (p + 1 : \u211a) * \u2211 k in range n, (k : \u211a) ^ p :=\nby { apply eq_add_of_sub_eq', rw sum_range_pow_eq_bernoulli_sub, }\n\nlemma bernoulli_eval_one_add (n : \u2115) (x : \u211a) :\n  (bernoulli n).eval (1 + x) = (bernoulli n).eval x + n * x^(n - 1) :=\nbegin\n  apply nat.strong_induction_on n (\u03bb d hd, _),\n  have nz : ((d.succ : \u2115): \u211a) \u2260 0,\n  { norm_cast, exact d.succ_ne_zero, },\n  apply (mul_right_inj' nz).1,\n  rw [\u2190 smul_eq_mul, \u2190eval_smul, bernoulli_eq_sub_sum, mul_add, \u2190smul_eq_mul,\n    \u2190eval_smul, bernoulli_eq_sub_sum, eval_sub, eval_finset_sum],\n  conv_lhs { congr, skip, apply_congr, skip, rw [eval_smul, hd x_1 (mem_range.1 H)], },\n  rw [eval_sub, eval_finset_sum],\n  simp_rw [eval_smul, smul_add],\n  rw [sum_add_distrib, sub_add, sub_eq_sub_iff_sub_eq_sub, _root_.add_sub_sub_cancel],\n  conv_rhs { congr, skip, congr, rw [succ_eq_add_one, \u2190choose_succ_self_right d], },\n  rw [nat.cast_succ, \u2190 smul_eq_mul, \u2190sum_range_succ _ d, eval_monomial_one_add_sub],\n  simp_rw [smul_eq_mul],\nend\n\nopen power_series\nvariables {A : Type*} [comm_ring A] [algebra \u211a A]\n\n-- TODO: define exponential generating functions, and use them here\n-- This name should probably be updated afterwards\n\n/-- The theorem that $(e^X - 1) * \u2211 B\u2099(t)* X^n/n! = Xe^{tX}$ -/\ntheorem bernoulli_generating_function (t : A) :\n  mk (\u03bb n, aeval t ((1 / n! : \u211a) \u2022 bernoulli n)) * (exp A - 1) =\n    power_series.X * rescale t (exp A) :=\nbegin\n  -- check equality of power series by checking coefficients of X^n\n  ext n,\n  -- n = 0 case solved by `simp`\n  cases n, { simp },\n  -- n \u2265 1, the coefficients is a sum to n+2, so use `sum_range_succ` to write as\n  -- last term plus sum to n+1\n  rw [coeff_succ_X_mul, coeff_rescale, coeff_exp, power_series.coeff_mul,\n    nat.sum_antidiagonal_eq_sum_range_succ_mk, sum_range_succ],\n  -- last term is zero so kill with `add_zero`\n  simp only [ring_hom.map_sub, tsub_self, constant_coeff_one, constant_coeff_exp,\n    coeff_zero_eq_constant_coeff, mul_zero, sub_self, add_zero],\n  -- Let's multiply both sides by (n+1)! (OK because it's a unit)\n  have hnp1 : is_unit ((n+1)! : \u211a) := is_unit.mk0 _ (by exact_mod_cast factorial_ne_zero (n+1)),\n  rw \u2190(hnp1.map (algebra_map \u211a A)).mul_right_inj,\n  -- do trivial rearrangements to make RHS (n+1)*t^n\n  rw [mul_left_comm, \u2190ring_hom.map_mul],\n  change _ = t^n * algebra_map \u211a A (((n+1)*n! : \u2115)*(1/n!)),\n  rw [cast_mul, mul_assoc, mul_one_div_cancel\n    (show (n! : \u211a) \u2260 0, from cast_ne_zero.2 (factorial_ne_zero n)), mul_one, mul_comm (t^n),\n    \u2190 aeval_monomial, cast_add, cast_one],\n  -- But this is the RHS of `sum_bernoulli_poly`\n  rw [\u2190 sum_bernoulli, finset.mul_sum, alg_hom.map_sum],\n  -- and now we have to prove a sum is a sum, but all the terms are equal.\n  apply finset.sum_congr rfl,\n  -- The rest is just trivialities, hampered by the fact that we're coercing\n  -- factorials and binomial coefficients between \u2115 and \u211a and A.\n  intros i hi,\n  -- deal with coefficients of e^X-1\n  simp only [nat.cast_choose \u211a (mem_range_le hi), coeff_mk,\n    if_neg (mem_range_sub_ne_zero hi), one_div, alg_hom.map_smul, power_series.coeff_one,\n    coeff_exp, sub_zero, linear_map.map_sub, algebra.smul_mul_assoc, algebra.smul_def,\n    mul_right_comm _ ((aeval t) _), \u2190mul_assoc, \u2190 ring_hom.map_mul, succ_eq_add_one,\n    \u2190 polynomial.C_eq_algebra_map, polynomial.aeval_mul, polynomial.aeval_C],\n  -- finally cancel the Bernoulli polynomial and the algebra_map\n  congr',\n  apply congr_arg,\n  rw [mul_assoc, div_eq_mul_inv, \u2190 mul_inv],\nend\n\nend polynomial\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/bernoulli_polynomials.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7034917088913204}}
{"text": "import Lean4Axiomatic.Metric\nimport Lean4Axiomatic.Rational.Order\n\n/-! # Rational numbers: metric functions -/\n\nnamespace Lean4Axiomatic.Rational\n\nopen Metric (abs dist MetricSpace)\nopen Signed (sgn)\n\n/-! ## Axioms -/\n\n/-- Operations pertaining to metrics on rational numbers. -/\nclass Metric.Ops (\u211a : Type) :=\n  /-- Absolute value. -/\n  _abs : \u211a \u2192 \u211a\n\n  /-- Distance. -/\n  _dist : \u211a \u2192 \u211a \u2192 \u211a\n\n/-- Enables the use of the standard names for absolute value and distance. -/\ninstance metric_space_inst {\u211a : Type} [Metric.Ops \u211a] : MetricSpace \u211a := {\n  abs := Metric.Ops._abs\n  dist := Metric.Ops._dist\n}\n\n/-- Properties of rational number metrics. -/\nclass Metric.Props\n    {\u2115 \u2124 : outParam Type} [Natural \u2115] [Integer (\u2115 := \u2115) \u2124]\n    (\u211a : Type)\n      [Core (\u2124 := \u2124) \u211a] [Addition \u211a] [Multiplication \u211a]\n      [Negation \u211a] [Sign \u211a] [Subtraction \u211a] [Ops \u211a]\n    :=\n  /--\n  The absolute value of a rational number is equivalent to the product of that\n  number with its sign.\n  -/\n  abs_sgn {p : \u211a} : abs p \u2243 p * sgn p\n\n  /--\n  The distance between two rational numbers is the absolute value of their\n  difference.\n   -/\n  dist_abs {p q : \u211a} : dist p q \u2243 abs (p - q)\n\nexport Metric.Props (abs_sgn dist_abs)\n\n/-- All rational number metric axioms. -/\nclass Metric\n    {\u2115 \u2124 : outParam Type} [Natural \u2115] [Integer (\u2115 := \u2115) \u2124]\n    (\u211a : Type)\n      [Core (\u2124 := \u2124) \u211a] [Addition \u211a] [Multiplication \u211a]\n      [Negation \u211a] [Sign \u211a] [Subtraction \u211a]\n    :=\n  toOps : Metric.Ops \u211a\n  toProps : Metric.Props \u211a\n\nattribute [instance] Metric.toOps\nattribute [instance] Metric.toProps\n\n/-! ## Derived properties -/\n\nvariable {\u2115 \u2124 \u211a : Type}\n  [Natural \u2115] [Integer (\u2115 := \u2115) \u2124]\n  [Core (\u2124 := \u2124) \u211a] [Addition \u211a] [Negation \u211a] [Subtraction \u211a]\n  [Multiplication \u211a] [Reciprocation \u211a] [Division \u211a]\n  [Sign \u211a] [Order \u211a] [Metric \u211a]\n\n/--\nThe absolute value function preserves equivalence over its argument.\n\n**Property intuition**: This must be the case for `abs` to be a function.\n\n**Proof intuition**: Expand `abs` into its `sgn` definition, and use\nsubstitution on multiplication and `sgn`.\n-/\ntheorem abs_subst {p\u2081 p\u2082 : \u211a} : p\u2081 \u2243 p\u2082 \u2192 abs p\u2081 \u2243 abs p\u2082 := by\n  intro (_ : p\u2081 \u2243 p\u2082)\n  show abs p\u2081 \u2243 abs p\u2082\n  calc\n    abs p\u2081      \u2243 _ := abs_sgn\n    p\u2081 * sgn p\u2081 \u2243 _ := mul_substL \u2039p\u2081 \u2243 p\u2082\u203a\n    p\u2082 * sgn p\u2081 \u2243 _ := mul_substR (from_integer_subst (sgn_subst \u2039p\u2081 \u2243 p\u2082\u203a))\n    p\u2082 * sgn p\u2082 \u2243 _ := eqv_symm abs_sgn\n    abs p\u2082      \u2243 _ := eqv_refl\n\n/--\nThe sign of a rational number's absolute value is the squared sign of the\nrational number.\n\n**Property and proof intuition**: The absolute value of a number is that number\ntimes its sign; taking the `sgn` of that gives the result.\n-/\ntheorem sgn_abs {p : \u211a} : sgn (abs p) \u2243 sgn p * sgn p := calc\n  sgn (abs p)             \u2243 _ := sgn_subst abs_sgn\n  sgn (p * sgn p)         \u2243 _ := sgn_compat_mul\n  sgn p * sgn (sgn p : \u211a) \u2243 _ := AA.substR sgn_from_integer\n  sgn p * sgn (sgn p)     \u2243 _ := AA.substR sgn_idemp\n  sgn p * sgn p           \u2243 _ := Rel.refl\n\n/--\nThe absolute value of a rational number is greater than or equivalent to zero.\n\n**Property intuition**: The absolute value discards the sign of a number and\nreturns the magnitude, so we'd expect it to be nonnegative.\n\n**Proof intuition**: The sign of a rational number's absolute value is that\nnumber's sign squared. A square can never be negative, thus the absolute value\nmust be positive or zero.\n-/\ntheorem abs_ge_zero {p : \u211a} : abs p \u2265 0 := by\n  have : sgn (p * p) \u2243 sgn (abs p) := calc\n    sgn (p * p)     \u2243 _ := sgn_compat_mul\n    sgn p * sgn p   \u2243 _ := Rel.symm sgn_abs\n    sgn (abs p)     \u2243 _ := Rel.refl\n  have : sgn (abs p) \u2244 -1 := AA.neqv_substL this nonneg_square\n  have : abs p \u2265 0 := ge_zero_sgn.mpr this\n  exact this\n\n/--\nZero is the only rational number that has an absolute value of zero.\n\n**Property intuition**: This fits the description of absolute value as\n\"distance from zero\".\n\n**Proof intuition**: In the forward direction, `abs p` expands to `p * sgn p`;\nboth factors imply that `p \u2243 0`. In the reverse direction, `p * sgn p` is\ntrivially zero when `p` is.\n-/\ntheorem abs_zero {p : \u211a} : abs p \u2243 0 \u2194 p \u2243 0 := by\n  apply Iff.intro\n  case mp =>\n    intro (_ : abs p \u2243 0)\n    show p \u2243 0\n    have : p * sgn p \u2243 0 := AA.eqv_substL abs_sgn \u2039abs p \u2243 0\u203a\n    have : p \u2243 0 \u2228 (sgn p : \u211a) \u2243 0 := mul_split_zero.mp this\n    match this with\n    | Or.inl (_ : p \u2243 0) =>\n      exact \u2039p \u2243 0\u203a\n    | Or.inr (_ : (sgn p : \u211a) \u2243 0) =>\n      have : sgn p \u2243 0 := from_integer_inject \u2039(sgn p : \u211a) \u2243 0\u203a\n      have : p \u2243 0 := sgn_zero.mpr this\n      exact this\n  case mpr =>\n    intro (_ : p \u2243 0)\n    show abs p \u2243 0\n    calc\n      abs p           \u2243 _ := abs_sgn\n      p * sgn p       \u2243 _ := mul_substL \u2039p \u2243 0\u203a\n      (0 : \u211a) * sgn p \u2243 _ := mul_absorbL\n      0               \u2243 _ := eqv_refl\n\nend Lean4Axiomatic.Rational\n", "meta": {"author": "cruhland", "repo": "lean4-axiomatic", "sha": "6384bd38b8ba104530247d25456858775fe3c442", "save_path": "github-repos/lean/cruhland-lean4-axiomatic", "path": "github-repos/lean/cruhland-lean4-axiomatic/lean4-axiomatic-6384bd38b8ba104530247d25456858775fe3c442/Lean4Axiomatic/Rational/Metric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7034091742788504}}
{"text": "import ...common.int ...common.atom ...common.list \n\nnamespace lia \n\nopen list\n\nvariables {\u03b1 \u03b2 : Type}\n\ninductive atom : Type \n| le : int \u2192 list int \u2192 atom\n| dvd : int \u2192 int \u2192 list int \u2192 atom\n| ndvd : int \u2192 int \u2192 list int \u2192 atom\n\n-- | (atom.le i ks) := sorry\n-- | (atom.dvd d i ks) := sorry\n-- | (atom.ndvd d i ks) := sorry\n\nmeta def coeffs_to_format : nat \u2192 list int \u2192 format \n| _ [] := \"_\"\n| n [k] := to_fmt k ++ \"x\" ++ to_fmt n\n| n (k1::k2::ks) := to_fmt k1 ++ \"x\" ++ to_fmt n ++ \" + \" ++ coeffs_to_format (n+1) (k2::ks)\n\nmeta def atom_to_format : atom \u2192 format \n| (atom.le i ks) := to_fmt i ++ \" \u2264 \" ++ coeffs_to_format 0 ks\n| (atom.dvd d i ks) := to_fmt d ++ \" | \" ++ to_fmt i ++ \" + \" ++ coeffs_to_format 0 ks\n| (atom.ndvd d i ks) := \"\u00ac(\" ++ atom_to_format (atom.dvd d i ks) ++ \")\"\n\nmeta instance : has_to_format atom := \n\u27e8atom_to_format\u27e9 \n\nmeta instance : has_to_tactic_format atom := \nhas_to_format_to_has_to_tactic_format _\n\nmeta instance : has_reflect int :=\nby tactic.mk_has_reflect_instance \n\nmeta instance has_reflect_atom : has_reflect atom :=\nby tactic.mk_has_reflect_instance \n\ninstance dec_eq : decidable_eq atom := \nby tactic.mk_dec_eq_instance\n\nopen atom \n\ndef val : list int \u2192 atom \u2192 Prop \n| xs (le i ks) := i \u2264 list.dot_prod ks xs\n| xs (dvd d i ks) := has_dvd.dvd d (i + list.dot_prod ks xs)\n| xs (ndvd d i ks) := \u00ac (has_dvd.dvd d (i + list.dot_prod ks xs))\n\ndef neg : atom \u2192 fm atom\n| (le i ks) := fm.atom (atom.le (1 - i) (list.map has_neg.neg ks))\n| (dvd d i ks)  := fm.atom (ndvd d i ks)\n| (ndvd d i ks) := fm.atom (dvd d i ks)\n\ndef neg_prsv : \u2200 (a : atom) (xs : list \u2124), interp val xs (neg a) \u2194 interp val xs (\u00ac' A' a) \n| (le i ks)     xs := \n  begin \n    unfold neg, unfold interp, \n    unfold val, \n    apply \n    (calc \n          (1 - i \u2264 list.dot_prod (list.map has_neg.neg ks) xs) \n        \u2194 (has_neg.neg (dot_prod (list.map has_neg.neg ks) xs) \u2264 has_neg.neg (1 - i)) : \n          by {apply iff.intro, apply neg_le_neg, apply le_of_neg_le_neg}\n    ... \u2194 (dot_prod ks xs \u2264 has_neg.neg (1 - i)) : \n          begin rewrite (@neg_dot_prod int _ ks xs), simp, end\n    ... \u2194 (dot_prod ks xs \u2264 i - 1) : \n           by rewrite neg_sub\n    ... \u2194 (dot_prod ks xs < i) : \n          begin\n            apply iff.intro,\n            apply int.lt_of_le_sub_one,\n            apply int.le_sub_one_of_lt \n          end\n    ... \u2194 \u00aci \u2264 dot_prod ks xs : \n          begin\n            apply iff.intro,\n            apply not_le_of_gt,\n            apply lt_of_not_ge\n          end )\n  end\n| (dvd d i ks)  xs := by refl\n| (ndvd d i ks) xs := by apply iff_not_not\n\ndef decr : atom \u2192 atom \n| (le i ks)     := le i (list.tail ks)\n| (dvd d i ks)  := dvd d i (list.tail ks)\n| (ndvd d i ks) := ndvd d i (list.tail ks)\n\ndef hd_coeff : atom \u2192 int \n| (le i ks)     := list.head_dft 0 ks\n| (dvd d i ks)  := list.head_dft 0 ks\n| (ndvd d i ks) := list.head_dft 0 ks\n\ndef dep0 (a) := hd_coeff a \u2260 0\n\nmeta def decr_prsv_aux : tactic unit := \n`[unfold decr, unfold val, \n  cases ks with k ks, \n  simp, repeat {rewrite nil_dot_prod},\n  unfold dep0 at h, unfold hd_coeff at h, \n  unfold list.head_dft at h, \n  have h' := classical.by_contradiction h, \n  clear h, subst h', cases bs with b' bs', \n  simp, rewrite cons_dot_prod_cons,\n  rewrite zero_mul, rewrite zero_add, simp]\n\nlemma decr_prsv : \u2200 (a : atom), \u00acdep0 a \u2192 \u2200 (b : \u2124) (bs : list \u2124), \n  val bs (decr a) \u2194 val (b :: bs) a\n| (le i ks)      h b bs := by decr_prsv_aux\n| (dvd d i ks)   h b bs := by decr_prsv_aux\n| (ndvd d i ks)  h b bs := by decr_prsv_aux\n\ndef normal : atom \u2192 Prop \n| (le i ks)     := true\n| (dvd d i ks)  := d \u2260 0\n| (ndvd d i ks) := d \u2260 0 \n\ndef divisor : atom \u2192 int \n| (le i ks)     := 1\n| (dvd d i ks)  := d \n| (ndvd d i ks) := d \n\nlemma normal_iff_divisor_nonzero {a : atom} :\n  normal a \u2194 divisor a \u2260 0 :=\nbegin\n  cases a with i ks d i ks d i ks,\n  apply true_iff_true, trivial, \n  intro hc, cases hc, refl, refl\nend\n\ndef dec_normal : decidable_pred normal  \n| (le i ks)     := decidable.is_true trivial\n| (dvd d i ks)  := by apply dec_not_pred_of_dec_pred\n| (ndvd d i ks) := by apply dec_not_pred_of_dec_pred\n\nmeta def neg_prsv_normal_aux :=\n  `[unfold neg at hb, unfold atoms at hb, \n    rewrite (eq_of_mem_singleton hb), trivial]\n\nlemma neg_prsv_normal : \u2200 (a : atom), normal a \u2192 \u2200 (b : atom), b \u2208 @atoms _ _ (neg a) \u2192 normal b \n| (le i ks)     h b hb := by neg_prsv_normal_aux\n| (dvd d i ks)  h b hb := by neg_prsv_normal_aux\n| (ndvd d i ks) h b hb := by neg_prsv_normal_aux\n\nlemma decr_prsv_normal : \u2200 (a : atom), normal a \u2192 \u00acdep0 a \u2192 normal (decr a) \n| (le i ks)     hn hd := by unfold decr\n| (dvd d i ks)  hn hd := begin intro hc, apply hn hc end \n| (ndvd d i ks) hn hd := begin intro hc, apply hn hc end \n\ninstance : atom_type atom int := \n{ val := val,\n  neg := neg,\n  neg_nqfree := \n    begin intro a, cases a; trivial, end,\n  neg_prsv := neg_prsv,\n  dep0 := dep0,\n  dec_dep0 := \n    begin intro a, apply dec_not_pred_of_dec_pred end,\n  decr := decr,\n  decr_prsv := decr_prsv,\n  inh := 0,\n  dec_eq := _,\n  normal := normal, \n  dec_normal := dec_normal,\n  neg_prsv_normal := neg_prsv_normal,\n  decr_prsv_normal := decr_prsv_normal }\n\ndef asubst (i') (ks') : atom \u2192 atom \n| (le i (k::ks))     := le (i - (k * i')) (comp_add (map_mul k ks') ks)\n| (dvd d i (k::ks))  := dvd d (i + (k * i')) (comp_add (map_mul k ks') ks)\n| (ndvd d i (k::ks)) := ndvd d (i + (k * i')) (comp_add (map_mul k ks') ks)\n| a := a\n\nmeta def asubst_prsv_tac := \n`[unfold asubst, unfold val, rewrite add_assoc,\n  have he : (i' * k + dot_prod (comp_add (map_mul k ks') ks) xs) \n            = (dot_prod (k :: ks) ((i' + dot_prod ks' xs) :: xs)),\n  rewrite cons_dot_prod_cons,\n  rewrite mul_add, rewrite mul_comm, simp, \n  rewrite comp_add_dot_prod, \n  simp, rewrite mul_comm at he, rewrite he]\n\nmeta def asubst_prsv_aux := \n`[unfold asubst, unfold val, \n  repeat {rewrite nil_dot_prod}]\n\nlemma asubst_prsv (i' ks' xs) : \n  \u2200 a, val xs (asubst i' ks' a) \u2194 val ((i' + dot_prod ks' xs)::xs) a \n| (le i (k::ks))     := \n  begin\n    unfold asubst, simp, unfold val, \n    rewrite add_le_iff_le_sub, simp, \n    have he : (i' * k + dot_prod (comp_add (map_mul k ks') ks) xs) \n               = (dot_prod (k :: ks) ((i' + dot_prod ks' xs) :: xs)),\n    rewrite cons_dot_prod_cons,\n    rewrite mul_add, rewrite mul_comm, simp, \n    rewrite comp_add_dot_prod, \n    simp, rewrite mul_comm at he, \n    simp at *, rewrite he\n  end\n| (dvd d i (k::ks))  := by asubst_prsv_tac\n| (ndvd d i (k::ks)) := by asubst_prsv_tac\n| (le i [])     := by asubst_prsv_aux\n| (dvd d i [])  := by asubst_prsv_aux\n| (ndvd d i []) := by asubst_prsv_aux\n\n\nend lia\n", "meta": {"author": "avigad", "repo": "qelim", "sha": "b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60", "save_path": "github-repos/lean/avigad-qelim", "path": "github-repos/lean/avigad-qelim/qelim-b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60/lia/common/atom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7033930287240886}}
{"text": "/-\nCopyright (c) 2021 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n-/\nimport data.set.lattice\nimport order.zorn\nimport tactic.by_contra\n\n/-!\n# Extend a partial order to a linear order\n\nThis file constructs a linear order which is an extension of the given partial order, using Zorn's\nlemma.\n-/\n\nuniverses u\nopen set classical\nopen_locale classical\n\n/--\nAny partial order can be extended to a linear order.\n-/\ntheorem extend_partial_order {\u03b1 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_partial_order \u03b1 r] :\n  \u2203 (s : \u03b1 \u2192 \u03b1 \u2192 Prop) (_ : is_linear_order \u03b1 s), r \u2264 s :=\nbegin\n  let S := {s | is_partial_order \u03b1 s},\n  have hS : \u2200 c, c \u2286 S \u2192 is_chain (\u2264) c \u2192 \u2200 y \u2208 c, (\u2203 ub \u2208 S, \u2200 z \u2208 c, z \u2264 ub),\n  { rintro c hc\u2081 hc\u2082 s hs,\n    haveI := (hc\u2081 hs).1,\n    refine \u27e8Sup c, _, \u03bb z hz, le_Sup hz\u27e9,\n    refine { refl := _, trans := _, antisymm := _ }; simp_rw binary_relation_Sup_iff,\n    { intro x,\n      exact \u27e8s, hs, refl x\u27e9 },\n    { rintro x y z \u27e8s\u2081, h\u2081s\u2081, h\u2082s\u2081\u27e9 \u27e8s\u2082, h\u2081s\u2082, h\u2082s\u2082\u27e9,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2081,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2082,\n      cases hc\u2082.total h\u2081s\u2081 h\u2081s\u2082,\n      { exact \u27e8s\u2082, h\u2081s\u2082, trans (h _ _ h\u2082s\u2081) h\u2082s\u2082\u27e9 },\n      { exact \u27e8s\u2081, h\u2081s\u2081, trans h\u2082s\u2081 (h _ _ h\u2082s\u2082)\u27e9 } },\n    { rintro x y \u27e8s\u2081, h\u2081s\u2081, h\u2082s\u2081\u27e9 \u27e8s\u2082, h\u2081s\u2082, h\u2082s\u2082\u27e9,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2081,\n      haveI : is_partial_order _ _ := hc\u2081 h\u2081s\u2082,\n      cases hc\u2082.total h\u2081s\u2081 h\u2081s\u2082,\n      { exact antisymm (h _ _ h\u2082s\u2081) h\u2082s\u2082 },\n      { apply antisymm h\u2082s\u2081 (h _ _ h\u2082s\u2082) } } },\n  obtain \u27e8s, hs\u2081 : is_partial_order _ _, rs, hs\u2082\u27e9 := zorn_nonempty_partial_order\u2080 S hS r \u2039_\u203a,\n  resetI,\n  refine \u27e8s, { total := _ }, rs\u27e9,\n  intros x y,\n  by_contra' h,\n  let s' := \u03bb x' y', s x' y' \u2228 s x' x \u2227 s y y',\n  rw \u2190hs\u2082 s' _ (\u03bb _ _, or.inl) at h,\n  { apply h.1 (or.inr \u27e8refl _, refl _\u27e9) },\n  { refine\n      { refl := \u03bb x, or.inl (refl _),\n        trans := _,\n        antisymm := _ },\n    { rintro a b c (ab | \u27e8ax : s a x, yb : s y b\u27e9) (bc | \u27e8bx : s b x, yc : s y c\u27e9),\n      { exact or.inl (trans ab bc), },\n      { exact or.inr \u27e8trans ab bx, yc\u27e9 },\n      { exact or.inr \u27e8ax, trans yb bc\u27e9 },\n      { exact or.inr \u27e8ax, yc\u27e9 } },\n    { rintro a b (ab | \u27e8ax : s a x, yb : s y b\u27e9) (ba | \u27e8bx : s b x, ya : s y a\u27e9),\n      { exact antisymm ab ba },\n      { exact (h.2 (trans ya (trans ab bx))).elim },\n      { exact (h.2 (trans yb (trans ba ax))).elim },\n      { exact (h.2 (trans yb bx)).elim } } },\nend\n\n/-- A type alias for `\u03b1`, intended to extend a partial order on `\u03b1` to a linear order. -/\ndef linear_extension (\u03b1 : Type u) : Type u := \u03b1\n\nnoncomputable instance {\u03b1 : Type u} [partial_order \u03b1] : linear_order (linear_extension \u03b1) :=\n{ le := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some,\n  le_refl := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.1.1.1.1,\n  le_trans := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.1.1.2.1,\n  le_antisymm := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.1.2.1,\n  le_total := (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some.2.1,\n  decidable_le := classical.dec_rel _ }\n\n/-- The embedding of `\u03b1` into `linear_extension \u03b1` as a relation homomorphism. -/\ndef to_linear_extension {\u03b1 : Type u} [partial_order \u03b1] :\n  ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop) \u2192r ((\u2264) : linear_extension \u03b1 \u2192 linear_extension \u03b1 \u2192 Prop) :=\n{ to_fun := \u03bb x, x,\n  map_rel' := \u03bb a b, (extend_partial_order ((\u2264) : \u03b1 \u2192 \u03b1 \u2192 Prop)).some_spec.some_spec _ _ }\n\ninstance {\u03b1 : Type u} [inhabited \u03b1] : inhabited (linear_extension \u03b1) :=\n\u27e8(default : \u03b1)\u27e9\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/order/extension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.703393026582305}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Chris Hughes, Floris van Doorn, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.nat.factorial.basic\n! leanprover-community/mathlib commit d012cd09a9b256d870751284dd6a29882b0be105\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Nat.Basic\nimport Mathlib.Data.Nat.Pow\n\n/-!\n# Factorial and variants\n\nThis file defines the factorial, along with the ascending and descending variants.\n\n## Main declarations\n\n* `Nat.factorial`: The factorial.\n* `Nat.ascFactorial`: The ascending factorial. Note that it runs from `n + 1` to `n + k`\n  and *not* from `n` to `n + k - 1`. We might want to change that in the future.\n* `Nat.descFactorial`: The descending factorial. It runs from `n - k` to `n`.\n-/\n\n\nnamespace Nat\n\n/-- `Nat.factorial n` is the factorial of `n`. -/\n@[simp]\ndef factorial : \u2115 \u2192 \u2115\n  | 0 => 1\n  | succ n => succ n * factorial n\n#align nat.factorial Nat.factorial\n\n/-- factorial notation `n!` -/\nscoped notation:10000 n \"!\" => Nat.factorial n\n\nsection Factorial\n\nvariable {m n : \u2115}\n\n@[simp]\ntheorem factorial_zero : 0! = 1 :=\n  rfl\n#align nat.factorial_zero Nat.factorial_zero\n\n@[simp]\ntheorem factorial_succ (n : \u2115) : n.succ ! = (n + 1) * n ! :=\n  rfl\n#align nat.factorial_succ Nat.factorial_succ\n\n\n-- Porting note: can be proved by simp, @[simp] removed\ntheorem factorial_one : 1! = 1 :=\n  rfl\n#align nat.factorial_one Nat.factorial_one\n\n-- Porting note: can be proved by simp, @[simp] removed\ntheorem factorial_two : 2! = 2 :=\n  rfl\n#align nat.factorial_two Nat.factorial_two\n\ntheorem mul_factorial_pred (hn : 0 < n) : n * (n - 1)! = n ! :=\n  tsub_add_cancel_of_le (Nat.succ_le_of_lt hn) \u25b8 rfl\n#align nat.mul_factorial_pred Nat.mul_factorial_pred\n\ntheorem factorial_pos : \u2200 n, 0 < n !\n  | 0 => zero_lt_one\n  | succ n => mul_pos (succ_pos _) (factorial_pos n)\n#align nat.factorial_pos Nat.factorial_pos\n\ntheorem factorial_ne_zero (n : \u2115) : n ! \u2260 0 :=\n  ne_of_gt (factorial_pos _)\n#align nat.factorial_ne_zero Nat.factorial_ne_zero\n\ntheorem factorial_dvd_factorial {m n} (h : m \u2264 n) : m ! \u2223 n ! := by\n  induction' n with n IH\n  \u00b7 simp [Nat.eq_zero_of_le_zero h]\n  obtain rfl | hl := h.eq_or_lt\n  \u00b7 simp\n  exact (IH (le_of_lt_succ hl)).mul_left _\n#align nat.factorial_dvd_factorial Nat.factorial_dvd_factorial\n\ntheorem dvd_factorial : \u2200 {m n}, 0 < m \u2192 m \u2264 n \u2192 m \u2223 n !\n  | succ _, _, _, h => dvd_of_mul_right_dvd (factorial_dvd_factorial h)\n#align nat.dvd_factorial Nat.dvd_factorial\n\n@[mono]\ntheorem factorial_le {m n} (h : m \u2264 n) : m ! \u2264 n ! :=\n  le_of_dvd (factorial_pos _) (factorial_dvd_factorial h)\n#align nat.factorial_le Nat.factorial_le\n\n-- Porting note: Interconversion between `succ` and `\u00b7 + 1` has to be done manually\ntheorem factorial_mul_pow_le_factorial : \u2200 {m n : \u2115}, m ! * m.succ ^ n \u2264 (m + n)!\n  | m, 0 => by simp\n  | m, n + 1 => by\n    rw [\u2190 add_assoc, \u2190 Nat.succ_eq_add_one (m + n), Nat.factorial_succ, pow_succ',\n        mul_comm (_ + 1), mul_comm (succ m), \u2190 mul_assoc]\n    exact\n      mul_le_mul factorial_mul_pow_le_factorial (Nat.succ_le_succ (Nat.le_add_right _ _))\n        (Nat.zero_le _) (Nat.zero_le _)\n#align nat.factorial_mul_pow_le_factorial Nat.factorial_mul_pow_le_factorial\n\ntheorem monotone_factorial : Monotone factorial := fun _ _ => factorial_le\n#align nat.monotone_factorial Nat.monotone_factorial\n\ntheorem factorial_lt (hn : 0 < n) : n ! < m ! \u2194 n < m := by\n  refine' \u27e8fun h => not_le.mp fun hmn => not_le_of_lt h (factorial_le hmn), fun h => _\u27e9\n  have : \u2200 {n}, 0 < n \u2192 n ! < n.succ ! := by\n    intro k hk\n    rw [factorial_succ, succ_mul, lt_add_iff_pos_left]\n    exact mul_pos hk k.factorial_pos\n  induction' h with k hnk ih generalizing hn\n  \u00b7 exact this hn\n  \u00b7 exact (ih hn).trans (this <| hn.trans <| lt_of_succ_le hnk)\n#align nat.factorial_lt Nat.factorial_lt\n\ntheorem one_lt_factorial : 1 < n ! \u2194 1 < n :=\n  factorial_lt one_pos\n#align nat.one_lt_factorial Nat.one_lt_factorial\n\n-- Porting note: `(_ | _)` notation for introduction with cases does not appear to be supported\ntheorem factorial_eq_one : n ! = 1 \u2194 n \u2264 1 := by\n  apply Iff.intro <;> intro\n  \u00b7 rw [\u2190 not_lt, \u2190 one_lt_factorial, \u2039n ! = 1\u203a]\n    apply lt_irrefl\n  \u00b7 cases \u2039n \u2264 1\u203a\n    \u00b7 rfl\n    \u00b7 cases \u2039n \u2264 0\u203a; rfl\n#align nat.factorial_eq_one Nat.factorial_eq_one\n\ntheorem factorial_inj (hn : 1 < n !) : n ! = m ! \u2194 n = m := by\n  refine' \u27e8fun h => _, congr_arg _\u27e9\n  obtain hnm | rfl | hnm := lt_trichotomy n m\n  \u00b7 rw [\u2190 factorial_lt <| pos_of_gt <| one_lt_factorial.mp hn, h] at hnm\n    cases lt_irrefl _ hnm\n  \u00b7 rfl\n  rw [h, one_lt_factorial] at hn\n  rw [\u2190 factorial_lt (lt_trans one_pos hn), h] at hnm\n  cases lt_irrefl _ hnm\n#align nat.factorial_inj Nat.factorial_inj\n\ntheorem self_le_factorial : \u2200 n : \u2115, n \u2264 n !\n  | 0 => zero_le_one\n  | k + 1 => le_mul_of_one_le_right k.zero_lt_succ.le (Nat.one_le_of_lt <| Nat.factorial_pos _)\n#align nat.self_le_factorial Nat.self_le_factorial\n\n-- Porting note: `zero_lt_two` does not work since `ZeroLEOneClass` fails to be synthesised.\n-- Porting note: `0 < 2` is proved `by decide` instead\ntheorem lt_factorial_self {n : \u2115} (hi : 3 \u2264 n) : n < n ! := by\n  have : 0 < n := (by decide : 0 < 2).trans (succ_le_iff.mp hi)\n  have : 1 < pred n := le_pred_of_lt (succ_le_iff.mp hi)\n  rw [\u2190 succ_pred_eq_of_pos \u20390 < n\u203a, factorial_succ]\n  exact\n    lt_mul_of_one_lt_right (pred n).succ_pos\n      ((\u20391 < pred n\u203a).trans_le (self_le_factorial _))\n#align nat.lt_factorial_self Nat.lt_factorial_self\n\ntheorem add_factorial_succ_lt_factorial_add_succ {i : \u2115} (n : \u2115) (hi : 2 \u2264 i) :\n    i + (n + 1)! < (i + n + 1)! := by\n  rw [\u2190 Nat.succ_eq_add_one (i + _), factorial_succ (i + _), add_mul, one_mul]\n  have : i \u2264 i + n := le.intro rfl\n  exact\n    add_lt_add_of_lt_of_le\n      (this.trans_lt\n        ((lt_mul_iff_one_lt_right ((by decide : 0 < 2).trans_le (hi.trans this))).mpr\n          (lt_iff_le_and_ne.mpr\n            \u27e8(i + n).factorial_pos, fun g =>\n              Nat.not_succ_le_self 1 ((hi.trans this).trans (factorial_eq_one.mp g.symm))\u27e9)))\n      (factorial_le\n        ((le_of_eq (add_comm n 1)).trans\n        ((add_le_add_iff_right n).mpr ((by decide : 1 \u2264 2).trans hi))))\n#align nat.add_factorial_succ_lt_factorial_add_succ Nat.add_factorial_succ_lt_factorial_add_succ\n\ntheorem add_factorial_lt_factorial_add {i n : \u2115} (hi : 2 \u2264 i) (hn : 1 \u2264 n) :\n    i + n ! < (i + n)! := by\n  cases hn\n  \u00b7 rw [factorial_one]\n    exact lt_factorial_self (succ_le_succ hi)\n  exact add_factorial_succ_lt_factorial_add_succ _ hi\n#align nat.add_factorial_lt_factorial_add Nat.add_factorial_lt_factorial_add\n\ntheorem add_factorial_succ_le_factorial_add_succ (i : \u2115) (n : \u2115) :\n    i + (n + 1)! \u2264 (i + (n + 1))! := by\n  cases (le_or_lt (2 : \u2115) i)\n  \u00b7 rw [\u2190 add_assoc]\n    apply Nat.le_of_lt\n    apply add_factorial_succ_lt_factorial_add_succ\n    assumption\n  \u00b7 match i with\n    | 0 => simp\n    | 1 =>\n      rw [\u2190 add_assoc, \u2190 Nat.succ_eq_add_one (1 + n), factorial_succ (1 + n),\n        add_mul, one_mul, add_comm 1 n, add_le_add_iff_right]\n      apply one_le_mul\n      \u00b7 apply Nat.le_add_left\n      \u00b7 apply factorial_pos\n    | succ (succ n) => contradiction\n#align nat.add_factorial_succ_le_factorial_add_succ Nat.add_factorial_succ_le_factorial_add_succ\n\ntheorem add_factorial_le_factorial_add (i : \u2115) {n : \u2115} (n1 : 1 \u2264 n) : i + n ! \u2264 (i + n)! := by\n  cases' n1 with h\n  \u00b7 exact self_le_factorial _\n  exact add_factorial_succ_le_factorial_add_succ i h\n#align nat.add_factorial_le_factorial_add Nat.add_factorial_le_factorial_add\n\n\n\nend Factorial\n\n/-! ### Ascending and descending factorials -/\n\n\nsection AscFactorial\n\n/-- `n.ascFactorial k = (n + k)! / n!` (as seen in `Nat.ascFactorial_eq_div`), but implemented\nrecursively to allow for \"quick\" computation when using `norm_num`. This is closely related to\n`pochhammer`, but much less general. -/\ndef ascFactorial (n : \u2115) : \u2115 \u2192 \u2115\n  | 0 => 1\n  | k + 1 => (n + k + 1) * ascFactorial n k\n#align nat.asc_factorial Nat.ascFactorial\n\n@[simp]\ntheorem ascFactorial_zero (n : \u2115) : n.ascFactorial 0 = 1 :=\n  rfl\n#align nat.asc_factorial_zero Nat.ascFactorial_zero\n\n@[simp]\ntheorem zero_ascFactorial (k : \u2115) : (0 : \u2115).ascFactorial k = k ! := by\n  induction' k with t ht\n  \u00b7 rfl\n  rw [ascFactorial, ht, zero_add, Nat.factorial_succ]\n#align nat.zero_asc_factorial Nat.zero_ascFactorial\n\ntheorem ascFactorial_succ {n k : \u2115} : n.ascFactorial k.succ = (n + k + 1) * n.ascFactorial k :=\n  rfl\n#align nat.asc_factorial_succ Nat.ascFactorial_succ\n\n-- Porting note: Explicit arguments are required to show that the recursion terminates\ntheorem succ_ascFactorial (n : \u2115) :\n    \u2200 k, (n + 1) * n.succ.ascFactorial k = (n + k + 1) * n.ascFactorial k\n  | 0 => by rw [add_zero, ascFactorial_zero, ascFactorial_zero]\n  | k + 1 => by\n    rw [ascFactorial, mul_left_comm, succ_ascFactorial n k, ascFactorial,\n      succ_add, \u2190 add_assoc, succ_eq_add_one]\n#align nat.succ_asc_factorial Nat.succ_ascFactorial\n\n/-- `n.ascFactorial k = (n + k)! / n!` but without \u2115-division. See `Nat.ascFactorial_eq_div` for\nthe version with \u2115-division. -/\n-- Porting note: Explicit arguments are required to show that the recursion terminates\n-- Porting note: Interconversion between `succ` and `\u00b7 + 1` has to be done manually\ntheorem factorial_mul_ascFactorial (n : \u2115) : \u2200 k, n ! * n.ascFactorial k = (n + k)!\n  | 0 => by rw [ascFactorial, add_zero, mul_one]\n  | k + 1 => by\n    rw [ascFactorial_succ, mul_left_comm, factorial_mul_ascFactorial n k,\n      \u2190 add_assoc, \u2190 Nat.succ_eq_add_one (n + k), factorial]\n#align nat.factorial_mul_asc_factorial Nat.factorial_mul_ascFactorial\n\n/-- Avoid in favor of `Nat.factorial_mul_ascFactorial` if you can. \u2115-division isn't worth it. -/\ntheorem ascFactorial_eq_div (n k : \u2115) : n.ascFactorial k = (n + k)! / n ! := by\n  apply mul_left_cancel\u2080 n.factorial_ne_zero\n  rw [factorial_mul_ascFactorial]\n  exact (Nat.mul_div_cancel' <| factorial_dvd_factorial <| le.intro rfl).symm\n#align nat.asc_factorial_eq_div Nat.ascFactorial_eq_div\n\ntheorem ascFactorial_of_sub {n k : \u2115} (h : k < n) :\n    (n - k) * (n - k).ascFactorial k = (n - (k + 1)).ascFactorial (k + 1) := by\n  let t := n - k.succ\n  let ht : t = n - k.succ := rfl\n  suffices h' : n - k = t.succ; \u00b7 rw [\u2190 ht, h', succ_ascFactorial, ascFactorial_succ]\n  rw [ht, succ_eq_add_one, \u2190 tsub_tsub_assoc (succ_le_of_lt h) (succ_pos _), succ_sub_one]\n#align nat.asc_factorial_of_sub Nat.ascFactorial_of_sub\n\ntheorem pow_succ_le_ascFactorial (n : \u2115) : \u2200 k : \u2115, (n + 1) ^ k \u2264 n.ascFactorial k\n  | 0 => by rw [ascFactorial_zero, pow_zero]\n  | k + 1 => by\n    rw [pow_succ, mul_comm]\n    exact Nat.mul_le_mul (Nat.add_le_add_right le_self_add _) (pow_succ_le_ascFactorial _ k)\n#align nat.pow_succ_le_asc_factorial Nat.pow_succ_le_ascFactorial\n\ntheorem pow_lt_ascFactorial' (n k : \u2115) : (n + 1) ^ (k + 2) < n.ascFactorial (k + 2) := by\n  rw [pow_succ, ascFactorial, mul_comm]\n  exact\n    Nat.mul_lt_mul (Nat.add_lt_add_right (Nat.lt_add_of_pos_right succ_pos') 1)\n      (pow_succ_le_ascFactorial n _) (pow_pos succ_pos' _)\n#align nat.pow_lt_asc_factorial' Nat.pow_lt_ascFactorial'\n\ntheorem pow_lt_ascFactorial (n : \u2115) : \u2200 {k : \u2115}, 2 \u2264 k \u2192 (n + 1) ^ k < n.ascFactorial k\n  | 0 => by rintro \u27e8\u27e9\n  | 1 => by intro; contradiction\n  | k + 2 => fun _ => pow_lt_ascFactorial' n k\n#align nat.pow_lt_asc_factorial Nat.pow_lt_ascFactorial\n\ntheorem ascFactorial_le_pow_add (n : \u2115) : \u2200 k : \u2115, n.ascFactorial k \u2264 (n + k) ^ k\n  | 0 => by rw [ascFactorial_zero, pow_zero]\n  | k + 1 => by\n    rw [ascFactorial_succ, pow_succ, \u2190 add_assoc,\n    \u2190 Nat.succ_eq_add_one (n + k), mul_comm _ (succ (n + k))]\n    exact\n      Nat.mul_le_mul_of_nonneg_left\n        ((ascFactorial_le_pow_add _ k).trans (Nat.pow_le_pow_of_le_left (le_succ _) _))\n#align nat.asc_factorial_le_pow_add Nat.ascFactorial_le_pow_add\n\ntheorem ascFactorial_lt_pow_add (n : \u2115) : \u2200 {k : \u2115}, 2 \u2264 k \u2192 n.ascFactorial k < (n + k) ^ k\n  | 0 => by rintro \u27e8\u27e9\n  | 1 => by intro; contradiction\n  | k + 2 => fun _ => by\n    rw [ascFactorial_succ, pow_succ]\n    rw [add_assoc n (k + 1) 1, mul_comm <| (n + (k + 2)) ^ (k + 1)]\n    refine'\n      Nat.mul_lt_mul' le_rfl\n        ((ascFactorial_le_pow_add n _).trans_lt\n          (pow_lt_pow_of_lt_left (lt_add_one _) (succ_pos _)))\n        (succ_pos _)\n#align nat.asc_factorial_lt_pow_add Nat.ascFactorial_lt_pow_add\n\ntheorem ascFactorial_pos (n k : \u2115) : 0 < n.ascFactorial k :=\n  (pow_pos (succ_pos n) k).trans_le (pow_succ_le_ascFactorial n k)\n#align nat.asc_factorial_pos Nat.ascFactorial_pos\n\nend AscFactorial\n\nsection DescFactorial\n\n/-- `n.descFactorial k = n! / (n - k)!` (as seen in `Nat.descFactorial_eq_div`), but\nimplemented recursively to allow for \"quick\" computation when using `norm_num`. This is closely\nrelated to `pochhammer`, but much less general. -/\ndef descFactorial (n : \u2115) : \u2115 \u2192 \u2115\n  | 0 => 1\n  | k + 1 => (n - k) * descFactorial n k\n#align nat.desc_factorial Nat.descFactorial\n\n@[simp]\ntheorem descFactorial_zero (n : \u2115) : n.descFactorial 0 = 1 :=\n  rfl\n#align nat.desc_factorial_zero Nat.descFactorial_zero\n\n@[simp]\ntheorem descFactorial_succ (n k : \u2115) : n.descFactorial k.succ = (n - k) * n.descFactorial k :=\n  rfl\n#align nat.desc_factorial_succ Nat.descFactorial_succ\n\ntheorem zero_descFactorial_succ (k : \u2115) : (0 : \u2115).descFactorial k.succ = 0 := by\n  rw [descFactorial_succ, zero_tsub, zero_mul]\n#align nat.zero_desc_factorial_succ Nat.zero_descFactorial_succ\n\n/- Porting note: simp removed because this can be proved by\nsimp only [Nat.descFactorial_succ, nonpos_iff_eq_zero, tsub_zero, Nat.descFactorial_zero, mul_one]\n-/\n-- @[simp]\ntheorem descFactorial_one (n : \u2115) : n.descFactorial 1 = n := by\n  rw [descFactorial_succ, descFactorial_zero, mul_one, tsub_zero]\n#align nat.desc_factorial_one Nat.descFactorial_one\n\n/- Porting note: simp removed because the lhs simplifies,\naccording to the linter:\nLeft-hand side simplifies from\n  Nat.descFactorial (n + 1) (k + 1)\nto\n  (n + 1 - k) * Nat.descFactorial (n + 1) k\nusing\n  simp only [Nat.descFactorial_succ]\n-/\n-- @[simp]\ntheorem succ_descFactorial_succ (n : \u2115) :\n    \u2200 k : \u2115, (n + 1).descFactorial (k + 1) = (n + 1) * n.descFactorial k\n  | 0 => by rw [descFactorial_zero, descFactorial_one, mul_one]\n  | succ k => by\n    rw [descFactorial_succ, succ_descFactorial_succ _ k, descFactorial_succ, succ_sub_succ,\n      mul_left_comm]\n#align nat.succ_desc_factorial_succ Nat.succ_descFactorial_succ\n\ntheorem succ_descFactorial (n : \u2115) :\n    \u2200 k, (n + 1 - k) * (n + 1).descFactorial k = (n + 1) * n.descFactorial k\n  | 0 => by rw [tsub_zero, descFactorial_zero, descFactorial_zero]\n  | k + 1 => by\n    rw [descFactorial, succ_descFactorial _ k, descFactorial_succ, succ_sub_succ, mul_left_comm]\n#align nat.succ_desc_factorial Nat.succ_descFactorial\n\ntheorem descFactorial_self : \u2200 n : \u2115, n.descFactorial n = n !\n  | 0 => by rw [descFactorial_zero, factorial_zero]\n  | succ n => by rw [succ_descFactorial_succ, descFactorial_self n, factorial_succ]\n#align nat.desc_factorial_self Nat.descFactorial_self\n\n@[simp]\ntheorem descFactorial_eq_zero_iff_lt {n : \u2115} : \u2200 {k : \u2115}, n.descFactorial k = 0 \u2194 n < k\n  | 0 => by simp only [descFactorial_zero, Nat.one_ne_zero, Nat.not_lt_zero]\n  | succ k => by\n    rw [descFactorial_succ, mul_eq_zero, descFactorial_eq_zero_iff_lt, lt_succ_iff,\n      tsub_eq_zero_iff_le, lt_iff_le_and_ne, or_iff_left_iff_imp, and_imp]\n    exact fun h _ => h\n#align nat.desc_factorial_eq_zero_iff_lt Nat.descFactorial_eq_zero_iff_lt\n\nalias descFactorial_eq_zero_iff_lt \u2194 _ descFactorial_of_lt\n#align nat.desc_factorial_of_lt Nat.descFactorial_of_lt\n\ntheorem add_descFactorial_eq_ascFactorial (n : \u2115) :\n    \u2200 k : \u2115, (n + k).descFactorial k = n.ascFactorial k\n  | 0 => by rw [ascFactorial_zero, descFactorial_zero]\n  | succ k => by\n    rw [Nat.add_succ, Nat.succ_eq_add_one, Nat.succ_eq_add_one,\n        succ_descFactorial_succ, ascFactorial_succ, add_descFactorial_eq_ascFactorial _ k]\n#align nat.add_desc_factorial_eq_asc_factorial Nat.add_descFactorial_eq_ascFactorial\n\n/-- `n.descFactorial k = n! / (n - k)!` but without \u2115-division. See `Nat.descFactorial_eq_div`\nfor the version using \u2115-division. -/\ntheorem factorial_mul_descFactorial : \u2200 {n k : \u2115}, k \u2264 n \u2192 (n - k)! * n.descFactorial k = n !\n  | n, 0 => fun _ => by rw [descFactorial_zero, mul_one, tsub_zero]\n  | 0, succ k => fun h => by\n    exfalso\n    exact not_succ_le_zero k h\n  | succ n, succ k => fun h => by\n    rw [succ_descFactorial_succ, succ_sub_succ, \u2190 mul_assoc, mul_comm (n - k)!, mul_assoc,\n      factorial_mul_descFactorial (Nat.succ_le_succ_iff.1 h), factorial_succ]\n#align nat.factorial_mul_desc_factorial Nat.factorial_mul_descFactorial\n\n/-- Avoid in favor of `Nat.factorial_mul_descFactorial` if you can. \u2115-division isn't worth it. -/\ntheorem descFactorial_eq_div {n k : \u2115} (h : k \u2264 n) : n.descFactorial k = n ! / (n - k)! := by\n  apply mul_left_cancel\u2080 (factorial_ne_zero (n - k))\n  rw [factorial_mul_descFactorial h]\n  exact (Nat.mul_div_cancel' <| factorial_dvd_factorial <| Nat.sub_le n k).symm\n#align nat.desc_factorial_eq_div Nat.descFactorial_eq_div\n\ntheorem pow_sub_le_descFactorial (n : \u2115) : \u2200 k : \u2115, (n + 1 - k) ^ k \u2264 n.descFactorial k\n  | 0 => by rw [descFactorial_zero, pow_zero]\n  | k + 1 => by\n    rw [descFactorial_succ, pow_succ, succ_sub_succ, mul_comm]\n    apply Nat.mul_le_mul_of_nonneg_left\n    exact   (le_trans (Nat.pow_le_pow_of_le_left (tsub_le_tsub_right (le_succ _) _) k)\n          (pow_sub_le_descFactorial n k))\n#align nat.pow_sub_le_desc_factorial Nat.pow_sub_le_descFactorial\n\ntheorem pow_sub_lt_descFactorial' {n : \u2115} :\n    \u2200 {k : \u2115}, k + 2 \u2264 n \u2192 (n - (k + 1)) ^ (k + 2) < n.descFactorial (k + 2)\n  | 0 => fun h => by\n    rw [descFactorial_succ, pow_succ, pow_one, descFactorial_one]\n    exact\n      Nat.mul_lt_mul_of_pos_left (tsub_lt_self (lt_of_lt_of_le zero_lt_two h) zero_lt_one)\n        (tsub_pos_of_lt h)\n  | k + 1 => fun h => by\n    rw [descFactorial_succ, pow_succ, mul_comm]\n    apply Nat.mul_lt_mul_of_pos_left\n    \u00b7 refine' ((Nat.pow_le_pow_of_le_left (tsub_le_tsub_right (le_succ n) _) _).trans_lt _)\n      rw [succ_sub_succ]\n      exact pow_sub_lt_descFactorial' ((le_succ _).trans h)\n    \u00b7 apply tsub_pos_of_lt; apply h\n#align nat.pow_sub_lt_desc_factorial' Nat.pow_sub_lt_descFactorial'\n\ntheorem pow_sub_lt_descFactorial {n : \u2115} :\n    \u2200 {k : \u2115}, 2 \u2264 k \u2192 k \u2264 n \u2192 (n + 1 - k) ^ k < n.descFactorial k\n  | 0 => by rintro \u27e8\u27e9\n  | 1 => by intro; contradiction\n  | k + 2 => fun _ h => by\n    rw [succ_sub_succ]\n    exact pow_sub_lt_descFactorial' h\n#align nat.pow_sub_lt_desc_factorial Nat.pow_sub_lt_descFactorial\n\ntheorem descFactorial_le_pow (n : \u2115) : \u2200 k : \u2115, n.descFactorial k \u2264 n ^ k\n  | 0 => by rw [descFactorial_zero, pow_zero]\n  | k + 1 => by\n    rw [descFactorial_succ, pow_succ, mul_comm _ n]\n    exact Nat.mul_le_mul (Nat.sub_le _ _) (descFactorial_le_pow _ k)\n#align nat.desc_factorial_le_pow Nat.descFactorial_le_pow\n\ntheorem descFactorial_lt_pow {n : \u2115} (hn : 1 \u2264 n) : \u2200 {k : \u2115}, 2 \u2264 k \u2192 n.descFactorial k < n ^ k\n  | 0 => by rintro \u27e8\u27e9\n  | 1 => by intro; contradiction\n  | k + 2 => fun _ => by\n    rw [descFactorial_succ, pow_succ', mul_comm, mul_comm n]\n    exact Nat.mul_lt_mul' (descFactorial_le_pow _ _) (tsub_lt_self hn k.zero_lt_succ)\n      (pow_pos (Nat.lt_of_succ_le hn) _)\n#align nat.desc_factorial_lt_pow Nat.descFactorial_lt_pow\n\nend DescFactorial\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Factorial/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7033930177260993}}
{"text": "/-\nFill in the sorry.\n\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2203 x, A x) \u2192 \u2203 x, A x \u2228 B x :=\n  sorry\nend\n-/\n\nsection\n  variable U : Type\n  variables A B : U \u2192 Prop\n\n  example : (\u2203 x, A x) \u2192 \u2203 x, A x \u2228 B x :=\n  assume h: (\u2203 x, A x),\n  exists.elim(h)(\n    assume (x: U) (hAx: A(x)),\n    have hAxoBx: A(x) \u2228 B(x), from or.inl(hAx),\n    show \u2203 x, A x \u2228 B x, from exists.intro(x)(hAxoBx)\n  )\nend", "meta": {"author": "chanind", "repo": "logic-and-proof-exercises", "sha": "8d797d400d937cb4f21954b1d7a5092ceb4f6dd7", "save_path": "github-repos/lean/chanind-logic-and-proof-exercises", "path": "github-repos/lean/chanind-logic-and-proof-exercises/logic-and-proof-exercises-8d797d400d937cb4f21954b1d7a5092ceb4f6dd7/chapters/chapter9/ex5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7033930137316032}}
{"text": "import tactic.norm_num data.nat.basic tactic.ring algebra.archimedean .limits data.nat.binomial\nsection a\nopen real nat is_absolute_value finset\nnoncomputable theory\nlocal attribute [instance, priority 0] classical.prop_decidable\n\nlemma pow_inv' {\u03b1 : Type*} [discrete_field \u03b1] (a : \u03b1) (n : \u2115) : (a ^ n)\u207b\u00b9 = a\u207b\u00b9 ^ n :=\nby induction n; simp [_root_.pow_succ, *, mul_inv', mul_comm]\n\nlemma pow_incrs_of_gt_one {\u03b1 : Type*}  [linear_ordered_semiring \u03b1] {x : \u03b1} {n m : \u2115}\n  (h1x : 1 < x) (hnm : n < m) : x ^ n < x ^ m :=\nbegin\n  rw [\u2190 nat.sub_add_cancel hnm, _root_.pow_add, _root_.pow_succ, \u2190 mul_assoc],\n  refine (lt_mul_iff_one_lt_left (pow_pos (lt_trans (by norm_num) h1x) _)).2 _,\n  rw \u2190 one_mul (1 : \u03b1),\n  refine mul_lt_mul' (one_le_pow_of_one_le (le_of_lt h1x) _) h1x (by norm_num)\n    (pow_pos (lt_trans (by norm_num) h1x) _)\nend\n\nlemma pow_dcrs_of_lt_one_of_pos {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1] {x : \u03b1} {n m : \u2115}\n  (hx1 : x < 1) (h0x : 0 < x) (hnm : n < m) : x ^ m < x ^ n :=\nbegin\n  refine (inv_lt_inv _ _).1 _,\n  { exact pow_pos h0x _ },\n  { exact pow_pos h0x _ },\n  { rw [pow_inv', pow_inv'],\n    refine pow_incrs_of_gt_one (one_lt_inv h0x hx1) hnm }\nend\n\nopen finset\n\nlemma geo_series_eq {\u03b1 : Type*} [field \u03b1] {x : \u03b1} (n : \u2115) (hx1 : x \u2260 1) :\n  (range n).sum (\u03bb m, x ^ m) = (1 - x ^ n) / (1 - x) :=\nhave 1 - x \u2260 0 := mt sub_eq_zero_iff_eq.1 hx1.symm,\nbegin\n  induction n with n ih,\n  { simp },\n  { rw [sum_range_succ, \u2190 mul_div_cancel (x ^ n) this, ih, \u2190 add_div, _root_.pow_succ],\n    refine congr_fun (congr_arg _ _) _,\n    ring }\nend\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n  [discrete_linear_ordered_field \u03b1] [archimedean \u03b1] {abv : \u03b2 \u2192 \u03b1}\n\nlemma forall_ge_le_of_forall_le_succ {\u03b1 : Type*} [preorder \u03b1] (f : \u2115 \u2192 \u03b1) {m : \u2115}\n  (h : \u2200 n \u2265 m, f (succ n) \u2264 f n) : \u2200 l, \u2200 k \u2265 m, k \u2264 l \u2192 f l \u2264 f k :=\nbegin\n  assume l k hkm hkl,\n  generalize hp : l - k = p,\n  have : l = k + p := add_comm p k \u25b8 (nat.sub_eq_iff_eq_add hkl).1 hp,\n  subst this,\n  clear hkl hp,\n  induction p with p ih,\n  { simp },\n  { exact le_trans (h _ (le_trans hkm (nat.le_add_right _ _))) ih }\nend\n\nlemma is_cau_of_dcrs_bounded {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1]\n  [archimedean \u03b1] (f : \u2115 \u2192 \u03b1)\n  {a : \u03b1} {m : \u2115} (ham : \u2200 n \u2265 m, abs (f n) \u2264 a)\n  (hnm : \u2200 n \u2265 m, f (succ n) \u2264 f n) : is_cau_seq abs f :=\n\u03bb \u03b5 \u03b50,\nlet \u27e8k, hk\u27e9 := archimedean.arch a \u03b50 in\nhave h : \u2203 l, \u2200 n \u2265 m, a - add_monoid.smul l \u03b5 < f n :=\n  \u27e8k + k + 1, \u03bb n hnm, lt_of_lt_of_le\n    (show a - add_monoid.smul (k + (k + 1)) \u03b5 < -abs (f n),\n      from lt_neg.1 $ lt_of_le_of_lt (ham n hnm) (begin\n        rw [neg_sub, lt_sub_iff_add_lt, add_monoid.add_smul],\n        exact add_lt_add_of_le_of_lt hk (lt_of_le_of_lt hk\n          (lt_add_of_pos_left _ \u03b50)),\n      end))\n    (neg_le.2 $ (abs_neg (f n)) \u25b8 le_abs_self _)\u27e9,\nlet l := nat.find h in\nhave hl : \u2200 (n : \u2115), n \u2265 m \u2192 f n > a - add_monoid.smul l \u03b5 := nat.find_spec h,\nhave hl0 : l \u2260 0 := \u03bb hl0, not_lt_of_ge (ham m (le_refl _))\n  (lt_of_lt_of_le (by have := hl m (le_refl m); simpa [hl0] using this) (le_abs_self (f m))),\nbegin\n  cases classical.not_forall.1\n    (nat.find_min h (pred_lt hl0)) with i hi,\n  rw [not_imp, not_lt] at hi,\n  existsi i,\n  assume j hj,\n  have hfij : f j \u2264 f i := forall_ge_le_of_forall_le_succ f hnm _ _ hi.1 hj,\n  rw [abs_of_nonpos (sub_nonpos.2 hfij), neg_sub, sub_lt_iff_lt_add'],\n  exact calc f i \u2264 a - add_monoid.smul (pred l) \u03b5 : hi.2\n    ... = a - add_monoid.smul l \u03b5 + \u03b5 :\n      by conv {to_rhs, rw [\u2190 succ_pred_eq_of_pos (nat.pos_of_ne_zero hl0), succ_smul',\n        sub_add, add_sub_cancel] }\n    ... < f j + \u03b5 : add_lt_add_right (hl j (le_trans hi.1 hj)) _\nend\n\nlemma is_cau_of_incrs_bounded {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1]\n  [archimedean \u03b1] (f : \u2115 \u2192 \u03b1)\n  {a : \u03b1} {m : \u2115} (ham : \u2200 n \u2265 m, abs (f n) \u2264 a)\n  (hnm : \u2200 n \u2265 m, f n \u2264 f (succ n)) : is_cau_seq abs f :=\nbegin\n  refine @eq.rec_on (\u2115 \u2192 \u03b1) _ (is_cau_seq abs) _ _\n    (-\u27e8_, @is_cau_of_dcrs_bounded _ _ _ (\u03bb n, -f n) a m (by simpa) (by simpa)\u27e9 : cau_seq \u03b1 abs).2,\n  ext,\n  exact neg_neg _\nend\n\nlemma series_cau_of_abv_le_cau {\u03b1 : Type*} {\u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2] {f : \u2115 \u2192 \u03b2}\n    {g : \u2115 \u2192 \u03b1} {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv] (n : \u2115) : (\u2200 m, n \u2264 m \u2192 abv (f m) \u2264 g m) \u2192\n    is_cau_seq abs (\u03bb n, (range n).sum g) \u2192 is_cau_seq abv (\u03bb n, (range n).sum f) := begin\n  assume hm hg \u03b5 \u03b50,cases hg (\u03b5 / 2) (div_pos \u03b50 (by norm_num)) with i hi,\n  existsi max n i,\n  assume j ji,\n  have hi\u2081 := hi j (le_trans (le_max_right n i) ji),\n  have hi\u2082 := hi (max n i) (le_max_right n i),\n  have sub_le := abs_sub_le ((range j).sum g) ((range i).sum g) ((range (max n i)).sum g),\n  have := add_lt_add hi\u2081 hi\u2082,\n  rw abs_sub ((range (max n i)).sum g) at this,\n  rw add_halves \u03b5 at this,\n  refine lt_of_le_of_lt (le_trans (le_trans _ (le_abs_self _)) sub_le) this,\n  generalize hk : j - max n i = k,clear this hi\u2082 hi\u2081 hi \u03b50 \u03b5 hg sub_le,\n  rw nat.sub_eq_iff_eq_add ji at hk,rw hk, clear hk ji j,\n  induction k with k' hi,\n  { simp [abv_zero abv] },\n  { dsimp at *,\n    rw [succ_add, sum_range_succ, sum_range_succ, add_assoc, add_assoc],\n    refine le_trans (abv_add _ _ _) _,\n    exact add_le_add (hm _ (le_add_of_nonneg_of_le (nat.zero_le _) (le_max_left _ _))) hi },\nend\n\nlemma pow_abv {\u03b1 \u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [domain \u03b2] (abv : \u03b2 \u2192 \u03b1) [is_absolute_value abv]\n  (a : \u03b2) (n : \u2115) : abv (a ^ n) = abv a ^ n :=\nby induction n; simp [abv_mul abv, _root_.pow_succ, abv_one abv, *]\n\nlemma series_cau_of_abv_cau {\u03b1 : Type*} {\u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2] {abv : \u03b2 \u2192 \u03b1} {f : \u2115 \u2192 \u03b2}\n    [is_absolute_value abv] : is_cau_seq abs (\u03bb m, (range m).sum (\u03bb n, abv (f n))) \u2192 is_cau_seq abv (\u03bb m, (range m).sum f) :=\n   \u03bb h, series_cau_of_abv_le_cau 0 (\u03bb n h, le_refl _) h\n\nlemma geo_series_cau {\u03b1 \u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [archimedean \u03b1] [field \u03b2]\n  {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv]\n   (x : \u03b2) (hx1 : abv x < 1) : is_cau_seq abv (\u03bb n, (range n).sum (\u03bb m, x ^ m)) :=\nhave hx1' : abv x \u2260 1 := \u03bb h, by simpa [h, lt_irrefl] using hx1,\nseries_cau_of_abv_cau\nbegin\n  simp only [pow_abv abv, geo_series_eq _ hx1'] {eta := ff},\n  refine @is_cau_of_incrs_bounded _ _ _ _ ((1 : \u03b1) / (1 - abv x)) 0 _ _,\n  { assume n hn,\n    rw abs_of_nonneg ,\n    refine div_le_div_of_le_of_pos (sub_le_self _ (pow_abv abv x n \u25b8 abv_nonneg _ _))\n      (sub_pos.2 hx1),\n    refine div_nonneg (sub_nonneg.2 _) (sub_pos.2 hx1),\n    clear hn,\n    induction n with n ih,\n    { simp },\n    { rw [_root_.pow_succ, \u2190 one_mul (1 : \u03b1)],\n      refine mul_le_mul (le_of_lt hx1) ih (pow_abv abv x n \u25b8 abv_nonneg _ _) (by norm_num) } },\n  { assume n hn,\n    refine div_le_div_of_le_of_pos (sub_le_sub_left _ _) (sub_pos.2 hx1),\n    rw [\u2190 one_mul (_ ^ n), _root_.pow_succ],\n    exact mul_le_mul_of_nonneg_right (le_of_lt hx1) (pow_nonneg (abv_nonneg _ _) _) }\nend\n\nlemma geo_series_const_cau {\u03b1 : Type*} [discrete_linear_ordered_field \u03b1] [archimedean \u03b1] (a x : \u03b1) :\n  abs x < 1 \u2192 is_cau_seq abs (\u03bb m, (range m).sum (\u03bb n, a * x ^ n)) :=\n\u03bb hx1, begin\n  have : is_cau_seq abs (\u03bb m, a * (range m).sum (\u03bb n, x ^ n)) := (cau_seq.const abs a * \u27e8_, geo_series_cau x hx1\u27e9).2,\n  simpa only [mul_sum] using this\nend\n\n-- The form of ratio test with  0 \u2264 r < 1, and abv (f (succ m)) \u2264 r * abv (f m) handled zero terms of series the best\nlemma series_ratio_test {\u03b1 : Type*} {\u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2]\n    [archimedean \u03b1] {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv] {f : \u2115 \u2192 \u03b2} (n : \u2115) (r : \u03b1) :\n    0 \u2264 r \u2192 r < 1 \u2192 (\u2200 m, n \u2264 m \u2192 abv (f (succ m)) \u2264 r * abv (f m)) \u2192 is_cau_seq abv (\u03bb m, (range m).sum f)\n  := begin\n  assume r0 r1 h,\n  refine series_cau_of_abv_le_cau (succ n) _ (geo_series_const_cau (abv (f (succ n)) * r\u207b\u00b9 ^ (succ n)) r _),\n  assume m mn,\n  generalize hk : m - (succ n) = k,rw nat.sub_eq_iff_eq_add mn at hk,\n  cases classical.em (r = 0) with r_zero r_pos,have m_pos := lt_of_lt_of_le (succ_pos n) mn,\n  have := pred_le_pred mn,simp at this,\n  have := h (pred m) this,simp[r_zero,succ_pred_eq_of_pos m_pos] at this,\n  refine le_trans this _,refine mul_nonneg _ _,\n  refine mul_nonneg (abv_nonneg _ _) (pow_nonneg (inv_nonneg.mpr r0) _),exact pow_nonneg r0 _,\n  replace r_pos : 0 < r,cases lt_or_eq_of_le r0 with h h,exact h,exact absurd h.symm r_pos,\n  revert m n,\n  induction k with k' hi,assume m n h mn hk,\n  rw [hk,zero_add,mul_right_comm,\u2190pow_inv',\u2190div_eq_mul_inv,mul_div_cancel],\n  exact (ne_of_lt (pow_pos r_pos _)).symm,\n  assume m n h mn hk,rw [hk,succ_add],\n  have kn : k' + (succ n) \u2265 (succ n), rw \u2190zero_add (succ n),refine add_le_add _ _,exact zero_le _,simp,\n  replace hi := hi (k' + (succ n)) n h kn rfl,\n  rw [(by simp [_root_.pow_succ'] : r ^ (succ (k' + succ n)) = r ^ (k' + succ n) * r),\u2190mul_assoc],\n  replace h := h (k' + succ n) (le_of_succ_le kn),rw mul_comm at h,\n  exact le_trans h (mul_le_mul_of_nonneg_right hi r0),\n  rwa abs_of_nonneg r0,\nend\n\nlemma sum_range_diag_flip {\u03b1 : Type*} [add_comm_monoid \u03b1] (n : \u2115) (f : \u2115 \u2192 \u2115 \u2192 \u03b1) :\n    (range n).sum (\u03bb m, (range (m + 1)).sum (\u03bb k, f k (m - k))) =\n    (range n).sum (\u03bb m, (range (n - m)).sum (f m)) :=\nhave h\u2081 : ((range n).sigma (range \u2218 succ)).sum\n    (\u03bb (a : \u03a3 m, \u2115), f (a.2) (a.1 - a.2)) =\n    (range n).sum (\u03bb m, (range (m + 1)).sum\n    (\u03bb k, f k (m - k))) := sum_sigma,\nhave h\u2082 : ((range n).sigma (\u03bb m, range (n - m))).sum (\u03bb a : \u03a3 (m : \u2115), \u2115, f (a.1) (a.2)) =\n    (range n).sum (\u03bb m, sum (range (n - m)) (f m)) := sum_sigma,\nh\u2081 \u25b8 h\u2082 \u25b8 sum_bij\n(\u03bb a _, \u27e8a.2, a.1 - a.2\u27e9)\n(\u03bb a ha, have h\u2081 : a.1 < n := mem_range.1 (mem_sigma.1 ha).1,\n  have h\u2082 : a.2 < succ a.1 := mem_range.1 (mem_sigma.1 ha).2,\n    mem_sigma.2 \u27e8mem_range.2 (lt_of_lt_of_le h\u2082 h\u2081),\n    mem_range.2 ((nat.sub_lt_sub_right_iff (le_of_lt_succ h\u2082)).2 h\u2081)\u27e9)\n(\u03bb _ _, rfl)\n(\u03bb \u27e8a\u2081, a\u2082\u27e9 \u27e8b\u2081, b\u2082\u27e9 ha hb h,\n  have ha : a\u2081 < n \u2227 a\u2082 \u2264 a\u2081 :=\n      \u27e8mem_range.1 (mem_sigma.1 ha).1, le_of_lt_succ (mem_range.1 (mem_sigma.1 ha).2)\u27e9,\n  have hb : b\u2081 < n \u2227 b\u2082 \u2264 b\u2081 :=\n      \u27e8mem_range.1 (mem_sigma.1 hb).1, le_of_lt_succ (mem_range.1 (mem_sigma.1 hb).2)\u27e9,\n  have h : a\u2082 = b\u2082 \u2227 _ := sigma.mk.inj h,\n  have h' : a\u2081 = b\u2081 - b\u2082 + a\u2082 := (nat.sub_eq_iff_eq_add ha.2).1 (eq_of_heq h.2),\n  sigma.mk.inj_iff.2\n    \u27e8nat.sub_add_cancel hb.2 \u25b8 h'.symm \u25b8 h.1 \u25b8 rfl,\n    (heq_of_eq h.1)\u27e9)\n(\u03bb \u27e8a\u2081, a\u2082\u27e9 ha,\n  have ha : a\u2081 < n \u2227 a\u2082 < n - a\u2081 :=\n      \u27e8mem_range.1 (mem_sigma.1 ha).1, (mem_range.1 (mem_sigma.1 ha).2)\u27e9,\n  \u27e8\u27e8a\u2082 + a\u2081, a\u2081\u27e9, \u27e8mem_sigma.2 \u27e8mem_range.2 ((nat.lt_sub_right_iff_add_lt\n      (le_of_lt ha.1)).1 ha.2),\n    mem_range.2 (lt_succ_of_le (le_add_left _ _))\u27e9,\n  sigma.mk.inj_iff.2 \u27e8rfl, heq_of_eq (nat.add_sub_cancel _ _).symm\u27e9\u27e9\u27e9)\n\nlemma abv_sum_le_sum_abv {\u03b1 \u03b2 \u03b3 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2]\n  (abv : \u03b2 \u2192 \u03b1) [is_absolute_value abv] (f : \u03b3 \u2192 \u03b2) (s : finset \u03b3) : abv (s.sum f) \u2264 s.sum (abv \u2218 f) :=\nfinset.induction_on s (by simp [abv_zero abv]) $ \u03bb a s has ih,\nby rw [sum_insert has, sum_insert has];\n  exact le_trans (abv_add abv _ _) (add_le_add_left ih _)\n\nlemma sum_nonneg {\u03b1 \u03b2 : Type*} [ordered_comm_monoid \u03b1] {f : \u03b2 \u2192 \u03b1} {s : finset \u03b2} :\n  (\u2200 x \u2208 s, 0 \u2264 f x) \u2192 0 \u2264 s.sum f :=\nfinset.induction_on s (by simp) $ \u03bb a s has ih h, begin\n  rw [sum_insert has],\n  exact add_nonneg' (h a (by simp)) (ih (\u03bbx hx, by simp *)),\nend\n\nlemma neg_sum {\u03b1 \u03b2 : Type*} [add_comm_group \u03b1] {f : \u03b2 \u2192 \u03b1} {s : finset \u03b2} :\n  -s.sum f = s.sum (\u03bb x, -f x) :=\nfinset.induction_on s (by simp) (by simp {contextual := tt})\n\n@[simp] lemma filter_true {\u03b1 : Type*} (s : finset \u03b1) : s.filter (\u03bb _, true) = s :=\nfinset.ext.2 $ by simp\n\nlemma sum_range_sub_sum_range {\u03b1 : Type*} [add_comm_group \u03b1] {f : \u2115 \u2192 \u03b1}\n  {n m : \u2115} (hnm : n \u2264 m) : (range m).sum f - (range n).sum f =\n  ((range m).filter (\u03bb k, n \u2264 k)).sum f :=\nbegin\n  rw [\u2190 sum_sdiff (@filter_subset _ (\u03bb k, n \u2264 k) _ (range m)),\n    sub_eq_iff_eq_add, \u2190 eq_sub_iff_add_eq, add_sub_cancel'],\n  refine finset.sum_congr\n    (finset.ext.2 $ \u03bb a, \u27e8\u03bb h, by simp at *; finish,\n    \u03bb h, have ham : a < m := lt_of_lt_of_le (mem_range.1 h) hnm,\n      by simp * at *\u27e9)\n    (\u03bb _ _, rfl),\nend\n\nlemma series_cauchy_prod {\u03b1 \u03b2 : Type*} [discrete_linear_ordered_field \u03b1] [ring \u03b2] {a b : \u2115 \u2192 \u03b2}\n  {abv : \u03b2 \u2192 \u03b1} [is_absolute_value abv] : is_cau_seq abs (\u03bb m, (range m).sum (\u03bb n, abv (a n))) \u2192 is_cau_seq abv (\u03bb m, (range m).sum b) \u2192\n  \u2200 \u03b5 : \u03b1, 0 < \u03b5 \u2192 \u2203 i : \u2115, \u2200 j \u2265 i, abv ((range j).sum a * (range j).sum b - (range j).sum (\u03bb n,\n  (range (n + 1)).sum (\u03bb m, a m * b (n - m))) ) < \u03b5 :=\nbegin\n-- slightly adapted version of theorem 9.4.7 from \"The Real Numbers and Real Analysis\", Ethan D. Bloch\n  assume ha hb \u03b5 \u03b50,\n  cases cau_seq.bounded \u27e8_, hb\u27e9 with Q hQ,simp at hQ,\n  cases cau_seq.bounded \u27e8_, ha\u27e9 with P hP,simp at hP,\n  have P0 : 0 < P,exact lt_of_le_of_lt (abs_nonneg _) (hP 0),\n  have P\u03b50 := div_pos \u03b50 (mul_pos (show (2 : \u03b1) > 0, from by norm_num) P0),\n  cases cau_seq.cauchy\u2082 \u27e8_, hb\u27e9 P\u03b50 with N hN,simp at hN,\n  have Q\u03b50 := div_pos \u03b50 (mul_pos (show (4 : \u03b1) > 0, from by norm_num) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))),\n  cases cau_seq.cauchy\u2082 \u27e8_, ha\u27e9 Q\u03b50 with M hM,simp at hM,\n  existsi 2 * (max N M + 1),\n  assume K hK,\n  have := sum_range_diag_flip K (\u03bb m n, a m * b n),\n  dsimp at this,\n  rw this,\n  have : (\u03bb (i : \u2115), (range (K - i)).sum (\u03bb (k : \u2115), a i * b k)) = (\u03bb (i : \u2115), a i * (range (K - i)).sum b),\n    by simp [finset.mul_sum],\n  rw this,clear this,\n  have : (range K).sum (\u03bb (i : \u2115), a i * (range (K - i)).sum b) =\n    (range K).sum (\u03bb (i : \u2115), a i * ((range (K - i)).sum b - (range K).sum b))\n    + (range K).sum (\u03bb i, a i * (range K).sum b),\n    {rw \u2190sum_add_distrib,simp[(mul_add _ _ _).symm]},\n  rw this, clear this,\n  rw sum_mul, simp,\n  rw abv_neg abv,\n  refine lt_of_le_of_lt (abv_sum_le_sum_abv _ _ _) _,\n  simp [abv_mul abv],\n  suffices : (range (max N M + 1)).sum (\u03bb (i : \u2115), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) +\n    ((range K).sum (\u03bb (i : \u2115), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) -(range (max N M + 1)).sum\n     (\u03bb (i : \u2115),\n    abv (a i) * abv ((range (K - i)).sum b - (range K).sum b))) < \u03b5 / (2 * P) * P + \u03b5 / (4 * Q) * (2 * Q),\n  { simp [(div_div_eq_div_mul _ _ _).symm] at this,\n    rwa[div_mul_cancel _ (ne_of_lt P0).symm,(by norm_num : (4 : \u03b1) = 2 * 2),\u2190div_div_eq_div_mul,mul_comm (2 : \u03b1),\u2190_root_.mul_assoc,\n    div_mul_cancel _ (ne_of_lt (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))).symm,div_mul_cancel,add_halves] at this,\n    norm_num},\n  refine add_lt_add _ _,\n  {have : (range (max N M + 1)).sum (\u03bb (i : \u2115), abv (a i) *\n    abv ((range (K - i)).sum b - (range K).sum b)) \u2264 (range (max N M + 1)).sum\n  (\u03bb (i : \u2115), abv (a i) * (\u03b5 / (2 * P))) := by\n    {refine sum_le_sum _,assume m mJ,refine mul_le_mul_of_nonneg_left _ _,\n      {refine le_of_lt (hN (K - m) K _ _),{\n      refine nat.le_sub_left_of_add_le (le_trans _ hK),\n      rw[succ_mul,_root_.one_mul],\n      exact add_le_add (le_of_lt (mem_range.1 mJ)) (le_trans (le_max_left _ _) (le_of_lt (lt_add_one _)))},\n      {refine le_trans _ hK,rw \u2190_root_.one_mul N,\n      refine mul_le_mul (by norm_num) (by rw _root_.one_mul;exact le_trans (le_max_left _ _)\n      (le_of_lt (lt_add_one _))) (zero_le _) (zero_le _)}},\n      exact abv_nonneg abv _},\n  refine lt_of_le_of_lt this _,\n  rw [\u2190 sum_mul, mul_comm],\n  specialize hP (max N M + 1),rwa abs_of_nonneg at hP,\n  exact (mul_lt_mul_left P\u03b50).mpr hP,\n  exact sum_nonneg (\u03bb x h, abv_nonneg abv _)},\n  {have hNMK : max N M + 1 < K := by\n    {refine lt_of_lt_of_le _ hK,\n    rw [succ_mul,_root_.one_mul,\u2190add_zero (max N M + 1)],\n    refine add_lt_add_of_le_of_lt (le_refl _) _,rw add_zero,\n    refine add_pos_of_nonneg_of_pos (zero_le _) (by norm_num)},\n  rw sum_range_sub_sum_range (le_of_lt hNMK),\n  exact calc sum (filter (\u03bb (k : \u2115), max N M + 1 \u2264 k) (range K))\n      (\u03bb (i : \u2115), abv (a i) * abv (sum (range (K - i)) b - sum (range K) b))\n      \u2264 sum (filter (\u03bb (k : \u2115), max N M + 1 \u2264 k) (range K)) (\u03bb i, abv (a i) * (2 * Q)) :\n    sum_le_sum (begin\n      assume n hn,\n      refine mul_le_mul_of_nonneg_left _ (abv_nonneg _ _),\n      rw sub_eq_add_neg,\n      refine le_trans (abv_add _ _ _) _,\n      rw [two_mul, abv_neg abv],\n      refine add_le_add (le_of_lt (hQ _)) (le_of_lt (hQ _)),\n    end)\n    ... < _ : begin\n      rw [\u2190 sum_mul, \u2190 sum_range_sub_sum_range (le_of_lt hNMK)],\n      refine (mul_lt_mul_right _).2 _,\n      rw two_mul,\n      refine add_pos (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))\n        (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0)),\n      refine lt_of_le_of_lt (le_abs_self _) _,\n      refine hM _ _ (le_trans (le_succ_of_le (le_max_right _ _)) (le_of_lt hNMK))\n        (le_succ_of_le (le_max_right _ _))\n     end }\nend\n\nend a\n\nopen nat finset\nlemma complex.exp_series_abs_cau (z : \u2102) : is_cau_seq abs (\u03bb n, (range n).sum (\u03bb m, complex.abs (z ^ m / fact m))) := begin\n  cases exists_nat_gt (complex.abs z) with n hn,\n  have n_pos : (0 : \u211d) < n := lt_of_le_of_lt (complex.abs_nonneg _) hn,\n  refine series_ratio_test n (complex.abs z / n) _ _ _,exact div_nonneg_of_nonneg_of_pos (complex.abs_nonneg _) n_pos,rwa [div_lt_iff n_pos,one_mul],\n  assume m mn,rw [abs_of_nonneg (complex.abs_nonneg _),abs_of_nonneg (complex.abs_nonneg _)],\n  unfold fact,simp only [_root_.pow_succ, complex.abs_div,complex.abs_mul,div_eq_mul_inv,mul_inv',\n    nat.cast_mul,complex.abs_inv],\n  have : complex.abs z * complex.abs (z ^ m) * ((complex.abs \u2191(fact m))\u207b\u00b9 * (complex.abs \u2191(succ m))\u207b\u00b9) = complex.abs z *\n    complex.abs (z ^ m) * (complex.abs \u2191(fact m))\u207b\u00b9 * (complex.abs \u2191(succ m))\u207b\u00b9,ring,rw this,\n  have : complex.abs z * (\u2191n)\u207b\u00b9 * (complex.abs (z ^ m) * (complex.abs \u2191(fact m))\u207b\u00b9) = complex.abs z * complex.abs (z ^ m) * (complex.abs \u2191(fact m))\u207b\u00b9 * (\u2191n)\u207b\u00b9,ring,\n  rw this,\n  rw[(by simp : (succ m : \u2102) = ((succ m : \u211d) : \u2102)),complex.abs_of_nonneg],\n  refine mul_le_mul_of_nonneg_left _ _,\n  rw [inv_le_inv,nat.cast_le],exact le_succ_of_le mn,\n  rw [\u2190nat.cast_zero,nat.cast_lt],exact succ_pos _,exact n_pos,rw[\u2190complex.abs_inv,\u2190complex.abs_mul,\u2190complex.abs_mul],\n  exact complex.abs_nonneg _,rw[\u2190nat.cast_zero,nat.cast_le],exact zero_le _,\nend\n\nlemma complex.exp_series_cau (z : \u2102) : is_cau_seq complex.abs (\u03bb n, (range n).sum (\u03bb m, z ^ m / fact m)) :=\n  series_cau_of_abv_cau (complex.exp_series_abs_cau z)\n\ndef exp' (z : \u2102) : cau_seq \u2102 complex.abs := \u27e8_, complex.exp_series_cau z\u27e9\n\nopen complex\ndef exp (z : \u2102) : \u2102 := complex.lim (exp' z)\n\ndef sin (z : \u2102) : \u2102 := (exp (I * z) - exp (-I * z)) / (2 * I)\n\ndef cos (z : \u2102) : \u2102 := (exp (I * z) + exp (-I * z)) / 2\n\ndef tan (z : \u2102) : \u2102 := sin z / cos z\n\ndef sinh (z : \u2102) : \u2102 := (exp z - exp (-z)) / 2\n\ndef cosh (z : \u2102) : \u2102 := (exp z + exp (-z)) / 2\n\ndef tanh (z : \u2102) : \u2102 := sinh z / cosh z\n\n@[simp] lemma exp_zero : exp 0 = 1 := begin\n  unfold exp exp',\n  refine lim_eq_of_equiv_const _,\n  assume \u03b5 \u03b50,\n  existsi 1,\n  assume j hj,\n  dsimp [exp'],\n  suffices : complex.abs (sum (range j) (\u03bb (m : \u2115), 0 ^ m / \u2191(fact m)) + -1) = 0,\n    rwa this,\n  cases j,\n  { exact absurd hj (by norm_num) },\n  { induction j,\n    { simpa },\n    { rw \u2190 j_ih dec_trivial,\n      simp only [sum_range_succ, _root_.pow_succ],\n      simp } }\nend\n\nlemma exp_add (x y : \u2102) : exp (x + y) = exp x * exp y :=\nshow complex.lim (\u27e8_, complex.exp_series_cau (x + y)\u27e9 : cau_seq \u2102 abs) =\n  complex.lim (show cau_seq \u2102 abs, from \u27e8_, complex.exp_series_cau x\u27e9)\n  * complex.lim (show cau_seq \u2102 abs, from \u27e8_, complex.exp_series_cau y\u27e9),\nbegin\n have hxa := complex.exp_series_abs_cau x,\n have hx := complex.exp_series_cau x,\n have hy := complex.exp_series_cau y,\n have hxy := complex.exp_series_cau (x + y),\n   rw complex.lim_mul_lim,\n have hj : \u2200 j : \u2115, (range j).sum (\u03bb (m : \u2115),\n    (x + y) ^ m / \u2191(fact m)) = (range j).sum\n    (\u03bb i, (range (i + 1)).sum (\u03bb k, x ^ k / fact k *\n    (y ^ (i - k) / fact (i - k)))),\n    { assume j,\n      refine finset.sum_congr rfl (\u03bb m hm, _),\n      rw [add_pow, div_eq_mul_inv, sum_mul],\n      refine finset.sum_congr rfl (\u03bb i hi, _),\n      have := choose_mul_fact_mul_fact (le_of_lt_succ $ finset.mem_range.1 hi),\n      rw [\u2190 this, nat.cast_mul, nat.cast_mul, mul_inv', mul_inv'],\n      simp only [mul_left_comm (choose m i : \u2102), mul_assoc, mul_left_comm (choose m i : \u2102)\u207b\u00b9,\n        mul_comm (choose m i : \u2102)],\n      have : (choose m i : \u2102) \u2260 0 := nat.cast_ne_zero.2 (\u03bb h,\n        by have := choose_pos (le_of_lt_succ (mem_range.1 hi)); simpa [h, lt_irrefl] using this),\n      rw inv_mul_cancel this,\n      simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] },\n  have hf := funext hj, have hxy1 := hxy, rw hf at hxy1,\n  have := series_cauchy_prod hxa hy,\n  refine eq.symm (lim_eq_lim_of_equiv _),\n  assume \u03b5 \u03b50,\n  dsimp,\n  simp only [hj],\n  exact this \u03b5 \u03b50,\nend\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/exp/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7033930040081832}}
{"text": "/-\nCopyright (c) 2022 Jake Levinson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jake Levinson\n\n! This file was ported from Lean 3 source module combinatorics.young.semistandard_tableau\n! leanprover-community/mathlib commit 50832daea47b195a48b5b33b1c8b2162c48c3afc\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Combinatorics.Young.YoungDiagram\n\n/-!\n# Semistandard Young tableaux\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA semistandard Young tableau is a filling of a Young diagram by natural numbers, such that\nthe entries are weakly increasing left-to-right along rows (i.e. for fixed `i`), and\nstrictly-increasing top-to-bottom along columns (i.e. for fixed `j`).\n\nAn example of an SSYT of shape `\u03bc = [4, 2, 1]` is:\n\n```text\n0 0 0 2\n1 1\n2\n```\n\nWe represent an SSYT as a function `\u2115 \u2192 \u2115 \u2192 \u2115`, which is required to be zero for all pairs\n`(i, j) \u2209 \u03bc` and to satisfy the row-weak and column-strict conditions on `\u03bc`.\n\n\n## Main definitions\n\n- `ssyt (\u03bc : young_diagram)` : semistandard Young tableaux of shape `\u03bc`. There is\n  a `has_coe_to_fun` instance such that `T i j` is value of the `(i, j)` entry of the SSYT `T`.\n- `ssyt.highest_weight (\u03bc : young_diagram)`: the semistandard Young tableau whose `i`th row\n  consists entirely of `i`s, for each `i`.\n\n## Tags\n\nSemistandard Young tableau\n\n## References\n\n<https://en.wikipedia.org/wiki/Young_tableau>\n\n-/\n\n\n#print Ssyt /-\n/-- A semistandard Young tableau (SSYT) is a filling of the cells of a Young diagram by natural\nnumbers, such that the entries in each row are weakly increasing (left to right), and the entries\nin each column are strictly increasing (top to bottom).\n\nHere, an SSYT is represented as an unrestricted function `\u2115 \u2192 \u2115 \u2192 \u2115` that, for reasons\nof extensionality, is required to vanish outside `\u03bc`. -/\nstructure Ssyt (\u03bc : YoungDiagram) where\n  entry : \u2115 \u2192 \u2115 \u2192 \u2115\n  row_weak' : \u2200 {i j1 j2 : \u2115}, j1 < j2 \u2192 (i, j2) \u2208 \u03bc \u2192 entry i j1 \u2264 entry i j2\n  col_strict' : \u2200 {i1 i2 j : \u2115}, i1 < i2 \u2192 (i2, j) \u2208 \u03bc \u2192 entry i1 j < entry i2 j\n  zeros' : \u2200 {i j}, (i, j) \u2209 \u03bc \u2192 entry i j = 0\n#align ssyt Ssyt\n-/\n\nnamespace Ssyt\n\n#print Ssyt.funLike /-\ninstance funLike {\u03bc : YoungDiagram} : FunLike (Ssyt \u03bc) \u2115 fun _ => \u2115 \u2192 \u2115\n    where\n  coe := Ssyt.entry\n  coe_injective' T T' h := by\n    cases T\n    cases T'\n    congr\n#align ssyt.fun_like Ssyt.funLike\n-/\n\n/-- Helper instance for when there's too many metavariables to apply\n`fun_like.has_coe_to_fun` directly. -/\ninstance {\u03bc : YoungDiagram} : CoeFun (Ssyt \u03bc) fun _ => \u2115 \u2192 \u2115 \u2192 \u2115 :=\n  FunLike.hasCoeToFun\n\n#print Ssyt.to_fun_eq_coe /-\n@[simp]\ntheorem to_fun_eq_coe {\u03bc : YoungDiagram} {T : Ssyt \u03bc} : T.entry = (T : \u2115 \u2192 \u2115 \u2192 \u2115) :=\n  rfl\n#align ssyt.to_fun_eq_coe Ssyt.to_fun_eq_coe\n-/\n\n#print Ssyt.ext /-\n@[ext]\ntheorem ext {\u03bc : YoungDiagram} {T T' : Ssyt \u03bc} (h : \u2200 i j, T i j = T' i j) : T = T' :=\n  FunLike.ext T T' fun x => by\n    funext\n    apply h\n#align ssyt.ext Ssyt.ext\n-/\n\n#print Ssyt.copy /-\n/-- Copy of an `ssyt \u03bc` with a new `entry` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy {\u03bc : YoungDiagram} (T : Ssyt \u03bc) (entry' : \u2115 \u2192 \u2115 \u2192 \u2115) (h : entry' = T) : Ssyt \u03bc\n    where\n  entry := entry'\n  row_weak' _ _ _ := h.symm \u25b8 T.row_weak'\n  col_strict' _ _ _ := h.symm \u25b8 T.col_strict'\n  zeros' _ _ := h.symm \u25b8 T.zeros'\n#align ssyt.copy Ssyt.copy\n-/\n\n#print Ssyt.coe_copy /-\n@[simp]\ntheorem coe_copy {\u03bc : YoungDiagram} (T : Ssyt \u03bc) (entry' : \u2115 \u2192 \u2115 \u2192 \u2115) (h : entry' = T) :\n    \u21d1(T.copy entry' h) = entry' :=\n  rfl\n#align ssyt.coe_copy Ssyt.coe_copy\n-/\n\n#print Ssyt.copy_eq /-\ntheorem copy_eq {\u03bc : YoungDiagram} (T : Ssyt \u03bc) (entry' : \u2115 \u2192 \u2115 \u2192 \u2115) (h : entry' = T) :\n    T.copy entry' h = T :=\n  FunLike.ext' h\n#align ssyt.copy_eq Ssyt.copy_eq\n-/\n\n#print Ssyt.row_weak /-\ntheorem row_weak {\u03bc : YoungDiagram} (T : Ssyt \u03bc) {i j1 j2 : \u2115} (hj : j1 < j2)\n    (hcell : (i, j2) \u2208 \u03bc) : T i j1 \u2264 T i j2 :=\n  T.row_weak' hj hcell\n#align ssyt.row_weak Ssyt.row_weak\n-/\n\n#print Ssyt.col_strict /-\ntheorem col_strict {\u03bc : YoungDiagram} (T : Ssyt \u03bc) {i1 i2 j : \u2115} (hi : i1 < i2)\n    (hcell : (i2, j) \u2208 \u03bc) : T i1 j < T i2 j :=\n  T.col_strict' hi hcell\n#align ssyt.col_strict Ssyt.col_strict\n-/\n\n#print Ssyt.zeros /-\ntheorem zeros {\u03bc : YoungDiagram} (T : Ssyt \u03bc) {i j : \u2115} (not_cell : (i, j) \u2209 \u03bc) : T i j = 0 :=\n  T.zeros' not_cell\n#align ssyt.zeros Ssyt.zeros\n-/\n\n#print Ssyt.row_weak_of_le /-\ntheorem row_weak_of_le {\u03bc : YoungDiagram} (T : Ssyt \u03bc) {i j1 j2 : \u2115} (hj : j1 \u2264 j2)\n    (cell : (i, j2) \u2208 \u03bc) : T i j1 \u2264 T i j2 :=\n  by\n  cases eq_or_lt_of_le hj\n  subst h\n  exact T.row_weak h cell\n#align ssyt.row_weak_of_le Ssyt.row_weak_of_le\n-/\n\n#print Ssyt.col_weak /-\ntheorem col_weak {\u03bc : YoungDiagram} (T : Ssyt \u03bc) {i1 i2 j : \u2115} (hi : i1 \u2264 i2) (cell : (i2, j) \u2208 \u03bc) :\n    T i1 j \u2264 T i2 j := by\n  cases eq_or_lt_of_le hi\n  subst h\n  exact le_of_lt (T.col_strict h cell)\n#align ssyt.col_weak Ssyt.col_weak\n-/\n\n#print Ssyt.highestWeight /-\n/-- The \"highest weight\" SSYT of a given shape is has all i's in row i, for each i. -/\ndef highestWeight (\u03bc : YoungDiagram) : Ssyt \u03bc\n    where\n  entry i j := if (i, j) \u2208 \u03bc then i else 0\n  row_weak' i j1 j2 hj hcell := by\n    rw [if_pos hcell, if_pos (\u03bc.up_left_mem (by rfl) (le_of_lt hj) hcell)]\n  col_strict' i1 i2 j hi hcell := by\n    rwa [if_pos hcell, if_pos (\u03bc.up_left_mem (le_of_lt hi) (by rfl) hcell)]\n  zeros' i j not_cell := if_neg not_cell\n#align ssyt.highest_weight Ssyt.highestWeight\n-/\n\n#print Ssyt.highestWeight_apply /-\n@[simp]\ntheorem highestWeight_apply {\u03bc : YoungDiagram} {i j : \u2115} :\n    highestWeight \u03bc i j = if (i, j) \u2208 \u03bc then i else 0 :=\n  rfl\n#align ssyt.highest_weight_apply Ssyt.highestWeight_apply\n-/\n\ninstance {\u03bc : YoungDiagram} : Inhabited (Ssyt \u03bc) :=\n  \u27e8Ssyt.highestWeight \u03bc\u27e9\n\nend Ssyt\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Combinatorics/Young/SemistandardTableau.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7033930037191117}}
{"text": "namespace prop_14\n\nvariables A B C : Prop\n\ntheorem prop_14 : ((A \u2192 C) \u2228 (B \u2192 C)) \u2192 ((A \u2227 B) \u2192 C) :=\nassume h1: ((A \u2192 C) \u2228 (B \u2192 C)),\nassume h2: A \u2227 B,\nhave h3: A, from and.left h2,\nhave h4: B, from and.right h2,\nshow C, from or.elim h1\n    (assume h5: A \u2192 C,\n     h5 h3)\n    (assume h6: B \u2192 C,\n     h6 h4)\n\n-- end namespace\nend prop_14", "meta": {"author": "tomasz-lisowski", "repo": "lean-logic-examples", "sha": "2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d", "save_path": "github-repos/lean/tomasz-lisowski-lean-logic-examples", "path": "github-repos/lean/tomasz-lisowski-lean-logic-examples/lean-logic-examples-2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d/src/logic_propositional/prop_14.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.7033923310246786}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nThis file contains various addenda to algebra/big_operators.\nOne issue is that I often prefer to work with fintypes and \nsums/products over all of univ, and it is helpful to have some \nlemmas specialised to that situation.\n\n-/\n\nimport algebra.big_operators data.fintype.basic\nimport tactic.squeeze\n\nuniverses u\u03b1 u\u03b2 u\u03b3 u\u03b4\nvariables {\u03b1 : Type u\u03b1} {\u03b2 : Type u\u03b2} {\u03b3 : Type u\u03b3} {\u03b4 : Type u\u03b4}\nvariables [decidable_eq \u03b1] [decidable_eq \u03b2]\nvariables [comm_monoid \u03b3] [add_comm_monoid \u03b4]\n\nnamespace finset\nopen finset \n\nlemma mem_range_succ {i n : \u2115} : i \u2208 range n.succ \u2194 i \u2264 n := \n by {rw[mem_range,nat.lt_succ_iff]}\n\n@[to_additive finset.sum_coe_list]\nlemma prod_coe_list {l : list \u03b1} (h : l.nodup) (f : \u03b1 \u2192 \u03b3) :\n l.to_finset.prod f = (l.map f).prod :=\nbegin\n let s := @finset.mk \u03b1 l h,\n have : s = l.to_finset := (list.to_finset_eq h),\n exact calc \n  l.to_finset.prod f = s.prod f : by rw[\u2190 this]\n  ... = ((l : multiset \u03b1).map f).prod : rfl\n  ... = ((l.map f) : multiset \u03b3).prod : by rw[multiset.coe_map]\n  ... = (l.map f).prod : by rw[multiset.coe_prod], \nend\n\n@[to_additive finset.sum_equiv]\nlemma prod_equiv {s : finset \u03b1} {t : finset \u03b2}\n (e : {a // a \u2208 s} \u2243 {b // b \u2208 t})\n  (f : \u03b1 \u2192 \u03b3) (g : \u03b2 \u2192 \u03b3) \n   (hfg : \u2200 (a : \u03b1) (ha : a \u2208 s), f a = g (e \u27e8a,ha\u27e9).val) :\n    s.prod f = t.prod g := \nprod_bij \n (\u03bb a a_in_s, (e.to_fun \u27e8a,a_in_s\u27e9).val)\n (\u03bb a a_in_s, (e.to_fun \u27e8a,a_in_s\u27e9).property)\n hfg\n (\u03bb a\u2081 a\u2082 a\u2081_in_s a\u2082_in_s h, \n  congr_arg subtype.val (e.injective (subtype.eq h)))\n (\u03bb b b_in_t, let aa := e.inv_fun \u27e8b,b_in_t\u27e9 in \n   exists.intro aa.val \n   begin\n    have ea : aa = \u27e8aa.val,aa.property\u27e9 := subtype.eq rfl,\n    use aa.property,\n    rw[\u2190 ea],\n    exact congr_arg subtype.val (e.right_inv \u27e8b,b_in_t\u27e9).symm,\n   end\n  )\n\n@[to_additive finset.univ_sum_equiv]\nlemma univ_prod_equiv [fintype \u03b1] [fintype \u03b2] (e : \u03b1 \u2243 \u03b2) (g : \u03b2 \u2192 \u03b3) :\n univ.prod (g \u2218 e.to_fun) = univ.prod g := \nprod_bij \n (\u03bb a _,e.to_fun a) (\u03bb a _,mem_univ _) (\u03bb a _, @rfl _ (g (e.to_fun a)))\n (\u03bb a\u2081 a\u2082 _ _ h, e.injective h)\n (\u03bb b _, begin use e.inv_fun b, use mem_univ _, exact (e.right_inv b).symm, end)\n\n@[to_additive finset.sum_eq_univ_sum]\nlemma prod_eq_univ_prod (s : finset \u03b1) (f : \u03b1 \u2192 \u03b3) : \n s.prod f = (@univ {a // a \u2208 s} _).prod (\u03bb a, f a.val) := \nbegin\n have : @univ {a // a \u2208 s} _ = s.attach := rfl,\n rw[\u2190 prod_attach,this],refl\nend\n\n@[to_additive finset.sum_univ_product]\nlemma prod_univ_product [fintype \u03b1] [fintype \u03b2] (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) :\n (@univ (\u03b1 \u00d7 \u03b2) _).prod (\u03bb ab, f ab.1 ab.2) = \n  (@univ \u03b1 _).prod (\u03bb a, (@univ \u03b2 _).prod (f a)) := \nbegin \n have : @univ (\u03b1 \u00d7 \u03b2) _ = (@univ \u03b1 _).product (@univ \u03b2 _) := rfl,\n rw[this,prod_product],\nend\n\n@[to_additive finset.sum_over_bool]\nlemma prod_over_bool (f : bool \u2192 \u03b3) : \n (@univ bool _).prod f = (f ff) * (f tt) := \nbegin\n let l : list bool := [ff,tt],\n let h : l.nodup := dec_trivial,\n have : (@univ bool _) = l.to_finset := dec_trivial,\n rw[this,prod_coe_list h],\n simp only [list.map,list.prod_cons,list.prod_nil,mul_one]\nend\n\nlemma prod_range_two (f : \u2115 \u2192 \u03b3) : \n (range 2).prod f = f 0 * f 1 := \n by {\n   rw[\u2190 one_mul (f 0)],\n  have : range 2 = list.to_finset [0,1] := rfl,\n  rw[this,prod_coe_list (dec_trivial : list.nodup [0,1])],\n  refl,\n }\n\nlemma sum_range_two (f : \u2115 \u2192 \u03b4) : \n (range 2).sum f = f 0 + f 1 := \n by {\n   rw[\u2190 zero_add (f 0)],\n  have : range 2 = list.to_finset [0,1] := rfl,\n  rw[this,sum_coe_list (dec_trivial : list.nodup [0,1])],\n  refl,\n }\n\n@[to_additive finset.sum_eq_zero_of_terms_eq_zero] \nlemma prod_eq_one_of_terms_eq_one\n (s : finset \u03b1) (f : \u03b1 \u2192 \u03b3) (e : \u2200 a, a \u2208 s \u2192 f a = 1) : \n  s.prod f = 1 := \n   by { have : s.prod f = s.prod (\u03bb a, 1) := prod_congr rfl e,\n        rw[this,prod_const_one]}\n\nend finset", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/algebra/prod_equiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7033779503514431}}
{"text": "/-\nCopyright (c) 2019 Minchao Wu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Minchao Wu, Chris Hughes\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.list.basic\nimport Mathlib.PostPort\n\nuniverses u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# Minimum and maximum of lists\n\n## Main definitions\n\nThe main definitions are `argmax`, `argmin`, `minimum` and `maximum` for lists.\n\n`argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such that\n  `f a = f b`, it returns whichever of `a` or `b` comes first in the list.\n  `argmax f []` = none`\n\n`minimum l` returns an `with_top \u03b1`, the smallest element of `l` for nonempty lists, and `\u22a4` for\n`[]`\n-/\n\nnamespace list\n\n\n/-- Auxiliary definition to define `argmax` -/\ndef argmax\u2082 {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (a : Option \u03b1) (b : \u03b1) :\n    Option \u03b1 :=\n  option.cases_on a (some b) fun (c : \u03b1) => ite (f b \u2264 f c) (some c) (some b)\n\n/-- `argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such\nthat `f a = f b`, it returns whichever of `a` or `b` comes first in the list.\n`argmax f []` = none` -/\ndef argmax {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (l : List \u03b1) : Option \u03b1 :=\n  foldl (argmax\u2082 f) none l\n\n/-- `argmin f l` returns `some a`, where `a` of `l` that minimises `f a`. If there are `a b` such\nthat `f a = f b`, it returns whichever of `a` or `b` comes first in the list.\n`argmin f []` = none` -/\ndef argmin {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (l : List \u03b1) : Option \u03b1 :=\n  argmax f l\n\n@[simp] theorem argmax_two_self {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1) :\n    argmax\u2082 f (some a) a = \u2191a :=\n  if_pos (le_refl (f a))\n\n@[simp] theorem argmax_nil {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) :\n    argmax f [] = none :=\n  rfl\n\n@[simp] theorem argmin_nil {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) :\n    argmin f [] = none :=\n  rfl\n\n@[simp] theorem argmax_singleton {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {a : \u03b1} : argmax f [a] = some a :=\n  rfl\n\n@[simp] theorem argmin_singleton {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {a : \u03b1} : argmin f [a] = \u2191a :=\n  rfl\n\n@[simp] theorem foldl_argmax\u2082_eq_none {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {l : List \u03b1} {o : Option \u03b1} : foldl (argmax\u2082 f) o l = none \u2194 l = [] \u2227 o = none :=\n  sorry\n\ntheorem argmax_mem {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {l : List \u03b1} {m : \u03b1} :\n    m \u2208 argmax f l \u2192 m \u2208 l :=\n  sorry\n\ntheorem argmin_mem {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {l : List \u03b1} {m : \u03b1} :\n    m \u2208 argmin f l \u2192 m \u2208 l :=\n  argmax_mem\n\n@[simp] theorem argmax_eq_none {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {l : List \u03b1} : argmax f l = none \u2194 l = [] :=\n  sorry\n\n@[simp] theorem argmin_eq_none {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {l : List \u03b1} : argmin f l = none \u2194 l = [] :=\n  argmax_eq_none\n\ntheorem le_argmax_of_mem {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {m : \u03b1}\n    {l : List \u03b1} : a \u2208 l \u2192 m \u2208 argmax f l \u2192 f a \u2264 f m :=\n  le_of_foldl_argmax\u2082\n\ntheorem argmin_le_of_mem {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {m : \u03b1}\n    {l : List \u03b1} : a \u2208 l \u2192 m \u2208 argmin f l \u2192 f m \u2264 f a :=\n  le_argmax_of_mem\n\ntheorem argmax_concat {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1)\n    (l : List \u03b1) :\n    argmax f (l ++ [a]) =\n        option.cases_on (argmax f l) (some a) fun (c : \u03b1) => ite (f a \u2264 f c) (some c) (some a) :=\n  sorry\n\ntheorem argmin_concat {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1)\n    (l : List \u03b1) :\n    argmin f (l ++ [a]) =\n        option.cases_on (argmin f l) (some a) fun (c : \u03b1) => ite (f c \u2264 f a) (some c) (some a) :=\n  argmax_concat f a l\n\ntheorem argmax_cons {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1)\n    (l : List \u03b1) :\n    argmax f (a :: l) =\n        option.cases_on (argmax f l) (some a) fun (c : \u03b1) => ite (f c \u2264 f a) (some a) (some c) :=\n  sorry\n\ntheorem argmin_cons {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] (f : \u03b1 \u2192 \u03b2) (a : \u03b1)\n    (l : List \u03b1) :\n    argmin f (a :: l) =\n        option.cases_on (argmin f l) (some a) fun (c : \u03b1) => ite (f a \u2264 f c) (some a) (some c) :=\n  argmax_cons f a l\n\ntheorem index_of_argmax {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] [DecidableEq \u03b1] {f : \u03b1 \u2192 \u03b2}\n    {l : List \u03b1} {m : \u03b1} :\n    m \u2208 argmax f l \u2192 \u2200 {a : \u03b1}, a \u2208 l \u2192 f m \u2264 f a \u2192 index_of m l \u2264 index_of a l :=\n  sorry\n\ntheorem index_of_argmin {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] [DecidableEq \u03b1] {f : \u03b1 \u2192 \u03b2}\n    {l : List \u03b1} {m : \u03b1} :\n    m \u2208 argmin f l \u2192 \u2200 {a : \u03b1}, a \u2208 l \u2192 f a \u2264 f m \u2192 index_of m l \u2264 index_of a l :=\n  index_of_argmax\n\ntheorem mem_argmax_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] [DecidableEq \u03b1] {f : \u03b1 \u2192 \u03b2}\n    {m : \u03b1} {l : List \u03b1} :\n    m \u2208 argmax f l \u2194\n        m \u2208 l \u2227\n          (\u2200 (a : \u03b1), a \u2208 l \u2192 f a \u2264 f m) \u2227\n            \u2200 (a : \u03b1), a \u2208 l \u2192 f m \u2264 f a \u2192 index_of m l \u2264 index_of a l :=\n  sorry\n\ntheorem argmax_eq_some_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] [DecidableEq \u03b1]\n    {f : \u03b1 \u2192 \u03b2} {m : \u03b1} {l : List \u03b1} :\n    argmax f l = some m \u2194\n        m \u2208 l \u2227\n          (\u2200 (a : \u03b1), a \u2208 l \u2192 f a \u2264 f m) \u2227\n            \u2200 (a : \u03b1), a \u2208 l \u2192 f m \u2264 f a \u2192 index_of m l \u2264 index_of a l :=\n  mem_argmax_iff\n\ntheorem mem_argmin_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] [DecidableEq \u03b1] {f : \u03b1 \u2192 \u03b2}\n    {m : \u03b1} {l : List \u03b1} :\n    m \u2208 argmin f l \u2194\n        m \u2208 l \u2227\n          (\u2200 (a : \u03b1), a \u2208 l \u2192 f m \u2264 f a) \u2227\n            \u2200 (a : \u03b1), a \u2208 l \u2192 f a \u2264 f m \u2192 index_of m l \u2264 index_of a l :=\n  mem_argmax_iff\n\ntheorem argmin_eq_some_iff {\u03b1 : Type u_1} {\u03b2 : Type u_2} [linear_order \u03b2] [DecidableEq \u03b1]\n    {f : \u03b1 \u2192 \u03b2} {m : \u03b1} {l : List \u03b1} :\n    argmin f l = some m \u2194\n        m \u2208 l \u2227\n          (\u2200 (a : \u03b1), a \u2208 l \u2192 f m \u2264 f a) \u2227\n            \u2200 (a : \u03b1), a \u2208 l \u2192 f a \u2264 f m \u2192 index_of m l \u2264 index_of a l :=\n  mem_argmin_iff\n\n/-- `maximum l` returns an `with_bot \u03b1`, the largest element of `l` for nonempty lists, and `\u22a5` for\n`[]`  -/\ndef maximum {\u03b1 : Type u_1} [linear_order \u03b1] (l : List \u03b1) : with_bot \u03b1 := argmax id l\n\n/-- `minimum l` returns an `with_top \u03b1`, the smallest element of `l` for nonempty lists, and `\u22a4` for\n`[]`  -/\ndef minimum {\u03b1 : Type u_1} [linear_order \u03b1] (l : List \u03b1) : with_top \u03b1 := argmin id l\n\n@[simp] theorem maximum_nil {\u03b1 : Type u_1} [linear_order \u03b1] : maximum [] = \u22a5 := rfl\n\n@[simp] theorem minimum_nil {\u03b1 : Type u_1} [linear_order \u03b1] : minimum [] = \u22a4 := rfl\n\n@[simp] theorem maximum_singleton {\u03b1 : Type u_1} [linear_order \u03b1] (a : \u03b1) : maximum [a] = \u2191a := rfl\n\n@[simp] theorem minimum_singleton {\u03b1 : Type u_1} [linear_order \u03b1] (a : \u03b1) : minimum [a] = \u2191a := rfl\n\ntheorem maximum_mem {\u03b1 : Type u_1} [linear_order \u03b1] {l : List \u03b1} {m : \u03b1} : maximum l = \u2191m \u2192 m \u2208 l :=\n  argmax_mem\n\ntheorem minimum_mem {\u03b1 : Type u_1} [linear_order \u03b1] {l : List \u03b1} {m : \u03b1} : minimum l = \u2191m \u2192 m \u2208 l :=\n  argmin_mem\n\n@[simp] theorem maximum_eq_none {\u03b1 : Type u_1} [linear_order \u03b1] {l : List \u03b1} :\n    maximum l = none \u2194 l = [] :=\n  argmax_eq_none\n\n@[simp] theorem minimum_eq_none {\u03b1 : Type u_1} [linear_order \u03b1] {l : List \u03b1} :\n    minimum l = none \u2194 l = [] :=\n  argmin_eq_none\n\ntheorem le_maximum_of_mem {\u03b1 : Type u_1} [linear_order \u03b1] {a : \u03b1} {m : \u03b1} {l : List \u03b1} :\n    a \u2208 l \u2192 maximum l = \u2191m \u2192 a \u2264 m :=\n  le_argmax_of_mem\n\ntheorem minimum_le_of_mem {\u03b1 : Type u_1} [linear_order \u03b1] {a : \u03b1} {m : \u03b1} {l : List \u03b1} :\n    a \u2208 l \u2192 minimum l = \u2191m \u2192 m \u2264 a :=\n  argmin_le_of_mem\n\ntheorem le_maximum_of_mem' {\u03b1 : Type u_1} [linear_order \u03b1] {a : \u03b1} {l : List \u03b1} (ha : a \u2208 l) :\n    \u2191a \u2264 maximum l :=\n  sorry\n\ntheorem le_minimum_of_mem' {\u03b1 : Type u_1} [linear_order \u03b1] {a : \u03b1} {l : List \u03b1} (ha : a \u2208 l) :\n    minimum l \u2264 \u2191a :=\n  le_maximum_of_mem' ha\n\ntheorem maximum_concat {\u03b1 : Type u_1} [linear_order \u03b1] (a : \u03b1) (l : List \u03b1) :\n    maximum (l ++ [a]) = max (maximum l) \u2191a :=\n  sorry\n\ntheorem minimum_concat {\u03b1 : Type u_1} [linear_order \u03b1] (a : \u03b1) (l : List \u03b1) :\n    minimum (l ++ [a]) = min (minimum l) \u2191a :=\n  maximum_concat a l\n\ntheorem maximum_cons {\u03b1 : Type u_1} [linear_order \u03b1] (a : \u03b1) (l : List \u03b1) :\n    maximum (a :: l) = max (\u2191a) (maximum l) :=\n  sorry\n\ntheorem minimum_cons {\u03b1 : Type u_1} [linear_order \u03b1] (a : \u03b1) (l : List \u03b1) :\n    minimum (a :: l) = min (\u2191a) (minimum l) :=\n  maximum_cons a l\n\ntheorem maximum_eq_coe_iff {\u03b1 : Type u_1} [linear_order \u03b1] {m : \u03b1} {l : List \u03b1} :\n    maximum l = \u2191m \u2194 m \u2208 l \u2227 \u2200 (a : \u03b1), a \u2208 l \u2192 a \u2264 m :=\n  sorry\n\ntheorem minimum_eq_coe_iff {\u03b1 : Type u_1} [linear_order \u03b1] {m : \u03b1} {l : List \u03b1} :\n    minimum l = \u2191m \u2194 m \u2208 l \u2227 \u2200 (a : \u03b1), a \u2208 l \u2192 m \u2264 a :=\n  maximum_eq_coe_iff\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/list/min_max_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7033779470362139}}
{"text": "-- Imagen_inversa_de_la_interseccion_general.lean\n-- Imagen inversa de la intersecci\u00f3n general\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 27 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {I : Type*}\nvariable  f : \u03b1 \u2192 \u03b2\nvariables B : I \u2192 set \u03b2\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  split,\n  { intro hx,\n    apply mem_Inter_of_mem,\n    intro i,\n    rw mem_preimage,\n    rw mem_preimage at hx,\n    rw mem_Inter at hx,\n    exact hx i, },\n  { intro hx,\n    rw mem_preimage,\n    rw mem_Inter,\n    intro i,\n    rw \u2190 mem_preimage,\n    rw mem_Inter at hx,\n    exact hx i, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  calc  (x \u2208 f \u207b\u00b9' \u22c2 (i : I), B i)\n      \u2194 f x \u2208 \u22c2 (i : I), B i       : mem_preimage\n  ... \u2194 (\u2200 i : I, f x \u2208 B i)       : mem_Inter\n  ... \u2194 (\u2200 i : I, x \u2208 f \u207b\u00b9' B i)   : iff_of_eq rfl\n  ... \u2194 x \u2208 \u22c2 (i : I), f \u207b\u00b9' B i   : mem_Inter.symm,\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nbegin\n  ext x,\n  simp,\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : f \u207b\u00b9' (\u22c2 i, B i) = \u22c2 i, f \u207b\u00b9' (B i) :=\nby { ext, simp }\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Imagen_inversa_de_la_interseccion_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7033779402949688}}
{"text": "/-\nCopyright (c) 2017 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Neil Strickland\n-/\nimport data.nat.basic\n\n/-!\n# The positive natural numbers\n\nThis file defines the type `\u2115+` or `pnat`, the subtype of natural numbers that are positive.\n-/\n\n/-- `\u2115+` is the type of positive natural numbers. It is defined as a subtype,\n  and the VM representation of `\u2115+` is the same as `\u2115` because the proof\n  is not stored. -/\ndef pnat := {n : \u2115 // 0 < n}\nnotation `\u2115+` := pnat\n\ninstance coe_pnat_nat : has_coe \u2115+ \u2115 := \u27e8subtype.val\u27e9\ninstance : has_repr \u2115+ := \u27e8\u03bb n, repr n.1\u27e9\n\n/-- Predecessor of a `\u2115+`, as a `\u2115`. -/\ndef pnat.nat_pred (i : \u2115+) : \u2115 := i - 1\n\nnamespace nat\n\n/-- Convert a natural number to a positive natural number. The\n  positivity assumption is inferred by `dec_trivial`. -/\ndef to_pnat (n : \u2115) (h : 0 < n . tactic.exact_dec_trivial) : \u2115+ := \u27e8n, h\u27e9\n\n/-- Write a successor as an element of `\u2115+`. -/\ndef succ_pnat (n : \u2115) : \u2115+ := \u27e8succ n, succ_pos n\u27e9\n\n@[simp] theorem succ_pnat_coe (n : \u2115) : (succ_pnat n : \u2115) = succ n := rfl\n\ntheorem succ_pnat_inj {n m : \u2115} : succ_pnat n = succ_pnat m \u2192 n = m :=\n\u03bb h, by { let h' := congr_arg (coe : \u2115+ \u2192 \u2115) h, exact nat.succ.inj h' }\n\n/-- Convert a natural number to a pnat. `n+1` is mapped to itself,\n  and `0` becomes `1`. -/\ndef to_pnat' (n : \u2115) : \u2115+ := succ_pnat (pred n)\n\n@[simp] theorem to_pnat'_coe : \u2200 (n : \u2115),\n ((to_pnat' n) : \u2115) = ite (0 < n) n 1\n| 0 := rfl\n| (m + 1) := by {rw [if_pos (succ_pos m)], refl}\n\nend nat\n\nnamespace pnat\n\nopen nat\n\n/-- We now define a long list of structures on \u2115+ induced by\n similar structures on \u2115. Most of these behave in a completely\n obvious way, but there are a few things to be said about\n subtraction, division and powers.\n-/\n\ninstance : decidable_eq \u2115+ := \u03bb (a b : \u2115+), by apply_instance\n\ninstance : linear_order \u2115+ :=\nsubtype.linear_order _\n\n@[simp] lemma mk_le_mk (n k : \u2115) (hn : 0 < n) (hk : 0 < k) :\n  (\u27e8n, hn\u27e9 : \u2115+) \u2264 \u27e8k, hk\u27e9 \u2194 n \u2264 k := iff.rfl\n\n@[simp] lemma mk_lt_mk (n k : \u2115) (hn : 0 < n) (hk : 0 < k) :\n  (\u27e8n, hn\u27e9 : \u2115+) < \u27e8k, hk\u27e9 \u2194 n < k := iff.rfl\n\n@[simp, norm_cast] lemma coe_le_coe (n k : \u2115+) : (n:\u2115) \u2264 k \u2194 n \u2264 k := iff.rfl\n\n@[simp, norm_cast] lemma coe_lt_coe (n k : \u2115+) : (n:\u2115) < k \u2194 n < k := iff.rfl\n\n@[simp] theorem pos (n : \u2115+) : 0 < (n : \u2115) := n.2\n\ntheorem eq {m n : \u2115+} : (m : \u2115) = n \u2192 m = n := subtype.eq\n\n@[simp] lemma coe_inj {m n : \u2115+} : (m : \u2115) = n \u2194 m = n := set_coe.ext_iff\n\nlemma coe_injective : function.injective (coe : \u2115+ \u2192 \u2115) := subtype.coe_injective\n\n@[simp] theorem mk_coe (n h) : ((\u27e8n, h\u27e9 : \u2115+) : \u2115) = n := rfl\n\ninstance : has_add \u2115+ := \u27e8\u03bb a b, \u27e8(a  + b : \u2115), add_pos a.pos b.pos\u27e9\u27e9\n\ninstance : add_comm_semigroup \u2115+ := coe_injective.add_comm_semigroup coe (\u03bb _ _, rfl)\n\n@[simp] theorem add_coe (m n : \u2115+) : ((m + n : \u2115+) : \u2115) = m + n := rfl\ninstance coe_add_hom : is_add_hom (coe : \u2115+ \u2192 \u2115) := \u27e8add_coe\u27e9\n\ninstance : add_left_cancel_semigroup \u2115+ :=\ncoe_injective.add_left_cancel_semigroup coe (\u03bb _ _, rfl)\n\ninstance : add_right_cancel_semigroup \u2115+ :=\ncoe_injective.add_right_cancel_semigroup coe (\u03bb _ _, rfl)\n\n@[simp] theorem ne_zero (n : \u2115+) : (n : \u2115) \u2260 0 := ne_of_gt n.2\n\ntheorem to_pnat'_coe {n : \u2115} : 0 < n \u2192 (n.to_pnat' : \u2115) = n := succ_pred_eq_of_pos\n\n@[simp] theorem coe_to_pnat' (n : \u2115+) : (n : \u2115).to_pnat' = n := eq (to_pnat'_coe n.pos)\n\ninstance : has_mul \u2115+ := \u27e8\u03bb m n, \u27e8m.1 * n.1, mul_pos m.2 n.2\u27e9\u27e9\ninstance : has_one \u2115+ := \u27e8succ_pnat 0\u27e9\n\ninstance : comm_monoid \u2115+ := coe_injective.comm_monoid coe rfl (\u03bb _ _, rfl)\n\ntheorem lt_add_one_iff : \u2200 {a b : \u2115+}, a < b + 1 \u2194 a \u2264 b :=\n\u03bb a b, nat.lt_add_one_iff\n\ntheorem add_one_le_iff : \u2200 {a b : \u2115+}, a + 1 \u2264 b \u2194 a < b :=\n\u03bb a b, nat.add_one_le_iff\n\n@[simp] lemma one_le (n : \u2115+) : (1 : \u2115+) \u2264 n := n.2\n\ninstance : order_bot \u2115+ :=\n{ bot := 1,\n  bot_le := \u03bb a, a.property,\n  .. pnat.linear_order }\n\n@[simp] lemma bot_eq_zero : (\u22a5 : \u2115+) = 1 := rfl\n\ninstance : inhabited \u2115+ := \u27e81\u27e9\n\n-- Some lemmas that rewrite `pnat.mk n h`, for `n` an explicit numeral, into explicit numerals.\n@[simp] lemma mk_one {h} : (\u27e81, h\u27e9 : \u2115+) = (1 : \u2115+) := rfl\n@[simp] lemma mk_bit0 (n) {h} : (\u27e8bit0 n, h\u27e9 : \u2115+) = (bit0 \u27e8n, pos_of_bit0_pos h\u27e9 : \u2115+) := rfl\n@[simp] lemma mk_bit1 (n) {h} {k} : (\u27e8bit1 n, h\u27e9 : \u2115+) = (bit1 \u27e8n, k\u27e9 : \u2115+) := rfl\n\n-- Some lemmas that rewrite inequalities between explicit numerals in `pnat`\n-- into the corresponding inequalities in `nat`.\n-- TODO: perhaps this should not be attempted by `simp`,\n-- and instead we should expect `norm_num` to take care of these directly?\n-- TODO: these lemmas are perhaps incomplete:\n-- * 1 is not represented as a bit0 or bit1\n-- * strict inequalities?\n@[simp] lemma bit0_le_bit0 (n m : \u2115+) : (bit0 n) \u2264 (bit0 m) \u2194 (bit0 (n : \u2115)) \u2264 (bit0 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit0_le_bit1 (n m : \u2115+) : (bit0 n) \u2264 (bit1 m) \u2194 (bit0 (n : \u2115)) \u2264 (bit1 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit1_le_bit0 (n m : \u2115+) : (bit1 n) \u2264 (bit0 m) \u2194 (bit1 (n : \u2115)) \u2264 (bit0 (m : \u2115)) :=\niff.rfl\n@[simp] lemma bit1_le_bit1 (n m : \u2115+) : (bit1 n) \u2264 (bit1 m) \u2194 (bit1 (n : \u2115)) \u2264 (bit1 (m : \u2115)) :=\niff.rfl\n\n@[simp] theorem one_coe : ((1 : \u2115+) : \u2115) = 1 := rfl\n@[simp] theorem mul_coe (m n : \u2115+) : ((m * n : \u2115+) : \u2115) = m * n := rfl\ninstance coe_mul_hom : is_monoid_hom (coe : \u2115+ \u2192 \u2115) :=\n {map_one := one_coe, map_mul := mul_coe}\n\n @[simp]\nlemma coe_eq_one_iff {m : \u2115+} :\n(m : \u2115) = 1 \u2194 m = 1 := by { split; intro h; try { apply pnat.eq}; rw h; simp }\n\n\n@[simp] lemma coe_bit0 (a : \u2115+) : ((bit0 a : \u2115+) : \u2115) = bit0 (a : \u2115) := rfl\n@[simp] lemma coe_bit1 (a : \u2115+) : ((bit1 a : \u2115+) : \u2115) = bit1 (a : \u2115) := rfl\n\n@[simp] theorem pow_coe (m : \u2115+) (n : \u2115) : ((m ^ n : \u2115+) : \u2115) = (m : \u2115) ^ n :=\nby induction n with n ih;\n [refl, rw [pow_succ', pow_succ, mul_coe, mul_comm, ih]]\n\ninstance : ordered_cancel_comm_monoid \u2115+ :=\n{ mul_le_mul_left := by { intros, apply nat.mul_le_mul_left, assumption },\n  le_of_mul_le_mul_left := by { intros a b c h, apply nat.le_of_mul_le_mul_left h a.property, },\n  mul_left_cancel := \u03bb a b c h, by {\n   replace h := congr_arg (coe : \u2115+ \u2192 \u2115) h,\n   exact eq ((nat.mul_right_inj a.pos).mp h)},\n  .. pnat.comm_monoid,\n  .. pnat.linear_order }\n\ninstance : distrib \u2115+ := coe_injective.distrib coe (\u03bb _ _, rfl) (\u03bb _ _, rfl)\n\n/-- Subtraction a - b is defined in the obvious way when\n  a > b, and by a - b = 1 if a \u2264 b.\n-/\ninstance : has_sub \u2115+ := \u27e8\u03bb a b, to_pnat' (a - b : \u2115)\u27e9\n\ntheorem sub_coe (a b : \u2115+) : ((a - b : \u2115+) : \u2115) = ite (b < a) (a - b : \u2115) 1 :=\nbegin\n  change ((to_pnat' ((a : \u2115) - (b :  \u2115)) : \u2115)) =\n    ite ((a : \u2115) > (b : \u2115)) ((a : \u2115) - (b : \u2115)) 1,\n  split_ifs with h,\n  { exact to_pnat'_coe (nat.sub_pos_of_lt h) },\n  { rw [nat.sub_eq_zero_iff_le.mpr (le_of_not_gt h)], refl }\nend\n\ntheorem add_sub_of_lt {a b : \u2115+} : a < b \u2192 a + (b - a) = b :=\n \u03bb h, eq $ by { rw [add_coe, sub_coe, if_pos h],\n                exact nat.add_sub_of_le (le_of_lt h) }\n\ninstance : has_well_founded \u2115+ := \u27e8(<), measure_wf coe\u27e9\n\n/-- Strong induction on `pnat`. -/\nlemma strong_induction_on {p : pnat \u2192 Prop} : \u2200 (n : pnat) (h : \u2200 k, (\u2200 m, m < k \u2192 p m) \u2192 p k), p n\n| n := \u03bb IH, IH _ (\u03bb a h, strong_induction_on a IH)\nusing_well_founded { dec_tac := `[assumption] }\n\n/-- If `(n : pnat)` is different from `1`, then it is the successor of some `(k : pnat)`. -/\nlemma exists_eq_succ_of_ne_one : \u2200 {n : pnat} (h1 : n \u2260 1), \u2203 (k : pnat), n = k + 1\n| \u27e81, _\u27e9 h1 := false.elim $ h1 rfl\n| \u27e8n+2, _\u27e9 _ := \u27e8\u27e8n+1, by simp\u27e9, rfl\u27e9\n\nlemma case_strong_induction_on {p : pnat \u2192 Prop} (a : pnat) (hz : p 1)\n  (hi : \u2200 n, (\u2200 m, m \u2264 n \u2192 p m) \u2192 p (n + 1)) : p a :=\nbegin\n  apply strong_induction_on a,\n  intros k hk,\n  by_cases h1 : k = 1, { rwa h1 },\n  obtain \u27e8b, rfl\u27e9 := exists_eq_succ_of_ne_one h1,\n  simp only [lt_add_one_iff] at hk,\n  exact hi b hk\nend\n\n/-- An induction principle for `pnat`: it takes values in `Sort*`, so it applies also to Types,\nnot only to `Prop`. -/\n@[elab_as_eliminator]\ndef rec_on (n : pnat) {p : pnat \u2192 Sort*} (p1 : p 1) (hp : \u2200 n, p n \u2192 p (n + 1)) : p n :=\nbegin\n  rcases n with \u27e8n, h\u27e9,\n  induction n with n IH,\n  { exact absurd h dec_trivial },\n  { cases n with n,\n    { exact p1 },\n    { exact hp _ (IH n.succ_pos) } }\nend\n\n@[simp] theorem rec_on_one {p} (p1 hp) : @pnat.rec_on 1 p p1 hp = p1 := rfl\n\n@[simp] theorem rec_on_succ (n : pnat) {p : pnat \u2192 Sort*} (p1 hp) :\n  @pnat.rec_on (n + 1) p p1 hp = hp n (@pnat.rec_on n p p1 hp) :=\nby { cases n with n h, cases n; [exact absurd h dec_trivial, refl] }\n\n/-- We define `m % k` and `m / k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` and\n  `m / k = n - 1`.  This ensures that `m % k` is always positive\n  and `m = (m % k) + k * (m / k)` in all cases.  Later we\n  define a function `div_exact` which gives the usual `m / k`\n  in the case where `k` divides `m`.\n-/\ndef mod_div_aux : \u2115+ \u2192 \u2115 \u2192 \u2115 \u2192 \u2115+ \u00d7 \u2115\n| k 0 q := \u27e8k, q.pred\u27e9\n| k (r + 1) q := \u27e8\u27e8r + 1, nat.succ_pos r\u27e9, q\u27e9\n\nlemma mod_div_aux_spec : \u2200 (k : \u2115+) (r q : \u2115) (h : \u00ac (r = 0 \u2227 q = 0)),\n (((mod_div_aux k r q).1 : \u2115) + k * (mod_div_aux k r q).2 = (r + k * q))\n| k 0 0 h := (h \u27e8rfl, rfl\u27e9).elim\n| k 0 (q + 1) h := by {\n  change (k : \u2115) + (k : \u2115) * (q + 1).pred = 0 + (k : \u2115) * (q + 1),\n  rw [nat.pred_succ, nat.mul_succ, zero_add, add_comm]}\n| k (r + 1) q h := rfl\n\n/-- `mod_div m k = (m % k, m / k)`.\n  We define `m % k` and `m / k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` and\n  `m / k = n - 1`.  This ensures that `m % k` is always positive\n  and `m = (m % k) + k * (m / k)` in all cases.  Later we\n  define a function `div_exact` which gives the usual `m / k`\n  in the case where `k` divides `m`.\n-/\ndef mod_div (m k : \u2115+) : \u2115+ \u00d7 \u2115 := mod_div_aux k ((m : \u2115) % (k : \u2115)) ((m : \u2115) / (k : \u2115))\n\n/-- We define `m % k` in the same way as for `\u2115`\n  except that when `m = n * k` we take `m % k = k` This ensures that `m % k` is always positive.\n-/\ndef mod (m k : \u2115+) : \u2115+ := (mod_div m k).1\n\n/-- We define `m / k` in the same way as for `\u2115` except that when `m = n * k` we take\n  `m / k = n - 1`. This ensures that `m = (m % k) + k * (m / k)` in all cases. Later we\n  define a function `div_exact` which gives the usual `m / k` in the case where `k` divides `m`.\n-/\ndef div (m k : \u2115+) : \u2115  := (mod_div m k).2\n\ntheorem mod_add_div (m k : \u2115+) : ((mod m k) + k * (div m k) : \u2115) = m :=\nbegin\n  let h\u2080 := nat.mod_add_div (m : \u2115) (k : \u2115),\n  have : \u00ac ((m : \u2115) % (k : \u2115) = 0 \u2227 (m : \u2115) / (k : \u2115) = 0),\n  by { rintro \u27e8hr, hq\u27e9, rw [hr, hq, mul_zero, zero_add] at h\u2080,\n       exact (m.ne_zero h\u2080.symm).elim },\n  have := mod_div_aux_spec k ((m : \u2115) % (k : \u2115)) ((m : \u2115) / (k : \u2115)) this,\n  exact (this.trans h\u2080),\nend\n\ntheorem div_add_mod (m k : \u2115+) : (k * (div m k) + mod m k : \u2115) = m :=\n(add_comm _ _).trans (mod_add_div _ _)\n\nlemma mod_add_div' (m k : \u2115+) : ((mod m k) + (div m k) * k : \u2115) = m :=\nby { rw mul_comm, exact mod_add_div _ _ }\n\nlemma div_add_mod' (m k : \u2115+) : ((div m k) * k + mod m k : \u2115) = m :=\nby { rw mul_comm, exact div_add_mod _ _ }\n\ntheorem mod_coe (m k : \u2115+) :\n ((mod m k) : \u2115) = ite ((m : \u2115) % (k : \u2115) = 0) (k : \u2115) ((m : \u2115) % (k : \u2115)) :=\nbegin\n  dsimp [mod, mod_div],\n  cases (m : \u2115) % (k : \u2115),\n  { rw [if_pos rfl], refl },\n  { rw [if_neg n.succ_ne_zero], refl }\nend\n\ntheorem div_coe (m k : \u2115+) :\n ((div m k) : \u2115) = ite ((m : \u2115) % (k : \u2115) = 0) ((m : \u2115) / (k : \u2115)).pred ((m : \u2115) / (k : \u2115)) :=\nbegin\n  dsimp [div, mod_div],\n  cases (m : \u2115) % (k : \u2115),\n  { rw [if_pos rfl], refl },\n  { rw [if_neg n.succ_ne_zero], refl }\nend\n\ntheorem mod_le (m k : \u2115+) : mod m k \u2264 m \u2227 mod m k \u2264 k :=\nbegin\n  change ((mod m k) : \u2115) \u2264 (m : \u2115) \u2227 ((mod m k) : \u2115) \u2264 (k : \u2115),\n  rw [mod_coe], split_ifs,\n  { have hm : (m : \u2115) > 0 := m.pos,\n    rw [\u2190 nat.mod_add_div (m : \u2115) (k : \u2115), h, zero_add] at hm \u22a2,\n    by_cases h' : ((m : \u2115) / (k : \u2115)) = 0,\n    { rw [h', mul_zero] at hm, exact (lt_irrefl _ hm).elim},\n    { let h' := nat.mul_le_mul_left (k : \u2115)\n             (nat.succ_le_of_lt (nat.pos_of_ne_zero h')),\n      rw [mul_one] at h', exact \u27e8h', le_refl (k : \u2115)\u27e9 } },\n  { exact \u27e8nat.mod_le (m : \u2115) (k : \u2115), le_of_lt (nat.mod_lt (m : \u2115) k.pos)\u27e9 }\nend\n\ntheorem dvd_iff {k m : \u2115+} : k \u2223 m \u2194 (k : \u2115) \u2223 (m : \u2115) :=\nbegin\n  split; intro h, rcases h with \u27e8_, rfl\u27e9, apply dvd_mul_right,\n  rcases h with \u27e8a, h\u27e9, cases a, { contrapose h, apply ne_zero, },\n  use a.succ, apply nat.succ_pos, rw [\u2190 coe_inj, h, mul_coe, mk_coe],\nend\n\ntheorem dvd_iff' {k m : \u2115+} : k \u2223 m \u2194 mod m k = k :=\nbegin\n  rw dvd_iff,\n  rw [nat.dvd_iff_mod_eq_zero], split,\n  { intro h, apply eq, rw [mod_coe, if_pos h] },\n  { intro h, by_cases h' : (m : \u2115) % (k : \u2115) = 0,\n    { exact h'},\n    { replace h : ((mod m k) : \u2115) = (k : \u2115) := congr_arg _ h,\n      rw [mod_coe, if_neg h'] at h,\n      exact (ne_of_lt (nat.mod_lt (m : \u2115) k.pos) h).elim } }\nend\n\nlemma le_of_dvd {m n : \u2115+} : m \u2223 n \u2192 m \u2264 n :=\nby { rw dvd_iff', intro h, rw \u2190 h, apply (mod_le n m).left }\n\n/-- If `h : k | m`, then `k * (div_exact m k) = m`. Note that this is not equal to `m / k`. -/\ndef div_exact (m k : \u2115+) : \u2115+ :=\n \u27e8(div m k).succ, nat.succ_pos _\u27e9\n\ntheorem mul_div_exact {m k : \u2115+} (h : k \u2223 m) : k * (div_exact m k) = m :=\nbegin\n apply eq, rw [mul_coe],\n change (k : \u2115) * (div m k).succ = m,\n rw [\u2190 div_add_mod m k, dvd_iff'.mp h, nat.mul_succ]\nend\n\n\n\ntheorem dvd_one_iff (n : \u2115+) : n \u2223 1 \u2194 n = 1 :=\n \u27e8\u03bb h, dvd_antisymm h (one_dvd n), \u03bb h, h.symm \u25b8 (dvd_refl 1)\u27e9\n\nlemma pos_of_div_pos {n : \u2115+} {a : \u2115} (h : a \u2223 n) : 0 < a :=\nbegin\n  apply pos_iff_ne_zero.2,\n  intro hzero,\n  rw hzero at h,\n  exact pnat.ne_zero n (eq_zero_of_zero_dvd h)\nend\n\nend pnat\n\nsection can_lift\n\ninstance nat.can_lift_pnat : can_lift \u2115 \u2115+ :=\n\u27e8coe, \u03bb n, 0 < n, \u03bb n hn, \u27e8nat.to_pnat' n, pnat.to_pnat'_coe hn\u27e9\u27e9\n\ninstance int.can_lift_pnat : can_lift \u2124 \u2115+ :=\n\u27e8coe, \u03bb n, 0 < n, \u03bb n hn, \u27e8nat.to_pnat' (int.nat_abs n),\n  by rw [coe_coe, nat.to_pnat'_coe, if_pos (int.nat_abs_pos_of_ne_zero (ne_of_gt hn)),\n    int.nat_abs_of_nonneg hn.le]\u27e9\u27e9\n\nend can_lift\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/pnat/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505964, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7033779301941795}}
{"text": "/-\nCopyright (c) 2023 Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Mar\u00eda In\u00e9s de Frutos-Fern\u00e1ndez\n-/\n\nimport tactic -- importa todas las t\u00e1cticas de Lean\n\n/-!\n# L\u00f3gica proposicional en Lean\n\n`P : Prop` significa que `P` es una proposici\u00f3n. \n`h : P` significa que `h` es una demostraci\u00f3n de que `P` es cierta.\n\nEn el apartado `Tactic state` de la ventana `Lean infoview`, detr\u00e1s del s\u00edmbolo `\u22a2` se muestra\nel resultado que queremos demostrar. Encima de dicha l\u00ednea tenemos las hip\u00f3tesis activas.\n\nLean 3 utiliza la siguente notaci\u00f3n para las conectivas l\u00f3gicas:\n* `\u2192` (\"implica\" -- escrito `\\l`)\n* `\u00ac` (\"no\" -- escrito  `\\not` o `\\n`)\n* `\u2227` (\"y\" -- escrito  `\\and` o `\\an`)\n* `\u2194` (\"si y s\u00f3lo si\" -- escrito  `\\iff` o `\\lr`)\n* `\u2228` (\"o\" -- escrito  `\\or` o `\\v`\n\nNOTA: en VSCode, para saber c\u00f3mo se ha escrito un s\u00edmbolo UNICODE, basta dejar el cursor\nsobre \u00e9l.\n\n# T\u00e1cticas\nPara completar los ejercicios, ser\u00e1 necesario utlizar las siguientes t\u00e1cticas de Lean, cuyo \nfuncionamiento se describe en el fichero `tacticas.lean`. Los ejercicios de la primera secci\u00f3n\npueden resolverse utilizando exclusivamente `intro`, `exact`, y `apply`. En los comentarios al\ninicio de cada secci\u00f3n se indica qu\u00e9 nuevas t\u00e1cticas son necesarias.\n\n* `intro`\n* `exact`\n* `apply`\n* `triv`\n* `exfalso`\n* `change`\n* `by_contra`\n* `cases`\n* `split`\n* `refl`\n* `rw`\n* `have`\n* `left`\n* `right`\n\n-/ \n\n-- `P`, `Q`, `R` y `S` denotan proposiciones.\nvariables (P Q R S : Prop)\n\n/- Convenci\u00f3n: utilizaremos variables cuyo nombre comienza por with `h` (como `hP` or `h1`) para\ndemostraciones o hip\u00f3tesis. -/\n\n\n/-\n## Implicaci\u00f3n\nLa t\u00e1ctica `sorry` se utiliza para evitar el error que de otro modo produce Lean cuando no \naportamos la demostraci\u00f3n de un resultado.\n\nEn los ejemplos siguientes, reemplaza el `sorry` por una demostraci\u00f3n que utilice las t\u00e1cticas\n`intro`, `exact` y `apply`. Recuerda a\u00f1adir una coma al final de cada instrucci\u00f3n.\n-/\nsection implicacion\n\n\n/-- Toda proposici\u00f3n se sigue de s\u00ed misma -/\nexample : P \u2192 P :=\nbegin\n  sorry\nend\n\n/- NOTA: La convenci\u00f3n en Lean es que `P \u2192 Q \u2192 R` significa `P \u2192 (Q \u2192 R)` (es decir, los\npar\u00e9ntesis impl\u00edcitos asocian por la derecha).\n\nEn particular, en este ejemplo se nos pide demostrar `P \u2192 (Q \u2192 P)`.\n\nComo consejo general, si no estamos seguros de si una cierta operaci\u00f3n se est\u00e1 asociando por la\nderecha o por la izquierda, podemos consultarlo pasando el cursor sobre la l\u00ednea correspondiente\nen el `Tactic state`.\n-/\nexample : P \u2192 Q \u2192 P :=\nbegin\n  sorry\nend\n\n/-- \"Modus Ponens\": dado `P` y `P \u2192 Q`, podemos deducir `Q`. -/\nlemma modus_ponens : P \u2192 (P \u2192 Q) \u2192 Q :=\nbegin\n  sorry\nend\n\n/-- `\u2192` es transitiva. Es decir, si `P \u2192 Q` y `Q \u2192 R` son verdaderas, `P \u2192 R` tambi\u00e9n. -/\nexample : (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\nbegin\n  sorry,\nend\n\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2192 Q) \u2192 (P \u2192 R) :=\nbegin\n  sorry\nend\n\n/- \nTermina los ejemplos de esta secci\u00f3n si quieres m\u00e1s pr\u00e1ctica con `intro`, `exact` y `apply`; de lo\ncontrario, puedes pasar a la secci\u00f3n `verdadero_falso`.\n-/\n\nexample : (P \u2192 Q) \u2192 ((P \u2192 Q) \u2192 P) \u2192 Q :=\nbegin\n  sorry\nend\n\nexample : ((P \u2192 Q) \u2192 R) \u2192 ((Q \u2192 R) \u2192 P) \u2192 ((R \u2192 P) \u2192 Q) \u2192 P :=\nbegin\n  sorry\nend\n\nexample : ((Q \u2192 P) \u2192 P) \u2192 (Q \u2192 R) \u2192 (R \u2192 P) \u2192 P :=\nbegin\n  sorry\nend\n\nexample : (((P \u2192 Q) \u2192 Q) \u2192 Q) \u2192 (P \u2192 Q) :=\nbegin\n  sorry\nend\n\nexample :\n  (((P \u2192 Q \u2192 Q) \u2192 ((P \u2192 Q) \u2192 Q)) \u2192 R) \u2192\n  ((((P \u2192 P) \u2192 Q) \u2192 (P \u2192 P \u2192 Q)) \u2192 R) \u2192\n  (((P \u2192 P \u2192 Q) \u2192 ((P \u2192 P) \u2192 Q)) \u2192 R) \u2192 R :=\nbegin\n  sorry\nend\n\nend implicacion\n\nsection verdadero_falso\n\n/-!\n# Verdadero y falso\nIntroducimos dos nuevas t\u00e1cticas:\n* `triv`: demuestra `\u22a2 true`.\n* `exfalso`: sustituye el resultado a probar por `false`.\n-/\nexample : true :=\nbegin\n  sorry\nend\n\nexample : true \u2192 true :=\nbegin\n  sorry\nend\n\nexample : false \u2192 true :=\nbegin\n  sorry\nend\n\nexample : false \u2192 false :=\nbegin\n  sorry\nend\n\nexample : (true \u2192 false) \u2192 false :=\nbegin\n  sorry\nend\n\nexample : false \u2192 P :=\nbegin\n  sorry\nend\n\nexample : true \u2192 false \u2192 true \u2192 false \u2192 true \u2192 false :=\nbegin\n  sorry\nend\n\nexample : P \u2192 ((P \u2192 false) \u2192 false) :=\nbegin\n  sorry\nend\n\nexample : (P \u2192 false) \u2192 P \u2192 Q :=\nbegin\n  sorry\nend\n\nexample : (true \u2192 false) \u2192 P :=\nbegin\n  sorry\nend\n\n\nend verdadero_falso\n\n\nsection negacion\n\n/-!\n# Negaci\u00f3n\nEn Lean, `\u00ac P` *est\u00e1 definido como* `P \u2192 false`. Por tanto, `\u00ac P` y `P \u2192 false`\nson *iguales por definici\u00f3n* (hablaremos de esto m\u00e1s adelante en el curso). \n\nLas siguientes t\u00e1cticas podr\u00edan ser \u00fatiles en esta secci\u00f3n:\n* `change`\n* `by_contra`\n-/\n\n\nexample : \u00ac true \u2192 false :=\nbegin\n  sorry\nend\n\nexample : false \u2192 \u00ac true :=\nbegin\n  sorry\nend\n\nexample : \u00ac false \u2192 true :=\nbegin\n  sorry\nend\n\nexample : true \u2192 \u00ac false :=\nbegin\n  sorry\nend\n\nexample : false \u2192 \u00ac P :=\nbegin\n  sorry\nend\n\nexample : P \u2192 \u00ac P \u2192 false :=\nbegin\n  sorry\nend\n\nexample : P \u2192 \u00ac (\u00ac P) :=\nbegin\n  sorry\nend\n\nexample : (P \u2192 Q) \u2192 (\u00ac Q \u2192 \u00ac P) :=\nbegin\n  sorry\nend\n\nexample : \u00ac \u00ac false \u2192 false :=\nbegin\n  sorry\nend\n\nexample : \u00ac \u00ac P \u2192 P :=\nbegin\n  sorry\nend\n\nexample : (\u00ac Q \u2192 \u00ac P) \u2192 (P \u2192 Q) :=\nbegin\n  sorry,\nend\n\n\nend negacion\n\n\nsection conjuncion\n\n/-!\n# Conjunci\u00f3n\nA\u00f1adimos las t\u00e1cticas:\n* `cases`\n* `split`\n-/\n\nexample : P \u2227 Q \u2192 P :=\nbegin\n  sorry\nend\n\nexample : P \u2227 Q \u2192 Q :=\nbegin\n  sorry\nend\n\nexample : (P \u2192 Q \u2192 R) \u2192 (P \u2227 Q \u2192 R) :=\nbegin\n  sorry\nend\n\nexample : P \u2192 Q \u2192 P \u2227 Q :=\nbegin\n  sorry\nend\n\n/-- `\u2227` es sim\u00e9trica. -/\nexample : P \u2227 Q \u2192 Q \u2227 P :=\nbegin\n  sorry\nend\n\nexample : P \u2192 P \u2227 true :=\nbegin\n  sorry\nend\n\nexample : false \u2192 P \u2227 false :=\nbegin\n  sorry\nend\n\n/-- `\u2227` es transitiva. -/\nexample : (P \u2227 Q) \u2192 (Q \u2227 R) \u2192 (P \u2227 R) :=\nbegin\n  sorry,\nend\n\nexample : ((P \u2227 Q) \u2192 R) \u2192 (P \u2192 Q \u2192 R) :=\nbegin\n  sorry,\nend\n\nend conjuncion\n\nsection doble_implicacion\n\n/-!\n# Doble implicaci\u00f3n\nNuevas t\u00e1cticas:\n* `refl`\n* `rw`\n* `have`\n-/\n\nexample : P \u2194 P :=\nbegin\n  sorry\nend\n\nexample : (P \u2194 Q) \u2192 (Q \u2194 P) :=\nbegin\n  sorry\nend\n\nexample : (P \u2194 Q) \u2194 (Q \u2194 P) :=\nbegin\n  sorry\nend\n\nexample : (P \u2194 Q) \u2192 (Q \u2194 R) \u2192 (P \u2194 R) :=\nbegin\n  sorry\nend\n\nexample : P \u2227 Q \u2194 Q \u2227 P :=\nbegin\n  sorry\nend\n\nexample : ((P \u2227 Q) \u2227 R) \u2194 (P \u2227 (Q \u2227 R)) :=\nbegin\n  sorry\nend\n\nexample : P \u2194 (P \u2227 true) :=\nbegin\n  sorry\nend\n\nexample : false \u2194 (P \u2227 false) :=\nbegin\n  sorry\nend\n\nexample : (P \u2194 Q) \u2192 (R \u2194 S) \u2192 (P \u2227 R \u2194 Q \u2227 S) :=\nbegin\n  sorry\nend\n\n/- Una forma de demostrar este teorema es utilizando `by_cases hP : P`. Sin embargo, tambi\u00e9n es\nposible dar una demostraci\u00f3n constructiva, utilizando la t\u00e1ctica `have`. -/\nexample : \u00ac (P \u2194 \u00ac P) :=\nbegin\n  sorry,\nend\n\nend doble_implicacion\n\n\nsection disyuncion\n\n/-!\n# Disyunci\u00f3n\nNuevas t\u00e1cticas\n* `left` y `right`\n* `cases` (nueva funcionalidad)\n-/\n\n\nexample : P \u2192 P \u2228 Q :=\nbegin\n  sorry\nend\n\nexample : Q \u2192 P \u2228 Q :=\nbegin\n  sorry,\nend\n\nexample : P \u2228 Q \u2192 (P \u2192 R) \u2192 (Q \u2192 R) \u2192 R :=\nbegin\n  sorry\nend\n\n/- `\u2228` es sim\u00e9trica. -/\nexample : P \u2228 Q \u2192 Q \u2228 P :=\nbegin\n  sorry\nend\n\n/- `\u2228` es asociativa. -/\nexample : (P \u2228 Q) \u2228 R \u2194 P \u2228 (Q \u2228 R) :=\nbegin\n  sorry,\nend\n\nexample : (P \u2192 R) \u2192 (Q \u2192 S) \u2192 P \u2228 Q \u2192 R \u2228 S :=\nbegin\n  sorry,\nend\n\nexample : (P \u2192 Q) \u2192 P \u2228 R \u2192 Q \u2228 R :=\nbegin\n  sorry,\nend\n\nexample : (P \u2194 R) \u2192 (Q \u2194 S) \u2192 (P \u2228 Q \u2194 R \u2228 S) :=\nbegin\n  sorry,\nend\n\n-- Leyes de de Morgan.\nexample : \u00ac (P \u2228 Q) \u2194 \u00ac P \u2227 \u00ac Q :=\nbegin\n  sorry\nend\n\nexample : \u00ac (P \u2227 Q) \u2194 \u00ac P \u2228 \u00ac Q :=\nbegin\n  sorry\nend\n\nend disyuncion\n\n", "meta": {"author": "mariainesdff", "repo": "curso_formalizacion", "sha": "90f540b0f1afeacecbb3d56a0622adb2a3a32921", "save_path": "github-repos/lean/mariainesdff-curso_formalizacion", "path": "github-repos/lean/mariainesdff-curso_formalizacion/curso_formalizacion-90f540b0f1afeacecbb3d56a0622adb2a3a32921/src/sesion_1/logica.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835411997897, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7033314761540239}}
{"text": "/-\nCopyright (c) 2021 Manuel Candales. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Manuel Candales\n-/\nimport data.real.basic\nimport data.real.sqrt\nimport data.real.nnreal\n\n/-!\n# IMO 2008 Q4\nFind all functions `f : (0,\u221e) \u2192 (0,\u221e)` (so, `f` is a function from the positive real\nnumbers to the positive real numbers) such that\n      ```\n      (f(w)^2 + f(x)^2)/(f(y^2) + f(z^2)) = (w^2 + x^2)/(y^2 + z^2)\n      ```\nfor all positive real numbers `w`, `x`, `y`, `z`, satisfying `wx = yz`.\n\n# Solution\nThe desired theorem is that either `f = \u03bb x, x` or `f = \u03bb x, 1/x`\n-/\n\nopen real\n\nlemma abs_eq_one_of_pow_eq_one (x : \u211d) (n : \u2115) (hn : n \u2260 0) (h : x ^ n = 1) : abs x = 1 :=\nbegin\n  let x\u2080 := nnreal.of_real (abs x),\n  have h' : (abs x) ^ n = 1, { rwa [pow_abs, h, abs_one] },\n  have : (x\u2080 : \u211d) ^ n = 1, rw (nnreal.coe_of_real (abs x) (abs_nonneg x)), exact h',\n  have : x\u2080 = 1 := eq_one_of_pow_eq_one hn (show x\u2080 ^ n = 1, by assumption_mod_cast),\n  rwa \u2190 nnreal.coe_of_real (abs x) (abs_nonneg x), assumption_mod_cast,\nend\n\ntheorem imo2008_q4\n  (f : \u211d \u2192 \u211d)\n  (H\u2081 : \u2200 x > 0, f(x) > 0) :\n  (\u2200 w x y z : \u211d, 0 < w \u2192 0 < x \u2192 0 < y \u2192 0 < z \u2192 w * x = y * z \u2192\n    (f(w) ^ 2 + f(x) ^ 2) / (f(y ^ 2) + f(z ^ 2)) = (w ^ 2 + x ^ 2) / (y ^ 2 + z ^ 2)) \u2194\n  ((\u2200 x > 0, f(x) = x) \u2228 (\u2200 x > 0, f(x) = 1 / x)) :=\nbegin\n  split, swap,\n  -- proof that f(x) = x and f(x) = 1/x satisfy the condition\n  { rintros (h | h),\n    { intros w x y z hw hx hy hz hprod,\n      rw [h w hw, h x hx, h (y ^ 2) (pow_pos hy 2), h (z ^ 2) (pow_pos hz 2)] },\n    { intros w x y z hw hx hy hz hprod,\n      rw [h w hw, h x hx, h (y ^ 2) (pow_pos hy 2), h (z ^ 2) (pow_pos hz 2)],\n      have hy2z2 : y ^ 2 + z ^ 2 \u2260 0 := ne_of_gt (add_pos (pow_pos hy 2) (pow_pos hz 2)),\n      have hz2y2 : z ^ 2 + y ^ 2 \u2260 0 := ne_of_gt (add_pos (pow_pos hz 2) (pow_pos hy 2)),\n      have hp2 : w ^ 2 * x ^ 2 = y ^ 2 * z ^ 2,\n      { rw [\u2190 mul_pow w x 2, \u2190 mul_pow y z 2, hprod] },\n      field_simp [ne_of_gt hw, ne_of_gt hx, ne_of_gt hy, ne_of_gt hz, hy2z2, hz2y2, hp2],\n      ring } },\n\n  -- proof that the only solutions are f(x) = x or f(x) = 1/x\n  intro H\u2082,\n  have h\u2080 : f(1) \u2260 0, { specialize H\u2081 1 zero_lt_one, exact ne_of_gt H\u2081 },\n\n  have h\u2081 : f(1) = 1,\n  { specialize H\u2082 1 1 1 1 zero_lt_one zero_lt_one zero_lt_one zero_lt_one rfl,\n    norm_num at H\u2082,\n    simp only [\u2190 two_mul] at H\u2082,\n    rw mul_div_mul_left (f(1) ^ 2) (f 1) two_ne_zero at H\u2082,\n    rwa \u2190 (div_eq_iff h\u2080).mpr (sq (f 1)) },\n\n  have h\u2082 : \u2200 x > 0, (f(x) - x) * (f(x) - 1 / x) = 0,\n  { intros x hx,\n    have h1xss : 1 * x = (sqrt x) * (sqrt x), { rw [one_mul, mul_self_sqrt (le_of_lt hx)] },\n    specialize H\u2082 1 x (sqrt x) (sqrt x) zero_lt_one hx (sqrt_pos.mpr hx) (sqrt_pos.mpr hx) h1xss,\n    rw [h\u2081, one_pow 2, sq_sqrt (le_of_lt hx), \u2190 two_mul (f(x)), \u2190 two_mul x] at H\u2082,\n    have hx_ne_0 : x \u2260 0 := ne_of_gt hx,\n    have hfx_ne_0 : f(x) \u2260 0, { specialize H\u2081 x hx, exact ne_of_gt H\u2081 },\n    field_simp at H\u2082,\n\n    have h1 : (2 * x) * ((f(x) - x) * (f(x) - 1 / x)) = 0,\n    { calc  (2 * x) * ((f(x) - x) * (f(x) - 1 / x))\n          = 2 * (f(x) - x) * (x * f(x) - x * 1 / x) : by ring\n      ... = 2 * (f(x) - x) * (x * f(x) - 1) : by rw (mul_div_cancel_left 1 hx_ne_0)\n      ... = ((1 + f(x) ^ 2) * (2 * x) - (1 + x ^ 2) * (2 * f(x))) : by ring\n      ... = 0 : sub_eq_zero.mpr H\u2082 },\n\n    have h2x_ne_0 : 2 * x \u2260 0 := mul_ne_zero two_ne_zero hx_ne_0,\n\n    calc  ((f(x) - x) * (f(x) - 1 / x))\n        = (2 * x) * ((f(x) - x) * (f(x) - 1 / x)) / (2 * x) : (mul_div_cancel_left _ h2x_ne_0).symm\n    ... = 0 : by { rw h1, exact zero_div (2 * x) } },\n\n  have h\u2083 : \u2200 x > 0, f(x) = x \u2228 f(x) = 1 / x, { simpa [sub_eq_zero] using h\u2082 },\n\n  by_contradiction,\n  push_neg at h,\n  rcases h with \u27e8\u27e8b, hb, hfb\u2081\u27e9, \u27e8a, ha, hfa\u2081\u27e9\u27e9,\n  obtain hfa\u2082 := or.resolve_right (h\u2083 a ha) hfa\u2081, -- f(a) \u2260 1/a, f(a) = a\n  obtain hfb\u2082 := or.resolve_left (h\u2083 b hb) hfb\u2081,  -- f(b) \u2260 b, f(b) = 1/b\n\n  have hab : a * b > 0 := mul_pos ha hb,\n  have habss : a * b = sqrt(a * b) * sqrt(a * b) := (mul_self_sqrt (le_of_lt hab)).symm,\n\n  specialize H\u2082 a b (sqrt (a * b)) (sqrt (a * b)) ha hb (sqrt_pos.mpr hab) (sqrt_pos.mpr hab) habss,\n  rw [sq_sqrt (le_of_lt hab), \u2190 two_mul (f(a * b)), \u2190 two_mul (a * b)] at H\u2082,\n  rw [hfa\u2082, hfb\u2082] at H\u2082,\n\n  have h2ab_ne_0 : 2 * (a * b) \u2260 0 := mul_ne_zero two_ne_zero (ne_of_gt hab),\n\n  specialize h\u2083 (a * b) hab,\n  cases h\u2083 with hab\u2081 hab\u2082,\n\n  -- f(ab) = ab \u2192 b^4 = 1 \u2192 b = 1 \u2192 f(b) = b \u2192 false\n  { rw hab\u2081 at H\u2082, field_simp at H\u2082,\n    obtain hb\u2081 := or.resolve_right H\u2082 h2ab_ne_0,\n    field_simp [ne_of_gt hb] at hb\u2081,\n    rw (show b ^ 2 * b ^ 2 = b ^ 4, by ring) at hb\u2081,\n    obtain hb\u2082 := abs_eq_one_of_pow_eq_one b 4 (show 4 \u2260 0, by norm_num) hb\u2081.symm,\n    rw abs_of_pos hb at hb\u2082, rw hb\u2082 at hfb\u2081, exact hfb\u2081 h\u2081 },\n\n  -- f(ab) = 1/ab \u2192 a^4 = 1 \u2192 a = 1 \u2192 f(a) = 1/a \u2192 false\n  { have hb_ne_0 : b \u2260 0 := ne_of_gt hb,\n    rw hab\u2082 at H\u2082, field_simp at H\u2082,\n    rw \u2190 sub_eq_zero at H\u2082,\n    rw (show (a ^ 2 * b ^ 2 + 1) * (a * b) * (2 * (a * b)) - (a ^ 2 + b ^ 2) * (b ^ 2 * 2)\n            = 2 * (b ^ 4) * (a ^ 4 - 1), by ring) at H\u2082,\n    have h2b4_ne_0 : 2 * (b ^ 4) \u2260 0 := mul_ne_zero two_ne_zero (pow_ne_zero 4 hb_ne_0),\n    have ha\u2081 : a ^ 4 = 1, { simpa [sub_eq_zero, h2b4_ne_0] using H\u2082 },\n    obtain ha\u2082 := abs_eq_one_of_pow_eq_one a 4 (show 4 \u2260 0, by norm_num) ha\u2081,\n    rw abs_of_pos ha at ha\u2082, rw ha\u2082 at hfa\u2081, norm_num at hfa\u2081 },\nend\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/archive/imo/imo2008_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835411997897, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.703331471180806}}
{"text": "import topology.metric_space.hausdorff_distance\n\nopen set metric\nopen_locale topology\n\nvariables {\u03b1 \u03b2 : Type*} [pseudo_metric_space \u03b1] [pseudo_metric_space \u03b2]\n\nnamespace metric\n\nlemma thickening_ball (x : \u03b1) (\u03b5 \u03b4 : \u211d) : thickening \u03b5 (ball x \u03b4) \u2286 ball x (\u03b5 + \u03b4) :=\nbegin\n  intro y,\n  simp only [mem_thickening_iff, mem_ball],\n  rintros \u27e8z, hz, hz'\u27e9,\n  calc dist y x \u2264 dist y z + dist z x : dist_triangle _ _ _\n  ... < \u03b5 + \u03b4 :  add_lt_add hz' hz\nend\n\nlemma inf_dist_pos_iff_not_mem_closure {x : \u03b1} {s : set \u03b1} (hs : s.nonempty) :\n  0 < inf_dist x s \u2194 x \u2209 closure s :=\nby rw [is_closed_closure.not_mem_iff_inf_dist_pos hs.closure, inf_dist_eq_closure]\n\nend metric\nopen metric\n\nlemma is_compact.exists_thickening_image {f : \u03b1 \u2192 \u03b2} {K : set \u03b1} {U : set \u03b2}\n  (hK : is_compact K) (ho : is_open U) (hf : continuous f) (hKU : maps_to f K U) :\n  \u2203 (\u03b5 > 0) (V \u2208 \ud835\udcdd\u02e2 K), thickening \u03b5 (f '' V) \u2286 U :=\nbegin\n  rcases (hK.image hf).exists_thickening_subset_open ho hKU.image_subset with \u27e8r, hr\u2080, hr\u27e9,\n  refine \u27e8r / 2, half_pos hr\u2080, f \u207b\u00b9' (thickening (r / 2) (f '' K)),\n    (is_open_thickening.preimage hf).mem_nhds_set.2 $ image_subset_iff.mp $\n      self_subset_thickening (half_pos hr\u2080) _, _\u27e9,\n  calc thickening (r / 2) (f '' (f \u207b\u00b9' thickening (r / 2) (f '' K)))\n     \u2286 thickening (r / 2) (thickening (r / 2) (f '' K)) :\n    thickening_subset_of_subset _ (image_preimage_subset _ _)\n  ... \u2286 thickening (r / 2 + r / 2) (f '' K) : thickening_thickening_subset _ _ _\n  ... = thickening r (f '' K) : by rw [add_halves]\n  ... \u2286 U : hr\nend\n", "meta": {"author": "leanprover-community", "repo": "sphere-eversion", "sha": "324e02c1509db6177cf363618f6ac5be343ce2f5", "save_path": "github-repos/lean/leanprover-community-sphere-eversion", "path": "github-repos/lean/leanprover-community-sphere-eversion/sphere-eversion-324e02c1509db6177cf363618f6ac5be343ce2f5/src/to_mathlib/topology/hausdorff_distance.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029118, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7033123897689066}}
{"text": "import tactic\nimport data.fintype.card\n\n/-!\n# Bits, Binary Words, and Binary Word Matrices\n\nThis file contains definitions of bits `B`, binary words `BW`, \nand binary word matrices `BWM`.\n\n## Notation\n\n- `O` and `I` for bits 0 and 1.\n- `::\u1d2e` for the cons constructor for binary words.\n- `\u1d2e[]` for writing binary words as lists of bits.\n- `::\u1d39` for the cons contructor for binary word matrices. \n- `\u1d39[]` for writing binary word matrices as lists of binary words.\n-/\n\n@[derive decidable_eq]\ninductive B : Type\n| O : B\n| I : B\n\nnamespace B\n\ninstance : fintype B := \n{\n  elems := {O, I},\n  complete := by {intro x, simp, cases x, {left, refl}, {right, refl}} \n}\n@[simp]\nlemma card_b : fintype.card B = 2 := rfl\n\ndef repr : B \u2192 string\n| O := \"0\"\n| I := \"1\"\ninstance : has_repr B := \u27e8repr\u27e9\n\n@[simp]\nlemma O_ne_I : O = I \u2192 false :=\n\u03bb h, by contradiction\n@[simp]\nlemma I_ne_O : I = O \u2192 false :=\n\u03bb h, by contradiction\n\ndef add : B \u2192 B \u2192 B\n| I I := O\n| O x := x\n| x O := x\n\ndef mul : B \u2192 B \u2192 B\n| I I := I\n| _ _ := O\n\ninstance : field B := \n{\n  add := add,\n  add_assoc := \u03bb a b c, by {cases a; cases b; cases c; refl},\n  zero := O,\n  zero_add := \u03bb a, by {cases a; refl},\n  add_zero := \u03bb a, by {cases a; refl},\n  neg := \u03bb x, x,\n  sub := \u03bb x, add x,\n  sub_eq_add_neg := \u03bb a b, rfl,\n  add_left_neg := \u03bb a, by {cases a; refl},\n  add_comm := \u03bb a b, by {cases a; cases b; refl},\n  mul := mul,\n  mul_assoc := \u03bb a b c, by {cases a; cases b; cases c; refl},\n  one := I,\n  one_mul := \u03bb a, by {cases a; refl},\n  mul_one := \u03bb a, by {cases a; refl},\n  left_distrib :=  \u03bb a b c, by {cases a; cases b; cases c; refl},\n  right_distrib :=  \u03bb a b c, by {cases a; cases b; cases c; refl},\n  mul_comm :=  \u03bb a b, by {cases a; cases b; refl},\n  inv := \u03bb x, x,\n  exists_pair_ne := \u27e8O, \u27e8I, O_ne_I\u27e9\u27e9,\n  mul_inv_cancel := begin\n    intros a h,\n    cases a,\n      {contradiction},\n      {refl}\n  end,\n  inv_zero := rfl,\n}\n\ndef flip : B \u2192 B\n| O := I\n| I := O\n\ndef to_nat : B \u2192 \u2115\n| O := 0\n| I := 1\n\nend B\n\n@[derive decidable_eq]\ninductive BW : \u2115 \u2192 Type\n| nil : BW 0\n| cons {n : \u2115} (b : B) (bw : BW n) : BW (n + 1)\n\nnamespace BW\nopen B\n\nnotation h `::\u1d2e` t := cons h t\nnotation `\u1d2e[` bw:(foldr `,` (h t, cons h t) nil) `]` := bw\n\ndef repr : \u03a0 {n : \u2115}, BW n \u2192 string\n| _   nil         := \"\"\n| _   (hd ::\u1d2e tl)  := hd.repr ++ (repr tl)\ninstance {n : \u2115} : has_repr (BW n) := \u27e8BW.repr\u27e9\n\ndef length : \u03a0 {n : \u2115}, BW n \u2192 \u2115\n| n _ := n\n\n@[simp]\nlemma nil_unique (x : BW 0) : x = BW.nil := by {cases x; refl}\n\nprivate\ndef reverse' : \u03a0 {n i : \u2115}, BW n \u2192 BW i \u2192 BW (n + i)\n| 0 i nil acc := by {simp, exact acc}\n| (m+1) i (hd::\u1d2etl) acc := by {rw nat.add_assoc, rw nat.one_add, apply reverse' tl (hd::\u1d2eacc)}\n\ndef reverse : \u03a0 {n : \u2115}, BW n \u2192 BW n := \u03bb (n : \u2115) (bwn : BW (n - 0)), reverse' bwn nil\n\ndef add : \u03a0 {n : \u2115}, BW n \u2192 BW n \u2192 BW n\n| _ nil nil := nil\n| _ (hd\u2081::\u1d2etl\u2081) (hd\u2082::\u1d2etl\u2082) := (hd\u2081 + hd\u2082) ::\u1d2e (add tl\u2081 tl\u2082)\n\ndef intersection : \u03a0 {n : \u2115}, BW n \u2192 BW n \u2192 BW n\n| _ nil nil := nil\n| _ (hd\u2081::\u1d2etl\u2081) (hd\u2082::\u1d2etl\u2082) := (hd\u2081 * hd\u2082) ::\u1d2e (intersection tl\u2081 tl\u2082)\n\nnotation bw\u2081 `\u2229` bw\u2082 := intersection bw\u2081 bw\u2082\n\ndef dot_product :  \u03a0 {n : \u2115}, BW n \u2192 BW n \u2192 B\n| _ nil         nil        := O\n| _ (hd\u2081::\u1d2etl\u2081) (hd\u2082::\u1d2etl\u2082) := (hd\u2081 * hd\u2082) + (dot_product tl\u2081 tl\u2082)\n\nnotation bw\u2081 `\u2b1d` bw\u2082 := dot_product bw\u2081 bw\u2082\n\n\ndef zero : \u03a0 (n : \u2115), BW n\n| 0       := nil\n| (m + 1) := O ::\u1d2e zero m\n\n\ndef to_nat : \u03a0 {n : \u2115}, BW n \u2192 \u2115\n| _     nil       := 0\n| (m+1) (hd::\u1d2etl) := (hd.to_nat * 2 ^ m) + tl.to_nat\n\n-- This function is no longer used, but kept here for reference.\ndef flip : \u03a0 {n : \u2115} (i : \u2115), i \u2264 n \u2192 BW n \u2192 BW n\n| _ _     _ nil       := nil\n| _ 0     _ (hd::\u1d2etl) := hd ::\u1d2e tl\n| _ 1     _ (hd::\u1d2etl) := hd.flip ::\u1d2e tl\n| _ (i+1) h (hd::\u1d2etl) := hd ::\u1d2e (flip i (nat.le_of_succ_le_succ h) tl)\n\n@[simp]\nlemma add_hds {n : \u2115} (hd\u2081 hd\u2082 : B) (tl\u2081 tl\u2082 : BW n) : \n  add (hd\u2081::\u1d2etl\u2081) (hd\u2082::\u1d2etl\u2082) = ((hd\u2081 + hd\u2082)::\u1d2e(add tl\u2081 tl\u2082)) :=\nrfl\n\ninstance : \u03a0 {n : \u2115}, add_comm_group (BW n) := \n\u03bb n, {\n  add := add,\n  add_assoc := begin\n    intros a b c,\n    induction a with m hda tla ih,\n      {rw nil_unique b, rw nil_unique c, refl},\n    cases b with _ hdb tlb,\n    cases c with _ hdc tlc,\n    simp,\n    split,\n      {conv {to_lhs, apply_congr add_assoc}},\n      {simp at ih, apply ih}\n  end,\n  zero := zero n,\n  zero_add := begin\n    intro a, \n    induction a with m hda tla ih,\n      {refl},\n    simp at *, rw zero,\n    cases hda;\n      {conv {to_lhs, apply_congr add_hds}, conv {to_lhs, congr, {whnf}, {apply_congr ih}}},\n  end,\n  add_zero := begin\n    intro a, \n    induction a with m hda tla ih,\n      {refl},\n    simp at *, rw zero,\n    cases hda;\n      {conv {to_lhs, apply_congr add_hds}, conv {to_lhs, congr, {whnf}, {apply_congr ih}}},\n  end,\n  neg := \u03bb x, x,\n  sub := \u03bb x, add x,\n  sub_eq_add_neg := \u03bb x y, rfl,\n  add_left_neg := begin\n    intro a,\n    induction a with m hda tla ih,\n      {refl},\n    conv {to_lhs, apply_congr add_hds},\n    conv {to_lhs, congr, skip, apply_congr ih},\n    cases hda; refl,\n  end,\n  add_comm := begin\n    intros a b,\n    induction a with m hda tla ih,\n      {rw nil_unique b,},\n    cases b with _ hdb tlb,\n    cases hda; cases hdb;\n    {conv {to_lhs, apply_congr add_hds},\n    conv {to_lhs, congr, {whnf}, {apply_congr ih}},\n    conv {to_rhs, apply_congr add_hds},\n    conv {to_rhs, congr, {whnf}},\n    refl}\n  end,\n}\n\ndef smul : \u03a0 {n : \u2115}, B \u2192 BW n \u2192 BW n\n| _ _ nil := nil\n| _ b (hd::\u1d2etl) := (b * hd)::\u1d2e(smul b tl)\n\ninstance : \u03a0 {n : \u2115}, vector_space B (BW n) :=\n\u03bb n, {\n  smul := smul,\n  one_smul := begin\n    intro b,\n    induction b with m hdb tlb ih,\n      {refl},\n    simp, rw smul,\n    conv {to_lhs, congr, skip, apply_congr ih},\n    cases hdb; refl,\n  end,\n  mul_smul := begin\n    intros x y b,\n    induction b with m hdb tlb ih,\n      {refl},\n    simp, rw smul,\n    conv {to_lhs, congr, skip, apply_congr ih},\n    cases x; cases y; cases hdb; refl,\n  end,\n  smul_add := begin\n    intros r x y,\n    induction y with m hdy tly ih,\n      {rw nil_unique x, refl},\n    cases x with _ hdx tlx,\n    simp,\n    conv {to_lhs, congr, skip, apply_congr add_hds},\n    rw smul,\n    conv {to_lhs, congr, skip, apply_congr ih},\n    cases r; cases hdx; cases hdy; refl,\n  end,\n  smul_zero := begin\n    intro r,\n    simp,\n    induction n with m ih,\n      {refl},\n    conv {to_lhs, whnf, congr, skip, apply_congr ih},\n    cases r; refl,\n  end,\n  add_smul := begin\n    intros r s x,\n    induction x with m hdx tlx ih,\n      {refl},\n    simp, rw smul,\n    conv {to_lhs, congr, skip, apply_congr ih},\n    cases r; cases s; cases hdx; refl,\n  end,\n  zero_smul := begin\n    intro x,\n    induction x with m hdx tlx ih,\n      {refl},\n    simp, rw smul,\n    conv {to_lhs, congr, skip, apply_congr ih},\n    cases hdx; refl,\n  end,\n}\n\n/-! \nThe remainder of this section establishes various equivalences between `BW n` and `vector B n`.\nWe use these equivalences to establish `fintype (BW n)` and `fintype.card (BW n) = 2 ^ n`.\n-/\n\ndef vector_to_bw : \u03a0 {n : \u2115}, vector B n \u2192 BW n\n| 0     \u27e8[],     _\u27e9 := nil\n| (n+1) \u27e8hd::tl, h\u27e9 := cons hd (vector_to_bw \u27e8tl, by {simp at h, exact h}\u27e9)\n\nlemma vector_to_bw_injective : \u03a0 {n : \u2115}, function.injective (@vector_to_bw n) :=\nbegin\n  intros n x y h,\n  induction n with k ih,\n    {simp},\n  cases x with xl hx,\n  cases xl with xhd xtl,\n    {simp at hx, contradiction},\n  cases y with yl hy,\n  cases yl with yhd ytl,\n    {simp at hy, contradiction},\n  repeat {rw vector_to_bw at h}, \n  simp at h, cases h with h_left h_right, rw h_left,\n  simp, specialize ih h_right, simp at ih, exact ih,\nend\n\nlemma vector_to_bw_surjective : \u03a0 {n : \u2115}, function.surjective (@vector_to_bw n) :=\nbegin\n  intros n b,\n  induction n with k ih,\n    {use vector.nil, rw nil_unique b, refl},\n  cases b with _ bhd btl,\n  specialize ih btl,\n  cases ih with a_ih ih,\n  cases a_ih with al_ih h_a_ih,\n  have : (bhd::al_ih).length = k.succ, by {rw list.length_cons, rw h_a_ih},\n  use \u27e8bhd::al_ih, this\u27e9,\n  rw vector_to_bw, simp, exact ih,\nend\n\nlemma vector_to_bw_bijective : \u03a0 {n : \u2115}, function.bijective (@vector_to_bw n) :=\n\u03bb n, \u27e8vector_to_bw_injective, vector_to_bw_surjective\u27e9\n\ninstance : \u03a0 {n : \u2115}, fintype (BW n) :=\n\u03bb n, fintype.of_bijective vector_to_bw vector_to_bw_bijective\n\ndef bw_to_vector : \u03a0 {n : \u2115}, BW n \u2192 vector B n\n| 0     nil       := vector.nil\n| (n+1) (hd::\u1d2etl) := hd ::\u1d65 bw_to_vector tl\n\ndef bw_to_vector_inv : \u03a0 {n : \u2115}, vector B n \u2192 BW n\n| 0     _ := nil\n| (n+1) v := (vector.head v) ::\u1d2e (bw_to_vector_inv (vector.tail v))\n\nlemma left_inv : \n  \u03a0 {n : \u2115} (x : BW n), bw_to_vector_inv (bw_to_vector x) = x\n| 0     nil       := by rw [bw_to_vector, bw_to_vector_inv]\n| (n+1) (hd::\u1d2etl) := by {rw [bw_to_vector, bw_to_vector_inv], simp, exact left_inv tl}\n\nlemma right_inv :\n  \u03a0 {n : \u2115} (x : vector B n), bw_to_vector (bw_to_vector_inv x) = x\n| 0     v := by rw [bw_to_vector_inv, bw_to_vector, vector.eq_nil v]\n| (n+1) v := by rw [bw_to_vector_inv, bw_to_vector, right_inv v.tail, vector.cons_head_tail]\n\ndef vector_bw_equiv : \u03a0 {n : \u2115}, equiv (BW n) (vector B n) :=\n\u03bb n, \n{\n  to_fun := bw_to_vector,\n  inv_fun := bw_to_vector_inv,\n  left_inv := left_inv,\n  right_inv := right_inv,\n}\n\nlemma card_bw_eq_card_vector {n : \u2115} : fintype.card (BW n) = fintype.card (vector B n) :=\nby {apply fintype.card_congr, exact vector_bw_equiv}\n\n@[simp]\nlemma card_bw {n : \u2115} : fintype.card (BW n) = 2 ^ n :=\nby {rw card_bw_eq_card_vector, simp}\n\nend BW\n\n\ninductive BWM (n : \u2115) : \u2115 \u2192 Type\n| nil : BWM nat.zero\n| cons {m : \u2115} (bw : BW n) (bwm : BWM m) : BWM m.succ\n\nnamespace BWM\n\nnotation h`::\u1d39` t := cons h t\nnotation `\u1d39[` bwm:(foldr `,` (h t, cons h t) nil) `]` := bwm\n\ndef repr : \u03a0 {n m : \u2115}, BWM n m \u2192 string\n| _ _ nil       := \"\"\n| _ _ (hd ::\u1d39 tl) := hd.repr ++ \"\\n\" ++ (repr tl)\ninstance {n m : \u2115} : has_repr (BWM n m) := \u27e8BWM.repr\u27e9\n\ndef length : \u03a0 {n m : \u2115}, BWM n m \u2192 \u2115\n| n _ _ := n\n\ndef size : \u03a0 {n m : \u2115}, BWM n m \u2192 \u2115\n| _ m _ := m\n\ndef r_mul : \u03a0 {n m : \u2115}, BWM n m \u2192 BW n \u2192 BW m\n| _ 0 nil         _  := BW.nil\n| n m (hd ::\u1d39 tl) bw := (hd \u2b1d bw) ::\u1d2e (r_mul tl bw)\n\nnotation bwm `\u00d7` bw := r_mul bwm bw\n\nend BWM", "meta": {"author": "GeorgeTillisch", "repo": "coding_theory_lean", "sha": "920e14b433080854d4248714c93a09ce4e391522", "save_path": "github-repos/lean/GeorgeTillisch-coding_theory_lean", "path": "github-repos/lean/GeorgeTillisch-coding_theory_lean/coding_theory_lean-920e14b433080854d4248714c93a09ce4e391522/src/binary.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7033123793328762}}
{"text": "/-\nCopyright (c) 2022 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\n\nimport algebra.associated\nimport data.int.units\n\n/-!\n# Associated elements and the integers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains some results on equality up to units in the integers.\n\n## Main results\n\n * `int.nat_abs_eq_iff_associated`: the absolute value is equal iff integers are associated\n-/\n\nlemma int.nat_abs_eq_iff_associated {a b : \u2124} :\n  a.nat_abs = b.nat_abs \u2194 associated a b :=\nbegin\n  refine int.nat_abs_eq_nat_abs_iff.trans _,\n  split,\n  { rintro (rfl | rfl),\n    { refl },\n    { exact \u27e8-1, by simp\u27e9 } },\n  { rintro \u27e8u, rfl\u27e9,\n    obtain (rfl | rfl) := int.units_eq_one_or u,\n    { exact or.inl (by simp) },\n    { exact or.inr (by simp) } }\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/int/associated.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7033123621495307}}
{"text": "/-\nCopyright (c) 2018 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel, Mario Carneiro\n\nType of bounded continuous functions taking values in a metric space, with\nthe uniform distance.\n -/\n\nimport analysis.normed_space.basic topology.metric_space.cau_seq_filter\n       topology.metric_space.lipschitz topology.instances.real\n\nnoncomputable theory\nlocal attribute [instance] classical.decidable_inhabited classical.prop_decidable\n\nopen set lattice filter metric\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\n/-- A locally uniform limit of continuous functions is continuous -/\nlemma continuous_of_locally_uniform_limit_of_continuous [topological_space \u03b1] [metric_space \u03b2]\n  {F : \u2115 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (L : \u2200x:\u03b1, \u2203s \u2208 nhds x, \u2200\u03b5>(0:\u211d), \u2203n, \u2200y\u2208s, dist (F n y) (f y) \u2264 \u03b5)\n  (C : \u2200 n, continuous (F n)) : continuous f :=\ncontinuous_iff'.2 $ \u03bb x \u03b5 \u03b50, begin\n  rcases L x with \u27e8r, rx, hr\u27e9,\n  rcases hr (\u03b5/2/2) (half_pos $ half_pos \u03b50) with \u27e8n, hn\u27e9,\n  rcases continuous_iff'.1 (C n) x (\u03b5/2) (half_pos \u03b50) with \u27e8s, sx, hs\u27e9,\n  refine \u27e8_, (nhds x).inter_sets rx sx, _\u27e9,\n  rintro y \u27e8yr, ys\u27e9,\n  calc dist (f y) (f x)\n        \u2264 dist (F n y) (F n x) + (dist (F n y) (f y) + dist (F n x) (f x)) : dist_triangle4_left _ _ _ _\n    ... < \u03b5/2 + (\u03b5/2/2 + \u03b5/2/2) :\n      add_lt_add_of_lt_of_le (hs _ ys) (add_le_add (hn _ yr) (hn _ (mem_of_nhds rx)))\n    ... = \u03b5 : by rw [add_halves, add_halves]\nend\n\n/-- A uniform limit of continuous functions is continuous -/\nlemma continuous_of_uniform_limit_of_continuous [topological_space \u03b1] {\u03b2 : Type v} [metric_space \u03b2]\n  {F : \u2115 \u2192 \u03b1 \u2192 \u03b2} {f : \u03b1 \u2192 \u03b2} (L : \u2200\u03b5>(0:\u211d), \u2203N, \u2200y, dist (F N y) (f y) \u2264 \u03b5) :\n  (\u2200 n, continuous (F n)) \u2192 continuous f :=\ncontinuous_of_locally_uniform_limit_of_continuous $ \u03bbx,\n  \u27e8univ, by simpa [filter.univ_mem_sets] using L\u27e9\n\n/-- The type of bounded continuous functions from a topological space to a metric space -/\ndef bounded_continuous_function (\u03b1 : Type u) (\u03b2 : Type v) [topological_space \u03b1] [metric_space \u03b2] : Type (max u v) :=\n{f : \u03b1 \u2192 \u03b2 // continuous f \u2227 \u2203C, \u2200x y:\u03b1, dist (f x) (f y) \u2264 C}\n\nlocal infixr ` \u2192\u1d47 `:25 := bounded_continuous_function\n\nnamespace bounded_continuous_function\nsection basics\nvariables [topological_space \u03b1] [metric_space \u03b2] [metric_space \u03b3]\nvariables {f g : \u03b1 \u2192\u1d47 \u03b2} {x : \u03b1} {C : \u211d}\n\ninstance : has_coe_to_fun (\u03b1 \u2192\u1d47 \u03b2) :=  \u27e8_, subtype.val\u27e9\n\nlemma bounded_range : bounded (range f) :=\nbounded_range_iff.2 f.2.2\n\n/-- If a function is continuous on a compact space, it is automatically bounded,\nand therefore gives rise to an element of the type of bounded continuous functions -/\ndef mk_of_compact [compact_space \u03b1] (f : \u03b1 \u2192 \u03b2) (hf : continuous f) : \u03b1 \u2192\u1d47 \u03b2 :=\n\u27e8f, hf, bounded_range_iff.1 $ by rw \u2190 image_univ; exact\n  bounded_of_compact (compact_image compact_univ hf)\u27e9\n\n/-- If a function is bounded on a discrete space, it is automatically continuous,\nand therefore gives rise to an element of the type of bounded continuous functions -/\ndef mk_of_discrete [discrete_topology \u03b1] (f : \u03b1 \u2192 \u03b2) (hf : \u2203C, \u2200x y, dist (f x) (f y) \u2264 C) :\n  \u03b1 \u2192\u1d47 \u03b2 :=\n\u27e8f, continuous_of_discrete_topology, hf\u27e9\n\n/-- The uniform distance between two bounded continuous functions -/\ninstance : has_dist (\u03b1 \u2192\u1d47 \u03b2) :=\n\u27e8\u03bbf g, Inf {C | C \u2265 0 \u2227 \u2200 x : \u03b1, dist (f x) (g x) \u2264 C}\u27e9\n\nlemma dist_eq : dist f g = Inf {C | C \u2265 0 \u2227 \u2200 x : \u03b1, dist (f x) (g x) \u2264 C} := rfl\n\nlemma dist_set_exists : \u2203 C, C \u2265 0 \u2227 \u2200 x : \u03b1, dist (f x) (g x) \u2264 C :=\nbegin\n  refine if h : nonempty \u03b1 then _ else \u27e80, le_refl _, \u03bb x, h.elim \u27e8x\u27e9\u27e9,\n  cases h with x,\n  rcases f.2 with \u27e8_, Cf, hCf\u27e9, /- hCf : \u2200 (x y : \u03b1), dist (f.val x) (f.val y) \u2264 Cf -/\n  rcases g.2 with \u27e8_, Cg, hCg\u27e9, /- hCg : \u2200 (x y : \u03b1), dist (g.val x) (g.val y) \u2264 Cg -/\n  let C := max 0 (dist (f x) (g x) + (Cf + Cg)),\n  exact \u27e8C, le_max_left _ _, \u03bb y, calc\n    dist (f y) (g y) \u2264 dist (f x) (g x) + (dist (f x) (f y) + dist (g x) (g y)) : dist_triangle4_left _ _ _ _\n                ... \u2264 dist (f x) (g x) + (Cf + Cg) : add_le_add_left (add_le_add (hCf _ _) (hCg _ _)) _\n                ... \u2264 C : le_max_right _ _\u27e9\nend\n\n/-- The pointwise distance is controlled by the distance between functions, by definition -/\nlemma dist_coe_le_dist (x : \u03b1) : dist (f x) (g x) \u2264 dist f g :=\nle_cInf (ne_empty_iff_exists_mem.2 dist_set_exists) $ \u03bbb hb, hb.2 x\n\n@[extensionality] lemma ext (H : \u2200x, f x = g x) : f = g :=\nsubtype.eq $ by ext; apply H\n\n/- This lemma will be needed in the proof of the metric space instance, but it will become\nuseless afterwards as it will be superceded by the general result that the distance is nonnegative\nis metric spaces. -/\nprivate lemma dist_nonneg' : 0 \u2264 dist f g :=\nle_cInf (ne_empty_iff_exists_mem.2 dist_set_exists) (\u03bb C, and.left)\n\n/-- The distance between two functions is controlled by the supremum of the pointwise distances -/\nlemma dist_le (C0 : (0 : \u211d) \u2264 C) : dist f g \u2264 C \u2194 \u2200x:\u03b1, dist (f x) (g x) \u2264 C :=\n\u27e8\u03bb h x, le_trans (dist_coe_le_dist x) h, \u03bb H, cInf_le \u27e80, \u03bb C, and.left\u27e9 \u27e8C0, H\u27e9\u27e9\n\n/-- On an empty space, bounded continuous functions are at distance 0 -/\nlemma dist_zero_of_empty (e : \u00ac nonempty \u03b1) : dist f g = 0 :=\nle_antisymm ((dist_le (le_refl _)).2 $ \u03bb x, e.elim \u27e8x\u27e9) dist_nonneg'\n\n/-- The type of bounded continuous functions, with the uniform distance, is a metric space. -/\ninstance : metric_space (\u03b1 \u2192\u1d47 \u03b2) :=\n{ dist_self := \u03bb f, le_antisymm ((dist_le (le_refl _)).2 $ \u03bb x, by simp) dist_nonneg',\n  eq_of_dist_eq_zero := \u03bb f g hfg, by ext x; exact\n    eq_of_dist_eq_zero (le_antisymm (hfg \u25b8 dist_coe_le_dist _) dist_nonneg),\n  dist_comm := \u03bb f g, by simp [dist_eq, dist_comm],\n  dist_triangle := \u03bb f g h,\n    (dist_le (add_nonneg dist_nonneg' dist_nonneg')).2 $ \u03bb x,\n      le_trans (dist_triangle _ _ _) (add_le_add (dist_coe_le_dist _) (dist_coe_le_dist _)) }\n\ndef const (b : \u03b2) : \u03b1 \u2192\u1d47 \u03b2 := \u27e8\u03bbx, b, continuous_const, 0, by simp [le_refl]\u27e9\n\n/-- If the target space is inhabited, so is the space of bounded continuous functions -/\ninstance [inhabited \u03b2] : inhabited (\u03b1 \u2192\u1d47 \u03b2) := \u27e8const (default \u03b2)\u27e9\n\n/-- The evaluation map is continuous, as a joint function of `u` and `x` -/\ntheorem continuous_eval : continuous (\u03bb p : (\u03b1 \u2192\u1d47 \u03b2) \u00d7 \u03b1, p.1 p.2) :=\ncontinuous_iff'.2 $ \u03bb \u27e8f, x\u27e9 \u03b5 \u03b50,\n/- use the continuity of `f` to find a neighborhood of `x` where it varies at most by \u03b5/2 -/\nlet \u27e8s, sx, Hs\u27e9 := continuous_iff'.1 f.2.1 x (\u03b5/2) (half_pos \u03b50) in\n/- s : set \u03b1, sx : s \u2208 nhds x, Hs : \u2200 (b : \u03b1), b \u2208 s \u2192 dist (f.val b) (f.val x) < \u03b5 / 2 -/\n\u27e8set.prod (ball f (\u03b5/2)) s, prod_mem_nhds_sets (ball_mem_nhds _ (half_pos \u03b50)) sx,\n\u03bb \u27e8g, y\u27e9 \u27e8hg, hy\u27e9, calc dist (g y) (f x)\n      \u2264 dist (g y) (f y) + dist (f y) (f x) : dist_triangle _ _ _\n  ... < \u03b5/2 + \u03b5/2 : add_lt_add (lt_of_le_of_lt (dist_coe_le_dist _) hg) (Hs _ hy)\n  ... = \u03b5 : add_halves _\u27e9\n\n/-- In particular, when `x` is fixed, `f \u2192 f x` is continuous -/\ntheorem continuous_evalx {x : \u03b1} : continuous (\u03bb f : \u03b1 \u2192\u1d47 \u03b2, f x) :=\n(continuous_id.prod_mk continuous_const).comp continuous_eval\n\n/-- When `f` is fixed, `x \u2192 f x` is also continuous, by definition -/\ntheorem continuous_evalf {f : \u03b1 \u2192\u1d47 \u03b2} : continuous f := f.2.1\n\n/-- Bounded continuous functions taking values in a complete space form a complete space. -/\ninstance [complete_space \u03b2] : complete_space (\u03b1 \u2192\u1d47 \u03b2) :=\ncomplete_of_cauchy_seq_tendsto $ \u03bb (f : \u2115 \u2192 \u03b1 \u2192\u1d47 \u03b2) (hf : cauchy_seq f),\nbegin\n  /- We have to show that `f n` converges to a bounded continuous function.\n  For this, we prove pointwise convergence to define the limit, then check\n  it is a continuous bounded function, and then check the norm convergence. -/\n  rcases cauchy_seq_iff_le_tendsto_0.1 hf with \u27e8b, b0, b_bound, b_lim\u27e9,\n  have f_bdd := \u03bbx n m N hn hm, le_trans (dist_coe_le_dist x) (b_bound n m N hn hm),\n  have fx_cau : \u2200x, cauchy_seq (\u03bbn, f n x) :=\n    \u03bbx, cauchy_seq_iff_le_tendsto_0.2 \u27e8b, b0, f_bdd x, b_lim\u27e9,\n  choose F hF using \u03bbx, cauchy_seq_tendsto_of_complete (fx_cau x),\n  /- F : \u03b1 \u2192 \u03b2,  hF : \u2200 (x : \u03b1), tendsto (\u03bb (n : \u2115), f n x) at_top (nhds (F x))\n  `F` is the desired limit function. Check that it is uniformly approximated by `f N` -/\n  have fF_bdd : \u2200x N, dist (f N x) (F x) \u2264 b N :=\n    \u03bb x N, le_of_tendsto (by simp)\n      (tendsto_dist tendsto_const_nhds (hF x))\n      (filter.mem_at_top_sets.2 \u27e8N, \u03bbn hn, f_bdd x N n N (le_refl N) hn\u27e9),\n  refine \u27e8\u27e8F, _, _\u27e9, _\u27e9,\n  { /- Check that `F` is continuous -/\n    refine continuous_of_uniform_limit_of_continuous (\u03bb \u03b5 \u03b50, _) (\u03bbN, (f N).2.1),\n    rcases metric.tendsto_at_top.1 b_lim \u03b5 \u03b50 with \u27e8N, hN\u27e9,\n    exact \u27e8N, \u03bby, calc\n      dist (f N y) (F y) \u2264 b N : fF_bdd y N\n      ... \u2264 dist (b N) 0 : begin simp, show b N \u2264 abs(b N), from le_abs_self _ end\n      ... \u2264 \u03b5 : le_of_lt (hN N (le_refl N))\u27e9 },\n  { /- Check that `F` is bounded -/\n    rcases (f 0).2.2 with \u27e8C, hC\u27e9,\n    exact \u27e8C + (b 0 + b 0), \u03bb x y, calc\n      dist (F x) (F y) \u2264 dist (f 0 x) (f 0 y) + (dist (f 0 x) (F x) + dist (f 0 y) (F y)) : dist_triangle4_left _ _ _ _\n         ... \u2264 C + (b 0 + b 0) : add_le_add (hC x y) (add_le_add (fF_bdd x 0) (fF_bdd y 0))\u27e9 },\n  { /- Check that `F` is close to `f N` in distance terms -/\n    refine tendsto_iff_dist_tendsto_zero.2 (squeeze_zero (\u03bb _, dist_nonneg) _ b_lim),\n    exact \u03bb N, (dist_le (b0 _)).2 (\u03bbx, fF_bdd x N) }\nend\n\n/-- Composition (in the target) of a bounded continuous function with a Lipschitz map again\ngives a bounded continuous function -/\ndef comp (G : \u03b2 \u2192 \u03b3) (H : \u2200x y, dist (G x) (G y) \u2264 C * dist x y)\n  (f : \u03b1 \u2192\u1d47 \u03b2) : \u03b1 \u2192\u1d47 \u03b3 :=\n\u27e8\u03bbx, G (f x), f.2.1.comp (continuous_of_lipschitz H),\n  let \u27e8D, hD\u27e9 := f.2.2 in\n  \u27e8max C 0 * D, \u03bb x y, calc\n    dist (G (f x)) (G (f y)) \u2264 C * dist (f x) (f y) : H _ _\n    ... \u2264 max C 0 * dist (f x) (f y) : mul_le_mul_of_nonneg_right (le_max_left C 0) dist_nonneg\n    ... \u2264 max C 0 * D : mul_le_mul_of_nonneg_left (hD _ _) (le_max_right C 0)\u27e9\u27e9\n\n/-- The composition operator (in the target) with a Lipschitz map is continuous -/\nlemma continuous_comp {G : \u03b2 \u2192 \u03b3} (H : \u2200x y, dist (G x) (G y) \u2264 C * dist x y) :\n  continuous (comp G H : (\u03b1 \u2192\u1d47 \u03b2) \u2192 \u03b1 \u2192\u1d47 \u03b3) :=\ncontinuous_of_lipschitz $ \u03bb f g,\n(dist_le (mul_nonneg (le_max_right C 0) dist_nonneg)).2 $ \u03bb x,\ncalc dist (G (f x)) (G (g x)) \u2264 C * dist (f x) (g x) : H _ _\n  ... \u2264 max C 0 * dist (f x) (g x) : mul_le_mul_of_nonneg_right (le_max_left C 0) (dist_nonneg)\n  ... \u2264 max C 0 * dist f g : mul_le_mul_of_nonneg_left (dist_coe_le_dist _) (le_max_right C 0)\n\n/-- Restriction (in the target) of a bounded continuous function taking values in a subset -/\ndef cod_restrict (s : set \u03b2) (f : \u03b1 \u2192\u1d47 \u03b2) (H : \u2200x, f x \u2208 s) : \u03b1 \u2192\u1d47 s :=\n\u27e8\u03bbx, \u27e8f x, H x\u27e9, continuous_subtype_mk _ f.2.1, f.2.2\u27e9\n\nend basics\n\nsection arzela_ascoli\nvariables [topological_space \u03b1] [compact_space \u03b1] [metric_space \u03b2]\nvariables {f g : \u03b1 \u2192\u1d47 \u03b2} {x : \u03b1} {C : \u211d}\n\n/- Arzela-Ascoli theorem asserts that, on a compact space, a set of functions sharing\na common modulus of continuity and taking values in a compact set forms a compact\nsubset for the topology of uniform convergence. In this section, we prove this theorem\nand several useful variations around it. -/\n\n/-- First version, with pointwise equicontinuity and range in a compact space -/\ntheorem arzela_ascoli\u2081 [compact_space \u03b2]\n  (A : set (\u03b1 \u2192\u1d47 \u03b2))\n  (closed : is_closed A)\n  (H : \u2200 (x:\u03b1) (\u03b5 > 0), \u2203U \u2208 nhds x, \u2200 (y z \u2208 U) (f : \u03b1 \u2192\u1d47 \u03b2),\n    f \u2208 A \u2192 dist (f y) (f z) < \u03b5) :\n  compact A :=\nbegin\n  refine compact_of_totally_bounded_is_closed _ closed,\n  refine totally_bounded_of_finite_discretization (\u03bb \u03b5 \u03b50, _),\n  rcases dense \u03b50 with \u27e8\u03b5\u2081, \u03b5\u20810, \u03b5\u03b5\u2081\u27e9,\n  let \u03b5\u2082 := \u03b5\u2081/2/2,\n  /- We have to find a finite discretization of `u`, i.e., finite information\n  that is sufficient to reconstruct `u` up to \u03b5. This information will be\n  provided by the values of `u` on a sufficiently dense set t\u03b1,\n  slightly translated to fit in a finite \u03b5\u2082-dense set t\u03b2 in the image. Such\n  sets exist by compactness of the source and range. Then, to check that these\n  data determine the function up to \u03b5, one uses the control on the modulus of\n  continuity to extend the closeness on t\u03b1 to closeness everywhere. -/\n  have \u03b5\u20820 : \u03b5\u2082 > 0 := half_pos (half_pos \u03b5\u20810),\n  have : \u2200x:\u03b1, \u2203U, x \u2208 U \u2227 is_open U \u2227 \u2200 (y z \u2208 U) {f : \u03b1 \u2192\u1d47 \u03b2},\n    f \u2208 A \u2192 dist (f y) (f z) < \u03b5\u2082 := \u03bb x,\n      let \u27e8U, nhdsU, hU\u27e9 := H x _ \u03b5\u20820,\n          \u27e8V, VU, openV, xV\u27e9 := mem_nhds_sets_iff.1 nhdsU in\n      \u27e8V, xV, openV, \u03bby z hy hz f hf, hU y z (VU hy) (VU hz) f hf\u27e9,\n  choose U hU using this,\n  /- For all x, the set hU x is an open set containing x on which the elements of A\n  fluctuate by at most \u03b5\u2082.\n  We extract finitely many of these sets that cover the whole space, by compactness -/\n  rcases compact_elim_finite_subcover_image compact_univ\n    (\u03bbx _, (hU x).2.1) (\u03bbx hx, mem_bUnion (mem_univ _) (hU x).1)\n    with \u27e8t\u03b1, _, \u27e8_\u27e9, ht\u03b1\u27e9,\n  /- t\u03b1 : set \u03b1, ht\u03b1 : univ \u2286 \u22c3x \u2208 t\u03b1, U x -/\n  rcases @finite_cover_balls_of_compact \u03b2 _ _ compact_univ _ \u03b5\u20820\n    with \u27e8t\u03b2, _, \u27e8_\u27e9, ht\u03b2\u27e9, resetI,\n  /- t\u03b2 : set \u03b2, ht\u03b2 : univ \u2286 \u22c3y \u2208 t\u03b2, ball y \u03b5\u2082 -/\n  /- Associate to every point `y` in the space a nearby point `F y` in t\u03b2 -/\n  choose F hF using \u03bby, show \u2203z\u2208t\u03b2, dist y z < \u03b5\u2082, by simpa using ht\u03b2 (mem_univ y),\n  /- F : \u03b2 \u2192 \u03b2, hF : \u2200 (y : \u03b2), F y \u2208 t\u03b2 \u2227 dist y (F y) < \u03b5\u2082 -/\n\n  /- Associate to every function a discrete approximation, mapping each point in `t\u03b1`\n  to a point in `t\u03b2` close to its true image by the function. -/\n  refine \u27e8t\u03b1 \u2192 t\u03b2, by apply_instance, \u03bb f a, \u27e8F (f a), (hF (f a)).fst\u27e9, _\u27e9,\n  rintro \u27e8f, hf\u27e9 \u27e8g, hg\u27e9 f_eq_g,\n  /- If two functions have the same approximation, then they are within distance \u03b5 -/\n  refine lt_of_le_of_lt ((dist_le $ le_of_lt \u03b5\u20810).2 (\u03bb x, _)) \u03b5\u03b5\u2081,\n  have : \u2203x', x' \u2208 t\u03b1 \u2227 x \u2208 U x' := mem_bUnion_iff.1 (ht\u03b1 (mem_univ x)),\n  rcases this with \u27e8x', x't\u03b1, hx'\u27e9,\n  refine calc dist (f x) (g x)\n      \u2264 dist (f x) (f x') + dist (g x) (g x') + dist (f x') (g x') : dist_triangle4_right _ _ _ _\n  ... \u2264 \u03b5\u2082 + \u03b5\u2082 + \u03b5\u2081/2 : le_of_lt (add_lt_add (add_lt_add _ _) _)\n  ... = \u03b5\u2081 : by rw [add_halves, add_halves],\n  { exact (hU x').2.2 _ _ hx' ((hU x').1) hf },\n  { exact (hU x').2.2 _ _ hx' ((hU x').1) hg },\n  { have F_f_g : F (f x') = F (g x') :=\n      (congr_arg (\u03bb f:t\u03b1 \u2192 t\u03b2, (f \u27e8x', x't\u03b1\u27e9 : \u03b2)) f_eq_g : _),\n    calc dist (f x') (g x')\n          \u2264 dist (f x') (F (f x')) + dist (g x') (F (f x')) : dist_triangle_right _ _ _\n      ... = dist (f x') (F (f x')) + dist (g x') (F (g x')) : by rw F_f_g\n      ... < \u03b5\u2082 + \u03b5\u2082 : add_lt_add (hF (f x')).snd (hF (g x')).snd\n      ... = \u03b5\u2081/2 : add_halves _ }\nend\n\n/-- Second version, with pointwise equicontinuity and range in a compact subset -/\ntheorem arzela_ascoli\u2082\n  (s : set \u03b2) (hs : compact s)\n  (A : set (\u03b1 \u2192\u1d47 \u03b2))\n  (closed : is_closed A)\n  (in_s : \u2200(f : \u03b1 \u2192\u1d47 \u03b2) (x : \u03b1), f \u2208 A \u2192 f x \u2208 s)\n  (H : \u2200(x:\u03b1) (\u03b5 > 0), \u2203U \u2208 nhds x, \u2200 (y z \u2208 U) (f : \u03b1 \u2192\u1d47 \u03b2),\n    f \u2208 A \u2192 dist (f y) (f z) < \u03b5) :\n  compact A :=\n/- This version is deduced from the previous one by restricting to the compact type in the target,\nusing compactness there and then lifting everything to the original space. -/\nbegin\n  have M : \u2200x y : s, dist (x : \u03b2) y \u2264 1 * dist x y := \u03bb x y, ge_of_eq (one_mul _),\n  let F : (\u03b1 \u2192\u1d47 s) \u2192 \u03b1 \u2192\u1d47 \u03b2 := comp coe M,\n  refine compact_of_is_closed_subset\n    (compact_image (_ : compact (F \u207b\u00b9' A)) (continuous_comp M)) closed (\u03bb f hf, _),\n  { haveI : compact_space s := compact_iff_compact_space.1 hs,\n    refine arzela_ascoli\u2081 _ (continuous_iff_is_closed.1 (continuous_comp M) _ closed)\n      (\u03bb x \u03b5 \u03b50, bex.imp_right (\u03bb U U_nhds hU y z hy hz f hf, _) (H x \u03b5 \u03b50)),\n    calc dist (f y) (f z) = dist (F f y) (F f z) : rfl\n                        ... < \u03b5 : hU y z hy hz (F f) hf },\n  { let g := cod_restrict s f (\u03bbx, in_s f x hf),\n    rw [show f = F g, by ext; refl] at hf \u22a2,\n    exact \u27e8g, hf, rfl\u27e9 }\nend\n\n/-- Third (main) version, with pointwise equicontinuity and range in a compact subset, but\nwithout closedness. The closure is then compact -/\ntheorem arzela_ascoli\n  (s : set \u03b2) (hs : compact s)\n  (A : set (\u03b1 \u2192\u1d47 \u03b2))\n  (in_s : \u2200(f : \u03b1 \u2192\u1d47 \u03b2) (x : \u03b1), f \u2208 A \u2192 f x \u2208 s)\n  (H : \u2200(x:\u03b1) (\u03b5 > 0), \u2203U \u2208 nhds x, \u2200 (y z \u2208 U) (f : \u03b1 \u2192\u1d47 \u03b2),\n    f \u2208 A \u2192 dist (f y) (f z) < \u03b5) :\n  compact (closure A) :=\n/- This version is deduced from the previous one by checking that the closure of A, in\naddition to being closed, still satisfies the properties of compact range and equicontinuity -/\narzela_ascoli\u2082 s hs (closure A) is_closed_closure\n  (\u03bb f x hf, (mem_of_closed' (closed_of_compact _ hs)).2 $ \u03bb \u03b5 \u03b50,\n    let \u27e8g, gA, dist_fg\u27e9 := mem_closure_iff'.1 hf \u03b5 \u03b50 in\n    \u27e8g x, in_s g x gA, lt_of_le_of_lt (dist_coe_le_dist _) dist_fg\u27e9)\n  (\u03bb x \u03b5 \u03b50, show \u2203 U \u2208 nhds x,\n      \u2200 y z \u2208 U, \u2200 (f : \u03b1 \u2192\u1d47 \u03b2), f \u2208 closure A \u2192 dist (f y) (f z) < \u03b5,\n    begin\n      refine bex.imp_right (\u03bb U U_set hU y z hy hz f hf, _) (H x (\u03b5/2) (half_pos \u03b50)),\n      rcases mem_closure_iff'.1 hf (\u03b5/2/2) (half_pos (half_pos \u03b50)) with \u27e8g, gA, dist_fg\u27e9,\n      replace dist_fg := \u03bb x, lt_of_le_of_lt (dist_coe_le_dist x) dist_fg,\n      calc dist (f y) (f z) \u2264 dist (f y) (g y) + dist (f z) (g z) + dist (g y) (g z) : dist_triangle4_right _ _ _ _\n          ... < \u03b5/2/2 + \u03b5/2/2 + \u03b5/2 :\n            add_lt_add (add_lt_add (dist_fg y) (dist_fg z)) (hU y z hy hz g gA)\n          ... = \u03b5 : by rw [add_halves, add_halves]\n    end)\n\n/- To apply the previous theorems, one needs to check the equicontinuity. An important\ninstance is when the source space is a metric space, and there is a fixed modulus of continuity\nfor all the functions in the set A -/\n\nlemma equicontinuous_of_continuity_modulus {\u03b1 : Type u} [metric_space \u03b1]\n  (b : \u211d \u2192 \u211d) (b_lim : tendsto b (nhds 0) (nhds 0))\n  (A : set (\u03b1 \u2192\u1d47 \u03b2))\n  (H : \u2200(x y:\u03b1) (f : \u03b1 \u2192\u1d47 \u03b2), f \u2208 A \u2192 dist (f x) (f y) \u2264 b (dist x y))\n  (x:\u03b1) (\u03b5 : \u211d) (\u03b50 : \u03b5 > 0) : \u2203U \u2208 nhds x, \u2200 (y z \u2208 U) (f : \u03b1 \u2192\u1d47 \u03b2),\n    f \u2208 A \u2192 dist (f y) (f z) < \u03b5 :=\nbegin\n  rcases tendsto_nhds_nhds.1 b_lim \u03b5 \u03b50 with \u27e8\u03b4, \u03b40, h\u03b4\u27e9,\n  refine \u27e8ball x (\u03b4/2), ball_mem_nhds x (half_pos \u03b40), \u03bb y z hy hz f hf, _\u27e9,\n  have : dist y z < \u03b4 := calc\n    dist y z \u2264 dist y x + dist z x : dist_triangle_right _ _ _\n    ... < \u03b4/2 + \u03b4/2 : add_lt_add hy hz\n    ... = \u03b4 : add_halves _,\n  calc\n    dist (f y) (f z) \u2264 b (dist y z) : H y z f hf\n    ... \u2264 abs (b (dist y z)) : le_abs_self _\n    ... = dist (b (dist y z)) 0 : by simp [real.dist_eq]\n    ... < \u03b5 : h\u03b4 (by simpa [real.dist_eq] using this),\nend\n\nend arzela_ascoli\n\nsection normed_group\n/- In this section, if \u03b2 is a normed group, then we show that the space of bounded\ncontinuous functions from \u03b1 to \u03b2 inherits a normed group structure, by using\npointwise operations and checking that they are compatible with the uniform distance. -/\n\nvariables [topological_space \u03b1] [normed_group \u03b2]\nvariables {f g : \u03b1 \u2192\u1d47 \u03b2} {x : \u03b1} {C : \u211d}\n\ninstance : has_zero (\u03b1 \u2192\u1d47 \u03b2) := \u27e8const 0\u27e9\n\n@[simp] lemma coe_zero : (0 : \u03b1 \u2192\u1d47 \u03b2) x = 0 := rfl\n\ninstance : has_norm (\u03b1 \u2192\u1d47 \u03b2) := \u27e8\u03bbu, dist u 0\u27e9\n\nlemma norm_def : \u2225f\u2225 = dist f 0 := rfl\n\nlemma norm_coe_le_norm (x : \u03b1) : \u2225f x\u2225 \u2264 \u2225f\u2225 := calc\n  \u2225f x\u2225 = dist (f x) ((0 : \u03b1 \u2192\u1d47 \u03b2) x) : by simp [dist_zero_right]\n  ... \u2264 \u2225f\u2225 : dist_coe_le_dist _\n\n/-- The norm of a function is controlled by the supremum of the pointwise norms -/\nlemma norm_le (C0 : (0 : \u211d) \u2264 C) : \u2225f\u2225 \u2264 C \u2194 \u2200x:\u03b1, \u2225f x\u2225 \u2264 C :=\nby simpa only [coe_zero, dist_zero_right] using @dist_le _ _ _ _ f 0 _ C0\n\n/-- The pointwise sum of two bounded continuous functions is again bounded continuous. -/\ninstance : has_add (\u03b1 \u2192\u1d47 \u03b2) :=\n\u27e8\u03bbf g, \u27e8\u03bbx, f x + g x, continuous_add f.2.1 g.2.1, (\u2225f\u2225 + \u2225g\u2225) + (\u2225f\u2225 + \u2225g\u2225),\n  \u03bb x y,\n    have \u2200x, dist (f x + g x) 0 \u2264 \u2225f\u2225 + \u2225g\u2225 := \u03bbx, calc\n      dist (f x + g x) 0 = \u2225f x + g x\u2225 : dist_zero_right _\n      ... \u2264 \u2225f x\u2225 + \u2225g x\u2225 : norm_triangle _ _\n      ... \u2264 \u2225f\u2225 + \u2225g\u2225 : add_le_add (norm_coe_le_norm _) (norm_coe_le_norm _),\n    calc dist (f x + g x) (f y + g y) \u2264 dist (f x + g x) 0 + dist (f y + g y) 0 : dist_triangle_right _ _ _\n        ... \u2264 (\u2225f\u2225 + \u2225g\u2225) + (\u2225f\u2225 + \u2225g\u2225) : add_le_add (this x) (this y) \u27e9\u27e9\n\n/-- The pointwise opposite of a bounded continuous function is again bounded continuous. -/\ninstance : has_neg (\u03b1 \u2192\u1d47 \u03b2) :=\n\u27e8\u03bbf, \u27e8\u03bbx, -f x, continuous_neg f.2.1,\n  begin\n    have dn : \u2200a b : \u03b2, dist (-a) (-b) = dist a b := \u03bb a b,\n      by rw [dist_eq_norm, neg_sub_neg, \u2190 dist_eq_norm, dist_comm],\n    simpa only [dn] using f.2.2\n  end\u27e9\u27e9\n\n@[simp] lemma coe_add : (f + g) x = f x + g x := rfl\n@[simp] lemma coe_neg : (-f) x = - (f x) := rfl\nlemma forall_coe_zero_iff_zero : (\u2200x, f x = 0) \u2194 f = 0 :=\n\u27e8@ext _ _ _ _ f 0, by rintro rfl _; refl\u27e9\n\ninstance : add_comm_group (\u03b1 \u2192\u1d47 \u03b2) :=\n{ add_assoc    := assume f g h, by ext; simp,\n  zero_add     := assume f, by ext; simp,\n  add_zero     := assume f, by ext; simp,\n  add_left_neg := assume f, by ext; simp,\n  add_comm     := assume f g, by ext; simp,\n  ..bounded_continuous_function.has_add,\n  ..bounded_continuous_function.has_neg,\n  ..bounded_continuous_function.has_zero }\n\n@[simp] lemma coe_diff : (f - g) x = f x - g x := rfl\n\ninstance : normed_group (\u03b1 \u2192\u1d47 \u03b2) :=\nnormed_group.of_add_dist (\u03bb _, rfl) $ \u03bb f g h,\n(dist_le dist_nonneg).2 $ \u03bb x,\nle_trans (by rw [dist_eq_norm, dist_eq_norm, coe_add, coe_add,\n  add_sub_add_right_eq_sub]) (dist_coe_le_dist x)\n\nlemma abs_diff_coe_le_dist : norm (f x - g x) \u2264 dist f g :=\nby rw normed_group.dist_eq; exact @norm_coe_le_norm _ _ _ _ (f-g) x\n\nlemma coe_le_coe_add_dist {f g : \u03b1 \u2192\u1d47 \u211d} : f x \u2264 g x + dist f g :=\nsub_le_iff_le_add'.1 $ (abs_le.1 $ @dist_coe_le_dist _ _ _ _ f g x).2\n\n/-- Constructing a bounded continuous function from a uniformly bounded continuous\nfunction taking values in a normed group. -/\ndef of_normed_group {\u03b1 : Type u} {\u03b2 : Type v} [topological_space \u03b1] [normed_group \u03b2]\n  (f : \u03b1  \u2192 \u03b2) (C : \u211d) (H : \u2200x, norm (f x) \u2264 C) (Hf : continuous f) : \u03b1 \u2192\u1d47 \u03b2 :=\n\u27e8\u03bbn, f n, \u27e8Hf, \u27e8C + C, \u03bb m n,\n  calc dist (f m) (f n) \u2264 dist (f m) 0 + dist (f n) 0 : dist_triangle_right _ _ _\n       ... = norm (f m) + norm (f n) : by simp\n       ... \u2264 C + C : add_le_add (H m) (H n)\u27e9\u27e9\u27e9\n\n/-- Constructing a bounded continuous function from a uniformly bounded\nfunction on a discrete space, taking values in a normed group -/\ndef of_normed_group_discrete {\u03b1 : Type u} {\u03b2 : Type v}\n  [topological_space \u03b1] [discrete_topology \u03b1] [normed_group \u03b2]\n  (f : \u03b1  \u2192 \u03b2) (C : \u211d) (H : \u2200x, norm (f x) \u2264 C) : \u03b1 \u2192\u1d47 \u03b2 :=\nof_normed_group f C H continuous_of_discrete_topology\n\nend normed_group\nend bounded_continuous_function\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/topology/bounded_continuous_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.7032881363971574}}
{"text": "import set_theory.pgame\nimport position\nimport tactic\nimport tactic.nth_rewrite.default\n\nuniverse u\n\n/-!\n# Basic deinitions about impartial (pre-)games\n\nWe will define an impartial game, one in which left and right can make exactly the same moves.\nOur definition differs slightly by saying that the game is always equivilent to its negitve,\nno matter what moves are played. This allows for games such as poker-nim to be classifed as\nimpartial.\n-/\n\nnamespace pgame\n\nlocal infix ` \u2248 ` := pgame.equiv\n\n/-- The definiton for a impartial game, defined using Conway induction -/\n@[class] def impartial : pgame \u2192 Prop \n| G := G \u2248 -G \u2227 (\u2200 i, impartial (G.move_left i)) \u2227 (\u2200 j, impartial (G.move_right j))\nusing_well_founded {dec_tac := pgame_wf_tac}\n\n@[instance] lemma zero_impartial : impartial 0 := by tidy\n\n@[simp] lemma impartial_def {G : pgame} : G.impartial \u2194 G \u2248 -G \u2227 (\u2200 i, impartial (G.move_left i)) \u2227 (\u2200 j, impartial (G.move_right j)) := \nbegin\n\tsplit,\n\t{\tintro hi,\n\t\tunfold1 impartial at hi,\n\t\texact hi },\n\t{\tintro hi,\n\t\tunfold1 impartial,\n\t\texact hi }\nend\n\nlemma impartial_neg_equiv_self (G : pgame) [h : G.impartial] : G \u2248 -G := (impartial_def.1 h).1\n\n@[instance] lemma impartial_move_left_impartial {G : pgame} [h : G.impartial] (i : G.left_moves) : impartial (G.move_left i) :=\n(impartial_def.1 h).2.1 i\n\n@[instance] lemma impartial_move_right_impartial {G : pgame} [h : G.impartial] (j : G.right_moves) : impartial (G.move_right j) :=\n(impartial_def.1 h).2.2 j\n\n@[instance] lemma impartial_add : \u2200 (G H : pgame) [hG : G.impartial] [hH : H.impartial], (G + H).impartial\n| G H :=\nbegin\n\tintrosI hG hH,\n\trw impartial_def,\n\tsplit,\n\t{\tapply equiv_trans _ (equiv_of_relabelling (neg_add_relabelling G H)).symm,\n\t\tapply add_congr;\n\t\texact impartial_neg_equiv_self _\t},\n\tsplit,\n\t{ intro i,\n\t\tequiv_rw pgame.left_moves_add G H at i,\n\t\tcases i with iG iH,\n\t\t{\trw add_move_left_inl,\n\t\t\texact impartial_add (G.move_left iG) H },\n\t\t{ rw add_move_left_inr,\n\t\t\texact impartial_add G (H.move_left iH) } },\n\t{ intro j,\n\t\tequiv_rw pgame.right_moves_add G H at j,\n\t\tcases j with jG jH,\n\t\t{ rw add_move_right_inl,\n\t\t\texact impartial_add (G.move_right jG) H },\n\t\t{ rw add_move_right_inr,\n\t\t\texact impartial_add G (H.move_right jH) } }\nend\nusing_well_founded {dec_tac := pgame_wf_tac}\n\n@[instance] lemma impartial_neg : \u2200 (G : pgame) [G.impartial], (-G).impartial\n| G :=\nbegin\n\tintroI,\n\trw impartial_def,\n\tsplit,\n\t{\trw neg_neg,\n\t\tsymmetry,\n\t\texact impartial_neg_equiv_self G },\n\tsplit,\n\t{ intro i,\n\t\tequiv_rw G.left_moves_neg at i,\n\t\trw move_left_left_moves_neg_symm,\n\t\texact impartial_neg (G.move_right i) },\n\t{ intro j,\n\t\tequiv_rw G.right_moves_neg at j,\n\t\trw move_right_right_moves_neg_symm,\n\t\texact impartial_neg (G.move_left j) }\nend\nusing_well_founded {dec_tac := pgame_wf_tac}\n\nlemma impartial_position_cases (G : pgame) [G.impartial] : G.p_position \u2228 G.n_position :=\nbegin\n  rcases G.position_cases with hl | hr | hp | hn,\n  { cases hl with hpos hnonneg,\n\t\trw \u2190not_lt at hnonneg,\n\t\thave hneg := lt_of_lt_of_equiv hpos G.impartial_neg_equiv_self,\n\t\trw [lt_iff_neg_gt, neg_neg, neg_zero] at hneg,\n\t\tcontradiction },\n\t{ cases hr with hnonpos hneg,\n\t\trw \u2190not_lt at hnonpos,\n\t\thave hpos := lt_of_equiv_of_lt G.impartial_neg_equiv_self.symm hneg,\n\t\trw [lt_iff_neg_gt, neg_neg, neg_zero] at hpos,\n\t\tcontradiction },\n\t{ left, assumption },\n\t{ right, assumption }\nend\n\nlemma impartial_add_self (G : pgame) [G.impartial] : (G + G).p_position :=\np_position_is_zero.2 $ equiv_trans (add_congr G.impartial_neg_equiv_self G.equiv_refl) add_left_neg_equiv\n\n/-- A different way of viewing equivalence. -/\ndef additive_equiv (G H : pgame) [G.impartial] [H.impartial] : Prop :=\n\t\u2200 (F : pgame) [F.impartial], (G + F).p_position \u2194 (H + F).p_position\n\nlemma additive_equiv_equiv_equiv (G H : pgame) [hG : G.impartial] [hH : H.impartial] : G.additive_equiv H \u2194 G \u2248 H :=\nbegin\n\tsplit,\n\t{ intro heq,\n\t\tcases G.impartial_position_cases with hGp hGn,\n\t\t{ specialize heq 0, \n\t\t\trw [p_position_of_equiv_iff G.add_zero_equiv, p_position_of_equiv_iff H.add_zero_equiv, p_position_is_zero, p_position_is_zero] at heq,\n\t\t\trw p_position_is_zero at hGp,\n\t\t\texact equiv_trans hGp (heq.1 hGp).symm },\n\t\t{ split,\n\t\t\t{ rw le_iff_sub_nonneg,\n\t\t\t\tspecialize heq (-G),\n\t\t\t\trw [p_position_of_equiv_iff add_comm_equiv, p_position_of_equiv_iff add_left_neg_equiv] at heq,\n\t\t\t\texact (heq.1 zero_p_postition).2 },\n\t\t\t{ rw le_iff_sub_nonneg,\n\t\t\t\tspecialize heq (-H),\n\t\t\t\tnth_rewrite 1 p_position_of_equiv_iff add_comm_equiv at heq,\n\t\t\t\trw p_position_of_equiv_iff add_left_neg_equiv at heq,\n\t\t\t\texact (heq.2 zero_p_postition).2 } } },\n\t{ intros heq F hf,\n\t\trw [p_position_is_zero, p_position_is_zero],\n\t\tsplit,\n\t\t{ intro hGF,\n\t\t\texact equiv_trans (add_congr heq.symm $ equiv_refl _) hGF },\n\t\t{ intro hHF,\n\t\t\texact equiv_trans (add_congr heq $ equiv_refl _) hHF } }\nend\n\nlemma equiv_iff_sum_p_position (G H : pgame) [G.impartial] [H.impartial] : G \u2248 H \u2194 (G + H).p_position :=\nbegin\n\tsplit,\n\t{ intro heq,\n\t\texact p_position_of_equiv (add_congr (equiv_refl _) heq) G.impartial_add_self },\n\t{ intro hGHp,\n\t\tsplit,\n\t\t{ rw le_iff_sub_nonneg,\n\t\t\texact le_trans hGHp.2 (le_trans add_comm_le $ le_of_le_of_equiv (le_refl _) $ add_congr (equiv_refl _) G.impartial_neg_equiv_self) },\n\t\t{ rw le_iff_sub_nonneg,\n\t\t\texact le_trans hGHp.2 (le_of_le_of_equiv (le_refl _) $ add_congr (equiv_refl _) H.impartial_neg_equiv_self) } }\nend\n\nlemma impartial_p_position_symm (G : pgame) [G.impartial] : G.p_position \u2194 G \u2264 0 :=\nbegin\n\tuse and.left,\n\t{ intro hneg,\n\t\texact \u27e8 hneg, zero_le_iff_neg_le_zero.2 (le_of_equiv_of_le (impartial_neg_equiv_self G).symm hneg) \u27e9 }\nend\n\nlemma impartial_n_position_symm (G : pgame) [G.impartial] : G.n_position \u2194 G < 0 :=\nbegin\n\tuse and.right,\n\t{ intro hneg,\n\t\tsplit,\n\t\trw lt_iff_neg_gt,\n\t\trw neg_zero,\n\t\texact lt_of_equiv_of_lt G.impartial_neg_equiv_self.symm hneg,\n\t\texact hneg }\nend\n\nlemma impartial_p_position_symm' (G : pgame) [G.impartial] : G.p_position \u2194 0 \u2264 G :=\nbegin\n\tuse and.right,\n\t{ intro hpos,\n\t\texact \u27e8 le_zero_iff_zero_le_neg.2 $ le_of_le_of_equiv hpos G.impartial_neg_equiv_self, hpos \u27e9 }\nend\n\nlemma impartial_n_position_symm' (G : pgame) [G.impartial] : G.n_position \u2194 0 < G :=\nbegin\n\tuse and.left,\n\t{ intro hpos,\n\t\tuse hpos,\n\t\trw lt_iff_neg_gt,\n\t\trw neg_zero,\n\t\texact lt_of_lt_of_equiv hpos G.impartial_neg_equiv_self }\nend\n\nlemma no_good_left_moves_iff_p_position (G : pgame) [G.impartial] : (\u2200 (i : G.left_moves), (G.move_left i).n_position) \u2194 G.p_position :=\nbegin\n\tsplit,\n\t{\tintro hbad,\n\t\trw [impartial_p_position_symm, le_def_lt],\n\t\tsplit,\n\t\t{ intro i,\n\t\t\tspecialize hbad i,\n\t\t\texact hbad.2 },\n\t\t{ intro j,\n\t\t\texact pempty.elim j } },\n\t{ intros hp i,\n\t\texact (G.move_left i).impartial_n_position_symm.2 ((le_def_lt.1 $ G.impartial_p_position_symm.1 hp).1 i) }\nend\n\nlemma no_good_right_moves_iff_p_position (G : pgame) [G.impartial] : (\u2200 (j : G.right_moves), (G.move_right j).n_position) \u2194 G.p_position :=\nbegin\n\tsplit,\n\t{ intro hbad,\n\t\trw [impartial_p_position_symm', le_def_lt],\n\t\tsplit,\n\t\t{ intro i,\n\t\t\texact pempty.elim i },\n\t\t{ intro j,\n\t\t\tspecialize hbad j,\n\t\t\texact hbad.1 } },\n\t{ intros hp j,\n\t\texact (G.move_right j).impartial_n_position_symm'.2 ((le_def_lt.1 $ G.impartial_p_position_symm'.1 hp).2 j) }\nend\n\nlemma good_left_move_iff_n_position (G : pgame) [G.impartial] : (\u2203 (i : G.left_moves), (G.move_left i).p_position) \u2194 G.n_position :=\nbegin\n\tsplit,\n\t{ rintro \u27e8 i, hi \u27e9,\n\t\texact G.impartial_n_position_symm'.2 (lt_def_le.2 $ or.inl \u27e8 i, hi.2 \u27e9) },\n\t{ intro hn,\n\t\trw [impartial_n_position_symm', lt_def_le] at hn,\n\t\trcases hn with \u27e8 i, hi \u27e9 | \u27e8 j, _ \u27e9,\n\t\t{ exact \u27e8 i, (G.move_left i).impartial_p_position_symm'.2 hi \u27e9 },\n\t\t{ exact pempty.elim j } }\nend\n\nlemma good_right_move_iff_n_position (G : pgame) [G.impartial] : (\u2203 j : G.right_moves,  (G.move_right j).p_position) \u2194 G.n_position :=\nbegin\n\tsplit,\n\t{ rintro \u27e8 j, hj \u27e9,\n\t\texact G.impartial_n_position_symm.2 (lt_def_le.2 $ or.inr \u27e8 j, hj.1 \u27e9) },\n\t{ intro hn,\n\t\trw [impartial_n_position_symm, lt_def_le] at hn,\n\t\trcases hn with \u27e8 i, _ \u27e9 | \u27e8 j, hj \u27e9,\n\t\t{ exact pempty.elim i },\n\t\t{ exact \u27e8 j, (G.move_right j).impartial_p_position_symm.2 hj \u27e9 } }\nend\n\nend pgame\n", "meta": {"author": "foxthomson", "repo": "impartial", "sha": "5f8b405dbbd864682f1ccd30ff7504a23bb20a42", "save_path": "github-repos/lean/foxthomson-impartial", "path": "github-repos/lean/foxthomson-impartial/impartial-5f8b405dbbd864682f1ccd30ff7504a23bb20a42/src/impartial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7032881337326727}}
{"text": "import ..fglib\nimport ..basic\nimport .vector\n\nnamespace FG\n\n/-\n  ## Square Matrix\n\n  The basic definitions of mathlib's `matrix` are used.\n-/\n\ndef matrix_func : Type := \u2115 \u2192 \u2115 \u2192 \u2102\n\n/- Note that a `square_matrix n` is a `(n+1) \u00d7 (n+1)` matrix. -/\ndef square_matrix (n : \u2115) : Type := matrix (fin (n + 1)) (fin (n + 1)) \u2102\n\nnamespace square_matrix\n\nvariables {n : \u2115} (A : square_matrix n)\n\n@[simp] def length : square_matrix n \u2192 \u2115 := n + 1\n\n@[simp] def to_func : matrix_func :=\n  \u03bb(i j : \u2115), if i < A.length \u2227 j < A.length\n    then A i j else 0\n\n@[simp] def I : square_matrix n :=\n  matrix.has_one.one\n\n/- `square_matrix n` is a module -/\n@[simps] instance : ring (square_matrix n) :=\n{ ..matrix.ring }\n\n/- `\u2102` is a module over `square_matrix` -/\ninstance : module \u2102 (square_matrix n) :=\n{ ..matrix.module }\n\n\n@[simp] def mul_vec (v : vec n) :\n  vec n :=\nmatrix.mul_vec A v\n\n/- `square_matrix n` is a module over `vec n` -/\ninstance : module (square_matrix n) (vec n) :=\n{ smul := mul_vec,\n  one_smul := \u03bbv, by simp,\n  mul_smul := \u03bbA B v, by simp,\n  smul_zero := \u03bbA,\n  begin\n    funext i j,\n    simp [matrix.mul_vec]\n  end,\n  smul_add := \u03bbA x y, by apply matrix.mul_vec_add,\n  zero_smul := \u03bbx, by simp,\n  add_smul := \u03bbA B x, by apply matrix.add_mul_vec, }\n\n@[simp] def det : \u2102 :=\n  matrix.det A\n\n@[simp] lemma det_one :\n  det (1 : square_matrix n) = 1 :=\nby simp\n\n@[simp] lemma det_zero :\n  det (0 : square_matrix n) = 0 :=\nby simp\n\n/- Finite nonzero dimensional matrices must have at least one eigenvalue/eigenvector. -/\n@[simp] lemma has_nonzero_eigenvalue_and_eigenvector\n  (h : A \u2260 0) :\n  \u2203 (x : \u2102) (v : vec n), x \u2260 0 \u2227 v \u2260 0 \u2227 (A - x \u2022 I).det = 0 \u2227 (A - x \u2022 I) \u2022 v = 0 :=\nsorry\n\ndef is_invertible : Prop :=\n  \u2203 (B : square_matrix n), B * A = 1\n\n/- The following functions are trying to calculate an inverse matrix by the adjacent matrix. -/\n\n@[simp] def minor (A : square_matrix n) (i j : fin (n + 1)) : \u2102 :=\nbegin\n  let submatrix : square_matrix (n - 1) :=\n  \u03bb(i' j'), A (if i' < i then i' else i' + 1) (if j' < j then j' else j' + 1),\n  use submatrix.det\nend\n\n@[simp] def transpose : square_matrix n :=\n  matrix.transpose A\n\n@[simp] def cofactor_matrix : square_matrix n :=\n  \u03bb(i j), (-1) ^ ((i : \u2115) + j) * A.minor i j\n\n@[simp] def adjacent : square_matrix n :=\n  A.cofactor_matrix.transpose\n\n@[simp] noncomputable def inverse (h : A.det \u2260 0) : square_matrix n :=\n  \u03bb(i j), A.adjacent i j / A.det\n\n/- TODO: Too compliated(?). Haven't figured out how to prove this yet. -/\n@[simp] lemma mul_inverse_left (h : A.det \u2260 0) :\n  A.inverse h * A = 1 :=\nbegin\n  funext i j,\n  simp [matrix.mul, matrix.dot_product],\n  sorry\nend\n\n@[simp] lemma det_ne_zero_invertible :\n  A.det \u2260 0 \u2192 A.is_invertible :=\nbegin\n  intro h,\n  use A.inverse h,\n  apply A.mul_inverse_left\nend\n\n@[simp] lemma invertible_det_ne_zero :\n  A.is_invertible \u2192 A.det \u2260 0 :=\nbegin\n  intro h,\n  cases' h with B,\n  have hdet := by calc B.det * A.det = (B * A).det\n      : (matrix.det_mul B A).symm\n    ... = (1 : square_matrix n).det\n      : by rw h\n    ... = (1 : \u2102)\n      : det_one,\n  simp,\n  intro hfalse,\n  have h := right_ne_zero_of_mul_eq_one hdet,\n  apply h,\n  assumption\nend\n\n@[simp] theorem det_ne_zero_iff :\n  A.det \u2260 0 \u2194 A.is_invertible :=\niff.intro (det_ne_zero_invertible A) (invertible_det_ne_zero A)\n\n@[simp] def to_linear_operator :\n  linear_operator \u2102 (vec n) :=\n{ to_fun := \u03bbv, A.mul_vec v,\n  map_add' :=\n  begin\n    intros v w,\n    apply vec.ext,\n    intro i,\n    simp [ matrix.mul_vec,\n      matrix.dot_product, matrix.dot_product_add,\n      mul_add, finset.sum_add_distrib ],\n  end,\n  map_smul' :=\n  begin\n    intros a v,\n    have h := (matrix.mul_vec_lin A).map_smul' a v,\n    simp at h,\n    simp [mul_vec],\n    exact h,\n  end }\n\n@[simp] lemma transpose_det :\n  A.transpose.det = A.det :=\nby apply matrix.det_transpose\n\n@[simp] def conj_transpose : square_matrix n :=\n  matrix.conj_transpose A\n\n@[simp] lemma conj_transpose_det :\n  A.conj_transpose.det = star A.det :=\nby apply matrix.det_conj_transpose\n\n@[simp] def is_unitary : Prop :=\n  A.conj_transpose = A\n\n@[simp] def det1 (A : square_matrix 0) : \u2102 :=\n  A 0 0\n\nlemma det1_eq (A : square_matrix 0) :\n  A.det = A.det1 :=\nby simp\n\nmeta def invertible_det1 : tactic unit :=\ndo\n  tactic.applyc `FG.square_matrix.det_ne_zero_invertible,\n  `[simp [FG.square_matrix.det1_eq]]\n\n@[simp] def det2 (A : square_matrix 1) : \u2102 :=\n  A 0 0 * A 1 1 - A 0 1 * A 1 0\n\n/- This was copied from mathlib's internal file :( -/\nlemma det2_eq (A : square_matrix 1) :\n  A.det = A.det2 :=\nbegin\n  simp [matrix.det_succ_row_zero, fin.sum_univ_succ],\n  ring,\nend\n\n/- Helper tactic for quickly solve simple 2-dimensional determinants. -/\nmeta def invertible_det2 : tactic unit :=\ndo\n  tactic.applyc `FG.square_matrix.det_ne_zero_invertible,\n  `[simp [FG.square_matrix.det2_eq]]\n\nend square_matrix\n\nend FG\n", "meta": {"author": "sunoru", "repo": "finite-groups", "sha": "5095d557eb2d923627ba10169ad5e1e68c25cb30", "save_path": "github-repos/lean/sunoru-finite-groups", "path": "github-repos/lean/sunoru-finite-groups/finite-groups-5095d557eb2d923627ba10169ad5e1e68c25cb30/src/linear_space/square_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.7032881308122387}}
{"text": "import data.fintype.basic\nimport data.equiv.basic\nimport data.real.basic\nimport algebra.group.defs\nimport tactic\n\n-- https://en.wikipedia.org/wiki/The_Prisoner_of_Benda#The_theorem\n\n\n-- Perhaps this could be improved by using more from:\n --https://leanprover-community.github.io/mathlib_docs/group_theory/perm/sign.html#equiv.perm.is_cycle\n\n-- Though this (more general) permutation infrastucture is often not decidable\nnamespace futurama\n\nopen equiv -- \"perm x\" is \"equiv x x\" AKA \"x \u2243 x\"\nopen nat\nopen list\n\n\n/-\n1. Abbreviations (could add more if needed)\n-/\n@[reducible] def finpairs (n:\u2115) : Type := list (fin n \u00d7 fin n)\nnotation `S[` n `]`  := perm (fin n) -- symmetric group on n elements\n\n/-\n2. Defining a predicate for a permutation on a finite set to be a k-cycle\nStart at 0, and take k steps (which don't bring you to 0 until the last one)\n-/\ndef cyclicrec : \u03a0{n:\u2115}, \u2115 \u2192 fin n \u2192 perm (fin n) \u2192 bool\n | n 0 curr p := (p.to_fun curr).val = 0\n | n (succ m) curr  p := ((p.to_fun curr).val > 0 )\n                         \u2227 cyclicrec m (p.to_fun curr) p\n\ndef cyclic : \u03a0{n:\u2115}, perm (fin n) \u2192 bool\n | 0        _ := ff -- exclude 0-cycles\n | (succ m) p := cyclicrec m \u27e80, succ_pos'\u27e9 p\n\n\n/-\n3. Proposed sequence of switches to solve futurama problem for a single cycle\n\nFor an arbitrary simple cycle of length k, the sequence of switches is (specializing 'i' from the wikipedia proof to '1'):\n    (x, 1) (y, 2) ... (y, k) (x k) (y 1)\nor, for any simple cycle with an element 'a':\n    (x, a) (y p\u00b9a) ... (y p\u1d4f\u207b\u00b9 a)  (x p\u1d4f\u207b\u00b9 a) (y a)\n\nThe two additional elements x and y are represented as n and n+1 respectively\n(elements within the set are 0,1,...,n-1).\n-/\n\n\ndef construction_rec : \u03a0{n:\u2115} , \u2115 \u2192 fin n \u2192 S[n] \u2192 finpairs (n+2)\n | n (succ counter) curr p := (n+1,p.to_fun curr)\n                              :: construction_rec counter (p.to_fun curr) p\n | n 0              _    _ := (n,1)::(n+1,0)::(n,n+1)::nil\n\ndef construction : \u03a0{n : \u2115}, S[n] \u2192 finpairs (n+2)\n | 0        _ := nil\n | (succ m) p := (succ m, 0) :: construction_rec m \u27e80, succ_pos'\u27e9 p\n\ndef construction_rec' : \u03a0{n:\u2115} , \u2115 \u2192 fin n \u2192 S[n] \u2192 finpairs (n+2)\n | n (succ counter) curr p := (n+1,p.to_fun curr)\n                              :: construction_rec counter (p.to_fun curr) p\n | n 0              _    _ := (n,1)::(n+1,0)::(n,n+1)::nil\n\ndef construction' : \u03a0{n : \u2115}, S[n] \u2192 finpairs (n+2)\n | 0        _ := nil\n | (succ m) p := (succ m, 0) :: construction_rec m \u27e80, succ_pos'\u27e9 p\n\n\n/-\n4. For a perm \u03c3, equiv.swap \u03c3 x y means:\n    If a\u2192x in \u03c3, then a\u2192y in the result (and vice versa)\n    If x\u2192b in \u03c3, then y\u2192b in the result (and vice versa)\n\nDefining the application of a list of swaps in sequence\n-/\n\n--\ndef swaps {\u03b1 : Type*} [decidable_eq \u03b1] : list (\u03b1\u00d7\u03b1) \u2192 perm \u03b1\n    | ((a1, a2) :: b) := (equiv.swap a1 a2) * swaps b\n    | nil             := 1\n\n/-\n5. Defining a predicate on a list of swaps to judge whether they\n   satisfy the constraints of The Prisoner of Benda\n\n   If we have the swap (x,y) at any position in the list, we fail\n   iff (x,y) or (y,x) appears at any other point in the list.\n\n   This is done by iterating through the list, accumulating a set of\n   (ordered) pairs. For each swap we check if it (or its reverse)\n   is in the seen set.\n-/\n\ndef valid_swaps_rec  {\u03b1 : Type*} [decidable_eq \u03b1]:\n    list (\u03b1\u00d7\u03b1) \u2192 finset (\u03b1\u00d7\u03b1) \u2192 bool\n| list.nil      _    := tt\n| ((ha,hb)::tl) seen := \u00ac((ha,hb) \u2208 seen \u2228 (hb,ha) \u2208 seen)\n                        \u2227 (valid_swaps_rec tl (insert (ha,hb) seen))\n\ndef valid_swaps {\u03b1 : Type*} [decidable_eq \u03b1] (s : list (\u03b1\u00d7\u03b1)) : bool :=\n    valid_swaps_rec s \u2205\n\n\n/-\n6. Two extra elems in the set being permuted needed for the construction to work.\nThis function takes a permutation on n elements and extends it to a\npermutation on n+2 elements.\n-/\n\ndef add_two_to_perm_forward {n: \u2115} (p : S[n]) : fin (n+2) \u2192 fin(n+2) :=\n    \u03bb m : fin (n+2),\n        if h: m.val < n\n        then have x : fin n, from p.to_fun (fin.mk m.val h),\n            (fin.mk x.val (lt.trans x.is_lt (by simp only [succ_pos', lt_add_iff_pos_right])))\n        else m\ndef add_two_to_perm_reverse {n: \u2115} (p : perm (fin n)) : fin (n+2) \u2192 fin(n+2) :=\n    \u03bb m : fin (n+2),\n        if h: m.val < n\n        then have x: fin n, from p.inv_fun (fin.mk m.val h),\n            (fin.mk x.val (lt.trans x.is_lt (by simp only [succ_pos', lt_add_iff_pos_right])))\n        else m\n\n-- The result is still a permutation after adding\nlemma a2finv {n : \u2115} (p : perm (fin n)) :\n    function.left_inverse (add_two_to_perm_reverse p) (add_two_to_perm_forward p) :=\n    begin\n        unfold function.left_inverse,\n        intros m,\n        rw add_two_to_perm_forward,\n        dsimp,\n        cases (decidable.em (m.val < n)) with hl hg,\n            {\n                rw dif_pos hl,\n                rw add_two_to_perm_reverse,\n                dsimp,\n                have t1: coe_fn (equiv.symm p) = p.inv_fun , by refl,\n                have t2: coe_fn p = p.to_fun , by refl,\n                rw t1, rw t2,\n                rw dif_pos (p.to_fun \u27e8m.val, hl\u27e9).is_lt,\n                simp only [symm_apply_apply, fin.eta, to_fun_as_coe, inv_fun_as_coe]\n            },\n            {\n                rw add_two_to_perm_reverse, dsimp,\n                rw dif_neg hg,\n                rw dif_neg hg,\n            }\nend\nlemma a2rinv {n : \u2115} (p : perm (fin n)):\n    function.right_inverse (add_two_to_perm_reverse p) (add_two_to_perm_forward p)\n    :=  begin\n        unfold function.right_inverse,\n        intros m,\n        rw add_two_to_perm_forward,\n        dsimp,\n        cases (decidable.em (m.val < n)) with hl hg,\n            {\n                rw add_two_to_perm_reverse,\n                dsimp,\n                rw dif_pos hl,\n                have t1: coe_fn (equiv.symm p) = p.inv_fun , by refl,\n                have t2: coe_fn p = p.to_fun , by refl,\n                rw t1, rw t2,\n                rw dif_pos (p.inv_fun \u27e8m.val, hl\u27e9).is_lt,\n                simp only [apply_symm_apply, fin.eta, to_fun_as_coe, inv_fun_as_coe],\n            },\n            {\n                rw add_two_to_perm_reverse, dsimp,\n                rw dif_neg hg,\n                rw dif_neg hg,\n            }\nend\n-- Combine the four above ingredients\ndef add_two {n :\u2115} (p : perm (fin n)) : perm (fin (n+2)) :=\n    \u27e8add_two_to_perm_forward p, add_two_to_perm_reverse p,\n     a2finv p, a2rinv p\u27e9\n\n/-\n7. The main theorem:\n\nTest that\n    1.) the construction above returns everyone to their original bodies\n        (yields the identity permutation)\nand 2.) it has no repeat swaps\n-/\n\ndef futurama_correct  {n: \u2115} {p: S[n]} (h: cyclic p) :\n    (add_two p) * swaps (construction p) = 1:= begin\n    induction n with k ih,\n    { --trivial n=0 case\n        unfold construction,\n        unfold swaps,\n        apply one_mul\n    },\n    {--n>0\n        ext,\n        rw perm.one_apply,\n        rw perm.mul_apply,\n        unfold construction,\n        rw cast_succ,\n        induction x with k2 ih2,\n        simp only [],\n\n        --cases (decidable.em (k2 < k)) with hl hg,\n\n        --squeeze_simp,\n        --unfold swaps,\n        --unfold add_two,\n        --unfold add_two_to_perm_forward,\n        --unfold add_two_to_perm_reverse,\n        sorry,\n    },\nend\n\n\ndef futurama_valid  {n: \u2115} {p: S[n]} (h: cyclic p) :\n    valid_swaps (construction p) := begin\n    induction n with k ih,\n    { -- trivial n=0 case\n         unfold construction,\n         unfold valid_swaps,\n         unfold valid_swaps_rec,\n         trivial\n\n    },\n    {\n        unfold construction,\n        unfold valid_swaps,\n        induction p,\n\n        sorry}\nend\n\ntheorem futurama_thm {n: \u2115} {p: S[n]} (h: cyclic p) :\n    (add_two p) * swaps (construction p) = 1\n    \u2227 valid_swaps (construction p)\n    := \u27e8futurama_correct h, futurama_valid h\u27e9\n\n\n/-\n8. Constructing+printing permutations for testing\n-/\n-- Make a simple cycle from a list, e.g. [2, 1, 3, 0]\ndef ss_rec  : \u03a0 {n:\u2115}, list (fin n) \u2192 perm (fin n)\n| _ nil         := 1\n| _ (h::nil)    := 1 -- Actually, this case is never encountered\n| _ (h::h2::t)  := (swap h h2) * (ss_rec (h2::t))\n\ndef mk_cyclic {n:\u2115} (l : list (fin n)) : S[n] := ss_rec l\n\n-- Show where each permuted element goes to\ndef pp_rec : \u03a0{n:\u2115}, \u2115 \u2192 S[n] \u2192 string\n | _ 0 _ := \"|\"\n | n (succ m) p := if h: m < n\n                   then (pp_rec m p) ++ to_string m ++\"\u2192\"++\n                        (to_string (p.to_fun \u27e8m, h\u27e9)) ++ \"|\"\n                   else \"ERROR\"\n\ndef print_perm {n:\u2115} (p: S[n]) : string := pp_rec n p\n\n-- Convert the (fin n) pairs to something that Lean can represent\ndef print_finpairs :  \u03a0 {n:\u2115}, list (fin n \u00d7 fin n) \u2192 list (\u2115\u00d7\u2115)\n  | _ nil    := nil\n  | n (h::t) := (h.1.val,h.2.val)::(print_finpairs t)\n\nend futurama\n", "meta": {"author": "kris-brown", "repo": "theorem_proving_in_lean", "sha": "774460c21bf857daff158210741bd88d1c8323cd", "save_path": "github-repos/lean/kris-brown-theorem_proving_in_lean", "path": "github-repos/lean/kris-brown-theorem_proving_in_lean/theorem_proving_in_lean-774460c21bf857daff158210741bd88d1c8323cd/futurama.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7032881289505993}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de dupla nega\u00e7o:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P \u2192 \u00ac\u00acP  :=\nbegin\n  intro hp,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  \u00ac\u00acP \u2192 P  :=\nbegin\n  intro hp,\n  by_contra destructionandtears,\n  apply hp,\n  exact destructionandtears,\nend\n\ntheorem doubleneg_law :\n  \u00ac\u00acP \u2194 P  :=\nbegin\n  split,\n  intro hp,\n  by_contra destructionandtears,\n  apply hp,\n  exact destructionandtears,\n  intro hp,\n  contradiction,\nend\n\n------------------------------------------------\n-- Comutatividade dos \u2228,\u2227:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P \u2228 Q) \u2192 (Q \u2228 P)  :=\nbegin\n  intro blood,\n  cases blood with sweat tears,\n  right,\n  exact sweat,\n  left,\n  exact tears,\nend\n\ntheorem conj_comm :\n  (P \u2227 Q) \u2192 (Q \u2227 P)  :=\nbegin\n  intro hp,\n  split,\n  cases hp with h1 h2,\n  exact h2,\n  cases hp with h1 h2,\n  exact h1,\nend\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de interdefinabilidade dos \u2192,\u2228:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (\u00acP \u2228 Q) \u2192 (P \u2192 Q)  :=\nbegin\n  intro verge,\n  intro hp2,\n  cases verge with of tears,\n  contradiction,\n  exact tears,\nend\n\ntheorem disj_as_impl :\n  (P \u2228 Q) \u2192 (\u00acP \u2192 Q)  :=\nbegin\n  intro the,\n  intro skip,\n  cases the with good part,\n  contradiction,\n  exact part,\nend\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de contraposi\u00e7\u00e3o:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P \u2192 Q) \u2192 (\u00acQ \u2192 \u00acP)  :=\nbegin\n  intro thehouse,\n  intro ajr,\n  intro down,\n  have burn : Q := thehouse down,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (\u00acQ \u2192 \u00acP) \u2192 (P \u2192 Q)  :=\nbegin\n  intro bummer,\n  intro pop,\n  by_contra land,\n  have ajr : \u00acP := bummer land,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P \u2192 Q) \u2194 (\u00acQ \u2192 \u00acP)  :=\nbegin\n  split,\n  intro hp,\n  intro hp2,\n  intro hp3,\n  have hp4 : Q := hp hp3,\n  contradiction,\n  intro bummer,\n  intro pop,\n  by_contra land,\n  have ajr : \u00acP := bummer land,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  \u00ac\u00ac(P\u2228\u00acP)  :=\nbegin\n  intro hp,\n  have h : P\u2228\u00acP,\n  right,\n  intro hp2,\n  have i : P\u2228\u00acP,\n  left,\n  exact hp2,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P \u2192 Q) \u2192 P) \u2192 \u00ac\u00acP  :=\nbegin\n  intro hp,\n  intro hp2,\n  have hp3 : \u00acP\u2228Q,\n  left,\n  exact hp2,\n  have hp4 : P\u2192Q,\n  intro hp5,\n  contradiction,\n  have hp6 : P := hp hp4,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de interdefinabilidade dos \u2228,\u2227:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P\u2228Q \u2192 \u00ac(\u00acP\u2227\u00acQ)  :=\nbegin\n  intro way,\n  intro the,\n  cases way with less sad,\n  cases the with good part,\n  contradiction,\n  cases the with entertainment ishere,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P\u2227Q \u2192 \u00ac(\u00acP\u2228\u00acQ)  :=\nbegin\n  intro Christmas,\n  intro Bang,\n  cases Christmas with In June,\n  cases Bang with I won't,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para \u2228,\u2227:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  \u00ac(P\u2228Q) \u2192 (\u00acP \u2227 \u00acQ)  :=\nbegin\n  intro Netflix,\n  split,\n  intro Trip,\n  have Karma : P\u2228Q,\n  left,\n  exact Trip,\n  contradiction,\n  intro Trip,\n  have Joe : P\u2228Q,\n  right,\n  exact Trip,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (\u00acP \u2227 \u00acQ) \u2192 \u00ac(P\u2228Q)  :=\nbegin\n  intro Indie,\n  intro next,\n  cases Indie with my play,\n  cases next with up forever,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  \u00ac(P\u2227Q) \u2192 (\u00acQ \u2228 \u00acP)  :=\nbegin\n  intro hp,\n  by_cases hp2 : P,\n  left,\n  intro hp3,\n  have hp4 : P\u2227Q,\n  split,\n  exact hp2,\n  exact hp3,\n  contradiction,\n  right, \n  exact hp2,\nend\n\ntheorem demorgan_conj_converse :\n  (\u00acQ \u2228 \u00acP) \u2192 \u00ac(P\u2227Q)  :=\nbegin\n  intro Ok,\n  intro Orchestra,\n  cases Orchestra with Sober Up,\n  cases Ok with Birthday Party,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  \u00ac(P\u2227Q) \u2194 (\u00acQ \u2228 \u00acP)  :=\nbegin\n  split,\n  intro hp,\n  by_cases hp2 : P,\n  left,\n  intro hp3,\n  have hp4 : P\u2227Q,\n  split,\n  exact hp2,\n  exact hp3,\n  contradiction,\n  right, \n  exact hp2,\n  intro Ok,\n  intro Orchestra,\n  cases Orchestra with Sober Up,\n  cases Ok with Birthday Party,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_disj_law :\n  \u00ac(P\u2228Q) \u2194 (\u00acP \u2227 \u00acQ)  :=\nbegin\n  split,\n  intro Netflix,\n  split,\n  intro Trip,\n  have Karma : P\u2228Q,\n  left,\n  exact Trip,\n  contradiction,\n  intro Trip,\n  have Joe : P\u2228Q,\n  right,\n  exact Trip,\n  contradiction,\n  intro Indie,\n  intro next,\n  cases Indie with my play,\n  cases next with up forever,\n  contradiction,\n  contradiction,\nend\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de distributividade dos \u2228,\u2227:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P\u2227(Q\u2228R) \u2192 (P\u2227Q)\u2228(P\u2227R)  :=\nbegin\n  intro Adventure,\n  cases Adventure with isOut There,\n  cases There with Ordinaryish People,\n  left,\n  split,\n  exact isOut,\n  exact Ordinaryish,\n  right,\n  split,\n  exact isOut,\n  exact People,\nend\n\ntheorem distr_conj_disj_converse :\n  (P\u2227Q)\u2228(P\u2227R) \u2192 P\u2227(Q\u2228R)  :=\nbegin\n  intro Don't,\n  cases Don't with Throw Out,\n  cases Throw with My Legos,\n  split,\n  exact My,\n  left,\n  exact Legos,\n  cases Out with Normal Drama,\n  split,\n  exact Normal,\n  right,\n  exact Drama,\nend\n\ntheorem distr_disj_conj :\n  P\u2228(Q\u2227R) \u2192 (P\u2228Q)\u2227(P\u2228R)  :=\nbegin\n  intro Weak,\n  split,\n  cases Weak with Thirty Three,\n  left,\n  exact Thirty,\n  right,\n  cases Three with O'clock Things,\n  exact O'clock,\n  cases Weak with Trick The,\n  left,\n  exact Trick,\n  right,\n  cases The with Good Part,\n  exact Part,\nend\n\ntheorem distr_disj_conj_converse :\n  (P\u2228Q)\u2227(P\u2228R) \u2192 P\u2228(Q\u2227R)  :=\nbegin\n  intro Wow,\n  cases Wow with I'm NotCrazy,\n  cases I'm with a Believer,\n  left,\n  exact a,\n  cases NotCrazy with Pitchfork Kids,\n  left,\n  exact Pitchfork,\n  right,\n  split,\n  exact Believer,\n  exact Kids,\nend\n\n\n------------------------------------------------\n-- Currifica\u00e7\u00e3o\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P\u2227Q)\u2192R) \u2192 (P\u2192(Q\u2192R))  :=\nbegin\n  intro hp,\n  intro hp2,\n  intro hp3,\n  have hp4: P\u2227Q,\n  split,\n  exact hp2,\n  exact hp3,\n  have hp5: R := hp hp4,\n  exact hp5,\nend\n\ntheorem uncurry_prop :\n  (P\u2192(Q\u2192R)) \u2192 ((P\u2227Q)\u2192R)  :=\nbegin\n  intro hp,\n  intro hp2,\n  cases hp2 with hp3 hp4,\n  have hp5 : Q\u2192R := hp hp3,\n  have hp6 : R := hp5 hp4,\n  exact hp6,\nend\n\n\n------------------------------------------------\n-- Reflexividade da \u2192:\n------------------------------------------------\n\ntheorem impl_refl :\n  P \u2192 P  :=\nbegin\n  intro h,\n  exact h,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P \u2192 (P\u2228Q)  :=\nbegin\n  intro hp,\n  left,\n  exact hp,\nend\n\ntheorem weaken_disj_left :\n  Q \u2192 (P\u2228Q)  :=\nbegin\n  intro hp,\n  right,\n  exact hp,\nend\n\ntheorem weaken_conj_right :\n  (P\u2227Q) \u2192 P  :=\nbegin\n  intro world's,\n  cases world's with smallest violin,\n  exact smallest,\nend\n\ntheorem weaken_conj_left :\n  (P\u2227Q) \u2192 Q  :=\nbegin\n  intro h,\n  cases h with hp hq,\n  exact hq,\nend\n\ntheorem conj_idempot :\n  (P\u2227P) \u2194 P :=\nbegin\n  split,\n  intro ajr,\n  cases ajr with bummer land,\n  exact bummer,\n  intro pop,\n  split,\n  exact pop,\n  exact pop,\nend\n\ntheorem disj_idempot :\n  (P\u2228P) \u2194 P  :=\nbegin\n  split,\n  intro come,\n  cases come with hang out,\n  exact hang,\n  exact out,\n  intro ajr,\n  left,\n  exact ajr,\nend\n\nend propositional\n\n\n----------------------------------------------------------------\n\n\nsection predicate\n\nvariable U : Type\nvariables P Q : U -> Prop\n\n\n------------------------------------------------\n-- As leis de De Morgan para \u2203,\u2200:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  \u00ac(\u2203x, P x) \u2192 (\u2200x, \u00acP x)  :=\nbegin\n  intro hp,\n  intro a,\n  intro boom,\n  apply hp,\n  existsi a,\n  exact boom,\nend\n\ntheorem demorgan_exists_converse :\n  (\u2200x, \u00acP x) \u2192 \u00ac(\u2203x, P x)  :=\nbegin\n  intro hp,\n  intro hp2,\n  cases hp2 with a ha,\n  apply hp,\n  exact ha,\nend\n\ntheorem demorgan_forall :\n  \u00ac(\u2200x, P x) \u2192 (\u2203x, \u00acP x)  :=\nbegin\n  intro hp,\n  by_contra cry,\n  have more: \u2200x, P x,\n  intro a,\n  by_contra boom,\n  have hp2 : \u2203x, \u00acP x,\n  existsi a,\n  exact boom,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_forall_converse :\n  (\u2203x, \u00acP x) \u2192 \u00ac(\u2200x, P x)  :=\nbegin\n  intro hp,\n  intro hp2,\n  cases hp with a ha,\n  have hp3 : P a := hp2 a,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  \u00ac(\u2200x, P x) \u2194 (\u2203x, \u00acP x)  :=\nbegin\n  split,\n  intro hp,\n  by_contra cry,\n  have more: \u2200x, P x,\n  intro a,\n  by_contra boom,\n  have hp2 : \u2203x, \u00acP x,\n  existsi a,\n  exact boom,\n  contradiction,\n  contradiction,\n  intro hp,\n  intro hp2,\n  cases hp with a ha,\n  have hp3 : P a := hp2 a,\n  contradiction,\nend\n\ntheorem demorgan_exists_law :\n  \u00ac(\u2203x, P x) \u2194 (\u2200x, \u00acP x)  :=\nbegin\n  split,\n  intro hp,\n  intro a,\n  intro hp2,\n  apply hp,\n  existsi a,\n  exact hp2,\n  intro hp,\n  intro hp2,\n  cases hp2 with a ha,\n  apply hp,\n  exact ha,\nend\n\n\n------------------------------------------------\n-- Proposi\u00e7\u00f5es de interdefinabilidade dos \u2203,\u2200:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (\u2203x, P x) \u2192 \u00ac(\u2200x, \u00acP x)  :=\nbegin\n  intro hp,\n  intro hp2,\n  cases hp with a ha,\n  apply hp2,\n  exact ha,\nend\n\ntheorem forall_as_neg_exists :\n  (\u2200x, P x) \u2192 \u00ac(\u2203x, \u00acP x)  :=\nbegin\n  intro hp,\n  intro hp2,\n  cases hp2 with a ha,\n  have hp3 : P a := hp a,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  \u00ac(\u2203x, \u00acP x) \u2192 (\u2200x, P x)  :=\nbegin\n  intro hp,\n  intro a,\n  by_contra boom,\n  have hp1 : \u2203x, \u00acP x,\n  existsi a,\n  exact boom,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_converse :\n  \u00ac(\u2200x, \u00acP x) \u2192 (\u2203x, P x)  :=\nbegin\n  intro hp,\n  by_contra boom,\n  have hp1 : \u2200 (x : U), \u00acP x,\n  intro a,\n  intro ha,\n  have hp2 : \u2203 (x : U), P x,\n  existsi a,\n  exact ha,\n  contradiction,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_law :\n  (\u2200x, P x) \u2194 \u00ac(\u2203x, \u00acP x)  :=\nbegin\n  split,\n  intro hp,\n  intro hp2,\n  cases hp2 with a ha,\n  have hp3 : P a := hp a,\n  contradiction,\n  intro hp,\n  intro a,\n  by_contra boom,\n  have hp1 : \u2203x, \u00acP x,\n  existsi a,\n  exact boom,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_law :\n  (\u2203x, P x) \u2194 \u00ac(\u2200x, \u00acP x)  :=\nbegin\n  split,\n  intro hp,\n  intro hp2,\n  cases hp with a ha,\n  apply hp2,\n  exact ha,\n  intro hp,\n  by_contra boom,\n  have hp1 : \u2200 (x : U), \u00acP x,\n  intro a,\n  intro ha,\n  have hp2 : \u2203 (x : U), P x,\n  existsi a,\n  exact ha,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n--  Proposi\u00e7\u00f5es de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (\u2203x, P x \u2227 Q x) \u2192 (\u2203x, P x) \u2227 (\u2203x, Q x)  :=\nbegin\n  intro hp,\n  cases hp with a ha,\n  cases ha with hp1 hp2,\n  split,\n  existsi a,\n  exact hp1,\n  existsi a,\n  exact hp2,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (\u2203x, P x \u2228 Q x) \u2192 (\u2203x, P x) \u2228 (\u2203x, Q x)  :=\nbegin\n  intro hp,\n  cases hp with a ha,\n  cases ha with hp1 hp2,\n  left,\n  existsi a,\n  exact hp1,\n  right,\n  existsi a,\n  exact hp2,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (\u2203x, P x) \u2228 (\u2203x, Q x) \u2192 (\u2203x, P x \u2228 Q x)  :=\nbegin\n  intro hp,\n  cases hp with hp1 hp2,\n  cases hp1 with a ha,\n  existsi a,\n  left,\n  exact ha,\n  cases hp2 with b hb,\n  existsi b,\n  right,\n  exact hb,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (\u2200x, P x \u2227 Q x) \u2192 (\u2200x, P x) \u2227 (\u2200x, Q x)  :=\nbegin\n  intro hp,\n  split,\n  intro a,\n  have hp1 : P a \u2227 Q a := hp a,\n  cases hp1 with ha hb,\n  exact ha,\n  intro b,\n  have hp2 : P b \u2227 Q b := hp b,\n  cases hp2 with ha hb,\n  exact hb,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (\u2200x, P x) \u2227 (\u2200x, Q x) \u2192 (\u2200x, P x \u2227 Q x)  :=\nbegin\n  intro hp,\n  cases hp with hp1 hp2,\n  intro a,\n  split,\n  have ha : P a := hp1 a,\n  exact ha,\n  have hb : Q a := hp2 a,\n  exact hb,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (\u2200x, P x) \u2228 (\u2200x, Q x) \u2192 (\u2200x, P x \u2228 Q x)  :=\nbegin\n  intro hp,\n  cases hp with hp1 hp2,\n  intro a,\n  left,\n  have ha: P a := hp1 a,\n  exact ha,\n  intro b,\n  right,\n  have hb : Q b := hp2 b,\n  exact hb,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (\u2200x, P x \u2228 Q x) \u2192 (\u2200x, P x) \u2228 (\u2200x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (\u2203x, P x) \u2227 (\u2203x, Q x) \u2192 (\u2203x, P x \u2227 Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "HannahSantos", "repo": "fmclean", "sha": "94473f68dffdad83f63c212974dcc2be4622e35b", "save_path": "github-repos/lean/HannahSantos-fmclean", "path": "github-repos/lean/HannahSantos-fmclean/fmclean-94473f68dffdad83f63c212974dcc2be4622e35b/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.703288127891805}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\n/--\nGiven the two functions $f(x)=x^3+2x+1$ and $g(x)=x-1$, find $f(g(1))$.\nAnswer: $1$.\n--/\ntheorem mathd_algebra_616\n  (f g : \u211d \u2192 \u211d)\n  (h\u2080 : \u2200 x, f x = x^3 + 2 * x + 1)\n  (h\u2081 : \u2200 x, g x = x - 1) :\n  f (g 1) = 1 :=\nbegin\n  simp [h\u2081, h\u2080],\nend\n", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p616.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7032881278918048}}
{"text": "import algebra.big_operators.order\nimport tactic.ring\n\n\nopen_locale big_operators\n\n\ntheorem finset.mem_le_pos_sum {\u03b1 : Type*} {\u03b2 : Type*} [linear_ordered_add_comm_group \u03b2] (f : \u03b1 \u2192 \u03b2) (s : finset \u03b1) (h1 : \u2200 x, x \u2208 s \u2192 0 < f x) \n:  \u2200 y (H : y \u2208 s), f y \u2264 \u2211 x in s, f x :=\nbegin\n  apply finset.single_le_sum,\n  intros x h,\n  apply le_of_lt (h1 x h),\n\nend\n", "meta": {"author": "ATOMSLab", "repo": "LeanChemicalTheories", "sha": "c2b15363c1e0ea0e52c1ae86abd1650670ff9044", "save_path": "github-repos/lean/ATOMSLab-LeanChemicalTheories", "path": "github-repos/lean/ATOMSLab-LeanChemicalTheories/LeanChemicalTheories-c2b15363c1e0ea0e52c1ae86abd1650670ff9044/src/statistical_thermodynamics/maximum_term.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7032881260301653}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_327\n  (a : \u211d)\n  (h\u2080 : 1 / 5 * abs (9 + 2 * a) < 1) :\n  -7 < a \u2227 a < -2 :=\nbegin\n  have h\u2081 := (mul_lt_mul_left (show 0 < (5:\u211d), by linarith)).mpr h\u2080,\n  have h\u2082 : abs (9 + 2 * a) < 5, linarith,\n  have h\u2083 := abs_lt.mp h\u2082,\n  cases h\u2083 with h\u2083 h\u2084,\n  split; nlinarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p327.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.7718434873426303, "lm_q1q2_score": 0.7032881175248125}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov, Alistair Tucker\n-/\nimport topology.algebra.ordered.basic\n\n/-!\n# Intermediate Value Theorem\n\nIn this file we prove the Intermediate Value Theorem: if `f : \u03b1 \u2192 \u03b2` is a function defined on a\nconnected set `s` that takes both values `\u2264 a` and values `\u2265 a` on `s`, then it is equal to `a` at\nsome point of `s`. We also prove that intervals in a dense conditionally complete order are\npreconnected and any preconnected set is an interval. Then we specialize IVT to functions continuous\non intervals.\n\n## Main results\n\n* `is_preconnected_I??` : all intervals `I??` are preconnected,\n* `is_preconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for\n  connected sets and connected spaces, respectively;\n* `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions\n  on closed intervals.\n\n### Miscellaneous facts\n\n* `is_closed.Icc_subset_of_forall_mem_nhds_within` : \u201cContinuous induction\u201d principle;\n  if `s \u2229 [a, b]` is closed, `a \u2208 s`, and for each `x \u2208 [a, b) \u2229 s` some of its right neighborhoods\n  is included `s`, then `[a, b] \u2286 s`.\n* `is_closed.Icc_subset_of_forall_exists_gt`, `is_closed.mem_of_ge_of_forall_exists_gt` : two\n  other versions of the \u201ccontinuous induction\u201d principle.\n\n## Tags\n\nintermediate value theorem, connected space, connected set\n-/\n\nopen filter order_dual topological_space function set\nopen_locale topological_space filter\n\nuniverses u v w\n\n/-!\n### Intermediate value theorem on a (pre)connected space\n\nIn this section we prove the following theorem (see `is_preconnected.intermediate_value\u2082`): if `f`\nand `g` are two functions continuous on a preconnected set `s`, `f a \u2264 g a` at some `a \u2208 s` and\n`g b \u2264 f b` at some `b \u2208 s`, then `f c = g c` at some `c \u2208 s`. We prove several versions of this\nstatement, including the classical IVT that corresponds to a constant function `g`.\n-/\n\nsection\n\nvariables {X : Type u} {\u03b1 : Type v} [topological_space X]\n  [linear_order \u03b1] [topological_space \u03b1] [order_closed_topology \u03b1]\n\n/-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions\non a preconnected space and `f a \u2264 g a` and `g b \u2264 f b`, then for some `x` we have `f x = g x`. -/\nlemma intermediate_value_univ\u2082 [preconnected_space X] {a b : X} {f g : X \u2192 \u03b1} (hf : continuous f)\n  (hg : continuous g) (ha : f a \u2264 g a) (hb : g b \u2264 f b) :\n  \u2203 x, f x = g x :=\nbegin\n  obtain \u27e8x, h, hfg, hgf\u27e9 : (univ \u2229 {x | f x \u2264 g x \u2227 g x \u2264 f x}).nonempty,\n    from is_preconnected_closed_iff.1 preconnected_space.is_preconnected_univ _ _\n      (is_closed_le hf hg) (is_closed_le hg hf) (\u03bb x hx, le_total _ _) \u27e8a, trivial, ha\u27e9\n      \u27e8b, trivial, hb\u27e9,\n  exact \u27e8x, le_antisymm hfg hgf\u27e9\nend\n\nlemma intermediate_value_univ\u2082_eventually\u2081 [preconnected_space X] {a : X} {l : filter X} [ne_bot l]\n  {f g : X \u2192 \u03b1} (hf : continuous f) (hg : continuous g) (ha : f a \u2264 g a) (he : g \u2264\u1da0[l] f) :\n  \u2203 x, f x = g x :=\nlet \u27e8c, hc\u27e9 := he.frequently.exists in intermediate_value_univ\u2082 hf hg ha hc\n\nlemma intermediate_value_univ\u2082_eventually\u2082 [preconnected_space X] {l\u2081 l\u2082 : filter X}\n  [ne_bot l\u2081] [ne_bot l\u2082] {f g : X \u2192 \u03b1} (hf : continuous f) (hg : continuous g)\n  (he\u2081 : f \u2264\u1da0[l\u2081] g ) (he\u2082 : g \u2264\u1da0[l\u2082] f) :\n  \u2203 x, f x = g x :=\nlet \u27e8c\u2081, hc\u2081\u27e9 := he\u2081.frequently.exists, \u27e8c\u2082, hc\u2082\u27e9 := he\u2082.frequently.exists in\nintermediate_value_univ\u2082 hf hg hc\u2081 hc\u2082\n\n/-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous\non a preconnected set `s` and for some `a b \u2208 s` we have `f a \u2264 g a` and `g b \u2264 f b`,\nthen for some `x \u2208 s` we have `f x = g x`. -/\nlemma is_preconnected.intermediate_value\u2082 {s : set X} (hs : is_preconnected s)\n  {a b : X} (ha : a \u2208 s) (hb : b \u2208 s) {f g : X \u2192 \u03b1}\n  (hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a \u2264 g a) (hb' : g b \u2264 f b) :\n  \u2203 x \u2208 s, f x = g x :=\nlet \u27e8x, hx\u27e9 := @intermediate_value_univ\u2082 s \u03b1 _ _ _ _ (subtype.preconnected_space hs) \u27e8a, ha\u27e9 \u27e8b, hb\u27e9\n  _ _ (continuous_on_iff_continuous_restrict.1 hf) (continuous_on_iff_continuous_restrict.1 hg)\n  ha' hb'\nin \u27e8x, x.2, hx\u27e9\n\nlemma is_preconnected.intermediate_value\u2082_eventually\u2081 {s : set X} (hs : is_preconnected s)\n  {a : X} {l : filter X} (ha : a \u2208 s) [ne_bot l] (hl : l \u2264 \ud835\udcdf s) {f g : X \u2192 \u03b1}\n  (hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a \u2264 g a) (he : g \u2264\u1da0[l] f) :\n  \u2203 x \u2208 s, f x = g x :=\nbegin\n  rw continuous_on_iff_continuous_restrict at hf hg,\n  obtain \u27e8b, h\u27e9 := @intermediate_value_univ\u2082_eventually\u2081 _ _ _ _ _ _ (subtype.preconnected_space hs)\n    \u27e8a, ha\u27e9 _ (comap_coe_ne_bot_of_le_principal hl) _ _ hf hg ha' (eventually_comap' he),\n  exact \u27e8b, b.prop, h\u27e9,\nend\n\nlemma is_preconnected.intermediate_value\u2082_eventually\u2082 {s : set X} (hs : is_preconnected s)\n  {l\u2081 l\u2082 : filter X} [ne_bot l\u2081] [ne_bot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f g : X \u2192 \u03b1}\n  (hf : continuous_on f s) (hg : continuous_on g s) (he\u2081 : f \u2264\u1da0[l\u2081] g) (he\u2082 : g \u2264\u1da0[l\u2082] f) :\n  \u2203 x \u2208 s, f x = g x :=\nbegin\n  rw continuous_on_iff_continuous_restrict at hf hg,\n  obtain \u27e8b, h\u27e9 := @intermediate_value_univ\u2082_eventually\u2082 _ _ _ _ _ _ (subtype.preconnected_space hs)\n    _ _ (comap_coe_ne_bot_of_le_principal hl\u2081) (comap_coe_ne_bot_of_le_principal hl\u2082)\n    _ _ hf hg (eventually_comap' he\u2081) (eventually_comap' he\u2082),\n  exact \u27e8b, b.prop, h\u27e9,\nend\n\n/-- **Intermediate Value Theorem** for continuous functions on connected sets. -/\nlemma is_preconnected.intermediate_value {s : set X} (hs : is_preconnected s)\n  {a b : X} (ha : a \u2208 s) (hb : b \u2208 s) {f : X \u2192 \u03b1} (hf : continuous_on f s) :\n  Icc (f a) (f b) \u2286 f '' s :=\n\u03bb x hx, mem_image_iff_bex.2 $ hs.intermediate_value\u2082 ha hb hf continuous_on_const hx.1 hx.2\n\nlemma is_preconnected.intermediate_value_Ico {s : set X} (hs : is_preconnected s)\n  {a : X} {l : filter X} (ha : a \u2208 s) [ne_bot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) {v : \u03b1} (ht : tendsto f l (\ud835\udcdd v)) :\n  Ico (f a) v \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ hs.intermediate_value\u2082_eventually\u2081 ha hl\n  hf continuous_on_const h.1 (eventually_ge_of_tendsto_gt h.2 ht)\n\nlemma is_preconnected.intermediate_value_Ioc {s : set X} (hs : is_preconnected s)\n  {a : X} {l : filter X} (ha : a \u2208 s) [ne_bot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) {v : \u03b1} (ht : tendsto f l (\ud835\udcdd v)) :\n  Ioc v (f a) \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ bex.imp_right (\u03bb x _, eq.symm) $ hs.intermediate_value\u2082_eventually\u2081 ha hl\n  continuous_on_const hf h.2 (eventually_le_of_tendsto_lt h.1 ht)\n\nlemma is_preconnected.intermediate_value_Ioo {s : set X} (hs : is_preconnected s)\n  {l\u2081 l\u2082 : filter X} [ne_bot l\u2081] [ne_bot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) {v\u2081 v\u2082 : \u03b1} (ht\u2081 : tendsto f l\u2081 (\ud835\udcdd v\u2081)) (ht\u2082 : tendsto f l\u2082 (\ud835\udcdd v\u2082)) :\n  Ioo v\u2081 v\u2082 \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082\n  hf continuous_on_const (eventually_le_of_tendsto_lt h.1 ht\u2081) (eventually_ge_of_tendsto_gt h.2 ht\u2082)\n\nlemma is_preconnected.intermediate_value_Ici {s : set X} (hs : is_preconnected s)\n  {a : X} {l : filter X} (ha : a \u2208 s) [ne_bot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) (ht : tendsto f l at_top) :\n  Ici (f a) \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ hs.intermediate_value\u2082_eventually\u2081 ha hl\n  hf continuous_on_const h (tendsto_at_top.1 ht y)\n\nlemma is_preconnected.intermediate_value_Iic {s : set X} (hs : is_preconnected s)\n  {a : X} {l : filter X} (ha : a \u2208 s) [ne_bot l] (hl : l \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) (ht : tendsto f l at_bot) :\n  Iic (f a) \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ bex.imp_right (\u03bb x _, eq.symm) $ hs.intermediate_value\u2082_eventually\u2081 ha hl\n  continuous_on_const hf h (tendsto_at_bot.1 ht y)\n\nlemma is_preconnected.intermediate_value_Ioi {s : set X} (hs : is_preconnected s)\n  {l\u2081 l\u2082 : filter X} [ne_bot l\u2081] [ne_bot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) {v : \u03b1} (ht\u2081 : tendsto f l\u2081 (\ud835\udcdd v)) (ht\u2082 : tendsto f l\u2082 at_top) :\n  Ioi v \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082\n  hf continuous_on_const (eventually_le_of_tendsto_lt h ht\u2081) (tendsto_at_top.1 ht\u2082 y)\n\nlemma is_preconnected.intermediate_value_Iio {s : set X} (hs : is_preconnected s)\n  {l\u2081 l\u2082 : filter X} [ne_bot l\u2081] [ne_bot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) {v : \u03b1} (ht\u2081 : tendsto f l\u2081 at_bot) (ht\u2082 : tendsto f l\u2082 (\ud835\udcdd v)) :\n  Iio v \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082\n  hf continuous_on_const (tendsto_at_bot.1 ht\u2081 y) (eventually_ge_of_tendsto_gt h ht\u2082)\n\nlemma is_preconnected.intermediate_value_Iii {s : set X} (hs : is_preconnected s)\n  {l\u2081 l\u2082 : filter X} [ne_bot l\u2081] [ne_bot l\u2082] (hl\u2081 : l\u2081 \u2264 \ud835\udcdf s) (hl\u2082 : l\u2082 \u2264 \ud835\udcdf s) {f : X \u2192 \u03b1}\n  (hf : continuous_on f s) (ht\u2081 : tendsto f l\u2081 at_bot) (ht\u2082 : tendsto f l\u2082 at_top) :\n  univ \u2286 f '' s :=\n\u03bb y h, bex_def.1 $ hs.intermediate_value\u2082_eventually\u2082 hl\u2081 hl\u2082\n  hf continuous_on_const (tendsto_at_bot.1 ht\u2081 y) (tendsto_at_top.1 ht\u2082 y)\n\n/-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/\nlemma intermediate_value_univ [preconnected_space X] (a b : X) {f : X \u2192 \u03b1} (hf : continuous f) :\n  Icc (f a) (f b) \u2286 range f :=\n\u03bb x hx, intermediate_value_univ\u2082 hf continuous_const hx.1 hx.2\n\n/-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/\nlemma mem_range_of_exists_le_of_exists_ge [preconnected_space X] {c : \u03b1} {f : X \u2192 \u03b1}\n  (hf : continuous f) (h\u2081 : \u2203 a, f a \u2264 c) (h\u2082 : \u2203 b, c \u2264 f b) :\n  c \u2208 range f :=\nlet \u27e8a, ha\u27e9 := h\u2081, \u27e8b, hb\u27e9 := h\u2082 in intermediate_value_univ a b hf \u27e8ha, hb\u27e9\n\n/-!\n### (Pre)connected sets in a linear order\n\nIn this section we prove the following results:\n\n* `is_preconnected.ord_connected`: any preconnected set `s` in a linear order is `ord_connected`,\n  i.e. `a \u2208 s` and `b \u2208 s` imply `Icc a b \u2286 s`;\n\n* `is_preconnected.mem_intervals`: any preconnected set `s` in a conditionally complete linear order\n  is one of the intervals `set.Icc`, `set.`Ico`, `set.Ioc`, `set.Ioo`, ``set.Ici`, `set.Iic`,\n  `set.Ioi`, `set.Iio`; note that this is false for non-complete orders: e.g., in `\u211d \\ {0}`, the set\n  of positive numbers cannot be represented as `set.Ioi _`.\n\n-/\n\n/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/\nlemma is_preconnected.Icc_subset {s : set \u03b1} (hs : is_preconnected s)\n  {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n  Icc a b \u2286 s :=\nby simpa only [image_id] using hs.intermediate_value ha hb continuous_on_id\n\nlemma is_preconnected.ord_connected {s : set \u03b1} (h : is_preconnected s) :\n  ord_connected s :=\n\u27e8\u03bb x hx y hy, h.Icc_subset hx hy\u27e9\n\n/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/\nlemma is_connected.Icc_subset {s : set \u03b1} (hs : is_connected s)\n  {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n  Icc a b \u2286 s :=\nhs.2.Icc_subset ha hb\n\n/-- If preconnected set in a linear order space is unbounded below and above, then it is the whole\nspace. -/\nlemma is_preconnected.eq_univ_of_unbounded {s : set \u03b1} (hs : is_preconnected s) (hb : \u00acbdd_below s)\n  (ha : \u00acbdd_above s) :\n  s = univ :=\nbegin\n  refine eq_univ_of_forall (\u03bb x, _),\n  obtain \u27e8y, ys, hy\u27e9 : \u2203 y \u2208 s, y < x := not_bdd_below_iff.1 hb x,\n  obtain \u27e8z, zs, hz\u27e9 : \u2203 z \u2208 s, x < z := not_bdd_above_iff.1 ha x,\n  exact hs.Icc_subset ys zs \u27e8le_of_lt hy, le_of_lt hz\u27e9\nend\n\nend\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n  [conditionally_complete_linear_order \u03b1] [topological_space \u03b1] [order_topology \u03b1]\n  [conditionally_complete_linear_order \u03b2] [topological_space \u03b2] [order_topology \u03b2]\n  [nonempty \u03b3]\n\n/-- A bounded connected subset of a conditionally complete linear order includes the open interval\n`(Inf s, Sup s)`. -/\nlemma is_connected.Ioo_cInf_cSup_subset {s : set \u03b1} (hs : is_connected s) (hb : bdd_below s)\n  (ha : bdd_above s) :\n  Ioo (Inf s) (Sup s) \u2286 s :=\n\u03bb x hx, let \u27e8y, ys, hy\u27e9 := (is_glb_lt_iff (is_glb_cInf hs.nonempty hb)).1 hx.1 in\nlet \u27e8z, zs, hz\u27e9 := (lt_is_lub_iff (is_lub_cSup hs.nonempty ha)).1 hx.2 in\nhs.Icc_subset ys zs \u27e8le_of_lt hy, le_of_lt hz\u27e9\n\nlemma eq_Icc_cInf_cSup_of_connected_bdd_closed {s : set \u03b1} (hc : is_connected s) (hb : bdd_below s)\n  (ha : bdd_above s) (hcl : is_closed s) :\n  s = Icc (Inf s) (Sup s) :=\nsubset.antisymm (subset_Icc_cInf_cSup hb ha) $\n  hc.Icc_subset (hcl.cInf_mem hc.nonempty hb) (hcl.cSup_mem hc.nonempty ha)\n\nlemma is_preconnected.Ioi_cInf_subset {s : set \u03b1} (hs : is_preconnected s) (hb : bdd_below s)\n  (ha : \u00acbdd_above s) :\n  Ioi (Inf s) \u2286 s :=\nbegin\n  have sne : s.nonempty := @nonempty_of_not_bdd_above \u03b1 _ s \u27e8Inf \u2205\u27e9 ha,\n  intros x hx,\n  obtain \u27e8y, ys, hy\u27e9 : \u2203 y \u2208 s, y < x := (is_glb_lt_iff (is_glb_cInf sne hb)).1 hx,\n  obtain \u27e8z, zs, hz\u27e9 : \u2203 z \u2208 s, x < z := not_bdd_above_iff.1 ha x,\n  exact hs.Icc_subset ys zs \u27e8le_of_lt hy, le_of_lt hz\u27e9\nend\n\nlemma is_preconnected.Iio_cSup_subset {s : set \u03b1} (hs : is_preconnected s) (hb : \u00acbdd_below s)\n  (ha : bdd_above s) :\n  Iio (Sup s) \u2286 s :=\n@is_preconnected.Ioi_cInf_subset (order_dual \u03b1) _ _ _ s hs ha hb\n\n/-- A preconnected set in a conditionally complete linear order is either one of the intervals\n`[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +\u221e)`,\n`(Inf s, +\u221e)`, `(-\u221e, Sup s]`, `(-\u221e, Sup s)`, `(-\u221e, +\u221e)`, or `\u2205`. The converse statement requires\n`\u03b1` to be densely ordererd. -/\nlemma is_preconnected.mem_intervals {s : set \u03b1} (hs : is_preconnected s) :\n  s \u2208 ({Icc (Inf s) (Sup s), Ico (Inf s) (Sup s), Ioc (Inf s) (Sup s), Ioo (Inf s) (Sup s),\n    Ici (Inf s), Ioi (Inf s), Iic (Sup s), Iio (Sup s), univ, \u2205} : set (set \u03b1)) :=\nbegin\n  rcases s.eq_empty_or_nonempty with rfl|hne,\n  { apply_rules [or.inr, mem_singleton] },\n  have hs' : is_connected s := \u27e8hne, hs\u27e9,\n  by_cases hb : bdd_below s; by_cases ha : bdd_above s,\n  { rcases mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_cInf_cSup_subset hb ha)\n      (subset_Icc_cInf_cSup hb ha) with hs|hs|hs|hs,\n    { exact (or.inl hs) },\n    { exact (or.inr $ or.inl hs) },\n    { exact (or.inr $ or.inr $ or.inl hs) },\n    { exact (or.inr $ or.inr $ or.inr $ or.inl hs) } },\n  { refine (or.inr $ or.inr $ or.inr $ or.inr _),\n    cases mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_cInf_subset hb ha) (\u03bb x hx, cInf_le hb hx)\n      with hs hs,\n    { exact or.inl hs },\n    { exact or.inr (or.inl hs) } },\n  { iterate 6 { apply or.inr },\n    cases mem_Iic_Iio_of_subset_of_subset (hs.Iio_cSup_subset hb ha) (\u03bb x hx, le_cSup ha hx)\n      with hs hs,\n    { exact or.inl hs },\n    { exact or.inr (or.inl hs) } },\n  { iterate 8 { apply or.inr },\n    exact or.inl (hs.eq_univ_of_unbounded hb ha) }\nend\n\n/-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`,\n`Iic`, `Iio`, or `univ`, or `\u2205`. The converse statement requires `\u03b1` to be densely ordered. Though\none can represent `\u2205` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve\nreadability. -/\nlemma set_of_is_preconnected_subset_of_ordered :\n  {s : set \u03b1 | is_preconnected s} \u2286\n    -- bounded intervals\n    (range (uncurry Icc) \u222a range (uncurry Ico) \u222a range (uncurry Ioc) \u222a range (uncurry Ioo)) \u222a\n    -- unbounded intervals and `univ`\n    (range Ici \u222a range Ioi \u222a range Iic \u222a range Iio \u222a {univ, \u2205}) :=\nbegin\n  intros s hs,\n  rcases hs.mem_intervals with hs|hs|hs|hs|hs|hs|hs|hs|hs|hs,\n  { exact (or.inl $ or.inl $ or.inl $ or.inl \u27e8(Inf s, Sup s), hs.symm\u27e9) },\n  { exact (or.inl $ or.inl $ or.inl $ or.inr \u27e8(Inf s, Sup s), hs.symm\u27e9) },\n  { exact (or.inl $ or.inl $ or.inr \u27e8(Inf s, Sup s), hs.symm\u27e9) },\n  { exact (or.inl $ or.inr \u27e8(Inf s, Sup s), hs.symm\u27e9) },\n  { exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inl \u27e8Inf s, hs.symm\u27e9) },\n  { exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inr \u27e8Inf s, hs.symm\u27e9) },\n  { exact (or.inr $ or.inl $ or.inl  $ or.inr \u27e8Sup s, hs.symm\u27e9) },\n  { exact (or.inr $ or.inl $  or.inr \u27e8Sup s, hs.symm\u27e9) },\n  { exact (or.inr $ or.inr $ or.inl hs) },\n  { exact (or.inr $ or.inr $ or.inr hs) }\nend\n\n/-!\n### Intervals are connected\n\nIn this section we prove that a closed interval (hence, any `ord_connected` set) in a dense\nconditionally complete linear order is preconnected.\n-/\n\n/-- A \"continuous induction principle\" for a closed interval: if a set `s` meets `[a, b]`\non a closed subset, contains `a`, and the set `s \u2229 [a, b)` has no maximal point, then `b \u2208 s`. -/\nlemma is_closed.mem_of_ge_of_forall_exists_gt {a b : \u03b1} {s : set \u03b1} (hs : is_closed (s \u2229 Icc a b))\n  (ha : a \u2208 s) (hab : a \u2264 b) (hgt : \u2200 x \u2208 s \u2229 Ico a b, (s \u2229 Ioc x b).nonempty) :\n  b \u2208 s :=\nbegin\n  let S := s \u2229 Icc a b,\n  replace ha : a \u2208 S, from \u27e8ha, left_mem_Icc.2 hab\u27e9,\n  have Sbd : bdd_above S, from \u27e8b, \u03bb z hz, hz.2.2\u27e9,\n  let c := Sup (s \u2229 Icc a b),\n  have c_mem : c \u2208 S, from hs.cSup_mem \u27e8_, ha\u27e9 Sbd,\n  have c_le : c \u2264 b, from cSup_le \u27e8_, ha\u27e9 (\u03bb x hx, hx.2.2),\n  cases eq_or_lt_of_le c_le with hc hc, from hc \u25b8 c_mem.1,\n  exfalso,\n  rcases hgt c \u27e8c_mem.1, c_mem.2.1, hc\u27e9 with \u27e8x, xs, cx, xb\u27e9,\n  exact not_lt_of_le (le_cSup Sbd \u27e8xs, le_trans (le_cSup Sbd ha) (le_of_lt cx), xb\u27e9) cx\nend\n\n/-- A \"continuous induction principle\" for a closed interval: if a set `s` meets `[a, b]`\non a closed subset, contains `a`, and for any `a \u2264 x < y \u2264 b`, `x \u2208 s`, the set `s \u2229 (x, y]`\nis not empty, then `[a, b] \u2286 s`. -/\nlemma is_closed.Icc_subset_of_forall_exists_gt {a b : \u03b1} {s : set \u03b1} (hs : is_closed (s \u2229 Icc a b))\n  (ha : a \u2208 s) (hgt : \u2200 x \u2208 s \u2229 Ico a b, \u2200 y \u2208 Ioi x, (s \u2229 Ioc x y).nonempty) :\n  Icc a b \u2286 s :=\nbegin\n  assume y hy,\n  have : is_closed (s \u2229 Icc a y),\n  { suffices : s \u2229 Icc a y = s \u2229 Icc a b \u2229 Icc a y,\n    { rw this, exact is_closed.inter hs is_closed_Icc },\n    rw [inter_assoc],\n    congr,\n    exact (inter_eq_self_of_subset_right $ Icc_subset_Icc_right hy.2).symm },\n  exact is_closed.mem_of_ge_of_forall_exists_gt this ha hy.1\n    (\u03bb x hx, hgt x \u27e8hx.1, Ico_subset_Ico_right hy.2 hx.2\u27e9 y hx.2.2)\nend\n\nvariables [densely_ordered \u03b1] {a b : \u03b1}\n\n/-- A \"continuous induction principle\" for a closed interval: if a set `s` meets `[a, b]`\non a closed subset, contains `a`, and for any `x \u2208 s \u2229 [a, b)` the set `s` includes some open\nneighborhood of `x` within `(x, +\u221e)`, then `[a, b] \u2286 s`. -/\nlemma is_closed.Icc_subset_of_forall_mem_nhds_within {a b : \u03b1} {s : set \u03b1}\n  (hs : is_closed (s \u2229 Icc a b)) (ha : a \u2208 s)\n  (hgt : \u2200 x \u2208 s \u2229 Ico a b, s \u2208 \ud835\udcdd[Ioi x] x) :\n  Icc a b \u2286 s :=\nbegin\n  apply hs.Icc_subset_of_forall_exists_gt ha,\n  rintros x \u27e8hxs, hxab\u27e9 y hyxb,\n  have : s \u2229 Ioc x y \u2208 \ud835\udcdd[Ioi x] x,\n    from inter_mem (hgt x \u27e8hxs, hxab\u27e9) (Ioc_mem_nhds_within_Ioi \u27e8le_refl _, hyxb\u27e9),\n  exact (nhds_within_Ioi_self_ne_bot' hxab.2).nonempty_of_mem this\nend\n\n/-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/\nlemma is_preconnected_Icc : is_preconnected (Icc a b) :=\nis_preconnected_closed_iff.2\nbegin\n  rintros s t hs ht hab \u27e8x, hx\u27e9 \u27e8y, hy\u27e9,\n  wlog hxy : x \u2264 y := le_total x y using [x y s t, y x t s],\n  have xyab : Icc x y \u2286 Icc a b := Icc_subset_Icc hx.1.1 hy.1.2,\n  by_contradiction hst,\n  suffices : Icc x y \u2286 s,\n    from hst \u27e8y, xyab $ right_mem_Icc.2 hxy, this $ right_mem_Icc.2 hxy, hy.2\u27e9,\n  apply (is_closed.inter hs is_closed_Icc).Icc_subset_of_forall_mem_nhds_within hx.2,\n  rintros z \u27e8zs, hz\u27e9,\n  have zt : z \u2208 t\u1d9c, from \u03bb zt, hst \u27e8z, xyab $ Ico_subset_Icc_self hz, zs, zt\u27e9,\n  have : t\u1d9c \u2229 Ioc z y \u2208 \ud835\udcdd[Ioi z] z,\n  { rw [\u2190 nhds_within_Ioc_eq_nhds_within_Ioi hz.2],\n    exact mem_nhds_within.2 \u27e8t\u1d9c, ht.is_open_compl, zt, subset.refl _\u27e9},\n  apply mem_of_superset this,\n  have : Ioc z y \u2286 s \u222a t, from \u03bb w hw, hab (xyab \u27e8le_trans hz.1 (le_of_lt hw.1), hw.2\u27e9),\n  exact \u03bb w \u27e8wt, wzy\u27e9, (this wzy).elim id (\u03bb h, (wt h).elim)\nend\n\nlemma is_preconnected_interval : is_preconnected (interval a b) := is_preconnected_Icc\n\nlemma set.ord_connected.is_preconnected {s : set \u03b1} (h : s.ord_connected) :\n  is_preconnected s :=\nis_preconnected_of_forall_pair $ \u03bb x y hx hy, \u27e8interval x y, h.interval_subset hx hy,\n  left_mem_interval, right_mem_interval, is_preconnected_interval\u27e9\n\nlemma is_preconnected_iff_ord_connected {s : set \u03b1} :\n  is_preconnected s \u2194 ord_connected s :=\n\u27e8is_preconnected.ord_connected, set.ord_connected.is_preconnected\u27e9\n\nlemma is_preconnected_Ici : is_preconnected (Ici a) := ord_connected_Ici.is_preconnected\nlemma is_preconnected_Iic : is_preconnected (Iic a) := ord_connected_Iic.is_preconnected\nlemma is_preconnected_Iio : is_preconnected (Iio a) := ord_connected_Iio.is_preconnected\nlemma is_preconnected_Ioi : is_preconnected (Ioi a) := ord_connected_Ioi.is_preconnected\nlemma is_preconnected_Ioo : is_preconnected (Ioo a b) := ord_connected_Ioo.is_preconnected\nlemma is_preconnected_Ioc : is_preconnected (Ioc a b) := ord_connected_Ioc.is_preconnected\nlemma is_preconnected_Ico : is_preconnected (Ico a b) := ord_connected_Ico.is_preconnected\n\n@[priority 100]\ninstance ordered_connected_space : preconnected_space \u03b1 :=\n\u27e8ord_connected_univ.is_preconnected\u27e9\n\n/-- In a dense conditionally complete linear order, the set of preconnected sets is exactly\nthe set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-\u221e, +\u221e)`,\nor `\u2205`. Though one can represent `\u2205` as `(Inf s, Inf s)`, we include it into the list of\npossible cases to improve readability. -/\nlemma set_of_is_preconnected_eq_of_ordered :\n  {s : set \u03b1 | is_preconnected s} =\n    -- bounded intervals\n    (range (uncurry Icc) \u222a range (uncurry Ico) \u222a range (uncurry Ioc) \u222a range (uncurry Ioo)) \u222a\n    -- unbounded intervals and `univ`\n    (range Ici \u222a range Ioi \u222a range Iic \u222a range Iio \u222a {univ, \u2205}) :=\nbegin\n  refine subset.antisymm set_of_is_preconnected_subset_of_ordered _,\n  simp only [subset_def, -mem_range, forall_range_iff, uncurry, or_imp_distrib, forall_and_distrib,\n    mem_union, mem_set_of_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true,\n    is_preconnected_Icc, is_preconnected_Ico, is_preconnected_Ioc,\n    is_preconnected_Ioo, is_preconnected_Ioi, is_preconnected_Iio, is_preconnected_Ici,\n    is_preconnected_Iic, is_preconnected_univ, is_preconnected_empty],\nend\n\n/-!\n### Intermediate Value Theorem on an interval\n\nIn this section we prove several versions of the Intermediate Value Theorem for a function\ncontinuous on an interval.\n-/\n\nvariables {\u03b4 : Type*} [linear_order \u03b4] [topological_space \u03b4] [order_closed_topology \u03b4]\n\n/-- **Intermediate Value Theorem** for continuous functions on closed intervals, case\n`f a \u2264 t \u2264 f b`.-/\nlemma intermediate_value_Icc {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Icc (f a) (f b) \u2286 f '' (Icc a b) :=\nis_preconnected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf\n\n/-- **Intermediate Value Theorem** for continuous functions on closed intervals, case\n`f a \u2265 t \u2265 f b`.-/\nlemma intermediate_value_Icc' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Icc (f b) (f a) \u2286 f '' (Icc a b) :=\nis_preconnected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf\n\n/-- **Intermediate Value Theorem** for continuous functions on closed intervals, unordered case. -/\nlemma intermediate_value_interval {a b : \u03b1} {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (interval a b)) :\n  interval (f a) (f b) \u2286 f '' interval a b :=\nby cases le_total (f a) (f b); simp [*, is_preconnected_interval.intermediate_value]\n\nlemma intermediate_value_Ico {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Ico (f a) (f b) \u2286 f '' (Ico a b) :=\nor.elim (eq_or_lt_of_le hab) (\u03bb he y h, absurd h.2 (not_lt_of_le (he \u25b8 h.1)))\n(\u03bb hlt, @is_preconnected.intermediate_value_Ico _ _ _ _ _ _ _ (is_preconnected_Ico)\n  _ _ \u27e8refl a, hlt\u27e9 (right_nhds_within_Ico_ne_bot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self)\n  _ ((hf.continuous_within_at \u27e8hab, refl b\u27e9).mono Ico_subset_Icc_self))\n\nlemma intermediate_value_Ico' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Ioc (f b) (f a) \u2286 f '' (Ico a b) :=\nor.elim (eq_or_lt_of_le hab) (\u03bb he y h, absurd h.1 (not_lt_of_le (he \u25b8 h.2)))\n(\u03bb hlt, @is_preconnected.intermediate_value_Ioc _ _ _ _ _ _ _ (is_preconnected_Ico)\n  _ _ \u27e8refl a, hlt\u27e9 (right_nhds_within_Ico_ne_bot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self)\n  _ ((hf.continuous_within_at \u27e8hab, refl b\u27e9).mono Ico_subset_Icc_self))\n\nlemma intermediate_value_Ioc {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Ioc (f a) (f b) \u2286 f '' (Ioc a b) :=\nor.elim (eq_or_lt_of_le hab) (\u03bb he y h, absurd h.2 (not_le_of_lt (he \u25b8 h.1)))\n(\u03bb hlt, @is_preconnected.intermediate_value_Ioc _ _ _ _ _ _ _ (is_preconnected_Ioc)\n  _ _ \u27e8hlt, refl b\u27e9 (left_nhds_within_Ioc_ne_bot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self)\n  _ ((hf.continuous_within_at \u27e8refl a, hab\u27e9).mono Ioc_subset_Icc_self))\n\nlemma intermediate_value_Ioc' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Ico (f b) (f a) \u2286 f '' (Ioc a b) :=\nor.elim (eq_or_lt_of_le hab) (\u03bb he y h, absurd h.1 (not_le_of_lt (he \u25b8 h.2)))\n(\u03bb hlt, @is_preconnected.intermediate_value_Ico _ _ _ _ _ _ _ (is_preconnected_Ioc)\n  _ _ \u27e8hlt, refl b\u27e9 (left_nhds_within_Ioc_ne_bot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self)\n  _ ((hf.continuous_within_at \u27e8refl a, hab\u27e9).mono Ioc_subset_Icc_self))\n\nlemma intermediate_value_Ioo {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Ioo (f a) (f b) \u2286 f '' (Ioo a b) :=\nor.elim (eq_or_lt_of_le hab) (\u03bb he y h, absurd h.2 (not_lt_of_lt (he \u25b8 h.1)))\n(\u03bb hlt, @is_preconnected.intermediate_value_Ioo _ _ _ _ _ _ _ (is_preconnected_Ioo)\n  _ _ (left_nhds_within_Ioo_ne_bot hlt) (right_nhds_within_Ioo_ne_bot hlt)\n  inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self)\n  _ _ ((hf.continuous_within_at \u27e8refl a, hab\u27e9).mono Ioo_subset_Icc_self)\n  ((hf.continuous_within_at \u27e8hab, refl b\u27e9).mono Ioo_subset_Icc_self))\n\nlemma intermediate_value_Ioo' {a b : \u03b1} (hab : a \u2264 b) {f : \u03b1 \u2192 \u03b4} (hf : continuous_on f (Icc a b)) :\n  Ioo (f b) (f a) \u2286 f '' (Ioo a b) :=\nor.elim (eq_or_lt_of_le hab) (\u03bb he y h, absurd h.1 (not_lt_of_lt (he \u25b8 h.2)))\n(\u03bb hlt, @is_preconnected.intermediate_value_Ioo _ _ _ _ _ _ _ (is_preconnected_Ioo)\n  _ _ (right_nhds_within_Ioo_ne_bot hlt) (left_nhds_within_Ioo_ne_bot hlt)\n  inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self)\n  _ _ ((hf.continuous_within_at \u27e8hab, refl b\u27e9).mono Ioo_subset_Icc_self)\n  ((hf.continuous_within_at \u27e8refl a, hab\u27e9).mono Ioo_subset_Icc_self))\n\n/-- **Intermediate value theorem**: if `f` is continuous on an order-connected set `s` and `a`,\n`b` are two points of this set, then `f` sends `s` to a superset of `Icc (f x) (f y)`. -/\nlemma continuous_on.surj_on_Icc {s : set \u03b1} [hs : ord_connected s] {f : \u03b1 \u2192 \u03b4}\n  (hf : continuous_on f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n  surj_on f s (Icc (f a) (f b)) :=\nhs.is_preconnected.intermediate_value ha hb hf\n\n/-- **Intermediate value theorem**: if `f` is continuous on an order-connected set `s` and `a`,\n`b` are two points of this set, then `f` sends `s` to a superset of `[f x, f y]`. -/\nlemma continuous_on.surj_on_interval {s : set \u03b1} [hs : ord_connected s] {f : \u03b1 \u2192 \u03b4}\n  (hf : continuous_on f s) {a b : \u03b1} (ha : a \u2208 s) (hb : b \u2208 s) :\n  surj_on f s (interval (f a) (f b)) :=\nby cases le_total (f a) (f b) with hab hab; simp [hf.surj_on_Icc, *]\n\n/-- A continuous function which tendsto `at_top` `at_top` and to `at_bot` `at_bot` is surjective. -/\nlemma continuous.surjective {f : \u03b1 \u2192 \u03b4} (hf : continuous f) (h_top : tendsto f at_top at_top)\n  (h_bot : tendsto f at_bot at_bot) :\n  function.surjective f :=\n\u03bb p, mem_range_of_exists_le_of_exists_ge hf\n  (h_bot.eventually (eventually_le_at_bot p)).exists\n  (h_top.eventually (eventually_ge_at_top p)).exists\n\n/-- A continuous function which tendsto `at_bot` `at_top` and to `at_top` `at_bot` is surjective. -/\nlemma continuous.surjective' {f : \u03b1 \u2192 \u03b4} (hf : continuous f) (h_top : tendsto f at_bot at_top)\n  (h_bot : tendsto f at_top at_bot) :\n  function.surjective f :=\n@continuous.surjective (order_dual \u03b1) _ _ _ _ _ _ _ _ _ hf h_top h_bot\n\n/-- If a function `f : \u03b1 \u2192 \u03b2` is continuous on a nonempty interval `s`, its restriction to `s`\ntends to `at_bot : filter \u03b2` along `at_bot : filter \u21a5s` and tends to `at_top : filter \u03b2` along\n`at_top : filter \u21a5s`, then the restriction of `f` to `s` is surjective. We formulate the\nconclusion as `surj_on f s univ`. -/\nlemma continuous_on.surj_on_of_tendsto {f : \u03b1 \u2192 \u03b4} {s : set \u03b1} [ord_connected s]\n  (hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (\u03bb x : s, f x) at_bot at_bot)\n  (htop : tendsto (\u03bb x : s, f x) at_top at_top) :\n  surj_on f s univ :=\nby haveI := classical.inhabited_of_nonempty hs.to_subtype;\n  exact (surj_on_iff_surjective.2 $\n    (continuous_on_iff_continuous_restrict.1 hf).surjective htop hbot)\n\n/-- If a function `f : \u03b1 \u2192 \u03b2` is continuous on a nonempty interval `s`, its restriction to `s`\ntends to `at_top : filter \u03b2` along `at_bot : filter \u21a5s` and tends to `at_bot : filter \u03b2` along\n`at_top : filter \u21a5s`, then the restriction of `f` to `s` is surjective. We formulate the\nconclusion as `surj_on f s univ`. -/\nlemma continuous_on.surj_on_of_tendsto' {f : \u03b1 \u2192 \u03b4} {s : set \u03b1} [ord_connected s]\n  (hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (\u03bb x : s, f x) at_bot at_top)\n  (htop : tendsto (\u03bb x : s, f x) at_top at_bot) :\n  surj_on f s univ :=\n@continuous_on.surj_on_of_tendsto \u03b1 _ _ _ _ (order_dual \u03b4) _ _ _ _ _ _ hs hf hbot htop\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/algebra/ordered/intermediate_value.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979306, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7032783600963655}}
{"text": "import data.list\nimport data.finset\nimport tactic\nimport myoption\n\nopen list\n\nnamespace list\n\nuniverse u\n\nlemma init_length_is_pred {A : Type u} {xs : list A} (h : xs \u2260 [])\n: xs.init.length = xs.length - 1 :=\nbegin\n  induction xs with x\u2080 xs ih, refl,\n  cases xs with x\u2081 xs, refl,\n  simp [init] at \u22a2 ih,\n  exact ih,\nend\n\nlemma init_nth {A : Type u} {xs : list A} (i : \u2115) (h : i + 1 < xs.length)\n: xs.init.nth i = xs.nth i :=\nbegin\n  induction xs with x\u2080 xs ih generalizing i, refl,\n  simp at h,\n  cases xs with x\u2081 xs, dsimp at h, exfalso, linarith only [h],\n  cases i, refl,\n  dsimp [init] at \u22a2,\n  exact ih i h,\nend\n\nlemma init_rep_nth {A : Type u} (f : \u2115 \u2192 list A)\n(sys : \u2200 k, f k = (f k.succ).init) (lens : \u2200 k, (f k).length = k)\n(i a b : \u2115) (h\u2081 : i < a) (h\u2082 : a \u2264 b)\n: list.nth (f a) i = list.nth (f b) i :=\nbegin\n  induction b with b ihb generalizing a,\n  exfalso, linarith only [h\u2081, h\u2082],\n  change a \u2264 b + 1 at h\u2082,\n  cases nat.eq_or_lt_of_le h\u2082 with h\u2083 h\u2083, rw h\u2083,\n  rw \u2190 init_nth i (_ : i + 1 < (f b.succ).length),\n  rw \u2190 sys,\n  exact ihb a h\u2081 (by linarith),\n  rw lens,\n  change _ < _ + 1, linarith,\nend\n\n@[norm_cast]\nlemma coe_nth {A B} [has_lift_t A B] (xs : list A) (i : \u2115)\n: (\u2191xs : list B).nth i = (\u2191(xs.nth i) : option B) :=\nbegin\n  unfold_coes, simp,\nend\n\n\n-- Produces a function \u2115 \u2192 A starting with the given list, then a constant value after that.\ndef as_fn {A : Type u} : list A \u2192 A \u2192 \u2115 \u2192 A\n| xs a i := option.get_or_else (xs.nth i) a\n\nlemma as_fn_inrange {A : Type u} {a : A} {xs : list A} {i : \u2115} (h : i < xs.init.length)\n: xs.init.as_fn a i = xs.as_fn a i :=\nbegin\n  dsimp only [as_fn, nth],\n  have h' : i + 1 < xs.length, {\n    cases xs with x\u2080 xs, dsimp [init] at h, linarith only [h],\n    have neq : (list.cons x\u2080 xs) \u2260 [], tauto,\n    rw init_length_is_pred neq at h, simp at h \u22a2, exact h,\n  },\n  rw init_nth i h',\nend\n\n-- range2 a n is the list [a, a+1, a+2, ..., a+n-1]\n@[simp] def range2 : \u2115 \u2192 \u2115 \u2192 list \u2115\n| _ 0 := []\n| a (b+1) := a :: range2 (a + 1) b\n\nprotected\nlemma range2_red_nth (a b i : \u2115)\n: (range2 a (b + i)).nth i = (range2 (a+i) b).nth 0 :=\nbegin\n  induction i with i ih generalizing a b,\n  refl,\n  change (range2 (a + 1) (b + i)).nth i = _,\n  rw ih,\n  ring,\nend\n\n@[simp] lemma range2_nth (a b i : \u2115) (h : i < b)\n: (range2 a b).nth i = some (a + i) :=\nbegin\n  have eq : b = (b - i) + i, omega,\n  rw eq,\n  rw list.range2_red_nth,\n  cases (b - i), exfalso, linarith,\n  refl,\nend\n\n@[simp] lemma range2_length (a b : \u2115) : (range2 a b).length = b :=\nbegin\n  induction b with b ihb generalizing a,\n  refl, simp, rw ihb,\nend\n\nend list\n", "meta": {"author": "kmill", "repo": "lean-graphcoloring", "sha": "1bb2050ed358ff647186f89922d6a09b838444e5", "save_path": "github-repos/lean/kmill-lean-graphcoloring", "path": "github-repos/lean/kmill-lean-graphcoloring/lean-graphcoloring-1bb2050ed358ff647186f89922d6a09b838444e5/src/mylist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7032783373413132}}
{"text": "import MyNat.Power\nimport AdditionWorld.Level5 -- one_eq_succ_zero\nimport MultiplicationWorld.Level3 -- one_mul\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Power World\n\n## Level 3: `pow_one`\n\n## Lemma\nFor all naturals `a`, `a ^ 1 = a`.\n-/\nlemma pow_one (a : MyNat) : a ^ (1 : MyNat) = a := by\n  rw [one_eq_succ_zero]\n  rw [pow_succ]\n  rw [pow_zero]\n  rw [one_mul]\n\n\n/-!\nNext up [Level 4](./Level4.lean.md)\n-/", "meta": {"author": "leanprover", "repo": "lean4-samples", "sha": "5c0db5f1e952e7ebada506ba3a390040972293a9", "save_path": "github-repos/lean/leanprover-lean4-samples", "path": "github-repos/lean/leanprover-lean4-samples/lean4-samples-5c0db5f1e952e7ebada506ba3a390040972293a9/NaturalNumbers/PowerWorld/Level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.7032410105601213}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\n\n! This file was ported from Lean 3 source module logic.encodable.basic\n! leanprover-community/mathlib commit 7c523cb78f4153682c2929e3006c863bfef463d0\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Logic.Equiv.Nat\nimport Mathlib.Data.PNat.Basic\nimport Mathlib.Order.Directed\nimport Mathlib.Data.Countable.Defs\nimport Mathlib.Order.RelIso.Basic\nimport Mathlib.Data.Fin.Basic\n\n/-!\n# Encodable types\n\nThis file defines encodable (constructively countable) types as a typeclass.\nThis is used to provide explicit encode/decode functions from and to `\u2115`, with the information that\nthose functions are inverses of each other.\nThe difference with `Denumerable` is that finite types are encodable. For infinite types,\n`Encodable` and `Denumerable` agree.\n\n## Main declarations\n\n* `Encodable \u03b1`: States that there exists an explicit encoding function `encode : \u03b1 \u2192 \u2115` with a\n  partial inverse `decode : \u2115 \u2192 Option \u03b1`.\n* `decode\u2082`: Version of `decode` that is equal to `none` outside of the range of `encode`. Useful as\n  we do not require this in the definition of `decode`.\n* `ulower \u03b1`: Any encodable type has an equivalent type living in the lowest universe, namely a\n  subtype of `\u2115`. `ulower \u03b1` finds it.\n\n## Implementation notes\n\nThe point of asking for an explicit partial inverse `decode : \u2115 \u2192 Option \u03b1` to `encode : \u03b1 \u2192 \u2115` is\nto make the range of `encode` decidable even when the finiteness of `\u03b1` is not.\n-/\n\n\nopen Option List Nat Function\n\n/-- Constructively countable type. Made from an explicit injection `encode : \u03b1 \u2192 \u2115` and a partial\ninverse `decode : \u2115 \u2192 Option \u03b1`. Note that finite types *are* countable. See `Denumerable` if you\nwish to enforce infiniteness. -/\nclass Encodable (\u03b1 : Type _) where\n  /-- Encoding from Type \u03b1 to \u2115 -/\n  encode : \u03b1 \u2192 \u2115\n  --Porting note: was `decode [] : \u2115 \u2192 Option \u03b1`. This means that `decode` does not take the type\n  --explicitly in Lean4\n  /-- Decoding from \u2115 to Option \u03b1-/\n  decode : \u2115 \u2192 Option \u03b1\n  /-- Invariant relationship between encoding and decoding-/\n  encodek : \u2200 a, decode (encode a) = some a\n#align encodable Encodable\n\nattribute [simp] Encodable.encodek\n\nnamespace Encodable\n\nvariable {\u03b1 : Type _} {\u03b2 : Type _}\n\nuniverse u\n\ntheorem encode_injective [Encodable \u03b1] : Function.Injective (@encode \u03b1 _)\n  | x, y, e => Option.some.inj <| by rw [\u2190 encodek, e, encodek]\n#align encodable.encode_injective Encodable.encode_injective\n\n@[simp]\ntheorem encode_inj [Encodable \u03b1] {a b : \u03b1} : encode a = encode b \u2194 a = b :=\n  encode_injective.eq_iff\n#align encodable.encode_inj Encodable.encode_inj\n\n-- The priority of the instance below is less than the priorities of `Subtype.Countable`\n-- and `Quotient.Countable`\ninstance (priority := 400) countable [Encodable \u03b1] : Countable \u03b1 where\n  exists_injective_nat' := \u27e8_,encode_injective\u27e9\n\ntheorem surjective_decode_iget (\u03b1 : Type _) [Encodable \u03b1] [Inhabited \u03b1] :\n    Surjective fun n => ((Encodable.decode n).iget : \u03b1) := fun x =>\n  \u27e8Encodable.encode x, by simp_rw [Encodable.encodek]\u27e9\n#align encodable.surjective_decode_iget Encodable.surjective_decode_iget\n\n/-- An encodable type has decidable equality. Not set as an instance because this is usually not the\nbest way to infer decidability. -/\ndef decidableEqOfEncodable (\u03b1) [Encodable \u03b1] : DecidableEq \u03b1\n  | _, _ => decidable_of_iff _ encode_inj\n#align encodable.decidable_eq_of_encodable Encodable.decidableEqOfEncodable\n\n/-- If `\u03b1` is encodable and there is an injection `f : \u03b2 \u2192 \u03b1`, then `\u03b2` is encodable as well. -/\ndef ofLeftInjection [Encodable \u03b1] (f : \u03b2 \u2192 \u03b1) (finv : \u03b1 \u2192 Option \u03b2)\n    (linv : \u2200 b, finv (f b) = some b) : Encodable \u03b2 :=\n  \u27e8fun b => encode (f b), fun n => (decode n).bind finv, fun b => by\n    simp [Encodable.encodek, linv]\u27e9\n#align encodable.of_left_injection Encodable.ofLeftInjection\n\n/-- If `\u03b1` is encodable and `f : \u03b2 \u2192 \u03b1` is invertible, then `\u03b2` is encodable as well. -/\ndef ofLeftInverse [Encodable \u03b1] (f : \u03b2 \u2192 \u03b1) (finv : \u03b1 \u2192 \u03b2) (linv : \u2200 b, finv (f b) = b) :\n    Encodable \u03b2 :=\n  ofLeftInjection f (some \u2218 finv) fun b => congr_arg some (linv b)\n#align encodable.of_left_inverse Encodable.ofLeftInverse\n\n/-- Encodability is preserved by equivalence. -/\ndef ofEquiv (\u03b1) [Encodable \u03b1] (e : \u03b2 \u2243 \u03b1) : Encodable \u03b2 :=\n  ofLeftInverse e e.symm e.left_inv\n#align encodable.of_equiv Encodable.ofEquiv\n\n-- Porting note: removing @[simp], too powerful\ntheorem encode_ofEquiv {\u03b1 \u03b2} [Encodable \u03b1] (e : \u03b2 \u2243 \u03b1) (b : \u03b2) :\n    @encode _ (ofEquiv _ e) b = encode (e b) :=\n  rfl\n#align encodable.encode_of_equiv Encodable.encode_ofEquiv\n\n-- Porting note: removing @[simp], too powerful\ntheorem decode_ofEquiv {\u03b1 \u03b2} [Encodable \u03b1] (e : \u03b2 \u2243 \u03b1) (n : \u2115) :\n    @decode _ (ofEquiv _ e) n = (decode n).map e.symm :=\n  show Option.bind _ _ = Option.map _ _\n  by rw [Option.map_eq_bind]\n#align encodable.decode_of_equiv Encodable.decode_ofEquiv\n\ninstance Nat.encodable : Encodable \u2115 :=\n  \u27e8id, some, fun _ => rfl\u27e9\n#align nat.encodable Encodable.Nat.encodable\n\n@[simp]\ntheorem encode_nat (n : \u2115) : encode n = n :=\n  rfl\n#align encodable.encode_nat Encodable.encode_nat\n\n@[simp 1100]\ntheorem decode_nat (n : \u2115) : decode n = some n :=\n  rfl\n#align encodable.decode_nat Encodable.decode_nat\n\ninstance (priority := 100) IsEmpty.toEncodable [IsEmpty \u03b1] : Encodable \u03b1 :=\n  \u27e8isEmptyElim, fun _ => none, isEmptyElim\u27e9\n#align is_empty.to_encodable Encodable.IsEmpty.toEncodable\n\ninstance PUnit.encodable : Encodable PUnit :=\n  \u27e8fun _ => 0, fun n => Nat.casesOn n (some PUnit.unit) fun _ => none, fun _ => by simp\u27e9\n#align punit.encodable Encodable.PUnit.encodable\n\n@[simp]\ntheorem encode_star : encode PUnit.unit = 0 :=\n  rfl\n#align encodable.encode_star Encodable.encode_star\n\n@[simp]\ntheorem decode_unit_zero : decode 0 = some PUnit.unit :=\n  rfl\n#align encodable.decode_unit_zero Encodable.decode_unit_zero\n\n@[simp]\ntheorem decode_unit_succ (n) : decode (succ n) = (none : Option PUnit) :=\n  rfl\n#align encodable.decode_unit_succ Encodable.decode_unit_succ\n\n/-- If `\u03b1` is encodable, then so is `Option \u03b1`. -/\ninstance _root_.Option.encodable {\u03b1 : Type _} [h : Encodable \u03b1] : Encodable (Option \u03b1) :=\n  \u27e8fun o => Option.casesOn o Nat.zero fun a => succ (encode a), fun n =>\n    Nat.casesOn n (some none) fun m => (decode m).map some, fun o => by\n    cases o <;> dsimp ; simp [encodek, Nat.succ_ne_zero]\u27e9\n#align option.encodable Option.encodable\n\n@[simp]\ntheorem encode_none [Encodable \u03b1] : encode (@none \u03b1) = 0 :=\n  rfl\n#align encodable.encode_none Encodable.encode_none\n\n@[simp]\ntheorem encode_some [Encodable \u03b1] (a : \u03b1) : encode (some a) = succ (encode a) :=\n  rfl\n#align encodable.encode_some Encodable.encode_some\n\n@[simp]\ntheorem decode_option_zero [Encodable \u03b1] : (decode 0 : Option (Option \u03b1))= some none :=\n  rfl\n#align encodable.decode_option_zero Encodable.decode_option_zero\n\n@[simp]\ntheorem decode_option_succ [Encodable \u03b1] (n) :\n    (decode (succ n) : Option (Option \u03b1)) = (decode n).map some :=\n  rfl\n#align encodable.decode_option_succ Encodable.decode_option_succ\n\n/-- Failsafe variant of `decode`. `decode\u2082 \u03b1 n` returns the preimage of `n` under `encode` if it\nexists, and returns `none` if it doesn't. This requirement could be imposed directly on `decode` but\nis not to help make the definition easier to use. -/\ndef decode\u2082 (\u03b1) [Encodable \u03b1] (n : \u2115) : Option \u03b1 :=\n  (decode n).bind (Option.guard fun a => encode a = n)\n#align encodable.decode\u2082 Encodable.decode\u2082\n\ntheorem mem_decode\u2082' [Encodable \u03b1] {n : \u2115} {a : \u03b1} :\n    a \u2208 decode\u2082 \u03b1 n \u2194 a \u2208 decode n \u2227 encode a = n := by\n  simp [decode\u2082] ; exact \u27e8fun \u27e8_, h\u2081, rfl, h\u2082\u27e9 => \u27e8h\u2081, h\u2082\u27e9, fun \u27e8h\u2081, h\u2082\u27e9 => \u27e8_, h\u2081, rfl, h\u2082\u27e9\u27e9\n#align encodable.mem_decode\u2082' Encodable.mem_decode\u2082'\n\ntheorem mem_decode\u2082 [Encodable \u03b1] {n : \u2115} {a : \u03b1} : a \u2208 decode\u2082 \u03b1 n \u2194 encode a = n :=\n  mem_decode\u2082'.trans (and_iff_right_of_imp fun e => e \u25b8 encodek _)\n#align encodable.mem_decode\u2082 Encodable.mem_decode\u2082\n\ntheorem decode\u2082_eq_some [Encodable \u03b1] {n : \u2115} {a : \u03b1} : decode\u2082 \u03b1 n = some a \u2194 encode a = n :=\n  mem_decode\u2082\n#align encodable.decode\u2082_eq_some Encodable.decode\u2082_eq_some\n\n@[simp]\ntheorem decode\u2082_encode [Encodable \u03b1] (a : \u03b1) : decode\u2082 \u03b1 (encode a) = some a :=\n  by\n  ext\n  simp [mem_decode\u2082, eq_comm, decode\u2082_eq_some]\n#align encodable.decode\u2082_encode Encodable.decode\u2082_encode\n\ntheorem decode\u2082_ne_none_iff [Encodable \u03b1] {n : \u2115} :\n    decode\u2082 \u03b1 n \u2260 none \u2194 n \u2208 Set.range (encode : \u03b1 \u2192 \u2115) := by\n  simp_rw [Set.range, Set.mem_setOf_eq, Ne.def, Option.eq_none_iff_forall_not_mem,\n    Encodable.mem_decode\u2082, not_forall, not_not]\n#align encodable.decode\u2082_ne_none_iff Encodable.decode\u2082_ne_none_iff\n\n\n\ntheorem decode\u2082_inj [Encodable \u03b1] {n : \u2115} {a\u2081 a\u2082 : \u03b1} (h\u2081 : a\u2081 \u2208 decode\u2082 \u03b1 n)\n    (h\u2082 : a\u2082 \u2208 decode\u2082 \u03b1 n) : a\u2081 = a\u2082 :=\n  encode_injective <| (mem_decode\u2082.1 h\u2081).trans (mem_decode\u2082.1 h\u2082).symm\n#align encodable.decode\u2082_inj Encodable.decode\u2082_inj\n\ntheorem encodek\u2082 [Encodable \u03b1] (a : \u03b1) : decode\u2082 \u03b1 (encode a) = some a :=\n  mem_decode\u2082.2 rfl\n#align encodable.encodek\u2082 Encodable.encodek\u2082\n\n/-- The encoding function has decidable range. -/\ndef decidableRangeEncode (\u03b1 : Type _) [Encodable \u03b1] : DecidablePred (\u00b7 \u2208 Set.range (@encode \u03b1 _)) :=\n  fun x =>\n  decidable_of_iff (Option.isSome (decode\u2082 \u03b1 x))\n    \u27e8fun h => \u27e8Option.get _ h, by rw [\u2190 decode\u2082_is_partial_inv (Option.get _ h), Option.some_get]\u27e9,\n      fun \u27e8n, hn\u27e9 => by rw [\u2190 hn, encodek\u2082] ; exact rfl\u27e9\n#align encodable.decidable_range_encode Encodable.decidableRangeEncode\n\n/-- An encodable type is equivalent to the range of its encoding function. -/\ndef equivRangeEncode (\u03b1 : Type _) [Encodable \u03b1] : \u03b1 \u2243 Set.range (@encode \u03b1 _)\n    where\n  toFun := fun a : \u03b1 => \u27e8encode a, Set.mem_range_self _\u27e9\n  invFun n :=\n    Option.get _\n      (show isSome (decode\u2082 \u03b1 n.1) by cases' n.2 with x hx ; rw [\u2190 hx, encodek\u2082] ; exact rfl)\n  left_inv a := by dsimp ; rw [\u2190 Option.some_inj, Option.some_get, encodek\u2082]\n  right_inv := fun \u27e8n, x, hx\u27e9 => by\n    apply Subtype.eq\n    dsimp\n    conv =>\n      rhs\n      rw [\u2190 hx]\n    rw [encode_injective.eq_iff, \u2190 Option.some_inj, Option.some_get, \u2190 hx, encodek\u2082]\n#align encodable.equiv_range_encode Encodable.equivRangeEncode\n\n/-- A type with unique element is encodable. This is not an instance to avoid diamonds. -/\ndef Unique.encodable [Unique \u03b1] : Encodable \u03b1 :=\n  \u27e8fun _ => 0, fun _ => some default, Unique.forall_iff.2 rfl\u27e9\n#align unique.encodable Encodable.Unique.encodable\n\nsection Sum\n\nvariable [Encodable \u03b1] [Encodable \u03b2]\n\n--Porting note: removing bit0 and bit1\n/-- Explicit encoding function for the sum of two encodable types. -/\ndef encodeSum : Sum \u03b1 \u03b2 \u2192 \u2115\n  | Sum.inl a => 2 * encode a\n  | Sum.inr b => 2 * encode b + 1\n#align encodable.encode_sum Encodable.encodeSum\n\n/-- Explicit decoding function for the sum of two encodable types. -/\ndef decodeSum (n : \u2115) : Option (Sum \u03b1 \u03b2) :=\n  match boddDiv2 n with\n  | (false, m) => (decode m : Option \u03b1).map Sum.inl\n  | (_, m) => (decode m : Option \u03b2).map Sum.inr\n#align encodable.decode_sum Encodable.decodeSum\n\n/-- If `\u03b1` and `\u03b2` are encodable, then so is their sum. -/\ninstance Sum.encodable : Encodable (Sum \u03b1 \u03b2) :=\n  \u27e8encodeSum, decodeSum, fun s => by cases s <;> simp [encodeSum, div2_val, decodeSum, encodek]\u27e9\n#align sum.encodable Encodable.Sum.encodable\n\n--Porting note: removing bit0 and bit1 from statement\n@[simp]\ntheorem encode_inl (a : \u03b1) : @encode (Sum \u03b1 \u03b2) _ (Sum.inl a) = 2 * (encode a) :=\n  rfl\n#align encodable.encode_inl Encodable.encode_inl\u2093\n\n--Porting note: removing bit0 and bit1 from statement\n@[simp]\ntheorem encode_inr (b : \u03b2) : @encode (Sum \u03b1 \u03b2) _ (Sum.inr b) = 2 * (encode b) + 1 :=\n  rfl\n#align encodable.encode_inr Encodable.encode_inr\u2093\n\n@[simp]\ntheorem decode_sum_val (n : \u2115) : (decode n : Option (Sum \u03b1 \u03b2)) = decodeSum n :=\n  rfl\n#align encodable.decode_sum_val Encodable.decode_sum_val\n\nend Sum\n\ninstance Bool.encodable : Encodable Bool :=\n  ofEquiv (Sum Unit Unit) Equiv.boolEquivPUnitSumPUnit\n#align bool.encodable Encodable.Bool.encodable\n\n@[simp]\ntheorem encode_true : encode true = 1 :=\n  rfl\n#align encodable.encode_tt Encodable.encode_true\n\n@[simp]\ntheorem encode_false : encode false = 0 :=\n  rfl\n#align encodable.encode_ff Encodable.encode_false\n\n@[simp]\ntheorem decode_zero : (decode 0 : Option Bool) = some false :=\n  rfl\n#align encodable.decode_zero Encodable.decode_zero\n\n@[simp]\ntheorem decode_one : (decode 1: Option Bool) = some true :=\n  rfl\n#align encodable.decode_one Encodable.decode_one\n\ntheorem decode_ge_two (n) (h : 2 \u2264 n) : (decode n : Option Bool) = none :=\n  by\n  suffices decodeSum n = none by\n    change (decodeSum n).bind _ = none\n    rw [this]\n    rfl\n  have : 1 \u2264 n / 2 := by\n    rw [Nat.le_div_iff_mul_le]\n    exacts[h, by decide]\n  cases' exists_eq_succ_of_ne_zero (_root_.ne_of_gt this) with m e\n  simp [decodeSum, div2_val]; cases bodd n <;> simp [e]\n#align encodable.decode_ge_two Encodable.decode_ge_two\n\nnoncomputable instance Prop.encodable : Encodable Prop :=\n  ofEquiv Bool Equiv.propEquivBool\n#align Prop.encodable Encodable.Prop.encodable\n\nsection Sigma\n\nvariable {\u03b3 : \u03b1 \u2192 Type _} [Encodable \u03b1] [\u2200 a, Encodable (\u03b3 a)]\n\n/-- Explicit encoding function for `Sigma \u03b3` -/\ndef encodeSigma : Sigma \u03b3 \u2192 \u2115\n  | \u27e8a, b\u27e9 => pair (encode a) (encode b)\n#align encodable.encode_sigma Encodable.encodeSigma\n\n/-- Explicit decoding function for `Sigma \u03b3` -/\ndef decodeSigma (n : \u2115) : Option (Sigma \u03b3) :=\n  let (n\u2081, n\u2082) := unpair n\n  (decode n\u2081).bind fun a => (decode n\u2082).map <| Sigma.mk a\n#align encodable.decode_sigma Encodable.decodeSigma\n\ninstance Sigma.encodable : Encodable (Sigma \u03b3) :=\n  \u27e8encodeSigma, decodeSigma, fun \u27e8a, b\u27e9 => by\n    simp [encodeSigma, decodeSigma, unpair_pair, encodek]\u27e9\n#align sigma.encodable Encodable.Sigma.encodable\n\n@[simp]\ntheorem decode_sigma_val (n : \u2115) :\n    (decode n : Option (Sigma \u03b3)) =\n      (decode n.unpair.1).bind fun a => (decode n.unpair.2).map <| Sigma.mk a :=\n  rfl\n#align encodable.decode_sigma_val Encodable.decode_sigma_val\n\n@[simp]\ntheorem encode_sigma_val (a b) : @encode (Sigma \u03b3) _ \u27e8a, b\u27e9 = pair (encode a) (encode b) :=\n  rfl\n#align encodable.encode_sigma_val Encodable.encode_sigma_val\n\nend Sigma\n\nsection Prod\n\nvariable [Encodable \u03b1] [Encodable \u03b2]\n\n/-- If `\u03b1` and `\u03b2` are encodable, then so is their product. -/\ninstance Prod.encodable : Encodable (\u03b1 \u00d7 \u03b2) :=\n  ofEquiv _ (Equiv.sigmaEquivProd \u03b1 \u03b2).symm\n\n@[simp]\ntheorem decode_prod_val [i : Encodable \u03b1] (n : \u2115) :\n    (@decode (\u03b1 \u00d7 \u03b2) _ n : Option (\u03b1 \u00d7 \u03b2))\n      = (decode n.unpair.1).bind fun a => (decode n.unpair.2).map <| Prod.mk a := by\n  simp only [decode_ofEquiv, Equiv.symm_symm, decode_sigma_val]\n  cases (decode n.unpair.1 : Option \u03b1) <;> cases (decode n.unpair.2 : Option \u03b2)\n  <;> rfl\n#align encodable.decode_prod_val Encodable.decode_prod_val\n\n@[simp]\ntheorem encode_prod_val (a b) : @encode (\u03b1 \u00d7 \u03b2) _ (a, b) = pair (encode a) (encode b) :=\n  rfl\n#align encodable.encode_prod_val Encodable.encode_prod_val\n\nend Prod\n\nsection Subtype\n\nopen Subtype Decidable\n\nvariable {P : \u03b1 \u2192 Prop} [encA : Encodable \u03b1] [decP : DecidablePred P]\n\n--include encA\n\n/-- Explicit encoding function for a decidable subtype of an encodable type -/\ndef encodeSubtype : { a : \u03b1 // P a } \u2192 \u2115\n  | \u27e8v,_\u27e9 => encode v\n#align encodable.encode_subtype Encodable.encodeSubtype\n\n--include decP\n\n/-- Explicit decoding function for a decidable subtype of an encodable type -/\ndef decodeSubtype (v : \u2115) : Option { a : \u03b1 // P a } :=\n  (decode v).bind fun a => if h : P a then some \u27e8a, h\u27e9 else none\n#align encodable.decode_subtype Encodable.decodeSubtype\n\n/-- A decidable subtype of an encodable type is encodable. -/\ninstance Subtype.encodable : Encodable { a : \u03b1 // P a } :=\n  \u27e8encodeSubtype, decodeSubtype, fun \u27e8v, h\u27e9 => by simp [encodeSubtype, decodeSubtype, encodek, h]\u27e9\n#align subtype.encodable Encodable.Subtype.encodable\n\ntheorem Subtype.encode_eq (a : Subtype P) : encode a = encode a.val := by cases a ; rfl\n#align encodable.subtype.encode_eq Encodable.Subtype.encode_eq\n\nend Subtype\n\ninstance Fin.encodable (n) : Encodable (Fin n) :=\n  ofEquiv _ Fin.equivSubtype\n#align fin.encodable Encodable.Fin.encodable\n\ninstance Int.encodable : Encodable \u2124 :=\n  ofEquiv _ Equiv.intEquivNat\n#align int.encodable Encodable.Int.encodable\n\ninstance PNat.encodable : Encodable \u2115+ :=\n  ofEquiv _ Equiv.pnatEquivNat\n#align pnat.encodable Encodable.PNat.encodable\n\n/-- The lift of an encodable type is encodable. -/\ninstance ULift.encodable [Encodable \u03b1] : Encodable (ULift \u03b1) :=\n  ofEquiv _ Equiv.ulift\n#align ulift.encodable Encodable.ULift.encodable\n\n/-- The lift of an encodable type is encodable. -/\ninstance PLift.encodable [Encodable \u03b1] : Encodable (PLift \u03b1) :=\n  ofEquiv _ Equiv.plift\n#align plift.encodable Encodable.PLift.encodable\n\n/-- If `\u03b2` is encodable and there is an injection `f : \u03b1 \u2192 \u03b2`, then `\u03b1` is encodable as well. -/\nnoncomputable def ofInj [Encodable \u03b2] (f : \u03b1 \u2192 \u03b2) (hf : Injective f) : Encodable \u03b1 :=\n  ofLeftInjection f (partialInv f) fun _ => (partialInv_of_injective hf _ _).2 rfl\n#align encodable.of_inj Encodable.ofInj\n\n/-- If `\u03b1` is countable, then it has a (non-canonical) `Encodable` structure. -/\nnoncomputable def ofCountable (\u03b1 : Type _) [Countable \u03b1] : Encodable \u03b1 :=\n  Nonempty.some <|\n    let \u27e8f, hf\u27e9 := exists_injective_nat \u03b1\n    \u27e8ofInj f hf\u27e9\n#align encodable.of_countable Encodable.ofCountable\n\n@[simp]\ntheorem nonempty_encodable : Nonempty (Encodable \u03b1) \u2194 Countable \u03b1 :=\n  \u27e8fun \u27e8h\u27e9 => @Encodable.countable \u03b1 h, fun h => \u27e8@ofCountable _ h\u27e9\u27e9\n#align encodable.nonempty_encodable Encodable.nonempty_encodable\n\nend Encodable\n\n/-- See also `nonempty_fintype`, `nonempty_denumerable`. -/\ntheorem nonempty_encodable (\u03b1 : Type _) [Countable \u03b1] : Nonempty (Encodable \u03b1) :=\n  \u27e8Encodable.ofCountable _\u27e9\n#align nonempty_encodable nonempty_encodable\n\ninstance : Countable \u2115+ := by delta PNat; infer_instance\n\n-- short-circuit instance search\nsection Ulower\n\nattribute [local instance] Encodable.decidableRangeEncode\n\n/-- `ULower \u03b1 : Type` is an equivalent type in the lowest universe, given `Encodable \u03b1`. -/\ndef Ulower (\u03b1 : Type _) [Encodable \u03b1] : Type :=\n  Set.range (Encodable.encode : \u03b1 \u2192 \u2115)\n#align ulower Ulower\n\ninstance {\u03b1 : Type _} [Encodable \u03b1] : DecidableEq (Ulower \u03b1) :=\n  by delta Ulower; exact Encodable.decidableEqOfEncodable _\n\ninstance {\u03b1 : Type _} [Encodable \u03b1] : Encodable (Ulower \u03b1) :=\n  by delta Ulower; infer_instance\n\nend Ulower\n\nnamespace Ulower\n\nvariable (\u03b1 : Type _) [Encodable \u03b1]\n\n/-- The equivalence between the encodable type `\u03b1` and `Ulower \u03b1 : Type`. -/\ndef equiv : \u03b1 \u2243 Ulower \u03b1 :=\n  Encodable.equivRangeEncode \u03b1\n#align ulower.equiv Ulower.equiv\n\nvariable {\u03b1}\n\n/-- Lowers an `a : \u03b1` into `Ulower \u03b1`. -/\ndef down (a : \u03b1) : Ulower \u03b1 :=\n  equiv \u03b1 a\n#align ulower.down Ulower.down\n\ninstance [Inhabited \u03b1] : Inhabited (Ulower \u03b1) :=\n  \u27e8down default\u27e9\n\n/-- Lifts an `a : Ulower \u03b1` into `\u03b1`. -/\ndef up (a : Ulower \u03b1) : \u03b1 :=\n  (equiv \u03b1).symm a\n#align ulower.up Ulower.up\n\n@[simp]\ntheorem down_up {a : Ulower \u03b1} : down a.up = a :=\n  Equiv.right_inv _ _\n#align ulower.down_up Ulower.down_up\n\n@[simp]\ntheorem up_down {a : \u03b1} : (down a).up = a := by\n  simp [up, down,Equiv.left_inv _ _, Equiv.symm_apply_apply]\n#align ulower.up_down Ulower.up_down\n\n@[simp]\ntheorem up_eq_up {a b : Ulower \u03b1} : a.up = b.up \u2194 a = b :=\n  Equiv.apply_eq_iff_eq _\n#align ulower.up_eq_up Ulower.up_eq_up\n\n@[simp]\ntheorem down_eq_down {a b : \u03b1} : down a = down b \u2194 a = b :=\n  Equiv.apply_eq_iff_eq _\n#align ulower.down_eq_down Ulower.down_eq_down\n\n@[ext]\nprotected theorem ext {a b : Ulower \u03b1} : a.up = b.up \u2192 a = b :=\n  up_eq_up.1\n#align ulower.ext Ulower.ext\n\nend Ulower\n\n/-\nChoice function for encodable types and decidable predicates.\nWe provide the following API\n\nchoose      {\u03b1 : Type _} {p : \u03b1 \u2192 Prop} [c : encodable \u03b1] [d : decidable_pred p] : (\u2203 x, p x) \u2192 \u03b1 :=\nchoose_spec {\u03b1 : Type _} {p : \u03b1 \u2192 Prop} [c : encodable \u03b1] [d : decidable_pred p] (ex : \u2203 x, p x) :\n  p (choose ex) :=\n-/\nnamespace Encodable\n\nsection FindA\n\nvariable {\u03b1 : Type _} (p : \u03b1 \u2192 Prop) [Encodable \u03b1] [DecidablePred p]\n\nprivate def good : Option \u03b1 \u2192 Prop\n  | some a => p a\n  | none => False\n\nprivate def decidable_good : DecidablePred (good p) :=\n  fun n => by\n    cases n <;> unfold good <;> dsimp <;> infer_instance\nattribute [local instance] decidable_good\n\nopen Encodable\n\nvariable {p}\n\n/-- Constructive choice function for a decidable subtype of an encodable type. -/\ndef chooseX (h : \u2203 x, p x) : { a : \u03b1 // p a } :=\n  have : \u2203 n, good p (decode n) :=\n    let \u27e8w, pw\u27e9 := h\n    \u27e8encode w, by simp [good, encodek, pw]\u27e9\n  match (motive := \u2200 o, good p o \u2192 { a // p a }) _, Nat.find_spec this with\n  | some a, h => \u27e8a, h\u27e9\n#align encodable.choose_x Encodable.chooseX\n\n/-- Constructive choice function for a decidable predicate over an encodable type. -/\ndef choose (h : \u2203 x, p x) : \u03b1 :=\n  (chooseX h).1\n#align encodable.choose Encodable.choose\n\ntheorem choose_spec (h : \u2203 x, p x) : p (choose h) :=\n  (chooseX h).2\n#align encodable.choose_spec Encodable.choose_spec\n\nend FindA\n\n/-- A constructive version of `Classical.axiom_of_choice` for `Encodable` types. -/\ntheorem axiom_of_choice {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _} {R : \u2200 x, \u03b2 x \u2192 Prop} [\u2200 a, Encodable (\u03b2 a)]\n    [\u2200 x y, Decidable (R x y)] (H : \u2200 x, \u2203 y, R x y) : \u2203 f : \u2200 a, \u03b2 a, \u2200 x, R x (f x) :=\n  \u27e8fun x => choose (H x), fun x => choose_spec (H x)\u27e9\n#align encodable.axiom_of_choice Encodable.axiom_of_choice\n\n/-- A constructive version of `Classical.skolem` for `Encodable` types. -/\ntheorem skolem {\u03b1 : Type _} {\u03b2 : \u03b1 \u2192 Type _} {P : \u2200 x, \u03b2 x \u2192 Prop} [\u2200 a, Encodable (\u03b2 a)]\n    [\u2200 x y, Decidable (P x y)] : (\u2200 x, \u2203 y, P x y) \u2194 \u2203 f : \u2200 a, \u03b2 a, \u2200 x, P x (f x) :=\n  \u27e8axiom_of_choice, fun \u27e8_, H\u27e9 x => \u27e8_, H x\u27e9\u27e9\n#align encodable.skolem Encodable.skolem\n\n/-\nThere is a total ordering on the elements of an encodable type, induced by the map to \u2115.\n-/\n/-- The `encode` function, viewed as an embedding. -/\ndef encode' (\u03b1) [Encodable \u03b1] : \u03b1 \u21aa \u2115 :=\n  \u27e8Encodable.encode, Encodable.encode_injective\u27e9\n#align encodable.encode' Encodable.encode'\n\ninstance {\u03b1} [Encodable \u03b1] : IsTrans _ (encode' \u03b1 \u207b\u00b9'o (\u00b7 \u2264 \u00b7)) :=\n  (RelEmbedding.preimage _ _).isTrans\n\ninstance {\u03b1} [Encodable \u03b1] : IsAntisymm _ (Encodable.encode' \u03b1 \u207b\u00b9'o (\u00b7 \u2264 \u00b7)) :=\n  (RelEmbedding.preimage _ _).isAntisymm\n\ninstance {\u03b1} [Encodable \u03b1] : IsTotal _ (Encodable.encode' \u03b1 \u207b\u00b9'o (\u00b7 \u2264 \u00b7)) :=\n  (RelEmbedding.preimage _ _).isTotal\n\nend Encodable\n\nnamespace Directed\n\nopen Encodable\n\nvariable {\u03b1 : Type _} {\u03b2 : Type _} [Encodable \u03b1] [Inhabited \u03b1]\n\n/-- Given a `Directed r` function `f : \u03b1 \u2192 \u03b2` defined on an encodable inhabited type,\nconstruct a noncomputable sequence such that `r (f (x n)) (f (x (n + 1)))`\nand `r (f a) (f (x (encode a + 1))`. -/\nprotected noncomputable def sequence {r : \u03b2 \u2192 \u03b2 \u2192 Prop} (f : \u03b1 \u2192 \u03b2) (hf : Directed r f) : \u2115 \u2192 \u03b1\n  | 0 => default\n  | n + 1 =>\n    let p := Directed.sequence f hf n\n    match (decode n: Option \u03b1) with\n    | none => Classical.choose (hf p p)\n    | some a => Classical.choose (hf p a)\n#align directed.sequence Directed.sequence\n\ntheorem sequence_mono_nat {r : \u03b2 \u2192 \u03b2 \u2192 Prop} {f : \u03b1 \u2192 \u03b2} (hf : Directed r f) (n : \u2115) :\n    r (f (hf.sequence f n)) (f (hf.sequence f (n + 1))) :=\n  by\n  dsimp [Directed.sequence]\n  generalize eq : hf.sequence f n = p\n  cases' h : (decode n: Option \u03b1) with a\n  \u00b7 exact (Classical.choose_spec (hf p p)).1\n  \u00b7 exact (Classical.choose_spec (hf p a)).1\n#align directed.sequence_mono_nat Directed.sequence_mono_nat\n\ntheorem rel_sequence {r : \u03b2 \u2192 \u03b2 \u2192 Prop} {f : \u03b1 \u2192 \u03b2} (hf : Directed r f) (a : \u03b1) :\n    r (f a) (f (hf.sequence f (encode a + 1))) := by\n  simp only [Directed.sequence, add_eq, add_zero, encodek, and_self]\n  exact (Classical.choose_spec (hf _ a)).2\n#align directed.rel_sequence Directed.rel_sequence\n\nvariable [Preorder \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Directed (\u00b7 \u2264 \u00b7) f)\n\ntheorem sequence_mono : Monotone (f \u2218 hf.sequence f) :=\n  monotone_nat_of_le_succ <| hf.sequence_mono_nat\n#align directed.sequence_mono Directed.sequence_mono\n\ntheorem le_sequence (a : \u03b1) : f a \u2264 f (hf.sequence f (encode a + 1)) :=\n  hf.rel_sequence a\n#align directed.le_sequence Directed.le_sequence\n\nend Directed\n\nsection Quotient\n\nopen Encodable Quotient\n\nvariable {\u03b1 : Type _} {s : Setoid \u03b1} [@DecidableRel \u03b1 (\u00b7 \u2248 \u00b7)] [Encodable \u03b1]\n\n/-- Representative of an equivalence class. This is a computable version of `quot.out` for a setoid\non an encodable type. -/\ndef Quotient.rep (q : Quotient s) : \u03b1 :=\n  choose (exists_rep q)\n#align quotient.rep Quotient.rep\n\ntheorem Quotient.rep_spec (q : Quotient s) : \u27e6q.rep\u27e7 = q :=\n  choose_spec (exists_rep q)\n#align quotient.rep_spec Quotient.rep_spec\n\n/-- The quotient of an encodable space by a decidable equivalence relation is encodable. -/\ndef encodableQuotient : Encodable (Quotient s) :=\n  \u27e8fun q => encode q.rep, fun n => Quotient.mk'' <$> decode n, by\n    rintro \u27e8l\u27e9 ; dsimp ; rw [encodek] ; exact congr_arg some \u27e6l\u27e7.rep_spec\u27e9\n#align encodable_quotient encodableQuotient\n\nend Quotient\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Logic/Encodable/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7032385631485465}}
{"text": "import mynat.definition -- Imports the natural numbers.\nimport mynat.add -- imports addition.\nnamespace mynat -- hide\n\n\n/- Axiom : add_zero (a : mynat) :\na + 0 = a\n-/\n\n/- Axiom : add_succ (a b : mynat) :\na + succ(b) = succ(a + b)\n-/\n\n/- Tactic : induction\n\n## Summary\n\nif `n : mynat` is in our assumptions, then `induction n with d hd`\nattempts to prove the goal by induction on `n`, with the inductive\nassumption in the `succ` case being `hd`.\n\n## Details\n\nIf you have a natural number `n : mynat` in your context\n(above the `\u22a2`) then `induction n with d hd` turns your\ngoal into two goals, a base case with `n = 0` and\nan inductive step where `hd` is a proof of the `n = d`\ncase and your goal is the `n = succ(d)` case.\n\n### Example:\nIf this is our local context:\n```\nn : mynat\n\u22a2 2 * n = n + n\n```\n\nthen\n\n`induction n with d hd`\n\nwill give us two goals:\n\n```\n\u22a2 2 * 0 = 0 + 0\n```\n\nand\n```\nd : mynat,\nhd : 2 * d = d + d\n\u22a2 2 * succ d = succ d + succ d\n```\n\n-/\n\n\n/- \n# Addition World. \n\nWelcome to Addition World. If you've done all four levels in tutorial world\nand know about `rw` and `refl`, then you're in the right place. Here's\na reminder of the things you're now equipped with which we'll need in this world.\n\n## Data:\n\n  * a type called `mynat`\n  * a term `0 : mynat`, interpreted as the number zero.\n  * a function `succ : mynat \u2192 mynat`, with `succ n` interpreted as \"the number after `n`\".\n  * Usual numerical notation 0,1,2 etc (although 2 onwards will be of no use to us until much later ;-) ).\n  * Addition (with notation `a + b`).\n\n## Theorems:\n\n  * `add_zero (a : mynat) : a + 0 = a`. Use with `rw add_zero`.\n  * `add_succ (a b : mynat) : a + succ(b) = succ(a + b)`. Use with `rw add_succ`.\n  * The principle of mathematical induction. Use with `induction` (see below)\n  \n\n## Tactics:\n\n  * `refl` :  proves goals of the form `X = X`\n  * `rw h` : if h is a proof of `A = B`, changes all A's in the goal to B's.\n  * `induction n with d hd` : we're going to learn this right now.\n\n# Important thing: \n\nThis is a *really* good time to check you understand about the box on the left with the drop down\nmenus. All the theorems and all the tactics above are documented there. You can find\nall you need to know about what theorems you have collected in Theorem statements -> Addition world.\nHave a click around and check that you can find statements of the theorems above, and explanations of\nthe tactics above. As we go through the game, these lists will grow. The box on the left\nwill prove invaluable as the number of theorems we prove gets bigger. On the other hand,\nwe only need to learn one more tactic to really start going places, so let's learn about\nthat tactic right now.\n\n## Level 1: the `induction` tactic.\n\nOK so let's see induction in action. We're going to prove\n\n  `zero_add (n : mynat) : 0 + n = n`. \n\nThat is: for all natural numbers $n$, $0+n=n$. Wait $-$ what is going on here?\nDidn't we already prove that adding zero to $n$ gave us $n$?\nNo we didn't! We proved $n + 0 = n$, and that proof was called `add_zero`. We're now\ntrying to establish `zero_add`, the proof that $0 + n = n$. But aren't these two theorems\nthe same? No they're not! It is *true* that `x + y = y + x`, but we haven't\n*proved* it yet, and in fact we will need both `add_zero` and `zero_add` in order\nto prove this. In fact `x + y = y + x` is the boss level for addition world,\nand `induction` is the only other tactic you'll need to beat it.\n\nNow `add_zero` is one of Peano's axioms, so we don't need to prove it, we already have it\n(indeed, if you've opened the Addition World theorem statements on the left, you can even see it).\nTo prove `0 + n = n` we need to use induction on $n$. While we're here,\n  note that `zero_add` is about zero add something, and `add_zero` is about something add zero.\n  The names of the proofs tell you what the theorems are. Anyway, let's prove `0 + n = n`.\n\n  Delete `sorry` and replace it with `induction n with d hd,`\nand **don't forget the comma**. Hit enter, wait for Lean to finish thinking,\nand let's see what we have.\n\nWhen Lean has finished thinking, we see that we now have *two goals*! The\ninduction tactic has generated for us a base case with `n = 0` (the goal at the top)\nand an inductive step (the goal underneath). The golden rule: **Tactics operate on the first goal** --\nthe goal at the top. So let's just worry about that top goal now, the base case `\u22a2 0 + 0 = 0`.\n\nRemember that `add_zero` (the proof we have already) is the proof of `x + 0 = x`\n(for any $x$) so we can try\n\n`rw add_zero,`\n\n. What do you think the goal will\nchange to? Remember to just keep\nfocussing on the top goal, ignore the other one for now, it's not changing\nand we're not working on it. You should be able to solve the top goal yourself\nnow with `refl`.\n\nWhen you solved this base case goal, we are now be back down\nto one goal -- the inductive step. Take a look at the\ntext below the lemma to see an explanation of this goal.\n-/\n\n/- Lemma\nFor all natural numbers $n$, we have\n$$0 + n = n.$$\n-/\nlemma zero_add (n : mynat) : 0 + n = n :=\nbegin [nat_num_game]\n  induction n with d hd,\n    rw add_zero,\n    refl,\n  rw add_succ,\n  rw hd,\n  refl\n\nend\n\n/-\nWe're in the successor case, and your top right box should look\nsomething like this:\n\n```\ncase mynat.succ\nd : mynat,\nhd : 0 + d = d\n\u22a2 0 + succ d = succ d\n```\n\n*Important:* make sure that you only have one goal at this point. You\nshould have proved `0 + 0 = 0` by now. Tactics only operate on the top goal.\n\nThe first line just reminds us we're doing the inductive step.\nWe have a fixed natural number `d`, and the inductive hypothesis `hd : 0 + d = d`\nsaying that we have a proof of `0 + d = d`.  \nOur goal is to prove `0 + succ d = succ d`. In words, we're showing that\nif the lemma is true for `d`, then it's also true for the number after `d`.\nThat's the inductive step. Once we've proved this inductive step, we will have proved\n`zero_add` by the principle of mathematical induction.\n\nTo prove our goal, we need to use `add_succ`. We know that `add_succ 0 d`\nis the result that `0 + succ d = succ (0 + d)`, so the first thing\nwe need to do is to replace the left hand side `0 + succ d` of our\ngoal with the right hand side. We do this with the `rw` command. You can write\n\n`rw add_succ,`\n\n(or even `rw add_succ 0 d,` if you want to give Lean all the inputs instead of making it\nfigure them out itself). Don't forget the comma though. Hit enter. The goal should change to\n\n`\u22a2 succ (0 + d) = succ d`\n\nNow remember our inductive hypothesis `hd : 0 + d = d`. We need\nto rewrite this too! Type \n\n`rw hd,`\n\n(don't forget the comma). The goal will now change to\n\n`\u22a2 succ d = succ d`\n\nThis goal can be solved with the `refl` tactic. After you apply it,\nLean will inform you that there are no goals left. You are done!\n\n## Now venture off on your own.\n\nThose three tactics -- \n\n* `induction n with d hd,` \n* `rw h,`\n* `refl,`\n\nwill get you quite a long way through this game. Using only these tactics\nyou can beat Addition World level 4 (the boss level of Addition World),\nall of Multiplication World including the boss level `a * b = b * a`,\nand even all of Power World including the fiendish final boss. This route will\ngive you a good grounding in these three basic tactics; after that, if you\nare still interested, there are other worlds to master, where you can learn\nmore tactics.\n\nBut we're getting ahead of ourselves, you still have to beat the rest of Addition World. \nWe're going to stop explaining stuff carefully now. If you get stuck or want\nto know more about Lean (e.g. how to do much harder maths in Lean),\nask in `#new members` at\n<a href=\"https://leanprover.zulipchat.com\" target=\"blank\">the Lean chat</a>\n(login required, real name preferred). Kevin or Mohammad or one of the other\npeople there might be able to help.\n\nGood luck! Click on \"next level\" to solve some levels on your own.\n\n-/\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world2/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7032385466794351}}
{"text": "\nimport data.real.basic\nimport tactic\n\n\n-- maybe try this? suggested by Leo\n/-\nclass geometry :=\n(line : Type)\n(point : Type)\n-/\n\n\n-- variables {P L : Type} (p q r : P) (l m n : L)\n\n-- A notion of a line going throuhg a point. The very closely-related notion of parallel lines is also defined\nclass has_goes_thru (line point : Type):=\n(goes_thru : line \u2192 point \u2192 Prop)\n\nopen has_goes_thru\n\n-- the idea of parallel lines is tied to Euclid's axioms\ndef parallel {line : Type} (point : Type) [inst : has_goes_thru line point] (l m : line) : Prop := (l = m) \u2228 \u2200 p : point, \u00ac(goes_thru l p \u2227 goes_thru m p)\n\nclass has_euclid_post5 (line point : Type) extends has_goes_thru line point :=\n(euclid_post5 : \u2200 (l : line) (p: point), \u2203! (m : line), parallel point l m \u2227 goes_thru m p)\n\nopen has_euclid_post5\n\n\nsection\nvariables {line : Type} (point: Type) [has_goes_thru line point] (l m n : line)\n\ntheorem parallel_refl : parallel point l l := begin\n  left, refl,\nend\n\ntheorem parallel_symm : parallel point l m \u2194 parallel point m l := begin\n  split; intro h; cases h,\n  left,exact h.symm,\n  right,\n  intros p f, specialize h p, exact h \u27e8f.2, f.1\u27e9,\n  left, exact h.symm,\n  right,\n  intros p f, specialize h p, exact h \u27e8f.2, f.1\u27e9,\nend\n\ntheorem parallel_trans : parallel point l m \u2192 parallel point m n \u2192 parallel point l n := begin\n  intros plm pmn,\n  cases plm; cases pmn,\n  left,\n  rwa plm,\n  right,\n  rwa plm,\n  right,\n  rwa \u2190pmn,\n  sorry, -- we need Euclid's 5th postulate\nend\nend\n\n-- theorem parallel_refl {line : Type} (point: Type) [inst : has_goes_thru line point] (l m : line)\n\n-- variables [has_goes_thru L P]\n\n-- parallel lines are those which do not intersect\n\n#check parallel\n#check goes_thru\n#check exists_unique\n\n-- Euclid's fifth postulate\n\n-- A notion of distance obeying basic laws.\nclass has_distance (point : Type) :=\n(distance : point \u2192 point \u2192 \u211d)\n(distance_nonnegative : \u2200 p q : point, distance p q \u2265 0)\n(distance_zero_iff_eq : \u2200 p q : point, distance p q = 0 \u2194 p = q)\n(distance_comm : \u2200 p q : point, distance p q = distance q p)\n(distance_add: \u2200 p q r : point, distance p q + distance q r \u2265 distance p r)\n\nopen has_distance\n\n-- a notion of \"between\" for points.\n-- TODO depend on has_goes_thru since a point can only be between two collinear points\n-- TODO move to axioms\nclass between (point : Type) :=\n(between : point \u2192 point \u2192 point \u2192 Prop)\n(between_comm : \u2200 p q r : point, between p q r \u2194 between r q p)\n(one_between : \u2200 p q r: point, \u00ac(between p q r \u2227 between q p r))\n\n-- basic notions that geometry should support\n-- the first point is between the others\n\n-- I'd like a way to use this in the geometry class\n-- def goes_thru2 : Prop := goes_thru l p \u2227 goes_thru l q\n\n\n-- there is a line through any two points. If those points are different, that line is unique.\n-- (line_thru_pts : \u2200 p q : point, \u2203 l : line, goes_thru l p \u2227 goes_thru l q)\n-- (uniq_line_thru_pts : \u2200 (p q : point) (l m : line), goes_thru l p \u2227 goes_thru l q \u2227 goes_thru m p \u2227 goes_thru l q \u2192 p = q \u2228 l = m)\n\n-- one point is between the two others\n", "meta": {"author": "Vilin97", "repo": "LLL", "sha": "ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9", "save_path": "github-repos/lean/Vilin97-LLL", "path": "github-repos/lean/Vilin97-LLL/LLL-ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9/Greg/Geometry/Axioms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7031847353455322}}
{"text": "import data.finset\n\nuniverses u\n\nopen finset\n\nvariables {\u03b1 : Type u} [decidable_eq \u03b1] -- need decidability for set difference\n\ndef independent (\u2110 : finset (finset \u03b1)) (I\u2081 I\u2082 : finset \u03b1) (h\u2081 : I\u2081 \u2208 \u2110) (h\u2082 : I\u2082 \u2208 \u2110) : Prop := \n  finset.card I\u2081 < finset.card I\u2082 \u2192 \u2203 (e \u2208 I\u2082 \\ I\u2081), (insert e I\u2081 \u2208 \u2110)\n-- how should i define this?\n\ndef independent' (\u2110 : finset \u03b1 \u2192 Prop) : Prop := \n\u2200 I\u2081 I\u2082, \u2110 I\u2081 \u2227 \u2110 I\u2082 \u2192 finset.card I\u2081 < finset.card I\u2082 \u2192 \u2203 (e \u2208 I\u2082 \\ I\u2081), (\u2110 (insert e I\u2081))\n\ndef independent_collection (\u2110 : finset (finset \u03b1)) : Prop := \n  \u2200 (I\u2081 I\u2082 : finset \u03b1) (h\u2081 : I\u2081 \u2208 \u2110) (h\u2082 : I\u2082 \u2208 \u2110), independent \u2110 I\u2081 I\u2082 h\u2081 h\u2082\n-- don't love that\n\nlemma subset_independent (\u2110 \u2110': finset (finset \u03b1)) (hi : independent_collection \u2110) : \n  \u2110' \u2286 \u2110 \u2192 independent_collection \u2110' :=\nbegin\n  intros h,\n  rw independent_collection,\n  intros I\u2081 I\u2082 h\u2081 h\u2082,\n  rw independent_collection at hi,\n  --rw subset_iff at h,\n  have h1' := h h\u2081,\n  have h2' := h h\u2082,\n  specialize hi I\u2081 I\u2082 h1' h2',\n  --exact hi,\n  sorry,\nend\n\n/- A matroid M is an ordered pair `(E, \u2110)` consisting of a finite set `E` and \na collection `\u2110` of subsets of `E` having the following three properties:\n  (I1) `\u2205 \u2208 \u2110`.\n  (I2) If `I \u2208 \u2110` and `I' \u2286 I`, then `I' \u2208 \u2110`.\n  (I3) If `I\u2081` and `I\u2082` are in `I` and `|I\u2081| < |I\u2082|`, then there is an element `e` of `I\u2082 \u2212 I\u2081`\n    such that `I\u2081 \u222a {e} \u2208 I`.-/\nstructure matroid (E : finset \u03b1) (\u2110 : finset (finset \u03b1)) :=\n(subsets : \u2200 (I \u2208 \u2110), I \u2286 E)\n(empty : \u2205 \u2208 \u2110) -- (I1)\n(hereditary : \u2200 (I\u2081 \u2208 \u2110), \u2200 (I\u2082 : finset \u03b1), I\u2082 \u2286 I\u2081 \u2192 I\u2082 \u2208 \u2110) -- (I2)\n(ind : independent_collection \u2110) -- (I3)\n\n\n/- A subset of `E` that is not in `\u2110` is called dependent. -/ \n-- is this something that merits a separate definition?\ndef dependent_sets (E : finset \u03b1) (\u2110 : finset (finset \u03b1)) : finset (finset \u03b1) := E.powerset \\ \u2110\n\nvariables {E : finset \u03b1} {\u2110 : finset (finset \u03b1)}\nvariables [decidable_pred (\u03bb (D : finset \u03b1), independent_collection (erase D.powerset D))]\n-- figure out where this needs to go later\n\nnamespace matroid\n\ndef circuit (M : matroid E \u2110) : finset (finset \u03b1) :=\n  filter (\u03bb (D : finset \u03b1), independent_collection (erase D.powerset D)) (dependent_sets E \u2110)\n\n-- we're not defining n-circuits lmao\n\n@[simp]\nlemma mem_circuit (M : matroid E \u2110) (C\u2081 : finset \u03b1) : \n  C\u2081 \u2208 M.circuit \u2194 C\u2081 \u2208 dependent_sets E \u2110 \u2227 independent_collection (erase C\u2081.powerset C\u2081) :=\nbegin\n  rw circuit,\n  rw mem_filter,\nend\n\n/- `(C1)` \u2205 \u2209 C  -/\nlemma empty_notmem_circuit (M : matroid E \u2110) : \u2205 \u2209 M.circuit := \nbegin\n  -- this is just due to the fact that \u2205 \u2208 \u2110 lol\n  unfold matroid.circuit,\n  unfold dependent_sets,\n  rw mem_filter,\n  rw and_comm,\n  push_neg,\n  intros h,\n  simp,\n  exact M.empty,\nend\n\n/- `(C2)` if C\u2081 and C\u2082 are members of C and C\u2081 \u2286 C\u2082, then C\u2082 = C\u2082. \nIn other words, C forms an antichain. -/\nlemma circuit_antichain (M : matroid E \u2110) (C\u2081 C\u2082 : finset \u03b1) (h\u2081 : C\u2081 \u2208 M.circuit) (h\u2082 : C\u2082 \u2208 M.circuit) :\n  C\u2081 \u2286 C\u2082 \u2192 C\u2081 = C\u2082 :=\nbegin\n  -- this is because the proper subsets are independent and therefore not in M.circuit\n  intros h,\n  rw mem_circuit at h\u2082,\n  by_contra h2,\n  have h3 : C\u2081 \u2208 powerset C\u2082,\n  { exact finset.mem_powerset.2 h },\n  have h4 : C\u2081 \u2208 C\u2082.powerset.erase C\u2082,\n  { rw mem_erase,\n    simp,\n    exact \u27e8h2, h\u27e9 },\n  have h5 : C\u2081 \u2282 C\u2082,\n  { sorry },\n  \n  \n  sorry,\nend\n\nend matroid", "meta": {"author": "agusakov", "repo": "matroids", "sha": "a95393f6321ccbdf12fafecc788c8bfb20928c3f", "save_path": "github-repos/lean/agusakov-matroids", "path": "github-repos/lean/agusakov-matroids/matroids-a95393f6321ccbdf12fafecc788c8bfb20928c3f/src/definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7031847333473374}}
{"text": "theorem tst0 {p q : Prop } (h : p \u2228 q) : q \u2228 p :=\nby {\n  induction h;\n  { apply Or.inr; assumption };\n  { apply Or.inl; assumption }\n}\n\ntheorem tst0' {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\ninduction h\nfocus\n  apply Or.inr\n  assumption\nfocus\n  apply Or.inl\n  assumption\n\ntheorem tst1 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\ninduction h with\n| inr h2 => exact Or.inl h2\n| inl h1 => exact Or.inr h1\n\ntheorem tst6 {p q : Prop } (h : p \u2228 q) : q \u2228 p :=\nby {\n  cases h with\n  | inr h2 => exact Or.inl h2\n  | inl h1 => exact Or.inr h1\n}\n\ntheorem tst7 {\u03b1 : Type} (xs : List \u03b1) (h : (a : \u03b1) \u2192 (as : List \u03b1) \u2192 xs \u2260 a :: as) : xs = [] :=\nby {\n  induction xs with\n  | nil          => exact rfl\n  | cons z zs ih => exact absurd rfl (h z zs)\n}\n\ntheorem tst8 {\u03b1 : Type} (xs : List \u03b1) (h : (a : \u03b1) \u2192 (as : List \u03b1) \u2192 xs \u2260 a :: as) : xs = [] := by {\n  induction xs;\n  exact rfl;\n  exact absurd rfl $ h _ _\n}\n\ntheorem tst9 {\u03b1 : Type} (xs : List \u03b1) (h : (a : \u03b1) \u2192 (as : List \u03b1) \u2192 xs \u2260 a :: as) : xs = [] := by\n  cases xs with\n     | nil       => exact rfl\n     | cons z zs => exact absurd rfl (h z zs)\n\ntheorem tst10 {p q : Prop } (h\u2081 : p \u2194 q) (h\u2082 : p) : q := by\n  induction h\u2081 with\n  | intro h _ => exact h h\u2082\n\ndef Iff2 (m p q : Prop) := p \u2194 q\n\ntheorem tst11 {p q r : Prop } (h\u2081 : Iff2 r p q) (h\u2082 : p) : q := by\n  induction h\u2081 using Iff.rec with\n  | intro h _ => exact h h\u2082\n\ntheorem tst12 {p q : Prop } (h\u2081 : p \u2228 q) (h\u2082 : p \u2194 q) (h\u2083 : p) : q := by\n  failIfSuccess induction h\u2081 using Iff.casesOn\n  induction h\u2082 using Iff.casesOn with\n  | intro h _ =>\n    exact h h\u2083\n\ninductive Tree\n  | leaf\u2081\n  | leaf\u2082\n  | node : Tree \u2192 Tree \u2192 Tree\n\ndef Tree.isLeaf\u2081 : Tree \u2192 Bool\n  | leaf\u2081 => true\n  | _     => false\n\ntheorem tst13 (x : Tree) (h : x = Tree.leaf\u2081) : x.isLeaf\u2081 = true := by\n  cases x with\n  | leaf\u2081 => rfl\n  | _     => injection h\n\ntheorem tst14 (x : Tree) (h : x = Tree.leaf\u2081) : x.isLeaf\u2081 = true := by\n  induction x with\n  | leaf\u2081 => rfl\n  | _     => injection h\n\ninductive Vec (\u03b1 : Type) : Nat \u2192 Type\n  | nil  : Vec \u03b1 0\n  | cons : (a : \u03b1) \u2192 {n : Nat} \u2192 (as : Vec \u03b1 n) \u2192 Vec \u03b1 (n+1)\n\ndef getHeads {\u03b1 \u03b2} {n} (xs : Vec \u03b1 (n+1)) (ys : Vec \u03b2 (n+1)) : \u03b1 \u00d7 \u03b2 := by\n  cases xs\n  cases ys\n  apply Prod.mk\n  repeat\n    traceState\n    assumption\n  done\n\ntheorem ex1 (n m o : Nat) : n = m + 0 \u2192 m = o \u2192 m = o := by\n  intro (h\u2081 : n = m) h\u2082\n  rw [\u2190 h\u2081, \u2190 h\u2082]\n  assumption\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/induction1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.703099195646226}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl, Damiano Testa,\nYuyang Zhao\n-/\nimport algebra.covariant_and_contravariant\nimport order.min_max\n\n/-!\n# Ordered monoids\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file develops the basics of ordered monoids.\n\n## Implementation details\n\nUnfortunately, the number of `'` appended to lemmas in this file\nmay differ between the multiplicative and the additive version of a lemma.\nThe reason is that we did not want to change existing names in the library.\n\n## Remark\n\nAlmost no monoid is actually present in this file: most assumptions have been generalized to\n`has_mul` or `mul_one_class`.\n\n-/\n\n-- TODO: If possible, uniformize lemma names, taking special care of `'`,\n-- after the `ordered`-refactor is done.\n\nopen function\n\nvariables {\u03b1 \u03b2 : Type*}\n\nsection has_mul\nvariables [has_mul \u03b1]\n\nsection has_le\nvariables [has_le \u03b1]\n\n/- The prime on this lemma is present only on the multiplicative version.  The unprimed version\nis taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/\n@[to_additive add_le_add_left]\nlemma mul_le_mul_left' [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {b c : \u03b1} (bc : b \u2264 c) (a : \u03b1) :\n  a * b \u2264 a * c :=\ncovariant_class.elim _ bc\n\n@[to_additive le_of_add_le_add_left]\nlemma le_of_mul_le_mul_left' [contravariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (bc : a * b \u2264 a * c) :\n  b \u2264 c :=\ncontravariant_class.elim _ bc\n\n/- The prime on this lemma is present only on the multiplicative version.  The unprimed version\nis taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/\n@[to_additive add_le_add_right]\nlemma mul_le_mul_right' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {b c : \u03b1} (bc : b \u2264 c) (a : \u03b1) :\n  b * a \u2264 c * a :=\ncovariant_class.elim a bc\n\n@[to_additive le_of_add_le_add_right]\nlemma le_of_mul_le_mul_right' [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (bc : b * a \u2264 c * a) :\n  b \u2264 c :=\ncontravariant_class.elim a bc\n\n@[simp, to_additive]\nlemma mul_le_mul_iff_left [covariant_class \u03b1 \u03b1 (*) (\u2264)] [contravariant_class \u03b1 \u03b1 (*) (\u2264)]\n  (a : \u03b1) {b c : \u03b1} :\n  a * b \u2264 a * c \u2194 b \u2264 c :=\nrel_iff_cov \u03b1 \u03b1 (*) (\u2264) a\n\n@[simp, to_additive]\nlemma mul_le_mul_iff_right\n  [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (a : \u03b1) {b c : \u03b1} :\n  b * a \u2264 c * a \u2194 b \u2264 c :=\nrel_iff_cov \u03b1 \u03b1 (swap (*)) (\u2264) a\n\nend has_le\n\nsection has_lt\nvariables [has_lt \u03b1]\n\n@[simp, to_additive]\nlemma mul_lt_mul_iff_left [covariant_class \u03b1 \u03b1 (*) (<)] [contravariant_class \u03b1 \u03b1 (*) (<)]\n  (a : \u03b1) {b c : \u03b1} :\n  a * b < a * c \u2194 b < c :=\nrel_iff_cov \u03b1 \u03b1 (*) (<) a\n\n@[simp, to_additive]\nlemma mul_lt_mul_iff_right\n  [covariant_class \u03b1 \u03b1 (swap (*)) (<)] [contravariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (a : \u03b1) {b c : \u03b1} :\n  b * a < c * a \u2194 b < c :=\nrel_iff_cov \u03b1 \u03b1 (swap (*)) (<) a\n\n@[to_additive add_lt_add_left]\nlemma mul_lt_mul_left' [covariant_class \u03b1 \u03b1 (*) (<)]\n  {b c : \u03b1} (bc : b < c) (a : \u03b1) :\n  a * b < a * c :=\ncovariant_class.elim _ bc\n\n@[to_additive lt_of_add_lt_add_left]\nlemma lt_of_mul_lt_mul_left' [contravariant_class \u03b1 \u03b1 (*) (<)]\n  {a b c : \u03b1} (bc : a * b < a * c) :\n  b < c :=\ncontravariant_class.elim _ bc\n\n@[to_additive add_lt_add_right]\nlemma mul_lt_mul_right' [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {b c : \u03b1} (bc : b < c) (a : \u03b1) :\n  b * a < c * a :=\ncovariant_class.elim a bc\n\n@[to_additive lt_of_add_lt_add_right]\nlemma lt_of_mul_lt_mul_right' [contravariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c : \u03b1} (bc : b * a < c * a) :\n  b < c :=\ncontravariant_class.elim a bc\n\nend has_lt\n\nsection preorder\nvariables [preorder \u03b1]\n\n@[to_additive]\nlemma mul_lt_mul_of_lt_of_lt [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c d : \u03b1} (h\u2081 : a < b) (h\u2082 : c < d) : a * c < b * d :=\ncalc  a * c < a * d : mul_lt_mul_left' h\u2082 a\n        ... < b * d : mul_lt_mul_right' h\u2081 d\n\nalias add_lt_add_of_lt_of_lt \u2190 add_lt_add\n\n@[to_additive]\nlemma mul_lt_mul_of_le_of_lt [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (h\u2081 : a \u2264 b) (h\u2082 : c < d) : a * c < b * d :=\n(mul_le_mul_right' h\u2081 _).trans_lt (mul_lt_mul_left' h\u2082 b)\n\n@[to_additive]\nlemma mul_lt_mul_of_lt_of_le [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c d : \u03b1} (h\u2081 : a < b) (h\u2082 : c \u2264 d) : a * c < b * d :=\n(mul_le_mul_left' h\u2082 _).trans_lt (mul_lt_mul_right' h\u2081 d)\n\n/-- Only assumes left strict covariance. -/\n@[to_additive \"Only assumes left strict covariance\"]\nlemma left.mul_lt_mul [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (h\u2081 : a < b) (h\u2082 : c < d) : a * c < b * d :=\nmul_lt_mul_of_le_of_lt h\u2081.le h\u2082\n\n/-- Only assumes right strict covariance. -/\n@[to_additive \"Only assumes right strict covariance\"]\nlemma right.mul_lt_mul [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c d : \u03b1} (h\u2081 : a < b) (h\u2082 : c < d) : a * c < b * d :=\nmul_lt_mul_of_lt_of_le h\u2081 h\u2082.le\n\n@[to_additive add_le_add]\nlemma mul_le_mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (h\u2081 : a \u2264 b) (h\u2082 : c \u2264 d) : a * c \u2264 b * d :=\n(mul_le_mul_left' h\u2082 _).trans (mul_le_mul_right' h\u2081 d)\n\n@[to_additive]\nlemma mul_le_mul_three [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d e f : \u03b1} (h\u2081 : a \u2264 d) (h\u2082 : b \u2264 e) (h\u2083 : c \u2264 f) :\n  a * b * c \u2264 d * e * f :=\nmul_le_mul' (mul_le_mul' h\u2081 h\u2082) h\u2083\n\n@[to_additive]\nlemma mul_lt_of_mul_lt_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c d : \u03b1} (h : a * b < c) (hle : d \u2264 b) :\n  a * d < c :=\n(mul_le_mul_left' hle a).trans_lt h\n\n@[to_additive]\nlemma mul_le_of_mul_le_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c d : \u03b1} (h : a * b \u2264 c) (hle : d \u2264 b) :\n  a * d \u2264 c :=\n@act_rel_of_rel_of_act_rel _ _ _ (\u2264) _ \u27e8\u03bb _ _ _, le_trans\u27e9 a _ _ _ hle h\n\n@[to_additive]\nlemma mul_lt_of_mul_lt_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (h : a * b < c) (hle : d \u2264 a) :\n  d * b < c :=\n(mul_le_mul_right' hle b).trans_lt h\n\n@[to_additive]\nlemma mul_le_of_mul_le_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (h : a * b \u2264 c) (hle : d \u2264 a) :\n  d * b \u2264 c :=\n(mul_le_mul_right' hle b).trans h\n\n@[to_additive]\nlemma lt_mul_of_lt_mul_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c d : \u03b1} (h : a < b * c) (hle : c \u2264 d) :\n  a < b * d :=\nh.trans_le (mul_le_mul_left' hle b)\n\n@[to_additive]\nlemma le_mul_of_le_mul_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c d : \u03b1} (h : a \u2264 b * c) (hle : c \u2264 d) :\n  a \u2264 b * d :=\n@rel_act_of_rel_of_rel_act _ _ _ (\u2264) _ \u27e8\u03bb _ _ _, le_trans\u27e9 b _ _ _ hle h\n\n@[to_additive]\nlemma lt_mul_of_lt_mul_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (h : a < b * c) (hle : b \u2264 d) :\n  a < d * c :=\nh.trans_le (mul_le_mul_right' hle c)\n\n@[to_additive]\nlemma le_mul_of_le_mul_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (h : a \u2264 b * c) (hle : b \u2264 d) :\n  a \u2264 d * c :=\nh.trans (mul_le_mul_right' hle c)\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1]\n\n@[to_additive]\nlemma mul_left_cancel'' [contravariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (h : a * b = a * c) :\n  b = c :=\n(le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge)\n\n@[to_additive]\nlemma mul_right_cancel'' [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (h : a * b = c * b) :\n  a = c :=\nle_antisymm (le_of_mul_le_mul_right' h.le) (le_of_mul_le_mul_right' h.ge)\n\nend partial_order\n\nsection linear_order\nvariables [linear_order \u03b1] {a b c d : \u03b1} [covariant_class \u03b1 \u03b1 (*) (<)]\n  [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n\n@[to_additive] lemma min_le_max_of_mul_le_mul (h : a * b \u2264 c * d) : min a b \u2264 max c d :=\nby { simp_rw [min_le_iff, le_max_iff], contrapose! h, exact mul_lt_mul_of_lt_of_lt h.1.1 h.2.2 }\n\nend linear_order\nend has_mul\n\n-- using one\nsection mul_one_class\nvariables [mul_one_class \u03b1]\n\nsection has_le\nvariables [has_le \u03b1]\n\n@[to_additive le_add_of_nonneg_right]\nlemma le_mul_of_one_le_right' [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (h : 1 \u2264 b) :\n  a \u2264 a * b :=\ncalc  a = a * 1  : (mul_one a).symm\n    ... \u2264 a * b  : mul_le_mul_left' h a\n\n@[to_additive add_le_of_nonpos_right]\nlemma mul_le_of_le_one_right' [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (h : b \u2264 1) :\n  a * b \u2264 a :=\ncalc  a * b \u2264 a * 1 : mul_le_mul_left' h a\n        ... = a     : mul_one a\n\n@[to_additive le_add_of_nonneg_left]\nlemma le_mul_of_one_le_left' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (h : 1 \u2264 b) :\n  a \u2264 b * a :=\ncalc  a = 1 * a  : (one_mul a).symm\n    ... \u2264 b * a  : mul_le_mul_right' h a\n\n@[to_additive add_le_of_nonpos_left]\nlemma mul_le_of_le_one_left' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (h : b \u2264 1) :\n  b * a \u2264 a :=\ncalc  b * a \u2264 1 * a : mul_le_mul_right' h a\n        ... = a     : one_mul a\n\n@[to_additive]\nlemma one_le_of_le_mul_right [contravariant_class \u03b1 \u03b1 (*) (\u2264)] {a b : \u03b1} (h : a \u2264 a * b) : 1 \u2264 b :=\nle_of_mul_le_mul_left' $ by simpa only [mul_one]\n\n@[to_additive]\nlemma le_one_of_mul_le_right [contravariant_class \u03b1 \u03b1 (*) (\u2264)] {a b : \u03b1} (h : a * b \u2264 a) : b \u2264 1 :=\nle_of_mul_le_mul_left' $ by simpa only [mul_one]\n\n@[to_additive]\nlemma one_le_of_le_mul_left [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b : \u03b1} (h : b \u2264 a * b) :\n  1 \u2264 a :=\nle_of_mul_le_mul_right' $ by simpa only [one_mul]\n\n@[to_additive]\nlemma le_one_of_mul_le_left [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b : \u03b1} (h : a * b \u2264 b) :\n  a \u2264 1 :=\nle_of_mul_le_mul_right' $ by simpa only [one_mul]\n\n@[simp, to_additive le_add_iff_nonneg_right]\nlemma le_mul_iff_one_le_right'\n  [covariant_class \u03b1 \u03b1 (*) (\u2264)] [contravariant_class \u03b1 \u03b1 (*) (\u2264)]\n  (a : \u03b1) {b : \u03b1} :\n  a \u2264 a * b \u2194 1 \u2264 b :=\niff.trans (by rw [mul_one]) (mul_le_mul_iff_left a)\n\n@[simp, to_additive le_add_iff_nonneg_left]\nlemma le_mul_iff_one_le_left'\n  [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (a : \u03b1) {b : \u03b1} :\n  a \u2264 b * a \u2194 1 \u2264 b :=\niff.trans (by rw one_mul) (mul_le_mul_iff_right a)\n\n@[simp, to_additive add_le_iff_nonpos_right]\nlemma mul_le_iff_le_one_right'\n  [covariant_class \u03b1 \u03b1 (*) (\u2264)] [contravariant_class \u03b1 \u03b1 (*) (\u2264)]\n  (a : \u03b1) {b : \u03b1} :\n  a * b \u2264 a \u2194 b \u2264 1 :=\niff.trans (by rw [mul_one]) (mul_le_mul_iff_left a)\n\n@[simp, to_additive add_le_iff_nonpos_left]\nlemma mul_le_iff_le_one_left'\n  [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} :\n  a * b \u2264 b \u2194 a \u2264 1 :=\niff.trans (by rw one_mul) (mul_le_mul_iff_right b)\n\nend has_le\n\nsection has_lt\nvariable [has_lt \u03b1]\n\n@[to_additive lt_add_of_pos_right]\nlemma lt_mul_of_one_lt_right' [covariant_class \u03b1 \u03b1 (*) (<)]\n  (a : \u03b1) {b : \u03b1} (h : 1 < b) :\n  a < a * b :=\ncalc  a = a * 1  : (mul_one a).symm\n    ... < a * b  : mul_lt_mul_left' h a\n\n@[to_additive add_lt_of_neg_right]\nlemma mul_lt_of_lt_one_right' [covariant_class \u03b1 \u03b1 (*) (<)]\n  (a : \u03b1) {b : \u03b1} (h : b < 1) :\n  a * b < a :=\ncalc  a * b < a * 1 : mul_lt_mul_left' h a\n        ... = a     : mul_one a\n\n@[to_additive lt_add_of_pos_left]\nlemma lt_mul_of_one_lt_left' [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (a : \u03b1) {b : \u03b1} (h : 1 < b) :\n  a < b * a :=\ncalc  a = 1 * a  : (one_mul a).symm\n    ... < b * a  : mul_lt_mul_right' h a\n\n@[to_additive add_lt_of_neg_left]\nlemma mul_lt_of_lt_one_left' [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (a : \u03b1) {b : \u03b1} (h : b < 1) :\n  b * a < a :=\ncalc  b * a < 1 * a : mul_lt_mul_right' h a\n        ... = a     : one_mul a\n\n@[to_additive]\nlemma one_lt_of_lt_mul_right [contravariant_class \u03b1 \u03b1 (*) (<)] {a b : \u03b1} (h : a < a * b) : 1 < b :=\nlt_of_mul_lt_mul_left' $ by simpa only [mul_one]\n\n@[to_additive]\nlemma lt_one_of_mul_lt_right [contravariant_class \u03b1 \u03b1 (*) (<)] {a b : \u03b1} (h : a * b < a) : b < 1 :=\nlt_of_mul_lt_mul_left' $ by simpa only [mul_one]\n\n@[to_additive]\nlemma one_lt_of_lt_mul_left [contravariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b : \u03b1} (h : b < a * b) :\n  1 < a :=\nlt_of_mul_lt_mul_right' $ by simpa only [one_mul]\n\n@[to_additive]\nlemma lt_one_of_mul_lt_left [contravariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b : \u03b1} (h : a * b < b) :\n  a < 1 :=\nlt_of_mul_lt_mul_right' $ by simpa only [one_mul]\n\n@[simp, to_additive lt_add_iff_pos_right]\nlemma lt_mul_iff_one_lt_right'\n  [covariant_class \u03b1 \u03b1 (*) (<)] [contravariant_class \u03b1 \u03b1 (*) (<)]\n  (a : \u03b1) {b : \u03b1} :\n  a < a * b \u2194 1 < b :=\niff.trans (by rw mul_one) (mul_lt_mul_iff_left a)\n\n@[simp, to_additive lt_add_iff_pos_left]\nlemma lt_mul_iff_one_lt_left'\n  [covariant_class \u03b1 \u03b1 (swap (*)) (<)] [contravariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (a : \u03b1) {b : \u03b1} :\n  a < b * a \u2194 1 < b :=\niff.trans (by rw one_mul) (mul_lt_mul_iff_right a)\n\n@[simp, to_additive add_lt_iff_neg_left]\nlemma mul_lt_iff_lt_one_left'\n  [covariant_class \u03b1 \u03b1 (*) (<)] [contravariant_class \u03b1 \u03b1 (*) (<)]\n  {a b : \u03b1} :\n  a * b < a \u2194 b < 1 :=\niff.trans (by rw mul_one) (mul_lt_mul_iff_left a)\n\n@[simp, to_additive add_lt_iff_neg_right]\nlemma mul_lt_iff_lt_one_right'\n  [covariant_class \u03b1 \u03b1 (swap (*)) (<)] [contravariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a : \u03b1} (b : \u03b1) :\n  a * b < b \u2194 a < 1 :=\niff.trans (by rw one_mul) (mul_lt_mul_iff_right b)\n\nend has_lt\n\nsection preorder\nvariable [preorder \u03b1]\n\n/-! Lemmas of the form `b \u2264 c \u2192 a \u2264 1 \u2192 b * a \u2264 c`,\nwhich assume left covariance. -/\n\n@[to_additive]\nlemma mul_le_of_le_of_le_one [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (hbc : b \u2264 c) (ha : a \u2264 1) : b * a \u2264 c :=\ncalc  b * a \u2264 b * 1 : mul_le_mul_left' ha b\n        ... = b     : mul_one b\n        ... \u2264 c     : hbc\n\n@[to_additive]\nlemma mul_lt_of_le_of_lt_one [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b c : \u03b1} (hbc : b \u2264 c) (ha : a < 1) : b * a < c :=\ncalc  b * a < b * 1 : mul_lt_mul_left' ha b\n        ... = b     : mul_one b\n        ... \u2264 c     : hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_of_le_one [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (hbc : b < c) (ha : a \u2264 1) : b * a < c :=\ncalc  b * a \u2264 b * 1 : mul_le_mul_left' ha b\n        ... = b     : mul_one b\n        ... < c     : hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_of_lt_one [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b c : \u03b1} (hbc : b < c) (ha : a < 1) : b * a < c :=\ncalc  b * a < b * 1 : mul_lt_mul_left' ha b\n        ... = b     : mul_one b\n        ... < c     : hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_of_lt_one' [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (hbc : b < c) (ha : a < 1) : b * a < c :=\nmul_lt_of_lt_of_le_one hbc ha.le\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.mul_le_one`. -/\n@[to_additive \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_nonpos`.\"]\nlemma left.mul_le_one [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : a \u2264 1) (hb : b \u2264 1) : a * b \u2264 1 :=\nmul_le_of_le_of_le_one ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.mul_lt_one_of_le_of_lt`. -/\n@[to_additive left.add_neg_of_nonpos_of_neg \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_neg_of_nonpos_of_neg`.\"]\nlemma left.mul_lt_one_of_le_of_lt [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b : \u03b1} (ha : a \u2264 1) (hb : b < 1) : a * b < 1 :=\nmul_lt_of_le_of_lt_one ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.mul_lt_one_of_lt_of_le`. -/\n@[to_additive left.add_neg_of_neg_of_nonpos \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_neg_of_neg_of_nonpos`.\"]\nlemma left.mul_lt_one_of_lt_of_le [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : a < 1) (hb : b \u2264 1) : a * b < 1 :=\nmul_lt_of_lt_of_le_one ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.mul_lt_one`. -/\n@[to_additive \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_neg`.\"]\nlemma left.mul_lt_one [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b : \u03b1} (ha : a < 1) (hb : b < 1) : a * b < 1 :=\nmul_lt_of_lt_of_lt_one ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.mul_lt_one'`. -/\n@[to_additive \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_neg'`.\"]\nlemma left.mul_lt_one' [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : a < 1) (hb : b < 1) : a * b < 1 :=\nmul_lt_of_lt_of_lt_one' ha hb\n\n/-! Lemmas of the form `b \u2264 c \u2192 1 \u2264 a \u2192 b \u2264 c * a`,\nwhich assume left covariance. -/\n\n@[to_additive]\nlemma le_mul_of_le_of_one_le [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (hbc : b \u2264 c) (ha : 1 \u2264 a) : b \u2264 c * a :=\ncalc  b \u2264 c     : hbc\n    ... = c * 1 : (mul_one c).symm\n    ... \u2264 c * a : mul_le_mul_left' ha c\n\n@[to_additive]\nlemma lt_mul_of_le_of_one_lt [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b c : \u03b1} (hbc : b \u2264 c) (ha : 1 < a) : b < c * a :=\ncalc  b \u2264 c     : hbc\n    ... = c * 1 : (mul_one c).symm\n    ... < c * a : mul_lt_mul_left' ha c\n\n@[to_additive]\nlemma lt_mul_of_lt_of_one_le [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (hbc : b < c) (ha : 1 \u2264 a) : b < c * a :=\ncalc  b < c     : hbc\n    ... = c * 1 : (mul_one c).symm\n    ... \u2264 c * a : mul_le_mul_left' ha c\n\n@[to_additive]\nlemma lt_mul_of_lt_of_one_lt [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b c : \u03b1} (hbc : b < c) (ha : 1 < a) : b < c * a :=\ncalc  b < c     : hbc\n    ... = c * 1 : (mul_one c).symm\n    ... < c * a : mul_lt_mul_left' ha c\n\n@[to_additive]\nlemma lt_mul_of_lt_of_one_lt' [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (hbc : b < c) (ha : 1 < a) : b < c * a :=\nlt_mul_of_lt_of_one_le hbc ha.le\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.one_le_mul`. -/\n@[to_additive left.add_nonneg \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_nonneg`.\"]\nlemma left.one_le_mul [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : 1 \u2264 a) (hb : 1 \u2264 b) : 1 \u2264 a * b :=\nle_mul_of_le_of_one_le ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.one_lt_mul_of_le_of_lt`. -/\n@[to_additive left.add_pos_of_nonneg_of_pos \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_pos_of_nonneg_of_pos`.\"]\nlemma left.one_lt_mul_of_le_of_lt [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b : \u03b1} (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\nlt_mul_of_le_of_one_lt ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.one_lt_mul_of_lt_of_le`. -/\n@[to_additive left.add_pos_of_pos_of_nonneg \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_pos_of_pos_of_nonneg`.\"]\nlemma left.one_lt_mul_of_lt_of_le [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : 1 < a) (hb : 1 \u2264 b) : 1 < a * b :=\nlt_mul_of_lt_of_one_le ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.one_lt_mul`. -/\n@[to_additive left.add_pos \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_pos`.\"]\nlemma left.one_lt_mul [covariant_class \u03b1 \u03b1 (*) (<)]\n  {a b : \u03b1} (ha : 1 < a) (hb : 1 < b) : 1 < a * b :=\nlt_mul_of_lt_of_one_lt ha hb\n\n/-- Assumes left covariance.\nThe lemma assuming right covariance is `right.one_lt_mul'`. -/\n@[to_additive left.add_pos' \"Assumes left covariance.\nThe lemma assuming right covariance is `right.add_pos'`.\"]\nlemma left.one_lt_mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : 1 < a) (hb : 1 < b) : 1 < a * b :=\nlt_mul_of_lt_of_one_lt' ha hb\n\n/-! Lemmas of the form `a \u2264 1 \u2192 b \u2264 c \u2192 a * b \u2264 c`,\nwhich assume right covariance. -/\n\n@[to_additive]\nlemma mul_le_of_le_one_of_le [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (ha : a \u2264 1) (hbc : b \u2264 c) : a * b \u2264 c :=\ncalc  a * b \u2264 1 * b : mul_le_mul_right' ha b\n        ... = b     : one_mul b\n        ... \u2264 c     : hbc\n\n@[to_additive]\nlemma mul_lt_of_lt_one_of_le [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c : \u03b1} (ha : a < 1) (hbc : b \u2264 c) : a * b < c :=\ncalc  a * b < 1 * b : mul_lt_mul_right' ha b\n        ... = b     : one_mul b\n        ... \u2264 c     : hbc\n\n@[to_additive]\nlemma mul_lt_of_le_one_of_lt [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (ha : a \u2264 1) (hb : b < c) : a * b < c :=\ncalc  a * b \u2264 1 * b : mul_le_mul_right' ha b\n        ... = b     : one_mul b\n        ... < c     : hb\n\n@[to_additive]\nlemma mul_lt_of_lt_one_of_lt [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c : \u03b1} (ha : a < 1) (hb : b < c) : a * b < c :=\ncalc  a * b < 1 * b : mul_lt_mul_right' ha b\n        ... = b     : one_mul b\n        ... < c     : hb\n\n@[to_additive]\nlemma mul_lt_of_lt_one_of_lt' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (ha : a < 1) (hbc : b < c) : a * b < c :=\nmul_lt_of_le_one_of_lt ha.le hbc\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.mul_le_one`. -/\n@[to_additive \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_nonpos`.\"]\nlemma right.mul_le_one [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (ha : a \u2264 1) (hb : b \u2264 1) : a * b \u2264 1 :=\nmul_le_of_le_one_of_le ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.mul_lt_one_of_lt_of_le`. -/\n@[to_additive right.add_neg_of_neg_of_nonpos \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_neg_of_neg_of_nonpos`.\"]\nlemma right.mul_lt_one_of_lt_of_le [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b : \u03b1} (ha : a < 1) (hb : b \u2264 1) : a * b < 1 :=\nmul_lt_of_lt_one_of_le ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.mul_lt_one_of_le_of_lt`. -/\n@[to_additive right.add_neg_of_nonpos_of_neg \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_neg_of_nonpos_of_neg`.\"]\nlemma right.mul_lt_one_of_le_of_lt [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (ha : a \u2264 1) (hb : b < 1) : a * b < 1 :=\nmul_lt_of_le_one_of_lt ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.mul_lt_one`. -/\n@[to_additive \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_neg`.\"]\nlemma right.mul_lt_one [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b : \u03b1} (ha : a < 1) (hb : b < 1) : a * b < 1 :=\nmul_lt_of_lt_one_of_lt ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.mul_lt_one'`. -/\n@[to_additive \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_neg'`.\"]\nlemma right.mul_lt_one' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (ha : a < 1) (hb : b < 1) : a * b < 1 :=\nmul_lt_of_lt_one_of_lt' ha hb\n\n/-! Lemmas of the form `1 \u2264 a \u2192 b \u2264 c \u2192 b \u2264 a * c`,\nwhich assume right covariance. -/\n\n@[to_additive]\nlemma le_mul_of_one_le_of_le [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (ha : 1 \u2264 a) (hbc : b \u2264 c) : b \u2264 a * c :=\ncalc  b \u2264 c     : hbc\n    ... = 1 * c : (one_mul c).symm\n    ... \u2264 a * c : mul_le_mul_right' ha c\n\n@[to_additive]\nlemma lt_mul_of_one_lt_of_le [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c : \u03b1} (ha : 1 < a) (hbc : b \u2264 c) : b < a * c :=\ncalc  b \u2264 c     : hbc\n    ... = 1 * c : (one_mul c).symm\n    ... < a * c : mul_lt_mul_right' ha c\n\n@[to_additive]\nlemma lt_mul_of_one_le_of_lt [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (ha : 1 \u2264 a) (hbc : b < c) : b < a * c :=\ncalc  b < c     : hbc\n    ... = 1 * c : (one_mul c).symm\n    ... \u2264 a * c : mul_le_mul_right' ha c\n\n@[to_additive]\nlemma lt_mul_of_one_lt_of_lt [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b c : \u03b1} (ha : 1 < a) (hbc : b < c) : b < a * c :=\ncalc  b < c     : hbc\n    ... = 1 * c : (one_mul c).symm\n    ... < a * c : mul_lt_mul_right' ha c\n\n@[to_additive]\nlemma lt_mul_of_one_lt_of_lt' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (ha : 1 < a) (hbc : b < c) : b < a * c :=\nlt_mul_of_one_le_of_lt ha.le hbc\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.one_le_mul`. -/\n@[to_additive right.add_nonneg \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_nonneg`.\"]\nlemma right.one_le_mul [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (ha : 1 \u2264 a) (hb : 1 \u2264 b) : 1 \u2264 a * b :=\nle_mul_of_one_le_of_le ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.one_lt_mul_of_lt_of_le`. -/\n@[to_additive right.add_pos_of_pos_of_nonneg \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_pos_of_pos_of_nonneg`.\"]\nlemma right.one_lt_mul_of_lt_of_le [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b : \u03b1} (ha : 1 < a) (hb : 1 \u2264 b) : 1 < a * b :=\nlt_mul_of_one_lt_of_le ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.one_lt_mul_of_le_of_lt`. -/\n@[to_additive right.add_pos_of_nonneg_of_pos \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_pos_of_nonneg_of_pos`.\"]\nlemma right.one_lt_mul_of_le_of_lt [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (ha : 1 \u2264 a) (hb : 1 < b) : 1 < a * b :=\nlt_mul_of_one_le_of_lt ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.one_lt_mul`. -/\n@[to_additive right.add_pos \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_pos`.\"]\nlemma right.one_lt_mul [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  {a b : \u03b1} (ha : 1 < a) (hb : 1 < b) : 1 < a * b :=\nlt_mul_of_one_lt_of_lt ha hb\n\n/-- Assumes right covariance.\nThe lemma assuming left covariance is `left.one_lt_mul'`. -/\n@[to_additive right.add_pos' \"Assumes right covariance.\nThe lemma assuming left covariance is `left.add_pos'`.\"]\nlemma right.one_lt_mul' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (ha : 1 < a) (hb : 1 < b) : 1 < a * b :=\nlt_mul_of_one_lt_of_lt' ha hb\n\nalias left.mul_le_one             \u2190 mul_le_one'\nalias left.mul_lt_one_of_le_of_lt \u2190 mul_lt_one_of_le_of_lt\nalias left.mul_lt_one_of_lt_of_le \u2190 mul_lt_one_of_lt_of_le\nalias left.mul_lt_one             \u2190 mul_lt_one\nalias left.mul_lt_one'            \u2190 mul_lt_one'\nattribute [to_additive add_nonpos \"**Alias** of `left.add_nonpos`.\"]\nmul_le_one'\nattribute [to_additive add_neg_of_nonpos_of_neg \"**Alias** of `left.add_neg_of_nonpos_of_neg`.\"]\nmul_lt_one_of_le_of_lt\nattribute [to_additive add_neg_of_neg_of_nonpos \"**Alias** of `left.add_neg_of_neg_of_nonpos`.\"]\nmul_lt_one_of_lt_of_le\nattribute [to_additive \"**Alias** of `left.add_neg`.\"]\nmul_lt_one\nattribute [to_additive \"**Alias** of `left.add_neg'`.\"]\nmul_lt_one'\n\nalias left.one_le_mul             \u2190 one_le_mul\nalias left.one_lt_mul_of_le_of_lt \u2190 one_lt_mul_of_le_of_lt'\nalias left.one_lt_mul_of_lt_of_le \u2190 one_lt_mul_of_lt_of_le'\nalias left.one_lt_mul             \u2190 one_lt_mul'\nalias left.one_lt_mul'            \u2190 one_lt_mul''\nattribute [to_additive add_nonneg \"**Alias** of `left.add_nonneg`.\"]\none_le_mul\nattribute [to_additive add_pos_of_nonneg_of_pos \"**Alias** of `left.add_pos_of_nonneg_of_pos`.\"]\none_lt_mul_of_le_of_lt'\nattribute [to_additive add_pos_of_pos_of_nonneg \"**Alias** of `left.add_pos_of_pos_of_nonneg`.\"]\none_lt_mul_of_lt_of_le'\nattribute [to_additive add_pos \"**Alias** of `left.add_pos`.\"]\none_lt_mul'\nattribute [to_additive add_pos' \"**Alias** of `left.add_pos'`.\"]\none_lt_mul''\n\n@[to_additive]\nlemma lt_of_mul_lt_of_one_le_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (h : a * b < c) (hle : 1 \u2264 b) : a < c :=\n(le_mul_of_one_le_right' hle).trans_lt h\n\n@[to_additive]\nlemma le_of_mul_le_of_one_le_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (h : a * b \u2264 c) (hle : 1 \u2264 b) : a \u2264 c :=\n(le_mul_of_one_le_right' hle).trans h\n\n@[to_additive]\nlemma lt_of_lt_mul_of_le_one_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (h : a < b * c) (hle : c \u2264 1) : a < b :=\nh.trans_le (mul_le_of_le_one_right' hle)\n\n@[to_additive]\nlemma le_of_le_mul_of_le_one_left [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (h : a \u2264 b * c) (hle : c \u2264 1) : a \u2264 b :=\nh.trans (mul_le_of_le_one_right' hle)\n\n@[to_additive]\nlemma lt_of_mul_lt_of_one_le_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (h : a * b < c) (hle : 1 \u2264 a) : b < c :=\n(le_mul_of_one_le_left' hle).trans_lt h\n\n@[to_additive]\nlemma le_of_mul_le_of_one_le_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (h : a * b \u2264 c) (hle : 1 \u2264 a) : b \u2264 c :=\n(le_mul_of_one_le_left' hle).trans h\n\n@[to_additive]\nlemma lt_of_lt_mul_of_le_one_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (h : a < b * c) (hle : b \u2264 1) : a < c :=\nh.trans_le (mul_le_of_le_one_left' hle)\n\n@[to_additive]\nlemma le_of_le_mul_of_le_one_right [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c : \u03b1} (h : a \u2264 b * c) (hle : b \u2264 1) : a \u2264 c :=\nh.trans (mul_le_of_le_one_left' hle)\n\nend preorder\n\nsection partial_order\nvariables [partial_order \u03b1]\n\n@[to_additive]\nlemma mul_eq_one_iff' [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b : \u03b1} (ha : 1 \u2264 a) (hb : 1 \u2264 b) : a * b = 1 \u2194 a = 1 \u2227 b = 1 :=\niff.intro\n  (assume hab : a * b = 1,\n   have a \u2264 1, from hab \u25b8 le_mul_of_le_of_one_le le_rfl hb,\n   have a = 1, from le_antisymm this ha,\n   have b \u2264 1, from hab \u25b8 le_mul_of_one_le_of_le ha le_rfl,\n   have b = 1, from le_antisymm this hb,\n   and.intro \u2039a = 1\u203a \u2039b = 1\u203a)\n  (assume \u27e8ha', hb'\u27e9, by rw [ha', hb', mul_one])\n\n@[to_additive] lemma mul_le_mul_iff_of_ge [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] [covariant_class \u03b1 \u03b1 (*) (<)]\n  [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a\u2081 a\u2082 b\u2081 b\u2082 : \u03b1} (ha : a\u2081 \u2264 a\u2082) (hb : b\u2081 \u2264 b\u2082) :\n  a\u2082 * b\u2082 \u2264 a\u2081 * b\u2081 \u2194 a\u2081 = a\u2082 \u2227 b\u2081 = b\u2082 :=\nbegin\n  refine \u27e8\u03bb h, _, by { rintro \u27e8rfl, rfl\u27e9, refl }\u27e9,\n  simp only [eq_iff_le_not_lt, ha, hb, true_and],\n  refine \u27e8\u03bb ha, h.not_lt _, \u03bb hb, h.not_lt _\u27e9,\n  { exact mul_lt_mul_of_lt_of_le ha hb },\n  { exact mul_lt_mul_of_le_of_lt ha hb }\nend\n\nsection left\nvariables [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b : \u03b1}\n\n@[to_additive eq_zero_of_add_nonneg_left]\nlemma eq_one_of_one_le_mul_left (ha : a \u2264 1) (hb : b \u2264 1) (hab : 1 \u2264 a * b) : a = 1 :=\nha.eq_of_not_lt $ \u03bb h, hab.not_lt $ mul_lt_one_of_lt_of_le h hb\n\n@[to_additive]\nlemma eq_one_of_mul_le_one_left (ha : 1 \u2264 a) (hb : 1 \u2264 b) (hab : a * b \u2264 1) : a = 1 :=\nha.eq_of_not_gt $ \u03bb h, hab.not_lt $ one_lt_mul_of_lt_of_le' h hb\n\nend left\n\nsection right\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b : \u03b1}\n\n@[to_additive eq_zero_of_add_nonneg_right]\nlemma eq_one_of_one_le_mul_right (ha : a \u2264 1) (hb : b \u2264 1) (hab : 1 \u2264 a * b) : b = 1 :=\nhb.eq_of_not_lt $ \u03bb h, hab.not_lt $ right.mul_lt_one_of_le_of_lt ha h\n\n@[to_additive]\nlemma eq_one_of_mul_le_one_right (ha : 1 \u2264 a) (hb : 1 \u2264 b) (hab : a * b \u2264 1) : b = 1 :=\nhb.eq_of_not_gt $ \u03bb h, hab.not_lt $ right.one_lt_mul_of_le_of_lt ha h\n\nend right\nend partial_order\n\nsection linear_order\nvariables [linear_order \u03b1]\n\nlemma exists_square_le [covariant_class \u03b1 \u03b1 (*) (<)]\n  (a : \u03b1) : \u2203 (b : \u03b1), b * b \u2264 a :=\nbegin\n  by_cases h : a < 1,\n  { use a,\n    have : a*a < a*1,\n    exact mul_lt_mul_left' h a,\n    rw mul_one at this,\n    exact le_of_lt this },\n  { use 1,\n    push_neg at h,\n    rwa mul_one }\nend\n\nend linear_order\n\nend mul_one_class\n\nsection semigroup\nvariables [semigroup \u03b1]\n\nsection partial_order\nvariables [partial_order \u03b1]\n\n/- This is not instance, since we want to have an instance from `left_cancel_semigroup`s\nto the appropriate `covariant_class`. -/\n/--  A semigroup with a partial order and satisfying `left_cancel_semigroup`\n(i.e. `a * c < b * c \u2192 a < b`) is a `left_cancel semigroup`. -/\n@[to_additive\n\"An additive semigroup with a partial order and satisfying `left_cancel_add_semigroup`\n(i.e. `c + a < c + b \u2192 a < b`) is a `left_cancel add_semigroup`.\"]\ndef contravariant.to_left_cancel_semigroup\n  [contravariant_class \u03b1 \u03b1 (*) (\u2264)] :\n  left_cancel_semigroup \u03b1 :=\n{ mul_left_cancel := \u03bb a b c, mul_left_cancel''\n  ..\u2039semigroup \u03b1\u203a }\n\n/- This is not instance, since we want to have an instance from `right_cancel_semigroup`s\nto the appropriate `covariant_class`. -/\n/--  A semigroup with a partial order and satisfying `right_cancel_semigroup`\n(i.e. `a * c < b * c \u2192 a < b`) is a `right_cancel semigroup`. -/\n@[to_additive\n\"An additive semigroup with a partial order and satisfying `right_cancel_add_semigroup`\n(`a + c < b + c \u2192 a < b`) is a `right_cancel add_semigroup`.\"]\ndef contravariant.to_right_cancel_semigroup\n  [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] :\n  right_cancel_semigroup \u03b1 :=\n{ mul_right_cancel := \u03bb a b c, mul_right_cancel''\n  ..\u2039semigroup \u03b1\u203a }\n\n@[to_additive] lemma left.mul_eq_mul_iff_eq_and_eq\n  [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  [contravariant_class \u03b1 \u03b1 (*) (\u2264)] [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (hac : a \u2264 c) (hbd : b \u2264 d) : a * b = c * d \u2194 a = c \u2227 b = d :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, congr_arg2 (*) h.1 h.2\u27e9,\n  rcases hac.eq_or_lt with rfl | hac,\n  { exact \u27e8rfl, mul_left_cancel'' h\u27e9 },\n  rcases eq_or_lt_of_le hbd with rfl | hbd,\n  { exact \u27e8mul_right_cancel'' h, rfl\u27e9 },\n  exact ((left.mul_lt_mul hac hbd).ne h).elim,\nend\n\n@[to_additive] lemma right.mul_eq_mul_iff_eq_and_eq\n  [covariant_class \u03b1 \u03b1 (*) (\u2264)] [contravariant_class \u03b1 \u03b1 (*) (\u2264)]\n  [covariant_class \u03b1 \u03b1 (swap (*)) (<)] [contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {a b c d : \u03b1} (hac : a \u2264 c) (hbd : b \u2264 d) : a * b = c * d \u2194 a = c \u2227 b = d :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, congr_arg2 (*) h.1 h.2\u27e9,\n  rcases hac.eq_or_lt with rfl | hac,\n  { exact \u27e8rfl, mul_left_cancel'' h\u27e9 },\n  rcases eq_or_lt_of_le hbd with rfl | hbd,\n  { exact \u27e8mul_right_cancel'' h, rfl\u27e9 },\n  exact ((right.mul_lt_mul hac hbd).ne h).elim,\nend\n\nalias left.mul_eq_mul_iff_eq_and_eq \u2190 mul_eq_mul_iff_eq_and_eq\nattribute [to_additive] mul_eq_mul_iff_eq_and_eq\n\nend partial_order\n\nend semigroup\n\nsection mono\nvariables [has_mul \u03b1] [preorder \u03b1] [preorder \u03b2] {f g : \u03b2 \u2192 \u03b1} {s : set \u03b2}\n\n@[to_additive const_add]\nlemma monotone.const_mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] (hf : monotone f) (a : \u03b1) :\n  monotone (\u03bb x, a * f x) :=\n\u03bb x y h, mul_le_mul_left' (hf h) a\n\n@[to_additive const_add]\nlemma monotone_on.const_mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] (hf : monotone_on f s) (a : \u03b1) :\n  monotone_on (\u03bb x, a * f x) s :=\n\u03bb x hx y hy h, mul_le_mul_left' (hf hx hy h) a\n\n@[to_additive const_add]\nlemma antitone.const_mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] (hf : antitone f) (a : \u03b1) :\n  antitone (\u03bb x, a * f x) :=\n\u03bb x y h, mul_le_mul_left' (hf h) a\n\n@[to_additive const_add]\nlemma antitone_on.const_mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] (hf : antitone_on f s) (a : \u03b1) :\n  antitone_on (\u03bb x, a * f x) s :=\n\u03bb x hx y hy h, mul_le_mul_left' (hf hx hy h) a\n\n@[to_additive add_const]\nlemma monotone.mul_const' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : monotone f) (a : \u03b1) : monotone (\u03bb x, f x * a) :=\n\u03bb x y h, mul_le_mul_right' (hf h) a\n\n@[to_additive add_const]\nlemma monotone_on.mul_const' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : monotone_on f s) (a : \u03b1) : monotone_on (\u03bb x, f x * a) s :=\n\u03bb x hx y hy h, mul_le_mul_right' (hf hx hy h) a\n\n@[to_additive add_const]\nlemma antitone.mul_const' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : antitone f) (a : \u03b1) : antitone (\u03bb x, f x * a) :=\n\u03bb x y h, mul_le_mul_right' (hf h) a\n\n@[to_additive add_const]\nlemma antitone_on.mul_const' [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : antitone_on f s) (a : \u03b1) : antitone_on (\u03bb x, f x * a) s :=\n\u03bb x hx y hy h, mul_le_mul_right' (hf hx hy h) a\n\n/--  The product of two monotone functions is monotone. -/\n@[to_additive add \"The sum of two monotone functions is monotone.\"]\nlemma monotone.mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : monotone f) (hg : monotone g) : monotone (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_le_mul' (hf h) (hg h)\n\n/--  The product of two monotone functions is monotone. -/\n@[to_additive add \"The sum of two monotone functions is monotone.\"]\nlemma monotone_on.mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (\u03bb x, f x * g x) s :=\n\u03bb x hx y hy h, mul_le_mul' (hf hx hy h) (hg hx hy h)\n\n/--  The product of two antitone functions is antitone. -/\n@[to_additive add \"The sum of two antitone functions is antitone.\"]\nlemma antitone.mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : antitone f) (hg : antitone g) : antitone (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_le_mul' (hf h) (hg h)\n\n/--  The product of two antitone functions is antitone. -/\n@[to_additive add \"The sum of two antitone functions is antitone.\"]\nlemma antitone_on.mul' [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  (hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (\u03bb x, f x * g x) s :=\n\u03bb x hx y hy h, mul_le_mul' (hf hx hy h) (hg hx hy h)\n\nsection left\nvariables [covariant_class \u03b1 \u03b1 (*) (<)]\n\n@[to_additive const_add] lemma strict_mono.const_mul' (hf : strict_mono f) (c : \u03b1) :\n  strict_mono (\u03bb x, c * f x) :=\n\u03bb a b ab, mul_lt_mul_left' (hf ab) c\n\n@[to_additive const_add] lemma strict_mono_on.const_mul' (hf : strict_mono_on f s) (c : \u03b1) :\n  strict_mono_on (\u03bb x, c * f x) s :=\n\u03bb a ha b hb ab, mul_lt_mul_left' (hf ha hb ab) c\n\n@[to_additive const_add] lemma strict_anti.const_mul' (hf : strict_anti f) (c : \u03b1) :\n  strict_anti (\u03bb x, c * f x) :=\n\u03bb a b ab, mul_lt_mul_left' (hf ab) c\n\n@[to_additive const_add] lemma strict_anti_on.const_mul' (hf : strict_anti_on f s) (c : \u03b1) :\n  strict_anti_on (\u03bb x, c * f x) s :=\n\u03bb a ha b hb ab, mul_lt_mul_left' (hf ha hb ab) c\n\nend left\n\nsection right\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n\n@[to_additive add_const] lemma strict_mono.mul_const' (hf : strict_mono f) (c : \u03b1) :\n  strict_mono (\u03bb x, f x * c) :=\n\u03bb a b ab, mul_lt_mul_right' (hf ab) c\n\n@[to_additive add_const] lemma strict_mono_on.mul_const' (hf : strict_mono_on f s) (c : \u03b1) :\n  strict_mono_on (\u03bb x, f x * c) s :=\n\u03bb a ha b hb ab, mul_lt_mul_right' (hf ha hb ab) c\n\n@[to_additive add_const] lemma strict_anti.mul_const' (hf : strict_anti f) (c : \u03b1) :\n  strict_anti (\u03bb x, f x * c) :=\n\u03bb a b ab, mul_lt_mul_right' (hf ab) c\n\n@[to_additive add_const] lemma strict_anti_on.mul_const' (hf : strict_anti_on f s) (c : \u03b1) :\n  strict_anti_on (\u03bb x, f x * c) s :=\n\u03bb a ha b hb ab, mul_lt_mul_right' (hf ha hb ab) c\n\nend right\n\n/--  The product of two strictly monotone functions is strictly monotone. -/\n@[to_additive add \"The sum of two strictly monotone functions is strictly monotone.\"]\nlemma strict_mono.mul' [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (hf : strict_mono f) (hg : strict_mono g) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb a b ab, mul_lt_mul_of_lt_of_lt (hf ab) (hg ab)\n\n/--  The product of two strictly monotone functions is strictly monotone. -/\n@[to_additive add \"The sum of two strictly monotone functions is strictly monotone.\"]\nlemma strict_mono_on.mul' [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (hf : strict_mono_on f s) (hg : strict_mono_on g s) :\n  strict_mono_on (\u03bb x, f x * g x) s :=\n\u03bb a ha b hb ab, mul_lt_mul_of_lt_of_lt (hf ha hb ab) (hg ha hb ab)\n\n/--  The product of two strictly antitone functions is strictly antitone. -/\n@[to_additive add \"The sum of two strictly antitone functions is strictly antitone.\"]\nlemma strict_anti.mul' [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (hf : strict_anti f) (hg : strict_anti g) :\n  strict_anti (\u03bb x, f x * g x) :=\n\u03bb a b ab, mul_lt_mul_of_lt_of_lt (hf ab) (hg ab)\n\n/--  The product of two strictly antitone functions is strictly antitone. -/\n@[to_additive add \"The sum of two strictly antitone functions is strictly antitone.\"]\nlemma strict_anti_on.mul' [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (hf : strict_anti_on f s) (hg : strict_anti_on g s) :\n  strict_anti_on (\u03bb x, f x * g x) s :=\n\u03bb a ha b hb ab, mul_lt_mul_of_lt_of_lt (hf ha hb ab) (hg ha hb ab)\n\n/--  The product of a monotone function and a strictly monotone function is strictly monotone. -/\n@[to_additive add_strict_mono\n\"The sum of a monotone function and a strictly monotone function is strictly monotone.\"]\nlemma monotone.mul_strict_mono' [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {f g : \u03b2 \u2192 \u03b1} (hf : monotone f) (hg : strict_mono g) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul_of_le_of_lt (hf h.le) (hg h)\n\n/--  The product of a monotone function and a strictly monotone function is strictly monotone. -/\n@[to_additive add_strict_mono\n\"The sum of a monotone function and a strictly monotone function is strictly monotone.\"]\nlemma monotone_on.mul_strict_mono' [covariant_class \u03b1 \u03b1 (*) (<)]\n  [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {f g : \u03b2 \u2192 \u03b1}\n  (hf : monotone_on f s) (hg : strict_mono_on g s) :\n  strict_mono_on (\u03bb x, f x * g x) s :=\n\u03bb x hx y hy h, mul_lt_mul_of_le_of_lt (hf hx hy h.le) (hg hx hy  h)\n\n/--  The product of a antitone function and a strictly antitone function is strictly antitone. -/\n@[to_additive add_strict_anti\n\"The sum of a antitone function and a strictly antitone function is strictly antitone.\"]\nlemma antitone.mul_strict_anti' [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n  {f g : \u03b2 \u2192 \u03b1} (hf : antitone f) (hg : strict_anti g) :\n  strict_anti (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul_of_le_of_lt (hf h.le) (hg h)\n\n/--  The product of a antitone function and a strictly antitone function is strictly antitone. -/\n@[to_additive add_strict_anti\n\"The sum of a antitone function and a strictly antitone function is strictly antitone.\"]\nlemma antitone_on.mul_strict_anti' [covariant_class \u03b1 \u03b1 (*) (<)]\n  [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {f g : \u03b2 \u2192 \u03b1}\n  (hf : antitone_on f s) (hg : strict_anti_on g s) :\n  strict_anti_on (\u03bb x, f x * g x) s :=\n\u03bb x hx y hy h, mul_lt_mul_of_le_of_lt (hf hx hy h.le) (hg hx hy  h)\n\nvariables [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n\n/--  The product of a strictly monotone function and a monotone function is strictly monotone. -/\n@[to_additive add_monotone\n\"The sum of a strictly monotone function and a monotone function is strictly monotone.\"]\nlemma strict_mono.mul_monotone' (hf : strict_mono f) (hg : monotone g) :\n  strict_mono (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul_of_lt_of_le (hf h) (hg h.le)\n\n/--  The product of a strictly monotone function and a monotone function is strictly monotone. -/\n@[to_additive add_monotone\n\"The sum of a strictly monotone function and a monotone function is strictly monotone.\"]\nlemma strict_mono_on.mul_monotone' (hf : strict_mono_on f s) (hg : monotone_on g s) :\n  strict_mono_on (\u03bb x, f x * g x) s :=\n\u03bb x hx y hy h, mul_lt_mul_of_lt_of_le (hf hx hy h) (hg hx hy h.le)\n\n/--  The product of a strictly antitone function and a antitone function is strictly antitone. -/\n@[to_additive add_antitone\n\"The sum of a strictly antitone function and a antitone function is strictly antitone.\"]\nlemma strict_anti.mul_antitone' (hf : strict_anti f) (hg : antitone g) :\n  strict_anti (\u03bb x, f x * g x) :=\n\u03bb x y h, mul_lt_mul_of_lt_of_le (hf h) (hg h.le)\n\n/--  The product of a strictly antitone function and a antitone function is strictly antitone. -/\n@[to_additive add_antitone\n\"The sum of a strictly antitone function and a antitone function is strictly antitone.\"]\nlemma strict_anti_on.mul_antitone' (hf : strict_anti_on f s) (hg : antitone_on g s) :\n  strict_anti_on (\u03bb x, f x * g x) s :=\n\u03bb x hx y hy h, mul_lt_mul_of_lt_of_le (hf hx hy h) (hg hx hy h.le)\n\n@[simp, to_additive cmp_add_left]\nlemma cmp_mul_left' {\u03b1 : Type*} [has_mul \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)]\n  (a b c : \u03b1) : cmp (a * b) (a * c) = cmp b c :=\n(strict_mono_id.const_mul' a).cmp_map_eq b c\n\n@[simp, to_additive cmp_add_right]\nlemma cmp_mul_right' {\u03b1 : Type*} [has_mul \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n  (a b c : \u03b1) : cmp (a * c) (b * c) = cmp a b :=\n(strict_mono_id.mul_const' c).cmp_map_eq a b\n\nend mono\n\n/--\nAn element `a : \u03b1` is `mul_le_cancellable` if `x \u21a6 a * x` is order-reflecting.\nWe will make a separate version of many lemmas that require `[contravariant_class \u03b1 \u03b1 (*) (\u2264)]` with\n`mul_le_cancellable` assumptions instead. These lemmas can then be instantiated to specific types,\nlike `ennreal`, where we can replace the assumption `add_le_cancellable x` by `x \u2260 \u221e`.\n-/\n@[to_additive /-\" An element `a : \u03b1` is `add_le_cancellable` if `x \u21a6 a + x` is order-reflecting.\nWe will make a separate version of many lemmas that require `[contravariant_class \u03b1 \u03b1 (+) (\u2264)]` with\n`mul_le_cancellable` assumptions instead. These lemmas can then be instantiated to specific types,\nlike `ennreal`, where we can replace the assumption `add_le_cancellable x` by `x \u2260 \u221e`. \"-/\n]\ndef mul_le_cancellable [has_mul \u03b1] [has_le \u03b1] (a : \u03b1) : Prop :=\n\u2200 \u2983b c\u2984, a * b \u2264 a * c \u2192 b \u2264 c\n\n@[to_additive]\nlemma contravariant.mul_le_cancellable [has_mul \u03b1] [has_le \u03b1] [contravariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a : \u03b1} : mul_le_cancellable a :=\n\u03bb b c, le_of_mul_le_mul_left'\n\n@[to_additive] lemma mul_le_cancellable_one [monoid \u03b1] [has_le \u03b1] : mul_le_cancellable (1 : \u03b1) :=\n\u03bb a b, by simpa only [one_mul] using id\n\nnamespace mul_le_cancellable\n\n@[to_additive]\nprotected lemma injective [has_mul \u03b1] [partial_order \u03b1] {a : \u03b1} (ha : mul_le_cancellable a) :\n  injective ((*) a) :=\n\u03bb b c h, le_antisymm (ha h.le) (ha h.ge)\n\n@[to_additive]\nprotected lemma inj [has_mul \u03b1] [partial_order \u03b1] {a b c : \u03b1} (ha : mul_le_cancellable a) :\n  a * b = a * c \u2194 b = c :=\nha.injective.eq_iff\n\n@[to_additive]\nprotected lemma injective_left [comm_semigroup \u03b1] [partial_order \u03b1] {a : \u03b1}\n  (ha : mul_le_cancellable a) : injective (* a) :=\n\u03bb b c h, ha.injective $ by rwa [mul_comm a, mul_comm a]\n\n@[to_additive]\nprotected lemma inj_left [comm_semigroup \u03b1] [partial_order \u03b1] {a b c : \u03b1}\n  (hc : mul_le_cancellable c) : a * c = b * c \u2194 a = b :=\nhc.injective_left.eq_iff\n\nvariable [has_le \u03b1]\n\n@[to_additive]\nprotected lemma mul_le_mul_iff_left [has_mul \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (ha : mul_le_cancellable a) : a * b \u2264 a * c \u2194 b \u2264 c :=\n\u27e8\u03bb h, ha h, \u03bb h, mul_le_mul_left' h a\u27e9\n\n@[to_additive]\nprotected lemma mul_le_mul_iff_right [comm_semigroup \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b c : \u03b1} (ha : mul_le_cancellable a) : b * a \u2264 c * a \u2194 b \u2264 c :=\nby rw [mul_comm b, mul_comm c, ha.mul_le_mul_iff_left]\n\n@[to_additive]\nprotected lemma le_mul_iff_one_le_right [mul_one_class \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : mul_le_cancellable a) : a \u2264 a * b \u2194 1 \u2264 b :=\niff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left\n\n@[to_additive]\nprotected lemma mul_le_iff_le_one_right [mul_one_class \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : mul_le_cancellable a) : a * b \u2264 a \u2194 b \u2264 1 :=\niff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left\n\n@[to_additive]\nprotected lemma le_mul_iff_one_le_left [comm_monoid \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : mul_le_cancellable a) : a \u2264 b * a \u2194 1 \u2264 b :=\nby rw [mul_comm, ha.le_mul_iff_one_le_right]\n\n@[to_additive]\nprotected lemma mul_le_iff_le_one_left [comm_monoid \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n  {a b : \u03b1} (ha : mul_le_cancellable a) : b * a \u2264 a \u2194 b \u2264 1 :=\nby rw [mul_comm, ha.mul_le_iff_le_one_right]\n\nend mul_le_cancellable\n\nsection bit\nvariables [has_add \u03b1] [preorder \u03b1]\n\nlemma bit0_mono [covariant_class \u03b1 \u03b1 (+) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)] :\n  monotone (bit0 : \u03b1 \u2192 \u03b1) := \u03bb a b h, add_le_add h h\n\nlemma bit0_strict_mono [covariant_class \u03b1 \u03b1 (+) (<)] [covariant_class \u03b1 \u03b1 (swap (+)) (<)] :\n  strict_mono (bit0 : \u03b1 \u2192 \u03b1) := \u03bb a b h, add_lt_add h h\n\nend bit\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/order/monoid/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7030991809646316}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\nPorted by: Matej Penciak\n\n! This file was ported from Lean 3 source module data.int.order.lemmas\n! leanprover-community/mathlib commit fc2ed6f838ce7c9b7c7171e58d78eaf7b438fb0e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Int.Order.Basic\nimport Mathlib.Algebra.GroupWithZero.Divisibility\nimport Mathlib.Algebra.Order.Ring.Abs\n\n/-!\n# Further lemmas about the integers\nThe distinction between this file and `Data.Int.Order.Basic` is not particularly clear.\nThey are separated by now to minimize the porting requirements for tactics during the transition to\nmathlib4. After `data.rat.order` has been ported, please feel free to reorganize these two files.\n-/\n\n\nopen Nat\n\nnamespace Int\n\n/-! ### nat abs -/\n\n\nvariable {a b : \u2124} {n : \u2115}\n\ntheorem natAbs_eq_iff_mul_self_eq {a b : \u2124} : a.natAbs = b.natAbs \u2194 a * a = b * b := by\n  rw [\u2190 abs_eq_iff_mul_self_eq, abs_eq_natAbs, abs_eq_natAbs]\n  exact Int.coe_nat_inj'.symm\n#align int.nat_abs_eq_iff_mul_self_eq Int.natAbs_eq_iff_mul_self_eq\n\n#align int.eq_nat_abs_iff_mul_eq_zero Int.eq_natAbs_iff_mul_eq_zero\n\ntheorem natAbs_lt_iff_mul_self_lt {a b : \u2124} : a.natAbs < b.natAbs \u2194 a * a < b * b := by\n  rw [\u2190 abs_lt_iff_mul_self_lt, abs_eq_natAbs, abs_eq_natAbs]\n  exact Int.ofNat_lt.symm\n#align int.nat_abs_lt_iff_mul_self_lt Int.natAbs_lt_iff_mul_self_lt\n\ntheorem natAbs_le_iff_mul_self_le {a b : \u2124} : a.natAbs \u2264 b.natAbs \u2194 a * a \u2264 b * b := by\n  rw [\u2190 abs_le_iff_mul_self_le, abs_eq_natAbs, abs_eq_natAbs]\n  exact Int.ofNat_le.symm\n#align int.nat_abs_le_iff_mul_self_le Int.natAbs_le_iff_mul_self_le\n\ntheorem dvd_div_of_mul_dvd {a b c : \u2124} (h : a * b \u2223 c) : b \u2223 c / a := by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  \u00b7 simp only [Int.ediv_zero, dvd_zero]\n  rcases h with \u27e8d, rfl\u27e9\n  refine' \u27e8d, _\u27e9\n  rw [mul_assoc, Int.mul_ediv_cancel_left _ ha]\n#align int.dvd_div_of_mul_dvd Int.dvd_div_of_mul_dvd\n\n/-! ### units -/\n\n\ntheorem eq_zero_of_abs_lt_dvd {m x : \u2124} (h1 : m \u2223 x) (h2 : |x| < m) : x = 0 := by\n  by_cases hm : m = 0;\n  \u00b7 subst m\n    exact zero_dvd_iff.mp h1\n  rcases h1 with \u27e8d, rfl\u27e9\n  apply mul_eq_zero_of_right\n  rw [\u2190 abs_lt_one_iff, \u2190 mul_lt_iff_lt_one_right (abs_pos.mpr hm), \u2190 abs_mul]\n  exact lt_of_lt_of_le h2 (le_abs_self m)\n#align int.eq_zero_of_abs_lt_dvd Int.eq_zero_of_abs_lt_dvd\n\nend Int\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/Order/Lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7030991806545256}}
{"text": "/-\nCopyright (c) 2018 Keeley Hoek. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Keeley Hoek\n-/\nimport tactic.converter.interactive\nimport tactic.ring\n\nexample : 0 + 0 = 0 :=\nbegin\n  conv_lhs {erw [add_zero]}\nend\n\nexample : 0 + 0 = 0 :=\nbegin\n  conv_lhs {simp}\nend\n\nexample : 0 = 0 + 0 :=\nbegin\n  conv_rhs {simp}\nend\n\n-- Example with ring discharging the goal\nexample : 22 + 7 * 4 + 3 * 8 = 0 + 7 * 4 + 46 :=\nbegin\n  conv { ring, },\nend\n\n-- Example with ring failing to discharge, to normalizing the goal\nexample : (22 + 7 * 4 + 3 * 8 = 0 + 7 * 4 + 47) = (74 = 75) :=\nbegin\n  conv { ring_nf, },\nend\n\n-- Example with ring discharging the goal\nexample (x : \u2115) : 22 + 7 * x + 3 * 8 = 0 + 7 * x + 46 :=\nbegin\n  conv { ring, },\nend\n\n-- Example with ring failing to discharge, to normalizing the goal\nexample (x : \u2115) : (22 + 7 * x + 3 * 8 = 0 + 7 * x + 46 + 1)\n                    = (7 * x + 46 = 7 * x + 47) :=\nbegin\n  conv { ring_nf, },\nend\n\n-- norm_num examples:\nexample : 22 + 7 * 4 + 3 * 8 = 74 :=\nbegin\n  conv { norm_num, },\nend\n\nexample (x : \u2115) : 22 + 7 * x + 3 * 8 = 7 * x + 46 :=\nbegin\n  simp [add_comm, add_left_comm],\n  conv { norm_num, },\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/test/conv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424450764199, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7030991768061924}}
{"text": "/-\nCopyright (c) 2020 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro, Yury G. Kudryashov\n-/\nimport order.basic\n\n/-!\n# Unbundled relation classes\n\nIn this file we prove some properties of `is_*` classes defined in `init.algebra.classes`. The main\ndifference between these classes and the usual order classes (`preorder` etc) is that usual classes\nextend `has_le` and/or `has_lt` while these classes take a relation as an explicit argument.\n\n-/\n\nuniverses u v\n\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n\nopen function\n\nlemma comm [is_symm \u03b1 r] {a b : \u03b1} : r a b \u2194 r b a := \u27e8symm, symm\u27e9\nlemma antisymm' [is_antisymm \u03b1 r] {a b : \u03b1} : r a b \u2192 r b a \u2192 b = a := \u03bb h h', antisymm h' h\n\nlemma antisymm_iff [is_refl \u03b1 r] [is_antisymm \u03b1 r] {a b : \u03b1} : r a b \u2227 r b a \u2194 a = b :=\n\u27e8\u03bb h, antisymm h.1 h.2, by { rintro rfl, exact \u27e8refl _, refl _\u27e9 }\u27e9\n\n/-- A version of `antisymm` with `r` explicit.\n\nThis lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there.  -/\n@[elab_simple]\nlemma antisymm_of (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_antisymm \u03b1 r] {a b : \u03b1} : r a b \u2192 r b a \u2192 a = b := antisymm\n\n/-- A version of `antisymm'` with `r` explicit.\n\nThis lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there.  -/\n@[elab_simple]\nlemma antisymm_of' (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_antisymm \u03b1 r] {a b : \u03b1} : r a b \u2192 r b a \u2192 b = a :=\nantisymm'\n\n/-- A version of `comm` with `r` explicit.\n\nThis lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there.  -/\nlemma comm_of (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_symm \u03b1 r] {a b : \u03b1} : r a b \u2194 r b a := comm\n\ntheorem is_refl.swap (r) [is_refl \u03b1 r] : is_refl \u03b1 (swap r) := \u27e8refl_of r\u27e9\ntheorem is_irrefl.swap (r) [is_irrefl \u03b1 r] : is_irrefl \u03b1 (swap r) := \u27e8irrefl_of r\u27e9\ntheorem is_trans.swap (r) [is_trans \u03b1 r] : is_trans \u03b1 (swap r) :=\n\u27e8\u03bb a b c h\u2081 h\u2082, trans_of r h\u2082 h\u2081\u27e9\ntheorem is_antisymm.swap (r) [is_antisymm \u03b1 r] : is_antisymm \u03b1 (swap r) :=\n\u27e8\u03bb a b h\u2081 h\u2082, antisymm h\u2082 h\u2081\u27e9\ntheorem is_asymm.swap (r) [is_asymm \u03b1 r] : is_asymm \u03b1 (swap r) :=\n\u27e8\u03bb a b h\u2081 h\u2082, asymm_of r h\u2082 h\u2081\u27e9\ntheorem is_total.swap (r) [is_total \u03b1 r] : is_total \u03b1 (swap r) :=\n\u27e8\u03bb a b, (total_of r a b).swap\u27e9\ntheorem is_trichotomous.swap (r) [is_trichotomous \u03b1 r] : is_trichotomous \u03b1 (swap r) :=\n\u27e8\u03bb a b, by simpa [swap, or.comm, or.left_comm] using trichotomous_of r a b\u27e9\ntheorem is_preorder.swap (r) [is_preorder \u03b1 r] : is_preorder \u03b1 (swap r) :=\n{..@is_refl.swap \u03b1 r _, ..@is_trans.swap \u03b1 r _}\ntheorem is_strict_order.swap (r) [is_strict_order \u03b1 r] : is_strict_order \u03b1 (swap r) :=\n{..@is_irrefl.swap \u03b1 r _, ..@is_trans.swap \u03b1 r _}\ntheorem is_partial_order.swap (r) [is_partial_order \u03b1 r] : is_partial_order \u03b1 (swap r) :=\n{..@is_preorder.swap \u03b1 r _, ..@is_antisymm.swap \u03b1 r _}\ntheorem is_total_preorder.swap (r) [is_total_preorder \u03b1 r] : is_total_preorder \u03b1 (swap r) :=\n{..@is_preorder.swap \u03b1 r _, ..@is_total.swap \u03b1 r _}\ntheorem is_linear_order.swap (r) [is_linear_order \u03b1 r] : is_linear_order \u03b1 (swap r) :=\n{..@is_partial_order.swap \u03b1 r _, ..@is_total.swap \u03b1 r _}\n\nprotected theorem is_asymm.is_antisymm (r) [is_asymm \u03b1 r] : is_antisymm \u03b1 r :=\n\u27e8\u03bb x y h\u2081 h\u2082, (asymm h\u2081 h\u2082).elim\u27e9\nprotected theorem is_asymm.is_irrefl [is_asymm \u03b1 r] : is_irrefl \u03b1 r :=\n\u27e8\u03bb a h, asymm h h\u27e9\nprotected theorem is_total.is_trichotomous (r) [is_total \u03b1 r] : is_trichotomous \u03b1 r :=\n\u27e8\u03bb a b, or.left_comm.1 (or.inr $ total_of r a b)\u27e9\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance is_total.to_is_refl (r) [is_total \u03b1 r] : is_refl \u03b1 r :=\n\u27e8\u03bb a, (or_self _).1 $ total_of r a a\u27e9\n\nlemma ne_of_irrefl {r} [is_irrefl \u03b1 r] : \u2200 {x y : \u03b1}, r x y \u2192 x \u2260 y | _ _ h rfl := irrefl _ h\nlemma ne_of_irrefl' {r} [is_irrefl \u03b1 r] : \u2200 {x y : \u03b1}, r x y \u2192 y \u2260 x | _ _ h rfl := irrefl _ h\n\nlemma trans_trichotomous_left [is_trans \u03b1 r] [is_trichotomous \u03b1 r] {a b c : \u03b1} :\n  \u00acr b a \u2192 r b c \u2192 r a c :=\nbegin\n  intros h\u2081 h\u2082, rcases trichotomous_of r a b with h\u2083|h\u2083|h\u2083,\n  exact trans h\u2083 h\u2082, rw h\u2083, exact h\u2082, exfalso, exact h\u2081 h\u2083\nend\n\nlemma trans_trichotomous_right [is_trans \u03b1 r] [is_trichotomous \u03b1 r] {a b c : \u03b1} :\n  r a b \u2192 \u00acr c b \u2192 r a c :=\nbegin\n  intros h\u2081 h\u2082, rcases trichotomous_of r b c with h\u2083|h\u2083|h\u2083,\n  exact trans h\u2081 h\u2083, rw \u2190h\u2083, exact h\u2081, exfalso, exact h\u2082 h\u2083\nend\n\n/-- Construct a partial order from a `is_strict_order` relation.\n\nSee note [reducible non-instances]. -/\n@[reducible] def partial_order_of_SO (r) [is_strict_order \u03b1 r] : partial_order \u03b1 :=\n{ le := \u03bb x y, x = y \u2228 r x y,\n  lt := r,\n  le_refl := \u03bb x, or.inl rfl,\n  le_trans := \u03bb x y z h\u2081 h\u2082,\n    match y, z, h\u2081, h\u2082 with\n    | _, _, or.inl rfl, h\u2082 := h\u2082\n    | _, _, h\u2081, or.inl rfl := h\u2081\n    | _, _, or.inr h\u2081, or.inr h\u2082 := or.inr (trans h\u2081 h\u2082)\n    end,\n  le_antisymm := \u03bb x y h\u2081 h\u2082,\n    match y, h\u2081, h\u2082 with\n    | _, or.inl rfl, h\u2082 := rfl\n    | _, h\u2081, or.inl rfl := rfl\n    | _, or.inr h\u2081, or.inr h\u2082 := (asymm h\u2081 h\u2082).elim\n    end,\n  lt_iff_le_not_le := \u03bb x y,\n    \u27e8\u03bb h, \u27e8or.inr h, not_or\n      (\u03bb e, by rw e at h; exact irrefl _ h)\n      (asymm h)\u27e9,\n    \u03bb \u27e8h\u2081, h\u2082\u27e9, h\u2081.resolve_left (\u03bb e, h\u2082 $ e \u25b8 or.inl rfl)\u27e9 }\n\n/-- This is basically the same as `is_strict_total_order`, but that definition has a redundant\nassumption `is_incomp_trans \u03b1 lt`. -/\n@[algebra] class is_strict_total_order' (\u03b1 : Type u) (lt : \u03b1 \u2192 \u03b1 \u2192 Prop)\n  extends is_trichotomous \u03b1 lt, is_strict_order \u03b1 lt : Prop.\n\n/-- Construct a linear order from an `is_strict_total_order'` relation.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef linear_order_of_STO' (r) [is_strict_total_order' \u03b1 r] [\u03a0 x y, decidable (\u00ac r x y)] :\n  linear_order \u03b1 :=\n{ le_total := \u03bb x y,\n    match y, trichotomous_of r x y with\n    | y, or.inl h := or.inl (or.inr h)\n    | _, or.inr (or.inl rfl) := or.inl (or.inl rfl)\n    | _, or.inr (or.inr h) := or.inr (or.inr h)\n    end,\n  decidable_le := \u03bb x y, decidable_of_iff (\u00ac r y x)\n    \u27e8\u03bb h, ((trichotomous_of r y x).resolve_left h).imp eq.symm id,\n      \u03bb h, h.elim (\u03bb h, h \u25b8 irrefl_of _ _) (asymm_of r)\u27e9,\n  ..partial_order_of_SO r }\n\ntheorem is_strict_total_order'.swap (r) [is_strict_total_order' \u03b1 r] :\n  is_strict_total_order' \u03b1 (swap r) :=\n{..is_trichotomous.swap r, ..is_strict_order.swap r}\n\n/-! ### Order connection -/\n\n/-- A connected order is one satisfying the condition `a < c \u2192 a < b \u2228 b < c`.\n  This is recognizable as an intuitionistic substitute for `a \u2264 b \u2228 b \u2264 a` on\n  the constructive reals, and is also known as negative transitivity,\n  since the contrapositive asserts transitivity of the relation `\u00ac a < b`.  -/\n@[algebra] class is_order_connected (\u03b1 : Type u) (lt : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop :=\n(conn : \u2200 a b c, lt a c \u2192 lt a b \u2228 lt b c)\n\ntheorem is_order_connected.neg_trans {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_order_connected \u03b1 r]\n  {a b c} (h\u2081 : \u00ac r a b) (h\u2082 : \u00ac r b c) : \u00ac r a c :=\nmt (is_order_connected.conn a b c) $ by simp [h\u2081, h\u2082]\n\ntheorem is_strict_weak_order_of_is_order_connected [is_asymm \u03b1 r]\n  [is_order_connected \u03b1 r] : is_strict_weak_order \u03b1 r :=\n{ trans := \u03bb a b c h\u2081 h\u2082, (is_order_connected.conn _ c _ h\u2081).resolve_right (asymm h\u2082),\n  incomp_trans := \u03bb a b c \u27e8h\u2081, h\u2082\u27e9 \u27e8h\u2083, h\u2084\u27e9,\n    \u27e8is_order_connected.neg_trans h\u2081 h\u2083, is_order_connected.neg_trans h\u2084 h\u2082\u27e9,\n  ..@is_asymm.is_irrefl \u03b1 r _ }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_order_connected_of_is_strict_total_order'\n  [is_strict_total_order' \u03b1 r] : is_order_connected \u03b1 r :=\n\u27e8\u03bb a b c h, (trichotomous _ _).imp_right (\u03bb o,\n  o.elim (\u03bb e, e \u25b8 h) (\u03bb h', trans h' h))\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_strict_total_order_of_is_strict_total_order'\n  [is_strict_total_order' \u03b1 r] : is_strict_total_order \u03b1 r :=\n{..is_strict_weak_order_of_is_order_connected}\n\n/-! ### Extensional relation -/\n\n/-- An extensional relation is one in which an element is determined by its set\n  of predecessors. It is named for the `x \u2208 y` relation in set theory, whose\n  extensionality is one of the first axioms of ZFC. -/\n@[algebra] class is_extensional (\u03b1 : Type u) (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : Prop :=\n(ext : \u2200 a b, (\u2200 x, r x a \u2194 r x b) \u2192 a = b)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_extensional_of_is_strict_total_order'\n  [is_strict_total_order' \u03b1 r] : is_extensional \u03b1 r :=\n\u27e8\u03bb a b H, ((@trichotomous _ r _ a b)\n  .resolve_left $ mt (H _).2 (irrefl a))\n  .resolve_right $ mt (H _).1 (irrefl b)\u27e9\n\n/-! ### Well-order -/\n\n/-- A well order is a well-founded linear order. -/\n@[algebra] class is_well_order (\u03b1 : Type u) (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n  extends is_strict_total_order' \u03b1 r : Prop :=\n(wf : well_founded r)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_well_order.is_strict_total_order {\u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  is_strict_total_order \u03b1 r := by apply_instance\n@[priority 100] -- see Note [lower instance priority]\ninstance is_well_order.is_extensional {\u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  is_extensional \u03b1 r := by apply_instance\n@[priority 100] -- see Note [lower instance priority]\ninstance is_well_order.is_trichotomous {\u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  is_trichotomous \u03b1 r := by apply_instance\n@[priority 100] -- see Note [lower instance priority]\ninstance is_well_order.is_trans {\u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  is_trans \u03b1 r := by apply_instance\n@[priority 100] -- see Note [lower instance priority]\ninstance is_well_order.is_irrefl {\u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  is_irrefl \u03b1 r := by apply_instance\n@[priority 100] -- see Note [lower instance priority]\ninstance is_well_order.is_asymm {\u03b1} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  is_asymm \u03b1 r := by apply_instance\n\n/-- Construct a decidable linear order from a well-founded linear order. -/\nnoncomputable def is_well_order.linear_order (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  linear_order \u03b1 :=\nby { letI := \u03bb x y, classical.dec (\u00acr x y), exact linear_order_of_STO' r }\n\ninstance empty_relation.is_well_order [subsingleton \u03b1] : is_well_order \u03b1 empty_relation :=\n{ trichotomous := \u03bb a b, or.inr $ or.inl $ subsingleton.elim _ _,\n  irrefl       := \u03bb a, id,\n  trans        := \u03bb a b c, false.elim,\n  wf           := \u27e8\u03bb a, \u27e8_, \u03bb y, false.elim\u27e9\u27e9 }\n\ninstance prod.lex.is_well_order [is_well_order \u03b1 r] [is_well_order \u03b2 s] :\n  is_well_order (\u03b1 \u00d7 \u03b2) (prod.lex r s) :=\n{ trichotomous := \u03bb \u27e8a\u2081, a\u2082\u27e9 \u27e8b\u2081, b\u2082\u27e9,\n    match @trichotomous _ r _ a\u2081 b\u2081 with\n    | or.inl h\u2081 := or.inl $ prod.lex.left _ _ h\u2081\n    | or.inr (or.inr h\u2081) := or.inr $ or.inr $ prod.lex.left _ _ h\u2081\n    | or.inr (or.inl e) := e \u25b8  match @trichotomous _ s _ a\u2082 b\u2082 with\n      | or.inl h := or.inl $ prod.lex.right _ h\n      | or.inr (or.inr h) := or.inr $ or.inr $ prod.lex.right _ h\n      | or.inr (or.inl e) := e \u25b8 or.inr $ or.inl rfl\n      end\n    end,\n  irrefl := \u03bb \u27e8a\u2081, a\u2082\u27e9 h, by cases h with _ _ _ _ h _ _ _ h;\n     [exact irrefl _ h, exact irrefl _ h],\n  trans := \u03bb a b c h\u2081 h\u2082, begin\n    cases h\u2081 with a\u2081 a\u2082 b\u2081 b\u2082 ab a\u2081 b\u2081 b\u2082 ab;\n    cases h\u2082 with _ _ c\u2081 c\u2082 bc _ _ c\u2082 bc,\n    { exact prod.lex.left _ _ (trans ab bc) },\n    { exact prod.lex.left _ _ ab },\n    { exact prod.lex.left _ _ bc },\n    { exact prod.lex.right _ (trans ab bc) }\n  end,\n  wf := prod.lex_wf is_well_order.wf is_well_order.wf }\n\nnamespace set\n\n/-- An unbounded or cofinal set. -/\ndef unbounded (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : set \u03b1) : Prop := \u2200 a, \u2203 b \u2208 s, \u00ac r b a\n/-- A bounded or final set. Not to be confused with `metric.bounded`. -/\ndef bounded (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : set \u03b1) : Prop := \u2203 a, \u2200 b \u2208 s, r b a\n\n@[simp] lemma not_bounded_iff {r : \u03b1 \u2192 \u03b1 \u2192 Prop} (s : set \u03b1) : \u00acbounded r s \u2194 unbounded r s :=\nby simp only [bounded, unbounded, not_forall, not_exists, exists_prop, not_and, not_not]\n\n@[simp] lemma not_unbounded_iff {r : \u03b1 \u2192 \u03b1 \u2192 Prop} (s : set \u03b1) : \u00acunbounded r s \u2194 bounded r s :=\nby rw [not_iff_comm, not_bounded_iff]\n\nend set\n\nnamespace prod\n\ninstance is_refl_preimage_fst {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [h : is_refl \u03b1 r] :\n  is_refl (\u03b1 \u00d7 \u03b1) (prod.fst \u207b\u00b9'o r) := \u27e8\u03bb a, refl_of r a.1\u27e9\n\ninstance is_refl_preimage_snd {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [h : is_refl \u03b1 r] :\n  is_refl (\u03b1 \u00d7 \u03b1) (prod.snd \u207b\u00b9'o r) := \u27e8\u03bb a, refl_of r a.2\u27e9\n\ninstance is_trans_preimage_fst {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [h : is_trans \u03b1 r] :\n  is_trans (\u03b1 \u00d7 \u03b1) (prod.fst \u207b\u00b9'o r) := \u27e8\u03bb _ _ _, trans_of r\u27e9\n\ninstance is_trans_preimage_snd {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [h : is_trans \u03b1 r] :\n  is_trans (\u03b1 \u00d7 \u03b1) (prod.snd \u207b\u00b9'o r) := \u27e8\u03bb _ _ _, trans_of r\u27e9\n\nend prod\n\n/-! ### Strict-non strict relations -/\n\n/-- An unbundled relation class stating that `r` is the nonstrict relation corresponding to the\nstrict relation `s`. Compare `preorder.lt_iff_le_not_le`. This is mostly meant to provide dot\nnotation on `(\u2286)` and `(\u2282)`. -/\nclass is_nonstrict_strict_order (\u03b1 : Type*) (r s : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n(right_iff_left_not_left (a b : \u03b1) : s a b \u2194 r a b \u2227 \u00ac r b a)\n\nlemma right_iff_left_not_left {r s : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_nonstrict_strict_order \u03b1 r s] {a b : \u03b1} :\n  s a b \u2194 r a b \u2227 \u00ac r b a :=\nis_nonstrict_strict_order.right_iff_left_not_left _ _\n\n/-- A version of `right_iff_left_not_left` with explicit `r` and `s`. -/\nlemma right_iff_left_not_left_of (r s : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_nonstrict_strict_order \u03b1 r s] {a b : \u03b1} :\n  s a b \u2194 r a b \u2227 \u00ac r b a :=\nright_iff_left_not_left\n\n-- The free parameter `r` is strictly speaking not uniquely determined by `s`, but in practice it\n-- always has a unique instance, so this is not dangerous.\n@[priority 100, nolint dangerous_instance] -- see Note [lower instance priority]\ninstance is_nonstrict_strict_order.to_is_irrefl {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b1 \u2192 \u03b1 \u2192 Prop}\n  [is_nonstrict_strict_order \u03b1 r s] :\n  is_irrefl \u03b1 s :=\n\u27e8\u03bb a h, ((right_iff_left_not_left_of r s).1 h).2 ((right_iff_left_not_left_of r s).1 h).1\u27e9\n\n/-! #### `\u2286` and `\u2282` -/\n\nsection subset\nvariables [has_subset \u03b1] {a b c : \u03b1}\n\n@[refl] lemma subset_refl [is_refl \u03b1 (\u2286)] (a : \u03b1) : a \u2286 a := refl _\nlemma subset_rfl [is_refl \u03b1 (\u2286)] : a \u2286 a := refl _\nlemma subset_of_eq [is_refl \u03b1 (\u2286)] : a = b \u2192 a \u2286 b := \u03bb h, h \u25b8 subset_rfl\nlemma superset_of_eq [is_refl \u03b1 (\u2286)] : a = b \u2192 b \u2286 a := \u03bb h, h \u25b8 subset_rfl\nlemma ne_of_not_subset [is_refl \u03b1 (\u2286)] : \u00ac a \u2286 b \u2192 a \u2260 b := mt subset_of_eq\nlemma ne_of_not_superset [is_refl \u03b1 (\u2286)] : \u00ac a \u2286 b \u2192 b \u2260 a := mt superset_of_eq\n@[trans] lemma subset_trans [is_trans \u03b1 (\u2286)] (h : a \u2286 b) (h' : b \u2286 c) : a \u2286 c := trans h h'\n\nlemma subset_antisymm [is_antisymm \u03b1 (\u2286)] (h : a \u2286 b) (h' : b \u2286 a) : a = b :=\nantisymm h h'\n\nlemma superset_antisymm [is_antisymm \u03b1 (\u2286)] (h : a \u2286 b) (h' : b \u2286 a) : b = a :=\nantisymm' h h'\n\nalias subset_of_eq \u2190 eq.subset' --TODO: Fix it and kill `eq.subset`\nalias superset_of_eq \u2190 eq.superset\nalias subset_trans      \u2190 has_subset.subset.trans\nalias subset_antisymm   \u2190 has_subset.subset.antisymm\nalias superset_antisymm \u2190 has_subset.subset.antisymm'\n\nlemma subset_antisymm_iff [is_refl \u03b1 (\u2286)] [is_antisymm \u03b1 (\u2286)] : a = b \u2194 a \u2286 b \u2227 b \u2286 a :=\n\u27e8\u03bb h, \u27e8h.subset', h.superset\u27e9, \u03bb h, h.1.antisymm h.2\u27e9\n\nlemma superset_antisymm_iff [is_refl \u03b1 (\u2286)] [is_antisymm \u03b1 (\u2286)] : a = b \u2194 b \u2286 a \u2227 a \u2286 b :=\n\u27e8\u03bb h, \u27e8h.superset, h.subset'\u27e9, \u03bb h, h.1.antisymm' h.2\u27e9\n\nend subset\n\nsection ssubset\nvariables [has_ssubset \u03b1]\n\nlemma ssubset_irrefl [is_irrefl \u03b1 (\u2282)] (a : \u03b1) : \u00ac a \u2282 a := irrefl _\nlemma ssubset_irrfl [is_irrefl \u03b1 (\u2282)] {a : \u03b1} : \u00ac a \u2282 a := irrefl _\nlemma ne_of_ssubset [is_irrefl \u03b1 (\u2282)] {a b : \u03b1} : a \u2282 b \u2192 a \u2260 b := ne_of_irrefl\nlemma ne_of_ssuperset [is_irrefl \u03b1 (\u2282)] {a b : \u03b1} : a \u2282 b \u2192 b \u2260 a := ne_of_irrefl'\n@[trans] lemma ssubset_trans [is_trans \u03b1 (\u2282)] {a b c : \u03b1} (h : a \u2282 b) (h' : b \u2282 c) : a \u2282 c :=\ntrans h h'\nlemma ssubset_asymm [is_asymm \u03b1 (\u2282)] {a b : \u03b1} (h : a \u2282 b) : \u00ac b \u2282 a := asymm h\n\nalias ssubset_irrfl   \u2190 has_ssubset.ssubset.false\nalias ne_of_ssubset   \u2190 has_ssubset.ssubset.ne\nalias ne_of_ssuperset \u2190 has_ssubset.ssubset.ne'\nalias ssubset_trans   \u2190 has_ssubset.ssubset.trans\nalias ssubset_asymm   \u2190 has_ssubset.ssubset.asymm\n\nend ssubset\n\nsection subset_ssubset\nvariables [has_subset \u03b1] [has_ssubset \u03b1] [is_nonstrict_strict_order \u03b1 (\u2286) (\u2282)] {a b c : \u03b1}\n\nlemma ssubset_iff_subset_not_subset : a \u2282 b \u2194 a \u2286 b \u2227 \u00ac b \u2286 a := right_iff_left_not_left\nlemma subset_of_ssubset (h : a \u2282 b) : a \u2286 b := (ssubset_iff_subset_not_subset.1 h).1\nlemma not_subset_of_ssubset (h : a \u2282 b) : \u00ac b \u2286 a := (ssubset_iff_subset_not_subset.1 h).2\nlemma not_ssubset_of_subset (h : a \u2286 b) : \u00ac b \u2282 a := \u03bb h', not_subset_of_ssubset h' h\n\nlemma ssubset_of_subset_not_subset (h\u2081 : a \u2286 b) (h\u2082 : \u00ac b \u2286 a) : a \u2282 b :=\nssubset_iff_subset_not_subset.2 \u27e8h\u2081, h\u2082\u27e9\n\nalias subset_of_ssubset            \u2190 has_ssubset.ssubset.subset\nalias not_subset_of_ssubset        \u2190 has_ssubset.ssubset.not_subset\nalias not_ssubset_of_subset        \u2190 has_subset.subset.not_ssubset\nalias ssubset_of_subset_not_subset \u2190 has_subset.subset.ssubset_of_not_subset\n\nlemma ssubset_of_subset_of_ssubset [is_trans \u03b1 (\u2286)] (h\u2081 : a \u2286 b) (h\u2082 : b \u2282 c) : a \u2282 c :=\n(h\u2081.trans h\u2082.subset).ssubset_of_not_subset $ \u03bb h, h\u2082.not_subset $ h.trans h\u2081\n\nlemma ssubset_of_ssubset_of_subset [is_trans \u03b1 (\u2286)] (h\u2081 : a \u2282 b) (h\u2082 : b \u2286 c) : a \u2282 c :=\n(h\u2081.subset.trans h\u2082).ssubset_of_not_subset $ \u03bb h, h\u2081.not_subset $ h\u2082.trans h\n\nlemma ssubset_of_subset_of_ne [is_antisymm \u03b1 (\u2286)] (h\u2081 : a \u2286 b) (h\u2082 : a \u2260 b) : a \u2282 b :=\nh\u2081.ssubset_of_not_subset $ mt h\u2081.antisymm h\u2082\n\nlemma ssubset_of_ne_of_subset [is_antisymm \u03b1 (\u2286)] (h\u2081 : a \u2260 b) (h\u2082 : a \u2286 b) : a \u2282 b :=\nssubset_of_subset_of_ne h\u2082 h\u2081\n\nlemma eq_or_ssubset_of_subset [is_antisymm \u03b1 (\u2286)] (h : a \u2286 b) : a = b \u2228 a \u2282 b :=\n(em (b \u2286 a)).imp h.antisymm h.ssubset_of_not_subset\n\nlemma ssubset_or_eq_of_subset [is_antisymm \u03b1 (\u2286)] (h : a \u2286 b) : a \u2282 b \u2228 a = b :=\n(eq_or_ssubset_of_subset h).swap\n\nalias ssubset_of_subset_of_ssubset \u2190 has_subset.subset.trans_ssubset\nalias ssubset_of_ssubset_of_subset \u2190 has_ssubset.ssubset.trans_subset\nalias ssubset_of_subset_of_ne      \u2190 has_subset.subset.ssubset_of_ne\nalias ssubset_of_ne_of_subset      \u2190 ne.ssubset_of_subset\nalias eq_or_ssubset_of_subset      \u2190 has_subset.subset.eq_or_ssubset\nalias ssubset_or_eq_of_subset      \u2190 has_subset.subset.ssubset_or_eq\n\nlemma ssubset_iff_subset_ne [is_antisymm \u03b1 (\u2286)] : a \u2282 b \u2194 a \u2286 b \u2227 a \u2260 b :=\n\u27e8\u03bb h, \u27e8h.subset, h.ne\u27e9, \u03bb h, h.1.ssubset_of_ne h.2\u27e9\n\nlemma subset_iff_ssubset_or_eq [is_refl \u03b1 (\u2286)] [is_antisymm \u03b1 (\u2286)] : a \u2286 b \u2194 a \u2282 b \u2228 a = b :=\n\u27e8\u03bb h, h.ssubset_or_eq, \u03bb h, h.elim subset_of_ssubset subset_of_eq\u27e9\n\nend subset_ssubset\n\n/-! ### Conversion of bundled order typeclasses to unbundled relation typeclasses -/\n\ninstance [preorder \u03b1] : is_refl \u03b1 (\u2264) := \u27e8le_refl\u27e9\ninstance [preorder \u03b1] : is_refl \u03b1 (\u2265) := is_refl.swap _\ninstance [preorder \u03b1] : is_trans \u03b1 (\u2264) := \u27e8@le_trans _ _\u27e9\ninstance [preorder \u03b1] : is_trans \u03b1 (\u2265) := is_trans.swap _\ninstance [preorder \u03b1] : is_preorder \u03b1 (\u2264) := {}\ninstance [preorder \u03b1] : is_preorder \u03b1 (\u2265) := {}\ninstance [preorder \u03b1] : is_irrefl \u03b1 (<) := \u27e8lt_irrefl\u27e9\ninstance [preorder \u03b1] : is_irrefl \u03b1 (>) := is_irrefl.swap _\ninstance [preorder \u03b1] : is_trans \u03b1 (<) := \u27e8@lt_trans _ _\u27e9\ninstance [preorder \u03b1] : is_trans \u03b1 (>) := is_trans.swap _\ninstance [preorder \u03b1] : is_asymm \u03b1 (<) := \u27e8@lt_asymm _ _\u27e9\ninstance [preorder \u03b1] : is_asymm \u03b1 (>) := is_asymm.swap _\ninstance [preorder \u03b1] : is_antisymm \u03b1 (<) := is_asymm.is_antisymm _\ninstance [preorder \u03b1] : is_antisymm \u03b1 (>) := is_asymm.is_antisymm _\ninstance [preorder \u03b1] : is_strict_order \u03b1 (<) := {}\ninstance [preorder \u03b1] : is_strict_order \u03b1 (>) := {}\ninstance [preorder \u03b1] : is_nonstrict_strict_order \u03b1 (\u2264) (<) := \u27e8@lt_iff_le_not_le _ _\u27e9\ninstance [partial_order \u03b1] : is_antisymm \u03b1 (\u2264) := \u27e8@le_antisymm _ _\u27e9\ninstance [partial_order \u03b1] : is_antisymm \u03b1 (\u2265) := is_antisymm.swap _\ninstance [partial_order \u03b1] : is_partial_order \u03b1 (\u2264) := {}\ninstance [partial_order \u03b1] : is_partial_order \u03b1 (\u2265) := {}\ninstance [linear_order \u03b1] : is_total \u03b1 (\u2264) := \u27e8le_total\u27e9\ninstance [linear_order \u03b1] : is_total \u03b1 (\u2265) := is_total.swap _\ninstance linear_order.is_total_preorder [linear_order \u03b1] : is_total_preorder \u03b1 (\u2264) :=\n  by apply_instance\ninstance [linear_order \u03b1] : is_total_preorder \u03b1 (\u2265) := {}\ninstance [linear_order \u03b1] : is_linear_order \u03b1 (\u2264) := {}\ninstance [linear_order \u03b1] : is_linear_order \u03b1 (\u2265) := {}\ninstance [linear_order \u03b1] : is_trichotomous \u03b1 (<) := \u27e8lt_trichotomy\u27e9\ninstance [linear_order \u03b1] : is_trichotomous \u03b1 (>) := is_trichotomous.swap _\ninstance [linear_order \u03b1] : is_trichotomous \u03b1 (\u2264) := is_total.is_trichotomous _\ninstance [linear_order \u03b1] : is_trichotomous \u03b1 (\u2265) := is_total.is_trichotomous _\ninstance [linear_order \u03b1] : is_strict_total_order \u03b1 (<) := by apply_instance\ninstance [linear_order \u03b1] : is_strict_total_order' \u03b1 (<) := {}\ninstance [linear_order \u03b1] : is_order_connected \u03b1 (<) := by apply_instance\ninstance [linear_order \u03b1] : is_incomp_trans \u03b1 (<) := by apply_instance\ninstance [linear_order \u03b1] : is_strict_weak_order \u03b1 (<) := by apply_instance\n\ninstance order_dual.is_total_le [has_le \u03b1] [is_total \u03b1 (\u2264)] : is_total (order_dual \u03b1) (\u2264) :=\n@is_total.swap \u03b1 _ _\n\ninstance nat.lt.is_well_order : is_well_order \u2115 (<) := \u27e8nat.lt_wf\u27e9\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/order/rel_classes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7030991688909449}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport algebra.star.basic\nimport data.set.pointwise\n\n/-!\n# Pointwise star operation on sets\n\nThis file defines the star operation pointwise on sets and provides the basic API.\nBesides basic facts about about how the star operation acts on sets (e.g., `(s \u2229 t)\u22c6 = s\u22c6 \u2229 t\u22c6`),\nif `s t : set \u03b1`, then under suitable assumption on `\u03b1`, it is shown\n\n* `(s + t)\u22c6 = s\u22c6 + t\u22c6`\n* `(s * t)\u22c6 = t\u22c6 + s\u22c6`\n* `(s\u207b\u00b9)\u22c6 = (s\u22c6)\u207b\u00b9`\n-/\n\nnamespace set\n\nopen_locale pointwise\n\nlocal postfix `\u22c6`:std.prec.max_plus := star\n\nvariables {\u03b1 : Type*} {s t : set \u03b1} {a : \u03b1}\n\n/-- The set `(star s : set \u03b1)` is defined as `{x | star x \u2208 s}` in locale `pointwise`.\nIn the usual case where `star` is involutive, it is equal to `{star s | x \u2208 s}`, see\n`set.image_star`. -/\nprotected def has_star [has_star \u03b1] : has_star (set \u03b1) :=\n\u27e8preimage has_star.star\u27e9\n\nlocalized \"attribute [instance] set.has_star\" in pointwise\n\n@[simp]\nlemma star_empty [has_star \u03b1] : (\u2205 : set \u03b1)\u22c6 = \u2205 := rfl\n\n@[simp]\nlemma star_univ [has_star \u03b1] : (univ : set \u03b1)\u22c6 = univ := rfl\n\n@[simp]\nlemma nonempty_star [has_involutive_star \u03b1] {s : set \u03b1} : (s\u22c6).nonempty \u2194 s.nonempty :=\nstar_involutive.surjective.nonempty_preimage\n\nlemma nonempty.star [has_involutive_star \u03b1] {s : set \u03b1} (h : s.nonempty) :\n  (s\u22c6).nonempty :=\nnonempty_star.2 h\n\n@[simp]\nlemma mem_star [has_star \u03b1] : a \u2208 s\u22c6 \u2194 a\u22c6 \u2208 s := iff.rfl\n\nlemma star_mem_star [has_involutive_star \u03b1] : a\u22c6 \u2208 s\u22c6 \u2194 a \u2208 s :=\nby simp only [mem_star, star_star]\n\n@[simp]\nlemma star_preimage [has_star \u03b1] : has_star.star \u207b\u00b9' s = s\u22c6 := rfl\n\n@[simp]\nlemma image_star [has_involutive_star \u03b1] : has_star.star '' s = s\u22c6 :=\nby { simp only [\u2190 star_preimage], rw [image_eq_preimage_of_inverse]; intro; simp only [star_star] }\n\n@[simp]\nlemma inter_star [has_star \u03b1] : (s \u2229 t)\u22c6 = s\u22c6 \u2229 t\u22c6 := preimage_inter\n\n@[simp]\nlemma union_star [has_star \u03b1] : (s \u222a t)\u22c6 = s\u22c6 \u222a t\u22c6 := preimage_union\n\n@[simp]\nlemma Inter_star {\u03b9 : Sort*} [has_star \u03b1] (s : \u03b9 \u2192 set \u03b1) : (\u22c2 i, s i)\u22c6 = \u22c2 i, (s i)\u22c6 :=\npreimage_Inter\n\n@[simp]\n\n\n@[simp]\nlemma compl_star [has_star \u03b1] : (s\u1d9c)\u22c6 = (s\u22c6)\u1d9c := preimage_compl\n\n@[simp]\ninstance [has_involutive_star \u03b1] : has_involutive_star (set \u03b1) :=\n{ star := has_star.star,\n  star_involutive :=\n    \u03bb s, by { simp only [\u2190 star_preimage, preimage_preimage, star_star, preimage_id'] } }\n\n@[simp]\nlemma star_subset_star [has_involutive_star \u03b1] {s t : set \u03b1} : s\u22c6 \u2286 t\u22c6 \u2194 s \u2286 t :=\nequiv.star.surjective.preimage_subset_preimage_iff\n\nlemma star_subset [has_involutive_star \u03b1] {s t : set \u03b1} : s\u22c6 \u2286 t \u2194 s \u2286 t\u22c6 :=\nby { rw [\u2190 star_subset_star, star_star] }\n\nlemma finite.star [has_involutive_star \u03b1] {s : set \u03b1} (hs : finite s) : finite s\u22c6 :=\nhs.preimage $ star_injective.inj_on _\n\nlemma star_singleton {\u03b2 : Type*} [has_involutive_star \u03b2] (x : \u03b2) : ({x} : set \u03b2)\u22c6 = {x\u22c6} :=\nby { ext1 y, rw [mem_star, mem_singleton_iff, mem_singleton_iff, star_eq_iff_star_eq, eq_comm], }\n\nprotected lemma star_mul [monoid \u03b1] [star_semigroup \u03b1] (s t : set \u03b1) :\n  (s * t)\u22c6 = t\u22c6 * s\u22c6 :=\nby simp_rw [\u2190image_star, \u2190image2_mul, image_image2, image2_image_left, image2_image_right,\n              star_mul, image2_swap _ s t]\n\nprotected lemma star_add [add_monoid \u03b1] [star_add_monoid \u03b1] (s t : set \u03b1) :\n  (s + t)\u22c6 = s\u22c6 + t\u22c6 :=\nby simp_rw [\u2190image_star, \u2190image2_add, image_image2, image2_image_left, image2_image_right, star_add]\n\n@[simp]\ninstance [has_star \u03b1] [has_trivial_star \u03b1] : has_trivial_star (set \u03b1) :=\n{ star_trivial := \u03bb s, by { rw [\u2190star_preimage], ext1, simp [star_trivial] } }\n\nprotected lemma star_inv [group \u03b1] [star_semigroup \u03b1] (s : set \u03b1) : (s\u207b\u00b9)\u22c6 = (s\u22c6)\u207b\u00b9 :=\nby { ext, simp only [mem_star, mem_inv, star_inv] }\n\nprotected lemma star_inv' [division_ring \u03b1] [star_ring \u03b1] (s : set \u03b1) : (s\u207b\u00b9)\u22c6 = (s\u22c6)\u207b\u00b9 :=\nby { ext, simp only [mem_star, mem_inv, star_inv'] }\n\nend set\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/star/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7030991680521497}}
{"text": "/-\nCopyright (c) 2020 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n-/\n\nimport algebra.order.field\nimport algebra.smul_with_zero\nimport group_theory.group_action.group\n\n/-!\n# Ordered scalar product\n\nIn this file we define\n\n* `ordered_smul R M` : an ordered additive commutative monoid `M` is an `ordered_smul`\n  over an `ordered_semiring` `R` if the scalar product respects the order relation on the\n  monoid and on the ring. There is a correspondence between this structure and convex cones,\n  which is proven in `analysis/convex/cone.lean`.\n\n## Implementation notes\n\n* We choose to define `ordered_smul` as a `Prop`-valued mixin, so that it can be\n  used for actions, modules, and algebras\n  (the axioms for an \"ordered algebra\" are exactly that the algebra is ordered as a module).\n* To get ordered modules and ordered vector spaces, it suffices to replace the\n  `order_add_comm_monoid` and the `ordered_semiring` as desired.\n\n## References\n\n* https://en.wikipedia.org/wiki/Ordered_module\n\n## Tags\n\nordered module, ordered scalar, ordered smul, ordered action, ordered vector space\n-/\n\n\n/--\nThe ordered scalar product property is when an ordered additive commutative monoid\nwith a partial order has a scalar multiplication which is compatible with the order.\n-/\n@[protect_proj]\nclass ordered_smul (R M : Type*)\n  [ordered_semiring R] [ordered_add_comm_monoid M] [smul_with_zero R M] : Prop :=\n(smul_lt_smul_of_pos : \u2200 {a b : M}, \u2200 {c : R}, a < b \u2192 0 < c \u2192 c \u2022 a < c \u2022 b)\n(lt_of_smul_lt_smul_of_pos : \u2200 {a b : M}, \u2200 {c : R}, c \u2022 a < c \u2022 b \u2192 0 < c \u2192 a < b)\n\nnamespace order_dual\n\nvariables {R M : Type*}\n\ninstance [has_smul R M] : has_smul R M\u1d52\u1d48 := \u27e8\u03bb k x, order_dual.rec (\u03bb x', (k \u2022 x' : M)) x\u27e9\n\ninstance [has_zero R] [add_zero_class M] [h : smul_with_zero R M] : smul_with_zero R M\u1d52\u1d48 :=\n{ zero_smul := \u03bb m, order_dual.rec (zero_smul _) m,\n  smul_zero := \u03bb r, order_dual.rec (smul_zero' _) r,\n  ..order_dual.has_smul }\n\ninstance [monoid R] [mul_action R M] : mul_action R M\u1d52\u1d48 :=\n{ one_smul := \u03bb m, order_dual.rec (one_smul _) m,\n  mul_smul := \u03bb r, order_dual.rec mul_smul r,\n  ..order_dual.has_smul }\n\ninstance [monoid_with_zero R] [add_monoid M] [mul_action_with_zero R M] :\n  mul_action_with_zero R M\u1d52\u1d48 :=\n{ ..order_dual.mul_action, ..order_dual.smul_with_zero }\n\ninstance [monoid_with_zero R] [add_monoid M] [distrib_mul_action R M] :\n  distrib_mul_action R M\u1d52\u1d48 :=\n{ smul_add := \u03bb k a, order_dual.rec (\u03bb a' b, order_dual.rec (smul_add _ _) b) a,\n  smul_zero := \u03bb r, order_dual.rec smul_zero r }\n\ninstance [ordered_semiring R] [ordered_add_comm_monoid M] [smul_with_zero R M]\n  [ordered_smul R M] :\n  ordered_smul R M\u1d52\u1d48 :=\n{ smul_lt_smul_of_pos := \u03bb a b, @ordered_smul.smul_lt_smul_of_pos R M _ _ _ _ b a,\n  lt_of_smul_lt_smul_of_pos := \u03bb a b,\n    @ordered_smul.lt_of_smul_lt_smul_of_pos R M _ _ _ _ b a }\n\n@[simp] lemma to_dual_smul [has_smul R M] {c : R} {a : M} : to_dual (c \u2022 a) = c \u2022 to_dual a := rfl\n@[simp] lemma of_dual_smul [has_smul R M] {c : R} {a : M\u1d52\u1d48} : of_dual (c \u2022 a) = c \u2022 of_dual a :=\nrfl\n\nend order_dual\n\nsection ordered_smul\n\nvariables {R M : Type*}\n  [ordered_semiring R] [ordered_add_comm_monoid M] [smul_with_zero R M] [ordered_smul R M]\n  {a b : M} {c : R}\n\nlemma smul_lt_smul_of_pos : a < b \u2192 0 < c \u2192 c \u2022 a < c \u2022 b := ordered_smul.smul_lt_smul_of_pos\n\nlemma smul_le_smul_of_nonneg (h\u2081 : a \u2264 b) (h\u2082 : 0 \u2264 c) : c \u2022 a \u2264 c \u2022 b :=\nbegin\n  rcases h\u2081.eq_or_lt with rfl|hab,\n  { refl },\n  { rcases h\u2082.eq_or_lt with rfl|hc,\n    { rw [zero_smul, zero_smul] },\n    { exact (smul_lt_smul_of_pos hab hc).le } }\nend\n\nlemma smul_nonneg (hc : 0 \u2264 c) (ha : 0 \u2264 a) : 0 \u2264 c \u2022 a :=\ncalc (0 : M) = c \u2022 (0 : M) : (smul_zero' M c).symm\n         ... \u2264 c \u2022 a : smul_le_smul_of_nonneg ha hc\n\nlemma smul_nonpos_of_nonneg_of_nonpos (hc : 0 \u2264 c) (ha : a \u2264 0) : c \u2022 a \u2264 0 :=\n@smul_nonneg R M\u1d52\u1d48 _ _ _ _ _ _ hc ha\n\nlemma eq_of_smul_eq_smul_of_pos_of_le (h\u2081 : c \u2022 a = c \u2022 b) (hc : 0 < c) (hle : a \u2264 b) :\n  a = b :=\nhle.lt_or_eq.resolve_left $ \u03bb hlt, (smul_lt_smul_of_pos hlt hc).ne h\u2081\n\nlemma lt_of_smul_lt_smul_of_nonneg (h : c \u2022 a < c \u2022 b) (hc : 0 \u2264 c) : a < b :=\nhc.eq_or_lt.elim (\u03bb hc, false.elim $ lt_irrefl (0:M) $ by rwa [\u2190 hc, zero_smul, zero_smul] at h)\n  (ordered_smul.lt_of_smul_lt_smul_of_pos h)\n\nlemma smul_lt_smul_iff_of_pos (hc : 0 < c) : c \u2022 a < c \u2022 b \u2194 a < b :=\n\u27e8\u03bb h, lt_of_smul_lt_smul_of_nonneg h hc.le, \u03bb h, smul_lt_smul_of_pos h hc\u27e9\n\nlemma smul_pos_iff_of_pos (hc : 0 < c) : 0 < c \u2022 a \u2194 0 < a :=\ncalc 0 < c \u2022 a \u2194 c \u2022 0 < c \u2022 a : by rw smul_zero'\n           ... \u2194 0 < a         : smul_lt_smul_iff_of_pos hc\n\nalias smul_pos_iff_of_pos \u2194 _ smul_pos\n\nlemma monotone_smul_left (hc : 0 \u2264 c) : monotone (has_smul.smul c : M \u2192 M) :=\n\u03bb a b h, smul_le_smul_of_nonneg h hc\n\nlemma strict_mono_smul_left (hc : 0 < c) : strict_mono (has_smul.smul c : M \u2192 M) :=\n\u03bb a b h, smul_lt_smul_of_pos h hc\n\nend ordered_smul\n\n/-- If `R` is a linear ordered semifield, then it suffices to verify only the first axiom of\n`ordered_smul`. Moreover, it suffices to verify that `a < b` and `0 < c` imply\n`c \u2022 a \u2264 c \u2022 b`. We have no semifields in `mathlib`, so we use the assumption `\u2200 c \u2260 0, is_unit c`\ninstead. -/\nlemma ordered_smul.mk'' {R M : Type*} [linear_ordered_semiring R] [ordered_add_comm_monoid M]\n  [mul_action_with_zero R M] (hR : \u2200 {c : R}, c \u2260 0 \u2192 is_unit c)\n  (hlt : \u2200 \u2983a b : M\u2984 \u2983c : R\u2984, a < b \u2192 0 < c \u2192 c \u2022 a \u2264 c \u2022 b) :\n  ordered_smul R M :=\nbegin\n  have hlt' : \u2200 \u2983a b : M\u2984 \u2983c : R\u2984, a < b \u2192 0 < c \u2192 c \u2022 a < c \u2022 b,\n  { refine \u03bb a b c hab hc, (hlt hab hc).lt_of_ne _,\n    rw [ne.def, (hR hc.ne').smul_left_cancel],\n    exact hab.ne },\n  refine { smul_lt_smul_of_pos := hlt', .. },\n  intros a b c h hc,\n  rcases (hR hc.ne') with \u27e8c, rfl\u27e9,\n  rw [\u2190 inv_smul_smul c a, \u2190 inv_smul_smul c b],\n  refine hlt' h (pos_of_mul_pos_left _ hc.le),\n  simp only [c.mul_inv, zero_lt_one]\nend\n\n/-- If `R` is a linear ordered field, then it suffices to verify only the first axiom of\n`ordered_smul`. -/\nlemma ordered_smul.mk' {k M : Type*} [linear_ordered_field k] [ordered_add_comm_monoid M]\n  [mul_action_with_zero k M] (hlt : \u2200 \u2983a b : M\u2984 \u2983c : k\u2984, a < b \u2192 0 < c \u2192 c \u2022 a \u2264 c \u2022 b) :\n  ordered_smul k M :=\nordered_smul.mk'' (\u03bb c hc, is_unit.mk0 _ hc) hlt\n\ninstance linear_ordered_semiring.to_ordered_smul {R : Type*} [linear_ordered_semiring R] :\n  ordered_smul R R :=\n{ smul_lt_smul_of_pos        := ordered_semiring.mul_lt_mul_of_pos_left,\n  lt_of_smul_lt_smul_of_pos  := \u03bb _ _ _ h hc, lt_of_mul_lt_mul_left h hc.le }\n\nsection field\n\nvariables {k M : Type*} [linear_ordered_field k]\n  [ordered_add_comm_group M] [mul_action_with_zero k M] [ordered_smul k M]\n  {a b : M} {c : k}\n\nlemma smul_le_smul_iff_of_pos (hc : 0 < c) : c \u2022 a \u2264 c \u2022 b \u2194 a \u2264 b :=\n\u27e8\u03bb h, inv_smul_smul\u2080 hc.ne' a \u25b8 inv_smul_smul\u2080 hc.ne' b \u25b8\n  smul_le_smul_of_nonneg h (inv_nonneg.2 hc.le),\n  \u03bb h, smul_le_smul_of_nonneg h hc.le\u27e9\n\nlemma smul_lt_iff_of_pos (hc : 0 < c) : c \u2022 a < b \u2194 a < c\u207b\u00b9 \u2022 b :=\ncalc c \u2022 a < b \u2194 c \u2022 a < c \u2022 c\u207b\u00b9 \u2022 b : by rw [smul_inv_smul\u2080 hc.ne']\n... \u2194 a < c\u207b\u00b9 \u2022 b : smul_lt_smul_iff_of_pos hc\n\nlemma lt_smul_iff_of_pos (hc : 0 < c) : a < c \u2022 b \u2194 c\u207b\u00b9 \u2022 a < b :=\ncalc a < c \u2022 b \u2194 c \u2022 c\u207b\u00b9 \u2022 a < c \u2022 b : by rw [smul_inv_smul\u2080 hc.ne']\n... \u2194 c\u207b\u00b9 \u2022 a < b : smul_lt_smul_iff_of_pos hc\n\nlemma smul_le_iff_of_pos (hc : 0 < c) : c \u2022 a \u2264 b \u2194 a \u2264 c\u207b\u00b9 \u2022 b :=\ncalc c \u2022 a \u2264 b \u2194 c \u2022 a \u2264 c \u2022 c\u207b\u00b9 \u2022 b : by rw [smul_inv_smul\u2080 hc.ne']\n... \u2194 a \u2264 c\u207b\u00b9 \u2022 b : smul_le_smul_iff_of_pos hc\n\nlemma le_smul_iff_of_pos (hc : 0 < c) : a \u2264 c \u2022 b \u2194 c\u207b\u00b9 \u2022 a \u2264 b :=\ncalc a \u2264 c \u2022 b \u2194 c \u2022 c\u207b\u00b9 \u2022 a \u2264 c \u2022 b : by rw [smul_inv_smul\u2080 hc.ne']\n... \u2194 c\u207b\u00b9 \u2022 a \u2264 b : smul_le_smul_iff_of_pos hc\n\nvariables (M)\n\n/-- Left scalar multiplication as an order isomorphism. -/\n@[simps] def order_iso.smul_left {c : k} (hc : 0 < c) : M \u2243o M :=\n{ to_fun := \u03bb b, c \u2022 b,\n  inv_fun := \u03bb b, c\u207b\u00b9 \u2022 b,\n  left_inv := inv_smul_smul\u2080 hc.ne',\n  right_inv := smul_inv_smul\u2080 hc.ne',\n  map_rel_iff' := \u03bb b\u2081 b\u2082, smul_le_smul_iff_of_pos hc }\n\nend field\n", "meta": {"author": "Parinya-Siri", "repo": "lean-machine-learning", "sha": "ec610bac246ae7108fc6f0c140b3440f0fbacc52", "save_path": "github-repos/lean/Parinya-Siri-lean-machine-learning", "path": "github-repos/lean/Parinya-Siri-lean-machine-learning/lean-machine-learning-ec610bac246ae7108fc6f0c140b3440f0fbacc52/matlib/algebra/order/smul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.7030405999607923}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\n\nimport algebra.polynomial.big_operators\nimport field_theory.minpoly\nimport field_theory.splitting_field\nimport field_theory.tower\nimport algebra.squarefree\n\n/-!\n\n# Separable polynomials\n\nWe define a polynomial to be separable if it is coprime with its derivative. We prove basic\nproperties about separable polynomials here.\n\n## Main definitions\n\n* `polynomial.separable f`: a polynomial `f` is separable iff it is coprime with its derivative.\n* `polynomial.expand R p f`: expand the polynomial `f` with coefficients in a\n  commutative semiring `R` by a factor of p, so `expand R p (\u2211 a\u2099 x\u207f)` is `\u2211 a\u2099 x\u207f\u1d56`.\n* `polynomial.contract p f`: the opposite of `expand`, so it sends `\u2211 a\u2099 x\u207f\u1d56` to `\u2211 a\u2099 x\u207f`.\n\n-/\n\nuniverses u v w\nopen_locale classical big_operators\nopen finset\n\nnamespace polynomial\n\nsection comm_semiring\n\nvariables {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S]\n\n/-- A polynomial is separable iff it is coprime with its derivative. -/\ndef separable (f : polynomial R) : Prop :=\nis_coprime f f.derivative\n\nlemma separable_def (f : polynomial R) :\n  f.separable \u2194 is_coprime f f.derivative :=\niff.rfl\n\nlemma separable_def' (f : polynomial R) :\n  f.separable \u2194 \u2203 a b : polynomial R, a * f + b * f.derivative = 1 :=\niff.rfl\n\nlemma separable_one : (1 : polynomial R).separable :=\nis_coprime_one_left\n\nlemma separable_X_add_C (a : R) : (X + C a).separable :=\nby { rw [separable_def, derivative_add, derivative_X, derivative_C, add_zero],\n  exact is_coprime_one_right }\n\nlemma separable_X : (X : polynomial R).separable :=\nby { rw [separable_def, derivative_X], exact is_coprime_one_right }\n\nlemma separable_C (r : R) : (C r).separable \u2194 is_unit r :=\nby rw [separable_def, derivative_C, is_coprime_zero_right, is_unit_C]\n\nlemma separable.of_mul_left {f g : polynomial R} (h : (f * g).separable) : f.separable :=\nbegin\n  have := h.of_mul_left_left, rw derivative_mul at this,\n  exact is_coprime.of_mul_right_left (is_coprime.of_add_mul_left_right this)\nend\n\nlemma separable.of_mul_right {f g : polynomial R} (h : (f * g).separable) : g.separable :=\nby { rw mul_comm at h, exact h.of_mul_left }\n\nlemma separable.of_dvd {f g : polynomial R} (hf : f.separable) (hfg : g \u2223 f) : g.separable :=\nby { rcases hfg with \u27e8f', rfl\u27e9, exact separable.of_mul_left hf }\n\nlemma separable_gcd_left {F : Type*} [field F] {f : polynomial F}\n  (hf : f.separable) (g : polynomial F) : (euclidean_domain.gcd f g).separable :=\nseparable.of_dvd hf (euclidean_domain.gcd_dvd_left f g)\n\nlemma separable_gcd_right {F : Type*} [field F] {g : polynomial F}\n  (f : polynomial F) (hg : g.separable) : (euclidean_domain.gcd f g).separable :=\nseparable.of_dvd hg (euclidean_domain.gcd_dvd_right f g)\n\nlemma separable.is_coprime {f g : polynomial R} (h : (f * g).separable) : is_coprime f g :=\nbegin\n  have := h.of_mul_left_left, rw derivative_mul at this,\n  exact is_coprime.of_mul_right_right (is_coprime.of_add_mul_left_right this)\nend\n\ntheorem separable.of_pow' {f : polynomial R} :\n  \u2200 {n : \u2115} (h : (f ^ n).separable), is_unit f \u2228 (f.separable \u2227 n = 1) \u2228 n = 0\n| 0     := \u03bb h, or.inr $ or.inr rfl\n| 1     := \u03bb h, or.inr $ or.inl \u27e8pow_one f \u25b8 h, rfl\u27e9\n| (n+2) := \u03bb h, by { rw [pow_succ, pow_succ] at h,\n    exact or.inl (is_coprime_self.1 h.is_coprime.of_mul_right_left) }\n\ntheorem separable.of_pow {f : polynomial R} (hf : \u00acis_unit f) {n : \u2115} (hn : n \u2260 0)\n  (hfs : (f ^ n).separable) : f.separable \u2227 n = 1 :=\n(hfs.of_pow'.resolve_left hf).resolve_right hn\n\ntheorem separable.map {p : polynomial R} (h : p.separable) {f : R \u2192+* S} : (p.map f).separable :=\nlet \u27e8a, b, H\u27e9 := h in \u27e8a.map f, b.map f,\nby rw [derivative_map, \u2190 map_mul, \u2190 map_mul, \u2190 map_add, H, map_one]\u27e9\n\nvariables (R) (p q : \u2115)\n\n/-- Expand the polynomial by a factor of p, so `\u2211 a\u2099 x\u207f` becomes `\u2211 a\u2099 x\u207f\u1d56`. -/\nnoncomputable def expand : polynomial R \u2192\u2090[R] polynomial R :=\n{ commutes' := \u03bb r, eval\u2082_C _ _,\n  .. (eval\u2082_ring_hom C (X ^ p) : polynomial R \u2192+* polynomial R) }\n\nlemma coe_expand : (expand R p : polynomial R \u2192 polynomial R) = eval\u2082 C (X ^ p) := rfl\n\nvariables {R}\n\nlemma expand_eq_sum {f : polynomial R} :\n  expand R p f = f.sum (\u03bb e a, C a * (X ^ p) ^ e) :=\nby { dsimp [expand, eval\u2082], refl, }\n\n@[simp] lemma expand_C (r : R) : expand R p (C r) = C r := eval\u2082_C _ _\n@[simp] lemma expand_X : expand R p X = X ^ p := eval\u2082_X _ _\n@[simp] lemma expand_monomial (r : R) : expand R p (monomial q r) = monomial (q * p) r :=\nby simp_rw [monomial_eq_smul_X, alg_hom.map_smul, alg_hom.map_pow, expand_X, mul_comm, pow_mul]\n\ntheorem expand_expand (f : polynomial R) : expand R p (expand R q f) = expand R (p * q) f :=\npolynomial.induction_on f (\u03bb r, by simp_rw expand_C)\n  (\u03bb f g ihf ihg, by simp_rw [alg_hom.map_add, ihf, ihg])\n  (\u03bb n r ih, by simp_rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X,\n    alg_hom.map_pow, expand_X, pow_mul])\n\ntheorem expand_mul (f : polynomial R) : expand R (p * q) f = expand R p (expand R q f) :=\n(expand_expand p q f).symm\n\n@[simp] theorem expand_one (f : polynomial R) : expand R 1 f = f :=\npolynomial.induction_on f\n  (\u03bb r, by rw expand_C)\n  (\u03bb f g ihf ihg, by rw [alg_hom.map_add, ihf, ihg])\n  (\u03bb n r ih, by rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X, pow_one])\n\ntheorem expand_pow (f : polynomial R) : expand R (p ^ q) f = (expand R p ^[q] f) :=\nnat.rec_on q (by rw [pow_zero, expand_one, function.iterate_zero, id]) $ \u03bb n ih,\nby rw [function.iterate_succ_apply', pow_succ, expand_mul, ih]\n\ntheorem derivative_expand (f : polynomial R) :\n  (expand R p f).derivative = expand R p f.derivative * (p * X ^ (p - 1)) :=\nby rw [coe_expand, derivative_eval\u2082_C, derivative_pow, derivative_X, mul_one]\n\ntheorem coeff_expand {p : \u2115} (hp : 0 < p) (f : polynomial R) (n : \u2115) :\n  (expand R p f).coeff n = if p \u2223 n then f.coeff (n / p) else 0 :=\nbegin\n  simp only [expand_eq_sum],\n  simp_rw [coeff_sum, \u2190 pow_mul, C_mul_X_pow_eq_monomial, coeff_monomial, finsupp.sum],\n  split_ifs with h,\n  { rw [finset.sum_eq_single (n/p), nat.mul_div_cancel' h, if_pos rfl], refl,\n    { intros b hb1 hb2, rw if_neg, intro hb3, apply hb2, rw [\u2190 hb3, nat.mul_div_cancel_left b hp] },\n    { intro hn, rw finsupp.not_mem_support_iff.1 hn, split_ifs; refl } },\n  { rw finset.sum_eq_zero, intros k hk, rw if_neg, exact \u03bb hkn, h \u27e8k, hkn.symm\u27e9, },\nend\n\n@[simp] theorem coeff_expand_mul {p : \u2115} (hp : 0 < p) (f : polynomial R) (n : \u2115) :\n  (expand R p f).coeff (n * p) = f.coeff n :=\nby rw [coeff_expand hp, if_pos (dvd_mul_left _ _), nat.mul_div_cancel _ hp]\n\n@[simp] theorem coeff_expand_mul' {p : \u2115} (hp : 0 < p) (f : polynomial R) (n : \u2115) :\n  (expand R p f).coeff (p * n) = f.coeff n :=\nby rw [mul_comm, coeff_expand_mul hp]\n\ntheorem expand_eq_map_domain (p : \u2115) (f : polynomial R) :\n  expand R p f = f.map_domain (*p) :=\npolynomial.induction_on' f (\u03bb p q hp hq, by simp [*, finsupp.map_domain_add]) $\n  \u03bb n a, by simp_rw [expand_monomial, monomial_def, finsupp.map_domain_single]\n\ntheorem expand_inj {p : \u2115} (hp : 0 < p) {f g : polynomial R} :\n  expand R p f = expand R p g \u2194 f = g :=\n\u27e8\u03bb H, ext $ \u03bb n, by rw [\u2190 coeff_expand_mul hp, H, coeff_expand_mul hp], congr_arg _\u27e9\n\ntheorem expand_eq_zero {p : \u2115} (hp : 0 < p) {f : polynomial R} : expand R p f = 0 \u2194 f = 0 :=\nby rw [\u2190 (expand R p).map_zero, expand_inj hp, alg_hom.map_zero]\n\ntheorem expand_eq_C {p : \u2115} (hp : 0 < p) {f : polynomial R} {r : R} :\n  expand R p f = C r \u2194 f = C r :=\nby rw [\u2190 expand_C, expand_inj hp, expand_C]\n\ntheorem nat_degree_expand (p : \u2115) (f : polynomial R) :\n  (expand R p f).nat_degree = f.nat_degree * p :=\nbegin\n  cases p.eq_zero_or_pos with hp hp,\n  { rw [hp, coe_expand, pow_zero, mul_zero, \u2190 C_1, eval\u2082_hom, nat_degree_C] },\n  by_cases hf : f = 0,\n  { rw [hf, alg_hom.map_zero, nat_degree_zero, zero_mul] },\n  have hf1 : expand R p f \u2260 0 := mt (expand_eq_zero hp).1 hf,\n  rw [\u2190 with_bot.coe_eq_coe, \u2190 degree_eq_nat_degree hf1],\n  refine le_antisymm ((degree_le_iff_coeff_zero _ _).2 $ \u03bb n hn, _) _,\n  { rw coeff_expand hp, split_ifs with hpn,\n    { rw coeff_eq_zero_of_nat_degree_lt, contrapose! hn,\n      rw [with_bot.coe_le_coe, \u2190 nat.div_mul_cancel hpn], exact nat.mul_le_mul_right p hn },\n    { refl } },\n  { refine le_degree_of_ne_zero _,\n    rw [coeff_expand_mul hp, \u2190 leading_coeff], exact mt leading_coeff_eq_zero.1 hf }\nend\n\ntheorem map_expand {p : \u2115} (hp : 0 < p) {f : R \u2192+* S} {q : polynomial R} :\n  map f (expand R p q) = expand S p (map f q) :=\nby { ext, rw [coeff_map, coeff_expand hp, coeff_expand hp], split_ifs; simp, }\n\n/-- Expansion is injective. -/\nlemma expand_injective {n : \u2115} (hn : 0 < n) :\n  function.injective (expand R n) :=\n\u03bb g g' h, begin\n  ext,\n  have h' : (expand R n g).coeff (n * n_1) = (expand R n g').coeff (n * n_1) :=\n  begin\n    apply polynomial.ext_iff.1,\n    exact h,\n  end,\n\n  rw [polynomial.coeff_expand hn g (n * n_1), polynomial.coeff_expand hn g' (n * n_1)] at h',\n  simp only [if_true, dvd_mul_right] at h',\n  rw (nat.mul_div_right n_1 hn) at h',\n  exact h',\nend\n\nend comm_semiring\n\nsection comm_ring\n\nvariables {R : Type u} [comm_ring R]\n\nlemma separable_X_sub_C {x : R} : separable (X - C x) :=\nby simpa only [sub_eq_add_neg, C_neg] using separable_X_add_C (-x)\n\nlemma separable.mul {f g : polynomial R} (hf : f.separable) (hg : g.separable)\n  (h : is_coprime f g) : (f * g).separable :=\nby { rw [separable_def, derivative_mul], exact ((hf.mul_right h).add_mul_left_right _).mul_left\n  ((h.symm.mul_right hg).mul_add_right_right _) }\n\nlemma separable_prod' {\u03b9 : Sort*} {f : \u03b9 \u2192 polynomial R} {s : finset \u03b9} :\n  (\u2200x\u2208s, \u2200y\u2208s, x \u2260 y \u2192 is_coprime (f x) (f y)) \u2192 (\u2200x\u2208s, (f x).separable) \u2192\n  (\u220f x in s, f x).separable :=\nfinset.induction_on s (\u03bb _ _, separable_one) $ \u03bb a s has ih h1 h2, begin\n  simp_rw [finset.forall_mem_insert, forall_and_distrib] at h1 h2, rw prod_insert has,\n  exact h2.1.mul (ih h1.2.2 h2.2) (is_coprime.prod_right $ \u03bb i his, h1.1.2 i his $\n    ne.symm $ ne_of_mem_of_not_mem his has)\nend\n\nlemma separable_prod {\u03b9 : Sort*} [fintype \u03b9] {f : \u03b9 \u2192 polynomial R}\n  (h1 : pairwise (is_coprime on f)) (h2 : \u2200 x, (f x).separable) : (\u220f x, f x).separable :=\nseparable_prod' (\u03bb x hx y hy hxy, h1 x y hxy) (\u03bb x hx, h2 x)\n\nlemma separable.inj_of_prod_X_sub_C [nontrivial R] {\u03b9 : Sort*} {f : \u03b9 \u2192 R} {s : finset \u03b9}\n  (hfs : (\u220f i in s, (X - C (f i))).separable)\n  {x y : \u03b9} (hx : x \u2208 s) (hy : y \u2208 s) (hfxy : f x = f y) : x = y :=\nbegin\n  by_contra hxy,\n  rw [\u2190 insert_erase hx, prod_insert (not_mem_erase _ _),\n      \u2190 insert_erase (mem_erase_of_ne_of_mem (ne.symm hxy) hy),\n      prod_insert (not_mem_erase _ _), \u2190 mul_assoc, hfxy, \u2190 sq] at hfs,\n  cases (hfs.of_mul_left.of_pow (by exact not_is_unit_X_sub_C) two_ne_zero).2\nend\n\nlemma separable.injective_of_prod_X_sub_C [nontrivial R] {\u03b9 : Sort*} [fintype \u03b9] {f : \u03b9 \u2192 R}\n  (hfs : (\u220f i, (X - C (f i))).separable) : function.injective f :=\n\u03bb x y hfxy, hfs.inj_of_prod_X_sub_C (mem_univ _) (mem_univ _) hfxy\n\nlemma is_unit_of_self_mul_dvd_separable {p q : polynomial R}\n  (hp : p.separable) (hq : q * q \u2223 p) : is_unit q :=\nbegin\n  obtain \u27e8p, rfl\u27e9 := hq,\n  apply is_coprime_self.mp,\n  have : is_coprime (q * (q * p)) (q * (q.derivative * p + q.derivative * p + q * p.derivative)),\n  { simp only [\u2190 mul_assoc, mul_add],\n    convert hp,\n    rw [derivative_mul, derivative_mul],\n    ring },\n  exact is_coprime.of_mul_right_left (is_coprime.of_mul_left_left this)\nend\n\nend comm_ring\n\nsection integral_domain\n\nvariables (R : Type u) [integral_domain R]\n\ntheorem is_local_ring_hom_expand {p : \u2115} (hp : 0 < p) :\n  is_local_ring_hom (\u2191(expand R p) : polynomial R \u2192+* polynomial R) :=\nbegin\n  refine \u27e8\u03bb f hf1, _\u27e9, rw \u2190 coe_fn_coe_base at hf1,\n  have hf2 := eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit hf1),\n  rw [coeff_expand hp, if_pos (dvd_zero _), p.zero_div] at hf2,\n  rw [hf2, is_unit_C] at hf1, rw expand_eq_C hp at hf2, rwa [hf2, is_unit_C]\nend\n\nend integral_domain\n\nsection field\n\nvariables {F : Type u} [field F] {K : Type v} [field K]\n\ntheorem separable_iff_derivative_ne_zero {f : polynomial F} (hf : irreducible f) :\n  f.separable \u2194 f.derivative \u2260 0 :=\n\u27e8\u03bb h1 h2, hf.not_unit $ is_coprime_zero_right.1 $ h2 \u25b8 h1,\n\u03bb h, is_coprime_of_dvd (mt and.right h) $ \u03bb g hg1 hg2 \u27e8p, hg3\u27e9 hg4,\nlet \u27e8u, hu\u27e9 := (hf.is_unit_or_is_unit hg3).resolve_left hg1 in\nhave f \u2223 f.derivative, by { conv_lhs { rw [hg3, \u2190 hu] }, rwa units.mul_right_dvd },\nnot_lt_of_le (nat_degree_le_of_dvd this h) $ nat_degree_derivative_lt h\u27e9\n\ntheorem separable_map (f : F \u2192+* K) {p : polynomial F} : (p.map f).separable \u2194 p.separable :=\nby simp_rw [separable_def, derivative_map, is_coprime_map]\n\nsection char_p\n\nvariables (p : \u2115) [hp : fact p.prime]\ninclude hp\n\n/-- The opposite of `expand`: sends `\u2211 a\u2099 x\u207f\u1d56` to `\u2211 a\u2099 x\u207f`. -/\nnoncomputable def contract (f : polynomial F) : polynomial F :=\n\u27e8f.support.preimage (*p) $ \u03bb _ _ _ _, (nat.mul_left_inj hp.1.pos).1,\n\u03bb n, f.coeff (n * p),\n\u03bb n, by rw [finset.mem_preimage, mem_support_iff]\u27e9\n\ntheorem coeff_contract (f : polynomial F) (n : \u2115) : (contract p f).coeff n = f.coeff (n * p) := rfl\n\ntheorem of_irreducible_expand {f : polynomial F} (hf : irreducible (expand F p f)) :\n  irreducible f :=\n@@of_irreducible_map _ _ _ (is_local_ring_hom_expand F hp.1.pos) hf\n\ntheorem of_irreducible_expand_pow {f : polynomial F} {n : \u2115} :\n  irreducible (expand F (p ^ n) f) \u2192 irreducible f :=\nnat.rec_on n (\u03bb hf, by rwa [pow_zero, expand_one] at hf) $ \u03bb n ih hf,\nih $ of_irreducible_expand p $ by { rw pow_succ at hf, rwa [expand_expand] }\n\nvariables [HF : char_p F p]\ninclude HF\n\ntheorem expand_char (f : polynomial F) :\n  map (frobenius F p) (expand F p f) = f ^ p :=\nbegin\n  refine f.induction_on' (\u03bb a b ha hb, _) (\u03bb n a, _),\n  { rw [alg_hom.map_add, map_add, ha, hb, add_pow_char], },\n  { rw [expand_monomial, map_monomial, single_eq_C_mul_X, single_eq_C_mul_X,\n        mul_pow, \u2190 C.map_pow, frobenius_def],\n    ring_exp }\nend\n\ntheorem map_expand_pow_char (f : polynomial F) (n : \u2115) :\n   map ((frobenius F p) ^ n) (expand F (p ^ n) f) = f ^ (p ^ n) :=\nbegin\n  induction n, {simp [ring_hom.one_def]},\n  symmetry,\n  rw [pow_succ', pow_mul, \u2190 n_ih, \u2190 expand_char, pow_succ, ring_hom.mul_def, \u2190 map_map, mul_comm,\n      expand_mul, \u2190 map_expand (nat.prime.pos hp.1)],\nend\n\ntheorem expand_contract {f : polynomial F} (hf : f.derivative = 0) :\n  expand F p (contract p f) = f :=\nbegin\n  ext n, rw [coeff_expand hp.1.pos, coeff_contract], split_ifs with h,\n  { rw nat.div_mul_cancel h },\n  { cases n, { exact absurd (dvd_zero p) h },\n    have := coeff_derivative f n, rw [hf, coeff_zero, zero_eq_mul] at this, cases this, { rw this },\n    rw [\u2190 nat.cast_succ, char_p.cast_eq_zero_iff F p] at this,\n    exact absurd this h }\nend\n\ntheorem separable_or {f : polynomial F} (hf : irreducible f) : f.separable \u2228\n  \u00acf.separable \u2227 \u2203 g : polynomial F, irreducible g \u2227 expand F p g = f :=\nif H : f.derivative = 0 then or.inr\n  \u27e8by rw [separable_iff_derivative_ne_zero hf, not_not, H],\n  contract p f,\n  by haveI := is_local_ring_hom_expand F hp.1.pos; exact\n    of_irreducible_map \u2191(expand F p) (by rwa \u2190 expand_contract p H at hf),\n  expand_contract p H\u27e9\nelse or.inl $ (separable_iff_derivative_ne_zero hf).2 H\n\ntheorem exists_separable_of_irreducible {f : polynomial F} (hf : irreducible f) (hf0 : f \u2260 0) :\n  \u2203 (n : \u2115) (g : polynomial F), g.separable \u2227 expand F (p ^ n) g = f :=\nbegin\n  generalize hn : f.nat_degree = N, unfreezingI { revert f },\n  apply nat.strong_induction_on N, intros N ih f hf hf0 hn,\n  rcases separable_or p hf with h | \u27e8h1, g, hg, hgf\u27e9,\n  { refine \u27e80, f, h, _\u27e9, rw [pow_zero, expand_one] },\n  { cases N with N,\n    { rw [nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff] at hn,\n      rw [hn, separable_C, is_unit_iff_ne_zero, not_not] at h1,\n      rw [h1, C_0] at hn, exact absurd hn hf0 },\n    have hg1 : g.nat_degree * p = N.succ,\n    { rwa [\u2190 nat_degree_expand, hgf] },\n    have hg2 : g.nat_degree \u2260 0,\n    { intro this, rw [this, zero_mul] at hg1, cases hg1 },\n    have hg3 : g.nat_degree < N.succ,\n    { rw [\u2190 mul_one g.nat_degree, \u2190 hg1],\n      exact nat.mul_lt_mul_of_pos_left hp.1.one_lt (nat.pos_of_ne_zero hg2) },\n    have hg4 : g \u2260 0,\n    { rintro rfl, exact hg2 nat_degree_zero },\n    rcases ih _ hg3 hg hg4 rfl with \u27e8n, g, hg5, rfl\u27e9, refine \u27e8n+1, g, hg5, _\u27e9,\n    rw [\u2190 hgf, expand_expand, pow_succ] }\nend\n\ntheorem is_unit_or_eq_zero_of_separable_expand {f : polynomial F} (n : \u2115)\n  (hf : (expand F (p ^ n) f).separable) : is_unit f \u2228 n = 0 :=\nbegin\n  rw or_iff_not_imp_right, intro hn,\n  have hf2 : (expand F (p ^ n) f).derivative = 0,\n  { by rw [derivative_expand, nat.cast_pow, char_p.cast_eq_zero,\n      zero_pow (nat.pos_of_ne_zero hn), zero_mul, mul_zero] },\n  rw [separable_def, hf2, is_coprime_zero_right, is_unit_iff] at hf, rcases hf with \u27e8r, hr, hrf\u27e9,\n  rw [eq_comm, expand_eq_C (pow_pos hp.1.pos _)] at hrf,\n  rwa [hrf, is_unit_C]\nend\n\ntheorem unique_separable_of_irreducible {f : polynomial F} (hf : irreducible f) (hf0 : f \u2260 0)\n  (n\u2081 : \u2115) (g\u2081 : polynomial F) (hg\u2081 : g\u2081.separable) (hgf\u2081 : expand F (p ^ n\u2081) g\u2081 = f)\n  (n\u2082 : \u2115) (g\u2082 : polynomial F) (hg\u2082 : g\u2082.separable) (hgf\u2082 : expand F (p ^ n\u2082) g\u2082 = f) :\n  n\u2081 = n\u2082 \u2227 g\u2081 = g\u2082 :=\nbegin\n  revert g\u2081 g\u2082, wlog hn : n\u2081 \u2264 n\u2082 := le_total n\u2081 n\u2082 using [n\u2081 n\u2082, n\u2082 n\u2081] tactic.skip,\n  unfreezingI { intros, rw le_iff_exists_add at hn, rcases hn with \u27e8k, rfl\u27e9,\n    rw [\u2190 hgf\u2081, pow_add, expand_mul, expand_inj (pow_pos hp.1.pos n\u2081)] at hgf\u2082, subst hgf\u2082,\n    subst hgf\u2081,\n    rcases is_unit_or_eq_zero_of_separable_expand p k hg\u2081 with h | rfl,\n    { rw is_unit_iff at h, rcases h with \u27e8r, hr, rfl\u27e9,\n      simp_rw expand_C at hf, exact absurd (is_unit_C.2 hr) hf.1 },\n    { rw [add_zero, pow_zero, expand_one], split; refl } },\n  exact \u03bb g\u2081 g\u2082 hg\u2081 hgf\u2081 hg\u2082 hgf\u2082, let \u27e8hn, hg\u27e9 :=\n    this g\u2082 g\u2081 hg\u2082 hgf\u2082 hg\u2081 hgf\u2081 in \u27e8hn.symm, hg.symm\u27e9\nend\n\nend char_p\n\nlemma separable_prod_X_sub_C_iff' {\u03b9 : Sort*} {f : \u03b9 \u2192 F} {s : finset \u03b9} :\n  (\u220f i in s, (X - C (f i))).separable \u2194 (\u2200 (x \u2208 s) (y \u2208 s), f x = f y \u2192 x = y) :=\n\u27e8\u03bb hfs x hx y hy hfxy, hfs.inj_of_prod_X_sub_C hx hy hfxy,\n\u03bb H, by { rw \u2190 prod_attach, exact separable_prod' (\u03bb x hx y hy hxy,\n    @pairwise_coprime_X_sub _ _ { x // x \u2208 s } (\u03bb x, f x)\n      (\u03bb x y hxy, subtype.eq $ H x.1 x.2 y.1 y.2 hxy) _ _ hxy)\n  (\u03bb _ _, separable_X_sub_C) }\u27e9\n\nlemma separable_prod_X_sub_C_iff {\u03b9 : Sort*} [fintype \u03b9] {f : \u03b9 \u2192 F} :\n  (\u220f i, (X - C (f i))).separable \u2194 function.injective f :=\nseparable_prod_X_sub_C_iff'.trans $ by simp_rw [mem_univ, true_implies_iff]\n\nsection splits\n\nopen_locale big_operators\n\nvariables {i : F \u2192+* K}\n\nlemma not_unit_X_sub_C (a : F) : \u00ac is_unit (X - C a) :=\n\u03bb h, have one_eq_zero : (1 : with_bot \u2115) = 0, by simpa using degree_eq_zero_of_is_unit h,\none_ne_zero (option.some_injective _ one_eq_zero)\n\nlemma nodup_of_separable_prod {s : multiset F}\n  (hs : separable (multiset.map (\u03bb a, X - C a) s).prod) : s.nodup :=\nbegin\n  rw multiset.nodup_iff_ne_cons_cons,\n  rintros a t rfl,\n  refine not_unit_X_sub_C a (is_unit_of_self_mul_dvd_separable hs _),\n  simpa only [multiset.map_cons, multiset.prod_cons] using mul_dvd_mul_left _ (dvd_mul_right _ _)\nend\n\nlemma multiplicity_le_one_of_separable {p q : polynomial F} (hq : \u00ac is_unit q)\n  (hsep : separable p) : multiplicity q p \u2264 1 :=\nbegin\n  contrapose! hq,\n  apply is_unit_of_self_mul_dvd_separable hsep,\n  rw \u2190 sq,\n  apply multiplicity.pow_dvd_of_le_multiplicity,\n  exact_mod_cast (enat.add_one_le_of_lt hq)\nend\n\nlemma separable.squarefree {p : polynomial F}  (hsep : separable p) : squarefree p :=\nbegin\n  rw multiplicity.squarefree_iff_multiplicity_le_one p,\n  intro f,\n  by_cases hunit : is_unit f,\n  { exact or.inr hunit },\n  exact or.inl (multiplicity_le_one_of_separable hunit hsep)\nend\n\n/--If `n \u2260 0` in `F`, then ` X ^ n - a` is separable for any `a \u2260 0`. -/\nlemma separable_X_pow_sub_C {n : \u2115} (a : F) (hn : (n : F) \u2260 0) (ha : a \u2260 0) :\n  separable (X ^ n - C a) :=\nbegin\n  cases nat.eq_zero_or_pos n with hzero hpos,\n  { exfalso,\n    rw hzero at hn,\n    exact hn (refl 0) },\n  apply (separable_def' (X ^ n - C a)).2,\n  use [-C (a\u207b\u00b9), (C ((a\u207b\u00b9) * (\u2191n)\u207b\u00b9) *  X)],\n  have mul_pow_sub : X * X ^ (n - 1) = X ^ n,\n  { nth_rewrite 0 [\u2190pow_one X],\n    rw pow_mul_pow_sub X (nat.succ_le_iff.mpr hpos) },\n  rw [derivative_sub, derivative_C, sub_zero, derivative_pow X n, derivative_X, mul_one],\n  have hcalc : C (a\u207b\u00b9 * (\u2191n)\u207b\u00b9) * (\u2191n * (X ^ n)) = C a\u207b\u00b9 * (X ^ n),\n  { calc C (a\u207b\u00b9 * (\u2191n)\u207b\u00b9) * (\u2191n * (X ^ n))\n       = C a\u207b\u00b9 * C ((\u2191n)\u207b\u00b9) * (C \u2191n * (X ^ n)) : by rw [C_mul, C_eq_nat_cast]\n   ... = C a\u207b\u00b9 * (C ((\u2191n)\u207b\u00b9) * C \u2191n) * (X ^ n) : by ring\n   ... = C a\u207b\u00b9 * C ((\u2191n)\u207b\u00b9 * \u2191n) * (X ^ n) : by rw [\u2190 C_mul]\n   ... = C a\u207b\u00b9 * C 1 * (X ^ n) : by field_simp [hn]\n   ... = C a\u207b\u00b9 * (X ^ n) : by rw [C_1, mul_one] },\n  calc -C a\u207b\u00b9 * (X ^ n - C a) + C (a\u207b\u00b9 * (\u2191n)\u207b\u00b9) * X * (\u2191n * X ^ (n - 1))\n      = -C a\u207b\u00b9 * (X ^ n - C a) + C (a\u207b\u00b9 * (\u2191n)\u207b\u00b9) * (\u2191n * (X * X ^ (n - 1))) : by ring\n  ... = -C a\u207b\u00b9 * (X ^ n - C a) + C a\u207b\u00b9 * (X ^ n) : by rw [mul_pow_sub, hcalc]\n  ... = C a\u207b\u00b9 * C a : by ring\n  ... = (1 : polynomial F) : by rw [\u2190 C_mul, inv_mul_cancel ha, C_1]\nend\n\n/--If `n \u2260 0` in `F`, then ` X ^ n - a` is squarefree for any `a \u2260 0`. -/\nlemma squarefree_X_pow_sub_C {n : \u2115} (a : F) (hn : (n : F) \u2260 0) (ha : a \u2260 0) :\n  squarefree (X ^ n - C a) :=\n(separable_X_pow_sub_C a hn ha).squarefree\n\nlemma root_multiplicity_le_one_of_separable {p : polynomial F} (hp : p \u2260 0)\n  (hsep : separable p) (x : F) : root_multiplicity x p \u2264 1 :=\nbegin\n  rw [root_multiplicity_eq_multiplicity, dif_neg hp, \u2190 enat.coe_le_coe, enat.coe_get],\n  exact multiplicity_le_one_of_separable (not_unit_X_sub_C _) hsep\nend\n\nlemma count_roots_le_one {p : polynomial F} (hsep : separable p) (x : F) :\n  p.roots.count x \u2264 1 :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp] },\n  rw count_roots hp,\n  exact root_multiplicity_le_one_of_separable hp hsep x\nend\n\nlemma nodup_roots {p : polynomial F} (hsep : separable p) :\n  p.roots.nodup :=\nmultiset.nodup_iff_count_le_one.mpr (count_roots_le_one hsep)\n\nlemma eq_X_sub_C_of_separable_of_root_eq {x : F} {h : polynomial F} (h_ne_zero : h \u2260 0)\n  (h_sep : h.separable) (h_root : h.eval x = 0) (h_splits : splits i h)\n  (h_roots : \u2200 y \u2208 (h.map i).roots, y = i x) : h = (C (leading_coeff h)) * (X - C x) :=\nbegin\n  apply polynomial.eq_X_sub_C_of_splits_of_single_root i h_splits,\n  apply finset.mk.inj,\n  { change _ = {i x},\n    rw finset.eq_singleton_iff_unique_mem,\n    split,\n    { apply finset.mem_mk.mpr,\n      rw mem_roots (show h.map i \u2260 0, by exact map_ne_zero h_ne_zero),\n      rw [is_root.def,\u2190eval\u2082_eq_eval_map,eval\u2082_hom,h_root],\n      exact ring_hom.map_zero i },\n    { exact h_roots } },\n  { exact nodup_roots (separable.map h_sep) },\nend\n\nend splits\n\nend field\n\nend polynomial\n\nopen polynomial\n\ntheorem irreducible.separable {F : Type u} [field F] [char_zero F] {f : polynomial F}\n  (hf : irreducible f) : f.separable :=\nbegin\n  rw [separable_iff_derivative_ne_zero hf, ne, \u2190 degree_eq_bot, degree_derivative_eq], rintro \u27e8\u27e9,\n  rw [pos_iff_ne_zero, ne, nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff],\n  refine \u03bb hf1, hf.not_unit _, rw [hf1, is_unit_C, is_unit_iff_ne_zero],\n  intro hf2, rw [hf2, C_0] at hf1, exact absurd hf1 hf.ne_zero\nend\n\n-- TODO: refactor to allow transcendental extensions?\n-- See: https://en.wikipedia.org/wiki/Separable_extension#Separability_of_transcendental_extensions\n\n/-- Typeclass for separable field extension: `K` is a separable field extension of `F` iff\nthe minimal polynomial of every `x : K` is separable. -/\nclass is_separable (F K : Sort*) [field F] [field K] [algebra F K] : Prop :=\n(is_integral' (x : K) : is_integral F x)\n(separable' (x : K) : (minpoly F x).separable)\n\ntheorem is_separable.is_integral {F K} [field F] [field K] [algebra F K] (h : is_separable F K) :\n  \u2200 x : K, is_integral F x := is_separable.is_integral'\n\ntheorem is_separable.separable {F K} [field F] [field K] [algebra F K] (h : is_separable F K) :\n  \u2200 x : K, (minpoly F x).separable := is_separable.separable'\n\ntheorem is_separable_iff {F K} [field F] [field K] [algebra F K] : is_separable F K \u2194\n  \u2200 x : K, is_integral F x \u2227 (minpoly F x).separable :=\n\u27e8\u03bb h x, \u27e8h.is_integral x, h.separable x\u27e9, \u03bb h, \u27e8\u03bb x, (h x).1, \u03bb x, (h x).2\u27e9\u27e9\n\ninstance is_separable_self (F : Type*) [field F] : is_separable F F :=\n\u27e8\u03bb x, is_integral_algebra_map, \u03bb x, by { rw minpoly.eq_X_sub_C', exact separable_X_sub_C }\u27e9\n\nsection is_separable_tower\nvariables (F K E : Type*) [field F] [field K] [field E] [algebra F K] [algebra F E]\n  [algebra K E] [is_scalar_tower F K E]\n\nlemma is_separable_tower_top_of_is_separable [h : is_separable F E] : is_separable K E :=\n\u27e8\u03bb x, is_integral_of_is_scalar_tower x (h.is_integral x),\n \u03bb x, (h.separable x).map.of_dvd (minpoly.dvd_map_of_is_scalar_tower _ _ _)\u27e9\n\nlemma is_separable_tower_bot_of_is_separable [h : is_separable F E] : is_separable F K :=\nis_separable_iff.2 $ \u03bb x, begin\n  refine (is_separable_iff.1 h (algebra_map K E x)).imp\n    is_integral_tower_bot_of_is_integral_field (\u03bb hs, _),\n  obtain \u27e8q, hq\u27e9 := minpoly.dvd F x\n    (is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero_field\n      (minpoly.aeval F ((algebra_map K E) x))),\n  rw hq at hs,\n  exact hs.of_mul_left\nend\n\nvariables {E}\n\nlemma is_separable.of_alg_hom (E' : Type*) [field E'] [algebra F E']\n  (f : E \u2192\u2090[F] E') [is_separable F E'] : is_separable F E :=\nbegin\n  letI : algebra E E' := ring_hom.to_algebra f.to_ring_hom,\n  haveI : is_scalar_tower F E E' := is_scalar_tower.of_algebra_map_eq (\u03bb x, (f.commutes x).symm),\n  exact is_separable_tower_bot_of_is_separable F E E',\nend\n\nend is_separable_tower\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/field_theory/separable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797081106935, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.7030405840112082}}
{"text": "/-\nCopyright stuff\n-/\nimport .base_family \nimport data.list.sort \n\n/-! \nThis file defines `supermatroids`; these are nonempty antichains of `bases` in a modular lattice \nthat satisfy two axioms asserting the existence of bases under various conditions.\n-/\n\nuniverses u v \n\nvariables {\u03b1 : Type u} {\u03ba : Type v}\n\nopen set order_dual \n\n/-- In a matroid on a finite lattice, bases for sets exist -/\nlemma indep.le_basis_of_le_of_finite [base_family \u03b1] [finite \u03b1] {i x : \u03b1} (hi : indep i) \n(hix : i \u2264 x) : \n  \u2203 j, j basis_for x \u2227 i \u2264 j := \n(set.finite.exists_maximal_mem \n  (\u27e8i, \u27e8hi,rfl.le,hix\u27e9\u27e9 : {i' | indep i' \u2227 i \u2264 i' \u2227 i' \u2264 x}.nonempty)).imp \n    (\u03bb j \u27e8\u27e8hj, hij,hjx\u27e9,hj_max\u27e9, \n     \u27e8\u27e8hj,hjx, \u03bb j' hj' hj'x hjj', hj_max j' \u27e8hj',hij.trans hjj',hj'x\u27e9 hjj'\u27e9, hij\u27e9)\n\n/-- In a matroid on a finite lattice, canopies for sets exist -/\nlemma spanning.super_of_le_of_le_of_finite [base_family \u03b1] [finite \u03b1] {s x : \u03b1} (hs : spanning s)\n(hxs : x \u2264 s) :\n  \u2203 t, t canopy_for x \u2227 t \u2264 s := \n@indep.le_basis_of_le_of_finite \u03b1\u1d52\u1d48 _ _ _ _ hs hxs\n\nsection supermatroid \n\n/-- Class for base families that satisfy an augmentation axiom and in which the base lattice\nis modular. Equivalent to independence augmentation in the case of finite set lattices. -/\nclass supermatroid (\u03b1 : Type u) extends base_family \u03b1, is_modular_lattice \u03b1 :=\n(exists_base_mid_of_indep_le_spanning : \n  \u2200 (x y : \u03b1), indep x \u2192 spanning y \u2192 x \u2264 y \u2192 \u2203 b, base b \u2227 x \u2264 b \u2227 b \u2264 y) \n(le_basis_of_indep_le : \u2200 (i x : \u03b1), indep i \u2192 i \u2264 x \u2192 \u2203 j, j basis_for x \u2227 i \u2264 j)\n  \nvariables [supermatroid \u03b1] {a i j b b' s t x y z x' y' z' : \u03b1}\n\n/-- A base_family on a finite lattice that satisfies the middle axiom is a supermatroid. -/\nnoncomputable lemma supermatroid_of_finite {\u03b1 : Type u} [base_family \u03b1] [finite \u03b1] \n[is_modular_lattice \u03b1] \n(h : \u2200 (x y : \u03b1), indep x \u2192 spanning y \u2192 x \u2264 y \u2192 \u2203 b, base b \u2227 x \u2264 b \u2227 b \u2264 y) : \n  supermatroid \u03b1 :=\n\u27e8h, @indep.le_basis_of_le_of_finite _ _ _\u27e9 \n\n/-- #### Extensions to bases -/\n\nlemma indep.exists_base_mid_of_le_spanning (hi : indep i) (hs : spanning s) (his : i \u2264 s) : \n  \u2203 b, base b \u2227 i \u2264 b \u2227 b \u2264 s := \nsupermatroid.exists_base_mid_of_indep_le_spanning _ _ hi hs his  \n\nlemma indep.exists_base_mid_of_le_sup_base (hi : indep i) (hb : base b) : \n   \u2203 b', base b' \u2227 i \u2264 b' \u2227 b' \u2264 i \u2294 b :=\nhi.exists_base_mid_of_le_spanning (hb.sup_left_spanning _) le_sup_left\n\nlemma base.exists_base_of_subset_le_supset_base (hb : base b) (hb' : base b') (hxy : x \u2264 y) \n  (hxb : x \u2264 b) (hb'y : b' \u2264 y): \n   \u2203 b\u2080, base b\u2080 \u2227 x \u2264 b\u2080 \u2227 b\u2080 \u2264 y :=\nsupermatroid.exists_base_mid_of_indep_le_spanning _ _ \u27e8b,hb,hxb\u27e9 \u27e8b',hb',hb'y\u27e9 hxy \n\nlemma indep.lt_base_le_spanning_of_not_base (hi : indep i) (hi_b : \u00acbase i) (hs : spanning s)\n(his : i \u2264 s) :\n  \u2203 b, base b \u2227 i < b \u2227 b \u2264 s  := \n(hi.exists_base_mid_of_le_spanning hs his).imp \n  (\u03bb j, \u03bb \u27e8hj,hij,hjs\u27e9, \u27e8hj, hij.lt_of_ne (\u03bb h, hi_b (h.substr hj)), hjs\u27e9)\n\nlemma indep.lt_base_sup_le_sup_base_of_not_base (hi : indep i) (hi_nb : \u00ac base i) \n(hb : base b) :\n  \u2203 b', base b' \u2227 i < b' \u2227 b' \u2264 i \u2294 b :=\n(hi.lt_base_le_spanning_of_not_base hi_nb (hb.sup_left_spanning _) le_sup_left)\n\nlemma indep.lt_base_le_spanning_of_lt (hj : indep j) (hs : spanning s) (hi : i < j) (his : i \u2264 s) :\n  \u2203 b, base b \u2227 i < b \u2227 b \u2264 s :=\n(hj.indep_of_le hi.le).lt_base_le_spanning_of_not_base (hj.not_base_of_lt hi) hs his\n\nlemma indep.lt_base_le_sup_base_of_lt (hj : indep j) (hi : i < j) (hb : base b) :\n  \u2203 b', base b' \u2227 i < b' \u2227 b' \u2264 i \u2294 b :=\nhj.lt_base_le_spanning_of_lt (hb.sup_left_spanning _) hi le_sup_left\n\nlemma indep.base_of_spanning (hi : indep i) (hs : spanning i) : base i := \nexists.elim (hi.exists_base_mid_of_le_spanning hs rfl.le) \n  (\u03bb a \u27e8ha,hia,hai\u27e9, (hai.antisymm hia).subst ha)\n\nlemma indep.le_basis_of_le (hi : indep i) (hix : i \u2264 x) : \u2203 j, j basis_for x \u2227 i \u2264 j := \nsupermatroid.le_basis_of_indep_le _ _ hi hix  \n\nlemma indep.le_basis_sup_right (hi : indep i) (x : \u03b1) : \u2203 j, j basis_for (i \u2294 x) \u2227 i \u2264 j := \nhi.le_basis_of_le le_sup_left \n\nlemma indep.le_basis_sup_left (hi : indep i) (x : \u03b1) : \u2203 j, j basis_for (x \u2294 i) \u2227 i \u2264 j := \nhi.le_basis_of_le le_sup_right \n\nlemma indep.lt_basis_of_not_basis_of_le (hi : indep i) (hi_n : \u00ac i basis_for x) \n(hix : i \u2264 x) : \n  \u2203 j, j basis_for x \u2227 i < j := \n(hi.le_basis_of_le hix).imp (\u03bb j hj, \u27e8hj.1, hj.2.lt_of_ne (\u03bb h, hi_n (h.substr hj.1))\u27e9) \n\nlemma indep.exists_lt_inf_base_of_not_basis (hi : indep i) (hnb : \u00ac i basis_for x) \n(hix : i \u2264 x) : \n  \u2203 b, base b \u2227 (x \u2293 b) basis_for x \u2227 i < x \u2293 b := \nbegin\n  obtain \u27e8j,hj,hjx\u27e9 := hi.lt_basis_of_not_basis_of_le hnb hix, \n  obtain \u27e8b,hb,hjb\u27e9 := hj.indep, \n  refine \u27e8b, hb, (hb.inf_left_indep _).basis_for inf_le_left _, hjx.trans_le (le_inf hj.le hjb)\u27e9, \n  refine \u03bb j' hj' hj'x hbxj, hbxj.antisymm _, \n  rw \u2190hj.eq_of_le_indep hj' ((le_inf hj.le hjb).trans hbxj) hj'x, \n  exact le_inf hj.le hjb, \nend \n\nlemma basis_for.base (hb : b basis_for s) (hs : spanning s) : base b := \nexists.elim (hb.indep.exists_base_mid_of_le_spanning hs hb.le) \n  (\u03bb b' \u27e8hb',hbb',hb's\u27e9, (hb.eq_of_le_indep hb'.indep hbb' hb's).substr hb') \n\nlemma exists_basis (x : \u03b1) : \u2203 i, i basis_for x := \nexists.elim (exists_base \u03b1) \n  (\u03bb b hb, ((hb.inf_right_indep x).le_basis_of_le inf_le_right).imp (\u03bb _ h, h.1)) \n\nlemma base.inf_basis (hb : base b) (x : \u03b1) : \n  \u2203 b', base b' \u2227 ((b' \u2293 x) basis_for x) \u2227 b' \u2264 x \u2294 b  :=\nbegin\n  obtain \u27e8i,hi\u27e9 := exists_basis x, \n  obtain \u27e8b',\u27e8hb',bib',hb'i\u27e9\u27e9 := hi.indep.exists_base_mid_of_le_sup_base hb,\n  refine \u27e8b',hb', \n    (hb'.inf_right_indep _).basis_for inf_le_right (\u03bb j hj hjx hb'j, hb'j.antisymm (le_inf _ hjx)), \n    hb'i.trans (sup_le_sup_right hi.le _)\u27e9,\n  rwa \u2190hi.eq_of_le_indep hj (le_trans (le_inf bib' hi.le) hb'j) hjx,  \nend \n\nlemma base.lt_base_le_spanning_of_lt (hb : base b) (hs : spanning s) (hib : i < b) \n(his : i \u2264 s) :\n  \u2203 b\u2080, base b\u2080 \u2227 i < b\u2080 \u2227 b\u2080 \u2264 s := \n(hb.indep_of_le hib.le).lt_base_le_spanning_of_not_base (hb.not_base_of_lt hib) hs his \n\nlemma base.lt_base_le_sup_base_of_lt (hb : base b) (hb' : base b') (hib : i < b) :\n  \u2203 b\u2080, base b\u2080 \u2227 i < b\u2080 \u2227 b\u2080 \u2264 i \u2294 b' :=\n(hb.indep_of_le hib.le).lt_base_sup_le_sup_base_of_not_base (hb.not_base_of_lt hib) hb' \n \n/-- #### Duality -/\n\nprivate lemma spanning.canopy_le_of_le' (hs : spanning s) (hxs : x \u2264 s) : \n  \u2203 t, t canopy_for x \u2227 t \u2264 s :=\nbegin\n  obtain \u27e8b,hb,hbs\u27e9 := hs, \n  obtain \u27e8b\u2081, hb\u2081, hb\u2081x, hb\u2081b\u27e9 := hb.inf_basis x, \n  refine \u27e8x \u2294 b\u2081, \u27e8hb\u2081.sup_left_spanning _, le_sup_left, _\u27e9, \n    sup_le hxs (hb\u2081b.trans (sup_le hxs hbs))\u27e9, \n  rintros t \u27e8b\u2082,hb\u2082,hb\u2082t\u27e9 hxt hty,\n  refine (sup_le hxt (by_contra (\u03bb hb\u2081t, _))).antisymm hty,   \n  set j := b\u2081 \u2293 (x \u2294 b\u2082) with hj, \n\n  have hj_lt : j < b\u2081 := inf_le_left.lt_of_ne \n    (\u03bb h_eq, hb\u2081t (by {rw \u2190 h_eq, exact inf_le_right.trans (sup_le hxt hb\u2082t)})),   \n  \n  obtain \u27e8b\u2083, hb\u2083, hjb\u2083, hb\u2083j\u27e9 := hb\u2081.lt_base_le_sup_base_of_lt hb\u2082 hj_lt, \n\n  have h1 := @inf_lt_inf_of_lt_of_sup_le_sup _ _ _ _ _ x hjb\u2083 (sup_le _ le_sup_right), \n  swap, \n  { rw [hj, inf_comm, inf_sup_assoc_of_le b\u2081 le_sup_right, le_inf_iff] at hb\u2083j, \n    rw [hj, inf_comm, inf_sup_assoc_of_le b\u2081 le_sup_left, le_inf_iff], \n    refine \u27e8hb\u2083j.1, hb\u2083j.2.trans (sup_le le_sup_left (hb\u2082t.trans _))\u27e9,\n    rwa sup_comm},\n  refine (hb\u2081x.not_indep_of_lt (lt_of_le_of_lt (le_inf _ inf_le_right) h1) \n    inf_le_right (hb\u2083.inf_right_indep x)), \n  rw [hj, inf_comm, @inf_comm _ _ _ (x \u2294 b\u2082)], \n  exact le_inf (inf_le_left.trans le_sup_left) inf_le_right,  \nend \n\n/-- A supermatroid family is also a supermatroid family in the dual  -/\ninstance : supermatroid \u03b1\u1d52\u1d48 := \n\u27e8 \u03bb i s hi hs his, \n  (indep.exists_base_mid_of_le_spanning hs hi his).imp (\u03bb b \u27e8hb,hsb,hbi\u27e9, \u27e8hb, hbi, hsb\u27e9), \n  \u03bb i x hi hix, (spanning.canopy_le_of_le' hi hix).imp (\u03bb a \u27e8ha, hia\u27e9, \u27e8ha, hia\u27e9)\u27e9\n\nlemma exists_canopy (x : \u03b1) : \u2203 s, s canopy_for x := @exists_basis \u03b1\u1d52\u1d48 _ x\n\n/-- #### Spanning sets -/\n\n-- Need to rename the lemmas in this section to match their indep equivalents \n\nlemma spanning.exists_base_mid_of_indep_le (hs : spanning s) (hi : indep i) (his : i \u2264 s) :\n  \u2203 b, base b \u2227 b \u2264 s \u2227 i \u2264 b :=\n@indep.exists_base_mid_of_le_spanning \u03b1\u1d52\u1d48 _ _ _ hs hi his  \n\nlemma spanning.base_lt_indep_le_of_not_base (hs : spanning s) (hs_nb : \u00acbase s) (hi : indep i) \n(his : i \u2264 s) : \n  \u2203 b, base b \u2227 b < s \u2227 i \u2264 b := \n@indep.lt_base_le_spanning_of_not_base \u03b1\u1d52\u1d48 _ _ _ hs hs_nb hi his\n\nlemma spanning.base_lt_inf_base_le_of_not_base (hs : spanning s) (hs_nb : \u00acbase s)\n(hb : base b) : \n  \u2203 b', base b' \u2227 b' < s \u2227 s \u2293 b \u2264 b' := \n@indep.lt_base_sup_le_sup_base_of_not_base \u03b1\u1d52\u1d48 _ _ _ hs hs_nb hb \n\nlemma canopy_for.base (hs : s canopy_for x) (hx : indep x) : base s :=\n@basis_for.base \u03b1\u1d52\u1d48 _ _ _ hs hx\n\nlemma spanning.canopy_le_of_le (hs : spanning s) (hxs : x \u2264 s) : \u2203 t, t canopy_for x \u2227 t \u2264 s :=\nspanning.canopy_le_of_le' hs hxs\n\nlemma spanning.base_le_base_inf_le (hs : spanning s) (hb : base b) :\n  \u2203 b', base b' \u2227 b' \u2264 s \u2227 s \u2293 b \u2264 b' := \n@indep.exists_base_mid_of_le_sup_base \u03b1\u1d52\u1d48 _ _ _ hs hb \n\nlemma spanning.exists_sup_base_lt_of_not_canopy_for (hs : spanning s) (hnb : \u00ac s canopy_for x) \n(hix : x \u2264 s) : \n  \u2203 b, base b \u2227 (x \u2294 b) canopy_for x \u2227 x \u2294 b < s := \n@indep.exists_lt_inf_base_of_not_basis \u03b1\u1d52\u1d48 _ _ _ hs hnb hix\n\nlemma base.base_lt_inf_le_base_of_lt (hb : base b) (hb' : base b') (hbs : b < s) : \n  \u2203 b\u2080, base b\u2080 \u2227 b\u2080 < s \u2227 s \u2293 b' \u2264 b\u2080 := \n@base.lt_base_le_sup_base_of_lt \u03b1\u1d52\u1d48 _ _ _ _ hb hb' hbs \n\nlemma base.sup_canopy_for (hb : base b) (x : \u03b1) :\n  \u2203 b',base b' \u2227 (b' \u2294 x) canopy_for x \u2227 x \u2293 b \u2264 b'  :=\n@base.inf_basis \u03b1\u1d52\u1d48 _ _ hb x\n\nlemma basis_for.eq_inf_base_of_le_base (hix : i basis_for x) (hb : base b) (hib : i \u2264 b) : \n  i = x \u2293 b := \nhix.eq_of_le_indep (hb.inf_left_indep x) (le_inf hix.le hib) inf_le_left \n\nlemma basis_for.exists_base (hi : i basis_for x) : \n  \u2203 b, base b \u2227 i = x \u2293 b \u2227 \u2200 b', base b' \u2192 x \u2293 b \u2264 b' \u2192 x \u2293 b' = x \u2293 b := \nbegin\n  obtain \u27e8b, hb, hib\u27e9 := hi.indep, \n  have := hi.eq_inf_base_of_le_base hb hib, subst this, \n  exact \u27e8_,hb, rfl, \u03bb b' hb' hxb', \n    (hi.eq_of_le_indep (hb'.inf_left_indep x) (le_inf inf_le_left hxb') inf_le_left).symm\u27e9, \nend \n\nlemma exists_base_inf_basis (x : \u03b1) : \u2203 b, base b \u2227 x \u2293 b basis_for x := \nlet \u27e8i,hi\u27e9 := exists_basis x in hi.exists_base.imp (\u03bb b \u27e8hb,hib,_\u27e9, \u27e8hb, hib \u25b8 hi\u27e9)\n  \nlemma basis_for.eq_inf_base_both (hix : i basis_for x) (hiy : i basis_for y) : \n  \u2203 b, base b \u2227 i = x \u2293 b \u2227 i = y \u2293 b :=\nhix.indep.imp (\u03bb b hb, \u27e8hb.1, hix.eq_inf_base_of_le_base hb.1 hb.2, \n    hiy.eq_inf_base_of_le_base hb.1 hb.2\u27e9)\n\nlemma canopy_for.eq_sup_super_both (hsx : s canopy_for x) (hsy : s canopy_for y) : \n  \u2203 b, base b \u2227 s = x \u2294 b \u2227 s = y \u2294 b :=\n@basis_for.eq_inf_base_both \u03b1\u1d52\u1d48 _ _ _ _ hsx hsy\n\nlemma eq_inf_basis_forall_of_basis_forall {x : \u03ba \u2192 \u03b1} (h : \u2200 k, i basis_for x k) : \n  \u2203 b, base b \u2227 \u2200 k, i = (x k) \u2293 b := \n(is_empty_or_nonempty \u03ba).elim (\u03bb he, (exists_base \u03b1).imp (\u03bb b hb, \u27e8hb, he.elim\u27e9 )) \n  (\u03bb \u27e8k\u27e9, (h k).indep.imp (\u03bb b hb, \u27e8hb.1, \u03bb k', (h k').eq_inf_base_of_le_base hb.1 hb.2\u27e9))\n\nlemma eq_inf_basis_forall_of_basis_forall_mem {S : set \u03b1} (hS : \u2200 x \u2208 S, i basis_for x) :\n  \u2203 b, base b \u2227 \u2200 x \u2208 S, i = x \u2293 b :=\n(@eq_inf_basis_forall_of_basis_forall \u03b1 S _ i coe (\u03bb \u27e8x,hx\u27e9, hS x hx)).imp \n  (\u03bb b hb, \u27e8hb.1, \u03bb x hx, (hb.2 \u27e8x,hx\u27e9)\u27e9)\n\nlemma eq_sup_basis_forall_of_canopy_forall {x : \u03ba \u2192 \u03b1} (h : \u2200 k, s canopy_for x k) :\n  \u2203 b, base b \u2227 \u2200 k, s = x k \u2294 b :=\n@eq_inf_basis_forall_of_basis_forall \u03b1\u1d52\u1d48 \u03ba _ _ _ h\n\nlemma eq_sup_basis_forall_of_canopy_forall_mem {S : set \u03b1} (hS : \u2200 x \u2208 S, s canopy_for x) : \n  \u2203 b, base b \u2227 \u2200 x \u2208 S, s = x \u2294 b :=\n@eq_inf_basis_forall_of_basis_forall_mem \u03b1\u1d52\u1d48 _ _ S hS\n\nlemma canopy_for.eq_sup_base_both (hsx : s canopy_for x) (hsy : s canopy_for y) : \n  \u2203 b, base b \u2227 s = x \u2294 b \u2227 s = y \u2294 b := \n@basis_for.eq_inf_base_both \u03b1\u1d52\u1d48 _ _ _ _ hsx hsy \n\nlemma canopy_for.exists_base (hs : s canopy_for x) : \n  \u2203 b, base b \u2227 s = x \u2294 b \u2227 \u2200 b', base b' \u2192 b' \u2264 x \u2294 b \u2192 x \u2294 b' = x \u2294 b := \n@basis_for.exists_base \u03b1\u1d52\u1d48 _ _ _ hs \n\n-- Probably this lemma is the right way to do duality. It might be that only semimodularity is needed... \n\nlemma base.sup_canopy_of_inf_basis (hb : base b) (hbx : (x \u2293 b) basis_for x) : \n  (x \u2294 b) canopy_for x :=\nbegin\n  by_contradiction h,\n  obtain \u27e8b\u2081,hb\u2081,-, hb\u2081x\u27e9 := \n    (hb.sup_left_spanning x).exists_sup_base_lt_of_not_canopy_for h le_sup_left, \n  \n  set i := (x \u2294 b\u2081) \u2293 b with hi, \n\n  have hlt : i < b := lt_of_le_of_ne inf_le_right \n    (\u03bb h, hb\u2081x.ne (le_antisymm \n      (sup_le (le_sup_left.trans hb\u2081x.le) (le_sup_right.trans hb\u2081x.le)) \n      (sup_le (le_sup_left) (by {rw [\u2190h,hi], exact inf_le_left})))), \n  \n  obtain \u27e8b\u2082,hb\u2082,hib\u2082,hb\u2082i\u27e9 := hb.lt_base_le_sup_base_of_lt hb\u2081 hlt, \n  \n  have hlast := @inf_lt_inf_of_lt_of_sup_le_sup _ _ _ _ _ x hib\u2082 (sup_le _ le_sup_right),\n  { refine hbx.not_indep_of_lt (lt_of_le_of_lt _ hlast) inf_le_right (hb\u2082.inf_right_indep x),  \n    exact le_inf (le_inf (inf_le_left.trans le_sup_left) inf_le_right) inf_le_left},\n  rw [hi, inf_sup_assoc_of_le, le_inf_iff] at hb\u2082i \u22a2, \n  { exact \u27e8hb\u2082i.1, hb\u2082i.1.trans (hb\u2081x.le.trans_eq sup_comm)\u27e9},\n  exact le_sup_left, exact le_sup_right,\nend \n\nlemma base.sup_canopy_iff_inf_basis (hb : base b):\n  (x \u2294 b) canopy_for x \u2194 (x \u2293 b) basis_for x := \n\u27e8@base.sup_canopy_of_inf_basis \u03b1\u1d52\u1d48 _ _ _ hb, hb.sup_canopy_of_inf_basis\u27e9\n\n\nlemma indep.le_basis_le_sup (hi : indep i) (hj : j basis_for x) (hix : i \u2264 x) : \n  \u2203 i', i' basis_for x \u2227 i \u2264 i' \u2227 i' \u2264 i \u2294 j :=\nbegin\n  obtain \u27e8b\u2081,hb\u2081,rfl,-\u27e9 := hj.exists_base, \n  obtain \u27e8b\u2082, hb\u2082,hib\u2082, hb\u2082i\u27e9 := hi.exists_base_mid_of_le_sup_base hb\u2081, \n  rw [\u2190hb\u2081.sup_canopy_iff_inf_basis] at hj,\n  have hb\u2081b\u2082 := hj.eq_of_spanning_le (hb\u2082.sup_left_spanning x) le_sup_left\n    (sup_le le_sup_left (hb\u2082i.trans (sup_le (le_sup_of_le_left hix) le_sup_right))),\n  rw [\u2190hb\u2081b\u2082, hb\u2082.sup_canopy_iff_inf_basis] at hj, \n  exact \u27e8x \u2293 b\u2082, hj, le_inf hix hib\u2082, (inf_le_inf_left x hb\u2082i).trans \n    (by rw [inf_comm, sup_inf_assoc_of_le _ hix, inf_comm])\u27e9, \nend \n\n-- This lemma is the independence augmentation axiom in the restriction to `x`\nlemma indep.lt_basis_le_sup_of_not_basis (hi : indep i) (hin : \u00ac (i basis_for x)) \n(hj : j basis_for x) (hix : i \u2264 x) :\n  \u2203 i', i' basis_for x \u2227 i < i' \u2227 i' \u2264 i \u2294 j :=\n(hi.le_basis_le_sup hj hix).imp (\u03bb b \u27e8hb, hib, h\u27e9, \n  \u27e8hb, hib.lt_of_ne (\u03bb hib, hin (hib.substr hb)), h\u27e9) \n\n/-- This lemma is saying that `x \u2294 i` is a canopy for `x` in the restriction to `x \u2294 i` --/\nlemma sup_eq_of_basis_basis_basis (hi_inf : x \u2293 i basis_for x) (hi_sup : i basis_for x \u2294 i) \n(hj : j basis_for x \u2294 i) : \n  x \u2294 j = x \u2294 i :=\nbegin\n  refine (sup_le le_sup_left hj.le).antisymm (sup_le le_sup_left (by_contra (\u03bb h', _))), \n  \n  have hnb : \u00ac (i \u2293 (x \u2294 j)) basis_for x \u2294 i := hi_sup.not_basis_of_lt (inf_le_left.lt_of_ne\n    (\u03bb h_eq, by {rw \u2190h_eq at h', exact h' inf_le_right} )),\n\n  obtain \u27e8i\u2081, hi\u2081,hi'i\u2081,hi\u2081i'\u27e9 := (hi_sup.indep.inf_right_indep _).lt_basis_le_sup_of_not_basis \n    hnb hj (le_sup_of_le_right inf_le_left), \n\n  have hlt := @inf_lt_inf_of_lt_of_sup_le_sup _ _ _ _ _ x hi'i\u2081\n    (sup_le (hi\u2081i'.trans (sup_le le_sup_left \n      (by {rw [inf_comm, inf_sup_assoc_of_le _ (le_sup_left : x \u2264 x \u2294 j), @sup_comm _ _ i], \n          exact le_inf le_sup_right hj.le}))) le_sup_right), \n\n  rw [inf_assoc, @inf_comm _ _ _ x, inf_sup_self, inf_comm, @inf_comm _ _ i\u2081] at hlt, \n  exact hi_inf.not_indep_of_lt hlt inf_le_left (hi\u2081.indep.inf_left_indep _), \nend \n\nlemma spanning.ge_canopy_ge_inf (hs : spanning s) (ht : t canopy_for x) (hxs : x \u2264 s) : \n  \u2203 s', s' canopy_for x \u2227 s' \u2264 s \u2227 s \u2293 t \u2264 s' :=\n@indep.le_basis_le_sup \u03b1\u1d52\u1d48 _ _ _ _ hs ht hxs\n\nlemma spanning.gt_canopy_ge_inf_of_not_canopy (hs : spanning s) (hsn : \u00ac (s canopy_for x)) \n(ht : t canopy_for x) (hxs : x \u2264 s) :\n  \u2203 s', s' canopy_for x \u2227 s' < s \u2227 s \u2293 t \u2264 s' :=\n@indep.lt_basis_le_sup_of_not_basis \u03b1\u1d52\u1d48 _ _ _ _ hs hsn ht hxs\n\nlemma basis_for.basis_sup_mono (hix : i basis_for x) (hj : indep j) (hij : i \u2264 j) :\n  j basis_for (x \u2294 j) :=\nbegin\n  obtain \u27e8b, hb, hjb\u27e9 := hj, \n  obtain \u27e8j',hj',hjj'\u27e9 := (hb.indep_of_le hjb).le_basis_of_le (le_sup_right : j \u2264 x \u2294 j), \n  obtain rfl := \n    (hix.eq_of_le_indep (hb.inf_left_indep x) (le_inf hix.le (hij.trans hjb)) inf_le_left), \n  by_contra h, \n  have hlt  := hjj'.lt_of_ne (by {rintro rfl, exact h hj'}),\n\n  refine hix.not_indep_of_lt _ inf_le_right (hj'.indep.inf_right_indep x),\n  refine lt_of_le_of_lt (le_inf hij inf_le_left) \n    (inf_lt_inf_of_lt_of_sup_le_sup hlt (sup_le (sup_comm.subst hj'.le) le_sup_right)),\nend \n\nlemma canopy_for.canopy_inf_mono (hsx : s canopy_for x) (ht : spanning t) (hts : t \u2264 s) :\n  t canopy_for (x \u2293 t) :=\n@basis_for.basis_sup_mono \u03b1\u1d52\u1d48 _ _ _ _ hsx ht hts\n\n \n\n-- lemma le_basis_nested {n : \u2115} (x : fin n \u2192 \u03b1) (h : monotone x) : \n--   \u2203 b, base b \u2227 \u2200 i, x i \u2293 b basis_for x i :=\n-- begin\n--   obtain (rfl | n) := n, exact (exists_base \u03b1).imp (\u03bb b hb, \u27e8hb, fin_zero_elim\u27e9),  \n--   suffices hk : \u2200 (k : fin n.succ), \u2203 b, base b \u2227 \u2200 (i : fin n.succ), i \u2264 k \u2192 x i \u2293 b basis_for x i, \n--     from (hk (fin.last n)).imp (\u03bb b hb, \u27e8hb.1, \u03bb i, hb.2 _ (fin.le_last _)\u27e9),\n--   obtain \u27e8b0,\u27e8hb0,hb0'\u27e9\u27e9 := exists_base_inf_basis (x 0), \n--   refine \u03bb k, fin.induction_on k \u27e8b0, hb0, \u03bb i hi, by rwa hi.antisymm (fin.zero_le _)\u27e9 _,\n--   rintros i \u27e8b1,hb1,hib1\u27e9, \n--   --obtain \u27e8j,hj\u27e9 := (hib1 _ rfl.le).indep.le_basis_of_le -, \n\n--   obtain \u27e8j,hj,hjb1\u27e9 := (hib1  _ rfl.le).indep.le_basis_of_le \n--     (inf_le_left.trans (h (fin.cast_succ_lt_succ i).le)),\n  \n--   obtain \u27e8b,hb,hjb\u27e9 := hj.indep, \n--   have := hj.eq_inf_base_of_le_base hb hjb, subst this,  \n--   refine \u27e8b,hb, \u03bb i\u2080 hi\u2080i, hi\u2080i.lt_or_eq.elim (\u03bb hj', _) (by {rintro rfl, assumption })\u27e9, \n  \n  \n\n--   convert hib1 _ (fin.le_cast_succ_iff.mpr hj') using 1, \n--   refine le_antisymm (le_inf inf_le_left _) (le_inf inf_le_left _), \n--   { },\n  \n\n  \n  \n   \n  \n  \n  \n--    --indep.le_basis_of_le\n\n  -- exact ((exists_base_inf_basis (x 0)).imp (\u03bb b hb, \n  --   \u27e8hb.1,\u03bb i hi, by {rw (le_antisymm hi (fin.zero_le i)), exact hb.2}\u27e9) \n  \n\n  \n\n  -- refine fin.cases _ (\u03bb i, _),\n  -- exact ) , \n  \n  \n\n  \n\n\n\n--end \n  -- obtain (rfl | n) := n, \n  -- exact (exists_base \u03b1).imp (\u03bb b hb, \u27e8hb, fin_zero_elim\u27e9),\n\n  -- suffices hwin : \u2200 (y : \u2115 \u2192 \u03b1), monotone y \u2192 (\u2203 m, \u2200 i, m \u2264 i \u2192 y i = y m) \u2192 \n  --   \u2203 b, base b \u2227 \u2200 i, y i \u2293 b basis_for y i, \n  -- { have h' := hwin (\u03bb i, x \u27e8min i n, (min_le_right _ _).trans_lt (lt_add_one _) \u27e9)\n  --   (\u03bb i j hij, (em (j \u2264 n)).elim (\u03bb hjn, \n  --     by {have := hij.trans hjn, \n  --     refine h (subtype.mk_le_mk.mpr _), convert hij; rwa min_eq_left}) (\u03bb h, by {}))\n  --   \u27e8n, \u03bb i hni, by simp [min_eq_right hni]\u27e9,\n  --   exact h'.imp (\u03bb b \u27e8hb,hbx\u27e9, \u27e8hb, \u03bb \u27e8i,hi\u27e9, \n  --     by {rwa nat.lt_succ_iff at hi, convert hbx i; rwa min_eq_left, }\u27e9) },  \n  \n  -- induction n with k hk,\n  -- exact (exists_base \u03b1).imp (\u03bb b hb, \u27e8hb, fin_zero_elim\u27e9),\n  -- obtain \u27e8b\u2080,hb\u2080,hxb\u2080\u27e9 := @hk (\u03bb i, x i) (\u03bb i j hij, h (by simpa : (i : fin k.succ) \u2264 j)), \n  -- dsimp only at hxb\u2080, \n\n  -- obtain (rfl | k) := k, \n  --   exact (exists_base_inf_basis (x 0)).imp (\u03bb b \u27e8hb,hxb\u27e9, \u27e8hb, \u03bb i, by rwa fin.eq_zero i\u27e9),\n  \n  -- have := hxb\u2080 \u27e8k, lt_add_one k\u27e9, dsimp at this, \n  -- have := h (sorry : (\u27e8k,_\u27e9 : fin (k+1+1)) \u2264 \u27e8k+1,_\u27e9), \n\n\n  -- have := (hxb\u2080 (fin.last _)).indep.le_basis_of_le (inf_le_left.trans _), \n\n\n\n  -- cases n, exact (exists_base \u03b1).imp (\u03bb b i, fin_zero_elim),\n  -- suffices h\u2080 : \u2200 (k : fin n.succ), \u2203 b, \u2200 i, i \u2264 k \u2192 (x i \u2293 b) basis_for x i, \n  --   from (h\u2080 (fin.last n)).imp (\u03bb b hb i, hb _ (fin.le_last i)),\n  -- intro k, \n  -- refine fin.induction \n  --   ((exists_base_inf_basis (x 0)).imp (\u03bb b \u27e8hb,hbx\u27e9 i hi, by rwa hi.antisymm (fin.zero_le _))) _ k, \n  -- rintros i \u27e8b\u2080,hb\u2080\u27e9, \n  \n\n-- lemma le_basis\u2082 {x y : \u03b1} (hxy : x \u2264 y) : \u2203 b, x \u2293 b basis_for x \u2227 y \u2293 b basis_for y := \n-- begin\n--   obtain \u27e8i,hi\u27e9 := exists_basis x, \n--   obtain \u27e8j,hj,hij\u27e9 := hi.indep.le_basis_of_le (hi.le.trans hxy), \n--   obtain \u27e8b, hb, rfl, fa\u27e9 := hj.exists_base, \n--   exact \u27e8b, by rwa \u2190(hi.eq_inf_base_of_le_base hb (hij.trans inf_le_right)), hj\u27e9, \n-- end \n\nend supermatroid\n", "meta": {"author": "apnelson1", "repo": "matroids", "sha": "8068a4d03b9c39a8fe0cc8871ae571890f7ad489", "save_path": "github-repos/lean/apnelson1-matroids", "path": "github-repos/lean/apnelson1-matroids/matroids-8068a4d03b9c39a8fe0cc8871ae571890f7ad489/src/lattice/supermatroid.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797081106935, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7030405818969884}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic\n\n/-\n\n# Constructive bijections\n\nI'm generally quite anti-constructive mathematics; it makes stuff harder\nto do in Lean whilst only providing benefits such as computational content\nwhich I am typically not interested in (I never `#eval` stuff, I just\nwant to prove theorems and I don't care if the proof isn't `refl`).\n\nBut one example of where I love constructivism is `X \u2243 Y`, the class\nof constructive bijections from `X` to `Y`. What is a constructive\nbijection? It is a function `f : X \u2192 Y` plus some more data, but here\nthe data is *not* just the propositional claim that `f` is bijective\n(i.e. the *existence* of a two-sided inverse) -- it is the actual\ndata of the two-sided inverse too. \n\n`X \u2243 Y` is notation for `equiv X Y`. This is the type of constructive\nbijections from `X` to `Y`. To make a term of type `X \u2243 Y` you need\nto give a 4-tuple consisting of two functions `f : X \u2192 Y` and `g : Y \u2192 X`,\nplus also two proofs: firstly a proof of `\u2200 y, f (g y) = y`, and secondly\na proof of `\u2200 x, g (f x) = x`.\n\nNote that `X \u2243 Y` has type `Type`, not `Prop`. It does *not* mean \"there exists\na bijection from `X` to `Y`\", it is the actual data of a bijection\nfrom `X` to `Y`. \n\nLet's build two different bijections from \u211a to \u211a. \n\nThe first one is easy; I'll do it for you, to show you the syntax.\n\n-/\n\ndef bijection1 : \u211a \u2243 \u211a :=\n{ to_fun := id, -- use the identity function from \u211a to \u211a\n  inv_fun := id, -- its inverse is also the identity function\n  left_inv := begin -- we have to prove \u2200 q, id (id q) = q\n    intro q,\n    refl, \n  end,\n  right_inv := \u03bb q, rfl } -- same proof but in term mode\n\n-- Now see if you can do a harder one.\ndef bijection2 : \u211a \u2243 \u211a :=\n{ to_fun := \u03bb q, 3 * q + 4,\n  inv_fun := \u03bb r, (r - 4) / 3,\n  left_inv := begin -- start with `intro r`, then use `dsimp` to tidy up the mess\n    intro r,\n    dsimp,\n    ring,\n  end,\n  right_inv := begin\n    intro s,\n    ring,\n  end }  ", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/solutions/section09bijections_and_isomorphisms/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7030079672145341}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\nimport order.bounded_order\n\n/-!\n# Disjointness and complements\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines `disjoint`, `codisjoint`, and the `is_compl` predicate.\n\n## Main declarations\n\n* `disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element.\n* `codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element.\n* `is_compl x y`: In a bounded lattice, predicate for \"`x` is a complement of `y`\". Note that in a\n  non distributive lattice, an element can have several complements.\n* `complemented_lattice \u03b1`: Typeclass stating that any element of a lattice has a complement.\n\n-/\n\nvariable {\u03b1 : Type*}\n\nsection disjoint\nsection partial_order_bot\nvariables [partial_order \u03b1] [order_bot \u03b1] {a b c d : \u03b1}\n\n/-- Two elements of a lattice are disjoint if their inf is the bottom element.\n  (This generalizes disjoint sets, viewed as members of the subset lattice.)\n\nNote that we define this without reference to `\u2293`, as this allows us to talk about orders where\nthe infimum is not unique, or where implementing `has_inf` would require additional `decidable`\narguments. -/\ndef disjoint (a b : \u03b1) : Prop := \u2200 \u2983x\u2984, x \u2264 a \u2192 x \u2264 b \u2192 x \u2264 \u22a5\n\nlemma disjoint.comm : disjoint a b \u2194 disjoint b a := forall_congr $ \u03bb _, forall_swap\n@[symm] lemma disjoint.symm \u2983a b : \u03b1\u2984 : disjoint a b \u2192 disjoint b a := disjoint.comm.1\nlemma symmetric_disjoint : symmetric (disjoint : \u03b1 \u2192 \u03b1 \u2192 Prop) := disjoint.symm\n\n@[simp] lemma disjoint_bot_left : disjoint \u22a5 a := \u03bb x hbot ha, hbot\n@[simp] lemma disjoint_bot_right : disjoint a \u22a5 := \u03bb x ha hbot, hbot\n\nlemma disjoint.mono (h\u2081 : a \u2264 b) (h\u2082 : c \u2264 d) : disjoint b d \u2192 disjoint a c :=\n\u03bb h x ha hc, h (ha.trans h\u2081) (hc.trans h\u2082)\n\nlemma disjoint.mono_left (h : a \u2264 b) : disjoint b c \u2192 disjoint a c := disjoint.mono h le_rfl\nlemma disjoint.mono_right : b \u2264 c \u2192 disjoint a c \u2192 disjoint a b := disjoint.mono le_rfl\n\n@[simp] lemma disjoint_self : disjoint a a \u2194 a = \u22a5 :=\n\u27e8\u03bb hd, bot_unique $ hd le_rfl le_rfl, \u03bb h x ha hb, ha.trans_eq h\u27e9\n\n/- TODO: Rename `disjoint.eq_bot` to `disjoint.inf_eq` and `disjoint.eq_bot_of_self` to\n`disjoint.eq_bot` -/\nalias disjoint_self \u2194 disjoint.eq_bot_of_self _\n\nlemma disjoint.ne (ha : a \u2260 \u22a5) (hab : disjoint a b) : a \u2260 b :=\n\u03bb h, ha $ disjoint_self.1 $ by rwa \u2190h at hab\n\nlemma disjoint.eq_bot_of_le (hab : disjoint a b) (h : a \u2264 b) : a = \u22a5 :=\neq_bot_iff.2 $ hab le_rfl h\n\nlemma disjoint.eq_bot_of_ge (hab : disjoint a b) : b \u2264 a \u2192 b = \u22a5 := hab.symm.eq_bot_of_le\n\nend partial_order_bot\n\nsection partial_bounded_order\nvariables [partial_order \u03b1] [bounded_order \u03b1] {a : \u03b1}\n\n@[simp] theorem disjoint_top : disjoint a \u22a4 \u2194 a = \u22a5 :=\n\u27e8\u03bb h, bot_unique $ h le_rfl le_top, \u03bb h x ha htop, ha.trans_eq h\u27e9\n\n@[simp] theorem top_disjoint : disjoint \u22a4 a \u2194 a = \u22a5 :=\n\u27e8\u03bb h, bot_unique $ h le_top le_rfl, \u03bb h x htop ha, ha.trans_eq h\u27e9\n\nend partial_bounded_order\n\nsection semilattice_inf_bot\nvariables [semilattice_inf \u03b1] [order_bot \u03b1] {a b c d : \u03b1}\n\nlemma disjoint_iff_inf_le : disjoint a b \u2194 a \u2293 b \u2264 \u22a5 :=\n\u27e8\u03bb hd, hd inf_le_left inf_le_right, \u03bb h x ha hb, (le_inf ha hb).trans h\u27e9\nlemma disjoint_iff : disjoint a b \u2194 a \u2293 b = \u22a5 := disjoint_iff_inf_le.trans le_bot_iff\nlemma disjoint.le_bot : disjoint a b \u2192 a \u2293 b \u2264 \u22a5 := disjoint_iff_inf_le.mp\nlemma disjoint.eq_bot : disjoint a b \u2192 a \u2293 b = \u22a5 := bot_unique \u2218 disjoint.le_bot\nlemma disjoint_assoc : disjoint (a \u2293 b) c \u2194 disjoint a (b \u2293 c) :=\nby rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc]\nlemma disjoint_left_comm : disjoint a (b \u2293 c) \u2194 disjoint b (a \u2293 c) :=\nby simp_rw [disjoint_iff_inf_le, inf_left_comm]\nlemma disjoint_right_comm : disjoint (a \u2293 b) c \u2194 disjoint (a \u2293 c) b :=\nby simp_rw [disjoint_iff_inf_le, inf_right_comm]\n\nvariables (c)\n\nlemma disjoint.inf_left (h : disjoint a b) : disjoint (a \u2293 c) b := h.mono_left inf_le_left\nlemma disjoint.inf_left' (h : disjoint a b) : disjoint (c \u2293 a) b := h.mono_left inf_le_right\nlemma disjoint.inf_right (h : disjoint a b) : disjoint a (b \u2293 c) := h.mono_right inf_le_left\nlemma disjoint.inf_right' (h : disjoint a b) : disjoint a (c \u2293 b) := h.mono_right inf_le_right\n\nvariables {c}\n\nlemma disjoint.of_disjoint_inf_of_le (h : disjoint (a \u2293 b) c) (hle : a \u2264 c) : disjoint a b :=\ndisjoint_iff.2 $ h.eq_bot_of_le $ inf_le_of_left_le hle\n\nlemma disjoint.of_disjoint_inf_of_le' (h : disjoint (a \u2293 b) c) (hle : b \u2264 c) : disjoint a b :=\ndisjoint_iff.2 $ h.eq_bot_of_le $ inf_le_of_right_le hle\n\nend semilattice_inf_bot\n\nsection distrib_lattice_bot\nvariables [distrib_lattice \u03b1] [order_bot \u03b1] {a b c : \u03b1}\n\n@[simp] lemma disjoint_sup_left : disjoint (a \u2294 b) c \u2194 disjoint a c \u2227 disjoint b c :=\nby simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff]\n\n@[simp] lemma disjoint_sup_right : disjoint a (b \u2294 c) \u2194 disjoint a b \u2227 disjoint a c :=\nby simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff]\n\nlemma disjoint.sup_left (ha : disjoint a c) (hb : disjoint b c) : disjoint (a \u2294 b) c :=\ndisjoint_sup_left.2 \u27e8ha, hb\u27e9\n\nlemma disjoint.sup_right (hb : disjoint a b) (hc : disjoint a c) : disjoint a (b \u2294 c) :=\ndisjoint_sup_right.2 \u27e8hb, hc\u27e9\n\nlemma disjoint.left_le_of_le_sup_right (h : a \u2264 b \u2294 c) (hd : disjoint a c) : a \u2264 b :=\nle_of_inf_le_sup_le (le_trans hd.le_bot bot_le) $ sup_le h le_sup_right\n\nlemma disjoint.left_le_of_le_sup_left (h : a \u2264 c \u2294 b) (hd : disjoint a c) : a \u2264 b :=\nhd.left_le_of_le_sup_right $ by rwa sup_comm\n\nend distrib_lattice_bot\nend disjoint\n\nsection codisjoint\nsection partial_order_top\nvariables [partial_order \u03b1] [order_top \u03b1] {a b c d : \u03b1}\n\n/-- Two elements of a lattice are codisjoint if their sup is the top element.\n\nNote that we define this without reference to `\u2294`, as this allows us to talk about orders where\nthe supremum is not unique, or where implement `has_sup` would require additional `decidable`\narguments. -/\ndef codisjoint (a b : \u03b1) : Prop := \u2200 \u2983x\u2984, a \u2264 x \u2192 b \u2264 x \u2192 \u22a4 \u2264 x\n\nlemma codisjoint.comm : codisjoint a b \u2194 codisjoint b a := forall_congr $ \u03bb _, forall_swap\n@[symm] lemma codisjoint.symm \u2983a b : \u03b1\u2984 : codisjoint a b \u2192 codisjoint b a := codisjoint.comm.1\nlemma symmetric_codisjoint : symmetric (codisjoint : \u03b1 \u2192 \u03b1 \u2192 Prop) := codisjoint.symm\n\n@[simp] lemma codisjoint_top_left : codisjoint \u22a4 a := \u03bb x htop ha, htop\n@[simp] lemma codisjoint_top_right : codisjoint a \u22a4 := \u03bb x ha htop, htop\n\nlemma codisjoint.mono (h\u2081 : a \u2264 b) (h\u2082 : c \u2264 d) : codisjoint a c \u2192 codisjoint b d :=\n\u03bb h x ha hc, h (h\u2081.trans ha) (h\u2082.trans hc)\n\nlemma codisjoint.mono_left (h : a \u2264 b) : codisjoint a c \u2192 codisjoint b c :=\ncodisjoint.mono h le_rfl\nlemma codisjoint.mono_right : b \u2264 c \u2192 codisjoint a b \u2192 codisjoint a c :=\ncodisjoint.mono le_rfl\n\n@[simp] lemma codisjoint_self : codisjoint a a \u2194 a = \u22a4 :=\n\u27e8\u03bb hd, top_unique $ hd le_rfl le_rfl, \u03bb h x ha hb, h.symm.trans_le ha\u27e9\n\n/- TODO: Rename `codisjoint.eq_top` to `codisjoint.sup_eq` and `codisjoint.eq_top_of_self` to\n`codisjoint.eq_top` -/\nalias codisjoint_self \u2194 codisjoint.eq_top_of_self _\n\nlemma codisjoint.ne (ha : a \u2260 \u22a4) (hab : codisjoint a b) : a \u2260 b :=\n\u03bb h, ha $ codisjoint_self.1 $ by rwa \u2190h at hab\n\nlemma codisjoint.eq_top_of_le (hab : codisjoint a b) (h : b \u2264 a) : a = \u22a4 :=\neq_top_iff.2 $ hab le_rfl h\n\nlemma codisjoint.eq_top_of_ge (hab : codisjoint a b) : a \u2264 b \u2192 b = \u22a4 := hab.symm.eq_top_of_le\n\nend partial_order_top\n\nsection partial_bounded_order\nvariables [partial_order \u03b1] [bounded_order \u03b1] {a : \u03b1}\n\n@[simp] theorem codisjoint_bot : codisjoint a \u22a5 \u2194 a = \u22a4 :=\n\u27e8\u03bb h, top_unique $ h le_rfl bot_le, \u03bb h x ha htop, h.symm.trans_le ha\u27e9\n\n@[simp] theorem bot_codisjoint : codisjoint \u22a5 a \u2194 a = \u22a4 :=\n\u27e8\u03bb h, top_unique $ h bot_le le_rfl, \u03bb h x htop ha, h.symm.trans_le ha\u27e9\n\nend partial_bounded_order\n\nsection semilattice_sup_top\nvariables [semilattice_sup \u03b1] [order_top \u03b1] {a b c d : \u03b1}\n\nlemma codisjoint_iff_le_sup : codisjoint a b \u2194 \u22a4 \u2264 a \u2294 b := @disjoint_iff_inf_le \u03b1\u1d52\u1d48 _ _ _ _\nlemma codisjoint_iff : codisjoint a b \u2194 a \u2294 b = \u22a4 := @disjoint_iff \u03b1\u1d52\u1d48 _ _ _ _\nlemma codisjoint.top_le : codisjoint a b \u2192 \u22a4 \u2264 a \u2294 b := @disjoint.le_bot \u03b1\u1d52\u1d48 _ _ _ _\nlemma codisjoint.eq_top : codisjoint a b \u2192 a \u2294 b = \u22a4 := @disjoint.eq_bot \u03b1\u1d52\u1d48 _ _ _ _\nlemma codisjoint_assoc : codisjoint (a \u2294 b) c \u2194 codisjoint a (b \u2294 c) :=\n@disjoint_assoc \u03b1\u1d52\u1d48 _ _ _ _ _\nlemma codisjoint_left_comm : codisjoint a (b \u2294 c) \u2194 codisjoint b (a \u2294 c) :=\n@disjoint_left_comm \u03b1\u1d52\u1d48 _ _ _ _ _\nlemma codisjoint_right_comm : codisjoint (a \u2294 b) c \u2194 codisjoint (a \u2294 c) b :=\n@disjoint_right_comm \u03b1\u1d52\u1d48 _ _ _ _ _\n\nvariables (c)\n\nlemma codisjoint.sup_left (h : codisjoint a b) : codisjoint (a \u2294 c) b := h.mono_left le_sup_left\nlemma codisjoint.sup_left' (h : codisjoint a b) : codisjoint (c \u2294 a) b := h.mono_left le_sup_right\nlemma codisjoint.sup_right (h : codisjoint a b) : codisjoint a (b \u2294 c) := h.mono_right le_sup_left\nlemma codisjoint.sup_right' (h : codisjoint a b) : codisjoint a (c \u2294 b) := h.mono_right le_sup_right\n\nvariables {c}\n\nlemma codisjoint.of_codisjoint_sup_of_le (h : codisjoint (a \u2294 b) c) (hle : c \u2264 a) :\n  codisjoint a b :=\n@disjoint.of_disjoint_inf_of_le \u03b1\u1d52\u1d48 _ _ _ _ _ h hle\n\nlemma codisjoint.of_codisjoint_sup_of_le' (h : codisjoint (a \u2294 b) c) (hle : c \u2264 b) :\n  codisjoint a b :=\n@disjoint.of_disjoint_inf_of_le' \u03b1\u1d52\u1d48 _ _ _ _ _ h hle\n\nend semilattice_sup_top\n\nsection distrib_lattice_top\nvariables [distrib_lattice \u03b1] [order_top \u03b1] {a b c : \u03b1}\n\n@[simp] lemma codisjoint_inf_left : codisjoint (a \u2293 b) c \u2194 codisjoint a c \u2227 codisjoint b c :=\nby simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff]\n\n@[simp] lemma codisjoint_inf_right : codisjoint a (b \u2293 c) \u2194 codisjoint a b \u2227 codisjoint a c :=\nby simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff]\n\nlemma codisjoint.inf_left (ha : codisjoint a c) (hb : codisjoint b c) : codisjoint (a \u2293 b) c :=\ncodisjoint_inf_left.2 \u27e8ha, hb\u27e9\n\nlemma codisjoint.inf_right (hb : codisjoint a b) (hc : codisjoint a c) : codisjoint a (b \u2293 c) :=\ncodisjoint_inf_right.2 \u27e8hb, hc\u27e9\n\nlemma codisjoint.left_le_of_le_inf_right (h : a \u2293 b \u2264 c) (hd : codisjoint b c) : a \u2264 c :=\n@disjoint.left_le_of_le_sup_right \u03b1\u1d52\u1d48 _ _ _ _ _ h hd.symm\n\nlemma codisjoint.left_le_of_le_inf_left (h : b \u2293 a \u2264 c) (hd : codisjoint b c) : a \u2264 c :=\nhd.left_le_of_le_inf_right $ by rwa inf_comm\n\nend distrib_lattice_top\nend codisjoint\n\nopen order_dual\n\nlemma disjoint.dual [semilattice_inf \u03b1] [order_bot \u03b1] {a b : \u03b1} :\n  disjoint a b \u2192 codisjoint (to_dual a) (to_dual b) := id\n\nlemma codisjoint.dual [semilattice_sup \u03b1] [order_top \u03b1] {a b : \u03b1} :\n  codisjoint a b \u2192 disjoint (to_dual a) (to_dual b) := id\n\n@[simp] lemma disjoint_to_dual_iff [semilattice_sup \u03b1] [order_top \u03b1] {a b : \u03b1} :\n  disjoint (to_dual a) (to_dual b) \u2194 codisjoint a b := iff.rfl\n@[simp] lemma disjoint_of_dual_iff [semilattice_inf \u03b1] [order_bot \u03b1] {a b : \u03b1\u1d52\u1d48} :\n  disjoint (of_dual a) (of_dual b) \u2194 codisjoint a b := iff.rfl\n@[simp] lemma codisjoint_to_dual_iff [semilattice_inf \u03b1] [order_bot \u03b1] {a b : \u03b1} :\n  codisjoint (to_dual a) (to_dual b) \u2194 disjoint a b := iff.rfl\n@[simp] lemma codisjoint_of_dual_iff [semilattice_sup \u03b1] [order_top \u03b1] {a b : \u03b1\u1d52\u1d48} :\n  codisjoint (of_dual a) (of_dual b) \u2194 disjoint a b := iff.rfl\n\nsection distrib_lattice\nvariables [distrib_lattice \u03b1] [bounded_order \u03b1] {a b c : \u03b1}\n\nlemma disjoint.le_of_codisjoint (hab : disjoint a b) (hbc : codisjoint b c) : a \u2264 c :=\nbegin\n  rw [\u2190@inf_top_eq _ _ _ a, \u2190@bot_sup_eq _ _ _ c, \u2190hab.eq_bot, \u2190hbc.eq_top, sup_inf_right],\n  exact inf_le_inf_right _ le_sup_left,\nend\n\nend distrib_lattice\n\nsection is_compl\n\n/-- Two elements `x` and `y` are complements of each other if `x \u2294 y = \u22a4` and `x \u2293 y = \u22a5`. -/\n@[protect_proj] structure is_compl [partial_order \u03b1] [bounded_order \u03b1] (x y : \u03b1) : Prop :=\n(disjoint : disjoint x y)\n(codisjoint : codisjoint x y)\n\nlemma is_compl_iff [partial_order \u03b1] [bounded_order \u03b1] {a b : \u03b1} :\n  is_compl a b \u2194 disjoint a b \u2227 codisjoint a b := \u27e8\u03bb h, \u27e8h.1, h.2\u27e9, \u03bb h, \u27e8h.1, h.2\u27e9\u27e9\n\nnamespace is_compl\n\nsection bounded_partial_order\nvariables [partial_order \u03b1] [bounded_order \u03b1] {x y z : \u03b1}\n\n@[symm] protected lemma symm (h : is_compl x y) : is_compl y x := \u27e8h.1.symm, h.2.symm\u27e9\n\nlemma dual (h : is_compl x y) : is_compl (to_dual x) (to_dual y) := \u27e8h.2, h.1\u27e9\nlemma of_dual {a b : \u03b1\u1d52\u1d48} (h : is_compl a b) : is_compl (of_dual a) (of_dual b) := \u27e8h.2, h.1\u27e9\n\nend bounded_partial_order\n\nsection bounded_lattice\nvariables [lattice \u03b1] [bounded_order \u03b1] {x y z : \u03b1}\n\nlemma of_le (h\u2081 : x \u2293 y \u2264 \u22a5) (h\u2082 : \u22a4 \u2264 x \u2294 y) : is_compl x y :=\n\u27e8disjoint_iff_inf_le.mpr h\u2081, codisjoint_iff_le_sup.mpr h\u2082\u27e9\n\nlemma of_eq (h\u2081 : x \u2293 y = \u22a5) (h\u2082 : x \u2294 y = \u22a4) : is_compl x y :=\n\u27e8disjoint_iff.mpr h\u2081, codisjoint_iff.mpr h\u2082\u27e9\n\nlemma inf_eq_bot (h : is_compl x y) : x \u2293 y = \u22a5 := h.disjoint.eq_bot\nlemma sup_eq_top (h : is_compl x y) : x \u2294 y = \u22a4 := h.codisjoint.eq_top\n\nend bounded_lattice\n\nvariables [distrib_lattice \u03b1] [bounded_order \u03b1] {a b x y z : \u03b1}\n\nlemma inf_left_le_of_le_sup_right (h : is_compl x y) (hle : a \u2264 b \u2294 y) : a \u2293 x \u2264 b :=\ncalc a \u2293 x \u2264 (b \u2294 y) \u2293 x : inf_le_inf hle le_rfl\n... = (b \u2293 x) \u2294 (y \u2293 x) : inf_sup_right\n... = b \u2293 x : by rw [h.symm.inf_eq_bot, sup_bot_eq]\n... \u2264 b : inf_le_left\n\nlemma le_sup_right_iff_inf_left_le {a b} (h : is_compl x y) : a \u2264 b \u2294 y \u2194 a \u2293 x \u2264 b :=\n\u27e8h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right\u27e9\n\nlemma inf_left_eq_bot_iff (h : is_compl y z) : x \u2293 y = \u22a5 \u2194 x \u2264 z :=\nby rw [\u2190 le_bot_iff, \u2190 h.le_sup_right_iff_inf_left_le, bot_sup_eq]\n\nlemma inf_right_eq_bot_iff (h : is_compl y z) : x \u2293 z = \u22a5 \u2194 x \u2264 y :=\nh.symm.inf_left_eq_bot_iff\n\nlemma disjoint_left_iff (h : is_compl y z) : disjoint x y \u2194 x \u2264 z :=\nby { rw disjoint_iff, exact h.inf_left_eq_bot_iff }\n\nlemma disjoint_right_iff (h : is_compl y z) : disjoint x z \u2194 x \u2264 y :=\nh.symm.disjoint_left_iff\n\nlemma le_left_iff (h : is_compl x y) : z \u2264 x \u2194 disjoint z y :=\nh.disjoint_right_iff.symm\n\nlemma le_right_iff (h : is_compl x y) : z \u2264 y \u2194 disjoint z x :=\nh.symm.le_left_iff\n\n\n\nlemma right_le_iff (h : is_compl x y) : y \u2264 z \u2194 codisjoint z x := h.symm.left_le_iff\n\nprotected lemma antitone {x' y'} (h : is_compl x y) (h' : is_compl x' y') (hx : x \u2264 x') :\n  y' \u2264 y :=\nh'.right_le_iff.2 $ h.symm.codisjoint.mono_right hx\n\nlemma right_unique (hxy : is_compl x y) (hxz : is_compl x z) :\n  y = z :=\nle_antisymm (hxz.antitone hxy $ le_refl x) (hxy.antitone hxz $ le_refl x)\n\nlemma left_unique (hxz : is_compl x z) (hyz : is_compl y z) :\n  x = y :=\nhxz.symm.right_unique hyz.symm\n\nlemma sup_inf {x' y'} (h : is_compl x y) (h' : is_compl x' y') :\n  is_compl (x \u2294 x') (y \u2293 y') :=\nof_eq\n  (by rw [inf_sup_right, \u2190 inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm,\n    h'.inf_eq_bot, inf_bot_eq])\n  (by rw [sup_inf_left, @sup_comm _ _ x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq,\n    sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq])\n\nlemma inf_sup {x' y'} (h : is_compl x y) (h' : is_compl x' y') :\n  is_compl (x \u2293 x') (y \u2294 y') :=\n(h.symm.sup_inf h'.symm).symm\n\nend is_compl\n\nnamespace prod\nvariables {\u03b2 : Type*} [partial_order \u03b1] [partial_order \u03b2]\n\nprotected lemma disjoint_iff [order_bot \u03b1] [order_bot \u03b2] {x y : \u03b1 \u00d7 \u03b2} :\n  disjoint x y \u2194 disjoint x.1 y.1 \u2227 disjoint x.2 y.2 :=\nbegin\n  split,\n  { intros h,\n    refine \u27e8\u03bb a hx hy, (@h (a, \u22a5) \u27e8hx, _\u27e9 \u27e8hy, _\u27e9).1, \u03bb b hx hy, (@h (\u22a5, b) \u27e8_, hx\u27e9 \u27e8_, hy\u27e9).2\u27e9,\n    all_goals { exact bot_le }, },\n  { rintros \u27e8ha, hb\u27e9 z hza hzb,\n    refine \u27e8ha hza.1 hzb.1, hb hza.2 hzb.2\u27e9 },\nend\n\nprotected lemma codisjoint_iff [order_top \u03b1] [order_top \u03b2] {x y : \u03b1 \u00d7 \u03b2} :\n  codisjoint x y \u2194 codisjoint x.1 y.1 \u2227 codisjoint x.2 y.2 :=\n@prod.disjoint_iff \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _ _ _\n\nprotected lemma is_compl_iff [bounded_order \u03b1] [bounded_order \u03b2]\n  {x y : \u03b1 \u00d7 \u03b2} :\n  is_compl x y \u2194 is_compl x.1 y.1 \u2227 is_compl x.2 y.2 :=\nby simp_rw [is_compl_iff, prod.disjoint_iff, prod.codisjoint_iff, and_and_and_comm]\n\nend prod\n\nsection\nvariables [lattice \u03b1] [bounded_order \u03b1] {a b x : \u03b1}\n\n@[simp] lemma is_compl_to_dual_iff : is_compl (to_dual a) (to_dual b) \u2194 is_compl a b :=\n\u27e8is_compl.of_dual, is_compl.dual\u27e9\n\n@[simp] lemma is_compl_of_dual_iff {a b : \u03b1\u1d52\u1d48} : is_compl (of_dual a) (of_dual b) \u2194 is_compl a b :=\n\u27e8is_compl.dual, is_compl.of_dual\u27e9\n\nlemma is_compl_bot_top : is_compl (\u22a5 : \u03b1) \u22a4 := is_compl.of_eq bot_inf_eq sup_top_eq\nlemma is_compl_top_bot : is_compl (\u22a4 : \u03b1) \u22a5 := is_compl.of_eq inf_bot_eq top_sup_eq\n\nlemma eq_top_of_is_compl_bot (h : is_compl x \u22a5) : x = \u22a4 := sup_bot_eq.symm.trans h.sup_eq_top\nlemma eq_top_of_bot_is_compl (h : is_compl \u22a5 x) : x = \u22a4 := eq_top_of_is_compl_bot h.symm\nlemma eq_bot_of_is_compl_top (h : is_compl x \u22a4) : x = \u22a5 := eq_top_of_is_compl_bot h.dual\nlemma eq_bot_of_top_is_compl (h : is_compl \u22a4 x) : x = \u22a5 := eq_top_of_bot_is_compl h.dual\n\nend\n\n/-- A complemented bounded lattice is one where every element has a (not necessarily unique)\ncomplement. -/\nclass complemented_lattice (\u03b1) [lattice \u03b1] [bounded_order \u03b1] : Prop :=\n(exists_is_compl : \u2200 (a : \u03b1), \u2203 (b : \u03b1), is_compl a b)\n\nexport complemented_lattice (exists_is_compl)\n\nnamespace complemented_lattice\nvariables [lattice \u03b1] [bounded_order \u03b1] [complemented_lattice \u03b1]\n\ninstance : complemented_lattice \u03b1\u1d52\u1d48 :=\n\u27e8\u03bb a, let \u27e8b, hb\u27e9 := exists_is_compl (show \u03b1, from a) in \u27e8b, hb.dual\u27e9\u27e9\n\nend complemented_lattice\n\nend is_compl\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/disjoint.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.70291339765579}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\n\nimport algebra.order.absolute_value\nimport algebra.order.ring.with_top\nimport algebra.big_operators.basic\nimport data.fintype.card\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nMostly monotonicity results for the `\u220f` and `\u2211` operations.\n\n-/\n\nopen function\nopen_locale big_operators\n\nvariables {\u03b9 \u03b1 \u03b2 M N G k R : Type*}\n\nnamespace finset\n\nsection ordered_comm_monoid\n\nvariables [comm_monoid M] [ordered_comm_monoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M \u2192 N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y`. Let `g i`, `i \u2208 s`, be\na nonempty finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u220f x in s, g x) \u2264 \u220f x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\nlemma le_prod_nonempty_of_submultiplicative_on_pred\n  (f : M \u2192 N) (p : M \u2192 Prop) (h_mul : \u2200 x y, p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y)\n  (hp_mul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (g : \u03b9 \u2192 M) (s : finset \u03b9) (hs_nonempty : s.nonempty)\n  (hs : \u2200 i \u2208 s, p (g i)) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  refine le_trans (multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _,\n  { simp [hs_nonempty.ne_empty], },\n  { exact multiset.forall_mem_map_iff.mpr hs, },\n  rw multiset.map_map,\n  refl,\nend\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M \u2192 N` be a map subadditive on `{x | p x}`, i.e., `p x \u2192 p y \u2192 f (x + y) \u2264 f x + f y`. Let\n`g i`, `i \u2208 s`, be a nonempty finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M \u2192 N` is a submultiplicative function, `f (x * y) \u2264 f x * f y` and `g i`, `i \u2208 s`, is a\nnonempty finite family of elements of `M`, then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\nlemma le_prod_nonempty_of_submultiplicative\n  (f : M \u2192 N) (h_mul : \u2200 x y, f (x * y) \u2264 f x * f y) {s : finset \u03b9} (hs : s.nonempty) (g : \u03b9 \u2192 M) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nle_prod_nonempty_of_submultiplicative_on_pred f (\u03bb i, true) (\u03bb x y _ _, h_mul x y)\n  (\u03bb _ _ _ _, trivial) g s hs (\u03bb _ _, trivial)\n\n/-- If `f : M \u2192 N` is a subadditive function, `f (x + y) \u2264 f x + f y` and `g i`, `i \u2208 s`, is a\nnonempty finite family of elements of `M`, then `f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M \u2192 N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y`. Let `g i`, `i \u2208 s`, be a finite family of elements of `M` such\nthat `\u2200 i \u2208 s, p (g i)`. Then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\nlemma le_prod_of_submultiplicative_on_pred (f : M \u2192 N) (p : M \u2192 Prop) (h_one : f 1 = 1)\n  (h_mul : \u2200 x y, p x \u2192 p y \u2192 f (x * y) \u2264 f x * f y)\n  (hp_mul : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (g : \u03b9 \u2192 M) {s : finset \u03b9} (hs : \u2200 i \u2208 s, p (g i)) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  rcases eq_empty_or_nonempty s with rfl|hs_nonempty,\n  { simp [h_one] },\n  { exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs, },\nend\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M \u2192 N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x \u2192 p y \u2192 f (x + y) \u2264 f x + f y`.\nLet `g i`, `i \u2208 s`, be a finite family of elements of `M` such that `\u2200 i \u2208 s, p (g i)`. Then\n`f (\u2211 x in s, g x) \u2264 \u2211 x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M \u2192 N` is a submultiplicative function, `f (x * y) \u2264 f x * f y`, `f 1 = 1`, and `g i`,\n`i \u2208 s`, is a finite family of elements of `M`, then `f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\nlemma le_prod_of_submultiplicative (f : M \u2192 N) (h_one : f 1 = 1)\n  (h_mul : \u2200 x y, f (x * y) \u2264 f x * f y) (s : finset \u03b9) (g : \u03b9 \u2192 M) :\n  f (\u220f i in s, g i) \u2264 \u220f i in s, f (g i) :=\nbegin\n  refine le_trans (multiset.le_prod_of_submultiplicative f h_one h_mul _) _,\n  rw multiset.map_map,\n  refl,\nend\n\n/-- If `f : M \u2192 N` is a subadditive function, `f (x + y) \u2264 f x + f y`, `f 0 = 0`, and `g i`,\n`i \u2208 s`, is a finite family of elements of `M`, then `f (\u2211 i in s, g i) \u2264 \u2211 i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariables {f g : \u03b9 \u2192 N} {s t : finset \u03b9}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`\u220f i in s, f i \u2264 \u220f i in s, g i`. -/\n@[to_additive sum_le_sum]\nlemma prod_le_prod' (h : \u2200 i \u2208 s, f i \u2264 g i) : \u220f i in s, f i \u2264 \u220f i in s, g i :=\nmultiset.prod_map_le_prod_map f g h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`\u2211 i in s, f i \u2264 \u2211 i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n@[to_additive sum_nonneg] lemma one_le_prod' (h : \u2200i \u2208 s, 1 \u2264 f i) : 1 \u2264 (\u220f i in s, f i) :=\nle_trans (by rw prod_const_one) (prod_le_prod' h)\n\n@[to_additive finset.sum_nonneg']\nlemma one_le_prod'' (h : \u2200 (i : \u03b9), 1 \u2264 f i) : 1 \u2264 \u220f (i : \u03b9) in s, f i :=\nfinset.one_le_prod' (\u03bb i hi, h i)\n\n@[to_additive sum_nonpos] lemma prod_le_one' (h : \u2200i \u2208 s, f i \u2264 1) : (\u220f i in s, f i) \u2264 1 :=\n(prod_le_prod' h).trans_eq (by rw prod_const_one)\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\nlemma prod_le_prod_of_subset_of_one_le' (h : s \u2286 t) (hf : \u2200 i \u2208 t, i \u2209 s \u2192 1 \u2264 f i) :\n  \u220f i in s, f i \u2264 \u220f i in t, f i :=\nby classical;\ncalc (\u220f i in s, f i) \u2264 (\u220f i in t \\ s, f i) * (\u220f i in s, f i) :\n    le_mul_of_one_le_left' $ one_le_prod' $ by simpa only [mem_sdiff, and_imp]\n  ... = \u220f i in t \\ s \u222a s, f i : (prod_union sdiff_disjoint).symm\n  ... = \u220f i in t, f i         : by rw [sdiff_union_of_subset h]\n\n@[to_additive sum_mono_set_of_nonneg]\nlemma prod_mono_set_of_one_le' (hf : \u2200 x, 1 \u2264 f x) : monotone (\u03bb s, \u220f x in s, f x) :=\n\u03bb s t hst, prod_le_prod_of_subset_of_one_le' hst $ \u03bb x _ _, hf x\n\n@[to_additive sum_le_univ_sum_of_nonneg]\nlemma prod_le_univ_prod_of_one_le' [fintype \u03b9] {s : finset \u03b9} (w : \u2200 x, 1 \u2264 f x) :\n  \u220f x in s, f x \u2264 \u220f x, f x :=\nprod_le_prod_of_subset_of_one_le' (subset_univ s) (\u03bb a _ _, w a)\n\n@[to_additive sum_eq_zero_iff_of_nonneg]\nlemma prod_eq_one_iff_of_one_le' : (\u2200 i \u2208 s, 1 \u2264 f i) \u2192 (\u220f i in s, f i = 1 \u2194 \u2200 i \u2208 s, f i = 1) :=\nbegin\n  classical,\n  apply finset.induction_on s,\n  exact \u03bb _, \u27e8\u03bb _ _, false.elim, \u03bb _, rfl\u27e9,\n  assume a s ha ih H,\n  have : \u2200 i \u2208 s, 1 \u2264 f i, from \u03bb _, H _ \u2218 mem_insert_of_mem,\n  rw [prod_insert ha, mul_eq_one_iff' (H _ $ mem_insert_self _ _) (one_le_prod' this),\n    forall_mem_insert, ih this]\nend\n\n@[to_additive sum_eq_zero_iff_of_nonneg]\nlemma prod_eq_one_iff_of_le_one' : (\u2200 i \u2208 s, f i \u2264 1) \u2192 (\u220f i in s, f i = 1 \u2194 \u2200 i \u2208 s, f i = 1) :=\n@prod_eq_one_iff_of_one_le' _ N\u1d52\u1d48 _ _ _\n\n@[to_additive single_le_sum]\nlemma single_le_prod' (hf : \u2200 i \u2208 s, 1 \u2264 f i) {a} (h : a \u2208 s) : f a \u2264 (\u220f x in s, f x) :=\ncalc f a = \u220f i in {a}, f i : prod_singleton.symm\n     ... \u2264 \u220f i in s, f i   :\n  prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) $ \u03bb i hi _, hf i hi\n\n@[to_additive sum_le_card_nsmul]\nlemma prod_le_pow_card (s : finset \u03b9) (f : \u03b9 \u2192 N) (n : N) (h : \u2200 x \u2208 s, f x \u2264 n) :\n  s.prod f \u2264 n ^ s.card :=\nbegin\n  refine (multiset.prod_le_pow_card (s.val.map f) n _).trans _,\n  { simpa using h },\n  { simpa }\nend\n\n@[to_additive card_nsmul_le_sum]\nlemma pow_card_le_prod (s : finset \u03b9) (f : \u03b9 \u2192 N) (n : N) (h : \u2200 x \u2208 s, n \u2264 f x) :\n  n ^ s.card \u2264 s.prod f :=\n@finset.prod_le_pow_card _ N\u1d52\u1d48 _ _ _ _ h\n\nlemma card_bUnion_le_card_mul [decidable_eq \u03b2] (s : finset \u03b9) (f : \u03b9 \u2192 finset \u03b2) (n : \u2115)\n  (h : \u2200 a \u2208 s, (f a).card \u2264 n) :\n  (s.bUnion f).card \u2264 s.card * n :=\ncard_bUnion_le.trans $ sum_le_card_nsmul _ _ _ h\n\nvariables {\u03b9' : Type*} [decidable_eq \u03b9']\n\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\nlemma prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : finset \u03b9'}\n  {g : \u03b9 \u2192 \u03b9'} {f : \u03b9 \u2192 N} (h : \u2200 y \u2209 t, (1 : N) \u2264 \u220f x in s.filter (\u03bb x, g x = y), f x) :\n  \u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x \u2264 \u220f x in s, f x :=\ncalc (\u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x) \u2264\n  (\u220f y in t \u222a s.image g, \u220f x in s.filter (\u03bb x, g x = y), f x) :\n  prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) $ \u03bb y hyts, h y\n... = \u220f x in s, f x :\n  prod_fiberwise_of_maps_to (\u03bb x hx, mem_union.2 $ or.inr $ mem_image_of_mem _ hx) _\n\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\nlemma prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : finset \u03b9'}\n  {g : \u03b9 \u2192 \u03b9'} {f : \u03b9 \u2192 N} (h : \u2200 y \u2209 t, (\u220f x in s.filter (\u03bb x, g x = y), f x) \u2264 1) :\n  (\u220f x in s, f x) \u2264 \u220f y in t, \u220f x in s.filter (\u03bb x, g x = y), f x :=\n@prod_fiberwise_le_prod_of_one_le_prod_fiber' _ N\u1d52\u1d48 _ _ _ _ _ _ _ h\n\nend ordered_comm_monoid\n\nlemma abs_sum_le_sum_abs {G : Type*} [linear_ordered_add_comm_group G] (f : \u03b9 \u2192 G) (s : finset \u03b9) :\n  |\u2211 i in s, f i| \u2264 \u2211 i in s, |f i| :=\nle_sum_of_subadditive _ abs_zero abs_add s f\n\nlemma abs_sum_of_nonneg {G : Type*} [linear_ordered_add_comm_group G] {f : \u03b9 \u2192 G} {s : finset \u03b9}\n  (hf : \u2200 i \u2208 s, 0 \u2264 f i) :\n  |\u2211 (i : \u03b9) in s, f i| = \u2211 (i : \u03b9) in s, f i :=\nby rw abs_of_nonneg (finset.sum_nonneg hf)\n\nlemma abs_sum_of_nonneg' {G : Type*} [linear_ordered_add_comm_group G] {f : \u03b9 \u2192 G} {s : finset \u03b9}\n  (hf : \u2200 i, 0 \u2264 f i) :\n  |\u2211 (i : \u03b9) in s, f i| = \u2211 (i : \u03b9) in s, f i :=\nby rw abs_of_nonneg (finset.sum_nonneg' hf)\n\nlemma abs_prod {R : Type*} [linear_ordered_comm_ring R] {f : \u03b9 \u2192 R} {s : finset \u03b9} :\n  |\u220f x in s, f x| = \u220f x in s, |f x| :=\n(abs_hom.to_monoid_hom : R \u2192* R).map_prod _ _\n\nsection pigeonhole\n\nvariable [decidable_eq \u03b2]\n\ntheorem card_le_mul_card_image_of_maps_to {f : \u03b1 \u2192 \u03b2} {s : finset \u03b1} {t : finset \u03b2}\n  (Hf : \u2200 a \u2208 s, f a \u2208 t) (n : \u2115) (hn : \u2200 a \u2208 t, (s.filter (\u03bb x, f x = a)).card \u2264 n) :\n  s.card \u2264 n * t.card :=\ncalc s.card = (\u2211 a in t, (s.filter (\u03bb x, f x = a)).card) : card_eq_sum_card_fiberwise Hf\n        ... \u2264 (\u2211 _ in t, n)                              : sum_le_sum hn\n        ... = _                                          : by simp [mul_comm]\n\ntheorem card_le_mul_card_image {f : \u03b1 \u2192 \u03b2} (s : finset \u03b1)\n  (n : \u2115) (hn : \u2200 a \u2208 s.image f, (s.filter (\u03bb x, f x = a)).card \u2264 n) :\n  s.card \u2264 n * (s.image f).card :=\ncard_le_mul_card_image_of_maps_to (\u03bb x, mem_image_of_mem _) n hn\n\ntheorem mul_card_image_le_card_of_maps_to {f : \u03b1 \u2192 \u03b2} {s : finset \u03b1} {t : finset \u03b2}\n  (Hf : \u2200 a \u2208 s, f a \u2208 t) (n : \u2115) (hn : \u2200 a \u2208 t, n \u2264 (s.filter (\u03bb x, f x = a)).card) :\n  n * t.card \u2264 s.card :=\ncalc n * t.card = (\u2211 _ in t, n) : by simp [mul_comm]\n            ... \u2264 (\u2211 a in t, (s.filter (\u03bb x, f x = a)).card) : sum_le_sum hn\n            ... = s.card : by rw \u2190 card_eq_sum_card_fiberwise Hf\n\ntheorem mul_card_image_le_card {f : \u03b1 \u2192 \u03b2} (s : finset \u03b1)\n  (n : \u2115) (hn : \u2200 a \u2208 s.image f, n \u2264 (s.filter (\u03bb x, f x = a)).card) :\n  n * (s.image f).card \u2264 s.card :=\nmul_card_image_le_card_of_maps_to (\u03bb x, mem_image_of_mem _) n hn\n\nend pigeonhole\n\nsection double_counting\nvariables [decidable_eq \u03b1] {s : finset \u03b1} {B : finset (finset \u03b1)} {n : \u2115}\n\n/-- If every element belongs to at most `n` finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\nlemma sum_card_inter_le (h : \u2200 a \u2208 s, (B.filter $ (\u2208) a).card \u2264 n) :\n  \u2211 t in B, (s \u2229 t).card \u2264 s.card * n :=\nbegin\n  refine le_trans _ (s.sum_le_card_nsmul _ _ h),\n  simp_rw [\u2190filter_mem_eq_inter, card_eq_sum_ones, sum_filter],\n  exact sum_comm.le,\nend\n\n/-- If every element belongs to at most `n` finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\nlemma sum_card_le [fintype \u03b1] (h : \u2200 a, (B.filter $ (\u2208) a).card \u2264 n) :\n  \u2211 s in B, s.card \u2264 fintype.card \u03b1 * n :=\ncalc \u2211 s in B, s.card = \u2211 s in B, (univ \u2229 s).card : by simp_rw univ_inter\n                  ... \u2264 fintype.card \u03b1 * n        : sum_card_inter_le (\u03bb a _, h a)\n\n/-- If every element belongs to at least `n` finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\nlemma le_sum_card_inter (h : \u2200 a \u2208 s, n \u2264 (B.filter $ (\u2208) a).card) :\n  s.card * n \u2264 \u2211 t in B, (s \u2229 t).card :=\nbegin\n  apply (s.card_nsmul_le_sum _ _ h).trans,\n  simp_rw [\u2190filter_mem_eq_inter, card_eq_sum_ones, sum_filter],\n  exact sum_comm.le,\nend\n\n/-- If every element belongs to at least `n` finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\nlemma le_sum_card [fintype \u03b1] (h : \u2200 a, n \u2264 (B.filter $ (\u2208) a).card) :\n  fintype.card \u03b1 * n \u2264 \u2211 s in B, s.card :=\ncalc fintype.card \u03b1 * n \u2264 \u2211 s in B, (univ \u2229 s).card : le_sum_card_inter (\u03bb a _, h a)\n                    ... = \u2211 s in B, s.card          : by simp_rw univ_inter\n\n/-- If every element belongs to exactly `n` finsets, then the sum of their sizes is `n` times how\nmany they are. -/\nlemma sum_card_inter (h : \u2200 a \u2208 s, (B.filter $ (\u2208) a).card = n) :\n  \u2211 t in B, (s \u2229 t).card = s.card * n :=\n(sum_card_inter_le $ \u03bb a ha, (h a ha).le).antisymm (le_sum_card_inter $ \u03bb a ha, (h a ha).ge)\n\n/-- If every element belongs to exactly `n` finsets, then the sum of their sizes is `n` times how\nmany they are. -/\nlemma sum_card [fintype \u03b1] (h : \u2200 a, (B.filter $ (\u2208) a).card = n) :\n  \u2211 s in B, s.card = fintype.card \u03b1 * n :=\nby simp_rw [fintype.card, \u2190sum_card_inter (\u03bb a _, h a), univ_inter]\n\nlemma card_le_card_bUnion {s : finset \u03b9} {f : \u03b9 \u2192 finset \u03b1} (hs : (s : set \u03b9).pairwise_disjoint f)\n  (hf : \u2200 i \u2208 s, (f i).nonempty) :\n  s.card \u2264 (s.bUnion f).card :=\nby { rw [card_bUnion hs, card_eq_sum_ones], exact sum_le_sum (\u03bb i hi, (hf i hi).card_pos) }\n\nlemma card_le_card_bUnion_add_card_fiber {s : finset \u03b9} {f : \u03b9 \u2192 finset \u03b1}\n  (hs : (s : set \u03b9).pairwise_disjoint f) :\n  s.card \u2264 (s.bUnion f).card + (s.filter $ \u03bb i, f i = \u2205).card :=\nbegin\n  rw [\u2190finset.filter_card_add_filter_neg_card_eq_card (\u03bb i, f i = \u2205), add_comm],\n  exact add_le_add_right ((card_le_card_bUnion (hs.subset $ filter_subset _ _) $ \u03bb i hi,\n    nonempty_of_ne_empty $ (mem_filter.1 hi).2).trans $ card_le_of_subset $\n    bUnion_subset_bUnion_of_subset_left _ $ filter_subset _ _) _,\nend\n\nlemma card_le_card_bUnion_add_one {s : finset \u03b9} {f : \u03b9 \u2192 finset \u03b1} (hf : injective f)\n  (hs : (s : set \u03b9).pairwise_disjoint f) :\n  s.card \u2264 (s.bUnion f).card + 1 :=\n(card_le_card_bUnion_add_card_fiber hs).trans $ add_le_add_left (card_le_one.2 $ \u03bb i hi j hj, hf $\n  (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n\nend double_counting\n\nsection canonically_ordered_monoid\n\nvariables [canonically_ordered_monoid M] {f : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[simp, to_additive sum_eq_zero_iff]\nlemma prod_eq_one_iff' : \u220f x in s, f x = 1 \u2194 \u2200 x \u2208 s, f x = 1 :=\nprod_eq_one_iff_of_one_le' $ \u03bb x hx, one_le (f x)\n\n@[to_additive sum_le_sum_of_subset]\nlemma prod_le_prod_of_subset' (h : s \u2286 t) : \u220f x in s, f x \u2264 \u220f x in t, f x :=\nprod_le_prod_of_subset_of_one_le' h $ assume x h\u2081 h\u2082, one_le _\n\n@[to_additive sum_mono_set]\nlemma prod_mono_set' (f : \u03b9 \u2192 M) : monotone (\u03bb s, \u220f x in s, f x) :=\n\u03bb s\u2081 s\u2082 hs, prod_le_prod_of_subset' hs\n\n@[to_additive sum_le_sum_of_ne_zero]\nlemma prod_le_prod_of_ne_one' (h : \u2200 x \u2208 s, f x \u2260 1 \u2192 x \u2208 t) :\n  \u220f x in s, f x \u2264 \u220f x in t, f x :=\nby classical;\ncalc \u220f x in s, f x = (\u220f x in s.filter (\u03bb x, f x = 1), f x) * \u220f x in s.filter (\u03bb x, f x \u2260 1), f x :\n    by rw [\u2190 prod_union, filter_union_filter_neg_eq];\n       exact disjoint_filter.2 (assume _ _ h n_h, n_h h)\n  ... \u2264 (\u220f x in t, f x) : mul_le_of_le_one_of_le\n      (prod_le_one' $ by simp only [mem_filter, and_imp]; exact \u03bb _ _, le_of_eq)\n      (prod_le_prod_of_subset' $ by simpa only [subset_iff, mem_filter, and_imp])\n\nend canonically_ordered_monoid\n\nsection ordered_cancel_comm_monoid\n\nvariables [ordered_cancel_comm_monoid M] {f g : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (Hle : \u2200 i \u2208 s, f i \u2264 g i) (Hlt : \u2203 i \u2208 s, f i < g i) :\n  \u220f i in s, f i < \u220f i in s, g i :=\nbegin\n  classical,\n  rcases Hlt with \u27e8i, hi, hlt\u27e9,\n  rw [\u2190 insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)],\n  exact mul_lt_mul_of_lt_of_le hlt (prod_le_prod' $ \u03bb j hj, Hle j  $ mem_of_mem_erase hj)\nend\n\n@[to_additive sum_lt_sum_of_nonempty]\nlemma prod_lt_prod_of_nonempty' (hs : s.nonempty) (Hlt : \u2200 i \u2208 s, f i < g i) :\n  \u220f i in s, f i < \u220f i in s, g i :=\nbegin\n  apply prod_lt_prod',\n  { intros i hi, apply le_of_lt (Hlt i hi) },\n  cases hs with i hi,\n  exact \u27e8i, hi, Hlt i hi\u27e9,\nend\n\n@[to_additive sum_lt_sum_of_subset]\nlemma prod_lt_prod_of_subset' (h : s \u2286 t) {i : \u03b9} (ht : i \u2208 t) (hs : i \u2209 s) (hlt : 1 < f i)\n  (hle : \u2200 j \u2208 t, j \u2209 s \u2192 1 \u2264 f j) :\n  \u220f j in s, f j < \u220f j in t, f j :=\nby classical;\ncalc \u220f j in s, f j < \u220f j in insert i s, f j :\nbegin\n  rw prod_insert hs,\n  exact lt_mul_of_one_lt_left' (\u220f j in s, f j) hlt,\nend\n... \u2264 \u220f j in t, f j :\nbegin\n  apply prod_le_prod_of_subset_of_one_le',\n  { simp [finset.insert_subset, h, ht] },\n  { assume x hx h'x,\n    simp only [mem_insert, not_or_distrib] at h'x,\n    exact hle x hx h'x.2 }\nend\n\n@[to_additive single_lt_sum]\nlemma single_lt_prod' {i j : \u03b9} (hij : j \u2260 i) (hi : i \u2208 s) (hj : j \u2208 s) (hlt : 1 < f j)\n  (hle : \u2200 k \u2208 s, k \u2260 i \u2192 1 \u2264 f k) :\n  f i < \u220f k in s, f k :=\ncalc f i = \u220f k in {i}, f k : prod_singleton.symm\n     ... < \u220f k in s, f k   :\n  prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt $\n    \u03bb k hks hki, hle k hks (mt mem_singleton.2 hki)\n\n@[to_additive sum_pos] lemma one_lt_prod (h : \u2200i \u2208 s, 1 < f i) (hs : s.nonempty) :\n  1 < (\u220f i in s, f i) :=\nlt_of_le_of_lt (by rw prod_const_one) $ prod_lt_prod_of_nonempty' hs h\n\n@[to_additive] lemma prod_lt_one (h : \u2200i \u2208 s, f i < 1) (hs : s.nonempty) :\n  (\u220f i in s, f i) < 1 :=\n(prod_lt_prod_of_nonempty' hs h).trans_le (by rw prod_const_one)\n\n@[to_additive sum_pos'] lemma one_lt_prod' (h : \u2200 i \u2208 s, 1 \u2264 f i) (hs : \u2203 i \u2208 s, 1 < f i) :\n  1 < (\u220f i in s, f i) :=\nprod_const_one.symm.trans_lt $ prod_lt_prod' h hs\n\n@[to_additive] lemma prod_lt_one' (h : \u2200 i \u2208 s, f i \u2264 1) (hs : \u2203 i \u2208 s, f i < 1)  :\n  \u220f i in s, f i < 1 :=\nprod_const_one.le.trans_lt' $ prod_lt_prod' h hs\n\n@[to_additive] lemma prod_eq_prod_iff_of_le {f g : \u03b9 \u2192 M} (h : \u2200 i \u2208 s, f i \u2264 g i) :\n  \u220f i in s, f i = \u220f i in s, g i \u2194 \u2200 i \u2208 s, f i = g i :=\nbegin\n  classical,\n  revert h,\n  refine finset.induction_on s (\u03bb _, \u27e8\u03bb _ _, false.elim, \u03bb _, rfl\u27e9) (\u03bb a s ha ih H, _),\n  specialize ih (\u03bb i, H i \u2218 finset.mem_insert_of_mem),\n  rw [finset.prod_insert ha, finset.prod_insert ha, finset.forall_mem_insert, \u2190ih],\n  exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (finset.prod_le_prod'\n    (\u03bb i, H i \u2218 finset.mem_insert_of_mem)),\nend\n\nend ordered_cancel_comm_monoid\n\nsection linear_ordered_cancel_comm_monoid\n\nvariables [linear_ordered_cancel_comm_monoid M] {f g : \u03b9 \u2192 M} {s t : finset \u03b9}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : \u220f i in s, f i < \u220f i in s, g i) :\n  \u2203 i \u2208 s, f i < g i :=\nbegin\n  contrapose! Hlt with Hle,\n  exact prod_le_prod' Hle\nend\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.nonempty) (Hle : \u220f i in s, f i \u2264 \u220f i in s, g i) :\n  \u2203 i \u2208 s, f i \u2264 g i :=\nbegin\n  contrapose! Hle with Hlt,\n  exact prod_lt_prod_of_nonempty' hs Hlt\nend\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\nlemma exists_one_lt_of_prod_one_of_exists_ne_one' (f : \u03b9 \u2192 M)\n  (h\u2081 : \u220f i in s, f i = 1) (h\u2082 : \u2203 i \u2208 s, f i \u2260 1) :\n  \u2203 i \u2208 s, 1 < f i :=\nbegin\n  contrapose! h\u2081,\n  obtain \u27e8i, m, i_ne\u27e9 : \u2203 i \u2208 s, f i \u2260 1 := h\u2082,\n  apply ne_of_lt,\n  calc \u220f j in s, f j < \u220f j in s, 1 : prod_lt_prod' h\u2081 \u27e8i, m, (h\u2081 i m).lt_of_ne i_ne\u27e9\n                 ... = 1           : prod_const_one\nend\n\nend linear_ordered_cancel_comm_monoid\n\nsection ordered_comm_semiring\n\nvariables [ordered_comm_semiring R] {f g : \u03b9 \u2192 R} {s t : finset \u03b9}\nopen_locale classical\n\n/- this is also true for a ordered commutative multiplicative monoid with zero -/\nlemma prod_nonneg (h0 : \u2200 i \u2208 s, 0 \u2264 f i) : 0 \u2264 \u220f i in s, f i :=\nprod_induction f (\u03bb i, 0 \u2264 i) (\u03bb _ _ ha hb, mul_nonneg ha hb) zero_le_one h0\n\n/-- If all `f i`, `i \u2208 s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\nlemma prod_le_prod (h0 : \u2200 i \u2208 s, 0 \u2264 f i) (h1 : \u2200 i \u2208 s, f i \u2264 g i) :\n  \u220f i in s, f i \u2264 \u220f i in s, g i :=\nbegin\n  induction s using finset.induction with a s has ih h,\n  { simp },\n  { simp only [prod_insert has], apply mul_le_mul,\n    { exact h1 a (mem_insert_self a s) },\n    { apply ih (\u03bb x H, h0 _ _) (\u03bb x H, h1 _ _); exact (mem_insert_of_mem H) },\n    { apply prod_nonneg (\u03bb x H, h0 x (mem_insert_of_mem H)) },\n    { apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) } }\nend\n\n/-- If each `f i`, `i \u2208 s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\nlemma prod_le_one (h0 : \u2200 i \u2208 s, 0 \u2264 f i) (h1 : \u2200 i \u2208 s, f i \u2264 1) :\n  \u220f i in s, f i \u2264 1 :=\nbegin\n  convert \u2190 prod_le_prod h0 h1,\n  exact finset.prod_const_one\nend\n\n/-- If `g, h \u2264 f` and `g i + h i \u2264 f i`, then the product of `f` over `s` is at least the\n  sum of the products of `g` and `h`. This is the version for `ordered_comm_semiring`. -/\nlemma prod_add_prod_le {i : \u03b9} {f g h : \u03b9 \u2192 R}\n  (hi : i \u2208 s) (h2i : g i + h i \u2264 f i) (hgf : \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2264 f j)\n  (hhf : \u2200 j \u2208 s, j \u2260 i \u2192 h j \u2264 f j) (hg : \u2200 i \u2208 s, 0 \u2264 g i) (hh : \u2200 i \u2208 s, 0 \u2264 h i) :\n  \u220f i in s, g i + \u220f i in s, h i \u2264 \u220f i in s, f i :=\nbegin\n  simp_rw [prod_eq_mul_prod_diff_singleton hi],\n  refine le_trans _ (mul_le_mul_of_nonneg_right h2i _),\n  { rw [right_distrib],\n    apply add_le_add; apply mul_le_mul_of_nonneg_left; try { apply_assumption; assumption };\n      apply prod_le_prod; simp * { contextual := tt } },\n  { apply prod_nonneg, simp only [and_imp, mem_sdiff, mem_singleton],\n    intros j h1j h2j, exact le_trans (hg j h1j) (hgf j h1j h2j) }\nend\n\nend ordered_comm_semiring\n\nsection strict_ordered_comm_semiring\nvariables [strict_ordered_comm_semiring R] [nontrivial R] {f : \u03b9 \u2192 R} {s : finset \u03b9}\n\n/- This is also true for a ordered commutative multiplicative monoid with zero -/\nlemma prod_pos (h0 : \u2200 i \u2208 s, 0 < f i) : 0 < \u220f i in s, f i :=\nprod_induction f (\u03bb x, 0 < x) (\u03bb _ _ ha hb, mul_pos ha hb) zero_lt_one h0\n\nend strict_ordered_comm_semiring\n\nsection canonically_ordered_comm_semiring\n\nvariables [canonically_ordered_comm_semiring R] {f g h : \u03b9 \u2192 R} {s : finset \u03b9} {i : \u03b9}\n\n@[simp]\nlemma _root_.canonically_ordered_comm_semiring.multiset_prod_pos [nontrivial R] {m : multiset R} :\n  0 < m.prod \u2194 (\u2200 x \u2208 m, (0 : R) < x) :=\nbegin\n  induction m using quotient.induction_on,\n  rw [multiset.quot_mk_to_coe, multiset.coe_prod],\n  exact canonically_ordered_comm_semiring.list_prod_pos,\nend\n\n/-- Note that the name is to match `canonically_ordered_comm_semiring.mul_pos`. -/\n@[simp]\nlemma _root_.canonically_ordered_comm_semiring.prod_pos [nontrivial R] :\n  0 < \u220f i in s, f i \u2194 (\u2200 i \u2208 s, (0 : R) < f i) :=\ncanonically_ordered_comm_semiring.multiset_prod_pos.trans $ by simp\n\n/-- If `g, h \u2264 f` and `g i + h i \u2264 f i`, then the product of `f` over `s` is at least the\n  sum of the products of `g` and `h`. This is the version for `canonically_ordered_comm_semiring`.\n-/\nlemma prod_add_prod_le' (hi : i \u2208 s) (h2i : g i + h i \u2264 f i)\n  (hgf : \u2200 j \u2208 s, j \u2260 i \u2192 g j \u2264 f j) (hhf : \u2200 j \u2208 s, j \u2260 i \u2192 h j \u2264 f j) :\n  \u220f i in s, g i + \u220f i in s, h i \u2264 \u220f i in s, f i :=\nbegin\n  classical, simp_rw [prod_eq_mul_prod_diff_singleton hi],\n  refine le_trans _ (mul_le_mul_right' h2i _),\n  rw [right_distrib],\n  apply add_le_add; apply mul_le_mul_left'; apply prod_le_prod';\n  simp only [and_imp, mem_sdiff, mem_singleton]; intros; apply_assumption; assumption\nend\n\nend canonically_ordered_comm_semiring\n\nend finset\n\nnamespace fintype\n\nvariables [fintype \u03b9]\n\n@[to_additive sum_mono, mono]\nlemma prod_mono' [ordered_comm_monoid M] : monotone (\u03bb f : \u03b9 \u2192 M, \u220f i, f i) :=\n\u03bb f g hfg, finset.prod_le_prod' $ \u03bb x _, hfg x\n\nattribute [mono] sum_mono\n\n@[to_additive sum_strict_mono]\nlemma prod_strict_mono' [ordered_cancel_comm_monoid M] : strict_mono (\u03bb f : \u03b9 \u2192 M, \u220f x, f x) :=\n\u03bb f g hfg, let \u27e8hle, i, hlt\u27e9 := pi.lt_def.mp hfg in\n  finset.prod_lt_prod' (\u03bb i _, hle i) \u27e8i, finset.mem_univ i, hlt\u27e9\n\nend fintype\n\nnamespace with_top\nopen finset\n\n/-- A product of finite numbers is still finite -/\nlemma prod_lt_top [comm_monoid_with_zero R] [no_zero_divisors R] [nontrivial R] [decidable_eq R]\n  [has_lt R] {s : finset \u03b9} {f : \u03b9 \u2192 with_top R} (h : \u2200 i \u2208 s, f i \u2260 \u22a4) :\n  \u220f i in s, f i < \u22a4 :=\nprod_induction f (\u03bb a, a < \u22a4) (\u03bb a b h\u2081 h\u2082, mul_lt_top' h\u2081 h\u2082) (coe_lt_top 1) $\n  \u03bb a ha, with_top.lt_top_iff_ne_top.2 (h a ha)\n\n/-- A sum of numbers is infinite iff one of them is infinite -/\nlemma sum_eq_top_iff [add_comm_monoid M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M} :\n  \u2211 i in s, f i = \u22a4 \u2194 \u2203 i \u2208 s, f i = \u22a4 :=\nby induction s using finset.cons_induction; simp [*, or_and_distrib_right, exists_or_distrib]\n\n/-- A sum of finite numbers is still finite -/\nlemma sum_lt_top_iff [add_comm_monoid M] [has_lt M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M} :\n  \u2211 i in s, f i < \u22a4 \u2194 \u2200 i \u2208 s, f i < \u22a4 :=\nby simp only [with_top.lt_top_iff_ne_top, ne.def, sum_eq_top_iff, not_exists]\n\n/-- A sum of finite numbers is still finite -/\nlemma sum_lt_top [add_comm_monoid M] [has_lt M] {s : finset \u03b9} {f : \u03b9 \u2192 with_top M}\n  (h : \u2200 i \u2208 s, f i \u2260 \u22a4) : (\u2211 i in s, f i) < \u22a4 :=\nsum_lt_top_iff.2 $ \u03bb i hi, with_top.lt_top_iff_ne_top.2 (h i hi)\n\nend with_top\n\nsection absolute_value\n\nvariables {S : Type*}\n\nlemma absolute_value.sum_le [semiring R] [ordered_semiring S]\n  (abv : absolute_value R S) (s : finset \u03b9) (f : \u03b9 \u2192 R) :\n  abv (\u2211 i in s, f i) \u2264 \u2211 i in s, abv (f i) :=\nfinset.le_sum_of_subadditive abv (map_zero _) abv.add_le _ _\n\nlemma is_absolute_value.abv_sum [semiring R] [ordered_semiring S] (abv : R \u2192 S)\n  [is_absolute_value abv] (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u2211 i in s, f i) \u2264 \u2211 i in s, abv (f i) :=\n(is_absolute_value.to_absolute_value abv).sum_le _ _\n\nlemma absolute_value.map_prod [comm_semiring R] [nontrivial R] [linear_ordered_comm_ring S]\n  (abv : absolute_value R S) (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u220f i in s, f i) = \u220f i in s, abv (f i) :=\nabv.to_monoid_hom.map_prod f s\n\nlemma is_absolute_value.map_prod [comm_semiring R] [nontrivial R] [linear_ordered_comm_ring S]\n  (abv : R \u2192 S) [is_absolute_value abv] (f : \u03b9 \u2192 R) (s : finset \u03b9) :\n  abv (\u220f i in s, f i) = \u220f i in s, abv (f i) :=\n(is_absolute_value.to_absolute_value abv).map_prod _ _\n\nend absolute_value\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/big_operators/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7029133821302173}}
{"text": "-- Simple theorems\n\nimport algebra.group_power.ring\nimport analysis.special_functions.pow\nimport data.real.basic\nimport data.complex.basic\nimport measure_theory.integral.circle_integral\nimport tactic.linarith.frontend\nopen tactic.interactive (nlinarith)\nopen complex (abs has_zero)\nopen_locale nnreal\n\nnamespace simple\n\nlemma abs_sub_ge (a b : \u2102) : abs (a + b) \u2265 abs a - abs b := begin\n  let h := complex.abs_add (a + b) (-b),\n  simp at h,\n  linarith,\nend\n\nlemma abs_sub_ge' {a b : \u2102} : abs (a + b) \u2265 abs a - abs b := abs_sub_ge _ _\n\nlemma le_to_ge {X : Type} [linear_order X] {a b : X} (h : a \u2264 b) : b \u2265 a := h\nlemma ge_to_le {X : Type} [linear_order X] {a b : X} (h : a \u2265 b) : b \u2264 a := h\nlemma lt_to_gt {X : Type} [linear_order X] {a b : X} (h : a < b) : b > a := h\nlemma gt_to_lt {X : Type} [linear_order X] {a b : X} (h : a > b) : b < a := h\n\nlemma sq_bound (x : \u211d) : (1 + x)^2 \u2265 1 + 2*x := begin\n  have h : (1 + x)^2 = 1 + 2*x + x^2 := by ring,\n  nlinarith\nend\n\nlemma sq_increasing {x y : \u211d} (p : 0 \u2264 x) (h : x \u2264 y) : x^2 \u2264 y^2 := by nlinarith\nlemma mul_increasing {x y z : \u211d} (p : 0 \u2264 x) (h : y \u2264 z) : x * y \u2264 x * z := mul_le_mul_of_nonneg_left h p\nlemma nat_nonneg (n : \u2115) : 0 \u2264 (\u2191n : \u211d) := by simp\n\nlemma large_div_nat (a b : \u211d) (h : a > 0) : \u2203 n : \u2115, a * n \u2265 b := begin\n  existsi (nat.ceil (b / a)),\n  have e : a * (b / a) = b := calc a * (b / a) = b / a * a : by ring\n                            ... = b : div_mul_cancel b (ne_of_gt h),\n  nth_rewrite 1 \u2190e,\n  refine mul_le_mul_of_nonneg_left _ _,\n  exact nat.le_ceil _,\n  apply le_of_lt,\n  assumption\nend\n\nlemma gap {x y : \u211d} (h : x < y) : \u2203 s : \u211d, s > 0 \u2227 x + s \u2264 y := begin\n  have sp := sub_lt_sub_right h x,\n  set s := y - x with q,\n  have xx : x - x = 0 := by ring,\n  rw [\u2190q, xx] at sp,\n  existsi s,\n  constructor,\n  assumption,\n  linarith\nend\n\nlemma not_all {A : Type} {p : A \u2192 Prop} (_ : \u00ac\u2200 x : A, p x) : \u2203 x : A, \u00ac(p x) := by finish\n\nlemma not_false (p : Prop) : \u00acp \u2194 (p \u2192 false) := by finish\nlemma not_lt {x y : \u211d} : (x < y \u2192 false) \u2194 (x \u2265 y) := begin\n  rw (not_false (x < y)).symm,\n  finish\nend\n\nlemma coe_increasing {a b : \u2115} (h : a \u2264 b) : (a : \u211d) \u2264 (b : \u211d) := nat.cast_le.mpr h\nlemma coe_pow_ge_one {n : \u2115} : 1 \u2264 (2^n : \u211d) := begin\n  induction n with n,\n  norm_num,\n  transitivity (2^n : \u211d),\n  assumption,\n  have h : 2^n.succ = 2*2^n := pow_succ _ _,\n  have he : (2^n.succ : \u211d) = (2*2^n : \u211d) := rfl,\n  rw he, linarith\nend\n\nlemma real_nnreal_ennreal (r : \u211d) : ennreal.of_real r = \u2191r.to_nnreal := rfl\nlemma nnreal_ennreal_coe_lt {a : ennreal} {b : nnreal} (h : a < b) : a.to_nnreal < b := begin\n  rw \u2190with_top.coe_lt_coe,\n  calc \u2191(a.to_nnreal) \u2264 a : ennreal.coe_to_nnreal_le_self\n  ... < \u2191b : h\nend\nlemma to_nnreal_pos {a b c : ennreal} (ab : a < b) (bc : b < c) : 0 < b.to_nnreal := begin\n  apply ennreal.to_nnreal_pos,\n  refine ne_of_gt _,\n  calc 0 \u2264 a : by simp\n  ... < b : ab,\n  refine ne_of_lt _,\n  calc b < c : bc\n  ... \u2264 \u22a4 : by simp\nend\n\nlemma inv_nonneg {x : \u211d} (h : x \u2265 0) : x\u207b\u00b9 \u2265 0 := inv_nonneg.mpr h\n\nlemma pow_inv (x : \u211d) (n : \u2115) : (x^n)\u207b\u00b9 = x\u207b\u00b9^n := begin by_cases x = 0, simp, field_simp end\n\nlemma div_pow_inv (x y : \u211d) (n : \u2115) : x / y^n = x * y\u207b\u00b9^n := begin\n  calc x / y^n = (y^n)\u207b\u00b9 * x : (inv_mul_eq_div (y^n) x).symm\n  ... = y\u207b\u00b9^n * x : by rw (pow_inv y n)\n  ... = x * y\u207b\u00b9^n : by ring\nend\n\nlemma abs_sub (z w : \u2102) : abs (z - w) \u2264 abs z + abs w := begin\n  set n := -w,\n  have h0 : z - w = z + n := rfl,\n  have h1 : abs w = abs n := (complex.abs_neg w).symm,\n  rw [h0, h1], exact complex.abs_add z n\nend\n\nlemma abs_sub' {z w : \u2102} : abs (z - w) \u2264 abs z + abs w := abs_sub z w\n\nlemma abs_le_zero {z : \u2102} (h : abs z \u2264 0) : z = 0 :=\n  complex.abs_eq_zero.mp (le_antisymm (complex.abs_nonneg z) h).symm\n\nlemma sqr_pos {x : \u211d} (h : x > 0) : x^2 > 0 := pow_pos h 2\n\nlemma zero_lt_bit1 {A : Type} [linear_ordered_semiring A] {a : A} : 0 < a \u2192 0 < bit1 a := begin\n  rw [bit1, bit0], intro, apply add_pos, apply add_pos, assumption, assumption, norm_num\nend\n\nlemma zero_le_bit1 {A : Type} [linear_ordered_semiring A] {a : A} : 0 \u2264 a \u2192 0 \u2264 bit1 a := begin\n  rw [bit1, bit0], intro, apply add_nonneg, apply add_nonneg, assumption, assumption, norm_num\nend\n\nlemma ring_sub_pos {A : Type} [linear_ordered_ring A] {a b : A} (h : a < b) : 0 < b - a := begin\n  simp, assumption\nend\n\nlemma ring_sub_le_sub {A : Type} [linear_ordered_ring A] {a b c d : A}\n    (ac : a \u2264 c) (db : d \u2264 b): a - b \u2264 c - d := sub_le_sub ac db\n\nlemma ring_add_le_add {A : Type} [linear_ordered_ring A] {a b c d : A}\n    (ac : a \u2264 c) (bd : b \u2264 d) : a + b \u2264 c + d := add_le_add ac bd\n\nlemma ring_add_nonneg {A : Type} [linear_ordered_ring A] {a b : A}\n    (ha : 0 \u2264 a) (hb : 0 \u2264 b) : 0 \u2264 a + b := add_nonneg ha hb\n\nlemma ring_sub_nonneg {A : Type} [linear_ordered_ring A] {a b : A} (h : b \u2264 a) : 0 \u2264 a - b := sub_nonneg.mpr h\n\nlemma ring_add_lt_add_left {A : Type} [linear_ordered_ring A] {a b c : A}\n    (h : b < c) : a + b < a + c := add_lt_add_left h a\n\nlemma ring_add_lt_add_right {A : Type} [linear_ordered_ring A] {a b c : A}\n    (h : b < c) : b + a < c + a := add_lt_add_right h a\n\ntheorem pow_pos' {A : Type} [ordered_semiring A] {a : A} {n : \u2115} (h : 0 < a) : 0 < a^n := pow_pos h _\ntheorem pow_nonneg' {A : Type} [ordered_semiring A] {a : A} {n : \u2115} (h : 0 \u2264 a) : 0 \u2264 a^n := pow_nonneg h _\n\nlemma finset_complex_abs_sum_le (N : finset \u2115) (f : \u2115 \u2192 \u2102)\n    : abs (N.sum (\u03bb n, f n)) \u2264 N.sum (\u03bb n, abs (f n)) :=\nbegin\n  induction N using finset.induction with n N Nn h, {\n    simp\n  }, {\n    rw finset.sum_insert Nn,\n    rw finset.sum_insert Nn,\n    transitivity abs (f n) + abs (N.sum (\u03bb n, f n)), {\n      exact complex.abs_add _ _\n    }, {\n      apply add_le_add_left, assumption\n    }\n  }\nend\n\nlemma div_self {K : Type} [division_ring K] {a : K} (h : a \u2260 0) : a / a = 1 :=\n  by rw [div_eq_mul_inv, mul_inv_cancel h]\n\nlemma div_cancel_le {x : \u211d} : x * x\u207b\u00b9 \u2264 1 := begin\n  rw \u2190div_eq_mul_inv,\n  exact div_self_le_one x,\nend\n\nlemma ne_iff_not_eq {T : Type} {a b : T} : \u00ac(a = b) \u2194 a \u2260 b := begin\n  have q := eq_or_ne a b,\n  finish\nend\n\nlemma div_le_div_right {a b c : \u211d} : c \u2265 0 \u2192 a \u2264 b \u2192 a / c \u2264 b / c := begin\n  intros c0 ab,\n  by_cases cnz : c = 0, { rw cnz, simp },\n  rw ne_iff_not_eq at cnz,\n  refine (div_le_div_right _).mpr ab,\n  exact lt_of_le_of_ne c0 cnz.symm\nend\n\nlemma subset_union_sdiff (A B : finset \u2115) : B \u2286 A \u222a B \\ A := begin\n  rw finset.subset_iff, intros x Bx,\n  rw [finset.mem_union, finset.mem_sdiff],\n  finish\nend\n\nlemma le_add_nonneg_right {a b : \u211d} : 0 \u2264 b \u2192 a \u2264 a + b := le_add_of_le_of_nonneg (le_refl a)\nlemma le_add_nonneg_left {a b : \u211d} : 0 \u2264 b \u2192 a \u2264 b + a := begin\n  rw add_comm, exact le_add_nonneg_right\nend\n\nlemma div_le_one {a b : \u211d} : 0 \u2264 b \u2192 a \u2264 b \u2192 a / b \u2264 1 := begin\n  intros b0 ab,\n  by_cases z : b = 0, {\n    rw z, simp\n  }, {\n    refine (div_le_one _).mpr _,\n    have z : b \u2260 0 := z,\n    exact lt_of_le_of_ne b0 z.symm,\n    assumption\n  }\nend\n\nlemma real_abs_nonneg {a : \u211d} : |a| \u2265 0 := abs_nonneg _\n\nlemma nat_real_coe_le_coe {n m : \u2115} : n \u2264 m \u2192 (n : \u211d) \u2264 (m : \u211d) := begin\n  exact nat.cast_le.mpr\nend\n\nlemma pow_div {z : \u2102} {n : \u2115} (z0 : z \u2260 0) : z ^ (n+1) / z = z ^ n := begin\n  rw pow_succ,\n  calc z * z^n / z = z / z * z^n : (div_mul_eq_mul_div _ _ _).symm\n  ... = 1 * z^n : by rw div_self z0\n  ... = z^n : by ring\nend\n\n-- (z ^ a) ^ n = z ^ (a * n)\nlemma pow_mul_nat {z w : \u2102} {n : \u2115} : (z ^ w) ^ n = z ^ (w * n) := begin\n  by_cases z0 : z = 0, {\n    rw z0,\n    by_cases w0 : w = 0, { rw w0, simp },\n    by_cases n0 : n = 0, { rw n0, simp },\n    have wn0 : w * n \u2260 0 := mul_ne_zero w0 (nat.cast_ne_zero.mpr n0),\n    rw complex.zero_cpow w0,\n    rw complex.zero_cpow wn0,\n    exact zero_pow' n n0\n  },\n  rw complex.cpow_def_of_ne_zero z0,\n  rw complex.cpow_def_of_ne_zero z0,\n  rw \u2190complex.exp_nat_mul,\n  ring_nf\nend\n\nlemma continuous_on.circle_map (c : \u2102) (r : \u211d) (s : set \u211d) : continuous_on (circle_map c r) s :=\n  continuous.continuous_on (continuous_circle_map _ _)\n\n-- Version of continuous_on.comp for f \u2218 g that puts everything about g after :,\n-- to behave well under apply_rules.\nlemma continuous_on.comp_left {B C : Type} [topological_space B] [topological_space C]\n    {s : set B} {f : B \u2192 C} (fc : continuous_on f s)\n    : \u2200 (A : Type) [tA : topological_space A] (t : set A) (g : A \u2192 B),\n      @continuous_on A B tA _ g t \u2192 set.maps_to g t s \u2192 @continuous_on A C tA _ (\u03bb a, f (g a)) t :=\n  \u03bb A tA t g gc m, @continuous_on.comp _ _ _ tA _ _ _ _ _ _ fc gc m\n\nlemma continuous_complex_abs : continuous complex.abs := begin\n  rw metric.continuous_iff, intros z e ep,\n  existsi [e, ep], intros w wz,\n  rw real.dist_eq,\n  rw complex.dist_eq at wz,\n  have h := abs_norm_sub_norm_le w z,\n  simp at h,\n  exact lt_of_le_of_lt h wz,\nend\n\nend simple", "meta": {"author": "girving", "repo": "ray", "sha": "e0c501756e067711e2d3667d4b1d18045d83a313", "save_path": "github-repos/lean/girving-ray", "path": "github-repos/lean/girving-ray/ray-e0c501756e067711e2d3667d4b1d18045d83a313/src/simple.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7028391599261312}}
{"text": "-- Producto_de_dos_binomios.lean\n-- Producto de dos binomios\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 25-agosto-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si a, b, c y d son n\u00fameros reales, entonces\n--    (a + b) * (c + d) = a * c + a * d + b * c + b * d\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b c d : \u211d\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\ncalc\n  (a + b) * (c + d)\n      = a * (c + d) + b * (c + d)       : by rw add_mul\n  ... = a * c + a * d + b * (c + d)     : by rw mul_add\n  ... = a * c + a * d + (b * c + b * d) : by rw mul_add\n  ... = a * c + a * d + b * c + b * d   : by rw \u2190add_assoc\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\ncalc\n  (a + b) * (c + d)\n      = a * (c + d) + b * (c + d)       : by ring\n  ... = a * c + a * d + b * (c + d)     : by ring\n  ... = a * c + a * d + (b * c + b * d) : by ring\n  ... = a * c + a * d + b * c + b * d   : by ring\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nby ring\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nbegin\n   rw add_mul,\n   rw mul_add,\n   rw mul_add,\n   rw \u2190 add_assoc,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nby rw [add_mul, mul_add, mul_add, \u2190add_assoc]\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Producto_de_dos_binomios.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7028391531654863}}
{"text": "-- Diferencia_de_diferencia_de_conjuntos.lean\n-- Diferencia de diferencia de conjuntos.\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 23-abril-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    (s \\ t) \\ u \u2286 s \\ (t \u222a u)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t u : set \u03b1\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  intros x hx,\n  cases hx with hxst hxnu,\n  cases hxst with hxs hxnt,\n  split,\n  { exact hxs, },\n  { dsimp,\n    by_contradiction hxtu,\n    cases hxtu with hxt hxu,\n    { apply hxnt,\n      exact hxt, },\n    { apply hxnu,\n      exact hxu, }},\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8hxs, hxnt\u27e9, hxnu\u27e9,\n  split,\n  { exact hxs, },\n  { by_contradiction hxtu,\n    cases hxtu with hxt hxu,\n    { exact hxnt hxt, },\n    { exact hxnu hxu, }},\nend\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8hxs, hxnt\u27e9, hxnu\u27e9,\n  use hxs,\n  rintros (hxt | hxu),\n  { contradiction, },\n  { contradiction, },\nend\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x \u27e8\u27e8hxs, hxnt\u27e9, hxnu\u27e9,\n  use hxs,\n  rintros (hxt | hxu); contradiction,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x hx,\n  simp at *,\n  finish,\nend\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nbegin\n  rintros x hx,\n  finish,\nend\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nby rw diff_diff\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nexample : (s \\ t) \\ u \u2286 s \\ (t \u222a u) :=\nby tidy\n", "meta": {"author": "jaalonso", "repo": "Razonando-con-Lean", "sha": "d6e3fe9e384bdb6d8cc6ce4383d86c72bbcc154c", "save_path": "github-repos/lean/jaalonso-Razonando-con-Lean", "path": "github-repos/lean/jaalonso-Razonando-con-Lean/Razonando-con-Lean-d6e3fe9e384bdb6d8cc6ce4383d86c72bbcc154c/src/Diferencia_de_diferencia_de_conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7028391521365343}}
{"text": "\nnamespace test\n\nconstant and : Prop \u2192 Prop \u2192 Prop\nconstant or : Prop \u2192 Prop \u2192 Prop\nconstant not : Prop \u2192 Prop\nconstant implies : Prop \u2192 Prop \u2192 Prop\n\nconstant Proof : Prop -> Type\nconstant and_comm : \u03a0 p q : Prop,\n  Proof (implies (and p q) (and q p))\n\nvariables p q : Prop\n#check and_comm p q\n\n\nconstant modus_ponens :\n  \u03a0 p q : Prop, Proof (implies p q) \u2192 Proof p \u2192 Proof q\n\nconstant implies_intro :\n  \u03a0 p q : Prop, (Proof p \u2192 Proof q) \u2192 Proof (implies p q)\n\nend test\n\nnamespace test2\n\nconstants p q : Prop\n\n-- theorem and lemma are identical, and are\n-- equivalent to definitions\ntheorem t1 : p \u2192 q \u2192 p := \u03bb hp : p, \u03bb hq : q, hp\ntheorem t2 : p \u2192 q \u2192 p :=\n  assume hp : p,\n  assume hq : q,\n  show p, from hp\ntheorem t3 (hp : p) (hq : q) : p := hp\n\n-- axiom is equivalent to constant\naxiom hp : p\ntheorem t4 : q \u2192 p := t1 hp\n\n-- \u2200 is equivalent to \u03a0\ntheorem t5 (p q : Prop) (hp : p) (hq : q) : p := hp\ntheorem t6 : \u2200 (p q : Prop), p \u2192 q \u2192 p :=\n  \u03bb (p q : Prop) (hp : p) (hq : q), hp\n\n-- variables are auto-generalized in theorems\nvariables p q : Prop\ntheorem t7 : p \u2192 q \u2192 p := \u03bb (hp : p) (hq : q), hp\n\n-- the assumption that p holds\nvariable hp : p\ntheorem t8 : q \u2192 p := \u03bb (hq : q), hp\n\nvariables r s : Prop\n\ntheorem t9 (h\u2081 : q \u2192 r) (h\u2082 : p \u2192 q) : p \u2192 r :=\n  assume h\u2083 : p,\n  show r, from h\u2081 (h\u2082 h\u2083)\n\n\n-- example is a theorem without naming or\n-- storing in the permanent context\nexample (hp : p) (hq : q) : p \u2227 q := and.intro hp hq\n\n#check assume (hp : p) (hq : q), and.intro hp hq\n\n-- and elimination\nexample (h : p \u2227 q) : p := and.elim_left h\nexample (h : p \u2227 q) : q := and.elim_right h\n\n-- and is isomorphic to \u00d7 (product type)\nexample (hpq : p \u2227 q) : q \u2227 p :=\n  and.intro (and.right hpq) (and.left hpq)\n\n\n-- or introduction\nexample (hp : p) : p \u2228 q := or.intro_left q hp\nexample (hq : q) : p \u2228 q := or.intro_right p hq\n\nexample (h : p \u2228 q) : q \u2228 p :=\n  or.elim h\n    (\u03bb hp : p,\n      show q \u2228 p, from or.intro_right q hp)\n    (\u03bb hq : q,\n      show q \u2228 p, from or.intro_left p hq)\n\n-- or.inr is shorthand for or.intro_right _\n-- or.inl is shorthand for or.intro_left _\nexample (h : p \u2228 q) : q \u2228 p :=\n  or.elim h\n    (\u03bb hp : p,\n      show q \u2228 p, from or.inr hp)\n    (\u03bb hq : q,\n      show q \u2228 p, from or.inl hq)\n\n-- negation is defined as \u00acp = p \u2192 false\nexample (hpq : p \u2192 q) (hnq : \u00acq) : \u00acp :=\n  assume hp : p,\n  show false, from hnq (hpq hp)\n\nexample (hp : p) (hnp : \u00acp) : q :=\n  false.elim (hnp hp)\n\nexample (hp : p) (hnp : \u00acp) : q := absurd hp hnp\n\n-- false only has an elimination rule, false \u2192 anything\n-- true only has an introduction rule, true.intro : true\n\ntheorem and_swap : p \u2227 q \u2194 q \u2227 p :=\n  iff.intro\n    (assume h : p \u2227 q,\n      show q \u2227 p, from and.intro h.right h.left)\n    (assume h : q \u2227 p,\n      show p \u2227 q, from and.intro h.right h.left)\n\ndefinition and_swap' : iff (and p q) (and q p) :=\n  iff.intro\n    (\u03bb h : and p q, and.intro h.right h.left)\n    (\u03bb h : and q p, and.intro h.right h.left)\n\ntheorem and_swap'' : p \u2227 q \u2194 q \u2227 p :=\n  \u27e8 \u03bb h, \u27e8h.right, h.left\u27e9, \u03bb h, \u27e8h.right, h.left\u27e9 \u27e9\n\nsection\nexample (h : p \u2227 q) : q \u2227 p := iff.mpr (and_swap q p) h\nexample : p \u2227 q \u2192 q \u2227 p := \u03bb h : p \u2227 q, iff.mpr (and_swap q p) h\n\nexample (h : p \u2227 q) : q \u2227 p :=\n  have hp : p, from and.left h,\n  have hq : q, from and.right h,\n  show q \u2227 p, from and.intro hq hp\n\nexample : p \u2227 q \u2192 q \u2227 p :=\n  \u03bb h : p \u2227 q,\n    (\u03bb hp : p, \u03bb hq : q, and.intro hq hp)\n    (and.left h) (and.right h)\n\n-- can reason backwards with suffices, i.e. if we show q,\n-- then we have proved it, and next we show q\nexample (h : p \u2227 q) : q \u2227 p :=\n  have hp : p, from h.left,\n  suffices hq : q, from and.intro hq hp,\n  show q, from h.right\n\nend\n\n\nsection\nopen classical\n\n-- p \u2228 \u00acp\n#check em p\n\ntheorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\n  or.elim (em p)\n    (assume hp : p, hp)\n    (assume hnp : \u00acp, absurd hnp h)\n\ntheorem dne' {p : Prop} (h : ((p \u2192 false) \u2192 false)) : p :=\n  or.elim (em p)\n    (\u03bb hp : p, hp)\n    (\u03bb hnp : p \u2192 false, absurd hnp h)\n\n/-\n - Assume \u00ac(p \u2228 \u00acp), then \u00acp, since p \u2192 (p \u2228 \u00acp) \u2192 false.\n - However, \u00acp \u2192 (p \u2228 \u00acp) \u2192 false, so we have a contradiction.\n - \u2234 dne \u00ac\u00ac(p \u2228 \u00acp)\n -/\ntheorem em' {p : Prop} : p \u2228 \u00acp :=\n  dne (\n    assume h : \u00ac(p \u2228 \u00acp),\n    have hnp : \u00acp, from (\n      assume hp : p,\n      show false, from h (or.inl hp)\n    ),\n    show false, from h (or.inr hnp))\n\ntheorem em'' {p : Prop} : p \u2228 \u00acp :=\n  dne (\n    \u03bb h : (p \u2228 \u00acp) \u2192 false,\n      h (or.inr (\u03bb hp : p, h (or.inl hp)))\n  )\n\ndef double (x : \u2115) : \u2115 := x + x\ndef double' : \u2115 \u2192 \u2115 := \u03bb (x : \u2115), x + x\n\nexample (h : \u00ac\u00acp) : p :=\n  by_cases\n    (\u03bb h1 : p, h1)\n    (\u03bb h2 : \u00acp, absurd h2 h)\n\nexample (h : \u00ac\u00acp) : p :=\n  by_contradiction\n    (\u03bb hnp : \u00acp, absurd hnp h)\n\nexample (h : \u00ac(p \u2227 q)) : \u00acp \u2228 \u00acq :=\n  or.elim (em p)\n    (\u03bb hp : p, or.inr (\u03bb hq : q, h (and.intro hp hq)))\n    (\u03bb hnp : \u00acp, or.inl hnp)\n\nend\n\nsection\n\nexample {p q r : Prop} : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  iff.intro\n    (\u03bb h : p \u2227 (q \u2228 r),\n      or.elim h.elim_right\n        (\u03bb hq : q, or.inl (and.intro h.elim_left hq))\n        (\u03bb hr : r, or.inr (and.intro h.elim_left hr)))\n    (\u03bb h : (p \u2227 q) \u2228 (p \u2227 r),\n      or.elim h\n        (\u03bb hpq : p \u2227 q, and.intro hpq.left (or.inl hpq.right))\n        (\u03bb hpr : p \u2227 r, and.intro hpr.left (or.inr hpr.right)))\n\nexample : \u00ac(p \u2227 \u00acq) \u2192 (p \u2192 q) :=\n  assume h : \u00ac(p \u2227 \u00acq),\n  assume hp : p,\n  show q, from\n    or.elim (classical.em q)\n      (assume hq : q, hq)\n      (assume hnq : \u00acq, absurd (and.intro hp hnq) h)\n\nend\n\nsection exercises\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p :=\n  iff.intro\n    (assume hpq : p \u2227 q, and.intro hpq.right hpq.left)\n    (assume hqp : q \u2227 p, and.intro hqp.right hqp.left)\n\nexample : p \u2228 q \u2194 q \u2228 p :=\n  iff.intro\n    (assume hpq : p \u2228 q, or.elim hpq\n      (assume hp : p, or.inr hp)\n      (assume hq : q, or.inl hq))\n    (assume hqp : q \u2228 p, or.elim hqp\n      (assume hq : q, or.inr hq)\n      (assume hp : p, or.inl hp))\n\n\n-- associativity of \u2227 and \u2228\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n  iff.intro\n    (assume h : (p \u2227 q) \u2227 r,\n      and.intro h.left.left (and.intro h.left.right h.right))\n    (assume h : p \u2227 (q \u2227 r),\n      and.intro (and.intro h.left h.right.left) h.right.right)\n\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n  iff.intro\n    (assume h : (p \u2228 q) \u2228 r,\n      or.elim h\n        (assume hpq : p \u2228 q,\n          or.elim hpq\n            (assume hp : p, or.inl hp)\n            (assume hq : q, or.inr (or.inl hq)))\n        (assume hr : r, or.inr (or.inr hr)))\n    (assume h : p \u2228 (q \u2228 r),\n      or.elim h\n        (assume hp : p, or.inl (or.inl hp))\n        (assume hqr : q \u2228 r,\n          or.elim hqr\n            (assume hq : q, or.inl (or.inr hq))\n            (assume hr : r, or.inr hr)))\n\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := sorry\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := sorry\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := sorry\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := sorry\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := sorry\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := sorry\nexample : \u00ac(p \u2227 \u00acp) := sorry\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := sorry\nexample : \u00acp \u2192 (p \u2192 q) := sorry\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := sorry\nexample : p \u2228 false \u2194 p := sorry\nexample : p \u2227 false \u2194 false := sorry\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := sorry\n\nexample {p : Prop} : \u00ac(p \u2194 \u00acp) :=\n  \u03bb h : p \u2194 \u00acp, or.elim (classical.em p)\n    (assume hp : p, absurd hp ((iff.mp h) hp))\n    (assume hnp : \u00acp, absurd ((iff.mpr h) hnp) hnp)\n\nexample {p : Prop} : \u00ac(p \u2194 \u00acp) :=\n  assume h : p \u2194 \u00acp,\n  have hnp : \u00acp, from\n    (assume hp : p,\n      absurd hp (iff.mp h hp)),\n  have hp : p, from\n    (iff.mpr h hnp),\n  show false, from hnp hp\n\nexample {p : Prop} : \u00ac(p \u2194 \u00acp) :=\n  \u03bb h : p \u2194 \u00acp,\n  have hnp : \u00acp, from\n    (\u03bb hp : p, absurd hp (iff.mp h hp)),\n  hnp (iff.mpr h hnp)\n\nend exercises\n\nend test2\n", "meta": {"author": "ClaytonKnittel", "repo": "lean-test", "sha": "efa1804f65db49f5be4f8b6b64330ac705f76bc0", "save_path": "github-repos/lean/ClaytonKnittel-lean-test", "path": "github-repos/lean/ClaytonKnittel-lean-test/lean-test-efa1804f65db49f5be4f8b6b64330ac705f76bc0/src/practice3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7028391512549221}}
{"text": "import Mathlib.Data.Int.Basic\nimport Mathlib.Data.Nat.Prime\nimport Mathlib.Tactic.LibrarySearch\nimport Mathlib.Tactic.Linarith\nimport Aesop\nimport Mathlib.Data.Set.Basic\n\n/-\n\nLean is a language that we will be using in CS22 this year.\n\nIf you're in this class, you've most likely used a programming language before.\nLean is a programming language too. But we'll be using it for a different reason:\nLean lets us state *propositions*, write *proofs* of these propositions, and *check*\nautomatically that these proofs are correct.\n\nSome basic Lean syntax:\n\n* Block comments, like this one, are written as /- ... -/.\n* Line comments begin with -- \n* If a file imports other files, this appears at the very top of the file.\n  You shouldn't change these imports!\n\n**Definition**. A *proposition* is a statement with a truth value.\nThat is, it is a statement that could be either true or false.\n\n\"Lean is a language\" is a proposition. \"Lean is not a language\" is a proposition.\n\"1 + 1 = 2\" is a proposition, as is \"1 + 1 = 3\".\nBut \"Lean\" is not a proposition, nor is \"1 + 1\", nor is \"is Lean a language?\".\n\n-/\n\n#check Prop \n#check \u2124\n\n/-\n\nLean uses the shorthand `Prop` for proposition.\nThe `#check` command asks Lean to tell us \"what kind of thing\" something is.\n(This will be very useful for us!)\nLean tells us that `Prop` is a Type, that is, a \"kind of thing\" -- not very enlightening!\n\nBut what if we try some of our examples from above?\n\n-/\n\n#check 1 + 1 = 2\n#check 1 + 1 = 3\n\n#check True \n#check False \n\n\n/-\n\nIn normal math, it's common for us to write things like \n\"let p, q, and r be propositions\" or \"let x and y be integers\".\n\nIn Lean, we write:\n\n-/\n\nvariable (p q r : Prop)\n\n#check p \n#check p \u2227 q \n#check p \u2227 q \u2192 r \n#check p \u2228 q \u2228 p \u2227 r \u2227 \u00ac (p \u2227 q \u2227 r) \n\n/-\n\nA few things to note here.\n\n* In the third `#check` above, if you hover over the output in the infoview,\n  you can see how this formula is parenthesized!\n* Those unicode symbols are input using \\ . To write the third line I typed\n  `p \\and q \\to r`. But there are lots of variants. \n  They usually match the LaTeX command.\n\n  * `\u2227`: and, wedge\n  * `\u2228`: or, vee \n  * `\u00ac`: not, neg\n  * `\u2192`: to, imp, rightarrow \n  * `\u2194`: iff\n  * `\u2115`: N, nat \n  * `\u2124`: Z, int\n  * `\u2200`: all, forall\n  * `\u2203`: ex, exist\n  * `\u2223` (divides): | (note, you need to type `\\|`, this isn't the normal pipe character)\n\n\nYou may have guessed from the list, Lean lets us write first-order propositions\n(i.e. with quantifiers). The syntax here looks like:\n\n-/\n\n#check \u2200 x : \u2115, \u2203 y : \u2115, x < y \u2227 1 = 1\n#check \u2200 x : \u2115, \u2203 y : \u2115, Prime x \u2227 x \u2223 y\n\n\n/-\n\nTry it out yourself: write some propositions.\nIf you want to use things like `Prime`, you can try to guess with\nauto-complete: write `#check Pr` and hit ctrl-space.\n\n-/\n\n#check Prime\n\ndef f (x : \u2115) : \u2115 := x + 2\n\n\n/-\n\nThe real magic of Lean is that we can *prove* these propositions.\nFor today we'll stick mostly to basic logic.\n\nThere is an array of *tactics* which represent individual proof steps.\nTo write a proof, we state a theorem, and then write a sequence of tactics.\nThe tactics manipulate the *proof state* by changing our *hypotheses* and *goals*.\n\n-/\n\ntheorem my_first_theorem : p \u2227 q \u2192 q \u2227 p := by \n  intro hpq               -- Assume we know `p \u2227 q`.\n  cases' hpq with hp hq   -- This means that we know `p` and we know `q`.\n  apply And.intro         -- In order to prove `q \u2227 p`, we must prove `q` and then prove `p`.\n  . exact hq              -- We can prove `q`, since we know `q`!\n  . exact hp              -- And we can prove `p`, since we know `p`.\n\ntheorem false_context : 1 = 2 \u2192 1 = 2 := by\n  intro h12 \n  exact h12\n\n/-\nSome notes here:\n\n* `intro`, `cases'`, `apply`, `exact` are *tactics*.\n* At each line in the proof we have 1 or more *goals*.\n* In each goal, there are 0 or more *hypotheses*.\n* The distinction here: hypotheses are what we know, \n  and the goal is what we are trying to show.\n* Some tactics take arguments. These can be fresh names (`intro hpq`),\n  or names of hypotheses (`exact hq`), or names of rules (`apply And.intro`).\n* When we applied a tactic that left us with multiple goals,\n  I tried to solve each one individually, indenting with `.` \n\nHere are some useful tactics:\n\n* `intro`: when our goal is of the form `_ \u2192 _`,\n  `intro h` will move the left hand side into a hypothesis,\n  like saying \"Assume _\".\n  When our goal is `\u2200 _, _`, `intro x` will create a new variable named `x`.\n\n* `cases'`: note the '. If `h` is a hypothesis proving an `and`,\n  `cases' h` will split it into its components.\n  If `h` is a hypothesis proving an `or`, `cases' h` will set up a\n  proof by cases with two goals.\n  If `h` is a hypothesis proving an `exists`, `cases' h` will find a witness.\n  Use the syntax `with` to name the new hypotheses. \n  In general, `cases'` is something we do to *hypotheses* only,\n  to \"extract\" information from them.\n\n* `apply`: uses a rule from the library, or from your context.\n  If a rule `r` says \"to prove `b`, it suffices to prove `a`\"\n  and your goal is to prove `b`, then\n  `apply r` will change your goal to proving `a`.\n\n* `exact`: when a hypothesis `h` matches the goal exactly, \n  `exact h` finishes that part of the proof.\n\n* `use`: when the goal is `\u2203 x, P(x)`,\n  `use z` will change the goal to `P(z)`. \n  Essentially, this is providing a *witness* to prove the existential.\n\n* `contradiction`: if we have hypotheses `p` and `\u00ac p`, we can prove anything!\n\n* `linarith`: does \"easy\" arithmetic to prove inequalities and equalities.\n\nTry out a few examples. Some useful rules from the library:\n\n-/\n\n#check Or.inl -- to prove `a \u2228 b`, it suffices to prove `a`.\n#check Or.inr -- to prove `a \u2228 b`, it suffices to prove `b`.\n\ntheorem flip_ors : p \u2228 q \u2192 q \u2228 p := by\n  sorry\n\ntheorem from_above : \u2200 x : \u2115, \u2203 y : \u2115, x < y := by \n  sorry\n\ntheorem other_order : \u2203 x : \u2115, \u2200 y : \u2115, x \u2264 y := by \n  sorry\n\ntheorem two_imp \n  (h1 : p \u2192 q) (h2 : q \u2192 \u00ac r) : r \u2192 \u00ac p := by\n  sorry\n  \n\n/- together: -/\n\ntheorem quantifier_switch (P : \u2115 \u2192 Prop) : \n  (\u00ac \u2203 x, P x) \u2192 (\u2200 x, \u00ac P x) := by\n  sorry\n\n\n/- Some other cool things we can do: induction!\n\nNote: `n \u2223 m` is defined to be `\u2203 k, n * k = m`. -/\n\n\n\nlemma div_by_5 : \u2200 n : \u2115, 5 \u2223 11^n - 6 := by\n  intro n \n  induction' n with k ih \n  . simp \n  . cases' ih with w hw\n    have : 11 ^ k = 5*w + 6 \n    . sorry\n    simp [Nat.pow_succ, this, add_mul]\n    use w*11\n    ring\n\n\nsection \nvariable (P : \u2115 \u2192 Prop)\n\nexample : \u2200 n : \u2115, P n := by \n  intro n \n  induction' n with k ih\n\nexample : \u2200 n : \u2115, P n := by \n  intro n \n  induction' n using Nat.strong_induction_on with k ih \n\nexample : \u2200 n : \u2115, P n := by \n  intro n \n  induction' n using Nat.two_step_induction with k ih1 ih2 \n  \n\n\nend \n\n/- sets! -/\n\ntheorem sets_eq (s t u : Set \u2115) : (s \u222a t) \u2229 u = (s \u2229 u) \u222a (t \u2229 u) := by \n  ext x\n  constructor\n\n#check \u2115 ", "meta": {"author": "robertylewis", "repo": "leanclass", "sha": "f609276675431388632d46619581bdb7c557be50", "save_path": "github-repos/lean/robertylewis-leanclass", "path": "github-repos/lean/robertylewis-leanclass/leanclass-f609276675431388632d46619581bdb7c557be50/BrownCs22/Demos/01-intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7028391465521812}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n-/\nimport analysis.complex.basic\nimport data.complex.exponential\n\n/-!\n# Complex and real exponential\n\nIn this file we prove continuity of `complex.exp` and `real.exp`. We also prove a few facts about\nlimits of `real.exp` at infinity.\n\n## Tags\n\nexp\n-/\n\nnoncomputable theory\n\nopen finset filter metric asymptotics set function\nopen_locale classical topological_space\n\nnamespace complex\n\nvariables {z y x : \u211d}\n\nlemma exp_bound_sq (x z : \u2102) (hz : \u2225z\u2225 \u2264 1) :\n  \u2225exp (x + z) - exp x - z \u2022 exp x\u2225 \u2264 \u2225exp x\u2225 * \u2225z\u2225 ^ 2 :=\ncalc \u2225exp (x + z) - exp x - z * exp x\u2225\n    = \u2225exp x * (exp z - 1 - z)\u2225 : by { congr, rw [exp_add], ring }\n... = \u2225exp x\u2225 * \u2225exp z - 1 - z\u2225 : normed_field.norm_mul _ _\n... \u2264 \u2225exp x\u2225 * \u2225z\u2225^2 : mul_le_mul_of_nonneg_left (abs_exp_sub_one_sub_id_le hz) (norm_nonneg _)\n\nlemma locally_lipschitz_exp {r : \u211d} (hr_nonneg : 0 \u2264 r) (hr_le : r \u2264 1) (x y : \u2102)\n  (hyx : \u2225y - x\u2225 < r) :\n  \u2225exp y - exp x\u2225 \u2264 (1 + r) * \u2225exp x\u2225 * \u2225y - x\u2225 :=\nbegin\n  have hy_eq : y = x + (y - x), by abel,\n  have hyx_sq_le : \u2225y - x\u2225 ^ 2 \u2264 r * \u2225y - x\u2225,\n  { rw pow_two,\n    exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg, },\n  have h_sq : \u2200 z, \u2225z\u2225 \u2264 1 \u2192 \u2225exp (x + z) - exp x\u2225 \u2264 \u2225z\u2225 * \u2225exp x\u2225 + \u2225exp x\u2225 * \u2225z\u2225 ^ 2,\n  { intros z hz,\n    have : \u2225exp (x + z) - exp x - z \u2022 exp x\u2225 \u2264 \u2225exp x\u2225 * \u2225z\u2225 ^ 2, from exp_bound_sq x z hz,\n    rw [\u2190 sub_le_iff_le_add',  \u2190 norm_smul z],\n    exact (norm_sub_norm_le _ _).trans this, },\n  calc \u2225exp y - exp x\u2225 = \u2225exp (x + (y - x)) - exp x\u2225 : by nth_rewrite 0 hy_eq\n  ... \u2264 \u2225y - x\u2225 * \u2225exp x\u2225 + \u2225exp x\u2225 * \u2225y - x\u2225 ^ 2 : h_sq (y - x) (hyx.le.trans hr_le)\n  ... \u2264 \u2225y - x\u2225 * \u2225exp x\u2225 + \u2225exp x\u2225 * (r * \u2225y - x\u2225) :\n    add_le_add_left (mul_le_mul le_rfl hyx_sq_le (sq_nonneg _) (norm_nonneg _)) _\n  ... = (1 + r) * \u2225exp x\u2225 * \u2225y - x\u2225 : by ring,\nend\n\n@[continuity] lemma continuous_exp : continuous exp :=\ncontinuous_iff_continuous_at.mpr $\n  \u03bb x, continuous_at_of_locally_lipschitz zero_lt_one (2 * \u2225exp x\u2225)\n    (locally_lipschitz_exp zero_le_one le_rfl x)\n\nlemma continuous_on_exp {s : set \u2102} : continuous_on exp s :=\ncontinuous_exp.continuous_on\n\nend complex\n\nsection complex_continuous_exp_comp\n\nvariable {\u03b1 : Type*}\n\nopen complex\n\nlemma filter.tendsto.cexp {l : filter \u03b1} {f : \u03b1 \u2192 \u2102} {z : \u2102} (hf : tendsto f l (\ud835\udcdd z)) :\n  tendsto (\u03bb x, exp (f x)) l (\ud835\udcdd (exp z)) :=\n(continuous_exp.tendsto _).comp hf\n\nvariables [topological_space \u03b1] {f : \u03b1 \u2192 \u2102} {s : set \u03b1} {x : \u03b1}\n\nlemma continuous_within_at.cexp (h : continuous_within_at f s x) :\n  continuous_within_at (\u03bb y, exp (f y)) s x :=\nh.cexp\n\nlemma continuous_at.cexp (h : continuous_at f x) : continuous_at (\u03bb y, exp (f y)) x :=\nh.cexp\n\nlemma continuous_on.cexp (h : continuous_on f s) : continuous_on (\u03bb y, exp (f y)) s :=\n\u03bb x hx, (h x hx).cexp\n\nlemma continuous.cexp (h : continuous f) : continuous (\u03bb y, exp (f y)) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, h.continuous_at.cexp\n\nend complex_continuous_exp_comp\n\nnamespace real\n\n@[continuity] lemma continuous_exp : continuous exp :=\ncomplex.continuous_re.comp complex.continuous_of_real.cexp\n\nlemma continuous_on_exp {s : set \u211d} : continuous_on exp s :=\ncontinuous_exp.continuous_on\n\nend real\n\nsection real_continuous_exp_comp\n\nvariable {\u03b1 : Type*}\n\nopen real\n\nlemma filter.tendsto.exp {l : filter \u03b1} {f : \u03b1 \u2192 \u211d} {z : \u211d} (hf : tendsto f l (\ud835\udcdd z)) :\n  tendsto (\u03bb x, exp (f x)) l (\ud835\udcdd (exp z)) :=\n(continuous_exp.tendsto _).comp hf\n\nvariables [topological_space \u03b1] {f : \u03b1 \u2192 \u211d} {s : set \u03b1} {x : \u03b1}\n\nlemma continuous_within_at.exp (h : continuous_within_at f s x) :\n  continuous_within_at (\u03bb y, exp (f y)) s x :=\nh.exp\n\nlemma continuous_at.exp (h : continuous_at f x) : continuous_at (\u03bb y, exp (f y)) x :=\nh.exp\n\nlemma continuous_on.exp (h : continuous_on f s) : continuous_on (\u03bb y, exp (f y)) s :=\n\u03bb x hx, (h x hx).exp\n\nlemma continuous.exp (h : continuous f) : continuous (\u03bb y, exp (f y)) :=\ncontinuous_iff_continuous_at.2 $ \u03bb x, h.continuous_at.exp\n\nend real_continuous_exp_comp\n\nnamespace real\n\nvariables {x y z : \u211d}\n\n/-- The real exponential function tends to `+\u221e` at `+\u221e`. -/\nlemma tendsto_exp_at_top : tendsto exp at_top at_top :=\nbegin\n  have A : tendsto (\u03bbx:\u211d, x + 1) at_top at_top :=\n    tendsto_at_top_add_const_right at_top 1 tendsto_id,\n  have B : \u2200\u1da0 x in at_top, x + 1 \u2264 exp x :=\n    eventually_at_top.2 \u27e80, \u03bbx hx, add_one_le_exp x\u27e9,\n  exact tendsto_at_top_mono' at_top B A\nend\n\n/-- The real exponential function tends to `0` at `-\u221e` or, equivalently, `exp(-x)` tends to `0`\nat `+\u221e` -/\nlemma tendsto_exp_neg_at_top_nhds_0 : tendsto (\u03bbx, exp (-x)) at_top (\ud835\udcdd 0) :=\n(tendsto_inv_at_top_zero.comp tendsto_exp_at_top).congr (\u03bbx, (exp_neg x).symm)\n\n/-- The real exponential function tends to `1` at `0`. -/\nlemma tendsto_exp_nhds_0_nhds_1 : tendsto exp (\ud835\udcdd 0) (\ud835\udcdd 1) :=\nby { convert continuous_exp.tendsto 0, simp }\n\nlemma tendsto_exp_at_bot : tendsto exp at_bot (\ud835\udcdd 0) :=\n(tendsto_exp_neg_at_top_nhds_0.comp tendsto_neg_at_bot_at_top).congr $\n  \u03bb x, congr_arg exp $ neg_neg x\n\nlemma tendsto_exp_at_bot_nhds_within : tendsto exp at_bot (\ud835\udcdd[Ioi 0] 0) :=\ntendsto_inf.2 \u27e8tendsto_exp_at_bot, tendsto_principal.2 $ eventually_of_forall exp_pos\u27e9\n\n/-- The function `exp(x)/x^n` tends to `+\u221e` at `+\u221e`, for any natural number `n` -/\nlemma tendsto_exp_div_pow_at_top (n : \u2115) : tendsto (\u03bbx, exp x / x^n) at_top at_top :=\nbegin\n  refine (at_top_basis_Ioi.tendsto_iff (at_top_basis' 1)).2 (\u03bb C hC\u2081, _),\n  have hC\u2080 : 0 < C, from zero_lt_one.trans_le hC\u2081,\n  have : 0 < (exp 1 * C)\u207b\u00b9 := inv_pos.2 (mul_pos (exp_pos _) hC\u2080),\n  obtain \u27e8N, hN\u27e9 : \u2203 N, \u2200 k \u2265 N, (\u2191k ^ n : \u211d) / exp 1 ^ k < (exp 1 * C)\u207b\u00b9 :=\n    eventually_at_top.1 ((tendsto_pow_const_div_const_pow_of_one_lt n\n      (one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)),\n  simp only [\u2190 exp_nat_mul, mul_one, div_lt_iff, exp_pos, \u2190 div_eq_inv_mul] at hN,\n  refine \u27e8N, trivial, \u03bb x hx, _\u27e9, rw set.mem_Ioi at hx,\n  have hx\u2080 : 0 < x, from N.cast_nonneg.trans_lt hx,\n  rw [set.mem_Ici, le_div_iff (pow_pos hx\u2080 _), \u2190 le_div_iff' hC\u2080],\n  calc x ^ n \u2264 \u2308x\u2309\u208a ^ n : pow_le_pow_of_le_left hx\u2080.le (nat.le_ceil _) _\n  ... \u2264 exp \u2308x\u2309\u208a / (exp 1 * C) : (hN _ (nat.lt_ceil.2 hx).le).le\n  ... \u2264 exp (x + 1) / (exp 1 * C) : div_le_div_of_le (mul_pos (exp_pos _) hC\u2080).le\n    (exp_le_exp.2 $ (nat.ceil_lt_add_one hx\u2080.le).le)\n  ... = exp x / C : by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne']\nend\n\n/-- The function `x^n * exp(-x)` tends to `0` at `+\u221e`, for any natural number `n`. -/\nlemma tendsto_pow_mul_exp_neg_at_top_nhds_0 (n : \u2115) : tendsto (\u03bbx, x^n * exp (-x)) at_top (\ud835\udcdd 0) :=\n(tendsto_inv_at_top_zero.comp (tendsto_exp_div_pow_at_top n)).congr $ \u03bbx,\n  by rw [comp_app, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg]\n\n/-- The function `(b * exp x + c) / (x ^ n)` tends to `+\u221e` at `+\u221e`, for any positive natural number\n`n` and any real numbers `b` and `c` such that `b` is positive. -/\nlemma tendsto_mul_exp_add_div_pow_at_top (b c : \u211d) (n : \u2115) (hb : 0 < b) (hn : 1 \u2264 n) :\n  tendsto (\u03bb x, (b * (exp x) + c) / (x^n)) at_top at_top :=\nbegin\n  refine tendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top 0) _)\n    (((tendsto_exp_div_pow_at_top n).const_mul_at_top hb).at_top_add\n      ((tendsto_pow_neg_at_top hn).mul (@tendsto_const_nhds _ _ _ c _))),\n  intros x hx,\n  simp only [zpow_neg\u2080 x n],\n  ring,\nend\n\n/-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+\u221e`, for any positive natural number\n`n` and any real numbers `b` and `c` such that `b` is nonzero. -/\nlemma tendsto_div_pow_mul_exp_add_at_top (b c : \u211d) (n : \u2115) (hb : 0 \u2260 b) (hn : 1 \u2264 n) :\n  tendsto (\u03bb x, x^n / (b * (exp x) + c)) at_top (\ud835\udcdd 0) :=\nbegin\n  have H : \u2200 d e, 0 < d \u2192 tendsto (\u03bb (x:\u211d), x^n / (d * (exp x) + e)) at_top (\ud835\udcdd 0),\n  { intros b' c' h,\n    convert (tendsto_mul_exp_add_div_pow_at_top b' c' n h hn).inv_tendsto_at_top ,\n    ext x,\n    simpa only [pi.inv_apply] using inv_div.symm },\n  cases lt_or_gt_of_ne hb,\n  { exact H b c h },\n  { convert (H (-b) (-c) (neg_pos.mpr h)).neg,\n    { ext x,\n      field_simp,\n      rw [\u2190 neg_add (b * exp x) c, neg_div_neg_eq] },\n    { exact neg_zero.symm } },\nend\n\n/-- `real.exp` as an order isomorphism between `\u211d` and `(0, +\u221e)`. -/\ndef exp_order_iso : \u211d \u2243o Ioi (0 : \u211d) :=\nstrict_mono.order_iso_of_surjective _ (exp_strict_mono.cod_restrict exp_pos) $\n  (continuous_subtype_mk _ continuous_exp).surjective\n    (by simp only [tendsto_Ioi_at_top, subtype.coe_mk, tendsto_exp_at_top])\n    (by simp [tendsto_exp_at_bot_nhds_within])\n\n@[simp] lemma coe_exp_order_iso_apply (x : \u211d) : (exp_order_iso x : \u211d) = exp x := rfl\n\n@[simp] lemma coe_comp_exp_order_iso : coe \u2218 exp_order_iso = exp := rfl\n\n@[simp] lemma range_exp : range exp = Ioi 0 :=\nby rw [\u2190 coe_comp_exp_order_iso, range_comp, exp_order_iso.range_eq, image_univ, subtype.range_coe]\n\n@[simp] lemma map_exp_at_top : map exp at_top = at_top :=\nby rw [\u2190 coe_comp_exp_order_iso, \u2190 filter.map_map, order_iso.map_at_top, map_coe_Ioi_at_top]\n\n@[simp] lemma comap_exp_at_top : comap exp at_top = at_top :=\nby rw [\u2190 map_exp_at_top, comap_map exp_injective, map_exp_at_top]\n\n@[simp] lemma tendsto_exp_comp_at_top {\u03b1 : Type*} {l : filter \u03b1} {f : \u03b1 \u2192 \u211d} :\n  tendsto (\u03bb x, exp (f x)) l at_top \u2194 tendsto f l at_top :=\nby rw [\u2190 tendsto_comap_iff, comap_exp_at_top]\n\nlemma tendsto_comp_exp_at_top {\u03b1 : Type*} {l : filter \u03b1} {f : \u211d \u2192 \u03b1} :\n  tendsto (\u03bb x, f (exp x)) at_top l \u2194 tendsto f at_top l :=\nby rw [\u2190 tendsto_map'_iff, map_exp_at_top]\n\n@[simp] lemma map_exp_at_bot : map exp at_bot = \ud835\udcdd[Ioi 0] 0 :=\nby rw [\u2190 coe_comp_exp_order_iso, \u2190 filter.map_map, exp_order_iso.map_at_bot, \u2190 map_coe_Ioi_at_bot]\n\nlemma comap_exp_nhds_within_Ioi_zero : comap exp (\ud835\udcdd[Ioi 0] 0) = at_bot :=\nby rw [\u2190 map_exp_at_bot, comap_map exp_injective]\n\nlemma tendsto_comp_exp_at_bot {\u03b1 : Type*} {l : filter \u03b1} {f : \u211d \u2192 \u03b1} :\n  tendsto (\u03bb x, f (exp x)) at_bot l \u2194 tendsto f (\ud835\udcdd[Ioi 0] 0) l :=\nby rw [\u2190 map_exp_at_bot, tendsto_map'_iff]\n\nend real\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/special_functions/exp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7028391464048414}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\nimport algebra.star.basic\nimport data.set.finite\nimport data.set.pointwise.basic\n\n/-!\n# Pointwise star operation on sets\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the star operation pointwise on sets and provides the basic API.\nBesides basic facts about about how the star operation acts on sets (e.g., `(s \u2229 t)\u22c6 = s\u22c6 \u2229 t\u22c6`),\nif `s t : set \u03b1`, then under suitable assumption on `\u03b1`, it is shown\n\n* `(s + t)\u22c6 = s\u22c6 + t\u22c6`\n* `(s * t)\u22c6 = t\u22c6 + s\u22c6`\n* `(s\u207b\u00b9)\u22c6 = (s\u22c6)\u207b\u00b9`\n-/\n\nnamespace set\n\nopen_locale pointwise\n\nlocal postfix `\u22c6`:std.prec.max_plus := star\n\nvariables {\u03b1 : Type*} {s t : set \u03b1} {a : \u03b1}\n\n/-- The set `(star s : set \u03b1)` is defined as `{x | star x \u2208 s}` in locale `pointwise`.\nIn the usual case where `star` is involutive, it is equal to `{star s | x \u2208 s}`, see\n`set.image_star`. -/\nprotected def has_star [has_star \u03b1] : has_star (set \u03b1) :=\n\u27e8preimage has_star.star\u27e9\n\nlocalized \"attribute [instance] set.has_star\" in pointwise\n\n@[simp]\nlemma star_empty [has_star \u03b1] : (\u2205 : set \u03b1)\u22c6 = \u2205 := rfl\n\n@[simp]\nlemma star_univ [has_star \u03b1] : (univ : set \u03b1)\u22c6 = univ := rfl\n\n@[simp]\nlemma nonempty_star [has_involutive_star \u03b1] {s : set \u03b1} : (s\u22c6).nonempty \u2194 s.nonempty :=\nstar_involutive.surjective.nonempty_preimage\n\nlemma nonempty.star [has_involutive_star \u03b1] {s : set \u03b1} (h : s.nonempty) :\n  (s\u22c6).nonempty :=\nnonempty_star.2 h\n\n@[simp]\nlemma mem_star [has_star \u03b1] : a \u2208 s\u22c6 \u2194 a\u22c6 \u2208 s := iff.rfl\n\nlemma star_mem_star [has_involutive_star \u03b1] : a\u22c6 \u2208 s\u22c6 \u2194 a \u2208 s :=\nby simp only [mem_star, star_star]\n\n@[simp]\nlemma star_preimage [has_star \u03b1] : has_star.star \u207b\u00b9' s = s\u22c6 := rfl\n\n@[simp]\nlemma image_star [has_involutive_star \u03b1] : has_star.star '' s = s\u22c6 :=\nby { simp only [\u2190 star_preimage], rw [image_eq_preimage_of_inverse]; intro; simp only [star_star] }\n\n@[simp]\nlemma inter_star [has_star \u03b1] : (s \u2229 t)\u22c6 = s\u22c6 \u2229 t\u22c6 := preimage_inter\n\n@[simp]\nlemma union_star [has_star \u03b1] : (s \u222a t)\u22c6 = s\u22c6 \u222a t\u22c6 := preimage_union\n\n@[simp]\nlemma Inter_star {\u03b9 : Sort*} [has_star \u03b1] (s : \u03b9 \u2192 set \u03b1) : (\u22c2 i, s i)\u22c6 = \u22c2 i, (s i)\u22c6 :=\npreimage_Inter\n\n@[simp]\n\n\n@[simp]\nlemma compl_star [has_star \u03b1] : (s\u1d9c)\u22c6 = (s\u22c6)\u1d9c := preimage_compl\n\n@[simp]\ninstance [has_involutive_star \u03b1] : has_involutive_star (set \u03b1) :=\n{ star := has_star.star,\n  star_involutive :=\n    \u03bb s, by { simp only [\u2190 star_preimage, preimage_preimage, star_star, preimage_id'] } }\n\n@[simp]\nlemma star_subset_star [has_involutive_star \u03b1] {s t : set \u03b1} : s\u22c6 \u2286 t\u22c6 \u2194 s \u2286 t :=\nequiv.star.surjective.preimage_subset_preimage_iff\n\nlemma star_subset [has_involutive_star \u03b1] {s t : set \u03b1} : s\u22c6 \u2286 t \u2194 s \u2286 t\u22c6 :=\nby { rw [\u2190 star_subset_star, star_star] }\n\nlemma finite.star [has_involutive_star \u03b1] {s : set \u03b1} (hs : s.finite) : s\u22c6.finite :=\nhs.preimage $ star_injective.inj_on _\n\nlemma star_singleton {\u03b2 : Type*} [has_involutive_star \u03b2] (x : \u03b2) : ({x} : set \u03b2)\u22c6 = {x\u22c6} :=\nby { ext1 y, rw [mem_star, mem_singleton_iff, mem_singleton_iff, star_eq_iff_star_eq, eq_comm], }\n\nprotected lemma star_mul [monoid \u03b1] [star_semigroup \u03b1] (s t : set \u03b1) :\n  (s * t)\u22c6 = t\u22c6 * s\u22c6 :=\nby simp_rw [\u2190image_star, \u2190image2_mul, image_image2, image2_image_left, image2_image_right,\n              star_mul, image2_swap _ s t]\n\nprotected lemma star_add [add_monoid \u03b1] [star_add_monoid \u03b1] (s t : set \u03b1) :\n  (s + t)\u22c6 = s\u22c6 + t\u22c6 :=\nby simp_rw [\u2190image_star, \u2190image2_add, image_image2, image2_image_left, image2_image_right, star_add]\n\n@[simp]\ninstance [has_star \u03b1] [has_trivial_star \u03b1] : has_trivial_star (set \u03b1) :=\n{ star_trivial := \u03bb s, by { rw [\u2190star_preimage], ext1, simp [star_trivial] } }\n\nprotected lemma star_inv [group \u03b1] [star_semigroup \u03b1] (s : set \u03b1) : (s\u207b\u00b9)\u22c6 = (s\u22c6)\u207b\u00b9 :=\nby { ext, simp only [mem_star, mem_inv, star_inv] }\n\nprotected lemma star_inv' [division_semiring \u03b1] [star_ring \u03b1] (s : set \u03b1) : (s\u207b\u00b9)\u22c6 = (s\u22c6)\u207b\u00b9 :=\nby { ext, simp only [mem_star, mem_inv, star_inv'] }\n\nend set\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/star/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7028391444942771}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module algebra.order.monoid.units\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.Hom.Basic\nimport Mathbin.Order.MinMax\nimport Mathbin.Algebra.Group.Units\n\n/-!\n# Units in ordered monoids\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\n\nvariable {\u03b1 : Type _}\n\nnamespace Units\n\n@[to_additive]\ninstance [Monoid \u03b1] [Preorder \u03b1] : Preorder \u03b1\u02e3 :=\n  Preorder.lift (coe : \u03b1\u02e3 \u2192 \u03b1)\n\n#print Units.val_le_val /-\n@[simp, norm_cast, to_additive]\ntheorem val_le_val [Monoid \u03b1] [Preorder \u03b1] {a b : \u03b1\u02e3} : (a : \u03b1) \u2264 b \u2194 a \u2264 b :=\n  Iff.rfl\n#align units.coe_le_coe Units.val_le_val\n#align add_units.coe_le_coe AddUnits.val_le_val\n-/\n\n#print Units.val_lt_val /-\n@[simp, norm_cast, to_additive]\ntheorem val_lt_val [Monoid \u03b1] [Preorder \u03b1] {a b : \u03b1\u02e3} : (a : \u03b1) < b \u2194 a < b :=\n  Iff.rfl\n#align units.coe_lt_coe Units.val_lt_val\n#align add_units.coe_lt_coe AddUnits.val_lt_val\n-/\n\n@[to_additive]\ninstance [Monoid \u03b1] [PartialOrder \u03b1] : PartialOrder \u03b1\u02e3 :=\n  PartialOrder.lift coe Units.ext\n\n@[to_additive]\ninstance [Monoid \u03b1] [LinearOrder \u03b1] : LinearOrder \u03b1\u02e3 :=\n  LinearOrder.lift' coe Units.ext\n\n#print Units.orderEmbeddingVal /-\n/-- `coe : \u03b1\u02e3 \u2192 \u03b1` as an order embedding. -/\n@[to_additive \"`coe : add_units \u03b1 \u2192 \u03b1` as an order embedding.\",\n  simps (config := { fullyApplied := false })]\ndef orderEmbeddingVal [Monoid \u03b1] [LinearOrder \u03b1] : \u03b1\u02e3 \u21aao \u03b1 :=\n  \u27e8\u27e8coe, ext\u27e9, fun _ _ => Iff.rfl\u27e9\n#align units.order_embedding_coe Units.orderEmbeddingVal\n#align add_units.order_embedding_coe AddUnits.orderEmbeddingVal\n-/\n\n/- warning: units.max_coe -> Units.max_val is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Monoid.{u1} \u03b1] [_inst_2 : LinearOrder.{u1} \u03b1] {a : Units.{u1} \u03b1 _inst_1} {b : Units.{u1} \u03b1 _inst_1}, Eq.{succ u1} \u03b1 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} \u03b1 _inst_1) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (coeBase.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (Units.hasCoe.{u1} \u03b1 _inst_1)))) (LinearOrder.max.{u1} (Units.{u1} \u03b1 _inst_1) (Units.linearOrder.{u1} \u03b1 _inst_1 _inst_2) a b)) (LinearOrder.max.{u1} \u03b1 _inst_2 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} \u03b1 _inst_1) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (coeBase.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (Units.hasCoe.{u1} \u03b1 _inst_1)))) a) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} \u03b1 _inst_1) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (coeBase.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (Units.hasCoe.{u1} \u03b1 _inst_1)))) b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Monoid.{u1} \u03b1] [_inst_2 : LinearOrder.{u1} \u03b1] {a : Units.{u1} \u03b1 _inst_1} {b : Units.{u1} \u03b1 _inst_1}, Eq.{succ u1} \u03b1 (Units.val.{u1} \u03b1 _inst_1 (Max.max.{u1} (Units.{u1} \u03b1 _inst_1) (LinearOrder.toMax.{u1} (Units.{u1} \u03b1 _inst_1) (Units.instLinearOrderUnits.{u1} \u03b1 _inst_1 _inst_2)) a b)) (Max.max.{u1} \u03b1 (LinearOrder.toMax.{u1} \u03b1 _inst_2) (Units.val.{u1} \u03b1 _inst_1 a) (Units.val.{u1} \u03b1 _inst_1 b))\nCase conversion may be inaccurate. Consider using '#align units.max_coe Units.max_val\u2093'. -/\n@[simp, norm_cast, to_additive]\ntheorem max_val [Monoid \u03b1] [LinearOrder \u03b1] {a b : \u03b1\u02e3} : (\u2191(max a b) : \u03b1) = max a b :=\n  Monotone.map_max orderEmbeddingVal.Monotone\n#align units.max_coe Units.max_val\n#align add_units.max_coe AddUnits.max_val\n\n/- warning: units.min_coe -> Units.min_val is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Monoid.{u1} \u03b1] [_inst_2 : LinearOrder.{u1} \u03b1] {a : Units.{u1} \u03b1 _inst_1} {b : Units.{u1} \u03b1 _inst_1}, Eq.{succ u1} \u03b1 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} \u03b1 _inst_1) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (coeBase.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (Units.hasCoe.{u1} \u03b1 _inst_1)))) (LinearOrder.min.{u1} (Units.{u1} \u03b1 _inst_1) (Units.linearOrder.{u1} \u03b1 _inst_1 _inst_2) a b)) (LinearOrder.min.{u1} \u03b1 _inst_2 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} \u03b1 _inst_1) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (coeBase.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (Units.hasCoe.{u1} \u03b1 _inst_1)))) a) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Units.{u1} \u03b1 _inst_1) \u03b1 (HasLiftT.mk.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (CoeTC\u2093.coe.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (coeBase.{succ u1, succ u1} (Units.{u1} \u03b1 _inst_1) \u03b1 (Units.hasCoe.{u1} \u03b1 _inst_1)))) b))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Monoid.{u1} \u03b1] [_inst_2 : LinearOrder.{u1} \u03b1] {a : Units.{u1} \u03b1 _inst_1} {b : Units.{u1} \u03b1 _inst_1}, Eq.{succ u1} \u03b1 (Units.val.{u1} \u03b1 _inst_1 (Min.min.{u1} (Units.{u1} \u03b1 _inst_1) (LinearOrder.toMin.{u1} (Units.{u1} \u03b1 _inst_1) (Units.instLinearOrderUnits.{u1} \u03b1 _inst_1 _inst_2)) a b)) (Min.min.{u1} \u03b1 (LinearOrder.toMin.{u1} \u03b1 _inst_2) (Units.val.{u1} \u03b1 _inst_1 a) (Units.val.{u1} \u03b1 _inst_1 b))\nCase conversion may be inaccurate. Consider using '#align units.min_coe Units.min_val\u2093'. -/\n@[simp, norm_cast, to_additive]\ntheorem min_val [Monoid \u03b1] [LinearOrder \u03b1] {a b : \u03b1\u02e3} : (\u2191(min a b) : \u03b1) = min a b :=\n  Monotone.map_min orderEmbeddingVal.Monotone\n#align units.min_coe Units.min_val\n#align add_units.min_coe AddUnits.min_val\n\nend Units\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Order/Monoid/Units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969193, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7027911358297094}}
{"text": "/-\nCopyright (c) 2022 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n\n! This file was ported from Lean 3 source module data.set.pointwise.support\n! leanprover-community/mathlib commit f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Set.Pointwise.SMul\nimport Mathlib.Algebra.Support\n\n/-!\n# Support of a function composed with a scalar action\n\nWe show that the support of `x \u21a6 f (c\u207b\u00b9 \u2022 x)` is equal to `c \u2022 support f`.\n-/\n\n\nopen Pointwise\n\nopen Function Set\n\nsection Group\n\nvariable {\u03b1 \u03b2 \u03b3 : Type _} [Group \u03b1] [MulAction \u03b1 \u03b2]\n\ntheorem mulSupport_comp_inv_smul [One \u03b3] (c : \u03b1) (f : \u03b2 \u2192 \u03b3) :\n    (mulSupport fun x \u21a6 f (c\u207b\u00b9 \u2022 x)) = c \u2022 mulSupport f := by\n  ext x\n  simp only [mem_smul_set_iff_inv_smul_mem, mem_mulSupport]\n#align mul_support_comp_inv_smul mulSupport_comp_inv_smul\n\n/- Note: to_additive also automatically translates `SMul` to `VAdd`, so we give the additive version\nmanually. -/\ntheorem support_comp_inv_smul [Zero \u03b3] (c : \u03b1) (f : \u03b2 \u2192 \u03b3) :\n    (support fun x \u21a6 f (c\u207b\u00b9 \u2022 x)) = c \u2022 support f := by\n  ext x\n  simp only [mem_smul_set_iff_inv_smul_mem, mem_support]\n#align support_comp_inv_smul support_comp_inv_smul\n\nattribute [to_additive existing support_comp_inv_smul] mulSupport_comp_inv_smul\n\nend Group\n\nsection GroupWithZero\n\nvariable {\u03b1 \u03b2 \u03b3 : Type _} [GroupWithZero \u03b1] [MulAction \u03b1 \u03b2]\n\ntheorem mulSupport_comp_inv_smul\u2080 [One \u03b3] {c : \u03b1} (hc : c \u2260 0) (f : \u03b2 \u2192 \u03b3) :\n    (mulSupport fun x \u21a6 f (c\u207b\u00b9 \u2022 x)) = c \u2022 mulSupport f := by\n  ext x\n  simp only [mem_smul_set_iff_inv_smul_mem\u2080 hc, mem_mulSupport]\n#align mul_support_comp_inv_smul\u2080 mulSupport_comp_inv_smul\u2080\n\n/- Note: to_additive also automatically translates `SMul` to `VAdd`, so we give the additive version\nmanually. -/\ntheorem support_comp_inv_smul\u2080 [Zero \u03b3] {c : \u03b1} (hc : c \u2260 0) (f : \u03b2 \u2192 \u03b3) :\n    (support fun x \u21a6 f (c\u207b\u00b9 \u2022 x)) = c \u2022 support f := by\n  ext x\n  simp only [mem_smul_set_iff_inv_smul_mem\u2080 hc, mem_support]\n#align support_comp_inv_smul\u2080 support_comp_inv_smul\u2080\n\nattribute [to_additive existing support_comp_inv_smul\u2080] mulSupport_comp_inv_smul\u2080\n\nend GroupWithZero\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/Pointwise/Support.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7027911344323727}}
{"text": "/-\nCopyright (c) 2019 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport ring_theory.adjoin.basic\nimport ring_theory.polynomial.scale_roots\nimport ring_theory.polynomial.tower\n\n/-!\n# Integral closure of a subring.\n\nIf A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial\nwith coefficients in R. Enough theory is developed to prove that integral elements\nform a sub-R-algebra of A.\n\n## Main definitions\n\nLet `R` be a `comm_ring` and let `A` be an R-algebra.\n\n* `ring_hom.is_integral_elem (f : R \u2192+* A) (x : A)` : `x` is integral with respect to the map `f`,\n\n* `is_integral (x : A)`  : `x` is integral over `R`, i.e., is a root of a monic polynomial with\n                           coefficients in `R`.\n* `integral_closure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`.\n-/\n\nopen_locale classical\nopen_locale big_operators\nopen polynomial submodule\n\nsection ring\nvariables {R S A : Type*}\nvariables [comm_ring R] [ring A] [ring S] (f : R \u2192+* S)\n\n/-- An element `x` of `A` is said to be integral over `R` with respect to `f`\nif it is a root of a monic polynomial `p : polynomial R` evaluated under `f` -/\ndef ring_hom.is_integral_elem (f : R \u2192+* A) (x : A) :=\n\u2203 p : polynomial R, monic p \u2227 eval\u2082 f x p = 0\n\n/-- A ring homomorphism `f : R \u2192+* A` is said to be integral\nif every element `A` is integral with respect to the map `f` -/\ndef ring_hom.is_integral (f : R \u2192+* A) :=\n\u2200 x : A, f.is_integral_elem x\n\nvariables [algebra R A] (R)\n\n/-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*,\nif it is a root of some monic polynomial `p : polynomial R`.\nEquivalently, the element is integral over `R` with respect to the induced `algebra_map` -/\ndef is_integral (x : A) : Prop :=\n(algebra_map R A).is_integral_elem x\n\nvariable (A)\n\n/-- An algebra is integral if every element of the extension is integral over the base ring -/\ndef algebra.is_integral : Prop :=\n(algebra_map R A).is_integral\n\nvariables {R A}\n\nlemma ring_hom.is_integral_map {x : R} : f.is_integral_elem (f x) :=\n\u27e8X - C x, monic_X_sub_C _, by simp\u27e9\n\ntheorem is_integral_algebra_map {x : R} : is_integral R (algebra_map R A x) :=\n(algebra_map R A).is_integral_map\n\ntheorem is_integral_of_noetherian (H : is_noetherian R A) (x : A) :\n  is_integral R x :=\nbegin\n  let leval : @linear_map R (polynomial R) A _ _ _ _ _ := (aeval x).to_linear_map,\n  let D : \u2115 \u2192 submodule R A := \u03bb n, (degree_le R n).map leval,\n  let M := well_founded.min (is_noetherian_iff_well_founded.1 H)\n    (set.range D) \u27e8_, \u27e80, rfl\u27e9\u27e9,\n  have HM : M \u2208 set.range D := well_founded.min_mem _ _ _,\n  cases HM with N HN,\n  have HM : \u00acM < D (N+1) := well_founded.not_lt_min\n    (is_noetherian_iff_well_founded.1 H) (set.range D) _ \u27e8N+1, rfl\u27e9,\n  rw \u2190 HN at HM,\n  have HN2 : D (N+1) \u2264 D N := classical.by_contradiction (\u03bb H, HM\n    (lt_of_le_not_le (map_mono (degree_le_mono\n      (with_bot.coe_le_coe.2 (nat.le_succ N)))) H)),\n  have HN3 : leval (X^(N+1)) \u2208 D N,\n  { exact HN2 (mem_map_of_mem (mem_degree_le.2 (degree_X_pow_le _))) },\n  rcases HN3 with \u27e8p, hdp, hpe\u27e9,\n  refine \u27e8X^(N+1) - p, monic_X_pow_sub (mem_degree_le.1 hdp), _\u27e9,\n  show leval (X ^ (N + 1) - p) = 0,\n  rw [linear_map.map_sub, hpe, sub_self]\nend\n\ntheorem is_integral_of_submodule_noetherian (S : subalgebra R A)\n  (H : is_noetherian R S.to_submodule) (x : A) (hx : x \u2208 S) :\n  is_integral R x :=\nbegin\n  suffices : is_integral R (show S, from \u27e8x, hx\u27e9),\n  { rcases this with \u27e8p, hpm, hpx\u27e9,\n    replace hpx := congr_arg S.val hpx,\n    refine \u27e8p, hpm, eq.trans _ hpx\u27e9,\n    simp only [aeval_def, eval\u2082, finsupp.sum],\n    rw S.val.map_sum,\n    refine finset.sum_congr rfl (\u03bb n hn, _),\n    rw [S.val.map_mul, S.val.map_pow, S.val.commutes, S.val_apply, subtype.coe_mk], },\n  refine is_integral_of_noetherian H \u27e8x, hx\u27e9\nend\n\nend ring\n\nsection\nvariables {R A B S : Type*}\nvariables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S]\nvariables [algebra R A] [algebra R B] (f : R \u2192+* S)\n\ntheorem is_integral_alg_hom (f : A \u2192\u2090[R] B) {x : A} (hx : is_integral R x) : is_integral R (f x) :=\nlet \u27e8p, hp, hpx\u27e9 :=\nhx in \u27e8p, hp, by rw [\u2190 aeval_def, aeval_alg_hom_apply, aeval_def, hpx, f.map_zero]\u27e9\n\ntheorem is_integral_of_is_scalar_tower [algebra A B] [is_scalar_tower R A B]\n  (x : B) (hx : is_integral R x) : is_integral A x :=\nlet \u27e8p, hp, hpx\u27e9 := hx in\n\u27e8p.map $ algebra_map R A, monic_map _ hp,\n  by rw [\u2190 aeval_def, \u2190 is_scalar_tower.aeval_apply, aeval_def, hpx]\u27e9\n\nsection\nlocal attribute [instance] subset.comm_ring algebra.of_is_subring\n\ntheorem is_integral_of_subring {x : A} (T : set R) [is_subring T]\n  (hx : is_integral T x) : is_integral R x :=\nis_integral_of_is_scalar_tower x hx\n\nlemma is_integral_algebra_map_iff [algebra A B] [is_scalar_tower R A B]\n  {x : A} (hAB : function.injective (algebra_map A B)) :\n  is_integral R (algebra_map A B x) \u2194 is_integral R x :=\nbegin\n  split; rintros \u27e8f, hf, hx\u27e9; use [f, hf],\n  { exact is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero R A B hAB hx },\n  { rw [is_scalar_tower.algebra_map_eq R A B, \u2190 hom_eval\u2082, hx, ring_hom.map_zero] }\nend\n\ntheorem is_integral_iff_is_integral_closure_finite {r : A} :\n  is_integral R r \u2194 \u2203 s : set R, s.finite \u2227 is_integral (ring.closure s) r :=\nbegin\n  split; intro hr,\n  { rcases hr with \u27e8p, hmp, hpr\u27e9,\n    refine \u27e8_, set.finite_mem_finset _, p.restriction, subtype.eq hmp, _\u27e9,\n    erw [\u2190 aeval_def, is_scalar_tower.aeval_apply _ R, map_restriction, aeval_def, hpr] },\n  rcases hr with \u27e8s, hs, hsr\u27e9,\n  exact is_integral_of_subring _ hsr\nend\n\nend\n\ntheorem fg_adjoin_singleton_of_integral (x : A) (hx : is_integral R x) :\n  (algebra.adjoin R ({x} : set A)).to_submodule.fg :=\nbegin\n  rcases hx with \u27e8f, hfm, hfx\u27e9,\n  existsi finset.image ((^) x) (finset.range (nat_degree f + 1)),\n  apply le_antisymm,\n  { rw span_le, intros s hs, rw finset.mem_coe at hs,\n    rcases finset.mem_image.1 hs with \u27e8k, hk, rfl\u27e9, clear hk,\n    exact is_submonoid.pow_mem (algebra.subset_adjoin (set.mem_singleton _)) },\n  intros r hr, change r \u2208 algebra.adjoin R ({x} : set A) at hr,\n  rw algebra.adjoin_singleton_eq_range at hr,\n  rcases (aeval x).mem_range.mp hr with \u27e8p, rfl\u27e9,\n  rw \u2190 mod_by_monic_add_div p hfm,\n  rw \u2190 aeval_def at hfx,\n  rw [alg_hom.map_add, alg_hom.map_mul, hfx, zero_mul, add_zero],\n  have : degree (p %\u2098 f) \u2264 degree f := degree_mod_by_monic_le p hfm,\n  generalize_hyp : p %\u2098 f = q at this \u22a2,\n  rw [\u2190 sum_C_mul_X_eq q, aeval_def, eval\u2082_sum, finsupp.sum],\n  refine sum_mem _ (\u03bb k hkq, _),\n  rw [eval\u2082_mul, eval\u2082_C, eval\u2082_pow, eval\u2082_X, \u2190 algebra.smul_def],\n  refine smul_mem _ _ (subset_span _),\n  rw finset.mem_coe, refine finset.mem_image.2 \u27e8_, _, rfl\u27e9,\n  rw [finset.mem_range, nat.lt_succ_iff], refine le_of_not_lt (\u03bb hk, _),\n  rw [degree_le_iff_coeff_zero] at this,\n  rw [finsupp.mem_support_iff] at hkq, apply hkq, apply this,\n  exact lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 hk)\nend\n\ntheorem fg_adjoin_of_finite {s : set A} (hfs : s.finite)\n  (his : \u2200 x \u2208 s, is_integral R x) : (algebra.adjoin R s).to_submodule.fg :=\nset.finite.induction_on hfs (\u03bb _, \u27e8{1}, submodule.ext $ \u03bb x,\n  by { erw [algebra.adjoin_empty, finset.coe_singleton, \u2190 one_eq_span, one_eq_map_top,\n      map_top, linear_map.mem_range, algebra.mem_bot], refl }\u27e9)\n(\u03bb a s has hs ih his, by rw [\u2190 set.union_singleton, algebra.adjoin_union_coe_submodule]; exact\n  fg_mul _ _ (ih $ \u03bb i hi, his i $ set.mem_insert_of_mem a hi)\n    (fg_adjoin_singleton_of_integral _ $ his a $ set.mem_insert a s)) his\n\ntheorem is_integral_of_mem_of_fg (S : subalgebra R A)\n  (HS : S.to_submodule.fg) (x : A) (hx : x \u2208 S) : is_integral R x :=\nbegin\n  cases HS with y hy,\n  obtain \u27e8lx, hlx1, hlx2\u27e9 :\n    \u2203 (l : A \u2192\u2080 R) (H : l \u2208 finsupp.supported R R \u2191y), (finsupp.total A A R id) l = x,\n  { rwa [\u2190(@finsupp.mem_span_iff_total A A R _ _ _ id \u2191y x), set.image_id \u2191y, hy] },\n  have hyS : \u2200 {p}, p \u2208 y \u2192 p \u2208 S := \u03bb p hp, show p \u2208 S.to_submodule,\n    by { rw \u2190 hy, exact subset_span hp },\n  have : \u2200 (jk : (\u2191(y.product y) : set (A \u00d7 A))), jk.1.1 * jk.1.2 \u2208 S.to_submodule :=\n    \u03bb jk, S.mul_mem (hyS (finset.mem_product.1 jk.2).1) (hyS (finset.mem_product.1 jk.2).2),\n  rw [\u2190 hy, \u2190 set.image_id \u2191y] at this, simp only [finsupp.mem_span_iff_total] at this,\n  choose ly hly1 hly2,\n  let S\u2080 : set R := ring.closure \u2191(lx.frange \u222a finset.bUnion finset.univ (finsupp.frange \u2218 ly)),\n  refine is_integral_of_subring S\u2080 _,\n  letI : comm_ring S\u2080 := @subtype.comm_ring _ _ _ ring.closure.is_subring,\n  letI : algebra S\u2080 A := algebra.of_is_subring _,\n  have :\n    span S\u2080 (insert 1 \u2191y : set A) * span S\u2080 (insert 1 \u2191y : set A) \u2264 span S\u2080 (insert 1 \u2191y : set A),\n  { rw span_mul_span, refine span_le.2 (\u03bb z hz, _),\n    rcases set.mem_mul.1 hz with \u27e8p, q, rfl | hp, hq, rfl\u27e9,\n    { rw one_mul, exact subset_span hq },\n    rcases hq with rfl | hq,\n    { rw mul_one, exact subset_span (or.inr hp) },\n    erw \u2190 hly2 \u27e8(p, q), finset.mem_product.2 \u27e8hp, hq\u27e9\u27e9,\n    rw [finsupp.total_apply, finsupp.sum],\n    refine (span S\u2080 (insert 1 \u2191y : set A)).sum_mem (\u03bb t ht, _),\n    have : ly \u27e8(p, q), finset.mem_product.2 \u27e8hp, hq\u27e9\u27e9 t \u2208 S\u2080 :=\n    ring.subset_closure (finset.mem_union_right _ $ finset.mem_bUnion.2\n      \u27e8\u27e8(p, q), finset.mem_product.2 \u27e8hp, hq\u27e9\u27e9, finset.mem_univ _,\n        finsupp.mem_frange.2 \u27e8finsupp.mem_support_iff.1 ht, _, rfl\u27e9\u27e9),\n    change (\u27e8_, this\u27e9 : S\u2080) \u2022 t \u2208 _, exact smul_mem _ _ (subset_span $ or.inr $ hly1 _ ht) },\n  haveI : is_subring (span S\u2080 (insert 1 \u2191y : set A) : set A) :=\n  { one_mem := subset_span $ or.inl rfl,\n    mul_mem := \u03bb p q hp hq, this $ mul_mem_mul hp hq,\n    zero_mem := (span S\u2080 (insert 1 \u2191y : set A)).zero_mem,\n    add_mem := \u03bb _ _, (span S\u2080 (insert 1 \u2191y : set A)).add_mem,\n    neg_mem := \u03bb _, (span S\u2080 (insert 1 \u2191y : set A)).neg_mem },\n  have : span S\u2080 (insert 1 \u2191y : set A) = (algebra.adjoin S\u2080 (\u2191y : set A)).to_submodule,\n  { refine le_antisymm (span_le.2 $ set.insert_subset.2\n        \u27e8(algebra.adjoin S\u2080 \u2191y).one_mem, algebra.subset_adjoin\u27e9) (\u03bb z hz, _),\n    rw [subalgebra.mem_to_submodule, algebra.mem_adjoin_iff] at hz, rw \u2190 set_like.mem_coe,\n    refine ring.closure_subset (set.union_subset (set.range_subset_iff.2 $ \u03bb t, _)\n      (\u03bb t ht, subset_span $ or.inr ht)) hz,\n    rw algebra.algebra_map_eq_smul_one,\n    exact smul_mem (span S\u2080 (insert 1 \u2191y : set A)) _ (subset_span $ or.inl rfl) },\n  haveI : is_noetherian_ring \u21a5S\u2080 := is_noetherian_ring_closure _ (finset.finite_to_set _),\n  refine is_integral_of_submodule_noetherian (algebra.adjoin S\u2080 \u2191y)\n    (is_noetherian_of_fg_of_noetherian _ \u27e8insert 1 y, by rw [finset.coe_insert, this]\u27e9) _ _,\n  rw [\u2190 hlx2, finsupp.total_apply, finsupp.sum], refine subalgebra.sum_mem _ (\u03bb r hr, _),\n  have : lx r \u2208 S\u2080 := ring.subset_closure (finset.mem_union_left _ (finset.mem_image_of_mem _ hr)),\n  change (\u27e8_, this\u27e9 : S\u2080) \u2022 r \u2208 _,\n  rw finsupp.mem_supported at hlx1,\n  exact subalgebra.smul_mem _ (algebra.subset_adjoin $ hlx1 hr) _\nend\n\nlemma ring_hom.is_integral_of_mem_closure {x y z : S}\n  (hx : f.is_integral_elem x) (hy : f.is_integral_elem y)\n  (hz : z \u2208 ring.closure ({x, y} : set S)) :\n  f.is_integral_elem z :=\nbegin\n  letI : algebra R S := f.to_algebra,\n  have := fg_mul _ _ (fg_adjoin_singleton_of_integral x hx) (fg_adjoin_singleton_of_integral y hy),\n  rw [\u2190 algebra.adjoin_union_coe_submodule, set.singleton_union] at this,\n  exact is_integral_of_mem_of_fg (algebra.adjoin R {x, y}) this z\n    (algebra.mem_adjoin_iff.2  $ ring.closure_mono (set.subset_union_right _ _) hz),\nend\n\ntheorem is_integral_of_mem_closure {x y z : A}\n  (hx : is_integral R x) (hy : is_integral R y)\n  (hz : z \u2208 ring.closure ({x, y} : set A)) :\n  is_integral R z :=\n(algebra_map R A).is_integral_of_mem_closure hx hy hz\n\nlemma ring_hom.is_integral_zero : f.is_integral_elem 0 :=\nf.map_zero \u25b8 f.is_integral_map\n\ntheorem is_integral_zero : is_integral R (0:A) :=\n(algebra_map R A).is_integral_zero\n\nlemma ring_hom.is_integral_one : f.is_integral_elem 1 :=\nf.map_one \u25b8 f.is_integral_map\n\ntheorem is_integral_one : is_integral R (1:A) :=\n(algebra_map R A).is_integral_one\n\nlemma ring_hom.is_integral_add {x y : S}\n  (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) :\n  f.is_integral_elem (x + y) :=\nf.is_integral_of_mem_closure hx hy (is_add_submonoid.add_mem\n  (ring.subset_closure (or.inl rfl)) (ring.subset_closure (or.inr rfl)))\n\ntheorem is_integral_add {x y : A}\n  (hx : is_integral R x) (hy : is_integral R y) :\n  is_integral R (x + y) :=\n(algebra_map R A).is_integral_add hx hy\n\nlemma ring_hom.is_integral_neg {x : S}\n  (hx : f.is_integral_elem x) : f.is_integral_elem (-x) :=\nf.is_integral_of_mem_closure hx hx (is_add_subgroup.neg_mem\n  (ring.subset_closure (or.inl rfl)))\n\ntheorem is_integral_neg {x : A}\n  (hx : is_integral R x) : is_integral R (-x) :=\n(algebra_map R A).is_integral_neg hx\n\nlemma ring_hom.is_integral_sub {x y : S}\n  (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x - y) :=\nby simpa only [sub_eq_add_neg] using f.is_integral_add hx (f.is_integral_neg hy)\n\ntheorem is_integral_sub {x y : A}\n  (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x - y) :=\n(algebra_map R A).is_integral_sub hx hy\n\nlemma ring_hom.is_integral_mul {x y : S}\n  (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x * y) :=\nf.is_integral_of_mem_closure hx hy (is_submonoid.mul_mem\n  (ring.subset_closure (or.inl rfl)) (ring.subset_closure (or.inr rfl)))\n\ntheorem is_integral_mul {x y : A}\n  (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x * y) :=\n(algebra_map R A).is_integral_mul hx hy\n\nvariables (R A)\n\n/-- The integral closure of R in an R-algebra A. -/\ndef integral_closure : subalgebra R A :=\n{ carrier := { r | is_integral R r },\n  zero_mem' := is_integral_zero,\n  one_mem' := is_integral_one,\n  add_mem' := \u03bb _ _, is_integral_add,\n  mul_mem' := \u03bb _ _, is_integral_mul,\n  algebra_map_mem' := \u03bb x, is_integral_algebra_map }\n\ntheorem mem_integral_closure_iff_mem_fg {r : A} :\n  r \u2208 integral_closure R A \u2194 \u2203 M : subalgebra R A, M.to_submodule.fg \u2227 r \u2208 M :=\n\u27e8\u03bb hr, \u27e8algebra.adjoin R {r}, fg_adjoin_singleton_of_integral _ hr, algebra.subset_adjoin rfl\u27e9,\n\u03bb \u27e8M, Hf, hrM\u27e9, is_integral_of_mem_of_fg M Hf _ hrM\u27e9\n\nvariables {R} {A}\n\n/-- Mapping an integral closure along an `alg_equiv` gives the integral closure. -/\nlemma integral_closure_map_alg_equiv (f : A \u2243\u2090[R] B) :\n  (integral_closure R A).map (f : A \u2192\u2090[R] B) = integral_closure R B :=\nbegin\n  ext y,\n  rw subalgebra.mem_map,\n  split,\n  { rintros \u27e8x, hx, rfl\u27e9,\n    exact is_integral_alg_hom f hx },\n  { intro hy,\n    use [f.symm y, is_integral_alg_hom (f.symm : B \u2192\u2090[R] A) hy],\n    simp }\nend\n\nlemma integral_closure.is_integral (x : integral_closure R A) : is_integral R x :=\nlet \u27e8p, hpm, hpx\u27e9 := x.2 in \u27e8p, hpm, subtype.eq $\nby rwa [\u2190 aeval_def, subtype.val_eq_coe, \u2190 subalgebra.val_apply, aeval_alg_hom_apply] at hpx\u27e9\n\nlemma ring_hom.is_integral_of_is_integral_mul_unit (x y : S) (r : R) (hr : f r * y = 1)\n  (hx : f.is_integral_elem (x * y)) : f.is_integral_elem x :=\nbegin\n  obtain \u27e8p, \u27e8p_monic, hp\u27e9\u27e9 := hx,\n  refine \u27e8scale_roots p r, \u27e8(monic_scale_roots_iff r).2 p_monic, _\u27e9\u27e9,\n  convert scale_roots_eval\u2082_eq_zero f hp,\n  rw [mul_comm x y, \u2190 mul_assoc, hr, one_mul],\nend\n\ntheorem is_integral_of_is_integral_mul_unit {x y : A} {r : R} (hr : algebra_map R A r * y = 1)\n  (hx : is_integral R (x * y)) : is_integral R x :=\n(algebra_map R A).is_integral_of_is_integral_mul_unit x y r hr hx\n\n/-- Generalization of `is_integral_of_mem_closure` bootstrapped up from that lemma -/\nlemma is_integral_of_mem_closure' (G : set A) (hG : \u2200 x \u2208 G, is_integral R x) :\n  \u2200 x \u2208 (subring.closure G), is_integral R x :=\n\u03bb x hx, subring.closure_induction hx hG is_integral_zero is_integral_one\n  (\u03bb _ _, is_integral_add) (\u03bb _, is_integral_neg) (\u03bb _ _, is_integral_mul)\n\nlemma is_integral_of_mem_closure'' {S : Type*} [comm_ring S] {f : R \u2192+* S} (G : set S)\n  (hG : \u2200 x \u2208 G, f.is_integral_elem x) : \u2200 x \u2208 (subring.closure G), f.is_integral_elem x :=\n\u03bb x hx, @is_integral_of_mem_closure' R S _ _ f.to_algebra G hG x hx\n\nend\n\nsection algebra\nopen algebra\nvariables {R A B S T : Type*}\nvariables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S] [comm_ring T]\nvariables [algebra A B] [algebra R B] (f : R \u2192+* S) (g : S \u2192+* T)\n\nlemma is_integral_trans_aux (x : B) {p : polynomial A} (pmonic : monic p) (hp : aeval x p = 0) :\n  is_integral (adjoin R (\u2191(p.map $ algebra_map A B).frange : set B)) x :=\nbegin\n  generalize hS : (\u2191(p.map $ algebra_map A B).frange : set B) = S,\n  have coeffs_mem : \u2200 i, (p.map $ algebra_map A B).coeff i \u2208 adjoin R S,\n  { intro i, by_cases hi : (p.map $ algebra_map A B).coeff i = 0,\n    { rw hi, exact subalgebra.zero_mem _ },\n    rw \u2190 hS, exact subset_adjoin (finsupp.mem_frange.2 \u27e8hi, i, rfl\u27e9) },\n  obtain \u27e8q, hq\u27e9 : \u2203 q : polynomial (adjoin R S), q.map (algebra_map (adjoin R S) B) =\n      (p.map $ algebra_map A B),\n  { rw \u2190 set.mem_range, exact (polynomial.mem_map_range _).2 (\u03bb i, \u27e8\u27e8_, coeffs_mem i\u27e9, rfl\u27e9) },\n  use q,\n  split,\n  { suffices h : (q.map (algebra_map (adjoin R S) B)).monic,\n    { refine monic_of_injective _ h,\n      exact subtype.val_injective },\n    { rw hq, exact monic_map _ pmonic } },\n  { convert hp using 1,\n    replace hq := congr_arg (eval x) hq,\n    convert hq using 1; symmetry; apply eval_map },\nend\n\nvariables [algebra R A] [is_scalar_tower R A B]\n\n/-- If A is an R-algebra all of whose elements are integral over R,\nand x is an element of an A-algebra that is integral over A, then x is integral over R.-/\nlemma is_integral_trans (A_int : is_integral R A) (x : B) (hx : is_integral A x) :\n  is_integral R x :=\nbegin\n  rcases hx with \u27e8p, pmonic, hp\u27e9,\n  let S : set B := \u2191(p.map $ algebra_map A B).frange,\n  refine is_integral_of_mem_of_fg (adjoin R (S \u222a {x})) _ _ (subset_adjoin $ or.inr rfl),\n  refine fg_trans (fg_adjoin_of_finite (finset.finite_to_set _) (\u03bb x hx, _)) _,\n  { rw [finset.mem_coe, finsupp.mem_frange] at hx, rcases hx with \u27e8_, i, rfl\u27e9,\n    show is_integral R ((p.map $ algebra_map A B).coeff i), rw coeff_map,\n    convert is_integral_alg_hom (is_scalar_tower.to_alg_hom R A B) (A_int _) },\n  { apply fg_adjoin_singleton_of_integral,\n    exact is_integral_trans_aux _ pmonic hp }\nend\n\n/-- If A is an R-algebra all of whose elements are integral over R,\nand B is an A-algebra all of whose elements are integral over A,\nthen all elements of B are integral over R.-/\nlemma algebra.is_integral_trans (hA : is_integral R A) (hB : is_integral A B) : is_integral R B :=\n\u03bb x, is_integral_trans hA x (hB x)\n\nlemma ring_hom.is_integral_trans (hf : f.is_integral) (hg : g.is_integral) :\n  (g.comp f).is_integral :=\n@algebra.is_integral_trans R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra\n  (@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra\n  (ring_hom.comp_apply g f)) hf hg\n\nlemma ring_hom.is_integral_of_surjective (hf : function.surjective f) : f.is_integral :=\n\u03bb x, (hf x).rec_on (\u03bb y hy, (hy \u25b8 f.is_integral_map : f.is_integral_elem x))\n\nlemma is_integral_of_surjective (h : function.surjective (algebra_map R A)) : is_integral R A :=\n(algebra_map R A).is_integral_of_surjective h\n\n/-- If `R \u2192 A \u2192 B` is an algebra tower with `A \u2192 B` injective,\nthen if the entire tower is an integral extension so is `R \u2192 A` -/\nlemma is_integral_tower_bot_of_is_integral (H : function.injective (algebra_map A B))\n  {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x :=\nbegin\n  rcases h with \u27e8p, \u27e8hp, hp'\u27e9\u27e9,\n  refine \u27e8p, \u27e8hp, _\u27e9\u27e9,\n  rw [is_scalar_tower.algebra_map_eq R A B, \u2190 eval\u2082_map,\n      eval\u2082_hom, \u2190 ring_hom.map_zero (algebra_map A B)] at hp',\n  rw [eval\u2082_eq_eval_map],\n  exact H hp',\nend\n\nlemma ring_hom.is_integral_tower_bot_of_is_integral (hg : function.injective g)\n  (hfg : (g.comp f).is_integral) : f.is_integral :=\n\u03bb x,\n  @is_integral_tower_bot_of_is_integral R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra\n  (@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra\n  (ring_hom.comp_apply g f))  hg x (hfg (g x))\n\nlemma is_integral_tower_bot_of_is_integral_field {R A B : Type*} [comm_ring R] [field A]\n  [comm_ring B] [nontrivial B] [algebra R A] [algebra A B] [algebra R B] [is_scalar_tower R A B]\n  {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x :=\nis_integral_tower_bot_of_is_integral (algebra_map A B).injective h\n\nlemma ring_hom.is_integral_elem_of_is_integral_elem_comp {x : T}\n  (h : (g.comp f).is_integral_elem x) : g.is_integral_elem x :=\nlet \u27e8p, \u27e8hp, hp'\u27e9\u27e9 := h in \u27e8p.map f, monic_map f hp, by rwa \u2190 eval\u2082_map at hp'\u27e9\n\nlemma ring_hom.is_integral_tower_top_of_is_integral (h : (g.comp f).is_integral) : g.is_integral :=\n\u03bb x, ring_hom.is_integral_elem_of_is_integral_elem_comp f g (h x)\n\n/-- If `R \u2192 A \u2192 B` is an algebra tower,\nthen if the entire tower is an integral extension so is `A \u2192 B`. -/\nlemma is_integral_tower_top_of_is_integral {x : B} (h : is_integral R x) : is_integral A x :=\nbegin\n  rcases h with \u27e8p, \u27e8hp, hp'\u27e9\u27e9,\n  refine \u27e8p.map (algebra_map R A), \u27e8monic_map (algebra_map R A) hp, _\u27e9\u27e9,\n  rw [is_scalar_tower.algebra_map_eq R A B, \u2190 eval\u2082_map] at hp',\n  exact hp',\nend\n\nlemma ring_hom.is_integral_quotient_of_is_integral {I : ideal S} (hf : f.is_integral) :\n  (ideal.quotient_map I f le_rfl).is_integral :=\nbegin\n  rintros \u27e8x\u27e9,\n  obtain \u27e8p, \u27e8p_monic, hpx\u27e9\u27e9 := hf x,\n  refine \u27e8p.map (ideal.quotient.mk _), \u27e8monic_map _ p_monic, _\u27e9\u27e9,\n  simpa only [hom_eval\u2082, eval\u2082_map] using congr_arg (ideal.quotient.mk I) hpx\nend\n\nlemma is_integral_quotient_of_is_integral {I : ideal A} (hRA : is_integral R A) :\n  is_integral (I.comap (algebra_map R A)).quotient I.quotient :=\n(algebra_map R A).is_integral_quotient_of_is_integral hRA\n\nlemma is_integral_quotient_map_iff {I : ideal S} :\n  (ideal.quotient_map I f le_rfl).is_integral \u2194\n    ((ideal.quotient.mk I).comp f : R \u2192+* I.quotient).is_integral :=\nbegin\n  let g := ideal.quotient.mk (I.comap f),\n  have := ideal.quotient_map_comp_mk le_rfl,\n  refine \u27e8\u03bb h, _, \u03bb h, ring_hom.is_integral_tower_top_of_is_integral g _ (this \u25b8 h)\u27e9,\n  refine this \u25b8 ring_hom.is_integral_trans g (ideal.quotient_map I f le_rfl) _ h,\n  exact ring_hom.is_integral_of_surjective g ideal.quotient.mk_surjective,\nend\n\n/-- If the integral extension `R \u2192 S` is injective, and `S` is a field, then `R` is also a field. -/\nlemma is_field_of_is_integral_of_is_field {R S : Type*} [integral_domain R] [integral_domain S]\n  [algebra R S] (H : is_integral R S) (hRS : function.injective (algebra_map R S))\n  (hS : is_field S) : is_field R :=\nbegin\n  refine \u27e8\u27e80, 1, zero_ne_one\u27e9, mul_comm, \u03bb a ha, _\u27e9,\n  -- Let `a_inv` be the inverse of `algebra_map R S a`,\n  -- then we need to show that `a_inv` is of the form `algebra_map R S b`.\n  obtain \u27e8a_inv, ha_inv\u27e9 := hS.mul_inv_cancel (\u03bb h, ha (hRS (trans h (ring_hom.map_zero _).symm))),\n\n  -- Let `p : polynomial R` be monic with root `a_inv`,\n  -- and `q` be `p` with coefficients reversed (so `q(a) = q'(a) * a + 1`).\n  -- We claim that `q(a) = 0`, so `-q'(a)` is the inverse of `a`.\n  obtain \u27e8p, p_monic, hp\u27e9 := H a_inv,\n  use -\u2211 (i : \u2115) in finset.range p.nat_degree, (p.coeff i) * a ^ (p.nat_degree - i - 1),\n\n  -- `q(a) = 0`, because multiplying everything with `a_inv^n` gives `p(a_inv) = 0`.\n  -- TODO: this could be a lemma for `polynomial.reverse`.\n  have hq : \u2211 (i : \u2115) in finset.range (p.nat_degree + 1), (p.coeff i) * a ^ (p.nat_degree - i) = 0,\n  { apply (algebra_map R S).injective_iff.mp hRS,\n    have a_inv_ne_zero : a_inv \u2260 0 := right_ne_zero_of_mul (mt ha_inv.symm.trans one_ne_zero),\n    refine (mul_eq_zero.mp _).resolve_right (pow_ne_zero p.nat_degree a_inv_ne_zero),\n    rw [eval\u2082_eq_sum_range] at hp,\n    rw [ring_hom.map_sum, finset.sum_mul],\n    refine (finset.sum_congr rfl (\u03bb i hi, _)).trans hp,\n    rw [ring_hom.map_mul, mul_assoc],\n    congr,\n    have : a_inv ^ p.nat_degree = a_inv ^ (p.nat_degree - i) * a_inv ^ i,\n    { rw [\u2190 pow_add a_inv, nat.sub_add_cancel (nat.le_of_lt_succ (finset.mem_range.mp hi))] },\n    rw [ring_hom.map_pow, this, \u2190 mul_assoc, \u2190 mul_pow, ha_inv, one_pow, one_mul] },\n\n  -- Since `q(a) = 0` and `q(a) = q'(a) * a + 1`, we have `a * -q'(a) = 1`.\n  -- TODO: we could use a lemma for `polynomial.div_X` here.\n  rw [finset.sum_range_succ_comm, p_monic.coeff_nat_degree, one_mul, nat.sub_self, pow_zero,\n      add_eq_zero_iff_eq_neg, eq_comm] at hq,\n  rw [mul_comm, \u2190 neg_mul_eq_neg_mul, finset.sum_mul],\n  convert hq using 2,\n  refine finset.sum_congr rfl (\u03bb i hi, _),\n  have : 1 \u2264 p.nat_degree - i := nat.le_sub_left_of_add_le (finset.mem_range.mp hi),\n  rw [mul_assoc, \u2190 pow_succ', nat.sub_add_cancel this]\nend\n\nend algebra\n\nsection\nlocal attribute [instance] subset.comm_ring algebra.of_is_subring\ntheorem integral_closure_idem {R : Type*} {A : Type*} [comm_ring R] [comm_ring A] [algebra R A] :\n  integral_closure (integral_closure R A : set A) A = \u22a5 :=\neq_bot_iff.2 $ \u03bb x hx, algebra.mem_bot.2\n\u27e8\u27e8x, @is_integral_trans _ _ _ _ _ _ _ _ (integral_closure R A).algebra\n     _ integral_closure.is_integral x hx\u27e9, rfl\u27e9\nend\n\nsection integral_domain\nvariables {R S : Type*} [comm_ring R] [integral_domain S] [algebra R S]\n\ninstance : integral_domain (integral_closure R S) :=\ninfer_instance\n\nend integral_domain\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/ring_theory/integral_closure.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7027911183904142}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n\nA square root function.\n\nNOTE : I wrote this before square roots were in mathlib; users should\nuse mathlib's version of square root now.\n\n1) The non-computable function\n\n  square_root : \u03a0 (x : \u211d), x \u2265 0 \u2192 \u211d\n\nreturns the non-negative square root of x, defined as the sup of all\nthe reals whose square is at most x.\n\n2) The non-computable function\n\nsqrt_abs : \u211d \u2192 \u211d\n\nsends a real number x to the non-negative square root of abs x (a.k.a. |x|).\n\n-/\n\nimport analysis.real tactic.norm_num\n-- analysis.real -- for reals\n-- tactic.norm_num -- because I want to do proofs of things like 1/4 < 1 in \u211d quickly\n\n-- Can I just dump the below things into Lean within no namespace?\ninfix ` ** `: 80 := monoid.pow \n\ntheorem pow_two_eq_mul_self {\u03b1 : Type} [monoid \u03b1] {x : \u03b1} : x ** 2 = x * x :=\nby simp [monoid.pow]\n\ntheorem mul_self_eq_pow_two {\u03b1 : Type} [monoid \u03b1] {x : \u03b1} : x * x = x ** 2 :=\neq.symm pow_two_eq_mul_self\n\ntheorem imp_of_not_or {A B : Prop} : (A \u2228 B) \u2192 (\u00ac A) \u2192 B := by cc\n\n/-\n\nPossibly more useful:\n\n#check @nonneg_le_nonneg_of_squares_le\nnonneg_le_nonneg_of_squares_le :\n  \u2200 {\u03b1 : Type u_1} [_inst_1 : linear_ordered_ring \u03b1] {a b : \u03b1}, b \u2265 0 \u2192 a * a \u2264 b * b \u2192 a \u2264 b\n-/\n\nnamespace square_root -- I have no idea whether this is the right thing to do\n\nopen square_root\n\n\n\ntheorem square_inj_on_nonneg {x y : \u211d} : (x \u2265 0) \u2192 (y \u2265 0) \u2192 (x**2 = y**2) \u2192 (x=y) :=\nbegin\nassume H_x_ge_zero : x \u2265 0,\nassume H_y_ge_zero : y \u2265 0,\nassume H : x ** 2 = y ** 2,\nrw [pow_two_eq_mul_self,pow_two_eq_mul_self] at H,\nhave Hle : x \u2264 y := nonneg_le_nonneg_of_squares_le H_y_ge_zero (le_of_eq H),\nhave Hge : y \u2264 x := nonneg_le_nonneg_of_squares_le H_x_ge_zero (le_of_eq H.symm),\nexact le_antisymm Hle Hge,\nend\n\ntheorem square_cont_at_zero : \u2200 (r : \u211d), r > 0 \u2192 \n                          \u2203 (eps : \u211d), (eps > 0) \u2227 eps ** 2 < r :=\nbegin\nintros r Hr_gt_0,\ncases lt_or_ge r 1 with Hrl1 Hrge1,\n  have H : r**2<r,\n    unfold monoid.pow,\n    exact calc r*(r*1) = r*r : by simp\n    ... < r*1 : mul_lt_mul_of_pos_left Hrl1 Hr_gt_0\n    ... = r : mul_one r,\n  existsi r,\n  exact \u27e8Hr_gt_0,H\u27e9,\ncases le_iff_eq_or_lt.mp Hrge1 with r1 rg1,\n  rw [\u2190r1],\n  exact \u27e8((1/2):\u211d),by norm_num\u27e9, \nexistsi (1:\u211d),\nsplit,\n  exact zero_lt_one,\nconvert rg1,\nunfold monoid.pow,\nsimp,\nend\n\n-- #check @nonneg_le_nonneg_of_squares_le\n-- \u2200 {\u03b1 : Type u_1} [_inst_1 : linear_ordered_ring \u03b1] {a b : \u03b1}, \n-- b \u2265 0 \u2192 a * a \u2264 b * b \u2192 a \u2264 b\n\ntheorem exists_square_root (r:\u211d) (rnneg : r \u2265 0) : \u2203 (q : \u211d), (q \u2265 0) \u2227 q**2=r :=\nbegin\ncases le_iff_eq_or_lt.mp rnneg with r0 rpos,\n  rw [\u2190r0],\n  exact \u27e8(0:\u211d),by norm_num\u27e9,\nclear rnneg,\nlet S := { x:\u211d | x**2 \u2264 r},\n-- S non-empty\nhave H0 : (0:\u211d) \u2208 S,\n  suffices : 0 \u2264 r, by simpa [pow_two_eq_mul_self],\n  exact le_of_lt rpos,\n-- S has upper bound\nhave H1 : max r 1 \u2208 upper_bounds S,\n  cases classical.em (r \u2264 1) with rle1 rgt1,\n    intros t Ht,\n    suffices H : t \u2264 1,\n      exact le_trans H (le_max_right r 1),\n    exact nonneg_le_nonneg_of_squares_le (zero_le_one) (by rw [mul_one,\u2190pow_two_eq_mul_self];exact (le_trans Ht rle1)),\n  have H : 1<r,\n    exact lt_of_not_ge rgt1,\n  clear rgt1,\n  intros t Ht,\n  suffices H : t \u2264 r,\n    exact le_trans H (le_max_left r 1),\n  -- need to prove t^2<=r implies t<=r\n  apply imp_of_not_or (lt_or_ge r t),\n  assume H1 : r<t,\n  apply not_le_of_gt H1,\n  apply nonneg_le_nonneg_of_squares_le (le_of_lt rpos),\n  exact le_of_lt (calc t*t=t**2 : mul_self_eq_pow_two\n  ... \u2264 r : Ht\n  ... = r*1 : eq.symm (mul_one r)\n  ... < r*r : mul_lt_mul_of_pos_left H rpos),\n-- get LUB\nhave H : \u2203 (x : \u211d), is_lub S x,\n  exact exists_supremum_real H0 H1,\ncases H with q Hq,\nexistsi q,\nhave Hqge0 : 0 \u2264 q,\n  exact Hq.left 0 H0,\nsplit,\n  exact Hqge0,\n-- I tidied the code up, up to here; the rest is my original effort.\n-- idea is to prove q^2=r by showing not < or >\n-- first not <\nhave H2 : \u00ac (q**2<r),\n  intro Hq2r,\n  have H2 : q \u2208 upper_bounds S,\n    exact Hq.left,\n  clear Hq H0 H1,\n  unfold upper_bounds at H2,\n  have H3 : \u2200 qe, q<qe \u2192 \u00ac(qe**2\u2264r),\n    intro qe,\n    intro qlqe,\n    intro H4,\n    have H5 : qe \u2264 q,\n      exact H2 qe H4,\n    exact not_lt_of_ge H5 qlqe,\n  have H4 : \u2200 eps > 0,(q+eps)**2>r,\n    intros eps Heps,\n    exact lt_of_not_ge (H3 (q+eps) ((lt_add_iff_pos_right q).mpr Heps)),\n  clear H3 H2 S,\n  cases le_iff_eq_or_lt.mp Hqge0 with Hq0 Hqg0,\n    cases (square_cont_at_zero r rpos) with eps Heps,\n    specialize H4 eps,\n    rw [\u2190Hq0] at H4,\n    simp at H4,\n    have H3 : eps**2>r,\n      exact H4 Heps.left,\n    exact (lt_iff_not_ge r (eps**2)).mp H3 (le_of_lt Heps.right), \n  clear Hqge0,\n  -- want eps such that 2*q*eps+eps^2 <= r-q^2\n  -- so eps=min((r-q^2)/4q,thing-produced-by-square-cts-function)\n  have H0 : (0:\u211d)<2, \n    norm_num,\n  have H : 0<(r-q**2),\n    exact sub_pos_of_lt Hq2r,\n  have H2 : 0 < (r-q**2)/2,\n    exact div_pos_of_pos_of_pos H H0,\n  have H3 : 0 < (r-q**2)/2/(2*q),\n    exact div_pos_of_pos_of_pos H2 (mul_pos H0 Hqg0),\n  cases (square_cont_at_zero ((r-q**2)/2) H2) with e0 He0,\n  let e1 := min ((r-q**2)/2/(2*q)) e0,\n  have He1 : e1>0,\n    exact lt_min H3 He0.left,\n  specialize H4 e1, -- should be a contradiction\n  have H1 : (q+e1)**2 > r,\n    exact H4 He1,\n  have H5 : e1 \u2264 ((r-q**2)/2/(2*q)),\n    exact (min_le_left ((r-q**2)/2/(2*q)) e0),\n  have H6 : e1*e1<(r - q ** 2) / 2,\n    exact calc e1*e1 \u2264 e0*e1 : mul_le_mul_of_nonneg_right (min_le_right ((r - q ** 2) / 2 / (2 * q)) e0) (le_of_lt He1)\n    ... \u2264 e0*e0 : mul_le_mul_of_nonneg_left (min_le_right ((r - q ** 2) / 2 / (2 * q)) e0) (le_of_lt He0.left )\n    ... = e0**2 :  by {unfold monoid.pow,simp}\n    ... < (r-q**2)/2 : He0.right,\n  have Hn1 : (q+e1)**2 < r,\n    exact calc (q+e1)**2 = (q+e1)*(q+e1) : by {unfold monoid.pow,simp}\n    ... = q*q+2*q*e1+e1*e1 : by rw [mul_add,add_mul,add_mul,mul_comm e1 q,two_mul,add_mul,add_assoc,add_assoc,add_assoc]\n    ... = q**2 + (2*q)*e1 + e1*e1 : by {unfold monoid.pow,simp}\n    ... \u2264 q**2 + (2*q)*((r - q ** 2) / 2 / (2 * q)) + e1*e1 : add_le_add_right (add_le_add_left ((mul_le_mul_left (mul_pos H0 Hqg0)).mpr H5) (q**2)) (e1*e1)\n    ... < q**2 + (2*q)*((r - q ** 2) / 2 / (2 * q)) + (r-q**2)/2 : add_lt_add_left H6 _\n    ... = r : by rw [mul_comm,div_mul_eq_mul_div,mul_div_assoc,div_self (ne_of_gt (mul_pos H0 Hqg0)),mul_one,add_assoc,div_add_div_same,\u2190two_mul,mul_comm,mul_div_assoc,div_self (ne_of_gt H0),mul_one,add_sub,add_comm,\u2190add_sub,sub_self,add_zero], -- rw [mul_div_cancel'], -- nearly there\nexact not_lt_of_ge (le_of_lt H1) Hn1,\n-- now not >\nhave H3 : \u00ac (q**2>r),\n  intro Hq2r,\n  have H3 : q \u2208 lower_bounds (upper_bounds S),\n    exact Hq.right,\n  clear Hq H0 H1 H2,\n  have Hqg0 : 0 < q,\n    cases le_iff_eq_or_lt.mp Hqge0 with Hq0 H,\n      tactic.swap,\n      exact H,\n    unfold monoid.pow at Hq2r,\n    rw [\u2190Hq0] at Hq2r,\n    simp at Hq2r,\n    exfalso,\n    exact not_lt_of_ge (le_of_lt rpos) Hq2r,\n  clear Hqge0,\n  have H : \u2200 (eps:\u211d), (eps > 0 \u2227 eps < q) \u2192 (q-eps)**2 < r,\n    unfold lower_bounds at H3,\n    unfold set_of at H3,\n    unfold has_mem.mem set.mem has_mem.mem at H3,\n    intros eps Heps,\n    have H : \u00ac ((q-eps) \u2208 (upper_bounds S)),\n      intro H,\n      have H2 : q \u2264 q-eps,\n        exact H3 (q-eps) H,\n      rw [le_sub_iff_add_le] at H2,\n      have Hf : q<q, \n        exact calc \n        q < eps+q : lt_add_of_pos_left q Heps.left\n        ...   = q+eps : add_comm eps q\n        ... \u2264 q : H2, \n      have Hf2 : \u00ac (q=q),\n        exact ne_of_lt Hf,\n      exact Hf2 (by simp),\n    unfold upper_bounds at H,\n    unfold has_mem.mem set.mem has_mem.mem set_of at H,\n    have H2 : \u2203 (b:\u211d), \u00ac (S b \u2192 b \u2264 q-eps),\n      exact classical.not_forall.mp H, \n    cases H2 with b Hb,\n    clear H,\n    cases classical.em (S b) with Hsb Hsnb,\n      tactic.swap,\n      have Hnb : S b \u2192 b \u2264 q - eps,\n        intro Hsb,\n        exfalso,\n        exact Hsnb Hsb,\n      exfalso,\n      exact Hb Hnb,\n    cases classical.em (b \u2264 q - eps) with Hlt Hg,\n      exfalso,\n      exact Hb (\u03bb _,Hlt),\n    have Hh : q-eps < b,\n      exact lt_of_not_ge Hg,\n    clear Hg Hb,\n    -- todo: (q-eps)>0, (q-eps)^2<b^2<=r, \n    have H0 : 0<q-eps,\n      rw [lt_sub_iff,zero_add],exact Heps.right,\n    unfold monoid.pow,\n    exact calc (q-eps)*((q-eps)*1) = (q-eps)*(q-eps) : congr_arg (\u03bb t, (q-eps)*t) (mul_one (q-eps))\n    ... < (q-eps) * b : mul_lt_mul_of_pos_left Hh H0\n    ... < b * b : mul_lt_mul_of_pos_right Hh (lt_trans H0 Hh)\n    ... = b**2 : by { unfold monoid.pow, simp}\n    ... \u2264 r : Hsb,\n  -- We now know (q-eps)^2<r for all eps>0, and q^2>r. Need a contradiction.\n  -- Idea: (q^2-2*q*eps+eps^2)<r so 2q.eps-eps^2>q^2-r>0, \n  -- so we need to find eps such that 2q.eps-eps^2<(q^2-r)\n  -- so set eps=min((q^2-r)/2q,q)\n  have H0 : (0:\u211d)<2, \n    norm_num,\n  have H1 : 0<(q**2-r),\n    exact sub_pos_of_lt Hq2r,\n  have H2 : 0 < (q/2),\n    exact div_pos_of_pos_of_pos Hqg0 H0,\n  have J1 : 0 < (q**2-r)/(2*q),\n    exact div_pos_of_pos_of_pos H1 (mul_pos H0 Hqg0),\n  let e1 := min ((q**2-r)/(2*q)) (q/2),\n  have He1 : e1>0,\n    exact lt_min J1 H2,\n  specialize H e1, -- should be a contradiction\n  have J0 : e1<q,\n    exact calc e1 \u2264 (q/2) : min_le_right ((q**2-r)/(2*q)) (q/2)\n    ... = q*(1/2) : by rw [\u2190mul_div_assoc,mul_one]\n    ... < q*1 : mul_lt_mul_of_pos_left (by norm_num) Hqg0\n    ... = q : by rw [mul_one],\n  have H4 : (q-e1)**2 < r,\n    exact H \u27e8He1,J0\u27e9,\n  have H5 : e1 \u2264 ((q**2-r)/(2*q)),\n    exact (min_le_left ((q**2-r)/(2*q)) (q/2)),\n  have H6 : e1*e1>0,\n    exact mul_pos He1 He1,\n  have Hn1 : (q-e1)**2 > r,\n    exact calc (q-e1)**2 = (q-e1)*(q-e1) : by {unfold monoid.pow,simp}\n    ... = q*q-2*q*e1+e1*e1 : by rw [mul_sub,sub_mul,sub_mul,mul_comm e1 q,two_mul,add_mul];simp\n    ... = q**2 - (2*q)*e1 + e1*e1 : by {unfold monoid.pow,simp}\n    ... > q**2 - (2*q)*e1         : lt_add_of_pos_right (q**2 -(2*q)*e1) H6\n    ... \u2265 q**2 - (2*q)*((q ** 2 - r) / (2 * q)) : sub_le_sub (le_of_eq (eq.refl (q**2))) (mul_le_mul_of_nonneg_left H5 (le_of_lt (mul_pos H0 Hqg0))) -- lt_add_iff_pos_right  -- (add_le_add_left ((mul_le_mul_left (mul_pos H0 Hqg0)).mpr H5) (q^2)) (e1*e1)\n    ... = r : by rw [\u2190div_mul_eq_mul_div_comm,div_self (ne_of_gt (mul_pos H0 Hqg0)),one_mul];simp, --     ... = r : by rw [mul_comm,div_mul_eq_mul_div,mul_div_assoc,div_self (ne_of_gt (mul_pos H0 Hqg0)),mul_one,add_assoc,div_add_div_same,\u2190two_mul,mul_comm,mul_div_assoc,div_self (ne_of_gt H0),mul_one,add_sub,add_comm,\u2190add_sub,sub_self,add_zero], -- rw [mul_div_cancel'], -- nearly there\n\n    exact not_lt_of_ge (le_of_lt (H \u27e8He1,J0\u27e9)) Hn1,\n  have H : q**2 \u2264 r,\n    exact le_of_not_lt H3,\n  cases lt_or_eq_of_le H with Hlt Heq,\n    exfalso,\n    exact H2 Hlt,\n  rw \u2190Heq,\n  exact mul_self_eq_pow_two\nend\n\n\n\n-- #check exists_square_root\n-- exists_square_root : \u2200 (r : \u211d), r \u2265 0 \u2192 (\u2203 (q : \u211d), q \u2265 0 \u2227 q ^ 2 = r)\n\ntheorem exists_unique_square_root : \u2200 (r:\u211d), (r \u2265 0) \u2192 \u2203 (q:\u211d), (q \u2265 0 \u2227 q**2 = r \u2227 \u2200 (s:\u211d), s \u2265 0 \u2227 s**2 = r \u2192 s=q) :=\nbegin\nintro r,\nassume H_r_ge_zero : r \u2265 0,\ncases (exists_square_root r H_r_ge_zero) with q H_q_squared_is_r,\nsuffices H_unique : \u2200 (s:\u211d), s \u2265 0 \u2227 s ** 2 = r \u2192 s = q,\n  exact \u27e8q,\u27e8H_q_squared_is_r.left,\u27e8H_q_squared_is_r.right,H_unique\u27e9\u27e9\u27e9, \nintro s,\nassume H_s_ge_zero_and_square_is_r,\nexact square_inj_on_nonneg H_s_ge_zero_and_square_is_r.left H_q_squared_is_r.left (eq.trans H_s_ge_zero_and_square_is_r.right (eq.symm H_q_squared_is_r.right))\nend\n\nnoncomputable def square_root (x:\u211d) (H_x_nonneg : x \u2265 0) : \u211d := classical.some (exists_unique_square_root x H_x_nonneg)\n\n-- #reduce (square_root 2 (by norm_num)) -- oops\n\n-- Next is what Mario says I should do (at least in terms of where the proof that x>=0 goes)\n\nnoncomputable def sqrt_abs (x : \u211d) : \u211d := square_root (abs x) (abs_nonneg x)\n\ndef square_root_proof (x:\u211d) (h : x \u2265 0) : (square_root x h) ** 2 = x := \n(classical.some_spec (exists_unique_square_root x h)).right.left\n\ndef square_root_allinfo (x:\u211d) (h : x \u2265 0) := \nclassical.some_spec (exists_unique_square_root x h)\n\ntheorem sqrt_abs_ge_zero (x : \u211d) : sqrt_abs x \u2265 0 :=\n(classical.some_spec (exists_unique_square_root (abs x) (abs_nonneg x))).left\n\ntheorem sqrt_abs_unique (x : \u211d) (Hx_nonneg : 0 \u2264 x) : \u2200 (s : \u211d), s \u2265 0 \u2227 s ** 2 = x \u2192 s = sqrt_abs x :=\nbegin\nhave H : \u2200 (s : \u211d), s \u2265 0 \u2227 s ** 2 = abs x \u2192 s = square_root (abs x) (abs_nonneg x),\n  exact (classical.some_spec (exists_unique_square_root (abs x) (abs_nonneg x))).right.right,\nintro s,\nintro Hs,\nrw [eq.symm (abs_of_nonneg Hx_nonneg)] at Hs,\nexact H s Hs,\nend\n\n\ntheorem sqrt_abs_squared (x : \u211d) (Hx_nonneg : 0 \u2264 x) : (sqrt_abs x) ** 2 = x :=\nbegin\nhave H0 : sqrt_abs x ** 2 = abs x,\n  exact square_root_proof (abs x) (abs_nonneg x),\nrw [H0],\nexact abs_of_nonneg Hx_nonneg,\nend\n\ntheorem sqrt_abs_mul_self (x : \u211d) (Hx_nonneg : 0 \u2264 x) : (sqrt_abs x) * (sqrt_abs x) = x :=\nbegin\nrw [mul_self_eq_pow_two],\nexact sqrt_abs_squared x Hx_nonneg,\nend\n\nmeta def sqrt_tac : tactic unit := `[assumption <|> norm_num]\nnoncomputable def sqrt (r : \u211d) (h : r \u2265 0 . sqrt_tac) : \u211d :=\nclassical.some (exists_unique_square_root r h)\n\n\n/- example of usage:\n\nnoncomputable def s2 : \u211d := sqrt 2\nexample : s2^2=2 := sqrt_proof 2\n\n-/\n\nend square_root\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/xenalib/M1F/square_root.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7027911176312394}}
{"text": "import game.world4.level7 -- hide\n-- incantation for importing ring into framework -- hide\nimport tactic.ring -- hide\nmeta def nat_num_game.interactive.ring := tactic.interactive.ring -- hide\nnamespace mynat -- hide\n\ndef two_eq_succ_one : (2 : mynat) = succ 1 := rfl -- hide\n\n/- \n# Power World\n-/\n\n/-\n## Level 8: `add_squared`\n\n[final boss music] \n\nYou see something written on the stone dungeon wall:\n```\nbegin\n  rw two_eq_succ_one,\n  rw one_eq_succ_zero,\n  repeat {rw pow_succ},\n  ...\n```\n\nand you can't make out the last two lines because there's a kind\nof thing in the way that will magically disappear\nbut only when you've beaten the boss.\n\n-/\n\n/- Theorem\nFor all naturals $a$ and $b$, we have\n$$(a+b)^2=a^2+b^2+2ab.$$\n-/\nlemma add_squared (a b : mynat) :\n  (a + b) ^ (2 : mynat) = a ^ (2 : mynat) + b ^ (2 : mynat) + 2 * a * b :=\nbegin [nat_num_game]\n  rw two_eq_succ_one,\n  rw one_eq_succ_zero,\n  repeat {rw pow_succ},\n  repeat {rw pow_zero},\n  ring,\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend\n\n/- \nAs the boss lies smouldering, you notice on the dungeon wall that\n<a href=\"https://twitter.com/XenaProject/status/1190453646904958976?s=20/\" target=\"blank\">\ntwo more lines of code are now visible under the first three...</a> (Twitter.com)\n\nI just beat this level with 27 single rewrites followed by a `refl`. \nCan you do any better? (The current rewrite record is 25 -- see <a href=\"https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/function.20with.20random.20definition/near/179723073\" target=\"blank\">here</a>\n(needs zulip login)).\nIf you beat it then well done! Do you\nfancy doing $(a+b)^3$ now? You might want to read \n<a href=\"https://xenaproject.wordpress.com/2018/06/13/ab3/\" target=\"blank\">\nthis Xena Project blog post</a> before you start though.\n-/\n\n/-\nIf you got this far -- very well done! If you only learnt the three\ntactics `rw`, `induction` and `refl` then there are now more tactics to\nlearn; go back to the main menu and choose Function World. \n\nThe main thing we really want to impress upon people is that we believe\nthat *all of pure mathematics* can be done in this new way.\nA system called Coq (which is very like Lean) has\n<a href=\"https://hal.inria.fr/hal-00816699\" target=\"blank\">\nchecked the proof of the Feit-Thompson theorem</a> (hundreds of pages of\ngroup theory) and Lean has a\n<a href=\"https://leanprover-community.github.io/lean-perfectoid-spaces/\"\n  target=\"blank\">\ndefinition of perfectoid spaces</a> (a very complex modern\nmathematical structure). I believe that these systems will one day\ncause a paradigm shift in the way mathematics is done, but first we need\nto build what we know, or at least build enough to state what we\nmathematicians believe. If you want to get involved, come and join\nus at the <a href=\"https://leanprover.zulipchat.com\" target=\"blank\">Zulip Lean chat</a>.\nThe #new members stream is a great place to start asking questions.\n\nTo come (possibly): the real number game, the group theory game,\nthe integer game, the natural number game 2,... . Alternatively\nsee <a href=\"http://wwwf.imperial.ac.uk/~buzzard/xena/natural_number_game/FAQ.html\" target=\"blank\">the FAQ</a>\nfor some more ideas about what to do next.\n\n-/\n\nend mynat -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world4/level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7027889775783209}}
{"text": "/-\nCopyright (c) 2021 Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bhavik Mehta\n\n! This file was ported from Lean 3 source module category_theory.limits.constructions.weakly_initial\n! leanprover-community/mathlib commit 239d882c4fb58361ee8b3b39fb2091320edef10a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.CategoryTheory.Limits.Shapes.WideEqualizers\nimport Mathbin.CategoryTheory.Limits.Shapes.Products\nimport Mathbin.CategoryTheory.Limits.Shapes.Terminal\n\n/-!\n# Constructions related to weakly initial objects\n\nThis file gives constructions related to weakly initial objects, namely:\n* If a category has small products and a small weakly initial set of objects, then it has a weakly\n  initial object.\n* If a category has wide equalizers and a weakly initial object, then it has an initial object.\n\nThese are primarily useful to show the General Adjoint Functor Theorem.\n-/\n\n\nuniverse v u\n\nnamespace CategoryTheory\n\nopen Limits\n\nvariable {C : Type u} [Category.{v} C]\n\n/--\nIf `C` has (small) products and a small weakly initial set of objects, then it has a weakly initial\nobject.\n-/\ntheorem has_weakly_initial_of_weakly_initial_set_and_hasProducts [HasProducts.{v} C] {\u03b9 : Type v}\n    {B : \u03b9 \u2192 C} (hB : \u2200 A : C, \u2203 i, Nonempty (B i \u27f6 A)) : \u2203 T : C, \u2200 X, Nonempty (T \u27f6 X) :=\n  \u27e8\u220f B, fun X => \u27e8Pi.\u03c0 _ _ \u226b (hB X).choose_spec.some\u27e9\u27e9\n#align category_theory.has_weakly_initial_of_weakly_initial_set_and_has_products CategoryTheory.has_weakly_initial_of_weakly_initial_set_and_hasProducts\n\n/-- If `C` has (small) wide equalizers and a weakly initial object, then it has an initial object.\n\nThe initial object is constructed as the wide equalizer of all endomorphisms on the given weakly\ninitial object.\n-/\ntheorem hasInitial_of_weakly_initial_and_hasWideEqualizers [HasWideEqualizers.{v} C] {T : C}\n    (hT : \u2200 X, Nonempty (T \u27f6 X)) : HasInitial C :=\n  by\n  let endos := T \u27f6 T\n  let i := wide_equalizer.\u03b9 (id : endos \u2192 endos)\n  haveI : Nonempty endos := \u27e8\ud835\udfd9 _\u27e9\n  have : \u2200 X : C, Unique (wide_equalizer (id : endos \u2192 endos) \u27f6 X) :=\n    by\n    intro X\n    refine' \u27e8\u27e8i \u226b Classical.choice (hT X)\u27e9, fun a => _\u27e9\n    let E := equalizer a (i \u226b Classical.choice (hT _))\n    let e : E \u27f6 wide_equalizer id := equalizer.\u03b9 _ _\n    let h : T \u27f6 E := Classical.choice (hT E)\n    have : ((i \u226b h) \u226b e) \u226b i = i \u226b \ud835\udfd9 _ :=\n      by\n      rw [category.assoc, category.assoc]\n      apply wide_equalizer.condition (id : endos \u2192 endos) (h \u226b e \u226b i)\n    rw [category.comp_id, cancel_mono_id i] at this\n    haveI : is_split_epi e := is_split_epi.mk' \u27e8i \u226b h, this\u27e9\n    rw [\u2190 cancel_epi e]\n    apply equalizer.condition\n  exact has_initial_of_unique (wide_equalizer (id : endos \u2192 endos))\n#align category_theory.has_initial_of_weakly_initial_and_has_wide_equalizers CategoryTheory.hasInitial_of_weakly_initial_and_hasWideEqualizers\n\nend CategoryTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/CategoryTheory/Limits/Constructions/WeaklyInitial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.7027889728570279}}
{"text": "open classical\nvariables (A B : Prop)\n\nexample : A \u2228 \u00ac A :=\nby_contradiction\n  (assume h1 : \u00ac (A \u2228 \u00ac A),\n    have h2 : \u00ac A, from\n      assume h3 : A,\n      have h4 : A \u2228 \u00ac A, from or.inl h3,\n      show false, from h1 h4,\n    have h5 : A \u2228 \u00ac A, from or.inr h2,\n    show false, from h1 h5)\n\n  \n\nexample (p : Prop) : p \u2228 \u00ac p :=\nem p\n\nexample (h : \u00ac B \u2192 \u00ac A) : A \u2192 B :=\nassume h1 : A,\nshow B, from\n  by_contradiction\n    (assume h2 : \u00ac B,\n      have h3 : \u00ac A, from h h2,\n      show false, from h3 h1)\n\nexample (h : \u00ac (A \u2227 \u00ac B)) : A \u2192 B :=\nassume : A,\nshow B, from\n  by_contradiction\n    (assume : \u00ac B,\n      have A \u2227 \u00ac B, from and.intro \u2039A\u203a this,\n      show false, from h this)", "meta": {"author": "faustoUrtiz", "repo": "learning-leanprover", "sha": "3acddd0ffb952ce32b0135b8f49de5e930c9820a", "save_path": "github-repos/lean/faustoUrtiz-learning-leanprover", "path": "github-repos/lean/faustoUrtiz-learning-leanprover/learning-leanprover-3acddd0ffb952ce32b0135b8f49de5e930c9820a/classic-reasoning.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.7027506855677815}}
{"text": "-- Math 52: Quiz 5\n-- Open this file in a folder that contains 'utils'.\n\nimport utils\n\ndefinition divides (a b : \u2124) : Prop := \u2203 (k : \u2124), b = a * k\nlocal infix \u2223 := divides\n\naxiom not_3_divides : \u2200 (m : \u2124), \u00ac (3 \u2223 m) \u2194 3 \u2223 m - 1 \u2228 3 \u2223 m + 1\n\ntheorem main : \u2200 (n : \u2124), \u00ac (3 \u2223 n) \u2192 3 \u2223 n * n - 1 :=\nbegin\nsorry\nend\n", "meta": {"author": "UVM-M52", "repo": "quiz-4-williamskaylee", "sha": "206d9b804479b1758c129e4450ab9387cd66fcc6", "save_path": "github-repos/lean/UVM-M52-quiz-4-williamskaylee", "path": "github-repos/lean/UVM-M52-quiz-4-williamskaylee/quiz-4-williamskaylee-206d9b804479b1758c129e4450ab9387cd66fcc6/src/quiz04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.7027367020430049}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\nPorted by: Kevin Buzzard, Ruben Vorster, Scott Morrison, Eric Rodriguez\n\n! This file was ported from Lean 3 source module logic.equiv.basic\n! leanprover-community/mathlib commit d2d8742b0c21426362a9dacebc6005db895ca963\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Bool.Basic\nimport Mathlib.Data.Prod.Basic\nimport Mathlib.Data.Sigma.Basic\nimport Mathlib.Data.Subtype\nimport Mathlib.Data.Sum.Basic\nimport Mathlib.Init.Data.Sigma.Basic\nimport Mathlib.Logic.Equiv.Defs\nimport Mathlib.Logic.Function.Conjugate\nimport Mathlib.Tactic.Convert\nimport Mathlib.Tactic.Contrapose\nimport Mathlib.Tactic.GeneralizeProofs\nimport Mathlib.Tactic.Lift\n\n/-!\n# Equivalence between types\n\nIn this file we continue the work on equivalences begun in `Logic/Equiv/Defs.lean`, defining\n\n* canonical isomorphisms between various types: e.g.,\n\n  - `Equiv.sumEquivSigmaBool` is the canonical equivalence between the sum of two types `\u03b1 \u2295 \u03b2`\n    and the sigma-type `\u03a3 b : Bool, cond b \u03b1 \u03b2`;\n\n  - `Equiv.prodSumDistrib : \u03b1 \u00d7 (\u03b2 \u2295 \u03b3) \u2243 (\u03b1 \u00d7 \u03b2) \u2295 (\u03b1 \u00d7 \u03b3)` shows that type product and type sum\n    satisfy the distributive law up to a canonical equivalence;\n\n* operations on equivalences: e.g.,\n\n  - `Equiv.prodCongr ea eb : \u03b1\u2081 \u00d7 \u03b2\u2081 \u2243 \u03b1\u2082 \u00d7 \u03b2\u2082`: combine two equivalences `ea : \u03b1\u2081 \u2243 \u03b1\u2082` and\n    `eb : \u03b2\u2081 \u2243 \u03b2\u2082` using `Prod.map`.\n\n  More definitions of this kind can be found in other files.\n  E.g., `Data/Equiv/TransferInstance.lean` does it for many algebraic type classes like\n  `Group`, `Module`, etc.\n\n## Tags\n\nequivalence, congruence, bijective map\n-/\n\nopen Function\n\nnamespace Equiv\n\n/-- `PProd \u03b1 \u03b2` is equivalent to `\u03b1 \u00d7 \u03b2` -/\n@[simps apply symm_apply]\ndef pprodEquivProd : PProd \u03b1 \u03b2 \u2243 \u03b1 \u00d7 \u03b2 where\n  toFun x := (x.1, x.2)\n  invFun x := \u27e8x.1, x.2\u27e9\n  left_inv := fun _ => rfl\n  right_inv := fun _ => rfl\n#align equiv.pprod_equiv_prod Equiv.pprodEquivProd\n#align equiv.pprod_equiv_prod_apply Equiv.pprodEquivProd_apply\n#align equiv.pprod_equiv_prod_symm_apply Equiv.pprodEquivProd_symm_apply\n\n/-- Product of two equivalences, in terms of `PProd`. If `\u03b1 \u2243 \u03b2` and `\u03b3 \u2243 \u03b4`, then\n`PProd \u03b1 \u03b3 \u2243 PProd \u03b2 \u03b4`. -/\n-- porting note: in Lean 3 this had @[congr]`\n@[simps apply]\ndef pprodCongr (e\u2081 : \u03b1 \u2243 \u03b2) (e\u2082 : \u03b3 \u2243 \u03b4) : PProd \u03b1 \u03b3 \u2243 PProd \u03b2 \u03b4 where\n  toFun x := \u27e8e\u2081 x.1, e\u2082 x.2\u27e9\n  invFun x := \u27e8e\u2081.symm x.1, e\u2082.symm x.2\u27e9\n  left_inv := fun \u27e8x, y\u27e9 => by simp\n  right_inv := fun \u27e8x, y\u27e9 => by simp\n#align equiv.pprod_congr Equiv.pprodCongr\n#align equiv.pprod_congr_apply Equiv.pprodCongr_apply\n\n/-- Combine two equivalences using `PProd` in the domain and `Prod` in the codomain. -/\n@[simps! apply symm_apply]\ndef pprodProd (ea : \u03b1\u2081 \u2243 \u03b1\u2082) (eb : \u03b2\u2081 \u2243 \u03b2\u2082) :\n    PProd \u03b1\u2081 \u03b2\u2081 \u2243 \u03b1\u2082 \u00d7 \u03b2\u2082 :=\n  (ea.pprodCongr eb).trans pprodEquivProd\n#align equiv.pprod_prod Equiv.pprodProd\n#align equiv.pprod_prod_apply Equiv.pprodProd_apply\n#align equiv.pprod_prod_symm_apply Equiv.pprodProd_symm_apply\n\n/-- Combine two equivalences using `PProd` in the codomain and `Prod` in the domain. -/\n@[simps! apply symm_apply]\ndef prodPProd (ea : \u03b1\u2081 \u2243 \u03b1\u2082) (eb : \u03b2\u2081 \u2243 \u03b2\u2082) :\n    \u03b1\u2081 \u00d7 \u03b2\u2081 \u2243 PProd \u03b1\u2082 \u03b2\u2082 :=\n  (ea.symm.pprodProd eb.symm).symm\n#align equiv.prod_pprod Equiv.prodPProd\n#align equiv.prod_pprod_symm_apply Equiv.prodPProd_symm_apply\n#align equiv.prod_pprod_apply Equiv.prodPProd_apply\n\n/-- `PProd \u03b1 \u03b2` is equivalent to `PLift \u03b1 \u00d7 PLift \u03b2` -/\n@[simps! apply symm_apply]\ndef pprodEquivProdPLift : PProd \u03b1 \u03b2 \u2243 PLift \u03b1 \u00d7 PLift \u03b2 :=\n  Equiv.plift.symm.pprodProd Equiv.plift.symm\n#align equiv.pprod_equiv_prod_plift Equiv.pprodEquivProdPLift\n#align equiv.pprod_equiv_prod_plift_symm_apply Equiv.pprodEquivProdPLift_symm_apply\n#align equiv.pprod_equiv_prod_plift_apply Equiv.pprodEquivProdPLift_apply\n\n/-- Product of two equivalences. If `\u03b1\u2081 \u2243 \u03b1\u2082` and `\u03b2\u2081 \u2243 \u03b2\u2082`, then `\u03b1\u2081 \u00d7 \u03b2\u2081 \u2243 \u03b1\u2082 \u00d7 \u03b2\u2082`. This is\n`Prod.map` as an equivalence. -/\n-- porting note: in Lean 3 there was also a @[congr] tag\n@[simps (config := .asFn) apply]\ndef prodCongr (e\u2081 : \u03b1\u2081 \u2243 \u03b1\u2082) (e\u2082 : \u03b2\u2081 \u2243 \u03b2\u2082) : \u03b1\u2081 \u00d7 \u03b2\u2081 \u2243 \u03b1\u2082 \u00d7 \u03b2\u2082 :=\n  \u27e8Prod.map e\u2081 e\u2082, Prod.map e\u2081.symm e\u2082.symm, fun \u27e8a, b\u27e9 => by simp, fun \u27e8a, b\u27e9 => by simp\u27e9\n#align equiv.prod_congr Equiv.prodCongr\n#align equiv.prod_congr_apply Equiv.prodCongr_apply\n\n@[simp]\ntheorem prodCongr_symm (e\u2081 : \u03b1\u2081 \u2243 \u03b1\u2082) (e\u2082 : \u03b2\u2081 \u2243 \u03b2\u2082) :\n    (prodCongr e\u2081 e\u2082).symm = prodCongr e\u2081.symm e\u2082.symm :=\n  rfl\n#align equiv.prod_congr_symm Equiv.prodCongr_symm\n\n/-- Type product is commutative up to an equivalence: `\u03b1 \u00d7 \u03b2 \u2243 \u03b2 \u00d7 \u03b1`. This is `Prod.swap` as an\nequivalence.-/\ndef prodComm (\u03b1 \u03b2) : \u03b1 \u00d7 \u03b2 \u2243 \u03b2 \u00d7 \u03b1 :=\n  \u27e8Prod.swap, Prod.swap, Prod.swap_swap, Prod.swap_swap\u27e9\n#align equiv.prod_comm Equiv.prodComm\n\n@[simp]\ntheorem coe_prodComm (\u03b1 \u03b2) : (\u21d1(prodComm \u03b1 \u03b2) : \u03b1 \u00d7 \u03b2 \u2192 \u03b2 \u00d7 \u03b1) = Prod.swap :=\n  rfl\n#align equiv.coe_prod_comm Equiv.coe_prodComm\n\n@[simp]\ntheorem prodComm_apply (x : \u03b1 \u00d7 \u03b2) : prodComm \u03b1 \u03b2 x = x.swap :=\n  rfl\n#align equiv.prod_comm_apply Equiv.prodComm_apply\n\n@[simp]\ntheorem prodComm_symm (\u03b1 \u03b2) : (prodComm \u03b1 \u03b2).symm = prodComm \u03b2 \u03b1 :=\n  rfl\n#align equiv.prod_comm_symm Equiv.prodComm_symm\n\n/-- Type product is associative up to an equivalence. -/\n@[simps]\ndef prodAssoc (\u03b1 \u03b2 \u03b3) : (\u03b1 \u00d7 \u03b2) \u00d7 \u03b3 \u2243 \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 :=\n  \u27e8fun p => (p.1.1, p.1.2, p.2), fun p => ((p.1, p.2.1), p.2.2), fun \u27e8\u27e8_, _\u27e9, _\u27e9 => rfl,\n    fun \u27e8_, \u27e8_, _\u27e9\u27e9 => rfl\u27e9\n#align equiv.prod_assoc Equiv.prodAssoc\n#align equiv.prod_assoc_symm_apply Equiv.prodAssoc_symm_apply\n#align equiv.prod_assoc_apply Equiv.prodAssoc_apply\n\n/-- `\u03b3`-valued functions on `\u03b1 \u00d7 \u03b2` are equivalent to functions `\u03b1 \u2192 \u03b2 \u2192 \u03b3`. -/\n@[simps (config := { fullyApplied := false })]\ndef curry (\u03b1 \u03b2 \u03b3) : (\u03b1 \u00d7 \u03b2 \u2192 \u03b3) \u2243 (\u03b1 \u2192 \u03b2 \u2192 \u03b3) where\n  toFun := Function.curry\n  invFun := uncurry\n  left_inv := uncurry_curry\n  right_inv := curry_uncurry\n#align equiv.curry Equiv.curry\n#align equiv.curry_symm_apply Equiv.curry_symm_apply\n#align equiv.curry_apply Equiv.curry_apply\n\nsection\n\n/-- `PUnit` is a right identity for type product up to an equivalence. -/\n@[simps]\ndef prodPUnit (\u03b1) : \u03b1 \u00d7 PUnit \u2243 \u03b1 :=\n  \u27e8fun p => p.1, fun a => (a, PUnit.unit), fun \u27e8_, PUnit.unit\u27e9 => rfl, fun _ => rfl\u27e9\n#align equiv.prod_punit Equiv.prodPUnit\n#align equiv.prod_punit_apply Equiv.prodPUnit_apply\n#align equiv.prod_punit_symm_apply Equiv.prodPUnit_symm_apply\n\n/-- `PUnit` is a left identity for type product up to an equivalence. -/\n@[simps!]\ndef punitProd (\u03b1) : PUnit \u00d7 \u03b1 \u2243 \u03b1 :=\n  calc\n    PUnit \u00d7 \u03b1 \u2243 \u03b1 \u00d7 PUnit := prodComm _ _\n    _ \u2243 \u03b1 := prodPUnit _\n#align equiv.punit_prod Equiv.punitProd\n#align equiv.punit_prod_symm_apply Equiv.punitProd_symm_apply\n#align equiv.punit_prod_apply Equiv.punitProd_apply\n\n/-- Any `Unique` type is a right identity for type product up to equivalence. -/\ndef prodUnique (\u03b1 \u03b2) [Unique \u03b2] : \u03b1 \u00d7 \u03b2 \u2243 \u03b1 :=\n  ((Equiv.refl \u03b1).prodCongr <| equivPUnit.{_,1} \u03b2).trans <| prodPUnit \u03b1\n#align equiv.prod_unique Equiv.prodUnique\n\n@[simp]\ntheorem coe_prodUnique [Unique \u03b2] : (\u21d1(prodUnique \u03b1 \u03b2) : \u03b1 \u00d7 \u03b2 \u2192 \u03b1) = Prod.fst :=\n  rfl\n#align equiv.coe_prod_unique Equiv.coe_prodUnique\n\ntheorem prodUnique_apply [Unique \u03b2] (x : \u03b1 \u00d7 \u03b2) : prodUnique \u03b1 \u03b2 x = x.1 :=\n  rfl\n#align equiv.prod_unique_apply Equiv.prodUnique_apply\n\n@[simp]\ntheorem prodUnique_symm_apply [Unique \u03b2] (x : \u03b1) :\n    (prodUnique \u03b1 \u03b2).symm x = (x, default) :=\n  rfl\n#align equiv.prod_unique_symm_apply Equiv.prodUnique_symm_apply\n\n/-- Any `Unique` type is a left identity for type product up to equivalence. -/\ndef uniqueProd (\u03b1 \u03b2) [Unique \u03b2] : \u03b2 \u00d7 \u03b1 \u2243 \u03b1 :=\n  ((equivPUnit.{_,1} \u03b2).prodCongr <| Equiv.refl \u03b1).trans <| punitProd \u03b1\n#align equiv.unique_prod Equiv.uniqueProd\n\n@[simp]\ntheorem coe_uniqueProd [Unique \u03b2] : (\u21d1(uniqueProd \u03b1 \u03b2) : \u03b2 \u00d7 \u03b1 \u2192 \u03b1) = Prod.snd :=\n  rfl\n#align equiv.coe_unique_prod Equiv.coe_uniqueProd\n\ntheorem uniqueProd_apply [Unique \u03b2] (x : \u03b2 \u00d7 \u03b1) : uniqueProd \u03b1 \u03b2 x = x.2 :=\n  rfl\n#align equiv.unique_prod_apply Equiv.uniqueProd_apply\n\n@[simp]\ntheorem uniqueProd_symm_apply [Unique \u03b2] (x : \u03b1) :\n    (uniqueProd \u03b1 \u03b2).symm x = (default, x) :=\n  rfl\n#align equiv.unique_prod_symm_apply Equiv.uniqueProd_symm_apply\n\n/-- `Empty` type is a right absorbing element for type product up to an equivalence. -/\ndef prodEmpty (\u03b1) : \u03b1 \u00d7 Empty \u2243 Empty :=\n  equivEmpty _\n#align equiv.prod_empty Equiv.prodEmpty\n\n/-- `Empty` type is a left absorbing element for type product up to an equivalence. -/\ndef emptyProd (\u03b1) : Empty \u00d7 \u03b1 \u2243 Empty :=\n  equivEmpty _\n#align equiv.empty_prod Equiv.emptyProd\n\n/-- `PEmpty` type is a right absorbing element for type product up to an equivalence. -/\ndef prodPEmpty (\u03b1) : \u03b1 \u00d7 PEmpty \u2243 PEmpty :=\n  equivPEmpty _\n#align equiv.prod_pempty Equiv.prodPEmpty\n\n/-- `PEmpty` type is a left absorbing element for type product up to an equivalence. -/\ndef pemptyProd (\u03b1) : PEmpty \u00d7 \u03b1 \u2243 PEmpty :=\n  equivPEmpty _\n#align equiv.pempty_prod Equiv.pemptyProd\n\nend\n\nsection\n\nopen Sum\n\n/-- `PSum` is equivalent to `Sum`. -/\ndef psumEquivSum (\u03b1 \u03b2) : PSum \u03b1 \u03b2 \u2243 Sum \u03b1 \u03b2 where\n  toFun s := PSum.casesOn s inl inr\n  invFun := Sum.elim PSum.inl PSum.inr\n  left_inv s := by cases s <;> rfl\n  right_inv s := by cases s <;> rfl\n#align equiv.psum_equiv_sum Equiv.psumEquivSum\n\n/-- If `\u03b1 \u2243 \u03b1'` and `\u03b2 \u2243 \u03b2'`, then `\u03b1 \u2295 \u03b2 \u2243 \u03b1' \u2295 \u03b2'`. This is `Sum.map` as an equivalence. -/\n@[simps apply]\ndef sumCongr (ea : \u03b1\u2081 \u2243 \u03b1\u2082) (eb : \u03b2\u2081 \u2243 \u03b2\u2082) : Sum \u03b1\u2081 \u03b2\u2081 \u2243 Sum \u03b1\u2082 \u03b2\u2082 :=\n  \u27e8Sum.map ea eb, Sum.map ea.symm eb.symm, fun x => by simp, fun x => by simp\u27e9\n#align equiv.sum_congr Equiv.sumCongr\n#align equiv.sum_congr_apply Equiv.sumCongr_apply\n\n/-- If `\u03b1 \u2243 \u03b1'` and `\u03b2 \u2243 \u03b2'`, then `PSum \u03b1 \u03b2 \u2243 PSum \u03b1' \u03b2'`. -/\ndef psumCongr (e\u2081 : \u03b1 \u2243 \u03b2) (e\u2082 : \u03b3 \u2243 \u03b4) : PSum \u03b1 \u03b3 \u2243 PSum \u03b2 \u03b4 where\n  toFun x := PSum.casesOn x (PSum.inl \u2218 e\u2081) (PSum.inr \u2218 e\u2082)\n  invFun x := PSum.casesOn x (PSum.inl \u2218 e\u2081.symm) (PSum.inr \u2218 e\u2082.symm)\n  left_inv := by rintro (x | x) <;> simp\n  right_inv := by rintro (x | x) <;> simp\n#align equiv.psum_congr Equiv.psumCongr\n\n/-- Combine two `Equiv`s using `PSum` in the domain and `Sum` in the codomain. -/\ndef psumSum (ea : \u03b1\u2081 \u2243 \u03b1\u2082) (eb : \u03b2\u2081 \u2243 \u03b2\u2082) :\n    PSum \u03b1\u2081 \u03b2\u2081 \u2243 Sum \u03b1\u2082 \u03b2\u2082 :=\n  (ea.psumCongr eb).trans (psumEquivSum _ _)\n#align equiv.psum_sum Equiv.psumSum\n\n/-- Combine two `Equiv`s using `Sum` in the domain and `PSum` in the codomain. -/\ndef sumPSum (ea : \u03b1\u2081 \u2243 \u03b1\u2082) (eb : \u03b2\u2081 \u2243 \u03b2\u2082) :\n    Sum \u03b1\u2081 \u03b2\u2081 \u2243 PSum \u03b1\u2082 \u03b2\u2082 :=\n  (ea.symm.psumSum eb.symm).symm\n#align equiv.sum_psum Equiv.sumPSum\n\n@[simp]\ntheorem sumCongr_trans (e : \u03b1\u2081 \u2243 \u03b2\u2081) (f : \u03b1\u2082 \u2243 \u03b2\u2082) (g : \u03b2\u2081 \u2243 \u03b3\u2081) (h : \u03b2\u2082 \u2243 \u03b3\u2082) :\n    (Equiv.sumCongr e f).trans (Equiv.sumCongr g h) = Equiv.sumCongr (e.trans g) (f.trans h) := by\n  ext i\n  cases i <;> rfl\n#align equiv.sum_congr_trans Equiv.sumCongr_trans\n\n@[simp]\ntheorem sumCongr_symm (e : \u03b1 \u2243 \u03b2) (f : \u03b3 \u2243 \u03b4) :\n    (Equiv.sumCongr e f).symm = Equiv.sumCongr e.symm f.symm :=\n  rfl\n#align equiv.sum_congr_symm Equiv.sumCongr_symm\n\n@[simp]\ntheorem sumCongr_refl : Equiv.sumCongr (Equiv.refl \u03b1) (Equiv.refl \u03b2) = Equiv.refl (Sum \u03b1 \u03b2) := by\n  ext i\n  cases i <;> rfl\n#align equiv.sum_congr_refl Equiv.sumCongr_refl\n\nnamespace Perm\n\n/-- Combine a permutation of `\u03b1` and of `\u03b2` into a permutation of `\u03b1 \u2295 \u03b2`. -/\n@[reducible]\ndef sumCongr (ea : Equiv.Perm \u03b1) (eb : Equiv.Perm \u03b2) : Equiv.Perm (Sum \u03b1 \u03b2) :=\n  Equiv.sumCongr ea eb\n#align equiv.perm.sum_congr Equiv.Perm.sumCongr\n\n@[simp]\ntheorem sumCongr_apply (ea : Equiv.Perm \u03b1) (eb : Equiv.Perm \u03b2) (x : Sum \u03b1 \u03b2) :\n    sumCongr ea eb x = Sum.map (\u21d1ea) (\u21d1eb) x :=\n  Equiv.sumCongr_apply ea eb x\n#align equiv.perm.sum_congr_apply Equiv.Perm.sumCongr_apply\n\n-- porting note: it seems the general theorem about `Equiv` is now applied, so there's no need\n-- to have this version also have `@[simp]`. Similarly for below.\ntheorem sumCongr_trans (e : Equiv.Perm \u03b1) (f : Equiv.Perm \u03b2) (g : Equiv.Perm \u03b1)\n    (h : Equiv.Perm \u03b2) : (sumCongr e f).trans (sumCongr g h) = sumCongr (e.trans g) (f.trans h) :=\n  Equiv.sumCongr_trans e f g h\n#align equiv.perm.sum_congr_trans Equiv.Perm.sumCongr_trans\n\ntheorem sumCongr_symm (e : Equiv.Perm \u03b1) (f : Equiv.Perm \u03b2) :\n    (sumCongr e f).symm = sumCongr e.symm f.symm :=\n  Equiv.sumCongr_symm e f\n#align equiv.perm.sum_congr_symm Equiv.Perm.sumCongr_symm\n\ntheorem sumCongr_refl : sumCongr (Equiv.refl \u03b1) (Equiv.refl \u03b2) = Equiv.refl (Sum \u03b1 \u03b2) :=\n  Equiv.sumCongr_refl\n#align equiv.perm.sum_congr_refl Equiv.Perm.sumCongr_refl\n\nend Perm\n\n/-- `Bool` is equivalent the sum of two `PUnit`s. -/\ndef boolEquivPUnitSumPUnit : Bool \u2243 Sum PUnit.{u + 1} PUnit.{v + 1} :=\n  \u27e8fun b => cond b (inr PUnit.unit) (inl PUnit.unit), Sum.elim (fun _ => false) fun _ => true,\n    fun b => by cases b <;> rfl, fun s => by rcases s with (\u27e8\u27e8\u27e9\u27e9 | \u27e8\u27e8\u27e9\u27e9) <;> rfl\u27e9\n#align equiv.bool_equiv_punit_sum_punit Equiv.boolEquivPUnitSumPUnit\n\n/-- Sum of types is commutative up to an equivalence. This is `Sum.swap` as an equivalence. -/\n@[simps (config := { fullyApplied := false }) apply]\ndef sumComm (\u03b1 \u03b2) : Sum \u03b1 \u03b2 \u2243 Sum \u03b2 \u03b1 :=\n  \u27e8Sum.swap, Sum.swap, Sum.swap_swap, Sum.swap_swap\u27e9\n#align equiv.sum_comm Equiv.sumComm\n#align equiv.sum_comm_apply Equiv.sumComm_apply\n\n@[simp]\ntheorem sumComm_symm (\u03b1 \u03b2) : (sumComm \u03b1 \u03b2).symm = sumComm \u03b2 \u03b1 :=\n  rfl\n#align equiv.sum_comm_symm Equiv.sumComm_symm\n\n/-- Sum of types is associative up to an equivalence. -/\ndef sumAssoc (\u03b1 \u03b2 \u03b3) : Sum (Sum \u03b1 \u03b2) \u03b3 \u2243 Sum \u03b1 (Sum \u03b2 \u03b3) :=\n  \u27e8Sum.elim (Sum.elim Sum.inl (Sum.inr \u2218 Sum.inl)) (Sum.inr \u2218 Sum.inr),\n    Sum.elim (Sum.inl \u2218 Sum.inl) <| Sum.elim (Sum.inl \u2218 Sum.inr) Sum.inr,\n      by rintro (\u27e8_ | _\u27e9 | _) <;> rfl, by\n    rintro (_ | \u27e8_ | _\u27e9) <;> rfl\u27e9\n#align equiv.sum_assoc Equiv.sumAssoc\n\n@[simp]\ntheorem sumAssoc_apply_inl_inl (a) : sumAssoc \u03b1 \u03b2 \u03b3 (inl (inl a)) = inl a :=\n  rfl\n#align equiv.sum_assoc_apply_inl_inl Equiv.sumAssoc_apply_inl_inl\n\n@[simp]\ntheorem sumAssoc_apply_inl_inr (b) : sumAssoc \u03b1 \u03b2 \u03b3 (inl (inr b)) = inr (inl b) :=\n  rfl\n#align equiv.sum_assoc_apply_inl_inr Equiv.sumAssoc_apply_inl_inr\n\n@[simp]\ntheorem sumAssoc_apply_inr (c) : sumAssoc \u03b1 \u03b2 \u03b3 (inr c) = inr (inr c) :=\n  rfl\n#align equiv.sum_assoc_apply_inr Equiv.sumAssoc_apply_inr\n\n@[simp]\ntheorem sumAssoc_symm_apply_inl {\u03b1 \u03b2 \u03b3} (a) : (sumAssoc \u03b1 \u03b2 \u03b3).symm (inl a) = inl (inl a) :=\n  rfl\n#align equiv.sum_assoc_symm_apply_inl Equiv.sumAssoc_symm_apply_inl\n\n@[simp]\ntheorem sumAssoc_symm_apply_inr_inl {\u03b1 \u03b2 \u03b3} (b) :\n    (sumAssoc \u03b1 \u03b2 \u03b3).symm (inr (inl b)) = inl (inr b) :=\n  rfl\n#align equiv.sum_assoc_symm_apply_inr_inl Equiv.sumAssoc_symm_apply_inr_inl\n\n@[simp]\ntheorem sumAssoc_symm_apply_inr_inr {\u03b1 \u03b2 \u03b3} (c) : (sumAssoc \u03b1 \u03b2 \u03b3).symm (inr (inr c)) = inr c :=\n  rfl\n#align equiv.sum_assoc_symm_apply_inr_inr Equiv.sumAssoc_symm_apply_inr_inr\n\n/-- Sum with `IsEmpty` is equivalent to the original type. -/\n@[simps symm_apply]\ndef sumEmpty (\u03b1 \u03b2) [IsEmpty \u03b2] : Sum \u03b1 \u03b2 \u2243 \u03b1 where\n  toFun := Sum.elim id isEmptyElim\n  invFun := inl\n  left_inv s := by\n    rcases s with (_ | x)\n    \u00b7 rfl\n    \u00b7 exact isEmptyElim x\n  right_inv _ := rfl\n#align equiv.sum_empty Equiv.sumEmpty\n#align equiv.sum_empty_symm_apply Equiv.sumEmpty_symm_apply\n\n@[simp]\ntheorem sumEmpty_apply_inl [IsEmpty \u03b2] (a : \u03b1) : sumEmpty \u03b1 \u03b2 (Sum.inl a) = a :=\n  rfl\n#align equiv.sum_empty_apply_inl Equiv.sumEmpty_apply_inl\n\n/-- The sum of `IsEmpty` with any type is equivalent to that type. -/\n@[simps! symm_apply]\ndef emptySum (\u03b1 \u03b2) [IsEmpty \u03b1] : Sum \u03b1 \u03b2 \u2243 \u03b2 :=\n  (sumComm _ _).trans <| sumEmpty _ _\n#align equiv.empty_sum Equiv.emptySum\n#align equiv.empty_sum_symm_apply Equiv.emptySum_symm_apply\n\n@[simp]\ntheorem emptySum_apply_inr [IsEmpty \u03b1] (b : \u03b2) : emptySum \u03b1 \u03b2 (Sum.inr b) = b :=\n  rfl\n#align equiv.empty_sum_apply_inr Equiv.emptySum_apply_inr\n\n/-- `Option \u03b1` is equivalent to `\u03b1 \u2295 punit` -/\ndef optionEquivSumPUnit (\u03b1) : Option \u03b1 \u2243 Sum \u03b1 PUnit :=\n  \u27e8fun o => o.elim (inr PUnit.unit) inl, fun s => s.elim some fun _ => none,\n    fun o => by cases o <;> rfl,\n    fun s => by rcases s with (_ | \u27e8\u27e8\u27e9\u27e9) <;> rfl\u27e9\n#align equiv.option_equiv_sum_punit Equiv.optionEquivSumPUnit\n\n@[simp]\ntheorem optionEquivSumPUnit_none : optionEquivSumPUnit \u03b1 none = Sum.inr PUnit.unit :=\n  rfl\n#align equiv.option_equiv_sum_punit_none Equiv.optionEquivSumPUnit_none\n\n@[simp]\ntheorem optionEquivSumPUnit_some (a) : optionEquivSumPUnit \u03b1 (some a) = Sum.inl a :=\n  rfl\n#align equiv.option_equiv_sum_punit_some Equiv.optionEquivSumPUnit_some\n\n@[simp]\ntheorem optionEquivSumPUnit_coe (a : \u03b1) : optionEquivSumPUnit \u03b1 a = Sum.inl a :=\n  rfl\n#align equiv.option_equiv_sum_punit_coe Equiv.optionEquivSumPUnit_coe\n\n@[simp]\ntheorem optionEquivSumPUnit_symm_inl (a) : (optionEquivSumPUnit \u03b1).symm (Sum.inl a) = a :=\n  rfl\n#align equiv.option_equiv_sum_punit_symm_inl Equiv.optionEquivSumPUnit_symm_inl\n\n@[simp]\ntheorem optionEquivSumPUnit_symm_inr (a) : (optionEquivSumPUnit \u03b1).symm (Sum.inr a) = none :=\n  rfl\n#align equiv.option_equiv_sum_punit_symm_inr Equiv.optionEquivSumPUnit_symm_inr\n\n/-- The set of `x : Option \u03b1` such that `isSome x` is equivalent to `\u03b1`. -/\n@[simps]\ndef optionIsSomeEquiv (\u03b1) : { x : Option \u03b1 // x.isSome } \u2243 \u03b1 where\n  toFun o := Option.get _ o.2\n  invFun x := \u27e8some x, rfl\u27e9\n  left_inv _ := Subtype.eq <| Option.some_get _\n  right_inv _ := Option.get_some _ _\n#align equiv.option_is_some_equiv Equiv.optionIsSomeEquiv\n#align equiv.option_is_some_equiv_apply Equiv.optionIsSomeEquiv_apply\n#align equiv.option_is_some_equiv_symm_apply_coe Equiv.optionIsSomeEquiv_symm_apply_coe\n\n/-- The product over `Option \u03b1` of `\u03b2 a` is the binary product of the\nproduct over `\u03b1` of `\u03b2 (some \u03b1)` and `\u03b2 none` -/\n@[simps]\ndef piOptionEquivProd {\u03b2 : Option \u03b1 \u2192 Type _} :\n    (\u2200 a : Option \u03b1, \u03b2 a) \u2243 \u03b2 none \u00d7 \u2200 a : \u03b1, \u03b2 (some a) where\n  toFun f := (f none, fun a => f (some a))\n  invFun x a := Option.casesOn a x.fst x.snd\n  left_inv f := funext fun a => by cases a <;> rfl\n  right_inv x := by simp\n#align equiv.pi_option_equiv_prod Equiv.piOptionEquivProd\n#align equiv.pi_option_equiv_prod_symm_apply Equiv.piOptionEquivProd_symm_apply\n#align equiv.pi_option_equiv_prod_apply Equiv.piOptionEquivProd_apply\n\n/-- `\u03b1 \u2295 \u03b2` is equivalent to a `Sigma`-type over `Bool`. Note that this definition assumes `\u03b1` and\n`\u03b2` to be types from the same universe, so it cannot by used directly to transfer theorems about\nsigma types to theorems about sum types. In many cases one can use `ulift` to work around this\ndifficulty. -/\ndef sumEquivSigmaBool (\u03b1 \u03b2 : Type u) : Sum \u03b1 \u03b2 \u2243 \u03a3 b : Bool, cond b \u03b1 \u03b2 :=\n  \u27e8fun s => s.elim (fun x => \u27e8true, x\u27e9) fun x => \u27e8false, x\u27e9, fun s =>\n    match s with\n    | \u27e8true, a\u27e9 => inl a\n    | \u27e8false, b\u27e9 => inr b,\n    fun s => by cases s <;> rfl, fun s => by rcases s with \u27e8_ | _, _\u27e9 <;> rfl\u27e9\n#align equiv.sum_equiv_sigma_bool Equiv.sumEquivSigmaBool\n\n-- See also `Equiv.sigmaPreimageEquiv`.\n/-- `sigmaFiberEquiv f` for `f : \u03b1 \u2192 \u03b2` is the natural equivalence between\nthe type of all fibres of `f` and the total space `\u03b1`. -/\n@[simps]\ndef sigmaFiberEquiv {\u03b1 \u03b2 : Type _} (f : \u03b1 \u2192 \u03b2) : (\u03a3 y : \u03b2, { x // f x = y }) \u2243 \u03b1 :=\n  \u27e8fun x => \u2191x.2, fun x => \u27e8f x, x, rfl\u27e9, fun \u27e8_, _, rfl\u27e9 => rfl, fun _ => rfl\u27e9\n#align equiv.sigma_fiber_equiv Equiv.sigmaFiberEquiv\n#align equiv.sigma_fiber_equiv_apply Equiv.sigmaFiberEquiv_apply\n#align equiv.sigma_fiber_equiv_symm_apply_fst Equiv.sigmaFiberEquiv_symm_apply_fst\n#align equiv.sigma_fiber_equiv_symm_apply_snd_coe Equiv.sigmaFiberEquiv_symm_apply_snd_coe\n\nend\n\nsection sumCompl\n\n/-- For any predicate `p` on `\u03b1`,\nthe sum of the two subtypes `{a // p a}` and its complement `{a // \u00ac p a}`\nis naturally equivalent to `\u03b1`.\n\nSee `subtypeOrEquiv` for sum types over subtypes `{x // p x}` and `{x // q x}`\nthat are not necessarily `IsCompl p q`.  -/\ndef sumCompl {\u03b1 : Type _} (p : \u03b1 \u2192 Prop) [DecidablePred p] :\n    Sum { a // p a } { a // \u00acp a } \u2243 \u03b1 where\n  toFun := Sum.elim Subtype.val Subtype.val\n  invFun a := if h : p a then Sum.inl \u27e8a, h\u27e9 else Sum.inr \u27e8a, h\u27e9\n  left_inv := by\n    rintro (\u27e8x, hx\u27e9 | \u27e8x, hx\u27e9) <;> dsimp;\n    { rw [dif_pos] }\n    { rw [dif_neg] }\n  right_inv a := by\n    dsimp\n    split_ifs <;> rfl\n#align equiv.sum_compl Equiv.sumCompl\n\n@[simp]\ntheorem sumCompl_apply_inl (p : \u03b1 \u2192 Prop) [DecidablePred p] (x : { a // p a }) :\n    sumCompl p (Sum.inl x) = x :=\n  rfl\n#align equiv.sum_compl_apply_inl Equiv.sumCompl_apply_inl\n\n@[simp]\ntheorem sumCompl_apply_inr (p : \u03b1 \u2192 Prop) [DecidablePred p] (x : { a // \u00acp a }) :\n    sumCompl p (Sum.inr x) = x :=\n  rfl\n#align equiv.sum_compl_apply_inr Equiv.sumCompl_apply_inr\n\n@[simp]\ntheorem sumCompl_apply_symm_of_pos (p : \u03b1 \u2192 Prop) [DecidablePred p] (a : \u03b1) (h : p a) :\n    (sumCompl p).symm a = Sum.inl \u27e8a, h\u27e9 :=\n  dif_pos h\n#align equiv.sum_compl_apply_symm_of_pos Equiv.sumCompl_apply_symm_of_pos\n\n@[simp]\ntheorem sumCompl_apply_symm_of_neg (p : \u03b1 \u2192 Prop) [DecidablePred p] (a : \u03b1) (h : \u00acp a) :\n    (sumCompl p).symm a = Sum.inr \u27e8a, h\u27e9 :=\n  dif_neg h\n#align equiv.sum_compl_apply_symm_of_neg Equiv.sumCompl_apply_symm_of_neg\n\n/-- Combines an `Equiv` between two subtypes with an `Equiv` between their complements to form a\n  permutation. -/\ndef subtypeCongr {p q : \u03b1 \u2192 Prop} [DecidablePred p] [DecidablePred q]\n    (e : { x // p x } \u2243 { x // q x }) (f : { x // \u00acp x } \u2243 { x // \u00acq x }) : Perm \u03b1 :=\n  (sumCompl p).symm.trans ((sumCongr e f).trans (sumCompl q))\n#align equiv.subtype_congr Equiv.subtypeCongr\n\nvariable {p : \u03b5 \u2192 Prop} [DecidablePred p]\n\nvariable (ep ep' : Perm { a // p a }) (en en' : Perm { a // \u00acp a })\n\n/-- Combining permutations on `\u03b5` that permute only inside or outside the subtype\nsplit induced by `p : \u03b5 \u2192 Prop` constructs a permutation on `\u03b5`. -/\ndef Perm.subtypeCongr : Equiv.Perm \u03b5 :=\n  permCongr (sumCompl p) (sumCongr ep en)\n#align equiv.perm.subtype_congr Equiv.Perm.subtypeCongr\n\ntheorem Perm.subtypeCongr.apply (a : \u03b5) : ep.subtypeCongr en a =\n    if h : p a then (ep \u27e8a, h\u27e9 : \u03b5) else en \u27e8a, h\u27e9 := by\n  by_cases h : p a <;> simp [Perm.subtypeCongr, h]\n#align equiv.perm.subtype_congr.apply Equiv.Perm.subtypeCongr.apply\n\n@[simp]\ntheorem Perm.subtypeCongr.left_apply {a : \u03b5} (h : p a) : ep.subtypeCongr en a = ep \u27e8a, h\u27e9 := by\n  simp [Perm.subtypeCongr.apply, h]\n#align equiv.perm.subtype_congr.left_apply Equiv.Perm.subtypeCongr.left_apply\n\n@[simp]\ntheorem Perm.subtypeCongr.left_apply_subtype (a : { a // p a }) : ep.subtypeCongr en a = ep a :=\n    Perm.subtypeCongr.left_apply ep en a.property\n#align equiv.perm.subtype_congr.left_apply_subtype Equiv.Perm.subtypeCongr.left_apply_subtype\n\n@[simp]\ntheorem Perm.subtypeCongr.right_apply {a : \u03b5} (h : \u00acp a) : ep.subtypeCongr en a = en \u27e8a, h\u27e9 := by\n  simp [Perm.subtypeCongr.apply, h]\n#align equiv.perm.subtype_congr.right_apply Equiv.Perm.subtypeCongr.right_apply\n\n@[simp]\ntheorem Perm.subtypeCongr.right_apply_subtype (a : { a // \u00acp a }) : ep.subtypeCongr en a = en a :=\n  Perm.subtypeCongr.right_apply ep en a.property\n#align equiv.perm.subtype_congr.right_apply_subtype Equiv.Perm.subtypeCongr.right_apply_subtype\n\n@[simp]\ntheorem Perm.subtypeCongr.refl :\n    Perm.subtypeCongr (Equiv.refl { a // p a }) (Equiv.refl { a // \u00acp a }) = Equiv.refl \u03b5 := by\n  ext x\n  by_cases h:p x <;> simp [h]\n#align equiv.perm.subtype_congr.refl Equiv.Perm.subtypeCongr.refl\n\n@[simp]\ntheorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr ep.symm en.symm := by\n  ext x\n  by_cases h:p x\n  \u00b7 have : p (ep.symm \u27e8x, h\u27e9) := Subtype.property _\n    simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this]\n\n  \u00b7 have : \u00acp (en.symm \u27e8x, h\u27e9) := Subtype.property (en.symm _)\n    simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this]\n\n#align equiv.perm.subtype_congr.symm Equiv.Perm.subtypeCongr.symm\n\n@[simp]\ntheorem Perm.subtypeCongr.trans :\n    (ep.subtypeCongr en).trans (ep'.subtypeCongr en')\n    = Perm.subtypeCongr (ep.trans ep') (en.trans en') := by\n  ext x\n  by_cases h:p x\n  \u00b7 have : p (ep \u27e8x, h\u27e9) := Subtype.property _\n    simp [Perm.subtypeCongr.apply, h, this]\n\n  \u00b7 have : \u00acp (en \u27e8x, h\u27e9) := Subtype.property (en _)\n    simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this]\n\n#align equiv.perm.subtype_congr.trans Equiv.Perm.subtypeCongr.trans\n\nend sumCompl\n\nsection subtypePreimage\n\nvariable (p : \u03b1 \u2192 Prop) [DecidablePred p] (x\u2080 : { a // p a } \u2192 \u03b2)\n\n/-- For a fixed function `x\u2080 : {a // p a} \u2192 \u03b2` defined on a subtype of `\u03b1`,\nthe subtype of functions `x : \u03b1 \u2192 \u03b2` that agree with `x\u2080` on the subtype `{a // p a}`\nis naturally equivalent to the type of functions `{a // \u00ac p a} \u2192 \u03b2`. -/\n@[simps]\ndef subtypePreimage : { x : \u03b1 \u2192 \u03b2 // x \u2218 Subtype.val = x\u2080 } \u2243 ({ a // \u00acp a } \u2192 \u03b2) where\n  toFun (x : { x : \u03b1 \u2192 \u03b2 // x \u2218 Subtype.val = x\u2080 }) a := (x : \u03b1 \u2192 \u03b2) a\n  invFun x := \u27e8fun a => if h : p a then x\u2080 \u27e8a, h\u27e9 else x \u27e8a, h\u27e9, funext fun \u27e8a, h\u27e9 => dif_pos h\u27e9\n  left_inv := fun \u27e8x, hx\u27e9 =>\n    Subtype.val_injective <|\n      funext fun a => by\n        dsimp only\n        split_ifs\n        \u00b7 rw [\u2190 hx]; rfl\n        \u00b7 rfl\n  right_inv x :=\n    funext fun \u27e8a, h\u27e9 =>\n      show dite (p a) _ _ = _ by\n        dsimp only\n        rw [dif_neg h]\n#align equiv.subtype_preimage Equiv.subtypePreimage\n#align equiv.subtype_preimage_symm_apply_coe Equiv.subtypePreimage_symm_apply_coe\n#align equiv.subtype_preimage_apply Equiv.subtypePreimage_apply\n\ntheorem subtypePreimage_symm_apply_coe_pos (x : { a // \u00acp a } \u2192 \u03b2) (a : \u03b1) (h : p a) :\n    ((subtypePreimage p x\u2080).symm x : \u03b1 \u2192 \u03b2) a = x\u2080 \u27e8a, h\u27e9 :=\n  dif_pos h\n#align equiv.subtype_preimage_symm_apply_coe_pos Equiv.subtypePreimage_symm_apply_coe_pos\n\ntheorem subtypePreimage_symm_apply_coe_neg (x : { a // \u00acp a } \u2192 \u03b2) (a : \u03b1) (h : \u00acp a) :\n    ((subtypePreimage p x\u2080).symm x : \u03b1 \u2192 \u03b2) a = x \u27e8a, h\u27e9 :=\n  dif_neg h\n#align equiv.subtype_preimage_symm_apply_coe_neg Equiv.subtypePreimage_symm_apply_coe_neg\n\nend subtypePreimage\n\nsection\n\n/-- A family of equivalences `\u2200 a, \u03b2\u2081 a \u2243 \u03b2\u2082 a` generates an equivalence between `\u2200 a, \u03b2\u2081 a` and\n`\u2200 a, \u03b2\u2082 a`. -/\ndef piCongrRight {\u03b2\u2081 \u03b2\u2082 : \u03b1 \u2192 Sort _} (F : \u2200 a, \u03b2\u2081 a \u2243 \u03b2\u2082 a) : (\u2200 a, \u03b2\u2081 a) \u2243 (\u2200 a, \u03b2\u2082 a) :=\n  \u27e8fun H a => F a (H a), fun H a => (F a).symm (H a), fun H => funext <| by simp,\n    fun H => funext <| by simp\u27e9\n#align equiv.Pi_congr_right Equiv.piCongrRight\n\n/-- Given `\u03c6 : \u03b1 \u2192 \u03b2 \u2192 Sort*`, we have an equivalence between `\u2200 a b, \u03c6 a b` and `\u2200 b a, \u03c6 a b`.\nThis is `Function.swap` as an `Equiv`. -/\n@[simps apply]\ndef piComm (\u03c6 : \u03b1 \u2192 \u03b2 \u2192 Sort _) : (\u2200 a b, \u03c6 a b) \u2243 \u2200 b a, \u03c6 a b :=\n  \u27e8swap, swap, fun _ => rfl, fun _ => rfl\u27e9\n#align equiv.Pi_comm Equiv.piComm\n#align equiv.Pi_comm_apply Equiv.piComm_apply\n\n@[simp]\ntheorem piComm_symm {\u03c6 : \u03b1 \u2192 \u03b2 \u2192 Sort _} : (piComm \u03c6).symm = (piComm <| swap \u03c6) :=\n  rfl\n#align equiv.Pi_comm_symm Equiv.piComm_symm\n\n/-- Dependent `curry` equivalence: the type of dependent functions on `\u03a3 i, \u03b2 i` is equivalent\nto the type of dependent functions of two arguments (i.e., functions to the space of functions).\n\nThis is `Sigma.curry` and `Sigma.uncurry` together as an equiv. -/\ndef piCurry {\u03b2 : \u03b1 \u2192 Sort _} (\u03b3 : \u2200 a, \u03b2 a \u2192 Sort _) :\n    (\u2200 x : \u03a3 i, \u03b2 i, \u03b3 x.1 x.2) \u2243 \u2200 a b, \u03b3 a b where\n  toFun := Sigma.curry\n  invFun := Sigma.uncurry\n  left_inv := Sigma.uncurry_curry\n  right_inv := Sigma.curry_uncurry\n#align equiv.Pi_curry Equiv.piCurry\n\nend\n\nsection prodCongr\n\nvariable (e : \u03b1\u2081 \u2192 \u03b2\u2081 \u2243 \u03b2\u2082)\n\n/-- A family of equivalences `\u2200 (a : \u03b1\u2081), \u03b2\u2081 \u2243 \u03b2\u2082` generates an equivalence\nbetween `\u03b2\u2081 \u00d7 \u03b1\u2081` and `\u03b2\u2082 \u00d7 \u03b1\u2081`. -/\ndef prodCongrLeft : \u03b2\u2081 \u00d7 \u03b1\u2081 \u2243 \u03b2\u2082 \u00d7 \u03b1\u2081 where\n  toFun ab := \u27e8e ab.2 ab.1, ab.2\u27e9\n  invFun ab := \u27e8(e ab.2).symm ab.1, ab.2\u27e9\n  left_inv := by\n    rintro \u27e8a, b\u27e9\n    simp\n  right_inv := by\n    rintro \u27e8a, b\u27e9\n    simp\n#align equiv.prod_congr_left Equiv.prodCongrLeft\n\n@[simp]\ntheorem prodCongrLeft_apply (b : \u03b2\u2081) (a : \u03b1\u2081) : prodCongrLeft e (b, a) = (e a b, a) :=\n  rfl\n#align equiv.prod_congr_left_apply Equiv.prodCongrLeft_apply\n\ntheorem prodCongr_refl_right (e : \u03b2\u2081 \u2243 \u03b2\u2082) :\n    prodCongr e (Equiv.refl \u03b1\u2081) = prodCongrLeft fun _ => e := by\n  ext \u27e8a, b\u27e9 : 1\n  simp\n#align equiv.prod_congr_refl_right Equiv.prodCongr_refl_right\n\n/-- A family of equivalences `\u2200 (a : \u03b1\u2081), \u03b2\u2081 \u2243 \u03b2\u2082` generates an equivalence\nbetween `\u03b1\u2081 \u00d7 \u03b2\u2081` and `\u03b1\u2081 \u00d7 \u03b2\u2082`. -/\ndef prodCongrRight : \u03b1\u2081 \u00d7 \u03b2\u2081 \u2243 \u03b1\u2081 \u00d7 \u03b2\u2082 where\n  toFun ab := \u27e8ab.1, e ab.1 ab.2\u27e9\n  invFun ab := \u27e8ab.1, (e ab.1).symm ab.2\u27e9\n  left_inv := by\n    rintro \u27e8a, b\u27e9\n    simp\n  right_inv := by\n    rintro \u27e8a, b\u27e9\n    simp\n#align equiv.prod_congr_right Equiv.prodCongrRight\n\n@[simp]\ntheorem prodCongrRight_apply (a : \u03b1\u2081) (b : \u03b2\u2081) : prodCongrRight e (a, b) = (a, e a b) :=\n  rfl\n#align equiv.prod_congr_right_apply Equiv.prodCongrRight_apply\n\ntheorem prodCongr_refl_left (e : \u03b2\u2081 \u2243 \u03b2\u2082) :\n    prodCongr (Equiv.refl \u03b1\u2081) e = prodCongrRight fun _ => e := by\n  ext \u27e8a, b\u27e9 : 1\n  simp\n#align equiv.prod_congr_refl_left Equiv.prodCongr_refl_left\n\n@[simp]\ntheorem prodCongrLeft_trans_prodComm :\n    (prodCongrLeft e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrRight e) := by\n  ext \u27e8a, b\u27e9 : 1\n  simp\n#align equiv.prod_congr_left_trans_prod_comm Equiv.prodCongrLeft_trans_prodComm\n\n@[simp]\ntheorem prodCongrRight_trans_prodComm :\n    (prodCongrRight e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrLeft e) := by\n  ext \u27e8a, b\u27e9 : 1\n  simp\n#align equiv.prod_congr_right_trans_prod_comm Equiv.prodCongrRight_trans_prodComm\n\ntheorem sigmaCongrRight_sigmaEquivProd :\n    (sigmaCongrRight e).trans (sigmaEquivProd \u03b1\u2081 \u03b2\u2082)\n    = (sigmaEquivProd \u03b1\u2081 \u03b2\u2081).trans (prodCongrRight e) := by\n  ext \u27e8a, b\u27e9 : 1\n  simp\n#align equiv.sigma_congr_right_sigma_equiv_prod Equiv.sigmaCongrRight_sigmaEquivProd\n\ntheorem sigmaEquivProd_sigmaCongrRight :\n    (sigmaEquivProd \u03b1\u2081 \u03b2\u2081).symm.trans (sigmaCongrRight e)\n    = (prodCongrRight e).trans (sigmaEquivProd \u03b1\u2081 \u03b2\u2082).symm := by\n  ext \u27e8a, b\u27e9 : 1\n  simp only [trans_apply, sigmaCongrRight_apply, prodCongrRight_apply]\n  rfl\n#align equiv.sigma_equiv_prod_sigma_congr_right Equiv.sigmaEquivProd_sigmaCongrRight\n\n-- See also `Equiv.ofPreimageEquiv`.\n/-- A family of equivalences between fibers gives an equivalence between domains. -/\n@[simps!]\ndef ofFiberEquiv {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3} (e : \u2200 c, { a // f a = c } \u2243 { b // g b = c }) : \u03b1 \u2243 \u03b2 :=\n  (sigmaFiberEquiv f).symm.trans <| (Equiv.sigmaCongrRight e).trans (sigmaFiberEquiv g)\n#align equiv.of_fiber_equiv Equiv.ofFiberEquiv\n#align equiv.of_fiber_equiv_apply Equiv.ofFiberEquiv_apply\n#align equiv.of_fiber_equiv_symm_apply Equiv.ofFiberEquiv_symm_apply\n\ntheorem ofFiberEquiv_map {\u03b1 \u03b2 \u03b3} {f : \u03b1 \u2192 \u03b3} {g : \u03b2 \u2192 \u03b3}\n    (e : \u2200 c, { a // f a = c } \u2243 { b // g b = c }) (a : \u03b1) : g (ofFiberEquiv e a) = f a :=\n  (_ : { b // g b = _ }).property\n#align equiv.of_fiber_equiv_map Equiv.ofFiberEquiv_map\n\n/-- A variation on `Equiv.prodCongr` where the equivalence in the second component can depend\n  on the first component. A typical example is a shear mapping, explaining the name of this\n  declaration. -/\n@[simps (config := { fullyApplied := false })]\ndef prodShear (e\u2081 : \u03b1\u2081 \u2243 \u03b1\u2082) (e\u2082 : \u03b1\u2081 \u2192 \u03b2\u2081 \u2243 \u03b2\u2082) : \u03b1\u2081 \u00d7 \u03b2\u2081 \u2243 \u03b1\u2082 \u00d7 \u03b2\u2082 where\n  toFun := fun x : \u03b1\u2081 \u00d7 \u03b2\u2081 => (e\u2081 x.1, e\u2082 x.1 x.2)\n  invFun := fun y : \u03b1\u2082 \u00d7 \u03b2\u2082 => (e\u2081.symm y.1, (e\u2082 <| e\u2081.symm y.1).symm y.2)\n  left_inv := by\n    rintro \u27e8x\u2081, y\u2081\u27e9\n    simp only [symm_apply_apply]\n  right_inv := by\n    rintro \u27e8x\u2081, y\u2081\u27e9\n    simp only [apply_symm_apply]\n#align equiv.prod_shear Equiv.prodShear\n#align equiv.prod_shear_apply Equiv.prodShear_apply\n#align equiv.prod_shear_symm_apply Equiv.prodShear_symm_apply\n\nend prodCongr\n\nnamespace Perm\n\nvariable [DecidableEq \u03b1\u2081] (a : \u03b1\u2081) (e : Perm \u03b2\u2081)\n\n/-- `prodExtendRight a e` extends `e : Perm \u03b2` to `Perm (\u03b1 \u00d7 \u03b2)` by sending `(a, b)` to\n`(a, e b)` and keeping the other `(a', b)` fixed. -/\ndef prodExtendRight : Perm (\u03b1\u2081 \u00d7 \u03b2\u2081) where\n  toFun ab := if ab.fst = a then (a, e ab.snd) else ab\n  invFun ab := if ab.fst = a then (a, e.symm ab.snd) else ab\n  left_inv := by\n    rintro \u27e8k', x\u27e9\n    dsimp only\n    split_ifs with h\u2081 h\u2082\n    \u00b7 simp [h\u2081]\n    \u00b7 simp at h\u2082\n    \u00b7 simp\n  right_inv := by\n    rintro \u27e8k', x\u27e9\n    dsimp only\n    split_ifs with h\u2081 h\u2082\n    \u00b7 simp [h\u2081]\n    \u00b7 simp at h\u2082\n    \u00b7 simp\n#align equiv.perm.prod_extend_right Equiv.Perm.prodExtendRight\n\n@[simp]\ntheorem prodExtendRight_apply_eq (b : \u03b2\u2081) : prodExtendRight a e (a, b) = (a, e b) :=\n  if_pos rfl\n#align equiv.perm.prod_extend_right_apply_eq Equiv.Perm.prodExtendRight_apply_eq\n\ntheorem prodExtendRight_apply_ne {a a' : \u03b1\u2081} (h : a' \u2260 a) (b : \u03b2\u2081) :\n    prodExtendRight a e (a', b) = (a', b) :=\n  if_neg h\n#align equiv.perm.prod_extend_right_apply_ne Equiv.Perm.prodExtendRight_apply_ne\n\ntheorem eq_of_prodExtendRight_ne {e : Perm \u03b2\u2081} {a a' : \u03b1\u2081} {b : \u03b2\u2081}\n    (h : prodExtendRight a e (a', b) \u2260 (a', b)) : a' = a := by\n  contrapose! h\n  exact prodExtendRight_apply_ne _ h _\n#align equiv.perm.eq_of_prod_extend_right_ne Equiv.Perm.eq_of_prodExtendRight_ne\n\n@[simp]\ntheorem fst_prodExtendRight (ab : \u03b1\u2081 \u00d7 \u03b2\u2081) : (prodExtendRight a e ab).fst = ab.fst := by\n  rw [prodExtendRight]\n  dsimp\n  split_ifs with h\n  \u00b7 rw [h]\n  \u00b7 rfl\n#align equiv.perm.fst_prod_extend_right Equiv.Perm.fst_prodExtendRight\n\nend Perm\n\nsection\n\n/-- The type of functions to a product `\u03b1 \u00d7 \u03b2` is equivalent to the type of pairs of functions\n`\u03b3 \u2192 \u03b1` and `\u03b3 \u2192 \u03b2`. -/\ndef arrowProdEquivProdArrow (\u03b1 \u03b2 \u03b3 : Type _) : (\u03b3 \u2192 \u03b1 \u00d7 \u03b2) \u2243 (\u03b3 \u2192 \u03b1) \u00d7 (\u03b3 \u2192 \u03b2) where\n  toFun := fun f => (fun c => (f c).1, fun c => (f c).2)\n  invFun := fun p c => (p.1 c, p.2 c)\n  left_inv := fun f => funext fun c => Prod.mk.eta\n  right_inv := fun p => by cases p; rfl\n#align equiv.arrow_prod_equiv_prod_arrow Equiv.arrowProdEquivProdArrow\n\nopen Sum\n\n/-- The type of functions on a sum type `\u03b1 \u2295 \u03b2` is equivalent to the type of pairs of functions\non `\u03b1` and on `\u03b2`. -/\ndef sumArrowEquivProdArrow (\u03b1 \u03b2 \u03b3 : Type _) : (Sum \u03b1 \u03b2 \u2192 \u03b3) \u2243 (\u03b1 \u2192 \u03b3) \u00d7 (\u03b2 \u2192 \u03b3) :=\n  \u27e8fun f => (f \u2218 inl, f \u2218 inr), fun p => Sum.elim p.1 p.2, fun f => by ext \u27e8\u27e9 <;> rfl, fun p => by\n    cases p\n    rfl\u27e9\n#align equiv.sum_arrow_equiv_prod_arrow Equiv.sumArrowEquivProdArrow\n\n@[simp]\ntheorem sumArrowEquivProdArrow_apply_fst (f : Sum \u03b1 \u03b2 \u2192 \u03b3) (a : \u03b1) :\n    (sumArrowEquivProdArrow \u03b1 \u03b2 \u03b3 f).1 a = f (inl a) :=\n  rfl\n#align equiv.sum_arrow_equiv_prod_arrow_apply_fst Equiv.sumArrowEquivProdArrow_apply_fst\n\n@[simp]\ntheorem sumArrowEquivProdArrow_apply_snd (f : Sum \u03b1 \u03b2 \u2192 \u03b3) (b : \u03b2) :\n    (sumArrowEquivProdArrow \u03b1 \u03b2 \u03b3 f).2 b = f (inr b) :=\n  rfl\n#align equiv.sum_arrow_equiv_prod_arrow_apply_snd Equiv.sumArrowEquivProdArrow_apply_snd\n\n@[simp]\ntheorem sumArrowEquivProdArrow_symm_apply_inl (f : \u03b1 \u2192 \u03b3) (g : \u03b2 \u2192 \u03b3) (a : \u03b1) :\n    ((sumArrowEquivProdArrow \u03b1 \u03b2 \u03b3).symm (f, g)) (inl a) = f a :=\n  rfl\n#align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inl Equiv.sumArrowEquivProdArrow_symm_apply_inl\n\n@[simp]\ntheorem sumArrowEquivProdArrow_symm_apply_inr (f : \u03b1 \u2192 \u03b3) (g : \u03b2 \u2192 \u03b3) (b : \u03b2) :\n    ((sumArrowEquivProdArrow \u03b1 \u03b2 \u03b3).symm (f, g)) (inr b) = g b :=\n  rfl\n#align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inr Equiv.sumArrowEquivProdArrow_symm_apply_inr\n\n/-- Type product is right distributive with respect to type sum up to an equivalence. -/\ndef sumProdDistrib (\u03b1 \u03b2 \u03b3) : Sum \u03b1 \u03b2 \u00d7 \u03b3 \u2243 Sum (\u03b1 \u00d7 \u03b3) (\u03b2 \u00d7 \u03b3) :=\n  \u27e8fun p => p.1.map (fun x => (x, p.2)) fun x => (x, p.2),\n    fun s => s.elim (Prod.map inl id) (Prod.map inr id), by\n      rintro \u27e8_ | _, _\u27e9 <;> rfl, by rintro (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) <;> rfl\u27e9\n#align equiv.sum_prod_distrib Equiv.sumProdDistrib\n\n@[simp]\ntheorem sumProdDistrib_apply_left (a : \u03b1) (c : \u03b3) :\n    sumProdDistrib \u03b1 \u03b2 \u03b3 (Sum.inl a, c) = Sum.inl (a, c) :=\n  rfl\n#align equiv.sum_prod_distrib_apply_left Equiv.sumProdDistrib_apply_left\n\n@[simp]\ntheorem sumProdDistrib_apply_right (b : \u03b2) (c : \u03b3) :\n    sumProdDistrib \u03b1 \u03b2 \u03b3 (Sum.inr b, c) = Sum.inr (b, c) :=\n  rfl\n#align equiv.sum_prod_distrib_apply_right Equiv.sumProdDistrib_apply_right\n\n@[simp]\ntheorem sumProdDistrib_symm_apply_left (a : \u03b1 \u00d7 \u03b3) :\n    (sumProdDistrib \u03b1 \u03b2 \u03b3).symm (inl a) = (inl a.1, a.2) :=\n  rfl\n#align equiv.sum_prod_distrib_symm_apply_left Equiv.sumProdDistrib_symm_apply_left\n\n@[simp]\ntheorem sumProdDistrib_symm_apply_right (b : \u03b2 \u00d7 \u03b3) :\n    (sumProdDistrib \u03b1 \u03b2 \u03b3).symm (inr b) = (inr b.1, b.2) :=\n  rfl\n#align equiv.sum_prod_distrib_symm_apply_right Equiv.sumProdDistrib_symm_apply_right\n\n/-- Type product is left distributive with respect to type sum up to an equivalence. -/\ndef prodSumDistrib (\u03b1 \u03b2 \u03b3) : \u03b1 \u00d7 Sum \u03b2 \u03b3 \u2243 Sum (\u03b1 \u00d7 \u03b2) (\u03b1 \u00d7 \u03b3) :=\n  calc\n    \u03b1 \u00d7 Sum \u03b2 \u03b3 \u2243 Sum \u03b2 \u03b3 \u00d7 \u03b1 := prodComm _ _\n    _ \u2243 Sum (\u03b2 \u00d7 \u03b1) (\u03b3 \u00d7 \u03b1) := sumProdDistrib _ _ _\n    _ \u2243 Sum (\u03b1 \u00d7 \u03b2) (\u03b1 \u00d7 \u03b3) := sumCongr (prodComm _ _) (prodComm _ _)\n#align equiv.prod_sum_distrib Equiv.prodSumDistrib\n\n@[simp]\ntheorem prodSumDistrib_apply_left (a : \u03b1) (b : \u03b2) :\n    prodSumDistrib \u03b1 \u03b2 \u03b3 (a, Sum.inl b) = Sum.inl (a, b) :=\n  rfl\n#align equiv.prod_sum_distrib_apply_left Equiv.prodSumDistrib_apply_left\n\n@[simp]\ntheorem prodSumDistrib_apply_right (a : \u03b1) (c : \u03b3) :\n    prodSumDistrib \u03b1 \u03b2 \u03b3 (a, Sum.inr c) = Sum.inr (a, c) :=\n  rfl\n#align equiv.prod_sum_distrib_apply_right Equiv.prodSumDistrib_apply_right\n\n@[simp]\ntheorem prodSumDistrib_symm_apply_left (a : \u03b1 \u00d7 \u03b2) :\n    (prodSumDistrib \u03b1 \u03b2 \u03b3).symm (inl a) = (a.1, inl a.2) :=\n  rfl\n#align equiv.prod_sum_distrib_symm_apply_left Equiv.prodSumDistrib_symm_apply_left\n\n@[simp]\ntheorem prodSumDistrib_symm_apply_right (a : \u03b1 \u00d7 \u03b3) :\n    (prodSumDistrib \u03b1 \u03b2 \u03b3).symm (inr a) = (a.1, inr a.2) :=\n  rfl\n#align equiv.prod_sum_distrib_symm_apply_right Equiv.prodSumDistrib_symm_apply_right\n\n/-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. -/\n@[simps]\ndef sigmaSumDistrib (\u03b1 \u03b2 : \u03b9 \u2192 Type _) :\n    (\u03a3 i, Sum (\u03b1 i) (\u03b2 i)) \u2243 Sum (\u03a3 i, \u03b1 i) (\u03a3 i, \u03b2 i) :=\n  \u27e8fun p => p.2.map (Sigma.mk p.1) (Sigma.mk p.1),\n    Sum.elim (Sigma.map id fun _ => Sum.inl) (Sigma.map id fun _ => Sum.inr), fun p => by\n    rcases p with \u27e8i, a | b\u27e9 <;> rfl, fun p => by rcases p with (\u27e8i, a\u27e9 | \u27e8i, b\u27e9) <;> rfl\u27e9\n#align equiv.sigma_sum_distrib Equiv.sigmaSumDistrib\n#align equiv.sigma_sum_distrib_apply Equiv.sigmaSumDistrib_apply\n#align equiv.sigma_sum_distrib_symm_apply Equiv.sigmaSumDistrib_symm_apply\n\n/-- The product of an indexed sum of types (formally, a `Sigma`-type `\u03a3 i, \u03b1 i`) by a type `\u03b2` is\nequivalent to the sum of products `\u03a3 i, (\u03b1 i \u00d7 \u03b2)`. -/\ndef sigmaProdDistrib (\u03b1 : \u03b9 \u2192 Type _) (\u03b2 : Type _) : (\u03a3 i, \u03b1 i) \u00d7 \u03b2 \u2243 \u03a3 i, \u03b1 i \u00d7 \u03b2 :=\n  \u27e8fun p => \u27e8p.1.1, (p.1.2, p.2)\u27e9, fun p => (\u27e8p.1, p.2.1\u27e9, p.2.2), fun p => by\n    rcases p with \u27e8\u27e8_, _\u27e9, _\u27e9\n    rfl, fun p => by\n    rcases p with \u27e8_, \u27e8_, _\u27e9\u27e9\n    rfl\u27e9\n#align equiv.sigma_prod_distrib Equiv.sigmaProdDistrib\n\n/-- An equivalence that separates out the 0th fiber of `(\u03a3 (n : \u2115), f n)`. -/\ndef sigmaNatSucc (f : \u2115 \u2192 Type u) : (\u03a3 n, f n) \u2243 Sum (f 0) (\u03a3 n, f (n + 1)) :=\n  \u27e8fun x =>\n    @Sigma.casesOn \u2115 f (fun _ => Sum (f 0) (\u03a3n, f (n + 1))) x fun n =>\n      @Nat.casesOn (fun i => f i \u2192 Sum (f 0) (\u03a3n : \u2115, f (n + 1))) n (fun x : f 0 => Sum.inl x)\n        fun (n : \u2115) (x : f n.succ) => Sum.inr \u27e8n, x\u27e9,\n    Sum.elim (Sigma.mk 0) (Sigma.map Nat.succ fun _ => id), by rintro \u27e8n | n, x\u27e9 <;> rfl, by\n    rintro (x | \u27e8n, x\u27e9) <;> rfl\u27e9\n#align equiv.sigma_nat_succ Equiv.sigmaNatSucc\n\n/-- The product `Bool \u00d7 \u03b1` is equivalent to `\u03b1 \u2295 \u03b1`. -/\n@[simps]\ndef boolProdEquivSum (\u03b1) : Bool \u00d7 \u03b1 \u2243 Sum \u03b1 \u03b1 where\n  toFun p := cond p.1 (inr p.2) (inl p.2)\n  invFun := Sum.elim (Prod.mk false) (Prod.mk true)\n  left_inv := by rintro \u27e8_ | _, _\u27e9 <;> rfl\n  right_inv := by rintro (_ | _) <;> rfl\n#align equiv.bool_prod_equiv_sum Equiv.boolProdEquivSum\n#align equiv.bool_prod_equiv_sum_apply Equiv.boolProdEquivSum_apply\n#align equiv.bool_prod_equiv_sum_symm_apply Equiv.boolProdEquivSum_symm_apply\n\n/-- The function type `Bool \u2192 \u03b1` is equivalent to `\u03b1 \u00d7 \u03b1`. -/\n@[simps]\ndef boolArrowEquivProd (\u03b1) : (Bool \u2192 \u03b1) \u2243 \u03b1 \u00d7 \u03b1 where\n  toFun f := (f true, f false)\n  invFun p b := cond b p.1 p.2\n  left_inv _ := funext <| Bool.forall_bool.2 \u27e8rfl, rfl\u27e9\n  right_inv := fun _ => rfl\n#align equiv.bool_arrow_equiv_prod Equiv.boolArrowEquivProd\n#align equiv.bool_arrow_equiv_prod_apply Equiv.boolArrowEquivProd_apply\n#align equiv.bool_arrow_equiv_prod_symm_apply Equiv.boolArrowEquivProd_symm_apply\n\nend\n\nsection\n\nopen Sum Nat\n\n/-- The set of natural numbers is equivalent to `\u2115 \u2295 PUnit`. -/\ndef natEquivNatSumPUnit : \u2115 \u2243 Sum \u2115 PUnit where\n  toFun n := Nat.casesOn n (inr PUnit.unit) inl\n  invFun := Sum.elim Nat.succ fun _ => 0\n  left_inv n := by cases n <;> rfl\n  right_inv := by rintro (_ | _) <;> rfl\n#align equiv.nat_equiv_nat_sum_punit Equiv.natEquivNatSumPUnit\n\n/-- `\u2115 \u2295 Punit` is equivalent to `\u2115`. -/\ndef natSumPUnitEquivNat : Sum \u2115 PUnit \u2243 \u2115 :=\n  natEquivNatSumPUnit.symm\n#align equiv.nat_sum_punit_equiv_nat Equiv.natSumPUnitEquivNat\n\n/-- The type of integer numbers is equivalent to `\u2115 \u2295 \u2115`. -/\ndef intEquivNatSumNat : \u2124 \u2243 Sum \u2115 \u2115 where\n  toFun z := Int.casesOn z inl inr\n  invFun := Sum.elim Int.ofNat Int.negSucc\n  left_inv := by rintro (m | n) <;> rfl\n  right_inv := by rintro (m | n) <;> rfl\n#align equiv.int_equiv_nat_sum_nat Equiv.intEquivNatSumNat\n\nend\n\n/-- An equivalence between `\u03b1` and `\u03b2` generates an equivalence between `List \u03b1` and `List \u03b2`. -/\ndef listEquivOfEquiv (e : \u03b1 \u2243 \u03b2) : List \u03b1 \u2243 List \u03b2 where\n  toFun := List.map e\n  invFun := List.map e.symm\n  left_inv l := by rw [List.map_map, e.symm_comp_self, List.map_id]\n  right_inv l := by rw [List.map_map, e.self_comp_symm, List.map_id]\n#align equiv.list_equiv_of_equiv Equiv.listEquivOfEquiv\n\n/-- If `\u03b1` is equivalent to `\u03b2`, then `Unique \u03b1` is equivalent to `Unique \u03b2`. -/\ndef uniqueCongr (e : \u03b1 \u2243 \u03b2) : Unique \u03b1 \u2243 Unique \u03b2 where\n  toFun h := @Equiv.unique _ _ h e.symm\n  invFun h := @Equiv.unique _ _ h e\n  left_inv _ := Subsingleton.elim _ _\n  right_inv _ := Subsingleton.elim _ _\n#align equiv.unique_congr Equiv.uniqueCongr\n\n/-- If `\u03b1` is equivalent to `\u03b2`, then `IsEmpty \u03b1` is equivalent to `IsEmpty \u03b2`. -/\ntheorem isEmpty_congr (e : \u03b1 \u2243 \u03b2) : IsEmpty \u03b1 \u2194 IsEmpty \u03b2 :=\n  \u27e8fun h => @Function.isEmpty _ _ h e.symm, fun h => @Function.isEmpty _ _ h e\u27e9\n#align equiv.is_empty_congr Equiv.isEmpty_congr\n\nprotected theorem isEmpty (e : \u03b1 \u2243 \u03b2) [IsEmpty \u03b2] : IsEmpty \u03b1 :=\n  e.isEmpty_congr.mpr \u2039_\u203a\n#align equiv.is_empty Equiv.isEmpty\n\nsection\n\nopen Subtype\n\n/-- If `\u03b1` is equivalent to `\u03b2` and the predicates `p : \u03b1 \u2192 Prop` and `q : \u03b2 \u2192 Prop` are equivalent\nat corresponding points, then `{a // p a}` is equivalent to `{b // q b}`.\nFor the statement where `\u03b1 = \u03b2`, that is, `e : perm \u03b1`, see `Perm.subtypePerm`. -/\ndef subtypeEquiv {p : \u03b1 \u2192 Prop} {q : \u03b2 \u2192 Prop} (e : \u03b1 \u2243 \u03b2) (h : \u2200 a, p a \u2194 q (e a)) :\n    { a : \u03b1 // p a } \u2243 { b : \u03b2 // q b } where\n  toFun a := \u27e8e a, (h _).mp a.property\u27e9\n  invFun b := \u27e8e.symm b, (h _).mpr ((e.apply_symm_apply b).symm \u25b8 b.property)\u27e9\n  left_inv a := Subtype.ext <| by simp\n  right_inv b := Subtype.ext <| by simp\n#align equiv.subtype_equiv Equiv.subtypeEquiv\n\n@[simp]\ntheorem subtypeEquiv_refl {p : \u03b1 \u2192 Prop} (h : \u2200 a, p a \u2194 p (Equiv.refl _ a) := fun a => Iff.rfl) :\n    (Equiv.refl \u03b1).subtypeEquiv h = Equiv.refl { a : \u03b1 // p a } := by\n  ext\n  rfl\n#align equiv.subtype_equiv_refl Equiv.subtypeEquiv_refl\n\n@[simp]\ntheorem subtypeEquiv_symm {p : \u03b1 \u2192 Prop} {q : \u03b2 \u2192 Prop} (e : \u03b1 \u2243 \u03b2) (h : \u2200 a : \u03b1, p a \u2194 q (e a)) :\n    (e.subtypeEquiv h).symm =\n      e.symm.subtypeEquiv fun a => by\n        convert (h <| e.symm a).symm\n        exact (e.apply_symm_apply a).symm :=\n  rfl\n#align equiv.subtype_equiv_symm Equiv.subtypeEquiv_symm\n\n@[simp]\ntheorem subtypeEquiv_trans {p : \u03b1 \u2192 Prop} {q : \u03b2 \u2192 Prop} {r : \u03b3 \u2192 Prop} (e : \u03b1 \u2243 \u03b2) (f : \u03b2 \u2243 \u03b3)\n    (h : \u2200 a : \u03b1, p a \u2194 q (e a)) (h' : \u2200 b : \u03b2, q b \u2194 r (f b)) :\n    (e.subtypeEquiv h).trans (f.subtypeEquiv h')\n    = (e.trans f).subtypeEquiv fun a => (h a).trans (h' <| e a) :=\n  rfl\n#align equiv.subtype_equiv_trans Equiv.subtypeEquiv_trans\n\n@[simp]\ntheorem subtypeEquiv_apply {p : \u03b1 \u2192 Prop} {q : \u03b2 \u2192 Prop}\n    (e : \u03b1 \u2243 \u03b2) (h : \u2200 a : \u03b1, p a \u2194 q (e a)) (x : { x // p x }) :\n    e.subtypeEquiv h x = \u27e8e x, (h _).1 x.2\u27e9 :=\n  rfl\n#align equiv.subtype_equiv_apply Equiv.subtypeEquiv_apply\n\n/-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to\n`{x // q x}`. -/\n@[simps!]\ndef subtypeEquivRight {p q : \u03b1 \u2192 Prop} (e : \u2200 x, p x \u2194 q x) : { x // p x } \u2243 { x // q x } :=\n  subtypeEquiv (Equiv.refl _) e\n#align equiv.subtype_equiv_right Equiv.subtypeEquivRight\n#align equiv.subtype_equiv_right_apply_coe Equiv.subtypeEquivRight_apply_coe\n#align equiv.subtype_equiv_right_symm_apply_coe Equiv.subtypeEquivRight_symm_apply_coe\n\n/-- If `\u03b1 \u2243 \u03b2`, then for any predicate `p : \u03b2 \u2192 Prop` the subtype `{a // p (e a)}` is equivalent\nto the subtype `{b // p b}`. -/\ndef subtypeEquivOfSubtype {p : \u03b2 \u2192 Prop} (e : \u03b1 \u2243 \u03b2) : { a : \u03b1 // p (e a) } \u2243 { b : \u03b2 // p b } :=\n  subtypeEquiv e <| by simp\n#align equiv.subtype_equiv_of_subtype Equiv.subtypeEquivOfSubtype\n\n/-- If `\u03b1 \u2243 \u03b2`, then for any predicate `p : \u03b1 \u2192 Prop` the subtype `{a // p a}` is equivalent\nto the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/\ndef subtypeEquivOfSubtype' {p : \u03b1 \u2192 Prop} (e : \u03b1 \u2243 \u03b2) :\n    { a : \u03b1 // p a } \u2243 { b : \u03b2 // p (e.symm b) } :=\n  e.symm.subtypeEquivOfSubtype.symm\n#align equiv.subtype_equiv_of_subtype' Equiv.subtypeEquivOfSubtype'\n\n/-- If two predicates are equal, then the corresponding subtypes are equivalent. -/\ndef subtypeEquivProp {p q : \u03b1 \u2192 Prop} (h : p = q) : Subtype p \u2243 Subtype q :=\n  subtypeEquiv (Equiv.refl \u03b1) fun _ => h \u25b8 Iff.rfl\n#align equiv.subtype_equiv_prop Equiv.subtypeEquivProp\n\n/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This\nversion allows the \u201cinner\u201d predicate to depend on `h : p a`. -/\n@[simps]\ndef subtypeSubtypeEquivSubtypeExists (p : \u03b1 \u2192 Prop) (q : Subtype p \u2192 Prop) :\n    Subtype q \u2243 { a : \u03b1 // \u2203 h : p a, q \u27e8a, h\u27e9 } :=\n  \u27e8fun a =>\n    \u27e8a.1, a.1.2, by\n      rcases a with \u27e8\u27e8a, hap\u27e9, haq\u27e9\n      exact haq\u27e9,\n    fun a => \u27e8\u27e8a, a.2.fst\u27e9, a.2.snd\u27e9, fun \u27e8\u27e8a, ha\u27e9, h\u27e9 => rfl, fun \u27e8a, h\u2081, h\u2082\u27e9 => rfl\u27e9\n#align equiv.subtype_subtype_equiv_subtype_exists Equiv.subtypeSubtypeEquivSubtypeExists\n#align equiv.subtype_subtype_equiv_subtype_exists_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeExists_symm_apply_coe_coe\n#align equiv.subtype_subtype_equiv_subtype_exists_apply_coe Equiv.subtypeSubtypeEquivSubtypeExists_apply_coe\n\n/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/\n@[simps!]\ndef subtypeSubtypeEquivSubtypeInter {\u03b1 : Type u} (p q : \u03b1 \u2192 Prop) :\n    { x : Subtype p // q x.1 } \u2243 Subtype fun x => p x \u2227 q x :=\n  (subtypeSubtypeEquivSubtypeExists p _).trans <|\n    subtypeEquivRight fun x => @exists_prop (q x) (p x)\n#align equiv.subtype_subtype_equiv_subtype_inter Equiv.subtypeSubtypeEquivSubtypeInter\n#align equiv.subtype_subtype_equiv_subtype_inter_apply_coe Equiv.subtypeSubtypeEquivSubtypeInter_apply_coe\n#align equiv.subtype_subtype_equiv_subtype_inter_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeInter_symm_apply_coe_coe\n\n/-- If the outer subtype has more restrictive predicate than the inner one,\nthen we can drop the latter. -/\n@[simps!]\ndef subtypeSubtypeEquivSubtype {p q : \u03b1 \u2192 Prop} (h : \u2200 {x}, q x \u2192 p x) :\n    { x : Subtype p // q x.1 } \u2243 Subtype q :=\n  (subtypeSubtypeEquivSubtypeInter p _).trans <| subtypeEquivRight fun _ => and_iff_right_of_imp h\n#align equiv.subtype_subtype_equiv_subtype Equiv.subtypeSubtypeEquivSubtype\n#align equiv.subtype_subtype_equiv_subtype_apply_coe Equiv.subtypeSubtypeEquivSubtype_apply_coe\n#align equiv.subtype_subtype_equiv_subtype_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtype_symm_apply_coe_coe\n\n/-- If a proposition holds for all elements, then the subtype is\nequivalent to the original type. -/\n@[simps apply symm_apply]\ndef subtypeUnivEquiv {p : \u03b1 \u2192 Prop} (h : \u2200 x, p x) : Subtype p \u2243 \u03b1 :=\n  \u27e8fun x => x, fun x => \u27e8x, h x\u27e9, fun _ => Subtype.eq rfl, fun _ => rfl\u27e9\n#align equiv.subtype_univ_equiv Equiv.subtypeUnivEquiv\n#align equiv.subtype_univ_equiv_apply Equiv.subtypeUnivEquiv_apply\n#align equiv.subtype_univ_equiv_symm_apply Equiv.subtypeUnivEquiv_symm_apply\n\n/-- A subtype of a sigma-type is a sigma-type over a subtype. -/\ndef subtypeSigmaEquiv (p : \u03b1 \u2192 Type v) (q : \u03b1 \u2192 Prop) : { y : Sigma p // q y.1 } \u2243 \u03a3 x :\n    Subtype q, p x.1 :=\n  \u27e8fun x => \u27e8\u27e8x.1.1, x.2\u27e9, x.1.2\u27e9, fun x => \u27e8\u27e8x.1.1, x.2\u27e9, x.1.2\u27e9, fun _ => rfl,\n    fun _ => rfl\u27e9\n#align equiv.subtype_sigma_equiv Equiv.subtypeSigmaEquiv\n\n/-- A sigma type over a subtype is equivalent to the sigma set over the original type,\nif the fiber is empty outside of the subset -/\ndef sigmaSubtypeEquivOfSubset (p : \u03b1 \u2192 Type v) (q : \u03b1 \u2192 Prop) (h : \u2200 x, p x \u2192 q x) :\n    (\u03a3 x : Subtype q, p x) \u2243 \u03a3 x : \u03b1, p x :=\n  (subtypeSigmaEquiv p q).symm.trans <| subtypeUnivEquiv fun x => h x.1 x.2\n#align equiv.sigma_subtype_equiv_of_subset Equiv.sigmaSubtypeEquivOfSubset\n\n/-- If a predicate `p : \u03b2 \u2192 Prop` is true on the range of a map `f : \u03b1 \u2192 \u03b2`, then\n`\u03a3 y : {y // p y}, {x // f x = y}` is equivalent to `\u03b1`. -/\ndef sigmaSubtypeFiberEquiv {\u03b1 \u03b2 : Type _} (f : \u03b1 \u2192 \u03b2) (p : \u03b2 \u2192 Prop) (h : \u2200 x, p (f x)) :\n    (\u03a3 y : Subtype p, { x : \u03b1 // f x = y }) \u2243 \u03b1 :=\n  calc\n    _ \u2243 \u03a3y : \u03b2, { x : \u03b1 // f x = y } := sigmaSubtypeEquivOfSubset _ p fun _ \u27e8x, h'\u27e9 => h' \u25b8 h x\n    _ \u2243 \u03b1 := sigmaFiberEquiv f\n#align equiv.sigma_subtype_fiber_equiv Equiv.sigmaSubtypeFiberEquiv\n\n/-- If for each `x` we have `p x \u2194 q (f x)`, then `\u03a3 y : {y // q y}, f \u207b\u00b9' {y}` is equivalent\nto `{x // p x}`. -/\ndef sigmaSubtypeFiberEquivSubtype {\u03b1 \u03b2 : Type _} (f : \u03b1 \u2192 \u03b2) {p : \u03b1 \u2192 Prop} {q : \u03b2 \u2192 Prop}\n    (h : \u2200 x, p x \u2194 q (f x)) : (\u03a3 y : Subtype q, { x : \u03b1 // f x = y }) \u2243 Subtype p :=\n  calc\n    (\u03a3y : Subtype q, { x : \u03b1 // f x = y }) \u2243 \u03a3y :\n        Subtype q, { x : Subtype p // Subtype.mk (f x) ((h x).1 x.2) = y } := by {\n          apply sigmaCongrRight\n          intro y\n          apply Equiv.symm\n          refine' (subtypeSubtypeEquivSubtypeExists _ _).trans (subtypeEquivRight _)\n          intro x\n          exact \u27e8fun \u27e8hp, h'\u27e9 => congr_arg Subtype.val h', fun h' => \u27e8(h x).2 (h'.symm \u25b8 y.2),\n            Subtype.eq h'\u27e9\u27e9 }\n    _ \u2243 Subtype p := sigmaFiberEquiv fun x : Subtype p => (\u27e8f x, (h x).1 x.property\u27e9 : Subtype q)\n#align equiv.sigma_subtype_fiber_equiv_subtype Equiv.sigmaSubtypeFiberEquivSubtype\n\n/-- A sigma type over an `Option` is equivalent to the sigma set over the original type,\nif the fiber is empty at none. -/\ndef sigmaOptionEquivOfSome (p : Option \u03b1 \u2192 Type v) (h : p none \u2192 False) :\n    (\u03a3 x : Option \u03b1, p x) \u2243 \u03a3 x : \u03b1, p (some x) :=\n  haveI h' : \u2200 x, p x \u2192 x.isSome := by\n    intro x\n    cases x\n    \u00b7 intro n\n      exfalso\n      exact h n\n    \u00b7 intro _\n      exact rfl\n  (sigmaSubtypeEquivOfSubset _ _ h').symm.trans (sigmaCongrLeft' (optionIsSomeEquiv \u03b1))\n#align equiv.sigma_option_equiv_of_some Equiv.sigmaOptionEquivOfSome\n\n/-- The `Pi`-type `\u2200 i, \u03c0 i` is equivalent to the type of sections `f : \u03b9 \u2192 \u03a3 i, \u03c0 i` of the\n`Sigma` type such that for all `i` we have `(f i).fst = i`. -/\ndef piEquivSubtypeSigma (\u03b9) (\u03c0 : \u03b9 \u2192 Type _) :\n    (\u2200 i, \u03c0 i) \u2243 { f : \u03b9 \u2192 \u03a3 i, \u03c0 i // \u2200 i, (f i).1 = i } where\n  toFun := fun f => \u27e8fun i => \u27e8i, f i\u27e9, fun i => rfl\u27e9\n  invFun := fun f i => by rw [\u2190 f.2 i]; exact (f.1 i).2\n  left_inv := fun f => funext fun i => rfl\n  right_inv := fun \u27e8f, hf\u27e9 =>\n    Subtype.eq <| funext fun i =>\n      Sigma.eq (hf i).symm <| eq_of_heq <| rec_heq_of_heq _ <| by simp\n#align equiv.pi_equiv_subtype_sigma Equiv.piEquivSubtypeSigma\n\n/-- The type of functions `f : \u2200 a, \u03b2 a` such that for all `a` we have `p a (f a)` is equivalent\nto the type of functions `\u2200 a, {b : \u03b2 a // p a b}`. -/\ndef subtypePiEquivPi {\u03b2 : \u03b1 \u2192 Sort v} {p : \u2200 a, \u03b2 a \u2192 Prop} :\n    { f : \u2200 a, \u03b2 a // \u2200 a, p a (f a) } \u2243 \u2200 a, { b : \u03b2 a // p a b } where\n  toFun := fun f a => \u27e8f.1 a, f.2 a\u27e9\n  invFun := fun f => \u27e8fun a => (f a).1, fun a => (f a).2\u27e9\n  left_inv := by\n    rintro \u27e8f, h\u27e9\n    rfl\n  right_inv := by\n    rintro f\n    funext a\n    exact Subtype.ext_val rfl\n#align equiv.subtype_pi_equiv_pi Equiv.subtypePiEquivPi\n\n/-- A subtype of a product defined by componentwise conditions\nis equivalent to a product of subtypes. -/\ndef subtypeProdEquivProd {p : \u03b1 \u2192 Prop} {q : \u03b2 \u2192 Prop} :\n    { c : \u03b1 \u00d7 \u03b2 // p c.1 \u2227 q c.2 } \u2243 { a // p a } \u00d7 { b // q b } where\n  toFun := fun x => \u27e8\u27e8x.1.1, x.2.1\u27e9, \u27e8x.1.2, x.2.2\u27e9\u27e9\n  invFun := fun x => \u27e8\u27e8x.1.1, x.2.1\u27e9, \u27e8x.1.2, x.2.2\u27e9\u27e9\n  left_inv := fun \u27e8\u27e8_, _\u27e9, \u27e8_, _\u27e9\u27e9 => rfl\n  right_inv := fun \u27e8\u27e8_, _\u27e9, \u27e8_, _\u27e9\u27e9 => rfl\n#align equiv.subtype_prod_equiv_prod Equiv.subtypeProdEquivProd\n\n/-- A subtype of a `Prod` is equivalent to a sigma type whose fibers are subtypes. -/\ndef subtypeProdEquivSigmaSubtype (p : \u03b1 \u2192 \u03b2 \u2192 Prop) :\n    { x : \u03b1 \u00d7 \u03b2 // p x.1 x.2 } \u2243 \u03a3a, { b : \u03b2 // p a b } where\n  toFun x := \u27e8x.1.1, x.1.2, x.property\u27e9\n  invFun x := \u27e8\u27e8x.1, x.2\u27e9, x.2.property\u27e9\n  left_inv x := by ext <;> rfl\n  right_inv := fun \u27e8a, b, pab\u27e9 => rfl\n#align equiv.subtype_prod_equiv_sigma_subtype Equiv.subtypeProdEquivSigmaSubtype\n\n/-- The type `\u2200 (i : \u03b1), \u03b2 i` can be split as a product by separating the indices in `\u03b1`\ndepending on whether they satisfy a predicate `p` or not. -/\n@[simps]\ndef piEquivPiSubtypeProd {\u03b1 : Type _} (p : \u03b1 \u2192 Prop) (\u03b2 : \u03b1 \u2192 Type _) [DecidablePred p] :\n    (\u2200 i : \u03b1, \u03b2 i) \u2243 (\u2200 i : { x // p x }, \u03b2 i) \u00d7 \u2200 i : { x // \u00acp x }, \u03b2 i where\n  toFun f := (fun x => f x, fun x => f x)\n  invFun f x := if h : p x then f.1 \u27e8x, h\u27e9 else f.2 \u27e8x, h\u27e9\n  right_inv := by\n    rintro \u27e8f, g\u27e9\n    ext1 <;>\n      \u00b7 ext y\n        rcases y with \u27e8val, property\u27e9\n        simp only [property, dif_pos, dif_neg, not_false_iff, Subtype.coe_mk]\n  left_inv f := by\n    ext x\n    by_cases h:p x <;>\n      \u00b7 simp only [h, dif_neg, dif_pos, not_false_iff]\n#align equiv.pi_equiv_pi_subtype_prod Equiv.piEquivPiSubtypeProd\n#align equiv.pi_equiv_pi_subtype_prod_symm_apply Equiv.piEquivPiSubtypeProd_symm_apply\n#align equiv.pi_equiv_pi_subtype_prod_apply Equiv.piEquivPiSubtypeProd_apply\n\n/-- A product of types can be split as the binary product of one of the types and the product\n  of all the remaining types. -/\n@[simps]\ndef piSplitAt {\u03b1 : Type _} [DecidableEq \u03b1] (i : \u03b1) (\u03b2 : \u03b1 \u2192 Type _) :\n    (\u2200 j, \u03b2 j) \u2243 \u03b2 i \u00d7 \u2200 j : { j // j \u2260 i }, \u03b2 j where\n  toFun f := \u27e8f i, fun j => f j\u27e9\n  invFun f j := if h : j = i then h.symm.rec f.1 else f.2 \u27e8j, h\u27e9\n  right_inv f := by\n    ext x\n    exacts[dif_pos rfl, (dif_neg x.2).trans (by cases x; rfl)]\n  left_inv f := by\n    ext x\n    dsimp only\n    split_ifs with h\n    \u00b7 subst h; rfl\n    \u00b7 rfl\n#align equiv.pi_split_at Equiv.piSplitAt\n#align equiv.pi_split_at_apply Equiv.piSplitAt_apply\n#align equiv.pi_split_at_symm_apply Equiv.piSplitAt_symm_apply\n\n/-- A product of copies of a type can be split as the binary product of one copy and the product\n  of all the remaining copies. -/\n@[simps!]\ndef funSplitAt {\u03b1 : Type _} [DecidableEq \u03b1] (i : \u03b1) (\u03b2 : Type _) :\n    (\u03b1 \u2192 \u03b2) \u2243 \u03b2 \u00d7 ({ j // j \u2260 i } \u2192 \u03b2) :=\n  piSplitAt i _\n#align equiv.fun_split_at Equiv.funSplitAt\n#align equiv.fun_split_at_symm_apply Equiv.funSplitAt_symm_apply\n#align equiv.fun_split_at_apply Equiv.funSplitAt_apply\n\nend\n\nsection subtypeEquivCodomain\n\nvariable [DecidableEq X] {x : X}\n\n/-- The type of all functions `X \u2192 Y` with prescribed values for all `x' \u2260 x`\nis equivalent to the codomain `Y`. -/\ndef subtypeEquivCodomain (f : { x' // x' \u2260 x } \u2192 Y) :\n    { g : X \u2192 Y // g \u2218 (\u2191) = f } \u2243 Y :=\n  (subtypePreimage _ f).trans <|\n    @funUnique { x' // \u00acx' \u2260 x } _ <|\n      show Unique { x' // \u00acx' \u2260 x } from\n        @Equiv.unique _ _\n          (show Unique { x' // x' = x } from {\n            default := \u27e8x, rfl\u27e9, uniq := fun \u27e8_, h\u27e9 => Subtype.val_injective h })\n          (subtypeEquivRight fun _ => not_not)\n#align equiv.subtype_equiv_codomain Equiv.subtypeEquivCodomain\n\n@[simp]\ntheorem coe_subtypeEquivCodomain (f : { x' // x' \u2260 x } \u2192 Y) :\n    (subtypeEquivCodomain f : _ \u2192 Y) =\n      fun g : { g : X \u2192 Y // g \u2218 (\u2191) = f } => (g : X \u2192 Y) x :=\n  rfl\n#align equiv.coe_subtype_equiv_codomain Equiv.coe_subtypeEquivCodomain\n\n@[simp]\ntheorem subtypeEquivCodomain_apply (f : { x' // x' \u2260 x } \u2192 Y) (g) :\n    subtypeEquivCodomain f g = (g : X \u2192 Y) x :=\n  rfl\n#align equiv.subtype_equiv_codomain_apply Equiv.subtypeEquivCodomain_apply\n\ntheorem coe_subtypeEquivCodomain_symm (f : { x' // x' \u2260 x } \u2192 Y) :\n    ((subtypeEquivCodomain f).symm : Y \u2192 _) = fun y =>\n      \u27e8fun x' => if h : x' \u2260 x then f \u27e8x', h\u27e9 else y, by\n        funext x'\n        simp only [ne_eq, dite_not, comp_apply, Subtype.coe_eta, dite_eq_ite, ite_eq_right_iff]\n        intro w\n        exfalso\n        exact x'.property w\u27e9 :=\n  rfl\n#align equiv.coe_subtype_equiv_codomain_symm Equiv.coe_subtypeEquivCodomain_symm\n\n@[simp]\ntheorem subtypeEquivCodomain_symm_apply (f : { x' // x' \u2260 x } \u2192 Y) (y : Y) (x' : X) :\n    ((subtypeEquivCodomain f).symm y : X \u2192 Y) x' = if h : x' \u2260 x then f \u27e8x', h\u27e9 else y :=\n  rfl\n#align equiv.subtype_equiv_codomain_symm_apply Equiv.subtypeEquivCodomain_symm_apply\n\ntheorem subtypeEquivCodomain_symm_apply_eq (f : { x' // x' \u2260 x } \u2192 Y) (y : Y) :\n    ((subtypeEquivCodomain f).symm y : X \u2192 Y) x = y :=\n  dif_neg (not_not.mpr rfl)\n#align equiv.subtype_equiv_codomain_symm_apply_eq Equiv.subtypeEquivCodomain_symm_apply_eq\n\ntheorem subtypeEquivCodomain_symm_apply_ne\n    (f : { x' // x' \u2260 x } \u2192 Y) (y : Y) (x' : X) (h : x' \u2260 x) :\n    ((subtypeEquivCodomain f).symm y : X \u2192 Y) x' = f \u27e8x', h\u27e9 :=\n  dif_pos h\n#align equiv.subtype_equiv_codomain_symm_apply_ne Equiv.subtypeEquivCodomain_symm_apply_ne\n\nend subtypeEquivCodomain\n\n/-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/\n@[simps apply]\nnoncomputable def ofBijective (f : \u03b1 \u2192 \u03b2) (hf : Bijective f) : \u03b1 \u2243 \u03b2 where\n  toFun := f\n  invFun := Function.surjInv hf.surjective\n  left_inv := Function.leftInverse_surjInv hf\n  right_inv := Function.rightInverse_surjInv _\n#align equiv.of_bijective Equiv.ofBijective\n#align equiv.of_bijective_apply Equiv.ofBijective_apply\n\ntheorem ofBijective_apply_symm_apply (f : \u03b1 \u2192 \u03b2) (hf : Bijective f) (x : \u03b2) :\n    f ((ofBijective f hf).symm x) = x :=\n  (ofBijective f hf).apply_symm_apply x\n#align equiv.of_bijective_apply_symm_apply Equiv.ofBijective_apply_symm_apply\n\n@[simp]\ntheorem ofBijective_symm_apply_apply (f : \u03b1 \u2192 \u03b2) (hf : Bijective f) (x : \u03b1) :\n    (ofBijective f hf).symm (f x) = x :=\n  (ofBijective f hf).symm_apply_apply x\n#align equiv.of_bijective_symm_apply_apply Equiv.ofBijective_symm_apply_apply\n\ninstance : CanLift (\u03b1 \u2192 \u03b2) (\u03b1 \u2243 \u03b2) (\u2191) Bijective where prf f hf := \u27e8ofBijective f hf, rfl\u27e9\n\nsection\n\nvariable {\u03b1' \u03b2' : Type _} (e : Perm \u03b1') {p : \u03b2' \u2192 Prop} [DecidablePred p] (f : \u03b1' \u2243 Subtype p)\n\n/-- Extend the domain of `e : Equiv.Perm \u03b1` to one that is over `\u03b2` via `f : \u03b1 \u2192 Subtype p`,\nwhere `p : \u03b2 \u2192 Prop`, permuting only the `b : \u03b2` that satisfy `p b`.\nThis can be used to extend the domain across a function `f : \u03b1 \u2192 \u03b2`,\nkeeping everything outside of `Set.range f` fixed. For this use-case `Equiv` given by `f` can\nbe constructed by `Equiv.of_leftInverse'` or `Equiv.of_leftInverse` when there is a known\ninverse, or `Equiv.ofInjective` in the general case.`.\n-/\ndef Perm.extendDomain : Perm \u03b2' :=\n  (permCongr f e).subtypeCongr (Equiv.refl _)\n#align equiv.perm.extend_domain Equiv.Perm.extendDomain\n\n@[simp]\ntheorem Perm.extendDomain_apply_image (a : \u03b1') : e.extendDomain f (f a) = f (e a) := by\n  simp [Perm.extendDomain]\n#align equiv.perm.extend_domain_apply_image Equiv.Perm.extendDomain_apply_image\n\ntheorem Perm.extendDomain_apply_subtype {b : \u03b2'} (h : p b) :\n    e.extendDomain f b = f (e (f.symm \u27e8b, h\u27e9)) := by\n  simp [Perm.extendDomain, h]\n#align equiv.perm.extend_domain_apply_subtype Equiv.Perm.extendDomain_apply_subtype\n\ntheorem Perm.extendDomain_apply_not_subtype {b : \u03b2'} (h : \u00acp b) : e.extendDomain f b = b := by\n  simp [Perm.extendDomain, h]\n#align equiv.perm.extend_domain_apply_not_subtype Equiv.Perm.extendDomain_apply_not_subtype\n\n@[simp]\ntheorem Perm.extendDomain_refl : Perm.extendDomain (Equiv.refl _) f = Equiv.refl _ := by\n  simp [Perm.extendDomain]\n#align equiv.perm.extend_domain_refl Equiv.Perm.extendDomain_refl\n\n@[simp]\ntheorem Perm.extendDomain_symm : (e.extendDomain f).symm = Perm.extendDomain e.symm f :=\n  rfl\n#align equiv.perm.extend_domain_symm Equiv.Perm.extendDomain_symm\n\ntheorem Perm.extendDomain_trans (e e' : Perm \u03b1') :\n    (e.extendDomain f).trans (e'.extendDomain f) = Perm.extendDomain (e.trans e') f := by\n  simp [Perm.extendDomain, permCongr_trans]\n#align equiv.perm.extend_domain_trans Equiv.Perm.extendDomain_trans\n\nend\n\n/-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `\u03b1` be a setoid with\nequivalence relation `~`. Let `p\u2082` be a predicate on the quotient type `\u03b1/~`, and `p\u2081` be the lift\nof this predicate to `\u03b1`: `p\u2081 a \u2194 p\u2082 \u27e6a\u27e7`. Let `~\u2082` be the restriction of `~` to `{x // p\u2081 x}`.\nThen `{x // p\u2082 x}` is equivalent to the quotient of `{x // p\u2081 x}` by `~\u2082`. -/\ndef subtypeQuotientEquivQuotientSubtype (p\u2081 : \u03b1 \u2192 Prop) [s\u2081 : Setoid \u03b1] [s\u2082 : Setoid (Subtype p\u2081)]\n    (p\u2082 : Quotient s\u2081 \u2192 Prop) (hp\u2082 : \u2200 a, p\u2081 a \u2194 p\u2082 \u27e6a\u27e7)\n    (h : \u2200 x y : Subtype p\u2081, @Setoid.r _ s\u2082 x y \u2194 (x : \u03b1) \u2248 y) :\n    { x // p\u2082 x } \u2243 Quotient s\u2082 where\n  toFun a :=\n    Quotient.hrecOn a.1 (fun a h => \u27e6\u27e8a, (hp\u2082 _).2 h\u27e9\u27e7)\n      (fun a b hab => hfunext (by rw [Quotient.sound hab]) fun h\u2081 h\u2082 _ =>\n        heq_of_eq (Quotient.sound ((h _ _).2 hab)))\n      a.2\n  invFun a :=\n    Quotient.liftOn a (fun a => (\u27e8\u27e6a.1\u27e7, (hp\u2082 _).1 a.2\u27e9 : { x // p\u2082 x })) fun a b hab =>\n      Subtype.ext_val (Quotient.sound ((h _ _).1 hab))\n  left_inv := by exact fun \u27e8a, ha\u27e9 => Quotient.inductionOn a (fun b hb => rfl) ha\n  right_inv a := Quotient.inductionOn a fun \u27e8a, ha\u27e9 => rfl\n#align equiv.subtype_quotient_equiv_quotient_subtype Equiv.subtypeQuotientEquivQuotientSubtype\n\n@[simp]\ntheorem subtypeQuotientEquivQuotientSubtype_mk (p\u2081 : \u03b1 \u2192 Prop)\n    [s\u2081 : Setoid \u03b1] [s\u2082 : Setoid (Subtype p\u2081)] (p\u2082 : Quotient s\u2081 \u2192 Prop) (hp\u2082 : \u2200 a, p\u2081 a \u2194 p\u2082 \u27e6a\u27e7)\n    (h : \u2200 x y : Subtype p\u2081, @Setoid.r _ s\u2082 x y \u2194 (x : \u03b1) \u2248 y)\n    (x hx) : subtypeQuotientEquivQuotientSubtype p\u2081 p\u2082 hp\u2082 h \u27e8\u27e6x\u27e7, hx\u27e9 = \u27e6\u27e8x, (hp\u2082 _).2 hx\u27e9\u27e7 :=\n  rfl\n#align equiv.subtype_quotient_equiv_quotient_subtype_mk Equiv.subtypeQuotientEquivQuotientSubtype_mk\n\n@[simp]\ntheorem subtypeQuotientEquivQuotientSubtype_symm_mk (p\u2081 : \u03b1 \u2192 Prop)\n    [s\u2081 : Setoid \u03b1] [s\u2082 : Setoid (Subtype p\u2081)] (p\u2082 : Quotient s\u2081 \u2192 Prop) (hp\u2082 : \u2200 a, p\u2081 a \u2194 p\u2082 \u27e6a\u27e7)\n    (h : \u2200 x y : Subtype p\u2081, @Setoid.r _ s\u2082 x y \u2194 (x : \u03b1) \u2248 y) (x) :\n    (subtypeQuotientEquivQuotientSubtype p\u2081 p\u2082 hp\u2082 h).symm \u27e6x\u27e7 = \u27e8\u27e6x\u27e7, (hp\u2082 _).1 x.property\u27e9 :=\n  rfl\n#align equiv.subtype_quotient_equiv_quotient_subtype_symm_mk Equiv.subtypeQuotientEquivQuotientSubtype_symm_mk\n\nsection Swap\n\nvariable [DecidableEq \u03b1]\n\n/-- A helper function for `Equiv.swap`. -/\ndef swapCore (a b r : \u03b1) : \u03b1 :=\n  if r = a then b else if r = b then a else r\n#align equiv.swap_core Equiv.swapCore\n\ntheorem swapCore_self (r a : \u03b1) : swapCore a a r = r := by\n  unfold swapCore\n  split_ifs <;> simp [*]\n#align equiv.swap_core_self Equiv.swapCore_self\n\ntheorem swapCore_swapCore (r a b : \u03b1) : swapCore a b (swapCore a b r) = r := by\n  unfold swapCore\n  -- Porting note: cc missing.\n  -- `casesm` would work here, with `casesm _ = _, \u00ac _ = _`,\n  -- if it would just continue past failures on hypotheses matching the pattern\n  split_ifs with h\u2081 h\u2082 h\u2083 h\u2084 h\u2085\n  \u00b7 subst h\u2081; exact h\u2082\n  \u00b7 subst h\u2081; rfl\n  \u00b7 cases h\u2083 rfl\n  \u00b7 exact h\u2084.symm\n  \u00b7 cases h\u2085 rfl\n  \u00b7 cases h\u2085 rfl\n  \u00b7 rfl\n#align equiv.swap_core_swap_core Equiv.swapCore_swapCore\n\ntheorem swapCore_comm (r a b : \u03b1) : swapCore a b r = swapCore b a r := by\n  unfold swapCore\n  -- Porting note: whatever solution works for `swapCore_swapCore` will work here too.\n  split_ifs with h\u2081 h\u2082 h\u2083 <;> simp\n  \u00b7 cases h\u2081; cases h\u2082; rfl\n#align equiv.swap_core_comm Equiv.swapCore_comm\n\n/-- `swap a b` is the permutation that swaps `a` and `b` and\n  leaves other values as is. -/\ndef swap (a b : \u03b1) : Perm \u03b1 :=\n  \u27e8swapCore a b, swapCore a b, fun r => swapCore_swapCore r a b,\n    fun r => swapCore_swapCore r a b\u27e9\n#align equiv.swap Equiv.swap\n\n@[simp]\ntheorem swap_self (a : \u03b1) : swap a a = Equiv.refl _ :=\n  ext fun r => swapCore_self r a\n#align equiv.swap_self Equiv.swap_self\n\ntheorem swap_comm (a b : \u03b1) : swap a b = swap b a :=\n  ext fun r => swapCore_comm r _ _\n#align equiv.swap_comm Equiv.swap_comm\n\ntheorem swap_apply_def (a b x : \u03b1) : swap a b x = if x = a then b else if x = b then a else x :=\n  rfl\n#align equiv.swap_apply_def Equiv.swap_apply_def\n\n@[simp]\ntheorem swap_apply_left (a b : \u03b1) : swap a b a = b :=\n  if_pos rfl\n#align equiv.swap_apply_left Equiv.swap_apply_left\n\n@[simp]\ntheorem swap_apply_right (a b : \u03b1) : swap a b b = a := by\n  by_cases h:b = a <;> simp [swap_apply_def, h]\n#align equiv.swap_apply_right Equiv.swap_apply_right\n\ntheorem swap_apply_of_ne_of_ne {a b x : \u03b1} : x \u2260 a \u2192 x \u2260 b \u2192 swap a b x = x := by\n  simp (config := { contextual := true }) [swap_apply_def]\n#align equiv.swap_apply_of_ne_of_ne Equiv.swap_apply_of_ne_of_ne\n\n@[simp]\ntheorem swap_swap (a b : \u03b1) : (swap a b).trans (swap a b) = Equiv.refl _ :=\n  ext fun _ => swapCore_swapCore _ _ _\n#align equiv.swap_swap Equiv.swap_swap\n\n@[simp]\ntheorem symm_swap (a b : \u03b1) : (swap a b).symm = swap a b :=\n  rfl\n#align equiv.symm_swap Equiv.symm_swap\n\n@[simp]\ntheorem swap_eq_refl_iff {x y : \u03b1} : swap x y = Equiv.refl _ \u2194 x = y := by\n  refine' \u27e8fun h => (Equiv.refl _).injective _, fun h => h \u25b8 swap_self _\u27e9\n  rw [\u2190 h, swap_apply_left, h, refl_apply]\n#align equiv.swap_eq_refl_iff Equiv.swap_eq_refl_iff\n\ntheorem swap_comp_apply {a b x : \u03b1} (\u03c0 : Perm \u03b1) :\n    \u03c0.trans (swap a b) x = if \u03c0 x = a then b else if \u03c0 x = b then a else \u03c0 x := by\n  cases \u03c0\n  rfl\n#align equiv.swap_comp_apply Equiv.swap_comp_apply\n\ntheorem swap_eq_update (i j : \u03b1) : (Equiv.swap i j : \u03b1 \u2192 \u03b1) = update (update id j i) i j :=\n  funext fun x => by rw [update_apply _ i j, update_apply _ j i, Equiv.swap_apply_def, id.def]\n#align equiv.swap_eq_update Equiv.swap_eq_update\n\ntheorem comp_swap_eq_update (i j : \u03b1) (f : \u03b1 \u2192 \u03b2) :\n    f \u2218 Equiv.swap i j = update (update f j (f i)) i (f j) := by\n  rw [swap_eq_update, comp_update, comp_update, comp.right_id]\n#align equiv.comp_swap_eq_update Equiv.comp_swap_eq_update\n\n@[simp]\ntheorem symm_trans_swap_trans [DecidableEq \u03b2] (a b : \u03b1) (e : \u03b1 \u2243 \u03b2) :\n    (e.symm.trans (swap a b)).trans e = swap (e a) (e b) :=\n  Equiv.ext fun x => by\n    have : \u2200 a, e.symm x = a \u2194 x = e a := fun a => by\n      rw [@eq_comm _ (e.symm x)]\n      constructor <;> intros <;> simp_all\n    simp [trans_apply, swap_apply_def, this]\n    split_ifs <;> simp\n#align equiv.symm_trans_swap_trans Equiv.symm_trans_swap_trans\n\n@[simp]\ntheorem trans_swap_trans_symm [DecidableEq \u03b2] (a b : \u03b2) (e : \u03b1 \u2243 \u03b2) :\n    (e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) :=\n  symm_trans_swap_trans a b e.symm\n#align equiv.trans_swap_trans_symm Equiv.trans_swap_trans_symm\n\n@[simp]\ntheorem swap_apply_self (i j a : \u03b1) : swap i j (swap i j a) = a := by\n  rw [\u2190 Equiv.trans_apply, Equiv.swap_swap, Equiv.refl_apply]\n#align equiv.swap_apply_self Equiv.swap_apply_self\n\n/-- A function is invariant to a swap if it is equal at both elements -/\ntheorem apply_swap_eq_self {v : \u03b1 \u2192 \u03b2} {i j : \u03b1} (hv : v i = v j) (k : \u03b1) :\n    v (swap i j k) = v k := by\n  by_cases hi : k = i\n  \u00b7 rw [hi, swap_apply_left, hv]\n\n  by_cases hj : k = j\n  \u00b7 rw [hj, swap_apply_right, hv]\n\n  rw [swap_apply_of_ne_of_ne hi hj]\n#align equiv.apply_swap_eq_self Equiv.apply_swap_eq_self\n\ntheorem swap_apply_eq_iff {x y z w : \u03b1} : swap x y z = w \u2194 z = swap x y w := by\n  rw [apply_eq_iff_eq_symm_apply, symm_swap]\n#align equiv.swap_apply_eq_iff Equiv.swap_apply_eq_iff\n\n\n\n  by_cases hax : x = a\n  \u00b7 simp [hax, eq_comm]\n\n  by_cases hbx : x = b\n  \u00b7 simp [hbx]\n\n  simp [hab, hax, hbx, swap_apply_of_ne_of_ne]\n#align equiv.swap_apply_ne_self_iff Equiv.swap_apply_ne_self_iff\n\nnamespace Perm\n\n@[simp]\ntheorem sumCongr_swap_refl {\u03b1 \u03b2 : Sort _} [DecidableEq \u03b1] [DecidableEq \u03b2] (i j : \u03b1) :\n    Equiv.Perm.sumCongr (Equiv.swap i j) (Equiv.refl \u03b2) = Equiv.swap (Sum.inl i) (Sum.inl j) := by\n  ext x\n  cases x\n  \u00b7 simp only [Equiv.sumCongr_apply, Sum.map, coe_refl, comp.right_id, Sum.elim_inl, comp_apply,\n      swap_apply_def, Sum.inl.injEq]\n    split_ifs <;> rfl\n\n  \u00b7 simp [Sum.map, swap_apply_of_ne_of_ne]\n\n#align equiv.perm.sum_congr_swap_refl Equiv.Perm.sumCongr_swap_refl\n\n@[simp]\ntheorem sumCongr_refl_swap {\u03b1 \u03b2 : Sort _} [DecidableEq \u03b1] [DecidableEq \u03b2] (i j : \u03b2) :\n    Equiv.Perm.sumCongr (Equiv.refl \u03b1) (Equiv.swap i j) = Equiv.swap (Sum.inr i) (Sum.inr j) := by\n  ext x\n  cases x\n  \u00b7 simp [Sum.map, swap_apply_of_ne_of_ne]\n\n  \u00b7 simp only [Equiv.sumCongr_apply, Sum.map, coe_refl, comp.right_id, Sum.elim_inr, comp_apply,\n      swap_apply_def, Sum.inr.injEq]\n    split_ifs <;> rfl\n\n#align equiv.perm.sum_congr_refl_swap Equiv.Perm.sumCongr_refl_swap\n\nend Perm\n\n/-- Augment an equivalence with a prescribed mapping `f a = b` -/\ndef setValue (f : \u03b1 \u2243 \u03b2) (a : \u03b1) (b : \u03b2) : \u03b1 \u2243 \u03b2 :=\n  (swap a (f.symm b)).trans f\n#align equiv.set_value Equiv.setValue\n\n@[simp]\ntheorem setValue_eq (f : \u03b1 \u2243 \u03b2) (a : \u03b1) (b : \u03b2) : setValue f a b a = b := by\n  simp [setValue, swap_apply_left]\n#align equiv.set_value_eq Equiv.setValue_eq\n\nend Swap\n\nend Equiv\n\nnamespace Function.Involutive\n\n/-- Convert an involutive function `f` to a permutation with `toFun = invFun = f`. -/\ndef toPerm (f : \u03b1 \u2192 \u03b1) (h : Involutive f) : Equiv.Perm \u03b1 :=\n  \u27e8f, f, h.leftInverse, h.rightInverse\u27e9\n#align function.involutive.to_perm Function.Involutive.toPerm\n\n@[simp]\ntheorem coe_toPerm {f : \u03b1 \u2192 \u03b1} (h : Involutive f) : (h.toPerm f : \u03b1 \u2192 \u03b1) = f :=\n  rfl\n#align function.involutive.coe_to_perm Function.Involutive.coe_toPerm\n\n@[simp]\ntheorem toPerm_symm {f : \u03b1 \u2192 \u03b1} (h : Involutive f) : (h.toPerm f).symm = h.toPerm f :=\n  rfl\n#align function.involutive.to_perm_symm Function.Involutive.toPerm_symm\n\ntheorem toPerm_involutive {f : \u03b1 \u2192 \u03b1} (h : Involutive f) : Involutive (h.toPerm f) :=\n  h\n#align function.involutive.to_perm_involutive Function.Involutive.toPerm_involutive\n\nend Function.Involutive\n\ntheorem PLift.eq_up_iff_down_eq {x : PLift \u03b1} {y : \u03b1} : x = PLift.up y \u2194 x.down = y :=\n  Equiv.plift.eq_symm_apply\n#align plift.eq_up_iff_down_eq PLift.eq_up_iff_down_eq\n\ntheorem Function.Injective.map_swap [DecidableEq \u03b1] [DecidableEq \u03b2] {f : \u03b1 \u2192 \u03b2}\n    (hf : Function.Injective f) (x y z : \u03b1) :\n    f (Equiv.swap x y z) = Equiv.swap (f x) (f y) (f z) := by\n  conv_rhs => rw [Equiv.swap_apply_def]\n  split_ifs with h\u2081 h\u2082\n  \u00b7 rw [hf h\u2081, Equiv.swap_apply_left]\n\n  \u00b7 rw [hf h\u2082, Equiv.swap_apply_right]\n\n  \u00b7 rw [Equiv.swap_apply_of_ne_of_ne (mt (congr_arg f) h\u2081) (mt (congr_arg f) h\u2082)]\n\n#align function.injective.map_swap Function.Injective.map_swap\n\nnamespace Equiv\n\nsection\n\nvariable (P : \u03b1 \u2192 Sort w) (e : \u03b1 \u2243 \u03b2)\n\n/-- Transport dependent functions through an equivalence of the base space.\n-/\n@[simps]\ndef piCongrLeft' (P : \u03b1 \u2192 Sort _) (e : \u03b1 \u2243 \u03b2) : (\u2200 a, P a) \u2243 \u2200 b, P (e.symm b) where\n  toFun f x := f (e.symm x)\n  invFun f x := (e.symm_apply_apply x).ndrec (f (e x))\n  left_inv f := funext fun x =>\n    (by rintro _ rfl; rfl : \u2200 {y} (h : y = x), h.ndrec (f y) = f x) (e.symm_apply_apply x)\n  right_inv f := funext fun x =>\n    (by rintro _ rfl; rfl : \u2200 {y} (h : y = x), (congr_arg e.symm h).ndrec (f y) = f x)\n      (e.apply_symm_apply x)\n#align equiv.Pi_congr_left' Equiv.piCongrLeft'\n#align equiv.Pi_congr_left'_apply Equiv.piCongrLeft'_apply\n#align equiv.Pi_congr_left'_symm_apply Equiv.piCongrLeft'_symm_apply\n\nend\n\nsection\n\nvariable (P : \u03b2 \u2192 Sort w) (e : \u03b1 \u2243 \u03b2)\n\n/-- Transporting dependent functions through an equivalence of the base,\nexpressed as a \"simplification\".\n-/\ndef piCongrLeft : (\u2200 a, P (e a)) \u2243 \u2200 b, P b :=\n  (piCongrLeft' P e.symm).symm\n#align equiv.Pi_congr_left Equiv.piCongrLeft\n\nend\n\nsection\n\nvariable {W : \u03b1 \u2192 Sort w} {Z : \u03b2 \u2192 Sort z} (h\u2081 : \u03b1 \u2243 \u03b2) (h\u2082 : \u2200 a : \u03b1, W a \u2243 Z (h\u2081 a))\n\n/-- Transport dependent functions through\nan equivalence of the base spaces and a family\nof equivalences of the matching fibers.\n-/\ndef piCongr : (\u2200 a, W a) \u2243 \u2200 b, Z b :=\n  (Equiv.piCongrRight h\u2082).trans (Equiv.piCongrLeft _ h\u2081)\n#align equiv.Pi_congr Equiv.piCongr\n\n@[simp]\ntheorem coe_piCongr_symm : ((h\u2081.piCongr h\u2082).symm :\n    (\u2200 b, Z b) \u2192 \u2200 a, W a) = fun f a => (h\u2082 a).symm (f (h\u2081 a)) :=\n  rfl\n#align equiv.coe_Pi_congr_symm Equiv.coe_piCongr_symm\n\ntheorem piCongr_symm_apply (f : \u2200 b, Z b) :\n    (h\u2081.piCongr h\u2082).symm f = fun a => (h\u2082 a).symm (f (h\u2081 a)) :=\n  rfl\n#align equiv.Pi_congr_symm_apply Equiv.piCongr_symm_apply\n\n@[simp]\ntheorem piCongr_apply_apply (f : \u2200 a, W a) (a : \u03b1) : h\u2081.piCongr h\u2082 f (h\u2081 a) = h\u2082 a (f a) := by\n  change Eq.ndrec _ _ = _\n  generalize_proofs hZa\n  revert hZa\n  rw [h\u2081.symm_apply_apply a]\n  simp; rfl\n#align equiv.Pi_congr_apply_apply Equiv.piCongr_apply_apply\n\nend\n\nsection\n\nvariable {W : \u03b1 \u2192 Sort w} {Z : \u03b2 \u2192 Sort z} (h\u2081 : \u03b1 \u2243 \u03b2) (h\u2082 : \u2200 b : \u03b2, W (h\u2081.symm b) \u2243 Z b)\n\n/-- Transport dependent functions through\nan equivalence of the base spaces and a family\nof equivalences of the matching fibres.\n-/\ndef piCongr' : (\u2200 a, W a) \u2243 \u2200 b, Z b :=\n  (piCongr h\u2081.symm fun b => (h\u2082 b).symm).symm\n#align equiv.Pi_congr' Equiv.piCongr'\n\n@[simp]\ntheorem coe_piCongr' :\n    (h\u2081.piCongr' h\u2082 : (\u2200 a, W a) \u2192 \u2200 b, Z b) = fun f b => h\u2082 b <| f <| h\u2081.symm b :=\n  rfl\n#align equiv.coe_Pi_congr' Equiv.coe_piCongr'\n\ntheorem piCongr'_apply (f : \u2200 a, W a) : h\u2081.piCongr' h\u2082 f = fun b => h\u2082 b <| f <| h\u2081.symm b :=\n  rfl\n#align equiv.Pi_congr'_apply Equiv.piCongr'_apply\n\n@[simp]\ntheorem piCongr'_symm_apply_symm_apply (f : \u2200 b, Z b) (b : \u03b2) :\n    (h\u2081.piCongr' h\u2082).symm f (h\u2081.symm b) = (h\u2082 b).symm (f b) := by\n  change Eq.ndrec _ _ = _\n  generalize_proofs hWb\n  revert hWb\n  generalize hb : h\u2081 (h\u2081.symm b) = b'\n  rw [h\u2081.apply_symm_apply b] at hb\n  subst hb\n  simp; rfl\n#align equiv.Pi_congr'_symm_apply_symm_apply Equiv.piCongr'_symm_apply_symm_apply\n\nend\n\nsection BinaryOp\n\nvariable (e : \u03b1\u2081 \u2243 \u03b2\u2081) (f : \u03b1\u2081 \u2192 \u03b1\u2081 \u2192 \u03b1\u2081)\n\ntheorem semiconj_conj (f : \u03b1\u2081 \u2192 \u03b1\u2081) : Semiconj e f (e.conj f) := fun x => by simp\n#align equiv.semiconj_conj Equiv.semiconj_conj\n\ntheorem semiconj\u2082_conj : Semiconj\u2082 e f (e.arrowCongr e.conj f) := fun x y => by simp [arrowCongr]\n#align equiv.semiconj\u2082_conj Equiv.semiconj\u2082_conj\n\ninstance [IsAssociative \u03b1\u2081 f] : IsAssociative \u03b2\u2081 (e.arrowCongr (e.arrowCongr e) f) :=\n  (e.semiconj\u2082_conj f).isAssociative_right e.surjective\n\ninstance [IsIdempotent \u03b1\u2081 f] : IsIdempotent \u03b2\u2081 (e.arrowCongr (e.arrowCongr e) f) :=\n  (e.semiconj\u2082_conj f).isIdempotent_right e.surjective\n\ninstance [IsLeftCancel \u03b1\u2081 f] : IsLeftCancel \u03b2\u2081 (e.arrowCongr (e.arrowCongr e) f) :=\n  \u27e8e.surjective.forall\u2083.2 fun x y z => by simpa using @IsLeftCancel.left_cancel _ f _ x y z\u27e9\n\ninstance [IsRightCancel \u03b1\u2081 f] : IsRightCancel \u03b2\u2081 (e.arrowCongr (e.arrowCongr e) f) :=\n  \u27e8e.surjective.forall\u2083.2 fun x y z => by simpa using @IsRightCancel.right_cancel _ f _ x y z\u27e9\n\nend BinaryOp\n\nend Equiv\n\ntheorem Function.Injective.swap_apply\n    [DecidableEq \u03b1] [DecidableEq \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Function.Injective f) (x y z : \u03b1) :\n    Equiv.swap (f x) (f y) (f z) = f (Equiv.swap x y z) := by\n  by_cases hx:z = x\n  \u00b7 simp [hx]\n\n  by_cases hy:z = y\n  \u00b7 simp [hy]\n\n  rw [Equiv.swap_apply_of_ne_of_ne hx hy, Equiv.swap_apply_of_ne_of_ne (hf.ne hx) (hf.ne hy)]\n#align function.injective.swap_apply Function.Injective.swap_apply\n\ntheorem Function.Injective.swap_comp\n    [DecidableEq \u03b1] [DecidableEq \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : Function.Injective f) (x y : \u03b1) :\n    Equiv.swap (f x) (f y) \u2218 f = f \u2218 Equiv.swap x y :=\n  funext fun _ => hf.swap_apply _ _ _\n#align function.injective.swap_comp Function.Injective.swap_comp\n\n/-- If `\u03b1` is a subsingleton, then it is equivalent to `\u03b1 \u00d7 \u03b1`. -/\ndef subsingletonProdSelfEquiv [Subsingleton \u03b1] : \u03b1 \u00d7 \u03b1 \u2243 \u03b1 where\n  toFun p := p.1\n  invFun a := (a, a)\n  left_inv _ := Subsingleton.elim _ _\n  right_inv _ := Subsingleton.elim _ _\n#align subsingleton_prod_self_equiv subsingletonProdSelfEquiv\n\n/-- To give an equivalence between two subsingleton types, it is sufficient to give any two\n    functions between them. -/\ndef equivOfSubsingletonOfSubsingleton [Subsingleton \u03b1] [Subsingleton \u03b2] (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b1) :\n    \u03b1 \u2243 \u03b2 where\n  toFun := f\n  invFun := g\n  left_inv _ := Subsingleton.elim _ _\n  right_inv _ := Subsingleton.elim _ _\n#align equiv_of_subsingleton_of_subsingleton equivOfSubsingletonOfSubsingleton\n\n/-- A nonempty subsingleton type is (noncomputably) equivalent to `PUnit`. -/\nnoncomputable def Equiv.punitOfNonemptyOfSubsingleton [h : Nonempty \u03b1] [Subsingleton \u03b1] :\n    \u03b1 \u2243 PUnit :=\n  equivOfSubsingletonOfSubsingleton (fun _ => PUnit.unit) fun _ => h.some\n#align equiv.punit_of_nonempty_of_subsingleton Equiv.punitOfNonemptyOfSubsingleton\n\n/-- `Unique (Unique \u03b1)` is equivalent to `Unique \u03b1`. -/\ndef uniqueUniqueEquiv : Unique (Unique \u03b1) \u2243 Unique \u03b1 :=\n  equivOfSubsingletonOfSubsingleton (fun h => h.default) fun h =>\n    { default := h, uniq := fun _ => Subsingleton.elim _ _ }\n#align unique_unique_equiv uniqueUniqueEquiv\n\nnamespace Function\n\ntheorem update_comp_equiv [DecidableEq \u03b1'] [DecidableEq \u03b1] (f : \u03b1 \u2192 \u03b2)\n    (g : \u03b1' \u2243 \u03b1) (a : \u03b1) (v : \u03b2) :\n    update f a v \u2218 g = update (f \u2218 g) (g.symm a) v := by\n  rw [\u2190 update_comp_eq_of_injective _ g.injective, g.apply_symm_apply]\n#align function.update_comp_equiv Function.update_comp_equiv\n\ntheorem update_apply_equiv_apply [DecidableEq \u03b1'] [DecidableEq \u03b1] (f : \u03b1 \u2192 \u03b2)\n    (g : \u03b1' \u2243 \u03b1) (a : \u03b1) (v : \u03b2) (a' : \u03b1') : update f a v (g a') = update (f \u2218 g) (g.symm a) v a' :=\n  congr_fun (update_comp_equiv f g a v) a'\n#align function.update_apply_equiv_apply Function.update_apply_equiv_apply\n\n-- porting note: EmbeddingLike.apply_eq_iff_eq broken here too\ntheorem piCongrLeft'_update [DecidableEq \u03b1] [DecidableEq \u03b2] (P : \u03b1 \u2192 Sort _) (e : \u03b1 \u2243 \u03b2)\n    (f : \u2200 a, P a) (b : \u03b2) (x : P (e.symm b)) :\n    e.piCongrLeft' P (update f (e.symm b) x) = update (e.piCongrLeft' P f) b x := by\n  ext b'\n  rcases eq_or_ne b' b with (rfl | h)\n  \u00b7 simp\n  \u00b7 simp only [Equiv.piCongrLeft'_apply, ne_eq, h, not_false_iff, update_noteq]\n    rw [update_noteq _]\n    rw [ne_eq]\n    intro h'\n    /- an example of something that should work, or also putting `EmbeddingLike.apply_eq_iff_eq`\n      in the `simp` should too:\n    have := (EmbeddingLike.apply_eq_iff_eq e).mp h' -/\n    cases e.symm.injective h' |> h\n\n#align function.Pi_congr_left'_update Function.piCongrLeft'_update\n\ntheorem piCongrLeft'_symm_update [DecidableEq \u03b1] [DecidableEq \u03b2] (P : \u03b1 \u2192 Sort _) (e : \u03b1 \u2243 \u03b2)\n    (f : \u2200 b, P (e.symm b)) (b : \u03b2) (x : P (e.symm b)) :\n    (e.piCongrLeft' P).symm (update f b x) = update ((e.piCongrLeft' P).symm f) (e.symm b) x := by\n  simp [(e.piCongrLeft' P).symm_apply_eq, piCongrLeft'_update]\n#align function.Pi_congr_left'_symm_update Function.piCongrLeft'_symm_update\n\nend Function\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Logic/Equiv/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7027142035519807}}
{"text": "-- Pruebas de la eliminaci\u00f3n de la doble negaci\u00f3n\n-- ==============================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--     \u00ac\u00acP \u22a2 P\n-- ----------------------------------------------------\n\nimport tactic\n\nvariable (P : Prop)\n\nopen_locale classical\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acP)\n  : P :=\nby_contra\n  ( assume h2 : \u00acP,\n    show false,\n      from h1 h2 )\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acP)\n  : P :=\nby_contra\n  ( assume h2 : \u00acP,\n    h1 h2 )\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acP)\n  : P :=\nby_contra (\u03bb h2, h1 h2)\n\n-- 4\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acP)\n  : P :=\n-- by library_search\nnot_not.mp h1\n\n-- 5\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acP)\n  : P :=\nbegin\n  by_contradiction h2,\n  exact h1 h2,\nend\n\n-- 6\u00aa demostraci\u00f3n\nexample\n  (h1 : \u00ac\u00acP)\n  : P :=\n-- by hint\nby tauto\n\n-- 7\u00aa demostraci\u00f3n\nlemma aux\n  (h1 : \u00ac\u00acP)\n  : P :=\nby finish\n\n-- #print axioms aux\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/1_Proposicional/Pruebas_de_la_eliminacion_de_la_doble_negacion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.702714201536098}}
{"text": "/-\nCopyright (c) 2020 Filippo A. E. Nuccio. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Filippo A. E. Nuccio\n-/\nimport algebraic_geometry.prime_spectrum.basic\n/-!\nThis file proves additional properties of the prime spectrum a ring is Noetherian.\n-/\n\nuniverses u v\n\nnamespace prime_spectrum\n\nopen submodule\n\nvariables (R : Type u) [comm_ring R] [is_noetherian_ring R]\nvariables {A : Type u} [comm_ring A] [is_domain A] [is_noetherian_ring A]\n\n/--In a noetherian ring, every ideal contains a product of prime ideals\n([samuel, \u00a7 3.3, Lemma 3])-/\nlemma exists_prime_spectrum_prod_le (I : ideal R) :\n  \u2203 (Z : multiset (prime_spectrum R)), multiset.prod (Z.map (coe : subtype _ \u2192 ideal R)) \u2264 I :=\nbegin\n  refine is_noetherian.induction (\u03bb (M : ideal R) hgt, _) I,\n  by_cases h_prM : M.is_prime,\n  { use {\u27e8M, h_prM\u27e9},\n    rw [multiset.map_singleton, multiset.prod_singleton, subtype.coe_mk],\n    exact le_rfl },\n  by_cases htop : M = \u22a4,\n  { rw htop,\n    exact \u27e80, le_top\u27e9 },\n  have lt_add : \u2200 z \u2209 M, M < M + span R {z},\n  { intros z hz,\n    refine lt_of_le_of_ne le_sup_left (\u03bb m_eq, hz _),\n    rw m_eq,\n    exact ideal.mem_sup_right (mem_span_singleton_self z) },\n  obtain \u27e8x, hx, y, hy, hxy\u27e9 := (ideal.not_is_prime_iff.mp h_prM).resolve_left htop,\n  obtain \u27e8Wx, h_Wx\u27e9 := hgt (M + span R {x}) (lt_add _ hx),\n  obtain \u27e8Wy, h_Wy\u27e9 := hgt (M + span R {y}) (lt_add _ hy),\n  use Wx + Wy,\n  rw [multiset.map_add, multiset.prod_add],\n  apply le_trans (submodule.mul_le_mul h_Wx h_Wy),\n  rw add_mul,\n  apply sup_le (show M * (M + span R {y}) \u2264 M, from ideal.mul_le_right),\n  rw mul_add,\n  apply sup_le (show span R {x} * M \u2264 M, from ideal.mul_le_left),\n  rwa [span_mul_span, set.singleton_mul_singleton, span_singleton_le_iff_mem],\nend\n\n/--In a noetherian integral domain which is not a field, every non-zero ideal contains a non-zero\n  product of prime ideals; in a field, the whole ring is a non-zero ideal containing only 0 as\n  product or prime ideals ([samuel, \u00a7 3.3, Lemma 3]) -/\nlemma exists_prime_spectrum_prod_le_and_ne_bot_of_domain\n  (h_fA : \u00ac is_field A) {I : ideal A} (h_nzI: I \u2260 \u22a5) :\n  \u2203 (Z : multiset (prime_spectrum A)), multiset.prod (Z.map (coe : subtype _ \u2192 ideal A)) \u2264 I \u2227\n    multiset.prod (Z.map (coe : subtype _ \u2192 ideal A)) \u2260 \u22a5 :=\nbegin\n  revert h_nzI,\n  refine is_noetherian.induction (\u03bb (M : ideal A) hgt, _) I,\n  intro h_nzM,\n  have hA_nont : nontrivial A,\n  apply is_domain.to_nontrivial A,\n  by_cases h_topM : M = \u22a4,\n  { rcases h_topM with rfl,\n    obtain \u27e8p_id, h_nzp, h_pp\u27e9 : \u2203 (p : ideal A), p \u2260 \u22a5 \u2227 p.is_prime,\n    { apply ring.not_is_field_iff_exists_prime.mp h_fA },\n    use [({\u27e8p_id, h_pp\u27e9} : multiset (prime_spectrum A)), le_top],\n    rwa [multiset.map_singleton, multiset.prod_singleton, subtype.coe_mk] },\n  by_cases h_prM : M.is_prime,\n  { use ({\u27e8M, h_prM\u27e9} : multiset (prime_spectrum A)),\n    rw [multiset.map_singleton, multiset.prod_singleton, subtype.coe_mk],\n    exact \u27e8le_rfl, h_nzM\u27e9 },\n  obtain \u27e8x, hx, y, hy, h_xy\u27e9 := (ideal.not_is_prime_iff.mp h_prM).resolve_left h_topM,\n  have lt_add : \u2200 z \u2209 M, M < M + span A {z},\n  { intros z hz,\n    refine lt_of_le_of_ne le_sup_left (\u03bb m_eq, hz _),\n    rw m_eq,\n    exact mem_sup_right (mem_span_singleton_self z) },\n  obtain \u27e8Wx, h_Wx_le, h_Wx_ne\u27e9 := hgt (M + span A {x}) (lt_add _ hx) (ne_bot_of_gt (lt_add _ hx)),\n  obtain \u27e8Wy, h_Wy_le, h_Wx_ne\u27e9 := hgt (M + span A {y}) (lt_add _ hy) (ne_bot_of_gt (lt_add _ hy)),\n  use Wx + Wy,\n  rw [multiset.map_add, multiset.prod_add],\n  refine \u27e8le_trans (submodule.mul_le_mul h_Wx_le h_Wy_le) _, mt ideal.mul_eq_bot.mp _\u27e9,\n  { rw add_mul,\n    apply sup_le (show M * (M + span A {y}) \u2264 M, from ideal.mul_le_right),\n    rw mul_add,\n    apply sup_le (show span A {x} * M \u2264 M, from ideal.mul_le_left),\n    rwa [span_mul_span, set.singleton_mul_singleton, span_singleton_le_iff_mem] },\n  { rintro (hx | hy); contradiction },\nend\n\nend prime_spectrum\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebraic_geometry/prime_spectrum/noetherian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7027142003516555}}
{"text": "/-\nCopyright (c) 2020 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\n\nimport group_theory.subgroup.basic\n\n/-!\n# Subgroups generated by an element\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\n## Tags\nsubgroup, subgroups\n\n-/\n\nvariables {G : Type*} [group G]\nvariables {A : Type*} [add_group A]\nvariables {N : Type*} [group N]\n\nnamespace subgroup\n\n/-- The subgroup generated by an element. -/\ndef zpowers (g : G) : subgroup G :=\nsubgroup.copy (zpowers_hom G g).range (set.range ((^) g : \u2124 \u2192 G)) rfl\n\n@[simp] lemma mem_zpowers (g : G) : g \u2208 zpowers g := \u27e81, zpow_one _\u27e9\n\nlemma zpowers_eq_closure (g : G) : zpowers g = closure {g} :=\nby { ext, exact mem_closure_singleton.symm }\n\n@[simp] lemma range_zpowers_hom (g : G) : (zpowers_hom G g).range = zpowers g := rfl\n\nlemma zpowers_subset {a : G} {K : subgroup G} (h : a \u2208 K) : zpowers a \u2264 K :=\n\u03bb x hx, match x, hx with _, \u27e8i, rfl\u27e9 := K.zpow_mem h i end\n\nlemma mem_zpowers_iff {g h : G} :\n  h \u2208 zpowers g \u2194 \u2203 (k : \u2124), g ^ k = h :=\niff.rfl\n\n@[simp] lemma zpow_mem_zpowers (g : G) (k : \u2124) : g^k \u2208 zpowers g :=\nmem_zpowers_iff.mpr \u27e8k, rfl\u27e9\n\n@[simp] lemma npow_mem_zpowers (g : G) (k : \u2115) : g^k \u2208 zpowers g :=\n(zpow_coe_nat g k) \u25b8 zpow_mem_zpowers g k\n\n@[simp] lemma forall_zpowers {x : G} {p : zpowers x \u2192 Prop} :\n  (\u2200 g, p g) \u2194 \u2200 m : \u2124, p \u27e8x ^ m, m, rfl\u27e9 :=\nset.forall_subtype_range_iff\n\n@[simp] lemma exists_zpowers {x : G} {p : zpowers x \u2192 Prop} :\n  (\u2203 g, p g) \u2194 \u2203 m : \u2124, p \u27e8x ^ m, m, rfl\u27e9 :=\nset.exists_subtype_range_iff\n\nlemma forall_mem_zpowers {x : G} {p : G \u2192 Prop} :\n  (\u2200 g \u2208 zpowers x, p g) \u2194 \u2200 m : \u2124, p (x ^ m) :=\nset.forall_range_iff\n\nlemma exists_mem_zpowers {x : G} {p : G \u2192 Prop} :\n  (\u2203 g \u2208 zpowers x, p g) \u2194 \u2203 m : \u2124, p (x ^ m) :=\nset.exists_range_iff\n\ninstance (a : G) : countable (zpowers a) :=\n((zpowers_hom G a).range_restrict_surjective.comp multiplicative.of_add.surjective).countable\n\nend subgroup\n\nnamespace add_subgroup\n\n/-- The subgroup generated by an element. -/\ndef zmultiples (a : A) : add_subgroup A :=\nadd_subgroup.copy (zmultiples_hom A a).range (set.range ((\u2022 a) : \u2124 \u2192 A)) rfl\n\n@[simp] lemma range_zmultiples_hom (a : A) : (zmultiples_hom A a).range = zmultiples a := rfl\n\nattribute [to_additive add_subgroup.zmultiples] subgroup.zpowers\nattribute [to_additive add_subgroup.mem_zmultiples] subgroup.mem_zpowers\nattribute [to_additive add_subgroup.zmultiples_eq_closure] subgroup.zpowers_eq_closure\nattribute [to_additive add_subgroup.range_zmultiples_hom] subgroup.range_zpowers_hom\nattribute [to_additive add_subgroup.zmultiples_subset] subgroup.zpowers_subset\nattribute [to_additive add_subgroup.mem_zmultiples_iff] subgroup.mem_zpowers_iff\nattribute [to_additive add_subgroup.zsmul_mem_zmultiples] subgroup.zpow_mem_zpowers\nattribute [to_additive add_subgroup.nsmul_mem_zmultiples] subgroup.npow_mem_zpowers\nattribute [to_additive add_subgroup.forall_zmultiples] subgroup.forall_zpowers\nattribute [to_additive add_subgroup.forall_mem_zmultiples] subgroup.forall_mem_zpowers\nattribute [to_additive add_subgroup.exists_zmultiples] subgroup.exists_zpowers\nattribute [to_additive add_subgroup.exists_mem_zmultiples] subgroup.exists_mem_zpowers\n\ninstance (a : A) : countable (zmultiples a) :=\n(zmultiples_hom A a).range_restrict_surjective.countable\n\nsection ring\n\nvariables {R : Type*} [ring R] (r : R) (k : \u2124)\n\n@[simp] \n\n@[simp] lemma int_cast_mem_zmultiples_one :\n  \u2191(k : \u2124) \u2208 zmultiples (1 : R) :=\nmem_zmultiples_iff.mp \u27e8k, by simp\u27e9\n\nend ring\n\nend add_subgroup\n\n@[simp, to_additive map_zmultiples] lemma monoid_hom.map_zpowers (f : G \u2192* N) (x : G) :\n  (subgroup.zpowers x).map f = subgroup.zpowers (f x) :=\nby rw [subgroup.zpowers_eq_closure, subgroup.zpowers_eq_closure, f.map_closure, set.image_singleton]\n\nlemma int.mem_zmultiples_iff {a b : \u2124} :\n  b \u2208 add_subgroup.zmultiples a \u2194 a \u2223 b :=\nexists_congr (\u03bb k, by rw [mul_comm, eq_comm, \u2190 smul_eq_mul])\n\nlemma of_mul_image_zpowers_eq_zmultiples_of_mul { x : G } :\n  additive.of_mul '' ((subgroup.zpowers x) : set G) = add_subgroup.zmultiples (additive.of_mul x) :=\nbegin\n  ext y,\n  split,\n  { rintro \u27e8z, \u27e8m, hm\u27e9, hz2\u27e9,\n    use m,\n    simp only,\n    rwa [\u2190 of_mul_zpow, hm] },\n  { rintros \u27e8n, hn\u27e9,\n    refine \u27e8x ^ n, \u27e8n, rfl\u27e9, _\u27e9,\n    rwa of_mul_zpow }\nend\n\nlemma of_add_image_zmultiples_eq_zpowers_of_add {x : A} :\n  multiplicative.of_add '' ((add_subgroup.zmultiples x) : set A) =\n  subgroup.zpowers (multiplicative.of_add x) :=\nbegin\n  symmetry,\n  rw equiv.eq_image_iff_symm_image_eq,\n  exact of_mul_image_zpowers_eq_zmultiples_of_mul,\nend\n\nnamespace subgroup\n\n@[to_additive zmultiples_is_commutative]\ninstance zpowers_is_commutative (g : G) : (zpowers g).is_commutative :=\n\u27e8\u27e8\u03bb \u27e8_, _, h\u2081\u27e9 \u27e8_, _, h\u2082\u27e9, by rw [subtype.ext_iff, coe_mul, coe_mul,\n  subtype.coe_mk, subtype.coe_mk, \u2190h\u2081, \u2190h\u2082, zpow_mul_comm]\u27e9\u27e9\n\n@[simp, to_additive zmultiples_le]\nlemma zpowers_le {g : G} {H : subgroup G} : zpowers g \u2264 H \u2194 g \u2208 H :=\nby rw [zpowers_eq_closure, closure_le, set.singleton_subset_iff, set_like.mem_coe]\n\n@[simp, to_additive zmultiples_eq_bot] lemma zpowers_eq_bot {g : G} : zpowers g = \u22a5 \u2194 g = 1 :=\nby rw [eq_bot_iff, zpowers_le, mem_bot]\n\n@[simp, to_additive zmultiples_zero_eq_bot] lemma zpowers_one_eq_bot :\n   subgroup.zpowers (1 : G) = \u22a5 :=\nsubgroup.zpowers_eq_bot.mpr rfl\n\n@[to_additive] lemma centralizer_closure (S : set G) :\n  (closure S).centralizer = \u2a05 g \u2208 S, (zpowers g).centralizer :=\nle_antisymm (le_infi $ \u03bb g, le_infi $ \u03bb hg, centralizer_le $ zpowers_le.2 $ subset_closure hg)\n  $ le_centralizer_iff.1 $ (closure_le _).2\n  $ \u03bb g, set_like.mem_coe.2 \u2218 zpowers_le.1 \u2218 le_centralizer_iff.1 \u2218 infi_le_of_le g \u2218 infi_le _\n\n@[to_additive] lemma center_eq_infi (S : set G) (hS : closure S = \u22a4) :\n  center G = \u2a05 g \u2208 S, centralizer (zpowers g) :=\nby rw [\u2190centralizer_top, \u2190hS, centralizer_closure]\n\n@[to_additive] lemma center_eq_infi' (S : set G) (hS : closure S = \u22a4) :\n  center G = \u2a05 g : S, centralizer (zpowers g) :=\nby rw [center_eq_infi S hS, \u2190infi_subtype'']\n\nend subgroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/subgroup/zpowers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7027141967669681}}
{"text": "/-\nInterpretation of memory constraints.\n-/\nimport starkware.cairo.lean.semantics.util\n\nnoncomputable theory\n\nopen_locale classical big_operators\n\n/-\nGeneral facts about polyomials\n-/\n\nnamespace polynomial_aux\n\nvariables {F : Type*} [field F] [fintype F]\nvariables {n : Type*} [fintype n] (a b : n \u2192 F)\n\nopen finset polynomial\n\ndef mprod := ((univ.val.map a).map (\u03bb r, X - C r)).prod\n\nlemma nat_degree_mprod : (mprod a).nat_degree = fintype.card n :=\nby { rw [mprod, nat_degree_multiset_prod_X_sub_C (univ.val.map a), multiset.card_map], refl }\n\nlemma eq_of_mprod_eq (h : mprod a = mprod b) : univ.val.map a = univ.val.map b :=\nbegin\n  have : (mprod a).roots = (mprod b).roots := congr_arg _ h,\n  rwa [mprod, mprod, multiset_prod_X_sub_C_roots, multiset_prod_X_sub_C_roots] at this\nend\n\nlemma prod_eq_mprod (z : F) : \u220f i : n, (z - a i) = (mprod a).eval z :=\nby { simp [mprod], refl }\n\ntheorem card_roots_le_or_all_eq [fintype F] :\n  card (univ.filter (\u03bb z : F, \u220f i, (z - a i) = \u220f i, (z - b i))) \u2264 fintype.card n \u2228\n    \u2200 z, \u220f i, (z - a i) = \u220f i, (z - b i) :=\nbegin\n  have h\u2080 : \u2200 z, (\u220f i, (z - a i)) - (\u220f i, (z - b i)) = (mprod a - mprod b).eval z,\n  { intro z, simp [mprod], refl },\n  by_cases h : mprod a - mprod b = 0,\n  { right, intro z, rw [\u2190sub_eq_zero, h\u2080, h, eval_zero] },\n  have : univ.filter (\u03bb z : F, \u220f i, (z - a i) = \u220f i, (z - b i)) =\n          (mprod a - mprod b).roots.to_finset,\n  { ext z; simp [mem_roots h], rw [\u2190sub_eq_zero, h\u2080, eval_sub] },\n  left, rw this,\n  apply (multiset.to_finset_card_le _).trans,\n  apply (card_roots' _).trans,\n  apply (nat_degree_add (mprod a) _).trans,\n  rw [nat_degree_neg, nat_degree_mprod, nat_degree_mprod, max_self]\nend\n\ndef exceptional_set : finset F :=\nif \u2200 z, \u220f i, (z - a i) = \u220f i, (z - b i) then \u2205 else\n  univ.filter (\u03bb z : F, \u220f i : n, (z - a i) = \u220f i, (z - b i))\n\n@[simp] theorem exception_set_eq_pos (h : \u2200 z, \u220f i, (z - a i) = \u220f i, (z - b i)) :\n  exceptional_set a b = \u2205 :=\nby rw [exceptional_set, if_pos h]\n\n@[simp] theorem exception_set_eq_neg (h : \u00ac \u2200 z, \u220f i, (z - a i) = \u220f i, (z - b i)) :\n  exceptional_set a b = univ.filter (\u03bb z : F, \u220f i : n, (z - a i) = \u220f i, (z - b i)) :=\nby rw [exceptional_set, if_neg h]\n\ntheorem card_exceptional_set_le : card (exceptional_set a b) \u2264 fintype.card n :=\nbegin\n  by_cases h : (\u2200 z, \u220f i, (z - a i) = \u220f i, (z - b i)); simp [h],\n  exact (card_roots_le_or_all_eq a b).resolve_right h\nend\n\ntheorem all_eq_of_not_mem_exceptional_set {z : F}\n    (h\u2081 : z \u2209 exceptional_set a b)\n    (h\u2082 : \u220f i : n, (z - a i) = \u220f i, (z - b i)) :\n  \u2200 z, \u220f i, (z - a i) = \u220f i, (z - b i) :=\nbegin\n  by_contradiction h,\n  simp [exceptional_set, if_neg h] at h\u2081,\n  contradiction\nend\n\nend polynomial_aux\n\nsection\n\nvariables {F : Type*} [field F] {n : \u2115} (a b : fin n \u2192 F)\n\ntheorem prod_sub_eq_zero_iff (z : F) :\n  \u220f i : fin n, (z - a i) = 0 \u2194 \u2203 j : fin n, z = a j :=\nbegin\n  induction n with n ih,\n  { simp },\n  rw [fin.prod_univ_cast_succ, mul_eq_zero, ih, fin.exists_fin_cast_succ],\n  simp only [sub_eq_zero]\nend\n\nvariable [fintype F]\n\ntheorem exceptional_set_spec {z : F}\n    (h\u2081 : z \u2209 polynomial_aux.exceptional_set a b)\n    (h\u2082 : \u220f i : fin n, (z - a i) = \u220f i, (z - b i)) :\n  \u2200 i, \u2203 j, a i = b j :=\nbegin\n  intro i,\n  have : \u220f i' : fin n, (a i - a i') = 0,\n  { rw prod_sub_eq_zero_iff, use i },\n  rw polynomial_aux.all_eq_of_not_mem_exceptional_set a b h\u2081 h\u2082 at this,\n  rwa \u2190prod_sub_eq_zero_iff\nend\n\ntheorem exceptional_set_spec' {z : F}\n    (h\u2081 : z \u2209 polynomial_aux.exceptional_set a b)\n    (h\u2082 : \u220f i : fin n, (z - a i) = \u220f i, (z - b i)) :\n  \u2200 i, \u2203 j, b i = a j :=\nbegin\n  intro i,\n  have : \u220f i' : fin n, (b i - b i') = 0,\n  { rw prod_sub_eq_zero_iff, use i },\n  rw \u2190polynomial_aux.all_eq_of_not_mem_exceptional_set a b h\u2081 h\u2082 at this,\n  rwa \u2190prod_sub_eq_zero_iff\nend\n\nend\n\n/-\nThe constraints.\n\nNote: where the whitepaper assumes `n > 0`, we use `n + 1` instead.\n-/\n\nsection constraints\n\nvariables {F : Type*} [field F]\n\nvariables {n : \u2115} {a v a' v' p : fin (n + 1) \u2192 F}\n\nvariables {alpha z : F}\n\nvariable h_continuity :\n  \u2200 i : fin n, (a' i.succ - a' i.cast_succ) * (a' i.succ - a' i.cast_succ - 1) = 0\n\nvariable h_single_valued :\n  \u2200 i : fin n, (v' i.succ - v' i.cast_succ) * (a' i.succ - a' i.cast_succ - 1) = 0\n\nvariable h_initial : (z - (a' 0 + alpha * v' 0)) * p 0 = z - (a 0 + alpha * v 0)\n\nvariable h_cumulative : \u2200 i : fin n, (z - (a' i.succ + alpha * v' i.succ)) * p i.succ =\n                                       (z - (a i.succ + alpha * v i.succ)) * p i.cast_succ\n\nvariable h_final : p (fin.last n) = 1\n\n/-\nSee also `hprob\u2081`, `hprob\u2082`, and `char_lt` below.\n-/\n\ndef a'_step (a' : fin (n + 1) \u2192 F) (i : fin n) : \u2115 :=\nif a' i.succ = a' i.cast_succ then 0 else 1\n\nlemma a'_step_of_eq (i : fin n) (h : a' i.succ = a' i.cast_succ) :\n  a'_step a' i = 0 :=\nby rw [a'_step, if_pos h]\n\nlemma a'_step_of_eq_add_one (i : fin n) (h : a' i.succ = a' i.cast_succ + 1) :\n  a'_step a' i = 1 :=\nby rw [a'_step, if_neg]; simp [h]\n\ndef a'_nat_offset (a' : fin (n + 1) \u2192 F) (i : fin (n + 1)) : \u2115 :=\n\u2211 j in fin.range i, (a'_step a') j\n\n@[simp] lemma a'_nat_offset_zero : a'_nat_offset a' 0 = 0 := fin.sum_range_zero _\n\n@[simp] lemma a'_nat_offset_succ (i : fin n) :\n  a'_nat_offset a' i.succ = a'_nat_offset a' i.cast_succ + a'_step a' i :=\nby rw [a'_nat_offset, fin.sum_range_succ _ _, add_comm]; refl\n\nlemma monotone_a'_nat_offset : monotone (a'_nat_offset a') :=\nby { intros i j ilej, apply finset.sum_mono_set, apply fin.range_subset.mpr ilej }\n\nlemma a'_nat_offset_le (i : fin (n + 1)) : a'_nat_offset a' i \u2264 \u2191i :=\nbegin\n  apply fin.induction_on i; simp,\n  intros i' ih,\n  apply add_le_add ih _,\n  by_cases h : a' i'.succ = a' i'.cast_succ; simp [a'_step, h]\nend\n\nlemma a'_nat_offset_le' (i : fin (n + 1)) : a'_nat_offset a' i \u2264 n :=\nle_trans (monotone_a'_nat_offset (fin.le_last i)) (a'_nat_offset_le _)\n\nsection h_continuity\ninclude h_continuity\n\nlemma a'_succ_eq (i : fin n) : a' i.succ = a' i.cast_succ \u2228 a' i.succ = a' i.cast_succ + 1 :=\nbegin\n  cases (eq_zero_or_eq_zero_of_mul_eq_zero $ h_continuity i) with h h,\n  { left, apply eq_of_sub_eq_zero h },\n  right, apply eq_of_sub_eq_zero, rw \u2190h, abel\nend\n\nlemma a'_succ_eq' (i : fin n) : a' i.succ = a' i.cast_succ + a'_step a' i :=\nbegin\n  cases (a'_succ_eq h_continuity i) with h h,\n  { simp [a'_step_of_eq _ h, h] },\n  simp [a'_step_of_eq_add_one _ h, h]\nend\n\nlemma a'_nat_offset_spec (i : fin (n + 1)) : a' i = a' 0 + a'_nat_offset a' i :=\nbegin\n  apply fin.induction_on i; simp [a'_succ_eq' h_continuity],\n  intros i' ih, rw [ih, add_assoc]\nend\n\nlemma nat_offset_eq (h_n_lt : n < ring_char F) {i j : fin (n + 1)} (h : a' i = a' j) :\n  a'_nat_offset a' i = a'_nat_offset a' j :=\nbegin\n  have : \u2191i < ring_char F := lt_of_le_of_lt (nat.le_of_lt_succ i.property) h_n_lt,\n  have : \u2191j < ring_char F := lt_of_le_of_lt (nat.le_of_lt_succ j.property) h_n_lt,\n  rw [a'_nat_offset_spec h_continuity i, a'_nat_offset_spec h_continuity j] at h,\n  apply nat.cast_inj_of_lt_char _ _ (add_left_cancel h);\n  { apply lt_of_le_of_lt (a'_nat_offset_le _), assumption }\nend\n\nlemma a'_continuous_aux (i : fin (n + 1)) :\n  \u2200 k \u2264 a'_nat_offset a' i, \u2203 j \u2264 i, a'_nat_offset a' j = k :=\nbegin\n  apply fin.induction_on i; simp,\n  { use [0, le_refl _], simp },\n  intros i' ih k,\n  cases (a'_succ_eq h_continuity i') with h h,\n  { simp [a'_step_of_eq _ h, h],\n    intro hk,\n    rcases ih k hk with \u27e8j, hj, hj'\u27e9,\n    exact \u27e8j, le_trans hj (le_of_lt (fin.cast_succ_lt_succ _)), hj'\u27e9 },\n   simp [a'_step_of_eq_add_one _ h, h],\n   intro hk,\n   cases (nat.of_le_succ hk) with hk' hk',\n   { rcases ih k hk' with \u27e8j, hj, hj'\u27e9,\n     exact\u27e8j, le_trans hj (le_of_lt (fin.cast_succ_lt_succ _)), hj'\u27e9 },\n   refine \u27e8i'.succ, le_refl _, _\u27e9,\n  rw [hk', a'_nat_offset_succ, a'_step_of_eq_add_one _ h]\nend\n\nlemma a'_continuous (k : \u2115) (hk : k \u2264 a'_nat_offset a' (fin.last n)) :\n  \u2203 j, a'_nat_offset a' j = k :=\nbegin\n  rcases a'_continuous_aux h_continuity _ _ hk with \u27e8j, _, hj\u27e9,\n  exact \u27e8j, hj\u27e9\nend\n\nsection single_valued\ninclude h_single_valued\n\nlemma a'_single_valued_aux {i : fin n} (h : a' i.succ = a' i.cast_succ) :\n  v' i.succ = v' i.cast_succ :=\nbegin\n  have := h_single_valued i,\n  simp [h] at this,\n  symmetry,\n  exact eq_of_sub_eq_zero this\nend\n\nlemma a'_single_valued_aux' (h_n_lt : n < ring_char F) (i : fin (n + 1)) :\n  \u2200 j < i, a' i = a' j \u2192 v' i = v' j :=\nbegin\n  apply i.induction_on,\n  { intros j hj, exfalso, apply fin.not_lt_zero _ hj },\n  intros i' ih j hj a'eq,\n  have hj' : j \u2264 i'.cast_succ := fin.le_of_lt_succ hj,\n  have a'eq2 : a' i'.succ = a' i'.cast_succ,\n  { rw [a'eq, a'_nat_offset_spec h_continuity, a'_nat_offset_spec h_continuity i'.cast_succ],\n    congr' 2, apply le_antisymm (monotone_a'_nat_offset $ fin.le_of_lt_succ hj),\n    rw \u2190nat_offset_eq h_continuity h_n_lt a'eq,\n    apply monotone_a'_nat_offset (le_of_lt $ fin.cast_succ_lt_succ _) },\n  rw [a'_single_valued_aux h_continuity h_single_valued a'eq2],\n  cases (lt_or_eq_of_le hj') with h h,\n  { exact ih j h (a'eq2.symm.trans a'eq) },\n  rw h\nend\n\nlemma a'_single_valued (h_n_lt : n < ring_char F) {i j : fin (n + 1)} :\n  a' i = a' j \u2192 v' i = v' j :=\nbegin\n  have : i < j \u2228 i = j \u2228 j < i := trichotomous i j,\n  rcases this with h | rfl | h,\n  { intro h', symmetry,\n    exact a'_single_valued_aux' h_continuity h_single_valued h_n_lt _ _ h h'.symm },\n  { intro _, refl },\n  exact a'_single_valued_aux' h_continuity h_single_valued h_n_lt _ _ h\nend\n\nend single_valued\n\nend h_continuity\n\nsection\n\nvariable [fintype F]\n\ndef bad_set_1 (a v a' v' : fin (n + 1) \u2192 F) : finset F :=\nfinset.univ.filter (\u03bb alpha, \u2203 i j, v i \u2260 v' j \u2227 a i + alpha * v i = a' j + alpha * v' j)\n\n@[simp] theorem mem_bad_set_1 {a v a' v' : fin (n + 1) \u2192 F} (alpha : F) :\n  alpha \u2208 bad_set_1 a v a' v' \u2194 \u2203 i j, v i \u2260 v' j \u2227 a i + alpha * v i = a' j + alpha * v' j :=\nby { rw [bad_set_1, finset.mem_filter], simp }\n\ntheorem card_bad_set_1_le  : (bad_set_1 a v a' v').card \u2264 (n + 1) * (n + 1) :=\nlet f := \u03bb p : fin (n + 1) \u00d7 fin (n + 1), (a p.1 - a' p.2) / (v' p.2 - v p.1) in\ncalc\n    (bad_set_1 a v a' v').card \u2264 (finset.image f finset.univ).card :\n      begin\n        apply finset.card_le_of_subset,\n        intros alpha,\n        simp,\n        intros i j hv ha,\n        use [i, j], dsimp [f],\n        have : v' j - v i \u2260 0,\n        { intro h, apply hv, symmetry, apply eq_of_sub_eq_zero h },\n        rw [div_eq_iff this, mul_sub, sub_eq_iff_eq_add, sub_add_eq_add_sub, add_comm, \u2190ha,\n             add_sub_cancel]\n      end\n    ... \u2264 (finset.univ : finset (fin (n + 1) \u00d7 fin (n + 1))).card : finset.card_image_le\n    ... = fintype.card (fin (n + 1) \u00d7 fin (n + 1))                : rfl\n    ... = (n + 1) * (n + 1)                                       : by simp\n\ntheorem bad_set_1_spec (h : alpha \u2209 bad_set_1 a v a' v') {i j : fin (n + 1)}\n    (h' : a i + alpha * v i = a' j + alpha * v' j) :\n  v i = v' j \u2227 a i = a' j :=\nbegin\n  simp at h,\n  specialize h i j,\n  have : v i = v' j := by_contradiction (\u03bb h\u2080, h h\u2080 h'),\n  split, { exact this },\n  rw this at h',\n  exact add_right_cancel h'\nend\n\ndef bad_set_2 (a v a' v' : fin (n + 1) \u2192 F) (alpha : F) : finset F :=\npolynomial_aux.exceptional_set (\u03bb i, a i + alpha * v i) (\u03bb i, a' i + alpha * v' i)\n\ntheorem card_bad_set_2_le : (bad_set_2 a v a' v' alpha).card \u2264 n + 1 :=\nby { transitivity, apply polynomial_aux.card_exceptional_set_le, simp }\n\ntheorem bad_set_2_spec {z : F}\n    (h\u2081 : z \u2209 bad_set_2 a v a' v' alpha)\n    (h\u2082 : \u220f i : fin (n + 1), (z - (a i + alpha * v i)) = \u220f i, (z - (a' i + alpha * v' i))) :\n  \u2200 i, \u2203 j, a i + alpha * v i = a' j + alpha * v' j :=\nexceptional_set_spec _ _ h\u2081 h\u2082\n\ntheorem bad_set_2_spec' {z : F}\n    (h\u2081 : z \u2209 bad_set_2 a v a' v' alpha)\n    (h\u2082 : \u220f i : fin (n + 1), (z - (a i + alpha * v i)) = \u220f i, (z - (a' i + alpha * v' i))) :\n  \u2200 i, \u2203 j, a' i + alpha * v' i = a j + alpha * v j :=\nexceptional_set_spec' _ _ h\u2081 h\u2082\n\nend\n\nsection permutation\n\ninclude h_initial h_cumulative\n\nlemma permutation_aux (j : fin (n + 1)) :\n  \u220f i in fin.range j.succ, (z - (a i + alpha * v i)) =\n    (\u220f i in fin.range j.succ, (z - (a' i + alpha * v' i))) * p j :=\nbegin\n  apply fin.induction_on j,\n  { rw [\u2190fin.one_eq_succ_zero, fin.prod_range_one, fin.prod_range_one, h_initial] },\n  intros j ih,\n  rw [fin.prod_range_succ, fin.prod_range_succ, \u2190fin.succ_cast_succ, ih, \u2190mul_assoc],\n  conv { to_rhs, rw [mul_right_comm, h_cumulative, mul_right_comm] }\nend\n\ninclude h_final\n\nlemma permutation_prod_eq :\n  \u220f i, (z - (a i + alpha * v i)) = \u220f i, (z - (a' i + alpha * v' i)) :=\nby rw [\u2190fin.range_last, \u2190fin.succ_last, permutation_aux h_initial h_cumulative,\n    h_final, mul_one]\n\nend permutation\n\n/-\nPut it all together!\n-/\n\nvariable [fintype F]\nvariable hprob\u2081 : alpha \u2209 bad_set_1 a v a' v'\nvariable hprob\u2082 : z \u2209 bad_set_2 a v a' v' alpha\n\ninclude hprob\u2081 hprob\u2082\n\nlemma permutation (h : \u220f (i : fin (n + 1)), (z - (a i + alpha * v i)) =\n                         \u220f (i : fin (n + 1)), (z - (a' i + alpha * v' i))) :\n  \u2200 i, \u2203 j, v i = v' j \u2227 a i = a' j :=\nbegin\n  intro i,\n  have : \u2203 j, a i + alpha * v i = a' j + alpha * v' j := bad_set_2_spec hprob\u2082 h i,\n  cases this with j hj,\n  use j,\n  show v i = v' j \u2227 a i = a' j,\n    from bad_set_1_spec hprob\u2081 hj\nend\n\nlemma permutation'  (h : \u220f (i : fin (n + 1)), (z - (a i + alpha * v i)) =\n                         \u220f (i : fin (n + 1)), (z - (a' i + alpha * v' i))) :\n  \u2200 i, \u2203 j, v' i = v j \u2227 a' i = a j :=\nbegin\n  intro i,\n  have := bad_set_2_spec' hprob\u2082 h i,\n  cases this with j hj,\n  have := bad_set_1_spec hprob\u2081 hj.symm,\n  use j, simp [this]\nend\n\ninclude h_continuity h_initial h_cumulative h_final\n\nlemma a_continuous : \u2203 base : F, \u2203 m : \u2115,\n    (\u2200 i, \u2203 k \u2264 m, a i = base + k) \u2227 (\u2200 k \u2264 m, \u2203 i, a i = base + k) :=\nbegin\n  have h : \u220f (i : fin (n + 1)), (z - (a i + alpha * v i)) =\n             \u220f (i : fin (n + 1)), (z - (a' i + alpha * v' i)) :=\n    permutation_prod_eq h_initial h_cumulative h_final,\n  have perm := permutation hprob\u2081 hprob\u2082 h,\n  use a' 0,\n  use a'_nat_offset a' (fin.last n),\n  split,\n  { intro i,\n    rcases perm i with \u27e8j, veq, aeq\u27e9,\n    use a'_nat_offset a' j,\n    split,\n    { apply monotone_a'_nat_offset, apply fin.le_last },\n    rw aeq,\n    exact a'_nat_offset_spec h_continuity j },\n  have perm' := permutation' hprob\u2081 hprob\u2082 h,\n  intros k kle,\n  rcases a'_continuous h_continuity k kle with \u27e8j, hj\u27e9,\n  rcases perm' j with \u27e8i, v'eq, a'eq\u27e9,\n  use i,\n  rw [\u2190a'eq, \u2190hj],\n  exact a'_nat_offset_spec h_continuity j\nend\n\ninclude h_single_valued\n\nlemma a_single_valued (h_char_lt : n < ring_char F) : \u2200 i i', a i = a i' \u2192 v i = v i' :=\nbegin\n  intros i i' aieq,\n  have h : \u220f (i : fin (n + 1)), (z - (a i + alpha * v i)) =\n             \u220f (i : fin (n + 1)), (z - (a' i + alpha * v' i)) :=\n    permutation_prod_eq h_initial h_cumulative h_final,\n  have perm := permutation hprob\u2081 hprob\u2082 h,\n  rcases perm i with \u27e8j, veq, aeq\u27e9,\n  rcases perm i' with \u27e8j', veq', aeq'\u27e9,\n  rw [veq, veq'],\n  apply a'_single_valued h_continuity h_single_valued h_char_lt,\n  rw [\u2190aeq, \u2190aeq', aieq]\nend\n\nend constraints\n\n-- #lint\n", "meta": {"author": "starkware-libs", "repo": "formal-proofs", "sha": "35613c65b6715601bbc0a550d52754f8e7d93e30", "save_path": "github-repos/lean/starkware-libs-formal-proofs", "path": "github-repos/lean/starkware-libs-formal-proofs/formal-proofs-35613c65b6715601bbc0a550d52754f8e7d93e30/src/starkware/cairo/lean/semantics/air_encoding/memory_aux.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7026905602610979}}
{"text": "import Architectural.LACU\n\ninductive LANG\n| T : LANG\n| atom : PORTS \u2192 LANG \n| lt : PORTS \u2192 PORTS \u2192 LANG \n| neg : LANG \u2192 LANG \n| conj : LANG \u2192 LANG \u2192 LANG\n| disj : LANG \u2192 LANG \u2192 LANG\n| always : LANG \u2192 LANG \n\nnamespace LANG \n\ninstance : has_top LANG := \u27e8LANG.T\u27e9 \n\n@[simp]\ndef sem : LANG \u2192 set (Trace (PORTS))\n| (LANG.atom x) := { \u03c3 | (\u03c3 0) x \u2260 0 }\n| (LANG.lt x v) := {\u03c3  |  (\u03c3 0) x < (\u03c3 0) v}\n| (LANG.neg A) := (set.univ) \\ (sem A)\n| (LANG.conj A B) := (sem A) \u2229 (sem B)\n| (LANG.disj A B) := (sem A) \u222a (sem B)\n| (LANG.always A) := {\u03c3 | \u2200 i, (\u03c3.drop i) \u2208 (sem A)}\n| T := set.univ \n\n@[simp]\ndef compl_def : \u2200 A : LANG, (sem (neg A)) = (set.univ) \\ (sem A) := \u03bb A, rfl \n@[simp]\ndef conj_def : \u2200 A B : LANG,   (sem (conj A B)) =  (sem A) \u2229 (sem B) := \u03bb A B, rfl  \n\n@[simp]\ndef disj_def : \u2200 A B : LANG,   (sem (disj A B)) =  (sem A) \u222a (sem B) := \u03bb A B , rfl  \n\n@[simp] theorem disj_comm :  \u2200 A B : LANG,  (sem (disj A B)) = sem (disj B A) := \nbegin\n  intros, rw sem, rw sem, rw set.union_comm, \nend \n\n@[simp]\ndef always_def : \u2200 A : LANG, sem (A.always) =  {\u03c3 | \u2200 i, (\u03c3.drop i) \u2208 (sem A)} := \u03bb A, rfl  \n\n@[reducible,simp]\ndef sub (x y : PORTS) : LANG \u2192 LANG\n| (LANG.atom a) := if a = x then LANG.atom y else LANG.atom a\n| (LANG.lt a v) := if a = x then LANG.lt y v else LANG.lt a v\n| (LANG.neg A) := LANG.neg (sub A)\n| (LANG.conj A B) := LANG.conj (sub A) (sub B)\n| (LANG.disj A B) :=  LANG.disj (sub A) (sub B)\n| (LANG.always A) :=  (LANG.always (sub A))\n| T := \u22a4\n\n\nend LANG \n\n\ninstance : AssertionLang LANG PORTS := \n{ sem := LANG.sem,\n  T_def := by {unfold has_top.top, rw LANG.sem,},\n  compl := LANG.neg,\n  conj := LANG.conj,\n  disj := LANG.disj,\n  compl_def := LANG.compl_def,\n  conj_def := LANG.conj_def,\n  disj_def := LANG.disj_def, }\n\n\naxiom synchronize {\u03c6 : LANG} {\u03c3 : Trace PORTS} : \u2200 v1 v2 : PORTS, \n(v1,v2) \u2208 LACU_ARCH_MODEL.delegation \u2228 (v2,v1) \u2208 LACU_ARCH_MODEL.delegation \u2192 \n\u03c3 \u2208 (@AssertionLang.sem LANG PORTS _ _ _ \u03c6) \u2194 \n\u03c3 \u2208 (@AssertionLang.sem LANG PORTS _ _ _ (\u03c6.sub v1 v2))\n\n\ntheorem forall_conj_distrib : \u2200 A B : LANG,   \n(@AssertionLang.sem LANG PORTS _ _ _  (LANG.conj A B).always) = (@AssertionLang.sem LANG PORTS _ _ _  ((A.always).conj (B.always))) :=\nbegin \n  intros, unfold AssertionLang.sem, simp, rw set.inter_def, simp,\n  ext, simp,\n  rw forall_and_distrib,\nend\n\ntheorem forall_conj_distrib_mem {x : Trace PORTS} : \u2200 A B : LANG, x \u2208 \n(@AssertionLang.sem LANG PORTS _ _ _ (LANG.conj A B).always) \u2194 x \u2208 (@AssertionLang.sem LANG PORTS _ _ _  ((A.always).conj (B.always))) :=\nbegin \n  intros, unfold AssertionLang.sem, split, simp, rintros a, split,\n   intro i, apply (a i).1, intro i, apply (a i).2,\n   simp, intros a b i, split, apply a i, apply b i,\nend\n\n\ntheorem forall_conj_distrib' : \u2200 A B : LANG,   \n(LANG.sem  (LANG.conj A B).always) = (LANG.sem ((A.always).conj (B.always))) :=\nbegin \n  intros, simp, rw set.inter_def, simp,\n  ext, simp,\n  rw forall_and_distrib,\nend\n\ntheorem forall_conj_distrib_mem' {x : Trace PORTS} : \u2200 A B : LANG, x \u2208 \n(LANG.sem (LANG.conj A B).always) \u2194 x \u2208 (LANG.sem ((A.always).conj (B.always))) :=\nbegin \n  intros, split, simp, rintros a, split,\n   intro i, apply (a i).1, intro i, apply (a i).2,\n   simp, intros a b i, split, apply a i, apply b i,\nend", "meta": {"author": "loganrjmurphy", "repo": "ForeMoSt", "sha": "c7affc7c8971562520d2775ac48fe4f188f84b02", "save_path": "github-repos/lean/loganrjmurphy-ForeMoSt", "path": "github-repos/lean/loganrjmurphy-ForeMoSt/ForeMoSt-c7affc7c8971562520d2775ac48fe4f188f84b02/src/Architectural/lang.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.7026905487815722}}
{"text": "/- \nCopyright (c) 2018 Blair Shi. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Kevin Buzzard, Blair Shi\n\nThis file is followed Linear Algebra Done Right and inspired by Johannes H\u00f6lzl's \nimplementation of linear algebra in mathlib.\n\nThe thing we improved is this file describes finite dimentional vector spaces\n-/\n\nimport algebra.module -- for definition of vector_space  \nimport linear_algebra.basic -- for definition of is_basis \nimport data.list.basic\nimport analysis.real\nuniverses u v \n\nclass finite_dimensional_vector_space (k : Type u) (V : Type v) [field k] \n  extends vector_space k V :=\n(ordered_basis : list V)\n(is_ordered_basis : is_basis {v : V | v \u2208 ordered_basis})\n\n\nvariables {k : Type u} {V : Type v}\nvariable [field k]\nvariable [module k V]\nvariables {a : k} {b : V}\ninclude k \n\ndefinition f_dimention\n(k : Type u) (V : Type v) [field k] (fvs : finite_dimensional_vector_space k V) : \u2115 :=\nfvs.ordered_basis.length\n\ndef f_span (l : list V) : set V :=\nspan {vc : V | vc \u2208 l}\n \ndef f_linear_independent (l : list V) : Prop := \nlinear_independent {vc : V | vc \u2208 l}\n\n-- helper function to check whether two basis are equal\ndef are_span_the_same (l\u2080 : list V) (l\u2081 : list V) : Prop := \n\u2200vc : V, vc \u2208 (f_span l\u2080) \u2227 vc \u2208 (f_span l\u2081) \n\ndef is_basis_of_vecsp (l : list V) (fvs : finite_dimensional_vector_space k V) : Prop := \n(f_span l = f_span fvs.ordered_basis) \u2227 (f_linear_independent l)\n\ndef is_in_vecsp (v : V) (fvs : finite_dimensional_vector_space k V) : Prop :=\nv \u2208 span {v\u2081 : V | v\u2081 \u2208 fvs.ordered_basis}\n\nsection basic_property\nvariables (x y : V)\nvariable (fvs : finite_dimensional_vector_space k V)\n\nend basic_property\n\nsection span_liid\nvariables (v\u2080 v\u2081 v\u2082 vc: V)\nvariables (l\u2080 l\u2081: list V)\nvariables (h\u2080 h\u2081 res\u2080 res\u2081 : Prop)\nvariable (fvs : finite_dimensional_vector_space k V)\n\n-- 2.4\ntheorem linear_dependence_th (l : list V)\n  (h\u2080 : \u00ac (f_linear_independent l)) \n  (h\u2081 : (vc \u2208 l) \u2227 (vc \u2260 (0:V))) \n  : \u2203 v\u2080, (v\u2080 \u2208 l) \u2227 (v\u2080 \u2260 vc) \u2227 (v\u2080 \u2208 span {vr : V | vr \u2208 l \u2227 vr \u2260 v\u2080}) \n  \u2227 (span {vr : V | vr \u2208 l \u2227 vr \u2260 v\u2080} = f_span l) :=\n  sorry\n  -- begin\n  --   apply exists.intro,\n  --   split,\n  --   intro v\u2080,\n  --   assume h\u2082 : v\u2080 \u2208 l \u2227 v\u2080 \u2260 vc,    \n    \n\n    \n  --   -- \u27e8finsupp.single v\u2080 1, by simp [finsupp.sum_single_index, this] {contextual := tt}\u27e9\n  --   sorry\n    \n  -- end\n  \n  \n  \n\n-- 2.5 In a finite-dimensional vector space, the length of \n-- every linearly independent list of vectors is less \n-- than or equal to the length of every spanning list of vectors.\ntheorem len_of_lide_le_dimention (fvs : finite_dimensional_vector_space k V) (l : list V) \n  (h\u2080 : f_linear_independent l \u2227 f_span l \u2286 f_span fvs.ordered_basis)\n  (h\u2081 : f_span l\u2080 = f_span fvs.ordered_basis)\n  : l.length <= l\u2080.length := \n  -- begin\n  sorry\n  -- end\n\n-- 2.8\ntheorem is_f_basis (l : list V) (fvs : finite_dimensional_vector_space k V):\n  (\u2200 v\u2080, (is_in_vecsp v\u2080 fvs) \u2227  (v\u2080 \u2208 f_span l)) \u2194 (is_basis_of_vecsp l fvs) := \n  sorry\n  -- begin\n  -- apply iff.intro,\n  -- -- A -> B\n  -- intro h,\n  -- split,\n  \n\n  -- -- B -> A\n\n\n\n  -- end \n\n-- 2.10 Every spanning list in a vector space can be reduced to a basis of the vector space.\ntheorem span_set_can_be_basis (fvs : finite_dimensional_vector_space k V) : \n  \u2200l\u2080, (f_span l\u2080  = f_span fvs.ordered_basis) \u2192 \u2203l\u2081 \u2286 l\u2080, is_basis_of_vecsp l\u2081 fvs := sorry\n\n-- 2.12 Every linearly independent list of vectors in a finite-dimensional vector space \n-- can be extended to a basis of the vector space.\ntheorem liide_list_can_be_basis (fvs : finite_dimensional_vector_space k V) :\n  \u2200l\u2080, linear_independent {vc : V | vc \u2208 l\u2080} \u2192 \u2203l\u2081, is_basis_of_vecsp (l\u2080 ++ l\u2081) fvs := \n  begin\n  sorry\n  end\n\n-- Any two bases of a finite-dimensional vector space have the same length.\ntheorem any_basis_have_len:\n  \u2200l\u2080 l\u2081, (is_basis_of_vecsp l\u2080 fvs) \u2227 (is_basis_of_vecsp l\u2081 fvs) \u2192\n   (l\u2080.length = l\u2081.length) := sorry \n\n-- If V is finite dimensional, then every spanning list of vectors in V with length dim V is a basis of V.\ntheorem span_with_dim_is_basis:\n  \u2200l\u2080 , (are_span_the_same l\u2080 fvs.ordered_basis \u2227 l\u2080.length = f_dimention k V fvs) \n  \u2192 is_basis_of_vecsp l\u2080 fvs := sorry\n\ntheorem liide_list_with_dim_is_basis:\n  \u2200(l\u2080 : list V) , (f_linear_independent l\u2080 \u2227 l\u2080.length = f_dimention k V fvs) \n  \u2192 is_basis_of_vecsp l\u2080 fvs := sorry \n\n\n\nend span_liid\n\n-- define subspace \n\n-- theorem: If V is finite dimensional and U is a subspace of V, then dimU \u2264 dimV.\n\n-- Proposition: Suppose V is finite dimensional and U is a subspace of V.\n-- Then there is a subspace W of V such that V = U \u2295 W.\n\n-- Theorem: If U1 and U2 are subspaces of a finite-dimensional vector space, then\n-- dim(U1 +U2)=dimU1 +dimU2 \u2212dim(U1 \u2229U2).\n\n-- 2.19 Proposition: Suppose V is finite dimensional and U1 , . . . , Um are subspaces of V such that\n-- 2.20 V=U1+\u00b7\u00b7\u00b7+Um\n-- 2.21 dimV =dimU1 +\u00b7\u00b7\u00b7+dimUm. Then V = U1 \u2295 \u00b7 \u00b7 \u00b7 \u2295 Um.\n\n-- define linear map \n\n\n-- \u2200l : lc \u03b1 \u03b2, (\u2200x\u2209s, l x = 0) \u2192 l.sum (\u03bbv c, c \u2022 v) = 0 \u2192 l = 0\n-- variable \u03b1 : Type\n-- variable i : \u03b1 \n-- theorem not_for_all (p q: \u03b1 \u2192 Prop) (h : \u00ac (\u2200x : \u03b1, p x \u2192 q x)) : \n-- \u2203x : \u03b1, p x \u2227 \u00ac (q x) :=\n-- begin\n-- apply exists.intro,\n-- split,\n-- apply exists.elim ((p i) \u2228 \u00ac (p i)) \n-- end\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/finite_dimensional_vector_spaces/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7026858437938736}}
{"text": "section  -- Propositions and Proofs\n  variables p q r s : Prop\n\n  -- commutativity of \u2227 and \u2228\n  example : p \u2227 q \u2194 q \u2227 p :=\n  begin\n    split;\n    intro h;\n    cases h with hl hr;\n    exact and.intro hr hl\n  end\n\n  example : p \u2228 q \u2194 q \u2228 p :=\n  begin\n    apply iff.intro;\n    intro h;\n    cases h with hl hl;\n    { right, exact hl } <|> { left, exact hl }\n  end\n\n  -- associativity of \u2227 and \u2228\n  example : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) :=\n  begin\n    apply iff.intro;\n    intro h;\n    repeat { split },\n    all_goals {\n      cases h with h_left h_right,\n      cases h_left with hp hq <|> cases h_right with hq hr,\n      assumption\n    }\n  end\n\n  example : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) :=\n  begin\n    split;\n    intro h, {\n      cases h with h1 h2,\n      cases h1 with hp hq,\n      all_goals {\n        repeat { { left, assumption} <|> right <|> assumption }\n      }\n    }, {\n      cases h with h1 h1,\n      { left, left, assumption },\n      cases h1 with hq hr,\n      try { left }, all_goals { right, assumption },\n    }\n  end\n\n  -- distributivity\n  example : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\n  begin\n    split; intro h, {\n      cases h.right,\n      left, exact and.intro h.left h_1,\n      right, exact and.intro h.left h_1,\n    }, {\n      cases h;\n      split; cases h,\n      all_goals { assumption <|> {left, assumption} <|> {right, assumption }}\n    },\n  end\n  example : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) :=\n  begin\n    split; intro h, {\n      cases h;\n      split,\n      any_goals { {left, assumption} },\n      all_goals { right },\n      exact h.left, exact h.right\n    }, {\n      cases h,\n      cases h_left;\n      cases h_right,\n      any_goals { left, assumption },\n      right, exact and.intro h_left h_right,\n    }\n  end\n\n  -- other properties\n  example : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) :=\n  begin\n    split; intro h,\n    {\n      intro pq,\n      show r, from (h (pq.left)) pq.right,\n    }, {\n      intro p, intro q,\n      exact h \u27e8p, q\u27e9\n    }\n  end\n\n  example : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) :=\n  begin\n    split; intro h, {\n      split; intro h1,\n        exact h (or.inl h1),\n        exact h (or.inr h1),\n    }, {\n      intro pq,\n      cases pq,\n        exact h.left pq,\n        exact h.right pq,\n    }\n  end\n\n  example : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq :=\n  begin\n    split; intro h, {\n      split; intro n,\n        have : p \u2228 q, from or.inl n, contradiction,\n        have : p \u2228 q, from or.inr n, contradiction,\n    }, {\n      intro n, cases n,\n        have : \u00acp, from h.left, contradiction,\n        have : \u00acq, from h.right, contradiction,\n    }\n  end\n  example : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) :=\n  begin\n    intro h,\n    intro pq,\n    have : p, from pq.left,\n    have : q, from pq.right,\n    cases h; contradiction\n  end\n\n  example : \u00ac(p \u2227 \u00acp) :=\n  begin\n    intro h,\n    cases h, contradiction\n  end\n\n  example : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) :=\n  begin\n    intro h,\n    cases h with hl hr,\n    intro pq,\n    have : q, from pq hl,\n    contradiction \n  end\n\n  example : \u00acp \u2192 (p \u2192 q) :=\n  begin\n    repeat { intro },\n    contradiction\n  end\n\n  example : (\u00acp \u2228 q) \u2192 (p \u2192 q) :=\n  begin\n    repeat { intro },\n    cases a,\n    contradiction,\n    assumption\n  end\n\n  example : p \u2228 false \u2194 p :=\n  begin\n    split; intro h, {\n      cases h,\n        assumption,\n        contradiction\n    }, {\n      exact or.inl h\n    }\n  end\n\n  example : p \u2227 false \u2194 false :=\n  begin\n    split; intro h,\n    cases h,\n    all_goals { contradiction }\n  end\n\n  example : \u00ac(p \u2194 \u00acp) :=\n  begin\n    intro h,\n    cases h,\n    have : p \u2192 false, {\n      intro hp,\n      have : \u00acp, from h_mp hp,\n      contradiction\n    },\n    have : p, from h_mpr this,\n    have : \u00acp, from h_mp this,\n    contradiction\n  end\n\n  example : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) :=\n  begin\n    repeat { intro },\n    have : q, from a a_2,\n    contradiction\n  end\n\n  -- these require classical reasoning\n  example : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) :=\n  begin\n    intro h,\n    cases classical.em r, {\n      have : p \u2192 r, { intro , assumption },\n      left, assumption,\n    }, {\n      have : p \u2192 s, {\n        intro,\n        have : r \u2228 s, from h a,\n        cases this, contradiction, assumption\n      },\n      right, assumption\n    }\n  end\n\n  example : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq :=\n  begin\n    intro h,\n    cases classical.em p, {\n      have : \u00acq, {\n        intro,\n        have : p \u2227 q, from and.intro h_1 a,\n        contradiction\n      },\n      exact or.inr this\n    }, {\n      left, assumption\n    }\n  end\n\n  example : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq :=\n  begin\n    intro h,\n    split, {\n      from classical.by_contradiction \n        begin\n          repeat { intro },\n          have : p \u2192 q, {\n            intro h, contradiction,\n          },\n          contradiction\n        end\n    }, {\n      intro,\n      have : p \u2192 q, intro, assumption,\n      contradiction,\n    }\n  end\n\n  example : (p \u2192 q) \u2192 (\u00acp \u2228 q) :=\n  begin\n    intro h,\n    cases classical.em p,\n      right, from h h_1,\n      left, assumption\n  end\n\n  example : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) :=\n  begin\n    repeat { intro },\n    from classical.by_contradiction\n      begin\n        intro nq,\n        have : \u00acp, from a nq,\n        contradiction\n      end\n  end\n\n  example : p \u2228 \u00acp := classical.em p\n\n  example : (((p \u2192 q) \u2192 p) \u2192 p) :=\n  begin\n    intro,\n    cases classical.em p,\n      { assumption },\n      { have : p \u2192 q, intro, contradiction,\n        from a this,\n      }\n  end\nend\n\n------ Quantifiers and Expressions\nsection  -- 4.1\n  variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\n  example : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) :=\n  begin\n    split; intro h, {\n      split; intro x,\n      from (h x).left,\n      from (h x).right,\n    }, {\n      cases h,\n      intro x,\n      split, from h_left x, from h_right x,\n    }\n  end\n\n  example : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) :=\n  begin\n    intros h h\u2081 x,\n    have : p x, from h\u2081 x,\n    from (h x) this\n  end\n\n  example : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x :=\n  begin\n    intros h x,\n    cases h,\n      { left, from h x },\n      { right, from h x },\n  end\nend\n\nsection -- 4.2\n  variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n  variable r : Prop\n\n  example : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) :=\n  begin\n    intro \u03b1,\n    split; intro h,\n      { from h \u03b1 },\n      { intro, from h }\n  end\n  example : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r :=\n  begin\n    split; intro h, {\n      apply classical.by_cases,\n        intro, right, assumption,\n        intro nr, left, intro x, cases h x,\n          assumption,\n          contradiction\n    }, {\n      intro x,\n      cases h,\n        left, from h x,\n        right, assumption\n    }\n  end\n\n  example : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\n  begin\n    split;\n    intros h h\u2081 h\u2082;\n    from h h\u2082 h\u2081\n  end\nend\n\nsection -- 4.3\n  variables (men : Type) (barber : men)\n  variable  (shaves : men \u2192 men \u2192 Prop)\n\n  example (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : false :=\n  begin\n    have shave_barber, from h barber,\n    have : \u2200 p: Prop, (p \u2194 \u00acp) \u2192 false, {\n      intros p h,\n      cases h,\n      have : \u00acp, { \n        intro hp, \n        have : \u00acp, from h_mp hp,\n        contradiction\n      },\n      have : p, from h_mpr this,\n      contradiction\n    }, \n    from (this (shaves barber barber)) shave_barber\n  end\nend\n\nsection -- 4.5\n  variables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n  variable a : \u03b1\n  variable r : Prop\n  \n  example : (\u2203 x : \u03b1, r) \u2192 r :=\n  begin\n    intro h,\n    cases h with x hr,\n    from hr\n  end\n  \n  include a\n  example : r \u2192 (\u2203 x : \u03b1, r) :=\n  begin\n    intro hr, split; assumption\n  end\n  example : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := \n  begin\n    split; intro h, {\n      cases h with x pr,\n      cases pr,\n      repeat { split },\n      all_goals { assumption }\n    }, {\n      cases h, cases h_left,\n      repeat { split },\n      all_goals { assumption },\n    }\n  end\n  \n  example : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) :=\n  begin\n    split; intro h, {\n      cases h with x pq,\n      cases pq,\n        { left, split; assumption },\n        { right, split; assumption },\n    }, {\n      cases h; cases h with x h;\n      split,\n        { left, from h },\n        { right, from h },\n    }\n  end\n  \n  example : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) :=\n  begin\n    split; intro h, {\n      intro ex,\n      cases ex with x np,\n      have : p x, from h x,\n      contradiction\n    }, {\n      intro x,\n      from classical.by_contradiction\n        (by { intro np, from h \u27e8x, np\u27e9 })\n    }\n  end\n  \n  example : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) :=\n  begin\n    split; intro h, {\n      intro apx, \n      cases h with x px,\n      have : \u00acp x, from apx x,\n      contradiction\n    }, {\n      from classical.by_contradiction\n      begin\n        intro epx,\n        have : \u2200 x, \u00acp x, {\n          intros x px,\n          from epx \u27e8x, px\u27e9\n        },\n        contradiction\n      end\n    }\n  end\n  \n  example : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) :=\n  begin\n    split; intro h, {\n      intros x px, from h \u27e8x, px\u27e9\n    }, { \n      intro ex,\n      cases ex with x px,\n      have : \u00acp x, from h x,\n      contradiction\n    }\n  end\n  \n  example : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) :=\n  begin\n    split; intro h, {\n      from classical.by_contradiction\n      begin\n        intro ex,\n        have : \u2200 x, p x, {\n          intro x,\n          from classical.by_contradiction \n            ( by { intro npx, from ex \u27e8x, npx\u27e9})\n        },\n        contradiction\n      end\n    }, {\n      cases h with x npx,\n      intros apx,\n      have : p x, from apx x,\n      contradiction\n    }\n  end\n  \n  example : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r :=\n  begin\n    split; intro h, {\n      intro epx,\n      cases epx with x px,\n      from (h x) px\n    }, {\n      intros x px,\n      from h \u27e8x, px\u27e9\n    }\n  end\n  \n  example : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r :=\n  begin\n    split; intro h, {\n      intro apx,\n      cases h with x pxr,\n      from pxr (apx x)\n    }, {\n      apply classical.by_cases, {\n        intro hapx,\n        have : r, from h hapx,\n        existsi a, intro, assumption\n      }, {\n        intro napx,\n        have : \u2203x, \u00acp x, apply classical.by_contradiction, {\n          intro nepx,\n          have : \u2200 x, p x, {\n            intro x,\n            apply classical.by_contradiction,\n            intro npx,\n            have : \u2203x, \u00acp x, from exists.intro x npx,\n            contradiction\n          },\n          contradiction\n        },\n        cases this with x npx,\n        existsi x,\n        intro, contradiction\n      }\n    }\n  end\n  \n  example : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) :=\n  begin\n    split; intro h, {\n      intro hr,\n      cases h with x rpx,\n      existsi x, from rpx hr,\n    }, {\n      apply classical.by_cases, {\n        intro hr,\n        cases (h hr) with x px,\n        existsi x, intro, assumption,\n      }, {\n        intro hr,\n        existsi a, intro, contradiction,\n      }\n    }\n  end\nend\n\nsection -- 4.6\n  variables (real : Type) [ordered_ring real]\n  variables (log exp : real \u2192 real)\n  variable  log_exp_eq : \u2200 x, log (exp x) = x\n  variable  exp_log_eq : \u2200 {x}, x > 0 \u2192 exp (log x) = x\n  variable  exp_pos    : \u2200 x, exp x > 0\n  variable  exp_add    : \u2200 x y, exp (x + y) = exp x * exp y\n  \n  -- this ensures the assumptions are available in tactic proofs\n  include log_exp_eq exp_log_eq exp_pos exp_add\n  \n  example (x y z : real) :\n    exp (x + y + z) = exp x * exp y * exp z :=\n  by rw [exp_add, exp_add]\n  \n  example (y : real) (h : y > 0)  : exp (log y) = y :=\n  exp_log_eq h\n  \n  theorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n    log (x * y) = log x + log y :=\n    begin\n      rw [\u2190(exp_log_eq hx), \u2190(exp_log_eq hy)],\n      rw \u2190exp_add,\n      repeat { rw log_exp_eq },\n    end\nend\n\nsection -- 4.7\n  example (x : \u2124) : x * 0 = 0 :=\n  begin\n    simp\n  end\nend\n\nsection -- 5.8\n  example (p q r : Prop) (hp : p) :\n  (p \u2228 q \u2228 r) \u2227 (q \u2228 p \u2228 r) \u2227 (q \u2228 r \u2228 p) :=\n  by { repeat { split }, repeat { {left, assumption} <|> right <|> assumption } }\nend", "meta": {"author": "alanhdu", "repo": "lean-proofs", "sha": "a02cb9d0d2b6a6457f35247b89253d727f641531", "save_path": "github-repos/lean/alanhdu-lean-proofs", "path": "github-repos/lean/alanhdu-lean-proofs/lean-proofs-a02cb9d0d2b6a6457f35247b89253d727f641531/theorem_proving_in_lean/tactics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7026858392084491}}
{"text": "import algebra.order.field.basic tactic.by_contra\n\n/-! # IMO 2009 A5 -/\n\nnamespace IMOSL\nnamespace IMO2009A5\n\ntheorem final_solution {F : Type*} [linear_ordered_field F] (f : F \u2192 F) :\n  \u2203 x y : F, y * f x + x < f (x - f y) :=\nbegin\n  ---- Assume contradiction, and start with `f(t) \u2264 t + f(0)` for all `t : F`\n  by_contra' h,\n  have h0 : \u2200 t : F, f t \u2264 t + f 0 :=\n    \u03bb t, by replace h := h (t + f 0) 0; rwa [add_sub_cancel, zero_mul, zero_add] at h,\n  by_cases h1 : \u2200 x : F, f x \u2264 0,\n\n  ---- Case 1: `f(x) \u2264 0` for all `x : F`\n  { replace h0 : \u2200 t : F, f t \u2264 t :=\n      \u03bb t, le_trans (h0 t) (add_le_of_nonpos_right $ h1 0),\n    cases exists_gt (max 0 (- 1 - f (-1))) with t h2,\n    rw max_lt_iff at h2; cases h2 with h2 h3,\n    revert h3; rw [imp_false, not_lt, le_sub_iff_add_le, \u2190 le_sub_iff_add_le', \u2190 neg_add'],\n    replace h := h (f t - 1) t,\n    rw sub_sub_cancel_left at h,\n    refine le_trans h _; clear h,\n    rw \u2190 le_sub_iff_add_le,\n    refine le_trans ((mul_le_mul_left h2).mpr $ h0 _) _,\n    rw [le_sub_iff_add_le, \u2190 add_one_mul, add_comm,\n        le_neg_iff_add_nonpos_right, \u2190 mul_add_one, sub_add_cancel],\n    exact mul_nonpos_of_nonneg_of_nonpos (le_of_lt $ add_pos one_pos h2) (h1 t) },\n\n  ---- Case 2: `f(c) > 0` for some `c : F`\n  { rw not_forall at h1,\n    cases h1 with c h1; rw not_le at h1,\n    cases exists_lt (min (c - f 0) ((- 1 - c - f 0) / f c)) with t h2,\n    rw lt_min_iff at h2; cases h2 with h2 h3,\n    rw [lt_div_iff h1, sub_right_comm, lt_sub_iff_add_lt] at h3,\n    revert h3; clear h1; rw [imp_false, not_lt],\n    refine le_trans _ (h c t),\n    rw sub_le_iff_le_add; refine le_trans _ (h0 _),\n    rw lt_sub_iff_add_lt at h2,\n    replace h2 := lt_of_le_of_lt (h0 t) h2,\n    rw \u2190 sub_pos at h2,\n    generalize_hyp : c - f t = y at h2 \u22a2,\n\n    -- Remains to prove `f(f(y)) \u2265 -1` for all `y > 0`\n    replace h := le_trans (h (f y) y) (add_le_add_left (h0 y) _),\n    rw [sub_self, \u2190 add_assoc, le_add_iff_nonneg_left, \u2190 mul_add_one] at h,\n    rwa [neg_le_iff_add_nonneg, \u2190 zero_le_mul_left h2] }\nend\n\nend IMO2009A5\nend IMOSL\n", "meta": {"author": "mortarsanjaya", "repo": "imo-A-and-N", "sha": "645a924da7442f41d56ee6a0d96dc4d777b593a9", "save_path": "github-repos/lean/mortarsanjaya-imo-A-and-N", "path": "github-repos/lean/mortarsanjaya-imo-A-and-N/imo-A-and-N-645a924da7442f41d56ee6a0d96dc4d777b593a9/src/IMO2009/A5/A5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.702685834623024}}
{"text": "-- begin header\n\nimport M40002.countability\n\nnamespace completeness\n\nvariables {X Y : Type}\n-- end header\n\n/- Sub-section\nThe Completeness Axiom\n-/\n\n/- Theorem\nIf a set $S \u2282 \u211d$ has maximums $a$ and $b$, then $a = b$, i.e. the maximum of a set is unique.\n-/\ntheorem unique_max (S : set \u211d) : \u2200 a b \u2208 S, (\u2200 x \u2208 S, x \u2264 a \u2227 x \u2264 b) \u2192 a = b :=\nbegin\n  intros a b ha hb hc,\n  have : a \u2264 b := (hc a ha).right,\n  cases lt_or_eq_of_le this,\n    {have : b \u2264 a := (hc b hb).left,\n    rw \u2190not_lt at this,\n    contradiction\n    },\n    {assumption}\nend\n\n/- Theorem\nIf a set $S \u2282 \u211d$ has minimums $a$ and $b$, then $a = b$, i.e. the minimum of a set is unique.\n-/\ntheorem neg_set_min (S : set \u211d) (s : \u211d) (h0 : s \u2208 S) (h1 : \u2200 x \u2208 S, x \u2264 s): \n  \u2200 x \u2208 {t : \u211d | -t \u2208 S}, -s \u2264 x \u2227 -s \u2208 {t : \u211d | -t \u2208 S} :=\nbegin\n  intros x hx,\n  split,\n  {rwa neg_le,\n  rw set.mem_set_of_eq at hx,\n  apply h1, assumption\n  },\n  {rwa set.mem_set_of_eq,\n  simpa\n  }\nend\n\n/- Definition\nA set $S \u2282 \u211d$ is bounded above if and only if $\u2203 M \u2208 \u211d, \u2200 s \u2208 S, s \u2264 M$\n-/\ndef bounded_above (S : set \u211d) := \u2203 M : \u211d, \u2200 s \u2208 S, s \u2264 M\n\n/- Definition\nWe call $M$ a upper bound of $S \u2282 \u211d$ if and only if $\u2200 s \u2208 S, s \u2264 M$.\n-/\ndef upper_bound (S : set \u211d) (M : \u211d) := \u2200 s \u2208 S, s \u2264 M\n\n/-\nWe can deduce some properties straight away from these definitions.\n-/\n\n/- Corollary\nA set $S \u2282 \u211d$ is bounded above if and only if there exists a $M \u2208 \u211d$, $M$ is an upper bound of $S$\n-/\ntheorem bdd_above_iff_have_upr_bd (S : set \u211d) : (\u2203 M : \u211d, upper_bound S M) \u2194 bounded_above S :=\nby {split, all_goals {rintro \u27e8M, hM\u27e9, use M, assumption} }\n\n/- Corollary\nIf $S$ has an upperbound $M$, then $\u2200 x \u2208 R, x \u2265 M$ implies $x$ is a upper bound of $S$ \n-/\ntheorem bigger_upperbound (S : set \u211d) (s : \u211d) (h : upper_bound S s) :\n  \u2200 x : \u211d, s \u2264 x \u2192 upper_bound S x :=\nby {intros x hx y hy, from le_trans (h y hy) hx}\n\n/-\nWe will define lower bounds and bounded below in a similar fashion.\n-/\n\n/- Definition\nA set $S \u2282 \u211d$ is bounded below if and only if $\u2203 M \u2208 \u211d, \u2200 s \u2208 S, s \u2265 M$\n-/\ndef bounded_below (S : set \u211d) := \u2203 M : \u211d, \u2200 s \u2208 S, M \u2264 s\n\n/- Definition\nWe call $M$ a lower bound of $S \u2282 \u211d$ if and only if $\u2200 s \u2208 S, s \u2265 M$.\n-/\ndef lower_bound (S : set \u211d) (M : \u211d) := \u2200 s \u2208 S, M \u2264 s\n\n/- Corollary\nA set $S \u2282 \u211d$ is bounded below if and only if there exists a $M \u2208 \u211d$, $M$ is an lower bound of $S$\n-/\ntheorem bdd_below_iff_have_lwr_bd (S : set \u211d) : (\u2203 M : \u211d, lower_bound S M) \u2194 bounded_below S :=\nby {split, all_goals {rintro \u27e8M, hM\u27e9, use M, assumption} }\n\n/- Exercise\nIf $s \u2208 \u211d$ is an upper bound of a set $S \u2282 \u211d$, then $-s$ is a lower bound of the set ${t \u2208 \u211d | -t \u2208 S}$.\n-/\ntheorem upr_bd_neg_set_lwr_bd (S : set \u211d) (s : \u211d) : upper_bound S s \u2194 lower_bound {t : \u211d | -t \u2208 S} (-s) :=\nbegin\n  split,\n    all_goals {intros h x hx},\n    {rw set.mem_set_of_eq at hx,\n    suffices : (-x) \u2264 s, rwa neg_le,\n    from h (-x) hx\n    },\n    unfold lower_bound at h,\n    suffices : (-s) \u2264 (-x), simp at this, assumption,\n    have : (-x) \u2208 {t : \u211d | -t \u2208 S} := by {rwa set.mem_set_of_eq, simp, assumption},\n    from h (-x) this\nend\n\n/- Definition\nWe call a set $S \u2282 \u211d$ bounded if it is bounded above and below.\n-/\ndef bounded (S : set \u211d) := bounded_above S \u2227 bounded_below S\n\n-- Okay, so I've switched around the definition of supremums but dw, the two definitions are equiv.\ndef sup (S : set \u211d) (x : \u211d) := upper_bound S x \u2227 (\u2200 y : \u211d, y < x \u2192 \u00ac (upper_bound S y)) -- Check out sup_def for the definition from the lecture notes\ndef inf (S : set \u211d) (x : \u211d) := lower_bound S x \u2227 (\u2200 y : \u211d, x < y \u2192 \u00ac (lower_bound S y))\n\n-- Exercise 2.24\ntheorem unique_sup (S : set \u211d) : \u2200 a b \u2208 S, sup S a \u2227 sup S b \u2192 a = b :=\nbegin\n  rintros a b ha hb \u27e8\u27e8bda, supa\u27e9, \u27e8bdb,supb\u27e9\u27e9,\n  have hc : \u2200 s \u2208 S, s \u2264 a \u2227 s \u2264 b := by {intros s hs, from \u27e8bda s hs, bdb s hs\u27e9},\n  from unique_max S a b ha hb hc\nend\n\ntheorem sup_non_empty (S : set \u211d) (s : \u211d) (h : sup S s) : S \u2260 \u2205 :=\nbegin\n  cases h with ha hb,\n  intro, \n  have hc : upper_bound S (s - 1) := \n    by {intros x hx,\n    rw a at hx,\n    simp at hx, contradiction\n    },\n  have hd : s - 1 < s := by linarith,\n  replace hb : \u00ac upper_bound S (s - 1) := by {apply hb (s - 1) hd},\n  contradiction\nend\n\ntheorem neg_set_inf (S : set \u211d) (s : \u211d) (h : sup S s) : \n  inf {t : \u211d | -t \u2208 S} (-s) :=\nbegin\n  cases h with hbd hlub,\n  split,\n    {intros x hx,\n    apply classical.by_contradiction,\n    intro h, push_neg at h,\n    have : -s \u2264 x := by {rw neg_le, from (hbd (-x) hx)},\n    apply not_le_of_lt h, assumption\n    },\n    {intros y hy hlbd,\n    have : upper_bound S (-y) := \n      by {intros x hx,\n      apply classical.by_contradiction,\n      intro h, push_neg at h,\n      unfold lower_bound at hlbd,\n      have : y \u2264 -x := \n        by {replace hx : -x \u2208 {t : \u211d | -t \u2208 S},\n          rw set.mem_set_of_eq, simp, assumption,\n        from hlbd (-x) hx\n        },\n      apply not_le_of_lt h, rwa le_neg\n      },\n    replace hy : -y < s := by {rwa neg_lt},\n    from hlub (-y) hy this\n    }\nend\n\ntheorem sup_def (S : set \u211d) (s : \u211d) : sup S s \u2194 upper_bound S s \u2227 \u2200 x : \u211d, (upper_bound S x \u2192 s \u2264 x) :=\nbegin\n  split,\n    {rintros \u27e8ha, hb\u27e9,\n    split,\n      {intros x hx,\n      from ha x hx\n      },\n      {intros x hx,\n      suffices : \u00ac x < s, revert this, simp,\n      intro, apply hb x, repeat {assumption}}\n    },\n    {rintros \u27e8ha, hb\u27e9, split,\n      {assumption},\n      {intros x hx hc,\n      replace hx : \u00ac s \u2264 x := by {push_neg, assumption},\n      from hx (hb x hc)\n      }\n    }\nend\n\ntheorem inf_def (S : set \u211d) (s : \u211d) : inf S s \u2194 lower_bound S s \u2227 \u2200 x : \u211d, (lower_bound S x \u2192 x \u2264 s) :=\nbegin -- proof essentially identical to that of sup_def\n    split,\n    {rintros \u27e8ha, hb\u27e9,\n    split,\n      {intros x hx,\n      from ha x hx\n      },\n      {intros x hx,\n      suffices : \u00ac s < x, revert this, simp,\n      intro, apply hb x, repeat {assumption}}\n    },\n    {rintros \u27e8ha, hb\u27e9, split,\n      {assumption},\n      {intros x hx hc,\n      replace hx : \u00ac x \u2264 s := by {push_neg, assumption},\n      from hx (hb x hc)\n      }\n    }\nend\n\n-- Defining the Completeness axiom\naxiom completeness (S : set \u211d) (h : bounded_above S) (h1 : S \u2260 \u2205) : \u2203 s : \u211d, sup S s\n\nlemma neg_bdd_above_of_bdd_below {S : set \u211d} \n(h : bounded_below S) : bounded_above {t | -t \u2208 S} :=\nbegin\n-- Since S is bounded below let b be its lower.\n  cases h with b hb,\n-- I now claim that -b is a lower bound of {t | -t \u2208 S}.\n  refine \u27e8-b, \u03bb s hs, _\u27e9,\n-- Let -s \u2208 S. But then from b being an lower bound of S, b \u2264 -s \u2192 s \u2264 -b as required!\n  linarith [hb (-s) hs]\nend\n\nopen set\n\n-- Exercise 2.29\ntheorem completeness_below (S : set \u211d) (h : bounded_below S) (h1 : S \u2260 \u2205) : \u2203 s : \u211d, inf S s :=\nbegin\n-- As we have S is not an empty set, there exists s \u2208 S.\n  cases ne_empty_iff_nonempty.1 h1 with s hs, \n-- Now let's consider the set T := {t : \u211d | -t \u2208 S}.\n-- This set is bounded above by our previous lemma so by completeness, it has a supremum (lets call it b).\n  cases completeness {t : \u211d | -t \u2208 S} \n  (neg_bdd_above_of_bdd_below h) \n  (ne_empty_iff_nonempty.2 \u27e8-s, by simp [hs]\u27e9) with b hb,\n-- I claim that -b is the infimum of S.\n  refine \u27e8-b, _\u27e9, \n-- As we have previously proven that if s is the supremum of S then -s is the infimum of {t : \u211d | -t \u2208 S},\n-- it suffices to show that S = {t : \u211d | -t \u2208 {t : \u211d | -t \u2208 S}}. But this is trivial, so we are done!\n  convert neg_set_inf {t : \u211d | -t \u2208 S} _ _,\n  simp, exact hb\nend\n\nopen classical\n\n-- Mentimeter Q 9\ntheorem equality_def (a x : \u211d) : (\u2200 \u03b5 : \u211d, 0 < \u03b5 \u2192 abs (x - a) < \u03b5) \u2194 x = a :=\nbegin\n-- Since this is an if and only if question we need to prove both directions of the equation.\n  split,\n-- Let use prove the forward direction first. \n-- Suppose otherwise. Then x \u2260 a.\n  intro h, by_contra h1,\n-- It suffices to prove abs (x - a) <  abs (x - a) since that's obviously false.\n  suffices : abs (x - a) <  abs (x - a), linarith,\n-- So, by choosing \u03b5 = abs (x - a), the contradiction follows easily.\n  refine h _ (abs_pos_iff.2 $ \u03bb h2, _), \n  rw sub_eq_zero at h2, contradiction,\n-- For the other direction it is much easier. \n-- If x = a then abs (x - a) = 0 < \u03b5 by construction so we are done!\n  intro h, rw h, simp\nend\n\nend completeness\n", "meta": {"author": "JasonKYi", "repo": "M4000x_LEAN_formalisation", "sha": "6e99793f2fcbe88596e27644f430e46aa2a464df", "save_path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation", "path": "github-repos/lean/JasonKYi-M4000x_LEAN_formalisation/M4000x_LEAN_formalisation-6e99793f2fcbe88596e27644f430e46aa2a464df/src/M40002/complete.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7026857545123733}}
{"text": "namespace Algebra\n\nsection\n  universe u\n  variable (X : Type u)\n  class Op where op : X \u2192 X \u2192 X\n  scoped infixl:70 \" \u22c6 \" => Op.op\nend\nsection\n  variable {X} (data : Op X)\n  namespace Op\n  class IsComm : Prop where comm : \u2200 x y : X, x \u22c6 y = y \u22c6 x\n  export IsComm (comm)\n  class IsSemigroup : Prop where assoc : \u2200 x y z : X, (x \u22c6 y) \u22c6 z = x \u22c6 (y \u22c6 z)\n  export IsSemigroup (assoc)\n  class IsCommSemigroup extends data.IsSemigroup, data.IsComm : Prop\n  end Op\nend\nsection\n  variable {X Y}\n  variable {src : Op X} {dst : Op Y}\n  namespace Op\n  structure Function (src : Op X) (dst : Op Y) where map : X \u2192 Y\n  namespace Function\n  instance : CoeFun (Function src dst) (\u03bb _ => X \u2192 Y) where coe f := f.map\n  class IsSemigroupMorphism [src.IsSemigroup] [dst.IsSemigroup] (f : Function src dst) : Prop where\n    op_law : \u2200 x y, f (x \u22c6 y) = f x \u22c6 f y\n  attribute [simp] IsSemigroupMorphism.op_law\n  end Function\n  end Op\nend\n\nsection\n  universe u\n  variable (X : Type u)\n  class Identity where identity : X\n  scoped notation:max \"\ud835\udfd9\" => Identity.identity\n  class Zero where zero : X\n  scoped notation:max \"\ud835\udfec\" => Zero.zero\n  class One where one : X\n  scoped notation:max \"\ud835\udfed\" => One.one\n  class OpId extends Op X, Identity X\n  attribute [reducible] OpId.toOp OpId.toIdentity\nend\nsection\n  variable {X} (data : OpId X)\n  namespace OpId\n  class IsUnital : Prop where\n    id_op : \u2200 x : X, \ud835\udfd9 \u22c6 x = x\n    op_id : \u2200 x : X, x \u22c6 \ud835\udfd9 = x\n  export IsUnital (id_op op_id)\n  attribute [simp] id_op op_id\n  class IsMonoid extends data.IsSemigroup, data.IsUnital : Prop\n  class IsAddMonoid (X) [Add X] [Zero X] extends IsMonoid { op := Add.add, identity := (Zero.zero : X) } : Prop\n  class IsCommMonoid extends data.IsMonoid, data.IsComm : Prop\n  end OpId\nend\nsection\n  variable {X Y}\n  variable {src : OpId X} {dst : OpId Y}\n  namespace OpId\n  structure Function (src : OpId X) (dst : OpId Y) where map : X \u2192 Y\n  namespace Function\n  instance : CoeFun (Function src dst) (\u03bb _ => X \u2192 Y) where coe f := f.map\n  abbrev toOp (f : Function src dst) : Op.Function src.toOp dst.toOp := \u27e8f.1\u27e9\n  class IsMonoidMorphism [src.IsMonoid] [dst.IsMonoid] (f : Function src dst)\n  extends f.toOp.IsSemigroupMorphism : Prop where\n    id_law : f \ud835\udfd9 = \ud835\udfd9\n  attribute [simp] IsMonoidMorphism.id_law\n  end Function\n  end OpId\nend\n\nsection\n  universe u\n  variable (X : Type u)\n  class Sym where sym : X \u2192 X\n  scoped postfix:max \"\u207b\u2071\" => Sym.sym\n  class Neg where neg : X \u2192 X\n  scoped prefix:max \"-\" => Neg.neg\n  class Inv where inv : X \u2192 X\n  scoped postfix:max \"\u207b\u00b9\" => Inv.inv\n  class OpIdSym extends OpId X, Sym X\n  attribute [reducible] OpIdSym.toOpId OpIdSym.toSym\nend\nsection\n  variable {X} (data : OpIdSym X)\n  namespace OpIdSym\n  class IsSymmetric : Prop where\n    op_sym : \u2200 x : X, x \u22c6 x\u207b\u2071 = \ud835\udfd9\n    sym_op : \u2200 x : X, x\u207b\u2071 \u22c6 x = \ud835\udfd9\n  export IsSymmetric (op_sym sym_op)\n  attribute [simp] op_sym sym_op\n  class IsGroup extends OpId.IsMonoid data.toOpId, IsSymmetric data  : Prop\n  class IsCommGroup extends IsGroup data, Op.IsComm data.toOp : Prop\n  end OpIdSym\nend\nsection\n  variable {X Y}\n  variable {src : OpIdSym X} {dst : OpIdSym Y}\n  namespace OpIdSym\n  structure Function (src : OpIdSym X) (dst : OpIdSym Y) where map : X \u2192 Y\n  namespace Function\n  instance : CoeFun (Function src dst) (\u03bb _ => X \u2192 Y) where coe f := f.map\n  abbrev toOpId (f : Function src dst) : OpId.Function src.toOpId dst.toOpId := \u27e8f.1\u27e9\n  abbrev toOp (f : Function src dst) : Op.Function src.toOp dst.toOp := f.toOpId.toOp\n  class IsGroupMorphism [src.IsGroup] [dst.IsGroup] (f : Function src dst)\n  extends f.toOpId.IsMonoidMorphism : Prop\n  end Function\n  end OpIdSym\nend\n\nsection\n  universe u\n  variable (X : Type u)\n  class AddZeroMulOne extends Add X, Zero X, Mul X, One X\n  attribute [reducible] AddZeroMulOne.toAdd AddZeroMulOne.toZero AddZeroMulOne.toMul AddZeroMulOne.toOne\nend\nsection\n  variable {X} (data : AddZeroMulOne X)\n  namespace AddZeroMulOne\n  abbrev toAddZero : OpId X := { op := data.add, identity := data.zero }\n  abbrev toMulOne : OpId X := { op := data.mul, identity := data.one }\n\n  class IsSemiring : Prop where\n    addZero_IsCommMonoid : data.toAddZero.IsCommMonoid\n    mulOne_IsMonoid : data.toMulOne.IsMonoid\n    mul_add : \u2200 x y z : X, x * (y + z) = x * y + x * z\n    add_mul : \u2200 x y z : X, (x + y) * z = x * z + y * z\n    mul_zero : \u2200 x : X, x * \ud835\udfec = \ud835\udfec\n    zero_mul : \u2200 x : X, \ud835\udfec * x = \ud835\udfec\n  export IsSemiring (addZero_IsCommMonoid mulOne_IsMonoid mul_add add_mul mul_zero zero_mul)\n  instance [data.IsSemiring] : data.toAddZero.IsCommMonoid := addZero_IsCommMonoid\n  instance [data.IsSemiring] : data.toMulOne.IsMonoid := mulOne_IsMonoid\n\n  class IsCommSemiring extends data.IsSemiring, data.toMulOne.IsComm : Prop where\n  instance [data.IsCommSemiring] : data.toMulOne.IsCommMonoid := {}\n\n  end AddZeroMulOne\nend\nsection\n  variable {X Y}\n  variable {src : AddZeroMulOne X} {dst : AddZeroMulOne Y}\n  namespace AddZeroMulOne\n  structure Function (src : AddZeroMulOne X) (dst : AddZeroMulOne Y) where map : X \u2192 Y\n  namespace Function\n  instance : CoeFun (Function src dst) (\u03bb _ => X \u2192 Y) where coe f := f.map\n  abbrev toAddZero (f : Function src dst) : OpId.Function src.toAddZero dst.toAddZero := \u27e8f.1\u27e9\n  abbrev toMulOne (f : Function src dst) : OpId.Function src.toMulOne dst.toMulOne := \u27e8f.1\u27e9\n  class IsSemiringMorphism [src.IsSemiring] [dst.IsSemiring] (f : Function src dst) : Prop where\n    addZero_Morphism : f.toAddZero.IsMonoidMorphism\n    mulOne_Morphism : f.toMulOne.IsMonoidMorphism\n  end Function\n  end AddZeroMulOne\nend\n\nsection\n  universe u\n  variable (X : Type u)\n  class AddZeroNegMulOne extends AddZeroMulOne X, Neg X\n  attribute [reducible] AddZeroNegMulOne.toAddZeroMulOne AddZeroNegMulOne.toNeg\nend\nsection\n  variable {X} (data : AddZeroNegMulOne X)\n  namespace AddZeroNegMulOne\n  abbrev toAddZero : OpId X := data.toAddZeroMulOne.toAddZero\n  abbrev toMulOne : OpId X := data.toAddZeroMulOne.toMulOne\n  abbrev toAddZeroNeg : OpIdSym X := { toOpId := data.toAddZero, sym := data.neg }\n\n  class IsRing extends data.IsSemiring : Prop where\n    addZeroNeg_IsSymmetric : data.toAddZeroNeg.IsSymmetric\n  instance [IsRing data] : data.toAddZeroNeg.IsSymmetric  := IsRing.addZeroNeg_IsSymmetric\n  instance [IsRing data] : data.IsSemiring := inferInstance\n  instance [IsRing data] : data.toAddZeroNeg.IsCommGroup := {\n    toIsComm := OpId.IsCommMonoid.toIsComm -- why cant it infer it?\n  }\n  end AddZeroNegMulOne\nend\nsection\n  variable {X Y}\n  variable {src : AddZeroNegMulOne X} {dst : AddZeroNegMulOne Y}\n  namespace AddZeroNegMulOne\n  structure Function (src : AddZeroNegMulOne X) (dst : AddZeroNegMulOne Y) where map : X \u2192 Y\n  namespace Function\n  instance : CoeFun (Function src dst) (\u03bb _ => X \u2192 Y) where coe f := f.map\n  abbrev toAddZeroMulOne (f : Function src dst) : AddZeroMulOne.Function src.toAddZeroMulOne dst.toAddZeroMulOne := \u27e8f.1\u27e9\n  abbrev toAddZeroNeg (f : Function src dst) : OpIdSym.Function src.toAddZeroNeg dst.toAddZeroNeg := \u27e8f.1\u27e9\n  abbrev toAddZero (f : Function src dst) : OpId.Function src.toAddZero dst.toAddZero := f.toAddZeroMulOne.toAddZero\n  abbrev toMulOne (f : Function src dst) : OpId.Function src.toMulOne dst.toMulOne := f.toAddZeroMulOne.toMulOne\n  class IsRingMorphism [src.IsRing] [dst.IsRing] (f : Function src dst)  \n  extends f.toAddZeroMulOne.IsSemiringMorphism : Prop\n  end Function\n  end AddZeroNegMulOne\nend\n\n\n\n\nexample (X) (data : OpIdSym X) [data.IsCommGroup] : \u2200 x y : X, x \u22c6 y = y \u22c6 x := Op.comm\nexample (X) (data : OpIdSym X) [data.IsCommGroup] : \u2200 x : X, x \u22c6 \ud835\udfd9 = x := by simp\nexample (X) (data : OpIdSym X) [data.IsCommGroup] : \u2200 x : X, x \u22c6 x\u207b\u2071 = \ud835\udfd9 := by simp\nexample (X) (data : AddZeroMulOne X) [data.IsSemiring] : \u2200 x : X, x + \ud835\udfec = x := \n  let _ := data.toAddZero\n  show \u2200 x : X, x \u22c6 \ud835\udfd9 = x from\n  by simp\n\n\ndef kernel {X Y} {src : OpId X} {dst : OpId Y} [src.IsMonoid] [dst.IsMonoid] (f : OpId.Function src dst) : X \u2192 Prop\n  := \u03bb x => f x = \ud835\udfd9\n\nexample {X Y} {src : AddZeroNegMulOne X} {dst : AddZeroNegMulOne Y} [src.IsRing] [dst.IsRing] \n  (f : AddZeroNegMulOne.Function src dst) (h : f.IsRingMorphism)\n  : kernel f.toAddZero \ud835\udfec := h.addZero_Morphism.id_law\nexample {X Y} {src : AddZeroNegMulOne X} {dst : AddZeroNegMulOne Y} [src.IsRing] [dst.IsRing] \n  (f : AddZeroNegMulOne.Function src dst) (h : f.IsRingMorphism)\n  : kernel f.toMulOne \ud835\udfed := h.mulOne_Morphism.id_law\n\n\n\nend Algebra", "meta": {"author": "michelsol", "repo": "lean-playground", "sha": "0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca", "save_path": "github-repos/lean/michelsol-lean-playground", "path": "github-repos/lean/michelsol-lean-playground/lean-playground-0bfffb7bd41729fb9f95974e93f6ecbc0b6e59ca/Playground/Misc/Structures/Unbundled.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7026857523820755}}
{"text": "import data.list.basic\nopen list\nuniverse u\nvariables {\u03b1 : Type} (x y z : \u03b1) (xs ys zs : list \u03b1)\n\ndef mk_symm (xs : list \u03b1) := xs ++ reverse xs\n\ntheorem reverse_mk_symm (xs : list \u03b1) :\n  reverse (mk_symm xs) = mk_symm xs :=\n  by simp [mk_symm]\n\nsection\nlocal attribute [simp] reverse_mk_symm\n\nexample (xs ys : list \u2115) :\n  reverse (xs ++ mk_symm ys) = mk_symm ys ++ reverse xs :=\n  by simp\n\nexample (xs ys : list \u2115) (p : list \u2115 \u2192 Prop) (h : p (reverse (xs ++ (mk_symm ys)))) :\n  p (mk_symm ys ++ reverse xs) :=\n  by simp at h; assumption\nend\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch5/ex0720.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.702685747715402}}
{"text": "/-\nCopyright (c) 2022 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n\n! This file was ported from Lean 3 source module analysis.normed_space.algebra\n! leanprover-community/mathlib commit 17ef379e997badd73e5eabb4d38f11919ab3c4b3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Topology.Algebra.Module.CharacterSpace\nimport Mathbin.Analysis.NormedSpace.WeakDual\nimport Mathbin.Analysis.NormedSpace.Spectrum\n\n/-!\n# Normed algebras\n\nThis file contains basic facts about normed algebras.\n\n## Main results\n\n* We show that the character space of a normed algebra is compact using the Banach-Alaoglu theorem.\n\n## TODO\n\n* Show compactness for topological vector spaces; this requires the TVS version of Banach-Alaoglu.\n\n## Tags\n\nnormed algebra, character space, continuous functional calculus\n\n-/\n\n\nvariable {\ud835\udd5c : Type _} {A : Type _}\n\nnamespace WeakDual\n\nnamespace CharacterSpace\n\nvariable [NontriviallyNormedField \ud835\udd5c] [NormedRing A] [NormedAlgebra \ud835\udd5c A] [CompleteSpace A]\n\ntheorem norm_le_norm_one (\u03c6 : characterSpace \ud835\udd5c A) : \u2016toNormedDual (\u03c6 : WeakDual \ud835\udd5c A)\u2016 \u2264 \u2016(1 : A)\u2016 :=\n  ContinuousLinearMap.op_norm_le_bound _ (norm_nonneg (1 : A)) fun a =>\n    mul_comm \u2016a\u2016 \u2016(1 : A)\u2016 \u25b8 spectrum.norm_le_norm_mul_of_mem (apply_mem_spectrum \u03c6 a)\n#align weak_dual.character_space.norm_le_norm_one WeakDual.characterSpace.norm_le_norm_one\n\ninstance [ProperSpace \ud835\udd5c] : CompactSpace (characterSpace \ud835\udd5c A) :=\n  by\n  rw [\u2190 isCompact_iff_compactSpace]\n  have h : character_space \ud835\udd5c A \u2286 to_normed_dual \u207b\u00b9' Metric.closedBall 0 \u2016(1 : A)\u2016 :=\n    by\n    intro \u03c6 h\u03c6\n    rw [Set.mem_preimage, mem_closedBall_zero_iff]\n    exact (norm_le_norm_one \u27e8\u03c6, \u27e8h\u03c6.1, h\u03c6.2\u27e9\u27e9 : _)\n  exact isCompact_of_isClosed_subset (is_compact_closed_ball \ud835\udd5c 0 _) character_space.is_closed h\n\nend CharacterSpace\n\nend WeakDual\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/NormedSpace/Algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7026857456753444}}
{"text": "/-\nCopyright (c) 2022 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport analysis.complex.cauchy_integral\nimport analysis.convex.integral\nimport analysis.normed_space.completion\nimport topology.algebra.order.extr_closure\n\n/-!\n# Maximum modulus principle\n\nIn this file we prove several versions of the maximum modulus principle.\n\nThere are several statements that can be called \"the maximum modulus principle\" for maps between\nnormed complex spaces.\n\nIn the most general case, see `complex.norm_eventually_eq_of_is_local_max`, we can only say that for\na differentiable function `f : E \u2192 F`, if the norm has a local maximum at `z`, then *the norm* is\nconstant in a neighborhood of `z`.\n\nIf the domain is a nontrivial finite dimensional space, then this implies the following version of\nthe maximum modulus principle, see `complex.exists_mem_frontier_is_max_on_norm`. If `f : E \u2192 F` is\ncomplex differentiable on a nonempty compact set `K`, then there exists a point `z \u2208 frontier K`\nsuch that `\u03bb z, \u2225f z\u2225` takes it maximum value on `K` at `z`.\n\nFinally, if the codomain is a strictly convex space, then the function cannot have a local maximum\nof the norm unless the function (not only its norm) is a constant. This version is not formalized\nyet.\n-/\n\nopen topological_space metric set filter asymptotics function measure_theory affine_map\nopen_locale topological_space filter nnreal real\n\nuniverses u v w\nvariables {E : Type u} [normed_group E] [normed_space \u2102 E]\n  {F : Type v} [normed_group F] [normed_space \u2102 F]\n\nlocal postfix `\u0302`:100 := uniform_space.completion\n\nnamespace complex\n\n/-!\n### Auxiliary lemmas\n\nWe split the proof into a series of lemmas. First we prove the principle for a function `f : \u2102 \u2192 F`\nwith an additional assumption that `F` is a complete space, then drop unneeded assumptions one by\none.\n\nThe only \"public API\" lemmas in this section are TODO and\n`complex.norm_eq_norm_of_is_max_on_of_closed_ball_subset`.\n-/\n\nlemma norm_max_aux\u2081 [complete_space F] {f : \u2102 \u2192 F} {z w : \u2102}\n  (hd : diff_on_int_cont \u2102 f (closed_ball z (dist w z)))\n  (hz : is_max_on (norm \u2218 f) (closed_ball z (dist w z)) z) :\n  \u2225f w\u2225 = \u2225f z\u2225 :=\nbegin\n  /- Consider a circle of radius `r = dist w z`. -/\n  set r : \u211d := dist w z,\n  have hw : w \u2208 closed_ball z r, from mem_closed_ball.2 le_rfl,\n  /- Assume the converse. Since `\u2225f w\u2225 \u2264 \u2225f z\u2225`, we have `\u2225f w\u2225 < \u2225f z\u2225`. -/\n  refine (is_max_on_iff.1 hz _ hw).antisymm (not_lt.1 _),\n  rintro hw_lt : \u2225f w\u2225 < \u2225f z\u2225,\n  have hr : 0 < r, from dist_pos.2 (ne_of_apply_ne (norm \u2218 f) hw_lt.ne),\n  /- Due to Cauchy integral formula, it suffices to prove the following inequality. -/\n  suffices : \u2225\u222e \u03b6 in C(z, r), (\u03b6 - z)\u207b\u00b9 \u2022 f \u03b6\u2225 < 2 * \u03c0 * \u2225f z\u2225,\n  { refine this.ne _,\n    have A : \u222e \u03b6 in C(z, r), (\u03b6 - z)\u207b\u00b9 \u2022 f \u03b6 = (2 * \u03c0 * I : \u2102) \u2022 f z :=\n      hd.circle_integral_sub_inv_smul (mem_ball_self hr),\n    simp [A, norm_smul, real.pi_pos.le] },\n  suffices : \u2225\u222e \u03b6 in C(z, r), (\u03b6 - z)\u207b\u00b9 \u2022 f \u03b6\u2225 < 2 * \u03c0 * r * (\u2225f z\u2225 / r),\n    by rwa [mul_assoc, mul_div_cancel' _ hr.ne'] at this,\n  /- This inequality is true because `\u2225(\u03b6 - z)\u207b\u00b9 \u2022 f \u03b6\u2225 \u2264 \u2225f z\u2225 / r` for all `\u03b6` on the circle and\n  this inequality is strict at `\u03b6 = w`. -/\n  have hsub : sphere z r \u2286 closed_ball z r, from sphere_subset_closed_ball,\n  refine circle_integral.norm_integral_lt_of_norm_le_const_of_lt hr _ _ \u27e8w, rfl, _\u27e9,\n  show continuous_on (\u03bb (\u03b6 : \u2102), (\u03b6 - z)\u207b\u00b9 \u2022 f \u03b6) (sphere z r),\n  { refine ((continuous_on_id.sub continuous_on_const).inv\u2080 _).smul (hd.continuous_on.mono hsub),\n    exact \u03bb \u03b6 h\u03b6, sub_ne_zero.2 (ne_of_mem_sphere h\u03b6 hr.ne') },\n  show \u2200 \u03b6 \u2208 sphere z r, \u2225(\u03b6 - z)\u207b\u00b9 \u2022 f \u03b6\u2225 \u2264 \u2225f z\u2225 / r,\n  { rintros \u03b6 (h\u03b6 : abs (\u03b6 - z) = r),\n    rw [le_div_iff hr, norm_smul, norm_inv, norm_eq_abs, h\u03b6, mul_comm, mul_inv_cancel_left\u2080 hr.ne'],\n    exact hz (hsub h\u03b6) },\n  show \u2225(w - z)\u207b\u00b9 \u2022 f w\u2225 < \u2225f z\u2225 / r,\n  { rw [norm_smul, norm_inv, norm_eq_abs, \u2190 div_eq_inv_mul],\n    exact (div_lt_div_right hr).2 hw_lt }\nend\n\n/-!\nNow we drop the assumption `complete_space F` by embedding `F` into its completion.\n-/\n\nlemma norm_max_aux\u2082 {f : \u2102 \u2192 F} {z w : \u2102} (hd : diff_on_int_cont \u2102 f (closed_ball z (dist w z)))\n  (hz : is_max_on (norm \u2218 f) (closed_ball z (dist w z)) z) :\n  \u2225f w\u2225 = \u2225f z\u2225 :=\nbegin\n  set e : F \u2192L[\u2102] F\u0302 := uniform_space.completion.to_complL,\n  have he : \u2200 x, \u2225e x\u2225 = \u2225x\u2225, from uniform_space.completion.norm_coe,\n  replace hz : is_max_on (norm \u2218 (e \u2218 f)) (closed_ball z (dist w z)) z,\n    by simpa only [is_max_on, (\u2218), he] using hz,\n  simpa only [he] using norm_max_aux\u2081 (e.differentiable.comp_diff_on_int_cont hd) hz\nend\n\n/-!\nThen we replace the assumption `is_max_on (norm \u2218 f) (closed_ball z r) z` with a seemingly weaker\nassumption `is_max_on (norm \u2218 f) (ball z r) z`.\n-/\n\nlemma norm_max_aux\u2083 {f : \u2102 \u2192 F} {z w : \u2102} {r : \u211d} (hr : dist w z = r)\n  (hd : diff_on_int_cont \u2102 f (closed_ball z r)) (hz : is_max_on (norm \u2218 f) (ball z r) z) :\n  \u2225f w\u2225 = \u2225f z\u2225 :=\nbegin\n  subst r,\n  rcases eq_or_ne w z with rfl|hne, { refl },\n  have : closure (ball z (dist w z)) = closed_ball z (dist w z),\n    from closure_ball z (dist_ne_zero.2 hne),\n  exact norm_max_aux\u2082 hd (this \u25b8 hz.closure (this.symm \u25b8 hd.continuous_on.norm))\nend\n\n/-!\nFinally, we generalize the theorem from a disk in `\u2102` to a closed ball in any normed space.\n-/\n\n/-- **Maximum modulus principle** on a closed ball: if `f : E \u2192 F` is continuous on a closed ball,\nis complex differentiable on the corresponding open ball, and the norm `\u2225f w\u2225` takes its maximum\nvalue on the open ball at its center, then the norm `\u2225f w\u2225` is constant on the closed ball.  -/\nlemma norm_eq_on_closed_ball_of_is_max_on {f : E \u2192 F} {z : E} {r : \u211d}\n  (hd : diff_on_int_cont \u2102 f (closed_ball z r)) (hz : is_max_on (norm \u2218 f) (ball z r) z) :\n  eq_on (norm \u2218 f) (const E \u2225f z\u2225) (closed_ball z r) :=\nbegin\n  intros w hw,\n  rw [mem_closed_ball, dist_comm] at hw,\n  rcases eq_or_ne z w with rfl|hne, { refl },\n  set e : \u2102 \u2192 E := line_map z w,\n  have hde : differentiable \u2102 e := (differentiable_id.smul_const (w - z)).add_const z,\n  suffices : \u2225(f \u2218 e) (1 : \u2102)\u2225 = \u2225(f \u2218 e) (0 : \u2102)\u2225, by simpa [e],\n  have hr : dist (1 : \u2102) 0 = 1, by simp,\n  have hball : maps_to e (ball 0 1) (ball z r),\n  { refine ((lipschitz_with_line_map z w).maps_to_ball\n      (mt nndist_eq_zero.1 hne) 0 1).mono subset.rfl _,\n    simpa only [line_map_apply_zero, mul_one, coe_nndist] using ball_subset_ball hw },\n  refine norm_max_aux\u2083 hr (diff_on_int_cont.mk_ball\n    (hd.differentiable_on_ball.comp hde.differentiable_on hball)\n    (hd.continuous_on.comp hde.continuous.continuous_on _)) _,\n  { refine ((lipschitz_with_line_map z w).maps_to_closed_ball 0 1).mono_right _,\n    simpa only [line_map_apply_zero, mul_one, coe_nndist] using closed_ball_subset_closed_ball hw },\n  { exact hz.comp_maps_to hball (line_map_apply_zero z w) }\nend\n\n/-!\n### Different forms of the maximum modulus principle\n-/\n\n/-- **Maximum modulus principle**: if `f : E \u2192 F` is complex differentiable on a set `s`, the norm\nof `f` takes it maximum on `s` at `z` and `w` is a point such that the closed ball with center `z`\nand radius `dist w z` is included in `s`, then `\u2225f w\u2225 = \u2225f z\u2225`. -/\nlemma norm_eq_norm_of_is_max_on_of_closed_ball_subset {f : E \u2192 F} {s : set E} {z w : E}\n  (hd : diff_on_int_cont \u2102 f s) (hz : is_max_on (norm \u2218 f) s z)\n  (hsub : closed_ball z (dist w z) \u2286 s) :\n  \u2225f w\u2225 = \u2225f z\u2225 :=\nnorm_eq_on_closed_ball_of_is_max_on (hd.mono hsub)\n  (hz.on_subset $ ball_subset_closed_ball.trans hsub) (mem_closed_ball.2 le_rfl)\n\n/-- **Maximum modulus principle**: if `f : E \u2192 F` is complex differentiable in a neighborhood of `c`\nand the norm `\u2225f z\u2225` has a local maximum at `c`, then `\u2225f z\u2225` is locally constant in a neighborhood\nof `c`. -/\nlemma norm_eventually_eq_of_is_local_max {f : E \u2192 F} {c : E}\n  (hd : \u2200\u1da0 z in \ud835\udcdd c, differentiable_at \u2102 f z) (hc : is_local_max (norm \u2218 f) c) :\n  \u2200\u1da0 y in \ud835\udcdd c, \u2225f y\u2225 = \u2225f c\u2225 :=\nbegin\n  rcases nhds_basis_closed_ball.eventually_iff.1 (hd.and hc) with \u27e8r, hr\u2080, hr\u27e9,\n  exact nhds_basis_closed_ball.eventually_iff.2 \u27e8r, hr\u2080, norm_eq_on_closed_ball_of_is_max_on\n    (differentiable_on.diff_on_int_cont $ \u03bb x hx, (hr hx).1.differentiable_within_at) $\n    \u03bb x hx, (hr $ ball_subset_closed_ball hx).2\u27e9\nend\n\nlemma is_open_set_of_mem_nhds_and_is_max_on_norm {f : E \u2192 F} {s : set E}\n  (hd : differentiable_on \u2102 f s) :\n  is_open {z | s \u2208 \ud835\udcdd z \u2227 is_max_on (norm \u2218 f) s z} :=\nbegin\n  refine is_open_iff_mem_nhds.2 (\u03bb z hz, (eventually_eventually_nhds.2 hz.1).and _),\n  replace hd : \u2200\u1da0 w in \ud835\udcdd z, differentiable_at \u2102 f w, from hd.eventually_differentiable_at hz.1,\n  exact (norm_eventually_eq_of_is_local_max hd $ (hz.2.is_local_max hz.1)).mono\n    (\u03bb x hx y hy, le_trans (hz.2 hy) hx.ge)\nend\n\n/-- **Maximum modulus principle**: if `f : E \u2192 F` is complex differentiable on a nonempty compact\nset `K`, then there exists a point `z \u2208 frontier K` such that `\u03bb z, \u2225f z\u2225` takes it maximum value on\n`K` at `z`. -/\nlemma exists_mem_frontier_is_max_on_norm [nontrivial E] {f : E \u2192 F} {K : set E} (hK : is_compact K)\n  (hne : K.nonempty) (hd : diff_on_int_cont \u2102 f K) :\n  \u2203 z \u2208 frontier K, is_max_on (norm \u2218 f) K z :=\nbegin\n  rcases hK.exists_forall_ge hne hd.continuous_on.norm with \u27e8w, hwK, hle\u27e9,\n  rcases hK.exists_mem_frontier_inf_dist_compl_eq_dist hwK with \u27e8z, hzK, hzw\u27e9,\n  refine \u27e8z, hzK, \u03bb x hx, (hle x hx).trans_eq _\u27e9,\n  refine (norm_eq_norm_of_is_max_on_of_closed_ball_subset hd hle _).symm,\n  calc closed_ball w (dist z w) = closed_ball w (inf_dist w K\u1d9c) : by rw [hzw, dist_comm]\n  ... \u2286 closure K : closed_ball_inf_dist_compl_subset_closure hwK\n  ... = K : hK.is_closed.closure_eq\nend\n\n/-- **Maximum modulus principle**: if `f : E \u2192 F` is complex differentiable on a compact set `K` and\n`\u2225f z\u2225 \u2264 C` for any `z \u2208 frontier K`, then the same is true for any `z \u2208 K`. -/\nlemma norm_le_of_forall_mem_frontier_norm_le [nontrivial E] {f : E \u2192 F} {K : set E}\n  (hK : is_compact K) (hd : diff_on_int_cont \u2102 f K)\n  {C : \u211d} (hC : \u2200 z \u2208 frontier K, \u2225f z\u2225 \u2264 C) {z : E} (hz : z \u2208 K) :\n  \u2225f z\u2225 \u2264 C :=\nlet \u27e8w, hwK, hw\u27e9 := exists_mem_frontier_is_max_on_norm hK \u27e8z, hz\u27e9 hd\nin le_trans (hw hz) (hC w hwK)\n\n/-- If two complex differentiable functions `f g : E \u2192 F` are equal on the boundary of a compact set\n`K`, then they are equal on `K`. -/\nlemma eq_on_of_eq_on_frontier [nontrivial E] {f g : E \u2192 F} {K : set E} (hK : is_compact K)\n  (hf : diff_on_int_cont \u2102 f K) (hg : diff_on_int_cont \u2102 g K) (hfg : eq_on f g (frontier K)) :\n  eq_on f g K :=\nbegin\n  suffices H : \u2200 z \u2208 K, \u2225f z - g z\u2225 \u2264 0, by simpa [sub_eq_zero] using H,\n  convert \u03bb z hz, norm_le_of_forall_mem_frontier_norm_le hK (hf.sub hg) _ hz,\n  simpa [sub_eq_zero]\nend\n\nend complex\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/complex/abs_max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7026857432292077}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Bhavik Mehta\n-/\nimport data.nat.factorial.basic\n\n/-!\n# Binomial coefficients\n\nThis file defines binomial coefficients and proves simple lemmas (i.e. those not\nrequiring more imports).\n\n## Main definition and results\n\n* `nat.choose`: binomial coefficients, defined inductively\n* `nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`\n* `nat.choose_symm`: symmetry of binomial coefficients\n* `nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`\n* `nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`\n* `nat.desc_factorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending\n  factorial. This is used to prove `nat.choose_le_pow` and variants. We provide similar statements\n  for the ascending factorial.\n\n-/\n\nopen_locale nat\n\nnamespace nat\n\n/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial\ncoefficients. -/\ndef choose : \u2115 \u2192 \u2115 \u2192 \u2115\n| _             0 := 1\n| 0       (k + 1) := 0\n| (n + 1) (k + 1) := choose n k + choose n (k + 1)\n\n@[simp] lemma choose_zero_right (n : \u2115) : choose n 0 = 1 := by cases n; refl\n\n@[simp] lemma choose_zero_succ (k : \u2115) : choose 0 (succ k) = 0 := rfl\n\nlemma choose_succ_succ (n k : \u2115) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl\n\nlemma choose_eq_zero_of_lt : \u2200 {n k}, n < k \u2192 choose n k = 0\n| _             0 hk := absurd hk dec_trivial\n| 0       (k + 1) hk := choose_zero_succ _\n| (n + 1) (k + 1) hk :=\n  have hnk : n < k, from lt_of_succ_lt_succ hk,\n  have hnk1 : n < k + 1, from lt_of_succ_lt hk,\n  by rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]\n\n@[simp] lemma choose_self (n : \u2115) : choose n n = 1 :=\nby induction n; simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]\n\n@[simp] lemma choose_succ_self (n : \u2115) : choose n (succ n) = 0 :=\nchoose_eq_zero_of_lt (lt_succ_self _)\n\n@[simp] lemma choose_one_right (n : \u2115) : choose n 1 = n :=\nby induction n; simp [*, choose, add_comm]\n\n/- The `n+1`-st triangle number is `n` more than the `n`-th triangle number -/\nlemma triangle_succ (n : \u2115) : (n + 1) * ((n + 1) - 1) / 2 = n * (n - 1) / 2 + n :=\nbegin\n  rw [\u2190 add_mul_div_left, mul_comm 2 n, \u2190 mul_add, add_tsub_cancel_right, mul_comm],\n  cases n; refl, apply zero_lt_succ\nend\n\n/-- `choose n 2` is the `n`-th triangle number. -/\nlemma choose_two_right (n : \u2115) : choose n 2 = n * (n - 1) / 2 :=\nbegin\n  induction n with n ih,\n  simp,\n  {rw triangle_succ n, simp [choose, ih], rw add_comm},\nend\n\nlemma choose_pos : \u2200 {n k}, k \u2264 n \u2192 0 < choose n k\n| 0             _ hk := by rw [nat.eq_zero_of_le_zero hk]; exact dec_trivial\n| (n + 1)       0 hk := by simp; exact dec_trivial\n| (n + 1) (k + 1) hk := by rw choose_succ_succ;\n    exact add_pos_of_pos_of_nonneg (choose_pos (le_of_succ_le_succ hk)) (nat.zero_le _)\n\nlemma succ_mul_choose_eq : \u2200 n k, succ n * choose n k = choose (succ n) (succ k) * succ k\n| 0             0 := dec_trivial\n| 0       (k + 1) := by simp [choose]\n| (n + 1)       0 := by simp\n| (n + 1) (k + 1) :=\n  by rw [choose_succ_succ (succ n) (succ k), add_mul, \u2190succ_mul_choose_eq, mul_succ,\n  \u2190succ_mul_choose_eq, add_right_comm, \u2190mul_add, \u2190choose_succ_succ, \u2190succ_mul]\n\nlemma choose_mul_factorial_mul_factorial : \u2200 {n k}, k \u2264 n \u2192 choose n k * k! * (n - k)! = n!\n| 0              _ hk := by simp [nat.eq_zero_of_le_zero hk]\n| (n + 1)        0 hk := by simp\n| (n + 1) (succ k) hk :=\nbegin\n  cases lt_or_eq_of_le hk with hk\u2081 hk\u2081,\n  { have h : choose n k * k.succ! * (n-k)! = (k + 1) * n! :=\n      by rw \u2190 choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk);\n      simp [factorial_succ, mul_comm, mul_left_comm],\n    have h\u2081 : (n - k)! = (n - k) * (n - k.succ)! :=\n      by rw [\u2190 succ_sub_succ, succ_sub (le_of_lt_succ hk\u2081), factorial_succ],\n    have h\u2082 : choose n (succ k) * k.succ! * ((n - k) * (n - k.succ)!) = (n - k) * n! :=\n      by rw \u2190 choose_mul_factorial_mul_factorial (le_of_lt_succ hk\u2081);\n      simp [factorial_succ, mul_comm, mul_left_comm, mul_assoc],\n    have h\u2083 : k * n! \u2264 n * n! := nat.mul_le_mul_right _ (le_of_succ_le_succ hk),\n    rw [choose_succ_succ, add_mul, add_mul, succ_sub_succ, h, h\u2081, h\u2082, add_mul,\n      tsub_mul, factorial_succ, \u2190 add_tsub_assoc_of_le h\u2083, add_assoc, \u2190 add_mul,\n      add_tsub_cancel_left, add_comm] },\n  { simp [hk\u2081, mul_comm, choose, tsub_self] }\nend\n\nlemma choose_mul {n k s : \u2115} (hkn : k \u2264 n) (hsk : s \u2264 k) :\n  n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=\nbegin\n  have h : 0 < (n - k)! * (k - s)! * s! :=\n    mul_pos (mul_pos (factorial_pos _) (factorial_pos _)) (factorial_pos _),\n  refine eq_of_mul_eq_mul_right h _,\n  calc\n    n.choose k * k.choose s * ((n - k)! * (k - s)! * s!)\n        = n.choose k * (k.choose s * s! * (k - s)!) * (n - k)!\n        : by rw [mul_assoc, mul_assoc, mul_assoc, mul_assoc _ s!, mul_assoc, mul_comm (n - k)!,\n              mul_comm s!]\n    ... = n!\n        : by rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]\n    ... = n.choose s * s! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!)\n        : by rw [choose_mul_factorial_mul_factorial (tsub_le_tsub_right hkn _),\n              choose_mul_factorial_mul_factorial (hsk.trans hkn)]\n    ... = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s!)\n        : by rw [tsub_tsub_tsub_cancel_right hsk, mul_assoc, mul_left_comm s!, mul_assoc,\n              mul_comm (k - s)!, mul_comm s!, mul_right_comm, \u2190mul_assoc]\nend\n\ntheorem choose_eq_factorial_div_factorial {n k : \u2115} (hk : k \u2264 n) :\n  choose n k = n! / (k! * (n - k)!) :=\nbegin\n  rw [\u2190 choose_mul_factorial_mul_factorial hk, mul_assoc],\n  exact (mul_div_left _ (mul_pos (factorial_pos _) (factorial_pos _))).symm\nend\n\nlemma add_choose (i j : \u2115) : (i + j).choose j = (i + j)! / (i! * j!) :=\nby rw [choose_eq_factorial_div_factorial (nat.le_add_left j i), add_tsub_cancel_right, mul_comm]\n\n\n\ntheorem factorial_mul_factorial_dvd_factorial {n k : \u2115} (hk : k \u2264 n) : k! * (n - k)! \u2223 n! :=\nby rw [\u2190choose_mul_factorial_mul_factorial hk, mul_assoc]; exact dvd_mul_left _ _\n\nlemma factorial_mul_factorial_dvd_factorial_add (i j : \u2115) :\n  i! * j! \u2223 (i + j)! :=\nbegin\n  convert factorial_mul_factorial_dvd_factorial (le.intro rfl),\n  rw add_tsub_cancel_left\nend\n\n@[simp] lemma choose_symm {n k : \u2115} (hk : k \u2264 n) : choose n (n-k) = choose n k :=\nby rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (nat.sub_le _ _),\n  tsub_tsub_cancel_of_le hk, mul_comm]\n\nlemma choose_symm_of_eq_add {n a b : \u2115} (h : n = a + b) : nat.choose n a = nat.choose n b :=\nby { convert nat.choose_symm (nat.le_add_left _ _), rw add_tsub_cancel_right}\n\nlemma choose_symm_add {a b : \u2115} : choose (a+b) a = choose (a+b) b :=\nchoose_symm_of_eq_add rfl\n\nlemma choose_symm_half (m : \u2115) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m :=\nby { apply choose_symm_of_eq_add,\n  rw [add_comm m 1, add_assoc 1 m m, add_comm (2 * m) 1, two_mul m] }\n\nlemma choose_succ_right_eq (n k : \u2115) : choose n (k + 1) * (k + 1) = choose n k * (n - k) :=\nbegin\n  have e : (n+1) * choose n k = choose n k * (k+1) + choose n (k+1) * (k+1),\n    rw [\u2190 right_distrib, \u2190 choose_succ_succ, succ_mul_choose_eq],\n  rw [\u2190 tsub_eq_of_eq_add_rev e, mul_comm, \u2190 mul_tsub, add_tsub_add_eq_tsub_right]\nend\n\n@[simp] lemma choose_succ_self_right : \u2200 (n:\u2115), (n+1).choose n = n+1\n| 0     := rfl\n| (n+1) := by rw [choose_succ_succ, choose_succ_self_right, choose_self]\n\nlemma choose_mul_succ_eq (n k : \u2115) :\n  (n.choose k) * (n + 1) = ((n+1).choose k) * (n + 1 - k) :=\nbegin\n  induction k with k ih, { simp },\n  obtain hk | hk := le_or_lt (k + 1) (n + 1),\n  { rw [choose_succ_succ, add_mul, succ_sub_succ, \u2190choose_succ_right_eq, \u2190succ_sub_succ,\n      mul_tsub, add_tsub_cancel_of_le (nat.mul_le_mul_left _ hk)] },\n  rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), zero_mul, zero_mul],\nend\n\nlemma asc_factorial_eq_factorial_mul_choose (n k : \u2115) :\n  n.asc_factorial k = k! * (n + k).choose k :=\nbegin\n  rw mul_comm,\n  apply mul_right_cancel\u2080 (factorial_ne_zero (n + k - k)),\n  rw [choose_mul_factorial_mul_factorial, add_tsub_cancel_right, \u2190factorial_mul_asc_factorial,\n    mul_comm],\n  exact nat.le_add_left k n,\nend\n\nlemma factorial_dvd_asc_factorial (n k : \u2115) : k! \u2223 n.asc_factorial k :=\n\u27e8(n+k).choose k, asc_factorial_eq_factorial_mul_choose _ _\u27e9\n\nlemma choose_eq_asc_factorial_div_factorial (n k : \u2115) :\n  (n + k).choose k = n.asc_factorial k / k! :=\nbegin\n  apply mul_left_cancel\u2080 (factorial_ne_zero k),\n  rw \u2190asc_factorial_eq_factorial_mul_choose,\n  exact (nat.mul_div_cancel' $ factorial_dvd_asc_factorial _ _).symm,\nend\n\nlemma desc_factorial_eq_factorial_mul_choose (n k : \u2115) : n.desc_factorial k = k! * n.choose k :=\nbegin\n  obtain h | h := nat.lt_or_ge n k,\n  { rw [desc_factorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, mul_zero] },\n  rw mul_comm,\n  apply mul_right_cancel\u2080 (factorial_ne_zero (n - k)),\n  rw [choose_mul_factorial_mul_factorial h, \u2190factorial_mul_desc_factorial h, mul_comm],\nend\n\nlemma factorial_dvd_desc_factorial (n k : \u2115) : k! \u2223 n.desc_factorial k :=\n\u27e8n.choose k, desc_factorial_eq_factorial_mul_choose _ _\u27e9\n\nlemma choose_eq_desc_factorial_div_factorial (n k : \u2115) : n.choose k = n.desc_factorial k / k! :=\nbegin\n  apply mul_left_cancel\u2080 (factorial_ne_zero k),\n  rw \u2190desc_factorial_eq_factorial_mul_choose,\n  exact (nat.mul_div_cancel' $ factorial_dvd_desc_factorial _ _).symm,\nend\n\n/-! ### Inequalities -/\n\n/-- Show that `nat.choose` is increasing for small values of the right argument. -/\nlemma choose_le_succ_of_lt_half_left {r n : \u2115} (h : r < n/2) :\n  choose n r \u2264 choose n (r+1) :=\nbegin\n  refine le_of_mul_le_mul_right _ (lt_tsub_iff_left.mpr (lt_of_lt_of_le h (n.div_le_self 2))),\n  rw \u2190 choose_succ_right_eq,\n  apply nat.mul_le_mul_left,\n  rw [\u2190 nat.lt_iff_add_one_le, lt_tsub_iff_left, \u2190 mul_two],\n  exact lt_of_lt_of_le (mul_lt_mul_of_pos_right h zero_lt_two) (n.div_mul_le_self 2),\nend\n\n/-- Show that for small values of the right argument, the middle value is largest. -/\nprivate lemma choose_le_middle_of_le_half_left {n r : \u2115} (hr : r \u2264 n/2) :\n  choose n r \u2264 choose n (n/2) :=\ndecreasing_induction\n  (\u03bb _ k a,\n      (eq_or_lt_of_le a).elim\n        (\u03bb t, t.symm \u25b8 le_refl _)\n        (\u03bb h, (choose_le_succ_of_lt_half_left h).trans (k h)))\n  hr (\u03bb _, le_rfl) hr\n\n/-- `choose n r` is maximised when `r` is `n/2`. -/\nlemma choose_le_middle (r n : \u2115) : choose n r \u2264 choose n (n/2) :=\nbegin\n  cases le_or_gt r n with b b,\n  { cases le_or_lt r (n/2) with a h,\n    { apply choose_le_middle_of_le_half_left a },\n    { rw \u2190 choose_symm b,\n      apply choose_le_middle_of_le_half_left,\n      rw [div_lt_iff_lt_mul' zero_lt_two] at h,\n      rw [le_div_iff_mul_le' zero_lt_two, tsub_mul, tsub_le_iff_tsub_le,\n          mul_two, add_tsub_cancel_right],\n      exact le_of_lt h } },\n  { rw choose_eq_zero_of_lt b,\n    apply zero_le }\nend\n\n/-! #### Inequalities about increasing the first argument -/\n\nlemma choose_le_succ (a c : \u2115) : choose a c \u2264 choose a.succ c :=\nby cases c; simp [nat.choose_succ_succ]\n\nlemma choose_le_add (a b c : \u2115) : choose a c \u2264 choose (a + b) c :=\nbegin\n  induction b with b_n b_ih,\n  { simp, },\n  exact le_trans b_ih (choose_le_succ (a + b_n) c),\nend\n\nlemma choose_le_choose {a b : \u2115} (c : \u2115) (h : a \u2264 b) : choose a c \u2264 choose b c :=\n(add_tsub_cancel_of_le h) \u25b8 choose_le_add a (b - a) c\n\nlemma choose_mono (b : \u2115) : monotone (\u03bb a, choose a b) := \u03bb _ _, choose_le_choose b\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/choose/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7026857389234933}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport data.nat.sqrt\n\nnamespace int\n\n/-- `sqrt n` is the square root of an integer `n`. If `n` is not a\n  perfect square, and is positive, it returns the largest `k:\u2124` such\n  that `k*k \u2264 n`. If it is negative, it returns 0. For example,\n  `sqrt 2 = 1` and `sqrt 1 = 1` and `sqrt (-1) = 0` -/\n@[pp_nodot] def sqrt (n : \u2124) : \u2124 :=\nnat.sqrt $ int.to_nat n\n\ntheorem sqrt_eq (n : \u2124) : sqrt (n*n) = n.nat_abs :=\nby rw [sqrt, \u2190 nat_abs_mul_self, to_nat_coe_nat, nat.sqrt_eq]\n\ntheorem exists_mul_self (x : \u2124) :\n  (\u2203 n, n * n = x) \u2194 sqrt x * sqrt x = x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, by rw [\u2190 hn, sqrt_eq, \u2190 int.coe_nat_mul, nat_abs_mul_self],\n\u03bb h, \u27e8sqrt x, h\u27e9\u27e9\n\ntheorem sqrt_nonneg (n : \u2124) : 0 \u2264 sqrt n := coe_nat_nonneg _\n\nend int\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/int/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7026857344372991}}
{"text": "/-\nCopyright (c) 2022 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle S\u00f6nne\n-/\nimport analysis.special_functions.log.basic\nimport analysis.special_functions.pow\nimport data.int.log\n\n/-!\n# Real logarithm base `b`\n\nIn this file we define `real.logb` to be the logarithm of a real number in a given base `b`. We\ndefine this as the division of the natural logarithms of the argument and the base, so that we have\na globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and\n`logb (-b) x = logb b x`.\n\nWe prove some basic properties of this function and its relation to `rpow`.\n\n## Tags\n\nlogarithm, continuity\n-/\n\nopen set filter function\nopen_locale topology\nnoncomputable theory\n\nnamespace real\n\nvariables {b x y : \u211d}\n\n/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to\nbe `logb b |x|` for `x < 0`, and `0` for `x = 0`.-/\n@[pp_nodot] noncomputable def logb (b x : \u211d) : \u211d := log x / log b\n\nlemma log_div_log : log x / log b = logb b x := rfl\n\n@[simp] lemma logb_zero : logb b 0 = 0 := by simp [logb]\n\n@[simp] lemma logb_one : logb b 1 = 0 := by simp [logb]\n\n@[simp] lemma logb_abs (x : \u211d) : logb b (|x|) = logb b x := by rw [logb, logb, log_abs]\n\n@[simp] lemma logb_neg_eq_logb (x : \u211d) : logb b (-x) = logb b x :=\nby rw [\u2190 logb_abs x, \u2190 logb_abs (-x), abs_neg]\n\nlemma logb_mul (hx : x \u2260 0) (hy : y \u2260 0) : logb b (x * y) = logb b x + logb b y :=\nby simp_rw [logb, log_mul hx hy, add_div]\n\nlemma logb_div (hx : x \u2260 0) (hy : y \u2260 0) : logb b (x / y) = logb b x - logb b y :=\nby simp_rw [logb, log_div hx hy, sub_div]\n\n@[simp] lemma logb_inv (x : \u211d) : logb b (x\u207b\u00b9) = -logb b x := by simp [logb, neg_div]\n\nsection b_pos_and_ne_one\n\nvariable (b_pos : 0 < b)\nvariable (b_ne_one : b \u2260 1)\ninclude b_pos b_ne_one\n\nprivate lemma log_b_ne_zero : log b \u2260 0 :=\nbegin\n  have b_ne_zero : b \u2260 0, linarith,\n  have b_ne_minus_one : b \u2260 -1, linarith,\n  simp [b_ne_one, b_ne_zero, b_ne_minus_one],\nend\n\n@[simp] lemma logb_rpow :\n  logb b (b ^ x) = x :=\nbegin\n  rw [logb, div_eq_iff, log_rpow b_pos],\n  exact log_b_ne_zero b_pos b_ne_one,\nend\n\nlemma rpow_logb_eq_abs (hx : x \u2260 0) : b ^ (logb b x) = |x| :=\nbegin\n  apply log_inj_on_pos,\n  simp only [set.mem_Ioi],\n  apply rpow_pos_of_pos b_pos,\n  simp only [abs_pos, mem_Ioi, ne.def, hx, not_false_iff],\n  rw [log_rpow b_pos, logb, log_abs],\n  field_simp [log_b_ne_zero b_pos b_ne_one],\nend\n\n@[simp] lemma rpow_logb (hx : 0 < x) : b ^ (logb b x) = x :=\nby { rw rpow_logb_eq_abs b_pos b_ne_one (hx.ne'), exact abs_of_pos hx, }\n\nlemma rpow_logb_of_neg (hx : x < 0) : b ^ (logb b x) = -x :=\nby { rw rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx), exact abs_of_neg hx }\n\nlemma surj_on_logb : surj_on (logb b) (Ioi 0) univ :=\n\u03bb x _, \u27e8rpow b x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one\u27e9\n\nlemma logb_surjective : surjective (logb b) :=\n\u03bb x, \u27e8b ^ x, logb_rpow b_pos b_ne_one\u27e9\n\n@[simp] lemma range_logb : range (logb b) = univ :=\n(logb_surjective b_pos b_ne_one).range_eq\n\nlemma surj_on_logb' : surj_on (logb b) (Iio 0) univ :=\nbegin\n  intros x x_in_univ,\n  use -b ^ x,\n  split,\n  { simp only [right.neg_neg_iff, set.mem_Iio], apply rpow_pos_of_pos b_pos, },\n  { rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one], },\nend\n\nend b_pos_and_ne_one\n\nsection one_lt_b\n\nvariable (hb : 1 < b)\ninclude hb\n\nprivate lemma b_pos : 0 < b := by linarith\n\nprivate \n\n@[simp] lemma logb_le_logb (h : 0 < x) (h\u2081 : 0 < y) :\n  logb b x \u2264 logb b y \u2194 x \u2264 y :=\nby { rw [logb, logb, div_le_div_right (log_pos hb), log_le_log h h\u2081], }\n\nlemma logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y :=\nby { rw [logb, logb, div_lt_div_right (log_pos hb)], exact log_lt_log hx hxy, }\n\n@[simp] lemma logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) :\n  logb b x < logb b y \u2194 x < y :=\nby { rw [logb, logb, div_lt_div_right (log_pos hb)], exact log_lt_log_iff hx hy, }\n\nlemma logb_le_iff_le_rpow (hx : 0 < x) : logb b x \u2264 y \u2194 x \u2264 b ^ y :=\nby rw [\u2190rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hx]\n\nlemma logb_lt_iff_lt_rpow (hx : 0 < x) : logb b x < y \u2194 x < b ^ y :=\nby rw [\u2190rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hx]\n\nlemma le_logb_iff_rpow_le (hy : 0 < y) : x \u2264 logb b y \u2194 b ^ x \u2264 y :=\nby rw [\u2190rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hy]\n\nlemma lt_logb_iff_rpow_lt (hy : 0 < y) : x < logb b y \u2194 b ^ x < y :=\nby rw [\u2190rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one hb) hy]\n\nlemma logb_pos_iff (hx : 0 < x) : 0 < logb b x \u2194 1 < x :=\nby { rw \u2190 @logb_one b, rw logb_lt_logb_iff hb zero_lt_one hx, }\n\nlemma logb_pos (hx : 1 < x) : 0 < logb b x :=\nby { rw logb_pos_iff hb (lt_trans zero_lt_one hx), exact hx, }\n\nlemma logb_neg_iff (h : 0 < x) : logb b x < 0 \u2194 x < 1 :=\nby { rw \u2190 logb_one, exact logb_lt_logb_iff hb h zero_lt_one, }\n\nlemma logb_neg (h0 : 0 < x) (h1 : x < 1) : logb b x < 0 :=\n(logb_neg_iff hb h0).2 h1\n\nlemma logb_nonneg_iff (hx : 0 < x) : 0 \u2264 logb b x \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, logb_neg_iff hb hx, not_lt]\n\nlemma logb_nonneg (hx : 1 \u2264 x) : 0 \u2264 logb b x :=\n(logb_nonneg_iff hb (zero_lt_one.trans_le hx)).2 hx\n\nlemma logb_nonpos_iff (hx : 0 < x) : logb b x \u2264 0 \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, logb_pos_iff hb hx, not_lt]\n\nlemma logb_nonpos_iff' (hx : 0 \u2264 x) : logb b x \u2264 0 \u2194 x \u2264 1 :=\nbegin\n  rcases hx.eq_or_lt with (rfl|hx),\n  { simp [le_refl, zero_le_one] },\n  exact logb_nonpos_iff hb hx,\nend\n\nlemma logb_nonpos (hx : 0 \u2264 x) (h'x : x \u2264 1) : logb b x \u2264 0 :=\n(logb_nonpos_iff' hb hx).2 h'x\n\nlemma strict_mono_on_logb : strict_mono_on (logb b) (set.Ioi 0) :=\n\u03bb x hx y hy hxy, logb_lt_logb hb hx hxy\n\nlemma strict_anti_on_logb : strict_anti_on (logb b) (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 logb_abs y, \u2190 logb_abs x],\n  refine logb_lt_logb hb (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff],\nend\n\nlemma logb_inj_on_pos : set.inj_on (logb b) (set.Ioi 0) :=\n(strict_mono_on_logb hb).inj_on\n\nlemma eq_one_of_pos_of_logb_eq_zero (h\u2081 : 0 < x) (h\u2082 : logb b x = 0) :\nx = 1 :=\nlogb_inj_on_pos hb (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one)\n  (h\u2082.trans real.logb_one.symm)\n\nlemma logb_ne_zero_of_pos_of_ne_one (hx_pos : 0 < x) (hx : x \u2260 1) :\n  logb b x \u2260 0 :=\nmt (eq_one_of_pos_of_logb_eq_zero hb hx_pos) hx\n\nlemma tendsto_logb_at_top : tendsto (logb b) at_top at_top :=\ntendsto.at_top_div_const (log_pos hb) tendsto_log_at_top\n\nend one_lt_b\n\nsection b_pos_and_b_lt_one\n\nvariable (b_pos : 0 < b)\nvariable (b_lt_one : b < 1)\ninclude b_lt_one\n\nprivate lemma b_ne_one : b \u2260 1 := by linarith\n\ninclude b_pos\n\n@[simp] lemma logb_le_logb_of_base_lt_one (h : 0 < x) (h\u2081 : 0 < y) :\n  logb b x \u2264 logb b y \u2194 y \u2264 x :=\nby { rw [logb, logb, div_le_div_right_of_neg (log_neg b_pos b_lt_one), log_le_log h\u2081 h], }\n\nlemma logb_lt_logb_of_base_lt_one (hx : 0 < x) (hxy : x < y) : logb b y < logb b x :=\nby { rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)], exact log_lt_log hx hxy, }\n\n@[simp] lemma logb_lt_logb_iff_of_base_lt_one (hx : 0 < x) (hy : 0 < y) :\n  logb b x < logb b y \u2194 y < x :=\nby { rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)], exact log_lt_log_iff hy hx }\n\nlemma logb_le_iff_le_rpow_of_base_lt_one (hx : 0 < x) : logb b x \u2264 y \u2194 b ^ y \u2264 x :=\nby rw [\u2190rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]\n\nlemma logb_lt_iff_lt_rpow_of_base_lt_one (hx : 0 < x) : logb b x < y \u2194 b ^ y < x :=\nby rw [\u2190rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]\n\nlemma le_logb_iff_rpow_le_of_base_lt_one (hy : 0 < y) : x \u2264 logb b y \u2194 y \u2264 b ^ x :=\nby rw [\u2190rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]\n\nlemma lt_logb_iff_rpow_lt_of_base_lt_one (hy : 0 < y) : x < logb b y \u2194 y < b ^ x :=\nby rw [\u2190rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]\n\nlemma logb_pos_iff_of_base_lt_one (hx : 0 < x) : 0 < logb b x \u2194 x < 1 :=\nby rw [\u2190 @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one zero_lt_one hx]\n\nlemma logb_pos_of_base_lt_one (hx : 0 < x) (hx' : x < 1) : 0 < logb b x :=\nby { rw logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, exact hx', }\n\nlemma logb_neg_iff_of_base_lt_one (h : 0 < x) : logb b x < 0 \u2194 1 < x :=\nby rw [\u2190 @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one h zero_lt_one]\n\nlemma logb_neg_of_base_lt_one (h1 : 1 < x) : logb b x < 0 :=\n(logb_neg_iff_of_base_lt_one b_pos b_lt_one (lt_trans zero_lt_one h1)).2 h1\n\nlemma logb_nonneg_iff_of_base_lt_one (hx : 0 < x) : 0 \u2264 logb b x \u2194 x \u2264 1 :=\nby rw [\u2190 not_lt, logb_neg_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]\n\nlemma logb_nonneg_of_base_lt_one (hx : 0 < x) (hx' : x \u2264 1) : 0 \u2264 logb b x :=\nby {rw [logb_nonneg_iff_of_base_lt_one b_pos b_lt_one hx], exact hx' }\n\nlemma logb_nonpos_iff_of_base_lt_one (hx : 0 < x) : logb b x \u2264 0 \u2194 1 \u2264 x :=\nby rw [\u2190 not_lt, logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]\n\nlemma strict_anti_on_logb_of_base_lt_one : strict_anti_on (logb b) (set.Ioi 0) :=\n\u03bb x hx y hy hxy, logb_lt_logb_of_base_lt_one b_pos b_lt_one hx hxy\n\nlemma strict_mono_on_logb_of_base_lt_one : strict_mono_on (logb b) (set.Iio 0) :=\nbegin\n  rintros x (hx : x < 0) y (hy : y < 0) hxy,\n  rw [\u2190 logb_abs y, \u2190 logb_abs x],\n  refine logb_lt_logb_of_base_lt_one b_pos b_lt_one (abs_pos.2 hy.ne) _,\n  rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff],\nend\n\nlemma logb_inj_on_pos_of_base_lt_one : set.inj_on (logb b) (set.Ioi 0) :=\n(strict_anti_on_logb_of_base_lt_one b_pos b_lt_one).inj_on\n\nlemma eq_one_of_pos_of_logb_eq_zero_of_base_lt_one (h\u2081 : 0 < x) (h\u2082 : logb b x = 0) :\nx = 1 :=\nlogb_inj_on_pos_of_base_lt_one b_pos b_lt_one (set.mem_Ioi.2 h\u2081) (set.mem_Ioi.2 zero_lt_one)\n  (h\u2082.trans real.logb_one.symm)\n\nlemma logb_ne_zero_of_pos_of_ne_one_of_base_lt_one (hx_pos : 0 < x) (hx : x \u2260 1) :\n  logb b x \u2260 0 :=\nmt (eq_one_of_pos_of_logb_eq_zero_of_base_lt_one b_pos b_lt_one hx_pos) hx\n\nlemma tendsto_logb_at_top_of_base_lt_one : tendsto (logb b) at_top at_bot :=\nbegin\n  rw tendsto_at_top_at_bot,\n  intro e,\n  use 1 \u2294 b ^ e,\n  intro a,\n  simp only [and_imp, sup_le_iff],\n  intro ha,\n  rw logb_le_iff_le_rpow_of_base_lt_one b_pos b_lt_one,\n  tauto,\n  exact lt_of_lt_of_le zero_lt_one ha,\nend\n\nend b_pos_and_b_lt_one\n\nlemma floor_logb_nat_cast {b : \u2115} {r : \u211d} (hb : 1 < b) (hr : 0 \u2264 r) : \u230alogb b r\u230b = int.log b r :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [logb_zero, int.log_zero_right, int.floor_zero] },\n  have hb1' : 1 < (b : \u211d) := nat.one_lt_cast.mpr hb,\n  apply le_antisymm,\n  { rw [\u2190int.zpow_le_iff_le_log hb hr, \u2190rpow_int_cast b],\n    refine le_of_le_of_eq _ (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr),\n    exact rpow_le_rpow_of_exponent_le hb1'.le (int.floor_le _) },\n  { rw [int.le_floor, le_logb_iff_rpow_le hb1' hr, rpow_int_cast],\n    exact int.zpow_log_le_self hb hr }\nend\n\nlemma ceil_logb_nat_cast {b : \u2115} {r : \u211d} (hb : 1 < b) (hr : 0 \u2264 r) : \u2308logb b r\u2309 = int.clog b r :=\nbegin\n  obtain rfl | hr := hr.eq_or_lt,\n  { rw [logb_zero, int.clog_zero_right, int.ceil_zero] },\n  have hb1' : 1 < (b : \u211d) := nat.one_lt_cast.mpr hb,\n  apply le_antisymm,\n  { rw [int.ceil_le, logb_le_iff_le_rpow hb1' hr, rpow_int_cast],\n    refine int.self_le_zpow_clog hb r },\n  { rw [\u2190int.le_zpow_iff_clog_le hb hr, \u2190rpow_int_cast b],\n    refine (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr).symm.trans_le _,\n    exact rpow_le_rpow_of_exponent_le hb1'.le (int.le_ceil _) },\nend\n\n@[simp] lemma logb_eq_zero :\n  logb b x = 0 \u2194 b = 0 \u2228 b = 1 \u2228 b = -1 \u2228 x = 0 \u2228 x = 1 \u2228 x = -1 :=\nbegin\n  simp_rw [logb, div_eq_zero_iff, log_eq_zero],\n  tauto,\nend\n\n/- TODO add other limits and continuous API lemmas analogous to those in log.lean -/\n\nopen_locale big_operators\n\nlemma logb_prod {\u03b1 : Type*} (s : finset \u03b1) (f : \u03b1 \u2192 \u211d) (hf : \u2200 x \u2208 s, f x \u2260 0):\n  logb b (\u220f i in s, f i) = \u2211 i in s, logb b (f i) :=\nbegin\n  classical,\n  induction s using finset.induction_on with a s ha ih,\n  { simp },\n  simp only [finset.mem_insert, forall_eq_or_imp] at hf,\n  simp [ha, ih hf.2, logb_mul hf.1 (finset.prod_ne_zero_iff.2 hf.2)],\nend\n\nend real\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/special_functions/log/base.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7026811955362333}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- $\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from by {\n    -- $\\leadstoandfrom \\dfrac {a + b + c} {b + c} + \\dfrac {a + b + c} {a + c} + \\dfrac {a + b + c} {a + b} \\ge \\dfrac 9 2$\n    have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2), from by {\n      calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by {\n        apply add_le_add,\n        apply add_le_add,\n        apply add_le_add,\n        apply div_le_div_of_le_of_pos,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\n        apply add_le_add_left,\nend --Needs more than 2000 tokens!\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- $\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from by {\n    -- $\\leadstoandfrom$\n    have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2), from by {\n      -- adding $3$\n      have h3 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b), from by {\n        rw [div_add_div_same,div_add_div_same,div_add_div_same], ring,\n      },\n      -- as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n      have h4 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) = (9 * (a + b + c)) / ((b + c) + (a + c) + (a + b)), from by {\n        rw [div_add_div_same,div_add_div_same,div_add_div_same], ring,\n      },\n      -- dividing by $3 \\paren {a + b + c}$\n      have h5 : (9 * (a + b + c)) / ((b + c) + (a + c) + (a + b)) = (9 / 2), from by {\n        rw [mul_comm,mul_div_assoc], ring,\n      },\n      show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2), from by {\n        rw h3 at h4, rw h4 at h5, rw h5,\n      },\n    },\n    -- These are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n    have h6 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) = (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) / 3, from by {\n      rw [div_add_div_same,div_add_div_same,div_add_div_same], ring,\n    },\n    have h7 : (9 / 2) = (3 / ((b + c) + (a + c) + (a + b))), from by {\n      rw [mul_comm,mul_div_assoc], ring,\n    },\n    -- From Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n    have h8 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) / 3 \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n      apply arithmetic_mean_never_less_than_harmonic_mean,\n    },\n    show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from by {\n      rw h6 at h2, rw h7 at h8, rw h8 at h2, rw h2,\n    },\n  },\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from h1,\nend\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nbegin\n  -- $\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  have h1 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2), from by {\n    -- $\\leadstoandfrom$\n    have h2 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / 2), from by {\n      -- $\\leadstoandfrom$\n      have h3 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (9 / (2 * (b + c + a))), from by {\n        -- $\\leadstoandfrom$\n        have h4 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n          -- $\\leadstoandfrom$\n          have h5 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n            -- $\\leadstoandfrom$\n            have h6 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n              -- $\\leadstoandfrom$\n              have h7 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                -- $\\leadstoandfrom$\n                have h8 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                  -- $\\leadstoandfrom$\n                  have h9 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                    -- $\\leadstoandfrom$\n                    have h10 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                      -- $\\leadstoandfrom$\n                      have h11 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                        -- $\\leadstoandfrom$\n                        have h12 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                          -- $\\leadstoandfrom$\n                          have h13 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                            -- $\\leadstoandfrom$\n                            have h14 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                              -- $\\leadstoandfrom$\n                              have h15 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                -- $\\leadstoandfrom$\n                                have h16 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                  -- $\\leadstoandfrom$\n                                  have h17 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                    -- $\\leadstoandfrom$\n                                    have h18 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                      -- $\\leadstoandfrom$\n                                      have h19 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                        -- $\\leadstoandfrom$\n                                        have h20 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                          -- $\\leadstoandfrom$\n                                          have h21 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                            -- $\\leadstoandfrom$\n                                            have h22 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                              -- $\\leadstoandfrom$\n                                              have h23 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                                -- $\\leadstoandfrom$\n                                                have h24 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                                  -- $\\leadstoandfrom$\n                                                  have h25 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                                    -- $\\leadstoandfrom$\n                                                    have h26 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                                      -- $\\leadstoandfrom$\n                                                      have h27 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                                        -- $\\leadstoandfrom$\n                                                        have h28 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                                          -- $\\leadstoandfrom$\n                                                          have h29 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / ((b + c) + (a + c) + (a + b))), from by {\n                                                            -- $\\leadsto\nend --Needs more than 2000 tokens!\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  -- Then $A \u2286 S$ and $B \u2286 S$, by power set definition\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB},\n  -- Then $(A \u2229 B) \u2286 A$, by intersection of set is a subset\n  have h2 : (A \u2229 B) \u2286 A, from by apply set.inter_subset_left,\n  -- Then $(A \u2229 B) \u2286 S$, by subset relation is transitive \n  have h3 : (A \u2229 B) \u2286 S, from by {apply set.subset.trans h2 h1.left},\n  -- Hence $(A \u2229 B) \u2208  \ud835\udcab S$, by power set definition\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by {apply set.mem_powerset h3},\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  -- expand the power\n  calc (x + y)^2 = (x+y)*(x+y) : by rw sq\n  -- distributive property of multiplication over addition gives:\n  ... = x*(x+y) + y*(x+y) : by rw add_mul\n  -- applying the above property further gives:\n  ... = x*x + x*y + y*x + y*y : by {rw [mul_comm x (x+y),mul_comm y (x+y)], rw [add_mul,add_mul], ring}\n  -- rearranging the terms using commutativity and adding gives:\n  ... = x^2 + 2*x*y + y^2 : by {repeat {rw \u2190 sq}, rw mul_comm y x, ring}\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  -- Group has Latin Square Property\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by {\n    assume a b : G, use a\u207b\u00b9 * b, obviously, },\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by {\n    assume a b : G, use b * a\u207b\u00b9, obviously, }, \n\n  -- Setting $b = a$, this becomes:\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from \n    assume a : G, h1 a a,\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from\n    assume a : G, h2 a a,\n\n  -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from assume a :G,\n    exists_unique.unique (h3 a) (classical.some_spec (exists_unique.exists (h3 a)))\n    (mul_one a),\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from assume a : G,\n    exists_unique.unique (h4 a) (classical.some_spec (exists_unique.exists (h4 a))) (one_mul a), \n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by {\n    use (1 : G),\n    have h7 : \u2200 e : G, (\u2200 a : G, e * a = a \u2227 a * e = a) \u2192 e = 1, from by {\n      assume (e : G) (hident : \u2200 a : G, e * a = a \u2227 a * e = a),\n      have h8 : \u2200 a : G, e = classical.some (h3 a).exists, from assume (a : G),\n        exists_unique.unique (h3 a) (hident a).right\n        (classical.some_spec (exists_unique.exists (h3 a))), \n      have h9 : \u2200 a : G, e = classical.some (h4 a).exists, from assume (a : G),\n        exists_unique.unique (h4 a) (hident a).left\n        (classical.some_spec (exists_unique.exists (h4 a))),\n      show e = (1 : G), from eq.trans (h9 e) (h6 _),     \n    },\n    exact \u27e8by obviously, h7\u27e9,\n  }\nend\n\n/--`theorem`\nNesbitt's inequality\nLet $a$, $b$ and $c$ be positive real numbers.\n\nThen:\n:$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n\n`proof`\n{{begin-eqn}}\n{{eqn | l = \\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}\n      | o = \\ge\n      | r = \\dfrac 3 2\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac 9 2\n      | c = by adding $3$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}\n      | o = \\ge\n      | r = \\frac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n}}\n{{eqn | ll= \\leadstoandfrom\n      | l = \\frac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3\n      | o = \\ge\n      | r = \\frac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }\n      | c = dividing by $3 \\paren {a + b + c}$\n}}\n{{end-eqn}}\nThese are the arithmetic mean and the harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$.\n\nFrom Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n\nThus Nesbitt's Inequality holds.\n{{qed}}\n\n-/\ntheorem  nesbitt_inequality {a b c : \u211d} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) \u2265 (3 / 2) :=\nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_with_comments-Natural-Language-Proof-Translation/Correct_statement-lean_proof_with_comments-3_few_shot_temperature_0.2_max_tokens_2000_n_3/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395157060208, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.7026769121627418}}
{"text": "@[derive decidable_eq]\ninductive N\n| zero : N\n| succ (n : N) : N\n\nnamespace N\n\ninstance : has_zero N := \u27e8 N.zero \u27e9 \ntheorem zero_eq_zero : zero = 0 := rfl\n\ndef one : N := succ 0\n\ninstance : has_one N := \u27e8 N.one \u27e9 \ntheorem one_eq_one : one = 1 := rfl\n\ndef nat_cast : \u2115 -> N\n| 0 := 0\n| (nat.succ a) := succ (nat_cast a)\n\ndef to_N : N -> \u2115 \n| 0 := 0\n| (N.succ a) := (to_N a) + 1\n\ntheorem eq (a : N) : a = a := rfl\n\ntheorem succ_eq (a b : N) : (succ a = succ b) -> (a = b) :=\nbegin\n  intro h,\n  cases h,\n  refl,\nend\n\ntheorem eq_succ (a b : N) : (a = b) -> (succ a = succ b) :=\nbegin\n  intro h,\n  cases h,\n  refl,\nend\n\ntheorem zero_neq_succ (a : N) : 0 \u2260 succ a := \nbegin\n  intro h,\n  cases h,\nend\n\nend N", "meta": {"author": "Jijasan", "repo": "UselessArithProofs", "sha": "c2e48e9a83b327246ba86debb1ef2fe87919c00d", "save_path": "github-repos/lean/Jijasan-UselessArithProofs", "path": "github-repos/lean/Jijasan-UselessArithProofs/UselessArithProofs-c2e48e9a83b327246ba86debb1ef2fe87919c00d/src/natural/definition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553433, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.702592435784509}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module algebra.covariant_and_contravariant\n! leanprover-community/mathlib commit 2258b40dacd2942571c8ce136215350c702dc78f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Group.Defs\nimport Mathlib.Order.Basic\nimport Mathlib.Order.Monotone.Basic\n\n/-!\n\n# Covariants and contravariants\n\nThis file contains general lemmas and instances to work with the interactions between a relation and\nan action on a Type.\n\nThe intended application is the splitting of the ordering from the algebraic assumptions on the\noperations in the `Ordered[...]` hierarchy.\n\nThe strategy is to introduce two more flexible typeclasses, `CovariantClass` and\n`ContravariantClass`:\n\n* `CovariantClass` models the implication `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone),\n* `ContravariantClass` models the implication `a * b < a * c \u2192 b < c`.\n\nSince `Co(ntra)variantClass` takes as input the operation (typically `(+)` or `(*)`) and the order\nrelation (typically `(\u2264)` or `(<)`), these are the only two typeclasses that I have used.\n\nThe general approach is to formulate the lemma that you are interested in and prove it, with the\n`Ordered[...]` typeclass of your liking.  After that, you convert the single typeclass,\nsay `[OrderedCancelMonoid M]`, into three typeclasses, e.g.\n`[LeftCancelSemigroup M] [PartialOrder M] [CovariantClass M M (Function.swap (*)) (\u2264)]`\nand have a go at seeing if the proof still works!\n\nNote that it is possible to combine several `Co(ntra)variantClass` assumptions together.\nIndeed, the usual ordered typeclasses arise from assuming the pair\n`[CovariantClass M M (*) (\u2264)] [ContravariantClass M M (*) (<)]`\non top of order/algebraic assumptions.\n\nA formal remark is that normally `CovariantClass` uses the `(\u2264)`-relation, while\n`ContravariantClass` uses the `(<)`-relation. This need not be the case in general, but seems to be\nthe most common usage. In the opposite direction, the implication\n```lean\n[Semigroup \u03b1] [PartialOrder \u03b1] [ContravariantClass \u03b1 \u03b1 (*) (\u2264)] => LeftCancelSemigroup \u03b1\n```\nholds -- note the `Co*ntra*` assumption on the `(\u2264)`-relation.\n\n# Formalization notes\n\nWe stick to the convention of using `Function.swap (*)` (or `Function.swap (+)`), for the\ntypeclass assumptions, since `Function.swap` is slightly better behaved than `flip`.\nHowever, sometimes as a **non-typeclass** assumption, we prefer `flip (*)` (or `flip (+)`),\nas it is easier to use.\n\n-/\n\n\n-- TODO: convert `has_exists_mul_of_le`, `has_exists_add_of_le`?\n-- TODO: relationship with `Con/AddCon`\n-- TODO: include equivalence of `LeftCancelSemigroup` with\n-- `Semigroup PartialOrder ContravariantClass \u03b1 \u03b1 (*) (\u2264)`?\n-- TODO : use \u21d2, as per Eric's suggestion?  See\n-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff/near/236148738\n-- for a discussion.\nopen Function\n\nsection Variants\n\nvariable {M N : Type _} (\u03bc : M \u2192 N \u2192 N) (r : N \u2192 N \u2192 Prop)\n\nvariable (M N)\n\n/-- `Covariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `CovariantClass` doc-string for its meaning. -/\ndef Covariant : Prop :=\n  \u2200 (m) {n\u2081 n\u2082}, r n\u2081 n\u2082 \u2192 r (\u03bc m n\u2081) (\u03bc m n\u2082)\n#align covariant Covariant\n\n/-- `Contravariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `ContravariantClass` doc-string for its meaning. -/\ndef Contravariant : Prop :=\n  \u2200 (m) {n\u2081 n\u2082}, r (\u03bc m n\u2081) (\u03bc m n\u2082) \u2192 r n\u2081 n\u2082\n#align contravariant Contravariant\n\n/-- Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`CovariantClass` says that \"the action `\u03bc` preserves the relation `r`.\"\n\nMore precisely, the `CovariantClass` is a class taking two Types `M N`, together with an \"action\"\n`\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the assertion that\nfor all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the pair\n`(n\u2081, n\u2082)`, then, the relation `r` also holds for the pair `(\u03bc m n\u2081, \u03bc m n\u2082)`,\nobtained from `(n\u2081, n\u2082)` by acting upon it by `m`.\n\nIf `m : M` and `h : r n\u2081 n\u2082`, then `CovariantClass.elim m h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`.\n-/\nclass CovariantClass : Prop where\n  /-- For all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the pair\n  `(n\u2081, n\u2082)`, then, the relation `r` also holds for the pair `(\u03bc m n\u2081, \u03bc m n\u2082)` -/\n  protected elim : Covariant M N \u03bc r\n#align covariant_class CovariantClass\n\n/-- Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`ContravariantClass` says that \"if the result of the action `\u03bc` on a pair satisfies the\nrelation `r`, then the initial pair satisfied the relation `r`.\"\n\nMore precisely, the `ContravariantClass` is a class taking two Types `M N`, together with an\n\"action\" `\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the\nassertion that for all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the\npair `(\u03bc m n\u2081, \u03bc m n\u2082)` obtained from `(n\u2081, n\u2082)` by acting upon it by `m`, then, the relation\n`r` also holds for the pair `(n\u2081, n\u2082)`.\n\nIf `m : M` and `h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`, then `ContravariantClass.elim m h : r n\u2081 n\u2082`.\n-/\nclass ContravariantClass : Prop where\n  /-- For all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the\n  pair `(\u03bc m n\u2081, \u03bc m n\u2082)` obtained from `(n\u2081, n\u2082)` by acting upon it by `m`, then, the relation\n  `r` also holds for the pair `(n\u2081, n\u2082)`. -/\n  protected elim : Contravariant M N \u03bc r\n#align contravariant_class ContravariantClass\n\ntheorem rel_iff_cov [CovariantClass M N \u03bc r] [ContravariantClass M N \u03bc r] (m : M) {a b : N} :\n    r (\u03bc m a) (\u03bc m b) \u2194 r a b :=\n  \u27e8ContravariantClass.elim _, CovariantClass.elim _\u27e9\n#align rel_iff_cov rel_iff_cov\n\nsection flip\n\nvariable {M N \u03bc r}\n\ntheorem Covariant.flip (h : Covariant M N \u03bc r) : Covariant M N \u03bc (flip r) :=\n  fun a _ _ hbc \u21a6 h a hbc\n#align covariant.flip Covariant.flip\n\ntheorem Contravariant.flip (h : Contravariant M N \u03bc r) : Contravariant M N \u03bc (flip r) :=\n  fun a _ _ hbc \u21a6 h a hbc\n#align contravariant.flip Contravariant.flip\n\nend flip\n\nsection Covariant\n\nvariable {M N \u03bc r} [CovariantClass M N \u03bc r]\n\ntheorem act_rel_act_of_rel (m : M) {a b : N} (ab : r a b) : r (\u03bc m a) (\u03bc m b) :=\n  CovariantClass.elim _ ab\n#align act_rel_act_of_rel act_rel_act_of_rel\n\n@[to_additive]\ntheorem Group.covariant_iff_contravariant [Group N] :\n    Covariant N N (\u00b7 * \u00b7) r \u2194 Contravariant N N (\u00b7 * \u00b7) r := by\n  refine \u27e8fun h a b c bc \u21a6 ?_, fun h a b c bc \u21a6 ?_\u27e9\n  \u00b7 rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c]\n    exact h a\u207b\u00b9 bc\n  \u00b7 rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c] at bc\n    exact h a\u207b\u00b9 bc\n#align group.covariant_iff_contravariant Group.covariant_iff_contravariant\n#align add_group.covariant_iff_contravariant AddGroup.covariant_iff_contravariant\n\n@[to_additive]\ninstance (priority := 100) Group.covconv [Group N] [CovariantClass N N (\u00b7 * \u00b7) r] :\n    ContravariantClass N N (\u00b7 * \u00b7) r :=\n  \u27e8Group.covariant_iff_contravariant.mp CovariantClass.elim\u27e9\n\n@[to_additive]\ntheorem Group.covariant_swap_iff_contravariant_swap [Group N] :\n    Covariant N N (swap (\u00b7 * \u00b7)) r \u2194 Contravariant N N (swap (\u00b7 * \u00b7)) r := by\n  refine \u27e8fun h a b c bc \u21a6 ?_, fun h a b c bc \u21a6 ?_\u27e9\n  \u00b7 rw [\u2190 mul_inv_cancel_right b a, \u2190 mul_inv_cancel_right c a]\n    exact h a\u207b\u00b9 bc\n  \u00b7 rw [\u2190 mul_inv_cancel_right b a, \u2190 mul_inv_cancel_right c a] at bc\n    exact h a\u207b\u00b9 bc\n#align group.covariant_swap_iff_contravariant_swap Group.covariant_swap_iff_contravariant_swap\n#align add_group.covariant_swap_iff_contravariant_swap AddGroup.covariant_swap_iff_contravariant_swap\n\n\n@[to_additive]\ninstance (priority := 100) Group.covconv_swap [Group N] [CovariantClass N N (swap (\u00b7 * \u00b7)) r] :\n    ContravariantClass N N (swap (\u00b7 * \u00b7)) r :=\n  \u27e8Group.covariant_swap_iff_contravariant_swap.mp CovariantClass.elim\u27e9\n\n\nsection Trans\n\nvariable [IsTrans N r] (m n : M) {a b c d : N}\n\n--  Lemmas with 3 elements.\ntheorem act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (\u03bc m b) c) : r (\u03bc m a) c :=\n  _root_.trans (act_rel_act_of_rel m ab) rl\n#align act_rel_of_rel_of_act_rel act_rel_of_rel_of_act_rel\n\ntheorem rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (\u03bc m a)) : r c (\u03bc m b) :=\n  _root_.trans rr (act_rel_act_of_rel _ ab)\n#align rel_act_of_rel_of_rel_act rel_act_of_rel_of_rel_act\n\nend Trans\n\nend Covariant\n\n--  Lemma with 4 elements.\nsection MEqN\n\nvariable {M N \u03bc r} {mu : N \u2192 N \u2192 N} [IsTrans N r] [i : CovariantClass N N mu r]\n  [i' : CovariantClass N N (swap mu) r] {a b c d : N}\n\ntheorem act_rel_act_of_rel_of_rel (ab : r a b) (cd : r c d) : r (mu a c) (mu b d) :=\n  _root_.trans (@act_rel_act_of_rel _ _ (swap mu) r _ c _ _ ab) (act_rel_act_of_rel b cd)\n#align act_rel_act_of_rel_of_rel act_rel_act_of_rel_of_rel\n\nend MEqN\n\nsection Contravariant\n\nvariable {M N \u03bc r} [ContravariantClass M N \u03bc r]\n\ntheorem rel_of_act_rel_act (m : M) {a b : N} (ab : r (\u03bc m a) (\u03bc m b)) : r a b :=\n  ContravariantClass.elim _ ab\n#align rel_of_act_rel_act rel_of_act_rel_act\n\nsection Trans\n\nvariable [IsTrans N r] (m n : M) {a b c d : N}\n\n--  Lemmas with 3 elements.\ntheorem act_rel_of_act_rel_of_rel_act_rel (ab : r (\u03bc m a) b) (rl : r (\u03bc m b) (\u03bc m c)) :\n    r (\u03bc m a) c :=\n  _root_.trans ab (rel_of_act_rel_act m rl)\n#align act_rel_of_act_rel_of_rel_act_rel act_rel_of_act_rel_of_rel_act_rel\n\ntheorem rel_act_of_act_rel_act_of_rel_act (ab : r (\u03bc m a) (\u03bc m b)) (rr : r b (\u03bc m c)) :\n    r a (\u03bc m c) :=\n  _root_.trans (rel_of_act_rel_act m ab) rr\n#align rel_act_of_act_rel_act_of_rel_act rel_act_of_act_rel_act_of_rel_act\n\nend Trans\n\nend Contravariant\n\nsection Monotone\n\nvariable {\u03b1 : Type _} {M N \u03bc} [Preorder \u03b1] [Preorder N]\n\nvariable {f : N \u2192 \u03b1}\n\n/-- The partial application of a constant to a covariant operator is monotone. -/\ntheorem Covariant.monotone_of_const [CovariantClass M N \u03bc (\u00b7 \u2264 \u00b7)] (m : M) : Monotone (\u03bc m) :=\n  fun _ _ ha \u21a6 CovariantClass.elim m ha\n#align covariant.monotone_of_const Covariant.monotone_of_const\n\n/-- A monotone function remains monotone when composed with the partial application\nof a covariant operator. E.g., `\u2200 (m : \u2115), Monotone f \u2192 Monotone (\u03bb n, f (m + n))`. -/\ntheorem Monotone.covariant_of_const [CovariantClass M N \u03bc (\u00b7 \u2264 \u00b7)] (hf : Monotone f) (m : M) :\n    Monotone fun n \u21a6 f (\u03bc m n) :=\n  fun _ _ x \u21a6 hf (Covariant.monotone_of_const m x)\n#align monotone.covariant_of_const Monotone.covariant_of_const\n\n/-- Same as `Monotone.covariant_of_const`, but with the constant on the other side of\nthe operator.  E.g., `\u2200 (m : \u2115), monotone f \u2192 monotone (\u03bb n, f (n + m))`. -/\ntheorem Monotone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [CovariantClass N N (swap \u03bc) (\u00b7 \u2264 \u00b7)]\n    (hf : Monotone f) (m : N) : Monotone fun n \u21a6 f (\u03bc n m) :=\n  fun _ _ x \u21a6 hf (@Covariant.monotone_of_const _ _ (swap \u03bc) _ _ m _ _ x)\n#align monotone.covariant_of_const' Monotone.covariant_of_const'\n\n/-- Dual of `Monotone.covariant_of_const` -/\ntheorem Antitone.covariant_of_const [CovariantClass M N \u03bc (\u00b7 \u2264 \u00b7)] (hf : Antitone f) (m : M) :\n    Antitone fun n \u21a6 f (\u03bc m n) :=\n  hf.comp_monotone <| Covariant.monotone_of_const m\n#align antitone.covariant_of_const Antitone.covariant_of_const\n\n/-- Dual of `Monotone.covariant_of_const'` -/\ntheorem Antitone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [CovariantClass N N (swap \u03bc) (\u00b7 \u2264 \u00b7)]\n    (hf : Antitone f) (m : N) : Antitone fun n \u21a6 f (\u03bc n m) :=\n  hf.comp_monotone <| @Covariant.monotone_of_const _ _ (swap \u03bc) _ _ m\n#align antitone.covariant_of_const' Antitone.covariant_of_const'\n\nend Monotone\n\ntheorem covariant_le_of_covariant_lt [PartialOrder N] :\n    Covariant M N \u03bc (\u00b7 < \u00b7) \u2192 Covariant M N \u03bc (\u00b7 \u2264 \u00b7) := by\n  intro h a b c bc\n  rcases le_iff_eq_or_lt.mp bc with (rfl | bc)\n  \u00b7 exact rfl.le\n  \u00b7 exact (h _ bc).le\n#align covariant_le_of_covariant_lt covariant_le_of_covariant_lt\n\ntheorem contravariant_lt_of_contravariant_le [PartialOrder N] :\n    Contravariant M N \u03bc (\u00b7 \u2264 \u00b7) \u2192 Contravariant M N \u03bc (\u00b7 < \u00b7) := by\n  refine fun h a b c bc \u21a6 lt_iff_le_and_ne.mpr \u27e8h a bc.le, ?_\u27e9\n  rintro rfl; exact lt_irrefl _ bc\n#align contravariant_lt_of_contravariant_le contravariant_lt_of_contravariant_le\n\ntheorem covariant_le_iff_contravariant_lt [LinearOrder N] :\n    Covariant M N \u03bc (\u00b7 \u2264 \u00b7) \u2194 Contravariant M N \u03bc (\u00b7 < \u00b7) :=\n  \u27e8fun h _ _ _ bc \u21a6 not_le.mp fun k \u21a6 not_le.mpr bc (h _ k),\n   fun h _ _ _ bc \u21a6 not_lt.mp fun k \u21a6 not_lt.mpr bc (h _ k)\u27e9\n#align covariant_le_iff_contravariant_lt covariant_le_iff_contravariant_lt\n\ntheorem covariant_lt_iff_contravariant_le [LinearOrder N] :\n    Covariant M N \u03bc (\u00b7 < \u00b7) \u2194 Contravariant M N \u03bc (\u00b7 \u2264 \u00b7) :=\n  \u27e8fun h _ _ _ bc \u21a6 not_lt.mp fun k \u21a6 not_lt.mpr bc (h _ k),\n   fun h _ _ _ bc \u21a6 not_le.mp fun k \u21a6 not_le.mpr bc (h _ k)\u27e9\n#align covariant_lt_iff_contravariant_le covariant_lt_iff_contravariant_le\n\n-- Porting note: `covariant_flip_mul_iff` used to use the `IsSymmOp` typeclass from Lean 3 core.\n-- To avoid it, we prove the relevant lemma here.\n@[to_additive]\nlemma flip_mul [CommSemigroup N] : (flip (\u00b7 * \u00b7) : N \u2192 N \u2192 N) = (\u00b7 * \u00b7) :=\n  funext fun a \u21a6 funext fun b \u21a6 mul_comm b a\n\n@[to_additive]\ntheorem covariant_flip_mul_iff [CommSemigroup N] :\n    Covariant N N (flip (\u00b7 * \u00b7)) r \u2194 Covariant N N (\u00b7 * \u00b7) r := by rw [flip_mul]\n#align covariant_flip_mul_iff covariant_flip_mul_iff\n#align covariant_flip_add_iff covariant_flip_add_iff\n\n@[to_additive]\ntheorem contravariant_flip_mul_iff [CommSemigroup N] :\n    Contravariant N N (flip (\u00b7 * \u00b7)) r \u2194 Contravariant N N (\u00b7 * \u00b7) r := by rw [flip_mul]\n#align contravariant_flip_mul_iff contravariant_flip_mul_iff\n#align contravariant_flip_add_iff contravariant_flip_add_iff\n\n@[to_additive]\ninstance contravariant_mul_lt_of_covariant_mul_le [Mul N] [LinearOrder N]\n    [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7) where\n  elim := (covariant_le_iff_contravariant_lt N N (\u00b7 * \u00b7)).mp CovariantClass.elim\n\n@[to_additive]\ninstance covariant_mul_lt_of_contravariant_mul_le [Mul N] [LinearOrder N]\n    [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : CovariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7) where\n  elim := (covariant_lt_iff_contravariant_le N N (\u00b7 * \u00b7)).mpr ContravariantClass.elim\n\n@[to_additive]\ninstance covariant_swap_mul_le_of_covariant_mul_le [CommSemigroup N] [LE N]\n    [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7) where\n  elim := (covariant_flip_mul_iff N (\u00b7 \u2264 \u00b7)).mpr CovariantClass.elim\n\n@[to_additive]\ninstance contravariant_swap_mul_le_of_contravariant_mul_le [CommSemigroup N] [LE N]\n    [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7) where\n  elim := (contravariant_flip_mul_iff N (\u00b7 \u2264 \u00b7)).mpr ContravariantClass.elim\n\n@[to_additive]\ninstance contravariant_swap_mul_lt_of_contravariant_mul_lt [CommSemigroup N] [LT N]\n    [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)] : ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7) where\n  elim := (contravariant_flip_mul_iff N (\u00b7 < \u00b7)).mpr ContravariantClass.elim\n\n@[to_additive]\ninstance covariant_swap_mul_lt_of_covariant_mul_lt [CommSemigroup N] [LT N]\n    [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)] : CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7) where\n  elim := (covariant_flip_mul_iff N (\u00b7 < \u00b7)).mpr CovariantClass.elim\n\n@[to_additive]\ninstance LeftCancelSemigroup.covariant_mul_lt_of_covariant_mul_le [LeftCancelSemigroup N]\n    [PartialOrder N] [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] :\n    CovariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7) where\n  elim a b c bc := by\n    cases' lt_iff_le_and_ne.mp bc with bc cb\n    exact lt_iff_le_and_ne.mpr \u27e8CovariantClass.elim a bc, (mul_ne_mul_right a).mpr cb\u27e9\n\n@[to_additive]\ninstance RightCancelSemigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le\n    [RightCancelSemigroup N] [PartialOrder N] [CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)] :\n    CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7) where\n  elim a b c bc := by\n    cases' lt_iff_le_and_ne.mp bc with bc cb\n    exact lt_iff_le_and_ne.mpr \u27e8CovariantClass.elim a bc, (mul_ne_mul_left a).mpr cb\u27e9\n\n@[to_additive]\ninstance LeftCancelSemigroup.contravariant_mul_le_of_contravariant_mul_lt [LeftCancelSemigroup N]\n    [PartialOrder N] [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)] :\n    ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7) where\n  elim a b c bc := by\n    cases' le_iff_eq_or_lt.mp bc with h h\n    \u00b7 exact ((mul_right_inj a).mp h).le\n    \u00b7 exact (ContravariantClass.elim _ h).le\n\n@[to_additive]\ninstance RightCancelSemigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt\n    [RightCancelSemigroup N] [PartialOrder N] [ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)] :\n    ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7) where\n  elim a b c bc := by\n    cases' le_iff_eq_or_lt.mp bc with h h\n    \u00b7 exact ((mul_left_inj a).mp h).le\n    \u00b7 exact (ContravariantClass.elim _ h).le\n\nend Variants\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/CovariantAndContravariant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553433, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.702592435784509}}
{"text": "/-\nCopyright (c) 2019 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro\n-/\n\nimport data.rat.order\nimport data.int.sqrt\n/-!\n# Square root on rational numbers\n\nThis file defines the square root function on rational numbers `rat.sqrt`\nand proves several theorems about it.\n\n-/\nnamespace rat\n\n/-- Square root function on rational numbers, defined by taking the (integer) square root of the\nnumerator and the square root (on natural numbers) of the denominator. -/\n@[pp_nodot] def sqrt (q : \u211a) : \u211a := rat.mk (int.sqrt q.num) (nat.sqrt q.denom)\n\ntheorem sqrt_eq (q : \u211a) : rat.sqrt (q*q) = abs q :=\nby rw [sqrt, mul_self_num, mul_self_denom, int.sqrt_eq, nat.sqrt_eq, abs_def]\n\ntheorem exists_mul_self (x : \u211a) : (\u2203 q, q * q = x) \u2194 rat.sqrt x * rat.sqrt x = x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, by rw [\u2190 hn, sqrt_eq, abs_mul_abs_self],\n\u03bb h, \u27e8rat.sqrt x, h\u27e9\u27e9\n\ntheorem sqrt_nonneg (q : \u211a) : 0 \u2264 rat.sqrt q :=\nnonneg_iff_zero_le.1 $ (mk_nonneg _ $ int.coe_nat_pos.2 $\nnat.pos_of_ne_zero $ \u03bb H, pos_iff_ne_zero.1 q.pos $ nat.sqrt_eq_zero.1 H).2\n$ int.coe_nat_nonneg _\n\nend rat\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/rat/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7025924336423627}}
{"text": "/-\nCopyright (c) 2022 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport model_theory.semantics\n\n/-!\n# Ordered First-Ordered Structures\nThis file defines ordered first-order languages and structures, as well as their theories.\n\n## Main Definitions\n* `first_order.language.order` is the language consisting of a single relation representing `\u2264`.\n* `first_order.language.order_Structure` is the structure on an ordered type, assigning the symbol\nrepresenting `\u2264` to the actual relation `\u2264`.\n* `first_order.language.is_ordered` points out a specific symbol in a language as representing `\u2264`.\n* `first_order.language.ordered_structure` indicates that the `\u2264` symbol in an ordered language\nis interpreted as the actual relation `\u2264` in a particular structure.\n* `first_order.language.linear_order_theory` and similar define the theories of preorders,\npartial orders, and linear orders.\n* `first_order.language.DLO` defines the theory of dense linear orders without endpoints, a\nparticularly useful example in model theory.\n\n## Main Results\n* `partial_order`s model the theory of partial orders, `linear_order`s model the theory of\nlinear orders, and dense linear orders without endpoints model `Theory.DLO`.\n\n-/\n\nuniverses u v w w'\n\nnamespace first_order\nnamespace language\nopen_locale first_order\nopen Structure\n\nvariables {L : language.{u v}} {\u03b1 : Type w} {M : Type w'} {n : \u2115}\n\n/-- The language consisting of a single relation representing `\u2264`. -/\nprotected def order : language :=\nlanguage.mk\u2082 empty empty empty empty unit\n\ninstance order_Structure [has_le M] : language.order.Structure M :=\nStructure.mk\u2082 empty.elim empty.elim empty.elim empty.elim (\u03bb _, (\u2264))\n\nnamespace order\n\ninstance : is_relational (language.order) := language.is_relational_mk\u2082\n\ninstance : subsingleton (language.order.relations n) :=\nlanguage.subsingleton_mk\u2082_relations\n\nend order\n\n/-- A language is ordered if it has a symbol representing `\u2264`. -/\nclass is_ordered (L : language.{u v}) := (le_symb : L.relations 2)\n\nexport is_ordered (le_symb)\n\nsection is_ordered\n\nvariables [is_ordered L]\n\n/-- Joins two terms `t\u2081, t\u2082` in a formula representing `t\u2081 \u2264 t\u2082`. -/\ndef term.le (t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)) : L.bounded_formula \u03b1 n :=\nle_symb.bounded_formula\u2082 t\u2081 t\u2082\n\n/-- Joins two terms `t\u2081, t\u2082` in a formula representing `t\u2081 < t\u2082`. -/\ndef term.lt (t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)) : L.bounded_formula \u03b1 n :=\n(t\u2081.le t\u2082) \u2293 \u223c (t\u2082.le t\u2081)\n\nvariable (L)\n\n/-- The language homomorphism sending the unique symbol `\u2264` of `language.order` to `\u2264` in an ordered\n language. -/\ndef order_Lhom : language.order \u2192\u1d38 L :=\nLhom.mk\u2082 empty.elim empty.elim empty.elim empty.elim (\u03bb _, le_symb)\n\nend is_ordered\n\ninstance : is_ordered language.order := \u27e8unit.star\u27e9\n\n@[simp] lemma order_Lhom_le_symb [L.is_ordered] :\n  (order_Lhom L).on_relation le_symb = (le_symb : L.relations 2) := rfl\n\n@[simp]\nlemma order_Lhom_order : order_Lhom language.order = Lhom.id language.order :=\nLhom.funext (subsingleton.elim _ _) (subsingleton.elim _ _)\n\ninstance : is_ordered (L.sum language.order) := \u27e8sum.inr is_ordered.le_symb\u27e9\n\nsection\nvariables (L) [is_ordered L]\n\n/-- The theory of preorders. -/\ndef preorder_theory : L.Theory :=\n{le_symb.reflexive, le_symb.transitive}\n\n/-- The theory of partial orders. -/\ndef partial_order_theory : L.Theory :=\n{le_symb.reflexive, le_symb.antisymmetric, le_symb.transitive}\n\n/-- The theory of linear orders. -/\ndef linear_order_theory : L.Theory :=\n{le_symb.reflexive, le_symb.antisymmetric, le_symb.transitive, le_symb.total}\n\n/-- A sentence indicating that an order has no top element:\n$\\forall x, \\exists y, \\neg y \\le x$.   -/\ndef no_top_order_sentence : L.sentence := \u2200' \u2203' \u223c ((&1).le &0)\n\n/-- A sentence indicating that an order has no bottom element:\n$\\forall x, \\exists y, \\neg x \\le y$. -/\ndef no_bot_order_sentence : L.sentence := \u2200' \u2203' \u223c ((&0).le &1)\n\n/-- A sentence indicating that an order is dense:\n$\\forall x, \\forall y, x < y \\to \\exists z, x < z \\wedge z < y$. -/\ndef densely_ordered_sentence : L.sentence :=\n\u2200' \u2200' (((&0).lt &1) \u27f9 (\u2203' (((&0).lt &2) \u2293 ((&2).lt &1))))\n\n/-- The theory of dense linear orders without endpoints. -/\ndef DLO : L.Theory :=\nL.linear_order_theory \u222a\n  {L.no_top_order_sentence, L.no_bot_order_sentence, L.densely_ordered_sentence}\n\nend\n\nvariables (L M)\n\n/-- A structure is ordered if its language has a `\u2264` symbol whose interpretation is -/\nabbreviation ordered_structure [is_ordered L] [has_le M] [L.Structure M] : Prop :=\nLhom.is_expansion_on (order_Lhom L) M\n\nvariables {L M}\n\n@[simp] lemma ordered_structure_iff [is_ordered L] [has_le M] [L.Structure M] :\n  L.ordered_structure M \u2194 Lhom.is_expansion_on (order_Lhom L) M := iff.rfl\n\ninstance ordered_structure_has_le [has_le M] :\n  ordered_structure language.order M :=\nbegin\n  rw [ordered_structure_iff, order_Lhom_order],\n  exact Lhom.id_is_expansion_on M,\nend\n\ninstance model_preorder [preorder M] :\n  M \u22a8 language.order.preorder_theory :=\nbegin\n  simp only [preorder_theory, Theory.model_iff, set.mem_insert_iff, set.mem_singleton_iff,\n    forall_eq_or_imp, relations.realize_reflexive, rel_map_apply\u2082, forall_eq,\n    relations.realize_transitive],\n  exact \u27e8le_refl, \u03bb _ _ _, le_trans\u27e9\nend\n\ninstance model_partial_order [partial_order M] :\n  M \u22a8 language.order.partial_order_theory :=\nbegin\n  simp only [partial_order_theory, Theory.model_iff, set.mem_insert_iff, set.mem_singleton_iff,\n    forall_eq_or_imp, relations.realize_reflexive, rel_map_apply\u2082, relations.realize_antisymmetric,\n    forall_eq, relations.realize_transitive],\n  exact \u27e8le_refl, \u03bb _ _, le_antisymm, \u03bb _ _ _, le_trans\u27e9,\nend\n\ninstance model_linear_order [linear_order M] :\n  M \u22a8 language.order.linear_order_theory :=\nbegin\n  simp only [linear_order_theory, Theory.model_iff, set.mem_insert_iff, set.mem_singleton_iff,\n    forall_eq_or_imp, relations.realize_reflexive, rel_map_apply\u2082, relations.realize_antisymmetric,\n    relations.realize_transitive, forall_eq, relations.realize_total],\n  exact \u27e8le_refl, \u03bb _ _, le_antisymm, \u03bb _ _ _, le_trans, le_total\u27e9,\nend\n\nsection ordered_structure\nvariables [is_ordered L] [L.Structure M]\n\n@[simp] lemma rel_map_le_symb [has_le M] [L.ordered_structure M] {a b : M} :\n  rel_map (le_symb : L.relations 2) ![a, b] \u2194 a \u2264 b :=\nbegin\n  rw [\u2190 order_Lhom_le_symb, Lhom.map_on_relation],\n  refl,\nend\n\n@[simp] lemma term.realize_le [has_le M] [L.ordered_structure M]\n  {t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)} {v : \u03b1 \u2192 M} {xs : fin n \u2192 M} :\n  (t\u2081.le t\u2082).realize v xs \u2194 t\u2081.realize (sum.elim v xs) \u2264 t\u2082.realize (sum.elim v xs) :=\nby simp [term.le]\n\n@[simp] lemma term.realize_lt [preorder M] [L.ordered_structure M]\n  {t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)} {v : \u03b1 \u2192 M} {xs : fin n \u2192 M} :\n  (t\u2081.lt t\u2082).realize v xs \u2194 t\u2081.realize (sum.elim v xs) < t\u2082.realize (sum.elim v xs) :=\nby simp [term.lt, lt_iff_le_not_le]\n\nend ordered_structure\n\nsection has_le\nvariables [has_le M]\n\ntheorem realize_no_top_order_iff : M \u22a8 language.order.no_top_order_sentence \u2194 no_top_order M :=\nbegin\n  simp only [no_top_order_sentence, sentence.realize, formula.realize, bounded_formula.realize_all,\n    bounded_formula.realize_ex, bounded_formula.realize_not, realize, term.realize_le,\n    sum.elim_inr],\n  refine \u27e8\u03bb h, \u27e8\u03bb a, h a\u27e9, _\u27e9,\n  introsI h a,\n  exact exists_not_le a,\nend\n\n@[simp] lemma realize_no_top_order [h : no_top_order M] :\n  M \u22a8 language.order.no_top_order_sentence :=\nrealize_no_top_order_iff.2 h\n\ntheorem realize_no_bot_order_iff : M \u22a8 language.order.no_bot_order_sentence \u2194 no_bot_order M :=\nbegin\n  simp only [no_bot_order_sentence, sentence.realize, formula.realize, bounded_formula.realize_all,\n    bounded_formula.realize_ex, bounded_formula.realize_not, realize, term.realize_le,\n    sum.elim_inr],\n  refine \u27e8\u03bb h, \u27e8\u03bb a, h a\u27e9, _\u27e9,\n  introsI h a,\n  exact exists_not_ge a,\nend\n\n@[simp] lemma realize_no_bot_order [h : no_bot_order M] :\n  M \u22a8 language.order.no_bot_order_sentence :=\nrealize_no_bot_order_iff.2 h\n\nend has_le\n\ntheorem realize_densely_ordered_iff [preorder M] :\n  M \u22a8 language.order.densely_ordered_sentence \u2194 densely_ordered M :=\nbegin\n  simp only [densely_ordered_sentence, sentence.realize, formula.realize,\n    bounded_formula.realize_imp, bounded_formula.realize_all, realize, term.realize_lt,\n    sum.elim_inr, bounded_formula.realize_ex, bounded_formula.realize_inf],\n  refine \u27e8\u03bb h, \u27e8\u03bb a b ab, h a b ab\u27e9, _\u27e9,\n  introsI h a b ab,\n  exact exists_between ab,\nend\n\n@[simp] lemma realize_densely_ordered [preorder M] [h : densely_ordered M] :\n  M \u22a8 language.order.densely_ordered_sentence :=\nrealize_densely_ordered_iff.2 h\n\ninstance model_DLO [linear_order M] [densely_ordered M] [no_top_order M] [no_bot_order M] :\n  M \u22a8 language.order.DLO :=\nbegin\n  simp only [DLO, set.union_insert, set.union_singleton, Theory.model_iff,\n    set.mem_insert_iff, forall_eq_or_imp, realize_no_top_order, realize_no_bot_order,\n    realize_densely_ordered, true_and],\n  rw \u2190 Theory.model_iff,\n  apply_instance,\nend\n\nend language\nend first_order\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/model_theory/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7025924290915572}}
{"text": "import topology.subset_properties\n\n/-\nIn this problem you will look at proving that the image of a compact set in a topological space\nalong a continuous map is also compact.\n\nSome things you should know:\n- A subset of a space `X` is an element of the type `set X` in Lean\n- The notation for image of a set `U` along a map `f` is `f '' U`\n- The simplifier `simp,`,\n  is very useful, especially simplifying your hypotheses  `simp at ht` !\n  You can use `simp at *,` to simplify as much as possible everywhere\n- there is a new helpful lemma in the sidebar\n-/\n/- Hint : click here for the first few lines of the proof\n```\nrw is_compact_iff_finite_subcover, -- rewrite the definition of compactness\nrw is_compact_iff_finite_subcover at h,  -- rewrite the definition of compactness\nintros \u03b9 V hV hVu, -- we are proving a forall, so introduce everything\nobtain \u27e8t, ht\u27e9 := h (\u03bb i, f \u207b\u00b9' (V i)) _ _, -- pull back the open sets from Y to X\n```\n-/\n/- Axiom : continuous.is_open_preimage : \u2200 {\u03b1 \u03b2 : Type} [_inst_1 : topological_space \u03b1]\n  [_inst_2 : topological_space \u03b2] {f : \u03b1 \u2192 \u03b2},\n  continuous f \u2192 \u2200 (s : set \u03b2), is_open s \u2192 is_open (f \u207b\u00b9' s)\n-/\n/- Lemma :\n-/\nlemma image_compact\n  (X : Type)\n  [topological_space X]\n  (V : set X)\n  (h : is_compact V)\n  (Y : Type)\n  [topological_space Y]\n  (f : X \u2192 Y)\n  (hf : continuous f) :\n  is_compact (f '' V) :=\nbegin\n  rw is_compact_iff_finite_subcover,\n  rw is_compact_iff_finite_subcover at h,\n  intros \u03b9 V hV hVu,\n  obtain \u27e8t, ht\u27e9 := h (\u03bb i, f \u207b\u00b9' (V i)) _ _,\n  use t,\n  simp [ht],\n  intro i,\n  simp,\n  apply continuous.is_open_preimage hf (V i) (hV i),\n  simp at hVu,\n  simp [hVu],\nend\n", "meta": {"author": "alexjbest", "repo": "CAP-game", "sha": "d823def7325d7142d61e766b2e027f936685a8ff", "save_path": "github-repos/lean/alexjbest-CAP-game", "path": "github-repos/lean/alexjbest-CAP-game/CAP-game-d823def7325d7142d61e766b2e027f936685a8ff/src/advanced/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7025924272159231}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Johannes H\u00f6lzl, Mario Carneiro\n-/\nimport data.int.basic\n\n/-!\n# Square root of natural numbers\n\nThis file defines an efficient binary implementation of the square root function that returns the\nunique `r` such that `r * r \u2264 n < (r + 1) * (r + 1)`. It takes advantage of the binary\nrepresentation by replacing the multiplication by 2 appearing in\n`(a + b)^2 = a^2 + 2 * a * b + b^2` by a bitmask manipulation.\n\n## Reference\n\nSee [Wikipedia, *Methods of computing square roots*]\n[https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)].\n-/\nnamespace nat\n\ntheorem sqrt_aux_dec {b} (h : b \u2260 0) : shiftr b 2 < b :=\nbegin\n  simp only [shiftr_eq_div_pow],\n  apply (nat.div_lt_iff_lt_mul' (dec_trivial : 0 < 4)).2,\n  have := nat.mul_lt_mul_of_pos_left\n    (dec_trivial : 1 < 4) (nat.pos_of_ne_zero h),\n  rwa mul_one at this\nend\n\n/-- Auxiliary function for `nat.sqrt`. See e.g.\n<https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)> -/\ndef sqrt_aux : \u2115 \u2192 \u2115 \u2192 \u2115 \u2192 \u2115\n| b r n := if b0 : b = 0 then r else\n  let b' := shiftr b 2 in\n  have b' < b, from sqrt_aux_dec b0,\n  match (n - (r + b : \u2115) : \u2124) with\n  | (n' : \u2115) := sqrt_aux b' (div2 r + b) n'\n  | _ := sqrt_aux b' (div2 r) n\n  end\n\n/-- `sqrt n` is the square root of a natural number `n`. If `n` is not a\n  perfect square, it returns the largest `k:\u2115` such that `k*k \u2264 n`. -/\n@[pp_nodot] def sqrt (n : \u2115) : \u2115 :=\nmatch size n with\n| 0      := 0\n| succ s := sqrt_aux (shiftl 1 (bit0 (div2 s))) 0 n\nend\n\ntheorem sqrt_aux_0 (r n) : sqrt_aux 0 r n = r :=\nby rw sqrt_aux; simp\nlocal attribute [simp] sqrt_aux_0\n\ntheorem sqrt_aux_1 {r n b} (h : b \u2260 0) {n'} (h\u2082 : r + b + n' = n) :\n  sqrt_aux b r n = sqrt_aux (shiftr b 2) (div2 r + b) n' :=\nby rw sqrt_aux; simp only [h, h\u2082.symm, int.coe_nat_add, if_false];\n   rw [add_comm _ (n':\u2124), add_sub_cancel, sqrt_aux._match_1]\n\ntheorem sqrt_aux_2 {r n b} (h : b \u2260 0) (h\u2082 : n < r + b) :\n  sqrt_aux b r n = sqrt_aux (shiftr b 2) (div2 r) n :=\nbegin\n  rw sqrt_aux; simp only [h, h\u2082, if_false],\n  cases int.eq_neg_succ_of_lt_zero\n    (sub_lt_zero.2 (int.coe_nat_lt_coe_nat_of_lt h\u2082)) with k e,\n  rw [e, sqrt_aux._match_1]\nend\n\nprivate def is_sqrt (n q : \u2115) : Prop := q*q \u2264 n \u2227 n < (q+1)*(q+1)\n\nlocal attribute [-simp] mul_eq_mul_left_iff mul_eq_mul_right_iff\n\nprivate lemma sqrt_aux_is_sqrt_lemma (m r n : \u2115)\n  (h\u2081 : r*r \u2264 n)\n  (m') (hm : shiftr (2^m * 2^m) 2 = m')\n  (H1 : n < (r + 2^m) * (r + 2^m) \u2192\n    is_sqrt n (sqrt_aux m' (r * 2^m) (n - r * r)))\n  (H2 : (r + 2^m) * (r + 2^m) \u2264 n \u2192\n    is_sqrt n (sqrt_aux m' ((r + 2^m) * 2^m) (n - (r + 2^m) * (r + 2^m)))) :\n  is_sqrt n (sqrt_aux (2^m * 2^m) ((2*r)*2^m) (n - r*r)) :=\nbegin\n  have b0 :=\n    have b0:_, from ne_of_gt (pow_pos (show 0 < 2, from dec_trivial) m),\n    nat.mul_ne_zero b0 b0,\n  have lb : n - r * r < 2 * r * 2^m + 2^m * 2^m \u2194\n            n < (r+2^m)*(r+2^m),\n  { rw [tsub_lt_iff_right h\u2081],\n    simp [left_distrib, right_distrib, two_mul, mul_comm, mul_assoc,\n      add_comm, add_assoc, add_left_comm] },\n  have re : div2 (2 * r * 2^m) = r * 2^m,\n  { rw [div2_val, mul_assoc,\n        nat.mul_div_cancel_left _ (dec_trivial:2>0)] },\n  cases lt_or_ge n ((r+2^m)*(r+2^m)) with hl hl,\n  { rw [sqrt_aux_2 b0 (lb.2 hl), hm, re], apply H1 hl },\n  { cases le.dest hl with n' e,\n    rw [@sqrt_aux_1 (2 * r * 2^m) (n-r*r) (2^m * 2^m) b0 (n - (r + 2^m) * (r + 2^m)),\n      hm, re, \u2190 right_distrib],\n    { apply H2 hl },\n    apply eq.symm, apply tsub_eq_of_eq_add_rev,\n    rw [\u2190 add_assoc, (_ : r*r + _ = _)],\n    exact (add_tsub_cancel_of_le hl).symm,\n    simp [left_distrib, right_distrib, two_mul, mul_comm, mul_assoc, add_assoc] },\nend\n\nprivate lemma sqrt_aux_is_sqrt (n) : \u2200 m r,\n  r*r \u2264 n \u2192 n < (r + 2^(m+1)) * (r + 2^(m+1)) \u2192\n  is_sqrt n (sqrt_aux (2^m * 2^m) (2*r*2^m) (n - r*r))\n| 0 r h\u2081 h\u2082 := by apply sqrt_aux_is_sqrt_lemma 0 r n h\u2081 0 rfl;\n  intro h; simp; [exact \u27e8h\u2081, h\u27e9, exact \u27e8h, h\u2082\u27e9]\n| (m+1) r h\u2081 h\u2082 := begin\n    apply sqrt_aux_is_sqrt_lemma\n      (m+1) r n h\u2081 (2^m * 2^m)\n      (by simp [shiftr, pow_succ, div2_val, mul_comm, mul_left_comm];\n          repeat {rw @nat.mul_div_cancel_left _ 2 dec_trivial});\n      intro h,\n    { have := sqrt_aux_is_sqrt m r h\u2081 h,\n      simpa [pow_succ, mul_comm, mul_assoc] },\n    { rw [pow_succ', mul_two, \u2190 add_assoc] at h\u2082,\n      have := sqrt_aux_is_sqrt m (r + 2^(m+1)) h h\u2082,\n      rwa show (r + 2^(m + 1)) * 2^(m+1) = 2 * (r + 2^(m + 1)) * 2^m,\n          by simp [pow_succ, mul_comm, mul_left_comm] }\n  end\n\nprivate lemma sqrt_is_sqrt (n : \u2115) : is_sqrt n (sqrt n) :=\nbegin\n  generalize e : size n = s, cases s with s; simp [e, sqrt],\n  { rw [size_eq_zero.1 e, is_sqrt], exact dec_trivial },\n  { have := sqrt_aux_is_sqrt n (div2 s) 0 (zero_le _),\n    simp [show 2^div2 s * 2^div2 s = shiftl 1 (bit0 (div2 s)), by\n    { generalize: div2 s = x,\n      change bit0 x with x+x,\n      rw [one_shiftl, pow_add] }] at this,\n    apply this,\n    rw [\u2190 pow_add, \u2190 mul_two], apply size_le.1,\n    rw e, apply (@div_lt_iff_lt_mul _ _ 2 dec_trivial).1,\n    rw [div2_val], apply lt_succ_self }\nend\n\ntheorem sqrt_le (n : \u2115) : sqrt n * sqrt n \u2264 n :=\n(sqrt_is_sqrt n).left\n\ntheorem sqrt_le' (n : \u2115) : (sqrt n) ^ 2 \u2264 n :=\neq.trans_le (sq (sqrt n)) (sqrt_le n)\n\ntheorem lt_succ_sqrt (n : \u2115) : n < succ (sqrt n) * succ (sqrt n) :=\n(sqrt_is_sqrt n).right\n\ntheorem lt_succ_sqrt' (n : \u2115) : n < (succ (sqrt n)) ^ 2 :=\ntrans_rel_left (\u03bb i j, i < j) (lt_succ_sqrt n) (sq (succ (sqrt n))).symm\n\ntheorem sqrt_le_add (n : \u2115) : n \u2264 sqrt n * sqrt n + sqrt n + sqrt n :=\nby rw \u2190 succ_mul; exact le_of_lt_succ (lt_succ_sqrt n)\n\ntheorem le_sqrt {m n : \u2115} : m \u2264 sqrt n \u2194 m*m \u2264 n :=\n\u27e8\u03bb h, le_trans (mul_self_le_mul_self h) (sqrt_le n),\n \u03bb h, le_of_lt_succ $ mul_self_lt_mul_self_iff.2 $\n   lt_of_le_of_lt h (lt_succ_sqrt n)\u27e9\n\ntheorem le_sqrt' {m n : \u2115} : m \u2264 sqrt n \u2194 m ^ 2 \u2264 n :=\nby simpa only [pow_two] using le_sqrt\n\ntheorem sqrt_lt {m n : \u2115} : sqrt m < n \u2194 m < n*n :=\nlt_iff_lt_of_le_iff_le le_sqrt\n\ntheorem sqrt_lt' {m n : \u2115} : sqrt m < n \u2194 m < n ^ 2 :=\nlt_iff_lt_of_le_iff_le le_sqrt'\n\ntheorem sqrt_le_self (n : \u2115) : sqrt n \u2264 n :=\nle_trans (le_mul_self _) (sqrt_le n)\n\ntheorem sqrt_le_sqrt {m n : \u2115} (h : m \u2264 n) : sqrt m \u2264 sqrt n :=\nle_sqrt.2 (le_trans (sqrt_le _) h)\n\n@[simp] lemma sqrt_zero : sqrt 0 = 0 :=\nby rw [sqrt, size_zero, sqrt._match_1]\n\ntheorem sqrt_eq_zero {n : \u2115} : sqrt n = 0 \u2194 n = 0 :=\n\u27e8\u03bb h, nat.eq_zero_of_le_zero $ le_of_lt_succ $ (@sqrt_lt n 1).1 $\n  by rw [h]; exact dec_trivial,\n by { rintro rfl, simp }\u27e9\n\ntheorem eq_sqrt {n q} : q = sqrt n \u2194 q*q \u2264 n \u2227 n < (q+1)*(q+1) :=\n\u27e8\u03bb e, e.symm \u25b8 sqrt_is_sqrt n,\n \u03bb \u27e8h\u2081, h\u2082\u27e9, le_antisymm (le_sqrt.2 h\u2081) (le_of_lt_succ $ sqrt_lt.2 h\u2082)\u27e9\n\ntheorem eq_sqrt' {n q} : q = sqrt n \u2194 q ^ 2 \u2264 n \u2227 n < (q+1) ^ 2 :=\nby simpa only [pow_two] using eq_sqrt\n\ntheorem le_three_of_sqrt_eq_one {n : \u2115} (h : sqrt n = 1) : n \u2264 3 :=\nle_of_lt_succ $ (@sqrt_lt n 2).1 $\nby rw [h]; exact dec_trivial\n\ntheorem sqrt_lt_self {n : \u2115} (h : 1 < n) : sqrt n < n :=\nsqrt_lt.2 $ by\n  have := nat.mul_lt_mul_of_pos_left h (lt_of_succ_lt h);\n  rwa [mul_one] at this\n\ntheorem sqrt_pos {n : \u2115} : 0 < sqrt n \u2194 0 < n := le_sqrt\n\ntheorem sqrt_add_eq (n : \u2115) {a : \u2115} (h : a \u2264 n + n) : sqrt (n*n + a) = n :=\nle_antisymm\n  (le_of_lt_succ $ sqrt_lt.2 $ by rw [succ_mul, mul_succ, add_succ, add_assoc];\n    exact lt_succ_of_le (nat.add_le_add_left h _))\n  (le_sqrt.2 $ nat.le_add_right _ _)\n\ntheorem sqrt_add_eq' (n : \u2115) {a : \u2115} (h : a \u2264 n + n) : sqrt (n ^ 2 + a) = n :=\n(congr_arg (\u03bb i, sqrt (i + a)) (sq n)).trans (sqrt_add_eq n h)\n\ntheorem sqrt_eq (n : \u2115) : sqrt (n*n) = n :=\nsqrt_add_eq n (zero_le _)\n\ntheorem sqrt_eq' (n : \u2115) : sqrt (n ^ 2) = n :=\nsqrt_add_eq' n (zero_le _)\n\n\n\ntheorem exists_mul_self (x : \u2115) :\n  (\u2203 n, n * n = x) \u2194 sqrt x * sqrt x = x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, by rw [\u2190 hn, sqrt_eq], \u03bb h, \u27e8sqrt x, h\u27e9\u27e9\n\ntheorem exists_mul_self' (x : \u2115) :\n  (\u2203 n, n ^ 2 = x) \u2194 (sqrt x) ^ 2 = x :=\nby simpa only [pow_two] using exists_mul_self x\n\ntheorem sqrt_mul_sqrt_lt_succ (n : \u2115) : sqrt n * sqrt n < n + 1 :=\nlt_succ_iff.mpr (sqrt_le _)\n\ntheorem sqrt_mul_sqrt_lt_succ' (n : \u2115) : (sqrt n) ^ 2 < n + 1 :=\nlt_succ_iff.mpr (sqrt_le' _)\n\ntheorem succ_le_succ_sqrt (n : \u2115) : n + 1 \u2264 (sqrt n + 1) * (sqrt n + 1) :=\nle_of_pred_lt (lt_succ_sqrt _)\n\ntheorem succ_le_succ_sqrt' (n : \u2115) : n + 1 \u2264 (sqrt n + 1) ^ 2 :=\nle_of_pred_lt (lt_succ_sqrt' _)\n\n/-- There are no perfect squares strictly between m\u00b2 and (m+1)\u00b2 -/\ntheorem not_exists_sq {n m : \u2115} (hl : m * m < n) (hr : n < (m + 1) * (m + 1)) :\n  \u00ac \u2203 t, t * t = n :=\nbegin\n  rintro \u27e8t, rfl\u27e9,\n  have h1 : m < t, from nat.mul_self_lt_mul_self_iff.mpr hl,\n  have h2 : t < m + 1, from nat.mul_self_lt_mul_self_iff.mpr hr,\n  exact (not_lt_of_ge $ le_of_lt_succ h2) h1\nend\n\ntheorem not_exists_sq' {n m : \u2115} (hl : m ^ 2 < n) (hr : n < (m + 1) ^ 2) :\n  \u00ac \u2203 t, t ^ 2 = n :=\n  by simpa only [pow_two]\n  using not_exists_sq (by simpa only [pow_two] using hl) (by simpa only [pow_two] using hr)\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7025924272159231}}
{"text": "import analysis.real\n\n-- Johannes' is_lub is the \"bound \u2227 all other bounds bigger\" definition.\n-- But Mario's real.exists_sup in the \u211d Lean files has conclusion\n-- (H : \u2200 y, x \u2264 y \u2194 \u2200 z \u2208 S, z \u2264 y)\n\n\ntheorem maths_lub {S : set \u211d} (x : \u211d) :\n  (\u2200 y, x \u2264 y \u2194 \u2200 z \u2208 S, z \u2264 y) \u2194 is_lub S x :=\nbegin\n  split,\n  { intro H,\n    -- H : \u2200 (y : \u211d), x \u2264 y \u2194 \u2200 (z : \u211d), z \u2208 S \u2192 z \u2264 y\n    -- \u22a2 is_lub S x\n    split,\n    { -- \u22a2 x \u2208 upper_bounds S\n      intros y Hy,\n      exact (H x).1 (le_refl _) y Hy,\n    },\n    { -- \u22a2 x \u2208 lower_bounds (upper_bounds S)\n      intros y Hy,\n      exact (H y).2 Hy,\n    }\n  },\n  intros H y,\n  split,\n  { intros Hxy z Hz,\n    exact le_trans (H.1 z Hz : z \u2264 x) Hxy,\n  },\n  { intro H2,\n    apply H.2,\n    exact H2\n  }\nend \n\n-- is this too hard for tactics?\n\ntheorem maths_lub' {S : set \u211d} (x : \u211d) :\n  (\u2200 y, x \u2264 y \u2194 \u2200 z \u2208 S, z \u2264 y) \u2194 is_lub S x := \n\u27e8\u03bb H,\u27e8\u03bb _ Hy,(H _).1 (le_refl _) _ Hy,\u03bb _ Hy,(H _).2 Hy\u27e9,\n  \u03bb H y,\u27e8\u03bb Hxy _ Hz,le_trans (H.1 _ Hz) Hxy,\u03bb H2,H.2 _ H2\u27e9\u27e9\n\ntheorem maths_lub'' {S : set \u211d} (x : \u211d) :\n  (\u2200 y, x \u2264 y \u2194 \u2200 z \u2208 S, z \u2264 y) \u2194 is_lub S x := \n\u27e8\u03bb H,\u27e8\u03bb y Hy,(H x).1 (le_refl x) y Hy,\u03bb y Hy,(H y).2 Hy\u27e9,\n  \u03bb H y,\u27e8\u03bb Hxy z Hz,le_trans (H.1 z Hz) Hxy,\u03bb H2,H.2 y H2\u27e9\u27e9\n\ntheorem ex_lub_of_nonempty_bdd (S : set \u211d) (H1 : \u2203 x, x \u2208 S) (H2 : \u2203 b, \u2200 s, s \u2208 S \u2192 s \u2264 b) : \n  \u2203 b, is_lub S b := begin\n  have H :=real.exists_sup S H1 H2,\n  cases H with x H,\n  existsi x,\n  exact (maths_lub x).1 H,  \nend \n\ntheorem ex_lub_of_nonempty_bdd' (S : set \u211d) (H1 : \u2203 x, x \u2208 S) (H2 : \u2203 b, \u2200 s, s \u2208 S \u2192 s \u2264 b) : \n  \u2203 b, is_lub S b := let \u27e8x,H\u27e9 := real.exists_sup S H1 H2 in \u27e8x,(maths_lub x).1 H\u27e9", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/src/xenalib/mathlib_someday.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.702592426682898}}
{"text": "import algebra.order.ring\n\nvariables {R : Type*} [ordered_ring R]\nvariables a b c : R\n\n#check sub_nonneg\n\n-- BEGIN\nexample : 0 \u2264 b - a \u2192 a \u2264 b := \nbegin \n  intro h,\n  rw sub_nonneg at h,\n  sorry,\nend\n\n/- Alternatively -/\nexample : 0 \u2264 b - a \u2192 a \u2264 b := \nbegin \n  intro h,\n  exact sub_nonneg.mp h,\nend\n\nexample : a \u2264 b \u2192 0 \u2264 b - a := \nbegin \n  intro h,\n  rw \u2190 sub_nonneg at h,\n  sorry,\nend\n\n/- Alternatively -/\nexample : a \u2264 b \u2192 0 \u2264 b - a := \nbegin \n  intro h,\n  sorry,\nend\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.2_exact/ex2_exact_sub_nonneg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7025924226651175}}
{"text": "example (p q r : Prop) : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  apply iff.intro,\n    intro h,\n    apply or.elim (and.right h),\n      intro hq,\n      apply or.inl,\n      apply and.intro,\n        exact and.left h,\n        exact hq,\n      intro hr,\n      apply or.inr,\n      apply and.intro,\n        exact and.left h,\n        exact hr,\n    intro h,\n    apply or.elim h,\n      intro hpq,\n      apply and.intro,\n        exact and.left hpq,\n        apply or.inl,\n        exact and.right hpq,\n      intro hpr,\n      apply and.intro,\n        exact and.left hpr,\n        apply or.inr,\n        exact and.right hpr\nend\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch5/ex0201.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952948443461, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7025924202564585}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n-/\n\nimport analysis.inner_product_space.projection\nimport measure_theory.function.l2_space\nimport measure_theory.decomposition.radon_nikodym\n\n/-! # Conditional expectation\n\nWe build the conditional expectation of an integrable function `f` with value in a Banach space\nwith respect to a measure `\u03bc` (defined on a measurable space structure `m0`) and a measurable space\nstructure `m` with `hm : m \u2264 m0` (a sub-sigma-algebra). This is an `m`-strongly measurable\nfunction `\u03bc[f|hm]` which is integrable and verifies `\u222b x in s, \u03bc[f|hm] x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc`\nfor all `m`-measurable sets `s`. It is unique as an element of `L\u00b9`.\n\nThe construction is done in four steps:\n* Define the conditional expectation of an `L\u00b2` function, as an element of `L\u00b2`. This is the\n  orthogonal projection on the subspace of almost everywhere `m`-measurable functions.\n* Show that the conditional expectation of the indicator of a measurable set with finite measure\n  is integrable and define a map `set \u03b1 \u2192 (E \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E))` which to a set associates a linear\n  map. That linear map sends `x \u2208 E` to the conditional expectation of the indicator of the set\n  with value `x`.\n* Extend that map to `condexp_L1_clm : (\u03b1 \u2192\u2081[\u03bc] E) \u2192L[\u211d] (\u03b1 \u2192\u2081[\u03bc] E)`. This is done using the same\n  construction as the Bochner integral (see the file `measure_theory/integral/set_to_L1`).\n* Define the conditional expectation of a function `f : \u03b1 \u2192 E`, which is an integrable function\n  `\u03b1 \u2192 E` equal to 0 if `f` is not integrable, and equal to an `m`-measurable representative of\n  `condexp_L1_clm` applied to `[f]`, the equivalence class of `f` in `L\u00b9`.\n\n## Main results\n\nThe conditional expectation and its properties\n\n* `condexp (hm : m \u2264 m0) (\u03bc : measure \u03b1) (f : \u03b1 \u2192 E)`: conditional expectation of `f` with respect\n  to `m`.\n* `integrable_condexp` : `condexp` is integrable.\n* `measurable_condexp` : `condexp` is `m`-measurable.\n* `set_integral_condexp (hf : integrable f \u03bc) (hs : measurable_set[m] s)` : the conditional\n  expectation verifies `\u222b x in s, condexp hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc` for any `m`-measurable\n  set `s`.\n\nWhile `condexp` is function-valued, we also define `condexp_L1` with value in `L1` and a continuous\nlinear map `condexp_L1_clm` from `L1` to `L1`. `condexp` should be used in most cases.\n\nUniqueness of the conditional expectation\n\n* `Lp.ae_eq_of_forall_set_integral_eq'`: two `Lp` functions verifying the equality of integrals\n  defining the conditional expectation are equal.\n* `ae_eq_of_forall_set_integral_eq_of_sigma_finite'`: two functions verifying the equality of\n  integrals defining the conditional expectation are equal almost everywhere.\n  Requires `[sigma_finite (\u03bc.trim hm)]`.\n* `ae_eq_condexp_of_forall_set_integral_eq`: an a.e. `m`-measurable function which verifies the\n  equality of integrals is a.e. equal to `condexp`.\n\n## Notations\n\nFor a measure `\u03bc` defined on a measurable space structure `m0`, another measurable space structure\n`m` with `hm : m \u2264 m0` (a sub-sigma-algebra) and a function `f`, we define the notation\n* `\u03bc[f|hm] = condexp hm \u03bc f`.\n\n## Implementation notes\n\nMost of the results in this file are valid for a complete real normed space `F`.\nHowever, some lemmas also use `\ud835\udd5c : is_R_or_C`:\n* `condexp_L2` is defined only for an `inner_product_space` for now, and we use `\ud835\udd5c` for its field.\n* results about scalar multiplication are stated not only for `\u211d` but also for `\ud835\udd5c` if we happen to\n  have `normed_space \ud835\udd5c F`.\n\n## Tags\n\nconditional expectation, conditional expected value\n\n-/\n\nnoncomputable theory\nopen topological_space measure_theory.Lp filter continuous_linear_map\nopen_locale nnreal ennreal topological_space big_operators measure_theory\n\nnamespace measure_theory\n\n/-- A function `f` verifies `ae_strongly_measurable' m f \u03bc` if it is `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. This is similar to `ae_strongly_measurable`, but the\n`measurable_space` structures used for the measurability statement and for the measure are\ndifferent. -/\ndef ae_strongly_measurable' {\u03b1 \u03b2} [topological_space \u03b2]\n  (m : measurable_space \u03b1) {m0 : measurable_space \u03b1}\n  (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) : Prop :=\n\u2203 g : \u03b1 \u2192 \u03b2, strongly_measurable[m] g \u2227 f =\u1d50[\u03bc] g\n\nnamespace ae_strongly_measurable'\n\nvariables {\u03b1 \u03b2 \ud835\udd5c : Type*} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  [topological_space \u03b2] {f g : \u03b1 \u2192 \u03b2}\n\nlemma congr (hf : ae_strongly_measurable' m f \u03bc) (hfg : f =\u1d50[\u03bc] g) :\n  ae_strongly_measurable' m g \u03bc :=\nby { obtain \u27e8f', hf'_meas, hff'\u27e9 := hf, exact \u27e8f', hf'_meas, hfg.symm.trans hff'\u27e9, }\n\nlemma add [has_add \u03b2] [has_continuous_add \u03b2] (hf : ae_strongly_measurable' m f \u03bc)\n  (hg : ae_strongly_measurable' m g \u03bc) :\n  ae_strongly_measurable' m (f+g) \u03bc :=\nbegin\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9,\n  rcases hg with \u27e8g', h_g'_meas, hgg'\u27e9,\n  exact \u27e8f' + g', h_f'_meas.add h_g'_meas, hff'.add hgg'\u27e9,\nend\n\nlemma neg [add_group \u03b2] [topological_add_group \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (-f) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  refine \u27e8-f', hf'_meas.neg, hf_ae.mono (\u03bb x hx, _)\u27e9,\n  simp_rw pi.neg_apply,\n  rw hx,\nend\n\nlemma sub [add_group \u03b2] [topological_add_group \u03b2] {f g : \u03b1 \u2192 \u03b2}\n  (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  ae_strongly_measurable' m (f - g) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  rcases hgm with \u27e8g', hg'_meas, hg_ae\u27e9,\n  refine \u27e8f'-g', hf'_meas.sub hg'_meas, hf_ae.mp (hg_ae.mono (\u03bb x hx1 hx2, _))\u27e9,\n  simp_rw pi.sub_apply,\n  rw [hx1, hx2],\nend\n\nlemma const_smul [has_scalar \ud835\udd5c \u03b2] [has_continuous_const_smul \ud835\udd5c \u03b2]\n  (c : \ud835\udd5c) (hf : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (c \u2022 f) \u03bc :=\nbegin\n  rcases hf with \u27e8f', h_f'_meas, hff'\u27e9,\n  refine \u27e8c \u2022 f', h_f'_meas.const_smul c, _\u27e9,\n  exact eventually_eq.fun_comp hff' (\u03bb x, c \u2022 x),\nend\n\nlemma const_inner {\ud835\udd5c \u03b2} [is_R_or_C \ud835\udd5c] [inner_product_space \ud835\udd5c \u03b2]\n  {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) (c : \u03b2) :\n  ae_strongly_measurable' m (\u03bb x, (inner c (f x) : \ud835\udd5c)) \u03bc :=\nbegin\n  rcases hfm with \u27e8f', hf'_meas, hf_ae\u27e9,\n  refine \u27e8\u03bb x, (inner c (f' x) : \ud835\udd5c), (@strongly_measurable_const _ _ m _ _).inner hf'_meas,\n    hf_ae.mono (\u03bb x hx, _)\u27e9,\n  dsimp only,\n  rw hx,\nend\n\n/-- An `m`-strongly measurable function almost everywhere equal to `f`. -/\ndef mk (f : \u03b1 \u2192 \u03b2) (hfm : ae_strongly_measurable' m f \u03bc) : \u03b1 \u2192 \u03b2 := hfm.some\n\nlemma strongly_measurable_mk {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) :\n  strongly_measurable[m] (hfm.mk f) :=\nhfm.some_spec.1\n\nlemma ae_eq_mk {f : \u03b1 \u2192 \u03b2} (hfm : ae_strongly_measurable' m f \u03bc) : f =\u1d50[\u03bc] hfm.mk f :=\nhfm.some_spec.2\n\nlemma continuous_comp {\u03b3} [topological_space \u03b3] {f : \u03b1 \u2192 \u03b2} {g : \u03b2 \u2192 \u03b3}\n  (hg : continuous g) (hf : ae_strongly_measurable' m f \u03bc) :\n  ae_strongly_measurable' m (g \u2218 f) \u03bc :=\n\u27e8\u03bb x, g (hf.mk _ x),\n  @continuous.comp_strongly_measurable _ _ _ m _ _ _ _ hg hf.strongly_measurable_mk,\n  hf.ae_eq_mk.mono (\u03bb x hx, by rw [function.comp_apply, hx])\u27e9\n\nend ae_strongly_measurable'\n\nlemma ae_strongly_measurable'_of_ae_strongly_measurable'_trim {\u03b1 \u03b2} {m m0 m0' : measurable_space \u03b1}\n  [topological_space \u03b2] (hm0 : m0 \u2264 m0') {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2}\n  (hf : ae_strongly_measurable' m f (\u03bc.trim hm0)) :\n  ae_strongly_measurable' m f \u03bc :=\nby { obtain \u27e8g, hg_meas, hfg\u27e9 := hf, exact \u27e8g, hg_meas, ae_eq_of_ae_eq_trim hfg\u27e9, }\n\nlemma strongly_measurable.ae_strongly_measurable'\n  {\u03b1 \u03b2} {m m0 : measurable_space \u03b1} [topological_space \u03b2]\n  {\u03bc : measure \u03b1} {f : \u03b1 \u2192 \u03b2} (hf : strongly_measurable[m] f) :\n  ae_strongly_measurable' m f \u03bc :=\n\u27e8f, hf, ae_eq_refl _\u27e9\n\nlemma ae_eq_trim_iff_of_ae_strongly_measurable' {\u03b1 \u03b2} [topological_space \u03b2] [metrizable_space \u03b2]\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f g : \u03b1 \u2192 \u03b2}\n  (hm : m \u2264 m0) (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  hfm.mk f =\u1d50[\u03bc.trim hm] hgm.mk g \u2194 f =\u1d50[\u03bc] g :=\n(ae_eq_trim_iff hm hfm.strongly_measurable_mk hgm.strongly_measurable_mk).trans\n\u27e8\u03bb h, hfm.ae_eq_mk.trans (h.trans hgm.ae_eq_mk.symm),\n  \u03bb h, hfm.ae_eq_mk.symm.trans (h.trans hgm.ae_eq_mk)\u27e9\n\n\nvariables {\u03b1 \u03b2 \u03b3 E E' F F' G G' H \ud835\udd5c : Type*} {p : \u211d\u22650\u221e}\n  [is_R_or_C \ud835\udd5c] -- \ud835\udd5c for \u211d or \u2102\n  [topological_space \u03b2] -- \u03b2 for a generic topological space\n  -- E for an inner product space\n  [inner_product_space \ud835\udd5c E]\n  -- E' for an inner product space on which we compute integrals\n  [inner_product_space \ud835\udd5c E']\n  [complete_space E'] [normed_space \u211d E']\n  -- F for a Lp submodule\n  [normed_group F] [normed_space \ud835\udd5c F]\n  -- F' for integrals on a Lp submodule\n  [normed_group F'] [normed_space \ud835\udd5c F'] [normed_space \u211d F'] [complete_space F']\n  -- G for a Lp add_subgroup\n  [normed_group G]\n  -- G' for integrals on a Lp add_subgroup\n  [normed_group G'] [normed_space \u211d G'] [complete_space G']\n  -- H for a normed group (hypotheses of mem_\u2112p)\n  [normed_group H]\n\nsection Lp_meas\n\n/-! ## The subset `Lp_meas` of `Lp` functions a.e. measurable with respect to a sub-sigma-algebra -/\n\nvariables (F)\n\n/-- `Lp_meas_subgroup F m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef Lp_meas_subgroup (m : measurable_space \u03b1) [measurable_space \u03b1] (p : \u211d\u22650\u221e) (\u03bc : measure \u03b1) :\n  add_subgroup (Lp F p \u03bc) :=\n{ carrier   := {f : (Lp F p \u03bc) | ae_strongly_measurable' m f \u03bc} ,\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _\u27e9,\n  add_mem'  := \u03bb f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,\n  neg_mem' := \u03bb f hf, ae_strongly_measurable'.congr hf.neg (Lp.coe_fn_neg f).symm, }\n\nvariables (\ud835\udd5c)\n/-- `Lp_meas F \ud835\udd5c m p \u03bc` is the subspace of `Lp F p \u03bc` containing functions `f` verifying\n`ae_strongly_measurable' m f \u03bc`, i.e. functions which are `\u03bc`-a.e. equal to\nan `m`-strongly measurable function. -/\ndef Lp_meas (m : measurable_space \u03b1) [measurable_space \u03b1] (p : \u211d\u22650\u221e)\n  (\u03bc : measure \u03b1) :\n  submodule \ud835\udd5c (Lp F p \u03bc) :=\n{ carrier   := {f : (Lp F p \u03bc) | ae_strongly_measurable' m f \u03bc} ,\n  zero_mem' := \u27e8(0 : \u03b1 \u2192 F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _\u27e9,\n  add_mem'  := \u03bb f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,\n  smul_mem' := \u03bb c f hf, (hf.const_smul c).congr (Lp.coe_fn_smul c f).symm, }\nvariables {F \ud835\udd5c}\n\nvariables\n\nlemma mem_Lp_meas_subgroup_iff_ae_strongly_measurable' {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {f : Lp F p \u03bc} :\n  f \u2208 Lp_meas_subgroup F m p \u03bc \u2194 ae_strongly_measurable' m f \u03bc :=\nby rw [\u2190 add_subgroup.mem_carrier, Lp_meas_subgroup, set.mem_set_of_eq]\n\nlemma mem_Lp_meas_iff_ae_strongly_measurable'\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f : Lp F p \u03bc} :\n  f \u2208 Lp_meas F \ud835\udd5c m p \u03bc \u2194 ae_strongly_measurable' m f \u03bc :=\nby rw [\u2190 set_like.mem_coe, \u2190 submodule.mem_carrier, Lp_meas, set.mem_set_of_eq]\n\nlemma Lp_meas.ae_strongly_measurable'\n  {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  ae_strongly_measurable' m f \u03bc :=\nmem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem\n\nlemma mem_Lp_meas_self\n  {m0 : measurable_space \u03b1} (\u03bc : measure \u03b1) (f : Lp F p \u03bc) :\n  f \u2208 Lp_meas F \ud835\udd5c m0 p \u03bc :=\nmem_Lp_meas_iff_ae_strongly_measurable'.mpr (Lp.ae_strongly_measurable f)\n\nlemma Lp_meas_subgroup_coe {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {f : Lp_meas_subgroup F m p \u03bc} :\n  \u21d1f = (f : Lp F p \u03bc) :=\ncoe_fn_coe_base f\n\nlemma Lp_meas_coe {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {f : Lp_meas F \ud835\udd5c m p \u03bc} :\n  \u21d1f = (f : Lp F p \u03bc) :=\ncoe_fn_coe_base f\n\nlemma mem_Lp_meas_indicator_const_Lp {m m0 : measurable_space \u03b1} (hm : m \u2264 m0)\n  {\u03bc : measure \u03b1} {s : set \u03b1} (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) {c : F} :\n  indicator_const_Lp p (hm s hs) h\u03bcs c \u2208 Lp_meas F \ud835\udd5c m p \u03bc :=\n\u27e8s.indicator (\u03bb x : \u03b1, c), (@strongly_measurable_const _ _ m _ _).indicator hs,\n  indicator_const_Lp_coe_fn\u27e9\n\nsection complete_subspace\n\n/-! ## The subspace `Lp_meas` is complete.\n\nWe define an `isometric` between `Lp_meas_subgroup` and the `Lp` space corresponding to the\nmeasure `\u03bc.trim hm`. As a consequence, the completeness of `Lp` implies completeness of\n`Lp_meas_subgroup` (and `Lp_meas`). -/\n\nvariables {\u03b9 : Type*} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\n/-- If `f` belongs to `Lp_meas_subgroup F m p \u03bc`, then the measurable function it is almost\neverywhere equal to (given by `ae_measurable.mk`) belongs to `\u2112p` for the measure `\u03bc.trim hm`. -/\nlemma mem_\u2112p_trim_of_mem_Lp_meas_subgroup (hm : m \u2264 m0) (f : Lp F p \u03bc)\n  (hf_meas : f \u2208 Lp_meas_subgroup F m p \u03bc) :\n  mem_\u2112p (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas).some p (\u03bc.trim hm) :=\nbegin\n  have hf : ae_strongly_measurable' m f \u03bc,\n    from (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas),\n  let g := hf.some,\n  obtain \u27e8hg, hfg\u27e9 := hf.some_spec,\n  change mem_\u2112p g p (\u03bc.trim hm),\n  refine \u27e8hg.ae_strongly_measurable, _\u27e9,\n  have h_snorm_fg : snorm g p (\u03bc.trim hm) = snorm f p \u03bc,\n    by { rw snorm_trim hm hg, exact snorm_congr_ae hfg.symm, },\n  rw h_snorm_fg,\n  exact Lp.snorm_lt_top f,\nend\n\n/-- If `f` belongs to `Lp` for the measure `\u03bc.trim hm`, then it belongs to the subgroup\n`Lp_meas_subgroup F m p \u03bc`. -/\nlemma mem_Lp_meas_subgroup_to_Lp_of_trim (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  (mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f \u2208 Lp_meas_subgroup F m p \u03bc :=\nbegin\n  let hf_mem_\u2112p := mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f),\n  rw mem_Lp_meas_subgroup_iff_ae_strongly_measurable',\n  refine ae_strongly_measurable'.congr _ (mem_\u2112p.coe_fn_to_Lp hf_mem_\u2112p).symm,\n  refine ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm _,\n  exact Lp.ae_strongly_measurable f,\nend\n\nvariables (F p \u03bc)\n/-- Map from `Lp_meas_subgroup` to `Lp F p (\u03bc.trim hm)`. -/\ndef Lp_meas_subgroup_to_Lp_trim (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) : Lp F p (\u03bc.trim hm) :=\nmem_\u2112p.to_Lp (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some\n  (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm f f.mem)\n\nvariables (\ud835\udd5c)\n/-- Map from `Lp_meas` to `Lp F p (\u03bc.trim hm)`. -/\ndef Lp_meas_to_Lp_trim (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) : Lp F p (\u03bc.trim hm) :=\nmem_\u2112p.to_Lp (mem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem).some\n  (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm f f.mem)\nvariables {\ud835\udd5c}\n\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas_subgroup`, inverse of\n`Lp_meas_subgroup_to_Lp_trim`. -/\ndef Lp_trim_to_Lp_meas_subgroup (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) : Lp_meas_subgroup F m p \u03bc :=\n\u27e8(mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f\u27e9\n\nvariables (\ud835\udd5c)\n/-- Map from `Lp F p (\u03bc.trim hm)` to `Lp_meas`, inverse of `Lp_meas_to_Lp_trim`. -/\ndef Lp_trim_to_Lp_meas (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) : Lp_meas F \ud835\udd5c m p \u03bc :=\n\u27e8(mem_\u2112p_of_mem_\u2112p_trim hm (Lp.mem_\u2112p f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f\u27e9\n\nvariables {F \ud835\udd5c p \u03bc}\n\nlemma Lp_meas_subgroup_to_Lp_trim_ae_eq (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f =\u1d50[\u03bc] f :=\n(ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm \u2191f f.mem))).trans\n  (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm\n\nlemma Lp_trim_to_Lp_meas_subgroup_ae_eq (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  Lp_trim_to_Lp_meas_subgroup F p \u03bc hm f =\u1d50[\u03bc] f :=\nmem_\u2112p.coe_fn_to_Lp _\n\nlemma Lp_meas_to_Lp_trim_ae_eq (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\n(ae_eq_of_ae_eq_trim (mem_\u2112p.coe_fn_to_Lp (mem_\u2112p_trim_of_mem_Lp_meas_subgroup hm \u2191f f.mem))).trans\n  (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm\n\nlemma Lp_trim_to_Lp_meas_ae_eq (hm : m \u2264 m0) (f : Lp F p (\u03bc.trim hm)) :\n  Lp_trim_to_Lp_meas F \ud835\udd5c p \u03bc hm f =\u1d50[\u03bc] f :=\nmem_\u2112p.coe_fn_to_Lp _\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a right inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\nlemma Lp_meas_subgroup_to_Lp_trim_right_inv (hm : m \u2264 m0) :\n  function.right_inverse (Lp_trim_to_Lp_meas_subgroup F p \u03bc hm)\n    (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  intro f,\n  ext1,\n  refine ae_eq_trim_of_strongly_measurable hm\n    (Lp.strongly_measurable _) (Lp.strongly_measurable _) _,\n  exact (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _),\nend\n\n/-- `Lp_trim_to_Lp_meas_subgroup` is a left inverse of `Lp_meas_subgroup_to_Lp_trim`. -/\nlemma Lp_meas_subgroup_to_Lp_trim_left_inv (hm : m \u2264 m0) :\n  function.left_inverse (Lp_trim_to_Lp_meas_subgroup F p \u03bc hm)\n    (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  intro f,\n  ext1,\n  ext1,\n  rw \u2190 Lp_meas_subgroup_coe,\n  exact (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _).trans (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_add (hm : m \u2264 m0) (f g : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (f + g)\n    = Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f + Lp_meas_subgroup_to_Lp_trim F p \u03bc hm g :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact (Lp.strongly_measurable _).add (Lp.strongly_measurable _), },\n  refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,\n  refine eventually_eq.trans _\n    (eventually_eq.add (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm\n      (Lp_meas_subgroup_to_Lp_trim_ae_eq hm g).symm),\n  refine (Lp.coe_fn_add _ _).trans _,\n  simp_rw Lp_meas_subgroup_coe,\n  exact eventually_of_forall (\u03bb x, by refl),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_neg (hm : m \u2264 m0) (f : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (-f)\n    = -Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_neg _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact @strongly_measurable.neg _ _ _ m _ _ _ (Lp.strongly_measurable _), },\n  refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,\n  refine eventually_eq.trans _\n    (eventually_eq.neg (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm),\n  refine (Lp.coe_fn_neg _).trans _,\n  simp_rw Lp_meas_subgroup_coe,\n  exact eventually_of_forall (\u03bb x, by refl),\nend\n\nlemma Lp_meas_subgroup_to_Lp_trim_sub (hm : m \u2264 m0) (f g : Lp_meas_subgroup F m p \u03bc) :\n  Lp_meas_subgroup_to_Lp_trim F p \u03bc hm (f - g)\n    = Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f - Lp_meas_subgroup_to_Lp_trim F p \u03bc hm g :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, Lp_meas_subgroup_to_Lp_trim_add,\n  Lp_meas_subgroup_to_Lp_trim_neg]\n\nlemma Lp_meas_to_Lp_trim_smul (hm : m \u2264 m0) (c : \ud835\udd5c) (f : Lp_meas F \ud835\udd5c m p \u03bc) :\n  Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm (c \u2022 f) = c \u2022 Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,\n  { exact (Lp.strongly_measurable _).const_smul c, },\n  refine (Lp_meas_to_Lp_trim_ae_eq hm _).trans _,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (Lp_meas_to_Lp_trim_ae_eq hm f).mono (\u03bb x hx, _),\n  rw [pi.smul_apply, pi.smul_apply, hx],\n  refl,\nend\n\n/-- `Lp_meas_subgroup_to_Lp_trim` preserves the norm. -/\nlemma Lp_meas_subgroup_to_Lp_trim_norm_map [hp : fact (1 \u2264 p)] (hm : m \u2264 m0)\n  (f : Lp_meas_subgroup F m p \u03bc) :\n  \u2225Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f\u2225 = \u2225f\u2225 :=\nbegin\n  rw [Lp.norm_def, snorm_trim hm (Lp.strongly_measurable _),\n    snorm_congr_ae (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _), Lp_meas_subgroup_coe, \u2190 Lp.norm_def],\n  congr,\nend\n\nlemma isometry_Lp_meas_subgroup_to_Lp_trim [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  isometry (Lp_meas_subgroup_to_Lp_trim F p \u03bc hm) :=\nbegin\n  rw isometry_emetric_iff_metric,\n  intros f g,\n  rw [dist_eq_norm, \u2190 Lp_meas_subgroup_to_Lp_trim_sub, Lp_meas_subgroup_to_Lp_trim_norm_map,\n    dist_eq_norm],\nend\n\nvariables (F p \u03bc)\n/-- `Lp_meas_subgroup` and `Lp F p (\u03bc.trim hm)` are isometric. -/\ndef Lp_meas_subgroup_to_Lp_trim_iso [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  Lp_meas_subgroup F m p \u03bc \u2243\u1d62 Lp F p (\u03bc.trim hm) :=\n{ to_fun    := Lp_meas_subgroup_to_Lp_trim F p \u03bc hm,\n  inv_fun   := Lp_trim_to_Lp_meas_subgroup F p \u03bc hm,\n  left_inv  := Lp_meas_subgroup_to_Lp_trim_left_inv hm,\n  right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,\n  isometry_to_fun := isometry_Lp_meas_subgroup_to_Lp_trim hm, }\n\nvariables (\ud835\udd5c)\n/-- `Lp_meas_subgroup` and `Lp_meas` are isometric. -/\ndef Lp_meas_subgroup_to_Lp_meas_iso [hp : fact (1 \u2264 p)] :\n  Lp_meas_subgroup F m p \u03bc \u2243\u1d62 Lp_meas F \ud835\udd5c m p \u03bc :=\nisometric.refl (Lp_meas_subgroup F m p \u03bc)\n\n/-- `Lp_meas` and `Lp F p (\u03bc.trim hm)` are isometric, with a linear equivalence. -/\ndef Lp_meas_to_Lp_trim_lie [hp : fact (1 \u2264 p)] (hm : m \u2264 m0) :\n  Lp_meas F \ud835\udd5c m p \u03bc \u2243\u2097\u1d62[\ud835\udd5c] Lp F p (\u03bc.trim hm) :=\n{ to_fun    := Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm,\n  inv_fun   := Lp_trim_to_Lp_meas F \ud835\udd5c p \u03bc hm,\n  left_inv  := Lp_meas_subgroup_to_Lp_trim_left_inv hm,\n  right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,\n  map_add'  := Lp_meas_subgroup_to_Lp_trim_add hm,\n  map_smul' := Lp_meas_to_Lp_trim_smul hm,\n  norm_map' := Lp_meas_subgroup_to_Lp_trim_norm_map hm, }\nvariables {F \ud835\udd5c p \u03bc}\n\ninstance [hm : fact (m \u2264 m0)] [complete_space F] [hp : fact (1 \u2264 p)] :\n  complete_space (Lp_meas_subgroup F m p \u03bc) :=\nby { rw (Lp_meas_subgroup_to_Lp_trim_iso F p \u03bc hm.elim).complete_space_iff, apply_instance, }\n\ninstance [hm : fact (m \u2264 m0)] [complete_space F] [hp : fact (1 \u2264 p)] :\n  complete_space (Lp_meas F \ud835\udd5c m p \u03bc) :=\nby { rw (Lp_meas_subgroup_to_Lp_meas_iso F \ud835\udd5c p \u03bc).symm.complete_space_iff, apply_instance, }\n\nlemma is_complete_ae_strongly_measurable' [hp : fact (1 \u2264 p)] [complete_space F] (hm : m \u2264 m0) :\n  is_complete {f : Lp F p \u03bc | ae_strongly_measurable' m f \u03bc} :=\nbegin\n  rw \u2190 complete_space_coe_iff_is_complete,\n  haveI : fact (m \u2264 m0) := \u27e8hm\u27e9,\n  change complete_space (Lp_meas_subgroup F m p \u03bc),\n  apply_instance,\nend\n\nlemma is_closed_ae_strongly_measurable' [hp : fact (1 \u2264 p)] [complete_space F] (hm : m \u2264 m0) :\n  is_closed {f : Lp F p \u03bc | ae_strongly_measurable' m f \u03bc} :=\nis_complete.is_closed (is_complete_ae_strongly_measurable' hm)\n\nend complete_subspace\n\nsection strongly_measurable\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\n/-- We do not get `ae_fin_strongly_measurable f (\u03bc.trim hm)`, since we don't have\n`f =\u1d50[\u03bc.trim hm] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f` but only the weaker\n`f =\u1d50[\u03bc] Lp_meas_to_Lp_trim F \ud835\udd5c p \u03bc hm f`. -/\nlemma Lp_meas.ae_fin_strongly_measurable' (hm : m \u2264 m0) (f : Lp_meas F \ud835\udd5c m p \u03bc) (hp_ne_zero : p \u2260 0)\n  (hp_ne_top : p \u2260 \u221e) :\n  \u2203 g, fin_strongly_measurable g (\u03bc.trim hm) \u2227 f =\u1d50[\u03bc] g :=\n\u27e8Lp_meas_subgroup_to_Lp_trim F p \u03bc hm f, Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top,\n  (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm\u27e9\n\nend strongly_measurable\n\nend Lp_meas\n\n\nsection uniqueness_of_conditional_expectation\n\n/-! ## Uniqueness of the conditional expectation -/\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n\nlemma Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero\n  (hm : m \u2264 m0) (f : Lp_meas E' \ud835\udd5c m p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hf_zero : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = 0) :\n  f =\u1d50[\u03bc] 0 :=\nbegin\n  obtain \u27e8g, hg_sm, hfg\u27e9 := Lp_meas.ae_fin_strongly_measurable' hm f hp_ne_zero hp_ne_top,\n  refine hfg.trans _,\n  refine ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim hm _ _ hg_sm,\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g, from ae_restrict_of_ae hfg,\n    rw [integrable_on, integrable_congr hfg_restrict.symm],\n    exact hf_int_finite s hs h\u03bcs, },\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] g, from ae_restrict_of_ae hfg,\n    rw integral_congr_ae hfg_restrict.symm,\n    exact hf_zero s hs h\u03bcs, },\nend\n\ninclude \ud835\udd5c\n\nlemma Lp.ae_eq_zero_of_forall_set_integral_eq_zero'\n  (hm : m \u2264 m0) (f : Lp E' p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hf_zero : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = 0)\n  (hf_meas : ae_strongly_measurable' m f \u03bc) :\n  f =\u1d50[\u03bc] 0 :=\nbegin\n  let f_meas : Lp_meas E' \ud835\udd5c m p \u03bc := \u27e8f, hf_meas\u27e9,\n  have hf_f_meas : f =\u1d50[\u03bc] f_meas, by simp only [coe_fn_coe_base', subtype.coe_mk],\n  refine hf_f_meas.trans _,\n  refine Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero hm f_meas hp_ne_zero hp_ne_top _ _,\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,\n    rw [integrable_on, integrable_congr hfg_restrict.symm],\n    exact hf_int_finite s hs h\u03bcs, },\n  { intros s hs h\u03bcs,\n    have hfg_restrict : f =\u1d50[\u03bc.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,\n    rw integral_congr_ae hfg_restrict.symm,\n    exact hf_zero s hs h\u03bcs, },\nend\n\n/-- **Uniqueness of the conditional expectation** -/\nlemma Lp.ae_eq_of_forall_set_integral_eq'\n  (hm : m \u2264 m0) (f g : Lp E' p \u03bc) (hp_ne_zero : p \u2260 0) (hp_ne_top : p \u2260 \u221e)\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hfg : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = \u222b x in s, g x \u2202\u03bc)\n  (hf_meas : ae_strongly_measurable' m f \u03bc) (hg_meas : ae_strongly_measurable' m g \u03bc) :\n  f =\u1d50[\u03bc] g :=\nbegin\n  suffices h_sub : \u21d1(f-g) =\u1d50[\u03bc] 0,\n    by { rw \u2190 sub_ae_eq_zero, exact (Lp.coe_fn_sub f g).symm.trans h_sub, },\n  have hfg' : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, (f - g) x \u2202\u03bc = 0,\n  { intros s hs h\u03bcs,\n    rw integral_congr_ae (ae_restrict_of_ae (Lp.coe_fn_sub f g)),\n    rw integral_sub' (hf_int_finite s hs h\u03bcs) (hg_int_finite s hs h\u03bcs),\n    exact sub_eq_zero.mpr (hfg s hs h\u03bcs), },\n  have hfg_int : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on \u21d1(f-g) s \u03bc,\n  { intros s hs h\u03bcs,\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub f g))],\n    exact (hf_int_finite s hs h\u03bcs).sub (hg_int_finite s hs h\u03bcs), },\n  have hfg_meas : ae_strongly_measurable' m \u21d1(f - g) \u03bc,\n    from ae_strongly_measurable'.congr (hf_meas.sub hg_meas) (Lp.coe_fn_sub f g).symm,\n  exact Lp.ae_eq_zero_of_forall_set_integral_eq_zero' hm (f-g) hp_ne_zero hp_ne_top hfg_int hfg'\n    hfg_meas,\nend\n\nomit \ud835\udd5c\n\nlemma ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  {f g : \u03b1 \u2192 F'}\n  (hf_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on f s \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hfg_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, f x \u2202\u03bc = \u222b x in s, g x \u2202\u03bc)\n  (hfm : ae_strongly_measurable' m f \u03bc) (hgm : ae_strongly_measurable' m g \u03bc) :\n  f =\u1d50[\u03bc] g :=\nbegin\n  rw \u2190 ae_eq_trim_iff_of_ae_strongly_measurable' hm hfm hgm,\n  have hf_mk_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    @integrable_on _ _ m _ (hfm.mk f) s (\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [integrable_on, restrict_trim hm _ hs],\n    refine integrable.trim hm _ hfm.strongly_measurable_mk,\n    exact integrable.congr (hf_int_finite s hs h\u03bcs) (ae_restrict_of_ae hfm.ae_eq_mk), },\n  have hg_mk_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    @integrable_on _ _ m _ (hgm.mk g) s (\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [integrable_on, restrict_trim hm _ hs],\n    refine integrable.trim hm _ hgm.strongly_measurable_mk,\n    exact integrable.congr (hg_int_finite s hs h\u03bcs) (ae_restrict_of_ae hgm.ae_eq_mk), },\n  have hfg_mk_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc.trim hm s < \u221e \u2192\n    \u222b x in s, (hfm.mk f x) \u2202(\u03bc.trim hm) = \u222b x in s, (hgm.mk g x) \u2202(\u03bc.trim hm),\n  { intros s hs h\u03bcs,\n    rw trim_measurable_set_eq hm hs at h\u03bcs,\n    rw [restrict_trim hm _ hs, \u2190 integral_trim hm hfm.strongly_measurable_mk,\n      \u2190 integral_trim hm hgm.strongly_measurable_mk,\n      integral_congr_ae (ae_restrict_of_ae hfm.ae_eq_mk.symm),\n      integral_congr_ae (ae_restrict_of_ae hgm.ae_eq_mk.symm)],\n    exact hfg_eq s hs h\u03bcs, },\n  exact ae_eq_of_forall_set_integral_eq_of_sigma_finite hf_mk_int_finite hg_mk_int_finite hfg_mk_eq,\nend\n\nend uniqueness_of_conditional_expectation\n\n\nsection integral_norm_le\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {s : set \u03b1}\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b x in s, \u2225g x\u2225 \u2202\u03bc \u2264 \u222b x in s, \u2225f x\u2225 \u2202\u03bc` on all `m`-measurable sets with finite measure. -/\nlemma integral_norm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n  (hf : strongly_measurable f) (hfi : integrable_on f s \u03bc)\n  (hg : strongly_measurable[m] g) (hgi : integrable_on g s \u03bc)\n  (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 \u222b x in t, g x \u2202\u03bc = \u222b x in t, f x \u2202\u03bc)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, \u2225g x\u2225 \u2202\u03bc \u2264 \u222b x in s, \u2225f x\u2225 \u2202\u03bc :=\nbegin\n  rw [integral_norm_eq_pos_sub_neg (hg.mono hm) hgi, integral_norm_eq_pos_sub_neg hf hfi],\n  have h_meas_nonneg_g : measurable_set[m] {x | 0 \u2264 g x},\n    from (@strongly_measurable_const _ _ m _ _).measurable_set_le hg,\n  have h_meas_nonneg_f : measurable_set {x | 0 \u2264 f x},\n    from strongly_measurable_const.measurable_set_le hf,\n  have h_meas_nonpos_g : measurable_set[m] {x | g x \u2264 0},\n    from hg.measurable_set_le (@strongly_measurable_const _ _ m _ _),\n  have h_meas_nonpos_f : measurable_set {x | f x \u2264 0},\n    from hf.measurable_set_le strongly_measurable_const,\n  refine sub_le_sub _ _,\n  { rw [measure.restrict_restrict (hm _ h_meas_nonneg_g),\n      measure.restrict_restrict h_meas_nonneg_f,\n      hgf _ (@measurable_set.inter \u03b1 m _ _ h_meas_nonneg_g hs)\n        ((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonneg_g),\n      \u2190 measure.restrict_restrict h_meas_nonneg_f],\n    exact set_integral_le_nonneg (hm _ h_meas_nonneg_g) hf hfi, },\n  { rw [measure.restrict_restrict (hm _ h_meas_nonpos_g),\n      measure.restrict_restrict h_meas_nonpos_f,\n      hgf _ (@measurable_set.inter \u03b1 m _ _ h_meas_nonpos_g hs)\n        ((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr h\u03bcs)),\n      \u2190 measure.restrict_restrict (hm _ h_meas_nonpos_g),\n      \u2190 measure.restrict_restrict h_meas_nonpos_f],\n    exact set_integral_nonpos_le (hm _ h_meas_nonpos_g) hf hfi, },\nend\n\n/-- Let `m` be a sub-\u03c3-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable\nfunction, such that their integrals coincide on `m`-measurable sets with finite measure.\nThen `\u222b\u207b x in s, \u2225g x\u2225\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2225f x\u2225\u208a \u2202\u03bc` on all `m`-measurable sets with finite\nmeasure. -/\nlemma lintegral_nnnorm_le_of_forall_fin_meas_integral_eq (hm : m \u2264 m0) {f g : \u03b1 \u2192 \u211d}\n  (hf : strongly_measurable f) (hfi : integrable_on f s \u03bc)\n  (hg : strongly_measurable[m] g) (hgi : integrable_on g s \u03bc)\n  (hgf : \u2200 t, measurable_set[m] t \u2192 \u03bc t < \u221e \u2192 \u222b x in t, g x \u2202\u03bc = \u222b x in t, f x \u2202\u03bc)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b\u207b x in s, \u2225g x\u2225\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2225f x\u2225\u208a \u2202\u03bc :=\nbegin\n  rw [\u2190 of_real_integral_norm_eq_lintegral_nnnorm hfi,\n    \u2190 of_real_integral_norm_eq_lintegral_nnnorm hgi, ennreal.of_real_le_of_real_iff],\n  { exact integral_norm_le_of_forall_fin_meas_integral_eq hm hf hfi hg hgi hgf hs h\u03bcs, },\n  { exact integral_nonneg (\u03bb x, norm_nonneg _), },\nend\n\nend integral_norm_le\n\n/-! ## Conditional expectation in L2\n\nWe define a conditional expectation in `L2`: it is the orthogonal projection on the subspace\n`Lp_meas`. -/\n\nsection condexp_L2\n\nvariables [complete_space E] {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {s t : set \u03b1}\n\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c E _ x y\nlocal notation `\u27ea`x`, `y`\u27eb\u2082` := @inner \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ x y\n\nvariables (\ud835\udd5c)\n/-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/\ndef condexp_L2 (hm : m \u2264 m0) : (\u03b1 \u2192\u2082[\u03bc] E) \u2192L[\ud835\udd5c] (Lp_meas E \ud835\udd5c m 2 \u03bc) :=\n@orthogonal_projection \ud835\udd5c (\u03b1 \u2192\u2082[\u03bc] E) _ _ (Lp_meas E \ud835\udd5c m 2 \u03bc)\n  (by { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact infer_instance, })\nvariables {\ud835\udd5c}\n\nlemma ae_strongly_measurable'_condexp_L2 (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  ae_strongly_measurable' m (condexp_L2 \ud835\udd5c hm f) \u03bc :=\nLp_meas.ae_strongly_measurable' _\n\nlemma integrable_on_condexp_L2_of_measure_ne_top (hm : m \u2264 m0) (h\u03bcs : \u03bc s \u2260 \u221e) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  integrable_on (condexp_L2 \ud835\udd5c hm f) s \u03bc :=\nintegrable_on_Lp_of_measure_ne_top ((condexp_L2 \ud835\udd5c hm f) : \u03b1 \u2192\u2082[\u03bc] E)\n  fact_one_le_two_ennreal.elim h\u03bcs\n\nlemma integrable_condexp_L2_of_is_finite_measure (hm : m \u2264 m0) [is_finite_measure \u03bc]\n  {f : \u03b1 \u2192\u2082[\u03bc] E} :\n  integrable (condexp_L2 \ud835\udd5c hm f) \u03bc :=\nintegrable_on_univ.mp $ integrable_on_condexp_L2_of_measure_ne_top hm (measure_ne_top _ _) f\n\nlemma norm_condexp_L2_le_one (hm : m \u2264 m0) : \u2225@condexp_L2 \u03b1 E \ud835\udd5c _ _ _ _ _ \u03bc hm\u2225 \u2264 1 :=\nby { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact orthogonal_projection_norm_le _, }\n\nlemma norm_condexp_L2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) : \u2225condexp_L2 \ud835\udd5c hm f\u2225 \u2264 \u2225f\u2225 :=\n((@condexp_L2 _ E \ud835\udd5c _ _ _ _ _ \u03bc hm).le_op_norm f).trans\n  (mul_le_of_le_one_left (norm_nonneg _) (norm_condexp_L2_le_one hm))\n\nlemma snorm_condexp_L2_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  snorm (condexp_L2 \ud835\udd5c hm f) 2 \u03bc \u2264 snorm f 2 \u03bc :=\nbegin\n  rw [Lp_meas_coe, \u2190 ennreal.to_real_le_to_real (Lp.snorm_ne_top _) (Lp.snorm_ne_top _),\n    \u2190 Lp.norm_def, \u2190 Lp.norm_def, submodule.norm_coe],\n  exact norm_condexp_L2_le hm f,\nend\n\nlemma norm_condexp_L2_coe_le (hm : m \u2264 m0) (f : \u03b1 \u2192\u2082[\u03bc] E) :\n  \u2225(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E)\u2225 \u2264 \u2225f\u2225 :=\nbegin\n  rw [Lp.norm_def, Lp.norm_def, \u2190 Lp_meas_coe],\n  refine (ennreal.to_real_le_to_real _ (Lp.snorm_ne_top _)).mpr (snorm_condexp_L2_le hm f),\n  exact Lp.snorm_ne_top _,\nend\n\nlemma inner_condexp_L2_left_eq_right (hm : m \u2264 m0) {f g : \u03b1 \u2192\u2082[\u03bc] E} :\n  \u27ea(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, (condexp_L2 \ud835\udd5c hm g : \u03b1 \u2192\u2082[\u03bc] E)\u27eb\u2082 :=\nby { haveI : fact (m \u2264 m0) := \u27e8hm\u27e9, exact inner_orthogonal_projection_left_eq_right _ f g, }\n\nlemma condexp_L2_indicator_of_measurable (hm : m \u2264 m0)\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : E) :\n  (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 (hm s hs) h\u03bcs c) : \u03b1 \u2192\u2082[\u03bc] E)\n    = indicator_const_Lp 2 (hm s hs) h\u03bcs c :=\nbegin\n  rw condexp_L2,\n  haveI : fact (m \u2264 m0) := \u27e8hm\u27e9,\n  have h_mem : indicator_const_Lp 2 (hm s hs) h\u03bcs c \u2208 Lp_meas E \ud835\udd5c m 2 \u03bc,\n    from mem_Lp_meas_indicator_const_Lp hm hs h\u03bcs,\n  let ind := (\u27e8indicator_const_Lp 2 (hm s hs) h\u03bcs c, h_mem\u27e9 : Lp_meas E \ud835\udd5c m 2 \u03bc),\n  have h_coe_ind : (ind : \u03b1 \u2192\u2082[\u03bc] E) = indicator_const_Lp 2 (hm s hs) h\u03bcs c, by refl,\n  have h_orth_mem := orthogonal_projection_mem_subspace_eq_self ind,\n  rw [\u2190 h_coe_ind, h_orth_mem],\nend\n\nlemma inner_condexp_L2_eq_inner_fun (hm : m \u2264 m0) (f g : \u03b1 \u2192\u2082[\u03bc] E)\n  (hg : ae_strongly_measurable' m g \u03bc) :\n  \u27ea(condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E), g\u27eb\u2082 = \u27eaf, g\u27eb\u2082 :=\nbegin\n  symmetry,\n  rw [\u2190 sub_eq_zero, \u2190 inner_sub_left, condexp_L2],\n  simp only [mem_Lp_meas_iff_ae_strongly_measurable'.mpr hg, orthogonal_projection_inner_eq_zero],\nend\n\nsection real\n\nvariables {hm : m \u2264 m0}\n\nlemma integral_condexp_L2_eq_of_fin_meas_real (f : Lp \ud835\udd5c 2 \u03bc) (hs : measurable_set[m] s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw \u2190 L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs,\n  have h_eq_inner : \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc\n    = inner (indicator_const_Lp 2 (hm s hs) h\u03bcs (1 : \ud835\udd5c)) (condexp_L2 \ud835\udd5c hm f),\n  { rw L2.inner_indicator_const_Lp_one (hm s hs) h\u03bcs,\n    congr, },\n  rw [h_eq_inner, \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable hm hs h\u03bcs],\nend\n\nlemma lintegral_nnnorm_condexp_L2_le (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (f : Lp \u211d 2 \u03bc) :\n  \u222b\u207b x in s, \u2225condexp_L2 \u211d hm f x\u2225\u208a \u2202\u03bc \u2264 \u222b\u207b x in s, \u2225f x\u2225\u208a \u2202\u03bc :=\nbegin\n  let h_meas := Lp_meas.ae_strongly_measurable' (condexp_L2 \u211d hm f),\n  let g := h_meas.some,\n  have hg_meas : strongly_measurable[m] g, from h_meas.some_spec.1,\n  have hg_eq : g =\u1d50[\u03bc] condexp_L2 \u211d hm f, from h_meas.some_spec.2.symm,\n  have hg_eq_restrict : g =\u1d50[\u03bc.restrict s] condexp_L2 \u211d hm f, from ae_restrict_of_ae hg_eq,\n  have hg_nnnorm_eq : (\u03bb x, (\u2225g x\u2225\u208a : \u211d\u22650\u221e))\n    =\u1d50[\u03bc.restrict s] (\u03bb x, (\u2225condexp_L2 \u211d hm f x\u2225\u208a : \u211d\u22650\u221e)),\n  { refine hg_eq_restrict.mono (\u03bb x hx, _),\n    dsimp only,\n    rw hx, },\n  rw lintegral_congr_ae hg_nnnorm_eq.symm,\n  refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm\n    (Lp.strongly_measurable f) _ _ _ _ hs h\u03bcs,\n  { exact integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs, },\n  { exact hg_meas, },\n  { rw [integrable_on, integrable_congr hg_eq_restrict],\n    exact integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs f, },\n  { intros t ht h\u03bct,\n    rw \u2190 integral_condexp_L2_eq_of_fin_meas_real f ht h\u03bct.ne,\n    exact set_integral_congr_ae (hm t ht) (hg_eq.mono (\u03bb x hx _, hx)), },\nend\n\nlemma condexp_L2_ae_eq_zero_of_ae_eq_zero (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  {f : Lp \u211d 2 \u03bc} (hf : f =\u1d50[\u03bc.restrict s] 0) :\n  condexp_L2 \u211d hm f =\u1d50[\u03bc.restrict s] 0 :=\nbegin\n  suffices h_nnnorm_eq_zero : \u222b\u207b x in s, \u2225condexp_L2 \u211d hm f x\u2225\u208a \u2202\u03bc = 0,\n  { rw lintegral_eq_zero_iff at h_nnnorm_eq_zero,\n    refine h_nnnorm_eq_zero.mono (\u03bb x hx, _),\n    dsimp only at hx,\n    rw pi.zero_apply at hx \u22a2,\n    { rwa [ennreal.coe_eq_zero, nnnorm_eq_zero] at hx, },\n    { refine measurable.coe_nnreal_ennreal (measurable.nnnorm _),\n      rw Lp_meas_coe,\n      exact (Lp.strongly_measurable _).measurable }, },\n  refine le_antisymm _ (zero_le _),\n  refine (lintegral_nnnorm_condexp_L2_le hs h\u03bcs f).trans (le_of_eq _),\n  rw lintegral_eq_zero_iff,\n  { refine hf.mono (\u03bb x hx, _),\n    dsimp only,\n    rw hx,\n    simp, },\n  { exact (Lp.strongly_measurable _).ennnorm, },\nend\n\nlemma lintegral_nnnorm_condexp_L2_indicator_le_real\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2225\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) :=\nbegin\n  refine (lintegral_nnnorm_condexp_L2_le ht h\u03bct _).trans (le_of_eq _),\n  have h_eq : \u222b\u207b x in t, \u2225(indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) x\u2225\u208a \u2202\u03bc\n    = \u222b\u207b x in t, s.indicator (\u03bb x, (1 : \u211d\u22650\u221e)) x \u2202\u03bc,\n  { refine lintegral_congr_ae (ae_restrict_of_ae _),\n    refine (@indicator_const_Lp_coe_fn _ _ _ 2 _ _ _ hs h\u03bcs (1 : \u211d)).mono (\u03bb x hx, _),\n    rw hx,\n    simp_rw set.indicator_apply,\n    split_ifs; simp, },\n  rw [h_eq, lintegral_indicator _ hs, lintegral_const, measure.restrict_restrict hs],\n  simp only [one_mul, set.univ_inter, measurable_set.univ, measure.restrict_apply],\nend\n\nend real\n\n/-- `condexp_L2` commutes with taking inner products with constants. See the lemma\n`condexp_L2_comp_continuous_linear_map` for a more general result about commuting with continuous\nlinear maps. -/\nlemma condexp_L2_const_inner (hm : m \u2264 m0) (f : Lp E 2 \u03bc) (c : E) :\n  condexp_L2 \ud835\udd5c hm (((Lp.mem_\u2112p f).const_inner c).to_Lp (\u03bb a, \u27eac, f a\u27eb))\n    =\u1d50[\u03bc] \u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb :=\nbegin\n  rw Lp_meas_coe,\n  have h_mem_Lp : mem_\u2112p (\u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb) 2 \u03bc,\n  { refine mem_\u2112p.const_inner _ _, rw Lp_meas_coe, exact Lp.mem_\u2112p _, },\n  have h_eq : h_mem_Lp.to_Lp _ =\u1d50[\u03bc] \u03bb a, \u27eac, condexp_L2 \ud835\udd5c hm f a\u27eb, from h_mem_Lp.coe_fn_to_Lp,\n  refine eventually_eq.trans _ h_eq,\n  refine Lp.ae_eq_of_forall_set_integral_eq' hm _ _ ennreal.zero_lt_two.ne.symm ennreal.coe_ne_top\n    (\u03bb s hs h\u03bcs, integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _) _ _ _ _,\n  { intros s hs h\u03bcs,\n    rw [integrable_on, integrable_congr (ae_restrict_of_ae h_eq)],\n    exact (integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _).const_inner _, },\n  { intros s hs h\u03bcs,\n    rw [\u2190 Lp_meas_coe, integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs.ne,\n      integral_congr_ae (ae_restrict_of_ae h_eq), Lp_meas_coe,\n      \u2190 L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c \u2191(condexp_L2 \ud835\udd5c hm f) (hm s hs) c h\u03bcs.ne,\n      \u2190 inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable,\n      L2.inner_indicator_const_Lp_eq_set_integral_inner \ud835\udd5c f (hm s hs) c h\u03bcs.ne,\n      set_integral_congr_ae (hm s hs)\n        ((mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).const_inner c)).mono (\u03bb x hx hxs, hx))], },\n  { rw \u2190 Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },\n  { refine ae_strongly_measurable'.congr _ h_eq.symm,\n    exact (Lp_meas.ae_strongly_measurable' _).const_inner _, },\nend\n\n/-- `condexp_L2` verifies the equality of integrals defining the conditional expectation. -/\nlemma integral_condexp_L2_eq (hm : m \u2264 m0)\n  (f : Lp E' 2 \u03bc) (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L2 \ud835\udd5c hm f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw [\u2190 sub_eq_zero, Lp_meas_coe, \u2190 integral_sub'\n      (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)\n      (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs)],\n  refine integral_eq_zero_of_forall_integral_inner_eq_zero _ _ _,\n  { rw integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub \u2191(condexp_L2 \ud835\udd5c hm f) f).symm),\n    exact integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs, },\n  intro c,\n  simp_rw [pi.sub_apply, inner_sub_right],\n  rw integral_sub\n    ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).const_inner c)\n    ((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs).const_inner c),\n  have h_ae_eq_f := mem_\u2112p.coe_fn_to_Lp ((Lp.mem_\u2112p f).const_inner c),\n  rw [\u2190 Lp_meas_coe, sub_eq_zero,\n    \u2190 set_integral_congr_ae (hm s hs) ((condexp_L2_const_inner hm f c).mono (\u03bb x hx _, hx)),\n    \u2190 set_integral_congr_ae (hm s hs) (h_ae_eq_f.mono (\u03bb x hx _, hx))],\n  exact integral_condexp_L2_eq_of_fin_meas_real _ hs h\u03bcs,\nend\n\nvariables {E'' \ud835\udd5c' : Type*} [is_R_or_C \ud835\udd5c']\n  [inner_product_space \ud835\udd5c' E''] [complete_space E''] [normed_space \u211d E'']\n\nvariables (\ud835\udd5c \ud835\udd5c')\nlemma condexp_L2_comp_continuous_linear_map (hm : m \u2264 m0) (T : E' \u2192L[\u211d] E'') (f : \u03b1 \u2192\u2082[\u03bc] E') :\n  (condexp_L2 \ud835\udd5c' hm (T.comp_Lp f) : \u03b1 \u2192\u2082[\u03bc] E'') =\u1d50[\u03bc] T.comp_Lp (condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E') :=\nbegin\n  refine Lp.ae_eq_of_forall_set_integral_eq' hm _ _ ennreal.zero_lt_two.ne.symm ennreal.coe_ne_top\n    (\u03bb s hs h\u03bcs, integrable_on_condexp_L2_of_measure_ne_top hm h\u03bcs.ne _)\n    (\u03bb s hs h\u03bcs, integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.ne)\n    _ _ _,\n  { intros s hs h\u03bcs,\n    rw [T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim h\u03bcs.ne),\n      \u2190 Lp_meas_coe, \u2190 Lp_meas_coe, integral_condexp_L2_eq hm f hs h\u03bcs.ne,\n      integral_condexp_L2_eq hm (T.comp_Lp f) hs h\u03bcs.ne, T.set_integral_comp_Lp _ (hm s hs),\n      T.integral_comp_comm\n        (integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim h\u03bcs.ne)], },\n  { rw \u2190 Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },\n  { have h_coe := T.coe_fn_comp_Lp (condexp_L2 \ud835\udd5c hm f : \u03b1 \u2192\u2082[\u03bc] E'),\n    rw \u2190 eventually_eq at h_coe,\n    refine ae_strongly_measurable'.congr _ h_coe.symm,\n    exact (Lp_meas.ae_strongly_measurable' (condexp_L2 \ud835\udd5c hm f)).continuous_comp T.continuous, },\nend\nvariables {\ud835\udd5c \ud835\udd5c'}\n\nsection condexp_L2_indicator\n\nvariables (\ud835\udd5c)\nlemma condexp_L2_indicator_ae_eq_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (x : E') :\n  condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x)\n    =\u1d50[\u03bc] \u03bb a, (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x :=\nbegin\n  rw indicator_const_Lp_eq_to_span_singleton_comp_Lp hs h\u03bcs x,\n  have h_comp := condexp_L2_comp_continuous_linear_map \u211d \ud835\udd5c hm (to_span_singleton \u211d x)\n    (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)),\n  rw \u2190 Lp_meas_coe at h_comp,\n  refine h_comp.trans _,\n  exact (to_span_singleton \u211d x).coe_fn_comp_Lp _,\nend\n\nlemma condexp_L2_indicator_eq_to_span_singleton_comp (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') :\n  (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) : \u03b1 \u2192\u2082[\u03bc] E')\n    = (to_span_singleton \u211d x).comp_Lp (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  refine (condexp_L2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).trans _,\n  have h_comp := (to_span_singleton \u211d x).coe_fn_comp_Lp\n    (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) : \u03b1 \u2192\u2082[\u03bc] \u211d),\n  rw \u2190 eventually_eq at h_comp,\n  refine eventually_eq.trans _ h_comp.symm,\n  refine eventually_of_forall (\u03bb y, _),\n  refl,\nend\n\nvariables {\ud835\udd5c}\n\nlemma set_lintegral_nnnorm_condexp_L2_indicator_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') {t : set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2225condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2225\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :=\ncalc \u222b\u207b a in t, \u2225condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2225\u208a \u2202\u03bc\n    = \u222b\u207b a in t, \u2225(condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x\u2225\u208a \u2202\u03bc :\nset_lintegral_congr_fun (hm t ht)\n  ((condexp_L2_indicator_ae_eq_smul \ud835\udd5c hm hs h\u03bcs x).mono (\u03bb a ha hat, by rw ha))\n... = \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2225\u208a \u2202\u03bc * \u2225x\u2225\u208a :\nbegin\n  simp_rw [nnnorm_smul, ennreal.coe_mul],\n  rw [lintegral_mul_const, Lp_meas_coe],\n  exact (Lp.strongly_measurable _).ennnorm\nend\n... \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :\n  ennreal.mul_le_mul (lintegral_nnnorm_condexp_L2_indicator_le_real hs h\u03bcs ht h\u03bct) le_rfl\n\nlemma lintegral_nnnorm_condexp_L2_indicator_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') [sigma_finite (\u03bc.trim hm)] :\n  \u222b\u207b a, \u2225condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x) a\u2225\u208a \u2202\u03bc \u2264 \u03bc s * \u2225x\u2225\u208a :=\nbegin\n  refine lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a) _ (\u03bb t ht h\u03bct, _),\n  { rw Lp_meas_coe,\n    exact (Lp.ae_strongly_measurable _).ennnorm },\n  refine (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _,\n  refine ennreal.mul_le_mul _ le_rfl,\n  exact measure_mono (set.inter_subset_left _ _),\nend\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\nlemma integrable_condexp_L2_indicator (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : E') :\n  integrable (condexp_L2 \ud835\udd5c hm (indicator_const_Lp 2 hs h\u03bcs x)) \u03bc :=\nbegin\n  refine integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a)\n    (ennreal.mul_lt_top h\u03bcs ennreal.coe_ne_top) _ _,\n  { rw Lp_meas_coe, exact Lp.ae_strongly_measurable _, },\n  { refine \u03bb t ht h\u03bct, (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs h\u03bcs x ht h\u03bct).trans _,\n    exact ennreal.mul_le_mul (measure_mono (set.inter_subset_left _ _)) le_rfl, },\nend\n\nend condexp_L2_indicator\n\nsection condexp_ind_smul\n\nvariables [normed_space \u211d G] {hm : m \u2264 m0}\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/\ndef condexp_ind_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : Lp G 2 \u03bc :=\n(to_span_singleton \u211d x).comp_LpL 2 \u03bc (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))\n\nlemma ae_strongly_measurable'_condexp_ind_smul\n  (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  ae_strongly_measurable' m (condexp_ind_smul hm hs h\u03bcs x) \u03bc :=\nbegin\n  have h : ae_strongly_measurable' m (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d))) \u03bc,\n    from ae_strongly_measurable'_condexp_L2 _ _,\n  rw condexp_ind_smul,\n  suffices : ae_strongly_measurable' m\n    ((to_span_singleton \u211d x) \u2218 (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))) \u03bc,\n  { refine ae_strongly_measurable'.congr this _,\n    refine eventually_eq.trans _ (coe_fn_comp_LpL _ _).symm,\n    rw Lp_meas_coe, },\n  exact ae_strongly_measurable'.continuous_comp (to_span_singleton \u211d x).continuous h,\nend\n\nlemma condexp_ind_smul_add (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n  condexp_ind_smul hm hs h\u03bcs (x + y)\n    = condexp_ind_smul hm hs h\u03bcs x + condexp_ind_smul hm hs h\u03bcs y :=\nby { simp_rw [condexp_ind_smul], rw [to_span_singleton_add, add_comp_LpL, add_apply], }\n\nlemma condexp_ind_smul_smul (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n  condexp_ind_smul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_smul hm hs h\u03bcs x :=\nby { simp_rw [condexp_ind_smul], rw [to_span_singleton_smul, smul_comp_LpL, smul_apply], }\n\nlemma condexp_ind_smul_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n  condexp_ind_smul hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_smul hm hs h\u03bcs x :=\nby rw [condexp_ind_smul, condexp_ind_smul, to_span_singleton_smul',\n  (to_span_singleton \u211d x).smul_comp_LpL_apply c\n  \u2191(condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)))]\n\nlemma condexp_ind_smul_ae_eq_smul (hm : m \u2264 m0) (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind_smul hm hs h\u03bcs x\n    =\u1d50[\u03bc] \u03bb a, (condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a) \u2022 x :=\n(to_span_singleton \u211d x).coe_fn_comp_LpL _\n\nlemma set_lintegral_nnnorm_condexp_ind_smul_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) {t : set \u03b1} (ht : measurable_set[m] t) (h\u03bct : \u03bc t \u2260 \u221e) :\n  \u222b\u207b a in t, \u2225condexp_ind_smul hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :=\ncalc \u222b\u207b a in t, \u2225condexp_ind_smul hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc\n    = \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a \u2022 x\u2225\u208a \u2202\u03bc :\nset_lintegral_congr_fun (hm t ht)\n  ((condexp_ind_smul_ae_eq_smul hm hs h\u03bcs x).mono (\u03bb a ha hat, by rw ha ))\n... = \u222b\u207b a in t, \u2225condexp_L2 \u211d hm (indicator_const_Lp 2 hs h\u03bcs (1 : \u211d)) a\u2225\u208a \u2202\u03bc * \u2225x\u2225\u208a :\nbegin\n  simp_rw [nnnorm_smul, ennreal.coe_mul],\n  rw [lintegral_mul_const, Lp_meas_coe],\n  exact (Lp.strongly_measurable _).ennnorm\nend\n... \u2264 \u03bc (s \u2229 t) * \u2225x\u2225\u208a :\n  ennreal.mul_le_mul (lintegral_nnnorm_condexp_L2_indicator_le_real hs h\u03bcs ht h\u03bct) le_rfl\n\nlemma lintegral_nnnorm_condexp_ind_smul_le (hm : m \u2264 m0) (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) [sigma_finite (\u03bc.trim hm)] :\n  \u222b\u207b a, \u2225condexp_ind_smul hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc \u2264 \u03bc s * \u2225x\u2225\u208a :=\nbegin\n  refine lintegral_le_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a) _ (\u03bb t ht h\u03bct, _),\n  { exact (Lp.ae_strongly_measurable _).ennnorm },\n  refine (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _,\n  refine ennreal.mul_le_mul _ le_rfl,\n  exact measure_mono (set.inter_subset_left _ _),\nend\n\n/-- If the measure `\u03bc.trim hm` is sigma-finite, then the conditional expectation of a measurable set\nwith finite measure is integrable. -/\nlemma integrable_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  integrable (condexp_ind_smul hm hs h\u03bcs x) \u03bc :=\nbegin\n  refine integrable_of_forall_fin_meas_le' hm (\u03bc s * \u2225x\u2225\u208a)\n    (ennreal.mul_lt_top h\u03bcs ennreal.coe_ne_top) _ _,\n  { exact Lp.ae_strongly_measurable _, },\n  { refine \u03bb t ht h\u03bct, (set_lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x ht h\u03bct).trans _,\n    exact ennreal.mul_le_mul (measure_mono (set.inter_subset_left _ _)) le_rfl, },\nend\n\nlemma condexp_ind_smul_empty {x : G} :\n  condexp_ind_smul hm measurable_set.empty\n    ((@measure_empty _ _ \u03bc).le.trans_lt ennreal.coe_lt_top).ne x = 0 :=\nbegin\n  rw [condexp_ind_smul, indicator_const_empty],\n  simp only [coe_fn_coe_base, submodule.coe_zero, continuous_linear_map.map_zero],\nend\n\nlemma set_integral_condexp_ind_smul (hs : measurable_set[m] s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (x : G') :\n  \u222b a in s, (condexp_ind_smul hm ht h\u03bct x) a \u2202\u03bc = (\u03bc (t \u2229 s)).to_real \u2022 x :=\ncalc \u222b a in s, (condexp_ind_smul hm ht h\u03bct x) a \u2202\u03bc\n    = (\u222b a in s, (condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) a \u2022 x) \u2202\u03bc) :\n  set_integral_congr_ae (hm s hs) ((condexp_ind_smul_ae_eq_smul hm ht h\u03bct x).mono (\u03bb x hx hxs, hx))\n... = (\u222b a in s, condexp_L2 \u211d hm (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) a \u2202\u03bc) \u2022 x :\n  integral_smul_const _ x\n... = (\u222b a in s, indicator_const_Lp 2 ht h\u03bct (1 : \u211d) a \u2202\u03bc) \u2022 x :\n  by rw @integral_condexp_L2_eq \u03b1 _ \u211d _ _ _ _ _ _ _ _ hm\n    (indicator_const_Lp 2 ht h\u03bct (1 : \u211d)) hs h\u03bcs\n... = (\u03bc (t \u2229 s)).to_real \u2022 x :\n  by rw [set_integral_indicator_const_Lp (hm s hs), smul_assoc, one_smul]\n\nend condexp_ind_smul\n\nend condexp_L2\n\nsection condexp_ind\n\n/-! ## Conditional expectation of an indicator as a continuous linear map.\n\nThe goal of this section is to build\n`condexp_ind (hm : m \u2264 m0) (\u03bc : measure \u03b1) (s : set s) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G`, which\ntakes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`,\nseen as an element of `\u03b1 \u2192\u2081[\u03bc] G`.\n-/\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1} {s t : set \u03b1} [normed_space \u211d G]\n\nsection condexp_ind_L1_fin\n\n/-- Conditional expectation of the indicator of a measurable set with finite measure,\nas a function in L1. -/\ndef condexp_ind_L1_fin (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)] (hs : measurable_set s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) : \u03b1 \u2192\u2081[\u03bc] G :=\n(integrable_condexp_ind_smul hm hs h\u03bcs x).to_L1 _\n\nlemma condexp_ind_L1_fin_ae_eq_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs x =\u1d50[\u03bc] condexp_ind_smul hm hs h\u03bcs x :=\n(integrable_condexp_ind_smul hm hs h\u03bcs x).coe_fn_to_L1\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma condexp_ind_L1_fin_add (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x y : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs (x + y)\n    = condexp_ind_L1_fin hm hs h\u03bcs x + condexp_ind_L1_fin hm hs h\u03bcs y :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  refine eventually_eq.trans _\n    (eventually_eq.add (mem_\u2112p.coe_fn_to_Lp _).symm (mem_\u2112p.coe_fn_to_Lp _).symm),\n  rw condexp_ind_smul_add,\n  refine (Lp.coe_fn_add _ _).trans (eventually_of_forall (\u03bb a, _)),\n  refl,\nend\n\nlemma condexp_ind_L1_fin_smul (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \u211d) (x : G) :\n  condexp_ind_L1_fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_L1_fin hm hs h\u03bcs x :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  rw condexp_ind_smul_smul hs h\u03bcs c x,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb y hy, _),\n  rw [pi.smul_apply, pi.smul_apply, hy],\nend\n\nlemma condexp_ind_L1_fin_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : \ud835\udd5c) (x : F) :\n  condexp_ind_L1_fin hm hs h\u03bcs (c \u2022 x) = c \u2022 condexp_ind_L1_fin hm hs h\u03bcs x :=\nbegin\n  ext1,\n  refine (mem_\u2112p.coe_fn_to_Lp _).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,\n  rw condexp_ind_smul_smul' hs h\u03bcs c x,\n  refine (Lp.coe_fn_smul _ _).trans _,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb y hy, _),\n  rw [pi.smul_apply, pi.smul_apply, hy],\nend\n\nlemma norm_condexp_ind_L1_fin_le (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  \u2225condexp_ind_L1_fin hm hs h\u03bcs x\u2225 \u2264 (\u03bc s).to_real * \u2225x\u2225 :=\nbegin\n  have : 0 \u2264 \u222b (a : \u03b1), \u2225condexp_ind_L1_fin hm hs h\u03bcs x a\u2225 \u2202\u03bc,\n    from integral_nonneg (\u03bb a, norm_nonneg _),\n  rw [L1.norm_eq_integral_norm, \u2190 ennreal.to_real_of_real (norm_nonneg x), \u2190 ennreal.to_real_mul,\n    \u2190 ennreal.to_real_of_real this, ennreal.to_real_le_to_real ennreal.of_real_ne_top\n      (ennreal.mul_ne_top h\u03bcs ennreal.of_real_ne_top),\n    of_real_integral_norm_eq_lintegral_nnnorm],\n  swap, { rw [\u2190 mem_\u2112p_one_iff_integrable], exact Lp.mem_\u2112p _, },\n  have h_eq : \u222b\u207b a, \u2225condexp_ind_L1_fin hm hs h\u03bcs x a\u2225\u208a \u2202\u03bc\n    = \u222b\u207b a, nnnorm (condexp_ind_smul hm hs h\u03bcs x a) \u2202\u03bc,\n  { refine lintegral_congr_ae _,\n    refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x).mono (\u03bb z hz, _),\n    dsimp only,\n    rw hz, },\n  rw [h_eq, of_real_norm_eq_coe_nnnorm],\n  exact lintegral_nnnorm_condexp_ind_smul_le hm hs h\u03bcs x,\nend\n\nlemma condexp_ind_L1_fin_disjoint_union (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind_L1_fin hm (hs.union ht) ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne x\n  = condexp_ind_L1_fin hm hs h\u03bcs x + condexp_ind_L1_fin hm ht h\u03bct x :=\nbegin\n  ext1,\n  have h\u03bcst := ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne,\n  refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm (hs.union ht) h\u03bcst x).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,\n  have hs_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x,\n  have ht_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm ht h\u03bct x,\n  refine eventually_eq.trans _ (eventually_eq.add hs_eq.symm ht_eq.symm),\n  rw condexp_ind_smul,\n  rw indicator_const_Lp_disjoint_union hs ht h\u03bcs h\u03bct hst (1 : \u211d),\n  rw (condexp_L2 \u211d hm).map_add,\n  push_cast,\n  rw ((to_span_singleton \u211d x).comp_LpL 2 \u03bc).map_add,\n  refine (Lp.coe_fn_add _ _).trans _,\n  refine eventually_of_forall (\u03bb y, _),\n  refl,\nend\n\nend condexp_ind_L1_fin\n\nopen_locale classical\n\nsection condexp_ind_L1\n\n/-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets\nwhich are not both measurable and of finite measure is not used: we set it to 0. -/\ndef condexp_ind_L1 {m m0 : measurable_space \u03b1} (hm : m \u2264 m0) (\u03bc : measure \u03b1) (s : set \u03b1)\n  [sigma_finite (\u03bc.trim hm)] (x : G) :\n  \u03b1 \u2192\u2081[\u03bc] G :=\nif hs : measurable_set s \u2227 \u03bc s \u2260 \u221e then condexp_ind_L1_fin hm hs.1 hs.2 x else 0\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (x : G) :\n  condexp_ind_L1 hm \u03bc s x = condexp_ind_L1_fin hm hs h\u03bcs x :=\nby simp only [condexp_ind_L1, and.intro hs h\u03bcs, dif_pos, ne.def, not_false_iff, and_self]\n\nlemma condexp_ind_L1_of_measure_eq_top (h\u03bcs : \u03bc s = \u221e) (x : G) :\n  condexp_ind_L1 hm \u03bc s x = 0 :=\nby simp only [condexp_ind_L1, h\u03bcs, eq_self_iff_true, not_true, ne.def, dif_neg, not_false_iff,\n  and_false]\n\nlemma condexp_ind_L1_of_not_measurable_set (hs : \u00ac measurable_set s) (x : G) :\n  condexp_ind_L1 hm \u03bc s x = 0 :=\nby simp only [condexp_ind_L1, hs, dif_neg, not_false_iff, false_and]\n\nlemma condexp_ind_L1_add (x y : G) :\n  condexp_ind_L1 hm \u03bc s (x + y) = condexp_ind_L1 hm \u03bc s x + condexp_ind_L1 hm \u03bc s y :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw zero_add, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw zero_add, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_add hs h\u03bcs x y, },\nend\n\nlemma condexp_ind_L1_smul (c : \u211d) (x : G) :\n  condexp_ind_L1 hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind_L1 hm \u03bc s x :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw smul_zero, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_smul hs h\u03bcs c x, },\nend\n\nlemma condexp_ind_L1_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n  condexp_ind_L1 hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind_L1 hm \u03bc s x :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { simp_rw condexp_ind_L1_of_measure_eq_top h\u03bcs, rw smul_zero, },\n  { simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs,\n    exact condexp_ind_L1_fin_smul' hs h\u03bcs c x, },\nend\n\nlemma norm_condexp_ind_L1_le (x : G) :\n  \u2225condexp_ind_L1 hm \u03bc s x\u2225 \u2264 (\u03bc s).to_real * \u2225x\u2225 :=\nbegin\n  by_cases hs : measurable_set s,\n  swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw Lp.norm_zero,\n    exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },\n  by_cases h\u03bcs : \u03bc s = \u221e,\n  { rw [condexp_ind_L1_of_measure_eq_top h\u03bcs x, Lp.norm_zero],\n    exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },\n  { rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x,\n    exact norm_condexp_ind_L1_fin_le hs h\u03bcs x, },\nend\n\nlemma continuous_condexp_ind_L1 : continuous (\u03bb x : G, condexp_ind_L1 hm \u03bc s x) :=\ncontinuous_of_linear_of_bound condexp_ind_L1_add condexp_ind_L1_smul norm_condexp_ind_L1_le\n\nlemma condexp_ind_L1_disjoint_union (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind_L1 hm \u03bc (s \u222a t) x = condexp_ind_L1 hm \u03bc s x + condexp_ind_L1 hm \u03bc t x :=\nbegin\n  have h\u03bcst : \u03bc (s \u222a t) \u2260 \u221e, from ((measure_union_le s t).trans_lt\n    (lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr \u27e8h\u03bcs, h\u03bct\u27e9))).ne,\n  rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs h\u03bcs x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top ht h\u03bct x,\n    condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs.union ht) h\u03bcst x],\n  exact condexp_ind_L1_fin_disjoint_union hs ht h\u03bcs h\u03bct hst x,\nend\n\nend condexp_ind_L1\n\n/-- Conditional expectation of the indicator of a set, as a linear map from `G` to L1. -/\ndef condexp_ind {m m0 : measurable_space \u03b1} (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)]\n  (s : set \u03b1) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G :=\n{ to_fun    := condexp_ind_L1 hm \u03bc s,\n  map_add'  := condexp_ind_L1_add,\n  map_smul' := condexp_ind_L1_smul,\n  cont      := continuous_condexp_ind_L1, }\n\nlemma condexp_ind_ae_eq_condexp_ind_smul (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  condexp_ind hm \u03bc s x =\u1d50[\u03bc] condexp_ind_smul hm hs h\u03bcs x :=\nbegin\n  refine eventually_eq.trans _ (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs h\u03bcs x),\n  simp [condexp_ind, condexp_ind_L1, hs, h\u03bcs],\nend\n\nvariables {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)]\n\nlemma ae_strongly_measurable'_condexp_ind (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : G) :\n  ae_strongly_measurable' m (condexp_ind hm \u03bc s x) \u03bc :=\nae_strongly_measurable'.congr (ae_strongly_measurable'_condexp_ind_smul hm hs h\u03bcs x)\n  (condexp_ind_ae_eq_condexp_ind_smul hm hs h\u03bcs x).symm\n\n@[simp] lemma condexp_ind_empty : condexp_ind hm \u03bc \u2205 = (0 : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) :=\nbegin\n  ext1,\n  ext1,\n  refine (condexp_ind_ae_eq_condexp_ind_smul hm measurable_set.empty (by simp) x).trans _,\n  rw condexp_ind_smul_empty,\n  refine (Lp.coe_fn_zero G 2 \u03bc).trans _,\n  refine eventually_eq.trans _ (Lp.coe_fn_zero G 1 \u03bc).symm,\n  refl,\nend\n\nlemma condexp_ind_smul' [normed_space \u211d F] [smul_comm_class \u211d \ud835\udd5c F] (c : \ud835\udd5c) (x : F) :\n  condexp_ind hm \u03bc s (c \u2022 x) = c \u2022 condexp_ind hm \u03bc s x :=\ncondexp_ind_L1_smul' c x\n\nlemma norm_condexp_ind_apply_le (x : G) : \u2225condexp_ind hm \u03bc s x\u2225 \u2264 (\u03bc s).to_real * \u2225x\u2225 :=\nnorm_condexp_ind_L1_le x\n\nlemma norm_condexp_ind_le : \u2225(condexp_ind hm \u03bc s : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G)\u2225 \u2264 (\u03bc s).to_real :=\ncontinuous_linear_map.op_norm_le_bound _ ennreal.to_real_nonneg norm_condexp_ind_apply_le\n\nlemma condexp_ind_disjoint_union_apply (hs : measurable_set s) (ht : measurable_set t)\n  (h\u03bcs : \u03bc s \u2260 \u221e) (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) (x : G) :\n  condexp_ind hm \u03bc (s \u222a t) x = condexp_ind hm \u03bc s x + condexp_ind hm \u03bc t x :=\ncondexp_ind_L1_disjoint_union hs ht h\u03bcs h\u03bct hst x\n\nlemma condexp_ind_disjoint_union (hs : measurable_set s) (ht : measurable_set t) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (h\u03bct : \u03bc t \u2260 \u221e) (hst : s \u2229 t = \u2205) :\n  (condexp_ind hm \u03bc (s \u222a t) : G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) = condexp_ind hm \u03bc s + condexp_ind hm \u03bc t :=\nby { ext1, push_cast, exact condexp_ind_disjoint_union_apply hs ht h\u03bcs h\u03bct hst x, }\n\nvariables (G)\n\nlemma dominated_fin_meas_additive_condexp_ind (hm : m \u2264 m0) (\u03bc : measure \u03b1)\n  [sigma_finite (\u03bc.trim hm)] :\n  dominated_fin_meas_additive \u03bc (condexp_ind hm \u03bc : set \u03b1 \u2192 G \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] G) 1 :=\n\u27e8\u03bb s t, condexp_ind_disjoint_union, \u03bb s _ _, norm_condexp_ind_le.trans (one_mul _).symm.le\u27e9\n\nvariables {G}\n\nlemma set_integral_condexp_ind (hs : measurable_set[m] s) (ht : measurable_set t) (h\u03bcs : \u03bc s \u2260 \u221e)\n  (h\u03bct : \u03bc t \u2260 \u221e) (x : G') :\n  \u222b a in s, condexp_ind hm \u03bc t x a \u2202\u03bc = (\u03bc (t \u2229 s)).to_real \u2022 x :=\ncalc\n\u222b a in s, condexp_ind hm \u03bc t x a \u2202\u03bc = \u222b a in s, condexp_ind_smul hm ht h\u03bct x a \u2202\u03bc :\n  set_integral_congr_ae (hm s hs)\n    ((condexp_ind_ae_eq_condexp_ind_smul hm ht h\u03bct x).mono (\u03bb x hx hxs, hx))\n... = (\u03bc (t \u2229 s)).to_real \u2022 x : set_integral_condexp_ind_smul hs ht h\u03bcs h\u03bct x\n\nlemma condexp_ind_of_measurable (hs : measurable_set[m] s) (h\u03bcs : \u03bc s \u2260 \u221e) (c : G) :\n  condexp_ind hm \u03bc s c = indicator_const_Lp 1 (hm s hs) h\u03bcs c :=\nbegin\n  ext1,\n  refine eventually_eq.trans _ indicator_const_Lp_coe_fn.symm,\n  refine (condexp_ind_ae_eq_condexp_ind_smul hm (hm s hs) h\u03bcs c).trans _,\n  refine (condexp_ind_smul_ae_eq_smul hm (hm s hs) h\u03bcs c).trans _,\n  rw [Lp_meas_coe, condexp_L2_indicator_of_measurable hm hs h\u03bcs (1 : \u211d)],\n  refine (@indicator_const_Lp_coe_fn \u03b1 _ _ 2 \u03bc _ s (hm s hs) h\u03bcs (1 : \u211d)).mono (\u03bb x hx, _),\n  dsimp only,\n  rw hx,\n  by_cases hx_mem : x \u2208 s; simp [hx_mem],\nend\n\nend condexp_ind\n\nsection condexp_L1\n\nvariables {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)] {f g : \u03b1 \u2192 F'} {s : set \u03b1}\n\n/-- Conditional expectation of a function as a linear map from `\u03b1 \u2192\u2081[\u03bc] F'` to itself. -/\ndef condexp_L1_clm (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)] :\n  (\u03b1 \u2192\u2081[\u03bc] F') \u2192L[\u211d] \u03b1 \u2192\u2081[\u03bc] F' :=\nL1.set_to_L1 (dominated_fin_meas_additive_condexp_ind F' hm \u03bc)\n\nlemma condexp_L1_clm_smul (c : \ud835\udd5c) (f : \u03b1 \u2192\u2081[\u03bc] F') :\n  condexp_L1_clm hm \u03bc (c \u2022 f) = c \u2022 condexp_L1_clm hm \u03bc f :=\nL1.set_to_L1_smul (dominated_fin_meas_additive_condexp_ind F' hm \u03bc)\n  (\u03bb c s x, condexp_ind_smul' c x) c f\n\nlemma condexp_L1_clm_indicator_const_Lp (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n  (condexp_L1_clm hm \u03bc) (indicator_const_Lp 1 hs h\u03bcs x) = condexp_ind hm \u03bc s x :=\nL1.set_to_L1_indicator_const_Lp (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hs h\u03bcs x\n\nlemma condexp_L1_clm_indicator_const (hs : measurable_set s) (h\u03bcs : \u03bc s \u2260 \u221e) (x : F') :\n  (condexp_L1_clm hm \u03bc) \u2191(simple_func.indicator_const 1 hs h\u03bcs x) = condexp_ind hm \u03bc s x :=\nby { rw Lp.simple_func.coe_indicator_const, exact condexp_L1_clm_indicator_const_Lp hs h\u03bcs x, }\n\n/-- Auxiliary lemma used in the proof of `set_integral_condexp_L1_clm`. -/\nlemma set_integral_condexp_L1_clm_of_measure_ne_top (f : \u03b1 \u2192\u2081[\u03bc] F') (hs : measurable_set[m] s)\n  (h\u03bcs : \u03bc s \u2260 \u221e) :\n  \u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  refine Lp.induction ennreal.one_ne_top\n    (\u03bb f : \u03b1 \u2192\u2081[\u03bc] F', \u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc)\n  _ _ (is_closed_eq _ _) f,\n  { intros x t ht h\u03bct,\n    simp_rw condexp_L1_clm_indicator_const ht h\u03bct.ne x,\n    rw [Lp.simple_func.coe_indicator_const, set_integral_indicator_const_Lp (hm _ hs)],\n    exact set_integral_condexp_ind hs ht h\u03bcs h\u03bct.ne x, },\n  { intros f g hf_Lp hg_Lp hfg_disj hf hg,\n    simp_rw (condexp_L1_clm hm \u03bc).map_add,\n    rw set_integral_congr_ae (hm s hs) ((Lp.coe_fn_add (condexp_L1_clm hm \u03bc (hf_Lp.to_Lp f))\n      (condexp_L1_clm hm \u03bc (hg_Lp.to_Lp g))).mono (\u03bb x hx hxs, hx)),\n    rw set_integral_congr_ae (hm s hs) ((Lp.coe_fn_add (hf_Lp.to_Lp f) (hg_Lp.to_Lp g)).mono\n      (\u03bb x hx hxs, hx)),\n    simp_rw pi.add_apply,\n    rw [integral_add (L1.integrable_coe_fn _).integrable_on (L1.integrable_coe_fn _).integrable_on,\n      integral_add (L1.integrable_coe_fn _).integrable_on (L1.integrable_coe_fn _).integrable_on,\n      hf, hg], },\n  { exact (continuous_set_integral s).comp (condexp_L1_clm hm \u03bc).continuous, },\n  { exact continuous_set_integral s, },\nend\n\n/-- The integral of the conditional expectation `condexp_L1_clm` over an `m`-measurable set is equal\nto the integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\nlemma set_integral_condexp_L1_clm (f : \u03b1 \u2192\u2081[\u03bc] F') (hs : measurable_set[m] s) :\n  \u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  let S := spanning_sets (\u03bc.trim hm),\n  have hS_meas : \u2200 i, measurable_set[m] (S i) := measurable_spanning_sets (\u03bc.trim hm),\n  have hS_meas0 : \u2200 i, measurable_set (S i) := \u03bb i, hm _ (hS_meas i),\n  have hs_eq : s = \u22c3 i, S i \u2229 s,\n  { simp_rw set.inter_comm,\n    rw [\u2190 set.inter_Union, (Union_spanning_sets (\u03bc.trim hm)), set.inter_univ], },\n  have hS_finite : \u2200 i, \u03bc (S i \u2229 s) < \u221e,\n  { refine \u03bb i, (measure_mono (set.inter_subset_left _ _)).trans_lt _,\n    have hS_finite_trim := measure_spanning_sets_lt_top (\u03bc.trim hm) i,\n    rwa trim_measurable_set_eq hm (hS_meas i) at hS_finite_trim, },\n  have h_mono : monotone (\u03bb i, (S i) \u2229 s),\n  { intros i j hij x,\n    simp_rw set.mem_inter_iff,\n    exact \u03bb h, \u27e8monotone_spanning_sets (\u03bc.trim hm) hij h.1, h.2\u27e9, },\n  have h_eq_forall : (\u03bb i, \u222b x in (S i) \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc)\n      = \u03bb i, \u222b x in (S i) \u2229 s, f x \u2202\u03bc,\n    from funext (\u03bb i, set_integral_condexp_L1_clm_of_measure_ne_top f\n      (@measurable_set.inter \u03b1 m _ _ (hS_meas i) hs) (hS_finite i).ne),\n  have h_right : tendsto (\u03bb i, \u222b x in (S i) \u2229 s, f x \u2202\u03bc) at_top (\ud835\udcdd (\u222b x in s, f x \u2202\u03bc)),\n  { have h := tendsto_set_integral_of_monotone (\u03bb i, (hS_meas0 i).inter (hm s hs)) h_mono\n      (L1.integrable_coe_fn f).integrable_on,\n    rwa \u2190 hs_eq at h, },\n  have h_left : tendsto (\u03bb i, \u222b x in (S i) \u2229 s, condexp_L1_clm hm \u03bc f x \u2202\u03bc) at_top\n    (\ud835\udcdd (\u222b x in s, condexp_L1_clm hm \u03bc f x \u2202\u03bc)),\n  { have h := tendsto_set_integral_of_monotone (\u03bb i, (hS_meas0 i).inter (hm s hs))\n      h_mono (L1.integrable_coe_fn (condexp_L1_clm hm \u03bc f)).integrable_on,\n    rwa \u2190 hs_eq at h, },\n  rw h_eq_forall at h_left,\n  exact tendsto_nhds_unique h_left h_right,\nend\n\nlemma ae_strongly_measurable'_condexp_L1_clm (f : \u03b1 \u2192\u2081[\u03bc] F') :\n  ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc :=\nbegin\n  refine Lp.induction ennreal.one_ne_top\n    (\u03bb f : \u03b1 \u2192\u2081[\u03bc] F', ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc)\n    _ _ _ f,\n  { intros c s hs h\u03bcs,\n    rw condexp_L1_clm_indicator_const hs h\u03bcs.ne c,\n    exact ae_strongly_measurable'_condexp_ind hs h\u03bcs.ne c, },\n  { intros f g hf hg h_disj hfm hgm,\n    rw (condexp_L1_clm hm \u03bc).map_add,\n    refine ae_strongly_measurable'.congr _ (coe_fn_add _ _).symm,\n    exact ae_strongly_measurable'.add hfm hgm, },\n  { have : {f : Lp F' 1 \u03bc | ae_strongly_measurable' m (condexp_L1_clm hm \u03bc f) \u03bc}\n        = (condexp_L1_clm hm \u03bc) \u207b\u00b9' {f | ae_strongly_measurable' m f \u03bc},\n      by refl,\n    rw this,\n    refine is_closed.preimage (condexp_L1_clm hm \u03bc).continuous _,\n    exact is_closed_ae_strongly_measurable' hm, },\nend\n\nlemma Lp_meas_to_Lp_trim_lie_symm_indicator [normed_space \u211d F] {\u03bc : measure \u03b1}\n  (hs : measurable_set[m] s) (h\u03bcs : \u03bc.trim hm s \u2260 \u221e) (c : F) :\n  ((Lp_meas_to_Lp_trim_lie F \u211d 1 \u03bc hm).symm\n      (indicator_const_Lp 1 hs h\u03bcs c) : \u03b1 \u2192\u2081[\u03bc] F)\n    = indicator_const_Lp 1 (hm s hs) ((le_trim hm).trans_lt h\u03bcs.lt_top).ne c :=\nbegin\n  ext1,\n  rw \u2190 Lp_meas_coe,\n  change Lp_trim_to_Lp_meas F \u211d 1 \u03bc hm (indicator_const_Lp 1 hs h\u03bcs c)\n    =\u1d50[\u03bc] (indicator_const_Lp 1 _ _ c : \u03b1 \u2192 F),\n  refine (Lp_trim_to_Lp_meas_ae_eq hm _).trans _,\n  exact (ae_eq_of_ae_eq_trim indicator_const_Lp_coe_fn).trans indicator_const_Lp_coe_fn.symm,\nend\n\nlemma condexp_L1_clm_Lp_meas (f : Lp_meas F' \u211d m 1 \u03bc) :\n  condexp_L1_clm hm \u03bc (f : \u03b1 \u2192\u2081[\u03bc] F') = \u2191f :=\nbegin\n  let g := Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm f,\n  have hfg : f = (Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g,\n    by simp only [linear_isometry_equiv.symm_apply_apply],\n  rw hfg,\n  refine @Lp.induction \u03b1 F' m _ 1 (\u03bc.trim hm) _ ennreal.coe_ne_top\n    (\u03bb g : \u03b1 \u2192\u2081[\u03bc.trim hm] F',\n      condexp_L1_clm hm \u03bc ((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g : \u03b1 \u2192\u2081[\u03bc] F')\n        = \u2191((Lp_meas_to_Lp_trim_lie F' \u211d 1 \u03bc hm).symm g)) _ _ _ g,\n  { intros c s hs h\u03bcs,\n    rw [Lp.simple_func.coe_indicator_const, Lp_meas_to_Lp_trim_lie_symm_indicator hs h\u03bcs.ne c,\n      condexp_L1_clm_indicator_const_Lp],\n    exact condexp_ind_of_measurable hs ((le_trim hm).trans_lt h\u03bcs).ne c, },\n  { intros f g hf hg hfg_disj hf_eq hg_eq,\n    rw linear_isometry_equiv.map_add,\n    push_cast,\n    rw [map_add, hf_eq, hg_eq], },\n  { refine is_closed_eq _ _,\n    { refine (condexp_L1_clm hm \u03bc).continuous.comp (continuous_induced_dom.comp _),\n      exact linear_isometry_equiv.continuous _, },\n    { refine continuous_induced_dom.comp _,\n      exact linear_isometry_equiv.continuous _, }, },\nend\n\nlemma condexp_L1_clm_of_ae_strongly_measurable'\n  (f : \u03b1 \u2192\u2081[\u03bc] F') (hfm : ae_strongly_measurable' m f \u03bc) :\n  condexp_L1_clm hm \u03bc f = f :=\ncondexp_L1_clm_Lp_meas (\u27e8f, hfm\u27e9 : Lp_meas F' \u211d m 1 \u03bc)\n\n/-- Conditional expectation of a function, in L1. Its value is 0 if the function is not\nintegrable. The function-valued `condexp` should be used instead in most cases. -/\ndef condexp_L1 (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)] (f : \u03b1 \u2192 F') : \u03b1 \u2192\u2081[\u03bc] F' :=\nset_to_fun \u03bc (condexp_ind hm \u03bc) (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) f\n\nlemma condexp_L1_undef (hf : \u00ac integrable f \u03bc) : condexp_L1 hm \u03bc f = 0 :=\nset_to_fun_undef (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hf\n\nlemma condexp_L1_eq (hf : integrable f \u03bc) :\n  condexp_L1 hm \u03bc f = condexp_L1_clm hm \u03bc (hf.to_L1 f) :=\nset_to_fun_eq (dominated_fin_meas_additive_condexp_ind F' hm \u03bc) hf\n\nlemma condexp_L1_zero : condexp_L1 hm \u03bc (0 : \u03b1 \u2192 F') = 0 :=\nset_to_fun_zero _\n\nlemma ae_strongly_measurable'_condexp_L1 {f : \u03b1 \u2192 F'} :\n  ae_strongly_measurable' m (condexp_L1 hm \u03bc f) \u03bc :=\nbegin\n  by_cases hf : integrable f \u03bc,\n  { rw condexp_L1_eq hf,\n    exact ae_strongly_measurable'_condexp_L1_clm _, },\n  { rw condexp_L1_undef hf,\n    refine ae_strongly_measurable'.congr _ (coe_fn_zero _ _ _).symm,\n    exact strongly_measurable.ae_strongly_measurable' (@strongly_measurable_zero _ _ m _ _), },\nend\n\nlemma integrable_condexp_L1 (f : \u03b1 \u2192 F') : integrable (condexp_L1 hm \u03bc f) \u03bc :=\nL1.integrable_coe_fn _\n\n/-- The integral of the conditional expectation `condexp_L1` over an `m`-measurable set is equal to\nthe integral of `f` on that set. See also `set_integral_condexp`, the similar statement for\n`condexp`. -/\nlemma set_integral_condexp_L1 (hf : integrable f \u03bc) (hs : measurable_set[m] s) :\n  \u222b x in s, condexp_L1 hm \u03bc f x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  simp_rw condexp_L1_eq hf,\n  rw set_integral_condexp_L1_clm (hf.to_L1 f) hs,\n  exact set_integral_congr_ae (hm s hs) ((hf.coe_fn_to_L1).mono (\u03bb x hx hxs, hx)),\nend\n\nlemma condexp_L1_add (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  condexp_L1 hm \u03bc (f + g) = condexp_L1 hm \u03bc f + condexp_L1 hm \u03bc g :=\nset_to_fun_add _ hf hg\n\nlemma condexp_L1_neg (f : \u03b1 \u2192 F') : condexp_L1 hm \u03bc (-f) = - condexp_L1 hm \u03bc f :=\nset_to_fun_neg _ f\n\nlemma condexp_L1_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : condexp_L1 hm \u03bc (c \u2022 f) = c \u2022 condexp_L1 hm \u03bc f :=\nset_to_fun_smul _ (\u03bb c _ x, condexp_ind_smul' c x) c f\n\nlemma condexp_L1_sub (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  condexp_L1 hm \u03bc (f - g) = condexp_L1 hm \u03bc f - condexp_L1 hm \u03bc g :=\nset_to_fun_sub _ hf hg\n\nlemma condexp_L1_of_ae_strongly_measurable'\n  (hfm : ae_strongly_measurable' m f \u03bc) (hfi : integrable f \u03bc) :\n  condexp_L1 hm \u03bc f =\u1d50[\u03bc] f :=\nbegin\n  rw condexp_L1_eq hfi,\n  refine eventually_eq.trans _ (integrable.coe_fn_to_L1 hfi),\n  rw condexp_L1_clm_of_ae_strongly_measurable',\n  exact ae_strongly_measurable'.congr hfm (integrable.coe_fn_to_L1 hfi).symm,\nend\n\nend condexp_L1\n\nsection condexp\n\n/-! ### Conditional expectation of a function -/\n\nopen_locale classical\n\nvariables {\ud835\udd5c} {m m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  {hm : m \u2264 m0} [sigma_finite (\u03bc.trim hm)] {f g : \u03b1 \u2192 F'} {s : set \u03b1}\n\nvariables (m)\n/-- Conditional expectation of a function. Its value is 0 if the function is not integrable. -/\n@[irreducible] def condexp (hm : m \u2264 m0) (\u03bc : measure \u03b1) [sigma_finite (\u03bc.trim hm)] (f : \u03b1 \u2192 F') :\n  \u03b1 \u2192 F' :=\nif (strongly_measurable[m] f \u2227 integrable f \u03bc) then f\nelse ae_strongly_measurable'_condexp_L1.mk (condexp_L1 hm \u03bc f)\n\nvariables {m}\n\n-- We define notations `\u03bc[f|hm]` and `\u03bc[f|m,hm]` for the conditional expectation of `f` with\n-- respect to `m`. Both can be used in code but only the second one will be used by the goal view.\n-- The first notation avoids the repetition of `m`, which is already present in `hm`. The second\n-- one ensures that `m` stays visible in the goal view: when `hm` is complicated, it gets rendered\n-- as `_` and the measurable space would not be visible in `\u03bc[f|_]`, but is clear in `\u03bc[f|m,_]`.\nlocalized \"notation  \u03bc `[` f `|` hm `]` := measure_theory.condexp _ hm \u03bc f\" in measure_theory\nlocalized \"notation  \u03bc `[` f `|` m `,` hm `]` := measure_theory.condexp m hm \u03bc f\" in measure_theory\n\nlemma condexp_of_strongly_measurable\n  {f : \u03b1 \u2192 F'} (hf : strongly_measurable[m] f) (hfi : integrable f \u03bc) :\n  \u03bc[f|m,hm] = f :=\nby rw [condexp, if_pos (\u27e8hf, hfi\u27e9 : strongly_measurable[m] f \u2227 integrable f \u03bc)]\n\nlemma condexp_const (c : F') [is_finite_measure \u03bc] : \u03bc[(\u03bb x : \u03b1, c)|m,hm] = \u03bb _, c :=\ncondexp_of_strongly_measurable (@strongly_measurable_const _ _ m _ _) (integrable_const c)\n\nlemma condexp_ae_eq_condexp_L1 (f : \u03b1 \u2192 F') : \u03bc[f|m,hm] =\u1d50[\u03bc] condexp_L1 hm \u03bc f :=\nbegin\n  unfold condexp,\n  by_cases hfm : strongly_measurable[m] f,\n  { by_cases hfi : integrable f \u03bc,\n    { rw if_pos (\u27e8hfm, hfi\u27e9 : strongly_measurable[m] f \u2227 integrable f \u03bc),\n      exact (condexp_L1_of_ae_strongly_measurable'\n        (strongly_measurable.ae_strongly_measurable' hfm) hfi).symm, },\n    { simp only [hfi, if_false, and_false],\n      exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm, }, },\n  simp only [hfm, if_false, false_and],\n  exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm,\nend\n\nlemma condexp_ae_eq_condexp_L1_clm (hf : integrable f \u03bc) :\n  \u03bc[f|m,hm] =\u1d50[\u03bc] condexp_L1_clm hm \u03bc (hf.to_L1 f) :=\nbegin\n  refine (condexp_ae_eq_condexp_L1 f).trans (eventually_of_forall (\u03bb x, _)),\n  rw condexp_L1_eq hf,\nend\n\nlemma condexp_undef (hf : \u00ac integrable f \u03bc) : \u03bc[f|m,hm] =\u1d50[\u03bc] 0 :=\nbegin\n  refine (condexp_ae_eq_condexp_L1 f).trans (eventually_eq.trans _ (coe_fn_zero _ 1 _)),\n  rw condexp_L1_undef hf,\nend\n\n@[simp] lemma condexp_zero : \u03bc[(0 : \u03b1 \u2192 F')|m,hm] = 0 :=\ncondexp_of_strongly_measurable (@strongly_measurable_zero _ _ m _ _) (integrable_zero _ _ _)\n\nlemma strongly_measurable_condexp : strongly_measurable[m] (\u03bc[f|m,hm]) :=\nbegin\n  unfold condexp,\n  by_cases hfm : strongly_measurable[m] f,\n  { by_cases hfi : integrable f \u03bc,\n    { rwa if_pos (\u27e8hfm, hfi\u27e9 : strongly_measurable[m] f \u2227 integrable f \u03bc), },\n    { simp only [hfi, if_false, and_false],\n      exact ae_strongly_measurable'.strongly_measurable_mk _, }, },\n  simp only [hfm, if_false, false_and],\n  exact ae_strongly_measurable'.strongly_measurable_mk _,\nend\n\nlemma integrable_condexp : integrable (\u03bc[f|m,hm]) \u03bc :=\n(integrable_condexp_L1 f).congr (condexp_ae_eq_condexp_L1 f).symm\n\nvariable (hm)\n\n/-- The integral of the conditional expectation `\u03bc[f|hm]` over an `m`-measurable set is equal to\nthe integral of `f` on that set. -/\nlemma set_integral_condexp (hf : integrable f \u03bc) (hs : measurable_set[m] s) :\n  \u222b x in s, \u03bc[f|m,hm] x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc :=\nbegin\n  rw set_integral_congr_ae (hm s hs) ((condexp_ae_eq_condexp_L1 f).mono (\u03bb x hx _, hx)),\n  exact set_integral_condexp_L1 hf hs,\nend\n\nvariable {hm}\n\nlemma integral_condexp (hf : integrable f \u03bc) : \u222b x, \u03bc[f|m,hm] x \u2202\u03bc = \u222b x, f x \u2202\u03bc :=\nbegin\n  suffices : \u222b x in set.univ, \u03bc[f|m,hm] x \u2202\u03bc = \u222b x in set.univ, f x \u2202\u03bc,\n    by { simp_rw integral_univ at this, exact this, },\n  exact set_integral_condexp hm hf (@measurable_set.univ _ m),\nend\n\n/-- **Uniqueness of the conditional expectation**\nIf a function is a.e. `m`-measurable, verifies an integrability condition and has same integral\nas `f` on all `m`-measurable sets, then it is a.e. equal to `\u03bc[f|hm]`. -/\nlemma ae_eq_condexp_of_forall_set_integral_eq (hm : m \u2264 m0) [sigma_finite (\u03bc.trim hm)]\n  {f g : \u03b1 \u2192 F'} (hf : integrable f \u03bc)\n  (hg_int_finite : \u2200 s, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 integrable_on g s \u03bc)\n  (hg_eq : \u2200 s : set \u03b1, measurable_set[m] s \u2192 \u03bc s < \u221e \u2192 \u222b x in s, g x \u2202\u03bc = \u222b x in s, f x \u2202\u03bc)\n  (hgm : ae_strongly_measurable' m g \u03bc) :\n  g =\u1d50[\u03bc] \u03bc[f|m,hm] :=\nbegin\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm hg_int_finite\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on) (\u03bb s hs h\u03bcs, _) hgm\n    (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),\n  rw [hg_eq s hs h\u03bcs, set_integral_condexp hm hf hs],\nend\n\nlemma condexp_add (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  \u03bc[f + g | m,hm] =\u1d50[\u03bc] \u03bc[f|m,hm] + \u03bc[g|m,hm] :=\nbegin\n  refine (condexp_ae_eq_condexp_L1 _).trans _,\n  rw condexp_L1_add hf hg,\n  exact (coe_fn_add _ _).trans\n    ((condexp_ae_eq_condexp_L1 _).symm.add (condexp_ae_eq_condexp_L1 _).symm),\nend\n\nlemma condexp_smul (c : \ud835\udd5c) (f : \u03b1 \u2192 F') : \u03bc[c \u2022 f | m,hm] =\u1d50[\u03bc] c \u2022 \u03bc[f|m,hm] :=\nbegin\n  refine (condexp_ae_eq_condexp_L1 _).trans _,\n  rw condexp_L1_smul c f,\n  refine (@condexp_ae_eq_condexp_L1 _ _ _ _ _ m _ _ hm _ f).mp _,\n  refine (coe_fn_smul c (condexp_L1 hm \u03bc f)).mono (\u03bb x hx1 hx2, _),\n  rw [hx1, pi.smul_apply, pi.smul_apply, hx2],\nend\n\nlemma condexp_neg (f : \u03b1 \u2192 F') : \u03bc[-f|m,hm] =\u1d50[\u03bc] - \u03bc[f|m,hm] :=\nby letI : module \u211d (\u03b1 \u2192 F') := @pi.module \u03b1 (\u03bb _, F') \u211d _ _ (\u03bb _, infer_instance);\ncalc \u03bc[-f|m,hm] = \u03bc[(-1 : \u211d) \u2022 f|m,hm] : by rw neg_one_smul \u211d f\n... =\u1d50[\u03bc] (-1 : \u211d) \u2022 \u03bc[f|m,hm] : condexp_smul (-1) f\n... = -\u03bc[f|m,hm] : neg_one_smul \u211d (\u03bc[f|m,hm])\n\nlemma condexp_sub (hf : integrable f \u03bc) (hg : integrable g \u03bc) :\n  \u03bc[f - g | m,hm] =\u1d50[\u03bc] \u03bc[f|m,hm] - \u03bc[g|m,hm] :=\nbegin\n  simp_rw sub_eq_add_neg,\n  exact (condexp_add hf hg.neg).trans (eventually_eq.rfl.add (condexp_neg g)),\nend\n\nlemma condexp_condexp_of_le {m\u2081 m\u2082 m0 : measurable_space \u03b1} {\u03bc : measure \u03b1}\n  (hm\u2081\u2082 : m\u2081 \u2264 m\u2082) (hm\u2082 : m\u2082 \u2264 m0) [sigma_finite (\u03bc.trim (hm\u2081\u2082.trans hm\u2082))]\n  [sigma_finite (\u03bc.trim hm\u2082)] :\n  \u03bc[ \u03bc[f|m\u2082, hm\u2082] | m\u2081, hm\u2081\u2082.trans hm\u2082] =\u1d50[\u03bc] \u03bc[f | m\u2081, hm\u2081\u2082.trans hm\u2082] :=\nbegin\n  refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm\u2081\u2082.trans hm\u2082)\n    (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on) (\u03bb s hs h\u03bcs, integrable_condexp.integrable_on)\n    _ (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp)\n      (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),\n  intros s hs h\u03bcs,\n  rw set_integral_condexp _ integrable_condexp hs,\n  by_cases hf : integrable f \u03bc,\n  { rw [set_integral_condexp _ hf hs, set_integral_condexp _ hf (hm\u2081\u2082 s hs)], },\n  { simp_rw integral_congr_ae (ae_restrict_of_ae (condexp_undef hf)), },\nend\n\nsection real\n\nlemma rn_deriv_ae_eq_condexp {f : \u03b1 \u2192 \u211d} (hf : integrable f \u03bc) :\n  signed_measure.rn_deriv ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm) =\u1d50[\u03bc] \u03bc[f | m,hm] :=\nbegin\n  refine ae_eq_condexp_of_forall_set_integral_eq hm hf _ _ _,\n  { exact \u03bb _ _ _, (integrable_of_integrable_trim hm (signed_measure.integrable_rn_deriv\n      ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm))).integrable_on },\n  { intros s hs hlt,\n    conv_rhs { rw [\u2190 hf.with_density\u1d65_trim_eq_integral hm hs,\n      \u2190 signed_measure.with_density\u1d65_rn_deriv_eq ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm)\n        (hf.with_density\u1d65_trim_absolutely_continuous hm)], },\n    rw [with_density\u1d65_apply\n        (signed_measure.integrable_rn_deriv ((\u03bc.with_density\u1d65 f).trim hm) (\u03bc.trim hm)) hs,\n      \u2190 set_integral_trim hm _ hs],\n    exact (signed_measure.measurable_rn_deriv _ _).strongly_measurable },\n  { exact strongly_measurable.ae_strongly_measurable'\n      (signed_measure.measurable_rn_deriv _ _).strongly_measurable },\nend\n\nend real\n\nend condexp\n\nend measure_theory\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/measure_theory/function/conditional_expectation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.7826624688140728, "lm_q1q2_score": 0.7025924049949197}}
{"text": "-- L\u00edmite de sucesiones constantes\n-- ===============================\n\nimport data.real.basic\n\nvariable (u : \u2115 \u2192 \u211d)\nvariable (c : \u211d)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la notaci\u00f3n |x| para el valor\n-- absoluto de x.\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Definir la funci\u00f3n\n--    limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop\n-- tal que (limite u c) expresa que c es el l\u00edmite de\n-- la sucesi\u00f3n u.\n-- ----------------------------------------------------\n\ndef limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n\u03bb u c, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - c| \u2264 \u03b5\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Demostrar que si u es la sucesi\u00f3n\n-- constante c, entonces el l\u00edmite de u es c.\n-- ----------------------------------------------------\n\n-- 1\u00aa demostraci\u00f3n\nexample :\n  limite (\u03bb n, c) c :=\nbegin\n  -- unfold limite,\n  intros \u03b5 h\u03b5,\n  use 0,\n  intros n hn,\n  -- dsimp,\n  norm_num,\n  linarith,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample :\n  limite (\u03bb n, c) c :=\nbegin\n  intros \u03b5 h\u03b5,\n  use 0,\n  intros n hn,\n  norm_num,\n  linarith,\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample :\n  limite (\u03bb n, c) c :=\nbegin\n  intros \u03b5 h\u03b5,\n  use 0,\n  intros n hn,\n  calc |(\u03bb n, c) n - c|\n       = |c - c|  : rfl\n   ... = 0        : by norm_num\n   ... \u2264 \u03b5        : by linarith,\nend\n\n-- 4\u00aa demostraci\u00f3n\nexample :\n  limite (\u03bb n, c) c :=\nassume \u03b5,\nassume h\u03b5 : \u03b5 > 0,\nexists.intro 0\n  ( assume n,\n    assume hn : n \u2265 0,\n    show |(\u03bb n, c) n - c| \u2264 \u03b5, from\n      calc |(\u03bb n, c) n - c|\n           = |c - c|  : rfl\n       ... = 0        : by norm_num\n       ... \u2264 \u03b5        : by linarith)\n", "meta": {"author": "jaalonso", "repo": "DAO_con_Lean", "sha": "1888a830871f358075ac712fc15bbf8b6806ac96", "save_path": "github-repos/lean/jaalonso-DAO_con_Lean", "path": "github-repos/lean/jaalonso-DAO_con_Lean/DAO_con_Lean-1888a830871f358075ac712fc15bbf8b6806ac96/src/5_Limites/Limite_de_sucesiones_constantes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7025907856706933}}
{"text": "import .affine_coordinate_space \n\n/-\nThis file exports \n- std_basis, given finite index set, return standard vector-space basis\n- std_frame, return standard frame on d-dimensional affine space\n-/\n\n/-\nWe've shown that <aff_pt_coord_tuple, aff_vec_coord_tuple> \nconstitutes an  affine space.There's no notion of a frame at this point. \nHowever,  we can endow such a space with a standard frame, taking the point,\n<1, 0, ..., 0> as the standard origin and the vectors, <0, 1, 0, ...>,\n..., <0, 0, ..., 1> as the standard basis for the vector space. To \nthis end, we now define what it means to be a frame for an affine space\nand we provide a function for obtaining a standard basis for any given\nspace of this kind.\n-/\n\n\nnamespace aff_basis\n\nuniverses u v w x\n\nvariables (X : Type u) (K : Type v) (V : Type w) (n : \u2115) (k : K)\n[inhabited K] [field K] [add_comm_group V] [vector_space K V] [affine_space V X]\n\nopen vecl\n\nabbreviation zero := zero_vector K n\n\ndef list.to_basis_vec : fin n \u2192 list K := \u03bb x, (zero K n).update_nth (x.1 + 1) 1\n\nlemma len_basis_vec_fixed (x : fin n) : (list.to_basis_vec K n x).length = n + 1 := sorry\n\nlemma head_basis_vec_fixed (x : fin n) : (list.to_basis_vec K n x).head = 0 := sorry\n\ndef std_basis : fin n \u2192 aff_vec_coord_tuple K n :=\n\u03bb x, \u27e8list.to_basis_vec K n x, len_basis_vec_fixed K n x, head_basis_vec_fixed K n x\u27e9\n\nlemma std_is_basis : is_basis K (std_basis K n) := sorry\n\n/-\nHere we equip any generic affine coordinate space with a standard frame\n-/\ndef aff_coord_space_std_frame : \n    affine_frame (aff_pt_coord_tuple K n) K (aff_vec_coord_tuple K n) (fin n) := \n        \u27e8pt_zero K n, std_basis K n, std_is_basis K n\u27e9\n#check aff_coord_space_std_frame\nend aff_basis\n\n/-\nWhat's funny is that:\n\n * FIXED! We don't have an explicit abstraction of affine coordinate space, e.g., as a type.\n-/", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/old/old/affine.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7025907788191449}}
{"text": "--import tactic.finish\n\nnamespace Three \n\nopen classical\n\nvariables p q r s : Prop\n\n-- commutativity of \u2227 and \u2228\nexample : p \u2227 q \u2194 q \u2227 p := begin\n  split,\n  intro hpq, \n    split, \n      exact hpq.right,\n    exact hpq.left,\n  intro hqp, \n    split, \n      exact hqp.right,\n    exact hqp.left,\nend\nexample : p \u2228 q \u2194 q \u2228 p := begin\n  split,\n    intro hpq, \n    cases hpq with hp hq,\n      right, exact hp,\n    left, exact hq,\n  intro hqp, \n    cases hqp with hq hp,\n      right, exact hq,\n    left, exact hp\nend\n\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r) := begin\n  split,\n    intro h,\n    split, \n      exact h.left.left,\n    split, \n      exact h.left.right,\n    exact h.right,\n  intro h,\n  split, \n    split, \n      exact h.left,\n    exact h.right.left,\n  exact h.right.right\nend\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r) := begin\n  split,\n    intro h,\n    cases h with hpq hr,\n      cases hpq with hp hq,\n        left, exact hp,\n      right, left, exact hq,\n    right, right, exact hr,\n  intro h,\n  cases h with hp hqr,\n    left, left, exact hp,\n  cases hqr with hq hr,\n    left, right, exact hq,\n  right, exact hr\nend\n\n-- distributivity\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := begin\n  split,\n    intro h,\n    cases h with hp hqr,\n    cases hqr with hq hr,\n      left,\n      split, \n        exact hp,\n      exact hq,\n    right,\n    split,\n      exact hp,\n    exact hr,\n  intro h,\n  cases h with hpq hpr,\n    cases hpq with hp hq,\n    split,\n      exact hp,\n    left, exact hq,\n  cases hpr with hp hr,\n  split,\n    exact hp,\n  right, exact hr\nend\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := begin\n  split,\n    intro h,\n    cases h with hp hqr,\n      split; {left, exact hp},\n    cases hqr with hq hr,\n    split; right, exact hq, exact hr,\n  intro h,\n  cases h with hpq hpr,\n  cases hpq with hp hq, \n    left, exact hp,\n  cases hpr with hp hr,\n    left, exact hp,\n  right, split, exact hq, exact hr\nend\n\n-- other properties\nexample : (p \u2192 (q \u2192 r)) \u2194 (p \u2227 q \u2192 r) := begin\n  split, \n    intros, \n      apply a, \n        exact a_1.left,\n      exact a_1.right,\n  intros,\n    apply a,\n    split,\n      exact a_1,\n    exact a_2\nend\nexample : ((p \u2228 q) \u2192 r) \u2194 (p \u2192 r) \u2227 (q \u2192 r) := begin\n  split,\n    intros, \n    split,\n      intros, \n      apply a,\n      exact or.intro_left q a_1,\n    intros,\n    apply a,\n      exact or.intro_right p a_1,\n  intros,\n  cases a, cases a_1,\n  exact a_left a_1,\n  exact a_right a_1\nend\nexample : \u00ac(p \u2228 q) \u2194 \u00acp \u2227 \u00acq := begin\n  split,\n    intros,\n    split,\n      intro hp, \n      exact a (or.intro_left q hp),\n    intro hq, \n    exact a (or.intro_right p hq),\n  intros, \n  intro hpq,\n  cases hpq,\n    exact a.left hpq,\n  exact a.right hpq\nend\nexample : \u00acp \u2228 \u00acq \u2192 \u00ac(p \u2227 q) := begin\n  intros,\n  intro h,\n  cases a,\n    exact a h.left,\n  exact a h.right,\nend\nexample : \u00ac(p \u2227 \u00acp) := begin\n  intro h,\n  exact h.right h.left\nend\nexample : p \u2227 \u00acq \u2192 \u00ac(p \u2192 q) := begin\n  intros a h, \n  exact a.right (h a.left)\nend\nexample : \u00acp \u2192 (p \u2192 q) := begin\n  intros, \n  exact absurd a_1 a\nend\nexample : (\u00acp \u2228 q) \u2192 (p \u2192 q) := begin\n  intros,\n  cases a, \n    exact absurd a_1 a,\n  exact a\nend\nexample : p \u2228 false \u2194 p := begin\n  split,\n    intros,\n    cases a,\n      exact a,\n    exact false.elim a,\n  intros,\n  left, exact a\nend\nexample : p \u2227 false \u2194 false := begin\n  split,\n    intros,\n    exact a.right,\n  intros, \n  exact false.elim a\nend\nexample : \u00ac(p \u2194 \u00acp) := begin\n  intro h, \n  cases h, \n  have hnp : \u00acp, from begin\n    intro hp,\n    exact (h_mp hp) hp,\n  end,\n  exact hnp (h_mpr hnp)\nend\nexample : (p \u2192 q) \u2192 (\u00acq \u2192 \u00acp) := begin\n  intros, intro hp,\n  exact a_1 (a hp)\nend\n\n-- these require classical reasoning\nexample : (p \u2192 r \u2228 s) \u2192 ((p \u2192 r) \u2228 (p \u2192 s)) := begin\n  intros,\n  cases (em p),\n    cases a h,\n      left, intro h, exact h_1,\n    right, intro h, exact h_1,\n  left,\n  intros,\n  exact absurd a_1 h\nend\nexample : \u00ac(p \u2227 q) \u2192 \u00acp \u2228 \u00acq := begin\n  intros, \n  cases (em p); cases (em q),\n        exact absurd (and.intro h h_1) a,\n      right, exact h_1,\n    left, exact h,\n  left, exact h\nend\nexample : \u00ac(p \u2192 q) \u2192 p \u2227 \u00acq := begin\n  intros,\n  cases (em p); cases (em q),\n        have hpq : p \u2192 q, from begin intros, exact h_1 end,\n        exact absurd hpq a,\n      split, exact h, exact h_1,\n    have hpq : p \u2192 q, from begin intros, exact h_1 end,\n    exact absurd hpq a,\n  have hpq : p \u2192 q, from begin intros, exact absurd a_1 h end,\n  exact absurd hpq a\nend\nexample : (p \u2192 q) \u2192 (\u00acp \u2228 q) := begin\n  intros,\n  cases (em p),\n    right, exact a h,\n  left, exact h,\nend\nexample : (\u00acq \u2192 \u00acp) \u2192 (p \u2192 q) := begin\n  intros,\n  cases (em q), \n    exact h,\n  exact absurd a_1 (a h)\nend\nexample : p \u2228 \u00acp := begin\n  cases (em p), left, assumption,\n  right, assumption\nend\n\nexample : (((p \u2192 q) \u2192 p) \u2192 p) := begin\n  intros,\n  apply classical.by_contradiction, \n  intros, \n  apply a_1, apply a,\n  intros,\n  exact absurd a_2 a_1\nend\n\n\nend Three\n\nnamespace Four\n\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\n\nexample : (\u2200 x, p x \u2227 q x) \u2194 (\u2200 x, p x) \u2227 (\u2200 x, q x) := begin\n  split,\n    intros,\n    split,\n      intros,\n      exact (a x).left,\n    intros,\n    exact (a x).right,\n  intros,\n  split,\n    exact a.left x,\n  exact a.right x\nend\nexample : (\u2200 x, p x \u2192 q x) \u2192 (\u2200 x, p x) \u2192 (\u2200 x, q x) := begin\n  intros,\n  exact (a x) (a_1 x)\nend\nexample : (\u2200 x, p x) \u2228 (\u2200 x, q x) \u2192 \u2200 x, p x \u2228 q x := begin\n  intros,\n  cases a,\n    left, exact a x,\n  right, exact a x\nend\n\nvariable r : Prop\n\nexample : \u03b1 \u2192 ((\u2200 x : \u03b1, r) \u2194 r) := begin\n  intros,\n  split, \n    intros,\n    exact a_1 a,\n  intros,\n  exact a_1\nend\n\nopen classical\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r := begin\n  split,\n    intros,\n    cases (em r),\n    right, exact h,\n    left, intros, \n    cases a x, \n    exact h_1,\n    exact absurd h_1 h,\n  intros,\n  cases a,\n  left, exact a x,\n  right,\n  exact a\nend\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) := begin\n  split,\n    intros,\n    exact (a x) a_1,\n  intros,\n  exact (a a_1) x\nend\n\nvariables (men : Type) (barber : men)\nvariable  (shaves : men \u2192 men \u2192 Prop)\n\nexample (h : \u2200 x : men, shaves barber x \u2194 \u00ac shaves x x) : false := begin\n  have h0 : \u2200 (p : Prop), \u00ac(p \u2194 \u00acp), from begin\n    intros p h,\n    cases h, \n    have hnp : \u00acp, from begin\n      intro hp,\n      exact (h_mp hp) hp,\n    end,\n    exact hnp (h_mpr hnp)\n  end,\n  exact (h0 (shaves barber barber)) (h barber)\nend\n\nnamespace hidden\n\ndef divides (m n : \u2115) : Prop := \u2203 k, m * k = n\n\ninstance : has_dvd nat := \u27e8divides\u27e9\n\ndef even (n : \u2115) : Prop := 2 \u2223 n\n\ndef prime (n : \u2115) : Prop := \u2200 (a b : \u2115), a * b = n \u2192 (a = 1 \u2228 b = 1)\n\ndef infinitely_many_primes : Prop := \u2200 (n : \u2115), \u2203 (p : \u2115), (n < p) \u2227 (prime p)\n\ndef Fermat_prime (n : \u2115) : Prop := (prime n) \u2227 (\u2203 (k : \u2115), n = 2 ^ k + 1)\n\ndef infinitely_many_Fermat_primes : Prop := \n\u2200 (n : \u2115), \u2203 (p : \u2115), (n < p) \u2227 (Fermat_prime p)\n\ndef goldbach_conjecture : Prop := \n\u2200 (n : \u2115), (even n) \u2192 (n > 2) \u2192 (\u2203 (p q : \u2115), (prime p) \u2192 (prime q) \u2192 n = p + q)\n\ndef Goldbach's_weak_conjecture : Prop := \n\u2200 (n : \u2115), (\u00ac (even n)) \u2192 (n > 5) \u2192 (\u2203 (p q r : \u2115), \n(prime p) \u2192 (prime q) \u2192 (prime r) \u2192 n = p + q + r)\n\ndef Fermat's_last_theorem : Prop := \n\u2200 (n : \u2115), (n > 2) \u2192 (\u00ac (\u2203 (a b c : \u2115), a ^ n + b ^ n = c ^ n))\n\nend hidden\n\nend Four\n\nopen classical\n\nvariables (\u03b1 : Type) (p q : \u03b1 \u2192 Prop)\nvariable a : \u03b1\nvariable r : Prop\n\n\ninclude a\nexample : (\u2203 x : \u03b1, r) \u2192 r := begin\n  intro h,\n  cases h,\n    exact h_h\nend\nexample : r \u2192 (\u2203 x : \u03b1, r) := begin\n  intros,\n  apply exists.intro,\n    exact a, exact a_1\nend\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := begin\n  split,\n    intros,\n    split,\n      cases a_1, \n      apply exists.intro,\n      exact a_1_h.left,\n    cases a_1,\n    exact a_1_h.right,\n  intros,\n  cases a_1.left,\n  apply exists.intro,\n  split,\n    exact h,\n  exact a_1.right\nend\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := begin\n  split,\n    intros,\n    cases a_1,\n    cases a_1_h,\n      left, \n      apply exists.intro,\n      exact a_1_h,\n    right,\n    apply exists.intro,\n    exact a_1_h,\n  intros,\n  cases a_1,\n    cases a_1,\n    apply exists.intro,\n    left, exact a_1_h,\n  cases a_1,\n  apply exists.intro,\n  right,\n  exact a_1_h\nend\n\nexample : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := begin\n  split,\n    intros h1 h2,\n    cases h2 with a h,\n    exact h (h1 a),\n  intros h x,\n  apply by_contradiction,\n  intros,\n  have h0 : \u2203 (x : \u03b1), \u00acp x, \n    apply exists.intro,\n    exact a_1,\n  exact h h0\nend\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := begin\n  split,\n    intros h h1,\n    cases h with x h,\n    exact (h1 x) h,\n  intros,\n  apply by_contradiction,\n  intros,\n  have h2 : \u2200 (x : \u03b1), \u00acp x, \n    intros x hpx,\n    exact a_2 (begin apply exists.intro, exact hpx end),\n  exact a_1 h2\nend\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) := begin\n  split,\n    intros h x hpx, \n    exact h (begin apply exists.intro, exact hpx end),\n  intros h h0,\n  cases h0,\n  exact (h h0_w) h0_h\nend\nexample : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) := begin\n  split,\n    intros h, \n    apply by_contradiction,\n    intros h1,\n    have h2 : \u2200 x, p x, \n      intro x,\n      apply by_contradiction,\n      intro hnp, \n      exact h1 (begin apply exists.intro, exact hnp end),\n    exact h h2,\n  intros h h0,\n  cases h, \n  exact h_h (h0 h_w)\nend\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r := begin\n  split,\n    intros, \n    cases a_2,\n    exact (a_1 a_2_w) a_2_h,\n  intros,\n  apply a_1,\n  apply exists.intro, \n  exact a_2\nend\nexample : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r := begin\n  split,\n    intros,\n    cases a_1,\n    exact a_1_h (a_2 a_1_w),\n  intros,\n  cases (em (\u2200 (x : \u03b1), p x)),\n    apply exists.intro,\n      intro hp,\n      exact a_1 h,\n    exact a,\n  apply by_contradiction,\n  intro h1,\n  have h2 : \u2200 (x : \u03b1), p x, \n    intro x,\n    apply by_contradiction,\n    intro npx,\n    exact h1 (begin fapply exists.intro,\n    exact x,\n    intro hpx,\n    exact absurd hpx npx end),\n  exact h h2\nend\nexample : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) := begin\n  split,\n    intros,\n    cases a_1,\n    apply exists.intro,\n    exact a_1_h a_2,\n  intros,\n  cases (em r),\n  cases a_1 h,\n  apply exists.intro,\n    intro h,\n    exact h_1,\n  apply exists.intro,\n    intro hr,\n    exact absurd hr h,\n  exact a,\nend\n\nexample (p q r : Prop) (hp : p) :\n(p \u2228 q \u2228 r) \u2227 (q \u2228 p \u2228 r) \u2227 (q \u2228 r \u2228 p) :=\nby {split, all_goals { try {split} }, \nrepeat {{left, assumption} <|> right <|> assumption}}", "meta": {"author": "AlexandruBosinta", "repo": "MyLeanPlayground", "sha": "5dc50a590d784bfc27e7fb37b6361a6dcc1b2790", "save_path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground", "path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground/MyLeanPlayground-5dc50a590d784bfc27e7fb37b6361a6dcc1b2790/5. Tactics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7025907786829089}}
{"text": "/-\nCopyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Pierre-Alexandre Bazin\n\n! This file was ported from Lean 3 source module algebra.module.dedekind_domain\n! leanprover-community/mathlib commit f694c7dead66f5d4c80f446c796a5aad14707f0e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Module.Torsion\nimport Mathbin.RingTheory.DedekindDomain.Ideal\n\n/-!\n# Modules over a Dedekind domain\n\nOver a Dedekind domain, a `I`-torsion module is the internal direct sum of its `p i ^ e i`-torsion\nsubmodules, where `I = \u220f i, p i ^ e i` is its unique decomposition in prime ideals.\nTherefore, as any finitely generated torsion module is `I`-torsion for some `I`, it is an internal\ndirect sum of its `p i ^ e i`-torsion submodules for some prime ideals `p i` and numbers `e i`.\n-/\n\n\nuniverse u v\n\nopen BigOperators\n\nvariable {R : Type u} [CommRing R] [IsDomain R] {M : Type v} [AddCommGroup M] [Module R M]\n\nopen DirectSum\n\nnamespace Submodule\n\nvariable [IsDedekindDomain R]\n\nopen UniqueFactorizationMonoid\n\n/-- Over a Dedekind domain, a `I`-torsion module is the internal direct sum of its `p i ^ e i`-\ntorsion submodules, where `I = \u220f i, p i ^ e i` is its unique decomposition in prime ideals.-/\ntheorem isInternal_prime_power_torsion_of_is_torsion_by_ideal {I : Ideal R} (hI : I \u2260 \u22a5)\n    (hM : Module.IsTorsionBySet R M I) :\n    \u2203 (P : Finset <| Ideal R)(_ : DecidableEq P)(_ : \u2200 p \u2208 P, Prime p)(e : P \u2192 \u2115),\n      DirectSum.IsInternal fun p : P => torsion_by_set R M (p ^ e p : Ideal R) :=\n  by\n  classical\n    let P := factors I\n    have prime_of_mem := fun p (hp : p \u2208 P.to_finset) =>\n      prime_of_factor p (multiset.mem_to_finset.mp hp)\n    refine' \u27e8P.to_finset, inferInstance, prime_of_mem, fun i => P.count i, _\u27e9\n    apply @torsion_by_set_is_internal _ _ _ _ _ _ _ _ (fun p => p ^ P.count p) _\n    \u00b7 convert hM\n      rw [\u2190 Finset.inf_eq_inf\u1d62, IsDedekindDomain.inf_prime_pow_eq_prod, \u2190\n        Finset.prod_multiset_count, \u2190 associated_iff_eq]\n      \u00b7 exact factors_prod hI\n      \u00b7 exact prime_of_mem\n      \u00b7 exact fun _ _ _ _ ij => ij\n    \u00b7 intro p hp q hq pq\n      dsimp\n      rw [irreducible_pow_sup]\n      \u00b7 suffices (normalized_factors _).count p = 0 by\n          rw [this, zero_min, pow_zero, Ideal.one_eq_top]\n        \u00b7 rw [Multiset.count_eq_zero,\n            normalized_factors_of_irreducible_pow (prime_of_mem q hq).Irreducible,\n            Multiset.mem_replicate]\n          exact fun H => pq <| H.2.trans <| normalize_eq q\n      \u00b7 rw [\u2190 Ideal.zero_eq_bot]\n        apply pow_ne_zero\n        exact (prime_of_mem q hq).NeZero\n      \u00b7 exact (prime_of_mem p hp).Irreducible\n#align submodule.is_internal_prime_power_torsion_of_is_torsion_by_ideal Submodule.isInternal_prime_power_torsion_of_is_torsion_by_ideal\n\n/-- A finitely generated torsion module over a Dedekind domain is an internal direct sum of its\n`p i ^ e i`-torsion submodules for some prime ideals `p i` and numbers `e i`.-/\ntheorem isInternal_prime_power_torsion [Module.Finite R M] (hM : Module.IsTorsion R M) :\n    \u2203 (P : Finset <| Ideal R)(_ : DecidableEq P)(_ : \u2200 p \u2208 P, Prime p)(e : P \u2192 \u2115),\n      DirectSum.IsInternal fun p : P => torsion_by_set R M (p ^ e p : Ideal R) :=\n  by\n  obtain \u27e8I, hI, hM'\u27e9 := is_torsion_by_ideal_of_finite_of_is_torsion hM\n  refine' is_internal_prime_power_torsion_of_is_torsion_by_ideal _ hM'\n  rw [\u2190 Set.nonempty_iff_ne_empty] at hI; rw [Submodule.ne_bot_iff]\n  obtain \u27e8x, H, hx\u27e9 := hI; exact \u27e8x, H, nonZeroDivisors.ne_zero hx\u27e9\n#align submodule.is_internal_prime_power_torsion Submodule.isInternal_prime_power_torsion\n\nend Submodule\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Module/DedekindDomain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7025907721038318}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n\n! This file was ported from Lean 3 source module data.nat.totient\n! leanprover-community/mathlib commit 5cc2dfdd3e92f340411acea4427d701dc7ed26f8\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.CharP.Two\nimport Mathlib.Data.Nat.Factorization.Basic\nimport Mathlib.Data.Nat.Periodic\nimport Mathlib.Data.ZMod.Basic\nimport Mathlib.Tactic.Monotonicity\n\n/-!\n# Euler's totient function\n\nThis file defines [Euler's totient function](https://en.wikipedia.org/wiki/Euler's_totient_function)\n`Nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`.\nWe prove the divisor sum formula, namely that `n` equals `\u03c6` summed over the divisors of `n`. See\n`sum_totient`. We also prove two lemmas to help compute totients, namely `totient_mul` and\n`totient_prime_pow`.\n-/\n\nopen Finset\n\nopen BigOperators\n\nnamespace Nat\n\n/-- Euler's totient function. This counts the number of naturals strictly less than `n` which are\ncoprime with `n`. -/\ndef totient (n : \u2115) : \u2115 :=\n  ((range n).filter n.coprime).card\n#align nat.totient Nat.totient\n\n@[inherit_doc]\nscoped notation \"\u03c6\" => Nat.totient\n\n@[simp]\ntheorem totient_zero : \u03c6 0 = 0 :=\n  rfl\n#align nat.totient_zero Nat.totient_zero\n\n@[simp]\ntheorem totient_one : \u03c6 1 = 1 := by simp [totient]\n#align nat.totient_one Nat.totient_one\n\ntheorem totient_eq_card_coprime (n : \u2115) : \u03c6 n = ((range n).filter n.coprime).card :=\n  rfl\n#align nat.totient_eq_card_coprime Nat.totient_eq_card_coprime\n\n/-- A characterisation of `nat.totient` that avoids `finset`. -/\ntheorem totient_eq_card_lt_and_coprime (n : \u2115) : \u03c6 n = Nat.card { m | m < n \u2227 n.coprime m } := by\n  let e : { m | m < n \u2227 n.coprime m } \u2243 Finset.filter n.coprime (Finset.range n) :=\n    { toFun := fun m => \u27e8m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.property\u27e9\n      invFun := fun m => \u27e8m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.property\u27e9\n      left_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta]\n      right_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta] }\n  rw [totient_eq_card_coprime, card_congr e, card_eq_fintype_card, Fintype.card_coe]\n#align nat.totient_eq_card_lt_and_coprime Nat.totient_eq_card_lt_and_coprime\n\ntheorem totient_le (n : \u2115) : \u03c6 n \u2264 n :=\n  ((range n).card_filter_le _).trans_eq (card_range n)\n#align nat.totient_le Nat.totient_le\n\ntheorem totient_lt (n : \u2115) (hn : 1 < n) : \u03c6 n < n :=\n  (card_lt_card (filter_ssubset.2 \u27e80, by simp [hn.ne', pos_of_gt hn]\u27e9)).trans_eq (card_range n)\n#align nat.totient_lt Nat.totient_lt\n\ntheorem totient_pos : \u2200 {n : \u2115}, 0 < n \u2192 0 < \u03c6 n\n  | 0 => by decide\n  | 1 => by simp [totient]\n  | n + 2 => fun _ => card_pos.2 \u27e81, mem_filter.2 \u27e8mem_range.2 (by simp), coprime_one_right _\u27e9\u27e9\n#align nat.totient_pos Nat.totient_pos\n\ntheorem filter_coprime_Ico_eq_totient (a n : \u2115) :\n    ((Ico n (n + a)).filter (coprime a)).card = totient a := by\n  rw [totient, filter_Ico_card_eq_of_periodic, count_eq_card_filter_range]\n  exact periodic_coprime a\n#align nat.filter_coprime_Ico_eq_totient Nat.filter_coprime_Ico_eq_totient\n\ntheorem Ico_filter_coprime_le {a : \u2115} (k n : \u2115) (a_pos : 0 < a) :\n    ((Ico k (k + n)).filter (coprime a)).card \u2264 totient a * (n / a + 1) := by\n  conv_lhs => rw [\u2190 Nat.mod_add_div n a]\n  induction' n / a with i ih\n  \u00b7 rw [\u2190 filter_coprime_Ico_eq_totient a k]\n    simp only [add_zero, mul_one, MulZeroClass.mul_zero, le_of_lt (mod_lt n a_pos),\n      Nat.zero_eq, zero_add]\n    --Porting note: below line was `mono`\n    refine Finset.card_mono ?_\n    refine' monotone_filter_left a.coprime _\n    simp only [Finset.le_eq_subset]\n    exact Ico_subset_Ico rfl.le (add_le_add_left (le_of_lt (mod_lt n a_pos)) k)\n  simp only [mul_succ]\n  simp_rw [\u2190 add_assoc] at ih \u22a2\n  calc\n    (filter a.coprime (Ico k (k + n % a + a * i + a))).card =\n        (filter a.coprime\n            (Ico k (k + n % a + a * i) \u222a Ico (k + n % a + a * i) (k + n % a + a * i + a))).card :=\n      by\n      congr\n      rw [Ico_union_Ico_eq_Ico]\n      rw [add_assoc]\n      exact le_self_add\n      exact le_self_add\n    _ \u2264 (filter a.coprime (Ico k (k + n % a + a * i))).card + a.totient := by\n      rw [filter_union, \u2190 filter_coprime_Ico_eq_totient a (k + n % a + a * i)]\n      apply card_union_le\n    _ \u2264 a.totient * i + a.totient + a.totient := add_le_add_right ih (totient a)\n\n#align nat.Ico_filter_coprime_le Nat.Ico_filter_coprime_le\n\nopen ZMod\n\n/-- Note this takes an explicit `Fintype ((ZMod n)\u02e3)` argument to avoid trouble with instance\ndiamonds. -/\n@[simp]\ntheorem _root_.ZMod.card_units_eq_totient (n : \u2115) [NeZero n] [Fintype (ZMod n)\u02e3] :\n    Fintype.card (ZMod n)\u02e3 = \u03c6 n :=\n  calc\n    Fintype.card (ZMod n)\u02e3 = Fintype.card { x : ZMod n // x.val.coprime n } :=\n      Fintype.card_congr ZMod.unitsEquivCoprime\n    _ = \u03c6 n := by\n      obtain \u27e8m, rfl\u27e9 : \u2203 m, n = m + 1 := exists_eq_succ_of_ne_zero NeZero.out\n      simp only [totient, Finset.card_eq_sum_ones, Fintype.card_subtype, Finset.sum_filter, \u2190\n        Fin.sum_univ_eq_sum_range, @Nat.coprime_comm (m + 1)]\n      rfl\n#align zmod.card_units_eq_totient ZMod.card_units_eq_totient\n\ntheorem totient_even {n : \u2115} (hn : 2 < n) : Even n.totient := by\n  haveI : Fact (1 < n) := \u27e8one_lt_two.trans hn\u27e9\n  haveI : NeZero n := NeZero.of_gt hn\n  suffices 2 = orderOf (-1 : (ZMod n)\u02e3) by\n    rw [\u2190 ZMod.card_units_eq_totient, even_iff_two_dvd, this]\n    exact orderOf_dvd_card_univ\n  rw [\u2190 orderOf_units, Units.coe_neg_one, orderOf_neg_one, ringChar.eq (ZMod n) n, if_neg hn.ne']\n#align nat.totient_even Nat.totient_even\n\ntheorem totient_mul {m n : \u2115} (h : m.coprime n) : \u03c6 (m * n) = \u03c6 m * \u03c6 n :=\n  if hmn0 : m * n = 0 then by\n    cases' Nat.mul_eq_zero.1 hmn0 with h h <;>\n      simp only [totient_zero, MulZeroClass.mul_zero, MulZeroClass.zero_mul, h]\n  else by\n    haveI : NeZero (m * n) := \u27e8hmn0\u27e9\n    haveI : NeZero m := \u27e8left_ne_zero_of_mul hmn0\u27e9\n    haveI : NeZero n := \u27e8right_ne_zero_of_mul hmn0\u27e9\n    simp only [\u2190 ZMod.card_units_eq_totient]\n    rw [Fintype.card_congr (Units.mapEquiv (ZMod.chineseRemainder h).toMulEquiv).toEquiv,\n      Fintype.card_congr (@MulEquiv.prodUnits (ZMod m) (ZMod n) _ _).toEquiv, Fintype.card_prod]\n#align nat.totient_mul Nat.totient_mul\n\n/-- For `d \u2223 n`, the totient of `n/d` equals the number of values `k < n` such that `gcd n k = d` -/\ntheorem totient_div_of_dvd {n d : \u2115} (hnd : d \u2223 n) :\n    \u03c6 (n / d) = (filter (fun k : \u2115 => n.gcd k = d) (range n)).card := by\n  rcases d.eq_zero_or_pos with (rfl | hd0); \u00b7 simp [eq_zero_of_zero_dvd hnd]\n  rcases hnd with \u27e8x, rfl\u27e9\n  rw [Nat.mul_div_cancel_left x hd0]\n  apply Finset.card_congr fun k _ => d * k\n  \u00b7 simp only [mem_filter, mem_range, and_imp, coprime]\n    refine' fun a ha1 ha2 => \u27e8(mul_lt_mul_left hd0).2 ha1, _\u27e9\n    rw [gcd_mul_left, ha2, mul_one]\n  \u00b7 simp [hd0.ne']\n  \u00b7 simp only [mem_filter, mem_range, exists_prop, and_imp]\n    refine' fun b hb1 hb2 => _\n    have : d \u2223 b := by\n      rw [\u2190 hb2]\n      apply gcd_dvd_right\n    rcases this with \u27e8q, rfl\u27e9\n    refine' \u27e8q, \u27e8\u27e8(mul_lt_mul_left hd0).1 hb1, _\u27e9, rfl\u27e9\u27e9\n    rwa [gcd_mul_left, mul_right_eq_self_iff hd0] at hb2\n#align nat.totient_div_of_dvd Nat.totient_div_of_dvd\n\ntheorem sum_totient (n : \u2115) : n.divisors.sum \u03c6 = n := by\n  rcases n.eq_zero_or_pos with (rfl | hn)\n  \u00b7 simp\n  rw [\u2190 sum_div_divisors n \u03c6]\n  have : n = \u2211 d : \u2115 in n.divisors, (filter (fun k : \u2115 => n.gcd k = d) (range n)).card := by\n    nth_rw 1 [\u2190 card_range n]\n    refine' card_eq_sum_card_fiberwise fun x _ => mem_divisors.2 \u27e8_, hn.ne'\u27e9\n    apply gcd_dvd_left\n  nth_rw 3 [this]\n  exact sum_congr rfl fun x hx => totient_div_of_dvd (dvd_of_mem_divisors hx)\n#align nat.sum_totient Nat.sum_totient\n\ntheorem sum_totient' (n : \u2115) : (\u2211 m in (range n.succ).filter (\u00b7 \u2223 n), \u03c6 m) = n := by\n  convert sum_totient _ using 1\n  simp only [Nat.divisors, sum_filter, range_eq_Ico]\n  rw [sum_eq_sum_Ico_succ_bot] <;> simp\n#align nat.sum_totient' Nat.sum_totient'\n\n/-- When `p` is prime, then the totient of `p ^ (n + 1)` is `p ^ n * (p - 1)` -/\ntheorem totient_prime_pow_succ {p : \u2115} (hp : p.Prime) (n : \u2115) : \u03c6 (p ^ (n + 1)) = p ^ n * (p - 1) :=\n  calc\n    \u03c6 (p ^ (n + 1)) = ((range (p ^ (n + 1))).filter (coprime (p ^ (n + 1)))).card :=\n      totient_eq_card_coprime _\n    _ = (range (p ^ (n + 1)) \\ (range (p ^ n)).image (\u00b7 * p)).card :=\n      (congr_arg card\n        (by\n          rw [sdiff_eq_filter]\n          apply filter_congr\n          simp only [mem_range, mem_filter, coprime_pow_left_iff n.succ_pos, mem_image, not_exists,\n            hp.coprime_iff_not_dvd]\n          intro a ha\n          constructor\n          \u00b7 intro hap b h; rcases h with \u27e8_, rfl\u27e9\n            exact hap (dvd_mul_left _ _)\n          \u00b7 rintro h \u27e8b, rfl\u27e9\n            rw [pow_succ'] at ha\n            exact h b \u27e8lt_of_mul_lt_mul_left ha (zero_le _), mul_comm _ _\u27e9))\n    _ = _ := by\n      have h1 : Function.Injective (\u00b7 * p) := mul_left_injective\u2080 hp.ne_zero\n      have h2 : (range (p ^ n)).image (\u00b7 * p) \u2286 range (p ^ (n + 1)) := fun a => by\n        simp only [mem_image, mem_range, exists_imp]\n        rintro b \u27e8h, rfl\u27e9\n        rw [pow_succ]\n        exact (mul_lt_mul_right hp.pos).2 h\n      rw [card_sdiff h2, card_image_of_injOn (h1.injOn _), card_range, card_range, \u2190\n        one_mul (p ^ n), pow_succ', \u2190 tsub_mul, one_mul, mul_comm]\n\n#align nat.totient_prime_pow_succ Nat.totient_prime_pow_succ\n\n/-- When `p` is prime, then the totient of `p ^ n` is `p ^ (n - 1) * (p - 1)` -/\ntheorem totient_prime_pow {p : \u2115} (hp : p.Prime) {n : \u2115} (hn : 0 < n) :\n    \u03c6 (p ^ n) = p ^ (n - 1) * (p - 1) := by\n  rcases exists_eq_succ_of_ne_zero (pos_iff_ne_zero.1 hn) with \u27e8m, rfl\u27e9\n  exact totient_prime_pow_succ hp _\n#align nat.totient_prime_pow Nat.totient_prime_pow\n\ntheorem totient_prime {p : \u2115} (hp : p.Prime) : \u03c6 p = p - 1 := by\n  rw [\u2190 pow_one p, totient_prime_pow hp] <;> simp\n#align nat.totient_prime Nat.totient_prime\n\ntheorem totient_eq_iff_prime {p : \u2115} (hp : 0 < p) : p.totient = p - 1 \u2194 p.Prime := by\n  refine' \u27e8fun h => _, totient_prime\u27e9\n  replace hp : 1 < p\n  \u00b7 apply lt_of_le_of_ne\n    \u00b7 rwa [succ_le_iff]\n    \u00b7 rintro rfl\n      rw [totient_one, tsub_self] at h\n      exact one_ne_zero h\n  rw [totient_eq_card_coprime, range_eq_Ico, \u2190 Ico_insert_succ_left hp.le, Finset.filter_insert,\n    if_neg (not_coprime_of_dvd_of_dvd hp (dvd_refl p) (dvd_zero p)), \u2190 Nat.card_Ico 1 p] at h\n  refine'\n    p.prime_of_coprime hp fun n hn hnz => Finset.filter_card_eq h n <| Finset.mem_Ico.mpr \u27e8_, hn\u27e9\n  rwa [succ_le_iff, pos_iff_ne_zero]\n#align nat.totient_eq_iff_prime Nat.totient_eq_iff_prime\n\ntheorem card_units_zMod_lt_sub_one {p : \u2115} (hp : 1 < p) [Fintype (ZMod p)\u02e3] :\n    Fintype.card (ZMod p)\u02e3 \u2264 p - 1 := by\n  haveI : NeZero p := \u27e8(pos_of_gt hp).ne'\u27e9\n  rw [ZMod.card_units_eq_totient p]\n  exact Nat.le_pred_of_lt (Nat.totient_lt p hp)\n#align nat.card_units_zmod_lt_sub_one Nat.card_units_zMod_lt_sub_one\n\ntheorem prime_iff_card_units (p : \u2115) [Fintype (ZMod p)\u02e3] :\n    p.Prime \u2194 Fintype.card (ZMod p)\u02e3 = p - 1 := by\n  cases' eq_zero_or_neZero p with hp hp\n  \u00b7 subst hp\n    simp only [ZMod, not_prime_zero, false_iff_iff, zero_tsub]\n    -- the substI created an non-defeq but subsingleton instance diamond; resolve it\n    suffices Fintype.card \u2124\u02e3 \u2260 0 by convert this\n    simp\n  rw [ZMod.card_units_eq_totient, Nat.totient_eq_iff_prime <| NeZero.pos p]\n#align nat.prime_iff_card_units Nat.prime_iff_card_units\n\n@[simp]\ntheorem totient_two : \u03c6 2 = 1 :=\n  (totient_prime prime_two).trans rfl\n#align nat.totient_two Nat.totient_two\n\ntheorem totient_eq_one_iff : \u2200 {n : \u2115}, n.totient = 1 \u2194 n = 1 \u2228 n = 2\n  | 0 => by simp\n  | 1 => by simp\n  | 2 => by simp\n  | n + 3 => by\n    have : 3 \u2264 n + 3 := le_add_self\n    simp only [succ_succ_ne_one, false_or_iff]\n    exact \u27e8fun h => not_even_one.elim <| h \u25b8 totient_even this, by rintro \u27e8\u27e9\u27e9\n#align nat.totient_eq_one_iff Nat.totient_eq_one_iff\n\n/-! ### Euler's product formula for the totient function\n\nWe prove several different statements of this formula. -/\n\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_eq_prod_factorization {n : \u2115} (hn : n \u2260 0) :\n    \u03c6 n = n.factorization.prod fun p k => p ^ (k - 1) * (p - 1) := by\n  rw [multiplicative_factorization \u03c6 (@totient_mul) totient_one hn]\n  apply Finsupp.prod_congr  _\n  intro p hp\n  have h := zero_lt_iff.mpr (Finsupp.mem_support_iff.mp hp)\n  rw [totient_prime_pow (prime_of_mem_factorization hp) h]\n#align nat.totient_eq_prod_factorization Nat.totient_eq_prod_factorization\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_mul_prod_factors (n : \u2115) :\n    (\u03c6 n * \u220f p in n.factors.toFinset, p) = n * \u220f p in n.factors.toFinset, (p - 1) := by\n  by_cases hn : n = 0; \u00b7 simp [hn]\n  rw [totient_eq_prod_factorization hn]\n  nth_rw 3 [\u2190 factorization_prod_pow_eq_self hn]\n  simp only [\u2190 prod_factorization_eq_prod_factors, \u2190 Finsupp.prod_mul]\n  refine' Finsupp.prod_congr (M := \u2115) (N := \u2115) fun p hp => _\n  rw [Finsupp.mem_support_iff, \u2190 zero_lt_iff] at hp\n  rw [mul_comm, \u2190 mul_assoc, \u2190 pow_succ', Nat.sub_one, Nat.succ_pred_eq_of_pos hp]\n#align nat.totient_mul_prod_factors Nat.totient_mul_prod_factors\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_eq_div_factors_mul (n : \u2115) :\n    \u03c6 n = (n / \u220f p in n.factors.toFinset, p) * \u220f p in n.factors.toFinset, (p - 1) := by\n  rw [\u2190 mul_div_left n.totient, totient_mul_prod_factors, mul_comm,\n    Nat.mul_div_assoc _ (prod_prime_factors_dvd n), mul_comm]\n  have := prod_pos (fun p => pos_of_mem_factorization (n := n))\n  simpa [prod_factorization_eq_prod_factors] using this\n#align nat.totient_eq_div_factors_mul Nat.totient_eq_div_factors_mul\n\n/-- Euler's product formula for the totient function. -/\ntheorem totient_eq_mul_prod_factors (n : \u2115) :\n    (\u03c6 n : \u211a) = n * \u220f p in n.factors.toFinset, (1 - (p : \u211a)\u207b\u00b9) := by\n  by_cases hn : n = 0\n  \u00b7 simp [hn]\n  have hn' : (n : \u211a) \u2260 0 := by simp [hn]\n  have hpQ : (\u220f p in n.factors.toFinset, (p : \u211a)) \u2260 0 := by\n    rw [\u2190 cast_prod, cast_ne_zero, \u2190 zero_lt_iff, \u2190 prod_factorization_eq_prod_factors]\n    exact prod_pos fun p hp => pos_of_mem_factorization hp\n  simp only [totient_eq_div_factors_mul n, prod_prime_factors_dvd n, cast_mul, cast_prod,\n    cast_div_charZero, mul_comm_div, mul_right_inj' hn', div_eq_iff hpQ, \u2190 prod_mul_distrib]\n  refine' prod_congr rfl fun p hp => _\n  have hp := pos_of_mem_factors (List.mem_toFinset.mp hp)\n  have hp' : (p : \u211a) \u2260 0 := cast_ne_zero.mpr hp.ne.symm\n  rw [sub_mul, one_mul, mul_comm, mul_inv_cancel hp', cast_pred hp]\n#align nat.totient_eq_mul_prod_factors Nat.totient_eq_mul_prod_factors\n\ntheorem totient_gcd_mul_totient_mul (a b : \u2115) : \u03c6 (a.gcd b) * \u03c6 (a * b) = \u03c6 a * \u03c6 b * a.gcd b := by\n  have shuffle :\n    \u2200 a1 a2 b1 b2 c1 c2 : \u2115,\n      b1 \u2223 a1 \u2192 b2 \u2223 a2 \u2192 a1 / b1 * c1 * (a2 / b2 * c2) = a1 * a2 / (b1 * b2) * (c1 * c2) := by\n    intro a1 a2 b1 b2 c1 c2 h1 h2\n    calc\n      a1 / b1 * c1 * (a2 / b2 * c2) = a1 / b1 * (a2 / b2) * (c1 * c2) := by apply mul_mul_mul_comm\n      _ = a1 * a2 / (b1 * b2) * (c1 * c2) := by\n        congr 1\n        exact div_mul_div_comm h1 h2\n  simp only [totient_eq_div_factors_mul]\n  rw [shuffle, shuffle]\n  rotate_left\n  repeat' apply prod_prime_factors_dvd\n  \u00b7 simp only [prod_factors_gcd_mul_prod_factors_mul]\n    rw [eq_comm, mul_comm, \u2190 mul_assoc, \u2190 Nat.mul_div_assoc]\n    exact mul_dvd_mul (prod_prime_factors_dvd a) (prod_prime_factors_dvd b)\n#align nat.totient_gcd_mul_totient_mul Nat.totient_gcd_mul_totient_mul\n\ntheorem totient_super_multiplicative (a b : \u2115) : \u03c6 a * \u03c6 b \u2264 \u03c6 (a * b) := by\n  let d := a.gcd b\n  rcases(zero_le a).eq_or_lt with (rfl | ha0)\n  \u00b7 simp\n  have hd0 : 0 < d := Nat.gcd_pos_of_pos_left _ ha0\n  apply le_of_mul_le_mul_right _ hd0\n  rw [\u2190 totient_gcd_mul_totient_mul a b, mul_comm]\n  apply mul_le_mul_left' (Nat.totient_le d)\n#align nat.totient_super_multiplicative Nat.totient_super_multiplicative\n\ntheorem totient_dvd_of_dvd {a b : \u2115} (h : a \u2223 b) : \u03c6 a \u2223 \u03c6 b := by\n  rcases eq_or_ne a 0 with (rfl | ha0)\n  \u00b7 simp [zero_dvd_iff.1 h]\n  rcases eq_or_ne b 0 with (rfl | hb0)\n  \u00b7 simp\n  have hab' : a.factorization.support \u2286 b.factorization.support := by\n    intro p\n    simp only [support_factorization, List.mem_toFinset]\n    apply factors_subset_of_dvd h hb0\n  rw [totient_eq_prod_factorization ha0, totient_eq_prod_factorization hb0]\n  refine' Finsupp.prod_dvd_prod_of_subset_of_dvd hab' fun p _ => mul_dvd_mul _ dvd_rfl\n  exact pow_dvd_pow p (tsub_le_tsub_right ((factorization_le_iff_dvd ha0 hb0).2 h p) 1)\n#align nat.totient_dvd_of_dvd Nat.totient_dvd_of_dvd\n\ntheorem totient_mul_of_prime_of_dvd {p n : \u2115} (hp : p.Prime) (h : p \u2223 n) :\n    (p * n).totient = p * n.totient := by\n  have h1 := totient_gcd_mul_totient_mul p n\n  rw [gcd_eq_left h, mul_assoc] at h1\n  simpa [(totient_pos hp.pos).ne', mul_comm] using h1\n#align nat.totient_mul_of_prime_of_dvd Nat.totient_mul_of_prime_of_dvd\n\ntheorem totient_mul_of_prime_of_not_dvd {p n : \u2115} (hp : p.Prime) (h : \u00acp \u2223 n) :\n    (p * n).totient = (p - 1) * n.totient := by\n  rw [totient_mul _, totient_prime hp]\n  simpa [h] using coprime_or_dvd_of_prime hp n\n#align nat.totient_mul_of_prime_of_not_dvd Nat.totient_mul_of_prime_of_not_dvd\n\nend Nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Nat/Totient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460027, "lm_q2_score": 0.7905303137346444, "lm_q1q2_score": 0.7025907655247546}}
{"text": "/-\nCopyright (c) 2019 Gabriel Ebner. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Gabriel Ebner, S\u00e9bastien Gou\u00ebzel\n-/\nimport analysis.calculus.fderiv\nimport data.polynomial.derivative\n\n/-!\n\n# One-dimensional derivatives\n\nThis file defines the derivative of a function `f : \ud835\udd5c \u2192 F` where `\ud835\udd5c` is a\nnormed field and `F` is a normed space over this field. The derivative of\nsuch a function `f` at a point `x` is given by an element `f' : F`.\n\nThe theory is developed analogously to the [Fr\u00e9chet\nderivatives](./fderiv.lean). We first introduce predicates defined in terms\nof the corresponding predicates for Fr\u00e9chet derivatives:\n\n - `has_deriv_at_filter f f' x L` states that the function `f` has the\n    derivative `f'` at the point `x` as `x` goes along the filter `L`.\n\n - `has_deriv_within_at f f' s x` states that the function `f` has the\n    derivative `f'` at the point `x` within the subset `s`.\n\n - `has_deriv_at f f' x` states that the function `f` has the derivative `f'`\n    at the point `x`.\n\n - `has_strict_deriv_at f f' x` states that the function `f` has the derivative `f'`\n    at the point `x` in the sense of strict differentiability, i.e.,\n   `f y - f z = (y - z) \u2022 f' + o (y - z)` as `y, z \u2192 x`.\n\nFor the last two notions we also define a functional version:\n\n  - `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the\n    derivative does not exist, then `deriv_within f s x` equals zero.\n\n  - `deriv f x` is a derivative of `f` at `x`. If the derivative does not\n    exist, then `deriv f x` equals zero.\n\nThe theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the\none-dimensional derivatives coincide with the general Fr\u00e9chet derivatives.\n\nWe also show the existence and compute the derivatives of:\n  - constants\n  - the identity function\n  - linear maps\n  - addition\n  - sum of finitely many functions\n  - negation\n  - subtraction\n  - multiplication\n  - inverse `x \u2192 x\u207b\u00b9`\n  - multiplication of two functions in `\ud835\udd5c \u2192 \ud835\udd5c`\n  - multiplication of a function in `\ud835\udd5c \u2192 \ud835\udd5c` and of a function in `\ud835\udd5c \u2192 E`\n  - composition of a function in `\ud835\udd5c \u2192 F` with a function in `\ud835\udd5c \u2192 \ud835\udd5c`\n  - composition of a function in `F \u2192 E` with a function in `\ud835\udd5c \u2192 F`\n  - inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)\n  - division\n  - polynomials\n\nFor most binary operations we also define `const_op` and `op_const` theorems for the cases when\nthe first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,\nand they more frequently lead to the desired result.\n\nWe set up the simplifier so that it can compute the derivative of simple functions. For instance,\n```lean\nexample (x : \u211d) : deriv (\u03bb x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=\nby { simp, ring }\n```\n\n## Implementation notes\n\nMost of the theorems are direct restatements of the corresponding theorems\nfor Fr\u00e9chet derivatives.\n\nThe strategy to construct simp lemmas that give the simplifier the possibility to compute\nderivatives is the same as the one for differentiability statements, as explained in `fderiv.lean`.\nSee the explanations there.\n-/\n\nuniverses u v w\nnoncomputable theory\nopen_locale classical topological_space big_operators filter ennreal\nopen filter asymptotics set\nopen continuous_linear_map (smul_right smul_right_one_eq_iff)\n\n\nvariables {\ud835\udd5c : Type u} [nondiscrete_normed_field \ud835\udd5c]\n\nsection\nvariables {F : Type v} [normed_group F] [normed_space \ud835\udd5c F]\nvariables {E : Type w} [normed_group E] [normed_space \ud835\udd5c E]\n\n/--\n`f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges along the filter `L`.\n-/\ndef has_deriv_at_filter (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) (L : filter \ud835\udd5c) :=\nhas_fderiv_at_filter f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x L\n\n/--\n`f` has the derivative `f'` at the point `x` within the subset `s`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef has_deriv_within_at (f : \ud835\udd5c \u2192 F) (f' : F) (s : set \ud835\udd5c) (x : \ud835\udd5c) :=\nhas_deriv_at_filter f f' x (\ud835\udcdd[s] x)\n\n/--\n`f` has the derivative `f'` at the point `x`.\n\nThat is, `f x' = f x + (x' - x) \u2022 f' + o(x' - x)` where `x'` converges to `x`.\n-/\ndef has_deriv_at (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) :=\nhas_deriv_at_filter f f' x (\ud835\udcdd x)\n\n/-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability.\n\nThat is, `f y - f z = (y - z) \u2022 f' + o(y - z)` as `y, z \u2192 x`. -/\ndef has_strict_deriv_at (f : \ud835\udd5c \u2192 F) (f' : F) (x : \ud835\udd5c) :=\nhas_strict_fderiv_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x\n\n/--\nDerivative of `f` at the point `x` within the set `s`, if it exists.  Zero otherwise.\n\nIf the derivative exists (i.e., `\u2203 f', has_deriv_within_at f f' s x`), then\n`f x' = f x + (x' - x) \u2022 deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef deriv_within (f : \ud835\udd5c \u2192 F) (s : set \ud835\udd5c) (x : \ud835\udd5c) :=\nfderiv_within \ud835\udd5c f s x 1\n\n/--\nDerivative of `f` at the point `x`, if it exists.  Zero otherwise.\n\nIf the derivative exists (i.e., `\u2203 f', has_deriv_at f f' x`), then\n`f x' = f x + (x' - x) \u2022 deriv f x + o(x' - x)` where `x'` converges to `x`.\n-/\ndef deriv (f : \ud835\udd5c \u2192 F) (x : \ud835\udd5c) :=\nfderiv \ud835\udd5c f x 1\n\nvariables {f f\u2080 f\u2081 g : \ud835\udd5c \u2192 F}\nvariables {f' f\u2080' f\u2081' g' : F}\nvariables {x : \ud835\udd5c}\nvariables {s t : set \ud835\udd5c}\nvariables {L L\u2081 L\u2082 : filter \ud835\udd5c}\n\n/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/\nlemma has_fderiv_at_filter_iff_has_deriv_at_filter {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at_filter f f' x L \u2194 has_deriv_at_filter f (f' 1) x L :=\nby simp [has_deriv_at_filter]\n\nlemma has_fderiv_at_filter.has_deriv_at_filter {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at_filter f f' x L \u2192 has_deriv_at_filter f (f' 1) x L :=\nhas_fderiv_at_filter_iff_has_deriv_at_filter.mp\n\n/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/\nlemma has_fderiv_within_at_iff_has_deriv_within_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_within_at f f' s x \u2194 has_deriv_within_at f (f' 1) s x :=\nhas_fderiv_at_filter_iff_has_deriv_at_filter\n\n/-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/\nlemma has_deriv_within_at_iff_has_fderiv_within_at {f' : F} :\n  has_deriv_within_at f f' s x \u2194\n  has_fderiv_within_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') s x :=\niff.rfl\n\nlemma has_fderiv_within_at.has_deriv_within_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_within_at f f' s x \u2192 has_deriv_within_at f (f' 1) s x :=\nhas_fderiv_within_at_iff_has_deriv_within_at.mp\n\nlemma has_deriv_within_at.has_fderiv_within_at {f' : F} :\n  has_deriv_within_at f f' s x \u2192 has_fderiv_within_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') s x :=\nhas_deriv_within_at_iff_has_fderiv_within_at.mp\n\n/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/\nlemma has_fderiv_at_iff_has_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at f f' x \u2194 has_deriv_at f (f' 1) x :=\nhas_fderiv_at_filter_iff_has_deriv_at_filter\n\nlemma has_fderiv_at.has_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_fderiv_at f f' x \u2192 has_deriv_at f (f' 1) x :=\nhas_fderiv_at_iff_has_deriv_at.mp\n\nlemma has_strict_fderiv_at_iff_has_strict_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_strict_fderiv_at f f' x \u2194 has_strict_deriv_at f (f' 1) x :=\nby simp [has_strict_deriv_at, has_strict_fderiv_at]\n\nprotected lemma has_strict_fderiv_at.has_strict_deriv_at {f' : \ud835\udd5c \u2192L[\ud835\udd5c] F} :\n  has_strict_fderiv_at f f' x \u2192 has_strict_deriv_at f (f' 1) x :=\nhas_strict_fderiv_at_iff_has_strict_deriv_at.mp\n\nlemma has_strict_deriv_at_iff_has_strict_fderiv_at :\n  has_strict_deriv_at f f' x \u2194 has_strict_fderiv_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x :=\niff.rfl\n\nalias has_strict_deriv_at_iff_has_strict_fderiv_at \u2194 has_strict_deriv_at.has_strict_fderiv_at _\n\n/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/\nlemma has_deriv_at_iff_has_fderiv_at {f' : F} :\n  has_deriv_at f f' x \u2194\n  has_fderiv_at f (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) f') x :=\niff.rfl\n\nalias has_deriv_at_iff_has_fderiv_at \u2194 has_deriv_at.has_fderiv_at _\n\nlemma deriv_within_zero_of_not_differentiable_within_at\n  (h : \u00ac differentiable_within_at \ud835\udd5c f s x) : deriv_within f s x = 0 :=\nby { unfold deriv_within, rw fderiv_within_zero_of_not_differentiable_within_at, simp, assumption }\n\nlemma deriv_zero_of_not_differentiable_at (h : \u00ac differentiable_at \ud835\udd5c f x) : deriv f x = 0 :=\nby { unfold deriv, rw fderiv_zero_of_not_differentiable_at, simp, assumption }\n\ntheorem unique_diff_within_at.eq_deriv (s : set \ud835\udd5c) (H : unique_diff_within_at \ud835\udd5c s x)\n  (h : has_deriv_within_at f f' s x) (h\u2081 : has_deriv_within_at f f\u2081' s x) : f' = f\u2081' :=\nsmul_right_one_eq_iff.mp $ unique_diff_within_at.eq H h h\u2081\n\ntheorem has_deriv_at_filter_iff_tendsto :\n  has_deriv_at_filter f f' x L \u2194\n  tendsto (\u03bb x' : \ud835\udd5c, \u2225x' - x\u2225\u207b\u00b9 * \u2225f x' - f x - (x' - x) \u2022 f'\u2225) L (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_deriv_within_at_iff_tendsto : has_deriv_within_at f f' s x \u2194\n  tendsto (\u03bb x', \u2225x' - x\u2225\u207b\u00b9 * \u2225f x' - f x - (x' - x) \u2022 f'\u2225) (\ud835\udcdd[s] x) (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_deriv_at_iff_tendsto : has_deriv_at f f' x \u2194\n  tendsto (\u03bb x', \u2225x' - x\u2225\u207b\u00b9 * \u2225f x' - f x - (x' - x) \u2022 f'\u2225) (\ud835\udcdd x) (\ud835\udcdd 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_strict_deriv_at.has_deriv_at (h : has_strict_deriv_at f f' x) :\n  has_deriv_at f f' x :=\nh.has_fderiv_at\n\n/-- If the domain has dimension one, then Fr\u00e9chet derivative is equivalent to the classical\ndefinition with a limit. In this version we have to take the limit along the subset `-{x}`,\nbecause for `y=x` the slope equals zero due to the convention `0\u207b\u00b9=0`. -/\nlemma has_deriv_at_filter_iff_tendsto_slope {x : \ud835\udd5c} {L : filter \ud835\udd5c} :\n  has_deriv_at_filter f f' x L \u2194\n    tendsto (\u03bb y, (y - x)\u207b\u00b9 \u2022 (f y - f x)) (L \u2293 \ud835\udcdf {x}\u1d9c) (\ud835\udcdd f') :=\nbegin\n  conv_lhs { simp only [has_deriv_at_filter_iff_tendsto, (normed_field.norm_inv _).symm,\n    (norm_smul _ _).symm, tendsto_zero_iff_norm_tendsto_zero.symm] },\n  conv_rhs { rw [\u2190 nhds_translation f', tendsto_comap_iff] },\n  refine (tendsto_inf_principal_nhds_iff_of_forall_eq $ by simp).symm.trans (tendsto_congr' _),\n  refine (eventually_principal.2 $ \u03bb z hz, _).filter_mono inf_le_right,\n  simp only [(\u2218)],\n  rw [smul_sub, \u2190 mul_smul, inv_mul_cancel (sub_ne_zero.2 hz), one_smul]\nend\n\nlemma has_deriv_within_at_iff_tendsto_slope :\n  has_deriv_within_at f f' s x \u2194\n    tendsto (\u03bb y, (y - x)\u207b\u00b9 \u2022 (f y - f x)) (\ud835\udcdd[s \\ {x}] x) (\ud835\udcdd f') :=\nbegin\n  simp only [has_deriv_within_at, nhds_within, diff_eq, inf_assoc.symm, inf_principal.symm],\n  exact has_deriv_at_filter_iff_tendsto_slope\nend\n\nlemma has_deriv_within_at_iff_tendsto_slope' (hs : x \u2209 s) :\n  has_deriv_within_at f f' s x \u2194\n    tendsto (\u03bb y, (y - x)\u207b\u00b9 \u2022 (f y - f x)) (\ud835\udcdd[s] x) (\ud835\udcdd f') :=\nbegin\n  convert \u2190 has_deriv_within_at_iff_tendsto_slope,\n  exact diff_singleton_eq_self hs\nend\n\nlemma has_deriv_at_iff_tendsto_slope :\n  has_deriv_at f f' x \u2194\n    tendsto (\u03bb y, (y - x)\u207b\u00b9 \u2022 (f y - f x)) (\ud835\udcdd[{x}\u1d9c] x) (\ud835\udcdd f') :=\nhas_deriv_at_filter_iff_tendsto_slope\n\n@[simp] lemma has_deriv_within_at_diff_singleton :\n  has_deriv_within_at f f' (s \\ {x}) x \u2194 has_deriv_within_at f f' s x :=\nby simp only [has_deriv_within_at_iff_tendsto_slope, sdiff_idem]\n\n@[simp] lemma has_deriv_within_at_Ioi_iff_Ici [partial_order \ud835\udd5c] :\n  has_deriv_within_at f f' (Ioi x) x \u2194 has_deriv_within_at f f' (Ici x) x :=\nby rw [\u2190 Ici_diff_left, has_deriv_within_at_diff_singleton]\n\nalias has_deriv_within_at_Ioi_iff_Ici \u2194\n  has_deriv_within_at.Ici_of_Ioi has_deriv_within_at.Ioi_of_Ici\n\n@[simp] lemma has_deriv_within_at_Iio_iff_Iic [partial_order \ud835\udd5c] :\n  has_deriv_within_at f f' (Iio x) x \u2194 has_deriv_within_at f f' (Iic x) x :=\nby rw [\u2190 Iic_diff_right, has_deriv_within_at_diff_singleton]\n\nalias has_deriv_within_at_Iio_iff_Iic \u2194\n  has_deriv_within_at.Iic_of_Iio has_deriv_within_at.Iio_of_Iic\n\ntheorem has_deriv_at_iff_is_o_nhds_zero : has_deriv_at f f' x \u2194\n  is_o (\u03bbh, f (x + h) - f x - h \u2022 f') (\u03bbh, h) (\ud835\udcdd 0) :=\nhas_fderiv_at_iff_is_o_nhds_zero\n\ntheorem has_deriv_at_filter.mono (h : has_deriv_at_filter f f' x L\u2082) (hst : L\u2081 \u2264 L\u2082) :\n  has_deriv_at_filter f f' x L\u2081 :=\nhas_fderiv_at_filter.mono h hst\n\ntheorem has_deriv_within_at.mono (h : has_deriv_within_at f f' t x) (hst : s \u2286 t) :\n  has_deriv_within_at f f' s x :=\nhas_fderiv_within_at.mono h hst\n\ntheorem has_deriv_at.has_deriv_at_filter (h : has_deriv_at f f' x) (hL : L \u2264 \ud835\udcdd x) :\n  has_deriv_at_filter f f' x L :=\nhas_fderiv_at.has_fderiv_at_filter h hL\n\ntheorem has_deriv_at.has_deriv_within_at\n  (h : has_deriv_at f f' x) : has_deriv_within_at f f' s x :=\nhas_fderiv_at.has_fderiv_within_at h\n\nlemma has_deriv_within_at.differentiable_within_at (h : has_deriv_within_at f f' s x) :\n  differentiable_within_at \ud835\udd5c f s x :=\nhas_fderiv_within_at.differentiable_within_at h\n\nlemma has_deriv_at.differentiable_at (h : has_deriv_at f f' x) : differentiable_at \ud835\udd5c f x :=\nhas_fderiv_at.differentiable_at h\n\n@[simp] lemma has_deriv_within_at_univ : has_deriv_within_at f f' univ x \u2194 has_deriv_at f f' x :=\nhas_fderiv_within_at_univ\n\ntheorem has_deriv_at.unique\n  (h\u2080 : has_deriv_at f f\u2080' x) (h\u2081 : has_deriv_at f f\u2081' x) : f\u2080' = f\u2081' :=\nsmul_right_one_eq_iff.mp $ h\u2080.has_fderiv_at.unique h\u2081\n\nlemma has_deriv_within_at_inter' (h : t \u2208 \ud835\udcdd[s] x) :\n  has_deriv_within_at f f' (s \u2229 t) x \u2194 has_deriv_within_at f f' s x :=\nhas_fderiv_within_at_inter' h\n\nlemma has_deriv_within_at_inter (h : t \u2208 \ud835\udcdd x) :\n  has_deriv_within_at f f' (s \u2229 t) x \u2194 has_deriv_within_at f f' s x :=\nhas_fderiv_within_at_inter h\n\nlemma has_deriv_within_at.union (hs : has_deriv_within_at f f' s x)\n  (ht : has_deriv_within_at f f' t x) :\n  has_deriv_within_at f f' (s \u222a t) x :=\nbegin\n  simp only [has_deriv_within_at, nhds_within_union],\n  exact hs.join ht,\nend\n\nlemma has_deriv_within_at.nhds_within (h : has_deriv_within_at f f' s x)\n  (ht : s \u2208 \ud835\udcdd[t] x) : has_deriv_within_at f f' t x :=\n(has_deriv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))\n\nlemma has_deriv_within_at.has_deriv_at (h : has_deriv_within_at f f' s x) (hs : s \u2208 \ud835\udcdd x) :\n  has_deriv_at f f' x :=\nhas_fderiv_within_at.has_fderiv_at h hs\n\nlemma differentiable_within_at.has_deriv_within_at (h : differentiable_within_at \ud835\udd5c f s x) :\n  has_deriv_within_at f (deriv_within f s x) s x :=\nshow has_fderiv_within_at _ _ _ _, by { convert h.has_fderiv_within_at, simp [deriv_within] }\n\nlemma differentiable_at.has_deriv_at (h : differentiable_at \ud835\udd5c f x) : has_deriv_at f (deriv f x) x :=\nshow has_fderiv_at _ _ _, by { convert h.has_fderiv_at, simp [deriv] }\n\nlemma has_deriv_at.deriv (h : has_deriv_at f f' x) : deriv f x = f' :=\nh.differentiable_at.has_deriv_at.unique h\n\nlemma has_deriv_within_at.deriv_within\n  (h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within f s x = f' :=\nhxs.eq_deriv _ h.differentiable_within_at.has_deriv_within_at h\n\nlemma fderiv_within_deriv_within : (fderiv_within \ud835\udd5c f s x : \ud835\udd5c \u2192 F) 1 = deriv_within f s x :=\nrfl\n\nlemma deriv_within_fderiv_within :\n  smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (deriv_within f s x) = fderiv_within \ud835\udd5c f s x :=\nby simp [deriv_within]\n\nlemma fderiv_deriv : (fderiv \ud835\udd5c f x : \ud835\udd5c \u2192 F) 1 = deriv f x :=\nrfl\n\nlemma deriv_fderiv :\n  smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (deriv f x) = fderiv \ud835\udd5c f x :=\nby simp [deriv]\n\nlemma differentiable_at.deriv_within (h : differentiable_at \ud835\udd5c f x)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within f s x = deriv f x :=\nby { unfold deriv_within deriv, rw h.fderiv_within hxs }\n\nlemma deriv_within_subset (st : s \u2286 t) (ht : unique_diff_within_at \ud835\udd5c s x)\n  (h : differentiable_within_at \ud835\udd5c f t x) :\n  deriv_within f s x = deriv_within f t x :=\n((differentiable_within_at.has_deriv_within_at h).mono st).deriv_within ht\n\n@[simp] lemma deriv_within_univ : deriv_within f univ = deriv f :=\nby { ext, unfold deriv_within deriv, rw fderiv_within_univ }\n\nlemma deriv_within_inter (ht : t \u2208 \ud835\udcdd x) (hs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within f (s \u2229 t) x = deriv_within f s x :=\nby { unfold deriv_within, rw fderiv_within_inter ht hs }\n\nlemma deriv_within_of_open (hs : is_open s) (hx : x \u2208 s) :\n  deriv_within f s x = deriv f x :=\nby { unfold deriv_within, rw fderiv_within_of_open hs hx, refl }\n\nsection congr\n/-! ### Congruence properties of derivatives -/\n\ntheorem filter.eventually_eq.has_deriv_at_filter_iff\n  (h\u2080 : f\u2080 =\u1da0[L] f\u2081) (hx : f\u2080 x = f\u2081 x) (h\u2081 : f\u2080' = f\u2081') :\n  has_deriv_at_filter f\u2080 f\u2080' x L \u2194 has_deriv_at_filter f\u2081 f\u2081' x L :=\nh\u2080.has_fderiv_at_filter_iff hx (by simp [h\u2081])\n\nlemma has_deriv_at_filter.congr_of_eventually_eq (h : has_deriv_at_filter f f' x L)\n  (hL : f\u2081 =\u1da0[L] f) (hx : f\u2081 x = f x) : has_deriv_at_filter f\u2081 f' x L :=\nby rwa hL.has_deriv_at_filter_iff hx rfl\n\nlemma has_deriv_within_at.congr_mono (h : has_deriv_within_at f f' s x) (ht : \u2200x \u2208 t, f\u2081 x = f x)\n  (hx : f\u2081 x = f x) (h\u2081 : t \u2286 s) : has_deriv_within_at f\u2081 f' t x :=\nhas_fderiv_within_at.congr_mono h ht hx h\u2081\n\nlemma has_deriv_within_at.congr (h : has_deriv_within_at f f' s x) (hs : \u2200x \u2208 s, f\u2081 x = f x)\n  (hx : f\u2081 x = f x) : has_deriv_within_at f\u2081 f' s x :=\nh.congr_mono hs hx (subset.refl _)\n\nlemma has_deriv_within_at.congr_of_eventually_eq (h : has_deriv_within_at f f' s x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : f\u2081 x = f x) : has_deriv_within_at f\u2081 f' s x :=\nhas_deriv_at_filter.congr_of_eventually_eq h h\u2081 hx\n\nlemma has_deriv_within_at.congr_of_eventually_eq_of_mem (h : has_deriv_within_at f f' s x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : x \u2208 s) : has_deriv_within_at f\u2081 f' s x :=\nh.congr_of_eventually_eq h\u2081 (h\u2081.eq_of_nhds_within hx)\n\nlemma has_deriv_at.congr_of_eventually_eq (h : has_deriv_at f f' x)\n  (h\u2081 : f\u2081 =\u1da0[\ud835\udcdd x] f) : has_deriv_at f\u2081 f' x :=\nhas_deriv_at_filter.congr_of_eventually_eq h h\u2081 (mem_of_nhds h\u2081 : _)\n\nlemma filter.eventually_eq.deriv_within_eq (hs : unique_diff_within_at \ud835\udd5c s x)\n  (hL : f\u2081 =\u1da0[\ud835\udcdd[s] x] f) (hx : f\u2081 x = f x) :\n  deriv_within f\u2081 s x = deriv_within f s x :=\nby { unfold deriv_within, rw hL.fderiv_within_eq hs hx }\n\nlemma deriv_within_congr (hs : unique_diff_within_at \ud835\udd5c s x)\n  (hL : \u2200y\u2208s, f\u2081 y = f y) (hx : f\u2081 x = f x) :\n  deriv_within f\u2081 s x = deriv_within f s x :=\nby { unfold deriv_within, rw fderiv_within_congr hs hL hx }\n\nlemma filter.eventually_eq.deriv_eq (hL : f\u2081 =\u1da0[\ud835\udcdd x] f) : deriv f\u2081 x = deriv f x :=\nby { unfold deriv, rwa filter.eventually_eq.fderiv_eq }\n\nend congr\n\nsection id\n/-! ### Derivative of the identity -/\nvariables (s x L)\n\ntheorem has_deriv_at_filter_id : has_deriv_at_filter id 1 x L :=\n(has_fderiv_at_filter_id x L).has_deriv_at_filter\n\ntheorem has_deriv_within_at_id : has_deriv_within_at id 1 s x :=\nhas_deriv_at_filter_id _ _\n\ntheorem has_deriv_at_id : has_deriv_at id 1 x :=\nhas_deriv_at_filter_id _ _\n\ntheorem has_deriv_at_id' : has_deriv_at (\u03bb (x : \ud835\udd5c), x) 1 x :=\nhas_deriv_at_filter_id _ _\n\ntheorem has_strict_deriv_at_id : has_strict_deriv_at id 1 x :=\n(has_strict_fderiv_at_id x).has_strict_deriv_at\n\nlemma deriv_id : deriv id x = 1 :=\nhas_deriv_at.deriv (has_deriv_at_id x)\n\n@[simp] lemma deriv_id' : deriv (@id \ud835\udd5c) = \u03bb _, 1 :=\nfunext deriv_id\n\n@[simp] lemma deriv_id'' : deriv (\u03bb x : \ud835\udd5c, x) x = 1 :=\nderiv_id x\n\nlemma deriv_within_id (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within id s x = 1 :=\n(has_deriv_within_at_id x s).deriv_within hxs\n\nend id\n\nsection const\n/-! ### Derivative of constant functions -/\nvariables (c : F) (s x L)\n\ntheorem has_deriv_at_filter_const : has_deriv_at_filter (\u03bb x, c) 0 x L :=\n(has_fderiv_at_filter_const c x L).has_deriv_at_filter\n\ntheorem has_strict_deriv_at_const : has_strict_deriv_at (\u03bb x, c) 0 x :=\n(has_strict_fderiv_at_const c x).has_strict_deriv_at\n\ntheorem has_deriv_within_at_const : has_deriv_within_at (\u03bb x, c) 0 s x :=\nhas_deriv_at_filter_const _ _ _\n\ntheorem has_deriv_at_const : has_deriv_at (\u03bb x, c) 0 x :=\nhas_deriv_at_filter_const _ _ _\n\nlemma deriv_const : deriv (\u03bb x, c) x = 0 :=\nhas_deriv_at.deriv (has_deriv_at_const x c)\n\n@[simp] lemma deriv_const' : deriv (\u03bb x:\ud835\udd5c, c) = \u03bb x, 0 :=\nfunext (\u03bb x, deriv_const x c)\n\nlemma deriv_within_const (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within (\u03bb x, c) s x = 0 :=\n(has_deriv_within_at_const _ _ _).deriv_within hxs\n\nend const\n\nsection continuous_linear_map\n/-! ### Derivative of continuous linear maps -/\nvariables (e : \ud835\udd5c \u2192L[\ud835\udd5c] F)\n\nprotected lemma continuous_linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=\ne.has_fderiv_at_filter.has_deriv_at_filter\n\nprotected lemma continuous_linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=\ne.has_strict_fderiv_at.has_strict_deriv_at\n\nprotected lemma continuous_linear_map.has_deriv_at : has_deriv_at e (e 1) x :=\ne.has_deriv_at_filter\n\nprotected lemma continuous_linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=\ne.has_deriv_at_filter\n\n@[simp] protected lemma continuous_linear_map.deriv : deriv e x = e 1 :=\ne.has_deriv_at.deriv\n\nprotected lemma continuous_linear_map.deriv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within e s x = e 1 :=\ne.has_deriv_within_at.deriv_within hxs\n\nend continuous_linear_map\n\nsection linear_map\n/-! ### Derivative of bundled linear maps -/\nvariables (e : \ud835\udd5c \u2192\u2097[\ud835\udd5c] F)\n\nprotected lemma linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=\ne.to_continuous_linear_map\u2081.has_deriv_at_filter\n\nprotected lemma linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=\ne.to_continuous_linear_map\u2081.has_strict_deriv_at\n\nprotected lemma linear_map.has_deriv_at : has_deriv_at e (e 1) x :=\ne.has_deriv_at_filter\n\nprotected lemma linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=\ne.has_deriv_at_filter\n\n@[simp] protected lemma linear_map.deriv : deriv e x = e 1 :=\ne.has_deriv_at.deriv\n\nprotected lemma linear_map.deriv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within e s x = e 1 :=\ne.has_deriv_within_at.deriv_within hxs\n\nend linear_map\n\nsection analytic\n\nvariables {p : formal_multilinear_series \ud835\udd5c \ud835\udd5c F} {r : \u211d\u22650\u221e}\n\nprotected lemma has_fpower_series_at.has_strict_deriv_at (h : has_fpower_series_at f p x) :\n  has_strict_deriv_at f (p 1 (\u03bb _, 1)) x :=\nh.has_strict_fderiv_at.has_strict_deriv_at\n\nprotected lemma has_fpower_series_at.has_deriv_at (h : has_fpower_series_at f p x) :\n  has_deriv_at f (p 1 (\u03bb _, 1)) x :=\nh.has_strict_deriv_at.has_deriv_at\n\nprotected lemma has_fpower_series_at.deriv (h : has_fpower_series_at f p x) :\n  deriv f x = p 1 (\u03bb _, 1) :=\nh.has_deriv_at.deriv\n\nend analytic\n\nsection add\n/-! ### Derivative of the sum of two functions -/\n\ntheorem has_deriv_at_filter.add\n  (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :\n  has_deriv_at_filter (\u03bb y, f y + g y) (f' + g') x L :=\nby simpa using (hf.add hg).has_deriv_at_filter\n\ntheorem has_strict_deriv_at.add\n  (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :\n  has_strict_deriv_at (\u03bb y, f y + g y) (f' + g') x :=\nby simpa using (hf.add hg).has_strict_deriv_at\n\ntheorem has_deriv_within_at.add\n  (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :\n  has_deriv_within_at (\u03bb y, f y + g y) (f' + g') s x :=\nhf.add hg\n\ntheorem has_deriv_at.add\n  (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :\n  has_deriv_at (\u03bb x, f x + g x) (f' + g') x :=\nhf.add hg\n\nlemma deriv_within_add (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  deriv_within (\u03bby, f y + g y) s x = deriv_within f s x + deriv_within g s x :=\n(hf.has_deriv_within_at.add hg.has_deriv_within_at).deriv_within hxs\n\n@[simp] lemma deriv_add\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  deriv (\u03bby, f y + g y) x = deriv f x + deriv g x :=\n(hf.has_deriv_at.add hg.has_deriv_at).deriv\n\ntheorem has_deriv_at_filter.add_const\n  (hf : has_deriv_at_filter f f' x L) (c : F) :\n  has_deriv_at_filter (\u03bb y, f y + c) f' x L :=\nadd_zero f' \u25b8 hf.add (has_deriv_at_filter_const x L c)\n\ntheorem has_deriv_within_at.add_const\n  (hf : has_deriv_within_at f f' s x) (c : F) :\n  has_deriv_within_at (\u03bb y, f y + c) f' s x :=\nhf.add_const c\n\ntheorem has_deriv_at.add_const\n  (hf : has_deriv_at f f' x) (c : F) :\n  has_deriv_at (\u03bb x, f x + c) f' x :=\nhf.add_const c\n\nlemma deriv_within_add_const (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, f y + c) s x = deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_add_const hxs]\n\nlemma deriv_add_const (c : F) : deriv (\u03bby, f y + c) x = deriv f x :=\nby simp only [deriv, fderiv_add_const]\n\ntheorem has_deriv_at_filter.const_add (c : F) (hf : has_deriv_at_filter f f' x L) :\n  has_deriv_at_filter (\u03bb y, c + f y) f' x L :=\nzero_add f' \u25b8 (has_deriv_at_filter_const x L c).add hf\n\ntheorem has_deriv_within_at.const_add (c : F) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb y, c + f y) f' s x :=\nhf.const_add c\n\ntheorem has_deriv_at.const_add (c : F) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, c + f x) f' x :=\nhf.const_add c\n\nlemma deriv_within_const_add (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, c + f y) s x = deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_const_add hxs]\n\nlemma deriv_const_add (c : F)  : deriv (\u03bby, c + f y) x = deriv f x :=\nby simp only [deriv, fderiv_const_add]\n\nend add\n\nsection sum\n/-! ### Derivative of a finite sum of functions -/\n\nopen_locale big_operators\n\nvariables {\u03b9 : Type*} {u : finset \u03b9} {A : \u03b9 \u2192 (\ud835\udd5c \u2192 F)} {A' : \u03b9 \u2192 F}\n\ntheorem has_deriv_at_filter.sum (h : \u2200 i \u2208 u, has_deriv_at_filter (A i) (A' i) x L) :\n  has_deriv_at_filter (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x L :=\nby simpa [continuous_linear_map.sum_apply] using (has_fderiv_at_filter.sum h).has_deriv_at_filter\n\ntheorem has_strict_deriv_at.sum (h : \u2200 i \u2208 u, has_strict_deriv_at (A i) (A' i) x) :\n  has_strict_deriv_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x :=\nby simpa [continuous_linear_map.sum_apply] using (has_strict_fderiv_at.sum h).has_strict_deriv_at\n\ntheorem has_deriv_within_at.sum (h : \u2200 i \u2208 u, has_deriv_within_at (A i) (A' i) s x) :\n  has_deriv_within_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) s x :=\nhas_deriv_at_filter.sum h\n\ntheorem has_deriv_at.sum (h : \u2200 i \u2208 u, has_deriv_at (A i) (A' i) x) :\n  has_deriv_at (\u03bb y, \u2211 i in u, A i y) (\u2211 i in u, A' i) x :=\nhas_deriv_at_filter.sum h\n\nlemma deriv_within_sum (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (h : \u2200 i \u2208 u, differentiable_within_at \ud835\udd5c (A i) s x) :\n  deriv_within (\u03bb y, \u2211 i in u, A i y) s x = \u2211 i in u, deriv_within (A i) s x :=\n(has_deriv_within_at.sum (\u03bb i hi, (h i hi).has_deriv_within_at)).deriv_within hxs\n\n@[simp] lemma deriv_sum (h : \u2200 i \u2208 u, differentiable_at \ud835\udd5c (A i) x) :\n  deriv (\u03bb y, \u2211 i in u, A i y) x = \u2211 i in u, deriv (A i) x :=\n(has_deriv_at.sum (\u03bb i hi, (h i hi).has_deriv_at)).deriv\n\nend sum\n\nsection pi\n\n/-! ### Derivatives of functions `f : \ud835\udd5c \u2192 \u03a0 i, E i` -/\n\nvariables {\u03b9 : Type*} [fintype \u03b9] {E' : \u03b9 \u2192 Type*} [\u03a0 i, normed_group (E' i)]\n  [\u03a0 i, normed_space \ud835\udd5c (E' i)] {\u03c6 : \ud835\udd5c \u2192 \u03a0 i, E' i} {\u03c6' : \u03a0 i, E' i}\n\n@[simp] lemma has_strict_deriv_at_pi :\n  has_strict_deriv_at \u03c6 \u03c6' x \u2194 \u2200 i, has_strict_deriv_at (\u03bb x, \u03c6 x i) (\u03c6' i) x :=\nhas_strict_fderiv_at_pi'\n\n@[simp] lemma has_deriv_at_filter_pi :\n  has_deriv_at_filter \u03c6 \u03c6' x L \u2194\n    \u2200 i, has_deriv_at_filter (\u03bb x, \u03c6 x i) (\u03c6' i) x L :=\nhas_fderiv_at_filter_pi'\n\nlemma has_deriv_at_pi :\n  has_deriv_at \u03c6 \u03c6' x \u2194 \u2200 i, has_deriv_at (\u03bb x, \u03c6 x i) (\u03c6' i) x:=\nhas_deriv_at_filter_pi\n\nlemma has_deriv_within_at_pi :\n  has_deriv_within_at \u03c6 \u03c6' s x \u2194 \u2200 i, has_deriv_within_at (\u03bb x, \u03c6 x i) (\u03c6' i) s x:=\nhas_deriv_at_filter_pi\n\nlemma deriv_within_pi (h : \u2200 i, differentiable_within_at \ud835\udd5c (\u03bb x, \u03c6 x i) s x)\n  (hs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within \u03c6 s x = \u03bb i, deriv_within (\u03bb x, \u03c6 x i) s x :=\n(has_deriv_within_at_pi.2 (\u03bb i, (h i).has_deriv_within_at)).deriv_within hs\n\nlemma deriv_pi (h : \u2200 i, differentiable_at \ud835\udd5c (\u03bb x, \u03c6 x i) x) :\n  deriv \u03c6 x = \u03bb i, deriv (\u03bb x, \u03c6 x i) x :=\n(has_deriv_at_pi.2 (\u03bb i, (h i).has_deriv_at)).deriv\n\nend pi\n\nsection mul_vector\n/-! ### Derivative of the multiplication of a scalar function and a vector function -/\nvariables {c : \ud835\udd5c \u2192 \ud835\udd5c} {c' : \ud835\udd5c}\n\ntheorem has_deriv_within_at.smul\n  (hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) s x :=\nby simpa using (has_fderiv_within_at.smul hc hf).has_deriv_within_at\n\ntheorem has_deriv_at.smul\n  (hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.smul hf\nend\n\ntheorem has_strict_deriv_at.smul\n  (hc : has_strict_deriv_at c c' x) (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb y, c y \u2022 f y) (c x \u2022 f' + c' \u2022 f x) x :=\nby simpa using (hc.smul hf).has_strict_deriv_at\n\nlemma deriv_within_smul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  deriv_within (\u03bb y, c y \u2022 f y) s x = c x \u2022 deriv_within f s x + (deriv_within c s x) \u2022 f x :=\n(hc.has_deriv_within_at.smul hf.has_deriv_within_at).deriv_within hxs\n\nlemma deriv_smul (hc : differentiable_at \ud835\udd5c c x) (hf : differentiable_at \ud835\udd5c f x) :\n  deriv (\u03bb y, c y \u2022 f y) x = c x \u2022 deriv f x + (deriv c x) \u2022 f x :=\n(hc.has_deriv_at.smul hf.has_deriv_at).deriv\n\ntheorem has_deriv_within_at.smul_const\n  (hc : has_deriv_within_at c c' s x) (f : F) :\n  has_deriv_within_at (\u03bb y, c y \u2022 f) (c' \u2022 f) s x :=\nbegin\n  have := hc.smul (has_deriv_within_at_const x s f),\n  rwa [smul_zero, zero_add] at this\nend\n\ntheorem has_deriv_at.smul_const\n  (hc : has_deriv_at c c' x) (f : F) :\n  has_deriv_at (\u03bb y, c y \u2022 f) (c' \u2022 f) x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.smul_const f\nend\n\nlemma deriv_within_smul_const (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (f : F) :\n  deriv_within (\u03bb y, c y \u2022 f) s x = (deriv_within c s x) \u2022 f :=\n(hc.has_deriv_within_at.smul_const f).deriv_within hxs\n\nlemma deriv_smul_const (hc : differentiable_at \ud835\udd5c c x) (f : F) :\n  deriv (\u03bb y, c y \u2022 f) x = (deriv c x) \u2022 f :=\n(hc.has_deriv_at.smul_const f).deriv\n\ntheorem has_deriv_within_at.const_smul\n  (c : \ud835\udd5c) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb y, c \u2022 f y) (c \u2022 f') s x :=\nbegin\n  convert (has_deriv_within_at_const x s c).smul hf,\n  rw [zero_smul, add_zero]\nend\n\ntheorem has_deriv_at.const_smul (c : \ud835\udd5c) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb y, c \u2022 f y) (c \u2022 f') x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hf.const_smul c\nend\n\nlemma deriv_within_const_smul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (c : \ud835\udd5c) (hf : differentiable_within_at \ud835\udd5c f s x) :\n  deriv_within (\u03bb y, c \u2022 f y) s x = c \u2022 deriv_within f s x :=\n(hf.has_deriv_within_at.const_smul c).deriv_within hxs\n\nlemma deriv_const_smul (c : \ud835\udd5c) (hf : differentiable_at \ud835\udd5c f x) :\n  deriv (\u03bb y, c \u2022 f y) x = c \u2022 deriv f x :=\n(hf.has_deriv_at.const_smul c).deriv\n\nend mul_vector\n\nsection neg\n/-! ### Derivative of the negative of a function -/\n\ntheorem has_deriv_at_filter.neg (h : has_deriv_at_filter f f' x L) :\n  has_deriv_at_filter (\u03bb x, -f x) (-f') x L :=\nby simpa using h.neg.has_deriv_at_filter\n\ntheorem has_deriv_within_at.neg (h : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, -f x) (-f') s x :=\nh.neg\n\ntheorem has_deriv_at.neg (h : has_deriv_at f f' x) : has_deriv_at (\u03bb x, -f x) (-f') x :=\nh.neg\n\ntheorem has_strict_deriv_at.neg (h : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, -f x) (-f') x :=\nby simpa using h.neg.has_strict_deriv_at\n\nlemma deriv_within.neg (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bby, -f y) s x = - deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_neg hxs, continuous_linear_map.neg_apply]\n\nlemma deriv.neg : deriv (\u03bby, -f y) x = - deriv f x :=\nby simp only [deriv, fderiv_neg, continuous_linear_map.neg_apply]\n\n@[simp] lemma deriv.neg' : deriv (\u03bby, -f y) = (\u03bb x, - deriv f x) :=\nfunext $ \u03bb x, deriv.neg\n\nend neg\n\nsection neg2\n/-! ### Derivative of the negation function (i.e `has_neg.neg`) -/\n\nvariables (s x L)\n\ntheorem has_deriv_at_filter_neg : has_deriv_at_filter has_neg.neg (-1) x L :=\nhas_deriv_at_filter.neg $ has_deriv_at_filter_id _ _\n\ntheorem has_deriv_within_at_neg : has_deriv_within_at has_neg.neg (-1) s x :=\nhas_deriv_at_filter_neg _ _\n\ntheorem has_deriv_at_neg : has_deriv_at has_neg.neg (-1) x :=\nhas_deriv_at_filter_neg _ _\n\ntheorem has_deriv_at_neg' : has_deriv_at (\u03bb x, -x) (-1) x :=\nhas_deriv_at_filter_neg _ _\n\ntheorem has_strict_deriv_at_neg : has_strict_deriv_at has_neg.neg (-1) x :=\nhas_strict_deriv_at.neg $ has_strict_deriv_at_id _\n\nlemma deriv_neg : deriv has_neg.neg x = -1 :=\nhas_deriv_at.deriv (has_deriv_at_neg x)\n\n@[simp] lemma deriv_neg' : deriv (has_neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) = \u03bb _, -1 :=\nfunext deriv_neg\n\n@[simp] lemma deriv_neg'' : deriv (\u03bb x : \ud835\udd5c, -x) x = -1 :=\nderiv_neg x\n\nlemma deriv_within_neg (hxs : unique_diff_within_at \ud835\udd5c s x) : deriv_within has_neg.neg s x = -1 :=\n(has_deriv_within_at_neg x s).deriv_within hxs\n\nlemma differentiable_neg : differentiable \ud835\udd5c (has_neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) :=\ndifferentiable.neg differentiable_id\n\nlemma differentiable_on_neg : differentiable_on \ud835\udd5c (has_neg.neg : \ud835\udd5c \u2192 \ud835\udd5c) s :=\ndifferentiable_on.neg differentiable_on_id\n\nend neg2\n\nsection sub\n/-! ### Derivative of the difference of two functions -/\n\ntheorem has_deriv_at_filter.sub\n  (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :\n  has_deriv_at_filter (\u03bb x, f x - g x) (f' - g') x L :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\ntheorem has_deriv_within_at.sub\n  (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :\n  has_deriv_within_at (\u03bb x, f x - g x) (f' - g') s x :=\nhf.sub hg\n\ntheorem has_deriv_at.sub\n  (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :\n  has_deriv_at (\u03bb x, f x - g x) (f' - g') x :=\nhf.sub hg\n\ntheorem has_strict_deriv_at.sub\n  (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :\n  has_strict_deriv_at (\u03bb x, f x - g x) (f' - g') x :=\nby simpa only [sub_eq_add_neg] using hf.add hg.neg\n\nlemma deriv_within_sub (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hf : differentiable_within_at \ud835\udd5c f s x) (hg : differentiable_within_at \ud835\udd5c g s x) :\n  deriv_within (\u03bby, f y - g y) s x = deriv_within f s x - deriv_within g s x :=\n(hf.has_deriv_within_at.sub hg.has_deriv_within_at).deriv_within hxs\n\n@[simp] lemma deriv_sub\n  (hf : differentiable_at \ud835\udd5c f x) (hg : differentiable_at \ud835\udd5c g x) :\n  deriv (\u03bb y, f y - g y) x = deriv f x - deriv g x :=\n(hf.has_deriv_at.sub hg.has_deriv_at).deriv\n\ntheorem has_deriv_at_filter.is_O_sub (h : has_deriv_at_filter f f' x L) :\n  is_O (\u03bb x', f x' - f x) (\u03bb x', x' - x) L :=\nhas_fderiv_at_filter.is_O_sub h\n\ntheorem has_deriv_at_filter.sub_const\n  (hf : has_deriv_at_filter f f' x L) (c : F) :\n  has_deriv_at_filter (\u03bb x, f x - c) f' x L :=\nby simpa only [sub_eq_add_neg] using hf.add_const (-c)\n\ntheorem has_deriv_within_at.sub_const\n  (hf : has_deriv_within_at f f' s x) (c : F) :\n  has_deriv_within_at (\u03bb x, f x - c) f' s x :=\nhf.sub_const c\n\ntheorem has_deriv_at.sub_const\n  (hf : has_deriv_at f f' x) (c : F) :\n  has_deriv_at (\u03bb x, f x - c) f' x :=\nhf.sub_const c\n\nlemma deriv_within_sub_const (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, f y - c) s x = deriv_within f s x :=\nby simp only [deriv_within, fderiv_within_sub_const hxs]\n\nlemma deriv_sub_const (c : F) : deriv (\u03bb y, f y - c) x = deriv f x :=\nby simp only [deriv, fderiv_sub_const]\n\ntheorem has_deriv_at_filter.const_sub (c : F) (hf : has_deriv_at_filter f f' x L) :\n  has_deriv_at_filter (\u03bb x, c - f x) (-f') x L :=\nby simpa only [sub_eq_add_neg] using hf.neg.const_add c\n\ntheorem has_deriv_within_at.const_sub (c : F) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (\u03bb x, c - f x) (-f') s x :=\nhf.const_sub c\n\ntheorem has_strict_deriv_at.const_sub (c : F) (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (\u03bb x, c - f x) (-f') x :=\nby simpa only [sub_eq_add_neg] using hf.neg.const_add c\n\ntheorem has_deriv_at.const_sub (c : F) (hf : has_deriv_at f f' x) :\n  has_deriv_at (\u03bb x, c - f x) (-f') x :=\nhf.const_sub c\n\nlemma deriv_within_const_sub (hxs : unique_diff_within_at \ud835\udd5c s x) (c : F) :\n  deriv_within (\u03bby, c - f y) s x = -deriv_within f s x :=\nby simp [deriv_within, fderiv_within_const_sub hxs]\n\nlemma deriv_const_sub (c : F) : deriv (\u03bb y, c - f y) x = -deriv f x :=\nby simp only [\u2190 deriv_within_univ, deriv_within_const_sub unique_diff_within_at_univ]\n\nend sub\n\nsection continuous\n/-! ### Continuity of a function admitting a derivative -/\n\ntheorem has_deriv_at_filter.tendsto_nhds\n  (hL : L \u2264 \ud835\udcdd x) (h : has_deriv_at_filter f f' x L) :\n  tendsto f L (\ud835\udcdd (f x)) :=\nh.tendsto_nhds hL\n\ntheorem has_deriv_within_at.continuous_within_at\n  (h : has_deriv_within_at f f' s x) : continuous_within_at f s x :=\nhas_deriv_at_filter.tendsto_nhds inf_le_left h\n\ntheorem has_deriv_at.continuous_at (h : has_deriv_at f f' x) : continuous_at f x :=\nhas_deriv_at_filter.tendsto_nhds (le_refl _) h\n\nprotected theorem has_deriv_at.continuous_on {f f' : \ud835\udd5c \u2192 F}\n  (hderiv : \u2200 x \u2208 s, has_deriv_at f (f' x) x) : continuous_on f s :=\n\u03bb x hx, (hderiv x hx).continuous_at.continuous_within_at\n\nend continuous\n\nsection cartesian_product\n/-! ### Derivative of the cartesian product of two functions -/\n\nvariables {G : Type w} [normed_group G] [normed_space \ud835\udd5c G]\nvariables {f\u2082 : \ud835\udd5c \u2192 G} {f\u2082' : G}\n\nlemma has_deriv_at_filter.prod\n  (hf\u2081 : has_deriv_at_filter f\u2081 f\u2081' x L) (hf\u2082 : has_deriv_at_filter f\u2082 f\u2082' x L) :\n  has_deriv_at_filter (\u03bb x, (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x L :=\nshow has_fderiv_at_filter _ _ _ _,\nby convert has_fderiv_at_filter.prod hf\u2081 hf\u2082\n\nlemma has_deriv_within_at.prod\n  (hf\u2081 : has_deriv_within_at f\u2081 f\u2081' s x) (hf\u2082 : has_deriv_within_at f\u2082 f\u2082' s x) :\n  has_deriv_within_at (\u03bb x, (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') s x :=\nhf\u2081.prod hf\u2082\n\nlemma has_deriv_at.prod (hf\u2081 : has_deriv_at f\u2081 f\u2081' x) (hf\u2082 : has_deriv_at f\u2082 f\u2082' x) :\n  has_deriv_at (\u03bb x, (f\u2081 x, f\u2082 x)) (f\u2081', f\u2082') x :=\nhf\u2081.prod hf\u2082\n\nend cartesian_product\n\nsection composition\n/-!\n### Derivative of the composition of a vector function and a scalar function\n\nWe use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`\nin lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also\nbecause the `comp` version with the shorter name will show up much more often in applications).\nThe formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to\nusual multiplication in `comp` lemmas.\n-/\n\nvariables {h h\u2081 h\u2082 : \ud835\udd5c \u2192 \ud835\udd5c} {h' h\u2081' h\u2082' : \ud835\udd5c}\n/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to\nget confused since there are too many possibilities for composition -/\nvariable (x)\n\ntheorem has_deriv_at_filter.scomp\n  (hg : has_deriv_at_filter g g' (h x) (L.map h))\n  (hh : has_deriv_at_filter h h' x L) :\n  has_deriv_at_filter (g \u2218 h) (h' \u2022 g') x L :=\nby simpa using (hg.comp x hh).has_deriv_at_filter\n\ntheorem has_deriv_within_at.scomp {t : set \ud835\udd5c}\n  (hg : has_deriv_within_at g g' t (h x))\n  (hh : has_deriv_within_at h h' s x) (hst : s \u2286 h \u207b\u00b9' t) :\n  has_deriv_within_at (g \u2218 h) (h' \u2022 g') s x :=\nhas_deriv_at_filter.scomp _ (has_deriv_at_filter.mono hg $\n  hh.continuous_within_at.tendsto_nhds_within hst) hh\n\n/-- The chain rule. -/\ntheorem has_deriv_at.scomp\n  (hg : has_deriv_at g g' (h x)) (hh : has_deriv_at h h' x) :\n  has_deriv_at (g \u2218 h) (h' \u2022 g') x :=\n(hg.mono hh.continuous_at).scomp x hh\n\ntheorem has_strict_deriv_at.scomp\n  (hg : has_strict_deriv_at g g' (h x)) (hh : has_strict_deriv_at h h' x) :\n  has_strict_deriv_at (g \u2218 h) (h' \u2022 g') x :=\nby simpa using (hg.comp x hh).has_strict_deriv_at\n\ntheorem has_deriv_at.scomp_has_deriv_within_at\n  (hg : has_deriv_at g g' (h x)) (hh : has_deriv_within_at h h' s x) :\n  has_deriv_within_at (g \u2218 h) (h' \u2022 g') s x :=\nbegin\n  rw \u2190 has_deriv_within_at_univ at hg,\n  exact has_deriv_within_at.scomp x hg hh subset_preimage_univ\nend\n\nlemma deriv_within.scomp\n  (hg : differentiable_within_at \ud835\udd5c g t (h x)) (hh : differentiable_within_at \ud835\udd5c h s x)\n  (hs : s \u2286 h \u207b\u00b9' t) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (g \u2218 h) s x = deriv_within h s x \u2022 deriv_within g t (h x) :=\nbegin\n  apply has_deriv_within_at.deriv_within _ hxs,\n  exact has_deriv_within_at.scomp x (hg.has_deriv_within_at) (hh.has_deriv_within_at) hs\nend\n\nlemma deriv.scomp\n  (hg : differentiable_at \ud835\udd5c g (h x)) (hh : differentiable_at \ud835\udd5c h x) :\n  deriv (g \u2218 h) x = deriv h x \u2022 deriv g (h x) :=\nbegin\n  apply has_deriv_at.deriv,\n  exact has_deriv_at.scomp x hg.has_deriv_at hh.has_deriv_at\nend\n\n/-! ### Derivative of the composition of a scalar and vector functions -/\n\ntheorem has_deriv_at_filter.comp_has_fderiv_at_filter {f : E \u2192 \ud835\udd5c} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c} (x)\n  {L : filter E} (hh\u2081 : has_deriv_at_filter h\u2081 h\u2081' (f x) (L.map f))\n  (hf : has_fderiv_at_filter f f' x L) :\n  has_fderiv_at_filter (h\u2081 \u2218 f) (h\u2081' \u2022 f') x L :=\nby { convert has_fderiv_at_filter.comp x hh\u2081 hf, ext x, simp [mul_comm] }\n\ntheorem has_strict_deriv_at.comp_has_strict_fderiv_at {f : E \u2192 \ud835\udd5c} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c} (x)\n  (hh\u2081 : has_strict_deriv_at h\u2081 h\u2081' (f x)) (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (h\u2081 \u2218 f) (h\u2081' \u2022 f') x :=\nby { rw has_strict_deriv_at at hh\u2081, convert hh\u2081.comp x hf, ext x, simp [mul_comm] }\n\ntheorem has_deriv_at.comp_has_fderiv_at {f : E \u2192 \ud835\udd5c} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c} (x)\n  (hh\u2081 : has_deriv_at h\u2081 h\u2081' (f x)) (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (h\u2081 \u2218 f) (h\u2081' \u2022 f') x :=\n(hh\u2081.mono hf.continuous_at).comp_has_fderiv_at_filter x hf\n\ntheorem has_deriv_at.comp_has_fderiv_within_at {f : E \u2192 \ud835\udd5c} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c} {s} (x)\n  (hh\u2081 : has_deriv_at h\u2081 h\u2081' (f x)) (hf : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (h\u2081 \u2218 f) (h\u2081' \u2022 f') s x :=\n(hh\u2081.mono hf.continuous_within_at).comp_has_fderiv_at_filter x hf\n\ntheorem has_deriv_within_at.comp_has_fderiv_within_at {f : E \u2192 \ud835\udd5c} {f' : E \u2192L[\ud835\udd5c] \ud835\udd5c} {s t} (x)\n  (hh\u2081 : has_deriv_within_at h\u2081 h\u2081' t (f x)) (hf : has_fderiv_within_at f f' s x)\n  (hst : maps_to f s t) :\n  has_fderiv_within_at (h\u2081 \u2218 f) (h\u2081' \u2022 f') s x :=\n(has_deriv_at_filter.mono hh\u2081 $\n  hf.continuous_within_at.tendsto_nhds_within hst).comp_has_fderiv_at_filter x hf\n\n/-! ### Derivative of the composition of two scalar functions -/\n\ntheorem has_deriv_at_filter.comp\n  (hh\u2081 : has_deriv_at_filter h\u2081 h\u2081' (h\u2082 x) (L.map h\u2082))\n  (hh\u2082 : has_deriv_at_filter h\u2082 h\u2082' x L) :\n  has_deriv_at_filter (h\u2081 \u2218 h\u2082) (h\u2081' * h\u2082') x L :=\nby { rw mul_comm, exact hh\u2081.scomp x hh\u2082 }\n\ntheorem has_deriv_within_at.comp {t : set \ud835\udd5c}\n  (hh\u2081 : has_deriv_within_at h\u2081 h\u2081' t (h\u2082 x))\n  (hh\u2082 : has_deriv_within_at h\u2082 h\u2082' s x) (hst : s \u2286 h\u2082 \u207b\u00b9' t) :\n  has_deriv_within_at (h\u2081 \u2218 h\u2082) (h\u2081' * h\u2082') s x :=\nby { rw mul_comm, exact hh\u2081.scomp x hh\u2082 hst, }\n\n/-- The chain rule. -/\ntheorem has_deriv_at.comp\n  (hh\u2081 : has_deriv_at h\u2081 h\u2081' (h\u2082 x)) (hh\u2082 : has_deriv_at h\u2082 h\u2082' x) :\n  has_deriv_at (h\u2081 \u2218 h\u2082) (h\u2081' * h\u2082') x :=\n(hh\u2081.mono hh\u2082.continuous_at).comp x hh\u2082\n\ntheorem has_strict_deriv_at.comp\n  (hh\u2081 : has_strict_deriv_at h\u2081 h\u2081' (h\u2082 x)) (hh\u2082 : has_strict_deriv_at h\u2082 h\u2082' x) :\n  has_strict_deriv_at (h\u2081 \u2218 h\u2082) (h\u2081' * h\u2082') x :=\nby { rw mul_comm, exact hh\u2081.scomp x hh\u2082 }\n\ntheorem has_deriv_at.comp_has_deriv_within_at\n  (hh\u2081 : has_deriv_at h\u2081 h\u2081' (h\u2082 x)) (hh\u2082 : has_deriv_within_at h\u2082 h\u2082' s x) :\n  has_deriv_within_at (h\u2081 \u2218 h\u2082) (h\u2081' * h\u2082') s x :=\nbegin\n  rw \u2190 has_deriv_within_at_univ at hh\u2081,\n  exact has_deriv_within_at.comp x hh\u2081 hh\u2082 subset_preimage_univ\nend\n\nlemma deriv_within.comp\n  (hh\u2081 : differentiable_within_at \ud835\udd5c h\u2081 t (h\u2082 x)) (hh\u2082 : differentiable_within_at \ud835\udd5c h\u2082 s x)\n  (hs : s \u2286 h\u2082 \u207b\u00b9' t) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (h\u2081 \u2218 h\u2082) s x = deriv_within h\u2081 t (h\u2082 x) * deriv_within h\u2082 s x :=\nbegin\n  apply has_deriv_within_at.deriv_within _ hxs,\n  exact has_deriv_within_at.comp x (hh\u2081.has_deriv_within_at) (hh\u2082.has_deriv_within_at) hs\nend\n\nlemma deriv.comp\n  (hh\u2081 : differentiable_at \ud835\udd5c h\u2081 (h\u2082 x)) (hh\u2082 : differentiable_at \ud835\udd5c h\u2082 x) :\n  deriv (h\u2081 \u2218 h\u2082) x = deriv h\u2081 (h\u2082 x) * deriv h\u2082 x :=\nbegin\n  apply has_deriv_at.deriv,\n  exact has_deriv_at.comp x hh\u2081.has_deriv_at hh\u2082.has_deriv_at\nend\n\nprotected lemma has_deriv_at_filter.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_deriv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : \u2115) :\n  has_deriv_at_filter (f^[n]) (f'^n) x L :=\nbegin\n  have := hf.iterate hL hx n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nprotected lemma has_deriv_at.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_deriv_at f f' x) (hx : f x = x) (n : \u2115) :\n  has_deriv_at (f^[n]) (f'^n) x :=\nbegin\n  have := has_fderiv_at.iterate hf hx n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nprotected lemma has_deriv_within_at.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_deriv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : \u2115) :\n  has_deriv_within_at (f^[n]) (f'^n) s x :=\nbegin\n  have := has_fderiv_within_at.iterate hf hx hs n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nprotected lemma has_strict_deriv_at.iterate {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' : \ud835\udd5c}\n  (hf : has_strict_deriv_at f f' x) (hx : f x = x) (n : \u2115) :\n  has_strict_deriv_at (f^[n]) (f'^n) x :=\nbegin\n  have := hf.iterate hx n,\n  rwa [continuous_linear_map.smul_right_one_pow] at this\nend\n\nend composition\n\nsection composition_vector\n/-! ### Derivative of the composition of a function between vector spaces and a function on `\ud835\udd5c` -/\n\nvariables {l : F \u2192 E} {l' : F \u2192L[\ud835\udd5c] E}\nvariable (x)\n\n/-- The composition `l \u2218 f` where `l : F \u2192 E` and `f : \ud835\udd5c \u2192 F`, has a derivative within a set\nequal to the Fr\u00e9chet derivative of `l` applied to the derivative of `f`. -/\ntheorem has_fderiv_within_at.comp_has_deriv_within_at {t : set F}\n  (hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x) (hst : s \u2286 f \u207b\u00b9' t) :\n  has_deriv_within_at (l \u2218 f) (l' (f')) s x :=\nbegin\n  rw has_deriv_within_at_iff_has_fderiv_within_at,\n  convert has_fderiv_within_at.comp x hl hf hst,\n  ext,\n  simp\nend\n\n/-- The composition `l \u2218 f` where `l : F \u2192 E` and `f : \ud835\udd5c \u2192 F`, has a derivative equal to the\nFr\u00e9chet derivative of `l` applied to the derivative of `f`. -/\ntheorem has_fderiv_at.comp_has_deriv_at\n  (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) :\n  has_deriv_at (l \u2218 f) (l' (f')) x :=\nbegin\n  rw has_deriv_at_iff_has_fderiv_at,\n  convert has_fderiv_at.comp x hl hf,\n  ext,\n  simp\nend\n\ntheorem has_fderiv_at.comp_has_deriv_within_at\n  (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) :\n  has_deriv_within_at (l \u2218 f) (l' (f')) s x :=\nbegin\n  rw \u2190 has_fderiv_within_at_univ at hl,\n  exact has_fderiv_within_at.comp_has_deriv_within_at x hl hf subset_preimage_univ\nend\n\nlemma fderiv_within.comp_deriv_within {t : set F}\n  (hl : differentiable_within_at \ud835\udd5c l t (f x)) (hf : differentiable_within_at \ud835\udd5c f s x)\n  (hs : s \u2286 f \u207b\u00b9' t) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (l \u2218 f) s x = (fderiv_within \ud835\udd5c l t (f x) : F \u2192 E) (deriv_within f s x) :=\nbegin\n  apply has_deriv_within_at.deriv_within _ hxs,\n  exact (hl.has_fderiv_within_at).comp_has_deriv_within_at x (hf.has_deriv_within_at) hs\nend\n\nlemma fderiv.comp_deriv\n  (hl : differentiable_at \ud835\udd5c l (f x)) (hf : differentiable_at \ud835\udd5c f x) :\n  deriv (l \u2218 f) x = (fderiv \ud835\udd5c l (f x) : F \u2192 E) (deriv f x) :=\nbegin\n  apply has_deriv_at.deriv _,\n  exact (hl.has_fderiv_at).comp_has_deriv_at x (hf.has_deriv_at)\nend\n\nend composition_vector\n\nsection mul\n/-! ### Derivative of the multiplication of two scalar functions -/\nvariables {c d : \ud835\udd5c \u2192 \ud835\udd5c} {c' d' : \ud835\udd5c}\n\ntheorem has_deriv_within_at.mul\n  (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) :\n  has_deriv_within_at (\u03bb y, c y * d y) (c' * d x + c x * d') s x :=\nbegin\n  convert hc.smul hd using 1,\n  rw [smul_eq_mul, smul_eq_mul, add_comm]\nend\n\ntheorem has_deriv_at.mul (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :\n  has_deriv_at (\u03bb y, c y * d y) (c' * d x + c x * d') x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.mul hd\nend\n\ntheorem has_strict_deriv_at.mul\n  (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) :\n  has_strict_deriv_at (\u03bb y, c y * d y) (c' * d x + c x * d') x :=\nbegin\n  convert hc.smul hd using 1,\n  rw [smul_eq_mul, smul_eq_mul, add_comm]\nend\n\nlemma deriv_within_mul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) :\n  deriv_within (\u03bb y, c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x :=\n(hc.has_deriv_within_at.mul hd.has_deriv_within_at).deriv_within hxs\n\n@[simp] lemma deriv_mul (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) :\n  deriv (\u03bb y, c y * d y) x = deriv c x * d x + c x * deriv d x :=\n(hc.has_deriv_at.mul hd.has_deriv_at).deriv\n\ntheorem has_deriv_within_at.mul_const (hc : has_deriv_within_at c c' s x) (d : \ud835\udd5c) :\n  has_deriv_within_at (\u03bb y, c y * d) (c' * d) s x :=\nbegin\n  convert hc.mul (has_deriv_within_at_const x s d),\n  rw [mul_zero, add_zero]\nend\n\ntheorem has_deriv_at.mul_const (hc : has_deriv_at c c' x) (d : \ud835\udd5c) :\n  has_deriv_at (\u03bb y, c y * d) (c' * d) x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hc.mul_const d\nend\n\ntheorem has_strict_deriv_at.mul_const (hc : has_strict_deriv_at c c' x) (d : \ud835\udd5c) :\n  has_strict_deriv_at (\u03bb y, c y * d) (c' * d) x :=\nbegin\n  convert hc.mul (has_strict_deriv_at_const x d),\n  rw [mul_zero, add_zero]\nend\n\nlemma deriv_within_mul_const (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (hc : differentiable_within_at \ud835\udd5c c s x) (d : \ud835\udd5c) :\n  deriv_within (\u03bb y, c y * d) s x = deriv_within c s x * d :=\n(hc.has_deriv_within_at.mul_const d).deriv_within hxs\n\nlemma deriv_mul_const (hc : differentiable_at \ud835\udd5c c x) (d : \ud835\udd5c) :\n  deriv (\u03bb y, c y * d) x = deriv c x * d :=\n(hc.has_deriv_at.mul_const d).deriv\n\ntheorem has_deriv_within_at.const_mul (c : \ud835\udd5c) (hd : has_deriv_within_at d d' s x) :\n  has_deriv_within_at (\u03bb y, c * d y) (c * d') s x :=\nbegin\n  convert (has_deriv_within_at_const x s c).mul hd,\n  rw [zero_mul, zero_add]\nend\n\ntheorem has_deriv_at.const_mul (c : \ud835\udd5c) (hd : has_deriv_at d d' x) :\n  has_deriv_at (\u03bb y, c * d y) (c * d') x :=\nbegin\n  rw [\u2190 has_deriv_within_at_univ] at *,\n  exact hd.const_mul c\nend\n\ntheorem has_strict_deriv_at.const_mul (c : \ud835\udd5c) (hd : has_strict_deriv_at d d' x) :\n  has_strict_deriv_at (\u03bb y, c * d y) (c * d') x :=\nbegin\n  convert (has_strict_deriv_at_const _ _).mul hd,\n  rw [zero_mul, zero_add]\nend\n\nlemma deriv_within_const_mul (hxs : unique_diff_within_at \ud835\udd5c s x)\n  (c : \ud835\udd5c) (hd : differentiable_within_at \ud835\udd5c d s x) :\n  deriv_within (\u03bb y, c * d y) s x = c * deriv_within d s x :=\n(hd.has_deriv_within_at.const_mul c).deriv_within hxs\n\nlemma deriv_const_mul (c : \ud835\udd5c) (hd : differentiable_at \ud835\udd5c d x) :\n  deriv (\u03bb y, c * d y) x = c * deriv d x :=\n(hd.has_deriv_at.const_mul c).deriv\n\nend mul\n\nsection inverse\n/-! ### Derivative of `x \u21a6 x\u207b\u00b9` -/\n\ntheorem has_strict_deriv_at_inv (hx : x \u2260 0) : has_strict_deriv_at has_inv.inv (-(x^2)\u207b\u00b9) x :=\nbegin\n  suffices : is_o (\u03bb p : \ud835\udd5c \u00d7 \ud835\udd5c, (p.1 - p.2) * ((x * x)\u207b\u00b9 - (p.1 * p.2)\u207b\u00b9))\n    (\u03bb (p : \ud835\udd5c \u00d7 \ud835\udd5c), (p.1 - p.2) * 1) (\ud835\udcdd (x, x)),\n  { refine this.congr' _ (eventually_of_forall $ \u03bb _, mul_one _),\n    refine eventually.mono (mem_nhds_sets (is_open_ne.prod is_open_ne) \u27e8hx, hx\u27e9) _,\n    rintro \u27e8y, z\u27e9 \u27e8hy, hz\u27e9,\n    simp only [mem_set_of_eq] at hy hz, -- hy : y \u2260 0, hz : z \u2260 0\n    field_simp [hx, hy, hz], ring, },\n  refine (is_O_refl (\u03bb p : \ud835\udd5c \u00d7 \ud835\udd5c, p.1 - p.2) _).mul_is_o ((is_o_one_iff _).2 _),\n  rw [\u2190 sub_self (x * x)\u207b\u00b9],\n  exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv' $ mul_ne_zero hx hx)\nend\n\ntheorem has_deriv_at_inv (x_ne_zero : x \u2260 0) :\n  has_deriv_at (\u03bby, y\u207b\u00b9) (-(x^2)\u207b\u00b9) x :=\n(has_strict_deriv_at_inv x_ne_zero).has_deriv_at\n\ntheorem has_deriv_within_at_inv (x_ne_zero : x \u2260 0) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, x\u207b\u00b9) (-(x^2)\u207b\u00b9) s x :=\n(has_deriv_at_inv x_ne_zero).has_deriv_within_at\n\nlemma differentiable_at_inv (x_ne_zero : x \u2260 0) :\n  differentiable_at \ud835\udd5c (\u03bbx, x\u207b\u00b9) x :=\n(has_deriv_at_inv x_ne_zero).differentiable_at\n\nlemma differentiable_within_at_inv (x_ne_zero : x \u2260 0) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, x\u207b\u00b9) s x :=\n(differentiable_at_inv x_ne_zero).differentiable_within_at\n\nlemma differentiable_on_inv : differentiable_on \ud835\udd5c (\u03bbx:\ud835\udd5c, x\u207b\u00b9) {x | x \u2260 0} :=\n\u03bbx hx, differentiable_within_at_inv hx\n\nlemma deriv_inv (x_ne_zero : x \u2260 0) :\n  deriv (\u03bbx, x\u207b\u00b9) x = -(x^2)\u207b\u00b9 :=\n(has_deriv_at_inv x_ne_zero).deriv\n\nlemma deriv_within_inv (x_ne_zero : x \u2260 0) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, x\u207b\u00b9) s x = -(x^2)\u207b\u00b9 :=\nbegin\n  rw differentiable_at.deriv_within (differentiable_at_inv x_ne_zero) hxs,\n  exact deriv_inv x_ne_zero\nend\n\nlemma has_fderiv_at_inv (x_ne_zero : x \u2260 0) :\n  has_fderiv_at (\u03bbx, x\u207b\u00b9) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\nhas_deriv_at_inv x_ne_zero\n\nlemma has_fderiv_within_at_inv (x_ne_zero : x \u2260 0) :\n  has_fderiv_within_at (\u03bbx, x\u207b\u00b9) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) s x :=\n(has_fderiv_at_inv x_ne_zero).has_fderiv_within_at\n\nlemma fderiv_inv (x_ne_zero : x \u2260 0) :\n  fderiv \ud835\udd5c (\u03bbx, x\u207b\u00b9) x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) :=\n(has_fderiv_at_inv x_ne_zero).fderiv\n\nlemma fderiv_within_inv (x_ne_zero : x \u2260 0) (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bbx, x\u207b\u00b9) s x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (-(x^2)\u207b\u00b9) :=\nbegin\n  rw differentiable_at.fderiv_within (differentiable_at_inv x_ne_zero) hxs,\n  exact fderiv_inv x_ne_zero\nend\n\nvariables {c : \ud835\udd5c \u2192 \ud835\udd5c} {c' : \ud835\udd5c}\n\nlemma has_deriv_within_at.inv\n  (hc : has_deriv_within_at c c' s x) (hx : c x \u2260 0) :\n  has_deriv_within_at (\u03bb y, (c y)\u207b\u00b9) (- c' / (c x)^2) s x :=\nbegin\n  convert (has_deriv_at_inv hx).comp_has_deriv_within_at x hc,\n  field_simp\nend\n\nlemma has_deriv_at.inv (hc : has_deriv_at c c' x) (hx : c x \u2260 0) :\n  has_deriv_at (\u03bb y, (c y)\u207b\u00b9) (- c' / (c x)^2) x :=\nbegin\n  rw \u2190 has_deriv_within_at_univ at *,\n  exact hc.inv hx\nend\n\nlemma differentiable_within_at.inv (hc : differentiable_within_at \ud835\udd5c c s x) (hx : c x \u2260 0) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, (c x)\u207b\u00b9) s x :=\n(hc.has_deriv_within_at.inv hx).differentiable_within_at\n\n@[simp] lemma differentiable_at.inv (hc : differentiable_at \ud835\udd5c c x) (hx : c x \u2260 0) :\n  differentiable_at \ud835\udd5c (\u03bbx, (c x)\u207b\u00b9) x :=\n(hc.has_deriv_at.inv hx).differentiable_at\n\nlemma differentiable_on.inv (hc : differentiable_on \ud835\udd5c c s) (hx : \u2200 x \u2208 s, c x \u2260 0) :\n  differentiable_on \ud835\udd5c (\u03bbx, (c x)\u207b\u00b9) s :=\n\u03bbx h, (hc x h).inv (hx x h)\n\n@[simp] lemma differentiable.inv (hc : differentiable \ud835\udd5c c) (hx : \u2200 x, c x \u2260 0) :\n  differentiable \ud835\udd5c (\u03bbx, (c x)\u207b\u00b9) :=\n\u03bbx, (hc x).inv (hx x)\n\nlemma deriv_within_inv' (hc : differentiable_within_at \ud835\udd5c c s x) (hx : c x \u2260 0)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, (c x)\u207b\u00b9) s x = - (deriv_within c s x) / (c x)^2 :=\n(hc.has_deriv_within_at.inv hx).deriv_within hxs\n\n@[simp] lemma deriv_inv' (hc : differentiable_at \ud835\udd5c c x) (hx : c x \u2260 0) :\n  deriv (\u03bbx, (c x)\u207b\u00b9) x = - (deriv c x) / (c x)^2 :=\n(hc.has_deriv_at.inv hx).deriv\n\nend inverse\n\nsection division\n/-! ### Derivative of `x \u21a6 c x / d x` -/\n\nvariables {c d : \ud835\udd5c \u2192 \ud835\udd5c} {c' d' : \ud835\udd5c}\n\nlemma has_deriv_within_at.div\n  (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x \u2260 0) :\n  has_deriv_within_at (\u03bb y, c y / d y) ((c' * d x - c x * d') / (d x)^2) s x :=\nbegin\n  convert hc.mul ((has_deriv_at_inv hx).comp_has_deriv_within_at x hd),\n  { simp only [div_eq_mul_inv] },\n  { field_simp, ring }\nend\n\nlemma has_strict_deriv_at.div (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x)\n  (hx : d x \u2260 0) :\n  has_strict_deriv_at (\u03bb y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=\nbegin\n  convert hc.mul ((has_strict_deriv_at_inv hx).comp x hd),\n  { simp only [div_eq_mul_inv] },\n  { field_simp, ring }\nend\n\nlemma has_deriv_at.div (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x \u2260 0) :\n  has_deriv_at (\u03bb y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=\nbegin\n  rw \u2190 has_deriv_within_at_univ at *,\n  exact hc.div hd hx\nend\n\nlemma differentiable_within_at.div\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) (hx : d x \u2260 0) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, c x / d x) s x :=\n((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).differentiable_within_at\n\n@[simp] lemma differentiable_at.div\n  (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) (hx : d x \u2260 0) :\n  differentiable_at \ud835\udd5c (\u03bbx, c x / d x) x :=\n((hc.has_deriv_at).div (hd.has_deriv_at) hx).differentiable_at\n\nlemma differentiable_on.div\n  (hc : differentiable_on \ud835\udd5c c s) (hd : differentiable_on \ud835\udd5c d s) (hx : \u2200 x \u2208 s, d x \u2260 0) :\n  differentiable_on \ud835\udd5c (\u03bbx, c x / d x) s :=\n\u03bbx h, (hc x h).div (hd x h) (hx x h)\n\n@[simp] lemma differentiable.div\n  (hc : differentiable \ud835\udd5c c) (hd : differentiable \ud835\udd5c d) (hx : \u2200 x, d x \u2260 0) :\ndifferentiable \ud835\udd5c (\u03bbx, c x / d x) :=\n\u03bbx, (hc x).div (hd x) (hx x)\n\nlemma deriv_within_div\n  (hc : differentiable_within_at \ud835\udd5c c s x) (hd : differentiable_within_at \ud835\udd5c d s x) (hx : d x \u2260 0)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, c x / d x) s x\n    = ((deriv_within c s x) * d x - c x * (deriv_within d s x)) / (d x)^2 :=\n((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).deriv_within hxs\n\n@[simp] lemma deriv_div\n  (hc : differentiable_at \ud835\udd5c c x) (hd : differentiable_at \ud835\udd5c d x) (hx : d x \u2260 0) :\n  deriv (\u03bbx, c x / d x) x = ((deriv c x) * d x - c x * (deriv d x)) / (d x)^2 :=\n((hc.has_deriv_at).div (hd.has_deriv_at) hx).deriv\n\nlemma differentiable_within_at.div_const (hc : differentiable_within_at \ud835\udd5c c s x) {d : \ud835\udd5c} :\n  differentiable_within_at \ud835\udd5c (\u03bbx, c x / d) s x :=\nby simp [div_eq_inv_mul, differentiable_within_at.const_mul, hc]\n\n@[simp] lemma differentiable_at.div_const (hc : differentiable_at \ud835\udd5c c x) {d : \ud835\udd5c} :\n  differentiable_at \ud835\udd5c (\u03bb x, c x / d) x :=\nby simpa only [div_eq_mul_inv] using (hc.has_deriv_at.mul_const d\u207b\u00b9).differentiable_at\n\nlemma differentiable_on.div_const (hc : differentiable_on \ud835\udd5c c s) {d : \ud835\udd5c} :\n  differentiable_on \ud835\udd5c (\u03bbx, c x / d) s :=\nby simp [div_eq_inv_mul, differentiable_on.const_mul, hc]\n\n@[simp] lemma differentiable.div_const (hc : differentiable \ud835\udd5c c) {d : \ud835\udd5c} :\n  differentiable \ud835\udd5c (\u03bbx, c x / d) :=\nby simp [div_eq_inv_mul, differentiable.const_mul, hc]\n\nlemma deriv_within_div_const (hc : differentiable_within_at \ud835\udd5c c s x) {d : \ud835\udd5c}\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, c x / d) s x = (deriv_within c s x) / d :=\nby simp [div_eq_inv_mul, deriv_within_const_mul, hc, hxs]\n\n@[simp] lemma deriv_div_const (hc : differentiable_at \ud835\udd5c c x) {d : \ud835\udd5c} :\n  deriv (\u03bbx, c x / d) x = (deriv c x) / d :=\nby simp [div_eq_inv_mul, deriv_const_mul, hc]\n\nend division\n\ntheorem has_strict_deriv_at.has_strict_fderiv_at_equiv {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' x : \ud835\udd5c}\n  (hf : has_strict_deriv_at f f' x) (hf' : f' \u2260 0) :\n  has_strict_fderiv_at f\n    (continuous_linear_equiv.units_equiv_aut \ud835\udd5c (units.mk0 f' hf') : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\nhf\n\ntheorem has_deriv_at.has_fderiv_at_equiv {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' x : \ud835\udd5c}\n  (hf : has_deriv_at f f' x) (hf' : f' \u2260 0) :\n  has_fderiv_at f\n    (continuous_linear_equiv.units_equiv_aut \ud835\udd5c (units.mk0 f' hf') : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) x :=\nhf\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'\u207b\u00b9` at `a`\nin the strict sense.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have an\ninverse function. -/\ntheorem has_strict_deriv_at.of_local_left_inverse {f g : \ud835\udd5c \u2192 \ud835\udd5c} {f' a : \ud835\udd5c}\n  (hg : continuous_at g a) (hf : has_strict_deriv_at f f' (g a)) (hf' : f' \u2260 0)\n  (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n  has_strict_deriv_at g f'\u207b\u00b9 a :=\n(hf.has_strict_fderiv_at_equiv hf').of_local_left_inverse hg hfg\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a\nnonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` has the derivative `f'\u207b\u00b9`\nat `a` in the strict sense.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\nlemma local_homeomorph.has_strict_deriv_at_symm (f : local_homeomorph \ud835\udd5c \ud835\udd5c) {a f' : \ud835\udd5c}\n  (ha : a \u2208 f.target) (hf' : f' \u2260 0) (htff' : has_strict_deriv_at f f' (f.symm a)) :\n  has_strict_deriv_at f.symm f'\u207b\u00b9 a :=\nhtff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)\n\n/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an\ninvertible derivative `f'` at `g a`, then `g` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\ntheorem has_deriv_at.of_local_left_inverse {f g : \ud835\udd5c \u2192 \ud835\udd5c} {f' a : \ud835\udd5c}\n  (hg : continuous_at g a) (hf : has_deriv_at f f' (g a)) (hf' : f' \u2260 0)\n  (hfg : \u2200\u1da0 y in \ud835\udcdd a, f (g y) = y) :\n  has_deriv_at g f'\u207b\u00b9 a :=\n(hf.has_fderiv_at_equiv hf').of_local_left_inverse hg hfg\n\n/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an\nnonzero derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'\u207b\u00b9` at `a`.\n\nThis is one of the easy parts of the inverse function theorem: it assumes that we already have\nan inverse function. -/\nlemma local_homeomorph.has_deriv_at_symm (f : local_homeomorph \ud835\udd5c \ud835\udd5c) {a f' : \ud835\udd5c}\n  (ha : a \u2208 f.target) (hf' : f' \u2260 0) (htff' : has_deriv_at f f' (f.symm a)) :\n  has_deriv_at f.symm f'\u207b\u00b9 a :=\nhtff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)\n\nlemma has_deriv_at.eventually_ne (h : has_deriv_at f f' x) (hf' : f' \u2260 0) :\n  \u2200\u1da0 z in \ud835\udcdd[{x}\u1d9c] x, f z \u2260 f x :=\n(has_deriv_at_iff_has_fderiv_at.1 h).eventually_ne\n  \u27e8\u2225f'\u2225\u207b\u00b9, \u03bb z, by field_simp [norm_smul, mt norm_eq_zero.1 hf']\u27e9\n\ntheorem not_differentiable_within_at_of_local_left_inverse_has_deriv_within_at_zero\n  {f g : \ud835\udd5c \u2192 \ud835\udd5c} {a : \ud835\udd5c} {s t : set \ud835\udd5c} (ha : a \u2208 s) (hsu : unique_diff_within_at \ud835\udd5c s a)\n  (hf : has_deriv_within_at f 0 t (g a)) (hst : maps_to g s t) (hfg : f \u2218 g =\u1da0[\ud835\udcdd[s] a] id) :\n  \u00acdifferentiable_within_at \ud835\udd5c g s a :=\nbegin\n  intro hg,\n  have := (hf.comp a hg.has_deriv_within_at hst).congr_of_eventually_eq_of_mem hfg.symm ha,\n  simpa using hsu.eq_deriv _ this (has_deriv_within_at_id _ _)\nend\n\ntheorem not_differentiable_at_of_local_left_inverse_has_deriv_at_zero\n  {f g : \ud835\udd5c \u2192 \ud835\udd5c} {a : \ud835\udd5c} (hf : has_deriv_at f 0 (g a)) (hfg : f \u2218 g =\u1da0[\ud835\udcdd a] id) :\n  \u00acdifferentiable_at \ud835\udd5c g a :=\nbegin\n  intro hg,\n  have := (hf.comp a hg.has_deriv_at).congr_of_eventually_eq hfg.symm,\n  simpa using this.unique (has_deriv_at_id a)\nend\n\nend\n\nnamespace polynomial\n/-! ### Derivative of a polynomial -/\n\nvariables {x : \ud835\udd5c} {s : set \ud835\udd5c}\nvariable (p : polynomial \ud835\udd5c)\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected lemma has_strict_deriv_at (x : \ud835\udd5c) :\n  has_strict_deriv_at (\u03bbx, p.eval x) (p.derivative.eval x) x :=\nbegin\n  apply p.induction_on,\n  { simp [has_strict_deriv_at_const] },\n  { assume p q hp hq,\n    convert hp.add hq;\n    simp },\n  { assume n a h,\n    convert h.mul (has_strict_deriv_at_id x),\n    { ext y, simp [pow_add, mul_assoc] },\n    { simp [pow_add], ring } }\nend\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected lemma has_deriv_at (x : \ud835\udd5c) : has_deriv_at (\u03bbx, p.eval x) (p.derivative.eval x) x :=\n(p.has_strict_deriv_at x).has_deriv_at\n\nprotected theorem has_deriv_within_at (x : \ud835\udd5c) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, p.eval x) (p.derivative.eval x) s x :=\n(p.has_deriv_at x).has_deriv_within_at\n\nprotected lemma differentiable_at : differentiable_at \ud835\udd5c (\u03bbx, p.eval x) x :=\n(p.has_deriv_at x).differentiable_at\n\nprotected lemma differentiable_within_at : differentiable_within_at \ud835\udd5c (\u03bbx, p.eval x) s x :=\np.differentiable_at.differentiable_within_at\n\nprotected lemma differentiable : differentiable \ud835\udd5c (\u03bbx, p.eval x) :=\n\u03bbx, p.differentiable_at\n\nprotected lemma differentiable_on : differentiable_on \ud835\udd5c (\u03bbx, p.eval x) s :=\np.differentiable.differentiable_on\n\n@[simp] protected lemma deriv : deriv (\u03bbx, p.eval x) x = p.derivative.eval x :=\n(p.has_deriv_at x).deriv\n\nprotected lemma deriv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, p.eval x) s x = p.derivative.eval x :=\nbegin\n  rw differentiable_at.deriv_within p.differentiable_at hxs,\n  exact p.deriv\nend\n\nprotected lemma has_fderiv_at (x : \ud835\udd5c) :\n  has_fderiv_at (\u03bbx, p.eval x) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x)) x :=\np.has_deriv_at x\n\nprotected lemma has_fderiv_within_at (x : \ud835\udd5c) :\n  has_fderiv_within_at (\u03bbx, p.eval x) (smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x)) s x :=\n(p.has_fderiv_at x).has_fderiv_within_at\n\n@[simp] protected lemma fderiv :\n  fderiv \ud835\udd5c (\u03bbx, p.eval x) x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x) :=\n(p.has_fderiv_at x).fderiv\n\nprotected lemma fderiv_within (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  fderiv_within \ud835\udd5c (\u03bbx, p.eval x) s x = smul_right (1 : \ud835\udd5c \u2192L[\ud835\udd5c] \ud835\udd5c) (p.derivative.eval x) :=\n(p.has_fderiv_within_at x).fderiv_within hxs\n\nend polynomial\n\nsection pow\n/-! ### Derivative of `x \u21a6 x^n` for `n : \u2115` -/\nvariables {x : \ud835\udd5c} {s : set \ud835\udd5c} {c : \ud835\udd5c \u2192 \ud835\udd5c} {c' : \ud835\udd5c}\nvariable {n : \u2115 }\n\nlemma has_strict_deriv_at_pow (n : \u2115) (x : \ud835\udd5c) :\n  has_strict_deriv_at (\u03bbx, x^n) ((n : \ud835\udd5c) * x^(n-1)) x :=\nbegin\n  convert (polynomial.C (1 : \ud835\udd5c) * (polynomial.X)^n).has_strict_deriv_at x,\n  { simp },\n  { rw [polynomial.derivative_C_mul_X_pow], simp }\nend\n\nlemma has_deriv_at_pow (n : \u2115) (x : \ud835\udd5c) : has_deriv_at (\u03bbx, x^n) ((n : \ud835\udd5c) * x^(n-1)) x :=\n(has_strict_deriv_at_pow n x).has_deriv_at\n\ntheorem has_deriv_within_at_pow (n : \u2115) (x : \ud835\udd5c) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, x^n) ((n : \ud835\udd5c) * x^(n-1)) s x :=\n(has_deriv_at_pow n x).has_deriv_within_at\n\nlemma differentiable_at_pow : differentiable_at \ud835\udd5c (\u03bbx, x^n) x :=\n(has_deriv_at_pow n x).differentiable_at\n\nlemma differentiable_within_at_pow : differentiable_within_at \ud835\udd5c (\u03bbx, x^n) s x :=\ndifferentiable_at_pow.differentiable_within_at\n\nlemma differentiable_pow : differentiable \ud835\udd5c (\u03bbx:\ud835\udd5c, x^n) :=\n\u03bbx, differentiable_at_pow\n\nlemma differentiable_on_pow : differentiable_on \ud835\udd5c (\u03bbx, x^n) s :=\ndifferentiable_pow.differentiable_on\n\nlemma deriv_pow : deriv (\u03bbx, x^n) x = (n : \ud835\udd5c) * x^(n-1) :=\n(has_deriv_at_pow n x).deriv\n\n@[simp] lemma deriv_pow' : deriv (\u03bbx, x^n) = \u03bb x, (n : \ud835\udd5c) * x^(n-1) :=\nfunext $ \u03bb x, deriv_pow\n\nlemma deriv_within_pow (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, x^n) s x = (n : \ud835\udd5c) * x^(n-1) :=\n(has_deriv_within_at_pow n x s).deriv_within hxs\n\nlemma iter_deriv_pow' {k : \u2115} :\n  deriv^[k] (\u03bbx:\ud835\udd5c, x^n) = \u03bb x, (\u220f i in finset.range k, (n - i) : \u2115) * x^(n-k) :=\nbegin\n  induction k with k ihk,\n  { simp only [one_mul, finset.prod_range_zero, function.iterate_zero_apply, nat.sub_zero,\n      nat.cast_one] },\n  { simp only [function.iterate_succ_apply', ihk, finset.prod_range_succ],\n    ext x,\n    rw [((has_deriv_at_pow (n - k) x).const_mul _).deriv, nat.cast_mul, mul_assoc, nat.sub_sub] }\nend\n\nlemma iter_deriv_pow {k : \u2115} :\n  deriv^[k] (\u03bbx:\ud835\udd5c, x^n) x = (\u220f i in finset.range k, (n - i) : \u2115) * x^(n-k) :=\ncongr_fun iter_deriv_pow' x\n\nlemma has_deriv_within_at.pow (hc : has_deriv_within_at c c' s x) :\n  has_deriv_within_at (\u03bb y, (c y)^n) ((n : \ud835\udd5c) * (c x)^(n-1) * c') s x :=\n(has_deriv_at_pow n (c x)).comp_has_deriv_within_at x hc\n\nlemma has_deriv_at.pow (hc : has_deriv_at c c' x) :\n  has_deriv_at (\u03bb y, (c y)^n) ((n : \ud835\udd5c) * (c x)^(n-1) * c') x :=\nby { rw \u2190 has_deriv_within_at_univ at *, exact hc.pow }\n\nlemma differentiable_within_at.pow (hc : differentiable_within_at \ud835\udd5c c s x) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, (c x)^n) s x :=\nhc.has_deriv_within_at.pow.differentiable_within_at\n\n@[simp] lemma differentiable_at.pow (hc : differentiable_at \ud835\udd5c c x) :\n  differentiable_at \ud835\udd5c (\u03bbx, (c x)^n) x :=\nhc.has_deriv_at.pow.differentiable_at\n\nlemma differentiable_on.pow (hc : differentiable_on \ud835\udd5c c s) :\n  differentiable_on \ud835\udd5c (\u03bbx, (c x)^n) s :=\n\u03bbx h, (hc x h).pow\n\n@[simp] lemma differentiable.pow (hc : differentiable \ud835\udd5c c) :\n  differentiable \ud835\udd5c (\u03bbx, (c x)^n) :=\n\u03bbx, (hc x).pow\n\nlemma deriv_within_pow' (hc : differentiable_within_at \ud835\udd5c c s x)\n  (hxs : unique_diff_within_at \ud835\udd5c s x) :\n  deriv_within (\u03bbx, (c x)^n) s x = (n : \ud835\udd5c) * (c x)^(n-1) * (deriv_within c s x) :=\nhc.has_deriv_within_at.pow.deriv_within hxs\n\n@[simp] lemma deriv_pow'' (hc : differentiable_at \ud835\udd5c c x) :\n  deriv (\u03bbx, (c x)^n) x = (n : \ud835\udd5c) * (c x)^(n-1) * (deriv c x) :=\nhc.has_deriv_at.pow.deriv\n\nend pow\n\nsection fpow\n/-! ### Derivative of `x \u21a6 x^m` for `m : \u2124` -/\nvariables {x : \ud835\udd5c} {s : set \ud835\udd5c}\nvariable {m : \u2124}\n\nlemma has_strict_deriv_at_fpow (m : \u2124) (hx : x \u2260 0) :\n  has_strict_deriv_at (\u03bbx, x^m) ((m : \ud835\udd5c) * x^(m-1)) x :=\nbegin\n  have : \u2200 m : \u2124, 0 < m \u2192 has_strict_deriv_at (\u03bbx, x^m) ((m:\ud835\udd5c) * x^(m-1)) x,\n  { assume m hm,\n    lift m to \u2115 using (le_of_lt hm),\n    simp only [gpow_coe_nat, int.cast_coe_nat],\n    convert has_strict_deriv_at_pow _ _ using 2,\n    rw [\u2190 int.coe_nat_one, \u2190 int.coe_nat_sub, gpow_coe_nat],\n    norm_cast at hm,\n    exact nat.succ_le_of_lt hm },\n  rcases lt_trichotomy m 0 with hm|hm|hm,\n  { have := (has_strict_deriv_at_inv _).scomp _ (this (-m) (neg_pos.2 hm));\n      [skip, exact fpow_ne_zero_of_ne_zero hx _],\n    simp only [(\u2218), fpow_neg, one_div, inv_inv', smul_eq_mul] at this,\n    convert this using 1,\n    rw [sq, mul_inv', inv_inv', int.cast_neg, \u2190 neg_mul_eq_neg_mul, neg_mul_neg,\n      \u2190 fpow_add hx, mul_assoc, \u2190 fpow_add hx], congr, abel },\n  { simp only [hm, gpow_zero, int.cast_zero, zero_mul, has_strict_deriv_at_const] },\n  { exact this m hm }\nend\n\nlemma has_deriv_at_fpow (m : \u2124) (hx : x \u2260 0) :\n  has_deriv_at (\u03bbx, x^m) ((m : \ud835\udd5c) * x^(m-1)) x :=\n(has_strict_deriv_at_fpow m hx).has_deriv_at\n\ntheorem has_deriv_within_at_fpow (m : \u2124) (hx : x \u2260 0) (s : set \ud835\udd5c) :\n  has_deriv_within_at (\u03bbx, x^m) ((m : \ud835\udd5c) * x^(m-1)) s x :=\n(has_deriv_at_fpow m hx).has_deriv_within_at\n\nlemma differentiable_at_fpow (hx : x \u2260 0)  : differentiable_at \ud835\udd5c (\u03bbx, x^m) x :=\n(has_deriv_at_fpow m hx).differentiable_at\n\nlemma differentiable_within_at_fpow (hx : x \u2260 0) :\n  differentiable_within_at \ud835\udd5c (\u03bbx, x^m) s x :=\n(differentiable_at_fpow hx).differentiable_within_at\n\nlemma differentiable_on_fpow (hs : (0:\ud835\udd5c) \u2209 s) : differentiable_on \ud835\udd5c (\u03bbx, x^m) s :=\n\u03bb x hxs, differentiable_within_at_fpow (\u03bb hx, hs $ hx \u25b8 hxs)\n\n-- TODO : this is true at `x=0` as well\nlemma deriv_fpow (hx : x \u2260 0) : deriv (\u03bbx, x^m) x = (m : \ud835\udd5c) * x^(m-1) :=\n(has_deriv_at_fpow m hx).deriv\n\nlemma deriv_within_fpow (hxs : unique_diff_within_at \ud835\udd5c s x) (hx : x \u2260 0) :\n  deriv_within (\u03bbx, x^m) s x = (m : \ud835\udd5c) * x^(m-1) :=\n(has_deriv_within_at_fpow m hx s).deriv_within hxs\n\nlemma iter_deriv_fpow {k : \u2115} (hx : x \u2260 0) :\n  deriv^[k] (\u03bbx:\ud835\udd5c, x^m) x = (\u220f i in finset.range k, (m - i) : \u2124) * x^(m-k) :=\nbegin\n  induction k with k ihk generalizing x hx,\n  { simp only [one_mul, finset.prod_range_zero, function.iterate_zero_apply, int.coe_nat_zero,\n      sub_zero, int.cast_one] },\n  { rw [function.iterate_succ', finset.prod_range_succ, int.cast_mul, mul_assoc,\n      int.coe_nat_succ, \u2190 sub_sub, \u2190 ((has_deriv_at_fpow _ hx).const_mul _).deriv],\n    exact filter.eventually_eq.deriv_eq (eventually.mono (mem_nhds_sets is_open_ne hx) @ihk) }\nend\n\nend fpow\n\n/-! ### Upper estimates on liminf and limsup -/\n\nsection real\n\nvariables {f : \u211d \u2192 \u211d} {f' : \u211d} {s : set \u211d} {x : \u211d} {r : \u211d}\n\nlemma has_deriv_within_at.limsup_slope_le (hf : has_deriv_within_at f f' s x) (hr : f' < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s \\ {x}] x, (z - x)\u207b\u00b9 * (f z - f x) < r :=\nhas_deriv_within_at_iff_tendsto_slope.1 hf (mem_nhds_sets is_open_Iio hr)\n\nlemma has_deriv_within_at.limsup_slope_le' (hf : has_deriv_within_at f f' s x)\n  (hs : x \u2209 s) (hr : f' < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s] x, (z - x)\u207b\u00b9 * (f z - f x) < r :=\n(has_deriv_within_at_iff_tendsto_slope' hs).1 hf (mem_nhds_sets is_open_Iio hr)\n\nlemma has_deriv_within_at.liminf_right_slope_le\n  (hf : has_deriv_within_at f f' (Ici x) x) (hr : f' < r) :\n  \u2203\u1da0 z in \ud835\udcdd[Ioi x] x, (z - x)\u207b\u00b9 * (f z - f x) < r :=\n(hf.Ioi_of_Ici.limsup_slope_le' (lt_irrefl x) hr).frequently\n\nend real\n\nsection real_space\n\nopen metric\n\nvariables {E : Type u} [normed_group E] [normed_space \u211d E] {f : \u211d \u2192 E} {f' : E} {s : set \u211d}\n  {x r : \u211d}\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > \u2225f'\u2225` the ratio\n`\u2225f z - f x\u2225 / \u2225z - x\u2225` is less than `r` in some neighborhood of `x` within `s`.\nIn other words, the limit superior of this ratio as `z` tends to `x` along `s`\nis less than or equal to `\u2225f'\u2225`. -/\nlemma has_deriv_within_at.limsup_norm_slope_le\n  (hf : has_deriv_within_at f f' s x) (hr : \u2225f'\u2225 < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s] x, \u2225z - x\u2225\u207b\u00b9 * \u2225f z - f x\u2225 < r :=\nbegin\n  have hr\u2080 : 0 < r, from lt_of_le_of_lt (norm_nonneg f') hr,\n  have A : \u2200\u1da0 z in \ud835\udcdd[s \\ {x}] x, \u2225(z - x)\u207b\u00b9 \u2022 (f z - f x)\u2225 \u2208 Iio r,\n    from (has_deriv_within_at_iff_tendsto_slope.1 hf).norm (mem_nhds_sets is_open_Iio hr),\n  have B : \u2200\u1da0 z in \ud835\udcdd[{x}] x, \u2225(z - x)\u207b\u00b9 \u2022 (f z - f x)\u2225 \u2208 Iio r,\n    from mem_sets_of_superset self_mem_nhds_within\n      (singleton_subset_iff.2 $ by simp [hr\u2080]),\n  have C := mem_sup_sets.2 \u27e8A, B\u27e9,\n  rw [\u2190 nhds_within_union, diff_union_self, nhds_within_union, mem_sup_sets] at C,\n  filter_upwards [C.1],\n  simp only [norm_smul, mem_Iio, normed_field.norm_inv],\n  exact \u03bb _, id\nend\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > \u2225f'\u2225` the ratio\n`(\u2225f z\u2225 - \u2225f x\u2225) / \u2225z - x\u2225` is less than `r` in some neighborhood of `x` within `s`.\nIn other words, the limit superior of this ratio as `z` tends to `x` along `s`\nis less than or equal to `\u2225f'\u2225`.\n\nThis lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`\nwhere `\u2225f z\u2225 - \u2225f x\u2225` is replaced by `\u2225f z - f x\u2225`. -/\nlemma has_deriv_within_at.limsup_slope_norm_le\n  (hf : has_deriv_within_at f f' s x) (hr : \u2225f'\u2225 < r) :\n  \u2200\u1da0 z in \ud835\udcdd[s] x, \u2225z - x\u2225\u207b\u00b9 * (\u2225f z\u2225 - \u2225f x\u2225) < r :=\nbegin\n  apply (hf.limsup_norm_slope_le hr).mono,\n  assume z hz,\n  refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz,\n  exact inv_nonneg.2 (norm_nonneg _)\nend\n\n/-- If `f` has derivative `f'` within `(x, +\u221e)` at `x`, then for any `r > \u2225f'\u2225` the ratio\n`\u2225f z - f x\u2225 / \u2225z - x\u2225` is frequently less than `r` as `z \u2192 x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `\u2225f'\u2225`. See also `has_deriv_within_at.limsup_norm_slope_le`\nfor a stronger version using limit superior and any set `s`. -/\nlemma has_deriv_within_at.liminf_right_norm_slope_le\n  (hf : has_deriv_within_at f f' (Ici x) x) (hr : \u2225f'\u2225 < r) :\n  \u2203\u1da0 z in \ud835\udcdd[Ioi x] x, \u2225z - x\u2225\u207b\u00b9 * \u2225f z - f x\u2225 < r :=\n(hf.Ioi_of_Ici.limsup_norm_slope_le hr).frequently\n\n/-- If `f` has derivative `f'` within `(x, +\u221e)` at `x`, then for any `r > \u2225f'\u2225` the ratio\n`(\u2225f z\u2225 - \u2225f x\u2225) / (z - x)` is frequently less than `r` as `z \u2192 x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `\u2225f'\u2225`.\n\nSee also\n\n* `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using\n  limit superior and any set `s`;\n* `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using\n  `\u2225f z - f x\u2225` instead of `\u2225f z\u2225 - \u2225f x\u2225`. -/\nlemma has_deriv_within_at.liminf_right_slope_norm_le\n  (hf : has_deriv_within_at f f' (Ici x) x) (hr : \u2225f'\u2225 < r) :\n  \u2203\u1da0 z in \ud835\udcdd[Ioi x] x, (z - x)\u207b\u00b9 * (\u2225f z\u2225 - \u2225f x\u2225) < r :=\nbegin\n  have := (hf.Ioi_of_Ici.limsup_slope_norm_le hr).frequently,\n  refine this.mp (eventually.mono self_mem_nhds_within _),\n  assume z hxz hz,\n  rwa [real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz\nend\n\nend real_space\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/calculus/deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7025907653885188}}
{"text": "/-\nCopyright \u00a9 2020 Nicol\u00f2 Cavalleri. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Nicol\u00f2 Cavalleri\n-/\nimport geometry.manifold.algebra.lie_group\n\n/-!\n# Smooth structures\n\nIn this file we define smooth structures that build on Lie groups. We prefer using the term smooth\ninstead of Lie mainly because Lie ring has currently another use in mathematics.\n-/\n\nopen_locale manifold\n\nsection smooth_ring\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{H : Type*} [topological_space H]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n\nset_option default_priority 100 -- see Note [default priority]\n\n/-- A smooth (semi)ring is a (semi)ring `R` where addition and multiplication are smooth.\nIf `R` is a ring, then negation is automatically smooth, as it is multiplication with `-1`. -/\n-- See note [Design choices about smooth algebraic structures]\nclass smooth_ring (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [semiring R] [topological_space R] [charted_space H R]\n  extends has_smooth_add I R : Prop :=\n(smooth_mul : smooth (I.prod I) I (\u03bb p : R\u00d7R, p.1 * p.2))\n\ninstance smooth_ring.to_has_smooth_mul (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [semiring R] [topological_space R] [charted_space H R] [h : smooth_ring I R] :\n  has_smooth_mul I R := { ..h }\n\ninstance smooth_ring.to_lie_add_group (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [ring R] [topological_space R] [charted_space H R] [smooth_ring I R] :\n  lie_add_group I R :=\n{ compatible := \u03bb e e', has_groupoid.compatible (cont_diff_groupoid \u22a4 I),\n  smooth_add := smooth_add I,\n  smooth_neg := by simpa only [neg_one_mul] using @smooth_mul_left \ud835\udd5c _ H _ E _ _ I R _ _ _ _ (-1) }\n\nend smooth_ring\n\ninstance field_smooth_ring {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c] :\n  smooth_ring \ud835\udcd8(\ud835\udd5c) \ud835\udd5c :=\n{ smooth_mul :=\n  begin\n    rw smooth_iff,\n    refine \u27e8continuous_mul, \u03bb x y, _\u27e9,\n    simp only [prod.mk.eta] with mfld_simps,\n    rw cont_diff_on_univ,\n    exact cont_diff_mul,\n  end,\n  ..normed_space_lie_add_group }\n\nvariables {\ud835\udd5c R E H : Type*} [topological_space R] [topological_space H]\n  [nondiscrete_normed_field \ud835\udd5c] [normed_group E] [normed_space \ud835\udd5c E]\n  [charted_space H R] (I : model_with_corners \ud835\udd5c E H)\n\n/-- A smooth (semi)ring is a topological (semi)ring. This is not an instance for technical reasons,\nsee note [Design choices about smooth algebraic structures]. -/\nlemma topological_semiring_of_smooth [semiring R] [smooth_ring I R] :\n  topological_semiring R :=\n{ .. has_continuous_mul_of_smooth I, .. has_continuous_add_of_smooth I }\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/geometry/manifold/algebra/structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7025907633317289}}
{"text": "import algebra.module.basic\nimport linear_algebra.affine_space.affine_equiv\nimport algebra.direct_sum.basic\nimport algebra.direct_sum.module\n-- import algebra.direct_sum\n-- import linear_algebra.direct_sum_module\nimport tactic.linarith\n\n/-\nThe type, fin n, of all natural numbers < n\n-/\n\n-- equivalent expressions\n#check (\u27e8 0, by linarith \u27e9 : fin 2) -- checks\n#check (\u27e8 1, by linarith \u27e9 : fin 2) -- checks\n#check (\u27e8 2, by linarith \u27e9 : fin 2) -- nocheck\n#reduce (\u27e8 0, by linarith \u27e9 : fin 2) -- checks\n#reduce (\u27e8 1, by linarith \u27e9 : fin 2) -- checks\n\n-- notation\n#check (0 : fin 2)\n-- provably equal to expanded term\nexample : (0 : fin 2) = (\u27e8 0, by linarith \u27e9) := rfl\n\n#check (0 : fin 2) -- 0\n#check (1 : fin 2) -- 1\n#check (2 : fin 2) -- not a type error\n\n#eval (0 : fin 2) -- 0\n#eval (1 : fin 2) -- 1\n#eval (2 : fin 2) -- 0, modulus conversion\n\n/-\nThe type, fin n \u2192 Type \n-/\n\ndef indexed_family : (fin 2) \u2192 Type \n| \u27e8 0, _ \u27e9  := \u211a\n| \u27e8 1, _ \u27e9  := \u2115 \n| \u27e8 _, p \u27e9 := empty -- can't happen\n\n#reduce indexed_family 0  -- \u211a  \n#reduce indexed_family 1  -- \u2115 \n#reduce indexed_family 2  -- \u211a, not empty (coercion again)\n\n\n\n\n/-\nThe type, finset \u03b1\n\nIt's defined as a structure with 2 fields:\n  - val is a multiset \u03b1 of elements;\n  - nodup is a proof that val has no duplicates.\n-/\n\n", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/lin2Kcoord/direct_sum_explore..lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7025907586732059}}
{"text": "import combinatorics.simple_graph.clique\nimport combinatorics.simple_graph.degree_sum\nimport data.finset.basic\nimport data.nat.basic\nimport tactic.core\nimport algebra.big_operators\n\n-- local imports\nimport fedges\nimport nbhd_res\nimport clique_free_sets\nimport misc_finset\nimport multipartite\nimport turanpartition\nimport induced\n\nopen finset nat turanpartition\n\nopen_locale big_operators \n\nnamespace simple_graph\n\nvariables {t n : \u2115} \nvariables {\u03b1 : Type*} (G H : simple_graph \u03b1)[fintype \u03b1][nonempty \u03b1][decidable_eq \u03b1][decidable_rel G.adj][decidable_rel H.adj]\ninclude G\n\n\n\n---for any (t+2)-clique free set there is a partition into B, a (t+1)-clique free set and A\\B \n-- such that e(A)+e(A\\B) \u2264 e(B) + |B|(|A|-|B|) \nlemma furedi_help : \u2200A:finset \u03b1, G.clique_free_set A (t+2) \u2192 \u2203B:finset \u03b1, B \u2286 A \u2227 G.clique_free_set B (t+1) \u2227 \n\u2211v in A, G.deg_res v A + \u2211 v in (A\\B), G.deg_res v (A\\B) \u2264 \u2211 v in B, G.deg_res v B + 2*B.card * (A\\B).card:=\nbegin\n  cases nat.eq_zero_or_pos t with ht,{\n  intros A hA,rw ht at *, rw zero_add at *,\n----- t = 0 need to check that \u2205 is not a 1-clique. \n  refine \u27e8\u2205,\u27e8empty_subset A,(G.clique_free_empty (by norm_num: 0 <1)),_\u27e9\u27e9,\n  rw [sdiff_empty, card_empty, mul_zero,zero_mul, sum_empty, zero_add,G.two_clique_free_sum hA]},{\n----- 0 < t case\n  intros A hA, by_cases hnem: A.nonempty,{\n    obtain \u27e8x,hxA,hxM\u27e9:=G.exists_max_res_deg_vertex hnem, -- get a vert x of max res deg in A\n    set hBA:= (G.sub_res_nbhd_A x A), \n    set B:=(G.nbhd_res x A) with hB,-- Let B be the res nbhd of the vertex x of max deg_A \n    refine \u27e8B, \u27e8hBA,(G.t_clique_free hA hxA),_\u27e9\u27e9,\n    rw [G.deg_res_add_sum hBA, G.sum_sdf hBA B, add_assoc],\n    rw [G.sum_sdf hBA (A\\B),G.bip_count hBA,\u2190 G.deg_res_add_sum hBA ],\n    rw \u2190 hB, rw \u2190 add_assoc, ring_nf,\n    apply add_le_add_left _ (\u2211 v in B, G.deg_res v B ), \n    rw add_comm, rw add_assoc, nth_rewrite 1 add_comm,\n    rw \u2190 G.deg_res_add_sum hBA, ring_nf,rw mul_assoc,\n    refine mul_le_mul' (by norm_num) _,\n    apply le_trans (G.max_deg_res_sum_le (sdiff_subset A B)) _,\n    rw [hxM,deg_res],},\n    {rw not_nonempty_iff_eq_empty at hnem, \n    refine \u27e8\u2205,\u27e8empty_subset A,(G.clique_free_empty (by norm_num: 0 <t+1)),_\u27e9\u27e9,\n    rw [sdiff_empty, card_empty, mul_zero,zero_mul, sum_empty, zero_add,hnem,sum_empty],}},\nend\n\n\n\n-- Putting together the deg counts of G induced on a larger partition (M with C inserted).\n-- Counting degrees sums over the parts of the larger partition is what you expect\n-- ie e(G[M_0])+ .. +e(G[M_t])+e(G[C]) = e(G[M'_0])+...+e(G[M'_{t+1}])\nlemma internal_count {M: multi_part \u03b1} {C : finset \u03b1} (h: disjoint M.A C):\n \u2211 i in range(M.t+1),\u2211 v in (M.P i), G.deg_res v (M.P i) + \u2211 v in C, G.deg_res v C  =\n\u2211 i in range((insert M h).t+1), \u2211 v in ((insert M h).P i), G.deg_res v ((insert M h).P i):=\nbegin\n  simp [insert_t, insert_P,ite_not],\n  have  ru:range((M.t+1)+1)=range(M.t+1) \u222a {M.t+1},{\n    rw range_succ, rw union_comm, rw insert_eq _,},\n  have nm:(M.t+1)\u2209(range(M.t+1)):=not_mem_range_self,\n  have rd: disjoint (range(M.t+1)) {M.t+1}:= disjoint_singleton_right.mpr nm,\n  rw [ru,sum_union rd],simp only [sum_singleton, eq_self_iff_true, if_true],\n  apply (add_left_inj _).mpr, apply sum_congr rfl, intros k hk,\n  have nm:(M.t+1)\u2209(range(M.t+1)):=not_mem_range_self,\n  have kne: k\u2260M.t+1,{intro h',rw h' at hk, exact nm hk},\n  apply sum_congr, split_ifs,{contradiction},{refl},{\n  intros v hv,split_ifs,{contradiction},{refl}},\nend\n\n-- Furedi's stability theorem: (t+2)-clique-free set A implies there is a (t+1)-partition of A\n-- such that edges in A + edges in parts (counted a second time) \u2264 edges in the complete\n-- (t+1)-partite graph on same partition\n-- implies Turan once we have know how to maximize edges of a complete multi-partite graph\ntheorem furedi : \u2200A:finset \u03b1, G.clique_free_set A (t+2) \u2192 \u2203M:multi_part \u03b1, M.A=A \u2227 M.t =t \u2227 \n\u2211v in A, G.deg_res v A + \u2211 i in range(M.t+1),\u2211 v in (M.P i), G.deg_res v (M.P i) \u2264 \u2211 v in A, (mp M).deg_res v A:=\nbegin\n  induction t with t ht, {rw zero_add,\n  intros A ha, use (default_M A 0), refine \u27e8rfl,rfl,_\u27e9, rw G.two_clique_free_sum ha,\n  rw zero_add, unfold default_M, dsimp,simp, apply sum_le_sum,\n  intros x hx, rw G.two_clique_free ha x hx,exact zero_le _ },\n  --- t.succ case\n  {intros A ha, obtain\u27e8B,hBa,hBc,hBs\u27e9:=G.furedi_help A ha,  \n  have hAsd:=union_sdiff_of_subset hBa,\n  obtain \u27e8M,Ma,Mt,Ms\u27e9:=ht B hBc,\n  have dAB:disjoint M.A (A\\B), {rw Ma, exact disjoint_sdiff,},\n  set H: simple_graph \u03b1:= (mp (insert M dAB)),\n  use (insert M dAB), refine \u27e8_,_,_\u27e9,{  \n  rw [insert_AB, Ma], exact union_sdiff_of_subset hBa}, {rwa [insert_t, Mt]},{\n  --- so we now have the new partition and \"just\" need to check the degree sum bound..\n  have mpc:=mp_count M dAB, rw [insert_AB, Ma , hAsd] at mpc,\n  -- need to sort out the sum over parts in the larger graph\n  rw \u2190  mpc, rw \u2190 G.internal_count dAB, linarith},},\nend\n\nend simple_graph\n", "meta": {"author": "jt496", "repo": "extremal_graph", "sha": "1bfb63ed1f6ca633d1ee4e1846f429cfe32c6a83", "save_path": "github-repos/lean/jt496-extremal_graph", "path": "github-repos/lean/jt496-extremal_graph/extremal_graph-1bfb63ed1f6ca633d1ee4e1846f429cfe32c6a83/src/counting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7025886539368714}}
{"text": "import game.sets.L01defs\n\n--NOTE: the recursive import from previous world breaks run_cmd add_interactive below??\n--I think the problem comes from sup_inf.rat_complete\n--So I will import sup_inf in the next level\n\nimport data.real.basic\nimport tactic.linarith\n\nnamespace xena -- hide\nnotation `|` x `|` := abs x -- hide\n\nlemma zero_of_abs_lt_all (x : \u211d) (h : \u2200 \u03b5 > 0, |x| < \u03b5) : x = 0 :=\neq_zero_of_abs_eq_zero $ eq_of_le_of_forall_le_of_dense (abs_nonneg x) $ \u03bb \u03b5 \u03b5_pos, le_of_lt (h \u03b5 \u03b5_pos)\n\n-- begin hide\n-- The next few things should be hidden\n@[user_attribute]\nmeta def ineq_rules : user_attribute :=\n{ name := `ineq_rules,\n  descr := \"lemmas usable to prove inequalities\" }\n\nattribute [ineq_rules] add_lt_add le_max_left le_max_right\n\nmeta def inequality := `[linarith <|> apply_rules ineq_rules]\nrun_cmd add_interactive [`inequality]\n-- end of scary things\n-- end hide\n\n\n-- World name : Sequences and limits\n\n/-\n# Chapter 3 : Sequences and limits\n\n# Level 1 : Introduction to sequences.\n\nLean's natural numbers start at zero, so it is convenient to let our sequences start from the zeroth term.\nIn other words, a sequence of reals will be $a_0, a_1, a_2, \\ldots$. \n-/\n\n/-\nLet's just step back for a minute and think about what a sequence really *is*. \nIf $n$ is a natural number then $a_n$ is a real number, \nso $n\\mapsto a_n$ is actually a function from natural numbers to real numbers. \nIf we just call this function $a$ then the $n$th term in the sequence\nwill be called `a(n)` or `a n` in Lean, rather than $a_n$, but this is OK.\n\nThe key definition we want is the concept of a limit of a sequence.\n-/\n\ndefinition is_limit (a : \u2115 \u2192 \u211d) (\u03b1 : \u211d) := \n  \u2200 \u03b5 : \u211d, 0 < \u03b5 \u2192 \u2203 N : \u2115, \u2200 n : \u2115, N \u2264 n \u2192 |a n - \u03b1| < \u03b5\n\n/-\nLet's now prove the basic fact that a sequence has at most one limit. \n-/\n\n/- Lemma\nIf $a_n \\to \\ell$ and $a_n \\to m$ then $\\ell = m$. \n-/\nlemma limit.unique (a : \u2115 \u2192 \u211d) (l m : \u211d) (hl : is_limit a l) (hm : is_limit a m) : l = m :=\nbegin\n  wlog h : l \u2264 m,\n  rw le_iff_lt_or_eq at h,\n  cases h,\n    exfalso,\n    generalize h : (m - l) / 2 = \u03b5,\n    have h\u03b5 : 0 < \u03b5,\n      {inequality},\n    cases (hl \u03b5 h\u03b5) with L hL,\n    cases (hm \u03b5 h\u03b5) with M hM,\n    have hL' := hL (max L M) (le_max_left _ _),\n    have hM' := hM (max L M) (le_max_right _ _),\n    rw abs_lt at hL',\n    rw abs_lt at hM',\n    cases hL', cases hM',\n    linarith,\n  assumption,\n\nend\n\nend xena -- hide\n", "meta": {"author": "ImperialCollegeLondon", "repo": "real-number-game", "sha": "f9dcb7d9255a79b57e62038228a23346c2dc301b", "save_path": "github-repos/lean/ImperialCollegeLondon-real-number-game", "path": "github-repos/lean/ImperialCollegeLondon-real-number-game/real-number-game-f9dcb7d9255a79b57e62038228a23346c2dc301b/src/game/limits/L01defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7025886499348263}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module algebra.free_monoid.count\n! leanprover-community/mathlib commit a2d2e18906e2b62627646b5d5be856e6a642062f\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.FreeMonoid.Basic\nimport Mathlib.Data.List.Count\n\n/-!\n# `List.count` as a bundled homomorphism\n\nIn this file we define `FreeMonoid.countp`, `FreeMonoid.count`, `FreeAddMonoid.countp`, and\n`FreeAddMonoid.count`. These are `List.countp` and `List.count` bundled as multiplicative and\nadditive homomorphisms from `FreeMonoid` and `FreeAddMonoid`.\n\nWe do not use `to_additive` because it can't map `Multiplicative \u2115` to `\u2115`.\n-/\n\nvariable {\u03b1 : Type _} (p : \u03b1 \u2192 Prop) [DecidablePred p]\n\nnamespace FreeAddMonoid\n\n/-- `List.countp` as a bundled additive monoid homomorphism. -/\ndef countp : FreeAddMonoid \u03b1 \u2192+ \u2115 where\n  toFun := List.countp p\n  map_zero' := List.countp_nil _\n  map_add' := List.countp_append _\n#align free_add_monoid.countp FreeAddMonoid.countp\n\ntheorem countp_of (x : \u03b1): countp p (of x) = if p x = true then 1 else 0 := by\n  simp [countp, List.countp, List.countp.go]\n#align free_add_monoid.countp_of FreeAddMonoid.countp_of\n\n\n\n/-- `List.count` as a bundled additive monoid homomorphism. -/\n-- Porting note: was (x = \u00b7)\ndef count [DecidableEq \u03b1] (x : \u03b1) : FreeAddMonoid \u03b1 \u2192+ \u2115 := countp (\u00b7 = x)\n#align free_add_monoid.count FreeAddMonoid.count\n\ntheorem count_of [DecidableEq \u03b1] (x y : \u03b1) : count x (of y) = (Pi.single x 1 : \u03b1 \u2192 \u2115) y := by\n  simp [Pi.single, Function.update, count, countp, List.countp, List.countp.go,\n    Bool.beq_eq_decide_eq]\n#align free_add_monoid.count_of FreeAddMonoid.count_of\n\ntheorem count_apply [DecidableEq \u03b1] (x : \u03b1) (l : FreeAddMonoid \u03b1) : count x l = List.count x l :=\n  rfl\n#align free_add_monoid.count_apply FreeAddMonoid.count_apply\n\nend FreeAddMonoid\n\nnamespace FreeMonoid\n\n/-- `list.countp` as a bundled multiplicative monoid homomorphism. -/\ndef countp : FreeMonoid \u03b1 \u2192* Multiplicative \u2115 :=\n    AddMonoidHom.toMultiplicative (FreeAddMonoid.countp p)\n#align free_monoid.countp FreeMonoid.countp\n\ntheorem countp_of' (x : \u03b1) :\n    countp p (of x) = if p x then Multiplicative.ofAdd 1 else Multiplicative.ofAdd 0 := by\n    erw [FreeAddMonoid.countp_of]\n    simp only [eq_iff_iff, iff_true, ofAdd_zero]; rfl\n#align free_monoid.countp_of' FreeMonoid.countp_of'\n\ntheorem countp_of (x : \u03b1) : countp p (of x) = if p x then Multiplicative.ofAdd 1 else 1 := by\n  rw [countp_of', ofAdd_zero]\n#align free_monoid.countp_of FreeMonoid.countp_of\n\n-- `rfl` is not transitive\ntheorem countp_apply (l : FreeAddMonoid \u03b1) : countp p l = Multiplicative.ofAdd (List.countp p l) :=\n  rfl\n#align free_monoid.countp_apply FreeMonoid.countp_apply\n\n/-- `List.count` as a bundled additive monoid homomorphism. -/\ndef count [DecidableEq \u03b1] (x : \u03b1) : FreeMonoid \u03b1 \u2192* Multiplicative \u2115 := countp (\u00b7 = x)\n#align free_monoid.count FreeMonoid.count\n\ntheorem count_apply [DecidableEq \u03b1] (x : \u03b1) (l : FreeAddMonoid \u03b1) :\n    count x l = Multiplicative.ofAdd (List.count x l) := rfl\n#align free_monoid.count_apply FreeMonoid.count_apply\n\ntheorem count_of [DecidableEq \u03b1] (x y : \u03b1) :\n    count x (of y) = @Pi.mulSingle \u03b1 (fun _ => Multiplicative \u2115) _ _ x (Multiplicative.ofAdd 1) y :=\n  by simp [count, countp_of, Pi.mulSingle_apply, eq_comm, Bool.beq_eq_decide_eq]\n#align free_monoid.count_of FreeMonoid.count_of\n\nend FreeMonoid\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/FreeMonoid/Count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7025886478481937}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes\n-/\nimport algebra.hom.aut\nimport group_theory.group_action.units\n\n/-!\n# Group actions applied to various types of group\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains lemmas about `smul` on `group_with_zero`, and `group`.\n-/\n\nopen function\n\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nsection mul_action\n\n/-- `monoid.to_mul_action` is faithful on cancellative monoids. -/\n@[to_additive /-\" `add_monoid.to_add_action` is faithful on additive cancellative monoids. \"-/]\ninstance right_cancel_monoid.to_has_faithful_smul [right_cancel_monoid \u03b1] :\n  has_faithful_smul \u03b1 \u03b1 :=\n\u27e8\u03bb x y h, mul_right_cancel (h 1)\u27e9\n\nsection group\nvariables [group \u03b1] [mul_action \u03b1 \u03b2]\n\n@[simp, to_additive] lemma inv_smul_smul (c : \u03b1) (x : \u03b2) : c\u207b\u00b9 \u2022 c \u2022 x = x :=\nby rw [smul_smul, mul_left_inv, one_smul]\n\n@[simp, to_additive] lemma smul_inv_smul (c : \u03b1) (x : \u03b2) : c \u2022 c\u207b\u00b9 \u2022 x = x :=\nby rw [smul_smul, mul_right_inv, one_smul]\n\n/-- Given an action of a group `\u03b1` on `\u03b2`, each `g : \u03b1` defines a permutation of `\u03b2`. -/\n@[to_additive, simps] def mul_action.to_perm (a : \u03b1) : equiv.perm \u03b2 :=\n\u27e8\u03bb x, a \u2022 x, \u03bb x, a\u207b\u00b9 \u2022 x, inv_smul_smul a, smul_inv_smul a\u27e9\n\n/-- Given an action of an additive group `\u03b1` on `\u03b2`, each `g : \u03b1` defines a permutation of `\u03b2`. -/\nadd_decl_doc add_action.to_perm\n\n/-- `mul_action.to_perm` is injective on faithful actions. -/\n@[to_additive \"`add_action.to_perm` is injective on faithful actions.\"]\nlemma mul_action.to_perm_injective [has_faithful_smul \u03b1 \u03b2] :\n  function.injective (mul_action.to_perm : \u03b1 \u2192 equiv.perm \u03b2) :=\n(show function.injective (equiv.to_fun \u2218 mul_action.to_perm), from smul_left_injective').of_comp\n\nvariables (\u03b1) (\u03b2)\n\n/-- Given an action of a group `\u03b1` on a set `\u03b2`, each `g : \u03b1` defines a permutation of `\u03b2`. -/\n@[simps]\ndef mul_action.to_perm_hom : \u03b1 \u2192* equiv.perm \u03b2 :=\n{ to_fun := mul_action.to_perm,\n  map_one' := equiv.ext $ one_smul \u03b1,\n  map_mul' := \u03bb u\u2081 u\u2082, equiv.ext $ mul_smul (u\u2081:\u03b1) u\u2082 }\n\n/-- Given an action of a additive group `\u03b1` on a set `\u03b2`, each `g : \u03b1` defines a permutation of\n`\u03b2`. -/\n@[simps]\ndef add_action.to_perm_hom (\u03b1 : Type*) [add_group \u03b1] [add_action \u03b1 \u03b2] :\n  \u03b1 \u2192+ additive (equiv.perm \u03b2) :=\n{ to_fun := \u03bb a, additive.of_mul $ add_action.to_perm a,\n  map_zero' := equiv.ext $ zero_vadd \u03b1,\n  map_add' := \u03bb a\u2081 a\u2082, equiv.ext $ add_vadd a\u2081 a\u2082 }\n\n/-- The tautological action by `equiv.perm \u03b1` on `\u03b1`.\n\nThis generalizes `function.End.apply_mul_action`.-/\ninstance equiv.perm.apply_mul_action (\u03b1 : Type*) : mul_action (equiv.perm \u03b1) \u03b1 :=\n{ smul := \u03bb f a, f a,\n  one_smul := \u03bb _, rfl,\n  mul_smul := \u03bb _ _ _, rfl }\n\n@[simp] protected lemma equiv.perm.smul_def {\u03b1 : Type*} (f : equiv.perm \u03b1) (a : \u03b1) : f \u2022 a = f a :=\nrfl\n\n/-- `equiv.perm.apply_mul_action` is faithful. -/\ninstance equiv.perm.apply_has_faithful_smul (\u03b1 : Type*) : has_faithful_smul (equiv.perm \u03b1) \u03b1 :=\n\u27e8\u03bb x y, equiv.ext\u27e9\n\nvariables {\u03b1} {\u03b2}\n\n@[to_additive] lemma inv_smul_eq_iff {a : \u03b1} {x y : \u03b2} : a\u207b\u00b9 \u2022 x = y \u2194 x = a \u2022 y :=\n(mul_action.to_perm a).symm_apply_eq\n\n@[to_additive] lemma eq_inv_smul_iff {a : \u03b1} {x y : \u03b2} : x = a\u207b\u00b9 \u2022 y \u2194 a \u2022 x = y :=\n(mul_action.to_perm a).eq_symm_apply\n\nlemma smul_inv [group \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2] (c : \u03b1) (x : \u03b2) :\n  (c \u2022 x)\u207b\u00b9 = c\u207b\u00b9 \u2022 x\u207b\u00b9  :=\nby rw [inv_eq_iff_mul_eq_one, smul_mul_smul, mul_right_inv, mul_right_inv, one_smul]\n\nlemma smul_zpow [group \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2]\n  (c : \u03b1) (x : \u03b2) (p : \u2124) :\n  (c \u2022 x) ^ p = c ^ p \u2022 x ^ p :=\nby { cases p; simp [smul_pow, smul_inv] }\n\n@[simp] lemma commute.smul_right_iff [has_mul \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2]\n  {a b : \u03b2} (r : \u03b1) :\n  commute a (r \u2022 b) \u2194 commute a b :=\n\u27e8\u03bb h, inv_smul_smul r b \u25b8 h.smul_right r\u207b\u00b9, \u03bb h, h.smul_right r\u27e9\n\n@[simp] lemma commute.smul_left_iff [has_mul \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2]\n  {a b : \u03b2} (r : \u03b1) :\n  commute (r \u2022 a) b \u2194 commute a b :=\nby rw [commute.symm_iff, commute.smul_right_iff, commute.symm_iff]\n\n@[to_additive] protected lemma mul_action.bijective (g : \u03b1) : bijective ((\u2022) g : \u03b2 \u2192 \u03b2) :=\n(mul_action.to_perm g).bijective\n\n@[to_additive] protected lemma mul_action.injective (g : \u03b1) : injective ((\u2022) g : \u03b2 \u2192 \u03b2) :=\n(mul_action.bijective g).injective\n\n@[to_additive] protected lemma mul_action.surjective (g : \u03b1) : surjective ((\u2022) g : \u03b2 \u2192 \u03b2) :=\n(mul_action.bijective g).surjective\n\n@[to_additive] lemma smul_left_cancel (g : \u03b1) {x y : \u03b2} (h : g \u2022 x = g \u2022 y) : x = y :=\nmul_action.injective g h\n\n@[simp, to_additive] lemma smul_left_cancel_iff (g : \u03b1) {x y : \u03b2} : g \u2022 x = g \u2022 y \u2194 x = y :=\n(mul_action.injective g).eq_iff\n\n@[to_additive] lemma smul_eq_iff_eq_inv_smul (g : \u03b1) {x y : \u03b2} :\n  g \u2022 x = y \u2194 x = g\u207b\u00b9 \u2022 y :=\n(mul_action.to_perm g).apply_eq_iff_eq_symm_apply\n\nend group\n\n/-- `monoid.to_mul_action` is faithful on nontrivial cancellative monoids with zero. -/\ninstance cancel_monoid_with_zero.to_has_faithful_smul [cancel_monoid_with_zero \u03b1] [nontrivial \u03b1] :\n  has_faithful_smul \u03b1 \u03b1 :=\n\u27e8\u03bb x y h, mul_left_injective\u2080 one_ne_zero (h 1)\u27e9\n\nsection gwz\nvariables [group_with_zero \u03b1] [mul_action \u03b1 \u03b2] {a : \u03b1}\n\n@[simp]\nlemma inv_smul_smul\u2080 {c : \u03b1} (hc : c \u2260 0) (x : \u03b2) : c\u207b\u00b9 \u2022 c \u2022 x = x :=\ninv_smul_smul (units.mk0 c hc) x\n\n@[simp]\nlemma smul_inv_smul\u2080 {c : \u03b1} (hc : c \u2260 0) (x : \u03b2) : c \u2022 c\u207b\u00b9 \u2022 x = x :=\nsmul_inv_smul (units.mk0 c hc) x\n\nlemma inv_smul_eq_iff\u2080 {a : \u03b1} (ha : a \u2260 0) {x y : \u03b2} : a\u207b\u00b9 \u2022 x = y \u2194 x = a \u2022 y :=\n(mul_action.to_perm (units.mk0 a ha)).symm_apply_eq\n\nlemma eq_inv_smul_iff\u2080 {a : \u03b1} (ha : a \u2260 0) {x y : \u03b2} : x = a\u207b\u00b9 \u2022 y \u2194 a \u2022 x = y :=\n(mul_action.to_perm (units.mk0 a ha)).eq_symm_apply\n\n@[simp] lemma commute.smul_right_iff\u2080 [has_mul \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2]\n  {a b : \u03b2} {c : \u03b1} (hc : c \u2260 0) :\n  commute a (c \u2022 b) \u2194 commute a b :=\ncommute.smul_right_iff (units.mk0 c hc)\n\n@[simp] lemma commute.smul_left_iff\u2080 [has_mul \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2]\n  {a b : \u03b2} {c : \u03b1} (hc : c \u2260 0) :\n  commute (c \u2022 a) b \u2194 commute a b :=\ncommute.smul_left_iff (units.mk0 c hc)\n\nprotected lemma mul_action.bijective\u2080 (ha : a \u2260 0) : bijective ((\u2022) a : \u03b2 \u2192 \u03b2) :=\nmul_action.bijective $ units.mk0 a ha\n\nprotected lemma mul_action.injective\u2080 (ha : a \u2260 0) : injective ((\u2022) a : \u03b2 \u2192 \u03b2) :=\n(mul_action.bijective\u2080 ha).injective\n\nprotected lemma mul_action.surjective\u2080 (ha : a \u2260 0) : surjective ((\u2022) a : \u03b2 \u2192 \u03b2) :=\n(mul_action.bijective\u2080 ha).surjective\n\nend gwz\n\nend mul_action\n\nsection distrib_mul_action\n\nsection group\nvariables [group \u03b1] [add_monoid \u03b2] [distrib_mul_action \u03b1 \u03b2]\n\nvariables (\u03b2)\n\n/-- Each element of the group defines an additive monoid isomorphism.\n\nThis is a stronger version of `mul_action.to_perm`. -/\n@[simps {simp_rhs := tt}]\ndef distrib_mul_action.to_add_equiv (x : \u03b1) : \u03b2 \u2243+ \u03b2 :=\n{ .. distrib_mul_action.to_add_monoid_hom \u03b2 x,\n  .. mul_action.to_perm_hom \u03b1 \u03b2 x }\n\nvariables (\u03b1 \u03b2)\n\n/-- Each element of the group defines an additive monoid isomorphism.\n\nThis is a stronger version of `mul_action.to_perm_hom`. -/\n@[simps]\ndef distrib_mul_action.to_add_aut : \u03b1 \u2192* add_aut \u03b2 :=\n{ to_fun := distrib_mul_action.to_add_equiv \u03b2,\n  map_one' := add_equiv.ext (one_smul _),\n  map_mul' := \u03bb a\u2081 a\u2082, add_equiv.ext (mul_smul _ _) }\n\nvariables {\u03b1 \u03b2}\n\ntheorem smul_eq_zero_iff_eq (a : \u03b1) {x : \u03b2} : a \u2022 x = 0 \u2194 x = 0 :=\n\u27e8\u03bb h, by rw [\u2190 inv_smul_smul a x, h, smul_zero], \u03bb h, h.symm \u25b8 smul_zero _\u27e9\n\ntheorem smul_ne_zero_iff_ne (a : \u03b1) {x : \u03b2} : a \u2022 x \u2260 0 \u2194 x \u2260 0 :=\nnot_congr $ smul_eq_zero_iff_eq a\n\nend group\n\nsection gwz\nvariables [group_with_zero \u03b1] [add_monoid \u03b2] [distrib_mul_action \u03b1 \u03b2]\n\ntheorem smul_eq_zero_iff_eq' {a : \u03b1} (ha : a \u2260 0) {x : \u03b2} : a \u2022 x = 0 \u2194 x = 0 :=\nshow units.mk0 a ha \u2022 x = 0 \u2194 x = 0, from smul_eq_zero_iff_eq _\n\ntheorem smul_ne_zero_iff_ne' {a : \u03b1} (ha : a \u2260 0) {x : \u03b2} : a \u2022 x \u2260 0 \u2194 x \u2260 0 :=\nshow units.mk0 a ha \u2022 x \u2260 0 \u2194 x \u2260 0, from smul_ne_zero_iff_ne _\n\nend gwz\n\nend distrib_mul_action\n\nsection mul_distrib_mul_action\nvariables [group \u03b1] [monoid \u03b2] [mul_distrib_mul_action \u03b1 \u03b2]\n\nvariables (\u03b2)\n\n/-- Each element of the group defines a multiplicative monoid isomorphism.\n\nThis is a stronger version of `mul_action.to_perm`. -/\n@[simps {simp_rhs := tt}]\ndef mul_distrib_mul_action.to_mul_equiv (x : \u03b1) : \u03b2 \u2243* \u03b2 :=\n{ .. mul_distrib_mul_action.to_monoid_hom \u03b2 x,\n  .. mul_action.to_perm_hom \u03b1 \u03b2 x }\n\nvariables (\u03b1 \u03b2)\n\n/-- Each element of the group defines an multiplicative monoid isomorphism.\n\nThis is a stronger version of `mul_action.to_perm_hom`. -/\n@[simps]\ndef mul_distrib_mul_action.to_mul_aut : \u03b1 \u2192* mul_aut \u03b2 :=\n{ to_fun := mul_distrib_mul_action.to_mul_equiv \u03b2,\n  map_one' := mul_equiv.ext (one_smul _),\n  map_mul' := \u03bb a\u2081 a\u2082, mul_equiv.ext (mul_smul _ _) }\n\nvariables {\u03b1 \u03b2}\n\nend mul_distrib_mul_action\n\nsection arrow\n\n/-- If `G` acts on `A`, then it acts also on `A \u2192 B`, by `(g \u2022 F) a = F (g\u207b\u00b9 \u2022 a)`. -/\n@[to_additive arrow_add_action \"If `G` acts on `A`, then it acts also on `A \u2192 B`, by\n`(g +\u1d65 F) a = F (g\u207b\u00b9 +\u1d65 a)`\", simps]\ndef arrow_action {G A B : Type*} [division_monoid G] [mul_action G A] : mul_action G (A \u2192 B) :=\n{ smul := \u03bb g F a, F (g\u207b\u00b9 \u2022 a),\n  one_smul := by { intro, simp only [inv_one, one_smul] },\n  mul_smul := by { intros, simp only [mul_smul, mul_inv_rev] } }\n\nlocal attribute [instance] arrow_action\n\n/-- When `B` is a monoid, `arrow_action` is additionally a `mul_distrib_mul_action`. -/\ndef arrow_mul_distrib_mul_action {G A B : Type*} [group G] [mul_action G A] [monoid B] :\n  mul_distrib_mul_action G (A \u2192 B) :=\n{ smul_one := \u03bb g, rfl,\n  smul_mul := \u03bb g f\u2081 f\u2082, rfl }\n\nlocal attribute [instance] arrow_mul_distrib_mul_action\n\n/-- Given groups `G H` with `G` acting on `A`, `G` acts by\n  multiplicative automorphisms on `A \u2192 H`. -/\n@[simps] def mul_aut_arrow {G A H} [group G] [mul_action G A] [monoid H] : G \u2192* mul_aut (A \u2192 H) :=\nmul_distrib_mul_action.to_mul_aut _ _\n\nend arrow\n\nnamespace is_unit\n\nsection mul_action\nvariables [monoid \u03b1] [mul_action \u03b1 \u03b2]\n\n@[to_additive] lemma smul_left_cancel {a : \u03b1} (ha : is_unit a) {x y : \u03b2} :\n  a \u2022 x = a \u2022 y \u2194 x = y :=\nlet \u27e8u, hu\u27e9 := ha in hu \u25b8 smul_left_cancel_iff u\n\nend mul_action\n\nsection distrib_mul_action\nvariables [monoid \u03b1] [add_monoid \u03b2] [distrib_mul_action \u03b1 \u03b2]\n\n@[simp] theorem smul_eq_zero {u : \u03b1} (hu : is_unit u) {x : \u03b2} :\n  u \u2022 x = 0 \u2194 x = 0 :=\nexists.elim hu $ \u03bb u hu, hu \u25b8 show u \u2022 x = 0 \u2194 x = 0, from smul_eq_zero_iff_eq u\n\nend distrib_mul_action\n\nend is_unit\n\nsection smul\n\nvariables [group \u03b1] [monoid \u03b2]\n\n@[simp] lemma is_unit_smul_iff [mul_action \u03b1 \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2]\n  (g : \u03b1) (m : \u03b2) : is_unit (g \u2022 m) \u2194 is_unit m :=\n\u27e8\u03bb h, inv_smul_smul g m \u25b8 h.smul g\u207b\u00b9, is_unit.smul g\u27e9\n\nlemma is_unit.smul_sub_iff_sub_inv_smul\n  [add_group \u03b2] [distrib_mul_action \u03b1 \u03b2] [is_scalar_tower \u03b1 \u03b2 \u03b2] [smul_comm_class \u03b1 \u03b2 \u03b2]\n  (r : \u03b1) (a : \u03b2) : is_unit (r \u2022 1 - a) \u2194 is_unit (1 - r\u207b\u00b9 \u2022 a) :=\nby rw [\u2190is_unit_smul_iff r (1 - r\u207b\u00b9 \u2022 a), smul_sub, smul_inv_smul]\n\nend smul\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/group_theory/group_action/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7025886427172221}}
{"text": "-- \u0412\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f, \u0441\u0432\u044f\u0437\u043a\u0438 \u0438 \u0430\u043a\u0441\u0438\u043e\u043c\u044b\n\nnamespace props \n  constant and'  : Prop \u2192 Prop \u2192 Prop     -- \u0432\u0441\u0435 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u0432 Lean \u0436\u0438\u0432\u0443\u0442 \u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0441\u0435\u043b\u0435\u043d\u043d\u043e\u0439 Prop\n                                          -- \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u043d\u0430\u0434 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f\n                                          -- \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u0434 Prop\n\n  constant or'   : Prop \u2192 Prop \u2192 Prop\n  constant not'  : Prop \u2192 Prop\n  constant impl' : Prop \u2192 Prop \u2192 Prop\n\n  variables a b c : Prop\n\n  #check and' a (or' b c) -- Prop         -- \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043d\u0430\u0441\u0435\u043b\u044f\u044e\u0449\u0438\u043c \u0432\u0441\u0435\u043b\u0435\u043d\u043d\u044b\u0435 Type u\n\n  constant Proof : Prop \u2192 Type            -- \u0432\u0432\u0435\u0434\u0435\u043c \u0442\u0438\u043f \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432: \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e (a : Prop), Proof a \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e a\n\n  constant and_comm' : \u03a0 a b : Prop,      -- \u0442\u043e\u0433\u0434\u0430 \u0430\u043a\u0441\u0438\u043e\u043c\u044b - \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0442\u0438\u043f\u0430 Proof \u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u043a\u0441\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f\n                        Proof (impl' (and' a b) (and' b a))\n\n  #check and_comm' a b -- Proof (impl' (and' a b) (and' b a)) -- \"\u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\" \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0430\u043a\u0441\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c (a \u2227 b) \u2192 (b \u2227 a)\n\n\n  constant modus_ponens : \u03a0 a b : Prop,   -- \u0437\u0430\u0434\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u043e Modes Ponens, \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0435\u0435 b \u0438\u0437 (a \u2192 b) \u0438 \u0438\u0441\u0442\u0438\u043d\u043e\u0441\u0442\u0438 a\n                            Proof (impl' a b) \u2192 Proof a \u2192 Proof b\nend props\n\n-- \u0422\u0435\u043e\u0440\u0435\u043c\u044b\n\nnamespace theorems\n  constants p q : Prop\n\n  theorem t1 : p \u2192 q \u2192 p :=               -- \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u0434 Prop \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0442\u0435\u043e\u0440\u0435\u043c\u0430\u043c\u0438\n    \u03bb (hp : p), \u03bb (hq : q), hp            -- \u0438\u0437\u043e\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u041a\u0430\u0440\u0440\u0438-\u0413\u043e\u0432\u0430\u0440\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u043e\u0431\u0438\u0442\u0430\u0435\u043c, \u0442\u043e \u044d\u0442\u043e \u0442\u043e \u0436\u0435, \u0447\u0442\u043e\n                                          -- \u0438\u0437\u043e\u043c\u043e\u0440\u0444\u043d\u043e\u0435 \u0435\u043c\u0443 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u0438\u0441\u0442\u0438\u043d\u043e; \u0437\u0434\u0435\u0441\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0430\u043a\u0441\u0438\u043e\u043c\u0430\n                                          -- \u0413\u0438\u043b\u044c\u0431\u0435\u0440\u0442\u0430\n\n  theorem t1' : p \u2192 q \u2192 p :=\n    assume hp : p,                        -- \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0435\u043e\u0440\u0435\u043c \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440:\n    assume hq : q,                        -- assume x : \u03b1 == \u03bb (x : \u03b1)\n    hp                                    -- assume - \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c\n\n  theorem t1'' : p \u2192 q \u2192 p :=\n    assume hp : p,\n    assume hq : q,\n    show p, from hp                       -- \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c p, \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0430\u0445\u0430\u0440\n                                          -- show {type}, from {expr}\n\n  lemma l1 : p \u2192 q \u2192 p :=                 -- \u0441\u043b\u043e\u0432\u043e theorem \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 lemma \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435\n    assume hp : p,\n    assume hq : q, \n    show p, from hp\n\n  lemma l1a (hp : p) (hq : q) : p := hp   -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u043f\u043e\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c\n\n  axiom hp : p                            -- \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440 - \u0441\u043b\u043e\u0432\u043e axiom, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c constant\n\n  theorem t2 : q \u2192 p := t1 hp             -- \u043b\u0435\u043c\u043c\u044b \u0438 \u0442\u0435\u043e\u0440\u0435\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439\n\n\n  theorem t1_common : \u2200 (p q : Prop),     -- \u043d\u0430\u0448\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0442\u0435\u043e\u0440\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 p \u0438 q \n                      p \u2192 q \u2192 p :=        -- \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0439, \u0432\u0432\u0435\u0434\u044f \u043a\u0432\u0430\u043d\u0442\u043e\u0440 \u2200 (\\forall),\n    assume p : Prop,                      -- \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0439 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0435\u0439 \u03a0 \u0434\u043b\u044f Prop\n    assume q : Prop,                      -- \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043a\u0436\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u03bb-\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e/assume \u0441\u0430\u043c\u0438 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f\n    assume hp : p,\n    assume hq : q,\n    show p, from hp\n\n  variables p' q' r' s' : Prop            -- \u043a\u0430\u043a \u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445, \u0432\u0441\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0432 \u043e\u0431\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435\n\n  theorem t1_common_var : p' \u2192 q' \u2192 p' := -- \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u043e\u0440\u0435\u043c \u0438 \u043b\u0435\u043c\u043c \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\n    assume hp : p',\n    assume hq : q',\n    show p', from hp\n\n  #check t1_common p' q' -- p' \u2192 q' \u2192 p'  -- \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0439 \u0442\u0435\u043e\u0440\u0435\u043c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u043d\u0430 \u043b\u044e\u0431\u044b\u0445 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f\u0445\n  #check t1_common r' s' -- r' \u2192 s' \u2192 r'\n  #check t1_common (p' \u2192 q') (s' \u2192 r') -- (p' \u2192 q') \u2192 (s' \u2192 r') \u2192 p' \u2192 q'\n\n  #check t1_common p q hp -- q \u2192 p        -- \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0430\u043a\u0441\u0438\u043e\u043c\u044b \u0432 \u0442\u0435\u043e\u0440\u0435\u043c\u0443 \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0430 \u0432\u044b\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\n\n  theorem t3 : \u2200 {p q r : Prop},          -- \u0432 \u0442\u0435\u043e\u0440\u0435\u043c\u0430\u0445 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b\n                (q \u2192 r) \u2192 (p \u2192 q) \u2192\n                p \u2192 r :=\n    assume p q r : Prop,                  -- \u043a\u0430\u043a \u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445, \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0432\u0432\u043e\u0434\u0438\u0442\u044c, \u0438, \u043a\u0441\u0442\u0430\u0442\u0438, assume \u0442\u043e\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0430\u0445\u0430\u0440\n    assume h\u2081 : q \u2192 r,                    -- \u0434\u043b\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430\n    assume h\u2082 : p \u2192 q,                    -- \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0435 \u043d\u0438\u0436\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \\_{\u0441\u0438\u043c\u0432\u043e\u043b} (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, h\\_1 \u0438\u043b\u0438 h\\_2)\n    assume h\u2083 : p,\n    show r, from h\u2081 (h\u2082 h\u2083)\n\n  #check @t3 -- \u2200 {p q r : Prop}, (q \u2192 r) \u2192 (p \u2192 q) \u2192 p \u2192 r\n\n  example : p \u2192 q \u2192 p :=                  -- \u0447\u0442\u043e\u0431 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e, \u043d\u043e \u043d\u0435 \u0437\u0430\u0441\u043e\u0440\u044f\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f\n    assume hp : p,                        -- \"\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c\", \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 example\n    assume hq : q,\n    show p, from hp\n\n  example (hp : p) (hq : q) : p := hp     -- \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043a\u0430\u043a \u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0447\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432\n\n  example : \u2200 {p q r : Prop},\n              (q \u2192 r) \u2192 (p \u2192 q) \u2192\n              p \u2192 r :=\n    assume p q r : Prop,\n    assume hqr : q \u2192 r,\n    assume hpq : p \u2192 q,\n    assume hp  : p,                       -- \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438\n    have hq : q, from hpq hp,             -- have {var : type}, from {expr}, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0439 show\n    show r, from hqr hq                   -- \u0434\u0430\u043b\u0435\u0435 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0445\u043e\u0434\u0443 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430\n                                          -- \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u0430\u0445\u0430\u0440 (have x : p, from e, t) \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432\n                                          -- (\u03bb (x : p), t) e\n\n   example : \u2200 {p q r : Prop},\n              (q \u2192 r) \u2192 (p \u2192 q) \u2192\n              p \u2192 r :=\n    assume p q r : Prop,\n    assume hqr : q \u2192 r,\n    assume hpq : p \u2192 q,\n    assume hp  : p,                  \n    have q, from hpq hp,                  -- have \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u043c (\u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f, \u0431\u0435\u0437 \u0442\u0435\u0440\u043c\u0430)\n    show r, from hqr this                 -- \u0447\u0442\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 have \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u043b\u043e\u0432\u043e this, \u043e\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f\n                                          -- \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 have; \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 (this : q)\n\n  example : \u2200 {p q r : Prop},             -- \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f suffices to show, \u0441\u0442\u0440\u043e\u044f\u0449\u0430\u044f \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e\u043c,\n              (q \u2192 r) \u2192 (p \u2192 q) \u2192         -- \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u0434\u0446\u0435\u043b\u044c, \u0447\u0442\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0446\u0435\u043b\u044c (\u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e)\n              p \u2192 r :=                    -- \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 (have x : p, from e, t)\n    assume p q r : Prop,\n    assume hqr : q \u2192 r,\n    assume hpq : p \u2192 q,\n    assume hp  : p,\n    suffices hq : q, from hqr hq,         -- \u0447\u0438\u0442\u0430\u0435\u043c: \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u0439\u0442\u0438 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u043e hq \u0434\u043b\u044f q, \u0447\u0442\u043e\u0431 \u0434\u0430\u043b\u044c\u0448\u0435\n    show q, from hpq hp                   -- \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u0447\u0435\u0440\u0435\u0437 hqr hq, \u0447\u0442\u043e \u043c\u044b \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f q \u0447\u0435\u0440\u0435\u0437 hpq hp\n\n  example : \u2200 {p q r : Prop},             -- \u043f\u043e\u043b\u043d\u0430\u044f \u0434\u0435\u0448\u0443\u0433\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0442\u0435\u043e\u0440\u0435\u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0436\u0443\u0442\u043a\u043e\u0432\u0430\u0442\u043e,\n              (q \u2192 r) \u2192 (p \u2192 q) \u2192         -- \u0445\u043e\u0442\u044f \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u0439 \u0440\u043e\u0432\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435\n              p \u2192 r :=\n    \u03bb p : Prop, \u03bb q : Prop, \u03bb r : Prop,\n    \u03bb hpr : q \u2192 r, \u03bb hpq : p \u2192 q, \u03bb hp : p,\n    (\u03bb hq : q, hpr hq) (hpq hp)\nend theorems\n\n-- \u041b\u043e\u0433\u0438\u043a\u0430 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435\n\nnamespace stdlib_logic\n  variables a b : Prop\n\n  #check a \u2192 b \u2192 a \u2227 b  -- Prop           -- \u0441\u0432\u044f\u0437\u043a\u0438 \u2192 (\\r), \u2227 (\\and), \u2228 (\\or), \u00ac (\\not), \u2194 (\\iff),\n  #check \u00aca \u2192 a \u2194 false -- Prop           -- \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b true \u0438 false \u0443\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435\n  #check a \u2228 b \u2192 b \u2228 a  -- Prop\nend stdlib_logic\n\n-- and\n\nnamespace stdlib_and\n  variables p q : Prop\n\n  example (hp : p) (hq : q) : p \u2227 q :=    -- \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0442\u0435\u043e\u0440\u0435\u043c \u0438 \u043b\u0435\u043c\u043c,\n    and.intro hp hq                       -- \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\n\n  example : p \u2227 q \u2192 p :=\n    assume hpq : p \u2227 q,\n    show p, from and.elim_left hpq\n\n  example : p \u2227 q \u2192 q :=\n    assume hpq : p \u2227 q,\n    show q, from and.elim_right hpq\n\n  #check @and.intro      -- \u2200 {a b : Prop}, a \u2192 b \u2192 a \u2227 b\n  #check @and.elim_left  -- \u2200 {a b : Prop}, a \u2227 b \u2192 a\n  #check @and.elim_right -- \u2200 {a b : Prop}, a \u2227 b \u2192 b\n\n  example : p \u2227 q \u2192 q \u2227 p :=              -- \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u0435\u0449\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0430\u0437 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430\n    assume hpq : p \u2227 q,                   -- \u0442\u0430\u043a, and.left == and.elim_left, \u0430 and.right == and.elim_right\n    show q \u2227 p, from \u27e8and.right hpq, and.left hpq\u27e9 -- and.intro \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u27e8,\u27e9 (\\< \u0438 \\>)\n\n  example : p \u2227 q \u2192 q \u2227 p :=\n    assume hpq : p \u2227 q,\n    show q \u2227 p, from \u27e8hpq.right, hpq.left\u27e9-- \u0435\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0430\u0445\u0430\u0440\u0430, and.left hpq \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 hpq.left \u0438 \u0442.\u0434.\n\n  example (hpq : p \u2227 q) : q \u2227 p :=        -- \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f, \u043d\u043e, imho, \u043c\u0430\u043b\u043e\u043f\u043e\u043d\u044f\u0442\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430\n  \u27e8hpq.right, hpq.left\u27e9                   -- \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0430\u043c, \u043d\u043e, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0432 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0435 \u0442\u0435\u043e\u0440\u0435\u043c \u0440\u0435\u0448\u0430\u0435\u0442 \u0432\u0435\u0440\u0431\u043e\u0437\u043d\u043e\u0441\u0442\u044c\nend stdlib_and\n\n-- or\n\nnamespace stdlib_or\n  variables p q : Prop\n\n  example : p \u2192 p \u2228 q :=                  -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0432\u0435\u0449\u0438 \u0435\u0441\u0442\u044c \u0434\u043b\u044f \u0438 \u2228 (\u0438 \u043a\u0443\u0447\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0435\u0449\u0435\u0439)\n    assume hp : p,\n    show p \u2228 q, from or.intro_left q hp\n\n  example : q \u2192 p \u2228 q :=\n    assume hq : q,\n    show p \u2228 q, from or.intro_right p hq\n\n  example : p \u2228 q \u2192 q \u2228 p :=\n    assume hpq : p \u2228 q,\n    or.elim hpq                           -- or.elim (x : a \u2228 b) \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u044f: \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u044c \u0430 \u0438 b\n      (assume hp : p,                     -- \u0435\u0441\u043b\u0438 \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e, \u0442\u043e \u043e\u0431\u0449\u0435\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u043d\u043e\n      show q \u2228 p, from or.inr hp)\n      (assume hq : q,                     -- or.inr \u0438 or.inl \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0430\u043c\u0438 intro_*, \u043d\u043e \u0441 \u043e\u0431\u043e\u0438\u043c\u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438\n      show q \u2228 p, from or.inl hq)\n\n  #check @or.elim        -- \u2200 {a b c : Prop}, a \u2228 b \u2192 (a \u2192 c) \u2192 (b \u2192 c)\n  #check @or.intro_left  -- \u2200 (a : Prop) {b : Prop}, a \u2192 a \u2228 b\n  #check @or.intro_right -- \u2200 {a : Prop} (b : Prop), b \u2192 a \u2228 b\n  #check @or.inl         -- \u2200 {a b : Prop}, a \u2192 a \u2228 b\n  #check @or.inr         -- \u2200 {a b : Prop}, b \u2192 a \u2228 b\nend stdlib_or\n\n-- not\n\nnamespace stdlib_not\n  variables p q : Prop\n\n  example : (p \u2192 q) \u2192 \u00acq \u2192 \u00acp :=          -- not \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0443\u043d\u0430\u0440\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 p \u2192 false\n    assume h\u2081 : p \u2192 q,                    -- \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0432 assume \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c\n    assume h\u2082 : \u00acq,                       -- assume h : p, \u0438 \u0442\u043e\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e false\n    assume h\u2083 : p,\n    show false, from h\u2082 (h\u2081 h\u2083)\n\n  example : p \u2192 \u00acp \u2192 q :=                 -- false.elim \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0438\u0437 \u043b\u0436\u0438\n    assume hp : p,\n    assume hnp : \u00acp,\n    false.elim (hnp hp)\n\n  example : p \u2192 \u00acp \u2192 q :=                 -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 absurd, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0438 \u0435\u0433\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435,\n    assume hp : p,                        -- \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e\n    assume hnp : \u00acp,\n    absurd hp hnp\n\n  #check @false.elim -- \u03a0 {c : Type u}, false \u2192 c\n  #check @absurd     -- \u03a0 {a : Prop} {c : Type u}, a \u2192 \u00aca \u2192 c\nend stdlib_not\n\n-- equiv\n\nnamespace stdlib_equiv\n  variables p q : Prop\n\n  theorem and_swap : p \u2227 q \u2194 q \u2227 p :=\n    iff.intro                             -- \u0434\u043b\u044f \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u043c\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0432 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443\n      (assume hpq : p \u2227 q,\n      show q \u2227 p, from and.swap hpq)\n      (assume hqp : q \u2227 p,\n      show p \u2227 q, from and.swap hqp)\n\n  #check @iff.intro -- \u2200 {a b : Prop}, (a \u2192 b) \u2192 (b \u2192 a) \u2192 (a \u2194 b)\n  #check @and.swap  -- \u2200 {a b : Prop}, a \u2227 b \u2192 b \u2227 a\n\n  #check and_swap p q  -- p \u2227 q \u2194 q \u2227 p\n\n  example (h : p \u2227 q) : q \u2227 p :=          -- \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u0437 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0446\u0438\u0438: (a \u2194 b) \u2192 a \u2192 b,\n    iff.mp (and_swap p q) h               -- \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0446\u0438\u0438 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443; \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435\n                                          -- \u0444\u0443\u043d\u043a\u0446\u0438\u0438: iff.mp \u0438 iff.mpr (modus ponens \u0438 modus ponens reverse)\n\n  #check @iff.mp  -- \u2200 {a b : Prop}, (a \u2194 b) \u2192 a \u2192 b\n  #check @iff.mpr -- \u2200 {a b : Prop}, (a \u2194 b) \u2192 b \u2192 a\n\n\nend stdlib_equiv\n\n-- classical\n\nnamespace stdlib_classical                -- \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u2014 \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u043e\u043d\u0438\u0441\u0442\u0441\u043a\u0430\u044f,\n  open classical                          -- \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u0435\u0451 \u0438\u0437 classical\n\n  #check em -- \u2200 {p : Prop}, p \u2228 \u00acp       -- \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0430\u043a\u0441\u0438\u043e\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0441\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u0438 \u043e\u0442\u0441\u0443\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439\n\n  theorem dne {p : Prop} (h : \u00ac\u00acp) : p := -- \u0434\u043e\u043a\u0430\u0436\u0435\u043c \u0437\u0430\u043a\u043e\u043d \u0441\u043d\u044f\u0442\u0438\u044f \u0434\u0432\u043e\u0439\u043d\u043e\u0433\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u044f (double negation elimination)\n    or.elim (em p)                        -- \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 p \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u043e\u0433\u043e or.elim\n      (assume hp  : p,\n       show p, from hp)                   -- \u0435\u0441\u043b\u0438 p \u0438\u0441\u0442\u0438\u043d\u043e, \u0442\u043e \u0432\u0441\u0435 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\n      (assume hnp : \u00acp,\n       show p, from absurd hnp h)         -- \u0438\u043d\u0430\u0447\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438 \u00acp \u0438 \u0435\u0433\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435 \u00ac(\u00acp), \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e\n\n  example {p : Prop} (h : \u00ac\u00acp) : p :=     -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e by_cases,\n    by_cases                              -- \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0439\u0441\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0435\u0439 or.elim \u0438 em\n      (assume hp  : p,\n       show p, from hp)\n      (assume hnp : \u00acp,\n       show p, from absurd hnp h)\n\n  #check @by_cases -- \u2200 {p q : Prop}, (p \u2192 q) \u2192 (\u00acp \u2192 q) \u2192 q\n\n  example {p : Prop} (h : \u00ac\u00acp) : p :=     -- \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u044d\u043b\u0438\u0433\u0430\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043e\u0442 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u0433\u043e, \u0433\u0434\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e,\n    by_contradiction                      -- \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 false\n      (assume hnp : \u00acp,\n       show false, from h hnp)\n\n  #check @by_contradiction -- \u2200 {p : Prop}, (\u00acp \u2192 false) \u2192 p\n\nend stdlib_classical", "meta": {"author": "zmactep", "repo": "llfgg", "sha": "ed684ae69b94a4a042615c412fef68bdec8fc80c", "save_path": "github-repos/lean/zmactep-llfgg", "path": "github-repos/lean/zmactep-llfgg/llfgg-ed684ae69b94a4a042615c412fef68bdec8fc80c/3_propositions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.7025886420671494}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.algebraic_geometry.prime_spectrum\nimport Mathlib.ring_theory.polynomial.basic\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\nThe morphism `Spec R[x] --> Spec R` induced by the natural inclusion `R --> R[x]` is an open map.\n-/\n\nnamespace algebraic_geometry\n\n\nnamespace polynomial\n\n\n/-- Given a polynomial `f \u2208 R[x]`, `image_of_Df` is the subset of `Spec R` where at least one\nof the coefficients of `f` does not vanish.  Lemma `image_of_Df_eq_comap_C_compl_zero_locus`\nproves that `image_of_Df` is the image of `(zero_locus {f})\u1d9c` under the morphism\n`comap C : Spec R[x] \u2192 Spec R`. -/\ndef image_of_Df {R : Type u_1} [comm_ring R] (f : polynomial R) : set (prime_spectrum R) :=\n  set_of fun (p : prime_spectrum R) => \u2203 (i : \u2115), \u00acpolynomial.coeff f i \u2208 prime_spectrum.as_ideal p\n\ntheorem is_open_image_of_Df {R : Type u_1} [comm_ring R] {f : polynomial R} :\n    is_open (image_of_Df f) :=\n  sorry\n\n/-- If a point of `Spec R[x]` is not contained in the vanishing set of `f`, then its image in\n`Spec R` is contained in the open set where at least one of the coefficients of `f` is non-zero.\nThis lemma is a reformulation of `exists_coeff_not_mem_C_inverse`. -/\ntheorem comap_C_mem_image_of_Df {R : Type u_1} [comm_ring R] {f : polynomial R}\n    {I : prime_spectrum (polynomial R)} (H : I \u2208 (prime_spectrum.zero_locus (singleton f)\u1d9c)) :\n    prime_spectrum.comap polynomial.C I \u2208 image_of_Df f :=\n  polynomial.exists_coeff_not_mem_C_inverse\n    (iff.mp prime_spectrum.mem_compl_zero_locus_iff_not_mem H)\n\n/-- The open set `image_of_Df f` coincides with the image of `basic_open f` under the\nmorphism `C\u207a : Spec R[x] \u2192 Spec R`. -/\ntheorem image_of_Df_eq_comap_C_compl_zero_locus {R : Type u_1} [comm_ring R] {f : polynomial R} :\n    image_of_Df f =\n        prime_spectrum.comap polynomial.C '' (prime_spectrum.zero_locus (singleton f)\u1d9c) :=\n  sorry\n\n/--  The morphism `C\u207a : Spec R[x] \u2192 Spec R` is open. -/\ntheorem is_open_map_comap_C {R : Type u_1} [comm_ring R] :\n    is_open_map (prime_spectrum.comap polynomial.C) :=\n  sorry\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/algebraic_geometry/is_open_comap_C_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7025886359784714}}
{"text": "import algebra.ring algebra.big_operators.basic\nimport data.birange\n\nuniverses u v\n\nvariables (\u03b1 : Type u) (\u03b2 : Type v)\n\ndef power_series := \u2115 \u2192 \u03b1 \n\nnamespace power_series\n\n@[ext]\nlemma ext {a b : power_series \u03b1} : a = b \u2194 \u2200 k, (a k) = (b k) := \n \u27e8\u03bb e, congr_fun e,\u03bb e,funext e\u27e9 \n\nsection add_comm_monoid\n\nvariable [add_comm_monoid \u03b1]\nvariables a b c : power_series \u03b1 \nvariables i j k n m : \u2115 \n\ninstance : add_comm_monoid (power_series \u03b1) := \n by {unfold power_series, apply_instance}\n\nvariable {\u03b1}\n\ndef C (x : \u03b1) : power_series \u03b1 \n| 0 := x\n| (n + 1) := 0\n\nlemma C_coeff_zero {x : \u03b1} : (C x) 0 = x := rfl\nlemma C_coeff_succ {x : \u03b1} (k : \u2115) : (C x) (k + 1) = (0 : \u03b1) := rfl\nlemma C_coeff {x : \u03b1} : \u2200 (k : \u2115), (C x) k = ite (k = 0) x (0 : \u03b1) \n| 0 := by {rw[C_coeff_zero,if_pos rfl],} \n| (k + 1) := by {rw[C_coeff_succ,if_neg (nat.succ_ne_zero k)],}\n\n@[simp]\nlemma zero_coeff : (0 : power_series \u03b1) k = 0 := rfl\n\n@[simp]\nlemma add_coeff : (a + b) k = (a k) + (b k) := rfl\n\nlemma C_zero : C (0 : \u03b1) = 0 := \n by {ext n, rw[zero_coeff],cases n,rw[C_coeff_zero],rw[C_coeff_succ]}\n\nlemma C_add {x y : \u03b1} : C (x + y) = C x + C y := \n by {ext n, rw[add_coeff],cases n,repeat{rw[C_coeff_zero]},\n     repeat{rw[C_coeff_succ]},rw[add_zero]}\n\nend add_comm_monoid\n\nsection semiring\n\nvariable [semiring \u03b1] \n\nvariable {\u03b1}\nvariables a b c : power_series \u03b1 \nvariables x y z : \u03b1\nvariables i j k n m : \u2115 \n\ndef one : (power_series \u03b1)\n| 0 := 1\n| (k + 1) := 0\n\ninstance : has_one (power_series \u03b1) := \u27e8one\u27e9 \n\nlemma one_coeff_zero : (1 : power_series \u03b1) 0 = (1 : \u03b1) := rfl\nlemma one_coeff_succ (k : \u2115) : (1 : power_series \u03b1) (k + 1) = (0 : \u03b1) := rfl\nlemma one_coeff : \u2200 (k : \u2115), (1 : power_series \u03b1) k = ite (k = 0) (1 : \u03b1) (0 : \u03b1) \n| 0 := by {rw[one_coeff_zero,if_pos rfl],} \n| (k + 1) := by {rw[one_coeff_succ,if_neg (nat.succ_ne_zero k)],}\n\nlemma C_one : C (1 : \u03b1) = 1 :=\n by {ext n,cases n,rw[one_coeff_zero,C_coeff_zero],rw[one_coeff_succ,C_coeff_succ]}\n\ndef X : (power_series \u03b1)\n| 0 := 0\n| 1 := 1\n| (k + 2) := 0\n\nlemma X_coeff_zero      : (X : power_series \u03b1) 0       = 0 := rfl\nlemma X_coeff_one       : (X : power_series \u03b1) 1       = 1 := rfl\nlemma X_coeff_succ_succ : (X : power_series \u03b1) (k + 2) = 0 := rfl\nlemma X_coeff : \u2200 (k : \u2115), (X : power_series \u03b1) k = ite (k = 1) 1 0\n| 0 := by {rw[X_coeff_zero, if_neg (dec_trivial : 0 \u2260 1)]}\n| 1 := by {rw[X_coeff_one, if_pos rfl]}\n| (k + 2) := by {have : k + 2 \u2260 1 := \u03bb h, by {cases h},\n                 rw[X_coeff_succ_succ,if_neg this],}\n\ndef shift : power_series \u03b1 \u2192 power_series \u03b1 := \u03bb a k, (a (k + 1))\n\nlemma shift_coeff : (shift a) k = a (k + 1) := rfl\n\nlemma shift_zero : shift (0 : power_series \u03b1)  = 0 := by { ext, refl, }\nlemma shift_one  : shift (1 : power_series \u03b1)  = 0 := by { ext, refl, }\nlemma shift_C {x : \u03b1} : shift (C x) = 0 := by {ext, refl,}\nlemma shift_add : shift (a + b) = shift a + shift b := by {ext, refl}\n\nlemma shift_X : shift (X : power_series \u03b1) = 1 := \n by { ext i, cases i with i, \n     {rw[shift_coeff,one_coeff_zero,zero_add,X_coeff_one],},\n     {rw[shift_coeff,one_coeff_succ,X_coeff_succ_succ]}}\n\ndef smul (x : \u03b1) (a : power_series \u03b1) : power_series \u03b1 := \u03bb k, x * (a k)\ndef rmul (a : power_series \u03b1) (x : \u03b1) : power_series \u03b1 := \u03bb k, (a k) * x\n\n@[simp] lemma smul_coeff : smul x a k = x * (a k) := rfl\n@[simp] lemma rmul_coeff : rmul a x k = (a k) * x := rfl\n\nlemma shift_smul : shift (smul x a) = smul x (shift a) := by { ext, refl, }\nlemma shift_rmul : shift (rmul a x) = rmul (shift a) x := by { ext, refl, }\n\nlemma smul_C : smul x (C y) = C (x * y) := \nby { ext n, cases n, refl, dsimp[smul,C],rw[mul_zero],}\n\nlemma C_smul : rmul (C x) y = C (x * y) := \nby { ext n, cases n, refl, dsimp[rmul,C],rw[zero_mul],}\n\nlemma zero_smul : smul (0 : \u03b1) a = 0 := by { ext n, simp only[smul,zero_coeff,zero_mul],} \nlemma rmul_zero : rmul a (0 : \u03b1) = 0 := by { ext n, simp only[rmul,zero_coeff,mul_zero],} \nlemma smul_zero : smul x 0 = 0 :=  by { ext n, simp only[smul,zero_coeff,mul_zero],} \nlemma zero_rmul : rmul 0 x = 0 :=  by { ext n, simp only[rmul,zero_coeff,zero_mul],} \n\nlemma one_smul : smul (1 : \u03b1) a = a := by { ext n,rw[smul_coeff,one_mul],}\nlemma rmul_one : rmul a (1 : \u03b1) = a := by { ext n,rw[rmul_coeff,mul_one],}\n\nlemma add_smul : smul (x + y) a = (smul x a) + (smul y a) := \n by {ext n, simp only[smul_coeff,add_coeff,add_mul],}\nlemma rmul_add : rmul a (x + y) = (rmul a x) + (rmul a y) := \n by {ext n, simp only[rmul_coeff,add_coeff,mul_add],}\nlemma smul_add : smul x (a + b) = smul x a + smul x b := \n by {ext n, simp only[smul_coeff,add_coeff,mul_add],}\nlemma add_rmul : rmul (a + b) x = rmul a x + rmul b x := \n by {ext n, simp only[rmul_coeff,add_coeff,add_mul],}\n\ndef mul : \u2200 (a b : power_series \u03b1), power_series \u03b1 \n| a b 0 := (a 0) * (b 0)\n| a b (n + 1) := (a (n + 1)) * (b 0) + (mul a b.shift) n\n\ninstance : has_mul (power_series \u03b1) := \u27e8mul\u27e9 \n\nlemma mul_coeff_zero : (a * b) 0 = (a 0) * (b 0) := rfl \n\nlemma mul_coeff_succ :\n (a * b) (n + 1) = (a (n + 1)) * (b 0) + (a * b.shift) n := rfl \n\nlemma mul_coeff_succ' : \n (a * b) (n + 1) = (a 0) * (b (n + 1)) + (a.shift * b) n := \nbegin\n induction n with n ih generalizing a b,\n {rw[mul_coeff_succ,mul_coeff_zero,mul_coeff_zero,shift_coeff,shift_coeff,zero_add,add_comm],},\n {rw[mul_coeff_succ,ih a b.shift,mul_coeff_succ,shift_coeff,shift_coeff],\n  rw[\u2190 add_assoc,\u2190 add_assoc,add_comm ((a 0) * (b (n + 2)))],\n }\nend\n\nlemma mul_eq_sum : \n (a * b) n = (finset.range (n + 1)).sum (\u03bb i, (a i) * (b (n - i))) := \nbegin\n induction n with n ih generalizing a b,\n {rw[mul_coeff_zero,finset.sum_range_succ,finset.range_zero,finset.sum_empty,zero_add]},\n {rw[mul_coeff_succ,finset.sum_range_succ,nat.sub_self,ih a b.shift,add_comm],\n  congr' 1,apply finset.sum_congr rfl,intros i hi,rw[shift_coeff],\n  congr,\n  exact (nat.succ_sub (nat.le_of_lt_succ (finset.mem_range.mp hi))).symm,\n }\nend\n\nlemma C_mul : (C x) * a = smul x a := \n by {\n  ext n, induction n with n ih generalizing a, \n  {rw[mul_coeff_zero,C_coeff_zero,smul]},\n  {rw[mul_coeff_succ,ih,C_coeff_succ,_root_.zero_mul (a 0),zero_add,\u2190 shift_smul,shift_coeff],}\n }\n\nlemma zero_mul : (0 : power_series \u03b1) * a = 0 := \n by { rw[\u2190 C_zero,C_mul,zero_smul,C_zero],}\n\nlemma one_mul : (1 : power_series \u03b1) * a = a := \n by { rw[\u2190 C_one,C_mul,one_smul],}\n\nlemma mul_zero : a * (0 : power_series \u03b1) = 0 := \n by {\n  ext n, induction n with n ih generalizing a, \n  {rw[mul_coeff_zero,zero_coeff,mul_zero]},\n  {rw[mul_coeff_succ,shift_zero,ih,zero_coeff,zero_coeff,zero_coeff,mul_zero,zero_add],}\n }\n\nlemma mul_C : a * (C x) = rmul a x := \n by {\n  ext n, cases n, \n  {rw[mul_coeff_zero,C_coeff_zero,rmul]},\n  {rw[mul_coeff_succ,C_coeff_zero,shift_C,mul_zero,zero_coeff,add_zero,rmul],}\n }\n\nlemma mul_one : a * (1 : power_series \u03b1) = a := \n by { rw[\u2190 C_one,mul_C,rmul_one] }\n\nlemma add_mul : (a + b) * c = a * c + b * c := \n by {\n  ext n,induction n with n ih generalizing c,\n  {simp only [mul_coeff_zero,add_coeff,_root_.add_mul],},\n  {rw[add_coeff,mul_coeff_succ,mul_coeff_succ,mul_coeff_succ],\n   rw[ih c.shift,add_coeff,add_coeff,_root_.add_mul],\n   simp only[add_comm,add_left_comm],}\n }\n\nlemma mul_add : a * (b + c) = a * b + a * c := \n by {\n  ext n,induction n with n ih generalizing b c,\n  {simp only [mul_coeff_zero,add_coeff,_root_.mul_add],},\n  {rw[add_coeff,mul_coeff_succ,mul_coeff_succ,mul_coeff_succ],\n   rw[shift_add,ih b.shift c.shift,add_coeff,add_coeff,_root_.mul_add],\n   simp only[add_comm,add_left_comm],}\n }\n\nlemma shift_mul : shift (a * b) = smul (a 0) b.shift + (a.shift * b) := \n by {\n  ext n,rw[shift_coeff,mul_coeff_succ',add_coeff,smul_coeff,shift_coeff],\n }\n\nlemma smul_mul : (smul x a) * b = smul x (a * b) := \n by {\n  ext n,induction n with n ih generalizing b,\n  {simp only[mul_coeff_zero,smul_coeff,_root_.mul_assoc]},\n  {simp only[mul_coeff_succ,ih,smul_coeff,_root_.mul_add,_root_.mul_assoc],}\n }\n\nlemma mul_rmul : a * rmul b x = rmul (a * b) x := \n by {\n  ext n,induction n with n ih generalizing b,\n  {simp only[mul_coeff_zero,rmul_coeff,_root_.mul_assoc]},\n  {simp only[mul_coeff_succ,shift_rmul,ih,rmul_coeff,_root_.add_mul,_root_.mul_assoc],}\n }\n\nlemma mul_assoc : a * b * c = a * (b * c) := \nby {\n  ext n,\n  induction n with n ih generalizing a b c,\n  {repeat{rw[mul_coeff_zero]},rw[_root_.mul_assoc]},\n  {rw[mul_coeff_succ',mul_coeff_succ',mul_coeff_succ',shift_mul],\n   rw[add_mul,add_coeff,smul_mul,smul_coeff,ih,_root_.mul_add],\n   rw[mul_coeff_zero,mul_assoc,add_assoc],\n  }  \n}\n\nvariable (\u03b1)\n\ninstance : semiring (power_series \u03b1) := {\n  one := (1),\n  mul := (*),\n  one_mul := one_mul,\n  mul_one := mul_one,\n  mul_assoc := mul_assoc,\n  zero_mul := zero_mul,\n  mul_zero := mul_zero,\n  left_distrib := mul_add,\n  right_distrib := add_mul,\n  .. (power_series.add_comm_monoid \u03b1) \n }\n\nend semiring\n\nend power_series", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/data/power_series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7025886359784713}}
{"text": "/- Test cases for cooper, from John Harrison's Handbook of Practical Logic and Automated Reasoning. -/\n\nimport .main\n\nset_option profiler true\n\n/- Theorems -/\n\nopen tactic lia\n\nexample : \u2203 (x : int), x < 1 := \nby cooper\n\nexample : \u2200 (x : int), \u2203 (y : int), y = x + 1 := \nby cooper_vm\n\nexample : \u2200 (x : int), \u2203 (y : int), (2 * y \u2264 x \u2227 x < 2 * (y + 1)) := \nby cooper_vm\n\nexample : \u2200 (y : int), ((\u2203 (d : int), y = 2 * d) \u2192 (\u2203 (c : int), y = 1 * c)) := \nby cooper_vm\n\nexample : \u2200 (x y z : int), (2 * x + 1 = 2 * y) \u2192 129 < x + y + z :=\nby cooper_vm\n\nexample : \u2203 (x y : int), 5 * x + 3 * y = 1 := \nby cooper_vm \n\nexample : \u2203 (w x y z : int), 2 * w + 3 * x + 4 * y + 5 * z = 1 := \nby cooper_vm \n\nexample : \u2200 (x y : int), 6 * x = 5 * y \u2192 \u2203 d, y = 3 * d := \nby cooper_vm \n\nexample : \u2200 (x : int), (\u00ac(\u2203 m, x = 2 * m) \u2227 (\u2203 m, x = 3 * m + 1))\n             \u2194 ((\u2203 m, x = 12 * m + 1) \u2228 (\u2203 m, x = 12 * m + 7)) := \nby cooper_vm\n\n-- example : \u2203 (l : int), \u2200 (x : int), \n--   x \u2265 l \u2192 \u2203 (u v : int), u \u2265 0 \u2227 v \u2265 0 \u2227 x = 3 * u + 5 * v := \n-- by cooper_vm -- timeout\n\n/- Nontheorems -/\n\n--example : \u2203 (x y z : int), 4 * x - 6 * y = 1 := \n--by cooper_vm\n\n-- example : \u2200 (x y : int), x \u2264 y \u2192 ((2 * x) + 1) < 2 * y := \n-- by cooper_vm\n\n-- example : \u2200 (a b : int), \u2203 (x : int), a < 20 * x /\\ 20 * x < b := \n-- by cooper_vm \n\n-- example : \u2203 (y : int), \u2200 x, 2 \u2264 x + 5 * y \u2227 2 \u2264 13 * x - y \u2227 x + 3 \u2264 0 := \n-- by cooper_vm \n\n-- example : \u2200 (x y : int), \u00ac(x = 0) \u2192 5 * y + 1 \u2264 6 * x \u2228 6 * x + 1 \u2264 5 * y  := \n-- by cooper_vm \n\n--  example : \u2200 (z : int), 3 \u2264 z \u2192 \u2203 (x y : int), x \u2265 0 \u2227 y \u2265 0 \u2227 3 * x + 5 * y = z := \n--  by cooper_vm -- timeout\n\n-- example : \u2203 (a b : int), a \u2265 2 \u2227 b \u2265 2 \u2227 ((2 * b = a) \u2228 (2 * b = 3 * a + 1)) \u2227 (a = b) := \n-- by cooper_vm ", "meta": {"author": "avigad", "repo": "qelim", "sha": "b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60", "save_path": "github-repos/lean/avigad-qelim", "path": "github-repos/lean/avigad-qelim/qelim-b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60/lia/cooper/tests.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.754914997895581, "lm_q1q2_score": 0.70241689781136}}
{"text": "import tactic\nimport data.set data.set.finite data.finset data.fintype.basic\n\nstructure fin_simplicial_complex := mk ::\n(vertices : Type*)\n(de : decidable_eq vertices := by apply_instance)\n(ft : fintype vertices := by apply_instance)\n(simplices : finset (finset vertices))\n(nonempty : \u2200 {\u03c3 : (finset vertices)}, \u03c3 \u2208 simplices \u2192 finset.nonempty \u03c3)\n(singleton : \u2200 v : vertices, {v} \u2208 simplices)\n(downwards : \u2200 {\u03c3 \u03c4 : (finset vertices)}, \u03c3 \u2208 simplices \u2192 \u03c4 \u2286 \u03c3 \u2192 \u03c4.nonempty \u2192 \u03c4 \u2208 simplices)\n\nnamespace fin_simplicial_complex\n\nvariable {K : fin_simplicial_complex}\n\ninstance : decidable_eq K.vertices := K.de\ninstance : fintype K.vertices := K.ft\n\nlemma nonempty' : \u00ac ((\u2205 : finset K.vertices) \u2208 K.simplices) := \u03bb h, \n  finset.not_nonempty_empty (K.nonempty h)\n\ndef singleton_simplex (v : K.vertices) : K.simplices := \n  \u27e8{v}, K.singleton v\u27e9 \n\ndef empty : fin_simplicial_complex := {\n  vertices := empty,\n  de := by apply_instance,\n  ft := by apply_instance,\n  simplices := \u2205,\n  nonempty := \u03bb \u03c3 h, (set.not_mem_empty \u03c3 h).elim,\n  singleton := \u03bb v, empty.elim v,\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, (set.not_mem_empty \u03c3 h\u03c3).elim\n}\n\ndef singleton_emb (V : Type*) : V \u21aa finset V := {\n  to_fun := \u03bb v, {v},\n  inj' := \u03bb a b h, finset.singleton_inj.mp h,\n}\n\n#check tactic.hint\ndef discrete (V : Type*) [decidable_eq V] [fintype V] : fin_simplicial_complex := {\n  vertices := V,\n  de := by apply_instance,\n  ft := by apply_instance,\n  simplices := (finset.univ : finset V).map (singleton_emb V),\n  nonempty := \u03bb \u03c3 h, begin\n    rw[finset.mem_map] at h, rcases h with \u27e8v, v_in_univ, rfl\u27e9, \n    use v, exact finset.mem_singleton_self v\n  end,\n  singleton := \u03bb v, begin rw[finset.mem_map], exact \u27e8v, finset.mem_univ v,rfl\u27e9 end,\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, begin\n    rw[finset.mem_map] at h\u03c3 \u22a2,\n    rcases h\u03c3 with \u27e8v, v_in_univ, rfl\u27e9,\n    rcases finset.subset_singleton_iff.mp h\u03c4\u03c3 with (rfl|rfl),\n    { exfalso, exact finset.not_nonempty_empty h\u03c4 },\n    { exact \u27e8v, finset.mem_univ v, rfl\u27e9 }\n  end\n}\n\ndef indiscrete (V : Type*) [decidable_eq V] [fintype V] : fin_simplicial_complex := {\n  vertices := V,\n  de := by apply_instance,\n  ft := by apply_instance,\n  simplices := finset.univ.filter (\u03bb \u03c3, \u03c3 \u2260 \u2205),\n  nonempty := \u03bb \u03c3 h, by { rw[finset.mem_filter] at h, exact finset.nonempty_of_ne_empty h.2 },\n  singleton := \u03bb v, by { rw[finset.mem_filter, \u2190 finset.nonempty_iff_ne_empty], \n    exact \u27e8finset.mem_univ {v}, finset.singleton_nonempty v\u27e9 \n  },\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, by { \n    rw[finset.mem_filter], rw[finset.nonempty_iff_ne_empty] at h\u03c4,\n    exact \u27e8finset.mem_univ \u03c4, h\u03c4\u27e9 \n  }\n}\n\ndef indiscrete_simplex {V : Type*} [decidable_eq V] [fintype V]\n   {\u03c3 : finset V} (h : \u03c3 \u2260 \u2205) : simplices (indiscrete V) := \n\u27e8\u03c3, by { dsimp[indiscrete], rw[finset.mem_filter], exact \u27e8finset.mem_univ \u03c3, h\u27e9 }\u27e9 \n\ndef standard (n : \u2115) : fin_simplicial_complex := indiscrete (fin n.succ)\n\ndef standard_simplex {n : \u2115} \n   {\u03c3 : finset (fin n.succ)} (h : \u03c3 \u2260 \u2205 ): simplices (standard n) := \n  indiscrete_simplex h\n\ndef top_standard_simplex (n : \u2115) := \n  @standard_simplex n finset.univ (\u03bb h, by {\n    have h' := finset.mem_univ (0 : fin n.succ),\n    rw[h] at h', exact finset.not_mem_empty _ h'\n  })\n\ndef sphere (n : \u2115) : fin_simplicial_complex := {\n  vertices := fin (n + 2),\n  de := by apply_instance,\n  ft := by apply_instance,\n  simplices := finset.univ.filter (\u03bb \u03c3, \u03c3 \u2260 \u2205 \u2227 \u03c3 \u2260 finset.univ),\n  nonempty := \u03bb \u03c3 h, by { rw[finset.mem_filter] at h, exact finset.nonempty_of_ne_empty h.2.1 },\n  singleton := \u03bb v, by { rw[finset.mem_filter, \u2190 finset.nonempty_iff_ne_empty],\n    split, exact finset.mem_univ {v},\n    split, exact finset.singleton_nonempty v,\n    intro h,\n    by_cases h' : v = 0,\n    { have := finset.mem_univ (1 : fin (n + 2)), \n      rw[\u2190 h, h', finset.mem_singleton] at this,\n      cases this },\n    { have := finset.mem_univ (0 : fin (n + 2)), \n      rw[\u2190 h, finset.mem_singleton] at this,\n      exact h' (eq.symm this)\n    }\n  },\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, by { \n    rw[finset.mem_filter] at h\u03c3 \u22a2, rw[finset.nonempty_iff_ne_empty] at h\u03c4,\n    split, exact finset.mem_univ \u03c4,\n    split, exact h\u03c4,\n    rintro rfl, apply h\u03c3.2.2, \n    exact subset_antisymm (finset.subset_univ \u03c3) h\u03c4\u03c3\n  }  \n}\n\ndef of_generators {V : Type*} [decidable_eq V] [fintype V] \n  (S : finset (finset V)) : fin_simplicial_complex := {\n  vertices := V,\n  de := by apply_instance,\n  ft := by apply_instance,\n  simplices := finset.univ.filter (\u03bb \u03c3, \u03c3 \u2260 \u2205 \u2227 \n    (\u03c3.card \u2264 1 \u2228 \u2203 \u03c4, \u03c4 \u2208 S \u2227 \u03c3 \u2286 \u03c4)\n  ),\n  nonempty := \u03bb \u03c3 h, by { \n    rw[finset.mem_filter] at h, \n    exact finset.nonempty_of_ne_empty h.2.1 \n  },\n  singleton := \u03bb v, by {\n    rw[finset.mem_filter],\n    split, exact finset.mem_univ {v},\n    split, rw[\u2190 finset.nonempty_iff_ne_empty], exact finset.singleton_nonempty v,\n    left, exact le_refl _\n  },\n  downwards := \u03bb \u03c3 \u03c4 h\u03c3 h\u03c4\u03c3 h\u03c4, by { \n    rw[finset.mem_filter] at h\u03c3 \u22a2,\n    split, exact finset.mem_univ \u03c4,\n    split, rw[\u2190 finset.nonempty_iff_ne_empty], exact h\u03c4,\n    rcases h\u03c3 with \u27e8hu,hn,hc|\u27e8\u03c1,h\u03c1S,h\u03c3\u03c1\u27e9\u27e9,\n    { left, exact le_trans (finset.card_le_of_subset h\u03c4\u03c3) hc },\n    { right, exact \u27e8\u03c1, h\u03c1S, finset.subset.trans h\u03c4\u03c3 h\u03c3\u03c1\u27e9} \n  }\n}\n\ndef of_fin_generators (n : \u2115) (S : finset (finset (fin n))) : fin_simplicial_complex :=\n  of_generators S \n\ndef dim (\u03c3 : K.simplices) : \u2115 := (\u03c3 : finset K.vertices).card.pred\n\nlemma simplex_card (\u03c3 : K.simplices) : \n   (\u03c3 : finset K.vertices).card = fin_simplicial_complex.dim \u03c3 + 1 := \nbegin\n  rcases \u03c3 with \u27e8\u03c3, h\u03c3\u27e9,\n  symmetry,\n  apply nat.succ_pred_eq_of_pos, apply nat.pos_of_ne_zero,\n  change \u03c3.card \u2260 0,\n  intro h,\n  rw[finset.card_eq_zero.mp h] at h\u03c3,\n  exact fin_simplicial_complex.nonempty' h\u03c3\nend\n\n@[derive decidable]\ndef subdim (K : fin_simplicial_complex) (n : \u2115) := \n  \u2200 (\u03c3 : K.simplices), fin_simplicial_complex.dim \u03c3 \u2264 n\n\n@[derive decidable]\ndef supdim (K : fin_simplicial_complex) (n : \u2115) := \n  \u2203 (\u03c3 : K.simplices), fin_simplicial_complex.dim \u03c3 \u2265 n\n\n@[derive decidable]\ndef dimeq (K : fin_simplicial_complex) (n : \u2115) := \n  subdim K n \u2227 supdim K n\n\nlemma dim_standard (n : \u2115) : dimeq (standard n) n := \nbegin\n  split,\n  { rintro \u27e8\u03c3 : finset (fin n.succ),h\u03c3\u27e9, change \u03c3.card.pred \u2264 n,\n    have := finset.card_le_univ \u03c3,\n    rw[fintype.card_fin, \u2190 nat.pred_le_iff] at this,\n    exact this\n  }, {\n    use top_standard_simplex n,\n    change finset.univ.card.pred \u2265 n,\n    rw[finset.card_univ], \n    change (fintype.card (fin n.succ)).pred \u2265 n,\n    rw[fintype.card_fin, nat.pred_succ],\n    exact le_refl n\n  }\nend\n\nstructure hom (K L : fin_simplicial_complex) := mk ::\n(to_fun : K.vertices \u2192 L.vertices)\n(map_simplex : \u2200 {\u03c3 : finset K.vertices} (h : \u03c3 \u2208 K.simplices), \u03c3.image to_fun \u2208 L.simplices)\n\nnamespace hom \n\ndef to_fun' {K L : fin_simplicial_complex} (f : hom K L) : K.simplices \u2192 L.simplices := \n  \u03bb \u03c3, \u27e8(\u03c3 : finset K.vertices).image f.to_fun, f.map_simplex \u03c3.property\u27e9\n\ndef id (K : fin_simplicial_complex) : hom K K := {\n  to_fun := id,\n  map_simplex := \u03bb \u03c3 h, by { rw[finset.image_id], exact h }\n}\n\nlemma id' (K : fin_simplicial_complex) : (id K).to_fun' = (_root_.id : K.simplices \u2192 K.simplices) :=\nbegin\n  funext \u03c3, rcases \u03c3 with \u27e8\u03c3,h\u27e9, ext1,\n  change \u03c3.image _root_.id = \u03c3, rw[finset.image_id]\nend\n\ndef comp {K L M : fin_simplicial_complex} (g : hom L M) (f : hom K L) : hom K M := {\n  to_fun := g.to_fun \u2218 f.to_fun,\n  map_simplex := \u03bb \u03c3 h,\n  begin \n    rw[\u2190 finset.image_image],\n    exact g.map_simplex (f.map_simplex h)\n  end\n}\n\ndef comp' {K L M : fin_simplicial_complex} (g : hom L M) (f : hom K L) : \n  (comp g f).to_fun' = g.to_fun' \u2218 f.to_fun' := \nbegin\n  funext \u03c3, rcases \u03c3 with \u27e8\u03c3,h\u27e9, ext1,\n  rw[function.comp],\n  change \u03c3.image (g.to_fun \u2218 f.to_fun) = (\u03c3.image f.to_fun).image g.to_fun,\n  rw[finset.image_image]\nend\n\ndef const (K : fin_simplicial_complex) {L : fin_simplicial_complex} (w : L.vertices) : hom K L := {\n  to_fun := function.const K.vertices w,\n  map_simplex := \u03bb \u03c3 h, by {\n    rw[finset.image_const (K.nonempty h) w], exact L.singleton w\n  }\n}\n\nlemma const' (K : fin_simplicial_complex) {L : fin_simplicial_complex} (w : L.vertices) :\n  (const K w).to_fun' = function.const K.simplices (fin_simplicial_complex.singleton_simplex w) := \nbegin\n  funext \u03c3, rcases \u03c3 with \u27e8\u03c3, h\u27e9, ext1,\n  change \u03c3.image (function.const _ w) = {w},\n  rw[finset.image_const (K.nonempty h) w]\nend\n\nend hom\n\nnamespace examples\n\ndef cylinder := of_fin_generators 6 {\n  {0,1,4},{0,3,4},{1,2,5},{1,4,5},{2,3,0},{2,5,3}\n}\n\ndef mobius_strip := of_fin_generators 6 {\n  {0,1,4},{0,3,4},{1,2,5},{1,4,5},{2,3,0},{2,5,0}\n}\n\ndef octahedron := of_fin_generators 6 {\n  {0,1,4},{0,1,5},{0,3,4},{0,3,5},{1,2,4},{1,2,5},{2,3,4},{2,3,5}\n}\n\ndef torus := of_fin_generators 9 {\n  {0, 1, 4}, {0, 3, 4}, {1, 2, 5}, {1, 4, 5}, {2, 0, 3}, {2, 5, 3},\n  {3, 4, 7}, {3, 6, 7}, {4, 5, 8}, {4, 7, 8}, {5, 3, 6}, {5, 8, 6},\n  {6, 7, 1}, {6, 0, 1}, {7, 8, 2}, {7, 1, 2}, {8, 6, 0}, {8, 2, 0}\n}\n\ndef klein_bottle := of_fin_generators 9 {\n  {0, 1, 4}, {0, 3, 4}, {1, 2, 5}, {1, 4, 5}, {2, 0, 6}, {2, 5, 6},\n  {3, 4, 7}, {3, 6, 7}, {4, 5, 8}, {4, 7, 8}, {5, 3, 6}, {5, 8, 3},\n  {6, 7, 1}, {6, 0, 1}, {7, 8, 2}, {7, 1, 2}, {8, 3, 0}, {8, 2, 0}\n}\n\ndef projective_plane  := of_fin_generators 9 {\n  {0, 1, 5}, {0, 4, 5}, {1, 2, 6}, {1, 5, 6}, {2, 3, 6}, {3, 6, 7},\n  {4, 5, 8}, {4, 7, 8}, {5, 6, 9}, {5, 8, 9}, {6, 7, 4}, {6, 4, 9},\n  {7, 8, 2}, {7, 3, 2}, {8, 9, 1}, {8, 2, 1}, {9, 4, 0}, {9, 1, 0}\n}\n\nend examples\nend fin_simplicial_complex\n\n\n\n\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/exercises/loh/fin_simplicial_complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7024068287870829}}
{"text": "/-\nCopyright (c) 2019 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin, Floris van Doorn\n\n! This file was ported from Lean 3 source module data.set.mul_antidiagonal\n! leanprover-community/mathlib commit 0a0ec35061ed9960bf0e7ffb0335f44447b58977\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.WellFoundedSet\n\n/-! # Multiplication antidiagonal -/\n\n\nnamespace Set\n\nvariable {\u03b1 : Type _}\n\nsection Mul\n\nvariable [Mul \u03b1] {s s\u2081 s\u2082 t t\u2081 t\u2082 : Set \u03b1} {a : \u03b1} {x : \u03b1 \u00d7 \u03b1}\n\n/-- `Set.mulAntidiagonal s t a` is the set of all pairs of an element in `s` and an element in `t`\nthat multiply to `a`. -/\n@[to_additive\n      \"`Set.addAntidiagonal s t a` is the set of all pairs of an element in `s` and an\n      element in `t` that add to `a`.\"]\ndef mulAntidiagonal (s t : Set \u03b1) (a : \u03b1) : Set (\u03b1 \u00d7 \u03b1) :=\n  { x | x.1 \u2208 s \u2227 x.2 \u2208 t \u2227 x.1 * x.2 = a }\n#align set.mul_antidiagonal Set.mulAntidiagonal\n#align set.add_antidiagonal Set.addAntidiagonal\n\n@[to_additive (attr := simp)]\ntheorem mem_mulAntidiagonal : x \u2208 mulAntidiagonal s t a \u2194 x.1 \u2208 s \u2227 x.2 \u2208 t \u2227 x.1 * x.2 = a :=\n  Iff.rfl\n#align set.mem_mul_antidiagonal Set.mem_mulAntidiagonal\n#align set.mem_add_antidiagonal Set.mem_addAntidiagonal\n\n@[to_additive]\ntheorem mulAntidiagonal_mono_left (h : s\u2081 \u2286 s\u2082) : mulAntidiagonal s\u2081 t a \u2286 mulAntidiagonal s\u2082 t a :=\n  fun _ hx => \u27e8h hx.1, hx.2.1, hx.2.2\u27e9\n#align set.mul_antidiagonal_mono_left Set.mulAntidiagonal_mono_left\n#align set.add_antidiagonal_mono_left Set.addAntidiagonal_mono_left\n\n@[to_additive]\ntheorem mulAntidiagonal_mono_right (h : t\u2081 \u2286 t\u2082) :\n    mulAntidiagonal s t\u2081 a \u2286 mulAntidiagonal s t\u2082 a := fun _ hx => \u27e8hx.1, h hx.2.1, hx.2.2\u27e9\n#align set.mul_antidiagonal_mono_right Set.mulAntidiagonal_mono_right\n#align set.add_antidiagonal_mono_right Set.addAntidiagonal_mono_right\n\nend Mul\n\n-- Porting note: Removed simp attribute, simpnf linter can simplify lhs. Added aux version below\n@[to_additive]\ntheorem swap_mem_mulAntidiagonal [CommSemigroup \u03b1] {s t : Set \u03b1} {a : \u03b1} {x : \u03b1 \u00d7 \u03b1} :\n    x.swap \u2208 Set.mulAntidiagonal s t a \u2194 x \u2208 Set.mulAntidiagonal t s a := by\n  simp [mul_comm, and_left_comm]\n#align set.swap_mem_mul_antidiagonal Set.swap_mem_mulAntidiagonal\n#align set.swap_mem_add_antidiagonal Set.swap_mem_addAntidiagonal\n\n@[to_additive (attr := simp)]\ntheorem swap_mem_mulAntidiagonal_aux [CommSemigroup \u03b1] {s t : Set \u03b1} {a : \u03b1} {x : \u03b1 \u00d7 \u03b1} :\n     x.snd \u2208 s \u2227 x.fst \u2208 t \u2227 x.snd * x.fst = a\n      \u2194 x \u2208 Set.mulAntidiagonal t s a := by\n  simp [mul_comm, and_left_comm]\n\n\nnamespace MulAntidiagonal\n\nsection CancelCommMonoid\n\nvariable [CancelCommMonoid \u03b1] {s t : Set \u03b1} {a : \u03b1} {x y : mulAntidiagonal s t a}\n\n-- Porting note: to_additive cannot translate the \"Mul\" in \"MulAntidiagonal\" by itself here\n@[to_additive Set.AddAntidiagonal.fst_eq_fst_iff_snd_eq_snd]\ntheorem fst_eq_fst_iff_snd_eq_snd : (x : \u03b1 \u00d7 \u03b1).1 = (y : \u03b1 \u00d7 \u03b1).1 \u2194 (x : \u03b1 \u00d7 \u03b1).2 = (y : \u03b1 \u00d7 \u03b1).2 :=\n  \u27e8fun h =>\n    mul_left_cancel\n      (y.2.2.2.trans <| by\n          rw [\u2190 h]\n          exact x.2.2.2.symm).symm,\n    fun h =>\n    mul_right_cancel\n      (y.2.2.2.trans <| by\n          rw [\u2190 h]\n          exact x.2.2.2.symm).symm\u27e9\n#align set.mul_antidiagonal.fst_eq_fst_iff_snd_eq_snd Set.MulAntidiagonal.fst_eq_fst_iff_snd_eq_snd\n#align set.add_antidiagonal.fst_eq_fst_iff_snd_eq_snd Set.AddAntidiagonal.fst_eq_fst_iff_snd_eq_snd\n\n@[to_additive Set.AddAntidiagonal.eq_of_fst_eq_fst]\n\n\n@[to_additive Set.AddAntidiagonal.eq_of_snd_eq_snd]\ntheorem eq_of_snd_eq_snd (h : (x : \u03b1 \u00d7 \u03b1).snd = (y : \u03b1 \u00d7 \u03b1).snd) : x = y :=\n  Subtype.ext <| Prod.ext (fst_eq_fst_iff_snd_eq_snd.2 h) h\n#align set.mul_antidiagonal.eq_of_snd_eq_snd Set.MulAntidiagonal.eq_of_snd_eq_snd\n#align set.add_antidiagonal.eq_of_snd_eq_snd Set.AddAntidiagonal.eq_of_snd_eq_snd\n\nend CancelCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid \u03b1] (s t : Set \u03b1) (a : \u03b1) {x y : mulAntidiagonal s t a}\n\n@[to_additive Set.AddAntidiagonal.eq_of_fst_le_fst_of_snd_le_snd]\ntheorem eq_of_fst_le_fst_of_snd_le_snd (h\u2081 : (x : \u03b1 \u00d7 \u03b1).1 \u2264 (y : \u03b1 \u00d7 \u03b1).1)\n    (h\u2082 : (x : \u03b1 \u00d7 \u03b1).2 \u2264 (y : \u03b1 \u00d7 \u03b1).2) : x = y :=\n  eq_of_fst_eq_fst <|\n    h\u2081.eq_of_not_lt fun hlt =>\n      (mul_lt_mul_of_lt_of_le hlt h\u2082).ne <|\n        (mem_mulAntidiagonal.1 x.2).2.2.trans (mem_mulAntidiagonal.1 y.2).2.2.symm\n#align set.mul_antidiagonal.eq_of_fst_le_fst_of_snd_le_snd Set.MulAntidiagonal.eq_of_fst_le_fst_of_snd_le_snd\n#align set.add_antidiagonal.eq_of_fst_le_fst_of_snd_le_snd Set.AddAntidiagonal.eq_of_fst_le_fst_of_snd_le_snd\n\nvariable {s t}\n\n@[to_additive Set.AddAntidiagonal.finite_of_isPwo]\ntheorem finite_of_isPwo (hs : s.IsPwo) (ht : t.IsPwo) (a) : (mulAntidiagonal s t a).Finite := by\n  refine' not_infinite.1 fun h => _\n  have h1 : (mulAntidiagonal s t a).PartiallyWellOrderedOn (Prod.fst \u207b\u00b9'o (\u00b7 \u2264 \u00b7)) := fun f hf =>\n    hs (Prod.fst \u2218 f) fun n => (mem_mulAntidiagonal.1 (hf n)).1\n  have h2 : (mulAntidiagonal s t a).PartiallyWellOrderedOn (Prod.snd \u207b\u00b9'o (\u00b7 \u2264 \u00b7)) := fun f hf =>\n    ht (Prod.snd \u2218 f) fun n => (mem_mulAntidiagonal.1 (hf n)).2.1\n  obtain \u27e8g, hg\u27e9 :=\n    h1.exists_monotone_subseq (fun n => h.natEmbedding _ n) fun n => (h.natEmbedding _ n).2\n  obtain \u27e8m, n, mn, h2'\u27e9 := h2 (fun x => (h.natEmbedding _) (g x)) fun n => (h.natEmbedding _ _).2\n  refine' mn.ne (g.injective <| (h.natEmbedding _).injective _)\n  exact eq_of_fst_le_fst_of_snd_le_snd _ _ _ (hg _ _ mn.le) h2'\n#align set.mul_antidiagonal.finite_of_is_pwo Set.MulAntidiagonal.finite_of_isPwo\n#align set.add_antidiagonal.finite_of_is_pwo Set.AddAntidiagonal.finite_of_isPwo\n\nend OrderedCancelCommMonoid\n\n@[to_additive Set.AddAntidiagonal.finite_of_isWf]\ntheorem finite_of_isWf [LinearOrderedCancelCommMonoid \u03b1] {s t : Set \u03b1} (hs : s.IsWf) (ht : t.IsWf)\n    (a) : (mulAntidiagonal s t a).Finite :=\n  finite_of_isPwo hs.isPwo ht.isPwo a\n#align set.mul_antidiagonal.finite_of_is_wf Set.MulAntidiagonal.finite_of_isWf\n#align set.add_antidiagonal.finite_of_is_wf Set.AddAntidiagonal.finite_of_isWf\n\nend MulAntidiagonal\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Set/MulAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7024026569036846}}
{"text": "/-\nCopyright (c) 2020 Zhouhang Zhou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Zhouhang Zhou\n\n! This file was ported from Lean 3 source module data.set.intervals.unordered_interval\n! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.Bounds.Basic\nimport Mathbin.Data.Set.Intervals.Basic\n\n/-!\n# Intervals without endpoints ordering\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn any lattice `\u03b1`, we define `uIcc a b` to be `Icc (a \u2293 b) (a \u2294 b)`, which in a linear order is the\nset of elements lying between `a` and `b`.\n\n`Icc a b` requires the assumption `a \u2264 b` to be meaningful, which is sometimes inconvenient. The\ninterval as defined in this file is always the set of things lying between `a` and `b`, regardless\nof the relative order of `a` and `b`.\n\nFor real numbers, `uIcc a b` is the same as `segment \u211d a b`.\n\nIn a product or pi type, `uIcc a b` is the smallest box containing `a` and `b`. For example,\n`uIcc (1, -1) (-1, 1) = Icc (-1, -1) (1, 1)` is the square of vertices `(1, -1)`, `(-1, -1)`,\n`(-1, 1)`, `(1, 1)`.\n\nIn `finset \u03b1` (seen as a hypercube of dimension `fintype.card \u03b1`), `uIcc a b` is the smallest\nsubcube containing both `a` and `b`.\n\n## Notation\n\nWe use the localized notation `[a, b]` for `uIcc a b`. One can open the locale `interval` to\nmake the notation available.\n\n-/\n\n\nopen Function\n\nopen OrderDual (toDual ofDual)\n\nvariable {\u03b1 \u03b2 : Type _}\n\nnamespace Set\n\nsection Lattice\n\nvariable [Lattice \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c x : \u03b1}\n\n#print Set.uIcc /-\n/-- `uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included.\nNote that we define it more generally in a lattice as `set.Icc (a \u2293 b) (a \u2294 b)`. In a product type,\n`uIcc` corresponds to the bounding box of the two elements. -/\ndef uIcc (a b : \u03b1) : Set \u03b1 :=\n  Icc (a \u2293 b) (a \u2294 b)\n#align set.uIcc Set.uIcc\n-/\n\n-- mathport name: set.uIcc\nscoped[Interval] notation \"[\" a \", \" b \"]\" => Set.uIcc a b\n\n#print Set.dual_uIcc /-\n@[simp]\ntheorem dual_uIcc (a b : \u03b1) : [toDual a, toDual b] = ofDual \u207b\u00b9' [a, b] :=\n  dual_Icc\n#align set.dual_uIcc Set.dual_uIcc\n-/\n\n#print Set.uIcc_of_le /-\n@[simp]\ntheorem uIcc_of_le (h : a \u2264 b) : [a, b] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h]\n#align set.uIcc_of_le Set.uIcc_of_le\n-/\n\n#print Set.uIcc_of_ge /-\n@[simp]\ntheorem uIcc_of_ge (h : b \u2264 a) : [a, b] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h]\n#align set.uIcc_of_ge Set.uIcc_of_ge\n-/\n\n#print Set.uIcc_comm /-\ntheorem uIcc_comm (a b : \u03b1) : [a, b] = [b, a] := by simp_rw [uIcc, inf_comm, sup_comm]\n#align set.uIcc_comm Set.uIcc_comm\n-/\n\n#print Set.uIcc_of_lt /-\ntheorem uIcc_of_lt (h : a < b) : [a, b] = Icc a b :=\n  uIcc_of_le h.le\n#align set.uIcc_of_lt Set.uIcc_of_lt\n-/\n\n#print Set.uIcc_of_gt /-\ntheorem uIcc_of_gt (h : b < a) : [a, b] = Icc b a :=\n  uIcc_of_ge h.le\n#align set.uIcc_of_gt Set.uIcc_of_gt\n-/\n\n#print Set.uIcc_self /-\n@[simp]\ntheorem uIcc_self : [a, a] = {a} := by simp [uIcc]\n#align set.uIcc_self Set.uIcc_self\n-/\n\n#print Set.nonempty_uIcc /-\n@[simp]\ntheorem nonempty_uIcc : [a, b].Nonempty :=\n  nonempty_Icc.2 inf_le_sup\n#align set.nonempty_uIcc Set.nonempty_uIcc\n-/\n\n#print Set.Icc_subset_uIcc /-\ntheorem Icc_subset_uIcc : Icc a b \u2286 [a, b] :=\n  Icc_subset_Icc inf_le_left le_sup_right\n#align set.Icc_subset_uIcc Set.Icc_subset_uIcc\n-/\n\n#print Set.Icc_subset_uIcc' /-\ntheorem Icc_subset_uIcc' : Icc b a \u2286 [a, b] :=\n  Icc_subset_Icc inf_le_right le_sup_left\n#align set.Icc_subset_uIcc' Set.Icc_subset_uIcc'\n-/\n\n#print Set.left_mem_uIcc /-\n@[simp]\ntheorem left_mem_uIcc : a \u2208 [a, b] :=\n  \u27e8inf_le_left, le_sup_left\u27e9\n#align set.left_mem_uIcc Set.left_mem_uIcc\n-/\n\n#print Set.right_mem_uIcc /-\n@[simp]\ntheorem right_mem_uIcc : b \u2208 [a, b] :=\n  \u27e8inf_le_right, le_sup_right\u27e9\n#align set.right_mem_uIcc Set.right_mem_uIcc\n-/\n\n#print Set.mem_uIcc_of_le /-\ntheorem mem_uIcc_of_le (ha : a \u2264 x) (hb : x \u2264 b) : x \u2208 [a, b] :=\n  Icc_subset_uIcc \u27e8ha, hb\u27e9\n#align set.mem_uIcc_of_le Set.mem_uIcc_of_le\n-/\n\n#print Set.mem_uIcc_of_ge /-\ntheorem mem_uIcc_of_ge (hb : b \u2264 x) (ha : x \u2264 a) : x \u2208 [a, b] :=\n  Icc_subset_uIcc' \u27e8hb, ha\u27e9\n#align set.mem_uIcc_of_ge Set.mem_uIcc_of_ge\n-/\n\n#print Set.uIcc_subset_uIcc /-\ntheorem uIcc_subset_uIcc (h\u2081 : a\u2081 \u2208 [a\u2082, b\u2082]) (h\u2082 : b\u2081 \u2208 [a\u2082, b\u2082]) : [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] :=\n  Icc_subset_Icc (le_inf h\u2081.1 h\u2082.1) (sup_le h\u2081.2 h\u2082.2)\n#align set.uIcc_subset_uIcc Set.uIcc_subset_uIcc\n-/\n\n#print Set.uIcc_subset_Icc /-\ntheorem uIcc_subset_Icc (ha : a\u2081 \u2208 Icc a\u2082 b\u2082) (hb : b\u2081 \u2208 Icc a\u2082 b\u2082) : [a\u2081, b\u2081] \u2286 Icc a\u2082 b\u2082 :=\n  Icc_subset_Icc (le_inf ha.1 hb.1) (sup_le ha.2 hb.2)\n#align set.uIcc_subset_Icc Set.uIcc_subset_Icc\n-/\n\n#print Set.uIcc_subset_uIcc_iff_mem /-\ntheorem uIcc_subset_uIcc_iff_mem : [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] \u2194 a\u2081 \u2208 [a\u2082, b\u2082] \u2227 b\u2081 \u2208 [a\u2082, b\u2082] :=\n  Iff.intro (fun h => \u27e8h left_mem_uIcc, h right_mem_uIcc\u27e9) fun h => uIcc_subset_uIcc h.1 h.2\n#align set.uIcc_subset_uIcc_iff_mem Set.uIcc_subset_uIcc_iff_mem\n-/\n\n/- warning: set.uIcc_subset_uIcc_iff_le' -> Set.uIcc_subset_uIcc_iff_le' is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1}, Iff (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 _inst_1 a\u2081 b\u2081) (Set.uIcc.{u1} \u03b1 _inst_1 a\u2082 b\u2082)) (And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a\u2082 b\u2082) (Inf.inf.{u1} \u03b1 (SemilatticeInf.toHasInf.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)) a\u2081 b\u2081)) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a\u2081 b\u2081) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toHasSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a\u2082 b\u2082)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Lattice.{u1} \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1}, Iff (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 _inst_1 a\u2081 b\u2081) (Set.uIcc.{u1} \u03b1 _inst_1 a\u2082 b\u2082)) (And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a\u2082 b\u2082) (Inf.inf.{u1} \u03b1 (Lattice.toInf.{u1} \u03b1 _inst_1) a\u2081 b\u2081)) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 _inst_1)))) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a\u2081 b\u2081) (Sup.sup.{u1} \u03b1 (SemilatticeSup.toSup.{u1} \u03b1 (Lattice.toSemilatticeSup.{u1} \u03b1 _inst_1)) a\u2082 b\u2082)))\nCase conversion may be inaccurate. Consider using '#align set.uIcc_subset_uIcc_iff_le' Set.uIcc_subset_uIcc_iff_le'\u2093'. -/\ntheorem uIcc_subset_uIcc_iff_le' : [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] \u2194 a\u2082 \u2293 b\u2082 \u2264 a\u2081 \u2293 b\u2081 \u2227 a\u2081 \u2294 b\u2081 \u2264 a\u2082 \u2294 b\u2082 :=\n  Icc_subset_Icc_iff inf_le_sup\n#align set.uIcc_subset_uIcc_iff_le' Set.uIcc_subset_uIcc_iff_le'\n\n#print Set.uIcc_subset_uIcc_right /-\ntheorem uIcc_subset_uIcc_right (h : x \u2208 [a, b]) : [x, b] \u2286 [a, b] :=\n  uIcc_subset_uIcc h right_mem_uIcc\n#align set.uIcc_subset_uIcc_right Set.uIcc_subset_uIcc_right\n-/\n\n#print Set.uIcc_subset_uIcc_left /-\ntheorem uIcc_subset_uIcc_left (h : x \u2208 [a, b]) : [a, x] \u2286 [a, b] :=\n  uIcc_subset_uIcc left_mem_uIcc h\n#align set.uIcc_subset_uIcc_left Set.uIcc_subset_uIcc_left\n-/\n\n#print Set.bdd_below_bdd_above_iff_subset_uIcc /-\ntheorem bdd_below_bdd_above_iff_subset_uIcc (s : Set \u03b1) :\n    BddBelow s \u2227 BddAbove s \u2194 \u2203 a b, s \u2286 [a, b] :=\n  bddBelow_bddAbove_iff_subset_Icc.trans\n    \u27e8fun \u27e8a, b, h\u27e9 => \u27e8a, b, fun x hx => Icc_subset_uIcc (h hx)\u27e9, fun \u27e8a, b, h\u27e9 => \u27e8_, _, h\u27e9\u27e9\n#align set.bdd_below_bdd_above_iff_subset_uIcc Set.bdd_below_bdd_above_iff_subset_uIcc\n-/\n\nend Lattice\n\nopen Interval\n\nsection DistribLattice\n\nvariable [DistribLattice \u03b1] {a a\u2081 a\u2082 b b\u2081 b\u2082 c x : \u03b1}\n\n#print Set.eq_of_mem_uIcc_of_mem_uIcc /-\ntheorem eq_of_mem_uIcc_of_mem_uIcc (ha : a \u2208 [b, c]) (hb : b \u2208 [a, c]) : a = b :=\n  eq_of_inf_eq_sup_eq (inf_congr_right ha.1 hb.1) <| sup_congr_right ha.2 hb.2\n#align set.eq_of_mem_uIcc_of_mem_uIcc Set.eq_of_mem_uIcc_of_mem_uIcc\n-/\n\n#print Set.eq_of_mem_uIcc_of_mem_uIcc' /-\ntheorem eq_of_mem_uIcc_of_mem_uIcc' : b \u2208 [a, c] \u2192 c \u2208 [a, b] \u2192 b = c := by\n  simpa only [uIcc_comm a] using eq_of_mem_uIcc_of_mem_uIcc\n#align set.eq_of_mem_uIcc_of_mem_uIcc' Set.eq_of_mem_uIcc_of_mem_uIcc'\n-/\n\n#print Set.uIcc_injective_right /-\ntheorem uIcc_injective_right (a : \u03b1) : Injective fun b => uIcc b a := fun b c h =>\n  by\n  rw [ext_iff] at h\n  exact eq_of_mem_uIcc_of_mem_uIcc ((h _).1 left_mem_uIcc) ((h _).2 left_mem_uIcc)\n#align set.uIcc_injective_right Set.uIcc_injective_right\n-/\n\n#print Set.uIcc_injective_left /-\ntheorem uIcc_injective_left (a : \u03b1) : Injective (uIcc a) := by\n  simpa only [uIcc_comm] using uIcc_injective_right a\n#align set.uIcc_injective_left Set.uIcc_injective_left\n-/\n\nend DistribLattice\n\nsection LinearOrder\n\nvariable [LinearOrder \u03b1] [LinearOrder \u03b2] {f : \u03b1 \u2192 \u03b2} {s : Set \u03b1} {a a\u2081 a\u2082 b b\u2081 b\u2082 c d x : \u03b1}\n\n/- warning: set.Icc_min_max -> Set.Icc_min_max is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) (LinearOrder.min.{u1} \u03b1 _inst_1 a b) (LinearOrder.max.{u1} \u03b1 _inst_1 a b)) (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a b)\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) (Min.min.{u1} \u03b1 (LinearOrder.toMin.{u1} \u03b1 _inst_1) a b) (Max.max.{u1} \u03b1 (LinearOrder.toMax.{u1} \u03b1 _inst_1) a b)) (Set.uIcc.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)) a b)\nCase conversion may be inaccurate. Consider using '#align set.Icc_min_max Set.Icc_min_max\u2093'. -/\ntheorem Icc_min_max : Icc (min a b) (max a b) = [a, b] :=\n  rfl\n#align set.Icc_min_max Set.Icc_min_max\n\n#print Set.uIcc_of_not_le /-\ntheorem uIcc_of_not_le (h : \u00aca \u2264 b) : [a, b] = Icc b a :=\n  uIcc_of_gt <| lt_of_not_ge h\n#align set.uIcc_of_not_le Set.uIcc_of_not_le\n-/\n\n#print Set.uIcc_of_not_ge /-\ntheorem uIcc_of_not_ge (h : \u00acb \u2264 a) : [a, b] = Icc a b :=\n  uIcc_of_lt <| lt_of_not_ge h\n#align set.uIcc_of_not_ge Set.uIcc_of_not_ge\n-/\n\n/- warning: set.uIcc_eq_union -> Set.uIcc_eq_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a b) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) a b) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) b a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)) a b) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) a b) (Set.Icc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) b a))\nCase conversion may be inaccurate. Consider using '#align set.uIcc_eq_union Set.uIcc_eq_union\u2093'. -/\ntheorem uIcc_eq_union : [a, b] = Icc a b \u222a Icc b a := by rw [Icc_union_Icc', max_comm] <;> rfl\n#align set.uIcc_eq_union Set.uIcc_eq_union\n\n#print Set.mem_uIcc /-\ntheorem mem_uIcc : a \u2208 [b, c] \u2194 b \u2264 a \u2227 a \u2264 c \u2228 c \u2264 a \u2227 a \u2264 b := by simp [uIcc_eq_union]\n#align set.mem_uIcc Set.mem_uIcc\n-/\n\n#print Set.not_mem_uIcc_of_lt /-\ntheorem not_mem_uIcc_of_lt (ha : c < a) (hb : c < b) : c \u2209 [a, b] :=\n  not_mem_Icc_of_lt <| lt_min_iff.mpr \u27e8ha, hb\u27e9\n#align set.not_mem_uIcc_of_lt Set.not_mem_uIcc_of_lt\n-/\n\n#print Set.not_mem_uIcc_of_gt /-\ntheorem not_mem_uIcc_of_gt (ha : a < c) (hb : b < c) : c \u2209 [a, b] :=\n  not_mem_Icc_of_gt <| max_lt_iff.mpr \u27e8ha, hb\u27e9\n#align set.not_mem_uIcc_of_gt Set.not_mem_uIcc_of_gt\n-/\n\n/- warning: set.uIcc_subset_uIcc_iff_le -> Set.uIcc_subset_uIcc_iff_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1}, Iff (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a\u2081 b\u2081) (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a\u2082 b\u2082)) (And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) (LinearOrder.min.{u1} \u03b1 _inst_1 a\u2082 b\u2082) (LinearOrder.min.{u1} \u03b1 _inst_1 a\u2081 b\u2081)) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1))))) (LinearOrder.max.{u1} \u03b1 _inst_1 a\u2081 b\u2081) (LinearOrder.max.{u1} \u03b1 _inst_1 a\u2082 b\u2082)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a\u2081 : \u03b1} {a\u2082 : \u03b1} {b\u2081 : \u03b1} {b\u2082 : \u03b1}, Iff (HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)) a\u2081 b\u2081) (Set.uIcc.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)) a\u2082 b\u2082)) (And (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) (Min.min.{u1} \u03b1 (LinearOrder.toMin.{u1} \u03b1 _inst_1) a\u2082 b\u2082) (Min.min.{u1} \u03b1 (LinearOrder.toMin.{u1} \u03b1 _inst_1) a\u2081 b\u2081)) (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)))))) (Max.max.{u1} \u03b1 (LinearOrder.toMax.{u1} \u03b1 _inst_1) a\u2081 b\u2081) (Max.max.{u1} \u03b1 (LinearOrder.toMax.{u1} \u03b1 _inst_1) a\u2082 b\u2082)))\nCase conversion may be inaccurate. Consider using '#align set.uIcc_subset_uIcc_iff_le Set.uIcc_subset_uIcc_iff_le\u2093'. -/\ntheorem uIcc_subset_uIcc_iff_le :\n    [a\u2081, b\u2081] \u2286 [a\u2082, b\u2082] \u2194 min a\u2082 b\u2082 \u2264 min a\u2081 b\u2081 \u2227 max a\u2081 b\u2081 \u2264 max a\u2082 b\u2082 :=\n  uIcc_subset_uIcc_iff_le'\n#align set.uIcc_subset_uIcc_iff_le Set.uIcc_subset_uIcc_iff_le\n\n/- warning: set.uIcc_subset_uIcc_union_uIcc -> Set.uIcc_subset_uIcc_union_uIcc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1}, HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.hasSubset.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a c) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a b) (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) b c))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1} {c : \u03b1}, HasSubset.Subset.{u1} (Set.{u1} \u03b1) (Set.instHasSubsetSet.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)) a c) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (Set.uIcc.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)) a b) (Set.uIcc.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1)) b c))\nCase conversion may be inaccurate. Consider using '#align set.uIcc_subset_uIcc_union_uIcc Set.uIcc_subset_uIcc_union_uIcc\u2093'. -/\n/-- A sort of triangle inequality. -/\ntheorem uIcc_subset_uIcc_union_uIcc : [a, c] \u2286 [a, b] \u222a [b, c] := fun x => by\n  simp only [mem_uIcc, mem_union] <;> cases le_total a c <;> cases le_total x b <;> tauto\n#align set.uIcc_subset_uIcc_union_uIcc Set.uIcc_subset_uIcc_union_uIcc\n\n/- warning: set.monotone_or_antitone_iff_uIcc -> Set.monotone_or_antitone_iff_uIcc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : LinearOrder.{u1} \u03b1] [_inst_2 : LinearOrder.{u2} \u03b2] {f : \u03b1 -> \u03b2}, Iff (Or (Monotone.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (LinearOrder.toLattice.{u2} \u03b2 _inst_2)))) f) (Antitone.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (LinearOrder.toLattice.{u2} \u03b2 _inst_2)))) f)) (forall (a : \u03b1) (b : \u03b1) (c : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a b)) -> (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) (f c) (Set.uIcc.{u2} \u03b2 (LinearOrder.toLattice.{u2} \u03b2 _inst_2) (f a) (f b))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : LinearOrder.{u2} \u03b1] [_inst_2 : LinearOrder.{u1} \u03b2] {f : \u03b1 -> \u03b2}, Iff (Or (Monotone.{u2, u1} \u03b1 \u03b2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_1))))) (PartialOrder.toPreorder.{u1} \u03b2 (SemilatticeInf.toPartialOrder.{u1} \u03b2 (Lattice.toSemilatticeInf.{u1} \u03b2 (DistribLattice.toLattice.{u1} \u03b2 (instDistribLattice.{u1} \u03b2 _inst_2))))) f) (Antitone.{u2, u1} \u03b1 \u03b2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_1))))) (PartialOrder.toPreorder.{u1} \u03b2 (SemilatticeInf.toPartialOrder.{u1} \u03b2 (Lattice.toSemilatticeInf.{u1} \u03b2 (DistribLattice.toLattice.{u1} \u03b2 (instDistribLattice.{u1} \u03b2 _inst_2))))) f)) (forall (a : \u03b1) (b : \u03b1) (c : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) c (Set.uIcc.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_1)) a b)) -> (Membership.mem.{u1, u1} \u03b2 (Set.{u1} \u03b2) (Set.instMembershipSet.{u1} \u03b2) (f c) (Set.uIcc.{u1} \u03b2 (DistribLattice.toLattice.{u1} \u03b2 (instDistribLattice.{u1} \u03b2 _inst_2)) (f a) (f b))))\nCase conversion may be inaccurate. Consider using '#align set.monotone_or_antitone_iff_uIcc Set.monotone_or_antitone_iff_uIcc\u2093'. -/\ntheorem monotone_or_antitone_iff_uIcc :\n    Monotone f \u2228 Antitone f \u2194 \u2200 a b c, c \u2208 [a, b] \u2192 f c \u2208 [f a, f b] :=\n  by\n  constructor\n  \u00b7 rintro (hf | hf) a b c <;> simp_rw [\u2190 Icc_min_max, \u2190 hf.map_min, \u2190 hf.map_max]\n    exacts[fun hc => \u27e8hf hc.1, hf hc.2\u27e9, fun hc => \u27e8hf hc.2, hf hc.1\u27e9]\n  contrapose!\n  rw [not_monotone_not_antitone_iff_exists_le_le]\n  rintro \u27e8a, b, c, hab, hbc, \u27e8hfab, hfcb\u27e9 | \u27e8hfba, hfbc\u27e9\u27e9\n  \u00b7 exact \u27e8a, c, b, Icc_subset_uIcc \u27e8hab, hbc\u27e9, fun h => h.2.not_lt <| max_lt hfab hfcb\u27e9\n  \u00b7 exact \u27e8a, c, b, Icc_subset_uIcc \u27e8hab, hbc\u27e9, fun h => h.1.not_lt <| lt_min hfba hfbc\u27e9\n#align set.monotone_or_antitone_iff_uIcc Set.monotone_or_antitone_iff_uIcc\n\n/- warning: set.monotone_on_or_antitone_on_iff_uIcc -> Set.monotoneOn_or_antitoneOn_iff_uIcc is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {\u03b2 : Type.{u2}} [_inst_1 : LinearOrder.{u1} \u03b1] [_inst_2 : LinearOrder.{u2} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u1} \u03b1}, Iff (Or (MonotoneOn.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (LinearOrder.toLattice.{u2} \u03b2 _inst_2)))) f s) (AntitoneOn.{u1, u2} \u03b1 \u03b2 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) (PartialOrder.toPreorder.{u2} \u03b2 (SemilatticeInf.toPartialOrder.{u2} \u03b2 (Lattice.toSemilatticeInf.{u2} \u03b2 (LinearOrder.toLattice.{u2} \u03b2 _inst_2)))) f s)) (forall (a : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) a s) -> (forall (b : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) b s) -> (forall (c : \u03b1), (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c s) -> (Membership.Mem.{u1, u1} \u03b1 (Set.{u1} \u03b1) (Set.hasMem.{u1} \u03b1) c (Set.uIcc.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1) a b)) -> (Membership.Mem.{u2, u2} \u03b2 (Set.{u2} \u03b2) (Set.hasMem.{u2} \u03b2) (f c) (Set.uIcc.{u2} \u03b2 (LinearOrder.toLattice.{u2} \u03b2 _inst_2) (f a) (f b))))))\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} {\u03b2 : Type.{u1}} [_inst_1 : LinearOrder.{u2} \u03b1] [_inst_2 : LinearOrder.{u1} \u03b2] {f : \u03b1 -> \u03b2} {s : Set.{u2} \u03b1}, Iff (Or (MonotoneOn.{u2, u1} \u03b1 \u03b2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_1))))) (PartialOrder.toPreorder.{u1} \u03b2 (SemilatticeInf.toPartialOrder.{u1} \u03b2 (Lattice.toSemilatticeInf.{u1} \u03b2 (DistribLattice.toLattice.{u1} \u03b2 (instDistribLattice.{u1} \u03b2 _inst_2))))) f s) (AntitoneOn.{u2, u1} \u03b1 \u03b2 (PartialOrder.toPreorder.{u2} \u03b1 (SemilatticeInf.toPartialOrder.{u2} \u03b1 (Lattice.toSemilatticeInf.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_1))))) (PartialOrder.toPreorder.{u1} \u03b2 (SemilatticeInf.toPartialOrder.{u1} \u03b2 (Lattice.toSemilatticeInf.{u1} \u03b2 (DistribLattice.toLattice.{u1} \u03b2 (instDistribLattice.{u1} \u03b2 _inst_2))))) f s)) (forall (a : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) a s) -> (forall (b : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) b s) -> (forall (c : \u03b1), (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) c s) -> (Membership.mem.{u2, u2} \u03b1 (Set.{u2} \u03b1) (Set.instMembershipSet.{u2} \u03b1) c (Set.uIcc.{u2} \u03b1 (DistribLattice.toLattice.{u2} \u03b1 (instDistribLattice.{u2} \u03b1 _inst_1)) a b)) -> (Membership.mem.{u1, u1} \u03b2 (Set.{u1} \u03b2) (Set.instMembershipSet.{u1} \u03b2) (f c) (Set.uIcc.{u1} \u03b2 (DistribLattice.toLattice.{u1} \u03b2 (instDistribLattice.{u1} \u03b2 _inst_2)) (f a) (f b))))))\nCase conversion may be inaccurate. Consider using '#align set.monotone_on_or_antitone_on_iff_uIcc Set.monotoneOn_or_antitoneOn_iff_uIcc\u2093'. -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (a b c \u00abexpr \u2208 \u00bb s) -/\ntheorem monotoneOn_or_antitoneOn_iff_uIcc :\n    MonotoneOn f s \u2228 AntitoneOn f s \u2194\n      \u2200 (a) (_ : a \u2208 s) (b) (_ : b \u2208 s) (c) (_ : c \u2208 s), c \u2208 [a, b] \u2192 f c \u2208 [f a, f b] :=\n  by\n  simp [monotone_on_iff_monotone, antitone_on_iff_antitone, monotone_or_antitone_iff_uIcc, mem_uIcc]\n#align set.monotone_on_or_antitone_on_iff_uIcc Set.monotoneOn_or_antitoneOn_iff_uIcc\n\n#print Set.uIoc /-\n/-- The open-closed interval with unordered bounds. -/\ndef uIoc : \u03b1 \u2192 \u03b1 \u2192 Set \u03b1 := fun a b => Ioc (min a b) (max a b)\n#align set.uIoc Set.uIoc\n-/\n\n-- mathport name: expr\u0399\n-- Below is a capital iota\nscoped[Interval] notation \"\u0399\" => Set.uIoc\n\n#print Set.uIoc_of_le /-\n@[simp]\ntheorem uIoc_of_le (h : a \u2264 b) : \u0399 a b = Ioc a b := by simp [uIoc, h]\n#align set.uIoc_of_le Set.uIoc_of_le\n-/\n\n#print Set.uIoc_of_lt /-\n@[simp]\ntheorem uIoc_of_lt (h : b < a) : \u0399 a b = Ioc b a := by simp [uIoc, h.le]\n#align set.uIoc_of_lt Set.uIoc_of_lt\n-/\n\n/- warning: set.uIoc_eq_union -> Set.uIoc_eq_union is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (Set.uIoc.{u1} \u03b1 _inst_1 a b) (Union.union.{u1} (Set.{u1} \u03b1) (Set.hasUnion.{u1} \u03b1) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) a b) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (LinearOrder.toLattice.{u1} \u03b1 _inst_1)))) b a))\nbut is expected to have type\n  forall {\u03b1 : Type.{u1}} [_inst_1 : LinearOrder.{u1} \u03b1] {a : \u03b1} {b : \u03b1}, Eq.{succ u1} (Set.{u1} \u03b1) (Set.uIoc.{u1} \u03b1 _inst_1 a b) (Union.union.{u1} (Set.{u1} \u03b1) (Set.instUnionSet.{u1} \u03b1) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) a b) (Set.Ioc.{u1} \u03b1 (PartialOrder.toPreorder.{u1} \u03b1 (SemilatticeInf.toPartialOrder.{u1} \u03b1 (Lattice.toSemilatticeInf.{u1} \u03b1 (DistribLattice.toLattice.{u1} \u03b1 (instDistribLattice.{u1} \u03b1 _inst_1))))) b a))\nCase conversion may be inaccurate. Consider using '#align set.uIoc_eq_union Set.uIoc_eq_union\u2093'. -/\ntheorem uIoc_eq_union : \u0399 a b = Ioc a b \u222a Ioc b a := by cases le_total a b <;> simp [uIoc, *]\n#align set.uIoc_eq_union Set.uIoc_eq_union\n\n#print Set.mem_uIoc /-\ntheorem mem_uIoc : a \u2208 \u0399 b c \u2194 b < a \u2227 a \u2264 c \u2228 c < a \u2227 a \u2264 b := by\n  simp only [uIoc_eq_union, mem_union, mem_Ioc]\n#align set.mem_uIoc Set.mem_uIoc\n-/\n\n#print Set.not_mem_uIoc /-\ntheorem not_mem_uIoc : a \u2209 \u0399 b c \u2194 a \u2264 b \u2227 a \u2264 c \u2228 c < a \u2227 b < a :=\n  by\n  simp only [uIoc_eq_union, mem_union, mem_Ioc, not_lt, \u2190 not_le]\n  tauto\n#align set.not_mem_uIoc Set.not_mem_uIoc\n-/\n\n#print Set.left_mem_uIoc /-\n@[simp]\ntheorem left_mem_uIoc : a \u2208 \u0399 a b \u2194 b < a := by simp [mem_uIoc]\n#align set.left_mem_uIoc Set.left_mem_uIoc\n-/\n\n#print Set.right_mem_uIoc /-\n@[simp]\ntheorem right_mem_uIoc : b \u2208 \u0399 a b \u2194 a < b := by simp [mem_uIoc]\n#align set.right_mem_uIoc Set.right_mem_uIoc\n-/\n\n#print Set.forall_uIoc_iff /-\ntheorem forall_uIoc_iff {P : \u03b1 \u2192 Prop} :\n    (\u2200 x \u2208 \u0399 a b, P x) \u2194 (\u2200 x \u2208 Ioc a b, P x) \u2227 \u2200 x \u2208 Ioc b a, P x := by\n  simp only [uIoc_eq_union, mem_union, or_imp, forall_and]\n#align set.forall_uIoc_iff Set.forall_uIoc_iff\n-/\n\n#print Set.uIoc_subset_uIoc_of_uIcc_subset_uIcc /-\ntheorem uIoc_subset_uIoc_of_uIcc_subset_uIcc (h : [a, b] \u2286 [c, d]) : \u0399 a b \u2286 \u0399 c d :=\n  Ioc_subset_Ioc (uIcc_subset_uIcc_iff_le.1 h).1 (uIcc_subset_uIcc_iff_le.1 h).2\n#align set.uIoc_subset_uIoc_of_uIcc_subset_uIcc Set.uIoc_subset_uIoc_of_uIcc_subset_uIcc\n-/\n\ntheorem uIoc_swap (a b : \u03b1) : \u0399 a b = \u0399 b a := by simp only [uIoc, min_comm a b, max_comm a b]\n#align set.uIoc_swap Set.uIoc_swap\n\n#print Set.Ioc_subset_uIoc /-\ntheorem Ioc_subset_uIoc : Ioc a b \u2286 \u0399 a b :=\n  Ioc_subset_Ioc (min_le_left _ _) (le_max_right _ _)\n#align set.Ioc_subset_uIoc Set.Ioc_subset_uIoc\n-/\n\n#print Set.Ioc_subset_uIoc' /-\ntheorem Ioc_subset_uIoc' : Ioc a b \u2286 \u0399 b a :=\n  Ioc_subset_Ioc (min_le_right _ _) (le_max_left _ _)\n#align set.Ioc_subset_uIoc' Set.Ioc_subset_uIoc'\n-/\n\n#print Set.eq_of_mem_uIoc_of_mem_uIoc /-\ntheorem eq_of_mem_uIoc_of_mem_uIoc : a \u2208 \u0399 b c \u2192 b \u2208 \u0399 a c \u2192 a = b := by\n  simp_rw [mem_uIoc] <;> rintro (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) <;> apply le_antisymm <;>\n    first |assumption|exact le_of_lt \u2039_\u203a|exact le_trans \u2039_\u203a (le_of_lt \u2039_\u203a)\n#align set.eq_of_mem_uIoc_of_mem_uIoc Set.eq_of_mem_uIoc_of_mem_uIoc\n-/\n\n#print Set.eq_of_mem_uIoc_of_mem_uIoc' /-\ntheorem eq_of_mem_uIoc_of_mem_uIoc' : b \u2208 \u0399 a c \u2192 c \u2208 \u0399 a b \u2192 b = c := by\n  simpa only [uIoc_swap a] using eq_of_mem_uIoc_of_mem_uIoc\n#align set.eq_of_mem_uIoc_of_mem_uIoc' Set.eq_of_mem_uIoc_of_mem_uIoc'\n-/\n\n#print Set.eq_of_not_mem_uIoc_of_not_mem_uIoc /-\ntheorem eq_of_not_mem_uIoc_of_not_mem_uIoc (ha : a \u2264 c) (hb : b \u2264 c) :\n    a \u2209 \u0399 b c \u2192 b \u2209 \u0399 a c \u2192 a = b := by\n  simp_rw [not_mem_uIoc] <;> rintro (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) (\u27e8_, _\u27e9 | \u27e8_, _\u27e9) <;> apply le_antisymm <;>\n    first |assumption|exact le_of_lt \u2039_\u203a|cases not_le_of_lt \u2039_\u203a \u2039_\u203a\n#align set.eq_of_not_mem_uIoc_of_not_mem_uIoc Set.eq_of_not_mem_uIoc_of_not_mem_uIoc\n-/\n\n#print Set.uIoc_injective_right /-\ntheorem uIoc_injective_right (a : \u03b1) : Injective fun b => \u0399 b a :=\n  by\n  rintro b c h\n  rw [ext_iff] at h\n  obtain ha | ha := le_or_lt b a\n  \u00b7 have hb := (h b).Not\n    simp only [ha, left_mem_uIoc, not_lt, true_iff_iff, not_mem_uIoc, \u2190 not_le, and_true_iff,\n      not_true, false_and_iff, not_false_iff, true_iff_iff, or_false_iff] at hb\n    refine' hb.eq_of_not_lt fun hc => _\n    simpa [ha, and_iff_right hc, \u2190 @not_le _ _ _ a, -not_le] using h c\n  \u00b7 refine'\n      eq_of_mem_uIoc_of_mem_uIoc ((h _).1 <| left_mem_uIoc.2 ha)\n        ((h _).2 <| left_mem_uIoc.2 <| ha.trans_le _)\n    simpa [ha, ha.not_le, mem_uIoc] using h b\n#align set.uIoc_injective_right Set.uIoc_injective_right\n-/\n\n#print Set.uIoc_injective_left /-\ntheorem uIoc_injective_left (a : \u03b1) : Injective (\u0399 a) := by\n  simpa only [uIoc_swap] using uIoc_injective_right a\n#align set.uIoc_injective_left Set.uIoc_injective_left\n-/\n\nend LinearOrder\n\nend Set\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Set/Intervals/UnorderedInterval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7024026409435524}}
{"text": "/-\nCopyright (c) 2022 Violeta Hern\u00e1ndez Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hern\u00e1ndez Palacios\n-/\n\nimport set_theory.zfc.basic\n\n/-!\n# Von Neumann ordinals\n\nThis file works towards the development of von Neumann ordinals, i.e. transitive sets, well-ordered\nunder `\u2208`. We currently only have an initial development of transitive sets.\n\nFurther development can be found on the branch `von_neumann_v2`.\n\n## Definitions\n\n- `Set.is_transitive` means that every element of a set is a subset.\n\n## Todo\n\n- Define von Neumann ordinals.\n- Define the basic arithmetic operations on ordinals from a purely set-theoretic perspective.\n- Prove the equivalences between these definitions and those provided in\n  `set_theory/ordinal/arithmetic.lean`.\n-/\n\nuniverse u\n\nvariables {x y z : Set.{u}}\n\nnamespace Set\n\n/-- A transitive set is one where every element is a subset. -/\ndef is_transitive (x : Set) : Prop := \u2200 y \u2208 x, y \u2286 x\n\n@[simp] theorem empty_is_transitive : is_transitive \u2205 := \u03bb y hy, (not_mem_empty y hy).elim\n\ntheorem is_transitive.subset_of_mem (h : x.is_transitive) : y \u2208 x \u2192 y \u2286 x := h y\n\ntheorem is_transitive_iff_mem_trans : z.is_transitive \u2194 \u2200 {x y : Set}, x \u2208 y \u2192 y \u2208 z \u2192 x \u2208 z :=\n\u27e8\u03bb h x y hx hy, h.subset_of_mem hy hx, \u03bb H x hx y hy, H hy hx\u27e9\n\nalias is_transitive_iff_mem_trans \u2194 is_transitive.mem_trans _\n\nprotected theorem is_transitive.inter (hx : x.is_transitive) (hy : y.is_transitive) :\n  (x \u2229 y).is_transitive :=\n\u03bb z hz w hw, by { rw mem_inter at hz \u22a2, exact \u27e8hx.mem_trans hw hz.1, hy.mem_trans hw hz.2\u27e9 }\n\nprotected theorem is_transitive.sUnion (h : x.is_transitive) : (\u22c3\u2080 x).is_transitive :=\n\u03bb y hy z hz, begin\n  rcases mem_sUnion.1 hy with \u27e8w, hw, hw'\u27e9,\n  exact mem_sUnion_of_mem hz (h.mem_trans hw' hw)\nend\n\ntheorem is_transitive.sUnion' (H : \u2200 y \u2208 x, is_transitive y) : (\u22c3\u2080 x).is_transitive :=\n\u03bb y hy z hz, begin\n  rcases mem_sUnion.1 hy with \u27e8w, hw, hw'\u27e9,\n  exact mem_sUnion_of_mem ((H w hw).mem_trans hz hw') hw\nend\n\nprotected theorem is_transitive.union (hx : x.is_transitive) (hy : y.is_transitive) :\n  (x \u222a y).is_transitive :=\nbegin\n  rw \u2190sUnion_pair,\n  apply is_transitive.sUnion' (\u03bb z, _),\n  rw mem_pair,\n  rintro (rfl | rfl),\n  assumption'\nend\n\nprotected theorem is_transitive.powerset (h : x.is_transitive) : (powerset x).is_transitive :=\n\u03bb y hy z hz, by { rw mem_powerset at \u22a2 hy, exact h.subset_of_mem (hy hz) }\n\ntheorem is_transitive_iff_sUnion_subset : x.is_transitive \u2194 \u22c3\u2080 x \u2286 x :=\n\u27e8\u03bb h y hy, by { rcases mem_sUnion.1 hy with \u27e8z, hz, hz'\u27e9, exact h.mem_trans hz' hz },\n  \u03bb H y hy z hz, H $ mem_sUnion_of_mem hz hy\u27e9\n\nalias is_transitive_iff_sUnion_subset \u2194 is_transitive.sUnion_subset _\n\ntheorem is_transitive_iff_subset_powerset : x.is_transitive \u2194 x \u2286 powerset x :=\n\u27e8\u03bb h y hy, mem_powerset.2 $ h.subset_of_mem hy, \u03bb H y hy z hz, mem_powerset.1 (H hy) hz\u27e9\n\nalias is_transitive_iff_subset_powerset \u2194 is_transitive.subset_powerset _\n\nend Set\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/set_theory/zfc/ordinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7024026377335749}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport topology.metric_space.basic\nimport topology.metric_space.emetric_paracompact\nimport topology.shrinking_lemma\n\n/-!\n# Shrinking lemma in a proper metric space\n\nIn this file we prove a few versions of the shrinking lemma for coverings by balls in a proper\n(pseudo) metric space.\n\n## Tags\n\nshrinking lemma, metric space\n-/\n\nuniverses u v\nopen set metric\nopen_locale topological_space\n\nvariables {\u03b1 : Type u} {\u03b9 : Type v} [metric_space \u03b1] [proper_space \u03b1] {c : \u03b9 \u2192 \u03b1}\nvariables {x : \u03b1} {r : \u211d} {s : set \u03b1}\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a closed subset of a proper metric space by open balls can be shrunk to a new cover by open balls\nso that each of the new balls has strictly smaller radius than the old one. This version assumes\nthat `\u03bb x, ball (c i) (r i)` is a locally finite covering and provides a covering indexed by the\nsame type. -/\nlemma exists_subset_Union_ball_radius_lt {r : \u03b9 \u2192 \u211d} (hs : is_closed s)\n  (uf : \u2200 x \u2208 s, finite {i | x \u2208 ball (c i) (r i)}) (us : s \u2286 \u22c3 i, ball (c i) (r i)) :\n  \u2203 r' : \u03b9 \u2192 \u211d, s \u2286 (\u22c3 i, ball (c i) (r' i)) \u2227 \u2200 i, r' i < r i :=\nbegin\n  rcases exists_subset_Union_closed_subset hs (\u03bb i, @is_open_ball _ _ (c i) (r i)) uf us\n    with \u27e8v, hsv, hvc, hcv\u27e9,\n  have := \u03bb i, exists_lt_subset_ball (hvc i) (hcv i),\n  choose r' hlt hsub,\n  exact \u27e8r', hsv.trans $ Union_mono $ hsub, hlt\u27e9\nend\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a proper metric space by open balls can be shrunk to a new cover by open balls so that each of\nthe new balls has strictly smaller radius than the old one. -/\nlemma exists_Union_ball_eq_radius_lt {r : \u03b9 \u2192 \u211d} (uf : \u2200 x, finite {i | x \u2208 ball (c i) (r i)})\n  (uU : (\u22c3 i, ball (c i) (r i)) = univ) :\n  \u2203 r' : \u03b9 \u2192 \u211d, (\u22c3 i, ball (c i) (r' i)) = univ \u2227 \u2200 i, r' i < r i :=\nlet \u27e8r', hU, hv\u27e9 := exists_subset_Union_ball_radius_lt is_closed_univ (\u03bb x _, uf x) uU.ge\nin \u27e8r', univ_subset_iff.1 hU, hv\u27e9\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a closed subset of a proper metric space by nonempty open balls can be shrunk to a new cover by\nnonempty open balls so that each of the new balls has strictly smaller radius than the old one. -/\nlemma exists_subset_Union_ball_radius_pos_lt {r : \u03b9 \u2192 \u211d} (hr : \u2200 i, 0 < r i) (hs : is_closed s)\n  (uf : \u2200 x \u2208 s, finite {i | x \u2208 ball (c i) (r i)}) (us : s \u2286 \u22c3 i, ball (c i) (r i)) :\n  \u2203 r' : \u03b9 \u2192 \u211d, s \u2286 (\u22c3 i, ball (c i) (r' i)) \u2227 \u2200 i, r' i \u2208 Ioo 0 (r i) :=\nbegin\n  rcases exists_subset_Union_closed_subset hs (\u03bb i, @is_open_ball _ _ (c i) (r i)) uf us\n    with \u27e8v, hsv, hvc, hcv\u27e9,\n  have := \u03bb i, exists_pos_lt_subset_ball (hr i) (hvc i) (hcv i),\n  choose r' hlt hsub,\n  exact \u27e8r', hsv.trans $ Union_mono hsub, hlt\u27e9\nend\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a proper metric space by nonempty open balls can be shrunk to a new cover by nonempty open balls\nso that each of the new balls has strictly smaller radius than the old one. -/\nlemma exists_Union_ball_eq_radius_pos_lt {r : \u03b9 \u2192 \u211d} (hr : \u2200 i, 0 < r i)\n  (uf : \u2200 x, finite {i | x \u2208 ball (c i) (r i)}) (uU : (\u22c3 i, ball (c i) (r i)) = univ) :\n  \u2203 r' : \u03b9 \u2192 \u211d, (\u22c3 i, ball (c i) (r' i)) = univ \u2227 \u2200 i, r' i \u2208 Ioo 0 (r i) :=\nlet \u27e8r', hU, hv\u27e9 := exists_subset_Union_ball_radius_pos_lt hr is_closed_univ (\u03bb x _, uf x) uU.ge\nin \u27e8r', univ_subset_iff.1 hU, hv\u27e9\n\n/-- Let `R : \u03b1 \u2192 \u211d` be a (possibly discontinuous) function on a proper metric space.\nLet `s` be a closed set in `\u03b1` such that `R` is positive on `s`. Then there exists a collection of\npairs of balls `metric.ball (c i) (r i)`, `metric.ball (c i) (r' i)` such that\n\n* all centers belong to `s`;\n* for all `i` we have `0 < r i < r' i < R (c i)`;\n* the family of balls `metric.ball (c i) (r' i)` is locally finite;\n* the balls `metric.ball (c i) (r i)` cover `s`.\n\nThis is a simple corollary of `refinement_of_locally_compact_sigma_compact_of_nhds_basis_set`\nand `exists_subset_Union_ball_radius_pos_lt`. -/\nlemma exists_locally_finite_subset_Union_ball_radius_lt (hs : is_closed s)\n  {R : \u03b1 \u2192 \u211d} (hR : \u2200 x \u2208 s, 0 < R x) :\n  \u2203 (\u03b9 : Type u) (c : \u03b9 \u2192 \u03b1) (r r' : \u03b9 \u2192 \u211d),\n    (\u2200 i, c i \u2208 s \u2227 0 < r i \u2227 r i < r' i \u2227 r' i < R (c i)) \u2227\n    locally_finite (\u03bb i, ball (c i) (r' i)) \u2227 s \u2286 \u22c3 i, ball (c i) (r i) :=\nbegin\n  have : \u2200 x \u2208 s, (\ud835\udcdd x).has_basis (\u03bb r : \u211d, 0 < r \u2227 r < R x) (\u03bb r, ball x r),\n    from \u03bb x hx, nhds_basis_uniformity (uniformity_basis_dist_lt (hR x hx)),\n  rcases refinement_of_locally_compact_sigma_compact_of_nhds_basis_set hs this\n    with \u27e8\u03b9, c, r', hr', hsub', hfin\u27e9,\n  rcases exists_subset_Union_ball_radius_pos_lt (\u03bb i, (hr' i).2.1) hs\n    (\u03bb x hx, hfin.point_finite x) hsub' with \u27e8r, hsub, hlt\u27e9,\n  exact \u27e8\u03b9, c, r, r', \u03bb i, \u27e8(hr' i).1, (hlt i).1, (hlt i).2, (hr' i).2.2\u27e9, hfin, hsub\u27e9\nend\n\n/-- Let `R : \u03b1 \u2192 \u211d` be a (possibly discontinuous) positive function on a proper metric space. Then\nthere exists a collection of pairs of balls `metric.ball (c i) (r i)`, `metric.ball (c i) (r' i)`\nsuch that\n\n* for all `i` we have `0 < r i < r' i < R (c i)`;\n* the family of balls `metric.ball (c i) (r' i)` is locally finite;\n* the balls `metric.ball (c i) (r i)` cover the whole space.\n\nThis is a simple corollary of `refinement_of_locally_compact_sigma_compact_of_nhds_basis`\nand `exists_Union_ball_eq_radius_pos_lt` or `exists_locally_finite_subset_Union_ball_radius_lt`. -/\nlemma exists_locally_finite_Union_eq_ball_radius_lt {R : \u03b1 \u2192 \u211d} (hR : \u2200 x, 0 < R x) :\n  \u2203 (\u03b9 : Type u) (c : \u03b9 \u2192 \u03b1) (r r' : \u03b9 \u2192 \u211d), (\u2200 i, 0 < r i \u2227 r i < r' i \u2227 r' i < R (c i)) \u2227\n    locally_finite (\u03bb i, ball (c i) (r' i)) \u2227 (\u22c3 i, ball (c i) (r i)) = univ :=\nlet \u27e8\u03b9, c, r, r', hlt, hfin, hsub\u27e9 := exists_locally_finite_subset_Union_ball_radius_lt\n  is_closed_univ (\u03bb x _, hR x)\nin \u27e8\u03b9, c, r, r', \u03bb i, (hlt i).2, hfin, univ_subset_iff.1 hsub\u27e9\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/topology/metric_space/shrinking_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7023996037257578}}
{"text": "/-\nCopyright (c) 2022 Moritz Doll. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Moritz Doll\n-/\n\nimport analysis.calculus.cont_diff\nimport analysis.locally_convex.with_seminorms\nimport topology.algebra.uniform_filter_basis\nimport topology.continuous_function.bounded\nimport tactic.positivity\nimport analysis.special_functions.pow\n\n/-!\n# Schwartz space\n\nThis file defines the Schwartz space. Usually, the Schwartz space is defined as the set of smooth\nfunctions $f : \u211d^n \u2192 \u2102$ such that there exists $C_{\u03b1\u03b2} > 0$ with $$|x^\u03b1 \u2202^\u03b2 f(x)| < C_{\u03b1\u03b2}$$ for\nall $x \u2208 \u211d^n$ and for all multiindices $\u03b1, \u03b2$.\nIn mathlib, we use a slightly different approach and define define the Schwartz space as all\nsmooth functions `f : E \u2192 F`, where `E` and `F` are real normed vector spaces such that for all\nnatural numbers `k` and `n` we have uniform bounds `\u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016 < C`.\nThis approach completely avoids using partial derivatives as well as polynomials.\nWe construct the topology on the Schwartz space by a family of seminorms, which are the best\nconstants in the above estimates, which is by abstract theory from\n`seminorm_family.module_filter_basis` and `with_seminorms.to_locally_convex_space` turns the\nSchwartz space into a locally convex topological vector space.\n\n## Main definitions\n\n* `schwartz_map`: The Schwartz space is the space of smooth functions such that all derivatives\ndecay faster than any power of `\u2016x\u2016`.\n* `schwartz_map.seminorm`: The family of seminorms as described above\n* `schwartz_map.fderiv_clm`: The differential as a continuous linear map\n`\ud835\udce2(E, F) \u2192L[\ud835\udd5c] \ud835\udce2(E, E \u2192L[\u211d] F)`\n\n## Main statements\n\n* `schwartz_map.uniform_add_group` and `schwartz_map.locally_convex`: The Schwartz space is a\nlocally convex topological vector space.\n\n## Implementation details\n\nThe implementation of the seminorms is taken almost literally from `continuous_linear_map.op_norm`.\n\n## Notation\n\n* `\ud835\udce2(E, F)`: The Schwartz space `schwartz_map E F` localized in `schwartz_space`\n\n## Tags\n\nSchwartz space, tempered distributions\n-/\n\nnoncomputable theory\n\nvariables {\ud835\udd5c \ud835\udd5c' E F : Type*}\n\nvariables [normed_add_comm_group E] [normed_space \u211d E]\nvariables [normed_add_comm_group F] [normed_space \u211d F]\n\nvariables (E F)\n\n/-- A function is a Schwartz function if it is smooth and all derivatives decay faster than\n  any power of `\u2016x\u2016`. -/\nstructure schwartz_map :=\n  (to_fun : E \u2192 F)\n  (smooth' : cont_diff \u211d \u22a4 to_fun)\n  (decay' : \u2200 (k n : \u2115), \u2203 (C : \u211d), \u2200 x, \u2016x\u2016^k * \u2016iterated_fderiv \u211d n to_fun x\u2016 \u2264 C)\n\nlocalized \"notation `\ud835\udce2(` E `, ` F `)` := schwartz_map E F\" in schwartz_space\n\nvariables {E F}\n\nnamespace schwartz_map\n\ninstance : has_coe \ud835\udce2(E, F) (E \u2192 F) := \u27e8to_fun\u27e9\n\ninstance fun_like : fun_like \ud835\udce2(E, F) E (\u03bb _, F) :=\n{ coe := \u03bb f, f.to_fun,\n  coe_injective' := \u03bb f g h, by cases f; cases g; congr' }\n\n/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`. -/\ninstance : has_coe_to_fun \ud835\udce2(E, F) (\u03bb _, E \u2192 F) := \u27e8\u03bb p, p.to_fun\u27e9\n\n/-- All derivatives of a Schwartz function are rapidly decaying. -/\nlemma decay (f : \ud835\udce2(E, F)) (k n : \u2115) : \u2203 (C : \u211d) (hC : 0 < C),\n  \u2200 x, \u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016 \u2264 C :=\nbegin\n  rcases f.decay' k n with \u27e8C, hC\u27e9,\n  exact \u27e8max C 1, by positivity, \u03bb x, (hC x).trans (le_max_left _ _)\u27e9,\nend\n\n/-- Every Schwartz function is smooth. -/\nlemma smooth (f : \ud835\udce2(E, F)) (n : \u2115\u221e) : cont_diff \u211d n f := f.smooth'.of_le le_top\n\n/-- Every Schwartz function is continuous. -/\n@[continuity, protected] lemma continuous (f : \ud835\udce2(E, F)) : continuous f := (f.smooth 0).continuous\n\n/-- Every Schwartz function is differentiable. -/\n@[protected] lemma differentiable (f : \ud835\udce2(E, F)) : differentiable \u211d f :=\n(f.smooth 1).differentiable rfl.le\n\n@[ext] lemma ext {f g : \ud835\udce2(E, F)} (h : \u2200 x, (f : E \u2192 F) x = g x) : f = g := fun_like.ext f g h\n\nsection is_O\n\nvariables (f : \ud835\udce2(E, F))\n\n/-- Auxiliary lemma, used in proving the more general result `is_O_cocompact_zpow`. -/\nlemma is_O_cocompact_zpow_neg_nat (k : \u2115) :\n  asymptotics.is_O (filter.cocompact E) f (\u03bb x, \u2016x\u2016 ^ (-k : \u2124)) :=\nbegin\n  obtain \u27e8d, hd, hd'\u27e9 := f.decay k 0,\n  simp_rw norm_iterated_fderiv_zero at hd',\n  simp_rw [asymptotics.is_O, asymptotics.is_O_with],\n  refine \u27e8d, filter.eventually.filter_mono filter.cocompact_le_cofinite _\u27e9,\n  refine (filter.eventually_cofinite_ne 0).mp (filter.eventually_of_forall (\u03bb x hx, _)),\n  rwa [real.norm_of_nonneg (zpow_nonneg (norm_nonneg _) _), zpow_neg, \u2190div_eq_mul_inv, le_div_iff'],\n  exacts [hd' x, zpow_pos_of_pos (norm_pos_iff.mpr hx) _],\nend\n\nlemma is_O_cocompact_rpow [proper_space E] (s : \u211d) :\n  asymptotics.is_O (filter.cocompact E) f (\u03bb x, \u2016x\u2016 ^ s) :=\nbegin\n  let k := \u2308-s\u2309\u208a,\n  have hk : -(k : \u211d) \u2264 s, from neg_le.mp (nat.le_ceil (-s)),\n  refine (is_O_cocompact_zpow_neg_nat f k).trans _,\n  refine (_ : asymptotics.is_O filter.at_top\n    (\u03bb x:\u211d, x ^ (-k : \u2124)) (\u03bb x:\u211d, x ^ s)).comp_tendsto tendsto_norm_cocompact_at_top,\n  simp_rw [asymptotics.is_O, asymptotics.is_O_with],\n  refine \u27e81, filter.eventually_of_mem (filter.eventually_ge_at_top 1) (\u03bb x hx, _)\u27e9,\n  rw [one_mul, real.norm_of_nonneg (real.rpow_nonneg_of_nonneg (zero_le_one.trans hx) _),\n    real.norm_of_nonneg (zpow_nonneg (zero_le_one.trans hx) _), \u2190real.rpow_int_cast, int.cast_neg,\n    int.cast_coe_nat],\n  exact real.rpow_le_rpow_of_exponent_le hx hk,\nend\n\nlemma is_O_cocompact_zpow [proper_space E] (k : \u2124) :\n  asymptotics.is_O (filter.cocompact E) f (\u03bb x, \u2016x\u2016 ^ k) :=\nby simpa only [real.rpow_int_cast] using is_O_cocompact_rpow f k\n\nend is_O\n\nsection aux\n\nlemma bounds_nonempty (k n : \u2115) (f : \ud835\udce2(E, F)) :\n  \u2203 (c : \u211d), c \u2208 {c : \u211d | 0 \u2264 c \u2227 \u2200 (x : E), \u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016 \u2264 c} :=\nlet \u27e8M, hMp, hMb\u27e9 := f.decay k n in \u27e8M, le_of_lt hMp, hMb\u27e9\n\nlemma bounds_bdd_below (k n : \u2115) (f : \ud835\udce2(E, F)) :\n  bdd_below {c | 0 \u2264 c \u2227 \u2200 x, \u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016 \u2264 c} :=\n\u27e80, \u03bb _ \u27e8hn, _\u27e9, hn\u27e9\n\nlemma decay_add_le_aux (k n : \u2115) (f g : \ud835\udce2(E, F)) (x : E) :\n  \u2016x\u2016^k * \u2016iterated_fderiv \u211d n (f+g) x\u2016 \u2264\n  \u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016\n  + \u2016x\u2016^k * \u2016iterated_fderiv \u211d n g x\u2016 :=\nbegin\n  rw \u2190mul_add,\n  refine mul_le_mul_of_nonneg_left _ (by positivity),\n  convert norm_add_le _ _,\n  exact iterated_fderiv_add_apply (f.smooth _) (g.smooth _),\nend\n\nlemma decay_neg_aux (k n : \u2115) (f : \ud835\udce2(E, F)) (x : E) :\n  \u2016x\u2016 ^ k * \u2016iterated_fderiv \u211d n (-f) x\u2016 = \u2016x\u2016 ^ k * \u2016iterated_fderiv \u211d n f x\u2016 :=\nbegin\n  nth_rewrite 3 \u2190norm_neg,\n  congr,\n  exact iterated_fderiv_neg_apply,\nend\n\nvariables [normed_field \ud835\udd5c] [normed_space \ud835\udd5c F] [smul_comm_class \u211d \ud835\udd5c F]\n\nlemma decay_smul_aux (k n : \u2115) (f : \ud835\udce2(E, F)) (c : \ud835\udd5c) (x : E) :\n  \u2016x\u2016 ^ k * \u2016iterated_fderiv \u211d n (c \u2022 f) x\u2016 =\n  \u2016c\u2016 * \u2016x\u2016 ^ k * \u2016iterated_fderiv \u211d n f x\u2016 :=\nby rw [mul_comm (\u2016c\u2016), mul_assoc, iterated_fderiv_const_smul_apply (f.smooth _), norm_smul]\n\nend aux\n\nsection seminorm_aux\n\n/-- Helper definition for the seminorms of the Schwartz space. -/\n@[protected]\ndef seminorm_aux (k n : \u2115) (f : \ud835\udce2(E, F)) : \u211d :=\nInf {c | 0 \u2264 c \u2227 \u2200 x, \u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016 \u2264 c}\n\nlemma seminorm_aux_nonneg (k n : \u2115) (f : \ud835\udce2(E, F)) : 0 \u2264 f.seminorm_aux k n :=\nle_cInf (bounds_nonempty k n f) (\u03bb _ \u27e8hx, _\u27e9, hx)\n\n\n\n/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/\nlemma seminorm_aux_le_bound (k n : \u2115) (f : \ud835\udce2(E, F)) {M : \u211d} (hMp: 0 \u2264 M)\n  (hM : \u2200 x, \u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016 \u2264 M) :\n  f.seminorm_aux k n \u2264 M :=\ncInf_le (bounds_bdd_below k n f) \u27e8hMp, hM\u27e9\n\nend seminorm_aux\n\n/-! ### Algebraic properties -/\n\nsection smul\n\nvariables [normed_field \ud835\udd5c] [normed_space \ud835\udd5c F] [smul_comm_class \u211d \ud835\udd5c F]\n  [normed_field \ud835\udd5c'] [normed_space \ud835\udd5c' F] [smul_comm_class \u211d \ud835\udd5c' F]\n\ninstance : has_smul \ud835\udd5c \ud835\udce2(E, F) :=\n\u27e8\u03bb c f, { to_fun := c \u2022 f,\n  smooth' := (f.smooth _).const_smul c,\n  decay' := \u03bb k n, begin\n    refine \u27e8f.seminorm_aux k n * (\u2016c\u2016+1), \u03bb x, _\u27e9,\n    have hc : 0 \u2264 \u2016c\u2016 := by positivity,\n    refine le_trans _ ((mul_le_mul_of_nonneg_right (f.le_seminorm_aux k n x) hc).trans _),\n    { apply eq.le,\n      rw [mul_comm _ (\u2016c\u2016), \u2190 mul_assoc],\n      exact decay_smul_aux k n f c x },\n    { apply mul_le_mul_of_nonneg_left _ (f.seminorm_aux_nonneg k n),\n      linarith }\n  end}\u27e9\n\n@[simp] lemma smul_apply {f : \ud835\udce2(E, F)} {c : \ud835\udd5c} {x : E} : (c \u2022 f) x = c \u2022 (f x) := rfl\n\ninstance\n[has_smul \ud835\udd5c \ud835\udd5c'] [is_scalar_tower \ud835\udd5c \ud835\udd5c' F] : is_scalar_tower \ud835\udd5c \ud835\udd5c' \ud835\udce2(E, F) :=\n\u27e8\u03bb a b f, ext $ \u03bb x, smul_assoc a b (f x)\u27e9\n\ninstance [smul_comm_class \ud835\udd5c \ud835\udd5c' F] : smul_comm_class \ud835\udd5c \ud835\udd5c' \ud835\udce2(E, F) :=\n\u27e8\u03bb a b f, ext $ \u03bb x, smul_comm a b (f x)\u27e9\n\nlemma seminorm_aux_smul_le (k n : \u2115) (c : \ud835\udd5c) (f : \ud835\udce2(E, F)) :\n  (c \u2022 f).seminorm_aux k n \u2264 \u2016c\u2016 * f.seminorm_aux k n :=\nbegin\n  refine (c \u2022 f).seminorm_aux_le_bound k n (mul_nonneg (norm_nonneg _) (seminorm_aux_nonneg _ _ _))\n    (\u03bb x, (decay_smul_aux k n f c x).le.trans _),\n  rw mul_assoc,\n  exact mul_le_mul_of_nonneg_left (f.le_seminorm_aux k n x) (norm_nonneg _),\nend\n\ninstance has_nsmul : has_smul \u2115 \ud835\udce2(E, F) :=\n\u27e8\u03bb c f, { to_fun := c \u2022 f,\n  smooth' := (f.smooth _).const_smul c,\n  decay' := begin\n    have : c \u2022 (f : E \u2192 F) = (c : \u211d) \u2022 f,\n    { ext x, simp only [pi.smul_apply, \u2190 nsmul_eq_smul_cast] },\n    simp only [this],\n    exact ((c : \u211d) \u2022 f).decay',\n  end}\u27e9\n\ninstance has_zsmul : has_smul \u2124 \ud835\udce2(E, F) :=\n\u27e8\u03bb c f, { to_fun := c \u2022 f,\n  smooth' := (f.smooth _).const_smul c,\n  decay' := begin\n    have : c \u2022 (f : E \u2192 F) = (c : \u211d) \u2022 f,\n    { ext x, simp only [pi.smul_apply, \u2190 zsmul_eq_smul_cast] },\n    simp only [this],\n    exact ((c : \u211d) \u2022 f).decay',\n  end}\u27e9\n\nend smul\n\nsection zero\n\ninstance : has_zero \ud835\udce2(E, F) :=\n\u27e8{ to_fun := \u03bb _, 0,\n  smooth' := cont_diff_const,\n  decay' := \u03bb _ _, \u27e81, \u03bb _, by simp\u27e9 }\u27e9\n\ninstance : inhabited \ud835\udce2(E, F) := \u27e80\u27e9\n\nlemma coe_zero : \u2191(0 : \ud835\udce2(E, F)) = (0 : E \u2192 F) := rfl\n\n@[simp] lemma coe_fn_zero : coe_fn (0 : \ud835\udce2(E, F)) = (0 : E \u2192 F) := rfl\n\n@[simp] lemma zero_apply {x : E} : (0 : \ud835\udce2(E, F)) x = 0 := rfl\n\nlemma seminorm_aux_zero (k n : \u2115) :\n  (0 : \ud835\udce2(E, F)).seminorm_aux k n = 0 :=\nle_antisymm (seminorm_aux_le_bound k n _ rfl.le (\u03bb _, by simp [pi.zero_def]))\n  (seminorm_aux_nonneg _ _ _)\n\nend zero\n\nsection neg\n\ninstance : has_neg \ud835\udce2(E, F) :=\n\u27e8\u03bb f, \u27e8-f, (f.smooth _).neg, \u03bb k n,\n  \u27e8f.seminorm_aux k n, \u03bb x, (decay_neg_aux k n f x).le.trans (f.le_seminorm_aux k n x)\u27e9\u27e9\u27e9\n\nend neg\n\nsection add\n\ninstance : has_add \ud835\udce2(E, F) :=\n\u27e8\u03bb f g, \u27e8f + g, (f.smooth _).add (g.smooth _), \u03bb k n,\n  \u27e8f.seminorm_aux k n + g.seminorm_aux k n, \u03bb x, (decay_add_le_aux k n f g x).trans\n    (add_le_add (f.le_seminorm_aux k n x) (g.le_seminorm_aux k n x))\u27e9\u27e9\u27e9\n\n@[simp] lemma add_apply {f g : \ud835\udce2(E, F)} {x : E} : (f + g) x = f x + g x := rfl\n\nlemma seminorm_aux_add_le (k n : \u2115) (f g : \ud835\udce2(E, F)) :\n  (f + g).seminorm_aux k n \u2264 f.seminorm_aux k n + g.seminorm_aux k n :=\n(f + g).seminorm_aux_le_bound k n\n  (add_nonneg (seminorm_aux_nonneg _ _ _) (seminorm_aux_nonneg _ _ _)) $\n  \u03bb x, (decay_add_le_aux k n f g x).trans $\n  add_le_add (f.le_seminorm_aux k n x) (g.le_seminorm_aux k n x)\n\nend add\n\nsection sub\n\ninstance : has_sub \ud835\udce2(E, F) :=\n\u27e8\u03bb f g, \u27e8f - g, (f.smooth _).sub (g.smooth _),\n  begin\n    intros k n,\n    refine \u27e8f.seminorm_aux k n + g.seminorm_aux k n, \u03bb x, _\u27e9,\n    refine le_trans _ (add_le_add (f.le_seminorm_aux k n x) (g.le_seminorm_aux k n x)),\n    rw sub_eq_add_neg,\n    rw \u2190decay_neg_aux k n g x,\n    convert decay_add_le_aux k n f (-g) x,\n    -- exact fails with deterministic timeout\n  end\u27e9 \u27e9\n\n@[simp] lemma sub_apply {f g : \ud835\udce2(E, F)} {x : E} : (f - g) x = f x - g x := rfl\n\nend sub\n\nsection add_comm_group\n\ninstance : add_comm_group \ud835\udce2(E, F) :=\nfun_like.coe_injective.add_comm_group _ rfl (\u03bb _ _, rfl) (\u03bb _, rfl) (\u03bb _ _, rfl) (\u03bb _ _, rfl)\n  (\u03bb _ _, rfl)\n\nvariables (E F)\n\n/-- Coercion as an additive homomorphism. -/\ndef coe_hom : \ud835\udce2(E, F) \u2192+ (E \u2192 F) :=\n{ to_fun := \u03bb f, f, map_zero' := coe_zero, map_add' := \u03bb _ _, rfl }\n\nvariables {E F}\n\nlemma coe_coe_hom : (coe_hom E F : \ud835\udce2(E, F) \u2192 (E \u2192 F)) = coe_fn := rfl\n\nlemma coe_hom_injective : function.injective (coe_hom E F) :=\nby { rw coe_coe_hom, exact fun_like.coe_injective }\n\nend add_comm_group\n\nsection module\n\nvariables [normed_field \ud835\udd5c] [normed_space \ud835\udd5c F] [smul_comm_class \u211d \ud835\udd5c F]\n\ninstance : module \ud835\udd5c \ud835\udce2(E, F) :=\ncoe_hom_injective.module \ud835\udd5c (coe_hom E F) (\u03bb _ _, rfl)\n\nend module\n\nsection seminorms\n\n/-! ### Seminorms on Schwartz space-/\n\nvariables [normed_field \ud835\udd5c] [normed_space \ud835\udd5c F] [smul_comm_class \u211d \ud835\udd5c F]\nvariable (\ud835\udd5c)\n\n/-- The seminorms of the Schwartz space given by the best constants in the definition of\n`\ud835\udce2(E, F)`. -/\n@[protected]\ndef seminorm (k n : \u2115) : seminorm \ud835\udd5c \ud835\udce2(E, F) := seminorm.of_smul_le (seminorm_aux k n)\n  (seminorm_aux_zero k n) (seminorm_aux_add_le k n) (seminorm_aux_smul_le k n)\n\n/-- If one controls the seminorm for every `x`, then one controls the seminorm. -/\nlemma seminorm_le_bound (k n : \u2115) (f : \ud835\udce2(E, F)) {M : \u211d} (hMp: 0 \u2264 M)\n  (hM : \u2200 x, \u2016x\u2016^k * \u2016iterated_fderiv \u211d n f x\u2016 \u2264 M) : seminorm \ud835\udd5c k n f \u2264 M :=\nf.seminorm_aux_le_bound k n hMp hM\n\n/-- The seminorm controls the Schwartz estimate for any fixed `x`. -/\nlemma le_seminorm (k n : \u2115) (f : \ud835\udce2(E, F)) (x : E) :\n  \u2016x\u2016 ^ k * \u2016iterated_fderiv \u211d n f x\u2016 \u2264 seminorm \ud835\udd5c k n f :=\nf.le_seminorm_aux k n x\n\nlemma norm_iterated_fderiv_le_seminorm (f : \ud835\udce2(E, F)) (n : \u2115) (x\u2080 : E) :\n  \u2016iterated_fderiv \u211d n f x\u2080\u2016 \u2264 (schwartz_map.seminorm \ud835\udd5c 0 n) f :=\nbegin\n  have := schwartz_map.le_seminorm \ud835\udd5c 0 n f x\u2080,\n  rwa [pow_zero, one_mul] at this,\nend\n\nlemma norm_pow_mul_le_seminorm (f : \ud835\udce2(E, F)) (k : \u2115) (x\u2080 : E) :\n  \u2016x\u2080\u2016^k * \u2016f x\u2080\u2016 \u2264 (schwartz_map.seminorm \ud835\udd5c k 0) f :=\nbegin\n  have := schwartz_map.le_seminorm \ud835\udd5c k 0 f x\u2080,\n  rwa norm_iterated_fderiv_zero at this,\nend\n\nlemma norm_le_seminorm (f : \ud835\udce2(E, F)) (x\u2080 : E) :\n  \u2016f x\u2080\u2016 \u2264 (schwartz_map.seminorm \ud835\udd5c 0 0) f :=\nbegin\n  have := norm_pow_mul_le_seminorm \ud835\udd5c f 0 x\u2080,\n  rwa [pow_zero, one_mul] at this,\nend\n\nend seminorms\n\nsection topology\n\n/-! ### The topology on the Schwartz space-/\n\nvariables [normed_field \ud835\udd5c] [normed_space \ud835\udd5c F] [smul_comm_class \u211d \ud835\udd5c F]\nvariables (\ud835\udd5c E F)\n\n/-- The family of Schwartz seminorms. -/\ndef _root_.schwartz_seminorm_family : seminorm_family \ud835\udd5c \ud835\udce2(E, F) (\u2115 \u00d7 \u2115) :=\n\u03bb n, seminorm \ud835\udd5c n.1 n.2\n\n@[simp] lemma schwartz_seminorm_family_apply (n k : \u2115) :\n  schwartz_seminorm_family \ud835\udd5c E F (n,k) = schwartz_map.seminorm \ud835\udd5c n k := rfl\n\n@[simp] lemma schwartz_seminorm_family_apply_zero :\n  schwartz_seminorm_family \ud835\udd5c E F 0 = schwartz_map.seminorm \ud835\udd5c 0 0 := rfl\n\ninstance : topological_space \ud835\udce2(E, F) :=\n(schwartz_seminorm_family \u211d E F).module_filter_basis.topology'\n\nlemma _root_.schwartz_with_seminorms : with_seminorms (schwartz_seminorm_family \ud835\udd5c E F) :=\nbegin\n  have A : with_seminorms (schwartz_seminorm_family \u211d E F) := \u27e8rfl\u27e9,\n  rw seminorm_family.with_seminorms_iff_nhds_eq_infi at \u22a2 A,\n  rw A,\n  refl\nend\n\nvariables {\ud835\udd5c E F}\n\ninstance : has_continuous_smul \ud835\udd5c \ud835\udce2(E, F) :=\nbegin\n  rw (schwartz_with_seminorms \ud835\udd5c E F).with_seminorms_eq,\n  exact (schwartz_seminorm_family \ud835\udd5c E F).module_filter_basis.has_continuous_smul,\nend\n\ninstance : topological_add_group \ud835\udce2(E, F) :=\n(schwartz_seminorm_family \u211d E F).add_group_filter_basis.is_topological_add_group\n\ninstance : uniform_space \ud835\udce2(E, F) :=\n(schwartz_seminorm_family \u211d E F).add_group_filter_basis.uniform_space\n\ninstance : uniform_add_group \ud835\udce2(E, F) :=\n(schwartz_seminorm_family \u211d E F).add_group_filter_basis.uniform_add_group\n\ninstance : locally_convex_space \u211d \ud835\udce2(E, F) :=\n(schwartz_with_seminorms \u211d E F).to_locally_convex_space\n\ninstance : topological_space.first_countable_topology (\ud835\udce2(E, F)) :=\n(schwartz_with_seminorms \u211d E F).first_countable\n\nend topology\n\nsection fderiv\n\n/-! ### Derivatives of Schwartz functions -/\n\nvariables {E F}\n\n/-- The derivative of a Schwartz function as a Schwartz function with values in the\ncontinuous linear maps `E\u2192L[\u211d] F`. -/\n@[protected] def fderiv (f : \ud835\udce2(E, F)) : \ud835\udce2(E, E \u2192L[\u211d] F) :=\n{ to_fun := fderiv \u211d f,\n  smooth' := (cont_diff_top_iff_fderiv.mp f.smooth').2,\n  decay' :=\n  begin\n    intros k n,\n    cases f.decay' k (n+1) with C hC,\n    use C,\n    intros x,\n    rw norm_iterated_fderiv_fderiv,\n    exact hC x,\n  end }\n\n@[simp, norm_cast] lemma coe_fderiv (f : \ud835\udce2(E, F)) : \u21d1f.fderiv = fderiv \u211d f := rfl\n@[simp] lemma fderiv_apply (f : \ud835\udce2(E, F)) (x : E) : f.fderiv x = fderiv \u211d f x := rfl\n\nvariables (\ud835\udd5c)\nvariables [is_R_or_C \ud835\udd5c] [normed_space \ud835\udd5c F] [smul_comm_class \u211d \ud835\udd5c F]\n\n/-- The derivative on Schwartz space as a linear map. -/\ndef fderiv_lm : \ud835\udce2(E, F) \u2192\u2097[\ud835\udd5c] \ud835\udce2(E, E \u2192L[\u211d] F) :=\n{ to_fun := schwartz_map.fderiv,\n  map_add' := \u03bb f g, ext $ \u03bb _, fderiv_add\n    f.differentiable.differentiable_at\n    g.differentiable.differentiable_at,\n  map_smul' := \u03bb a f, ext $ \u03bb _, fderiv_const_smul f.differentiable.differentiable_at a }\n\n@[simp, norm_cast] lemma fderiv_lm_apply (f : \ud835\udce2(E, F)) : fderiv_lm \ud835\udd5c f = schwartz_map.fderiv f :=\nrfl\n\n/-- The derivative on Schwartz space as a continuous linear map. -/\ndef fderiv_clm : \ud835\udce2(E, F) \u2192L[\ud835\udd5c] \ud835\udce2(E, E \u2192L[\u211d] F) :=\n{ cont :=\n  begin\n    change continuous (fderiv_lm \ud835\udd5c : \ud835\udce2(E, F) \u2192\u2097[\ud835\udd5c] \ud835\udce2(E, E \u2192L[\u211d] F)),\n    refine seminorm.continuous_from_bounded (schwartz_with_seminorms \ud835\udd5c E F)\n      (schwartz_with_seminorms \ud835\udd5c E (E \u2192L[\u211d] F)) _ _,\n    rintros \u27e8k, n\u27e9,\n    use [{\u27e8k, n+1\u27e9}, 1],\n    intros f,\n    simp only [schwartz_seminorm_family_apply, seminorm.comp_apply, finset.sup_singleton, one_smul],\n    refine (fderiv_lm \ud835\udd5c f).seminorm_le_bound \ud835\udd5c k n (by positivity) _,\n    intros x,\n    rw [fderiv_lm_apply, coe_fderiv, norm_iterated_fderiv_fderiv],\n    exact f.le_seminorm \ud835\udd5c k (n+1) x,\n  end,\n  to_linear_map := fderiv_lm \ud835\udd5c }\n\n@[simp, norm_cast] lemma fderiv_clm_apply (f : \ud835\udce2(E, F)) : fderiv_clm \ud835\udd5c f = schwartz_map.fderiv f :=\nrfl\n\nend fderiv\n\nsection bounded_continuous_function\n\n/-! ### Inclusion into the space of bounded continuous functions -/\n\nopen_locale bounded_continuous_function\n\n/-- Schwartz functions as bounded continuous functions -/\ndef to_bounded_continuous_function (f : \ud835\udce2(E, F)) : E \u2192\u1d47 F :=\nbounded_continuous_function.of_normed_add_comm_group f (schwartz_map.continuous f)\n  (schwartz_map.seminorm \u211d 0 0 f) (norm_le_seminorm \u211d f)\n\n@[simp] lemma to_bounded_continuous_function_apply (f : \ud835\udce2(E, F)) (x : E) :\n  f.to_bounded_continuous_function x = f x := rfl\n\n/-- Schwartz functions as continuous functions -/\ndef to_continuous_map (f : \ud835\udce2(E, F)) : C(E, F) :=\nf.to_bounded_continuous_function.to_continuous_map\n\nvariables (\ud835\udd5c E F)\nvariables [is_R_or_C \ud835\udd5c] [normed_space \ud835\udd5c F] [smul_comm_class \u211d \ud835\udd5c F]\n\n/-- The inclusion map from Schwartz functions to bounded continuous functions as a linear map. -/\ndef to_bounded_continuous_function_lm : \ud835\udce2(E, F) \u2192\u2097[\ud835\udd5c] E \u2192\u1d47 F :=\n{ to_fun := \u03bb f, f.to_bounded_continuous_function,\n  map_add' := \u03bb f g, by { ext, exact add_apply },\n  map_smul' := \u03bb a f, by { ext, exact smul_apply } }\n\n@[simp] lemma to_bounded_continuous_function_lm_apply (f : \ud835\udce2(E, F)) (x : E) :\n  to_bounded_continuous_function_lm \ud835\udd5c E F f x = f x := rfl\n\n/-- The inclusion map from Schwartz functions to bounded continuous functions as a continuous linear\nmap. -/\ndef to_bounded_continuous_function_clm : \ud835\udce2(E, F) \u2192L[\ud835\udd5c] E \u2192\u1d47 F :=\n{ cont :=\n  begin\n    change continuous (to_bounded_continuous_function_lm \ud835\udd5c E F),\n    refine seminorm.continuous_from_bounded (schwartz_with_seminorms \ud835\udd5c E F)\n      (norm_with_seminorms \ud835\udd5c (E \u2192\u1d47 F)) _ (\u03bb i, \u27e8{0}, 1, \u03bb f, _\u27e9),\n    rw [finset.sup_singleton, one_smul , seminorm.comp_apply, coe_norm_seminorm,\n        schwartz_seminorm_family_apply_zero, bounded_continuous_function.norm_le (map_nonneg _ _)],\n    intros x,\n    exact norm_le_seminorm \ud835\udd5c _ _,\n  end,\n  .. to_bounded_continuous_function_lm \ud835\udd5c E F}\n\n@[simp] lemma to_bounded_continuous_function_clm_apply (f : \ud835\udce2(E, F)) (x : E) :\n  to_bounded_continuous_function_clm \ud835\udd5c E F f x = f x := rfl\n\nvariables {E}\n\n/-- The Dirac delta distribution -/\ndef delta (x : E) : \ud835\udce2(E, F) \u2192L[\ud835\udd5c] F :=\n(bounded_continuous_function.eval_clm \ud835\udd5c x).comp (to_bounded_continuous_function_clm \ud835\udd5c E F)\n\n@[simp] lemma delta_apply (x\u2080 : E) (f : \ud835\udce2(E, F)) : delta \ud835\udd5c F x\u2080 f = f x\u2080 := rfl\n\nend bounded_continuous_function\n\nend schwartz_map\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/analysis/schwartz_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7023995928984029}}
{"text": "\n/-\nGive an alternative characterisation `eqv_gen_alt` of `eqv_gen`, the equiverlance relation generated\nby a binary relation, and prove it is the same.\n\nAlso define the infix `contains` which will refer to binary relations.\n-/\n\nnamespace relation\n\n  def contains_ {\u03b1 : Type*} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : \u03b1 \u2192 \u03b1 \u2192 Prop) := \u2200 x y : \u03b1, s x y \u2192 r x y\n  infix ` contains `:55 := contains_\n\n  section\n    parameter {\u03b1 : Type*}\n    variable (r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n    variables (x y : \u03b1)\n\n    def eqv_gen_alt (r) (x y) := \u2200 (s : \u03b1 \u2192 \u03b1 \u2192 Prop), equivalence s \u2192 s contains r \u2192 s x y\n\n    theorem eqv_gen_alt_is_reflexive : reflexive (eqv_gen_alt r) :=\n    begin\n      intros x s h_eqv h_contains,\n      exact h_eqv.left x,\n    end\n\n    theorem eqv_gen_alt_is_symmetric : symmetric (eqv_gen_alt r) :=\n    begin\n      intros x y h s h_eqv h_contains,\n      specialize h s h_eqv h_contains,\n      exact h_eqv.right.left h,\n    end\n\n    theorem eqv_gen_alt_is_transitive : transitive (eqv_gen_alt r) :=\n    begin\n      intros x y z h_xy h_yz s h_eqv h_contains,\n      specialize h_xy s h_eqv h_contains,\n      specialize h_yz s h_eqv h_contains,\n      exact h_eqv.right.right h_xy h_yz,\n    end\n\n    theorem eqv_gen_alt_is_equivalence : equivalence (eqv_gen_alt r) :=\n    begin\n      rw equivalence,\n      split,\n      exact eqv_gen_alt_is_reflexive r,\n      split,\n      exact eqv_gen_alt_is_symmetric r,\n      exact eqv_gen_alt_is_transitive r,\n    end\n\n    theorem eqv_gen_alt_same : (eqv_gen r) x y \u2194 (eqv_gen_alt r) x y :=\n    begin\n      split,\n\n      intro h,\n      induction h,\n      case eqv_gen.rel   : a b               { intros _ _ h_contains, specialize h_contains a b, cc, },\n      case eqv_gen.refl  : a                 { exact  eqv_gen_alt_is_reflexive r a, },\n      case eqv_gen.symm  : a b   _   hab     { exact  eqv_gen_alt_is_symmetric r hab, },\n      case eqv_gen.trans : a b c _ _ hab hbc { exact eqv_gen_alt_is_transitive r hab hbc, },\n\n      intro h,\n      exact h (eqv_gen r) (eqv_gen.is_equivalence r) (eqv_gen.rel),\n    end\n\n  end\nend relation\n", "meta": {"author": "gilesgshaw", "repo": "UA-Lean", "sha": "b2187168c11a13756d9c8196377fdb97069580b0", "save_path": "github-repos/lean/gilesgshaw-UA-Lean", "path": "github-repos/lean/gilesgshaw-UA-Lean/UA-Lean-b2187168c11a13756d9c8196377fdb97069580b0/src/relation/additional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7023995857161263}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl\n-/\nimport data.set.finite\nimport logic.equiv.list\n\n/-!\n# Countable sets\n-/\nnoncomputable theory\n\nopen function set encodable\n\nopen classical (hiding some)\nopen_locale classical\nuniverses u v w\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nnamespace set\n\n/-- A set is countable if there exists an encoding of the set into the natural numbers.\nAn encoding is an injection with a partial inverse, which can be viewed as a\nconstructive analogue of countability. (For the most part, theorems about\n`countable` will be classical and `encodable` will be constructive.)\n-/\ndef countable (s : set \u03b1) : Prop := nonempty (encodable s)\n\nlemma countable_iff_exists_injective {s : set \u03b1} :\n  countable s \u2194 \u2203f:s \u2192 \u2115, injective f :=\n\u27e8\u03bb \u27e8h\u27e9, by exactI \u27e8encode, encode_injective\u27e9,\n \u03bb \u27e8f, h\u27e9, \u27e8\u27e8f, partial_inv f, partial_inv_left h\u27e9\u27e9\u27e9\n\n/-- A set `s : set \u03b1` is countable if and only if there exists a function `\u03b1 \u2192 \u2115` injective\non `s`. -/\nlemma countable_iff_exists_inj_on {s : set \u03b1} :\n  countable s \u2194 \u2203 f : \u03b1 \u2192 \u2115, inj_on f s :=\ncountable_iff_exists_injective.trans\n\u27e8\u03bb \u27e8f, hf\u27e9, \u27e8\u03bb a, if h : a \u2208 s then f \u27e8a, h\u27e9 else 0,\n   \u03bb a as b bs h, congr_arg subtype.val $\n     hf $ by simpa [as, bs] using h\u27e9,\n \u03bb \u27e8f, hf\u27e9, \u27e8_, inj_on_iff_injective.1 hf\u27e9\u27e9\n\nlemma countable_iff_exists_surjective [ne : nonempty \u03b1] {s : set \u03b1} :\n  countable s \u2194 \u2203f:\u2115 \u2192 \u03b1, s \u2286 range f :=\n\u27e8\u03bb \u27e8h\u27e9, by inhabit \u03b1; exactI \u27e8\u03bb n, ((decode s n).map subtype.val).iget,\n  \u03bb a as, \u27e8encode (\u27e8a, as\u27e9 : s), by simp [encodek]\u27e9\u27e9,\n \u03bb \u27e8f, hf\u27e9, \u27e8\u27e8\n  \u03bb x, inv_fun f x.1,\n  \u03bb n, if h : f n \u2208 s then some \u27e8f n, h\u27e9 else none,\n  \u03bb \u27e8x, hx\u27e9, begin\n    have := inv_fun_eq (hf hx), dsimp at this \u22a2,\n    simp [this, hx]\n  end\u27e9\u27e9\u27e9\n\n/--\nA non-empty set is countable iff there exists a surjection from the\nnatural numbers onto the subtype induced by the set.\n-/\nlemma countable_iff_exists_surjective_to_subtype {s : set \u03b1} (hs : s.nonempty) :\n  countable s \u2194 \u2203 f : \u2115 \u2192 s, surjective f :=\nhave inhabited s, from \u27e8classical.choice hs.to_subtype\u27e9,\nhave countable s \u2192 \u2203 f : \u2115 \u2192 s, surjective f, from assume \u27e8h\u27e9,\n  by exactI \u27e8\u03bb n, (decode s n).iget, \u03bb a, \u27e8encode a, by simp [encodek]\u27e9\u27e9,\nhave (\u2203 f : \u2115 \u2192 s, surjective f) \u2192 countable s, from assume \u27e8f, fsurj\u27e9,\n  \u27e8\u27e8inv_fun f, option.some \u2218 f,\n    by intro h; simp [(inv_fun_eq (fsurj h) : f (inv_fun f h) = h)]\u27e9\u27e9,\nby split; assumption\n\n/-- Convert `countable s` to `encodable s` (noncomputable). -/\ndef countable.to_encodable {s : set \u03b1} : countable s \u2192 encodable s :=\nclassical.choice\n\nlemma countable_encodable' (s : set \u03b1) [H : encodable s] : countable s :=\n\u27e8H\u27e9\n\nlemma countable_encodable [encodable \u03b1] (s : set \u03b1) : countable s :=\n\u27e8by apply_instance\u27e9\n\n/-- If `s : set \u03b1` is a nonempty countable set, then there exists a map\n`f : \u2115 \u2192 \u03b1` such that `s = range f`. -/\nlemma countable.exists_surjective {s : set \u03b1} (hc : countable s) (hs : s.nonempty) :\n  \u2203f:\u2115 \u2192 \u03b1, s = range f :=\nbegin\n  letI : encodable s := countable.to_encodable hc,\n  letI : nonempty s := hs.to_subtype,\n  have : countable (univ : set s) := countable_encodable _,\n  rcases countable_iff_exists_surjective.1 this with \u27e8g, hg\u27e9,\n  have : range g = univ := univ_subset_iff.1 hg,\n  use coe \u2218 g,\n  simp only [range_comp, this, image_univ, subtype.range_coe]\nend\n\n@[simp] \n\n@[simp] lemma countable_singleton (a : \u03b1) : countable ({a} : set \u03b1) :=\n\u27e8of_equiv _ (equiv.set.singleton a)\u27e9\n\nlemma countable.mono {s\u2081 s\u2082 : set \u03b1} (h : s\u2081 \u2286 s\u2082) : countable s\u2082 \u2192 countable s\u2081\n| \u27e8H\u27e9 := \u27e8@of_inj _ _ H _ (embedding_of_subset _ _ h).2\u27e9\n\nlemma countable.image {s : set \u03b1} (hs : countable s) (f : \u03b1 \u2192 \u03b2) : countable (f '' s) :=\nhave surjective ((maps_to_image f s).restrict _ _ _), from surjective_maps_to_image_restrict f s,\n\u27e8@encodable.of_inj _ _ hs.to_encodable (surj_inv this) (injective_surj_inv this)\u27e9\n\nlemma countable_range [encodable \u03b1] (f : \u03b1 \u2192 \u03b2) : countable (range f) :=\nby rw \u2190 image_univ; exact (countable_encodable _).image _\n\nlemma maps_to.countable_of_inj_on {s : set \u03b1} {t : set \u03b2} {f : \u03b1 \u2192 \u03b2}\n  (hf : maps_to f s t) (hf' : inj_on f s) (ht : countable t) :\n  countable s :=\nhave injective (hf.restrict f s t), from (inj_on_iff_injective.1 hf').cod_restrict _,\n\u27e8@encodable.of_inj _ _ ht.to_encodable _ this\u27e9\n\nlemma countable.preimage_of_inj_on {s : set \u03b2} (hs : countable s) {f : \u03b1 \u2192 \u03b2}\n  (hf : inj_on f (f \u207b\u00b9' s)) : countable (f \u207b\u00b9' s) :=\n(maps_to_preimage f s).countable_of_inj_on hf hs\n\nprotected lemma countable.preimage {s : set \u03b2} (hs : countable s) {f : \u03b1 \u2192 \u03b2} (hf : injective f) :\n  countable (f \u207b\u00b9' s) :=\nhs.preimage_of_inj_on (hf.inj_on _)\n\nlemma exists_seq_supr_eq_top_iff_countable [complete_lattice \u03b1] {p : \u03b1 \u2192 Prop} (h : \u2203 x, p x) :\n  (\u2203 s : \u2115 \u2192 \u03b1, (\u2200 n, p (s n)) \u2227 (\u2a06 n, s n) = \u22a4) \u2194\n    \u2203 S : set \u03b1, countable S \u2227 (\u2200 s \u2208 S, p s) \u2227 Sup S = \u22a4 :=\nbegin\n  split,\n  { rintro \u27e8s, hps, hs\u27e9,\n    refine \u27e8range s, countable_range s, forall_range_iff.2 hps, _\u27e9, rwa Sup_range },\n  { rintro \u27e8S, hSc, hps, hS\u27e9,\n    rcases eq_empty_or_nonempty S with rfl|hne,\n    { rw [Sup_empty] at hS, haveI := subsingleton_of_bot_eq_top hS,\n      rcases h with \u27e8x, hx\u27e9, exact \u27e8\u03bb n, x, \u03bb n, hx, subsingleton.elim _ _\u27e9 },\n    { rcases (countable_iff_exists_surjective_to_subtype hne).1 hSc with \u27e8s, hs\u27e9,\n      refine \u27e8\u03bb n, s n, \u03bb n, hps _ (s n).coe_prop, _\u27e9,\n      rwa [hs.supr_comp, \u2190 Sup_eq_supr'] } }\nend\n\nlemma exists_seq_cover_iff_countable {p : set \u03b1 \u2192 Prop} (h : \u2203 s, p s) :\n  (\u2203 s : \u2115 \u2192 set \u03b1, (\u2200 n, p (s n)) \u2227 (\u22c3 n, s n) = univ) \u2194\n    \u2203 S : set (set \u03b1), countable S \u2227 (\u2200 s \u2208 S, p s) \u2227 \u22c3\u2080 S = univ :=\nexists_seq_supr_eq_top_iff_countable h\n\nlemma countable_of_injective_of_countable_image {s : set \u03b1} {f : \u03b1 \u2192 \u03b2}\n  (hf : inj_on f s) (hs : countable (f '' s)) : countable s :=\nlet \u27e8g, hg\u27e9 := countable_iff_exists_inj_on.1 hs in\ncountable_iff_exists_inj_on.2 \u27e8g \u2218 f, hg.comp hf (maps_to_image _ _)\u27e9\n\nlemma countable_Union {t : \u03b1 \u2192 set \u03b2} [encodable \u03b1] (ht : \u2200a, countable (t a)) :\n  countable (\u22c3a, t a) :=\nby haveI := (\u03bb a, (ht a).to_encodable);\n   rw Union_eq_range_sigma; apply countable_range\n\nlemma countable.bUnion\n  {s : set \u03b1} {t : \u03a0 x \u2208 s, set \u03b2} (hs : countable s) (ht : \u2200a\u2208s, countable (t a \u2039_\u203a)) :\n  countable (\u22c3a\u2208s, t a \u2039_\u203a) :=\nbegin\n  rw bUnion_eq_Union,\n  haveI := hs.to_encodable,\n  exact countable_Union (by simpa using ht)\nend\n\nlemma countable.sUnion {s : set (set \u03b1)} (hs : countable s) (h : \u2200a\u2208s, countable a) :\n  countable (\u22c3\u2080 s) :=\nby rw sUnion_eq_bUnion; exact hs.bUnion h\n\nlemma countable_Union_Prop {p : Prop} {t : p \u2192 set \u03b2} (ht : \u2200h:p, countable (t h)) :\n  countable (\u22c3h:p, t h) :=\nby by_cases p; simp [h, ht]\n\nlemma countable.union\n  {s\u2081 s\u2082 : set \u03b1} (h\u2081 : countable s\u2081) (h\u2082 : countable s\u2082) : countable (s\u2081 \u222a s\u2082) :=\nby rw union_eq_Union; exact\ncountable_Union (bool.forall_bool.2 \u27e8h\u2082, h\u2081\u27e9)\n\n@[simp] lemma countable_union {s t : set \u03b1} : countable (s \u222a t) \u2194 countable s \u2227 countable t :=\n\u27e8\u03bb h, \u27e8h.mono (subset_union_left s t), h.mono (subset_union_right _ _)\u27e9, \u03bb h, h.1.union h.2\u27e9\n\n@[simp] lemma countable_insert {s : set \u03b1} {a : \u03b1} : countable (insert a s) \u2194 countable s :=\nby simp only [insert_eq, countable_union, countable_singleton, true_and]\n\nlemma countable.insert {s : set \u03b1} (a : \u03b1) (h : countable s) : countable (insert a s) :=\ncountable_insert.2 h\n\nlemma finite.countable {s : set \u03b1} : finite s \u2192 countable s\n| \u27e8h\u27e9 := trunc.nonempty (by exactI trunc_encodable_of_fintype s)\n\nlemma subsingleton.countable {s : set \u03b1} (hs : s.subsingleton) : countable s :=\nhs.finite.countable\n\nlemma countable_is_top (\u03b1 : Type*) [partial_order \u03b1] : countable {x : \u03b1 | is_top x} :=\n(finite_is_top \u03b1).countable\n\nlemma countable_is_bot (\u03b1 : Type*) [partial_order \u03b1] : countable {x : \u03b1 | is_bot x} :=\n(finite_is_bot \u03b1).countable\n\n/-- The set of finite subsets of a countable set is countable. -/\nlemma countable_set_of_finite_subset {s : set \u03b1} : countable s \u2192\n  countable {t | finite t \u2227 t \u2286 s} | \u27e8h\u27e9 :=\nbegin\n  resetI,\n  refine countable.mono _ (countable_range\n    (\u03bb t : finset s, {a | \u2203 h:a \u2208 s, subtype.mk a h \u2208 t})),\n  rintro t \u27e8\u27e8ht\u27e9, ts\u27e9, resetI,\n  refine \u27e8finset.univ.map (embedding_of_subset _ _ ts),\n    set.ext $ \u03bb a, _\u27e9,\n  suffices : a \u2208 s \u2227 a \u2208 t \u2194 a \u2208 t, by simpa,\n  exact \u27e8and.right, \u03bb h, \u27e8ts h, h\u27e9\u27e9\nend\n\nlemma countable_pi {\u03c0 : \u03b1 \u2192 Type*} [fintype \u03b1] {s : \u03a0a, set (\u03c0 a)} (hs : \u2200a, countable (s a)) :\n  countable {f : \u03a0a, \u03c0 a | \u2200a, f a \u2208 s a} :=\ncountable.mono\n  (show {f : \u03a0a, \u03c0 a | \u2200a, f a \u2208 s a} \u2286 range (\u03bbf : \u03a0a, s a, \u03bba, (f a).1), from\n    assume f hf, \u27e8\u03bba, \u27e8f a, hf a\u27e9, funext $ assume a, rfl\u27e9) $\nhave trunc (encodable (\u03a0 (a : \u03b1), s a)), from\n  @encodable.fintype_pi \u03b1 _ _ _ (assume a, (hs a).to_encodable),\ntrunc.induction_on this $ assume h,\n@countable_range _ _ h _\n\nprotected lemma countable.prod {s : set \u03b1} {t : set \u03b2} (hs : countable s) (ht : countable t) :\n  countable (s \u00d7\u02e2 t) :=\nbegin\n  haveI : encodable s := hs.to_encodable,\n  haveI : encodable t := ht.to_encodable,\n  exact \u27e8of_equiv (s \u00d7 t) (equiv.set.prod _ _)\u27e9\nend\n\nlemma countable.image2 {s : set \u03b1} {t : set \u03b2} (hs : countable s) (ht : countable t)\n  (f : \u03b1 \u2192 \u03b2 \u2192 \u03b3) : countable (image2 f s t) :=\nby { rw \u2190 image_prod, exact (hs.prod ht).image _ }\n\nsection enumerate\n\n/-- Enumerate elements in a countable set.-/\ndef enumerate_countable {s : set \u03b1} (h : countable s) (default : \u03b1) : \u2115 \u2192 \u03b1 :=\nassume n, match @encodable.decode s (h.to_encodable) n with\n        | (some y) := y\n        | (none)   := default\n        end\n\nlemma subset_range_enumerate {s : set \u03b1} (h : countable s) (default : \u03b1) :\n   s \u2286 range (enumerate_countable h default) :=\nassume x hx,\n\u27e8@encodable.encode s h.to_encodable \u27e8x, hx\u27e9,\nby simp [enumerate_countable, encodable.encodek]\u27e9\n\nend enumerate\n\nend set\n\nlemma finset.countable_to_set (s : finset \u03b1) : set.countable (\u2191s : set \u03b1) :=\ns.finite_to_set.countable\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/data/set/countable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7023539488103435}}
{"text": "/-\nCopyright (c) 2019 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann\n-/\nimport algebra.continued_fractions.translations\n/-!\n# Recurrence Lemmas for the `continuants` Function of Continued Fractions.\n\n## Summary\n\nGiven a generalized continued fraction `g`, for all `n \u2265 1`, we prove that the `continuants`\nfunction indeed satisfies the following recurrences:\n- `A\u2099 = b\u2099 * A\u2099\u208b\u2081 + a\u2099 * A\u2099\u208b\u2082`, and\n- `B\u2099 = b\u2099 * B\u2099\u208b\u2081 + a\u2099 * B\u2099\u208b\u2082`.\n-/\n\nnamespace generalized_continued_fraction\n\nvariables {K : Type*} {g : generalized_continued_fraction K} {n : \u2115} [division_ring K]\n\nlemma continuants_aux_recurrence\n  {gp ppred pred : pair K} (nth_s_eq : g.s.nth n = some gp)\n  (nth_conts_aux_eq : g.continuants_aux n = ppred)\n  (succ_nth_conts_aux_eq : g.continuants_aux (n + 1) = pred) :\n  g.continuants_aux (n + 2) = \u27e8gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b\u27e9 :=\nby simp [*, continuants_aux, next_continuants, next_denominator, next_numerator]\n\nlemma continuants_recurrence_aux\n  {gp ppred pred : pair K} (nth_s_eq : g.s.nth n = some gp)\n  (nth_conts_aux_eq : g.continuants_aux n = ppred)\n  (succ_nth_conts_aux_eq : g.continuants_aux (n + 1) = pred) :\n  g.continuants (n + 1) = \u27e8gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b\u27e9 :=\nby simp [nth_cont_eq_succ_nth_cont_aux,\n  (continuants_aux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq)]\n\n/-- Shows that `A\u2099 = b\u2099 * A\u2099\u208b\u2081 + a\u2099 * A\u2099\u208b\u2082` and `B\u2099 = b\u2099 * B\u2099\u208b\u2081 + a\u2099 * B\u2099\u208b\u2082`. -/\ntheorem continuants_recurrence\n  {gp ppred pred : pair K}\n  (succ_nth_s_eq : g.s.nth (n + 1) = some gp)\n  (nth_conts_eq : g.continuants n = ppred)\n  (succ_nth_conts_eq : g.continuants (n + 1) = pred) :\n  g.continuants (n + 2) = \u27e8gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b\u27e9 :=\nbegin\n  rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq,\n  exact (continuants_recurrence_aux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq)\nend\n\n/-- Shows that `A\u2099 = b\u2099 * A\u2099\u208b\u2081 + a\u2099 * A\u2099\u208b\u2082`. -/\nlemma numerators_recurrence {gp : pair K} {ppredA predA : K}\n  (succ_nth_s_eq : g.s.nth (n + 1) = some gp)\n  (nth_num_eq : g.numerators n = ppredA)\n  (succ_nth_num_eq : g.numerators (n + 1) = predA) :\n  g.numerators (n + 2) = gp.b * predA + gp.a * ppredA :=\nbegin\n  obtain \u27e8ppredConts, nth_conts_eq, \u27e8rfl\u27e9\u27e9 : \u2203 conts, g.continuants n = conts \u2227 conts.a = ppredA,\n    from exists_conts_a_of_num nth_num_eq,\n  obtain \u27e8predConts, succ_nth_conts_eq, \u27e8rfl\u27e9\u27e9 :\n    \u2203 conts, g.continuants (n + 1) = conts \u2227 conts.a = predA, from\n      exists_conts_a_of_num succ_nth_num_eq,\n  rw [num_eq_conts_a, (continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq)]\nend\n\n/-- Shows that `B\u2099 = b\u2099 * B\u2099\u208b\u2081 + a\u2099 * B\u2099\u208b\u2082`. -/\n\n\nend generalized_continued_fraction\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/continued_fractions/continuants_recurrence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105441, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7023539333545898}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport data.set.finite\nimport data.finset\nimport group_theory.quotient_group\nimport group_theory.submonoid.operations\nimport group_theory.subgroup.basic\n\n/-!\n# Finitely generated monoids and groups\n\nWe define finitely generated monoids and groups. See also `submodule.fg` and `module.finite` for\nfinitely-generated modules.\n\n## Main definition\n\n* `submonoid.fg S`, `add_submonoid.fg S` : A submonoid `S` is finitely generated.\n* `monoid.fg M`, `add_monoid.fg M` : A typeclass indicating a type `M` is finitely generated as a\nmonoid.\n* `subgroup.fg S`, `add_subgroup.fg S` : A subgroup `S` is finitely generated.\n* `group.fg M`, `add_group.fg M` : A typeclass indicating a type `M` is finitely generated as a\ngroup.\n\n-/\n\n/-! ### Monoids and submonoids -/\n\nopen_locale pointwise\nvariables {M N : Type*} [monoid M] [add_monoid N]\n\nsection submonoid\n\n/-- A submonoid of `M` is finitely generated if it is the closure of a finite subset of `M`. -/\n@[to_additive]\ndef submonoid.fg (P : submonoid M) : Prop := \u2203 S : finset M, submonoid.closure \u2191S = P\n\n/-- An additive submonoid of `N` is finitely generated if it is the closure of a finite subset of\n`M`. -/\nadd_decl_doc add_submonoid.fg\n\n/-- An equivalent expression of `submonoid.fg` in terms of `set.finite` instead of `finset`. -/\n@[to_additive \"An equivalent expression of `add_submonoid.fg` in terms of `set.finite` instead of\n`finset`.\"]\nlemma submonoid.fg_iff (P : submonoid M) : submonoid.fg P \u2194\n  \u2203 S : set M, submonoid.closure S = P \u2227 S.finite :=\n\u27e8\u03bb \u27e8S, hS\u27e9, \u27e8S, hS, finset.finite_to_set S\u27e9, \u03bb \u27e8S, hS, hf\u27e9, \u27e8set.finite.to_finset hf, by simp [hS]\u27e9\u27e9\n\nlemma submonoid.fg_iff_add_fg (P : submonoid M) : P.fg \u2194 P.to_add_submonoid.fg :=\n\u27e8\u03bb h, let \u27e8S, hS, hf\u27e9 := (submonoid.fg_iff _).1 h in (add_submonoid.fg_iff _).mpr\n  \u27e8additive.to_mul \u207b\u00b9' S, by simp [\u2190 submonoid.to_add_submonoid_closure, hS], hf\u27e9,\n \u03bb h, let \u27e8T, hT, hf\u27e9 := (add_submonoid.fg_iff _).1 h in (submonoid.fg_iff _).mpr\n  \u27e8multiplicative.of_add \u207b\u00b9' T, by simp [\u2190 add_submonoid.to_submonoid'_closure, hT], hf\u27e9\u27e9\n\nlemma add_submonoid.fg_iff_mul_fg (P : add_submonoid N) : P.fg \u2194 P.to_submonoid.fg :=\nbegin\n  convert (submonoid.fg_iff_add_fg P.to_submonoid).symm,\n  exact set_like.ext' rfl\nend\n\nend submonoid\n\nsection monoid\n\nvariables (M N)\n\n/-- A monoid is finitely generated if it is finitely generated as a submonoid of itself. -/\nclass monoid.fg : Prop := (out : (\u22a4 : submonoid M).fg)\n\n/-- An additive monoid is finitely generated if it is finitely generated as an additive submonoid of\nitself. -/\nclass add_monoid.fg : Prop := (out : (\u22a4 : add_submonoid N).fg)\n\nattribute [to_additive] monoid.fg\n\nvariables {M N}\n\nlemma monoid.fg_def : monoid.fg M \u2194 (\u22a4 : submonoid M).fg := \u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\nlemma add_monoid.fg_def : add_monoid.fg N \u2194 (\u22a4 : add_submonoid N).fg := \u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\n/-- An equivalent expression of `monoid.fg` in terms of `set.finite` instead of `finset`. -/\n@[to_additive \"An equivalent expression of `add_monoid.fg` in terms of `set.finite` instead of\n`finset`.\"]\nlemma monoid.fg_iff : monoid.fg M \u2194\n  \u2203 S : set M, submonoid.closure S = (\u22a4 : submonoid M) \u2227 S.finite :=\n\u27e8\u03bb h, (submonoid.fg_iff \u22a4).1 h.out, \u03bb h, \u27e8(submonoid.fg_iff \u22a4).2 h\u27e9\u27e9\n\nlemma monoid.fg_iff_add_fg : monoid.fg M \u2194 add_monoid.fg (additive M) :=\n\u27e8\u03bb h, \u27e8(submonoid.fg_iff_add_fg \u22a4).1 h.out\u27e9, \u03bb h, \u27e8(submonoid.fg_iff_add_fg \u22a4).2 h.out\u27e9\u27e9\n\nlemma add_monoid.fg_iff_mul_fg : add_monoid.fg N \u2194 monoid.fg (multiplicative N) :=\n\u27e8\u03bb h, \u27e8(add_submonoid.fg_iff_mul_fg \u22a4).1 h.out\u27e9, \u03bb h, \u27e8(add_submonoid.fg_iff_mul_fg \u22a4).2 h.out\u27e9\u27e9\n\ninstance add_monoid.fg_of_monoid_fg [monoid.fg M] : add_monoid.fg (additive M) :=\nmonoid.fg_iff_add_fg.1 \u2039_\u203a\n\ninstance monoid.fg_of_add_monoid_fg [add_monoid.fg N] : monoid.fg (multiplicative N) :=\nadd_monoid.fg_iff_mul_fg.1 \u2039_\u203a\n\nend monoid\n\n@[to_additive]\nlemma submonoid.fg.map {M' : Type*} [monoid M'] {P : submonoid M} (h : P.fg) (e : M \u2192* M') :\n  (P.map e).fg :=\nbegin\n  classical,\n  obtain \u27e8s, rfl\u27e9 := h,\n  exact \u27e8s.image e, by rw [finset.coe_image, monoid_hom.map_mclosure]\u27e9\nend\n\n@[to_additive]\nlemma submonoid.fg.map_injective {M' : Type*} [monoid M'] {P : submonoid M}\n  (e : M \u2192* M') (he : function.injective e) (h : (P.map e).fg) : P.fg :=\nbegin\n  obtain \u27e8s, hs\u27e9 := h,\n  use s.preimage e (he.inj_on _),\n  apply submonoid.map_injective_of_injective he,\n  rw [\u2190 hs, e.map_mclosure, finset.coe_preimage],\n  congr,\n  rw [set.image_preimage_eq_iff, \u2190 e.coe_mrange, \u2190 submonoid.closure_le, hs, e.mrange_eq_map],\n  exact submonoid.monotone_map le_top\nend\n\n@[simp, to_additive]\nlemma monoid.fg_iff_submonoid_fg (N : submonoid M) : monoid.fg N \u2194 N.fg :=\nbegin\n  conv_rhs { rw [\u2190 N.range_subtype, monoid_hom.mrange_eq_map] },\n  exact \u27e8\u03bb h, h.out.map N.subtype, \u03bb h, \u27e8h.map_injective N.subtype subtype.coe_injective\u27e9\u27e9\nend\n\n@[to_additive]\nlemma monoid.fg_of_surjective {M' : Type*} [monoid M'] [monoid.fg M]\n  (f : M \u2192* M') (hf : function.surjective f) : monoid.fg M' :=\nbegin\n  classical,\n  obtain \u27e8s, hs\u27e9 := monoid.fg_def.mp \u2039_\u203a,\n  use s.image f,\n  rwa [finset.coe_image, \u2190 monoid_hom.map_mclosure, hs, \u2190 monoid_hom.mrange_eq_map,\n    monoid_hom.mrange_top_iff_surjective],\nend\n\n@[to_additive]\ninstance monoid.fg_range {M' : Type*} [monoid M'] [monoid.fg M] (f : M \u2192* M') :\n  monoid.fg f.mrange :=\nmonoid.fg_of_surjective f.mrange_restrict f.mrange_restrict_surjective\n\n@[to_additive add_submonoid.multiples_fg]\nlemma submonoid.powers_fg (r : M) : (submonoid.powers r).fg :=\n\u27e8{r}, (finset.coe_singleton r).symm \u25b8 (submonoid.powers_eq_closure r).symm\u27e9\n\n@[to_additive add_monoid.multiples_fg]\ninstance monoid.powers_fg (r : M) : monoid.fg (submonoid.powers r) :=\n(monoid.fg_iff_submonoid_fg _).mpr (submonoid.powers_fg r)\n\n/-! ### Groups and subgroups -/\n\nvariables {G H : Type*} [group G] [add_group H]\n\nsection subgroup\n\n/-- A subgroup of `G` is finitely generated if it is the closure of a finite subset of `G`. -/\n@[to_additive]\ndef subgroup.fg (P : subgroup G) : Prop := \u2203 S : finset G, subgroup.closure \u2191S = P\n\n/-- An additive subgroup of `H` is finitely generated if it is the closure of a finite subset of\n`H`. -/\nadd_decl_doc add_subgroup.fg\n\n/-- An equivalent expression of `subgroup.fg` in terms of `set.finite` instead of `finset`. -/\n@[to_additive \"An equivalent expression of `add_subgroup.fg` in terms of `set.finite` instead of\n`finset`.\"]\nlemma subgroup.fg_iff (P : subgroup G) : subgroup.fg P \u2194\n  \u2203 S : set G, subgroup.closure S = P \u2227 S.finite :=\n\u27e8\u03bb\u27e8S, hS\u27e9, \u27e8S, hS, finset.finite_to_set S\u27e9, \u03bb\u27e8S, hS, hf\u27e9, \u27e8set.finite.to_finset hf, by simp [hS]\u27e9\u27e9\n\n/-- A subgroup is finitely generated if and only if it is finitely generated as a submonoid. -/\n@[to_additive add_subgroup.fg_iff_add_submonoid.fg \"An additive subgroup is finitely generated if\nand only if it is finitely generated as an additive submonoid.\"]\nlemma subgroup.fg_iff_submonoid_fg (P : subgroup G) : P.fg \u2194 P.to_submonoid.fg :=\nbegin\n  split,\n  { rintro \u27e8S, rfl\u27e9,\n    rw submonoid.fg_iff,\n    refine \u27e8S \u222a S\u207b\u00b9, _, S.finite_to_set.union S.finite_to_set.inv\u27e9,\n    exact (subgroup.closure_to_submonoid _).symm },\n  { rintro \u27e8S, hS\u27e9,\n    refine \u27e8S, le_antisymm _ _\u27e9,\n    { rw [subgroup.closure_le, \u2190subgroup.coe_to_submonoid, \u2190hS],\n      exact submonoid.subset_closure },\n    { rw [\u2190 subgroup.to_submonoid_le, \u2190 hS, submonoid.closure_le],\n      exact subgroup.subset_closure } }\nend\n\nlemma subgroup.fg_iff_add_fg (P : subgroup G) : P.fg \u2194 P.to_add_subgroup.fg :=\nbegin\n  rw [subgroup.fg_iff_submonoid_fg, add_subgroup.fg_iff_add_submonoid.fg],\n  exact (subgroup.to_submonoid P).fg_iff_add_fg\nend\n\nlemma add_subgroup.fg_iff_mul_fg (P : add_subgroup H) :\n  P.fg \u2194 P.to_subgroup.fg :=\nbegin\n  rw [add_subgroup.fg_iff_add_submonoid.fg, subgroup.fg_iff_submonoid_fg],\n  exact add_submonoid.fg_iff_mul_fg (add_subgroup.to_add_submonoid P)\nend\n\nend subgroup\n\nsection group\n\nvariables (G H)\n\n/-- A group is finitely generated if it is finitely generated as a submonoid of itself. -/\nclass group.fg : Prop := (out : (\u22a4 : subgroup G).fg)\n\n/-- An additive group is finitely generated if it is finitely generated as an additive submonoid of\nitself. -/\nclass add_group.fg : Prop := (out : (\u22a4 : add_subgroup H).fg)\n\nattribute [to_additive] group.fg\n\nvariables {G H}\n\nlemma group.fg_def : group.fg G \u2194 (\u22a4 : subgroup G).fg := \u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\nlemma add_group.fg_def : add_group.fg H \u2194 (\u22a4 : add_subgroup H).fg := \u27e8\u03bb h, h.1, \u03bb h, \u27e8h\u27e9\u27e9\n\n/-- An equivalent expression of `group.fg` in terms of `set.finite` instead of `finset`. -/\n@[to_additive \"An equivalent expression of `add_group.fg` in terms of `set.finite` instead of\n`finset`.\"]\nlemma group.fg_iff : group.fg G \u2194\n  \u2203 S : set G, subgroup.closure S = (\u22a4 : subgroup G) \u2227 S.finite :=\n\u27e8\u03bb h, (subgroup.fg_iff \u22a4).1 h.out, \u03bb h, \u27e8(subgroup.fg_iff \u22a4).2 h\u27e9\u27e9\n\n@[to_additive] lemma group.fg_iff' :\n  group.fg G \u2194 \u2203 n (S : finset G), S.card = n \u2227 subgroup.closure (S : set G) = \u22a4 :=\ngroup.fg_def.trans \u27e8\u03bb \u27e8S, hS\u27e9, \u27e8S.card, S, rfl, hS\u27e9, \u03bb \u27e8n, S, hn, hS\u27e9, \u27e8S, hS\u27e9\u27e9\n\n/-- A group is finitely generated if and only if it is finitely generated as a monoid. -/\n@[to_additive add_group.fg_iff_add_monoid.fg \"An additive group is finitely generated if and only\nif it is finitely generated as an additive monoid.\"]\nlemma group.fg_iff_monoid.fg : group.fg G \u2194 monoid.fg G :=\n\u27e8\u03bb h, monoid.fg_def.2 $ (subgroup.fg_iff_submonoid_fg \u22a4).1 (group.fg_def.1 h),\n    \u03bb h, group.fg_def.2 $ (subgroup.fg_iff_submonoid_fg \u22a4).2 (monoid.fg_def.1 h)\u27e9\n\nlemma group_fg.iff_add_fg : group.fg G \u2194 add_group.fg (additive G) :=\n\u27e8\u03bb h, \u27e8(subgroup.fg_iff_add_fg \u22a4).1 h.out\u27e9, \u03bb h, \u27e8(subgroup.fg_iff_add_fg \u22a4).2 h.out\u27e9\u27e9\n\nlemma add_group.fg_iff_mul_fg : add_group.fg H \u2194 group.fg (multiplicative H) :=\n\u27e8\u03bb h, \u27e8(add_subgroup.fg_iff_mul_fg \u22a4).1 h.out\u27e9, \u03bb h, \u27e8(add_subgroup.fg_iff_mul_fg \u22a4).2 h.out\u27e9\u27e9\n\ninstance add_group.fg_of_group_fg [group.fg G] : add_group.fg (additive G) :=\ngroup_fg.iff_add_fg.1 \u2039_\u203a\n\ninstance group.fg_of_mul_group_fg [add_group.fg H] : group.fg (multiplicative H) :=\nadd_group.fg_iff_mul_fg.1 \u2039_\u203a\n\n@[to_additive]\nlemma group.fg_of_surjective {G' : Type*} [group G'] [hG : group.fg G] {f : G \u2192* G'}\n  (hf : function.surjective f) : group.fg G' :=\ngroup.fg_iff_monoid.fg.mpr $ @monoid.fg_of_surjective G _ G' _ (group.fg_iff_monoid.fg.mp hG) f hf\n\n@[to_additive]\ninstance group.fg_range {G' : Type*} [group G'] [group.fg G] (f : G \u2192* G') : group.fg f.range :=\ngroup.fg_of_surjective f.range_restrict_surjective\n\nvariables (G)\n\n/-- The minimum number of generators of a group. -/\n@[to_additive \"The minimum number of generators of an additive group\"]\ndef group.rank [h : group.fg G]\n  [decidable_pred (\u03bb n, \u2203 (S : finset G), S.card = n \u2227 subgroup.closure (S : set G) = \u22a4)] :=\nnat.find (group.fg_iff'.mp h)\n\n@[to_additive] lemma group.rank_spec [h : group.fg G]\n  [decidable_pred (\u03bb n, \u2203 (S : finset G), S.card = n \u2227 subgroup.closure (S : set G) = \u22a4)] :\n  \u2203 S : finset G, S.card = group.rank G \u2227 subgroup.closure (S : set G) = \u22a4 :=\nnat.find_spec (group.fg_iff'.mp h)\n\n@[to_additive] lemma group.rank_le [group.fg G]\n  [decidable_pred (\u03bb n, \u2203 (S : finset G), S.card = n \u2227 subgroup.closure (S : set G) = \u22a4)]\n  {S : finset G} (hS : subgroup.closure (S : set G) = \u22a4) : group.rank G \u2264 S.card :=\nnat.find_le \u27e8S, rfl, hS\u27e9\n\nend group\n\nsection quotient_group\n\n@[to_additive]\ninstance quotient_group.fg [group.fg G] (N : subgroup G) [subgroup.normal N] : group.fg $ G \u29f8 N :=\ngroup.fg_of_surjective $ quotient_group.mk'_surjective N\n\nend quotient_group\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/group_theory/finiteness.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7023539333498247}}
{"text": "/-\nCopyright (c) 2021 Vladimir Goryachev. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies, Vladimir Goryachev, Kyle Miller, Scott Morrison, Eric Rodriguez\n-/\nimport set_theory.cardinal.basic\nimport tactic.ring\n\n/-!\n# Counting on \u2115\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the `count` function, which gives, for any predicate on the natural numbers,\n\"how many numbers under `k` satisfy this predicate?\".\nWe then prove several expected lemmas about `count`, relating it to the cardinality of other\nobjects, and helping to evaluate it for specific `k`.\n\n-/\n\nopen finset\n\nnamespace nat\nvariable (p : \u2115 \u2192 Prop)\n\nsection count\nvariable [decidable_pred p]\n\n/-- Count the number of naturals `k < n` satisfying `p k`. -/\ndef count (n : \u2115) : \u2115 := (list.range n).countp p\n\n@[simp] lemma count_zero : count p 0 = 0 :=\nby rw [count, list.range_zero, list.countp]\n\n/-- A fintype instance for the set relevant to `nat.count`. Locally an instance in locale `count` -/\ndef count_set.fintype (n : \u2115) : fintype {i // i < n \u2227 p i} :=\nbegin\n  apply fintype.of_finset ((finset.range n).filter p),\n  intro x,\n  rw [mem_filter, mem_range],\n  refl,\nend\n\nlocalized \"attribute [instance] nat.count_set.fintype\" in count\n\nlemma count_eq_card_filter_range (n : \u2115) : count p n = ((range n).filter p).card :=\nby { rw [count, list.countp_eq_length_filter], refl, }\n\n/-- `count p n` can be expressed as the cardinality of `{k // k < n \u2227 p k}`. -/\nlemma count_eq_card_fintype (n : \u2115) : count p n = fintype.card {k : \u2115 // k < n \u2227 p k} :=\nby { rw [count_eq_card_filter_range, \u2190fintype.card_of_finset, \u2190count_set.fintype], refl, }\n\nlemma count_succ (n : \u2115) : count p (n + 1) = count p n + (if p n then 1 else 0) :=\nby split_ifs; simp [count, list.range_succ, h]\n\n@[mono] lemma count_monotone : monotone (count p) :=\nmonotone_nat_of_le_succ $ \u03bb n, by by_cases h : p n; simp [count_succ, h]\n\nlemma count_add (a b : \u2115) : count p (a + b) = count p a + count (\u03bb k, p (a + k)) b :=\nbegin\n  have : disjoint ((range a).filter p) (((range b).map $ add_left_embedding a).filter p),\n  { apply disjoint_filter_filter,\n    rw finset.disjoint_left,\n    simp_rw [mem_map, mem_range, add_left_embedding_apply],\n    rintro x hx \u27e8c, _, rfl\u27e9,\n    exact (self_le_add_right _ _).not_lt hx },\n  simp_rw [count_eq_card_filter_range, range_add, filter_union, card_disjoint_union this,\n    filter_map, add_left_embedding, card_map], refl,\nend\n\nlemma count_add' (a b : \u2115) : count p (a + b) = count (\u03bb k, p (k + b)) a + count p b :=\nby { rw [add_comm, count_add, add_comm], simp_rw [add_comm b] }\n\nlemma count_one : count p 1 = if p 0 then 1 else 0 := by simp [count_succ]\n\nlemma count_succ' (n : \u2115) : count p (n + 1) = count (\u03bb k, p (k + 1)) n + if p 0 then 1 else 0 :=\nby rw [count_add', count_one]\n\nvariables {p}\n\n@[simp] lemma count_lt_count_succ_iff {n : \u2115} : count p n < count p (n + 1) \u2194 p n :=\nby by_cases h : p n; simp [count_succ, h]\n\nlemma count_succ_eq_succ_count_iff {n : \u2115} : count p (n + 1) = count p n + 1 \u2194 p n :=\nby by_cases h : p n; simp [h, count_succ]\n\nlemma count_succ_eq_count_iff {n : \u2115} : count p (n + 1) = count p n \u2194 \u00acp n :=\nby by_cases h : p n; simp [h, count_succ]\n\nalias count_succ_eq_succ_count_iff \u2194 _ count_succ_eq_succ_count\nalias count_succ_eq_count_iff \u2194 _ count_succ_eq_count\n\nlemma count_le_cardinal (n : \u2115) : (count p n : cardinal) \u2264 cardinal.mk {k | p k} :=\nbegin\n  rw [count_eq_card_fintype, \u2190 cardinal.mk_fintype],\n  exact cardinal.mk_subtype_mono (\u03bb x hx, hx.2),\nend\n\nlemma lt_of_count_lt_count {a b : \u2115} (h : count p a < count p b) : a < b :=\n(count_monotone p).reflect_lt h\n\nlemma count_strict_mono {m n : \u2115} (hm : p m) (hmn : m < n) : count p m < count p n :=\n(count_lt_count_succ_iff.2 hm).trans_le $ count_monotone _ (nat.succ_le_iff.2 hmn)\n\nlemma count_injective {m n : \u2115} (hm : p m) (hn : p n) (heq : count p m = count p n) : m = n :=\nbegin\n  by_contra' h : m \u2260 n,\n  wlog hmn : m < n,\n  { exact this hn hm heq.symm h.symm (h.lt_or_lt.resolve_left hmn) },\n  { simpa [heq] using count_strict_mono hm hmn }\nend\n\nlemma count_le_card (hp : (set_of p).finite) (n : \u2115) : count p n \u2264 hp.to_finset.card :=\nbegin\n  rw count_eq_card_filter_range,\n  exact finset.card_mono (\u03bb x hx, hp.mem_to_finset.2 (mem_filter.1 hx).2)\nend\n\nlemma count_lt_card {n : \u2115} (hp : (set_of p).finite) (hpn : p n) :\n  count p n < hp.to_finset.card :=\n(count_lt_count_succ_iff.2 hpn).trans_le (count_le_card hp _)\n\nvariable {q : \u2115 \u2192 Prop}\nvariable [decidable_pred q]\n\n\n\nend count\n\nend nat\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7023539304468074}}
{"text": "import algebra\nimport data.real.basic\n\n\n-- This file contains lemmas that are used in `linear_combination.lean`\n\nlemma left_mul_both_sides {\u03b1} [hmul : has_mul \u03b1] (x y coeff : \u03b1) (h : x = y) :\n  coeff * x = coeff * y :=\nby apply congr_arg (has_mul.mul coeff) h\n\n\nlemma sum_two_equations {\u03b1} [hadd : has_add \u03b1] (x1 y1 x2 y2 : \u03b1) (h1 : x1 = y1) (h2: x2 = y2) :\n  x1 + x2 = y1 + y2 :=\nby convert congr (congr_arg has_add.add h1) h2\n\n\nlemma left_minus_right {\u03b1} [ha : add_group \u03b1] (x y : \u03b1) (h : x = y) :\n  x - y = 0 :=\nby apply sub_eq_zero.mpr h\n\n\nlemma all_on_left_equiv {\u03b1} [ha : add_group \u03b1] (x y : \u03b1) :\n  (x = y) = (x - y = 0) :=\nbegin\n  simp,\n  apply iff.intro,\n  { apply left_minus_right },\n  { intro h0,\n    exact sub_eq_zero.mp h0 }\nend\n", "meta": {"author": "agoldb10", "repo": "csci1951x-final-project-ajg", "sha": "89c0dbd70095c6ee43a6220fb7e568482ed6ac94", "save_path": "github-repos/lean/agoldb10-csci1951x-final-project-ajg", "path": "github-repos/lean/agoldb10-csci1951x-final-project-ajg/csci1951x-final-project-ajg-89c0dbd70095c6ee43a6220fb7e568482ed6ac94/src/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672954, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.702305816681113}}
{"text": "/-\nCopyright (c) 2019 Scott Morrison All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n\n! This file was ported from Lean 3 source module category_theory.core\n! leanprover-community/mathlib commit 369525b73f229ccd76a6ec0e0e0bf2be57599768\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Control.EquivFunctor\nimport Mathlib.CategoryTheory.Groupoid\nimport Mathlib.CategoryTheory.Whiskering\nimport Mathlib.CategoryTheory.Types\n\n/-!\n# The core of a category\n\nThe core of a category `C` is the (non-full) subcategory of `C` consisting of all objects,\nand all isomorphisms. We construct it as a `CategoryTheory.Groupoid`.\n\n`CategoryTheory.Core.inclusion : Core C \u2964 C` gives the faithful inclusion into the original\ncategory.\n\nAny functor `F` from a groupoid `G` into `C` factors through `CategoryTheory.Core C`,\nbut this is not functorial with respect to `F`.\n-/\n\nnamespace CategoryTheory\n\nuniverse v\u2081 v\u2082 u\u2081 u\u2082\n\n-- morphism levels before object levels. See note [CategoryTheory universes].\n/-- The core of a category C is the groupoid whose morphisms are all the\nisomorphisms of C. -/\n-- Porting note: This linter does not exist yet\n-- @[nolint has_nonempty_instance]\n\ndef Core (C : Type u\u2081) := C\n#align category_theory.core CategoryTheory.Core\n\nvariable {C : Type u\u2081} [Category.{v\u2081} C]\n\ninstance coreCategory : Groupoid.{v\u2081} (Core C) where\n  Hom (X Y : C) := X \u2245 Y\n  id (X : C) := Iso.refl X\n  comp f g := Iso.trans f g\n  inv {X Y} f := Iso.symm f\n#align category_theory.core_category CategoryTheory.coreCategory\n\nnamespace Core\n\n@[simp]\n/- Porting note: abomination -/\ntheorem id_hom (X : C) : Iso.hom (coreCategory.id X) = @CategoryStruct.id C _ X := by\n  rfl\n#align category_theory.core.id_hom CategoryTheory.Core.id_hom\n\n@[simp]\ntheorem comp_hom {X Y Z : Core C} (f : X \u27f6 Y) (g : Y \u27f6 Z) : (f \u226b g).hom = f.hom \u226b g.hom :=\n  rfl\n#align category_theory.core.comp_hom CategoryTheory.Core.comp_hom\n\nvariable (C)\n\n/-- The core of a category is naturally included in the category. -/\ndef inclusion : Core C \u2964 C where\n  obj := id\n  map f := f.hom\n#align category_theory.core.inclusion CategoryTheory.Core.inclusion\n\n-- porting note: This worked wihtout proof before.\ninstance : Faithful (inclusion C) where\n  map_injective := by\n    intro _ _\n    apply Iso.ext\n\nvariable {C} {G : Type u\u2082} [Groupoid.{v\u2082} G]\n\n-- Note that this function is not functorial\n-- (consider the two functors from [0] to [1], and the natural transformation between them).\n/-- A functor from a groupoid to a category C factors through the core of C. -/\nnoncomputable def functorToCore (F : G \u2964 C) : G \u2964 Core C where\n  obj X := F.obj X\n  map f := \u27e8F.map f, F.map (inv f), _, _\u27e9\n#align category_theory.core.functor_to_core CategoryTheory.Core.functorToCore\n\n/-- We can functorially associate to any functor from a groupoid to the core of a category `C`,\na functor from the groupoid to `C`, simply by composing with the embedding `Core C \u2964 C`.\n-/\ndef forgetFunctorToCore : (G \u2964 Core C) \u2964 G \u2964 C :=\n  (whiskeringRight _ _ _).obj (inclusion C)\n#align category_theory.core.forget_functor_to_core CategoryTheory.Core.forgetFunctorToCore\n\nend Core\n\n/-- `ofEquivFunctor m` lifts a type-level `EquivFunctor`\nto a categorical functor `Core (Type u\u2081) \u2964 Core (Type u\u2082)`.\n-/\ndef ofEquivFunctor (m : Type u\u2081 \u2192 Type u\u2082) [EquivFunctor m] : Core (Type u\u2081) \u2964 Core (Type u\u2082)\n    where\n  obj := m\n  map f := (EquivFunctor.mapEquiv m f.toEquiv).toIso\n  map_id \u03b1 := by apply Iso.ext; funext x; exact congr_fun (EquivFunctor.map_refl' _) x\n  map_comp f g := by\n    apply Iso.ext; funext x; dsimp\n    erw [Iso.toEquiv_comp, EquivFunctor.map_trans']\n    rw [Function.comp]\n#align category_theory.of_equiv_functor CategoryTheory.ofEquivFunctor\n\nend CategoryTheory\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/CategoryTheory/Core.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7023058043630097}}
{"text": "theorem problem1 (A B : Prop) : (A \u2192 B) \u2192 (\u00ac B \u2192 \u00ac A) := sorry\n\ntheorem problem2 (A B : Prop) : \u00ac (A \u2228 B) \u2194 \u00ac A \u2227 \u00ac B := sorry \n\ntheorem problem3 (A B C : Prop) (h : B \u2194 C) : (A \u2228 B) \u2194 (A \u2228 C) := sorry\n\ntheorem problem4 (A B : Prop) : (A \u2192 B) \u2194 \u00ac A \u2228 B := sorry \n\ntheorem problem5 (A B : Prop) : \u00ac A \u2192 A \u2192 B := sorry \n", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "homework5", "sha": "9775e690c2ffbaf37992f8441e2772e837306f15", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework5", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-homework5/homework5-9775e690c2ffbaf37992f8441e2772e837306f15/Hw5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741281688026, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.7021977995890584}}
{"text": "/-\nCopyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying, Kevin Buzzard, Yury Kudryashov\n\n! This file was ported from Lean 3 source module algebra.big_operators.finprod\n! leanprover-community/mathlib commit d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.IndicatorFunction\nimport Mathlib.Tactic.ScopedNS\n\n/-!\n# Finite products and sums over types and sets\n\nWe define products and sums over types and subsets of types, with no finiteness hypotheses.\nAll infinite products and sums are defined to be junk values (i.e. one or zero).\nThis approach is sometimes easier to use than `Finset.sum`,\nwhen issues arise with `Finset` and `Fintype` being data.\n\n## Main definitions\n\nWe use the following variables:\n\n* `\u03b1`, `\u03b2` - types with no structure;\n* `s`, `t` - sets\n* `M`, `N` - additive or multiplicative commutative monoids\n* `f`, `g` - functions\n\nDefinitions in this file:\n\n* `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite.\n   Zero otherwise.\n\n* `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if\n   it's finite. One otherwise.\n\n## Notation\n\n* `\u2211\u1da0 i, f i` and `\u2211\u1da0 i : \u03b1, f i` for `finsum f`\n\n* `\u220f\u1da0 i, f i` and `\u220f\u1da0 i : \u03b1, f i` for `finprod f`\n\nThis notation works for functions `f : p \u2192 M`, where `p : Prop`, so the following works:\n\n* `\u2211\u1da0 i \u2208 s, f i`, where `f : \u03b1 \u2192 M`, `s : Set \u03b1` : sum over the set `s`;\n* `\u2211\u1da0 n < 5, f n`, where `f : \u2115 \u2192 M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`;\n* `\u220f\u1da0 (n >= -2) (hn : n < 3), f n`, where `f : \u2124 \u2192 M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`.\n\n## Implementation notes\n\n`Finsum` and `Finprod` is \"yet another way of doing finite sums and products in Lean\". However\nexperiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings\nwhere the user is not interested in computability and wants to do reasoning without running into\ntypeclass diamonds caused by the constructive finiteness used in definitions such as `Finset` and\n`Fintype`. By sticking solely to `Set.finite` we avoid these problems. We are aware that there are\nother solutions but for beginner mathematicians this approach is easier in practice.\n\nAnother application is the construction of a partition of unity from a collection of \u201cbump\u201d\nfunction. In this case the finite set depends on the point and it's convenient to have a definition\nthat does not mention the set explicitly.\n\nThe first arguments in all definitions and lemmas is the codomain of the function of the big\noperator. This is necessary for the heuristic in `@[to_additive]`.\nSee the documentation of `to_additive.attr` for more information.\n\nWe did not add `IsFinite (X : Type) : Prop`, because it is simply `Nonempty (Fintype X)`.\n\n## Tags\n\nfinsum, finprod, finite sum, finite product\n-/\n\n\nopen Function Set\n\n/-!\n### Definition and relation to `Finset.sum` and `Finset.prod`\n-/\n\n-- Porting note: Used to be section Sort\nsection sort\n\nvariable {G M N : Type _} {\u03b1 \u03b2 \u03b9 : Sort _} [CommMonoid M] [CommMonoid N]\n\nopen BigOperators\n\nsection\n\n/- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas\nwith `Classical.dec` in their statement. -/\nopen Classical\n\n\n-- Porting note: replaced irreducible_def with def and an irreducible tag here.\n/-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero\notherwise. -/\n@[irreducible]\nnoncomputable def finsum {M \u03b1} [AddCommMonoid M] (f : \u03b1 \u2192 M) : M :=\n  if h : (support (f \u2218 PLift.down)).Finite then \u2211 i in h.toFinset, f i.down else 0\n#align finsum finsum\n\n-- Porting note: replaced irreducible_def with def and an irreducible tag here.\n/-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's\nfinite. One otherwise. -/\n@[to_additive existing (attr:= irreducible)]\nnoncomputable def finprod (f : \u03b1 \u2192 M) : M :=\n  if h : (mulSupport (f \u2218 PLift.down)).Finite then \u220f i in h.toFinset, f i.down else 1\n#align finprod finprod\n\nend\n\nopen Std.ExtendedBinder\n\n-- Porting note: removed scoped[BigOperators], `notation3` doesn't mesh with `scoped[Foo]`\n\n/-- `\u2211\u1da0 x, f x` is notation for `finsum f`. It is the sum of `f x`, where `x` ranges over the the\nsupport of `f`, if it's finite, zero otherwise. Taking the sum over multiple arguments or\nconditions is possible, e.g. `\u220f\u1da0 (x) (y), f x y` and `\u220f\u1da0 (x) (h: x \u2208 s), f x`-/\nnotation3\"\u2211\u1da0 \"(...)\", \"r:(scoped f => finsum f) => r\n\n-- Porting note: removed scoped[BigOperators], `notation3` doesn't mesh with `scoped[Foo]`\n\n/-- `\u220f\u1da0 x, f x` is notation for `finprod f`. It is the sum of `f x`, where `x` ranges over the the\nmultiplicative support of `f`, if it's finite, one otherwise. Taking the product over multiple\narguments or conditions is possible, e.g. `\u220f\u1da0 (x) (y), f x y` and `\u220f\u1da0 (x) (h: x \u2208 s), f x`-/\nnotation3\"\u220f\u1da0 \"(...)\", \"r:(scoped f => finprod f) => r\n\n-- Porting note: The following ports the lean3 notation for this file, but is currently very fickle.\n\n-- syntax (name := bigfinsum) \"\u2211\u1da0\" extBinders \", \" term:67 : term\n-- macro_rules (kind := bigfinsum)\n--   | `(\u2211\u1da0 $x:ident, $p) => `(finsum (fun $x:ident \u21a6 $p))\n--   | `(\u2211\u1da0 $x:ident : $t, $p) => `(finsum (fun $x:ident : $t \u21a6 $p))\n--   | `(\u2211\u1da0 $x:ident $b:binderPred, $p) =>\n--     `(finsum fun $x => (finsum (\u03b1 := satisfies_binder_pred% $x $b) (fun _ => $p)))\n\n--   | `(\u2211\u1da0 ($x:ident) ($h:ident : $t), $p) =>\n--       `(finsum fun ($x) => finsum (\u03b1 := $t) (fun $h => $p))\n--   | `(\u2211\u1da0 ($x:ident : $_) ($h:ident : $t), $p) =>\n--       `(finsum fun ($x) => finsum (\u03b1 := $t) (fun $h => $p))\n\n--   | `(\u2211\u1da0 ($x:ident) ($y:ident), $p) =>\n--       `(finsum fun $x => (finsum fun $y => $p))\n--   | `(\u2211\u1da0 ($x:ident) ($y:ident) ($h:ident : $t), $p) =>\n--       `(finsum fun $x => (finsum fun $y => (finsum (\u03b1 := $t) fun $h => $p)))\n\n--   | `(\u2211\u1da0 ($x:ident) ($y:ident) ($z:ident), $p) =>\n--       `(finsum fun $x => (finsum fun $y => (finsum fun $z => $p)))\n--   | `(\u2211\u1da0 ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>\n--       `(finsum fun $x => (finsum fun $y => (finsum fun $z => (finsum (\u03b1 := $t) fun $h => $p))))\n--\n--\n-- syntax (name := bigfinprod) \"\u220f\u1da0 \" extBinders \", \" term:67 : term\n-- macro_rules (kind := bigfinprod)\n--   | `(\u220f\u1da0 $x:ident, $p) => `(finprod (fun $x:ident \u21a6 $p))\n--   | `(\u220f\u1da0 $x:ident : $t, $p) => `(finprod (fun $x:ident : $t \u21a6 $p))\n--   | `(\u220f\u1da0 $x:ident $b:binderPred, $p) =>\n--     `(finprod fun $x => (finprod (\u03b1 := satisfies_binder_pred% $x $b) (fun _ => $p)))\n\n--   | `(\u220f\u1da0 ($x:ident) ($h:ident : $t), $p) =>\n--       `(finprod fun ($x) => finprod (\u03b1 := $t) (fun $h => $p))\n--   | `(\u220f\u1da0 ($x:ident : $_) ($h:ident : $t), $p) =>\n--       `(finprod fun ($x) => finprod (\u03b1 := $t) (fun $h => $p))\n\n--   | `(\u220f\u1da0 ($x:ident) ($y:ident), $p) =>\n--       `(finprod fun $x => (finprod fun $y => $p))\n--   | `(\u220f\u1da0 ($x:ident) ($y:ident) ($h:ident : $t), $p) =>\n--       `(finprod fun $x => (finprod fun $y => (finprod (\u03b1 := $t) fun $h => $p)))\n\n--   | `(\u220f\u1da0 ($x:ident) ($y:ident) ($z:ident), $p) =>\n--       `(finprod fun $x => (finprod fun $y => (finprod fun $z => $p)))\n--   | `(\u220f\u1da0 ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>\n--       `(finprod fun $x => (finprod fun $y => (finprod fun $z =>\n--          (finprod (\u03b1 := $t) fun $h => $p))))\n\n@[to_additive]\ntheorem finprod_eq_prod_pLift_of_mulSupport_toFinset_subset {f : \u03b1 \u2192 M}\n    (hf : (mulSupport (f \u2218 PLift.down)).Finite) {s : Finset (PLift \u03b1)} (hs : hf.toFinset \u2286 s) :\n    (\u220f\u1da0 i, f i) = \u220f i in s, f i.down := by\n  rw [finprod, dif_pos]\n  refine' Finset.prod_subset hs fun x _ hxf => _\n  rwa [hf.mem_toFinset, nmem_mulSupport] at hxf\n#align\n  finprod_eq_prod_plift_of_mul_support_to_finset_subset\n  finprod_eq_prod_pLift_of_mulSupport_toFinset_subset\n#align\n  finsum_eq_sum_plift_of_support_to_finset_subset\n  finsum_eq_sum_pLift_of_support_toFinset_subset\n\n@[to_additive]\ntheorem finprod_eq_prod_pLift_of_mulSupport_subset {f : \u03b1 \u2192 M} {s : Finset (PLift \u03b1)}\n    (hs : mulSupport (f \u2218 PLift.down) \u2286 s) : (\u220f\u1da0 i, f i) = \u220f i in s, f i.down :=\n  finprod_eq_prod_pLift_of_mulSupport_toFinset_subset (s.finite_toSet.subset hs) fun x hx =>\n    by\n    rw [Finite.mem_toFinset] at hx\n    exact hs hx\n#align finprod_eq_prod_plift_of_mul_support_subset finprod_eq_prod_pLift_of_mulSupport_subset\n#align finsum_eq_sum_plift_of_support_subset finsum_eq_sum_pLift_of_support_subset\n\n@[to_additive (attr := simp)]\ntheorem finprod_one : (\u220f\u1da0 _i : \u03b1, (1 : M)) = 1 := by\n  have : (mulSupport fun x : PLift \u03b1 => (fun _ => 1 : \u03b1 \u2192 M) x.down) \u2286 (\u2205 : Finset (PLift \u03b1)) :=\n    fun x h => by simp at h\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset this, Finset.prod_empty]\n#align finprod_one finprod_one\n#align finsum_zero finsum_zero\n\n@[to_additive]\ntheorem finprod_of_isEmpty [IsEmpty \u03b1] (f : \u03b1 \u2192 M) : (\u220f\u1da0 i, f i) = 1 := by\n  rw [\u2190 finprod_one]\n  congr\n  simp\n#align finprod_of_is_empty finprod_of_isEmpty\n#align finsum_of_is_empty finsum_of_isEmpty\n\n@[to_additive (attr := simp)]\ntheorem finprod_false (f : False \u2192 M) : (\u220f\u1da0 i, f i) = 1 :=\n  finprod_of_isEmpty _\n#align finprod_false finprod_false\n#align finsum_false finsum_false\n\n@[to_additive]\ntheorem finprod_eq_single (f : \u03b1 \u2192 M) (a : \u03b1) (ha : \u2200 (x) (_ : x \u2260 a), f x = 1) :\n    (\u220f\u1da0 x, f x) = f a := by\n  have : mulSupport (f \u2218 PLift.down) \u2286 ({PLift.up a} : Finset (PLift \u03b1)) :=\n    by\n    intro x\n    contrapose\n    simpa [PLift.eq_up_iff_down_eq] using ha x.down\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset this, Finset.prod_singleton]\n#align finprod_eq_single finprod_eq_single\n#align finsum_eq_single finsum_eq_single\n\n@[to_additive]\ntheorem finprod_unique [Unique \u03b1] (f : \u03b1 \u2192 M) : (\u220f\u1da0 i, f i) = f default :=\n  finprod_eq_single f default fun _x hx => (hx <| Unique.eq_default _).elim\n#align finprod_unique finprod_unique\n#align finsum_unique finsum_unique\n\n@[to_additive (attr := simp)]\ntheorem finprod_true (f : True \u2192 M) : (\u220f\u1da0 i, f i) = f trivial :=\n  @finprod_unique M True _ \u27e8\u27e8trivial\u27e9, fun _ => rfl\u27e9 f\n#align finprod_true finprod_true\n#align finsum_true finsum_true\n\n@[to_additive]\ntheorem finprod_eq_dif {p : Prop} [Decidable p] (f : p \u2192 M) :\n    (\u220f\u1da0 i, f i) = if h : p then f h else 1 := by\n  split_ifs with h\n  \u00b7 haveI : Unique p := \u27e8\u27e8h\u27e9, fun _ => rfl\u27e9\n    exact finprod_unique f\n  \u00b7 haveI : IsEmpty p := \u27e8h\u27e9\n    exact finprod_of_isEmpty f\n#align finprod_eq_dif finprod_eq_dif\n#align finsum_eq_dif finsum_eq_dif\n\n@[to_additive]\ntheorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : (\u220f\u1da0 _i : p, x) = if p then x else 1 :=\n  finprod_eq_dif fun _ => x\n#align finprod_eq_if finprod_eq_if\n#align finsum_eq_if finsum_eq_if\n\n@[to_additive]\ntheorem finprod_congr {f g : \u03b1 \u2192 M} (h : \u2200 x, f x = g x) : finprod f = finprod g :=\n  congr_arg _ <| funext h\n#align finprod_congr finprod_congr\n#align finsum_congr finsum_congr\n\n@[to_additive (attr := congr)]\ntheorem finprod_congr_Prop {p q : Prop} {f : p \u2192 M} {g : q \u2192 M} (hpq : p = q)\n    (hfg : \u2200 h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by\n  subst q\n  exact finprod_congr hfg\n#align finprod_congr_Prop finprod_congr_Prop\n#align finsum_congr_Prop finsum_congr_Prop\n\n/-- To prove a property of a finite product, it suffices to prove that the property is\nmultiplicative and holds on the factors. -/\n@[to_additive\n      \"To prove a property of a finite sum, it suffices to prove that the property is\n      additive and holds on the summands.\"]\ntheorem finprod_induction {f : \u03b1 \u2192 M} (p : M \u2192 Prop) (hp\u2080 : p 1)\n    (hp\u2081 : \u2200 x y, p x \u2192 p y \u2192 p (x * y)) (hp\u2082 : \u2200 i, p (f i)) : p (\u220f\u1da0 i, f i) := by\n  rw [finprod]\n  split_ifs\n  exacts[Finset.prod_induction _ _ hp\u2081 hp\u2080 fun i _ => hp\u2082 _, hp\u2080]\n#align finprod_induction finprod_induction\n#align finsum_induction finsum_induction\n\ntheorem finprod_nonneg {R : Type _} [OrderedCommSemiring R] {f : \u03b1 \u2192 R} (hf : \u2200 x, 0 \u2264 f x) :\n    0 \u2264 \u220f\u1da0 x, f x :=\n  finprod_induction (fun x => 0 \u2264 x) zero_le_one (fun _ _ => mul_nonneg) hf\n#align finprod_nonneg finprod_nonneg\n\n@[to_additive finsum_nonneg]\ntheorem one_le_finprod' {M : Type _} [OrderedCommMonoid M] {f : \u03b1 \u2192 M} (hf : \u2200 i, 1 \u2264 f i) :\n    1 \u2264 \u220f\u1da0 i, f i :=\n  finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf\n#align one_le_finprod' one_le_finprod'\n#align finsum_nonneg finsum_nonneg\n\n@[to_additive]\ntheorem MonoidHom.map_finprod_pLift (f : M \u2192* N) (g : \u03b1 \u2192 M)\n    (h : (mulSupport <| g \u2218 PLift.down).Finite) : f (\u220f\u1da0 x, g x) = \u220f\u1da0 x, f (g x) := by\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset h.coe_toFinset.ge,\n    finprod_eq_prod_pLift_of_mulSupport_subset, f.map_prod]\n  rw [h.coe_toFinset]\n  exact mulSupport_comp_subset f.map_one (g \u2218 PLift.down)\n#align monoid_hom.map_finprod_plift MonoidHom.map_finprod_pLift\n#align add_monoid_hom.map_finsum_plift AddMonoidHom.map_finsum_pLift\n\n@[to_additive]\ntheorem MonoidHom.map_finprod_Prop {p : Prop} (f : M \u2192* N) (g : p \u2192 M) :\n    f (\u220f\u1da0 x, g x) = \u220f\u1da0 x, f (g x) :=\n  f.map_finprod_pLift g (Set.toFinite _)\n#align monoid_hom.map_finprod_Prop MonoidHom.map_finprod_Prop\n#align add_monoid_hom.map_finsum_Prop AddMonoidHom.map_finsum_Prop\n\n@[to_additive]\ntheorem MonoidHom.map_finprod_of_preimage_one (f : M \u2192* N) (hf : \u2200 x, f x = 1 \u2192 x = 1) (g : \u03b1 \u2192 M) :\n    f (\u220f\u1da0 i, g i) = \u220f\u1da0 i, f (g i) := by\n  by_cases hg : (mulSupport <| g \u2218 PLift.down).Finite; \u00b7 exact f.map_finprod_pLift g hg\n  rw [finprod, dif_neg, f.map_one, finprod, dif_neg]\n  exacts[Infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg]\n#align monoid_hom.map_finprod_of_preimage_one MonoidHom.map_finprod_of_preimage_one\n#align add_monoid_hom.map_finsum_of_preimage_zero AddMonoidHom.map_finsum_of_preimage_zero\n\n@[to_additive]\ntheorem MonoidHom.map_finprod_of_injective (g : M \u2192* N) (hg : Injective g) (f : \u03b1 \u2192 M) :\n    g (\u220f\u1da0 i, f i) = \u220f\u1da0 i, g (f i) :=\n  g.map_finprod_of_preimage_one (fun _ => (hg.eq_iff' g.map_one).mp) f\n#align monoid_hom.map_finprod_of_injective MonoidHom.map_finprod_of_injective\n#align add_monoid_hom.map_finsum_of_injective AddMonoidHom.map_finsum_of_injective\n\n@[to_additive]\ntheorem MulEquiv.map_finprod (g : M \u2243* N) (f : \u03b1 \u2192 M) : g (\u220f\u1da0 i, f i) = \u220f\u1da0 i, g (f i) :=\n  g.toMonoidHom.map_finprod_of_injective (EquivLike.injective g) f\n#align mul_equiv.map_finprod MulEquiv.map_finprod\n#align add_equiv.map_finsum AddEquiv.map_finsum\n\ntheorem finsum_smul {R M : Type _} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]\n    (f : \u03b9 \u2192 R) (x : M) : (\u2211\u1da0 i, f i) \u2022 x = \u2211\u1da0 i, f i \u2022 x := by\n  rcases eq_or_ne x 0 with (rfl | hx); \u00b7 simp\n  exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _\n#align finsum_smul finsum_smul\n\ntheorem smul_finsum {R M : Type _} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]\n    (c : R) (f : \u03b9 \u2192 M) : (c \u2022 \u2211\u1da0 i, f i) = \u2211\u1da0 i, c \u2022 f i := by\n  rcases eq_or_ne c 0 with (rfl | hc); \u00b7 simp\n  exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _\n#align smul_finsum smul_finsum\n\n@[to_additive]\ntheorem finprod_inv_distrib [DivisionCommMonoid G] (f : \u03b1 \u2192 G) : (\u220f\u1da0 x, (f x)\u207b\u00b9) = (\u220f\u1da0 x, f x)\u207b\u00b9 :=\n  ((MulEquiv.inv G).map_finprod f).symm\n#align finprod_inv_distrib finprod_inv_distrib\n#align finsum_neg_distrib finsum_neg_distrib\n\nend sort\n\n-- Porting note: Used to be section Type\nsection type\n\nvariable {\u03b1 \u03b2 \u03b9 G M N : Type _} [CommMonoid M] [CommMonoid N]\n\nopen BigOperators\n\n@[to_additive]\ntheorem finprod_eq_mulIndicator_apply (s : Set \u03b1) (f : \u03b1 \u2192 M) (a : \u03b1) :\n    (\u220f\u1da0 _h : a \u2208 s, f a) = mulIndicator s f a := by\n  classical convert finprod_eq_if (M := M) (p := a \u2208 s) (x := f a)\n#align finprod_eq_mul_indicator_apply finprod_eq_mulIndicator_apply\n#align finsum_eq_indicator_apply finsum_eq_indicator_apply\n\n@[to_additive (attr := simp)]\ntheorem finprod_mem_mulSupport (f : \u03b1 \u2192 M) (a : \u03b1) : (\u220f\u1da0 _h : f a \u2260 1, f a) = f a := by\n  rw [\u2190 mem_mulSupport, finprod_eq_mulIndicator_apply, mulIndicator_mulSupport]\n#align finprod_mem_mul_support finprod_mem_mulSupport\n#align finsum_mem_support finsum_mem_support\n\n@[to_additive]\ntheorem finprod_mem_def (s : Set \u03b1) (f : \u03b1 \u2192 M) : (\u220f\u1da0 a \u2208 s, f a) = \u220f\u1da0 a, mulIndicator s f a :=\n  finprod_congr <| finprod_eq_mulIndicator_apply s f\n#align finprod_mem_def finprod_mem_def\n#align finsum_mem_def finsum_mem_def\n\n@[to_additive]\ntheorem finprod_eq_prod_of_mulSupport_subset (f : \u03b1 \u2192 M) {s : Finset \u03b1} (h : mulSupport f \u2286 s) :\n    (\u220f\u1da0 i, f i) = \u220f i in s, f i := by\n  have A : mulSupport (f \u2218 PLift.down) = Equiv.plift.symm '' mulSupport f :=\n    by\n    rw [mulSupport_comp_eq_preimage]\n    exact (Equiv.plift.symm.image_eq_preimage _).symm\n  have : mulSupport (f \u2218 PLift.down) \u2286 s.map Equiv.plift.symm.toEmbedding :=\n    by\n    rw [A, Finset.coe_map]\n    exact image_subset _ h\n  rw [finprod_eq_prod_pLift_of_mulSupport_subset this]\n  simp only [Finset.prod_map, Equiv.coe_toEmbedding]\n  congr\n#align finprod_eq_prod_of_mul_support_subset finprod_eq_prod_of_mulSupport_subset\n#align finsum_eq_sum_of_support_subset finsum_eq_sum_of_support_subset\n\n@[to_additive]\ntheorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : \u03b1 \u2192 M) (hf : (mulSupport f).Finite)\n    {s : Finset \u03b1} (h : hf.toFinset \u2286 s) : (\u220f\u1da0 i, f i) = \u220f i in s, f i :=\n  finprod_eq_prod_of_mulSupport_subset _ fun _ hx => h <| hf.mem_toFinset.2 hx\n#align finprod_eq_prod_of_mul_support_to_finset_subset finprod_eq_prod_of_mulSupport_toFinset_subset\n#align finsum_eq_sum_of_support_to_finset_subset finsum_eq_sum_of_support_toFinset_subset\n\n@[to_additive]\ntheorem finprod_eq_finset_prod_of_mulSupport_subset (f : \u03b1 \u2192 M) {s : Finset \u03b1}\n    (h : mulSupport f \u2286 (s : Set \u03b1)) : (\u220f\u1da0 i, f i) = \u220f i in s, f i :=\n  haveI h' : (s.finite_toSet.subset h).toFinset \u2286 s := by\n    simpa [\u2190 Finset.coe_subset, Set.coe_toFinset]\n  finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h'\n#align finprod_eq_finset_prod_of_mul_support_subset finprod_eq_finset_prod_of_mulSupport_subset\n#align finsum_eq_finset_sum_of_support_subset finsum_eq_finset_sum_of_support_subset\n\n@[to_additive]\ntheorem finprod_def (f : \u03b1 \u2192 M) [Decidable (mulSupport f).Finite] :\n    (\u220f\u1da0 i : \u03b1, f i) = if h : (mulSupport f).Finite then \u220f i in h.toFinset, f i else 1 := by\n  split_ifs with h\n  \u00b7 exact finprod_eq_prod_of_mulSupport_toFinset_subset _ h (Finset.Subset.refl _)\n  \u00b7 rw [finprod, dif_neg]\n    rw [mulSupport_comp_eq_preimage]\n    exact mt (fun hf => hf.of_preimage Equiv.plift.surjective) h\n#align finprod_def finprod_def\n#align finsum_def finsum_def\n\n@[to_additive]\ntheorem finprod_of_infinite_mulSupport {f : \u03b1 \u2192 M} (hf : (mulSupport f).Infinite) :\n    (\u220f\u1da0 i, f i) = 1 := by classical rw [finprod_def, dif_neg hf]\n#align finprod_of_infinite_mul_support finprod_of_infinite_mulSupport\n#align finsum_of_infinite_support finsum_of_infinite_support\n\n@[to_additive]\ntheorem finprod_eq_prod (f : \u03b1 \u2192 M) (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 i : \u03b1, f i) = \u220f i in hf.toFinset, f i := by classical rw [finprod_def, dif_pos hf]\n#align finprod_eq_prod finprod_eq_prod\n#align finsum_eq_sum finsum_eq_sum\n\n@[to_additive]\ntheorem finprod_eq_prod_of_fintype [Fintype \u03b1] (f : \u03b1 \u2192 M) : (\u220f\u1da0 i : \u03b1, f i) = \u220f i, f i :=\n  finprod_eq_prod_of_mulSupport_toFinset_subset _ (Set.toFinite _) <| Finset.subset_univ _\n#align finprod_eq_prod_of_fintype finprod_eq_prod_of_fintype\n#align finsum_eq_sum_of_fintype finsum_eq_sum_of_fintype\n\n@[to_additive]\ntheorem finprod_cond_eq_prod_of_cond_iff (f : \u03b1 \u2192 M) {p : \u03b1 \u2192 Prop} {t : Finset \u03b1}\n    (h : \u2200 {x}, f x \u2260 1 \u2192 (p x \u2194 x \u2208 t)) : (\u220f\u1da0 (i) (_hi : p i), f i) = \u220f i in t, f i := by\n  set s := { x | p x }\n  have : mulSupport (s.mulIndicator f) \u2286 t :=\n    by\n    rw [Set.mulSupport_mulIndicator]\n    intro x hx\n    exact (h hx.2).1 hx.1\n  erw [finprod_mem_def, finprod_eq_prod_of_mulSupport_subset _ this]\n  refine' Finset.prod_congr rfl fun x hx => mulIndicator_apply_eq_self.2 fun hxs => _\n  contrapose! hxs\n  exact (h hxs).2 hx\n#align finprod_cond_eq_prod_of_cond_iff finprod_cond_eq_prod_of_cond_iff\n#align finsum_cond_eq_sum_of_cond_iff finsum_cond_eq_sum_of_cond_iff\n\n@[to_additive]\ntheorem finprod_cond_ne (f : \u03b1 \u2192 M) (a : \u03b1) [DecidableEq \u03b1] (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 (i) (_h : i \u2260 a), f i) = \u220f i in hf.toFinset.erase a, f i := by\n  apply finprod_cond_eq_prod_of_cond_iff\n  intro x hx\n  rw [Finset.mem_erase, Finite.mem_toFinset, mem_mulSupport]\n  exact \u27e8fun h => And.intro h hx, fun h => h.1\u27e9\n#align finprod_cond_ne finprod_cond_ne\n#align finsum_cond_ne finsum_cond_ne\n\n@[to_additive]\ntheorem finprod_mem_eq_prod_of_inter_mulSupport_eq (f : \u03b1 \u2192 M) {s : Set \u03b1} {t : Finset \u03b1}\n    (h : s \u2229 mulSupport f = t.toSet \u2229 mulSupport f) : (\u220f\u1da0 i \u2208 s, f i) = \u220f i in t, f i :=\n  finprod_cond_eq_prod_of_cond_iff _ <| by\n    intro x hxf\n    rw [\u2190 mem_mulSupport] at hxf\n    refine \u27e8fun hx => ?_, fun hx => ?_\u27e9\n    \u00b7 refine ((mem_inter_iff x t (mulSupport f)).mp ?_).1\n      rw [\u2190 Set.ext_iff.mp h x, mem_inter_iff]\n      exact \u27e8hx, hxf\u27e9\n    \u00b7 refine ((mem_inter_iff x s (mulSupport f)).mp ?_).1\n      rw [Set.ext_iff.mp h x, mem_inter_iff]\n      exact \u27e8hx, hxf\u27e9\n#align finprod_mem_eq_prod_of_inter_mul_support_eq finprod_mem_eq_prod_of_inter_mulSupport_eq\n#align finsum_mem_eq_sum_of_inter_support_eq finsum_mem_eq_sum_of_inter_support_eq\n\n@[to_additive]\ntheorem finprod_mem_eq_prod_of_subset (f : \u03b1 \u2192 M) {s : Set \u03b1} {t : Finset \u03b1}\n    (h\u2081 : s \u2229 mulSupport f \u2286 t) (h\u2082 : \u2191t \u2286 s) : (\u220f\u1da0 i \u2208 s, f i) = \u220f i in t, f i :=\n  finprod_cond_eq_prod_of_cond_iff _ fun hx => \u27e8fun h => h\u2081 \u27e8h, hx\u27e9, fun h => h\u2082 h\u27e9\n#align finprod_mem_eq_prod_of_subset finprod_mem_eq_prod_of_subset\n#align finsum_mem_eq_sum_of_subset finsum_mem_eq_sum_of_subset\n\n@[to_additive]\ntheorem finprod_mem_eq_prod (f : \u03b1 \u2192 M) {s : Set \u03b1} (hf : (s \u2229 mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in hf.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp [inter_assoc]\n#align finprod_mem_eq_prod finprod_mem_eq_prod\n#align finsum_mem_eq_sum finsum_mem_eq_sum\n\n@[to_additive]\ntheorem finprod_mem_eq_prod_filter (f : \u03b1 \u2192 M) (s : Set \u03b1) [DecidablePred (\u00b7 \u2208 s)]\n    (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in Finset.filter (\u00b7 \u2208 s) hf.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by\n    ext x\n    simp [and_comm]\n#align finprod_mem_eq_prod_filter finprod_mem_eq_prod_filter\n#align finsum_mem_eq_sum_filter finsum_mem_eq_sum_filter\n\n@[to_additive]\ntheorem finprod_mem_eq_toFinset_prod (f : \u03b1 \u2192 M) (s : Set \u03b1) [Fintype s] :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in s.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp_rw [coe_toFinset s]\n#align finprod_mem_eq_to_finset_prod finprod_mem_eq_toFinset_prod\n#align finsum_mem_eq_to_finset_sum finsum_mem_eq_toFinset_sum\n\n@[to_additive]\ntheorem finprod_mem_eq_finite_toFinset_prod (f : \u03b1 \u2192 M) {s : Set \u03b1} (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f i in hs.toFinset, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by rw [hs.coe_toFinset]\n#align finprod_mem_eq_finite_to_finset_prod finprod_mem_eq_finite_toFinset_prod\n#align finsum_mem_eq_finite_to_finset_sum finsum_mem_eq_finite_toFinset_sum\n\n@[to_additive]\ntheorem finprod_mem_finset_eq_prod (f : \u03b1 \u2192 M) (s : Finset \u03b1) : (\u220f\u1da0 i \u2208 s, f i) = \u220f i in s, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl\n#align finprod_mem_finset_eq_prod finprod_mem_finset_eq_prod\n#align finsum_mem_finset_eq_sum finsum_mem_finset_eq_sum\n\n@[to_additive]\ntheorem finprod_mem_coe_finset (f : \u03b1 \u2192 M) (s : Finset \u03b1) :\n    (\u220f\u1da0 i \u2208 (s : Set \u03b1), f i) = \u220f i in s, f i :=\n  finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl\n#align finprod_mem_coe_finset finprod_mem_coe_finset\n#align finsum_mem_coe_finset finsum_mem_coe_finset\n\n@[to_additive]\ntheorem finprod_mem_eq_one_of_infinite {f : \u03b1 \u2192 M} {s : Set \u03b1} (hs : (s \u2229 mulSupport f).Infinite) :\n    (\u220f\u1da0 i \u2208 s, f i) = 1 := by\n  rw [finprod_mem_def]\n  apply finprod_of_infinite_mulSupport\n  rwa [\u2190 mulSupport_mulIndicator] at hs\n#align finprod_mem_eq_one_of_infinite finprod_mem_eq_one_of_infinite\n#align finsum_mem_eq_zero_of_infinite finsum_mem_eq_zero_of_infinite\n\n@[to_additive]\ntheorem finprod_mem_eq_one_of_forall_eq_one {f : \u03b1 \u2192 M} {s : Set \u03b1} (h : \u2200 x \u2208 s, f x = 1) :\n    (\u220f\u1da0 i \u2208 s, f i) = 1 := by simp (config := { contextual := true }) [h]\n#align finprod_mem_eq_one_of_forall_eq_one finprod_mem_eq_one_of_forall_eq_one\n#align finsum_mem_eq_zero_of_forall_eq_zero finsum_mem_eq_zero_of_forall_eq_zero\n\n@[to_additive]\ntheorem finprod_mem_inter_mulSupport (f : \u03b1 \u2192 M) (s : Set \u03b1) :\n    (\u220f\u1da0 i \u2208 s \u2229 mulSupport f, f i) = \u220f\u1da0 i \u2208 s, f i := by\n  rw [finprod_mem_def, finprod_mem_def, mulIndicator_inter_mulSupport]\n#align finprod_mem_inter_mul_support finprod_mem_inter_mulSupport\n#align finsum_mem_inter_support finsum_mem_inter_support\n\n@[to_additive]\ntheorem finprod_mem_inter_mulSupport_eq (f : \u03b1 \u2192 M) (s t : Set \u03b1)\n    (h : s \u2229 mulSupport f = t \u2229 mulSupport f) : (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_inter_mulSupport, h, finprod_mem_inter_mulSupport]\n#align finprod_mem_inter_mul_support_eq finprod_mem_inter_mulSupport_eq\n#align finsum_mem_inter_support_eq finsum_mem_inter_support_eq\n\n@[to_additive]\ntheorem finprod_mem_inter_mulSupport_eq' (f : \u03b1 \u2192 M) (s t : Set \u03b1)\n    (h : \u2200 x \u2208 mulSupport f, x \u2208 s \u2194 x \u2208 t) : (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 t, f i := by\n  apply finprod_mem_inter_mulSupport_eq\n  ext x\n  exact and_congr_left (h x)\n#align finprod_mem_inter_mul_support_eq' finprod_mem_inter_mulSupport_eq'\n#align finsum_mem_inter_support_eq' finsum_mem_inter_support_eq'\n\n@[to_additive]\ntheorem finprod_mem_univ (f : \u03b1 \u2192 M) : (\u220f\u1da0 i \u2208 @Set.univ \u03b1, f i) = \u220f\u1da0 i : \u03b1, f i :=\n  finprod_congr fun _ => finprod_true _\n#align finprod_mem_univ finprod_mem_univ\n#align finsum_mem_univ finsum_mem_univ\n\nvariable {f g : \u03b1 \u2192 M} {a b : \u03b1} {s t : Set \u03b1}\n\n@[to_additive]\ntheorem finprod_mem_congr (h\u2080 : s = t) (h\u2081 : \u2200 x \u2208 t, f x = g x) :\n    (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 t, g i :=\n  h\u2080.symm \u25b8 finprod_congr fun i => finprod_congr_Prop rfl (h\u2081 i)\n#align finprod_mem_congr finprod_mem_congr\n#align finsum_mem_congr finsum_mem_congr\n\n@[to_additive]\ntheorem finprod_eq_one_of_forall_eq_one {f : \u03b1 \u2192 M} (h : \u2200 x, f x = 1) : (\u220f\u1da0 i, f i) = 1 := by\n  simp (config := { contextual := true }) [h]\n#align finprod_eq_one_of_forall_eq_one finprod_eq_one_of_forall_eq_one\n#align finsum_eq_zero_of_forall_eq_zero finsum_eq_zero_of_forall_eq_zero\n\n/-!\n### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication\n-/\n\n\n/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals\nthe product of `f i` multiplied by the product of `g i`. -/\n@[to_additive\n      \"If the additive supports of `f` and `g` are finite, then the sum of `f i + g i`\n      equals the sum of `f i` plus the sum of `g i`.\"]\ntheorem finprod_mul_distrib (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) :\n    (\u220f\u1da0 i, f i * g i) = (\u220f\u1da0 i, f i) * \u220f\u1da0 i, g i := by\n  classical\n    rw [finprod_eq_prod_of_mulSupport_toFinset_subset _ hf (Finset.subset_union_left _ _),\n      finprod_eq_prod_of_mulSupport_toFinset_subset _ hg (Finset.subset_union_right _ _), \u2190\n      Finset.prod_mul_distrib]\n    refine' finprod_eq_prod_of_mulSupport_subset _ _\n    simp only [Finset.coe_union, Finite.coe_toFinset, mulSupport_subset_iff,\n      mem_union, mem_mulSupport]\n    intro x\n    contrapose!\n    rintro \u27e8hf,hg\u27e9\n    simp [hf, hg]\n#align finprod_mul_distrib finprod_mul_distrib\n#align finsum_add_distrib finsum_add_distrib\n\n/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i`\nequals the product of `f i` divided by the product of `g i`. -/\n@[to_additive\n      \"If the additive supports of `f` and `g` are finite, then the sum of `f i - g i`\n      equals the sum of `f i` minus the sum of `g i`.\"]\ntheorem finprod_div_distrib [DivisionCommMonoid G] {f g : \u03b1 \u2192 G} (hf : (mulSupport f).Finite)\n    (hg : (mulSupport g).Finite) : (\u220f\u1da0 i, f i / g i) = (\u220f\u1da0 i, f i) / \u220f\u1da0 i, g i := by\n  simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mulSupport_inv g).symm.rec hg),\n    finprod_inv_distrib]\n#align finprod_div_distrib finprod_div_distrib\n#align finsum_sub_distrib finsum_sub_distrib\n\n/-- A more general version of `finprod_mem_mul_distrib` that only requires `s \u2229 mulSupport f` and\n`s \u2229 mulSupport g` rather than `s` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_add_distrib` that only requires `s \u2229 support f`\n      and `s \u2229 support g` rather than `s` to be finite.\"]\ntheorem finprod_mem_mul_distrib' (hf : (s \u2229 mulSupport f).Finite) (hg : (s \u2229 mulSupport g).Finite) :\n    (\u220f\u1da0 i \u2208 s, f i * g i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 s, g i := by\n  rw [\u2190 mulSupport_mulIndicator] at hf hg\n  simp only [finprod_mem_def, mulIndicator_mul, finprod_mul_distrib hf hg]\n#align finprod_mem_mul_distrib' finprod_mem_mul_distrib'\n#align finsum_mem_add_distrib' finsum_mem_add_distrib'\n\n/-- The product of the constant function `1` over any set equals `1`. -/\n@[to_additive \"The product of the constant function `0` over any set equals `0`.\"]\ntheorem finprod_mem_one (s : Set \u03b1) : (\u220f\u1da0 i \u2208 s, (1 : M)) = 1 := by simp\n#align finprod_mem_one finprod_mem_one\n#align finsum_mem_zero finsum_mem_zero\n\n/-- If a function `f` equals `1` on a set `s`, then the product of `f i` over `i \u2208 s` equals `1`. -/\n@[to_additive\n      \"If a function `f` equals `0` on a set `s`, then the product of `f i` over `i \u2208 s`\n      equals `0`.\"]\ntheorem finprod_mem_of_eqOn_one (hf : s.EqOn f 1) : (\u220f\u1da0 i \u2208 s, f i) = 1 := by\n  rw [\u2190 finprod_mem_one s]\n  exact finprod_mem_congr rfl hf\n#align finprod_mem_of_eq_on_one finprod_mem_of_eqOn_one\n#align finsum_mem_of_eq_on_zero finsum_mem_of_eqOn_zero\n\n/-- If the product of `f i` over `i \u2208 s` is not equal to `1`, then there is some `x \u2208 s` such that\n`f x \u2260 1`. -/\n@[to_additive\n      \"If the product of `f i` over `i \u2208 s` is not equal to `0`, then there is some `x \u2208 s`\n      such that `f x \u2260 0`.\"]\ntheorem exists_ne_one_of_finprod_mem_ne_one (h : (\u220f\u1da0 i \u2208 s, f i) \u2260 1) : \u2203 x \u2208 s, f x \u2260 1 := by\n  by_contra' h'\n  exact h (finprod_mem_of_eqOn_one h')\n#align exists_ne_one_of_finprod_mem_ne_one exists_ne_one_of_finprod_mem_ne_one\n#align exists_ne_zero_of_finsum_mem_ne_zero exists_ne_zero_of_finsum_mem_ne_zero\n\n/-- Given a finite set `s`, the product of `f i * g i` over `i \u2208 s` equals the product of `f i`\nover `i \u2208 s` times the product of `g i` over `i \u2208 s`. -/\n@[to_additive\n      \"Given a finite set `s`, the sum of `f i + g i` over `i \u2208 s` equals the sum of `f i`\n      over `i \u2208 s` plus the sum of `g i` over `i \u2208 s`.\"]\ntheorem finprod_mem_mul_distrib (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 s, f i * g i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 s, g i :=\n  finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _)\n#align finprod_mem_mul_distrib finprod_mem_mul_distrib\n#align finsum_mem_add_distrib finsum_mem_add_distrib\n\n@[to_additive]\ntheorem MonoidHom.map_finprod {f : \u03b1 \u2192 M} (g : M \u2192* N) (hf : (mulSupport f).Finite) :\n    g (\u220f\u1da0 i, f i) = \u220f\u1da0 i, g (f i) :=\n  g.map_finprod_pLift f <| hf.preimage <| Equiv.plift.injective.injOn _\n#align monoid_hom.map_finprod MonoidHom.map_finprod\n#align add_monoid_hom.map_finsum AddMonoidHom.map_finsum\n\n@[to_additive]\ntheorem finprod_pow (hf : (mulSupport f).Finite) (n : \u2115) : (\u220f\u1da0 i, f i) ^ n = \u220f\u1da0 i, f i ^ n :=\n  (powMonoidHom n).map_finprod hf\n#align finprod_pow finprod_pow\n#align finsum_nsmul finsum_nsmul\n\n/-- A more general version of `MonoidHom.map_finprod_mem` that requires `s \u2229 mulSupport f` rather\nthan `s` to be finite. -/\n@[to_additive\n      \"A more general version of `AddMonoidHom.map_finsum_mem` that requires\n      `s \u2229 support f` rather than `s` to be finite.\"]\ntheorem MonoidHom.map_finprod_mem' {f : \u03b1 \u2192 M} (g : M \u2192* N) (h\u2080 : (s \u2229 mulSupport f).Finite) :\n    g (\u220f\u1da0 j \u2208 s, f j) = \u220f\u1da0 i \u2208 s, g (f i) := by\n  rw [g.map_finprod]\n  \u00b7 simp only [g.map_finprod_Prop]\n  \u00b7 simpa only [finprod_eq_mulIndicator_apply, mulSupport_mulIndicator]\n#align monoid_hom.map_finprod_mem' MonoidHom.map_finprod_mem'\n#align add_monoid_hom.map_finsum_mem' AddMonoidHom.map_finsum_mem'\n\n/-- Given a monoid homomorphism `g : M \u2192* N` and a function `f : \u03b1 \u2192 M`, the value of `g` at the\nproduct of `f i` over `i \u2208 s` equals the product of `g (f i)` over `s`. -/\n@[to_additive\n      \"Given an additive monoid homomorphism `g : M \u2192* N` and a function `f : \u03b1 \u2192 M`, the\n      value of `g` at the sum of `f i` over `i \u2208 s` equals the sum of `g (f i)` over `s`.\"]\ntheorem MonoidHom.map_finprod_mem (f : \u03b1 \u2192 M) (g : M \u2192* N) (hs : s.Finite) :\n    g (\u220f\u1da0 j \u2208 s, f j) = \u220f\u1da0 i \u2208 s, g (f i) :=\n  g.map_finprod_mem' (hs.inter_of_left _)\n#align monoid_hom.map_finprod_mem MonoidHom.map_finprod_mem\n#align add_monoid_hom.map_finsum_mem AddMonoidHom.map_finsum_mem\n\n@[to_additive]\ntheorem MulEquiv.map_finprod_mem (g : M \u2243* N) (f : \u03b1 \u2192 M) {s : Set \u03b1} (hs : s.Finite) :\n    g (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 i \u2208 s, g (f i) :=\n  g.toMonoidHom.map_finprod_mem f hs\n#align mul_equiv.map_finprod_mem MulEquiv.map_finprod_mem\n#align add_equiv.map_finsum_mem AddEquiv.map_finsum_mem\n\n@[to_additive]\ntheorem finprod_mem_inv_distrib [DivisionCommMonoid G] (f : \u03b1 \u2192 G) (hs : s.Finite) :\n    (\u220f\u1da0 x \u2208 s, (f x)\u207b\u00b9) = (\u220f\u1da0 x \u2208 s, f x)\u207b\u00b9 :=\n  ((MulEquiv.inv G).map_finprod_mem f hs).symm\n#align finprod_mem_inv_distrib finprod_mem_inv_distrib\n#align finsum_mem_neg_distrib finsum_mem_neg_distrib\n\n/-- Given a finite set `s`, the product of `f i / g i` over `i \u2208 s` equals the product of `f i`\nover `i \u2208 s` divided by the product of `g i` over `i \u2208 s`. -/\n@[to_additive\n      \"Given a finite set `s`, the sum of `f i / g i` over `i \u2208 s` equals the sum of `f i`\n      over `i \u2208 s` minus the sum of `g i` over `i \u2208 s`.\"]\ntheorem finprod_mem_div_distrib [DivisionCommMonoid G] (f g : \u03b1 \u2192 G) (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 s, f i / g i) = (\u220f\u1da0 i \u2208 s, f i) / \u220f\u1da0 i \u2208 s, g i := by\n  simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib g hs]\n#align finprod_mem_div_distrib finprod_mem_div_distrib\n#align finsum_mem_sub_distrib finsum_mem_sub_distrib\n\n/-!\n### `\u220f\u1da0 x \u2208 s, f x` and set operations\n-/\n\n\n/-- The product of any function over an empty set is `1`. -/\n@[to_additive \"The sum of any function over an empty set is `0`.\"]\ntheorem finprod_mem_empty : (\u220f\u1da0 i \u2208 (\u2205 : Set \u03b1), f i) = 1 := by simp\n#align finprod_mem_empty finprod_mem_empty\n#align finsum_mem_empty finsum_mem_empty\n\n/-- A set `s` is nonempty if the product of some function over `s` is not equal to `1`. -/\n@[to_additive \"A set `s` is nonempty if the sum of some function over `s` is not equal to `0`.\"]\ntheorem nonempty_of_finprod_mem_ne_one (h : (\u220f\u1da0 i \u2208 s, f i) \u2260 1) : s.Nonempty :=\n  nonempty_iff_ne_empty.2 fun h' => h <| h'.symm \u25b8 finprod_mem_empty\n#align nonempty_of_finprod_mem_ne_one nonempty_of_finprod_mem_ne_one\n#align nonempty_of_finsum_mem_ne_zero nonempty_of_finsum_mem_ne_zero\n\n/-- Given finite sets `s` and `t`, the product of `f i` over `i \u2208 s \u222a t` times the product of\n`f i` over `i \u2208 s \u2229 t` equals the product of `f i` over `i \u2208 s` times the product of `f i`\nover `i \u2208 t`. -/\n@[to_additive\n      \"Given finite sets `s` and `t`, the sum of `f i` over `i \u2208 s \u222a t` plus the sum of\n      `f i` over `i \u2208 s \u2229 t` equals the sum of `f i` over `i \u2208 s` plus the sum of `f i`\n      over `i \u2208 t`.\"]\ntheorem finprod_mem_union_inter (hs : s.Finite) (ht : t.Finite) :\n    ((\u220f\u1da0 i \u2208 s \u222a t, f i) * \u220f\u1da0 i \u2208 s \u2229 t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i := by\n  lift s to Finset \u03b1 using hs; lift t to Finset \u03b1 using ht\n  classical\n    rw [\u2190 Finset.coe_union, \u2190 Finset.coe_inter]\n    simp only [finprod_mem_coe_finset, Finset.prod_union_inter]\n#align finprod_mem_union_inter finprod_mem_union_inter\n#align finsum_mem_union_inter finsum_mem_union_inter\n\n/-- A more general version of `finprod_mem_union_inter` that requires `s \u2229 mulSupport f` and\n`t \u2229 mulSupport f` rather than `s` and `t` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_union_inter` that requires `s \u2229 support f` and\n      `t \u2229 support f` rather than `s` and `t` to be finite.\"]\ntheorem finprod_mem_union_inter' (hs : (s \u2229 mulSupport f).Finite) (ht : (t \u2229 mulSupport f).Finite) :\n    ((\u220f\u1da0 i \u2208 s \u222a t, f i) * \u220f\u1da0 i \u2208 s \u2229 t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_inter_mulSupport f s, \u2190 finprod_mem_inter_mulSupport f t, \u2190\n    finprod_mem_union_inter hs ht, \u2190 union_inter_distrib_right, finprod_mem_inter_mulSupport, \u2190\n    finprod_mem_inter_mulSupport f (s \u2229 t)]\n  congr 2\n  rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm]\n#align finprod_mem_union_inter' finprod_mem_union_inter'\n#align finsum_mem_union_inter' finsum_mem_union_inter'\n\n/-- A more general version of `finprod_mem_union` that requires `s \u2229 mulSupport f` and\n`t \u2229 mulSupport f` rather than `s` and `t` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_union` that requires `s \u2229 support f` and\n      `t \u2229 support f` rather than `s` and `t` to be finite.\"]\ntheorem finprod_mem_union' (hst : Disjoint s t) (hs : (s \u2229 mulSupport f).Finite)\n    (ht : (t \u2229 mulSupport f).Finite) : (\u220f\u1da0 i \u2208 s \u222a t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty,\n    mul_one]\n#align finprod_mem_union' finprod_mem_union'\n#align finsum_mem_union' finsum_mem_union'\n\n/-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i \u2208 s \u222a t` equals the\nproduct of `f i` over `i \u2208 s` times the product of `f i` over `i \u2208 t`. -/\n@[to_additive\n      \"Given two finite disjoint sets `s` and `t`, the sum of `f i` over `i \u2208 s \u222a t` equals\n      the sum of `f i` over `i \u2208 s` plus the sum of `f i` over `i \u2208 t`.\"]\ntheorem finprod_mem_union (hst : Disjoint s t) (hs : s.Finite) (ht : t.Finite) :\n    (\u220f\u1da0 i \u2208 s \u222a t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i :=\n  finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _)\n#align finprod_mem_union finprod_mem_union\n#align finsum_mem_union finsum_mem_union\n\n/-- A more general version of `finprod_mem_union'` that requires `s \u2229 mulSupport f` and\n`t \u2229 mulSupport f` rather than `s` and `t` to be disjoint -/\n@[to_additive\n      \"A more general version of `finsum_mem_union'` that requires `s \u2229 support f` and\n      `t \u2229 support f` rather than `s` and `t` to be disjoint\"]\ntheorem finprod_mem_union'' (hst : Disjoint (s \u2229 mulSupport f) (t \u2229 mulSupport f))\n    (hs : (s \u2229 mulSupport f).Finite) (ht : (t \u2229 mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 s \u222a t, f i) = (\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_inter_mulSupport f s, \u2190 finprod_mem_inter_mulSupport f t, \u2190\n    finprod_mem_union hst hs ht, \u2190 union_inter_distrib_right, finprod_mem_inter_mulSupport]\n#align finprod_mem_union'' finprod_mem_union''\n#align finsum_mem_union'' finsum_mem_union''\n\n/-- The product of `f i` over `i \u2208 {a}` equals `f a`. -/\n@[to_additive \"The sum of `f i` over `i \u2208 {a}` equals `f a`.\"]\ntheorem finprod_mem_singleton : (\u220f\u1da0 i \u2208 ({a} : Set \u03b1), f i) = f a := by\n  rw [\u2190 Finset.coe_singleton, finprod_mem_coe_finset, Finset.prod_singleton]\n#align finprod_mem_singleton finprod_mem_singleton\n#align finsum_mem_singleton finsum_mem_singleton\n\n@[to_additive (attr := simp)]\ntheorem finprod_cond_eq_left : (\u220f\u1da0 (i) (_h : i = a), f i) = f a :=\n  finprod_mem_singleton\n#align finprod_cond_eq_left finprod_cond_eq_left\n#align finsum_cond_eq_left finsum_cond_eq_left\n\n@[to_additive (attr := simp)]\ntheorem finprod_cond_eq_right : (\u220f\u1da0 (i) (_hi : a = i), f i) = f a := by simp [@eq_comm _ a]\n#align finprod_cond_eq_right finprod_cond_eq_right\n#align finsum_cond_eq_right finsum_cond_eq_right\n\n/-- A more general version of `finprod_mem_insert` that requires `s \u2229 mulSupport f` rather than `s`\nto be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_insert` that requires `s \u2229 support f` rather\n      than `s` to be finite.\"]\ntheorem finprod_mem_insert' (f : \u03b1 \u2192 M) (h : a \u2209 s) (hs : (s \u2229 mulSupport f).Finite) :\n    (\u220f\u1da0 i \u2208 insert a s, f i) = f a * \u220f\u1da0 i \u2208 s, f i := by\n  rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton]\n  \u00b7 rwa [disjoint_singleton_left]\n  \u00b7 exact (finite_singleton a).inter_of_left _\n#align finprod_mem_insert' finprod_mem_insert'\n#align finsum_mem_insert' finsum_mem_insert'\n\n/-- Given a finite set `s` and an element `a \u2209 s`, the product of `f i` over `i \u2208 insert a s` equals\n`f a` times the product of `f i` over `i \u2208 s`. -/\n@[to_additive\n      \"Given a finite set `s` and an element `a \u2209 s`, the sum of `f i` over `i \u2208 insert a s`\n      equals `f a` plus the sum of `f i` over `i \u2208 s`.\"]\ntheorem finprod_mem_insert (f : \u03b1 \u2192 M) (h : a \u2209 s) (hs : s.Finite) :\n    (\u220f\u1da0 i \u2208 insert a s, f i) = f a * \u220f\u1da0 i \u2208 s, f i :=\n  finprod_mem_insert' f h <| hs.inter_of_left _\n#align finprod_mem_insert finprod_mem_insert\n#align finsum_mem_insert finsum_mem_insert\n\n/-- If `f a = 1` when `a \u2209 s`, then the product of `f i` over `i \u2208 insert a s` equals the product of\n`f i` over `i \u2208 s`. -/\n@[to_additive\n      \"If `f a = 0` when `a \u2209 s`, then the sum of `f i` over `i \u2208 insert a s` equals the sum\n      of `f i` over `i \u2208 s`.\"]\ntheorem finprod_mem_insert_of_eq_one_if_not_mem (h : a \u2209 s \u2192 f a = 1) :\n    (\u220f\u1da0 i \u2208 insert a s, f i) = \u220f\u1da0 i \u2208 s, f i := by\n  refine' finprod_mem_inter_mulSupport_eq' _ _ _ fun x hx => \u27e8_, Or.inr\u27e9\n  rintro (rfl | hxs)\n  exacts[not_imp_comm.1 h hx, hxs]\n#align finprod_mem_insert_of_eq_one_if_not_mem finprod_mem_insert_of_eq_one_if_not_mem\n#align finsum_mem_insert_of_eq_zero_if_not_mem finsum_mem_insert_of_eq_zero_if_not_mem\n\n/-- If `f a = 1`, then the product of `f i` over `i \u2208 insert a s` equals the product of `f i` over\n`i \u2208 s`. -/\n@[to_additive\n      \"If `f a = 0`, then the sum of `f i` over `i \u2208 insert a s` equals the sum of `f i`\n      over `i \u2208 s`.\"]\ntheorem finprod_mem_insert_one (h : f a = 1) : (\u220f\u1da0 i \u2208 insert a s, f i) = \u220f\u1da0 i \u2208 s, f i :=\n  finprod_mem_insert_of_eq_one_if_not_mem fun _ => h\n#align finprod_mem_insert_one finprod_mem_insert_one\n#align finsum_mem_insert_zero finsum_mem_insert_zero\n\n/-- If the multiplicative support of `f` is finite, then for every `x` in the domain of `f`, `f x`\ndivides `finprod f`.  -/\ntheorem finprod_mem_dvd {f : \u03b1 \u2192 N} (a : \u03b1) (hf : (mulSupport f).Finite) : f a \u2223 finprod f := by\n  by_cases ha : a \u2208 mulSupport f\n  \u00b7 rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf (Set.Subset.refl _)]\n    exact Finset.dvd_prod_of_mem f ((Finite.mem_toFinset hf).mpr ha)\n  \u00b7 rw [nmem_mulSupport.mp ha]\n    exact one_dvd (finprod f)\n#align finprod_mem_dvd finprod_mem_dvd\n\n/-- The product of `f i` over `i \u2208 {a, b}`, `a \u2260 b`, is equal to `f a * f b`. -/\n@[to_additive \"The sum of `f i` over `i \u2208 {a, b}`, `a \u2260 b`, is equal to `f a + f b`.\"]\ntheorem finprod_mem_pair (h : a \u2260 b) : (\u220f\u1da0 i \u2208 ({a, b} : Set \u03b1), f i) = f a * f b := by\n  rw [finprod_mem_insert, finprod_mem_singleton]\n  exacts[h, finite_singleton b]\n#align finprod_mem_pair finprod_mem_pair\n#align finsum_mem_pair finsum_mem_pair\n\n/-- The product of `f y` over `y \u2208 g '' s` equals the product of `f (g i)` over `s`\nprovided that `g` is injective on `s \u2229 mulSupport (f \u2218 g)`. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 g '' s` equals the sum of `f (g i)` over `s` provided that\n      `g` is injective on `s \u2229 support (f \u2218 g)`.\"]\ntheorem finprod_mem_image' {s : Set \u03b2} {g : \u03b2 \u2192 \u03b1} (hg : (s \u2229 mulSupport (f \u2218 g)).InjOn g) :\n    (\u220f\u1da0 i \u2208 g '' s, f i) = \u220f\u1da0 j \u2208 s, f (g j) := by\n  classical\n    by_cases hs : (s \u2229 mulSupport (f \u2218 g)).Finite\n    \u00b7 have hg : \u2200 x \u2208 hs.toFinset, \u2200 y \u2208 hs.toFinset, g x = g y \u2192 x = y := by\n        simpa only [hs.mem_toFinset]\n      have := finprod_mem_eq_prod (comp f g) hs\n      unfold Function.comp at this\n      rw [this, \u2190 Finset.prod_image hg]\n      refine' finprod_mem_eq_prod_of_inter_mulSupport_eq f _\n      rw [Finset.coe_image, hs.coe_toFinset, \u2190 image_inter_mulSupport_eq, inter_assoc, inter_self]\n    \u00b7 unfold Function.comp at hs\n      rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite]\n      rwa [image_inter_mulSupport_eq, infinite_image_iff hg]\n#align finprod_mem_image' finprod_mem_image'\n#align finsum_mem_image' finsum_mem_image'\n\n/-- The product of `f y` over `y \u2208 g '' s` equals the product of `f (g i)` over `s` provided that\n`g` is injective on `s`. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 g '' s` equals the sum of `f (g i)` over `s` provided that\n      `g` is injective on `s`.\"]\ntheorem finprod_mem_image {s : Set \u03b2} {g : \u03b2 \u2192 \u03b1} (hg : s.InjOn g) :\n    (\u220f\u1da0 i \u2208 g '' s, f i) = \u220f\u1da0 j \u2208 s, f (g j) :=\n  finprod_mem_image' <| hg.mono <| inter_subset_left _ _\n#align finprod_mem_image finprod_mem_image\n#align finsum_mem_image finsum_mem_image\n\n/-- The product of `f y` over `y \u2208 set.range g` equals the product of `f (g i)` over all `i`\nprovided that `g` is injective on `mulSupport (f \u2218 g)`. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 Set.range g` equals the sum of `f (g i)` over all `i`\n      provided that `g` is injective on `support (f \u2218 g)`.\"]\ntheorem finprod_mem_range' {g : \u03b2 \u2192 \u03b1} (hg : (mulSupport (f \u2218 g)).InjOn g) :\n    (\u220f\u1da0 i \u2208 range g, f i) = \u220f\u1da0 j, f (g j) := by\n  rw [\u2190 image_univ, finprod_mem_image', finprod_mem_univ]\n  rwa [univ_inter]\n#align finprod_mem_range' finprod_mem_range'\n#align finsum_mem_range' finsum_mem_range'\n\n/-- The product of `f y` over `y \u2208 Set.range g` equals the product of `f (g i)` over all `i`\nprovided that `g` is injective. -/\n@[to_additive\n      \"The sum of `f y` over `y \u2208 Set.range g` equals the sum of `f (g i)` over all `i`\n      provided that `g` is injective.\"]\ntheorem finprod_mem_range {g : \u03b2 \u2192 \u03b1} (hg : Injective g) : (\u220f\u1da0 i \u2208 range g, f i) = \u220f\u1da0 j, f (g j) :=\n  finprod_mem_range' (hg.injOn _)\n#align finprod_mem_range finprod_mem_range\n#align finsum_mem_range finsum_mem_range\n\n/-- See also `Finset.prod_bij`. -/\n@[to_additive \"See also `Finset.sum_bij`.\"]\ntheorem finprod_mem_eq_of_bijOn {s : Set \u03b1} {t : Set \u03b2} {f : \u03b1 \u2192 M} {g : \u03b2 \u2192 M} (e : \u03b1 \u2192 \u03b2)\n    (he\u2080 : s.BijOn e t) (he\u2081 : \u2200 x \u2208 s, f x = g (e x)) : (\u220f\u1da0 i \u2208 s, f i) = \u220f\u1da0 j \u2208 t, g j := by\n  rw [\u2190 Set.BijOn.image_eq he\u2080, finprod_mem_image he\u2080.2.1]\n  exact finprod_mem_congr rfl he\u2081\n#align finprod_mem_eq_of_bij_on finprod_mem_eq_of_bijOn\n#align finsum_mem_eq_of_bij_on finsum_mem_eq_of_bijOn\n\n/-- See `finprod_comp`, `Fintype.prod_bijective` and `Finset.prod_bij`. -/\n@[to_additive \"See `finsum_comp`, `Fintype.sum_bijective` and `Finset.sum_bij`.\"]\ntheorem finprod_eq_of_bijective {f : \u03b1 \u2192 M} {g : \u03b2 \u2192 M} (e : \u03b1 \u2192 \u03b2) (he\u2080 : Bijective e)\n    (he\u2081 : \u2200 x, f x = g (e x)) : (\u220f\u1da0 i, f i) = \u220f\u1da0 j, g j := by\n  rw [\u2190 finprod_mem_univ f, \u2190 finprod_mem_univ g]\n  exact finprod_mem_eq_of_bijOn _ (bijective_iff_bijOn_univ.mp he\u2080) fun x _ => he\u2081 x\n#align finprod_eq_of_bijective finprod_eq_of_bijective\n#align finsum_eq_of_bijective finsum_eq_of_bijective\n\n/-- See also `finprod_eq_of_bijective`, `Fintype.prod_bijective` and `Finset.prod_bij`. -/\n@[to_additive \"See also `finsum_eq_of_bijective`, `Fintype.sum_bijective` and `Finset.sum_bij`.\"]\ntheorem finprod_comp {g : \u03b2 \u2192 M} (e : \u03b1 \u2192 \u03b2) (he\u2080 : Function.Bijective e) :\n    (\u220f\u1da0 i, g (e i)) = \u220f\u1da0 j, g j :=\n  finprod_eq_of_bijective e he\u2080 fun _ => rfl\n#align finprod_comp finprod_comp\n#align finsum_comp finsum_comp\n\n@[to_additive]\ntheorem finprod_comp_equiv (e : \u03b1 \u2243 \u03b2) {f : \u03b2 \u2192 M} : (\u220f\u1da0 i, f (e i)) = \u220f\u1da0 i', f i' :=\n  finprod_comp e e.bijective\n#align finprod_comp_equiv finprod_comp_equiv\n#align finsum_comp_equiv finsum_comp_equiv\n\n@[to_additive]\ntheorem finprod_set_coe_eq_finprod_mem (s : Set \u03b1) : (\u220f\u1da0 j : s, f j) = \u220f\u1da0 i \u2208 s, f i := by\n  rw [\u2190 finprod_mem_range, Subtype.range_coe]\n  exact Subtype.coe_injective\n#align finprod_set_coe_eq_finprod_mem finprod_set_coe_eq_finprod_mem\n#align finsum_set_coe_eq_finsum_mem finsum_set_coe_eq_finsum_mem\n\n@[to_additive]\ntheorem finprod_subtype_eq_finprod_cond (p : \u03b1 \u2192 Prop) :\n    (\u220f\u1da0 j : Subtype p, f j) = \u220f\u1da0 (i) (_hi : p i), f i :=\n  finprod_set_coe_eq_finprod_mem { i | p i }\n#align finprod_subtype_eq_finprod_cond finprod_subtype_eq_finprod_cond\n#align finsum_subtype_eq_finsum_cond finsum_subtype_eq_finsum_cond\n\n@[to_additive]\ntheorem finprod_mem_inter_mul_diff' (t : Set \u03b1) (h : (s \u2229 mulSupport f).Finite) :\n    ((\u220f\u1da0 i \u2208 s \u2229 t, f i) * \u220f\u1da0 i \u2208 s \\ t, f i) = \u220f\u1da0 i \u2208 s, f i := by\n  rw [\u2190 finprod_mem_union', inter_union_diff]\n  rw [disjoint_iff_inf_le]\n  exacts[fun x hx => hx.2.2 hx.1.2, h.subset fun x hx => \u27e8hx.1.1, hx.2\u27e9,\n    h.subset fun x hx => \u27e8hx.1.1, hx.2\u27e9]\n#align finprod_mem_inter_mul_diff' finprod_mem_inter_mul_diff'\n#align finsum_mem_inter_add_diff' finsum_mem_inter_add_diff'\n\n@[to_additive]\ntheorem finprod_mem_inter_mul_diff (t : Set \u03b1) (h : s.Finite) :\n    ((\u220f\u1da0 i \u2208 s \u2229 t, f i) * \u220f\u1da0 i \u2208 s \\ t, f i) = \u220f\u1da0 i \u2208 s, f i :=\n  finprod_mem_inter_mul_diff' _ <| h.inter_of_left _\n#align finprod_mem_inter_mul_diff finprod_mem_inter_mul_diff\n#align finsum_mem_inter_add_diff finsum_mem_inter_add_diff\n\n/-- A more general version of `finprod_mem_mul_diff` that requires `t \u2229 mulSupport f` rather than\n`t` to be finite. -/\n@[to_additive\n      \"A more general version of `finsum_mem_add_diff` that requires `t \u2229 support f` rather\n      than `t` to be finite.\"]\ntheorem finprod_mem_mul_diff' (hst : s \u2286 t) (ht : (t \u2229 mulSupport f).Finite) :\n    ((\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t \\ s, f i) = \u220f\u1da0 i \u2208 t, f i := by\n  rw [\u2190 finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst]\n#align finprod_mem_mul_diff' finprod_mem_mul_diff'\n#align finsum_mem_add_diff' finsum_mem_add_diff'\n\n/-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i \u2208 s`\ntimes the product of `f i` over `t \\ s` equals the product of `f i` over `i \u2208 t`. -/\n@[to_additive\n      \"Given a finite set `t` and a subset `s` of `t`, the sum of `f i` over `i \u2208 s` plus\n      the sum of `f i` over `t \\\\ s` equals the sum of `f i` over `i \u2208 t`.\"]\ntheorem finprod_mem_mul_diff (hst : s \u2286 t) (ht : t.Finite) :\n    ((\u220f\u1da0 i \u2208 s, f i) * \u220f\u1da0 i \u2208 t \\ s, f i) = \u220f\u1da0 i \u2208 t, f i :=\n  finprod_mem_mul_diff' hst (ht.inter_of_left _)\n#align finprod_mem_mul_diff finprod_mem_mul_diff\n#align finsum_mem_add_diff finsum_mem_add_diff\n\n/-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the product of\n`f a` over the union `\u22c3 i, t i` is equal to the product over all indexes `i` of the products of\n`f a` over `a \u2208 t i`. -/\n@[to_additive\n      \"Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the\n      sum of `f a` over the union `\u22c3 i, t i` is equal to the sum over all indexes `i` of the\n      sums of `f a` over `a \u2208 t i`.\"]\ntheorem finprod_mem_union\u1d62 [Finite \u03b9] {t : \u03b9 \u2192 Set \u03b1} (h : Pairwise (Disjoint on t))\n    (ht : \u2200 i, (t i).Finite) : (\u220f\u1da0 a \u2208 \u22c3 i : \u03b9, t i, f a) = \u220f\u1da0 i, \u220f\u1da0 a \u2208 t i, f a := by\n  cases nonempty_fintype \u03b9\n  lift t to \u03b9 \u2192 Finset \u03b1 using ht\n  classical\n    rw [\u2190 bunion\u1d62_univ, \u2190 Finset.coe_univ, \u2190 Finset.coe_bunion\u1d62, finprod_mem_coe_finset,\n      Finset.prod_bunion\u1d62]\n    \u00b7 simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype]\n    \u00b7 exact fun x _ y _ hxy => Finset.disjoint_coe.1 (h hxy)\n#align finprod_mem_Union finprod_mem_union\u1d62\n#align finsum_mem_Union finsum_mem_union\u1d62\n\n/-- Given a family of sets `t : \u03b9 \u2192 Set \u03b1`, a finite set `I` in the index type such that all sets\n`t i`, `i \u2208 I`, are finite, if all `t i`, `i \u2208 I`, are pairwise disjoint, then the product of `f a`\nover `a \u2208 \u22c3 i \u2208 I, t i` is equal to the product over `i \u2208 I` of the products of `f a` over\n`a \u2208 t i`. -/\n@[to_additive\n      \"Given a family of sets `t : \u03b9 \u2192 Set \u03b1`, a finite set `I` in the index type such that\n      all sets `t i`, `i \u2208 I`, are finite, if all `t i`, `i \u2208 I`, are pairwise disjoint, then the\n      sum of `f a` over `a \u2208 \u22c3 i \u2208 I, t i` is equal to the sum over `i \u2208 I` of the sums of `f a`\n      over `a \u2208 t i`.\"]\ntheorem finprod_mem_bunion\u1d62 {I : Set \u03b9} {t : \u03b9 \u2192 Set \u03b1} (h : I.PairwiseDisjoint t) (hI : I.Finite)\n    (ht : \u2200 i \u2208 I, (t i).Finite) : (\u220f\u1da0 a \u2208 \u22c3 x \u2208 I, t x, f a) = \u220f\u1da0 i \u2208 I, \u220f\u1da0 j \u2208 t i, f j := by\n  haveI := hI.fintype\n  rw [bunion\u1d62_eq_union\u1d62, finprod_mem_union\u1d62, \u2190 finprod_set_coe_eq_finprod_mem]\n  exacts[fun x y hxy => h x.2 y.2 (Subtype.coe_injective.ne hxy), fun b => ht b b.2]\n#align finprod_mem_bUnion finprod_mem_bunion\u1d62\n#align finsum_mem_bUnion finsum_mem_bunion\u1d62\n\n/-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a`\nover `a \u2208 \u22c3\u2080 t` is the product over `s \u2208 t` of the products of `f a` over `a \u2208 s`. -/\n@[to_additive\n      \"If `t` is a finite set of pairwise disjoint finite sets, then the sum of `f a` over\n      `a \u2208 \u22c3\u2080 t` is the sum over `s \u2208 t` of the sums of `f a` over `a \u2208 s`.\"]\ntheorem finprod_mem_union\u209b {t : Set (Set \u03b1)} (h : t.PairwiseDisjoint id) (ht\u2080 : t.Finite)\n    (ht\u2081 : \u2200 x \u2208 t, Set.Finite x) : (\u220f\u1da0 a \u2208 \u22c3\u2080 t, f a) = \u220f\u1da0 s \u2208 t, \u220f\u1da0 a \u2208 s, f a := by\n  rw [Set.union\u209b_eq_bunion\u1d62]\n  exact finprod_mem_bunion\u1d62 h ht\u2080 ht\u2081\n#align finprod_mem_sUnion finprod_mem_union\u209b\n#align finsum_mem_sUnion finsum_mem_union\u209b\n\n@[to_additive]\ntheorem mul_finprod_cond_ne (a : \u03b1) (hf : (mulSupport f).Finite) :\n    (f a * \u220f\u1da0 (i) (_h : i \u2260 a), f i) = \u220f\u1da0 i, f i := by\n  classical\n    rw [finprod_eq_prod _ hf]\n    have h : \u2200 x : \u03b1, f x \u2260 1 \u2192 (x \u2260 a \u2194 x \u2208 hf.toFinset \\ {a}) :=\n      by\n      intro x hx\n      rw [Finset.mem_sdiff, Finset.mem_singleton, Finite.mem_toFinset, mem_mulSupport]\n      exact \u27e8fun h => And.intro hx h, fun h => h.2\u27e9\n    rw [finprod_cond_eq_prod_of_cond_iff f (fun hx => h _ hx), Finset.sdiff_singleton_eq_erase]\n    by_cases ha : a \u2208 mulSupport f\n    \u00b7 apply Finset.mul_prod_erase _ _ ((Finite.mem_toFinset _).mpr ha)\n    \u00b7 rw [mem_mulSupport, not_not] at ha\n      rw [ha, one_mul]\n      apply Finset.prod_erase _ ha\n#align mul_finprod_cond_ne mul_finprod_cond_ne\n#align add_finsum_cond_ne add_finsum_cond_ne\n\n/-- If `s : Set \u03b1` and `t : Set \u03b2` are finite sets, then taking the product over `s` commutes with\ntaking the product over `t`. -/\n@[to_additive\n      \"If `s : Set \u03b1` and `t : Set \u03b2` are finite sets, then summing over `s` commutes with\n      summing over `t`.\"]\ntheorem finprod_mem_comm {s : Set \u03b1} {t : Set \u03b2} (f : \u03b1 \u2192 \u03b2 \u2192 M) (hs : s.Finite) (ht : t.Finite) :\n    (\u220f\u1da0 i \u2208 s, \u220f\u1da0 j \u2208 t, f i j) = \u220f\u1da0 j \u2208 t, \u220f\u1da0 i \u2208 s, f i j := by\n  lift s to Finset \u03b1 using hs; lift t to Finset \u03b2 using ht\n  simp only [finprod_mem_coe_finset]\n  exact Finset.prod_comm\n#align finprod_mem_comm finprod_mem_comm\n#align finsum_mem_comm finsum_mem_comm\n\n/-- To prove a property of a finite product, it suffices to prove that the property is\nmultiplicative and holds on factors. -/\n@[to_additive\n      \"To prove a property of a finite sum, it suffices to prove that the property is\n      additive and holds on summands.\"]\ntheorem finprod_mem_induction (p : M \u2192 Prop) (hp\u2080 : p 1) (hp\u2081 : \u2200 x y, p x \u2192 p y \u2192 p (x * y))\n    (hp\u2082 : \u2200 x \u2208 s, p <| f x) : p (\u220f\u1da0 i \u2208 s, f i) :=\n  finprod_induction _ hp\u2080 hp\u2081 fun x => finprod_induction _ hp\u2080 hp\u2081 <| hp\u2082 x\n#align finprod_mem_induction finprod_mem_induction\n#align finsum_mem_induction finsum_mem_induction\n\ntheorem finprod_cond_nonneg {R : Type _} [OrderedCommSemiring R] {p : \u03b1 \u2192 Prop} {f : \u03b1 \u2192 R}\n    (hf : \u2200 x, p x \u2192 0 \u2264 f x) : 0 \u2264 \u220f\u1da0 (x) (_h : p x), f x :=\n  finprod_nonneg fun x => finprod_nonneg <| hf x\n#align finprod_cond_nonneg finprod_cond_nonneg\n\n@[to_additive]\ntheorem single_le_finprod {M : Type _} [OrderedCommMonoid M] (i : \u03b1) {f : \u03b1 \u2192 M}\n    (hf : (mulSupport f).Finite) (h : \u2200 j, 1 \u2264 f j) : f i \u2264 \u220f\u1da0 j, f j := by\n  classical calc\n      f i \u2264 \u220f j in insert i hf.toFinset, f j :=\n        Finset.single_le_prod' (fun j _ => h j) (Finset.mem_insert_self _ _)\n      _ = \u220f\u1da0 j, f j :=\n        (finprod_eq_prod_of_mulSupport_toFinset_subset _ hf (Finset.subset_insert _ _)).symm\n\n#align single_le_finprod single_le_finprod\n#align single_le_finsum single_le_finsum\n\ntheorem finprod_eq_zero {M\u2080 : Type _} [CommMonoidWithZero M\u2080] (f : \u03b1 \u2192 M\u2080) (x : \u03b1) (hx : f x = 0)\n    (hf : (mulSupport f).Finite) : (\u220f\u1da0 x, f x) = 0 := by\n  nontriviality\n  rw [finprod_eq_prod f hf]\n  refine' Finset.prod_eq_zero (hf.mem_toFinset.2 _) hx\n  simp [hx]\n#align finprod_eq_zero finprod_eq_zero\n\n@[to_additive]\ntheorem finprod_prod_comm (s : Finset \u03b2) (f : \u03b1 \u2192 \u03b2 \u2192 M)\n    (h : \u2200 b \u2208 s, (mulSupport fun a => f a b).Finite) :\n    (\u220f\u1da0 a : \u03b1, \u220f b in s, f a b) = \u220f b in s, \u220f\u1da0 a : \u03b1, f a b := by\n  have hU :\n    (mulSupport fun a => \u220f b in s, f a b) \u2286\n      (s.finite_toSet.bunion\u1d62 fun b hb => h b (Finset.mem_coe.1 hb)).toFinset :=\n    by\n    rw [Finite.coe_toFinset]\n    intro x hx\n    simp only [exists_prop, mem_union\u1d62, Ne.def, mem_mulSupport, Finset.mem_coe]\n    contrapose! hx\n    rw [mem_mulSupport, not_not, Finset.prod_congr rfl hx, Finset.prod_const_one]\n  rw [finprod_eq_prod_of_mulSupport_subset _ hU, Finset.prod_comm]\n  refine' Finset.prod_congr rfl fun b hb => (finprod_eq_prod_of_mulSupport_subset _ _).symm\n  intro a ha\n  simp only [Finite.coe_toFinset, mem_union\u1d62]\n  exact \u27e8b, hb, ha\u27e9\n#align finprod_prod_comm finprod_prod_comm\n#align finsum_sum_comm finsum_sum_comm\n\n@[to_additive]\ntheorem prod_finprod_comm (s : Finset \u03b1) (f : \u03b1 \u2192 \u03b2 \u2192 M) (h : \u2200 a \u2208 s, (mulSupport (f a)).Finite) :\n    (\u220f a in s, \u220f\u1da0 b : \u03b2, f a b) = \u220f\u1da0 b : \u03b2, \u220f a in s, f a b :=\n  (finprod_prod_comm s (fun b a => f a b) h).symm\n#align prod_finprod_comm prod_finprod_comm\n#align sum_finsum_comm sum_finsum_comm\n\ntheorem mul_finsum {R : Type _} [Semiring R] (f : \u03b1 \u2192 R) (r : R) (h : (support f).Finite) :\n    (r * \u2211\u1da0 a : \u03b1, f a) = \u2211\u1da0 a : \u03b1, r * f a :=\n  (AddMonoidHom.mulLeft r).map_finsum h\n#align mul_finsum mul_finsum\n\ntheorem finsum_mul {R : Type _} [Semiring R] (f : \u03b1 \u2192 R) (r : R) (h : (support f).Finite) :\n    (\u2211\u1da0 a : \u03b1, f a) * r = \u2211\u1da0 a : \u03b1, f a * r :=\n  (AddMonoidHom.mulRight r).map_finsum h\n#align finsum_mul finsum_mul\n\n@[to_additive]\ntheorem Finset.mulSupport_of_fiberwise_prod_subset_image [DecidableEq \u03b2] (s : Finset \u03b1) (f : \u03b1 \u2192 M)\n    (g : \u03b1 \u2192 \u03b2) : (mulSupport fun b => (s.filter fun a => g a = b).prod f) \u2286 s.image g := by\n  simp only [Finset.coe_image, Set.mem_image, Finset.mem_coe, Function.support_subset_iff]\n  intro b h\n  suffices (s.filter fun a : \u03b1 => g a = b).Nonempty by\n    simpa only [s.fiber_nonempty_iff_mem_image g b, Finset.mem_image, exists_prop]\n  exact Finset.nonempty_of_prod_ne_one h\n#align\n  finset.mul_support_of_fiberwise_prod_subset_image\n  Finset.mulSupport_of_fiberwise_prod_subset_image\n#align\n  finset.support_of_fiberwise_sum_subset_image\n  Finset.support_of_fiberwise_sum_subset_image\n\n/-- Note that `b \u2208 (s.filter (fun ab => Prod.fst ab = a)).image Prod.snd` iff `(a, b) \u2208 s` so\nwe can simplify the right hand side of this lemma. However the form stated here is more useful for\niterating this lemma, e.g., if we have `f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M`. -/\n@[to_additive\n      \"Note that `b \u2208 (s.filter (fun ab => Prod.fst ab = a)).image Prod.snd` iff `(a, b) \u2208 s` so\n      we can simplify the right hand side of this lemma. However the form stated here is more\n      useful for iterating this lemma, e.g., if we have `f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M`.\"]\ntheorem finprod_mem_finset_product' [DecidableEq \u03b1] [DecidableEq \u03b2] (s : Finset (\u03b1 \u00d7 \u03b2))\n    (f : \u03b1 \u00d7 \u03b2 \u2192 M) :\n    (\u220f\u1da0 (ab) (_h : ab \u2208 s), f ab) =\n      \u220f\u1da0 (a) (b) (_h : b \u2208 (s.filter fun ab => Prod.fst ab = a).image Prod.snd), f (a, b) := by\n  have :\n    \u2200 a,\n      (\u220f i : \u03b2 in (s.filter fun ab => Prod.fst ab = a).image Prod.snd, f (a, i)) =\n        (Finset.filter (fun ab => Prod.fst ab = a) s).prod f :=\n    by\n    refine' fun a => Finset.prod_bij (fun b _ => (a, b)) _ _ _ _ <;>-- `finish` closes these goals\n      try simp; done\n    suffices \u2200 a' b, (a', b) \u2208 s \u2192 a' = a \u2192 (a, b) \u2208 s \u2227 a' = a by simpa\n    rintro a' b hp rfl\n    exact \u27e8hp, rfl\u27e9\n  rw [finprod_mem_finset_eq_prod]\n  simp_rw [finprod_mem_finset_eq_prod, this]\n  rw [finprod_eq_prod_of_mulSupport_subset _\n      (s.mulSupport_of_fiberwise_prod_subset_image f Prod.fst),\n    \u2190 Finset.prod_fiberwise_of_maps_to (t := Finset.image Prod.fst s) _ f]\n  -- `finish` could close the goal here\n  simp only [Finset.mem_image, Prod.mk.eta]\n  exact fun x hx => \u27e8x, hx, rfl\u27e9\n#align finprod_mem_finset_product' finprod_mem_finset_product'\n#align finsum_mem_finset_product' finsum_mem_finset_product'\n\n/-- See also `finprod_mem_finset_product'`. -/\n@[to_additive \"See also `finsum_mem_finset_product'`.\"]\ntheorem finprod_mem_finset_product (s : Finset (\u03b1 \u00d7 \u03b2)) (f : \u03b1 \u00d7 \u03b2 \u2192 M) :\n    (\u220f\u1da0 (ab) (_h : ab \u2208 s), f ab) = \u220f\u1da0 (a) (b) (_h : (a, b) \u2208 s), f (a, b) := by\n  classical\n    rw [finprod_mem_finset_product']\n    simp\n#align finprod_mem_finset_product finprod_mem_finset_product\n#align finsum_mem_finset_product finsum_mem_finset_product\n\n@[to_additive]\ntheorem finprod_mem_finset_product\u2083 {\u03b3 : Type _} (s : Finset (\u03b1 \u00d7 \u03b2 \u00d7 \u03b3)) (f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M) :\n    (\u220f\u1da0 (abc) (_h : abc \u2208 s), f abc) = \u220f\u1da0 (a) (b) (c) (_h : (a, b, c) \u2208 s), f (a, b, c) := by\n  classical\n    rw [finprod_mem_finset_product']\n    simp_rw [finprod_mem_finset_product']\n    simp\n#align finprod_mem_finset_product\u2083 finprod_mem_finset_product\u2083\n#align finsum_mem_finset_product\u2083 finsum_mem_finset_product\u2083\n\n@[to_additive]\ntheorem finprod_curry (f : \u03b1 \u00d7 \u03b2 \u2192 M) (hf : (mulSupport f).Finite) :\n    (\u220f\u1da0 ab, f ab) = \u220f\u1da0 (a) (b), f (a, b) := by\n  have h\u2081 : \u2200 a, (\u220f\u1da0 _h : a \u2208 hf.toFinset, f a) = f a := by simp\n  have h\u2082 : (\u220f\u1da0 a, f a) = \u220f\u1da0 (a) (_h : a \u2208 hf.toFinset), f a := by simp\n  simp_rw [h\u2082, finprod_mem_finset_product, h\u2081]\n#align finprod_curry finprod_curry\n#align finsum_curry finsum_curry\n\n@[to_additive]\ntheorem finprod_curry\u2083 {\u03b3 : Type _} (f : \u03b1 \u00d7 \u03b2 \u00d7 \u03b3 \u2192 M) (h : (mulSupport f).Finite) :\n    (\u220f\u1da0 abc, f abc) = \u220f\u1da0 (a) (b) (c), f (a, b, c) := by\n  rw [finprod_curry f h]\n  congr\n  ext a\n  rw [finprod_curry]\n  simp [h]\n#align finprod_curry\u2083 finprod_curry\u2083\n#align finsum_curry\u2083 finsum_curry\u2083\n\n@[to_additive]\ntheorem finprod_dmem {s : Set \u03b1} [DecidablePred (\u00b7 \u2208 s)] (f : \u2200 a : \u03b1, a \u2208 s \u2192 M) :\n    (\u220f\u1da0 (a : \u03b1) (h : a \u2208 s), f a h) = \u220f\u1da0 (a : \u03b1) (_h : a \u2208 s), if h' : a \u2208 s then f a h' else 1 :=\n  finprod_congr fun _ => finprod_congr fun ha => (dif_pos ha).symm\n#align finprod_dmem finprod_dmem\n#align finsum_dmem finsum_dmem\n\n@[to_additive]\ntheorem finprod_emb_domain' {f : \u03b1 \u2192 \u03b2} (hf : Injective f) [DecidablePred (\u00b7 \u2208 Set.range f)]\n    (g : \u03b1 \u2192 M) :\n    (\u220f\u1da0 b : \u03b2, if h : b \u2208 Set.range f then g (Classical.choose h) else 1) = \u220f\u1da0 a : \u03b1, g a := by\n  simp_rw [\u2190 finprod_eq_dif]\n  rw [finprod_dmem, finprod_mem_range hf, finprod_congr fun a => _]\n  intro a\n  rw [dif_pos (Set.mem_range_self a), hf (Classical.choose_spec (Set.mem_range_self a))]\n#align finprod_emb_domain' finprod_emb_domain'\n#align finsum_emb_domain' finsum_emb_domain'\n\n@[to_additive]\ntheorem finprod_emb_domain (f : \u03b1 \u21aa \u03b2) [DecidablePred (\u00b7 \u2208 Set.range f)] (g : \u03b1 \u2192 M) :\n    (\u220f\u1da0 b : \u03b2, if h : b \u2208 Set.range f then g (Classical.choose h) else 1) = \u220f\u1da0 a : \u03b1, g a :=\n  finprod_emb_domain' f.injective g\n#align finprod_emb_domain finprod_emb_domain\n#align finsum_emb_domain finsum_emb_domain\n\nend type\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Algebra/BigOperators/Finprod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942093072239, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7021304634944076}}
{"text": "/-\nCopyright (c) 2020 Shing Tak Lam. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Shing Tak Lam\n-/\nimport data.zmod.basic\nimport group_theory.order_of_element\n\n/-!\n# Dihedral Groups\n\nWe define the dihedral groups `dihedral_group n`, with elements `r i` and `sr i` for `i : zmod n`.\n\nFor `n \u2260 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`\nrepresents the rotations of the `n`-gon by `2\u03c0i/n`, and `sr i` represents the reflections of the\n`n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.\n-/\n\n/--\nFor `n \u2260 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon.\n`r i` represents the rotations of the `n`-gon by `2\u03c0i/n`, and `sr i` represents the reflections of\nthe `n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.\n-/\n@[derive decidable_eq]\ninductive dihedral_group (n : \u2115) : Type\n| r : zmod n \u2192 dihedral_group\n| sr : zmod n \u2192 dihedral_group\n\nnamespace dihedral_group\n\nvariables {n : \u2115}\n\n/--\nMultiplication of the dihedral group.\n-/\nprivate def mul : dihedral_group n \u2192 dihedral_group n \u2192 dihedral_group n\n| (r i) (r j) := r (i + j)\n| (r i) (sr j) := sr (j - i)\n| (sr i) (r j) := sr (i + j)\n| (sr i) (sr j) := r (j - i)\n\n/--\nThe identity `1` is the rotation by `0`.\n-/\nprivate def one : dihedral_group n := r 0\n\ninstance : inhabited (dihedral_group n) := \u27e8one\u27e9\n\n/--\nThe inverse of a an element of the dihedral group.\n-/\nprivate def inv : dihedral_group n \u2192 dihedral_group n\n| (r i) := r (-i)\n| (sr i) := sr i\n\n/--\nThe group structure on `dihedral_group n`.\n-/\ninstance : group (dihedral_group n) :=\n{ mul := mul,\n  mul_assoc :=\n  begin\n    rintros (a | a) (b | b) (c | c);\n    simp only [mul];\n    ring,\n  end,\n  one := one,\n  one_mul :=\n  begin\n    rintros (a | a),\n    exact congr_arg r (zero_add a),\n    exact congr_arg sr (sub_zero a),\n  end,\n  mul_one := begin\n    rintros (a | a),\n    exact congr_arg r (add_zero a),\n    exact congr_arg sr (add_zero a),\n  end,\n  inv := inv,\n  mul_left_inv := begin\n    rintros (a | a),\n    exact congr_arg r (neg_add_self a),\n    exact congr_arg r (sub_self a),\n  end }\n\n@[simp] lemma r_mul_r (i j : zmod n) : r i * r j = r (i + j) := rfl\n@[simp] lemma r_mul_sr (i j : zmod n) : r i * sr j = sr (j - i) := rfl\n@[simp] lemma sr_mul_r (i j : zmod n) : sr i * r j = sr (i + j) := rfl\n@[simp] lemma sr_mul_sr (i j : zmod n) : sr i * sr j = r (j - i) := rfl\n\nlemma one_def : (1 : dihedral_group n) = r 0 := rfl\n\nprivate def fintype_helper : (zmod n \u2295 zmod n) \u2243 dihedral_group n :=\n{ inv_fun := \u03bb i, match i with\n                 | (r j) := sum.inl j\n                 | (sr j) := sum.inr j\n                 end,\n  to_fun := \u03bb i, match i with\n                 | (sum.inl j) := r j\n                 | (sum.inr j) := sr j\n                 end,\n  left_inv := by rintro (x | x); refl,\n  right_inv := by rintro (x | x); refl }\n\n/--\nIf `0 < n`, then `dihedral_group n` is a finite group.\n-/\ninstance [fact (0 < n)] : fintype (dihedral_group n) := fintype.of_equiv _ fintype_helper\n\ninstance : nontrivial (dihedral_group n) := \u27e8\u27e8r 0, sr 0, dec_trivial\u27e9\u27e9\n\n/--\nIf `0 < n`, then `dihedral_group n` has `2n` elements.\n-/\nlemma card [fact (0 < n)] : fintype.card (dihedral_group n) = 2 * n :=\nby rw [\u2190 fintype.card_eq.mpr \u27e8fintype_helper\u27e9, fintype.card_sum, zmod.card, two_mul]\n\n@[simp] lemma r_one_pow (k : \u2115) : (r 1 : dihedral_group n) ^ k = r k :=\nbegin\n  induction k with k IH,\n  { refl },\n  { rw [pow_succ, IH, r_mul_r],\n    congr' 1,\n    norm_cast,\n    rw nat.one_add }\nend\n\n@[simp] lemma r_one_pow_n : (r (1 : zmod n))^n = 1 :=\nbegin\n  cases n,\n  { rw pow_zero },\n  { rw [r_one_pow, one_def],\n    congr' 1,\n    exact zmod.nat_cast_self _, }\nend\n\n@[simp] \n\n/--\nIf `0 < n`, then `sr i` has order 2.\n-/\n@[simp] lemma order_of_sr (i : zmod n) : order_of (sr i) = 2 :=\nbegin\n  rw order_of_eq_prime _ _,\n  { exact \u27e8nat.prime_two\u27e9 },\n  rw [sq, sr_mul_self],\n  dec_trivial,\nend\n\n/--\nIf `0 < n`, then `r 1` has order `n`.\n-/\n@[simp] lemma order_of_r_one : order_of (r 1 : dihedral_group n) = n :=\nbegin\n  by_cases hnpos : 0 < n,\n  { haveI : fact (0 < n) := \u27e8hnpos\u27e9,\n    cases lt_or_eq_of_le (nat.le_of_dvd hnpos (order_of_dvd_of_pow_eq_one (@r_one_pow_n n)))\n      with h h,\n    { have h1 : (r 1 : dihedral_group n)^(order_of (r 1)) = 1,\n      { exact pow_order_of_eq_one _ },\n      rw r_one_pow at h1,\n      injection h1 with h2,\n      rw [\u2190 zmod.val_eq_zero, zmod.val_nat_cast, nat.mod_eq_of_lt h] at h2,\n      apply absurd h2.symm,\n      apply ne_of_lt,\n      exact absurd h2.symm (ne_of_lt (order_of_pos _)) },\n      { exact h } },\n    { simp only [not_lt, nonpos_iff_eq_zero] at hnpos,\n      rw hnpos,\n      apply order_of_eq_zero,\n      rw is_of_fin_order_iff_pow_eq_one,\n      push_neg,\n      intros m hm,\n      rw [r_one_pow, one_def],\n      by_contradiction,\n      rw not_not at h,\n      have h' : (m : zmod 0) = 0,\n      { exact r.inj h, },\n      have h'' : m = 0,\n      { simp only [int.coe_nat_eq_zero, int.nat_cast_eq_coe_nat] at h',\n        exact h', },\n      rw h'' at hm,\n      apply nat.lt_irrefl,\n      exact hm },\nend\n\n/--\nIf `0 < n`, then `i : zmod n` has order `n / gcd n i`.\n-/\nlemma order_of_r [fact (0 < n)] (i : zmod n) : order_of (r i) = n / nat.gcd n i.val :=\nbegin\n  conv_lhs { rw \u2190zmod.nat_cast_zmod_val i },\n  rw [\u2190r_one_pow, order_of_pow, order_of_r_one]\nend\n\nend dihedral_group\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/specific_groups/dihedral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88242786954645, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.702110877850346}}
{"text": "/-\nCopyright (c) 2021 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport analysis.calculus.parametric_integral\nimport measure_theory.integral.interval_integral\n\n/-!\n# Derivatives of interval integrals depending on parameters\n\nIn this file we restate theorems about derivatives of integrals depending on parameters for interval\nintegrals.  -/\n\n\nopen topological_space measure_theory filter metric\nopen_locale topological_space filter interval\n\nvariables {\u03b1 \ud835\udd5c : Type*} [measurable_space \u03b1] [linear_order \u03b1] [topological_space \u03b1]\n          [order_topology \u03b1] [opens_measurable_space \u03b1] {\u03bc : measure \u03b1} [is_R_or_C \ud835\udd5c]\n          {E : Type*} [normed_group E] [normed_space \u211d E] [normed_space \ud835\udd5c E]\n          [complete_space E] [second_countable_topology E]\n          [measurable_space E] [borel_space E]\n          {H : Type*} [normed_group H] [normed_space \ud835\udd5c H] [second_countable_topology $ H \u2192L[\ud835\udd5c] E]\n          {a b : \u03b1} {bound : \u03b1 \u2192 \u211d} {\u03b5 : \u211d}\n\nnamespace interval_integral\n\n/-- Differentiation under integral of `x \u21a6 \u222b t in a..b, F x t` at a given point `x\u2080`, assuming\n`F x\u2080` is integrable, `x \u21a6 F x a` is locally Lipschitz on a ball around `x\u2080` for ae `a`\n(with a ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is ae-measurable\nfor `x` in a possibly smaller neighborhood of `x\u2080`. -/\nlemma has_fderiv_at_integral_of_dominated_loc_of_lip {F : H \u2192 \u03b1 \u2192 E} {F' : \u03b1 \u2192 (H \u2192L[\ud835\udd5c] E)} {x\u2080 : H}\n  (\u03b5_pos : 0 < \u03b5)\n  (hF_meas : \u2200\u1da0 x in \ud835\udcdd x\u2080, ae_measurable (F x) (\u03bc.restrict (\u0399 a b)))\n  (hF_int : interval_integrable (F x\u2080) \u03bc a b)\n  (hF'_meas : ae_measurable F' (\u03bc.restrict (\u0399 a b)))\n  (h_lip : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192 lipschitz_on_with (real.nnabs $ bound t) (\u03bb x, F x t) (ball x\u2080 \u03b5))\n  (bound_integrable : interval_integrable bound \u03bc a b)\n  (h_diff : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192 has_fderiv_at (\u03bb x, F x t) (F' t) x\u2080) :\n  interval_integrable F' \u03bc a b \u2227\n    has_fderiv_at (\u03bb x, \u222b t in a..b, F x t \u2202\u03bc) (\u222b t in a..b, F' t \u2202\u03bc) x\u2080 :=\nbegin\n  simp only [interval_integrable_iff, interval_integral_eq_integral_interval_oc,\n    \u2190 ae_restrict_iff' measurable_set_interval_oc] at *,\n  have := has_fderiv_at_integral_of_dominated_loc_of_lip \u03b5_pos hF_meas hF_int hF'_meas h_lip\n    bound_integrable h_diff,\n  exact \u27e8this.1, this.2.const_smul _\u27e9\nend\n\n/-- Differentiation under integral of `x \u21a6 \u222b F x a` at a given point `x\u2080`, assuming\n`F x\u2080` is integrable, `x \u21a6 F x a` is differentiable on a ball around `x\u2080` for ae `a` with\nderivative norm uniformly bounded by an integrable function (the ball radius is independent of `a`),\nand `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x\u2080`. -/\nlemma has_fderiv_at_integral_of_dominated_of_fderiv_le {F : H \u2192 \u03b1 \u2192 E} {F' : H \u2192 \u03b1 \u2192 (H \u2192L[\ud835\udd5c] E)}\n  {x\u2080 : H} (\u03b5_pos : 0 < \u03b5)\n  (hF_meas : \u2200\u1da0 x in \ud835\udcdd x\u2080, ae_measurable (F x) (\u03bc.restrict (\u0399 a b)))\n  (hF_int : interval_integrable (F x\u2080) \u03bc a b)\n  (hF'_meas : ae_measurable (F' x\u2080) (\u03bc.restrict (\u0399 a b)))\n  (h_bound : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192 \u2200 x \u2208 ball x\u2080 \u03b5, \u2225F' x t\u2225 \u2264 bound t)\n  (bound_integrable : interval_integrable bound \u03bc a b)\n  (h_diff : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192 \u2200 x \u2208 ball x\u2080 \u03b5, has_fderiv_at (\u03bb x, F x t) (F' x t) x) :\n  has_fderiv_at (\u03bb x, \u222b t in a..b, F x t \u2202\u03bc) (\u222b t in a..b, F' x\u2080 t \u2202\u03bc) x\u2080 :=\nbegin\n  simp only [interval_integrable_iff, interval_integral_eq_integral_interval_oc,\n    \u2190 ae_restrict_iff' measurable_set_interval_oc] at *,\n  exact (has_fderiv_at_integral_of_dominated_of_fderiv_le \u03b5_pos hF_meas hF_int hF'_meas h_bound\n    bound_integrable h_diff).const_smul _\nend\n\n/-- Derivative under integral of `x \u21a6 \u222b F x a` at a given point `x\u2080 : \ud835\udd5c`, `\ud835\udd5c = \u211d` or `\ud835\udd5c = \u2102`,\nassuming `F x\u2080` is integrable, `x \u21a6 F x a` is locally Lipschitz on a ball around `x\u2080` for ae `a`\n(with ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is\nae-measurable for `x` in a possibly smaller neighborhood of `x\u2080`. -/\nlemma has_deriv_at_integral_of_dominated_loc_of_lip {F : \ud835\udd5c \u2192 \u03b1 \u2192 E} {F' : \u03b1 \u2192 E} {x\u2080 : \ud835\udd5c}\n  (\u03b5_pos : 0 < \u03b5)\n  (hF_meas : \u2200\u1da0 x in \ud835\udcdd x\u2080, ae_measurable (F x) (\u03bc.restrict (\u0399 a b)))\n  (hF_int : interval_integrable (F x\u2080) \u03bc a b)\n  (hF'_meas : ae_measurable F' (\u03bc.restrict (\u0399 a b)))\n  (h_lipsch : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192\n    lipschitz_on_with (real.nnabs $ bound t) (\u03bb x, F x t) (ball x\u2080 \u03b5))\n  (bound_integrable : interval_integrable (bound : \u03b1 \u2192 \u211d) \u03bc a b)\n  (h_diff : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192 has_deriv_at (\u03bb x, F x t) (F' t) x\u2080) :\n  (interval_integrable F' \u03bc a b) \u2227\n    has_deriv_at (\u03bb x, \u222b t in a..b, F x t \u2202\u03bc) (\u222b t in a..b, F' t \u2202\u03bc) x\u2080 :=\nbegin\n  simp only [interval_integrable_iff, interval_integral_eq_integral_interval_oc,\n    \u2190 ae_restrict_iff' measurable_set_interval_oc] at *,\n  have := has_deriv_at_integral_of_dominated_loc_of_lip \u03b5_pos hF_meas hF_int hF'_meas h_lipsch\n    bound_integrable h_diff,\n  exact \u27e8this.1, this.2.const_smul _\u27e9\nend\n\n/-- Derivative under integral of `x \u21a6 \u222b F x a` at a given point `x\u2080 : \ud835\udd5c`, `\ud835\udd5c = \u211d` or `\ud835\udd5c = \u2102`,\nassuming `F x\u2080` is integrable, `x \u21a6 F x a` is differentiable on an interval around `x\u2080` for ae `a`\n(with interval radius independent of `a`) with derivative uniformly bounded by an integrable\nfunction, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x\u2080`. -/\nlemma has_deriv_at_integral_of_dominated_loc_of_deriv_le {F : \ud835\udd5c \u2192 \u03b1 \u2192 E} {F' : \ud835\udd5c \u2192 \u03b1 \u2192 E} {x\u2080 : \ud835\udd5c}\n  (\u03b5_pos : 0 < \u03b5)\n  (hF_meas : \u2200\u1da0 x in \ud835\udcdd x\u2080, ae_measurable (F x) (\u03bc.restrict (\u0399 a b)))\n  (hF_int : interval_integrable (F x\u2080) \u03bc a b)\n  (hF'_meas : ae_measurable (F' x\u2080) (\u03bc.restrict (\u0399 a b)))\n  (h_bound : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192 \u2200 x \u2208 ball x\u2080 \u03b5, \u2225F' x t\u2225 \u2264 bound t)\n  (bound_integrable : interval_integrable bound \u03bc a b)\n  (h_diff : \u2200\u1d50 t \u2202\u03bc, t \u2208 \u0399 a b \u2192 \u2200 x \u2208 ball x\u2080 \u03b5, has_deriv_at (\u03bb x, F x t) (F' x t) x) :\n  (interval_integrable (F' x\u2080) \u03bc a b) \u2227\n    has_deriv_at (\u03bb x, \u222b t in a..b, F x t \u2202\u03bc) (\u222b t in a..b, F' x\u2080 t \u2202\u03bc) x\u2080 :=\nbegin\n  simp only [interval_integrable_iff, interval_integral_eq_integral_interval_oc,\n    \u2190 ae_restrict_iff' measurable_set_interval_oc] at *,\n  have := has_deriv_at_integral_of_dominated_loc_of_deriv_le \u03b5_pos hF_meas hF_int hF'_meas h_bound\n    bound_integrable h_diff,\n  exact \u27e8this.1, this.2.const_smul _\u27e9\nend\n\nend interval_integral\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/calculus/parametric_interval_integral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7021108726077991}}
{"text": "import term\nimport data.list.perm\nimport cdclt\n\nuniverse variables uu vv\nvariables {\u03b1 : Type uu} {\u03b2 : Type vv}\n\nopen list\n\n#check @perm\n#check @perm.refl\n#check @perm.swap\n\n#check (perm.swap 0 2 [1])\n\ntheorem rotate3 : [2,0,1] ~ [0,1,2] :=\n have h\u2080 : [2,0,1] ~ [0,2,1], from perm.swap 0 2 [1],\n have h\u2081 : [0,2,1] ~ [0,1,2], from perm.cons 0 (perm.swap 1 2 []),\n perm.trans h\u2080 h\u2081\n\ntheorem rotate3' : [2,0,1] ~ [0,1,2] :=\n perm.trans (perm.swap 0 2 [1]) (perm.cons 0 (perm.swap 1 2 []))\n\n@[reducible]\ndef swap_nth : \u2115 \u2192 list \u03b1 \u2192 list \u03b1\n| 0     (a::b::l) := b::a::l\n| (n+1) (a::l)    := a::(swap_nth n l)\n| _ l := l\n\n#eval swap_nth 0 [0,1,2]\n#eval swap_nth 1 [0,1,2]\n#eval swap_nth 2 [0,1,2]\n#eval swap_nth 3 [0,1,2]\n\ntheorem perm.swap_nth : \u2200 (n:\u2115) (l:list \u03b1), l ~ (swap_nth n l)\n| n [] := by cases n; exact perm.nil\n| 0 (a::nil) := perm.refl (a::nil)\n| 0 (a::b::l)  := perm.swap b a l\n| (n+1) (a::l) := by { rw [swap_nth, perm_cons], exact (perm.swap_nth n l) }\n\ntheorem rotate3'' : [2,0,1] ~ [0,1,2] :=\n have h\u2080 : [2,0,1] ~ [0,2,1], from perm.swap_nth 0 [2,0,1],\n have h\u2081 : [0,2,1] ~ [0,1,2], from perm.swap_nth 1 [0,2,1],\n perm.trans h\u2080 h\u2081\n\ntheorem rotate4 : [3,0,1,2] ~ [0,1,2,3] :=\n have h\u2080 : [3,0,1,2] ~ [0,3,1,2], from perm.swap_nth 0 [3,0,1,2],\n have h\u2081 : [0,3,1,2] ~ [0,1,3,2], from perm.swap_nth 1 [0,3,1,2],\n have h\u2082 : [0,1,3,2] ~ [0,1,2,3], from perm.swap_nth 2 [0,1,3,2],\n perm.trans h\u2080 (perm.trans h\u2081 h\u2082)\n\n#check perm.trans (perm.swap_nth 0 [3,0,1,2]) $\n        (perm.trans\n          (perm.swap_nth 1 [0,3,1,2])\n          (perm.swap_nth 2 [0,1,3,2]))\n\n#check @list.foldr\n\n#eval range 3\n#check list.length\n\ntheorem rotate (a:\u03b1) (l : list \u03b1) : a::l ~ l++[a] :=\n list.foldr\n  (\u03bb (n:\u2115), \u03bb (x:list \u03b1), perm.trans x (perm.swap_nth n x))\n  l (range l.length)\n\ndef swap_nonlocal : \u2115 \u2192 \u2115 \u2192 list \u03b1 \u2192 list \u03b1 := sorry\n\ndef gen_permutation : list \u03b1 \u2192 list (\u2115\u00d7\u2115) \u2192 perm _ _ := sorry\n\n-- so need to enact a sorting algorithm\n-- bubble sort\n\n-- bubble [1] -> [1]\n#check decidable_linear_order\n\ndef bubble_insert [h_dec : decidable_linear_order \u03b1] : \u03b1 \u2192 list \u03b1 \u2192 list \u03b1\n| a [] := [a]\n| a (h::t) := if a <= h then a::h::t else h::(insert a t)\n#check bubble_insert\n\ndef bubble [h_dec : decidable_linear_order \u03b1] : list \u03b1 \u2192 list \u03b1\n| [] := []\n| (h::t) := bubble_insert h (bubble t)\n", "meta": {"author": "CVC4", "repo": "signatures", "sha": "c64ffc4421cd37773c444a9ecb68f5075c47842a", "save_path": "github-repos/lean/CVC4-signatures", "path": "github-repos/lean/CVC4-signatures/signatures-c64ffc4421cd37773c444a9ecb68f5075c47842a/lean/reordering.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7021108722855364}}
{"text": "import Proofs.Naturals\n\nuniverse u \n\n-- If two functions returns the same things for the same inputs then they're equal!\naxiom extensionality : \u2200 { a b : Type u } { f g : a \u2192 b }, (\u2200 (x : a), f x = g x) \u2192 (f = g)\n\ntheorem sameAddComm : \u2200 (m n : \u2115), (add n m) = (add' m n)\n  | m, 0 => by simp [add, add']; \n  | m, \u2115.s n => by simp [add, add']; exact (sameAddComm m n)\n\ntheorem sameAdd (m n : \u2115) : (add n m) = (add' n m) := by rw [Nt.Add.comm n m]; apply sameAddComm\n\ntheorem sameFunAdd : add = add' := extensionality (\u03bbm => extensionality (\u03bbn => sameAdd n m))\n\nstructure Iso (A B : Type) where \n  To : A \u2192 B \n  From : B \u2192 A\n  FromTo : \u2200 (x : A), (From (To x) = x)\n  ToFrom : \u2200 (y : B), (To (From y) = y)\n\ninfixl:60 \"\u2245\" => Iso\n\ntheorem Iso.refl : \u2200 {a : Type}, a \u2245 a \n  | a => { To := \u03bbx => x, From := \u03bby => y, FromTo := \u03bbx => rfl, ToFrom := \u03bbx => rfl }\n\ntheorem Iso.sym : \u2200 {A B : Type}, A \u2245 B \u2192 B \u2245 A\n  | x, y, t => { To := t.From, \n                 From := t.To, \n                 FromTo := Iso.ToFrom t, \n                 ToFrom := Iso.FromTo t\n               }\n\ntheorem Iso.trans : \u2200 { a b c : Type }, a \u2245 b \u2192 b \u2245 c \u2192 a \u2245 c \n  | x, y, z, h1, h2 => \n    { To     := h2.To \u2218 h1.To,\n      From   := h1.From \u2218 h2.From,\n      FromTo := by simp[Iso.FromTo h2, Iso.FromTo h1];\n      ToFrom := by simp[Iso.ToFrom h2, Iso.ToFrom h1];\n    }\n\n-- Embedding is the notion that one function is included in other\n\nstructure Emb (A B : Type) where \n  To : A \u2192 B \n  From : B \u2192 A\n  FromTo : \u2200 (x : A), (From (To x) = x)\n\nmacro_rules | `($x emb< $y)  => `(Emb $x $y)\n\ntheorem Emb.refl : \u2200 {a : Type}, a emb< a \n  | a => { To := \u03bbx => x, From := \u03bby => y, FromTo := \u03bbx => rfl }\n\ntheorem Emb.trans : \u2200 { a b c : Type }, a emb< b \u2192 b emb< c \u2192 a emb< c \n  | x, y, z, h1, h2 => \n    { To     := h2.To \u2218 h1.To,\n      From   := h1.From \u2218 h2.From,\n      FromTo := by simp[Emb.FromTo h2, Emb.FromTo h1];\n    }", "meta": {"author": "algebraic-sofia", "repo": "books", "sha": "adb282081975c81716f8835c56e97dff0fda2748", "save_path": "github-repos/lean/algebraic-sofia-books", "path": "github-repos/lean/algebraic-sofia-books/books-adb282081975c81716f8835c56e97dff0fda2748/plfa/Proofs/Isomorphism.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.7021108698253938}}
{"text": "import ntac\nimport data.nat.prime\n\nopen nat\n\nnotation n `!`:10000 := nat.factorial n\ntheorem exists_infinite_primes_tactic (n : \u2115) : \u2203 p, n \u2264 p \u2227 nat.prime p :=\nbegin\nlet p := min_fac (n! + 1),\nexistsi p,\n  have pp : nat.prime p, {\n    have : n! + 1 \u2260 1,from (ne_of_gt $ succ_lt_succ $ factorial_pos n),\n  from min_fac_prime this},\nsimp [pp],\n{ apply le_of_not_ge,\n  intro h,\n  have h\u2081 : p \u2223 n!,from dvd_factorial (min_fac_pos _) h,\n  have h\u2082 : p \u2223 1, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _),\n  from nat.prime.not_dvd_one pp h\u2082,\n}\nend\n\ntheorem exists_infinite_primes_ntac (n : \u2115) : \u2203 p, n \u2264 p \u2227 nat.prime p :=\nbegin[ntac]\nlet p := min_fac (n! + 1),\n  existsi p,\n  have pp : nat.prime p, NTAC_focus1_list{\n    have : n! + 1 \u2260 1, from (ne_of_gt $ succ_lt_succ $ factorial_pos n),\n     from min_fac_prime this} [\"\", p, \" is prime. \"] tt tt,\n  simp [pp],\n  { apply le_of_not_ge, \n    intro h, \n    have h\u2082 : p \u2223 1, {have h\u2081 : p \u2223 n!, TRIV, from dvd_factorial (min_fac_pos _) h,\n    TRIV, from (nat.dvd_add_iff_right h\u2081).2 (min_fac_dvd _) },\n    \n    NTAC_focus1_str{from nat.prime.not_dvd_one pp h\u2082}\"This is contradiction. \" tt tt}, \n  trace_state,trace_proof_file LANG_en\nend\n\n\n", "meta": {"author": "ge9", "repo": "ntac", "sha": "c34eceeeaee6957f716874a5482ae23be94bbab1", "save_path": "github-repos/lean/ge9-ntac", "path": "github-repos/lean/ge9-ntac/ntac-c34eceeeaee6957f716874a5482ae23be94bbab1/sample/ntac-sample-prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.7021103576221615}}
{"text": "import group_theory.subgroup\nimport group_theory.quotient_group\nimport group_theory.category\nimport .category_theory\nopen category_theory\n\nuniverse u\nstructure SES (A B C : Group.{u}) :=\n(f : A \u27f6 B) (g : B \u27f6 C)\n(f_inj : function.injective f)\n(g_surj : function.surjective g)\n(im_f_eq_ker_g : set.range f = is_group_hom.ker g)\n\nlemma SES.is_cc {A B C : Group} (S : SES A B C)\n  : \u2200 x : A, S.g (S.f x) = 1 :=\n  by { intro x, apply iff.mp (is_group_hom.mem_ker S.g), \n       rw \u2190 SES.im_f_eq_ker_g, existsi x, refl }\n\nlemma is_group_hom.im_trivial {G H : Group} (\u03c6 : G \u2192 H) [is_group_hom \u03c6]\n  : \u03c6 '' is_subgroup.trivial G = is_subgroup.trivial H :=\nbegin\n  simp [set.image, set_of], rw is_group_hom.map_one \u03c6, \n  simp [is_subgroup.trivial], funext, apply propext,\n  constructor; intro h,\n  { rw h, apply or.inl, refl },\n  { symmetry, apply or.resolve_right h, exact not_false }\nend\n\nlemma SES.inj_of_left_triv {A B C : Group} [subsingleton A] (S : SES A B C)\n  : function.injective S.g :=\nbegin\n  apply iff.mpr (is_group_hom.inj_iff_trivial_ker S.g),\n  rw \u2190 S.im_f_eq_ker_g, \n  transitivity S.f '' is_subgroup.trivial A,\n  rw \u2190 set.image_univ, congr, ext, simp, apply subsingleton.elim,\n  apply is_group_hom.im_trivial\nend\n\nnoncomputable\ndef SES.iso_of_left_triv {A B C : Group} [subsingleton A] (S : SES A B C) : B \u2245 C :=\n  Group.iso_of_bijective S.g \u27e8S.inj_of_left_triv, S.g_surj\u27e9\n\nlemma SES.surj_of_right_triv {A B C : Group} [subsingleton C] (S : SES A B C)\n  : function.surjective S.f :=\nbegin\n  rw [\u2190 set.range_iff_surjective, S.im_f_eq_ker_g],\n  ext, rw is_group_hom.mem_ker, simp,\n  apply subsingleton.elim,\nend\n\nnoncomputable\ndef SES.iso_of_right_triv {A B C : Group} [subsingleton C] (S : SES A B C) : A \u2245 B :=\n  Group.iso_of_bijective S.f \u27e8S.f_inj, S.surj_of_right_triv\u27e9\n\ndef SES.transport_iso_mid {A B B' C : Group}\n  (S : SES A B C) (iso : B \u2245 B') : SES A B' C :=\n  { f := S.f \u226b iso.hom, g := iso.inv \u226b S.g,\n    f_inj := function.injective_comp (Group.iso_inj iso) S.f_inj,\n    g_surj := function.surjective_comp S.g_surj (Group.iso_surj iso.symm),\n    im_f_eq_ker_g := by {\n      unfold_coes, simp, \n      rw set.range_comp,\n      have := Group.ker_of_comp_inj S.g iso.inv (Group.iso_inj iso.symm),\n      unfold_coes at this, simp at this, rw this,\n      have := S.im_f_eq_ker_g, unfold_coes at this, rw this,\n      apply congr_fun, apply set.image_eq_preimage_of_inverse,\n      apply Group.iso_left_inverse, apply Group.iso_right_inverse } }\n\ndef SES.transport_iso_right {A B C C' : Group}\n  (S : SES A B C) (iso : C \u2245 C') : SES A B C' :=\n  { f := S.f, g := S.g \u226b iso.hom, f_inj := S.f_inj,\n    g_surj := function.surjective_comp\n                (Group.iso_surj iso)\n                S.g_surj,\n    im_f_eq_ker_g := by {\n      unfold_coes, simp,\n      transitivity is_group_hom.ker S.g,\n      exact S.im_f_eq_ker_g,\n      transitivity is_group_hom.ker (@category_struct.comp Group _ _ _ _ S.g iso.hom),\n      symmetry, apply Group.ker_of_inj_comp,\n      apply Group.iso_inj, refl } }\n\ndef SES.self_right (G : Group) : SES 1 G G :=\n  { f := \u27e8\u03bb x, 1, is_group_hom.mk' (\u03bb x y, eq.symm $ mul_one 1)\u27e9,\n    g := \ud835\udfd9 G,\n    f_inj := by { intros x y _, apply subsingleton.elim },\n    g_surj := \u03bb x, \u27e8x, rfl\u27e9,\n    im_f_eq_ker_g := by {\n      transitivity is_subgroup.trivial G,\n      ext, unfold_coes, simp, constructor; intro h; exact h.symm,\n      symmetry, apply iff.mpr (is_group_hom.trivial_ker_iff_eq_one _),\n      intros x hx, exact hx } }\n\ndef SES.normal_quotient {G : Group} (H : set G) [normal_subgroup H]\n  : SES (Group.of H) G (Group.of (quotient_group.quotient H)) := {\n    f := subtype_val.group_hom,\n    g := \u27e8quotient_group.mk, quotient_group.is_group_hom _\u27e9,\n    f_inj := subtype.val_injective,\n    g_surj := @quotient.exists_rep _ (quotient_group.left_rel _),\n    im_f_eq_ker_g := by {\n      unfold_coes, transitivity set.range subtype.val, refl,\n      rw [quotient_group.ker_mk, subtype.val_range], refl } }\n\ndef is_group_hom.coim {G H : Group} (\u03c6 : G \u2192 H) [is_group_hom \u03c6]\n  := quotient_group.quotient (is_group_hom.ker \u03c6)\n\ninstance coim_is_group {G H : Group}\n  {\u03c6 : G \u2192 H} [is_group_hom \u03c6] : group (is_group_hom.coim \u03c6) :=\n  quotient_group.group (is_group_hom.ker \u03c6)\n\ndef SES.ker_coim {G H : Group} (\u03c6 : G \u2192 H) [is_group_hom \u03c6]\n  : SES (Group.of (is_group_hom.ker \u03c6)) G (Group.of (is_group_hom.coim \u03c6)) :=\n  SES.normal_quotient (is_group_hom.ker \u03c6)\n\ndef SES.ker_im {G H : Group} (\u03c6 : G \u2192 H) [is_group_hom \u03c6]\n  : SES (Group.of (is_group_hom.ker \u03c6)) G (Group.of (set.range \u03c6)) := {\n    f := subtype_val.group_hom,\n    g := \u27e8set.range_factorization \u03c6, by apply_instance\u27e9,\n    f_inj := subtype.val_injective,\n    g_surj := set.surjective_onto_range,\n    im_f_eq_ker_g := by {\n      unfold_coes,\n      transitivity set.range subtype.val, refl,\n      transitivity is_group_hom.ker \u03c6,\n      rw subtype.range_val, funext,\n      funext, simp [set.range_factorization],\n      transitivity \u03c6 x = 1,\n      rw \u2190 is_group_hom.mem_ker \u03c6, refl,\n      rw \u2190 @set.mem_def _ _ (is_group_hom.ker _),\n      rw is_group_hom.mem_ker, rw subtype.ext, refl } }\n\nlemma SES.left_normal {A B C : Group} (S : SES A B C)\n  : normal_subgroup (set.range S.f) := \n  by rw SES.im_f_eq_ker_g; apply is_group_hom.normal_subgroup_ker\n\nnoncomputable\ndef SES.f_rev {A B C : Group} (S : SES A B C) : set.range S.f \u2192 A :=\n\u03bb y, classical.some y.property\n\nlemma SES.f_rev_spec_r {A B C : Group} (S : SES A B C)\n  : \u2200 y, S.f (S.f_rev y) = y := \u03bb y, classical.some_spec y.property\n\nlemma SES.f_rev_spec_l {A B C : Group} (S : SES A B C)\n  : \u2200 x, S.f_rev \u27e8S.f x, x, rfl\u27e9 = x :=\n  \u03bb x, S.f_inj (S.f_rev_spec_r \u27e8S.f x, x, rfl\u27e9)\n\ninstance SES.f_rev_hom {A B C} {S : SES A B C}\n  : is_group_hom (SES.f_rev S) :=\n  @is_group_hom.mk _ _ _ _ (SES.f_rev S) $ by {\n    constructor, intros,\n    cases x with x hx, cases y with y hy,\n    cases hx with a ha, cases hy with b hb,\n    subst ha, subst hb,\n    transitivity SES.f_rev S \u27e8S.f (a * b), a*b, rfl\u27e9,\n    congr, apply subtype.eq, simp,\n    rw (is_group_hom.to_is_monoid_hom S.f).map_mul,\n    apply subtype_val.is_monoid_hom.map_mul,\n    repeat { rw SES.f_rev_spec_l } }\n\nnoncomputable\ndef SES.left_iso_range {A B C : Group} (S : SES A B C) : A \u2245 Group.of (set.range S.f) := {\n  hom := \u27e8\u03bb x, \u27e8S.f x, set.mem_range_self x\u27e9,\n          is_group_hom.mk' $ \u03bb x y, by {\n            apply subtype.eq, rw is_monoid_hom.map_mul subtype.val,\n            apply is_monoid_hom.map_mul S.f, exact subtype_val.is_monoid_hom\n          }\u27e9,\n  inv := \u27e8S.f_rev, by apply_instance\u27e9,\n  hom_inv_id' := subtype.eq (funext S.f_rev_spec_l),\n  inv_hom_id' := subtype.eq (funext $ \u03bb x, subtype.eq $ S.f_rev_spec_r x)\n}\n\nnoncomputable\ndef SES.pullback {H G K A B : Group} (S : SES H G K) (S' : SES A K B)\n  : SES H (Group.of ((S.g) \u207b\u00b9' set.range (S'.f))) A := \n  { f := \u27e8\u03bb x, subtype.mk (S.f x)\n            $ by { rw set.mem_preimage, \n                    have : S.f x \u2208 is_group_hom.ker S.g,\n                    { rw \u2190 SES.im_f_eq_ker_g, existsi x, refl },\n                    rw this.resolve_right not_false,\n                    have : is_subgroup (set.range S'.f) := is_group_hom.range_subgroup S'.f,\n                    apply is_submonoid.one_mem },\n          @is_group_hom.mk _ _ _ _ _ $ by {\n      constructor, intros, apply subtype.eq,\n      unfold_coes, simp, transitivity S.f x * S.f y,\n      apply is_monoid_hom.map_mul, refl }\u27e9,\n    f_inj := by { intros x y h, apply S.f_inj, \n                  unfold_coes at h, simp at h, exact h },\n    g := \u27e8\u03bb x, S'.f_rev \u27e8S.g x.val, x.property\u27e9,\n          @is_group_hom.mk _ _ _ _ _ $ by {\n            constructor, intros, \n            rw \u2190 is_monoid_hom.map_mul S'.f_rev, congr, \n            rw is_monoid_hom.map_mul subtype.val,\n            unfold_coes, simp,\n            apply is_monoid_hom.map_mul,\n            apply is_group_hom.to_is_monoid_hom, }\u27e9,\n    g_surj := \u03bb y, by { unfold_coes, simp,\n                        cases S.g_surj (S'.f y) with x hx, \n                        refine exists.intro (subtype.mk x _) _,\n                        apply set.mem_preimage.mpr, existsi y, exact hx.symm,\n                        simp, transitivity S'.f_rev \u27e8S'.f y, y, rfl\u27e9,\n                        congr, assumption, apply SES.f_rev_spec_l },\n    im_f_eq_ker_g := by {\n      ext, cases x with x hx,\n      transitivity x \u2208 set.range S.f,\n      { constructor; intro h; cases h with a ha,\n        { existsi a, unfold_coes at ha, simp at ha, assumption },\n        { have h := hx, rw \u2190 ha at h,\n          rw (_ : subtype.mk x hx = subtype.mk (S.f a) h),\n          existsi a, refl, apply subtype.eq, exact ha.symm, } },\n      rw [SES.im_f_eq_ker_g, is_group_hom.mem_ker, is_group_hom.mem_ker],\n      unfold_coes, simp,\n      constructor; intro h,\n      { transitivity S'.f_rev \u27e81, is_submonoid.one_mem _\u27e9,\n        congr, assumption, apply is_group_hom.map_one S'.f_rev, },\n      { have := congr_arg S'.f h,\n        rw SES.f_rev_spec_r at this,\n        unfold_coes at this, simp at this, rw this,\n        apply is_group_hom.map_one, } } }.\n\nlemma ker_comp {A B C : Group} (f : A \u27f6 B) (g : B \u27f6 C)\n  : is_group_hom.ker (g \u2218 f) = f\u207b\u00b9' (is_group_hom.ker g) :=\nby ext; rw [is_group_hom.mem_ker, set.mem_preimage, is_group_hom.mem_ker]\n\ndef third_iso {H G K A B : Group}\n  (S : SES H G K) (S' : SES A K B)\n  : SES (Group.of (S.g \u207b\u00b9' set.range S'.f)) G B := {\n    f := subtype_val.group_hom,\n    g := S.g \u226b S'.g,\n    f_inj := \u03bb _ _ h, subtype.eq h,\n    g_surj := function.surjective_comp S'.g_surj S.g_surj,\n    im_f_eq_ker_g := by {\n      unfold_coes, transitivity is_group_hom.ker (S'.g \u2218 S.g),\n      rw ker_comp, rw \u2190 S'.im_f_eq_ker_g, \n      transitivity set.range subtype.val, refl,\n      simp, refl, refl } }\n\nlocal attribute [instance] classical.prop_decidable\nlemma SES.simple {G : Group}\n  : simple_group G \u2194 (\u2200 {H K : Group}, nonempty (SES H G K) \u2192 subsingleton H \u2228 subsingleton K) := \nbegin\n  constructor; intro h,\n  { intros H K S, cases S with S,\n    cases h, cases h (is_group_hom.ker S.g) with h h,\n    { apply or.inl,\n      rw [\u2190 S.im_f_eq_ker_g, is_subgroup.eq_trivial_iff] at h,\n      constructor, intros, apply S.f_inj, \n      transitivity (1 : G), apply h, existsi a, refl,\n      symmetry, apply h, existsi b, refl },\n    { apply or.inr, constructor, intros,\n      cases (S.g_surj a) with a ha, subst ha,\n      cases (S.g_surj b) with b hb, subst hb,\n      have ha : a \u2208 set.univ := set.mem_univ _,\n      have hb : b \u2208 set.univ := set.mem_univ _,\n      rw [\u2190 h, is_group_hom.mem_ker] at ha hb,\n      transitivity (1 : K), assumption, symmetry, assumption } },\n  { constructor, intros,\n    cases h \u27e8@SES.normal_quotient G N _inst_1\u27e9 with h h,\n    { apply or.inl,\n      rw @is_subgroup.eq_trivial_iff _ _ N _inst_1.to_is_subgroup,\n      intros, apply @subtype.mk.inj _ N, apply @subsingleton.elim _ h,\n      assumption, apply @is_submonoid.one_mem _ _ _ _inst_1.to_is_submonoid },\n    { apply or.inr, apply set.eq_univ_of_forall,\n      suffices : \u2200 x : G, 1\u207b\u00b9 * x \u2208 N,\n      { intro, specialize this x, rw [one_inv, one_mul] at this, exact this },\n      cases h with h, intro x,\n      specialize h (@quotient_group.mk _ _ N _inst_1.to_is_subgroup 1),\n      specialize h (@quotient_group.mk _ _ N _inst_1.to_is_subgroup x),\n      dsimp [quotient_group.mk] at h,\n      rw quotient.eq' at h_1, assumption, } }\nend\n\ndef partial_second_iso {H H' G G' K K' : Group.{u}}\n  (iso : G \u2245 G') (hK' : simple_group K')\n  (S : SES H G K) (S' : SES H' G' K')\n  (x : H) (x_not_in_H' : \u00ac (S'.g (iso.hom (S.f x)) = 1))\n  : SES (Group.of $ pullback (S.f \u226b iso.hom) S'.f) H K' := {\n    f := @subtype_val.group_hom (Group.of $ H \u00d7 H') _ _ \u226b @Group.fst H H',\n    g := S.f \u226b iso.hom \u226b S'.g,\n    f_inj := by { intros x y h,\n                  cases x with x hx, cases x with x\u2081 x\u2082,\n                  cases y with y hy, cases y with y\u2081 y\u2082,\n                  replace h : x\u2081 = y\u2081 := h, apply subtype.eq,\n                  simp, apply and.intro h, apply S'.f_inj,\n                  exact eq.trans (eq.symm hx) (eq.trans (congr_arg _ h) hy) },\n    g_surj := by { intro y, cases S'.g_surj y with a ha,\n                   destruct hK', intro hK',\n                   replace hK' := \u03bb inst, @hK' (S'.g '' (iso.hom '' set.range S.f)) inst,\n                   suffices : normal_subgroup (S'.g '' (iso.hom '' set.range S.f)),\n                   have : S'.g '' (iso.hom '' set.range S.f) = set.univ,\n                   { apply or.resolve_left (hK' this), intro h,\n                     apply x_not_in_H',\n                     rw [\u2190 is_subgroup.mem_trivial, \u2190 h],\n                     apply set.mem_image_of_mem,\n                     apply set.mem_image_of_mem,\n                     apply set.mem_range_self },\n                   rw set.eq_univ_iff_forall at this,\n                   simp, cases this y with a ha,\n                   cases ha with ha' ha, cases ha' with a ha, cases ha with ha' ha,\n                   subst ha, subst ha, cases ha' with a ha', existsi a, rw ha',\n                   rw SES.im_f_eq_ker_g, rw \u2190 set.image_comp,\n                   apply @surj_im_normal G K' (iso.hom \u226b S'.g),\n                   apply function.surjective_comp, exact S'.g_surj, apply Group.iso_surj },\n    im_f_eq_ker_g := by {\n      unfold_coes, simp,\n      transitivity is_group_hom.ker (@category_struct.comp Group _ _ _ _ S.f\n                                      (@category_struct.comp Group _ _ _ _ iso.hom S'.g)),\n      rw Group.ker_of_comp_inj _ _ S.f_inj,\n      dsimp [subtype_val.group_hom, Group.fst],\n      rw [set.range_comp, subtype.range_val],\n      rw [Group.ker_of_comp_inj _ _ (Group.iso_inj iso), \u2190 S'.im_f_eq_ker_g],\n      ext x, rw set.mem_preimage,\n      constructor; intro h; cases h with k hk,\n      { existsi k.snd, symmetry, rw \u2190 hk.right, exact hk.left },\n      { existsi (x, k), constructor, exact hk.symm, refl },\n      refl\n    }\n  }\n\nstructure SES.equiv {H H' G G' K K' : Group}\n  (iso : G \u2245 G') (S : SES H G K) (S' : SES H' G' K') :=\n(\u03b1 : H \u2245 H') (\u03b2 : K \u2245 K')\n(l_comm : S.f \u226b iso.hom = \u03b1.hom \u226b S'.f)\n(r_comm : S.g \u226b \u03b2.hom = iso.hom \u226b S'.g)\n\ndef SES.equiv_symm {H H' G G' K K' : Group}\n  (iso : G \u2245 G') (S : SES H G K) (S' : SES H' G' K')\n  (eqv : SES.equiv iso S S') : SES.equiv iso.symm S' S := {\n    \u03b1 := eqv.\u03b1.symm, \u03b2 := eqv.\u03b2.symm,\n    l_comm := by {\n      refine (_ : @category_struct.comp Group _ _ _ _ S'.f iso.inv \n                = @category_struct.comp Group _ _ _ _ eqv.\u03b1.inv S.f),\n      rw [iso.comp_inv_eq, category.assoc, eqv.l_comm, \u2190 category.assoc,\n          eqv.\u03b1.inv_hom_id, category.id_comp] },\n    r_comm := by {\n      refine (_ : @category_struct.comp Group _ _ _ _ S'.g eqv.\u03b2.inv \n                = @category_struct.comp Group _ _ _ _ iso.inv S.g),\n      symmetry,\n      rw [iso.inv_comp_eq, \u2190 category.assoc, \u2190 eqv.r_comm, category.assoc,\n          eqv.\u03b2.hom_inv_id, category.comp_id] }\n  }\n\nnoncomputable\ndef SES.map_out_right {H G G' K : Group} (S : SES H G K)\n  (\u03c6 : G \u27f6 G') (hker : \u2200 x : H, \u03c6 (S.f x) = 1) : K \u27f6 G' := {\n    val := \u03bb k, \u03c6 (function.inv_fun S.g k),\n    property := is_group_hom.mk' $ by {\n      intros,\n      rw [\u2190 is_monoid_hom.map_mul \u03c6, is_group_hom.one_iff_ker_inv \u03c6],\n      suffices : function.inv_fun S.g (x * y)\n               * (function.inv_fun S.g x * function.inv_fun \u21d1(S.g) y)\u207b\u00b9\n               \u2208 set.range S.f,\n      { cases this with a ha, rw \u2190 ha, apply_assumption },\n      rw [SES.im_f_eq_ker_g, is_group_hom.mem_ker, \u2190 is_group_hom.one_iff_ker_inv],\n      rw is_monoid_hom.map_mul S.g,\n      repeat { rw @function.inv_fun_eq _ _ _ S.g _ (S.g_surj _) }\n    }\n  }\n\nlemma SES.map_out_right_comm {H G G' K : Group} (S : SES H G K)\n  (\u03c6 : G \u27f6 G') (hker : \u2200 x : H, \u03c6 (S.f x) = 1)\n  : \u2200 x : G, SES.map_out_right S \u03c6 hker (S.g x) = \u03c6 x :=\nbegin\n  intros,\n  apply iff.mpr (is_group_hom.one_iff_ker_inv \u03c6 (function.inv_fun S.g $ S.g x) x),\n  suffices : function.inv_fun S.g (S.g x) * x\u207b\u00b9 \u2208 set.range S.f,\n  { cases this with a ha, rw \u2190 ha, apply_assumption },\n  rw [SES.im_f_eq_ker_g, is_group_hom.mem_ker, \u2190 is_group_hom.one_iff_ker_inv],\n  apply function.right_inverse_inv_fun, exact S.g_surj\nend\n\nnoncomputable\ndef SES.equiv_of_left {H H' G G' K K' : Group}\n  (iso : G \u2245 G') (S : SES H G K) (S' : SES H' G' K')\n  (\u03b1 : H \u2245 H') (l_comm : S.f \u226b iso.hom = \u03b1.hom \u226b S'.f)\n  : SES.equiv iso S S' := \n  have h1 : \u2200 x, (iso.hom \u226b S'.g) (S.f x) = 1,\n  by { intro, rw \u2190 iso.eq_comp_inv at l_comm, rw l_comm,\n       suffices : S'.g ((iso.hom.val \u2218 iso.inv.val) (S'.f (\u03b1.hom x))) = 1,\n       exact this, have := iso.inv_hom_id,\n       simp [(\u226b), category_struct.id] at this,\n       rw this, simp, apply S'.is_cc },\n  have h2 : \u2200 x, (iso.inv \u226b S.g) (S'.f x) = 1,\n  by by { intro, replace l_comm := l_comm.symm,\n          rw \u2190 \u03b1.eq_inv_comp at l_comm, rw l_comm,\n          suffices : S.g ((iso.inv.val \u2218 iso.hom.val) (S.f (\u03b1.inv x))) = 1,\n          exact this, have := iso.hom_inv_id,\n          simp [(\u226b), category_struct.id] at this,\n          rw this, simp, apply S.is_cc },\n  { \u03b1 := \u03b1, l_comm := l_comm,\n    \u03b2 := {\n      hom := SES.map_out_right S (iso.hom \u226b S'.g) h1,\n      inv := SES.map_out_right S' (iso.inv \u226b S.g) h2,\n      hom_inv_id' := by {\n        ext, cases S.g_surj x with x h, subst h, unfold_coes, simp,\n        have := SES.map_out_right_comm S (iso.hom \u226b S'.g) h1 x,\n        unfold_coes at this, simp [(\u226b)] at this, rw this, clear this,\n        have := SES.map_out_right_comm S' (iso.inv \u226b S.g) h2 (iso.hom.val x),\n        unfold_coes at this, simp [(\u226b)] at this, rw this, clear this,\n        congr, transitivity (iso.inv.val \u2218 iso.hom.val) x, refl,\n        transitivity id x, apply congr_fun, exact subtype.mk.inj iso.hom_inv_id, refl,\n      },\n      inv_hom_id' := by {\n        ext, cases S'.g_surj x with x h, subst h, unfold_coes, simp,\n        have := SES.map_out_right_comm S' (iso.inv \u226b S.g) h2 x,\n        unfold_coes at this, simp [(\u226b)] at this, rw this, clear this,\n        have := SES.map_out_right_comm S (iso.hom \u226b S'.g) h1 (iso.inv.val x),\n        unfold_coes at this, simp [(\u226b)] at this, rw this, clear this,\n        congr, transitivity (iso.hom.val \u2218 iso.inv.val) x, refl,\n        transitivity id x, apply congr_fun, exact subtype.mk.inj iso.inv_hom_id, refl,\n      }\n    },\n    r_comm := by {\n      unfold_coes, simp,\n      ext, transitivity SES.map_out_right S (iso.hom \u226b S'.g) h1 (S.g x),\n      refl, apply SES.map_out_right_comm,\n    }\n  }.\n\nnoncomputable\ndef SES.equiv_of_ker_im_match {H H' G G' K K' : Group}\n  (iso : G \u2245 G') (S : SES H G K) (S' : SES H' G' K')\n  (h_l : \u2200 x : H, S'.g (iso.hom (S.f x)) = 1)\n  (h_r : \u2200 x : H', S.g (iso.inv (S'.f x)) = 1)\n  : SES.equiv iso S S' :=\n    have h1 : iso.hom '' set.range S.f \u2286 is_group_hom.ker S'.g\n            \u2227 iso.inv '' set.range S'.f \u2286 is_group_hom.ker S.g,\n    from by { constructor; intros x hx;\n              cases hx with x hx; cases hx with hx hx;\n              subst hx; cases hx with x hx; subst hx;\n              rw is_group_hom.mem_ker; apply_assumption },\n    have h2 : iso.hom '' set.range S.f = set.range S'.f,\n    by { rw [\u2190 S.im_f_eq_ker_g, \u2190 S'.im_f_eq_ker_g] at h1,\n         cases h1 with h h', rw set.image_subset_iff at h',\n         rw \u2190 set.image_eq_preimage_of_inverse at h',\n         exact funext (\u03bb x, propext \u27e8@h x, @h' x\u27e9),\n         apply Group.iso_left_inverse, apply Group.iso_right_inverse },\n    have h3  : Group.of \u21a5(\u21d1(iso.hom) '' set.range \u21d1(S.f)) = Group.of \u21a5(set.range \u21d1(S'.f)),\n    by { rw Group.subgroup_eq_of_eq h2, },\n    have h4 : \u2200 {A B : Group} (h : A = B) (t : A),\n          t == (eq.rec (category_theory.iso.refl A) h : A \u2245 B).hom.val t,\n    by { intros, cases h, refl },\n    begin\n      refine SES.equiv_of_left iso S S' _ _,  \n      transitivity,\n      exact (S.left_iso_range \u226a\u226b Group.iso_restrict iso _),\n      transitivity, tactic.swap, apply S'.left_iso_range.symm,\n      exact eq.rec (category_theory.iso.refl (Group.of \u21a5(\u21d1(iso.hom) '' set.range \u21d1(S.f)))) h3,\n      rw category_theory.iso.trans_assoc,\n      ext, \n      dsimp [(\u226a\u226b)], \n      dsimp [SES.left_iso_range],\n      dsimp [Group.iso_restrict],\n      unfold_coes,\n      dsimp [subtype.val],\n      rw (_ : S'.f.val = \u21d1(S'.f)), tactic.swap, refl,\n      rw S'.f_rev_spec_r,\n      unfold_coes, \n      clear h1, clear h_l, clear h_r, \n      generalize h : subtype.mk ((iso.hom).val ((S.f).val x)) _ = t,\n      transitivity t.val, { subst h },\n      congr, ext, rw h2, apply h4 h3\n    end\n\nlemma Group.normal_subgroup_card_lt_of_nontriv_quot\n  {H G K : Group} [fintype G] (S : SES H G K) (hK : \u00ac subsingleton K)\n  : @fintype.card H (fintype.of_injective S.f S.f_inj) < fintype.card G :=\nbegin\n  have : \u2203 k : K, k \u2260 1,\n  { by_contradiction h, rw not_exists_not at h,\n    apply hK, constructor, intros,\n    transitivity (1 : K), apply h, symmetry, apply h },\n  cases this with k hk, cases S.g_surj k with x hx, subst hx,\n  replace hk := mt (iff.mp (is_group_hom.mem_ker S.g)) hk,\n  rw [\u2190 S.im_f_eq_ker_g] at hk,\n  apply @nat.lt_of_le_of_lt _ (@finset.card _ (finset.erase finset.univ x)),\n  have h1 : \u2200 (y : G), y \u2208 finset.erase finset.univ x \u2194 y \u2260 x,\n  { intro, rw [finset.mem_erase, (_ : y \u2208 finset.univ \u2194 true)],\n    apply and_true, rw iff_true, apply finset.mem_univ },\n  have h2 : fintype { y : G // y \u2260 x } := fintype.subtype _ h1,\n  rw \u2190 @fintype.subtype_card _ (\u03bb y, y \u2260 x) _ h1,\n  apply @nat.le_trans _ (@fintype.card { y : G // y \u2260 x } h2),\n  apply @fintype.card_le_of_injective H _ (fintype.of_injective S.f S.f_inj) h2\n          (\u03bb y, \u27e8S.f y, \u03bb h, hk \u27e8y, h\u27e9\u27e9)\n          (\u03bb _ _ hab, S.f_inj (subtype.mk.inj hab)),\n  apply nat.le_of_eq, congr, \n  rw finset.card_erase_of_mem, dsimp [fintype.card],\n  apply nat.pred_lt, refine (_ : \u00ac (fintype.card G = 0)),\n  rw fintype.card_eq_zero_iff, exact \u03bb h, h 1, apply finset.mem_univ\nend\n\ndef SES.not_contains_of_simple_quot_and_proper {H H' G G' K K' : Group} (iso : G \u2245 G')\n  (S : SES H G K) (S' : SES H' G' K')\n  (hK : simple_group K) (hK' : \u00ac subsingleton K')\n  (hnoteqv : SES.equiv iso S S' \u2192 false)\n  : \u2203 x, S'.g (iso.hom (S.f x)) \u2260 1 :=\nbegin\n  have h1 : \u00ac ((\u2200 x, S'.g (iso.hom (S.f x)) = 1)\n          \u2227 (\u2200 x, S.g (iso.inv (S'.f x)) = 1)),\n  { intro h, apply hnoteqv, cases h,\n    apply SES.equiv_of_ker_im_match; assumption },\n  rw classical.not_and_distrib at h1, cases h1, \n  rw \u2190 classical.not_forall, assumption,\n  rw \u2190 classical.not_forall, intro h2, apply h1,\n  suffices : iso.inv '' set.range S'.f \u2286 is_group_hom.ker S.g,\n  { intro, rw \u2190 is_group_hom.mem_ker S.g,\n    exact this \u27e8S'.f x, set.mem_range_self x, rfl\u27e9 },\n  destruct hK, intro,\n  have : iso.hom '' set.range S.f \u2286 is_group_hom.ker S'.g,\n  { intros x hx, cases hx with x' hx,\n    rw \u2190 hx.right, cases hx.left with x hx, rw \u2190 hx,\n    rw is_group_hom.mem_ker, apply h2 },\n  cases @simple (S.g '' (iso.inv '' is_group_hom.ker S'.g))\n                (@surj_im_normal _ _ S.g S.g_surj _\n                  (surj_im_normal iso.inv (Group.iso_surj iso.symm) _)),\n  rw [set.image_subset_iff,\n    \u2190 set.image_eq_preimage_of_inverse\n      (Group.iso_right_inverse _) (Group.iso_left_inverse _)] at this,\n  transitivity S.g \u207b\u00b9' (S.g '' (iso.inv '' is_group_hom.ker S'.g)),\n  rw S'.im_f_eq_ker_g, apply set.subset_preimage_image S.g,\n  rw h, refl, exfalso, apply hK',\n  have : \u2200 x : K', x = 1,\n  { have h3 := Group.eq_of_im_eq_and_contain_ker _ h _,\n    intro x, cases S'.g_surj x with x hx, subst hx,\n    rw \u2190 is_group_hom.mem_ker S'.g,\n    have h4 : iso.inv x \u2208 set.univ := set.mem_univ _,\n    rw [\u2190 h3, set.mem_image_iff_of_inverse\n              (Group.iso_right_inverse _) (Group.iso_left_inverse _),\n        Group.iso_right_inverse _] at h4, \n    assumption,\n    rw [\u2190 S.im_f_eq_ker_g,\n        set.image_eq_preimage_of_inverse\n          (Group.iso_right_inverse _) (Group.iso_left_inverse _)],\n    rw \u2190 set.image_subset_iff, assumption },\n  constructor, intros, transitivity (1 : K'),\n  apply_assumption, symmetry, apply_assumption, \nend\n\nnoncomputable\ndef SES.partial_second_iso' {H H' G G' K K' : Group} (iso : G \u2245 G')\n  (S : SES H G K) (S' : SES H' G' K')\n  (hK\u2081 : simple_group K) (hK\u2082 : \u00ac subsingleton K)\n  (hK'\u2081 : simple_group K') (hK'\u2082 : \u00ac subsingleton K')\n  (hnoteqv : SES.equiv iso S S' \u2192 false)\n  : SES (Group.of (pullback (S.f \u226b iso.hom) S'.f)) H K' :=\nbegin\n  cases classical.subtype_of_exists (SES.not_contains_of_simple_quot_and_proper iso S S' hK\u2081 hK'\u2082 hnoteqv),\n  apply @partial_second_iso H H' G G' K K' iso hK'\u2081 S S', assumption,\nend", "meta": {"author": "Shamrock-Frost", "repo": "jordan-holder", "sha": "bab3daccd70a4f3c5b25731b899a2cd72d7b8376", "save_path": "github-repos/lean/Shamrock-Frost-jordan-holder", "path": "github-repos/lean/Shamrock-Frost-jordan-holder/jordan-holder-bab3daccd70a4f3c5b25731b899a2cd72d7b8376/src/SES.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7021103313247724}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\n\nimport topology.algebra.nonarchimedean.bases\nimport topology.algebra.uniform_filter_basis\nimport ring_theory.valuation.basic\n\n/-!\n# The topology on a valued ring\n\nIn this file, we define the non archimedean topology induced by a valuation on a ring.\nThe main definition is a `valued` type class which equips a ring with a valuation taking\nvalues in a group with zero (living in the same universe). Other instances are then deduced from\nthis.\n-/\n\nopen_locale classical topological_space\nopen set valuation\nnoncomputable theory\n\nuniverse u\n\n/-- A valued ring is a ring that comes equipped with a distinguished valuation.-/\nclass valued (R : Type u) [ring R] :=\n(\u0393\u2080 : Type u)\n[grp : linear_ordered_comm_group_with_zero \u0393\u2080]\n(v : valuation R \u0393\u2080)\n\nattribute [instance] valued.grp\n\nnamespace valued\nvariables {R : Type*} [ring R] [valued R]\n\n/-- The basis of open subgroups for the topology on a valued ring.-/\nlemma subgroups_basis : ring_subgroups_basis (\u03bb \u03b3 : (\u0393\u2080 R)\u02e3, valued.v.lt_add_subgroup \u03b3) :=\n{ inter := begin\n    rintros \u03b3\u2080 \u03b3\u2081,\n    use min \u03b3\u2080 \u03b3\u2081,\n    simp [valuation.lt_add_subgroup] ; tauto\n  end,\n  mul := begin\n    rintros \u03b3,\n    cases exists_square_le \u03b3 with \u03b3\u2080 h,\n    use \u03b3\u2080,\n    rintro - \u27e8r, s, r_in, s_in, rfl\u27e9,\n    calc v (r*s) = v r * v s : valuation.map_mul _ _ _\n             ... < \u03b3\u2080*\u03b3\u2080 : mul_lt_mul\u2080 r_in s_in\n             ... \u2264 \u03b3 : by exact_mod_cast h\n  end,\n  left_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use 1,\n      rintros y (y_in : v y < 1),\n      change v (x * y) < _,\n      rw [valuation.map_mul, Hx, zero_mul],\n      exact units.zero_lt \u03b3 },\n    { simp only [image_subset_iff, set_of_subset_set_of, preimage_set_of_eq, valuation.map_mul],\n      use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change v (x * y) < \u03b3,\n      rw [valuation.map_mul, Hx, mul_comm],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end,\n  right_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use 1,\n      rintros y (y_in : v y < 1),\n      change v (y * x) < _,\n      rw [valuation.map_mul, Hx, mul_zero],\n      exact units.zero_lt \u03b3 },\n    { use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change v (y * x) < \u03b3,\n      rw [valuation.map_mul, Hx],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end }\n\n@[priority 100]\ninstance : topological_space R := subgroups_basis.topology\n\nlemma mem_nhds {s : set R} {x : R} :\n  (s \u2208 \ud835\udcdd x) \u2194 \u2203 \u03b3 : (valued.\u0393\u2080 R)\u02e3, {y | v (y - x) < \u03b3 } \u2286 s :=\nby simpa [(subgroups_basis.has_basis_nhds x).mem_iff]\n\nlemma mem_nhds_zero {s : set R} :\n  (s \u2208 \ud835\udcdd (0 : R)) \u2194 \u2203 \u03b3 : (\u0393\u2080 R)\u02e3, {x | v x < (\u03b3 : \u0393\u2080 R) } \u2286 s :=\nby simp [valued.mem_nhds, sub_zero]\n\nlemma loc_const {x : R} (h : v x \u2260 0) : {y : R | v y = v x} \u2208 \ud835\udcdd x :=\nbegin\n  rw valued.mem_nhds,\n  rcases units.exists_iff_ne_zero.mpr h with \u27e8\u03b3, hx\u27e9,\n  use \u03b3,\n  rw hx,\n  intros y y_in,\n  exact valuation.map_eq_of_sub_lt _ y_in\nend\n\n/-- The uniform structure on a valued ring.-/\n@[priority 100]\ninstance uniform_space : uniform_space R := topological_add_group.to_uniform_space R\n\n/-- A valued ring is a uniform additive group.-/\n@[priority 100]\ninstance uniform_add_group : uniform_add_group R := topological_add_group_is_uniform\n\nlemma cauchy_iff {F : filter R} :\n  cauchy F \u2194 F.ne_bot \u2227 \u2200 \u03b3 : (\u0393\u2080 R)\u02e3, \u2203 M \u2208 F, \u2200 x y \u2208 M, v (y - x) < \u03b3 :=\nbegin\n  rw add_group_filter_basis.cauchy_iff,\n  apply and_congr iff.rfl,\n  simp_rw subgroups_basis.mem_add_group_filter_basis_iff,\n  split,\n  { intros h \u03b3,\n    exact h _ (subgroups_basis.mem_add_group_filter_basis _) },\n  { rintros h - \u27e8\u03b3, rfl\u27e9,\n    exact h \u03b3 }\nend\nend valued\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/topology/algebra/valuation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7020777912007402}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.int.least_greatest\n! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Int.Order.Basic\n\n/-! # Least upper bound and greatest lower bound properties for integers\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove that a bounded above nonempty set of integers has the greatest element, and a\ncounterpart of this statement for the least element.\n\n## Main definitions\n\n* `int.least_of_bdd`: if `P : \u2124 \u2192 Prop` is a decidable predicate, `b` is a lower bound of the set\n  `{m | P m}`, and there exists `m : \u2124` such that `P m` (this time, no witness is required), then\n  `int.least_of_bdd` returns the least number `m` such that `P m`, together with proofs of `P m` and\n  of the minimality. This definition is computable and does not rely on the axiom of choice.\n* `int.greatest_of_bdd`: a similar definition with all inequalities reversed.\n\n## Main statements\n\n* `int.exists_least_of_bdd`: if `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is\n  bounded below and nonempty, then this set has the least element. This lemma uses classical logic\n  to avoid assumption `[decidable_pred P]`. See `int.least_of_bdd` for a constructive counterpart.\n\n* `int.coe_least_of_bdd_eq`: `(int.least_of_bdd b Hb Hinh : \u2124)` does not depend on `b`.\n\n* `int.exists_greatest_of_bdd`, `int.coe_greatest_of_bdd_eq`: versions of the above lemmas with all\n  inequalities reversed.\n\n## Tags\n\ninteger numbers, least element, greatest element\n-/\n\n\nnamespace Int\n\n#print Int.leastOfBdd /-\n/-- A computable version of `exists_least_of_bdd`: given a decidable predicate on the\nintegers, with an explicit lower bound and a proof that it is somewhere true, return\nthe least value for which the predicate is true. -/\ndef leastOfBdd {P : \u2124 \u2192 Prop} [DecidablePred P] (b : \u2124) (Hb : \u2200 z : \u2124, P z \u2192 b \u2264 z)\n    (Hinh : \u2203 z : \u2124, P z) : { lb : \u2124 // P lb \u2227 \u2200 z : \u2124, P z \u2192 lb \u2264 z } :=\n  have EX : \u2203 n : \u2115, P (b + n) :=\n    let \u27e8elt, Helt\u27e9 := Hinh\n    match elt, le.dest (Hb _ Helt), Helt with\n    | _, \u27e8n, rfl\u27e9, Hn => \u27e8n, Hn\u27e9\n  \u27e8b + (Nat.find EX : \u2124), Nat.find_spec EX, fun z h =>\n    match z, le.dest (Hb _ h), h with\n    | _, \u27e8n, rfl\u27e9, h => add_le_add_left (Int.ofNat_le.2 <| Nat.find_min' _ h) _\u27e9\n#align int.least_of_bdd Int.leastOfBdd\n-/\n\n/- warning: int.exists_least_of_bdd -> Int.exists_least_of_bdd is a dubious translation:\nlean 3 declaration is\n  forall {P : Int -> Prop}, (Exists.{1} Int (fun (b : Int) => forall (z : Int), (P z) -> (LE.le.{0} Int Int.hasLe b z))) -> (Exists.{1} Int (fun (z : Int) => P z)) -> (Exists.{1} Int (fun (lb : Int) => And (P lb) (forall (z : Int), (P z) -> (LE.le.{0} Int Int.hasLe lb z))))\nbut is expected to have type\n  forall {P : Int -> Prop} [Hbdd : DecidablePred.{1} Int P], (Exists.{1} Int (fun (z : Int) => forall (z_1 : Int), (P z_1) -> (LE.le.{0} Int Int.instLEInt z z_1))) -> (Exists.{1} Int (fun (z : Int) => P z)) -> (Exists.{1} Int (fun (lb : Int) => And (P lb) (forall (z : Int), (P z) -> (LE.le.{0} Int Int.instLEInt lb z))))\nCase conversion may be inaccurate. Consider using '#align int.exists_least_of_bdd Int.exists_least_of_bdd\u2093'. -/\n/-- If `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is bounded below and nonempty,\nthen this set has the least element. This lemma uses classical logic to avoid assumption\n`[decidable_pred P]`. See `int.least_of_bdd` for a constructive counterpart. -/\ntheorem exists_least_of_bdd {P : \u2124 \u2192 Prop} (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 b \u2264 z)\n    (Hinh : \u2203 z : \u2124, P z) : \u2203 lb : \u2124, P lb \u2227 \u2200 z : \u2124, P z \u2192 lb \u2264 z := by\n  classical exact\n      let \u27e8b, Hb\u27e9 := Hbdd\n      let \u27e8lb, H\u27e9 := least_of_bdd b Hb Hinh\n      \u27e8lb, H\u27e9\n#align int.exists_least_of_bdd Int.exists_least_of_bdd\n\n#print Int.coe_leastOfBdd_eq /-\ntheorem coe_leastOfBdd_eq {P : \u2124 \u2192 Prop} [DecidablePred P] {b b' : \u2124} (Hb : \u2200 z : \u2124, P z \u2192 b \u2264 z)\n    (Hb' : \u2200 z : \u2124, P z \u2192 b' \u2264 z) (Hinh : \u2203 z : \u2124, P z) :\n    (leastOfBdd b Hb Hinh : \u2124) = leastOfBdd b' Hb' Hinh :=\n  by\n  rcases least_of_bdd b Hb Hinh with \u27e8n, hn, h2n\u27e9\n  rcases least_of_bdd b' Hb' Hinh with \u27e8n', hn', h2n'\u27e9\n  exact le_antisymm (h2n _ hn') (h2n' _ hn)\n#align int.coe_least_of_bdd_eq Int.coe_leastOfBdd_eq\n-/\n\n#print Int.greatestOfBdd /-\n/-- A computable version of `exists_greatest_of_bdd`: given a decidable predicate on the\nintegers, with an explicit upper bound and a proof that it is somewhere true, return\nthe greatest value for which the predicate is true. -/\ndef greatestOfBdd {P : \u2124 \u2192 Prop} [DecidablePred P] (b : \u2124) (Hb : \u2200 z : \u2124, P z \u2192 z \u2264 b)\n    (Hinh : \u2203 z : \u2124, P z) : { ub : \u2124 // P ub \u2227 \u2200 z : \u2124, P z \u2192 z \u2264 ub } :=\n  have Hbdd' : \u2200 z : \u2124, P (-z) \u2192 -b \u2264 z := fun z h => neg_le.1 (Hb _ h)\n  have Hinh' : \u2203 z : \u2124, P (-z) :=\n    let \u27e8elt, Helt\u27e9 := Hinh\n    \u27e8-elt, by rw [neg_neg] <;> exact Helt\u27e9\n  let \u27e8lb, Plb, al\u27e9 := leastOfBdd (-b) Hbdd' Hinh'\n  \u27e8-lb, Plb, fun z h => le_neg.1 <| al _ <| by rwa [neg_neg]\u27e9\n#align int.greatest_of_bdd Int.greatestOfBdd\n-/\n\n/- warning: int.exists_greatest_of_bdd -> Int.exists_greatest_of_bdd is a dubious translation:\nlean 3 declaration is\n  forall {P : Int -> Prop}, (Exists.{1} Int (fun (b : Int) => forall (z : Int), (P z) -> (LE.le.{0} Int Int.hasLe z b))) -> (Exists.{1} Int (fun (z : Int) => P z)) -> (Exists.{1} Int (fun (ub : Int) => And (P ub) (forall (z : Int), (P z) -> (LE.le.{0} Int Int.hasLe z ub))))\nbut is expected to have type\n  forall {P : Int -> Prop} [Hbdd : DecidablePred.{1} Int P], (Exists.{1} Int (fun (z : Int) => forall (z_1 : Int), (P z_1) -> (LE.le.{0} Int Int.instLEInt z_1 z))) -> (Exists.{1} Int (fun (z : Int) => P z)) -> (Exists.{1} Int (fun (ub : Int) => And (P ub) (forall (z : Int), (P z) -> (LE.le.{0} Int Int.instLEInt z ub))))\nCase conversion may be inaccurate. Consider using '#align int.exists_greatest_of_bdd Int.exists_greatest_of_bdd\u2093'. -/\n/-- If `P : \u2124 \u2192 Prop` is a predicate such that the set `{m : P m}` is bounded above and nonempty,\nthen this set has the greatest element. This lemma uses classical logic to avoid assumption\n`[decidable_pred P]`. See `int.greatest_of_bdd` for a constructive counterpart. -/\ntheorem exists_greatest_of_bdd {P : \u2124 \u2192 Prop} (Hbdd : \u2203 b : \u2124, \u2200 z : \u2124, P z \u2192 z \u2264 b)\n    (Hinh : \u2203 z : \u2124, P z) : \u2203 ub : \u2124, P ub \u2227 \u2200 z : \u2124, P z \u2192 z \u2264 ub := by\n  classical exact\n      let \u27e8b, Hb\u27e9 := Hbdd\n      let \u27e8lb, H\u27e9 := greatest_of_bdd b Hb Hinh\n      \u27e8lb, H\u27e9\n#align int.exists_greatest_of_bdd Int.exists_greatest_of_bdd\n\n#print Int.coe_greatestOfBdd_eq /-\ntheorem coe_greatestOfBdd_eq {P : \u2124 \u2192 Prop} [DecidablePred P] {b b' : \u2124} (Hb : \u2200 z : \u2124, P z \u2192 z \u2264 b)\n    (Hb' : \u2200 z : \u2124, P z \u2192 z \u2264 b') (Hinh : \u2203 z : \u2124, P z) :\n    (greatestOfBdd b Hb Hinh : \u2124) = greatestOfBdd b' Hb' Hinh :=\n  by\n  rcases greatest_of_bdd b Hb Hinh with \u27e8n, hn, h2n\u27e9\n  rcases greatest_of_bdd b' Hb' Hinh with \u27e8n', hn', h2n'\u27e9\n  exact le_antisymm (h2n' _ hn) (h2n _ hn')\n#align int.coe_greatest_of_bdd_eq Int.coe_greatestOfBdd_eq\n-/\n\nend Int\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Int/LeastGreatest.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694177, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7020777888078474}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar si\n--    s \u2286 t\n-- entonces\n--    s \u2229 u \u2286 t \u2229 u\n-- ----------------------------------------------------------------------\n\nimport tactic\n\nvariable {\u03b1 : Type*}\nvariables (s t u : set \u03b1)\n\nopen set\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  rw subset_def,\n  rw inter_def,\n  rw inter_def,\n  dsimp,\n  rw subset_def at h,\n  rintros x \u27e8xs, xu\u27e9,\n  split,\n  { exact h x xs },\n  { exact xu },\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u\n  >> rw subset_def,\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2229 u \u2192 x \u2208 t \u2229 u\n  >> rw inter_def,\n\u22a2 \u2200 (x : \u03b1), x \u2208 {a : \u03b1 | a \u2208 s \u2227 a \u2208 u} \u2192 x \u2208 t \u2229 u\n  >> rw inter_def,\n\u22a2 \u2200 (x : \u03b1), x \u2208 {a : \u03b1 | a \u2208 s \u2227 a \u2208 u} \u2192 x \u2208 {a : \u03b1 | a \u2208 t \u2227 a \u2208 u}\n  >> dsimp,\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> rw subset_def at h,\nh : \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2208 t\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> rintros x \u27e8xs, xu\u27e9,\nx : \u03b1,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> split,\n| \u22a2 x \u2208 t\n|   >> { exact h x xs },\n\u22a2 x \u2208 u\n  >> { exact xu },\nno goals\n-/\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  rw [subset_def, inter_def, inter_def],\n  dsimp,\n  rw subset_def at h,\n  rintros x \u27e8xs, xu\u27e9,\n  exact \u27e8h _ xs, xu\u27e9,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u  >> rw [subset_def, inter_def, inter_def],\n  >> dsimp,\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> rw subset_def at h,\nh : \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2208 t\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> rintros x \u27e8xs, xu\u27e9,\nx : \u03b1,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> exact \u27e8h _ xs, xu\u27e9,\nno goals\n-/\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  simp only [subset_def, mem_inter_eq] at *,\n  rintros x \u27e8xs, xu\u27e9,\n  exact \u27e8h _ xs, xu\u27e9,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u\n  >> simp only [subset_def, mem_inter_eq] at *,\nh : \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2208 t\n\u22a2 \u2200 (x : \u03b1), x \u2208 s \u2227 x \u2208 u \u2192 x \u2208 t \u2227 x \u2208 u\n  >> rintros x \u27e8xs, xu\u27e9,\nx : \u03b1,\nxs : x \u2208 s,\nxu : x \u2208 u\n\u22a2 x \u2208 t \u2227 x \u2208 u\n  >> exact \u27e8h _ xs, xu\u27e9,\nno goals\n-/\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nby finish [subset_def, mem_inter_eq]\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\nbegin\n  intros x xsu,\n  exact \u27e8h xsu.1, xsu.2\u27e9,\nend\n\n-- Prueba\n-- ======\n\n/-\n\u03b1 : Type u_1,\ns t u : set \u03b1,\nh : s \u2286 t\n\u22a2 s \u2229 u \u2286 t \u2229 u\n  >> intros x xsu,\nx : \u03b1,\nxsu : x \u2208 s \u2229 u\n\u22a2 x \u2208 t \u2229 u\n  >> exact \u27e8h xsu.1, xsu.2\u27e9,\nno goals\n-/\n\n-- Comentario: La t\u00e1ctica *intro* aplica una *reducci\u00f3n definicional*\n-- expandiendo las definiciones.\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample (h : s \u2286 t) : s \u2229 u \u2286 t \u2229 u :=\nby exact \u03bb x \u27e8xs, xu\u27e9, \u27e8h xs, xu\u27e9\n\n-- 7\u00aa demostraci\u00f3n\n-- ===============\n\nlemma monotonia\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\n\u03bb x \u27e8xs, xu\u27e9, \u27e8h xs, xu\u27e9\n\n-- 8\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : s \u2286 t)\n  : s \u2229 u \u2286 t \u2229 u :=\ninter_subset_inter_left u h\n\n-- Comentario: Se han usado los lemas\n-- + inter_def : s \u2229 t = {a : \u03b1 | a \u2208 s \u2227 a \u2208 t}\n-- + inter_subset_inter_left : s \u2286 t \u2192 s \u2229 u \u2286 t \u2229 u\n-- + mem_inter_eq x s t : x \u2208 s \u2229 t = (x \u2208 s \u2227 x \u2208 t)\n-- + subset_def : s \u2286 t = \u2200 (x : \u03b1), x \u2208 s \u2192 x \u2208 t\n\n-- Comprobaci\u00f3n:\nvariable (x : \u03b1)\n-- #check @subset_def _ s t\n-- #check @inter_def _ s t\n-- #check @mem_inter_eq _ x s t\n-- #check @inter_subset_inter_left _ s t u\n", "meta": {"author": "jaalonso", "repo": "Matematicas_en_Lean", "sha": "c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8", "save_path": "github-repos/lean/jaalonso-Matematicas_en_Lean", "path": "github-repos/lean/jaalonso-Matematicas_en_Lean/Matematicas_en_Lean-c44e23d87665cb4aa00c813c6bfb3c41ebc83aa8/src/Conjuntos/Monotonia_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7020777814980739}}
{"text": "/-\nCopyright (c) 2021 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot\n-/\n\nimport topology.algebra.nonarchimedean.bases\nimport topology.algebra.uniform_filter_basis\nimport ring_theory.valuation.basic\n\n/-!\n# The topology on a valued ring\n\nIn this file, we define the non archimedean topology induced by a valuation on a ring.\nThe main definition is a `valued` type class which equips a ring with a valuation taking\nvalues in a group with zero (living in the same universe). Other instances are then deduced from\nthis.\n-/\n\nopen_locale classical topological_space\nopen set valuation\nnoncomputable theory\n\nuniverse u\n\n/-- A valued ring is a ring that comes equipped with a distinguished valuation.-/\nclass valued (R : Type u) [ring R] :=\n(\u0393\u2080 : Type u)\n[grp : linear_ordered_comm_group_with_zero \u0393\u2080]\n(v : valuation R \u0393\u2080)\n\nattribute [instance] valued.grp\n\nnamespace valued\nvariables {R : Type*} [ring R] [valued R]\n\n/-- The basis of open subgroups for the topology on a valued ring.-/\nlemma subgroups_basis : ring_subgroups_basis (\u03bb \u03b3 : units (\u0393\u2080 R), valued.v.lt_add_subgroup \u03b3) :=\n{ inter := begin\n    rintros \u03b3\u2080 \u03b3\u2081,\n    use min \u03b3\u2080 \u03b3\u2081,\n    simp [valuation.lt_add_subgroup] ; tauto\n  end,\n  mul := begin\n    rintros \u03b3,\n    cases exists_square_le \u03b3 with \u03b3\u2080 h,\n    use \u03b3\u2080,\n    rintro - \u27e8r, s, r_in, s_in, rfl\u27e9,\n    calc v (r*s) = v r * v s : valuation.map_mul _ _ _\n             ... < \u03b3\u2080*\u03b3\u2080 : mul_lt_mul\u2080 r_in s_in\n             ... \u2264 \u03b3 : by exact_mod_cast h\n  end,\n  left_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use 1,\n      rintros y (y_in : v y < 1),\n      change v (x * y) < _,\n      rw [valuation.map_mul, Hx, zero_mul],\n      exact units.zero_lt \u03b3 },\n    { simp only [image_subset_iff, set_of_subset_set_of, preimage_set_of_eq, valuation.map_mul],\n      use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change v (x * y) < \u03b3,\n      rw [valuation.map_mul, Hx, mul_comm],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end,\n  right_mul := begin\n    rintros x \u03b3,\n    rcases group_with_zero.eq_zero_or_unit (v x) with Hx | \u27e8\u03b3x, Hx\u27e9,\n    { use 1,\n      rintros y (y_in : v y < 1),\n      change v (y * x) < _,\n      rw [valuation.map_mul, Hx, mul_zero],\n      exact units.zero_lt \u03b3 },\n    { use \u03b3x\u207b\u00b9*\u03b3,\n      rintros y (vy_lt : v y < \u2191(\u03b3x\u207b\u00b9 * \u03b3)),\n      change v (y * x) < \u03b3,\n      rw [valuation.map_mul, Hx],\n      rw [units.coe_mul, mul_comm] at vy_lt,\n      simpa using mul_inv_lt_of_lt_mul\u2080 vy_lt }\n  end }\n\n@[priority 100]\ninstance : topological_space R := subgroups_basis.topology\n\nlemma mem_nhds {s : set R} {x : R} :\n  (s \u2208 \ud835\udcdd x) \u2194 \u2203 \u03b3 : units (valued.\u0393\u2080 R), {y | v (y - x) < \u03b3 } \u2286 s :=\nby simpa [(subgroups_basis.has_basis_nhds x).mem_iff]\n\nlemma mem_nhds_zero {s : set R} :\n  (s \u2208 \ud835\udcdd (0 : R)) \u2194 \u2203 \u03b3 : units (\u0393\u2080 R), {x | v x < (\u03b3 : \u0393\u2080 R) } \u2286 s :=\nby simp [valued.mem_nhds, sub_zero]\n\nlemma loc_const {x : R} (h : v x \u2260 0) : {y : R | v y = v x} \u2208 \ud835\udcdd x :=\nbegin\n  rw valued.mem_nhds,\n  rcases units.exists_iff_ne_zero.mpr h with \u27e8\u03b3, hx\u27e9,\n  use \u03b3,\n  rw hx,\n  intros y y_in,\n  exact valuation.map_eq_of_sub_lt _ y_in\nend\n\n/-- The uniform structure on a valued ring.-/\n@[priority 100]\ninstance uniform_space : uniform_space R := topological_add_group.to_uniform_space R\n\n/-- A valued ring is a uniform additive group.-/\n@[priority 100]\ninstance uniform_add_group : uniform_add_group R := topological_add_group_is_uniform\n\nlemma cauchy_iff {F : filter R} :\n  cauchy F \u2194 F.ne_bot \u2227 \u2200 \u03b3 : units (\u0393\u2080 R), \u2203 M \u2208 F, \u2200 x y, x \u2208 M \u2192 y \u2208 M \u2192 v (y - x) < \u03b3 :=\nbegin\n  rw add_group_filter_basis.cauchy_iff,\n  apply and_congr iff.rfl,\n  simp_rw subgroups_basis.mem_add_group_filter_basis_iff,\n  split,\n  { intros h \u03b3,\n    exact h _ (subgroups_basis.mem_add_group_filter_basis _) },\n  { rintros h - \u27e8\u03b3, rfl\u27e9,\n    exact h \u03b3 }\nend\nend valued\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/algebra/valuation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985636, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.702077780301627}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov, Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Anne Baanen\n-/\nimport data.fintype.card\nimport data.fintype.fin\nimport logic.equiv.fin\n\n/-!\n# Big operators and `fin`\n\nSome results about products and sums over the type `fin`.\n\nThe most important results are the induction formulas `fin.prod_univ_cast_succ`\nand `fin.prod_univ_succ`, and the formula `fin.prod_const` for the product of a\nconstant function. These results have variants for sums instead of products.\n\n-/\n\nopen_locale big_operators\n\nopen finset\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*}\n\nnamespace finset\n\n@[to_additive]\ntheorem prod_range [comm_monoid \u03b2] {n : \u2115} (f : \u2115 \u2192 \u03b2) :\n  \u220f i in finset.range n, f i = \u220f i : fin n, f i :=\nprod_bij'\n  (\u03bb k w, \u27e8k, mem_range.mp w\u27e9)\n  (\u03bb a ha, mem_univ _)\n  (\u03bb a ha, congr_arg _ (fin.coe_mk _).symm)\n  (\u03bb a m, a)\n  (\u03bb a m, mem_range.mpr a.prop)\n  (\u03bb a ha, fin.coe_mk _)\n  (\u03bb a ha, fin.eta _ _)\n\nend finset\n\nnamespace fin\n\n@[to_additive]\ntheorem prod_univ_def [comm_monoid \u03b2] {n : \u2115} (f : fin n \u2192 \u03b2) :\n  \u220f i, f i = ((list.fin_range n).map f).prod :=\nby simp [univ_def, finset.fin_range]\n\n@[to_additive]\ntheorem prod_of_fn [comm_monoid \u03b2] {n : \u2115} (f : fin n \u2192 \u03b2) :\n  (list.of_fn f).prod = \u220f i, f i :=\nby rw [list.of_fn_eq_map, prod_univ_def]\n\n/-- A product of a function `f : fin 0 \u2192 \u03b2` is `1` because `fin 0` is empty -/\n@[to_additive \"A sum of a function `f : fin 0 \u2192 \u03b2` is `0` because `fin 0` is empty\"]\ntheorem prod_univ_zero [comm_monoid \u03b2] (f : fin 0 \u2192 \u03b2) : \u220f i, f i = 1 := rfl\n\n/-- A product of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the product of `f x`, for some `x : fin (n + 1)` times the remaining product -/\n@[to_additive\n/- A sum of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the sum of `f x`, for some `x : fin (n + 1)` plus the remaining product -/]\n\n\n/-- A product of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the product of `f 0` plus the remaining product -/\n@[to_additive\n/- A sum of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the sum of `f 0` plus the remaining product -/]\ntheorem prod_univ_succ [comm_monoid \u03b2] {n : \u2115} (f : fin (n + 1) \u2192 \u03b2) :\n  \u220f i, f i = f 0 * \u220f i : fin n, f i.succ :=\nprod_univ_succ_above f 0\n\n/-- A product of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the product of `f (fin.last n)` plus the remaining product -/\n@[to_additive\n/- A sum of a function `f : fin (n + 1) \u2192 \u03b2` over all `fin (n + 1)`\nis the sum of `f (fin.last n)` plus the remaining sum -/]\ntheorem prod_univ_cast_succ [comm_monoid \u03b2] {n : \u2115} (f : fin (n + 1) \u2192 \u03b2) :\n  \u220f i, f i = (\u220f i : fin n, f i.cast_succ) * f (last n) :=\nby simpa [mul_comm] using prod_univ_succ_above f (last n)\n\n@[to_additive] lemma prod_cons [comm_monoid \u03b2] {n : \u2115} (x : \u03b2) (f : fin n \u2192 \u03b2) :\n  \u220f i : fin n.succ, (cons x f : fin n.succ \u2192 \u03b2) i = x * \u220f i : fin n, f i :=\nby simp_rw [prod_univ_succ, cons_zero, cons_succ]\n\n@[to_additive sum_univ_one] theorem prod_univ_one [comm_monoid \u03b2] (f : fin 1 \u2192 \u03b2) :\n  \u220f i, f i = f 0 :=\nby simp\n\n@[to_additive] theorem prod_univ_two [comm_monoid \u03b2] (f : fin 2 \u2192 \u03b2) :\n  \u220f i, f i = f 0 * f 1 :=\nby simp [prod_univ_succ]\n\nlemma sum_pow_mul_eq_add_pow {n : \u2115} {R : Type*} [comm_semiring R] (a b : R) :\n  \u2211 s : finset (fin n), a ^ s.card * b ^ (n - s.card) = (a + b) ^ n :=\nby simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b\n\nlemma prod_const [comm_monoid \u03b1] (n : \u2115) (x : \u03b1) : \u220f i : fin n, x = x ^ n := by simp\n\nlemma sum_const [add_comm_monoid \u03b1] (n : \u2115) (x : \u03b1) : \u2211 i : fin n, x = n \u2022 x := by simp\n\n@[to_additive] lemma prod_Ioi_zero {M : Type*} [comm_monoid M] {n : \u2115} {v : fin n.succ \u2192 M} :\n  \u220f i in Ioi 0, v i = \u220f j : fin n, v j.succ :=\nby rw [Ioi_zero_eq_map, finset.prod_map, rel_embedding.coe_fn_to_embedding, coe_succ_embedding]\n\n@[to_additive]\nlemma prod_Ioi_succ {M : Type*} [comm_monoid M] {n : \u2115} (i : fin n) (v : fin n.succ \u2192 M) :\n  \u220f j in Ioi i.succ, v j = \u220f j in Ioi i, v j.succ :=\nby rw [Ioi_succ, finset.prod_map, rel_embedding.coe_fn_to_embedding, coe_succ_embedding]\n\n@[to_additive]\nlemma prod_congr' {M : Type*} [comm_monoid M] {a b : \u2115} (f : fin b \u2192 M) (h : a = b) :\n  \u220f (i : fin a), f (cast h i) = \u220f (i : fin b), f i :=\nby { subst h, congr, ext, congr, ext, rw coe_cast, }\n\n@[to_additive]\nlemma prod_univ_add {M : Type*} [comm_monoid M] {a b : \u2115} (f : fin (a+b) \u2192 M) :\n  \u220f (i : fin (a+b)), f i =\n  (\u220f (i : fin a), f (cast_add b i)) * \u220f (i : fin b), f (nat_add a i) :=\nbegin\n  rw fintype.prod_equiv fin_sum_fin_equiv.symm f (\u03bb i, f (fin_sum_fin_equiv.to_fun i)), swap,\n  { intro x,\n    simp only [equiv.to_fun_as_coe, equiv.apply_symm_apply], },\n  apply prod_on_sum,\nend\n\n@[to_additive]\nlemma prod_trunc {M : Type*} [comm_monoid M] {a b : \u2115} (f : fin (a+b) \u2192 M)\n  (hf : \u2200 (j : fin b), f (nat_add a j) = 1) :\n  \u220f (i : fin (a+b)), f i =\n  \u220f (i : fin a), f (cast_le (nat.le.intro rfl) i) :=\nby simpa only [prod_univ_add, fintype.prod_eq_one _ hf, mul_one]\n\nend fin\n\nnamespace list\n\n@[to_additive]\nlemma prod_take_of_fn [comm_monoid \u03b1] {n : \u2115} (f : fin n \u2192 \u03b1) (i : \u2115) :\n  ((of_fn f).take i).prod = \u220f j in finset.univ.filter (\u03bb (j : fin n), j.val < i), f j :=\nbegin\n  have A : \u2200 (j : fin n), \u00ac ((j : \u2115) < 0) := \u03bb j, not_lt_bot,\n  induction i with i IH, { simp [A] },\n  by_cases h : i < n,\n  { have : i < length (of_fn f), by rwa [length_of_fn f],\n    rw prod_take_succ _ _ this,\n    have A : ((finset.univ : finset (fin n)).filter (\u03bb j, j.val < i + 1))\n      = ((finset.univ : finset (fin n)).filter (\u03bb j, j.val < i)) \u222a {(\u27e8i, h\u27e9 : fin n)},\n        by { ext j, simp [nat.lt_succ_iff_lt_or_eq, fin.ext_iff, - add_comm] },\n    have B : _root_.disjoint (finset.filter (\u03bb (j : fin n), j.val < i) finset.univ)\n      (singleton (\u27e8i, h\u27e9 : fin n)), by simp,\n    rw [A, finset.prod_union B, IH],\n    simp },\n  { have A : (of_fn f).take i = (of_fn f).take i.succ,\n    { rw \u2190 length_of_fn f at h,\n      have : length (of_fn f) \u2264 i := not_lt.mp h,\n      rw [take_all_of_le this, take_all_of_le (le_trans this (nat.le_succ _))] },\n    have B : \u2200 (j : fin n), ((j : \u2115) < i.succ) = ((j : \u2115) < i),\n    { assume j,\n      have : (j : \u2115) < i := lt_of_lt_of_le j.2 (not_lt.mp h),\n      simp [this, lt_trans this (nat.lt_succ_self _)] },\n    simp [\u2190 A, B, IH] }\nend\n\n@[to_additive]\nlemma prod_of_fn [comm_monoid \u03b1] {n : \u2115} {f : fin n \u2192 \u03b1} :\n  (of_fn f).prod = \u220f i, f i :=\nbegin\n  convert prod_take_of_fn f n,\n  { rw [take_all_of_le (le_of_eq (length_of_fn f))] },\n  { have : \u2200 (j : fin n), (j : \u2115) < n := \u03bb j, j.is_lt,\n    simp [this] }\nend\n\nlemma alternating_sum_eq_finset_sum {G : Type*} [add_comm_group G] :\n  \u2200 (L : list G), alternating_sum L = \u2211 i : fin L.length, (-1 : \u2124) ^ (i : \u2115) \u2022 L.nth_le i i.is_lt\n| [] := by { rw [alternating_sum, finset.sum_eq_zero], rintro \u27e8i, \u27e8\u27e9\u27e9 }\n| (g :: []) := by simp\n| (g :: h :: L) :=\ncalc g + -h + L.alternating_sum\n    = g + -h + \u2211 i : fin L.length, (-1 : \u2124) ^ (i : \u2115) \u2022 L.nth_le i i.2 :\n      congr_arg _ (alternating_sum_eq_finset_sum _)\n... = \u2211 i : fin (L.length + 2), (-1 : \u2124) ^ (i : \u2115) \u2022 list.nth_le (g :: h :: L) i _ :\nbegin\n  rw [fin.sum_univ_succ, fin.sum_univ_succ, add_assoc],\n  unfold_coes,\n  simp [nat.succ_eq_add_one, pow_add],\n  refl,\nend\n\n@[to_additive]\nlemma alternating_prod_eq_finset_prod {G : Type*} [comm_group G] :\n  \u2200 (L : list G), alternating_prod L = \u220f i : fin L.length, (L.nth_le i i.2) ^ ((-1 : \u2124) ^ (i : \u2115))\n| [] := by { rw [alternating_prod, finset.prod_eq_one], rintro \u27e8i, \u27e8\u27e9\u27e9 }\n| (g :: []) :=\nbegin\n  show g = \u220f i : fin 1, [g].nth_le i i.2 ^ (-1 : \u2124) ^ (i : \u2115),\n  rw [fin.prod_univ_succ], simp,\nend\n| (g :: h :: L) :=\ncalc g * h\u207b\u00b9 * L.alternating_prod\n    = g * h\u207b\u00b9 * \u220f i : fin L.length, L.nth_le i i.2 ^ (-1 : \u2124) ^ (i : \u2115) :\n      congr_arg _ (alternating_prod_eq_finset_prod _)\n... = \u220f i : fin (L.length + 2), list.nth_le (g :: h :: L) i _ ^ (-1 : \u2124) ^ (i : \u2115) :\nbegin\n  rw [fin.prod_univ_succ, fin.prod_univ_succ, mul_assoc],\n  unfold_coes,\n  simp [nat.succ_eq_add_one, pow_add],\n  refl,\nend\n\nend list\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/big_operators/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7020777777776396}}
{"text": "import data.int.basic\n\ndef zpow (x : \u2124) (y : \u2124) : \u2124 := x ^ int.to_nat y\n\nnamespace zpow\n\ninstance : has_pow \u2124 \u2124 := \u27e8zpow\u27e9\n\n@[simp] lemma zpow_eq_pow (x y : \u2124) : zpow x y = x ^ y := rfl\n\nlemma zpow_def (x y : \u2124) : x ^ y = x ^ int.to_nat y := rfl\n\n@[simp] lemma zpow_zero (x : \u2124) : x ^ (0 : \u2124) = 1 := \nby simp [zpow_def, int.to_nat_zero]\n\n-- TODO: Move.\nlemma int.to_nat_nonneg (x : \u2124) : 0 \u2264 int.to_nat x := by simp\n\n@[simp] lemma zpow_eq_zero_iff (x y : \u2124) : x ^ y = 0 \u2194 x = 0 \u2227 0 < y :=\nbegin \n    simp only [zpow_def],\n    split,\n    { intros h, refine \u27e8_, _\u27e9,\n      exact (pow_eq_zero h),\n      cases y,\n      { erw int.to_nat_coe_nat at h,\n        cases y,\n        { rw pow_zero at h, cases h, },\n        { have hy := int.lt_add_succ 0 y,\n          rw zero_add at hy,\n          exact hy, } },\n      { rw [int.to_nat_zero_of_neg (int.neg_succ_lt_zero y)] at h,\n        rw pow_zero at h, cases h, }, },\n    { rintros \u27e8hx, hy\u27e9,\n      have hy' : 0 < int.to_nat y := int.to_nat_zero \u25b8 (int.to_nat_lt_to_nat hy).2 hy,\n      rw [hx, zero_pow hy'], },\nend\n\n@[simp] lemma zero_zpow {x : \u2124} (h : x > 0) : (0 : \u2124) ^ x = 0 := \n(zpow_eq_zero_iff 0 x).mpr \u27e8rfl, h\u27e9\n\n@[simp] lemma zpow_one (x : \u2124) : x ^ (1 : \u2124) = x := \nby simp only [zpow_def, int.to_nat_one]; exact pow_one x\n\n@[simp] lemma one_zpow (x : \u2124) : (1 : \u2124) ^ x = 1 := \nby simp only [zpow_def]; exact one_pow (int.to_nat x)\n\nlemma zpow_add {x : \u2124} (y z : \u2124) (hy : 0 \u2264 y) (hz : 0 \u2264 z) \n: x ^ (y + z) = x ^ y * x ^ z := \nby simp only [zpow_def, int.to_nat_add hy hz]; exact (pow_add _ _ _)\n\n-- TODO: Move.\nlemma int.to_nat_mul {a b : \u2124} (ha : 0 \u2264 a) (hb : 0 \u2264 b) :\n  (a * b).to_nat = a.to_nat * b.to_nat :=\nbegin\n  lift a to \u2115 using ha,\n  lift b to \u2115 using hb,\n  norm_cast,\nend\n\nlemma zpow_mul {x y : \u2124} (z : \u2124) (hy : 0 \u2264 y) (hz : 0 \u2264 z) \n: x ^ (y * z) = (x ^ y) ^ z := \nby simp only [zpow_def, int.to_nat_mul hy hz]; exact (pow_mul x _ _)\n\n@[simp] lemma zpow_nat_cast (x : \u2124) : \u2200 (n : \u2115), x ^ (n : \u2124) = x ^ n := \n\u03bb n, by simp only [zpow_def]; rw int.to_nat_coe_nat\n\nend zpow\n", "meta": {"author": "ramonfmir", "repo": "lean-experiments", "sha": "041c8727bb540fb8d1519c1ad84924d473885c27", "save_path": "github-repos/lean/ramonfmir-lean-experiments", "path": "github-repos/lean/ramonfmir-lean-experiments/lean-experiments-041c8727bb540fb8d1519c1ad84924d473885c27/src/ODE_enclosures/zpow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7020777772449633}}
{"text": "import analysis.specific_limits.normed\n\n\nopen_locale big_operators\n\ntheorem tsum_coe_mul_geometric_succ\n{x : \u211d} (hx1: x<1) (hx2 : 0 < x)\n:\n\u2211' k : \u2115, (k + 1 : \u211d)*(x^(k+1)) = x/(1-x)^2\n:=\nbegin\n  have hxnorm : \u2016x\u2016 < 1, {refine abs_lt.mpr \u27e8_, _\u27e9 ; linarith }, \n  conv{find (_*_){rw [pow_succ, mul_comm x _, \u2190 mul_assoc, right_distrib, one_mul],}},\n  rw [tsum_mul_right, tsum_add, tsum_coe_mul_geometric_of_norm_lt_1, tsum_geometric_of_lt_1, inv_eq_one_div, right_distrib,\n  show x/(1-x)^2*x = x^2/(1-x)^2, by {field_simp, rw \u2190 pow_two}, mul_comm (1/_) x, \u2190 mul_div_assoc x 1 _, mul_one, show  x^2/(1-x)^2+x/(1-x) = x/(1-x)^2, \n  by {rw [show x^2/(1-x)^2+x/(1-x) = x/(1-x)*(x/(1-x)+1), by {rw left_distrib, simp, rw [\u2190 pow_two, div_pow]}, \n  div_add_one, \u2190 add_sub_assoc, add_sub_cancel', pow_two], field_simp, nlinarith}],\n  iterate 3 {linarith},\n  simpa using summable_pow_mul_geometric_of_norm_lt_1 1 hxnorm,\n  simpa using summable_geometric_of_norm_lt_1 hxnorm,\nend\n\ntheorem tsum_geometric_of_lt_1_pow_succ\n{x : \u211d}(hx1: x<1)(hx2 : 0 < x)\n:\n\u2211' k, x^(k+1) = x/(1-x)\n:=\nbegin\nconv{find (x^(_+1)){rw [pow_succ, mul_comm x _],}},\nrw [tsum_mul_right, tsum_geometric_of_lt_1, inv_eq_one_div, mul_comm, \u2190 mul_div_assoc, mul_one],\niterate 2 {linarith},\nend\n\nnamespace nnreal\n\ntheorem tsum_eq_zero_add {f : \u2115 \u2192 nnreal} (hf : summable f) :\n\u2211' (b : \u2115), f b = f 0 + \u2211' (b : \u2115), f (b + 1) :=\nbegin\n  apply subtype.ext,\n  push_cast,\n  let g : \u2115 \u2192 \u211d := \u03bb n, f n,\n  have hg : summable g,\n  { apply summable.map hf (nnreal.to_real_hom : nnreal \u2192+ \u211d) continuous_induced_dom },\n  exact tsum_eq_zero_add hg,\nend\n\ntheorem tsum_coe_mul_geometric_of_norm_lt_1 {r : nnreal} (hr : r < 1) :\n\u2211' (n : \u2115), (\u2191n) * r ^ n = r / (1 - r) ^ 2 :=\nbegin\nhave hr' : \u2016(r : \u211d)\u2016 < 1,\n{ rw [real.norm_eq_abs, abs_lt],\nsplit,\n{ refine lt_of_lt_of_le _ r.coe_nonneg, norm_num },\n{ exact_mod_cast hr } },\napply nnreal.coe_injective,\nconvert tsum_coe_mul_geometric_of_norm_lt_1 hr',\n{ norm_cast },\n{ push_cast,\nrw nnreal.coe_sub hr.le,\nnorm_cast },\nend\n\nend nnreal\n", "meta": {"author": "ATOMSLab", "repo": "LeanChemicalTheories", "sha": "c2b15363c1e0ea0e52c1ae86abd1650670ff9044", "save_path": "github-repos/lean/ATOMSLab-LeanChemicalTheories", "path": "github-repos/lean/ATOMSLab-LeanChemicalTheories/LeanChemicalTheories-c2b15363c1e0ea0e52c1ae86abd1650670ff9044/src/math/infinite_series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7020704306615313}}
{"text": "/-\nCopyright (c) 2022 Jun Yoshida. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n-/\n\nimport Mathlib.Algebra.Group.Defs\nimport Moncalc.CategoryTheory.Monoidal.Unbiased\n\n/-!\n# Unbiased monoical structure on `Nat`\n\n`Nat` becomes an unbiased monoidal category as a poset.\n-/\n\nnamespace List\n\nvariable {\u03b1 : Type u} [AddMonoid \u03b1]\n\ndef sum : List \u03b1 \u2192 \u03b1 :=\n  List.foldr (\u00b7+\u00b7) 0\n\ntheorem sum_nil : sum (\u03b1:=\u03b1) [] = 0 := rfl\n\ntheorem sum_cons (a : \u03b1) (as : List \u03b1) : sum (a::as) = a + sum as := rfl\n\ntheorem sum_append (as bs : List \u03b1) : (as++bs).sum = as.sum + bs.sum := by\n  induction as\n  case nil =>\n    change sum bs = 0 + sum bs\n    rw [AddMonoid.zero_add]\n  case cons a as h_ind =>\n    dsimp\n    change a + sum (as++bs) = a + sum as + sum bs\n    rw [h_ind]\n    rw [AddSemigroup.add_assoc]\n\ntheorem sum_join (ass : List (List \u03b1)) : ass.join.sum = (ass.map sum).sum := by\n  induction ass\n  case nil => rfl\n  case cons n ns h_ind =>\n    dsimp\n    rw [sum_append, sum_cons, h_ind]\n\nend List\n\n\ninductive LEHom : Nat \u2192 Nat \u2192 Type\n| mk {m n : Nat} : m \u2264 n \u2192 LEHom m n\n\nnamespace LEHom\n\n@[reducible]\nprotected\ndef comp {l m n : Nat} : LEHom l m \u2192 LEHom m n \u2192 LEHom l n\n| mk hlm, mk hmn => mk (trans hlm hmn)\n\nprotected\ndef sum : {ms ns : List Nat} \u2192 (hs : DVect2 LEHom ms ns) \u2192 LEHom ms.sum ns.sum\n| [], [], DVect2.nil => mk (Nat.le_refl 0)\n| (_::_), (_::_), DVect2.cons (mk h) hs => mk $ by\n  simp\n  let (mk h_ind) := LEHom.sum hs\n  exact Nat.add_le_add h h_ind\n\nend LEHom\n\nopen CategoryTheory\n\ninstance instCateroyNatWithLE : Category Nat where\n  Hom := LEHom\n  id n := LEHom.mk (Nat.le_refl n)\n  comp := LEHom.comp\n\ndef isoOfEq {m n : Nat} (h : m = n) : m \u2245 n where\n  hom := LEHom.mk (Nat.le_of_eq h)\n  inv := LEHom.mk (Nat.le_of_eq h.symm)\n\ninstance instUnbiasedMonoidalNatWithLT : UnbiasedMonoidal Nat where\n  tensor := {obj := List.sum, map := LEHom.sum}\n  unitor := Iso.refl _\n  associator := {\n    hom := {app:=\u03bb nss => (isoOfEq (List.sum_join nss)).inv}\n    inv := {app:=\u03bb nss => (isoOfEq (List.sum_join nss)).hom}\n  }\n  coherence_unit_left := rfl\n  coherence_unit_right := rfl\n  coherence_assoc := rfl\n\n", "meta": {"author": "Junology", "repo": "Moncalc", "sha": "5c93c9eb907de01720e47397b5701754cc0e00c3", "save_path": "github-repos/lean/Junology-Moncalc", "path": "github-repos/lean/Junology-Moncalc/Moncalc-5c93c9eb907de01720e47397b5701754cc0e00c3/test/NatLE.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7020704279169506}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland\n-/\nimport algebra.ring.inj_surj\nimport algebra.group.units\n\n/-!\n# Units in semirings and rings\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {R : Type x}\n\nopen function\n\nnamespace units\n\nsection has_distrib_neg\nvariables [monoid \u03b1] [has_distrib_neg \u03b1] {a b : \u03b1}\n\n/-- Each element of the group of units of a ring has an additive inverse. -/\ninstance : has_neg \u03b1\u02e3 := \u27e8\u03bbu, \u27e8-\u2191u, -\u2191u\u207b\u00b9, by simp, by simp\u27e9 \u27e9\n\n/-- Representing an element of a ring's unit group as an element of the ring commutes with\n    mapping this element to its additive inverse. -/\n@[simp, norm_cast] protected theorem coe_neg (u : \u03b1\u02e3) : (\u2191-u : \u03b1) = -u := rfl\n\n@[simp, norm_cast] protected theorem coe_neg_one : ((-1 : \u03b1\u02e3) : \u03b1) = -1 := rfl\n\ninstance : has_distrib_neg \u03b1\u02e3 := units.ext.has_distrib_neg _ units.coe_neg units.coe_mul\n\n@[field_simps] lemma neg_divp (a : \u03b1) (u : \u03b1\u02e3) : -(a /\u209a u) = (-a) /\u209a u :=\nby simp only [divp, neg_mul]\n\nend has_distrib_neg\n\nsection ring\n\nvariables [ring \u03b1] {a b : \u03b1}\n\n@[field_simps] lemma divp_add_divp_same (a b : \u03b1) (u : \u03b1\u02e3) :\n  a /\u209a u + b /\u209a u = (a + b) /\u209a u :=\nby simp only [divp, add_mul]\n\n@[field_simps] lemma divp_sub_divp_same (a b : \u03b1) (u : \u03b1\u02e3) :\n  a /\u209a u - b /\u209a u = (a - b) /\u209a u :=\nby rw [sub_eq_add_neg, sub_eq_add_neg, neg_divp, divp_add_divp_same]\n\n@[field_simps] lemma add_divp (a b : \u03b1) (u : \u03b1\u02e3)  : a + b /\u209a u = (a * u + b) /\u209a u :=\nby simp only [divp, add_mul, units.mul_inv_cancel_right]\n\n@[field_simps] lemma sub_divp (a b : \u03b1) (u : \u03b1\u02e3) : a - b /\u209a u = (a * u - b) /\u209a u :=\nby simp only [divp, sub_mul, units.mul_inv_cancel_right]\n\n@[field_simps] lemma divp_add (a b : \u03b1) (u : \u03b1\u02e3) : a /\u209a u + b = (a + b * u) /\u209a u :=\nby simp only [divp, add_mul, units.mul_inv_cancel_right]\n\n@[field_simps] lemma divp_sub (a b : \u03b1) (u : \u03b1\u02e3) : a /\u209a u - b = (a - b * u) /\u209a u :=\nbegin\n  simp only [divp, sub_mul, sub_right_inj],\n  assoc_rw [units.mul_inv, mul_one],\nend\n\nend ring\n\nend units\n\nlemma is_unit.neg [monoid \u03b1] [has_distrib_neg \u03b1] {a : \u03b1} : is_unit a \u2192 is_unit (-a)\n| \u27e8x, hx\u27e9 := hx \u25b8 (-x).is_unit\n\n@[simp]\nlemma is_unit.neg_iff [monoid \u03b1] [has_distrib_neg \u03b1] (a : \u03b1) : is_unit (-a) \u2194 is_unit a :=\n\u27e8\u03bb h, neg_neg a \u25b8 h.neg, is_unit.neg\u27e9\n\nlemma is_unit.sub_iff [ring \u03b1] {x y : \u03b1} :\n  is_unit (x - y) \u2194 is_unit (y - x) :=\n(is_unit.neg_iff _).symm.trans $ neg_sub x y \u25b8 iff.rfl\n\nnamespace units\n\n@[field_simps] lemma divp_add_divp [comm_ring \u03b1] (a b : \u03b1) (u\u2081 u\u2082 : \u03b1\u02e3) :\na /\u209a u\u2081 + b /\u209a u\u2082 = (a * u\u2082 + u\u2081 * b) /\u209a (u\u2081 * u\u2082) :=\nbegin\n  simp only [divp, add_mul, mul_inv_rev, coe_mul],\n  rw [mul_comm (\u2191u\u2081 * b), mul_comm b],\n  assoc_rw [mul_inv, mul_inv, mul_one, mul_one],\nend\n\n@[field_simps] \n\nlemma add_eq_mul_one_add_div [semiring R] {a : R\u02e3} {b : R} : \u2191a + b = a * (1 + \u2191a\u207b\u00b9 * b) :=\nby rwa [mul_add, mul_one, \u2190 mul_assoc, units.mul_inv, one_mul]\n\nend units\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/ring/units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.7020704239010778}}
{"text": "/-\nA logic is a \"formal language\" that has\na mathematically defined syntax and a\nmathematically defined semantics. The\nsemantics in turn depends on an intended\n\"real-world interpretation\" of the basic\nsymbols in a given logical expression.\n\nConsider for example this proposition\n\u2200 p : Person, \u2203 m: Person, motherOf p m. \nWe could have written it in a logically\nequivalent form: \u2200 x : X, \u2203 m : X, r p m.\nThe benefit of the first version is that\nit *suggests* an intended interpretation.\nWe mean for p and m to represent people\n(any human beings), and we intend the\nmotherOf predicate to represent the real\nrelationship connecting people to moms.\n\nWe now drill down on the notions of the\nsyntax and semantics of a formal language.\nThe syntax of a language defines the set\nof valid expressions in the language. In\npredicate logic, for example, \u2200 p: Person,\n\u2203 m : Person, motherOf p m is well formed.\nHowever, the expression, \u2200 \u2203 r, is not.\n\nThe semantics of a language then assigns \na meaning of some kind to each expression\nin the language given an interpretation\nof the basic elements of an expression.\nWhen the formal language is a logic, the\nsyntax defines a language of propositions,\npredicates, etc., while a semantics tells\nus how to evaluate the truth of any such\nexpression.\n\nIn this unit we begin by formalizing the\nsyntax, interpretation, and semantics of\npropositional logic. Proposition logic is\na very simple logic, one that essentially\nmirrors (is \"isomorphic to\") the language\nof Boolean expressions.\n-/\n\n-- Syntax\n\n/-\nWe formalize the syntax of a language \nwith an inductive definition of the set\nof valid expressions.\n\nAn expression in propositional logic \nis built from a (1) a logical constant,\ntrue or false, (2) a propositional (you\ncan think \"Boolean\") variable, or (3) a\nlogical connective (and, or, not, etc)\nand one or more smaller expressions.\n-/\n\n/-\nTo formalize this idea, we need to \ndefine what we mean by a variable. \nWe do with with a new type, pVar,\nwhere each such variable holds a \u2115\nvalue that distinguishes it from any\nother propVar. \n-/\n\ninductive pVar : Type \n| mk : \u2115 \u2192 pVar\n\n-- Examples\n\ndef X := pVar.mk 0\ndef Y := pVar.mk 1\ndef Z := pVar.mk 2\ndef W := pVar.mk 3\n\n\ndef pVar_eq (v1 v2 : pVar) : bool :=\nmatch v1, v2 with\n    (pVar.mk m), (pVar.mk n) := m = n\nend      \n\n#reduce pVar_eq X X\n#reduce pVar_eq X Y\n\ndef Q := pVar.mk 0\n#reduce pVar_eq Q X\n\n/-\nNow we formalize a language of\nexpressions in propositional logic. \n-/\n\ninductive pExp : Type\n| mk_lit_pexp : bool \u2192 pExp\n| mk_var_pexp : pVar \u2192 pExp\n| mk_not_pexp : pExp \u2192 pExp\n| mk_and_pexp : pExp \u2192 pExp \u2192 pExp\n| mk_or_pexp  : pExp \u2192 pExp \u2192 pExp\n\nopen pExp\n\n-- Examples of expressions\n\ndef ff_exp := mk_lit_pexp ff\ndef tt_exp := mk_lit_pexp tt\n#reduce tt_exp\n\ndef X_exp := mk_var_pexp X\ndef Y_exp := mk_var_pexp Y\ndef Z_exp := mk_var_pexp Z\n#reduce Z_exp\n\ndef not_X_exp := mk_not_pexp X_exp\ndef and_X_Y_exp := mk_and_pexp X_exp Y_exp\ndef and_X_Z_exp := mk_and_pexp X_exp Z_exp\ndef or_X_Y_exp := mk_or_pexp X_exp Y_exp\n#reduce and_X_Z_exp\n\n-- syntactic sugar!\n\nnotation e1 \u2227 e2 :=  mk_and_pexp e1 e2\nnotation e1 \u2228 e2 := mk_or_pexp e1 e2\nnotation \u00ac e := mk_not_pexp e\n\ndef not_X_exp' := \u00ac X_exp\ndef and_X_Y_exp' := X_exp \u2227 Y_exp\ndef and_X_Z_exp' := X_exp \u2227 Z_exp\ndef or_X_Y_exp' := X_exp \u2228 Y_exp\n\n\ndef tf := mk_and_pexp (mk_lit_pexp tt) (mk_lit_pexp ff)\ndef nt := mk_not_pexp (mk_lit_pexp tt)\ndef nxy := mk_not_pexp (mk_and_pexp X_exp Y_exp)\n\n\n-- Semantics\n\n/-\nTo formalize a semantics for our\nrealization of propositional logic,\nwe need to formally define what we\nmean by an interpretation.\n\nAn interpretation in propositional \nlogic is a function from propositional\nvariables to corresponding (Boolean)\ntruth values. An interpretation tells\nus what each variable \"means\" -- i.e.,\nwhether it means true, or false. \n\nWe now define a name for the type\nof an interpretation (pVar \u2192 bool).\nThen we present several examples of\ninterpretations.\n-/\n\ndef pInterp := pVar \u2192 bool\n\n-- an \"all false\" interpretation\ndef falseInterp (v : pVar) : bool :=\n    ff\n\n-- an \"all true\" interpretation\ndef trueInterp (v : pVar) :=\n    tt\n\n-- X = tt, Y=ff, Z=tt, _ = ff\n\ndef anInterp: pInterp :=\n\u03bb(v: pVar),\n  match v with\n  | (pVar.mk 0) := tt     -- X\n  | (pVar.mk 1) := ff     -- Y\n  | (pVar.mk 2) := tt     -- Z\n  | _ := ff               -- otherwise\n  end\n\n-- Semantics\n\n/-\nWe now define a semantics for our\nlanguage in the form of a function\nthat, when given any expression in\nour language *and* an interpretation\nfor the variables that might appear\nin it, evaluates its truth value and\nreturns it as a result.\n\nThe definition is by cases, i.e., \nwith one rule for each possible form\n(constructor) of expression.\n\nNote: Lean \"overloads\" logical\noperator notations, such as \u2227, \u2228, \nand \u00ac. Here they are applied not to\nvalues of type Prop, but to values \nof type bool, where they have their\nusual means from Boolean algebra.\n-/\n\ndef pEval : pExp \u2192 pInterp \u2192 bool \n-- how to evaluate literal expression\n| (mk_lit_pexp b) i := b\n-- how to evaluate variable expression\n| (mk_var_pexp v) i := i v\n-- how to evaluate a \"not\" expression\n| (mk_not_pexp e) i := bnot (pEval e i)\n-- how to evaluate an \"and\" expression\n| (mk_and_pexp e1 e2) i := \n    band (pEval e1 i) (pEval e2 i)\n| (mk_or_pexp e1 e2) i :=\n    bor (pEval e1 i) (pEval e2 i)\n\n/-\nAnd now we have a formal language, with\na syntax, interpretations, and semantics.\nLet's evaluate some of our expressions\nunder varying interpretations.\n-/\n\n-- literal expressions\n\n#reduce pEval tt_exp falseInterp\n#reduce pEval tt_exp trueInterp\n#reduce pEval tt_exp anInterp\n\n#reduce pEval ff_exp falseInterp\n#reduce pEval ff_exp trueInterp\n#reduce pEval ff_exp anInterp\n\n-- variable expressions\n#reduce pEval X_exp falseInterp\n#reduce pEval X_exp trueInterp\n#reduce pEval X_exp anInterp\n\n#reduce pEval Y_exp falseInterp\n#reduce pEval Y_exp trueInterp\n#reduce pEval Y_exp anInterp\n\n#reduce pEval Z_exp falseInterp\n#reduce pEval Z_exp trueInterp\n#reduce pEval Z_exp anInterp\n\n#reduce pEval (mk_var_pexp W) falseInterp\n#reduce pEval (mk_var_pexp W) trueInterp\n#reduce pEval (mk_var_pexp W) anInterp\n\n-- We don't have to give variables names\n#reduce pEval (mk_var_pexp (pVar.mk 10)) anInterp\n\n-- not expression\n#reduce pEval not_X_exp falseInterp\n#reduce pEval not_X_exp trueInterp\n#reduce pEval not_X_exp anInterp\n\n-- and expressio\n#reduce pEval and_X_Z_exp falseInterp\n#reduce pEval and_X_Z_exp trueInterp\n#reduce pEval and_X_Z_exp anInterp\n\n#reduce pEval and_X_Z_exp' falseInterp\n#reduce pEval and_X_Z_exp' trueInterp\n#reduce pEval and_X_Z_exp' anInterp\n\n#reduce pEval and_X_Y_exp anInterp\n\n/-\nSo there you have it: a complete\nformal definition of the syntax,\ninterpretation, and semantics of\npropositional logic, in Lean, with\na nice \"surface syntax,\" to boot.\n(Ok, it's complete except for the\ndefinitions for the other logical\nconnectives. You will add some of\nthem in homework and on the exam.)\n-/\n\n/-\nFrom here, we can define richer\nfunctions, such as functions that\nanalyze expressions; and we can\neven state and prove theorems \nabout our language.\n-/\n\n/-\nA function that returns the set \nof variables in a given pExp.\n-/\n\n/-\nHelper function that adds variables\nin given expression to given set of\nvariables.\n-/\ndef vars_in_exp_helper: \n    pExp \u2192 set pVar \u2192 set pVar\n| (mk_lit_pexp _) s := s\n| (mk_var_pexp v) s := s \u222a { v }\n| (mk_not_pexp e) s := \n    s \u222a (vars_in_exp_helper e s)\n| (mk_and_pexp e1 e2) s := \n    s \u222a \n    (vars_in_exp_helper e1 s) \u222a \n    (vars_in_exp_helper e2 s)\n| (mk_or_pexp e1 e2) s := \n    s \u222a \n    (vars_in_exp_helper e1 s) \u222a \n    (vars_in_exp_helper e2 s)\n\n/-\nMain function: add variables in given\nexpression to initially empty set and\nreturn result.\n-/\ndef vars_in_exp (e: pExp) : set pVar :=\n    vars_in_exp_helper e ({}: set pVar)\n\n#reduce vars_in_exp and_X_Y_exp\n#reduce vars_in_exp and_X_Z_exp\n\n/-\nEXERCISE: Write a function that when\ngiven an expression, e, returns the \n\"nesting depth\" of the expression. The\nnesting depth of a literal or variable\nexpression is 1. The depth of a (not e) \nexpression is 1 + the depth of e. And\nthe depth of an (and e1 e2) expression\nis 1 + the max of the depths of e1 and\ne2. You can use the Lean-provided max function in your answer.\n-/\n\n#reduce max 5 7\n#reduce max 7 5\n\n/-\nWe can also prove theorems about\nour language in general. Here's a\nproof that evaluation under a given\ninterpretation is deterministic. It\nalways produces the same result.\nThis is really just a corollary of\nthe fact that functions in Lean are\nsingle valued and we've defined the\nsemantics of expressions with a\nfunction.\n-/\n\ntheorem pEval_deterministic :\n\u2200 e : pExp, \n\u2200 i : pInterp,\n\u2200 v1 v2 : bool,\nv1 = pEval e i \u2192 v2 = pEval e i \u2192 v1 = v2 :=\nbegin\nintros e i v1 v2 h_v1 h_v2,\nrw h_v1, \nrw h_v2,\nend\n\n/-\nWe can also prove theorems about\nparticular expressions in our language.\nFor example, if X_exp is some variable\nexpression, then the expression \nX_exp \u2227 (\u00ac X_exp) is false under *any*\ninterpretation.\n-/\n\ntheorem contra :\n\u2200 V : pVar,\n\u2200 i : pInterp,\npEval \n    ((mk_var_pexp V) \u2227 \u00ac (mk_var_pexp V)) i = ff \n:=\nbegin\nintros X i,\nsimp [pEval],\n-- case analysis on result of function!\ncases (i X),\nleft, apply rfl,\nright, apply rfl,\nend\n\n/-\nEXERCISE: extend the syntax, surface\nsyntax, and semantics of the language\nwith an \"or\" operator. Use \u2228 as surface\nsyntax.\n-/\n\n/-\nExercise: now prove that for any \nvariable, V, the logical expression\n(mk_var_exp V) \u2228 (\u00ac (mk_var_exp V))\nalways evaluates to true.\n-/", "meta": {"author": "tcmch", "repo": "cs-dm-lean", "sha": "16ef75c7e68077e265441acc16cf5fe643db911b", "save_path": "github-repos/lean/tcmch-cs-dm-lean", "path": "github-repos/lean/tcmch-cs-dm-lean/cs-dm-lean-16ef75c7e68077e265441acc16cf5fe643db911b/src/15_Formal_Languages/00_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.702035939512625}}
{"text": "import data.real.basic\nimport data.nat.prime\n\n/- Structures and classes.\n\nCorresponding LFTCM lectures:\n* https://www.youtube.com/watch?v=xYenPIeX6MY\n* https://www.youtube.com/watch?v=1W_fyjaaY0M\n-/\n\n\n\n/- The `structure` command introduces a new type (or proposition)\nwhich is built up from existing types.\nLet's start with a basic example of a structure. -/\n\nstructure complex : Type :=\n(re : \u211d)\n(im : \u211d)\n\n\n\n\n\n\nvariables (w : complex)\n\n/- Field projections. -/\n#check w.re\n#check w.im\n\n/- The \"dot notation\" above is short for: -/\n#check complex.re w\n#check complex.im w\n\n\n\n/- Constructing values. These four lines below are exactly equivalent.\nBy default, the constructor of a structure is named `mk`. -/\n#check complex.mk 1 2\n#check (\u27e81, 2\u27e9 : complex)\n#check ({ re := 1, im := 2 } : complex)\n#check { complex . re := 1, im := 2 }\n\n/-\n`{ re := ..., im := ... }` is \"record constructor syntax\"\nand \u27e8..., ...\u27e9 is \"anonymous constructor syntax.\nWhen the expected type is known, we can omit it from the notation.\n-/\n\n#check (show complex, from \u27e81, 2\u27e9)\n#check (show complex, from { re := 1, im := 2 })\n\n\n\n\n\n\n\n\n/- The \"dot notation\" is not specific to fields of structures;\nit works with any qualified name (= name in a namespace).\nIf the type of `x` is of the form `T a1 ... an`,\nthen `x.y` is interpreted as `T.y x`. -/\n\nvariables (n : nat)\n#check nat.prime n\n#check n.prime\n\n\n\n\n\n\n/- Let's add a complex conjugation function,\nand prove that taking the conjugate twice is the identity. -/\n\ndef complex.conj (z : complex) : complex :=\n{ re := z.re, im := - z.im }    -- or \u27e8z.re, - z.im\u27e9\n\nlemma complex.conj_conj (z : complex) : z.conj.conj = z :=\nbegin\n  sorry\nend\n\n\n\n\n/-\nAbove, we manipulated the equation `z.conj.conj = z` into a form\nequating two record constructor applications.\nAnother strategy is to reason about the two components separately.\nFor this we use an \"extensionality\" lemma:\ntwo complex numbers are equal if they are built from the same components.\nWe can automatically derive this lemma using the `ext` attribute.\n-/\n\n\nattribute [ext] complex    -- or add `@[ext]` before `structure complex`\n\n#check @complex.ext\n\n\n/-\nThis strategy pairs well with lemmas which describe the components of `z.conj`.\n(These can also be automatically generated using the `simps` attribute.)\n-/\n\nlemma complex.conj_re (z : complex) : z.conj.re = z.re := rfl\nlemma complex.conj_im (z : complex) : z.conj.im = - z.im := rfl\n\n\nexample (z : complex) : z.conj.conj = z :=\nbegin\n  sorry\nend\n\n\n\n\n\n/- Let's now look at some more interesting examples of structures. -/\n\nstructure Prime : Type :=\n(val : \u2115)\n(is_prime : nat.prime val)\n\n/-\n`Prime` is a type whose values correspond to the prime numbers.\nA value of type `Prime` is a natural number `val`\ntogether with a \"proof\" that the number `val` is prime;\nor in more ordinary language, a natural number `val` such that `val` is prime.\n\nCombining data and properties like this is sometimes called \"bundling\".\nFor example, we could call an argument `(p : Prime)` a \"bundled prime number\"\nto distinguish it from two arguments `(p : \u2115) (hp : nat.prime p)`.\n(In general \"bundling\" is a relative notion, and there might be\nmore than two possible levels of bundled-ness.)\n-/\n\nvariables (p : Prime)\n\n#check p.val\n#check p.is_prime\n\n/-\nIn order to construct a value of type `Prime`,\nwe have to provide a proof of primality.\n-/\n#check show Prime, from \u27e85, by norm_num\u27e9\n\n\n\n\n/-\nThis example generalizes to any type and predicate on that type (or subset of that type).\n-/\n\n#check @subtype\n\ndef Prime2 : Type := { p : \u2115 // p.prime }    -- or `subtype nat.prime`\n\n-- compare:\ndef primes : set \u2115 := { p : \u2115 | p.prime }\n\n\nvariables (q : Prime2)\n\n#check q.val\n#check q.property\n\n\n\n\n/- Other basic structures: -/\n#check and\n\n#check @prod\n\n\n\n\n\n\n/-\nAnother important kind of \"data with properties\" are algebraic structures.\n-/\n\nstructure monoid_structure (\u03b1 : Type) : Type :=\n(one : \u03b1)\n(mul : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(mul_one : \u2200 x, mul x one = x)\n(one_mul : \u2200 x, mul one x = x)\n(mul_assoc : \u2200 x y z, mul (mul x y) z = mul x (mul y z))\n\n\n\ndef nat_mul_monoid : monoid_structure \u2115 :=\nsorry\n\n\ndef int_mul_monoid : monoid_structure \u2124 :=\nsorry\n\n\n\n\n#eval nat_mul_monoid.mul 2 3\n\n#eval int_mul_monoid.mul (-1) 5\n\n\n\n\n\n/-\nRecall that the dot notation is another way to write:\n-/\n\n#eval monoid_structure.mul nat_mul_monoid 2 3\n\n#eval monoid_structure.mul int_mul_monoid (-1) 5\n\n\n\n\nnamespace monoid_structure\n\n/- Example function defined in terms of a `monoid_structure`:\npower x^n of an element x of a monoid. -/\ndef pow {\u03b1 : Type} (m : monoid_structure \u03b1) (x : \u03b1) : \u2115 \u2192 \u03b1\n| 0 := m.one\n| (n+1) := m.mul (pow n) x\n\n#eval nat_mul_monoid.pow 2 5\n\n-- a^(m+n) = a^m * a^n\nlemma pow_add {\u03b1 : Type} (M : monoid_structure \u03b1) (a : \u03b1) (m n : \u2115) :\n  M.pow a (m + n) = M.mul (M.pow a m) (M.pow a n) :=\nbegin\n  induction n with n IH,\n  { symmetry,\n    apply M.mul_one },\n  { calc M.pow a (m + (n + 1))\n        = M.pow a ((m + n) + 1)                   : rfl\n    ... = M.mul (M.pow a (m + n)) a               : rfl\n    ... = M.mul (M.mul (M.pow a m) (M.pow a n)) a : by rw IH\n    ... = M.mul (M.pow a m) (M.mul (M.pow a n) a) : by rw M.mul_assoc\n    ... = M.mul (M.pow a m) (M.pow a (n+1))       : rfl }\nend\n\nend monoid_structure            -- end namespace\n\n\n\n\n-- To use this lemma, we need to pass the `monoid_structure` explicitly.\n#check nat_mul_monoid.pow_add 2 3 5\n\n\n\n\n\n\n/-\nWe would like Lean to automatically know\nto use `nat_mul_monoid` when it needs a `monoid_structure \u2115`,\nand `int_mul_monoid` when it needs a `monoid_structure \u2124`.\nThis is what the type class system is for.\nLean maintains a database of \"instances\" for each \"type class\",\nand it searches this database when it needs to infer\nan argument which is passed in square brackets.\n-/\n\n/- `class` is the same as `structure`,\nexcept it also makes the structure a type class. -/\nclass my_monoid (\u03b1 : Type) : Type :=\n(one : \u03b1)\n(mul : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\n(mul_one : \u2200 x, mul x one = x)\n(one_mul : \u2200 x, mul one x = x)\n(mul_assoc : \u2200 x y z, mul (mul x y) z = mul x (mul y z))\n\n/- Register instances with the type class system\nso they are available to instance search. -/\ninstance : my_monoid \u2115 :=\n{ one := 1,\n  mul := nat.mul,\n  mul_one := nat.mul_one,\n  one_mul := nat.one_mul,\n  mul_assoc := nat.mul_assoc }\n\ninstance : my_monoid \u2124 :=\n{ one := 1,\n  mul := int.mul,\n  mul_one := int.mul_one,\n  one_mul := int.one_mul,\n  mul_assoc := int.mul_assoc }\n\n\n/- The monoid structure is now an argument passed in square brackets. -/\n#check @monoid_structure.mul\n\n#check @my_monoid.mul\n\n\n/- This means we don't write the argument explicitly.\nInstead, Lean will search its database for a matching instance. -/\n#eval my_monoid.mul 2 3\n#eval my_monoid.mul (-1 : \u2124) 5\n\n\n\n\nnamespace my_monoid\n\n/- Square brackets tell Lean that the argument will be supplied by instance search.\nIt is then also available for other functions, like `mul`. -/\ndef pow {\u03b1 : Type} [my_monoid \u03b1] (x : \u03b1) : \u2115 \u2192 \u03b1\n| 0 := one\n| (n+1) := mul (pow n) x\n\n\n/- Same as original `pow_add`, but now all explicit references\nto the monoid structure are gone. -/\nlemma pow_add {\u03b1 : Type} [my_monoid \u03b1] (a : \u03b1) (m n : \u2115) :\n  pow a (m + n) = mul (pow a m) (pow a n) :=\nbegin\n  induction n with n IH,\n  { symmetry,\n    apply mul_one },\n  { calc pow a (m + (n + 1))\n        = pow a ((m + n) + 1)             : rfl\n    ... = mul (pow a (m + n)) a           : rfl\n    ... = mul (mul (pow a m) (pow a n)) a : by rw IH\n    ... = mul (pow a m) (mul (pow a n) a) : by rw mul_assoc\n    ... = mul (pow a m) (pow a (n+1))     : rfl }\nend\n\nend my_monoid                   -- end namespace\n\n\n\n\n-- No longer need to explicitly pass the monoid structure.\n#check my_monoid.pow_add 2 3 5\n\n\n-- By adding notation, we could get a type like the actual lemma `pow_add`.\n#check @my_monoid.pow_add\n\n#check @pow_add\n\n\n\n\n/-\nExercises:\nLFTCM exercises (https://leanprover-community.github.io/lftcm2020/exercises.html)\nfile `wednesday/structures.lean`.\nI especially recommend solving Exercises 1 and 2 from that file\nand checking your answers with one of the instructors.\n-/\n", "meta": {"author": "fpvandoorn", "repo": "Harvard-tutoring", "sha": "a8846c08e32cdc7b91a7e28adfa5d9b2810088b0", "save_path": "github-repos/lean/fpvandoorn-Harvard-tutoring", "path": "github-repos/lean/fpvandoorn-Harvard-tutoring/Harvard-tutoring-a8846c08e32cdc7b91a7e28adfa5d9b2810088b0/src/meetings/structures_classes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7020359280663513}}
{"text": "/-\nCopyright (c) 2022 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n-/\nimport dynamics.ergodic.add_circle\nimport measure_theory.covering.liminf_limsup\nimport data.nat.totient\n\n/-!\n# Well-approximable numbers and Gallagher's ergodic theorem\n\nGallagher's ergodic theorem is a result in metric number theory. It thus belongs to that branch of\nmathematics concerning arithmetic properties of real numbers which hold almost eveywhere with\nrespect to the Lebesgue measure.\n\nGallagher's theorem concerns the approximation of real numbers by rational numbers. The input is a\nsequence of distances `\u03b4\u2081, \u03b4\u2082, ...`, and the theorem concerns the set of real numbers `x` for which\nthere is an infinity of solutions to:\n$$\n  |x - m/n| < \u03b4\u2099,\n$$\nwhere the rational number `m/n` is in lowest terms. The result is that for any `\u03b4`, this set is\neither almost all `x` or almost no `x`.\n\nThis result was proved by Gallagher in 1959\n[P. Gallagher, *Approximation by reduced fractions*](Gallagher1961). It is formalised here as\n`add_circle.add_well_approximable_ae_empty_or_univ` except with `x` belonging to the circle `\u211d \u29f8 \u2124`\nsince this turns out to be more natural.\n\nGiven a particular `\u03b4`, the Duffin-Schaeffer conjecture (now a theorem) gives a criterion for\ndeciding which of the two cases in the conclusion of Gallagher's theorem actually occurs. It was\nproved by Koukoulopoulos and Maynard in 2019\n[D. Koukoulopoulos, J. Maynard, *On the Duffin-Schaeffer conjecture*](KoukoulopoulosMaynard2020).\nWe do *not* include a formalisation of the Koukoulopoulos-Maynard result here.\n\n## Main definitions and results:\n\n * `approx_order_of`: in a seminormed group `A`, given `n : \u2115` and `\u03b4 : \u211d`, `approx_order_of A n \u03b4`\n   is the set of elements within a distance `\u03b4` of a point of order `n`.\n * `well_approximable`: in a seminormed group `A`, given a sequence of distances `\u03b4\u2081, \u03b4\u2082, ...`,\n   `well_approximable A \u03b4` is the limsup as `n \u2192 \u221e` of the sets `approx_order_of A n \u03b4\u2099`. Thus, it\n   is the set of points that lie in infinitely many of the sets `approx_order_of A n \u03b4\u2099`.\n * `add_circle.add_well_approximable_ae_empty_or_univ`: *Gallagher's ergodic theorem* says that for\n   for the (additive) circle `\ud835\udd4a`, for any sequence of distances `\u03b4`, the set\n   `add_well_approximable \ud835\udd4a \u03b4` is almost empty or almost full.\n\n## TODO:\n\nThe hypothesis `h\u03b4` in `add_circle.add_well_approximable_ae_empty_or_univ` can be dropped.\nAn elementary (non-measure-theoretic) argument shows that if `\u00ac h\u03b4` holds then\n`add_well_approximable \ud835\udd4a \u03b4 = univ` (provided `\u03b4` is non-negative).\n-/\n\nopen set filter function metric measure_theory\nopen_locale measure_theory topology pointwise\n\n/-- In a seminormed group `A`, given `n : \u2115` and `\u03b4 : \u211d`, `approx_order_of A n \u03b4` is the set of\nelements within a distance `\u03b4` of a point of order `n`. -/\n@[to_additive approx_add_order_of \"In a seminormed additive group `A`, given `n : \u2115` and `\u03b4 : \u211d`,\n`approx_add_order_of A n \u03b4` is the set of elements within a distance `\u03b4` of a point of order `n`.\"]\ndef approx_order_of (A : Type*) [seminormed_group A] (n : \u2115) (\u03b4 : \u211d) : set A :=\nthickening \u03b4 {y | order_of y = n}\n\n@[to_additive mem_approx_add_order_of_iff]\nlemma mem_approx_order_of_iff {A : Type*} [seminormed_group A] {n : \u2115} {\u03b4 : \u211d} {a : A} :\n  a \u2208 approx_order_of A n \u03b4 \u2194 \u2203 (b : A), order_of b = n \u2227 a \u2208 ball b \u03b4 :=\nby simp only [approx_order_of, thickening_eq_bUnion_ball, mem_Union\u2082, mem_set_of_eq, exists_prop]\n\n/-- In a seminormed group `A`, given a sequence of distances `\u03b4\u2081, \u03b4\u2082, ...`, `well_approximable A \u03b4`\nis the limsup as `n \u2192 \u221e` of the sets `approx_order_of A n \u03b4\u2099`. Thus, it is the set of points that\nlie in infinitely many of the sets `approx_order_of A n \u03b4\u2099`. -/\n@[to_additive add_well_approximable \"In a seminormed additive group `A`, given a sequence of\ndistances `\u03b4\u2081, \u03b4\u2082, ...`, `add_well_approximable A \u03b4` is the limsup as `n \u2192 \u221e` of the sets\n`approx_add_order_of A n \u03b4\u2099`. Thus, it is the set of points that lie in infinitely many of the sets\n`approx_add_order_of A n \u03b4\u2099`.\"]\ndef well_approximable (A : Type*) [seminormed_group A] (\u03b4 : \u2115 \u2192 \u211d) : set A :=\nblimsup (\u03bb n, approx_order_of A n (\u03b4 n)) at_top (\u03bb n, 0 < n)\n\n@[to_additive mem_add_well_approximable_iff]\nlemma mem_well_approximable_iff {A : Type*} [seminormed_group A] {\u03b4 : \u2115 \u2192 \u211d} {a : A} :\n  a \u2208 well_approximable A \u03b4 \u2194 a \u2208 blimsup (\u03bb n, approx_order_of A n (\u03b4 n)) at_top (\u03bb n, 0 < n) :=\niff.rfl\n\nnamespace approx_order_of\n\nvariables {A : Type*} [seminormed_comm_group A] {a : A} {m n : \u2115} (\u03b4 : \u211d)\n\n@[to_additive]\nlemma image_pow_subset_of_coprime (hm : 0 < m) (hmn : n.coprime m) :\n  (\u03bb y, y^m) '' (approx_order_of A n \u03b4) \u2286 approx_order_of A n (m * \u03b4) :=\nbegin\n  rintros - \u27e8a, ha, rfl\u27e9,\n  obtain \u27e8b, hb, hab\u27e9 := mem_approx_order_of_iff.mp ha,\n  replace hb : b^m \u2208 {u : A | order_of u = n}, { rw \u2190 hb at hmn \u22a2, exact order_of_pow_coprime hmn },\n  apply ball_subset_thickening hb ((m : \u211d) \u2022 \u03b4),\n  convert pow_mem_ball hm hab using 1,\n  simp only [nsmul_eq_mul, algebra.id.smul_eq_mul],\nend\n\n@[to_additive]\nlemma image_pow_subset (n : \u2115) (hm : 0 < m) :\n  (\u03bb y, y^m) '' (approx_order_of A (n * m) \u03b4) \u2286 approx_order_of A n (m * \u03b4) :=\nbegin\n  rintros - \u27e8a, ha, rfl\u27e9,\n  obtain \u27e8b, hb : order_of b = n * m, hab : a \u2208 ball b \u03b4\u27e9 := mem_approx_order_of_iff.mp ha,\n  replace hb : b^m \u2208 {y : A | order_of y = n},\n  { rw [mem_set_of_eq, order_of_pow' b hm.ne', hb, nat.gcd_mul_left_left, n.mul_div_cancel hm], },\n  apply ball_subset_thickening hb (m * \u03b4),\n  convert pow_mem_ball hm hab,\n  simp only [nsmul_eq_mul],\nend\n\n@[to_additive]\nlemma smul_subset_of_coprime (han : (order_of a).coprime n) :\n  a \u2022 approx_order_of A n \u03b4 \u2286 approx_order_of A ((order_of a) * n) \u03b4 :=\nbegin\n  simp_rw [approx_order_of, thickening_eq_bUnion_ball, \u2190 image_smul, image_Union\u2082,\n    image_smul, smul_ball'', smul_eq_mul, mem_set_of_eq],\n  refine Union\u2082_subset_iff.mpr (\u03bb b hb c hc, _),\n  simp only [mem_Union, exists_prop],\n  refine \u27e8a * b, _, hc\u27e9,\n  rw \u2190 hb at \u22a2 han,\n  exact (commute.all a b).order_of_mul_eq_mul_order_of_of_coprime han,\nend\n\n@[to_additive vadd_eq_of_mul_dvd]\nlemma smul_eq_of_mul_dvd (hn : 0 < n) (han : (order_of a)^2 \u2223 n) :\n  a \u2022 approx_order_of A n \u03b4 = approx_order_of A n \u03b4 :=\nbegin\n  simp_rw [approx_order_of, thickening_eq_bUnion_ball, \u2190 image_smul, image_Union\u2082,\n    image_smul, smul_ball'', smul_eq_mul, mem_set_of_eq],\n  replace han : \u2200 {b : A}, order_of b = n \u2192 order_of (a * b) = n,\n  { intros b hb,\n    rw \u2190 hb at han hn,\n    rw sq at han,\n    rwa [(commute.all a b).order_of_mul_eq_right_of_forall_prime_mul_dvd (order_of_pos_iff.mp hn)\n      (\u03bb p hp hp', dvd_trans (mul_dvd_mul_right hp' $ order_of a) han)], },\n  let f : {b : A | order_of b = n} \u2192 {b : A | order_of b = n} := \u03bb b, \u27e8a * b, han b.property\u27e9,\n  have hf : surjective f,\n  { rintros \u27e8b, hb\u27e9,\n    refine \u27e8\u27e8a\u207b\u00b9 * b, _\u27e9, _\u27e9,\n    { rw [mem_set_of_eq, \u2190 order_of_inv, mul_inv_rev, inv_inv, mul_comm],\n      apply han,\n      simpa, },\n    { simp only [subtype.mk_eq_mk, subtype.coe_mk, mul_inv_cancel_left], }, },\n  simpa only [f, mem_set_of_eq, subtype.coe_mk, Union_coe_set] using\n    hf.Union_comp (\u03bb b, ball (b : A) \u03b4),\nend\n\nend approx_order_of\n\nnamespace unit_add_circle\n\nlemma mem_approx_add_order_of_iff {\u03b4 : \u211d} {x : unit_add_circle} {n : \u2115} (hn : 0 < n) :\n  x \u2208 approx_add_order_of unit_add_circle n \u03b4 \u2194\n  \u2203 m < n, gcd m n = 1 \u2227 \u2016x - \u2191((m : \u211d) / n)\u2016 < \u03b4 :=\nbegin\n  haveI := real.fact_zero_lt_one,\n  simp only [mem_approx_add_order_of_iff, mem_set_of_eq, ball, exists_prop, dist_eq_norm,\n    add_circle.add_order_of_eq_pos_iff hn, mul_one],\n  split,\n  { rintros \u27e8y, \u27e8m, hm\u2081, hm\u2082, rfl\u27e9, hx\u27e9, exact \u27e8m, hm\u2081, hm\u2082, hx\u27e9, },\n  { rintros \u27e8m, hm\u2081, hm\u2082, hx\u27e9, exact \u27e8\u2191((m : \u211d) / n), \u27e8m, hm\u2081, hm\u2082, rfl\u27e9, hx\u27e9, },\nend\n\nlemma mem_add_well_approximable_iff (\u03b4 : \u2115 \u2192 \u211d) (x : unit_add_circle) :\n  x \u2208 add_well_approximable unit_add_circle \u03b4 \u2194\n  {n : \u2115 | \u2203 m < n, gcd m n = 1 \u2227 \u2016x - \u2191((m : \u211d) / n)\u2016 < \u03b4 n}.infinite :=\nbegin\n  simp only [mem_add_well_approximable_iff, \u2190 nat.cofinite_eq_at_top, cofinite.blimsup_set_eq,\n    mem_set_of_eq],\n  refine iff_of_eq (congr_arg set.infinite $ ext (\u03bb n, \u27e8\u03bb hn, _, \u03bb hn, _\u27e9)),\n  { exact (mem_approx_add_order_of_iff hn.1).mp hn.2, },\n  { have h : 0 < n := by { obtain \u27e8m, hm\u2081, hm\u2082, hm\u2083\u27e9 := hn, exact pos_of_gt hm\u2081, },\n    exact \u27e8h, (mem_approx_add_order_of_iff h).mpr hn\u27e9, },\nend\n\nend unit_add_circle\n\nnamespace add_circle\n\nvariables {T : \u211d} [hT : fact (0 < T)]\ninclude hT\n\nlocal notation a `\u2224` b := \u00ac a \u2223 b\nlocal notation a `\u2223\u2223` b := (a \u2223 b) \u2227 (a*a \u2224 b)\nlocal notation `\ud835\udd4a` := add_circle T\n\n/-- *Gallagher's ergodic theorem* on Diophantine approximation. -/\ntheorem add_well_approximable_ae_empty_or_univ (\u03b4 : \u2115 \u2192 \u211d) (h\u03b4 : tendsto \u03b4 at_top (\ud835\udcdd 0)) :\n  (\u2200\u1d50 x, \u00ac add_well_approximable \ud835\udd4a \u03b4 x) \u2228 \u2200\u1d50 x, add_well_approximable \ud835\udd4a \u03b4 x :=\nbegin\n  /- Sketch of proof:\n\n  Let `E := add_well_approximable \ud835\udd4a \u03b4`. For each prime `p : \u2115`, we can partition `E` into three\n  pieces `E = (A p) \u222a (B p) \u222a (C p)` where:\n    `A p = blimsup (approx_add_order_of \ud835\udd4a n (\u03b4 n)) at_top (\u03bb n, 0 < n \u2227 (p \u2224 n))`\n    `B p = blimsup (approx_add_order_of \ud835\udd4a n (\u03b4 n)) at_top (\u03bb n, 0 < n \u2227 (p \u2223\u2223 n))`\n    `C p = blimsup (approx_add_order_of \ud835\udd4a n (\u03b4 n)) at_top (\u03bb n, 0 < n \u2227 (p*p \u2223 n))`.\n  (In other words, `A p` is the set of points `x` for which there exist infinitely-many `n` such\n  that `x` is within a distance `\u03b4 n` of a point of order `n` and `p \u2224 n`. Similarly for `B`, `C`.)\n\n  These sets have the following key properties:\n    1. `A p` is almost invariant under the ergodic map `y \u21a6 p \u2022 y`\n    2. `B p` is almost invariant under the ergodic map `y \u21a6 p \u2022 y + 1/p`\n    3. `C p` is invariant under the map `y \u21a6 y + 1/p`\n  To prove 1 and 2 we need the key result `blimsup_thickening_mul_ae_eq` but 3 is elementary.\n\n  It follows from `add_circle.ergodic_nsmul_add` and `ergodic.ae_empty_or_univ_of_image_ae_le` that\n  if either `A p` or `B p` is not almost empty for any `p`, then it is almost full and thus so is\n  `E`. We may therefore assume that both `A p` and `B p` are almost empty for all `p`. We thus have\n  `E` is almost equal to `C p` for every prime. Combining this with 3 we find that `E` is almost\n  invariant under the map `y \u21a6 y + 1/p` for every prime `p`. The required result then follows from\n  `add_circle.ae_empty_or_univ_of_forall_vadd_ae_eq_self`. -/\n  letI : semilattice_sup nat.primes := nat.subtype.semilattice_sup _,\n  set \u03bc : measure \ud835\udd4a := volume,\n  set u : nat.primes \u2192 \ud835\udd4a := \u03bb p, \u2191(((\u2191(1 : \u2115) : \u211d) / p) * T),\n  have hu\u2080 : \u2200 (p : nat.primes), add_order_of (u p) = (p : \u2115),\n  { rintros \u27e8p, hp\u27e9, exact add_order_of_div_of_gcd_eq_one hp.pos (gcd_one_left p), },\n  have hu : tendsto (add_order_of \u2218 u) at_top at_top,\n  { rw (funext hu\u2080 : add_order_of \u2218 u = coe),\n    have h_mono : monotone (coe : nat.primes \u2192 \u2115) := \u03bb p q hpq, hpq,\n    refine h_mono.tendsto_at_top_at_top (\u03bb n, _),\n    obtain \u27e8p, hp, hp'\u27e9 := n.exists_infinite_primes,\n    exact \u27e8\u27e8p, hp'\u27e9, hp\u27e9, },\n  set E := add_well_approximable \ud835\udd4a \u03b4,\n  set X : \u2115 \u2192 set \ud835\udd4a := \u03bb n, approx_add_order_of \ud835\udd4a n (\u03b4 n),\n  set A : \u2115 \u2192 set \ud835\udd4a := \u03bb p, blimsup X at_top (\u03bb n, 0 < n \u2227 (p \u2224 n)),\n  set B : \u2115 \u2192 set \ud835\udd4a := \u03bb p, blimsup X at_top (\u03bb n, 0 < n \u2227 (p \u2223\u2223 n)),\n  set C : \u2115 \u2192 set \ud835\udd4a := \u03bb p, blimsup X at_top (\u03bb n, 0 < n \u2227 (p^2 \u2223 n)),\n  have hA\u2080 : \u2200 p, measurable_set (A p) :=\n    \u03bb p, measurable_set.measurable_set_blimsup (\u03bb n hn, is_open_thickening.measurable_set),\n  have hB\u2080 : \u2200 p, measurable_set (B p) :=\n    \u03bb p, measurable_set.measurable_set_blimsup (\u03bb n hn, is_open_thickening.measurable_set),\n  have hE\u2080 : null_measurable_set E \u03bc,\n  { refine (measurable_set.measurable_set_blimsup\n      (\u03bb n hn, is_open.measurable_set _)).null_measurable_set,\n    exact is_open_thickening, },\n  have hE\u2081 : \u2200 p, E = (A p) \u222a (B p) \u222a (C p),\n  { intros p,\n    simp only [E, add_well_approximable, \u2190 blimsup_or_eq_sup, \u2190 and_or_distrib_left, \u2190 sup_eq_union,\n      sq],\n    congr,\n    refine funext (\u03bb n, propext $ iff_self_and.mpr (\u03bb hn, _)),\n    -- `tauto` can finish from here but unfortunately it's very slow.\n    simp only [(em (p \u2223 n)).symm, (em (p*p \u2223 n)).symm, or_and_distrib_left, or_true, true_and,\n      or_assoc], },\n  have hE\u2082 : \u2200 (p : nat.primes), A p =\u1d50[\u03bc] (\u2205 : set \ud835\udd4a) \u2227 B p =\u1d50[\u03bc] (\u2205 : set \ud835\udd4a) \u2192 E =\u1d50[\u03bc] C p,\n  { rintros p \u27e8hA, hB\u27e9,\n    rw hE\u2081 p,\n    exact union_ae_eq_right_of_ae_eq_empty ((union_ae_eq_right_of_ae_eq_empty hA).trans hB), },\n  have hA : \u2200 (p : nat.primes), A p =\u1d50[\u03bc] (\u2205 : set \ud835\udd4a) \u2228 A p =\u1d50[\u03bc] univ,\n  { rintros \u27e8p, hp\u27e9,\n    let f : \ud835\udd4a \u2192 \ud835\udd4a := \u03bb y, (p : \u2115) \u2022 y,\n    suffices : f '' (A p) \u2286\n      blimsup (\u03bb n, approx_add_order_of \ud835\udd4a n (p * \u03b4 n)) at_top (\u03bb n, 0 < n \u2227 (p \u2224 n)),\n    { apply (ergodic_nsmul hp.one_lt).ae_empty_or_univ_of_image_ae_le (hA\u2080 p),\n      apply (has_subset.subset.eventually_le this).congr eventually_eq.rfl,\n      exact blimsup_thickening_mul_ae_eq \u03bc\n        (\u03bb n, 0 < n \u2227 (p \u2224 n)) (\u03bb n, {y | add_order_of y = n}) (nat.cast_pos.mpr hp.pos) _ h\u03b4, },\n    refine (Sup_hom.set_image f).apply_blimsup_le.trans (mono_blimsup $ \u03bb n hn, _),\n    replace hn := nat.coprime_comm.mp (hp.coprime_iff_not_dvd.2 hn.2),\n    exact approx_add_order_of.image_nsmul_subset_of_coprime (\u03b4 n) hp.pos hn, },\n  have hB : \u2200 (p : nat.primes), B p =\u1d50[\u03bc] (\u2205 : set \ud835\udd4a) \u2228 B p =\u1d50[\u03bc] univ,\n  { rintros \u27e8p, hp\u27e9,\n    let x := u \u27e8p, hp\u27e9,\n    let f : \ud835\udd4a \u2192 \ud835\udd4a := \u03bb y, p \u2022 y + x,\n    suffices : f '' (B p) \u2286\n      blimsup (\u03bb n, approx_add_order_of \ud835\udd4a n (p * \u03b4 n)) at_top (\u03bb n, 0 < n \u2227 (p \u2223\u2223 n)),\n    { apply (ergodic_nsmul_add x hp.one_lt).ae_empty_or_univ_of_image_ae_le (hB\u2080 p),\n      apply (has_subset.subset.eventually_le this).congr eventually_eq.rfl,\n      exact blimsup_thickening_mul_ae_eq \u03bc\n        (\u03bb n, 0 < n \u2227 (p \u2223\u2223 n)) (\u03bb n, {y | add_order_of y = n}) (nat.cast_pos.mpr hp.pos) _ h\u03b4, },\n    refine (Sup_hom.set_image f).apply_blimsup_le.trans (mono_blimsup _),\n    rintros n \u27e8hn, h_div, h_ndiv\u27e9,\n    have h_cop : (add_order_of x).coprime (n/p),\n    { obtain \u27e8q, rfl\u27e9 := h_div,\n      rw [hu\u2080, subtype.coe_mk, hp.coprime_iff_not_dvd, q.mul_div_cancel_left hp.pos],\n      exact \u03bb contra, h_ndiv (mul_dvd_mul_left p contra), },\n    replace h_div : n / p * p = n := nat.div_mul_cancel h_div,\n    have hf : f = (\u03bb y, x + y) \u2218 (\u03bb y, p \u2022 y), { ext, simp [add_comm x], },\n    simp_rw [comp_app],\n    rw [le_eq_subset, Sup_hom.set_image_to_fun, hf, image_comp],\n    have := @monotone_image \ud835\udd4a \ud835\udd4a (\u03bb y, x + y),\n    specialize this (approx_add_order_of.image_nsmul_subset (\u03b4 n) (n/p) hp.pos),\n    simp only [h_div] at this \u22a2,\n    refine this.trans _,\n    convert approx_add_order_of.vadd_subset_of_coprime (p * \u03b4 n) h_cop,\n    simp only [hu\u2080, subtype.coe_mk, h_div, mul_comm p], },\n  change (\u2200\u1d50 x, x \u2209 E) \u2228 E \u2208 volume.ae,\n  rw [\u2190 eventually_eq_empty, \u2190 eventually_eq_univ],\n  have hC : \u2200 (p : nat.primes), (u p) +\u1d65 C p = C p,\n  { intros p,\n    let e := (add_action.to_perm (u p) : equiv.perm \ud835\udd4a).to_order_iso_set,\n    change e (C p) = C p,\n    rw [e.apply_blimsup, \u2190 hu\u2080 p],\n    exact blimsup_congr (eventually_of_forall $ \u03bb n hn,\n      approx_add_order_of.vadd_eq_of_mul_dvd (\u03b4 n) hn.1 hn.2), },\n  by_cases h : \u2200 (p : nat.primes), A p =\u1d50[\u03bc] (\u2205 : set \ud835\udd4a) \u2227 B p =\u1d50[\u03bc] (\u2205 : set \ud835\udd4a),\n  { replace h : \u2200 (p : nat.primes), ((u p) +\u1d65 E : set _) =\u1d50[\u03bc] E,\n    { intros p,\n      replace hE\u2082 : E =\u1d50[\u03bc] C p := hE\u2082 p (h p),\n      have h_qmp : measure_theory.measure.quasi_measure_preserving ((+\u1d65) (-u p)) \u03bc \u03bc :=\n        (measure_preserving_vadd _ \u03bc).quasi_measure_preserving,\n      refine (h_qmp.vadd_ae_eq_of_ae_eq (u p) hE\u2082).trans (ae_eq_trans _ hE\u2082.symm),\n      rw hC, },\n    exact ae_empty_or_univ_of_forall_vadd_ae_eq_self hE\u2080 h hu, },\n  { right,\n    simp only [not_forall, not_and_distrib] at h,\n    obtain \u27e8p, hp\u27e9 := h,\n    rw hE\u2081 p,\n    cases hp,\n    { cases hA p, { contradiction, },\n      simp only [h, union_ae_eq_univ_of_ae_eq_univ_left], },\n    { cases hB p, { contradiction, },\n      simp only [h, union_ae_eq_univ_of_ae_eq_univ_left, union_ae_eq_univ_of_ae_eq_univ_right], } },\nend\n\nend add_circle\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/number_theory/well_approximable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7020359239482943}}
{"text": "/-\nCopyright (c) 2018 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Chris Hughes\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.ring_theory.coprime\nimport Mathlib.ring_theory.ideal.basic\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Lemmas about Euclidean domains\n\nVarious about Euclidean domains are proved; all of them seem to be true\nmore generally for principal ideal domains, so these lemmas should\nprobably be reproved in more generality and this file perhaps removed?\n\n## Tags\n\neuclidean domain\n-/\n\n-- TODO -- this should surely be proved for PIDs instead?\n\ntheorem span_gcd {\u03b1 : Type u_1} [euclidean_domain \u03b1] (x : \u03b1) (y : \u03b1) : ideal.span (singleton (euclidean_domain.gcd x y)) = ideal.span (insert x (singleton y)) := sorry\n\n-- this should be proved for PIDs?\n\ntheorem gcd_is_unit_iff {\u03b1 : Type u_1} [euclidean_domain \u03b1] {x : \u03b1} {y : \u03b1} : is_unit (euclidean_domain.gcd x y) \u2194 is_coprime x y := sorry\n\n-- this should be proved for UFDs surely?\n\ntheorem is_coprime_of_dvd {\u03b1 : Type u_1} [euclidean_domain \u03b1] {x : \u03b1} {y : \u03b1} (z : \u00ac(x = 0 \u2227 y = 0)) (H : \u2200 (z : \u03b1), z \u2208 nonunits \u03b1 \u2192 z \u2260 0 \u2192 z \u2223 x \u2192 \u00acz \u2223 y) : is_coprime x y := sorry\n\n-- this should be proved for UFDs surely?\n\ntheorem dvd_or_coprime {\u03b1 : Type u_1} [euclidean_domain \u03b1] (x : \u03b1) (y : \u03b1) (h : irreducible x) : x \u2223 y \u2228 is_coprime x y := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/ring_theory/euclidean_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.7020089865527065}}
{"text": "import SciLean.Core\nimport SciLean.Functions.EpsNorm\n\nnamespace SciLean\n\n  variable {X} [Hilbert X]\n\n  def \u03b5pow (\u03b5 : \u211d) (x : X) (y : \u211d) : \u211d := Math.pow (\u2225x\u2225\u00b2 + \u03b5^2) (y/2)\n  argument x [Fact (\u03b5\u22600)]\n    isSmooth     := sorry,\n    diff_simp    := y * \u27eadx, x\u27eb * \u03b5pow \u03b5 x (y-2) by sorry,\n    hasAdjDiff   := by constructor; infer_instance; simp; intro; infer_instance; done,\n    adjDiff_simp := (y * (dx' * \u03b5pow \u03b5 x (y-2))) * x by (simp[adjointDifferential]; unfold hold; simp; unfold hold; simp; done)\n  -- Defined in EpsLog.lean \n  -- argument y [Fact (\u03b5\u22600)]\n  --   isSmooth := sorry,\n  --   diff_simp := dy * (\u03b5log \u03b5 x) * \u03b5pow \u03b5 x y by sorry\n\n  notation  \"\u2225\" x \"\u2225^{\" y \",\" \u03b5 \"}\" => \u03b5pow \u03b5 x y\n\n  @[simp]\n  theorem \u03b5pow.is_\u03b5norm_at_one (x : X) (\u03b5 : \u211d) : \u2225x\u2225^{1,\u03b5} = \u2225x\u2225{\u03b5} := sorry\n\n  @[simp]\n  theorem \u03b5pow.is_pow_at_zero (x : X) (y : \u211d)  : \u2225x\u2225^{y,0} = \u2225x\u2225^y := sorry\n\n  theorem \u03b5pow.is_normSqr_at_two (x : X) (y : \u211d)  : \u2225x\u2225^{(2:\u211d),\u03b5} = \u2225x\u2225\u00b2 + \u03b5^2 := sorry\n\n  @[simp]\n  theorem \u03b5pow.recip_\u03b5norm_is_\u03b5pow (x : X) (\u03b5 : \u211d) (c : \u211d) : c/\u2225x\u2225{\u03b5} = c * \u2225x\u2225^{-1,\u03b5} := sorry\n\n  instance \u03b5pow.isNonNegative           (x : X) (y : \u211d) : Fact (\u2225x\u2225^{y,\u03b5} \u2265 0) := sorry\n  instance \u03b5pow.isPositive [Fact (\u03b5\u22600)] (x : X) (y : \u211d) : Fact (\u2225x\u2225^{y,\u03b5} > 0) := sorry\n\n  @[simp]\n  theorem \u03b5pow.is_pow_of_\u03b5norm (\u03b5 : \u211d) [Fact (\u03b5\u22600)] (x : X) (y : \u211d) : \u2225x\u2225{\u03b5}^y = \u2225x\u2225^{y,\u03b5} := sorry\n  \n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/SciLean/Functions/EpsPow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.7020089564640829}}
{"text": "/-\nCopyright (c) 2022 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\n\nimport ring_theory.witt_vector.frobenius_fraction_field\n\n/-!\n\n## F-isocrystals over a perfect field\n\nWhen `k` is an integral domain, so is `\ud835\udd4e k`, and we can consider its field of fractions `K(p, k)`.\nThe endomorphism `witt_vector.frobenius` lifts to `\u03c6 : K(p, k) \u2192 K(p, k)`; if `k` is perfect, `\u03c6` is\nan automorphism.\n\nLet `k` be a perfect integral domain. Let `V` be a vector space over `K(p,k)`.\nAn *isocrystal* is a bijective map `V \u2192 V` that is `\u03c6`-semilinear.\nA theorem of Dieudonn\u00e9 and Manin classifies the finite-dimensional isocrystals over algebraically\nclosed fields. In the one-dimensional case, this classification states that the isocrystal\nstructures are parametrized by their \"slope\" `m : \u2124`.\nAny one-dimensional isocrystal is isomorphic to `\u03c6(p^m \u2022 x) : K(p,k) \u2192 K(p,k)` for some `m`.\n\nThis file proves this one-dimensional case of the classification theorem.\nThe construction is described in Dupuis, Lewis, and Macbeth,\n[Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022].\n\n## Main declarations\n\n* `witt_vector.isocrystal`: a vector space over the field `K(p, k)` additionally equipped with a\n  Frobenius-linear automorphism.\n* `witt_vector.isocrystal_classification`: a one-dimensional isocrystal admits an isomorphism to one\n  of the standard one-dimensional isocrystals.\n\n## Notation\n\nThis file introduces notation in the locale `isocrystal`.\n* `K(p, k)`: `fraction_ring (witt_vector p k)`\n* `\u03c6(p, k)`: `witt_vector.fraction_ring.frobenius_ring_hom p k`\n* `M \u2192\u1da0\u02e1[p, k] M\u2082`: `linear_map (witt_vector.fraction_ring.frobenius_ring_hom p k) M M\u2082`\n* `M \u2243\u1da0\u02e1[p, k] M\u2082`: `linear_equiv (witt_vector.fraction_ring.frobenius_ring_hom p k) M M\u2082`\n* `\u03a6(p, k)`: `witt_vector.isocrystal.frobenius p k`\n* `M \u2192\u1da0\u2071[p, k] M\u2082`: `witt_vector.isocrystal_hom p k M M\u2082`\n* `M \u2243\u1da0\u2071[p, k] M\u2082`: `witt_vector.isocrystal_equiv p k M M\u2082`\n\n## References\n\n* [Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022]\n* [Theory of commutative formal groups over fields of finite characteristic][manin1963]\n* <https://www.math.ias.edu/~lurie/205notes/Lecture26-Isocrystals.pdf>\n\n-/\n\nnoncomputable theory\nopen finite_dimensional\n\nnamespace witt_vector\n\nvariables (p : \u2115) [fact p.prime]\nvariables (k : Type*) [comm_ring k]\nlocalized \"notation (name := witt_vector.fraction_ring)\n  `K(`p`, `k`)` := fraction_ring (witt_vector p k)\" in isocrystal\n\nsection perfect_ring\nvariables [is_domain k] [char_p k p] [perfect_ring k p]\n\n/-! ### Frobenius-linear maps -/\n\n/-- The Frobenius automorphism of `k` induces an automorphism of `K`. -/\ndef fraction_ring.frobenius : K(p, k) \u2243+* K(p, k) :=\nis_fraction_ring.field_equiv_of_ring_equiv (frobenius_equiv p k)\n\n/-- The Frobenius automorphism of `k` induces an endomorphism of `K`. For notation purposes. -/\ndef fraction_ring.frobenius_ring_hom : K(p, k) \u2192+* K(p, k) := fraction_ring.frobenius p k\n\nlocalized \"notation (name := witt_vector.frobenius_ring_hom)\n  `\u03c6(`p`, `k`)` := witt_vector.fraction_ring.frobenius_ring_hom p k\" in isocrystal\n\ninstance inv_pair\u2081 : ring_hom_inv_pair (\u03c6(p, k)) _ :=\nring_hom_inv_pair.of_ring_equiv (fraction_ring.frobenius p k)\n\ninstance inv_pair\u2082 :\n  ring_hom_inv_pair ((fraction_ring.frobenius p k).symm : K(p, k) \u2192+* K(p, k)) _ :=\nring_hom_inv_pair.of_ring_equiv (fraction_ring.frobenius p k).symm\n\nlocalized \"notation (name := frobenius_ring_hom.linear_map) M ` \u2192\u1da0\u02e1[`:50 p `, ` k `] ` M\u2082 :=\n  linear_map (witt_vector.fraction_ring.frobenius_ring_hom p k) M M\u2082\" in isocrystal\nlocalized \"notation (name := frobenius_ring_hom.linear_equiv) M ` \u2243\u1da0\u02e1[`:50 p `, ` k `] ` M\u2082 :=\n  linear_equiv (witt_vector.fraction_ring.frobenius_ring_hom p k) M M\u2082\" in isocrystal\n\n/-! ### Isocrystals -/\n\n/--\nAn isocrystal is a vector space over the field `K(p, k)` additionally equipped with a\nFrobenius-linear automorphism.\n-/\nclass isocrystal (V : Type*) [add_comm_group V] extends module K(p, k) V :=\n( frob : V \u2243\u1da0\u02e1[p, k] V )\n\nvariables (V : Type*) [add_comm_group V] [isocrystal p k V]\nvariables (V\u2082 : Type*) [add_comm_group V\u2082] [isocrystal p k V\u2082]\n\nvariables {V}\n\n/--\nProject the Frobenius automorphism from an isocrystal. Denoted by `\u03a6(p, k)` when V can be inferred.\n-/\ndef isocrystal.frobenius : V \u2243\u1da0\u02e1[p, k] V := @isocrystal.frob p _ k _ _ _ _ _ _ _\nvariables (V)\n\nlocalized \"notation `\u03a6(`p`, `k`)` := witt_vector.isocrystal.frobenius p k\" in isocrystal\n\n/-- A homomorphism between isocrystals respects the Frobenius map. -/\n@[nolint has_nonempty_instance]\nstructure isocrystal_hom extends V \u2192\u2097[K(p, k)] V\u2082 :=\n( frob_equivariant : \u2200 x : V, \u03a6(p, k) (to_linear_map x) = to_linear_map (\u03a6(p, k) x) )\n\n/-- An isomorphism between isocrystals respects the Frobenius map. -/\n@[nolint has_nonempty_instance]\nstructure isocrystal_equiv extends V \u2243\u2097[K(p, k)] V\u2082 :=\n( frob_equivariant : \u2200 x : V, \u03a6(p, k) (to_linear_equiv x) = to_linear_equiv (\u03a6(p, k) x) )\n\nlocalized \"notation (name := isocrystal_hom)\n  M ` \u2192\u1da0\u2071[`:50 p `, ` k `] ` M\u2082 := witt_vector.isocrystal_hom p k M M\u2082\" in isocrystal\nlocalized \"notation (name := isocrystal_equiv)\n  M ` \u2243\u1da0\u2071[`:50 p `, ` k `] ` M\u2082 := witt_vector.isocrystal_equiv p k M M\u2082\" in isocrystal\n\n\nend perfect_ring\n\nopen_locale isocrystal\n\n/-! ### Classification of isocrystals in dimension 1 -/\n\n/-- A helper instance for type class inference. -/\nlocal attribute [instance]\ndef fraction_ring.module : module K(p, k) K(p, k) := semiring.to_module\n\n/--\nType synonym for `K(p, k)` to carry the standard 1-dimensional isocrystal structure\nof slope `m : \u2124`.\n-/\n@[nolint unused_arguments has_nonempty_instance, derive [add_comm_group, module K(p, k)]]\ndef standard_one_dim_isocrystal (m : \u2124) : Type* :=\nK(p, k)\n\nsection perfect_ring\nvariables [is_domain k] [char_p k p] [perfect_ring k p]\n\n/-- The standard one-dimensional isocrystal of slope `m : \u2124` is an isocrystal. -/\ninstance (m : \u2124) : isocrystal p k (standard_one_dim_isocrystal p k m) :=\n{ frob := (fraction_ring.frobenius p k).to_semilinear_equiv.trans\n   (linear_equiv.smul_of_ne_zero _ _ _ (zpow_ne_zero m (witt_vector.fraction_ring.p_nonzero p k))) }\n\n@[simp] lemma standard_one_dim_isocrystal.frobenius_apply (m : \u2124)\n  (x : standard_one_dim_isocrystal p k m) :\n  \u03a6(p, k) x = (p:K(p, k)) ^ m \u2022 \u03c6(p, k) x :=\nrfl\n\nend perfect_ring\n\n/-- A one-dimensional isocrystal over an algebraically closed field\nadmits an isomorphism to one of the standard (indexed by `m : \u2124`) one-dimensional isocrystals. -/\ntheorem isocrystal_classification\n  (k : Type*) [field k] [is_alg_closed k] [char_p k p]\n  (V : Type*) [add_comm_group V] [isocrystal p k V]\n  (h_dim : finrank K(p, k) V = 1) :\n  \u2203 (m : \u2124), nonempty (standard_one_dim_isocrystal p k m \u2243\u1da0\u2071[p, k] V) :=\nbegin\n  haveI : nontrivial V := finite_dimensional.nontrivial_of_finrank_eq_succ h_dim,\n  obtain \u27e8x, hx\u27e9 : \u2203 x : V, x \u2260 0 := exists_ne 0,\n  have : \u03a6(p, k) x \u2260 0 := by simpa only [map_zero] using \u03a6(p,k).injective.ne hx,\n  obtain \u27e8a, ha, hax\u27e9 : \u2203 a : K(p, k), a \u2260 0 \u2227 \u03a6(p, k) x = a \u2022 x,\n  { rw finrank_eq_one_iff_of_nonzero' x hx at h_dim,\n    obtain \u27e8a, ha\u27e9 := h_dim (\u03a6(p, k) x),\n    refine \u27e8a, _, ha.symm\u27e9,\n    intros ha',\n    apply this,\n    simp only [\u2190ha, ha', zero_smul] },\n  obtain \u27e8b, hb, m, hmb\u27e9 := witt_vector.exists_frobenius_solution_fraction_ring p ha,\n  replace hmb : \u03c6(p, k) b * a = p ^ m * b := by convert hmb,\n  use m,\n  let F\u2080 : standard_one_dim_isocrystal p k m \u2192\u2097[K(p,k)] V :=\n    linear_map.to_span_singleton K(p, k) V x,\n  let F : standard_one_dim_isocrystal p k m \u2243\u2097[K(p,k)] V,\n  { refine linear_equiv.of_bijective F\u2080 \u27e8_, _\u27e9,\n    { rw \u2190 linear_map.ker_eq_bot,\n      exact linear_map.ker_to_span_singleton K(p, k) V hx },\n    { rw \u2190 linear_map.range_eq_top,\n      rw \u2190 (finrank_eq_one_iff_of_nonzero x hx).mp h_dim,\n      rw linear_map.span_singleton_eq_range } },\n  refine \u27e8\u27e8(linear_equiv.smul_of_ne_zero K(p, k) _ _ hb).trans F, _\u27e9\u27e9,\n  intros c,\n  rw [linear_equiv.trans_apply, linear_equiv.trans_apply,\n      linear_equiv.smul_of_ne_zero_apply, linear_equiv.smul_of_ne_zero_apply,\n      linear_equiv.map_smul, linear_equiv.map_smul],\n  simp only [hax, linear_equiv.of_bijective_apply, linear_map.to_span_singleton_apply,\n    linear_equiv.map_smul\u209b\u2097, standard_one_dim_isocrystal.frobenius_apply, algebra.id.smul_eq_mul],\n  simp only [\u2190mul_smul],\n  congr' 1,\n  linear_combination \u03c6(p,k) c * hmb,\nend\n\nend witt_vector\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/witt_vector/isocrystal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317888, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.7019477590742665}}
{"text": "import Mathlib.Data.Nat.Basic\nimport Mathlib.Data.Nat.Prime\n\nnamespace BrownCs22 \nnamespace Nat\n\ndef isOdd (n : \u2115) : Prop := \n  \u2203 k : \u2115, n = 2 * k + 1\n\nlemma quotient_remainder {a b c : \u2115} (h : a % b = c) : \u2203 q, a = q*b + c := by \n  use a/b\n  rw [\u2190 h, mul_comm, Nat.div_add_mod]\n\n\nend Nat\n\n\nlemma Set.inter_union_cancel_left {\u03b1 : Type u} {s t : Set \u03b1} : \n  (s \u2229 t) \u222a s = s := by simp\n\nlemma Set.inter_union_cancel_right {\u03b1 : Type u} {s t : Set \u03b1} : \n  (s \u2229 t) \u222a t = t := by simp\n\nnamespace Int\n\n-- def ModEq (n a b : \u2124) : Prop := n \u2223 a - b\n\n\n\n\n-- notation:50 a \" \u2261 \" b \" [ZMOD \" n \"]\" => Int.ModEq n a b\n\nend Int\n\ndef totient (n : \u2115) : \u2115 := ((List.range n).filter n.coprime).length\n\n\nend BrownCs22\n\n", "meta": {"author": "brown-cs22", "repo": "CS22-Lean-2023", "sha": "ad33820fb600dadb2306dadfc74f44629397add2", "save_path": "github-repos/lean/brown-cs22-CS22-Lean-2023", "path": "github-repos/lean/brown-cs22-CS22-Lean-2023/CS22-Lean-2023-ad33820fb600dadb2306dadfc74f44629397add2/BrownCs22/Library/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.7019477509240002}}
{"text": "import linear_algebra.basic\n\nuniverses u v w x\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b4 : Type x}  {\u03b9 : Type x}\n\nnamespace linear_map\nsection\nvariables [ring \u03b1] [add_comm_group \u03b2] [add_comm_group \u03b3] [add_comm_group \u03b4] \nvariables [module \u03b1 \u03b2] [module \u03b1 \u03b3] [module \u03b1 \u03b4] \nvariables (f g : \u03b2 \u2192\u2097[\u03b1] \u03b3)\ninclude \u03b1\n\nlemma comp_eq_mul (f g : \u03b2 \u2192\u2097[\u03b1] \u03b2) : f.comp g = f * g := rfl\n\ndef restrict\n  (f : \u03b2 \u2192\u2097[\u03b1] \u03b3) (p : submodule \u03b1 \u03b2) (q : submodule \u03b1 \u03b3) (hf : \u2200 x \u2208 p, f x \u2208 q) : \n  p \u2192\u2097[\u03b1] q :=\n{ to_fun := \u03bb x, \u27e8f x, hf x.1 x.2\u27e9,\n  add := begin intros, apply set_coe.ext, simp end,\n  smul := begin intros, apply set_coe.ext, simp end }\n\nlemma restrict_apply (f : \u03b2 \u2192\u2097[\u03b1] \u03b3) (p : submodule \u03b1 \u03b2) (q : submodule \u03b1 \u03b3) (hf : \u2200 x \u2208 p, f x \u2208 q) (x : p) :\n  f.restrict p q hf x = \u27e8f x, hf x.1 x.2\u27e9 := rfl\n\n-- TODO: replace sum_apply (wrong type classes on \u03b4)\nlemma sum_apply' [decidable_eq \u03b9] (t : finset \u03b9) (f : \u03b9 \u2192 \u03b2 \u2192\u2097[\u03b1] \u03b3) (b : \u03b2) :\n  t.sum f b = t.sum (\u03bbd, f d b) :=\n(@finset.sum_hom _ _ _ t f _ _ (\u03bb g : \u03b2 \u2192\u2097[\u03b1] \u03b3, g b) _).symm\nend\nend linear_map\n\nvariables {R:discrete_field \u03b1} [add_comm_group \u03b2] [add_comm_group \u03b3]\nvariables [vector_space \u03b1 \u03b2] [vector_space \u03b1 \u03b3]\nvariables (p p' : submodule \u03b1 \u03b2)\nvariables {r : \u03b1} {x y : \u03b2}\ninclude R\n\nset_option class.instance_max_depth 36\n\nlemma vector_space.smul_neq_zero (x : \u03b2) (hr : r \u2260 0) : r \u2022 x = 0 \u2194 x = 0 :=\nbegin\n  have := submodule.smul_mem_iff \u22a5 hr,\n  rwa [submodule.mem_bot, submodule.mem_bot] at this,\nend\n", "meta": {"author": "skbaek", "repo": "cvx", "sha": "c50c790c9116f9fac8dfe742903a62bdd7292c15", "save_path": "github-repos/lean/skbaek-cvx", "path": "github-repos/lean/skbaek-cvx/cvx-c50c790c9116f9fac8dfe742903a62bdd7292c15/src/missing_mathlib/linear_algebra/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7018228366858206}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov\n-/\nimport data.finsupp.basic\nimport data.multiset.antidiagonal\n\n/-!\n# The `finsupp` counterpart of `multiset.antidiagonal`.\n\nThe antidiagonal of `s : \u03b1 \u2192\u2080 \u2115` consists of\nall pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)` such that `t\u2081 + t\u2082 = s`.\n-/\n\nnoncomputable theory\nopen_locale classical big_operators\n\nnamespace finsupp\n\nopen finset\nvariables {\u03b1 : Type*}\n\n/-- The `finsupp` counterpart of `multiset.antidiagonal`: the antidiagonal of\n`s : \u03b1 \u2192\u2080 \u2115` consists of all pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)` such that `t\u2081 + t\u2082 = s`.\nThe finitely supported function `antidiagonal s` is equal to the multiplicities of these pairs. -/\ndef antidiagonal' (f : \u03b1 \u2192\u2080 \u2115) : ((\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)) \u2192\u2080 \u2115 :=\n(f.to_multiset.antidiagonal.map (prod.map multiset.to_finsupp multiset.to_finsupp)).to_finsupp\n\n/-- The antidiagonal of `s : \u03b1 \u2192\u2080 \u2115` is the finset of all pairs `(t\u2081, t\u2082) : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)`\nsuch that `t\u2081 + t\u2082 = s`. -/\ndef antidiagonal (f : \u03b1 \u2192\u2080 \u2115) : finset ((\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)) :=\nf.antidiagonal'.support\n\n@[simp] lemma mem_antidiagonal {f : \u03b1 \u2192\u2080 \u2115} {p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)} :\n  p \u2208 antidiagonal f \u2194 p.1 + p.2 = f :=\nbegin\n  rcases p with \u27e8p\u2081, p\u2082\u27e9,\n  simp [antidiagonal, antidiagonal', \u2190 and.assoc, \u2190 finsupp.to_multiset.apply_eq_iff_eq]\nend\n\nlemma swap_mem_antidiagonal {n : \u03b1 \u2192\u2080 \u2115} {f : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)} :\n  f.swap \u2208 antidiagonal n \u2194 f \u2208 antidiagonal n :=\nby simp only [mem_antidiagonal, add_comm, prod.swap]\n\nlemma antidiagonal_filter_fst_eq (f g : \u03b1 \u2192\u2080 \u2115)\n  [D : \u03a0 (p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)), decidable (p.1 = g)] :\n  (antidiagonal f).filter (\u03bb p, p.1 = g) = if g \u2264 f then {(g, f - g)} else \u2205 :=\nbegin\n  ext \u27e8a, b\u27e9,\n  suffices : a = g \u2192 (a + b = f \u2194 g \u2264 f \u2227 b = f - g),\n  { simpa [apply_ite ((\u2208) (a, b)), \u2190 and.assoc, @and.right_comm _ (a = _), and.congr_left_iff] },\n  unfreezingI {rintro rfl}, split,\n  { rintro rfl, exact \u27e8le_add_right le_rfl, (add_tsub_cancel_left _ _).symm\u27e9 },\n  { rintro \u27e8h, rfl\u27e9, exact add_tsub_cancel_of_le h }\nend\n\nlemma antidiagonal_filter_snd_eq (f g : \u03b1 \u2192\u2080 \u2115)\n  [D : \u03a0 (p : (\u03b1 \u2192\u2080 \u2115) \u00d7 (\u03b1 \u2192\u2080 \u2115)), decidable (p.2 = g)] :\n  (antidiagonal f).filter (\u03bb p, p.2 = g) = if g \u2264 f then {(f - g, g)} else \u2205 :=\nbegin\n  ext \u27e8a, b\u27e9,\n  suffices : b = g \u2192 (a + b = f \u2194 g \u2264 f \u2227 a = f - g),\n  { simpa [apply_ite ((\u2208) (a, b)), \u2190 and.assoc, and.congr_left_iff] },\n  unfreezingI {rintro rfl}, split,\n  { rintro rfl, exact \u27e8le_add_left le_rfl, (add_tsub_cancel_right _ _).symm\u27e9 },\n  { rintro \u27e8h, rfl\u27e9, exact tsub_add_cancel_of_le h }\nend\n\n@[simp] lemma antidiagonal_zero : antidiagonal (0 : \u03b1 \u2192\u2080 \u2115) = singleton (0,0) :=\nby rw [antidiagonal, antidiagonal', multiset.to_finsupp_support]; refl\n\n@[to_additive]\nlemma prod_antidiagonal_swap {M : Type*} [comm_monoid M] (n : \u03b1 \u2192\u2080 \u2115)\n  (f : (\u03b1 \u2192\u2080 \u2115) \u2192 (\u03b1 \u2192\u2080 \u2115) \u2192 M) :\n  \u220f p in antidiagonal n, f p.1 p.2 = \u220f p in antidiagonal n, f p.2 p.1 :=\nfinset.prod_bij (\u03bb p hp, p.swap) (\u03bb p, swap_mem_antidiagonal.2) (\u03bb p hp, rfl)\n  (\u03bb p\u2081 p\u2082 _ _ h, prod.swap_injective h)\n  (\u03bb p hp, \u27e8p.swap, swap_mem_antidiagonal.2 hp, p.swap_swap.symm\u27e9)\n\n/-- The set `{m : \u03b1 \u2192\u2080 \u2115 | m \u2264 n}` as a `finset`. -/\ndef Iic_finset (n : \u03b1 \u2192\u2080 \u2115) : finset (\u03b1 \u2192\u2080 \u2115) :=\n(antidiagonal n).image prod.fst\n\n@[simp] lemma mem_Iic_finset {m n : \u03b1 \u2192\u2080 \u2115} : m \u2208 Iic_finset n \u2194 m \u2264 n :=\nby simp [Iic_finset, le_iff_exists_add, eq_comm]\n\n@[simp] lemma coe_Iic_finset (n : \u03b1 \u2192\u2080 \u2115) : \u2191(Iic_finset n) = set.Iic n :=\nby { ext, simp }\n\n/-- Let `n : \u03b1 \u2192\u2080 \u2115` be a finitely supported function.\nThe set of `m : \u03b1 \u2192\u2080 \u2115` that are coordinatewise less than or equal to `n`,\nis a finite set. -/\nlemma finite_le_nat (n : \u03b1 \u2192\u2080 \u2115) : set.finite {m | m \u2264 n} :=\nby simpa using (Iic_finset n).finite_to_set\n\n/-- Let `n : \u03b1 \u2192\u2080 \u2115` be a finitely supported function.\nThe set of `m : \u03b1 \u2192\u2080 \u2115` that are coordinatewise less than or equal to `n`,\nbut not equal to `n` everywhere, is a finite set. -/\nlemma finite_lt_nat (n : \u03b1 \u2192\u2080 \u2115) : set.finite {m | m < n} :=\n(finite_le_nat n).subset $ \u03bb m, le_of_lt\n\nend finsupp\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/finsupp/antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064586998, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.701822821342586}}
{"text": "/-\nCopyright (c) 2022 Yakov Pechersky. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yakov Pechersky\n-/\n\nimport data.polynomial.taylor\nimport field_theory.ratfunc\nimport ring_theory.laurent_series\n\n/-!\n# Laurent expansions of rational functions\n\n## Main declarations\n\n* `ratfunc.laurent`: the Laurent expansion of the rational function `f` at `r`, as an `alg_hom`.\n* `ratfunc.laurent_injective`: the Laurent expansion at `r` is unique\n\n## Implementation details\n\nImplemented as the quotient of two Taylor expansions, over domains.\nAn auxiliary definition is provided first to make the construction of the `alg_hom` easier,\n  which works on `comm_ring` which are not necessarily domains.\n-/\n\nuniverse u\nnamespace ratfunc\nnoncomputable theory\nopen polynomial\nopen_locale classical non_zero_divisors\n\nvariables {R : Type u} [comm_ring R] [hdomain : is_domain R]\n  (r s : R) (p q : polynomial R) (f : ratfunc R)\n\nlemma taylor_mem_non_zero_divisors (hp : p \u2208 (polynomial R)\u2070) : taylor r p \u2208 (polynomial R)\u2070 :=\nbegin\n  rw mem_non_zero_divisors_iff,\n  intros x hx,\n  have : x = taylor (r - r) x,\n  { simp },\n  have ht := polynomial.taylor_injective r,\n  rwa [this, sub_eq_add_neg, \u2190taylor_taylor, \u2190taylor_mul,\n       linear_map.map_eq_zero_iff _ (taylor_injective _),\n       mul_right_mem_non_zero_divisors_eq_zero_iff hp,\n       linear_map.map_eq_zero_iff _ (taylor_injective _)] at hx,\nend\n\n/-- The Laurent expansion of rational functions about a value.\nAuxiliary definition, usage when over integral domains should prefer `ratfunc.laurent`. -/\ndef laurent_aux : ratfunc R \u2192+* ratfunc R :=\nratfunc.map_ring_hom (ring_hom.mk (taylor r) (taylor_one _) (taylor_mul _)\n  (linear_map.map_zero _) (linear_map.map_add _)) (taylor_mem_non_zero_divisors _)\n\nlemma laurent_aux_of_fraction_ring_mk (q : (polynomial R)\u2070) :\n  laurent_aux r (of_fraction_ring (localization.mk p q)) =\n    of_fraction_ring (localization.mk (taylor r p)\n      \u27e8taylor r q, taylor_mem_non_zero_divisors r q q.prop\u27e9) :=\nmap_apply_of_fraction_ring_mk _ _ _ _\n\ninclude hdomain\n\nlemma laurent_aux_div :\n  laurent_aux r (algebra_map _ _ p / (algebra_map _ _ q)) =\n    algebra_map _ _ (taylor r p) / (algebra_map _ _ (taylor r q)) :=\nmap_apply_div _ _ _ _\n\n@[simp] lemma laurent_aux_algebra_map :\n  laurent_aux r (algebra_map _ _ p) = algebra_map _ _ (taylor r p) :=\nby rw [\u2190mk_one, \u2190mk_one, mk_eq_div, laurent_aux_div, mk_eq_div, taylor_one, _root_.map_one]\n\n/-- The Laurent expansion of rational functions about a value. -/\ndef laurent : ratfunc R \u2192\u2090[R] ratfunc R :=\nratfunc.map_alg_hom (alg_hom.mk (taylor r) (taylor_one _) (taylor_mul _)\n  (linear_map.map_zero _) (linear_map.map_add _) (by simp [polynomial.algebra_map_apply]))\n  (taylor_mem_non_zero_divisors _)\n\nlemma laurent_div :\n  laurent r (algebra_map _ _ p / (algebra_map _ _ q)) =\n    algebra_map _ _ (taylor r p) / (algebra_map _ _ (taylor r q)) :=\nlaurent_aux_div r p q\n\n@[simp] lemma laurent_algebra_map :\n  laurent r (algebra_map _ _ p) = algebra_map _ _ (taylor r p) :=\nlaurent_aux_algebra_map _ _\n\n@[simp] lemma laurent_X : laurent r X = X + C r :=\nby rw [\u2190algebra_map_X, laurent_algebra_map, taylor_X, _root_.map_add, algebra_map_C]\n\n@[simp] lemma laurent_C (x : R) : laurent r (C x) = C x :=\nby rw [\u2190algebra_map_C, laurent_algebra_map, taylor_C]\n\n@[simp] lemma laurent_at_zero : laurent 0 f = f :=\nby { induction f using ratfunc.induction_on, simp }\n\nlemma laurent_laurent :\n  laurent r (laurent s f) = laurent (r + s) f :=\nbegin\n  induction f using ratfunc.induction_on,\n  simp_rw [laurent_div, taylor_taylor]\nend\n\nlemma laurent_injective : function.injective (laurent r) :=\n\u03bb _ _ h, by simpa [laurent_laurent] using congr_arg (laurent (-r)) h\n\nend ratfunc\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/field_theory/laurent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7018228049425871}}
{"text": "import Lake\nimport Init\nimport Mathlib.Data.Real.Basic\n\n\nset_option autoImplicit false\n\n/-! \nWe define basic geometric objects and state Euclid's 5 postulates. \nConvention:\n * Begin variable/theorem names with capital letters.\n * Use underscore between \"words\" in the variable names.\n * Small letters for Points, Lines, etc.\n\nTODO:\n  * Prove equivalence of 5th Postulate and Playfair's axiom.\n  * Prove transitivity of `is_parallel` using Playfair's axiom.\n  * Show that interior of `Symm_angles` is the same.\n-/\n\nstructure IncidenceGeometry /- (Point Line : Type) -/ where\n  Point : Type\n  Line : Type\n  \n  /-- The point lies on the given line.-/\n  lies_on : Point \u2192 Line \u2192 Prop\n\n  /-- `in_between a b c` means \"`b` is in between `a` & `c`\"-/\n  in_between : Point \u2192 Point \u2192 Point \u2192 Prop -- is this supposed to be here?\n  \n  \n  -- properties of in_between\n  /--`Between_refl_left a b` means \"`a` is in between `a` & `b`\"-/\n  Between_refl_left (a b : Point) : in_between a a b\n  \n  /--`Between_refl_right a b` means \"`b` is in between `a` & `b`\"-/\n  Between_refl_right (a b : Point) : in_between a b b\n  \n-- def IncidenceGeometry.Point {P L : Type}(ig : IncidenceGeometry)\n\n\n-- Enter some description here.\nstructure EuclidGeometry extends IncidenceGeometry where\n  \n  -- defining distance\n  distance (a b : Point) : \u211d \n\n  -- distance axioms\n  /--distance between two points is non-negative.-/\n  dist_is_not_neg (a b : Point): distance a b \u2265 0 \n  /--distance from a point to itself is 0.-/\n  dist_same_point (a : Point) : distance a a = 0\n  /--distance between two distinct points is strictly positive.-/\n  dist_geq_0 (a b : Point) : a \u2260 b \u2194 distance a b > 0\n  /--distance from `a` to `b` = distance from `b` to `a`-/\n  dist_is_symm (a b : Point) : distance a b = distance b a\n  /--Triangle Inequality: `distance a b + distance b c \u2265 distance a c`-/\n  dist_tri_ineq (a b c : Point) : distance a b + distance b c \u2265 distance a c\n  /--distance between collinear points `a`, `b`, `c`: `distance a b + distance b c = distance a c`.-/\n  dist_in_between (a b c : Point) : \n    in_between a b c \u2194 (distance a b + distance b c = distance a c)\n\n\n  -- Postulate 1\n  -- Between two points there is an unique line passing through them\n  \n  /--Function that takes two distinct points `a` & `b` and gives a line.-/\n  Line_of_two_points (a b : Point) (h : a \u2260 b): Line \n  /--The line `Line_of_two_points a b` contains the points `a` & `b`.-/\n  Point_contain (a b : Point) (h : a \u2260 b) : \n    have l : Line := Line_of_two_points a b h\n    lies_on a l \u2227 lies_on b l\n  \n  /--A unique line passes through two distinct points `a` & `b`.-/\n  Line_unique (A B: Point) (h : A \u2260 B) (l1 l2 : Line): \n    (lies_on A l1 \u2227 lies_on B l1) \u2227 (lies_on A l2 \u2227 lies_on B l2) \u2192 l1 = l2\n\n  /--Definition of Collinear points `a`, `b`, `c`.-/\n  Collinear_point (A B C : Point) (h : A \u2260 B): \n    in_between A B C \u2228 in_between A C B \u2228 in_between C A B \n    \u2192 lies_on C (Line_of_two_points A B h)\n  \n  \n  \nvariable (geom : EuclidGeometry)\n\n/--A line segment is determined by its endpoints. \nsegment is a structure that consisting of two endpoints: `p1` & `p2`.-/\nstructure segment (geom : IncidenceGeometry) where\n  p1 : geom.Point\n  p2 : geom.Point\n\n\n\ninstance : Coe EuclidGeometry IncidenceGeometry where\n  coe geom := { Point := geom.Point, Line := geom.Line, lies_on := geom.lies_on, in_between := geom.in_between, Between_refl_left := geom.Between_refl_left, Between_refl_right := geom.Between_refl_right}\n  \n\n/--Function gives the length of the segment `seg`.-/\ndef EuclidGeometry.length (seg : segment geom) : \u211d :=\n  geom.distance seg.p1 seg.p2\n\n\n\n\n/--`lies_on_segment p seg` means that point `p` lies on segment `seg`.-/\ndef EuclidGeometry.lies_on_segment (p : geom.Point) (seg : segment geom) : Prop :=\n  geom.in_between seg.p1 p seg.p2\n\n\n-- this defines when a segment lies on a line (use with CAUTION)\n/--`segment_in_line seg l` says that all the points of the segment `seg` lie on the line `l`.-/\ndef EuclidGeometry.segment_in_line\n  (seg: segment geom)(l: geom.Line) : Prop :=\n  \u2200 p: geom.Point, geom.in_between seg.p1 p seg.p2 \u2192 geom.lies_on p l\n\n\n\n-- this theorem says that the line is unique when the length of the segment is non-zero\n/--There is a unique line that contains a line segment of non-zero length.-/\ntheorem EuclidGeometry.Unique_line_from_segment \n  (seg : segment geom) (h : \u00ac seg.p1 = seg.p2) (l1 l2 : geom.Line) : \n  geom.segment_in_line seg l1 \u2227 geom.segment_in_line seg l2\n  \u2192 l1 = l2\n  := by\n    intro h1\n    let \u27e8h2, h3\u27e9 := h1\n    apply geom.Line_unique seg.p1 seg.p2 h l1 l2\n    apply And.intro\n    case left =>\n      apply And.intro\n      case left =>\n        have lem : geom.in_between seg.p1 seg.p1 seg.p2 := \n          geom.Between_refl_left seg.p1 seg.p2\n        simp [segment_in_line] at h2\n        have lem' : geom.in_between seg.p1 seg.p1 seg.p2 \u2192\n          geom.lies_on seg.p1 l1 := by\n            simp [h2, lem]\n        apply lem'\n        assumption\n      case right =>\n        have lem : geom.in_between seg.p1 seg.p2 seg.p2 := \n          geom.Between_refl_right seg.p1 seg.p2\n        simp [segment_in_line] at h2\n        have lem' : geom.in_between seg.p1 seg.p2 seg.p2 \u2192\n          geom.lies_on seg.p2 l1 := by\n            simp [h2, lem]\n        apply lem'\n        assumption\n    case right =>\n      apply And.intro\n      case left =>\n        have lem : geom.in_between seg.p1 seg.p1 seg.p2 := \n          geom.Between_refl_left seg.p1 seg.p2\n        simp [segment_in_line] at h3\n        have lem' : geom.in_between seg.p1 seg.p1 seg.p2 \u2192\n          geom.lies_on seg.p1 l2 := by\n            simp [h3, lem]\n        apply lem'\n        assumption\n      case right =>\n        have lem : geom.in_between seg.p1 seg.p2 seg.p2 := \n          geom.Between_refl_right seg.p1 seg.p2\n        simp [segment_in_line] at h3\n        have lem' : geom.in_between seg.p1 seg.p2 seg.p2 \u2192\n          geom.lies_on seg.p2 l2 := by\n            simp [h3, lem]\n        apply lem'\n        assumption\n\n\n\n\n/--Definition of Parallel Lines-/\ndef EuclidGeometry.is_parallel (l1 l2 : geom.Line) : Prop :=\n  (l1 = l2) \u2228 (\u2200 a : geom.Point, geom.lies_on a l1 \u2192 \u00ac geom.lies_on a l2)\n\n\n-- is_parallel is an equivalence relation on Lines\n/--`is_parallel` is reflexive.-/\ntheorem EuclidGeometry.parallel_refl (l : geom.Line) : \n  is_parallel geom l l \n  := by\n    simp [is_parallel]\n\n/-- `is_parallel` is symmetric.-/\ntheorem EuclidGeometry.Parallel_symm (l1 l2 : geom.Line) : \n  is_parallel geom l1 l2 \u2192 is_parallel geom l2 l1 \n  := by\n    intro h\n    simp [is_parallel]\n    simp [is_parallel] at h\n    apply Or.elim h\n    case left =>\n      intro h1\n      apply Or.inl\n      rw [h1]\n    case right =>\n      intro h2\n      apply Or.inr\n      intro p hp\n      have lem : geom.lies_on p l1 \u2192 \u00ac geom.lies_on p l2 := by\n        apply of_eq_true\n        apply eq_true (h2 p)\n      by_contra h3\n      simp [h3] at lem\n      contradiction\n  \n\n-- transitivity : for this we need Playfair's theorem. \n-- Transitivity has not been used in any definition/theorem,\n-- so we shall prove it later.\n/--`is_parallel` is transitive.-/\ntheorem EuclidGeometry.Parallel_trans (l1 l2 l3: geom.Line) : \n  is_parallel geom l1 l2 \u2192 is_parallel geom l2 l3 \u2192 is_parallel geom l1 l3\n  := by\n    intro h1 h2\n    have h1' : is_parallel geom l1 l2 := h1\n    have h2' : is_parallel geom l2 l3 := h2\n\n    simp [is_parallel]\n    simp [is_parallel] at h1\n    simp [is_parallel] at h2\n    apply Or.elim h1\n    case left =>\n      intro h12eq\n      apply Or.elim h2\n      case left =>\n        intro h23eq\n        apply Or.inl\n        rw [<- h23eq, h12eq]\n      case right =>\n        intro hk\n        rw [<-h12eq] at h2'\n        simp [is_parallel] at h2'\n        assumption\n    case right =>\n      intro hk\n      apply Or.elim h2\n      case left =>\n        intro h23eq\n        rw [h23eq] at h1'\n        simp [is_parallel] at h1'\n        assumption\n      case right =>\n        intro hk1\n        by_cases l1 = l3\n        case pos =>\n          apply Or.inl\n          assumption\n        case neg =>\n          apply Or.inr\n          intro p hp\n          by_contra hk'\n          sorry               -- need to use Playfair's axiom here for this case.\n\n\n        \n/--Definition of intersection of lines. Here, we just say: `\u00ac is_parallel`. -/\ndef EuclidGeometry.Lines_intersect (l1 l2 : geom.Line) : Prop\n  := \u00ac is_parallel geom l1 l2\n\n\n/-- Existence of intersection point for two intersecting lines.-/\ntheorem EuclidGeometry.Lines_intersect_Point_Exist \n  (l1 l2 : geom.Line) (h : Lines_intersect geom l1 l2) :\n  \u2203 c : geom.Point, geom.lies_on c l1 \u2227 geom.lies_on c l2\n  := by\n    simp [Lines_intersect, is_parallel] at h\n    rw [not_or] at h\n    let \u27e8_, h2\u27e9 := h\n    simp at h2\n    assumption\n  \n\n/--`Lines_intersect2 l1 l2 p` states that the lines `l1, l2` \nintersect at the point `p`.-/\ndef EuclidGeometry.Lines_intersect2\n  (l1 l2 : geom.Line) (p : geom.Point) :\n  Prop\n  := geom.lies_on p l1 \u2227 geom.lies_on p l2\n\n\n/--Uniqueness of intersection point for two intersecting lines.-/\ntheorem EuclidGeometry.Lines_intersect_point_unique\n  (l1 l2 : geom.Line) (h : Lines_intersect geom l1 l2) (A B : geom.Point) :\n  Lines_intersect2 geom l1 l2 A \u2192 \n  Lines_intersect2 geom l1 l2 B \u2192\n  A = B\n  := by\n    intro h1 h2\n    by_contra hab\n    simp [Lines_intersect2] at h1\n    let \u27e8h1l, h1r\u27e9 := h1\n    simp [Lines_intersect2] at h2\n    let \u27e8h2l, h2r\u27e9 := h2\n    have lem1 : l1 = l2 := by\n      apply geom.Line_unique A B hab\n      simp [h1l, h1r, h2l, h2r]\n    simp [Lines_intersect, is_parallel] at h\n    rw [not_or] at h\n    let \u27e8hk, _\u27e9 := h\n    contradiction\n\n\n\n/--Existence of intersection point of a line and a segment -/\ndef EuclidGeometry.Line_intersect_segment\n  (seg : segment geom) (l : geom.Line) : Prop := \n  \u2203 p : geom.Point, geom.lies_on p l \u2227 geom.lies_on_segment p seg\n\n/--`Line_intersect_segment2 seg l p` states that \nline `l` intersects the segment `seg` at point `p`-/\ndef EuclidGeometry.Line_intersect_segment2\n  (seg : segment geom) (l : geom.Line) (p : geom.Point): Prop := \n  geom.lies_on p l \u2227 geom.lies_on_segment p seg\n\n\n-- postulate 3\n-- A circle can be constructed with any centre and any radius.\n-- this is just the definition of a circle.\n/-- Circle is a structure with a point `centre` and positive real `radius`.-/\nstructure Circle (geom : EuclidGeometry) where\n  centre : geom.Point\n  radius : \u211d\n\n/--`On_circle p circ` states that the point `p` lies on the circle `circ`.-/\ndef EuclidGeometry.On_circle (p : geom.Point) (circ : Circle geom) : Prop\n  := geom.distance p circ.centre = circ.radius\n\n\n-- postulate 4\n\n/--Angle is a structure with three points. \n`p1 = a`, `Pivot = o`, `p2 = b` denotes the angle (a o b).-/\nstructure Angle (geom : EuclidGeometry) where\n  p1 : geom.Point\n  Pivot : geom.Point\n  p2 : geom.Point\n-- p1 and p2 need to be different from the Pivot\n\n-- TODO: equivalence of angles. Congruence of angles. Same-sidedness with.\n\n\n\nvariable (reflexAngle : Angle geom \u2192 Angle geom)\n\n--measure of an angle\nvariable (mAngle : Angle geom \u2192 \u211d)\n\n\n/--`Int_point_angle a A` states that point `a` is inside angle `A`.-/\ndef EuclidGeometry.Int_point_angle (a : geom.Point) (A : Angle geom) : Prop :=\n  let A1 : Angle geom := Angle.mk a A.Pivot A.p1\n  let A2 : Angle geom := Angle.mk a A.Pivot A.p2\n  (mAngle (A1) < mAngle  A) \u2227 (mAngle (A2) < mAngle A) -- strict inequality because of 120  \n\n\n-- we need to write that Int_point_angle for angles AOB and BOA are the same\n\n-- Postulate 4 says all right angles are equal.\n-- We are assigning it a value of 90\n/--Define a property called `Is_right_angle A` which states that \n`A` is a right angle and its measure is 90.-/\ndef EuclidGeometry.Is_right_angle (A : Angle geom): Prop := mAngle A = 90\n\n\n-- Postulate 5\n\n/--`Opp_sided_points p1 p2 l` states that the two points `p1, p2` \nare on opposite sides of line `l`.-/\ndef EuclidGeometry.Opp_sided_points (p1 p2 : geom.Point) (l : geom.Line) : Prop :=\n  geom.Line_intersect_segment (segment.mk p1 p2) l\n\n/--`Same_sided_points p1 p2 l` states that the two points `p1, p2` \nare on the same side of line `l`. Here, it is: `\u00ac Opp_sided_points p1 p2 l`-/\ndef EuclidGeometry.Same_sided_points (p1 p2 : geom.Point) (l : geom.Line) : Prop :=\n  \u00ac geom.Opp_sided_points p1 p2 l\n \n\n-- List of Axioms and Euclid's Postulates\nstructure Axioms where\n  \n  /--Euclid Postulate #2: every segment lies on a line.-/\n  Post2 (geom : EuclidGeometry) :\n    \u2200 s : segment geom, \u2203 l: geom.Line, geom.segment_in_line s l\n    \n  /--Line can be obtained from a segment.-/\n  Line_from_segment : segment geom \u2192 geom.Line\n\n  -- property of Line_from_segment\n  /---/\n  Line_from_segment_contains_segment (seg : segment geom) :\n    geom.segment_in_line seg (Line_from_segment seg)\n  \n  -- properties of mAngle\n  -- TODO: given a real number r, then given a line and a point, there is a line with that angle r on it.\n  /--Measure of any angle is non-negative.-/\n  mAngle_non_neg (a b c : geom.Point) : \n    mAngle (Angle.mk a b c) \u2265 0\n\n  /--Definition of Zero Angle.-/\n  ZeroAngle (a b c : geom.Point) (_ : geom.in_between a c b): \n    mAngle (Angle.mk a b c) = 0\n\n  /--If not a zero angle, then the measure of the angle is positive.-/\n  mAngle_postive (a b c : geom.Point) : \n    \u00ac geom.in_between a c b \u2192 \n    \u00ac geom.in_between c a b \u2192 \n    mAngle (Angle.mk a b c) > 0\n  \n  /--`mReflexAngle A` returns the measure of the reflex angle of angle `A`.-/\n  mReflexAngle (A : Angle geom) : \n    mAngle (reflexAngle A) = 360 - mAngle A\n  \n  \n  \n  /-- Angle `A` as sum of its constituents.\n  For `mAngle_add a A h`, we have:\n\n  `have A1 : Angle geom := Angle.mk a A.Pivot A.p1`\n\n  `have A2 : Angle geom := Angle.mk a A.Pivot A.p2`\n  \n  then \n  `mAngle A = mAngle A1 + mAngle A2`-/\n  mAngle_add (a : geom.Point) (A : Angle geom) \n    (_ : EuclidGeometry.Int_point_angle geom mAngle a A) :\n    have A1 : Angle geom := Angle.mk a A.Pivot A.p1\n    have A2 : Angle geom := Angle.mk a A.Pivot A.p2\n    mAngle A = mAngle A1 + mAngle A2\n  \n  /--The measure of a straight angle is 180.-/\n  StraightAngle (a b c : geom.Point) (_ : geom.in_between a b c) :\n    mAngle (Angle.mk a b c) = 180\n\n  -- equality of measure of \"symmetric\" angles: e.g. Angle AOB = Angle BOA\n  -- can't write directly that they are equal as they are different structures \"entrywise\".\n  -- we need to also mention that their interior points are equal.\n  /--`Symm_angles (a o b)` states that:\n  \n  `mAngle (Angle (a o b)) = mAngle (Angle (b o a))`.-/\n  Symm_angles (a o b : geom.Point): \n    mAngle (Angle.mk a o b) = mAngle (Angle.mk b o a)\n\n\n  -- Statement of Postulate 5: \n  -- Let line segment AB and CD be intersected by \n  -- line l at points p1 and p2 respectively.\n  -- Let A and C be same-sided wrt l.\n  -- Let mAngle(A p1 p2) + mAngle(C p2 p1) < 180.\n  -- Then there exists a point p such that\n  -- line from AB and CD intersect at p\n  -- and p is same-sided as A wrt to line l.\n  /--Euclid's Postulate #5.-/\n  Post5 (a b c d p1 p2 : geom.Point) (l : geom.Line)\n    (hab : \u00ac a = b) (hcd : \u00ac c = d) :\n    geom.Line_intersect_segment2 (segment.mk a b) l p1\n    \u2192\n    geom.Line_intersect_segment2 (segment.mk c d) l p2\n    \u2192 \n    geom.Same_sided_points a c l\n    \u2192 \n    mAngle (Angle.mk a p1 p2) + mAngle (Angle.mk c p2 p1) < 180\n    \u2192 \n    \u2203 p : geom.Point, \n    geom.Lines_intersect2 \n    (geom.Line_of_two_points a b hab) (geom.Line_of_two_points c d hcd) p\n    \u2227 \n    geom.Same_sided_points p a l\n\n\n\n/--Vertically opposite angles are equal.-/\ntheorem VOAequal (a b c d o : geom.Point) (SELF : Axioms geom reflexAngle mAngle)\n(h1 : \u00aca = b)\n(h2 : \u00acc = d)\n(h3 : geom.in_between a o b \u2227 geom.in_between c o d)\n(_ : \u00acgeom.is_parallel \n  (geom.Line_of_two_points a b h1) \n  (geom.Line_of_two_points c d h2)) \n(h5: geom.Int_point_angle mAngle c (Angle.mk a o b)) \n(h6: geom.Int_point_angle mAngle a (Angle.mk c o d)):\nlet COB := Angle.mk c o b\nlet AOD := Angle.mk a o d\nmAngle (COB) = mAngle (AOD)\n:= by \n  let COA := Angle.mk c o a\n  let AOC := Angle.mk a o c\n  let AOD := Angle.mk a o d \n  let AOB := Angle.mk a o b\n  let COD := Angle.mk c o d\n  let COB := Angle.mk c o b\n  have lem1 : mAngle (AOB) = 180 := Axioms.StraightAngle SELF a o b (And.left h3)\n  have lem2 : mAngle (COD) = 180 := Axioms.StraightAngle SELF c o d (And.right h3)\n  have lem3 : mAngle (AOB) = mAngle (COA) + mAngle (COB) := \n    Axioms.mAngle_add SELF c AOB h5\n  have lem4 : mAngle (COD) = mAngle (AOC) + mAngle (AOD) := \n    Axioms.mAngle_add SELF a COD h6\n  have lem5 : mAngle COA = mAngle AOC := by \n    apply Axioms.Symm_angles SELF\n  have lem6 : mAngle (COA) + mAngle (COB) = mAngle (AOC) + mAngle (AOD) := by\n    rw [<-lem3, <-lem4, lem1, lem2]\n  rw [lem5] at lem6\n  simp [add_left_cancel] at lem6\n  assumption\n  \n\n-- Defination of a triangle.\n\nstructure Triangle (geom : EuclidGeometry) where\n  p1 : geom.Point\n  p2 : geom.Point\n  p3 : geom.Point\n  h12 : p1 \u2260 p2\n  h23 : p2 \u2260 p3\n  h31 : p3 \u2260 p1\n\ndef triangles_are_congruent (T1 T2 : Triangle geom) : Prop :=\n  geom.distance T1.p1 T1.p2 = geom.distance T2.p1 T2.p2 \u2227 \n  geom.distance T1.p2 T1.p3 = geom.distance T2.p2 T2.p3 \u2227\n  geom.distance T1.p3 T1.p1 = geom.distance T2.p3 T2.p1 \u2227\n  mAngle (Angle.mk T1.p2 T1.p1 T1.p3) = mAngle (Angle.mk T2.p2 T2.p1 T2.p3) \u2227 \n  mAngle (Angle.mk T1.p1 T1.p2 T1.p3) = mAngle (Angle.mk T2.p1 T2.p2 T2.p3) \u2227 \n  mAngle (Angle.mk T1.p2 T1.p3 T1.p1) = mAngle (Angle.mk T2.p2 T2.p3 T2.p1)\n \n\nstructure triangle_axioms where\n  -- Assuming SAS congruency an axiom\n  SAS (T1 T2 : Triangle geom) : \n    (geom.distance T1.p1 T1.p2 = geom.distance T2.p1 T2.p2) \n    \u2192 \n    (mAngle (Angle.mk T1.p2 T1.p1 T1.p3) = mAngle (Angle.mk T2.p2 T2.p1 T2.p3)) \n    \u2192 \n    (geom.distance T1.p1 T1.p2 = geom.distance T2.p1 T2.p2)\n    \u2192 \n    triangles_are_congruent geom mAngle T1 T2\n\n\n-- intersection of two circles\ndef EuclidGeometry.circles_intersect (C1 C2 : Circle geom) : Prop :=\n  \u2203 p : geom.Point, \n  (EuclidGeometry.On_circle geom p C1) \u2227 (EuclidGeometry.On_circle geom p C2)\n\n\n-- condition when circles do not intersect and neither is a circle in the interior\ntheorem circles_not_intersect (C1 C2 : Circle geom) : \n  ((C1.radius + C2.radius) < geom.distance C1.centre C2.centre)\n  \u2192 \n  \u00ac geom.circles_intersect C1 C2 \n  := by\n    intro h h'\n    let \u27e8p, hp1, hp2\u27e9 := h'\n    have lem1 : geom.distance C1.centre p = C1.radius := by\n      simp [EuclidGeometry.On_circle] at hp1\n      simp [geom.dist_is_symm]\n      assumption\n    have lem2 : geom.distance p C2.centre = C2.radius := by\n      simp [EuclidGeometry.On_circle] at hp2\n      assumption\n    have lem3 : geom.distance C1.centre p + geom.distance p C2.centre \u2265 \n      geom.distance C1.centre C2.centre := geom.dist_tri_ineq C1.centre p C2.centre \n    rw[lem1, lem2] at lem3\n    have lem4 : \u00ac ((C1.radius + C2.radius) < geom.distance C1.centre C2.centre) := by\n      apply not_lt_of_ge\n      assumption\n    contradiction\n\n\n-- circle non-intersection when one is in the interior of the other.\ntheorem circles_not_intersect2 (C1 C2 : Circle geom) : \n  C1.radius > geom.distance C1.centre C2.centre + C2.radius\n  \u2192 \n  \u00ac geom.circles_intersect C1 C2 \n  := by\n    intro h1 h2 \n    let \u27e8p, hp1, hp2\u27e9 := h2\n    have lem1 : geom.distance C1.centre p = C1.radius := by\n      simp [EuclidGeometry.On_circle] at hp1\n      simp [geom.dist_is_symm]\n      assumption\n    have lem2 : geom.distance C2.centre p = C2.radius := by\n      simp [EuclidGeometry.On_circle] at hp2\n      simp [geom.dist_is_symm]\n      assumption\n    have lem3 : geom.distance C1.centre C2.centre + geom.distance C2.centre p \u2265 \n      geom.distance C1.centre p := geom.dist_tri_ineq C1.centre C2.centre p\n    rw[lem1, lem2] at lem3\n    have lem4 : \u00ac C1.radius > geom.distance C1.centre C2.centre + C2.radius := by\n      apply not_lt_of_ge\n      assumption\n    contradiction\n\n\nstructure circle_axioms where\n  -- circles meeting at one point\n  circles_one_intersect (C1 C2 : Circle geom) :\n    (C1.radius + C2.radius = geom.distance C1.centre C2.centre)\n    \u2192 \n    \u2203! p : geom.Point, geom.On_circle p C1 \u2227 geom.On_circle p C2\n  -- TODO: given line segment AB, and a real number r less than the length(AB), then there is a point p in the segment AB that is at that distance r\n\n  -- circles intersecting at two points\n  circles_two_intersect (C1 C2 : Circle geom) :\n    C1.radius > C2.radius\n    \u2192 \n    (C1.radius - C2.radius < geom.distance C1.centre C2.centre)\n    \u2192\n    (geom.distance C1.centre C2.centre < C1.radius + C2.radius) \n    \u2192\n    \u2203 p1 p2 : geom.Point, (p1 \u2260 p2) \u2227 \n      (geom.On_circle p1 C1 \u2227 geom.On_circle p1 C2) \u2227\n      (geom.On_circle p2 C1 \u2227 geom.On_circle p2 C2)\n\n\n    \n\n", "meta": {"author": "AdarshBasu", "repo": "Elementary-Euclidean-Geometry", "sha": "3a8b70af0258d5d4daa4eca7040a02b99a2afc0e", "save_path": "github-repos/lean/AdarshBasu-Elementary-Euclidean-Geometry", "path": "github-repos/lean/AdarshBasu-Elementary-Euclidean-Geometry/Elementary-Euclidean-Geometry-3a8b70af0258d5d4daa4eca7040a02b99a2afc0e/trials/EuclidPostulates.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7017646717044259}}
{"text": "/-\nCopyright (c) 2022 Huub Vromen. All rights reserved.\nAuthor: Huub Vromen\n-/\n\nimport data.list.basic\n\n/-- Type for individuals -/\nvariable {indiv : Type}\nvariables {i j : indiv}\n\n/-- Type for reasons to believe -/\nvariables {reason : Type} [has_mul reason]\nvariables {r s t : reason}\n\n/-- These reasons will be used in the axioms for reasoning with reasons -/\nconstants {a b c : reason}\n\n/-- A and \u03c6 are propositions that are used in the definition of a basis for common knowledge -/\nconstants {A \u03c6 : Prop}\n\nvariables {\u03b1 \u03b2 \u03b3 : Prop}\n\n/-- `rb` is the property of being a reason for an individual to believe a \n    proposition -/\nvariable rb : reason \u2192 indiv \u2192 Prop \u2192 Prop\n\n/-- R is defined as having `a` reason to believe a proposition -/\ndef R (i : indiv) (\u03c6 : Prop) : Prop := \u2203r, rb r i \u03c6 \n\n/-- Indication is defined as having `a` reason to believe that \u03c6 implies \u03c8 -/\ndef Ind (\u03c6 : Prop) (i : indiv) (\u03c8 : Prop) : Prop := R rb i (\u03c6 \u2192 \u03c8)\n\n/-- Our logic of reasons has the `application rule` as an axiom. This rule is\nbased on the justification logic of Artemov (2019). -/\naxiom AR : rb s i (\u03b1 \u2192 \u03b2 ) \u2192 rb t i \u03b1 \u2192 rb (s * t) i \u03b2\n\n/-- The following axioms define a minimal logic of reasons -/\naxiom T1 : rb a i (\u03b1 \u2192 \u03b2 \u2192 (\u03b1 \u2227 \u03b2))\naxiom T2 : rb b i (((\u03b1 \u2192 \u03b2 ) \u2227 ( \u03b2 \u2192 \u03b3 )) \u2192 (\u03b1 \u2192 \u03b3 ))\naxiom T3 : rb c i (R rb j (\u03b1 \u2192 \u03b2 ) \u2192 (R rb j \u03b1 \u2192 R rb j \u03b2 ))\n\n/-- This lemma is a direct consequence of the application rule `AR` -/\nlemma E1 : R rb i (\u03b1 \u2192 \u03b2) \u2192 R rb i \u03b1 \u2192 R rb i \u03b2 :=\nbegin\nintros h1 h2,\nrw R at *,\ncases h1 with s hs,\ncases h2 with t ht,\napply exists.intro (s * t),\nexact AR rb hs ht,\nend\n\n/-- This lemma is needed for proving lemma (E2) -/\nlemma L1 : R rb i \u03b1 \u2192 R rb i \u03b2 \u2192 R rb i (\u03b1 \u2227 \u03b2) := \nbegin\nintros h1 h2,\nrw R at *,\ncases h1 with s hs,\ncases h2 with t ht,\nhave h3 : rb (a * s) i (\u03b2 \u2192 (\u03b1 \u2227 \u03b2)) :=\n  begin\n  have h4 : rb a i (\u03b1 \u2192 (\u03b2 \u2192 (\u03b1 \u2227 \u03b2))) := T1 rb,\n  exact AR rb h4 hs\n  end,\napply exists.intro (a * s * t),\nexact AR rb h3 ht,\nend\n\n/-- The lemmas (E2) and (E3) are needed for proving lemma (A6) -/\nlemma E2 : R rb i (\u03b1 \u2192 \u03b2 ) \u2192 R rb i (\u03b2 \u2192 \u03b3 ) \u2192 R rb i (\u03b1 \u2192 \u03b3 ) :=\nbegin\nintros h1 h2,\nhave h3 : R rb i ((\u03b1 \u2192 \u03b2) \u2227 (\u03b2 \u2192 \u03b3)) := L1 rb h1 h2,\ncases h3 with s hs,\napply exists.intro (b * s),\nexact AR rb (T2 rb) hs\nend\n\nlemma E3 : R rb i (R rb j (\u03b1 \u2192 \u03b2 )) \u2192 R rb i (R rb j \u03b1 \u2192 R rb j \u03b2 ) := \nbegin\nintros h1,\ncases h1 with s hs,\napply exists.intro (c * s),\nexact AR rb (T3 rb) hs\nend\n\n/-- (A1) follows immediately from the definition of indication and the application \n    rule. So it does not have to be taken as an axiom, like Cubitt and Sugden did. -/\nlemma A1 : Ind rb A i \u03b1 \u2192 R rb i A \u2192 R rb i \u03b1 :=\nbegin\nintros h1 h2,\nrw Ind at h1,\nrw R at *,\ncases h2 with t ht,\ncases h1 with s hs,\napply exists.intro (s * t),\nexact AR rb hs ht\nend\n\n/-- Using (E1) provides a simpler proof -/\nlemma A1_alternative_proof : Ind rb A i \u03b1 \u2192 R rb i A \u2192 R rb i \u03b1 :=\n\u03bb h1 h2, E1 rb h1 h2\n\n\n/-- (A6) can be proven using lemmas (E2) and (E3). So it does not have to be taken \n    as an axiom anymore, like Cubitt and Sugden did. -/\nlemma A6 : \u2200\u03b1, Ind rb A i (R rb j A) \u2192 R rb i (Ind rb A j \u03b1) \u2192 Ind rb A i (R rb j \u03b1) := \nbegin\nintros p h1 h2,\nrw Ind at *,\nhave h3: R rb i (R rb j A \u2192 R rb j p) := E3 rb h2,\nhave h4 : R rb i (A \u2192 R rb j p) := E2 rb h1 h3,\nassumption\nend \n\n\n/-- We are now at the point where we can prove Lewis' theorem -/\ninductive G : Prop \u2192 Prop\n| base                          : G \u03c6 \n| step (p : Prop) (i : indiv)   : G p \u2192 G (R rb i p)\n\nlemma Lewis (p : Prop) \n(C1 : \u2200i, R rb i A)\n(C2 : \u2200i j, Ind rb A i (R rb j A))\n(C3 : \u2200i, Ind rb A i \u03c6)\n(C4 : \u2200\u03b1 i j, Ind rb A i \u03b1 \u2192 R rb i (Ind rb A j \u03b1))\n(h7 : G rb p) : \n    \u2200i, R rb i p :=\nbegin\nintro i,\nhave h1 : Ind rb A i p :=\n    begin\n    induction h7 with u j hu ih,\n{   exact C3 _ },\n{   have h3 : R rb i (Ind rb A j u) := C4 u _ _ ih,\n    have h4 : R rb i (Ind rb A j u) \u2192 Ind rb A i (R rb j u) := A6 rb u (C2 _ _),\n    have h5 : Ind rb A i (R rb j u) := h4 h3,\n    assumption }\n    end,\nexact A1 rb h1 (C1 _),\nend\n\n#lint\n", "meta": {"author": "hjvromen", "repo": "lewis", "sha": "105b675f73630f028ad5d890897a51b3c1146fb0", "save_path": "github-repos/lean/hjvromen-lewis", "path": "github-repos/lean/hjvromen-lewis/lewis-105b675f73630f028ad5d890897a51b3c1146fb0/src/reasons.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7017366252720798}}
{"text": "/-\nCopyright (c) 2022 Clara L\u00f6h. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.txt.\nAuthor: Clara L\u00f6h.\n-/\n\nimport tactic                      -- standard proof tactics\nimport topology.metric_space.basic -- basics on metric spaces\nimport topology.instances.real     -- \u2124 as metric space\n\nopen classical  -- we work in classical logic\n\n/-\nWe define quasi-isometries as quasi-isometric embeddings \nthat admit a quasi-inverse quasi-isometric embedding. \nWe then prove that a quasi-isometric embedding is a \nquasi-isometry if and only if it has quasi-dense image.\n-/\n\n-- Changes by Georgi Kocharyan: Defined on pseudometric spaces, QI-dense definition doesn't\n-- require X to be a metric space\n\n/-\n# Quasi-isometric embeddings and quasi-isometries\n-/\n\n-- quasi-isometric embeddings\ndef is_QIE_lower\n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n    (c b : \u211d)\n:= \u2200 x x' : X, dist (f x) (f x') \u2265 1/c * dist x x' - b    \n\ndef is_QIE_upper\n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n    (c b : \u211d)\n:= \u2200 x x' : X, dist (f x) (f x') \u2264 c * dist x x' + b    \n\ndef is_QIE' \n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n    (c b : \u211d)\n:= is_QIE_upper f c b \n \u2227 is_QIE_lower f c b \n\ndef is_QIE \n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n:= \u2203 c : \u211d, \u2203 b : \u211d,\n   c > 0 \n \u2227 b > 0\n \u2227 is_QIE' f c b \n\n\n-- finite distance\ndef has_fin_dist' \n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f g : X \u2192 Y)\n    (c : \u211d)\n:= \u2200 x : X, dist (f x) (g x) \u2264 c    \n\ndef has_fin_dist \n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f g : X \u2192 Y)\n:= \u2203 c : \u211d, \n   c > 0\n \u2227 has_fin_dist' f g c\n\ndef are_quasi_inverse \n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n    (g : Y \u2192 X)\n:= has_fin_dist (g \u2218 f) id\n \u2227 has_fin_dist (f \u2218 g) id \n\n-- quasi-isometry\ndef is_QI \n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n:= is_QIE f\n \u2227 \u2203 g : Y \u2192 X, is_QIE g \n              \u2227 are_quasi_inverse f g\n\n/-\n# Two lemmas on quasi-isometric embeddings\n-/\n\n-- rewriting the lower estimate for quasi-isometric embeddings\nlemma QIE_lower_est \n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n    (c b : \u211d)\n    (c_pos : c > 0)\n    (f_is_QIE : is_QIE' f c b)\n  : \u2200 x x' : X, dist x x' \u2264 c * dist (f x) (f x') + c * b \n:=\nbegin \n  have c_neq_0 : c \u2260 0, \n       by exact ne_of_gt c_pos,\n  have nonneg_c : 0 \u2264 c,\n       by exact le_of_lt c_pos,\n\n  assume x x' : X,\n\n  have lower_est : 1/c * dist x x' - b \u2264 dist (f x) (f x'), \n       by exact f_is_QIE.2 x x',\n\n  calc dist x x' \n         = c * 1/c * dist x x' - c * b + c * b \n         : by simp[div_self,c_neq_0]\n     ... = c * (1/c * dist x x' - b) + c * b \n         : by ring\n     ... \u2264 c * dist (f x) (f x') + c * b \n         : by {apply add_le_add_right, \n               exact mul_le_mul_of_nonneg_left lower_est nonneg_c},\nend  \n\n-- Sometimes, it is convenient to be able to use \n-- different constants for the upper/lower estimates\nlemma QIE_from_different_constants\n    {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n    (c1 b1 c2 b2: \u211d)\n    (c1_pos : c1 > 0)\n    (b1_pos : b1 > 0)\n    (c2_pos : c2 > 0)\n    (b2_pos : b2 > 0)\n    (f_QIE_upper : is_QIE_upper f c1 b1)\n    (f_QIE_lower : is_QIE_lower f c2 b2)\n  : is_QIE f \n:=\nbegin\n  unfold is_QIE,\n  unfold is_QIE',\n\n  -- we increase the given constants suitably:\n  let c := c1 + c2,\n  let b := b1 + b2,\n\n  use c,\n  use b,\n\n  -- preparation: basic estimates for the constants:\n  have c_pos : c > 0, \n       by exact add_pos c1_pos c2_pos,\n  have nonneg_c : 0 \u2264 c, \n       by exact le_of_lt c_pos,\n  have b_pos : b > 0,\n       by exact add_pos b1_pos b2_pos,\n  have c1_leq_c : c1 \u2264 c, \n       by simp[le_of_lt c2_pos],\n  have b1_leq_b : b1 \u2264 b, \n       by simp[le_of_lt b2_pos],\n  have b2_leq_b : -b2 \u2265 -b,\n       by simp[le_of_lt b1_pos],\n  have c2_leq_c' : c2 \u2264 c, \n       by simp[le_of_lt c1_pos],     \n  have c2_leq_c : 1/c2 \u2265 1/c,\n       by simp[c2_leq_c', inv_le_inv_of_le c2_pos],\n\n  -- Now, the upper/lower estimates are basic calculations:\n  have f_QIE_upper_cb : is_QIE_upper f c b, by \n  begin \n    unfold is_QIE_upper,\n    assume x x' : X,\n    calc dist (f x) (f x')\n           \u2264 c1 * dist x x' + b1 \n           : by exact f_QIE_upper x x' \n       ... \u2264 c1 * dist x x' + b \n           : by exact add_le_add_left b1_leq_b (c1 * dist x x')\n       ... \u2264 c * dist x x' + b \n           : by {apply add_le_add_right,\n                 exact mul_le_mul_of_nonneg_right c1_leq_c dist_nonneg},\n  end,\n\n  have f_QIE_lower_cb : is_QIE_lower f c b, by \n  begin \n    unfold is_QIE_lower,\n    assume x x' : X,\n    calc dist (f x) (f x')\n           \u2265 1/c2 * dist x x' - b2 \n           : by exact f_QIE_lower x x' \n       ... \u2265 1/c2 * dist x x' - b \n           : by exact add_le_add_left b2_leq_b _\n       ... \u2265 1/c * dist x x' - b\n           : by {apply add_le_add_right, \n                 exact mul_le_mul_of_nonneg_right c2_leq_c dist_nonneg}, \n  end,\n\n  show _, \n       by exact \u27e8 c_pos, b_pos, \n                  \u27e8 f_QIE_upper_cb, f_QIE_lower_cb \u27e9\u27e9,\nend     \n\n\n/-\n# An alternative characterisation of quasi-isometries\n-/\n\n-- We show that a quasi-isometric embedding is a quasi-isometry \n-- if and only if it has quasi-dense image.\n-- We show the two implications separately: \n\ndef has_quasidense_image'\n    {X Y : Type*} [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n    (c : \u211d)\n:= \u2200 y : Y, \u2203 x : X, dist (f x) y \u2264 c    \n\ndef has_quasidense_image \n    {X Y : Type*} [pseudo_metric_space Y]\n    (f : X \u2192 Y)\n:= \u2203 c : \u211d, \n   c > 0 \n \u2227 has_quasidense_image' f c\n\n-- Quasi-isometries have quasi-dense image:\ntheorem QI_has_quasidense_image\n     {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n     (f : X \u2192 Y)\n     (f_is_QI : is_QI f)\n   : has_quasidense_image f \n:= \nbegin \n  have ex_qinv : \u2203 g : Y \u2192 X, is_QIE g \n                            \u2227 are_quasi_inverse f g, \n       by exact f_is_QI.2,\n  rcases ex_qinv with \u27e8 g, \u27e8 is_QIE_g, fg_qinv \u27e9\u27e9,\n\n  have fg_close_to_id : \u2203 c : \u211d, c > 0 \u2227 has_fin_dist' (f \u2218 g) id c, \n       by exact fg_qinv.2,\n  rcases fg_close_to_id with \u27e8 c, c_pos, fg_c_close_to_id \u27e9,\n  \n  -- This constant c is a witness for the quasi-density of the image:\n  use c,\n  split,\n  show c > 0, \n       by exact c_pos,\n\n  show has_quasidense_image' f c, by \n  begin \n    unfold has_quasidense_image',\n    assume y,\n    let x := g y,\n    use x,\n    show dist (f x) y \u2264 c, by \n    calc dist (f x) y = dist (f (g y)) y : by simp \n                  ... \u2264 c                : by exact fg_c_close_to_id y,\n  end,\nend\n\n-- Quasi-isometric embeddings with quasi-dense image are quasi-isometries:\n\n-- Preparation: \n-- Quasi-inverses of quasi-isometric embeddings \n-- are quasi-isometric embeddings\nlemma quasiinverse_of_QIE_is_QIE \n     {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n     (f : X \u2192 Y)\n     (g : Y \u2192 X)\n     (f_is_QIE : is_QIE f)\n     (fg_qinv : are_quasi_inverse f g)\n   : is_QIE g\n:=\nbegin\n  -- We choose constants witnessing that \n  -- f is a quasi-isometric embedding and that \n  -- f and g are quasi-inverse to each other:\n  rcases f_is_QIE with \u27e8cf, bf, cf_pos, bf_pos,  \n                        f_is_QIE_upper, f_is_QIE_lower\u27e9,\n  rcases fg_qinv with \u27e8\u27e8c_gf, c_gf_pos, gf_close_to_id\u27e9, \n                       \u27e8c_fg, c_fg_pos, fg_close_to_id\u27e9\u27e9,\n  have f_is_cfbf_QIE : is_QIE' f cf bf,\n       by exact \u27e8 f_is_QIE_upper, f_is_QIE_lower \u27e9, \n\n  -- We combine these constants appropriately:\n  let c1 := cf,\n  let b1 := cf * (2 * c_fg + bf),\n  let c2 := cf,\n  let b2 := 1/cf * (2 * c_fg + bf),\n  have c1_pos : c1 > 0, \n       by exact cf_pos,\n  have b1_pos : b1 > 0, \n       by {apply mul_pos cf_pos, \n           apply add_pos _ bf_pos, \n           simp[mul_pos _ c_fg_pos]},\n  have c2_pos : c2 > 0,\n       by exact cf_pos,\n  have b2_pos : b2 > 0,\n       by {apply mul_pos,\n           apply one_div_pos.mpr cf_pos,\n           apply add_pos _ bf_pos, \n           simp[mul_pos _ c_fg_pos]},\n\n  -- The upper estimate for g:\n  have g_is_QIE_upper : is_QIE_upper g c1 b1, by \n  begin \n    unfold is_QIE_upper,\n    assume y y' : Y,\n    let x  := g y,\n    let x' := g y',\n\n    have dist_f_estimate : dist (f x) (f x') \u2264 dist y y' + 2 * c_fg, \n    by calc dist (f x) (f x') \n              \u2264 dist (f x) y + dist y (f x')\n              : by simp[dist_triangle]\n          ... \u2264 dist (f x) y + dist y y' + dist y' (f x') \n              : by {ring_nf,simp[dist_triangle y y' (f x')]}\n          ... \u2264 c_fg + dist y y' + dist y' (f x') \n              : by {simp, exact fg_close_to_id y}\n          ... \u2264 c_fg + dist y y' + c_fg \n              : by {simp,rw[dist_comm],exact fg_close_to_id y'}    \n          ... \u2264 dist y y' + 2 *c_fg \n              : by ring_nf,\n\n    calc dist (g y) (g y')\n           = dist x x' \n           : by  refl \n       ... \u2264 cf * dist (f x) (f x') + cf * bf \n           : by exact QIE_lower_est f cf bf cf_pos f_is_cfbf_QIE x x'\n       ... \u2264 cf * (dist y y' + 2 * c_fg) + cf * bf \n           : by simp[le_of_lt cf_pos,mul_le_mul_of_nonneg_left,\n                     dist_f_estimate]\n       ... = cf * dist y y' + cf * (2 * c_fg + bf)\n           : by ring        \n       ... \u2264 c1 * dist y y' + b1 \n           : by refl,\n  end,\n\n  -- The lower estimate for g:\n  have g_is_QIE_lower : is_QIE_lower g c2 b2, by \n  begin \n    unfold is_QIE_lower,\n    assume y y' : Y,\n    let x  := g y,\n    let x' := g y',\n\n    have cf_times_claim : \n         cf * dist (g y) (g y') \u2265 dist y y' - cf * b2, \n    by calc cf * dist (g y) (g y') \n             = cf * dist x x' \n             : by refl \n         ... \u2265 dist (f x) (f x') - bf \n             : by {simp,exact f_is_QIE_upper x x'}\n         ... \u2265 dist (f x) y' - dist (f x') y' - bf\n             : by simp[dist_triangle]\n         ... \u2265 dist y' y - dist (f x) y - dist (f x') y' - bf \n             : by simp[dist_triangle_left y' y (f x)]\n         ... \u2265 dist y' y - c_fg - dist (f x') y' - bf \n             : by {simp, exact fg_close_to_id y}\n         ... \u2265 dist y' y - c_fg - c_fg - bf \n             : by {simp, exact fg_close_to_id y'}\n         ... \u2265 dist y y' - cf * (1/cf * (2 * c_fg + bf)) \n             : by {simp[ne_of_gt cf_pos,dist_comm], ring_nf}           \n         ... = dist y y' - cf * b2\n             : by refl,\n\n    have cf_inv_nonneg : 0 \u2264 cf\u207b\u00b9, \n         by simp[inv_nonneg.mpr (le_of_lt cf_pos)],\n\n    calc dist (g y) (g y')\n           = 1/cf * (cf * dist (g y) (g y'))\n           : by simp[ne_of_gt cf_pos] \n       ... \u2265 1/cf * (dist y y' - cf * b2)\n           : by simp[mul_le_mul_of_nonneg_left cf_times_claim \n                                               cf_inv_nonneg]  \n       ... = 1/cf * dist y y' - 1/cf * cf * b2\n           : by ring \n       ... = 1/c2 * dist y y' - b2     \n           : by simp[ne_of_gt cf_pos],\n  end,\n\n  show is_QIE g, \n       by exact QIE_from_different_constants g \n                  c1 b1 c2 b2 \n                  c1_pos b1_pos c2_pos b2_pos \n                  g_is_QIE_upper g_is_QIE_lower,\nend\n\ntheorem QIE_with_quasidense_image_is_QI \n     {X Y : Type*} [pseudo_metric_space X] [pseudo_metric_space Y]\n     (f : X \u2192 Y)\n     (f_is_QIE : is_QIE f)\n     (f_qdense_im : has_quasidense_image f)\n   : is_QI f\n:= \nbegin \n  -- We obtain a quasi-inverse from the quasi-density of the image \n  -- and the axiom of choice:\n  rcases f_qdense_im with \u27e8 c, c_pos, f_has_c_dense_im \u27e9,  \n  rcases classical.axiom_of_choice f_has_c_dense_im\n         with \u27e8 g, fg_c_close_to_id \u27e9,\n  -- basic simplifications       \n  dsimp at g, \n  dsimp at fg_c_close_to_id,\n\n  -- This candidate indeed is quasi-inverse to f:\n  have f_and_g_are_qinv : are_quasi_inverse f g, by \n  begin \n    -- By construction, f \u2218 g has finite distance from id  \n    have fg_close_to_id : has_fin_dist (f \u2218 g) id, by \n    begin \n      unfold has_fin_dist,\n      unfold has_fin_dist',\n      use c,\n      split, \n      show c > 0, \n           by exact c_pos,\n\n      assume y : Y,\n      calc dist ((f \u2218 g) y) y \n             = dist (f (g y)) y : by refl \n         ... \u2264 c                : by exact fg_c_close_to_id y,\n    end,\n\n    -- Conversely, also g \u2218 f has finite distance from id; \n    have gf_close_to_id : has_fin_dist (g \u2218 f) id, by \n    begin \n      unfold has_fin_dist,\n      unfold has_fin_dist',\n      -- we choose QIE-constants for f ...\n      rcases f_is_QIE with \u27e8 cf, bf, cf_pos, bf_pos, f_is_cfbf_QIE \u27e9,\n      -- ... and construct a suitably large constant c':\n      let c' := cf * c + cf * bf,\n      use c',\n      split, \n      show c' > 0, \n           by {apply add_pos, \n               apply mul_pos cf_pos,\n               exact c_pos,\n               apply mul_pos cf_pos bf_pos},\n\n      assume x,\n      show dist ((g \u2218 f) x) x \u2264 c', by \n      begin \n        let x_fx := g (f x),\n        calc dist ((g \u2218 f) x) x\n               = dist x_fx x \n               : by refl \n           ... \u2264 cf * dist (f x_fx) (f x) + cf * bf \n               : by exact QIE_lower_est f cf bf cf_pos f_is_cfbf_QIE x_fx x \n           ... \u2264 cf * c + cf * bf \n               : by simp[fg_c_close_to_id (f x), \n                         le_of_lt cf_pos, mul_le_mul_of_nonneg_left]\n           ... \u2264 c' \n               : by refl,\n      end,\n    end,\n\n    show are_quasi_inverse f g, \n         by exact \u27e8 gf_close_to_id, fg_close_to_id \u27e9,\n  end,\n\n  -- Hence, g is a quasi-isometric embedding:\n  have g_is_QIE : is_QIE g, \n       by exact quasiinverse_of_QIE_is_QIE f g \n                  f_is_QIE f_and_g_are_qinv,\n\n  -- We conclude that f is a quasi-isometry \n  -- by putting everything together:\n  show is_QI f, \n       by exact \u27e8 f_is_QIE, \n                  begin \n                    use g, \n                    exact \u27e8 g_is_QIE, f_and_g_are_qinv\u27e9 \n                  end\u27e9,\nend    \n\n/-\n# An example\n-/\n\n-- We use the quasi-density criterion to show that\n-- the inclusion of \u2124 into \u211d is a quasi-isometry\ndef i_ZR \n   : \u2124 \u2192 \u211d \n:= \u03bb x, x\n\nlemma Z_into_R_is_QI \n   : is_QI i_ZR\n:= \nbegin\n  apply QIE_with_quasidense_image_is_QI, \n\n  show is_QIE i_ZR, by \n  begin \n    unfold is_QIE,\n    use 1,\n    use 1,\n\n    have one_pos : (1:real) > 0, \n         by simp,\n\n    have i_ZR_is_QIE : is_QIE' i_ZR 1 1, by \n    begin \n      unfold is_QIE',\n\n      have upper_estimate : \u2200 x x' : \u2124, \n           dist (i_ZR x) (i_ZR x') \u2264 1 * dist x x' + 1, by\n      begin  \n        assume x x' : \u2124,\n        simp[i_ZR],\n      end,\n\n      have lower_estimate : \u2200 x x' : \u2124, \n           dist (i_ZR x) (i_ZR x') \u2265 1/1 * dist x x' - 1, by \n      begin \n        assume x x' : \u2124,\n        simp[i_ZR],\n      end,        \n\n      show _, \n           by {simp only[is_QIE_upper,is_QIE_lower], \n               exact \u27e8upper_estimate, lower_estimate \u27e9},\n    end,\n\n    show _, \n        by exact \u27e8 one_pos, \u27e8one_pos, i_ZR_is_QIE\u27e9\u27e9, \n  end,\n\n  show has_quasidense_image i_ZR, by \n  begin \n    unfold has_quasidense_image,\n    use 1, \n\n    have one_pos : (1:real) > 0, \n         by simp,\n\n    have qdense_im : has_quasidense_image' i_ZR 1, by \n    begin \n      unfold has_quasidense_image',\n\n      assume y : \u211d,\n      let x := int.floor y,\n      use x,\n\n      show dist (i_ZR x) y \u2264 1, by \n      begin \n        calc dist (i_ZR x) y \n               = dist y (i_ZR x) \n               : by exact dist_comm _ _ \n           ... = |y - \u2191x| \n               : by refl\n           ... = y - \u2191x\n               : by simp[int.floor_le,int.fract_nonneg]\n           ... \u2264 1 \n               : by simp[int.fract_lt_one,le_of_lt],\n      end,\n    end,\n\n    show _, \n         by exact \u27e8one_pos, qdense_im\u27e9,\n  end,\nend   \n\n", "meta": {"author": "GregorSamsa42", "repo": "svarc-milnor", "sha": "f00cf43ac608402bbcda977998ca8227d52b93e6", "save_path": "github-repos/lean/GregorSamsa42-svarc-milnor", "path": "github-repos/lean/GregorSamsa42-svarc-milnor/svarc-milnor-f00cf43ac608402bbcda977998ca8227d52b93e6/src/quasiisometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7017233373213572}}
{"text": "/-\nSome basic facts unrelated to clauses, etc.\n\nAuthor: Cayden Codel, Marijn Heule, Jeremy Avigad\nCarnegie Mellon University\n-/\n\nimport data.bool.basic\nimport data.list.basic\nimport data.list.indexes\nimport init.data.nat.lemmas\nimport data.finset.basic\nimport data.finset.fold\nimport init.function\nimport tactic\n\nopen list\nopen function\nopen nat\n\nuniverses u v\nvariables {\u03b1 : Type u} {\u03b2 : Type v}\n\n/-! # Boolean logic -/\n\n/- General -/\n\ntheorem ne_of_eq_ff_of_eq_tt {a b : bool} : a = ff \u2192 b = tt \u2192 a \u2260 b :=\nassume h\u2081 h\u2082, by { rw [h\u2081, h\u2082], intro h, contradiction }\n\ntheorem bool_symm : \u2200 (a b : bool), a = b \u2194 b = a :=\nby simp only [bool.forall_bool, iff_self, and_self]\n\n/- bxor -/\n\n@[simp] theorem bxor_tt_left  : \u2200 a, bxor tt a = !a := dec_trivial\n@[simp] theorem bxor_tt_right : \u2200 a, bxor a tt = !a := dec_trivial\n\ntheorem bxor_conjunctive (a b : bool) : bxor a b = (a || b) && (!a || !b) :=\nby cases a; cases b; dec_trivial\n\ntheorem bxor_disjunctive (a b : bool) : bxor a b = (!a && b) || (a && !b) :=\nby cases a; cases b; dec_trivial\n\n/- cond -/\n\n@[simp] theorem cond_tt_ff : \u2200 a, cond a tt ff = a := dec_trivial\n@[simp] theorem cond_ff_tt : \u2200 a, cond a ff tt = !a := dec_trivial\n\ntheorem tt_of_cond_ne_second [decidable_eq \u03b1] {c d : \u03b1} {b : bool} :\n  cond b c d \u2260 d \u2192 b = tt :=\nby { cases b, contradiction, tautology }\n\ntheorem ff_of_cond_ne_first [decidable_eq \u03b1] {c d : \u03b1} {b : bool} :\n  cond b c d \u2260 c \u2192 b = ff :=\nby { cases b, tautology, contradiction }\n\ntheorem tt_of_ne_second_of_cond_eq [decidable_eq \u03b1] {c d e : \u03b1} {b : bool} :\n  d \u2260 e \u2192 cond b c d = e \u2192 b = tt :=\nby { cases b, { intros, contradiction }, { tautology } }\n\ntheorem ff_of_ne_first_of_cond_eq [decidable_eq \u03b1] {c d e : \u03b1} {b : bool} :\n  c \u2260 e \u2192 cond b c d = e \u2192 b = ff :=\nby { cases b, { tautology }, { intros, contradiction } }\n\ntheorem tt_of_ne_of_cond_eq_first [decidable_eq \u03b1] {c d : \u03b1} {b : bool} :\n  c \u2260 d \u2192 cond b c d = c \u2192 b = tt :=\nby { cases b, { intros h\u2081 h\u2082, exact absurd h\u2082.symm h\u2081 }, { tautology } }\n\ntheorem ff_of_ne_of_cond_eq_second [decidable_eq \u03b1] {c d : \u03b1} {b : bool} :\n  c \u2260 d \u2192 cond b c d = d \u2192 b = ff :=\nby { cases b, { tautology }, { intros, contradiction }}\n\n/-! # List operations -/\n\n/- General results -/\n\ntheorem exists_append_singleton_of_ne_nil {l : list \u03b1} :\n  l \u2260 [] \u2192 \u2203 L a, l = L ++ [a] :=\nbegin\n  induction l with l\u2081 l ih,\n  { contradiction },\n  { intro h,\n    cases l with l\u2082 l,\n    { use [[], l\u2081], simp only [nil_append, eq_self_iff_true, and_self] },\n    { rcases ih (cons_ne_nil l\u2082 l) with \u27e8L, t, ht\u27e9,\n      use [l\u2081 :: L, t], simp only [ht, cons_append, eq_self_iff_true, and_self] } }\nend\n\n-- TODO: do casewise with |, not in tactic\ntheorem exists_cons_cons_of_length_ge_two {l : list \u03b1} : \n  length l \u2265 2 \u2192 \u2203 (a b : \u03b1) (L : list \u03b1), (a :: b :: L) = l :=\nbegin\n  cases l with a as,\n  { intro h, rw length at h, linarith },\n  { cases as with b bs, \n    { intro h, rw [length, length] at h, linarith },\n    { intro _,\n      use [a, b, bs] } }\nend\n\ntheorem exists_cons_cons_of_length_eq_two {l : list \u03b1} :\n  length l = 2 \u2192 \u2203 (a b : \u03b1), [a, b] = l :=\nbegin\n  cases l with a as,\n  { intro h, rw length at h, linarith },\n  { cases as with b bs,\n    { intro h, rw [length, length] at h, linarith },\n    { cases bs with c cs,\n      { simp },\n      { intro h, rw [length, length, length] at h, linarith } } }\nend\n\ntheorem nth_le_of_ge {\u03b1 : Type*} {l : list \u03b1} {n c : nat} (Hn : n < length l) :\n  n \u2265 c \u2192 \u2203 (Hn' : (n - c) + c < length l), \n  nth_le l n Hn = nth_le l ((n - c) + c) Hn' :=\nbegin\n  intro hc,\n  have := nat.sub_add_cancel hc,\n  use this.symm \u25b8 Hn,\n  simp [this]\nend\n\ntheorem take_one_of_ne_nil {\u03b1 : Type*} [inhabited \u03b1] {l : list \u03b1} : \n  l \u2260 [] \u2192 l.take 1 = [l.head] :=\nbegin\n  intro hl,\n  rcases exists_cons_of_ne_nil hl with \u27e8a, as, rfl\u27e9,\n  simp [take, head]\nend\n\n@[simp] theorem mem_map_with_index {\u03b1 \u03b2 : Type*} {l : list \u03b1} {b : \u03b2} {f : nat \u2192 \u03b1 \u2192 \u03b2} :\n  b \u2208 l.map_with_index f \u2194 \u2203 (a : \u03b1) (i : nat) (Hi : i < length l), a = l.nth_le i Hi \u2227 f i a = b :=\nbegin\n  induction l with a l ih generalizing f,\n  { split, { rintro \u27e8_\u27e9 }, { rintro \u27e8a, _, \u27e8_\u27e9, _\u27e9 } },\n  { split,\n    { intro hb,\n      rcases eq_or_mem_of_mem_cons hb with (rfl | hw),\n      { use [a, 0, dec_trivial],\n        rw nth_le,\n        exact \u27e8rfl, rfl\u27e9 },\n      { rw map_with_index_core_eq at hw,\n        rcases ih.mp hw with \u27e8a, i, Hi, ha, hf\u27e9,\n        use [a, i + 1, succ_lt_succ_iff.mpr Hi],\n        rw nth_le,\n        subst ha,\n        simp [hf], -- Investigate below later\n        exact equiv.apply_swap_eq_self rfl Hi } },\n    { rintros \u27e8a, i, Hi, ha, hf\u27e9,\n      cases i,\n      { rw nth_le at ha,\n        subst hf,\n        rw [map_with_index, map_with_index_core, ha],\n        exact mem_cons_self _ _ },\n      { rw nth_le at ha,\n        have := succ_lt_succ_iff.mp Hi,\n        rw [map_with_index, map_with_index_core],\n        apply (mem_cons_iff _ _ _).mpr,\n        right,\n        rw map_with_index_core_eq,\n        apply ih.mpr,\n        use [a, i, this, ha, hf] } } }\nend\n\ntheorem take_sublist_of_le {\u03b1 : Type*} {i j : nat} : i \u2264 j \u2192 \n  \u2200 (l : list \u03b1), l.take i <+ l.take j :=\nbegin\n  intros hij l,\n  induction l with a as ih generalizing i j,\n  { rw [take_nil, take_nil] },\n  { cases i,\n    { rw take_zero,\n      exact nil_sublist _ },\n    { cases j,\n      { exact absurd hij (not_le.mpr (succ_pos i)) },\n      { rw [take, take],\n        exact cons_sublist_cons_iff.mpr (ih (succ_le_succ_iff.mp hij)) } } }\nend\n\ntheorem ne_tail_of_eq_head_of_ne [decidable_eq \u03b1] {a b : \u03b1} {l\u2081 l\u2082 : list \u03b1} :\n  (a :: l\u2081) \u2260 (b :: l\u2082) \u2192 a = b \u2192 l\u2081 \u2260 l\u2082 :=\nassume hne hab hl, absurd (congr (congr_arg cons hab) hl) hne\n\ntheorem length_lt_length_cons (a : \u03b1) (l : list \u03b1) :\n  length l < length (a :: l) :=\nby { rw length_cons, exact lt_add_one _ }\n\ntheorem strong_induction_on_lists [inhabited \u03b1] {p : list \u03b1 \u2192 Prop} (l : list \u03b1)\n  (h : \u2200 l\u2081, (\u2200 l\u2082, length l\u2082 < length l\u2081 \u2192 p l\u2082) \u2192 p l\u2081) : p l :=\nsuffices \u2200 (l\u2081 : list \u03b1) (l\u2082 : list \u03b1), length l\u2082 < length l\u2081 \u2192 p l\u2082,\n  from this ((arbitrary \u03b1) :: l) l (length_lt_length_cons (arbitrary \u03b1) l),\nbegin\n  intro l\u2081, induction l\u2081 with a as ih,\n  { intros l\u2082 h\u2081, exact absurd h\u2081 (l\u2082.length).not_lt_zero },\n  { intros m h\u2081,\n    apply or.by_cases (decidable.lt_or_eq_of_le (nat.le_of_lt_succ h\u2081)),\n    { intros, apply ih, assumption },\n    { intro hlen, have := h m, rw hlen at this, exact this ih } }\nend\n\ntheorem exists_append_of_gt_length {l : list \u03b1} {n : nat} : \n  length l > n \u2192 \u2203 (l\u2081 l\u2082 : list \u03b1), l\u2081 ++ l\u2082 = l \u2227 length l\u2081 = n :=\nbegin\n  induction n with n ih,\n  { intro h, use [nil, l, nil_append l, rfl] },\n  { intro h,\n    rcases ih (nat.lt_of_succ_lt h) with \u27e8l\u2081, l\u2082, rfl, hl\u2081\u27e9,\n    cases l\u2082 with l\u2082h hl\u2082t,\n    { simp [hl\u2081] at h,\n      exact absurd h (nat.not_succ_lt_self) },\n    { use [l\u2081 ++ [l\u2082h], hl\u2082t],\n      simp only [hl\u2081, eq_self_iff_true, length, singleton_append, \n        append_assoc, and_self, length_append] } }\nend\n\ntheorem exists_append_mem_of_mem_of_ne {l : list \u03b1} {a b : \u03b1} :\n  a \u2208 l \u2192 b \u2208 l \u2192 a \u2260 b \u2192 \u2203 (l\u2081 l\u2082), l\u2081 ++ l\u2082 = l \u2227 \n  ((a \u2208 l\u2081 \u2227 b \u2208 l\u2082) \u2228 (a \u2208 l\u2082 \u2227 b \u2208 l\u2081)) :=\nbegin\n  induction l with x xs ih,\n  { simp only [not_mem_nil, is_empty.forall_iff] },\n  { intros ha hb hne,\n    rcases eq_or_mem_of_mem_cons ha with (rfl | ha),\n    { have := mem_of_ne_of_mem hne.symm hb,\n      use [[a], xs],\n      simp only [this, true_or, eq_self_iff_true, singleton_append, \n        and_self, mem_singleton] },\n    { rcases eq_or_mem_of_mem_cons hb with (rfl | hb),\n      { have := mem_of_ne_of_mem hne ha,\n        use [[b], xs],\n        simp only [this, hne, false_or, eq_self_iff_true, singleton_append, \n          and_self, mem_singleton, false_and] },\n      { rcases ih ha hb hne with \u27e8l\u2081, l\u2082, rfl, (\u27e8hl\u2081, hl\u2082\u27e9 | \u27e8hl\u2081, hl\u2082\u27e9)\u27e9,\n        { use [(x :: l\u2081), l\u2082],\n          simp only [hl\u2081, hl\u2082, mem_cons_iff, cons_append, true_or, \n            eq_self_iff_true, or_true, and_self] },\n        { use [(x :: l\u2081), l\u2082],\n          simp only [hl\u2081, hl\u2082, mem_cons_iff, cons_append, eq_self_iff_true, \n            or_true, and_self] } } } }\nend\n\ntheorem nth_le_sub_of_gt_zero {l : list \u03b1} {a : \u03b1} {n : nat} \n  (hn : n < length (a :: l)) (hnsub : (n - 1) < length l) :\n  n > 0 \u2192 nth_le (a :: l) n hn = nth_le l (n - 1) hnsub :=\nbegin\n  cases n,\n  { intro h, exact absurd (ge_of_eq (refl 0)) (not_le.mpr h) },\n  { intro _,\n    rw nth_le,\n    refl }\nend\n\n/- fold -/\n\ntheorem foldr_bor_tt (l : list \u03b1) (f : \u03b1 \u2192 bool) : \n  foldr (\u03bb x b, b || f x) tt l = tt :=\nbegin\n  induction l with x xs ih,\n  { rw foldr_nil },\n  { rw [foldr_cons, ih, tt_bor] }\nend\n\ntheorem foldr_band_ff (l : list \u03b1) (f : \u03b1 \u2192 bool) :\n  foldr (\u03bb x b, b && f x) ff l = ff :=\nbegin\n  induction l with x xs ih,\n  { rw foldr_nil },\n  { rw [foldr_cons, ih, ff_band] }\nend\n\nsection map\n\nvariables {f : \u03b1 \u2192 \u03b2} {a : \u03b1} {b : \u03b2} {l : list \u03b1}\n\ntheorem exists_of_map_singleton : map f l = [b] \u2192 \u2203 a, [a] = l \u2227 f a = b :=\nbegin\n  cases l with x xs,\n  { contradiction },\n  { simp [map_cons],\n    intros h\u2081 h\u2082,\n    simp [h\u2081, h\u2082] }\nend\n\ntheorem exists_cons_of_map_cons {bs : list \u03b2} :\n  map f l = b :: bs \u2192 \u2203 h L, l = h :: L \u2227 f h = b \u2227 map f L = bs :=\nbegin\n  cases l with x xs,\n  { contradiction },\n  { rw map_cons,\n    intro h,\n    use [x, xs, \u27e8refl _, (head_eq_of_cons_eq h), (tail_eq_of_cons_eq h)\u27e9] }\nend\n\ntheorem exists_map_cons_of_map_cons {as : list \u03b1} : map f l = map f (a :: as) \u2192 \n  \u2203 h L, l = h :: L \u2227 f h = f a \u2227 map f L = map f as :=\nby { rw [map_cons], intro h, exact exists_cons_of_map_cons h }\n\ntheorem mem_map_append {l\u2081 l\u2082 : list \u03b1} {f : \u03b1 \u2192 \u03b2} {b : \u03b2} :\n  b \u2208 map f (l\u2081 ++ l\u2082) \u2192 b \u2208 map f l\u2081 \u2228 b \u2208 map f l\u2082 :=\nby { rw [map_append, mem_append], exact id }\n\ntheorem mem_map_fst_of_mem {l : list (\u03b1 \u00d7 \u03b2)} {a : \u03b1} {b : \u03b2} :\n  (a, b) \u2208 l \u2192 a \u2208 map prod.fst l :=\nassume h, mem_map.mpr \u27e8\u27e8a, b\u27e9, h, rfl\u27e9\n\ntheorem mem_map_snd_of_mem {l : list (\u03b1 \u00d7 \u03b2)} {a : \u03b1} {b : \u03b2} :\n  (a, b) \u2208 l \u2192 b \u2208 map prod.snd l :=\nassume h, mem_map.mpr \u27e8\u27e8a, b\u27e9, h, rfl\u27e9\n\nend map\n\n/- filter -/\n\ntheorem length_filter {p : \u03b1 \u2192 Prop} [decidable_pred p] {l : list \u03b1} : \n  length (filter p l) \u2264 length l :=\nbegin\n  induction l with x xs ih,\n  { refl },\n  { by_cases p x,\n    { rw [filter_cons_of_pos _ h, length_cons, length_cons],\n      exact nat.succ_le_succ_iff.mpr ih },\n    { rw [filter_cons_of_neg _ h, length_cons],\n      exact le_add_right ih } }\nend\n\n/-! # Naturals and successors of supremums -/\n\nsection nat\n\nopen nat\n\nvariables {f : \u03b1 \u2192 nat} {l : list nat} {n m : nat}\n\n/- General -/\n\ntheorem ne_succ_add (n m : nat) : n.succ + m \u2260 n :=\nbegin\n  rw [succ_eq_add_one, add_assoc, \u2190 succ_eq_one_add],\n  exact ne_of_gt (lt_add_of_pos_right n (succ_pos m))\nend\n\ntheorem eq_succ_of_gt_of_le_succ {n m : nat} : m < n \u2192 n \u2264 m + 1 \u2192 n = m + 1 :=\nassume h\u2081 h\u2082, ge_antisymm (succ_le_iff.mpr h\u2081) h\u2082\n\ntheorem add_gt_one_of_gt_zero_of_gt_zero {n m : nat} : n > 0 \u2192 m > 0 \u2192 n + m > 1 :=\nassume h\u2081 h\u2082, succ_le_iff.mp (add_le_add (succ_le_iff.mpr h\u2081) (succ_le_iff.mpr h\u2082))\n\nsection max_nat\n\ndef max_nat : list nat \u2192 nat\n| []        := 0\n| (n :: ns) := max n (max_nat ns)\n\ntheorem max_nat_eq_foldr_max (l) : max_nat l = foldr max 0 l :=\nbegin\n  induction l with n ns ih,\n  { refl },\n  { unfold max_nat, rw [foldr_cons, ih] }\nend\n\ntheorem le_max_nat_of_mem : n \u2208 l \u2192 n \u2264 max_nat l :=\nbegin\n  induction l with m ms ih,\n  { intro h, exact absurd h (not_mem_nil _) },\n  { intros h,\n    rcases eq_or_mem_of_mem_cons h with rfl | hms,\n    { exact le_max_iff.mpr (or.inl (le_refl n)) },\n    { exact le_max_iff.mpr (or.inr (ih hms)) } }\nend\n\ntheorem not_mem_of_gt_max_nat : n > max_nat l \u2192 n \u2209 l :=\nby { contrapose, simp, exact le_max_nat_of_mem }\n\ntheorem exists_not_mem_of_bijective_of_gt_max_nat \n  (hf : bijective f) {l : list \u03b1} :\n  n > max_nat (map f l) \u2192 \u2203 a, f a = n \u2227 a \u2209 l :=\nbegin\n  intros h,\n  rcases (bijective_iff_exists_unique f).mp hf n with \u27e8b, hb, _\u27e9,\n  use b,\n  split,\n  { exact hb },\n  { intro hbl,\n    exact (not_mem_of_gt_max_nat h) (hb \u25b8 mem_map_of_mem f hbl) }\nend\n\nend max_nat\n\nend nat", "meta": {"author": "chasenorman", "repo": "verified-encodings-social-choice", "sha": "72f88c5a31ce30df5a04a99f726244c327b9a6f6", "save_path": "github-repos/lean/chasenorman-verified-encodings-social-choice", "path": "github-repos/lean/chasenorman-verified-encodings-social-choice/verified-encodings-social-choice-72f88c5a31ce30df5a04a99f726244c327b9a6f6/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7017066654943912}}
{"text": "/-\nCopyright (c) 2017 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard, Mario Carneiro\n\nThe complex numbers, modelled as R^2 in the obvious way.\n-/\nimport data.real.basic tactic.ring algebra.field_power\n\nstructure complex : Type :=\n(re : \u211d) (im : \u211d)\n\nnotation `\u2102` := complex\n\nnamespace complex\n\n@[simp] theorem eta : \u2200 z : \u2102, complex.mk z.re z.im = z\n| \u27e8a, b\u27e9 := rfl\n\ntheorem ext : \u2200 {z w : \u2102}, z.re = w.re \u2192 z.im = w.im \u2192 z = w\n| \u27e8zr, zi\u27e9 \u27e8_, _\u27e9 rfl rfl := rfl\n\ntheorem ext_iff {z w : \u2102} : z = w \u2194 z.re = w.re \u2227 z.im = w.im :=\n\u27e8\u03bb H, by simp [H], and.rec ext\u27e9\n\ndef of_real (r : \u211d) : \u2102 := \u27e8r, 0\u27e9\ninstance : has_coe \u211d \u2102 := \u27e8of_real\u27e9\n@[simp] lemma of_real_eq_coe (r : \u211d) : of_real r = r := rfl\n\n@[simp] lemma of_real_re (r : \u211d) : (r : \u2102).re = r := rfl\n@[simp] lemma of_real_im (r : \u211d) : (r : \u2102).im = 0 := rfl\n\n@[simp] theorem of_real_inj {z w : \u211d} : (z : \u2102) = w \u2194 z = w :=\n\u27e8congr_arg re, congr_arg _\u27e9\n\ninstance : has_zero \u2102 := \u27e8(0 : \u211d)\u27e9\ninstance : inhabited \u2102 := \u27e80\u27e9\n\n@[simp] lemma zero_re : (0 : \u2102).re = 0 := rfl\n@[simp] lemma zero_im : (0 : \u2102).im = 0 := rfl\n@[simp] lemma of_real_zero : ((0 : \u211d) : \u2102) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : \u211d} : (z : \u2102) = 0 \u2194 z = 0 := of_real_inj\n@[simp] theorem of_real_ne_zero {z : \u211d} : (z : \u2102) \u2260 0 \u2194 z \u2260 0 := not_congr of_real_eq_zero\n\ninstance : has_one \u2102 := \u27e8(1 : \u211d)\u27e9\n\n@[simp] lemma one_re : (1 : \u2102).re = 1 := rfl\n@[simp] lemma one_im : (1 : \u2102).im = 0 := rfl\n@[simp] lemma of_real_one : ((1 : \u211d) : \u2102) = 1 := rfl\n\ndef I : \u2102 := \u27e80, 1\u27e9\n\n@[simp] lemma I_re : I.re = 0 := rfl\n@[simp] lemma I_im : I.im = 1 := rfl\n\ninstance : has_add \u2102 := \u27e8\u03bb z w, \u27e8z.re + w.re, z.im + w.im\u27e9\u27e9\n\n@[simp] lemma add_re (z w : \u2102) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : \u2102) : (z + w).im = z.im + w.im := rfl\n@[simp] lemma of_real_add (r s : \u211d) : ((r + s : \u211d) : \u2102) = r + s := ext_iff.2 $ by simp\n\n@[simp] lemma of_real_bit0 (r : \u211d) : ((bit0 r : \u211d) : \u2102) = bit0 r := ext_iff.2 $ by simp [bit0]\n@[simp] lemma of_real_bit1 (r : \u211d) : ((bit1 r : \u211d) : \u2102) = bit1 r := ext_iff.2 $ by simp [bit1]\n\ninstance : has_neg \u2102 := \u27e8\u03bb z, \u27e8-z.re, -z.im\u27e9\u27e9\n\n@[simp] lemma neg_re (z : \u2102) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : \u2102) : (-z).im = -z.im := rfl\n@[simp] lemma of_real_neg (r : \u211d) : ((-r : \u211d) : \u2102) = -r := ext_iff.2 $ by simp\n\ninstance : has_mul \u2102 := \u27e8\u03bb z w, \u27e8z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re\u27e9\u27e9\n\n@[simp] lemma mul_re (z w : \u2102) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : \u2102) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp] lemma of_real_mul (r s : \u211d) : ((r * s : \u211d) : \u2102) = r * s := ext_iff.2 $ by simp\n\nlemma smul_re (r : \u211d) (z : \u2102) : (\u2191r * z).re = r * z.re := by simp\nlemma smul_im (r : \u211d) (z : \u2102) : (\u2191r * z).im = r * z.im := by simp\n\n@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp\n\nlemma I_ne_zero : (I : \u2102) \u2260 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : \u211d) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : \u2102) : (z.re : \u2102) + z.im * I = z :=\next_iff.2 $ by simp\n\ndef real_prod_equiv : \u2102 \u2243 (\u211d \u00d7 \u211d) :=\n{ to_fun := \u03bb z, \u27e8z.re, z.im\u27e9,\n  inv_fun := \u03bb p, \u27e8p.1, p.2\u27e9,\n  left_inv := \u03bb \u27e8x, y\u27e9, rfl,\n  right_inv := \u03bb \u27e8x, y\u27e9, rfl }\n\n@[simp] theorem real_prod_equiv_apply (z : \u2102) : real_prod_equiv z = (z.re, z.im) := rfl\ntheorem real_prod_equiv_symm_re (x y : \u211d) : (real_prod_equiv.symm (x, y)).re = x := rfl\ntheorem real_prod_equiv_symm_im (x y : \u211d) : (real_prod_equiv.symm (x, y)).im = y := rfl\n\ndef conj (z : \u2102) : \u2102 := \u27e8z.re, -z.im\u27e9\n\n@[simp] lemma conj_re (z : \u2102) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : \u2102) : (conj z).im = -z.im := rfl\n\n@[simp] lemma conj_of_real (r : \u211d) : conj r = r := ext_iff.2 $ by simp [conj]\n\n@[simp] lemma conj_zero : conj 0 = 0 := ext_iff.2 $ by simp [conj]\n@[simp] lemma conj_one : conj 1 = 1 := ext_iff.2 $ by simp\n@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp\n@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp\n\n@[simp] lemma conj_add (z w : \u2102) : conj (z + w) = conj z + conj w :=\next_iff.2 $ by simp\n\n@[simp] lemma conj_neg (z : \u2102) : conj (-z) = -conj z := rfl\n\n@[simp] lemma conj_mul (z w : \u2102) : conj (z * w) = conj z * conj w :=\next_iff.2 $ by simp\n\n@[simp] lemma conj_conj (z : \u2102) : conj (conj z) = z :=\next_iff.2 $ by simp\n\nlemma conj_bijective : function.bijective conj :=\n\u27e8function.injective_of_has_left_inverse \u27e8conj, conj_conj\u27e9,\n function.surjective_of_has_right_inverse \u27e8conj, conj_conj\u27e9\u27e9\n\nlemma conj_inj {z w : \u2102} : conj z = conj w \u2194 z = w :=\nconj_bijective.1.eq_iff\n\n@[simp] lemma conj_eq_zero {z : \u2102} : conj z = 0 \u2194 z = 0 :=\nby simpa using @conj_inj z 0\n\n@[simp] lemma eq_conj_iff_real (z : \u2102) : conj z = z \u2194 \u2203 r : \u211d, z = r :=\n\u27e8\u03bb h, \u27e8z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)\u27e9,\n \u03bb \u27e8h, e\u27e9, e.symm \u25b8 rfl\u27e9\n\ndef norm_sq (z : \u2102) : \u211d := z.re * z.re + z.im * z.im\n\n@[simp] lemma norm_sq_of_real (r : \u211d) : norm_sq r = r * r :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := by simp [norm_sq]\n@[simp] lemma norm_sq_one : norm_sq 1 = 1 := by simp [norm_sq]\n@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]\n\nlemma norm_sq_nonneg (z : \u2102) : 0 \u2264 norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\n@[simp] lemma norm_sq_eq_zero {z : \u2102} : norm_sq z = 0 \u2194 z = 0 :=\n\u27e8\u03bb h, ext\n  (eq_zero_of_mul_self_add_mul_self_eq_zero h)\n  (eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),\n \u03bb h, h.symm \u25b8 norm_sq_zero\u27e9\n\n@[simp] lemma norm_sq_pos {z : \u2102} : 0 < norm_sq z \u2194 z \u2260 0 :=\nby rw [lt_iff_le_and_ne, ne, eq_comm]; simp [norm_sq_nonneg]\n\n@[simp] lemma norm_sq_neg (z : \u2102) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : \u2102) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mul (z w : \u2102) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nby dsimp [norm_sq]; ring\n\nlemma norm_sq_add (z w : \u2102) : norm_sq (z + w) =\n  norm_sq z + norm_sq w + 2 * (z * conj w).re :=\nby dsimp [norm_sq]; ring\n\nlemma re_sq_le_norm_sq (z : \u2102) : z.re * z.re \u2264 norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : \u2102) : z.im * z.im \u2264 norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : \u2102) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm]\n\ntheorem add_conj (z : \u2102) : z + conj z = (2 * z.re : \u211d) :=\next_iff.2 $ by simp [two_mul]\n\ninstance : comm_ring \u2102 :=\nby refine { zero := 0, add := (+), neg := has_neg.neg, one := 1, mul := (*), ..};\n   { intros, apply ext_iff.2; split; simp; ring }\n\n@[simp] lemma bit0_re (z : \u2102) : (bit0 z).re = bit0 z.re := rfl\n@[simp] lemma bit1_re (z : \u2102) : (bit1 z).re = bit1 z.re := rfl\n@[simp] lemma bit0_im (z : \u2102) : (bit0 z).im = bit0 z.im := eq.refl _\n@[simp] lemma bit1_im (z : \u2102) : (bit1 z).im = bit0 z.im := add_zero _\n\n@[simp] lemma sub_re (z w : \u2102) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : \u2102) : (z - w).im = z.im - w.im := rfl\n@[simp] lemma of_real_sub (r s : \u211d) : ((r - s : \u211d) : \u2102) = r - s := ext_iff.2 $ by simp\n@[simp] lemma of_real_pow (r : \u211d) (n : \u2115) : ((r ^ n : \u211d) : \u2102) = r ^ n :=\nby induction n; simp [*, of_real_mul, pow_succ]\n\ntheorem sub_conj (z : \u2102) : z - conj z = (2 * z.im : \u211d) * I :=\next_iff.2 $ by simp [two_mul]\n\nlemma conj_pow (z : \u2102) (n : \u2115) : conj (z ^ n) = conj z ^ n :=\nby induction n; simp [*, conj_mul, pow_succ]\n\n@[simp] lemma conj_two : conj (2 : \u2102) = 2 := by apply complex.ext; simp\n\nlemma norm_sq_sub (z w : \u2102) : norm_sq (z - w) =\n  norm_sq z + norm_sq w - 2 * (z * conj w).re :=\nby rw [sub_eq_add_neg, norm_sq_add]; simp [-mul_re]\n\nnoncomputable instance : has_inv \u2102 := \u27e8\u03bb z, conj z * ((norm_sq z)\u207b\u00b9:\u211d)\u27e9\n\ntheorem inv_def (z : \u2102) : z\u207b\u00b9 = conj z * ((norm_sq z)\u207b\u00b9:\u211d) := rfl\n@[simp] lemma inv_re (z : \u2102) : (z\u207b\u00b9).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : \u2102) : (z\u207b\u00b9).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\n@[simp] lemma of_real_inv (r : \u211d) : ((r\u207b\u00b9 : \u211d) : \u2102) = r\u207b\u00b9 :=\next_iff.2 $ begin\n  simp,\n  by_cases r = 0, {simp [h]},\n  rw [\u2190 div_div_eq_div_mul, div_self h, one_div_eq_inv]\nend\n\nprotected \n\nprotected theorem mul_inv_cancel {z : \u2102} (h : z \u2260 0) : z * z\u207b\u00b9 = 1 :=\nby rw [inv_def, \u2190 mul_assoc, mul_conj, \u2190 of_real_mul,\n  mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]\n\nnoncomputable instance : discrete_field \u2102 :=\n{ inv := has_inv.inv,\n  zero_ne_one := mt (congr_arg re) zero_ne_one,\n  mul_inv_cancel := @complex.mul_inv_cancel,\n  inv_mul_cancel := \u03bb z h, by rw [mul_comm, complex.mul_inv_cancel h],\n  inv_zero := complex.inv_zero,\n  has_decidable_eq := classical.dec_eq _,\n  ..complex.comm_ring }\n\ninstance re.is_add_group_hom : is_add_group_hom complex.re :=\nby refine_struct {..}; simp\n\ninstance im.is_add_group_hom : is_add_group_hom complex.im :=\nby refine_struct {..}; simp\n\ninstance : is_ring_hom conj :=\nby refine_struct {..}; simp\n\ninstance of_real.is_ring_hom : is_ring_hom (coe : \u211d \u2192 \u2102) :=\nby refine_struct {..}; simp\n\n@[simp] lemma of_real_div (r s : \u211d) : ((r / s : \u211d) : \u2102) = r / s :=\nis_field_hom.map_div coe\n\n@[simp] lemma of_real_fpow (r : \u211d) (n : \u2124) : ((r ^ n : \u211d) : \u2102) = (r : \u2102) ^ n :=\nis_field_hom.map_fpow of_real r n\n\n@[simp] theorem of_real_int_cast : \u2200 n : \u2124, ((n : \u211d) : \u2102) = n :=\nint.eq_cast (\u03bb n, ((n : \u211d) : \u2102))\n  (by rw [int.cast_one, of_real_one])\n  (\u03bb _ _, by rw [int.cast_add, of_real_add])\n\n@[simp] theorem of_real_nat_cast (n : \u2115) : ((n : \u211d) : \u2102) = n :=\nby rw [\u2190 int.cast_coe_nat, of_real_int_cast]; refl\n\n@[simp] lemma conj_inv (z : \u2102) : conj z\u207b\u00b9 = (conj z)\u207b\u00b9 :=\nif h : z = 0 then by simp [h] else\n(domain.mul_left_inj (mt conj_eq_zero.1 h)).1 $\nby rw [\u2190 conj_mul]; simp [h, -conj_mul]\n\n@[simp] lemma conj_sub (z w : \u2102) : conj (z - w) = conj z - conj w :=\nby simp\n\n@[simp] lemma conj_div (z w : \u2102) : conj (z / w) = conj z / conj w :=\nby rw [division_def, conj_mul, conj_inv]; refl\n\n@[simp] lemma norm_sq_inv (z : \u2102) : norm_sq z\u207b\u00b9 = (norm_sq z)\u207b\u00b9 :=\nif h : z = 0 then by simp [h] else\n(domain.mul_left_inj (mt norm_sq_eq_zero.1 h)).1 $\nby rw [\u2190 norm_sq_mul]; simp [h, -norm_sq_mul]\n\n@[simp] lemma norm_sq_div (z w : \u2102) : norm_sq (z / w) = norm_sq z / norm_sq w :=\nby rw [division_def, norm_sq_mul, norm_sq_inv]; refl\n\ninstance char_zero_complex : char_zero \u2102 :=\nadd_group.char_zero_of_inj_zero $ \u03bb n h,\nby rwa [\u2190 of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h\n\n@[simp] theorem of_real_rat_cast : \u2200 n : \u211a, ((n : \u211d) : \u2102) = n :=\nby apply rat.eq_cast (\u03bb n, ((n : \u211d) : \u2102)); simp\n\ntheorem re_eq_add_conj (z : \u2102) : (z.re : \u2102) = (z + conj z) / 2 :=\nby rw [add_conj]; simp; rw [mul_div_cancel_left (z.re:\u2102) two_ne_zero']\n\n@[simp] lemma nat_cast_re (n : \u2115) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_nat_cast, of_real_re]\n\n@[simp] lemma nat_cast_im (n : \u2115) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_nat_cast, of_real_im]\n\n@[simp] lemma int_cast_re (n : \u2124) : (n : \u2102).re = n :=\nby rw [\u2190 of_real_int_cast, of_real_re]\n\n@[simp] lemma int_cast_im (n : \u2124) : (n : \u2102).im = 0 :=\nby rw [\u2190 of_real_int_cast, of_real_im]\n\n@[simp] lemma rat_cast_re (q : \u211a) : (q : \u2102).re = q :=\nby rw [\u2190 of_real_rat_cast, of_real_re]\n\n@[simp] lemma rat_cast_im (q : \u211a) : (q : \u2102).im = 0 :=\nby rw [\u2190 of_real_rat_cast, of_real_im]\n\nnoncomputable def abs (z : \u2102) : \u211d := (norm_sq z).sqrt\n\nlocal notation `abs'` := _root_.abs\n\n@[simp] lemma abs_of_real (r : \u211d) : abs r = abs' r :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : \u211d} (h : 0 \u2264 r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\n@[simp] lemma abs_of_nat (n : \u2115) : complex.abs n = n :=\ncalc complex.abs n = complex.abs (n:\u211d) : by rw [of_real_nat_cast]\n  ... = _ : abs_of_nonneg (nat.cast_nonneg n)\n\nlemma mul_self_abs (z : \u2102) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]\n@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]\n@[simp] lemma abs_I : abs I = 1 := by simp [abs]\n\n@[simp] lemma abs_two : abs 2 = 2 :=\ncalc abs 2 = abs (2 : \u211d) : by rw [of_real_bit0, of_real_one]\n... = (2 : \u211d) : abs_of_nonneg (by norm_num)\n\nlemma abs_nonneg (z : \u2102) : 0 \u2264 abs z :=\nreal.sqrt_nonneg _\n\n@[simp] lemma abs_eq_zero {z : \u2102} : abs z = 0 \u2194 z = 0 :=\n(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero\n\n@[simp] lemma abs_conj (z : \u2102) : abs (conj z) = abs z :=\nby simp [abs]\n\n@[simp] lemma abs_mul (z w : \u2102) : abs (z * w) = abs z * abs w :=\nby rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl\n\nlemma abs_re_le_abs (z : \u2102) : abs' z.re \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply re_sq_le_norm_sq\n\nlemma abs_im_le_abs (z : \u2102) : abs' z.im \u2264 abs z :=\nby rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),\n       abs_mul_abs_self, mul_self_abs];\n   apply im_sq_le_norm_sq\n\nlemma re_le_abs (z : \u2102) : z.re \u2264 abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : \u2102) : z.im \u2264 abs z :=\n(abs_le.1 (abs_im_le_abs _)).2\n\nlemma abs_add (z w : \u2102) : abs (z + w) \u2264 abs z + abs w :=\n(mul_self_le_mul_self_iff (abs_nonneg _)\n  (add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $\nbegin\n  rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,\n      add_right_comm, norm_sq_add, add_le_add_iff_left,\n      mul_assoc, mul_le_mul_left (@two_pos \u211d _)],\n  simpa [-mul_re] using re_le_abs (z * conj w)\nend\n\ninstance : is_absolute_value abs :=\n{ abv_nonneg  := abs_nonneg,\n  abv_eq_zero := \u03bb _, abs_eq_zero,\n  abv_add     := abs_add,\n  abv_mul     := abs_mul }\nopen is_absolute_value\n\n@[simp] lemma abs_abs (z : \u2102) : abs' (abs z) = abs z :=\n_root_.abs_of_nonneg (abs_nonneg _)\n\n@[simp] lemma abs_pos {z : \u2102} : 0 < abs z \u2194 z \u2260 0 := abv_pos abs\n@[simp] lemma abs_neg : \u2200 z, abs (-z) = abs z := abv_neg abs\nlemma abs_sub : \u2200 z w, abs (z - w) = abs (w - z) := abv_sub abs\nlemma abs_sub_le : \u2200 a b c, abs (a - c) \u2264 abs (a - b) + abs (b - c) := abv_sub_le abs\n@[simp] theorem abs_inv : \u2200 z, abs z\u207b\u00b9 = (abs z)\u207b\u00b9 := abv_inv abs\n@[simp] theorem abs_div : \u2200 z w, abs (z / w) = abs z / abs w := abv_div abs\nlemma abs_abs_sub_le_abs_sub : \u2200 z w, abs' (abs z - abs w) \u2264 abs (z - w) := abs_abv_sub_le_abv_sub abs\n\nlemma abs_le_abs_re_add_abs_im (z : \u2102) : abs z \u2264 abs' z.re + abs' z.im :=\nby simpa [re_add_im] using abs_add z.re (z.im * I)\n\nlemma abs_re_div_abs_le_one (z : \u2102) : abs' (z.re / z.abs) \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by rw [_root_.abs_div, abs_abs]; exact\n  div_le_of_le_mul (abs_pos.2 hz) (by rw mul_one; exact abs_re_le_abs _)\n\nlemma abs_im_div_abs_le_one (z : \u2102) : abs' (z.im / z.abs) \u2264 1 :=\nif hz : z = 0 then by simp [hz, zero_le_one]\nelse by rw [_root_.abs_div, abs_abs]; exact\n  div_le_of_le_mul (abs_pos.2 hz) (by rw mul_one; exact abs_im_le_abs _)\n\n@[simp] lemma abs_cast_nat (n : \u2115) : abs (n : \u2102) = n :=\nby rw [\u2190 of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]\n\nlemma norm_sq_eq_abs (x : \u2102) : norm_sq x = abs x ^ 2 :=\nby rw [abs, pow_two, real.mul_self_sqrt (norm_sq_nonneg _)]\n\ntheorem is_cau_seq_re (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).re) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)\n\ntheorem is_cau_seq_im (f : cau_seq \u2102 abs) : is_cau_seq abs' (\u03bb n, (f n).im) :=\n\u03bb \u03b5 \u03b50, (f.cauchy \u03b50).imp $ \u03bb i H j ij,\nlt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)\n\nnoncomputable def cau_seq_re (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_re f\u27e9\n\nnoncomputable def cau_seq_im (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_im f\u27e9\n\nlemma is_cau_seq_abs {f : \u2115 \u2192 \u2102} (hf : is_cau_seq abs f) :\n  is_cau_seq abs' (abs \u2218 f) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := hf \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9\n\nnoncomputable def lim_aux (f : cau_seq \u2102 abs) : \u2102 :=\n\u27e8cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)\u27e9\n\ntheorem equiv_lim_aux (f : cau_seq \u2102 abs) : f \u2248 cau_seq.const abs (lim_aux f) :=\n\u03bb \u03b5 \u03b50, (exists_forall_ge_and\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_re f\u27e9 _ (half_pos \u03b50))\n  (cau_seq.equiv_lim \u27e8_, is_cau_seq_im f\u27e9 _ (half_pos \u03b50))).imp $\n\u03bb i H j ij, begin\n  cases H _ ij with H\u2081 H\u2082,\n  apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),\n  dsimp [lim_aux] at *,\n  have := add_lt_add H\u2081 H\u2082,\n  rwa add_halves at this,\nend\n\nnoncomputable instance : cau_seq.is_complete \u2102 abs :=\n\u27e8\u03bb f, \u27e8lim_aux f, equiv_lim_aux f\u27e9\u27e9\n\nopen cau_seq\n\nlemma lim_eq_lim_im_add_lim_re (f : cau_seq \u2102 abs) : lim f =\n  \u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I :=\nlim_eq_of_equiv_const $\ncalc f \u2248 _ : equiv_lim_aux f\n... = cau_seq.const abs (\u2191(lim (cau_seq_re f)) + \u2191(lim (cau_seq_im f)) * I) :\n  cau_seq.ext (\u03bb _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))\n\nlemma lim_re (f : cau_seq \u2102 abs) : lim (cau_seq_re f) = (lim f).re :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma lim_im (f : cau_seq \u2102 abs) : lim (cau_seq_im f) = (lim f).im :=\nby rw [lim_eq_lim_im_add_lim_re]; simp\n\nlemma is_cau_seq_conj (f : cau_seq \u2102 abs) : is_cau_seq abs (\u03bb n, conj (f n)) :=\n\u03bb \u03b5 \u03b50, let \u27e8i, hi\u27e9 := f.2 \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, by rw [\u2190 conj_sub, abs_conj]; exact hi j hj\u27e9\n\nnoncomputable def cau_seq_conj (f : cau_seq \u2102 abs) : cau_seq \u2102 abs := \u27e8_, is_cau_seq_conj f\u27e9\n\nlemma lim_conj (f : cau_seq \u2102 abs) : lim (cau_seq_conj f) = conj (lim f) :=\ncomplex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])\n  (by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)\n\nnoncomputable def cau_seq_abs (f : cau_seq \u2102 abs) : cau_seq \u211d abs' :=\n\u27e8_, is_cau_seq_abs f.2\u27e9\n\nlemma lim_abs (f : cau_seq \u2102 abs) : lim (cau_seq_abs f) = abs (lim f) :=\nlim_eq_of_equiv_const (\u03bb \u03b5 \u03b50,\nlet \u27e8i, hi\u27e9 := equiv_lim f \u03b5 \u03b50 in\n\u27e8i, \u03bb j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)\u27e9)\n\nend complex\n", "meta": {"author": "digama0", "repo": "mathlib-ITP2019", "sha": "5cbd0362e04e671ef5db1284870592af6950197c", "save_path": "github-repos/lean/digama0-mathlib-ITP2019", "path": "github-repos/lean/digama0-mathlib-ITP2019/mathlib-ITP2019-5cbd0362e04e671ef5db1284870592af6950197c/src/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7017066609726246}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Yury Kudryashov, S\u00e9bastien Gou\u00ebzel\n-/\nimport measure_theory.constructions.borel_space\n\n/-!\n# Stieltjes measures on the real line\n\nConsider a function `f : \u211d \u2192 \u211d` which is monotone and right-continuous. Then one can define a\ncorrresponding measure, giving mass `f b - f a` to the interval `(a, b]`.\n\n## Main definitions\n\n* `stieltjes_function` is a structure containing a function from `\u211d \u2192 \u211d`, together with the\nassertions that it is monotone and right-continuous. To `f : stieltjes_function`, one associates\na Borel measure `f.measure`.\n* `f.left_lim x` is the limit of `f` to the left of `x`.\n* `f.measure_Ioc` asserts that `f.measure (Ioc a b) = of_real (f b - f a)`\n* `f.measure_Ioo` asserts that `f.measure (Ioo a b) = of_real (f.left_lim b - f a)`.\n* `f.measure_Icc` and `f.measure_Ico` are analogous.\n-/\n\nnoncomputable theory\nopen classical set filter\nopen ennreal (of_real)\nopen_locale big_operators ennreal nnreal topological_space\n\n/-! ### Basic properties of Stieltjes functions -/\n\n/-- Bundled monotone right-continuous real functions, used to construct Stieltjes measures. -/\nstructure stieltjes_function :=\n(to_fun : \u211d \u2192 \u211d)\n(mono' : monotone to_fun)\n(right_continuous' : \u2200 x, continuous_within_at to_fun (Ici x) x)\n\nnamespace stieltjes_function\n\ninstance : has_coe_to_fun stieltjes_function (\u03bb _, \u211d \u2192 \u211d) := \u27e8to_fun\u27e9\n\ninitialize_simps_projections stieltjes_function (to_fun \u2192 apply)\n\nvariable (f : stieltjes_function)\n\nlemma mono : monotone f := f.mono'\n\nlemma right_continuous (x : \u211d) : continuous_within_at f (Ici x) x := f.right_continuous' x\n\n/-- The limit of a Stieltjes function to the left of `x` (it exists by monotonicity). The fact that\nit is indeed a left limit is asserted in `tendsto_left_lim` -/\n@[irreducible] def left_lim (x : \u211d) := Sup (f '' (Iio x))\n\nlemma tendsto_left_lim (x : \u211d) : tendsto f (\ud835\udcdd[<] x) (\ud835\udcdd (f.left_lim x)) :=\nby { rw left_lim, exact f.mono.tendsto_nhds_within_Iio x }\n\nlemma left_lim_le {x y : \u211d} (h : x \u2264 y) : f.left_lim x \u2264 f y :=\nbegin\n  apply le_of_tendsto (f.tendsto_left_lim x),\n  filter_upwards [self_mem_nhds_within] with _ hz using (f.mono (le_of_lt hz)).trans (f.mono h),\nend\n\nlemma le_left_lim {x y : \u211d} (h : x < y) : f x \u2264 f.left_lim y :=\nbegin\n  apply ge_of_tendsto (f.tendsto_left_lim y),\n  apply mem_nhds_within_Iio_iff_exists_Ioo_subset.2 \u27e8x, h, _\u27e9,\n  assume z hz,\n  exact f.mono hz.1.le,\nend\n\nlemma left_lim_le_left_lim {x y : \u211d} (h : x \u2264 y) : f.left_lim x \u2264 f.left_lim y :=\nbegin\n  rcases eq_or_lt_of_le h with rfl|hxy,\n  { exact le_rfl },\n  { exact (f.left_lim_le le_rfl).trans (f.le_left_lim hxy) }\nend\n\n/-- The identity of `\u211d` as a Stieltjes function, used to construct Lebesgue measure. -/\n@[simps] protected def id : stieltjes_function :=\n{ to_fun := id,\n  mono' := \u03bb x y, id,\n  right_continuous' := \u03bb x, continuous_within_at_id }\n\n@[simp] lemma id_left_lim (x : \u211d) : stieltjes_function.id.left_lim x = x :=\ntendsto_nhds_unique (stieltjes_function.id.tendsto_left_lim x) $\n  (continuous_at_id).tendsto.mono_left nhds_within_le_nhds\n\ninstance : inhabited stieltjes_function := \u27e8stieltjes_function.id\u27e9\n\n/-! ### The outer measure associated to a Stieltjes function -/\n\n/-- Length of an interval. This is the largest monotone function which correctly measures all\nintervals. -/\ndef length (s : set \u211d) : \u211d\u22650\u221e := \u2a05a b (h : s \u2286 Ioc a b), of_real (f b - f a)\n\n@[simp] lemma length_empty : f.length \u2205 = 0 :=\nnonpos_iff_eq_zero.1 $ infi_le_of_le 0 $ infi_le_of_le 0 $ by simp\n\n@[simp] lemma length_Ioc (a b : \u211d) :\n  f.length (Ioc a b) = of_real (f b - f a) :=\nbegin\n  refine le_antisymm (infi_le_of_le a $ binfi_le b (subset.refl _))\n    (le_infi $ \u03bb a', le_infi $ \u03bb b', le_infi $ \u03bb h, ennreal.coe_le_coe.2 _),\n  cases le_or_lt b a with ab ab,\n  { rw real.to_nnreal_of_nonpos (sub_nonpos.2 (f.mono ab)), apply zero_le, },\n  cases (Ioc_subset_Ioc_iff ab).1 h with h\u2081 h\u2082,\n  exact real.to_nnreal_le_to_nnreal (sub_le_sub (f.mono h\u2081) (f.mono h\u2082))\nend\n\nlemma length_mono {s\u2081 s\u2082 : set \u211d} (h : s\u2081 \u2286 s\u2082) :\n  f.length s\u2081 \u2264 f.length s\u2082 :=\ninfi_le_infi $ \u03bb a, infi_le_infi $ \u03bb b, infi_le_infi2 $ \u03bb h', \u27e8subset.trans h h', le_rfl\u27e9\n\nopen measure_theory\n\n/-- The Stieltjes outer measure associated to a Stieltjes function. -/\nprotected def outer : outer_measure \u211d :=\nouter_measure.of_function f.length f.length_empty\n\nlemma outer_le_length (s : set \u211d) : f.outer s \u2264 f.length s :=\nouter_measure.of_function_le _\n\n/-- If a compact interval `[a, b]` is covered by a union of open interval `(c i, d i)`, then\n`f b - f a \u2264 \u2211 f (d i) - f (c i)`. This is an auxiliary technical statement to prove the same\nstatement for half-open intervals, the point of the current statement being that one can use\ncompactness to reduce it to a finite sum, and argue by induction on the size of the covering set. -/\nlemma length_subadditive_Icc_Ioo {a b : \u211d} {c d : \u2115 \u2192 \u211d}\n  (ss : Icc a b \u2286 \u22c3 i, Ioo (c i) (d i)) :\n  of_real (f b - f a) \u2264 \u2211' i, of_real (f (d i) - f (c i)) :=\nbegin\n  suffices : \u2200 (s:finset \u2115) b\n    (cv : Icc a b \u2286 \u22c3 i \u2208 (\u2191s:set \u2115), Ioo (c i) (d i)),\n    (of_real (f b - f a) : \u211d\u22650\u221e) \u2264 \u2211 i in s, of_real (f (d i) - f (c i)),\n  { rcases is_compact_Icc.elim_finite_subcover_image (\u03bb (i : \u2115) (_ : i \u2208 univ),\n      @is_open_Ioo _ _ _ _ (c i) (d i)) (by simpa using ss) with \u27e8s, su, hf, hs\u27e9,\n    have e : (\u22c3 i \u2208 (\u2191hf.to_finset:set \u2115), Ioo (c i) (d i)) = (\u22c3 i \u2208 s, Ioo (c i) (d i)),\n      by simp only [ext_iff, exists_prop, finset.set_bUnion_coe, mem_Union, forall_const, iff_self,\n                    finite.mem_to_finset],\n    rw ennreal.tsum_eq_supr_sum,\n    refine le_trans _ (le_supr _ hf.to_finset),\n    exact this hf.to_finset _ (by simpa only [e]) },\n  clear ss b,\n  refine \u03bb s, finset.strong_induction_on s (\u03bb s IH b cv, _),\n  cases le_total b a with ab ab,\n  { rw ennreal.of_real_eq_zero.2 (sub_nonpos.2 (f.mono ab)), exact zero_le _, },\n  have := cv \u27e8ab, le_rfl\u27e9, simp at this,\n  rcases this with \u27e8i, is, cb, bd\u27e9,\n  rw [\u2190 finset.insert_erase is] at cv \u22a2,\n  rw [finset.coe_insert, bUnion_insert] at cv,\n  rw [finset.sum_insert (finset.not_mem_erase _ _)],\n  refine le_trans _ (add_le_add_left (IH _ (finset.erase_ssubset is) (c i) _) _),\n  { refine le_trans (ennreal.of_real_le_of_real _) ennreal.of_real_add_le,\n    rw sub_add_sub_cancel,\n    exact sub_le_sub_right (f.mono bd.le) _ },\n  { rintro x \u27e8h\u2081, h\u2082\u27e9,\n    refine (cv \u27e8h\u2081, le_trans h\u2082 (le_of_lt cb)\u27e9).resolve_left\n      (mt and.left (not_lt_of_le h\u2082)) }\nend\n\n@[simp] lemma outer_Ioc (a b : \u211d) :\n  f.outer (Ioc a b) = of_real (f b - f a) :=\nbegin\n  /- It suffices to show that, if `(a, b]` is covered by sets `s i`, then `f b - f a` is bounded\n  by `\u2211 f.length (s i) + \u03b5`. The difficulty is that `f.length` is expressed in terms of half-open\n  intervals, while we would like to have a compact interval covered by open intervals to use\n  compactness and finite sums, as provided by `length_subadditive_Icc_Ioo`. The trick is to use the\n  right-continuity of `f`. If `a'` is close enough to `a` on its right, then `[a', b]` is still\n  covered by the sets `s i` and moreover `f b - f a'` is very close to `f b - f a` (up to `\u03b5/2`).\n  Also, by definition one can cover `s i` by a half-closed interval `(p i, q i]` with `f`-length\n  very close to  that of `s i` (within a suitably small `\u03b5' i`, say). If one moves `q i` very\n  slightly to the right, then the `f`-length will change very little by right continuity, and we\n  will get an open interval `(p i, q' i)` covering `s i` with `f (q' i) - f (p i)` within `\u03b5' i`\n  of the `f`-length of `s i`. -/\n  refine le_antisymm (by { rw \u2190 f.length_Ioc, apply outer_le_length })\n    (le_binfi $ \u03bb s hs, ennreal.le_of_forall_pos_le_add $ \u03bb \u03b5 \u03b5pos h, _),\n  let \u03b4 := \u03b5 / 2,\n  have \u03b4pos : 0 < (\u03b4 : \u211d\u22650\u221e), by simpa using \u03b5pos.ne',\n  rcases ennreal.exists_pos_sum_of_encodable \u03b4pos.ne' \u2115 with \u27e8\u03b5', \u03b5'0, h\u03b5\u27e9,\n  obtain \u27e8a', ha', aa'\u27e9 : \u2203 a', f a' - f a < \u03b4 \u2227 a < a',\n  { have A : continuous_within_at (\u03bb r, f r - f a) (Ioi a) a,\n    { refine continuous_within_at.sub _ continuous_within_at_const,\n      exact (f.right_continuous a).mono Ioi_subset_Ici_self },\n    have B : f a - f a < \u03b4, by rwa [sub_self, nnreal.coe_pos, \u2190 ennreal.coe_pos],\n    exact (((tendsto_order.1 A).2 _ B).and self_mem_nhds_within).exists },\n  have : \u2200 i, \u2203 p:\u211d\u00d7\u211d, s i \u2286 Ioo p.1 p.2 \u2227\n                        (of_real (f p.2 - f p.1) : \u211d\u22650\u221e) < f.length (s i) + \u03b5' i,\n  { intro i,\n    have := (ennreal.lt_add_right ((ennreal.le_tsum i).trans_lt h).ne\n        (ennreal.coe_ne_zero.2 (\u03b5'0 i).ne')),\n    conv at this { to_lhs, rw length },\n    simp only [infi_lt_iff, exists_prop] at this,\n    rcases this with \u27e8p, q', spq, hq'\u27e9,\n    have : continuous_within_at (\u03bb r, of_real (f r - f p)) (Ioi q') q',\n    { apply ennreal.continuous_of_real.continuous_at.comp_continuous_within_at,\n      refine continuous_within_at.sub _ continuous_within_at_const,\n      exact (f.right_continuous q').mono Ioi_subset_Ici_self },\n    rcases (((tendsto_order.1 this).2 _ hq').and self_mem_nhds_within).exists with \u27e8q, hq, q'q\u27e9,\n    exact \u27e8\u27e8p, q\u27e9, spq.trans (Ioc_subset_Ioo_right q'q), hq\u27e9 },\n  choose g hg using this,\n  have I_subset : Icc a' b \u2286 \u22c3 i, Ioo (g i).1 (g i).2 := calc\n    Icc a' b \u2286 Ioc a b : \u03bb x hx, \u27e8aa'.trans_le hx.1, hx.2\u27e9\n    ... \u2286 \u22c3 i, s i : hs\n    ... \u2286 \u22c3 i, Ioo (g i).1 (g i).2 : Union_mono (\u03bb i, (hg i).1),\n  calc of_real (f b - f a)\n      = of_real ((f b - f a') + (f a' - f a)) : by rw sub_add_sub_cancel\n  ... \u2264 of_real (f b - f a') + of_real (f a' - f a) : ennreal.of_real_add_le\n  ... \u2264 (\u2211' i, of_real (f (g i).2 - f (g i).1)) + of_real \u03b4 :\n    add_le_add (f.length_subadditive_Icc_Ioo I_subset) (ennreal.of_real_le_of_real ha'.le)\n  ... \u2264 (\u2211' i, (f.length (s i) + \u03b5' i)) + \u03b4 :\n    add_le_add (ennreal.tsum_le_tsum (\u03bb i, (hg i).2.le))\n      (by simp only [ennreal.of_real_coe_nnreal, le_rfl])\n  ... = (\u2211' i, f.length (s i)) + (\u2211' i, \u03b5' i) + \u03b4 : by rw [ennreal.tsum_add]\n  ... \u2264 (\u2211' i, f.length (s i)) + \u03b4 + \u03b4 : add_le_add (add_le_add le_rfl h\u03b5.le) le_rfl\n  ... = \u2211' (i : \u2115), f.length (s i) + \u03b5 : by simp [add_assoc, ennreal.add_halves]\nend\n\nlemma measurable_set_Ioi {c : \u211d} :\n  f.outer.caratheodory.measurable_set' (Ioi c) :=\nbegin\n  apply outer_measure.of_function_caratheodory (\u03bb t, _),\n  refine le_infi (\u03bb a, le_infi (\u03bb b, le_infi (\u03bb h, _))),\n  refine le_trans (add_le_add\n    (f.length_mono $ inter_subset_inter_left _ h)\n    (f.length_mono $ diff_subset_diff_left h)) _,\n  cases le_total a c with hac hac; cases le_total b c with hbc hbc,\n  { simp only [Ioc_inter_Ioi, f.length_Ioc, hac, sup_eq_max, hbc, le_refl, Ioc_eq_empty,\n      max_eq_right, min_eq_left, Ioc_diff_Ioi, f.length_empty, zero_add, not_lt] },\n  { simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right,\n      sup_eq_max, \u2190ennreal.of_real_add, f.mono hac, f.mono hbc, sub_nonneg, sub_add_sub_cancel,\n      le_refl, max_eq_right] },\n  { simp only [hbc, le_refl, Ioc_eq_empty, Ioc_inter_Ioi, min_eq_left, Ioc_diff_Ioi,\n      f.length_empty, zero_add, or_true, le_sup_iff, f.length_Ioc, not_lt] },\n  { simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right,\n      sup_eq_max, le_refl, Ioc_eq_empty, add_zero, max_eq_left, f.length_empty, not_lt] }\nend\n\ntheorem outer_trim : f.outer.trim = f.outer :=\nbegin\n  refine le_antisymm (\u03bb s, _) (outer_measure.le_trim _),\n  rw outer_measure.trim_eq_infi,\n  refine le_infi (\u03bb t, le_infi $ \u03bb ht,\n    ennreal.le_of_forall_pos_le_add $ \u03bb \u03b5 \u03b50 h, _),\n  rcases ennreal.exists_pos_sum_of_encodable\n    (ennreal.coe_pos.2 \u03b50).ne' \u2115 with \u27e8\u03b5', \u03b5'0, h\u03b5\u27e9,\n  refine le_trans _ (add_le_add_left (le_of_lt h\u03b5) _),\n  rw \u2190 ennreal.tsum_add,\n  choose g hg using show\n    \u2200 i, \u2203 s, t i \u2286 s \u2227 measurable_set s \u2227\n      f.outer s \u2264 f.length (t i) + of_real (\u03b5' i),\n  { intro i,\n    have := (ennreal.lt_add_right ((ennreal.le_tsum i).trans_lt h).ne\n        (ennreal.coe_pos.2 (\u03b5'0 i)).ne'),\n    conv at this {to_lhs, rw length},\n    simp only [infi_lt_iff] at this,\n    rcases this with \u27e8a, b, h\u2081, h\u2082\u27e9,\n    rw \u2190 f.outer_Ioc at h\u2082,\n    exact \u27e8_, h\u2081, measurable_set_Ioc, le_of_lt $ by simpa using h\u2082\u27e9 },\n  simp at hg,\n  apply infi_le_of_le (Union g) _,\n  apply infi_le_of_le (ht.trans $ Union_mono (\u03bb i, (hg i).1)) _,\n  apply infi_le_of_le (measurable_set.Union (\u03bb i, (hg i).2.1)) _,\n  exact le_trans (f.outer.Union _) (ennreal.tsum_le_tsum $ \u03bb i, (hg i).2.2)\nend\n\nlemma borel_le_measurable : borel \u211d \u2264 f.outer.caratheodory :=\nbegin\n  rw borel_eq_generate_from_Ioi,\n  refine measurable_space.generate_from_le _,\n  simp [f.measurable_set_Ioi] { contextual := tt }\nend\n\n/-! ### The measure associated to a Stieltjes function -/\n\n/-- The measure associated to a Stieltjes function, giving mass `f b - f a` to the\ninterval `(a, b]`. -/\n@[irreducible] protected def measure : measure \u211d :=\n{ to_outer_measure := f.outer,\n  m_Union := \u03bb s hs, f.outer.Union_eq_of_caratheodory $\n    \u03bb i, f.borel_le_measurable _ (hs i),\n  trimmed := f.outer_trim }\n\n@[simp] lemma measure_Ioc (a b : \u211d) : f.measure (Ioc a b) = of_real (f b - f a) :=\nby { rw stieltjes_function.measure, exact f.outer_Ioc a b }\n\n@[simp] lemma measure_singleton (a : \u211d) : f.measure {a} = of_real (f a - f.left_lim a) :=\nbegin\n  obtain \u27e8u, u_mono, u_lt_a, u_lim\u27e9 : \u2203 (u : \u2115 \u2192 \u211d), strict_mono u \u2227 (\u2200 (n : \u2115), u n < a)\n    \u2227 tendsto u at_top (\ud835\udcdd a) := exists_seq_strict_mono_tendsto a,\n  have A : {a} = \u22c2 n, Ioc (u n) a,\n  { refine subset.antisymm (\u03bb x hx, by simp [mem_singleton_iff.1 hx, u_lt_a]) (\u03bb x hx, _),\n    simp at hx,\n    have : a \u2264 x := le_of_tendsto' u_lim (\u03bb n, (hx n).1.le),\n    simp [le_antisymm this (hx 0).2] },\n  have L1 : tendsto (\u03bb n, f.measure (Ioc (u n) a)) at_top (\ud835\udcdd (f.measure {a})),\n  { rw A,\n    refine tendsto_measure_Inter (\u03bb n, measurable_set_Ioc) (\u03bb m n hmn, _) _,\n    { exact Ioc_subset_Ioc (u_mono.monotone hmn) le_rfl },\n    { exact \u27e80, by simpa only [measure_Ioc] using ennreal.of_real_ne_top\u27e9 } },\n  have L2 : tendsto (\u03bb n, f.measure (Ioc (u n) a)) at_top (\ud835\udcdd (of_real (f a - f.left_lim a))),\n  { simp only [measure_Ioc],\n    have : tendsto (\u03bb n, f (u n)) at_top (\ud835\udcdd (f.left_lim a)),\n    { apply (f.tendsto_left_lim a).comp,\n      exact tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ u_lim\n        (eventually_of_forall (\u03bb n, u_lt_a n)) },\n    exact ennreal.continuous_of_real.continuous_at.tendsto.comp (tendsto_const_nhds.sub this) },\n  exact tendsto_nhds_unique L1 L2\nend\n\n@[simp] lemma measure_Icc (a b : \u211d) : f.measure (Icc a b) = of_real (f b - f.left_lim a) :=\nbegin\n  rcases le_or_lt a b with hab|hab,\n  { have A : disjoint {a} (Ioc a b), by simp,\n    simp [\u2190 Icc_union_Ioc_eq_Icc le_rfl hab, -singleton_union, \u2190 ennreal.of_real_add, f.left_lim_le,\n      measure_union A measurable_set_Ioc, f.mono hab] },\n  { simp only [hab, measure_empty, Icc_eq_empty, not_le],\n    symmetry,\n    simp [ennreal.of_real_eq_zero, f.le_left_lim hab] }\nend\n\n@[simp] lemma measure_Ioo {a b : \u211d} : f.measure (Ioo a b) = of_real (f.left_lim b - f a) :=\nbegin\n  rcases le_or_lt b a with hab|hab,\n  { simp only [hab, measure_empty, Ioo_eq_empty, not_lt],\n    symmetry,\n    simp [ennreal.of_real_eq_zero, f.left_lim_le hab] },\n  { have A : disjoint (Ioo a b) {b}, by simp,\n    have D : f b - f a = (f b - f.left_lim b) + (f.left_lim b - f a), by abel,\n    have := f.measure_Ioc a b,\n    simp only [\u2190Ioo_union_Icc_eq_Ioc hab le_rfl, measure_singleton,\n      measure_union A (measurable_set_singleton b), Icc_self] at this,\n    rw [D, ennreal.of_real_add, add_comm] at this,\n    { simpa only [ennreal.add_right_inj ennreal.of_real_ne_top] },\n    { simp only [f.left_lim_le, sub_nonneg] },\n    { simp only [f.le_left_lim hab, sub_nonneg] } },\nend\n\n@[simp] \n\nend stieltjes_function\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/measure_theory/measure/stieltjes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7017066549469235}}
{"text": "-- Teorema_de_Cantor.lean\n-- Teorema de Cantor\n-- Jos\u00e9 A. Alonso Jim\u00e9nez <https://jaalonso.github.io>\n-- Sevilla, 4-mayo-2022\n-- ---------------------------------------------------------------------\n\nimport data.set.basic\nimport set_theory.cardinal.basic\n\nopen set\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\ntheorem cantor_injective\n  {\u03b1 : Type} (f : set \u03b1 \u2192 \u03b1) :\n  \u00acfunction.injective f :=\nbegin\n  set B := {x : set \u03b1 | f x \u2209 x},\n  set B' := {y : \u03b1 | \u2203 x : set \u03b1, f x = y \u2227 x \u2208 B},\n  by_contradiction h,\n  by_cases hp : f(B') \u2208 B',\n  { have : \u2203 X, f(X) = f(B') \u2227 f(X) \u2209 X := mem_set_of_eq.mp hp,\n    cases this with s hs,\n    rw \u2190 (h hs.1) at hp,\n    have hp' := hs.2,\n    contradiction, },\n  { have : f(B') \u2208 B',\n    { rw mem_set_of_eq,\n      use B',\n      split,\n      { refl, },\n      { rw mem_set_of_eq,\n        exact hp, }, },\n    contradiction, },\nend\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\ntheorem cantor_injective2\n  {\u03b1 : Type}\n  (f : set \u03b1 \u2192 \u03b1)\n  : \u00acfunction.injective f :=\nbegin\n  set B := {x : set \u03b1 | f x \u2209 x},\n  set B' := {y : \u03b1 | \u2203 x : set \u03b1, f x = y \u2227 x \u2208 B},\n  intro h,\n  by_cases hp : f B' \u2208 B',\n  { obtain \u27e8s, hs\u27e9 : \u2203 X, f X = f B' \u2227 f X \u2209 X := set.mem_set_of_eq.mp hp,\n    rw \u2190 (h hs.1) at hp,\n    exact hs.2 hp, },\n  { exact hp \u27e8B', rfl, hp\u27e9, }\nend\n\n-- 2\u00aa teorema\n-- ==========\n\ntheorem cantor_surjective'\n  {\u03b1 : Type}\n  (f : \u03b1 \u2192 set \u03b1)\n  : \u00acfunction.surjective f :=\nbegin\n  set B := {x : \u03b1 | x \u2209 f x},\n  by_contradiction,\n  obtain \u27e8\u03be, fx\u27e9 : \u2203 \u03be, f \u03be = B := h B,\n  have : \u03be \u2208 B \u2194 \u03be \u2209 f(\u03be),\n  { exact mem_def, },\n  { rw fx at this,\n    exact (iff_not_self (\u03be \u2208 B)).mp this, },\nend\n", "meta": {"author": "jaalonso", "repo": "Demostraciones-con-Lean", "sha": "034ee559250cf55e28d10d8e65f1a4642e284251", "save_path": "github-repos/lean/jaalonso-Demostraciones-con-Lean", "path": "github-repos/lean/jaalonso-Demostraciones-con-Lean/Demostraciones-con-Lean-034ee559250cf55e28d10d8e65f1a4642e284251/src/Teorema_de_Cantor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7017066421369116}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov\n-/\nimport linear_algebra.span\n\n/-!\n# Quotients by submodules\n\n* If `p` is a submodule of `M`, `M \u29f8 p` is the quotient of `M` with respect to `p`:\n  that is, elements of `M` are identified if their difference is in `p`. This is itself a module.\n\n-/\n\n-- For most of this file we work over a noncommutative ring\nsection ring\n\nnamespace submodule\n\nvariables {R M : Type*} {r : R} {x y : M} [ring R] [add_comm_group M] [module R M]\nvariables (p p' : submodule R M)\n\nopen linear_map\n\n/-- The equivalence relation associated to a submodule `p`, defined by `x \u2248 y` iff `-x + y \u2208 p`.\n\nNote this is equivalent to `y - x \u2208 p`, but defined this way to be be defeq to the `add_subgroup`\nversion, where commutativity can't be assumed. -/\ndef quotient_rel : setoid M :=\nquotient_add_group.left_rel p.to_add_subgroup\n\nlemma quotient_rel_r_def {x y : M} : @setoid.r _ (p.quotient_rel) x y \u2194 x - y \u2208 p :=\niff.trans (by { rw [sub_eq_add_neg, neg_add, neg_neg], refl }) neg_mem_iff\n\n/-- The quotient of a module `M` by a submodule `p \u2286 M`. -/\ninstance has_quotient : has_quotient M (submodule R M) := \u27e8\u03bb p, quotient (quotient_rel p)\u27e9\n\nnamespace quotient\n\n/-- Map associating to an element of `M` the corresponding element of `M/p`,\nwhen `p` is a submodule of `M`. -/\ndef mk {p : submodule R M} : M \u2192 M \u29f8 p := quotient.mk'\n\n@[simp] theorem mk_eq_mk {p : submodule R M} (x : M) :\n  (@_root_.quotient.mk _ (quotient_rel p) x) = mk x := rfl\n@[simp] theorem mk'_eq_mk {p : submodule R M} (x : M) : (quotient.mk' x : M \u29f8 p) = mk x := rfl\n@[simp] theorem quot_mk_eq_mk {p : submodule R M} (x : M) : (quot.mk _ x : M \u29f8 p) = mk x := rfl\n\nprotected theorem eq' {x y : M} : (mk x : M \u29f8 p) = mk y \u2194 -x + y \u2208 p := quotient.eq'\n\nprotected theorem eq {x y : M} : (mk x : M \u29f8 p) = mk y \u2194 x - y \u2208 p :=\n(p^.quotient.eq').trans p.quotient_rel_r_def\n\ninstance : has_zero (M \u29f8 p) := \u27e8mk 0\u27e9\ninstance : inhabited (M \u29f8 p) := \u27e80\u27e9\n\n@[simp] theorem mk_zero : mk 0 = (0 : M \u29f8 p) := rfl\n\n@[simp] theorem mk_eq_zero : (mk x : M \u29f8 p) = 0 \u2194 x \u2208 p :=\nby simpa using (quotient.eq p : mk x = 0 \u2194 _)\n\ninstance add_comm_group : add_comm_group (M \u29f8 p) :=\nquotient_add_group.add_comm_group p.to_add_subgroup\n\n@[simp] theorem mk_add : (mk (x + y) : M \u29f8 p) = mk x + mk y := rfl\n\n@[simp] theorem mk_neg : (mk (-x) : M \u29f8 p) = -mk x := rfl\n\n@[simp] theorem mk_sub : (mk (x - y) : M \u29f8 p) = mk x - mk y := rfl\n\nsection has_scalar\n\nvariables {S : Type*} [has_scalar S R] [has_scalar S M] [is_scalar_tower S R M] (P : submodule R M)\n\ninstance has_scalar' : has_scalar S (M \u29f8 P) :=\n\u27e8\u03bb a, quotient.map' ((\u2022) a) $ \u03bb x y h, by simpa [smul_sub] using P.smul_mem (a \u2022 1 : R) h\u27e9\n\n/-- Shortcut to help the elaborator in the common case. -/\ninstance has_scalar : has_scalar R (M \u29f8 P) :=\nquotient.has_scalar' P\n\n@[simp] theorem mk_smul (r : S) (x : M) : (mk (r \u2022 x) : M \u29f8 p) = r \u2022 mk x := rfl\n\ninstance smul_comm_class (T : Type*) [has_scalar T R] [has_scalar T M] [is_scalar_tower T R M]\n  [smul_comm_class S T M] : smul_comm_class S T (M \u29f8 P) :=\n{ smul_comm := \u03bb x y, quotient.ind' $ by exact \u03bb z, congr_arg mk (smul_comm _ _ _) }\n\ninstance is_scalar_tower (T : Type*) [has_scalar T R] [has_scalar T M] [is_scalar_tower T R M]\n  [has_scalar S T] [is_scalar_tower S T M] : is_scalar_tower S T (M \u29f8 P) :=\n{ smul_assoc := \u03bb x y, quotient.ind' $ by exact \u03bb z, congr_arg mk (smul_assoc _ _ _) }\n\ninstance is_central_scalar [has_scalar S\u1d50\u1d52\u1d56 R] [has_scalar S\u1d50\u1d52\u1d56 M] [is_scalar_tower S\u1d50\u1d52\u1d56 R M]\n  [is_central_scalar S M] : is_central_scalar S (M \u29f8 P) :=\n{ op_smul_eq_smul := \u03bb x, quotient.ind' $ by exact \u03bb z, congr_arg mk $ op_smul_eq_smul _ _ }\n\nend has_scalar\n\nsection module\n\nvariables {S : Type*}\n\ninstance mul_action' [monoid S] [has_scalar S R] [mul_action S M] [is_scalar_tower S R M]\n  (P : submodule R M) : mul_action S (M \u29f8 P) :=\nfunction.surjective.mul_action mk (surjective_quot_mk _) P^.quotient.mk_smul\n\ninstance mul_action (P : submodule R M) : mul_action R (M \u29f8 P) :=\nquotient.mul_action' P\n\ninstance distrib_mul_action' [monoid S] [has_scalar S R] [distrib_mul_action S M]\n  [is_scalar_tower S R M]\n  (P : submodule R M) : distrib_mul_action S (M \u29f8 P) :=\nfunction.surjective.distrib_mul_action\n  \u27e8mk, rfl, \u03bb _ _, rfl\u27e9 (surjective_quot_mk _) P^.quotient.mk_smul\n\ninstance distrib_mul_action (P : submodule R M) : distrib_mul_action R (M \u29f8 P) :=\nquotient.distrib_mul_action' P\n\ninstance module' [semiring S] [has_scalar S R] [module S M] [is_scalar_tower S R M]\n  (P : submodule R M) : module S (M \u29f8 P) :=\nfunction.surjective.module _\n  \u27e8mk, rfl, \u03bb _ _, rfl\u27e9 (surjective_quot_mk _) P^.quotient.mk_smul\n\ninstance module (P : submodule R M) : module R (M \u29f8 P) :=\nquotient.module' P\n\nvariables (S)\n\n/-- The quotient of `P` as an `S`-submodule is the same as the quotient of `P` as an `R`-submodule,\nwhere `P : submodule R M`.\n-/\ndef restrict_scalars_equiv [ring S] [has_scalar S R] [module S M] [is_scalar_tower S R M]\n  (P : submodule R M) :\n  (M \u29f8 P.restrict_scalars S) \u2243\u2097[S] M \u29f8 P :=\n{ map_add' := \u03bb x y, quotient.induction_on\u2082' x y (\u03bb x' y', rfl),\n  map_smul' := \u03bb c x, quotient.induction_on' x (\u03bb x', rfl),\n  ..quotient.congr_right $ \u03bb _ _, iff.rfl }\n\n@[simp] lemma restrict_scalars_equiv_mk\n  [ring S] [has_scalar S R] [module S M] [is_scalar_tower S R M] (P : submodule R M)\n  (x : M) : restrict_scalars_equiv S P (mk x) = mk x :=\nrfl\n\n@[simp] lemma restrict_scalars_equiv_symm_mk\n  [ring S] [has_scalar S R] [module S M] [is_scalar_tower S R M] (P : submodule R M)\n  (x : M) : (restrict_scalars_equiv S P).symm (mk x) = mk x :=\nrfl\n\n\nend module\n\nlemma mk_surjective : function.surjective (@mk _ _ _ _ _ p) :=\nby { rintros \u27e8x\u27e9, exact \u27e8x, rfl\u27e9 }\n\nlemma nontrivial_of_lt_top (h : p < \u22a4) : nontrivial (M \u29f8 p) :=\nbegin\n  obtain \u27e8x, _, not_mem_s\u27e9 := set_like.exists_of_lt h,\n  refine \u27e8\u27e8mk x, 0, _\u27e9\u27e9,\n  simpa using not_mem_s\nend\n\nend quotient\n\nsection\n\nvariables {M\u2082 : Type*} [add_comm_group M\u2082] [module R M\u2082]\n\nlemma quot_hom_ext \u2983f g : M \u29f8 p \u2192\u2097[R] M\u2082\u2984 (h : \u2200 x, f (quotient.mk x) = g (quotient.mk x)) :\n  f = g :=\nlinear_map.ext $ \u03bb x, quotient.induction_on' x h\n\n/-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/\ndef mkq : M \u2192\u2097[R] M \u29f8 p :=\n{ to_fun := quotient.mk, map_add' := by simp, map_smul' := by simp }\n\n@[simp] theorem mkq_apply (x : M) : p.mkq x = quotient.mk x := rfl\n\nlemma mkq_surjective (A : submodule R M) : function.surjective A.mkq :=\nby rintro \u27e8x\u27e9; exact \u27e8x, rfl\u27e9\n\nend\n\nvariables {R\u2082 M\u2082 : Type*} [ring R\u2082] [add_comm_group M\u2082] [module R\u2082 M\u2082] {\u03c4\u2081\u2082 : R \u2192+* R\u2082}\n\n/-- Two `linear_map`s from a quotient module are equal if their compositions with\n`submodule.mkq` are equal.\n\nSee note [partially-applied ext lemmas]. -/\n@[ext]\nlemma linear_map_qext \u2983f g : M \u29f8 p \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082\u2984 (h : f.comp p.mkq = g.comp p.mkq) : f = g :=\nlinear_map.ext $ \u03bb x, quotient.induction_on' x $ (linear_map.congr_fun h : _)\n\n/-- The map from the quotient of `M` by a submodule `p` to `M\u2082` induced by a linear map `f : M \u2192 M\u2082`\nvanishing on `p`, as a linear map. -/\ndef liftq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : p \u2264 f.ker) : M \u29f8 p \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082 :=\n{ map_smul' := by rintro a \u27e8x\u27e9; exact f.map_smul\u209b\u2097 a x,\n  ..quotient_add_group.lift p.to_add_subgroup f.to_add_monoid_hom h }\n\n@[simp] theorem liftq_apply (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) {h} (x : M) :\n  p.liftq f h (quotient.mk x) = f x := rfl\n\n@[simp] theorem liftq_mkq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) : (p.liftq f h).comp p.mkq = f :=\nby ext; refl\n\n/--Special case of `liftq` when `p` is the span of `x`. In this case, the condition on `f` simply\nbecomes vanishing at `x`.-/\ndef liftq_span_singleton (x : M) (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : f x = 0) : (M \u29f8 R \u2219 x) \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082 :=\n(R \u2219 x).liftq f $ by rw [span_singleton_le_iff_mem, linear_map.mem_ker, h]\n\n@[simp] lemma liftq_span_singleton_apply (x : M) (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : f x = 0) (y : M) :\nliftq_span_singleton x f h (quotient.mk y) = f y := rfl\n\n@[simp] theorem range_mkq : p.mkq.range = \u22a4 :=\neq_top_iff'.2 $ by rintro \u27e8x\u27e9; exact \u27e8x, rfl\u27e9\n\n@[simp] theorem ker_mkq : p.mkq.ker = p :=\nby ext; simp\n\nlemma le_comap_mkq (p' : submodule R (M \u29f8 p)) : p \u2264 comap p.mkq p' :=\nby simpa using (comap_mono bot_le : p.mkq.ker \u2264 comap p.mkq p')\n\n@[simp] theorem mkq_map_self : map p.mkq p = \u22a5 :=\nby rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkq]; exact le_rfl\n\n@[simp] theorem comap_map_mkq : comap p.mkq (map p.mkq p') = p \u2294 p' :=\nby simp [comap_map_eq, sup_comm]\n\n@[simp] theorem map_mkq_eq_top : map p.mkq p' = \u22a4 \u2194 p \u2294 p' = \u22a4 :=\nby simp only [map_eq_top_iff p.range_mkq, sup_comm, ker_mkq]\n\nvariables (q : submodule R\u2082 M\u2082)\n\n/-- The map from the quotient of `M` by submodule `p` to the quotient of `M\u2082` by submodule `q` along\n`f : M \u2192 M\u2082` is linear. -/\ndef mapq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h : p \u2264 comap f q) :\n  (M \u29f8 p) \u2192\u209b\u2097[\u03c4\u2081\u2082] (M\u2082 \u29f8 q) :=\np.liftq (q.mkq.comp f) $ by simpa [ker_comp] using h\n\n@[simp] theorem mapq_apply (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) {h} (x : M) :\n  mapq p q f h (quotient.mk x) = quotient.mk (f x) := rfl\n\ntheorem mapq_mkq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) {h} : (mapq p q f h).comp p.mkq = q.mkq.comp f :=\nby ext x; refl\n\n@[simp] lemma mapq_zero (h : p \u2264 q.comap (0 : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) := by simp) :\n  p.mapq q (0 : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) h = 0 :=\nby { ext, simp, }\n\n/-- Given submodules `p \u2286 M`, `p\u2082 \u2286 M\u2082`, `p\u2083 \u2286 M\u2083` and maps `f : M \u2192 M\u2082`, `g : M\u2082 \u2192 M\u2083` inducing\n`mapq f : M \u29f8 p \u2192 M\u2082 \u29f8 p\u2082` and `mapq g : M\u2082 \u29f8 p\u2082 \u2192 M\u2083 \u29f8 p\u2083` then\n`mapq (g \u2218 f) = (mapq g) \u2218 (mapq f)`. -/\nlemma mapq_comp {R\u2083 M\u2083 : Type*} [ring R\u2083] [add_comm_group M\u2083] [module R\u2083 M\u2083]\n  (p\u2082 : submodule R\u2082 M\u2082) (p\u2083 : submodule R\u2083 M\u2083)\n  {\u03c4\u2082\u2083 : R\u2082 \u2192+* R\u2083} {\u03c4\u2081\u2083 : R \u2192+* R\u2083} [ring_hom_comp_triple \u03c4\u2081\u2082 \u03c4\u2082\u2083 \u03c4\u2081\u2083]\n  (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (g : M\u2082 \u2192\u209b\u2097[\u03c4\u2082\u2083] M\u2083) (hf : p \u2264 p\u2082.comap f) (hg : p\u2082 \u2264 p\u2083.comap g)\n  (h := (hf.trans (comap_mono hg))) :\n  p.mapq p\u2083 (g.comp f) h = (p\u2082.mapq p\u2083 g hg).comp (p.mapq p\u2082 f hf) :=\nby { ext, simp, }\n\n@[simp] lemma mapq_id (h : p \u2264 p.comap linear_map.id := by simp) :\n  p.mapq p linear_map.id h = linear_map.id :=\nby { ext, simp, }\n\nlemma mapq_pow {f : M \u2192\u2097[R] M} (h : p \u2264 p.comap f) (k : \u2115)\n  (h' : p \u2264 p.comap (f^k) := p.le_comap_pow_of_le_comap h k) :\n  p.mapq p (f^k) h' = (p.mapq p f h)^k :=\nbegin\n  induction k with k ih,\n  { simp [linear_map.one_eq_id], },\n  { simp only [linear_map.iterate_succ, \u2190 ih],\n    apply p.mapq_comp, },\nend\n\ntheorem comap_liftq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) :\n  q.comap (p.liftq f h) = (q.comap f).map (mkq p) :=\nle_antisymm\n  (by rintro \u27e8x\u27e9 hx; exact \u27e8_, hx, rfl\u27e9)\n  (by rw [map_le_iff_le_comap, \u2190 comap_comp, liftq_mkq]; exact le_rfl)\n\ntheorem map_liftq [ring_hom_surjective \u03c4\u2081\u2082] (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) (q : submodule R (M \u29f8 p)) :\n  q.map (p.liftq f h) = (q.comap p.mkq).map f :=\nle_antisymm\n  (by rintro _ \u27e8\u27e8x\u27e9, hxq, rfl\u27e9; exact \u27e8x, hxq, rfl\u27e9)\n  (by rintro _ \u27e8x, hxq, rfl\u27e9; exact \u27e8quotient.mk x, hxq, rfl\u27e9)\n\ntheorem ker_liftq (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) :\n  ker (p.liftq f h) = (ker f).map (mkq p) := comap_liftq _ _ _ _\n\ntheorem range_liftq [ring_hom_surjective \u03c4\u2081\u2082] (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) :\n  range (p.liftq f h) = range f :=\nby simpa only [range_eq_map] using map_liftq _ _ _ _\n\ntheorem ker_liftq_eq_bot (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) (h) (h' : ker f \u2264 p) : ker (p.liftq f h) = \u22a5 :=\nby rw [ker_liftq, le_antisymm h h', mkq_map_self]\n\n/-- The correspondence theorem for modules: there is an order isomorphism between submodules of the\nquotient of `M` by `p`, and submodules of `M` larger than `p`. -/\ndef comap_mkq.rel_iso :\n  submodule R (M \u29f8 p) \u2243o {p' : submodule R M // p \u2264 p'} :=\n{ to_fun    := \u03bb p', \u27e8comap p.mkq p', le_comap_mkq p _\u27e9,\n  inv_fun   := \u03bb q, map p.mkq q,\n  left_inv  := \u03bb p', map_comap_eq_self $ by simp,\n  right_inv := \u03bb \u27e8q, hq\u27e9, subtype.ext_val $ by simpa [comap_map_mkq p],\n  map_rel_iff'      := \u03bb p\u2081 p\u2082, comap_le_comap_iff $ range_mkq _ }\n\n/-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules\nof `M`. -/\ndef comap_mkq.order_embedding :\n  submodule R (M \u29f8 p) \u21aao submodule R M :=\n(rel_iso.to_rel_embedding $ comap_mkq.rel_iso p).trans (subtype.rel_embedding _ _)\n\n@[simp] lemma comap_mkq_embedding_eq (p' : submodule R (M \u29f8 p)) :\n  comap_mkq.order_embedding p p' = comap p.mkq p' := rfl\n\nlemma span_preimage_eq [ring_hom_surjective \u03c4\u2081\u2082] {f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082} {s : set M\u2082} (h\u2080 : s.nonempty)\n  (h\u2081 : s \u2286 range f) :\n  span R (f \u207b\u00b9' s) = (span R\u2082 s).comap f :=\nbegin\n  suffices : (span R\u2082 s).comap f \u2264 span R (f \u207b\u00b9' s),\n  { exact le_antisymm (span_preimage_le f s) this, },\n  have hk : ker f \u2264 span R (f \u207b\u00b9' s),\n  { let y := classical.some h\u2080, have hy : y \u2208 s, { exact classical.some_spec h\u2080, },\n    rw ker_le_iff, use [y, h\u2081 hy], rw \u2190 set.singleton_subset_iff at hy,\n    exact set.subset.trans subset_span (span_mono (set.preimage_mono hy)), },\n  rw \u2190 left_eq_sup at hk, rw f.range_coe at h\u2081,\n  rw [hk, \u2190linear_map.map_le_map_iff, map_span, map_comap_eq, set.image_preimage_eq_of_subset h\u2081],\n  exact inf_le_right,\nend\n\nend submodule\n\nopen submodule\n\nnamespace linear_map\n\nsection ring\n\nvariables {R M R\u2082 M\u2082 R\u2083 M\u2083 : Type*}\nvariables [ring R] [ring R\u2082] [ring R\u2083]\nvariables [add_comm_monoid M] [add_comm_group M\u2082] [add_comm_monoid M\u2083]\nvariables [module R M] [module R\u2082 M\u2082] [module R\u2083 M\u2083]\nvariables {\u03c4\u2081\u2082 : R \u2192+* R\u2082} {\u03c4\u2082\u2083 : R\u2082 \u2192+* R\u2083} {\u03c4\u2081\u2083 : R \u2192+* R\u2083}\nvariables [ring_hom_comp_triple \u03c4\u2081\u2082 \u03c4\u2082\u2083 \u03c4\u2081\u2083] [ring_hom_surjective \u03c4\u2081\u2082]\n\nlemma range_mkq_comp (f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082) : f.range.mkq.comp f = 0 :=\nlinear_map.ext $ \u03bb x, by simp\n\nlemma ker_le_range_iff {f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082} {g : M\u2082 \u2192\u209b\u2097[\u03c4\u2082\u2083] M\u2083} :\n  g.ker \u2264 f.range \u2194 f.range.mkq.comp g.ker.subtype = 0 :=\nby rw [\u2190range_le_ker_iff, submodule.ker_mkq, submodule.range_subtype]\n\n/-- An epimorphism is surjective. -/\nlemma range_eq_top_of_cancel {f : M \u2192\u209b\u2097[\u03c4\u2081\u2082] M\u2082}\n  (h : \u2200 (u v : M\u2082 \u2192\u2097[R\u2082] M\u2082 \u29f8 f.range), u.comp f = v.comp f \u2192 u = v) : f.range = \u22a4 :=\nbegin\n  have h\u2081 : (0 : M\u2082 \u2192\u2097[R\u2082] M\u2082 \u29f8 f.range).comp f = 0 := zero_comp _,\n  rw [\u2190submodule.ker_mkq f.range, \u2190h 0 f.range.mkq (eq.trans h\u2081 (range_mkq_comp _).symm)],\n  exact ker_zero\nend\n\nend ring\n\nend linear_map\n\nopen linear_map\n\nnamespace submodule\n\nvariables {R M : Type*} {r : R} {x y : M} [ring R] [add_comm_group M] [module R M]\nvariables (p p' : submodule R M)\n\n/-- If `p = \u22a5`, then `M / p \u2243\u2097[R] M`. -/\ndef quot_equiv_of_eq_bot (hp : p = \u22a5) : (M \u29f8 p) \u2243\u2097[R] M :=\nlinear_equiv.of_linear (p.liftq id $ hp.symm \u25b8 bot_le) p.mkq (liftq_mkq _ _ _) $\n  p.quot_hom_ext $ \u03bb x, rfl\n\n@[simp] lemma quot_equiv_of_eq_bot_apply_mk (hp : p = \u22a5) (x : M) :\n  p.quot_equiv_of_eq_bot hp (quotient.mk x) = x := rfl\n\n@[simp] lemma quot_equiv_of_eq_bot_symm_apply (hp : p = \u22a5) (x : M) :\n  (p.quot_equiv_of_eq_bot hp).symm x = quotient.mk x := rfl\n\n@[simp] lemma coe_quot_equiv_of_eq_bot_symm (hp : p = \u22a5) :\n  ((p.quot_equiv_of_eq_bot hp).symm : M \u2192\u2097[R] M \u29f8 p) = p.mkq := rfl\n\n/-- Quotienting by equal submodules gives linearly equivalent quotients. -/\ndef quot_equiv_of_eq (h : p = p') : (M \u29f8 p) \u2243\u2097[R] M \u29f8 p' :=\n{ map_add' := by { rintros \u27e8x\u27e9 \u27e8y\u27e9, refl }, map_smul' := by { rintros x \u27e8y\u27e9, refl },\n  ..@quotient.congr _ _ (quotient_rel p) (quotient_rel p') (equiv.refl _) $\n    \u03bb a b, by { subst h, refl } }\n\n@[simp]\nlemma quot_equiv_of_eq_mk (h : p = p') (x : M) :\n  submodule.quot_equiv_of_eq p p' h (submodule.quotient.mk x) = submodule.quotient.mk x :=\nrfl\n\nend submodule\n\nend ring\n\nsection comm_ring\n\nvariables {R M M\u2082 : Type*} {r : R} {x y : M} [comm_ring R]\n  [add_comm_group M] [module R M] [add_comm_group M\u2082] [module R M\u2082]\n  (p : submodule R M) (q : submodule R M\u2082)\n\nnamespace submodule\n\n/-- Given modules `M`, `M\u2082` over a commutative ring, together with submodules `p \u2286 M`, `q \u2286 M\u2082`,\nthe natural map $\\{f \u2208 Hom(M, M\u2082) | f(p) \u2286 q \\} \\to Hom(M/p, M\u2082/q)$ is linear. -/\ndef mapq_linear : compatible_maps p q \u2192\u2097[R] (M \u29f8 p) \u2192\u2097[R] (M\u2082 \u29f8 q) :=\n{ to_fun    := \u03bb f, mapq _ _ f.val f.property,\n  map_add'  := \u03bb x y, by { ext, refl, },\n  map_smul' := \u03bb c f, by { ext, refl, } }\n\nend submodule\n\nend comm_ring\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/linear_algebra/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7016072029744607}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.multiset.powerset\n\n/-!\n# The antidiagonal on a multiset.\n\nThe antidiagonal of a multiset `s` consists of all pairs `(t\u2081, t\u2082)`\nsuch that `t\u2081 + t\u2082 = s`. These pairs are counted with multiplicities.\n-/\n\nnamespace multiset\nopen list\n\nvariables {\u03b1 \u03b2 : Type*}\n\n/-- The antidiagonal of a multiset `s` consists of all pairs `(t\u2081, t\u2082)`\n    such that `t\u2081 + t\u2082 = s`. These pairs are counted with multiplicities. -/\ndef antidiagonal (s : multiset \u03b1) : multiset (multiset \u03b1 \u00d7 multiset \u03b1) :=\nquot.lift_on s\n  (\u03bb l, (revzip (powerset_aux l) : multiset (multiset \u03b1 \u00d7 multiset \u03b1)))\n  (\u03bb l\u2081 l\u2082 h, quot.sound (revzip_powerset_aux_perm h))\n\ntheorem antidiagonal_coe (l : list \u03b1) :\n  @antidiagonal \u03b1 l = revzip (powerset_aux l) := rfl\n\n@[simp] theorem antidiagonal_coe' (l : list \u03b1) :\n  @antidiagonal \u03b1 l = revzip (powerset_aux' l) :=\nquot.sound revzip_powerset_aux_perm_aux'\n\n/-- A pair `(t\u2081, t\u2082)` of multisets is contained in `antidiagonal s`\n    if and only if `t\u2081 + t\u2082 = s`. -/\n@[simp] theorem mem_antidiagonal {s : multiset \u03b1} {x : multiset \u03b1 \u00d7 multiset \u03b1} :\n  x \u2208 antidiagonal s \u2194 x.1 + x.2 = s :=\nquotient.induction_on s $ \u03bb l, begin\n  simp [antidiagonal_coe], refine \u27e8\u03bb h, revzip_powerset_aux h, \u03bb h, _\u27e9,\n  haveI := classical.dec_eq \u03b1,\n  simp [revzip_powerset_aux_lemma l revzip_powerset_aux, h.symm],\n  cases x with x\u2081 x\u2082,\n  exact \u27e8_, le_add_right _ _, by rw add_sub_cancel_left _ _\u27e9\nend\n\n@[simp] theorem antidiagonal_map_fst (s : multiset \u03b1) :\n  (antidiagonal s).map prod.fst = powerset s :=\nquotient.induction_on s $ \u03bb l,\nby simp [powerset_aux']\n\n@[simp] theorem antidiagonal_map_snd (s : multiset \u03b1) :\n  (antidiagonal s).map prod.snd = powerset s :=\nquotient.induction_on s $ \u03bb l,\nby simp [powerset_aux']\n\n@[simp] theorem antidiagonal_zero : @antidiagonal \u03b1 0 = (0, 0) ::\u2098 0 := rfl\n\n@[simp] theorem antidiagonal_cons (a : \u03b1) (s) : antidiagonal (a ::\u2098 s) =\n  map (prod.map id (cons a)) (antidiagonal s) +\n  map (prod.map (cons a) id) (antidiagonal s) :=\nquotient.induction_on s $ \u03bb l, begin\n  simp only [revzip, reverse_append, quot_mk_to_coe, coe_eq_coe, powerset_aux'_cons, cons_coe,\n    coe_map, antidiagonal_coe', coe_add],\n  rw [\u2190 zip_map, \u2190 zip_map, zip_append, (_ : _++_=_)],\n  {congr; simp}, {simp}\nend\n\n@[simp] theorem card_antidiagonal (s : multiset \u03b1) :\n  card (antidiagonal s) = 2 ^ card s :=\nby have := card_powerset s;\n   rwa [\u2190 antidiagonal_map_fst, card_map] at this\n\nlemma prod_map_add [comm_semiring \u03b2] {s : multiset \u03b1} {f g : \u03b1 \u2192 \u03b2} :\n  prod (s.map (\u03bba, f a + g a)) =\n  sum ((antidiagonal s).map (\u03bbp, (p.1.map f).prod * (p.2.map g).prod)) :=\nbegin\n  refine s.induction_on _ _,\n  { simp },\n  { assume a s ih,\n    simp [ih, add_mul, mul_comm, mul_left_comm, mul_assoc, sum_map_mul_left.symm],\n    cc },\nend\n\nend multiset\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/multiset/antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619959279793, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7016072012768161}}
{"text": "/-\nCopyright (c) 2021 Henry Swanson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henry Swanson\n-/\nimport combinatorics.derangements.basic\nimport data.fintype.big_operators\nimport tactic.delta_instance\nimport tactic.ring\n\n/-!\n# Derangements on fintypes\n\nThis file contains lemmas that describe the cardinality of `derangements \u03b1` when `\u03b1` is a fintype.\n\n# Main definitions\n\n* `card_derangements_invariant`: A lemma stating that the number of derangements on a type `\u03b1`\n    depends only on the cardinality of `\u03b1`.\n* `num_derangements n`: The number of derangements on an n-element set, defined in a computation-\n    friendly way.\n* `card_derangements_eq_num_derangements`: Proof that `num_derangements` really does compute the\n    number of derangements.\n* `num_derangements_sum`: A lemma giving an expression for `num_derangements n` in terms of\n    factorials.\n-/\n\nopen derangements equiv fintype\nopen_locale big_operators\n\nvariables {\u03b1 : Type*} [decidable_eq \u03b1] [fintype \u03b1]\n\ninstance : decidable_pred (derangements \u03b1) := \u03bb _, fintype.decidable_forall_fintype\n\ninstance : fintype (derangements \u03b1) := by delta_instance derangements\n\nlemma card_derangements_invariant {\u03b1 \u03b2 : Type*} [fintype \u03b1] [decidable_eq \u03b1]\n  [fintype \u03b2] [decidable_eq \u03b2] (h : card \u03b1 = card \u03b2) :\n  card (derangements \u03b1) = card (derangements \u03b2) :=\nfintype.card_congr (equiv.derangements_congr $ equiv_of_card_eq h)\n\nlemma card_derangements_fin_add_two (n : \u2115) :\n  card (derangements (fin (n+2))) = (n+1) * card (derangements (fin n)) +\n  (n+1) * card (derangements (fin (n+1))) :=\nbegin\n  -- get some basic results about the size of fin (n+1) plus or minus an element\n  have h1 : \u2200 a : fin (n+1), card ({a}\u1d9c : set (fin (n+1))) = card (fin n),\n  { intro a,\n    simp only [fintype.card_fin, finset.card_fin, fintype.card_of_finset, finset.filter_ne' _ a,\n      set.mem_compl_singleton_iff, finset.card_erase_of_mem (finset.mem_univ a),\n      add_tsub_cancel_right] },\n  have h2 : card (fin (n+2)) = card (option (fin (n+1))),\n  { simp only [card_fin, card_option] },\n  -- rewrite the LHS and substitute in our fintype-level equivalence\n  simp only [card_derangements_invariant h2,\n    card_congr (@derangements_recursion_equiv (fin (n+1)) _),\n  -- push the cardinality through the \u03a3 and \u2295 so that we can use `card_n`\n    card_sigma, card_sum, card_derangements_invariant (h1 _), finset.sum_const, nsmul_eq_mul,\n    finset.card_fin, mul_add, nat.cast_id],\nend\n\n/-- The number of derangements of an `n`-element set. -/\ndef num_derangements : \u2115 \u2192 \u2115\n| 0 := 1\n| 1 := 0\n| (n + 2) := (n + 1) * (num_derangements n + num_derangements (n+1))\n\n@[simp] lemma num_derangements_zero : num_derangements 0 = 1 := rfl\n\n@[simp] lemma num_derangements_one : num_derangements 1 = 0 := rfl\n\nlemma num_derangements_add_two (n : \u2115) :\n  num_derangements (n+2) = (n+1) * (num_derangements n + num_derangements (n+1)) := rfl\n\nlemma num_derangements_succ (n : \u2115) :\n  (num_derangements (n+1) : \u2124) = (n + 1) * (num_derangements n : \u2124) - (-1)^n :=\nbegin\n  induction n with n hn,\n  { refl },\n  { simp only [num_derangements_add_two, hn, pow_succ,\n      int.coe_nat_mul, int.coe_nat_add, int.coe_nat_succ],\n    ring }\nend\n\nlemma card_derangements_fin_eq_num_derangements {n : \u2115} :\n  card (derangements (fin n)) = num_derangements n :=\nbegin\n  induction n using nat.strong_induction_on with n hyp,\n  obtain (_|_|n) := n, { refl }, { refl },  -- knock out cases 0 and 1\n  -- now we have n \u2265 2. rewrite everything in terms of card_derangements, so that we can use\n  -- `card_derangements_fin_add_two`\n  rw [num_derangements_add_two, card_derangements_fin_add_two, mul_add,\n    hyp _ (nat.lt_add_of_pos_right zero_lt_two), hyp _ (lt_add_one _)],\nend\n\nlemma card_derangements_eq_num_derangements (\u03b1 : Type*) [fintype \u03b1] [decidable_eq \u03b1] :\n  card (derangements \u03b1) = num_derangements (card \u03b1) :=\nbegin\n  rw \u2190card_derangements_invariant (card_fin _),\n  exact card_derangements_fin_eq_num_derangements,\nend\n\ntheorem num_derangements_sum (n : \u2115) :\n  (num_derangements n : \u2124) = \u2211 k in finset.range (n + 1), (-1:\u2124)^k * nat.asc_factorial k (n - k) :=\nbegin\n  induction n with n hn, { refl },\n  rw [finset.sum_range_succ, num_derangements_succ, hn, finset.mul_sum, tsub_self,\n    nat.asc_factorial_zero, int.coe_nat_one, mul_one, pow_succ, neg_one_mul, sub_eq_add_neg,\n    add_left_inj, finset.sum_congr rfl],\n  -- show that (n + 1) * (-1)^x * asc_fac x (n - x) = (-1)^x * asc_fac x (n.succ - x)\n  intros x hx,\n  have h_le : x \u2264 n := finset.mem_range_succ_iff.mp hx,\n  rw [nat.succ_sub h_le, nat.asc_factorial_succ, add_tsub_cancel_of_le h_le,\n    int.coe_nat_mul, int.coe_nat_succ, mul_left_comm],\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/combinatorics/derangements/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7015838972037031}}
{"text": "/-\nCopyright (c) 2017 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Floris van Doorn\n-/\nimport data.sum.order\nimport order.initial_seg\nimport set_theory.cardinal.basic\n\n/-!\n# Ordinals\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nOrdinals are defined as equivalences of well-ordered sets under order isomorphism. They are endowed\nwith a total order, where an ordinal is smaller than another one if it embeds into it as an\ninitial segment (or, equivalently, in any way). This total order is well founded.\n\n## Main definitions\n\n* `ordinal`: the type of ordinals (in a given universe)\n* `ordinal.type r`: given a well-founded order `r`, this is the corresponding ordinal\n* `ordinal.typein r a`: given a well-founded order `r` on a type `\u03b1`, and `a : \u03b1`, the ordinal\n  corresponding to all elements smaller than `a`.\n* `enum r o h`: given a well-order `r` on a type `\u03b1`, and an ordinal `o` strictly smaller than\n  the ordinal corresponding to `r` (this is the assumption `h`), returns the `o`-th element of `\u03b1`.\n  In other words, the elements of `\u03b1` can be enumerated using ordinals up to `type r`.\n* `ordinal.card o`: the cardinality of an ordinal `o`.\n* `ordinal.lift` lifts an ordinal in universe `u` to an ordinal in universe `max u v`.\n  For a version registering additionally that this is an initial segment embedding, see\n  `ordinal.lift.initial_seg`.\n  For a version regiserting that it is a principal segment embedding if `u < v`, see\n  `ordinal.lift.principal_seg`.\n* `ordinal.omega` or `\u03c9` is the order type of `\u2115`. This definition is universe polymorphic:\n  `ordinal.omega.{u} : ordinal.{u}` (contrast with `\u2115 : Type`, which lives in a specific\n  universe). In some cases the universe level has to be given explicitly.\n\n* `o\u2081 + o\u2082` is the order on the disjoint union of `o\u2081` and `o\u2082` obtained by declaring that\n  every element of `o\u2081` is smaller than every element of `o\u2082`. The main properties of addition\n  (and the other operations on ordinals) are stated and proved in `ordinal_arithmetic.lean`. Here,\n  we only introduce it and prove its basic properties to deduce the fact that the order on ordinals\n  is total (and well founded).\n* `succ o` is the successor of the ordinal `o`.\n* `cardinal.ord c`: when `c` is a cardinal, `ord c` is the smallest ordinal with this cardinality.\n  It is the canonical way to represent a cardinal with an ordinal.\n\nA conditionally complete linear order with bot structure is registered on ordinals, where `\u22a5` is\n`0`, the ordinal corresponding to the empty type, and `Inf` is the minimum for nonempty sets and `0`\nfor the empty set by convention.\n\n## Notations\n\n* `\u03c9` is a notation for the first infinite ordinal in the locale `ordinal`.\n-/\n\nnoncomputable theory\n\nopen function cardinal set equiv order\nopen_locale classical cardinal initial_seg\n\nuniverses u v w\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03b3 : Type*}\n  {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop} {t : \u03b3 \u2192 \u03b3 \u2192 Prop}\n\n/-! ### Well order on an arbitrary type -/\n\nsection well_ordering_thm\nparameter {\u03c3 : Type u}\nopen function\n\ntheorem nonempty_embedding_to_cardinal : nonempty (\u03c3 \u21aa cardinal.{u}) :=\n(embedding.total _ _).resolve_left $ \u03bb \u27e8\u27e8f, hf\u27e9\u27e9,\n  let g : \u03c3 \u2192 cardinal.{u} := inv_fun f in\n  let \u27e8x, (hx : g x = 2 ^ sum g)\u27e9 := inv_fun_surjective hf (2 ^ sum g) in\n  have g x \u2264 sum g, from le_sum.{u u} g x,\n  not_le_of_gt (by rw hx; exact cantor _) this\n\n/-- An embedding of any type to the set of cardinals. -/\ndef embedding_to_cardinal : \u03c3 \u21aa cardinal.{u} := classical.choice nonempty_embedding_to_cardinal\n\n/-- Any type can be endowed with a well order, obtained by pulling back the well order over\ncardinals by some embedding. -/\ndef well_ordering_rel : \u03c3 \u2192 \u03c3 \u2192 Prop := embedding_to_cardinal \u207b\u00b9'o (<)\n\ninstance well_ordering_rel.is_well_order : is_well_order \u03c3 well_ordering_rel :=\n(rel_embedding.preimage _ _).is_well_order\n\ninstance is_well_order.subtype_nonempty : nonempty {r // is_well_order \u03c3 r} :=\n\u27e8\u27e8well_ordering_rel, infer_instance\u27e9\u27e9\n\nend well_ordering_thm\n\n/-! ### Definition of ordinals -/\n\n/-- Bundled structure registering a well order on a type. Ordinals will be defined as a quotient\nof this type. -/\nstructure Well_order : Type (u+1) :=\n(\u03b1 : Type u)\n(r : \u03b1 \u2192 \u03b1 \u2192 Prop)\n(wo : is_well_order \u03b1 r)\n\nattribute [instance] Well_order.wo\n\nnamespace Well_order\n\ninstance : inhabited Well_order := \u27e8\u27e8pempty, _, empty_relation.is_well_order\u27e9\u27e9\n\n@[simp] lemma eta (o : Well_order) : mk o.\u03b1 o.r o.wo = o := by { cases o, refl }\n\nend Well_order\n\n/-- Equivalence relation on well orders on arbitrary types in universe `u`, given by order\nisomorphism. -/\ninstance ordinal.is_equivalent : setoid Well_order :=\n{ r     := \u03bb \u27e8\u03b1, r, wo\u27e9 \u27e8\u03b2, s, wo'\u27e9, nonempty (r \u2243r s),\n  iseqv := \u27e8\u03bb \u27e8\u03b1, r, _\u27e9, \u27e8rel_iso.refl _\u27e9,\n    \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8e\u27e9, \u27e8e.symm\u27e9,\n    \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9 \u27e8e\u2081\u27e9 \u27e8e\u2082\u27e9, \u27e8e\u2081.trans e\u2082\u27e9\u27e9 }\n\n/-- `ordinal.{u}` is the type of well orders in `Type u`, up to order isomorphism. -/\ndef ordinal : Type (u + 1) := quotient ordinal.is_equivalent\n\ninstance has_well_founded_out (o : ordinal) : has_well_founded o.out.\u03b1 := \u27e8o.out.r, o.out.wo.wf\u27e9\n\ninstance linear_order_out (o : ordinal) : linear_order o.out.\u03b1 :=\nis_well_order.linear_order o.out.r\n\ninstance is_well_order_out_lt (o : ordinal) : is_well_order o.out.\u03b1 (<) :=\no.out.wo\n\nnamespace ordinal\n\n/- ### Basic properties of the order type -/\n\n/-- The order type of a well order is an ordinal. -/\ndef type (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [wo : is_well_order \u03b1 r] : ordinal :=\n\u27e6\u27e8\u03b1, r, wo\u27e9\u27e7\n\ninstance : has_zero ordinal := \u27e8type $ @empty_relation pempty\u27e9\ninstance : inhabited ordinal := \u27e80\u27e9\ninstance : has_one ordinal := \u27e8type $ @empty_relation punit\u27e9\n\n/-- The order type of an element inside a well order. For the embedding as a principal segment, see\n`typein.principal_seg`. -/\ndef typein (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (a : \u03b1) : ordinal :=\ntype (subrel r {b | r b a})\n\n@[simp] theorem type_def' (w : Well_order) : \u27e6w\u27e7 = type w.r :=\nby { cases w, refl }\n\n@[simp] theorem type_def (r) [wo : is_well_order \u03b1 r] : (\u27e6\u27e8\u03b1, r, wo\u27e9\u27e7 : ordinal) = type r :=\nrfl\n\n@[simp] lemma type_out (o : ordinal) : ordinal.type o.out.r = o :=\nby rw [ordinal.type, Well_order.eta, quotient.out_eq]\n\ntheorem type_eq {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] : type r = type s \u2194 nonempty (r \u2243r s) :=\nquotient.eq\n\ntheorem _root_.rel_iso.ordinal_type_eq {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] (h : r \u2243r s) : type r = type s :=\ntype_eq.2 \u27e8h\u27e9\n\n@[simp] theorem type_lt (o : ordinal) : type ((<) : o.out.\u03b1 \u2192 o.out.\u03b1 \u2192 Prop) = o :=\n(type_def' _).symm.trans $ quotient.out_eq o\n\ntheorem type_eq_zero_of_empty (r) [is_well_order \u03b1 r] [is_empty \u03b1] : type r = 0 :=\n(rel_iso.rel_iso_of_is_empty r _).ordinal_type_eq\n\n@[simp] theorem type_eq_zero_iff_is_empty [is_well_order \u03b1 r] : type r = 0 \u2194 is_empty \u03b1 :=\n\u27e8\u03bb h, let \u27e8s\u27e9 := type_eq.1 h in s.to_equiv.is_empty, @type_eq_zero_of_empty \u03b1 r _\u27e9\n\ntheorem type_ne_zero_iff_nonempty [is_well_order \u03b1 r] : type r \u2260 0 \u2194 nonempty \u03b1 := by simp\n\ntheorem type_ne_zero_of_nonempty (r) [is_well_order \u03b1 r] [h : nonempty \u03b1] : type r \u2260 0 :=\ntype_ne_zero_iff_nonempty.2 h\n\ntheorem type_pempty : type (@empty_relation pempty) = 0 := rfl\ntheorem type_empty : type (@empty_relation empty) = 0 := type_eq_zero_of_empty _\n\ntheorem type_eq_one_of_unique (r) [is_well_order \u03b1 r] [unique \u03b1] : type r = 1 :=\n(rel_iso.rel_iso_of_unique_of_irrefl r _).ordinal_type_eq\n\n@[simp] theorem type_eq_one_iff_unique [is_well_order \u03b1 r] : type r = 1 \u2194 nonempty (unique \u03b1) :=\n\u27e8\u03bb h, let \u27e8s\u27e9 := type_eq.1 h in \u27e8s.to_equiv.unique\u27e9, \u03bb \u27e8h\u27e9, @type_eq_one_of_unique \u03b1 r _ h\u27e9\n\ntheorem type_punit : type (@empty_relation punit) = 1 := rfl\ntheorem type_unit : type (@empty_relation unit) = 1 := rfl\n\n@[simp] theorem out_empty_iff_eq_zero {o : ordinal} : is_empty o.out.\u03b1 \u2194 o = 0 :=\nby rw [\u2190@type_eq_zero_iff_is_empty o.out.\u03b1 (<), type_lt]\n\nlemma eq_zero_of_out_empty (o : ordinal) [h : is_empty o.out.\u03b1] : o = 0 :=\nout_empty_iff_eq_zero.1 h\n\ninstance is_empty_out_zero : is_empty (0 : ordinal).out.\u03b1 := out_empty_iff_eq_zero.2 rfl\n\n@[simp] theorem out_nonempty_iff_ne_zero {o : ordinal} : nonempty o.out.\u03b1 \u2194 o \u2260 0 :=\nby rw [\u2190@type_ne_zero_iff_nonempty o.out.\u03b1 (<), type_lt]\n\nlemma ne_zero_of_out_nonempty (o : ordinal) [h : nonempty o.out.\u03b1] : o \u2260 0 :=\nout_nonempty_iff_ne_zero.1 h\n\nprotected lemma one_ne_zero : (1 : ordinal) \u2260 0 := type_ne_zero_of_nonempty _\n\ninstance : nontrivial ordinal.{u} := \u27e8\u27e81, 0, ordinal.one_ne_zero\u27e9\u27e9\n\n@[simp] theorem type_preimage {\u03b1 \u03b2 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (f : \u03b2 \u2243 \u03b1) :\n  type (f \u207b\u00b9'o r) = type r :=\n(rel_iso.preimage f r).ordinal_type_eq\n\n@[elab_as_eliminator] theorem induction_on {C : ordinal \u2192 Prop}\n  (o : ordinal) (H : \u2200 \u03b1 r [is_well_order \u03b1 r], by exactI C (type r)) : C o :=\nquot.induction_on o $ \u03bb \u27e8\u03b1, r, wo\u27e9, @H \u03b1 r wo\n\n/-! ### The order on ordinals -/\n\ninstance : partial_order ordinal :=\n{ le := \u03bb a b, quotient.lift_on\u2082 a b (\u03bb \u27e8\u03b1, r, wo\u27e9 \u27e8\u03b2, s, wo'\u27e9, nonempty (r \u227ci s)) $\n    \u03bb \u27e8\u03b1\u2081, r\u2081, o\u2081\u27e9 \u27e8\u03b1\u2082, r\u2082, o\u2082\u27e9 \u27e8\u03b2\u2081, s\u2081, p\u2081\u27e9 \u27e8\u03b2\u2082, s\u2082, p\u2082\u27e9 \u27e8f\u27e9 \u27e8g\u27e9,\n    propext \u27e8\n      \u03bb \u27e8h\u27e9, \u27e8(initial_seg.of_iso f.symm).trans $\n        h.trans (initial_seg.of_iso g)\u27e9,\n      \u03bb \u27e8h\u27e9, \u27e8(initial_seg.of_iso f).trans $\n        h.trans (initial_seg.of_iso g.symm)\u27e9\u27e9,\n  lt := \u03bb a b, quotient.lift_on\u2082 a b (\u03bb \u27e8\u03b1, r, wo\u27e9 \u27e8\u03b2, s, wo'\u27e9, nonempty (r \u227ai s)) $\n    \u03bb \u27e8\u03b1\u2081, r\u2081, o\u2081\u27e9 \u27e8\u03b1\u2082, r\u2082, o\u2082\u27e9 \u27e8\u03b2\u2081, s\u2081, p\u2081\u27e9 \u27e8\u03b2\u2082, s\u2082, p\u2082\u27e9 \u27e8f\u27e9 \u27e8g\u27e9,\n    by exactI propext \u27e8\n      \u03bb \u27e8h\u27e9, \u27e8principal_seg.equiv_lt f.symm $\n        h.lt_le (initial_seg.of_iso g)\u27e9,\n      \u03bb \u27e8h\u27e9, \u27e8principal_seg.equiv_lt f $\n        h.lt_le (initial_seg.of_iso g.symm)\u27e9\u27e9,\n  le_refl := quot.ind $ by exact \u03bb \u27e8\u03b1, r, wo\u27e9, \u27e8initial_seg.refl _\u27e9,\n  le_trans := \u03bb a b c, quotient.induction_on\u2083 a b c $\n    \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9 \u27e8f\u27e9 \u27e8g\u27e9, \u27e8f.trans g\u27e9,\n  lt_iff_le_not_le := \u03bb a b, quotient.induction_on\u2082 a b $\n    \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9, by exactI\n      \u27e8\u03bb \u27e8f\u27e9, \u27e8\u27e8f\u27e9, \u03bb \u27e8g\u27e9, (f.lt_le g).irrefl\u27e9,\n      \u03bb \u27e8\u27e8f\u27e9, h\u27e9, sum.rec_on f.lt_or_eq (\u03bb g, \u27e8g\u27e9)\n      (\u03bb g, (h \u27e8initial_seg.of_iso g.symm\u27e9).elim)\u27e9,\n  le_antisymm := \u03bb a b,\n    quotient.induction_on\u2082 a b $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8h\u2081\u27e9 \u27e8h\u2082\u27e9,\n    by exactI quot.sound \u27e8initial_seg.antisymm h\u2081 h\u2082\u27e9 }\n\n/-- Ordinal less-equal is defined such that\n  well orders `r` and `s` satisfy `type r \u2264 type s` if there exists\n  a function embedding `r` as an initial segment of `s`. -/\nadd_decl_doc ordinal.partial_order.le\n\n/-- Ordinal less-than is defined such that\n  well orders `r` and `s` satisfy `type r < type s` if there exists\n  a function embedding `r` as a principal segment of `s`. -/\nadd_decl_doc ordinal.partial_order.lt\n\ntheorem type_le_iff {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] :\n  type r \u2264 type s \u2194 nonempty (r \u227ci s) := iff.rfl\n\ntheorem type_le_iff' {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] : type r \u2264 type s \u2194 nonempty (r \u21aar s) :=\n\u27e8\u03bb \u27e8f\u27e9, \u27e8f\u27e9, \u03bb \u27e8f\u27e9, \u27e8f.collapse\u27e9\u27e9\n\ntheorem _root_.initial_seg.ordinal_type_le {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] (h : r \u227ci s) : type r \u2264 type s := \u27e8h\u27e9\n\ntheorem _root_.rel_embedding.ordinal_type_le {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] (h : r \u21aar s) : type r \u2264 type s := \u27e8h.collapse\u27e9\n\n@[simp] theorem type_lt_iff {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] :\n  type r < type s \u2194 nonempty (r \u227ai s) := iff.rfl\n\ntheorem _root_.principal_seg.ordinal_type_lt {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] (h : r \u227ai s) : type r < type s := \u27e8h\u27e9\n\nprotected theorem zero_le (o : ordinal) : 0 \u2264 o :=\ninduction_on o $ \u03bb \u03b1 r _, by exactI (initial_seg.of_is_empty _ r).ordinal_type_le\n\ninstance : order_bot ordinal := \u27e80, ordinal.zero_le\u27e9\n\n@[simp] lemma bot_eq_zero : (\u22a5 : ordinal) = 0 := rfl\n\n@[simp] protected theorem le_zero {o : ordinal} : o \u2264 0 \u2194 o = 0 := le_bot_iff\nprotected theorem pos_iff_ne_zero {o : ordinal} : 0 < o \u2194 o \u2260 0 := bot_lt_iff_ne_bot\nprotected theorem not_lt_zero (o : ordinal) : \u00ac o < 0 := not_lt_bot\ntheorem eq_zero_or_pos : \u2200 a : ordinal, a = 0 \u2228 0 < a := eq_bot_or_bot_lt\n\ninstance : zero_le_one_class ordinal := \u27e8ordinal.zero_le _\u27e9\n\ninstance ne_zero.one : ne_zero (1 : ordinal) := \u27e8ordinal.one_ne_zero\u27e9\n\n/-- Given two ordinals `\u03b1 \u2264 \u03b2`, then `initial_seg_out \u03b1 \u03b2` is the initial segment embedding\nof `\u03b1` to `\u03b2`, as map from a model type for `\u03b1` to a model type for `\u03b2`. -/\ndef initial_seg_out {\u03b1 \u03b2 : ordinal} (h : \u03b1 \u2264 \u03b2) :\n  initial_seg ((<) : \u03b1.out.\u03b1 \u2192 \u03b1.out.\u03b1 \u2192 Prop) ((<) : \u03b2.out.\u03b1 \u2192 \u03b2.out.\u03b1 \u2192 Prop) :=\nbegin\n  change \u03b1.out.r \u227ci \u03b2.out.r,\n  rw [\u2190quotient.out_eq \u03b1, \u2190quotient.out_eq \u03b2] at h, revert h,\n  cases quotient.out \u03b1, cases quotient.out \u03b2, exact classical.choice\nend\n\n/-- Given two ordinals `\u03b1 < \u03b2`, then `principal_seg_out \u03b1 \u03b2` is the principal segment embedding\nof `\u03b1` to `\u03b2`, as map from a model type for `\u03b1` to a model type for `\u03b2`. -/\ndef principal_seg_out {\u03b1 \u03b2 : ordinal} (h : \u03b1 < \u03b2) :\n  principal_seg ((<) : \u03b1.out.\u03b1 \u2192 \u03b1.out.\u03b1 \u2192 Prop) ((<) : \u03b2.out.\u03b1 \u2192 \u03b2.out.\u03b1 \u2192 Prop) :=\nbegin\n  change \u03b1.out.r \u227ai \u03b2.out.r,\n  rw [\u2190quotient.out_eq \u03b1, \u2190quotient.out_eq \u03b2] at h, revert h,\n  cases quotient.out \u03b1, cases quotient.out \u03b2, exact classical.choice\nend\n\ntheorem typein_lt_type (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (a : \u03b1) : typein r a < type r :=\n\u27e8principal_seg.of_element _ _\u27e9\n\ntheorem typein_lt_self {o : ordinal} (i : o.out.\u03b1) : typein (<) i < o :=\nby { simp_rw \u2190type_lt o, apply typein_lt_type }\n\n@[simp] theorem typein_top {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] (f : r \u227ai s) :\n  typein s f.top = type r :=\neq.symm $ quot.sound \u27e8rel_iso.of_surjective\n  (rel_embedding.cod_restrict _ f f.lt_top)\n  (\u03bb \u27e8a, h\u27e9, by rcases f.down.1 h with \u27e8b, rfl\u27e9; exact \u27e8b, rfl\u27e9)\u27e9\n\n@[simp] theorem typein_apply {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] (f : r \u227ci s) (a : \u03b1) :\n  ordinal.typein s (f a) = ordinal.typein r a :=\neq.symm $ quotient.sound \u27e8rel_iso.of_surjective\n  (rel_embedding.cod_restrict _\n    ((subrel.rel_embedding _ _).trans f)\n    (\u03bb \u27e8x, h\u27e9, by rw [rel_embedding.trans_apply]; exact f.to_rel_embedding.map_rel_iff.2 h))\n  (\u03bb \u27e8y, h\u27e9, by rcases f.init h with \u27e8a, rfl\u27e9;\n    exact \u27e8\u27e8a, f.to_rel_embedding.map_rel_iff.1 h\u27e9, subtype.eq $ rel_embedding.trans_apply _ _ _\u27e9)\u27e9\n\n@[simp] theorem typein_lt_typein (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r]\n  {a b : \u03b1} : typein r a < typein r b \u2194 r a b :=\n\u27e8\u03bb \u27e8f\u27e9, begin\n  have : f.top.1 = a,\n  { let f' := principal_seg.of_element r a,\n    let g' := f.trans (principal_seg.of_element r b),\n    have : g'.top = f'.top, {rw subsingleton.elim f' g'},\n    exact this },\n  rw \u2190 this, exact f.top.2\nend, \u03bb h, \u27e8principal_seg.cod_restrict _\n  (principal_seg.of_element r a)\n  (\u03bb x, @trans _ r _ _ _ _ x.2 h) h\u27e9\u27e9\n\ntheorem typein_surj (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r]\n  {o} (h : o < type r) : \u2203 a, typein r a = o :=\ninduction_on o (\u03bb \u03b2 s _ \u27e8f\u27e9, by exactI \u27e8f.top, typein_top _\u27e9) h\n\nlemma typein_injective (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] : injective (typein r) :=\ninjective_of_increasing r (<) (typein r) (\u03bb x y, (typein_lt_typein r).2)\n\n@[simp] theorem typein_inj (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r]\n  {a b} : typein r a = typein r b \u2194 a = b :=\n(typein_injective r).eq_iff\n\n/-! ### Enumerating elements in a well-order with ordinals. -/\n\n/-- `enum r o h` is the `o`-th element of `\u03b1` ordered by `r`.\n  That is, `enum` maps an initial segment of the ordinals, those\n  less than the order type of `r`, to the elements of `\u03b1`. -/\ndef enum (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (o) : o < type r \u2192 \u03b1 :=\nquot.rec_on o (\u03bb \u27e8\u03b2, s, _\u27e9 h, (classical.choice h).top) $\n\u03bb \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9 \u27e8h\u27e9, begin\n  resetI, refine funext (\u03bb (H\u2082 : type t < type r), _),\n  have H\u2081 : type s < type r, {rwa type_eq.2 \u27e8h\u27e9},\n  have : \u2200 {o e} (H : o < type r), @@eq.rec\n   (\u03bb (o : ordinal), o < type r \u2192 \u03b1)\n   (\u03bb (h : type s < type r), (classical.choice h).top)\n     e H = (classical.choice H\u2081).top, {intros, subst e},\n  exact (this H\u2082).trans (principal_seg.top_eq h\n    (classical.choice H\u2081) (classical.choice H\u2082))\nend\n\ntheorem enum_type {\u03b1 \u03b2} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] (f : s \u227ai r)\n  {h : type s < type r} : enum r (type s) h = f.top :=\nprincipal_seg.top_eq (rel_iso.refl _) _ _\n\n@[simp] theorem enum_typein (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (a : \u03b1) :\n  enum r (typein r a) (typein_lt_type r a) = a :=\nenum_type (principal_seg.of_element r a)\n\n@[simp] theorem typein_enum (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r]\n  {o} (h : o < type r) : typein r (enum r o h) = o :=\nlet \u27e8a, e\u27e9 := typein_surj r h in\nby clear _let_match; subst e; rw enum_typein\n\ntheorem enum_lt_enum {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_well_order \u03b1 r]\n  {o\u2081 o\u2082 : ordinal} (h\u2081 : o\u2081 < type r) (h\u2082 : o\u2082 < type r) :\n  r (enum r o\u2081 h\u2081) (enum r o\u2082 h\u2082) \u2194 o\u2081 < o\u2082 :=\nby rw [\u2190 typein_lt_typein r, typein_enum, typein_enum]\n\nlemma rel_iso_enum' {\u03b1 \u03b2 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s]\n  (f : r \u2243r s) (o : ordinal) : \u2200(hr : o < type r) (hs : o < type s),\n  f (enum r o hr) = enum s o hs :=\nbegin\n  refine induction_on o _, rintros \u03b3 t wo \u27e8g\u27e9 \u27e8h\u27e9,\n  resetI, rw [enum_type g, enum_type (principal_seg.lt_equiv g f)], refl\nend\n\nlemma rel_iso_enum {\u03b1 \u03b2 : Type u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop}\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s]\n  (f : r \u2243r s) (o : ordinal) (hr : o < type r) :\n  f (enum r o hr) =\n  enum s o (by {convert hr using 1, apply quotient.sound, exact \u27e8f.symm\u27e9 }) :=\nrel_iso_enum' _ _ _ _\n\ntheorem lt_wf : @well_founded ordinal (<) :=\n\u27e8\u03bb a, induction_on a $ \u03bb \u03b1 r wo, by exactI\nsuffices \u2200 a, acc (<) (typein r a), from\n\u27e8_, \u03bb o h, let \u27e8a, e\u27e9 := typein_surj r h in e \u25b8 this a\u27e9,\n\u03bb a, acc.rec_on (wo.wf.apply a) $ \u03bb x H IH, \u27e8_, \u03bb o h, begin\n  rcases typein_surj r (lt_trans h (typein_lt_type r _)) with \u27e8b, rfl\u27e9,\n  exact IH _ ((typein_lt_typein r).1 h)\nend\u27e9\u27e9\n\ninstance : has_well_founded ordinal := \u27e8(<), lt_wf\u27e9\n\n/-- Reformulation of well founded induction on ordinals as a lemma that works with the\n`induction` tactic, as in `induction i using ordinal.induction with i IH`. -/\nlemma induction {p : ordinal.{u} \u2192 Prop} (i : ordinal.{u})\n  (h : \u2200 j, (\u2200 k, k < j \u2192 p k) \u2192 p j) : p i :=\nlt_wf.induction i h\n\n/-- Principal segment version of the `typein` function, embedding a well order into\n  ordinals as a principal segment. -/\ndef typein.principal_seg {\u03b1 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  @principal_seg \u03b1 ordinal.{u} r (<) :=\n\u27e8rel_embedding.of_monotone (typein r)\n  (\u03bb a b, (typein_lt_typein r).2), type r, \u03bb b,\n    \u27e8\u03bb h, \u27e8enum r _ h, typein_enum r h\u27e9,\n    \u03bb \u27e8a, e\u27e9, e \u25b8 typein_lt_type _ _\u27e9\u27e9\n\n@[simp] theorem typein.principal_seg_coe (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  (typein.principal_seg r : \u03b1 \u2192 ordinal) = typein r := rfl\n\n/-! ### Cardinality of ordinals -/\n\n/-- The cardinal of an ordinal is the cardinality of any type on which a relation with that order\ntype is defined. -/\ndef card : ordinal \u2192 cardinal := quotient.map Well_order.\u03b1 $ \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8e\u27e9, \u27e8e.to_equiv\u27e9\n\n@[simp] theorem card_type (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] : card (type r) = #\u03b1 := rfl\n\n@[simp] lemma card_typein {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [wo : is_well_order \u03b1 r] (x : \u03b1) :\n  #{y // r y x} = (typein r x).card :=\nrfl\n\ntheorem card_le_card {o\u2081 o\u2082 : ordinal} : o\u2081 \u2264 o\u2082 \u2192 card o\u2081 \u2264 card o\u2082 :=\ninduction_on o\u2081 $ \u03bb \u03b1 r _, induction_on o\u2082 $ \u03bb \u03b2 s _ \u27e8\u27e8\u27e8f, _\u27e9, _\u27e9\u27e9, \u27e8f\u27e9\n\n@[simp] theorem card_zero : card 0 = 0 := rfl\n\n@[simp] theorem card_eq_zero {o} : card o = 0 \u2194 o = 0 :=\n\u27e8induction_on o $ \u03bb \u03b1 r _ h, begin\n  haveI := cardinal.mk_eq_zero_iff.1 h,\n  apply type_eq_zero_of_empty\nend, \u03bb e, by simp only [e, card_zero]\u27e9\n\n@[simp] theorem card_one : card 1 = 1 := rfl\n\n/-! ### Lifting ordinals to a higher universe -/\n\n/-- The universe lift operation for ordinals, which embeds `ordinal.{u}` as\n  a proper initial segment of `ordinal.{v}` for `v > u`. For the initial segment version,\n  see `lift.initial_seg`. -/\ndef lift (o : ordinal.{v}) : ordinal.{max v u} :=\nquotient.lift_on o (\u03bb w, type $ ulift.down \u207b\u00b9'o w.r) $\n  \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8f\u27e9, quot.sound \u27e8(rel_iso.preimage equiv.ulift r).trans $\n    f.trans (rel_iso.preimage equiv.ulift s).symm\u27e9\n\n@[simp] theorem type_ulift (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] :\n  type (ulift.down \u207b\u00b9'o r) = lift.{v} (type r) :=\nrfl\n\ntheorem _root_.rel_iso.ordinal_lift_type_eq {\u03b1 : Type u} {\u03b2 : Type v}\n  {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {s : \u03b2 \u2192 \u03b2 \u2192 Prop} [is_well_order \u03b1 r] [is_well_order \u03b2 s] (f : r \u2243r s) :\n  lift.{v} (type r) = lift.{u} (type s) :=\n((rel_iso.preimage equiv.ulift r).trans $\n  f.trans (rel_iso.preimage equiv.ulift s).symm).ordinal_type_eq\n\n@[simp] theorem type_lift_preimage {\u03b1 : Type u} {\u03b2 : Type v} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r]\n  (f : \u03b2 \u2243 \u03b1) : lift.{u} (type (f \u207b\u00b9'o r)) = lift.{v} (type r) :=\n(rel_iso.preimage f r).ordinal_lift_type_eq\n\n/-- `lift.{(max u v) u}` equals `lift.{v u}`. Using `set_option pp.universes true` will make it much\n    easier to understand what's happening when using this lemma. -/\n@[simp] theorem lift_umax : lift.{(max u v) u} = lift.{v u} :=\nfunext $ \u03bb a, induction_on a $ \u03bb \u03b1 r _,\nquotient.sound \u27e8(rel_iso.preimage equiv.ulift r).trans (rel_iso.preimage equiv.ulift r).symm\u27e9\n\n/-- `lift.{(max v u) u}` equals `lift.{v u}`. Using `set_option pp.universes true` will make it much\n    easier to understand what's happening when using this lemma. -/\n@[simp] theorem lift_umax' : lift.{(max v u) u} = lift.{v u} := lift_umax\n\n/-- An ordinal lifted to a lower or equal universe equals itself. -/\n@[simp] theorem lift_id' (a : ordinal) : lift a = a :=\ninduction_on a $ \u03bb \u03b1 r _, quotient.sound \u27e8rel_iso.preimage equiv.ulift r\u27e9\n\n/-- An ordinal lifted to the same universe equals itself. -/\n@[simp] theorem lift_id : \u2200 a, lift.{u u} a = a := lift_id'.{u u}\n\n/-- An ordinal lifted to the zero universe equals itself. -/\n@[simp] theorem lift_uzero (a : ordinal.{u}) : lift.{0} a = a := lift_id'.{0 u} a\n\n@[simp] theorem lift_lift (a : ordinal) : lift.{w} (lift.{v} a) = lift.{max v w} a :=\ninduction_on a $ \u03bb \u03b1 r _,\nquotient.sound \u27e8(rel_iso.preimage equiv.ulift _).trans $\n  (rel_iso.preimage equiv.ulift _).trans (rel_iso.preimage equiv.ulift _).symm\u27e9\n\ntheorem lift_type_le {\u03b1 : Type u} {\u03b2 : Type v} {r s} [is_well_order \u03b1 r] [is_well_order \u03b2 s] :\n  lift.{max v w} (type r) \u2264 lift.{max u w} (type s) \u2194 nonempty (r \u227ci s) :=\n\u27e8\u03bb \u27e8f\u27e9, \u27e8(initial_seg.of_iso (rel_iso.preimage equiv.ulift r).symm).trans $\n    f.trans (initial_seg.of_iso (rel_iso.preimage equiv.ulift s))\u27e9,\n \u03bb \u27e8f\u27e9, \u27e8(initial_seg.of_iso (rel_iso.preimage equiv.ulift r)).trans $\n    f.trans (initial_seg.of_iso (rel_iso.preimage equiv.ulift s).symm)\u27e9\u27e9\n\ntheorem lift_type_eq {\u03b1 : Type u} {\u03b2 : Type v} {r s} [is_well_order \u03b1 r] [is_well_order \u03b2 s] :\n  lift.{max v w} (type r) = lift.{max u w} (type s) \u2194 nonempty (r \u2243r s) :=\nquotient.eq.trans\n\u27e8\u03bb \u27e8f\u27e9, \u27e8(rel_iso.preimage equiv.ulift r).symm.trans $\n    f.trans (rel_iso.preimage equiv.ulift s)\u27e9,\n \u03bb \u27e8f\u27e9, \u27e8(rel_iso.preimage equiv.ulift r).trans $\n    f.trans (rel_iso.preimage equiv.ulift s).symm\u27e9\u27e9\n\ntheorem lift_type_lt {\u03b1 : Type u} {\u03b2 : Type v} {r s} [is_well_order \u03b1 r] [is_well_order \u03b2 s] :\n  lift.{max v w} (type r) < lift.{max u w} (type s) \u2194 nonempty (r \u227ai s) :=\nby haveI := @rel_embedding.is_well_order _ _ (@equiv.ulift.{max v w} \u03b1 \u207b\u00b9'o r)\n     r (rel_iso.preimage equiv.ulift.{max v w} r) _;\n   haveI := @rel_embedding.is_well_order _ _ (@equiv.ulift.{max u w} \u03b2 \u207b\u00b9'o s)\n     s (rel_iso.preimage equiv.ulift.{max u w} s) _; exact\n\u27e8\u03bb \u27e8f\u27e9, \u27e8(f.equiv_lt (rel_iso.preimage equiv.ulift r).symm).lt_le\n    (initial_seg.of_iso (rel_iso.preimage equiv.ulift s))\u27e9,\n \u03bb \u27e8f\u27e9, \u27e8(f.equiv_lt (rel_iso.preimage equiv.ulift r)).lt_le\n    (initial_seg.of_iso (rel_iso.preimage equiv.ulift s).symm)\u27e9\u27e9\n\n@[simp] theorem lift_le {a b : ordinal} : lift.{u v} a \u2264 lift b \u2194 a \u2264 b :=\ninduction_on a $ \u03bb \u03b1 r _, induction_on b $ \u03bb \u03b2 s _, by { rw \u2190 lift_umax, exactI lift_type_le }\n\n@[simp] theorem lift_inj {a b : ordinal} : lift a = lift b \u2194 a = b :=\nby simp only [le_antisymm_iff, lift_le]\n\n@[simp] theorem lift_lt {a b : ordinal} : lift a < lift b \u2194 a < b :=\nby simp only [lt_iff_le_not_le, lift_le]\n\n@[simp] theorem lift_zero : lift 0 = 0 := type_eq_zero_of_empty _\n@[simp] theorem lift_one : lift 1 = 1 := type_eq_one_of_unique _\n\n@[simp] theorem lift_card (a) : (card a).lift = card (lift a) :=\ninduction_on a $ \u03bb \u03b1 r _, rfl\n\ntheorem lift_down' {a : cardinal.{u}} {b : ordinal.{max u v}}\n  (h : card b \u2264 a.lift) : \u2203 a', lift a' = b :=\nlet \u27e8c, e\u27e9 := cardinal.lift_down h in\ncardinal.induction_on c (\u03bb \u03b1, induction_on b $ \u03bb \u03b2 s _ e', begin\n  resetI,\n  rw [card_type, \u2190 cardinal.lift_id'.{(max u v) u} (#\u03b2),\n      \u2190 cardinal.lift_umax.{u v}, lift_mk_eq.{u (max u v) (max u v)}] at e',\n  cases e' with f,\n  have g := rel_iso.preimage f s,\n  haveI := (g : \u21d1f \u207b\u00b9'o s \u21aar s).is_well_order,\n  have := lift_type_eq.{u (max u v) (max u v)}.2 \u27e8g\u27e9,\n  rw [lift_id, lift_umax.{u v}] at this,\n  exact \u27e8_, this\u27e9\nend) e\n\ntheorem lift_down {a : ordinal.{u}} {b : ordinal.{max u v}}\n  (h : b \u2264 lift a) : \u2203 a', lift a' = b :=\n@lift_down' (card a) _ (by rw lift_card; exact card_le_card h)\n\n\n\ntheorem lt_lift_iff {a : ordinal.{u}} {b : ordinal.{max u v}} :\n  b < lift a \u2194 \u2203 a', lift a' = b \u2227 a' < a :=\n\u27e8\u03bb h, let \u27e8a', e\u27e9 := lift_down (le_of_lt h) in\n      \u27e8a', e, lift_lt.1 $ e.symm \u25b8 h\u27e9,\n \u03bb \u27e8a', e, h\u27e9, e \u25b8 lift_lt.2 h\u27e9\n\n/-- Initial segment version of the lift operation on ordinals, embedding `ordinal.{u}` in\n  `ordinal.{v}` as an initial segment when `u \u2264 v`. -/\ndef lift.initial_seg : @initial_seg ordinal.{u} ordinal.{max u v} (<) (<) :=\n\u27e8\u27e8\u27e8lift.{v}, \u03bb a b, lift_inj.1\u27e9, \u03bb a b, lift_lt\u27e9,\n  \u03bb a b h, lift_down (le_of_lt h)\u27e9\n\n@[simp] theorem lift.initial_seg_coe : (lift.initial_seg : ordinal \u2192 ordinal) = lift := rfl\n\n/-! ### The first infinite ordinal `omega` -/\n\n/-- `\u03c9` is the first infinite ordinal, defined as the order type of `\u2115`. -/\ndef omega : ordinal.{u} := lift $ @type \u2115 (<) _\n\nlocalized \"notation (name := ordinal.omega) `\u03c9` := ordinal.omega\" in ordinal\n\n/-- Note that the presence of this lemma makes `simp [omega]` form a loop. -/\n@[simp] theorem type_nat_lt : @type \u2115 (<) _ = \u03c9 := (lift_id _).symm\n\n@[simp] theorem card_omega : card \u03c9 = \u2135\u2080 := rfl\n\n@[simp] theorem lift_omega : lift \u03c9 = \u03c9 := lift_lift _\n\n/-!\n### Definition and first properties of addition on ordinals\n\nIn this paragraph, we introduce the addition on ordinals, and prove just enough properties to\ndeduce that the order on ordinals is total (and therefore well-founded). Further properties of\nthe addition, together with properties of the other operations, are proved in\n`ordinal_arithmetic.lean`.\n-/\n\n/-- `o\u2081 + o\u2082` is the order on the disjoint union of `o\u2081` and `o\u2082` obtained by declaring that\n  every element of `o\u2081` is smaller than every element of `o\u2082`. -/\ninstance : has_add ordinal.{u} :=\n\u27e8\u03bb o\u2081 o\u2082, quotient.lift_on\u2082 o\u2081 o\u2082\n  (\u03bb \u27e8\u03b1, r, wo\u27e9 \u27e8\u03b2, s, wo'\u27e9, by exactI type (sum.lex r s)) $\n  \u03bb \u27e8\u03b1\u2081, r\u2081, o\u2081\u27e9 \u27e8\u03b1\u2082, r\u2082, o\u2082\u27e9 \u27e8\u03b2\u2081, s\u2081, p\u2081\u27e9 \u27e8\u03b2\u2082, s\u2082, p\u2082\u27e9 \u27e8f\u27e9 \u27e8g\u27e9,\n  quot.sound \u27e8rel_iso.sum_lex_congr f g\u27e9\u27e9\n\ninstance : add_monoid_with_one ordinal.{u} :=\n{ add       := (+),\n  zero      := 0,\n  one       := 1,\n  zero_add  := \u03bb o, induction_on o $ \u03bb \u03b1 r _, eq.symm $ quotient.sound\n    \u27e8\u27e8(empty_sum pempty \u03b1).symm, \u03bb a b, sum.lex_inr_inr\u27e9\u27e9,\n  add_zero  := \u03bb o, induction_on o $ \u03bb \u03b1 r _, eq.symm $ quotient.sound\n    \u27e8\u27e8(sum_empty \u03b1 pempty).symm, \u03bb a b, sum.lex_inl_inl\u27e9\u27e9,\n  add_assoc := \u03bb o\u2081 o\u2082 o\u2083, quotient.induction_on\u2083 o\u2081 o\u2082 o\u2083 $\n    \u03bb \u27e8\u03b1, r, _\u27e9 \u27e8\u03b2, s, _\u27e9 \u27e8\u03b3, t, _\u27e9, quot.sound\n    \u27e8\u27e8sum_assoc _ _ _, \u03bb a b,\n    begin rcases a with \u27e8a|a\u27e9|a; rcases b with \u27e8b|b\u27e9|b;\n      simp only [sum_assoc_apply_inl_inl, sum_assoc_apply_inl_inr, sum_assoc_apply_inr,\n        sum.lex_inl_inl, sum.lex_inr_inr, sum.lex.sep, sum.lex_inr_inl] end\u27e9\u27e9 }\n\n@[simp] theorem card_add (o\u2081 o\u2082 : ordinal) : card (o\u2081 + o\u2082) = card o\u2081 + card o\u2082 :=\ninduction_on o\u2081 $ \u03bb \u03b1 r _, induction_on o\u2082 $ \u03bb \u03b2 s _, rfl\n\n@[simp] theorem type_sum_lex {\u03b1 \u03b2 : Type u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (s : \u03b2 \u2192 \u03b2 \u2192 Prop)\n  [is_well_order \u03b1 r] [is_well_order \u03b2 s] : type (sum.lex r s) = type r + type s := rfl\n\n@[simp] theorem card_nat (n : \u2115) : card.{u} n = n :=\nby induction n; [refl, simp only [card_add, card_one, nat.cast_succ, *]]\n\ninstance add_covariant_class_le : covariant_class ordinal.{u} ordinal.{u} (+) (\u2264) :=\n\u27e8\u03bb c a b h, begin\n  revert h c, exact (\n  induction_on a $ \u03bb \u03b1\u2081 r\u2081 _, induction_on b $ \u03bb \u03b1\u2082 r\u2082 _ \u27e8\u27e8\u27e8f, fo\u27e9, fi\u27e9\u27e9 c,\n  induction_on c $ \u03bb \u03b2 s _,\n  \u27e8\u27e8\u27e8(embedding.refl _).sum_map f,\n    \u03bb a b, match a, b with\n      | sum.inl a, sum.inl b := sum.lex_inl_inl.trans sum.lex_inl_inl.symm\n      | sum.inl a, sum.inr b := by apply iff_of_true; apply sum.lex.sep\n      | sum.inr a, sum.inl b := by apply iff_of_false; exact sum.lex_inr_inl\n      | sum.inr a, sum.inr b := sum.lex_inr_inr.trans $ fo.trans sum.lex_inr_inr.symm\n      end\u27e9,\n    \u03bb a b H, match a, b, H with\n      | _,         sum.inl b, _ := \u27e8sum.inl b, rfl\u27e9\n      | sum.inl a, sum.inr b, H := (sum.lex_inr_inl H).elim\n      | sum.inr a, sum.inr b, H := let \u27e8w, h\u27e9 := fi _ _ (sum.lex_inr_inr.1 H) in\n          \u27e8sum.inr w, congr_arg sum.inr h\u27e9\n    end\u27e9\u27e9)\nend\u27e9\n\ninstance add_swap_covariant_class_le : covariant_class ordinal.{u} ordinal.{u} (swap (+)) (\u2264) :=\n\u27e8\u03bb c a b h, begin\n  revert h c, exact (\n  induction_on a $ \u03bb \u03b1\u2081 r\u2081 hr\u2081, induction_on b $ \u03bb \u03b1\u2082 r\u2082 hr\u2082 \u27e8\u27e8\u27e8f, fo\u27e9, fi\u27e9\u27e9 c,\n  induction_on c $ \u03bb \u03b2 s hs, by exactI\n  @rel_embedding.ordinal_type_le _ _ (sum.lex r\u2081 s) (sum.lex r\u2082 s) _ _\n  \u27e8f.sum_map (embedding.refl _), \u03bb a b, begin\n    split; intro H,\n    { cases a with a a; cases b with b b; cases H; constructor; [rwa \u2190 fo, assumption] },\n    { cases H; constructor; [rwa fo, assumption] }\n  end\u27e9)\nend\u27e9\n\ntheorem le_add_right (a b : ordinal) : a \u2264 a + b :=\nby simpa only [add_zero] using add_le_add_left (ordinal.zero_le b) a\n\ntheorem le_add_left (a b : ordinal) : a \u2264 b + a :=\nby simpa only [zero_add] using add_le_add_right (ordinal.zero_le b) a\n\ninstance : linear_order ordinal :=\n{ le_total     := \u03bb a b,\n    match lt_or_eq_of_le (le_add_left b a), lt_or_eq_of_le (le_add_right a b) with\n    | or.inr h, _ := by rw h; exact or.inl (le_add_right _ _)\n    | _, or.inr h := by rw h; exact or.inr (le_add_left _ _)\n    | or.inl h\u2081, or.inl h\u2082 := induction_on a (\u03bb \u03b1\u2081 r\u2081 _,\n      induction_on b $ \u03bb \u03b1\u2082 r\u2082 _ \u27e8f\u27e9 \u27e8g\u27e9, begin\n        resetI,\n        rw [\u2190 typein_top f, \u2190 typein_top g, le_iff_lt_or_eq,\n            le_iff_lt_or_eq, typein_lt_typein, typein_lt_typein],\n        rcases trichotomous_of (sum.lex r\u2081 r\u2082) g.top f.top with h|h|h;\n        [exact or.inl (or.inl h), {left, right, rw h}, exact or.inr (or.inl h)]\n      end) h\u2081 h\u2082\n    end,\n  decidable_le := classical.dec_rel _,\n  ..ordinal.partial_order }\n\ninstance : well_founded_lt ordinal := \u27e8lt_wf\u27e9\ninstance : is_well_order ordinal (<) := { }\n\ninstance : conditionally_complete_linear_order_bot ordinal :=\nis_well_order.conditionally_complete_linear_order_bot _\n\n@[simp] lemma max_zero_left : \u2200 a : ordinal, max 0 a = a := max_bot_left\n@[simp] lemma max_zero_right : \u2200 a : ordinal, max a 0 = a := max_bot_right\n@[simp] lemma max_eq_zero {a b : ordinal} : max a b = 0 \u2194 a = 0 \u2227 b = 0 := max_eq_bot\n\n@[simp] theorem Inf_empty : Inf (\u2205 : set ordinal) = 0 :=\ndif_neg not_nonempty_empty\n\n/- ### Successor order properties -/\n\nprivate theorem succ_le_iff' {a b : ordinal} : a + 1 \u2264 b \u2194 a < b :=\n\u27e8lt_of_lt_of_le (induction_on a $ \u03bb \u03b1 r _, \u27e8\u27e8\u27e8\u27e8\u03bb x, sum.inl x, \u03bb _ _, sum.inl.inj\u27e9,\n  \u03bb _ _, sum.lex_inl_inl\u27e9,\n  sum.inr punit.star, \u03bb b, sum.rec_on b\n    (\u03bb x, \u27e8\u03bb _, \u27e8x, rfl\u27e9, \u03bb _, sum.lex.sep _ _\u27e9)\n    (\u03bb x, sum.lex_inr_inr.trans \u27e8false.elim, \u03bb \u27e8x, H\u27e9, sum.inl_ne_inr H\u27e9)\u27e9\u27e9),\ninduction_on a $ \u03bb \u03b1 r hr, induction_on b $ \u03bb \u03b2 s hs \u27e8\u27e8f, t, hf\u27e9\u27e9, begin\n  haveI := hs,\n  refine \u27e8\u27e8@rel_embedding.of_monotone (\u03b1 \u2295 punit) \u03b2 _ _ _ _ (sum.rec _ _) (\u03bb a b, _), \u03bb a b, _\u27e9\u27e9,\n  { exact f }, { exact \u03bb _, t },\n  { rcases a with a|_; rcases b with b|_,\n    { simpa only [sum.lex_inl_inl] using f.map_rel_iff.2 },\n    { intro _, rw hf, exact \u27e8_, rfl\u27e9 },\n    { exact false.elim \u2218 sum.lex_inr_inl },\n    { exact false.elim \u2218 sum.lex_inr_inr.1 } },\n  { rcases a with a|_,\n    { intro h, have := @principal_seg.init _ _ _ _ _ \u27e8f, t, hf\u27e9 _ _ h,\n      cases this with w h, exact \u27e8sum.inl w, h\u27e9 },\n    { intro h, cases (hf b).1 h with w h, exact \u27e8sum.inl w, h\u27e9 } }\nend\u27e9\n\ninstance : no_max_order ordinal := \u27e8\u03bb a, \u27e8_, succ_le_iff'.1 le_rfl\u27e9\u27e9\n\ninstance : succ_order ordinal.{u} := succ_order.of_succ_le_iff (\u03bb o, o + 1) (\u03bb a b, succ_le_iff')\n\n@[simp] theorem add_one_eq_succ (o : ordinal) : o + 1 = succ o := rfl\n\n@[simp] theorem succ_zero : succ (0 : ordinal) = 1 := zero_add 1\n@[simp] theorem succ_one : succ (1 : ordinal) = 2 := rfl\n\ntheorem add_succ (o\u2081 o\u2082 : ordinal) : o\u2081 + succ o\u2082 = succ (o\u2081 + o\u2082) :=\n(add_assoc _ _ _).symm\n\ntheorem one_le_iff_pos {o : ordinal} : 1 \u2264 o \u2194 0 < o :=\nby rw [\u2190 succ_zero, succ_le_iff]\n\ntheorem one_le_iff_ne_zero {o : ordinal} : 1 \u2264 o \u2194 o \u2260 0 :=\nby rw [one_le_iff_pos, ordinal.pos_iff_ne_zero]\n\ntheorem succ_pos (o : ordinal) : 0 < succ o := bot_lt_succ o\ntheorem succ_ne_zero (o : ordinal) : succ o \u2260 0 := ne_of_gt $ succ_pos o\ntheorem lt_one_iff_zero {a : ordinal} : a < 1 \u2194 a = 0 := by simpa using @lt_succ_bot_iff _ _ _ a _ _\ntheorem le_one_iff {a : ordinal} : a \u2264 1 \u2194 a = 0 \u2228 a = 1 :=\nby simpa using @le_succ_bot_iff _ _ _ a _\n\n@[simp] theorem card_succ (o : ordinal) : card (succ o) = card o + 1 :=\nby simp only [\u2190add_one_eq_succ, card_add, card_one]\n\ntheorem nat_cast_succ (n : \u2115) : \u2191n.succ = succ (n : ordinal) := rfl\n\ninstance unique_Iio_one : unique (Iio (1 : ordinal)) :=\n{ default := \u27e80, zero_lt_one\u27e9,\n  uniq := \u03bb a, subtype.ext $ lt_one_iff_zero.1 a.prop }\n\ninstance unique_out_one : unique (1 : ordinal).out.\u03b1 :=\n{ default := enum (<) 0 (by simp),\n  uniq := \u03bb a, begin\n    rw \u2190enum_typein (<) a,\n    unfold default,\n    congr,\n    rw \u2190lt_one_iff_zero,\n    apply typein_lt_self\n  end }\n\ntheorem one_out_eq (x : (1 : ordinal).out.\u03b1) : x = enum (<) 0 (by simp) := unique.eq_default x\n\n/-! ### Extra properties of typein and enum -/\n\n@[simp] theorem typein_one_out (x : (1 : ordinal).out.\u03b1) : typein (<) x = 0 :=\nby rw [one_out_eq x, typein_enum]\n\n@[simp] lemma typein_le_typein (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] {x x' : \u03b1} :\n  typein r x \u2264 typein r x' \u2194 \u00acr x' x :=\nby rw [\u2190not_lt, typein_lt_typein]\n\n@[simp] lemma typein_le_typein' (o : ordinal) {x x' : o.out.\u03b1} :\n  typein (<) x \u2264 typein (<) x' \u2194 x \u2264 x' :=\nby { rw typein_le_typein, exact not_lt }\n\n@[simp] lemma enum_le_enum (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] {o o' : ordinal}\n  (ho : o < type r) (ho' : o' < type r) : \u00acr (enum r o' ho') (enum r o ho) \u2194 o \u2264 o' :=\nby rw [\u2190@not_lt _ _ o' o, enum_lt_enum ho']\n\n@[simp] lemma enum_le_enum' (a : ordinal) {o o' : ordinal}\n  (ho : o < type (<)) (ho' : o' < type (<)) : enum (<) o ho \u2264 @enum a.out.\u03b1 (<) _ o' ho' \u2194 o \u2264 o' :=\nby rw [\u2190enum_le_enum (<), \u2190not_lt]\n\ntheorem enum_zero_le {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_well_order \u03b1 r] (h0 : 0 < type r) (a : \u03b1) :\n  \u00ac r a (enum r 0 h0) :=\nby { rw [\u2190enum_typein r a, enum_le_enum r], apply ordinal.zero_le }\n\ntheorem enum_zero_le' {o : ordinal} (h0 : 0 < o) (a : o.out.\u03b1) :\n  @enum o.out.\u03b1 (<) _ 0 (by rwa type_lt) \u2264 a :=\nby { rw \u2190not_lt, apply enum_zero_le }\n\ntheorem le_enum_succ {o : ordinal} (a : (succ o).out.\u03b1) :\n  a \u2264 @enum (succ o).out.\u03b1 (<) _ o (by { rw type_lt, exact lt_succ o }) :=\nby { rw [\u2190enum_typein (<) a, enum_le_enum', \u2190lt_succ_iff], apply typein_lt_self }\n\n@[simp] theorem enum_inj {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [is_well_order \u03b1 r] {o\u2081 o\u2082 : ordinal} (h\u2081 : o\u2081 < type r)\n  (h\u2082 : o\u2082 < type r) : enum r o\u2081 h\u2081 = enum r o\u2082 h\u2082 \u2194 o\u2081 = o\u2082 :=\n\u27e8\u03bb h, begin\n  by_contra hne,\n  cases lt_or_gt_of_ne hne with hlt hlt;\n    apply (is_well_order.is_irrefl r).1,\n    { rwa [\u2190@enum_lt_enum \u03b1 r _ o\u2081 o\u2082 h\u2081 h\u2082, h] at hlt },\n    { change _ < _ at hlt, rwa [\u2190@enum_lt_enum \u03b1 r _ o\u2082 o\u2081 h\u2082 h\u2081, h] at hlt }\nend, \u03bb h, by simp_rw h\u27e9\n\n/-- A well order `r` is order isomorphic to the set of ordinals smaller than `type r`. -/\n@[simps] def enum_iso (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] : subrel (<) (< type r) \u2243r r :=\n{ to_fun := \u03bb x, enum r x.1 x.2,\n  inv_fun := \u03bb x, \u27e8typein r x, typein_lt_type r x\u27e9,\n  left_inv := \u03bb \u27e8o, h\u27e9, subtype.ext_val (typein_enum _ _),\n  right_inv := \u03bb h, enum_typein _ _,\n  map_rel_iff' := by { rintros \u27e8a, _\u27e9 \u27e8b, _\u27e9, apply enum_lt_enum } }\n\n/-- The order isomorphism between ordinals less than `o` and `o.out.\u03b1`. -/\n@[simps] noncomputable def enum_iso_out (o : ordinal) : set.Iio o \u2243o o.out.\u03b1 :=\n{ to_fun := \u03bb x, enum (<) x.1 $ by { rw type_lt, exact x.2 },\n  inv_fun := \u03bb x, \u27e8typein (<) x, typein_lt_self x\u27e9,\n  left_inv := \u03bb \u27e8o', h\u27e9, subtype.ext_val (typein_enum _ _),\n  right_inv := \u03bb h, enum_typein _ _,\n  map_rel_iff' := by { rintros \u27e8a, _\u27e9 \u27e8b, _\u27e9, apply enum_le_enum' } }\n\n/-- `o.out.\u03b1` is an `order_bot` whenever `0 < o`. -/\ndef out_order_bot_of_pos {o : ordinal} (ho : 0 < o) : order_bot o.out.\u03b1 :=\n\u27e8_, enum_zero_le' ho\u27e9\n\ntheorem enum_zero_eq_bot {o : ordinal} (ho : 0 < o) :\n  enum (<) 0 (by rwa type_lt) = by { haveI H := out_order_bot_of_pos ho, exact \u22a5 } :=\nrfl\n\n/-! ### Universal ordinal -/\n\n/-- `univ.{u v}` is the order type of the ordinals of `Type u` as a member\n  of `ordinal.{v}` (when `u < v`). It is an inaccessible cardinal. -/\n@[nolint check_univs] -- intended to be used with explicit universe parameters\ndef univ : ordinal.{max (u + 1) v} := lift.{v (u+1)} (@type ordinal (<) _)\n\ntheorem univ_id : univ.{u (u+1)} = @type ordinal (<) _ := lift_id _\n\n@[simp] theorem lift_univ : lift.{w} univ.{u v} = univ.{u (max v w)} := lift_lift _\n\ntheorem univ_umax : univ.{u (max (u+1) v)} = univ.{u v} := congr_fun lift_umax _\n\n/-- Principal segment version of the lift operation on ordinals, embedding `ordinal.{u}` in\n  `ordinal.{v}` as a principal segment when `u < v`. -/\ndef lift.principal_seg : @principal_seg ordinal.{u} ordinal.{max (u+1) v} (<) (<) :=\n\u27e8\u2191lift.initial_seg.{u (max (u+1) v)}, univ.{u v}, begin\n  refine \u03bb b, induction_on b _, introsI \u03b2 s _,\n  rw [univ, \u2190 lift_umax], split; intro h,\n  { rw \u2190 lift_id (type s) at h \u22a2,\n    cases lift_type_lt.1 h with f, cases f with f a hf,\n    existsi a, revert hf,\n    apply induction_on a, introsI \u03b1 r _ hf,\n    refine lift_type_eq.{u (max (u+1) v) (max (u+1) v)}.2\n      \u27e8(rel_iso.of_surjective (rel_embedding.of_monotone _ _) _).symm\u27e9,\n    { exact \u03bb b, enum r (f b) ((hf _).2 \u27e8_, rfl\u27e9) },\n    { refine \u03bb a b h, (typein_lt_typein r).1 _,\n      rw [typein_enum, typein_enum],\n      exact f.map_rel_iff.2 h },\n    { intro a', cases (hf _).1 (typein_lt_type _ a') with b e,\n      existsi b, simp, simp [e] } },\n  { cases h with a e, rw [\u2190 e],\n    apply induction_on a, introsI \u03b1 r _,\n    exact lift_type_lt.{u (u+1) (max (u+1) v)}.2\n      \u27e8typein.principal_seg r\u27e9 }\nend\u27e9\n\n@[simp] theorem lift.principal_seg_coe :\n  (lift.principal_seg.{u v} : ordinal \u2192 ordinal) = lift.{max (u+1) v} := rfl\n\n@[simp] theorem lift.principal_seg_top : lift.principal_seg.top = univ := rfl\n\ntheorem lift.principal_seg_top' :\n  lift.principal_seg.{u (u+1)}.top = @type ordinal (<) _ :=\nby simp only [lift.principal_seg_top, univ_id]\n\nend ordinal\n\n/-! ### Representing a cardinal with an ordinal -/\n\nnamespace cardinal\nopen ordinal\n\n@[simp] theorem mk_ordinal_out (o : ordinal) : #(o.out.\u03b1) = o.card :=\n(ordinal.card_type _).symm.trans $ by rw ordinal.type_lt\n\n/-- The ordinal corresponding to a cardinal `c` is the least ordinal\n  whose cardinal is `c`. For the order-embedding version, see `ord.order_embedding`. -/\ndef ord (c : cardinal) : ordinal :=\nlet F := \u03bb \u03b1 : Type u, \u2a05 r : {r // is_well_order \u03b1 r}, @type \u03b1 r.1 r.2 in\nquot.lift_on c F\nbegin\n  suffices : \u2200 {\u03b1 \u03b2}, \u03b1 \u2248 \u03b2 \u2192 F \u03b1 \u2264 F \u03b2,\n  from \u03bb \u03b1 \u03b2 h, (this h).antisymm (this (setoid.symm h)),\n  rintros \u03b1 \u03b2 \u27e8f\u27e9,\n  refine le_cinfi_iff'.2 (\u03bb i, _),\n  haveI := @rel_embedding.is_well_order _ _ (f \u207b\u00b9'o i.1) _ \u2191(rel_iso.preimage f i.1) i.2,\n  exact (cinfi_le' _ (subtype.mk (\u21d1f \u207b\u00b9'o i.val)\n    (@rel_embedding.is_well_order _ _  _ _ \u2191(rel_iso.preimage f i.1) i.2))).trans_eq\n    (quot.sound \u27e8rel_iso.preimage f i.1\u27e9)\nend\n\nlemma ord_eq_Inf (\u03b1 : Type u) : ord (#\u03b1) = \u2a05 r : {r // is_well_order \u03b1 r}, @type \u03b1 r.1 r.2 :=\nrfl\n\ntheorem ord_eq (\u03b1) : \u2203 (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [wo : is_well_order \u03b1 r], ord (#\u03b1) = @type \u03b1 r wo :=\nlet \u27e8r, wo\u27e9 := infi_mem (\u03bb r : {r // is_well_order \u03b1 r}, @type \u03b1 r.1 r.2) in \u27e8r.1, r.2, wo.symm\u27e9\n\ntheorem ord_le_type (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [h : is_well_order \u03b1 r] : ord (#\u03b1) \u2264 type r :=\ncinfi_le' _ (subtype.mk r h)\n\ntheorem ord_le {c o} : ord c \u2264 o \u2194 c \u2264 o.card :=\ninduction_on c $ \u03bb \u03b1, ordinal.induction_on o $ \u03bb \u03b2 s _,\nlet \u27e8r, _, e\u27e9 := ord_eq \u03b1 in begin\n  resetI, simp only [card_type], split; intro h,\n  { rw e at h, exact let \u27e8f\u27e9 := h in \u27e8f.to_embedding\u27e9 },\n  { cases h with f,\n    have g := rel_embedding.preimage f s,\n    haveI := rel_embedding.is_well_order g,\n    exact le_trans (ord_le_type _) g.ordinal_type_le }\nend\n\ntheorem gc_ord_card : galois_connection ord card := \u03bb _ _, ord_le\n\ntheorem lt_ord {c o} : o < ord c \u2194 o.card < c := gc_ord_card.lt_iff_lt\n\n@[simp] theorem card_ord (c) : (ord c).card = c :=\nquotient.induction_on c $ \u03bb \u03b1,\nlet \u27e8r, _, e\u27e9 := ord_eq \u03b1 in by simp only [mk_def, e, card_type]\n\n/-- Galois coinsertion between `cardinal.ord` and `ordinal.card`. -/\ndef gci_ord_card : galois_coinsertion ord card :=\ngc_ord_card.to_galois_coinsertion $ \u03bb c, c.card_ord.le\n\ntheorem ord_card_le (o : ordinal) : o.card.ord \u2264 o := gc_ord_card.l_u_le _\n\nlemma lt_ord_succ_card (o : ordinal) : o < (succ o.card).ord := lt_ord.2 $ lt_succ _\n\n@[mono] theorem ord_strict_mono : strict_mono ord := gci_ord_card.strict_mono_l\n@[mono] theorem ord_mono : monotone ord := gc_ord_card.monotone_l\n\n@[simp] theorem ord_le_ord {c\u2081 c\u2082} : ord c\u2081 \u2264 ord c\u2082 \u2194 c\u2081 \u2264 c\u2082 := gci_ord_card.l_le_l_iff\n@[simp] theorem ord_lt_ord {c\u2081 c\u2082} : ord c\u2081 < ord c\u2082 \u2194 c\u2081 < c\u2082 := ord_strict_mono.lt_iff_lt\n@[simp] theorem ord_zero : ord 0 = 0 := gc_ord_card.l_bot\n\n@[simp] theorem ord_nat (n : \u2115) : ord n = n :=\n(ord_le.2 (card_nat n).ge).antisymm begin\n  induction n with n IH,\n  { apply ordinal.zero_le },\n  { exact succ_le_of_lt (IH.trans_lt $ ord_lt_ord.2 $ nat_cast_lt.2 (nat.lt_succ_self n)) }\nend\n\n@[simp] theorem ord_one : ord 1 = 1 :=\nby simpa using ord_nat 1\n\n@[simp] theorem lift_ord (c) : (ord c).lift = ord (lift c) :=\nbegin\n  refine le_antisymm (le_of_forall_lt (\u03bb a ha, _)) _,\n  { rcases ordinal.lt_lift_iff.1 ha with \u27e8a, rfl, h\u27e9,\n    rwa [lt_ord, \u2190 lift_card, lift_lt, \u2190 lt_ord, \u2190 ordinal.lift_lt] },\n  { rw [ord_le, \u2190 lift_card, card_ord] }\nend\n\nlemma mk_ord_out (c : cardinal) : #c.ord.out.\u03b1 = c := by simp\n\nlemma card_typein_lt (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] (x : \u03b1)\n  (h : ord (#\u03b1) = type r) : card (typein r x) < #\u03b1 :=\nby { rw [\u2190lt_ord, h], apply typein_lt_type }\n\nlemma card_typein_out_lt (c : cardinal) (x : c.ord.out.\u03b1) : card (typein (<) x) < c :=\nby { rw \u2190lt_ord, apply typein_lt_self }\n\nlemma ord_injective : injective ord :=\nby { intros c c' h, rw [\u2190card_ord c, \u2190card_ord c', h] }\n\n/-- The ordinal corresponding to a cardinal `c` is the least ordinal\n  whose cardinal is `c`. This is the order-embedding version. For the regular function, see `ord`.\n-/\ndef ord.order_embedding : cardinal \u21aao ordinal :=\nrel_embedding.order_embedding_of_lt_embedding\n  (rel_embedding.of_monotone cardinal.ord $ \u03bb a b, cardinal.ord_lt_ord.2)\n\n@[simp] theorem ord.order_embedding_coe :\n  (ord.order_embedding : cardinal \u2192 ordinal) = ord := rfl\n\n/-- The cardinal `univ` is the cardinality of ordinal `univ`, or\n  equivalently the cardinal of `ordinal.{u}`, or `cardinal.{u}`,\n  as an element of `cardinal.{v}` (when `u < v`). -/\n@[nolint check_univs] -- intended to be used with explicit universe parameters\ndef univ := lift.{v (u+1)} (#ordinal)\n\ntheorem univ_id : univ.{u (u+1)} = #ordinal := lift_id _\n\n@[simp] theorem lift_univ : lift.{w} univ.{u v} = univ.{u (max v w)} := lift_lift _\n\ntheorem univ_umax : univ.{u (max (u+1) v)} = univ.{u v} := congr_fun lift_umax _\n\ntheorem lift_lt_univ (c : cardinal) : lift.{(u+1) u} c < univ.{u (u+1)} :=\nby simpa only [lift.principal_seg_coe, lift_ord, lift_succ, ord_le, succ_le_iff] using le_of_lt\n  (lift.principal_seg.{u (u+1)}.lt_top (succ c).ord)\n\ntheorem lift_lt_univ' (c : cardinal) : lift.{(max (u+1) v) u} c < univ.{u v} :=\nby simpa only [lift_lift, lift_univ, univ_umax] using\n  lift_lt.{_ (max (u+1) v)}.2 (lift_lt_univ c)\n\n@[simp] theorem ord_univ : ord univ.{u v} = ordinal.univ.{u v} :=\nle_antisymm (ord_card_le _) $ le_of_forall_lt $ \u03bb o h,\nlt_ord.2 begin\n  rcases lift.principal_seg.{u v}.down.1\n    (by simpa only [lift.principal_seg_coe] using h) with \u27e8o', rfl\u27e9,\n  simp only [lift.principal_seg_coe], rw [\u2190 lift_card],\n  apply lift_lt_univ'\nend\n\ntheorem lt_univ {c} : c < univ.{u (u+1)} \u2194 \u2203 c', c = lift.{(u+1) u} c' :=\n\u27e8\u03bb h, begin\n  have := ord_lt_ord.2 h,\n  rw ord_univ at this,\n  cases lift.principal_seg.{u (u+1)}.down.1\n    (by simpa only [lift.principal_seg_top]) with o e,\n  have := card_ord c,\n  rw [\u2190 e, lift.principal_seg_coe, \u2190 lift_card] at this,\n  exact \u27e8_, this.symm\u27e9\nend, \u03bb \u27e8c', e\u27e9, e.symm \u25b8 lift_lt_univ _\u27e9\n\ntheorem lt_univ' {c} : c < univ.{u v} \u2194 \u2203 c', c = lift.{(max (u+1) v) u} c' :=\n\u27e8\u03bb h, let \u27e8a, e, h'\u27e9 := lt_lift_iff.1 h in begin\n  rw [\u2190 univ_id] at h',\n  rcases lt_univ.{u}.1 h' with \u27e8c', rfl\u27e9,\n  exact \u27e8c', by simp only [e.symm, lift_lift]\u27e9\nend, \u03bb \u27e8c', e\u27e9, e.symm \u25b8 lift_lt_univ' _\u27e9\n\ntheorem small_iff_lift_mk_lt_univ {\u03b1 : Type u} :\n  small.{v} \u03b1 \u2194 cardinal.lift (#\u03b1) < univ.{v (max u (v + 1))} :=\nbegin\n  rw lt_univ',\n  split,\n  { rintro \u27e8\u03b2, e\u27e9,\n    exact \u27e8#\u03b2, lift_mk_eq.{u _ (v + 1)}.2 e\u27e9 },\n  { rintro \u27e8c, hc\u27e9,\n    exact \u27e8\u27e8c.out, lift_mk_eq.{u _ (v + 1)}.1 (hc.trans (congr rfl c.mk_out.symm))\u27e9\u27e9 }\nend\n\nend cardinal\n\nnamespace ordinal\n\n@[simp] theorem card_univ : card univ = cardinal.univ := rfl\n\n@[simp] theorem nat_le_card {o} {n : \u2115} : (n : cardinal) \u2264 card o \u2194 (n : ordinal) \u2264 o :=\nby rw [\u2190 cardinal.ord_le, cardinal.ord_nat]\n\n@[simp] theorem nat_lt_card {o} {n : \u2115} : (n : cardinal) < card o \u2194 (n : ordinal) < o :=\nby { rw [\u2190succ_le_iff, \u2190succ_le_iff, \u2190nat_succ, nat_le_card], refl }\n\n@[simp] theorem card_lt_nat {o} {n : \u2115} : card o < n \u2194 o < n :=\nlt_iff_lt_of_le_iff_le nat_le_card\n\n@[simp] theorem card_le_nat {o} {n : \u2115} : card o \u2264 n \u2194 o \u2264 n :=\nle_iff_le_iff_lt_iff_lt.2 nat_lt_card\n\n@[simp] theorem card_eq_nat {o} {n : \u2115} : card o = n \u2194 o = n :=\nby simp only [le_antisymm_iff, card_le_nat, nat_le_card]\n\n@[simp] theorem type_fintype (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [is_well_order \u03b1 r] [fintype \u03b1] :\n  type r = fintype.card \u03b1 :=\nby rw [\u2190card_eq_nat, card_type, mk_fintype]\n\ntheorem type_fin (n : \u2115) : @type (fin n) (<) _ = n := by simp\n\nend ordinal\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/set_theory/ordinal/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7015235486539769}}
{"text": "import subgroup_world.subgroup_inv -- hide\n\nvariables {G : Type} [group G] {H : set G} -- hide\n\n/-\n## The inverse of an element is in the group (II)\n\nThe following variation is useful because since it is an `\u2194` statement, it can be `rw`ritten.\n-/\n/- Symbol:\n\u2194 : \\iff\n\u2208 : \\in\nx\u207b\u00b9 : x\\-1\n-/\n/- Lemma:\nIf $H\\leq G$, then $x \\in H$ if and only if $x^{-1} \\in H$.\n-/\nlemma subgroup.inv_mem  [h : subgroup H] (x : G) : x \u2208 H \u2194 x\u207b\u00b9 \u2208 H :=\nbegin\n  split,\n  {\n    apply subgroup.inv_mem',\n  },\n  {\n    intro hg,\n    rw show x = x\u207b\u00b9\u207b\u00b9, by group,\n    apply subgroup.inv_mem',\n    assumption,\n  }\n\n\n\n\n\n\nend\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/subgroup_world/subgroup_inv_bis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.7015235486402803}}
{"text": "import Lean\n\nopen Lean\nopen Lean.Meta\nopen Lean.Elab.Tactic\n\nuniverse u\naxiom elimEx (motive : Nat \u2192 Nat \u2192 Sort u) (x y : Nat)\n  (diag  : (a : Nat) \u2192 motive a a)\n  (upper : (delta a : Nat) \u2192 motive a (a + delta.succ))\n  (lower : (delta a : Nat) \u2192 motive (a + delta.succ) a)\n  : motive y x\n\ntheorem ex1 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => apply Or.inl; apply Nat.leRefl\n  | lower d => apply Or.inl; show p \u2264 p + d.succ; admit\n  | upper d => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex2 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx\n  case lower => admit\n  case upper => admit\n  case diag  => apply Or.inl; apply Nat.leRefl\n\naxiom Nat.parityElim (motive : Nat \u2192 Sort u)\n  (even : (n : Nat) \u2192 motive (2*n))\n  (odd  : (n : Nat) \u2192 motive (2*n+1))\n  (n : Nat)\n  : motive n\n\ntheorem time2Eq (n : Nat) : 2*n = n + n := by\n  rw [Nat.mul_comm]\n  show (0 + n) + n = n+n\n  simp\n\ntheorem ex3 (n : Nat) : Exists (fun m => n = m + m \u2228 n = m + m + 1) := by\n  cases n using Nat.parityElim with\n  | even i =>\n    apply Exists.intro i\n    apply Or.inl\n    rw [time2Eq]\n  | odd i =>\n    apply Exists.intro i\n    apply Or.inr\n    rw [time2Eq]\n\nopen Nat in\ntheorem ex3b (n : Nat) : Exists (fun m => n = m + m \u2228 n = m + m + 1) := by\n  cases n using parityElim with\n  | even i =>\n    apply Exists.intro i\n    apply Or.inl\n    rw [time2Eq]\n  | odd i =>\n    apply Exists.intro i\n    apply Or.inr\n    rw [time2Eq]\n\ndef ex4 {\u03b1} (xs : List \u03b1) (h : xs = [] \u2192 False) : \u03b1 := by\n  cases he:xs with\n  | nil      => contradiction\n  | cons x _ => exact x\n\ndef ex5 {\u03b1} (xs : List \u03b1) (h : xs = [] \u2192 False) : \u03b1 := by\n  cases he:xs using List.casesOn with\n  | nil      => contradiction\n  | cons x _ => exact x\n\ntheorem ex6 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false :=\n  match he:f xs with\n  | true  => False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex7 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false := by\n  cases he:f xs with\n  | true  => exact False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex8 {\u03b1} (f : List \u03b1 \u2192 Bool) (h\u2081 : {xs : List \u03b1} \u2192 f xs = true \u2192 xs = []) (xs : List \u03b1) (h\u2082 : xs \u2260 []) : f xs = false := by\n  cases he:f xs using Bool.casesOn with\n  | true  => exact False.elim (h\u2082 (h\u2081 he))\n  | false => rfl\n\ntheorem ex9 (xs : List \u03b1) (h : xs = [] \u2192 False) : Nonempty \u03b1 := by\n  cases xs using List.rec with\n  | nil      => contradiction\n  | cons x _ => apply Nonempty.intro; assumption\n\ntheorem modLt (x : Nat) {y : Nat} (h : y > 0) : x % y < y := by\n  induction x, y using Nat.mod.inductionOn with\n  | ind x y h\u2081 ih =>\n    rw [Nat.mod_eq_sub_mod h\u2081.2]\n    exact ih h\n  | base x y h\u2081 =>\n    match Iff.mp (Decidable.notAndIffOrNot ..) h\u2081 with\n    | Or.inl h\u2081 => contradiction\n    | Or.inr h\u2081 =>\n      have hgt := Nat.gtOfNotLe h\u2081\n      have heq := Nat.mod_eq_of_lt hgt\n      rw [\u2190 heq] at hgt\n      assumption\n\ntheorem ex11 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\n  induction h using Or.casesOn with\n  | inr h  => ?myright\n  | inl h  => ?myleft\n  case myleft  => exact Or.inr h\n  case myright => exact Or.inl h\n\ntheorem ex12 {p q : Prop } (h : p \u2228 q) : q \u2228 p := by\n  cases h using Or.casesOn with\n  | inr h  => ?myright\n  | inl h  => ?myleft\n  case myleft  => exact Or.inr h\n  case myright => exact Or.inl h\n\ntheorem ex13 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => ?hlower\n  | upper d => ?hupper\n  case hdiag  => apply Or.inl; apply Nat.leRefl\n  case hlower => apply Or.inl; show p \u2264 p + d.succ; admit\n  case hupper => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex14 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => _\n  | upper d => ?hupper\n  case hdiag  => apply Or.inl; apply Nat.leRefl\n  case lower => apply Or.inl; show p \u2264 p + d.succ; admit\n  case hupper => apply Or.inr; show q + d.succ > q; admit\n\ntheorem ex15 (p q : Nat) : p \u2264 q \u2228 p > q := by\n  cases p, q using elimEx with\n  | diag    => ?hdiag\n  | lower d => _\n  | upper d => ?hupper\n  { apply Or.inl; apply Nat.leRefl }\n  { apply Or.inr; show q + d.succ > q; admit }\n  { apply Or.inl; show p \u2264 p + d.succ; admit }\n\ntheorem ex16 {p q : Prop} (h : p \u2228 q) : q \u2228 p := by\n  induction h\n  case inl h' => exact Or.inr h'\n  case inr h' => exact Or.inl h'\n\ntheorem ex17 (n : Nat) : 0 + n = n := by\n  induction n\n  case zero => rfl\n  case succ m ih =>\n    show Nat.succ (0 + m) = Nat.succ m\n    rw [ih]\n", "meta": {"author": "JLimperg", "repo": "lean4-aesop", "sha": "5c4b9a3e05c32f69a4357c3047c274f4b94f9c71", "save_path": "github-repos/lean/JLimperg-lean4-aesop", "path": "github-repos/lean/JLimperg-lean4-aesop/lean4-aesop-5c4b9a3e05c32f69a4357c3047c274f4b94f9c71/tests/lean/run/casesUsing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543487, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7015235464507866}}
{"text": "/-\nCopyright (c) 2014 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.nat.basic\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Definitions and properties of `gcd`, `lcm`, and `coprime`\n\n-/\n\nnamespace nat\n\n\n/-! ### `gcd` -/\n\ntheorem gcd_dvd (m : \u2115) (n : \u2115) : gcd m n \u2223 m \u2227 gcd m n \u2223 n := sorry\n\ntheorem gcd_dvd_left (m : \u2115) (n : \u2115) : gcd m n \u2223 m :=\n  and.left (gcd_dvd m n)\n\ntheorem gcd_dvd_right (m : \u2115) (n : \u2115) : gcd m n \u2223 n :=\n  and.right (gcd_dvd m n)\n\ntheorem gcd_le_left {m : \u2115} (n : \u2115) (h : 0 < m) : gcd m n \u2264 m :=\n  le_of_dvd h (gcd_dvd_left m n)\n\ntheorem gcd_le_right (m : \u2115) {n : \u2115} (h : 0 < n) : gcd m n \u2264 n :=\n  le_of_dvd h (gcd_dvd_right m n)\n\ntheorem dvd_gcd {m : \u2115} {n : \u2115} {k : \u2115} : k \u2223 m \u2192 k \u2223 n \u2192 k \u2223 gcd m n := sorry\n\ntheorem dvd_gcd_iff {m : \u2115} {n : \u2115} {k : \u2115} : k \u2223 gcd m n \u2194 k \u2223 m \u2227 k \u2223 n := sorry\n\ntheorem gcd_comm (m : \u2115) (n : \u2115) : gcd m n = gcd n m :=\n  dvd_antisymm (dvd_gcd (gcd_dvd_right m n) (gcd_dvd_left m n)) (dvd_gcd (gcd_dvd_right n m) (gcd_dvd_left n m))\n\ntheorem gcd_eq_left_iff_dvd {m : \u2115} {n : \u2115} : m \u2223 n \u2194 gcd m n = m := sorry\n\ntheorem gcd_eq_right_iff_dvd {m : \u2115} {n : \u2115} : m \u2223 n \u2194 gcd n m = m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (m \u2223 n \u2194 gcd n m = m)) (gcd_comm n m))) gcd_eq_left_iff_dvd\n\ntheorem gcd_assoc (m : \u2115) (n : \u2115) (k : \u2115) : gcd (gcd m n) k = gcd m (gcd n k) := sorry\n\n@[simp] theorem gcd_one_right (n : \u2115) : gcd n 1 = 1 :=\n  Eq.trans (gcd_comm n 1) (gcd_one_left n)\n\ntheorem gcd_mul_left (m : \u2115) (n : \u2115) (k : \u2115) : gcd (m * n) (m * k) = m * gcd n k := sorry\n\ntheorem gcd_mul_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd (m * n) (k * n) = gcd m k * n := sorry\n\ntheorem gcd_pos_of_pos_left {m : \u2115} (n : \u2115) (mpos : 0 < m) : 0 < gcd m n :=\n  pos_of_dvd_of_pos (gcd_dvd_left m n) mpos\n\ntheorem gcd_pos_of_pos_right (m : \u2115) {n : \u2115} (npos : 0 < n) : 0 < gcd m n :=\n  pos_of_dvd_of_pos (gcd_dvd_right m n) npos\n\ntheorem eq_zero_of_gcd_eq_zero_left {m : \u2115} {n : \u2115} (H : gcd m n = 0) : m = 0 :=\n  or.elim (eq_zero_or_pos m) id fun (H1 : 0 < m) => absurd (Eq.symm H) (ne_of_lt (gcd_pos_of_pos_left n H1))\n\ntheorem eq_zero_of_gcd_eq_zero_right {m : \u2115} {n : \u2115} (H : gcd m n = 0) : n = 0 :=\n  eq_zero_of_gcd_eq_zero_left (eq.mp (Eq._oldrec (Eq.refl (gcd m n = 0)) (gcd_comm m n)) H)\n\ntheorem gcd_div {m : \u2115} {n : \u2115} {k : \u2115} (H1 : k \u2223 m) (H2 : k \u2223 n) : gcd (m / k) (n / k) = gcd m n / k := sorry\n\ntheorem gcd_dvd_gcd_of_dvd_left {m : \u2115} {k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd m n \u2223 gcd k n :=\n  dvd_gcd (dvd.trans (gcd_dvd_left m n) H) (gcd_dvd_right m n)\n\ntheorem gcd_dvd_gcd_of_dvd_right {m : \u2115} {k : \u2115} (n : \u2115) (H : m \u2223 k) : gcd n m \u2223 gcd n k :=\n  dvd_gcd (gcd_dvd_left n m) (dvd.trans (gcd_dvd_right n m) H)\n\ntheorem gcd_dvd_gcd_mul_left (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd (k * m) n :=\n  gcd_dvd_gcd_of_dvd_left n (dvd_mul_left m k)\n\ntheorem gcd_dvd_gcd_mul_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd (m * k) n :=\n  gcd_dvd_gcd_of_dvd_left n (dvd_mul_right m k)\n\ntheorem gcd_dvd_gcd_mul_left_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd m (k * n) :=\n  gcd_dvd_gcd_of_dvd_right m (dvd_mul_left n k)\n\ntheorem gcd_dvd_gcd_mul_right_right (m : \u2115) (n : \u2115) (k : \u2115) : gcd m n \u2223 gcd m (n * k) :=\n  gcd_dvd_gcd_of_dvd_right m (dvd_mul_right n k)\n\ntheorem gcd_eq_left {m : \u2115} {n : \u2115} (H : m \u2223 n) : gcd m n = m :=\n  dvd_antisymm (gcd_dvd_left m n) (dvd_gcd (dvd_refl m) H)\n\ntheorem gcd_eq_right {m : \u2115} {n : \u2115} (H : n \u2223 m) : gcd m n = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd m n = n)) (gcd_comm m n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd n m = n)) (gcd_eq_left H))) (Eq.refl n))\n\n@[simp] theorem gcd_mul_left_left (m : \u2115) (n : \u2115) : gcd (m * n) n = n :=\n  dvd_antisymm (gcd_dvd_right (m * n) n) (dvd_gcd (dvd_mul_left n m) (dvd_refl n))\n\n@[simp] theorem gcd_mul_left_right (m : \u2115) (n : \u2115) : gcd n (m * n) = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd n (m * n) = n)) (gcd_comm n (m * n))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (m * n) n = n)) (gcd_mul_left_left m n))) (Eq.refl n))\n\n@[simp] theorem gcd_mul_right_left (m : \u2115) (n : \u2115) : gcd (n * m) n = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (n * m) n = n)) (mul_comm n m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (m * n) n = n)) (gcd_mul_left_left m n))) (Eq.refl n))\n\n@[simp] theorem gcd_mul_right_right (m : \u2115) (n : \u2115) : gcd n (n * m) = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd n (n * m) = n)) (gcd_comm n (n * m))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (n * m) n = n)) (gcd_mul_right_left m n))) (Eq.refl n))\n\n@[simp] theorem gcd_gcd_self_right_left (m : \u2115) (n : \u2115) : gcd m (gcd m n) = gcd m n :=\n  dvd_antisymm (gcd_dvd_right m (gcd m n)) (dvd_gcd (gcd_dvd_left m n) (dvd_refl (gcd m n)))\n\n@[simp] theorem gcd_gcd_self_right_right (m : \u2115) (n : \u2115) : gcd m (gcd n m) = gcd n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (gcd n m) = gcd n m)) (gcd_comm n m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (gcd m n) = gcd m n)) (gcd_gcd_self_right_left m n))) (Eq.refl (gcd m n)))\n\n@[simp] theorem gcd_gcd_self_left_right (m : \u2115) (n : \u2115) : gcd (gcd n m) m = gcd n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (gcd n m) m = gcd n m)) (gcd_comm (gcd n m) m)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (gcd n m) = gcd n m)) (gcd_gcd_self_right_right m n))) (Eq.refl (gcd n m)))\n\n@[simp] theorem gcd_gcd_self_left_left (m : \u2115) (n : \u2115) : gcd (gcd m n) m = gcd m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (gcd m n) m = gcd m n)) (gcd_comm m n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (gcd n m) m = gcd n m)) (gcd_gcd_self_left_right m n))) (Eq.refl (gcd n m)))\n\ntheorem gcd_add_mul_self (m : \u2115) (n : \u2115) (k : \u2115) : gcd m (n + k * m) = gcd m n := sorry\n\ntheorem gcd_eq_zero_iff {i : \u2115} {j : \u2115} : gcd i j = 0 \u2194 i = 0 \u2227 j = 0 := sorry\n\n/-! ### `lcm` -/\n\ntheorem lcm_comm (m : \u2115) (n : \u2115) : lcm m n = lcm n m :=\n  id\n    (eq.mpr (id (Eq._oldrec (Eq.refl (m * n / gcd m n = n * m / gcd n m)) (mul_comm m n)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (n * m / gcd m n = n * m / gcd n m)) (gcd_comm m n))) (Eq.refl (n * m / gcd n m))))\n\n@[simp] theorem lcm_zero_left (m : \u2115) : lcm 0 m = 0 :=\n  id\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 * m / gcd 0 m = 0)) (zero_mul m)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (0 / gcd 0 m = 0)) (nat.zero_div (gcd 0 m)))) (Eq.refl 0)))\n\n@[simp] theorem lcm_zero_right (m : \u2115) : lcm m 0 = 0 :=\n  lcm_comm 0 m \u25b8 lcm_zero_left m\n\n@[simp] theorem lcm_one_left (m : \u2115) : lcm 1 m = m := sorry\n\n@[simp] theorem lcm_one_right (m : \u2115) : lcm m 1 = m :=\n  lcm_comm 1 m \u25b8 lcm_one_left m\n\n@[simp] theorem lcm_self (m : \u2115) : lcm m m = m := sorry\n\ntheorem dvd_lcm_left (m : \u2115) (n : \u2115) : m \u2223 lcm m n :=\n  dvd.intro (n / gcd m n) (Eq.symm (nat.mul_div_assoc m (gcd_dvd_right m n)))\n\ntheorem dvd_lcm_right (m : \u2115) (n : \u2115) : n \u2223 lcm m n :=\n  lcm_comm n m \u25b8 dvd_lcm_left n m\n\ntheorem gcd_mul_lcm (m : \u2115) (n : \u2115) : gcd m n * lcm m n = m * n := sorry\n\ntheorem lcm_dvd {m : \u2115} {n : \u2115} {k : \u2115} (H1 : m \u2223 k) (H2 : n \u2223 k) : lcm m n \u2223 k := sorry\n\ntheorem lcm_assoc (m : \u2115) (n : \u2115) (k : \u2115) : lcm (lcm m n) k = lcm m (lcm n k) := sorry\n\ntheorem lcm_ne_zero {m : \u2115} {n : \u2115} (hm : m \u2260 0) (hn : n \u2260 0) : lcm m n \u2260 0 := sorry\n\n/-!\n### `coprime`\n\nSee also `nat.coprime_of_dvd` and `nat.coprime_of_dvd'` to prove `nat.coprime m n`.\n-/\n\nprotected instance coprime.decidable (m : \u2115) (n : \u2115) : Decidable (coprime m n) :=\n  eq.mpr sorry (nat.decidable_eq (gcd m n) 1)\n\ntheorem coprime.gcd_eq_one {m : \u2115} {n : \u2115} : coprime m n \u2192 gcd m n = 1 :=\n  id\n\ntheorem coprime.symm {m : \u2115} {n : \u2115} : coprime n m \u2192 coprime m n :=\n  Eq.trans (gcd_comm m n)\n\ntheorem coprime.dvd_of_dvd_mul_right {m : \u2115} {n : \u2115} {k : \u2115} (H1 : coprime k n) (H2 : k \u2223 m * n) : k \u2223 m := sorry\n\ntheorem coprime.dvd_of_dvd_mul_left {m : \u2115} {n : \u2115} {k : \u2115} (H1 : coprime k m) (H2 : k \u2223 m * n) : k \u2223 n :=\n  coprime.dvd_of_dvd_mul_right H1 (eq.mp (Eq._oldrec (Eq.refl (k \u2223 m * n)) (mul_comm m n)) H2)\n\ntheorem coprime.gcd_mul_left_cancel {k : \u2115} (m : \u2115) {n : \u2115} (H : coprime k n) : gcd (k * m) n = gcd m n := sorry\n\ntheorem coprime.gcd_mul_right_cancel (m : \u2115) {k : \u2115} {n : \u2115} (H : coprime k n) : gcd (m * k) n = gcd m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd (m * k) n = gcd m n)) (mul_comm m k)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd (k * m) n = gcd m n)) (coprime.gcd_mul_left_cancel m H))) (Eq.refl (gcd m n)))\n\ntheorem coprime.gcd_mul_left_cancel_right {k : \u2115} {m : \u2115} (n : \u2115) (H : coprime k m) : gcd m (k * n) = gcd m n := sorry\n\ntheorem coprime.gcd_mul_right_cancel_right {k : \u2115} {m : \u2115} (n : \u2115) (H : coprime k m) : gcd m (n * k) = gcd m n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (n * k) = gcd m n)) (mul_comm n k)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (gcd m (k * n) = gcd m n)) (coprime.gcd_mul_left_cancel_right n H)))\n      (Eq.refl (gcd m n)))\n\ntheorem coprime_div_gcd_div_gcd {m : \u2115} {n : \u2115} (H : 0 < gcd m n) : coprime (m / gcd m n) (n / gcd m n) := sorry\n\ntheorem not_coprime_of_dvd_of_dvd {m : \u2115} {n : \u2115} {d : \u2115} (dgt1 : 1 < d) (Hm : d \u2223 m) (Hn : d \u2223 n) : \u00accoprime m n :=\n  fun (co : gcd m n = 1) =>\n    not_lt_of_ge (le_of_dvd zero_lt_one (eq.mpr (id (Eq._oldrec (Eq.refl (d \u2223 1)) (Eq.symm co))) (dvd_gcd Hm Hn))) dgt1\n\ntheorem exists_coprime {m : \u2115} {n : \u2115} (H : 0 < gcd m n) : \u2203 (m' : \u2115), \u2203 (n' : \u2115), coprime m' n' \u2227 m = m' * gcd m n \u2227 n = n' * gcd m n := sorry\n\ntheorem exists_coprime' {m : \u2115} {n : \u2115} (H : 0 < gcd m n) : \u2203 (g : \u2115), \u2203 (m' : \u2115), \u2203 (n' : \u2115), 0 < g \u2227 coprime m' n' \u2227 m = m' * g \u2227 n = n' * g := sorry\n\ntheorem coprime.mul {m : \u2115} {n : \u2115} {k : \u2115} (H1 : coprime m k) (H2 : coprime n k) : coprime (m * n) k :=\n  Eq.trans (coprime.gcd_mul_left_cancel n H1) H2\n\ntheorem coprime.mul_right {k : \u2115} {m : \u2115} {n : \u2115} (H1 : coprime k m) (H2 : coprime k n) : coprime k (m * n) :=\n  coprime.symm (coprime.mul (coprime.symm H1) (coprime.symm H2))\n\ntheorem coprime.coprime_dvd_left {m : \u2115} {k : \u2115} {n : \u2115} (H1 : m \u2223 k) (H2 : coprime k n) : coprime m n := sorry\n\ntheorem coprime.coprime_dvd_right {m : \u2115} {k : \u2115} {n : \u2115} (H1 : n \u2223 m) (H2 : coprime k m) : coprime k n :=\n  coprime.symm (coprime.coprime_dvd_left H1 (coprime.symm H2))\n\ntheorem coprime.coprime_mul_left {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime (k * m) n) : coprime m n :=\n  coprime.coprime_dvd_left (dvd_mul_left m k) H\n\ntheorem coprime.coprime_mul_right {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime (m * k) n) : coprime m n :=\n  coprime.coprime_dvd_left (dvd_mul_right m k) H\n\ntheorem coprime.coprime_mul_left_right {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime m (k * n)) : coprime m n :=\n  coprime.coprime_dvd_right (dvd_mul_left n k) H\n\ntheorem coprime.coprime_mul_right_right {k : \u2115} {m : \u2115} {n : \u2115} (H : coprime m (n * k)) : coprime m n :=\n  coprime.coprime_dvd_right (dvd_mul_right n k) H\n\ntheorem coprime.coprime_div_left {m : \u2115} {n : \u2115} {a : \u2115} (cmn : coprime m n) (dvd : a \u2223 m) : coprime (m / a) n := sorry\n\ntheorem coprime.coprime_div_right {m : \u2115} {n : \u2115} {a : \u2115} (cmn : coprime m n) (dvd : a \u2223 n) : coprime m (n / a) :=\n  coprime.symm (coprime.coprime_div_left (coprime.symm cmn) dvd)\n\ntheorem coprime_mul_iff_left {k : \u2115} {m : \u2115} {n : \u2115} : coprime (m * n) k \u2194 coprime m k \u2227 coprime n k := sorry\n\ntheorem coprime_mul_iff_right {k : \u2115} {m : \u2115} {n : \u2115} : coprime k (m * n) \u2194 coprime k m \u2227 coprime k n := sorry\n\ntheorem coprime.gcd_left (k : \u2115) {m : \u2115} {n : \u2115} (hmn : coprime m n) : coprime (gcd k m) n :=\n  coprime.coprime_dvd_left (gcd_dvd_right k m) hmn\n\ntheorem coprime.gcd_right (k : \u2115) {m : \u2115} {n : \u2115} (hmn : coprime m n) : coprime m (gcd k n) :=\n  coprime.coprime_dvd_right (gcd_dvd_right k n) hmn\n\ntheorem coprime.gcd_both (k : \u2115) (l : \u2115) {m : \u2115} {n : \u2115} (hmn : coprime m n) : coprime (gcd k m) (gcd l n) :=\n  coprime.gcd_right l (coprime.gcd_left k hmn)\n\ntheorem coprime.mul_dvd_of_dvd_of_dvd {a : \u2115} {n : \u2115} {m : \u2115} (hmn : coprime m n) (hm : m \u2223 a) (hn : n \u2223 a) : m * n \u2223 a := sorry\n\ntheorem coprime_one_left (n : \u2115) : coprime 1 n :=\n  gcd_one_left\n\ntheorem coprime_one_right (n : \u2115) : coprime n 1 :=\n  gcd_one_right\n\ntheorem coprime.pow_left {m : \u2115} {k : \u2115} (n : \u2115) (H1 : coprime m k) : coprime (m ^ n) k :=\n  nat.rec_on n (coprime_one_left k) fun (n : \u2115) (IH : coprime (m ^ n) k) => coprime.mul H1 IH\n\ntheorem coprime.pow_right {m : \u2115} {k : \u2115} (n : \u2115) (H1 : coprime k m) : coprime k (m ^ n) :=\n  coprime.symm (coprime.pow_left n (coprime.symm H1))\n\ntheorem coprime.pow {k : \u2115} {l : \u2115} (m : \u2115) (n : \u2115) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) :=\n  coprime.pow_right n (coprime.pow_left m H1)\n\ntheorem coprime.eq_one_of_dvd {k : \u2115} {m : \u2115} (H : coprime k m) (d : k \u2223 m) : k = 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (k = 1)) (Eq.symm (coprime.gcd_eq_one H))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (k = gcd k m)) (gcd_eq_left d))) (Eq.refl k))\n\n@[simp] theorem coprime_zero_left (n : \u2115) : coprime 0 n \u2194 n = 1 := sorry\n\n@[simp] theorem coprime_zero_right (n : \u2115) : coprime n 0 \u2194 n = 1 := sorry\n\n@[simp] theorem coprime_one_left_iff (n : \u2115) : coprime 1 n \u2194 True := sorry\n\n@[simp] theorem coprime_one_right_iff (n : \u2115) : coprime n 1 \u2194 True := sorry\n\n@[simp] theorem coprime_self (n : \u2115) : coprime n n \u2194 n = 1 := sorry\n\n/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. -/\ndef prod_dvd_and_dvd_of_dvd_prod {m : \u2115} {n : \u2115} {k : \u2115} (H : k \u2223 m * n) : Subtype fun (d : (Subtype fun (m' : \u2115) => m' \u2223 m) \u00d7 Subtype fun (n' : \u2115) => n' \u2223 n) => k = \u2191(prod.fst d) * \u2191(prod.snd d) :=\n  (fun (_x : \u2115) (h0 : gcd k m = _x) =>\n      nat.cases_on _x\n        (fun (h0 : gcd k m = 0) =>\n          Eq._oldrec\n            (fun (H : 0 \u2223 m * n) (h0 : gcd 0 m = 0) =>\n              Eq._oldrec\n                (fun (H : 0 \u2223 0 * n) (h0 : gcd 0 0 = 0) =>\n                  { val := ({ val := 0, property := sorry }, { val := n, property := dvd_refl n }), property := sorry })\n                sorry H h0)\n            sorry H h0)\n        (fun (n_1 : \u2115) (h0 : gcd k m = Nat.succ n_1) =>\n          (fun (h0 : gcd k m = Nat.succ n_1) =>\n              { val := ({ val := gcd k m, property := gcd_dvd_right k m }, { val := k / gcd k m, property := sorry }),\n                property := sorry })\n            h0)\n        h0)\n    (gcd k m) sorry\n\ntheorem gcd_mul_dvd_mul_gcd (k : \u2115) (m : \u2115) (n : \u2115) : gcd k (m * n) \u2223 gcd k m * gcd k n := sorry\n\ntheorem coprime.gcd_mul (k : \u2115) {m : \u2115} {n : \u2115} (h : coprime m n) : gcd k (m * n) = gcd k m * gcd k n :=\n  dvd_antisymm (gcd_mul_dvd_mul_gcd k m n)\n    (coprime.mul_dvd_of_dvd_of_dvd (coprime.gcd_both k k h) (gcd_dvd_gcd_mul_right_right k m n)\n      (gcd_dvd_gcd_mul_left_right k n m))\n\ntheorem pow_dvd_pow_iff {a : \u2115} {b : \u2115} {n : \u2115} (n0 : 0 < n) : a ^ n \u2223 b ^ n \u2194 a \u2223 b := sorry\n\ntheorem gcd_mul_gcd_of_coprime_of_mul_eq_mul {a : \u2115} {b : \u2115} {c : \u2115} {d : \u2115} (cop : coprime c d) (h : a * b = c * d) : gcd a c * gcd b c = c := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/nat/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7015235441654168}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem amc12b_2002_p6\n  (a b : \u211d)\n  (h\u2080 : a \u2260 0 \u2227 b \u2260 0)\n  (h\u2081 : \u2200 x, x^2 + a * x + b = (x - a) * (x - b)) :\n  a = 1 \u2227 b = -2 :=\nbegin\n  have h\u2082 := h\u2081 a,\n  have h\u2083 := h\u2081 b,\n  have h\u2084 := h\u2081 0,\n  simp at *,\n  have h\u2085 : b * (1 - a) = 0, linarith,\n  simp at h\u2085,\n  cases h\u2085 with h\u2085 h\u2086,\n  exfalso,\n  exact absurd h\u2085 h\u2080.2,\n  have h\u2086 : a = 1, linarith,\n  split,\n  exact h\u2086,\n  rw h\u2086 at h\u2082,\n  linarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/amc/12/2002/b/p6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7015235397590359}}
{"text": "/-\nCopyright \u00a9 2020 Nicol\u00f2 Cavalleri. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Nicol\u00f2 Cavalleri\n-/\nimport geometry.manifold.algebra.lie_group\n\n/-!\n# Smooth structures\n\nIn this file we define smooth structures that build on Lie groups. We prefer using the term smooth\ninstead of Lie mainly because Lie ring has currently another use in mathematics.\n-/\n\nopen_locale manifold\n\nsection smooth_ring\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{H : Type*} [topological_space H]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n\nset_option default_priority 100 -- see Note [default priority]\n\n/-- A smooth (semi)ring is a (semi)ring `R` where addition and multiplication are smooth.\nIf `R` is a ring, then negation is automatically smooth, as it is multiplication with `-1`. -/\n-- See note [Design choices about smooth algebraic structures]\nclass smooth_ring (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [semiring R] [topological_space R] [charted_space H R]\n  extends has_smooth_add I R : Prop :=\n(smooth_mul : smooth (I.prod I) I (\u03bb p : R\u00d7R, p.1 * p.2))\n\ninstance smooth_ring.to_has_smooth_mul (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [semiring R] [topological_space R] [charted_space H R] [h : smooth_ring I R] :\n  has_smooth_mul I R := { ..h }\n\ninstance smooth_ring.to_lie_add_group (I : model_with_corners \ud835\udd5c E H)\n  (R : Type*) [ring R] [topological_space R] [charted_space H R] [smooth_ring I R] :\n  lie_add_group I R :=\n{ compatible := \u03bb e e', has_groupoid.compatible (times_cont_diff_groupoid \u22a4 I),\n  smooth_add := smooth_add I,\n  smooth_neg := by simpa only [neg_one_mul] using @smooth_mul_left \ud835\udd5c _ H _ E _ _ I R _ _ _ _ (-1) }\n\nend smooth_ring\n\ninstance field_smooth_ring {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c] :\n  smooth_ring \ud835\udcd8(\ud835\udd5c) \ud835\udd5c :=\n{ smooth_mul :=\n  begin\n    rw smooth_iff,\n    refine \u27e8continuous_mul, \u03bb x y, _\u27e9,\n    simp only [prod.mk.eta] with mfld_simps,\n    rw times_cont_diff_on_univ,\n    exact times_cont_diff_mul,\n  end,\n  ..normed_space_lie_add_group }\n\nvariables {\ud835\udd5c R E H : Type*} [topological_space R] [topological_space H]\n  [nondiscrete_normed_field \ud835\udd5c] [normed_group E] [normed_space \ud835\udd5c E]\n  [charted_space H R] (I : model_with_corners \ud835\udd5c E H)\n\n/-- A smooth (semi)ring is a topological (semi)ring. This is not an instance for technical reasons,\nsee note [Design choices about smooth algebraic structures]. -/\nlemma topological_ring_of_smooth [semiring R] [smooth_ring I R] :\n  topological_ring R :=\n{ .. has_continuous_mul_of_smooth I, .. has_continuous_add_of_smooth I }\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/geometry/manifold/algebra/structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7015235352704758}}
{"text": "/-\nCopyright (c) 2021 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying\n-/\nimport measure_theory.measure.vector_measure\nimport order.symm_diff\n\n/-!\n# Hahn decomposition\n\nThis file prove the Hahn decomposition theorem (signed version). The Hahn decomposition theorem\nstates that, given a signed measure `s`, there exist complement, measurable sets `i` and `j`,\nsuch that `i` is positive and `j` is negative with repsect to `s`; that is, `s` restricted on `i`\nis non-negative and `s` restricted on `j` is non-positive.\n\nThe Hahn decomposition theorem leads to many other results in measure theory, most notably,\nthe Jordan decomposition theorem, the Lebesgue decomposition theorem and the Radon-Nikodym theorem.\n\n## Main results\n\n* `measure_theory.signed_measure.exists_is_compl_positive_negative` : the Hahn decomposition\n  theorem.\n* `measure_theory.signed_measure.exists_subset_restrict_nonpos` : A measurable set of negative\n  measure contains a negative subset.\n\n## Notation\n\nWe use the notations `0 \u2264[i] s` and `s \u2264[i] 0` to denote the usual definitions of a set `i`\nbeing positive/negative with respect to the signed measure `s`.\n\n## Tags\n\nHahn decomposition theorem\n-/\n\nnoncomputable theory\nopen_locale classical big_operators nnreal ennreal measure_theory\n\nvariables {\u03b1 \u03b2 : Type*} [measurable_space \u03b1]\nvariables {M : Type*} [add_comm_monoid M] [topological_space M] [ordered_add_comm_monoid M]\n\nnamespace measure_theory\n\nnamespace signed_measure\n\nopen filter vector_measure\n\nvariables {s : signed_measure \u03b1} {i j : set \u03b1}\n\nsection exists_subset_restrict_nonpos\n\n/-! ### exists_subset_restrict_nonpos\n\nIn this section we will prove that a set `i` whose measure is negative contains a negative subset\n`j` with respect to the signed measure `s` (i.e. `s \u2264[j] 0`), whose measure is negative. This lemma\nis used to prove the Hahn decomposition theorem.\n\nTo prove this lemma, we will construct a sequence of measurable sets $(A_n)_{n \\in \\mathbb{N}}$,\nsuch that, for all $n$, $s(A_{n + 1})$ is close to maximal among subsets of\n$i \\setminus \\bigcup_{k \\le n} A_k$.\n\nThis sequence of sets does not necessarily exist. However, if this sequence terminates; that is,\nthere does not exists any sets satisfying the property, the last $A_n$ will be a negative subset\nof negative measure, hence proving our claim.\n\nIn the case that the sequence does not terminate, it is easy to see that\n$i \\setminus \\bigcup_{k = 0}^\\infty A_k$ is the required negative set.\n\nTo implement this in Lean, we define several auxilary definitions.\n\n- given the sets `i` and the natural number `n`, `exists_one_div_lt s i n` is the property that\n  there exists a measurable set `k \u2286 i` such that `1 / (n + 1) < s k`.\n- given the sets `i` and that `i` is not negative, `find_exists_one_div_lt s i` is the\n  least natural number `n` such that `exists_one_div_lt s i n`.\n- given the sets `i` and that `i` is not negative, `some_exists_one_div_lt` chooses the set\n  `k` from `exists_one_div_lt s i (find_exists_one_div_lt s i)`.\n- lastly, given the set `i`, `restrict_nonpos_seq s i` is the sequence of sets defined inductively\n  where\n  `restrict_nonpos_seq s i 0 = some_exists_one_div_lt s (i \\ \u2205)` and\n  `restrict_nonpos_seq s i (n + 1) = some_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq k)`.\n  This definition represents the sequence $(A_n)$\u00a0in the proof as described above.\n\nWith these definitions, we are able consider the case where the sequence terminates separately,\nallowing us to prove `exists_subset_restrict_nonpos`.\n-/\n\n/-- Given the set `i` and the natural number `n`, `exists_one_div_lt s i j` is the property that\nthere exists a measurable set `k \u2286 i` such that `1 / (n + 1) < s k`. -/\nprivate def exists_one_div_lt (s : signed_measure \u03b1) (i : set \u03b1) (n : \u2115) : Prop :=\n\u2203 k : set \u03b1, k \u2286 i \u2227 measurable_set k \u2227 (1 / (n + 1) : \u211d) < s k\n\nprivate lemma exists_nat_one_div_lt_measure_of_not_negative (hi : \u00ac s \u2264[i] 0) :\n  \u2203 (n : \u2115), exists_one_div_lt s i n :=\nlet \u27e8k, hj\u2081, hj\u2082, hj\u27e9 := exists_pos_measure_of_not_restrict_le_zero s hi in\nlet \u27e8n, hn\u27e9 := exists_nat_one_div_lt hj in \u27e8n, k, hj\u2082, hj\u2081, hn\u27e9\n\n/-- Given the set `i`, if `i` is not negative, `find_exists_one_div_lt s i` is the\nleast natural number `n` such that `exists_one_div_lt s i n`, otherwise, it returns 0. -/\nprivate def find_exists_one_div_lt (s : signed_measure \u03b1) (i : set \u03b1) : \u2115 :=\nif hi : \u00ac s \u2264[i] 0 then nat.find (exists_nat_one_div_lt_measure_of_not_negative hi) else 0\n\nprivate lemma find_exists_one_div_lt_spec (hi : \u00ac s \u2264[i] 0) :\n  exists_one_div_lt s i (find_exists_one_div_lt s i) :=\nbegin\n  rw [find_exists_one_div_lt, dif_pos hi],\n  convert nat.find_spec _,\nend\n\nprivate lemma find_exists_one_div_lt_min (hi : \u00ac s \u2264[i] 0) {m : \u2115}\n  (hm : m < find_exists_one_div_lt s i) : \u00ac exists_one_div_lt s i m :=\nbegin\n  rw [find_exists_one_div_lt, dif_pos hi] at hm,\n  exact nat.find_min _ hm\nend\n\n/-- Given the set `i`, if `i` is not negative, `some_exists_one_div_lt` chooses the set\n`k` from `exists_one_div_lt s i (find_exists_one_div_lt s i)`, otherwise, it returns the\nempty set. -/\nprivate def some_exists_one_div_lt (s : signed_measure \u03b1) (i : set \u03b1) : set \u03b1 :=\nif hi : \u00ac s \u2264[i] 0 then classical.some (find_exists_one_div_lt_spec hi) else \u2205\n\nprivate lemma some_exists_one_div_lt_spec (hi : \u00ac s \u2264[i] 0) :\n  (some_exists_one_div_lt s i) \u2286 i \u2227 measurable_set (some_exists_one_div_lt s i) \u2227\n  (1 / (find_exists_one_div_lt s i + 1) : \u211d) < s (some_exists_one_div_lt s i) :=\nbegin\n  rw [some_exists_one_div_lt, dif_pos hi],\n  exact classical.some_spec (find_exists_one_div_lt_spec hi),\nend\n\nprivate lemma some_exists_one_div_lt_subset : some_exists_one_div_lt s i \u2286 i :=\nbegin\n  by_cases hi : \u00ac s \u2264[i] 0,\n  { exact let \u27e8h, _\u27e9 := some_exists_one_div_lt_spec hi in h },\n  { rw [some_exists_one_div_lt, dif_neg hi],\n    exact set.empty_subset _ },\nend\n\nprivate lemma some_exists_one_div_lt_subset' : some_exists_one_div_lt s (i \\ j) \u2286 i :=\nset.subset.trans some_exists_one_div_lt_subset (set.diff_subset _ _)\n\nprivate \n\nprivate lemma some_exists_one_div_lt_lt (hi : \u00ac s \u2264[i] 0) :\n  (1 / (find_exists_one_div_lt s i + 1) : \u211d) < s (some_exists_one_div_lt s i) :=\nlet \u27e8_, _, h\u27e9 := some_exists_one_div_lt_spec hi in h\n\n/-- Given the set `i`, `restrict_nonpos_seq s i` is the sequence of sets defined inductively where\n`restrict_nonpos_seq s i 0 = some_exists_one_div_lt s (i \\ \u2205)` and\n`restrict_nonpos_seq s i (n + 1) = some_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq k)`.\n\nFor each `n : \u2115`,`s (restrict_nonpos_seq s i n)` is close to maximal among all subsets of\n`i \\ \u22c3 k \u2264 n, restrict_nonpos_seq s i k`. -/\nprivate def restrict_nonpos_seq (s : signed_measure \u03b1) (i : set \u03b1) : \u2115 \u2192 set \u03b1\n| 0 := some_exists_one_div_lt s (i \\ \u2205) -- I used `i \\ \u2205` instead of `i` to simplify some proofs\n| (n + 1) := some_exists_one_div_lt s (i \\ \u22c3 k \u2264 n,\n  have k < n + 1 := nat.lt_succ_iff.mpr H,\n  restrict_nonpos_seq k)\n\nprivate lemma restrict_nonpos_seq_succ (n : \u2115) :\n  restrict_nonpos_seq s i n.succ =\n  some_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq s i k) :=\nby rw restrict_nonpos_seq\n\nprivate lemma restrict_nonpos_seq_subset (n : \u2115) :\n  restrict_nonpos_seq s i n \u2286 i :=\nbegin\n  cases n;\n  { rw restrict_nonpos_seq, exact some_exists_one_div_lt_subset' }\nend\n\nprivate lemma restrict_nonpos_seq_lt\n  (n : \u2115) (hn : \u00ac s \u2264[i \\ \u22c3 k \u2264 n, restrict_nonpos_seq s i k] 0) :\n  (1 / (find_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq s i k) + 1) : \u211d)\n  < s (restrict_nonpos_seq s i n.succ) :=\nbegin\n  rw restrict_nonpos_seq_succ,\n  apply some_exists_one_div_lt_lt hn,\nend\n\nprivate lemma measure_of_restrict_nonpos_seq (hi\u2082 : \u00ac s \u2264[i] 0)\n  (n : \u2115) (hn : \u00ac s \u2264[i \\ \u22c3 k < n, restrict_nonpos_seq s i k] 0) :\n  0 < s (restrict_nonpos_seq s i n) :=\nbegin\n  cases n,\n  { rw restrict_nonpos_seq, rw \u2190 @set.diff_empty _ i at hi\u2082,\n    rcases some_exists_one_div_lt_spec hi\u2082 with \u27e8_, _, h\u27e9,\n    exact (lt_trans nat.one_div_pos_of_nat h) },\n  { rw restrict_nonpos_seq_succ,\n    have h\u2081 : \u00ac s \u2264[i \\ \u22c3 (k : \u2115) (H : k \u2264 n), restrict_nonpos_seq s i k] 0,\n    { refine mt (restrict_le_zero_subset _ _ (by simp [nat.lt_succ_iff])) hn,\n      convert measurable_of_not_restrict_le_zero _ hn,\n      exact funext (\u03bb x, by rw nat.lt_succ_iff) },\n    rcases some_exists_one_div_lt_spec h\u2081 with \u27e8_, _, h\u27e9,\n    exact (lt_trans nat.one_div_pos_of_nat h) }\nend\n\nprivate lemma restrict_nonpos_seq_measurable_set (n : \u2115) :\n  measurable_set (restrict_nonpos_seq s i n) :=\nbegin\n  cases n;\n  { rw restrict_nonpos_seq,\n    exact some_exists_one_div_lt_measurable_set },\nend\n\nprivate lemma restrict_nonpos_seq_disjoint' {n m : \u2115} (h : n < m) :\n  restrict_nonpos_seq s i n \u2229 restrict_nonpos_seq s i m = \u2205 :=\nbegin\n  rw set.eq_empty_iff_forall_not_mem,\n  rintro x \u27e8hx\u2081, hx\u2082\u27e9,\n  cases m, { linarith },\n  { rw restrict_nonpos_seq at hx\u2082,\n    exact (some_exists_one_div_lt_subset hx\u2082).2\n      (set.mem_Union.2 \u27e8n, set.mem_Union.2 \u27e8nat.lt_succ_iff.mp h, hx\u2081\u27e9\u27e9) }\nend\n\nprivate lemma restrict_nonpos_seq_disjoint : pairwise (disjoint on (restrict_nonpos_seq s i)) :=\nbegin\n  intros n m h,\n  rcases lt_or_gt_of_ne h with (h | h),\n  { intro x,\n    rw [set.inf_eq_inter, restrict_nonpos_seq_disjoint' h],\n    exact id },\n  { intro x,\n    rw [set.inf_eq_inter, set.inter_comm, restrict_nonpos_seq_disjoint' h],\n    exact id }\nend\n\nprivate lemma exists_subset_restrict_nonpos' (hi\u2081 : measurable_set i) (hi\u2082 : s i < 0)\n  (hn : \u00ac \u2200 n : \u2115, \u00ac s \u2264[i \\ \u22c3 l < n, restrict_nonpos_seq s i l] 0) :\n  \u2203 j : set \u03b1, measurable_set j \u2227 j \u2286 i \u2227 s \u2264[j] 0 \u2227 s j < 0 :=\nbegin\n  by_cases s \u2264[i] 0, { exact \u27e8i, hi\u2081, set.subset.refl _, h, hi\u2082\u27e9 },\n  push_neg at hn,\n  set k := nat.find hn with hk\u2081,\n  have hk\u2082 : s \u2264[i \\ \u22c3 l < k, restrict_nonpos_seq s i l] 0 := nat.find_spec hn,\n  have hmeas : measurable_set (\u22c3 (l : \u2115) (H : l < k), restrict_nonpos_seq s i l) :=\n    (measurable_set.Union $ \u03bb _, measurable_set.Union_Prop\n      (\u03bb _, restrict_nonpos_seq_measurable_set _)),\n  refine \u27e8i \\ \u22c3 l < k, restrict_nonpos_seq s i l, hi\u2081.diff hmeas, set.diff_subset _ _, hk\u2082, _\u27e9,\n  rw [of_diff hmeas hi\u2081, s.of_disjoint_Union_nat],\n  { have h\u2081 : \u2200 l < k, 0 \u2264 s (restrict_nonpos_seq s i l),\n    { intros l hl,\n      refine le_of_lt (measure_of_restrict_nonpos_seq h _ _),\n      refine mt (restrict_le_zero_subset _ (hi\u2081.diff _) (set.subset.refl _)) (nat.find_min hn hl),\n      exact (measurable_set.Union $ \u03bb _, measurable_set.Union_Prop\n        (\u03bb _, restrict_nonpos_seq_measurable_set _)) },\n    suffices : 0 \u2264 \u2211' (l : \u2115), s (\u22c3 (H : l < k), restrict_nonpos_seq s i l),\n    { rw sub_neg,\n      exact lt_of_lt_of_le hi\u2082 this },\n    refine tsum_nonneg _,\n    intro l, by_cases l < k,\n    { convert h\u2081 _ h,\n      ext x,\n      rw [set.mem_Union, exists_prop, and_iff_right_iff_imp],\n      exact \u03bb _, h },\n    { convert le_of_eq s.empty.symm,\n      ext, simp only [exists_prop, set.mem_empty_eq, set.mem_Union, not_and, iff_false],\n      exact \u03bb h', false.elim (h h') } },\n  { intro, exact measurable_set.Union_Prop (\u03bb _, restrict_nonpos_seq_measurable_set _) },\n  { intros a b hab x hx,\n    simp only [exists_prop, set.mem_Union, set.mem_inter_eq, set.inf_eq_inter] at hx,\n    exact let \u27e8\u27e8_, hx\u2081\u27e9, _, hx\u2082\u27e9 := hx in restrict_nonpos_seq_disjoint a b hab \u27e8hx\u2081, hx\u2082\u27e9 },\n  { apply set.Union_subset,\n    intros a x,\n    simp only [and_imp, exists_prop, set.mem_Union],\n    intros _ hx,\n    exact restrict_nonpos_seq_subset _ hx },\n  { apply_instance }\nend\n\n/-- A measurable set of negative measure has a negative subset of negative measure. -/\ntheorem exists_subset_restrict_nonpos (hi : s i < 0) :\n  \u2203 j : set \u03b1, measurable_set j \u2227 j \u2286 i \u2227 s \u2264[j] 0 \u2227 s j < 0 :=\nbegin\n  have hi\u2081 : measurable_set i :=\n    classical.by_contradiction (\u03bb h, ne_of_lt hi $ s.not_measurable h),\n  by_cases s \u2264[i] 0, { exact \u27e8i, hi\u2081, set.subset.refl _, h, hi\u27e9 },\n  by_cases hn : \u2200 n : \u2115, \u00ac s \u2264[i \\ \u22c3 l < n, restrict_nonpos_seq s i l] 0,\n  swap, { exact exists_subset_restrict_nonpos' hi\u2081 hi hn },\n  set A := i \\ \u22c3 l, restrict_nonpos_seq s i l with hA,\n  set bdd : \u2115 \u2192 \u2115 := \u03bb n,\n    find_exists_one_div_lt s (i \\ \u22c3 k \u2264 n, restrict_nonpos_seq s i k) with hbdd,\n  have hn' : \u2200 n : \u2115, \u00ac s \u2264[i \\ \u22c3 l \u2264 n, restrict_nonpos_seq s i l] 0,\n  { intro n,\n    convert hn (n + 1);\n    { ext l,\n      simp only [exists_prop, set.mem_Union, and.congr_left_iff],\n      exact \u03bb _, nat.lt_succ_iff.symm } },\n  have h\u2081 : s i = s A + \u2211' l, s (restrict_nonpos_seq s i l),\n  { rw [hA, \u2190 s.of_disjoint_Union_nat, add_comm, of_add_of_diff],\n    exact measurable_set.Union (\u03bb _, restrict_nonpos_seq_measurable_set _),\n    exacts [hi\u2081, set.Union_subset (\u03bb _, restrict_nonpos_seq_subset _), \u03bb _,\n            restrict_nonpos_seq_measurable_set _, restrict_nonpos_seq_disjoint] },\n  have h\u2082 : s A \u2264 s i,\n  { rw h\u2081,\n    apply le_add_of_nonneg_right,\n    exact tsum_nonneg (\u03bb n, le_of_lt (measure_of_restrict_nonpos_seq h _ (hn n))) },\n  have h\u2083' : summable (\u03bb n, (1 / (bdd n + 1) : \u211d)),\n  { have : summable (\u03bb l, s (restrict_nonpos_seq s i l)) :=\n      has_sum.summable (s.m_Union (\u03bb _, restrict_nonpos_seq_measurable_set _)\n        restrict_nonpos_seq_disjoint),\n    refine summable_of_nonneg_of_le (\u03bb n, _) (\u03bb n, _)\n      (summable.comp_injective this nat.succ_injective),\n    { exact le_of_lt nat.one_div_pos_of_nat },\n    { exact le_of_lt (restrict_nonpos_seq_lt n (hn' n)) } },\n  have h\u2083 : tendsto (\u03bb n, (bdd n : \u211d) + 1) at_top at_top,\n  { simp only [one_div] at h\u2083',\n    exact summable.tendsto_top_of_pos h\u2083' (\u03bb n, nat.cast_add_one_pos (bdd n)) },\n  have h\u2084 : tendsto (\u03bb n, (bdd n : \u211d)) at_top at_top,\n  { convert at_top.tendsto_at_top_add_const_right (-1) h\u2083, simp },\n  have A_meas : measurable_set A :=\n    hi\u2081.diff (measurable_set.Union (\u03bb _, restrict_nonpos_seq_measurable_set _)),\n  refine \u27e8A, A_meas, set.diff_subset _ _, _, h\u2082.trans_lt hi\u27e9,\n  by_contra hnn,\n  rw restrict_le_restrict_iff _ _ A_meas at hnn, push_neg at hnn,\n  obtain \u27e8E, hE\u2081, hE\u2082, hE\u2083\u27e9 := hnn,\n  have : \u2203 k, 1 \u2264 bdd k \u2227 1 / (bdd k : \u211d) < s E,\n  { rw tendsto_at_top_at_top at h\u2084,\n    obtain \u27e8k, hk\u27e9 := h\u2084 (max (1 / s E + 1) 1),\n    refine \u27e8k, _, _\u27e9,\n    { have hle := le_of_max_le_right (hk k le_rfl),\n      norm_cast at hle,\n      exact hle },\n    { have : 1 / s E < bdd k,\n      { linarith [le_of_max_le_left (hk k le_rfl)] {restrict_type := \u211d} },\n      rw one_div at this \u22a2,\n      rwa inv_lt (lt_trans (inv_pos.2 hE\u2083) this) hE\u2083 } },\n  obtain \u27e8k, hk\u2081, hk\u2082\u27e9 := this,\n  have hA' : A \u2286 i \\ \u22c3 l \u2264 k, restrict_nonpos_seq s i l,\n  { apply set.diff_subset_diff_right,\n    intro x, simp only [set.mem_Union],\n    rintro \u27e8n, _, hn\u2082\u27e9,\n    exact \u27e8n, hn\u2082\u27e9 },\n  refine find_exists_one_div_lt_min (hn' k)\n    (buffer.lt_aux_2 hk\u2081) \u27e8E, set.subset.trans hE\u2082 hA', hE\u2081, _\u27e9,\n  convert hk\u2082, norm_cast,\n  exact tsub_add_cancel_of_le hk\u2081\nend\n\nend exists_subset_restrict_nonpos\n\n/-- The set of measures of the set of measurable negative sets. -/\ndef measure_of_negatives (s : signed_measure \u03b1) : set \u211d :=\ns '' { B | measurable_set B \u2227 s \u2264[B] 0 }\n\nlemma zero_mem_measure_of_negatives : (0 : \u211d) \u2208 s.measure_of_negatives :=\n\u27e8\u2205, \u27e8measurable_set.empty, le_restrict_empty _ _\u27e9, s.empty\u27e9\n\nlemma bdd_below_measure_of_negatives :\n  bdd_below s.measure_of_negatives :=\nbegin\n  simp_rw [bdd_below, set.nonempty, mem_lower_bounds],\n  by_contra, push_neg at h,\n  have h' : \u2200 n : \u2115, \u2203 y : \u211d, y \u2208 s.measure_of_negatives \u2227 y < -n := \u03bb n, h (-n),\n  choose f hf using h',\n  have hf' : \u2200 n : \u2115, \u2203 B, measurable_set B \u2227 s \u2264[B] 0 \u2227 s B < -n,\n  { intro n,\n    rcases hf n with \u27e8\u27e8B, \u27e8hB\u2081, hBr\u27e9, hB\u2082\u27e9, hlt\u27e9,\n    exact \u27e8B, hB\u2081, hBr, hB\u2082.symm \u25b8 hlt\u27e9 },\n  choose B hmeas hr h_lt using hf',\n  set A := \u22c3 n, B n with hA,\n  have hfalse : \u2200 n : \u2115, s A \u2264 -n,\n  { intro n,\n    refine le_trans _ (le_of_lt (h_lt _)),\n    rw [hA, \u2190 set.diff_union_of_subset (set.subset_Union _ n),\n        of_union (disjoint.comm.1 set.disjoint_diff) _ (hmeas n)],\n    { refine add_le_of_nonpos_left _,\n      have : s \u2264[A] 0 := restrict_le_restrict_Union _ _ hmeas hr,\n      refine nonpos_of_restrict_le_zero _ (restrict_le_zero_subset _ _ (set.diff_subset _ _) this),\n      exact measurable_set.Union hmeas },\n    { apply_instance },\n    { exact (measurable_set.Union hmeas).diff (hmeas n) } },\n  rcases exists_nat_gt (-(s A)) with \u27e8n, hn\u27e9,\n  exact lt_irrefl _ ((neg_lt.1 hn).trans_le (hfalse n)),\nend\n\n/-- Alternative formulation of `measure_theory.signed_measure.exists_is_compl_positive_negative`\n(the Hahn decomposition theorem) using set complements. -/\nlemma exists_compl_positive_negative (s : signed_measure \u03b1) :\n  \u2203 i : set \u03b1, measurable_set i \u2227 0 \u2264[i] s \u2227 s \u2264[i\u1d9c] 0 :=\nbegin\n  obtain \u27e8f, _, hf\u2082, hf\u2081\u27e9 := exists_seq_tendsto_Inf\n    \u27e80, @zero_mem_measure_of_negatives _ _ s\u27e9 bdd_below_measure_of_negatives,\n  choose B hB using hf\u2081,\n  have hB\u2081 : \u2200 n, measurable_set (B n) := \u03bb n, (hB n).1.1,\n  have hB\u2082 : \u2200 n, s \u2264[B n] 0 := \u03bb n, (hB n).1.2,\n  set A := \u22c3 n, B n with hA,\n  have hA\u2081 : measurable_set A := measurable_set.Union hB\u2081,\n  have hA\u2082 : s \u2264[A] 0 := restrict_le_restrict_Union _ _ hB\u2081 hB\u2082,\n  have hA\u2083 : s A = Inf s.measure_of_negatives,\n  { apply le_antisymm,\n    { refine le_of_tendsto_of_tendsto tendsto_const_nhds hf\u2082 (eventually_of_forall (\u03bb n, _)),\n      rw [\u2190 (hB n).2, hA, \u2190 set.diff_union_of_subset (set.subset_Union _ n),\n          of_union (disjoint.comm.1 set.disjoint_diff) _ (hB\u2081 n)],\n      { refine add_le_of_nonpos_left _,\n        have : s \u2264[A] 0 :=\n          restrict_le_restrict_Union _ _ hB\u2081 (\u03bb m, let \u27e8_, h\u27e9 := (hB m).1 in h),\n        refine nonpos_of_restrict_le_zero _\n          (restrict_le_zero_subset _ _ (set.diff_subset _ _) this),\n        exact measurable_set.Union hB\u2081 },\n      { apply_instance },\n      { exact (measurable_set.Union hB\u2081).diff (hB\u2081 n) } },\n    { exact cInf_le bdd_below_measure_of_negatives \u27e8A, \u27e8hA\u2081, hA\u2082\u27e9, rfl\u27e9 } },\n  refine \u27e8A\u1d9c, hA\u2081.compl, _, (compl_compl A).symm \u25b8 hA\u2082\u27e9,\n  rw restrict_le_restrict_iff _ _ hA\u2081.compl,\n  intros C hC hC\u2081,\n  by_contra hC\u2082, push_neg at hC\u2082,\n  rcases exists_subset_restrict_nonpos hC\u2082 with \u27e8D, hD\u2081, hD, hD\u2082, hD\u2083\u27e9,\n  have : s (A \u222a D) < Inf s.measure_of_negatives,\n  { rw [\u2190 hA\u2083, of_union (set.disjoint_of_subset_right (set.subset.trans hD hC\u2081)\n        disjoint_compl_right) hA\u2081 hD\u2081],\n    linarith, apply_instance },\n  refine not_le.2 this _,\n  refine cInf_le bdd_below_measure_of_negatives \u27e8A \u222a D, \u27e8_, _\u27e9, rfl\u27e9,\n  { exact hA\u2081.union hD\u2081 },\n  { exact restrict_le_restrict_union _ _ hA\u2081 hA\u2082 hD\u2081 hD\u2082 },\nend\n\n/-- **The Hahn decomposition thoerem**: Given a signed measure `s`, there exist\ncomplement measurable sets `i` and `j` such that `i` is positive, `j` is negative. -/\ntheorem exists_is_compl_positive_negative (s : signed_measure \u03b1) :\n  \u2203 i j : set \u03b1, measurable_set i \u2227 0 \u2264[i] s \u2227 measurable_set j \u2227 s \u2264[j] 0 \u2227 is_compl i j :=\nlet \u27e8i, hi\u2081, hi\u2082, hi\u2083\u27e9 := exists_compl_positive_negative s in\n  \u27e8i, i\u1d9c, hi\u2081, hi\u2082, hi\u2081.compl, hi\u2083, is_compl_compl\u27e9\n\n/-- The symmetric difference of two Hahn decompositions have measure zero. -/\nlemma of_symm_diff_compl_positive_negative {s : signed_measure \u03b1}\n  {i j : set \u03b1} (hi : measurable_set i) (hj : measurable_set j)\n  (hi' : 0 \u2264[i] s \u2227 s \u2264[i\u1d9c] 0) (hj' : 0 \u2264[j] s \u2227 s \u2264[j\u1d9c] 0) :\n  s (i \u0394 j) = 0 \u2227 s (i\u1d9c \u0394 j\u1d9c) = 0 :=\nbegin\n  rw [restrict_le_restrict_iff s 0, restrict_le_restrict_iff 0 s] at hi' hj',\n  split,\n  { rw [symm_diff_def, set.diff_eq_compl_inter, set.diff_eq_compl_inter,\n        set.sup_eq_union, of_union,\n        le_antisymm (hi'.2 (hi.compl.inter hj) (set.inter_subset_left _ _))\n          (hj'.1 (hi.compl.inter hj) (set.inter_subset_right _ _)),\n        le_antisymm (hj'.2 (hj.compl.inter hi) (set.inter_subset_left _ _))\n          (hi'.1 (hj.compl.inter hi) (set.inter_subset_right _ _)),\n        zero_apply, zero_apply, zero_add],\n    { exact set.disjoint_of_subset_left (set.inter_subset_left _ _)\n        (set.disjoint_of_subset_right (set.inter_subset_right _ _)\n        (disjoint.comm.1 (is_compl.disjoint is_compl_compl))) },\n    { exact hj.compl.inter hi },\n    { exact hi.compl.inter hj } },\n  { rw [symm_diff_def, set.diff_eq_compl_inter, set.diff_eq_compl_inter,\n        compl_compl, compl_compl, set.sup_eq_union, of_union,\n        le_antisymm (hi'.2 (hj.inter hi.compl) (set.inter_subset_right _ _))\n          (hj'.1 (hj.inter hi.compl) (set.inter_subset_left _ _)),\n        le_antisymm (hj'.2 (hi.inter hj.compl) (set.inter_subset_right _ _))\n          (hi'.1 (hi.inter hj.compl) (set.inter_subset_left _ _)),\n        zero_apply, zero_apply, zero_add],\n    { exact set.disjoint_of_subset_left (set.inter_subset_left _ _)\n        (set.disjoint_of_subset_right (set.inter_subset_right _ _)\n        (is_compl.disjoint is_compl_compl)) },\n    { exact hj.inter hi.compl },\n    { exact hi.inter hj.compl } },\n  all_goals { measurability },\nend\n\nend signed_measure\n\nend measure_theory\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/measure_theory/decomposition/signed_hahn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.701523535243083}}
{"text": "/-\nCopyright (c) 2021 Eric Wieser. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Eric Wieser\n-/\nimport algebra.char_p.basic\n\n/-!\n# Lemmas about rings of characteristic two\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains results about `char_p R 2`, in the `char_two` namespace.\n\nThe lemmas in this file with a `_sq` suffix are just special cases of the `_pow_char` lemmas\nelsewhere, with a shorter name for ease of discovery, and no need for a `[fact (prime 2)]` argument.\n-/\n\nvariables {R \u03b9 : Type*}\n\nnamespace char_two\n\nsection semiring\nvariables [semiring R] [char_p R 2]\n\nlemma two_eq_zero : (2 : R) = 0 :=\nby rw [\u2190 nat.cast_two, char_p.cast_eq_zero]\n\n@[simp] lemma add_self_eq_zero (x : R) : x + x = 0 :=\nby rw [\u2190two_smul R x, two_eq_zero, zero_smul]\n\n@[simp] lemma bit0_eq_zero : (bit0 : R \u2192 R) = 0 :=\nby { funext, exact add_self_eq_zero _ }\n\nlemma bit0_apply_eq_zero (x : R) : (bit0 x : R) = 0 :=\nby simp\n\n@[simp] lemma bit1_eq_one : (bit1 : R \u2192 R) = 1 :=\nby { funext, simp [bit1] }\n\nlemma bit1_apply_eq_one (x : R) : (bit1 x : R) = 1 :=\nby simp\n\nend semiring\n\nsection ring\nvariables [ring R] [char_p R 2]\n\n@[simp] lemma neg_eq (x : R) : -x = x :=\nby rw [neg_eq_iff_add_eq_zero, \u2190two_smul R x, two_eq_zero, zero_smul]\n\nlemma neg_eq' : has_neg.neg = (id : R \u2192 R) :=\nfunext neg_eq\n\n@[simp] lemma sub_eq_add (x y : R) : x - y = x + y :=\nby rw [sub_eq_add_neg, neg_eq]\n\nlemma sub_eq_add' : has_sub.sub = ((+) : R \u2192 R \u2192 R) :=\nfunext $ \u03bb x, funext $ \u03bb y, sub_eq_add x y\n\nend ring\n\nsection comm_semiring\nvariables [comm_semiring R] [char_p R 2]\n\nlemma add_sq (x y : R) : (x + y) ^ 2 = x ^ 2 + y ^ 2 :=\nadd_pow_char _ _ _\n\nlemma add_mul_self (x y : R) : (x + y) * (x + y) = x * x + y * y :=\nby rw [\u2190pow_two, \u2190pow_two, \u2190pow_two, add_sq]\n\nopen_locale big_operators\n\nlemma list_sum_sq (l : list R) : l.sum ^ 2 = (l.map (^ 2)).sum :=\nlist_sum_pow_char _ _\n\nlemma list_sum_mul_self (l : list R) : l.sum * l.sum = (list.map (\u03bb x, x * x) l).sum :=\nby simp_rw [\u2190pow_two, list_sum_sq]\n\nlemma multiset_sum_sq (l : multiset R) : l.sum ^ 2 = (l.map (^ 2)).sum :=\nmultiset_sum_pow_char _ _\n\nlemma multiset_sum_mul_self (l : multiset R) : l.sum * l.sum = (multiset.map (\u03bb x, x * x) l).sum :=\nby simp_rw [\u2190pow_two, multiset_sum_sq]\n\nlemma sum_sq (s : finset \u03b9) (f : \u03b9 \u2192 R) :\n  (\u2211 i in s, f i) ^ 2 = \u2211 i in s, f i ^ 2 :=\nsum_pow_char _ _ _\n\nlemma sum_mul_self (s : finset \u03b9) (f : \u03b9 \u2192 R) :\n  (\u2211 i in s, f i) * (\u2211 i in s, f i) = \u2211 i in s, f i * f i :=\nby simp_rw [\u2190pow_two, sum_sq]\n\nend comm_semiring\n\nend char_two\n\nsection ring_char\nvariables [ring R]\n\nlemma neg_one_eq_one_iff [nontrivial R]: (-1 : R) = 1 \u2194 ring_char R = 2 :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, @@char_two.neg_eq _ (ring_char.of_eq h) 1\u27e9,\n  rw [eq_comm, \u2190sub_eq_zero, sub_neg_eq_add, \u2190 nat.cast_one, \u2190 nat.cast_add] at h,\n  exact ((nat.dvd_prime nat.prime_two).mp (ring_char.dvd h)).resolve_left char_p.ring_char_ne_one\nend\n\n@[simp] lemma order_of_neg_one [nontrivial R] :\n  order_of (-1 : R) = if ring_char R = 2 then 1 else 2 :=\nbegin\n  split_ifs,\n  { rw [neg_one_eq_one_iff.2 h, order_of_one] },\n  apply order_of_eq_prime,\n  { simp },\n  simpa [neg_one_eq_one_iff] using h\nend\n\nend ring_char\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/char_p/two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7015140317891596}}
{"text": "/-\nCopyright (c) 2019 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann\n-/\nimport algebra.continued_fractions.basic\n/-!\n# Basic Translation Lemmas Between Functions Defined for Continued Fractions\n\n## Summary\n\nSome simple translation lemmas between the different definitions of functions defined in\n`algebra.continued_fractions.basic`.\n-/\n\nnamespace generalized_continued_fraction\n\nsection general\n/-!\n### Translations Between General Access Functions\n\nHere we give some basic translations that hold by definition between the various methods that allow\nus to access the numerators and denominators of a continued fraction.\n-/\n\nvariables {\u03b1 : Type*} {g : generalized_continued_fraction \u03b1} {n : \u2115}\n\nlemma terminated_at_iff_s_terminated_at : g.terminated_at n \u2194 g.s.terminated_at n := by refl\n\nlemma terminated_at_iff_s_none : g.terminated_at n \u2194 g.s.nth n = none := by refl\n\nlemma part_num_none_iff_s_none : g.partial_numerators.nth n = none \u2194 g.s.nth n = none :=\nby cases s_nth_eq : (g.s.nth n); simp [partial_numerators, s_nth_eq]\n\nlemma terminated_at_iff_part_num_none : g.terminated_at n \u2194 g.partial_numerators.nth n = none :=\nby rw [terminated_at_iff_s_none, part_num_none_iff_s_none]\n\nlemma part_denom_none_iff_s_none : g.partial_denominators.nth n = none \u2194 g.s.nth n = none :=\nby cases s_nth_eq : (g.s.nth n); simp [partial_denominators, s_nth_eq]\n\nlemma terminated_at_iff_part_denom_none : g.terminated_at n \u2194 g.partial_denominators.nth n = none :=\nby rw [terminated_at_iff_s_none, part_denom_none_iff_s_none]\n\nlemma part_num_eq_s_a {gp : pair \u03b1} (s_nth_eq : g.s.nth n = some gp) :\n  g.partial_numerators.nth n = some gp.a :=\nby simp [partial_numerators, s_nth_eq]\n\nlemma part_denom_eq_s_b {gp : pair \u03b1} (s_nth_eq : g.s.nth n = some gp) :\n  g.partial_denominators.nth n = some gp.b :=\nby simp [partial_denominators, s_nth_eq]\n\nlemma exists_s_a_of_part_num {a : \u03b1} (nth_part_num_eq : g.partial_numerators.nth n = some a) :\n  \u2203 gp, g.s.nth n = some gp \u2227 gp.a = a :=\nby simpa [partial_numerators, seq.map_nth] using nth_part_num_eq\n\nlemma exists_s_b_of_part_denom {b : \u03b1} (nth_part_denom_eq : g.partial_denominators.nth n = some b) :\n  \u2203 gp, g.s.nth n = some gp \u2227 gp.b = b :=\nby simpa [partial_denominators, seq.map_nth] using nth_part_denom_eq\n\nend general\n\nsection with_division_ring\n/-!\n### Translations Between Computational Functions\n\nHere we  give some basic translations that hold by definition for the computational methods of a\ncontinued fraction.\n-/\n\nvariables {K : Type*} {g : generalized_continued_fraction K} {n : \u2115} [division_ring K]\n\nlemma nth_cont_eq_succ_nth_cont_aux : g.continuants n = g.continuants_aux (n + 1) := rfl\nlemma num_eq_conts_a : g.numerators n = (g.continuants n).a := rfl\nlemma denom_eq_conts_b : g.denominators n = (g.continuants n).b := rfl\nlemma convergent_eq_num_div_denom : g.convergents n = g.numerators n / g.denominators n := rfl\nlemma convergent_eq_conts_a_div_conts_b :\n  g.convergents n = (g.continuants n).a / (g.continuants n).b := rfl\n\nlemma exists_conts_a_of_num {A : K} (nth_num_eq : g.numerators n = A) :\n  \u2203 conts, g.continuants n = conts \u2227 conts.a = A :=\nby simpa\n\nlemma exists_conts_b_of_denom {B : K} (nth_denom_eq : g.denominators n = B) :\n  \u2203 conts, g.continuants n = conts \u2227 conts.b = B :=\nby simpa\n\n@[simp]\nlemma zeroth_continuant_aux_eq_one_zero : g.continuants_aux 0 = \u27e81, 0\u27e9 := rfl\n@[simp]\nlemma first_continuant_aux_eq_h_one : g.continuants_aux 1 = \u27e8g.h, 1\u27e9 := rfl\n@[simp]\nlemma zeroth_continuant_eq_h_one : g.continuants 0 = \u27e8g.h, 1\u27e9 := rfl\n@[simp]\nlemma zeroth_numerator_eq_h : g.numerators 0 = g.h := rfl\n@[simp]\nlemma zeroth_denominator_eq_one : g.denominators 0 = 1 := rfl\n@[simp]\nlemma zeroth_convergent_eq_h : g.convergents 0 = g.h :=\nby simp [convergent_eq_num_div_denom, num_eq_conts_a, denom_eq_conts_b, div_one]\n\nlemma second_continuant_aux_eq {gp : pair K} (zeroth_s_eq : g.s.nth 0 = some gp) :\n  g.continuants_aux 2 = \u27e8gp.b * g.h + gp.a, gp.b\u27e9 :=\nby simp [zeroth_s_eq, continuants_aux, next_continuants, next_denominator, next_numerator]\n\nlemma first_continuant_eq {gp : pair K} (zeroth_s_eq : g.s.nth 0 = some gp) :\n  g.continuants 1 = \u27e8gp.b * g.h + gp.a, gp.b\u27e9 :=\nby simp [nth_cont_eq_succ_nth_cont_aux, (second_continuant_aux_eq zeroth_s_eq)]\n\nlemma first_numerator_eq {gp : pair K} (zeroth_s_eq : g.s.nth 0 = some gp) :\n  g.numerators 1 = gp.b * g.h + gp.a :=\nby simp[num_eq_conts_a, (first_continuant_eq zeroth_s_eq)]\n\nlemma first_denominator_eq {gp : pair K} (zeroth_s_eq : g.s.nth 0 = some gp) :\n  g.denominators 1 = gp.b :=\nby simp[denom_eq_conts_b, (first_continuant_eq zeroth_s_eq)]\n\n@[simp]\nlemma zeroth_convergent'_aux_eq_zero {s : seq $ pair K} : convergents'_aux s 0 = 0 := rfl\n@[simp]\nlemma zeroth_convergent'_eq_h : g.convergents' 0 = g.h := by simp [convergents']\n\nend with_division_ring\nend generalized_continued_fraction\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/continued_fractions/translations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832332, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7015140169969245}}
{"text": "import tactic\nimport data.set\nimport logic.basic\n\nopen set\n\nnamespace mth1001\n\nsection intersection_and_union\n\n-- We'll deal with sets on a type `U`.\nvariable U : Type*\nvariables A B C : set U\n\n/-\nTyping set notation in Lean:\n\n`\u222a` is `\\cup`\n`\u2229` is `\\cap`\n`\u2208` is `\\in`\n`\u2209` is `\\notin`\n`\u2205` is `\\empty`\n-/\n\n\n/-\nThroughout this file, we use `mem_inter_iff` and `mem_union_eq` to rewrite intersections and\nunions as conjunctions and disjunctions.\n-/\nexample (x : U) : x \u2208 A \u2229 B \u2194 x \u2208 A \u2227 x \u2208 B := by rw mem_inter_iff\nexample (x : U) : x \u2208 A \u222a B \u2194 x \u2208 A \u2228 x \u2208 B := by rw mem_union_eq\n\n/-\nWe prove right distributivity of intersection over union.\n-/\nexample : (A \u222a B) \u2229 C = (A \u2229 C) \u222a (B \u2229 C) :=\nbegin\n  ext, -- Assume `x : U`. It suffices to show `x \u2208 (A \u222a B) \u2229 C \u2194 x \u2208 (A \u2229 C) \u222a (B \u2229 C)`.\n  -- Repeatedly apply the basic theorems on membership of intersections and unions.\n  -- `or_and_distrib_right` is the distributive law, `(P \u2228 Q) \u2227 R \u2194 (P \u2227 Q) \u2228 (Q \u2227 R)`.\n  calc x \u2208 (A \u222a B) \u2229 C\n        \u2194 x \u2208 (A \u222a B) \u2227 x \u2208 C                : by rw mem_inter_iff\n    ... \u2194 (x \u2208 A \u2228 x \u2208 B) \u2227 x \u2208 C            : by rw mem_union_eq\n    ... \u2194 (x \u2208 A \u2227 x \u2208 C) \u2228 (x \u2208 B \u2227 x \u2208 C)  : by rw or_and_distrib_right\n    ... \u2194 x \u2208 A \u2229 C \u2228 x \u2208 B \u2229 C              : by rw [mem_inter_iff, mem_inter_iff]\n    ... \u2194 x \u2208 (A \u2229 C) \u222a (B \u2229 C)              : by rw mem_union_eq,            \nend\n\n-- Alternatively, we can just rewrite the goal many times.\nexample : (A \u222a B) \u2229 C = (A \u2229 C) \u222a (B \u2229 C) :=\nbegin\n  ext, -- Assume `x : U`. It suffices to show `x \u2208 (A \u222a B) \u2229 C \u2194 x \u2208 (A \u2229 C) \u222a (B \u2229 C)`.\n  repeat { rw mem_inter_iff }, \n  repeat { rw mem_union_eq, },\n  repeat { rw mem_inter_iff },\n  rw or_and_distrib_right,  \nend\n\n/-  ***************************\n    Laws of propositional logic\n    *************************** -/\n\n-- Feel free to use the following laws in the proofs below.\n\nvariables p q r : Prop\n\nexample : p \u2228 (q \u2227 r) \u2194 (p \u2228 q) \u2227 (p \u2228 r) := by rw or_and_distrib_left\nexample : p \u2227 (q \u2228 r) \u2194 (p \u2227 q) \u2228 (p \u2227 r) := by rw and_or_distrib_left\nexample : (p \u2228 q) \u2227 r \u2194 (p \u2227 r) \u2228 (q \u2227 r) := by rw or_and_distrib_right\nexample : (p \u2227 q) \u2228 r \u2194 (p \u2228 r) \u2227 (q \u2228 r) := by rw and_or_distrib_right\nexample : (p \u2227 q) \u2227 r \u2194 p \u2227 (q \u2227 r)       := by rw and_assoc\nexample : (p \u2228 q) \u2228 r \u2194 p \u2228 (q \u2228 r)       := by rw or_assoc\nexample : p \u2228 false \u2194 p                   := by rw or_false\nexample : p \u2227 false \u2194 false               := by rw and_false\nexample : p \u2227 p \u2194 p                       := by rw and_self\nexample : p \u2228 p \u2194 p                       := by rw or_self\n\n-- Exercise 131:\n-- Adapt either of the proofs above to give the following distributive law.\nexample : A \u2229 (B \u222a C) = (A \u2229 B) \u222a (A \u2229 C) :=\nbegin\n  sorry  \nend\n\n-- Exercise 132:\nexample : A \u2229 B = B \u2229 A :=\nbegin\n  sorry  end\n\n-- Exercise 133:\nexample : A \u222a B = B \u222a A :=\nbegin\n  sorry  \nend\n\n-- Exercise 134:\nexample : (A \u2229 B) \u2229 C = A \u2229 (B \u2229 C) :=\nbegin\n  sorry  \nend\n\n-- Exercise 135:\nexample : (A \u222a B) \u222a C = A \u222a (B \u222a C) :=\nbegin\n  sorry  \nend\n\n-- Exercise 136:\nexample : A \u2229 A = A :=\nbegin\n  sorry  \nend\n\n/-\nFor the next result, we use `empty_def` and `mem_set_of_eq`, statements that are equivalent to our\nmathematical definitions of empty set and set membership, respectively.\n-/\nexample : \u2205 = {x : U | false}                            := by rw empty_def\nexample (P : U \u2192 Prop) (z : U) : z \u2208 {x : U | P x} = P z := by rw mem_set_of_eq\n\nexample : A \u2229 \u2205 = \u2205 :=\nbegin\n  ext x, -- Assume `x : U`. It remains to prove `x \u2208 A \u2229 \u2205 \u2194 x \u2208 \u2205`.\n  rw mem_inter_iff, -- Rewrite `x \u2208 A \u2229 \u2205` as `x \u2208 A \u2227 x \u2208 \u2205`.\n  rw empty_def, -- Rewrite `\u2205` as `{x : U | \u22a5}`.\n  rw mem_set_of_eq, -- Rewrite `x \u2208 {x : U | \u22a5}` as `\u22a5`.\n  rw and_false, -- Complete the goal using the result `P \u2227 \u22a5 \u2194 \u22a5` and reflexivity of `\u2194`.\nend\n\n-- Exercise 137:\nexample : A \u222a \u2205 = A :=\nbegin\n  sorry  \nend\n\nend intersection_and_union\n\nend mth1001\n", "meta": {"author": "gihanmarasingha", "repo": "mth1001_tutorial", "sha": "bb277eebd5013766e1418365b91416b406275130", "save_path": "github-repos/lean/gihanmarasingha-mth1001_tutorial", "path": "github-repos/lean/gihanmarasingha-mth1001_tutorial/mth1001_tutorial-bb277eebd5013766e1418365b91416b406275130/src/exercises/src_25_intersection_and_union.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7015140166414658}}
{"text": "/- Homework 2.3: Functional Programming \u2014 Monads -/\n\nnamespace homework\n\n\n/- Question 1: `map` for monads\n\nDefine `map` for monads. This is the generalization of `map` on lists. Use the monad operations to\ndefine `map`. The _functorial properties_ (`map_id` and `map_map`) are derived from the monad laws.\n\nThis time, we use Lean's monad definition. In combination, `monad` and `is_lawful_monad` include the\nsame constants, laws, and syntactic sugar as the `monad` type class from the lecture. -/\n \nsection map\n\nvariables {M : Type \u2192 Type} [monad M] [is_lawful_monad M]\n\n/- 1.1. Define `map` on `M`.\n\n**Hint:** The challenge is to find a way to create `M \u03b2`. Follow the types. -/\n\ndef map {\u03b1 \u03b2} (f : \u03b1 \u2192 \u03b2) (m : M \u03b1) : M \u03b2:=\ndo a <- m,\n   return (f a)\n/- 1.2. Prove the identity law for `map`. -/\n\nlemma map_id {\u03b1} (m : M \u03b1) : map id m = m := by simp[map]\n\n/- 1.3. Prove the composition law for `map`. -/\n\nlemma map_map {\u03b1 \u03b2 \u03b3} (f : \u03b1 \u2192 \u03b2) (g : \u03b2 \u2192 \u03b3) (m : M \u03b1) :\n  map g (map f m) = map (g \u2218 f) m :=\nbegin\nsimp[map, return],\n\nend\n\nend map\n\n\n/- Question 2: Monadic structure on lists -/\n\n/- `list` can be seen as a monad, similar to `option` but with several possible outcomes. It is also\nsimilar to `set`, but the results are ordered and finite. The code below sets `list` up as a\nmonad. -/\n\nnamespace list\n\nprotected def bind {\u03b1 \u03b2 : Type} : list \u03b1 \u2192 (\u03b1 \u2192 list \u03b2) \u2192 list \u03b2\n| []       f := []\n| (a :: l) f := f a ++ bind l f\n\nprotected def pure {\u03b1 : Type} (a : \u03b1) : list \u03b1 := [a]\n\nlemma pure_eq_singleton {\u03b1} (a : \u03b1) : pure a = [a] :=\nby refl\n\ninstance : monad list :=\n{ pure := @list.pure,\n  bind := @list.bind }\n\n/- 2.1. Prove the following properties of `bind` under the empty list (`[]`), the list constructor\n(`::`), and `++`. -/\n\n@[simp] lemma bind_nil {\u03b1 \u03b2} (f : \u03b1 \u2192 list \u03b2) : [] >>= f = [] := by refl\n\n@[simp] lemma bind_cons {\u03b1 \u03b2} (f : \u03b1 \u2192 list \u03b2) (a : \u03b1) (l : list \u03b1) :\n  (a :: l) >>= f = f a ++ (l >>= f) := by simp[bind]\n\n@[simp] lemma bind_append {\u03b1 \u03b2} (f : \u03b1 \u2192 list \u03b2) :\n  \u2200l l':list \u03b1, (l ++ l') >>= f = (l >>= f) ++ (l' >>= f):=\n  begin\n  intros a b,\n  simp[bind]\n  end\n\n/- 2.2. Prove the monadic laws for `list`.\n\n**Hint:** The simplifier cannot see through the type class definition of `pure`. You can use\n`pure_eq_singleton` to unfold the definition or `show` to state the lemma statement using `bind` and\n`[...]`. -/\n\nlemma pure_bind {\u03b1 \u03b2} (a : \u03b1) (f : \u03b1 \u2192 list \u03b2) : (pure a >>= f) = f a := by simp[pure_eq_singleton]\n\nlemma bind_pure {\u03b1} : \u2200l : list \u03b1, l >>= pure = l := by simp[pure_eq_singleton]\n\nlemma bind_assoc {\u03b1 \u03b2 \u03b3} (f : \u03b1 \u2192 list \u03b2) (g : \u03b2 \u2192 list \u03b3) :\n  \u2200l : list \u03b1, (l >>= f) >>= g = l >>= (\u03bba, f a >>= g)\n| [] := by refl\n| (x :: xs) := by simp[bind_assoc xs] \n\nlemma bind_pure_comp_eq_map {\u03b1 \u03b2} {f : \u03b1 \u2192 \u03b2} :\n  \u2200l : list \u03b1, l >>= (pure \u2218 f) = list.map f l\n| [] := by refl\n| (x :: xs) := begin simp[bind_pure_comp_eq_map xs], simp[pure], simp[list.ret] end\n\n/- 2.3 **optional**. Register `list` as a lawful monad. This may be a challenge. -/\n\ninstance : is_lawful_monad list :=\nsorry\n\nend list\n\nend homework\n", "meta": {"author": "KjellZijlemaker", "repo": "Logical_Verification_VU", "sha": "4578b93bf1615466996157bb333c84122b201d99", "save_path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU", "path": "github-repos/lean/KjellZijlemaker-Logical_Verification_VU/Logical_Verification_VU-4578b93bf1615466996157bb333c84122b201d99/Exercises week 6/23_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544824, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7015140078409993}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport measure_theory.constructions.borel_space\n\n/-!\n# Measurability of `\u230ax\u230b` etc\n\nIn this file we prove that `int.floor`, `int.ceil`, `int.fract`, `nat.floor`, and `nat.ceil` are\nmeasurable under some assumptions on the (semi)ring.\n-/\n\nopen set\n\nsection floor_ring\n\nvariables {\u03b1 R : Type*} [measurable_space \u03b1] [linear_ordered_ring R] [floor_ring R]\n  [topological_space R] [order_topology R] [measurable_space R]\n\nlemma int.measurable_floor [opens_measurable_space R] :\n  measurable (int.floor : R \u2192 \u2124) :=\nmeasurable_to_encodable $ \u03bb x, by simpa only [int.preimage_floor_singleton]\n  using measurable_set_Ico\n\n@[measurability] lemma measurable.floor [opens_measurable_space R]\n  {f : \u03b1 \u2192 R} (hf : measurable f) : measurable (\u03bb x, \u230af x\u230b) :=\nint.measurable_floor.comp hf\n\nlemma int.measurable_ceil [opens_measurable_space R] :\n  measurable (int.ceil : R \u2192 \u2124) :=\nmeasurable_to_encodable $ \u03bb x,\n  by simpa only [int.preimage_ceil_singleton] using measurable_set_Ioc\n\n@[measurability] lemma measurable.ceil [opens_measurable_space R]\n  {f : \u03b1 \u2192 R} (hf : measurable f) : measurable (\u03bb x, \u2308f x\u2309) :=\nint.measurable_ceil.comp hf\n\nlemma measurable_fract [borel_space R] : measurable (int.fract : R \u2192 R) :=\nbegin\n  intros s hs,\n  rw int.preimage_fract,\n  exact measurable_set.Union (\u03bb z, measurable_id.sub_const _ (hs.inter measurable_set_Ico))\nend\n\n@[measurability] lemma measurable.fract [borel_space R]\n  {f : \u03b1 \u2192 R} (hf : measurable f) : measurable (\u03bb x, int.fract (f x)) :=\nmeasurable_fract.comp hf\n\nlemma measurable_set.image_fract [borel_space R] {s : set R} (hs : measurable_set s) :\n  measurable_set (int.fract '' s) :=\nbegin\n  simp only [int.image_fract, sub_eq_add_neg, image_add_right'],\n  exact measurable_set.Union (\u03bb m, (measurable_add_const _ hs).inter measurable_set_Ico)\nend\n\nend floor_ring\n\nsection floor_semiring\n\nvariables {\u03b1 R : Type*} [measurable_space \u03b1] [linear_ordered_semiring R] [floor_semiring R]\n  [topological_space R] [order_topology R] [measurable_space R] [opens_measurable_space R]\n  {f : \u03b1 \u2192 R}\n\nlemma nat.measurable_floor : measurable (nat.floor : R \u2192 \u2115) :=\nmeasurable_to_encodable $ \u03bb n, by cases eq_or_ne \u230an\u230b\u208a 0; simp [*, nat.preimage_floor_of_ne_zero]\n\n@[measurability] lemma measurable.nat_floor (hf : measurable f) : measurable (\u03bb x, \u230af x\u230b\u208a) :=\nnat.measurable_floor.comp hf\n\nlemma nat.measurable_ceil : measurable (nat.ceil : R \u2192 \u2115) :=\nmeasurable_to_encodable $ \u03bb n, by cases eq_or_ne \u2308n\u2309\u208a 0; simp [*, nat.preimage_ceil_of_ne_zero]\n\n@[measurability] lemma measurable.nat_ceil (hf : measurable f) : measurable (\u03bb x, \u2308f x\u2309\u208a) :=\nnat.measurable_ceil.comp hf\n\nend floor_semiring\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/measure_theory/function/floor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7014906076698736}}
{"text": "import data.real.basic\n\nimport for_mathlib.decimal_expansions\nimport zero_point_seven_one -- \"obvious\" proof that 0.71 has no 8's in decimal expansion!\n/-\n\nM1F May exam 2018, question 2.\n\n-/\n\nuniverse u\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n-- Q2(a)(i)\ndef ub (S : set \u211d) (x : \u211d) := \u2200 s \u2208 S, s \u2264 x ---ans\n\n-- Q2(a)(ii)\n-- iba: is bounded above\ndef iba (S : set \u211d) := \u2203 x, ub S x ---ans\n\n-- Q2(a)(iii)\ndef lub (S : set \u211d) (b : \u211d) := ub S b \u2227 \u2200 y : \u211d, (ub S y \u2192 b \u2264 y) ---ans\n\n-- Q2(b)\ntheorem lub_duh (S : set \u211d) : (\u2203 x, lub S x) \u2192 S \u2260 \u2205 \u2227 iba S := ---ans\n    begin\n        intro Hexlub, cases Hexlub with x Hlub,\n        split,\n            intro Hemp, rw set.empty_def at Hemp, \n            cases Hlub with Hub Hl,\n            have Hallub : \u2200 y : \u211d, ub S y, \n                unfold ub, rw Hemp, change (\u2200 (y s : \u211d), false \u2192 s \u2264 y), \n                intros y s Hf, exfalso, exact Hf,\n            have Hneginf : \u2200 y : \u211d, x \u2264 y,\n                intro y, apply Hl, apply Hallub,\n            have Hcontr := Hneginf (x - 1),\n            revert Hcontr, norm_num,\n            existsi x, exact Hlub.left,\n    end\n\n-- Q2(c)(i) preparation\ndef S1 := {x : \u211d | x < 59}\n\nlemma between_bounds (x y : \u211d) (H : x < y) : x < (x + y) / 2 \u2227 (x + y) / 2 < y := \n\u27e8by linarith, by linarith\u27e9\n\n-- Q2(c)(i)\ntheorem S1_lub : lub S1 59 := ---ans\n    begin\n        split,\n            intro, change (s < 59 \u2192 s \u2264 59), exact le_of_lt,\n        intro y, change ((\u2200 (s : \u211d), s < 59 \u2192 s \u2264 y) \u2192 59 \u2264 y), intro Hbub,\n        apply le_of_not_gt, intro Hbadub,\n        have Houtofbounds := between_bounds y 59 Hbadub,\n        apply not_le_of_gt Houtofbounds.1 (Hbub ((y + 59) / 2) Houtofbounds.2),\n    end\n\n-- Q2(c)(ii) preparations\n\ndefinition S2 : set \u211d := {x | 7/10 < x \u2227 x < 9/10 \u2227 \n  \u2200 n : \u2115, decimal.expansion_nonneg x n \u2260 8}\n\nlemma S2_nonempty_and_bounded : (\u2203 s : \u211d, s \u2208 S2) \u2227 \u2200 (s : \u211d), s \u2208 S2 \u2192 s \u2264 9/10 :=\nbegin\n  split,\n  { -- 0.71 \u2208 S\n    use (71 / 100 : \u211d),\n    split, norm_num, split, norm_num,\n    exact no_eights_in_0_point_71\n  },\n  rintro s \u27e8hs1, hs2, h\u27e9,\n  exact le_of_lt hs2 \nend\n\n-- Q2(c)(ii)\ntheorem S2_has_lub : \u2203 b : \u211d, lub S2 b :=\nbegin\n  cases S2_nonempty_and_bounded with Hne Hbd,\n  have H := real.exists_sup S2 Hne \u27e8(9/10 : \u211d), Hbd\u27e9,\n  cases H with b Hb,\n  use b,\n  split,\n  { intros s2 Hs2,\n    exact (Hb b).mp (le_refl _) s2 Hs2, \n  },\n  { intros y Hy,\n    exact (Hb y).mpr Hy,\n  }\nend \n\n-- Q2(d)(i)\ntheorem ublub_the_first (S : set \u211d) (b : \u211d) (hub : ub S b) (hin : b \u2208 S) : lub S b := ---ans\n    begin\n        split,\n            exact hub,\n            intros y huby,\n            exact huby b hin,\n    end\n\n-- Q2(d)(ii)\ntheorem adlub_the_second (S T : set \u211d) (b c : \u211d) (hlubb : lub S b) (hlubc : lub T c) ---ans\n: lub ({x : \u211d | \u2203 s t : \u211d, s \u2208 S \u2227 t \u2208 T \u2227 x = s + t}) (b + c) :=\n    begin\n        split,\n            unfold ub, simp, intros x s hss t htt hxst, rw hxst,\n            apply add_le_add (hlubb.1 s hss) (hlubc.1 t htt),\n            unfold ub, simp, intros x Hx,\n            apply le_of_not_gt, intro Hcontr,\n            let \u03b5 := b + c - x, \n            have Hcontr' : \u03b5 > 0 := (by linarith : b + c - x > 0),\n            have rwx : x = (b - \u03b5 / 2) + (c - \u03b5 / 2) \n            := (by linarith : x = (b - (b + c - x) / 2) + (c - (b + c - x) / 2)),\n            have hnbub : \u2203 s' \u2208 S, b - \u03b5 / 2 < s',\n                by_contradiction,\n                have a' : (\u00ac\u2203 (s' : \u211d), s' \u2208 S \u2227 b - \u03b5 / 2 < s'), \n                    intro b, apply a, cases b with \u03c3 H\u03c3, existsi \u03c3, existsi H\u03c3.1, exact H\u03c3.2,\n                have a'' : \u2200 (x : \u211d), x \u2208 S \u2192 \u00ac(b - \u03b5 / 2 < x),\n                    intros x Hx Hb, rw not_exists at a', apply a' x, exact \u27e8Hx, Hb\u27e9,\n                simp only [not_lt] at a'', rw \u2190ub at a'',\n                have a''' := hlubb.2 _ a'',\n                linarith,\n            have hnbuc : \u2203 t' \u2208 T, c - \u03b5 / 2 < t',\n                by_contradiction,\n                have a' : (\u00ac\u2203 (t' : \u211d), t' \u2208 T \u2227 c - \u03b5 / 2 < t'), \n                    intro b, apply a, cases b with \u03c3 H\u03c3, existsi \u03c3, existsi H\u03c3.1, exact H\u03c3.2,\n                have a'' : \u2200 (x : \u211d), x \u2208 T \u2192 \u00ac(c - \u03b5 / 2 < x),\n                    intros x Hx Hc, rw not_exists at a', apply a' x, exact \u27e8Hx, Hc\u27e9,\n                simp only [not_lt] at a'', rw \u2190ub at a'',\n                have a''' := hlubc.2 _ a'',\n                linarith,\n            cases hnbub with s' hnbub', cases hnbub' with Hs' hnbub'',\n            cases hnbuc with t' hnbuc', cases hnbuc' with Ht' hnbuc'',\n            have Hx' := Hx (s' + t') s' Hs' t' Ht' rfl,\n            have Haha : x < x \n            := lt_of_lt_of_le (by { rw rwx, apply add_lt_add hnbub'' hnbuc'' } : x < s' + t') Hx',\n            linarith,            \n    end\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M1F-exam-may-2018", "sha": "8b5eca2037d4a14d6cfac3da1858b6c4119216d3", "save_path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018", "path": "github-repos/lean/ImperialCollegeLondon-M1F-exam-may-2018/M1F-exam-may-2018-8b5eca2037d4a14d6cfac3da1858b6c4119216d3/src/Q2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7014905940622962}}
{"text": "import game.world9.level3 -- hide\nnamespace mynat -- hide\n\n/-\n# Advanced Multiplication World\n\n## Level 4: `mul_left_cancel`\n\nThis is the last of the bonus multiplication levels.\n`mul_left_cancel` will be useful in inequality world.\n\nPeople find this level hard. I have probably had more questions about this\nlevel than all the other levels put together, in fact. Many levels in this\ngame can just be solved by \"running at it\" -- do induction on one of the\nvariables, keep your head, and you're done. In fact, if you like a challenge,\nit might be instructive if you stop reading after the end of this paragraph and try solving this level now by induction,\nseeing the trouble you run into, and reading the rest of these comments afterwards. This level\nhas a sting in the tail. If you are a competent mathematician, try\nand figure out what is going on. Write down a maths proof of the\ntheorem in this level. Exactly what statement do you want to prove\nby induction? It is subtle.\n\nOk so here are some spoilers. The problem with naively running at it, is that if you try induction on,\nsay, $c$, then you are imagining a and b as fixed, and your inductive\nhypothesis $P(c)$ is $ab=ac \\implies b=c$. So for your inductive step\nyou will be able to assume $ab=ad \\implies b=d$ and your goal will\nbe to show $ab=a(d+1) \\implies b=d+1$. When you also assume $ab=a(d+1)$\nyou will realise that your inductive hypothesis is *useless*, because\n$ab=ad$ is not true! The statement $P(c)$ (with $a$ and $b$ regarded\nas constants) is not provable by induction.\n\nWhat you *can* prove by induction is the following *stronger* statement.\nImagine $a\\not=0$ as fixed, and then prove \"for all $b$, if $ab=ac$ then $b=c$\"\nby induction on $c$. This gives us the extra flexibility we require.\nNote that we are quantifying over all $b$ in the inductive hypothesis -- it\nis essential that $b$ is not fixed. \n\nYou can do this in two ways in Lean -- before you start the induction\nyou can write `revert b,`. The `revert` tactic is the opposite of the `intro`\ntactic; it replaces the `b` in the hypotheses with \"for all $b$\" in the goal.\n\nAlternatively, you can write `induction c with d hd\ngeneralizing b` as the first line of the proof. \n\nIf you do not modify your technique in this way, then this level seems\nto be impossible (judging by the comments I've had about it!)\n-/\n\n/- Theorem\nIf $a \\neq 0$, $b$ and $c$ are natural numbers such that\n$ ab = ac, $\nthen $b = c$.\n-/\ntheorem mul_left_cancel (a b c : mynat) (ha : a \u2260 0) : a * b = a * c \u2192 b = c :=\nbegin [nat_num_game]\n  induction c with d hd generalizing b,\n  { rw mul_zero,\n    intro h,\n    cases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ h) with h1 h2,\n      exfalso,\n      apply ha,\n      assumption,\n    assumption\n  },\n  { intro hb,\n    cases b with c,\n    { rw mul_zero at hb,\n      exfalso,\n      apply ha,\n      symmetry at hb,\n      cases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ hb) with h h,\n        exact h,\n      exfalso,\n      exact succ_ne_zero _ h,\n    },\n    { have h : c = d,\n        apply hd,\n        rw mul_succ at hb,\n        rw mul_succ at hb,\n        apply add_right_cancel _ _ _ hb,\n      rw h,\n      refl,\n    }\n  }\nend\n\nend mynat -- hide\n\n/-\nYou should now be ready for inequality world.\n-/\n\n/- Tactic : revert\n\n## Summary\n\n`revert x` is the opposite to `intro x`.\n\n## Details\n\nIf the tactic state looks like this\n\n```\nP Q : Prop,\nh : P\n\u22a2 Q\n```\n\nthen `revert h` will change it to\n\n```\nP Q : Prop\n\u22a2 P \u2192 Q\n```\n\n`revert` also works with things like natural numbers: if\nthe tactic state looks like this\n\n```\nm : mynat\n\u22a2 m + 1 = succ m\n```\n\nthen `revert m` will turn it into\n\n```\n\u22a2 \u2200 (m : mynat), m + 1 = mynat.succ m\n```\n\n-/\n", "meta": {"author": "ImperialCollegeLondon", "repo": "natural_number_game", "sha": "f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd", "save_path": "github-repos/lean/ImperialCollegeLondon-natural_number_game", "path": "github-repos/lean/ImperialCollegeLondon-natural_number_game/natural_number_game-f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd/src/game/world9/level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7014905916152737}}
{"text": "import topologia\n\nopen topological_space\nopen set\n\nvariables (X : Type) [topological_space X]\n\ndef is_dense {X : Type} [topological_space X] (A : set X) : Prop := closure A = univ\n\nlemma dense_iff (A : set X) : is_dense A \u2194 (interior (A.compl) = \u2205) := -- why not A\u1d9c?, then the refl, line it's not necesary\nbegin\n  rw is_dense,\n  rw closure_eq_compl_of_interior_compl,\n  rw compl_univ_iff,\n  refl,\nend\n\nlemma dense_iff' (A : set X) : is_dense A \u2194\n  \u2200 x : X, \u2200 U : set X, is_neighborhood U x \u2192 U \u2229 A \u2260 \u2205 :=\nbegin\n  unfold is_dense,\n  split; intro h,\n  {\n    intros x U hUx,\n    have hx : x \u2208 closure A,\n    {\n      rw h,\n      exact mem_univ x,\n    },\n    exact hx U hUx,\n  },\n  {\n    simp only [closure_eq_compl_of_interior_compl, compl_univ_iff,\n      set.eq_empty_iff_forall_not_mem, interior],\n    intro x,\n    intro hx,\n    refine h x A\u1d9c hx _,\n    norm_num,\n  },\nend\n\ndef boundary {X : Type} [topological_space X] (A : set X) := closure A \u2229 closure A\u1d9c\n\nlemma boundary_def (A : set X) : boundary A = (closure A) \\ (interior A) :=\nbegin\n  rw boundary,\n  rw closure_eq_compl_of_interior_compl A\u1d9c,\n  rw compl_compl,\n  refl,\nend\n\nlemma mem_boundary_iff (A : set X) (x : X) :\n  x \u2208 boundary A \u2194 \u2200 U : set X, is_neighborhood U x \u2192 (U \u2229 A \u2260 \u2205 \u2227 U \u2229 A.compl \u2260 \u2205) :=\nbegin\n  split; intro h,\n  {\n    intros U hU,\n    exact \u27e8h.1 U hU, h.2 U hU\u27e9,\n  },\n  {\n    have hx: (is_adherent_point A x) \u2227 (is_adherent_point A\u1d9c x), \n    {\n      split; intros U hU,\n        exact (h U hU).1,\n        exact (h U hU).2,\n    },\n    exact \u27e8hx.1, hx.2\u27e9,\n  }\nend\n\nclass kolmogorov_space : Prop :=\n(t0 : \u2200 (x y : X) (h : y \u2260 x) , \u2203 (U : set X) (hU : is_open U), ((x \u2208 U) \u2227 (y \u2209 U)) \u2228 ((x \u2209 U) \u2227 (y \u2208 U)))\n\nclass frechet_space : Prop := \n(t1 : \u2200 (x y : X) (h : y \u2260 x), \u2203 (U : set X) (hU : is_open U), (x \u2208 U) \u2227 (y \u2209 U)) -- Marc : look up what's the best way to do this\n\nnamespace frechet_space\n\ninstance T1_is_T0 [frechet_space X] : kolmogorov_space X :=\n{ t0 := \nbegin\n  intros x y hxy,\n  obtain \u27e8U, hU, hh\u27e9 := t1 x y hxy,\n  use U,\n  split,\n  { exact hU },\n  {\n    left,\n    exact hh,\n  },\nend\n}\n\nlemma T1_characterisation : frechet_space X \u2194 (\u2200 (x : X), is_closed ({x} : set X)) :=\nbegin\n  split,\n  {\n    intros h x,\n    unfold is_closed,\n    let I := {U : set X | (x \u2209 U) \u2227 (is_open U)},\n    have p : \u22c3\u2080 I = {x}\u1d9c,\n    {\n      apply subset.antisymm; intros t ht, \n      {\n        rcases ht with \u27e8A,\u27e8hxA, hA\u27e9, htA\u27e9,\n        simp,\n        intro htx,\n        rw htx at htA,\n        exact hxA htA,     \n      },\n      {\n        have htx := (mem_compl_singleton_iff.mp ht).symm,\n        replace h := h.t1,\n        obtain \u27e8U, hU, hh\u27e9 := h t x htx,\n        exact \u27e8U, \u27e8hh.2, hU\u27e9, hh.1\u27e9,\n      }\n    },\n    rw \u2190 p,\n    have c : \u2200 B \u2208 I, is_open B,\n      finish,\n    exact topological_space.union I c,\n  },\n  {\n    intros h,\n    fconstructor,\n    intros x y hxy,\n    exact \u27e8{y}\u1d9c,h y, mem_compl_singleton_iff.mpr (ne.symm hxy), not_not.mpr rfl\u27e9,\n  }\nend\n\nend frechet_space\n\n\nclass hausdorff_space :=\n(t2 : \u2200 (x y : X) (h : y \u2260 x), \u2203 (U V: set X) (hU : is_open U) (hV : is_open V) (hUV : U \u2229 V = \u2205), (x \u2208 U) \u2227 (y \u2208 V))\n\nnamespace hausdorff_space\n\ninstance T2_is_T1 [hausdorff_space X] : frechet_space X :=\n{ t1 := \nbegin\n  intros x y hxy,\n  obtain \u27e8U, V, hU, hV, hUV, hh\u27e9 := t2 x y hxy,\n  rw inter_comm at hUV,\n  exact \u27e8U, hU, \u27e8hh.1, (inter_is_not_is_empty_intersection hh.2 hUV)\u27e9\u27e9,\nend }\n\nend hausdorff_space\n\nclass T2_5_space : Prop :=\n(t2_5 : \u2200 (x y : X) (h : y \u2260 x), \u2203 (U V: set X), is_open U \u2227  is_open V\n  \u2227 (closure U) \u2229 (closure V) = \u2205 \u2227 x \u2208 U \u2227 y \u2208 V)\n\nnamespace T2_5_space\n\ninstance T2_5_is_T2 [T2_5_space X] : hausdorff_space X :=\n{ t2 := \nbegin\n  intros x y hxy,\n  obtain \u27e8U, V, hU, hV, hUV, hh\u27e9 := t2_5 x y hxy,\n  have hUV\u2082 : U \u2229 V = \u2205,\n  {\n    apply subset.antisymm,\n    {\n      intros t h,\n      rw \u2190 hUV,\n      exact \u27e8(closure_supset_self U) h.1, (closure_supset_self V) h.2 \u27e9,\n    },\n    {\n      exact (U \u2229 V).empty_subset,\n    },\n  },\n  exact \u27e8U, V, hU, hV, hUV\u2082, hh\u27e9,\nend } \n\nend T2_5_space\n\ndef topology_is_regular := \u2200 (x : X) (F : set X) (hF : is_closed F) (hxF: x \u2209 F),\n  \u2203 (U V : set X) (hU : is_open U) (hV : is_open V) (hUV : U \u2229 V = \u2205), (x \u2208 U) \u2227 (F \u2286 V)\n\nclass T3_space extends frechet_space X : Prop :=\n(regular : topology_is_regular X)\n\nnamespace T3_space\nopen frechet_space\nopen hausdorff_space\n\ninstance T3_is_T2 [T3_space X] : hausdorff_space X :=\n{ t2 := \nbegin\n  intros x y hxy,\n  have H := (T1_characterisation X).1 _inst_2.to_frechet_space y,\n  have x_notin_y : x \u2209 ({y} : set X), by tauto,\n  obtain \u27e8U, V, hU, hV, hUV, hh\u27e9 := regular x ({y} : set X) H x_notin_y,\n  rw singleton_subset_iff at hh,\n  exact \u27e8U, V, hU, \u27e8hV, \u27e8hUV, \u27e8hh.1, hh.2\u27e9\u27e9\u27e9\u27e9,\nend}\n\ninstance T3_is_T2_5 [T3_space X] : T2_5_space X :=\n{ t2_5 := \nbegin\n  intros x y hxy,\n  obtain \u27e8U, V, hU, hV, hUV, hh\u27e9  := t2 x y hxy,\n  have hxcV : x \u2209 closure V,\n  {\n    rw closure_eq_compl_of_interior_compl V,\n    have hxint := (interior_maximal V\u1d9c U hU (subset_compl_iff_disjoint.mpr hUV)),\n    tauto,\n  },\n  obtain \u27e8A, B, hA, hB, hAB, hh2 \u27e9 := regular x (closure V) (closure_is_closed V) hxcV,\n  have t : closure A \u2229 closure V = \u2205,\n  {\n    have hBc : is_closed B\u1d9c, by simp[hB],\n    have hcA := subset.trans (subset_closed_inclusion_closure'  hBc (subset_compl_iff_disjoint.mpr hAB)) (compl_subset_compl.2 hh2.2),\n    apply subset.antisymm,\n    {\n      rw \u2190 compl_inter_self (closure V),\n      exact (closure V).inter_subset_inter_left hcA,\n    },\n    exact (closure A \u2229 closure V).empty_subset,\n  },\n  exact \u27e8A, V, hA, hV, t, hh2.1, hh.2\u27e9,\nend }\n\nlemma T0_and_regular_is_T3 [kolmogorov_space X] (h: topology_is_regular X) :\n  T3_space X :=\n{ \n  t1 := \n  begin\n    intros x y hxy,\n    obtain \u27e8U, hU, hh\u27e9 := kolmogorov_space.t0 x y hxy,\n    cases hh,\n      exact \u27e8U, hU, hh\u27e9,\n    {\n      have hUc : is_closed U\u1d9c,\n      {\n        rw [is_closed, compl_compl],\n        exact hU,\n      },\n      have hy_not_Uc : y \u2209 U\u1d9c,\n      {\n        intro t,\n        exact (not_mem_of_mem_compl t) hh.2,\n      },\n      obtain \u27e8A, B, hA, hB, hAB, hhAB\u27e9 := h y U\u1d9c hUc hy_not_Uc,\n      exact \u27e8B, hB, hhAB.2 hh.1, inter_is_not_is_empty_intersection hhAB.1 hAB\u27e9,\n    }\n  end,\n  regular := h,\n}\n\nlemma T0_and_regular_if_only_if_T3 : (kolmogorov_space X) \u2227 (topology_is_regular X) \u2194 T3_space X :=\nbegin\n  split; intro h,\n    exact @T0_and_regular_is_T3 X _inst_1 h.1 h.2,\n    exact \u27e8@frechet_space.T1_is_T0 X _inst_1 (@hausdorff_space.T2_is_T1 X _inst_1 (@T3_space.T3_is_T2 X _inst_1 h)), h.regular\u27e9,\nend\n\nend T3_space\n\ndef is_normal (X : Type) [topological_space X] :=\n  \u2200 (F E : set X) (hF : is_closed F) (hE : is_closed E) (hEF : F \u2229 E = \u2205), \n  \u2203 (U V : set X) (hU : is_open U) (hV : is_open V) (hUV : U \u2229 V = \u2205), (F \u2286 U) \u2227 (E \u2286 V)\n\nclass T4_space extends frechet_space X : Prop :=\n(normal : is_normal X)\n\nnamespace T4_space\nopen frechet_space\n\ninstance T4_is_T3 [T4_space X] : T3_space X :=\n{ regular := \nbegin\n  intros x F hF hxF,\n  obtain \u27e8U, V, hU, hV, hUV, hh \u27e9 := normal F {x} hF ((T1_characterisation X).1 _inst_2.to_frechet_space x)\n  (inter_singleton_eq_empty.mpr hxF),\n  rw inter_comm U V at hUV,\n  exact \u27e8V, U, hV, hU, hUV, hh.2 (mem_singleton x), hh.1\u27e9,\nend  \n}\n\nend T4_space\n\nclass T5_space extends frechet_space X : Prop :=\n(t5 : \u2200 (A B : set X) (hAB : A \u2229 (closure B) = \u2205) (hBA : (closure A) \u2229 B = \u2205), \u2203 (U V : set X) (hU : is_open U) (hV : is_open V) (hUV : U \u2229 V = \u2205), A \u2286 U \u2227 B \u2286 V)\n\nnamespace T5_space\nopen frechet_space\n\ninstance T5_is_T4 [T5_space X] : T4_space X :=\n{ normal := \n  begin\n    intros F E hF hE hFE,\n    have h\u2081 : (closure F) \u2229 E = \u2205,\n      rwa \u2190 ((eq_closure_iff_is_closed F).2 hF),\n    have h\u2082 : F \u2229 (closure E) = \u2205,\n      rwa \u2190 ((eq_closure_iff_is_closed E).2 hE),\n    exact t5 F E h\u2082 h\u2081,\n  end}\n\nend T5_space", "meta": {"author": "mmasdeu", "repo": "barcelonaleanseminar", "sha": "140478080f6680ea5e3ce61e6523272e7e12219f", "save_path": "github-repos/lean/mmasdeu-barcelonaleanseminar", "path": "github-repos/lean/mmasdeu-barcelonaleanseminar/barcelonaleanseminar-140478080f6680ea5e3ce61e6523272e7e12219f/src/separacio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.701490589705529}}
{"text": "/-\nCopyright (c) 2022 Adam Topaz. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Adam Topaz\n\n! This file was ported from Lean 3 source module ring_theory.valuation.extend_to_localization\n! leanprover-community/mathlib commit 64b3576ff5bbac1387223e93988368644fcbcd7e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.RingTheory.Localization.AtPrime\nimport Mathbin.RingTheory.Valuation.Basic\n\n/-!\n\n# Extending valuations to a localization\n\nWe show that, given a valuation `v` taking values in a linearly ordered commutative *group*\nwith zero `\u0393`, and a submonoid `S` of `v.supp.prime_compl`, the valuation `v` can be naturally\nextended to the localization `S\u207b\u00b9A`.\n\n-/\n\n\nvariable {A : Type _} [CommRing A] {\u0393 : Type _} [LinearOrderedCommGroupWithZero \u0393]\n  (v : Valuation A \u0393) {S : Submonoid A} (hS : S \u2264 v.supp.primeCompl) (B : Type _) [CommRing B]\n  [Algebra A B] [IsLocalization S B]\n\n/-- We can extend a valuation `v` on a ring to a localization at a submonoid of\nthe complement of `v.supp`. -/\nnoncomputable def Valuation.extendToLocalization : Valuation B \u0393 :=\n  let f := IsLocalization.toLocalizationMap S B\n  let h : \u2200 s : S, IsUnit (v.1.toMonoidHom s) := fun s => isUnit_iff_ne_zero.2 (hS s.2)\n  { f.lift h with\n    map_zero' := by convert f.lift_eq _ 0 <;> simp\n    map_add_le_max' := fun x y =>\n      by\n      obtain \u27e8a, b, s, rfl, rfl\u27e9 : \u2203 (a b : A)(s : S), f.mk' a s = x \u2227 f.mk' b s = y :=\n        by\n        obtain \u27e8a, s, rfl\u27e9 := f.mk'_surjective x\n        obtain \u27e8b, t, rfl\u27e9 := f.mk'_surjective y\n        use a * t, b * s, s * t\n        constructor <;>\n          \u00b7 rw [f.mk'_eq_iff_eq, Submonoid.coe_mul]\n            ring_nf\n      convert_to f.lift h (f.mk' (a + b) s) \u2264 max (f.lift h _) (f.lift h _)\n      \u00b7 refine' congr_arg (f.lift h) (IsLocalization.eq_mk'_iff_mul_eq.2 _)\n        rw [add_mul, map_add]\n        iterate 2 erw [IsLocalization.mk'_spec]\n      iterate 3 rw [f.lift_mk']\n      rw [max_mul_mul_right]\n      apply mul_le_mul_right' (v.map_add a b) }\n#align valuation.extend_to_localization Valuation.extendToLocalization\n\n@[simp]\ntheorem Valuation.extendToLocalization_apply_map_apply (a : A) :\n    v.extendToLocalization hS B (algebraMap A B a) = v a :=\n  Submonoid.LocalizationMap.lift_eq _ _ a\n#align valuation.extend_to_localization_apply_map_apply Valuation.extendToLocalization_apply_map_apply\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/RingTheory/Valuation/ExtendToLocalization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7014905893217593}}
{"text": "import category_theory.basic\nimport misc.function\n\nuniverses u v w y\n\nclass comm_ring (R: Type u) extends has_add R, has_mul R, has_one R, has_zero R, has_neg R :=\n  (add_assoc : \u2200 a b c : R, a + (b + c) = (a + b) + c)\n  (add_comm : \u2200 a b : R, a + b = b + a)\n  (add_zero : \u2200 a : R, a + 0 = a)\n  (minus_inverse : \u2200 a : R, a + (-a) = 0)\n  (mul_assoc : \u2200 a b c : R, a * (b * c) = (a * b) * c)\n  (mul_comm : \u2200 a b : R, a * b = b * a)\n  (mul_one : \u2200 a : R, a * 1 = a)\n  (mul_dis : \u2200 a b c : R, a * (b + c) = a * b + a * c)\n\nnamespace comm_ring\n\nopen list\nopen function\n\ninstance comm_ring_inhabited (R : Type u) [comm_ring R] : inhabited R := \u27e8(0:R)\u27e9\n\n/-\n  Trival algebraic identities. \n-/\n\ndef unit {R: Type u} [comm_ring R] (x : R) : Prop := \u2203 a : R,  a * x = 1\n\ntheorem one_is_unit {R: Type u} [l:comm_ring R] : unit l.one := \nbegin\n  existsi l.one,\n  rw mul_one,\nend\n\ntheorem zero_unquie {R: Type u} [comm_ring R] : \u2200 a : R, (\u2200 b : R, b + a = b) \u2192 a = 0 :=\nbegin\n  intros a h,\n  exact calc a = a + 0 : by rw add_zero\n        ...    = 0 + a : by rw add_comm\n        ...    = 0      : h 0\nend\n\ntheorem one_unquie {R: Type u} [comm_ring R] : \u2200 a : R, (\u2200 b : R, b * a = b) \u2192 a = 1 :=\nbegin\n  intros a h,\n  exact calc a = a * 1 : by rw mul_one\n        ...    = 1 * a : by rw mul_comm\n        ...    = 1      : h 1\nend\n\ntheorem minus_unquie {R: Type u} [comm_ring R] : \u2200 a b : R, a + b = 0 \u2192 b = -a :=\nbegin\n  intros a b h,\n  rw \u2190 minus_inverse a at h,\n  exact calc b = b + 0          : by rw  add_zero b\n           ... = b + (a + (-a)) : by rw \u2190 minus_inverse a\n           ... = (b + a) + -a   : by rw add_assoc\n           ... = (a + b) + -a   : by rw add_comm a b\n           ... = (a + -a) + -a  : by rw \u2190 h\n           ... = (-a + a) + -a  : by simp [add_comm]\n           ... = -a + 0         : by rw [\u2190 add_assoc,minus_inverse]\n           ... = -a             : add_zero (-a)\nend\n\ntheorem mul_zero {R : Type u} [l:comm_ring R] : \u2200 a : R, a * 0 = 0 := \nbegin\n  intro a,\n  have sub : (a * 0) + (a * 0) = a * 0,\n  simp [\u2190mul_dis,add_zero],\n  exact calc a * 0 = (a * 0 + a * 0) + -(a * 0) : by simp [add_zero,minus_inverse,\u2190add_assoc]\n               ... = 0                          : by simp [sub,minus_inverse]\nend\n\ntheorem mul_minus_one {R : Type u} [comm_ring R] : \u2200 a : R, a * (-1) = -a :=\nbegin\n  intro a,\n  apply minus_unquie,\n  exact calc a + a * -1 = a * (1 + (-1)) : by simp [mul_one,mul_dis]\n                    ... = 0              : by simp [minus_inverse,mul_zero], \nend\n\ntheorem minus_dis {R : Type u} [comm_ring R] : \u2200 a b : R , -(a + b) = -a + -b :=\nbegin\n  intros a b,\n  symmetry,\n  apply minus_unquie,\n  exact calc (a + b) + (-a + -b) = a + (b + -a) + -b   : by simp [add_assoc]\n                             ... = (a + -a) + (b + -b) : by {rw add_comm b (-a), simp [add_assoc]}\n                             ... = 0                   : by rw [minus_inverse,minus_inverse,add_zero], \nend\n\ntheorem minus_zero_zero {R : Type u} [l:comm_ring R] : -l.zero = l.zero :=\nbegin\n  symmetry,\n  apply minus_unquie,\n  exact add_zero 0,\nend\n\ntheorem minus_mul {R : Type u} [comm_ring R] : \u2200 a b : R, -(a * b) = (-a) * b :=\nbegin\n  intros a b,\n  symmetry,\n  apply minus_unquie,\n  rw [mul_comm a b,mul_comm (-a) b,\u2190 mul_dis,minus_inverse,mul_zero],\nend\n\nlemma mul_assoc\u2084 {R : Type u} [comm_ring R]: \u2200 r\u2081 r\u2082 r\u2083 r\u2084 : R ,\n   r\u2081 * r\u2082 * (r\u2083 * r\u2084) = r\u2081 * (r\u2082 * r\u2083) * r\u2084 :=\nbegin\n  intros r\u2081 r\u2082 r\u2083 r\u2084,\n  simp[mul_assoc],\nend\n\nlemma add_assoc\u2084 {R : Type u} [comm_ring R]: \u2200 r\u2081 r\u2082 r\u2083 r\u2084 : R ,\n   r\u2081 + r\u2082 + (r\u2083 + r\u2084) = r\u2081 + (r\u2082 + r\u2083) + r\u2084 :=\nbegin\n  intros r\u2081 r\u2082 r\u2083 r\u2084,\n  simp[add_assoc],\nend\n\ntheorem minus_minus {R : Type u} [comm_ring R] : \u2200 x : R , -(-x) = x :=\nbegin\n  intro x,\n  symmetry,\n  apply minus_unquie,\n  rw add_comm,\n  rw minus_inverse,\nend\n\ntheorem zero_diff_equal {R : Type u} [comm_ring R] : \u2200 {x y : R}, x + (-y) = 0 \u2192 x = y :=\nbegin\n  intros x y h,\n  exact calc x = x + 0        : by rw add_zero\n           ... = x + (y + -y) : by rw minus_inverse\n           ... = x + (-y + y) : by rw add_comm y (-y) \n           ... = (x + -y) + y : by rw add_assoc\n           ... = 0 + y        : by rw \u2190h \n           ... = y            : by simp [add_comm,add_zero],\nend\n\ndef pow {R : Type u} [comm_ring R] : R \u2192 \u2115 \u2192 R \n  | r nat.zero     := 1\n  | r (nat.succ n) := r * (pow r n)\n\ninstance ring_has_pow {R: Type u} [comm_ring R] : has_pow R \u2115 := \u27e8pow\u27e9\n\nlemma power_of_one {R : Type u} [comm_ring R] : \u2200 a : R, a^1 = a :=\nbegin\n  intro a,\n  have trv : a^1 = a * 1 := rfl,\n  rw [trv,mul_one],\nend\n\nlemma power_of_zero {R : Type u} [comm_ring R] : \u2200 a : R, a^0 = 1 :=\nbegin\n  intro a,\n  refl,\nend\n\nlemma power_of_succ {R : Type u} [comm_ring R] (a : R) : \u2200 n : \u2115, a^n.succ = a^n * a :=\nbegin\n  intro n,\n  rw mul_comm,\n  refl,\nend\n\nlemma power_of_add {R : Type u} [comm_ring R] (a : R) : \u2200 n m : \u2115, a^(n + m) = (a^n) * (a^m) :=\nbegin\n  intros n m,\n  induction m with m hm,\n  rw [nat.add_zero n,power_of_zero,mul_one],\n  rw [nat.add_succ,power_of_succ,power_of_succ,hm],\n  rw mul_assoc,\nend\n\nlemma power_of_power {R : Type u} [comm_ring R] (a : R) : \u2200 n m : \u2115, (a^n)^m = a^(n*m) :=\nbegin\n  intros n m,\n  induction m with m hm,\n  rw [nat.mul_zero,power_of_zero,power_of_zero],\n  rw [power_of_succ,nat.mul_succ,hm,power_of_add],\nend\n\ndef nat_to_ring (R :Type u) [comm_ring R] : \u2115 \u2192 R \n  | 0            := 0\n  | (nat.succ n) := 1 + nat_to_ring n \n\n\ntheorem minus_inj {R : Type u} [comm_ring R] : \u2200 {x y : R}, -x = -y \u2192 x = y :=\nbegin\n  intros x y h,\n  exact calc x = x + 0 : by rw add_zero \n           ... = x + (y + -y) : by rw \u2190 minus_inverse \n           ... = x + (-y + y) : by rw add_comm y \n           ... = (x + -x) + y : by rw [\u2190 h, add_assoc]\n           ... = 0 + y        : by rw [minus_inverse]\n           ... = y            : by rw [add_comm,add_zero],\nend\n\ntheorem add_midpoint {R : Type u} [comm_ring R] : \u2200 (y x z : R), x + -z = (x + -y) + (y + -z) :=\nbegin\n  intros y x z,\n  rw [add_assoc\u2084,add_comm (-y),minus_inverse,add_zero],\nend\n\ndef sum_list {R : Type u} [comm_ring R] : list R \u2192 R := foldr (\u03bb a b : R, a + b) 0\n\ndef scale_list {R : Type u} [comm_ring R] : R \u2192 list R \u2192 list R := \u03bb a, map (\u03bb b: R, a * b)\n\ndef add_lists {R : Type u} [comm_ring R] : list R \u2192 list R \u2192 list R \n  | (a :: as) (b :: bs) := (a + b) :: (add_lists as bs)\n  | [] bs               := bs \n  | as []               := as \n\nnotation `\u03a3\u2080` : 110 := sum_list\n\ntheorem mul_dis_finite_sum {R : Type u} [comm_ring R] : \u2200 (a : R) (l : list R), a * (\u03a3\u2080 l) = \u03a3\u2080 (scale_list a l) :=\nbegin\n  intros a l,\n  induction l with b l hl,\n  have trv\u2081 : (\u03a3\u2080 (@nil R)) = 0 := rfl,\n  have trv\u2082 : scale_list a nil = nil := rfl,\n  rw [trv\u2082,trv\u2081,mul_zero],\n  have trv\u2081 : \u03a3\u2080 (b::l) = b + \u03a3\u2080 l := rfl,\n  rw [trv\u2081,mul_dis,hl],\n  refl, \nend\n\ninductive linear_combination {R : Type u} [comm_ring R] (S\u2081 : set R) (S\u2082 : set R): R \u2192 Prop \n  | empty_sum : linear_combination 0 \n  | add_term (x : R) : \u2200 s\u2081 s\u2082 l : R, s\u2081 \u2208 S\u2081 \u2192 s\u2082 \u2208 S\u2082 \u2192 linear_combination l \u2192 x = s\u2081 * s\u2082 + l \u2192 linear_combination x\n\nstructure ring_hom (R\u2081: Type u) (R\u2082 : Type v) [comm_ring R\u2081] [comm_ring R\u2082] : Type max u v :=\n  (map : R\u2081 \u2192 R\u2082)\n  (prevs_one : map 1 = 1)\n  (prevs_mul : \u2200 a b : R\u2081, map (a * b) = map a * map b)\n  (prevs_add : \u2200 a b : R\u2081, map (a + b) = map a + map b)\n\ninfixr `\u2192\u1d63`:25 := ring_hom\n\ninstance ring_hom_to_function {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] : has_coe_to_fun (R\u2081 \u2192\u1d63 R\u2082) (\u03bb _, R\u2081 \u2192 R\u2082) := \u27e8\u03bb \u03c6, \u03c6.map\u27e9 \n\ndef id\u1d63 {R : Type u} [comm_ring R] : R \u2192\u1d63 R := \n  {\n    map := id,\n    prevs_one := rfl,\n    prevs_mul := \u03bb _ _, rfl,\n    prevs_add := \u03bb _ _, rfl,\n  }\n\nlemma compose_prevs_mul {R\u2081 : Type u} {R\u2082 : Type v} {R\u2083 : Type w}[comm_ring R\u2081] [comm_ring R\u2082] [comm_ring R\u2083] (\u03c6\u2081 : R\u2082 \u2192\u1d63 R\u2083) (\u03c6\u2082 : R\u2081 \u2192\u1d63 R\u2082)\n  : \u2200 a b : R\u2081, (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) (a * b) = (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) a * (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) b :=\nbegin\n  intros a b,\n  exact calc (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) (a * b) = \u03c6\u2081.map (\u03c6\u2082.map (a * b))               : rfl\n                             ... = \u03c6\u2081.map (\u03c6\u2082.map a) * \u03c6\u2081.map (\u03c6\u2082.map b) : by simp [\u03c6\u2082.prevs_mul ,\u03c6\u2081.prevs_mul]\n                             ... = (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) a * (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) b         : rfl\nend \n\nlemma compose_prevs_add {R\u2081 : Type u} {R\u2082 : Type v} {R\u2083 : Type w}[comm_ring R\u2081] [comm_ring R\u2082] [comm_ring R\u2083] (\u03c6\u2081 : R\u2082 \u2192\u1d63 R\u2083) (\u03c6\u2082 : R\u2081 \u2192\u1d63 R\u2082)\n  : \u2200 a b : R\u2081, (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) (a + b) = (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) a + (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) b :=\nbegin\n  intros a b,\n  exact calc (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) (a + b) = \u03c6\u2081.map (\u03c6\u2082.map (a + b))               : rfl\n                             ... = \u03c6\u2081.map (\u03c6\u2082.map a) + \u03c6\u2081.map (\u03c6\u2082.map b) : by simp [\u03c6\u2082.prevs_add ,\u03c6\u2081.prevs_add]\n                             ... = (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) a + (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) b         : rfl\nend\n\nlemma compose_prevs_one {R\u2081 : Type u} {R\u2082 : Type v} {R\u2083 : Type w}[comm_ring R\u2081] [comm_ring R\u2082] [comm_ring R\u2083] (\u03c6\u2081 : R\u2082 \u2192\u1d63 R\u2083) (\u03c6\u2082 : R\u2081 \u2192\u1d63 R\u2082)\n  : (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) (1) = 1 :=\nbegin\n  exact calc (\u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082) (1) = \u03c6\u2081.map (\u03c6\u2082.map (1)) : rfl\n                         ... = 1                   : by simp [\u03c6\u2082.prevs_one ,\u03c6\u2081.prevs_one]\nend\n\ndef ring_hom_comp {R\u2081 : Type u} {R\u2082 : Type v} {R\u2083 : Type w}[comm_ring R\u2081] [comm_ring R\u2082] [comm_ring R\u2083] (\u03c6\u2081 : R\u2082 \u2192\u1d63 R\u2083) (\u03c6\u2082 : R\u2081 \u2192\u1d63 R\u2082)\n  : R\u2081 \u2192\u1d63 R\u2083 :=\n  {\n    map := \u21d1\u03c6\u2081 \u2218 \u21d1\u03c6\u2082,\n    prevs_one := compose_prevs_one \u03c6\u2081 \u03c6\u2082,\n    prevs_add := compose_prevs_add \u03c6\u2081 \u03c6\u2082,\n    prevs_mul := compose_prevs_mul \u03c6\u2081 \u03c6\u2082,\n  }\n\ninfixr ` \u2218\u1d63 ` : 25 := ring_hom_comp\n\ntheorem ring_hom_preserves_zero {R\u2081 : Type u} {R\u2082 : Type v} [l\u2081 :comm_ring R\u2081] [l\u2082:comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082) : \u03c6 0 = 0 :=\nbegin\n  have sub : \u03c6 0 = \u03c6 0 + \u03c6 0,\n    exact calc \u03c6 0 = \u03c6 (0 + 0) : by rw add_zero\n               ... = \u03c6 0 + \u03c6 0 : \u03c6.prevs_add 0 0,\n  symmetry,\n  exact calc 0 = \u03c6 0 + - \u03c6 0        : by rw \u2190 minus_inverse\n           ... = (\u03c6 0 + \u03c6 0) + -\u03c6 0 : by rw \u2190 sub\n           ... = \u03c6 0                : by rw [\u2190 add_assoc, minus_inverse, add_zero],\nend\n\nlemma minus_commutes_with_hom {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082) : \u2200 x : R\u2081, \u03c6 (-x) = - \u03c6 x :=\nbegin\n  intro x,\n  apply minus_unquie,\n  have trv : \u03c6.map = \u21d1\u03c6 := rfl,\n  rw [\u2190trv, \u2190 \u03c6.prevs_add, minus_inverse,trv,ring_hom_preserves_zero],\nend\n\ntheorem ring_hom_prevs_pow {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082) (n :\u2115)\n  : \u2200 x : R\u2081, \u03c6 (x^n) = (\u03c6 x)^n :=\nbegin\n  intro x,\n  induction n with n hn,\n  simp [power_of_zero],\n  exact \u03c6.prevs_one,\n  rw power_of_succ,\n  have trv: \u21d1\u03c6 = \u03c6.map := rfl,\n  simp [trv],\n  rw \u03c6.prevs_mul,\n  simp [\u2190trv],\n  rw hn,\n  rw \u2190 power_of_succ,\nend\n\ntheorem ring_hom_equality_hack {R\u2081 : Type u} [comm_ring R\u2081] {R\u2082 : Type v} [comm_ring R\u2082] {\u03c6\u2081 \u03c6\u2082: R\u2081 \u2192\u1d63 R\u2082} \n: (\u21d1\u03c6\u2081) = (\u03c6\u2082.map) \u2192 \u03c6\u2081 = \u03c6\u2082 :=\nbegin\n  intro h,\n  cases \u03c6\u2081,\n  cases \u03c6\u2082,\n  rw ring_hom.mk.inj_eq,\n  exact h,\nend\n\ntheorem ring_hom_equality {R\u2081 : Type u} [comm_ring R\u2081] {R\u2082 : Type v} [comm_ring R\u2082] {\u03c6\u2081 \u03c6\u2082: R\u2081 \u2192\u1d63 R\u2082} \n: (\u03c6\u2081.map) = (\u03c6\u2082.map) \u2192 \u03c6\u2081 = \u03c6\u2082 :=\nbegin\n  intro h,\n  cases \u03c6\u2081,\n  cases \u03c6\u2082,\n  rw ring_hom.mk.inj_eq,\n  exact h,\nend\n\ndef ring_isomorphism {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082) : Prop := \u2203 \u03c8 : R\u2082 \u2192\u1d63 R\u2081, (\u03c8 \u2218\u1d63 \u03c6) = id\u1d63 \u2227 (\u03c6 \u2218\u1d63 \u03c8) = id\u1d63 \n\ntheorem ring_comp_assoc {R\u2081 : Type u} {R\u2082 : Type v} {R\u2083 : Type w} {R\u2084 : Type y} [comm_ring R\u2081] \n  [comm_ring R\u2082] [comm_ring R\u2083] [comm_ring R\u2084] (\u03c6\u2081 : R\u2083 \u2192\u1d63 R\u2084) (\u03c6\u2082 : R\u2082 \u2192\u1d63 R\u2083) (\u03c6\u2083 : R\u2081 \u2192\u1d63 R\u2082) \n  : (\u03c6\u2081 \u2218\u1d63 (\u03c6\u2082 \u2218\u1d63 \u03c6\u2083)) = ((\u03c6\u2081 \u2218\u1d63 \u03c6\u2082) \u2218\u1d63 \u03c6\u2083) :=\nbegin\n  apply ring_hom_equality,\n  refl,\nend\n\ntheorem id_hom_left_comp {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082)\n  : (id\u1d63 \u2218\u1d63 \u03c6) = \u03c6 :=\nbegin\n  apply ring_hom_equality,\n  refl,\nend\n\ntheorem id_hom_right_comp {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] (\u03c6 : R\u2081 \u2192\u1d63 R\u2082)\n  : (\u03c6 \u2218\u1d63 id\u1d63) = \u03c6 :=\nbegin\n  apply ring_hom_equality,\n  refl,\nend\n\n/-\n  showing that a bijective ring hom is an isomorphism.\n-/\n\ntheorem inverse_prevs_one {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] {\u03c6 : R\u2081 \u2192\u1d63 R\u2082} {g : R\u2082 \u2192 R\u2081} \n  : inverse g \u21d1\u03c6 \u2192 g 1 = 1 := \nbegin\n  intro h,\n  cases h with h\u2081 h\u2082,\n  rw \u2190\u03c6.prevs_one,\n  have trv : \u03c6.map = \u21d1\u03c6 := rfl,\n  rw [trv,\u2190 comp_app g (\u21d1\u03c6), h\u2082],\n  refl,\nend\n\ntheorem inverse_prevs_mul {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] {\u03c6 : R\u2081 \u2192\u1d63 R\u2082} {g : R\u2082 \u2192 R\u2081} \n  : inverse g \u21d1\u03c6 \u2192 \u2200 a b : R\u2082, g (a * b) = (g a) * (g b) := \nbegin\n  intro h,\n  have \u03c6inj : injective \u21d1\u03c6 := inverse.injective h,\n  cases h with h\u2081 h\u2082,\n  intros a b,\n  apply \u03c6inj,\n  have trv : \u03c6.map = \u21d1\u03c6 := rfl,\n  rw \u2190 trv,\n  rw \u03c6.prevs_mul,\n  rw trv,\n  rw \u2190 comp_app (\u21d1\u03c6) g,\n  rw \u2190 comp_app (\u21d1\u03c6) g,\n  rw \u2190 comp_app (\u21d1\u03c6) g,\n  simp [h\u2081],\nend\n\ntheorem inverse_prevs_add {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] {\u03c6 : R\u2081 \u2192\u1d63 R\u2082} {g : R\u2082 \u2192 R\u2081} \n  : inverse g \u21d1\u03c6 \u2192 \u2200 a b : R\u2082, g (a + b) = (g a) + (g b) := \nbegin\n  intro h,\n  have \u03c6inj : injective \u21d1\u03c6 := inverse.injective h,\n  cases h with h\u2081 h\u2082,\n  intros a b,\n  apply \u03c6inj,\n  have trv : \u03c6.map = \u21d1\u03c6 := rfl,\n  rw \u2190 trv,\n  rw \u03c6.prevs_add,\n  rw trv,\n  rw \u2190 comp_app (\u21d1\u03c6) g,\n  rw \u2190 comp_app (\u21d1\u03c6) g,\n  rw \u2190 comp_app (\u21d1\u03c6) g,\n  simp [h\u2081],\nend\n\ntheorem bijective_ring_hom_ring_iso {R\u2081 : Type u} {R\u2082 : Type v} [comm_ring R\u2081] [comm_ring R\u2082] {\u03c6 : R\u2081 \u2192\u1d63 R\u2082}\n  : bijective \u21d1\u03c6 \u2192 ring_isomorphism \u03c6 :=\nbegin\n  intro h\u03c6b,\n  cases bijection_has_inverse h\u03c6b with g hg,\n  let ghom : R\u2082 \u2192\u1d63 R\u2081,\n    split,\n    exact inverse_prevs_one hg,\n    exact inverse_prevs_mul hg,\n    exact inverse_prevs_add hg,\n  have trv\u2081 : \u21d1ghom = g := rfl,\n  cases hg with hg\u2081 hg\u2082,\n  existsi ghom,\n  split,\n  apply ring_hom_equality_hack,\n  have trv\u2082 : \u21d1(ghom \u2218\u1d63 \u03c6) = \u21d1ghom \u2218 \u21d1\u03c6 := rfl,\n  rw [trv\u2082,trv\u2081,hg\u2082],\n  refl,\n  apply ring_hom_equality_hack,\n  have trv\u2082 : \u21d1(\u03c6 \u2218\u1d63 ghom) = \u03c6 \u2218 \u21d1ghom := rfl,\n  rw [trv\u2082,trv\u2081,hg\u2081],\n  refl,\nend\n\nend comm_ring", "meta": {"author": "CameronTorrance", "repo": "Schemes", "sha": "f407ce80b8407101231170680b03b55984c42496", "save_path": "github-repos/lean/CameronTorrance-Schemes", "path": "github-repos/lean/CameronTorrance-Schemes/Schemes-f407ce80b8407101231170680b03b55984c42496/src/algebra/comm_rings/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.7014905805314718}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n-/\nimport topology.metric_space.metrizable\n\n/-!\n# Metrizable uniform spaces\n\nIn this file we prove that a uniform space with countably generated uniformity filter is\npseudometrizable: there exists a `pseudo_metric_space` structure that generates the same uniformity.\nThe proof follows [Sergey Melikhov, Metrizable uniform spaces][melikhov2011].\n## Main definitions\n\n* `pseudo_metric_space.of_prenndist`: given a function `d : X \u2192 X \u2192 \u211d\u22650` such that `d x x = 0` and\n  `d x y = d y x` for all `x y : X`, constructs the maximal pseudo metric space structure such that\n  `nndist x y \u2264 d x y` for all `x y : X`.\n\n* `uniform_space.pseudo_metric_space`: given a uniform space `X` with countably generated `\ud835\udce4 X`,\n  constructs a `pseudo_metric_space X` instance that is compatible with the uniform space structure.\n\n* `uniform_space.metric_space`: given a T\u2080 uniform space `X` with countably generated `\ud835\udce4 X`,\n  constructs a `metric_space X` instance that is compatible with the uniform space structure.\n\n## Main statements\n\n* `uniform_space.metrizable_uniformity`: if `X` is a uniform space with countably generated `\ud835\udce4 X`,\n  then there exists a `pseudo_metric_space` structure that is compatible with this `uniform_space`\n  structure. Use `uniform_space.pseudo_metric_space` or `uniform_space.metric_space` instead.\n\n* `uniform_space.pseudo_metrizable_space`: a uniform space with countably generated `\ud835\udce4 X` is pseudo\n  metrizable.\n\n* `uniform_space.metrizable_space`: a T\u2080 uniform space with countably generated `\ud835\udce4 X` is\n  metrizable. This is not an instance to avoid loops.\n\n## Tags\n\nmetrizable space, uniform space\n-/\n\nopen set function metric list filter\nopen_locale nnreal filter uniformity\n\nvariables {X : Type*}\n\nnamespace pseudo_metric_space\n\n/-- The maximal pseudo metric space structure on `X` such that `dist x y \u2264 d x y` for all `x y`,\nwhere `d : X \u2192 X \u2192 \u211d\u22650` is a function such that `d x x = 0` and `d x y = d y x` for all `x`, `y`. -/\nnoncomputable def of_prenndist (d : X \u2192 X \u2192 \u211d\u22650) (dist_self : \u2200 x, d x x = 0)\n  (dist_comm : \u2200 x y, d x y = d y x) :\n  pseudo_metric_space X :=\n{ dist := \u03bb x y, \u2191(\u2a05 l : list X, ((x :: l).zip_with d (l ++ [y])).sum : \u211d\u22650),\n  dist_self := \u03bb x, (nnreal.coe_eq_zero _).2 $ nonpos_iff_eq_zero.1 $\n    (cinfi_le (order_bot.bdd_below _) []).trans_eq $ by simp [dist_self],\n  dist_comm := \u03bb x y, nnreal.coe_eq.2 $\n    begin\n      refine reverse_surjective.infi_congr _ (\u03bb l, _),\n      rw [\u2190 sum_reverse, zip_with_distrib_reverse, reverse_append, reverse_reverse,\n        reverse_singleton, singleton_append, reverse_cons, reverse_reverse,\n        zip_with_comm_of_comm _ dist_comm],\n      simp only [length, length_append]\n    end,\n  dist_triangle := \u03bb x y z,\n    begin\n      rw [\u2190 nnreal.coe_add, nnreal.coe_le_coe],\n      refine nnreal.le_infi_add_infi (\u03bb lxy lyz, _),\n      calc (\u2a05 l, (zip_with d (x :: l) (l ++ [z])).sum) \u2264\n        (zip_with d (x :: (lxy ++ y :: lyz)) ((lxy ++ y :: lyz) ++ [z])).sum :\n        cinfi_le (order_bot.bdd_below _) (lxy ++ y :: lyz)\n      ... = (zip_with d (x :: lxy) (lxy ++ [y])).sum + (zip_with d (y :: lyz) (lyz ++ [z])).sum : _,\n      rw [\u2190 sum_append, \u2190 zip_with_append, cons_append, \u2190 @singleton_append _ y, append_assoc,\n        append_assoc, append_assoc],\n      rw [length_cons, length_append, length_singleton]\n    end }\n\nlemma dist_of_prenndist (d : X \u2192 X \u2192 \u211d\u22650) (dist_self : \u2200 x, d x x = 0)\n  (dist_comm : \u2200 x y, d x y = d y x) (x y : X) :\n  @dist X (@pseudo_metric_space.to_has_dist X\n    (pseudo_metric_space.of_prenndist d dist_self dist_comm)) x y =\n    \u2191(\u2a05 l : list X, ((x :: l).zip_with d (l ++ [y])).sum : \u211d\u22650) := rfl\n\nlemma dist_of_prenndist_le (d : X \u2192 X \u2192 \u211d\u22650) (dist_self : \u2200 x, d x x = 0)\n  (dist_comm : \u2200 x y, d x y = d y x) (x y : X) :\n  @dist X (@pseudo_metric_space.to_has_dist X\n    (pseudo_metric_space.of_prenndist d dist_self dist_comm)) x y \u2264 d x y :=\nnnreal.coe_le_coe.2 $ (cinfi_le (order_bot.bdd_below _) []).trans_eq $ by simp\n\n/-- Consider a function `d : X \u2192 X \u2192 \u211d\u22650` such that `d x x = 0` and `d x y = d y x` for all `x`,\n`y`. Let `dist` be the largest pseudometric distance such that `dist x y \u2264 d x y`, see\n`pseudo_metric_space.of_prenndist`. Suppose that `d` satisfies the following triangle-like\ninequality: `d x\u2081 x\u2084 \u2264 2 * max (d x\u2081 x\u2082, d x\u2082 x\u2083, d x\u2083 x\u2084)`. Then `d x y \u2264 2 * dist x y` for all\n`x`, `y`. -/\nlemma le_two_mul_dist_of_prenndist (d : X \u2192 X \u2192 \u211d\u22650) (dist_self : \u2200 x, d x x = 0)\n  (dist_comm : \u2200 x y, d x y = d y x)\n  (hd : \u2200 x\u2081 x\u2082 x\u2083 x\u2084, d x\u2081 x\u2084 \u2264 2 * max (d x\u2081 x\u2082) (max (d x\u2082 x\u2083) (d x\u2083 x\u2084))) (x y : X) :\n  \u2191(d x y) \u2264 2 * @dist X (@pseudo_metric_space.to_has_dist X\n    (pseudo_metric_space.of_prenndist d dist_self dist_comm)) x y :=\nbegin\n  /- We need to show that `d x y` is at most twice the sum `L` of `d x\u1d62 x\u1d62\u208a\u2081` over a path\n  `x\u2080=x, ..., x\u2099=y`. We prove it by induction on the length `n` of the sequence. Find an edge that\n  splits the path into two parts of almost equal length: both `d x\u2080 x\u2081 + ... + d x\u2096\u208b\u2081 x\u2096` and\n  `d x\u2096\u208a\u2081 x\u2096\u208a\u2082 + ... + d x\u2099\u208b\u2081 x\u2099` are less than or equal to `L / 2`.\n  Then `d x\u2080 x\u2096 \u2264 L`, `d x\u2096 x\u2096\u208a\u2081 \u2264 L`, and `d x\u2096\u208a\u2081 x\u2099 \u2264 L`, thus `d x\u2080 x\u2099 \u2264 2 * L`. -/\n  rw [dist_of_prenndist, \u2190 nnreal.coe_two, \u2190 nnreal.coe_mul, nnreal.mul_infi, nnreal.coe_le_coe],\n  refine le_cinfi (\u03bb l, _),\n  have hd\u2080_trans : transitive (\u03bb x y, d x y = 0),\n  { intros a b c hab hbc,\n    rw \u2190 nonpos_iff_eq_zero,\n    simpa only [*, max_eq_right, mul_zero] using hd a b c c },\n  haveI : is_trans X (\u03bb x y, d x y = 0) := \u27e8hd\u2080_trans\u27e9,\n  induction hn : length l using nat.strong_induction_on with n ihn generalizing x y l,\n  simp only at ihn, subst n,\n  set L := zip_with d (x :: l) (l ++ [y]),\n  have hL_len : length L = length l + 1, by simp,\n  cases eq_or_ne (d x y) 0 with hd\u2080 hd\u2080, { simp only [hd\u2080, zero_le] },\n  rsuffices \u27e8z, z', hxz, hzz', hz'y\u27e9 : \u2203 z z' : X, d x z \u2264 L.sum \u2227 d z z' \u2264 L.sum \u2227 d z' y \u2264 L.sum,\n  { exact (hd x z z' y).trans (mul_le_mul_left' (max_le hxz (max_le hzz' hz'y)) _) },\n  set s : set \u2115 := {m : \u2115 | 2 * (take m L).sum \u2264 L.sum},\n  have hs\u2080 : 0 \u2208 s, by simp [s],\n  have hsne : s.nonempty, from \u27e80, hs\u2080\u27e9,\n  obtain \u27e8M, hMl, hMs\u27e9 : \u2203 M \u2264 length l, is_greatest s M,\n  { have hs_ub : length l \u2208 upper_bounds s,\n    { intros m hm,\n      rw [\u2190 not_lt, nat.lt_iff_add_one_le, \u2190 hL_len],\n      intro hLm,\n      rw [mem_set_of_eq, take_all_of_le hLm, two_mul, add_le_iff_nonpos_left, nonpos_iff_eq_zero,\n        sum_eq_zero_iff, \u2190 all\u2082_iff_forall, all\u2082_zip_with, \u2190 chain_append_singleton_iff_forall\u2082]\n        at hm; [skip, by simp],\n      exact hd\u2080 (hm.rel (mem_append.2 $ or.inr $ mem_singleton_self _)) },\n    have hs_bdd : bdd_above s, from \u27e8length l, hs_ub\u27e9,\n    exact \u27e8Sup s, cSup_le hsne hs_ub, \u27e8nat.Sup_mem hsne hs_bdd, \u03bb k, le_cSup hs_bdd\u27e9\u27e9 },\n  have hM_lt : M < length L, by rwa [hL_len, nat.lt_succ_iff],\n  have hM_ltx : M < length (x :: l), from lt_length_left_of_zip_with hM_lt,\n  have hM_lty : M < length (l ++ [y]), from lt_length_right_of_zip_with hM_lt,\n  refine \u27e8(x :: l).nth_le M hM_ltx, (l ++ [y]).nth_le M hM_lty, _, _, _\u27e9,\n  { cases M, { simp [dist_self] },\n    rw nat.succ_le_iff at hMl,\n    have hMl' : length (take M l) = M, from (length_take _ _).trans (min_eq_left hMl.le),\n    simp only [nth_le],\n    refine (ihn _ hMl _ _ _ hMl').trans _,\n    convert hMs.1.out,\n    rw [zip_with_distrib_take, take, take_succ, nth_append hMl, nth_le_nth hMl,\n      \u2190 option.coe_def, option.to_list_some, take_append_of_le_length hMl.le],\n    refl },\n  { refine single_le_sum (\u03bb x hx, zero_le x) _ (mem_iff_nth_le.2 \u27e8M, hM_lt, _\u27e9),\n    apply nth_le_zip_with },\n  { rcases hMl.eq_or_lt with rfl|hMl,\n    { simp only [nth_le_append_right le_rfl, sub_self, nth_le_singleton, dist_self, zero_le] },\n    rw [nth_le_append _ hMl],\n    have hlen : length (drop (M + 1) l) = length l - (M + 1), from length_drop _ _,\n    have hlen_lt : length l - (M + 1) < length l, from nat.sub_lt_of_pos_le _ _ M.succ_pos hMl,\n    refine (ihn _ hlen_lt _ y _ hlen).trans _,\n    rw [cons_nth_le_drop_succ],\n    have hMs' : L.sum \u2264 2 * (L.take (M + 1)).sum,\n      from not_lt.1 (\u03bb h, (hMs.2 h.le).not_lt M.lt_succ_self),\n    rw [\u2190 sum_take_add_sum_drop L (M + 1), two_mul, add_le_add_iff_left,\n      \u2190 add_le_add_iff_right, sum_take_add_sum_drop, \u2190 two_mul] at hMs',\n    convert hMs',\n    rwa [zip_with_distrib_drop, drop, drop_append_of_le_length] }\nend\n\nend pseudo_metric_space\n\n/-- If `X` is a uniform space with countably generated uniformity filter, there exists a\n`pseudo_metric_space` structure compatible with the `uniform_space` structure. Use\n`uniform_space.pseudo_metric_space` or `uniform_space.metric_space` instead. -/\nprotected lemma uniform_space.metrizable_uniformity (X : Type*) [uniform_space X]\n  [is_countably_generated (\ud835\udce4 X)] :\n  \u2203 I : pseudo_metric_space X, I.to_uniform_space = \u2039_\u203a :=\nbegin\n  /- Choose a fast decreasing antitone basis `U : \u2115 \u2192 set (X \u00d7 X)` of the uniformity filter `\ud835\udce4 X`.\n  Define `d x y : \u211d\u22650` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates\n  `x` and `y`: `(x, y) \u2209 U n`, or `0` if `x` is not separated from `y`. This function satisfies the\n  assumptions of `pseudo_metric_space.of_prenndist` and\n  `pseudo_metric_space.le_two_mul_dist_of_prenndist`, hence the distance given by the former pseudo\n  metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by\n  `d` and `dist` are equal. Since the former uniformity is equal to `\ud835\udce4 X`, the latter is equal to\n  `\ud835\udce4 X` as well. -/\n  classical,\n  obtain \u27e8U, hU_symm, hU_comp, hB\u27e9 : \u2203 U : \u2115 \u2192 set (X \u00d7 X), (\u2200 n, symmetric_rel (U n)) \u2227\n    (\u2200 \u2983m n\u2984, m < n \u2192 U n \u25cb (U n \u25cb U n) \u2286 U m) \u2227 (\ud835\udce4 X).has_antitone_basis U,\n  { rcases uniform_space.has_seq_basis X with \u27e8V, hB, hV_symm\u27e9,\n    rcases hB.subbasis_with_rel (\u03bb m, hB.tendsto_small_sets.eventually\n      (eventually_uniformity_iterate_comp_subset (hB.mem m) 2)) with \u27e8\u03c6, h\u03c6_mono, h\u03c6_comp, h\u03c6B\u27e9,\n    exact \u27e8V \u2218 \u03c6, \u03bb n, hV_symm _, h\u03c6_comp, h\u03c6B\u27e9 },\n  letI := uniform_space.separation_setoid X,\n  set d : X \u2192 X \u2192 \u211d\u22650 := \u03bb x y, if h : \u2203 n, (x, y) \u2209 U n then (1 / 2) ^ nat.find h else 0,\n  have hd\u2080 : \u2200 {x y}, d x y = 0 \u2194 x \u2248 y,\n  { intros x y, dsimp only [d],\n    refine iff.trans _ hB.to_has_basis.mem_separation_rel.symm,\n    simp only [true_implies_iff],\n    split_ifs with h,\n    { rw [\u2190 not_forall] at h, simp [h, pow_eq_zero_iff'] },\n    { simpa only [not_exists, not_not, eq_self_iff_true, true_iff] using h } },\n  have hd_symm : \u2200 x y, d x y = d y x,\n  { intros x y, dsimp only [d],\n    simp only [@symmetric_rel.mk_mem_comm _ _ (hU_symm _) x y] },\n  have hr : (1 / 2 : \u211d\u22650) \u2208 Ioo (0 : \u211d\u22650) 1,\n    from \u27e8half_pos one_pos, nnreal.half_lt_self one_ne_zero\u27e9,\n  letI I := pseudo_metric_space.of_prenndist d (\u03bb x, hd\u2080.2 (setoid.refl _)) hd_symm,\n  have hdist_le : \u2200 x y, dist x y \u2264 d x y,\n    from pseudo_metric_space.dist_of_prenndist_le _ _ _,\n  have hle_d : \u2200 {x y : X} {n : \u2115}, (1 / 2) ^ n \u2264 d x y \u2194 (x, y) \u2209 U n,\n  { intros x y n,\n    simp only [d], split_ifs with h,\n    { rw [(strict_anti_pow hr.1 hr.2).le_iff_le, nat.find_le_iff],\n      exact \u27e8\u03bb \u27e8m, hmn, hm\u27e9 hn, hm (hB.antitone hmn hn), \u03bb h, \u27e8n, le_rfl, h\u27e9\u27e9 },\n    { push_neg at h,\n      simp only [h, not_true, (pow_pos hr.1 _).not_le] } },\n  have hd_le : \u2200 x y, \u2191(d x y) \u2264 2 * dist x y,\n  { refine pseudo_metric_space.le_two_mul_dist_of_prenndist _ _ _ (\u03bb x\u2081 x\u2082 x\u2083 x\u2084, _),\n    by_cases H : \u2203 n, (x\u2081, x\u2084) \u2209 U n,\n    { refine (dif_pos H).trans_le _,\n      rw [\u2190 nnreal.div_le_iff' two_ne_zero, \u2190 mul_one_div (_ ^ _), \u2190 pow_succ'],\n      simp only [le_max_iff, hle_d, \u2190 not_and_distrib],\n      rintro \u27e8h\u2081\u2082, h\u2082\u2083, h\u2083\u2084\u27e9,\n      refine nat.find_spec H (hU_comp (lt_add_one $ nat.find H) _),\n      exact \u27e8x\u2082, h\u2081\u2082, x\u2083, h\u2082\u2083, h\u2083\u2084\u27e9 },\n    { exact (dif_neg H).trans_le (zero_le _) } },\n  refine \u27e8I, uniform_space_eq $ (uniformity_basis_dist_pow hr.1 hr.2).ext hB.to_has_basis _ _\u27e9,\n  { refine \u03bb n hn, \u27e8n, hn, \u03bb x hx, (hdist_le _ _).trans_lt _\u27e9,\n    rwa [\u2190 nnreal.coe_pow, nnreal.coe_lt_coe, \u2190 not_le, hle_d, not_not, prod.mk.eta] },\n  { refine \u03bb n hn, \u27e8n + 1, trivial, \u03bb x hx, _\u27e9,\n    rw [mem_set_of_eq] at hx,\n    contrapose! hx,\n    refine le_trans _ ((div_le_iff' (zero_lt_two' \u211d)).2 (hd_le x.1 x.2)),\n    rwa [\u2190 nnreal.coe_two, \u2190 nnreal.coe_div, \u2190 nnreal.coe_pow, nnreal.coe_le_coe, pow_succ',\n      mul_one_div, nnreal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' \u211d\u22650),\n      hle_d, prod.mk.eta] }\nend\n\n/-- A `pseudo_metric_space` instance compatible with a given `uniform_space` structure. -/\nprotected noncomputable def uniform_space.pseudo_metric_space (X : Type*) [uniform_space X]\n  [is_countably_generated (\ud835\udce4 X)] : pseudo_metric_space X :=\n(uniform_space.metrizable_uniformity X).some.replace_uniformity $\n  congr_arg _ (uniform_space.metrizable_uniformity X).some_spec.symm\n\n/-- A `metric_space` instance compatible with a given `uniform_space` structure. -/\nprotected noncomputable def uniform_space.metric_space (X : Type*) [uniform_space X]\n  [is_countably_generated (\ud835\udce4 X)] [t0_space X] : metric_space X :=\n@metric_space.of_t0_pseudo_metric_space X (uniform_space.pseudo_metric_space X) _\n\n/-- A uniform space with countably generated `\ud835\udce4 X` is pseudo metrizable. -/\n@[priority 100]\ninstance uniform_space.pseudo_metrizable_space [uniform_space X] [is_countably_generated (\ud835\udce4 X)] :\n  topological_space.pseudo_metrizable_space X :=\nby { letI := uniform_space.pseudo_metric_space X, apply_instance }\n\n/-- A T\u2080 uniform space with countably generated `\ud835\udce4 X` is metrizable. This is not an instance to\navoid loops. -/\nlemma uniform_space.metrizable_space [uniform_space X] [is_countably_generated (\ud835\udce4 X)] [t0_space X] :\n  topological_space.metrizable_space X :=\nby { letI := uniform_space.metric_space X, apply_instance }\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/metric_space/metrizable_uniformity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7014623257995062}}
{"text": "import data.real.basic\n\ndef fn_ub (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, f x \u2264 a\ndef fn_has_ub (f : \u211d \u2192 \u211d) := \u2203 a, fn_ub f a\n\nopen_locale classical\n\nvariable (f : \u211d \u2192 \u211d)\n\n-- BEGIN\nexample (h : \u00ac fn_has_ub f) : \u2200 a, \u2203 x, f x > a :=\nbegin\n  contrapose! h,\n  exact h,\nend\n\nexample (x : \u211d) (h : \u2200 \u03b5 > 0, x \u2264 \u03b5) : x \u2264 0 :=\nbegin\n  contrapose! h,\n  use x / 2,\n  split,\n  linarith,\n  linarith,\nend\n\nexample (x : \u211d) (h : \u2200 \u03b5 > 0, x \u2264 \u03b5) : x \u2264 0 :=\nbegin\n  contrapose! h,\n  use x / 2,\n  split; linarith,\nend\n\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/9_Tactics used for classical reasoning/9.3_contrapose/ex1_contrapose!_h.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7014623255937931}}
{"text": "/-\nCopyright (c) 2022 Kexing Ying. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kexing Ying, R\u00e9my Degenne\n\n! This file was ported from Lean 3 source module probability.process.hitting_time\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Probability.Process.Stopping\n\n/-!\n# Hitting time\n\nGiven a stochastic process, the hitting time provides the first time the process ``hits'' some\nsubset of the state space. The hitting time is a stopping time in the case that the time index is\ndiscrete and the process is adapted (this is true in a far more general setting however we have\nonly proved it for the discrete case so far).\n\n## Main definition\n\n* `measure_theory.hitting`: the hitting time of a stochastic process\n\n## Main results\n\n* `measure_theory.hitting_is_stopping_time`: a discrete hitting time of an adapted process is a\n  stopping time\n\n## Implementation notes\n\nIn the definition of the hitting time, we bound the hitting time by an upper and lower bound.\nThis is to ensure that our result is meaningful in the case we are taking the infimum of an\nempty set or the infimum of a set which is unbounded from below. With this, we can talk about\nhitting times indexed by the natural numbers or the reals. By taking the bounds to be\n`\u22a4` and `\u22a5`, we obtain the standard definition in the case that the index is `\u2115\u221e` or `\u211d\u22650\u221e`.\n\n-/\n\n\nopen Filter Order TopologicalSpace\n\nopen Classical MeasureTheory NNReal ENNReal Topology BigOperators\n\nnamespace MeasureTheory\n\nvariable {\u03a9 \u03b2 \u03b9 : Type _} {m : MeasurableSpace \u03a9}\n\n/-- Hitting time: given a stochastic process `u` and a set `s`, `hitting u s n m` is the first time\n`u` is in `s` after time `n` and before time `m` (if `u` does not hit `s` after time `n` and\nbefore `m` then the hitting time is simply `m`).\n\nThe hitting time is a stopping time if the process is adapted and discrete. -/\nnoncomputable def hitting [Preorder \u03b9] [InfSet \u03b9] (u : \u03b9 \u2192 \u03a9 \u2192 \u03b2) (s : Set \u03b2) (n m : \u03b9) : \u03a9 \u2192 \u03b9 :=\n  fun x => if \u2203 j \u2208 Set.Icc n m, u j x \u2208 s then inf\u209b (Set.Icc n m \u2229 { i : \u03b9 | u i x \u2208 s }) else m\n#align measure_theory.hitting MeasureTheory.hitting\n\nsection Inequalities\n\nvariable [ConditionallyCompleteLinearOrder \u03b9] {u : \u03b9 \u2192 \u03a9 \u2192 \u03b2} {s : Set \u03b2} {n i : \u03b9} {\u03c9 : \u03a9}\n\n/-- This lemma is strictly weaker than `hitting_of_le`. -/\ntheorem hitting_of_lt {m : \u03b9} (h : m < n) : hitting u s n m \u03c9 = m :=\n  by\n  simp_rw [hitting]\n  have h_not : \u00ac\u2203 (j : \u03b9)(H : j \u2208 Set.Icc n m), u j \u03c9 \u2208 s :=\n    by\n    push_neg\n    intro j\n    rw [Set.Icc_eq_empty_of_lt h]\n    simp only [Set.mem_empty_iff_false, IsEmpty.forall_iff]\n  simp only [h_not, if_false]\n#align measure_theory.hitting_of_lt MeasureTheory.hitting_of_lt\n\ntheorem hitting_le {m : \u03b9} (\u03c9 : \u03a9) : hitting u s n m \u03c9 \u2264 m :=\n  by\n  cases' le_or_lt n m with h_le h_lt\n  \u00b7 simp only [hitting]\n    split_ifs\n    \u00b7 obtain \u27e8j, hj\u2081, hj\u2082\u27e9 := h\n      exact (cinf\u209b_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter hj\u2081 hj\u2082)).trans hj\u2081.2\n    \u00b7 exact le_rfl\n  \u00b7 rw [hitting_of_lt h_lt]\n#align measure_theory.hitting_le MeasureTheory.hitting_le\n\ntheorem not_mem_of_lt_hitting {m k : \u03b9} (hk\u2081 : k < hitting u s n m \u03c9) (hk\u2082 : n \u2264 k) : u k \u03c9 \u2209 s :=\n  by\n  classical\n    intro h\n    have hexists : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s\n    refine' \u27e8k, \u27e8hk\u2082, le_trans hk\u2081.le <| hitting_le _\u27e9, h\u27e9\n    refine' not_le.2 hk\u2081 _\n    simp_rw [hitting, if_pos hexists]\n    exact cinf\u209b_le bdd_below_Icc.inter_of_left \u27e8\u27e8hk\u2082, le_trans hk\u2081.le <| hitting_le _\u27e9, h\u27e9\n#align measure_theory.not_mem_of_lt_hitting MeasureTheory.not_mem_of_lt_hitting\n\ntheorem hitting_eq_end_iff {m : \u03b9} :\n    hitting u s n m \u03c9 = m \u2194\n      (\u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s) \u2192 inf\u209b (Set.Icc n m \u2229 { i : \u03b9 | u i \u03c9 \u2208 s }) = m :=\n  by rw [hitting, ite_eq_right_iff]\n#align measure_theory.hitting_eq_end_iff MeasureTheory.hitting_eq_end_iff\n\ntheorem hitting_of_le {m : \u03b9} (hmn : m \u2264 n) : hitting u s n m \u03c9 = m :=\n  by\n  obtain rfl | h := le_iff_eq_or_lt.1 hmn\n  \u00b7 simp only [hitting, Set.Icc_self, ite_eq_right_iff, Set.mem_Icc, exists_prop,\n      forall_exists_index, and_imp]\n    intro i hi\u2081 hi\u2082 hi\n    rw [Set.inter_eq_left_iff_subset.2, cinf\u209b_singleton]\n    exact Set.singleton_subset_iff.2 (le_antisymm hi\u2082 hi\u2081 \u25b8 hi)\n  \u00b7 exact hitting_of_lt h\n#align measure_theory.hitting_of_le MeasureTheory.hitting_of_le\n\ntheorem le_hitting {m : \u03b9} (hnm : n \u2264 m) (\u03c9 : \u03a9) : n \u2264 hitting u s n m \u03c9 :=\n  by\n  simp only [hitting]\n  split_ifs\n  \u00b7 refine' le_cinf\u209b _ fun b hb => _\n    \u00b7 obtain \u27e8k, hk_Icc, hk_s\u27e9 := h\n      exact \u27e8k, hk_Icc, hk_s\u27e9\n    \u00b7 rw [Set.mem_inter_iff] at hb\n      exact hb.1.1\n  \u00b7 exact hnm\n#align measure_theory.le_hitting MeasureTheory.le_hitting\n\ntheorem le_hitting_of_exists {m : \u03b9} (h_exists : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s) :\n    n \u2264 hitting u s n m \u03c9 := by\n  refine' le_hitting _ \u03c9\n  by_contra\n  rw [Set.Icc_eq_empty_of_lt (not_le.mp h)] at h_exists\n  simpa using h_exists\n#align measure_theory.le_hitting_of_exists MeasureTheory.le_hitting_of_exists\n\ntheorem hitting_mem_Icc {m : \u03b9} (hnm : n \u2264 m) (\u03c9 : \u03a9) : hitting u s n m \u03c9 \u2208 Set.Icc n m :=\n  \u27e8le_hitting hnm \u03c9, hitting_le \u03c9\u27e9\n#align measure_theory.hitting_mem_Icc MeasureTheory.hitting_mem_Icc\n\ntheorem hitting_mem_set [IsWellOrder \u03b9 (\u00b7 < \u00b7)] {m : \u03b9} (h_exists : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s) :\n    u (hitting u s n m \u03c9) \u03c9 \u2208 s :=\n  by\n  simp_rw [hitting, if_pos h_exists]\n  have h_nonempty : (Set.Icc n m \u2229 { i : \u03b9 | u i \u03c9 \u2208 s }).Nonempty :=\n    by\n    obtain \u27e8k, hk\u2081, hk\u2082\u27e9 := h_exists\n    exact \u27e8k, Set.mem_inter hk\u2081 hk\u2082\u27e9\n  have h_mem := cinf\u209b_mem h_nonempty\n  rw [Set.mem_inter_iff] at h_mem\n  exact h_mem.2\n#align measure_theory.hitting_mem_set MeasureTheory.hitting_mem_set\n\ntheorem hitting_mem_set_of_hitting_lt [IsWellOrder \u03b9 (\u00b7 < \u00b7)] {m : \u03b9} (hl : hitting u s n m \u03c9 < m) :\n    u (hitting u s n m \u03c9) \u03c9 \u2208 s :=\n  by\n  by_cases h : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s\n  \u00b7 exact hitting_mem_set h\n  \u00b7 simp_rw [hitting, if_neg h] at hl\n    exact False.elim (hl.ne rfl)\n#align measure_theory.hitting_mem_set_of_hitting_lt MeasureTheory.hitting_mem_set_of_hitting_lt\n\ntheorem hitting_le_of_mem {m : \u03b9} (hin : n \u2264 i) (him : i \u2264 m) (his : u i \u03c9 \u2208 s) :\n    hitting u s n m \u03c9 \u2264 i :=\n  by\n  have h_exists : \u2203 k \u2208 Set.Icc n m, u k \u03c9 \u2208 s := \u27e8i, \u27e8hin, him\u27e9, his\u27e9\n  simp_rw [hitting, if_pos h_exists]\n  exact cinf\u209b_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter \u27e8hin, him\u27e9 his)\n#align measure_theory.hitting_le_of_mem MeasureTheory.hitting_le_of_mem\n\ntheorem hitting_le_iff_of_exists [IsWellOrder \u03b9 (\u00b7 < \u00b7)] {m : \u03b9}\n    (h_exists : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s) :\n    hitting u s n m \u03c9 \u2264 i \u2194 \u2203 j \u2208 Set.Icc n i, u j \u03c9 \u2208 s :=\n  by\n  constructor <;> intro h'\n  \u00b7 exact \u27e8hitting u s n m \u03c9, \u27e8le_hitting_of_exists h_exists, h'\u27e9, hitting_mem_set h_exists\u27e9\n  \u00b7 have h'' : \u2203 k \u2208 Set.Icc n (min m i), u k \u03c9 \u2208 s :=\n      by\n      obtain \u27e8k\u2081, hk\u2081_mem, hk\u2081_s\u27e9 := h_exists\n      obtain \u27e8k\u2082, hk\u2082_mem, hk\u2082_s\u27e9 := h'\n      refine' \u27e8min k\u2081 k\u2082, \u27e8le_min hk\u2081_mem.1 hk\u2082_mem.1, min_le_min hk\u2081_mem.2 hk\u2082_mem.2\u27e9, _\u27e9\n      exact min_rec' (fun j => u j \u03c9 \u2208 s) hk\u2081_s hk\u2082_s\n    obtain \u27e8k, hk\u2081, hk\u2082\u27e9 := h''\n    refine' le_trans _ (hk\u2081.2.trans (min_le_right _ _))\n    exact hitting_le_of_mem hk\u2081.1 (hk\u2081.2.trans (min_le_left _ _)) hk\u2082\n#align measure_theory.hitting_le_iff_of_exists MeasureTheory.hitting_le_iff_of_exists\n\ntheorem hitting_le_iff_of_lt [IsWellOrder \u03b9 (\u00b7 < \u00b7)] {m : \u03b9} (i : \u03b9) (hi : i < m) :\n    hitting u s n m \u03c9 \u2264 i \u2194 \u2203 j \u2208 Set.Icc n i, u j \u03c9 \u2208 s :=\n  by\n  by_cases h_exists : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s\n  \u00b7 rw [hitting_le_iff_of_exists h_exists]\n  \u00b7 simp_rw [hitting, if_neg h_exists]\n    push_neg  at h_exists\n    simp only [not_le.mpr hi, Set.mem_Icc, false_iff_iff, not_exists, and_imp]\n    exact fun k hkn hki => h_exists k \u27e8hkn, hki.trans hi.le\u27e9\n#align measure_theory.hitting_le_iff_of_lt MeasureTheory.hitting_le_iff_of_lt\n\ntheorem hitting_lt_iff [IsWellOrder \u03b9 (\u00b7 < \u00b7)] {m : \u03b9} (i : \u03b9) (hi : i \u2264 m) :\n    hitting u s n m \u03c9 < i \u2194 \u2203 j \u2208 Set.Ico n i, u j \u03c9 \u2208 s :=\n  by\n  constructor <;> intro h'\n  \u00b7 have h : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s := by\n      by_contra\n      simp_rw [hitting, if_neg h, \u2190 not_le] at h'\n      exact h' hi\n    exact \u27e8hitting u s n m \u03c9, \u27e8le_hitting_of_exists h, h'\u27e9, hitting_mem_set h\u27e9\n  \u00b7 obtain \u27e8k, hk\u2081, hk\u2082\u27e9 := h'\n    refine' lt_of_le_of_lt _ hk\u2081.2\n    exact hitting_le_of_mem hk\u2081.1 (hk\u2081.2.le.trans hi) hk\u2082\n#align measure_theory.hitting_lt_iff MeasureTheory.hitting_lt_iff\n\ntheorem hitting_eq_hitting_of_exists {m\u2081 m\u2082 : \u03b9} (h : m\u2081 \u2264 m\u2082)\n    (h' : \u2203 j \u2208 Set.Icc n m\u2081, u j \u03c9 \u2208 s) : hitting u s n m\u2081 \u03c9 = hitting u s n m\u2082 \u03c9 :=\n  by\n  simp only [hitting, if_pos h']\n  obtain \u27e8j, hj\u2081, hj\u2082\u27e9 := h'\n  rw [if_pos]\n  \u00b7 refine'\n      le_antisymm _\n        (cinf\u209b_le_cinf\u209b bdd_below_Icc.inter_of_left \u27e8j, hj\u2081, hj\u2082\u27e9\n          (Set.inter_subset_inter_left _ (Set.Icc_subset_Icc_right h)))\n    refine' le_cinf\u209b \u27e8j, Set.Icc_subset_Icc_right h hj\u2081, hj\u2082\u27e9 fun i hi => _\n    by_cases hi' : i \u2264 m\u2081\n    \u00b7 exact cinf\u209b_le bdd_below_Icc.inter_of_left \u27e8\u27e8hi.1.1, hi'\u27e9, hi.2\u27e9\n    \u00b7\n      exact\n        ((cinf\u209b_le bdd_below_Icc.inter_of_left \u27e8hj\u2081, hj\u2082\u27e9).trans (hj\u2081.2.trans le_rfl)).trans\n          (le_of_lt (not_le.1 hi'))\n  exact \u27e8j, \u27e8hj\u2081.1, hj\u2081.2.trans h\u27e9, hj\u2082\u27e9\n#align measure_theory.hitting_eq_hitting_of_exists MeasureTheory.hitting_eq_hitting_of_exists\n\ntheorem hitting_mono {m\u2081 m\u2082 : \u03b9} (hm : m\u2081 \u2264 m\u2082) : hitting u s n m\u2081 \u03c9 \u2264 hitting u s n m\u2082 \u03c9 :=\n  by\n  by_cases h : \u2203 j \u2208 Set.Icc n m\u2081, u j \u03c9 \u2208 s\n  \u00b7 exact (hitting_eq_hitting_of_exists hm h).le\n  \u00b7 simp_rw [hitting, if_neg h]\n    split_ifs with h'\n    \u00b7 obtain \u27e8j, hj\u2081, hj\u2082\u27e9 := h'\n      refine' le_cinf\u209b \u27e8j, hj\u2081, hj\u2082\u27e9 _\n      by_contra hneg\n      push_neg  at hneg\n      obtain \u27e8i, hi\u2081, hi\u2082\u27e9 := hneg\n      exact h \u27e8i, \u27e8hi\u2081.1.1, hi\u2082.le\u27e9, hi\u2081.2\u27e9\n    \u00b7 exact hm\n#align measure_theory.hitting_mono MeasureTheory.hitting_mono\n\nend Inequalities\n\n/-- A discrete hitting time is a stopping time. -/\ntheorem hitting_isStoppingTime [ConditionallyCompleteLinearOrder \u03b9] [IsWellOrder \u03b9 (\u00b7 < \u00b7)]\n    [Countable \u03b9] [TopologicalSpace \u03b2] [PseudoMetrizableSpace \u03b2] [MeasurableSpace \u03b2] [BorelSpace \u03b2]\n    {f : Filtration \u03b9 m} {u : \u03b9 \u2192 \u03a9 \u2192 \u03b2} {s : Set \u03b2} {n n' : \u03b9} (hu : Adapted f u)\n    (hs : MeasurableSet s) : IsStoppingTime f (hitting u s n n') :=\n  by\n  intro i\n  cases' le_or_lt n' i with hi hi\n  \u00b7 have h_le : \u2200 \u03c9, hitting u s n n' \u03c9 \u2264 i := fun x => (hitting_le x).trans hi\n    simp [h_le]\n  \u00b7 have h_set_eq_Union : { \u03c9 | hitting u s n n' \u03c9 \u2264 i } = \u22c3 j \u2208 Set.Icc n i, u j \u207b\u00b9' s :=\n      by\n      ext x\n      rw [Set.mem_setOf_eq, hitting_le_iff_of_lt _ hi]\n      simp only [Set.mem_Icc, exists_prop, Set.mem_union\u1d62, Set.mem_preimage]\n    rw [h_set_eq_Union]\n    exact\n      MeasurableSet.union\u1d62 fun j =>\n        MeasurableSet.union\u1d62 fun hj => f.mono hj.2 _ ((hu j).Measurable hs)\n#align measure_theory.hitting_is_stopping_time MeasureTheory.hitting_isStoppingTime\n\ntheorem stoppedValue_hitting_mem [ConditionallyCompleteLinearOrder \u03b9] [IsWellOrder \u03b9 (\u00b7 < \u00b7)]\n    {u : \u03b9 \u2192 \u03a9 \u2192 \u03b2} {s : Set \u03b2} {n m : \u03b9} {\u03c9 : \u03a9} (h : \u2203 j \u2208 Set.Icc n m, u j \u03c9 \u2208 s) :\n    stoppedValue u (hitting u s n m) \u03c9 \u2208 s :=\n  by\n  simp only [stopped_value, hitting, if_pos h]\n  obtain \u27e8j, hj\u2081, hj\u2082\u27e9 := h\n  have : Inf (Set.Icc n m \u2229 { i | u i \u03c9 \u2208 s }) \u2208 Set.Icc n m \u2229 { i | u i \u03c9 \u2208 s } :=\n    cinf\u209b_mem (Set.nonempty_of_mem \u27e8hj\u2081, hj\u2082\u27e9)\n  exact this.2\n#align measure_theory.stopped_value_hitting_mem MeasureTheory.stoppedValue_hitting_mem\n\n/-- The hitting time of a discrete process with the starting time indexed by a stopping time\nis a stopping time. -/\ntheorem isStoppingTime_hitting_isStoppingTime [ConditionallyCompleteLinearOrder \u03b9]\n    [IsWellOrder \u03b9 (\u00b7 < \u00b7)] [Countable \u03b9] [TopologicalSpace \u03b9] [OrderTopology \u03b9]\n    [FirstCountableTopology \u03b9] [TopologicalSpace \u03b2] [PseudoMetrizableSpace \u03b2] [MeasurableSpace \u03b2]\n    [BorelSpace \u03b2] {f : Filtration \u03b9 m} {u : \u03b9 \u2192 \u03a9 \u2192 \u03b2} {\u03c4 : \u03a9 \u2192 \u03b9} (h\u03c4 : IsStoppingTime f \u03c4)\n    {N : \u03b9} (h\u03c4bdd : \u2200 x, \u03c4 x \u2264 N) {s : Set \u03b2} (hs : MeasurableSet s) (hf : Adapted f u) :\n    IsStoppingTime f fun x => hitting u s (\u03c4 x) N x :=\n  by\n  intro n\n  have h\u2081 :\n    { x | hitting u s (\u03c4 x) N x \u2264 n } =\n      (\u22c3 i \u2264 n, { x | \u03c4 x = i } \u2229 { x | hitting u s i N x \u2264 n }) \u222a\n        \u22c3 i > n, { x | \u03c4 x = i } \u2229 { x | hitting u s i N x \u2264 n } :=\n    by\n    ext x\n    simp [\u2190 exists_or, \u2190 or_and_right, le_or_lt]\n  have h\u2082 : (\u22c3 i > n, { x | \u03c4 x = i } \u2229 { x | hitting u s i N x \u2264 n }) = \u2205 :=\n    by\n    ext x\n    simp only [gt_iff_lt, Set.mem_union\u1d62, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop,\n      Set.mem_empty_iff_false, iff_false_iff, not_exists, not_and, not_le]\n    rintro m hm rfl\n    exact lt_of_lt_of_le hm (le_hitting (h\u03c4bdd _) _)\n  rw [h\u2081, h\u2082, Set.union_empty]\n  exact\n    MeasurableSet.union\u1d62 fun i =>\n      MeasurableSet.union\u1d62 fun hi =>\n        (f.mono hi _ (h\u03c4.measurable_set_eq i)).inter (hitting_is_stopping_time hf hs n)\n#align measure_theory.is_stopping_time_hitting_is_stopping_time MeasureTheory.isStoppingTime_hitting_isStoppingTime\n\nsection CompleteLattice\n\nvariable [CompleteLattice \u03b9] {u : \u03b9 \u2192 \u03a9 \u2192 \u03b2} {s : Set \u03b2} {f : Filtration \u03b9 m}\n\ntheorem hitting_eq_inf\u209b (\u03c9 : \u03a9) : hitting u s \u22a5 \u22a4 \u03c9 = inf\u209b { i : \u03b9 | u i \u03c9 \u2208 s } :=\n  by\n  simp only [hitting, Set.mem_Icc, bot_le, le_top, and_self_iff, exists_true_left, Set.Icc_bot,\n    Set.Iic_top, Set.univ_inter, ite_eq_left_iff, not_exists]\n  intro h_nmem_s\n  symm\n  rw [inf\u209b_eq_top]\n  exact fun i hi_mem_s => absurd hi_mem_s (h_nmem_s i)\n#align measure_theory.hitting_eq_Inf MeasureTheory.hitting_eq_inf\u209b\n\nend CompleteLattice\n\nsection ConditionallyCompleteLinearOrderBot\n\nvariable [ConditionallyCompleteLinearOrderBot \u03b9] [IsWellOrder \u03b9 (\u00b7 < \u00b7)]\n\nvariable {u : \u03b9 \u2192 \u03a9 \u2192 \u03b2} {s : Set \u03b2} {f : Filtration \u2115 m}\n\ntheorem hitting_bot_le_iff {i n : \u03b9} {\u03c9 : \u03a9} (hx : \u2203 j, j \u2264 n \u2227 u j \u03c9 \u2208 s) :\n    hitting u s \u22a5 n \u03c9 \u2264 i \u2194 \u2203 j \u2264 i, u j \u03c9 \u2208 s :=\n  by\n  cases' lt_or_le i n with hi hi\n  \u00b7 rw [hitting_le_iff_of_lt _ hi]\n    simp\n  \u00b7 simp only [(hitting_le \u03c9).trans hi, true_iff_iff]\n    obtain \u27e8j, hj\u2081, hj\u2082\u27e9 := hx\n    exact \u27e8j, hj\u2081.trans hi, hj\u2082\u27e9\n#align measure_theory.hitting_bot_le_iff MeasureTheory.hitting_bot_le_iff\n\nend ConditionallyCompleteLinearOrderBot\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Probability/Process/HittingTime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7013811938994654}}
{"text": "import tactic\n\nvariables (x y : \u2115)\n\nopen nat\n\ntheorem Q2a : 1 * x = x \u2227 x = x * 1 :=\nbegin\n  split,\n  { induction x with d hd,\n      refl,\n    rw [mul_succ,hd],\n  },\n  rw [mul_succ, mul_zero, zero_add],\nend\n\n-- Dr Lawn does not define z in her problem sheet.\n-- Fortunately I can infer the type of z from the context.\nvariable z : \u2115\n\ntheorem Q2b : (x + y) * z = x * z + y * z :=\nbegin\n  induction z with d hd,\n    refl,\n  rw [mul_succ, hd, mul_succ, mul_succ],\n  ac_refl,\nend\n\ntheorem Q2c : (x * y) * z = x * (y * z) :=\nbegin\n  induction z with d hd,\n  { refl },\n  { rw [mul_succ, mul_succ, hd, mul_add] }\nend\n\n-- Q3 def\ndef is_pred (x y : \u2115) := x.succ = y\n\ntheorem Q3a : \u00ac \u2203 x : \u2115, is_pred x 0 :=\nbegin\n  intro h,\n  cases h with x hx,\n  unfold is_pred at hx,\n  apply succ_ne_zero x,\n  assumption,\nend\n\ntheorem Q3b : y \u2260 0 \u2192 \u2203! x, is_pred x y :=\nbegin\n  intro hy,\n  cases y,\n    exfalso,\n    apply hy,\n    refl,\n  clear hy,\n  use y,\n  split,\n  { dsimp only,\n    unfold is_pred,\n  },\n  intro z,\n  dsimp only [is_pred],\n  exact succ_inj'.1,\nend\n\ndef aux : 0 < y \u2192 \u2203 x, is_pred x y :=\nbegin\n  intro hy,\n  cases Q3b _ (ne_of_lt hy).symm with x hx,\n  use x,\n  exact hx.1,\nend\n\n-- definition of pred' is \"choose a random d such that succ(d) = n\"\nnoncomputable def pred' : \u2115+ \u2192 \u2115 := \u03bb nhn, classical.some (aux nhn nhn.2)\n\ntheorem pred'_def : \u2200 np : \u2115+, is_pred (pred' np) np :=\n\u03bb nhn, classical.some_spec (aux nhn nhn.2)\n\ndef succ' : \u2115 \u2192 \u2115+ :=\n\u03bb n, \u27e8n.succ, zero_lt_succ n\u27e9\n\nnoncomputable definition Q3c : \u2115+ \u2243 \u2115 :=\n{ to_fun := pred',\n  inv_fun := succ',\n  left_inv := begin\n    rintro np,\n    have h := pred'_def,\n    unfold succ',\n    ext, dsimp,\n    unfold is_pred at h,\n    rw h,\n  end,\n  right_inv := begin\n    intro n,\n    unfold succ',\n    have h := pred'_def,\n    unfold is_pred at h,\n    rw \u2190 succ_inj',\n    rw h,\n    clear h,\n    refl,\n  end\n   }\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M40001_lean", "sha": "62a76fa92654c855af2b2fc2bef8e60acd16ccec", "save_path": "github-repos/lean/ImperialCollegeLondon-M40001_lean", "path": "github-repos/lean/ImperialCollegeLondon-M40001_lean/M40001_lean-62a76fa92654c855af2b2fc2bef8e60acd16ccec/src/2020/problem_sheets/Part_II/sheet1_q2_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382004, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.701381189825611}}
{"text": "/-\nCopyright (c) 2021 Fr\u00e9d\u00e9ric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Fr\u00e9d\u00e9ric Dupuis\n-/\n\nimport analysis.normed_space.basic\nimport analysis.normed_space.linear_isometry\n\n/-!\n# Normed star rings and algebras\n\nA normed star monoid is a `star_add_monoid` endowed with a norm such that the star operation is\nisometric.\n\nA C\u22c6-ring is a normed star monoid that is also a ring and that verifies the stronger\ncondition `\u2225x\u22c6 * x\u2225 = \u2225x\u2225^2` for all `x`.  If a C\u22c6-ring is also a star algebra, then it is a\nC\u22c6-algebra.\n\nTo get a C\u22c6-algebra `E` over field `\ud835\udd5c`, use\n`[normed_field \ud835\udd5c] [star_ring \ud835\udd5c] [normed_ring E] [star_ring E] [cstar_ring E]\n [normed_algebra \ud835\udd5c E] [star_module \ud835\udd5c E]`.\n\n## TODO\n\n- Show that `\u2225x\u22c6 * x\u2225 = \u2225x\u2225^2` is equivalent to `\u2225x\u22c6 * x\u2225 = \u2225x\u22c6\u2225 * \u2225x\u2225`, which is used as the\n  definition of C*-algebras in some sources (e.g. Wikipedia).\n\n-/\n\nlocal postfix `\u22c6`:1000 := star\n\n/-- A normed star ring is a star ring endowed with a norm such that `star` is isometric. -/\nclass normed_star_monoid (E : Type*) [normed_group E] [star_add_monoid E] :=\n(norm_star : \u2200 {x : E}, \u2225x\u22c6\u2225 = \u2225x\u2225)\n\nexport normed_star_monoid (norm_star)\nattribute [simp] norm_star\n\n/-- A C*-ring is a normed star ring that satifies the stronger condition `\u2225x\u22c6 * x\u2225 = \u2225x\u2225^2`\nfor every `x`. -/\nclass cstar_ring (E : Type*) [normed_ring E] [star_ring E] :=\n(norm_star_mul_self : \u2200 {x : E}, \u2225x\u22c6 * x\u2225 = \u2225x\u2225 * \u2225x\u2225)\n\nnoncomputable instance : cstar_ring \u211d :=\n{ norm_star_mul_self := \u03bb x, by simp only [star, id.def, normed_field.norm_mul] }\n\nvariables {\ud835\udd5c E : Type*}\n\nopen cstar_ring\n\n/-- In a C*-ring, star preserves the norm. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance cstar_ring.to_normed_star_monoid {E : Type*} [normed_ring E] [star_ring E] [cstar_ring E] :\n  normed_star_monoid E :=\n\u27e8begin\n  intro x,\n  by_cases htriv : x = 0,\n  { simp only [htriv, star_zero] },\n  { have hnt : 0 < \u2225x\u2225 := norm_pos_iff.mpr htriv,\n    have hnt_star : 0 < \u2225x\u22c6\u2225 :=\n      norm_pos_iff.mpr ((add_equiv.map_ne_zero_iff star_add_equiv).mpr htriv),\n    have h\u2081 := calc\n      \u2225x\u2225 * \u2225x\u2225 = \u2225x\u22c6 * x\u2225        : norm_star_mul_self.symm\n            ... \u2264 \u2225x\u22c6\u2225 * \u2225x\u2225      : norm_mul_le _ _,\n    have h\u2082 := calc\n      \u2225x\u22c6\u2225 * \u2225x\u22c6\u2225 = \u2225x * x\u22c6\u2225      : by rw [\u2190norm_star_mul_self, star_star]\n             ... \u2264 \u2225x\u2225 * \u2225x\u22c6\u2225     : norm_mul_le _ _,\n    exact le_antisymm (le_of_mul_le_mul_right h\u2082 hnt_star) (le_of_mul_le_mul_right h\u2081 hnt) },\nend\u27e9\n\nlemma cstar_ring.norm_self_mul_star [normed_ring E] [star_ring E] [cstar_ring E] {x : E} :\n  \u2225x * x\u22c6\u2225 = \u2225x\u2225 * \u2225x\u2225 :=\nby { nth_rewrite 0 [\u2190star_star x], simp only [norm_star_mul_self, norm_star] }\n\nlemma cstar_ring.norm_star_mul_self' [normed_ring E] [star_ring E] [cstar_ring E] {x : E} :\n  \u2225x\u22c6 * x\u2225 = \u2225x\u22c6\u2225 * \u2225x\u2225 :=\nby rw [norm_star_mul_self, norm_star]\n\nsection star\u2097\u1d62\n\nvariables [comm_semiring \ud835\udd5c] [star_ring \ud835\udd5c] [normed_ring E] [star_ring E] [normed_star_monoid E]\nvariables [module \ud835\udd5c E] [star_module \ud835\udd5c E]\n\nvariables (\ud835\udd5c)\n/-- `star` bundled as a linear isometric equivalence -/\ndef star\u2097\u1d62 : E \u2243\u2097\u1d62\u22c6[\ud835\udd5c] E :=\n{ map_smul' := star_smul,\n  norm_map' := \u03bb x, norm_star,\n  .. star_add_equiv }\n\nvariables {\ud835\udd5c}\n\n@[simp] lemma coe_star\u2097\u1d62 : (star\u2097\u1d62 \ud835\udd5c : E \u2192 E) = star := rfl\n\nlemma star\u2097\u1d62_apply {x : E} : star\u2097\u1d62 \ud835\udd5c x = star x := rfl\n\nend star\u2097\u1d62\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/analysis/normed_space/star.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7013811830799535}}
{"text": "example (x y : \u2115) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n  by rw [mul_add, add_mul, add_mul, \u2190add_assoc]\n\nexample (x y : \u2115) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n  by simp [mul_add, add_mul, add_left_comm]\n-- lean 3.6 removes simp attributes from add_left_comm\n-- i.e., now it is required to provide that lemma to solve this example.\n", "meta": {"author": "Ailrun", "repo": "Theorem_Proving_in_Lean", "sha": "2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68", "save_path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean", "path": "github-repos/lean/Ailrun-Theorem_Proving_in_Lean/Theorem_Proving_in_Lean-2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68/src/ch4/ex0308.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7013811729228808}}
{"text": "/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n\n! This file was ported from Lean 3 source module data.int.dvd.pow\n! leanprover-community/mathlib commit b3f25363ae62cb169e72cd6b8b1ac97bacf21ca7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Int.Dvd.Basic\nimport Mathlib.Data.Nat.Pow\n\n/-!\n# Basic lemmas about the divisibility relation in `\u2124` involving powers.\n-/\n\n\nopen Nat\n\nnamespace Int\n\nset_option linter.deprecated false in\n@[simp]\ntheorem sign_pow_bit1 (k : \u2115) : \u2200 n : \u2124, n.sign ^ bit1 k = n.sign\n  | (_ + 1 : \u2115) => one_pow (bit1 k)\n  | 0 => zero_pow (Nat.zero_lt_bit1 k)\n  | -[_+1] => (neg_pow_bit1 1 k).trans (congr_arg (fun x => -x) (one_pow (bit1 k)))\n#align int.sign_pow_bit1 Int.sign_pow_bit1\n\ntheorem pow_dvd_of_le_of_pow_dvd {p m n : \u2115} {k : \u2124} (hmn : m \u2264 n) (hdiv : \u2191(p ^ n) \u2223 k) :\n    \u2191(p ^ m) \u2223 k := by\n  induction k with\n  | ofNat k =>\n    apply Int.coe_nat_dvd.2\n    apply Nat.pow_dvd_of_le_of_pow_dvd hmn\n    apply Int.coe_nat_dvd.1 hdiv\n  | negSucc k =>\n    show \u2191(p ^ m) \u2223 -(\u2191(k + 1) : \u2124)\n    apply dvd_neg_of_dvd\n    apply Int.coe_nat_dvd.2\n    apply Nat.pow_dvd_of_le_of_pow_dvd hmn\n    apply Int.coe_nat_dvd.1\n    apply dvd_of_dvd_neg\n    exact hdiv\n#align int.pow_dvd_of_le_of_pow_dvd Int.pow_dvd_of_le_of_pow_dvd\n\ntheorem dvd_of_pow_dvd {p k : \u2115} {m : \u2124} (hk : 1 \u2264 k) (hpk : \u2191(p ^ k) \u2223 m) : \u2191p \u2223 m := by\n  rw [\u2190 pow_one p] ; exact pow_dvd_of_le_of_pow_dvd hk hpk\n#align int.dvd_of_pow_dvd Int.dvd_of_pow_dvd\n\nend Int\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Data/Int/Dvd/Pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7013811715649296}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Patrick Stevens\n-/\nimport data.nat.choose.basic\nimport data.nat.prime\n\n/-!\n# Divisibility properties of binomial coefficients\n-/\n\nnamespace nat\n\nopen_locale nat\n\nnamespace prime\n\nlemma dvd_choose_add {p a b : \u2115} (hap : a < p) (hbp : b < p) (h : p \u2264 a + b)\n  (hp : prime p) : p \u2223 choose (a + b) a :=\nhave h\u2081 : p \u2223 (a + b)!, from hp.dvd_factorial.2 h,\nhave h\u2082 : \u00acp \u2223 a!, from mt hp.dvd_factorial.1 (not_le_of_gt hap),\nhave h\u2083 : \u00acp \u2223 b!, from mt hp.dvd_factorial.1 (not_le_of_gt hbp),\nby\n  rw [\u2190 choose_mul_factorial_mul_factorial (le.intro rfl), mul_assoc, hp.dvd_mul, hp.dvd_mul,\n      add_tsub_cancel_left a b] at h\u2081;\n  exact h\u2081.resolve_right (not_or_distrib.2 \u27e8h\u2082, h\u2083\u27e9)\n\nlemma dvd_choose_self {p k : \u2115} (hk : 0 < k) (hkp : k < p) (hp : prime p) :\n  p \u2223 choose p k :=\nbegin\n  have r : k + (p - k) = p,\n    by rw [\u2190 add_tsub_assoc_of_le (nat.le_of_lt hkp) k, add_tsub_cancel_left],\n  have e : p \u2223 choose (k + (p - k)) k,\n    by exact dvd_choose_add hkp (nat.sub_lt (hk.trans hkp) hk) (by rw r) hp,\n  rwa r at e,\nend\n\nend prime\n\nend nat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/choose/dvd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7013621418162718}}
{"text": "import data.real.basic\n\n\n--- rising and falling factorials\ndef falling_qfact (q: \u211d) (n k: \u2115) : \u211d :=\nfinset.prod (finset.range k) (\u03bb i, 1 - q^(n-i))\n\ndef rising_qfact (q: \u211d) (k: \u2115) : \u211d :=\nfinset.prod (finset.range k) (\u03bb i, 1 - q^(i+1))\n\n\n--- q-binomial coefficient\nnoncomputable def qbinom (q: \u211d) (n k: \u2115) : \u211d := (falling_qfact q n k) / (rising_qfact q k)\n\n\n--- Some lemmas for splitting up the problem\nlemma q_pow_n_ne_one (q: \u211d) (n: \u2115) (qpos: q \u2265 0) (qn1: q \u2260 1) (npos: 0 < n) :\nq^n \u2260 1 :=\nbegin\n  cases ne.lt_or_lt qn1,\n  have q_pow_lt_one := pow_lt_pow_of_lt_left h qpos npos,\n  rw one_pow at q_pow_lt_one,\n  exact ne_of_lt q_pow_lt_one,\n\n  have q_pow_lt_one := pow_lt_pow_of_lt_left h zero_le_one npos,\n  rw one_pow at q_pow_lt_one,\n  exact ne_of_gt q_pow_lt_one,\nend\n\nlemma one_minus_q_pow_n_ne_zero (q: \u211d) (n: \u2115) (qpos: q \u2265 0) (qn1: q \u2260 1) (npos: 0 < n) :\n1 - q^n \u2260 0 :=\nbegin\n  have q_pow_n_ne_one := q_pow_n_ne_one q n qpos qn1 npos,\n  rw ne_comm at q_pow_n_ne_one,\n  exact sub_ne_zero_of_ne q_pow_n_ne_one,\nend\n\nlemma q_expand_one (q: \u211d) (n k: \u2115) (qpos: q \u2265 0) (qn1: q \u2260 1) (npos: 0 < n) (kln: k \u2264 n) :\n(1 : \u211d) = q^k * (1 - q^(n-k)) / (1 - q^n) + (1 - q^k) / (1 - q^n) :=\nbegin\n  have denom_nonzero := one_minus_q_pow_n_ne_zero q n qpos qn1 npos,\n  symmetry,\n  rw div_eq_mul_inv,\n  rw div_eq_mul_inv,\n  rw \u2190 right_distrib,\n  rw sub_eq_neg_add,\n  rw left_distrib,\n  rw \u2190 neg_mul_eq_mul_neg,\n  rw \u2190 pow_add,\n  rw nat.add_sub_of_le,\n  simp,\n  rw \u2190 sub_eq_neg_add,\n  rw mul_inv_cancel denom_nonzero,\n  exact kln,\nend\n\nlemma rising_fact_rec2 (q: \u211d) (n k: \u2115) (qpos: q \u2265 0) (qn1: q \u2260 1) (npos: 0 < n) (kpos: 0 < k) (kln: k \u2264 n) :\n(1 - q ^ (n - k)) / (1 - q ^ n) * (falling_qfact q n k) = (falling_qfact q (n-1) k) :=\nbegin\n  have denom_nonzero := one_minus_q_pow_n_ne_zero q n qpos qn1 npos,\n  rw falling_qfact,\n  rw mul_comm,\n  rw div_eq_mul_inv,\n  rw \u2190 mul_assoc,\n  rw \u2190 finset.prod_range_succ,\n  rw finset.prod_range_succ',\n  rw nat.sub_zero,\n  rw mul_assoc,\n  rw mul_inv_cancel denom_nonzero,\n  simp,\n  conv in (\u03bb (i : \u2115), 1 - q ^ (n - (i + 1))) {\n    rw add_comm,\n    rw \u2190 nat.sub_sub,\n  },\n  rw \u2190 falling_qfact,\nend\n\nlemma falling_fact_rec (q: \u211d) (n k: \u2115) (qpos: q \u2265 0) (qn1: q \u2260 1) (npos: 0 < n) (kpos: 0 < k) (kln: k \u2264 n) :\n(falling_qfact q n k) = (1 - q ^ n) * (falling_qfact q (n-1) (k-1)) :=\nbegin\n  symmetry,\n  rw falling_qfact,\n  rw mul_comm,\n  conv in (\u03bb (i : \u2115), 1 - q ^ (n - 1 - i)) {\n    rw nat.sub_sub,\n    rw add_comm,\n  },\n  conv in (1 - q ^ n) { rw \u2190 nat.sub_zero n },\n  rw \u2190 finset.prod_range_succ' (\u03bb (i : \u2115), 1 - q ^ (n - i)),\n  rw \u2190 falling_qfact,\n  rw nat.sub_add_cancel,\n  exact nat.succ_le_of_lt kpos,\nend\n\nlemma rising_fact_rec (q: \u211d) (k: \u2115) (qpos: q \u2265 0) (qn1: q \u2260 1) (kpos: 0 < k):\n(rising_qfact q k) = (1 - q ^ k) * (rising_qfact q (k-1)) :=\nbegin\n  symmetry,\n  rw rising_qfact,\n  conv in (1 - q^k) { rw \u2190 nat.sub_add_cancel (nat.succ_le_of_lt kpos), },\n  rw mul_comm,\n  rw \u2190 finset.prod_range_succ,\n  rw nat.sub_add_cancel,\n  rw \u2190 rising_qfact,\n  exact nat.succ_le_of_lt kpos,\nend\n\n\n--- Recurrence for q-binomial coefficients\ntheorem qbinom_recurrence (q: \u211d) (n k: \u2115) (qpos: q \u2265 0) (qn1: q \u2260 1) (npos: 0 < n) (kpos: 0 < k) (kln: k \u2264 n) :\nqbinom q n k = q^k * qbinom q (n-1) k + qbinom q (n-1) (k-1) :=\nbegin\n  -- rw qbinom, rw falling_qfact, rw rising_qfact,  -- Unwrap left side\n  rw \u2190 one_mul (qbinom q n k),\n  rw q_expand_one q n k qpos qn1 npos kln,\n  rw right_distrib,\n  rw qbinom,\n  rw mul_comm (q^k),\n  rw \u2190 div_mul_eq_mul_div,\n  rw mul_comm _ (q^k),\n  rw mul_assoc,\n  rw mul_comm ((1 - q ^ (n - k)) / (1 - q ^ n)),\n  rw div_mul_eq_mul_div _ _ (rising_qfact q k),\n  rw mul_comm (falling_qfact q n k),\n  rw (rising_fact_rec2 q n k qpos qn1 npos kpos kln),\n  rw \u2190 qbinom,\n\n  rw add_comm,\n  rw (falling_fact_rec q n k qpos qn1 npos kpos kln),\n  rw (rising_fact_rec q k qpos qn1 kpos),\n  rw \u2190 div_mul_div,\n  rw \u2190 qbinom,\n  rw \u2190 mul_assoc,\n  rw div_mul_div,\n  rw mul_comm (1 - q ^ k),\n  rw div_self,\n  simp,\n  rw add_comm,\n\n  -- Make sure we can do div_self\n  have q_pos_n_ne_zero := one_minus_q_pow_n_ne_zero q n qpos qn1 npos,\n  have q_pos_k_ne_zero := one_minus_q_pow_n_ne_zero q k qpos qn1 kpos,\n  exact (mul_ne_zero q_pos_n_ne_zero q_pos_k_ne_zero),\nend", "meta": {"author": "hdamron17", "repo": "Lean-q-binomial", "sha": "fcbdb385258e9d1fa25489023198206064a11c0d", "save_path": "github-repos/lean/hdamron17-Lean-q-binomial", "path": "github-repos/lean/hdamron17-Lean-q-binomial/Lean-q-binomial-fcbdb385258e9d1fa25489023198206064a11c0d/src/Lean-q-Binomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7013621327225418}}
{"text": "/-\nCopyright (c) 2023 Mark Andrew Gerads. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mark Andrew Gerads, Junyan Xu, Eric Wieser\n-/\nimport tactic.ring\nimport data.nat.parity\n\n/-!\n# Hyperoperation sequence\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines the Hyperoperation sequence.\n`hyperoperation 0 m k = k + 1`\n`hyperoperation 1 m k = m + k`\n`hyperoperation 2 m k = m * k`\n`hyperoperation 3 m k = m ^ k`\n`hyperoperation (n + 3) m 0 = 1`\n`hyperoperation (n + 1) m (k + 1) = hyperoperation n m (hyperoperation (n + 1) m k)`\n\n## References\n\n* <https://en.wikipedia.org/wiki/Hyperoperation>\n\n## Tags\n\nhyperoperation\n-/\n\n/--\nImplementation of the hyperoperation sequence\nwhere `hyperoperation n m k` is the `n`th hyperoperation between `m` and `k`.\n-/\ndef hyperoperation : \u2115 \u2192 \u2115 \u2192 \u2115 \u2192 \u2115\n| 0 _ k := k + 1\n| 1 m 0 := m\n| 2 _ 0 := 0\n| (n + 3) _ 0 := 1\n| (n + 1) m (k + 1) := hyperoperation n m (hyperoperation (n + 1) m k)\n\n-- Basic hyperoperation lemmas\n\n@[simp] lemma hyperoperation_zero (m : \u2115) : hyperoperation 0 m = nat.succ :=\nfunext $ \u03bb k, by rw [hyperoperation, nat.succ_eq_add_one]\n\nlemma hyperoperation_ge_three_eq_one (n m : \u2115) : hyperoperation (n + 3) m 0 = 1 :=\nby rw hyperoperation\n\nlemma hyperoperation_recursion (n m k : \u2115) :\n  hyperoperation (n + 1) m (k + 1) = hyperoperation n m (hyperoperation (n + 1) m k) :=\nby obtain (_|_|_) := n; rw hyperoperation\n\n-- Interesting hyperoperation lemmas\n\n@[simp] lemma hyperoperation_one : hyperoperation 1 = (+) :=\nbegin\n  ext m k,\n  induction k with bn bih,\n  { rw [nat_add_zero m, hyperoperation], },\n  { rw [hyperoperation_recursion, bih, hyperoperation_zero],\n    exact nat.add_assoc m bn 1, },\nend\n\n@[simp] lemma hyperoperation_two : hyperoperation 2 = (*) :=\nbegin\n  ext m k,\n  induction k with bn bih,\n  { rw hyperoperation,\n    exact (nat.mul_zero m).symm, },\n  { rw [hyperoperation_recursion, hyperoperation_one, bih],\n    ring, },\nend\n\n@[simp] lemma hyperoperation_three : hyperoperation 3 = (^) :=\nbegin\n  ext m k,\n  induction k with bn bih,\n  { rw hyperoperation_ge_three_eq_one,\n    exact (pow_zero m).symm, },\n  { rw [hyperoperation_recursion, hyperoperation_two, bih],\n    exact (pow_succ m bn).symm, },\nend\n\nlemma hyperoperation_ge_two_eq_self (n m : \u2115) : hyperoperation (n + 2) m 1 = m :=\nbegin\n  induction n with nn nih,\n  { rw hyperoperation_two,\n    ring, },\n  { rw [hyperoperation_recursion, hyperoperation_ge_three_eq_one, nih], },\nend\n\nlemma hyperoperation_two_two_eq_four (n : \u2115) : hyperoperation (n + 1) 2 2 = 4 :=\nbegin\n  induction n with nn nih,\n  { rw hyperoperation_one, },\n  { rw [hyperoperation_recursion, hyperoperation_ge_two_eq_self, nih], },\nend\n\nlemma hyperoperation_ge_three_one (n : \u2115) : \u2200 (k : \u2115), hyperoperation (n + 3) 1 k = 1 :=\nbegin\n  induction n with nn nih,\n  { intros k,\n    rw [hyperoperation_three, one_pow], },\n  { intros k,\n    cases k,\n    { rw hyperoperation_ge_three_eq_one, },\n    { rw [hyperoperation_recursion, nih], }, },\nend\n\nlemma hyperoperation_ge_four_zero (n k : \u2115) :\n  hyperoperation (n + 4) 0 k = if (even k) then 1 else 0 :=\nbegin\n  induction k with kk kih,\n  { rw hyperoperation_ge_three_eq_one,\n    simp only [even_zero, if_true], },\n  { rw hyperoperation_recursion,\n    rw kih,\n    simp_rw nat.even_add_one,\n    split_ifs,\n    { exact hyperoperation_ge_two_eq_self (n + 1) 0, },\n    { exact hyperoperation_ge_three_eq_one n 0, }, },\nend\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/data/nat/hyperoperation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7013621236288116}}
{"text": "variable (\u03b1 : Type) \n\nvariable (A B : \u03b1 \u2192 Prop) \n\nvariable (C : \u03b1 \u2192 \u03b1 \u2192 Prop) \n\ntheorem totally_fake (A : Prop) : A := sorry \n\n#check totally_fake\n\n-- \u2200 \\forall for universal quantifier\n\nexample (h : \u2200 (x:\u03b1), A x) (a : \u03b1) : A a := h a \n\nexample : \u2200 x, A x \u2192 A x := fun (x:\u03b1) (h: A x) => h \n\n-- \u2203 \\exists for existential quantifier \n\n#check @Exists \u03b1 \n\n#check @Exists.intro \n\n#check @Exists.elim \n\n-- = equality \n\n#check @Eq \u03b1 \n\n#check @Eq.refl \u03b1 \n\n#check @Eq.symm \u03b1 \n\n#check @Eq.trans \u03b1 \n\n#check @Eq.subst \u03b1 A \n\nvariable (f: \u03b1 \u2192 \u03b2) \nvariable (x y : \u03b1)\nvariable (h : x = y)\n\n#check @congrArg \u03b1 \u03b2 x y f \n\n#check congrArg f h \n\n\n\n\n\n", "meta": {"author": "UofSC-Fall-2022-Math-300-H01", "repo": "lean-notes", "sha": "40c1fe4cff620355bc3c9fa31ad886cb7836f7f3", "save_path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-lean-notes", "path": "github-repos/lean/UofSC-Fall-2022-Math-300-H01-lean-notes/lean-notes-40c1fe4cff620355bc3c9fa31ad886cb7836f7f3/10_05-notes2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7013621234603279}}
{"text": "/-\nCopyright (c) 2020 Alexander Bentkamp, S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp, S\u00e9bastien Gou\u00ebzel\n-/\nimport data.complex.basic\nimport algebra.algebra.ordered\nimport data.matrix.notation\nimport field_theory.tower\nimport linear_algebra.finite_dimensional\n\n/-!\n# Complex number as a vector space over `\u211d`\n\nThis file contains the following instances:\n* Any `\u2022`-structure (`has_scalar`, `mul_action`, `distrib_mul_action`, `module`, `algebra`) on\n  `\u211d` imbues a corresponding structure on `\u2102`. This includes the statement that `\u2102` is an `\u211d`\n  algebra.\n* any complex vector space is a real vector space;\n* any finite dimensional complex vector space is a finite dimensional real vector space;\n* the space of `\u211d`-linear maps from a real vector space to a complex vector space is a complex\n  vector space.\n\nIt also defines three linear maps:\n\n* `complex.re_lm`;\n* `complex.im_lm`;\n* `complex.of_real_lm`;\n* `complex.conj_lm`.\n\nThey are bundled versions of the real part, the imaginary part, the embedding of `\u211d` in `\u2102`, and\nthe complex conjugate as `\u211d`-linear maps.\n-/\nnoncomputable theory\n\nnamespace complex\n\nvariables {R : Type*} {S : Type*}\n\nsection\n\nvariables [has_scalar R \u211d]\n\n/- The useless `0` multiplication in `smul` is to make sure that\n`restrict_scalars.module \u211d \u2102 \u2102  = complex.module` definitionally. -/\ninstance : has_scalar R \u2102 :=\n{ smul := \u03bb r x, \u27e8r \u2022 x.re - 0 * x.im, r \u2022 x.im + 0 * x.re\u27e9 }\n\nlemma smul_re (r : R) (z : \u2102) : (r \u2022 z).re = r \u2022 z.re := by simp [(\u2022)]\nlemma smul_im (r : R) (z : \u2102) : (r \u2022 z).im = r \u2022 z.im := by simp [(\u2022)]\n\n@[simp] lemma smul_coe {x : \u211d} {z : \u2102} : x \u2022 z = x * z :=\nby ext; simp [smul_re, smul_im]\n\nend\n\ninstance [has_scalar R \u211d] [has_scalar S \u211d] [smul_comm_class R S \u211d] : smul_comm_class R S \u2102 :=\n{ smul_comm := \u03bb r s x, by ext; simp [smul_re, smul_im, smul_comm] }\n\ninstance [has_scalar R S] [has_scalar R \u211d] [has_scalar S \u211d] [is_scalar_tower R S \u211d] :\n  is_scalar_tower R S \u2102 :=\n{ smul_assoc := \u03bb r s x, by ext; simp [smul_re, smul_im, smul_assoc] }\n\ninstance [monoid R] [mul_action R \u211d] : mul_action R \u2102 :=\n{ one_smul := \u03bb x, by ext; simp [smul_re, smul_im, one_smul],\n  mul_smul := \u03bb r s x, by ext; simp  [smul_re, smul_im, mul_smul] }\n\ninstance [semiring R] [distrib_mul_action R \u211d] : distrib_mul_action R \u2102 :=\n{ smul_add := \u03bb r x y, by ext; simp [smul_re, smul_im, smul_add],\n  smul_zero := \u03bb r, by ext; simp [smul_re, smul_im, smul_zero] }\n\ninstance [semiring R] [module R \u211d] : module R \u2102 :=\n{ add_smul := \u03bb r s x, by ext; simp [smul_re, smul_im, add_smul],\n  zero_smul := \u03bb r, by ext; simp [smul_re, smul_im, zero_smul] }\n\ninstance [comm_semiring R] [algebra R \u211d] : algebra R \u2102 :=\n{ smul := (\u2022),\n  smul_def' := \u03bb r x, by ext; simp [smul_re, smul_im, algebra.smul_def],\n  commutes' := \u03bb r \u27e8xr, xi\u27e9, by ext; simp [smul_re, smul_im, algebra.commutes],\n  ..complex.of_real.comp (algebra_map R \u211d) }\n\n/-- Complex conjugation as an `\u211d`-algebra isomorphism  -/\ndef conj_alg_equiv : \u2102 \u2243\u2090[\u211d] \u2102 :=\n{ inv_fun := complex.conj,\n  left_inv := complex.conj_conj,\n  right_inv := complex.conj_conj,\n  commutes' := complex.conj_of_real,\n  .. complex.conj }\n\nsection\nopen_locale complex_order\n\nlemma complex_ordered_module : ordered_module \u211d \u2102 :=\n{ smul_lt_smul_of_pos := \u03bb z w x h\u2081 h\u2082,\n  begin\n    obtain \u27e8y, l, rfl\u27e9 := lt_def.mp h\u2081,\n    refine lt_def.mpr \u27e8x * y, _, _\u27e9,\n    exact mul_pos h\u2082 l,\n    ext; simp [mul_add],\n  end,\n  lt_of_smul_lt_smul_of_pos := \u03bb z w x h\u2081 h\u2082,\n  begin\n    obtain \u27e8y, l, e\u27e9 := lt_def.mp h\u2081,\n    by_cases h : x = 0,\n    { subst h, exfalso, apply lt_irrefl 0 h\u2082, },\n    { refine lt_def.mpr \u27e8y / x, div_pos l h\u2082, _\u27e9,\n      replace e := congr_arg (\u03bb z, (x\u207b\u00b9 : \u2102) * z) e,\n      simp only [mul_add, \u2190mul_assoc, h, one_mul, of_real_eq_zero, smul_coe, ne.def,\n        not_false_iff, inv_mul_cancel] at e,\n      convert e,\n      simp only [div_eq_iff_mul_eq, h, of_real_eq_zero, of_real_div, ne.def, not_false_iff],\n      norm_cast,\n      simp [mul_comm _ y, mul_assoc, h],\n    },\n  end }\n\nlocalized \"attribute [instance] complex_ordered_module\" in complex_order\n\nend\n\n\n@[simp] lemma coe_algebra_map : \u21d1(algebra_map \u211d \u2102) = complex.of_real := rfl\n\nopen submodule finite_dimensional\n\nlemma is_basis_one_I : is_basis \u211d ![1, I] :=\nbegin\n  refine \u27e8linear_independent_fin2.2 \u27e8by simp [I_ne_zero], \u03bb a, mt (congr_arg re) $ by simp\u27e9,\n    eq_top_iff'.2 $ \u03bb z, _\u27e9,\n  suffices : \u2203 a b : \u211d, z = a \u2022 I + b \u2022 1,\n    by simpa [mem_span_insert, mem_span_singleton, -set.singleton_one],\n  use [z.im, z.re],\n  simp [algebra.smul_def, add_comm]\nend\n\ninstance : finite_dimensional \u211d \u2102 := of_fintype_basis is_basis_one_I\n\n@[simp] lemma finrank_real_complex : finite_dimensional.finrank \u211d \u2102 = 2 :=\nby rw [finrank_eq_card_basis is_basis_one_I, fintype.card_fin]\n\n@[simp] lemma dim_real_complex : module.rank \u211d \u2102 = 2 :=\nby simp [\u2190 finrank_eq_dim, finrank_real_complex]\n\nlemma {u} dim_real_complex' : cardinal.lift.{0 u} (module.rank \u211d \u2102) = 2 :=\nby simp [\u2190 finrank_eq_dim, finrank_real_complex, bit0]\n\n/-- `fact` version of the dimension of `\u2102` over `\u211d`, locally useful in the definition of the\ncircle. -/\nlemma finrank_real_complex_fact : fact (finrank \u211d \u2102 = 2) := \u27e8finrank_real_complex\u27e9\n\nend complex\n\n/- Register as an instance (with low priority) the fact that a complex vector space is also a real\nvector space. -/\n@[priority 900]\ninstance module.complex_to_real (E : Type*) [add_comm_group E] [module \u2102 E] : module \u211d E :=\nrestrict_scalars.module \u211d \u2102 E\n\ninstance module.real_complex_tower (E : Type*) [add_comm_group E] [module \u2102 E] :\n  is_scalar_tower \u211d \u2102 E :=\nrestrict_scalars.is_scalar_tower \u211d \u2102 E\n\n@[priority 100]\ninstance finite_dimensional.complex_to_real (E : Type*) [add_comm_group E] [module \u2102 E]\n  [finite_dimensional \u2102 E] : finite_dimensional \u211d E :=\nfinite_dimensional.trans \u211d \u2102 E\n\nlemma dim_real_of_complex (E : Type*) [add_comm_group E] [module \u2102 E] :\n  module.rank \u211d E = 2 * module.rank \u2102 E :=\ncardinal.lift_inj.1 $\n  by { rw [\u2190 dim_mul_dim' \u211d \u2102 E, complex.dim_real_complex], simp [bit0] }\n\nlemma finrank_real_of_complex (E : Type*) [add_comm_group E] [module \u2102 E] :\n  finite_dimensional.finrank \u211d E = 2 * finite_dimensional.finrank \u2102 E :=\nby rw [\u2190 finite_dimensional.finrank_mul_finrank \u211d \u2102 E, complex.finrank_real_complex]\n\nnamespace complex\n\n/-- Linear map version of the real part function, from `\u2102` to `\u211d`. -/\ndef re_lm : \u2102 \u2192\u2097[\u211d] \u211d :=\n{ to_fun := \u03bbx, x.re,\n  map_add' := add_re,\n  map_smul' := by simp, }\n\n@[simp] lemma re_lm_coe : \u21d1re_lm = re := rfl\n\n/-- Linear map version of the imaginary part function, from `\u2102` to `\u211d`. -/\ndef im_lm : \u2102 \u2192\u2097[\u211d] \u211d :=\n{ to_fun := \u03bbx, x.im,\n  map_add' := add_im,\n  map_smul' := by simp, }\n\n@[simp] lemma im_lm_coe : \u21d1im_lm = im := rfl\n\n/-- Linear map version of the canonical embedding of `\u211d` in `\u2102`. -/\ndef of_real_lm : \u211d \u2192\u2097[\u211d] \u2102 :=\n{ to_fun := coe,\n  map_add' := of_real_add,\n  map_smul' := \u03bbc x, by simp [algebra.smul_def] }\n\n@[simp] lemma of_real_lm_coe : \u21d1of_real_lm = coe := rfl\n\n/-- `\u211d`-linear map version of the complex conjugation function from `\u2102` to `\u2102`. -/\ndef conj_lm : \u2102 \u2192\u2097[\u211d] \u2102 :=\n{ map_smul' := by simp [restrict_scalars_smul_def],\n  ..conj }\n\n@[simp] lemma conj_lm_coe : \u21d1conj_lm = conj := rfl\n\nend complex\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/complex/module.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7013621212711371}}
{"text": "-- ----------------------------------\n-- Demostrar que\n--    (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u)\n-- ----------------------------------\n\nimport data.set.basic\nopen set\n\nvariable {\u03b1 : Type}\nvariables s t u : set \u03b1\n\nexample : (s \u2229 t) \u222a (s \u2229 u) \u2286 s \u2229 (t \u222a u):=\nsorry\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/enunciados/Propiedad_semidistributiva_de_la_interseccion_sobre_la_union_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.7013591138158989}}
{"text": "import data.fintype.basic\nimport algebra.group.defs\nimport algebra.hom.group\nimport group_theory.subgroup.basic\nimport group_theory.order_of_element\nimport tactic\n\nvariables {G : Type*} [group G] [fintype G]\n\nvariable (G)\ndef cubedistr_prop : Prop := \u2200 (a b : G), (a * b) ^ 3 = a ^ 3 * b ^ 3\n\nvariable {G}\n\nlemma pow_three (a : G) : a ^ 3 = a * a * a := by group\n\nlemma sq_antihom (cubedistr : cubedistr_prop G) (a b : G) :\n  (a * b) ^ 2 = b ^ 2 * a ^ 2 :=\ncalc (a * b) ^ 2 = a * b * a * b : by {rw pow_two, group}\n... = b\u207b\u00b9 * ((b * a) * (b * a) * (b * a)) * a\u207b\u00b9 : by group\n... = b\u207b\u00b9 * (b * a) ^ 3 * a\u207b\u00b9 : by rw pow_three\n... = b\u207b\u00b9 * (b ^ 3 * a ^ 3) * a\u207b\u00b9 : by rw cubedistr \n... = b ^ 2 * a ^ 2 : by group\n\nlemma sqcube_comm (cubedistr : cubedistr_prop G) (a b : G) :\n  a ^ 2 * b ^ 3 = b ^ 3 * a ^ 2 :=\ncalc a ^ 2 * b ^ 3 = a ^ 2 * b ^ 2 * b * a * a\u207b\u00b9 : by group\n... = (b * a) * (b * a) * (b * a) * a\u207b\u00b9 : by {rw [\u2190sq_antihom cubedistr, pow_two], group}\n... = (b * a) ^ 3 * a\u207b\u00b9 : by rw pow_three\n... = b ^ 3 * a ^ 3 * a\u207b\u00b9 : by rw cubedistr\n... = b ^ 3 * a ^ 2 : by group\n\n-- If G is a finite group such that (xy)^3 = x^3y^3 and 3 \u2224 |G|, then G is abelian.\ntheorem comm_of_cubehom_group (cubedistr : cubedistr_prop G)\n  (hord : \u00ac3 \u2223 fintype.card G) :\n  \u2200 (a b : G), a * b = b * a :=\nbegin\n  set cubehom : G \u2192* G := {\n    to_fun := \u03bb x, x ^ 3,\n    map_one' := by group,\n    map_mul' := cubedistr,\n  } with hcubehom,\n\n  have hinj : function.injective \u21d1cubehom := by {\n    simp_rw [\u2190monoid_hom.ker_eq_bot_iff, subgroup.eq_bot_iff_forall,\n      monoid_hom.mem_ker, hcubehom],\n    intros x hx,\n    by_contra h,\n    exact hord (order_of_eq_prime hx h \u25b8 order_of_dvd_card_univ),\n  },\n  have hsur : function.surjective \u21d1cubehom := fintype.injective_iff_surjective.mp hinj,\n  \n  have sqcomm' : \u2200 (a b : G), a ^ 2 * b = b * a ^ 2 := by {\n    intros a b,\n    obtain \u27e8t, ht\u27e9 := hsur b,\n    dsimp [hcubehom] at ht, subst ht,\n    exact sqcube_comm cubedistr a t,\n  },\n\n  have sqcomm : \u2200 (a b : G), a ^ 2 * b ^ 2 = b ^ 2 * a ^ 2 :=\n    \u03bb a b, calc a ^ 2 * b ^ 2 = a ^ 2 * b * b : by group\n    ... = b * a ^ 2 * b : by rw sqcomm'\n    ... = b * (a ^ 2 * b) : mul_assoc _ _ _\n    ... = b * (b * a ^ 2) : by rw sqcomm'\n    ... = b ^ 2 * a ^ 2 : by group,\n\n  intros a b,\n  calc a * b = a\u207b\u00b9 * (a ^ 2 * b ^ 2) * b\u207b\u00b9 : by group\n  ... = a\u207b\u00b9 * (b ^ 2 * a ^ 2) * b\u207b\u00b9 : by rw sqcomm\n  ... = a\u207b\u00b9 * (a * b) ^ 2 * b\u207b\u00b9 : by rw sq_antihom cubedistr\n  ... = a\u207b\u00b9 * a * b * a * b * b\u207b\u00b9 : by {rw pow_two, group}\n  ... = b * a : by group\nend", "meta": {"author": "greysome", "repo": "lean-practice", "sha": "00729df4b18a2538cd3f63f68ab9c59308e3a6c2", "save_path": "github-repos/lean/greysome-lean-practice", "path": "github-repos/lean/greysome-lean-practice/lean-practice-00729df4b18a2538cd3f63f68ab9c59308e3a6c2/src/new/commofcubedistr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7013108233951261}}
{"text": "-- import the definition of the gcd maze\nimport mazes.gcd_maze.definition\nimport data.int.gcd\nopen maze direction\n\n/-\n\n# Prove Bezout's Theorem\n\nYou are in a maze of integers, all distinct. \n\nYou can go north, south east or west.\n\nNorth adds `a` to your integer, South subtracts `a`.\nEast adds `b` to your integer, West subtracts `b`.\nYou start at 0. The exit is at `nat.gcd a b`.\nCan you prove you can always exit?\n\nSolver remark : there are infinitely many mazes.\n-/\n\n/- Lemma : no-side-bar\nCan you prove you can escape in the general case?\n-/\ntheorem challenge (A B : \u2115) : can_escape A B 0 :=\nbegin\n  have solution : can_escape A B (nat.gcd A B),\n    out,\n  have hs : \u2200 t l : \u2115, can_escape A B t \u2192 can_escape A B (t + l*A),\n  { intros t l,\n    induction l with d hd,\n    { intro h, convert h, simp },\n    intro h,\n    specialize hd h,\n    s,\n    convert hd,\n    ring\n  },\n  have hns : \u2200 t : \u2124, \u2200 l : \u2124, can_escape A B t \u2192 can_escape A B (t + l * A),\n  { intros t l,\n    apply int.induction_on l; clear l,\n    { intro h, convert h, ring},\n    { intros d hd, \n      intro h, specialize hd h,\n      s,\n      convert hd,\n      ring,\n    },\n    { intros d hd, \n      intro h, specialize hd h,\n      n,\n      convert hd using 1,\n      ring,\n    } },\n  have hew : \u2200 t : \u2124, \u2200 m : \u2124, can_escape A B t \u2192 can_escape A B (t + m * B),\n  { intros t l,\n    apply int.induction_on l; clear l,\n    { intro h, convert h, ring},\n    { intros d hd, \n      intro h, specialize hd h,\n      w,\n      convert hd,\n      ring,\n    },\n    { intros d hd, \n      intro h, specialize hd h,\n      e,\n      convert hd using 1,\n      ring,\n    } },\n  suffices : \u2203 L M : \u2124, L * A + M * B = nat.gcd A B,\n  { rcases this with \u27e8L, M, h\u27e9,\n    rw \u2190 h at solution,\n    specialize hew _ (-M) solution,\n    simp at hew,\n    specialize hns _ (-L) hew,\n    convert hns,\n    ring,\n  },\n  have h := nat.gcd_eq_gcd_ab A B,\n  rw h,\n  use [A.gcd_a B, A.gcd_b B],\n  ring,\nend\n\n", "meta": {"author": "kbuzzard", "repo": "lean-game-skeleton", "sha": "098454dd6acc4c06beccf52b6547bf4cd99cc581", "save_path": "github-repos/lean/kbuzzard-lean-game-skeleton", "path": "github-repos/lean/kbuzzard-lean-game-skeleton/lean-game-skeleton-098454dd6acc4c06beccf52b6547bf4cd99cc581/src/mazes/gcd_maze/level_challenge.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.701310811960408}}
{"text": "/-\nCopyright (c) 2018 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport tactic.suggest\nimport ring_theory.principal_ideal_domain\nimport ring_theory.polynomial\n\nopen_locale polynomial\n/- Turn off trace messages so they don't pollute the test build: -/\nset_option trace.silence_library_search true\n\nexample {\u03b1 : Type} [euclidean_domain \u03b1] {S : ideal \u03b1} {x y : \u03b1} (hy : y \u2208 S) : x % y \u2208 S \u2194 x \u2208 S :=\nby library_search -- exact mod_mem_iff hy\n\nvariables {R : Type} [comm_ring R] [decidable_eq R]\nvariables {I : ideal R[X]}\n\nexample {m n : \u2115} (H : m \u2264 n) : I.leading_coeff_nth m \u2264 I.leading_coeff_nth n :=\nby library_search -- exact ideal.leading_coeff_nth_mono I H\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/test/library_search/ring_theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178944582995, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7013108043206119}}
{"text": "/-\nCopyright (c) 2022 Henrik B\u00f6ving. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Henrik B\u00f6ving\n-/\n\nnamespace Cpdt\nnamespace Chapter4\n\ninductive Even : Nat \u2192 Prop where\n  | zero : Even 0\n  | succSucc (n : Nat) : Even n \u2192 Even n.succ.succ\n\ntheorem even4 : Even 4 := by\n  simp[Even.succSucc, Even.zero]\n\ntheorem even_3_contra : Even 3 \u2192 False := by\n  intro h\n  cases h with\n  | succSucc _ h => cases h\n\n\ntheorem even_add : Even n \u2192 Even m \u2192 Even (n + m) := by\n  intro h1\n  induction h1 with\n  | zero =>\n    intro h\n    simp_arith\n    assumption\n  | succSucc x xh ih =>\n    intro h\n    simp_arith\n    constructor\n    simp_arith\n    apply ih\n    assumption\n\ntheorem even_contra_helper : \u2200 n', Even n' \u2192 \u2200 n, n' \u2260 Nat.succ (n + n) := by\n  intro n' hn'\n  induction hn' with\n  | zero => simp_all\n  | succSucc x hx ih =>\n    intro n hn\n    cases x <;> cases n <;> simp_all <;> simp_arith at *\n    case succSucc.succ.succ y m =>\n      apply ih m\n      assumption\n\ntheorem even_contra : Even (Nat.succ (n + n)) \u2192 False := by\n  intro h\n  apply even_contra_helper\n  assumption\n  rfl\n\nend Chapter4\nend Cpdt\n", "meta": {"author": "hargoniX", "repo": "cpdt-lean", "sha": "65896137166a8ef74e816efc187346bc8f8bbd22", "save_path": "github-repos/lean/hargoniX-cpdt-lean", "path": "github-repos/lean/hargoniX-cpdt-lean/cpdt-lean-65896137166a8ef74e816efc187346bc8f8bbd22/Cpdt/Chapter4/RecPred.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7013083041506682}}
{"text": "import float.basic\nimport float.round\n\nopen float\n\nvariable (prec : \u2115)\n\ndef divl (x y : \ud835\udd3d) : \ud835\udd3d :=\nround_down prec (eval x / eval y)\n\ndef divr (x y : \ud835\udd3d) : \ud835\udd3d :=\nround_up prec (eval x / eval y)\n\nmeta def div_rat' (x y : \ud835\udd3d) : \u211a :=\nlet x' := quot.unquot x, y' := quot.unquot y in \nif x'.e \u2264 y'.e\nthen rat.mk (x'.m) (y'.m * 2 ^ int.to_nat (y'.e - x'.e))\nelse rat.mk (x'.m * 2 ^ int.to_nat (x'.e - y'.e)) (y'.m)\n\nmeta def divl' (x y : \ud835\udd3d) : \ud835\udd3d :=\nround_down prec (div_rat' x y)\n\nmeta def divr' (x y : \ud835\udd3d) : \ud835\udd3d :=\nround_up prec (div_rat' x y)\n\n--instance : has_div \ud835\udd3d := \u27e8divl 10\u27e9 -- Fixed precision for now \nmeta instance : has_div \ud835\udd3d := \u27e8divl' 10\u27e9 -- Fixed precision for now \n\n\n-- Lemmas.\n\nlemma divl_bound (x y : \ud835\udd3d) \n: eval (divl prec x y) \u2264 eval x / eval y :=\nbegin \n  simp [divl, round_down, eval_mk], \n  have h : 0 < ((2 : \u211a) ^ prec), { norm_num, },\n  rw [mul_inv_le_iff h, mul_comm], exact floor_le _,\nend \n\nlemma divr_bound (x y : \ud835\udd3d) \n: eval x / eval y \u2264 eval (divr prec x y) :=\nbegin \n  simp [divr, round_up, eval_mk], \n  have h : 0 < ((2 : \u211a) ^ prec), { norm_num, },\n  rw [\u2190mul_le_mul_right h, mul_assoc, inv_mul_cancel (ne_of_gt h), mul_one],\n  exact le_ceil _,\nend \n\nlemma divl_diff_lb (x y : \ud835\udd3d) \n: 0 \u2264 (eval x / eval y) - eval (divl prec x y) :=\nsub_nonneg_of_le (divl_bound prec x y)\n\nlemma divl_diff_ub (x y : \ud835\udd3d) \n: (eval x / eval y) - eval (divl prec x y) \u2264 2 ^ (-(prec : \u2124)) :=\nbegin \n  have h := divr_bound prec x y, \n  replace h := sub_le_sub_right h (eval (divl prec x y)),\n  apply le_trans h, simp only [divr, divl],\n  rw [\u2190eval_sub],\n  have h1 : 2 ^ (-(prec : \u2124)) = eval (float.mk 1 (-prec)),\n  { simp [eval_mk], },\n  rw h1, exact round_up_diff_round_down prec _,\nend \n\n-- #eval divl 10 (mk 50 0) (mk 3 2)\n\n-- Isabelle version:\n-- lift_definition float_divr :: \"nat => float => float => float\" is\n--   \"\u03bb(prec::nat) a b. round_up (prec + \u230a log 2 \u00a6b\u00a6 \u230b - \u230a log 2 \u00a6a\u00a6 \u230b) (a / b)\" by simp\n\n-- TODO: Precision needs to change?\n", "meta": {"author": "ramonfmir", "repo": "leanSOS", "sha": "14b50713dc887f6d408b7b2bce1f8af5bb619958", "save_path": "github-repos/lean/ramonfmir-leanSOS", "path": "github-repos/lean/ramonfmir-leanSOS/leanSOS-14b50713dc887f6d408b7b2bce1f8af5bb619958/lean3SOS/src/float/div.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7013082903558168}}
{"text": "/-\nCopyright (c) 2021 Thomas Browning. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Thomas Browning\n-/\nimport field_theory.abel_ruffini\nimport analysis.calculus.local_extr\nimport ring_theory.eisenstein_criterion\n/-!\nConstruction of an algebraic number that is not solvable by radicals.\n\nThe main ingredients are:\n * `solvable_by_rad.is_solvable'` in `field_theory/abel_ruffini` :\n  an irreducible polynomial with an `is_solvable_by_rad` root has solvable Galois group\n * `gal_action_hom_bijective_of_prime_degree'` in `field_theory/polynomial_galois_group` :\n  an irreducible polynomial of prime degree with 1-3 non-real roots has full Galois group\n * `equiv.perm.not_solvable` in `group_theory/solvable` : the symmetric group is not solvable\n\nThen all that remains is the construction of a specific polynomial satisfying the conditions of\n`gal_action_hom_bijective_of_prime_degree'`, which is done in this file.\n\n-/\n\nnamespace abel_ruffini\n\nopen function polynomial polynomial.gal ideal\n\nlocal attribute [instance] splits_\u211a_\u2102\n\nvariables (R : Type*) [comm_ring R] (a b : \u2115)\n\n/-- A quintic polynomial that we will show is irreducible -/\nnoncomputable def \u03a6 : polynomial R := X ^ 5 - C \u2191a * X + C \u2191b\n\nvariables {R}\n\n@[simp] lemma map_Phi {S : Type*} [comm_ring S] (f : R \u2192+* S) : (\u03a6 R a b).map f = \u03a6 S a b :=\nby simp [\u03a6]\n\n@[simp] lemma coeff_zero_Phi : (\u03a6 R a b).coeff 0 = \u2191b :=\nby simp [\u03a6, coeff_X_pow]\n\n@[simp] lemma coeff_five_Phi : (\u03a6 R a b).coeff 5 = 1 :=\nby simp [\u03a6, coeff_X, coeff_C, -C_eq_nat_cast, -map_nat_cast]\n\nvariables [nontrivial R]\n\nlemma degree_Phi : (\u03a6 R a b).degree = \u21915 :=\nbegin\n  suffices : degree (X ^ 5 - C \u2191a * X) = \u21915,\n  { rwa [\u03a6, degree_add_eq_left_of_degree_lt],\n    convert degree_C_le.trans_lt (with_bot.coe_lt_coe.mpr (nat.zero_lt_bit1 2)) },\n  rw degree_sub_eq_left_of_degree_lt; rw degree_X_pow,\n  exact (degree_C_mul_X_le _).trans_lt (with_bot.coe_lt_coe.mpr (nat.one_lt_bit1 two_ne_zero)),\nend\n\nlemma nat_degree_Phi : (\u03a6 R a b).nat_degree = 5 :=\nnat_degree_eq_of_degree_eq_some (degree_Phi a b)\n\nlemma leading_coeff_Phi : (\u03a6 R a b).leading_coeff = 1 :=\nby rw [polynomial.leading_coeff, nat_degree_Phi, coeff_five_Phi]\n\nlemma monic_Phi : (\u03a6 R a b).monic :=\nleading_coeff_Phi a b\n\nlemma irreducible_Phi (p : \u2115) (hp : p.prime) (hpa : p \u2223 a) (hpb : p \u2223 b) (hp2b : \u00ac p ^ 2 \u2223 b) :\n  irreducible (\u03a6 \u211a a b) :=\nbegin\n  rw [\u2190map_Phi a b (int.cast_ring_hom \u211a), \u2190is_primitive.int.irreducible_iff_irreducible_map_cast],\n  apply irreducible_of_eisenstein_criterion,\n  { rwa [span_singleton_prime (int.coe_nat_ne_zero.mpr hp.ne_zero), int.prime_iff_nat_abs_prime] },\n  { rw [leading_coeff_Phi, mem_span_singleton],\n    exact_mod_cast mt nat.dvd_one.mp (hp.ne_one) },\n  { intros n hn,\n    rw mem_span_singleton,\n    rw [degree_Phi, with_bot.coe_lt_coe] at hn,\n    interval_cases n with hn;\n    simp only [\u03a6, coeff_X_pow, coeff_C, int.coe_nat_dvd.mpr, hpb, if_true, coeff_C_mul, if_false,\n      nat.zero_ne_bit1, eq_self_iff_true, coeff_X_zero, hpa, coeff_add, zero_add, mul_zero,\n      int.nat_cast_eq_coe_nat, coeff_sub, sub_self, nat.one_ne_zero, add_zero, coeff_X_one, mul_one,\n      zero_sub, dvd_neg, nat.one_eq_bit1, bit0_eq_zero, neg_zero, nat.bit0_ne_bit1,\n      dvd_mul_of_dvd_left, nat.bit1_eq_bit1, nat.one_ne_bit0, nat.bit1_ne_zero], },\n  { simp only [degree_Phi, \u2190with_bot.coe_zero, with_bot.coe_lt_coe, nat.succ_pos'] },\n  { rw [coeff_zero_Phi, span_singleton_pow, mem_span_singleton, int.nat_cast_eq_coe_nat],\n    exact mt int.coe_nat_dvd.mp hp2b },\n  all_goals { exact monic.is_primitive (monic_Phi a b) },\nend\n\nlemma real_roots_Phi_le : fintype.card ((\u03a6 \u211a a b).root_set \u211d) \u2264 3 :=\nbegin\n  rw [\u2190map_Phi a b (algebra_map \u2124 \u211a), \u03a6, \u2190one_mul (X ^ 5), \u2190C_1],\n  refine (card_root_set_le_derivative _).trans\n    (nat.succ_le_succ ((card_root_set_le_derivative _).trans (nat.succ_le_succ _))),\n  suffices : ((C ((algebra_map \u2124 \u211a) 20) * X ^ 3).root_set \u211d).subsingleton,\n  { norm_num [fintype.card_le_one_iff_subsingleton, \u2190 mul_assoc, *] at * },\n  rw root_set_C_mul_X_pow; norm_num,\nend\n\nlemma real_roots_Phi_ge_aux (hab : b < a) :\n  \u2203 x y : \u211d, x \u2260 y \u2227 aeval x (\u03a6 \u211a a b) = 0 \u2227 aeval y (\u03a6 \u211a a b) = 0 :=\nbegin\n  let f := \u03bb x : \u211d, aeval x (\u03a6 \u211a a b),\n  have hf : f = \u03bb x, x ^ 5 - a * x + b := by simp [f, \u03a6],\n  have hc : \u2200 s : set \u211d, continuous_on f s := \u03bb s, (\u03a6 \u211a a b).continuous_on_aeval,\n  have ha : (1 : \u211d) \u2264 a := nat.one_le_cast.mpr (nat.one_le_of_lt hab),\n  have hle : (0 : \u211d) \u2264 1 := zero_le_one,\n  have hf0 : 0 \u2264 f 0 := by norm_num [hf],\n  by_cases hb : (1 : \u211d) - a + b < 0,\n  { have hf1 : f 1 < 0 := by norm_num [hf, hb],\n    have hfa : 0 \u2264 f a,\n    { simp_rw [hf, \u2190sq],\n      refine add_nonneg (sub_nonneg.mpr (pow_le_pow ha _)) _; norm_num },\n    obtain \u27e8x, \u27e8-, hx1\u27e9, hx2\u27e9 := intermediate_value_Ico' hle (hc _) (set.mem_Ioc.mpr \u27e8hf1, hf0\u27e9),\n    obtain \u27e8y, \u27e8hy1, -\u27e9, hy2\u27e9 := intermediate_value_Ioc ha (hc _) (set.mem_Ioc.mpr \u27e8hf1, hfa\u27e9),\n    exact \u27e8x, y, (hx1.trans hy1).ne, hx2, hy2\u27e9 },\n  { replace hb : (b : \u211d) = a - 1 := by linarith [show (b : \u211d) + 1 \u2264 a, by exact_mod_cast hab],\n    have hf1 : f 1 = 0 := by norm_num [hf, hb],\n    have hfa := calc f (-a) = a ^ 2 - a ^ 5 + b       : by norm_num [hf, \u2190 sq]\n                        ... \u2264 a ^ 2 - a ^ 3 + (a - 1) : by refine add_le_add (sub_le_sub_left\n                                                            (pow_le_pow ha _) _) _; linarith\n                        ... = -(a - 1) ^ 2 * (a + 1)  : by ring\n                        ... \u2264 0                       : by nlinarith,\n    have ha' := neg_nonpos.mpr (hle.trans ha),\n    obtain \u27e8x, \u27e8-, hx1\u27e9, hx2\u27e9 := intermediate_value_Icc ha' (hc _) (set.mem_Icc.mpr \u27e8hfa, hf0\u27e9),\n    exact \u27e8x, 1, (hx1.trans_lt zero_lt_one).ne, hx2, hf1\u27e9 },\nend\n\nlemma real_roots_Phi_ge (hab : b < a) : 2 \u2264 fintype.card ((\u03a6 \u211a a b).root_set \u211d) :=\nbegin\n  have q_ne_zero : \u03a6 \u211a a b \u2260 0 := (monic_Phi a b).ne_zero,\n  obtain \u27e8x, y, hxy, hx, hy\u27e9 := real_roots_Phi_ge_aux a b hab,\n  have key : \u2191({x, y} : finset \u211d) \u2286 (\u03a6 \u211a a b).root_set \u211d,\n  { simp [set.insert_subset, mem_root_set q_ne_zero, hx, hy] },\n  convert fintype.card_le_of_embedding (set.embedding_of_subset _ _ key),\n  simp only [finset.coe_sort_coe, fintype.card_coe, finset.card_singleton,\n             finset.card_insert_of_not_mem (mt finset.mem_singleton.mp hxy)]\nend\n\nlemma complex_roots_Phi (h : (\u03a6 \u211a a b).separable) : fintype.card ((\u03a6 \u211a a b).root_set \u2102) = 5 :=\n(card_root_set_eq_nat_degree h (is_alg_closed.splits_codomain _)).trans (nat_degree_Phi a b)\n\nlemma gal_Phi (hab : b < a) (h_irred : irreducible (\u03a6 \u211a a b)) :\n  bijective (gal_action_hom (\u03a6 \u211a a b) \u2102) :=\nbegin\n  apply gal_action_hom_bijective_of_prime_degree' h_irred,\n  { norm_num [nat_degree_Phi] },\n  { rw [complex_roots_Phi a b h_irred.separable, nat.succ_le_succ_iff],\n    exact (real_roots_Phi_le a b).trans (nat.le_succ 3) },\n  { simp_rw [complex_roots_Phi a b h_irred.separable, nat.succ_le_succ_iff],\n    exact real_roots_Phi_ge a b hab },\nend\n\ntheorem not_solvable_by_rad (p : \u2115) (x : \u2102) (hx : aeval x (\u03a6 \u211a a b) = 0) (hab : b < a)\n  (hp : p.prime) (hpa : p \u2223 a) (hpb : p \u2223 b) (hp2b : \u00ac p ^ 2 \u2223 b) :\n  \u00ac is_solvable_by_rad \u211a x :=\nbegin\n  have h_irred := irreducible_Phi a b p hp hpa hpb hp2b,\n  apply mt (solvable_by_rad.is_solvable' h_irred hx),\n  introI h,\n  refine equiv.perm.not_solvable _ (le_of_eq _)\n    (solvable_of_surjective (gal_Phi a b hab h_irred).2),\n  rw_mod_cast [cardinal.mk_fintype, complex_roots_Phi a b h_irred.separable],\nend\n\ntheorem not_solvable_by_rad' (x : \u2102) (hx : aeval x (\u03a6 \u211a 4 2) = 0) :\n  \u00ac is_solvable_by_rad \u211a x :=\nby apply not_solvable_by_rad 4 2 2 x hx; norm_num\n\n/-- **Abel-Ruffini Theorem** -/\ntheorem exists_not_solvable_by_rad : \u2203 x : \u2102, is_algebraic \u211a x \u2227 \u00ac is_solvable_by_rad \u211a x :=\nbegin\n  obtain \u27e8x, hx\u27e9 := exists_root_of_splits (algebra_map \u211a \u2102)\n    (is_alg_closed.splits_codomain (\u03a6 \u211a 4 2))\n    (ne_of_eq_of_ne (degree_Phi 4 2) (mt with_bot.coe_eq_coe.mp (nat.bit1_ne_zero 2))),\n  exact \u27e8x, \u27e8\u03a6 \u211a 4 2, (monic_Phi 4 2).ne_zero, hx\u27e9, not_solvable_by_rad' x hx\u27e9,\nend\n\nend abel_ruffini\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/archive/100-theorems-list/16_abel_ruffini.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7013082861389662}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_59\n  (b : \u211d)\n  (h\u2080 : (4:\u211d)^b + 2^3 = 12) :\n  b = 1 :=\nbegin\n  have h\u2081 : (4:\u211d)^b = 4, linarith,\n  by_contradiction h,\n  clear h\u2080,\n  change b \u2260 1 at h,\n  by_cases b\u2080 : b < 1,\n  have key\u2081 : (4:\u211d)^b < (4:\u211d)^(1:\u211d), {\n    apply real.rpow_lt_rpow_of_exponent_lt _ _,\n    linarith,\n    exact b\u2080,\n  },\n  simp at key\u2081,\n  have key\u2082 : (4:\u211d)^b \u2260 (4:\u211d), {\n    exact ne_of_lt key\u2081,\n  },\n  exact h (false.rec (b = 1) (key\u2082 h\u2081)),\n  have key\u2083 : 1 < b, {\n    refine h.symm.le_iff_lt.mp _,\n    exact not_lt.mp b\u2080,\n  },\n  have key\u2084 : (4:\u211d)^(1:\u211d) < (4:\u211d)^b, {\n    apply real.rpow_lt_rpow_of_exponent_lt _ _,\n    linarith,\n    exact key\u2083,\n  },\n  simp at key\u2084,\n  have key\u2082 : (4:\u211d)^b \u2260 (4:\u211d), {\n    rw ne_comm,\n    exact ne_of_lt key\u2084,\n  },\n  exact h (false.rec (b = 1) (key\u2082 h\u2081)),\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p59.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7013082752154061}}
{"text": "-- Simple test.\n\nimport data.real.basic\n\nsection real_tree\n\ninductive real_tree\n| Leaf : \u211d \u2192 real_tree\n| Node : real_tree \u2192 real_tree \u2192 real_tree \n\nopen real_tree\n\n--#print real_tree.rec\n--#print real_tree.cases_on\n\ndef sum_real_tree : real_tree \u2192 \u211d \n| (Leaf r) := r \n| (Node t1 t2) := (sum_real_tree t1) + (sum_real_tree t2)\n\nend real_tree \n\n-- List construction (Nested inductive).\n-- Note: This will change in Lean 4?\n\nsection real_branching_tree\n\ninductive real_branching_tree\n| Leaf : \u211d \u2192 real_branching_tree\n| Node : list real_branching_tree \u2192 real_branching_tree\n\nopen real_branching_tree\n\n--#print real_branching_tree.rec\n--#print real_branching_tree.cases_on\n\n@[elab_as_eliminator] \nprotected def real_branching_tree.cases_on'\n: \u03a0 {C : real_branching_tree \u2192 Sort*} (x : real_branching_tree),\n  (\u03a0 (a : \u211d), C (Leaf a)) \u2192 \n  (\u03a0 (l : list real_branching_tree), C (Node l)) \u2192 \n  C x\n| C (Leaf a) mL mN := mL a \n| C (Node l) mL mN := mN l\n\ndef real_branching_tree.lt : real_branching_tree \u2192 real_branching_tree \u2192 Prop \n| t (Node l) := t \u2208 l\n| t _ := false\n\ninstance : has_lt real_branching_tree := \u27e8real_branching_tree.lt\u27e9\n\n@[simp] lemma real_branching_tree.lt_Node \n(t : real_branching_tree) (l : list real_branching_tree) \n: t < (Node l) \u2194 t \u2208 l :=\nby rw [\u2190real_branching_tree.lt.equations._eqn_2 t l]; refl\n\nlemma real_branching_tree.lt_sizeof (t1 t2 : real_branching_tree) \n: t1 < t2 \u2192 sizeof t1 < sizeof t2 :=\nbegin\n    intro H,\n    cases t2 with r l,\n    { cases H, },\n    { change sizeof t1 < real_branching_tree.sizeof (Node l),\n      rw real_branching_tree.Node.sizeof_spec l,\n      have H1 := (real_branching_tree.lt_Node t1 l).1 H,\n      have H2 := list.sizeof_lt_sizeof_of_mem H1,\n      exact ((nat.one_add (sizeof l)).symm \u25b8 (nat.lt_succ_of_lt H2)), }\nend\n\nlemma real_branching_tree.lt_well_founded : well_founded real_branching_tree.lt :=\n(subrelation.wf real_branching_tree.lt_sizeof) (inv_image.wf _ nat.lt_wf)\n\n@[elab_as_eliminator]\nprotected def real_branching_tree.rec' \n: \u03a0 {C : real_branching_tree \u2192 Sort*},\n  (\u03a0 (a : \u211d), C (Leaf a)) \u2192 \n  (\u03a0 (a : list real_branching_tree), C (Node a)) \u2192 \n  \u03a0 (x : real_branching_tree), C x :=\nbegin\n    intros C m1 m2 x,\n    apply (well_founded.fix real_branching_tree.lt_well_founded),\n    intros y Hy,\n    exact (real_branching_tree.cases_on' y m1 m2),\nend \n\n--def real_branching_tree.sum : real_branching_tree \u2192 \u211d \n--| (Leaf r) := r\n--| (Node l) := list.sum (list.map real_branching_tree.sum l)\n\n-- This is still not good enough. Best we can do:\n\n-- mutual inductive foo, list_foo\n-- with foo : Type\n-- | mk : list_foo -> foo\n-- with list_foo : Type\n-- | nil : list_foo\n-- | cons : foo -> list_foo -> list_foo\n\nend real_branching_tree\n", "meta": {"author": "ramonfmir", "repo": "lean-experiments", "sha": "041c8727bb540fb8d1519c1ad84924d473885c27", "save_path": "github-repos/lean/ramonfmir-lean-experiments", "path": "github-repos/lean/ramonfmir-lean-experiments/lean-experiments-041c8727bb540fb8d1519c1ad84924d473885c27/src/misc/nested_inductive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7012893110392496}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov\n\n! This file was ported from Lean 3 source module measure_theory.measure.ae_disjoint\n! leanprover-community/mathlib commit bc7d81beddb3d6c66f71449c5bc76c38cb77cf9e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.MeasureTheory.Measure.MeasureSpaceDef\n\n/-!\n# Almost everywhere disjoint sets\n\nWe say that sets `s` and `t` are `\u03bc`-a.e. disjoint (see `measure_theory.ae_disjoint`) if their\nintersection has measure zero. This assumption can be used instead of `disjoint` in most theorems in\nmeasure theory.\n-/\n\n\nopen Set Function\n\nnamespace MeasureTheory\n\nvariable {\u03b9 \u03b1 : Type _} {m : MeasurableSpace \u03b1} (\u03bc : Measure \u03b1)\n\n/-- Two sets are said to be `\u03bc`-a.e. disjoint if their intersection has measure zero. -/\ndef AeDisjoint (s t : Set \u03b1) :=\n  \u03bc (s \u2229 t) = 0\n#align measure_theory.ae_disjoint MeasureTheory.AeDisjoint\n\nvariable {\u03bc} {s t u v : Set \u03b1}\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (j \u00abexpr \u2260 \u00bb i) -/\n/-- If `s : \u03b9 \u2192 set \u03b1` is a countable family of pairwise a.e. disjoint sets, then there exists a\nfamily of measurable null sets `t i` such that `s i \\ t i` are pairwise disjoint. -/\ntheorem exists_null_pairwise_disjoint_diff [Countable \u03b9] {s : \u03b9 \u2192 Set \u03b1}\n    (hd : Pairwise (AeDisjoint \u03bc on s)) :\n    \u2203 t : \u03b9 \u2192 Set \u03b1,\n      (\u2200 i, MeasurableSet (t i)) \u2227 (\u2200 i, \u03bc (t i) = 0) \u2227 Pairwise (Disjoint on fun i => s i \\ t i) :=\n  by\n  refine'\n    \u27e8fun i => to_measurable \u03bc (s i \u2229 \u22c3 j \u2208 ({i}\u1d9c : Set \u03b9), s j), fun i =>\n      measurable_set_to_measurable _ _, fun i => _, _\u27e9\n  \u00b7 simp only [measure_to_measurable, inter_Union]\n    exact (measure_bUnion_null_iff <| to_countable _).2 fun j hj => hd (Ne.symm hj)\n  \u00b7 simp only [Pairwise, disjoint_left, on_fun, mem_diff, not_and, and_imp, Classical.not_not]\n    intro i j hne x hi hU hj\n    replace hU : x \u2209 s i \u2229 \u22c3 (j) (_ : j \u2260 i), s j := fun h => hU (subset_to_measurable _ _ h)\n    simp only [mem_inter_iff, mem_Union, not_and, not_exists] at hU\n    exact (hU hi j hne.symm hj).elim\n#align measure_theory.exists_null_pairwise_disjoint_diff MeasureTheory.exists_null_pairwise_disjoint_diff\n\nnamespace AeDisjoint\n\nprotected theorem eq (h : AeDisjoint \u03bc s t) : \u03bc (s \u2229 t) = 0 :=\n  h\n#align measure_theory.ae_disjoint.eq MeasureTheory.AeDisjoint.eq\n\n@[symm]\nprotected theorem symm (h : AeDisjoint \u03bc s t) : AeDisjoint \u03bc t s := by rwa [ae_disjoint, inter_comm]\n#align measure_theory.ae_disjoint.symm MeasureTheory.AeDisjoint.symm\n\nprotected theorem symmetric : Symmetric (AeDisjoint \u03bc) := fun s t h => h.symm\n#align measure_theory.ae_disjoint.symmetric MeasureTheory.AeDisjoint.symmetric\n\nprotected theorem comm : AeDisjoint \u03bc s t \u2194 AeDisjoint \u03bc t s :=\n  \u27e8fun h => h.symm, fun h => h.symm\u27e9\n#align measure_theory.ae_disjoint.comm MeasureTheory.AeDisjoint.comm\n\nprotected theorem Disjoint.aeDisjoint (h : Disjoint s t) : AeDisjoint \u03bc s t := by\n  rw [ae_disjoint, disjoint_iff_inter_eq_empty.1 h, measure_empty]\n#align disjoint.ae_disjoint Disjoint.aeDisjoint\n\nprotected theorem Pairwise.aeDisjoint {f : \u03b9 \u2192 Set \u03b1} (hf : Pairwise (Disjoint on f)) :\n    Pairwise (AeDisjoint \u03bc on f) :=\n  hf.mono fun i j h => h.AeDisjoint\n#align pairwise.ae_disjoint Pairwise.aeDisjoint\n\nprotected theorem Set.PairwiseDisjoint.aeDisjoint {f : \u03b9 \u2192 Set \u03b1} {s : Set \u03b9}\n    (hf : s.PairwiseDisjoint f) : s.Pairwise (AeDisjoint \u03bc on f) :=\n  hf.mono' fun i j h => h.AeDisjoint\n#align set.pairwise_disjoint.ae_disjoint Set.PairwiseDisjoint.aeDisjoint\n\ntheorem monoAe (h : AeDisjoint \u03bc s t) (hu : u \u2264\u1d50[\u03bc] s) (hv : v \u2264\u1d50[\u03bc] t) : AeDisjoint \u03bc u v :=\n  measure_mono_null_ae (hu.inter hv) h\n#align measure_theory.ae_disjoint.mono_ae MeasureTheory.AeDisjoint.monoAe\n\nprotected theorem mono (h : AeDisjoint \u03bc s t) (hu : u \u2286 s) (hv : v \u2286 t) : AeDisjoint \u03bc u v :=\n  h.monoAe hu.EventuallyLE hv.EventuallyLE\n#align measure_theory.ae_disjoint.mono MeasureTheory.AeDisjoint.mono\n\nprotected theorem congr (h : AeDisjoint \u03bc s t) (hu : u =\u1d50[\u03bc] s) (hv : v =\u1d50[\u03bc] t) :\n    AeDisjoint \u03bc u v :=\n  h.monoAe (Filter.EventuallyEq.le hu) (Filter.EventuallyEq.le hv)\n#align measure_theory.ae_disjoint.congr MeasureTheory.AeDisjoint.congr\n\n@[simp]\ntheorem union\u1d62_left_iff [Countable \u03b9] {s : \u03b9 \u2192 Set \u03b1} :\n    AeDisjoint \u03bc (\u22c3 i, s i) t \u2194 \u2200 i, AeDisjoint \u03bc (s i) t := by\n  simp only [ae_disjoint, Union_inter, measure_Union_null_iff]\n#align measure_theory.ae_disjoint.Union_left_iff MeasureTheory.AeDisjoint.union\u1d62_left_iff\n\n@[simp]\ntheorem union\u1d62_right_iff [Countable \u03b9] {t : \u03b9 \u2192 Set \u03b1} :\n    AeDisjoint \u03bc s (\u22c3 i, t i) \u2194 \u2200 i, AeDisjoint \u03bc s (t i) := by\n  simp only [ae_disjoint, inter_Union, measure_Union_null_iff]\n#align measure_theory.ae_disjoint.Union_right_iff MeasureTheory.AeDisjoint.union\u1d62_right_iff\n\n@[simp]\ntheorem union_left_iff : AeDisjoint \u03bc (s \u222a t) u \u2194 AeDisjoint \u03bc s u \u2227 AeDisjoint \u03bc t u := by\n  simp [union_eq_Union, and_comm]\n#align measure_theory.ae_disjoint.union_left_iff MeasureTheory.AeDisjoint.union_left_iff\n\n@[simp]\ntheorem union_right_iff : AeDisjoint \u03bc s (t \u222a u) \u2194 AeDisjoint \u03bc s t \u2227 AeDisjoint \u03bc s u := by\n  simp [union_eq_Union, and_comm]\n#align measure_theory.ae_disjoint.union_right_iff MeasureTheory.AeDisjoint.union_right_iff\n\ntheorem unionLeft (hs : AeDisjoint \u03bc s u) (ht : AeDisjoint \u03bc t u) : AeDisjoint \u03bc (s \u222a t) u :=\n  union_left_iff.mpr \u27e8hs, ht\u27e9\n#align measure_theory.ae_disjoint.union_left MeasureTheory.AeDisjoint.unionLeft\n\ntheorem unionRight (ht : AeDisjoint \u03bc s t) (hu : AeDisjoint \u03bc s u) : AeDisjoint \u03bc s (t \u222a u) :=\n  union_right_iff.2 \u27e8ht, hu\u27e9\n#align measure_theory.ae_disjoint.union_right MeasureTheory.AeDisjoint.unionRight\n\ntheorem diff_ae_eq_left (h : AeDisjoint \u03bc s t) : (s \\ t : Set \u03b1) =\u1d50[\u03bc] s :=\n  @diff_self_inter _ s t \u25b8 diff_null_ae_eq_self h\n#align measure_theory.ae_disjoint.diff_ae_eq_left MeasureTheory.AeDisjoint.diff_ae_eq_left\n\ntheorem diff_ae_eq_right (h : AeDisjoint \u03bc s t) : (t \\ s : Set \u03b1) =\u1d50[\u03bc] t :=\n  h.symm.diff_ae_eq_left\n#align measure_theory.ae_disjoint.diff_ae_eq_right MeasureTheory.AeDisjoint.diff_ae_eq_right\n\ntheorem measure_diff_left (h : AeDisjoint \u03bc s t) : \u03bc (s \\ t) = \u03bc s :=\n  measure_congr h.diff_ae_eq_left\n#align measure_theory.ae_disjoint.measure_diff_left MeasureTheory.AeDisjoint.measure_diff_left\n\ntheorem measure_diff_right (h : AeDisjoint \u03bc s t) : \u03bc (t \\ s) = \u03bc t :=\n  measure_congr h.diff_ae_eq_right\n#align measure_theory.ae_disjoint.measure_diff_right MeasureTheory.AeDisjoint.measure_diff_right\n\n/-- If `s` and `t` are `\u03bc`-a.e. disjoint, then `s \\ u` and `t` are disjoint for some measurable null\nset `u`. -/\ntheorem exists_disjoint_diff (h : AeDisjoint \u03bc s t) :\n    \u2203 u, MeasurableSet u \u2227 \u03bc u = 0 \u2227 Disjoint (s \\ u) t :=\n  \u27e8toMeasurable \u03bc (s \u2229 t), measurableSet_toMeasurable _ _, (measure_toMeasurable _).trans h,\n    disjoint_sdiff_self_left.mono_left fun x hx =>\n      \u27e8hx.1, fun hxt => hx.2 <| subset_toMeasurable _ _ \u27e8hx.1, hxt\u27e9\u27e9\u27e9\n#align measure_theory.ae_disjoint.exists_disjoint_diff MeasureTheory.AeDisjoint.exists_disjoint_diff\n\ntheorem ofNullRight (h : \u03bc t = 0) : AeDisjoint \u03bc s t :=\n  measure_mono_null (inter_subset_right _ _) h\n#align measure_theory.ae_disjoint.of_null_right MeasureTheory.AeDisjoint.ofNullRight\n\ntheorem ofNullLeft (h : \u03bc s = 0) : AeDisjoint \u03bc s t :=\n  (ofNullRight h).symm\n#align measure_theory.ae_disjoint.of_null_left MeasureTheory.AeDisjoint.ofNullLeft\n\nend AeDisjoint\n\ntheorem aeDisjointComplLeft : AeDisjoint \u03bc (s\u1d9c) s :=\n  (@disjoint_compl_left _ _ s).AeDisjoint\n#align measure_theory.ae_disjoint_compl_left MeasureTheory.aeDisjointComplLeft\n\ntheorem aeDisjointComplRight : AeDisjoint \u03bc s (s\u1d9c) :=\n  (@disjoint_compl_right _ _ s).AeDisjoint\n#align measure_theory.ae_disjoint_compl_right MeasureTheory.aeDisjointComplRight\n\nend MeasureTheory\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/MeasureTheory/Measure/AeDisjoint.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7012893091328983}}
{"text": "/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.instances.real\nimport order.filter.archimedean\n\n/-!\n# Convergence of subadditive sequences\n\nA subadditive sequence `u : \u2115 \u2192 \u211d` is a sequence satisfying `u (m + n) \u2264 u m + u n` for all `m, n`.\nWe define this notion as `subadditive u`, and prove in `subadditive.tendsto_lim` that, if `u n / n`\nis bounded below, then it converges to a limit (that we denote by `subadditive.lim` for\nconvenience). This result is known as Fekete's lemma in the literature.\n-/\n\nnoncomputable theory\nopen set filter\nopen_locale topological_space\n\n/-- A real-valued sequence is subadditive if it satisfies the inequality `u (m + n) \u2264 u m + u n`\nfor all `m, n`. -/\ndef subadditive (u : \u2115 \u2192 \u211d) : Prop :=\n\u2200 m n, u (m + n) \u2264 u m + u n\n\nnamespace subadditive\n\nvariables {u : \u2115 \u2192 \u211d} (h : subadditive u)\ninclude h\n\n/-- The limit of a bounded-below subadditive sequence. The fact that the sequence indeed tends to\nthis limit is given in `subadditive.tendsto_lim` -/\n@[irreducible, nolint unused_arguments]\nprotected def lim := Inf ((\u03bb (n : \u2115), u n / n) '' (Ici 1))\n\nlemma lim_le_div (hbdd : bdd_below (range (\u03bb n, u n / n))) {n : \u2115} (hn : n \u2260 0) :\n  h.lim \u2264 u n / n :=\nbegin\n  rw subadditive.lim,\n  apply cInf_le _ _,\n  { rcases hbdd with \u27e8c, hc\u27e9,\n    exact \u27e8c, \u03bb x hx, hc (image_subset_range _ _ hx)\u27e9 },\n  { apply mem_image_of_mem,\n    exact zero_lt_iff.2 hn }\nend\n\nlemma apply_mul_add_le (k n r) : u (k * n + r) \u2264 k * u n + u r :=\nbegin\n  induction k with k IH, { simp only [nat.cast_zero, zero_mul, zero_add] },\n  calc\n  u ((k+1) * n + r)\n      = u (n + (k * n + r)) : by { congr' 1, ring }\n  ... \u2264 u n + u (k * n + r) : h _ _\n  ... \u2264 u n + (k * u n + u r) : add_le_add_left IH _\n  ... = (k+1 : \u2115) * u n + u r : by simp; ring\nend\n\nlemma eventually_div_lt_of_div_lt {L : \u211d} {n : \u2115} (hn : n \u2260 0) (hL : u n / n < L) :\n  \u2200\u1da0 p in at_top, u p / p < L :=\nbegin\n  have I : \u2200 (i : \u2115), 0 < i \u2192 (i : \u211d) \u2260 0,\n  { assume i hi, simp only [hi.ne', ne.def, nat.cast_eq_zero, not_false_iff] },\n  obtain \u27e8w, nw, wL\u27e9 : \u2203 w, u n / n < w \u2227 w < L := exists_between hL,\n  obtain \u27e8x, hx\u27e9 : \u2203 x, \u2200 i < n, u i - i * w \u2264 x,\n  { obtain \u27e8x, hx\u27e9 : bdd_above (\u2191(finset.image (\u03bb i, u i - i * w) (finset.range n))) :=\n      finset.bdd_above _,\n    refine \u27e8x, \u03bb i hi, _\u27e9,\n    simp only [upper_bounds, mem_image, and_imp, forall_exists_index, mem_set_of_eq,\n      forall_apply_eq_imp_iff\u2082, finset.mem_range, finset.mem_coe, finset.coe_image] at hx,\n    exact hx _ hi },\n  have A : \u2200 (p : \u2115), u p \u2264 p * w + x,\n  { assume p,\n    let s := p / n,\n    let r := p % n,\n    have hp : p = s * n + r, by rw [mul_comm, nat.div_add_mod],\n    calc u p = u (s * n + r) : by rw hp\n    ... \u2264 s * u n + u r : h.apply_mul_add_le _ _ _\n    ... = s * n * (u n / n) + u r : by { field_simp [I _ hn.bot_lt], ring }\n    ... \u2264 s * n * w + u r : add_le_add_right\n      (mul_le_mul_of_nonneg_left nw.le (mul_nonneg (nat.cast_nonneg _) (nat.cast_nonneg _))) _\n    ... = (s * n + r) * w + (u r - r * w) : by ring\n    ... = p * w + (u r - r * w) : by { rw hp, simp only [nat.cast_add, nat.cast_mul] }\n    ... \u2264 p * w + x : add_le_add_left (hx _ (nat.mod_lt _ hn.bot_lt)) _ },\n  have B : \u2200\u1da0 p in at_top, u p / p \u2264 w + x / p,\n  { refine eventually_at_top.2 \u27e81, \u03bb p hp, _\u27e9,\n    simp only [I p hp, ne.def, not_false_iff] with field_simps,\n    refine div_le_div_of_le_of_nonneg _ (nat.cast_nonneg _),\n    rw mul_comm,\n    exact A _ },\n  have C : \u2200\u1da0 (p : \u2115) in at_top, w + x / p < L,\n  { have : tendsto (\u03bb (p : \u2115), w + x / p) at_top (\ud835\udcdd (w + 0)) :=\n      tendsto_const_nhds.add (tendsto_const_nhds.div_at_top tendsto_coe_nat_at_top_at_top),\n    rw add_zero at this,\n    exact (tendsto_order.1 this).2 _ wL },\n  filter_upwards [B, C] with _ hp h'p using hp.trans_lt h'p,\nend\n\n/-- Fekete's lemma: a subadditive sequence which is bounded below converges. -/\ntheorem tendsto_lim (hbdd : bdd_below (range (\u03bb n, u n / n))) :\n  tendsto (\u03bb n, u n / n) at_top (\ud835\udcdd h.lim) :=\nbegin\n  refine tendsto_order.2 \u27e8\u03bb l hl, _, \u03bb L hL, _\u27e9,\n  { refine eventually_at_top.2\n      \u27e81, \u03bb n hn, hl.trans_le (h.lim_le_div hbdd ((zero_lt_one.trans_le hn).ne'))\u27e9 },\n  { obtain \u27e8n, npos, hn\u27e9 : \u2203 (n : \u2115), 0 < n \u2227 u n / n < L,\n    { rw subadditive.lim at hL,\n      rcases exists_lt_of_cInf_lt (by simp) hL with \u27e8x, hx, xL\u27e9,\n      rcases (mem_image _ _ _).1 hx with \u27e8n, hn, rfl\u27e9,\n      exact \u27e8n, zero_lt_one.trans_le hn, xL\u27e9 },\n    exact h.eventually_div_lt_of_div_lt npos.ne' hn }\nend\n\nend subadditive\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/analysis/subadditive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7012893004411908}}
{"text": "/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_342\n  (a d: \u211d)\n  (h\u2080 : \u2211 k in (finset.range 5), (a + k * d) = 70)\n  (h\u2081 : \u2211 k in (finset.range 10), (a + k * d) = 210) :\n  a = 42/5 :=\nbegin\n  revert h\u2080 h\u2081,\n  simp [finset.sum_range_succ, mul_comm d],\n  intros,\n  linarith,\nend", "meta": {"author": "leanprover-community", "repo": "mathzoo", "sha": "87e9b492daeb929838706942aaa2437621b34a0e", "save_path": "github-repos/lean/leanprover-community-mathzoo", "path": "github-repos/lean/leanprover-community-mathzoo/mathzoo-87e9b492daeb929838706942aaa2437621b34a0e/src/mathzoo/olympiads/mathd/algebra/p342.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7012604355024175}}
{"text": "/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn\n-/\nprelude\nimport init.datatypes init.reserved_notation init.tactic\n\ndefinition id [reducible] [unfold_full] {A : Type} (a : A) : A :=\na\n\n/- implication -/\n\ndefinition implies (a b : Prop) := a \u2192 b\n\nlemma implies.trans [trans] {p q r : Prop} (h\u2081 : implies p q) (h\u2082 : implies q r) : implies p r :=\nassume hp, h\u2082 (h\u2081 hp)\n\ndefinition trivial := true.intro\n\ndefinition not (a : Prop) := a \u2192 false\nprefix `\u00ac` := not\n\ndefinition absurd {a : Prop} {b : Type} (H1 : a) (H2 : \u00aca) : b :=\nfalse.rec b (H2 H1)\n\nlemma not.intro [intro!] {a : Prop} (H : a \u2192 false) : \u00ac a :=\nH\n\ntheorem mt {a b : Prop} (H1 : a \u2192 b) (H2 : \u00acb) : \u00aca :=\nassume Ha : a, absurd (H1 Ha) H2\n\ndefinition implies.resolve {a b : Prop} (H : a \u2192 b) (nb : \u00ac b) : \u00ac a := assume Ha, nb (H Ha)\n\n/- not -/\n\ntheorem not_false : \u00acfalse :=\nassume H : false, H\n\ndefinition non_contradictory (a : Prop) : Prop := \u00ac\u00aca\n\ntheorem non_contradictory_intro {a : Prop} (Ha : a) : \u00ac\u00aca :=\nassume Hna : \u00aca, absurd Ha Hna\n\n/- false -/\n\ntheorem false.elim {c : Prop} (H : false) : c :=\nfalse.rec c H\n\n\n/- eq -/\n\nnotation a = b := eq a b\ndefinition rfl {A : Type} {a : A} : a = a := eq.refl a\n\ndefinition id.def [defeq] {A : Type} (a : A) : id a = a := rfl\n\n-- proof irrelevance is built in\ntheorem proof_irrel {a : Prop} (H\u2081 H\u2082 : a) : H\u2081 = H\u2082 :=\nrfl\n\n-- Remark: we provide the universe levels explicitly to make sure `eq.drec` has the same type of `eq.rec` in the HoTT library\nprotected theorem eq.drec.{l\u2081 l\u2082} {A : Type.{l\u2082}} {a : A} {C : \u03a0 (x : A), a = x \u2192 Type.{l\u2081}} (h\u2081 : C a (eq.refl a)) {b : A} (h\u2082 : a = b) : C b h\u2082 :=\neq.rec (\u03bbh\u2082 : a = a, show C a h\u2082, from h\u2081) h\u2082 h\u2082\n\nnamespace eq\n  variables {A : Type}\n  variables {a b c a': A}\n\n  protected theorem drec_on {a : A} {C : \u03a0 (x : A), a = x \u2192 Type} {b : A} (h\u2082 : a = b) (h\u2081 : C a (refl a)) : C b h\u2082 :=\n  eq.drec h\u2081 h\u2082\n\n  theorem subst {P : A \u2192 Prop} (H\u2081 : a = b) (H\u2082 : P a) : P b :=\n  eq.rec H\u2082 H\u2081\n\n  theorem trans (H\u2081 : a = b) (H\u2082 : b = c) : a = c :=\n  subst H\u2082 H\u2081\n\n  theorem symm : a = b \u2192 b = a :=\n  eq.rec (refl a)\n\n  theorem substr {P : A \u2192 Prop} (H\u2081 : b = a) : P a \u2192 P b :=\n  subst (symm H\u2081)\n\n  theorem mp {a b : Type} : (a = b) \u2192 a \u2192 b :=\n  eq.rec_on\n\n  theorem mpr {a b : Type} : (a = b) \u2192 b \u2192 a :=\n  assume H\u2081 H\u2082, eq.rec_on (eq.symm H\u2081) H\u2082\n\n  namespace ops\n    notation H `\u207b\u00b9` := symm H --input with \\sy or \\-1 or \\inv\n    notation H1 \u2b1d H2 := trans H1 H2\n    notation H1 \u25b8 H2 := subst H1 H2\n    notation H1 \u25b9 H2 := eq.rec H2 H1\n  end ops\nend eq\n\ntheorem congr {A B : Type} {f\u2081 f\u2082 : A \u2192 B} {a\u2081 a\u2082 : A} (H\u2081 : f\u2081 = f\u2082) (H\u2082 : a\u2081 = a\u2082) : f\u2081 a\u2081 = f\u2082 a\u2082 :=\neq.subst H\u2081 (eq.subst H\u2082 rfl)\n\ntheorem congr_fun {A : Type} {B : A \u2192 Type} {f g : \u03a0 x, B x} (H : f = g) (a : A) : f a = g a :=\neq.subst H (eq.refl (f a))\n\ntheorem congr_arg {A B : Type} {a\u2081 a\u2082 : A} (f : A \u2192 B) : a\u2081 = a\u2082 \u2192 f a\u2081 = f a\u2082 :=\ncongr rfl\n\nsection\n  variables {A : Type} {a b c: A}\n  open eq.ops\n\n  theorem trans_rel_left (R : A \u2192 A \u2192 Prop) (H\u2081 : R a b) (H\u2082 : b = c) : R a c :=\n  H\u2082 \u25b8 H\u2081\n\n  theorem trans_rel_right (R : A \u2192 A \u2192 Prop) (H\u2081 : a = b) (H\u2082 : R b c) : R a c :=\n  H\u2081\u207b\u00b9 \u25b8 H\u2082\nend\n\nsection\n  variable {p : Prop}\n  open eq.ops\n\n  theorem of_eq_true (H : p = true) : p :=\n  H\u207b\u00b9 \u25b8 trivial\n\n  theorem not_of_eq_false (H : p = false) : \u00acp :=\n  assume Hp, H \u25b8 Hp\nend\n\nattribute eq.subst [subst]\nattribute eq.refl [refl]\nattribute eq.trans [trans]\nattribute eq.symm [symm]\n\ndefinition cast {A B : Type} (H : A = B) (a : A) : B :=\neq.rec a H\n\ntheorem cast_proof_irrel {A B : Type} (H\u2081 H\u2082 : A = B) (a : A) : cast H\u2081 a = cast H\u2082 a :=\nrfl\n\ntheorem cast_eq {A : Type} (H : A = A) (a : A) : cast H a = a :=\nrfl\n\n/- ne -/\n\ndefinition ne [reducible] {A : Type} (a b : A) := \u00ac(a = b)\ndefinition ne.def [defeq] {A : Type} (a b : A) : ne a b = \u00ac (a = b) := rfl\nnotation a \u2260 b := ne a b\n\nnamespace ne\n  open eq.ops\n  variable {A : Type}\n  variables {a b : A}\n\n  theorem intro (H : a = b \u2192 false) : a \u2260 b := H\n\n  theorem elim (H : a \u2260 b) : a = b \u2192 false := H\n\n  theorem irrefl (H : a \u2260 a) : false := H rfl\n\n  theorem symm (H : a \u2260 b) : b \u2260 a :=\n  assume (H\u2081 : b = a), H (H\u2081\u207b\u00b9)\nend ne\n\ntheorem false_of_ne {A : Type} {a : A} : a \u2260 a \u2192 false := ne.irrefl\n\nsection\n  open eq.ops\n  variables {p : Prop}\n\n  theorem ne_false_of_self : p \u2192 p \u2260 false :=\n  assume (Hp : p) (Heq : p = false), Heq \u25b8 Hp\n\n  theorem ne_true_of_not : \u00acp \u2192 p \u2260 true :=\n  assume (Hnp : \u00acp) (Heq : p = true), (Heq \u25b8 Hnp) trivial\n\n  theorem true_ne_false : \u00actrue = false :=\n  ne_false_of_self trivial\nend\n\ninfixl ` == `:50 := heq\n\nsection\nuniverse variable u\nvariables {A B C : Type.{u}} {a a' : A} {b b' : B} {c : C}\n\ntheorem eq_of_heq (H : a == a') : a = a' :=\nhave H\u2081 : \u2200 (Ht : A = A), eq.rec a Ht = a, from\n  \u03bb Ht, eq.refl a,\nheq.rec H\u2081 H (eq.refl A)\n\ntheorem heq.elim {A : Type} {a : A} {P : A \u2192 Type} {b : A} (H\u2081 : a == b)\n: P a \u2192 P b := eq.rec_on (eq_of_heq H\u2081)\n\ntheorem heq.subst {P : \u2200T : Type, T \u2192 Prop} : a == b \u2192 P A a \u2192 P B b :=\nheq.rec_on\n\ntheorem heq.symm (H : a == b) : b == a :=\nheq.rec_on H (heq.refl a)\n\ntheorem heq_of_eq (H : a = a') : a == a' :=\neq.subst H (heq.refl a)\n\ntheorem heq.trans (H\u2081 : a == b) (H\u2082 : b == c) : a == c :=\nheq.subst H\u2082 H\u2081\n\ntheorem heq_of_heq_of_eq (H\u2081 : a == b) (H\u2082 : b = b') : a == b' :=\nheq.trans H\u2081 (heq_of_eq H\u2082)\n\ntheorem heq_of_eq_of_heq (H\u2081 : a = a') (H\u2082 : a' == b) : a == b :=\nheq.trans (heq_of_eq H\u2081) H\u2082\n\ndefinition type_eq_of_heq (H : a == b) : A = B :=\nheq.rec_on H (eq.refl A)\nend\n\nopen eq.ops\ntheorem eq_rec_heq {A : Type} {P : A \u2192 Type} {a a' : A} (H : a = a') (p : P a) : H \u25b9 p == p :=\neq.drec_on H !heq.refl\n\ntheorem heq_of_eq_rec_left {A : Type} {P : A \u2192 Type} : \u2200 {a a' : A} {p\u2081 : P a} {p\u2082 : P a'} (e : a = a') (h\u2082 : e \u25b9 p\u2081 = p\u2082), p\u2081 == p\u2082\n| a a p\u2081 p\u2082 (eq.refl a) h := eq.rec_on h !heq.refl\n\ntheorem heq_of_eq_rec_right {A : Type} {P : A \u2192 Type} : \u2200 {a a' : A} {p\u2081 : P a} {p\u2082 : P a'} (e : a' = a) (h\u2082 : p\u2081 = e \u25b9 p\u2082), p\u2081 == p\u2082\n| a a p\u2081 p\u2082 (eq.refl a) h := eq.rec_on h !heq.refl\n\ntheorem of_heq_true {a : Prop} (H : a == true) : a :=\nof_eq_true (eq_of_heq H)\n\ntheorem eq_rec_compose : \u2200 {A B C : Type} (p\u2081 : B = C) (p\u2082 : A = B) (a : A), p\u2081 \u25b9 (p\u2082 \u25b9 a : B) = (p\u2082 \u2b1d p\u2081) \u25b9 a\n| A A A (eq.refl A) (eq.refl A) a := calc\n  eq.refl A \u25b9 eq.refl A \u25b9 a = eq.refl A \u25b9 a              : rfl\n            ...             = (eq.refl A \u2b1d eq.refl A) \u25b9 a : {proof_irrel (eq.refl A) (eq.refl A \u2b1d eq.refl A)}\n\ntheorem eq_rec_eq_eq_rec {A\u2081 A\u2082 : Type} {p : A\u2081 = A\u2082} : \u2200 {a\u2081 : A\u2081} {a\u2082 : A\u2082}, p \u25b9 a\u2081 = a\u2082 \u2192 a\u2081 = p\u207b\u00b9 \u25b9 a\u2082 :=\neq.drec_on p (\u03bb a\u2081 a\u2082 h, eq.drec_on h rfl)\n\ntheorem eq_rec_of_heq_left : \u2200 {A\u2081 A\u2082 : Type} {a\u2081 : A\u2081} {a\u2082 : A\u2082} (h : a\u2081 == a\u2082), type_eq_of_heq h \u25b9 a\u2081 = a\u2082\n| A A a a (heq.refl a) := rfl\n\ntheorem eq_rec_of_heq_right {A\u2081 A\u2082 : Type} {a\u2081 : A\u2081} {a\u2082 : A\u2082} (h : a\u2081 == a\u2082) : a\u2081 = (type_eq_of_heq h)\u207b\u00b9 \u25b9 a\u2082 :=\neq_rec_eq_eq_rec (eq_rec_of_heq_left h)\n\nattribute heq.refl [refl]\nattribute heq.trans [trans]\nattribute heq_of_heq_of_eq [trans]\nattribute heq_of_eq_of_heq [trans]\nattribute heq.symm [symm]\n\ntheorem cast_heq : \u2200 {A B : Type} (H : A = B) (a : A), cast H a == a\n| A A (eq.refl A) a := !heq.refl\n\n/- and -/\n\nnotation a /\\ b := and a b\nnotation a \u2227 b  := and a b\n\nvariables {a b c d : Prop}\n\nattribute and.rec [elim]\nattribute and.intro [intro!]\n\ntheorem and.elim (H\u2081 : a \u2227 b) (H\u2082 : a \u2192 b \u2192 c) : c :=\nand.rec H\u2082 H\u2081\n\ntheorem and.swap : a \u2227 b \u2192 b \u2227 a :=\nand.rec (\u03bbHa Hb, and.intro Hb Ha)\n\n/- or -/\n\nnotation a \\/ b := or a b\nnotation a \u2228 b := or a b\n\nattribute or.rec [elim]\n\nnamespace or\n  theorem elim (H\u2081 : a \u2228 b) (H\u2082 : a \u2192 c) (H\u2083 : b \u2192 c) : c :=\n  or.rec H\u2082 H\u2083 H\u2081\nend or\n\ntheorem non_contradictory_em (a : Prop) : \u00ac\u00ac(a \u2228 \u00aca) :=\nassume not_em : \u00ac(a \u2228 \u00aca),\n  have neg_a : \u00aca, from\n    assume pos_a : a, absurd (or.inl pos_a) not_em,\n  absurd (or.inr neg_a) not_em\n\ntheorem or.swap : a \u2228 b \u2192 b \u2228 a := or.rec or.inr or.inl\n\n/- iff -/\n\ndefinition iff (a b : Prop) := (a \u2192 b) \u2227 (b \u2192 a)\n\nnotation a <-> b := iff a b\nnotation a \u2194 b := iff a b\n\ntheorem iff.intro : (a \u2192 b) \u2192 (b \u2192 a) \u2192 (a \u2194 b) := and.intro\n\nattribute iff.intro [intro!]\n\ntheorem iff.elim : ((a \u2192 b) \u2192 (b \u2192 a) \u2192 c) \u2192 (a \u2194 b) \u2192 c := and.rec\n\nattribute iff.elim [recursor 5] [elim]\n\ntheorem iff.elim_left : (a \u2194 b) \u2192 a \u2192 b := and.left\n\ndefinition iff.mp := @iff.elim_left\n\ntheorem iff.elim_right : (a \u2194 b) \u2192 b \u2192 a := and.right\n\ndefinition iff.mpr := @iff.elim_right\n\ntheorem iff.refl [refl] (a : Prop) : a \u2194 a :=\niff.intro (assume H, H) (assume H, H)\n\ntheorem iff.rfl {a : Prop} : a \u2194 a :=\niff.refl a\n\ntheorem iff.trans [trans] (H\u2081 : a \u2194 b) (H\u2082 : b \u2194 c) : a \u2194 c :=\niff.intro\n  (assume Ha, iff.mp H\u2082 (iff.mp H\u2081 Ha))\n  (assume Hc, iff.mpr H\u2081 (iff.mpr H\u2082 Hc))\n\ntheorem iff.symm [symm] (H : a \u2194 b) : b \u2194 a :=\niff.intro (iff.elim_right H) (iff.elim_left H)\n\ntheorem iff.comm : (a \u2194 b) \u2194 (b \u2194 a) :=\niff.intro iff.symm iff.symm\n\ntheorem iff.of_eq {a b : Prop} (H : a = b) : a \u2194 b :=\neq.rec_on H iff.rfl\n\ntheorem not_iff_not_of_iff (H\u2081 : a \u2194 b) : \u00aca \u2194 \u00acb :=\niff.intro\n (assume (Hna : \u00ac a) (Hb : b), Hna (iff.elim_right H\u2081 Hb))\n (assume (Hnb : \u00ac b) (Ha : a), Hnb (iff.elim_left H\u2081 Ha))\n\ntheorem of_iff_true (H : a \u2194 true) : a :=\niff.mp (iff.symm H) trivial\n\ntheorem not_of_iff_false : (a \u2194 false) \u2192 \u00aca := iff.mp\n\ntheorem iff_true_intro (H : a) : a \u2194 true :=\niff.intro\n  (\u03bb Hl, trivial)\n  (\u03bb Hr, H)\n\ntheorem iff_false_intro (H : \u00aca) : a \u2194 false :=\niff.intro H !false.rec\n\ntheorem not_non_contradictory_iff_absurd (a : Prop) : \u00ac\u00ac\u00aca \u2194 \u00aca :=\niff.intro\n  (\u03bb (Hl : \u00ac\u00ac\u00aca) (Ha : a), Hl (non_contradictory_intro Ha))\n  absurd\n\ntheorem imp_congr [congr] (H1 : a \u2194 c) (H2 : b \u2194 d) : (a \u2192 b) \u2194 (c \u2192 d) :=\niff.intro\n  (\u03bbHab Hc, iff.mp H2 (Hab (iff.mpr H1 Hc)))\n  (\u03bbHcd Ha, iff.mpr H2 (Hcd (iff.mp H1 Ha)))\n\ntheorem imp_congr_right (H : a \u2192 (b \u2194 c)) : (a \u2192 b) \u2194 (a \u2192 c) :=\niff.intro\n  (take Hab Ha, iff.elim_left (H Ha) (Hab Ha))\n  (take Hab Ha, iff.elim_right (H Ha) (Hab Ha))\n\ntheorem not_not_intro (Ha : a) : \u00ac\u00aca :=\nassume Hna : \u00aca, Hna Ha\n\ntheorem not_of_not_not_not (H : \u00ac\u00ac\u00aca) : \u00aca :=\n\u03bb Ha, absurd (not_not_intro Ha) H\n\ntheorem not_true [simp] : (\u00ac true) \u2194 false :=\niff_false_intro (not_not_intro trivial)\n\ntheorem not_false_iff [simp] : (\u00ac false) \u2194 true :=\niff_true_intro not_false\n\ntheorem not_congr [congr] (H : a \u2194 b) : \u00aca \u2194 \u00acb :=\niff.intro (\u03bb H\u2081 H\u2082, H\u2081 (iff.mpr H H\u2082)) (\u03bb H\u2081 H\u2082, H\u2081 (iff.mp H H\u2082))\n\ntheorem ne_self_iff_false [simp] {A : Type} (a : A) : (not (a = a)) \u2194 false :=\niff.intro false_of_ne false.elim\n\ntheorem eq_self_iff_true [simp] {A : Type} (a : A) : (a = a) \u2194 true :=\niff_true_intro rfl\n\ntheorem heq_self_iff_true [simp] {A : Type} (a : A) : (a == a) \u2194 true :=\niff_true_intro (heq.refl a)\n\ntheorem iff_not_self [simp] (a : Prop) : (a \u2194 \u00aca) \u2194 false :=\niff_false_intro (\u03bb H,\n   have H' : \u00aca, from (\u03bb Ha, (iff.mp H Ha) Ha),\n   H' (iff.mpr H H'))\n\ntheorem not_iff_self [simp] (a : Prop) : (\u00aca \u2194 a) \u2194 false :=\niff_false_intro (\u03bb H,\n   have H' : \u00aca, from (\u03bb Ha, (iff.mpr H Ha) Ha),\n   H' (iff.mp H H'))\n\ntheorem true_iff_false [simp] : (true \u2194 false) \u2194 false :=\niff_false_intro (\u03bb H, iff.mp H trivial)\n\ntheorem false_iff_true [simp] : (false \u2194 true) \u2194 false :=\niff_false_intro (\u03bb H, iff.mpr H trivial)\n\ntheorem false_of_true_iff_false : (true \u2194 false) \u2192 false :=\nassume H, iff.mp H trivial\n\n/- and simp rules -/\ntheorem and.imp (H\u2082 : a \u2192 c) (H\u2083 : b \u2192 d) : a \u2227 b \u2192 c \u2227 d :=\nand.rec (\u03bbHa Hb, and.intro (H\u2082 Ha) (H\u2083 Hb))\n\ntheorem and_congr [congr] (H1 : a \u2194 c) (H2 : b \u2194 d) : (a \u2227 b) \u2194 (c \u2227 d) :=\niff.intro (and.imp (iff.mp H1) (iff.mp H2)) (and.imp (iff.mpr H1) (iff.mpr H2))\n\ntheorem and_congr_right (H : a \u2192 (b \u2194 c)) : (a \u2227 b) \u2194 (a \u2227 c) :=\niff.intro\n  (take Hab, obtain `a` `b`, from Hab, and.intro `a` (iff.elim_left (H `a`) `b`))\n  (take Hac, obtain `a` `c`, from Hac, and.intro `a` (iff.elim_right (H `a`) `c`))\n\ntheorem and.comm [simp] : a \u2227 b \u2194 b \u2227 a :=\niff.intro and.swap and.swap\n\ntheorem and.assoc [simp] : (a \u2227 b) \u2227 c \u2194 a \u2227 (b \u2227 c) :=\niff.intro\n  (and.rec (\u03bb H' Hc, and.rec (\u03bb Ha Hb, and.intro Ha (and.intro Hb Hc)) H'))\n  (and.rec (\u03bb Ha, and.rec (\u03bb Hb Hc, and.intro (and.intro Ha Hb) Hc)))\n\ntheorem and.left_comm [simp] : a \u2227 (b \u2227 c) \u2194 b \u2227 (a \u2227 c) :=\niff.trans (iff.symm !and.assoc) (iff.trans (and_congr !and.comm !iff.refl) !and.assoc)\n\ntheorem and_iff_left {a b : Prop} (Hb : b) : (a \u2227 b) \u2194 a :=\niff.intro and.left (\u03bbHa, and.intro Ha Hb)\n\ntheorem and_iff_right {a b : Prop} (Ha : a) : (a \u2227 b) \u2194 b :=\niff.intro and.right (and.intro Ha)\n\ntheorem and_true [simp] (a : Prop) : a \u2227 true \u2194 a :=\nand_iff_left trivial\n\ntheorem true_and [simp] (a : Prop) : true \u2227 a \u2194 a :=\nand_iff_right trivial\n\ntheorem and_false [simp] (a : Prop) : a \u2227 false \u2194 false :=\niff_false_intro and.right\n\ntheorem false_and [simp] (a : Prop) : false \u2227 a \u2194 false :=\niff_false_intro and.left\n\ntheorem not_and_self [simp] (a : Prop) : (\u00aca \u2227 a) \u2194 false :=\niff_false_intro (\u03bb H, and.elim H (\u03bb H\u2081 H\u2082, absurd H\u2082 H\u2081))\n\ntheorem and_not_self [simp] (a : Prop) : (a \u2227 \u00aca) \u2194 false :=\niff_false_intro (\u03bb H, and.elim H (\u03bb H\u2081 H\u2082, absurd H\u2081 H\u2082))\n\ntheorem and_self [simp] (a : Prop) : a \u2227 a \u2194 a :=\niff.intro and.left (assume H, and.intro H H)\n\n/- or simp rules -/\n\ntheorem or.imp (H\u2082 : a \u2192 c) (H\u2083 : b \u2192 d) : a \u2228 b \u2192 c \u2228 d :=\nor.rec (\u03bb H, or.inl (H\u2082 H)) (\u03bb H, or.inr (H\u2083 H))\n\ntheorem or.imp_left (H : a \u2192 b) : a \u2228 c \u2192 b \u2228 c :=\nor.imp H id\n\ntheorem or.imp_right (H : a \u2192 b) : c \u2228 a \u2192 c \u2228 b :=\nor.imp id H\n\ntheorem or_congr [congr] (H1 : a \u2194 c) (H2 : b \u2194 d) : (a \u2228 b) \u2194 (c \u2228 d) :=\niff.intro (or.imp (iff.mp H1) (iff.mp H2)) (or.imp (iff.mpr H1) (iff.mpr H2))\n\ntheorem or.comm [simp] : a \u2228 b \u2194 b \u2228 a := iff.intro or.swap or.swap\n\ntheorem or.assoc [simp] : (a \u2228 b) \u2228 c \u2194 a \u2228 (b \u2228 c) :=\niff.intro\n  (or.rec (or.imp_right or.inl) (\u03bb H, or.inr (or.inr H)))\n  (or.rec (\u03bb H, or.inl (or.inl H)) (or.imp_left or.inr))\n\ntheorem or.left_comm [simp] : a \u2228 (b \u2228 c) \u2194 b \u2228 (a \u2228 c) :=\niff.trans (iff.symm !or.assoc) (iff.trans (or_congr !or.comm !iff.refl) !or.assoc)\n\ntheorem or_true [simp] (a : Prop) : a \u2228 true \u2194 true :=\niff_true_intro (or.inr trivial)\n\ntheorem true_or [simp] (a : Prop) : true \u2228 a \u2194 true :=\niff_true_intro (or.inl trivial)\n\ntheorem or_false [simp] (a : Prop) : a \u2228 false \u2194 a :=\niff.intro (or.rec id false.elim) or.inl\n\ntheorem false_or [simp] (a : Prop) : false \u2228 a \u2194 a :=\niff.trans or.comm !or_false\n\ntheorem or_self [simp] (a : Prop) : a \u2228 a \u2194 a :=\niff.intro (or.rec id id) or.inl\n\n/- or resolution rulse -/\n\ndefinition or.resolve_left {a b : Prop} (H : a \u2228 b) (na : \u00ac a) : b :=\n  or.elim H (\u03bb Ha, absurd Ha na) id\n\ndefinition or.neg_resolve_left {a b : Prop} (H : \u00ac a \u2228 b) (Ha : a) : b :=\n  or.elim H (\u03bb na, absurd Ha na) id\n\ndefinition or.resolve_right {a b : Prop} (H : a \u2228 b) (nb : \u00ac b) : a :=\n  or.elim H id (\u03bb Hb, absurd Hb nb)\n\ndefinition or.neg_resolve_right {a b : Prop} (H : a \u2228 \u00ac b) (Hb : b) : a :=\n  or.elim H id (\u03bb nb, absurd Hb nb)\n\n/- iff simp rules -/\n\ntheorem iff_true [simp] (a : Prop) : (a \u2194 true) \u2194 a :=\niff.intro (assume H, iff.mpr H trivial) iff_true_intro\n\ntheorem true_iff [simp] (a : Prop) : (true \u2194 a) \u2194 a :=\niff.trans iff.comm !iff_true\n\ntheorem iff_false [simp] (a : Prop) : (a \u2194 false) \u2194 \u00ac a :=\niff.intro and.left iff_false_intro\n\ntheorem false_iff [simp] (a : Prop) : (false \u2194 a) \u2194 \u00ac a :=\niff.trans iff.comm !iff_false\n\ntheorem iff_self [simp] (a : Prop) : (a \u2194 a) \u2194 true :=\niff_true_intro iff.rfl\n\ntheorem iff_congr [congr] (H1 : a \u2194 c) (H2 : b \u2194 d) : (a \u2194 b) \u2194 (c \u2194 d) :=\nand_congr (imp_congr H1 H2) (imp_congr H2 H1)\n\n/- exists -/\n\ninductive Exists {A : Type} (P : A \u2192 Prop) : Prop :=\nintro : \u2200 (a : A), P a \u2192 Exists P\n\nattribute Exists.intro [intro]\n\ndefinition exists.intro := @Exists.intro\n\nnotation `exists` binders `, ` r:(scoped P, Exists P) := r\nnotation `\u2203` binders `, ` r:(scoped P, Exists P) := r\n\nattribute Exists.rec [elim]\n\ntheorem exists.elim {A : Type} {p : A \u2192 Prop} {B : Prop}\n  (H1 : \u2203x, p x) (H2 : \u2200 (a : A), p a \u2192 B) : B :=\nExists.rec H2 H1\n\n/- exists unique -/\n\ndefinition exists_unique {A : Type} (p : A \u2192 Prop) :=\n\u2203x, p x \u2227 \u2200y, p y \u2192 y = x\n\nnotation `\u2203!` binders `, ` r:(scoped P, exists_unique P) := r\n\ntheorem exists_unique.intro [intro] {A : Type} {p : A \u2192 Prop} (w : A) (H1 : p w) (H2 : \u2200y, p y \u2192 y = w) :\n  \u2203!x, p x :=\nexists.intro w (and.intro H1 H2)\n\ntheorem exists_unique.elim [recursor 4] [elim] {A : Type} {p : A \u2192 Prop} {b : Prop}\n    (H2 : \u2203!x, p x) (H1 : \u2200x, p x \u2192 (\u2200y, p y \u2192 y = x) \u2192 b) : b :=\nexists.elim H2 (\u03bb w Hw, H1 w (and.left Hw) (and.right Hw))\n\ntheorem exists_unique_of_exists_of_unique {A : Type} {p : A \u2192 Prop}\n    (Hex : \u2203 x, p x) (Hunique : \u2200 y\u2081 y\u2082, p y\u2081 \u2192 p y\u2082 \u2192 y\u2081 = y\u2082) :  \u2203! x, p x :=\nexists.elim Hex (\u03bb x px, exists_unique.intro x px (take y, suppose p y, Hunique y x this px))\n\ntheorem exists_of_exists_unique {A : Type} {p : A \u2192 Prop} (H : \u2203! x, p x) : \u2203 x, p x :=\nexists.elim H (\u03bb x Hx, exists.intro x (and.left Hx))\n\ntheorem unique_of_exists_unique {A : Type} {p : A \u2192 Prop}\n    (H : \u2203! x, p x) {y\u2081 y\u2082 : A} (py\u2081 : p y\u2081) (py\u2082 : p y\u2082) : y\u2081 = y\u2082 :=\nexists_unique.elim H\n  (take x, suppose p x,\n    assume unique : \u2200 y, p y \u2192 y = x,\n    show y\u2081 = y\u2082, from eq.trans (unique _ py\u2081) (eq.symm (unique _ py\u2082)))\n\n/- exists, forall, exists unique congruences -/\nsection\nvariables {A : Type} {p\u2081 p\u2082 : A \u2192 Prop}\n\ntheorem forall_congr [congr] {A : Type} {P Q : A \u2192 Prop} (H : \u2200a, (P a \u2194 Q a)) : (\u2200a, P a) \u2194 \u2200a, Q a :=\niff.intro (\u03bbp a, iff.mp (H a) (p a)) (\u03bbq a, iff.mpr (H a) (q a))\n\ntheorem exists_imp_exists {A : Type} {P Q : A \u2192 Prop} (H : \u2200a, (P a \u2192 Q a)) (p : \u2203a, P a) : \u2203a, Q a :=\nexists.elim p (\u03bba Hp, exists.intro a (H a Hp))\n\ntheorem exists_congr [congr] {A : Type} {P Q : A \u2192 Prop} (H : \u2200a, (P a \u2194 Q a)) : (\u2203a, P a) \u2194 \u2203a, Q a :=\niff.intro\n  (exists_imp_exists (\u03bba, iff.mp (H a)))\n  (exists_imp_exists (\u03bba, iff.mpr (H a)))\n\ntheorem exists_unique_congr [congr] (H : \u2200 x, p\u2081 x \u2194 p\u2082 x) : (\u2203! x, p\u2081 x) \u2194 (\u2203! x, p\u2082 x) :=\nexists_congr (\u03bbx, and_congr (H x) (forall_congr (\u03bby, imp_congr (H y) iff.rfl)))\nend\n\n/- decidable -/\n\ninductive decidable [class] (p : Prop) : Type :=\n| inl :  p \u2192 decidable p\n| inr : \u00acp \u2192 decidable p\n\ndefinition decidable_true [instance] : decidable true :=\ndecidable.inl trivial\n\ndefinition decidable_false [instance] : decidable false :=\ndecidable.inr not_false\n\n-- We use \"dependent\" if-then-else to be able to communicate the if-then-else condition\n-- to the branches\ndefinition dite (c : Prop) [H : decidable c] {A : Type} : (c \u2192 A) \u2192 (\u00ac c \u2192 A) \u2192 A :=\ndecidable.rec_on H\n\n/- if-then-else -/\n\ndefinition ite (c : Prop) [H : decidable c] {A : Type} (t e : A) : A :=\ndecidable.rec_on H (\u03bb Hc, t) (\u03bb Hnc, e)\n\nnamespace decidable\n  variables {p q : Prop}\n\n  definition rec_on_true [H : decidable p] {H1 : p \u2192 Type} {H2 : \u00acp \u2192 Type} (H3 : p) (H4 : H1 H3)\n      : decidable.rec_on H H1 H2 :=\n  decidable.rec_on H (\u03bbh, H4) (\u03bbh, !false.rec (h H3))\n\n  definition rec_on_false [H : decidable p] {H1 : p \u2192 Type} {H2 : \u00acp \u2192 Type} (H3 : \u00acp) (H4 : H2 H3)\n      : decidable.rec_on H H1 H2 :=\n  decidable.rec_on H (\u03bbh, false.rec _ (H3 h)) (\u03bbh, H4)\n\n  definition by_cases {q : Type} [C : decidable p] : (p \u2192 q) \u2192 (\u00acp \u2192 q) \u2192 q := !dite\n\n  theorem em (p : Prop) [decidable p] : p \u2228 \u00acp := by_cases or.inl or.inr\n\n  theorem by_contradiction [decidable p] (H : \u00acp \u2192 false) : p :=\n  if H1 : p then H1 else false.rec _ (H H1)\nend decidable\n\nsection\n  variables {p q : Prop}\n  open decidable\n  definition  decidable_of_decidable_of_iff (Hp : decidable p) (H : p \u2194 q) : decidable q :=\n  if Hp : p then inl (iff.mp H Hp)\n  else inr (iff.mp (not_iff_not_of_iff H) Hp)\n\n  definition  decidable_of_decidable_of_eq (Hp : decidable p) (H : p = q) : decidable q :=\n  decidable_of_decidable_of_iff Hp (iff.of_eq H)\n\n  protected definition or.by_cases [decidable p] [decidable q] {A : Type}\n                                   (h : p \u2228 q) (h\u2081 : p \u2192 A) (h\u2082 : q \u2192 A) : A :=\n  if hp : p then h\u2081 hp else\n    if hq : q then h\u2082 hq else\n      false.rec _ (or.elim h hp hq)\nend\n\nsection\n  variables {p q : Prop}\n  open decidable (rec_on inl inr)\n\n  definition decidable_and [instance] [decidable p] [decidable q] : decidable (p \u2227 q) :=\n  if hp : p then\n    if hq : q then inl (and.intro hp hq)\n    else inr (assume H : p \u2227 q, hq (and.right H))\n  else inr (assume H : p \u2227 q, hp (and.left H))\n\n  definition decidable_or [instance] [decidable p] [decidable q] : decidable (p \u2228 q) :=\n  if hp : p then inl (or.inl hp) else\n    if hq : q then inl (or.inr hq) else\n      inr (or.rec hp hq)\n\n  definition decidable_not [instance] [decidable p] : decidable (\u00acp) :=\n  if hp : p then inr (absurd hp) else inl hp\n\n  definition decidable_implies [instance] [decidable p] [decidable q] : decidable (p \u2192 q) :=\n  if hp : p then\n    if hq : q then inl (assume H, hq)\n    else inr (assume H : p \u2192 q, absurd (H hp) hq)\n  else inl (assume Hp, absurd Hp hp)\n\n  definition decidable_iff [instance] [decidable p] [decidable q] : decidable (p \u2194 q) :=\n  decidable_and\n\nend\n\ndefinition decidable_pred [reducible] {A : Type} (R : A   \u2192   Prop) := \u03a0 (a   : A), decidable (R a)\ndefinition decidable_rel  [reducible] {A : Type} (R : A \u2192 A \u2192 Prop) := \u03a0 (a b : A), decidable (R a b)\ndefinition decidable_eq   [reducible] (A : Type) := decidable_rel (@eq A)\ndefinition decidable_ne [instance] {A : Type} [decidable_eq A] (a b : A) : decidable (a \u2260 b) :=\ndecidable_implies\n\nnamespace bool\n  theorem ff_ne_tt : ff = tt \u2192 false\n  | [none]\nend bool\n\nopen bool\ndefinition is_dec_eq {A : Type} (p : A \u2192 A \u2192 bool) : Prop   := \u2200 \u2983x y : A\u2984, p x y = tt \u2192 x = y\ndefinition is_dec_refl {A : Type} (p : A \u2192 A \u2192 bool) : Prop := \u2200x, p x x = tt\n\nopen decidable\nprotected definition bool.has_decidable_eq [instance] : \u2200a b : bool, decidable (a = b)\n| ff ff := inl rfl\n| ff tt := inr ff_ne_tt\n| tt ff := inr (ne.symm ff_ne_tt)\n| tt tt := inl rfl\n\ndefinition decidable_eq_of_bool_pred {A : Type} {p : A \u2192 A \u2192 bool} (H\u2081 : is_dec_eq p) (H\u2082 : is_dec_refl p) : decidable_eq A :=\ntake x y : A, if Hp : p x y = tt then inl (H\u2081 Hp)\n else inr (assume Hxy : x = y, (eq.subst Hxy Hp) (H\u2082 y))\n\ntheorem decidable_eq_inl_refl {A : Type} [H : decidable_eq A] (a : A) : H a a = inl (eq.refl a) :=\nmatch H a a with\n| inl e := rfl\n| inr n := absurd rfl n\nend\n\nopen eq.ops\ntheorem decidable_eq_inr_neg {A : Type} [H : decidable_eq A] {a b : A} : \u03a0 n : a \u2260 b, H a b = inr n :=\nassume n,\nmatch H a b with\n| inl e  := absurd e n\n| inr n\u2081 := proof_irrel n n\u2081 \u25b8 rfl\nend\n\n/- inhabited -/\n\ninductive inhabited [class] (A : Type) : Type :=\nmk : A \u2192 inhabited A\n\nprotected definition inhabited.value {A : Type} : inhabited A \u2192 A :=\ninhabited.rec (\u03bba, a)\n\nprotected definition inhabited.destruct {A : Type} {B : Type} (H1 : inhabited A) (H2 : A \u2192 B) : B :=\ninhabited.rec H2 H1\n\ndefinition default (A : Type) [H : inhabited A] : A :=\ninhabited.value H\n\ndefinition arbitrary [irreducible] (A : Type) [H : inhabited A] : A :=\ninhabited.value H\n\ndefinition Prop.is_inhabited [instance] : inhabited Prop :=\ninhabited.mk true\n\ndefinition inhabited_fun [instance] (A : Type) {B : Type} [H : inhabited B] : inhabited (A \u2192 B) :=\ninhabited.rec_on H (\u03bbb, inhabited.mk (\u03bba, b))\n\ndefinition inhabited_Pi [instance] (A : Type) {B : A \u2192 Type} [\u03a0x, inhabited (B x)] :\n  inhabited (\u03a0x, B x) :=\ninhabited.mk (\u03bba, !default)\n\nprotected definition bool.is_inhabited [instance] : inhabited bool :=\ninhabited.mk ff\n\nprotected definition pos_num.is_inhabited [instance] : inhabited pos_num :=\ninhabited.mk pos_num.one\n\nprotected definition num.is_inhabited [instance] : inhabited num :=\ninhabited.mk num.zero\n\ninductive nonempty [class] (A : Type) : Prop :=\nintro : A \u2192 nonempty A\n\nprotected definition nonempty.elim {A : Type} {B : Prop} (H1 : nonempty A) (H2 : A \u2192 B) : B :=\nnonempty.rec H2 H1\n\ntheorem nonempty_of_inhabited [instance] {A : Type} [inhabited A] : nonempty A :=\nnonempty.intro !default\n\ntheorem nonempty_of_exists {A : Type} {P : A \u2192 Prop} : (\u2203x, P x) \u2192 nonempty A :=\nExists.rec (\u03bbw H, nonempty.intro w)\n\n/- subsingleton -/\n\ninductive subsingleton [class] (A : Type) : Prop :=\nintro : (\u2200 a b : A, a = b) \u2192 subsingleton A\n\nprotected definition subsingleton.elim {A : Type} [H : subsingleton A] : \u2200(a b : A), a = b :=\nsubsingleton.rec (\u03bbp, p) H\n\nprotected definition subsingleton.helim {A B : Type} [H : subsingleton A] (h : A = B) (a : A) (b : B) : a == b :=\nby induction h; apply heq_of_eq; apply subsingleton.elim\n\ndefinition subsingleton_prop [instance] (p : Prop) : subsingleton p :=\nsubsingleton.intro (\u03bba b, !proof_irrel)\n\ndefinition subsingleton_decidable [instance] (p : Prop) : subsingleton (decidable p) :=\nsubsingleton.intro (\u03bb d\u2081,\n  match d\u2081 with\n  | inl t\u2081 := (\u03bb d\u2082,\n    match d\u2082 with\n    | inl t\u2082 := eq.rec_on (proof_irrel t\u2081 t\u2082) rfl\n    | inr f\u2082 := absurd t\u2081 f\u2082\n    end)\n  | inr f\u2081 := (\u03bb d\u2082,\n    match d\u2082 with\n    | inl t\u2082 := absurd t\u2082 f\u2081\n    | inr f\u2082 := eq.rec_on (proof_irrel f\u2081 f\u2082) rfl\n    end)\n  end)\n\nprotected theorem rec_subsingleton {p : Prop} [H : decidable p]\n    {H1 : p \u2192 Type} {H2 : \u00acp \u2192 Type}\n    [H3 : \u03a0(h : p), subsingleton (H1 h)] [H4 : \u03a0(h : \u00acp), subsingleton (H2 h)]\n  : subsingleton (decidable.rec_on H H1 H2) :=\ndecidable.rec_on H (\u03bbh, H3 h) (\u03bbh, H4 h) --this can be proven using dependent version of \"by_cases\"\n\ntheorem if_pos {c : Prop} [H : decidable c] (Hc : c) {A : Type} {t e : A} : (ite c t e) = t :=\ndecidable.rec\n  (\u03bb Hc : c,    eq.refl (@ite c (decidable.inl Hc) A t e))\n  (\u03bb Hnc : \u00acc,  absurd Hc Hnc)\n  H\n\ntheorem if_neg {c : Prop} [H : decidable c] (Hnc : \u00acc) {A : Type} {t e : A} : (ite c t e) = e :=\ndecidable.rec\n  (\u03bb Hc : c,    absurd Hc Hnc)\n  (\u03bb Hnc : \u00acc,  eq.refl (@ite c (decidable.inr Hnc) A t e))\n  H\n\ntheorem if_t_t [simp] (c : Prop) [H : decidable c] {A : Type} (t : A) : (ite c t t) = t :=\ndecidable.rec\n  (\u03bb Hc  : c,  eq.refl (@ite c (decidable.inl Hc)  A t t))\n  (\u03bb Hnc : \u00acc, eq.refl (@ite c (decidable.inr Hnc) A t t))\n  H\n\ntheorem implies_of_if_pos {c t e : Prop} [decidable c] (h : ite c t e) : c \u2192 t :=\nassume Hc, eq.rec_on (if_pos Hc) h\n\ntheorem implies_of_if_neg {c t e : Prop} [decidable c] (h : ite c t e) : \u00acc \u2192 e :=\nassume Hnc, eq.rec_on (if_neg Hnc) h\n\ntheorem if_ctx_congr {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]\n                     {x y u v : A}\n                     (h_c : b \u2194 c) (h_t : c \u2192 x = u) (h_e : \u00acc \u2192 y = v) :\n        ite b x y = ite c u v :=\ndecidable.rec_on dec_b\n  (\u03bb hp : b, calc\n    ite b x y = x           : if_pos hp\n         ...  = u           : h_t (iff.mp h_c hp)\n         ...  = ite c u v : if_pos (iff.mp h_c hp))\n  (\u03bb hn : \u00acb, calc\n    ite b x y = y         : if_neg hn\n         ...  = v         : h_e (iff.mp (not_iff_not_of_iff h_c) hn)\n         ...  = ite c u v : if_neg (iff.mp (not_iff_not_of_iff h_c) hn))\n\ntheorem if_congr [congr] {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]\n                 {x y u v : A}\n                 (h_c : b \u2194 c) (h_t : x = u) (h_e : y = v) :\n        ite b x y = ite c u v :=\n@if_ctx_congr A b c dec_b dec_c x y u v h_c (\u03bb h, h_t) (\u03bb h, h_e)\n\ntheorem if_ctx_simp_congr {A : Type} {b c : Prop} [dec_b : decidable b] {x y u v : A}\n                        (h_c : b \u2194 c) (h_t : c \u2192 x = u) (h_e : \u00acc \u2192 y = v) :\n        ite b x y = (@ite c (decidable_of_decidable_of_iff dec_b h_c) A u v) :=\n@if_ctx_congr A b c dec_b (decidable_of_decidable_of_iff dec_b h_c) x y u v h_c h_t h_e\n\ntheorem if_simp_congr [congr] {A : Type} {b c : Prop} [dec_b : decidable b] {x y u v : A}\n                 (h_c : b \u2194 c) (h_t : x = u) (h_e : y = v) :\n        ite b x y = (@ite c (decidable_of_decidable_of_iff dec_b h_c) A u v) :=\n@if_ctx_simp_congr A b c dec_b x y u v h_c (\u03bb h, h_t) (\u03bb h, h_e)\n\ndefinition if_true [simp] {A : Type} (t e : A) : (if true then t else e) = t :=\nif_pos trivial\n\ndefinition if_false [simp] {A : Type} (t e : A) : (if false then t else e) = e :=\nif_neg not_false\n\ntheorem if_ctx_congr_prop {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c]\n                      (h_c : b \u2194 c) (h_t : c \u2192 (x \u2194 u)) (h_e : \u00acc \u2192 (y \u2194 v)) :\n        ite b x y \u2194 ite c u v :=\ndecidable.rec_on dec_b\n  (\u03bb hp : b, calc\n    ite b x y \u2194 x         : iff.of_eq (if_pos hp)\n         ...  \u2194 u         : h_t (iff.mp h_c hp)\n         ...  \u2194 ite c u v : iff.of_eq (if_pos (iff.mp h_c hp)))\n  (\u03bb hn : \u00acb, calc\n    ite b x y \u2194 y         : iff.of_eq (if_neg hn)\n         ...  \u2194 v         : h_e (iff.mp (not_iff_not_of_iff h_c) hn)\n         ...  \u2194 ite c u v : iff.of_eq (if_neg (iff.mp (not_iff_not_of_iff h_c) hn)))\n\ntheorem if_congr_prop [congr] {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c]\n                      (h_c : b \u2194 c) (h_t : x \u2194 u) (h_e : y \u2194 v) :\n        ite b x y \u2194 ite c u v :=\nif_ctx_congr_prop h_c (\u03bb h, h_t) (\u03bb h, h_e)\n\ntheorem if_ctx_simp_congr_prop {b c x y u v : Prop} [dec_b : decidable b]\n                               (h_c : b \u2194 c) (h_t : c \u2192 (x \u2194 u)) (h_e : \u00acc \u2192 (y \u2194 v)) :\n        ite b x y \u2194 (@ite c (decidable_of_decidable_of_iff dec_b h_c) Prop u v) :=\n@if_ctx_congr_prop b c x y u v dec_b (decidable_of_decidable_of_iff dec_b h_c) h_c h_t h_e\n\ntheorem if_simp_congr_prop [congr] {b c x y u v : Prop} [dec_b : decidable b]\n                           (h_c : b \u2194 c) (h_t : x \u2194 u) (h_e : y \u2194 v) :\n        ite b x y \u2194 (@ite c (decidable_of_decidable_of_iff dec_b h_c) Prop u v) :=\n@if_ctx_simp_congr_prop b c x y u v dec_b h_c (\u03bb h, h_t) (\u03bb h, h_e)\n\ntheorem dif_pos {c : Prop} [H : decidable c] (Hc : c) {A : Type} {t : c \u2192 A} {e : \u00ac c \u2192 A} : dite c t e = t Hc :=\ndecidable.rec\n  (\u03bb Hc : c,    eq.refl (@dite c (decidable.inl Hc) A t e))\n  (\u03bb Hnc : \u00acc,  absurd Hc Hnc)\n  H\n\ntheorem dif_neg {c : Prop} [H : decidable c] (Hnc : \u00acc) {A : Type} {t : c \u2192 A} {e : \u00ac c \u2192 A} : dite c t e = e Hnc :=\ndecidable.rec\n  (\u03bb Hc : c,    absurd Hc Hnc)\n  (\u03bb Hnc : \u00acc,  eq.refl (@dite c (decidable.inr Hnc) A t e))\n  H\n\ntheorem dif_ctx_congr {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]\n                      {x : b \u2192 A} {u : c \u2192 A} {y : \u00acb \u2192 A} {v : \u00acc \u2192 A}\n                      (h_c : b \u2194 c)\n                      (h_t : \u2200 (h : c),    x (iff.mpr h_c h)                      = u h)\n                      (h_e : \u2200 (h : \u00acc),   y (iff.mpr (not_iff_not_of_iff h_c) h) = v h) :\n        (@dite b dec_b A x y) = (@dite c dec_c A u v) :=\ndecidable.rec_on dec_b\n  (\u03bb hp : b, calc\n    dite b x y = x hp                            : dif_pos hp\n          ...  = x (iff.mpr h_c (iff.mp h_c hp)) : proof_irrel\n          ...  = u (iff.mp h_c hp)               : h_t\n          ...  = dite c u v                      : dif_pos (iff.mp h_c hp))\n  (\u03bb hn : \u00acb, let h_nc : \u00acb \u2194 \u00acc := not_iff_not_of_iff h_c in calc\n    dite b x y = y hn                              : dif_neg hn\n          ...  = y (iff.mpr h_nc (iff.mp h_nc hn)) : proof_irrel\n          ...  = v (iff.mp h_nc hn)                : h_e\n          ...  = dite c u v                        : dif_neg (iff.mp h_nc hn))\n\ntheorem dif_ctx_simp_congr {A : Type} {b c : Prop} [dec_b : decidable b]\n                         {x : b \u2192 A} {u : c \u2192 A} {y : \u00acb \u2192 A} {v : \u00acc \u2192 A}\n                         (h_c : b \u2194 c)\n                         (h_t : \u2200 (h : c),    x (iff.mpr h_c h)                      = u h)\n                         (h_e : \u2200 (h : \u00acc),   y (iff.mpr (not_iff_not_of_iff h_c) h) = v h) :\n        (@dite b dec_b A x y) = (@dite c (decidable_of_decidable_of_iff dec_b h_c) A u v) :=\n@dif_ctx_congr A b c dec_b (decidable_of_decidable_of_iff dec_b h_c) x u y v h_c h_t h_e\n\n-- Remark: dite and ite are \"definitionally equal\" when we ignore the proofs.\ntheorem dite_ite_eq (c : Prop) [decidable c] {A : Type} (t : A) (e : A) : dite c (\u03bbh, t) (\u03bbh, e) = ite c t e :=\nrfl\n\ndefinition is_true (c : Prop) [decidable c] : Prop :=\nif c then true else false\n\ndefinition is_false (c : Prop) [decidable c] : Prop :=\nif c then false else true\n\ndefinition of_is_true {c : Prop} [H\u2081 : decidable c] (H\u2082 : is_true c) : c :=\ndecidable.rec_on H\u2081 (\u03bb Hc, Hc) (\u03bb Hnc, !false.rec (if_neg Hnc \u25b8 H\u2082))\n\nnotation `dec_trivial` := of_is_true trivial\n\ntheorem not_of_not_is_true {c : Prop} [decidable c] (H : \u00ac is_true c) : \u00ac c :=\nif Hc : c then absurd trivial (if_pos Hc \u25b8 H) else Hc\n\ntheorem not_of_is_false {c : Prop} [decidable c] (H : is_false c) : \u00ac c :=\nif Hc : c then !false.rec (if_pos Hc \u25b8 H) else Hc\n\ntheorem of_not_is_false {c : Prop} [decidable c] (H : \u00ac is_false c) : c :=\nif Hc : c then Hc else absurd trivial (if_neg Hc \u25b8 H)\n\n-- The following symbols should not be considered in the pattern inference procedure used by\n-- heuristic instantiation.\nattribute and or not iff ite dite eq ne heq [no_pattern]\n\n-- namespace used to collect congruence rules for \"contextual simplification\"\nnamespace contextual\n  attribute if_ctx_simp_congr      [congr]\n  attribute if_ctx_simp_congr_prop [congr]\n  attribute dif_ctx_simp_congr     [congr]\nend contextual\n", "meta": {"author": "Bolt64", "repo": "lean2-aur", "sha": "1d7148e58a17b2d326b032ed1ebf8c5217320242", "save_path": "github-repos/lean/Bolt64-lean2-aur", "path": "github-repos/lean/Bolt64-lean2-aur/lean2-aur-1d7148e58a17b2d326b032ed1ebf8c5217320242/library/init/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7012458865737793}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nGiven a poset `P`, we define `subdiv P` to be the poset of \nfinite nonempty chains `s \u2286 P`.  Any such `s` has a largest \nelement, and the map `max : (subdiv P) \u2192 P` is a morphism \nof posets.  There is an approach to the homotopy theory of\nfinite complexes based on finite posets, and the above map\n`max` plays a key role in this. \n-/\n\nimport data.list.sort data.fintype.basic\nimport poset.basic order.sort_rank\n\nuniverses uP uQ uR uS\n\nvariables (P : Type uP) [partial_order P] [decidable_eq P]\nvariables (Q : Type uQ) [partial_order Q] [decidable_eq Q]\nvariables (R : Type uR) [partial_order R] [decidable_eq R]\nvariables (S : Type uS) [partial_order S] [decidable_eq S]\n\nvariable [decidable_rel (has_le.le : P \u2192 P \u2192 Prop)]\nvariable [decidable_rel (has_le.le : Q \u2192 Q \u2192 Prop)]\nvariable [decidable_rel (has_le.le : R \u2192 R \u2192 Prop)]\nvariable [decidable_rel (has_le.le : S \u2192 S \u2192 Prop)]\n\nnamespace poset \nopen poset\n\nvariables {P} [fintype P]\n\n/-- Definition of chains \n  LaTeX: defn-subdiv\n-/\ndef is_chain (s : finset P) : Prop := \n \u2200 (p \u2208 s) (q \u2208 s), (p \u2264 q \u2228 q \u2264 p)\n\ninstance decidable_is_chain (s : finset P) : decidable (is_chain s) := \nby { unfold is_chain, apply_instance }\n\n/-- Definition of simplices as nonempty chains \n  LaTeX: defn-subdiv\n-/\ndef is_simplex (s : finset P) : Prop := s.nonempty \u2227 (is_chain s)\n\ninstance decidable_is_simplex (s : finset P) : decidable (is_simplex s) := \nby { unfold is_simplex, unfold finset.nonempty, apply_instance }\n\nvariable (P)\n\n/-- Definition of subdiv P as a type \n  LaTeX: defn-subdiv\n-/\ndef subdiv := {s : finset P // is_simplex s}\n\ninstance : has_coe (subdiv P) (finset P) := \u27e8subtype.val\u27e9\n\n/-- Vertices as 0-simplices -/\nvariable {P}\ndef vertex (p : P) : subdiv P := \u27e8 \n{p},\nbegin\n  split,\n  {exact \u27e8p,finset.mem_singleton_self p\u27e9},\n  {intros x hx y hy,\n   rw [finset.mem_singleton.mp hx, finset.mem_singleton.mp hy],\n   left, exact le_refl p }\nend\u27e9 \nvariable (P)\n\nnamespace subdiv\n\ninstance : decidable_eq (subdiv P) := \n  by { unfold subdiv, apply_instance }\n\n/-- Definition of the partial order on subdiv P \n  LaTeX: defn-subdiv\n-/\ninstance : partial_order (subdiv P) := \n{ le := \u03bb s t, s.val \u2286 t.val,\n  le_refl := \u03bb s, (le_refl s.val),\n  le_antisymm := \u03bb s t hst hts, subtype.eq (le_antisymm hst hts),\n  le_trans := \u03bb s t u (hst : s.val \u2286 t.val) (htu : t.val \u2286 u.val) p hs, \n                (htu (hst hs)) }\n\ninstance decidable_le : decidable_rel\n (has_le.le : (subdiv P) \u2192 (subdiv P) \u2192 Prop) := \n  \u03bb s t, by { apply_instance }\n\nvariable {P}\n\n/-- Definition of the dimension of a simplex, as one less than \n  the cardinality.  We use the predecessor operation on \n  natural numbers, which sends zero to zero.  Because of this,\n  we need a small argument to show that the cardinality is \n  strictly positive and thus equal to one more than the dimension.\n\n  LaTeX: defn-subdiv\n-/\ndef dim (s : subdiv P) : \u2115 := (s : finset P).card.pred\n\nlemma card_eq (s : subdiv P) : (s : finset P).card = s.dim.succ := \nbegin \n  by_cases h : s.val.card = 0,\n  { exfalso,\n    have h\u2080 := s.property.left, rw[finset.card_eq_zero.mp h] at h\u2080,\n    exact finset.not_nonempty_empty h\u2080},\n  { replace h := nat.pos_of_ne_zero h,\n    exact (nat.succ_pred_eq_of_pos h).symm }\nend\n\n/-- The dimension function dim : subdiv P \u2192 \u2115 is monotone. -/\nlemma dim_mono : monotone (dim : (subdiv P) \u2192 \u2115) := \nbegin\n  intros s t hst,\n  let h : (s : finset P).card \u2264 (t : finset P).card := finset.card_le_of_subset hst,\n  rw[card_eq,card_eq] at h,\n  exact nat.le_of_succ_le_succ h\nend\n\n/-- If we have simplices s \u2264 t with dim s \u2265 dim t then s = t. -/\nlemma eq_of_le_of_dim_ge (s t : subdiv P)\n (hst : s \u2264 t) (hd : s.dim \u2265 t.dim) : s = t := \nbegin\n  let hc := nat.succ_le_succ hd,\n  rw [\u2190 card_eq, \u2190 card_eq] at hc,\n  exact subtype.eq (finset.eq_of_subset_of_card_le hst hc)\nend\n\n/-- This allows us to treat a simplex as a type in its own right. -/\ninstance : has_coe_to_sort (subdiv P) (Type uP) := \u27e8\u03bb s, {p : P // p \u2208 s.val}\u27e9\n\nsection els\n\nvariable (s : subdiv P)\n\ninstance els_decidable_eq : decidable_eq s := by { apply_instance }\ninstance els_fintype : fintype s           := by { apply_instance }\n\nlemma card_eq' : fintype.card s = s.dim.succ := begin\n rw[\u2190 s.card_eq], rw[\u2190 fintype.card_coe],congr\nend\n\n/-- If s is a simplex, we can treat it as a linearly ordered set. -/\ninstance els_order : linear_order s := \n{ le := \u03bb p q,p.val \u2264 q.val,\n  le_refl := \u03bb p, ((le_refl (p.val : P)) : p.val \u2264 p.val),\n  le_antisymm := \u03bb p q (hpq : p.val \u2264 q.val) (hqp : q.val \u2264 p.val),\n                 subtype.eq (le_antisymm hpq hqp),\n  le_trans := \u03bb p q r (hpq : p.val \u2264 q.val) (hqr : q.val \u2264 r.val), \n                 le_trans hpq hqr,\n  le_total := \u03bb p q,s.property.right p.val p.property q.val q.property,\n  lt := \u03bb p q,p.val < q.val,\n  lt_iff_le_not_le := \u03bb p q, \n  begin \n    change p.val < q.val \u2194 p.val \u2264 q.val \u2227 \u00ac q.val \u2264 p.val,\n    apply lt_iff_le_not_le, \n  end,\n  decidable_le := \u03bb p q, by { apply_instance } }\n\nvariable {s}\n\n/-- The inclusion of a simplex in the full poset P. -/\ndef inc : s \u2192 P := \u03bb p, p.val\n\n/-- The inclusion map is injective. -/\nlemma inc_inj (p\u2080 p\u2081 : s) : (inc p\u2080) = (inc p\u2081) \u2192 p\u2080 = p\u2081 := subtype.eq\n\n/-- The inclusion map is monotone. -/\nlemma inc_mono : monotone (inc : s \u2192 P) := \u03bb p\u2080 p\u2081 hp, hp\n\nvariable (s)\nvariables {d : \u2115} (e : s.dim = d)\n\n/-- If dim s = d, then we have a canonical bijection from s \n  to the set  fin d.succ = { 0,1,...,d }.  We define \n  rank_equiv s to be a package consisting of this bijection\n  and its inverse.  We define seq s and rank s to be \n  auxiliary functions defined in terms of rank_equiv s,\n  and we prove some lemmas about the behaviour of these.\n-/\n\ndef rank_equiv : s \u2243 fin d.succ := \n fintype.rank_equiv (s.card_eq'.trans (congr_arg nat.succ e))\n\ndef seq : (fin d.succ) \u2192 P := \u03bb i, inc ((rank_equiv s e).inv_fun i)\n\ndef rank (p : P) (hp : p \u2208 s.val) : fin d.succ := \n (rank_equiv s e).to_fun \u27e8p,hp\u27e9\n\nlemma seq_mem (i : fin d.succ) : seq s e i \u2208 s.val := \n  ((rank_equiv s e).inv_fun i).property\n\nlemma seq_rank (p : P) (hp : p \u2208 s.val) : \n seq s e (rank s e p hp) = p := \n  congr_arg inc ((rank_equiv s e).left_inv \u27e8p,hp\u27e9)\n\nlemma seq_eq (i : fin d.succ) :\n ((rank_equiv s e).symm i) = \u27e8seq s e i,seq_mem s e i\u27e9 := \n  by { apply subtype.eq, refl }\n\nlemma rank_seq (i : fin d.succ) : \n rank s e (seq s e i) (seq_mem s e i) = i := \nbegin\n  dsimp [rank],\n  rw [\u2190 (seq_eq s e i)], \n  exact (rank_equiv s e).right_inv i,\nend\n\nlemma seq_le (i\u2080 i\u2081 : fin d.succ) :\n i\u2080 \u2264 i\u2081 \u2194 seq s e i\u2080 \u2264 seq s e i\u2081 := \n  fintype.seq_le (s.card_eq'.trans (congr_arg nat.succ e)) i\u2080 i\u2081\n\nlemma seq_lt (i\u2080 i\u2081 : fin d.succ) :\n i\u2080 < i\u2081 \u2194 seq s e i\u2080 < seq s e i\u2081 := \n  fintype.seq_lt (s.card_eq'.trans (congr_arg nat.succ e)) i\u2080 i\u2081\n\n\nvariables {P Q} [fintype Q]\n\ndef map (f : poset.hom P Q) : (poset.hom (subdiv P) (subdiv Q)) := \nbegin\n  let sf : subdiv P \u2192 subdiv Q := \u03bb s, \n  begin\n    let t0 : finset Q := s.val.image f.val,\n    have : is_simplex t0 := \n    begin \n      split,\n      { rcases s.property.1 with \u27e8p,p_in_s\u27e9, \n        exact \u27e8_,(finset.mem_image_of_mem f.val p_in_s)\u27e9 },\n      { intros q\u2080 hq\u2080 q\u2081 hq\u2081, \n        rcases finset.mem_image.mp hq\u2080 with \u27e8p\u2080,hp\u2080,hfp\u2080\u27e9,\n        rcases finset.mem_image.mp hq\u2081 with \u27e8p\u2081,hp\u2081,hfp\u2081\u27e9,\n        rw [\u2190 hfp\u2080, \u2190 hfp\u2081],\n        rcases s.property.2 p\u2080 hp\u2080 p\u2081 hp\u2081 with h\u2080\u2081 | h\u2081\u2080,\n        { left,  exact f.property h\u2080\u2081 },\n        { right, exact f.property h\u2081\u2080 } }\n    end,\n    exact \u27e8t0,this\u27e9\n  end,\n  have : monotone sf := \u03bb s\u2080 s\u2081 hs, \n  begin\n    change s\u2080.val.image f.val \u2286 s\u2081.val.image f.val, \n    intros q hq, \n    rcases finset.mem_image.mp hq with \u27e8p,hp,hfp\u27e9,\n    exact finset.mem_image.mpr \u27e8p,hs hp,hfp\u27e9\n  end,\n  exact \u27e8sf, this\u27e9\nend\n\nlemma map_val (f : poset.hom P Q) (s : subdiv P) : \n ((subdiv.map f).val s).val = s.val.image f.val := rfl\n\nsection interleave \n\nvariables [fintype P] {f g : poset.hom P Q} (hfg : f \u2264 g)\ninclude hfg\n\ndef interleave :\n \u2200 (r : fin_ranking P) (m : \u2115), hom (subdiv P) (subdiv Q) \n| \u27e8n,r,r_mono\u27e9 m := \n  \u27e8 \u03bb (\u03c3 : subdiv P), \n    \u27e8 ((\u03c3.val.filter (\u03bb p, 2 * (r p).val < m)).image f) \u222a  \n      ((\u03c3.val.filter (\u03bb p, 2 * (r p).val + 1 \u2265 m)).image g),  \n      begin \n        split,\n        { rcases \u03c3.property.1 with \u27e8p, p_in_\u03c3\u27e9,\n          by_cases h : 2 * (r p).val < m,\n          { use f p,\n            apply finset.mem_union_left,\n            apply finset.mem_image_of_mem,\n            rw [finset.mem_filter],\n            exact \u27e8p_in_\u03c3, h\u27e9 },\n          { replace h := le_trans (le_of_not_gt h) (nat.le_succ _), \n            use (g p),\n            apply finset.mem_union_right,\n            apply finset.mem_image_of_mem,\n            rw [finset.mem_filter],\n            exact \u27e8p_in_\u03c3, h\u27e9 } },\n        { intros q\u2080 h\u2080 q\u2081 h\u2081,\n          rcases finset.mem_union.mp h\u2080 with h\u2080 | h\u2080;\n          rcases finset.mem_union.mp h\u2081 with h\u2081 | h\u2081;\n          rcases finset.mem_image.mp h\u2080 with \u27e8p\u2080,hf\u2080,he\u2080\u27e9;\n          rcases finset.mem_image.mp h\u2081 with \u27e8p\u2081,hf\u2081,he\u2081\u27e9;\n          rw [finset.mem_filter] at hf\u2080 hf\u2081; \n          rw [\u2190 he\u2080, \u2190 he\u2081];\n          let r\u2080 := (r p\u2080).val ; let r\u2081 := (r p\u2081).val ; \n          rcases \u03c3.property.right p\u2080 hf\u2080.1 p\u2081 hf\u2081.1 with hpp | hpp;\n          let hfpp := f.property hpp;\n          let hgpp := g.property hpp,\n          { left , exact hfpp },\n          { right, exact hfpp },\n          { left , exact le_trans hfpp (hfg p\u2081) },\n          { by_cases hrr : r\u2080 = r\u2081, \n            { rw [r.injective (fin.eq_of_veq hrr)],\n              left, exact hfg p\u2081 },\n            { exfalso, \n              change r\u2080 \u2260 r\u2081 at hrr,\n              replace hrr : r\u2081 < r\u2080 := lt_of_le_of_ne (r_mono hpp) hrr.symm, \n              change r\u2081 + 1 \u2264 r\u2080 at hrr,\n              have := calc\n                2 * r\u2081 + 2 = 2 * (r\u2081 + 1) : by rw [mul_add, mul_one]\n                ... \u2264 2 * r\u2080 : nat.mul_le_mul_left 2 hrr\n                ... < m : hf\u2080.2\n                ... \u2264 2 * r\u2081 + 1 : hf\u2081.2 \n                ... < 2 * r\u2081 + 2 : nat.lt_succ_self _, \n              exact lt_irrefl _ this } }, \n          { by_cases hrr : r\u2080 = r\u2081, \n            { rw [r.injective (fin.eq_of_veq hrr)],\n              right, exact hfg p\u2081 },\n            { exfalso, \n              change r\u2080 \u2260 r\u2081 at hrr,\n              replace hrr : r\u2080 < r\u2081 := lt_of_le_of_ne (r_mono hpp) hrr, \n              change r\u2080 + 1 \u2264 r\u2081 at hrr,\n              have := calc\n                2 * r\u2081 < m : hf\u2081.2 \n                ... \u2264 2 * r\u2080 + 1 : hf\u2080.2 \n                ... < 2 * r\u2080 + 2 : nat.lt_succ_self _\n                ... = 2 * (r\u2080 + 1) : by rw [mul_add, mul_one]\n                ... \u2264 2 * r\u2081 : nat.mul_le_mul_left 2 hrr,\n              exact lt_irrefl _ this } }, \n          { right, exact le_trans hfpp (hfg p\u2080) },\n          { left , exact hgpp },\n          { right, exact hgpp } }\n      end \u27e9,\n      begin \n        intros \u03c3\u2080 \u03c3\u2081 h_le q hq,\n        rw [finset.mem_union] at hq \u22a2, \n        rcases hq with hq | hq;\n        rcases finset.mem_image.mp hq with \u27e8p,hm,he\u27e9;\n        rw [\u2190 he];\n        rw [finset.mem_filter] at hm;\n        replace hm := and.intro (h_le hm.1) hm.2,\n        { left , apply finset.mem_image_of_mem, \n          rw [finset.mem_filter], exact hm },\n        { right, apply finset.mem_image_of_mem, \n          rw [finset.mem_filter], exact hm }\n      end \u27e9 \n\nlemma interleave_start :\n \u2200 (r : fin_ranking P), interleave hfg r 0 = subdiv.map g \n| \u27e8n,r,r_mono\u27e9 := \nbegin\n  ext1 \u03c3, \n  apply subtype.eq,\n  change _ \u222a _ = \u03c3.val.image g.val,\n  ext q,\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val < 0) = \u2205 := \n  begin\n    ext p, rw [finset.mem_filter],\n    simp [nat.not_lt_zero, finset.not_mem_empty] \n  end,\n  rw [this, finset.image_empty],\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val + 1 \u2265 0) = \u03c3.val := \n  begin\n    ext p, rw [finset.mem_filter], \n    have : _ \u2265 0 := nat.zero_le (2 * (r p).val + 1),\n    simp only [this, and_true]\n  end,\n  rw [this, finset.mem_union],\n  have : (g : P \u2192 Q) = g.val := rfl, rw [this], \n  simp [finset.not_mem_empty],\nend\n\nlemma interleave_end :\n \u2200 (r : fin_ranking P) (m : \u2115) (hm : m \u2265 2 * r.card), \n  interleave hfg r m = subdiv.map f \n| \u27e8n,r,r_mono\u27e9 m hm := \nbegin\n  change m \u2265 2 * n at hm,\n  ext1 \u03c3,\n  apply subtype.eq,\n  change _ \u222a _ = \u03c3.val.image f.val,\n  ext q,\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val < m) = \u03c3.val := \n  begin\n    ext p, rw [finset.mem_filter], \n    have := calc\n      2 * (r p).val < 2 * n :\n        nat.mul_lt_mul_of_pos_left (r p).is_lt (dec_trivial : 2 > 0)\n      ... \u2264 m : hm,\n    simp only [this,and_true],\n  end,\n  rw [this],\n  have : \u03c3.val.filter (\u03bb (p : P), 2 * (r p).val + 1 \u2265 m) = \u2205 := \n  begin\n    ext p, rw [finset.mem_filter],\n    have := calc \n      2 * (r p).val + 1 < 2 * (r p).val + 2 : nat.lt_succ_self _\n      ... = 2 * ((r p).val + 1) : by rw [mul_add, mul_one]\n      ... \u2264 2 * n : nat.mul_le_mul_left 2 (r p).is_lt\n      ... \u2264 m : hm,\n    have : \u00ac (_ \u2265 m) := not_le_of_gt this,\n    simp only [this, finset.not_mem_empty, and_false]\n  end,\n  rw [this, finset.image_empty, finset.union_empty],\n  have : (f : P \u2192 Q) = f.val := rfl, rw [this]\nend\n\nlemma interleave_even_step : \n \u2200 (r : fin_ranking P) (k : \u2115), \n  interleave hfg r (2 * k) \u2264 interleave hfg r (2 * k + 1)\n| \u27e8n,r,r_mono\u27e9 k := \nbegin\n  intros \u03c3 q h,\n  change q \u2208 _ \u222a _ at h,\n  change q \u2208 _ \u222a _, \n  rw [finset.mem_union] at h \u22a2,  \n  rcases h with h | h;\n  rcases finset.mem_image.mp h with \u27e8p,hf,he\u27e9; \n  rw [finset.mem_filter] at hf;\n  rw [\u2190 he],\n  { left, \n    apply finset.mem_image_of_mem, \n    rw [finset.mem_filter],\n    exact \u27e8hf.1, lt_trans hf.2 (nat.lt_succ_self _)\u27e9 },\n  { right,\n    apply finset.mem_image_of_mem,\n    rw [finset.mem_filter],\n    rcases le_or_gt k (r p).val with hk | hk,\n    { exact \u27e8hf.1, nat.succ_le_succ (nat.mul_le_mul_left 2 hk)\u27e9 },\n    { exfalso, \n      have := calc\n        2 * (r p).val + 2 = 2 * ((r p).val + 1) : by rw [mul_add, mul_one]\n        ... \u2264 2 * k : nat.mul_le_mul_left 2 hk\n        ... \u2264 2 * (r p).val + 1 : hf.2\n        ... < 2 * (r p).val + 2 : nat.lt_succ_self _,\n      exact lt_irrefl _ this } }\nend\n\nlemma interleave_odd_step : \n \u2200 (r : fin_ranking P) (k : \u2115), \n  interleave hfg r (2 * k + 2) \u2264 interleave hfg r (2 * k + 1)\n| \u27e8n,r,r_mono\u27e9 k := \nbegin\n  intros \u03c3 q h,\n  change q \u2208 _ \u222a _ at h,\n  change q \u2208 _ \u222a _, \n  rw [finset.mem_union] at h \u22a2,  \n  rcases h with h | h;\n  rcases finset.mem_image.mp h with \u27e8p,hf,he\u27e9; \n  rw [finset.mem_filter] at hf;\n  rw [\u2190 he],\n  { left, \n    apply finset.mem_image_of_mem, \n    rw [finset.mem_filter],\n    rcases le_or_gt (r p).val k with hk | hk,\n    { have := calc\n       2 * (r p).val \u2264 2 * k : nat.mul_le_mul_left 2 hk\n       ... < 2 * k + 1 : nat.lt_succ_self _,\n      exact \u27e8hf.1, this\u27e9 },\n    { exfalso, \n      have := calc\n        2 * k + 2 = 2 * (k + 1) : by rw [mul_add, mul_one]\n        ... \u2264 2 * (r p).val : nat.mul_le_mul_left 2 hk\n        ... < 2 * k + 2 : hf.2,\n      exact lt_irrefl _ this } },\n  { right,\n    apply finset.mem_image_of_mem,\n    rw [finset.mem_filter],\n    exact \u27e8hf.1, le_trans (le_of_lt (nat.lt_succ_self (2 * k + 1))) hf.2\u27e9 }\nend\n\nlemma interleave_component (r : fin_ranking P) (m : \u2115) : \n  component (interleave hfg r m) = component (interleave hfg r 0) := \nzigzag (interleave hfg r) \n  (interleave_even_step hfg r)\n  (interleave_odd_step hfg r) m\n\nend interleave \n\ndef subdiv.map\u2095 [fintype P] :\n  \u03c0\u2080 (hom P Q) \u2192 \u03c0\u2080 (hom (subdiv P) (subdiv Q)) := \n\u03c0\u2080.lift (\u03bb f, component (subdiv.map f))\nbegin\n  intros f g hfg,\n  rcases exists_fin_ranking P with \u27e8r\u27e9,\n  let n := r.card,\n  let c := interleave hfg r,\n  have : c 0 = subdiv.map g := interleave_start hfg r,\n  rw [\u2190 this],\n  have : c (2 * n) = subdiv.map f := interleave_end hfg r (2 * n) (le_refl _),\n  rw [\u2190 this],\n  apply interleave_component\nend\n\n/-- For a simplex s, we define max s to be the largest element. -/\n\ndef max\u2080 : P := seq s rfl (fin.last s.dim)\n\nlemma max\u2080_mem : s.max\u2080 \u2208 s.val := seq_mem s rfl (fin.last s.dim)\n\nlemma le_max\u2080 (p : P) (hp : p \u2208 s.val) : p \u2264 s.max\u2080 := \nbegin\n  rw [\u2190 seq_rank s rfl p hp],\n  apply (seq_le s rfl (rank s rfl p hp) (fin.last s.dim)).mp,\n  apply fin.le_last\nend\n\nend els\n\n/-- The function max : subdiv P \u2192 P is monotone. -/\nlemma max\u2080_mono : monotone (max\u2080 : subdiv P \u2192 P) := \n  \u03bb s t hst, t.le_max\u2080 s.max\u2080 (hst s.max\u2080_mem)\n\nvariable (P)\n\ndef max : hom (subdiv P) P := \u27e8max\u2080,max\u2080_mono\u27e9\n\nlemma max_mem (s : subdiv P) : max P s \u2208 s.val := max\u2080_mem s\n\nlemma le_max (s : subdiv P) (p : P) (hp : p \u2208 s.val) : p \u2264 max P s := \nle_max\u2080 s p hp\n\nlemma max_vertex (p : P) : max P (vertex p) = p := \n finset.mem_singleton.mp (max\u2080_mem (vertex p))\n\nlemma max_cofinal : cofinal\u2095 (max P) := \nbegin\n  intro p,\n  let C := comma (max P) p,\n  let c : C := \u27e8vertex p,by {rw[max_vertex]}\u27e9, \n  let T := punit.{uP + 1},\n  let f : hom C T := const C punit.star, \n  let g : hom T C := const T c,\n  have hfg : comp f g = id T := \n  by { ext t, rcases t, refl },\n  let m\u2080 : C \u2192 C := \u03bb x, \n  begin\n    let \u03c4\u2080 := x.val.val \u222a {p},\n    have h\u2080 : \u03c4\u2080.nonempty := \u27e8_,(finset.mem_union_right _ (finset.mem_singleton_self p))\u27e9,\n    have h\u2081 : is_chain \u03c4\u2080 := \u03bb a ha b hb, \n    begin\n      rcases finset.mem_union.mp ha with hax | hap;\n      rcases finset.mem_union.mp hb with hbx | hbp,\n      { exact x.val.property.2 a hax b hbx },\n      { left, \n        rw [finset.mem_singleton.mp hbp],\n        exact le_trans (le_max P x.val a hax) x.property },\n      { right,\n        rw [finset.mem_singleton.mp hap],\n        exact le_trans (le_max P x.val b hbx) x.property },\n      { left, \n        rw [finset.mem_singleton.mp hbp],\n        rw [finset.mem_singleton.mp hap] }\n    end,\n    let \u03c4 : subdiv P := \u27e8\u03c4\u2080,\u27e8h\u2080,h\u2081\u27e9\u27e9,\n    have h\u2082 : max P \u03c4 \u2264 p := \n    begin\n      rcases finset.mem_union.mp (max_mem P \u03c4) with h | h,\n      { exact le_trans (le_max P x.val _ h) x.property },\n      { rw [finset.mem_singleton.mp h] } \n    end,\n    exact \u27e8\u03c4,h\u2082\u27e9\n  end,\n  have m\u2080_mono : monotone m\u2080 := \u03bb x\u2080 x\u2081 h,\n  begin\n    change x\u2080.val.val \u2286 x\u2081.val.val at h,\n    change x\u2080.val.val \u222a {p} \u2286 x\u2081.val.val \u222a {p},\n    intros a ha,\n    rcases finset.mem_union.mp ha with hax | hap,\n    { exact finset.mem_union_left _ (h hax) },\n    { exact finset.mem_union_right _ hap }\n  end,\n  let m : hom C C := \u27e8m\u2080,m\u2080_mono\u27e9,\n  have hm\u2080 : comp g f \u2264 m := \u03bb x a ha, \n  begin\n    change a \u2208 {p} at ha,\n    change a \u2208 x.val.val \u222a {p},\n    exact finset.mem_union_right _ ha\n  end,\n  have hm\u2081 : id C \u2264 m := \u03bb x a ha,\n  begin\n    change a \u2208 x.val.val at ha,\n    change a \u2208 x.val.val \u222a {p},\n    exact finset.mem_union_left _ ha\n  end,\n  let hgf := (\u03c0\u2080.sound hm\u2080).trans (\u03c0\u2080.sound hm\u2081).symm,\n  have e : equiv\u2095 C T := \n  { to_fun := component f,\n    inv_fun := component g,\n    left_inv := hgf,\n    right_inv := congr_arg component hfg },\n  exact \u27e8e\u27e9 \nend\n\nend subdiv\n\nend poset", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/poset/subdiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.7012458741630778}}
{"text": "import data.nat.basic\n\ninductive weekday : Type\n| sunday : weekday\n| monday : weekday\n| tuesday : weekday\n| wednesday : weekday\n| thursday : weekday\n| friday : weekday\n| saturday : weekday\n\n#check weekday.sunday\n#check weekday.monday\n\nopen weekday\n\n#check sunday\n#check monday\n\n#check weekday.rec\n#check weekday.rec_on\n#check weekday.cases_on\n\nnamespace weekday\n  @[reducible]\n  private def cases_on := @weekday.cases_on\n\n  def number_of_day (d : weekday) : nat :=\n  cases_on d 1 2 3 4 5 6 7\n\n def next (d : weekday) : weekday :=\n  weekday.cases_on d monday tuesday wednesday thursday friday\n    saturday sunday\n\n  def previous (d : weekday) : weekday :=\n  weekday.cases_on d saturday sunday monday tuesday wednesday\n    thursday friday\n\n  #reduce next (next tuesday)\n  #reduce next (previous tuesday)\n\n  example : next (previous tuesday) = tuesday := rfl\n\n  theorem next_previous (d: weekday) : next (previous d) = d :=\n    by apply weekday.cases_on d; refl\nend weekday\n\n#reduce weekday.number_of_day weekday.sunday\n\nopen weekday (renaming cases_on \u2192 cases_on)\n\n#reduce number_of_day sunday\n#check cases_on\n\n#check @nat.cases_on\n#check @nat.rec_on\n\nopen nat\n\ntheorem zero_add' (n : \u2115) : 0 + n = n :=\nnat.rec_on n rfl (\u03bb n ih, by rw [add_succ, ih])\n\ntheorem zero_add'' (n : \u2115) : 0 + n = n :=\nbegin\napply n.rec_on,\n  refl,\nintros n ih,\ncalc\n  0 + succ n = succ (0 + n) : rfl\n  ... = succ n : by rw ih\nend\n\ntheorem zero_add''' (n : \u2115) : 0 + n = n :=\nbegin\napply n.rec_on,\n  refl,\nintros n ih,\nhave : 0 + succ n = succ (0 + n),\n  refl,\nrw this,\nrw ih\nend\n\n\ntheorem add_assoc'' (m n k : \u2115) : m + n + k = m + (n + k) :=\nbegin\napply k.rec_on,\n  refl,\nintros k ih,\ncalc\n  m + n + succ k = succ (m + n + k) : rfl\n  ... = succ (m + (n + k)) : by rw ih\nend\n\n#print add_succ\n\n\ntheorem succ_add' (m n : nat) : succ m + n = succ (m + n) :=\nbegin\napply n.rec_on,\n  refl,\nintros n ih,\nrw add_succ,\nrw ih\nend\n\ntheorem add_comm' (m n : nat) : m + n = n + m :=\nbegin\napply n.rec_on,\n  rw add_zero,\n  rw zero_add,\nintros n ih,\nrw succ_add',\nrw \u2190ih\nend\n\n#check @list.rec\n#check @list.rec_on\n\nuniverse u\n\ninductive list' (\u03b1 : Type u)\n| nil {} : list'\n| cons : \u03b1 \u2192 list' \u2192 list'\n\nnamespace list'\n\nnotation `\u2983` l:(foldr `,` (h t, cons h t) nil) `\u2984` := l\n\nsection\n  open nat\n  #check ([1, 2, 3, 4, 5] : list int)\nend\n\nend list'\n\nvariable p : \u2115 \u2192 Prop\n\nexample (hz : p 0) (hs : \u2200 n, p (succ n)) : \u2200 n, p n :=\nbegin\n  intro n,\n  cases n,\n  { exact hz },  -- goal is p 0\n  apply hs       -- goal is a : \u2115 \u22a2 p (succ a)\nend\n\nexample (n : \u2115) (h : n \u2260 0) : succ (pred n) = n :=\nbegin\n  cases n with m,\n  -- first goal: h : 0 \u2260 0 \u22a2 succ (pred 0) = 0\n    { apply (absurd rfl h) },\n  -- second goal: h : succ m \u2260 0 \u22a2 succ (pred (succ a)) = succ a\n  reflexivity\nend\n\n\nexample (hz : p 0) (hs : \u2200 n, p (succ n)) (m k : \u2115) :\n  p (m + 3 * k) :=\nbegin\n  cases (m + 3 * k),\n  { exact hz },  -- goal is p 0\n  apply hs       -- goal is a : \u2115 \u22a2 p (succ a)\nend\n\ntheorem zero_add_t (n : \u2115) : 0 + n = n :=\nbegin\ninduction n,\n  case succ : n ih {\n    rw add_succ,\n    rw ih\n  },\n\n  case zero {\n    refl\n  }\nend\n\nexample (m n k : \u2115) (h : succ (succ m) = succ (succ n)) :\n  n + k = m + k :=\nbegin\n  injection h with h',\n  injection h' with h'',\n  rw h''\nend\n\nexample (m n k : \u2115) (h : succ (succ m) = succ (succ n)) :\n  n + k = m + k :=\nbegin\n  injections with h' h'',\n  rw h''\nend\n\nexample (m n : \u2115) (h : succ m = 0) : n = n + 7 :=\nby injections\n\nexample (m n : \u2115) (h : succ m = 0) : n = n + 7 :=\nby contradiction\n\nexample (h : 7 = 4) : false :=\nby injections\n\nmutual inductive even, odd\nwith even : \u2115 \u2192 Prop\n| even_zero : even 0\n| even_succ : \u2200 n, odd n \u2192 even (n + 1)\nwith odd : \u2115 \u2192 Prop\n| odd_succ : \u2200 n, even n \u2192 odd (n + 1)\n\n#print even\n#print odd", "meta": {"author": "michens", "repo": "learn-lean", "sha": "f38fc342780ddff5a164a18e5482163dea506ccd", "save_path": "github-repos/lean/michens-learn-lean", "path": "github-repos/lean/michens-learn-lean/learn-lean-f38fc342780ddff5a164a18e5482163dea506ccd/tpil/inductive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789040926007, "lm_q2_score": 0.8652240860523327, "lm_q1q2_score": 0.7012458690582166}}
{"text": "import tactic\nimport analysis.normed_space.basic\nimport analysis.complex.basic\nimport analysis.calculus.deriv\nimport measure_theory.integral.interval_integral\nnoncomputable theory\n\nsection order\n\nvariables {\u03b1 : Type*}[linear_order \u03b1]\n\nlemma Ioo_subset_interval {a b :\u03b1}:\nset.Ioo a b \u2286 set.interval a b :=\nset.subset.trans set.Ioo_subset_Icc_self set.Icc_subset_interval\n\nlemma Iio_inter_Icc {a b: \u03b1}:\nset.Iio b \u2229 set.Icc a b = set.Ico a b :=\nby {rw subset_antisymm_iff, split,\nrw [set.Iio, set.Icc, set.Ico], intros x x_in, \nsimp at x_in, simp, split, exact x_in.2.1,\nexact x_in.1, rw set.subset_inter_iff, split,\nexact set.Ico_subset_Iio_self,\nexact set.Ico_subset_Icc_self,} \n\nend order\n\nsection topology\n\nuniverses u v\n\nvariables {\u03b1 : Type u}{\u03b2 : Type v}\nvariables [topological_space \u03b1]\n\n-- modified from eventually_nhds_iff\nlemma eventually_nhds_eq_iff {a : \u03b1} {f g : \u03b1 \u2192 \u03b2} :\n  (\u2200\u1da0 x in nhds a, f x = g x) \u2194 \u2203 (t : set \u03b1), (\u2200 x \u2208 t, f x = g x) \u2227 is_open t \u2227 a \u2208 t := \n  mem_nhds_iff.trans $ by simp only [set.subset_def, exists_prop, set.mem_set_of_eq]\n\nend topology\n\nsection complex\n\nlemma continuous_on_log_of_upper_plane:\n  continuous_on complex.log {z : \u2102 | 0 \u2264 z.im \u2227 z\u2260 0}:=\nbegin\n  intros z z_in,\n  simp at z_in,\n  by_cases him:z.im=0,\n  by_cases hre:z.re<0,\n  {\n    apply continuous_within_at.mono,\n    exact complex.continuous_within_at_log_of_re_neg_of_im_zero\n      hre him,\n    simp, intros a a_in_1 a_in_2, exact a_in_1,\n  },\n  {\n    apply continuous_at.continuous_within_at,\n    apply continuous_at_clog, \n    left, simp at hre, by_cases z.re=0,\n    exfalso, exact z_in.2 (complex.ext h him),\n    exact (ne.symm h).lt_of_le hre,\n  },\n  {\n    apply continuous_at.continuous_within_at,\n    apply continuous_at_clog, \n    right, exact him,\n  },\nend\n\nend complex\n\nsection integral\n\nvariables {E : Type} \n[normed_add_comm_group E] [normed_space \u2102 E] [complete_space E] \n\nlemma interval_integrable_iff_integrable_Ico_of_le {\u03bc:measure_theory.measure \u211d}\n{f : \u211d \u2192 E} {a b : \u211d} (hab : a \u2264 b) [measure_theory.has_no_atoms \u03bc] :\n  interval_integrable f \u03bc a b \u2194 measure_theory.integrable_on f (set.Ico a b) \u03bc :=\nbegin\n  rw interval_integrable_iff',\n  split,\n  have hinc: set.interval a b = (set.Ico a b) \u222a {b} := by rw [set.interval_of_le hab, set.Ico_union_right hab],\n  rw hinc,\n  intro condition,\n  exact measure_theory.integrable_on.left_of_union condition,\n  intro condition,\n  apply integrable_on_Icc_iff_integrable_on_Ioo.2,\n  have minab:min a b=a:= by rw [min_eq_left hab],\n  have maxab:max a b=b:= by rw [max_eq_right hab],\n  rw minab,\n  rw maxab,\n  cases decidable.em (a = b) with heq hneq,\n  {rw [heq, set.Ioo_eq_empty _], simp, simp,},\n  {\n    have h : a < b := ne.lt_of_le hneq hab,\n    have hinc:set.Ico a b= set.Ioo a b \u222a {a} := by rw [\u2190set.Ioo_union_left h],\n    rw hinc at condition,\n    exact measure_theory.integrable_on.left_of_union condition,\n  },\n  exact _inst_4,\nend\n\nlemma interval_integrable_iff_integrable_Ioo_of_le {\u03bc:measure_theory.measure \u211d}\n{f : \u211d \u2192 E} {a b : \u211d} (hab : a \u2264 b) [measure_theory.has_no_atoms \u03bc] :\n  interval_integrable f \u03bc a b \u2194 measure_theory.integrable_on f (set.Ioo a b) \u03bc :=\nbegin\n  rw interval_integrable_iff_integrable_Icc_of_le hab,\n  exact integrable_on_Icc_iff_integrable_on_Ioo,\n  exact _inst_4,\nend\n\nlemma integral_congr'''{\u03bc:measure_theory.measure \u211d}{a b : \u211d}\n{f g : \u211d \u2192 E} (hab : a \u2264 b) (h : set.eq_on f g (set.Ioo a b))\n[measure_theory.has_no_atoms \u03bc] :\n  \u222b x in a..b, f x \u2202\u03bc = \u222b x in a..b, g x \u2202\u03bc :=\nbegin\n  repeat {rw interval_integral.integral_of_le hab,},\n  repeat {rw measure_theory.set_integral_congr_set_ae\n    measure_theory.Ioo_ae_eq_Ioc.symm,},\n  exact measure_theory.set_integral_congr measurable_set_Ioo h,\n  exact _inst_4, exact _inst_4,\nend\n\nlemma integral_congr' {\u03bc:measure_theory.measure \u211d}{a b : \u211d}\n{f g : \u211d \u2192 E} (hab : a \u2264 b) (h : set.eq_on f g (set.Ioc a b)) :\n  \u222b x in a..b, f x \u2202\u03bc = \u222b x in a..b, g x \u2202\u03bc :=\nbegin \nlet ha : \u222b (x : \u211d) in set.Ioc a b, f x \u2202\u03bc = \u222b (x : \u211d) in set.Ioc a b, g x \u2202\u03bc := measure_theory.set_integral_congr measurable_set_Ioc h,\n  simp [interval_integral, hab],\n  simp at ha,\n  exact ha,\nend\n\nlemma integral_congr''  {a b : \u211d}{f g : \u211d \u2192 E}{a b : \u211d} \n(hab : a \u2264 b) (h : set.eq_on f g (set.Ico a b)) :\n  \u222b x in a..b, f x = \u222b x in a..b, g x :=\nbegin\n  let f' := \u03bb x, f (- x),\n  let g' := \u03bb x, g (- x),\n  have hf' : (\u03bb x, f (- x))= (\u03bb x, f' x) := by simp,\n  have hg' : (\u03bb x, g (- x))= (\u03bb x, g' x) := by simp,\n  have h1 : set.eq_on f' g' (set.Ioc (- b) (- a)) := \n    begin\n      unfold set.eq_on,\n      simp,\n      intro x,\n      let y := - x,\n      have h_ : x = - y := by simp,\n      rw h_,\n      intros hy1 hy2,\n      have hf' : f' (- y) = f y := by simp, \n      have hg' : g' (- y) = g y := by simp, \n      rw [hf', hg'],\n      unfold set.eq_on at h,\n      have hy1' := (iff.elim_right (mul_lt_mul_right_of_neg neg_one_lt_zero)) hy1,\n      simp only [neg_mul_neg,mul_one] at hy1', \n      have hy2' := (iff.elim_right (mul_le_mul_right_of_neg neg_one_lt_zero)) hy2,\n      simp only [neg_mul_neg,mul_one] at hy2', \n      have hy : y \u2208 set.Ico a b := \n        begin \n          unfold set.Ico, \n          simp,\n          exact and.intro hy2' hy1',\n        end,\n      exact h hy,\n    end,\n  have hba := (iff.elim_right (mul_le_mul_right_of_neg neg_one_lt_zero)) hab,\n  simp only [mul_neg_one] at hba,\n  have h2 : \u222b (x : \u211d) in -b..-a, f' x = \u222b (x : \u211d) in -b..-a, g' x := integral_congr' hba h1,\n  rw [\u2190hf', \u2190hg'] at h2,\n  rw[interval_integral.integral_comp_neg] at h2,\n  rw[interval_integral.integral_comp_neg] at h2,\n  simp at h2,\n  exact h2,\nend\n\nlemma volume_add_right (a : \u211d) :\n  measure_theory.measure.map ((+) a) measure_theory.measure_space.volume = \n  measure_theory.measure_space.volume :=\nbegin\n  have t:=real.is_add_left_invariant_real_volume.map_add_left_eq_self,\n  exact t a,\nend\n\nlemma integrable_comp_add_left {f:\u211d \u2192 E}{a b:\u211d}\n(hf : interval_integrable f measure_theory.measure_space.volume a b) \n(h : \u211d) :\n  interval_integrable (\u03bb x, f (h+x)) measure_theory.measure_space.volume (a-h) (b-h) :=\nbegin\n  rw interval_integrable_iff' at hf \u22a2,\n  have A : measurable_embedding (\u03bb x, (-h)+x) :=\n    measurable_embedding_add_left (-h),\n  rw [\u2190volume_add_right (-h), measure_theory.integrable_on, \n      \u2190measure_theory.integrable_on, measurable_embedding.integrable_on_map_iff A],\n  convert hf using 1,\n  { ext, simp, },\n  { simp,},\nend\n\n/- The following codes are from Oliver Nash and Bhavik Mehta. \nSee Zulip discussion https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/ae.20measurable.20condition \n-/\nlemma interval_integrable_norm_iff {f : \u211d \u2192 E} {\u03bc : measure_theory.measure \u211d} {a b : \u211d}\n  (hf : measure_theory.ae_strongly_measurable f (\u03bc.restrict (set.interval_oc a b))) :\n  interval_integrable (\u03bb t, \u2225f t\u2225) \u03bc a b \u2194 interval_integrable f \u03bc a b :=\nbegin\n  simp_rw [interval_integrable_iff, measure_theory.integrable_on],\n  exact measure_theory.integrable_norm_iff hf,\nend \n\nlemma smul_continuous_on\n{\u03bc : measure_theory.measure \u211d} {a b : \u211d} {f : \u211d \u2192 \u2102} {g : \u211d \u2192 E}\n  (hf : measure_theory.ae_strongly_measurable f (\u03bc.restrict (set.interval_oc a b)))\n  (hg : continuous_on g (set.interval a b)) :\n  measure_theory.ae_strongly_measurable (\u03bb x, f x \u2022 g x) (\u03bc.restrict (set.interval_oc a b)) :=\nhf.smul ((hg.mono set.Ioc_subset_Icc_self).ae_strongly_measurable measurable_set_interval_oc)\n\nlemma interval_integrable.smul_continuous_on \n{\u03bc : measure_theory.measure \u211d} {a b : \u211d} {f : \u211d \u2192 \u2102} {g : \u211d \u2192 E}\n  (hf : interval_integrable f \u03bc a b) \n  (hg : continuous_on g (set.interval a b)) :\n  interval_integrable (\u03bb x, f x \u2022 g x) \u03bc a b :=\nbegin\nhave hf' : measure_theory.ae_strongly_measurable (\u03bb (t : \u211d), f t) (\u03bc.restrict (set.interval_oc a b)),\n  { -- Missing lemma for `Ioc a b` case.\n    rcases le_or_gt a b with h | h,\n    { convert hf.ae_strongly_measurable,\n      exact set.interval_oc_of_le h, },\n    { convert hf.ae_strongly_measurable',\n      rw set.interval_oc_swap, -- Missing lemma `interval_oc_of_ge`\n      exact set.interval_oc_of_le (le_of_lt h), }, },\n  rw \u2190 interval_integrable_norm_iff,\n  { simp_rw norm_smul,\n    refine interval_integrable.mul_continuous_on _ (continuous_norm.comp_continuous_on hg),\n    simp at hf',\n    rw interval_integrable_norm_iff hf',\n    assumption, },\n  exact smul_continuous_on hf' hg,\nend\n\nend integral\n", "meta": {"author": "xinhjBrant", "repo": "prime-number-theorem", "sha": "e23408949a2d158070a2dc1dcf69da1f4a5c50be", "save_path": "github-repos/lean/xinhjBrant-prime-number-theorem", "path": "github-repos/lean/xinhjBrant-prime-number-theorem/prime-number-theorem-e23408949a2d158070a2dc1dcf69da1f4a5c50be/src/tomathlib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7012458645690249}}
{"text": "-- See: https://leanprover.github.io/logic_and_proof/first_order_logic_in_lean.html\n\n-- My \"hello, world\" in Lean\n-- Here \"love\" refers to romantic attraction only\n\nconstant Person : Type\n  -- Domain of discourse\n\nconstant Loves : Person \u2192 Person \u2192 Prop\n  -- (Loves a b) means \"a loves b\"\n\nconstant BetterThan : Person \u2192 Person \u2192 Person \u2192 Prop\n  -- (BetterThan a b c) means \"a thinks that b is better than c\"\n\nconstant QZR : Person\n  -- Me.\n\naxiom exclusiveness :\n  \u2200(x y : Person), Loves x y \u2192 (\u2200z : Person, z \u2260 y \u2192 \u00ac(Loves x z))\n  -- Exclusiveness: Everyone loves at most one person.\n\naxiom preference :\n  \u2200(x y z : Person), BetterThan x y z \u2192 (Loves x z \u2192 Loves x y)\n  -- Preference: if x thinks that y is better than z,\n  --             that means x will also fall in love with y if x appreciates z.\n\naxiom shadowing :\n  \u2203y : Person, (y \u2260 QZR \u2227 (\u2200x : Person, BetterThan x y QZR))\n  -- Shadowing: there is someone who is better than QZR in everyone's eyes.\n\ntheorem no_one_loves_QZR : \u00ac(\u2203x : Person, Loves x QZR) :=\n-- (Tactic mode proof)\nbegin\n  intros hx,\n  cases hx with x hx,\n  cases shadowing with y hy,\n  cases hy with hy\u2081 hy\u2082,\n  specialize hy\u2082 x,\n  have hnxy : \u00acLoves x y, {\n    have hx\u2081 := (exclusiveness x QZR) hx,\n    specialize hx\u2081 y,\n    exact hx\u2081 hy\u2081,\n  },\n  have hxy : Loves x y, {\n    have hy\u2083 := (preference x y QZR) hy\u2082 hx,\n    exact hy\u2083,\n  },\n  exact hnxy hxy,\nend\n\ntheorem no_one_loves_QZR' : \u00ac(\u2203x : Person, Loves x QZR) :=\n-- (Term mode proof)\n  \u03bb \u27e8x, hx\u27e9,\n    let \u27e8z, hz\u2081, hz\u2082\u27e9 := shadowing in\n      (exclusiveness x QZR hx) z hz\u2081 (preference x z QZR (hz\u2082 x) hx)\n", "meta": {"author": "bridgekat", "repo": "lean-notes", "sha": "18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d", "save_path": "github-repos/lean/bridgekat-lean-notes", "path": "github-repos/lean/bridgekat-lean-notes/lean-notes-18ee3dec74cfc52cb2dcd9cf33f30c4bba87c09d/src/experiments/loves.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.7012447602733212}}
{"text": "import data.complex.basic \nimport data.fintype.basic \nimport data.matrix.basic\nimport linear_algebra.determinant\nimport linear_algebra.nonsingular_inverse\nimport tactic \n\nnoncomputable theory \nopen_locale classical\nopen_locale matrix\nopen_locale big_operators\n\nuniverses u u'\nvariables {m n l : Type u} [fintype m] [fintype n] [fintype l]\n\nlocal notation `Euc` := (n \u2192 \u2102)\n\nnamespace matrix\n/-- Complex conjugate of a vector.-/\ndef conj (M : matrix m n \u2102) : matrix m n \u2102 := \n\u03bb i j, complex.conj (M i j)\n\n@[simp] \nlemma conj_val (M : matrix m n \u2102) (i j) : conj M i j = complex.conj (M i j) := rfl\n\ndef complex_transpose (M : matrix m n \u2102) : matrix n m \u2102 :=\nM.transpose.conj\nend matrix\n\nsection complex_transpose\nopen complex matrix\n/--\n  Tell `simp` what the entries are in a transposed matrix.\n-/\n@[simp] lemma complex_transpose_val (M : matrix m n \u2102) (i j) : M.complex_transpose j i = complex.conj (M i j) := rfl\n\n@[simp] lemma complex_transpose_transpose (M : matrix m n \u2102) :\n  M.complex_transpose.complex_transpose = M :=\nby ext; simp\n\n@[simp] lemma complex_transpose_zero : (0 : matrix m n \u2102).complex_transpose = 0 :=\nby ext; simp\n\n@[simp] lemma complex_transpose_one [decidable_eq n] : (1 : matrix n n \u2102).complex_transpose = 1 := \nby ext; simp [matrix.one_val]; split_ifs; simp; cc\n\n@[simp] lemma complex_transpose_add (M : matrix m n \u2102) (N : matrix m n \u2102) :\n  (M + N).complex_transpose = M.complex_transpose + N.complex_transpose  :=\nby ext; simp\n\n@[simp] lemma complex_transpose_neg (M : matrix m n \u2102) :\n  (- M).complex_transpose = - M.complex_transpose  :=\nby ext; simp \n\n@[simp] lemma complex_transpose_sub (M : matrix m n \u2102) (N : matrix m n \u2102) :\n  (M - N).complex_transpose = M.complex_transpose - N.complex_transpose  :=\nby ext; simp\n\n@[simp] lemma complex_transpose_mul (M : matrix m n \u2102) (N : matrix n l \u2102) :\n  (M \u2b1d N).complex_transpose = N.complex_transpose \u2b1d M.complex_transpose  :=\nbegin\n  ext; simp, delta matrix.mul, delta matrix.dot_product, simp,\n  -- rw add_monoid_hom.map_sum, -- I think this would work if re were a bundled hom\n  {sorry}, \n  {sorry}\nend\n\n@[simp] lemma complex_transpose_smul (c : \u2102) (M : matrix m n \u2102) :\n  (c \u2022 M).complex_transpose = complex.conj c \u2022 M.complex_transpose :=\nby ext; simp\n\nlemma det_complex_conj {M : matrix n n \u2102} :\n  M.conj.det = M.det.conj :=\nsorry\n\n@[simp]\nlemma det_complex_transpose {M : matrix n n \u2102} : \nM.complex_transpose.det = complex.conj (M.det) :=\nby {unfold matrix.complex_transpose, rw [det_complex_conj, matrix.det_transpose]}\n\nend complex_transpose", "meta": {"author": "apurvanakade", "repo": "mc2020-lean-projects", "sha": "02466225aa629ab1232043bcc0a053a099fdb939", "save_path": "github-repos/lean/apurvanakade-mc2020-lean-projects", "path": "github-repos/lean/apurvanakade-mc2020-lean-projects/mc2020-lean-projects-02466225aa629ab1232043bcc0a053a099fdb939/src/apurva/complex_transpose.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479467, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7012356460000297}}
{"text": "-- Las irreflexivas y transitivas son asim\u00e9tricas\n-- ==============================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar que las relaciones irreflexivas y \n-- transitivas son asim\u00e9tricas.\n-- ----------------------------------------------------\n\nvariable A : Type\nvariable R : A \u2192 A \u2192 Prop\n\n-- #reduce irreflexive R\n-- #reduce transitive R\n\n-- 1\u00aa demostraci\u00f3n\nexample \n  (h1 : irreflexive R) \n  (h2 : transitive R) \n  : \u2200 x y, R x y \u2192 \u00ac R y x :=\nbegin\n  intros x y h3 h4,\n  apply h1 x,\n  apply h2 h3 h4,\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample \n  (h1 : irreflexive R) \n  (h2 : transitive R) \n  : \u2200 x y, R x y \u2192 \u00ac R y x :=\nbegin\n  intros x y h3 h4,\n  apply (h1 x) (h2 h3 h4),\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample \n  (h1 : irreflexive R) \n  (h2 : transitive R) \n  : \u2200 x y, R x y \u2192 \u00ac R y x :=\n\u03bb x y h3 h4, (h1 x) (h2 h3 h4)\n\n-- 4\u00aa demostraci\u00f3n\nexample \n  (h1 : irreflexive R) \n  (h2 : transitive R) \n  : \u2200 x y, R x y \u2192 \u00ac R y x :=\nassume x y,\nassume h3 : R x y,\nassume h4 : R y x,\nhave h5 : R x x, from h2 h3 h4,\nhave h6 : \u00ac R x x, from h1 x,\nshow false, from h6 h5\n", "meta": {"author": "jaalonso", "repo": "Logica_con_Lean", "sha": "beb6765c6ff3c05590a03f45722eda0c815a25cd", "save_path": "github-repos/lean/jaalonso-Logica_con_Lean", "path": "github-repos/lean/jaalonso-Logica_con_Lean/Logica_con_Lean-beb6765c6ff3c05590a03f45722eda0c815a25cd/src/4_Relaciones/Las_irreflexivas_y_transitivas_son_asimetricas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7012356418348015}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Wrenna Robson\n-/\n\nimport algebra.big_operators.basic\nimport linear_algebra.vandermonde\nimport ring_theory.polynomial.basic\n\n/-!\n# Lagrange interpolation\n\n## Main definitions\n* In everything that follows, `s : finset \u03b9` is a finite set of indexes, with `v : \u03b9 \u2192 F` an\nindexing of the field over some type. We call the image of v on s the interpolation nodes,\nthough strictly unique nodes are only defined when v is injective on s.\n* `lagrange.basis_divisor x y`, with `x y : F`. These are the normalised irreducible factors of\nthe Lagrange basis polynomials. They evaluate to `1` at `x` and `0` at `y` when `x` and `y`\nare distinct.\n* `lagrange.basis v i` with `i : \u03b9`: the Lagrange basis polynomial that evaluates to `1` at `v i`\nand `0` at `v j` for `i \u2260 j`.\n* `lagrange.interpolate v r` where `r : \u03b9 \u2192 F` is a function from the fintype to the field: the\nLagrange interpolant that evaluates to `r i` at `x i` for all `i : \u03b9`. The `r i` are the _values_\nassociated with the _nodes_`x i`.\n* `lagrange.interpolate_at v f`, where `v : \u03b9 \u21aa F` and `\u03b9` is a fintype, and `f : F \u2192 F` is a\nfunction from the field to itself: this is the Lagrange interpolant that evaluates to `f (x i)`\nat `x i`, and so approximates the function `f`. This is just a special case of the general\ninterpolation, where the values are given by a known function `f`.\n-/\n\nopen_locale polynomial big_operators\n\nsection polynomial_determination\n\nnamespace polynomial\nvariables {R : Type*} [comm_ring R] [is_domain R] {f g : R[X]}\n\nsection finset\nopen function fintype\nvariables (s : finset R)\n\ntheorem eq_zero_of_degree_lt_of_eval_finset_eq_zero (degree_f_lt : f.degree < s.card)\n  (eval_f : \u2200 x \u2208 s, f.eval x = 0) : f = 0 :=\nbegin\n  rw \u2190 mem_degree_lt at degree_f_lt,\n  simp_rw eval_eq_sum_degree_lt_equiv degree_f_lt at eval_f,\n  rw \u2190 degree_lt_equiv_eq_zero_iff_eq_zero degree_f_lt,\n  exact matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero\n    (injective.comp (embedding.subtype _).inj' (equiv_fin_of_card_eq (card_coe _)).symm.injective)\n    (\u03bb _, eval_f _ (finset.coe_mem _))\nend\n\ntheorem eq_of_degree_sub_lt_of_eval_finset_eq (degree_fg_lt : (f - g).degree < s.card)\n  (eval_fg : \u2200 x \u2208 s, f.eval x = g.eval x) : f = g :=\nbegin\n  rw \u2190 sub_eq_zero,\n  refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_fg_lt _,\n  simp_rw [eval_sub, sub_eq_zero],\n  exact eval_fg\nend\n\ntheorem eq_of_degrees_lt_of_eval_finset_eq (degree_f_lt : f.degree < s.card)\n  (degree_g_lt : g.degree < s.card) (eval_fg : \u2200 x \u2208 s, f.eval x = g.eval x) : f = g :=\nbegin\n  rw \u2190 mem_degree_lt at degree_f_lt degree_g_lt,\n  refine eq_of_degree_sub_lt_of_eval_finset_eq _ _ eval_fg,\n  rw \u2190 mem_degree_lt, exact submodule.sub_mem _ degree_f_lt degree_g_lt\nend\n\nend finset\n\nsection indexed\nopen finset\nvariables {\u03b9 : Type*} {v : \u03b9 \u2192 R} (s : finset \u03b9)\n\ntheorem eq_zero_of_degree_lt_of_eval_index_eq_zero (hvs : set.inj_on v s)\n  (degree_f_lt : f.degree < s.card) (eval_f : \u2200 i \u2208 s, f.eval (v i) = 0) : f = 0 :=\nbegin\n  classical,\n  rw \u2190 card_image_of_inj_on hvs at degree_f_lt,\n  refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_f_lt _,\n  intros x hx,\n  rcases mem_image.mp hx with \u27e8_, hj, rfl\u27e9,\n  exact eval_f _ hj\nend\n\ntheorem eq_of_degree_sub_lt_of_eval_index_eq (hvs : set.inj_on v s)\n  (degree_fg_lt : (f - g).degree < s.card) (eval_fg : \u2200 i \u2208 s, f.eval (v i) = g.eval (v i)) :\n  f = g :=\nbegin\n  rw \u2190 sub_eq_zero,\n  refine eq_zero_of_degree_lt_of_eval_index_eq_zero _ hvs degree_fg_lt _,\n  simp_rw [eval_sub, sub_eq_zero],\n  exact eval_fg\nend\n\ntheorem eq_of_degrees_lt_of_eval_index_eq (hvs : set.inj_on v s) (degree_f_lt : f.degree < s.card)\n  (degree_g_lt : g.degree < s.card) (eval_fg : \u2200 i \u2208 s, f.eval (v i) = g.eval (v i)) : f = g :=\nbegin\n  refine eq_of_degree_sub_lt_of_eval_index_eq _ hvs _ eval_fg,\n  rw \u2190 mem_degree_lt at degree_f_lt degree_g_lt \u22a2,\n  exact submodule.sub_mem _ degree_f_lt degree_g_lt\nend\n\nend indexed\n\nend polynomial\n\nend polynomial_determination\n\nnoncomputable theory\n\nnamespace lagrange\nopen polynomial\nvariables {F : Type*} [field F]\n\nsection basis_divisor\nvariables {x y : F}\n/-- `basis_divisor x y` is the unique linear or constant polynomial such that\nwhen evaluated at `x` it gives `1` and `y` it gives `0` (where when `x = y` it is identically `0`).\nSuch polynomials are the building blocks for the Lagrange interpolants. -/\ndef basis_divisor (x y : F) : F[X] := C ((x - y)\u207b\u00b9) * (X - C (y))\n\nlemma basis_divisor_self : basis_divisor x x = 0 :=\nby simp only [basis_divisor, sub_self, inv_zero, map_zero, zero_mul]\n\nlemma basis_divisor_inj (hxy : basis_divisor x y = 0) : x = y :=\nbegin\n  simp_rw [basis_divisor, mul_eq_zero, X_sub_C_ne_zero, or_false,\n            C_eq_zero, inv_eq_zero, sub_eq_zero] at hxy,\n  exact hxy\nend\n\n@[simp] lemma basis_divisor_eq_zero_iff : basis_divisor x y = 0 \u2194 x = y :=\n\u27e8basis_divisor_inj, \u03bb H, H \u25b8 basis_divisor_self\u27e9\n\nlemma basis_divisor_ne_zero_iff : basis_divisor x y \u2260 0 \u2194 x \u2260 y :=\nby rw [ne.def, basis_divisor_eq_zero_iff]\n\nlemma degree_basis_divisor_of_ne (hxy : x \u2260 y) : (basis_divisor x y).degree = 1 :=\nbegin\n  rw [basis_divisor, degree_mul, degree_X_sub_C, degree_C, zero_add],\n  exact inv_ne_zero (sub_ne_zero_of_ne hxy)\nend\n\n@[simp] lemma degree_basis_divisor_self : (basis_divisor x x).degree = \u22a5 :=\nby rw [basis_divisor_self, degree_zero]\n\nlemma nat_degree_basis_divisor_self : (basis_divisor x x).nat_degree = 0 :=\nby rw [basis_divisor_self, nat_degree_zero]\n\nlemma nat_degree_basis_divisor_of_ne (hxy : x \u2260 y) : (basis_divisor x y).nat_degree = 1 :=\nnat_degree_eq_of_degree_eq_some (degree_basis_divisor_of_ne hxy)\n\n@[simp] lemma eval_basis_divisor_right : eval y (basis_divisor x y) = 0 :=\nby simp only [basis_divisor, eval_mul, eval_C, eval_sub, eval_X, sub_self, mul_zero]\n\nlemma eval_basis_divisor_left_of_ne (hxy : x \u2260 y) : eval x (basis_divisor x y) = 1 :=\nbegin\n  simp only [basis_divisor, eval_mul, eval_C, eval_sub, eval_X],\n  exact inv_mul_cancel (sub_ne_zero_of_ne hxy)\nend\n\nend basis_divisor\n\nsection basis\nopen finset\nvariables {\u03b9 : Type*} [decidable_eq \u03b9] {s : finset \u03b9} {v : \u03b9 \u2192 F} {i j : \u03b9}\n\n/-- Lagrange basis polynomials indexed by `s : finset \u03b9`, defined at nodes `v i` for a\nmap `v : \u03b9 \u2192 F`. For `i, j \u2208 s`, `basis s v i` evaluates to 0 at `v j` for `i \u2260 j`. When\n`v` is injective on `s`, `basis s v i` evaluates to 1 at `v i`. -/\nprotected def basis (s : finset \u03b9) (v : \u03b9 \u2192 F) (i : \u03b9) : F[X] :=\n\u220f j in s.erase i, basis_divisor (v i) (v j)\n\n@[simp] theorem basis_empty : lagrange.basis \u2205 v i = 1 := rfl\n\n@[simp] theorem basis_singleton (i : \u03b9) : lagrange.basis {i} v i = 1 :=\nby rw [lagrange.basis, erase_singleton, prod_empty]\n\n@[simp] theorem basis_pair_left (hij : i \u2260 j) :\n  lagrange.basis {i, j} v i = basis_divisor (v i) (v j) :=\nby simp only [lagrange.basis, hij, erase_insert_eq_erase, erase_eq_of_not_mem,\n              mem_singleton, not_false_iff, prod_singleton]\n\n@[simp] theorem basis_pair_right (hij : i \u2260 j) :\n  lagrange.basis {i, j} v j = basis_divisor (v j) (v i) :=\nby { rw pair_comm, exact basis_pair_left hij.symm }\n\nlemma basis_ne_zero (hvs : set.inj_on v s) (hi : i \u2208 s) : lagrange.basis s v i \u2260 0 :=\nbegin\n  simp_rw [lagrange.basis, prod_ne_zero_iff, ne.def, mem_erase],\n  rintros j \u27e8hij, hj\u27e9,\n  rw [basis_divisor_eq_zero_iff, hvs.eq_iff hi hj],\n  exact hij.symm\nend\n\n@[simp] theorem eval_basis_self (hvs : set.inj_on v s) (hi : i \u2208 s) :\n  (lagrange.basis s v i).eval (v i) = 1 :=\nbegin\n  rw [lagrange.basis, eval_prod],\n  refine prod_eq_one (\u03bb j H, _),\n  rw eval_basis_divisor_left_of_ne,\n  rcases mem_erase.mp H with \u27e8hij, hj\u27e9,\n  exact mt (hvs hi hj) hij.symm\nend\n\n@[simp] theorem eval_basis_of_ne (hij : i \u2260 j) (hj : j \u2208 s) :\n  (lagrange.basis s v i).eval (v j) = 0 :=\nbegin\n  simp_rw [lagrange.basis, eval_prod, prod_eq_zero_iff],\n  exact \u27e8j, \u27e8mem_erase.mpr \u27e8hij.symm, hj\u27e9, eval_basis_divisor_right\u27e9\u27e9\nend\n\n@[simp] theorem nat_degree_basis (hvs : set.inj_on v s) (hi : i \u2208 s) :\n  (lagrange.basis s v i).nat_degree = s.card - 1 :=\nbegin\n  have H : \u2200 j, j \u2208 s.erase i \u2192 basis_divisor (v i) (v j) \u2260 0,\n  { simp_rw [ne.def, mem_erase, basis_divisor_eq_zero_iff],\n    exact \u03bb j \u27e8hij\u2081, hj\u27e9 hij\u2082, hij\u2081 (hvs hj hi hij\u2082.symm) },\n  rw [\u2190 card_erase_of_mem hi, card_eq_sum_ones],\n  convert nat_degree_prod _ _ H using 1,\n  refine sum_congr rfl (\u03bb j hj, (nat_degree_basis_divisor_of_ne _).symm),\n  rw [ne.def, \u2190 basis_divisor_eq_zero_iff],\n  exact H _ hj\nend\n\ntheorem degree_basis (hvs : set.inj_on v s) (hi : i \u2208 s) :\n  (lagrange.basis s v i).degree = \u2191(s.card - 1) :=\nby rw [degree_eq_nat_degree (basis_ne_zero hvs hi), nat_degree_basis hvs hi]\n\nlemma sum_basis (hvs : set.inj_on v s) (hs : s.nonempty) : \u2211 j in s, (lagrange.basis s v j) = 1 :=\nbegin\n  refine eq_of_degrees_lt_of_eval_index_eq s hvs (lt_of_le_of_lt (degree_sum_le _ _) _) _ _,\n  { rw finset.sup_lt_iff (with_bot.bot_lt_coe s.card),\n    intros i hi,\n    rw [degree_basis hvs hi, with_bot.coe_lt_coe],\n    exact nat.pred_lt (card_ne_zero_of_mem hi) },\n  { rw [degree_one, \u2190 with_bot.coe_zero, with_bot.coe_lt_coe],\n    exact nonempty.card_pos hs },\n  { intros i hi,\n    rw [eval_finset_sum, eval_one, \u2190 add_sum_erase _ _ hi,\n        eval_basis_self hvs hi, add_right_eq_self],\n    refine sum_eq_zero (\u03bb j hj, _),\n    rcases mem_erase.mp hj with \u27e8hij, hj\u27e9,\n    rw eval_basis_of_ne hij hi }\nend\n\nlemma basis_divisor_add_symm {x y : F} (hxy : x \u2260 y) : basis_divisor x y + basis_divisor y x = 1 :=\nbegin\n  classical,\n  rw [\u2190sum_basis (set.inj_on_of_injective function.injective_id _) \u27e8x, mem_insert_self _ {y}\u27e9,\n      sum_insert (not_mem_singleton.mpr hxy), sum_singleton, basis_pair_left hxy,\n      basis_pair_right hxy, id, id]\nend\n\nend basis\n\nsection interpolate\nopen finset\nvariables {\u03b9 : Type*} [decidable_eq \u03b9] {s t : finset \u03b9} {i j : \u03b9} {v : \u03b9 \u2192 F} (r r' : \u03b9 \u2192 F)\n\n/-- Lagrange interpolation: given a finset `s : finset \u03b9`, a nodal map  `v : \u03b9 \u2192 F` injective on\n`s` and a value function `r : \u03b9 \u2192 F`,  `interpolate s v r` is the unique\npolynomial of degree `< s.card` that takes value `r i` on `v i` for all `i` in `s`. -/\n@[simps]\ndef interpolate (s : finset \u03b9) (v : \u03b9 \u2192 F) : (\u03b9 \u2192 F) \u2192\u2097[F] F[X] :=\n{ to_fun := \u03bb r, \u2211 i in s, C (r i) * (lagrange.basis s v i),\n  map_add' := \u03bb f g, by simp_rw [\u2190 finset.sum_add_distrib, \u2190 add_mul,\n                                 \u2190 C_add, pi.add_apply],\n  map_smul' := \u03bb c f, by simp_rw [finset.smul_sum, C_mul', smul_smul,\n                                  pi.smul_apply, ring_hom.id_apply, smul_eq_mul] }\n\n@[simp] theorem interpolate_empty : interpolate \u2205 v r = 0 :=\nby rw [interpolate_apply, sum_empty]\n\n@[simp] theorem interpolate_singleton : interpolate {i} v r = C (r i) :=\nby rw [interpolate_apply, sum_singleton, basis_singleton, mul_one]\n\ntheorem interpolate_one (hvs : set.inj_on v s) (hs : s.nonempty) : interpolate s v 1 = 1 :=\nby { simp_rw [interpolate_apply, pi.one_apply, map_one, one_mul], exact sum_basis hvs hs }\n\ntheorem eval_interpolate_at_node (hvs : set.inj_on v s) (hi : i \u2208 s) :\n  eval (v i) (interpolate s v r) = r i :=\nbegin\n  rw [interpolate_apply, eval_finset_sum, \u2190 add_sum_erase _ _ hi],\n  simp_rw [eval_mul, eval_C, eval_basis_self hvs hi, mul_one, add_right_eq_self],\n  refine sum_eq_zero (\u03bb j H, _),\n  rw [eval_basis_of_ne (mem_erase.mp H).1 hi, mul_zero]\nend\n\ntheorem degree_interpolate_le (hvs : set.inj_on v s) : (interpolate s v r).degree \u2264 \u2191(s.card - 1) :=\nbegin\n  refine (degree_sum_le _ _).trans _,\n  rw finset.sup_le_iff,\n  intros i hi,\n  rw [degree_mul, degree_basis hvs hi],\n  by_cases hr : r i = 0,\n  { simpa only [hr, map_zero, degree_zero, with_bot.bot_add] using bot_le },\n  { rw [degree_C hr, zero_add, with_bot.coe_le_coe] }\nend\n\ntheorem degree_interpolate_lt (hvs : set.inj_on v s) : (interpolate s v r).degree < s.card :=\nbegin\n  rcases eq_empty_or_nonempty s with rfl | h,\n  { rw [interpolate_empty, degree_zero, card_empty],\n    exact with_bot.bot_lt_coe _ },\n  { refine lt_of_le_of_lt (degree_interpolate_le _ hvs) _,\n    rw with_bot.coe_lt_coe,\n    exact nat.sub_lt (nonempty.card_pos h) zero_lt_one }\nend\n\ntheorem degree_interpolate_erase_lt (hvs : set.inj_on v s) (hi : i \u2208 s) :\n  (interpolate (s.erase i) v r).degree < \u2191(s.card - 1) :=\nbegin\n  rw \u2190 finset.card_erase_of_mem hi,\n  exact degree_interpolate_lt _ (set.inj_on.mono (coe_subset.mpr (erase_subset _ _)) hvs),\nend\n\ntheorem values_eq_on_of_interpolate_eq (hvs : set.inj_on v s)\n  (hrr' : interpolate s v r = interpolate s v r') : \u2200 i \u2208 s, r i = r' i :=\n\u03bb _ hi, by rw [\u2190 eval_interpolate_at_node r hvs hi, hrr', eval_interpolate_at_node r' hvs hi]\n\ntheorem interpolate_eq_of_values_eq_on (hrr' : \u2200 i \u2208 s, r i = r' i) :\n  interpolate s v r = interpolate s v r' :=\nsum_congr rfl (\u03bb i hi, (by rw hrr' _ hi))\n\ntheorem interpolate_eq_iff_values_eq_on (hvs : set.inj_on v s) :\n  interpolate s v r = interpolate s v r' \u2194 \u2200 i \u2208 s, r i = r' i :=\n\u27e8values_eq_on_of_interpolate_eq _ _ hvs, interpolate_eq_of_values_eq_on _ _\u27e9\n\ntheorem eq_interpolate {f : F[X]} (hvs : set.inj_on v s) (degree_f_lt : f.degree < s.card) :\n  f = interpolate s v (\u03bb i, f.eval (v i)) :=\neq_of_degrees_lt_of_eval_index_eq _ hvs degree_f_lt (degree_interpolate_lt _ hvs) $\n\u03bb i hi, (eval_interpolate_at_node _ hvs hi).symm\n\ntheorem eq_interpolate_of_eval_eq {f : F[X]} (hvs : set.inj_on v s)\n  (degree_f_lt : f.degree < s.card) (eval_f : \u2200 i \u2208 s, f.eval (v i) = r i) :\n  f = interpolate s v r :=\nby { rw eq_interpolate hvs degree_f_lt, exact interpolate_eq_of_values_eq_on _ _ eval_f }\n\n/--\nThis is the characteristic property of the interpolation: the interpolation is the\nunique polynomial of `degree < fintype.card \u03b9` which takes the value of the `r i` on the `v i`.\n-/\ntheorem eq_interpolate_iff {f : F[X]} (hvs : set.inj_on v s) :\n  (f.degree < s.card \u2227 \u2200 i \u2208 s, eval (v i) f = r i) \u2194 f = interpolate s v r :=\nbegin\n  split; intro h,\n  { exact eq_interpolate_of_eval_eq _ hvs h.1 h.2 },\n  { rw h, exact \u27e8degree_interpolate_lt _ hvs, \u03bb _ hi, eval_interpolate_at_node _ hvs hi\u27e9 }\nend\n\n/-- Lagrange interpolation induces isomorphism between functions from `s`\nand polynomials of degree less than `fintype.card \u03b9`.-/\ndef fun_equiv_degree_lt (hvs : set.inj_on v s) : degree_lt F s.card \u2243\u2097[F] (s \u2192 F) :=\n{ to_fun := \u03bb f i, f.1.eval (v i),\n  map_add' := \u03bb f g, funext $ \u03bb v, eval_add,\n  map_smul' := \u03bb c f, funext $ by simp,\n  inv_fun := \u03bb r, \u27e8interpolate s v (\u03bb x, if hx : x \u2208 s then r \u27e8x, hx\u27e9 else 0),\n                   mem_degree_lt.2 $ degree_interpolate_lt _ hvs\u27e9,\n  left_inv :=\n  begin\n    rintros \u27e8f, hf\u27e9,\n    simp only [subtype.mk_eq_mk, subtype.coe_mk, dite_eq_ite],\n    rw mem_degree_lt at hf,\n    nth_rewrite_rhs 0 eq_interpolate hvs hf,\n    exact interpolate_eq_of_values_eq_on _ _ (\u03bb _ hi, if_pos hi)\n  end,\n  right_inv :=\n  begin\n    intro f,\n    ext \u27e8i, hi\u27e9,\n    simp only [subtype.coe_mk, eval_interpolate_at_node _ hvs hi],\n    exact dif_pos hi,\n  end }\n\ntheorem interpolate_eq_sum_interpolate_insert_sdiff (hvt : set.inj_on v t) (hs : s.nonempty)\n  (hst : s \u2286 t) : interpolate t v r =\n  \u2211 i in s, (interpolate (insert i (t \\ s)) v r) * lagrange.basis s v i :=\nbegin\n  symmetry,\n  refine eq_interpolate_of_eval_eq _ hvt (lt_of_le_of_lt (degree_sum_le _ _) _) (\u03bb i hi, _),\n  { simp_rw [(finset.sup_lt_iff (with_bot.bot_lt_coe t.card)), degree_mul],\n    intros i hi,\n    have hs : 1 \u2264 s.card := nonempty.card_pos \u27e8_, hi\u27e9,\n    have hst' : s.card \u2264 t.card := card_le_of_subset hst,\n    have H : t.card = (1 + (t.card - s.card)) + (s.card - 1),\n    { rw [add_assoc, tsub_add_tsub_cancel hst' hs, \u2190 add_tsub_assoc_of_le (hs.trans hst'),\n          nat.succ_add_sub_one, zero_add] },\n    rw [degree_basis (set.inj_on.mono hst hvt) hi, H, with_bot.coe_add,\n        with_bot.add_lt_add_iff_right (@with_bot.coe_ne_bot _ (s.card - 1))],\n    convert degree_interpolate_lt _ (hvt.mono (coe_subset.mpr (insert_subset.mpr\n      \u27e8hst hi, sdiff_subset _ _\u27e9))),\n    rw [card_insert_of_not_mem (not_mem_sdiff_of_mem_right hi), card_sdiff hst, add_comm] },\n\n  { simp_rw [eval_finset_sum, eval_mul],\n    by_cases hi' : i \u2208 s,\n    { rw [\u2190 add_sum_erase _ _ hi', eval_basis_self (hvt.mono hst) hi',\n          eval_interpolate_at_node _ (hvt.mono (coe_subset.mpr\n            (insert_subset.mpr \u27e8hi, sdiff_subset _ _\u27e9))) (mem_insert_self _ _),\n          mul_one, add_right_eq_self],\n      refine sum_eq_zero (\u03bb j hj, _),\n      rcases mem_erase.mp hj with \u27e8hij, hj\u27e9,\n      rw [eval_basis_of_ne hij hi', mul_zero] },\n    { have H : \u2211 j in s, eval (v i) (lagrange.basis s v j) = 1,\n      { rw [\u2190 eval_finset_sum, sum_basis (hvt.mono hst) hs, eval_one] },\n      rw [\u2190 mul_one (r i), \u2190 H, mul_sum],\n      refine sum_congr rfl (\u03bb j hj, _),\n      congr,\n      exact eval_interpolate_at_node _ (hvt.mono (insert_subset.mpr \u27e8hst hj, sdiff_subset _ _\u27e9))\n                                (mem_insert.mpr (or.inr (mem_sdiff.mpr \u27e8hi, hi'\u27e9))) } }\nend\n\n\n\nend interpolate\n\nsection nodal\nopen finset polynomial\nvariables {\u03b9 : Type*} {s : finset \u03b9} {v : \u03b9 \u2192 F} {i : \u03b9} (r : \u03b9 \u2192 F) {x : F}\n\n/--\n`nodal s v` is the unique monic polynomial whose roots are the nodes defined by `v` and `s`.\n\nThat is, the roots of `nodal s v` are exactly the image of `v` on `s`,\nwith appropriate multiplicity.\n\nWe can use `nodal` to define the barycentric forms of the evaluated interpolant.\n-/\ndef nodal (s : finset \u03b9) (v : \u03b9 \u2192 F) : F[X] := \u220f i in s, (X - C (v i))\n\nlemma nodal_eq (s : finset \u03b9) (v : \u03b9 \u2192 F) : nodal s v = \u220f i in s, (X - C (v i)) := rfl\n\n@[simp] lemma nodal_empty : nodal \u2205 v = 1 := rfl\n\nlemma degree_nodal : (nodal s v).degree = s.card :=\nby simp_rw [nodal, degree_prod, degree_X_sub_C, sum_const, nat.smul_one_eq_coe]\n\nlemma eval_nodal {x : F} : (nodal s v).eval x = \u220f i in s, (x - v i) :=\nby simp_rw [nodal, eval_prod, eval_sub, eval_X, eval_C]\n\nlemma eval_nodal_at_node (hi : i \u2208 s) : eval (v i) (nodal s v) = 0 :=\nby { rw [eval_nodal, prod_eq_zero_iff], exact \u27e8i, hi, sub_eq_zero_of_eq rfl\u27e9 }\n\nlemma eval_nodal_not_at_node (hx : \u2200 i \u2208 s, x \u2260 v i) : eval x (nodal s v) \u2260 0 :=\nby { simp_rw [nodal, eval_prod, prod_ne_zero_iff, eval_sub, eval_X, eval_C, sub_ne_zero], exact hx }\n\nlemma nodal_eq_mul_nodal_erase [decidable_eq \u03b9] (hi : i \u2208 s) :\n  nodal s v = (X - C (v i)) * nodal (s.erase i) v := by simp_rw [nodal, mul_prod_erase _ _ hi]\n\nlemma X_sub_C_dvd_nodal (v : \u03b9 \u2192 F) (hi : i \u2208 s) : (X - C (v i)) \u2223 nodal s v :=\n\u27e8_, by { classical, exact nodal_eq_mul_nodal_erase hi }\u27e9\n\nvariable [decidable_eq \u03b9]\n\nlemma nodal_erase_eq_nodal_div (hi : i \u2208 s) :\n  nodal (s.erase i) v = nodal s v / (X - C (v i)) :=\nbegin\n  rw [nodal_eq_mul_nodal_erase hi, euclidean_domain.mul_div_cancel_left],\n  exact X_sub_C_ne_zero _\nend\n\nlemma nodal_insert_eq_nodal (hi : i \u2209 s) :\n  nodal (insert i s) v = (X - C (v i)) * (nodal s v) := by simp_rw [nodal, prod_insert hi]\n\nlemma derivative_nodal : (nodal s v).derivative = \u2211 i in s, nodal (s.erase i) v :=\nbegin\n  refine finset.induction_on s _ (\u03bb _ _ hit IH, _),\n  { rw [nodal_empty, derivative_one, sum_empty] },\n  { rw [nodal_insert_eq_nodal hit, derivative_mul, IH, derivative_sub,\n        derivative_X, derivative_C, sub_zero, one_mul, sum_insert hit,\n        mul_sum, erase_insert hit, add_right_inj],\n    refine sum_congr rfl (\u03bb j hjt, _),\n    rw [nodal_erase_eq_nodal_div (mem_insert_of_mem hjt), nodal_insert_eq_nodal hit,\n        euclidean_domain.mul_div_assoc _ (X_sub_C_dvd_nodal v hjt),\n        nodal_erase_eq_nodal_div hjt] }\nend\n\nlemma eval_nodal_derivative_eval_node_eq (hi : i \u2208 s) :\n  eval (v i) (nodal s v).derivative = eval (v i) (nodal (s.erase i) v) :=\nbegin\n  rw [derivative_nodal, eval_finset_sum, \u2190 add_sum_erase _ _ hi, add_right_eq_self],\n  refine sum_eq_zero (\u03bb j hj, _),\n  simp_rw [nodal, eval_prod, eval_sub, eval_X, eval_C, prod_eq_zero_iff, mem_erase],\n  exact \u27e8i, \u27e8(mem_erase.mp hj).1.symm, hi\u27e9, sub_eq_zero_of_eq rfl\u27e9\nend\n\n/-- This defines the nodal weight for a given set of node indexes and node mapping function `v`. -/\ndef nodal_weight (s : finset \u03b9) (v : \u03b9 \u2192 F) (i : \u03b9) := \u220f j in s.erase i, (v i - v j)\u207b\u00b9\n\nlemma nodal_weight_eq_eval_nodal_erase_inv : nodal_weight s v i =\n  (eval (v i) (nodal (s.erase i) v))\u207b\u00b9 :=\nby rw [eval_nodal, nodal_weight, prod_inv_distrib]\n\nlemma nodal_weight_eq_eval_nodal_derative (hi : i \u2208 s) : nodal_weight s v i =\n  (eval (v i) (nodal s v).derivative)\u207b\u00b9 :=\nby rw [eval_nodal_derivative_eval_node_eq hi, nodal_weight_eq_eval_nodal_erase_inv]\n\nlemma nodal_weight_ne_zero (hvs : set.inj_on v s) (hi : i \u2208 s) : nodal_weight s v i \u2260 0 :=\nbegin\n  rw [nodal_weight, prod_ne_zero_iff],\n  intros j hj,\n  rcases mem_erase.mp hj with \u27e8hij, hj\u27e9,\n  refine inv_ne_zero (sub_ne_zero_of_ne (mt (hvs.eq_iff hi hj).mp hij.symm)),\nend\n\nlemma basis_eq_prod_sub_inv_mul_nodal_div (hi : i \u2208 s) :\n  lagrange.basis s v i = C (nodal_weight s v i) * ( nodal s v / (X - C (v i)) )  :=\nby simp_rw [lagrange.basis, basis_divisor, nodal_weight, prod_mul_distrib,\n            map_prod, \u2190 nodal_erase_eq_nodal_div hi, nodal]\n\nlemma eval_basis_not_at_node (hi : i \u2208 s) (hxi : x \u2260 v i) :\n  eval x (lagrange.basis s v i) = (eval x (nodal s v)) * (nodal_weight s v i * (x - v i)\u207b\u00b9)  :=\nby rw [mul_comm, basis_eq_prod_sub_inv_mul_nodal_div hi, eval_mul, eval_C,\n       \u2190 nodal_erase_eq_nodal_div hi, eval_nodal, eval_nodal, mul_assoc, \u2190 mul_prod_erase _ _ hi,\n       \u2190 mul_assoc (x - v i)\u207b\u00b9, inv_mul_cancel (sub_ne_zero_of_ne hxi), one_mul]\n\nlemma interpolate_eq_nodal_weight_mul_nodal_div_X_sub_C :\n  interpolate s v r = \u2211 i in s, C (nodal_weight s v i) * (nodal s v / (X - C (v i))) * C (r i) :=\nsum_congr rfl (\u03bb j hj, by rw [mul_comm, basis_eq_prod_sub_inv_mul_nodal_div hj])\n\n/-- This is the first barycentric form of the Lagrange interpolant. -/\nlemma eval_interpolate_not_at_node (hx : \u2200 i \u2208 s, x \u2260 v i) : eval x (interpolate s v r) =\n  eval x (nodal s v) * \u2211 i in s, nodal_weight s v i * (x - v i)\u207b\u00b9 * r i :=\nbegin\n  simp_rw [interpolate_apply, mul_sum, eval_finset_sum, eval_mul, eval_C],\n  refine sum_congr rfl (\u03bb i hi, _),\n  rw [\u2190 mul_assoc, mul_comm, eval_basis_not_at_node hi (hx _ hi)]\nend\n\nlemma sum_nodal_weight_mul_inv_sub_ne_zero (hvs : set.inj_on v s)\n  (hx : \u2200 i \u2208 s, x \u2260 v i) (hs : s.nonempty) :\n  \u2211 i in s, nodal_weight s v i * (x - v i)\u207b\u00b9 \u2260 0 :=\n@right_ne_zero_of_mul_eq_one  _ _ _ (eval x (nodal s v)) _ $\n  by simpa only [pi.one_apply, interpolate_one hvs hs, eval_one, mul_one]\n    using (eval_interpolate_not_at_node 1 hx).symm\n\n/-- This is the second barycentric form of the Lagrange interpolant. -/\nlemma eval_interpolate_not_at_node' (hvs : set.inj_on v s) (hs : s.nonempty)\n  (hx : \u2200 i \u2208 s, x \u2260 v i) : eval x (interpolate s v r) =\n  (\u2211 i in s, nodal_weight s v i * (x - v i)\u207b\u00b9 * r i) /\n  \u2211 i in s, nodal_weight s v i * (x - v i)\u207b\u00b9 :=\nbegin\n  rw [\u2190 div_one (eval x (interpolate s v r)), \u2190 @eval_one _ _ x, \u2190 interpolate_one hvs hs,\n      eval_interpolate_not_at_node r hx, eval_interpolate_not_at_node 1 hx],\n  simp only [mul_div_mul_left _ _ (eval_nodal_not_at_node hx), pi.one_apply, mul_one]\nend\n\nend nodal\n\nend lagrange\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/linear_algebra/lagrange.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7012356392093082}}
{"text": "-- Las_clases_de_equivalencia_son_iguales_a_las_de_sus_elementos.lean\n-- Las clases de equivalencia son iguales a las de sus elementos\n-- Jos\u00e9 A. Alonso Jim\u00e9nez\n-- Sevilla, 4 de octubre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Este ejercicio es el 5\u00ba de una serie, que comenz\u00f3 con el [ejercicio\n-- del 30 de septiembre](https://bit.ly/2YfsvBZ), cuyo objetivo es\n-- demostrar que el tipo de las particiones de un conjunto `X` es\n-- isomorfo al tipo de las relaciones de equivalencia sobre `X`.\n--\n-- El ejercicio consiste en demostrar que si C es una clase de\n-- equivalencia y a \u2208 C, entonces la clase de equivalencia de a es C.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\nvariable {A : Type}\nvariable (R : A \u2192 A \u2192 Prop)\n\ndef clase (a : A) :=\n  {b : A | R b a}\n\n-- Se usar\u00e1n los siguientes dos lemas auxiliares\nlemma pertenece_clase_syss\n  {a b : A}\n  : b \u2208 clase R a \u2194 R b a :=\nby refl\n\nlemma subclase_si_pertenece\n  {R : A \u2192 A \u2192 Prop}\n  (hR: equivalence R)\n  {a b : A}\n  : a \u2208 clase R b \u2192 clase R a \u2286 clase R b :=\n\u03bb hab z hza, hR.2.2 hza hab\n\n-- 1\u00aa demostraci\u00f3n\nexample\n  (hR: equivalence R)\n  {a b : A}\n  : a \u2208 clase R b \u2192 clase R a = clase R b :=\nbegin\n  intro hab,\n  apply set.subset.antisymm,\n  { apply subclase_si_pertenece hR hab, },\n  { apply subclase_si_pertenece hR,\n    rcases hR with \u27e8-, hsymm, -\u27e9,\n    exact hsymm hab }\nend\n\n-- 2\u00aa demostraci\u00f3n\nexample\n  (hR: equivalence R)\n  {a b : A}\n  : a \u2208 clase R b \u2192 clase R a = clase R b :=\nbegin\n  intro hab,\n  apply set.subset.antisymm,\n  { exact subclase_si_pertenece hR hab, },\n  { exact subclase_si_pertenece hR (hR.2.1 hab), }\nend\n\n-- 3\u00aa demostraci\u00f3n\nexample\n  (hR: equivalence R)\n  {a b : A}\n  : a \u2208 clase R b \u2192 clase R a = clase R b :=\nbegin\n  intro hab,\n  exact set.subset.antisymm\n         (subclase_si_pertenece hR hab)\n         (subclase_si_pertenece hR (hR.2.1 hab))\nend\n\n-- 4\u00aa demostraci\u00f3n\nlemma clases_iguales_si_pertenece\n  (hR: equivalence R)\n  {a b : A}\n  : a \u2208 clase R b \u2192 clase R a = clase R b :=\n\u03bb hab, set.subset.antisymm\n        (subclase_si_pertenece hR hab)\n        (subclase_si_pertenece hR (hR.2.1 hab))\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Las_clases_de_equivalencia_son_iguales_a_las_de_sus_elementos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8757869884059266, "lm_q1q2_score": 0.7012356371563278}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\n\nimport algebra.algebra.basic\nimport linear_algebra.prod\nimport algebra.hom.non_unital_alg\n\n/-!\n# Unitization of a non-unital algebra\n\nGiven a non-unital `R`-algebra `A` (given via the type classes\n`[non_unital_ring A] [module R A] [smul_comm_class R A A] [is_scalar_tower R A A]`) we construct\nthe minimal unital `R`-algebra containing `A` as an ideal. This object `algebra.unitization R A` is\na type synonym for `R \u00d7 A` on which we place a different multiplicative structure, namely,\n`(r\u2081, a\u2081) * (r\u2082, a\u2082) = (r\u2081 * r\u2082, r\u2081 \u2022 a\u2082 + r\u2082 \u2022 a\u2081 + a\u2081 * a\u2082)` where the multiplicative identity\nis `(1, 0)`.\n\nNote, when `A` is a *unital* `R`-algebra, then `unitization R A` constructs a new multiplicative\nidentity different from the old one, and so in general `unitization R A` and `A` will not be\nisomorphic even in the unital case. This approach actually has nice functorial properties.\n\nThere is a natural coercion from `A` to `unitization R A` given by `\u03bb a, (0, a)`, the image\nof which is a proper ideal (TODO), and when `R` is a field this ideal is maximal. Moreover,\nthis ideal is always an essential ideal (it has nontrivial intersection with every other nontrivial\nideal).\n\nEvery non-unital algebra homomorphism from `A` into a *unital* `R`-algebra `B` has a unique\nextension to a (unital) algebra homomorphism from `unitization R A` to `B`.\n\n## Main definitions\n\n* `unitization R A`: the unitization of a non-unital `R`-algebra `A`.\n* `unitization.algebra`: the unitization of `A` as a (unital) `R`-algebra.\n* `unitization.coe_non_unital_alg_hom`: coercion as a non-unital algebra homomorphism.\n* `non_unital_alg_hom.to_alg_hom \u03c6`: the extension of a non-unital algebra homomorphism `\u03c6 : A \u2192 B`\n  into a unital `R`-algebra `B` to an algebra homomorphism `unitization R A \u2192\u2090[R] B`.\n\n## Main results\n\n* `non_unital_alg_hom.to_alg_hom_unique`: the extension is unique\n\n## TODO\n\n* prove the unitization operation is a functor between the appropriate categories\n* prove the image of the coercion is an essential ideal, maximal if scalars are a field.\n-/\n\n/-- The minimal unitization of a non-unital `R`-algebra `A`. This is just a type synonym for\n`R \u00d7 A`.-/\ndef unitization (R A : Type*) := R \u00d7 A\n\nnamespace unitization\n\nsection basic\n\nvariables {R A : Type*}\n\n/-- The canonical inclusion `R \u2192 unitization R A`. -/\ndef inl [has_zero A] (r : R) : unitization R A :=\n(r, 0)\n\n/-- The canonical inclusion `A \u2192 unitization R A`. -/\ninstance [has_zero R] : has_coe_t A (unitization R A) := { coe := \u03bb a, (0, a) }\n\n/-- The canonical projection `unitization R A \u2192 R`. -/\ndef fst (x : unitization R A) : R :=\nx.1\n\n/-- The canonical projection `unitization R A \u2192 A`. -/\ndef snd (x : unitization R A) : A :=\nx.2\n\n@[ext] lemma ext {x y : unitization R A} (h1 : x.fst = y.fst) (h2 : x.snd = y.snd) : x = y :=\nprod.ext h1 h2\n\nsection\nvariables (A)\n@[simp] lemma fst_inl [has_zero A] (r : R) : (inl r : unitization R A).fst = r := rfl\n@[simp] lemma snd_inl [has_zero A] (r : R) : (inl r : unitization R A).snd = 0 := rfl\nend\n\nsection\nvariables (R)\n@[simp] lemma fst_coe [has_zero R] (a : A) : (a : unitization R A).fst = 0 := rfl\n@[simp] lemma snd_coe [has_zero R] (a : A) : (a : unitization R A).snd = a := rfl\nend\n\nlemma inl_injective [has_zero A] : function.injective (inl : R \u2192 unitization R A) :=\nfunction.left_inverse.injective $ fst_inl _\n\nlemma coe_injective [has_zero R] : function.injective (coe : A \u2192 unitization R A) :=\nfunction.left_inverse.injective $ snd_coe _\n\nend basic\n\n/-! ### Structures inherited from `prod`\n\nAdditive operators and scalar multiplication operate elementwise. -/\n\nsection additive\n\nvariables {T : Type*} {S : Type*} {R : Type*} {A : Type*}\n\ninstance [inhabited R] [inhabited A] : inhabited (unitization R A) :=\nprod.inhabited\n\ninstance [has_zero R] [has_zero A] : has_zero (unitization R A) :=\nprod.has_zero\n\ninstance [has_add R] [has_add A] : has_add (unitization R A) :=\nprod.has_add\n\ninstance [has_neg R] [has_neg A] : has_neg (unitization R A) :=\nprod.has_neg\n\ninstance [add_semigroup R] [add_semigroup A] : add_semigroup (unitization R A) :=\nprod.add_semigroup\n\ninstance [add_zero_class R] [add_zero_class A] : add_zero_class (unitization R A) :=\nprod.add_zero_class\n\ninstance [add_monoid R] [add_monoid A] : add_monoid (unitization R A) :=\nprod.add_monoid\n\ninstance [add_group R] [add_group A] : add_group (unitization R A) :=\nprod.add_group\n\ninstance [add_comm_semigroup R] [add_comm_semigroup A] : add_comm_semigroup (unitization R A) :=\nprod.add_comm_semigroup\n\ninstance [add_comm_monoid R] [add_comm_monoid A] : add_comm_monoid (unitization R A) :=\nprod.add_comm_monoid\n\ninstance [add_comm_group R] [add_comm_group A] : add_comm_group (unitization R A) :=\nprod.add_comm_group\n\ninstance [has_scalar S R] [has_scalar S A] : has_scalar S (unitization R A) :=\nprod.has_scalar\n\ninstance [has_scalar T R] [has_scalar T A] [has_scalar S R] [has_scalar S A] [has_scalar T S]\n  [is_scalar_tower T S R] [is_scalar_tower T S A] : is_scalar_tower T S (unitization R A) :=\nprod.is_scalar_tower\n\ninstance [has_scalar T R] [has_scalar T A] [has_scalar S R] [has_scalar S A]\n  [smul_comm_class T S R] [smul_comm_class T S A] : smul_comm_class T S (unitization R A) :=\nprod.smul_comm_class\n\ninstance [has_scalar S R] [has_scalar S A] [has_scalar S\u1d50\u1d52\u1d56 R] [has_scalar S\u1d50\u1d52\u1d56 A]\n  [is_central_scalar S R] [is_central_scalar S A] : is_central_scalar S (unitization R A) :=\nprod.is_central_scalar\n\ninstance [monoid S] [mul_action S R] [mul_action S A] : mul_action S (unitization R A) :=\nprod.mul_action\n\ninstance [monoid S] [add_monoid R] [add_monoid A]\n  [distrib_mul_action S R] [distrib_mul_action S A] : distrib_mul_action S (unitization R A) :=\nprod.distrib_mul_action\n\ninstance [semiring S] [add_comm_monoid R] [add_comm_monoid A]\n  [module S R] [module S A] : module S (unitization R A) :=\nprod.module\n\n@[simp] lemma fst_zero [has_zero R] [has_zero A] : (0 : unitization R A).fst = 0 := rfl\n@[simp] lemma snd_zero [has_zero R] [has_zero A] : (0 : unitization R A).snd = 0 := rfl\n\n@[simp] lemma fst_add [has_add R] [has_add A] (x\u2081 x\u2082 : unitization R A) :\n  (x\u2081 + x\u2082).fst = x\u2081.fst + x\u2082.fst := rfl\n@[simp] lemma snd_add [has_add R] [has_add A] (x\u2081 x\u2082 : unitization R A) :\n  (x\u2081 + x\u2082).snd = x\u2081.snd + x\u2082.snd := rfl\n\n@[simp] lemma fst_neg [has_neg R] [has_neg A] (x : unitization R A) : (-x).fst = -x.fst := rfl\n@[simp] lemma snd_neg [has_neg R] [has_neg A] (x : unitization R A) : (-x).snd = -x.snd := rfl\n\n@[simp] lemma fst_smul [has_scalar S R] [has_scalar S A] (s : S) (x : unitization R A) :\n  (s \u2022 x).fst = s \u2022 x.fst := rfl\n@[simp] lemma snd_smul [has_scalar S R] [has_scalar S A] (s : S) (x : unitization R A) :\n  (s \u2022 x).snd = s \u2022 x.snd := rfl\n\nsection\nvariables (A)\n\n@[simp] lemma inl_zero [has_zero R] [has_zero A] : (inl 0 : unitization R A) = 0 := rfl\n\n@[simp] lemma inl_add [has_add R] [add_zero_class A] (r\u2081 r\u2082 : R) :\n  (inl (r\u2081 + r\u2082) : unitization R A) = inl r\u2081 + inl r\u2082 :=\next rfl (add_zero 0).symm\n\n@[simp] lemma inl_neg [has_neg R] [add_group A] (r : R) :\n  (inl (-r) : unitization R A) = -inl r :=\next rfl neg_zero.symm\n\n@[simp] lemma inl_smul [monoid S] [add_monoid A] [has_scalar S R] [distrib_mul_action S A]\n  (s : S) (r : R) : (inl (s \u2022 r) : unitization R A) = s \u2022 inl r :=\next rfl (smul_zero s).symm\n\nend\n\nsection\nvariables (R)\n\n@[simp] lemma coe_zero [has_zero R] [has_zero A] : \u2191(0 : A) = (0 : unitization R A) := rfl\n\n@[simp] lemma coe_add [add_zero_class R] [add_zero_class A] (m\u2081 m\u2082 : A) :\n  (\u2191(m\u2081 + m\u2082) : unitization R A)  = m\u2081 + m\u2082 :=\next (add_zero 0).symm rfl\n\n@[simp] lemma coe_neg [add_group R] [has_neg A] (m : A) :\n  (\u2191(-m) : unitization R A) = -m :=\next neg_zero.symm rfl\n\n@[simp] lemma coe_smul [has_zero R] [has_zero S] [smul_with_zero S R] [has_scalar S A]\n  (r : S) (m : A) : (\u2191(r \u2022 m) : unitization R A) = r \u2022 m :=\next (smul_zero' _ _).symm rfl\n\nend\n\nlemma inl_fst_add_coe_snd_eq [add_zero_class R] [add_zero_class A] (x : unitization R A) :\n  inl x.fst + \u2191x.snd = x :=\next (add_zero x.1) (zero_add x.2)\n\n/-- To show a property hold on all `unitization R A` it suffices to show it holds\non terms of the form `inl r + a`.\n\nThis can be used as `induction x using unitization.ind`. -/\nlemma ind {R A} [add_zero_class R] [add_zero_class A] {P : unitization R A \u2192 Prop}\n  (h : \u2200 (r : R) (a : A), P (inl r + a)) (x) : P x :=\ninl_fst_add_coe_snd_eq x \u25b8 h x.1 x.2\n\n/-- This cannot be marked `@[ext]` as it ends up being used instead of `linear_map.prod_ext` when\nworking with `R \u00d7 A`. -/\nlemma linear_map_ext {N} [semiring S] [add_comm_monoid R] [add_comm_monoid A] [add_comm_monoid N]\n  [module S R] [module S A] [module S N] \u2983f g : unitization R A \u2192\u2097[S] N\u2984\n  (hl : \u2200 r, f (inl r) = g (inl r)) (hr : \u2200 a : A, f a = g a) :\n  f = g :=\nlinear_map.prod_ext (linear_map.ext hl) (linear_map.ext hr)\n\nvariables (R A)\n\n/-- The canonical `R`-linear inclusion `A \u2192 unitization R A`. -/\n@[simps apply]\ndef coe_hom [semiring R] [add_comm_monoid A] [module R A] : A \u2192\u2097[R] unitization R A :=\n{ to_fun := coe, ..linear_map.inr R R A }\n\n/-- The canonical `R`-linear projection `unitization R A \u2192 A`. -/\n@[simps apply]\ndef snd_hom [semiring R] [add_comm_monoid A] [module R A] : unitization R A \u2192\u2097[R] A :=\n{ to_fun := snd, ..linear_map.snd _ _ _ }\n\nend additive\n\n/-! ### Multiplicative structure -/\n\nsection mul\nvariables {R A : Type*}\n\ninstance [has_one R] [has_zero A] : has_one (unitization R A) :=\n\u27e8(1, 0)\u27e9\n\ninstance [has_mul R] [has_add A] [has_mul A] [has_scalar R A] : has_mul (unitization R A) :=\n\u27e8\u03bb x y, (x.1 * y.1, x.1 \u2022 y.2 + y.1 \u2022 x.2 + x.2 * y.2)\u27e9\n\n@[simp] lemma fst_one [has_one R] [has_zero A] : (1 : unitization R A).fst = 1 := rfl\n@[simp] lemma snd_one [has_one R] [has_zero A] : (1 : unitization R A).snd = 0 := rfl\n\n@[simp] lemma fst_mul [has_mul R] [has_add A] [has_mul A] [has_scalar R A]\n  (x\u2081 x\u2082 : unitization R A) : (x\u2081 * x\u2082).fst = x\u2081.fst * x\u2082.fst := rfl\n@[simp] lemma snd_mul [has_mul R] [has_add A] [has_mul A] [has_scalar R A]\n  (x\u2081 x\u2082 : unitization R A) : (x\u2081 * x\u2082).snd = x\u2081.fst \u2022 x\u2082.snd + x\u2082.fst \u2022 x\u2081.snd + x\u2081.snd * x\u2082.snd :=\nrfl\n\nsection\nvariables (A)\n\n@[simp] lemma inl_one [has_one R] [has_zero A] : (inl 1 : unitization R A) = 1 := rfl\n\n@[simp] lemma inl_mul [monoid R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A]\n  (r\u2081 r\u2082 : R) : (inl (r\u2081 * r\u2082) : unitization R A) = inl r\u2081 * inl r\u2082 :=\next rfl $ show (0 : A) = r\u2081 \u2022 (0 : A) + r\u2082 \u2022 0 + 0 * 0, by simp only [smul_zero, add_zero, mul_zero]\n\nlemma inl_mul_inl [monoid R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A]\n  (r\u2081 r\u2082 : R) : (inl r\u2081 * inl r\u2082 : unitization R A) = inl (r\u2081 * r\u2082) :=\n(inl_mul A r\u2081 r\u2082).symm\n\nend\n\nsection\nvariables (R)\n\n@[simp] \n\nend\n\nlemma inl_mul_coe [semiring R] [non_unital_non_assoc_semiring A] [module R A] (r : R) (a : A) :\n  (inl r * a : unitization R A) = \u2191(r \u2022 a) :=\next (mul_zero r) $ show r \u2022 a + (0 : R) \u2022 0 + 0 * a = r \u2022 a,\n  by rw [smul_zero, add_zero, zero_mul, add_zero]\n\nlemma coe_mul_inl [semiring R] [non_unital_non_assoc_semiring A] [module R A] (r : R) (a : A) :\n  (a * inl r : unitization R A) = \u2191(r \u2022 a) :=\next (zero_mul r) $ show (0 : R) \u2022 0 + r \u2022 a + a * 0 = r \u2022 a,\n  by rw [smul_zero, zero_add, mul_zero, add_zero]\n\ninstance mul_one_class [monoid R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A] :\n  mul_one_class (unitization R A) :=\n{ one_mul := \u03bb x, ext (one_mul x.1) $ show (1 : R) \u2022 x.2 + x.1 \u2022 0 + 0 * x.2 = x.2,\n    by rw [one_smul, smul_zero, add_zero, zero_mul, add_zero],\n  mul_one := \u03bb x, ext (mul_one x.1) $ show (x.1 \u2022 0 : A) + (1 : R) \u2022 x.2 + x.2 * 0 = x.2,\n    by rw [smul_zero, zero_add, one_smul, mul_zero, add_zero],\n  .. unitization.has_one,\n  .. unitization.has_mul }\n\ninstance [semiring R] [non_unital_non_assoc_semiring A] [module R A] :\n  non_assoc_semiring (unitization R A) :=\n{ zero_mul := \u03bb x, ext (zero_mul x.1) $ show (0 : R) \u2022 x.2 + x.1 \u2022 0 + 0 * x.2 = 0,\n    by rw [zero_smul, zero_add, smul_zero, zero_mul, add_zero],\n  mul_zero := \u03bb x, ext (mul_zero x.1) $ show (x.1 \u2022 0 : A) + (0 : R) \u2022 x.2 + x.2 * 0 = 0,\n    by rw [smul_zero, zero_add, zero_smul, mul_zero, add_zero],\n  left_distrib := \u03bb x\u2081 x\u2082 x\u2083, ext (mul_add x\u2081.1 x\u2082.1 x\u2083.1) $\n    show x\u2081.1 \u2022 (x\u2082.2 + x\u2083.2) + (x\u2082.1 + x\u2083.1) \u2022 x\u2081.2 + x\u2081.2 * (x\u2082.2 + x\u2083.2) =\n      x\u2081.1 \u2022 x\u2082.2 + x\u2082.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2082.2 + (x\u2081.1 \u2022 x\u2083.2 + x\u2083.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2083.2),\n    by { simp only [smul_add, add_smul, mul_add], abel },\n  right_distrib := \u03bb x\u2081 x\u2082 x\u2083, ext (add_mul x\u2081.1 x\u2082.1 x\u2083.1) $\n    show (x\u2081.1 + x\u2082.1) \u2022 x\u2083.2 + x\u2083.1 \u2022 (x\u2081.2 + x\u2082.2) + (x\u2081.2 + x\u2082.2) * x\u2083.2 =\n      x\u2081.1 \u2022 x\u2083.2 + x\u2083.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2083.2 + (x\u2082.1 \u2022 x\u2083.2 + x\u2083.1 \u2022 x\u2082.2 + x\u2082.2 * x\u2083.2),\n    by { simp only [add_smul, smul_add, add_mul], abel },\n  .. unitization.mul_one_class,\n  .. unitization.add_comm_monoid }\n\ninstance [comm_monoid R] [non_unital_semiring A] [distrib_mul_action R A] [is_scalar_tower R A A]\n  [smul_comm_class R A A] : monoid (unitization R A) :=\n{ mul_assoc := \u03bb x y z, ext (mul_assoc x.1 y.1 z.1) $\n    show (x.1 * y.1) \u2022 z.2 + z.1 \u2022 (x.1 \u2022 y.2 + y.1 \u2022 x.2 + x.2 * y.2) +\n      (x.1 \u2022 y.2 + y.1 \u2022 x.2 + x.2 * y.2) * z.2 =\n      x.1 \u2022 (y.1 \u2022 z.2 + z.1 \u2022 y.2 + y.2 * z.2) + (y.1 * z.1) \u2022 x.2 +\n      x.2 * (y.1 \u2022 z.2 + z.1 \u2022 y.2 + y.2 * z.2),\n    { simp only [smul_add, mul_add, add_mul, smul_smul, smul_mul_assoc, mul_smul_comm, mul_assoc],\n      nth_rewrite 1 mul_comm,\n      nth_rewrite 2 mul_comm,\n      abel },\n  ..unitization.mul_one_class }\n\n-- This should work for `non_unital_comm_semiring`s, but we don't seem to have those\ninstance [comm_monoid R] [comm_semiring A] [distrib_mul_action R A] [is_scalar_tower R A A]\n  [smul_comm_class R A A] : comm_monoid (unitization R A) :=\n{ mul_comm := \u03bb x\u2081 x\u2082, ext (mul_comm x\u2081.1 x\u2082.1) $\n    show x\u2081.1 \u2022 x\u2082.2 + x\u2082.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2082.2 = x\u2082.1 \u2022 x\u2081.2 + x\u2081.1 \u2022 x\u2082.2 + x\u2082.2 * x\u2081.2,\n    by rw [add_comm (x\u2081.1 \u2022 x\u2082.2), mul_comm],\n  ..unitization.monoid }\n\ninstance [comm_semiring R] [non_unital_semiring A] [module R A] [is_scalar_tower R A A]\n  [smul_comm_class R A A] : semiring (unitization R A) :=\n{ ..unitization.monoid,\n  ..unitization.non_assoc_semiring }\n\n-- This should work for `non_unital_comm_semiring`s, but we don't seem to have those\ninstance [comm_semiring R] [comm_semiring A] [module R A] [is_scalar_tower R A A]\n  [smul_comm_class R A A] : comm_semiring (unitization R A) :=\n{ ..unitization.comm_monoid,\n  ..unitization.non_assoc_semiring }\n\nvariables (R A)\n\n/-- The canonical inclusion of rings `R \u2192+* unitization R A`. -/\n@[simps apply]\ndef inl_ring_hom [semiring R] [non_unital_semiring A] [module R A] : R \u2192+* unitization R A :=\n{ to_fun := inl,\n  map_one' := inl_one A,\n  map_mul' := inl_mul A,\n  map_zero' := inl_zero A,\n  map_add' := inl_add A }\n\nend mul\n\n/-! ### Star structure -/\n\nsection star\n\nvariables {R A : Type*}\n\ninstance [has_star R] [has_star A] : has_star (unitization R A) :=\n\u27e8\u03bb ra, (star ra.fst, star ra.snd)\u27e9\n\n@[simp] lemma fst_star [has_star R] [has_star A] (x : unitization R A) :\n  (star x).fst = star x.fst := rfl\n\n@[simp] lemma snd_star [has_star R] [has_star A] (x : unitization R A) :\n  (star x).snd = star x.snd := rfl\n\n@[simp] lemma inl_star [has_star R] [add_monoid A] [star_add_monoid A] (r : R) :\n  inl (star r) = star (inl r : unitization R A) :=\next rfl (by simp only [snd_star, star_zero, snd_inl])\n\n@[simp] lemma coe_star [add_monoid R] [star_add_monoid R] [has_star A] (a : A) :\n  \u2191(star a) = star (a : unitization R A) :=\next (by simp only [fst_star, star_zero, fst_coe]) rfl\n\ninstance [add_monoid R] [add_monoid A] [star_add_monoid R] [star_add_monoid A] :\n  star_add_monoid (unitization R A) :=\n{ star_involutive := \u03bb x, ext (star_star x.fst) (star_star x.snd),\n  star_add := \u03bb x y, ext (star_add x.fst y.fst) (star_add x.snd y.snd) }\n\ninstance [comm_semiring R] [star_ring R] [add_comm_monoid A] [star_add_monoid A]\n  [module R A] [star_module R A] : star_module R (unitization R A) :=\n{ star_smul := \u03bb r x, ext (by simp) (by simp) }\n\ninstance [comm_semiring R] [star_ring R] [non_unital_semiring A] [star_ring A]\n  [module R A] [is_scalar_tower R A A] [smul_comm_class R A A] [star_module R A] :\n  star_ring (unitization R A) :=\n{ star_mul := \u03bb x y, ext (by simp [star_mul])\n    (by simp [star_mul, add_comm (star x.fst \u2022 star y.snd)]),\n  ..unitization.star_add_monoid }\n\nend star\n\n/-! ### Algebra structure -/\n\nsection algebra\nvariables (S R A : Type*)\n[comm_semiring S] [comm_semiring R] [non_unital_semiring A]\n[module R A] [is_scalar_tower R A A] [smul_comm_class R A A]\n[algebra S R] [distrib_mul_action S A] [is_scalar_tower S R A]\n\ninstance algebra : algebra S (unitization R A) :=\n{ commutes' := \u03bb r x,\n  begin\n    induction x using unitization.ind,\n    simp only [mul_add, add_mul, ring_hom.to_fun_eq_coe, ring_hom.coe_comp, function.comp_app,\n      inl_ring_hom_apply, inl_mul_inl],\n    rw [inl_mul_coe, coe_mul_inl, mul_comm]\n  end,\n  smul_def' := \u03bb s x,\n  begin\n    induction x using unitization.ind,\n    simp only [mul_add, smul_add, ring_hom.to_fun_eq_coe, ring_hom.coe_comp, function.comp_app,\n      inl_ring_hom_apply, algebra.algebra_map_eq_smul_one],\n    rw [inl_mul_inl, inl_mul_coe, smul_one_mul, inl_smul, coe_smul, smul_one_smul]\n  end,\n  ..(unitization.inl_ring_hom R A).comp (algebra_map S R) }\n\nlemma algebra_map_eq_inl_comp : \u21d1(algebra_map S (unitization R A)) = inl \u2218 algebra_map S R := rfl\nlemma algebra_map_eq_inl_ring_hom_comp :\n  algebra_map S (unitization R A) = (inl_ring_hom R A).comp (algebra_map S R) := rfl\nlemma algebra_map_eq_inl : \u21d1(algebra_map R (unitization R A)) = inl := rfl\nlemma algebra_map_eq_inl_hom : algebra_map R (unitization R A) = inl_ring_hom R A := rfl\n\n/-- The canonical `R`-algebra projection `unitization R A \u2192 R`. -/\n@[simps]\ndef fst_hom : unitization R A \u2192\u2090[R] R :=\n{ to_fun := fst,\n  map_one' := fst_one,\n  map_mul' := fst_mul,\n  map_zero' := fst_zero,\n  map_add' := fst_add,\n  commutes' := fst_inl A }\n\nend algebra\n\nsection coe\n\n/-- The coercion from a non-unital `R`-algebra `A` to its unitization `unitization R A`\nrealized as a non-unital algebra homomorphism. -/\n@[simps]\ndef coe_non_unital_alg_hom (R A : Type*) [comm_semiring R] [non_unital_semiring A] [module R A] :\n  non_unital_alg_hom R A (unitization R A) :=\n{ to_fun := coe,\n  map_smul' := coe_smul R,\n  map_zero' := coe_zero R,\n  map_add' := coe_add R,\n  map_mul' := coe_mul R }\n\nend coe\n\nsection alg_hom\n\nvariables {S R A : Type*}\n  [comm_semiring S] [comm_semiring R] [non_unital_semiring A]\n  [module R A] [smul_comm_class R A A] [is_scalar_tower R A A]\n  {B : Type*} [ring B] [algebra S B]\n  [algebra S R] [distrib_mul_action S A] [is_scalar_tower S R A]\n  {C : Type*} [ring C] [algebra R C]\n\nlemma alg_hom_ext {\u03c6 \u03c8 : unitization R A \u2192\u2090[S] B} (h : \u2200 a : A, \u03c6 a = \u03c8 a)\n  (h' : \u2200 r, \u03c6 (algebra_map R (unitization R A) r) = \u03c8 (algebra_map R (unitization R A) r)) :\n  \u03c6 = \u03c8 :=\nbegin\n  ext,\n  induction x using unitization.ind,\n  simp only [map_add, \u2190algebra_map_eq_inl, h, h'],\nend\n\n/-- See note [partially-applied ext lemmas] -/\n@[ext]\nlemma alg_hom_ext' {\u03c6 \u03c8 : unitization R A \u2192\u2090[R] C}\n  (h : \u03c6.to_non_unital_alg_hom.comp (coe_non_unital_alg_hom R A) =\n    \u03c8.to_non_unital_alg_hom.comp (coe_non_unital_alg_hom R A)) :\n  \u03c6 = \u03c8 :=\nalg_hom_ext (non_unital_alg_hom.congr_fun h) (by simp [alg_hom.commutes])\n\n/-- Non-unital algebra homomorphisms from `A` into a unital `R`-algebra `C` lift uniquely to\n`unitization R A \u2192\u2090[R] C`. This is the universal property of the unitization. -/\n@[simps apply_apply]\ndef lift : non_unital_alg_hom R A C \u2243 (unitization R A \u2192\u2090[R] C) :=\n{ to_fun := \u03bb \u03c6,\n  { to_fun := \u03bb x, algebra_map R C x.fst + \u03c6 x.snd,\n    map_one' := by simp only [fst_one, map_one, snd_one, \u03c6.map_zero, add_zero],\n    map_mul' := \u03bb x y,\n    begin\n      induction x using unitization.ind,\n      induction y using unitization.ind,\n      simp only [mul_add, add_mul, coe_mul, fst_add, fst_mul, fst_inl, fst_coe, mul_zero,\n        add_zero, zero_mul, map_mul, snd_add, snd_mul, snd_inl, smul_zero, snd_coe, zero_add,\n        \u03c6.map_add, \u03c6.map_smul, \u03c6.map_mul, zero_smul, zero_add],\n      rw \u2190algebra.commutes _ (\u03c6 x_a),\n      simp only [algebra.algebra_map_eq_smul_one, smul_one_mul, add_assoc],\n    end,\n    map_zero' := by simp only [fst_zero, map_zero, snd_zero, \u03c6.map_zero, add_zero],\n    map_add' := \u03bb x y,\n    begin\n      induction x using unitization.ind,\n      induction y using unitization.ind,\n      simp only [fst_add, fst_inl, fst_coe, add_zero, map_add, snd_add, snd_inl, snd_coe, zero_add,\n        \u03c6.map_add],\n      rw add_add_add_comm,\n    end,\n    commutes' := \u03bb r, by simp only [algebra_map_eq_inl, fst_inl, snd_inl, \u03c6.map_zero, add_zero] },\n  inv_fun := \u03bb \u03c6, \u03c6.to_non_unital_alg_hom.comp (coe_non_unital_alg_hom R A),\n  left_inv := \u03bb \u03c6, by { ext, simp, },\n  right_inv := \u03bb \u03c6, unitization.alg_hom_ext' (by { ext, simp }), }\n\nlemma lift_symm_apply (\u03c6 : unitization R A \u2192\u2090[R] C) (a : A) :\n  unitization.lift.symm \u03c6 a = \u03c6 a := rfl\n\nend alg_hom\n\nend unitization\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/algebra/algebra/unitization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.701235636100204}}
{"text": "-- copyright 2017/18 Ellen Arlt\n-- August 2018, Proved module R (matrix R n m) by Blair Shi\n\nimport algebra.big_operators data.set.finite\nimport algebra.module \n\ndefinition matrix (R: Type) (n m : nat)[ring R] :=  fin n \u2192( fin m \u2192 R ) \n \nnamespace matrix \n\ndefinition add ( R : Type) [ring R] {n m: nat }(A:matrix R m n) ( B : matrix R m n): (matrix R m n):= \n\u03bb I J, A I J + B I J\n\ndefinition neg ( R : Type) [ring R] {n m: nat } (A:matrix R m n) : (matrix R m n):= \n\u03bb I J, - A I J\n\ndefinition zero ( R : Type) [ring R] {m n: nat }: (matrix R m n):= \n\u03bb  I J , 0 \n\ndefinition sub ( R : Type) [ring R] {n m: nat }(A:matrix R m n) ( B : matrix R m n): (matrix R m n):=\n\u03bb I J, A I J - B I J\n\ntheorem add_assoc1 ( R : Type) [ring R] {m n: nat }(A:matrix R m n) ( B : matrix R m n) ( C : matrix R m n) :\n add R A (add R  B C) = add R (add R A B) C :=\nbegin\napply funext,\nintro,\napply funext,\nintro y,\nunfold add,\nshow A x y + (B x y + C x y) = ( A x y + B x y) + C x y,\nrw [add_assoc],\nend\n\ntheorem add_assoc2 ( R : Type) [ring R] {m n: nat }(A:matrix R m n) ( B : matrix R m n) ( C : matrix R m n) :\n add R (add R A B) C = add R A (add R  B C)  :=\nbegin\napply funext,\nintro,\napply funext,\nintro y,\nshow  ( A x y + B x y) + C x y = A x y + (B x y + C x y) ,\nrw[add_assoc],\nend\n\ntheorem zero_add   ( R : Type) [ring R] {m n: nat }(A:matrix R m n):\nadd R (zero R) A = A:=\nbegin\napply funext,\nintro,\napply funext,\nintro y,\nshow 0 + A x y = A x y,\nrw[zero_add]\nend\n\ntheorem add_zero (R : Type) [ring R] {m n: nat }(A:matrix R m n):\nadd R A (zero R) = A:=\nbegin\napply funext,\nintro,\napply funext,\nintro y,\nshow  A x y + 0 = A x y,\nrw[add_zero]\nend\n\n\ntheorem add_left_neg (R : Type) [ring R] {m n: nat }(A:matrix R m n) :\nadd R ( neg R A) A = zero R := \nbegin\napply funext,\nintro,\napply funext,\nintro y,\nshow  - A x y + A x y = 0 ,\nrw[add_left_neg]\nend\n\n\ntheorem add_comm (R : Type) [ring R] {m n: nat }(A:matrix R m n)( B : matrix R m n):\nadd R A B = add R B A :=\nbegin\napply funext,\nintro,\napply funext,\nintro y,\nshow  A x y + B x y = B x y + A x y ,\nrw [add_comm]\nend\n\n\ninstance matrices_add_comm_group ( R : Type) [ring R] {m n: nat }: add_comm_group (matrix R m n):={\nadd:= matrix.add R ,\nadd_assoc := @matrix.add_assoc2 R _ m n,\nzero := matrix.zero R ,\nneg := matrix.neg R,\nzero_add := @matrix.zero_add R _ m n,\nadd_zero := @matrix.add_zero R _ m n,\nadd_left_neg := @matrix.add_left_neg R _ m n,\nadd_comm := @matrix.add_comm R _ m n\n}\n\ndefinition mul ( R : Type) [ring R] {n m l: nat }(A:matrix R m n) ( B : matrix R n l): (matrix R m l ):= \n\u03bb I J, finset.sum finset.univ (\u03bb K, A I K * B K J) \n \ntheorem mul_assoc ( R : Type) [ring R] {m n l o: nat }(A:matrix R m n) ( B : matrix R n l) ( C : matrix R l o) :\nmul R A (mul R B C) = mul R (mul R A B) C :=\nbegin\nunfold mul,\napply funext,\nintro x,\napply funext,\nintro y,\n-- This next line just rewrites the goal so that the variables we're summing over \n-- are the same on both sides.\n\nshow finset.sum finset.univ (\u03bb (K : fin n), A x K * finset.sum finset.univ (\u03bb (J : fin l), B K J * C J y)) =\n     finset.sum finset.univ (\u03bb (J : fin l), finset.sum finset.univ (\u03bb (K : fin n), A x K * B K J) * C J y),\n-- So the key things we now need to use are:\n\n-- finset.mul_sum (which says c * sum_n a_n = sum_n (c*a_n))\n-- finset.sum_mul (which says the same but multiplication on the right)\n-- and finset.sum_comm (which says that two finite sums can be commuted).\n\n-- However, rw finset.sum_mul doesn't work\n-- and neither does rw finset.mul_sum,\n-- and until we apply these we can't commute the sums.\n-- I think the reasons they don't work are that C J y, which we need to move, depends on J,\n-- which is not one of our variables.\n\n-- So here's a trick. We prove an intermediate lemma which says we can\n-- move C J y into the sum, by checking the things we're summing over are the same.\n\nhave H2 : (\u03bb (J : fin l), finset.sum finset.univ (\u03bb (K : fin n), A x K * B K J) * C J y)\n        = (\u03bb (J : fin l), finset.sum finset.univ (\u03bb (K : fin n), A x K * B K J * C J y)),\n{ apply funext,\n  intro J,\n  exact finset.sum_mul,\n},\n\n-- Now we can commute the sums after using this lemma.\n\nrw [H2],\nclear H2,\nrw [finset.sum_comm],\n\n-- Now I just rewrite the goal to show that both things are a sum over K in fin n.\n\nshow finset.sum finset.univ (\u03bb (K : fin n), A x K * finset.sum finset.univ (\u03bb (K_1 : fin l), B K K_1 * C K_1 y)) =\n    finset.sum finset.univ (\u03bb (K : fin n), finset.sum finset.univ (\u03bb (x_1 : fin l), A x K * B K x_1 * C x_1 y)),\n\n-- Now we can cancel the first sum and it's all downhill from here.\n\napply congr_arg _,\napply funext,\nintro z,\nrw finset.mul_sum, -- c*sum a_n = sum c*a_n\n\napply congr_arg,\napply funext,\n\nintro w,\nrw mul_assoc,\nend\n\ntheorem left_distrib (R:Type) [ring R] {m n l  : nat} (A : matrix R m n) (B : matrix R n l) (C : matrix R n l ) :\nmul R A (add R B C) = add R (mul R A B) (mul R A C) :=\nbegin\nunfold mul,\nunfold add,\napply funext,\nintro x,\napply funext,\nintro y,\n\n\nhave H3 :     finset.sum finset.univ (\u03bb (K : fin n), A x K * B K y) + finset.sum finset.univ (\u03bb (K : fin n), A x K * C K y)\n            = finset.sum finset.univ (\u03bb (K : fin n), A x K * B K y + A x K * C K y),\n{simp[finset.sum_add_distrib]},\n\nrw[H3],\nclear H3,\n\napply congr_arg _,\napply funext,\nintro z,\nrw [left_distrib]\nend\n\n\ntheorem right_distrib (R:Type) [ring R] {m n l  : nat} (A : matrix R m n) (B : matrix R m n) (C : matrix R n l ) :\nmul R (add R A B) C  = add R (mul R A C) (mul R B C) :=\nbegin\nunfold mul,\nunfold add,\napply funext,\nintro x,\napply funext,\nintro y,\n\nhave H4 :     finset.sum finset.univ (\u03bb (K : fin n), A x K * C K y) + finset.sum finset.univ (\u03bb (K : fin n), B x K * C K y)\n            = finset.sum finset.univ (\u03bb (K : fin n), A x K * C K y + B x K * C K y),\n{simp[finset.sum_add_distrib]},\n\nrw[H4],\nclear H4,\n\napply congr_arg _,\napply funext,\nintro z,\nrw [right_distrib]\nend\n\ntheorem mul_sub_mul {R : Type} [comm_ring R] (a b c : \u2115) :\n\u2200 (A B: matrix R a b), \u2200 C : matrix R b c,\nmatrix.sub R (matrix.mul R A C) (matrix.mul R B C) = matrix.mul R (matrix.sub R A B) C :=\nbegin \nintros A B C,\nunfold matrix.sub,\nunfold matrix.mul,\nfunext,\nconv in ((A _ _ - B _ _) * C _ _)\nbegin\n  rw [sub_mul],\nend,\n{simp[finset.sum_add_distrib]},\nend\n\ndefinition identity_matrix ( R : Type) [ring R] { n: nat }: (matrix R n n):= \n\u03bb  I J ,\nif I=J then 1\nelse 0\n\n--set_option pp.all true\n--set_option pp.notation false\ntheorem one_mul ( R : Type) [ring R] {n: nat }(A:matrix R n n):\nmul R (identity_matrix R) A = A:=\nbegin\nunfold mul,\nunfold identity_matrix,\napply funext,\nintro x,\napply funext,\nintro y,\nlet xfinset : finset (fin n) := finset.singleton x,\nsuffices : finset.sum finset.univ (\u03bb (K : fin n), ite (x = K) 1 0 * A K y)\n            = finset.sum xfinset (\u03bb t, A t y),\n  simp [this],\n--  exact finset.sum_singleton,\n  apply eq.symm,\n  have H1 : finset.sum xfinset (\u03bb (t : fin n), A t y) = finset.sum xfinset (\u03bb (K : fin n), ite (x = K) 1 0 * A K y),\n    rw finset.sum_singleton, \n    rw finset.sum_singleton, \n    simp,\n  rw H1,\n  refine (finset.sum_subset (_ : xfinset \u2286 finset.univ) _),\n  exact finset.subset_univ xfinset,\n  intros K H H2,\n  have H3 : \u00ac (x = K),\n    intro H4,\n    apply H2,\n    rw \u2190H4,\n    apply finset.mem_singleton.2,\n    refl,\n  simp [H3],  \n\nend\n--#check @finset.sum_subset\n--finset.sum_subset :\n--  \u2200 {\u03b1 : Type u_1} {\u03b2 : Type u_2} {s\u2081 s\u2082 : finset \u03b1} {f : \u03b1 \u2192 \u03b2} [_inst_1 : add_comm_monoid \u03b2],\n--    s\u2081 \u2286 s\u2082 \u2192 (\u2200 (x : \u03b1), x \u2208 s\u2082 \u2192 x \u2209 s\u2081 \u2192 f x = 0) \u2192 finset.sum s\u2081 f = finset.sum s\u2082 f\n\ntheorem mul_one ( R : Type) [ring R] {n: nat }(A:matrix R n n):\nmul R A (identity_matrix R) = A:=\nbegin\nunfold mul,\nunfold identity_matrix,\napply funext,\nintro x,\napply funext,\nintro y,\nlet yfinset : finset (fin n) := finset.singleton y,\nsuffices : finset.sum finset.univ (\u03bb (K : fin n), A x K * ite (K = y) 1 0 )\n           = finset.sum yfinset (\u03bb t, A x t),  \nsimp [this],\napply eq.symm,\nhave H1 : finset.sum yfinset (\u03bb (t : fin n), A x t) = finset.sum yfinset (\u03bb (K : fin n), A x K * ite (K = y) 1 0 ),\n         rw finset.sum_singleton, \n         rw finset.sum_singleton, \n         simp,\nrw H1,\nrefine (finset.sum_subset (_ : yfinset \u2286 finset.univ) _),\nexact finset.subset_univ yfinset,\nintros K H H2,\nhave H3 : \u00ac (K = y),\n         intro H4,\n         apply H2,\n         rw H4,\n         apply finset.mem_singleton.2,\n         refl,\nsimp[H3],\nend\n\n\ninstance ring ( R : Type) [ring R] { n: nat }: ring (matrix R n n):={\nadd:= matrix.add R ,\nadd_assoc := @matrix.add_assoc2 R _ n n,\nzero := matrix.zero R ,\nneg := matrix.neg R,\nzero_add := @matrix.zero_add R _ n n,\nadd_zero := @matrix.add_zero R _ n n,\nadd_left_neg := @matrix.add_left_neg R _ n n,\nadd_comm := @matrix.add_comm R _ n n,\nmul := matrix.mul R,\nmul_assoc := \u03bb A B C, eq.symm $ @matrix.mul_assoc R _ n n n n A B C,\nmul_one := @matrix.mul_one R _ n ,\none := matrix.identity_matrix R,\none_mul := @matrix.one_mul R _ n ,\nleft_distrib := @matrix.left_distrib R _ n n n,\nright_distrib := @matrix.right_distrib R _ n n n\n}\n\nend matrix\n\nnamespace M_module\n\ndef smul_M {F : Type} {n m : \u2115} [ring F] (a : F) (M : matrix F n m) :\nmatrix F n m := \u03bb I, \u03bb J, a * (M I J)\n\ninstance (F : Type) [ring F] (n m : \u2115) : has_scalar F (matrix F n m) :=\n{ \n    smul := smul_M\n}\n\ntheorem smul_add' {F : Type} {n m : \u2115} [ring F] (s : F) (m1 m2 : matrix F n m) : \n  smul_M s (matrix.add F m1 m2) = matrix.add F (smul_M s m1) (smul_M s m2) := \nbegin\nunfold smul_M,\nfunext,\nunfold matrix.add,\nrw [mul_add],\nend\n\ntheorem add_smul' {F : Type} {n m : \u2115} [ring F] (s t : F) (M : matrix F n m) :\nsmul_M (s + t) M = (smul_M s M) + (smul_M t M) := \nbegin\nunfold smul_M,\nsimp only [add_mul],\nfunext,\ncongr,\nend\n\ntheorem mul_smul' {F : Type} {n m : \u2115} [ring F] (s t : F) (M : matrix F n m) :\nsmul_M (s * t) M = smul_M s (smul_M t M) := \nbegin\nunfold smul_M,\nfunext,\nrw [mul_assoc],\nend\n\ntheorem one_smul' {F : Type} {n m : \u2115} [ring F] (M : matrix F n m) :\nsmul_M (1 : F) M = M :=\nbegin\n  unfold smul_M,\n  funext,\n  rw [one_mul],\nend\n\ninstance {R : Type} {n m : \u2115} [ring R] : module R (matrix R n m) :=\n{\n  smul_add := smul_add',\n  add_smul := add_smul',\n  mul_smul := mul_smul',\n  one_smul := one_smul',\n}\nend M_module\n/-\n\ndec_trivial\nfinset.range\nI.val \n-/\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/xenalib/Ellen_Arlt_matrix_rings.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7012356356165914}}
{"text": "import combinatorics.simple_graph.coloring\n\n\n--OUTPUT 1\ntheorem bipartite_graph_two_colorable (G : Type*) [graph G] : two_colorable G \u2194 bipartite G :=\nbegin\n  -- Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color.\n  assume h1 : two_colorable G,\n  -- Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue.\n  have h2 : \u2203 A B : set G, \u2200 v : G, v \u2208 A \u2228 v \u2208 B, from by auto [h1],\n  -- Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$.\n  have h3 : \u2200 a b : G, a \u2208 A \u2227 b \u2208 A \u2192 \u00ac edge a b, from by auto [h1],\n  have h4 : \u2200 a b : G, a \u2208 B \u2227 b \u2208 B \u2192 \u00ac edge a b, from by auto [h1],\n  -- This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n  have h5 : \u2200 a b : G, edge a b \u2192 (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A), from by auto [h1],\n  show bipartite G, from by auto [h2, h3, h4, h5],\n\n  -- Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$.\n  assume h1 : bipartite G,\n  -- Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n  have h2 : \u2203 A B : set G, \u2200 v : G, v \u2208 A \u2228 v \u2208 B, from by auto [h1],\n  have h3 : \u2200 a b : G, a \u2208 A \u2227 b \u2208 A \u2192 \u00ac edge a b, from by auto [h1],\n  have h4 : \u2200 a b : G, a \u2208 B \u2227 b \u2208 B \u2192 \u00ac edge a b, from by auto [h1],\n  have h5 : \u2200 a b : G, edge a b \u2192 (a \u2208 A \u2227 b \u2208 B) \u2228 (a \u2208 B \u2227 b \u2208 A), from by auto [h1],\n  show two_colorable G, from by auto [h2, h3, h4, h5],\nend\n\n/- FEW SHOT PROMPTS TO CODEX(START)\n/--`theorem`\nPower Set is Closed under Intersection\nLet $S$ be a set.\n\nLet $\\powerset S$ be the power set of $S$.\n\n\nThen:\n:$\\forall A, B \\in \\powerset S: A \\cap B \\in \\powerset S$\n`proof`\nLet $A, B \\in \\powerset S$.\n\nThen by the definition of power set, $A \\subseteq S$ and $B \\subseteq S$.\n\nFrom Intersection is Subset we have that $A \\cap B \\subseteq A$.\n\nIt follows from Subset Relation is Transitive that $A \\cap B \\subseteq S$.\n\nThus $A \\cap B \\in \\powerset S$ and closure is proved.\n{{qed}}\n-/\ntheorem power_set_intersection_closed {\u03b1 : Type*} (S : set \u03b1) : \u2200 A B \u2208 \ud835\udcab S, (A \u2229 B) \u2208 \ud835\udcab S :=\nbegin\n  -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$\n  assume (A : set \u03b1) (hA : A \u2208 \ud835\udcab S) (B : set \u03b1) (hB : B \u2208 \ud835\udcab S),\n  -- Then $A \u2286 S$ and $B \u2286 S$, by power set definition\n  have h1 : (A \u2286 S) \u2227 (B \u2286 S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],\n  -- Then $(A \u2229 B) \u2286 A$, by intersection of set is a subset\n  have h2 : (A \u2229 B) \u2286 A, from by auto [set.inter_subset_left],\n  -- Then $(A \u2229 B) \u2286 S$, by subset relation is transitive \n  have h3 : (A \u2229 B) \u2286 S, from by auto [set.subset.trans],\n  -- Hence $(A \u2229 B) \u2208  \ud835\udcab S$, by power set definition\n  show (A \u2229 B) \u2208  \ud835\udcab S, from by auto [set.mem_powerset],\nend\n\n/--`theorem`\nSquare of Sum\n :$\\forall x, y \\in \\R: \\paren {x + y}^2 = x^2 + 2 x y + y^2$\n`proof`\nFollows from the distribution of multiplication over addition:\n\n{{begin-eqn}}\n{{eqn | l = \\left({x + y}\\right)^2\n      | r = \\left({x + y}\\right) \\cdot \\left({x + y}\\right)\n}}\n{{eqn | r = x \\cdot \\left({x + y}\\right) + y \\cdot \\left({x + y}\\right)\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x \\cdot x + x \\cdot y + y \\cdot x + y \\cdot y\n      | c = Real Multiplication Distributes over Addition\n}}\n{{eqn | r = x^2 + 2xy + y^2\n      | c = \n}}\n{{end-eqn}}\n{{qed}}\n-/\ntheorem square_of_sum (x y : \u211d) : (x + y)^2 = (x^2 + 2*x*y + y^2) := \nbegin\n  -- expand the power\n  calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]\n  -- distributive property of multiplication over addition gives:\n  ... = x*(x+y) + y*(x+y) : by auto [add_mul]\n  -- applying the above property further gives:\n  ... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]\n  -- rearranging the terms using commutativity and adding gives:\n  ... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring]\nend\n\n/--`theorem`\nIdentity of Group is Unique\nLet $\\struct {G, \\circ}$ be a group. Then there is a unique identity element $e \\in G$.\n`proof`\nFrom Group has Latin Square Property, there exists a unique $x \\in G$ such that:\n:$a x = b$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = b$\n\nSetting $b = a$, this becomes:\n\nThere exists a unique $x \\in G$ such that:\n:$a x = a$\n\nand there exists a unique $y \\in G$ such that:\n:$y a = a$\n\nThese $x$ and $y$ are both $e$, by definition of identity element.\n{{qed}}\n-/\ntheorem group_identity_unique {G : Type*} [group G] : \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a :=\nbegin\n  -- Group has Latin Square Property\n  have h1 : \u2200 a b : G, \u2203! x : G, a * x = b, from by auto using [use (a\u207b\u00b9 * b)],\n  have h2 : \u2200 a b : G, \u2203! y : G, y * a = b, from by auto using [use b * a\u207b\u00b9], \n\n  -- Setting $b = a$, this becomes:\n  have h3 : \u2200 a : G, \u2203! x : G, a * x = a, from by auto [h1],\n  have h4 : \u2200 a : G, \u2203! y : G, y * a = a, from by auto [h2],\n\n  -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element\n  have h5 : \u2200 a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one],\n  have h6 : \u2200 a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul],\n\n  show \u2203! e : G, \u2200 a : G, e * a = a \u2227 a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)],\nend\n\n/--`theorem`\nBipartite Graph is two colorable\nLet $G$ be a graph. Then $G$ is 2-colorable if and only if $G$ is bipartite.\n`proof`\nLet $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite.\n\nConversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$. Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable.\n\nQED\n\n-/\ntheorem \nFEW SHOT PROMPTS TO CODEX(END)-/\n", "meta": {"author": "ayush1801", "repo": "Autoformalisation_benchmarks", "sha": "51e1e942a0314a46684f2521b95b6b091c536051", "save_path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks", "path": "github-repos/lean/ayush1801-Autoformalisation_benchmarks/Autoformalisation_benchmarks-51e1e942a0314a46684f2521b95b6b091c536051/proof/lean_proof_auto_with_comments-Natural-Language-Proof-Translation/lean_proof_auto_with_comments-3_few_shot_temperature_0_max_tokens_2000_n_1/clean_files/Bipartite Graph is two colorable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387956435734, "lm_q2_score": 0.8459424392504911, "lm_q1q2_score": 0.7012345067760888}}
{"text": "import tactic -- hide\nopen nat -- hide\n\n/-\n## The `use` tactic\n\nThe following tactic works on goals of the form \"There exists $x$ such that...\". So if the goal starts\nwith `\u2203`, to prove it you need to supply a value for $x$ and then prove that this value works. The first\npart will be done with the `use x` (replace `x` with an actual value) and then the goal will\nchange into proving the required property of `x`.\n-/\n\n/- Symbol:\n\u2203 : \\exists\n-/\n/- Lemma : no-side-bar\nThere is a solution to $x^2+5 = 14$ in $\\mathbb{N}$.\n-/\nlemma use0 : \u2203 (x : \u2115), x^2 + 5 = 14 :=\nbegin\n  use 3,\n  ring,\n\n\n\n  \nend", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/tactics_world/01_use.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7011368294486934}}
{"text": "-- Negation and Falsity\n\nvariables p q r : Prop\n\nexample (hpq : p \u2192 q) (hnq : \u00ac q) : \u00ac p :=\nassume hp : p,\nshow false, from hnq (hpq hp)\n\nexample (hp : p) (hnp : \u00ac p) : q := false.elim (hnp hp)\n\nexample (hp : p) (hnp : \u00ac p) : q := absurd hp hnp\n\nexample (hnp : \u00ac p) (hq : q) (hqp : q \u2192 p) : r :=\nabsurd (hqp hq) hnp\n", "meta": {"author": "agryman", "repo": "theorem-proving-in-lean", "sha": "cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9", "save_path": "github-repos/lean/agryman-theorem-proving-in-lean", "path": "github-repos/lean/agryman-theorem-proving-in-lean/theorem-proving-in-lean-cf5a3a19d0d9d9c0a4f178f79e9b0fa67c5cddb9/src/03-Propositions-and-Proofs/example-3.3.3-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7011368219180403}}
{"text": "/-\nCopyright (c) 2021 Ashvni Narayanan. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ashvni Narayanan, Anne Baanen\n-/\n\nimport algebra.field.basic\nimport data.rat.basic\nimport ring_theory.algebraic\nimport ring_theory.dedekind_domain\nimport ring_theory.integral_closure\nimport ring_theory.polynomial.rational_root\n\n/-!\n# Number fields\nThis file defines a number field and the ring of integers corresponding to it.\n\n## Main definitions\n - `number_field` defines a number field as a field which has characteristic zero and is finite\n    dimensional over \u211a.\n - `ring_of_integers` defines the ring of integers (or number ring) corresponding to a number field\n    as the integral closure of \u2124 in the number field.\n\n## Implementation notes\nThe definitions that involve a field of fractions choose a canonical field of fractions,\nbut are independent of that choice.\n\n## References\n* [D. Marcus, *Number Fields*][marcus1977number]\n* [J.W.S. Cassels, A. Fr\u00f6lich, *Algebraic Number Theory*][cassels1967algebraic]\n* [P. Samuel, *Algebraic Theory of Numbers*][samuel1970algebraic]\n\n## Tags\nnumber field, ring of integers\n-/\n\n/-- A number field is a field which has characteristic zero and is finite\ndimensional over \u211a. -/\nclass number_field (K : Type*) [field K] : Prop :=\n[to_char_zero : char_zero K]\n[to_finite_dimensional : finite_dimensional \u211a K]\n\nopen function\nopen_locale classical big_operators\n\nnamespace number_field\nvariables (K : Type*) [field K] [nf : number_field K]\n\ninclude nf\n\n-- See note [lower instance priority]\nattribute [priority 100, instance] number_field.to_char_zero number_field.to_finite_dimensional\n\nprotected lemma is_algebraic : algebra.is_algebraic \u211a K := algebra.is_algebraic_of_finite\n\nomit nf\n\n/-- The ring of integers (or number ring) corresponding to a number field\nis the integral closure of \u2124 in the number field. -/\ndef ring_of_integers := integral_closure \u2124 K\n\nnamespace ring_of_integers\n\nvariables {K}\n\ninstance [number_field K] : is_fraction_ring (ring_of_integers K) K :=\nintegral_closure.is_fraction_ring_of_finite_extension \u211a _\n\ninstance : is_integral_closure (ring_of_integers K) \u2124 K :=\nintegral_closure.is_integral_closure _ _\n\ninstance [number_field K] : is_integrally_closed (ring_of_integers K) :=\nintegral_closure.is_integrally_closed_of_finite_extension \u211a\n\nlemma is_integral_coe (x : ring_of_integers K) : is_integral \u2124 (x : K) :=\nx.2\n\n/-- The ring of integers of `K` are equivalent to any integral closure of `\u2124` in `K` -/\nprotected noncomputable def equiv (R : Type*) [comm_ring R] [algebra R K]\n  [is_integral_closure R \u2124 K] : ring_of_integers K \u2243+* R :=\n(is_integral_closure.equiv \u2124 R K _).symm.to_ring_equiv\n\nvariables (K)\n\ninstance [number_field K] : char_zero (ring_of_integers K) := char_zero.of_module _ K\n\ninstance [number_field K] : is_dedekind_domain (ring_of_integers K) :=\nis_integral_closure.is_dedekind_domain \u2124 \u211a K _\n\nend ring_of_integers\n\nend number_field\n\nnamespace rat\n\nopen number_field\n\ninstance rat.number_field : number_field \u211a :=\n{ to_char_zero := infer_instance,\n  to_finite_dimensional := by { convert (infer_instance : finite_dimensional \u211a \u211a),\n             -- The vector space structure of `\u211a` over itself can arise in multiple ways:\n             -- all fields are vector spaces over themselves (used in `rat.finite_dimensional`)\n             -- all char 0 fields have a canonical embedding of `\u211a` (used in `number_field`).\n             -- Show that these coincide:\n             ext, simp [algebra.smul_def] } }\n\n/-- The ring of integers of `\u211a` as a number field is just `\u2124`. -/\nnoncomputable def ring_of_integers_equiv : ring_of_integers \u211a \u2243+* \u2124 :=\nring_of_integers.equiv \u2124\n\nend rat\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/number_theory/number_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7011368183793242}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module combinatorics.additive.ruzsa_covering\n! leanprover-community/mathlib commit b363547b3113d350d053abdf2884e9850a56b205\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.Finset.Pointwise\n\n/-!\n# Ruzsa's covering lemma\n\nThis file proves the Ruzsa covering lemma. This says that, for `s`, `t` finsets, we can cover `s`\nwith at most `(s + t).card / t.card` copies of `t - t`.\n\n## TODO\n\nMerge this file with other prerequisites to Freiman's theorem once we have them.\n-/\n\n\nopen Pointwise\n\nnamespace Finset\n\nvariable {\u03b1 : Type _} [DecidableEq \u03b1] [CommGroup \u03b1] (s : Finset \u03b1) {t : Finset \u03b1}\n\n/-- **Ruzsa's covering lemma**. -/\n@[to_additive \"**Ruzsa's covering lemma**\"]\ntheorem exists_subset_mul_div (ht : t.Nonempty) :\n    \u2203 u : Finset \u03b1, u.card * t.card \u2264 (s * t).card \u2227 s \u2286 u * t / t := by\n  haveI : \u2200 u, Decidable ((u : Set \u03b1).PairwiseDisjoint (\u00b7 \u2022 t)) := fun u \u21a6 Classical.dec _\n  set C := s.powerset.filter fun u \u21a6 u.toSet.PairwiseDisjoint (\u00b7 \u2022 t)\n  obtain \u27e8u, hu, hCmax\u27e9 := C.exists_maximal (filter_nonempty_iff.2\n    \u27e8\u2205, empty_mem_powerset _, by rw [coe_empty]; exact Set.pairwiseDisjoint_empty\u27e9)\n  rw [mem_filter, mem_powerset] at hu\n  refine' \u27e8u,\n    (card_mul_iff.2 <| pairwiseDisjoint_smul_iff.1 hu.2).ge.trans\n      (card_le_of_subset <| mul_subset_mul_right hu.1),\n    fun a ha \u21a6 _\u27e9\n  rw [mul_div_assoc]\n  by_cases hau : a \u2208 u\n  \u00b7 exact subset_mul_left _ ht.one_mem_div hau\n  by_cases H : \u2200 b \u2208 u, Disjoint (a \u2022 t) (b \u2022 t)\n  \u00b7 refine' (hCmax _ _ <| ssubset_insert hau).elim\n    rw [mem_filter, mem_powerset, insert_subset, coe_insert]\n    exact \u27e8\u27e8ha, hu.1\u27e9, hu.2.insert fun _ hb _ \u21a6 H _ hb\u27e9\n  push_neg at H\n  simp_rw [not_disjoint_iff, \u2190 inv_smul_mem_iff] at H\n  obtain \u27e8b, hb, c, hc\u2081, hc\u2082\u27e9 := H\n  refine' mem_mul.2 \u27e8b, a / b, hb, _, by simp\u27e9\n  exact mem_div.2 \u27e8_, _, hc\u2082, hc\u2081, by simp [div_eq_mul_inv a b, mul_comm]\u27e9\n#align finset.exists_subset_mul_div Finset.exists_subset_mul_div\n#align finset.exists_subset_add_sub Finset.exists_subset_add_sub\n\nend Finset\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Combinatorics/Additive/RuzsaCovering.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7011368100642307}}
{"text": "import divisibility2\nimport data.nat.sqrt\nimport number_theory.quadratic_reciprocity\n\nlemma qr_mod4 (a : \u2115 ): (a^2%4)=0 \u2228 (a^2%4)=1:=\nbegin\n    rw nat.pow_two, rw nat.mul_mod, \n    have h1:= nat.mod_lt a (show 4>0, by linarith), interval_cases a%4; rw h; tauto\nend\n\nlemma diff_of_squares_neq_2 (a b: \u2115 ): a^2 +2 \u2260 b^2:=\nbegin\n    by_contra, push_neg at a_1, apply_fun (\u03bb (u: \u2115 ), u%4) at a_1, rw nat.add_mod at a_1,\n    have h1:= qr_mod4 b, cases qr_mod4 a, \n    {rw h at a_1, simp [(show 2%4 =2, from rfl)] at a_1,rw \u2190 a_1 at h1, cc},\n    {rw h at a_1, simp [(show (1+2)%4 = 3, from rfl)] at a_1, rw \u2190 a_1 at h1,cc}\nend\n\nlemma is_contra (P:  Prop) : P \u2194 (\u00ac P \u2192 false):=\nbegin\n    cc,\nend \n\nlemma to_3_n_gt_n (n:\u2115 ): n + 1 \u2264 3^n :=\nbegin\n  induction n with d hd,\n  {simp},\n  {calc d.succ + 1 = (d + 1) + 1 : rfl\n  ...             \u2264 3 ^ d + 1 : add_le_add_right' hd\n  ...             \u2264 3 ^ d + 2 * 3 ^ d : add_le_add_left' _\n  ... = 3 ^ d.succ : by rw [nat.pow_succ]; ring,\n  show 0 < _,\n  apply mul_pos, simp,\n  apply nat.pow_pos, simp}\nend\n\nlemma max_pow_3 (n: \u2115 ) (h0 : n>0): \u2203 (r: \u2115 ), 3^r \u2223 n \u2227 \u00ac 3^(r+1)\u2223 n:=\nbegin\n    rw is_contra ( \u2203 (r : \u2115), 3 ^ r \u2223 n \u2227  \u00ac3 ^ (r + 1) \u2223 n), rw  not_exists, intro p, push_neg at p,\n    have h1: \u2200 x: \u2115 , 3 ^(x+1) \u2223 n,\n        {intro q, induction q with d hd,\n        {cases p 0 with p1 p2, exfalso, simp at p1, assumption, assumption},\n        {rw nat.succ_eq_add_one, cases p (d+1) with p1 p2,  contradiction, assumption}},\n    have h3:= nat.le_of_dvd h0 (h1 n),\n    have h4:= to_3_n_gt_n (n+1), linarith\nend\n\nlemma decomp_pow_3 (n: \u2115 ) (h : n>0): \u2203 (r k: \u2115 ), n = 3^r *k \u2227 \u00ac 3 \u2223 k:=\nbegin \n    cases max_pow_3 n h with s h1, cases h1 with h1 h2, cases h1 with m h1, use s, use m,\n    split, \n    {assumption}, \n    {by_contra, cases a with b a, rw a at h1, rw \u2190 mul_assoc at h1, \n    have h3: 3^(s+1) \u2223 n, \n        {use b, rw nat.pow_add, simp [h1]},\n    contradiction}\nend\n\nlemma non_res_3_mod_4 (d a: \u2115 ) (h: d>0): (a^2: zmod d) = -1 \u2192 (d%4) \u2260 3:=\nbegin\n    apply nat.strong_induction_on d, intros n h1 h2, cases classical.em (n.prime), \n    {have h3: fact n.prime, {assumption},\n    rw \u2190 @zmod.exists_pow_two_eq_neg_one_iff_mod_four_ne_three n h3, use a, exact h2},\n    {cases classical.em (n<2), \n        {interval_cases n,  \n        {rw [show 0%4=0, from rfl], linarith},  \n        {rw [show 1%4=1, from rfl], linarith}},\n    push_neg at h_2, cases nat.exists_dvd_of_not_prime2 h_2 h_1, \n    rcases h_3 with \u27e8 h3, h4, h5\u27e9, cases h3 with v h3, rw nat.succ_le_iff at h4, \n    have h5': v>0,\n        {by_contra, push_neg at a_1, interval_cases v, rotate, linarith}, \n    rw \u2190  lt_mul_iff_one_lt_left h5' at h4, rw \u2190 h3 at h4, \n    have h6: ((a^2:\u2124 ): zmod n) = ((-1: \u2124 ) : zmod n), {simp, exact h2}, \n    rw zmod.int_coe_eq_int_coe_iff at h6, \n    have h7:= int.modeq.modeq_of_dvd_of_modeq (show (w: \u2124 ) \u2223 (n:\u2124  ), by simp[h3]) h6,\n    have h8:= int.modeq.modeq_of_dvd_of_modeq (show (v:\u2124 ) \u2223 (n:\u2124 ), by simp[h3]) h6,\n    rw \u2190 zmod.int_coe_eq_int_coe_iff at *,  simp at h7, simp at h8, \n    have h9:= h1 v h4 h8, \n    have h10:= h1 w h5 h7,\n    rw h3, rw nat.mul_mod, \n    have h11:= nat.mod_lt w (show 4>0, by linarith),\n    have h12:= nat.mod_lt v (show 4>0, by linarith),\n    interval_cases w%4; rw h_3; simp, {linarith}, {assumption},\n    interval_cases v%4; rw h_4; simp [(show 2*2 =4, from rfl), (show 2%4=2, from rfl)]; linarith}\nend\n\nlemma squares_inv (a b n x: \u2115 ) (h: nat.coprime a n) (h0: nat.coprime b n) (h1: (b*x^2 :zmod n) = -(b*a^2)) (h2:fact (0<n)):  \u2203 (r: \u2115 ),(r^2 : zmod n ) = -1:=\nbegin\n    use ((x* a\u207b\u00b9 :zmod n).val), rw zmod.cast_val ((x* a\u207b\u00b9: zmod n)),\n    have h3:= zmod.coe_mul_inv_eq_one a h, \n    have h4:= zmod.coe_mul_inv_eq_one b h0,\n    rw mul_comm at h1, nth_rewrite 1 mul_comm at h1, apply_fun (\u03bb (a: zmod n), (a* b\u207b\u00b9 :zmod n) ) at h1, rw \u2190 neg_one_mul at h1, repeat {rw mul_assoc at h1}, rw h4 at h1, rw mul_one at h1,\n    rw [show (-1: zmod n)=-1*1, by simp],rw \u2190 h3, rw mul_pow, rw h1, ring\nend\n\nlemma pow_3_odd (u :\u2115 ): (3^u)%2=1:=\nbegin\n    induction u with d hd,\n    {ring},\n    {rw nat.pow_succ, simp [nat.mul_mod, hd], ring}\nend\n\nlemma double_not_zero_mod3 (u: \u2115 ) (h1: \u00ac 3 \u2223 u) : 2 \u2223 2*u \u2227 (2*u)%3 \u2260 0:=\nbegin\n    split, {simp},\n    {by_contra, push_neg at a, rw \u2190 nat.dvd_iff_mod_eq_zero at a, \n    have a2:= nat.coprime.dvd_of_dvd_mul_left (show nat.coprime 3 2, by tauto) a, contradiction}\nend \n\nlemma fun_gen_add (a u n s q r x y: \u2115 ) (f: \u2115 \u2192 \u2115 ) (h2: n =  x+4*a*s ) (h3: s =q+1 ) (h4: s=3^r*u ) (h5: \u2200 (m: \u2115),y \u2223 f(m+2*(2*a*u)) +f(m)): y \u2223 f(n) + f(x):=\nbegin\n    nth_rewrite 0 h2, rw \u2190 one_mul (f x),\n    have g8: 1  = (-1: \u2124 )^(3^r *(0+1)-1), \n        {have g9: 2 \u2223 3^r-1, {nth_rewrite 2 \u2190 pow_3_odd r, apply nat.dvd_sub_mod}, \n        rw zero_add, rw mul_one, rw neg_1_pow_even _ g9},\n    rw \u2190 int.coe_nat_dvd, push_cast, rw g8, rw h4, rw [show (4*a)* (3 ^ r * u) = 3^r * (2*a*(2*u)), by ring],\n    apply mod_fun_gen y (2*a*(2*u)) 0 (3^r) (x) (f) (nat.one_le_pow' r 2), rw [show (-1:\u2124 )^0 =1, by ring], norm_cast, intro m, rw one_mul, rw [show 2*a*(2*u) = 2*(2*a*u), by ring], exact h5 m,\nend\n\nlemma res_mod_4' (n: \u2115 ): n%2=0 \u2228 n%4=1 \u2228 n%4=3:=\nbegin\n    have g1:= nat.mod_lt n (show 4>0, by linarith),\n    have g2:= nat.mod_mul_left_mod n 2 2, rw (show 2*2 =4, from rfl) at g2,\n    interval_cases n%4; rw h at g2; simp [*, (show 2%2=0, from rfl), (show 0%2=0, from rfl)] at *\nend \n\ntheorem luc_square (n k: \u2115 ) (h: luc n =k^2) :  n=1 \u2228 n=3:=\nbegin\n    cases res_mod_4' n with h0 h1', cases div_algo n 2 with  w h1, rw h0 at h1, rw add_zero at h1,\n    {rw h1 at h, apply_fun (\u03bb (a: \u2115 ), (a + 2*(-1)^w : \u2124 )) at h, rw fib_luc3 at h, cases even_or_odd w with v h3, cases h3 with h3 h4,\n    {rw h3 at h, \n    have h5:= neg_1_pow_even (2*v) (show 2 \u2223 2*v, by simp), rw h5 at h, rw mul_one at h, norm_cast at h,\n    have h6:= diff_of_squares_neq_2 k (luc(2*v)), rw h at h6, contradiction},\n    {rw h4 at h, rw neg_1_pow_odd at h, apply_fun (\u03bb (a: \u2124 ), a+2) at h, \n    have h7:= diff_of_squares_neq_2 (luc(2*v+1)) k, ring at h, norm_cast at h}},\n\n    {cases div_algo n 4 with s h2, cases nat_case_bash s 0 with g2 g3, swap,\n    {cases g3 with q g3, rw add_zero q at g3, cases decomp_pow_3 s (show s>0, by linarith) with r g4, rcases g4 with \u27e8 u, g4, g5 \u27e9, rw add_comm at h2,\n    have g6:=double_not_zero_mod3 u g5, \n    have g7:=fun_gen_add 1 u n s q r (n%4) (luc(2*u)) (luc) h2 g3 g4 (mod_luc (2*1*u) g6), repeat{rw mul_one at g7},\n    rw h at g7, rw \u2190 zmod.nat_coe_zmod_eq_zero_iff_dvd at g7, apply_fun (\u03bb (a: zmod (luc(2*u))), (a- luc(n%4))) at g7,\n    have H: (k^2 : zmod (luc(2*u))) = -luc(n%4), {simp at g7, exact g7}, cases h1' with h_1 h_2,\n    {rw h_1 at H, rw [show luc 1 =1, from rfl] at H, simp at H, \n    have g10:= non_res_3_mod_4 _ _ (luc_pos (2*u)) H, rw luc_mod_4 (2*u) g6 at g10, contradiction},\n\n    {rw h_2 at H, rw [show luc 3 =4, from rfl] at H,  \n    rw [show 4=1*2*2, by ring] at H, rw pow_two at H, nth_rewrite 0 \u2190 one_mul (k) at H, repeat{rw nat.cast_mul at H}, repeat{rw mul_assoc at H}, repeat{rw \u2190 pow_two at H}, \n    have g11:= squares_inv 2 1 (luc(2*u)) k (show nat.coprime 2 (luc(2*u)), from luc_coprime_2 _ (g6.2)) (nat.coprime_one_left (luc(2*u))) H (luc_pos(2*u)), cases g11 with r g11,\n    have g12:= non_res_3_mod_4 _ _ (luc_pos (2*u)) g11, rw luc_mod_4 (2*u) g6 at g12, contradiction}},\n    rw le_zero_iff_eq at g2, rw g2 at h2, \n    have g3:= nat.mod_lt n (show 4>0, by linarith), interval_cases (n%4); rw h_1 at h2; simp[h2]; omega}\nend", "meta": {"author": "mhk119", "repo": "fibonacci_squares", "sha": "d3ca98693c352e192471268da584a4d73573b0be", "save_path": "github-repos/lean/mhk119-fibonacci_squares", "path": "github-repos/lean/mhk119-fibonacci_squares/fibonacci_squares-d3ca98693c352e192471268da584a4d73573b0be/src/luc_squares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.7011340454333315}}
{"text": "example (n : \u2115) : n + 1 = nat.succ n :=\nbegin\n  show nat.succ n = nat.succ n,\n  reflexivity\nend\n\nexample (p q : Prop) : p \u2227 q \u2192 q \u2227 p :=\nbegin\n  intro h,\n  cases h with hp hq,\n  split,\n  show q, from hq,\n  show p, from hp\nend\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  intro h,\n  cases h with hp hqr,\n  show (p \u2227 q) \u2228 (p \u2227 r),\n  cases hqr with hq hr,\n    have hpq : p \u2227 q,\n      from and.intro hp hq,\n    left, exact hpq,\n  have hpr : p \u2227 r,\n  from and.intro hp hr,\n  right, exact hpr\nend\n\n\nexample (p q r : Prop) : p \u2227 (q \u2228 r) \u2192 (p \u2227 q) \u2228 (p \u2227 r) :=\nbegin\n  intro h,\n  cases h with hp hqr,\n  show (p \u2227 q) \u2228 (p \u2227 r),\n  cases hqr with hq hr,\n    have hpq : p \u2227 q,\n      split, repeat {assumption},\n    left, exact hpq,\n  have hpr : p \u2227 r,\n    split, repeat {assumption},\n  right, exact hpr\nend\n\nexample : \u2203 x, x + 2 = 8 :=\nbegin\n  let a : \u2115 := 3 * 2,\n  existsi a,\n  reflexivity\nend\n\n\n\n", "meta": {"author": "robkorn", "repo": "theorem-proving-in-lean-exercises", "sha": "9c51da587105ee047a9db55d52709d881a39be7a", "save_path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises", "path": "github-repos/lean/robkorn-theorem-proving-in-lean-exercises/theorem-proving-in-lean-exercises-9c51da587105ee047a9db55d52709d881a39be7a/Chapter5/5-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.701062819260735}}
{"text": "def f : Nat \u00d7 Nat \u2192 Nat\n  | (a, b) => a + b\n\ndef f' : Nat \u00d7 Nat \u2192 Nat\n  | (a, b) => by done\n\nexample (x : Nat \u00d7 Nat) (h : x.1 > 0) : f x > 0 := by\n  match x with\n  | (a, b) => done\n\ndef g (x : Nat) : Nat \u00d7 Nat :=\n  (x, x+1)\n\nexample (x : Nat) : Nat :=\n  match g x with\n  | (a, b) => by done\n\ninductive Vector (\u03b1 : Type u) : Nat \u2192 Type u where\n  | nil  : Vector \u03b1 0\n  | cons : \u03b1 \u2192 Vector \u03b1 n \u2192 Vector \u03b1 (n+1)\n\nnamespace Vector\n  def insert (a: \u03b1): Fin (n+1) \u2192 Vector \u03b1 n \u2192 Vector \u03b1 (n+1)\n    | \u27e80  , _\u27e9,        xs => cons a xs\n    | \u27e8i+1, h\u27e9, cons x xs => by done\n\nend Vector\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/tests/lean/matchLeftovers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7010628094003137}}
{"text": "/-\nCopyright (c) 2021 R\u00e9my Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: R\u00e9my Degenne\n-/\nimport measure_theory.measure_space\nimport order.filter.ennreal\n\n/-!\n# Essential supremum and infimum\nWe define the essential supremum and infimum of a function `f : \u03b1 \u2192 \u03b2` with respect to a measure\n`\u03bc` on `\u03b1`. The essential supremum is the infimum of the constants `c : \u03b2` such that `f x \u2264 c`\nalmost everywhere.\n\nTODO: The essential supremum of functions `\u03b1 \u2192 \u211d\u22650\u221e` is used in particular to define the norm in\nthe `L\u221e` space (see measure_theory/lp_space.lean).\n\nThere is a different quantity which is sometimes also called essential supremum: the least\nupper-bound among measurable functions of a family of measurable functions (in an almost-everywhere\nsense). We do not define that quantity here, which is simply the supremum of a map with values in\n`\u03b1 \u2192\u2098[\u03bc] \u03b2` (see measure_theory/ae_eq_fun.lean).\n\n## Main definitions\n\n* `ess_sup f \u03bc := \u03bc.ae.limsup f`\n* `ess_inf f \u03bc := \u03bc.ae.liminf f`\n-/\n\nopen measure_theory\nopen_locale ennreal\n\nvariables {\u03b1 \u03b2 : Type*} [measurable_space \u03b1] {\u03bc : measure \u03b1}\n\nsection conditionally_complete_lattice\nvariable [conditionally_complete_lattice \u03b2]\n\n/-- Essential supremum of `f` with respect to measure `\u03bc`: the smallest `c : \u03b2` such that\n`f x \u2264 c` a.e. -/\ndef ess_sup (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) := \u03bc.ae.limsup f\n\n/-- Essential infimum of `f` with respect to measure `\u03bc`: the greatest `c : \u03b2` such that\n`c \u2264 f x` a.e. -/\ndef ess_inf (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1) := \u03bc.ae.liminf f\n\nlemma ess_sup_congr_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f =\u1d50[\u03bc] g) : ess_sup f \u03bc = ess_sup g \u03bc :=\nfilter.limsup_congr hfg\n\nlemma ess_inf_congr_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f =\u1d50[\u03bc] g) :  ess_inf f \u03bc = ess_inf g \u03bc :=\n@ess_sup_congr_ae \u03b1 (order_dual \u03b2) _ _ _ _ _ hfg\n\nend conditionally_complete_lattice\n\nsection complete_lattice\nvariable [complete_lattice \u03b2]\n\n@[simp] lemma ess_sup_measure_zero {f : \u03b1 \u2192 \u03b2} : ess_sup f 0 = \u22a5 :=\nle_bot_iff.mp (Inf_le (by simp [set.mem_set_of_eq, filter.eventually_le, ae_iff]))\n\n@[simp] lemma ess_inf_measure_zero {f : \u03b1 \u2192 \u03b2} : ess_inf f 0 = \u22a4 :=\n@ess_sup_measure_zero \u03b1 (order_dual \u03b2) _ _ _\n\nlemma ess_sup_mono_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f \u2264\u1d50[\u03bc] g) : ess_sup f \u03bc \u2264 ess_sup g \u03bc :=\nfilter.limsup_le_limsup hfg\n\nlemma ess_inf_mono_ae {f g : \u03b1 \u2192 \u03b2} (hfg : f \u2264\u1d50[\u03bc] g) : ess_inf f \u03bc \u2264 ess_inf g \u03bc :=\nfilter.liminf_le_liminf hfg\n\nlemma ess_sup_const (c : \u03b2) (h\u03bc : \u03bc \u2260 0) : ess_sup (\u03bb x : \u03b1, c) \u03bc = c :=\nbegin\n  haveI h\u03bc_ne_bot : \u03bc.ae.ne_bot := by rwa [filter.ne_bot_iff, ne.def, ae_eq_bot],\n  exact filter.limsup_const c,\nend\n\nlemma ess_inf_const (c : \u03b2) (h\u03bc : \u03bc \u2260 0) : ess_inf (\u03bb x : \u03b1, c) \u03bc = c :=\n@ess_sup_const \u03b1 (order_dual \u03b2) _ _ _ _ h\u03bc\n\nlemma ess_sup_const_bot : ess_sup (\u03bb x : \u03b1, (\u22a5 : \u03b2)) \u03bc = (\u22a5 : \u03b2) :=\nfilter.limsup_const_bot\n\nlemma ess_inf_const_top : ess_inf (\u03bb x : \u03b1, (\u22a4 : \u03b2)) \u03bc = (\u22a4 : \u03b2) :=\nfilter.liminf_const_top\n\nlemma order_iso.ess_sup_apply {\u03b3} [complete_lattice \u03b3] (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1)\n  (g : \u03b2 \u2243o \u03b3) :\n  g (ess_sup f \u03bc) = ess_sup (\u03bb x, g (f x)) \u03bc :=\nbegin\n  refine order_iso.limsup_apply g _ _ _ _,\n  all_goals { by filter.is_bounded_default},\nend\n\nlemma order_iso.ess_inf_apply {\u03b3} [complete_lattice \u03b3] (f : \u03b1 \u2192 \u03b2) (\u03bc : measure \u03b1)\n  (g : \u03b2 \u2243o \u03b3) :\n  g (ess_inf f \u03bc) = ess_inf (\u03bb x, g (f x)) \u03bc :=\n@order_iso.ess_sup_apply \u03b1 (order_dual \u03b2) _ _  (order_dual \u03b3) _ _ _ g.dual\n\nend complete_lattice\n\nsection complete_linear_order\nvariable [complete_linear_order \u03b2]\n\nlemma ae_lt_of_ess_sup_lt {f : \u03b1 \u2192 \u03b2} {x : \u03b2} (hf : ess_sup f \u03bc < x) : \u2200\u1d50 y \u2202\u03bc, f y < x :=\nfilter.eventually_lt_of_limsup_lt hf\n\nlemma ae_lt_of_lt_ess_inf {f : \u03b1 \u2192 \u03b2} {x : \u03b2} (hf : x < ess_inf f \u03bc) : \u2200\u1d50 y \u2202\u03bc, x < f y :=\n@ae_lt_of_ess_sup_lt \u03b1 (order_dual \u03b2) _ _ _ _ _ hf\n\nend complete_linear_order\n\nnamespace ennreal\n\nlemma ae_le_ess_sup (f : \u03b1 \u2192 \u211d\u22650\u221e) : \u2200\u1d50 y \u2202\u03bc, f y \u2264 ess_sup f \u03bc :=\neventually_le_limsup f\n\n@[simp] lemma ess_sup_eq_zero_iff {f : \u03b1 \u2192 \u211d\u22650\u221e} : ess_sup f \u03bc = 0 \u2194 f =\u1d50[\u03bc] 0 :=\nlimsup_eq_zero_iff\n\nlemma ess_sup_const_mul {f : \u03b1 \u2192 \u211d\u22650\u221e} {a : \u211d\u22650\u221e} :\n  ess_sup (\u03bb (x : \u03b1), a * (f x)) \u03bc = a * ess_sup f \u03bc :=\nlimsup_const_mul\n\nlemma ess_sup_add_le (f g : \u03b1 \u2192 \u211d\u22650\u221e) : ess_sup (f + g) \u03bc \u2264 ess_sup f \u03bc + ess_sup g \u03bc :=\nlimsup_add_le f g\n\nlemma ess_sup_liminf_le {\u03b9} [encodable \u03b9] [linear_order \u03b9] (f : \u03b9 \u2192 \u03b1 \u2192 \u211d\u22650\u221e) :\n  ess_sup (\u03bb x, filter.at_top.liminf (\u03bb n, f n x)) \u03bc\n    \u2264 filter.at_top.liminf (\u03bb n, ess_sup (\u03bb x, f n x) \u03bc) :=\nby { simp_rw ess_sup, exact ennreal.limsup_liminf_le_liminf_limsup (\u03bb a b, f b a), }\n\nend ennreal\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/measure_theory/ess_sup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7010249472867027}}
{"text": "import ..lovelib\n\nnamespace LoVe\n/- ## Fixpoints\n\nA __fixpoint__ (or fixed point) of `f` is a solution for `X` in the equation\n\n    `X = f X`\n\nIn general, fixpoints may not exist at all (e.g., `f := nat.succ`), or there may\nbe several fixpoints (e.g., `f := id`). But under some conditions on `f`, a\nunique __least fixpoint__ and a unique __greatest fixpoint__ are guaranteed to\nexist.\n\nConsider this __fixpoint equation__:\n\n    `X = (\u03bb(p : \u2115 \u2192 Prop) (n : \u2115), n = 0 \u2228 \u2203m : \u2115, n = m + 2 \u2227 p m) X`\n      `= (\u03bbn : \u2115, n = 0 \u2228 \u2203m : \u2115, n = m + 2 \u2227 X m)`\n\nwhere `X : \u2115 \u2192 Prop` and\n`f := (\u03bb(p : \u2115 \u2192 Prop) (n : \u2115), n = 0 \u2228 \u2203m : \u2115, n = m + 2 \u2227 p m)`.\n\nThe above example admits only one fixpoint. The fixpoint equation uniquely\nspecifies `X` as the set of even numbers.\n\nIn general, the least and greatest fixpoint may be different:\n\n    `X = X`\n\nHere, the least fixpoint is `(\u03bb_, False)` and the greatest fixpoint is\n`(\u03bb_, True)`. Conventionally, `False < True`, and thus\n`(\u03bb_, False) < (\u03bb_, True)`. Similarly, `\u2205 < @set.univ \u03b1` (assuming `\u03b1` is\ninhabited).\n\nFor the semantics of programming languages:\n\n* `X` will have type `set (state \u00d7 state)` (which is isomorphic to\n  `state \u2192 state \u2192 Prop`), representing relations between states;\n\n* `f` will correspond to either taking one extra iteration of the loop (if the\n  condition `b` is true) or the identity (if `b` is false).\n\nKleene's fixpoint theorem:\n\n    `f^0(\u2205) \u222a f^1(\u2205) \u222a f^2(\u2205) \u222a \u22ef = lfp f`\n\nThe least fixpoint corresponds to finite executions of a program, which is all\nwe care about.\n\n**Key observation**:\n\n    Inductive predicates correspond to least fixpoints, but they are built into\n    Lean's logic (the calculus of inductive constructions).\n\n\n## Monotone Functions\n\nLet `\u03b1` and `\u03b2` be types with partial order `\u2264`. A function `f : \u03b1 \u2192 \u03b2` is\n__monotone__ if\n\n    `a\u2081 \u2264 a\u2082 \u2192 f a\u2081 \u2264 f a\u2082`   for all `a\u2081`, `a\u2082`\n\nMany operations on sets (e.g., `\u222a`), relations (e.g., `\u25ef`), and functions\n(e.g., `\u03bbx, x`, `\u03bb_, k`, `\u2218`) are monotone or preserve monotonicity.\n\nAll monotone functions `f : set \u03b1 \u2192 set \u03b1` admit least and greatest fixpoints.\n\n**Example of a nonmonotone function**:\n\n    `f A = (if A = \u2205 then set.univ else \u2205)`\n\nAssuming `\u03b1` is inhabited, we have `\u2205 \u2286 set.univ`, but\n`f \u2205 = set.univ \u2288 \u2205 = f set.univ`. -/\n\ndef monotone {\u03b1 \u03b2 : Type} [partial_order \u03b1] [partial_order \u03b2]\n  (f : \u03b1 \u2192 \u03b2) : Prop :=\n\u2200a\u2081 a\u2082, a\u2081 \u2264 a\u2082 \u2192 f a\u2081 \u2264 f a\u2082\n\nlemma monotone_id {\u03b1 : Type} [partial_order \u03b1] :\n  monotone (\u03bba : \u03b1, a) :=\nbegin\n  intros a\u2081 a\u2082 ha,\n  exact ha\nend\n\nlemma monotone_const {\u03b1 \u03b2 : Type} [partial_order \u03b1]\n    [partial_order \u03b2] (b : \u03b2) :\n  monotone (\u03bb_ : \u03b1, b) :=\nbegin\n  intros a\u2081 a\u2082 ha,\n  exact le_refl b\nend\n\nlemma monotone_union {\u03b1 \u03b2 : Type} [partial_order \u03b1]\n    (f g : \u03b1 \u2192 set \u03b2) (hf : monotone f) (hg : monotone g) :\n  monotone (\u03bba, f a \u222a g a) :=\nbegin\n  intros a\u2081 a\u2082 ha b hb,\n  cases' hb,\n  { exact or.intro_left _ (hf a\u2081 a\u2082 ha h) },\n  { exact or.intro_right _ (hg a\u2081 a\u2082 ha h) }\nend\n\n/-! We will prove the following two lemmas in the exercise. -/\n\nnamespace sorry_lemmas\n\nlemma monotone_comp {\u03b1 \u03b2 : Type} [partial_order \u03b1]\n    (f g : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2)) (hf : monotone f)\n    (hg : monotone g) :\n  monotone (\u03bba, f a \u25ef g a) :=\nsorry\n\nlemma monotone_restrict {\u03b1 \u03b2 : Type} [partial_order \u03b1]\n    (f : \u03b1 \u2192 set (\u03b2 \u00d7 \u03b2)) (p : \u03b2 \u2192 Prop) (hf : monotone f) :\n  monotone (\u03bba, f a \u21c3 p) :=\nsorry\n\nend sorry_lemmas\n\n\n/-! ## Complete Lattices\n\nTo define the least fixpoint on sets, we need `\u2286` and `\u22c2`. Complete lattices\ncapture this concept abstractly. A __complete lattice__ is an ordered type `\u03b1`\nfor which each set of type `set \u03b1` has an infimum.\n\nMore precisely, A complete lattice consists of\n\n* a partial order `\u2264 : \u03b1 \u2192 \u03b1 \u2192 Prop` (i.e., a reflexive, transitive, and\n  antisymmetric binary predicate);\n\n* an operator `Inf : set \u03b1 \u2192 \u03b1`, called __infimum__.\n\nMoreover, `Inf A` must satisfy these two properties:\n\n* `Inf A` is a lower bound of `A`: `Inf A \u2264 b` for all `b \u2208 A`;\n\n* `Inf A` is a greatest lower bound: `b \u2264 Inf A` for all `b` such that\n  `\u2200a, a \u2208 A \u2192 b \u2264 a`.\n\n**Warning:** `Inf A` is not necessarily an element of `A`.\n\nExamples:\n\n* `set \u03b1` is an instance w.r.t. `\u2286` and `\u22c2` for all `\u03b1`;\n* `Prop` is an instance w.r.t. `\u2192` and `\u2200` (`Inf A := \u2200a \u2208 A, a`);\n* `enat := \u2115 \u222a {\u221e}`;\n* `ereal := \u211d \u222a {- \u221e, \u221e}`;\n* `\u03b2 \u2192 \u03b1` if `\u03b1` is a complete lattice;\n* `\u03b1 \u00d7 \u03b2` if `\u03b1`, `\u03b2` are complete lattices.\n\nFinite example (with apologies for the ASCII art):\n\n                Z            Inf {}           = ?\n              /   \\          Inf {Z}          = ?\n             A     B         Inf {A, B}       = ?\n              \\   /          Inf {Z, A}       = ?\n                Y            Inf {Z, A, B, Y} = ?\n\nNonexamples:\n\n* `\u2115`, `\u2124`, `\u211a`, `\u211d`: no infimum for `\u2205`, `Inf \u2115`, etc.\n* `erat := \u211a \u222a {- \u221e, \u221e}`: `Inf {q | 2 < q * q} = sqrt 2` is not in `erat`. -/\n\n@[class] structure complete_lattice (\u03b1 : Type)\n  extends partial_order \u03b1 : Type :=\n(Inf    : set \u03b1 \u2192 \u03b1)\n(Inf_le : \u2200A b, b \u2208 A \u2192 Inf A \u2264 b)\n(le_Inf : \u2200A b, (\u2200a, a \u2208 A \u2192 b \u2264 a) \u2192 b \u2264 Inf A)\n\n/-! For sets: -/\n\n@[instance] def set.complete_lattice {\u03b1 : Type} :\n  complete_lattice (set \u03b1) :=\n{ le          := (\u2286),\n  le_refl     := by tautology,\n  le_trans    := by tautology,\n  le_antisymm :=\n    begin\n      intros A B hAB hBA,\n      apply set.ext,\n      tautology\n    end,\n  Inf         := \u03bbX, {a | \u2200A, A \u2208 X \u2192 a \u2208 A},\n  Inf_le      := by tautology,\n  le_Inf      := by tautology }\n\n\n/-! ## Least Fixpoint -/\n\ndef lfp {\u03b1 : Type} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1) : \u03b1 :=\ncomplete_lattice.Inf ({a | f a \u2264 a})\n\nlemma lfp_le {\u03b1 : Type} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1)\n    (a : \u03b1) (h : f a \u2264 a) :\n  lfp f \u2264 a :=\ncomplete_lattice.Inf_le _ _ h\n\nlemma le_lfp {\u03b1 : Type} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1)\n    (a : \u03b1) (h : \u2200a', f a' \u2264 a' \u2192 a \u2264 a') :\n  a \u2264 lfp f :=\ncomplete_lattice.le_Inf _ _ h\n\n/-! **Knaster-Tarski theorem:** For any monotone function `f`:\n\n* `lfp f` is a fixpoint: `lfp f = f (lfp f)` (lemma `lfp_eq`);\n* `lfp f` is smaller than any other fixpoint: `X = f X \u2192 lfp f \u2264 X`. -/\n\nlemma lfp_eq {\u03b1 : Type} [complete_lattice \u03b1] (f : \u03b1 \u2192 \u03b1)\n    (hf : monotone f) :\n  lfp f = f (lfp f) :=\nbegin\n  have h : f (lfp f) \u2264 lfp f :=\n    begin\n      apply le_lfp,\n      intros a' ha',\n      apply @le_trans _ _ _ (f a'),\n      { apply hf,\n        apply lfp_le,\n        assumption },\n      { assumption }\n    end,\n  apply le_antisymm,\n  { apply lfp_le,\n    apply hf,\n    assumption },\n  { assumption }\nend\nend LoVe\n", "meta": {"author": "BrownCS1951x", "repo": "fpv2022", "sha": "aeaf291183721460387f8ae4c3c008836b8460e7", "save_path": "github-repos/lean/BrownCS1951x-fpv2022", "path": "github-repos/lean/BrownCS1951x-fpv2022/fpv2022-aeaf291183721460387f8ae4c3c008836b8460e7/src/homework/love06_hw_support_file.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012105, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.7010249463985364}}
{"text": "/-\nCopyright (c) 2021 Peter Nelson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Peter Nelson, Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module data.fintype.order\n! leanprover-community/mathlib commit 63f84d91dd847f50bae04a01071f3a5491934e36\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Data.Fintype.Lattice\nimport Mathbin.Data.Finset.Order\n\n/-!\n# Order structures on finite types\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file provides order instances on fintypes.\n\n## Computable instances\n\nOn a `fintype`, we can construct\n* an `order_bot` from `semilattice_inf`.\n* an `order_top` from `semilattice_sup`.\n* a `bounded_order` from `lattice`.\n\nThose are marked as `def` to avoid defeqness issues.\n\n## Completion instances\n\nThose instances are noncomputable because the definitions of `Sup` and `Inf` use `set.to_finset` and\nset membership is undecidable in general.\n\nOn a `fintype`, we can promote:\n* a `lattice` to a `complete_lattice`.\n* a `distrib_lattice` to a `complete_distrib_lattice`.\n* a `linear_order`  to a `complete_linear_order`.\n* a `boolean_algebra` to a `complete_boolean_algebra`.\n\nThose are marked as `def` to avoid typeclass loops.\n\n## Concrete instances\n\nWe provide a few instances for concrete types:\n* `fin.complete_linear_order`\n* `bool.complete_linear_order`\n* `bool.complete_boolean_algebra`\n-/\n\n\nopen Finset\n\nnamespace Fintype\n\nvariable {\u03b9 \u03b1 : Type _} [Fintype \u03b9] [Fintype \u03b1]\n\nsection Nonempty\n\nvariable (\u03b1) [Nonempty \u03b1]\n\n#print Fintype.toOrderBot /-\n-- See note [reducible non-instances]\n/-- Constructs the `\u22a5` of a finite nonempty `semilattice_inf`. -/\n@[reducible]\ndef toOrderBot [SemilatticeInf \u03b1] : OrderBot \u03b1\n    where\n  bot := univ.inf' univ_nonempty id\n  bot_le a := inf'_le _ <| mem_univ a\n#align fintype.to_order_bot Fintype.toOrderBot\n-/\n\n#print Fintype.toOrderTop /-\n-- See note [reducible non-instances]\n/-- Constructs the `\u22a4` of a finite nonempty `semilattice_sup` -/\n@[reducible]\ndef toOrderTop [SemilatticeSup \u03b1] : OrderTop \u03b1\n    where\n  top := univ.sup' univ_nonempty id\n  le_top a := le_sup' _ <| mem_univ a\n#align fintype.to_order_top Fintype.toOrderTop\n-/\n\n#print Fintype.toBoundedOrder /-\n-- See note [reducible non-instances]\n/-- Constructs the `\u22a4` and `\u22a5` of a finite nonempty `lattice`. -/\n@[reducible]\ndef toBoundedOrder [Lattice \u03b1] : BoundedOrder \u03b1 :=\n  { toOrderBot \u03b1, toOrderTop \u03b1 with }\n#align fintype.to_bounded_order Fintype.toBoundedOrder\n-/\n\nend Nonempty\n\nsection BoundedOrder\n\nvariable (\u03b1)\n\nopen Classical\n\n#print Fintype.toCompleteLattice /-\n-- See note [reducible non-instances]\n/-- A finite bounded lattice is complete. -/\n@[reducible]\nnoncomputable def toCompleteLattice [Lattice \u03b1] [BoundedOrder \u03b1] : CompleteLattice \u03b1 :=\n  { \u2039Lattice \u03b1\u203a,\n    \u2039BoundedOrder \u03b1\u203a with\n    sup\u209b := fun s => s.toFinset.sup id\n    inf\u209b := fun s => s.toFinset.inf id\n    le_sup := fun _ _ ha => Finset.le_sup (Set.mem_toFinset.mpr ha)\n    sup_le := fun s _ ha => Finset.sup_le fun b hb => ha _ <| Set.mem_toFinset.mp hb\n    inf_le := fun _ _ ha => Finset.inf_le (Set.mem_toFinset.mpr ha)\n    le_inf := fun s _ ha => Finset.le_inf fun b hb => ha _ <| Set.mem_toFinset.mp hb }\n#align fintype.to_complete_lattice Fintype.toCompleteLattice\n-/\n\n#print Fintype.toCompleteDistribLattice /-\n-- See note [reducible non-instances]\n/-- A finite bounded distributive lattice is completely distributive. -/\n@[reducible]\nnoncomputable def toCompleteDistribLattice [DistribLattice \u03b1] [BoundedOrder \u03b1] :\n    CompleteDistribLattice \u03b1 :=\n  {\n    toCompleteLattice\n      \u03b1 with\n    inf\u1d62_sup_le_sup_inf := fun a s =>\n      by\n      convert(Finset.inf_sup_distrib_left _ _ _).ge\n      convert(Finset.inf_eq_inf\u1d62 _ _).symm\n      simp_rw [Set.mem_toFinset]\n      rfl\n    inf_sup_le_sup\u1d62_inf := fun a s =>\n      by\n      convert(Finset.sup_inf_distrib_left _ _ _).le\n      convert(Finset.sup_eq_sup\u1d62 _ _).symm\n      simp_rw [Set.mem_toFinset]\n      rfl }\n#align fintype.to_complete_distrib_lattice Fintype.toCompleteDistribLattice\n-/\n\n#print Fintype.toCompleteLinearOrder /-\n-- See note [reducible non-instances]\n/-- A finite bounded linear order is complete. -/\n@[reducible]\nnoncomputable def toCompleteLinearOrder [LinearOrder \u03b1] [BoundedOrder \u03b1] : CompleteLinearOrder \u03b1 :=\n  { toCompleteLattice \u03b1, \u2039LinearOrder \u03b1\u203a with }\n#align fintype.to_complete_linear_order Fintype.toCompleteLinearOrder\n-/\n\n#print Fintype.toCompleteBooleanAlgebra /-\n-- See note [reducible non-instances]\n/-- A finite boolean algebra is complete. -/\n@[reducible]\nnoncomputable def toCompleteBooleanAlgebra [BooleanAlgebra \u03b1] : CompleteBooleanAlgebra \u03b1 :=\n  { Fintype.toCompleteDistribLattice \u03b1, \u2039BooleanAlgebra \u03b1\u203a with }\n#align fintype.to_complete_boolean_algebra Fintype.toCompleteBooleanAlgebra\n-/\n\nend BoundedOrder\n\nsection Nonempty\n\nvariable (\u03b1) [Nonempty \u03b1]\n\n#print Fintype.toCompleteLatticeOfNonempty /-\n-- See note [reducible non-instances]\n/-- A nonempty finite lattice is complete. If the lattice is already a `bounded_order`, then use\n`fintype.to_complete_lattice` instead, as this gives definitional equality for `\u22a5` and `\u22a4`. -/\n@[reducible]\nnoncomputable def toCompleteLatticeOfNonempty [Lattice \u03b1] : CompleteLattice \u03b1 :=\n  @toCompleteLattice _ _ _ <| @toBoundedOrder \u03b1 _ \u27e8Classical.arbitrary \u03b1\u27e9 _\n#align fintype.to_complete_lattice_of_nonempty Fintype.toCompleteLatticeOfNonempty\n-/\n\n#print Fintype.toCompleteLinearOrderOfNonempty /-\n-- See note [reducible non-instances]\n/-- A nonempty finite linear order is complete. If the linear order is already a `bounded_order`,\nthen use `fintype.to_complete_linear_order` instead, as this gives definitional equality for `\u22a5` and\n`\u22a4`. -/\n@[reducible]\nnoncomputable def toCompleteLinearOrderOfNonempty [LinearOrder \u03b1] : CompleteLinearOrder \u03b1 :=\n  { toCompleteLatticeOfNonempty \u03b1, \u2039LinearOrder \u03b1\u203a with }\n#align fintype.to_complete_linear_order_of_nonempty Fintype.toCompleteLinearOrderOfNonempty\n-/\n\nend Nonempty\n\nend Fintype\n\n/-! ### Concrete instances -/\n\n\nnoncomputable instance {n : \u2115} : CompleteLinearOrder (Fin (n + 1)) :=\n  Fintype.toCompleteLinearOrder _\n\nnoncomputable instance : CompleteLinearOrder Bool :=\n  Fintype.toCompleteLinearOrder _\n\nnoncomputable instance : CompleteBooleanAlgebra Bool :=\n  Fintype.toCompleteBooleanAlgebra _\n\n/-! ### Directed Orders -/\n\n\nvariable {\u03b1 : Type _}\n\n/- warning: directed.fintype_le -> Directed.fintype_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsTrans.{u1} \u03b1 r] {\u03b2 : Type.{u2}} {\u03b3 : Type.{u3}} [_inst_2 : Nonempty.{succ u3} \u03b3] {f : \u03b3 -> \u03b1} [_inst_3 : Fintype.{u2} \u03b2], (Directed.{u1, succ u3} \u03b1 \u03b3 r f) -> (forall (g : \u03b2 -> \u03b3), Exists.{succ u3} \u03b3 (fun (z : \u03b3) => forall (i : \u03b2), r (f (g i)) (f z)))\nbut is expected to have type\n  forall {\u03b1 : Type.{u3}} {r : \u03b1 -> \u03b1 -> Prop} [_inst_1 : IsTrans.{u3} \u03b1 r] {\u03b2 : Type.{u2}} {\u03b3 : Type.{u1}} [_inst_2 : Nonempty.{succ u1} \u03b3] {f : \u03b3 -> \u03b1} [_inst_3 : Fintype.{u2} \u03b2], (Directed.{u3, succ u1} \u03b1 \u03b3 r f) -> (forall (g : \u03b2 -> \u03b3), Exists.{succ u1} \u03b3 (fun (z : \u03b3) => forall (i : \u03b2), r (f (g i)) (f z)))\nCase conversion may be inaccurate. Consider using '#align directed.fintype_le Directed.fintype_le\u2093'. -/\ntheorem Directed.fintype_le {r : \u03b1 \u2192 \u03b1 \u2192 Prop} [IsTrans \u03b1 r] {\u03b2 \u03b3 : Type _} [Nonempty \u03b3] {f : \u03b3 \u2192 \u03b1}\n    [Fintype \u03b2] (D : Directed r f) (g : \u03b2 \u2192 \u03b3) : \u2203 z, \u2200 i, r (f (g i)) (f z) := by\n  classical\n    obtain \u27e8z, hz\u27e9 := D.finset_le (Finset.image g Finset.univ)\n    exact \u27e8z, fun i => hz (g i) (Finset.mem_image_of_mem g (Finset.mem_univ i))\u27e9\n#align directed.fintype_le Directed.fintype_le\n\n/- warning: fintype.exists_le -> Fintype.exists_le is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Nonempty.{succ u1} \u03b1] [_inst_2 : Preorder.{u1} \u03b1] [_inst_3 : IsDirected.{u1} \u03b1 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_2))] {\u03b2 : Type.{u2}} [_inst_4 : Fintype.{u2} \u03b2] (f : \u03b2 -> \u03b1), Exists.{succ u1} \u03b1 (fun (M : \u03b1) => forall (i : \u03b2), LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_2) (f i) M)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : Nonempty.{succ u2} \u03b1] [_inst_2 : Preorder.{u2} \u03b1] [_inst_3 : IsDirected.{u2} \u03b1 (fun (x._@.Mathlib.Data.Fintype.Order._hyg.1052 : \u03b1) (x._@.Mathlib.Data.Fintype.Order._hyg.1054 : \u03b1) => LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 _inst_2) x._@.Mathlib.Data.Fintype.Order._hyg.1052 x._@.Mathlib.Data.Fintype.Order._hyg.1054)] {\u03b2 : Type.{u1}} [_inst_4 : Fintype.{u1} \u03b2] (f : \u03b2 -> \u03b1), Exists.{succ u2} \u03b1 (fun (M : \u03b1) => forall (i : \u03b2), LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 _inst_2) (f i) M)\nCase conversion may be inaccurate. Consider using '#align fintype.exists_le Fintype.exists_le\u2093'. -/\ntheorem Fintype.exists_le [Nonempty \u03b1] [Preorder \u03b1] [IsDirected \u03b1 (\u00b7 \u2264 \u00b7)] {\u03b2 : Type _} [Fintype \u03b2]\n    (f : \u03b2 \u2192 \u03b1) : \u2203 M, \u2200 i, f i \u2264 M :=\n  directed_id.fintype_le _\n#align fintype.exists_le Fintype.exists_le\n\n/- warning: fintype.bdd_above_range -> Fintype.bddAbove_range is a dubious translation:\nlean 3 declaration is\n  forall {\u03b1 : Type.{u1}} [_inst_1 : Nonempty.{succ u1} \u03b1] [_inst_2 : Preorder.{u1} \u03b1] [_inst_3 : IsDirected.{u1} \u03b1 (LE.le.{u1} \u03b1 (Preorder.toLE.{u1} \u03b1 _inst_2))] {\u03b2 : Type.{u2}} [_inst_4 : Fintype.{u2} \u03b2] (f : \u03b2 -> \u03b1), BddAbove.{u1} \u03b1 _inst_2 (Set.range.{u1, succ u2} \u03b1 \u03b2 f)\nbut is expected to have type\n  forall {\u03b1 : Type.{u2}} [_inst_1 : Nonempty.{succ u2} \u03b1] [_inst_2 : Preorder.{u2} \u03b1] [_inst_3 : IsDirected.{u2} \u03b1 (fun (x._@.Mathlib.Data.Fintype.Order._hyg.1107 : \u03b1) (x._@.Mathlib.Data.Fintype.Order._hyg.1109 : \u03b1) => LE.le.{u2} \u03b1 (Preorder.toLE.{u2} \u03b1 _inst_2) x._@.Mathlib.Data.Fintype.Order._hyg.1107 x._@.Mathlib.Data.Fintype.Order._hyg.1109)] {\u03b2 : Type.{u1}} [_inst_4 : Fintype.{u1} \u03b2] (f : \u03b2 -> \u03b1), BddAbove.{u2} \u03b1 _inst_2 (Set.range.{u2, succ u1} \u03b1 \u03b2 f)\nCase conversion may be inaccurate. Consider using '#align fintype.bdd_above_range Fintype.bddAbove_range\u2093'. -/\ntheorem Fintype.bddAbove_range [Nonempty \u03b1] [Preorder \u03b1] [IsDirected \u03b1 (\u00b7 \u2264 \u00b7)] {\u03b2 : Type _}\n    [Fintype \u03b2] (f : \u03b2 \u2192 \u03b1) : BddAbove (Set.range f) :=\n  by\n  obtain \u27e8M, hM\u27e9 := Fintype.exists_le f\n  refine' \u27e8M, fun a ha => _\u27e9\n  obtain \u27e8b, rfl\u27e9 := ha\n  exact hM b\n#align fintype.bdd_above_range Fintype.bddAbove_range\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Data/Fintype/Order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7010249450324362}}
{"text": "/-\nCopyright (c) 2020 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker, Devon Tuma\n\n! This file was ported from Lean 3 source module analysis.special_functions.polynomials\n! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Analysis.Asymptotics.AsymptoticEquivalent\nimport Mathbin.Analysis.Asymptotics.SpecificAsymptotics\nimport Mathbin.Data.Polynomial.RingDivision\n\n/-!\n# Limits related to polynomial and rational functions\n\nThis file proves basic facts about limits of polynomial and rationals functions.\nThe main result is `eval_is_equivalent_at_top_eval_lead`, which states that for\nany polynomial `P` of degree `n` with leading coefficient `a`, the corresponding\npolynomial function is equivalent to `a * x^n` as `x` goes to +\u221e.\n\nWe can then use this result to prove various limits for polynomial and rational\nfunctions, depending on the degrees and leading coefficients of the considered\npolynomials.\n-/\n\n\nopen Filter Finset Asymptotics\n\nopen Asymptotics Polynomial Topology\n\nnamespace Polynomial\n\nvariable {\ud835\udd5c : Type _} [NormedLinearOrderedField \ud835\udd5c] (P Q : \ud835\udd5c[X])\n\ntheorem eventually_no_roots (hP : P \u2260 0) : \u2200\u1da0 x in atTop, \u00acP.IsRoot x :=\n  atTop_le_cofinite <| (finite_setOf_isRoot hP).compl_mem_cofinite\n#align polynomial.eventually_no_roots Polynomial.eventually_no_roots\n\nvariable [OrderTopology \ud835\udd5c]\n\nsection PolynomialAtTop\n\ntheorem isEquivalent_atTop_lead :\n    (fun x => eval x P) ~[atTop] fun x => P.leadingCoeff * x ^ P.natDegree :=\n  by\n  by_cases h : P = 0\n  \u00b7 simp [h]\n  \u00b7 simp only [Polynomial.eval_eq_sum_range, sum_range_succ]\n    exact\n      is_o.add_is_equivalent\n        (is_o.sum fun i hi =>\n          is_o.const_mul_left\n            ((is_o.const_mul_right fun hz => h <| leading_coeff_eq_zero.mp hz) <|\n              is_o_pow_pow_at_top_of_lt (mem_range.mp hi))\n            _)\n        is_equivalent.refl\n#align polynomial.is_equivalent_at_top_lead Polynomial.isEquivalent_atTop_lead\n\ntheorem tendsto_atTop_of_leadingCoeff_nonneg (hdeg : 0 < P.degree) (hnng : 0 \u2264 P.leadingCoeff) :\n    Tendsto (fun x => eval x P) atTop atTop :=\n  P.isEquivalent_atTop_lead.symm.tendsto_atTop <|\n    tendsto_const_mul_pow_atTop (natDegree_pos_iff_degree_pos.2 hdeg).ne' <|\n      hnng.lt_of_ne' <| leadingCoeff_ne_zero.mpr <| ne_zero_of_degree_gt hdeg\n#align polynomial.tendsto_at_top_of_leading_coeff_nonneg Polynomial.tendsto_atTop_of_leadingCoeff_nonneg\n\ntheorem tendsto_atTop_iff_leadingCoeff_nonneg :\n    Tendsto (fun x => eval x P) atTop atTop \u2194 0 < P.degree \u2227 0 \u2264 P.leadingCoeff :=\n  by\n  refine' \u27e8fun h => _, fun h => tendsto_at_top_of_leading_coeff_nonneg P h.1 h.2\u27e9\n  have : tendsto (fun x => P.leading_coeff * x ^ P.nat_degree) at_top at_top :=\n    (is_equivalent_at_top_lead P).tendsto_atTop h\n  rw [tendsto_const_mul_pow_at_top_iff, \u2190 pos_iff_ne_zero, nat_degree_pos_iff_degree_pos] at this\n  exact \u27e8this.1, this.2.le\u27e9\n#align polynomial.tendsto_at_top_iff_leading_coeff_nonneg Polynomial.tendsto_atTop_iff_leadingCoeff_nonneg\n\ntheorem tendsto_atBot_iff_leadingCoeff_nonpos :\n    Tendsto (fun x => eval x P) atTop atBot \u2194 0 < P.degree \u2227 P.leadingCoeff \u2264 0 := by\n  simp only [\u2190 tendsto_neg_at_top_iff, \u2190 eval_neg, tendsto_at_top_iff_leading_coeff_nonneg,\n    degree_neg, leading_coeff_neg, neg_nonneg]\n#align polynomial.tendsto_at_bot_iff_leading_coeff_nonpos Polynomial.tendsto_atBot_iff_leadingCoeff_nonpos\n\ntheorem tendsto_atBot_of_leadingCoeff_nonpos (hdeg : 0 < P.degree) (hnps : P.leadingCoeff \u2264 0) :\n    Tendsto (fun x => eval x P) atTop atBot :=\n  P.tendsto_atBot_iff_leadingCoeff_nonpos.2 \u27e8hdeg, hnps\u27e9\n#align polynomial.tendsto_at_bot_of_leading_coeff_nonpos Polynomial.tendsto_atBot_of_leadingCoeff_nonpos\n\ntheorem abs_tendsto_atTop (hdeg : 0 < P.degree) : Tendsto (fun x => abs <| eval x P) atTop atTop :=\n  by\n  cases' le_total 0 P.leading_coeff with hP hP\n  \u00b7 exact tendsto_abs_at_top_at_top.comp (P.tendsto_at_top_of_leading_coeff_nonneg hdeg hP)\n  \u00b7 exact tendsto_abs_at_bot_at_top.comp (P.tendsto_at_bot_of_leading_coeff_nonpos hdeg hP)\n#align polynomial.abs_tendsto_at_top Polynomial.abs_tendsto_atTop\n\ntheorem abs_isBoundedUnder_iff :\n    (IsBoundedUnder (\u00b7 \u2264 \u00b7) atTop fun x => |eval x P|) \u2194 P.degree \u2264 0 :=\n  by\n  refine'\n    \u27e8fun h => _, fun h =>\n      \u27e8|P.coeff 0|,\n        eventually_map.mpr\n          (eventually_of_forall\n            (forall_imp (fun _ => le_of_eq) fun x =>\n              congr_arg abs <| trans (congr_arg (eval x) (eq_C_of_degree_le_zero h)) eval_C))\u27e9\u27e9\n  contrapose! h\n  exact not_is_bounded_under_of_tendsto_at_top (abs_tendsto_at_top P h)\n#align polynomial.abs_is_bounded_under_iff Polynomial.abs_isBoundedUnder_iff\n\ntheorem abs_tendsto_atTop_iff : Tendsto (fun x => abs <| eval x P) atTop atTop \u2194 0 < P.degree :=\n  \u27e8fun h => not_le.mp (mt (abs_isBoundedUnder_iff P).mpr (not_isBoundedUnder_of_tendsto_atTop h)),\n    abs_tendsto_atTop P\u27e9\n#align polynomial.abs_tendsto_at_top_iff Polynomial.abs_tendsto_atTop_iff\n\ntheorem tendsto_nhds_iff {c : \ud835\udd5c} :\n    Tendsto (fun x => eval x P) atTop (\ud835\udcdd c) \u2194 P.leadingCoeff = c \u2227 P.degree \u2264 0 :=\n  by\n  refine' \u27e8fun h => _, fun h => _\u27e9\n  \u00b7 have := P.is_equivalent_at_top_lead.tendsto_nhds h\n    by_cases hP : P.leading_coeff = 0\n    \u00b7 simp only [hP, MulZeroClass.zero_mul, tendsto_const_nhds_iff] at this\n      refine' \u27e8trans hP this, by simp [leading_coeff_eq_zero.1 hP]\u27e9\n    \u00b7 rw [tendsto_const_mul_pow_nhds_iff hP, nat_degree_eq_zero_iff_degree_le_zero] at this\n      exact this.symm\n  \u00b7 refine' P.is_equivalent_at_top_lead.symm.tendsto_nhds _\n    have : P.nat_degree = 0 := nat_degree_eq_zero_iff_degree_le_zero.2 h.2\n    simp only [h.1, this, pow_zero, mul_one]\n    exact tendsto_const_nhds\n#align polynomial.tendsto_nhds_iff Polynomial.tendsto_nhds_iff\n\nend PolynomialAtTop\n\nsection PolynomialDivAtTop\n\ntheorem isEquivalent_atTop_div :\n    (fun x => eval x P / eval x Q) ~[atTop] fun x =>\n      P.leadingCoeff / Q.leadingCoeff * x ^ (P.natDegree - Q.natDegree : \u2124) :=\n  by\n  by_cases hP : P = 0\n  \u00b7 simp [hP]\n  by_cases hQ : Q = 0\n  \u00b7 simp [hQ]\n  refine'\n    (P.is_equivalent_at_top_lead.symm.div Q.is_equivalent_at_top_lead.symm).symm.trans\n      (eventually_eq.is_equivalent ((eventually_gt_at_top 0).mono fun x hx => _))\n  simp [\u2190 div_mul_div_comm, hP, hQ, zpow_sub\u2080 hx.ne.symm]\n#align polynomial.is_equivalent_at_top_div Polynomial.isEquivalent_atTop_div\n\ntheorem div_tendsto_zero_of_degree_lt (hdeg : P.degree < Q.degree) :\n    Tendsto (fun x => eval x P / eval x Q) atTop (\ud835\udcdd 0) :=\n  by\n  by_cases hP : P = 0\n  \u00b7 simp [hP, tendsto_const_nhds]\n  rw [\u2190 nat_degree_lt_nat_degree_iff hP] at hdeg\n  refine' (is_equivalent_at_top_div P Q).symm.tendsto_nhds _\n  rw [\u2190 MulZeroClass.mul_zero]\n  refine' (tendsto_zpow_atTop_zero _).const_mul _\n  linarith\n#align polynomial.div_tendsto_zero_of_degree_lt Polynomial.div_tendsto_zero_of_degree_lt\n\ntheorem div_tendsto_zero_iff_degree_lt (hQ : Q \u2260 0) :\n    Tendsto (fun x => eval x P / eval x Q) atTop (\ud835\udcdd 0) \u2194 P.degree < Q.degree :=\n  by\n  refine' \u27e8fun h => _, div_tendsto_zero_of_degree_lt P Q\u27e9\n  by_cases hPQ : P.leading_coeff / Q.leading_coeff = 0\n  \u00b7 simp only [div_eq_mul_inv, inv_eq_zero, mul_eq_zero] at hPQ\n    cases' hPQ with hP0 hQ0\n    \u00b7 rw [leading_coeff_eq_zero.1 hP0, degree_zero]\n      exact bot_lt_iff_ne_bot.2 fun hQ' => hQ (degree_eq_bot.1 hQ')\n    \u00b7 exact absurd (leading_coeff_eq_zero.1 hQ0) hQ\n  \u00b7 have := (is_equivalent_at_top_div P Q).tendsto_nhds h\n    rw [tendsto_const_mul_zpow_atTop_nhds_iff hPQ] at this\n    cases' this with h h\n    \u00b7 exact absurd h.2 hPQ\n    \u00b7 rw [sub_lt_iff_lt_add, zero_add, Int.ofNat_lt] at h\n      exact degree_lt_degree h.1\n#align polynomial.div_tendsto_zero_iff_degree_lt Polynomial.div_tendsto_zero_iff_degree_lt\n\ntheorem div_tendsto_leadingCoeff_div_of_degree_eq (hdeg : P.degree = Q.degree) :\n    Tendsto (fun x => eval x P / eval x Q) atTop (\ud835\udcdd <| P.leadingCoeff / Q.leadingCoeff) :=\n  by\n  refine' (is_equivalent_at_top_div P Q).symm.tendsto_nhds _\n  rw [show (P.nat_degree : \u2124) = Q.nat_degree by simp [hdeg, nat_degree]]\n  simp [tendsto_const_nhds]\n#align polynomial.div_tendsto_leading_coeff_div_of_degree_eq Polynomial.div_tendsto_leadingCoeff_div_of_degree_eq\n\ntheorem div_tendsto_atTop_of_degree_gt' (hdeg : Q.degree < P.degree)\n    (hpos : 0 < P.leadingCoeff / Q.leadingCoeff) :\n    Tendsto (fun x => eval x P / eval x Q) atTop atTop :=\n  by\n  have hQ : Q \u2260 0 := fun h =>\n    by\n    simp only [h, div_zero, leading_coeff_zero] at hpos\n    linarith\n  rw [\u2190 nat_degree_lt_nat_degree_iff hQ] at hdeg\n  refine' (is_equivalent_at_top_div P Q).symm.tendsto_atTop _\n  apply tendsto.const_mul_at_top hpos\n  apply tendsto_zpow_atTop_atTop\n  linarith\n#align polynomial.div_tendsto_at_top_of_degree_gt' Polynomial.div_tendsto_atTop_of_degree_gt'\n\ntheorem div_tendsto_atTop_of_degree_gt (hdeg : Q.degree < P.degree) (hQ : Q \u2260 0)\n    (hnng : 0 \u2264 P.leadingCoeff / Q.leadingCoeff) :\n    Tendsto (fun x => eval x P / eval x Q) atTop atTop :=\n  have ratio_pos : 0 < P.leadingCoeff / Q.leadingCoeff :=\n    lt_of_le_of_ne hnng\n      (div_ne_zero (fun h => ne_zero_of_degree_gt hdeg <| leadingCoeff_eq_zero.mp h) fun h =>\n          hQ <| leadingCoeff_eq_zero.mp h).symm\n  div_tendsto_atTop_of_degree_gt' P Q hdeg ratio_pos\n#align polynomial.div_tendsto_at_top_of_degree_gt Polynomial.div_tendsto_atTop_of_degree_gt\n\ntheorem div_tendsto_atBot_of_degree_gt' (hdeg : Q.degree < P.degree)\n    (hneg : P.leadingCoeff / Q.leadingCoeff < 0) :\n    Tendsto (fun x => eval x P / eval x Q) atTop atBot :=\n  by\n  have hQ : Q \u2260 0 := fun h =>\n    by\n    simp only [h, div_zero, leading_coeff_zero] at hneg\n    linarith\n  rw [\u2190 nat_degree_lt_nat_degree_iff hQ] at hdeg\n  refine' (is_equivalent_at_top_div P Q).symm.tendsto_atBot _\n  apply tendsto.neg_const_mul_at_top hneg\n  apply tendsto_zpow_atTop_atTop\n  linarith\n#align polynomial.div_tendsto_at_bot_of_degree_gt' Polynomial.div_tendsto_atBot_of_degree_gt'\n\ntheorem div_tendsto_atBot_of_degree_gt (hdeg : Q.degree < P.degree) (hQ : Q \u2260 0)\n    (hnps : P.leadingCoeff / Q.leadingCoeff \u2264 0) :\n    Tendsto (fun x => eval x P / eval x Q) atTop atBot :=\n  have ratio_neg : P.leadingCoeff / Q.leadingCoeff < 0 :=\n    lt_of_le_of_ne hnps\n      (div_ne_zero (fun h => ne_zero_of_degree_gt hdeg <| leadingCoeff_eq_zero.mp h) fun h =>\n        hQ <| leadingCoeff_eq_zero.mp h)\n  div_tendsto_atBot_of_degree_gt' P Q hdeg ratio_neg\n#align polynomial.div_tendsto_at_bot_of_degree_gt Polynomial.div_tendsto_atBot_of_degree_gt\n\ntheorem abs_div_tendsto_atTop_of_degree_gt (hdeg : Q.degree < P.degree) (hQ : Q \u2260 0) :\n    Tendsto (fun x => |eval x P / eval x Q|) atTop atTop :=\n  by\n  by_cases h : 0 \u2264 P.leading_coeff / Q.leading_coeff\n  \u00b7 exact tendsto_abs_at_top_at_top.comp (P.div_tendsto_at_top_of_degree_gt Q hdeg hQ h)\n  \u00b7 push_neg  at h\n    exact tendsto_abs_at_bot_at_top.comp (P.div_tendsto_at_bot_of_degree_gt Q hdeg hQ h.le)\n#align polynomial.abs_div_tendsto_at_top_of_degree_gt Polynomial.abs_div_tendsto_atTop_of_degree_gt\n\nend PolynomialDivAtTop\n\ntheorem isO_of_degree_le (h : P.degree \u2264 Q.degree) :\n    (fun x => eval x P) =O[atTop] fun x => eval x Q :=\n  by\n  by_cases hp : P = 0\n  \u00b7 simpa [hp] using is_O_zero (fun x => eval x Q) at_top\n  \u00b7 have hq : Q \u2260 0 := ne_zero_of_degree_ge_degree h hp\n    have hPQ : \u2200\u1da0 x : \ud835\udd5c in at_top, eval x Q = 0 \u2192 eval x P = 0 :=\n      Filter.mem_of_superset (Polynomial.eventually_no_roots Q hq) fun x h h' => absurd h' h\n    cases' le_iff_lt_or_eq.mp h with h h\n    \u00b7 exact is_O_of_div_tendsto_nhds hPQ 0 (div_tendsto_zero_of_degree_lt P Q h)\n    \u00b7 exact is_O_of_div_tendsto_nhds hPQ _ (div_tendsto_leading_coeff_div_of_degree_eq P Q h)\n#align polynomial.is_O_of_degree_le Polynomial.isO_of_degree_le\n\nend Polynomial\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Analysis/SpecialFunctions/Polynomials.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7010249414120692}}
{"text": "\n\naxiom P : Prop\naxiom Q : Prop\naxiom R : Prop\n\n\n-->> def true_intro : pExp := pTrue\n#check true       -- a type\n#check true.intro -- a constructor (value)\n#print true\n\n-- true is a proposition \n-- in Lean represented as a type\n-- intro is defined to be a proof of it (a value)\n-- because there is proof, we judge the proposition to be true\n-- a proof is necessary and sufficient *evidence* of truth\n\n-- *** FALSE ***\n\n-- false\n#check false\n#print false\n-- there is no proof of the proposition false\n-- this is by definition of false as a type with no values\n-- so we judge the proposition, false, to be false (untrue)\n\n-->> def false_elim := pFalse >> P\n#check @false.elim\n\n\n-- def true_imp := pTrue >> P\n-- oops, this is not a valid law\n\ndef true_imp : \u2200 (P : Prop), true \u2192 P :=\n\u03bb P t, _\n\n-- *** AND ***\n\n#check and\n#print and\n\n-->> def and_intro := P >> Q >> P \u2227 Q\n#check @and.intro -- constructor\n\n-->> def and_elim_left := P \u2227 Q >> P\n#check @and.elim_left\n#print and.elim_left\n\n\n-->> def and_elim_right := P \u2227 Q >> Q\n#check @and.elim_right\n#print and.elim_right\n\n-- *** OR ***\n\n-->> def or_intro_left := P >> P \u2228 Q\n#check @or.intro_left\n\n-->> def or_intro_right := Q >> P \u2228 Q\n#check @or.intro_right\n\n-->> def or_elim := P \u2228 Q >> (P >> R) >> (Q >> R) >> R\n#check @or.elim\n\n-- *** IFF ***\n\n#check iff\n#print iff\n\n-- def iff_intro := (P >> Q) >> (Q >> P) >> (P \u2194 Q)\n#check @iff.intro\n\n-- def iff_elim_left := (P \u2194 Q) >> (P >> Q)\n#check @iff.elim_left\n#check @iff.mp\n\n-- def iff_elim_right := (P \u2194 Q) >> (Q >> P)\n#check @iff.elim_right\n#check @iff.mpr\n\n-- *** ARROW ***\n\n-- introduction rule:\n-- if you show that given any (p : P) you can derive\n-- a value (q : Q), then you've proven P \u2192 Q. To prove\n-- P \u2192 Q, define any function of this type. The totality\n-- of functions in Lean is essential here: to the \"any\".\n  \n-- def arrow_elim := (P >> Q) >> P >> Q\n-- if you're given a function of type P \u2192 Q and \n-- any value of type P, you can derive one of type Q\n\naxiom p : P\naxiom pf : P \u2192 Q\n#check (pf p)\n\n-- *** RESOLUTION ***\n--def resolution := (P \u2228 Q) >> (\u00ac Q \u2228 R) >> (P \u2228 R)\n--def unit_resolution := (P \u2228 Q) >> \u00ac Q >> P\n\n-- The resolution rules are used in some automated\n-- theorem provers. We won't study them in this class\n-- That said, they are clearly valid reasoning rules.\n\n-- *** NEGATION\n\n-- def neg_intro := (P >> pFalse) >> (\u00ac P)\n#print not\n\n-- def neg_elim := (\u00ac\u00acP) >> P -- \"proof by contradiction\"\n\n#check classical.em\n\n\n-- *** THEOREMS ***\n\n-- def syllogism := (P >> Q) >> (Q >> R) >> (P >> R)\ndef syllogism : \u2200 {P Q R : Prop}, (P \u2192 Q) \u2192 (Q \u2192 R) \u2192 (P \u2192 R) :=\n  \u03bb (P Q R : Prop) (pq : P \u2192 Q) (qr : Q \u2192 R), \n    qr \u2218 pq\n\n--def modus_tollens := (P >> Q) >> (\u00ac Q >> \u00ac P)\ntheorem modus_tollens : \u2200 {P Q : Prop}, (P \u2192 Q) \u2192 \u00ac Q \u2192 \u00ac P :=\n\u03bb P Q pq nq, syllogism pq nq\n\n-- *** AXIOMS ***\n\n-- def excluded_middle := P \u2228 (\u00ac P)\n#check classical.em\n\n\n-- *** NON-THEOREMS (FALSEHOODS) ***\n--def affirm_consequence := (P >> Q) >> (Q >> P)\n\ntheorem affirm_consequence : \u2200 {P Q : Prop}, (P \u2192 Q) \u2192 Q \u2192 P :=\n\u03bb P Q pq q, _                             -- sTuCK!\n\n--def affirm_disjunct := (P \u2228 Q) >> (P >> \u00ac Q)\ntheorem  affirm_disjunct : \u2200 {P Q : Prop }, (P \u2228 Q) \u2192 P \u2192 \u00ac Q :=\n\u03bb (P Q : Prop) (pq : P \u2228 Q) (p : P), _    -- sTuCK!\n\n--def deny_antecedent := (P >> Q) >> (\u00ac P >> \u00ac Q)\ntheorem deny_antecedent : \u2200 {P Q : Prop }, (P \u2192 Q) \u2192 (\u00acP \u2192 \u00acQ) :=\n\u03bb P Q pq np, _  ", "meta": {"author": "jngo13", "repo": "Discrete-Mathematics", "sha": "bf674a866e61f60e6e6d128df85fa73819091787", "save_path": "github-repos/lean/jngo13-Discrete-Mathematics", "path": "github-repos/lean/jngo13-Discrete-Mathematics/Discrete-Mathematics-bf674a866e61f60e6e6d128df85fa73819091787/exam_2/predicate_logic/rules_of_reasoning.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088055075428, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7008697263367414}}
{"text": "section\nvariables (P Q : Prop)\n\ntheorem my_theorem : P \u2227 Q \u2192 Q \u2227 P :=\nassume h : P \u2227 Q,\nhave P, from and.left h,\nhave Q, from and.right h,\nshow Q \u2227 P, from and.intro \u2039Q\u203a \u2039P\u203a\n\nend\n", "meta": {"author": "marcofavorito", "repo": "leanings", "sha": "581b83be66ff4f8dd946fb6a1bb045d2ddf91076", "save_path": "github-repos/lean/marcofavorito-leanings", "path": "github-repos/lean/marcofavorito-leanings/leanings-581b83be66ff4f8dd946fb6a1bb045d2ddf91076/logic_and_proof/src/01-02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.7008697108645174}}
{"text": "/-\naluno:\n - Lucas Emanuel Resck Domingues\n -/\n\nopen set\n\n\n-- ex 1\n\nsection\n    variable U : Type\n    variables A B C : set U\n\n    example : \u2200 x, x \u2208 A \u2229 C \u2192 x \u2208 A \u222a B :=\n        assume x,\n        show x \u2208 A \u2229 C \u2192 x \u2208 A \u222a B, from\n            assume h1 : x \u2208 A \u2229 C,\n            show x \u2208 A \u222a B, from or.inl h1.left\n\n    example : \u2200 x, x \u2208 -(A \u222a B) \u2192 x \u2208 -A :=\n        assume x,\n        show x \u2208 -(A \u222a B) \u2192 x \u2208 -A, from\n            assume h1 : x \u2208 -(A \u222a B),\n            show x \u2208 -A, from\n                assume h2 : x \u2208 A,\n                show false, from h1 $ or.inl h2\nend\n\n\n-- ex 2\n\nsection\n    variable {U : Type}\n\n    /- defining \"disjoint\" -/\n\n    def disj (A B : set U) : Prop := \u2200 \u2983x\u2984, x \u2208 A \u2192 x \u2208 B \u2192 false\n\n    example (A B : set U) (h : \u2200 x, \u00ac (x \u2208 A \u2227 x \u2208 B)) :\n    disj A B :=\n        assume x,\n            assume h1 : x \u2208 A,\n                assume h2 : x \u2208 B,\n                have h3 : x \u2208 A \u2227 x \u2208 B, from and.intro h1 h2,\n                show false, from h x h3\n\n    -- notice that we do not have to mention x when applying\n    --   h : disj A B\n    example (A B : set U) (h1 : disj A B) (x : U)\n        (h2 : x \u2208 A) (h3 : x \u2208 B) :\n    false :=\n        h1 h2 h3\n\n    -- the same is true of \u2286\n    example (A B : set U) (x : U) (h : A \u2286 B) (h1 : x \u2208 A) :\n    x \u2208 B :=\n        h h1\n\n    example (A B C D : set U) (h1 : disj A B) (h2 : C \u2286 A)\n        (h3 : D \u2286 B) :\n    disj C D :=\n        assume x,\n        show x \u2208 C \u2192 x \u2208 D \u2192 false, from\n            assume h4 : x \u2208 C,\n            show x \u2208 D \u2192 false, from\n                assume h5 : x \u2208 D,\n                show false, from h1 (h2 h4) (h3 h5)\nend\n\n\n-- ex 3\n\nsection\n    variables {I U : Type}\n    variables {A B : I \u2192 set U}\n\n    def Union (A : I \u2192 set U) : set U := { x | \u2203 i : I, x \u2208 A i }\n    def Inter (A : I \u2192 set U) : set U := { x | \u2200 i : I, x \u2208 A i }\n\n    notation `\u22c3` binders `, ` r:(scoped f, Union f) := r\n    notation `\u22c2` binders `, ` r:(scoped f, Inter f) := r\n\n    theorem Inter.intro {x : U} (h : \u2200 i, x \u2208 A i) : x \u2208 \u22c2 i, A i :=\n    by simp; assumption\n\n    @[elab_simple]\n    theorem Inter.elim {x : U} (h : x \u2208 \u22c2 i, A i) (i : I) : x \u2208 A i :=\n    by simp at h; apply h\n\n    theorem Union.intro {x : U} (i : I) (h : x \u2208 A i) : x \u2208 \u22c3 i, A i :=\n    by {simp, existsi i, exact h}\n\n    theorem Union.elim {b : Prop} {x : U}\n    (h\u2081 : x \u2208 \u22c3 i, A i) (h\u2082 : \u2200 (i : I), x \u2208 A i \u2192 b) : b :=\n    by {simp at h\u2081, cases h\u2081 with i h, exact h\u2082 i h}\nend\n\nsection\n    variables {I U : Type}\n\n    variables (A : I \u2192 set U) (B : I \u2192 set U) (C : set U)\n\n    example : (\u22c2 i, A i) \u2229 (\u22c2 i, B i) \u2286 (\u22c2 i, A i \u2229 B i) :=\n        assume x,\n        show x \u2208 (\u22c2 i, A i) \u2229 (\u22c2 i, B i) \u2192 x \u2208 (\u22c2 i, A i \u2229 B i), from\n            assume h1 : x \u2208 (\u22c2 i, A i) \u2229 (\u22c2 i, B i),\n            have h2 : x \u2208 (\u22c2 i, A i), from h1.left,\n            have h3 : x \u2208 (\u22c2 i, B i), from h1.right,\n            show x \u2208 (\u22c2 i, A i \u2229 B i), from Inter.intro $\n                assume i,\n                have h4 : x \u2208 A i, from Inter.elim h2 i,\n                have h5 : x \u2208 B i, from Inter.elim h3 i,\n                show x \u2208 A i \u2229 B i, from and.intro h4 h5\n\n    example : C \u2229 (\u22c3i, A i) \u2286 \u22c3i, C \u2229 A i :=\n        assume x,\n        show x \u2208 C \u2229 (\u22c3i, A i) \u2192 x \u2208 \u22c3i, C \u2229 A i, from\n            assume h1 : x \u2208 C \u2229 (\u22c3i, A i),\n            have h2 : x \u2208 \u22c3i, A i, from h1.right,\n            have h5 : x \u2208 C, from h1.left,\n            show x \u2208 \u22c3i, C \u2229 A i, from Union.elim h2 $\n                assume i,\n                show x \u2208 A i \u2192  x \u2208 \u22c3j, C \u2229 A j, from\n                    assume h3 : x \u2208 A i,\n                    have h4 : x \u2208 C \u2229 A i, from and.intro h5 h3,  \n                    show x \u2208 \u22c3j, C \u2229 A j, from Union.intro i h4\nend\n\n\n-- ex 4\n\nsection \n    variable  {U : Type}\n    variables A B C : set U\n    universes u v w x\n\n    theorem subset.refl (A : set U) : A \u2286 A :=\n        assume x,\n        show x \u2208 A \u2192 x \u2208 A, from\n            assume h : x \u2208 A,\n            show x \u2208 A, from h\n\n    theorem subset.trans {A B C : set U} (h1 : A \u2286 B) (h2 : B \u2286 C) : A \u2286 C :=\n        assume x,\n        show x \u2208 A \u2192 x \u2208 C, from\n            assume h3 : x \u2208 A,\n            have h4 : x \u2208 B, from h1 h3,\n            show x \u2208 C, from h2 h4\n\n    -- For this exercise these two facts are useful\n    example (h1 : A \u2286 B) (h2 : B \u2286 C) : A \u2286 C :=\n    subset.trans h1 h2\n\n    example : A \u2286 A :=\n    subset.refl A\n\n    example (h : A \u2286 B) : powerset A \u2286 powerset B :=\n        assume X : set U,\n        show X \u2208 powerset A \u2192 X \u2208 powerset B, from\n            assume h1 : X \u2208 powerset A,\n            have h2 : X \u2286 A, from h1,\n            have h3 : X \u2286 B, from subset.trans h2 h,\n            show X \u2208 powerset B, from h3\n\n    example (h : powerset A \u2286 powerset B) : A \u2286 B :=\n        assume x,\n        show x \u2208 A \u2192 x \u2208 B, from\n            assume h1 : x \u2208 A,\n            have h2 : \u2200 X, X \u2286 A \u2192 X \u2286 B, from h,\n            have h3 : A \u2286 A, from subset.refl A,\n            have h4 : A \u2286 B, from h2 A h3,\n            show x \u2208 B, from h4 h1\nend\n\n", "meta": {"author": "lucasresck", "repo": "Discrete-Mathematics", "sha": "0a08081c5f393e5765259d3f1253c3a6dd043dac", "save_path": "github-repos/lean/lucasresck-Discrete-Mathematics", "path": "github-repos/lean/lucasresck-Discrete-Mathematics/Discrete-Mathematics-0a08081c5f393e5765259d3f1253c3a6dd043dac/Lists of exercises/List 5/cap12-Domingues.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.859663754105328, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7008258280536191}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n\n! This file was ported from Lean 3 source module algebra.covariant_and_contravariant\n! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Group.Defs\nimport Mathbin.Order.Basic\nimport Mathbin.Order.Monotone.Basic\n\n/-!\n\n# Covariants and contravariants\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file contains general lemmas and instances to work with the interactions between a relation and\nan action on a Type.\n\nThe intended application is the splitting of the ordering from the algebraic assumptions on the\noperations in the `ordered_[...]` hierarchy.\n\nThe strategy is to introduce two more flexible typeclasses, `covariant_class` and\n`contravariant_class`:\n\n* `covariant_class` models the implication `a \u2264 b \u2192 c * a \u2264 c * b` (multiplication is monotone),\n* `contravariant_class` models the implication `a * b < a * c \u2192 b < c`.\n\nSince `co(ntra)variant_class` takes as input the operation (typically `(+)` or `(*)`) and the order\nrelation (typically `(\u2264)` or `(<)`), these are the only two typeclasses that I have used.\n\nThe general approach is to formulate the lemma that you are interested in and prove it, with the\n`ordered_[...]` typeclass of your liking.  After that, you convert the single typeclass,\nsay `[ordered_cancel_monoid M]`, into three typeclasses, e.g.\n`[left_cancel_semigroup M] [partial_order M] [covariant_class M M (function.swap (*)) (\u2264)]`\nand have a go at seeing if the proof still works!\n\nNote that it is possible to combine several co(ntra)variant_class assumptions together.\nIndeed, the usual ordered typeclasses arise from assuming the pair\n`[covariant_class M M (*) (\u2264)] [contravariant_class M M (*) (<)]`\non top of order/algebraic assumptions.\n\nA formal remark is that normally `covariant_class` uses the `(\u2264)`-relation, while\n`contravariant_class` uses the `(<)`-relation. This need not be the case in general, but seems to be\nthe most common usage. In the opposite direction, the implication\n```lean\n[semigroup \u03b1] [partial_order \u03b1] [contravariant_class \u03b1 \u03b1 (*) (\u2264)] => left_cancel_semigroup \u03b1\n```\nholds -- note the `co*ntra*` assumption on the `(\u2264)`-relation.\n\n# Formalization notes\n\nWe stick to the convention of using `function.swap (*)` (or `function.swap (+)`), for the\ntypeclass assumptions, since `function.swap` is slightly better behaved than `flip`.\nHowever, sometimes as a **non-typeclass** assumption, we prefer `flip (*)` (or `flip (+)`),\nas it is easier to use. -/\n\n\n-- TODO: convert `has_exists_mul_of_le`, `has_exists_add_of_le`?\n-- TODO: relationship with `con/add_con`\n-- TODO: include equivalence of `left_cancel_semigroup` with\n-- `semigroup partial_order contravariant_class \u03b1 \u03b1 (*) (\u2264)`?\n-- TODO : use \u21d2, as per Eric's suggestion?  See\n-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff/near/236148738\n-- for a discussion.\nopen Function\n\nsection Variants\n\nvariable {M N : Type _} (\u03bc : M \u2192 N \u2192 N) (r : N \u2192 N \u2192 Prop)\n\nvariable (M N)\n\n#print Covariant /-\n/-- `covariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `covariant_class` doc-string for its meaning. -/\ndef Covariant : Prop :=\n  \u2200 (m) {n\u2081 n\u2082}, r n\u2081 n\u2082 \u2192 r (\u03bc m n\u2081) (\u03bc m n\u2082)\n#align covariant Covariant\n-/\n\n#print Contravariant /-\n/-- `contravariant` is useful to formulate succintly statements about the interactions between an\naction of a Type on another one and a relation on the acted-upon Type.\n\nSee the `contravariant_class` doc-string for its meaning. -/\ndef Contravariant : Prop :=\n  \u2200 (m) {n\u2081 n\u2082}, r (\u03bc m n\u2081) (\u03bc m n\u2082) \u2192 r n\u2081 n\u2082\n#align contravariant Contravariant\n-/\n\n#print CovariantClass /-\n/-- Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`covariant_class` says that \"the action `\u03bc` preserves the relation `r`.\"\n\nMore precisely, the `covariant_class` is a class taking two Types `M N`, together with an \"action\"\n`\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the assertion that\nfor all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the pair\n`(n\u2081, n\u2082)`, then, the relation `r` also holds for the pair `(\u03bc m n\u2081, \u03bc m n\u2082)`,\nobtained from `(n\u2081, n\u2082)` by acting upon it by `m`.\n\nIf `m : M` and `h : r n\u2081 n\u2082`, then `covariant_class.elim m h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`.\n-/\n@[protect_proj]\nclass CovariantClass : Prop where\n  elim : Covariant M N \u03bc r\n#align covariant_class CovariantClass\n-/\n\n#print ContravariantClass /-\n/-- Given an action `\u03bc` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the\n`contravariant_class` says that \"if the result of the action `\u03bc` on a pair satisfies the\nrelation `r`, then the initial pair satisfied the relation `r`.\"\n\nMore precisely, the `contravariant_class` is a class taking two Types `M N`, together with an\n\"action\" `\u03bc : M \u2192 N \u2192 N` and a relation `r : N \u2192 N \u2192 Prop`.  Its unique field `elim` is the\nassertion that for all `m \u2208 M` and all elements `n\u2081, n\u2082 \u2208 N`, if the relation `r` holds for the\npair `(\u03bc m n\u2081, \u03bc m n\u2082)` obtained from `(n\u2081, n\u2082)` by acting upon it by `m`, then, the relation\n`r` also holds for the pair `(n\u2081, n\u2082)`.\n\nIf `m : M` and `h : r (\u03bc m n\u2081) (\u03bc m n\u2082)`, then `contravariant_class.elim m h : r n\u2081 n\u2082`.\n-/\n@[protect_proj]\nclass ContravariantClass : Prop where\n  elim : Contravariant M N \u03bc r\n#align contravariant_class ContravariantClass\n-/\n\n/- warning: rel_iff_cov -> rel_iff_cov is a dubious translation:\nlean 3 declaration is\n  forall (M : Type.{u1}) (N : Type.{u2}) (\u03bc : M -> N -> N) (r : N -> N -> Prop) [_inst_1 : CovariantClass.{u1, u2} M N \u03bc r] [_inst_2 : ContravariantClass.{u1, u2} M N \u03bc r] (m : M) {a : N} {b : N}, Iff (r (\u03bc m a) (\u03bc m b)) (r a b)\nbut is expected to have type\n  forall (M : Type.{u2}) (N : Type.{u1}) (\u03bc : M -> N -> N) (r : N -> N -> Prop) [_inst_1 : CovariantClass.{u2, u1} M N \u03bc r] [_inst_2 : ContravariantClass.{u2, u1} M N \u03bc r] (m : M) {a : N} {b : N}, Iff (r (\u03bc m a) (\u03bc m b)) (r a b)\nCase conversion may be inaccurate. Consider using '#align rel_iff_cov rel_iff_cov\u2093'. -/\ntheorem rel_iff_cov [CovariantClass M N \u03bc r] [ContravariantClass M N \u03bc r] (m : M) {a b : N} :\n    r (\u03bc m a) (\u03bc m b) \u2194 r a b :=\n  \u27e8ContravariantClass.elim _, CovariantClass.elim _\u27e9\n#align rel_iff_cov rel_iff_cov\n\nsection flip\n\nvariable {M N \u03bc r}\n\n/- warning: covariant.flip -> Covariant.flip is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03bc : M -> N -> N} {r : N -> N -> Prop}, (Covariant.{u1, u2} M N \u03bc r) -> (Covariant.{u1, u2} M N \u03bc (flip.{succ u2, succ u2, 1} N N Prop r))\nbut is expected to have type\n  forall {M : Type.{u2}} {N : Type.{u1}} {\u03bc : M -> N -> N} {r : N -> N -> Prop}, (Covariant.{u2, u1} M N \u03bc r) -> (Covariant.{u2, u1} M N \u03bc (flip.{succ u1, succ u1, 1} N N Prop r))\nCase conversion may be inaccurate. Consider using '#align covariant.flip Covariant.flip\u2093'. -/\ntheorem Covariant.flip (h : Covariant M N \u03bc r) : Covariant M N \u03bc (flip r) := fun a b c hbc =>\n  h a hbc\n#align covariant.flip Covariant.flip\n\n/- warning: contravariant.flip -> Contravariant.flip is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03bc : M -> N -> N} {r : N -> N -> Prop}, (Contravariant.{u1, u2} M N \u03bc r) -> (Contravariant.{u1, u2} M N \u03bc (flip.{succ u2, succ u2, 1} N N Prop r))\nbut is expected to have type\n  forall {M : Type.{u2}} {N : Type.{u1}} {\u03bc : M -> N -> N} {r : N -> N -> Prop}, (Contravariant.{u2, u1} M N \u03bc r) -> (Contravariant.{u2, u1} M N \u03bc (flip.{succ u1, succ u1, 1} N N Prop r))\nCase conversion may be inaccurate. Consider using '#align contravariant.flip Contravariant.flip\u2093'. -/\ntheorem Contravariant.flip (h : Contravariant M N \u03bc r) : Contravariant M N \u03bc (flip r) :=\n  fun a b c hbc => h a hbc\n#align contravariant.flip Contravariant.flip\n\nend flip\n\nsection Covariant\n\nvariable {M N \u03bc r} [CovariantClass M N \u03bc r]\n\n#print act_rel_act_of_rel /-\ntheorem act_rel_act_of_rel (m : M) {a b : N} (ab : r a b) : r (\u03bc m a) (\u03bc m b) :=\n  CovariantClass.elim _ ab\n#align act_rel_act_of_rel act_rel_act_of_rel\n-/\n\n/- warning: group.covariant_iff_contravariant -> Group.covariant_iff_contravariant is a dubious translation:\nlean 3 declaration is\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N], Iff (Covariant.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2)))))) r) (Contravariant.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2)))))) r)\nbut is expected to have type\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N], Iff (Covariant.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.425 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.427 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.425 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.427) r) (Contravariant.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.444 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.446 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.444 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.446) r)\nCase conversion may be inaccurate. Consider using '#align group.covariant_iff_contravariant Group.covariant_iff_contravariant\u2093'. -/\n@[to_additive]\ntheorem Group.covariant_iff_contravariant [Group N] :\n    Covariant N N (\u00b7 * \u00b7) r \u2194 Contravariant N N (\u00b7 * \u00b7) r :=\n  by\n  refine' \u27e8fun h a b c bc => _, fun h a b c bc => _\u27e9\n  \u00b7 rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c]\n    exact h a\u207b\u00b9 bc\n  \u00b7 rw [\u2190 inv_mul_cancel_left a b, \u2190 inv_mul_cancel_left a c] at bc\n    exact h a\u207b\u00b9 bc\n#align group.covariant_iff_contravariant Group.covariant_iff_contravariant\n#align add_group.covariant_iff_contravariant AddGroup.covariant_iff_contravariant\n\n/- warning: group.covconv -> Group.covconv is a dubious translation:\nlean 3 declaration is\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2)))))) r], ContravariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2)))))) r\nbut is expected to have type\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.600 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.602 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.600 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.602) r], ContravariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.619 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.621 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.619 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.621) r\nCase conversion may be inaccurate. Consider using '#align group.covconv Group.covconv\u2093'. -/\n@[to_additive]\ninstance (priority := 100) Group.covconv [Group N] [CovariantClass N N (\u00b7 * \u00b7) r] :\n    ContravariantClass N N (\u00b7 * \u00b7) r :=\n  \u27e8Group.covariant_iff_contravariant.mp CovariantClass.elim\u27e9\n#align group.covconv Group.covconv\n#align add_group.covconv AddGroup.covconv\n\n/- warning: group.covariant_swap_iff_contravariant_swap -> Group.covariant_swap_iff_contravariant_swap is a dubious translation:\nlean 3 declaration is\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N], Iff (Covariant.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))))) r) (Contravariant.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))))) r)\nbut is expected to have type\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N], Iff (Covariant.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.674 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.676 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.674 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.676)) r) (Contravariant.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.696 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.698 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.696 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.698)) r)\nCase conversion may be inaccurate. Consider using '#align group.covariant_swap_iff_contravariant_swap Group.covariant_swap_iff_contravariant_swap\u2093'. -/\n@[to_additive]\ntheorem Group.covariant_swap_iff_contravariant_swap [Group N] :\n    Covariant N N (swap (\u00b7 * \u00b7)) r \u2194 Contravariant N N (swap (\u00b7 * \u00b7)) r :=\n  by\n  refine' \u27e8fun h a b c bc => _, fun h a b c bc => _\u27e9\n  \u00b7 rw [\u2190 mul_inv_cancel_right b a, \u2190 mul_inv_cancel_right c a]\n    exact h a\u207b\u00b9 bc\n  \u00b7 rw [\u2190 mul_inv_cancel_right b a, \u2190 mul_inv_cancel_right c a] at bc\n    exact h a\u207b\u00b9 bc\n#align group.covariant_swap_iff_contravariant_swap Group.covariant_swap_iff_contravariant_swap\n#align add_group.covariant_swap_iff_contravariant_swap AddGroup.covariant_swap_iff_contravariant_swap\n\n/- warning: group.covconv_swap -> Group.covconv_swap is a dubious translation:\nlean 3 declaration is\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))))) r], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toHasMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))))) r\nbut is expected to have type\n  forall {N : Type.{u1}} {r : N -> N -> Prop} [_inst_2 : Group.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.855 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.857 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.855 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.857)) r], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.877 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.879 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (MulOneClass.toMul.{u1} N (Monoid.toMulOneClass.{u1} N (DivInvMonoid.toMonoid.{u1} N (Group.toDivInvMonoid.{u1} N _inst_2))))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.877 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.879)) r\nCase conversion may be inaccurate. Consider using '#align group.covconv_swap Group.covconv_swap\u2093'. -/\n@[to_additive]\ninstance (priority := 100) Group.covconv_swap [Group N] [CovariantClass N N (swap (\u00b7 * \u00b7)) r] :\n    ContravariantClass N N (swap (\u00b7 * \u00b7)) r :=\n  \u27e8Group.covariant_swap_iff_contravariant_swap.mp CovariantClass.elim\u27e9\n#align group.covconv_swap Group.covconv_swap\n#align add_group.covconv_swap AddGroup.covconv_swap\n\nsection IsTrans\n\nvariable [IsTrans N r] (m n : M) {a b c d : N}\n\n#print act_rel_of_rel_of_act_rel /-\n--  Lemmas with 3 elements.\ntheorem act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (\u03bc m b) c) : r (\u03bc m a) c :=\n  trans (act_rel_act_of_rel m ab) rl\n#align act_rel_of_rel_of_act_rel act_rel_of_rel_of_act_rel\n-/\n\n#print rel_act_of_rel_of_rel_act /-\ntheorem rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (\u03bc m a)) : r c (\u03bc m b) :=\n  trans rr (act_rel_act_of_rel _ ab)\n#align rel_act_of_rel_of_rel_act rel_act_of_rel_of_rel_act\n-/\n\nend IsTrans\n\nend Covariant\n\n--  Lemma with 4 elements.\nsection MEqN\n\nvariable {M N \u03bc r} {mu : N \u2192 N \u2192 N} [IsTrans N r] [CovariantClass N N mu r]\n  [CovariantClass N N (swap mu) r] {a b c d : N}\n\n#print act_rel_act_of_rel_of_rel /-\ntheorem act_rel_act_of_rel_of_rel (ab : r a b) (cd : r c d) : r (mu a c) (mu b d) :=\n  trans (act_rel_act_of_rel c ab : _) (act_rel_act_of_rel b cd)\n#align act_rel_act_of_rel_of_rel act_rel_act_of_rel_of_rel\n-/\n\nend MEqN\n\nsection Contravariant\n\nvariable {M N \u03bc r} [ContravariantClass M N \u03bc r]\n\n#print rel_of_act_rel_act /-\ntheorem rel_of_act_rel_act (m : M) {a b : N} (ab : r (\u03bc m a) (\u03bc m b)) : r a b :=\n  ContravariantClass.elim _ ab\n#align rel_of_act_rel_act rel_of_act_rel_act\n-/\n\nsection IsTrans\n\nvariable [IsTrans N r] (m n : M) {a b c d : N}\n\n#print act_rel_of_act_rel_of_rel_act_rel /-\n--  Lemmas with 3 elements.\ntheorem act_rel_of_act_rel_of_rel_act_rel (ab : r (\u03bc m a) b) (rl : r (\u03bc m b) (\u03bc m c)) :\n    r (\u03bc m a) c :=\n  trans ab (rel_of_act_rel_act m rl)\n#align act_rel_of_act_rel_of_rel_act_rel act_rel_of_act_rel_of_rel_act_rel\n-/\n\n#print rel_act_of_act_rel_act_of_rel_act /-\ntheorem rel_act_of_act_rel_act_of_rel_act (ab : r (\u03bc m a) (\u03bc m b)) (rr : r b (\u03bc m c)) :\n    r a (\u03bc m c) :=\n  trans (rel_of_act_rel_act m ab) rr\n#align rel_act_of_act_rel_act_of_rel_act rel_act_of_act_rel_act_of_rel_act\n-/\n\nend IsTrans\n\nend Contravariant\n\nsection Monotone\n\nvariable {\u03b1 : Type _} {M N \u03bc} [Preorder \u03b1] [Preorder N]\n\nvariable {f : N \u2192 \u03b1}\n\n/- warning: covariant.monotone_of_const -> Covariant.monotone_of_const is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03bc : M -> N -> N} [_inst_2 : Preorder.{u2} N] [_inst_3 : CovariantClass.{u1, u2} M N \u03bc (LE.le.{u2} N (Preorder.toLE.{u2} N _inst_2))] (m : M), Monotone.{u2, u2} N N _inst_2 _inst_2 (\u03bc m)\nbut is expected to have type\n  forall {M : Type.{u2}} {N : Type.{u1}} {\u03bc : M -> N -> N} [_inst_2 : Preorder.{u1} N] [_inst_3 : CovariantClass.{u2, u1} M N \u03bc (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1485 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1487 : N) => LE.le.{u1} N (Preorder.toLE.{u1} N _inst_2) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1485 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1487)] (m : M), Monotone.{u1, u1} N N _inst_2 _inst_2 (\u03bc m)\nCase conversion may be inaccurate. Consider using '#align covariant.monotone_of_const Covariant.monotone_of_const\u2093'. -/\n/-- The partial application of a constant to a covariant operator is monotone. -/\ntheorem Covariant.monotone_of_const [CovariantClass M N \u03bc (\u00b7 \u2264 \u00b7)] (m : M) : Monotone (\u03bc m) :=\n  fun a b ha => CovariantClass.elim m ha\n#align covariant.monotone_of_const Covariant.monotone_of_const\n\n/- warning: monotone.covariant_of_const -> Monotone.covariant_of_const is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03bc : M -> N -> N} {\u03b1 : Type.{u3}} [_inst_1 : Preorder.{u3} \u03b1] [_inst_2 : Preorder.{u2} N] {f : N -> \u03b1} [_inst_3 : CovariantClass.{u1, u2} M N \u03bc (LE.le.{u2} N (Preorder.toLE.{u2} N _inst_2))], (Monotone.{u2, u3} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : M), Monotone.{u2, u3} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc m n)))\nbut is expected to have type\n  forall {M : Type.{u3}} {N : Type.{u2}} {\u03bc : M -> N -> N} {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} N] {f : N -> \u03b1} [_inst_3 : CovariantClass.{u3, u2} M N \u03bc (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1549 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1551 : N) => LE.le.{u2} N (Preorder.toLE.{u2} N _inst_2) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1549 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1551)], (Monotone.{u2, u1} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : M), Monotone.{u2, u1} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc m n)))\nCase conversion may be inaccurate. Consider using '#align monotone.covariant_of_const Monotone.covariant_of_const\u2093'. -/\n/-- A monotone function remains monotone when composed with the partial application\nof a covariant operator. E.g., `\u2200 (m : \u2115), monotone f \u2192 monotone (\u03bb n, f (m + n))`. -/\ntheorem Monotone.covariant_of_const [CovariantClass M N \u03bc (\u00b7 \u2264 \u00b7)] (hf : Monotone f) (m : M) :\n    Monotone fun n => f (\u03bc m n) :=\n  hf.comp <| Covariant.monotone_of_const m\n#align monotone.covariant_of_const Monotone.covariant_of_const\n\n/- warning: monotone.covariant_of_const' -> Monotone.covariant_of_const' is a dubious translation:\nlean 3 declaration is\n  forall {N : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : Preorder.{u2} \u03b1] [_inst_2 : Preorder.{u1} N] {f : N -> \u03b1} {\u03bc : N -> N -> N} [_inst_3 : CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) \u03bc) (LE.le.{u1} N (Preorder.toLE.{u1} N _inst_2))], (Monotone.{u1, u2} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : N), Monotone.{u1, u2} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc n m)))\nbut is expected to have type\n  forall {N : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} N] {f : N -> \u03b1} {\u03bc : N -> N -> N} [_inst_3 : CovariantClass.{u2, u2} N N (Function.swap.{succ u2, succ u2, succ u2} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) \u03bc) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1631 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1633 : N) => LE.le.{u2} N (Preorder.toLE.{u2} N _inst_2) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1631 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1633)], (Monotone.{u2, u1} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : N), Monotone.{u2, u1} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc n m)))\nCase conversion may be inaccurate. Consider using '#align monotone.covariant_of_const' Monotone.covariant_of_const'\u2093'. -/\n/-- Same as `monotone.covariant_of_const`, but with the constant on the other side of\nthe operator.  E.g., `\u2200 (m : \u2115), monotone f \u2192 monotone (\u03bb n, f (n + m))`. -/\ntheorem Monotone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [CovariantClass N N (swap \u03bc) (\u00b7 \u2264 \u00b7)]\n    (hf : Monotone f) (m : N) : Monotone fun n => f (\u03bc n m) :=\n  hf.comp <| Covariant.monotone_of_const m\n#align monotone.covariant_of_const' Monotone.covariant_of_const'\n\n/- warning: antitone.covariant_of_const -> Antitone.covariant_of_const is a dubious translation:\nlean 3 declaration is\n  forall {M : Type.{u1}} {N : Type.{u2}} {\u03bc : M -> N -> N} {\u03b1 : Type.{u3}} [_inst_1 : Preorder.{u3} \u03b1] [_inst_2 : Preorder.{u2} N] {f : N -> \u03b1} [_inst_3 : CovariantClass.{u1, u2} M N \u03bc (LE.le.{u2} N (Preorder.toLE.{u2} N _inst_2))], (Antitone.{u2, u3} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : M), Antitone.{u2, u3} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc m n)))\nbut is expected to have type\n  forall {M : Type.{u3}} {N : Type.{u2}} {\u03bc : M -> N -> N} {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} N] {f : N -> \u03b1} [_inst_3 : CovariantClass.{u3, u2} M N \u03bc (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1713 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1715 : N) => LE.le.{u2} N (Preorder.toLE.{u2} N _inst_2) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1713 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1715)], (Antitone.{u2, u1} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : M), Antitone.{u2, u1} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc m n)))\nCase conversion may be inaccurate. Consider using '#align antitone.covariant_of_const Antitone.covariant_of_const\u2093'. -/\n/-- Dual of `monotone.covariant_of_const` -/\ntheorem Antitone.covariant_of_const [CovariantClass M N \u03bc (\u00b7 \u2264 \u00b7)] (hf : Antitone f) (m : M) :\n    Antitone fun n => f (\u03bc m n) :=\n  hf.comp_monotone <| Covariant.monotone_of_const m\n#align antitone.covariant_of_const Antitone.covariant_of_const\n\n/- warning: antitone.covariant_of_const' -> Antitone.covariant_of_const' is a dubious translation:\nlean 3 declaration is\n  forall {N : Type.{u1}} {\u03b1 : Type.{u2}} [_inst_1 : Preorder.{u2} \u03b1] [_inst_2 : Preorder.{u1} N] {f : N -> \u03b1} {\u03bc : N -> N -> N} [_inst_3 : CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) \u03bc) (LE.le.{u1} N (Preorder.toLE.{u1} N _inst_2))], (Antitone.{u1, u2} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : N), Antitone.{u1, u2} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc n m)))\nbut is expected to have type\n  forall {N : Type.{u2}} {\u03b1 : Type.{u1}} [_inst_1 : Preorder.{u1} \u03b1] [_inst_2 : Preorder.{u2} N] {f : N -> \u03b1} {\u03bc : N -> N -> N} [_inst_3 : CovariantClass.{u2, u2} N N (Function.swap.{succ u2, succ u2, succ u2} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) \u03bc) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1787 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1789 : N) => LE.le.{u2} N (Preorder.toLE.{u2} N _inst_2) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1787 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.1789)], (Antitone.{u2, u1} N \u03b1 _inst_2 _inst_1 f) -> (forall (m : N), Antitone.{u2, u1} N \u03b1 _inst_2 _inst_1 (fun (n : N) => f (\u03bc n m)))\nCase conversion may be inaccurate. Consider using '#align antitone.covariant_of_const' Antitone.covariant_of_const'\u2093'. -/\n/-- Dual of `monotone.covariant_of_const'` -/\ntheorem Antitone.covariant_of_const' {\u03bc : N \u2192 N \u2192 N} [CovariantClass N N (swap \u03bc) (\u00b7 \u2264 \u00b7)]\n    (hf : Antitone f) (m : N) : Antitone fun n => f (\u03bc n m) :=\n  hf.comp_monotone <| Covariant.monotone_of_const m\n#align antitone.covariant_of_const' Antitone.covariant_of_const'\n\nend Monotone\n\n#print covariant_le_of_covariant_lt /-\ntheorem covariant_le_of_covariant_lt [PartialOrder N] :\n    Covariant M N \u03bc (\u00b7 < \u00b7) \u2192 Covariant M N \u03bc (\u00b7 \u2264 \u00b7) :=\n  by\n  refine' fun h a b c bc => _\n  rcases le_iff_eq_or_lt.mp bc with (rfl | bc)\n  \u00b7 exact rfl.le\n  \u00b7 exact (h _ bc).le\n#align covariant_le_of_covariant_lt covariant_le_of_covariant_lt\n-/\n\n#print contravariant_lt_of_contravariant_le /-\ntheorem contravariant_lt_of_contravariant_le [PartialOrder N] :\n    Contravariant M N \u03bc (\u00b7 \u2264 \u00b7) \u2192 Contravariant M N \u03bc (\u00b7 < \u00b7) :=\n  by\n  refine' fun h a b c bc => lt_iff_le_and_ne.mpr \u27e8h a bc.le, _\u27e9\n  rintro rfl\n  exact lt_irrefl _ bc\n#align contravariant_lt_of_contravariant_le contravariant_lt_of_contravariant_le\n-/\n\n#print covariant_le_iff_contravariant_lt /-\ntheorem covariant_le_iff_contravariant_lt [LinearOrder N] :\n    Covariant M N \u03bc (\u00b7 \u2264 \u00b7) \u2194 Contravariant M N \u03bc (\u00b7 < \u00b7) :=\n  \u27e8fun h a b c bc => not_le.mp fun k => not_le.mpr bc (h _ k), fun h a b c bc =>\n    not_lt.mp fun k => not_lt.mpr bc (h _ k)\u27e9\n#align covariant_le_iff_contravariant_lt covariant_le_iff_contravariant_lt\n-/\n\n#print covariant_lt_iff_contravariant_le /-\ntheorem covariant_lt_iff_contravariant_le [LinearOrder N] :\n    Covariant M N \u03bc (\u00b7 < \u00b7) \u2194 Contravariant M N \u03bc (\u00b7 \u2264 \u00b7) :=\n  \u27e8fun h a b c bc => not_lt.mp fun k => not_lt.mpr bc (h _ k), fun h a b c bc =>\n    not_le.mp fun k => not_le.mpr bc (h _ k)\u27e9\n#align covariant_lt_iff_contravariant_le covariant_lt_iff_contravariant_le\n-/\n\n/- warning: covariant_flip_mul_iff -> covariant_flip_mul_iff is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) (r : N -> N -> Prop) [_inst_1 : CommSemigroup.{u1} N], Iff (Covariant.{u1, u1} N N (flip.{succ u1, succ u1, succ u1} N N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))))) r) (Covariant.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1)))) r)\nbut is expected to have type\n  forall (N : Type.{u1}) (r : N -> N -> Prop) [_inst_1 : CommSemigroup.{u1} N], Iff (Covariant.{u1, u1} N N (flip.{succ u1, succ u1, succ u1} N N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2299 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2301 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2299 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2301)) r) (Covariant.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2318 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2320 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2318 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2320) r)\nCase conversion may be inaccurate. Consider using '#align covariant_flip_mul_iff covariant_flip_mul_iff\u2093'. -/\n@[to_additive]\ntheorem covariant_flip_mul_iff [CommSemigroup N] :\n    Covariant N N (flip (\u00b7 * \u00b7)) r \u2194 Covariant N N (\u00b7 * \u00b7) r := by rw [IsSymmOp.flip_eq]\n#align covariant_flip_mul_iff covariant_flip_mul_iff\n#align covariant_flip_add_iff covariant_flip_add_iff\n\n/- warning: contravariant_flip_mul_iff -> contravariant_flip_mul_iff is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) (r : N -> N -> Prop) [_inst_1 : CommSemigroup.{u1} N], Iff (Contravariant.{u1, u1} N N (flip.{succ u1, succ u1, succ u1} N N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))))) r) (Contravariant.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1)))) r)\nbut is expected to have type\n  forall (N : Type.{u1}) (r : N -> N -> Prop) [_inst_1 : CommSemigroup.{u1} N], Iff (Contravariant.{u1, u1} N N (flip.{succ u1, succ u1, succ u1} N N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2389 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2391 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2389 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2391)) r) (Contravariant.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2408 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2410 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2408 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2410) r)\nCase conversion may be inaccurate. Consider using '#align contravariant_flip_mul_iff contravariant_flip_mul_iff\u2093'. -/\n@[to_additive]\ntheorem contravariant_flip_mul_iff [CommSemigroup N] :\n    Contravariant N N (flip (\u00b7 * \u00b7)) r \u2194 Contravariant N N (\u00b7 * \u00b7) r := by rw [IsSymmOp.flip_eq]\n#align contravariant_flip_mul_iff contravariant_flip_mul_iff\n#align contravariant_flip_add_iff contravariant_flip_add_iff\n\n#print contravariant_mul_lt_of_covariant_mul_le /-\n@[to_additive]\ninstance contravariant_mul_lt_of_covariant_mul_le [Mul N] [LinearOrder N]\n    [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)\n    where elim := (covariant_le_iff_contravariant_lt N N (\u00b7 * \u00b7)).mp CovariantClass.elim\n#align contravariant_mul_lt_of_covariant_mul_le contravariant_mul_lt_of_covariant_mul_le\n#align contravariant_add_lt_of_covariant_add_le contravariant_add_lt_of_covariant_add_le\n-/\n\n#print covariant_mul_lt_of_contravariant_mul_le /-\n@[to_additive]\ninstance covariant_mul_lt_of_contravariant_mul_le [Mul N] [LinearOrder N]\n    [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : CovariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)\n    where elim := (covariant_lt_iff_contravariant_le N N (\u00b7 * \u00b7)).mpr ContravariantClass.elim\n#align covariant_mul_lt_of_contravariant_mul_le covariant_mul_lt_of_contravariant_mul_le\n#align covariant_add_lt_of_contravariant_add_le covariant_add_lt_of_contravariant_add_le\n-/\n\n/- warning: covariant_swap_mul_le_of_covariant_mul_le -> covariant_swap_mul_le_of_covariant_mul_le is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LE.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1)))) (LE.le.{u1} N _inst_2)], CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))))) (LE.le.{u1} N _inst_2)\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LE.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2701 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2703 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2701 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2703) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2716 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2718 : N) => LE.le.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2716 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2718)], CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2737 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2739 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2737 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2739)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2752 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2754 : N) => LE.le.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2752 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2754)\nCase conversion may be inaccurate. Consider using '#align covariant_swap_mul_le_of_covariant_mul_le covariant_swap_mul_le_of_covariant_mul_le\u2093'. -/\n@[to_additive]\ninstance covariant_swap_mul_le_of_covariant_mul_le [CommSemigroup N] [LE N]\n    [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)\n    where elim := (covariant_flip_mul_iff N (\u00b7 \u2264 \u00b7)).mpr CovariantClass.elim\n#align covariant_swap_mul_le_of_covariant_mul_le covariant_swap_mul_le_of_covariant_mul_le\n#align covariant_swap_add_le_of_covariant_add_le covariant_swap_add_le_of_covariant_add_le\n\n/- warning: contravariant_swap_mul_le_of_contravariant_mul_le -> contravariant_swap_mul_le_of_contravariant_mul_le is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LE.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1)))) (LE.le.{u1} N _inst_2)], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))))) (LE.le.{u1} N _inst_2)\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LE.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2815 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2817 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2815 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2817) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2830 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2832 : N) => LE.le.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2830 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2832)], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2851 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2853 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2851 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2853)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2866 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2868 : N) => LE.le.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2866 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2868)\nCase conversion may be inaccurate. Consider using '#align contravariant_swap_mul_le_of_contravariant_mul_le contravariant_swap_mul_le_of_contravariant_mul_le\u2093'. -/\n@[to_additive]\ninstance contravariant_swap_mul_le_of_contravariant_mul_le [CommSemigroup N] [LE N]\n    [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)\n    where elim := (contravariant_flip_mul_iff N (\u00b7 \u2264 \u00b7)).mpr ContravariantClass.elim\n#align contravariant_swap_mul_le_of_contravariant_mul_le contravariant_swap_mul_le_of_contravariant_mul_le\n#align contravariant_swap_add_le_of_contravariant_add_le contravariant_swap_add_le_of_contravariant_add_le\n\n/- warning: contravariant_swap_mul_lt_of_contravariant_mul_lt -> contravariant_swap_mul_lt_of_contravariant_mul_lt is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LT.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1)))) (LT.lt.{u1} N _inst_2)], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))))) (LT.lt.{u1} N _inst_2)\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LT.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2929 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2931 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2929 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2931) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2944 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2946 : N) => LT.lt.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2944 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2946)], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2965 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2967 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2965 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2967)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2980 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2982 : N) => LT.lt.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2980 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.2982)\nCase conversion may be inaccurate. Consider using '#align contravariant_swap_mul_lt_of_contravariant_mul_lt contravariant_swap_mul_lt_of_contravariant_mul_lt\u2093'. -/\n@[to_additive]\ninstance contravariant_swap_mul_lt_of_contravariant_mul_lt [CommSemigroup N] [LT N]\n    [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)] : ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)\n    where elim := (contravariant_flip_mul_iff N (\u00b7 < \u00b7)).mpr ContravariantClass.elim\n#align contravariant_swap_mul_lt_of_contravariant_mul_lt contravariant_swap_mul_lt_of_contravariant_mul_lt\n#align contravariant_swap_add_lt_of_contravariant_add_lt contravariant_swap_add_lt_of_contravariant_add_lt\n\n/- warning: covariant_swap_mul_lt_of_covariant_mul_lt -> covariant_swap_mul_lt_of_covariant_mul_lt is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LT.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1)))) (LT.lt.{u1} N _inst_2)], CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))))) (LT.lt.{u1} N _inst_2)\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : CommSemigroup.{u1} N] [_inst_2 : LT.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3043 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3045 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3043 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3045) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3058 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3060 : N) => LT.lt.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3058 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3060)], CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3079 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3081 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (CommSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3079 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3081)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3094 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3096 : N) => LT.lt.{u1} N _inst_2 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3094 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3096)\nCase conversion may be inaccurate. Consider using '#align covariant_swap_mul_lt_of_covariant_mul_lt covariant_swap_mul_lt_of_covariant_mul_lt\u2093'. -/\n@[to_additive]\ninstance covariant_swap_mul_lt_of_covariant_mul_lt [CommSemigroup N] [LT N]\n    [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)] : CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)\n    where elim := (covariant_flip_mul_iff N (\u00b7 < \u00b7)).mpr CovariantClass.elim\n#align covariant_swap_mul_lt_of_covariant_mul_lt covariant_swap_mul_lt_of_covariant_mul_lt\n#align covariant_swap_add_lt_of_covariant_add_lt covariant_swap_add_lt_of_covariant_add_lt\n\n/- warning: left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le -> LeftCancelSemigroup.covariant_mul_lt_of_covariant_mul_le is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : LeftCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1)))) (LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))], CovariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1)))) (LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : LeftCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3160 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3162 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3160 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3162) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3175 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3177 : N) => LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3175 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3177)], CovariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3193 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3195 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3193 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3195) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3208 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3210 : N) => LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3208 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3210)\nCase conversion may be inaccurate. Consider using '#align left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le LeftCancelSemigroup.covariant_mul_lt_of_covariant_mul_le\u2093'. -/\n@[to_additive]\ninstance LeftCancelSemigroup.covariant_mul_lt_of_covariant_mul_le [LeftCancelSemigroup N]\n    [PartialOrder N] [CovariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)] : CovariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)\n    where elim a b c bc := by\n    cases' lt_iff_le_and_ne.mp bc with bc cb\n    exact lt_iff_le_and_ne.mpr \u27e8CovariantClass.elim a bc, (mul_ne_mul_right a).mpr cb\u27e9\n#align left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le LeftCancelSemigroup.covariant_mul_lt_of_covariant_mul_le\n#align add_left_cancel_semigroup.covariant_add_lt_of_covariant_add_le AddLeftCancelSemigroup.covariant_add_lt_of_covariant_add_le\n\n/- warning: right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le -> RightCancelSemigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : RightCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))))) (LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))], CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))))) (LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : RightCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3285 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3287 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3285 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3287)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3300 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3302 : N) => LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3300 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3302)], CovariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3321 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3323 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3321 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3323)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3336 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3338 : N) => LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3336 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3338)\nCase conversion may be inaccurate. Consider using '#align right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le RightCancelSemigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le\u2093'. -/\n@[to_additive]\ninstance RightCancelSemigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le\n    [RightCancelSemigroup N] [PartialOrder N] [CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)] :\n    CovariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)\n    where elim a b c bc := by\n    cases' lt_iff_le_and_ne.mp bc with bc cb\n    exact lt_iff_le_and_ne.mpr \u27e8CovariantClass.elim a bc, (mul_ne_mul_left a).mpr cb\u27e9\n#align right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le RightCancelSemigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le\n#align add_right_cancel_semigroup.covariant_swap_add_lt_of_covariant_swap_add_le AddRightCancelSemigroup.covariant_swap_add_lt_of_covariant_swap_add_le\n\n/- warning: left_cancel_semigroup.contravariant_mul_le_of_contravariant_mul_lt -> LeftCancelSemigroup.contravariant_mul_le_of_contravariant_mul_lt is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : LeftCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1)))) (LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))], ContravariantClass.{u1, u1} N N (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1)))) (LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : LeftCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3410 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3412 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3410 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3412) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3425 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3427 : N) => LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3425 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3427)], ContravariantClass.{u1, u1} N N (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3443 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3445 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (LeftCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3443 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3445) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3458 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3460 : N) => LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3458 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3460)\nCase conversion may be inaccurate. Consider using '#align left_cancel_semigroup.contravariant_mul_le_of_contravariant_mul_lt LeftCancelSemigroup.contravariant_mul_le_of_contravariant_mul_lt\u2093'. -/\n@[to_additive]\ninstance LeftCancelSemigroup.contravariant_mul_le_of_contravariant_mul_lt [LeftCancelSemigroup N]\n    [PartialOrder N] [ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 < \u00b7)] :\n    ContravariantClass N N (\u00b7 * \u00b7) (\u00b7 \u2264 \u00b7)\n    where elim a b c bc := by\n    cases' le_iff_eq_or_lt.mp bc with h h\n    \u00b7 exact ((mul_right_inj a).mp h).le\n    \u00b7 exact (ContravariantClass.elim _ h).le\n#align left_cancel_semigroup.contravariant_mul_le_of_contravariant_mul_lt LeftCancelSemigroup.contravariant_mul_le_of_contravariant_mul_lt\n#align add_left_cancel_semigroup.contravariant_add_le_of_contravariant_add_lt AddLeftCancelSemigroup.contravariant_add_le_of_contravariant_add_lt\n\n/- warning: right_cancel_semigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt -> RightCancelSemigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt is a dubious translation:\nlean 3 declaration is\n  forall (N : Type.{u1}) [_inst_1 : RightCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))))) (LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toHasMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))))) (LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)))\nbut is expected to have type\n  forall (N : Type.{u1}) [_inst_1 : RightCancelSemigroup.{u1} N] [_inst_2 : PartialOrder.{u1} N] [_inst_3 : ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3544 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3546 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3544 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3546)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3559 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3561 : N) => LT.lt.{u1} N (Preorder.toLT.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3559 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3561)], ContravariantClass.{u1, u1} N N (Function.swap.{succ u1, succ u1, succ u1} N N (fun (\u1fb0 : N) (\u1fb0 : N) => N) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3580 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3582 : N) => HMul.hMul.{u1, u1, u1} N N N (instHMul.{u1} N (Semigroup.toMul.{u1} N (RightCancelSemigroup.toSemigroup.{u1} N _inst_1))) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3580 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3582)) (fun (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3595 : N) (x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3597 : N) => LE.le.{u1} N (Preorder.toLE.{u1} N (PartialOrder.toPreorder.{u1} N _inst_2)) x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3595 x._@.Mathlib.Algebra.CovariantAndContravariant._hyg.3597)\nCase conversion may be inaccurate. Consider using '#align right_cancel_semigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt RightCancelSemigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt\u2093'. -/\n@[to_additive]\ninstance RightCancelSemigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt\n    [RightCancelSemigroup N] [PartialOrder N] [ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 < \u00b7)] :\n    ContravariantClass N N (swap (\u00b7 * \u00b7)) (\u00b7 \u2264 \u00b7)\n    where elim a b c bc := by\n    cases' le_iff_eq_or_lt.mp bc with h h\n    \u00b7 exact ((mul_left_inj a).mp h).le\n    \u00b7 exact (ContravariantClass.elim _ h).le\n#align right_cancel_semigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt RightCancelSemigroup.contravariant_swap_mul_le_of_contravariant_swap_mul_lt\n#align add_right_cancel_semigroup.contravariant_swap_add_le_of_contravariant_swap_add_lt AddRightCancelSemigroup.contravariant_swap_add_le_of_contravariant_swap_add_lt\n\nend Variants\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/CovariantAndContravariant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7008258251960683}}
{"text": "import tactic.basic\nimport .ch05_tactics\n\nopen basics (oddb evenb eqb)\nopen induction (double evenb_succ)\nopen lists (eqb_refl)\nopen tactics (eqb_true)\n\nopen list (map cons_append nil_append)\nopen nat (pred succ eq_zero_of_mul_eq_zero)\n\nnamespace logic\n\nvariables {\u03b1 \u03b2 \u03b3 : Type}\nvariable {a : \u03b1}\nvariables {P Q R : Prop}\nvariables {m n o p : \u2115}\nvariables {l l' : list \u03b1}\n\n/-\nCheck 3 = 3.\n(* ===> Prop *)\nCheck \u2200n m : nat, n + m = m + n.\n(* ===> Prop *)\n-/\n\n#check 3 = 3\n\n#check \u2200n m : \u2115, n + m = m + n\n\n/-\nCheck 2 = 2.\n(* ===> Prop *)\nCheck \u2200n : nat, n = 2.\n(* ===> Prop *)\nCheck 3 = 4.\n(* ===> Prop *)\n-/\n\n#check 2 = 2\n\n#check \u2200n : \u2115, n = 2\n\n#check 3 = 4\n\n/-\nTheorem plus_2_2_is_4 :\n  2 + 2 = 4.\nProof. reflexivity. Qed.\n-/\n\ntheorem plus_2_2_is_4 : 2 + 2 = 4 := rfl\n\n/-\nDefinition plus_fact : Prop := 2 + 2 = 4.\nCheck plus_fact.\n(* ===> plus_fact : Prop *)\n-/\n\ndef plus_fact : Prop := 2 + 2 = 4\n\n#check plus_fact\n\n/-\nTheorem plus_fact_is_true :\n  plus_fact.\nProof. reflexivity. Qed.\n-/\n\ntheorem plus_fact_is_true : plus_fact := by rw plus_fact\n\n/-\nDefinition is_three (n : nat) : Prop :=\n  n = 3.\nCheck is_three.\n(* ===> nat -> Prop *)\n-/\n\ndef is_three (n : \u2115) : Prop := n = 3\n\n#check is_three\n\n/-\nDefinition injective {A B} (f : A \u2192 B) :=\n  \u2200x y : A, f x = f y \u2192 x = y.\nLemma succ_inj : injective S.\nProof.\n  intros n m H. injection H as H1. apply H1.\nQed.\n-/\n\ndef injective (f : \u03b1 \u2192 \u03b2) :=  \u2200(x y: \u03b1), f x = f y \u2192 x = y\n\nlemma nat.succ_inj : injective succ :=\nbegin\n  intros n m h,\n  injection h,\nend\n\n/-\nCheck @eq.\n(* ===> forall A : Type, A -> A -> Prop *)\n-/\n\n#check @eq\n\n/-\nExample and_example : 3 + 4 = 7 \u2227 2 * 2 = 4.\nProof.\n  split.\n  - (* 3 + 4 = 7 *) reflexivity.\n  - (* 2 + 2 = 4 *) reflexivity.\nQed.\n-/\n\nexample : 3 + 4 = 7 \u2227 2 * 2 = 4 :=\nbegin\n  split,\n    refl,\n  refl,\nend\n\n/-\nLemma and_intro : \u2200A B : Prop, A \u2192 B \u2192 A \u2227 B.\nProof.\n  intros A B HA HB. split.\n  - apply HA.\n  - apply HB.\nQed.\n-/\n\n/- TODO: be better about namespacing earlier defs -/\nlemma and.intro (p : P) (q : Q) : P \u2227 Q := \u27e8p, q\u27e9\n\n/-\nExample and_example' : 3 + 4 = 7 \u2227 2 * 2 = 4.\nProof.\n  apply and_intro.\n  - (* 3 + 4 = 7 *) reflexivity.\n  - (* 2 + 2 = 4 *) reflexivity.\nQed.\n-/\n\nexample : 3 + 4 = 7 \u2227 2 * 2 = 4 :=\nbegin\n  apply and.intro,\n    refl,\n  refl,\nend\n\n/-\nExample and_exercise :\n  \u2200n m : nat, n + m = 0 \u2192 n = 0 \u2227 m = 0.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/- can't be example as it's used below -/\nlemma and_exercise : \u2200(n m : \u2115) (h : n + m = 0), n = 0 \u2227 m = 0\n| 0 0 h :=\nbegin\n  split,\n    refl,\n  refl,\nend\n| (n + 1) m h :=\nbegin\n  rw [add_comm, \u2190add_assoc] at h,\n  cases h,\nend\n| n (m + 1) h :=\nbegin\n  rw [\u2190add_assoc] at h,\n  cases h,\nend\n\n/-\nLemma and_example2 :\n  \u2200n m : nat, n = 0 \u2227 m = 0 \u2192 n + m = 0.\nProof.\n  (* WORKED IN CLASS *)\n  intros n m H.\n  destruct H as [Hn Hm].\n  rewrite Hn. rewrite Hm.\n  reflexivity.\nQed.\n-/\n\nlemma and_example\u2082 (h : n = 0 \u2227 m = 0) : n + m = 0 :=\nbegin\n  cases h with hn hm,\n  rw [hn, hm],\nend\n\n/-\nLemma and_example2' :\n  \u2200n m : nat, n = 0 \u2227 m = 0 \u2192 n + m = 0.\nProof.\n  intros n m [Hn Hm].\n  rewrite Hn. rewrite Hm.\n  reflexivity.\nQed.\n-/\n\nlemma and_example\u2082' : n = 0 \u2227 m = 0 \u2192 n + m = 0 :=\nbegin\n  rintro \u27e8hn, hm\u27e9,\n  rw [hn, hm],\nend\n\n/-\nLemma and_example2'' :\n  \u2200n m : nat, n = 0 \u2192 m = 0 \u2192 n + m = 0.\nProof.\n  intros n m Hn Hm.\n  rewrite Hn. rewrite Hm.\n  reflexivity.\nQed.\n-/\n\nlemma and_example2'' (hn : n = 0) (hm : m = 0) : n + m = 0 := by rw [hn, hm]\n\n/-\nLemma and_example3 :\n  \u2200n m : nat, n + m = 0 \u2192 n * m = 0.\nProof.\n  (* WORKED IN CLASS *)\n  intros n m H.\n  assert (H' : n = 0 \u2227 m = 0).\n  { apply and_exercise. apply H. }\n  destruct H' as [Hn Hm].\n  rewrite Hn. reflexivity.\nQed.\n-/\n\nlemma and_example\u2083 (h : n + m = 0) : n * m = 0 :=\nbegin\n  have h : n = 0 \u2227 m = 0,\n    apply and_exercise,\n    exact h,\n  cases h with hn hm,\n  rw hn,\n  rw zero_mul,\nend\n\n/-\nLemma proj1 : \u2200P Q : Prop,\n  P \u2227 Q \u2192 P.\nProof.\n  intros P Q [HP HQ].\n  apply HP. Qed.\n-/\n\nlemma and.left (h : P \u2227 Q) : P :=\nbegin\n  cases h with hp hq,\n  apply hp,\nend\n\n/- h.1 also works -/\nlemma and.left' (h : P \u2227 Q) : P := h.left\n\n/-\nLemma proj2 : \u2200P Q : Prop,\n  P \u2227 Q \u2192 Q.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma and.right (h : P \u2227 Q) : Q := h.right\n\n/-\nTheorem and_commut : \u2200P Q : Prop,\n  P \u2227 Q \u2192 Q \u2227 P.\nProof.\n  intros P Q [HP HQ].\n  split.\n    - (* left *) apply HQ.\n    - (* right *) apply HP. Qed.\n-/\n\ntheorem and.comm (h : P \u2227 Q) : Q \u2227 P := \u27e8h.right, h.left\u27e9\n\n/-\nTheorem and_assoc : \u2200P Q R : Prop,\n  P \u2227 (Q \u2227 R) \u2192 (P \u2227 Q) \u2227 R.\nProof.\n  intros P Q R [HP [HQ HR]].\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem and.assoc (h : (P \u2227 Q) \u2227 R) : P \u2227 (Q \u2227 R) :=\n  \u27e8h.left.left, h.left.right, h.right\u27e9\n\n/-\nCheck and.\n(* ===> and : Prop -> Prop -> Prop *)\n-/\n\n#check @and\n\n/-\nLemma or_example :\n  \u2200n m : nat, n = 0 \u2228 m = 0 \u2192 n * m = 0.\nProof.\n  (* This pattern implicitly does case analysis on\n     n = 0 \u2228 m = 0 *)\n  intros n m [Hn | Hm].\n  - (* Here, n = 0 *)\n    rewrite Hn. reflexivity.\n  - (* Here, m = 0 *)\n    rewrite Hm. rewrite <- mult_n_O.\n    reflexivity.\nQed.\n-/\n\nlemma or_example (h : n = 0 \u2228 m = 0) : n * m = 0 :=\nbegin\n  cases h with hn hm,\n    rw hn,\n    rw zero_mul,\n  rw hm,\n  refl,\nend\n\n/-\nLemma or_intro : \u2200A B : Prop, A \u2192 A \u2228 B.\nProof.\n  intros A B HA.\n  left.\n  apply HA.\nQed.\n-/\n\nlemma or.inl (p : P) : P \u2228 Q :=\nbegin\n  left,\n  exact p,\nend\n\n/-\nLemma zero_or_succ :\n  \u2200n : nat, n = 0 \u2228 n = S (pred n).\nProof.\n  (* WORKED IN CLASS *)\n  intros [|n].\n  - left. reflexivity.\n  - right. reflexivity.\nQed.\n-/\n\nlemma nat.eq_zero_or_eq_succ_pred : n = 0 \u2228 n = succ (pred n) :=\nbegin\n  cases n,\n    exact or.inl rfl,\n  exact or.inr rfl,\nend\n\n/-\nModule MyNot.\n\nDefinition not (P:Prop) := P \u2192 False.\n\nNotation \"\u00acx\" := (not x) : type_scope.\n\nCheck not.\n(* ===> Prop -> Prop *)\n\nEnd MyNot.\n-/\n\ndef not (P : Prop) := P \u2192 false\n\nlocal prefix `\u00ac` := not\n\n#check not\n\n/-\nTheorem ex_falso_quodlibet : \u2200(P:Prop),\n  False \u2192 P.\nProof.\n  (* WORKED IN CLASS *)\n  intros P contra.\n  destruct contra. Qed.\n-/\n\ntheorem false.rec (f : false) : P := by cases f\n\n/-\nFact not_implies_our_not : \u2200(P:Prop),\n  \u00acP \u2192 (\u2200(Q:Prop), P \u2192 Q).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma absurd (hnp : \u00acP) (hp : P) : Q := false.rec (hnp hp)\n\n/-\nNotation \"x \u2260 y\" := (~(x = y)).\n-/\n\nlocal notation x \u2260 y := \u00ac(x = y)\n\n/-\nTheorem zero_not_one : 0 \u2260 1.\nProof.\n  unfold not.\n  intros contra.\n  discriminate contra.\nQed.\n-/\n\ntheorem zero_ne_one : 0 \u2260 1 :=\nbegin\n  unfold not,\n  rintro \u27e8contra\u27e9,\nend\n\n/-\nTheorem not_False :\n  \u00acFalse.\nProof.\n  unfold not. intros H. destruct H. Qed.\n\nTheorem contradiction_implies_anything : \u2200P Q : Prop,\n  (P \u2227 \u00acP) \u2192 Q.\nProof.\n  (* WORKED IN CLASS *)\n  intros P Q [HP HNA]. unfold not in HNA.\n  apply HNA in HP. destruct HP. Qed.\n\nTheorem double_neg : \u2200P : Prop,\n  P \u2192 ~~P.\nProof.\n  (* WORKED IN CLASS *)\n  intros P H. unfold not. intros G. apply G. apply H. Qed.\n-/\n\ntheorem not_false : \u00acfalse :=\nbegin\n  unfold not,\n  rintro \u27e8h\u27e9,\nend\n\ntheorem contradiction_implies_anything (h : P \u2227 \u00acP) : Q :=\nbegin\n  cases h with hp hnp,\n  unfold not at hnp,\n  replace hp, exact hnp hp,\n  cases hp,\nend\n\ntheorem non_contradictory_intro (h : P) : \u00ac\u00acP :=\nbegin\n  unfold not,\n  intro g,\n  apply g,\n  exact h,\nend\n\n/-\nTheorem contrapositive : \u2200(P Q : Prop),\n  (P \u2192 Q) \u2192 (\u00acQ \u2192 \u00acP).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem contrapositive (h: P \u2192 Q) : (\u00acQ \u2192 \u00acP) :=\nbegin\n  intro hnq,\n  unfold not,\n  intro p,\n  exact absurd hnq (h p),\nend\n\n/-\nTheorem not_both_true_and_false : \u2200P : Prop,\n  \u00ac(P \u2227 \u00acP).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem not_both_true_and_false : \u00ac(P \u2227 \u00acP) :=\nbegin\n  unfold not,\n  rintro \u27e8hp, hnp\u27e9,\n  exact hnp hp,\nend\n\n/-\nTheorem not_true_is_false : \u2200b : bool,\n  b \u2260 true \u2192 b = false.\nProof.\n  intros [] H.\n  - (* b = true *)\n    unfold not in H.\n    apply ex_falso_quodlibet.\n    apply H. reflexivity.\n  - (* b = false *)\n    reflexivity.\nQed.\n-/\n\ntheorem not_true_is_false {b: bool} (h : b \u2260 tt) : b = ff :=\nbegin\n  cases b,\n    refl,\n  unfold not at h,\n  apply false.rec,\n  apply h,\n  refl,\nend\n\n/-\nTheorem not_true_is_false' : \u2200b : bool,\n  b \u2260 true \u2192 b = false.\nProof.\n  intros [] H.\n  - (* b = true *)\n    unfold not in H.\n    exfalso. (* <=== *)\n    apply H. reflexivity.\n  - (* b = false *) reflexivity.\nQed.\n-/\n\ntheorem not_true_is_false' {b : bool} (h : b \u2260 tt) : b = ff :=\nbegin\n  cases b,\n    refl,\n  unfold not at h,\n  exfalso,\n  apply h,\n  refl,\nend\n\n/-\nLemma True_is_true : True.\nProof. apply I. Qed.\n-/\n\nlemma true_is_tt : true := trivial\n\n/-\nModule MyIff.\n\nDefinition iff (P Q : Prop) := (P \u2192 Q) \u2227 (Q \u2192 P).\n\nNotation \"P \u2194 Q\" := (iff P Q)\n                      (at level 95, no associativity)\n                      : type_scope.\n\nEnd MyIff.\n\nTheorem iff_sym : \u2200P Q : Prop,\n  (P \u2194 Q) \u2192 (Q \u2194 P).\nProof.\n  (* WORKED IN CLASS *)\n  intros P Q [HAB HBA].\n  split.\n  - (* -> *) apply HBA.\n  - (* <- *) apply HAB. Qed.\n\nLemma not_true_iff_false : \u2200b,\n  b \u2260 true \u2194 b = false.\nProof.\n  (* WORKED IN CLASS *)\n  intros b. split.\n  - (* -> *) apply not_true_is_false.\n  - (* <- *)\n    intros H. rewrite H. intros H'. discriminate H'.\nQed.\n-/\n\nsection my_iff\n\n/- this def doesn't work with rewrite -/\nstructure iff (P Q : Prop): Prop :=\nintro :: (mp : P \u2192 Q) (mpr : Q \u2192 P)\n\nlocal infix \u2194 := iff\n\nend my_iff\n\ntheorem iff.sym (h : P \u2194 Q) : Q \u2194 P :=\nbegin\n  cases h with hpq hqp,\n  split,\n    exact hqp,\n  exact hpq,\nend\n\nlemma not_true_iff_false (b: bool) : b \u2260 tt \u2194 b = ff :=\nbegin\n  split,\n    apply not_true_is_false,\n  intro h,\n  rw h,\n  intro h',\n  cases h',\nend\n\n/-\nTheorem or_distributes_over_and : \u2200P Q R : Prop,\n  P \u2228 (Q \u2227 R) \u2194 (P \u2228 Q) \u2227 (P \u2228 R).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem or_and_distrib_left : P \u2228 (Q \u2227 R) \u2194 (P \u2228 Q) \u2227 (P \u2228 R) :=\nbegin\n  split,\n    rintro (hp | hqr),\n      split,\n        exact or.inl hp,\n      exact or.inl hp,\n    split,\n      exact or.inr hqr.left,\n    exact or.inr hqr.right,\n  rintro \u27e8hpq, hpr\u27e9,\n  cases hpq with hp hq,\n    exact or.inl hp,\n  cases hpr with hp hr,\n    exact or.inl hp,\n  exact or.inr \u27e8hq, hr\u27e9\nend\n\n/-\nFrom Coq Require Import Setoids.Setoid.\n-/\n\n/-\nnothing like that needed in lean\n-/\n\n/-\nLemma mult_0 : \u2200n m, n * m = 0 \u2194 n = 0 \u2228 m = 0.\nProof.\n  split.\n  - apply mult_eq_0.\n  - apply or_example.\nQed.\n\nLemma or_assoc :\n  \u2200P Q R : Prop, P \u2228 (Q \u2228 R) \u2194 (P \u2228 Q) \u2228 R.\nProof.\n  intros P Q R. split.\n  - intros [H | [H | H]].\n    + left. left. apply H.\n    + left. right. apply H.\n    + right. apply H.\n  - intros [[H | H] | H].\n    + left. apply H.\n    + right. left. apply H.\n    + right. right. apply H.\nQed.\n-/\n\nlemma mul_zero : n * m = 0 \u2194 n = 0 \u2228 m = 0 :=\nbegin\n  split,\n   exact eq_zero_of_mul_eq_zero,\n  apply or_example,\nend\n\nlemma or.assoc : P \u2228 (Q \u2228 R) \u2194 (P \u2228 Q) \u2228 R :=\nbegin\n  split,\n    rintro (h | h | h),\n        exact or.inl (or.inl h),\n      exact or.inl (or.inr h),\n    exact or.inr h,\n  rintro (\u27e8h | h\u27e9 | h),\n      exact or.inl h,\n    exact or.inr (or.inl h),\n  exact or.inr (or.inr h),\nend\n\n/-\nLemma mult_0_3 :\n  \u2200n m p, n * m * p = 0 \u2194 n = 0 \u2228 m = 0 \u2228 p = 0.\nProof.\n  intros n m p.\n  rewrite mult_0. rewrite mult_0. rewrite or_assoc.\n  reflexivity.\nQed.\n-/\n\nlemma mul_zero_three : n * m * p = 0 \u2194 n = 0 \u2228 m = 0 \u2228 p = 0 :=\nbegin\n  rw [mul_zero, mul_zero],\n  rewrite or.assoc,\nend\n\n/-\nLemma apply_iff_example :\n  \u2200n m : nat, n * m = 0 \u2192 n = 0 \u2228 m = 0.\nProof.\n  intros n m H. apply mult_0. apply H.\nQed.\n-/\n\n/- apply doesn't seem to work with iff in lean -/\n/- can use mp/mpr to pick a direction -/\n\nlemma apply_iff_example (h : n * m = 0) : n = 0 \u2228 m = 0 :=\nbegin\n  apply mul_zero.mp,\n  exact h,\nend\n\n/-\nLemma four_is_even : \u2203n : nat, 4 = n + n.\nProof.\n  \u22032. reflexivity.\nQed.\n-/\n\nlemma four_is_even : \u2203n : \u2115, 4 = n + n := by use 2\n\n/-\nTheorem exists_example_2 : \u2200n,\n  (\u2203m, n = 4 + m) \u2192\n  (\u2203o, n = 2 + o).\nProof.\n  (* WORKED IN CLASS *)\n  intros n [m Hm]. (* note implicit destruct here *)\n  \u2203(2 + m).\n  apply Hm. Qed.\n-/\n\ntheorem exists_example\u2082 (h : \u2203m, n = 4 + m) : \u2203o, n = 2 + o :=\nbegin\n  cases h with m hm,\n  use 2 + m,\n  rw \u2190add_assoc,\n  exact hm,\nend\n\n/-\nTheorem dist_not_exists : \u2200(X:Type) (P : X \u2192 Prop),\n  (\u2200x, P x) \u2192 \u00ac(\u2203x, \u00acP x).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n#check exists_or_distrib\n\ntheorem not_exists_not.mpr (p : \u03b1 \u2192 Prop) (h : \u2200x, p x) : \u00ac(\u2203x, \u00acp x) :=\nbegin\n  rintro \u27e8a, hnp\u27e9,\n  exact hnp (h a),\nend\n\n/-\nTheorem dist_exists_or : \u2200(X:Type) (P Q : X \u2192 Prop),\n  (\u2203x, P x \u2228 Q x) \u2194 (\u2203x, P x) \u2228 (\u2203x, Q x).\nProof.\n   (* FILL IN HERE *) Admitted.\n-/\n\ntheorem exists_or_distrib (p q : \u03b1 \u2192 Prop) :\n  (\u2203a, p a \u2228 q a) \u2194 (\u2203a, p a) \u2228 (\u2203a, q a) :=\nbegin\n  split,\n    rintro \u27e8a, hp | hq\u27e9,\n      exact or.inl \u27e8a, hp\u27e9,\n    exact or.inr \u27e8a, hq\u27e9,\n  rintro (\u27e8a, hp\u27e9 | \u27e8a, hq\u27e9),\n    exact \u27e8a, or.inl hp\u27e9,\n  exact \u27e8a, or.inr hq\u27e9,\nend\n\n/-\nFixpoint In {A : Type} (x : A) (l : list A) : Prop :=\n  match l with\n  | [] \u21d2 False\n  | x' :: l' \u21d2 x' = x \u2228 In x l'\n  end.\n-/\n\ndef In (a : \u03b1) : list \u03b1 \u2192 Prop\n| [] := false\n| (h::t) := h = a \u2228 In t\n\n/-\nExample In_example_1 : In 4 [1; 2; 3; 4; 5].\nProof.\n  (* WORKED IN CLASS *)\n  simpl. right. right. right. left. reflexivity.\nQed.\n\nExample In_example_2 :\n  \u2200n, In n [2; 4] \u2192\n  \u2203n', n = 2 * n'.\nProof.\n  (* WORKED IN CLASS *)\n  simpl.\n  intros n [H | [H | []]].\n  - \u22031. rewrite <- H. reflexivity.\n  - \u22032. rewrite <- H. reflexivity.\nQed.\n-/\n\nexample : In 4 [1, 2, 3, 4, 5] :=\nbegin\n  right,\n  right,\n  right,\n  left,\n  refl,\nend\n\n/-\noh yeah, rcases doing subst for rfl is awesome\n-/\nexample (h : In n [2, 4]) : \u2203n', n = 2 * n' :=\nbegin\n  rcases h with rfl | rfl | \u27e8\u27e8\u27e9\u27e9,\n    use 1,\n    refl,\n  use 2,\n  refl,\nend\n\n/-\nLemma In_map :\n  \u2200(A B : Type) (f : A \u2192 B) (l : list A) (x : A),\n    In x l \u2192\n    In (f x) (map f l).\nProof.\n  intros A B f l x.\n  induction l as [|x' l' IHl'].\n  - (* l = nil, contradiction *)\n    simpl. intros [].\n  - (* l = x' :: l' *)\n    simpl. intros [H | H].\n    + rewrite H. left. reflexivity.\n    + right. apply IHl'. apply H.\nQed.\n-/\n\nlemma in_map (f : \u03b1 \u2192 \u03b2) (h : In a l) : In (f a) (l.map f) :=\nbegin\n  induction l with a' l ih,\n    cases h,\n  rcases h with rfl | h,\n    exact or.inl rfl,\n  exact or.inr (ih h),\nend\n\n/-\nLemma In_map_iff :\n  \u2200(A B : Type) (f : A \u2192 B) (l : list A) (y : B),\n    In y (map f l) \u2194\n    \u2203x, f x = y \u2227 In x l.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/-\nTODO: at this point, i realize a lot of unfold and rw aren't needed\n      as unification will handle refl stuff\n-/\n\nlemma in_map_iff (f : \u03b1 \u2192 \u03b2) (b : \u03b2) : In b (l.map f) \u2194 \u2203a, f a = b \u2227 In a l :=\nbegin\n  split,\n    induction l with a l ih,\n      rintro \u27e8\u27e9,\n    rintro (rfl | h),\n      use a,\n      split,\n        refl,\n      exact or.inl rfl,\n    specialize ih h,\n    rcases ih with \u27e8a', rfl, ih\u27e9,\n    use a',\n    split,\n      refl,\n    exact or.inr ih,\n  rintro \u27e8a', rfl, h\u27e9,\n  induction l with a l ih,\n    cases h,\n  rcases h with rfl | h,\n    exact or.inl rfl,\n  exact or.inr (ih h),\nend\n\n/-\nLemma In_app_iff : \u2200A l l' (a:A),\n  In a (l++l') \u2194 In a l \u2228 In a l'.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma in_app_iff : In a (l ++ l') \u2194 In a l \u2228 In a l' :=\nbegin\n  split,\n    intro h,\n    induction l with a' l ih,\n      exact or.inr h,\n    rcases h with rfl | h,\n      exact or.inl (or.inl rfl),\n    specialize ih h,\n    cases ih,\n      exact or.inl (or.inr ih),\n    exact or.inr ih,\n  rintro (h | h),\n    induction l with a' l ih,\n      cases h,\n    rcases h with rfl | h,\n      exact or.inl rfl,\n    exact or.inr (ih h),\n  cases l' with a' l',\n    cases h,\n  cases h,\n    induction l with a'' l ih,\n      exact or.inl h,\n    exact or.inr ih,\n  induction l with a'' l ih,\n    exact or.inr h,\n  exact or.inr ih,\nend\n\n/-\nFixpoint All {T : Type} (P : T \u2192 Prop) (l : list T) : Prop\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n\nLemma All_In :\n  \u2200T (P : T \u2192 Prop) (l : list T),\n    (\u2200x, In x l \u2192 P x) \u2194\n    All P l.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ndef all (p : \u03b1 \u2192 Prop) : list \u03b1 \u2192 Prop\n| [] := true\n| (h::t) := p h \u2227 all t\n\nlemma all_in (p : \u03b1 \u2192 Prop) : (\u2200{a}, In a l \u2192 p a) \u2194 all p l :=\nbegin\n  split,\n    intro h,\n    induction l with a l ih,\n      unfold all,\n    split,\n      apply h,\n      exact or.inl rfl,\n    apply ih,\n    intros a' i,\n    exact h (or.inr i),\n  induction l with a l ih,\n    rintro h a' \u27e8\u27e9,\n  rintro \u27e8hl, hr\u27e9 a' (rfl | i),\n    exact hl,\n  exact ih hr i,\nend\n\n/-\nDefinition combine_odd_even (Podd Peven : nat \u2192 Prop) : nat \u2192 Prop\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n-/\n\n/-\neither i super missed the mark with this def\nor this is not a three star problem\n-/\n\ndef combine_odd_even (podd peven : \u2115 \u2192 Prop) (n : \u2115): Prop :=\n  if oddb n then podd n else peven n\n\n/-\nTheorem combine_odd_even_intro :\n  \u2200(Podd Peven : nat \u2192 Prop) (n : nat),\n    (oddb n = true \u2192 Podd n) \u2192\n    (oddb n = false \u2192 Peven n) \u2192\n    combine_odd_even Podd Peven n.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem combine_odd_even_elim_odd :\n  \u2200(Podd Peven : nat \u2192 Prop) (n : nat),\n    combine_odd_even Podd Peven n \u2192\n    oddb n = true \u2192\n    Podd n.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem combine_odd_even_elim_even :\n  \u2200(Podd Peven : nat \u2192 Prop) (n : nat),\n    combine_odd_even Podd Peven n \u2192\n    oddb n = false \u2192\n    Peven n.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem combine_odd_even_intro\n  (podd peven : \u2115 \u2192 Prop)\n  (hodd : oddb n = true \u2192 podd n)\n  (heven : oddb n = false \u2192 peven n)\n  : combine_odd_even podd peven n :=\nbegin\n  unfold combine_odd_even,\n  cases oddb n,\n    exact heven rfl,\n  exact hodd rfl,\nend\n\ntheorem combine_odd_even_elim_odd\n  (podd peven : \u2115 \u2192 Prop)\n  (h : combine_odd_even podd peven n)\n  (hodd : oddb n = true)\n  : podd n :=\nbegin\n  unfold combine_odd_even at h,\n  cases oddb n,\n    cases hodd,\n  exact h,\nend\n\ntheorem combine_odd_even_elim_even\n  (podd peven : \u2115 \u2192 Prop)\n  (h : combine_odd_even podd peven n)\n  (heven : oddb n = false)\n  : peven n :=\nbegin\n  unfold combine_odd_even at h,\n  cases oddb n,\n    exact h,\n  cases heven,\nend\n\n/-\nCheck plus_comm.\n(* ===> forall n m : nat, n + m = m + n *)\n-/\n\n#check add_comm\n\n/-\nLemma plus_comm3 :\n  \u2200x y z, x + (y + z) = (z + y) + x.\nProof.\n  (* WORKED IN CLASS *)\n  intros x y z.\n  rewrite plus_comm.\n  rewrite plus_comm.\n  (* We are back where we started... *)\nAbort.\n-/\n\n-- lemma plus_comm3 : n + (m + o) = (o + m) + m :=\n-- begin\n--   rw add_comm,\n--   rw add_comm,\n--   sorry\n-- end\n\n/-\nLemma plus_comm3_take2 :\n  \u2200x y z, x + (y + z) = (z + y) + x.\nProof.\n  intros x y z.\n  rewrite plus_comm.\n  assert (H : y + z = z + y).\n  { rewrite plus_comm. reflexivity. }\n  rewrite H.\n  reflexivity.\nQed.\n-/\n\nlemma plus_comm3_take2 : n + (m + o) = (o + m) + n :=\nbegin\n  rw add_comm,\n  have h : m + o = o + m, rw add_comm,\n  rw h,\nend\n\n/-\nLemma plus_comm3_take3 :\n  \u2200x y z, x + (y + z) = (z + y) + x.\nProof.\n  intros x y z.\n  rewrite plus_comm.\n  rewrite (plus_comm y z).\n  reflexivity.\nQed.\n-/\n\n/-\nTODO: i find it unlikely i haven't used this earlier\n-/\nlemma plus_comm3_take3 : n + (m + o) = (o + m) + n :=\nbegin\n  rw add_comm,\n  /- i assume partial app works in coq as well -/\n  rw add_comm m,\nend\n\n/-\nLemma in_not_nil :\n  \u2200A (x : A) (l : list A), In x l \u2192 l \u2260 [].\nProof.\n  intros A x l H. unfold not. intro Hl. destruct l.\n  - simpl in H. destruct H.\n  - discriminate Hl.\nQed.\n-/\n\nlemma in_not_nil (h : In a l) : l \u2260 [] :=\nbegin\n  unfold not,\n  intro hl,\n  cases l with a l,\n    cases h,\n  cases hl,\nend\n\n/-\nLemma in_not_nil_42 :\n  \u2200l : list nat, In 42 l \u2192 l \u2260 [].\nProof.\n  (* WORKED IN CLASS *)\n  intros l H.\n  Fail apply in_not_nil.\nAbort.\n(* apply ... with ... *)\n\nLemma in_not_nil_42_take2 :\n  \u2200l : list nat, In 42 l \u2192 l \u2260 [].\nProof.\n  intros l H.\n  apply in_not_nil with (x := 42).\n  apply H.\nQed.\n(* apply ... in ... *)\n\nLemma in_not_nil_42_take3 :\n  \u2200l : list nat, In 42 l \u2192 l \u2260 [].\nProof.\n  intros l H.\n  apply in_not_nil in H.\n  apply H.\nQed.\n(* Explicitly apply the lemma to the value for x. *)\n\nLemma in_not_nil_42_take4 :\n  \u2200l : list nat, In 42 l \u2192 l \u2260 [].\nProof.\n  intros l H.\n  apply (in_not_nil nat 42).\n  apply H.\nQed.\n(* Explicitly apply the lemma to a hypothesis. *)\n\nLemma in_not_nil_42_take5 :\n  \u2200l : list nat, In 42 l \u2192 l \u2260 [].\nProof.\n  intros l H.\n  apply (in_not_nil _ _ _ H).\nQed.\n-/\n\n/- this works perfectly fine in lean -/\nlemma in_not_nil_42 (l : list \u2115) (h : In 42 l) : l \u2260 [] :=\nbegin\n  apply in_not_nil,\n  exact h,\nend\n\n/-\nTODO: see if lean has named parameters\n-/\nlemma in_not_nil_42_take2 (l : list \u2115) (h : In 42 l) : l \u2260 [] :=\nbegin\n  /- don't know of a syntax like with -/\n  apply in_not_nil,\n  exact h,\nend\n\n/- learned about conv, still not able to apply at h -/\n-- lemma in_not_nil_42_take3 (l : list \u2115) (h : In 42 l)\n--   : l \u2260 [] := sorry\n\nlemma in_not_nil_42_take4 (l : list \u2115) (h : In 42 l) : l \u2260 [] :=\nbegin\n  apply @in_not_nil \u2115 42,\n  exact h,\nend\n\nlemma in_not_nil_42_take5 (l : list \u2115) (h : In 42 l) : l \u2260 [] :=\nby apply in_not_nil h\n\n/-\nExample lemma_application_ex :\n  \u2200{n : nat} {ns : list nat},\n    In n (map (fun m \u21d2 m * 0) ns) \u2192\n    n = 0.\nProof.\n  intros n ns H.\n  destruct (proj1 _ _ (In_map_iff _ _ _ _ _) H)\n           as [m [Hm _]].\n  rewrite mult_0_r in Hm. rewrite <- Hm. reflexivity.\nQed.\n-/\n\nexample {ns: list \u2115} (h : In n (ns.map (\u03bbm, m * 0))): n = 0 :=\nbegin\n  cases (in_map_iff _ _).mp h with m hm,\n  rw \u2190hm.left,\n  refl,\nend\n\n/-\nExample function_equality_ex1 :\n  (fun x \u21d2 3 + x) = (fun x \u21d2 (pred 4) + x).\nProof. reflexivity. Qed.\n-/\n\nexample : (\u03bbx, 3 + x) = (\u03bbx, (pred 4) + x) := rfl\n\n/-\nExample function_equality_ex2 :\n  (fun x \u21d2 plus x 1) = (fun x \u21d2 plus 1 x).\nProof.\n   (* Stuck *)\nAbort.\n-/\n\n-- example : (\u03bbx, x + 1) = (\u03bbx, 1 + x) := sorry\n\n/-\nAxiom functional_extensionality : \u2200{X Y: Type}\n                                    {f g : X \u2192 Y},\n  (\u2200(x:X), f x = g x) \u2192 f = g.\n-/\n\n\naxiom functional_extensionality {f g : \u03b1 \u2192 \u03b2} : (\u2200a, f a = g a) \u2192 f = g\n\n/-\nExample function_equality_ex2 :\n  (fun x \u21d2 plus x 1) = (fun x \u21d2 plus 1 x).\nProof.\n  apply functional_extensionality. intros x.\n  apply plus_comm.\nQed.\n-/\n\nlemma function_equality_ex\u2082 : (\u03bbx, x + 1) = (\u03bbx, 1 + x) :=\nbegin\n  apply functional_extensionality,\n  intro x,\n  rw add_comm,\nend\n\n/- built in as funext -/\n/-\nTODO: examine previous definitions that have tactics\n-/\n\nexample : (\u03bbx, x + 1) = (\u03bbx, 1 + x) :=\nbegin\n  funext,\n  rw add_comm,\nend\n\n/-\nPrint Assumptions function_equality_ex2.\n(* ===>\n     Axioms:\n     functional_extensionality :\n         forall (X Y : Type) (f g : X -> Y),\n                (forall x : X, f x = g x) -> f = g *)\n-/\n\n#print axioms function_equality_ex\u2082\n\n/-\nFixpoint rev_append {X} (l1 l2 : list X) : list X :=\n  match l1 with\n  | [] \u21d2 l2\n  | x :: l1' \u21d2 rev_append l1' (x :: l2)\n  end.\n\nDefinition tr_rev {X} (l : list X) : list X :=\n  rev_append l [].\n-/\n\nsection reverse\n\n/- using poly.list as the library uses a rev_append style reverse -/\n\nopen poly.list\n\nlocal notation `[]` := nil\nlocal infix :: := cons\nlocal infix ++ := append\n\ndef rev_append : poly.list \u03b1 \u2192 poly.list \u03b1 \u2192 poly.list \u03b1\n| [] l\u2082 := l\u2082\n| (h::t) l\u2082 := rev_append t (h::l\u2082)\n\ndef tr_rev (l: poly.list \u03b1) := rev_append l []\n\n/-\nLemma tr_rev_correct : \u2200X, @tr_rev X = @rev X.\n(* FILL IN HERE *) Admitted.\n-/\n\nlemma rev_app (l\u2081 l\u2082 l\u2083: poly.list \u03b1)\n  : rev_append l\u2081 l\u2082 ++ l\u2083 = rev_append l\u2081 (l\u2082 ++ l\u2083) :=\nbegin\n  induction l\u2081 with a l\u2081 ih generalizing l\u2082 l\u2083,\n    refl,\n  unfold rev_append,\n  rw ih,\n  refl,\nend\n\nlemma tr_rev_correct : @tr_rev \u03b1 = reverse :=\nbegin\n  funext,\n  induction l with a l ih,\n    refl,\n  unfold reverse,\n  rw \u2190ih,\n  unfold rev_append tr_rev,\n  rw rev_app,\n  refl,\nend\n\nend reverse\n\n/-\nExample even_42_bool : evenb 42 = true.\nProof. reflexivity. Qed.\n-/\n\nexample : evenb 42 = tt := rfl\n\n/-\nExample even_42_prop : \u2203k, 42 = double k.\nProof. \u220321. reflexivity. Qed.\n-/\n\nexample : \u2203k, 42 = double k := \u27e821, rfl\u27e9\n\n/-\nTheorem evenb_double : \u2200k, evenb (double k) = true.\nProof.\n  intros k. induction k as [|k' IHk'].\n  - reflexivity.\n  - simpl. apply IHk'.\nQed.\n-/\n\ntheorem evenb_double (k) : evenb (double k) = tt :=\nbegin\n  induction k with k ih,\n    refl,\n  unfold double evenb,\n  exact ih,\nend\n\n/-\nTheorem evenb_double_conv : \u2200n,\n  \u2203k, n = if evenb n then double k\n                else S (double k).\nProof.\n  (* Hint: Use the evenb_S lemma from Induction.v. *)\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem evenb_double_conv\n  : \u2203k, n = if evenb n then double k else succ (double k) :=\nbegin\n  induction n with n ih,\n    exact \u27e80, rfl\u27e9,\n  cases ih with k ih,\n    rw evenb_succ,\n    conv in (n + 1) { rw ih, },\n    cases h : evenb n,\n      use succ k,\n      refl,\n    use k,\n    refl,\nend\n\ntheorem evenb_double_conv'\n  : \u2200n, \u2203k, n = if evenb n then double k else succ (double k)\n| 0 := \u27e80, rfl\u27e9\n| 1 := \u27e80, rfl\u27e9\n| (n + 2) :=\nbegin\n  cases evenb_double_conv' n with k ih,\n  use succ k,\n  rw [evenb_succ, evenb_succ],\n  conv in (n + 2) { rw ih, },\n  cases evenb n,\n    refl,\n  refl,\nend\n\n/-\nTheorem even_bool_prop : \u2200n,\n  evenb n = true \u2194 \u2203k, n = double k.\nProof.\n  intros n. split.\n  - intros H. destruct (evenb_double_conv n) as [k Hk].\n    rewrite Hk. rewrite H. \u2203k. reflexivity.\n  - intros [k Hk]. rewrite Hk. apply evenb_double.\nQed.\n-/\n\ntheorem even_bool_prop : evenb n = tt \u2194 \u2203k, n = double k :=\nbegin\n  split,\n    intro h,\n    cases (@evenb_double_conv n) with k hk,\n    rw hk,\n    rw h,\n    exact \u27e8k, rfl\u27e9,\n  rintro \u27e8k, rfl\u27e9,\n  apply evenb_double,\nend\n\n/-\nTheorem eqb_eq : \u2200n1 n2 : nat,\n  n1 =? n2 = true \u2194 n1 = n2.\nProof.\n  intros n1 n2. split.\n  - apply eqb_true.\n  - intros H. rewrite H. rewrite <- eqb_refl. reflexivity.\nQed.\n-/\n\ntheorem eqb_eq : n =? m = tt \u2194 n = m :=\nbegin\n  split,\n    apply eqb_true,\n  rintro rfl,\n  rw \u2190eqb_refl,\nend\n\n/-\nFail Definition is_even_prime n :=\n  if n = 2 then true\n  else false.\n-/\n\n/-\nn = 2 is decidable, so lean allows it\nnot all props are\n-/\ndef is_even_prime := if n = 2 then tt else ff\n\n/-\nExample even_1000 : \u2203k, 1000 = double k.\nProof. \u2203500. reflexivity. Qed.\n-/\n\nexample : \u2203k, 1000 = double k := \u27e8500, rfl\u27e9\n\n/-\nExample even_1000' : evenb 1000 = true.\nProof. reflexivity. Qed.\n-/\n\nexample : evenb 1000 := rfl\n\n/-\nExample even_1000'' : \u2203k, 1000 = double k.\nProof. apply even_bool_prop. reflexivity. Qed.\n-/\n\n/-\nneed to mention the direction in lean\n-/\nexample : \u2203k, 1000 = double k :=\nbegin\n  apply even_bool_prop.mp,\n  refl,\nend\n\n/-\nExample not_even_1001 : evenb 1001 = false.\nProof.\n  (* WORKED IN CLASS *)\n  reflexivity.\nQed.\n-/\n\nexample : evenb 1001 = ff := rfl\n\n/-\nExample not_even_1001' : ~(\u2203k, 1001 = double k).\nProof.\n  (* WORKED IN CLASS *)\n  rewrite <- even_bool_prop.\n  unfold not.\n  simpl.\n  intro H.\n  discriminate H.\nQed.\n-/\n\nexample : \u00ac(\u2203k, 1001 = double k) :=\nbegin\n  rw \u2190even_bool_prop,\n  unfold not,\n  intro h,\n  cases h,\nend\n\n/-\nLemma plus_eqb_example : \u2200n m p : nat,\n    n =? m = true \u2192 n + p =? m + p = true.\nProof.\n  (* WORKED IN CLASS *)\n  intros n m p H.\n    rewrite eqb_eq in H.\n  rewrite H.\n  rewrite eqb_eq.\n  reflexivity.\nQed.\n-/\n\nlemma plus_eqb_example (h : n =? m = tt) : n + p =? m + p = tt :=\nbegin\n  rw eqb_eq at h \u22a2,\n  rw h,\nend\n\n/-\nLemma andb_true_iff : \u2200b1 b2:bool,\n  b1 && b2 = true \u2194 b1 = true \u2227 b2 = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nLemma orb_true_iff : \u2200b1 b2,\n  b1 || b2 = true \u2194 b1 = true \u2228 b2 = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma band_eq_true_eq_eq_tt_and_eq_tt (b\u2081 b\u2082 : bool)\n  : b\u2081 && b\u2082 = tt \u2194 b\u2081 = tt \u2227 b\u2082 = tt :=\nbegin\n  split,\n    intro h,\n    cases b\u2081,\n      cases h,\n    cases b\u2082,\n      cases h,\n    exact \u27e8rfl, rfl\u27e9,\n  rintro \u27e8rfl, rfl\u27e9,\n  refl,\nend\n\nlemma bor_eq_true_eq_eq_tt_or_eq_tt (b\u2081 b\u2082 : bool)\n  : b\u2081 || b\u2082 = tt \u2194 b\u2081 = tt \u2228 b\u2082 = tt :=\nbegin\n  split,\n    intro h,\n    cases b\u2081,\n      cases b\u2082,\n        cases h,\n      exact or.inr rfl,\n    exact or.inl rfl,\n  rintro (rfl | rfl),\n    refl,\n  cases b\u2081,\n    refl,\n  refl,\nend\n\n/-\nTheorem eqb_neq : \u2200x y : nat,\n  x =? y = false \u2194 x \u2260 y.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/- how is this one star? -/\ntheorem eqb_neq : n =? m = ff \u2194 n \u2260 m :=\nbegin\n  split,\n    intro h,\n    rintro rfl,\n    rw eqb_refl n at h,\n    cases h,\n  intro c,\n  unfold not at c,\n  induction n with n ih generalizing m,\n    cases m,\n      cases c rfl,\n    refl,\n  cases m,\n    refl,\n  unfold eqb,\n  apply ih,\n  rintro rfl,\n  exact c rfl,\nend\n\n/-\nFixpoint eqb_list {A : Type} (eqb : A \u2192 A \u2192 bool)\n                  (l1 l2 : list A) : bool\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n\nLemma eqb_list_true_iff :\n  \u2200A (eqb : A \u2192 A \u2192 bool),\n    (\u2200a1 a2, eqb a1 a2 = true \u2194 a1 = a2) \u2192\n    \u2200l1 l2, eqb_list eqb l1 l2 = true \u2194 l1 = l2.\nProof.\n(* FILL IN HERE *) Admitted.\n-/\n\ndef eqb_list (eqb : \u03b1 \u2192 \u03b1 \u2192 bool) : list \u03b1 \u2192 list \u03b1 \u2192 bool\n| [] [] := tt\n| (h\u2081::t\u2081) (h\u2082::t\u2082) := eqb h\u2081 h\u2082 && eqb_list t\u2081 t\u2082\n| _ _ := ff\n\nlemma eqb_list_true_iff\n  (eqb : \u03b1 \u2192 \u03b1 \u2192 bool)\n  (heq : \u2200a\u2081 a\u2082, eqb a\u2081 a\u2082 = tt \u2194 a\u2081 = a\u2082)\n  (l\u2081 : list \u03b1)\n  (l\u2082 : list \u03b1)\n  : eqb_list eqb l\u2081 l\u2082 = tt \u2194 l\u2081 = l\u2082 :=\nbegin\n  split,\n    intro h,\n    induction l\u2081 with h\u2081 t\u2081 ih generalizing l\u2082,\n      cases l\u2082 with h\u2082 t\u2082,\n        refl,\n      cases h,\n    cases l\u2082 with h\u2082 t\u2082,\n      cases h,\n    unfold eqb_list at h,\n    rw band_eq_true_eq_eq_tt_and_eq_tt at h,\n    congr,\n      rw heq at h,\n      exact h.left,\n    exact ih _ h.right,\n  rintro rfl,\n  induction l\u2081 with h\u2081 t\u2081 ih,\n    refl,\n  unfold eqb_list,\n  rw ih,\n  rw (heq h\u2081 h\u2081).mpr rfl,\n  refl,\nend\n\n/-\nTheorem forallb_true_iff : \u2200X test (l : list X),\n   forallb test l = true \u2194 All (fun x \u21d2 test x = true) l.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem all_true_iff (p : \u03b1 \u2192 bool) : l.all p = tt \u2194 all (\u03bba, p a = tt) l :=\nbegin\n  split,\n    intro h,\n    induction l with a l ih,\n      unfold all,\n    unfold all,\n    unfold list.all list.foldr at h,\n    rw band_eq_true_eq_eq_tt_and_eq_tt at h,\n    exact \u27e8h.left, ih h.right\u27e9,\n  intro h,\n  induction l with a l ih,\n    refl,\n  unfold all at h,\n  unfold list.all list.foldr,\n  rw band_eq_true_eq_eq_tt_and_eq_tt,\n  exact \u27e8h.left, ih h.right\u27e9,\nend\n\n/-\nDefinition excluded_middle := \u2200P : Prop,\n  P \u2228 \u00acP.\n-/\n\ndef classical.em := \u2200P : Prop, P \u2228 \u00acP\n\n/-\nTheorem restricted_excluded_middle : \u2200P b,\n  (P \u2194 b = true) \u2192 P \u2228 \u00acP.\nProof.\n  intros P [] H.\n  - left. rewrite H. reflexivity.\n  - right. rewrite H. intros contra. discriminate contra.\nQed.\n-/\n\ntheorem restricted_excluded_middle (b : bool) (h : P \u2194 b = tt) : P \u2228 \u00acP :=\nbegin\n  rw h,\n  cases b,\n    right,\n    rintro \u27e8\u27e9,\n  exact or.inl rfl,\nend\n\n/-\nTheorem restricted_excluded_middle_eq : \u2200(n m : nat),\n  n = m \u2228 n \u2260 m.\nProof.\n  intros n m.\n  apply (restricted_excluded_middle (n = m) (n =? m)).\n  symmetry.\n  apply eqb_eq.\nQed.\n-/\n\ntheorem restricted_excluded_middle_eq : n = m \u2228 n \u2260 m :=\nbegin\n  apply @restricted_excluded_middle (n = m) (n =? m),\n  symmetry,\n  exact eqb_eq,\nend\n\n/-\nTheorem excluded_middle_irrefutable: \u2200(P:Prop),\n  \u00ac\u00ac(P \u2228 \u00acP).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem excluded_middle_irrefutable (P : Prop) : \u00ac\u00ac(P \u2228 \u00acP) :=\nbegin\n  intro h,\n  apply h,\n  right,\n  intro p,\n  apply h,\n  exact or.inl p,\nend\n\n/-\nTheorem not_exists_dist :\n  excluded_middle \u2192\n  \u2200(X:Type) (P : X \u2192 Prop),\n    \u00ac(\u2203x, \u00acP x) \u2192 (\u2200x, P x).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem not_exists_dist (em : classical.em) (p : \u03b1 \u2192 Prop) (h : \u00ac(\u2203a, \u00acp a))\n  : p a :=\nbegin\n  cases em (p a) with hp hnp,\n    exact hp,\n  have c : \u2203a, \u00acp a,\n    exact \u27e8a, hnp\u27e9,\n  exact absurd h c,\nend\n\n/-\nDefinition peirce := \u2200P Q: Prop,\n  ((P\u2192Q)\u2192P)\u2192P.\n\nDefinition double_negation_elimination := \u2200P:Prop,\n  ~~P \u2192 P.\n\nDefinition de_morgan_not_and_not := \u2200P Q:Prop,\n  ~(~P \u2227 \u00acQ) \u2192 P\u2228Q.\n\nDefinition implies_to_or := \u2200P Q:Prop,\n  (P\u2192Q) \u2192 (\u00acP\u2228Q).\n-/\n\n/- peirce and peirce' are in core -/\ndef peirce := \u2200P Q : Prop, ((P \u2192 Q) \u2192 P) \u2192 P\n\ndef double_negation_elimination := \u2200P : Prop, \u00ac\u00acP \u2192 P\n\ndef de_morgan_not_and_not := \u2200P Q : Prop, \u00ac(\u00acP \u2227 \u00acQ) \u2192 P \u2228 Q\n\ndef implies_to_or := \u2200P Q : Prop, (P \u2192 Q) \u2192 \u00acP \u2228 Q\n\ndef em_iff_peirce : classical.em \u2194 peirce :=\nbegin\n  unfold classical.em peirce,\n  split,\n    intros em P Q h,\n    cases em P with p np,\n      exact p,\n    apply h,\n    intro p,\n    exact absurd np p,\n  intros peirce P,\n  apply peirce _ false,\n  intro h,\n  right,\n  intro p,\n  exact h (or.inl p),\nend\n\ndef em_iff_dne : classical.em \u2194 double_negation_elimination :=\nbegin\n  unfold classical.em double_negation_elimination,\n  split,\n    intros em P nnp,\n    cases em P with p np,\n      exact p,\n    exact absurd nnp np,\n  intros dne P,\n  exact dne _ (excluded_middle_irrefutable P),\nend\n\ndef em_iff_dmnn : classical.em \u2194 de_morgan_not_and_not :=\nbegin\n  unfold classical.em de_morgan_not_and_not,\n  split,\n    intros em P Q npq,\n    cases em P with p np,\n      exact or.inl p,\n    cases em Q with q nq,\n      exact or.inr q,\n    exact absurd npq \u27e8np, nq\u27e9,\n  intros dmnn P,\n  apply dmnn,\n  rintro \u27e8np, nnp\u27e9,\n  exact absurd nnp np,\nend\n\ndef em_iff_tor : classical.em \u2194 implies_to_or :=\nbegin\n  unfold classical.em implies_to_or,\n  split,\n    intros em P Q hpq,\n    cases em P with p np,\n      exact or.inr (hpq p),\n    exact or.inl np,\n  intros tor P,\n  rw or.comm,\n  apply tor,\n  exact id,\nend\n\nend logic", "meta": {"author": "michens", "repo": "learn-lean", "sha": "f38fc342780ddff5a164a18e5482163dea506ccd", "save_path": "github-repos/lean/michens-learn-lean", "path": "github-repos/lean/michens-learn-lean/learn-lean-f38fc342780ddff5a164a18e5482163dea506ccd/sf/v1/ch06_logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7008258115421346}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n-/\nimport analysis.convex.strict_convex_between\nimport geometry.euclidean.basic\n\n/-!\n# Spheres\n\nThis file defines and proves basic results about spheres and cospherical sets of points in\nEuclidean affine spaces.\n\n## Main definitions\n\n* `euclidean_geometry.sphere` bundles a `center` and a `radius`.\n\n* `euclidean_geometry.cospherical` is the property of a set of points being equidistant from some\n  point.\n\n* `euclidean_geometry.concyclic` is the property of a set of points being cospherical and\n  coplanar.\n\n-/\n\nnoncomputable theory\nopen_locale real_inner_product_space\n\nnamespace euclidean_geometry\n\nvariables {V : Type*} (P : Type*)\n\nopen finite_dimensional\n\n/-- A `sphere P` bundles a `center` and `radius`. This definition does not require the radius to\nbe positive; that should be given as a hypothesis to lemmas that require it. -/\n@[ext] structure sphere [metric_space P] :=\n(center : P)\n(radius : \u211d)\n\nvariables {P}\n\nsection metric_space\nvariables [metric_space P]\n\ninstance [nonempty P] : nonempty (sphere P) := \u27e8\u27e8classical.arbitrary P, 0\u27e9\u27e9\n\ninstance : has_coe (sphere P) (set P) := \u27e8\u03bb s, metric.sphere s.center s.radius\u27e9\ninstance : has_mem P (sphere P) := \u27e8\u03bb p s, p \u2208 (s : set P)\u27e9\n\nlemma sphere.mk_center (c : P) (r : \u211d) : (\u27e8c, r\u27e9 : sphere P).center = c := rfl\n\nlemma sphere.mk_radius (c : P) (r : \u211d) : (\u27e8c, r\u27e9 : sphere P).radius = r := rfl\n\n@[simp] lemma sphere.mk_center_radius (s : sphere P) : (\u27e8s.center, s.radius\u27e9 : sphere P) = s :=\nby ext; refl\n\nlemma sphere.coe_def (s : sphere P) : (s : set P) = metric.sphere s.center s.radius := rfl\n\n@[simp] lemma sphere.coe_mk (c : P) (r : \u211d) : \u2191(\u27e8c, r\u27e9 : sphere P) = metric.sphere c r := rfl\n\n@[simp] lemma sphere.mem_coe {p : P} {s : sphere P} : p \u2208 (s : set P) \u2194 p \u2208 s := iff.rfl\n\nlemma mem_sphere {p : P} {s : sphere P} : p \u2208 s \u2194 dist p s.center = s.radius := iff.rfl\n\nlemma mem_sphere' {p : P} {s : sphere P} : p \u2208 s \u2194 dist s.center p = s.radius :=\nmetric.mem_sphere'\n\nlemma subset_sphere {ps : set P} {s : sphere P} : ps \u2286 s \u2194 \u2200 p \u2208 ps, p \u2208 s := iff.rfl\n\nlemma dist_of_mem_subset_sphere {p : P} {ps : set P} {s : sphere P} (hp : p \u2208 ps)\n  (hps : ps \u2286 (s : set P)) : dist p s.center = s.radius :=\nmem_sphere.1 (sphere.mem_coe.1 (set.mem_of_mem_of_subset hp hps))\n\nlemma dist_of_mem_subset_mk_sphere {p c : P} {ps : set P} {r : \u211d} (hp : p \u2208 ps)\n  (hps : ps \u2286 \u2191(\u27e8c, r\u27e9 : sphere P)) : dist p c = r :=\ndist_of_mem_subset_sphere hp hps\n\nlemma sphere.ne_iff {s\u2081 s\u2082 : sphere P} :\n  s\u2081 \u2260 s\u2082 \u2194 s\u2081.center \u2260 s\u2082.center \u2228 s\u2081.radius \u2260 s\u2082.radius :=\nby rw [\u2190not_and_distrib, \u2190sphere.ext_iff]\n\nlemma sphere.center_eq_iff_eq_of_mem {s\u2081 s\u2082 : sphere P} {p : P} (hs\u2081 : p \u2208 s\u2081) (hs\u2082 : p \u2208 s\u2082) :\n  s\u2081.center = s\u2082.center \u2194 s\u2081 = s\u2082 :=\nbegin\n  refine \u27e8\u03bb h, sphere.ext _ _ h _, \u03bb h, h \u25b8 rfl\u27e9,\n  rw mem_sphere at hs\u2081 hs\u2082,\n  rw [\u2190hs\u2081, \u2190hs\u2082, h]\nend\n\nlemma sphere.center_ne_iff_ne_of_mem {s\u2081 s\u2082 : sphere P} {p : P} (hs\u2081 : p \u2208 s\u2081) (hs\u2082 : p \u2208 s\u2082) :\n  s\u2081.center \u2260 s\u2082.center \u2194 s\u2081 \u2260 s\u2082 :=\n(sphere.center_eq_iff_eq_of_mem hs\u2081 hs\u2082).not\n\nlemma dist_center_eq_dist_center_of_mem_sphere {p\u2081 p\u2082 : P} {s : sphere P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) : dist p\u2081 s.center = dist p\u2082 s.center :=\nby rw [mem_sphere.1 hp\u2081, mem_sphere.1 hp\u2082]\n\nlemma dist_center_eq_dist_center_of_mem_sphere' {p\u2081 p\u2082 : P} {s : sphere P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : p\u2082 \u2208 s) : dist s.center p\u2081 = dist s.center p\u2082 :=\nby rw [mem_sphere'.1 hp\u2081, mem_sphere'.1 hp\u2082]\n\n/-- A set of points is cospherical if they are equidistant from some\npoint.  In two dimensions, this is the same thing as being\nconcyclic. -/\ndef cospherical (ps : set P) : Prop :=\n\u2203 (center : P) (radius : \u211d), \u2200 p \u2208 ps, dist p center = radius\n\n/-- The definition of `cospherical`. -/\nlemma cospherical_def (ps : set P) :\n  cospherical ps \u2194 \u2203 (center : P) (radius : \u211d), \u2200 p \u2208 ps, dist p center = radius :=\niff.rfl\n\n/-- A set of points is cospherical if and only if they lie in some sphere. -/\nlemma cospherical_iff_exists_sphere {ps : set P} :\n  cospherical ps \u2194 \u2203 s : sphere P, ps \u2286 (s : set P) :=\nbegin\n  refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n  { rcases h with \u27e8c, r, h\u27e9,\n    exact \u27e8\u27e8c, r\u27e9, h\u27e9 },\n  { rcases h with \u27e8s, h\u27e9,\n    exact \u27e8s.center, s.radius, h\u27e9 }\nend\n\n/-- The set of points in a sphere is cospherical. -/\n\n\n/-- A subset of a cospherical set is cospherical. -/\nlemma cospherical.subset {ps\u2081 ps\u2082 : set P} (hs : ps\u2081 \u2286 ps\u2082) (hc : cospherical ps\u2082) :\n  cospherical ps\u2081 :=\nbegin\n  rcases hc with \u27e8c, r, hcr\u27e9,\n  exact \u27e8c, r, \u03bb p hp, hcr p (hs hp)\u27e9\nend\n\n/-- The empty set is cospherical. -/\nlemma cospherical_empty [nonempty P] : cospherical (\u2205 : set P) :=\nlet \u27e8p\u27e9 := \u2039nonempty P\u203a in \u27e8p, 0, \u03bb p, false.elim\u27e9\n\n/-- A single point is cospherical. -/\nlemma cospherical_singleton (p : P) : cospherical ({p} : set P) :=\nbegin\n  use p,\n  simp\nend\n\nend metric_space\n\nsection normed_space\nvariables [normed_add_comm_group V] [normed_space \u211d V] [metric_space P] [normed_add_torsor V P]\ninclude V\n\n/-- Two points are cospherical. -/\nlemma cospherical_pair (p\u2081 p\u2082 : P) : cospherical ({p\u2081, p\u2082} : set P) :=\n\u27e8midpoint \u211d p\u2081 p\u2082, \u2016(2 : \u211d)\u2016\u207b\u00b9 * dist p\u2081 p\u2082, begin\n  rintros p (rfl | rfl | _),\n  { rw [dist_comm, dist_midpoint_left] },\n  { rw [dist_comm, dist_midpoint_right] }\nend\u27e9\n\n/-- A set of points is concyclic if it is cospherical and coplanar. (Most results are stated\ndirectly in terms of `cospherical` instead of using `concyclic`.) -/\nstructure concyclic (ps : set P) : Prop :=\n(cospherical : cospherical ps)\n(coplanar : coplanar \u211d ps)\n\n/-- A subset of a concyclic set is concyclic. -/\nlemma concyclic.subset {ps\u2081 ps\u2082 : set P} (hs : ps\u2081 \u2286 ps\u2082) (h : concyclic ps\u2082) : concyclic ps\u2081 :=\n\u27e8h.1.subset hs, h.2.subset hs\u27e9\n\n/-- The empty set is concyclic. -/\nlemma concyclic_empty : concyclic (\u2205 : set P) :=\n\u27e8cospherical_empty, coplanar_empty \u211d P\u27e9\n\n/-- A single point is concyclic. -/\nlemma concyclic_singleton (p : P) : concyclic ({p} : set P) :=\n\u27e8cospherical_singleton p, coplanar_singleton \u211d p\u27e9\n\n/-- Two points are concyclic. -/\nlemma concyclic_pair (p\u2081 p\u2082 : P) : concyclic ({p\u2081, p\u2082} : set P) :=\n\u27e8cospherical_pair p\u2081 p\u2082, coplanar_pair \u211d p\u2081 p\u2082\u27e9\n\nend normed_space\n\nsection euclidean_space\nvariables\n  [normed_add_comm_group V] [inner_product_space \u211d V] [metric_space P] [normed_add_torsor V P]\ninclude V\n\n/-- Any three points in a cospherical set are affinely independent. -/\nlemma cospherical.affine_independent {s : set P} (hs : cospherical s) {p : fin 3 \u2192 P}\n  (hps : set.range p \u2286 s) (hpi : function.injective p) :\n  affine_independent \u211d p :=\nbegin\n  rw affine_independent_iff_not_collinear,\n  intro hc,\n  rw collinear_iff_of_mem (set.mem_range_self (0 : fin 3)) at hc,\n  rcases hc with \u27e8v, hv\u27e9,\n  rw set.forall_range_iff at hv,\n  have hv0 : v \u2260 0,\n  { intro h,\n    have he : p 1 = p 0, by simpa [h] using hv 1,\n    exact (dec_trivial : (1 : fin 3) \u2260 0) (hpi he) },\n  rcases hs with \u27e8c, r, hs\u27e9,\n  have hs' := \u03bb i, hs (p i) (set.mem_of_mem_of_subset (set.mem_range_self _) hps),\n  choose f hf using hv,\n  have hsd : \u2200 i, dist ((f i \u2022 v) +\u1d65 p 0) c = r,\n  { intro i,\n    rw \u2190hf,\n    exact hs' i },\n  have hf0 : f 0 = 0,\n  { have hf0' := hf 0,\n    rw [eq_comm, \u2190@vsub_eq_zero_iff_eq V, vadd_vsub, smul_eq_zero] at hf0',\n    simpa [hv0] using hf0' },\n  have hfi : function.injective f,\n  { intros i j h,\n    have hi := hf i,\n    rw [h, \u2190hf j] at hi,\n    exact hpi hi },\n  simp_rw [\u2190hsd 0, hf0, zero_smul, zero_vadd, dist_smul_vadd_eq_dist (p 0) c hv0] at hsd,\n  have hfn0 : \u2200 i, i \u2260 0 \u2192 f i \u2260 0 := \u03bb i, (hfi.ne_iff' hf0).2,\n  have hfn0' : \u2200 i, i \u2260 0 \u2192 f i = (-2) * \u27eav, (p 0 -\u1d65 c)\u27eb / \u27eav, v\u27eb,\n  { intros i hi,\n    have hsdi := hsd i,\n    simpa [hfn0, hi] using hsdi },\n  have hf12 : f 1 = f 2, { rw [hfn0' 1 dec_trivial, hfn0' 2 dec_trivial] },\n  exact (dec_trivial : (1 : fin 3) \u2260 2) (hfi hf12)\nend\n\n/-- Any three points in a cospherical set are affinely independent. -/\nlemma cospherical.affine_independent_of_mem_of_ne {s : set P} (hs : cospherical s) {p\u2081 p\u2082 p\u2083 : P}\n  (h\u2081 : p\u2081 \u2208 s) (h\u2082 : p\u2082 \u2208 s) (h\u2083 : p\u2083 \u2208 s) (h\u2081\u2082 : p\u2081 \u2260 p\u2082) (h\u2081\u2083 : p\u2081 \u2260 p\u2083) (h\u2082\u2083 : p\u2082 \u2260 p\u2083) :\n  affine_independent \u211d ![p\u2081, p\u2082, p\u2083] :=\nbegin\n  refine hs.affine_independent _ _,\n  { simp [h\u2081, h\u2082, h\u2083, set.insert_subset] },\n  { erw [fin.cons_injective_iff, fin.cons_injective_iff],\n    simp [h\u2081\u2082, h\u2081\u2083, h\u2082\u2083, function.injective] }\nend\n\n/-- The three points of a cospherical set are affinely independent. -/\nlemma cospherical.affine_independent_of_ne {p\u2081 p\u2082 p\u2083 : P} (hs : cospherical ({p\u2081, p\u2082, p\u2083} : set P))\n  (h\u2081\u2082 : p\u2081 \u2260 p\u2082) (h\u2081\u2083 : p\u2081 \u2260 p\u2083) (h\u2082\u2083 : p\u2082 \u2260 p\u2083) :\n  affine_independent \u211d ![p\u2081, p\u2082, p\u2083] :=\nhs.affine_independent_of_mem_of_ne (set.mem_insert _ _)\n  (set.mem_insert_of_mem _ (set.mem_insert _ _))\n  (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_singleton _))) h\u2081\u2082 h\u2081\u2083 h\u2082\u2083\n\n/-- Suppose that `p\u2081` and `p\u2082` lie in spheres `s\u2081` and `s\u2082`.  Then the vector between the centers\nof those spheres is orthogonal to that between `p\u2081` and `p\u2082`; this is a version of\n`inner_vsub_vsub_of_dist_eq_of_dist_eq` for bundled spheres.  (In two dimensions, this says that\nthe diagonals of a kite are orthogonal.) -/\nlemma inner_vsub_vsub_of_mem_sphere_of_mem_sphere {p\u2081 p\u2082 : P} {s\u2081 s\u2082 : sphere P}\n  (hp\u2081s\u2081 : p\u2081 \u2208 s\u2081) (hp\u2082s\u2081 : p\u2082 \u2208 s\u2081) (hp\u2081s\u2082 : p\u2081 \u2208 s\u2082) (hp\u2082s\u2082 : p\u2082 \u2208 s\u2082) :\n  \u27eas\u2082.center -\u1d65 s\u2081.center, p\u2082 -\u1d65 p\u2081\u27eb = 0 :=\ninner_vsub_vsub_of_dist_eq_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere hp\u2081s\u2081 hp\u2082s\u2081)\n                                      (dist_center_eq_dist_center_of_mem_sphere hp\u2081s\u2082 hp\u2082s\u2082)\n\n/-- Two spheres intersect in at most two points in a two-dimensional subspace containing their\ncenters; this is a version of `eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two` for bundled\nspheres. -/\nlemma eq_of_mem_sphere_of_mem_sphere_of_mem_of_finrank_eq_two {s : affine_subspace \u211d P}\n  [finite_dimensional \u211d s.direction] (hd : finrank \u211d s.direction = 2) {s\u2081 s\u2082 : sphere P}\n  {p\u2081 p\u2082 p : P} (hs\u2081 : s\u2081.center \u2208 s) (hs\u2082 : s\u2082.center \u2208 s) (hp\u2081s : p\u2081 \u2208 s) (hp\u2082s : p\u2082 \u2208 s)\n  (hps : p \u2208 s) (hs : s\u2081 \u2260 s\u2082) (hp : p\u2081 \u2260 p\u2082) (hp\u2081s\u2081 : p\u2081 \u2208 s\u2081) (hp\u2082s\u2081 : p\u2082 \u2208 s\u2081) (hps\u2081 : p \u2208 s\u2081)\n  (hp\u2081s\u2082 : p\u2081 \u2208 s\u2082) (hp\u2082s\u2082 : p\u2082 \u2208 s\u2082) (hps\u2082 : p \u2208 s\u2082) : p = p\u2081 \u2228 p = p\u2082 :=\neq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd hs\u2081 hs\u2082 hp\u2081s hp\u2082s hps\n  ((sphere.center_ne_iff_ne_of_mem hps\u2081 hps\u2082).2 hs) hp hp\u2081s\u2081 hp\u2082s\u2081 hps\u2081 hp\u2081s\u2082 hp\u2082s\u2082 hps\u2082\n\n/-- Two spheres intersect in at most two points in two-dimensional space; this is a version of\n`eq_of_dist_eq_of_dist_eq_of_finrank_eq_two` for bundled spheres. -/\nlemma eq_of_mem_sphere_of_mem_sphere_of_finrank_eq_two [finite_dimensional \u211d V]\n  (hd : finrank \u211d V = 2) {s\u2081 s\u2082 : sphere P} {p\u2081 p\u2082 p : P} (hs : s\u2081 \u2260 s\u2082) (hp : p\u2081 \u2260 p\u2082)\n  (hp\u2081s\u2081 : p\u2081 \u2208 s\u2081) (hp\u2082s\u2081 : p\u2082 \u2208 s\u2081) (hps\u2081 : p \u2208 s\u2081) (hp\u2081s\u2082 : p\u2081 \u2208 s\u2082) (hp\u2082s\u2082 : p\u2082 \u2208 s\u2082)\n  (hps\u2082 : p \u2208 s\u2082) : p = p\u2081 \u2228 p = p\u2082 :=\neq_of_dist_eq_of_dist_eq_of_finrank_eq_two hd ((sphere.center_ne_iff_ne_of_mem hps\u2081 hps\u2082).2 hs)\n  hp hp\u2081s\u2081 hp\u2082s\u2081 hps\u2081 hp\u2081s\u2082 hp\u2082s\u2082 hps\u2082\n\n/-- Given a point on a sphere and a point not outside it, the inner product between the\ndifference of those points and the radius vector is positive unless the points are equal. -/\nlemma inner_pos_or_eq_of_dist_le_radius {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : dist p\u2082 s.center \u2264 s.radius) : 0 < \u27eap\u2081 -\u1d65 p\u2082, p\u2081 -\u1d65 s.center\u27eb \u2228 p\u2081 = p\u2082 :=\nbegin\n  by_cases h : p\u2081 = p\u2082, { exact or.inr h },\n  refine or.inl _,\n  rw mem_sphere at hp\u2081,\n  rw [\u2190vsub_sub_vsub_cancel_right p\u2081 p\u2082 s.center, inner_sub_left,\n      real_inner_self_eq_norm_mul_norm/-, \u2190dist_eq_norm_vsub, hp\u2081-/, sub_pos],\n  refine lt_of_le_of_ne\n    ((real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right _ (norm_nonneg _)))\n    _,\n  { rwa [\u2190dist_eq_norm_vsub, \u2190dist_eq_norm_vsub, hp\u2081] },\n  { rcases hp\u2082.lt_or_eq with hp\u2082' | hp\u2082',\n    { refine ((real_inner_le_norm _ _).trans_lt (mul_lt_mul_of_pos_right _ _)).ne,\n      { rwa [\u2190hp\u2081, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp\u2082' },\n      { rw [norm_pos_iff, vsub_ne_zero],\n        rintro rfl,\n        rw \u2190hp\u2081 at hp\u2082',\n        refine (dist_nonneg.not_lt : \u00acdist p\u2082 s.center < 0) _,\n        simpa using hp\u2082' } },\n    { rw [\u2190hp\u2081, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp\u2082',\n      nth_rewrite 0 \u2190hp\u2082',\n      rw [ne.def, inner_eq_norm_mul_iff_real, hp\u2082', \u2190sub_eq_zero, \u2190smul_sub,\n          vsub_sub_vsub_cancel_right, \u2190ne.def, smul_ne_zero_iff, vsub_ne_zero,\n          and_iff_left (ne.symm h), norm_ne_zero_iff, vsub_ne_zero],\n      rintro rfl,\n      refine h (eq.symm _),\n      simpa using hp\u2082' } }\nend\n\n/-- Given a point on a sphere and a point not outside it, the inner product between the\ndifference of those points and the radius vector is nonnegative. -/\nlemma inner_nonneg_of_dist_le_radius {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : dist p\u2082 s.center \u2264 s.radius) : 0 \u2264 \u27eap\u2081 -\u1d65 p\u2082, p\u2081 -\u1d65 s.center\u27eb :=\nbegin\n  rcases inner_pos_or_eq_of_dist_le_radius hp\u2081 hp\u2082 with h | rfl,\n  { exact h.le },\n  { simp }\nend\n\n/-- Given a point on a sphere and a point inside it, the inner product between the difference of\nthose points and the radius vector is positive. -/\nlemma inner_pos_of_dist_lt_radius {s : sphere P} {p\u2081 p\u2082 : P} (hp\u2081 : p\u2081 \u2208 s)\n  (hp\u2082 : dist p\u2082 s.center < s.radius) : 0 < \u27eap\u2081 -\u1d65 p\u2082, p\u2081 -\u1d65 s.center\u27eb :=\nbegin\n  by_cases h : p\u2081 = p\u2082,\n  { rw [h, mem_sphere] at hp\u2081,\n    exact false.elim (hp\u2082.ne hp\u2081) },\n  exact (inner_pos_or_eq_of_dist_le_radius hp\u2081 hp\u2082.le).resolve_right h\nend\n\n/-- Given three collinear points, two on a sphere and one not outside it, the one not outside it\nis weakly between the other two points. -/\nlemma wbtw_of_collinear_of_dist_center_le_radius {s : sphere P} {p\u2081 p\u2082 p\u2083 : P}\n  (h : collinear \u211d ({p\u2081, p\u2082, p\u2083} : set P)) (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : dist p\u2082 s.center \u2264 s.radius)\n  (hp\u2083 : p\u2083 \u2208 s) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) : wbtw \u211d p\u2081 p\u2082 p\u2083 :=\nh.wbtw_of_dist_eq_of_dist_le hp\u2081 hp\u2082 hp\u2083 hp\u2081p\u2083\n\n/-- Given three collinear points, two on a sphere and one inside it, the one inside it is\nstrictly between the other two points. -/\nlemma sbtw_of_collinear_of_dist_center_lt_radius {s : sphere P} {p\u2081 p\u2082 p\u2083 : P}\n  (h : collinear \u211d ({p\u2081, p\u2082, p\u2083} : set P)) (hp\u2081 : p\u2081 \u2208 s) (hp\u2082 : dist p\u2082 s.center < s.radius)\n  (hp\u2083 : p\u2083 \u2208 s) (hp\u2081p\u2083 : p\u2081 \u2260 p\u2083) : sbtw \u211d p\u2081 p\u2082 p\u2083 :=\nh.sbtw_of_dist_eq_of_dist_lt hp\u2081 hp\u2082 hp\u2083 hp\u2081p\u2083\n\nend euclidean_space\n\nend euclidean_geometry\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/geometry/euclidean/sphere/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7008258115421346}}
{"text": "import algebra.big_operators\nimport data.finset.slice\nimport data.rat\nimport tactic\n\nopen finset nat\nopen_locale big_operators \n\nnamespace finset\nnamespace bbsetpair2\n--Bollobas set pair theorem \n--A and B are the families of finite sets indexed by I\n--sp is the condition the family satisfies\n--spi is a shortcut for disjoint-ness  of A i and B i \n--U is the universe of elements in any of the sets \n-- it has size u\n@[ext] structure setpair :=\n  (A : \u2115 \u2192 finset \u2115) (B : \u2115 \u2192 finset \u2115) (I : finset \u2115)\n  (sp : \u2200i\u2208 I,\u2200j\u2208 I, ((A i)\u2229(B j)).nonempty \u2194 i \u2260 j)\n  (spi : \u2200i\u2208 I, disjoint (A i) (B i))\n  (U : finset \u2115) (Ug : U = I.bUnion(\u03bb i, (A i) \u222a (B i )))\n  (u : \u2115) (ug: u= card U)\n --- we take the trivial system with I=\u2205  \ninstance  : inhabited setpair :={\ndefault:= {A:=\u03bb _,\u2205, B:=\u03bb _,\u2205,I:=\u2205, \nsp:=begin tauto, end,\nspi:=begin tauto, end,\nU:=\u2205, Ug:=begin tauto, end,\nu:=0, ug:=begin tauto,end,}}\n-- density of a setpair system\n@[simp]def den (S : setpair) :\u211a := \u2211 i in S.I, ((1 : \u211a)/(card(S.A i)+card(S.B i)).choose (card (S.B i)))\n-- helper - if A i and B j are disjoint then i=j\nlemma sp' {S : setpair} {i j : \u2115}: i\u2208 S.I \u2192 j\u2208S.I \u2192 (disjoint (S.A i) (S.B j) \u2192 i = j):=\nbegin\n  intros hi hj hd, \n  by_contra,\n  have ne: ((S.A i)\u2229(S.B j)).nonempty,\n    apply (S.sp i hi j hj).mpr h,\n    rw disjoint_iff_inter_eq_empty at hd, \n    simp only [ * , not_nonempty_empty] at *,\nend\n\n-- the erase constructor - gives a new setpair without element x\n-- we discard all i such that B i contains x and then erase x from any A i containing x\n@[simp]def er  (S : setpair) (x : \u2115) : setpair :={\n  A:=\u03bb  n, erase (S.A n) x,\n  B:=S.B,\n  I:=S.I.filter(\u03bbi, x\u2209(S.B i)),\n  sp:=begin\n    intros i  hi j  hj,\n    rw [mem_filter] at *,\n    suffices same: ((S.A i).erase x \u2229 S.B j) = (S.A i) \u2229 (S.B j),{\n      rw same, exact S.sp i hi.1 j hj.1,}, cases hj, cases hi, dsimp at *,\n      ext1, simp only [mem_inter, mem_erase, ne.def, and.congr_left_iff, and_iff_right_iff_imp] at *,\n      intros m n p, cases p,solve_by_elim,\n  end,\n  U:= (S.I.filter(\u03bbi, x\u2209(S.B i))).bUnion(\u03bb i, (((S.A i).erase x) \u222a (S.B i ))),\n  Ug:=rfl,  \n  u:=card((S.I.filter(\u03bbi, x\u2209(S.B i))).bUnion(\u03bb i, (((S.A i).erase x) \u222a (S.B i )))),\n  ug:=rfl,\n  spi:=begin\n    intros i hi,\n    rw [mem_filter] at *,\n    apply disjoint_of_subset_left _ (S.spi i hi.1), apply erase_subset _,end,\n}\n\n--- the sets are in the universe...\nlemma univ_ss {S : setpair} {i : \u2115} : i \u2208 S.I \u2192 (S.A i \u222a S.B i)\u2286 S.U:=\nbegin\n  intro hi, intros x, rw [setpair.Ug,mem_bUnion],tauto,\nend\n-- applying er y gives a smaller universe if y was in the universe.\nlemma er_univ_lt (S : setpair) {y : \u2115} : y \u2208 S.U \u2192 (er S y).u < S.u :=\nbegin\n  intro hy,\n  have ss: (er S y).U \u2286 S.U,{\n    simp [er,S.Ug], intros i hi hy, intros x hx, rw [mem_bUnion], use i ,\n    split, exact hi, rw [mem_union] at *, cases hx with ha hb,\n    left, apply mem_of_mem_erase ha,right, exact hb,},\n  have ey: y\u2209 (er S y).U, {simp [er,S.Ug]},\n  simp [setpair.ug],\n  apply card_lt_card,\n  apply  (ssubset_iff_of_subset ss).mpr _, \n  use [y, hy, ey], \nend\n\n-- pairs are disjoint so sizes add.\nlemma card_pair {S : setpair} {i : \u2115} : i  \u2208 S.I \u2192 card((S.A i \u222a S.B i)) = card(S.A i) + card(S.B i):=\u03bb hi, card_union_eq (S.spi i hi)\n-- U is partitioned into each pair and their complement\nlemma card_U {S :setpair} {i : \u2115} : i \u2208 S.I \u2192 card(S.U\\(S.A i \u222a S.B i)) + card(S.A i) + card(S.B i) = card(S.U):=\nbegin\n  intros hi, rw [add_assoc, \u2190 card_pair hi],\n  apply card_sdiff_add_card_eq_card (univ_ss hi),\nend\n\nlemma card_Udiv (S :setpair) :\u2200i\u2208 S.I, ((card(S.A i) + card(S.B i)).choose (card(S.B i)):\u211a)\u207b\u00b9*(card S.U)=\n((card(S.A i) + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*((card(S.U\\(S.A i \u222a S.B i)) + card(S.A i) + card(S.B i))) :=\nbegin\n  intros i hi, rw \u2190 card_U hi, norm_cast,\nend\n\n\n--- want to work mainly with non-trivial setpairs so assume ever A i is non-empty\ndef triv_sp (S : setpair) : Prop := (\u2203i\u2208S.I, card(S.A i) =0) \n--- trivial sp has at most one pair.\nlemma triv_imp_I1 {S :setpair} (h: triv_sp S) : card S.I \u2264 1:=\nbegin\n  by_contra h', \n    obtain \u27e8a,ha,b,hb,ne\u27e9:=one_lt_card.mp (by linarith: 1< S.I.card),\n    obtain \u27e8x,hx\u27e9:=(S.sp a ha b hb).mpr ne,\n    obtain \u27e8i,h\u27e9:=h,\n    rw card_eq_zero at h,\n    cases h with hi hie,\n    rw mem_inter at hx,\n    have ia: i=a, {\n      apply sp' hi ha  _, rw hie, simp only [disjoint_empty_left],\n    },\n    have ib: i=b, {\n      apply sp' hi hb  _, rw hie, simp only [disjoint_empty_left],\n    },\n    rw [\u2190ia,\u2190ib] at ne, tauto,\nend\n\n\n-- non-trivial means each A i is non-empty so has at least one element\nlemma ntriv_sp {S : setpair} (ht: \u00actriv_sp S): \u2200i\u2208S.I, 1 \u2264 card(S.A i):=\nbegin\n  rw triv_sp at ht,push_neg at ht, intros i hi,  \n  exact one_le_iff_ne_zero.mpr  (ht i hi),\nend\n\n-- making the casting of the densities slightly less painful\nlemma binhelp {a b c d: \u2115 } (h: (a+b)*c=d*a) (hc: 0 < c) (hd: 0 < d): (\u2191d:\u211a)\u207b\u00b9*(a+b)=(\u2191c:\u211a)\u207b\u00b9*a:=\nbegin\n  have qh:((a:\u211a)+(b:\u211a))*(c:\u211a)=(d:\u211a)*(a:\u211a), norm_cast, exact h,\n  have dnz: (d:\u211a)\u2260 0,\n  { simp only [ne.def, cast_eq_zero],  linarith,  },\n  have cnz: (c:\u211a)\u2260 0,\n  { simp only [ne.def, cast_eq_zero],  linarith,  },\n   rw \u2190 div_eq_inv_mul,rw \u2190 div_eq_inv_mul, \n   rw div_eq_iff dnz, rw mul_comm, rw mul_div,\n    rw mul_comm,\n    symmetry,\n    rw  div_eq_iff cnz, symmetry, rw mul_comm (\u2191a), exact qh,\nend\n\n-- the key fact we need for binomials -- really should have done this in the nats.\nlemma binom_frac (a b : \u2115) (h:0 < a) :((a+b).choose(b):\u211a)\u207b\u00b9*(a+b)=((a-1+b).choose(b):\u211a)\u207b\u00b9*a:=\nbegin\n  have a1: a= (a -1).succ,{\n    rw succ_eq_add_one, linarith,},\n  have ab: a+b= (a-1+b).succ,{\n    rw [succ_eq_add_one, add_assoc,add_comm b 1,\u2190 add_assoc,\u2190succ_eq_add_one,\u2190 a1],},  \n  have ch: (a-1+b).succ* (a-1+b).choose (a-1)= (a-1+b).succ.choose((a-1).succ)*((a-1).succ),\n  apply succ_mul_choose_eq (a-1+b) (a-1),\n  rw [\u2190ab,\u2190 a1] at ch,\n  have abn: (a-1+b)-(a-1)=b:=add_tsub_cancel_left (a-1) b, \n  have abs : a+b-a=b:=add_tsub_cancel_left a b,\n  have aln: a-1 \u2264 a-1+b:=(by linarith),\n  have aln2: a\u2264 a+b:=(by linarith),\n  have f1:  (a-1+b).choose((a-1+b)-(a-1))=(a-1+b).choose(a-1):=choose_symm aln,\n  rw abn at f1,\n  have f2:  (a+b).choose(a+b-a)=(a+b).choose(a):=choose_symm aln2,\n  rw abs at f2,\n  rw [\u2190f1, \u2190 f2] at ch,\n -- clear_except ch,\n  rw [mul_comm],\n  norm_cast,\n  rw [mul_comm], simp [ch],\n  have ap :(a-1+b).choose b > 0,{\n    apply choose_pos (by linarith: b\u2264 a-1+b),\n  },\n  have bp:(a+b).choose b >0,{\n    apply choose_pos (by linarith:b\u2264a+b),},\n  apply binhelp ch ap bp, \nend\n\nlemma den_rhs_1   {S : setpair} : \u2211 i in S.I, ((card(S.A i) + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*card(S.U\\(S.A i \u222a S.B i)) +\n\u2211 i in S.I, ((card(S.A i) + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*(card(S.A i) + card(S.B i))\n= den S * S.u :=\nbegin\n  simp only [den, one_div], rw [setpair.ug],rw sum_mul, rw \u2190 sum_add_distrib,\n  apply sum_congr _ _, refl,\n  intros i hi, rw \u2190 mul_add, norm_cast, rw \u2190 add_assoc, \n  convert card_Udiv S i hi, exact card_U hi, norm_cast, exact (card_U hi).symm,\nend\n\nlemma den_rhs_2   {S : setpair} (ht: \u00actriv_sp S) : \u2211 i in S.I, ((card(S.A i) + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*(card(S.A i) + card(S.B i)) =\n\u2211 i in S.I, ((card(S.A i)-1 + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*(card(S.A i))\n :=\nbegin\n  apply sum_congr _ _, refl, \n  intros i hi, rw binom_frac _ _ ((ntriv_sp ht) i hi),\nend\n\nlemma den_help_1 {S : setpair}  : \u2200i, \u2200y\u2208(S.U\\((S.A i)\u222a(S.B i))), (S.A i).card +(S.B i).card = ((S.A i).erase y).card + (S.B i).card:=\nbegin\n  intros i  y hy, simp only [add_left_inj], rw card_erase_eq_ite,split_ifs,\n  simp only [*, mem_sdiff, mem_union, true_or, not_true, and_false] at *,\nend\n\nlemma den_help_2 {S : setpair}  : \u2200i, \u2200y\u2208(S.A i), (S.A i).card - 1 +(S.B i).card = ((S.A i).erase y).card + (S.B i).card:=\nbegin\n  intros i  y hy, simp only [add_left_inj], rw card_erase_of_mem hy,\nend\n\nlemma den_rhs_3 {S : setpair}  : \u2200 i\u2208S.I , ((card(S.A i) + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*(card(S.U\\((S.A i)\u222a(S.B i)))) =\n\u2211y in (S.U\\((S.A i)\u222a(S.B i))), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9:=\nbegin\n  intros i hi, rw card_eq_sum_ones (S.U\\((S.A i)\u222a(S.B i))),\n  push_cast, rw zero_add, rw mul_sum, rw mul_one, \n  rw sum_congr _ _, refl,\n  intros y hy,rw (den_help_1  i  y hy),\nend\n\n\nlemma den_rhs_4 {S : setpair}  : \u2200 i\u2208S.I , ((card(S.A i) - 1 + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*(card(S.A i)) =\n\u2211y in (S.A i), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9:=\nbegin\n  intros i hi, nth_rewrite 1  card_eq_sum_ones (S.A i),\n  push_cast, rw zero_add, rw mul_sum, rw mul_one, \n  rw sum_congr _ _, refl,\n  intros y hy,rw (den_help_2  i y hy),\nend\n\nlemma den_rhs_5 {S : setpair}  : \u2211 i in S.I , ((card(S.A i) + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*(card(S.U\\((S.A i)\u222a(S.B i)))) =\n \u2211 i in S.I, (\u2211y in (S.U\\((S.A i)\u222a(S.B i))), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9):=\nbegin\n  apply  sum_congr (rfl) (den_rhs_3),\nend\n\nlemma den_rhs_6 {S : setpair} : \u2211 i in S.I, ((card(S.A i) - 1 + card(S.B i)).choose (card (S.B i)):\u211a)\u207b\u00b9*(card(S.A i)) =\n\u2211 i in S.I, (\u2211y in (S.A i), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9):=\nbegin\n  apply  sum_congr (rfl) (den_rhs_4),\nend\n\n\nlemma disj_den {S : setpair}  : \u2200i, disjoint (S.U\\((S.A i)\u222a(S.B i))) (S.A i):=\nbegin\n  intros i, \n  apply disjoint_of_subset_right (subset_union_left (S.A i) (S.B i)), \n  exact sdiff_disjoint,\nend\n\n\nlemma sp_sdiff (S : setpair) : \u2200i\u2208S.I, (S.U\\((S.A i)\u222a(S.B i)))\u222a (S.A i) = (S.U\\(S.B i)) :=\nbegin\n  intros i hi,\n  have he: (S.A i)\u222a (S.B i)\u2286 S.U:=univ_ss hi,\n  have heA: (S.A i)\u2286 S.U:=subset_trans (subset_union_left (S.A i) (S.B i)) he,\n  have ab: disjoint (S.A i) (S.B i):=S.spi i hi,  \n  rw sdiff_union_distrib, ext x,split, simp only [mem_union, mem_inter, mem_sdiff] at *,\n  intro h, \n  rcases h, exact h.2, split, exact heA h, intro hb,\n  exact  ab (mem_inter.mpr \u27e8h,hb\u27e9),\n  intros h, rw [mem_union,mem_inter,mem_sdiff],\n  by_cases hA: x\u2208 (S.A i) ,\n    right, exact hA, left,split, simp only [*, mem_sdiff, not_false_iff, and_self] at *, exact h,\nend\n\nlemma den_rhs_7 {S : setpair} : \u2200i\u2208 S.I, (\u2211y in (S.U\\((S.A i)\u222a(S.B i))), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9)\n+(\u2211y in (S.A i), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9)=(\u2211y in (S.U\\(S.B i)), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9)\n:=\nbegin\n  intros i hi, rw [\u2190 sp_sdiff S i hi, sum_union (disj_den i )],\nend\n\nlemma den_rhs_8 {S : setpair}  : \u2211 i in S.I, ((\u2211y in (S.U\\((S.A i)\u222a(S.B i))), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9)\n+(\u2211y in (S.A i), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9))=\u2211 i in S.I,(\u2211y in (S.U\\(S.B i)), ((((S.A i).erase y).card + card(S.B i)).choose ((S.B i).card):\u211a)\u207b\u00b9)\n:=\nbegin\n   apply sum_congr (rfl) (den_rhs_7),\nend\n\n\n\nlemma doublecount {A B : finset \u2115} {f: \u2115 \u2192 \u2115 \u2192 \u211a}  {p: \u2115 \u2192 \u2115 \u2192 Prop} [decidable_rel p] :\n \u2211 a in A, \u2211 b in filter (\u03bb i , p a i) B, f a b = \u2211 b in B, \u2211 a in filter (\u03bb i, p i b) A, f a b:=\nbegin\n  have inL: \u2200a\u2208A,\u2211 b in filter (\u03bb i, p a i) B, (f a b)= \u2211 b in B, ite (p a b) (f a b) 0,{\n      intros a ha, rw sum_filter,},\n  have inL2: \u2211a in A, \u2211 b in filter (\u03bb i, p a i) B, (f a b)= \u2211 a in A, \u2211 b in B, ite (p a b) (f a b) 0, {\n      apply sum_congr, refl, exact inL,},\n  have inR: \u2200b\u2208B,\u2211 a in filter (\u03bb i, p i b) A, (f a b)= \u2211 a in A, ite (p a b) (f a b) 0,{\n    intros b hb, rw sum_filter,},\n  have inR2: \u2211b in B, \u2211 a in filter (\u03bb i, p i b) A, (f a b)= \u2211 b in B, \u2211 a in A, ite (p a b) (f a b) 0, {\n      apply sum_congr, refl, exact inR,},\n  rw [inL2,inR2,sum_comm],\nend\n\nlemma doublecount' {A B : finset \u2115} {f g: \u2115 \u2192 \u2115 \u2192 \u211a} {a b : \u2115} {p: \u2115 \u2192 \u2115 \u2192 Prop} [decidable_rel p] : (\u2200a\u2208 A,\u2200b\u2208B , p a b \u2192 f a b = g a b)\n \u2192 \u2211 a in A, \u2211 b in filter (\u03bb i , p a i) B, f a b = \u2211 b in B, \u2211 a in filter (\u03bb i, p i b) A, g a b:=\nbegin\n  intros h, rw doublecount, apply sum_congr, refl, intros b hb, apply sum_congr, refl,\n  intro x, rw mem_filter, intro ha, exact h x ha.1 b hb ha.2,\nend\n\n\n\nlemma dc_4 {S : setpair} {f: \u2115 \u2192 \u2115 \u2192 \u211a} : \u2211 i in S.I, \u2211 y in S.U\\(S.B i), f y i = \u2211 i in S.I, \u2211 y in filter (\u03bb x, x\u2209(S.B i)) S.U, f y i:=\nbegin\n  have H: \u2200 i\u2208S.I, S.U\\S.B i = filter (\u03bb x, x\u2209 S.B i) S.U,{\n    intros i hi, ext x,rw [mem_sdiff,mem_filter],},\n  have H1: \u2200 i\u2208S.I,\u2211 y in S.U\\(S.B i), f y i =  \u2211 y in filter (\u03bb x, x\u2209(S.B i)) S.U, f y i,{\n    intros i hi, apply sum_congr , exact H i hi, intros x hx,refl,},\n    apply sum_congr, refl,exact H1,  \nend\n\nlemma den_double {S : setpair} (ht: \u00actriv_sp S) : (\u2211  y in S.U, den (er S y))= den S * S.u  := \nbegin\n  rw \u2190 den_rhs_1,  simp only [den, er, one_div],\n  rw [den_rhs_2 ht, den_rhs_5 , den_rhs_6 , \u2190  sum_add_distrib],\n  rw [den_rhs_8,dc_4,doublecount],\nend\n\nlemma trival_mem {S : setpair} (h: \u2203i\u2208S.I, (S.A i) = \u2205) : card S.I \u2264 1 :=\nbegin\n  by_contra h', \n  obtain \u27e8a,ha,b,hb,ne\u27e9:=one_lt_card.mp (by linarith: 1< S.I.card),\n  obtain \u27e8x,hx\u27e9:=(S.sp a ha b hb).mpr ne,\n  obtain \u27e8i, hi, inem\u27e9:=h,\n  rw mem_inter at hx, \n  have ha' : disjoint (S.A i) (S.B a),\n    rw inem, simp only [disjoint_empty_left],\n  have hb' : disjoint (S.A i) (S.B b),\n    rw inem, simp only [disjoint_empty_left],\n  have ia: i=a:=sp'  hi ha ha', \n  have ib: i=b:=sp'  hi hb hb', \n  rw ia at ib, tauto, \nend\n\nlemma trival_univ {S : setpair} (h: S.u = 0) : card S.I \u2264 1 :=\nbegin\n  by_contra h', \n  obtain \u27e8a,ha,b,hb,ne\u27e9:=one_lt_card.mp (by linarith: 1< S.I.card),\n  obtain \u27e8x,hx\u27e9:=(S.sp a ha b hb).mpr ne,\n  have xinU: x\u2208 S.U,{\n    simp only [mem_inter, setpair.Ug, mem_bUnion, mem_union, exists_prop, not_le, _root_.ne.def] at *,\n    use [a,ha,hx.1], },\n  rw [setpair.ug,card_eq_zero] at h, \n  have :S.U.nonempty:=\u27e8x,xinU\u27e9,   \n    rw h at this, apply not_nonempty_empty this,\nend\n\n\nlemma den_triv {S : setpair} (h: triv_sp S) :den S\u2264 1:=\nbegin\n  have I1: card(S.I) \u2264 1:=triv_imp_I1 h,\n  have Ic: card S.I \u2208 Icc 0 1, {\n  simp only [mem_Icc, zero_le, true_and,I1],},\n  fin_cases Ic,\n  {-- empty sum is zero\n    have : den S =0,{\n    rw card_eq_zero at Ic, rw [den, Ic],\n    apply sum_empty,\n    },linarith,\n  },\n  {--- only have I={a} so sum over singleton\n    rw card_eq_one at Ic, rw [den],\n    cases Ic with a ha, rw ha,\n    rw sum_singleton, \n    set d:=((S.A a).card + (S.B a).card).choose ((S.B a).card),\n    have nch: 0< d :=choose_pos (le_add_self),\n    have d1: 1 \u2264 d:= by linarith, \n    clear_except d1,\n    rw one_div, apply inv_le_one _, rwa one_le_cast,\n  },  \nend\n\n\nlemma emp_U_den {S : setpair} (h: S.u = 0): den S \u2264 1 :=\nbegin\n  have Ic: card S.I \u2208 Icc 0 1, {\n  simp only [mem_Icc, zero_le, true_and, trival_univ h],},\n  fin_cases Ic,\n  {-- empty sum is zero\n    have : den S =0,{\n    rw card_eq_zero at Ic, rw [den, Ic],\n    apply sum_empty,\n    },linarith,\n  },\n  {--- only have I={a} so sum over singleton\n    rw card_eq_one at Ic, rw [den],\n    cases Ic with a ha, rw ha,\n    rw sum_singleton, \n    set d:=((S.A a).card + (S.B a).card).choose ((S.B a).card),\n    have nch: 0< d :=choose_pos (le_add_self),\n    have d1: 1 \u2264 d:= by linarith, \n    clear_except d1,\n    rw one_div, apply inv_le_one _, rwa one_le_cast,\n  },  \nend\n\ntheorem bollobas_sp {S : setpair} {n : \u2115}: S.u=n \u2192  den S \u2264 1 :=\nbegin\n  revert S,\n  --- should really do induction on S.wA so n= 0 \u2192 I.nonempty \u2192 (\u2203i\u2208S.I, (S.A i) = \u2205) \n  induction n using nat.strong_induction_on with n hn,\n  intros S hs,\n  cases nat.eq_zero_or_pos n with Uem,\n  {rw \u2190 hs at Uem, exact emp_U_den Uem,},\n   by_cases ht: triv_sp S,\n   {--- do case where there is an empty set in A or no sets at all!\n    exact den_triv ht, },\n  { rw \u2190 hs at h,\n    apply (mul_le_iff_le_one_left (cast_pos.mpr h)).mp, \n    have e: (\u2211  y in S.U, den (er S y)) = den S * S.u,{\n      exact den_double ht,},\n    rw \u2190 e,\n    have dc: \u2200y\u2208 S.U, (er S y).u< S.u,{\n      intros y hy, exact er_univ_lt S hy,},\n    have dd: \u2200y\u2208 S.U, den(er S y)\u2264 (1:\u211a),{\n      intros y hy, rw hs at dc,\n      apply  hn ((er S y).u) (dc y hy),refl,},\n  { rw setpair.ug,\n    rw card_eq_sum_ones, \n    convert sum_le_sum dd, norm_cast,},\n    exact rat.nontrivial, },\nend\n\n\n\n\n\ntheorem bollobas_sp' {S : setpair} : den S \u2264 1 :=\nbegin\n  set n:\u2115:=S.u with h, exact bollobas_sp h,\nend\nend bbsetpair2\nend finset\n\n", "meta": {"author": "jt496", "repo": "setpair", "sha": "ebd080cfca6b09fdf87d7bc7cbc58c4ef27d2512", "save_path": "github-repos/lean/jt496-setpair", "path": "github-repos/lean/jt496-setpair/setpair-ebd080cfca6b09fdf87d7bc7cbc58c4ef27d2512/src/sp2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7008133285378771}}
{"text": "import tuto_lib\n/-\nThis file continues the elementary study of limits of sequences. \nIt can be skipped if the previous file was too easy, it won't introduce\nany new tactic or trick.\n\nRemember useful lemmas:\n\nabs_le {x y : \u211d} : |x| \u2264 y \u2194 -y \u2264 x \u2227 x \u2264 y\n\nabs_add (x y : \u211d) : |x + y| \u2264 |x| + |y|\n\nabs_sub_comm (x y : \u211d) : |x - y| = |y - x|\n\nge_max_iff (p q r) : r \u2265 max p q  \u2194 r \u2265 p \u2227 r \u2265 q\n\nle_max_left p q : p \u2264 max p q\n\nle_max_right p q : q \u2264 max p q\n\nand the definition:\n\ndef seq_limit (u : \u2115 \u2192 \u211d) (l : \u211d) : Prop :=\n\u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - l| \u2264 \u03b5\n\nYou can also use a property proved in the previous file:\n\nunique_limit : seq_limit u l \u2192 seq_limit u l' \u2192 l = l'\n\ndef extraction (\u03c6 : \u2115 \u2192 \u2115) := \u2200 n m, n < m \u2192 \u03c6 n < \u03c6 m\n-/\n\n\nvariable { \u03c6 : \u2115 \u2192 \u2115}\n\n/-\nThe next lemma is proved by an easy induction, but we haven't seen induction\nin this tutorial. If you did the natural number game then you can delete \nthe proof below and try to reconstruct it.\n-/\n/-- An extraction is greater than id -/\nlemma id_le_extraction' : extraction \u03c6 \u2192 \u2200 n, n \u2264 \u03c6 n :=\nbegin\n  intros hyp n,\n  induction n with n hn,\n  { exact nat.zero_le _ },\n  { exact nat.succ_le_of_lt (by linarith [hyp n (n+1) (by linarith)]) },\nend\n\n/-- Extractions take arbitrarily large values for arbitrarily large \ninputs. -/\n-- 0039\nlemma extraction_ge : extraction \u03c6 \u2192 \u2200 N N', \u2203 n \u2265 N', \u03c6 n \u2265 N :=\nbegin\n  sorry\nend\n\n/-- A real number `a` is a cluster point of a sequence `u` \nif `u` has a subsequence converging to `a`. \n\ndef cluster_point (u : \u2115 \u2192 \u211d) (a : \u211d) :=\n\u2203 \u03c6, extraction \u03c6 \u2227 seq_limit (u \u2218 \u03c6) a\n-/\n\nvariables {u : \u2115 \u2192 \u211d} {a l : \u211d}\n\n/-\nIn the exercise, we use `\u2203 n \u2265 N, ...` which is the abbreviation of\n`\u2203 n, n \u2265 N \u2227 ...`.\nLean can read this abbreviation, but displays it as the confusing:\n`\u2203 (n : \u2115) (H : n \u2265 N)`\nOne gets used to it. Alternatively, one can get rid of it using the lemma\n  exists_prop {p q : Prop} : (\u2203 (h : p), q) \u2194 p \u2227 q\n-/\n\n/-- If `a` is a cluster point of `u` then there are values of\n`u` arbitrarily close to `a` for arbitrarily large input. -/\n-- 0040\nlemma near_cluster :\n  cluster_point u a \u2192 \u2200 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |u n - a| \u2264 \u03b5 :=\nbegin\n  sorry\nend\n\n/-\nThe above exercice can be done in five lines. \nHint: you can use the anonymous constructor syntax when proving\nexistential statements.\n-/\n\n/-- If `u` tends to `l` then its subsequences tend to `l`. -/\n-- 0041\nlemma subseq_tendsto_of_tendsto' (h : seq_limit u l) (h\u03c6 : extraction \u03c6) :\nseq_limit (u \u2218 \u03c6) l :=\nbegin\n  sorry\nend\n\n/-- If `u` tends to `l` all its cluster points are equal to `l`. -/\n-- 0042\nlemma cluster_limit (hl : seq_limit u l) (ha : cluster_point u a) : a = l :=\nbegin\n  sorry\nend\n\n/-- Cauchy_sequence sequence -/\ndef cauchy_sequence (u : \u2115 \u2192 \u211d) := \u2200 \u03b5 > 0, \u2203 N, \u2200 p q, p \u2265 N \u2192 q \u2265 N \u2192 |u p - u q| \u2264 \u03b5\n\n-- 0043\nexample : (\u2203 l, seq_limit u l) \u2192 cauchy_sequence u :=\nbegin\n  sorry\nend\n\n\n/- \nIn the next exercise, you can reuse\n near_cluster : cluster_point u a \u2192 \u2200 \u03b5 > 0, \u2200 N, \u2203 n \u2265 N, |u n - a| \u2264 \u03b5\n-/\n-- 0044\nexample (hu : cauchy_sequence u) (hl : cluster_point u l) : seq_limit u l :=\nbegin\n  sorry\nend\n\n", "meta": {"author": "leanprover-community", "repo": "tutorials", "sha": "79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1", "save_path": "github-repos/lean/leanprover-community-tutorials", "path": "github-repos/lean/leanprover-community-tutorials/tutorials-79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1/src/exercises/06_sub_sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7008133160900328}}
{"text": "/-\nCopyright (c) 2023 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Kevin Buzzard\n-/\n\nimport tactic -- imports all the Lean tactics\nimport measure_theory.measurable_space\n\n/-\n\n# Measure theory\n\n## Sigma algebras.\n\nA \u03c3-algebra on a type `X` is a collection of subsets of `X` satisfying some\naxioms, and in Lean you write it like this:\n\n-/\n\n-- let X be a set\nvariable (X : Type)\n-- ...and let \ud835\udcd0 be a sigma-algebra on X\nvariable (\ud835\udcd0 : measurable_space X)\n\n/-\n\nNote that `measurable_space` is a *class*, so really we should be writing `[measurable_space X]`,\nmeaning \"let `X` be equipped once and for all with a sigma algebra which we won't give a name to\".\nBut in this sheet we'll consider making them explicitly.\n\nLet's do the following exercise. Show that if `A` is a subset of `X` then `{0,A,A\u1d9c,X}`\nis a sigma algebra on `X`.\n\n-/\n\ndef gen_by (A : set X) : measurable_space X :=\n{ measurable_set' := \u03bb S, S = \u2205 \u2228 S = A \u2228 S = A\u1d9c \u2228 S = \u22a4,\n  measurable_set_empty := begin\n    sorry,\n  end,\n  measurable_set_compl := begin\n    sorry,\n  end,\n  measurable_set_Union := begin\n    sorry,\n  end }\n\n-- An alternative approach to defining the sigma algebra generated by `{A}` is just\n-- to use `measurable_space.generate_from`:\n\nexample (A : set X) : measurable_space X := measurable_space.generate_from {A}\n\n-- But the problem with that approach is that you don't get the actual sets\n-- in the sigma algebra for free. Try this, to see what I mean!\nexample (A : set X) : (measurable_space.generate_from {A}).measurable_set' = ({\u2205,A,A\u1d9c,\u22a4} : set (set X)) := \nbegin\n  sorry,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "formalising-mathematics-2023", "sha": "982f6d28a900f2e04e93e7cf298db4f5998be0d5", "save_path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023", "path": "github-repos/lean/ImperialCollegeLondon-formalising-mathematics-2023/formalising-mathematics-2023-982f6d28a900f2e04e93e7cf298db4f5998be0d5/src/section12measure_theory/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7007703018250047}}
{"text": "import Std\n\ninductive Expr where\n  | var (i : Nat)\n  | op  (lhs rhs : Expr)\n  deriving Inhabited, Repr\n\ndef List.getIdx : List \u03b1 \u2192 Nat \u2192 \u03b1 \u2192 \u03b1\n  | [],    i,   u => u\n  | a::as, 0,   u => a\n  | a::as, i+1, u => getIdx as i u\n\nstructure Context (\u03b1 : Type u) where\n  op    : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n  unit  : \u03b1\n  assoc : (a b c : \u03b1) \u2192 op (op a b) c = op a (op b c)\n  comm  : (a b : \u03b1) \u2192 op a b = op b a\n  vars  : List \u03b1\n\ntheorem Context.left_comm (ctx : Context \u03b1) (a b c : \u03b1) : ctx.op a (ctx.op b c) = ctx.op b (ctx.op a c) := by\n  rw [\u2190 ctx.assoc, ctx.comm a b, ctx.assoc]\n\ndef Expr.denote (ctx : Context \u03b1) : Expr \u2192 \u03b1\n  | Expr.op a b => ctx.op (denote ctx a) (denote ctx b)\n  | Expr.var i  => ctx.vars.getIdx i ctx.unit\n\ntheorem Expr.denote_op (ctx : Context \u03b1) (a b : Expr) : denote ctx (Expr.op a b) = ctx.op (denote ctx a) (denote ctx b) :=\n  rfl\n\ndef Expr.concat : Expr \u2192 Expr \u2192 Expr\n  | Expr.op a b, c => Expr.op a (concat b c)\n  | Expr.var i, c  => Expr.op (Expr.var i) c\n\ntheorem Expr.denote_concat (ctx : Context \u03b1) (a b : Expr) : denote ctx (concat a b) = denote ctx (Expr.op a b) := by\n  induction a with\n  | var i => rfl\n  | op _ _ _ ih => simp [denote, ih, ctx.assoc]\n\ndef Expr.flat : Expr \u2192 Expr\n  | Expr.op a b => concat (flat a) (flat b)\n  | Expr.var i  => Expr.var i\n\ntheorem Expr.denote_flat (ctx : Context \u03b1) (e : Expr) : denote ctx (flat e) = denote ctx e := by\n  induction e with\n  | var i => rfl\n  | op a b ih\u2081 ih\u2082 => simp [flat, denote, denote_concat, ih\u2081, ih\u2082]\n\ntheorem Expr.eq_of_flat (ctx : Context \u03b1) (a b : Expr) (h : flat a = flat b) : denote ctx a = denote ctx b := by\n  have h := congrArg (denote ctx) h\n  simp [denote_flat] at h\n  assumption\n\ndef Expr.length : Expr \u2192 Nat\n  | op a b => 1 + b.length\n  | _      => 1\n\ndef Expr.sort (e : Expr) : Expr :=\n  loop e.length e\nwhere\n  loop : Nat \u2192 Expr \u2192 Expr\n    | fuel+1, Expr.op a e =>\n      let (e\u2081, e\u2082) := swap a e\n      Expr.op e\u2081 (loop fuel e\u2082)\n    | _, e => e\n\n  swap : Expr \u2192 Expr \u2192 Expr \u00d7 Expr\n    | Expr.var i, Expr.op (Expr.var j) e =>\n      if i > j then\n        let (e\u2081, e\u2082) := swap (Expr.var j) e\n        (e\u2081, Expr.op (Expr.var i) e\u2082)\n      else\n        let (e\u2081, e\u2082) := swap (Expr.var i) e\n        (e\u2081, Expr.op (Expr.var j) e\u2082)\n    | Expr.var i, Expr.var j =>\n      if i > j then\n        (Expr.var j, Expr.var i)\n      else\n        (Expr.var i, Expr.var j)\n    | e\u2081, e\u2082 => (e\u2081, e\u2082)\n\ntheorem Expr.denote_sort (ctx : Context \u03b1) (e : Expr) : denote ctx (sort e) = denote ctx e := by\n  apply denote_loop\nwhere\n  denote_loop (n : Nat) (e : Expr) : denote ctx (sort.loop n e) = denote ctx e := by\n    induction n generalizing e with\n    | zero => rfl\n    | succ n ih =>\n      match e with\n      | var _  => rfl\n      | op a b =>\n        simp [denote, sort.loop]\n        match h:sort.swap a b with\n        | (r\u2081, r\u2082) =>\n          have hs := denote_swap a b\n          rw [h] at hs\n          simp [denote] at hs\n          simp [denote, ih]\n          assumption\n\n  denote_swap (e\u2081 e\u2082 : Expr) : denote ctx (Expr.op (sort.swap e\u2081 e\u2082).1 (sort.swap e\u2081 e\u2082).2) = denote ctx (Expr.op e\u2081 e\u2082) := by\n    induction e\u2082 generalizing e\u2081 with\n    | op a b ih' ih =>\n      clear ih'\n      cases e\u2081 with\n      | var i =>\n        cases a with\n        | var j =>\n          byCases h : i > j\n          focus\n            simp [sort.swap, h]\n            match h:sort.swap (var j) b with\n            | (r\u2081, r\u2082) => simp; rw [denote_op (a := var i), \u2190 ih]; simp [h, denote]; rw [Context.left_comm]\n          focus\n            simp [sort.swap, h]\n            match h:sort.swap (var i) b with\n            | (r\u2081, r\u2082) =>\n              simp\n              rw [denote_op (a := var i), denote_op (a := var j), Context.left_comm, \u2190 denote_op (a := var i), \u2190 ih]\n              simp [h, denote]\n              rw [Context.left_comm]\n        | _ => rfl\n      | _ => rfl\n    | var j =>\n      cases e\u2081 with\n      | var i =>\n        byCases h : i > j\n        focus simp [sort.swap, h, denote, Context.comm]\n        focus simp [sort.swap, h]\n      | _ => rfl\n\ntheorem Expr.eq_of_sort_flat (ctx : Context \u03b1) (a b : Expr) (h : sort (flat a) = sort (flat b)) : denote ctx a = denote ctx b := by\n  have h := congrArg (denote ctx) h\n  simp [denote_flat, denote_sort] at h\n  assumption\n\ntheorem ex\u2081 (x\u2081 x\u2082 x\u2083 x\u2084 : Nat) : (x\u2081 + x\u2082) + (x\u2083 + x\u2084) = x\u2081 + x\u2082 + x\u2083 + x\u2084 :=\n  Expr.eq_of_flat\n    { op    := Nat.add\n      assoc := Nat.add_assoc\n      comm  := Nat.add_comm\n      unit  := Nat.zero\n      vars  := [x\u2081, x\u2082, x\u2083, x\u2084] }\n    (Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.op (Expr.var 2) (Expr.var 3)))\n    (Expr.op (Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.var 2)) (Expr.var 3))\n    rfl\n\ntheorem ex\u2082 (x\u2081 x\u2082 x\u2083 x\u2084 : Nat) : (x\u2081 + x\u2082) + (x\u2083 + x\u2084) = x\u2083 + x\u2081 + x\u2082 + x\u2084 :=\n  Expr.eq_of_sort_flat\n    { op    := Nat.add\n      assoc := Nat.add_assoc\n      comm  := Nat.add_comm\n      unit  := Nat.zero\n      vars  := [x\u2081, x\u2082, x\u2083, x\u2084] }\n    (Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.op (Expr.var 2) (Expr.var 3)))\n    (Expr.op (Expr.op (Expr.op (Expr.var 2) (Expr.var 0)) (Expr.var 1)) (Expr.var 3))\n    rfl\n\n#print ex\u2082\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/ac_expr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7007688809467845}}
{"text": "import M4R.Set.Basic\nimport M4R.Set.Finite.Pairwise\n\nnamespace M4R\n\n  inductive Perm : List \u03b1 \u2192 List \u03b1 \u2192 Prop\n  | nil                           : Perm [] []\n  | cons (x : \u03b1) {l\u2081 l\u2082 : List \u03b1} : Perm l\u2081 l\u2082 \u2192 Perm (x::l\u2081) (x::l\u2082)\n  | swap (x y : \u03b1) (l : List \u03b1)   : Perm (y::x::l) (x::y::l)\n  | trans {l\u2081 l\u2082 l\u2083 : List \u03b1}     : Perm l\u2081 l\u2082 \u2192 Perm l\u2082 l\u2083 \u2192 Perm l\u2081 l\u2083\n\n  infix:50 \" ~ \" => Perm\n\n  namespace Perm\n\n    @[simp] protected theorem refl : \u2200 (x : List \u03b1), x ~ x\n    | []      => Perm.nil\n    | (x::xl) => (Perm.refl xl).cons x\n\n    protected theorem symm {x y : List \u03b1} (h : x ~ y) : y ~ x :=\n      @Perm.recOn \u03b1 (fun (a b : List \u03b1) _ => b ~ a) x y h\n        Perm.nil\n        (fun x _ _ _ r\u2081 => r\u2081.cons x)\n        (fun x y l => swap y x l)\n        (fun _ _ p\u2082\u2081 p\u2083\u2082 => p\u2083\u2082.trans p\u2082\u2081)\n\n    instance PermEquivalence : Equivalence (@Perm \u03b1) where\n      refl  := Perm.refl\n      symm  := Perm.symm\n      trans := Perm.trans\n\n    instance PermSetoid (\u03b1 : Type _) : Setoid (List \u03b1) where\n      r := Perm\n      iseqv := PermEquivalence\n\n    theorem subset {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 \u2286 l\u2082 :=\n      fun x => @Perm.recOn \u03b1 (fun (a b : List \u03b1) _ => x \u2208 a \u2192 x \u2208 b) l\u2081 l\u2082 p id\n          (fun y a b _ xab xya => Or.elim xya\n            (fun exy => Or.inl exy)\n            (fun xa => Or.inr (xab xa)))\n          (fun y z a xzya => Or.elim xzya\n              (fun exz => Or.inr (Or.inl exz))\n              (fun xya => Or.elim xya\n                  (fun exy => Or.inl exy)\n                  (fun xa => Or.inr (Or.inr xa))))\n          (fun _ _ x\u2081\u2082 x\u2082\u2083 x\u2081 => x\u2082\u2083 (x\u2081\u2082 x\u2081))\n\n    theorem mem_iff {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) (a : \u03b1) : a \u2208 l\u2081 \u2194 a \u2208 l\u2082 :=\n      Iff.intro (fun x => p.subset x) (fun x => p.symm.subset x)\n\n    theorem append_right {l\u2081 l\u2082 : List \u03b1} (t : List \u03b1) (p : l\u2081 ~ l\u2082) : l\u2081++t ~ l\u2082++t :=\n      @Perm.recOn \u03b1 (fun a b pab => a++t ~ b++t) _ _ p\n        (Perm.refl ([] ++ t))\n        (fun x _ _ _ r\u2081 => r\u2081.cons x)\n        (fun x y _ => swap x y _)\n        (fun _ _ r\u2081 r\u2082 => r\u2081.trans r\u2082)\n\n    theorem append_left {t\u2081 t\u2082 : List \u03b1} (l : List \u03b1) (p : t\u2081 ~ t\u2082) : l++t\u2081 ~ l++t\u2082 :=\n      match l with\n      | [] => p\n      | x::xs => (append_left xs p).cons x\n\n    theorem append {l\u2081 l\u2082 t\u2081 t\u2082 : List \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081++t\u2081 ~ l\u2082++t\u2082 :=\n      (p\u2081.append_right t\u2081).trans (p\u2082.append_left l\u2082)\n\n    theorem middle (a : \u03b1) : \u2200 (l\u2081 l\u2082 : List \u03b1), l\u2081++a::l\u2082 ~ a::(l\u2081++l\u2082)\n    | []     , l\u2082 => Perm.refl _\n    | (b::l\u2081), l\u2082 => ((@middle \u03b1 a l\u2081 l\u2082).cons b).trans (swap a b _)\n\n    theorem append_singleton (a : \u03b1) (l : List \u03b1) : l ++ [a] ~ a::l := by\n      have := middle a l []\n      rw [List.append_nil] at this\n      exact this\n\n    theorem append_comm {l\u2081 l\u2082 : List \u03b1} : (l\u2081++l\u2082) ~ (l\u2082++l\u2081) :=\n      match l\u2081 with\n      | []     => by simp\n      | (a::t) => ((append_comm).cons a).trans (middle a l\u2082 t).symm\n\n    theorem length_eq {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081.length = l\u2082.length :=\n      @Perm.recOn \u03b1 (fun (a b : List \u03b1) _ => a.length = b.length) l\u2081 l\u2082 p rfl\n        (fun _ _ _ _ h => by simp[h])\n        (fun _ _ _ => by simp)\n        (fun _ _ r\u2081\u2082 r\u2082\u2083 => Eq.trans r\u2081\u2082 r\u2082\u2083)\n\n    theorem eq_nil {l : List \u03b1} (p : l ~ []) : l = [] :=\n      List.eq_nil_of_length_eq_zero p.length_eq\n    theorem nil_eq {l : List \u03b1} (p : [] ~ l) : l = [] :=\n      eq_nil p.symm\n\n    theorem inductionOn (motive : List \u03b1 \u2192 List \u03b1 \u2192 Prop) {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082)\n      (h\u2081 : motive [] [])\n      (h\u2082 : \u2200 x l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 motive l\u2081 l\u2082 \u2192 motive (x::l\u2081) (x::l\u2082))\n      (h\u2083 : \u2200 x y l\u2081 l\u2082, l\u2081 ~ l\u2082 \u2192 motive l\u2081 l\u2082 \u2192 motive (y::x::l\u2081) (x::y::l\u2082))\n      (h\u2084 : \u2200 l\u2081 l\u2082 l\u2083, l\u2081 ~ l\u2082 \u2192 l\u2082 ~ l\u2083 \u2192 motive l\u2081 l\u2082 \u2192 motive l\u2082 l\u2083 \u2192 motive l\u2081 l\u2083) : motive l\u2081 l\u2082 := by\n        have P_refl : \u2200 l, motive l l :=\n          fun l => @List.recOn \u03b1 (fun x => motive x x) l h\u2081 (fun x xs ih => h\u2082 x xs xs (Perm.refl xs) ih)\n        exact Perm.recOn p h\u2081 h\u2082 (fun x y l => h\u2083 x y l l (Perm.refl l) (P_refl l)) (h\u2084 _ _ _)\n\n    theorem invCore {a : \u03b1} {l\u2081 l\u2082 r\u2081 r\u2082 : List \u03b1} : l\u2081++a::r\u2081 ~ l\u2082++a::r\u2082 \u2192 l\u2081++r\u2081 ~ l\u2082++r\u2082 := by\n      generalize e\u2081 : l\u2081++a::r\u2081 = s\u2081; generalize e\u2082 : l\u2082++a::r\u2082 = s\u2082\n      intro p; revert l\u2081 l\u2082 r\u2081 r\u2082 e\u2081 e\u2082\n      apply inductionOn (fun (t\u2081 t\u2082 : List \u03b1) => \u2200 {l\u2081' l\u2082' r\u2081' r\u2082' : List \u03b1},\n        l\u2081'++a::r\u2081' = t\u2081 \u2192 l\u2082'++a::r\u2082' = t\u2082 \u2192 l\u2081'++r\u2081' ~ l\u2082'++r\u2082') p\n      { intro l\u2081 _ r\u2081 _ e\u2081 _\n        have h\u2080 := List.not_mem_nil a; rw [\u2190e\u2081] at h\u2080\n        have : a \u2208 l\u2081 ++ a :: r\u2081 := by apply (mem_iff (middle a l\u2081 r\u2081) _).mpr; apply Or.inl; rfl\n        contradiction }\n      { intro _ _ _ p\u2081\u2082 ih l\u2081 l\u2082 _ _ e\u2081 e\u2082\n        match l\u2081, l\u2082 with\n        | [], [] =>\n          simp only [List.nil_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n          rw [e\u2081.right, e\u2082.right]; exact p\u2081\u2082\n        | [], List.cons _ _ =>\n          simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n          rw [e\u2082.left, e\u2081.right, \u2190e\u2081.left]; apply trans p\u2081\u2082; rw [\u2190e\u2082.right]; exact middle _ _ _\n        | List.cons _ _, [] =>\n          simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n          rw [e\u2081.left, \u2190e\u2082.left, e\u2082.right]; apply Perm.symm; apply trans p\u2081\u2082.symm\n          rw [\u2190e\u2081.right]; exact middle _ _ _\n        | List.cons _ _, List.cons z l\u2082 =>\n          simp only [List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n          rw [e\u2081.left, e\u2082.left]; exact cons _ (ih e\u2081.right e\u2082.right) }\n      { intro _ _ _ _ p\u2081\u2082 ih l\u2081 l\u2082 _ _ e\u2081 e\u2082\n        match l\u2081, l\u2082 with\n        | [], [] =>\n          simp only [List.nil_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n          rw [e\u2081.right, e\u2082.right, \u2190e\u2081.left, e\u2082.left]; exact Perm.cons _ p\u2081\u2082\n        | [], List.cons _ l\u2082 =>\n          match l\u2082 with\n          | [] =>\n            simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2081.right, e\u2082.left, e\u2082.right.right]; exact Perm.cons _ p\u2081\u2082\n          | List.cons _ _ =>\n            simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2081.right, e\u2082.left, e\u2082.right.left, \u2190e\u2081.left]; apply cons;\n              apply trans p\u2081\u2082; rw [\u2190e\u2082.right.right]; exact middle _ _ _\n        | List.cons _ l\u2081, [] =>\n          match l\u2081 with\n          | [] =>\n            simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2081.right.right, e\u2082.right, e\u2081.left]; exact Perm.cons _ p\u2081\u2082\n          | List.cons _ l\u2082 =>\n            simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2082.right, e\u2081.left, e\u2081.right.left, \u2190e\u2082.left]; apply cons;\n              apply Perm.symm; apply trans p\u2081\u2082.symm; rw [\u2190e\u2081.right.right]; exact middle _ _ _\n        | List.cons _ l\u2081, List.cons _ l\u2082 =>\n          match l\u2081, l\u2082 with\n          | [], [] =>\n            simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2081.left, e\u2082.left, \u2190e\u2081.right.left, \u2190e\u2082.right.left, e\u2081.right.right, e\u2082.right.right]\n              exact cons _ p\u2081\u2082\n          | [], List.cons _ _ =>\n            simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2081.left, e\u2082.left, \u2190e\u2081.right.left, e\u2082.right.left, e\u2081.right.right]\n              apply trans (cons _ p\u2081\u2082); rw [\u2190e\u2082.right.right]; apply Perm.symm; apply trans (swap _ _ _);\n                apply cons; apply Perm.symm; exact middle _ _ _\n          | List.cons _ _, [] =>\n            simp only [List.nil_append, List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2081.left, e\u2082.left, e\u2081.right.left, \u2190e\u2082.right.left]; apply trans (swap _ _ _); apply cons;\n              rw [e\u2082.right.right]; apply Perm.symm; apply trans p\u2081\u2082.symm; rw [\u2190e\u2081.right.right]; exact middle _ _ _\n          | List.cons _ _, List.cons _ _ =>\n            simp only [List.cons_append, List.cons.injEq] at e\u2081 e\u2082 \u22a2\n            rw [e\u2081.left, e\u2082.left, e\u2081.right.left, e\u2082.right.left]; apply trans (swap _ _ _); apply cons;\n              apply cons; exact ih e\u2081.right.right e\u2082.right.right }\n      { intro _ t\u2082 _ p\u2081\u2082 p\u2082\u2083 ih\u2081 ih\u2082 l\u2081 _ r\u2081 _ e\u2081 e\u2083;\n          rw [\u2190e\u2081] at p\u2081\u2082; rw [\u2190e\u2083] at p\u2082\u2083\n          have : a \u2208 t\u2082 := p\u2081\u2082.subset (by apply (mem_iff (middle a l\u2081 r\u2081) _).mpr; apply Or.inl; rfl)\n          let \u27e8l\u2082, r\u2082, e\u2082\u27e9 := List.mem_split this;\n          exact trans (ih\u2081 e\u2081 e\u2082.symm) (ih\u2082 e\u2082.symm e\u2083) }\n\n    theorem cons_inv {a : \u03b1} {l\u2081 l\u2082 : List \u03b1} : a::l\u2081 ~ a::l\u2082 \u2192 l\u2081 ~ l\u2082 :=\n      @invCore _ _ [] [] _ _\n\n    theorem pairwiseIff {r : \u03b1 \u2192 \u03b1 \u2192 Prop} (h : \u2200 a b, r a b \u2192 r b a) :\n      \u2200 {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082), Pairwise r l\u2081 \u2194 Pairwise r l\u2082 := by\n      have : \u2200 {l\u2081 l\u2082}, l\u2081 ~ l\u2082 \u2192 Pairwise r l\u2081 \u2192 Pairwise r l\u2082 := by\n        intro l\u2081 l\u2082 p\u2081\u2082 pwl\u2081\n        induction pwl\u2081 generalizing l\u2082 with\n        | nil => rw [p\u2081\u2082.nil_eq]; constructor\n        | @cons a l\u2083 hl\u2083 pwl\u2083 ih =>\n          let \u27e8s, t, e\u27e9 := List.mem_split (p\u2081\u2082.subset (List.mem_cons_self a l\u2083))\n          rw [e, Pairwise.middle, Pairwise.consIff]; rw [e] at p\u2081\u2082\n          have p' : l\u2083 ~ s ++ t := (p\u2081\u2082.trans (middle _ _ _)).cons_inv\n          exact And.intro (fun x xst => hl\u2083 x ((mem_iff p' _).mpr xst)) (ih p')\n          exact h\n      exact fun _ _ p => \u27e8this p, this p.symm\u27e9\n\n    theorem nodupIff {l\u2081 l\u2082 : List \u03b1} : l\u2081 ~ l\u2082 \u2192 (l\u2081.nodup \u2194 l\u2082.nodup) :=\n      pairwiseIff (@Ne.symm \u03b1)\n\n    theorem sizeOf_Eq_sizeOf {l\u2081 l\u2082 : List \u03b1} (h : l\u2081 ~ l\u2082) :\n      sizeOf l\u2081 = sizeOf l\u2082 := by\n      induction h with\n      | nil => rfl\n      | cons _ _ h => rw [List.sizeOf_cons, List.sizeOf_cons, h]\n      | swap _ _ _ => rw [List.sizeOf_cons, List.sizeOf_cons, List.sizeOf_cons, List.sizeOf_cons]\n      | trans _ _ h\u2081 h\u2082 => exact Eq.trans h\u2081 h\u2082\n\n    theorem filterMap (f : \u03b1 \u2192 Option \u03b2) {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) :\n      List.filterMap f l\u2081 ~ List.filterMap f l\u2082 := by\n        induction p with\n        | nil => simp only [List.filterMap]; exact Perm.nil\n        | cons x p ih =>\n          simp only [List.filterMap]\n          cases f x with\n          | none => exact ih\n          | some a => exact cons a ih\n        | swap x y l =>\n          simp only [List.filterMap]\n          cases f x with\n          | none =>\n            cases f y with\n            | none => exact Perm.refl _\n            | some b => exact Perm.cons b (Perm.refl _)\n          | some a =>\n            cases f y with\n            | none => exact Perm.refl _\n            | some b => exact Perm.swap a b _\n        | trans p\u2081\u2082 p\u2082\u2083 ih\u2081\u2082 ih\u2082\u2083 => exact ih\u2081\u2082.trans ih\u2082\u2083\n\n    theorem map (f : \u03b1 \u2192 \u03b2) {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081.map f ~ l\u2082.map f := by\n      rw [\u2190List.filterMap_Eq_map f]; exact filterMap (some \u2218 f) p\n\n    theorem pmap {p : \u03b1 \u2192 Prop} (f : \u2200 a, p a \u2192 \u03b2)\n      {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) {H\u2081 H\u2082} : l\u2081.pmap f H\u2081 ~ l\u2082.pmap f H\u2082 := by\n        induction p with\n        | nil => simp [Perm.refl]\n        | cons x p ih => simp [ih, cons]\n        | swap x y l\u2082=> simp [swap]\n        | trans p\u2081 p\u2082 ih\u2081 ih\u2082 => apply ih\u2081.trans ih\u2082; exact fun a m => H\u2082 a (p\u2082.subset m)\n\n    theorem exists_perm_sublist {l\u2081 l\u2082 l\u2082' : List \u03b1} (s : l\u2081 <+ l\u2082) (p : l\u2082 ~ l\u2082') :\n      \u2203 l\u2081', l\u2081' ~ l\u2081 \u2227 l\u2081' <+ l\u2082' := by\n        induction p generalizing l\u2081 with\n        | nil => exact \u27e8[], List.Sublist.eq_nil_of_sublist_nil s \u25b8 Perm.refl _, List.Sublist.nil_sublist _\u27e9\n        | cons x p ih =>\n          cases s with\n          | cons _ _ _ s => let \u27e8l, pl, hl\u27e9 := ih s; exact \u27e8l, pl, hl.cons _ _ x\u27e9\n          | cons' l\u2081 _ _ s => let \u27e8l, pl, hl\u27e9 := ih s; exact \u27e8x::l, pl.cons x, hl.cons' _ _ x\u27e9\n        | swap x y l\u2082 =>\n          cases s with\n          | cons _ _ _ s =>\n            cases s with\n            | cons _ _ _ s => exact \u27e8l\u2081, Perm.refl _, (s.cons _ _ y).cons _ _ x\u27e9\n            | cons' l\u2081 _ _ s => exact \u27e8x::l\u2081, Perm.refl _, (s.cons _ _ y).cons' _ _ x\u27e9\n          | cons' l\u2081 _ _ s =>\n            cases s with\n            | cons _ _ _ s => exact \u27e8y::l\u2081, Perm.refl _, (s.cons' _ _ y).cons _ _ x\u27e9\n            | cons' l\u2081 _ _ s => exact \u27e8x::y::l\u2081, Perm.swap _ _ _, (s.cons' _ _ y).cons' _ _ x\u27e9\n        | trans p\u2081 p\u2082 ih\u2081 ih\u2082 => let \u27e8l, pl, hl\u27e9 := ih\u2081 s; let \u27e8m, pm, hm\u27e9 := ih\u2082 hl; exact \u27e8m, pm.trans pl, hm\u27e9\n\n    def Subperm (l\u2081 l\u2082 : List \u03b1) : Prop := \u2203 l, l ~ l\u2081 \u2227 l <+ l\u2082\n    infix:50 \" <+~ \" => Subperm\n  end Perm\nend M4R\n\nnamespace List.Sublist\n  open M4R\n\n  protected theorem subperm {l\u2081 l\u2082 : List \u03b1} (s : l\u2081 <+ l\u2082) : l\u2081 <+~ l\u2082 :=\n    \u27e8l\u2081, M4R.Perm.refl _, s\u27e9\n\n  theorem exists_perm_append {l\u2081 l\u2082 : List \u03b1} : l\u2081 <+ l\u2082 \u2192 \u2203 l, l\u2082 ~ l\u2081 ++ l\n  | nil             => \u27e8[], Perm.refl _\u27e9\n  | cons l\u2081 l\u2082 a s  =>\n    let \u27e8l, p\u27e9 := exists_perm_append s\n    \u27e8a::l, (p.cons a).trans (Perm.middle _ _ _).symm\u27e9\n  | cons' l\u2081 l\u2082 a s =>\n    let \u27e8l, p\u27e9 := exists_perm_append s\n    \u27e8l, p.cons a\u27e9\n\nend List.Sublist\n\nnamespace M4R\n  namespace Perm\n    protected theorem subperm {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 <+~ l\u2082 :=\n      \u27e8l\u2082, p.symm, List.Sublist.refl _\u27e9\n\n    theorem subperm_left {l l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l <+~ l\u2081 \u2194 l <+~ l\u2082 := by\n      have : \u2200 {l\u2081 l\u2082 : List \u03b1}, l\u2081 ~ l\u2082 \u2192 l <+~ l\u2081 \u2192 l <+~ l\u2082 := fun p \u27e8u, pu, su\u27e9 =>\n        let \u27e8v, pv, sv\u27e9 := exists_perm_sublist su p\n        \u27e8v, pv.trans pu, sv\u27e9\n      exact \u27e8this p, this p.symm\u27e9\n\n    theorem subperm_right {l\u2081 l\u2082 l : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081 <+~ l \u2194 l\u2082 <+~ l :=\n      \u27e8fun \u27e8u, pu, su\u27e9 => \u27e8u, pu.trans p, su\u27e9,\n        fun \u27e8u, pu, su\u27e9 => \u27e8u, pu.trans p.symm, su\u27e9\u27e9\n\n    namespace Subperm\n      theorem nil_subperm {l : List \u03b1} : [] <+~ l :=\n        \u27e8[], Perm.nil, by simp\u27e9\n\n      protected theorem refl (l : List \u03b1) : l <+~ l := (Perm.refl _).subperm\n\n      protected theorem trans {l\u2081 l\u2082 l\u2083 : List \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2082 <+~ l\u2083 \u2192 l\u2081 <+~ l\u2083\n      | s, \u27e8l\u2082', p\u2082, s\u2082\u27e9 =>\n        let \u27e8l\u2081', p\u2081, s\u2081\u27e9 := p\u2082.subperm_left.mpr s\n        \u27e8l\u2081', p\u2081, s\u2081.trans s\u2082\u27e9\n\n      theorem length_le {l\u2081 l\u2082 : List \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2081.length \u2264 l\u2082.length\n      | \u27e8l, p, s\u27e9 => p.length_eq \u25b8 s.length_le_of_sublist\n\n      theorem perm_of_length_le {l\u2081 l\u2082 : List \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2082.length \u2264 l\u2081.length \u2192 l\u2081 ~ l\u2082\n      | \u27e8l, p, s\u27e9, h =>\n        have := List.Sublist.eq_of_sublist_of_length_le s (p.symm.length_eq \u25b8 h)\n        this \u25b8 p.symm\n\n      theorem antisymm {l\u2081 l\u2082 : List \u03b1} (h\u2081 : l\u2081 <+~ l\u2082) (h\u2082 : l\u2082 <+~ l\u2081) : l\u2081 ~ l\u2082 :=\n        h\u2081.perm_of_length_le h\u2082.length_le\n\n      theorem subset {l\u2081 l\u2082 : List \u03b1} : l\u2081 <+~ l\u2082 \u2192 l\u2081 \u2286 l\u2082\n      | \u27e8l, p, s\u27e9 => Subset.trans p.symm.subset s.subset\n\n      theorem subperm_cons (a : \u03b1) {l\u2081 l\u2082 : List \u03b1} : a::l\u2081 <+~ a::l\u2082 \u2194 l\u2081 <+~ l\u2082 :=\n        \u27e8fun \u27e8l, p, s\u27e9 => by\n          cases s with\n          | cons _ _ _ s' =>\n            exact (p.subperm_left.mpr (List.Sublist.sublist_cons _ _).subperm).trans s'.subperm\n          | cons' u _ _ s' => exact \u27e8u, p.cons_inv, s'\u27e9,\n        fun \u27e8l, p, s\u27e9 => \u27e8a::l, p.cons a, s.cons' _ _ _\u27e9\u27e9\n\n      theorem subperm_swap_left {a b : \u03b1} {l\u2081 l\u2082 : List \u03b1} : a::b::l\u2081 <+~ l\u2082 \u2192 b::a::l\u2081 <+~ l\u2082 :=\n        fun \u27e8t, p, s\u27e9 => \u27e8t, p.trans (Perm.swap b a l\u2081), s\u27e9\n\n      theorem cons_subperm_of_mem {a : \u03b1} {l\u2081 l\u2082 : List \u03b1} (d\u2081 : l\u2081.nodup) (h\u2081 : a \u2209 l\u2081) (h\u2082 : a \u2208 l\u2082)\n        (s : l\u2081 <+~ l\u2082) : a :: l\u2081 <+~ l\u2082 := by\n          let \u27e8l, p, s\u27e9 := s\n          induction s generalizing l\u2081 with\n          | nil => cases h\u2082\n          | cons r\u2081 r\u2082  b s' ih =>\n            cases h\u2082 with\n            | inl e => rw [e]; exact \u27e8b::r\u2081, p.cons b, s'.cons' _ _ _\u27e9\n            | inr m => let \u27e8t, p', s'\u27e9 := ih d\u2081 h\u2081 m \u27e8r\u2081, p, s'\u27e9 p; exact \u27e8t, p', s'.cons _ _ _\u27e9\n          | cons' r\u2081 r\u2082 b s' ih =>\n            have bm : b \u2208 l\u2081 := p.subset (List.mem_cons_self _ _)\n            have am : a \u2208 r\u2082 := h\u2082.resolve_left (fun e => h\u2081 (e.symm \u25b8 bm))\n            cases List.mem_split bm with\n            | intro t\u2081 t\u2082 =>\n              let \u27e8t\u2082, h\u27e9 := t\u2082; rw [h]\n              have st : t\u2081 ++ t\u2082 <+ l\u2081 := by\n                rw [h]; exact (List.Sublist.append_sublist_append_left t\u2081).mpr\n                  (List.Sublist.cons t\u2082 t\u2082 b (List.Sublist.refl t\u2082))\n              have rt : r\u2081 ~ t\u2081 ++ t\u2082 := cons_inv (p.trans (by rw [h]; exact Perm.middle _ _ _))\n              let \u27e8t, p', s'\u27e9 := ih (List.nodup_of_sublist st d\u2081) (fun h' => absurd (st.subset h') h\u2081) am\n                \u27e8r\u2081, rt, s'\u27e9 rt\n              exact \u27e8b::t, (p'.cons b).trans ((swap _ _ _).trans ((Perm.middle _ _ _).symm.cons a)), s'.cons' _ _ _\u27e9\n\n      theorem subperm_append_left {l\u2081 l\u2082 : List \u03b1} : \u2200 l, l++l\u2081 <+~ l++l\u2082 \u2194 l\u2081 <+~ l\u2082\n      | []   => Iff.rfl\n      | a::l => (subperm_cons a).trans (subperm_append_left l)\n\n      theorem subperm_append_right {l\u2081 l\u2082 : List \u03b1} (l : List \u03b1) : l\u2081++l <+~ l\u2082++l \u2194 l\u2081 <+~ l\u2082 :=\n        (append_comm.subperm_left.trans append_comm.subperm_right).trans (subperm_append_left l)\n\n      theorem subperm_of_subset_nodup {l\u2081 l\u2082 : List \u03b1} (d : l\u2081.nodup) (H : l\u2081 \u2286 l\u2082) : l\u2081 <+~ l\u2082 := by\n        induction d with\n        | nil => exact \u27e8[], Perm.nil, List.Sublist.nil_sublist _\u27e9\n        | cons h d IH =>\n          let \u27e8H\u2081, H\u2082\u27e9 := List.forall_mem_cons.mp H\n          exact cons_subperm_of_mem d (fun h' => by apply h _ h'; rfl) H\u2081 (IH H\u2082)\n\n      @[simp] theorem subperm_nil {l : List \u03b1} (h : l <+~ []) : l = [] := by\n        let \u27e8t, p, s\u27e9 := h\n        rw [List.Sublist.eq_nil_of_sublist_nil s] at p\n        exact eq_nil p.symm\n\n      theorem not_cons_self (l : List \u03b1) (a : \u03b1) : \u00ac (a::l <+~ l) := by\n        induction l with\n        | nil =>\n          intro h; have := subperm_nil h\n          contradiction\n        | cons x l ih =>\n          intro h; exact ih ((subperm_cons x).mp (subperm_swap_left h))\n\n      theorem exists_of_length_lt {l\u2081 l\u2082 : List \u03b1} :\n        l\u2081 <+~ l\u2082 \u2192 l\u2081.length < l\u2082.length \u2192 \u2203 a, a :: l\u2081 <+~ l\u2082 := by\n          intro \u27e8l, p, s\u27e9 hlt\n          have : l.length < l\u2082.length \u2192 \u2203 a, a :: l <+~ l\u2082 := by\n            clear p hlt l\u2081\n            induction s with\n            | nil => intro hlt'; cases hlt'\n            | cons l\u2081' l\u2082' a s ih =>\n              intro hlt'\n              cases Nat.lt_or_eq_of_le (Nat.le_of_lt_succ hlt') with\n              | inl h' => exact (ih h').imp (fun a s => s.trans (List.Sublist.sublist_cons _ _).subperm)\n              | inr h' => exact \u27e8a, List.Sublist.eq_of_sublist_of_length_eq s h' \u25b8 Subperm.refl _\u27e9\n            | cons' l\u2081' l\u2082' b s ih =>\n              intro h'\n              exact (ih (Nat.lt_of_succ_lt_succ h')).imp (fun a s =>\n                (swap _ _ _).subperm_right.mp ((subperm_cons _).mpr s))\n          exact (this (p.symm.length_eq \u25b8 hlt)).imp (fun a => (p.cons a).subperm_right.mp)\n\n      theorem exists_of_subperm_ne {l\u2081 l\u2082 : List \u03b1} (h\u2081 : l\u2081 <+~ l\u2082) (h\u2082 : \u00ac l\u2081 ~ l\u2082) : \u2203 a, a::l\u2081 <+~ l\u2082 :=\n        exists_of_length_lt h\u2081 (Nat.gt_of_not_le (mt (perm_of_length_le h\u2081) h\u2082))\n\n    end Subperm\n\n    protected theorem ext {l\u2081 l\u2082 : List \u03b1} (d\u2081 : l\u2081.nodup) (d\u2082 : l\u2082.nodup) : l\u2081 ~ l\u2082 \u2194 \u2200a, a \u2208 l\u2081 \u2194 a \u2208 l\u2082 :=\n      \u27e8fun p a => p.mem_iff _, fun H =>\n        Subperm.antisymm\n          (Subperm.subperm_of_subset_nodup d\u2081 (fun a => (H a).mp))\n          (Subperm.subperm_of_subset_nodup d\u2082 (fun a => (H a).mpr))\u27e9\n\n    open Classical\n\n    theorem insert (a : \u03b1) {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081.insert a ~ l\u2082.insert a :=\n      if h : a \u2208 l\u2081 then by\n        simp only [List.insert, h, p.subset h]; exact p\n      else by\n        simp only [List.insert, h, mt (p.mem_iff a).mpr h]\n        exact Perm.cons a p\n\n    theorem insert_swap (x y : \u03b1) (l : List \u03b1) : (l.insert y).insert x ~ (l.insert x).insert y := by\n      byCases xl : x \u2208 l; { byCases yl : y \u2208 l; { simp [xl, yl] } simp [xl, yl] }\n      byCases xy : x = y; { simp [xy] } byCases yl : y \u2208 l; { simp [xl, yl] }\n      simp [xl, yl, List.not_mem_cons_of_ne_of_not_mem xy xl,\n        List.not_mem_cons_of_ne_of_not_mem (Ne.symm xy) yl, swap]\n\n    theorem union_right {l\u2081 l\u2082 : List \u03b1} (t\u2081 : List \u03b1) (h : l\u2081 ~ l\u2082) : l\u2081 \u222a t\u2081 ~ l\u2082 \u222a t\u2081 := by\n      induction h with\n      | nil => simp\n      | cons a _ ih => exact ih.insert a\n      | swap => exact insert_swap _ _ _\n      | trans _ _ ih\u2081 ih\u2082 => exact ih\u2081.trans ih\u2082\n\n    theorem union_left (l : List \u03b1) {t\u2081 t\u2082 : List \u03b1} (h : t\u2081 ~ t\u2082) : l \u222a t\u2081 ~ l \u222a t\u2082 := by\n      induction l with\n      | nil => simp [h]\n      | cons a l ih => simp [insert a ih]\n\n    theorem union {l\u2081 l\u2082 t\u2081 t\u2082 : List \u03b1} (p\u2081 : l\u2081 ~ l\u2082) (p\u2082 : t\u2081 ~ t\u2082) : l\u2081 \u222a t\u2081 ~ l\u2082 \u222a t\u2082 :=\n      (p\u2081.union_right t\u2081).trans (p\u2082.union_left l\u2082)\n\n    theorem Sublist.union_left (l\u2081 l\u2082 : List \u03b1) : l\u2081 <+ l\u2082 \u222a l\u2081 := by\n      let \u27e8t, s, e\u27e9 := List.sublist_suffix_of_union l\u2082 l\u2081\n      rw [\u2190e]; exact List.Sublist.sublist_append_right t l\u2081\n\n    theorem Subperm.union_left (l\u2081 l\u2082 : List \u03b1) : l\u2081 <+~ l\u2082 \u222a l\u2081 :=\n      (Sublist.union_left l\u2081 l\u2082).subperm\n\n    theorem filter' (p : \u03b1 \u2192 Prop) {l\u2081 l\u2082 : List \u03b1} (s : l\u2081 ~ l\u2082) : l\u2081.filter' p ~ l\u2082.filter' p := by\n      rw [\u2190List.filter_map_eq_filter']; exact s.filterMap _\n\n    theorem cons_erase {a : \u03b1} {l : List \u03b1} (h : a \u2208 l) : l ~ a :: l.erase a :=\n      let \u27e8l\u2081, l\u2082, _, e\u2081, e\u2082\u27e9 := List.exists_erase_eq h\n      e\u2082.symm \u25b8 e\u2081.symm \u25b8 (middle a l\u2081 l\u2082)\n\n    theorem erase (a : \u03b1) {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) :\n      l\u2081.erase a ~ l\u2082.erase a :=\n        if h\u2081 : a \u2208 l\u2081 then\n          have h\u2082 : a \u2208 l\u2082 := p.subset h\u2081\n          cons_inv ((cons_erase h\u2081).symm.trans (p.trans (cons_erase h\u2082)))\n        else by\n          have h\u2082 : a \u2209 l\u2082 := mt (p.mem_iff _).mpr h\u2081\n          rw [List.erase_of_not_mem h\u2081, List.erase_of_not_mem h\u2082]; exact p\n\n    theorem diff_right {l\u2081 l\u2082 : List \u03b1} (t : List \u03b1) (h : l\u2081 ~ l\u2082) : l\u2081.diff t ~ l\u2082.diff t := by\n      induction t generalizing l\u2081 l\u2082 h with\n      | nil => simp [h]\n      | cons a t ih =>\n        simp only [List.diff_cons]\n        exact ih (erase a h)\n\n    theorem diff_left (l : List \u03b1) {t\u2081 t\u2082 : List \u03b1} (h : t\u2081 ~ t\u2082) : l.diff t\u2081 = l.diff t\u2082 := by\n      induction h generalizing l with\n      | nil => simp\n      | cons a p ih => simp; exact ih _\n      | swap x y t => simp [List.erase_comm]\n      | trans p\u2081 p\u2082 ih\u2081 ih\u2082 => exact (ih\u2081 _).trans (ih\u2082 _)\n\n    theorem diff {l\u2081 l\u2082 t\u2081 t\u2082 : List \u03b1} (hl : l\u2081 ~ l\u2082) (ht : t\u2081 ~ t\u2082) :\n      l\u2081.diff t\u2081 ~ l\u2082.diff t\u2082 :=\n        ht.diff_left l\u2082 \u25b8 hl.diff_right _\n\n    theorem countp_eq (p : \u03b1 \u2192 Prop) {l\u2081 l\u2082 : List \u03b1} (s : l\u2081 ~ l\u2082) : l\u2081.countp p = l\u2082.countp p := by\n      rw [List.countp_eq_length_filter', List.countp_eq_length_filter']\n      exact (s.filter' _).length_eq\n\n    theorem count_eq {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) (a) : l\u2081.count a = l\u2082.count a :=\n      p.countp_eq _\n\n    theorem perm_iff_count {l\u2081 l\u2082 : List \u03b1} : l\u2081 ~ l\u2082 \u2194 \u2200 a, l\u2081.count a = l\u2082.count a :=\n      \u27e8count_eq, fun h => by\n        induction l\u2081 generalizing l\u2082 with\n        | nil => cases l\u2082 with\n          | nil => exact Perm.refl _\n          | cons b l\u2082 => have := h b; simp only [List.count.count_nil,\n            List.count.count_cons_of_pos] at this; contradiction\n        | cons a l\u2081 ih =>\n          have : a \u2208 l\u2082 := List.count.count_pos.mp ((List.count.count_cons_of_pos a l\u2081 \u25b8 h a :\n            List.count a l\u2081 + 1 = List.count a l\u2082) \u25b8 Nat.succ_pos _)\n          exact ((ih fun b => by\n            have h\u2081 := h b; rw [(cons_erase this).count_eq] at h\u2081\n            byCases h\u2082 : b = a\n            { simp only [h\u2082, List.count.count_cons_of_pos] at h\u2081 \u22a2; exact Nat.succ.inj h\u2081 }\n            { simp only [List.count.count_cons_of_neg h\u2082] at h\u2081; exact h\u2081 }).cons a).trans (cons_erase this).symm\u27e9\n\n    section bag_inter\n\n      theorem bag_inter_right {l\u2081 l\u2082 : List \u03b1} (t : List \u03b1) (h : l\u2081 ~ l\u2082) :\n        l\u2081.bag_inter t ~ l\u2082.bag_inter t := by\n          induction h generalizing t with\n          | nil => exact Perm.refl _\n          | cons x p ih =>\n            byCases hx : x \u2208 t\n            { rw [List.cons_bag_inter_of_pos _ hx, List.cons_bag_inter_of_pos _ hx]\n            exact (ih (t.erase x)).cons x }\n            { rw [List.cons_bag_inter_of_neg _ hx, List.cons_bag_inter_of_neg _ hx]\n            exact ih t }\n          | swap x y l =>\n            byCases hxy : x = y\n            { rw [hxy]; exact Perm.refl _ }\n            { byCases hx : x \u2208 t;\n              { rw [List.cons_bag_inter_of_pos _ hx]\n                byCases hy : y \u2208 t;\n                { rw [List.cons_bag_inter_of_pos _ hy,\n                    List.cons_bag_inter_of_pos _ ((List.mem_erase_of_ne hxy).mpr hx),\n                    List.cons_bag_inter_of_pos _ ((List.mem_erase_of_ne (Ne.symm hxy)).mpr hy),\n                    List.erase_comm]\n                  exact Perm.swap x y _ }\n                { rw [List.cons_bag_inter_of_neg _ hy,\n                    List.cons_bag_inter_of_pos _ hx,\n                    List.cons_bag_inter_of_neg _ (mt List.mem_of_mem_erase hy)]\n                  exact Perm.cons x (Perm.refl _) } }\n              { rw [List.cons_bag_inter_of_neg _ hx]\n                byCases hy : y \u2208 t;\n                { rw [List.cons_bag_inter_of_pos _ hy,\n                    List.cons_bag_inter_of_pos _ hy,\n                    List.cons_bag_inter_of_neg _ (mt List.mem_of_mem_erase hx)]\n                  exact Perm.cons y (Perm.refl _) }\n                { rw [List.cons_bag_inter_of_neg _ hy,\n                    List.cons_bag_inter_of_neg _ hx,\n                    List.cons_bag_inter_of_neg _ hy]\n                  exact Perm.refl _ } } }\n          | trans p\u2081 p\u2082 ih\u2081 ih\u2082 => exact (ih\u2081 _).trans (ih\u2082 _)\n\n      theorem bag_inter_left (l : List \u03b1) {t\u2081 t\u2082 : List \u03b1} (p : t\u2081 ~ t\u2082) :\n        l.bag_inter t\u2081 = l.bag_inter t\u2082 := by\n          induction l generalizing t\u2081 t\u2082 p with\n          | nil => simp only [List.nil_bag_inter]\n          | cons a l ih =>\n            byCases h : a \u2208 t\u2081\n            { rw [List.cons_bag_inter_of_pos _ h,\n              List.cons_bag_inter_of_pos _ ((p.mem_iff a).mp h)]\n              exact List.cons_ext.mpr \u27e8rfl, ih (p.erase _)\u27e9 }\n            { rw [List.cons_bag_inter_of_neg _ h,\n              List.cons_bag_inter_of_neg _ (mt (p.mem_iff a).mpr h)]\n              exact ih p }\n\n      theorem bag_inter {l\u2081 l\u2082 t\u2081 t\u2082 : List \u03b1} (hl : l\u2081 ~ l\u2082) (ht : t\u2081 ~ t\u2082) :\n        l\u2081.bag_inter t\u2081 ~ l\u2082.bag_inter t\u2082 :=\n          ht.bag_inter_left l\u2082 \u25b8 hl.bag_inter_right _\n\n    end bag_inter\n\n    theorem dedup {l\u2081 l\u2082 : List \u03b1} (p : l\u2081 ~ l\u2082) : l\u2081.dedup ~ l\u2082.dedup :=\n      perm_iff_count.mpr fun a => by\n        byCases h : a \u2208 l\u2081\n        { simp only [List.mem_dedup, List.nodup_dedup, List.count_eq_one_of_mem, h, p.subset h] }\n        { simp only [List.mem_dedup, List.count_eq_zero_of_not_mem, h, mt (p.mem_iff a).mpr h] }\n\n  end Perm\nend M4R\n", "meta": {"author": "Hop311", "repo": "M4R", "sha": "ebd1b04af344f9737d290bf8b48b3cde35e9787b", "save_path": "github-repos/lean/Hop311-M4R", "path": "github-repos/lean/Hop311-M4R/M4R-ebd1b04af344f9737d290bf8b48b3cde35e9787b/M4R/Set/Finite/Perm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7007688676461338}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers, S\u00e9bastien Gou\u00ebzel, Heather Macbeth\n-/\nimport analysis.inner_product_space.projection\nimport analysis.normed_space.pi_Lp\n\n/-!\n# `L\u00b2` inner product space structure on finite products of inner product spaces\n\nThe `L\u00b2` norm on a finite product of inner product spaces is compatible with an inner product\n$$\n\\langle x, y\\rangle = \\sum \\langle x_i, y_i \\rangle.\n$$\nThis is recorded in this file as an inner product space instance on `pi_Lp 2`.\n\n## Main definitions\n\n- `euclidean_space \ud835\udd5c n`: defined to be `pi_Lp 2 (n \u2192 \ud835\udd5c)` for any `fintype n`, i.e., the space\n  from functions to `n` to `\ud835\udd5c` with the `L\u00b2` norm. We register several instances on it (notably\n  that it is a finite-dimensional inner product space).\n\n- `orthonormal_basis \ud835\udd5c \u03b9`: defined to be an isometry to Euclidean space from a given\n  finite-dimensional innner product space, `E \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9`.\n\n- `basis.to_orthonormal_basis`: constructs an `orthonormal_basis` for a finite-dimensional\n  Euclidean space from a `basis` which is `orthonormal`.\n\n- `linear_isometry_equiv.of_inner_product_space`: provides an arbitrary isometry to Euclidean space\n  from a given finite-dimensional inner product space, induced by choosing an arbitrary basis.\n\n- `complex.isometry_euclidean`: standard isometry from `\u2102` to `euclidean_space \u211d (fin 2)`\n\n-/\n\nopen real set filter is_R_or_C\nopen_locale big_operators uniformity topological_space nnreal ennreal complex_conjugate direct_sum\n\nnoncomputable theory\n\nvariables {\u03b9 : Type*}\nvariables {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {E : Type*} [inner_product_space \ud835\udd5c E]\nvariables {E' : Type*} [inner_product_space \ud835\udd5c E']\nvariables {F : Type*} [inner_product_space \u211d F]\nvariables {F' : Type*} [inner_product_space \u211d F']\nlocal notation `\u27ea`x`, `y`\u27eb` := @inner \ud835\udd5c _ _ x y\n\n/-\n If `\u03b9` is a finite type and each space `f i`, `i : \u03b9`, is an inner product space,\nthen `\u03a0 i, f i` is an inner product space as well. Since `\u03a0 i, f i` is endowed with the sup norm,\nwe use instead `pi_Lp 2 f` for the product space, which is endowed with the `L^2` norm.\n-/\ninstance pi_Lp.inner_product_space {\u03b9 : Type*} [fintype \u03b9] (f : \u03b9 \u2192 Type*)\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] : inner_product_space \ud835\udd5c (pi_Lp 2 f) :=\n{ inner := \u03bb x y, \u2211 i, inner (x i) (y i),\n  norm_sq_eq_inner :=\n  begin\n    intro x,\n    have h\u2081 : \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u2115) = \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d),\n    { apply finset.sum_congr rfl,\n      intros j hj,\n      simp [\u2190rpow_nat_cast] },\n    have h\u2082 : 0 \u2264 \u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d),\n    { rw [\u2190h\u2081],\n      exact finset.sum_nonneg (\u03bb j (hj : j \u2208 finset.univ), pow_nonneg (norm_nonneg (x j)) 2) },\n    simp [norm, add_monoid_hom.map_sum, \u2190norm_sq_eq_inner],\n    rw [\u2190rpow_nat_cast ((\u2211 (i : \u03b9), \u2225x i\u2225 ^ (2 : \u211d)) ^ (2 : \u211d)\u207b\u00b9) 2],\n    rw [\u2190rpow_mul h\u2082],\n    norm_num [h\u2081],\n  end,\n  conj_sym :=\n  begin\n    intros x y,\n    unfold inner,\n    rw ring_hom.map_sum,\n    apply finset.sum_congr rfl,\n    rintros z -,\n    apply inner_conj_sym,\n  end,\n  add_left := \u03bb x y z,\n    show \u2211 i, inner (x i + y i) (z i) = \u2211 i, inner (x i) (z i) + \u2211 i, inner (y i) (z i),\n    by simp only [inner_add_left, finset.sum_add_distrib],\n  smul_left := \u03bb x y r,\n    show \u2211 (i : \u03b9), inner (r \u2022 x i) (y i) = (conj r) * \u2211 i, inner (x i) (y i),\n    by simp only [finset.mul_sum, inner_smul_left] }\n\n@[simp] lemma pi_Lp.inner_apply {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 Type*}\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] (x y : pi_Lp 2 f) :\n  \u27eax, y\u27eb = \u2211 i, \u27eax i, y i\u27eb :=\nrfl\n\nlemma pi_Lp.norm_eq_of_L2 {\u03b9 : Type*} [fintype \u03b9] {f : \u03b9 \u2192 Type*}\n  [\u03a0 i, inner_product_space \ud835\udd5c (f i)] (x : pi_Lp 2 f) :\n  \u2225x\u2225 = sqrt (\u2211 (i : \u03b9), \u2225x i\u2225 ^ 2) :=\nby { rw [pi_Lp.norm_eq_of_nat 2]; simp [sqrt_eq_rpow] }\n\n/-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional\nspace use `euclidean_space \ud835\udd5c (fin n)`. -/\n@[reducible, nolint unused_arguments]\ndef euclidean_space (\ud835\udd5c : Type*) [is_R_or_C \ud835\udd5c]\n  (n : Type*) [fintype n] : Type* := pi_Lp 2 (\u03bb (i : n), \ud835\udd5c)\n\nlemma euclidean_space.norm_eq {\ud835\udd5c : Type*} [is_R_or_C \ud835\udd5c] {n : Type*} [fintype n]\n  (x : euclidean_space \ud835\udd5c n) : \u2225x\u2225 = real.sqrt (\u2211 (i : n), \u2225x i\u2225 ^ 2) :=\npi_Lp.norm_eq_of_L2 x\n\nvariables [fintype \u03b9]\n\nsection\nlocal attribute [reducible] pi_Lp\n\ninstance : finite_dimensional \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\ninstance : inner_product_space \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) := by apply_instance\n\n@[simp] lemma finrank_euclidean_space :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9) = fintype.card \u03b9 := by simp\n\nlemma finrank_euclidean_space_fin {n : \u2115} :\n  finite_dimensional.finrank \ud835\udd5c (euclidean_space \ud835\udd5c (fin n)) = n := by simp\n\n/-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry\nfrom `E` to `pi_Lp 2` of the subspaces equipped with the `L2` inner product. -/\ndef direct_sum.submodule_is_internal.isometry_L2_of_orthogonal_family\n  [decidable_eq \u03b9] {V : \u03b9 \u2192 submodule \ud835\udd5c E} (hV : direct_sum.submodule_is_internal V)\n  (hV' : @orthogonal_family \ud835\udd5c _ _ _ _ (\u03bb i, V i) _ (\u03bb i, (V i).subtype\u2097\u1d62)) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] pi_Lp 2 (\u03bb i, V i) :=\nbegin\n  let e\u2081 := direct_sum.linear_equiv_fun_on_fintype \ud835\udd5c \u03b9 (\u03bb i, V i),\n  let e\u2082 := linear_equiv.of_bijective _ hV.injective hV.surjective,\n  refine (e\u2082.symm.trans e\u2081).isometry_of_inner _,\n  suffices : \u2200 v w, \u27eav, w\u27eb = \u27eae\u2082 (e\u2081.symm v), e\u2082 (e\u2081.symm w)\u27eb,\n  { intros v\u2080 w\u2080,\n    convert this (e\u2081 (e\u2082.symm v\u2080)) (e\u2081 (e\u2082.symm w\u2080));\n    simp only [linear_equiv.symm_apply_apply, linear_equiv.apply_symm_apply] },\n  intros v w,\n  transitivity \u27ea(\u2211 i, (V i).subtype\u2097\u1d62 (v i)), \u2211 i, (V i).subtype\u2097\u1d62 (w i)\u27eb,\n  { simp only [sum_inner, hV'.inner_right_fintype, pi_Lp.inner_apply] },\n  { congr; simp }\nend\n\n@[simp] lemma direct_sum.submodule_is_internal.isometry_L2_of_orthogonal_family_symm_apply\n  [decidable_eq \u03b9] {V : \u03b9 \u2192 submodule \ud835\udd5c E} (hV : direct_sum.submodule_is_internal V)\n  (hV' : @orthogonal_family \ud835\udd5c _ _ _ _ (\u03bb i, V i) _ (\u03bb i, (V i).subtype\u2097\u1d62))\n  (w : pi_Lp 2 (\u03bb i, V i)) :\n  (hV.isometry_L2_of_orthogonal_family hV').symm w = \u2211 i, (w i : E) :=\nbegin\n  classical,\n  let e\u2081 := direct_sum.linear_equiv_fun_on_fintype \ud835\udd5c \u03b9 (\u03bb i, V i),\n  let e\u2082 := linear_equiv.of_bijective _ hV.injective hV.surjective,\n  suffices : \u2200 v : \u2a01 i, V i, e\u2082 v = \u2211 i, e\u2081 v i,\n  { exact this (e\u2081.symm w) },\n  intros v,\n  simp [e\u2082, direct_sum.submodule_coe, direct_sum.to_module, dfinsupp.sum_add_hom_apply]\nend\n\nend\n\n/-- The vector given in euclidean space by being `1 : \ud835\udd5c` at coordinate `i : \u03b9` and `0 : \ud835\udd5c` at\nall other coordinates. -/\ndef euclidean_space.single [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) :\n  euclidean_space \ud835\udd5c \u03b9 :=\npi.single i a\n\n@[simp] theorem euclidean_space.single_apply [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) (j : \u03b9) :\n  (euclidean_space.single i a) j = ite (j = i) a 0 :=\nby { rw [euclidean_space.single, \u2190 pi.single_apply i a j] }\n\nlemma euclidean_space.inner_single_left [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c) (v : euclidean_space \ud835\udd5c \u03b9) :\n  \u27eaeuclidean_space.single i (a : \ud835\udd5c), v\u27eb = conj a * (v i) :=\nby simp [apply_ite conj]\n\nlemma euclidean_space.inner_single_right [decidable_eq \u03b9] (i : \u03b9) (a : \ud835\udd5c)\n  (v : euclidean_space \ud835\udd5c \u03b9) :\n  \u27eav, euclidean_space.single i (a : \ud835\udd5c)\u27eb =  a * conj (v i) :=\nby simp [apply_ite conj, mul_comm]\n\nvariables (\u03b9 \ud835\udd5c E)\n\n/-- An orthonormal basis on E is an identification of `E` with its dimensional-matching\n`euclidean_space \ud835\udd5c \u03b9`. -/\nstructure orthonormal_basis := of_repr :: (repr : E \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9)\n\nvariables {\u03b9 \ud835\udd5c E}\n\nnamespace orthonormal_basis\n\ninstance : inhabited (orthonormal_basis \u03b9 \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9)) :=\n\u27e8of_repr (linear_isometry_equiv.refl \ud835\udd5c (euclidean_space \ud835\udd5c \u03b9))\u27e9\n\n/-- `b i` is the `i`th basis vector. -/\ninstance : has_coe_to_fun (orthonormal_basis \u03b9 \ud835\udd5c E) (\u03bb _, \u03b9 \u2192 E) :=\n{ coe := \u03bb b i, by classical; exact b.repr.symm (euclidean_space.single i (1 : \ud835\udd5c)) }\n\n@[simp] protected lemma repr_symm_single [decidable_eq \u03b9] (b : orthonormal_basis \u03b9 \ud835\udd5c E) (i : \u03b9) :\n  b.repr.symm (euclidean_space.single i (1:\ud835\udd5c)) = b i :=\nby { classical, congr, simp, }\n\n@[simp] protected lemma repr_self [decidable_eq \u03b9] (b : orthonormal_basis \u03b9 \ud835\udd5c E) (i : \u03b9) :\n  b.repr (b i) = euclidean_space.single i (1:\ud835\udd5c) :=\nbegin\n  classical,\n  rw [\u2190 b.repr_symm_single i, linear_isometry_equiv.apply_symm_apply],\n  congr,\n  simp,\nend\n\nprotected lemma repr_apply_apply (b : orthonormal_basis \u03b9 \ud835\udd5c E) (v : E) (i : \u03b9) :\n  b.repr v i = \u27eab i, v\u27eb :=\nbegin\n  classical,\n  rw [\u2190 b.repr.inner_map_map (b i) v, b.repr_self i, euclidean_space.inner_single_left],\n  simp only [one_mul, eq_self_iff_true, map_one],\nend\n\n@[simp]\nprotected lemma orthonormal (b : orthonormal_basis \u03b9 \ud835\udd5c E) : orthonormal \ud835\udd5c b :=\nbegin\n  classical,\n  rw orthonormal_iff_ite,\n  intros i j,\n  rw [\u2190 b.repr.inner_map_map (b i) (b j), b.repr_self i, b.repr_self j],\n  rw euclidean_space.inner_single_left,\n  rw euclidean_space.single_apply,\n  simp only [mul_boole, map_one],\nend\n\n/-- The `basis \u03b9 \ud835\udd5c E` underlying the `orthonormal_basis` --/\nprotected def to_basis (b : orthonormal_basis \u03b9 \ud835\udd5c E) : basis \u03b9 \ud835\udd5c E :=\nbasis.of_equiv_fun b.repr.to_linear_equiv\n\n@[simp] protected lemma coe_to_basis (b : orthonormal_basis \u03b9 \ud835\udd5c E) :\n  (\u21d1b.to_basis : \u03b9 \u2192 E) = \u21d1b :=\nbegin\n  change \u21d1(basis.of_equiv_fun b.repr.to_linear_equiv) = b,\n  ext j,\n  rw basis.coe_of_equiv_fun,\n  simp only [orthonormal_basis.repr_symm_single],\n  congr,\nend\n\n@[simp] protected lemma coe_to_basis_repr (b : orthonormal_basis \u03b9 \ud835\udd5c E) :\n  b.to_basis.equiv_fun = b.repr.to_linear_equiv :=\nbegin\n  change (basis.of_equiv_fun b.repr.to_linear_equiv).equiv_fun = b.repr.to_linear_equiv,\n  ext x j,\n  simp only [basis.of_equiv_fun_repr_apply, eq_self_iff_true,\n    linear_isometry_equiv.coe_to_linear_equiv, basis.equiv_fun_apply],\nend\n\nprotected lemma sum_repr_symm (b : orthonormal_basis \u03b9 \ud835\udd5c E) (v : euclidean_space \ud835\udd5c \u03b9) :\n  \u2211 i , v i \u2022 b i = (b.repr.symm v) :=\nby { classical, simpa using (b.to_basis.equiv_fun_symm_apply v).symm }\n\nvariable {v : \u03b9 \u2192 E}\n\n/-- A basis that is orthonormal is an orthonormal basis. -/\ndef _root_.basis.to_orthonormal_basis (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  orthonormal_basis \u03b9 \ud835\udd5c E :=\northonormal_basis.of_repr $\nlinear_equiv.isometry_of_inner v.equiv_fun\nbegin\n  intros x y,\n  let p : euclidean_space \ud835\udd5c \u03b9 := v.equiv_fun x,\n  let q : euclidean_space \ud835\udd5c \u03b9 := v.equiv_fun y,\n  have key : \u27eap, q\u27eb = \u27ea\u2211 i, p i \u2022 v i, \u2211 i, q i \u2022 v i\u27eb,\n  { simp [sum_inner, inner_smul_left, hv.inner_right_fintype] },\n  convert key,\n  { rw [\u2190 v.equiv_fun.symm_apply_apply x, v.equiv_fun_symm_apply] },\n  { rw [\u2190 v.equiv_fun.symm_apply_apply y, v.equiv_fun_symm_apply] }\nend\n\n@[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  ((v.to_orthonormal_basis hv).repr : E \u2192 euclidean_space \ud835\udd5c \u03b9) = v.equiv_fun :=\nrfl\n\n@[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr_symm\n  (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  ((v.to_orthonormal_basis hv).repr.symm : euclidean_space \ud835\udd5c \u03b9 \u2192 E) = v.equiv_fun.symm :=\nrfl\n\n@[simp] lemma _root_.basis.to_basis_to_orthonormal_basis (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  (v.to_orthonormal_basis hv).to_basis = v :=\nby simp [basis.to_orthonormal_basis, orthonormal_basis.to_basis]\n\n@[simp] lemma _root_.basis.coe_to_orthonormal_basis (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v) :\n  (v.to_orthonormal_basis hv : \u03b9 \u2192 E) = (v : \u03b9 \u2192 E) :=\ncalc (v.to_orthonormal_basis hv : \u03b9 \u2192 E) = ((v.to_orthonormal_basis hv).to_basis : \u03b9 \u2192 E) :\n  by { classical, rw orthonormal_basis.coe_to_basis }\n... = (v : \u03b9 \u2192 E) : by simp\n\n/-- An orthonormal set that spans is an orthonormal basis -/\nprotected def mk (hon : orthonormal \ud835\udd5c v) (hsp: submodule.span \ud835\udd5c (set.range v) = \u22a4):\n  orthonormal_basis \u03b9 \ud835\udd5c E :=\n(basis.mk (orthonormal.linear_independent hon) hsp).to_orthonormal_basis (by rwa basis.coe_mk)\n\n@[simp]\nprotected lemma coe_mk (hon : orthonormal \ud835\udd5c v) (hsp: submodule.span \ud835\udd5c (set.range v) = \u22a4) :\n  \u21d1(orthonormal_basis.mk hon hsp) = v :=\nby classical; rw [orthonormal_basis.mk, _root_.basis.coe_to_orthonormal_basis, basis.coe_mk]\n\nend orthonormal_basis\n\n/-- If `f : E \u2243\u2097\u1d62[\ud835\udd5c] E'` is a linear isometry of inner product spaces then an orthonormal basis `v`\nof `E` determines a linear isometry `e : E' \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9`. This result states that\n`e` may be obtained either by transporting `v` to `E'` or by composing with the linear isometry\n`E \u2243\u2097\u1d62[\ud835\udd5c] euclidean_space \ud835\udd5c \u03b9` provided by `v`. -/\n@[simp] lemma basis.map_isometry_euclidean_of_orthonormal (v : basis \u03b9 \ud835\udd5c E) (hv : orthonormal \ud835\udd5c v)\n  (f : E \u2243\u2097\u1d62[\ud835\udd5c] E') :\n  ((v.map f.to_linear_equiv).to_orthonormal_basis (hv.map_linear_isometry_equiv f)).repr =\n    f.symm.trans (v.to_orthonormal_basis hv).repr :=\nlinear_isometry_equiv.to_linear_equiv_injective $ v.map_equiv_fun _\n\n/-- `\u2102` is isometric to `\u211d\u00b2` with the Euclidean inner product. -/\ndef complex.isometry_euclidean : \u2102 \u2243\u2097\u1d62[\u211d] (euclidean_space \u211d (fin 2)) :=\n(complex.basis_one_I.to_orthonormal_basis\nbegin\n  rw orthonormal_iff_ite,\n  intros i, fin_cases i;\n  intros j; fin_cases j;\n  simp [real_inner_eq_re_inner]\nend).repr\n\n@[simp] lemma complex.isometry_euclidean_symm_apply (x : euclidean_space \u211d (fin 2)) :\n  complex.isometry_euclidean.symm x = (x 0) + (x 1) * I :=\nbegin\n  convert complex.basis_one_I.equiv_fun_symm_apply x,\n  { simpa },\n  { simp },\nend\n\nlemma complex.isometry_euclidean_proj_eq_self (z : \u2102) :\n  \u2191(complex.isometry_euclidean z 0) + \u2191(complex.isometry_euclidean z 1) * (I : \u2102) = z :=\nby rw [\u2190 complex.isometry_euclidean_symm_apply (complex.isometry_euclidean z),\n  complex.isometry_euclidean.symm_apply_apply z]\n\n@[simp] lemma complex.isometry_euclidean_apply_zero (z : \u2102) :\n  complex.isometry_euclidean z 0 = z.re :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\n@[simp] lemma complex.isometry_euclidean_apply_one (z : \u2102) :\n  complex.isometry_euclidean z 1 = z.im :=\nby { conv_rhs { rw \u2190 complex.isometry_euclidean_proj_eq_self z }, simp }\n\n/-- The isometry between `\u2102` and a two-dimensional real inner product space given by a basis. -/\ndef complex.isometry_of_orthonormal {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v) : \u2102 \u2243\u2097\u1d62[\u211d] F :=\ncomplex.isometry_euclidean.trans (v.to_orthonormal_basis hv).repr.symm\n\n@[simp] lemma complex.map_isometry_of_orthonormal {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v)\n  (f : F \u2243\u2097\u1d62[\u211d] F') :\n  complex.isometry_of_orthonormal (hv.map_linear_isometry_equiv f) =\n    (complex.isometry_of_orthonormal hv).trans f :=\nby simp [complex.isometry_of_orthonormal, linear_isometry_equiv.trans_assoc]\n\nlemma complex.isometry_of_orthonormal_symm_apply\n  {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v) (f : F) :\n  (complex.isometry_of_orthonormal hv).symm f = (v.coord 0 f : \u2102) + (v.coord 1 f : \u2102) * I :=\nby simp [complex.isometry_of_orthonormal]\n\nlemma complex.isometry_of_orthonormal_apply\n  {v : basis (fin 2) \u211d F} (hv : orthonormal \u211d v) (z : \u2102) :\n  complex.isometry_of_orthonormal hv z = z.re \u2022 v 0 + z.im \u2022 v 1 :=\nby simp [complex.isometry_of_orthonormal, (dec_trivial : (finset.univ : finset (fin 2)) = {0, 1})]\n\nopen finite_dimensional\n\n/-- Given a natural number `n` equal to the `finrank` of a finite-dimensional inner product space,\nthere exists an isometry from the space to `euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.of_inner_product_space\n  [finite_dimensional \ud835\udd5c E] {n : \u2115} (hn : finrank \ud835\udd5c E = n) :\n  E \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\n((fin_std_orthonormal_basis hn).to_orthonormal_basis\n  (fin_std_orthonormal_basis_orthonormal hn)).repr\n\nlocal attribute [instance] fact_finite_dimensional_of_finrank_eq_succ\n\n/-- Given a natural number `n` one less than the `finrank` of a finite-dimensional inner product\nspace, there exists an isometry from the orthogonal complement of a nonzero singleton to\n`euclidean_space \ud835\udd5c (fin n)`. -/\ndef linear_isometry_equiv.from_orthogonal_span_singleton\n  (n : \u2115) [fact (finrank \ud835\udd5c E = n + 1)] {v : E} (hv : v \u2260 0) :\n  (\ud835\udd5c \u2219 v)\u15ee \u2243\u2097\u1d62[\ud835\udd5c] (euclidean_space \ud835\udd5c (fin n)) :=\nlinear_isometry_equiv.of_inner_product_space (finrank_orthogonal_span_singleton hv)\n\nsection linear_isometry\n\nvariables {V : Type*} [inner_product_space \ud835\udd5c V] [finite_dimensional \ud835\udd5c V]\n\nvariables {S : submodule \ud835\udd5c V} {L : S \u2192\u2097\u1d62[\ud835\udd5c] V}\n\nopen finite_dimensional\n\n/-- Let `S` be a subspace of a finite-dimensional complex inner product space `V`.  A linear\nisometry mapping `S` into `V` can be extended to a full isometry of `V`.\n\nTODO:  The case when `S` is a finite-dimensional subspace of an infinite-dimensional `V`.-/\nnoncomputable def linear_isometry.extend (L : S \u2192\u2097\u1d62[\ud835\udd5c] V): V \u2192\u2097\u1d62[\ud835\udd5c] V :=\nbegin\n  -- Build an isometry from S\u15ee to L(S)\u15ee through euclidean_space\n  let d := finrank \ud835\udd5c S\u15ee,\n  have dim_S_perp : finrank \ud835\udd5c S\u15ee = d := rfl,\n  let LS := L.to_linear_map.range,\n  have E : S\u15ee \u2243\u2097\u1d62[\ud835\udd5c] LS\u15ee,\n  { have dim_LS_perp : finrank \ud835\udd5c LS\u15ee = d,\n    calc  finrank \ud835\udd5c LS\u15ee = finrank \ud835\udd5c V - finrank \ud835\udd5c LS : by simp only\n        [\u2190 LS.finrank_add_finrank_orthogonal, add_tsub_cancel_left]\n      ...               = finrank \ud835\udd5c V - finrank \ud835\udd5c S : by simp only\n        [linear_map.finrank_range_of_inj L.injective]\n      ...               = finrank \ud835\udd5c S\u15ee : by simp only\n        [\u2190 S.finrank_add_finrank_orthogonal, add_tsub_cancel_left]\n      ...               = d : dim_S_perp,\n    let BS := ((fin_std_orthonormal_basis dim_S_perp).to_orthonormal_basis\n      (fin_std_orthonormal_basis_orthonormal dim_S_perp)),\n    let BLS := ((fin_std_orthonormal_basis dim_LS_perp).to_orthonormal_basis\n      (fin_std_orthonormal_basis_orthonormal dim_LS_perp)),\n    exact BS.repr.trans BLS.repr.symm },\n  let L3 := (LS)\u15ee.subtype\u2097\u1d62.comp E.to_linear_isometry,\n  -- Project onto S and S\u15ee\n  haveI : complete_space S := finite_dimensional.complete \ud835\udd5c S,\n  haveI : complete_space V := finite_dimensional.complete \ud835\udd5c V,\n  let p1 := (orthogonal_projection S).to_linear_map,\n  let p2 := (orthogonal_projection S\u15ee).to_linear_map,\n  -- Build a linear map from the isometries on S and S\u15ee\n  let M := L.to_linear_map.comp p1 + L3.to_linear_map.comp p2,\n  -- Prove that M is an isometry\n  have M_norm_map : \u2200 (x : V), \u2225M x\u2225 = \u2225x\u2225,\n  { intro x,\n    -- Apply M to the orthogonal decomposition of x\n    have Mx_decomp : M x = L (p1 x) + L3 (p2 x),\n    { simp only [linear_map.add_apply, linear_map.comp_apply, linear_map.comp_apply,\n      linear_isometry.coe_to_linear_map]},\n    -- Mx_decomp is the orthogonal decomposition of M x\n    have Mx_orth : \u27ea L (p1 x), L3 (p2 x) \u27eb = 0,\n    { have Lp1x : L (p1 x) \u2208 L.to_linear_map.range := L.to_linear_map.mem_range_self (p1 x),\n      have Lp2x : L3 (p2 x) \u2208 (L.to_linear_map.range)\u15ee,\n      { simp only [L3, linear_isometry.coe_comp, function.comp_app, submodule.coe_subtype\u2097\u1d62,\n          \u2190 submodule.range_subtype (LS\u15ee)],\n        apply linear_map.mem_range_self},\n      apply submodule.inner_right_of_mem_orthogonal Lp1x Lp2x},\n    -- Apply the Pythagorean theorem and simplify\n    rw [\u2190 sq_eq_sq (norm_nonneg _) (norm_nonneg _), norm_sq_eq_add_norm_sq_projection x S],\n    simp only [sq, Mx_decomp],\n    rw norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (L (p1 x)) (L3 (p2 x)) Mx_orth,\n    simp only [linear_isometry.norm_map, p1, p2, continuous_linear_map.to_linear_map_eq_coe,\n      add_left_inj, mul_eq_mul_left_iff, norm_eq_zero, true_or, eq_self_iff_true,\n      continuous_linear_map.coe_coe, submodule.coe_norm, submodule.coe_eq_zero] },\n  exact { to_linear_map := M, norm_map' := M_norm_map },\nend\n\nlemma linear_isometry.extend_apply (L : S \u2192\u2097\u1d62[\ud835\udd5c] V) (s : S):\n  L.extend s = L s :=\nbegin\n  haveI : complete_space S := finite_dimensional.complete \ud835\udd5c S,\n  simp only [linear_isometry.extend, continuous_linear_map.to_linear_map_eq_coe,\n    \u2190linear_isometry.coe_to_linear_map],\n  simp only [add_right_eq_self, linear_isometry.coe_to_linear_map,\n    linear_isometry_equiv.coe_to_linear_isometry, linear_isometry.coe_comp, function.comp_app,\n    orthogonal_projection_mem_subspace_eq_self, linear_map.coe_comp, continuous_linear_map.coe_coe,\n    submodule.coe_subtype, linear_map.add_apply, submodule.coe_eq_zero,\n    linear_isometry_equiv.map_eq_zero_iff, submodule.coe_subtype\u2097\u1d62,\n    orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero,\n    submodule.orthogonal_orthogonal, submodule.coe_mem],\nend\n\nend linear_isometry\n\nsection matrix\n\nopen_locale matrix\n\nvariables {n m : \u2115}\n\nlocal notation `\u27ea`x`, `y`\u27eb\u2098` := @inner \ud835\udd5c (euclidean_space \ud835\udd5c (fin m)) _ x y\nlocal notation `\u27ea`x`, `y`\u27eb\u2099` := @inner \ud835\udd5c (euclidean_space \ud835\udd5c (fin n)) _ x y\n\n/-- The inner product of a row of A and a row of B is an entry of B \u2b1d A\u1d34. -/\nlemma inner_matrix_row_row (A B : matrix (fin n) (fin m) \ud835\udd5c) (i j : (fin n)) :\n  \u27eaA i, B j\u27eb\u2098 = (B \u2b1d A\u1d34) j i := by {simp only [inner, matrix.mul_apply, star_ring_end_apply,\n    matrix.conj_transpose_apply,mul_comm]}\n\n/-- The inner product of a column of A and a column of B is an entry of A\u1d34 \u2b1d B -/\nlemma inner_matrix_col_col (A B : matrix (fin n) (fin m) \ud835\udd5c) (i j : (fin m)) :\n  \u27eaA\u1d40 i, B\u1d40 j\u27eb\u2099 = (A\u1d34 \u2b1d B) i j := rfl\n\nend matrix\n\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/analysis/inner_product_space/pi_L2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7007688647476208}}
{"text": "/-\nCopyright (c) 2020 Kevin Kappelmann. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Kappelmann\n-/\nimport algebra.order.floor\nimport algebra.continued_fractions.basic\nimport algebra.order.field\n/-!\n# Computable Continued Fractions\n\n## Summary\n\nWe formalise the standard computation of (regular) continued fractions for linear ordered floor\nfields. The algorithm is rather simple. Here is an outline of the procedure adapted from Wikipedia:\n\nTake a value `v`. We call `\u230av\u230b` the *integer part* of `v` and `v \u2212 \u230av\u230b` the *fractional part* of\n`v`.  A continued fraction representation of `v` can then be given by `[\u230av\u230b; b\u2080, b\u2081, b\u2082,...]`, where\n`[b\u2080; b\u2081, b\u2082,...]` recursively is the continued fraction representation of `1 / (v \u2212 \u230av\u230b)`.  This\nprocess stops when the fractional part hits 0.\n\nIn other words: to calculate a continued fraction representation of a number `v`, write down the\ninteger part (i.e. the floor) of `v`. Subtract this integer part from `v`. If the difference is 0,\nstop; otherwise find the reciprocal of the difference and repeat. The procedure will terminate if\nand only if `v` is rational.\n\nFor an example, refer to `int_fract_pair.stream`.\n\n## Main definitions\n\n- `generalized_continued_fraction.int_fract_pair.stream`: computes the stream of integer and\n  fractional parts of a given value as described in the summary.\n- `generalized_continued_fraction.of`: computes the generalised continued fraction of a value `v`.\n  In fact, it computes a regular continued fraction that terminates if and only if `v` is rational\n  (those proofs will be added in a future commit).\n\n## Implementation Notes\n\nThere is an intermediate definition `generalized_continued_fraction.int_fract_pair.seq1` between\n`generalized_continued_fraction.int_fract_pair.stream` and `generalized_continued_fraction.of`\nto wire up things. User should not (need to) directly interact with it.\n\nThe computation of the integer and fractional pairs of a value can elegantly be\ncaptured by a recursive computation of a stream of option pairs. This is done in\n`int_fract_pair.stream`. However, the type then does not guarantee the first pair to always be\n`some` value, as expected by a continued fraction.\n\nTo separate concerns, we first compute a single head term that always exists in\n`generalized_continued_fraction.int_fract_pair.seq1` followed by the remaining stream of option\npairs. This sequence with a head term (`seq1`) is then transformed to a generalized continued\nfraction in `generalized_continued_fraction.of` by extracting the wanted integer parts of the\nhead term and the stream.\n\n## References\n\n- https://en.wikipedia.org/wiki/Continued_fraction\n\n## Tags\n\nnumerics, number theory, approximations, fractions\n-/\n\nnamespace generalized_continued_fraction\n\n-- Fix a carrier `K`.\nvariable (K : Type*)\n\n/--\nWe collect an integer part `b = \u230av\u230b` and fractional part `fr = v - \u230av\u230b` of a value `v` in a pair\n`\u27e8b, fr\u27e9`.\n-/\nstructure int_fract_pair := (b : \u2124) (fr : K)\n\nvariable {K}\n\n/-! Interlude: define some expected coercions and instances. -/\nnamespace int_fract_pair\n\n/-- Make an `int_fract_pair` printable. -/\ninstance [has_repr K] : has_repr (int_fract_pair K) :=\n\u27e8\u03bb p, \"(b : \" ++ (repr p.b) ++ \", fract : \" ++ (repr p.fr) ++ \")\"\u27e9\n\ninstance inhabited [inhabited K] : inhabited (int_fract_pair K) := \u27e8\u27e80, (default _)\u27e9\u27e9\n\n/--\nMaps a function `f` on the fractional components of a given pair.\n-/\ndef mapFr {\u03b2 : Type*} (f : K \u2192 \u03b2) (gp : int_fract_pair K) : int_fract_pair \u03b2 :=\n\u27e8gp.b, f gp.fr\u27e9\n\nsection coe\n/-! Interlude: define some expected coercions. -/\n/- Fix another type `\u03b2` which we will convert to. -/\nvariables {\u03b2 : Type*} [has_coe K \u03b2]\n\n/-- Coerce a pair by coercing the fractional component. -/\ninstance has_coe_to_int_fract_pair : has_coe (int_fract_pair K) (int_fract_pair \u03b2) :=\n\u27e8mapFr coe\u27e9\n\n@[simp, norm_cast]\nlemma coe_to_int_fract_pair {b : \u2124} {fr : K} :\n  (\u2191(int_fract_pair.mk b fr) : int_fract_pair \u03b2) = int_fract_pair.mk b (\u2191fr : \u03b2) :=\nrfl\n\nend coe\n\n-- Note: this could be relaxed to something like `linear_ordered_division_ring` in the\n-- future.\n/- Fix a discrete linear ordered field with `floor` function. -/\nvariables [linear_ordered_field K] [floor_ring K]\n\n/-- Creates the integer and fractional part of a value `v`, i.e. `\u27e8\u230av\u230b, v - \u230av\u230b\u27e9`. -/\nprotected def of (v : K) : int_fract_pair K := \u27e8\u230av\u230b, int.fract v\u27e9\n\n/--\nCreates the stream of integer and fractional parts of a value `v` needed to obtain the continued\nfraction representation of `v` in `generalized_continued_fraction.of`. More precisely, given a value\n`v : K`, it recursively computes a stream of option `\u2124 \u00d7 K` pairs as follows:\n- `stream v 0 = some \u27e8\u230av\u230b, v - \u230av\u230b\u27e9`\n- `stream v (n + 1) = some \u27e8\u230afr\u2099\u207b\u00b9\u230b, fr\u2099\u207b\u00b9 - \u230afr\u2099\u207b\u00b9\u230b\u27e9`,\n    if `stream v n = some \u27e8_, fr\u2099\u27e9` and `fr\u2099 \u2260 0`\n- `stream v (n + 1) = none`, otherwise\n\nFor example, let `(v : \u211a) := 3.4`. The process goes as follows:\n- `stream v 0 = some \u27e8\u230av\u230b, v - \u230av\u230b\u27e9 = some \u27e83, 0.4\u27e9`\n- `stream v 1 = some \u27e8\u230a0.4\u207b\u00b9\u230b, 0.4\u207b\u00b9 - \u230a0.4\u207b\u00b9\u230b\u27e9 = some \u27e8\u230a2.5\u230b, 2.5 - \u230a2.5\u230b\u27e9 = some \u27e82, 0.5\u27e9`\n- `stream v 2 = some \u27e8\u230a0.5\u207b\u00b9\u230b, 0.5\u207b\u00b9 - \u230a0.5\u207b\u00b9\u230b\u27e9 = some \u27e8\u230a2\u230b, 2 - \u230a2\u230b\u27e9 = some \u27e82, 0\u27e9`\n- `stream v n = none`, for `n \u2265 3`\n-/\nprotected def stream (v : K) : stream $ option (int_fract_pair K)\n| 0 := some (int_fract_pair.of v)\n| (n + 1) := do ap_n \u2190 stream n,\n  if ap_n.fr = 0 then none else int_fract_pair.of ap_n.fr\u207b\u00b9\n\n/--\nShows that `int_fract_pair.stream` has the sequence property, that is once we return `none` at\nposition `n`, we also return `none` at `n + 1`.\n-/\nlemma stream_is_seq (v : K) : (int_fract_pair.stream v).is_seq :=\nby { assume _ hyp, simp [int_fract_pair.stream, hyp] }\n\n/--\nUses `int_fract_pair.stream` to create a sequence with head (i.e. `seq1`) of integer and fractional\nparts of a value `v`. The first value of `int_fract_pair.stream` is never `none`, so we can safely\nextract it and put the tail of the stream in the sequence part.\n\nThis is just an intermediate representation and users should not (need to) directly interact with\nit. The setup of rewriting/simplification lemmas that make the definitions easy to use is done in\n`algebra.continued_fractions.computation.translations`.\n-/\nprotected def seq1 (v : K) : seq1 $ int_fract_pair K :=\n\u27e8 int_fract_pair.of v,--the head\n  seq.tail -- take the tail of `int_fract_pair.stream` since the first element is already in the\n  -- head create a sequence from `int_fract_pair.stream`\n  \u27e8 int_fract_pair.stream v, -- the underlying stream\n    @stream_is_seq _ _ _ v \u27e9 \u27e9 -- the proof that the stream is a sequence\n\nend int_fract_pair\n\n/--\nReturns the `generalized_continued_fraction` of a value. In fact, the returned gcf is also\na `continued_fraction` that terminates if and only if `v` is rational (those proofs will be\nadded in a future commit).\n\nThe continued fraction representation of `v` is given by `[\u230av\u230b; b\u2080, b\u2081, b\u2082,...]`, where\n`[b\u2080; b\u2081, b\u2082,...]` recursively is the continued fraction representation of `1 / (v \u2212 \u230av\u230b)`. This\nprocess stops when the fractional part `v - \u230av\u230b` hits 0 at some step.\n\nThe implementation uses `int_fract_pair.stream` to obtain the partial denominators of the continued\nfraction. Refer to said function for more details about the computation process.\n-/\nprotected def of [linear_ordered_field K] [floor_ring K] (v : K) :\n  generalized_continued_fraction K :=\nlet \u27e8h, s\u27e9 := int_fract_pair.seq1 v in -- get the sequence of integer and fractional parts.\n\u27e8 h.b, -- the head is just the first integer part\n  s.map (\u03bb p, \u27e81, p.b\u27e9) \u27e9 -- the sequence consists of the remaining integer parts as the partial\n                          -- denominators; all partial numerators are simply 1\n\n\nend generalized_continued_fraction\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/algebra/continued_fractions/computation/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.7007272736900763}}
{"text": "import .affine_coordinate_space \n\n/-\nThis file exports \n- std_basis, given finite index set, return standard vector-space basis\n- std_frame, return standard frame on d-dimensional affine space\n-/\n\n/-\nWe've shown that <aff_pt_coord_tuple, aff_vec_coord_tuple> \nconstitutes an  affine space.There's no notion of a frame at this point. \nHowever,  we can endow such a space with a standard frame, taking the point,\n<1, 0, ..., 0> as the standard origin and the vectors, <0, 1, 0, ...>,\n..., <0, 0, ..., 1> as the standard basis for the vector space. To \nthis end, we now define what it means to be a frame for an affine space\nand we provide a function for obtaining a standard basis for any given\nspace of this kind.\n-/\n\n\nnamespace aff_basis\n\nuniverses u v w x\n\nvariables (X : Type u) (K : Type v) (V : Type w) (n : \u2115) (k : K)\n[inhabited K] [field K] [add_comm_group V] [vector_space K V] [affine_space V X]\n\nopen vecl\n\nabbreviation zero := zero_vector K n\n\ndef list.to_basis_vec : fin n \u2192 list K := \u03bb x, (zero K n).update_nth (x.1 + 1) 1\n\nlemma len_basis_vec_fixed (x : fin n) : (list.to_basis_vec K n x).length = n + 1 := sorry\n\nlemma head_basis_vec_fixed (x : fin n) : (list.to_basis_vec K n x).head = 0 := sorry\n\ndef std_basis : fin n \u2192 aff_vec_coord_tuple K n :=\n\u03bb x, \u27e8list.to_basis_vec K n x, len_basis_vec_fixed K n x, head_basis_vec_fixed K n x\u27e9\n\n\nlemma std_is_basis : is_basis K (std_basis K n) := sorry\n\n/-\nHere we equip any generic affine coordinate space with a standard frame\n-/\ndef aff_coord_space_std_frame : \n    affine_frame (aff_pt_coord_tuple K n) K (aff_vec_coord_tuple K n) (fin n) := \n        \u27e8pt_zero K n, std_basis K n, std_is_basis K n\u27e9\n\nend aff_basis\n\n/-\nWhat's funny is that we don't actually have an explicit abstraction of \naffine coordinate space, e.g., as a type.\n-/", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/old/new_affine/affine_coordinate_frame.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7007272702488251}}
{"text": "/-\nCopyright (c) 2019 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad\n-/\nimport order.filter.basic\nimport data.pfun\n\n/-!\n# `tendsto` for relations and partial functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file generalizes `filter` definitions from functions to partial functions and relations.\n\n## Considering functions and partial functions as relations\n\nA function `f : \u03b1 \u2192 \u03b2` can be considered as the relation `rel \u03b1 \u03b2` which relates `x` and `f x` for\nall `x`, and nothing else. This relation is called `function.graph f`.\n\nA partial function `f : \u03b1 \u2192. \u03b2` can be considered as the relation `rel \u03b1 \u03b2` which relates `x` and\n`f x` for all `x` for which `f x` exists, and nothing else. This relation is called\n`pfun.graph' f`.\n\nIn this regard, a function is a relation for which every element in `\u03b1` is related to exactly one\nelement in `\u03b2` and a partial function is a relation for which every element in `\u03b1` is related to at\nmost one element in `\u03b2`.\n\nThis file leverages this analogy to generalize `filter` definitions from functions to partial\nfunctions and relations.\n\n## Notes\n\n`set.preimage` can be generalized to relations in two ways:\n* `rel.preimage` returns the image of the set under the inverse relation.\n* `rel.core` returns the set of elements that are only related to those in the set.\nBoth generalizations are sensible in the context of filters, so `filter.comap` and `filter.tendsto`\nget two generalizations each.\n\nWe first take care of relations. Then the definitions for partial functions are taken as special\ncases of the definitions for relations.\n-/\n\nuniverses u v w\nnamespace filter\nvariables {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w}\n\nopen_locale filter\n\n/-! ### Relations -/\n\n/-- The forward map of a filter under a relation. Generalization of `filter.map` to relations. Note\nthat `rel.core` generalizes `set.preimage`. -/\ndef rmap (r : rel \u03b1 \u03b2) (l : filter \u03b1) : filter \u03b2 :=\n{ sets             := {s | r.core s \u2208 l},\n  univ_sets        := by simp,\n  sets_of_superset := \u03bb s t hs st, mem_of_superset hs $ rel.core_mono _ st,\n  inter_sets       := \u03bb s t hs ht, by simp [rel.core_inter, inter_mem hs ht] }\n\ntheorem rmap_sets (r : rel \u03b1 \u03b2) (l : filter \u03b1) : (l.rmap r).sets = r.core \u207b\u00b9' l.sets := rfl\n\n@[simp]\ntheorem mem_rmap (r : rel \u03b1 \u03b2) (l : filter \u03b1) (s : set \u03b2) :\n  s \u2208 l.rmap r \u2194 r.core s \u2208 l :=\niff.rfl\n\n@[simp]\ntheorem rmap_rmap (r : rel \u03b1 \u03b2) (s : rel \u03b2 \u03b3) (l : filter \u03b1) :\n  rmap s (rmap r l) = rmap (r.comp s) l :=\nfilter_eq $\nby simp [rmap_sets, set.preimage, rel.core_comp]\n\n@[simp]\nlemma rmap_compose (r : rel \u03b1 \u03b2) (s : rel \u03b2 \u03b3) : rmap s \u2218 rmap r = rmap (r.comp s) :=\nfunext $ rmap_rmap _ _\n\n/-- Generic \"limit of a relation\" predicate. `rtendsto r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `r`-core of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to relations. -/\ndef rtendsto (r : rel \u03b1 \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) := l\u2081.rmap r \u2264 l\u2082\n\ntheorem rtendsto_def (r : rel \u03b1 \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) :\n  rtendsto r l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, r.core s \u2208 l\u2081 :=\niff.rfl\n\n/-- One way of taking the inverse map of a filter under a relation. One generalization of\n`filter.comap` to relations. Note that `rel.core` generalizes `set.preimage`. -/\ndef rcomap (r : rel \u03b1 \u03b2) (f : filter \u03b2) : filter \u03b1 :=\n{ sets             := rel.image (\u03bb s t, r.core s \u2286 t) f.sets,\n  univ_sets        := \u27e8set.univ, univ_mem, set.subset_univ _\u27e9,\n  sets_of_superset := \u03bb a b \u27e8a', ha', ma'a\u27e9 ab, \u27e8a', ha', ma'a.trans ab\u27e9,\n  inter_sets       := \u03bb a b \u27e8a', ha\u2081, ha\u2082\u27e9 \u27e8b', hb\u2081, hb\u2082\u27e9,\n                        \u27e8a' \u2229 b', inter_mem ha\u2081 hb\u2081,\n                          (r.core_inter a' b').subset.trans (set.inter_subset_inter ha\u2082 hb\u2082)\u27e9 }\n\ntheorem rcomap_sets (r : rel \u03b1 \u03b2) (f : filter \u03b2) :\n  (rcomap r f).sets = rel.image (\u03bb s t, r.core s \u2286 t) f.sets := rfl\n\n\ntheorem rcomap_rcomap (r : rel \u03b1 \u03b2) (s : rel \u03b2 \u03b3) (l : filter \u03b3) :\n  rcomap r (rcomap s l) = rcomap (r.comp s) l :=\nfilter_eq $\nbegin\n  ext t, simp [rcomap_sets, rel.image, rel.core_comp], split,\n  { rintros \u27e8u, \u27e8v, vsets, hv\u27e9, h\u27e9,\n    exact \u27e8v, vsets, set.subset.trans (rel.core_mono _ hv) h\u27e9 },\n  rintros \u27e8t, tsets, ht\u27e9,\n  exact \u27e8rel.core s t, \u27e8t, tsets, set.subset.rfl\u27e9, ht\u27e9\nend\n\n@[simp]\nlemma rcomap_compose (r : rel \u03b1 \u03b2) (s : rel \u03b2 \u03b3) : rcomap r \u2218 rcomap s = rcomap (r.comp s) :=\nfunext $ rcomap_rcomap _ _\n\ntheorem rtendsto_iff_le_rcomap (r : rel \u03b1 \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) :\n  rtendsto r l\u2081 l\u2082 \u2194 l\u2081 \u2264 l\u2082.rcomap r :=\nbegin\n  rw rtendsto_def,\n  change (\u2200 (s : set \u03b2), s \u2208 l\u2082.sets \u2192 r.core s \u2208 l\u2081) \u2194 l\u2081 \u2264 rcomap r l\u2082,\n  simp [filter.le_def, rcomap, rel.mem_image], split,\n  { exact \u03bb h s t tl\u2082, mem_of_superset (h t tl\u2082) },\n  { exact \u03bb h t tl\u2082, h _ t tl\u2082 set.subset.rfl }\nend\n\n-- Interestingly, there does not seem to be a way to express this relation using a forward map.\n-- Given a filter `f` on `\u03b1`, we want a filter `f'` on `\u03b2` such that `r.preimage s \u2208 f` if\n-- and only if `s \u2208 f'`. But the intersection of two sets satisfying the lhs may be empty.\n\n/-- One way of taking the inverse map of a filter under a relation. Generalization of `filter.comap`\nto relations. -/\ndef rcomap' (r : rel \u03b1 \u03b2) (f : filter \u03b2) : filter \u03b1 :=\n{ sets             := rel.image (\u03bb s t, r.preimage s \u2286 t) f.sets,\n  univ_sets        := \u27e8set.univ, univ_mem, set.subset_univ _\u27e9,\n  sets_of_superset := \u03bb a b \u27e8a', ha', ma'a\u27e9 ab, \u27e8a', ha', ma'a.trans ab\u27e9,\n  inter_sets       := \u03bb a b \u27e8a', ha\u2081, ha\u2082\u27e9 \u27e8b', hb\u2081, hb\u2082\u27e9,\n                        \u27e8a' \u2229 b', inter_mem ha\u2081 hb\u2081,\n                         (@rel.preimage_inter _ _ r _ _).trans (set.inter_subset_inter ha\u2082 hb\u2082)\u27e9 }\n\n@[simp]\nlemma mem_rcomap' (r : rel \u03b1 \u03b2) (l : filter \u03b2) (s : set \u03b1) :\n  s \u2208 l.rcomap' r \u2194 \u2203 t \u2208 l, r.preimage t \u2286 s :=\niff.rfl\n\ntheorem rcomap'_sets (r : rel \u03b1 \u03b2) (f : filter \u03b2) :\n  (rcomap' r f).sets = rel.image (\u03bb s t, r.preimage s \u2286 t) f.sets := rfl\n\n@[simp]\ntheorem rcomap'_rcomap' (r : rel \u03b1 \u03b2) (s : rel \u03b2 \u03b3) (l : filter \u03b3) :\n  rcomap' r (rcomap' s l) = rcomap' (r.comp s) l :=\nfilter.ext $ \u03bb t,\nbegin\n  simp [rcomap'_sets, rel.image, rel.preimage_comp], split,\n  { rintro \u27e8u, \u27e8v, vsets, hv\u27e9, h\u27e9,\n    exact \u27e8v, vsets, (rel.preimage_mono _ hv).trans h\u27e9 },\n  rintro \u27e8t, tsets, ht\u27e9,\n  exact \u27e8s.preimage t, \u27e8t, tsets, set.subset.rfl\u27e9, ht\u27e9\nend\n\n@[simp]\nlemma rcomap'_compose (r : rel \u03b1 \u03b2) (s : rel \u03b2 \u03b3) : rcomap' r \u2218 rcomap' s = rcomap' (r.comp s) :=\nfunext $ rcomap'_rcomap' _ _\n\n/-- Generic \"limit of a relation\" predicate. `rtendsto' r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `r`-preimage of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to relations. -/\ndef rtendsto' (r : rel \u03b1 \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) := l\u2081 \u2264 l\u2082.rcomap' r\n\ntheorem rtendsto'_def (r : rel \u03b1 \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) :\n  rtendsto' r l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, r.preimage s \u2208 l\u2081 :=\nbegin\n  unfold rtendsto' rcomap', simp [le_def, rel.mem_image], split,\n  { exact \u03bb h s hs, h _ _ hs set.subset.rfl },\n  { exact \u03bb h s t ht, mem_of_superset (h t ht) }\nend\n\ntheorem tendsto_iff_rtendsto (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) (f : \u03b1 \u2192 \u03b2) :\n  tendsto f l\u2081 l\u2082 \u2194 rtendsto (function.graph f) l\u2081 l\u2082 :=\nby { simp [tendsto_def, function.graph, rtendsto_def, rel.core, set.preimage] }\n\ntheorem tendsto_iff_rtendsto' (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) (f : \u03b1 \u2192 \u03b2) :\n  tendsto f l\u2081 l\u2082 \u2194 rtendsto' (function.graph f) l\u2081 l\u2082 :=\nby { simp [tendsto_def, function.graph, rtendsto'_def, rel.preimage_def, set.preimage] }\n\n/-! ### Partial functions -/\n\n/-- The forward map of a filter under a partial function. Generalization of `filter.map` to partial\nfunctions. -/\ndef pmap (f : \u03b1 \u2192. \u03b2) (l : filter \u03b1) : filter \u03b2 :=\nfilter.rmap f.graph' l\n\n@[simp]\nlemma mem_pmap (f : \u03b1 \u2192. \u03b2) (l : filter \u03b1) (s : set \u03b2) : s \u2208 l.pmap f \u2194 f.core s \u2208 l :=\niff.rfl\n\n/-- Generic \"limit of a partial function\" predicate. `ptendsto r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `p`-core of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to partial function. -/\ndef ptendsto (f : \u03b1 \u2192. \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) := l\u2081.pmap f \u2264 l\u2082\n\ntheorem ptendsto_def (f : \u03b1 \u2192. \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) :\n  ptendsto f l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, f.core s \u2208 l\u2081 :=\niff.rfl\n\ntheorem ptendsto_iff_rtendsto (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) (f : \u03b1 \u2192. \u03b2) :\n  ptendsto f l\u2081 l\u2082 \u2194 rtendsto f.graph' l\u2081 l\u2082 :=\niff.rfl\n\ntheorem pmap_res (l : filter \u03b1) (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  pmap (pfun.res f s) l = map f (l \u2293 \ud835\udcdf s) :=\nbegin\n  ext t,\n  simp only [pfun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or],\n  refl\nend\n\ntheorem tendsto_iff_ptendsto (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) (s : set \u03b1) (f : \u03b1 \u2192 \u03b2) :\n  tendsto f (l\u2081 \u2293 \ud835\udcdf s) l\u2082 \u2194 ptendsto (pfun.res f s) l\u2081 l\u2082 :=\nby simp only [tendsto, ptendsto, pmap_res]\n\ntheorem tendsto_iff_ptendsto_univ (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) (f : \u03b1 \u2192 \u03b2) :\n  tendsto f l\u2081 l\u2082 \u2194 ptendsto (pfun.res f set.univ) l\u2081 l\u2082 :=\nby { rw \u2190 tendsto_iff_ptendsto, simp [principal_univ] }\n\n/-- Inverse map of a filter under a partial function. One generalization of `filter.comap` to\npartial functions. -/\ndef pcomap' (f : \u03b1 \u2192. \u03b2) (l : filter \u03b2) : filter \u03b1 :=\nfilter.rcomap' f.graph' l\n\n/-- Generic \"limit of a partial function\" predicate. `ptendsto' r l\u2081 l\u2082` asserts that for every\n`l\u2082`-neighborhood `a`, the `p`-preimage of `a` is an `l\u2081`-neighborhood. One generalization of\n`filter.tendsto` to partial functions. -/\ndef ptendsto' (f : \u03b1 \u2192. \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) := l\u2081 \u2264 l\u2082.rcomap' f.graph'\n\ntheorem ptendsto'_def (f : \u03b1 \u2192. \u03b2) (l\u2081 : filter \u03b1) (l\u2082 : filter \u03b2) :\n  ptendsto' f l\u2081 l\u2082 \u2194 \u2200 s \u2208 l\u2082, f.preimage s \u2208 l\u2081 :=\nrtendsto'_def _ _ _\n\ntheorem ptendsto_of_ptendsto' {f : \u03b1 \u2192. \u03b2} {l\u2081 : filter \u03b1} {l\u2082 : filter \u03b2} :\n  ptendsto' f l\u2081 l\u2082 \u2192 ptendsto f l\u2081 l\u2082 :=\nbegin\n  rw [ptendsto_def, ptendsto'_def],\n  exact \u03bb h s sl\u2082, mem_of_superset (h s sl\u2082) (pfun.preimage_subset_core _ _),\nend\n\ntheorem ptendsto'_of_ptendsto {f : \u03b1 \u2192. \u03b2} {l\u2081 : filter \u03b1} {l\u2082 : filter \u03b2} (h : f.dom \u2208 l\u2081) :\n  ptendsto f l\u2081 l\u2082 \u2192 ptendsto' f l\u2081 l\u2082 :=\nbegin\n  rw [ptendsto_def, ptendsto'_def],\n  intros h' s sl\u2082,\n  rw pfun.preimage_eq,\n  exact inter_mem (h' s sl\u2082) h\nend\n\nend filter\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/order/filter/partial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7006465653792309}}
{"text": "/-\nCopyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bryan Gin-ge Chen\n-/\n\nimport tactic.ring\nimport tactic.abel\n\n/-!\n# Boolean rings\n\nA Boolean ring is a ring where multiplication is idempotent. They are equivalent to Boolean\nalgebras.\n\n## Main declarations\n\n* `boolean_ring`: a typeclass for rings where multiplication is idempotent.\n* `boolean_ring.to_boolean_algebra`: every Boolean ring is a Boolean algebra; this definition and\n  the `sup` and `inf` notations for `boolean_ring` are localized as instances in the\n  `boolean_algebra_of_boolean_ring` locale.\n\n## Tags\n\nboolean ring, boolean algebra\n\n-/\n\n/-- A Boolean ring is a ring where multiplication is idempotent. -/\nclass boolean_ring \u03b1 extends ring \u03b1 :=\n(mul_self : \u2200 a : \u03b1, a * a = a)\n\nsection boolean_ring\nvariables {\u03b1 : Type*} [boolean_ring \u03b1] (a b : \u03b1)\n\ninstance : is_idempotent \u03b1 (*) := \u27e8boolean_ring.mul_self\u27e9\n\n@[simp] lemma mul_self : a * a = a := boolean_ring.mul_self _\n\n@[simp] lemma add_self : a + a = 0 :=\nhave a + a = a + a + (a + a) :=\n  calc a + a = (a+a) * (a+a)           : by rw mul_self\n         ... = a*a + a*a + (a*a + a*a) : by rw [add_mul, mul_add]\n         ... = a + a + (a + a)         : by rw mul_self,\nby rwa self_eq_add_left at this\n\n@[simp] lemma neg_eq : -a = a :=\ncalc -a = -a + 0      : by rw add_zero\n    ... = -a + -a + a : by rw [\u2190neg_add_self, add_assoc]\n    ... = a           : by rw [add_self, zero_add]\n\nlemma add_eq_zero : a + b = 0 \u2194 a = b :=\ncalc a + b = 0 \u2194 a = -b : add_eq_zero_iff_eq_neg\n           ... \u2194 a = b  : by rw neg_eq\n\n@[simp] lemma mul_add_mul : a*b + b*a = 0 :=\nhave a + b = a + b + (a*b + b*a) :=\n  calc a + b = (a + b) * (a + b)       : by rw mul_self\n         ... = a*a + a*b + (b*a + b*b) : by rw [add_mul, mul_add, mul_add]\n         ... = a + a*b + (b*a + b)     : by simp only [mul_self]\n         ... = a + b + (a*b + b*a)     : by abel,\nby rwa self_eq_add_right at this\n\n@[simp] lemma sub_eq_add : a - b = a + b :=\nby rw [sub_eq_add_neg, add_right_inj, neg_eq]\n\n@[simp] lemma mul_one_add_self : a * (1 + a) = 0 := by rw [mul_add, mul_one, mul_self, add_self]\n\nend boolean_ring\n\nnamespace boolean_ring\nvariables {\u03b1 : Type*} [boolean_ring \u03b1]\n\n@[priority 100] -- Note [lower instance priority]\ninstance : comm_ring \u03b1 :=\n{ mul_comm := \u03bb a b, by rw [\u2190add_eq_zero, mul_add_mul],\n  .. (infer_instance : boolean_ring \u03b1) }\n\n/-- The join operation in a Boolean ring is `x + y + x*y`. -/\ndef has_sup : has_sup \u03b1 := \u27e8\u03bb x y, x + y + x*y\u27e9\n/-- The meet operation in a Boolean ring is `x * y`. -/\ndef has_inf : has_inf \u03b1 := \u27e8(*)\u27e9\n\n-- Note [lower instance priority]\nlocalized \"attribute [instance, priority 100] boolean_ring.has_sup\" in\n  boolean_algebra_of_boolean_ring\nlocalized \"attribute [instance, priority 100] boolean_ring.has_inf\" in\n  boolean_algebra_of_boolean_ring\n\nlemma sup_comm (a b : \u03b1) : a \u2294 b = b \u2294 a := by { dsimp only [(\u2294)], ring }\nlemma inf_comm (a b : \u03b1) : a \u2293 b = b \u2293 a := by { dsimp only [(\u2293)], ring }\n\nlemma sup_assoc (a b c : \u03b1) : a \u2294 b \u2294 c = a \u2294 (b \u2294 c) := by { dsimp only [(\u2294)], ring }\nlemma inf_assoc (a b c : \u03b1) : a \u2293 b \u2293 c = a \u2293 (b \u2293 c) := by { dsimp only [(\u2293)], ring }\n\nlemma sup_inf_self (a b : \u03b1) : a \u2294 a \u2293 b = a :=\nby { dsimp only [(\u2294), (\u2293)], assoc_rw [mul_self, add_self, add_zero] }\nlemma inf_sup_self (a b : \u03b1) : a \u2293 (a \u2294 b) = a :=\nby { dsimp only [(\u2294), (\u2293)], assoc_rw [mul_add, mul_add, mul_self, mul_self, add_self, add_zero] }\n\n\n\nlemma le_sup_inf (a b c : \u03b1) : (a \u2294 b) \u2293 (a \u2294 c) \u2294 (a \u2294 b \u2293 c) = a \u2294 b \u2293 c :=\nby { dsimp only [(\u2294), (\u2293)], rw [le_sup_inf_aux, add_self, mul_self, zero_add] }\n\n/-- The \"set difference\" operation in a Boolean ring is `x * (1 + y)`. -/\ndef has_sdiff : has_sdiff \u03b1 := \u27e8\u03bb a b, a * (1 + b)\u27e9\n/-- The bottom element of a Boolean ring is `0`. -/\ndef has_bot : has_bot \u03b1 := \u27e80\u27e9\n\nlocalized \"attribute [instance, priority 100] boolean_ring.has_sdiff\" in\n  boolean_algebra_of_boolean_ring\nlocalized \"attribute [instance, priority 100] boolean_ring.has_bot\" in\n  boolean_algebra_of_boolean_ring\n\nlemma sup_inf_sdiff (a b : \u03b1) : a \u2293 b \u2294 a \\ b = a :=\ncalc a * b + a * (1 + b) + (a * b) * (a * (1 + b)) =\n       a * b + a * (1 + b) + a * a * (b * (1 + b)) : by ac_refl\n... = a * b + (a + a * b)           : by rw [mul_one_add_self, mul_zero, add_zero, mul_add, mul_one]\n... = a + (a * b + a * b)                          : by ac_refl\n... = a                                            : by rw [add_self, add_zero]\n\nlemma inf_inf_sdiff (a b : \u03b1) : a \u2293 b \u2293 (a \\ b) = \u22a5 :=\ncalc a * b * (a * (1 + b)) = a * a * (b * (1 + b)) : by ac_refl\n                       ... = 0                     : by rw [mul_one_add_self, mul_zero]\n\n/--\nThe Boolean algebra structure on a Boolean ring.\n\nThe data is defined so that:\n* `a \u2294 b` unfolds to `a + b + a * b`\n* `a \u2293 b` unfolds to `a * b`\n* `a \u2264 b` unfolds to `a + b + a * b = b`\n* `\u22a5` unfolds to `0`\n* `\u22a4` unfolds to `1`\n* `a\u1d9c` unfolds to `1 + a`\n* `a \\ b` unfolds to `a * (1 + b)`\n-/\ndef to_boolean_algebra : boolean_algebra \u03b1 :=\n{ le_sup_inf := le_sup_inf,\n  top := 1,\n  le_top := \u03bb a, show a + 1 + a * 1 = 1, by assoc_rw [mul_one, add_comm, add_self, add_zero],\n  bot_le := \u03bb a, show 0 + a + 0 * a = a, by rw [zero_mul, zero_add, add_zero],\n  compl := \u03bb a, 1 + a,\n  sup_inf_sdiff := sup_inf_sdiff,\n  inf_inf_sdiff := inf_inf_sdiff,\n  inf_compl_le_bot := \u03bb a,\n    show a*(1+a) + 0 + a*(1+a)*0 = 0,\n    by norm_num [mul_add, mul_self, add_self],\n  top_le_sup_compl := \u03bb a,\n    begin\n      change 1 + (a + (1+a) + a*(1+a)) + 1*(a + (1+a) + a*(1+a)) = a + (1+a) + a*(1+a),\n      norm_num [mul_add, mul_self],\n      rw [\u2190add_assoc, add_self],\n    end,\n  sdiff_eq := \u03bb a b, rfl,\n  .. lattice.mk' sup_comm sup_assoc inf_comm inf_assoc sup_inf_self inf_sup_self,\n  .. has_sdiff,\n  .. has_bot }\n\nlocalized \"attribute [instance, priority 100] boolean_ring.to_boolean_algebra\" in\n  boolean_algebra_of_boolean_ring\n\nend boolean_ring\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/algebra/ring/boolean_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7006465588271344}}
{"text": "/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura, Mario Carneiro\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.equiv.basic\nimport Mathlib.algebra.group.basic\nimport Mathlib.algebra.group.hom\nimport Mathlib.algebra.group.pi\nimport Mathlib.algebra.group.prod\nimport Mathlib.PostPort\n\nuniverses u u_1 u_2 \n\nnamespace Mathlib\n\n/-!\n# The group of permutations (self-equivalences) of a type `\u03b1`\n\nThis file defines the `group` structure on `equiv.perm \u03b1`.\n-/\n\nnamespace equiv\n\n\nnamespace perm\n\n\nprotected instance perm_group {\u03b1 : Type u} : group (perm \u03b1) :=\n  group.mk (fun (f g : perm \u03b1) => equiv.trans g f) sorry (equiv.refl \u03b1) sorry sorry equiv.symm\n    (div_inv_monoid.div._default (fun (f g : perm \u03b1) => equiv.trans g f) sorry (equiv.refl \u03b1) sorry sorry equiv.symm)\n    sorry\n\ntheorem mul_apply {\u03b1 : Type u} (f : perm \u03b1) (g : perm \u03b1) (x : \u03b1) : coe_fn (f * g) x = coe_fn f (coe_fn g x) :=\n  trans_apply g f x\n\ntheorem one_apply {\u03b1 : Type u} (x : \u03b1) : coe_fn 1 x = x :=\n  rfl\n\n@[simp] theorem inv_apply_self {\u03b1 : Type u} (f : perm \u03b1) (x : \u03b1) : coe_fn (f\u207b\u00b9) (coe_fn f x) = x :=\n  symm_apply_apply f x\n\n@[simp] theorem apply_inv_self {\u03b1 : Type u} (f : perm \u03b1) (x : \u03b1) : coe_fn f (coe_fn (f\u207b\u00b9) x) = x :=\n  apply_symm_apply f x\n\ntheorem one_def {\u03b1 : Type u} : 1 = equiv.refl \u03b1 :=\n  rfl\n\ntheorem mul_def {\u03b1 : Type u} (f : perm \u03b1) (g : perm \u03b1) : f * g = equiv.trans g f :=\n  rfl\n\ntheorem inv_def {\u03b1 : Type u} (f : perm \u03b1) : f\u207b\u00b9 = equiv.symm f :=\n  rfl\n\n@[simp] theorem coe_mul {\u03b1 : Type u} (f : perm \u03b1) (g : perm \u03b1) : \u21d1(f * g) = \u21d1f \u2218 \u21d1g :=\n  rfl\n\n@[simp] theorem coe_one {\u03b1 : Type u} : \u21d11 = id :=\n  rfl\n\ntheorem eq_inv_iff_eq {\u03b1 : Type u} {f : perm \u03b1} {x : \u03b1} {y : \u03b1} : x = coe_fn (f\u207b\u00b9) y \u2194 coe_fn f x = y :=\n  eq_symm_apply f\n\ntheorem inv_eq_iff_eq {\u03b1 : Type u} {f : perm \u03b1} {x : \u03b1} {y : \u03b1} : coe_fn (f\u207b\u00b9) x = y \u2194 x = coe_fn f y :=\n  symm_apply_eq f\n\n/-! Lemmas about mixing `perm` with `equiv`. Because we have multiple ways to express\n`equiv.refl`, `equiv.symm`, and `equiv.trans`, we want simp lemmas for every combination.\nThe assumption made here is that if you're using the group structure, you want to preserve it after\nsimp. -/\n\n@[simp] theorem trans_one {\u03b1 : Sort u_1} {\u03b2 : Type u_2} (e : \u03b1 \u2243 \u03b2) : equiv.trans e 1 = e :=\n  trans_refl e\n\n@[simp] theorem mul_refl {\u03b1 : Type u} (e : perm \u03b1) : e * equiv.refl \u03b1 = e :=\n  trans_refl e\n\n@[simp] theorem one_symm {\u03b1 : Type u} : equiv.symm 1 = 1 :=\n  refl_symm\n\n@[simp] theorem refl_inv {\u03b1 : Type u} : equiv.refl \u03b1\u207b\u00b9 = 1 :=\n  refl_symm\n\n@[simp] theorem one_trans {\u03b1 : Type u_1} {\u03b2 : Sort u_2} (e : \u03b1 \u2243 \u03b2) : equiv.trans 1 e = e :=\n  refl_trans e\n\n@[simp] theorem refl_mul {\u03b1 : Type u} (e : perm \u03b1) : equiv.refl \u03b1 * e = e :=\n  refl_trans e\n\n@[simp] theorem inv_trans {\u03b1 : Type u} (e : perm \u03b1) : equiv.trans (e\u207b\u00b9) e = 1 :=\n  symm_trans e\n\n@[simp] theorem mul_symm {\u03b1 : Type u} (e : perm \u03b1) : e * equiv.symm e = 1 :=\n  symm_trans e\n\n@[simp] theorem trans_inv {\u03b1 : Type u} (e : perm \u03b1) : equiv.trans e (e\u207b\u00b9) = 1 :=\n  trans_symm e\n\n@[simp] theorem symm_mul {\u03b1 : Type u} (e : perm \u03b1) : equiv.symm e * e = 1 :=\n  trans_symm e\n\n/-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/\n\n@[simp] theorem sum_congr_mul {\u03b1 : Type u_1} {\u03b2 : Type u_2} (e : perm \u03b1) (f : perm \u03b2) (g : perm \u03b1) (h : perm \u03b2) : sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) :=\n  sum_congr_trans g h e f\n\n@[simp] theorem sum_congr_inv {\u03b1 : Type u_1} {\u03b2 : Type u_2} (e : perm \u03b1) (f : perm \u03b2) : sum_congr e f\u207b\u00b9 = sum_congr (e\u207b\u00b9) (f\u207b\u00b9) :=\n  sum_congr_symm e f\n\n@[simp] theorem sum_congr_one {\u03b1 : Type u_1} {\u03b2 : Type u_2} : sum_congr 1 1 = 1 :=\n  sum_congr_refl\n\n/-- `equiv.perm.sum_congr` as a `monoid_hom`, with its two arguments bundled into a single `prod`.\n\nThis is particularly useful for its `monoid_hom.range` projection, which is the subgroup of\npermutations which do not exchange elements between `\u03b1` and `\u03b2`. -/\ndef sum_congr_hom (\u03b1 : Type u_1) (\u03b2 : Type u_2) : perm \u03b1 \u00d7 perm \u03b2 \u2192* perm (\u03b1 \u2295 \u03b2) :=\n  monoid_hom.mk (fun (a : perm \u03b1 \u00d7 perm \u03b2) => sum_congr (prod.fst a) (prod.snd a)) sum_congr_one sorry\n\ntheorem sum_congr_hom_injective {\u03b1 : Type u_1} {\u03b2 : Type u_2} : function.injective \u21d1(sum_congr_hom \u03b1 \u03b2) := sorry\n\n@[simp] theorem sum_congr_swap_one {\u03b1 : Type u_1} {\u03b2 : Type u_2} [DecidableEq \u03b1] [DecidableEq \u03b2] (i : \u03b1) (j : \u03b1) : sum_congr (swap i j) 1 = swap (sum.inl i) (sum.inl j) :=\n  sum_congr_swap_refl i j\n\n@[simp] theorem sum_congr_one_swap {\u03b1 : Type u_1} {\u03b2 : Type u_2} [DecidableEq \u03b1] [DecidableEq \u03b2] (i : \u03b2) (j : \u03b2) : sum_congr 1 (swap i j) = swap (sum.inr i) (sum.inr j) :=\n  sum_congr_refl_swap i j\n\n/-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/\n\n@[simp] theorem sigma_congr_right_mul {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} (F : (a : \u03b1) \u2192 perm (\u03b2 a)) (G : (a : \u03b1) \u2192 perm (\u03b2 a)) : sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) :=\n  sigma_congr_right_trans G F\n\n@[simp] theorem sigma_congr_right_inv {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} (F : (a : \u03b1) \u2192 perm (\u03b2 a)) : sigma_congr_right F\u207b\u00b9 = sigma_congr_right fun (a : \u03b1) => F a\u207b\u00b9 :=\n  sigma_congr_right_symm F\n\n@[simp] theorem sigma_congr_right_one {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} : sigma_congr_right 1 = 1 :=\n  sigma_congr_right_refl\n\n/-- `equiv.perm.sigma_congr_right` as a `monoid_hom`.\n\nThis is particularly useful for its `monoid_hom.range` projection, which is the subgroup of\npermutations which do not exchange elements between fibers. -/\ndef sigma_congr_right_hom {\u03b1 : Type u_1} (\u03b2 : \u03b1 \u2192 Type u_2) : ((a : \u03b1) \u2192 perm (\u03b2 a)) \u2192* perm (sigma fun (a : \u03b1) => \u03b2 a) :=\n  monoid_hom.mk sigma_congr_right sorry sorry\n\ntheorem sigma_congr_right_hom_injective {\u03b1 : Type u_1} {\u03b2 : \u03b1 \u2192 Type u_2} : function.injective \u21d1(sigma_congr_right_hom \u03b2) := sorry\n\nend perm\n\n\n@[simp] theorem swap_inv {\u03b1 : Type u} [DecidableEq \u03b1] (x : \u03b1) (y : \u03b1) : swap x y\u207b\u00b9 = swap x y :=\n  rfl\n\n@[simp] theorem swap_mul_self {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) : swap i j * swap i j = 1 :=\n  swap_swap i j\n\ntheorem swap_mul_eq_mul_swap {\u03b1 : Type u} [DecidableEq \u03b1] (f : perm \u03b1) (x : \u03b1) (y : \u03b1) : swap x y * f = f * swap (coe_fn (f\u207b\u00b9) x) (coe_fn (f\u207b\u00b9) y) := sorry\n\ntheorem mul_swap_eq_swap_mul {\u03b1 : Type u} [DecidableEq \u03b1] (f : perm \u03b1) (x : \u03b1) (y : \u03b1) : f * swap x y = swap (coe_fn f x) (coe_fn f y) * f := sorry\n\n/-- Left-multiplying a permutation with `swap i j` twice gives the original permutation.\n\n  This specialization of `swap_mul_self` is useful when using cosets of permutations.\n-/\n@[simp] theorem swap_mul_self_mul {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) (\u03c3 : perm \u03b1) : swap i j * (swap i j * \u03c3) = \u03c3 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (swap i j * (swap i j * \u03c3) = \u03c3)) (Eq.symm (mul_assoc (swap i j) (swap i j) \u03c3))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (swap i j * swap i j * \u03c3 = \u03c3)) (swap_mul_self i j)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (1 * \u03c3 = \u03c3)) (one_mul \u03c3))) (Eq.refl \u03c3)))\n\n/-- Right-multiplying a permutation with `swap i j` twice gives the original permutation.\n\n  This specialization of `swap_mul_self` is useful when using cosets of permutations.\n-/\n@[simp] theorem mul_swap_mul_self {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) (\u03c3 : perm \u03b1) : \u03c3 * swap i j * swap i j = \u03c3 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (\u03c3 * swap i j * swap i j = \u03c3)) (mul_assoc \u03c3 (swap i j) (swap i j))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u03c3 * (swap i j * swap i j) = \u03c3)) (swap_mul_self i j)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (\u03c3 * 1 = \u03c3)) (mul_one \u03c3))) (Eq.refl \u03c3)))\n\n/-- A stronger version of `mul_right_injective` -/\n@[simp] theorem swap_mul_involutive {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) : function.involutive (Mul.mul (swap i j)) :=\n  swap_mul_self_mul i j\n\n/-- A stronger version of `mul_left_injective` -/\n@[simp] theorem mul_swap_involutive {\u03b1 : Type u} [DecidableEq \u03b1] (i : \u03b1) (j : \u03b1) : function.involutive fun (_x : perm \u03b1) => _x * swap i j :=\n  mul_swap_mul_self i j\n\ntheorem swap_mul_eq_iff {\u03b1 : Type u} [DecidableEq \u03b1] {i : \u03b1} {j : \u03b1} {\u03c3 : perm \u03b1} : swap i j * \u03c3 = \u03c3 \u2194 i = j := sorry\n\ntheorem mul_swap_eq_iff {\u03b1 : Type u} [DecidableEq \u03b1] {i : \u03b1} {j : \u03b1} {\u03c3 : perm \u03b1} : \u03c3 * swap i j = \u03c3 \u2194 i = j := sorry\n\ntheorem swap_mul_swap_mul_swap {\u03b1 : Type u} [DecidableEq \u03b1] {x : \u03b1} {y : \u03b1} {z : \u03b1} (hwz : x \u2260 y) (hxz : x \u2260 z) : swap y z * swap x y * swap y z = swap z x := sorry\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/group_theory/perm/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7006465532728211}}
{"text": "import tactic\nimport binary\nimport hamming\nimport binary_codes\nimport algebra.module.submodule\n\n/-!\n# Linear Binary Codes\n\nThis file contains the definition of a linear binary code.\nWe also use this definition to formalize the Hamming(7,4) code \nand some of its properties.\n-/\n\nopen B BW binary_code\n\nstructure linear_binary_code (n M d : \u2115) extends binary_code n M d :=\n  (is_subspace : subspace B (BW n))\n\ndef H74C : finset (BW 7) := {\n  val := {\n    \u1d2e[O,O,O,O,O,O,O],\n    \u1d2e[I,I,O,I,O,O,I],\n    \u1d2e[O,I,O,I,O,I,O],\n    \u1d2e[I,O,O,O,O,I,I],\n    \u1d2e[I,O,O,I,I,O,O],\n    \u1d2e[O,I,O,O,I,O,I],\n    \u1d2e[I,I,O,O,I,I,O],\n    \u1d2e[O,O,O,I,I,I,I],\n    \u1d2e[I,I,I,O,O,O,O],\n    \u1d2e[O,O,I,I,O,O,I],\n    \u1d2e[I,O,I,I,O,I,O],\n    \u1d2e[O,I,I,O,O,I,I],\n    \u1d2e[O,I,I,I,I,O,O],\n    \u1d2e[I,O,I,O,I,O,I],\n    \u1d2e[O,O,I,O,I,I,O],\n    \u1d2e[I,I,I,I,I,I,I]\n  },\n  nodup := by simp,\n}\n\ndef hamming74Code : linear_binary_code 7 16 3 :=\n{\n  cws := H74C,\n  has_card_M := rfl,\n  card_gte := by {have : H74C.card = 16, from rfl, linarith},\n  has_min_distance_d := rfl,\n  is_subspace := {\n    carrier := H74C,\n    zero_mem' := by {simp, left, refl},\n    add_mem' := begin\n      rintros a b\n        (rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | ha)\n        (rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | hb),\n        all_goals {\n          try {rw list.eq_of_mem_singleton ha}, \n          try {rw list.eq_of_mem_singleton hb}, \n          repeat {{left, refl} <|> right <|> refl},\n        },\n        all_goals {simp, refl},\n    end,\n    smul_mem' := begin\n      intros c x x_mem,\n      cases c,\n        {conv {congr, apply_congr zero_smul}, simp, left, refl},\n        {conv {congr, apply_congr one_smul}, exact x_mem}\n    end,\n  },\n}\n\nlemma hamming74Code_2_error_detecting : \n  hamming74Code.to_binary_code.error_detecting 2 := \nbegin\n  rw [s_error_detecting_iff_min_distance_gt_s, hamming74Code.has_min_distance_d],\n  linarith,\nend\n\nlemma hamming74Code_1_error_correcting :\n  hamming74Code.to_binary_code.error_correcting 1 :=\nbegin\n  rw [t_error_correcting_iff_min_distance_gte, hamming74Code.has_min_distance_d],\n  linarith,\nend\n\nlemma hamming74Code_perfect :\n  hamming74Code.to_binary_code.perfect :=\nbegin\n  unfold perfect,\n  rw [hamming74Code.has_card_M],\n  simp,\n  refl,\nend", "meta": {"author": "GeorgeTillisch", "repo": "coding_theory_lean", "sha": "920e14b433080854d4248714c93a09ce4e391522", "save_path": "github-repos/lean/GeorgeTillisch-coding_theory_lean", "path": "github-repos/lean/GeorgeTillisch-coding_theory_lean/coding_theory_lean-920e14b433080854d4248714c93a09ce4e391522/src/linear_binary_code.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7006465385009097}}
{"text": "import tactic\n\n-- set_option trace.simp_lemmas true\nset_option trace.simplify.rewrite true\n\ninductive sorted : list \u2115 \u2192 Prop\n| nil : sorted []\n| single {x : \u2115} : sorted [x]\n| two_or_more {x y : \u2115} {zs : list \u2115} (hle : x \u2264 y)\n    (hsorted : sorted (y :: zs)) :\n  sorted (x :: y :: zs)\n\nlemma sorted_3_5 :\n  sorted [3, 5] :=\nbegin\n  apply sorted.two_or_more, -- give us two goals:\n  -- \u22a2 3 \u2264 5\n  exact dec_trivial,\n  -- \u22a2 sorted [5]\n  exact sorted.single,\nend\n\nlemma sorted_3_5\u2082 :\n  sorted [3, 5] :=\nsorted.two_or_more dec_trivial sorted.single\n-- of_as_true : \u2200 {c : Prop} [h\u2081 : decidable c], as_true c \u2192 c\n\nlemma sorted_3_5\u2083 :\n  sorted [3, 5] :=\nsorted.two_or_more (of_as_true trivial) sorted.single\n\n-- Some strange tries:\n\n-- example : dec_trivial = of_as_true trivial := lean doesn't support that kind of proving?\n\n-- example : sorted_3_5 \u2194 sorted_3_5\u2082 := wrong\n-- example (h1 : sorted_3_5) (h2 : sorted_3_5\u2082): h1 \u2194 h2 := wrong\n\nlemma sorted_7_9_9_11:\n  sorted [7, 9, 9, 11] :=\nsorted.two_or_more dec_trivial\n  (\n    sorted.two_or_more dec_trivial\n    (\n      sorted.two_or_more dec_trivial sorted.single\n    )\n  )\n\nlemma sorted_7_9_9_11\u2082:\n  sorted [7, 9, 9, 11,15,666,1000] :=\nbegin\n  -- backward_chaining, -- unknown identifier 'backward_chaining'\n  repeat {\n    constructor,\n    exact dec_trivial, \n    try { exact sorted.single }\n  },\n    -- simp [sorted.two_or_more, sorted.single],\n  /-\n  simp see only that rules:\n    list.nil_subset\n    list.subset.refl\n    list.subset_cons\n    list.subset_append_left\n    list.subset_append_right\n  -/\nend\n\nexample (x): 15 \u2264 x \u2192 sorted [7, 9, 9, 11, 15, x] :=\nbegin\n  assume h : 15 \u2264 x,\n   repeat {\n    constructor,\n    exact dec_trivial, \n    try { exact sorted.single }\n  },\n  -- exact sorted.two_or_more (h : 15 \u2264 x) (sorted.single : sorted [x]),\n  apply sorted.two_or_more; exact sorted.single <|> assumption,\n  tactic.trace_result,\nend\n\nexample (x): x \u2264 15 \u2227 11 \u2264 x \u2192 sorted [7, 9, 9, 11, x, 15] :=\nbegin\n  assume h : x \u2264 15 \u2227 11 \u2264 x,\n  have h\u2081 := h.1, have h\u2082 := h.2, -- for good working assumption\n   repeat {\n    constructor,\n    exact dec_trivial, \n    try { exact sorted.single }\n  },\n  show_term { apply sorted.two_or_more; exact sorted.single <|> assumption <|> skip, },\n  show_term { apply sorted.two_or_more; exact sorted.single <|> assumption <|> skip, },\n  tactic.trace_result,\nend\n\nnamespace helper\nlemma sorted_nil : sorted [] := sorry\nlemma sorted_single (n : \u2115): sorted [n] := sorry\nlemma sorted_two_or_more\n  (n m : \u2115) (ls : list \u2115) \n  (hsorted : sorted (m :: ls)) :\n    sorted (n :: m :: ls) := sorry\nend helper\n\nlemma ex1 : sorted [] :=\nbegin\n  exact helper.sorted_nil,\nend\n\n#print ex1\n\nlemma ex2 : sorted [] :=\nbegin\n  simp only [helper.sorted_nil],\n  -- [helper.sorted_nil]: sorted list.nil ==> true\n  -- (id (propext (iff_true_intro helper.sorted_nil))).mpr trivial\nend\n#print ex2\n\nlemma ex2' : sorted [] :=\nbegin\n  simp only [sorted.nil],\n  -- [sorted.nil]: sorted list.nil ==> true\n  -- (id (propext (iff_true_intro sorted.nil))).mpr trivial\nend\n#print ex2'\n\nlemma ex3 : sorted [1] \u2227 sorted [] :=\nbegin\n  simp only [sorted.nil, sorted.single, and_self],\nend\n#print ex3\n\nlemma ex4 : sorted [1, 2] :=\nbegin\n  -- library_search [sorted.two_or_more], not works\n  -- have H : sorted [1],\n  --   exact sorted.single,\n  repeat {\n    constructor,\n    linarith,\n    simp only [sorted.nil, sorted.single],\n  },\nend\n#print ex4 -- proof is too long :( >> sorted.two_or_more (of_as_true trivial) sorted.single\n\nlemma ex4' : sorted [1, 2] :=\n  sorted.two_or_more dec_trivial sorted.single\n\n#print ex4' -- sorted.two_or_more (of_as_true trivial) sorted.single\n\nlemma ex5 : sorted [40, 70] :=\nbegin\n  -- library_search [sorted.two_or_more], not works\n  -- have H : sorted [1],\n  --   exact sorted.single,\n  repeat {\n    constructor,\n    linarith,\n    simp only [sorted.single],\n  },\nend\n\nlemma ex6 : sorted [1, 2, 3] :=\nbegin\n  constructor,\n  simp,\n  constructor,\n  simp,\n  exact sorted.single,\nend\n#print ex6\n/-\nsorted_lists.lean:132:0: information print result\ntheorem ex6 : sorted [1, 2, 3] :=\nsorted.two_or_more\n  ((id ((propext nat.one_le_bit0_iff).trans (propext (\u03bb {n : \u2115}, iff_true_intro nat.succ_pos')))).mpr trivial)\n  (sorted.two_or_more ((id (propext nat.bit0_le_bit1_iff)).mpr (le_refl 1)) sorted.single)\n-/\n\nlemma ex7 : sorted [1, 2, 3, 4, 5] :=\nbegin\n  repeat {constructor, simp, },\n  exact sorted.single,\nend\n#print ex7\n-- GIVE:\n/-\nsorted.two_or_more\n  ((id ((propext nat.one_le_bit0_iff).trans (propext (\u03bb {n : \u2115}, iff_true_intro nat.succ_pos')))).mpr trivial)\n  (sorted.two_or_more ((id (propext nat.bit0_le_bit1_iff)).mpr (le_refl 1))\n     (sorted.two_or_more ((id ((propext nat.bit1_le_bit0_iff).trans (propext nat.one_lt_bit0_iff))).mpr (le_refl 1))\n        (sorted.two_or_more ((id ((propext nat.bit0_le_bit1_iff).trans (propext bit0_le_bit0))).mpr (le_refl 1))\n           sorted.single)))\n-/\n-- EXPECTED:\n/-\nsorted.two_or_more (of_as_true trivial)\n  (sorted.two_or_more (of_as_true trivial)\n     (sorted.two_or_more (of_as_true trivial) \n        (sorted.two_or_more (of_as_true trivial) \n          sorted.single)))\n-/\n\nlemma ex7' : sorted [1, 2, 3, 3, 5] :=\nbegin\n  -- constructor_matching _ <=> constructor \n  repeat { constructor, exact dec_trivial, },\n  exact sorted.single,\nend\n#print ex7'\n/-\ntheorem ex7' : sorted [1, 2, 3, 3, 5] :=\nsorted.two_or_more (of_as_true trivial)\n  (sorted.two_or_more (of_as_true trivial)\n     (sorted.two_or_more (of_as_true trivial) \n        (sorted.two_or_more (of_as_true trivial) \n            sorted.single)))\n-/\nlemma not_sorted_17_13 : \u00ac sorted [2, 1] :=\nbegin\n  assume h : sorted [2, 1],\n  have h2: 2 \u2264 1 :=\n    match h with\n    | sorted.two_or_more hle _ := hle\n    end,\n  have h3: \u00ac 2 \u2264 1 :=\n    dec_trivial,\n  -- contradiction, <=>\n  show false, from by cc,\nend\n#print not_sorted_17_13\n/-\nsorted_lists.lean:202:0: information print result\ntheorem not_sorted_17_13 : \u00acsorted [2, 1] :=\nid\n  (\u03bb (h : sorted [2, 1]),\n     (false_of_true_eq_false\n        ((eq_true_intro\n            ((\u03bb (_a : sorted [2, 1]),\n                _a.dcases_on (\u03bb (H_1 : [2, 1] = list.nil), list.no_confusion H_1)\n                  (\u03bb {x : \u2115} (H_1 : [2, 1] = [x]),\n                     list.no_confusion H_1\n                       (\u03bb (a : (1.add 0).succ = x), eq.rec (\u03bb (tl_eq : [1] = list.nil), list.no_confusion tl_eq) a))\n                  (\u03bb {x y : \u2115} {zs : list \u2115} (hle : x \u2264 y) (hsorted : sorted (y :: zs))\n                   (H_1 : [2, 1] = x :: y :: zs),\n                     list.no_confusion H_1\n                       (\u03bb (a : (1.add 0).succ = x),\n                          eq.rec\n                            (\u03bb (hle : (1.add 0).succ \u2264 y) (tl_eq : [1] = y :: zs),\n                               list.no_confusion tl_eq\n                                 (\u03bb (a : 1 = y),\n                                    eq.rec\n                                      (\u03bb (hsorted : sorted (1 :: zs)) (hle : (1.add 0).succ \u2264 1)\n                                       (tl_eq : list.nil = zs),\n                                         eq.rec\n                                           (\u03bb (hsorted : sorted [1]) (H_2 : _a == sorted.two_or_more hle hsorted),\n                                              id_rhs ((1.add 0).succ \u2264 1) hle)\n                                           tl_eq\n                                           hsorted)\n                                      a\n                                      hsorted\n                                      hle))\n                            a\n                            hle))\n                  (eq.refl [2, 1])\n                  (heq.refl _a))\n               h)).symm.trans\n           (eq_false_intro (of_as_true trivial)))).elim)\n-/\n", "meta": {"author": "mathprocessing", "repo": "lean_mathlib_examples", "sha": "743c6456c0a3219dd1722efdd31ee6f3a113818a", "save_path": "github-repos/lean/mathprocessing-lean_mathlib_examples", "path": "github-repos/lean/mathprocessing-lean_mathlib_examples/lean_mathlib_examples-743c6456c0a3219dd1722efdd31ee6f3a113818a/src/sorted_lists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8670357632379241, "lm_q1q2_score": 0.7006231732502626}}
{"text": "/-\nCopyright (c) 2019 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n-/\nimport set_theory.cardinal_ordinal\nimport analysis.specific_limits\nimport data.rat.denumerable\nimport data.set.intervals.image_preimage\n\n/-!\n# The cardinality of the reals\n\nThis file shows that the real numbers have cardinality continuum, i.e. `#\u211d = 2^\u03c9`.\n\nWe shows that `#\u211d \u2264 2^\u03c9` by noting that every real number is determined by a Cauchy-sequence of the\nform `\u2115 \u2192 \u211a`, which has cardinality `2^\u03c9`. To show that `#\u211d \u2265 2^\u03c9` we define an injection from\n`{0, 1} ^ \u2115` to `\u211d` with `f \u21a6 \u03a3 n, f n * (1 / 3) ^ n`.\n\nWe conclude that all intervals with distinct endpoints have cardinality continuum.\n\n## Main definitions\n\n* `cardinal.cantor_function` is the function that sends `f` in `{0, 1} ^ \u2115` to `\u211d` by\n  `f \u21a6 \u03a3' n, f n * (1 / 3) ^ n`\n\n## Main statements\n\n* `cardinal.mk_real : #\u211d = 2 ^ omega`: the reals have cardinality continuum.\n* `cardinal.not_countable_real`: the universal set of real numbers is not countable.\n  We can use this same proof to show that all the other sets in this file are not countable.\n* 8 lemmas of the form `mk_Ixy_real` for `x,y \u2208 {i,o,c}` state that intervals on the reals\n  have cardinality continuum.\n\n## Tags\ncontinuum, cardinality, reals, cardinality of the reals\n-/\n\nopen nat set\nopen_locale cardinal\nnoncomputable theory\n\nnamespace cardinal\n\nvariables {c : \u211d} {f g : \u2115 \u2192 bool} {n : \u2115}\n\n/-- The body of the sum in `cantor_function`.\n`cantor_function_aux c f n = c ^ n` if `f n = tt`;\n`cantor_function_aux c f n = 0` if `f n = ff`. -/\ndef cantor_function_aux (c : \u211d) (f : \u2115 \u2192 bool) (n : \u2115) : \u211d := cond (f n) (c ^ n) 0\n\n@[simp] lemma cantor_function_aux_tt (h : f n = tt) : cantor_function_aux c f n = c ^ n :=\nby simp [cantor_function_aux, h]\n\n@[simp] lemma cantor_function_aux_ff (h : f n = ff) : cantor_function_aux c f n = 0 :=\nby simp [cantor_function_aux, h]\n\nlemma cantor_function_aux_nonneg (h : 0 \u2264 c) : 0 \u2264 cantor_function_aux c f n :=\nby { cases h' : f n; simp [h'], apply pow_nonneg h }\n\nlemma cantor_function_aux_eq (h : f n = g n) :\n  cantor_function_aux c f n = cantor_function_aux c g n :=\nby simp [cantor_function_aux, h]\n\nlemma cantor_function_aux_succ (f : \u2115 \u2192 bool) :\n  (\u03bb n, cantor_function_aux c f (n + 1)) = \u03bb n, c * cantor_function_aux c (\u03bb n, f (n + 1)) n :=\nby { ext n, cases h : f (n + 1); simp [h, pow_succ] }\n\nlemma summable_cantor_function (f : \u2115 \u2192 bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n  summable (cantor_function_aux c f) :=\nbegin\n  apply (summable_geometric_of_lt_1 h1 h2).summable_of_eq_zero_or_self,\n  intro n, cases h : f n; simp [h]\nend\n\n/-- `cantor_function c (f : \u2115 \u2192 bool)` is `\u03a3 n, f n * c ^ n`, where `tt` is interpreted as `1` and\n`ff` is interpreted as `0`. It is implemented using `cantor_function_aux`. -/\ndef cantor_function (c : \u211d) (f : \u2115 \u2192 bool) : \u211d := \u2211' n, cantor_function_aux c f n\n\nlemma cantor_function_le (h1 : 0 \u2264 c) (h2 : c < 1) (h3 : \u2200 n, f n \u2192 g n) :\n  cantor_function c f \u2264 cantor_function c g :=\nbegin\n  apply tsum_le_tsum _ (summable_cantor_function f h1 h2) (summable_cantor_function g h1 h2),\n  intro n, cases h : f n, simp [h, cantor_function_aux_nonneg h1],\n  replace h3 : g n = tt := h3 n h, simp [h, h3]\nend\n\nlemma cantor_function_succ (f : \u2115 \u2192 bool) (h1 : 0 \u2264 c) (h2 : c < 1) :\n  cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (\u03bb n, f (n+1)) :=\nbegin\n  rw [cantor_function, tsum_eq_zero_add (summable_cantor_function f h1 h2)],\n  rw [cantor_function_aux_succ, tsum_mul_left, cantor_function_aux, pow_zero],\n  refl\nend\n\n/-- `cantor_function c` is strictly increasing with if `0 < c < 1/2`, if we endow `\u2115 \u2192 bool` with a\nlexicographic order. The lexicographic order doesn't exist for these infinitary products, so we\nexplicitly write out what it means. -/\nlemma increasing_cantor_function (h1 : 0 < c) (h2 : c < 1 / 2) {n : \u2115} {f g : \u2115 \u2192 bool}\n  (hn : \u2200(k < n), f k = g k) (fn : f n = ff) (gn : g n = tt) :\n  cantor_function c f < cantor_function c g :=\nbegin\n  have h3 : c < 1, { apply h2.trans, norm_num },\n  induction n with n ih generalizing f g,\n  { let f_max : \u2115 \u2192 bool := \u03bb n, nat.rec ff (\u03bb _ _, tt) n,\n    have hf_max : \u2200n, f n \u2192 f_max n,\n    { intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl },\n    let g_min : \u2115 \u2192 bool := \u03bb n, nat.rec tt (\u03bb _ _, ff) n,\n    have hg_min : \u2200n, g_min n \u2192 g n,\n    { intros n hn, cases n, rw [gn], apply rfl, contradiction },\n    apply (cantor_function_le (le_of_lt h1) h3 hf_max).trans_lt,\n    refine lt_of_lt_of_le _ (cantor_function_le (le_of_lt h1) h3 hg_min),\n    have : c / (1 - c) < 1,\n    { rw [div_lt_one, lt_sub_iff_add_lt],\n      { convert add_lt_add h2 h2, norm_num },\n      rwa sub_pos },\n    convert this,\n    { rw [cantor_function_succ _ (le_of_lt h1) h3, div_eq_mul_inv,\n          \u2190tsum_geometric_of_lt_1 (le_of_lt h1) h3],\n      apply zero_add },\n    { convert tsum_eq_single 0 _,\n      { apply_instance },\n      { intros n hn, cases n, contradiction, refl } } },\n  rw [cantor_function_succ f (le_of_lt h1) h3, cantor_function_succ g (le_of_lt h1) h3],\n  rw [hn 0 $ zero_lt_succ n],\n  apply add_lt_add_left, rw mul_lt_mul_left h1, exact ih (\u03bb k hk, hn _ $ succ_lt_succ hk) fn gn\nend\n\n/-- `cantor_function c` is injective if `0 < c < 1/2`. -/\nlemma cantor_function_injective (h1 : 0 < c) (h2 : c < 1 / 2) :\n  function.injective (cantor_function c) :=\nbegin\n  intros f g hfg, classical, by_contra h, revert hfg,\n  have : \u2203n, f n \u2260 g n,\n  { rw [\u2190not_forall], intro h', apply h, ext, apply h' },\n  let n := nat.find this,\n  have hn : \u2200 (k : \u2115), k < n \u2192 f k = g k,\n  { intros k hk, apply of_not_not, exact nat.find_min this hk },\n  cases fn : f n,\n  { apply ne_of_lt, refine increasing_cantor_function h1 h2 hn fn _,\n    apply eq_tt_of_not_eq_ff, rw [\u2190fn], apply ne.symm, exact nat.find_spec this },\n  { apply ne_of_gt, refine increasing_cantor_function h1 h2 (\u03bb k hk, (hn k hk).symm) _ fn,\n    apply eq_ff_of_not_eq_tt, rw [\u2190fn], apply ne.symm, exact nat.find_spec this }\nend\n\n/-- The cardinality of the reals, as a type. -/\nlemma mk_real : #\u211d = 2 ^ omega.{0} :=\nbegin\n  apply le_antisymm,\n  { rw real.equiv_Cauchy.cardinal_eq,\n    apply mk_quotient_le.trans, apply (mk_subtype_le _).trans,\n    rw [\u2190power_def, mk_nat, mk_rat, power_self_eq (le_refl _)] },\n  { convert mk_le_of_injective (cantor_function_injective _ _),\n    rw [\u2190power_def, mk_bool, mk_nat], exact 1 / 3, norm_num, norm_num }\nend\n\n/-- The cardinality of the reals, as a set. -/\nlemma mk_univ_real : #(set.univ : set \u211d) = 2 ^ omega.{0} :=\nby rw [mk_univ, mk_real]\n\n/-- The reals are not countable. -/\nlemma not_countable_real : \u00ac countable (set.univ : set \u211d) :=\nby { rw [countable_iff, not_le, mk_univ_real], apply cantor }\n\n/-- The cardinality of the interval (a, \u221e). -/\nlemma mk_Ioi_real (a : \u211d) : #(Ioi a) = 2 ^ omega.{0} :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  rw [\u2190 not_lt], intro h,\n  refine ne_of_lt _ mk_univ_real,\n  have hu : Iio a \u222a {a} \u222a Ioi a = set.univ,\n  { convert Iic_union_Ioi, exact Iio_union_right },\n  rw \u2190 hu,\n  refine lt_of_le_of_lt (mk_union_le _ _) _,\n  refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) _,\n  have h2 : (\u03bb x, a + a - x) '' Ioi a = Iio a,\n  { convert image_const_sub_Ioi _ _, simp },\n  rw \u2190 h2,\n  refine add_lt_of_lt (cantor _).le _ h,\n  refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) _,\n  rw mk_singleton,\n  exact one_lt_omega.trans (cantor _)\nend\n\n/-- The cardinality of the interval [a, \u221e). -/\nlemma mk_Ici_real (a : \u211d) : #(Ici a) = 2 ^ omega.{0} :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioi_real a \u25b8 mk_le_mk_of_subset Ioi_subset_Ici_self)\n\n/-- The cardinality of the interval (-\u221e, a). -/\nlemma mk_Iio_real (a : \u211d) : #(Iio a) = 2 ^ omega.{0} :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  have h2 : (\u03bb x, a + a - x) '' Iio a = Ioi a,\n  { convert image_const_sub_Iio _ _, simp },\n  exact mk_Ioi_real a \u25b8 h2 \u25b8 mk_image_le\nend\n\n/-- The cardinality of the interval (-\u221e, a]. -/\nlemma mk_Iic_real (a : \u211d) : #(Iic a) = 2 ^ omega.{0} :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Iio_real a \u25b8 mk_le_mk_of_subset Iio_subset_Iic_self)\n\n/-- The cardinality of the interval (a, b). -/\nlemma mk_Ioo_real {a b : \u211d} (h : a < b) : #(Ioo a b) = 2 ^ omega.{0} :=\nbegin\n  refine le_antisymm (mk_real \u25b8 mk_set_le _) _,\n  have h1 : #((\u03bb x, x - a) '' Ioo a b) \u2264 #(Ioo a b) := mk_image_le,\n  refine le_trans _ h1,\n  rw [image_sub_const_Ioo, sub_self],\n  replace h := sub_pos_of_lt h,\n  have h2 : #(has_inv.inv '' Ioo 0 (b - a)) \u2264 #(Ioo 0 (b - a)) := mk_image_le,\n  refine le_trans _ h2,\n  rw [image_inv_Ioo_0_left h, mk_Ioi_real]\nend\n\n/-- The cardinality of the interval [a, b). -/\n\n\n/-- The cardinality of the interval [a, b]. -/\nlemma mk_Icc_real {a b : \u211d} (h : a < b) : #(Icc a b) = 2 ^ omega.{0} :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Icc_self)\n\n/-- The cardinality of the interval (a, b]. -/\nlemma mk_Ioc_real {a b : \u211d} (h : a < b) : #(Ioc a b) = 2 ^ omega.{0} :=\nle_antisymm (mk_real \u25b8 mk_set_le _) (mk_Ioo_real h \u25b8 mk_le_mk_of_subset Ioo_subset_Ioc_self)\n\nend cardinal\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/real/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8080672181749421, "lm_q1q2_score": 0.7006231661525782}}
{"text": "/-\nCopyright (c) 2020 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller\n\n! This file was ported from Lean 3 source module algebra.quandle\n! leanprover-community/mathlib commit 28aa996fc6fb4317f0083c4e6daf79878d81be33\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.Hom.Equiv.Basic\nimport Mathbin.Algebra.Hom.Aut\nimport Mathbin.Data.Zmod.Defs\nimport Mathbin.Tactic.Group\n\n/-!\n# Racks and Quandles\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines racks and quandles, algebraic structures for sets\nthat bijectively act on themselves with a self-distributivity\nproperty.  If `R` is a rack and `act : R \u2192 (R \u2243 R)` is the self-action,\nthen the self-distributivity is, equivalently, that\n```\nact (act x y) = act x * act y * (act x)\u207b\u00b9\n```\nwhere multiplication is composition in `R \u2243 R` as a group.\nQuandles are racks such that `act x x = x` for all `x`.\n\nOne example of a quandle (not yet in mathlib) is the action of a Lie\nalgebra on itself, defined by `act x y = Ad (exp x) y`.\n\nQuandles and racks were independently developed by multiple\nmathematicians.  David Joyce introduced quandles in his thesis\n[Joyce1982] to define an algebraic invariant of knot and link\ncomplements that is analogous to the fundamental group of the\nexterior, and he showed that the quandle associated to an oriented\nknot is invariant up to orientation-reversed mirror image.  Racks were\nused by Fenn and Rourke for framed codimension-2 knots and\nlinks in [FennRourke1992].  Unital shelves are discussed in [crans2017].\n\nThe name \"rack\" came from wordplay by Conway and Wraith for the \"wrack\nand ruin\" of forgetting everything but the conjugation operation for a\ngroup.\n\n## Main definitions\n\n* `shelf` is a type with a self-distributive action\n* `unital_shelf` is a shelf with a left and right unit\n* `rack` is a shelf whose action for each element is invertible\n* `quandle` is a rack whose action for an element fixes that element\n* `quandle.conj` defines a quandle of a group acting on itself by conjugation.\n* `shelf_hom` is homomorphisms of shelves, racks, and quandles.\n* `rack.envel_group` gives the universal group the rack maps to as a conjugation quandle.\n* `rack.opp` gives the rack with the action replaced by its inverse.\n\n## Main statements\n* `rack.envel_group` is left adjoint to `quandle.conj` (`to_envel_group.map`).\n  The universality statements are `to_envel_group.univ` and `to_envel_group.univ_uniq`.\n\n## Implementation notes\n\n\"Unital racks\" are uninteresting (see `rack.assoc_iff_id`, `unital_shelf.assoc`), so we do not\ndefine them.\n\n## Notation\n\nThe following notation is localized in `quandles`:\n\n* `x \u25c3 y` is `shelf.act x y`\n* `x \u25c3\u207b\u00b9 y` is `rack.inv_act x y`\n* `S \u2192\u25c3 S'` is `shelf_hom S S'`\n\nUse `open_locale quandles` to use these.\n\n## Todo\n\n* If `g` is the Lie algebra of a Lie group `G`, then `(x \u25c3 y) = Ad (exp x) x` forms a quandle.\n* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,\n  forming a quandle.\n* Alexander quandle with `a \u25c3 b = t * b + (1 - t) * b`, with `a` and `b` elements\n  of a module over `Z[t,t\u207b\u00b9]`.\n* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by\n  `yH \u25c3 xH = yzy\u207b\u00b9xH`.  Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts\n  transitively on `Q` as a set) is isomorphic to such a quandle.\n  There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].\n\n## Tags\n\nrack, quandle\n-/\n\n\nopen MulOpposite\n\nuniverse u v\n\n#print Shelf /-\n/-- A *shelf* is a structure with a self-distributive binary operation.\nThe binary operation is regarded as a left action of the type on itself.\n-/\nclass Shelf (\u03b1 : Type u) where\n  act : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n  self_distrib : \u2200 {x y z : \u03b1}, act x (act y z) = act (act x y) (act x z)\n#align shelf Shelf\n-/\n\n#print UnitalShelf /-\n/-- A *unital shelf* is a shelf equipped with an element `1` such that, for all elements `x`,\nwe have both `x \u25c3 1` and `1 \u25c3 x` equal `x`.\n-/\nclass UnitalShelf (\u03b1 : Type u) extends Shelf \u03b1, One \u03b1 where\n  one_act : \u2200 a : \u03b1, act 1 a = a\n  act_one : \u2200 a : \u03b1, act a 1 = a\n#align unital_shelf UnitalShelf\n-/\n\n#print ShelfHom /-\n/-- The type of homomorphisms between shelves.\nThis is also the notion of rack and quandle homomorphisms.\n-/\n@[ext]\nstructure ShelfHom (S\u2081 : Type _) (S\u2082 : Type _) [Shelf S\u2081] [Shelf S\u2082] where\n  toFun : S\u2081 \u2192 S\u2082\n  map_act' : \u2200 {x y : S\u2081}, to_fun (Shelf.act x y) = Shelf.act (to_fun x) (to_fun y)\n#align shelf_hom ShelfHom\n-/\n\n#print Rack /-\n/-- A *rack* is an automorphic set (a set with an action on itself by\nbijections) that is self-distributive.  It is a shelf such that each\nelement's action is invertible.\n\nThe notations `x \u25c3 y` and `x \u25c3\u207b\u00b9 y` denote the action and the\ninverse action, respectively, and they are right associative.\n-/\nclass Rack (\u03b1 : Type u) extends Shelf \u03b1 where\n  invAct : \u03b1 \u2192 \u03b1 \u2192 \u03b1\n  left_inv : \u2200 x, Function.LeftInverse (inv_act x) (act x)\n  right_inv : \u2200 x, Function.RightInverse (inv_act x) (act x)\n#align rack Rack\n-/\n\n-- mathport name: shelf.act\nscoped[Quandles] infixr:65 \" \u25c3 \" => Shelf.act\n\n-- mathport name: rack.inv_act\nscoped[Quandles] infixr:65 \" \u25c3\u207b\u00b9 \" => Rack.invAct\n\n-- mathport name: shelf_hom\nscoped[Quandles] infixr:25 \" \u2192\u25c3 \" => ShelfHom\n\nopen Quandles\n\nnamespace UnitalShelf\n\nopen Shelf\n\nvariable {S : Type _} [UnitalShelf S]\n\n#print UnitalShelf.act_act_self_eq /-\n/-- A monoid is *graphic* if, for all `x` and `y`, the *graphic identity*\n`(x * y) * x = x * y` holds.  For a unital shelf, this graphic\nidentity holds.\n-/\ntheorem act_act_self_eq (x y : S) : (x \u25c3 y) \u25c3 x = x \u25c3 y :=\n  by\n  have h : (x \u25c3 y) \u25c3 x = (x \u25c3 y) \u25c3 x \u25c3 1 := by rw [act_one]\n  rw [h, \u2190 Shelf.self_distrib, act_one]\n#align unital_shelf.act_act_self_eq UnitalShelf.act_act_self_eq\n-/\n\n#print UnitalShelf.act_idem /-\ntheorem act_idem (x : S) : x \u25c3 x = x := by rw [\u2190 act_one x, \u2190 Shelf.self_distrib, act_one, act_one]\n#align unital_shelf.act_idem UnitalShelf.act_idem\n-/\n\n#print UnitalShelf.act_self_act_eq /-\ntheorem act_self_act_eq (x y : S) : x \u25c3 x \u25c3 y = x \u25c3 y :=\n  by\n  have h : x \u25c3 x \u25c3 y = (x \u25c3 1) \u25c3 x \u25c3 y := by rw [act_one]\n  rw [h, \u2190 Shelf.self_distrib, one_act]\n#align unital_shelf.act_self_act_eq UnitalShelf.act_self_act_eq\n-/\n\n#print UnitalShelf.assoc /-\n/-- The associativity of a unital shelf comes for free.\n-/\ntheorem assoc (x y z : S) : (x \u25c3 y) \u25c3 z = x \u25c3 y \u25c3 z := by\n  rw [self_distrib, self_distrib, act_act_self_eq, act_self_act_eq]\n#align unital_shelf.assoc UnitalShelf.assoc\n-/\n\nend UnitalShelf\n\nnamespace Rack\n\nvariable {R : Type _} [Rack R]\n\ntheorem self_distrib {x y z : R} : x \u25c3 y \u25c3 z = (x \u25c3 y) \u25c3 x \u25c3 z :=\n  Shelf.self_distrib\n#align rack.self_distrib Rack.self_distrib\n\n#print Rack.act' /-\n/-- A rack acts on itself by equivalences.\n-/\ndef act' (x : R) : R \u2243 R where\n  toFun := Shelf.act x\n  invFun := invAct x\n  left_inv := left_inv x\n  right_inv := right_inv x\n#align rack.act Rack.act'\n-/\n\n#print Rack.act'_apply /-\n@[simp]\ntheorem act'_apply (x y : R) : act' x y = x \u25c3 y :=\n  rfl\n#align rack.act_apply Rack.act'_apply\n-/\n\n#print Rack.act'_symm_apply /-\n@[simp]\ntheorem act'_symm_apply (x y : R) : (act' x).symm y = x \u25c3\u207b\u00b9 y :=\n  rfl\n#align rack.act_symm_apply Rack.act'_symm_apply\n-/\n\n#print Rack.invAct_apply /-\n@[simp]\ntheorem invAct_apply (x y : R) : (act' x)\u207b\u00b9 y = x \u25c3\u207b\u00b9 y :=\n  rfl\n#align rack.inv_act_apply Rack.invAct_apply\n-/\n\n#print Rack.invAct_act_eq /-\n@[simp]\ntheorem invAct_act_eq (x y : R) : x \u25c3\u207b\u00b9 x \u25c3 y = y :=\n  left_inv x y\n#align rack.inv_act_act_eq Rack.invAct_act_eq\n-/\n\n#print Rack.act_invAct_eq /-\n@[simp]\ntheorem act_invAct_eq (x y : R) : x \u25c3 x \u25c3\u207b\u00b9 y = y :=\n  right_inv x y\n#align rack.act_inv_act_eq Rack.act_invAct_eq\n-/\n\n#print Rack.left_cancel /-\ntheorem left_cancel (x : R) {y y' : R} : x \u25c3 y = x \u25c3 y' \u2194 y = y' :=\n  by\n  constructor\n  apply (act x).Injective\n  rintro rfl\n  rfl\n#align rack.left_cancel Rack.left_cancel\n-/\n\n#print Rack.left_cancel_inv /-\ntheorem left_cancel_inv (x : R) {y y' : R} : x \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y' \u2194 y = y' :=\n  by\n  constructor\n  apply (act x).symm.Injective\n  rintro rfl\n  rfl\n#align rack.left_cancel_inv Rack.left_cancel_inv\n-/\n\n#print Rack.self_distrib_inv /-\ntheorem self_distrib_inv {x y z : R} : x \u25c3\u207b\u00b9 y \u25c3\u207b\u00b9 z = (x \u25c3\u207b\u00b9 y) \u25c3\u207b\u00b9 x \u25c3\u207b\u00b9 z :=\n  by\n  rw [\u2190 left_cancel (x \u25c3\u207b\u00b9 y), right_inv, \u2190 left_cancel x, right_inv, self_distrib]\n  repeat' rw [right_inv]\n#align rack.self_distrib_inv Rack.self_distrib_inv\n-/\n\n/- warning: rack.ad_conj -> Rack.ad_conj is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_2 : Rack.{u1} R] (x : R) (y : R), Eq.{succ u1} (Equiv.{succ u1, succ u1} R R) (Rack.act'.{u1} R _inst_2 (Shelf.act.{u1} R (Rack.toShelf.{u1} R _inst_2) x y)) (HMul.hMul.{u1, u1, u1} (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (instHMul.{u1} (Equiv.{succ u1, succ u1} R R) (MulOneClass.toHasMul.{u1} (Equiv.{succ u1, succ u1} R R) (Monoid.toMulOneClass.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvMonoid.toMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivInvMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R)))))) (HMul.hMul.{u1, u1, u1} (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (instHMul.{u1} (Equiv.{succ u1, succ u1} R R) (MulOneClass.toHasMul.{u1} (Equiv.{succ u1, succ u1} R R) (Monoid.toMulOneClass.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvMonoid.toMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivInvMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R)))))) (Rack.act'.{u1} R _inst_2 x) (Rack.act'.{u1} R _inst_2 y)) (Inv.inv.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvMonoid.toHasInv.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivInvMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R))) (Rack.act'.{u1} R _inst_2 x)))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_2 : Rack.{u1} R] (x : R) (y : R), Eq.{succ u1} (Equiv.{succ u1, succ u1} R R) (Rack.act'.{u1} R _inst_2 (Shelf.act.{u1} R (Rack.toShelf.{u1} R _inst_2) x y)) (HMul.hMul.{u1, u1, u1} (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (instHMul.{u1} (Equiv.{succ u1, succ u1} R R) (MulOneClass.toMul.{u1} (Equiv.{succ u1, succ u1} R R) (Monoid.toMulOneClass.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvMonoid.toMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivInvMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R)))))) (HMul.hMul.{u1, u1, u1} (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (Equiv.{succ u1, succ u1} R R) (instHMul.{u1} (Equiv.{succ u1, succ u1} R R) (MulOneClass.toMul.{u1} (Equiv.{succ u1, succ u1} R R) (Monoid.toMulOneClass.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvMonoid.toMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivInvMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R)))))) (Rack.act'.{u1} R _inst_2 x) (Rack.act'.{u1} R _inst_2 y)) (Inv.inv.{u1} (Equiv.{succ u1, succ u1} R R) (InvOneClass.toInv.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvOneMonoid.toInvOneClass.{u1} (Equiv.{succ u1, succ u1} R R) (DivisionMonoid.toDivInvOneMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivisionMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R))))) (Rack.act'.{u1} R _inst_2 x)))\nCase conversion may be inaccurate. Consider using '#align rack.ad_conj Rack.ad_conj\u2093'. -/\n/-- The *adjoint action* of a rack on itself is `op'`, and the adjoint\naction of `x \u25c3 y` is the conjugate of the action of `y` by the action\nof `x`. It is another way to understand the self-distributivity axiom.\n\nThis is used in the natural rack homomorphism `to_conj` from `R` to\n`conj (R \u2243 R)` defined by `op'`.\n-/\ntheorem ad_conj {R : Type _} [Rack R] (x y : R) : act' (x \u25c3 y) = act' x * act' y * (act' x)\u207b\u00b9 :=\n  by\n  rw [eq_mul_inv_iff_mul_eq]; ext z\n  apply self_distrib.symm\n#align rack.ad_conj Rack.ad_conj\n\n#print Rack.oppositeRack /-\n/-- The opposite rack, swapping the roles of `\u25c3` and `\u25c3\u207b\u00b9`.\n-/\ninstance oppositeRack : Rack R\u1d50\u1d52\u1d56\n    where\n  act x y := op (invAct (unop x) (unop y))\n  self_distrib :=\n    MulOpposite.rec' fun x =>\n      MulOpposite.rec' fun y =>\n        MulOpposite.rec' fun z => by\n          simp only [unop_op, op_inj]\n          exact self_distrib_inv\n  invAct x y := op (Shelf.act (unop x) (unop y))\n  left_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp\n  right_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp\n#align rack.opposite_rack Rack.oppositeRack\n-/\n\n#print Rack.op_act_op_eq /-\n@[simp]\ntheorem op_act_op_eq {x y : R} : op x \u25c3 op y = op (x \u25c3\u207b\u00b9 y) :=\n  rfl\n#align rack.op_act_op_eq Rack.op_act_op_eq\n-/\n\n#print Rack.op_invAct_op_eq /-\n@[simp]\ntheorem op_invAct_op_eq {x y : R} : op x \u25c3\u207b\u00b9 op y = op (x \u25c3 y) :=\n  rfl\n#align rack.op_inv_act_op_eq Rack.op_invAct_op_eq\n-/\n\n#print Rack.self_act_act_eq /-\n@[simp]\ntheorem self_act_act_eq {x y : R} : (x \u25c3 x) \u25c3 y = x \u25c3 y := by rw [\u2190 right_inv x y, \u2190 self_distrib]\n#align rack.self_act_act_eq Rack.self_act_act_eq\n-/\n\n#print Rack.self_invAct_invAct_eq /-\n@[simp]\ntheorem self_invAct_invAct_eq {x y : R} : (x \u25c3\u207b\u00b9 x) \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y :=\n  by\n  have h := @self_act_act_eq _ _ (op x) (op y)\n  simpa using h\n#align rack.self_inv_act_inv_act_eq Rack.self_invAct_invAct_eq\n-/\n\n#print Rack.self_act_invAct_eq /-\n@[simp]\ntheorem self_act_invAct_eq {x y : R} : (x \u25c3 x) \u25c3\u207b\u00b9 y = x \u25c3\u207b\u00b9 y :=\n  by\n  rw [\u2190 left_cancel (x \u25c3 x)]\n  rw [right_inv]\n  rw [self_act_act_eq]\n  rw [right_inv]\n#align rack.self_act_inv_act_eq Rack.self_act_invAct_eq\n-/\n\n#print Rack.self_invAct_act_eq /-\n@[simp]\ntheorem self_invAct_act_eq {x y : R} : (x \u25c3\u207b\u00b9 x) \u25c3 y = x \u25c3 y :=\n  by\n  have h := @self_act_inv_act_eq _ _ (op x) (op y)\n  simpa using h\n#align rack.self_inv_act_act_eq Rack.self_invAct_act_eq\n-/\n\n#print Rack.self_act_eq_iff_eq /-\ntheorem self_act_eq_iff_eq {x y : R} : x \u25c3 x = y \u25c3 y \u2194 x = y :=\n  by\n  constructor; swap; rintro rfl; rfl\n  intro h\n  trans (x \u25c3 x) \u25c3\u207b\u00b9 x \u25c3 x\n  rw [\u2190 left_cancel (x \u25c3 x), right_inv, self_act_act_eq]\n  rw [h, \u2190 left_cancel (y \u25c3 y), right_inv, self_act_act_eq]\n#align rack.self_act_eq_iff_eq Rack.self_act_eq_iff_eq\n-/\n\n#print Rack.self_invAct_eq_iff_eq /-\ntheorem self_invAct_eq_iff_eq {x y : R} : x \u25c3\u207b\u00b9 x = y \u25c3\u207b\u00b9 y \u2194 x = y :=\n  by\n  have h := @self_act_eq_iff_eq _ _ (op x) (op y)\n  simpa using h\n#align rack.self_inv_act_eq_iff_eq Rack.self_invAct_eq_iff_eq\n-/\n\n#print Rack.selfApplyEquiv /-\n/-- The map `x \u21a6 x \u25c3 x` is a bijection.  (This has applications for the\nregular isotopy version of the Reidemeister I move for knot diagrams.)\n-/\ndef selfApplyEquiv (R : Type _) [Rack R] : R \u2243 R\n    where\n  toFun x := x \u25c3 x\n  invFun x := x \u25c3\u207b\u00b9 x\n  left_inv x := by simp\n  right_inv x := by simp\n#align rack.self_apply_equiv Rack.selfApplyEquiv\n-/\n\n#print Rack.IsInvolutory /-\n/-- An involutory rack is one for which `rack.op R x` is an involution for every x.\n-/\ndef IsInvolutory (R : Type _) [Rack R] : Prop :=\n  \u2200 x : R, Function.Involutive (Shelf.act x)\n#align rack.is_involutory Rack.IsInvolutory\n-/\n\n#print Rack.involutory_invAct_eq_act /-\ntheorem involutory_invAct_eq_act {R : Type _} [Rack R] (h : IsInvolutory R) (x y : R) :\n    x \u25c3\u207b\u00b9 y = x \u25c3 y := by\n  rw [\u2190 left_cancel x, right_inv]\n  exact ((h x).LeftInverse y).symm\n#align rack.involutory_inv_act_eq_act Rack.involutory_invAct_eq_act\n-/\n\n#print Rack.IsAbelian /-\n/-- An abelian rack is one for which the mediality axiom holds.\n-/\ndef IsAbelian (R : Type _) [Rack R] : Prop :=\n  \u2200 x y z w : R, (x \u25c3 y) \u25c3 z \u25c3 w = (x \u25c3 z) \u25c3 y \u25c3 w\n#align rack.is_abelian Rack.IsAbelian\n-/\n\n#print Rack.assoc_iff_id /-\n/-- Associative racks are uninteresting.\n-/\ntheorem assoc_iff_id {R : Type _} [Rack R] {x y z : R} : x \u25c3 y \u25c3 z = (x \u25c3 y) \u25c3 z \u2194 x \u25c3 z = z :=\n  by\n  rw [self_distrib]\n  rw [left_cancel]\n#align rack.assoc_iff_id Rack.assoc_iff_id\n-/\n\nend Rack\n\nnamespace ShelfHom\n\nvariable {S\u2081 : Type _} {S\u2082 : Type _} {S\u2083 : Type _} [Shelf S\u2081] [Shelf S\u2082] [Shelf S\u2083]\n\ninstance : CoeFun (S\u2081 \u2192\u25c3 S\u2082) fun _ => S\u2081 \u2192 S\u2082 :=\n  \u27e8ShelfHom.toFun\u27e9\n\n/- warning: shelf_hom.to_fun_eq_coe clashes with [anonymous] -> [anonymous]\nwarning: shelf_hom.to_fun_eq_coe -> [anonymous] is a dubious translation:\nlean 3 declaration is\n  forall {S\u2081 : Type.{u1}} {S\u2082 : Type.{u2}} [_inst_1 : Shelf.{u1} S\u2081] [_inst_2 : Shelf.{u2} S\u2082] (f : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} (S\u2081 -> S\u2082) (ShelfHom.toFun.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2 f) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) (fun (_x : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) => S\u2081 -> S\u2082) (ShelfHom.hasCoeToFun.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) f)\nbut is expected to have type\n  forall {S\u2081 : Type.{u1}} {S\u2082 : Type.{u2}}, (Nat -> S\u2081 -> S\u2082) -> Nat -> (List.{u1} S\u2081) -> (List.{u2} S\u2082)\nCase conversion may be inaccurate. Consider using '#align shelf_hom.to_fun_eq_coe [anonymous]\u2093'. -/\n@[simp]\ntheorem [anonymous] (f : S\u2081 \u2192\u25c3 S\u2082) : f.toFun = f :=\n  rfl\n#align shelf_hom.to_fun_eq_coe [anonymous]\n\n/- warning: shelf_hom.map_act -> ShelfHom.map_act is a dubious translation:\nlean 3 declaration is\n  forall {S\u2081 : Type.{u1}} {S\u2082 : Type.{u2}} [_inst_1 : Shelf.{u1} S\u2081] [_inst_2 : Shelf.{u2} S\u2082] (f : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) {x : S\u2081} {y : S\u2081}, Eq.{succ u2} S\u2082 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) (fun (_x : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) => S\u2081 -> S\u2082) (ShelfHom.hasCoeToFun.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) f (Shelf.act.{u1} S\u2081 _inst_1 x y)) (Shelf.act.{u2} S\u2082 _inst_2 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) (fun (_x : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) => S\u2081 -> S\u2082) (ShelfHom.hasCoeToFun.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) f x) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) (fun (_x : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) => S\u2081 -> S\u2082) (ShelfHom.hasCoeToFun.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) f y))\nbut is expected to have type\n  forall {S\u2081 : Type.{u2}} {S\u2082 : Type.{u1}} [_inst_1 : Shelf.{u2} S\u2081] [_inst_2 : Shelf.{u1} S\u2082] (f : ShelfHom.{u2, u1} S\u2081 S\u2082 _inst_1 _inst_2) {x : S\u2081} {y : S\u2081}, Eq.{succ u1} S\u2082 (ShelfHom.toFun.{u2, u1} S\u2081 S\u2082 _inst_1 _inst_2 f (Shelf.act.{u2} S\u2081 _inst_1 x y)) (Shelf.act.{u1} S\u2082 _inst_2 (ShelfHom.toFun.{u2, u1} S\u2081 S\u2082 _inst_1 _inst_2 f x) (ShelfHom.toFun.{u2, u1} S\u2081 S\u2082 _inst_1 _inst_2 f y))\nCase conversion may be inaccurate. Consider using '#align shelf_hom.map_act ShelfHom.map_act\u2093'. -/\n@[simp]\ntheorem map_act (f : S\u2081 \u2192\u25c3 S\u2082) {x y : S\u2081} : f (x \u25c3 y) = f x \u25c3 f y :=\n  map_act' f\n#align shelf_hom.map_act ShelfHom.map_act\n\n#print ShelfHom.id /-\n/-- The identity homomorphism -/\ndef id (S : Type _) [Shelf S] : S \u2192\u25c3 S where\n  toFun := id\n  map_act' := by simp\n#align shelf_hom.id ShelfHom.id\n-/\n\n#print ShelfHom.inhabited /-\ninstance inhabited (S : Type _) [Shelf S] : Inhabited (S \u2192\u25c3 S) :=\n  \u27e8id S\u27e9\n#align shelf_hom.inhabited ShelfHom.inhabited\n-/\n\n#print ShelfHom.comp /-\n/-- The composition of shelf homomorphisms -/\ndef comp (g : S\u2082 \u2192\u25c3 S\u2083) (f : S\u2081 \u2192\u25c3 S\u2082) : S\u2081 \u2192\u25c3 S\u2083\n    where\n  toFun := g.toFun \u2218 f.toFun\n  map_act' := by simp\n#align shelf_hom.comp ShelfHom.comp\n-/\n\n/- warning: shelf_hom.comp_apply -> ShelfHom.comp_apply is a dubious translation:\nlean 3 declaration is\n  forall {S\u2081 : Type.{u1}} {S\u2082 : Type.{u2}} {S\u2083 : Type.{u3}} [_inst_1 : Shelf.{u1} S\u2081] [_inst_2 : Shelf.{u2} S\u2082] [_inst_3 : Shelf.{u3} S\u2083] (g : ShelfHom.{u2, u3} S\u2082 S\u2083 _inst_2 _inst_3) (f : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) (x : S\u2081), Eq.{succ u3} S\u2083 (coeFn.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (ShelfHom.{u1, u3} S\u2081 S\u2083 _inst_1 _inst_3) (fun (_x : ShelfHom.{u1, u3} S\u2081 S\u2083 _inst_1 _inst_3) => S\u2081 -> S\u2083) (ShelfHom.hasCoeToFun.{u1, u3} S\u2081 S\u2083 _inst_1 _inst_3) (ShelfHom.comp.{u1, u2, u3} S\u2081 S\u2082 S\u2083 _inst_1 _inst_2 _inst_3 g f) x) (coeFn.{max (succ u2) (succ u3), max (succ u2) (succ u3)} (ShelfHom.{u2, u3} S\u2082 S\u2083 _inst_2 _inst_3) (fun (_x : ShelfHom.{u2, u3} S\u2082 S\u2083 _inst_2 _inst_3) => S\u2082 -> S\u2083) (ShelfHom.hasCoeToFun.{u2, u3} S\u2082 S\u2083 _inst_2 _inst_3) g (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) (fun (_x : ShelfHom.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) => S\u2081 -> S\u2082) (ShelfHom.hasCoeToFun.{u1, u2} S\u2081 S\u2082 _inst_1 _inst_2) f x))\nbut is expected to have type\n  forall {S\u2081 : Type.{u1}} {S\u2082 : Type.{u3}} {S\u2083 : Type.{u2}} [_inst_1 : Shelf.{u1} S\u2081] [_inst_2 : Shelf.{u3} S\u2082] [_inst_3 : Shelf.{u2} S\u2083] (g : ShelfHom.{u3, u2} S\u2082 S\u2083 _inst_2 _inst_3) (f : ShelfHom.{u1, u3} S\u2081 S\u2082 _inst_1 _inst_2) (x : S\u2081), Eq.{succ u2} S\u2083 (ShelfHom.toFun.{u1, u2} S\u2081 S\u2083 _inst_1 _inst_3 (ShelfHom.comp.{u1, u3, u2} S\u2081 S\u2082 S\u2083 _inst_1 _inst_2 _inst_3 g f) x) (ShelfHom.toFun.{u3, u2} S\u2082 S\u2083 _inst_2 _inst_3 g (ShelfHom.toFun.{u1, u3} S\u2081 S\u2082 _inst_1 _inst_2 f x))\nCase conversion may be inaccurate. Consider using '#align shelf_hom.comp_apply ShelfHom.comp_apply\u2093'. -/\n@[simp]\ntheorem comp_apply (g : S\u2082 \u2192\u25c3 S\u2083) (f : S\u2081 \u2192\u25c3 S\u2082) (x : S\u2081) : (g.comp f) x = g (f x) :=\n  rfl\n#align shelf_hom.comp_apply ShelfHom.comp_apply\n\nend ShelfHom\n\n#print Quandle /-\n/-- A quandle is a rack such that each automorphism fixes its corresponding element.\n-/\nclass Quandle (\u03b1 : Type _) extends Rack \u03b1 where\n  fix : \u2200 {x : \u03b1}, act x x = x\n#align quandle Quandle\n-/\n\nnamespace Quandle\n\nopen Rack\n\nvariable {Q : Type _} [Quandle Q]\n\nattribute [simp] fix\n\n#print Quandle.fix_inv /-\n@[simp]\ntheorem fix_inv {x : Q} : x \u25c3\u207b\u00b9 x = x :=\n  by\n  rw [\u2190 left_cancel x]\n  simp\n#align quandle.fix_inv Quandle.fix_inv\n-/\n\n#print Quandle.oppositeQuandle /-\ninstance oppositeQuandle : Quandle Q\u1d50\u1d52\u1d56\n    where fix x := by\n    induction x using MulOpposite.rec'\n    simp\n#align quandle.opposite_quandle Quandle.oppositeQuandle\n-/\n\n#print Quandle.Conj /-\n/-- The conjugation quandle of a group.  Each element of the group acts by\nthe corresponding inner automorphism.\n-/\n@[nolint has_nonempty_instance]\ndef Conj (G : Type _) :=\n  G\n#align quandle.conj Quandle.Conj\n-/\n\n#print Quandle.Conj.quandle /-\ninstance Conj.quandle (G : Type _) [Group G] : Quandle (Conj G)\n    where\n  act x := @MulAut.conj G _ x\n  self_distrib x y z :=\n    by\n    dsimp only [MulEquiv.coe_toEquiv, MulAut.conj_apply, conj]\n    group\n  invAct x := (@MulAut.conj G _ x).symm\n  left_inv x y := by\n    dsimp [act, conj]\n    group\n  right_inv x y := by\n    dsimp [act, conj]\n    group\n  fix x := by simp\n#align quandle.conj.quandle Quandle.Conj.quandle\n-/\n\n/- warning: quandle.conj_act_eq_conj -> Quandle.conj_act_eq_conj is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_2 : Group.{u1} G] (x : Quandle.Conj.{u1} G) (y : Quandle.Conj.{u1} G), Eq.{succ u1} (Quandle.Conj.{u1} G) (Shelf.act.{u1} (Quandle.Conj.{u1} G) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2))) x y) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))))) (HMul.hMul.{u1, u1, u1} G G G (instHMul.{u1} G (MulOneClass.toHasMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))))) x y) (Inv.inv.{u1} G (DivInvMonoid.toHasInv.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2)) x))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_2 : Group.{u1} G] (x : Quandle.Conj.{u1} G) (y : Quandle.Conj.{u1} G), Eq.{succ u1} (Quandle.Conj.{u1} G) (Shelf.act.{u1} (Quandle.Conj.{u1} G) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2))) x y) (HMul.hMul.{u1, u1, u1} (Quandle.Conj.{u1} G) (Quandle.Conj.{u1} G) (Quandle.Conj.{u1} G) (instHMul.{u1} (Quandle.Conj.{u1} G) (MulOneClass.toMul.{u1} (Quandle.Conj.{u1} G) (Monoid.toMulOneClass.{u1} (Quandle.Conj.{u1} G) (DivInvMonoid.toMonoid.{u1} (Quandle.Conj.{u1} G) (Group.toDivInvMonoid.{u1} (Quandle.Conj.{u1} G) _inst_2))))) (HMul.hMul.{u1, u1, u1} (Quandle.Conj.{u1} G) (Quandle.Conj.{u1} G) (Quandle.Conj.{u1} G) (instHMul.{u1} (Quandle.Conj.{u1} G) (MulOneClass.toMul.{u1} (Quandle.Conj.{u1} G) (Monoid.toMulOneClass.{u1} (Quandle.Conj.{u1} G) (DivInvMonoid.toMonoid.{u1} (Quandle.Conj.{u1} G) (Group.toDivInvMonoid.{u1} (Quandle.Conj.{u1} G) _inst_2))))) x y) (Inv.inv.{u1} (Quandle.Conj.{u1} G) (InvOneClass.toInv.{u1} (Quandle.Conj.{u1} G) (DivInvOneMonoid.toInvOneClass.{u1} (Quandle.Conj.{u1} G) (DivisionMonoid.toDivInvOneMonoid.{u1} (Quandle.Conj.{u1} G) (Group.toDivisionMonoid.{u1} (Quandle.Conj.{u1} G) _inst_2)))) x))\nCase conversion may be inaccurate. Consider using '#align quandle.conj_act_eq_conj Quandle.conj_act_eq_conj\u2093'. -/\n@[simp]\ntheorem conj_act_eq_conj {G : Type _} [Group G] (x y : Conj G) :\n    x \u25c3 y = ((x : G) * (y : G) * (x : G)\u207b\u00b9 : G) :=\n  rfl\n#align quandle.conj_act_eq_conj Quandle.conj_act_eq_conj\n\n#print Quandle.conj_swap /-\ntheorem conj_swap {G : Type _} [Group G] (x y : Conj G) : x \u25c3 y = y \u2194 y \u25c3 x = x :=\n  by\n  dsimp [conj] at *; constructor\n  repeat' intro h; conv_rhs => rw [eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h)]; simp\n#align quandle.conj_swap Quandle.conj_swap\n-/\n\n#print Quandle.Conj.map /-\n/-- `conj` is functorial\n-/\ndef Conj.map {G : Type _} {H : Type _} [Group G] [Group H] (f : G \u2192* H) : Conj G \u2192\u25c3 Conj H\n    where\n  toFun := f\n  map_act' := by simp\n#align quandle.conj.map Quandle.Conj.map\n-/\n\ninstance {G : Type _} {H : Type _} [Group G] [Group H] : HasLift (G \u2192* H) (Conj G \u2192\u25c3 Conj H)\n    where lift := Conj.map\n\n#print Quandle.Dihedral /-\n/-- The dihedral quandle. This is the conjugation quandle of the dihedral group restrict to flips.\n\nUsed for Fox n-colorings of knots.\n-/\n@[nolint has_nonempty_instance]\ndef Dihedral (n : \u2115) :=\n  ZMod n\n#align quandle.dihedral Quandle.Dihedral\n-/\n\n#print Quandle.dihedralAct /-\n/-- The operation for the dihedral quandle.  It does not need to be an equivalence\nbecause it is an involution (see `dihedral_act.inv`).\n-/\ndef dihedralAct (n : \u2115) (a : ZMod n) : ZMod n \u2192 ZMod n := fun b => 2 * a - b\n#align quandle.dihedral_act Quandle.dihedralAct\n-/\n\n#print Quandle.dihedralAct.inv /-\ntheorem dihedralAct.inv (n : \u2115) (a : ZMod n) : Function.Involutive (dihedralAct n a) :=\n  by\n  intro b\n  dsimp [dihedral_act]\n  ring\n#align quandle.dihedral_act.inv Quandle.dihedralAct.inv\n-/\n\ninstance (n : \u2115) : Quandle (Dihedral n)\n    where\n  act := dihedralAct n\n  self_distrib x y z := by dsimp [dihedral_act]; ring\n  invAct := dihedralAct n\n  left_inv x := (dihedralAct.inv n x).LeftInverse\n  right_inv x := (dihedralAct.inv n x).RightInverse\n  fix x := by dsimp [dihedral_act]; ring\n\nend Quandle\n\nnamespace Rack\n\n#print Rack.toConj /-\n/-- This is the natural rack homomorphism to the conjugation quandle of the group `R \u2243 R`\nthat acts on the rack.\n-/\ndef toConj (R : Type _) [Rack R] : R \u2192\u25c3 Quandle.Conj (R \u2243 R)\n    where\n  toFun := act'\n  map_act' := ad_conj\n#align rack.to_conj Rack.toConj\n-/\n\nsection EnvelGroup\n\n/-!\n### Universal enveloping group of a rack\n\nThe universal enveloping group `envel_group R` of a rack `R` is the\nuniversal group such that every rack homomorphism `R \u2192\u25c3 conj G` is\ninduced by a unique group homomorphism `envel_group R \u2192* G`.\nFor quandles, Joyce called this group `AdConj R`.\n\nThe `envel_group` functor is left adjoint to the `conj` forgetful\nfunctor, and the way we construct the enveloping group is via a\ntechnique that should work for left adjoints of forgetful functors in\ngeneral.  It involves thinking a little about 2-categories, but the\npayoff is that the map `envel_group R \u2192* G` has a nice description.\n\nLet's think of a group as being a one-object category.  The first step\nis to define `pre_envel_group`, which gives formal expressions for all\nthe 1-morphisms and includes the unit element, elements of `R`,\nmultiplication, and inverses.  To introduce relations, the second step\nis to define `pre_envel_group_rel'`, which gives formal expressions\nfor all 2-morphisms between the 1-morphisms.  The 2-morphisms include\nassociativity, multiplication by the unit, multiplication by inverses,\ncompatibility with multiplication and inverses (`congr_mul` and\n`congr_inv`), the axioms for an equivalence relation, and,\nimportantly, the relationship between conjugation and the rack action\n(see `rack.ad_conj`).\n\nNone of this forms a 2-category yet, for example due to lack of\nassociativity of `trans`.  The `pre_envel_group_rel` relation is a\n`Prop`-valued version of `pre_envel_group_rel'`, and making it\n`Prop`-valued essentially introduces enough 3-isomorphisms so that\nevery pair of compatible 2-morphisms is isomorphic.  Now, while\ncomposition in `pre_envel_group` does not strictly satisfy the category\naxioms, `pre_envel_group` and `pre_envel_group_rel'` do form a weak\n2-category.\n\nSince we just want a 1-category, the last step is to quotient\n`pre_envel_group` by `pre_envel_group_rel'`, and the result is the\ngroup `envel_group`.\n\nFor a homomorphism `f : R \u2192\u25c3 conj G`, how does\n`envel_group.map f : envel_group R \u2192* G` work?  Let's think of `G` as\nbeing a 2-category with one object, a 1-morphism per element of `G`,\nand a single 2-morphism called `eq.refl` for each 1-morphism.  We\ndefine the map using a \"higher `quotient.lift`\" -- not only do we\nevaluate elements of `pre_envel_group` as expressions in `G` (this is\n`to_envel_group.map_aux`), but we evaluate elements of\n`pre_envel_group'` as expressions of 2-morphisms of `G` (this is\n`to_envel_group.map_aux.well_def`).  That is to say,\n`to_envel_group.map_aux.well_def` recursively evaluates formal\nexpressions of 2-morphisms as equality proofs in `G`.  Now that all\nmorphisms are accounted for, the map descends to a homomorphism\n`envel_group R \u2192* G`.\n\nNote: `Type`-valued relations are not common.  The fact it is\n`Type`-valued is what makes `to_envel_group.map_aux.well_def` have\nwell-founded recursion.\n-/\n\n\n#print Rack.PreEnvelGroup /-\n/-- Free generators of the enveloping group.\n-/\ninductive PreEnvelGroup (R : Type u) : Type u\n  | Unit : pre_envel_group\n  | incl (x : R) : pre_envel_group\n  | mul (a b : pre_envel_group) : pre_envel_group\n  | inv (a : pre_envel_group) : pre_envel_group\n#align rack.pre_envel_group Rack.PreEnvelGroup\n-/\n\n#print Rack.PreEnvelGroup.inhabited /-\ninstance PreEnvelGroup.inhabited (R : Type u) : Inhabited (PreEnvelGroup R) :=\n  \u27e8PreEnvelGroup.unit\u27e9\n#align rack.pre_envel_group.inhabited Rack.PreEnvelGroup.inhabited\n-/\n\nopen PreEnvelGroup\n\n#print Rack.PreEnvelGroupRel' /-\n/-- Relations for the enveloping group. This is a type-valued relation because\n`to_envel_group.map_aux.well_def` inducts on it to show `to_envel_group.map`\nis well-defined.  The relation `pre_envel_group_rel` is the `Prop`-valued version,\nwhich is used to define `envel_group` itself.\n-/\ninductive PreEnvelGroupRel' (R : Type u) [Rack R] : PreEnvelGroup R \u2192 PreEnvelGroup R \u2192 Type u\n  | refl {a : PreEnvelGroup R} : pre_envel_group_rel' a a\n  | symm {a b : PreEnvelGroup R} (hab : pre_envel_group_rel' a b) : pre_envel_group_rel' b a\n  |\n  trans {a b c : PreEnvelGroup R} (hab : pre_envel_group_rel' a b)\n    (hbc : pre_envel_group_rel' b c) : pre_envel_group_rel' a c\n  |\n  congr_mul {a b a' b' : PreEnvelGroup R} (ha : pre_envel_group_rel' a a')\n    (hb : pre_envel_group_rel' b b') : pre_envel_group_rel' (mul a b) (mul a' b')\n  |\n  congr_inv {a a' : PreEnvelGroup R} (ha : pre_envel_group_rel' a a') :\n    pre_envel_group_rel' (inv a) (inv a')\n  | assoc (a b c : PreEnvelGroup R) : pre_envel_group_rel' (mul (mul a b) c) (mul a (mul b c))\n  | one_mul (a : PreEnvelGroup R) : pre_envel_group_rel' (mul Unit a) a\n  | mul_one (a : PreEnvelGroup R) : pre_envel_group_rel' (mul a Unit) a\n  | mul_left_inv (a : PreEnvelGroup R) : pre_envel_group_rel' (mul (inv a) a) Unit\n  |\n  act_incl (x y : R) :\n    pre_envel_group_rel' (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x \u25c3 y))\n#align rack.pre_envel_group_rel' Rack.PreEnvelGroupRel'\n-/\n\n#print Rack.PreEnvelGroupRel'.inhabited /-\ninstance PreEnvelGroupRel'.inhabited (R : Type u) [Rack R] :\n    Inhabited (PreEnvelGroupRel' R Unit Unit) :=\n  \u27e8PreEnvelGroupRel'.refl\u27e9\n#align rack.pre_envel_group_rel'.inhabited Rack.PreEnvelGroupRel'.inhabited\n-/\n\n#print Rack.PreEnvelGroupRel /-\n/--\nThe `pre_envel_group_rel` relation as a `Prop`.  Used as the relation for `pre_envel_group.setoid`.\n-/\ninductive PreEnvelGroupRel (R : Type u) [Rack R] : PreEnvelGroup R \u2192 PreEnvelGroup R \u2192 Prop\n  | Rel {a b : PreEnvelGroup R} (r : PreEnvelGroupRel' R a b) : pre_envel_group_rel a b\n#align rack.pre_envel_group_rel Rack.PreEnvelGroupRel\n-/\n\n#print Rack.PreEnvelGroupRel'.rel /-\n/-- A quick way to convert a `pre_envel_group_rel'` to a `pre_envel_group_rel`.\n-/\ntheorem PreEnvelGroupRel'.rel {R : Type u} [Rack R] {a b : PreEnvelGroup R} :\n    PreEnvelGroupRel' R a b \u2192 PreEnvelGroupRel R a b :=\n  PreEnvelGroupRel.rel\n#align rack.pre_envel_group_rel'.rel Rack.PreEnvelGroupRel'.rel\n-/\n\n#print Rack.PreEnvelGroupRel.refl /-\n@[refl]\ntheorem PreEnvelGroupRel.refl {R : Type u} [Rack R] {a : PreEnvelGroup R} :\n    PreEnvelGroupRel R a a :=\n  PreEnvelGroupRel.rel PreEnvelGroupRel'.refl\n#align rack.pre_envel_group_rel.refl Rack.PreEnvelGroupRel.refl\n-/\n\n#print Rack.PreEnvelGroupRel.symm /-\n@[symm]\ntheorem PreEnvelGroupRel.symm {R : Type u} [Rack R] {a b : PreEnvelGroup R} :\n    PreEnvelGroupRel R a b \u2192 PreEnvelGroupRel R b a\n  | \u27e8r\u27e9 => r.symm.Rel\n#align rack.pre_envel_group_rel.symm Rack.PreEnvelGroupRel.symm\n-/\n\n#print Rack.PreEnvelGroupRel.trans /-\n@[trans]\ntheorem PreEnvelGroupRel.trans {R : Type u} [Rack R] {a b c : PreEnvelGroup R} :\n    PreEnvelGroupRel R a b \u2192 PreEnvelGroupRel R b c \u2192 PreEnvelGroupRel R a c\n  | \u27e8rab\u27e9, \u27e8rbc\u27e9 => (rab.trans rbc).Rel\n#align rack.pre_envel_group_rel.trans Rack.PreEnvelGroupRel.trans\n-/\n\n#print Rack.PreEnvelGroup.setoid /-\ninstance PreEnvelGroup.setoid (R : Type _) [Rack R] : Setoid (PreEnvelGroup R)\n    where\n  R := PreEnvelGroupRel R\n  iseqv := by\n    constructor; apply pre_envel_group_rel.refl\n    constructor; apply pre_envel_group_rel.symm\n    apply pre_envel_group_rel.trans\n#align rack.pre_envel_group.setoid Rack.PreEnvelGroup.setoid\n-/\n\n#print Rack.EnvelGroup /-\n/-- The universal enveloping group for the rack R.\n-/\ndef EnvelGroup (R : Type _) [Rack R] :=\n  Quotient (PreEnvelGroup.setoid R)\n#align rack.envel_group Rack.EnvelGroup\n-/\n\n-- Define the `group` instances in two steps so `inv` can be inferred correctly.\n-- TODO: is there a non-invasive way of defining the instance directly?\ninstance (R : Type _) [Rack R] : DivInvMonoid (EnvelGroup R)\n    where\n  mul a b :=\n    Quotient.liftOn\u2082 a b (fun a b => \u27e6PreEnvelGroup.mul a b\u27e7) fun a b a' b' \u27e8ha\u27e9 \u27e8hb\u27e9 =>\n      Quotient.sound (PreEnvelGroupRel'.congr_mul ha hb).Rel\n  one := \u27e6Unit\u27e7\n  inv a :=\n    Quotient.liftOn a (fun a => \u27e6PreEnvelGroup.inv a\u27e7) fun a a' \u27e8ha\u27e9 =>\n      Quotient.sound (PreEnvelGroupRel'.congr_inv ha).Rel\n  mul_assoc a b c :=\n    Quotient.induction_on\u2083 a b c fun a b c => Quotient.sound (PreEnvelGroupRel'.assoc a b c).Rel\n  one_mul a := Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.one_mul a).Rel\n  mul_one a := Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.mul_one a).Rel\n\ninstance (R : Type _) [Rack R] : Group (EnvelGroup R) :=\n  { EnvelGroup.divInvMonoid _ with\n    mul_left_inv := fun a =>\n      Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.mul_left_inv a).Rel }\n\n#print Rack.EnvelGroup.inhabited /-\ninstance EnvelGroup.inhabited (R : Type _) [Rack R] : Inhabited (EnvelGroup R) :=\n  \u27e81\u27e9\n#align rack.envel_group.inhabited Rack.EnvelGroup.inhabited\n-/\n\n/- warning: rack.to_envel_group -> Rack.toEnvelGroup is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) [_inst_1 : Rack.{u1} R], ShelfHom.{u1, u1} R (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.toRack.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.Conj.quandle.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.group.{u1} R _inst_1))))\nbut is expected to have type\n  forall (R : Type.{u1}) [_inst_1 : Rack.{u1} R], ShelfHom.{u1, u1} R (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.toRack.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.Conj.quandle.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.instGroupEnvelGroup.{u1} R _inst_1))))\nCase conversion may be inaccurate. Consider using '#align rack.to_envel_group Rack.toEnvelGroup\u2093'. -/\n/-- The canonical homomorphism from a rack to its enveloping group.\nSatisfies universal properties given by `to_envel_group.map` and `to_envel_group.univ`.\n-/\ndef toEnvelGroup (R : Type _) [Rack R] : R \u2192\u25c3 Quandle.Conj (EnvelGroup R)\n    where\n  toFun x := \u27e6incl x\u27e7\n  map_act' x y := Quotient.sound (PreEnvelGroupRel'.act_incl x y).symm.Rel\n#align rack.to_envel_group Rack.toEnvelGroup\n\n#print Rack.toEnvelGroup.mapAux /-\n/-- The preliminary definition of the induced map from the enveloping group.\nSee `to_envel_group.map`.\n-/\ndef toEnvelGroup.mapAux {R : Type _} [Rack R] {G : Type _} [Group G] (f : R \u2192\u25c3 Quandle.Conj G) :\n    PreEnvelGroup R \u2192 G\n  | Unit => 1\n  | incl x => f x\n  | mul a b => to_envel_group.map_aux a * to_envel_group.map_aux b\n  | inv a => (to_envel_group.map_aux a)\u207b\u00b9\n#align rack.to_envel_group.map_aux Rack.toEnvelGroup.mapAux\n-/\n\nnamespace ToEnvelGroup.MapAux\n\nopen PreEnvelGroupRel'\n\n/- warning: rack.to_envel_group.map_aux.well_def -> Rack.toEnvelGroup.mapAux.well_def is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Rack.{u1} R] {G : Type.{u2}} [_inst_2 : Group.{u2} G] (f : ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) {a : Rack.PreEnvelGroup.{u1} R} {b : Rack.PreEnvelGroup.{u1} R}, (Rack.PreEnvelGroupRel'.{u1} R _inst_1 a b) -> (Eq.{succ u2} G (Rack.toEnvelGroup.mapAux.{u1, u2} R _inst_1 G _inst_2 f a) (Rack.toEnvelGroup.mapAux.{u1, u2} R _inst_1 G _inst_2 f b))\nbut is expected to have type\n  forall {R : Type.{u2}} [_inst_1 : Rack.{u2} R] {G : Type.{u1}} [_inst_2 : Group.{u1} G] (f : ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) {a : Rack.PreEnvelGroup.{u2} R} {b : Rack.PreEnvelGroup.{u2} R}, (Rack.PreEnvelGroupRel'.{u2} R _inst_1 a b) -> (Eq.{succ u1} G (Rack.toEnvelGroup.mapAux.{u2, u1} R _inst_1 G _inst_2 f a) (Rack.toEnvelGroup.mapAux.{u2, u1} R _inst_1 G _inst_2 f b))\nCase conversion may be inaccurate. Consider using '#align rack.to_envel_group.map_aux.well_def Rack.toEnvelGroup.mapAux.well_def\u2093'. -/\n/-- Show that `to_envel_group.map_aux` sends equivalent expressions to equal terms.\n-/\ntheorem well_def {R : Type _} [Rack R] {G : Type _} [Group G] (f : R \u2192\u25c3 Quandle.Conj G) :\n    \u2200 {a b : PreEnvelGroup R},\n      PreEnvelGroupRel' R a b \u2192 toEnvelGroup.mapAux f a = toEnvelGroup.mapAux f b\n  | a, b, refl => rfl\n  | a, b, symm h => (well_def h).symm\n  | a, b, trans hac hcb => Eq.trans (well_def hac) (well_def hcb)\n  | _, _, congr_mul ha hb => by simp [to_envel_group.map_aux, well_def ha, well_def hb]\n  | _, _, congr_inv ha => by simp [to_envel_group.map_aux, well_def ha]\n  | _, _, assoc a b c => by apply mul_assoc\n  | _, _, one_mul a => by simp [to_envel_group.map_aux]\n  | _, _, mul_one a => by simp [to_envel_group.map_aux]\n  | _, _, mul_left_inv a => by simp [to_envel_group.map_aux]\n  | _, _, act_incl x y => by simp [to_envel_group.map_aux]\n#align rack.to_envel_group.map_aux.well_def Rack.toEnvelGroup.mapAux.well_def\n\nend ToEnvelGroup.MapAux\n\n/- warning: rack.to_envel_group.map -> Rack.toEnvelGroup.map is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Rack.{u1} R] {G : Type.{u2}} [_inst_2 : Group.{u2} G], Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Rack.{u1} R] {G : Type.{u2}} [_inst_2 : Group.{u2} G], Equiv.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))\nCase conversion may be inaccurate. Consider using '#align rack.to_envel_group.map Rack.toEnvelGroup.map\u2093'. -/\n/-- Given a map from a rack to a group, lift it to being a map from the enveloping group.\nMore precisely, the `envel_group` functor is left adjoint to `quandle.conj`.\n-/\ndef toEnvelGroup.map {R : Type _} [Rack R] {G : Type _} [Group G] :\n    (R \u2192\u25c3 Quandle.Conj G) \u2243 (EnvelGroup R \u2192* G)\n    where\n  toFun f :=\n    { toFun := fun x =>\n        Quotient.liftOn x (toEnvelGroup.mapAux f) fun a b \u27e8hab\u27e9 =>\n          toEnvelGroup.mapAux.well_def f hab\n      map_one' :=\n        by\n        change Quotient.liftOn \u27e6Rack.PreEnvelGroup.unit\u27e7 (to_envel_group.map_aux f) _ = 1\n        simp [to_envel_group.map_aux]\n      map_mul' := fun x y =>\n        Quotient.induction_on\u2082 x y fun x y =>\n          by\n          change Quotient.liftOn \u27e6mul x y\u27e7 (to_envel_group.map_aux f) _ = _\n          simp [to_envel_group.map_aux] }\n  invFun F := (Quandle.Conj.map F).comp (toEnvelGroup R)\n  left_inv f := by\n    ext\n    rfl\n  right_inv F :=\n    MonoidHom.ext fun x =>\n      Quotient.inductionOn x fun x => by\n        induction x\n        \u00b7 exact F.map_one.symm\n        \u00b7 rfl\n        \u00b7 have hm : \u27e6x_a.mul x_b\u27e7 = @Mul.mul (envel_group R) _ \u27e6x_a\u27e7 \u27e6x_b\u27e7 := rfl\n          rw [hm, F.map_mul, MonoidHom.map_mul, \u2190 x_ih_a, \u2190 x_ih_b]\n        \u00b7 have hm : \u27e6x_a.inv\u27e7 = @Inv.inv (envel_group R) _ \u27e6x_a\u27e7 := rfl\n          rw [hm, F.map_inv, MonoidHom.map_inv, x_ih]\n#align rack.to_envel_group.map Rack.toEnvelGroup.map\n\n/- warning: rack.to_envel_group.univ -> Rack.toEnvelGroup.univ is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) [_inst_1 : Rack.{u1} R] (G : Type.{u2}) [_inst_2 : Group.{u2} G] (f : ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))), Eq.{max (succ u1) (succ u2)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (ShelfHom.comp.{u1, u1, u2} R (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.toRack.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.Conj.quandle.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.group.{u1} R _inst_1)))) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2))) (Quandle.Conj.map.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Rack.EnvelGroup.group.{u1} R _inst_1) _inst_2 (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ u2) (succ u1)) (max (succ u2) (succ u1)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ u2) (succ u1)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) => (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) -> (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) (Rack.toEnvelGroup.map.{u1, u2} R _inst_1 G _inst_2) f)) (Rack.toEnvelGroup.{u1} R _inst_1)) f\nbut is expected to have type\n  forall (R : Type.{u2}) [_inst_1 : Rack.{u2} R] (G : Type.{u1}) [_inst_2 : Group.{u1} G] (f : ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))), Eq.{max (succ u2) (succ u1)} (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (ShelfHom.comp.{u2, u2, u1} R (Quandle.Conj.{u2} (Rack.EnvelGroup.{u2} R _inst_1)) (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} (Rack.EnvelGroup.{u2} R _inst_1)) (Quandle.toRack.{u2} (Quandle.Conj.{u2} (Rack.EnvelGroup.{u2} R _inst_1)) (Quandle.Conj.quandle.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instGroupEnvelGroup.{u2} R _inst_1)))) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2))) (Quandle.Conj.map.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Rack.instGroupEnvelGroup.{u2} R _inst_1) _inst_2 (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))))) (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (fun (_x : ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) => MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2)))) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))))) (Rack.toEnvelGroup.map.{u2, u1} R _inst_1 G _inst_2) f)) (Rack.toEnvelGroup.{u2} R _inst_1)) f\nCase conversion may be inaccurate. Consider using '#align rack.to_envel_group.univ Rack.toEnvelGroup.univ\u2093'. -/\n/-- Given a homomorphism from a rack to a group, it factors through the enveloping group.\n-/\ntheorem toEnvelGroup.univ (R : Type _) [Rack R] (G : Type _) [Group G] (f : R \u2192\u25c3 Quandle.Conj G) :\n    (Quandle.Conj.map (toEnvelGroup.map f)).comp (toEnvelGroup R) = f :=\n  toEnvelGroup.map.symm_apply_apply f\n#align rack.to_envel_group.univ Rack.toEnvelGroup.univ\n\n/- warning: rack.to_envel_group.univ_uniq -> Rack.toEnvelGroup.univ_uniq is a dubious translation:\nlean 3 declaration is\n  forall (R : Type.{u1}) [_inst_1 : Rack.{u1} R] (G : Type.{u2}) [_inst_2 : Group.{u2} G] (f : ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (g : MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2)))), (Eq.{max (succ u1) (succ u2)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) f (ShelfHom.comp.{u1, u1, u2} R (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.toRack.{u1} (Quandle.Conj.{u1} (Rack.EnvelGroup.{u1} R _inst_1)) (Quandle.Conj.quandle.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.group.{u1} R _inst_1)))) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2))) (Quandle.Conj.map.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Rack.EnvelGroup.group.{u1} R _inst_1) _inst_2 g) (Rack.toEnvelGroup.{u1} R _inst_1))) -> (Eq.{max (succ u2) (succ u1)} (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2)))) g (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ u2) (succ u1)) (max (succ u2) (succ u1)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ u2) (succ u1)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) => (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) -> (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (ShelfHom.{u1, u2} R (Quandle.Conj.{u2} G) (Rack.toShelf.{u1} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} G) (Quandle.toRack.{u2} (Quandle.Conj.{u2} G) (Quandle.Conj.quandle.{u2} G _inst_2)))) (MonoidHom.{u1, u2} (Rack.EnvelGroup.{u1} R _inst_1) G (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))))) (Rack.toEnvelGroup.map.{u1, u2} R _inst_1 G _inst_2) f))\nbut is expected to have type\n  forall (R : Type.{u2}) [_inst_1 : Rack.{u2} R] (G : Type.{u1}) [_inst_2 : Group.{u1} G] (f : ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (g : MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2)))), (Eq.{max (succ u2) (succ u1)} (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) f (ShelfHom.comp.{u2, u2, u1} R (Quandle.Conj.{u2} (Rack.EnvelGroup.{u2} R _inst_1)) (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u2} (Quandle.Conj.{u2} (Rack.EnvelGroup.{u2} R _inst_1)) (Quandle.toRack.{u2} (Quandle.Conj.{u2} (Rack.EnvelGroup.{u2} R _inst_1)) (Quandle.Conj.quandle.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instGroupEnvelGroup.{u2} R _inst_1)))) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2))) (Quandle.Conj.map.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Rack.instGroupEnvelGroup.{u2} R _inst_1) _inst_2 g) (Rack.toEnvelGroup.{u2} R _inst_1))) -> (Eq.{max (succ u2) (succ u1)} (MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2)))) g (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))))) (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (fun (_x : ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) => (fun (x._@.Mathlib.Logic.Equiv.Defs._hyg.808 : ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) => MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2)))) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ShelfHom.{u2, u1} R (Quandle.Conj.{u1} G) (Rack.toShelf.{u2} R _inst_1) (Rack.toShelf.{u1} (Quandle.Conj.{u1} G) (Quandle.toRack.{u1} (Quandle.Conj.{u1} G) (Quandle.Conj.quandle.{u1} G _inst_2)))) (MonoidHom.{u2, u1} (Rack.EnvelGroup.{u2} R _inst_1) G (Monoid.toMulOneClass.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (DivInvMonoid.toMonoid.{u2} (Rack.EnvelGroup.{u2} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u2} R _inst_1))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))))) (Rack.toEnvelGroup.map.{u2, u1} R _inst_1 G _inst_2) f))\nCase conversion may be inaccurate. Consider using '#align rack.to_envel_group.univ_uniq Rack.toEnvelGroup.univ_uniq\u2093'. -/\n/-- The homomorphism `to_envel_group.map f` is the unique map that fits into the commutative\ntriangle in `to_envel_group.univ`.\n-/\ntheorem toEnvelGroup.univ_uniq (R : Type _) [Rack R] (G : Type _) [Group G]\n    (f : R \u2192\u25c3 Quandle.Conj G) (g : EnvelGroup R \u2192* G)\n    (h : f = (Quandle.Conj.map g).comp (toEnvelGroup R)) : g = toEnvelGroup.map f :=\n  h.symm \u25b8 (toEnvelGroup.map.apply_symm_apply g).symm\n#align rack.to_envel_group.univ_uniq Rack.toEnvelGroup.univ_uniq\n\n/- warning: rack.envel_action -> Rack.envelAction is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : Rack.{u1} R], MonoidHom.{u1, u1} (Rack.EnvelGroup.{u1} R _inst_1) (Equiv.{succ u1, succ u1} R R) (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.EnvelGroup.divInvMonoid.{u1} R _inst_1))) (Monoid.toMulOneClass.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvMonoid.toMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivInvMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : Rack.{u1} R], MonoidHom.{u1, u1} (Rack.EnvelGroup.{u1} R _inst_1) (Equiv.{succ u1, succ u1} R R) (Monoid.toMulOneClass.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (DivInvMonoid.toMonoid.{u1} (Rack.EnvelGroup.{u1} R _inst_1) (Rack.instDivInvMonoidEnvelGroup.{u1} R _inst_1))) (Monoid.toMulOneClass.{u1} (Equiv.{succ u1, succ u1} R R) (DivInvMonoid.toMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Group.toDivInvMonoid.{u1} (Equiv.{succ u1, succ u1} R R) (Equiv.Perm.permGroup.{u1} R))))\nCase conversion may be inaccurate. Consider using '#align rack.envel_action Rack.envelAction\u2093'. -/\n/-- The induced group homomorphism from the enveloping group into bijections of the rack,\nusing `rack.to_conj`. Satisfies the property `envel_action_prop`.\n\nThis gives the rack `R` the structure of an augmented rack over `envel_group R`.\n-/\ndef envelAction {R : Type _} [Rack R] : EnvelGroup R \u2192* R \u2243 R :=\n  toEnvelGroup.map (toConj R)\n#align rack.envel_action Rack.envelAction\n\n#print Rack.envelAction_prop /-\n@[simp]\ntheorem envelAction_prop {R : Type _} [Rack R] (x y : R) :\n    envelAction (toEnvelGroup R x) y = x \u25c3 y :=\n  rfl\n#align rack.envel_action_prop Rack.envelAction_prop\n-/\n\nend EnvelGroup\n\nend Rack\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/Algebra/Quandle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7004663415331375}}
{"text": "/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.finset.lattice\nimport data.multiset.sort\nimport data.list.nodup_equiv_fin\n\n/-!\n# Construct a sorted list from a finset.\n-/\n\nnamespace finset\n\nopen multiset nat\nvariables {\u03b1 \u03b2 : Type*}\n\n/-! ### sort -/\nsection sort\nvariables (r : \u03b1 \u2192 \u03b1 \u2192 Prop) [decidable_rel r]\n  [is_trans \u03b1 r] [is_antisymm \u03b1 r] [is_total \u03b1 r]\n\n/-- `sort s` constructs a sorted list from the unordered set `s`.\n  (Uses merge sort algorithm.) -/\ndef sort (s : finset \u03b1) : list \u03b1 := sort r s.1\n\n@[simp] theorem sort_sorted (s : finset \u03b1) : list.sorted r (sort r s) :=\nsort_sorted _ _\n\n@[simp] theorem sort_eq (s : finset \u03b1) : \u2191(sort r s) = s.1 :=\nsort_eq _ _\n\n@[simp] theorem sort_nodup (s : finset \u03b1) : (sort r s).nodup :=\n(by rw sort_eq; exact s.2 : @multiset.nodup \u03b1 (sort r s))\n\n@[simp] theorem sort_to_finset [decidable_eq \u03b1] (s : finset \u03b1) : (sort r s).to_finset = s :=\nlist.to_finset_eq (sort_nodup r s) \u25b8 eq_of_veq (sort_eq r s)\n\n@[simp] theorem mem_sort {s : finset \u03b1} {a : \u03b1} : a \u2208 sort r s \u2194 a \u2208 s :=\nmultiset.mem_sort _\n\n@[simp] theorem length_sort {s : finset \u03b1} : (sort r s).length = s.card :=\nmultiset.length_sort _\n\nend sort\n\nsection sort_linear_order\n\nvariables [linear_order \u03b1]\n\ntheorem sort_sorted_lt (s : finset \u03b1) : list.sorted (<) (sort (\u2264) s) :=\n(sort_sorted _ _).imp\u2082 (@lt_of_le_of_ne _ _) (sort_nodup _ _)\n\nlemma sorted_zero_eq_min'_aux (s : finset \u03b1) (h : 0 < (s.sort (\u2264)).length) (H : s.nonempty) :\n  (s.sort (\u2264)).nth_le 0 h = s.min' H :=\nbegin\n  let l := s.sort (\u2264),\n  apply le_antisymm,\n  { have : s.min' H \u2208 l := (finset.mem_sort (\u2264)).mpr (s.min'_mem H),\n    obtain \u27e8i, i_lt, hi\u27e9 : \u2203 i (hi : i < l.length), l.nth_le i hi = s.min' H :=\n      list.mem_iff_nth_le.1 this,\n    rw \u2190 hi,\n    exact (s.sort_sorted (\u2264)).rel_nth_le_of_le _ _ (nat.zero_le i) },\n  { have : l.nth_le 0 h \u2208 s := (finset.mem_sort (\u2264)).1 (list.nth_le_mem l 0 h),\n    exact s.min'_le _ this }\nend\n\nlemma sorted_zero_eq_min' {s : finset \u03b1} {h : 0 < (s.sort (\u2264)).length} :\n  (s.sort (\u2264)).nth_le 0 h = s.min' (card_pos.1 $ by rwa length_sort at h) :=\nsorted_zero_eq_min'_aux _ _ _\n\nlemma min'_eq_sorted_zero {s : finset \u03b1} {h : s.nonempty} :\n  s.min' h = (s.sort (\u2264)).nth_le 0 (by { rw length_sort, exact card_pos.2 h }) :=\n(sorted_zero_eq_min'_aux _ _ _).symm\n\nlemma sorted_last_eq_max'_aux (s : finset \u03b1) (h : (s.sort (\u2264)).length - 1 < (s.sort (\u2264)).length)\n  (H : s.nonempty) : (s.sort (\u2264)).nth_le ((s.sort (\u2264)).length - 1) h = s.max' H :=\nbegin\n  let l := s.sort (\u2264),\n  apply le_antisymm,\n  { have : l.nth_le ((s.sort (\u2264)).length - 1) h \u2208 s :=\n      (finset.mem_sort (\u2264)).1 (list.nth_le_mem l _ h),\n    exact s.le_max' _ this },\n  { have : s.max' H \u2208 l := (finset.mem_sort (\u2264)).mpr (s.max'_mem H),\n    obtain \u27e8i, i_lt, hi\u27e9 : \u2203 i (hi : i < l.length), l.nth_le i hi = s.max' H :=\n      list.mem_iff_nth_le.1 this,\n    rw \u2190 hi,\n    have : i \u2264 l.length - 1 := nat.le_pred_of_lt i_lt,\n    exact (s.sort_sorted (\u2264)).rel_nth_le_of_le _ _ (nat.le_pred_of_lt i_lt) },\nend\n\nlemma sorted_last_eq_max' {s : finset \u03b1} {h : (s.sort (\u2264)).length - 1 < (s.sort (\u2264)).length} :\n  (s.sort (\u2264)).nth_le ((s.sort (\u2264)).length - 1) h =\n  s.max' (by { rw length_sort at h, exact card_pos.1 (lt_of_le_of_lt bot_le h) }) :=\nsorted_last_eq_max'_aux _ _ _\n\nlemma max'_eq_sorted_last {s : finset \u03b1} {h : s.nonempty} :\n  s.max' h = (s.sort (\u2264)).nth_le ((s.sort (\u2264)).length - 1)\n    (by simpa using sub_lt (card_pos.mpr h) zero_lt_one) :=\n(sorted_last_eq_max'_aux _ _ _).symm\n\n/-- Given a finset `s` of cardinality `k` in a linear order `\u03b1`, the map `order_iso_of_fin s h`\nis the increasing bijection between `fin k` and `s` as an `order_iso`. Here, `h` is a proof that\nthe cardinality of `s` is `k`. We use this instead of an iso `fin s.card \u2243o s` to avoid\ncasting issues in further uses of this function. -/\ndef order_iso_of_fin (s : finset \u03b1) {k : \u2115} (h : s.card = k) : fin k \u2243o (s : set \u03b1) :=\norder_iso.trans (fin.cast ((length_sort (\u2264)).trans h).symm) $\n  (s.sort_sorted_lt.nth_le_iso _).trans $ order_iso.set_congr _ _ $\n    set.ext $ \u03bb x, mem_sort _\n\n/-- Given a finset `s` of cardinality `k` in a linear order `\u03b1`, the map `order_emb_of_fin s h` is\nthe increasing bijection between `fin k` and `s` as an order embedding into `\u03b1`. Here, `h` is a\nproof that the cardinality of `s` is `k`. We use this instead of an embedding `fin s.card \u21aao \u03b1` to\navoid casting issues in further uses of this function. -/\ndef order_emb_of_fin (s : finset \u03b1) {k : \u2115} (h : s.card = k) : fin k \u21aao \u03b1 :=\n(order_iso_of_fin s h).to_order_embedding.trans (order_embedding.subtype _)\n\n@[simp] lemma coe_order_iso_of_fin_apply (s : finset \u03b1) {k : \u2115} (h : s.card = k) (i : fin k) :\n  \u2191(order_iso_of_fin s h i) = order_emb_of_fin s h i :=\nrfl\n\nlemma order_iso_of_fin_symm_apply (s : finset \u03b1) {k : \u2115} (h : s.card = k) (x : (s : set \u03b1)) :\n  \u2191((s.order_iso_of_fin h).symm x) = (s.sort (\u2264)).index_of x :=\nrfl\n\nlemma order_emb_of_fin_apply (s : finset \u03b1) {k : \u2115} (h : s.card = k) (i : fin k) :\n  s.order_emb_of_fin h i = (s.sort (\u2264)).nth_le i (by { rw [length_sort, h], exact i.2 }) :=\nrfl\n\n@[simp] lemma order_emb_of_fin_mem (s : finset \u03b1) {k : \u2115} (h : s.card = k) (i : fin k) :\n  s.order_emb_of_fin h i \u2208 s :=\n(s.order_iso_of_fin h i).2\n\n@[simp] lemma range_order_emb_of_fin (s : finset \u03b1) {k : \u2115} (h : s.card = k) :\n  set.range (s.order_emb_of_fin h) = s :=\nby simp [order_emb_of_fin, set.range_comp coe (s.order_iso_of_fin h)]\n\n/-- The bijection `order_emb_of_fin s h` sends `0` to the minimum of `s`. -/\nlemma order_emb_of_fin_zero {s : finset \u03b1} {k : \u2115} (h : s.card = k) (hz : 0 < k) :\n  order_emb_of_fin s h \u27e80, hz\u27e9 = s.min' (card_pos.mp (h.symm \u25b8 hz)) :=\nby simp only [order_emb_of_fin_apply, subtype.coe_mk, sorted_zero_eq_min']\n\n/-- The bijection `order_emb_of_fin s h` sends `k-1` to the maximum of `s`. -/\nlemma order_emb_of_fin_last {s : finset \u03b1} {k : \u2115} (h : s.card = k) (hz : 0 < k) :\n  order_emb_of_fin s h \u27e8k-1, buffer.lt_aux_2 hz\u27e9 = s.max' (card_pos.mp (h.symm \u25b8 hz)) :=\nby simp [order_emb_of_fin_apply, max'_eq_sorted_last, h]\n\n/-- `order_emb_of_fin {a} h` sends any argument to `a`. -/\n@[simp] lemma order_emb_of_fin_singleton (a : \u03b1) (i : fin 1) :\n  order_emb_of_fin {a} (card_singleton a) i = a :=\nby rw [subsingleton.elim i \u27e80, zero_lt_one\u27e9, order_emb_of_fin_zero _ zero_lt_one, min'_singleton]\n\n/-- Any increasing map `f` from `fin k` to a finset of cardinality `k` has to coincide with\nthe increasing bijection `order_emb_of_fin s h`. -/\nlemma order_emb_of_fin_unique {s : finset \u03b1} {k : \u2115} (h : s.card = k) {f : fin k \u2192 \u03b1}\n  (hfs : \u2200 x, f x \u2208 s) (hmono : strict_mono f) : f = s.order_emb_of_fin h :=\nbegin\n  apply fin.strict_mono_unique hmono (s.order_emb_of_fin h).strict_mono,\n  rw [range_order_emb_of_fin, \u2190 set.image_univ, \u2190 coe_fin_range, \u2190 coe_image, coe_inj],\n  refine eq_of_subset_of_card_le (\u03bb x hx, _) _,\n  { rcases mem_image.1 hx with \u27e8x, hx, rfl\u27e9, exact hfs x },\n  { rw [h, card_image_of_injective _ hmono.injective, fin_range_card] }\nend\n\n/-- An order embedding `f` from `fin k` to a finset of cardinality `k` has to coincide with\nthe increasing bijection `order_emb_of_fin s h`. -/\nlemma order_emb_of_fin_unique' {s : finset \u03b1} {k : \u2115} (h : s.card = k) {f : fin k \u21aao \u03b1}\n  (hfs : \u2200 x, f x \u2208 s) : f = s.order_emb_of_fin h :=\nrel_embedding.ext $ function.funext_iff.1 $ order_emb_of_fin_unique h hfs f.strict_mono\n\n/-- Two parametrizations `order_emb_of_fin` of the same set take the same value on `i` and `j` if\nand only if `i = j`. Since they can be defined on a priori not defeq types `fin k` and `fin l`\n(although necessarily `k = l`), the conclusion is rather written `(i : \u2115) = (j : \u2115)`. -/\n@[simp] lemma order_emb_of_fin_eq_order_emb_of_fin_iff\n  {k l : \u2115} {s : finset \u03b1} {i : fin k} {j : fin l} {h : s.card = k} {h' : s.card = l} :\n  s.order_emb_of_fin h i = s.order_emb_of_fin h' j \u2194 (i : \u2115) = (j : \u2115) :=\nbegin\n  substs k l,\n  exact (s.order_emb_of_fin rfl).eq_iff_eq.trans (fin.ext_iff _ _)\nend\n\nend sort_linear_order\n\ninstance [has_repr \u03b1] : has_repr (finset \u03b1) := \u27e8\u03bb s, repr s.1\u27e9\n\nend finset\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/finset/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7004663341093474}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Patrick Massot\n-/\nimport data.set.intervals.proj_Icc\nimport topology.order.basic\n\n/-!\n# Projection onto a closed interval\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file we prove that the projection `set.proj_Icc f a b h` is a quotient map, and use it\nto show that `Icc_extend h f` is continuous if and only if `f` is continuous.\n-/\n\nopen set filter\nopen_locale filter topology\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*} [linear_order \u03b1] [topological_space \u03b3] {a b c : \u03b1} {h : a \u2264 b}\n\nlemma filter.tendsto.Icc_extend (f : \u03b3 \u2192 Icc a b \u2192 \u03b2) {z : \u03b3} {l : filter \u03b1} {l' : filter \u03b2}\n  (hf : tendsto \u21bff (\ud835\udcdd z \u00d7\u1da0 l.map (proj_Icc a b h)) l') :\n  tendsto \u21bf(Icc_extend h \u2218 f) (\ud835\udcdd z \u00d7\u1da0 l) l' :=\nshow tendsto (\u21bff \u2218 prod.map id (proj_Icc a b h)) (\ud835\udcdd z \u00d7\u1da0 l) l', from\nhf.comp $ tendsto_id.prod_map tendsto_map\n\nvariables [topological_space \u03b1] [order_topology \u03b1] [topological_space \u03b2]\n\n@[continuity]\nlemma continuous_proj_Icc : continuous (proj_Icc a b h) :=\n(continuous_const.max $ continuous_const.min continuous_id).subtype_mk _\n\nlemma quotient_map_proj_Icc : quotient_map (proj_Icc a b h) :=\nquotient_map_iff.2 \u27e8proj_Icc_surjective h, \u03bb s,\n  \u27e8\u03bb hs, hs.preimage continuous_proj_Icc,\n   \u03bb hs, \u27e8_, hs, by { ext, simp }\u27e9\u27e9\u27e9\n\n@[simp] lemma continuous_Icc_extend_iff {f : Icc a b \u2192 \u03b2} :\n  continuous (Icc_extend h f) \u2194 continuous f :=\nquotient_map_proj_Icc.continuous_iff.symm\n\n/-- See Note [continuity lemma statement]. -/\nlemma continuous.Icc_extend {f : \u03b3 \u2192 Icc a b \u2192 \u03b2} {g : \u03b3 \u2192 \u03b1}\n  (hf : continuous \u21bff) (hg : continuous g) : continuous (\u03bb a, Icc_extend h (f a) (g a)) :=\nhf.comp $ continuous_id.prod_mk $ continuous_proj_Icc.comp hg\n\n/-- A useful special case of `continuous.Icc_extend`. -/\n@[continuity]\nlemma continuous.Icc_extend' {f : Icc a b \u2192 \u03b2} (hf : continuous f) : continuous (Icc_extend h f) :=\nhf.comp continuous_proj_Icc\n\nlemma continuous_at.Icc_extend {x : \u03b3} (f : \u03b3 \u2192 Icc a b \u2192 \u03b2) {g : \u03b3 \u2192 \u03b1}\n  (hf : continuous_at \u21bff (x, proj_Icc a b h (g x))) (hg : continuous_at g x) :\n  continuous_at (\u03bb a, Icc_extend h (f a) (g a)) x :=\nshow continuous_at (\u21bff \u2218 \u03bb x, (x, proj_Icc a b h (g x))) x, from\ncontinuous_at.comp hf $ continuous_at_id.prod $ continuous_proj_Icc.continuous_at.comp hg\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/algebra/order/proj_Icc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7004663297922183}}
{"text": "/-\nCopyright (c) 2019 Michael Howes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Michael Howes\n\nDefining a group given by generators and relations\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.group_theory.free_group\nimport Mathlib.group_theory.quotient_group\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-- Given a set of relations, rels, over a type \u03b1, presented_group constructs the group with\ngenerators \u03b1 and relations rels as a quotient of free_group \u03b1.-/\ndef presented_group {\u03b1 : Type} (rels : set (free_group \u03b1)) :=\n  quotient_group.quotient (subgroup.normal_closure rels)\n\nnamespace presented_group\n\n\nprotected instance group {\u03b1 : Type} (rels : set (free_group \u03b1)) : group (presented_group rels) :=\n  quotient_group.quotient.group (subgroup.normal_closure rels)\n\n/-- `of x` is the canonical map from \u03b1 to a presented group with generators \u03b1. The term x is\nmapped to the equivalence class of the image of x in free_group \u03b1. -/\ndef of {\u03b1 : Type} {rels : set (free_group \u03b1)} (x : \u03b1) : presented_group rels :=\n  quotient_group.mk (free_group.of x)\n\n/-\nPresented groups satisfy a universal property. If \u03b2 is a group and f : \u03b1 \u2192 \u03b2 is a map such that the\nimages of f satisfy all the given relations, then f extends uniquely to a group homomorphism from\npresented_group rels to \u03b2\n-/\n\ntheorem closure_rels_subset_ker {\u03b1 : Type} {\u03b2 : Type} [group \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {rels : set (free_group \u03b1)}\n    (h : \u2200 (r : free_group \u03b1), r \u2208 rels \u2192 coe_fn (free_group.to_group f) r = 1) :\n    subgroup.normal_closure rels \u2264 monoid_hom.ker (free_group.to_group f) :=\n  subgroup.normal_closure_le_normal\n    fun (x : free_group \u03b1) (w : x \u2208 rels) =>\n      iff.mpr (monoid_hom.mem_ker (free_group.to_group f)) (h x w)\n\ntheorem to_group_eq_one_of_mem_closure {\u03b1 : Type} {\u03b2 : Type} [group \u03b2] {f : \u03b1 \u2192 \u03b2}\n    {rels : set (free_group \u03b1)}\n    (h : \u2200 (r : free_group \u03b1), r \u2208 rels \u2192 coe_fn (free_group.to_group f) r = 1) (x : free_group \u03b1)\n    (H : x \u2208 subgroup.normal_closure rels) : coe_fn (free_group.to_group f) x = 1 :=\n  iff.mp (monoid_hom.mem_ker (free_group.to_group f)) (closure_rels_subset_ker h w)\n\n/-- The extension of a map f : \u03b1 \u2192 \u03b2 that satisfies the given relations to a group homomorphism\nfrom presented_group rels \u2192 \u03b2. -/\ndef to_group {\u03b1 : Type} {\u03b2 : Type} [group \u03b2] {f : \u03b1 \u2192 \u03b2} {rels : set (free_group \u03b1)}\n    (h : \u2200 (r : free_group \u03b1), r \u2208 rels \u2192 coe_fn (free_group.to_group f) r = 1) :\n    presented_group rels \u2192* \u03b2 :=\n  quotient_group.lift (subgroup.normal_closure rels) (monoid_hom.of \u21d1(free_group.to_group f))\n    (to_group_eq_one_of_mem_closure h)\n\n@[simp] theorem to_group.of {\u03b1 : Type} {\u03b2 : Type} [group \u03b2] {f : \u03b1 \u2192 \u03b2} {rels : set (free_group \u03b1)}\n    (h : \u2200 (r : free_group \u03b1), r \u2208 rels \u2192 coe_fn (free_group.to_group f) r = 1) {x : \u03b1} :\n    coe_fn (to_group h) (of x) = f x :=\n  free_group.to_group.of\n\ntheorem to_group.unique {\u03b1 : Type} {\u03b2 : Type} [group \u03b2] {f : \u03b1 \u2192 \u03b2} {rels : set (free_group \u03b1)}\n    (h : \u2200 (r : free_group \u03b1), r \u2208 rels \u2192 coe_fn (free_group.to_group f) r = 1)\n    (g : presented_group rels \u2192* \u03b2) (hg : \u2200 (x : \u03b1), coe_fn g (of x) = f x)\n    {x : presented_group rels} : coe_fn g x = coe_fn (to_group h) x :=\n  quotient_group.induction_on x\n    fun (_x : free_group \u03b1) =>\n      free_group.to_group.unique\n        (monoid_hom.comp g (quotient_group.mk' (subgroup.normal_closure rels))) hg\n\nprotected instance inhabited {\u03b1 : Type} (rels : set (free_group \u03b1)) :\n    Inhabited (presented_group rels) :=\n  { default := 1 }\n\nend Mathlib", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/group_theory/presented_group_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7004663279362708}}
{"text": "/-\nCopyright (c) 2018 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport order.bounds\nimport data.set.intervals.basic\nimport data.set.finite\nimport data.set.lattice\n\n/-!\n# Theory of conditionally complete lattices.\n\nA conditionally complete lattice is a lattice in which every non-empty bounded subset s\nhas a least upper bound and a greatest lower bound, denoted below by Sup s and Inf s.\nTypical examples are real, nat, int with their usual orders.\n\nThe theory is very comparable to the theory of complete lattices, except that suitable\nboundedness and nonemptiness assumptions have to be added to most statements.\nWe introduce two predicates bdd_above and bdd_below to express this boundedness, prove\ntheir basic properties, and then go on to prove most useful properties of Sup and Inf\nin conditionally complete lattices.\n\nTo differentiate the statements between complete lattices and conditionally complete\nlattices, we prefix Inf and Sup in the statements by c, giving cInf and cSup. For instance,\nInf_le is a statement in complete lattices ensuring Inf s \u2264 x, while cInf_le is the same\nstatement in conditionally complete lattices with an additional assumption that s is\nbounded below.\n-/\n\nset_option old_structure_cmd true\n\nopen function order_dual set\n\nvariables {\u03b1 \u03b2 \u03b3 : Type*} {\u03b9 : Sort*}\n\nsection\n\n/-!\nExtension of Sup and Inf from a preorder `\u03b1` to `with_top \u03b1` and `with_bot \u03b1`\n-/\n\nopen_locale classical\n\nnoncomputable instance {\u03b1 : Type*} [preorder \u03b1] [has_Sup \u03b1] : has_Sup (with_top \u03b1) :=\n\u27e8\u03bb S, if \u22a4 \u2208 S then \u22a4 else\n  if bdd_above (coe \u207b\u00b9' S : set \u03b1) then \u2191(Sup (coe \u207b\u00b9' S : set \u03b1)) else \u22a4\u27e9\n\nnoncomputable instance {\u03b1 : Type*} [has_Inf \u03b1] : has_Inf (with_top \u03b1) :=\n\u27e8\u03bb S, if S \u2286 {\u22a4} then \u22a4 else \u2191(Inf (coe \u207b\u00b9' S : set \u03b1))\u27e9\n\nnoncomputable instance {\u03b1 : Type*} [has_Sup \u03b1] : has_Sup (with_bot \u03b1) :=\n\u27e8(@with_top.has_Inf \u03b1\u1d52\u1d48 _).Inf\u27e9\n\nnoncomputable instance {\u03b1 : Type*} [preorder \u03b1] [has_Inf \u03b1] : has_Inf (with_bot \u03b1) :=\n\u27e8(@with_top.has_Sup \u03b1\u1d52\u1d48 _ _).Sup\u27e9\n\n@[simp]\ntheorem with_top.cInf_empty {\u03b1 : Type*} [has_Inf \u03b1] : Inf (\u2205 : set (with_top \u03b1)) = \u22a4 :=\nif_pos $ set.empty_subset _\n\n@[simp]\ntheorem with_bot.cSup_empty {\u03b1 : Type*} [has_Sup \u03b1] : Sup (\u2205 : set (with_bot \u03b1)) = \u22a5 :=\nif_pos $ set.empty_subset _\n\nend -- section\n\n/-- A conditionally complete lattice is a lattice in which\nevery nonempty subset which is bounded above has a supremum, and\nevery nonempty subset which is bounded below has an infimum.\nTypical examples are real numbers or natural numbers.\n\nTo differentiate the statements from the corresponding statements in (unconditional)\ncomplete lattices, we prefix Inf and Sup by a c everywhere. The same statements should\nhold in both worlds, sometimes with additional assumptions of nonemptiness or\nboundedness.-/\nclass conditionally_complete_lattice (\u03b1 : Type*) extends lattice \u03b1, has_Sup \u03b1, has_Inf \u03b1 :=\n(le_cSup : \u2200 s a, bdd_above s \u2192 a \u2208 s \u2192 a \u2264 Sup s)\n(cSup_le : \u2200 s a, set.nonempty s \u2192 a \u2208 upper_bounds s \u2192 Sup s \u2264 a)\n(cInf_le : \u2200 s a, bdd_below s \u2192 a \u2208 s \u2192 Inf s \u2264 a)\n(le_cInf : \u2200 s a, set.nonempty s \u2192 a \u2208 lower_bounds s \u2192 a \u2264 Inf s)\n\n/-- A conditionally complete linear order is a linear order in which\nevery nonempty subset which is bounded above has a supremum, and\nevery nonempty subset which is bounded below has an infimum.\nTypical examples are real numbers or natural numbers.\n\nTo differentiate the statements from the corresponding statements in (unconditional)\ncomplete linear orders, we prefix Inf and Sup by a c everywhere. The same statements should\nhold in both worlds, sometimes with additional assumptions of nonemptiness or\nboundedness.-/\nclass conditionally_complete_linear_order (\u03b1 : Type*)\n  extends conditionally_complete_lattice \u03b1, linear_order \u03b1 renaming max \u2192 sup min \u2192 inf\n\n/-- A conditionally complete linear order with `bot` is a linear order with least element, in which\nevery nonempty subset which is bounded above has a supremum, and every nonempty subset (necessarily\nbounded below) has an infimum.  A typical example is the natural numbers.\n\nTo differentiate the statements from the corresponding statements in (unconditional)\ncomplete linear orders, we prefix Inf and Sup by a c everywhere. The same statements should\nhold in both worlds, sometimes with additional assumptions of nonemptiness or\nboundedness.-/\n@[ancestor conditionally_complete_linear_order has_bot]\nclass conditionally_complete_linear_order_bot (\u03b1 : Type*)\n  extends conditionally_complete_linear_order \u03b1, has_bot \u03b1 :=\n(bot_le : \u2200 x : \u03b1, \u22a5 \u2264 x)\n(cSup_empty : Sup \u2205 = \u22a5)\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance conditionally_complete_linear_order_bot.to_order_bot\n  [h : conditionally_complete_linear_order_bot \u03b1] : order_bot \u03b1 :=\n{ ..h }\n\n/-- A complete lattice is a conditionally complete lattice, as there are no restrictions\non the properties of Inf and Sup in a complete lattice.-/\n@[priority 100] -- see Note [lower instance priority]\ninstance complete_lattice.to_conditionally_complete_lattice [complete_lattice \u03b1] :\n  conditionally_complete_lattice \u03b1 :=\n{ le_cSup := by intros; apply le_Sup; assumption,\n  cSup_le := by intros; apply Sup_le; assumption,\n  cInf_le := by intros; apply Inf_le; assumption,\n  le_cInf := by intros; apply le_Inf; assumption,\n  ..\u2039complete_lattice \u03b1\u203a }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance complete_linear_order.to_conditionally_complete_linear_order_bot {\u03b1 : Type*}\n  [complete_linear_order \u03b1] :\n  conditionally_complete_linear_order_bot \u03b1 :=\n{ cSup_empty := Sup_empty,\n  ..complete_lattice.to_conditionally_complete_lattice, .. \u2039complete_linear_order \u03b1\u203a }\n\nsection\nopen_locale classical\n\n/-- A well founded linear order is conditionally complete, with a bottom element. -/\n@[reducible] noncomputable def is_well_order.conditionally_complete_linear_order_bot\n  (\u03b1 : Type*) [i\u2081 : linear_order \u03b1] [i\u2082 : order_bot \u03b1] [h : is_well_order \u03b1 (<)] :\n  conditionally_complete_linear_order_bot \u03b1 :=\n{ Inf := \u03bb s, if hs : s.nonempty then h.wf.min s hs else \u22a5,\n  cInf_le := \u03bb s a hs has, begin\n    have s_ne : s.nonempty := \u27e8a, has\u27e9,\n    simpa [s_ne] using not_lt.1 (h.wf.not_lt_min s s_ne has),\n  end,\n  le_cInf := \u03bb s a hs has, begin\n    simp only [hs, dif_pos],\n    exact has (h.wf.min_mem s hs),\n  end,\n  Sup := \u03bb s, if hs : (upper_bounds s).nonempty then h.wf.min _ hs else \u22a5,\n  le_cSup := \u03bb s a hs has, begin\n    have h's : (upper_bounds s).nonempty := hs,\n    simp only [h's, dif_pos],\n    exact h.wf.min_mem _ h's has,\n  end,\n  cSup_le := \u03bb s a hs has, begin\n    have h's : (upper_bounds s).nonempty := \u27e8a, has\u27e9,\n    simp only [h's, dif_pos],\n    simpa using h.wf.not_lt_min _ h's has,\n  end,\n  cSup_empty := by simpa using eq_bot_iff.2 (not_lt.1 $ h.wf.not_lt_min _ _ $ mem_univ \u22a5),\n  ..i\u2081, ..i\u2082, ..linear_order.to_lattice }\n\nend\n\nsection order_dual\n\ninstance (\u03b1 : Type*) [conditionally_complete_lattice \u03b1] : conditionally_complete_lattice \u03b1\u1d52\u1d48 :=\n{ le_cSup := @conditionally_complete_lattice.cInf_le \u03b1 _,\n  cSup_le := @conditionally_complete_lattice.le_cInf \u03b1 _,\n  le_cInf := @conditionally_complete_lattice.cSup_le \u03b1 _,\n  cInf_le := @conditionally_complete_lattice.le_cSup \u03b1 _,\n  ..order_dual.has_Inf \u03b1,\n  ..order_dual.has_Sup \u03b1,\n  ..order_dual.lattice \u03b1 }\n\ninstance (\u03b1 : Type*) [conditionally_complete_linear_order \u03b1] :\n  conditionally_complete_linear_order \u03b1\u1d52\u1d48 :=\n{ ..order_dual.conditionally_complete_lattice \u03b1,\n  ..order_dual.linear_order \u03b1 }\n\nend order_dual\n\nsection conditionally_complete_lattice\nvariables [conditionally_complete_lattice \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\ntheorem le_cSup (h\u2081 : bdd_above s) (h\u2082 : a \u2208 s) : a \u2264 Sup s :=\nconditionally_complete_lattice.le_cSup s a h\u2081 h\u2082\n\ntheorem cSup_le (h\u2081 : s.nonempty) (h\u2082 : \u2200 b \u2208 s, b \u2264 a) : Sup s \u2264 a :=\nconditionally_complete_lattice.cSup_le s a h\u2081 h\u2082\n\ntheorem cInf_le (h\u2081 : bdd_below s) (h\u2082 : a \u2208 s) : Inf s \u2264 a :=\nconditionally_complete_lattice.cInf_le s a h\u2081 h\u2082\n\ntheorem le_cInf (h\u2081 : s.nonempty) (h\u2082 : \u2200 b \u2208 s, a \u2264 b) : a \u2264 Inf s :=\nconditionally_complete_lattice.le_cInf s a h\u2081 h\u2082\n\ntheorem le_cSup_of_le (hs : bdd_above s) (hb : b \u2208 s) (h : a \u2264 b) : a \u2264 Sup s :=\nle_trans h (le_cSup hs hb)\n\ntheorem cInf_le_of_le (hs : bdd_below s) (hb : b \u2208 s) (h : b \u2264 a) : Inf s \u2264 a :=\nle_trans (cInf_le hs hb) h\n\ntheorem cSup_le_cSup (ht : bdd_above t) (hs : s.nonempty) (h : s \u2286 t) : Sup s \u2264 Sup t :=\ncSup_le hs (\u03bb a ha, le_cSup ht (h ha))\n\ntheorem cInf_le_cInf (ht : bdd_below t) (hs : s.nonempty) (h : s \u2286 t) : Inf t \u2264 Inf s :=\nle_cInf hs (\u03bb a ha, cInf_le ht (h ha))\n\ntheorem le_cSup_iff (h : bdd_above s) (hs : s.nonempty) :\n  a \u2264 Sup s \u2194 \u2200 b, b \u2208 upper_bounds s \u2192 a \u2264 b :=\n\u27e8\u03bb h b hb, le_trans h (cSup_le hs hb), \u03bb hb, hb _ (\u03bb x, le_cSup h)\u27e9\n\ntheorem cInf_le_iff (h : bdd_below s) (hs : s.nonempty) :\n  Inf s \u2264 a \u2194 \u2200 b \u2208 lower_bounds s, b \u2264 a :=\n\u27e8\u03bb h b hb, le_trans (le_cInf hs hb) h, \u03bb hb, hb _ (\u03bb x, cInf_le h)\u27e9\n\nlemma is_lub_cSup (ne : s.nonempty) (H : bdd_above s) : is_lub s (Sup s) :=\n\u27e8\u03bb x, le_cSup H, \u03bb x, cSup_le ne\u27e9\n\nlemma is_lub_csupr [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : bdd_above (range f)) :\n  is_lub (range f) (\u2a06 i, f i) :=\nis_lub_cSup (range_nonempty f) H\n\nlemma is_lub_csupr_set {f : \u03b2 \u2192 \u03b1} {s : set \u03b2} (H : bdd_above (f '' s)) (Hne : s.nonempty) :\n  is_lub (f '' s) (\u2a06 i : s, f i) :=\nby { rw \u2190 Sup_image', exact is_lub_cSup (Hne.image _) H }\n\nlemma is_glb_cInf (ne : s.nonempty) (H : bdd_below s) : is_glb s (Inf s) :=\n\u27e8\u03bb x, cInf_le H, \u03bb x, le_cInf ne\u27e9\n\nlemma is_glb_cinfi [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : bdd_below (range f)) :\n  is_glb (range f) (\u2a05 i, f i) :=\nis_glb_cInf (range_nonempty f) H\n\nlemma is_glb_cinfi_set {f : \u03b2 \u2192 \u03b1} {s : set \u03b2} (H : bdd_below (f '' s)) (Hne : s.nonempty) :\n  is_glb (f '' s) (\u2a05 i : s, f i) :=\n@is_lub_csupr_set \u03b1\u1d52\u1d48 _ _ _ _ H Hne\n\nlemma csupr_le_iff [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (hf : bdd_above (range f)) :\n  supr f \u2264 a \u2194 \u2200 i, f i \u2264 a :=\n(is_lub_le_iff $ is_lub_csupr hf).trans forall_range_iff\n\nlemma le_cinfi_iff [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (hf : bdd_below (range f)) :\n  a \u2264 infi f \u2194 \u2200 i, a \u2264 f i :=\n(le_is_glb_iff $ is_glb_cinfi hf).trans forall_range_iff\n\nlemma csupr_set_le_iff {\u03b9 : Type*} {s : set \u03b9} {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (hs : s.nonempty)\n  (hf : bdd_above (f '' s)) :\n  (\u2a06 i : s, f i) \u2264 a \u2194 \u2200 i \u2208 s, f i \u2264 a :=\n(is_lub_le_iff $ is_lub_csupr_set hf hs).trans ball_image_iff\n\nlemma le_cinfi_set_iff {\u03b9 : Type*} {s : set \u03b9} {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (hs : s.nonempty)\n  (hf : bdd_below (f '' s)) :\n  a \u2264 (\u2a05 i : s, f i) \u2194 \u2200 i \u2208 s, a \u2264 f i :=\n(le_is_glb_iff $ is_glb_cinfi_set hf hs).trans ball_image_iff\n\nlemma is_lub.cSup_eq (H : is_lub s a) (ne : s.nonempty) : Sup s = a :=\n(is_lub_cSup ne \u27e8a, H.1\u27e9).unique H\n\nlemma is_lub.csupr_eq [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : is_lub (range f) a) : (\u2a06 i, f i) = a :=\nH.cSup_eq (range_nonempty f)\n\nlemma is_lub.csupr_set_eq {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} (H : is_lub (f '' s) a) (Hne : s.nonempty) :\n  (\u2a06 i : s, f i) = a :=\nis_lub.cSup_eq (image_eq_range f s \u25b8 H) (image_eq_range f s \u25b8 Hne.image f)\n\n/-- A greatest element of a set is the supremum of this set. -/\nlemma is_greatest.cSup_eq (H : is_greatest s a) : Sup s = a :=\nH.is_lub.cSup_eq H.nonempty\n\nlemma is_greatest.Sup_mem (H : is_greatest s a) : Sup s \u2208 s :=\nH.cSup_eq.symm \u25b8 H.1\n\nlemma is_glb.cInf_eq (H : is_glb s a) (ne : s.nonempty) : Inf s = a :=\n(is_glb_cInf ne \u27e8a, H.1\u27e9).unique H\n\nlemma is_glb.cinfi_eq [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (H : is_glb (range f) a) : (\u2a05 i, f i) = a :=\nH.cInf_eq (range_nonempty f)\n\nlemma is_glb.cinfi_set_eq {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} (H : is_glb (f '' s) a) (Hne : s.nonempty) :\n  (\u2a05 i : s, f i) = a :=\nis_glb.cInf_eq (image_eq_range f s \u25b8 H) (image_eq_range f s \u25b8 Hne.image f)\n\n/-- A least element of a set is the infimum of this set. -/\nlemma is_least.cInf_eq (H : is_least s a) : Inf s = a :=\nH.is_glb.cInf_eq H.nonempty\n\nlemma is_least.Inf_mem (H : is_least s a) : Inf s \u2208 s :=\nH.cInf_eq.symm \u25b8 H.1\n\nlemma subset_Icc_cInf_cSup (hb : bdd_below s) (ha : bdd_above s) :\n  s \u2286 Icc (Inf s) (Sup s) :=\n\u03bb x hx, \u27e8cInf_le hb hx, le_cSup ha hx\u27e9\n\ntheorem cSup_le_iff (hb : bdd_above s) (hs : s.nonempty) : Sup s \u2264 a \u2194 \u2200 b \u2208 s, b \u2264 a :=\nis_lub_le_iff (is_lub_cSup hs hb)\n\ntheorem le_cInf_iff (hb : bdd_below s) (hs : s.nonempty) : a \u2264 Inf s \u2194 \u2200 b \u2208 s, a \u2264 b :=\nle_is_glb_iff (is_glb_cInf hs hb)\n\nlemma cSup_lower_bounds_eq_cInf {s : set \u03b1} (h : bdd_below s) (hs : s.nonempty) :\n  Sup (lower_bounds s) = Inf s :=\n(is_lub_cSup h $ hs.mono $ \u03bb x hx y hy, hy hx).unique (is_glb_cInf hs h).is_lub\n\nlemma cInf_upper_bounds_eq_cSup {s : set \u03b1} (h : bdd_above s) (hs : s.nonempty) :\n  Inf (upper_bounds s) = Sup s :=\n(is_glb_cInf h $ hs.mono $ \u03bb x hx y hy, hy hx).unique (is_lub_cSup hs h).is_glb\n\nlemma not_mem_of_lt_cInf {x : \u03b1} {s : set \u03b1} (h : x < Inf s) (hs : bdd_below s) : x \u2209 s :=\n\u03bb hx, lt_irrefl _ (h.trans_le (cInf_le hs hx))\n\nlemma not_mem_of_cSup_lt {x : \u03b1} {s : set \u03b1} (h : Sup s < x) (hs : bdd_above s) : x \u2209 s :=\n@not_mem_of_lt_cInf \u03b1\u1d52\u1d48 _ x s h hs\n\n/--Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b`\nis larger than all elements of `s`, and that this is not the case of any `w<b`.\nSee `Sup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/\ntheorem cSup_eq_of_forall_le_of_forall_lt_exists_gt (hs : s.nonempty)\n  (H : \u2200 a \u2208 s, a \u2264 b) (H' : \u2200 w, w < b \u2192 \u2203 a \u2208 s, w < a) : Sup s = b :=\neq_of_le_of_not_lt (cSup_le hs H) $ \u03bb hb, let \u27e8a, ha, ha'\u27e9 := H' _ hb in\n  lt_irrefl _ $ ha'.trans_le $ le_cSup \u27e8b, H\u27e9 ha\n\n/--Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b`\nis smaller than all elements of `s`, and that this is not the case of any `w>b`.\nSee `Inf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/\ntheorem cInf_eq_of_forall_ge_of_forall_gt_exists_lt : s.nonempty \u2192 (\u2200 a \u2208 s, b \u2264 a) \u2192\n  (\u2200 w, b < w \u2192 \u2203 a \u2208 s, a < w) \u2192 Inf s = b :=\n@cSup_eq_of_forall_le_of_forall_lt_exists_gt \u03b1\u1d52\u1d48 _ _ _\n\n/--b < Sup s when there is an element a in s with b < a, when s is bounded above.\nThis is essentially an iff, except that the assumptions for the two implications are\nslightly different (one needs boundedness above for one direction, nonemptiness and linear\norder for the other one), so we formulate separately the two implications, contrary to\nthe complete_lattice case.-/\nlemma lt_cSup_of_lt (hs : bdd_above s) (ha : a \u2208 s) (h : b < a) : b < Sup s :=\nlt_of_lt_of_le h (le_cSup hs ha)\n\n/--Inf s < b when there is an element a in s with a < b, when s is bounded below.\nThis is essentially an iff, except that the assumptions for the two implications are\nslightly different (one needs boundedness below for one direction, nonemptiness and linear\norder for the other one), so we formulate separately the two implications, contrary to\nthe complete_lattice case.-/\nlemma cInf_lt_of_lt : bdd_below s \u2192 a \u2208 s \u2192 a < b \u2192 Inf s < b :=\n@lt_cSup_of_lt \u03b1\u1d52\u1d48 _ _ _ _\n\n/-- If all elements of a nonempty set `s` are less than or equal to all elements\nof a nonempty set `t`, then there exists an element between these sets. -/\nlemma exists_between_of_forall_le (sne : s.nonempty) (tne : t.nonempty)\n  (hst : \u2200 (x \u2208 s) (y \u2208 t), x \u2264 y) : (upper_bounds s \u2229 lower_bounds t).nonempty :=\n\u27e8Inf t, \u03bb x hx, le_cInf tne $ hst x hx, \u03bb y hy, cInf_le (sne.mono hst) hy\u27e9\n\n/--The supremum of a singleton is the element of the singleton-/\n@[simp] theorem cSup_singleton (a : \u03b1) : Sup {a} = a :=\nis_greatest_singleton.cSup_eq\n\n/--The infimum of a singleton is the element of the singleton-/\n@[simp] theorem cInf_singleton (a : \u03b1) : Inf {a} = a :=\nis_least_singleton.cInf_eq\n\n@[simp] theorem cSup_pair (a b : \u03b1) : Sup {a, b} = a \u2294 b :=\n(@is_lub_pair _ _ a b).cSup_eq (nonempty_insert _ _)\n\n@[simp] theorem cInf_pair (a b : \u03b1) : Inf {a, b} = a \u2293 b :=\n(@is_glb_pair _ _ a b).cInf_eq (nonempty_insert _ _)\n\n/--If a set is bounded below and above, and nonempty, its infimum is less than or equal to\nits supremum.-/\ntheorem cInf_le_cSup (hb : bdd_below s) (ha : bdd_above s) (ne : s.nonempty) : Inf s \u2264 Sup s :=\nis_glb_le_is_lub (is_glb_cInf ne hb) (is_lub_cSup ne ha) ne\n\n/--The sup of a union of two sets is the max of the suprema of each subset, under the assumptions\nthat all sets are bounded above and nonempty.-/\ntheorem cSup_union (hs : bdd_above s) (sne : s.nonempty) (ht : bdd_above t) (tne : t.nonempty) :\n  Sup (s \u222a t) = Sup s \u2294 Sup t :=\n((is_lub_cSup sne hs).union (is_lub_cSup tne ht)).cSup_eq sne.inl\n\n/--The inf of a union of two sets is the min of the infima of each subset, under the assumptions\nthat all sets are bounded below and nonempty.-/\ntheorem cInf_union (hs : bdd_below s) (sne : s.nonempty) (ht : bdd_below t) (tne : t.nonempty) :\n  Inf (s \u222a t) = Inf s \u2293 Inf t :=\n@cSup_union \u03b1\u1d52\u1d48 _ _ _ hs sne ht tne\n\n/--The supremum of an intersection of two sets is bounded by the minimum of the suprema of each\nset, if all sets are bounded above and nonempty.-/\ntheorem cSup_inter_le (hs : bdd_above s) (ht : bdd_above t) (hst : (s \u2229 t).nonempty) :\n  Sup (s \u2229 t) \u2264 Sup s \u2293 Sup t :=\ncSup_le hst $ \u03bb x hx, le_inf (le_cSup hs hx.1) (le_cSup ht hx.2)\n\n/--The infimum of an intersection of two sets is bounded below by the maximum of the\ninfima of each set, if all sets are bounded below and nonempty.-/\ntheorem le_cInf_inter : bdd_below s \u2192 bdd_below t \u2192 (s \u2229 t).nonempty \u2192\n  Inf s \u2294 Inf t \u2264 Inf (s \u2229 t) :=\n@cSup_inter_le \u03b1\u1d52\u1d48 _ _ _\n\n/-- The supremum of insert a s is the maximum of a and the supremum of s, if s is\nnonempty and bounded above.-/\ntheorem cSup_insert (hs : bdd_above s) (sne : s.nonempty) : Sup (insert a s) = a \u2294 Sup s :=\n((is_lub_cSup sne hs).insert a).cSup_eq (insert_nonempty a s)\n\n/-- The infimum of insert a s is the minimum of a and the infimum of s, if s is\nnonempty and bounded below.-/\ntheorem cInf_insert (hs : bdd_below s) (sne : s.nonempty) : Inf (insert a s) = a \u2293 Inf s :=\n@cSup_insert \u03b1\u1d52\u1d48 _ _ _ hs sne\n\n@[simp] lemma cInf_Icc (h : a \u2264 b) : Inf (Icc a b) = a :=\n(is_glb_Icc h).cInf_eq (nonempty_Icc.2 h)\n\n@[simp] lemma cInf_Ici : Inf (Ici a) = a := is_least_Ici.cInf_eq\n\n@[simp] lemma cInf_Ico (h : a < b) : Inf (Ico a b) = a :=\n(is_glb_Ico h).cInf_eq (nonempty_Ico.2 h)\n\n@[simp] lemma cInf_Ioc [densely_ordered \u03b1] (h : a < b) : Inf (Ioc a b) = a :=\n(is_glb_Ioc h).cInf_eq (nonempty_Ioc.2 h)\n\n@[simp] lemma cInf_Ioi [no_max_order \u03b1] [densely_ordered \u03b1] : Inf (Ioi a) = a :=\ncInf_eq_of_forall_ge_of_forall_gt_exists_lt nonempty_Ioi (\u03bb _, le_of_lt)\n  (\u03bb w hw, by simpa using exists_between hw)\n\n@[simp] lemma cInf_Ioo [densely_ordered \u03b1] (h : a < b) : Inf (Ioo a b) = a :=\n(is_glb_Ioo h).cInf_eq (nonempty_Ioo.2 h)\n\n@[simp] lemma cSup_Icc (h : a \u2264 b) : Sup (Icc a b) = b :=\n(is_lub_Icc h).cSup_eq (nonempty_Icc.2 h)\n\n@[simp] lemma cSup_Ico [densely_ordered \u03b1] (h : a < b) : Sup (Ico a b) = b :=\n(is_lub_Ico h).cSup_eq (nonempty_Ico.2 h)\n\n@[simp] lemma cSup_Iic : Sup (Iic a) = a := is_greatest_Iic.cSup_eq\n\n@[simp] lemma cSup_Iio [no_min_order \u03b1] [densely_ordered \u03b1] : Sup (Iio a) = a :=\ncSup_eq_of_forall_le_of_forall_lt_exists_gt nonempty_Iio (\u03bb _, le_of_lt)\n  (\u03bb w hw, by simpa [and_comm] using exists_between hw)\n\n@[simp] lemma cSup_Ioc (h : a < b) : Sup (Ioc a b) = b :=\n(is_lub_Ioc h).cSup_eq (nonempty_Ioc.2 h)\n\n@[simp] lemma cSup_Ioo [densely_ordered \u03b1] (h : a < b) : Sup (Ioo a b) = b :=\n(is_lub_Ioo h).cSup_eq (nonempty_Ioo.2 h)\n\n/--The indexed supremum of a function is bounded above by a uniform bound-/\nlemma csupr_le [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} {c : \u03b1} (H : \u2200 x, f x \u2264 c) : supr f \u2264 c :=\ncSup_le (range_nonempty f) (by rwa forall_range_iff)\n\n/--The indexed supremum of a function is bounded below by the value taken at one point-/\nlemma le_csupr {f : \u03b9 \u2192 \u03b1} (H : bdd_above (range f)) (c : \u03b9) : f c \u2264 supr f :=\nle_cSup H (mem_range_self _)\n\nlemma le_csupr_of_le {f : \u03b9 \u2192 \u03b1} (H : bdd_above (range f)) (c : \u03b9) (h : a \u2264 f c) : a \u2264 supr f :=\nle_trans h (le_csupr H c)\n\n/--The indexed supremum of two functions are comparable if the functions are pointwise comparable-/\nlemma csupr_mono {f g : \u03b9 \u2192 \u03b1} (B : bdd_above (range g)) (H : \u2200 x, f x \u2264 g x) :\n  supr f \u2264 supr g :=\nbegin\n  casesI is_empty_or_nonempty \u03b9,\n  { rw [supr_of_empty', supr_of_empty'] },\n  { exact csupr_le (\u03bb x, le_csupr_of_le B x (H x)) },\nend\n\nlemma le_csupr_set {f : \u03b2 \u2192 \u03b1} {s : set \u03b2}\n  (H : bdd_above (f '' s)) {c : \u03b2} (hc : c \u2208 s) : f c \u2264 \u2a06 i : s, f i :=\n(le_cSup H $ mem_image_of_mem f hc).trans_eq Sup_image'\n\n/--The indexed infimum of two functions are comparable if the functions are pointwise comparable-/\nlemma cinfi_mono {f g : \u03b9 \u2192 \u03b1} (B : bdd_below (range f)) (H : \u2200 x, f x \u2264 g x) :\n  infi f \u2264 infi g :=\n@csupr_mono \u03b1\u1d52\u1d48 _ _ _ _ B H\n\n/--The indexed minimum of a function is bounded below by a uniform lower bound-/\nlemma le_cinfi [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} {c : \u03b1} (H : \u2200 x, c \u2264 f x) : c \u2264 infi f :=\n@csupr_le \u03b1\u1d52\u1d48 _ _ _ _ _ H\n\n/--The indexed infimum of a function is bounded above by the value taken at one point-/\nlemma cinfi_le {f : \u03b9 \u2192 \u03b1} (H : bdd_below (range f)) (c : \u03b9) : infi f \u2264 f c :=\n@le_csupr \u03b1\u1d52\u1d48 _ _ _ H c\n\nlemma cinfi_le_of_le {f : \u03b9 \u2192 \u03b1} (H : bdd_below (range f)) (c : \u03b9) (h : f c \u2264 a) : infi f \u2264 a :=\n@le_csupr_of_le \u03b1\u1d52\u1d48 _ _ _ _ H c h\n\nlemma cinfi_set_le {f : \u03b2 \u2192 \u03b1} {s : set \u03b2}\n  (H : bdd_below (f '' s)) {c : \u03b2} (hc : c \u2208 s) : (\u2a05 i : s, f i) \u2264 f c :=\n@le_csupr_set \u03b1\u1d52\u1d48 _ _ _ _ H _ hc\n\n@[simp] theorem csupr_const [h\u03b9 : nonempty \u03b9] {a : \u03b1} : (\u2a06 b : \u03b9, a) = a :=\nby rw [supr, range_const, cSup_singleton]\n\n@[simp] theorem cinfi_const [h\u03b9 : nonempty \u03b9] {a : \u03b1} : (\u2a05 b:\u03b9, a) = a := @csupr_const \u03b1\u1d52\u1d48 _ _ _ _\n\n@[simp] theorem supr_unique [unique \u03b9] {s : \u03b9 \u2192 \u03b1} : (\u2a06 i, s i) = s default :=\nhave \u2200 i, s i = s default := \u03bb i, congr_arg s (unique.eq_default i),\nby simp only [this, csupr_const]\n\n@[simp] theorem infi_unique [unique \u03b9] {s : \u03b9 \u2192 \u03b1} : (\u2a05 i, s i) = s default :=\n@supr_unique \u03b1\u1d52\u1d48 _ _ _ _\n\n@[simp] lemma csupr_pos {p : Prop} {f : p \u2192 \u03b1} (hp : p) : (\u2a06 h : p, f h) = f hp :=\nby haveI := unique_prop hp; exact supr_unique\n\n@[simp] lemma cinfi_pos {p : Prop} {f : p \u2192 \u03b1} (hp : p) : (\u2a05 h : p, f h) = f hp :=\n@csupr_pos \u03b1\u1d52\u1d48 _ _ _ hp\n\nlemma csupr_set {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} : (\u2a06 x : s, f x) = Sup (f '' s) :=\nbegin\n  rw supr,\n  congr,\n  ext,\n  rw [mem_image, mem_range, set_coe.exists],\n  simp_rw [subtype.coe_mk, exists_prop],\nend\n\nlemma cinfi_set {s : set \u03b2} {f : \u03b2 \u2192 \u03b1} : (\u2a05 x : s, f x) = Inf (f '' s) := @csupr_set \u03b1\u1d52\u1d48 _ _ _ _\n\n/--Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b`\nis larger than `f i` for all `i`, and that this is not the case of any `w<b`.\nSee `supr_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/\ntheorem csupr_eq_of_forall_le_of_forall_lt_exists_gt [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h\u2081 : \u2200 i, f i \u2264 b)\n  (h\u2082 : \u2200 w, w < b \u2192 (\u2203 i, w < f i)) : (\u2a06 (i : \u03b9), f i) = b :=\ncSup_eq_of_forall_le_of_forall_lt_exists_gt (range_nonempty f) (forall_range_iff.mpr h\u2081)\n  (\u03bb w hw, exists_range_iff.mpr $ h\u2082 w hw)\n\n/--Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b`\nis smaller than `f i` for all `i`, and that this is not the case of any `w>b`.\nSee `infi_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/\ntheorem cinfi_eq_of_forall_ge_of_forall_gt_exists_lt [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h\u2081 : \u2200 i, b \u2264 f i)\n  (h\u2082 : \u2200 w, b < w \u2192 (\u2203 i, f i < w)) : (\u2a05 (i : \u03b9), f i) = b :=\n@csupr_eq_of_forall_le_of_forall_lt_exists_gt \u03b1\u1d52\u1d48 _ _ _ _ \u2039_\u203a \u2039_\u203a \u2039_\u203a\n\n/-- Nested intervals lemma: if `f` is a monotone sequence, `g` is an antitone sequence, and\n`f n \u2264 g n` for all `n`, then `\u2a06 n, f n` belongs to all the intervals `[f n, g n]`. -/\nlemma monotone.csupr_mem_Inter_Icc_of_antitone [semilattice_sup \u03b2]\n  {f g : \u03b2 \u2192 \u03b1} (hf : monotone f) (hg : antitone g) (h : f \u2264 g) :\n  (\u2a06 n, f n) \u2208 \u22c2 n, Icc (f n) (g n) :=\nbegin\n  refine mem_Inter.2 (\u03bb n, _),\n  haveI : nonempty \u03b2 := \u27e8n\u27e9,\n  have : \u2200 m, f m \u2264 g n := \u03bb m, hf.forall_le_of_antitone hg h m n,\n  exact \u27e8le_csupr \u27e8g $ n, forall_range_iff.2 this\u27e9 _, csupr_le this\u27e9\nend\n\n/-- Nested intervals lemma: if `[f n, g n]` is an antitone sequence of nonempty\nclosed intervals, then `\u2a06 n, f n` belongs to all the intervals `[f n, g n]`. -/\nlemma csupr_mem_Inter_Icc_of_antitone_Icc [semilattice_sup \u03b2]\n  {f g : \u03b2 \u2192 \u03b1} (h : antitone (\u03bb n, Icc (f n) (g n))) (h' : \u2200 n, f n \u2264 g n) :\n  (\u2a06 n, f n) \u2208 \u22c2 n, Icc (f n) (g n) :=\nmonotone.csupr_mem_Inter_Icc_of_antitone (\u03bb m n hmn, ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).1)\n  (\u03bb m n hmn, ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).2) h'\n\nlemma finset.nonempty.sup'_eq_cSup_image {s : finset \u03b2} (hs : s.nonempty) (f : \u03b2 \u2192 \u03b1) :\n  s.sup' hs f = Sup (f '' s) :=\neq_of_forall_ge_iff $ \u03bb a,\n  by simp [cSup_le_iff (s.finite_to_set.image f).bdd_above (hs.to_set.image f)]\n\nlemma finset.nonempty.sup'_id_eq_cSup {s : finset \u03b1} (hs : s.nonempty) :\n  s.sup' hs id = Sup s :=\nby rw [hs.sup'_eq_cSup_image, image_id]\n\n/--Introduction rule to prove that b is the supremum of s: it suffices to check that\n1) b is an upper bound\n2) every other upper bound b' satisfies b \u2264 b'.-/\ntheorem cSup_eq_of_is_forall_le_of_forall_le_imp_ge (hs : s.nonempty)\n  (h_is_ub : \u2200 a \u2208 s, a \u2264 b) (h_b_le_ub : \u2200ub, (\u2200 a \u2208 s, a \u2264 ub) \u2192 (b \u2264 ub)) : Sup s = b :=\n(cSup_le hs h_is_ub).antisymm (h_b_le_ub _ $ \u03bb a, le_cSup \u27e8b, h_is_ub\u27e9)\n\nend conditionally_complete_lattice\n\ninstance pi.conditionally_complete_lattice {\u03b9 : Type*} {\u03b1 : \u03a0 i : \u03b9, Type*}\n  [\u03a0 i, conditionally_complete_lattice (\u03b1 i)] :\n  conditionally_complete_lattice (\u03a0 i, \u03b1 i) :=\n{ le_cSup := \u03bb s f \u27e8g, hg\u27e9 hf i, le_cSup \u27e8g i, set.forall_range_iff.2 $ \u03bb \u27e8f', hf'\u27e9, hg hf' i\u27e9\n    \u27e8\u27e8f, hf\u27e9, rfl\u27e9,\n  cSup_le := \u03bb s f hs hf i, cSup_le (by haveI := hs.to_subtype; apply range_nonempty) $\n    \u03bb b \u27e8\u27e8g, hg\u27e9, hb\u27e9, hb \u25b8 hf hg i,\n  cInf_le := \u03bb s f \u27e8g, hg\u27e9 hf i, cInf_le \u27e8g i, set.forall_range_iff.2 $ \u03bb \u27e8f', hf'\u27e9, hg hf' i\u27e9\n    \u27e8\u27e8f, hf\u27e9, rfl\u27e9,\n  le_cInf := \u03bb s f hs hf i, le_cInf (by haveI := hs.to_subtype; apply range_nonempty) $\n    \u03bb b \u27e8\u27e8g, hg\u27e9, hb\u27e9, hb \u25b8 hf hg i,\n  .. pi.lattice, .. pi.has_Sup, .. pi.has_Inf }\n\nsection conditionally_complete_linear_order\nvariables [conditionally_complete_linear_order \u03b1] {s t : set \u03b1} {a b : \u03b1}\n\nlemma finset.nonempty.cSup_eq_max' {s : finset \u03b1} (h : s.nonempty) : Sup \u2191s = s.max' h :=\neq_of_forall_ge_iff $ \u03bb a, (cSup_le_iff s.bdd_above h.to_set).trans (s.max'_le_iff h).symm\n\nlemma finset.nonempty.cInf_eq_min' {s : finset \u03b1} (h : s.nonempty) : Inf \u2191s = s.min' h :=\n@finset.nonempty.cSup_eq_max' \u03b1\u1d52\u1d48 _ s h\n\nlemma finset.nonempty.cSup_mem {s : finset \u03b1} (h : s.nonempty) : Sup (s : set \u03b1) \u2208 s :=\nby { rw h.cSup_eq_max', exact s.max'_mem _ }\n\nlemma finset.nonempty.cInf_mem {s : finset \u03b1} (h : s.nonempty) : Inf (s : set \u03b1) \u2208 s :=\n@finset.nonempty.cSup_mem \u03b1\u1d52\u1d48 _ _ h\n\nlemma set.nonempty.cSup_mem (h : s.nonempty) (hs : s.finite) : Sup s \u2208 s :=\nby { lift s to finset \u03b1 using hs, exact finset.nonempty.cSup_mem h }\n\nlemma set.nonempty.cInf_mem (h : s.nonempty) (hs : s.finite) : Inf s \u2208 s :=\n@set.nonempty.cSup_mem \u03b1\u1d52\u1d48 _ _ h hs\n\nlemma set.finite.cSup_lt_iff (hs : s.finite) (h : s.nonempty) : Sup s < a \u2194 \u2200 x \u2208 s, x < a :=\n\u27e8\u03bb h x hx, (le_cSup hs.bdd_above hx).trans_lt h, \u03bb H, H _ $ h.cSup_mem hs\u27e9\n\nlemma set.finite.lt_cInf_iff (hs : s.finite) (h : s.nonempty) : a < Inf s \u2194 \u2200 x \u2208 s, a < x :=\n@set.finite.cSup_lt_iff \u03b1\u1d52\u1d48 _ _ _ hs h\n\n/-- When b < Sup s, there is an element a in s with b < a, if s is nonempty and the order is\na linear order. -/\nlemma exists_lt_of_lt_cSup (hs : s.nonempty) (hb : b < Sup s) : \u2203 a \u2208 s, b < a :=\nby { contrapose! hb, exact cSup_le hs hb }\n\n/--\nIndexed version of the above lemma `exists_lt_of_lt_cSup`.\nWhen `b < supr f`, there is an element `i` such that `b < f i`.\n-/\nlemma exists_lt_of_lt_csupr [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h : b < supr f) : \u2203 i, b < f i :=\nlet \u27e8_, \u27e8i, rfl\u27e9, h\u27e9 := exists_lt_of_lt_cSup (range_nonempty f) h in \u27e8i, h\u27e9\n\n/--When Inf s < b, there is an element a in s with a < b, if s is nonempty and the order is\na linear order.-/\nlemma exists_lt_of_cInf_lt (hs : s.nonempty) (hb : Inf s < b) : \u2203 a \u2208 s, a < b :=\n@exists_lt_of_lt_cSup \u03b1\u1d52\u1d48 _ _ _ hs hb\n\n/--\nIndexed version of the above lemma `exists_lt_of_cInf_lt`\nWhen `infi f < a`, there is an element `i` such that `f i < a`.\n-/\nlemma exists_lt_of_cinfi_lt [nonempty \u03b9] {f : \u03b9 \u2192 \u03b1} (h : infi f < a) : \u2203 i, f i < a :=\n@exists_lt_of_lt_csupr \u03b1\u1d52\u1d48 _ _ _ _ _ h\n\nopen function\nvariables [is_well_order \u03b1 (<)]\n\nlemma Inf_eq_argmin_on (hs : s.nonempty) : Inf s = argmin_on id (@is_well_order.wf \u03b1 (<) _) s hs :=\nis_least.cInf_eq \u27e8argmin_on_mem _ _ _ _, \u03bb a ha, argmin_on_le id _ _ ha\u27e9\n\nlemma is_least_Inf (hs : s.nonempty) : is_least s (Inf s) :=\nby { rw Inf_eq_argmin_on hs, exact \u27e8argmin_on_mem _ _ _ _, \u03bb a ha, argmin_on_le id _ _ ha\u27e9 }\n\nlemma le_cInf_iff' (hs : s.nonempty) : b \u2264 Inf s \u2194 b \u2208 lower_bounds s :=\nle_is_glb_iff (is_least_Inf hs).is_glb\n\nlemma Inf_mem (hs : s.nonempty) : Inf s \u2208 s := (is_least_Inf hs).1\n\nlemma monotone_on.map_Inf {\u03b2 : Type*} [conditionally_complete_lattice \u03b2] {f : \u03b1 \u2192 \u03b2}\n  (hf : monotone_on f s) (hs : s.nonempty) : f (Inf s) = Inf (f '' s) :=\n(hf.map_is_least (is_least_Inf hs)).cInf_eq.symm\n\nlemma monotone.map_Inf {\u03b2 : Type*} [conditionally_complete_lattice \u03b2] {f : \u03b1 \u2192 \u03b2} (hf : monotone f)\n  (hs : s.nonempty) : f (Inf s) = Inf (f '' s) :=\n(hf.map_is_least (is_least_Inf hs)).cInf_eq.symm\n\nend conditionally_complete_linear_order\n\n/-!\n### Lemmas about a conditionally complete linear order with bottom element\n\nIn this case we have `Sup \u2205 = \u22a5`, so we can drop some `nonempty`/`set.nonempty` assumptions.\n-/\n\nsection conditionally_complete_linear_order_bot\n\nvariables [conditionally_complete_linear_order_bot \u03b1]\n\n@[simp] lemma cSup_empty : (Sup \u2205 : \u03b1) = \u22a5 :=\nconditionally_complete_linear_order_bot.cSup_empty\n\n@[simp] lemma csupr_of_empty [is_empty \u03b9] (f : \u03b9 \u2192 \u03b1) : (\u2a06 i, f i) = \u22a5 :=\nby rw [supr_of_empty', cSup_empty]\n\n@[simp] lemma csupr_false (f : false \u2192 \u03b1) : (\u2a06 i, f i) = \u22a5 := csupr_of_empty f\n\n@[simp] lemma cInf_univ : Inf (univ : set \u03b1) = \u22a5 := is_least_univ.cInf_eq\n\nlemma is_lub_cSup' {s : set \u03b1} (hs : bdd_above s) : is_lub s (Sup s) :=\nbegin\n  rcases eq_empty_or_nonempty s with (rfl|hne),\n  { simp only [cSup_empty, is_lub_empty] },\n  { exact is_lub_cSup hne hs }\nend\n\nlemma cSup_le_iff' {s : set \u03b1} (hs : bdd_above s) {a : \u03b1} : Sup s \u2264 a \u2194 \u2200 x \u2208 s, x \u2264 a :=\nis_lub_le_iff (is_lub_cSup' hs)\n\nlemma cSup_le' {s : set \u03b1} {a : \u03b1} (h : a \u2208 upper_bounds s) : Sup s \u2264 a :=\n(cSup_le_iff' \u27e8a, h\u27e9).2 h\n\ntheorem le_cSup_iff' {s : set \u03b1} {a : \u03b1} (h : bdd_above s) :\n  a \u2264 Sup s \u2194 \u2200 b, b \u2208 upper_bounds s \u2192 a \u2264 b :=\n\u27e8\u03bb h b hb, le_trans h (cSup_le' hb), \u03bb hb, hb _ (\u03bb x, le_cSup h)\u27e9\n\nlemma le_csupr_iff' {s : \u03b9 \u2192 \u03b1} {a : \u03b1} (h : bdd_above (range s)) :\n  a \u2264 supr s \u2194 \u2200 b, (\u2200 i, s i \u2264 b) \u2192 a \u2264 b :=\nby simp [supr, h, le_cSup_iff', upper_bounds]\n\ntheorem le_cInf_iff'' {s : set \u03b1} {a : \u03b1} (ne : s.nonempty) :\n  a \u2264 Inf s \u2194 \u2200 (b : \u03b1), b \u2208 s \u2192 a \u2264 b :=\nle_cInf_iff \u27e8\u22a5, \u03bb a _, bot_le\u27e9 ne\n\ntheorem cInf_le' {s : set \u03b1} {a : \u03b1} (h : a \u2208 s) : Inf s \u2264 a :=\ncInf_le \u27e8\u22a5, \u03bb a _, bot_le\u27e9 h\n\nlemma exists_lt_of_lt_cSup' {s : set \u03b1} {a : \u03b1} (h : a < Sup s) : \u2203 b \u2208 s, a < b :=\nby { contrapose! h, exact cSup_le' h }\n\nlemma csupr_le_iff' {f : \u03b9 \u2192 \u03b1} (h : bdd_above (range f)) {a : \u03b1} :\n  (\u2a06 i, f i) \u2264 a \u2194 \u2200 i, f i \u2264 a :=\n(cSup_le_iff' h).trans forall_range_iff\n\nlemma csupr_le' {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (h : \u2200 i, f i \u2264 a) : (\u2a06 i, f i) \u2264 a :=\ncSup_le' $ forall_range_iff.2 h\n\nlemma exists_lt_of_lt_csupr' {f : \u03b9 \u2192 \u03b1} {a : \u03b1} (h : a < \u2a06 i, f i) : \u2203 i, a < f i :=\nby { contrapose! h, exact csupr_le' h }\n\nlemma csupr_mono' {\u03b9'} {f : \u03b9 \u2192 \u03b1} {g : \u03b9' \u2192 \u03b1} (hg : bdd_above (range g))\n  (h : \u2200 i, \u2203 i', f i \u2264 g i') : supr f \u2264 supr g :=\ncsupr_le' $ \u03bb i, exists.elim (h i) (le_csupr_of_le hg)\n\nlemma cInf_le_cInf' {s t : set \u03b1} (h\u2081 : t.nonempty) (h\u2082 : t \u2286 s) : Inf s \u2264 Inf t :=\ncInf_le_cInf (order_bot.bdd_below s) h\u2081 h\u2082\n\nend conditionally_complete_linear_order_bot\n\nnamespace with_top\nopen_locale classical\n\nvariables [conditionally_complete_linear_order_bot \u03b1]\n\n/-- The Sup of a non-empty set is its least upper bound for a conditionally\ncomplete lattice with a top. -/\nlemma is_lub_Sup' {\u03b2 : Type*} [conditionally_complete_lattice \u03b2]\n  {s : set (with_top \u03b2)} (hs : s.nonempty) : is_lub s (Sup s) :=\nbegin\n  split,\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { intros _ _, exact le_top },\n    { rintro (\u27e8\u27e9|a) ha,\n      { contradiction },\n      apply some_le_some.2,\n      exact le_cSup h_1 ha },\n    { intros _ _, exact le_top } },\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { rintro (\u27e8\u27e9|a) ha,\n      { exact le_rfl },\n      { exact false.elim (not_top_le_coe a (ha h)) } },\n    { rintro (\u27e8\u27e9|b) hb,\n      { exact le_top },\n      refine some_le_some.2 (cSup_le _ _),\n      { rcases hs with \u27e8\u27e8\u27e9|b, hb\u27e9,\n        { exact absurd hb h },\n        { exact \u27e8b, hb\u27e9 } },\n      { intros a ha, exact some_le_some.1 (hb ha) } },\n    { rintro (\u27e8\u27e9|b) hb,\n      { exact le_rfl },\n      { exfalso, apply h_1, use b, intros a ha, exact some_le_some.1 (hb ha) } } }\nend\n\nlemma is_lub_Sup (s : set (with_top \u03b1)) : is_lub s (Sup s) :=\nbegin\n  cases s.eq_empty_or_nonempty with hs hs,\n  { rw hs,\n    show is_lub \u2205 (ite _ _ _),\n    split_ifs,\n    { cases h },\n    { rw [preimage_empty, cSup_empty], exact is_lub_empty },\n    { exfalso, apply h_1, use \u22a5, rintro a \u27e8\u27e9 } },\n  exact is_lub_Sup' hs,\nend\n\n/-- The Inf of a bounded-below set is its greatest lower bound for a conditionally\ncomplete lattice with a top. -/\nlemma is_glb_Inf' {\u03b2 : Type*} [conditionally_complete_lattice \u03b2]\n  {s : set (with_top \u03b2)} (hs : bdd_below s) : is_glb s (Inf s) :=\nbegin\n  split,\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { intros a ha, exact top_le_iff.2 (set.mem_singleton_iff.1 (h ha)) },\n    { rintro (\u27e8\u27e9|a) ha,\n      { exact le_top },\n      refine some_le_some.2 (cInf_le _ ha),\n      rcases hs with \u27e8\u27e8\u27e9|b, hb\u27e9,\n      { exfalso,\n        apply h,\n        intros c hc,\n        rw [mem_singleton_iff, \u2190top_le_iff],\n        exact hb hc },\n      use b,\n      intros c hc,\n      exact some_le_some.1 (hb hc) } },\n  { show ite _ _ _ \u2208 _,\n    split_ifs,\n    { intros _ _, exact le_top },\n    { rintro (\u27e8\u27e9|a) ha,\n      { exfalso, apply h, intros b hb, exact set.mem_singleton_iff.2 (top_le_iff.1 (ha hb)) },\n      { refine some_le_some.2 (le_cInf _ _),\n        { classical, contrapose! h,\n          rintros (\u27e8\u27e9|a) ha,\n          { exact mem_singleton \u22a4 },\n          { exact (h \u27e8a, ha\u27e9).elim }},\n        { intros b hb,\n          rw \u2190some_le_some,\n          exact ha hb } } } }\nend\n\nlemma is_glb_Inf (s : set (with_top \u03b1)) : is_glb s (Inf s) :=\nbegin\n  by_cases hs : bdd_below s,\n  { exact is_glb_Inf' hs },\n  { exfalso, apply hs, use \u22a5, intros _ _, exact bot_le },\nend\n\nnoncomputable instance : complete_linear_order (with_top \u03b1) :=\n{ Sup := Sup, le_Sup := \u03bb s, (is_lub_Sup s).1, Sup_le := \u03bb s, (is_lub_Sup s).2,\n  Inf := Inf, le_Inf := \u03bb s, (is_glb_Inf s).2, Inf_le := \u03bb s, (is_glb_Inf s).1,\n  .. with_top.linear_order, ..with_top.lattice, ..with_top.order_top, ..with_top.order_bot }\n\nlemma coe_Sup {s : set \u03b1} (hb : bdd_above s) : (\u2191(Sup s) : with_top \u03b1) = \u2a06 a \u2208 s, \u2191a :=\nbegin\n  cases s.eq_empty_or_nonempty with hs hs,\n  { rw [hs, cSup_empty], simp only [set.mem_empty_eq, supr_bot, supr_false], refl },\n  apply le_antisymm,\n  { refine (coe_le_iff.2 $ \u03bb b hb, cSup_le hs $ \u03bb a has, coe_le_coe.1 $ hb \u25b8 _),\n    exact le_supr\u2082_of_le a has le_rfl },\n  { exact supr\u2082_le (\u03bb a ha, coe_le_coe.2 $ le_cSup hb ha) }\nend\n\nlemma coe_Inf {s : set \u03b1} (hs : s.nonempty) : (\u2191(Inf s) : with_top \u03b1) = \u2a05 a \u2208 s, \u2191a :=\nbegin\n  obtain \u27e8x, hx\u27e9 := hs,\n  have : (\u2a05 a \u2208 s, \u2191a : with_top \u03b1) \u2264 x := infi\u2082_le_of_le x hx le_rfl,\n  rcases le_coe_iff.1 this with \u27e8r, r_eq, hr\u27e9,\n  refine le_antisymm\n    (le_infi\u2082 $ \u03bb a ha, coe_le_coe.2 $ cInf_le (order_bot.bdd_below s) ha) _,\n  { rw r_eq,\n    apply coe_le_coe.2 (le_cInf \u27e8x, hx\u27e9 (\u03bb a has, coe_le_coe.1 _)),\n    rw \u2190r_eq,\n    exact infi\u2082_le_of_le a has le_rfl }\nend\n\nend with_top\n\nnamespace monotone\nvariables [preorder \u03b1] [conditionally_complete_lattice \u03b2] {f : \u03b1 \u2192 \u03b2} (h_mono : monotone f)\n\n/-! A monotone function into a conditionally complete lattice preserves the ordering properties of\n`Sup` and `Inf`. -/\n\nlemma le_cSup_image {s : set \u03b1} {c : \u03b1} (hcs : c \u2208 s) (h_bdd : bdd_above s) :\n  f c \u2264 Sup (f '' s) :=\nle_cSup (map_bdd_above h_mono h_bdd) (mem_image_of_mem f hcs)\n\nlemma cSup_image_le {s : set \u03b1} (hs : s.nonempty) {B : \u03b1} (hB: B \u2208 upper_bounds s) :\n  Sup (f '' s) \u2264 f B :=\ncSup_le (nonempty.image f hs) (h_mono.mem_upper_bounds_image hB)\n\nlemma cInf_image_le {s : set \u03b1} {c : \u03b1} (hcs : c \u2208 s) (h_bdd : bdd_below s) :\n  Inf (f '' s) \u2264 f c :=\n@le_cSup_image \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ (\u03bb x y hxy, h_mono hxy) _ _ hcs h_bdd\n\nlemma le_cInf_image {s : set \u03b1} (hs : s.nonempty) {B : \u03b1} (hB: B \u2208 lower_bounds s) :\n  f B \u2264 Inf (f '' s) :=\n@cSup_image_le \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ (\u03bb x y hxy, h_mono hxy) _ hs _ hB\n\nend monotone\n\nnamespace galois_connection\nvariables [conditionally_complete_lattice \u03b1] [conditionally_complete_lattice \u03b2] [nonempty \u03b9]\n  {l : \u03b1 \u2192 \u03b2} {u : \u03b2 \u2192 \u03b1}\n\nlemma l_cSup (gc : galois_connection l u) {s : set \u03b1} (hne : s.nonempty)\n  (hbdd : bdd_above s) :\n  l (Sup s) = \u2a06 x : s, l x :=\neq.symm $ is_lub.csupr_set_eq (gc.is_lub_l_image $ is_lub_cSup hne hbdd) hne\n\nlemma l_cSup' (gc : galois_connection l u) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_above s) :\n  l (Sup s) = Sup (l '' s) :=\nby rw [gc.l_cSup hne hbdd, csupr_set]\n\nlemma l_csupr (gc : galois_connection l u) {f : \u03b9 \u2192 \u03b1}\n  (hf : bdd_above (range f)) :\n  l (\u2a06 i, f i) = \u2a06 i, l (f i) :=\nby rw [supr, gc.l_cSup (range_nonempty _) hf, supr_range']\n\nlemma l_csupr_set (gc : galois_connection l u) {s : set \u03b3} {f : \u03b3 \u2192 \u03b1}\n  (hf : bdd_above (f '' s)) (hne : s.nonempty) :\n  l (\u2a06 i : s, f i) = \u2a06 i : s, l (f i) :=\nby { haveI := hne.to_subtype, rw image_eq_range at hf, exact gc.l_csupr hf }\n\nlemma u_cInf (gc : galois_connection l u) {s : set \u03b2} (hne : s.nonempty)\n  (hbdd : bdd_below s) :\n  u (Inf s) = \u2a05 x : s, u x :=\ngc.dual.l_cSup hne hbdd\n\nlemma u_cInf' (gc : galois_connection l u) {s : set \u03b2} (hne : s.nonempty) (hbdd : bdd_below s) :\n  u (Inf s) = Inf (u '' s) :=\ngc.dual.l_cSup' hne hbdd\n\nlemma u_cinfi (gc : galois_connection l u) {f : \u03b9 \u2192 \u03b2}\n  (hf : bdd_below (range f)) :\n  u (\u2a05 i, f i) = \u2a05 i, u (f i) :=\ngc.dual.l_csupr hf\n\nlemma u_cinfi_set (gc : galois_connection l u) {s : set \u03b3} {f : \u03b3 \u2192 \u03b2}\n  (hf : bdd_below (f '' s)) (hne : s.nonempty) :\n  u (\u2a05 i : s, f i) = \u2a05 i : s, u (f i) :=\ngc.dual.l_csupr_set hf hne\n\nend galois_connection\n\nnamespace order_iso\nvariables [conditionally_complete_lattice \u03b1] [conditionally_complete_lattice \u03b2] [nonempty \u03b9]\n\nlemma map_cSup (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_above s) :\n  e (Sup s) = \u2a06 x : s, e x :=\ne.to_galois_connection.l_cSup hne hbdd\n\nlemma map_cSup' (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_above s) :\n  e (Sup s) = Sup (e '' s) :=\ne.to_galois_connection.l_cSup' hne hbdd\n\nlemma map_csupr (e : \u03b1 \u2243o \u03b2) {f : \u03b9 \u2192 \u03b1} (hf : bdd_above (range f)) :\n  e (\u2a06 i, f i) = \u2a06 i, e (f i) :=\ne.to_galois_connection.l_csupr hf\n\nlemma map_csupr_set (e : \u03b1 \u2243o \u03b2) {s : set \u03b3} {f : \u03b3 \u2192 \u03b1}\n  (hf : bdd_above (f '' s)) (hne : s.nonempty) :\n  e (\u2a06 i : s, f i) = \u2a06 i : s, e (f i) :=\ne.to_galois_connection.l_csupr_set hf hne\n\nlemma map_cInf (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_below s) :\n  e (Inf s) = \u2a05 x : s, e x :=\ne.dual.map_cSup hne hbdd\n\nlemma map_cInf' (e : \u03b1 \u2243o \u03b2) {s : set \u03b1} (hne : s.nonempty) (hbdd : bdd_below s) :\n  e (Inf s) = Inf (e '' s) :=\ne.dual.map_cSup' hne hbdd\n\nlemma map_cinfi (e : \u03b1 \u2243o \u03b2) {f : \u03b9 \u2192 \u03b1} (hf : bdd_below (range f)) :\n  e (\u2a05 i, f i) = \u2a05 i, e (f i) :=\ne.dual.map_csupr hf\n\nlemma map_cinfi_set (e : \u03b1 \u2243o \u03b2) {s : set \u03b3} {f : \u03b3 \u2192 \u03b1}\n  (hf : bdd_below (f '' s)) (hne : s.nonempty) :\n  e (\u2a05 i : s, f i) = \u2a05 i : s, e (f i) :=\ne.dual.map_csupr_set hf hne\n\nend order_iso\n\n/-!\n### Supremum/infimum of `set.image2`\n\nA collection of lemmas showing what happens to the suprema/infima of `s` and `t` when mapped under\na binary function whose partial evaluations are lower/upper adjoints of Galois connections.\n-/\n\nsection\nvariables [conditionally_complete_lattice \u03b1] [conditionally_complete_lattice \u03b2]\n  [conditionally_complete_lattice \u03b3] {f : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {s : set \u03b1} {t : set \u03b2}\n\nvariables {l u : \u03b1 \u2192 \u03b2 \u2192 \u03b3} {l\u2081 u\u2081 : \u03b2 \u2192 \u03b3 \u2192 \u03b1} {l\u2082 u\u2082 : \u03b1 \u2192 \u03b3 \u2192 \u03b2}\n\nlemma cSup_image2_eq_cSup_cSup (h\u2081 : \u2200 b, galois_connection (swap l b) (u\u2081 b))\n  (h\u2082 : \u2200 a, galois_connection (l a) (u\u2082 a))\n  (hs\u2080 : s.nonempty) (hs\u2081 : bdd_above s) (ht\u2080 : t.nonempty) (ht\u2081 : bdd_above t) :\n  Sup (image2 l s t) = l (Sup s) (Sup t) :=\nbegin\n  refine eq_of_forall_ge_iff (\u03bb c, _),\n  rw [cSup_le_iff (hs\u2081.image2 (\u03bb _, (h\u2081 _).monotone_l) (\u03bb _, (h\u2082 _).monotone_l) ht\u2081)\n    (hs\u2080.image2 ht\u2080), forall_image2_iff, forall\u2082_swap, (h\u2082 _).le_iff_le, cSup_le_iff ht\u2081 ht\u2080],\n  simp_rw [\u2190(h\u2082 _).le_iff_le, (h\u2081 _).le_iff_le, cSup_le_iff hs\u2081 hs\u2080],\nend\n\nlemma cSup_image2_eq_cSup_cInf (h\u2081 : \u2200 b, galois_connection (swap l b) (u\u2081 b))\n  (h\u2082 : \u2200 a, galois_connection (l a \u2218 of_dual) (to_dual \u2218 u\u2082 a)) :\n  s.nonempty \u2192 bdd_above s \u2192 t.nonempty \u2192 bdd_below t \u2192 Sup (image2 l s t) = l (Sup s) (Inf t) :=\n@cSup_image2_eq_cSup_cSup _ \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ _ h\u2081 h\u2082\n\nlemma cSup_image2_eq_cInf_cSup (h\u2081 : \u2200 b, galois_connection (swap l b \u2218 of_dual) (to_dual \u2218 u\u2081 b))\n  (h\u2082 : \u2200 a, galois_connection (l a) (u\u2082 a)) :\n  s.nonempty \u2192 bdd_below s \u2192 t.nonempty \u2192 bdd_above t \u2192 Sup (image2 l s t) = l (Inf s) (Sup t) :=\n@cSup_image2_eq_cSup_cSup \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ _ _ _ h\u2081 h\u2082\n\nlemma cSup_image2_eq_cInf_cInf (h\u2081 : \u2200 b, galois_connection (swap l b \u2218 of_dual) (to_dual \u2218 u\u2081 b))\n  (h\u2082 : \u2200 a, galois_connection (l a \u2218 of_dual) (to_dual \u2218 u\u2082 a)) :\n  s.nonempty \u2192 bdd_below s \u2192 t.nonempty \u2192 bdd_below t \u2192 Sup (image2 l s t) = l (Inf s) (Inf t) :=\n@cSup_image2_eq_cSup_cSup \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ _ h\u2081 h\u2082\n\nlemma cInf_image2_eq_cInf_cInf (h\u2081 : \u2200 b, galois_connection (l\u2081 b) (swap u b))\n  (h\u2082 : \u2200 a, galois_connection (l\u2082 a) (u a)) :\n  s.nonempty \u2192 bdd_below s \u2192 t.nonempty \u2192 bdd_below t \u2192\n  Inf (image2 u s t) = u (Inf s) (Inf t) :=\n@cSup_image2_eq_cSup_cSup \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 \u03b3\u1d52\u1d48 _ _ _ _ _ _ l\u2081 l\u2082 (\u03bb _, (h\u2081 _).dual) (\u03bb _, (h\u2082 _).dual)\n\nlemma cInf_image2_eq_cInf_cSup (h\u2081 : \u2200 b, galois_connection (l\u2081 b) (swap u b))\n  (h\u2082 : \u2200 a, galois_connection (to_dual \u2218 l\u2082 a) (u a \u2218 of_dual)) :\n  s.nonempty \u2192 bdd_below s \u2192 t.nonempty \u2192 bdd_above t \u2192 Inf (image2 u s t) = u (Inf s) (Sup t) :=\n@cInf_image2_eq_cInf_cInf _ \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ _ h\u2081 h\u2082\n\nlemma cInf_image2_eq_cSup_cInf (h\u2081 : \u2200 b, galois_connection (to_dual \u2218 l\u2081 b) (swap u b \u2218 of_dual))\n  (h\u2082 : \u2200 a, galois_connection (l\u2082 a) (u a)) :\n  s.nonempty \u2192 bdd_above s \u2192 t.nonempty \u2192 bdd_below t \u2192 Inf (image2 u s t) = u (Sup s) (Inf t) :=\n@cInf_image2_eq_cInf_cInf \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ _ _ _ h\u2081 h\u2082\n\nlemma cInf_image2_eq_cSup_cSup (h\u2081 : \u2200 b, galois_connection (to_dual \u2218 l\u2081 b) (swap u b \u2218 of_dual))\n  (h\u2082 : \u2200 a, galois_connection (to_dual \u2218 l\u2082 a) (u a \u2218 of_dual)) :\n  s.nonempty \u2192  bdd_above s \u2192 t.nonempty \u2192 bdd_above t \u2192 Inf (image2 u s t) = u (Sup s) (Sup t) :=\n@cInf_image2_eq_cInf_cInf \u03b1\u1d52\u1d48 \u03b2\u1d52\u1d48 _ _ _ _ _ _ _ _ _ h\u2081 h\u2082\n\nend\n\n/-!\n### Relation between `Sup` / `Inf` and `finset.sup'` / `finset.inf'`\n\nLike the `Sup` of a `conditionally_complete_lattice`, `finset.sup'` also requires the set to be\nnon-empty. As a result, we can translate between the two.\n-/\n\nnamespace finset\n\nlemma sup'_eq_cSup_image [conditionally_complete_lattice \u03b2] (s : finset \u03b1) (H) (f : \u03b1 \u2192 \u03b2) :\n  s.sup' H f = Sup (f '' s) :=\nbegin\n  apply le_antisymm,\n  { refine (finset.sup'_le _ _ $ \u03bb a ha, _),\n    refine le_cSup \u27e8s.sup' H f, _\u27e9 \u27e8a, ha, rfl\u27e9,\n    rintros i \u27e8j, hj, rfl\u27e9,\n    exact finset.le_sup' _ hj },\n  { apply cSup_le ((coe_nonempty.mpr H).image _),\n    rintros _ \u27e8a, ha, rfl\u27e9,\n    exact finset.le_sup' _ ha, }\nend\n\nlemma inf'_eq_cInf_image [conditionally_complete_lattice \u03b2] (s : finset \u03b1) (H) (f : \u03b1 \u2192 \u03b2) :\n  s.inf' H f = Inf (f '' s) :=\n@sup'_eq_cSup_image _ \u03b2\u1d52\u1d48 _ _ _ _\n\nlemma sup'_id_eq_cSup [conditionally_complete_lattice \u03b1] (s : finset \u03b1) (H) :\n  s.sup' H id = Sup s :=\nby rw [sup'_eq_cSup_image s H, set.image_id]\n\nlemma inf'_id_eq_cInf [conditionally_complete_lattice \u03b1] (s : finset \u03b1) (H) :\n  s.inf' H id = Inf s :=\n@sup'_id_eq_cSup \u03b1\u1d52\u1d48 _ _ _\n\nend finset\n\nsection with_top_bot\n\n/-!\n### Complete lattice structure on `with_top (with_bot \u03b1)`\n\nIf `\u03b1` is a `conditionally_complete_lattice`, then we show that `with_top \u03b1` and `with_bot \u03b1`\nalso inherit the structure of conditionally complete lattices. Furthermore, we show\nthat `with_top (with_bot \u03b1)` naturally inherits the structure of a complete lattice. Note that\nfor \u03b1 a conditionally complete lattice, `Sup` and `Inf` both return junk values\nfor sets which are empty or unbounded. The extension of `Sup` to `with_top \u03b1` fixes\nthe unboundedness problem and the extension to `with_bot \u03b1` fixes the problem with\nthe empty set.\n\nThis result can be used to show that the extended reals [-\u221e, \u221e] are a complete lattice.\n-/\n\nopen_locale classical\n\n/-- Adding a top element to a conditionally complete lattice\ngives a conditionally complete lattice -/\nnoncomputable instance with_top.conditionally_complete_lattice\n  {\u03b1 : Type*} [conditionally_complete_lattice \u03b1] :\n  conditionally_complete_lattice (with_top \u03b1) :=\n{ le_cSup := \u03bb S a hS haS, (with_top.is_lub_Sup' \u27e8a, haS\u27e9).1 haS,\n  cSup_le := \u03bb S a hS haS, (with_top.is_lub_Sup' hS).2 haS,\n  cInf_le := \u03bb S a hS haS, (with_top.is_glb_Inf' hS).1 haS,\n  le_cInf := \u03bb S a hS haS, (with_top.is_glb_Inf' \u27e8a, haS\u27e9).2 haS,\n  ..with_top.lattice,\n  ..with_top.has_Sup,\n  ..with_top.has_Inf }\n\n/-- Adding a bottom element to a conditionally complete lattice\ngives a conditionally complete lattice -/\nnoncomputable instance with_bot.conditionally_complete_lattice\n  {\u03b1 : Type*} [conditionally_complete_lattice \u03b1] :\n  conditionally_complete_lattice (with_bot \u03b1) :=\n{ le_cSup := (@with_top.conditionally_complete_lattice \u03b1\u1d52\u1d48 _).cInf_le,\n  cSup_le := (@with_top.conditionally_complete_lattice \u03b1\u1d52\u1d48 _).le_cInf,\n  cInf_le := (@with_top.conditionally_complete_lattice \u03b1\u1d52\u1d48 _).le_cSup,\n  le_cInf := (@with_top.conditionally_complete_lattice \u03b1\u1d52\u1d48 _).cSup_le,\n  ..with_bot.lattice,\n  ..with_bot.has_Sup,\n  ..with_bot.has_Inf }\n\nnoncomputable instance with_top.with_bot.complete_lattice {\u03b1 : Type*}\n  [conditionally_complete_lattice \u03b1] : complete_lattice (with_top (with_bot \u03b1)) :=\n{ le_Sup := \u03bb S a haS, (with_top.is_lub_Sup' \u27e8a, haS\u27e9).1 haS,\n  Sup_le := \u03bb S a ha,\n    begin\n      cases S.eq_empty_or_nonempty with h,\n      { show ite _ _ _ \u2264 a,\n        split_ifs,\n        { rw h at h_1, cases h_1 },\n        { convert bot_le, convert with_bot.cSup_empty, rw h, refl },\n        { exfalso, apply h_2, use \u22a5, rw h, rintro b \u27e8\u27e9 } },\n      { refine (with_top.is_lub_Sup' h).2 ha }\n    end,\n  Inf_le := \u03bb S a haS,\n    show ite _ _ _ \u2264 a,\n    begin\n      split_ifs,\n      { cases a with a, exact le_rfl,\n        cases (h haS); tauto },\n      { cases a,\n        { exact le_top },\n        { apply with_top.some_le_some.2, refine cInf_le _ haS, use \u22a5, intros b hb, exact bot_le } }\n    end,\n  le_Inf := \u03bb S a haS, (with_top.is_glb_Inf' \u27e8a, haS\u27e9).2 haS,\n  ..with_top.has_Inf,\n  ..with_top.has_Sup,\n  ..with_top.bounded_order,\n  ..with_top.lattice }\n\nnoncomputable instance with_top.with_bot.complete_linear_order {\u03b1 : Type*}\n  [conditionally_complete_linear_order \u03b1] : complete_linear_order (with_top (with_bot \u03b1)) :=\n{ .. with_top.with_bot.complete_lattice,\n  .. with_top.linear_order }\n\nend with_top_bot\n\nsection group\n\nvariables {\u03b9' : Sort*} [nonempty \u03b9] [nonempty \u03b9'] [conditionally_complete_lattice \u03b1] [group \u03b1]\n\n@[to_additive]\nlemma le_mul_cinfi [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a : \u03b1} {g : \u03b1} {h : \u03b9 \u2192 \u03b1}\n  (H : \u2200 j, a \u2264 g * h j) : a \u2264 g * infi h :=\ninv_mul_le_iff_le_mul.mp $ le_cinfi $ \u03bb hi, inv_mul_le_iff_le_mul.mpr $ H _\n\n@[to_additive]\nlemma mul_csupr_le [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a : \u03b1} {g : \u03b1} {h : \u03b9 \u2192 \u03b1}\n  (H : \u2200 j, g * h j \u2264 a) : g * supr h \u2264 a :=\n@le_mul_cinfi \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ _ H\n\n@[to_additive]\nlemma le_cinfi_mul [covariant_class \u03b1 \u03b1 (function.swap (*)) (\u2264)] {a : \u03b1} {g : \u03b9 \u2192 \u03b1} {h : \u03b1}\n  (H : \u2200 i, a \u2264 g i * h) : a \u2264 infi g * h :=\nmul_inv_le_iff_le_mul.mp $ le_cinfi $ \u03bb gi, mul_inv_le_iff_le_mul.mpr $ H _\n\n@[to_additive]\nlemma csupr_mul_le [covariant_class \u03b1 \u03b1 (function.swap (*)) (\u2264)] {a : \u03b1} {g : \u03b9 \u2192 \u03b1} {h : \u03b1}\n  (H : \u2200 i, g i * h \u2264 a) : supr g * h \u2264 a :=\n@le_cinfi_mul \u03b1\u1d52\u1d48 _ _ _ _ _ _ _ _ H\n\n@[to_additive]\nlemma le_cinfi_mul_cinfi [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (function.swap (*)) (\u2264)]\n  {a : \u03b1} {g : \u03b9 \u2192 \u03b1} {h : \u03b9' \u2192 \u03b1} (H : \u2200 i j, a \u2264 g i * h j) : a \u2264 infi g * infi h :=\nle_cinfi_mul $ \u03bb i, le_mul_cinfi $ H _\n\n@[to_additive]\nlemma csupr_mul_csupr_le [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (function.swap (*)) (\u2264)]\n  {a : \u03b1} {g : \u03b9 \u2192 \u03b1} {h : \u03b9' \u2192 \u03b1} (H : \u2200 i j, g i * h j \u2264 a) : supr g * supr h \u2264 a :=\ncsupr_mul_le $ \u03bb i, mul_csupr_le $ H _\n\nend group\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/order/conditionally_complete_lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8221891218080991, "lm_q1q2_score": 0.7004663260722747}}
{"text": "import analysis.normed_space.basic\n\n/-!\n#  The typeclass `nnnorm_add_class \u03b1`\n\nIn this file, we introduce the typeclass `nnnorm_add_class \u03b1`.\n\nLet `\u03b1` be a type with a non-negative norm `\u2225_\u2225\u208a`, a zero `0`, an addition `+` and a negation `-`.\n\nThe typeclass `nnnorm_add_class \u03b1` requires to prove the identities:\n* the nnnorm of `0` is `0` : `\u22250\u2225\u208a = 0`;\n* the nnnorm of `-x` is equal to the nnnorm of `x`: `\u2225- x\u2225\u208a = \u2225x\u2225\u208a`;\n* the nnnorm of a sum is at most the sum of the nnnorms: `\u2225x + y\u2225\u208a \u2264 \u2225x\u2225\u208a + \u2225y\u2225\u208a`.\n-/\n\nopen_locale nnreal\n\nvariables (\u03b1 : Type*) [has_nnnorm \u03b1]\n\n/--  A typeclass for an additive monoid `\u03b1` with a nnnorm.\nIts fields `nnn_zero, nnn_neg, nnn_add_le` assert that\n* `\u22250\u2225\u208a = 0`;\n* `\u2225- x\u2225\u208a = \u2225x\u2225\u208a`;\n* `\u2225x + y\u2225\u208a \u2264 \u2225x\u2225\u208a + \u2225y\u2225\u208a`.\n\nThe class only assumes that `\u03b1` has `0, +, -`. -/\nclass nnnorm_add_class [has_zero \u03b1] [has_add \u03b1] [has_neg \u03b1] : Prop :=\n(nnn_zero   : \u2225(0 : \u03b1)\u2225\u208a = 0)\n(nnn_neg    : \u2200 \u2983x : \u03b1\u2984, \u2225- x\u2225\u208a = \u2225x\u2225\u208a)\n(nnn_add_le : \u2200 \u2983x y : \u03b1\u2984, \u2225x + y\u2225\u208a \u2264 \u2225x\u2225\u208a + \u2225y\u2225\u208a)\n\nnamespace nnnorm_add_class\nvariables {\u03b1}\n\nsection def_lemmas\nvariables [has_zero \u03b1] [has_add \u03b1] [has_neg \u03b1] [nnnorm_add_class \u03b1]\n\n@[simp] lemma nnnorm_zero : \u2225(0 : \u03b1)\u2225\u208a = 0 := nnn_zero\n\n@[simp] lemma nnnorm_neg (x : \u03b1) : \u2225- x\u2225\u208a = \u2225x\u2225\u208a :=\nby apply nnn_neg\n\nlemma nnnorm_add_le (x y : \u03b1) : \u2225x + y\u2225\u208a \u2264 \u2225x\u2225\u208a + \u2225y\u2225\u208a :=\nby apply nnn_add_le\n\nend def_lemmas\n\nvariables [add_group \u03b1] [nnnorm_add_class \u03b1]\n\nlemma nnnorm_sub (x y : \u03b1) : \u2225x - y\u2225\u208a = \u2225y - x\u2225\u208a :=\n(nnnorm_neg _).symm.trans (congr_arg _ (neg_sub _ _))\n\nlemma nnnorm_triangle (x y z : \u03b1) : \u2225x - z\u2225\u208a \u2264 \u2225x - y\u2225\u208a + \u2225y - z\u2225\u208a :=\n(le_of_eq (by simp only [sub_add_sub_cancel])).trans (nnnorm_add_le _ _)\n\nend nnnorm_add_class\n", "meta": {"author": "leanprover-community", "repo": "lean-liquid", "sha": "92f188bd17f34dbfefc92a83069577f708851aec", "save_path": "github-repos/lean/leanprover-community-lean-liquid", "path": "github-repos/lean/leanprover-community-lean-liquid/lean-liquid-92f188bd17f34dbfefc92a83069577f708851aec/src/Lbar/nnnorm_add_class.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.700390379320071}}
{"text": "/-\nCopyright (c) 2022 Jireh Loreaux. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jireh Loreaux\n-/\n\nimport algebra.algebra.basic\nimport linear_algebra.prod\nimport algebra.hom.non_unital_alg\n\n/-!\n# Unitization of a non-unital algebra\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGiven a non-unital `R`-algebra `A` (given via the type classes\n`[non_unital_ring A] [module R A] [smul_comm_class R A A] [is_scalar_tower R A A]`) we construct\nthe minimal unital `R`-algebra containing `A` as an ideal. This object `algebra.unitization R A` is\na type synonym for `R \u00d7 A` on which we place a different multiplicative structure, namely,\n`(r\u2081, a\u2081) * (r\u2082, a\u2082) = (r\u2081 * r\u2082, r\u2081 \u2022 a\u2082 + r\u2082 \u2022 a\u2081 + a\u2081 * a\u2082)` where the multiplicative identity\nis `(1, 0)`.\n\nNote, when `A` is a *unital* `R`-algebra, then `unitization R A` constructs a new multiplicative\nidentity different from the old one, and so in general `unitization R A` and `A` will not be\nisomorphic even in the unital case. This approach actually has nice functorial properties.\n\nThere is a natural coercion from `A` to `unitization R A` given by `\u03bb a, (0, a)`, the image\nof which is a proper ideal (TODO), and when `R` is a field this ideal is maximal. Moreover,\nthis ideal is always an essential ideal (it has nontrivial intersection with every other nontrivial\nideal).\n\nEvery non-unital algebra homomorphism from `A` into a *unital* `R`-algebra `B` has a unique\nextension to a (unital) algebra homomorphism from `unitization R A` to `B`.\n\n## Main definitions\n\n* `unitization R A`: the unitization of a non-unital `R`-algebra `A`.\n* `unitization.algebra`: the unitization of `A` as a (unital) `R`-algebra.\n* `unitization.coe_non_unital_alg_hom`: coercion as a non-unital algebra homomorphism.\n* `non_unital_alg_hom.to_alg_hom \u03c6`: the extension of a non-unital algebra homomorphism `\u03c6 : A \u2192 B`\n  into a unital `R`-algebra `B` to an algebra homomorphism `unitization R A \u2192\u2090[R] B`.\n\n## Main results\n\n* `non_unital_alg_hom.to_alg_hom_unique`: the extension is unique\n\n## TODO\n\n* prove the unitization operation is a functor between the appropriate categories\n* prove the image of the coercion is an essential ideal, maximal if scalars are a field.\n-/\n\n/-- The minimal unitization of a non-unital `R`-algebra `A`. This is just a type synonym for\n`R \u00d7 A`.-/\ndef unitization (R A : Type*) := R \u00d7 A\n\nnamespace unitization\n\nsection basic\n\nvariables {R A : Type*}\n\n/-- The canonical inclusion `R \u2192 unitization R A`. -/\ndef inl [has_zero A] (r : R) : unitization R A :=\n(r, 0)\n\n/-- The canonical inclusion `A \u2192 unitization R A`. -/\ninstance [has_zero R] : has_coe_t A (unitization R A) := { coe := \u03bb a, (0, a) }\n\n/-- The canonical projection `unitization R A \u2192 R`. -/\ndef fst (x : unitization R A) : R :=\nx.1\n\n/-- The canonical projection `unitization R A \u2192 A`. -/\ndef snd (x : unitization R A) : A :=\nx.2\n\n@[ext] lemma ext {x y : unitization R A} (h1 : x.fst = y.fst) (h2 : x.snd = y.snd) : x = y :=\nprod.ext h1 h2\n\nsection\nvariables (A)\n@[simp] lemma fst_inl [has_zero A] (r : R) : (inl r : unitization R A).fst = r := rfl\n@[simp] lemma snd_inl [has_zero A] (r : R) : (inl r : unitization R A).snd = 0 := rfl\nend\n\nsection\nvariables (R)\n@[simp] lemma fst_coe [has_zero R] (a : A) : (a : unitization R A).fst = 0 := rfl\n@[simp] lemma snd_coe [has_zero R] (a : A) : (a : unitization R A).snd = a := rfl\nend\n\nlemma inl_injective [has_zero A] : function.injective (inl : R \u2192 unitization R A) :=\nfunction.left_inverse.injective $ fst_inl _\n\nlemma coe_injective [has_zero R] : function.injective (coe : A \u2192 unitization R A) :=\nfunction.left_inverse.injective $ snd_coe _\n\nend basic\n\n/-! ### Structures inherited from `prod`\n\nAdditive operators and scalar multiplication operate elementwise. -/\n\nsection additive\n\nvariables {T : Type*} {S : Type*} {R : Type*} {A : Type*}\n\ninstance [inhabited R] [inhabited A] : inhabited (unitization R A) :=\nprod.inhabited\n\ninstance [has_zero R] [has_zero A] : has_zero (unitization R A) :=\nprod.has_zero\n\ninstance [has_add R] [has_add A] : has_add (unitization R A) :=\nprod.has_add\n\ninstance [has_neg R] [has_neg A] : has_neg (unitization R A) :=\nprod.has_neg\n\ninstance [add_semigroup R] [add_semigroup A] : add_semigroup (unitization R A) :=\nprod.add_semigroup\n\ninstance [add_zero_class R] [add_zero_class A] : add_zero_class (unitization R A) :=\nprod.add_zero_class\n\ninstance [add_monoid R] [add_monoid A] : add_monoid (unitization R A) :=\nprod.add_monoid\n\ninstance [add_group R] [add_group A] : add_group (unitization R A) :=\nprod.add_group\n\ninstance [add_comm_semigroup R] [add_comm_semigroup A] : add_comm_semigroup (unitization R A) :=\nprod.add_comm_semigroup\n\ninstance [add_comm_monoid R] [add_comm_monoid A] : add_comm_monoid (unitization R A) :=\nprod.add_comm_monoid\n\ninstance [add_comm_group R] [add_comm_group A] : add_comm_group (unitization R A) :=\nprod.add_comm_group\n\ninstance [has_smul S R] [has_smul S A] : has_smul S (unitization R A) :=\nprod.has_smul\n\ninstance [has_smul T R] [has_smul T A] [has_smul S R] [has_smul S A] [has_smul T S]\n  [is_scalar_tower T S R] [is_scalar_tower T S A] : is_scalar_tower T S (unitization R A) :=\nprod.is_scalar_tower\n\ninstance [has_smul T R] [has_smul T A] [has_smul S R] [has_smul S A]\n  [smul_comm_class T S R] [smul_comm_class T S A] : smul_comm_class T S (unitization R A) :=\nprod.smul_comm_class\n\ninstance [has_smul S R] [has_smul S A] [has_smul S\u1d50\u1d52\u1d56 R] [has_smul S\u1d50\u1d52\u1d56 A]\n  [is_central_scalar S R] [is_central_scalar S A] : is_central_scalar S (unitization R A) :=\nprod.is_central_scalar\n\ninstance [monoid S] [mul_action S R] [mul_action S A] : mul_action S (unitization R A) :=\nprod.mul_action\n\ninstance [monoid S] [add_monoid R] [add_monoid A]\n  [distrib_mul_action S R] [distrib_mul_action S A] : distrib_mul_action S (unitization R A) :=\nprod.distrib_mul_action\n\ninstance [semiring S] [add_comm_monoid R] [add_comm_monoid A]\n  [module S R] [module S A] : module S (unitization R A) :=\nprod.module\n\n@[simp] lemma fst_zero [has_zero R] [has_zero A] : (0 : unitization R A).fst = 0 := rfl\n@[simp] lemma snd_zero [has_zero R] [has_zero A] : (0 : unitization R A).snd = 0 := rfl\n\n@[simp] lemma fst_add [has_add R] [has_add A] (x\u2081 x\u2082 : unitization R A) :\n  (x\u2081 + x\u2082).fst = x\u2081.fst + x\u2082.fst := rfl\n@[simp] lemma snd_add [has_add R] [has_add A] (x\u2081 x\u2082 : unitization R A) :\n  (x\u2081 + x\u2082).snd = x\u2081.snd + x\u2082.snd := rfl\n\n@[simp] lemma fst_neg [has_neg R] [has_neg A] (x : unitization R A) : (-x).fst = -x.fst := rfl\n@[simp] lemma snd_neg [has_neg R] [has_neg A] (x : unitization R A) : (-x).snd = -x.snd := rfl\n\n@[simp] lemma fst_smul [has_smul S R] [has_smul S A] (s : S) (x : unitization R A) :\n  (s \u2022 x).fst = s \u2022 x.fst := rfl\n@[simp] lemma snd_smul [has_smul S R] [has_smul S A] (s : S) (x : unitization R A) :\n  (s \u2022 x).snd = s \u2022 x.snd := rfl\n\nsection\nvariables (A)\n\n@[simp] lemma inl_zero [has_zero R] [has_zero A] : (inl 0 : unitization R A) = 0 := rfl\n\n@[simp] lemma inl_add [has_add R] [add_zero_class A] (r\u2081 r\u2082 : R) :\n  (inl (r\u2081 + r\u2082) : unitization R A) = inl r\u2081 + inl r\u2082 :=\next rfl (add_zero 0).symm\n\n@[simp] lemma inl_neg [has_neg R] [add_group A] (r : R) :\n  (inl (-r) : unitization R A) = -inl r :=\next rfl neg_zero.symm\n\n@[simp] lemma inl_smul [monoid S] [add_monoid A] [has_smul S R] [distrib_mul_action S A]\n  (s : S) (r : R) : (inl (s \u2022 r) : unitization R A) = s \u2022 inl r :=\next rfl (smul_zero s).symm\n\nend\n\nsection\nvariables (R)\n\n@[simp] lemma coe_zero [has_zero R] [has_zero A] : \u2191(0 : A) = (0 : unitization R A) := rfl\n\n@[simp] lemma coe_add [add_zero_class R] [has_add A] (m\u2081 m\u2082 : A) :\n  (\u2191(m\u2081 + m\u2082) : unitization R A)  = m\u2081 + m\u2082 :=\next (add_zero 0).symm rfl\n\n@[simp] lemma coe_neg [add_group R] [has_neg A] (m : A) :\n  (\u2191(-m) : unitization R A) = -m :=\next neg_zero.symm rfl\n\n@[simp] lemma coe_smul [has_zero R] [has_zero S] [smul_with_zero S R] [has_smul S A]\n  (r : S) (m : A) : (\u2191(r \u2022 m) : unitization R A) = r \u2022 m :=\next (smul_zero _).symm rfl\n\nend\n\nlemma inl_fst_add_coe_snd_eq [add_zero_class R] [add_zero_class A] (x : unitization R A) :\n  inl x.fst + \u2191x.snd = x :=\next (add_zero x.1) (zero_add x.2)\n\n/-- To show a property hold on all `unitization R A` it suffices to show it holds\non terms of the form `inl r + a`.\n\nThis can be used as `induction x using unitization.ind`. -/\nlemma ind {R A} [add_zero_class R] [add_zero_class A] {P : unitization R A \u2192 Prop}\n  (h : \u2200 (r : R) (a : A), P (inl r + a)) (x) : P x :=\ninl_fst_add_coe_snd_eq x \u25b8 h x.1 x.2\n\n/-- This cannot be marked `@[ext]` as it ends up being used instead of `linear_map.prod_ext` when\nworking with `R \u00d7 A`. -/\nlemma linear_map_ext {N} [semiring S] [add_comm_monoid R] [add_comm_monoid A] [add_comm_monoid N]\n  [module S R] [module S A] [module S N] \u2983f g : unitization R A \u2192\u2097[S] N\u2984\n  (hl : \u2200 r, f (inl r) = g (inl r)) (hr : \u2200 a : A, f a = g a) :\n  f = g :=\nlinear_map.prod_ext (linear_map.ext hl) (linear_map.ext hr)\n\nvariables (R A)\n\n/-- The canonical `R`-linear inclusion `A \u2192 unitization R A`. -/\n@[simps apply]\ndef coe_hom [semiring R] [add_comm_monoid A] [module R A] : A \u2192\u2097[R] unitization R A :=\n{ to_fun := coe, ..linear_map.inr R R A }\n\n/-- The canonical `R`-linear projection `unitization R A \u2192 A`. -/\n@[simps apply]\ndef snd_hom [semiring R] [add_comm_monoid A] [module R A] : unitization R A \u2192\u2097[R] A :=\n{ to_fun := snd, ..linear_map.snd _ _ _ }\n\nend additive\n\n/-! ### Multiplicative structure -/\n\nsection mul\nvariables {R A : Type*}\n\ninstance [has_one R] [has_zero A] : has_one (unitization R A) :=\n\u27e8(1, 0)\u27e9\n\ninstance [has_mul R] [has_add A] [has_mul A] [has_smul R A] : has_mul (unitization R A) :=\n\u27e8\u03bb x y, (x.1 * y.1, x.1 \u2022 y.2 + y.1 \u2022 x.2 + x.2 * y.2)\u27e9\n\n@[simp] lemma fst_one [has_one R] [has_zero A] : (1 : unitization R A).fst = 1 := rfl\n@[simp] lemma snd_one [has_one R] [has_zero A] : (1 : unitization R A).snd = 0 := rfl\n\n@[simp] lemma fst_mul [has_mul R] [has_add A] [has_mul A] [has_smul R A]\n  (x\u2081 x\u2082 : unitization R A) : (x\u2081 * x\u2082).fst = x\u2081.fst * x\u2082.fst := rfl\n@[simp] lemma snd_mul [has_mul R] [has_add A] [has_mul A] [has_smul R A]\n  (x\u2081 x\u2082 : unitization R A) : (x\u2081 * x\u2082).snd = x\u2081.fst \u2022 x\u2082.snd + x\u2082.fst \u2022 x\u2081.snd + x\u2081.snd * x\u2082.snd :=\nrfl\n\nsection\nvariables (A)\n\n@[simp] lemma inl_one [has_one R] [has_zero A] : (inl 1 : unitization R A) = 1 := rfl\n\n@[simp] lemma inl_mul [monoid R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A]\n  (r\u2081 r\u2082 : R) : (inl (r\u2081 * r\u2082) : unitization R A) = inl r\u2081 * inl r\u2082 :=\next rfl $ show (0 : A) = r\u2081 \u2022 (0 : A) + r\u2082 \u2022 0 + 0 * 0, by simp only [smul_zero, add_zero, mul_zero]\n\nlemma inl_mul_inl [monoid R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A]\n  (r\u2081 r\u2082 : R) : (inl r\u2081 * inl r\u2082 : unitization R A) = inl (r\u2081 * r\u2082) :=\n(inl_mul A r\u2081 r\u2082).symm\n\nend\n\nsection\nvariables (R)\n\n@[simp] \n\nend\n\nlemma inl_mul_coe [semiring R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A]\n  (r : R) (a : A) : (inl r * a : unitization R A) = \u2191(r \u2022 a) :=\next (mul_zero r) $ show r \u2022 a + (0 : R) \u2022 0 + 0 * a = r \u2022 a,\n  by rw [smul_zero, add_zero, zero_mul, add_zero]\n\nlemma coe_mul_inl [semiring R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A]\n  (r : R) (a : A) : (a * inl r : unitization R A) = \u2191(r \u2022 a) :=\next (zero_mul r) $ show (0 : R) \u2022 0 + r \u2022 a + a * 0 = r \u2022 a,\n  by rw [smul_zero, zero_add, mul_zero, add_zero]\n\ninstance mul_one_class [monoid R] [non_unital_non_assoc_semiring A] [distrib_mul_action R A] :\n  mul_one_class (unitization R A) :=\n{ one_mul := \u03bb x, ext (one_mul x.1) $ show (1 : R) \u2022 x.2 + x.1 \u2022 0 + 0 * x.2 = x.2,\n    by rw [one_smul, smul_zero, add_zero, zero_mul, add_zero],\n  mul_one := \u03bb x, ext (mul_one x.1) $ show (x.1 \u2022 0 : A) + (1 : R) \u2022 x.2 + x.2 * 0 = x.2,\n    by rw [smul_zero, zero_add, one_smul, mul_zero, add_zero],\n  .. unitization.has_one,\n  .. unitization.has_mul }\n\ninstance [semiring R] [non_unital_non_assoc_semiring A] [module R A] :\n  non_assoc_semiring (unitization R A) :=\n{ zero_mul := \u03bb x, ext (zero_mul x.1) $ show (0 : R) \u2022 x.2 + x.1 \u2022 0 + 0 * x.2 = 0,\n    by rw [zero_smul, zero_add, smul_zero, zero_mul, add_zero],\n  mul_zero := \u03bb x, ext (mul_zero x.1) $ show (x.1 \u2022 0 : A) + (0 : R) \u2022 x.2 + x.2 * 0 = 0,\n    by rw [smul_zero, zero_add, zero_smul, mul_zero, add_zero],\n  left_distrib := \u03bb x\u2081 x\u2082 x\u2083, ext (mul_add x\u2081.1 x\u2082.1 x\u2083.1) $\n    show x\u2081.1 \u2022 (x\u2082.2 + x\u2083.2) + (x\u2082.1 + x\u2083.1) \u2022 x\u2081.2 + x\u2081.2 * (x\u2082.2 + x\u2083.2) =\n      x\u2081.1 \u2022 x\u2082.2 + x\u2082.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2082.2 + (x\u2081.1 \u2022 x\u2083.2 + x\u2083.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2083.2),\n    by { simp only [smul_add, add_smul, mul_add], abel },\n  right_distrib := \u03bb x\u2081 x\u2082 x\u2083, ext (add_mul x\u2081.1 x\u2082.1 x\u2083.1) $\n    show (x\u2081.1 + x\u2082.1) \u2022 x\u2083.2 + x\u2083.1 \u2022 (x\u2081.2 + x\u2082.2) + (x\u2081.2 + x\u2082.2) * x\u2083.2 =\n      x\u2081.1 \u2022 x\u2083.2 + x\u2083.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2083.2 + (x\u2082.1 \u2022 x\u2083.2 + x\u2083.1 \u2022 x\u2082.2 + x\u2082.2 * x\u2083.2),\n    by { simp only [add_smul, smul_add, add_mul], abel },\n  .. unitization.mul_one_class,\n  .. unitization.add_comm_monoid }\n\ninstance [comm_monoid R] [non_unital_semiring A] [distrib_mul_action R A] [is_scalar_tower R A A]\n  [smul_comm_class R A A] : monoid (unitization R A) :=\n{ mul_assoc := \u03bb x y z, ext (mul_assoc x.1 y.1 z.1) $\n    show (x.1 * y.1) \u2022 z.2 + z.1 \u2022 (x.1 \u2022 y.2 + y.1 \u2022 x.2 + x.2 * y.2) +\n      (x.1 \u2022 y.2 + y.1 \u2022 x.2 + x.2 * y.2) * z.2 =\n      x.1 \u2022 (y.1 \u2022 z.2 + z.1 \u2022 y.2 + y.2 * z.2) + (y.1 * z.1) \u2022 x.2 +\n      x.2 * (y.1 \u2022 z.2 + z.1 \u2022 y.2 + y.2 * z.2),\n    { simp only [smul_add, mul_add, add_mul, smul_smul, smul_mul_assoc, mul_smul_comm, mul_assoc],\n      nth_rewrite 1 mul_comm,\n      nth_rewrite 2 mul_comm,\n      abel },\n  ..unitization.mul_one_class }\n\ninstance [comm_monoid R] [non_unital_comm_semiring A] [distrib_mul_action R A]\n  [is_scalar_tower R A A] [smul_comm_class R A A] : comm_monoid (unitization R A) :=\n{ mul_comm := \u03bb x\u2081 x\u2082, ext (mul_comm x\u2081.1 x\u2082.1) $\n    show x\u2081.1 \u2022 x\u2082.2 + x\u2082.1 \u2022 x\u2081.2 + x\u2081.2 * x\u2082.2 = x\u2082.1 \u2022 x\u2081.2 + x\u2081.1 \u2022 x\u2082.2 + x\u2082.2 * x\u2081.2,\n    by rw [add_comm (x\u2081.1 \u2022 x\u2082.2), mul_comm],\n  ..unitization.monoid }\n\ninstance [comm_semiring R] [non_unital_semiring A] [module R A] [is_scalar_tower R A A]\n  [smul_comm_class R A A] : semiring (unitization R A) :=\n{ ..unitization.monoid,\n  ..unitization.non_assoc_semiring }\n\ninstance [comm_semiring R] [non_unital_comm_semiring A] [module R A] [is_scalar_tower R A A]\n  [smul_comm_class R A A] : comm_semiring (unitization R A) :=\n{ ..unitization.comm_monoid,\n  ..unitization.non_assoc_semiring }\n\nvariables (R A)\n\n/-- The canonical inclusion of rings `R \u2192+* unitization R A`. -/\n@[simps apply]\ndef inl_ring_hom [semiring R] [non_unital_semiring A] [module R A] : R \u2192+* unitization R A :=\n{ to_fun := inl,\n  map_one' := inl_one A,\n  map_mul' := inl_mul A,\n  map_zero' := inl_zero A,\n  map_add' := inl_add A }\n\nend mul\n\n/-! ### Star structure -/\n\nsection star\n\nvariables {R A : Type*}\n\ninstance [has_star R] [has_star A] : has_star (unitization R A) :=\n\u27e8\u03bb ra, (star ra.fst, star ra.snd)\u27e9\n\n@[simp] lemma fst_star [has_star R] [has_star A] (x : unitization R A) :\n  (star x).fst = star x.fst := rfl\n\n@[simp] lemma snd_star [has_star R] [has_star A] (x : unitization R A) :\n  (star x).snd = star x.snd := rfl\n\n@[simp] lemma inl_star [has_star R] [add_monoid A] [star_add_monoid A] (r : R) :\n  inl (star r) = star (inl r : unitization R A) :=\next rfl (by simp only [snd_star, star_zero, snd_inl])\n\n@[simp] lemma coe_star [add_monoid R] [star_add_monoid R] [has_star A] (a : A) :\n  \u2191(star a) = star (a : unitization R A) :=\next (by simp only [fst_star, star_zero, fst_coe]) rfl\n\ninstance [add_monoid R] [add_monoid A] [star_add_monoid R] [star_add_monoid A] :\n  star_add_monoid (unitization R A) :=\n{ star_involutive := \u03bb x, ext (star_star x.fst) (star_star x.snd),\n  star_add := \u03bb x y, ext (star_add x.fst y.fst) (star_add x.snd y.snd) }\n\ninstance [comm_semiring R] [star_ring R] [add_comm_monoid A] [star_add_monoid A]\n  [module R A] [star_module R A] : star_module R (unitization R A) :=\n{ star_smul := \u03bb r x, ext (by simp) (by simp) }\n\ninstance [comm_semiring R] [star_ring R] [non_unital_semiring A] [star_ring A]\n  [module R A] [is_scalar_tower R A A] [smul_comm_class R A A] [star_module R A] :\n  star_ring (unitization R A) :=\n{ star_mul := \u03bb x y, ext (by simp [star_mul])\n    (by simp [star_mul, add_comm (star x.fst \u2022 star y.snd)]),\n  ..unitization.star_add_monoid }\n\nend star\n\n/-! ### Algebra structure -/\n\nsection algebra\nvariables (S R A : Type*)\n[comm_semiring S] [comm_semiring R] [non_unital_semiring A]\n[module R A] [is_scalar_tower R A A] [smul_comm_class R A A]\n[algebra S R] [distrib_mul_action S A] [is_scalar_tower S R A]\n\ninstance algebra : algebra S (unitization R A) :=\n{ commutes' := \u03bb r x,\n  begin\n    induction x using unitization.ind,\n    simp only [mul_add, add_mul, ring_hom.to_fun_eq_coe, ring_hom.coe_comp, function.comp_app,\n      inl_ring_hom_apply, inl_mul_inl],\n    rw [inl_mul_coe, coe_mul_inl, mul_comm]\n  end,\n  smul_def' := \u03bb s x,\n  begin\n    induction x using unitization.ind,\n    simp only [mul_add, smul_add, ring_hom.to_fun_eq_coe, ring_hom.coe_comp, function.comp_app,\n      inl_ring_hom_apply, algebra.algebra_map_eq_smul_one],\n    rw [inl_mul_inl, inl_mul_coe, smul_one_mul, inl_smul, coe_smul, smul_one_smul]\n  end,\n  ..(unitization.inl_ring_hom R A).comp (algebra_map S R) }\n\nlemma algebra_map_eq_inl_comp : \u21d1(algebra_map S (unitization R A)) = inl \u2218 algebra_map S R := rfl\nlemma algebra_map_eq_inl_ring_hom_comp :\n  algebra_map S (unitization R A) = (inl_ring_hom R A).comp (algebra_map S R) := rfl\nlemma algebra_map_eq_inl : \u21d1(algebra_map R (unitization R A)) = inl := rfl\nlemma algebra_map_eq_inl_hom : algebra_map R (unitization R A) = inl_ring_hom R A := rfl\n\n/-- The canonical `R`-algebra projection `unitization R A \u2192 R`. -/\n@[simps]\ndef fst_hom : unitization R A \u2192\u2090[R] R :=\n{ to_fun := fst,\n  map_one' := fst_one,\n  map_mul' := fst_mul,\n  map_zero' := fst_zero,\n  map_add' := fst_add,\n  commutes' := fst_inl A }\n\nend algebra\n\nsection coe\n\n/-- The coercion from a non-unital `R`-algebra `A` to its unitization `unitization R A`\nrealized as a non-unital algebra homomorphism. -/\n@[simps]\ndef coe_non_unital_alg_hom (R A : Type*) [comm_semiring R] [non_unital_semiring A] [module R A] :\n  A \u2192\u2099\u2090[R] unitization R A :=\n{ to_fun := coe,\n  map_smul' := coe_smul R,\n  map_zero' := coe_zero R,\n  map_add' := coe_add R,\n  map_mul' := coe_mul R }\n\nend coe\n\nsection alg_hom\n\nvariables {S R A : Type*}\n  [comm_semiring S] [comm_semiring R] [non_unital_semiring A]\n  [module R A] [smul_comm_class R A A] [is_scalar_tower R A A]\n  {B : Type*} [semiring B] [algebra S B]\n  [algebra S R] [distrib_mul_action S A] [is_scalar_tower S R A]\n  {C : Type*} [ring C] [algebra R C]\n\nlemma alg_hom_ext {\u03c6 \u03c8 : unitization R A \u2192\u2090[S] B} (h : \u2200 a : A, \u03c6 a = \u03c8 a)\n  (h' : \u2200 r, \u03c6 (algebra_map R (unitization R A) r) = \u03c8 (algebra_map R (unitization R A) r)) :\n  \u03c6 = \u03c8 :=\nbegin\n  ext,\n  induction x using unitization.ind,\n  simp only [map_add, \u2190algebra_map_eq_inl, h, h'],\nend\n\n/-- See note [partially-applied ext lemmas] -/\n@[ext]\nlemma alg_hom_ext' {\u03c6 \u03c8 : unitization R A \u2192\u2090[R] C}\n  (h : \u03c6.to_non_unital_alg_hom.comp (coe_non_unital_alg_hom R A) =\n    \u03c8.to_non_unital_alg_hom.comp (coe_non_unital_alg_hom R A)) :\n  \u03c6 = \u03c8 :=\nalg_hom_ext (non_unital_alg_hom.congr_fun h) (by simp [alg_hom.commutes])\n\n/-- Non-unital algebra homomorphisms from `A` into a unital `R`-algebra `C` lift uniquely to\n`unitization R A \u2192\u2090[R] C`. This is the universal property of the unitization. -/\n@[simps apply_apply]\ndef lift : (A \u2192\u2099\u2090[R] C) \u2243 (unitization R A \u2192\u2090[R] C) :=\n{ to_fun := \u03bb \u03c6,\n  { to_fun := \u03bb x, algebra_map R C x.fst + \u03c6 x.snd,\n    map_one' := by simp only [fst_one, map_one, snd_one, \u03c6.map_zero, add_zero],\n    map_mul' := \u03bb x y,\n    begin\n      induction x using unitization.ind,\n      induction y using unitization.ind,\n      simp only [mul_add, add_mul, coe_mul, fst_add, fst_mul, fst_inl, fst_coe, mul_zero,\n        add_zero, zero_mul, map_mul, snd_add, snd_mul, snd_inl, smul_zero, snd_coe, zero_add,\n        \u03c6.map_add, \u03c6.map_smul, \u03c6.map_mul, zero_smul, zero_add],\n      rw \u2190algebra.commutes _ (\u03c6 x_a),\n      simp only [algebra.algebra_map_eq_smul_one, smul_one_mul, add_assoc],\n    end,\n    map_zero' := by simp only [fst_zero, map_zero, snd_zero, \u03c6.map_zero, add_zero],\n    map_add' := \u03bb x y,\n    begin\n      induction x using unitization.ind,\n      induction y using unitization.ind,\n      simp only [fst_add, fst_inl, fst_coe, add_zero, map_add, snd_add, snd_inl, snd_coe, zero_add,\n        \u03c6.map_add],\n      rw add_add_add_comm,\n    end,\n    commutes' := \u03bb r, by simp only [algebra_map_eq_inl, fst_inl, snd_inl, \u03c6.map_zero, add_zero] },\n  inv_fun := \u03bb \u03c6, \u03c6.to_non_unital_alg_hom.comp (coe_non_unital_alg_hom R A),\n  left_inv := \u03bb \u03c6, by { ext, simp, },\n  right_inv := \u03bb \u03c6, unitization.alg_hom_ext' (by { ext, simp }), }\n\nlemma lift_symm_apply (\u03c6 : unitization R A \u2192\u2090[R] C) (a : A) :\n  unitization.lift.symm \u03c6 a = \u03c6 a := rfl\n\nend alg_hom\n\nend unitization\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/algebra/unitization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.700390379320071}}
{"text": "/-\nCopyright (c) 2021 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa\n-/\nimport algebra.group.defs\nimport logic.embedding.basic\n\n/-!\n# The embedding of a cancellative semigroup into itself by multiplication by a fixed element.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {R : Type*}\n\nsection left_or_right_cancel_semigroup\n\n/--\nThe embedding of a left cancellative semigroup into itself\nby left multiplication by a fixed element.\n -/\n@[to_additive\n  \"The embedding of a left cancellative additive semigroup into itself\n   by left translation by a fixed element.\", simps]\ndef mul_left_embedding {G : Type*} [left_cancel_semigroup G] (g : G) : G \u21aa G :=\n{ to_fun := \u03bb h, g * h, inj' := mul_right_injective g }\n\n/--\nThe embedding of a right cancellative semigroup into itself\nby right multiplication by a fixed element.\n -/\n@[to_additive\n  \"The embedding of a right cancellative additive semigroup into itself\n   by right translation by a fixed element.\", simps]\ndef mul_right_embedding {G : Type*} [right_cancel_semigroup G] (g : G) : G \u21aa G :=\n{ to_fun := \u03bb h, h * g, inj' := mul_left_injective g }\n\n@[to_additive]\nlemma mul_left_embedding_eq_mul_right_embedding {G : Type*} [cancel_comm_monoid G] (g : G) :\n  mul_left_embedding g = mul_right_embedding g :=\nby { ext, exact mul_comm _ _ }\n\nend left_or_right_cancel_semigroup\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/algebra/hom/embedding.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.7003903728515265}}
{"text": "/-\nCopyright (c) 2022 Ya\u00ebl Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ya\u00ebl Dillies\n\n! This file was ported from Lean 3 source module topology.order.priestley\n! leanprover-community/mathlib commit 4c19a16e4b705bf135cf9a80ac18fcc99c438514\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.UpperLower.Basic\nimport Mathlib.Topology.Separation\n\n/-!\n# Priestley spaces\n\nThis file defines Priestley spaces. A Priestley space is an ordered compact topological space such\nthat any two distinct points can be separated by a clopen upper set.\n\n## Main declarations\n\n* `PriestleySpace`: Prop-valued mixin stating the Priestley separation axiom: Any two distinct\n  points can be separated by a clopen upper set.\n\n## Implementation notes\n\nWe do not include compactness in the definition, so a Priestley space is to be declared as follows:\n`[Preorder \u03b1] [TopologicalSpace \u03b1] [CompactSpace \u03b1] [PriestleySpace \u03b1]`\n\n## References\n\n* [Wikipedia, *Priestley space*](https://en.wikipedia.org/wiki/Priestley_space)\n* [Davey, Priestley *Introduction to Lattices and Order*][davey_priestley]\n-/\n\n\nopen Set\n\nvariable {\u03b1 : Type _}\n\n/-- A Priestley space is an ordered topological space such that any two distinct points can be\nseparated by a clopen upper set. Compactness is often assumed, but we do not include it here. -/\nclass PriestleySpace (\u03b1 : Type _) [Preorder \u03b1] [TopologicalSpace \u03b1] where\n  priestley {x y : \u03b1} : \u00acx \u2264 y \u2192 \u2203 U : Set \u03b1, IsClopen U \u2227 IsUpperSet U \u2227 x \u2208 U \u2227 y \u2209 U\n#align priestley_space PriestleySpace\n\nvariable [TopologicalSpace \u03b1]\n\nsection Preorder\n\nvariable [Preorder \u03b1] [PriestleySpace \u03b1] {x y : \u03b1}\n\ntheorem exists_clopen_upper_of_not_le :\n    \u00acx \u2264 y \u2192 \u2203 U : Set \u03b1, IsClopen U \u2227 IsUpperSet U \u2227 x \u2208 U \u2227 y \u2209 U :=\n  PriestleySpace.priestley\n#align exists_clopen_upper_of_not_le exists_clopen_upper_of_not_le\n\ntheorem exists_clopen_lower_of_not_le (h : \u00acx \u2264 y) :\n    \u2203 U : Set \u03b1, IsClopen U \u2227 IsLowerSet U \u2227 x \u2209 U \u2227 y \u2208 U :=\n  let \u27e8U, hU, hU', hx, hy\u27e9 := exists_clopen_upper_of_not_le h\n  \u27e8U\u1d9c, hU.compl, hU'.compl, Classical.not_not.2 hx, hy\u27e9\n#align exists_clopen_lower_of_not_le exists_clopen_lower_of_not_le\n\nend Preorder\n\nsection PartialOrder\n\nvariable [PartialOrder \u03b1] [PriestleySpace \u03b1] {x y : \u03b1}\n\ntheorem exists_clopen_upper_or_lower_of_ne (h : x \u2260 y) :\n    \u2203 U : Set \u03b1, IsClopen U \u2227 (IsUpperSet U \u2228 IsLowerSet U) \u2227 x \u2208 U \u2227 y \u2209 U := by\n  obtain h | h := h.not_le_or_not_le\n  \u00b7 exact (exists_clopen_upper_of_not_le h).imp fun _ \u21a6 And.imp_right <| And.imp_left Or.inl\n  \u00b7 obtain \u27e8U, hU, hU', hy, hx\u27e9 := exists_clopen_lower_of_not_le h\n    exact \u27e8U, hU, Or.inr hU', hx, hy\u27e9\n#align exists_clopen_upper_or_lower_of_ne exists_clopen_upper_or_lower_of_ne\n\n-- See note [lower instance priority]\ninstance (priority := 100) PriestleySpace.toT2Space : T2Space \u03b1 :=\n  \u27e8fun _ _ h \u21a6\n    let \u27e8U, hU, _, hx, hy\u27e9 := exists_clopen_upper_or_lower_of_ne h\n    \u27e8U, U\u1d9c, hU.isOpen, hU.compl.isOpen, hx, hy, disjoint_compl_right\u27e9\u27e9\n#align priestley_space.to_t2_space PriestleySpace.toT2Space\n\nend PartialOrder\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Topology/Order/Priestley.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7003903704438627}}
{"text": "/-\nCopyright (c) 2021 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Scott Morrison\n-/\nimport algebra.homology.homotopy\nimport algebra.category.Module.abelian\nimport algebra.category.Module.subobject\n\n/-!\n# Complexes of modules\n\nWe provide some additional API to work with homological complexes in `Module R`.\n-/\n\nuniverses v u\n\nopen_locale classical\nnoncomputable theory\n\nopen category_theory category_theory.limits homological_complex\n\nvariables {R : Type v} [ring R]\nvariables {\u03b9 : Type*} {c : complex_shape \u03b9} {C D : homological_complex (Module.{u} R) c}\n\nnamespace Module\n\n/--\nTo prove that two maps out of a homology group are equal,\nit suffices to check they are equal on the images of cycles.\n-/\nlemma homology_ext {L M N K : Module R} {f : L \u27f6 M} {g : M \u27f6 N} (w : f \u226b g = 0)\n  {h k : homology f g w \u27f6 K}\n  (w : \u2200 (x : linear_map.ker g),\n    h (cokernel.\u03c0 (image_to_kernel _ _ w) (to_kernel_subobject x)) =\n      k (cokernel.\u03c0 (image_to_kernel _ _ w) (to_kernel_subobject x))) : h = k :=\nbegin\n  refine cokernel_funext (\u03bb n, _),\n  -- Gosh it would be nice if `equiv_rw` could directly use an isomorphism, or an enriched `\u2243`.\n  equiv_rw (kernel_subobject_iso g \u226a\u226b Module.kernel_iso_ker g).to_linear_equiv.to_equiv at n,\n  convert w n; simp [to_kernel_subobject],\nend\n\n/-- Bundle an element `C.X i` such that `C.d_from i x = 0` as a term of `C.cycles i`. -/\nabbreviation to_cycles {C : homological_complex (Module.{u} R) c}\n  {i : \u03b9} (x : linear_map.ker (C.d_from i)) : C.cycles i :=\nto_kernel_subobject x\n\n@[ext]\nlemma cycles_ext {C : homological_complex (Module.{u} R) c} {i : \u03b9}\n  {x y : C.cycles i} (w : (C.cycles i).arrow x = (C.cycles i).arrow y) : x = y :=\nbegin\n  apply_fun (C.cycles i).arrow using (Module.mono_iff_injective _).mp (cycles C i).arrow_mono,\n  exact w,\nend\n\nlocal attribute [instance] concrete_category.has_coe_to_sort\n\n@[simp] lemma cycles_map_to_cycles (f : C \u27f6 D) {i : \u03b9} (x : linear_map.ker (C.d_from i)) :\n  (cycles_map f i) (to_cycles x) = to_cycles \u27e8f.f i x.1, by simp [x.2]\u27e9 :=\nby { ext, simp, }\n\n/-- Build a term of `C.homology i` from an element `C.X i` such that `C.d_from i x = 0`. -/\nabbreviation to_homology\n  {C : homological_complex (Module.{u} R) c} {i : \u03b9} (x : linear_map.ker (C.d_from i)) :\n  C.homology i :=\nhomology.\u03c0 (C.d_to i) (C.d_from i) _ (to_cycles x)\n\n@[ext]\nlemma homology_ext' {M : Module R} (i : \u03b9) {h k : C.homology i \u27f6 M}\n  (w : \u2200 (x : linear_map.ker (C.d_from i)), h (to_homology x) = k (to_homology x)) :\n  h = k :=\nhomology_ext _ w\n\n/-- We give an alternative proof of `homology_map_eq_of_homotopy`,\nspecialized to the setting of `V = Module R`,\nto demonstrate the use of extensionality lemmas for homology in `Module R`. -/\nexample (f g : C \u27f6 D) (h : homotopy f g) (i : \u03b9) :\n  (homology_functor (Module.{u} R) c i).map f = (homology_functor (Module.{u} R) c i).map g :=\nbegin\n  -- To check that two morphisms out of a homology group agree, it suffices to check on cycles:\n  ext,\n  dsimp,\n  simp only [homology.\u03c0_map_apply],\n  -- To check that two elements are equal mod boundaries, it suffices to exhibit a boundary:\n  ext1,\n  swap, exact (to_prev i h.hom) x.1,\n  -- Moreover, to check that two cycles are equal, it suffices to check their underlying elements:\n  ext1,\n  simp [h.comm i, x.2]; abel,\nend\n\nend Module\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/algebra/homology/Module.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7003903639753181}}
{"text": "/- \nCopyright (c) 2022 Sina Hazratpour. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n----------------\n\n# A short introduction to type classes \nSina Hazratpour\nIntroduction to Proof  \nMATH 301, Johns Hopkins University, Fall 2022   \n-/\n\nimport ..prooflab\nimport .lec10_surj_inj_fact\n\n\nnamespace PROOFS\n\n\nnamespace STR\n\n-- the bundled structure of types with a point in them \nstructure pointed_type := \n(type : Type)\n(point : type)\n\n\n\n\n#check unit \n#check unit.star\n#check @unit.ext\n\n\n\nlocal notation `\ud835\udfd9` := unit -- type as \\b1\nlocal notation `\u22c6` := unit.star\n#check \u22c6 \n\n\n\n/- \ud835\udfd9 is a pointed type but `empty` is not.-/\ndef unit_ptd : pointed_type  := \n{\n  type := \ud835\udfd9, -- if you change \ud835\udfd9 to `empty`, you cannot provide for the second field any longer. \n  point := \u22c6,\n}\n\n\n#check unit_ptd\n\n\n\n\ndef bool_ptd : pointed_type := \n{\n  type := bool, \n  point := ff, \n}\n\n\ndef nat_ptd : pointed_type := \n{\n  type := \u2115, \n  point := 0, \n}\n\n\nstructure Q2 := \n(x : \u211a)\n(y : \u211a)\n\ndef Q2_ptd : pointed_type := \n{\n  type := Q2, \n  point := \u27e80,0\u27e9, \n}\n\n\ndef R3_ptd : pointed_type := \n{\n  type := R3, \n  point := \u27e80,0,0\u27e9, \n}\n\n\n\n\nnamespace pointed_type\nvariables {A B : pointed_type}\n\n\n/- The __product__ of two pointed types is a pointed type.\n\n  The attribute `@[simps point]` in below  is a hint to `simp` that it can unfold the point of this definition. -/\n\n@[simps point]\ndef product (A B : pointed_type) : pointed_type := \n{\n  type := A.type \u00d7 B.type,\n  point := (A.point, B.point),   \n}\n\n\n#check product\n\n\n#check product nat_ptd Q2_ptd\n#check (product nat_ptd Q2_ptd).point\n#eval (product nat_ptd Q2_ptd).point\n\n#eval (product nat_ptd bool_ptd).point -- type classes help with this\n\n\n\n@[ext]\nstructure morphism (A B : pointed_type) :=\n(to_fun : A.type \u2192 B.type)\n(resp_pt : to_fun A.point = B.point)\n\n\nend pointed_type\n\n\n#check pointed_type.product\n#print pointed_type.morphism\n#check @pointed_type.morphism.to_fun \n\n\n\n\ninfix ` \u2192\u2022 `:25 := pointed_type.morphism\n\n\nnamespace pointed_type\nvariables {A B C D : pointed_type}\n\n\n@[simp]\ndef compose (g : B \u2192\u2022 C) (f : A \u2192\u2022 B) : A \u2192\u2022 C :=\n{\n  to_fun := g.to_fun \u2218 f.to_fun,  \n  resp_pt := by {dsimp, rw f.resp_pt, exact g.resp_pt,},\n}\n\ndef id : A \u2192\u2022 A := \n{\n  to_fun := id, \n  resp_pt := rfl, \n}\n\ninfixr  ` \u2218\u2022 ` : 90  := compose\n\n\nlemma comp_assoc {g : A \u2192\u2022 B} {k : B \u2192\u2022 C} {l : C \u2192\u2022 D}: l \u2218\u2022 (k \u2218\u2022 g) = (l \u2218\u2022 k) \u2218\u2022 g :=\nbegin\n  simp, \nend \n\nend pointed_type\nend STR \n\n\n\n\n\n\nnamespace type_classes \n\nvariables X Y Z U V W : Type\n\n\n/-! ### Inhabited types -/\n-- @[class] structure has_element (X : Type) : Prop := (some_el : \u2203 x : X, true)\n\n-- This is an example of an unbundle type : the structure of all elements of `X`\n\n@[class] -- the new bit\nstructure has_element (X : Type) :=\n(el [] : X) -- el is a generic element of X, it has no other propetry than being an element of X. \n\n\nsection \n#check has_element -- it is a function which provides for any type `X` the type of its elements \n#check has_element X -- the type of elements of X -- compare this to the example of upper bounds from HW7\n#print has_element \n#check has_element.el \n#print has_element.el -- the [] bracket makes X  in \u03a0 (X : Type u_10) explicit.\nend \n\n\n@[instance] -- the new bit\ndef natural : has_element \u2115 :=\n{ el := 0 }\n\n\n/-\nA shorthand for `@[instance] def` is `instance`. \n-/\n\ninstance integer : has_element \u2124 := \n{ el := 0 }\n\n\ninstance boolean : has_element bool := \n{ el := ff }\n\n\ninstance unit : has_element unit := \n{ el := () }\n\n\n\ninstance list {X : Type} : has_element (list X):= \n{ el := [] }\n\n\n\n\nnamespace has_element\n/- The product of two types, each with an element, has an element.-/\ninstance product {A B : Type} [has_element A] [has_element B] :\n  has_element (A \u00d7 B) :=\n{\n  el := (has_element.el A, has_element.el B), \n}\n\n\n/-! ### Instance Synthesis  \n\n**Based on the type, Lean retrieves the relevant instances.**\n\nWhenever the elaborator is looking for a value to assign to an argument `?M` of type `has_element X` for some `X`, it can check the list for a suitable instance: For example, if it looking for an instance of `has_element nat` and `has_element bool`, it will find respectively `bool.has_element` and `nat.has_element`. \n\nThen Lean synthesizes these instances with the instance `prod.has_element` to know that the product `\u2115 \u00d7 bool` is nonempty. \n-/\n\nsection \n#check has_element (\u2115 \u00d7 bool)\n#check has_element.el (\u2115 \u00d7 bool) -- how does Lean know that `\u2115 \u00d7 bool` has an elemnet? that is how does it know an instance of `has_element` structure for the type `\u2115 \u00d7 bool`? Well, `\u2115 \u00d7 bool` is a product type, so to have an instance `has_element` for it, Lean will look for an instance of `has_element` for product types which we defined above (see `product`). `prodcut` instance tells us that to have a  `has_element` structure for a product `A \u00d7 B` it is enough to have a `has_element` structure for `A` and a `has_element` structure for `B`. But, in our situation `A` is `\u2115` and `B` is `bool`. So, Lean's task now is to find instances `has_element` structure for `nat` and for `bool` which are provided by `has_element.natural` and `has_element.boolean`. We actually do not need to provide any of these names explicitly in constructing an element of `\u2115 \u00d7 bool`; Lean's instance synthesis does it automatically for us.  \n#eval has_element.el (\u2115 \u00d7 bool)\nend \n\n-- we can do this by explicitly naming the instances of `has_element A` and `has_element B`, although this is against the automation spirit of using Lean. \ninstance product_alt {A B : Type} [hA : has_element A] [hB : has_element B] :\n  has_element (A \u00d7 B) :=\n{ el := \u27e8hA.el, hB.el\u27e9 }\n\n\n@[instance] def fun_from_empty {Y : Type} :\n  has_element (empty \u2192 Y) :=\n{ el := \u03bb a : empty, match a with end }\n\n#reduce has_element.el (empty \u2192 empty) \n\n\nclass morphism (X Y : Type) [has_element X] [has_element Y] := \n(to_fun : X \u2192 Y) \n(resp_el : to_fun (has_element.el X) = has_element.el Y)\n\n\n\ninstance unit_to_bool : morphism unit bool := \n{ \n  to_fun := \u03bb x, ff, -- try changing `ff` to `tt`. Does it work? why not? \n  resp_el := by {refl}, \n}\n\n\ninstance bool_to_nat : morphism bool nat := \n{ \n  to_fun := nat_of_bool, \n  resp_el := by {refl}, \n}\n\n\n#check has_element.bool_to_nat\n\n\n\nend has_element\n\n\n\nend type_classes\n\n\n\nend PROOFS ", "meta": {"author": "sinhp", "repo": "ProofLab", "sha": "f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2", "save_path": "github-repos/lean/sinhp-ProofLab", "path": "github-repos/lean/sinhp-ProofLab/ProofLab-f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2/src/lectures/lec11_type_classes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867729389246, "lm_q2_score": 0.8774767762675405, "lm_q1q2_score": 0.7003903563778389}}
{"text": "import algebra.char_p.basic\nimport algebra.euclidean_domain.defs\n\nimport lib.wronskian\nimport lib.div_radical\nimport lib.max3\n\nnoncomputable theory\nopen_locale polynomial classical\n\nopen polynomial\nopen unique_factorization_monoid\n\nvariables {k: Type*} [field k]\n\n@[simp]\nlemma dvd_derivative_iff {a : k[X]} : \n  a \u2223 a.derivative \u2194 a.derivative = 0 :=\nbegin\n  split,\n  intro h,\n  by_cases a_nz : a = 0,\n  { rw a_nz, simp only [derivative_zero], },\n  by_contra deriv_nz,\n  have deriv_lt := degree_derivative_lt a_nz,\n  have le_deriv := polynomial.degree_le_of_dvd h deriv_nz,\n  have lt_self := le_deriv.trans_lt deriv_lt,\n  simp only [lt_self_iff_false] at lt_self, exact lt_self,\n\n  intro h, rw h, simp,\nend\n\nlemma is_coprime.wronskian_eq_zero_iff\n  {a b : k[X]} (hc: is_coprime a b) : \n  wronskian a b = 0 \u2194 (a.derivative = 0 \u2227 b.derivative = 0) :=\nbegin\n  split,\n\n  intro hw,\n  rw [wronskian, sub_eq_iff_eq_add, zero_add] at hw,\n  split,\n  { rw \u2190dvd_derivative_iff,\n    apply hc.dvd_of_dvd_mul_right,\n    rw \u2190hw, exact dvd_mul_right _ _, },\n  { rw \u2190dvd_derivative_iff,\n    apply hc.symm.dvd_of_dvd_mul_left,\n    rw hw, exact dvd_mul_left _ _, },\n\n  intro hdab,\n  cases hdab with hda hdb,\n  rw wronskian,\n  rw [hda, hdb], simp only [mul_zero, zero_mul, sub_self],\nend\n\n/- ABC for polynomials (Mason-Stothers theorem)\n\nFor coprime polynomials a, b, c satisfying a + b + c = 0 and deg(a) \u2265 deg(rad(abc)), we have a' = b' = c' = 0.\n\nProof is based on this online note by Franz Lemmermeyer http://www.fen.bilkent.edu.tr/~franz/ag05/ag-02.pdf, which is essentially based on Noah Snyder's proof (\"An Alternative Proof of Mason's Theorem\"), but slightly different.\n\n1. Show that W(a, b) = W(b, c) = W(c, a) =: W. `wronskian_eq_of_sum_zero`\n2. (a / rad(a)) | W, and same for b and c. `poly_mod_rad_div_diff`\n3. a / rad(a), b / rad(b), c / rad(c) are all coprime, so their product abc / rad(abc) also divides W. `poly_coprime_div_mul_div`\n4. Using the assumption on degrees, deduce that deg (abc / rad(abc)) > deg W.\n5. By `polynomial.degree_le_of_dvd`, W = 0.\n6. Since W(a, b) = ab' - a'b = 0 and a and b are coprime, a' = 0. Similarly we have b' = c' = 0. `coprime_wronskian_eq_zero_const`\n-/\n\nprotected lemma is_coprime.div_radical {a b : k[X]}\n  (h : is_coprime a b) : is_coprime a.div_radical b.div_radical :=\nbegin\n  rw \u2190polynomial.mul_radical_div_radical a at h,\n  rw \u2190polynomial.mul_radical_div_radical b at h,\n  exact h.of_mul_left_right.of_mul_right_right,\nend\n\nprivate lemma abc_subcall {a b c w : k[X]}\n  {hw : w \u2260 0} (wab : w = wronskian a b)\n  (ha : a \u2260 0) (hb : b \u2260 0) (hc : c \u2260 0)\n  (hab: is_coprime a b) (hbc: is_coprime b c) (hca: is_coprime c a)\n  (abc_dr_dvd_w : (a*b*c).div_radical \u2223 w) : \n    c.nat_degree < (a*b*c).radical.nat_degree :=\nbegin\n  have hab := mul_ne_zero ha hb,\n  have habc := mul_ne_zero hab hc,\n\n  set abc_dr_nd := (a*b*c).div_radical.nat_degree with def_abc_dr_nd,\n  set abc_r_nd := (a*b*c).radical.nat_degree with def_abc_r_nd,\n  have t11 : abc_dr_nd < a.nat_degree + b.nat_degree := by calc\n    abc_dr_nd \u2264 w.nat_degree : \n        polynomial.nat_degree_le_of_dvd abc_dr_dvd_w hw\n    ... < a.nat_degree + b.nat_degree :\n        by rw wab at hw \u22a2; exact wronskian.nat_degree_lt_add hw,\n  have t4 : abc_dr_nd + abc_r_nd < a.nat_degree + b.nat_degree + abc_r_nd :=\n    nat.add_lt_add_right t11 abc_r_nd,\n  have t3 : abc_dr_nd + abc_r_nd = a.nat_degree + b.nat_degree + c.nat_degree := by calc\n    abc_dr_nd + abc_r_nd = ((a*b*c).div_radical * (a*b*c).radical).nat_degree : \n      by rw \u2190polynomial.nat_degree_mul\n        (polynomial.div_radical_ne_zero habc)\n        (a*b*c).radical_ne_zero\n    ... = (a*b*c).nat_degree :\n      by rw mul_comm _ (polynomial.radical _);\n         rw (a * b * c).mul_radical_div_radical\n    ... = a.nat_degree + b.nat_degree + c.nat_degree :\n      by rw [polynomial.nat_degree_mul hab hc, polynomial.nat_degree_mul ha hb],\n  rw t3 at t4,\n  exact nat.lt_of_add_lt_add_left t4,\nend\n\nprivate lemma rot3_add {a b c : k[X]} : a + b + c = b + c + a := by ring_nf\nprivate lemma rot3_mul {a b c : k[X]} : a * b * c = b * c * a := by ring_nf\n\ntheorem polynomial.abc {a b c : k[X]}\n  (ha : a \u2260 0) (hb : b \u2260 0) (hc : c \u2260 0)\n  (hab: is_coprime a b) (hbc: is_coprime b c) (hca: is_coprime c a) (hsum: a + b + c = 0) : \n    (max3 a.nat_degree b.nat_degree c.nat_degree < (a*b*c).radical.nat_degree) \u2228\n    (a.derivative = 0 \u2227 b.derivative = 0 \u2227 c.derivative = 0) :=\nbegin\n  -- Utility assertions\n  have wbc := wronskian_eq_of_sum_zero hsum,\n  set w := wronskian a b with wab,\n  have wca : w = wronskian c a := begin\n    rw rot3_add at hsum,\n    have h := wronskian_eq_of_sum_zero hsum,\n    rw \u2190wbc at h, exact h,\n  end,\n  have abc_dr_dvd_w : (a*b*c).div_radical \u2223 w := begin\n    have adr_dvd_w := a.div_radical_dvd_wronskian_left b,\n    have bdr_dvd_w := a.div_radical_dvd_wronskian_right b,\n    have cdr_dvd_w := b.div_radical_dvd_wronskian_right c,\n    rw \u2190wab at adr_dvd_w bdr_dvd_w, \n    rw \u2190wbc at cdr_dvd_w,\n\n    have cop_ab_dr := hab.div_radical,\n    have cop_bc_dr := hbc.div_radical,\n    have cop_ca_dr := hca.div_radical,\n    have cop_abc_dr := cop_ca_dr.symm.mul_left cop_bc_dr,\n    have abdr_dvd_w := cop_ab_dr.mul_dvd adr_dvd_w bdr_dvd_w,\n    have abcdr_dvd_w := cop_abc_dr.mul_dvd abdr_dvd_w cdr_dvd_w,\n\n    convert abcdr_dvd_w,\n\n    rw \u2190polynomial.div_radical_mul hab,\n    rw \u2190polynomial.div_radical_mul _,\n    exact hca.symm.mul_left hbc,\n  end,\n\n  by_cases hw : w = 0,\n  { right,\n    rw hw at wab wbc,\n    cases hab.wronskian_eq_zero_iff.mp wab.symm with ga gb,\n    cases hbc.wronskian_eq_zero_iff.mp wbc.symm with _ gc,\n    refine \u27e8ga, gb, gc\u27e9, },\n  { left, rw max3_lt_iff,\n    refine \u27e8_, _, _\u27e9,\n    { rw rot3_mul at \u22a2 abc_dr_dvd_w,\n      apply abc_subcall wbc; assumption, },\n    { rw [rot3_mul, rot3_mul] at \u22a2 abc_dr_dvd_w,\n      apply abc_subcall wca; assumption, },\n    { apply abc_subcall wab; assumption, }, },\nend\n\nlemma pow_derivative_eq_zero \n  {n : \u2115} (chn : \u00ac(ring_char k \u2223 n))\n  {a : k[X]} (ha : a \u2260 0) :\n  (a^n).derivative = 0 \u2194 a.derivative = 0 :=\nbegin\n  split,\n  { intro apd,\n    rw derivative_pow at apd,\n    simp only [C_eq_nat_cast, mul_eq_zero] at apd,\n    have pnz : a^(n-1) \u2260 0 := pow_ne_zero (n-1) ha,\n    have cn_neq_zero : (\u2191(\u2191n : k) : k[X]) \u2260 0 := begin\n      simp only [polynomial.C_eq_zero, ne.def,\n        algebra_map.lift_map_eq_zero_iff],\n      intro cn_eq_zero,\n      exact chn (ring_char.dvd cn_eq_zero),\n    end,\n    tauto, },\n  { intro hd, rw derivative_pow, rw hd, \n    simp only [mul_zero], },\nend", "meta": {"author": "seewoo5", "repo": "lean-poly-abc", "sha": "30649e24bee0182999d494b07847e2ddf06607ef", "save_path": "github-repos/lean/seewoo5-lean-poly-abc", "path": "github-repos/lean/seewoo5-lean-poly-abc/lean-poly-abc-30649e24bee0182999d494b07847e2ddf06607ef/src/mason_stothers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7003468822492985}}
{"text": "/-\nCopyright (c) 2020 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth\n-/\nimport analysis.specific_limits\n\n/-!\n# The group of units of a complete normed ring\n\nThis file contains the basic theory for the group of units (invertible elements) of a complete\nnormed ring (Banach algebras being a notable special case).\n\n## Main results\n\nThe constructions `one_sub`, `add` and `unit_of_nearby` state, in varying forms, that perturbations\nof a unit are units.  The latter two are not stated in their optimal form; more precise versions\nwould use the spectral radius.\n\nThe first main result is `is_open`:  the group of units of a complete normed ring is an open subset\nof the ring.\n\nThe function `inverse` (defined in `algebra.ring`), for a ring `R`, sends `a : R` to `a\u207b\u00b9` if `a` is\na unit and 0 if not.  The other major results of this file (notably `inverse_add`,\n`inverse_add_norm` and `inverse_add_norm_diff_nth_order`) cover the asymptotic properties of\n`inverse (x + t)` as `t \u2192 0`.\n\n-/\n\nnoncomputable theory\nopen_locale topological_space\nvariables {R : Type*} [normed_ring R] [complete_space R]\n\nnamespace units\n\n/-- In a complete normed ring, a perturbation of `1` by an element `t` of distance less than `1`\nfrom `1` is a unit.  Here we construct its `units` structure.  -/\n@[simps coe]\ndef one_sub (t : R) (h : \u2225t\u2225 < 1) : R\u02e3 :=\n{ val := 1 - t,\n  inv := \u2211' n : \u2115, t ^ n,\n  val_inv := mul_neg_geom_series t h,\n  inv_val := geom_series_mul_neg t h }\n\n/-- In a complete normed ring, a perturbation of a unit `x` by an element `t` of distance less than\n`\u2225x\u207b\u00b9\u2225\u207b\u00b9` from `x` is a unit.  Here we construct its `units` structure. -/\n@[simps coe]\ndef add (x : R\u02e3) (t : R) (h : \u2225t\u2225 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9) : R\u02e3 :=\nunits.copy  -- to make `coe_add` true definitionally, for convenience\n  (x * (units.one_sub (-(\u2191x\u207b\u00b9 * t)) begin\n      nontriviality R using [zero_lt_one],\n      have hpos : 0 < \u2225(\u2191x\u207b\u00b9 : R)\u2225 := units.norm_pos x\u207b\u00b9,\n      calc \u2225-(\u2191x\u207b\u00b9 * t)\u2225\n          = \u2225\u2191x\u207b\u00b9 * t\u2225                    : by { rw norm_neg }\n      ... \u2264 \u2225(\u2191x\u207b\u00b9 : R)\u2225 * \u2225t\u2225            : norm_mul_le \u2191x\u207b\u00b9 _\n      ... < \u2225(\u2191x\u207b\u00b9 : R)\u2225 * \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9 : by nlinarith only [h, hpos]\n      ... = 1                             : mul_inv_cancel (ne_of_gt hpos)\n    end))\n  (x + t) (by simp [mul_add]) _ rfl\n\n/-- In a complete normed ring, an element `y` of distance less than `\u2225x\u207b\u00b9\u2225\u207b\u00b9` from `x` is a unit.\nHere we construct its `units` structure. -/\n@[simps coe]\ndef unit_of_nearby (x : R\u02e3) (y : R) (h : \u2225y - x\u2225 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9) : R\u02e3 :=\nunits.copy (x.add (y - x : R) h) y (by simp) _ rfl\n\n/-- The group of units of a complete normed ring is an open subset of the ring. -/\nprotected lemma is_open : is_open {x : R | is_unit x} :=\nbegin\n  nontriviality R,\n  apply metric.is_open_iff.mpr,\n  rintros x' \u27e8x, rfl\u27e9,\n  refine \u27e8\u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9, _root_.inv_pos.mpr (units.norm_pos x\u207b\u00b9), _\u27e9,\n  intros y hy,\n  rw [metric.mem_ball, dist_eq_norm] at hy,\n  exact (x.unit_of_nearby y hy).is_unit\nend\n\nprotected lemma nhds (x : R\u02e3) : {x : R | is_unit x} \u2208 \ud835\udcdd (x : R) :=\nis_open.mem_nhds units.is_open x.is_unit\n\nend units\n\nnamespace normed_ring\nopen_locale classical big_operators\nopen asymptotics filter metric finset ring\n\nlemma inverse_one_sub (t : R) (h : \u2225t\u2225 < 1) : inverse (1 - t) = \u2191(units.one_sub t h)\u207b\u00b9 :=\nby rw [\u2190 inverse_unit (units.one_sub t h), units.coe_one_sub]\n\n/-- The formula `inverse (x + t) = inverse (1 + x\u207b\u00b9 * t) * x\u207b\u00b9` holds for `t` sufficiently small. -/\nlemma inverse_add (x : R\u02e3) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((x : R) + t) = inverse (1 + \u2191x\u207b\u00b9 * t) * \u2191x\u207b\u00b9 :=\nbegin\n  nontriviality R,\n  rw [eventually_iff, metric.mem_nhds_iff],\n  have hinv : 0 < \u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9, by cancel_denoms,\n  use [\u2225(\u2191x\u207b\u00b9 : R)\u2225\u207b\u00b9, hinv],\n  intros t ht,\n  simp only [mem_ball, dist_zero_right] at ht,\n  have ht' : \u2225-\u2191x\u207b\u00b9 * t\u2225 < 1,\n  { refine lt_of_le_of_lt (norm_mul_le _ _) _,\n    rw norm_neg,\n    refine lt_of_lt_of_le (mul_lt_mul_of_pos_left ht x\u207b\u00b9.norm_pos) _,\n    cancel_denoms },\n  have hright := inverse_one_sub (-\u2191x\u207b\u00b9 * t) ht',\n  have hleft := inverse_unit (x.add t ht),\n  simp only [\u2190 neg_mul_eq_neg_mul, sub_neg_eq_add] at hright,\n  simp only [units.coe_add] at hleft,\n  simp [hleft, hright, units.add]\nend\n\nlemma inverse_one_sub_nth_order (n : \u2115) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((1:R) - t) = (\u2211 i in range n, t ^ i) + (t ^ n) * inverse (1 - t) :=\nbegin\n  simp only [eventually_iff, metric.mem_nhds_iff],\n  use [1, by norm_num],\n  intros t ht,\n  simp only [mem_ball, dist_zero_right] at ht,\n  simp only [inverse_one_sub t ht, set.mem_set_of_eq],\n  have h : 1 = ((range n).sum (\u03bb i, t ^ i)) * (units.one_sub t ht) + t ^ n,\n  { simp only [units.coe_one_sub],\n    rw [\u2190 geom_sum, geom_sum_mul_neg],\n    simp },\n  rw [\u2190 one_mul \u2191(units.one_sub t ht)\u207b\u00b9, h, add_mul],\n  congr,\n  { rw [mul_assoc, (units.one_sub t ht).mul_inv],\n    simp },\n  { simp only [units.coe_one_sub],\n    rw [\u2190 add_mul, \u2190 geom_sum, geom_sum_mul_neg],\n    simp }\nend\n\n/-- The formula\n`inverse (x + t) = (\u2211 i in range n, (- x\u207b\u00b9 * t) ^ i) * x\u207b\u00b9 + (- x\u207b\u00b9 * t) ^ n * inverse (x + t)`\nholds for `t` sufficiently small. -/\nlemma inverse_add_nth_order (x : R\u02e3) (n : \u2115) :\n  \u2200\u1da0 t in (\ud835\udcdd 0), inverse ((x : R) + t)\n  = (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9 + (- \u2191x\u207b\u00b9 * t) ^ n * inverse (x + t) :=\nbegin\n  refine (inverse_add x).mp _,\n  have hzero : tendsto (\u03bb (t : R), - \u2191x\u207b\u00b9 * t) (\ud835\udcdd 0) (\ud835\udcdd 0),\n  { convert ((mul_left_continuous (- (\u2191x\u207b\u00b9 : R))).tendsto 0).comp tendsto_id,\n    simp },\n  refine (hzero.eventually (inverse_one_sub_nth_order n)).mp (eventually_of_forall _),\n  simp only [neg_mul_eq_neg_mul_symm, sub_neg_eq_add],\n  intros t h1 h2,\n  have h := congr_arg (\u03bb (a : R), a * \u2191x\u207b\u00b9) h1,\n  dsimp at h,\n  convert h,\n  rw [add_mul, mul_assoc],\n  simp [h2.symm]\nend\n\nlemma inverse_one_sub_norm : is_O (\u03bb t, inverse ((1:R) - t)) (\u03bb t, (1:\u211d)) (\ud835\udcdd (0:R)) :=\nbegin\n  simp only [is_O, is_O_with, eventually_iff, metric.mem_nhds_iff],\n  refine \u27e8\u2225(1:R)\u2225 + 1, (2:\u211d)\u207b\u00b9, by norm_num, _\u27e9,\n  intros t ht,\n  simp only [ball, dist_zero_right, set.mem_set_of_eq] at ht,\n  have ht' : \u2225t\u2225 < 1,\n  { have : (2:\u211d)\u207b\u00b9 < 1 := by cancel_denoms,\n    linarith },\n  simp only [inverse_one_sub t ht', norm_one, mul_one, set.mem_set_of_eq],\n  change \u2225\u2211' n : \u2115, t ^ n\u2225 \u2264 _,\n  have := normed_ring.tsum_geometric_of_norm_lt_1 t ht',\n  have : (1 - \u2225t\u2225)\u207b\u00b9 \u2264 2,\n  { rw \u2190 inv_inv\u2080 (2:\u211d),\n    refine inv_le_inv_of_le (by norm_num) _,\n    have : (2:\u211d)\u207b\u00b9 + (2:\u211d)\u207b\u00b9 = 1 := by ring,\n    linarith },\n  linarith\nend\n\n/-- The function `\u03bb t, inverse (x + t)` is O(1) as `t \u2192 0`. -/\nlemma inverse_add_norm (x : R\u02e3) : is_O (\u03bb t, inverse (\u2191x + t)) (\u03bb t, (1:\u211d)) (\ud835\udcdd (0:R)) :=\nbegin\n  simp only [is_O_iff, norm_one, mul_one],\n  cases is_O_iff.mp (@inverse_one_sub_norm R _ _) with C hC,\n  use C * \u2225((x\u207b\u00b9:R\u02e3):R)\u2225,\n  have hzero : tendsto (\u03bb t, - (\u2191x\u207b\u00b9 : R) * t) (\ud835\udcdd 0) (\ud835\udcdd 0),\n  { convert ((mul_left_continuous (-\u2191x\u207b\u00b9 : R)).tendsto 0).comp tendsto_id,\n    simp },\n  refine (inverse_add x).mp ((hzero.eventually hC).mp (eventually_of_forall _)),\n  intros t bound iden,\n  rw iden,\n  simp at bound,\n  have hmul := norm_mul_le (inverse (1 + \u2191x\u207b\u00b9 * t)) \u2191x\u207b\u00b9,\n  nlinarith [norm_nonneg (\u2191x\u207b\u00b9 : R)]\nend\n\n/-- The function\n`\u03bb t, inverse (x + t) - (\u2211 i in range n, (- x\u207b\u00b9 * t) ^ i) * x\u207b\u00b9`\nis `O(t ^ n)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_nth_order (x : R\u02e3) (n : \u2115) :\n  is_O (\u03bb (t : R), inverse (\u2191x + t) - (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9)\n  (\u03bb t, \u2225t\u2225 ^ n) (\ud835\udcdd (0:R)) :=\nbegin\n  by_cases h : n = 0,\n  { simpa [h] using inverse_add_norm x },\n  have hn : 0 < n := nat.pos_of_ne_zero h,\n  simp [is_O_iff],\n  cases (is_O_iff.mp (inverse_add_norm x)) with C hC,\n  use C * \u2225(1:\u211d)\u2225 * \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n,\n  have h : eventually_eq (\ud835\udcdd (0:R))\n    (\u03bb t, inverse (\u2191x + t) - (\u2211 i in range n, (- \u2191x\u207b\u00b9 * t) ^ i) * \u2191x\u207b\u00b9)\n    (\u03bb t, ((- \u2191x\u207b\u00b9 * t) ^ n) * inverse (x + t)),\n  { refine (inverse_add_nth_order x n).mp (eventually_of_forall _),\n    intros t ht,\n    convert congr_arg (\u03bb a, a - (range n).sum (pow (-\u2191x\u207b\u00b9 * t)) * \u2191x\u207b\u00b9) ht,\n    simp },\n  refine h.mp (hC.mp (eventually_of_forall _)),\n  intros t _ hLHS,\n  simp only [neg_mul_eq_neg_mul_symm] at hLHS,\n  rw hLHS,\n  refine le_trans (norm_mul_le _ _ ) _,\n  have h' : \u2225(-(\u2191x\u207b\u00b9 * t)) ^ n\u2225 \u2264 \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n * \u2225t\u2225 ^ n,\n  { calc \u2225(-(\u2191x\u207b\u00b9 * t)) ^ n\u2225 \u2264 \u2225(-(\u2191x\u207b\u00b9 * t))\u2225 ^ n : norm_pow_le' _ hn\n    ... = \u2225\u2191x\u207b\u00b9 * t\u2225 ^ n : by rw norm_neg\n    ... \u2264 (\u2225(\u2191x\u207b\u00b9 : R)\u2225 * \u2225t\u2225) ^ n : _\n    ... =  \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n * \u2225t\u2225 ^ n : mul_pow _ _ n,\n    exact pow_le_pow_of_le_left (norm_nonneg _) (norm_mul_le \u2191x\u207b\u00b9 t) n },\n  have h'' : 0 \u2264 \u2225(\u2191x\u207b\u00b9 : R)\u2225 ^ n * \u2225t\u2225 ^ n,\n  { refine mul_nonneg _ _;\n    exact pow_nonneg (norm_nonneg _) n },\n  nlinarith [norm_nonneg (inverse (\u2191x + t))],\nend\n\n/-- The function `\u03bb t, inverse (x + t) - x\u207b\u00b9` is `O(t)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_first_order (x : R\u02e3) :\n  is_O (\u03bb t, inverse (\u2191x + t) - \u2191x\u207b\u00b9) (\u03bb t, \u2225t\u2225) (\ud835\udcdd (0:R)) :=\nby simpa using inverse_add_norm_diff_nth_order x 1\n\n/-- The function\n`\u03bb t, inverse (x + t) - x\u207b\u00b9 + x\u207b\u00b9 * t * x\u207b\u00b9`\nis `O(t ^ 2)` as `t \u2192 0`. -/\nlemma inverse_add_norm_diff_second_order (x : R\u02e3) :\n  is_O (\u03bb t, inverse (\u2191x + t) - \u2191x\u207b\u00b9 + \u2191x\u207b\u00b9 * t * \u2191x\u207b\u00b9) (\u03bb t, \u2225t\u2225 ^ 2) (\ud835\udcdd (0:R)) :=\nbegin\n  convert inverse_add_norm_diff_nth_order x 2,\n  ext t,\n  simp only [range_succ, range_one, sum_insert, mem_singleton, sum_singleton, not_false_iff,\n    one_ne_zero, pow_zero, add_mul, pow_one, one_mul, neg_mul_eq_neg_mul_symm,\n    sub_add_eq_sub_sub_swap, sub_neg_eq_add],\nend\n\n/-- The function `inverse` is continuous at each unit of `R`. -/\nlemma inverse_continuous_at (x : R\u02e3) : continuous_at inverse (x : R) :=\nbegin\n  have h_is_o : is_o (\u03bb (t : R), inverse (\u2191x + t) - \u2191x\u207b\u00b9) (\u03bb _, 1 : R \u2192 \u211d) (\ud835\udcdd 0),\n    from ((inverse_add_norm_diff_first_order x).trans_is_o\n      (is_o_id_const (@one_ne_zero \u211d _ _)).norm_left),\n  have h_lim : tendsto (\u03bb (y:R), y - x) (\ud835\udcdd x) (\ud835\udcdd 0),\n  { refine tendsto_zero_iff_norm_tendsto_zero.mpr _,\n    exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },\n  rw [continuous_at, tendsto_iff_norm_tendsto_zero, inverse_unit],\n  simpa [(\u2218)] using h_is_o.norm_left.tendsto_div_nhds_zero.comp h_lim\nend\n\nend normed_ring\n\nnamespace units\nopen mul_opposite filter normed_ring\n\n/-- In a normed ring, the coercion from `R\u02e3` (equipped with the induced topology from the\nembedding in `R \u00d7 R`) to `R` is an open map. -/\nlemma is_open_map_coe : is_open_map (coe : R\u02e3 \u2192 R) :=\nbegin\n  rw is_open_map_iff_nhds_le,\n  intros x s,\n  rw [mem_map, mem_nhds_induced],\n  rintros \u27e8t, ht, hts\u27e9,\n  obtain \u27e8u, hu, v, hv, huvt\u27e9 :\n    \u2203 (u : set R), u \u2208 \ud835\udcdd \u2191x \u2227 \u2203 (v : set R\u1d50\u1d52\u1d56), v \u2208 \ud835\udcdd (op \u2191x\u207b\u00b9) \u2227 u \u00d7\u02e2 v \u2286 t,\n  { simpa [embed_product, mem_nhds_prod_iff] using ht },\n  have : u \u2229 (op \u2218 ring.inverse) \u207b\u00b9' v \u2229 (set.range (coe : R\u02e3 \u2192 R)) \u2208 \ud835\udcdd \u2191x,\n  { refine inter_mem (inter_mem hu _) (units.nhds x),\n    refine (continuous_op.continuous_at.comp (inverse_continuous_at x)).preimage_mem_nhds _,\n    simpa using hv },\n  refine mem_of_superset this _,\n  rintros _ \u27e8\u27e8huy, hvy\u27e9, \u27e8y, rfl\u27e9\u27e9,\n  have : embed_product R y \u2208 u \u00d7\u02e2 v := \u27e8huy, by simpa using hvy\u27e9,\n  simpa using hts (huvt this)\nend\n\n/-- In a normed ring, the coercion from `R\u02e3` (equipped with the induced topology from the\nembedding in `R \u00d7 R`) to `R` is an open embedding. -/\nlemma open_embedding_coe : open_embedding (coe : R\u02e3 \u2192 R) :=\nopen_embedding_of_continuous_injective_open continuous_coe ext is_open_map_coe\n\nend units\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/analysis/normed_space/units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7003468709587191}}
{"text": "import data.real.basic tactic.norm_num\nimport xenalib.M1F.real_half_not_an_integer\nimport xenalib.M1F.int_squared_lt_3\n\nnoncomputable theory\n\n-- what they need to know before they embark on this:\n-- x \u2208 A \u2229 B \u2192 x \u2208 A\n-- x \u2208 A \u2192 x \u2208 A \u222a B\n-- A \u2286 C \u2227 x \u2208 A \u2227 x \u2209 C \u2192 false\n-- B = {-1,0,1} (only way to prove (d))\n-- rw an iff\n-- real_half_not_an_integer : \u00ac\u2203 (n : \u2124), 1 / 2 = \u2191n\n-- \u00ac x is the same as x \u2192 false\n-- x \u2208 C \u2227 x \u2209 A \u2227 x \u2209 B \u2227 C \u2286 A \u222a B \u2192 false\n-- what to do with H : x = a \u2228 x = b\n-- rw H at H'\n\ndef A : set \u211d := { x | x^2 < 3}\ndef B : set \u211d := { x | x^2 < 3 \u2227 \u2203 y : \u2124, x = \u2191y}\ndef C : set \u211d := { x | x^3 < 3}\n\n/-\ntheorem part_a_true : (1/2 : \u211d) \u2208 A \u2229 B := sorry\ntheorem part_a_false : \u00ac (1/2 : \u211d) \u2208 A \u2229 B := sorry\ntheorem part_b_true : (1/2 : \u211d) \u2208 A \u222a B := sorry\ntheorem part_b_false : (1/2 : \u211d) \u2208 A \u222a B := sorry\ntheorem part_c_true : A \u2286 C := sorry\ntheorem part_c_false : \u00ac A \u2286 C := sorry\ntheorem part_d_true : B \u2286 C := sorry\ntheorem part_d_false : \u00ac B \u2286 C := sorry\ntheorem part_e_true : C \u2286 A \u222a B := sorry\ntheorem part_e_false : \u00ac C \u2286 A \u222a B := sorry\ntheorem part_f_true : (A \u2229 B) \u222a C = (A \u222a B) \u2229 C := sorry\ntheorem part_f_false : \u00ac (A \u2229 B) \u222a C = (A \u222a B) \u2229 C := sorry\n-/\n\ntheorem part_a_false : \u00ac (1/2 : \u211d) \u2208 A \u2229 B :=\nbegin\n  assume H : ((1/2):\u211d) \u2208 A \u2229 B,\n  have H2: ((1/2):\u211d) \u2208 B,\n    exact and.right H,\n  have H3: \u2203 y : \u2124, ((1/2):\u211d) = \u2191y,\n    exact and.right H2,\n  exact real_half_not_an_integer H3,\nend\n\ntheorem part_b_true : (1/2 : \u211d) \u2208 A \u222a B :=\nbegin\n  apply set.subset_union_left,\n  -- goal now \"1/2 in A\"\n  -- let's rewrite this\n  show (1/2 : \u211d) ^ 2 < 3,\n  norm_num\nend\n\ntheorem part_c_false : \u00ac A \u2286 C :=\nbegin\n  assume H : A \u2286 C,\n  let x := (3/2 : \u211d), --  strat is to prove x is in A but not C\n  have H2 : x \u2208 A,\n    show (3/2 : \u211d)^2 < 3,\n    norm_num,\n  have H3 : \u00ac (x \u2208 C),\n    show \u00ac (3/2 : \u211d) ^ 3 < 3,\n    norm_num,\n  suffices : x \u2208 C,\n    exact absurd this H3,\n  suffices : x \u2208 A,\n    exact H this,\n  exact H2,\nend\n-- To do part (d) it's helpful to evaluate B completely.\n-- def B : set \u211d := {x | (\u2203 y : \u2124, x = of_rat y) \u2227 x^2 < 3}\n\n-- #check @eq.subst\n-- #check rat.coe_int_mul\n-- #check rat.coe_int_lt\n\nlemma B_is_minus_one_or_zero_or_one (x : \u211d) (Hx : x \u2208 B) : x = -1 \u2228 x = 0 \u2228 x = 1 :=\n(B_is_minus_one_zero_one x).1 Hx\n\n-- set_option pp.notation false\ntheorem part_d : B \u2286 C :=  -- B={-1,0,1} so this is true\nbegin\n  intros x Hx,\n  cases B_is_minus_one_or_zero_or_one x Hx with H H,\n    rw H,\n    unfold C,\n    norm_num,\n  cases H with H H,\n    rw H,\n    unfold C,norm_num,\n  rw H,unfold C,norm_num,\nend\n\n-- To do parts e and f it's useful to note that -2 is in C but not A or B.\n\nlemma two_in_C : (-2 : \u211d) \u2208 C :=\nbegin\n  unfold C,\n  norm_num,\nend\n\nlemma two_not_in_A : (-2:real) \u2209 A :=\nbegin\n  unfold A,norm_num\nend\n\nlemma two_not_in_B : (-2:real) \u2209 B :=\nbegin\n  unfold B,norm_num,\nend\n\ntheorem part_e : \u00ac (C \u2286 A \u222a B) := -- not true as C contains -2\nbegin\n  let x:=(-2:real),\n  have HC : x \u2208 C,\n    exact two_in_C,\n  have HnA : x \u2209 A,\n    exact two_not_in_A,\n  have HnB : x \u2209 B,\n    exact two_not_in_B,\n  intro H,\n  have H2 : x \u2208 (A \u222a B),\n    exact H HC,\n  cases H2 with HA HB,\n    contradiction,\n    contradiction,\nend\n\ntheorem part_f : \u00ac ((A \u2229 B) \u222a C = (A \u222a B) \u2229 C) :=\nbegin\nlet x:=(-2:real),\nhave HC : x \u2208 C,\n  exact two_in_C,\nhave HnA : x \u2209 A,\n  exact two_not_in_A,\nhave HnB : x \u2209 B,\n  exact two_not_in_B,\nintro H,\nhave H1 : x \u2208 ((A \u2229 B) \u222a C),\n  right,exact HC,\nhave H2 : x \u2208 (A \u222a B) \u2229 C,\n  rw \u2190H,\n  exact H1,\nhave H3 : x \u2208 (A \u222a B),\n  exact H2.left,\ncases H3 with HA HB,\n  contradiction,\n  contradiction,\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "xena-UROP-2018", "sha": "b111fb87f343cf79eca3b886f99ee15c1dd9884b", "save_path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018", "path": "github-repos/lean/ImperialCollegeLondon-xena-UROP-2018/xena-UROP-2018-b111fb87f343cf79eca3b886f99ee15c1dd9884b/src/M1F/problem_bank/0107/M1F_sheet01_solution07.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.7003468687886044}}
{"text": "import tactic -- hide\nimport data.real.basic -- hide\n\n/-\n## Some more on `cases`\n\nThere is another application of the swiss-army knife `cases`. If we have `h : \u2203 x, P x`, then sometimes we want to have\na witness for such an $x$. There are possibly many choices for such an $x$, but we\nwill just get one. When one does `cases h with x hx`, there will be a new value `x`\nadded to the list of \"hypotheses\", and the fact `hx : P x` for us to use.\n-/\n\n/- Lemma : no-side-bar\nIf we have $\\sqrt{2}$ then we also have $\\sqrt{8}$.\n-/\nlemma c3 (h : \u2203 (x : \u211d), x^2 = 2) : \u2203 (x : \u211d), x^2 = 8 :=\nbegin\ncases h with r hr,\nuse 2 * r,\nrw show (2 * r) ^ 2 = 2^2 * r^2, by ring,\nrw hr,\nring,\n\n  \n\n\nend", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/tactics_world/08_cases3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.700346859756141}}
{"text": "/-\nCopyright (c) 2021 Ashvni Narayanan. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ashvni Narayanan\n-/\n\nimport number_theory.bernoulli\n\n/-!\n# Bernoulli polynomials\n\nThe Bernoulli polynomials (defined here : https://en.wikipedia.org/wiki/Bernoulli_polynomials)\nare an important tool obtained from Bernoulli numbers.\n\n## Mathematical overview\n\nThe $n$-th Bernoulli polynomial is defined as\n$$ B_n(X) = \u2211_{k = 0}^n {n \\choose k} (-1)^k * B_k * X^{n - k} $$\nwhere $B_k$ is the $k$-th Bernoulli number. The Bernoulli polynomials are generating functions,\n$$ t * e^{tX} / (e^t - 1) = \u2211_{n = 0}^{\\infty} B_n(X) * \\frac{t^n}{n!} $$\n\n## Implementation detail\n\nBernoulli polynomials are defined using `bernoulli`, the Bernoulli numbers.\n\n## Main theorems\n\n- `sum_bernoulli_poly`: The sum of the $k^\\mathrm{th}$ Bernoulli polynomial with binomial\n  coefficients up to n is `(n + 1) * X^n`.\n- `exp_bernoulli_poly`: The Bernoulli polynomials act as generating functions for the exponential.\n\n## TODO\n\n- `bernoulli_poly_eval_one_neg` : $$ B_n(1 - x) = (-1)^n*B_n(x) $$\n- ``bernoulli_poly_eval_one` : Follows as a consequence of `bernoulli_poly_eval_one_neg`.\n\n-/\n\nnoncomputable theory\nopen_locale big_operators\nopen_locale nat\n\nopen nat finset\n\n/-- The Bernoulli polynomials are defined in terms of the negative Bernoulli numbers. -/\ndef bernoulli_poly (n : \u2115) : polynomial \u211a :=\n  \u2211 i in range (n + 1), polynomial.monomial (n - i) ((bernoulli i) * (choose n i))\n\nlemma bernoulli_poly_def (n : \u2115) : bernoulli_poly n =\n  \u2211 i in range (n + 1), polynomial.monomial i ((bernoulli (n - i)) * (choose n i)) :=\nbegin\n  rw [\u2190sum_range_reflect, add_succ_sub_one, add_zero, bernoulli_poly],\n  apply sum_congr rfl,\n  rintros x hx,\n  rw mem_range_succ_iff at hx, rw [choose_symm hx, nat.sub_sub_self hx],\nend\n\nnamespace bernoulli_poly\n\n/-\n### examples\n-/\n\nsection examples\n\n@[simp] lemma bernoulli_poly_zero : bernoulli_poly 0 = 1 :=\nby simp [bernoulli_poly]\n\n@[simp] lemma bernoulli_poly_eval_zero (n : \u2115) : (bernoulli_poly n).eval 0 = bernoulli n :=\nbegin\n rw [bernoulli_poly, polynomial.eval_finset_sum, sum_range_succ],\n  have : \u2211 (x : \u2115) in range n, bernoulli x * (n.choose x) * 0 ^ (n - x) = 0,\n  { apply sum_eq_zero (\u03bb x hx, _),\n    have h : 0 < n - x := nat.sub_pos_of_lt (mem_range.1 hx),\n    simp [h] },\n  simp [this],\nend\n\n@[simp] lemma bernoulli_poly_eval_one (n : \u2115) : (bernoulli_poly n).eval 1 = bernoulli' n :=\nbegin\n  simp only [bernoulli_poly, polynomial.eval_finset_sum],\n  simp only [\u2190succ_eq_add_one, sum_range_succ, mul_one, cast_one, choose_self,\n    (bernoulli _).mul_comm, sum_bernoulli, one_pow, mul_one, polynomial.eval_C,\n    polynomial.eval_monomial],\n  by_cases h : n = 1,\n  { norm_num [h], },\n  { simp [h],\n    exact bernoulli_eq_bernoulli'_of_ne_one h, }\nend\n\nend examples\n\n@[simp] theorem sum_bernoulli_poly (n : \u2115) :\n  \u2211 k in range (n + 1), ((n + 1).choose k : \u211a) \u2022 bernoulli_poly k =\n    polynomial.monomial n (n + 1 : \u211a) :=\nbegin\n simp_rw [bernoulli_poly_def, finset.smul_sum, finset.range_eq_Ico, \u2190finset.sum_Ico_Ico_comm,\n    finset.sum_Ico_eq_sum_range],\n  simp only [cast_succ, nat.add_sub_cancel_left, nat.sub_zero, zero_add, linear_map.map_add],\n  simp_rw [polynomial.smul_monomial, mul_comm (bernoulli _) _, smul_eq_mul, \u2190mul_assoc],\n  conv_lhs { apply_congr, skip, conv\n    { apply_congr, skip,\n      rw [choose_mul ((nat.le_sub_left_iff_add_le (mem_range_le H)).1 (mem_range_le H_1))\n        (le.intro rfl), add_comm x x_1, nat.add_sub_cancel, mul_assoc, mul_comm, \u2190smul_eq_mul,\n        \u2190polynomial.smul_monomial], },\n    rw [\u2190sum_smul], },\n  rw [sum_range_succ_comm],\n  simp only [add_right_eq_self, cast_succ, mul_one, cast_one, cast_add, nat.add_sub_cancel_left,\n    choose_succ_self_right, one_smul, bernoulli_zero, sum_singleton, zero_add,\n    linear_map.map_add, range_one],\n  apply sum_eq_zero (\u03bb x hx, _),\n  have f : \u2200 x \u2208 range n, \u00ac n + 1 - x = 1,\n  { rintros x H, rw [mem_range] at H,\n    rw [eq_comm],\n    exact ne_of_lt (nat.lt_of_lt_of_le one_lt_two (nat.le_sub_left_of_add_le (succ_le_succ H))),\n  },\n  rw [sum_bernoulli],\n  have g : (ite (n + 1 - x = 1) (1 : \u211a) 0) = 0,\n    { simp only [ite_eq_right_iff, one_ne_zero],\n      intro h\u2081,\n      exact (f x hx) h\u2081, },\n  rw [g, zero_smul],\nend\n\nopen power_series\nopen polynomial (aeval)\nvariables {A : Type*} [comm_ring A] [algebra \u211a A]\n\n-- TODO: define exponential generating functions, and use them here\n-- This name should probably be updated afterwards\n\n/-- The theorem that `\u2211 B\u2099(t)X^n/n!)(e^X-1)=Xe^{tX}`  -/\ntheorem exp_bernoulli_poly' (t : A) :\n  mk (\u03bb n, aeval t ((1 / n! : \u211a) \u2022 bernoulli_poly n)) * (exp A - 1) = X * rescale t (exp A) :=\nbegin\n  -- check equality of power series by checking coefficients of X^n\n  ext n,\n  -- n = 0 case solved by `simp`\n  cases n, { simp },\n  -- n \u2265 1, the coefficients is a sum to n+2, so use `sum_range_succ` to write as\n  -- last term plus sum to n+1\n  rw [coeff_succ_X_mul, coeff_rescale, coeff_exp, coeff_mul,\n    nat.sum_antidiagonal_eq_sum_range_succ_mk, sum_range_succ],\n  -- last term is zero so kill with `add_zero`\n  simp only [ring_hom.map_sub, nat.sub_self, constant_coeff_one, constant_coeff_exp,\n    coeff_zero_eq_constant_coeff, mul_zero, sub_self, add_zero],\n  -- Let's multiply both sides by (n+1)! (OK because it's a unit)\n  set u : units \u211a := \u27e8(n+1)!, (n+1)!\u207b\u00b9,\n    mul_inv_cancel (by exact_mod_cast factorial_ne_zero (n+1)),\n      inv_mul_cancel (by exact_mod_cast factorial_ne_zero (n+1))\u27e9 with hu,\n  rw \u2190units.mul_right_inj (units.map (algebra_map \u211a A).to_monoid_hom u),\n  -- now tidy up unit mess and generally do trivial rearrangements\n  -- to make RHS (n+1)*t^n\n  rw [units.coe_map, mul_left_comm, ring_hom.to_monoid_hom_eq_coe,\n      ring_hom.coe_monoid_hom, \u2190ring_hom.map_mul, hu, units.coe_mk],\n  change _ = t^n * algebra_map \u211a A (((n+1)*n! : \u2115)*(1/n!)),\n  rw [cast_mul, mul_assoc, mul_one_div_cancel\n    (show (n! : \u211a) \u2260 0, from cast_ne_zero.2 (factorial_ne_zero n)), mul_one, mul_comm (t^n),\n    \u2190 polynomial.aeval_monomial, cast_add, cast_one],\n  -- But this is the RHS of `sum_bernoulli_poly`\n  rw [\u2190 sum_bernoulli_poly, finset.mul_sum, alg_hom.map_sum],\n  -- and now we have to prove a sum is a sum, but all the terms are equal.\n  apply finset.sum_congr rfl,\n  -- The rest is just trivialities, hampered by the fact that we're coercing\n  -- factorials and binomial coefficients between \u2115 and \u211a and A.\n  intros i hi,\n  -- NB prime.choose_eq_factorial_div_factorial' is in the wrong namespace\n  -- deal with coefficients of e^X-1\n  simp only [choose_eq_factorial_div_factorial' (mem_range_le hi), coeff_mk,\n    if_neg (mem_range_sub_ne_zero hi), one_div, alg_hom.map_smul, coeff_one, units.coe_mk,\n    coeff_exp, sub_zero, linear_map.map_sub, algebra.smul_mul_assoc, algebra.smul_def,\n    mul_right_comm _ ((aeval t) _), \u2190mul_assoc, \u2190 ring_hom.map_mul, succ_eq_add_one],\n  -- finally cancel the Bernoulli polynomial and the algebra_map\n  congr',\n  apply congr_arg,\n  rw [mul_assoc, div_eq_mul_inv, \u2190 mul_inv'],\nend\n\nend bernoulli_poly\n", "meta": {"author": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/number_theory/bernoulli_polynomials.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072387, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7003456853744237}}
{"text": "import algebra.comm_rings.instances.basic\n\ninductive pos_nat \n| one  : pos_nat\n| succ : pos_nat \u2192 pos_nat\n\nnotation `\u2115\u207a` := pos_nat\n\ndef pos_nat_add : \u2115\u207a \u2192 \u2115\u207a \u2192 \u2115\u207a \n| pos_nat.one n      := pos_nat.succ n\n| (pos_nat.succ k) n := pos_nat.succ (pos_nat_add k n)\n\ninstance pos_nat_has_one : has_one \u2115\u207a := \u27e8pos_nat.one\u27e9\ninstance pos_nat_has_add : has_add \u2115\u207a := \u27e8pos_nat_add\u27e9   \n\ndef pos_nat_mul : \u2115\u207a \u2192 \u2115\u207a \u2192 \u2115\u207a \n| (1:\u2115\u207a) n           := n\n| (pos_nat.succ k) n := n + (pos_nat_mul k n)\n\ninstance pos_nat_has_mul : has_mul \u2115\u207a := \u27e8pos_nat_mul\u27e9\n\ntheorem pos_nat_mul_suc : \u2200 n m : \u2115\u207a, (pos_nat.succ n) * m = m + (n * m) := \u03bb _ _, rfl\n\ntheorem pos_nat.one_mul : \u2200 n : \u2115\u207a, pos_nat.one * n = n := \u03bb _,rfl\ntheorem pos_nat.one_mul\u2081 : \u2200 n : \u2115\u207a , 1 * n = n := \u03bb _, rfl\n\ndef pos_nat_to_nat : \u2115\u207a \u2192 \u2115 \n| pos_nat.one      := 1\n| (pos_nat.succ k) := nat.succ (pos_nat_to_nat k) \n\ndef pot_nat_to_int :  \u2115\u207a \u2192 \u2124 \n| 1       := int.of_nat 1 \n| (1 + n) := 1 + pot_nat_to_int n \n\ntheorem pos_nat_to_nat_never_zero : \u2200 n : \u2115\u207a, pos_nat_to_nat n \u2260 0 :=\nbegin\n  intros n ab,\n  cases n with n,\n  cases ab,\n  cases ab,\nend\n\ntheorem pos_nat_to_nat_inj : \u2200 {n\u2081 n\u2082 : \u2115\u207a}, pos_nat_to_nat n\u2081 = pos_nat_to_nat n\u2082 \u2192 n\u2081 = n\u2082 \n| pos_nat.one pos_nat.one _ := rfl\n| (pos_nat.succ n) pos_nat.one h := \n  begin\n    apply false.elim,\n    apply pos_nat_to_nat_never_zero n,\n    apply nat.succ.inj,\n    assumption,\n  end\n| pos_nat.one (pos_nat.succ n) h :=\n  begin\n    apply false.elim,\n    apply pos_nat_to_nat_never_zero n,\n    apply nat.succ.inj,\n    symmetry,\n    assumption,\n  end\n| (pos_nat.succ n\u2081) (pos_nat.succ n\u2082) h :=\n  begin\n    have hrw : n\u2081 = n\u2082,\n      apply pos_nat_to_nat_inj,\n      apply nat.succ.inj,\n      assumption,\n    rw hrw,\n  end\n\ninstance pos_nat_coe : has_coe \u2115\u207a \u2124 := \u27e8pot_nat_to_int\u27e9\n\n@[simp]\ntheorem coe_pos_one : \u2191(pos_nat.one) = (1:\u2124) := rfl\n\n@[simp]\ntheorem coe_pos_one\u2081 : \u2191(1:\u2115\u207a) = (1:\u2124) := rfl\n\n@[simp]\ntheorem coe_pos_suc : \u2200 n : \u2115\u207a, \u2191(pos_nat.succ n) = (1 + \u2191n : \u2124) := \u03bb _, rfl\n\ntheorem pos_nat_nat_coor : \u2200 n : \u2115\u207a, \u2203 m : \u2115, \u2191n = int.of_nat m :=\nbegin\n  intro n,\n  induction n with n hn,\n  existsi 1,\n  refl,\n  cases hn with m hm,\n  existsi nat.succ m,\n  simp[hm,int.of_nat_succ,int.add_comm],\nend\n\ntheorem strong_pos_nat_nat_coor : \u2200 n : \u2115\u207a, \u2191n = int.of_nat (pos_nat_to_nat n) :=\nbegin\n  intro n,\n  induction n with n hn,\n  refl,\n  simp[hn],\n  have trv : pos_nat_to_nat n.succ = (pos_nat_to_nat n).succ := rfl, \n  simp [trv,int.of_nat_succ,int.add_comm],\nend\n\n@[simp]\ntheorem coe_prevs_add : \u2200 n\u2081 n\u2082 : \u2115\u207a, (\u2191(n\u2081 + n\u2082) : \u2124) = \u2191n\u2081 + \u2191n\u2082 :=\nbegin\n  intros n\u2081 n\u2082,\n  induction n\u2081 with n\u2081 hn\u2081,\n  have trv : pos_nat.one + n\u2082 = n\u2082.succ := rfl,\n  simp[trv],\n  have trv : n\u2081.succ + n\u2082 = (n\u2081 + n\u2082).succ := rfl,\n  simp[trv,hn\u2081,int.add_assoc],\nend\n\n@[simp]\ntheorem coe_prevs_mul : \u2200 n\u2081 n\u2082 : \u2115\u207a, (\u2191(n\u2081 * n\u2082) : \u2124) = \u2191n\u2081 * \u2191n\u2082 :=\nbegin\n  intros n\u2081 n\u2082,\n  induction n\u2081 with n\u2081 hn\u2081,\n  simp [pos_nat.one_mul, int.one_mul],\n  simp[int.distrib_right, int.one_mul],\n  have trv : n\u2081.succ * n\u2082 = n\u2082 + n\u2081 * n\u2082 := rfl,\n  simp[trv,coe_prevs_add, hn\u2081],\nend\n\ntheorem coe_inj : \u2200 n\u2081 n\u2082 : \u2115\u207a, (\u2191n\u2081 : \u2124) = \u2191n\u2082 \u2192 n\u2081 = n\u2082 :=\nbegin\n  intros n\u2081 n\u2082,\n  simp[strong_pos_nat_nat_coor],\n  intro h,\n  apply pos_nat_to_nat_inj,\n  assumption,\nend \n\ntheorem mul_zero_eq_zero : \u2200 {z : \u2124} (n : \u2115\u207a), z * n = 0 \u2192 z = 0 :=\nbegin\n  intros z n h,\n  cases z with m m,\n  cases m,\n  refl,\n  apply false.elim,\n  rw int.of_nat_succ at h,\n  rw int.distrib_right at h,\n  rw int.one_mul at h,\n  cases n,\n  simp[int.mul_one] at h,\n  rw \u2190 int.of_nat_succ at h,\n  cases h,\n  cases pos_nat_nat_coor n with c hc,\n  simp [hc,int.distrib_left,int.mul_one] at h,\n  rw [\u2190 int.of_nat_mul, \u2190 int.of_nat_add, int.add_comm 1] at h,\n  rw [\u2190 int.add_assoc,\u2190 int.of_nat_add,\u2190 int.of_nat_succ] at h,\n  cases h,\n  cases n,\n  simp[int.mul_one] at h,\n  assumption,\n  simp[int.distrib_left] at h,\n  rw int.mul_one at h,\n  cases pos_nat_nat_coor n with c hc,\n  simp[hc] at h,\n  have hrw : -[1+ m] * int.of_nat c = int.neg_of_nat (nat.succ m * c) := rfl,\n  rw hrw at h, \n  cases c,\n  rw nat.mul_zero m.succ at h,\n  simp[int.neg_of_nat,int.add_zero] at h,\n  assumption,\n  simp [nat.mul_succ,nat.add_succ,int.neg_of_nat] at h,\n  have trv : \u2200 m\u2081 m\u2082,  -[1+ m\u2081] + -[1+ m\u2082] = -[1+ nat.succ (m\u2081 + m\u2082)] := \u03bb _ _, rfl,\n  simp[trv] at h,\n  apply false.elim,\n  cases h,\nend \n\nlemma pos_nat_mul_right_cancel : \u2200 {z\u2081 z\u2082: \u2124} (n : \u2115\u207a), z\u2081 * n = z\u2082 * n  \u2192 z\u2081 = z\u2082 :=\nbegin\n  intros z\u2081 z\u2082 n h,\n  have hrw : z\u2081 + -z\u2082 = 0,\n    apply mul_zero_eq_zero n,\n    rw [int.distrib_right, h,\u2190 comm_ring.minus_mul],\n    rw comm_ring.minus_inverse,\n    exact calc z\u2081 = z\u2081 + 0          : by rw int.add_zero z\u2081\n              ... = z\u2081 + (z\u2082 + -z\u2082) : by rw comm_ring.minus_inverse\n              ... = z\u2081 + (-z\u2082 + z\u2082) : by rw int.add_comm z\u2082\n              ... = (z\u2081 + -z\u2082) + z\u2082 : by simp[int.add_assoc]\n              ... = 0 + z\u2082          : by rw hrw\n              ... = z\u2082              : by rw int.zero_add,\nend", "meta": {"author": "CameronTorrance", "repo": "Schemes", "sha": "f407ce80b8407101231170680b03b55984c42496", "save_path": "github-repos/lean/CameronTorrance-Schemes", "path": "github-repos/lean/CameronTorrance-Schemes/Schemes-f407ce80b8407101231170680b03b55984c42496/src/misc/rationals/pos_nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.7003456750181059}}
{"text": "/-\nCopyright (c) 2022 David Kurniadi Angdinata. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Kurniadi Angdinata\n-/\nimport algebra.hom.equiv.type_tags\nimport data.zmod.quotient\nimport ring_theory.dedekind_domain.adic_valuation\nimport ring_theory.norm\n\n/-!\n# Selmer groups of fraction fields of Dedekind domains\n\nLet $K$ be the field of fractions of a Dedekind domain $R$. For any set $S$ of prime ideals in the\nheight one spectrum of $R$, and for any natural number $n$, the Selmer group $K(S, n)$ is defined to\nbe the subgroup of the unit group $K^\\times$ modulo $n$-th powers where each element has $v$-adic\nvaluation divisible by $n$ for all prime ideals $v$ away from $S$. In other words, this is precisely\n$$ K(S, n) := \\{x(K^\\times)^n \\in K^\\times / (K^\\times)^n \\ \\mid \\\n                \\forall v \\notin S, \\ \\mathrm{ord}_v(x) \\equiv 0 \\pmod n\\}. $$\n\nThere is a fundamental short exact sequence\n$$ 1 \\to R_S^\\times / (R_S^\\times)^n \\to K(S, n) \\to \\mathrm{Cl}_S(R)[n] \\to 0, $$\nwhere $R_S^\\times$ is the $S$-unit group of $R$ and $\\mathrm{Cl}_S(R)$ is the $S$-class group of\n$R$. If the flanking groups are both finite, then $K(S, n)$ is finite by the first isomorphism\ntheorem. Such is the case when $R$ is the ring of integers of a number field $K$, $S$ is finite, and\n$n$ is positive, in which case $R_S^\\times$ is finitely generated by Dirichlet's unit theorem and\n$\\mathrm{Cl}_S(R)$ is finite by the class number theorem.\n\nThis file defines the Selmer group $K(S, n)$ and some basic facts.\n\n## Main definitions\n\n * `is_dedekind_domain.selmer_group`: the Selmer group.\n * TODO: maps in the sequence.\n\n## Main statements\n\n * TODO: proofs of exactness of the sequence.\n * TODO: proofs of finiteness for global fields.\n\n## Notations\n\n * `K\u27eeS, n\u27ef`: the Selmer group with parameters `K`, `S`, and `n`.\n\n## Implementation notes\n\nThe Selmer group is typically defined as a subgroup of the Galois cohomology group $H^1(K, \\mu_n)$\nwith certain local conditions defined by $v$-adic valuations, where $\\mu_n$ is the group of $n$-th\nroots of unity over a separable closure of $K$. Here $H^1(K, \\mu_n)$ is identified with\n$K^\\times / (K^\\times)^n$ by the long exact sequence from Kummer theory and Hilbert's theorem 90,\nand the fundamental short exact sequence becomes an easy consequence of the snake lemma. This file\nwill define all the maps explicitly for computational purposes, but isomorphisms to the Galois\ncohomological definition will be provided when possible.\n\n## References\n\nhttps://doc.sagemath.org/html/en/reference/number_fields/sage/rings/number_field/selmer_group.html\n\n## Tags\n\nclass group, selmer group, unit group\n-/\n\nlocal notation (name := quot) K/n := K\u02e3 \u29f8 (pow_monoid_hom n : K\u02e3 \u2192* K\u02e3).range\n\nnamespace is_dedekind_domain\n\nnoncomputable theory\n\nopen_locale classical discrete_valuation non_zero_divisors\n\nuniverses u v\n\nvariables {R : Type u} [comm_ring R] [is_domain R] [is_dedekind_domain R] {K : Type v} [field K]\n  [algebra R K] [is_fraction_ring R K] (v : height_one_spectrum R)\n\n/-! ### Valuations of non-zero elements -/\n\nnamespace height_one_spectrum\n\n/-- The multiplicative `v`-adic valuation on `K\u02e3`. -/\ndef valuation_of_ne_zero_to_fun (x : K\u02e3) : multiplicative \u2124 :=\nlet hx := is_localization.sec R\u2070 (x : K) in multiplicative.of_add $\n  (-(associates.mk v.as_ideal).count (associates.mk $ ideal.span {hx.fst}).factors : \u2124)\n  - (-(associates.mk v.as_ideal).count (associates.mk $ ideal.span {(hx.snd : R)}).factors : \u2124)\n\n@[simp] lemma valuation_of_ne_zero_to_fun_eq (x : K\u02e3) :\n  (v.valuation_of_ne_zero_to_fun x : \u2124\u2098\u2080) = v.valuation (x : K) :=\nbegin\n  change _ = _ * _,\n  rw [units.coe_inv],\n  change _ = ite _ _ _ * (ite (coe _ = _) _ _)\u207b\u00b9,\n  rw [is_localization.to_localization_map_sec,\n      if_neg $ is_localization.sec_fst_ne_zero le_rfl x.ne_zero,\n      if_neg $ non_zero_divisors.coe_ne_zero _],\n  any_goals { exact is_domain.to_nontrivial R },\n  refl\nend\n\n/-- The multiplicative `v`-adic valuation on `K\u02e3`. -/\ndef valuation_of_ne_zero : K\u02e3 \u2192* multiplicative \u2124 :=\n{ to_fun   := v.valuation_of_ne_zero_to_fun,\n  map_one' := by { rw [\u2190 with_zero.coe_inj, valuation_of_ne_zero_to_fun_eq], exact map_one _ },\n  map_mul' := \u03bb _ _, by { rw [\u2190 with_zero.coe_inj, with_zero.coe_mul],\n                          simp only [valuation_of_ne_zero_to_fun_eq], exact map_mul _ _ _ } }\n\n@[simp] lemma valuation_of_ne_zero_eq (x : K\u02e3) :\n  (v.valuation_of_ne_zero x : \u2124\u2098\u2080) = v.valuation (x : K) :=\nvaluation_of_ne_zero_to_fun_eq v x\n\n@[simp] lemma valuation_of_unit_eq (x : R\u02e3) :\n  v.valuation_of_ne_zero (units.map (algebra_map R K : R \u2192* K) x) = 1 :=\nbegin\n  rw [\u2190 with_zero.coe_inj, valuation_of_ne_zero_eq, units.coe_map, eq_iff_le_not_lt],\n  split,\n  { exact v.valuation_le_one x },\n  { cases x with x _ hx _,\n    change \u00acv.valuation (algebra_map R K x) < 1,\n    apply_fun v.int_valuation at hx,\n    rw [map_one, map_mul] at hx,\n    rw [not_lt, \u2190 hx, \u2190 mul_one $ v.valuation _, valuation_of_algebra_map,\n        mul_le_mul_left\u2080 $ left_ne_zero_of_mul_eq_one hx],\n    exact v.int_valuation_le_one _ }\nend\n\nlocal attribute [semireducible] mul_opposite\n\n/-- The multiplicative `v`-adic valuation on `K\u02e3` modulo `n`-th powers. -/\ndef valuation_of_ne_zero_mod (n : \u2115) : K/n \u2192* multiplicative (zmod n) :=\n(int.quotient_zmultiples_nat_equiv_zmod n).to_multiplicative.to_monoid_hom.comp $\n  quotient_group.map (pow_monoid_hom n : K\u02e3 \u2192* K\u02e3).range\n  (add_subgroup.zmultiples (n : \u2124)).to_subgroup v.valuation_of_ne_zero\nbegin\n  rintro _ \u27e8x, rfl\u27e9,\n  exact \u27e8v.valuation_of_ne_zero x, by simpa only [pow_monoid_hom_apply, map_pow, int.to_add_pow]\u27e9\nend\n\n@[simp] lemma valuation_of_unit_mod_eq (n : \u2115) (x : R\u02e3) :\n  v.valuation_of_ne_zero_mod n (units.map (algebra_map R K : R \u2192* K) x : K/n) = 1 :=\nby rw [valuation_of_ne_zero_mod, monoid_hom.comp_apply, \u2190 quotient_group.coe_mk',\n       quotient_group.map_mk', valuation_of_unit_eq, quotient_group.coe_one, map_one]\n\nend height_one_spectrum\n\n/-! ### Selmer groups -/\n\nvariables {S S' : set $ height_one_spectrum R} {n : \u2115}\n\n/-- The Selmer group `K\u27eeS, n\u27ef`. -/\ndef selmer_group : subgroup $ K/n :=\n{ carrier  := {x : K/n | \u2200 v \u2209 S, (v : height_one_spectrum R).valuation_of_ne_zero_mod n x = 1},\n  one_mem' := \u03bb _ _, by rw [map_one],\n  mul_mem' := \u03bb _ _ hx hy v hv, by rw [map_mul, hx v hv, hy v hv, one_mul],\n  inv_mem' := \u03bb _ hx v hv, by rw [map_inv, hx v hv, inv_one] }\n\nlocalized \"notation K`\u27ee`S, n`\u27ef` := @selmer_group _ _ _ _ K _ _ _ S n\" in selmer_group\n\nnamespace selmer_group\n\nlemma monotone (hS : S \u2264 S') : K\u27eeS, n\u27ef \u2264 (K\u27eeS', n\u27ef) := \u03bb _ hx v, hx v \u2218 mt (@hS v)\n\n/-- The multiplicative `v`-adic valuations on `K\u27eeS, n\u27ef` for all `v \u2208 S`. -/\ndef valuation : K\u27eeS, n\u27ef \u2192* S \u2192 multiplicative (zmod n) :=\n{ to_fun   := \u03bb x v, (v : height_one_spectrum R).valuation_of_ne_zero_mod n (x : K/n),\n  map_one' := funext $ \u03bb v, map_one _,\n  map_mul' := \u03bb x y, funext $ \u03bb v, map_mul _ x y }\n\nlemma valuation_ker_eq :\n  valuation.ker = (K\u27ee(\u2205 : set $ height_one_spectrum R), n\u27ef).subgroup_of (K\u27eeS, n\u27ef) :=\nbegin\n  ext \u27e8_, hx\u27e9,\n  split,\n  { intros hx' v _,\n    by_cases hv : v \u2208 S,\n    { exact congr_fun hx' \u27e8v, hv\u27e9 },\n    { exact hx v hv } },\n  { exact \u03bb hx', funext $ \u03bb v, hx' v $ set.not_mem_empty v }\nend\n\n/-- The natural homomorphism from `R\u02e3` to `K\u27ee\u2205, n\u27ef`. -/\ndef from_unit {n : \u2115} : R\u02e3 \u2192* K\u27ee(\u2205 : set $ height_one_spectrum R), n\u27ef :=\n{ to_fun   := \u03bb x, \u27e8quotient_group.mk $ units.map (algebra_map R K).to_monoid_hom x,\n                    \u03bb v _, v.valuation_of_unit_mod_eq n x\u27e9,\n  map_one' := by simpa only [map_one],\n  map_mul' := \u03bb _ _, by simpa only [map_mul] }\n\nlemma from_unit_ker [hn : fact $ 0 < n] :\n  (@from_unit R _ _ _ K _ _ _ n).ker = (pow_monoid_hom n : R\u02e3 \u2192* R\u02e3).range :=\nbegin\n  ext \u27e8_, _, _, _\u27e9,\n  split,\n  { intro hx,\n    rcases (quotient_group.eq_one_iff _).mp (subtype.mk.inj hx) with \u27e8\u27e8v, i, vi, iv\u27e9, hx\u27e9,\n    have hv : \u2191(_ ^ n : K\u02e3) = algebra_map R K _ := congr_arg units.val hx,\n    have hi : \u2191(_ ^ n : K\u02e3)\u207b\u00b9 = algebra_map R K _ := congr_arg units.inv hx,\n    rw [units.coe_pow] at hv,\n    rw [\u2190 inv_pow, units.inv_mk, units.coe_pow] at hi,\n    rcases @is_integrally_closed.exists_algebra_map_eq_of_is_integral_pow R _ _ _ _ _ _ _ v _\n      hn.out (hv.symm \u25b8 is_integral_algebra_map) with \u27e8v', rfl\u27e9,\n    rcases @is_integrally_closed.exists_algebra_map_eq_of_is_integral_pow R _ _ _ _ _ _ _ i _\n      hn.out (hi.symm \u25b8 is_integral_algebra_map) with \u27e8i', rfl\u27e9,\n    rw [\u2190 map_mul, map_eq_one_iff _ $ no_zero_smul_divisors.algebra_map_injective R K] at vi,\n    rw [\u2190 map_mul, map_eq_one_iff _ $ no_zero_smul_divisors.algebra_map_injective R K] at iv,\n    rw [units.coe_mk, \u2190 map_pow] at hv,\n    exact \u27e8\u27e8v', i', vi, iv\u27e9, by simpa only [units.ext_iff, pow_monoid_hom_apply, units.coe_pow]\n                               using no_zero_smul_divisors.algebra_map_injective R K hv\u27e9 },\n  { rintro \u27e8_, hx\u27e9,\n    rw [\u2190 hx],\n    exact subtype.mk_eq_mk.mpr\n      ((quotient_group.eq_one_iff _).mpr \u27e8_, by simp only [pow_monoid_hom_apply, map_pow]\u27e9) }\nend\n\n/-- The injection induced by the natural homomorphism from `R\u02e3` to `K\u27ee\u2205, n\u27ef`. -/\ndef from_unit_lift [fact $ 0 < n] : R/n \u2192* K\u27ee(\u2205 : set $ height_one_spectrum R), n\u27ef :=\n(quotient_group.ker_lift _).comp\n  (quotient_group.quotient_mul_equiv_of_eq from_unit_ker).symm.to_monoid_hom\n\nlemma from_unit_lift_injective [fact $ 0 < n] :\n  function.injective $ @from_unit_lift R _ _ _ K _ _ _ n _ :=\nfunction.injective.comp (quotient_group.ker_lift_injective _) (mul_equiv.injective _)\n\nend selmer_group\n\nend is_dedekind_domain\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/dedekind_domain/selmer_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856559, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7003181305571353}}
{"text": "import SciLean.Core\nimport SciLean.Functions.Limit\nimport SciLean.Functions.OdeSolve\n\n\nnamespace SciLean\n\n/-- Solution of differential-algebraic equation in fully implicit form:\n`\n  \u2200 t, 0 = f t (\u2146 x t) (x t)\n`\n\n-/\nnoncomputable\ndef odeSolveFullyImplicit {X Y} [Vec X] [Vec Y] (f : \u211d \u2192 X \u2192 X \u2192 Y) (t : \u211d) (x\u2080 v\u2080 : X) : X :=\n  let solution_exists := \u2203 (x : \u211d \u2192 X) (_ : IsSmooth x),\n      \u2200 t, 0 = f t (\u2146 x t) (x t)\n      \u2227\n      x 0 = x\u2080 \u2227 \u2146 x 0 = v\u2080\n  match Classical.dec solution_exists with\n  | isFalse _ => 0\n  | isTrue h =>\n    let x := Classical.choose h\n    x t\n\n\nnoncomputable\ndef odeSolveSemiImplicit {X Y} [Vec X] [Vec Y]\n  (f : \u211d \u2192 X \u2192 Y \u2192 X) (g : \u211d \u2192 X \u2192 Y \u2192 Y)\n  (t : \u211d) (x\u2080 : X) (y\u2080 : Y)\n  : X \u00d7 Y :=\n  let solution_exists := \u2203 (x : \u211d \u2192 X) (y : \u211d \u2192 Y) (_ : IsSmooth x) (_ : IsSmooth y),\n      \u2200 t, (\u2146 x t = f t (x t) (y t) \u2227\n            0 = g t (x t) (y t))\n      \u2227\n      x 0 = x\u2080 \u2227 y 0 = y\u2080\n  match Classical.dec solution_exists with\n  | isFalse _ => 0\n  | isTrue h =>\n    let x := Classical.choose h\n    let y := Classical.choose (Classical.choose_spec h)\n    (x t, y t)\n\n\n/--\n  Semi-implicit ODE can be rewriten as a normal ODE if the constrain has invertible jacobian in `y`\n-/\ntheorem odeSolveSemiImplicit_as_odeSolve {X Y} [Vec X] [Vec Y]\n  (f : \u211d \u2192 X \u2192 Y \u2192 X) (g : \u211d \u2192 X \u2192 Y \u2192 Y)\n  (t : \u211d) (x\u2080 : X) (y\u2080 : Y)\n  (valid_constraint : \u2200 t x y, IsInv (\u2202 (g t x) y))\n  : \n  odeSolveSemiImplicit f g t x\u2080 y\u2080\n  =\n  let g' t x y :=\n    (\u2202 (g t x) y)\u207b\u00b9 (\u2202 (g t) x (f t x y) y)\n  odeSolve (\u03bb t xy => (f t xy.1 xy.2, g' t xy.1 xy.2)) t (x\u2080,y\u2080)\n  :=\n  sorry_proof\n\n\n/--\n  The idea for this spliting is that we can approximate `y t \u2248 y\u2080 + t * \u0394y`\n  Then the evolution of `x` looks like:\n  \n    `\u2146 x t = f t (x t) (y\u2080 + t * \u0394y)`\n  \n  First order Taylor expansion yieds\n\n    `\u2146 x t = f t (x t) y\u2080 + \u2202 (f t (x t)) y\u2080 (t*\u0394y)`\n\n  By splitting we can alternate between two systems\n\n    `\u2146 x t = f t (x t) y\u2080`\n    and \n    `\u2146 x t = \u2202 (f t (x t)) y\u2080 (t*\u0394y)`\n  \n  The idea is to find such `\u0394y` after one round than the solution satisfies the constraint\n\n-/\ntheorem odeSolveSemiImplicit_evolve_and_project {X Y} [Vec X] [Vec Y]\n  (f : \u211d \u2192 X \u2192 Y \u2192 X) (g : \u211d \u2192 X \u2192 Y \u2192 Y)\n  (\u0394t : \u211d) (x\u2080 : X) (y\u2080 : Y)\n  : \n  odeSolveSemiImplicit f g \u0394t x\u2080 y\u2080\n  =\n  let step (n : \u2115) := \u03bb (x,y) =>\n    let \u0394t' := \u0394t/n\n\n    let x' := odeSolve (f \u00b7 \u00b7 y) \u0394t' x\n \n    -- It is not intirelly clear what the general form of the correction term should look like\n    -- This seems like a good choice\n    let dy := (\u03bb dy => g t (x' + \u0394t'*\u0394t'/2 * \u2202 (f t x') y dy) (y + \u0394t' * dy))\u207b\u00b9 0 \n\n    -- Alternativelly we can minimize the residual insted of doing an exact solve. \n    -- For non-linear problems exact solution might not be possible.\n    -- let \u0394y := argmin \u0394y', \u2225g t (x' + \u0394t' * \u2202 (f t x') y \u0394y') (y + \u0394y')\u2225\u00b2\n\n    (x' + \u0394t'*\u0394t'/2 * \u2202 (f t x') y dy, y + \u0394t' * dy)\n  limit \u03bb n => (step n)^[n] (x\u2080, y\u2080)\n  := sorry_proof\n\n\n/-- Solution of differential equation `\u1e8b = f t x` with a constraint `g t x = 0`. \nThis equates to solving the following semi-implicit differential-algebraic equation:\n`\n  \u2146 x t = f t (x t) + \u2202\u2020 (g t) (x t) \u03bc\n      0 = g t x \n`\nWhere `\u2202\u2020 (g t) (x t) \u03bc` is a modification to the original ODE, with `\u03bc` as a Lagrange multiplier,\nallowing for the solution to satisfy the constraint.\n-/\nnoncomputable \ndef odeSolveConstrained {X Y} [SemiHilbert X] [SemiHilbert Y]\n  (f : \u211d \u2192 X \u2192 X) (g : \u211d \u2192 X \u2192 Y)\n  (t : \u211d) (x\u2080 : X)\n  : X\n  :=\n  (odeSolveSemiImplicit (\u03bb t x \u03bc => f t x + \u2202\u2020 (g t) x \u03bc) (\u03bb t x y => g t x) t x\u2080 0).1\n\nnoncomputable \ndef odeSolveConstrained' {X Y} [SemiHilbert X] [SemiHilbert Y]\n  (f : \u211d \u2192 X \u2192 X) (g : \u211d \u2192 X \u2192 Y)\n  (t : \u211d) (x\u2080 : X) (y\u2080 : Y)\n  : X \u00d7 Y\n  :=\n  (odeSolveSemiImplicit (\u03bb t x y => f t x + \u2202\u2020 (g t) x y) (\u03bb t x _ => g t x) t x\u2080 y\u2080)\n\n\n/-- A constrained ODE is a normal ODE if the constraint is solvable at every time and point. \n\nThe constraint `valid_constraint` is roughly saying that for every time `t` and point `x`:\n  1. We can find the Lagrange multiplier `\u03bc` used to correcly modify the unconstrained ODE\n  2. The jacobian of the constraint function `J := \u2202 (g t) x` has full rank\n  3. The square jacobian of the constraint function, `J := \u2202 (g t) x`, has invertible square i.e. `J \u2218 J\u2020` is invertible matrix\n-/\ntheorem odeSolveConstrained_as_odeSolve {X Y} [SemiHilbert X] [SemiHilbert Y]\n  (f : \u211d \u2192 X \u2192 X) (g : \u211d \u2192 X \u2192 Y) (t\u2080 : \u211d)\n  (valid_constraint : \u2200 t x, let J := \u2202 (g t) x; IsInv (J \u2218 J\u2020))\n  : \n  odeSolveConstrained f g\n  =\n  let solveConstraint t x :=\n    -- let J  := \u2202 (g t) x\n    -- solve \u03bc, J (J\u2020 \u03bc) = - J (f t x)\n    (\u03bb \u03bc => \n      let J := \u2202 (g t) x\n      J (J\u2020 \u03bc) + J (f t x))\u207b\u00b9 0\n  let f' t x :=\n    let \u03bc := solveConstraint t x\n    f t x + \u2202\u2020 (g t) x \u03bc\n  odeSolve f'\n  :=\n  sorry_proof\n\n\n\ntheorem odeSolveConstrained_evolve_and_project {X Y} [SemiHilbert X] [SemiHilbert Y]\n  (f : \u211d \u2192 X \u2192 X) (g : \u211d \u2192 X \u2192 Y) (\u0394t : \u211d) (x\u2080 : X)\n  : \n  odeSolveConstrained f g \u0394t x\u2080\n  =\n  let step (n : \u2115) := \u03bb x =>\n    let \u0394t' := \u0394t/n\n\n    let x' := odeSolve f \u0394t' x\n \n    let y := (\u03bb y => g t (x' + \u0394t' * \u2202\u2020 (g t) x' y))\u207b\u00b9 0 \n\n    x' + \u0394t' * \u2202\u2020 (g t) x y\n\n  limit \u03bb n => (step n)^[n] x\u2080\n  := sorry_proof\n\n\n/-- This is usefull when we want to reuse the Lagrange multiplier `y` from the previous time step -/\ntheorem odeSolveConstrained'_evolve_and_project {X Y} [SemiHilbert X] [SemiHilbert Y]\n  (f : \u211d \u2192 X \u2192 X) (g : \u211d \u2192 X \u2192 Y) (\u0394t : \u211d) (x\u2080 : X) (y\u2080 : Y)\n  : \n  odeSolveConstrained' f g \u0394t x\u2080 y\u2080\n  =\n  let step (n : \u2115) := \u03bb (x,_) =>\n    let \u0394t' := \u0394t/n\n\n    let x' := odeSolve f \u0394t' x\n \n    let y := (\u03bb y => g t (x' + \u0394t' * \u2202\u2020 (g t) x' y))\u207b\u00b9 0 \n\n    (x' + \u0394t' * \u2202\u2020 (g t) x y, y)\n\n  limit \u03bb n => (step n)^[n] (x\u2080,y\u2080)\n  := sorry_proof\n\n\n/-- This is usefull when we want to reuse the Lagrange multiplier `y` from the previous time step -/\ntheorem odeSolveConstrained'_evolve_and_reflect {X Y} [SemiHilbert X] [SemiHilbert Y]\n  (f : \u211d \u2192 X \u2192 X) (g : \u211d \u2192 X \u2192 Y) (\u0394t : \u211d) (x\u2080 : X) (y\u2080 : Y)\n  : \n  odeSolveConstrained' f g \u0394t x\u2080 y\u2080\n  =\n  let step (n : \u2115) := \u03bb (x,_) =>\n    let \u0394t' := \u0394t/n\n\n    let x' := odeSolve f \u0394t' x\n \n    let y := (\u03bb y => g t (x' + \u0394t' * \u2202\u2020 (g t) x' y))\u207b\u00b9 0 \n\n    (x' + \u0394t' * \u2202\u2020 (g t) x y, y)\n\n  limit \u03bb n => (step n)^[n] (x\u2080,y\u2080)\n  := sorry_proof\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/SciLean/Functions/DaeSolve.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.7003181260210607}}
{"text": "lemma nat.not_self_lt_lt_succ_self {a b : nat}\n  : a < b \u2192 b < a + 1 \u2192 false :=\nbegin\n  intros h1 h2, \n  cases nat.le.dest h1 with w h_1,\n  cases nat.le.dest h2 with w_1 h_2,\n  rw \u2190 h_1 at h_2,\n  rw \u2190 nat.succ_add at h_2,\n  apply nat.lt_irrefl (nat.succ a),\n  apply nat.lt_of_lt_of_le,\n  apply lt_add_of_pos_right (nat.succ a),\n  refine (_ : nat.succ (w + w_1) > 0),\n  apply nat.succ_pos,\n  have : \u2200 x y z, nat.succ x + y + z = x + nat.succ (y + z),\n  { intros, rw \u2190 nat.add_one, rw \u2190 nat.add_one, ac_refl },\n  rw this at h_2, rw h_2\nend\n\ndef sub_lt_if_ge : \u2200 n m k : \u2115, n \u2264 k \u2192 k < n + m \u2192 k - n < m :=\nbegin\n  intros n m k hnk h,\n  rw \u2190 nat.add_sub_of_le hnk at h,\n  apply lt_of_add_lt_add_left h\nend\n\ndef ge_if_not_lt {n k : \u2115} (h : \u00ac (n < k)) : n \u2265 k :=\nby { cases nat.lt_or_ge n k, exfalso, exact h h_1, exact h_1 }\n\nlemma pos_of_prod_pos_l {n m : \u2115} : 0 < n * m \u2192 0 < n :=\nbegin\n  intro h, apply decidable.by_contradiction, intro h',\n  have : n = 0,\n  { cases nat.lt_trichotomy n 0,\n    { exfalso, apply nat.not_lt_zero _ h_1 },\n    { cases h_1, assumption, trivial } },\n  rw [this, zero_mul] at h, apply nat.lt_irrefl _ h,\nend\n\nlemma mod_of_add_multiple (n m k : \u2115) : (n + m * k) % m = n % m :=\nbegin\n  induction k, simp,\n  { have : m \u2264 m * nat.succ k_n,\n    { rw nat.mul_succ, apply nat.le_add_left },\n    rw nat.mod_eq_sub_mod (nat.le_trans this (nat.le_add_left _ _)),\n    rw nat.add_sub_assoc this,\n    rw (_ : m * nat.succ k_n - m = m * nat.succ k_n - m * 1),\n    rw \u2190 nat.mul_sub_left_distrib, rw \u2190 nat.add_one,\n    rw nat.add_sub_cancel, assumption, simp }\nend\n\nlemma nat.mul_two : \u2200 n, n * 2 = n + n :=\nby simp [(*), nat.mul]\n\ndef binomial_coefficient : nat \u2192 nat \u2192 nat\n| _     0     := 1\n| 0     _     := 0\n| (n+1) (k+1) := binomial_coefficient n (k+1) + binomial_coefficient n k\n\nlemma binomial_coefficient_lt\n  : \u2200 n k, n < k \u2192 binomial_coefficient n k = 0 :=\nbegin\n  intro, induction n with n ih; intros k h,\n  { cases k, cases h, refl },\n  cases k, cases h,\n  simp [binomial_coefficient],\n  rw [ih, ih], transitivity,\n  apply nat.lt_succ_self, assumption,\n  apply nat.lt_of_succ_lt_succ h\nend\n\nlemma binomial_coefficient_self\n  : \u2200 n, binomial_coefficient n n = 1 :=\nbegin\n  intro, induction n with n ih, refl,\n  simp [binomial_coefficient], rw ih,\n  rw binomial_coefficient_lt, apply nat.lt_succ_self\nend\n\nlemma binomial_coefficient_zero\n  : \u2200 n, binomial_coefficient n 0 = 1 :=\nby intro; cases n; refl\n\ntheorem nat.even_odd_induction (P : nat \u2192 Sort _)\n  (bc\u2080 : P 0) (bc\u2081 : P 1) (rec : \u2200 n, P n \u2192 P n.succ \u2192 P n.succ.succ) : \u2200 n, P n\n| 0     := bc\u2080\n| 1     := bc\u2081\n| (n+2) := rec n (nat.even_odd_induction n) (nat.even_odd_induction n.succ)", "meta": {"author": "Shamrock-Frost", "repo": "boolean_rings", "sha": "5da11beeaa37ec186c1deff946f2dbf7594fceb4", "save_path": "github-repos/lean/Shamrock-Frost-boolean_rings", "path": "github-repos/lean/Shamrock-Frost-boolean_rings/boolean_rings-5da11beeaa37ec186c1deff946f2dbf7594fceb4/nat_util.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7003162642159458}}
{"text": "/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Julian Kuelshammer\n-/\nimport data.int.gcd\nimport algebra.iterate_hom\nimport algebra.pointwise\nimport dynamics.periodic_pts\nimport group_theory.coset\n\n/-!\n# Order of an element\n\nThis file defines the order of an element of a finite group. For a finite group `G` the order of\n`x \u2208 G` is the minimal `n \u2265 1` such that `x ^ n = 1`.\n\n## Main definitions\n\n* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite\n  order.\n* `is_of_fin_add_order` is the additive analogue of `is_of_find_order`.\n* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`\n  if `x` has infinite order.\n* `add_order_of` is the additive analogue of `order_of`.\n\n## Tags\norder of an element\n-/\n\nopen function nat\nopen_locale pointwise\n\nuniverses u v\n\nvariables {G : Type u} {A : Type v}\nvariables {x y : G} {a b : A} {n m : \u2115}\n\nsection monoid_add_monoid\n\nvariables [monoid G] [add_monoid A]\n\nsection is_of_fin_order\n\nlemma is_periodic_pt_add_iff_nsmul_eq_zero (a : A) :\n  is_periodic_pt ((+) a) n 0 \u2194 n \u2022 a = 0 :=\nby rw [is_periodic_pt, is_fixed_pt, add_left_iterate, add_zero]\n\n@[to_additive is_periodic_pt_add_iff_nsmul_eq_zero]\nlemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 \u2194 x ^ n = 1 :=\nby rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]\n\n/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite\norder, i.e. there exists `n \u2265 1` such that `n \u2022 a = 0`.-/\ndef is_of_fin_add_order (a : A) : Prop :=\n(0 : A) \u2208 periodic_pts ((+) a)\n\n/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there\nexists `n \u2265 1` such that `x ^ n = 1`.-/\n@[to_additive is_of_fin_add_order]\ndef is_of_fin_order (x : G) : Prop :=\n(1 : G) \u2208 periodic_pts ((*) x)\n\nlemma is_of_fin_add_order_of_mul_iff :\n  is_of_fin_add_order (additive.of_mul x) \u2194 is_of_fin_order x := iff.rfl\n\nlemma is_of_fin_order_of_add_iff :\n  is_of_fin_order (multiplicative.of_add a) \u2194 is_of_fin_add_order a := iff.rfl\n\nlemma is_of_fin_add_order_iff_nsmul_eq_zero (a : A) :\n  is_of_fin_add_order a \u2194 \u2203 n, 0 < n \u2227 n \u2022 a = 0 :=\nby { convert iff.rfl, simp only [exists_prop, is_periodic_pt_add_iff_nsmul_eq_zero] }\n\n@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]\nlemma is_of_fin_order_iff_pow_eq_one (x : G) :\n  is_of_fin_order x \u2194 \u2203 n, 0 < n \u2227 x ^ n = 1 :=\nby { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }\n\nend is_of_fin_order\n\n/-- `order_of x` is the order of the element `x`, i.e. the `n \u2265 1`, s.t. `x ^ n = 1` if it exists.\nOtherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/\n@[to_additive add_order_of\n\"`add_order_of a` is the order of the element `a`, i.e. the `n \u2265 1`, s.t. `n \u2022 a = 0` if it\nexists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention.\"]\nnoncomputable def order_of (x : G) : \u2115 :=\nminimal_period ((*) x) 1\n\n@[to_additive]\nlemma commute.order_of_mul_dvd_lcm (h : commute x y) :\n  order_of (x * y) \u2223 nat.lcm (order_of x) (order_of y) :=\nbegin\n  convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,\n  rw [order_of, comp_mul_left],\nend\n\n@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :\n  add_order_of (additive.of_mul x) = order_of x := rfl\n\n@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :\n  order_of (multiplicative.of_add a) = add_order_of a := rfl\n\n@[to_additive add_order_of_pos']\nlemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=\nminimal_period_pos_of_mem_periodic_pts h\n\n@[to_additive add_order_of_nsmul_eq_zero]\nlemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=\nbegin\n  convert is_periodic_pt_minimal_period ((*) x) _,\n  rw [order_of, mul_left_iterate, mul_one],\nend\n\n@[to_additive add_order_of_eq_zero]\nlemma order_of_eq_zero (h : \u00ac is_of_fin_order x) : order_of x = 0 :=\nby rwa [order_of, minimal_period, dif_neg]\n\n@[to_additive add_order_of_eq_zero_iff] lemma order_of_eq_zero_iff :\n  order_of x = 0 \u2194 \u00ac is_of_fin_order x :=\n\u27e8\u03bb h H, (order_of_pos' H).ne' h, order_of_eq_zero\u27e9\n\n@[to_additive add_order_of_eq_zero_iff'] lemma order_of_eq_zero_iff' :\n  order_of x = 0 \u2194 \u2200 n : \u2115, 0 < n \u2192 x ^ n \u2260 1 :=\nby simp_rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one, not_exists, not_and]\n\n@[to_additive nsmul_ne_zero_of_lt_add_order_of']\nlemma pow_ne_one_of_lt_order_of' (n0 : n \u2260 0) (h : n < order_of x) : x ^ n \u2260 1 :=\n\u03bb j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h\n  ((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)\n\n@[to_additive add_order_of_le_of_nsmul_eq_zero]\nlemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x \u2264 n :=\nis_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)\n\n@[simp, to_additive] lemma order_of_one : order_of (1 : G) = 1 :=\nby rw [order_of, one_mul_eq_id, minimal_period_id]\n\n@[simp, to_additive add_monoid.order_of_eq_one_iff] lemma order_of_eq_one_iff :\n  order_of x = 1 \u2194 x = 1 :=\nby rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]\n\n@[to_additive nsmul_eq_mod_add_order_of]\nlemma pow_eq_mod_order_of {n : \u2115} : x ^ n = x ^ (n % order_of x) :=\ncalc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]\n       ... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]\n\n@[to_additive add_order_of_dvd_of_nsmul_eq_zero]\nlemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x \u2223 n :=\nis_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)\n\n@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]\nlemma order_of_dvd_iff_pow_eq_one {n : \u2115} : order_of x \u2223 n \u2194 x ^ n = 1 :=\n\u27e8\u03bb h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one\u27e9\n\n@[to_additive exists_nsmul_eq_self_of_coprime]\nlemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :\n  \u2203 m : \u2115, (x ^ n) ^ m = x :=\nbegin\n  by_cases h0 : order_of x = 0,\n  { rw [h0, coprime_zero_right] at h,\n    exact \u27e81, by rw [h, pow_one, pow_one]\u27e9 },\n  by_cases h1 : order_of x = 1,\n  { exact \u27e80, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]\u27e9 },\n  obtain \u27e8m, hm\u27e9 :=\n    exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr \u27e8h0, h1\u27e9),\n  exact \u27e8m, by rw [\u2190pow_mul, pow_eq_mod_order_of, hm, pow_one]\u27e9,\nend\n\n/--\nIf `x^n = 1`, but `x^(n/p) \u2260 1` for all prime factors `p` of `r`,\nthen `x` has order `n` in `G`.\n-/\n@[to_additive add_order_of_eq_of_nsmul_and_div_prime_nsmul]\ntheorem order_of_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x^n = 1)\n  (hd : \u2200 p : \u2115, p.prime \u2192 p \u2223 n \u2192 x^(n/p) \u2260 1) :\n  order_of x = n :=\nbegin\n  -- Let `a` be `n/(order_of x)`, and show `a = 1`\n  cases exists_eq_mul_right_of_dvd (order_of_dvd_of_pow_eq_one hx) with a ha,\n  suffices : a = 1, by simp [this, ha],\n  -- Assume `a` is not one...\n  by_contra,\n  have a_min_fac_dvd_p_sub_one : a.min_fac \u2223 n,\n  { obtain \u27e8b, hb\u27e9 : \u2203 (b : \u2115), a = b * a.min_fac := exists_eq_mul_left_of_dvd a.min_fac_dvd,\n    rw [hb, \u2190mul_assoc] at ha,\n    exact dvd.intro_left (order_of x * b) ha.symm, },\n  -- Use the minimum prime factor of `a` as `p`.\n  refine hd a.min_fac (nat.min_fac_prime h) a_min_fac_dvd_p_sub_one _,\n  rw [\u2190order_of_dvd_iff_pow_eq_one, nat.dvd_div_iff (a_min_fac_dvd_p_sub_one),\n      ha, mul_comm, nat.mul_dvd_mul_iff_left (order_of_pos' _)],\n  { exact nat.min_fac_dvd a, },\n  { rw is_of_fin_order_iff_pow_eq_one,\n    exact Exists.intro n (id \u27e8hn, hx\u27e9) },\nend\n\n@[to_additive add_order_of_eq_add_order_of_iff]\nlemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :\n  order_of x = order_of y \u2194 \u2200 n : \u2115, x ^ n = 1 \u2194 y ^ n = 1 :=\nby simp_rw [\u2190 is_periodic_pt_mul_iff_pow_eq_one, \u2190 minimal_period_eq_minimal_period_iff, order_of]\n\n@[to_additive add_order_of_injective]\nlemma order_of_injective {H : Type*} [monoid H] (f : G \u2192* H)\n  (hf : function.injective f) (x : G) : order_of (f x) = order_of x :=\nby simp_rw [order_of_eq_order_of_iff, \u2190f.map_pow, \u2190f.map_one, hf.eq_iff, iff_self, forall_const]\n\n@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}\n  (y : H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive order_of_add_units]\nlemma order_of_units {y : units G} : order_of (y : G) = order_of y :=\norder_of_injective (units.coe_hom G) units.ext y\n\nvariables (x)\n@[to_additive add_order_of_nsmul']\nlemma order_of_pow' (h : n \u2260 0) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd h,\n  simp only [order_of, mul_left_iterate],\nend\n\nvariables (a)\n\nvariable (n)\n\n@[to_additive add_order_of_nsmul'']\nlemma order_of_pow'' (h : is_of_fin_order x) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n :=\nbegin\n  convert minimal_period_iterate_eq_div_gcd' h,\n  simp only [order_of, mul_left_iterate],\nend\n\nlemma commute.order_of_mul_dvd_lcm_order_of {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 lcm (order_of x) (order_of y) :=\nbegin\n  convert h.function_commute_mul_left.minimal_period_of_comp_dvd_lcm,\n  simp only [order_of, comp_mul_left],\nend\n\nlemma commute.order_of_mul_dvd_mul_order_of {x y : G} (h : commute x y) :\n  order_of (x * y) \u2223 (order_of x) * (order_of y) :=\ndvd_trans h.order_of_mul_dvd_lcm_order_of (lcm_dvd_mul _ _)\n\nlemma commute.order_of_mul_eq_mul_order_of_of_coprime {x y : G} (h : commute x y)\n  (hco : nat.coprime (order_of x) (order_of y)) :\n  order_of (x * y) = (order_of x) * (order_of y) :=\nbegin\n  convert h.function_commute_mul_left.minimal_period_of_comp_eq_mul_of_coprime hco,\n  simp only [order_of, comp_mul_left],\nend\n\nsection p_prime\n\nvariables {a x n} {p : \u2115} [hp : fact p.prime]\ninclude hp\n\nlemma add_order_of_eq_prime (hg : p \u2022 a = 0) (hg1 : a \u2260 0) : add_order_of a = p :=\nminimal_period_eq_prime ((is_periodic_pt_add_iff_nsmul_eq_zero _).mpr hg)\n  (by rwa [is_fixed_pt, add_zero])\n\n@[to_additive add_order_of_eq_prime]\nlemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x \u2260 1) : order_of x = p :=\nminimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)\n  (by rwa [is_fixed_pt, mul_one])\n\n@[to_additive add_order_of_eq_prime_pow]\nlemma order_of_eq_prime_pow (hnot : \u00ac x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :\n  order_of x = p ^ (n + 1) :=\nbegin\n  apply minimal_period_eq_prime_pow;\n  rwa is_periodic_pt_mul_iff_pow_eq_one,\nend\n\nomit hp\n-- An example on how to determine the order of an element of a finite group.\nexample : order_of (-1 : units \u2124) = 2 :=\nbegin\n  haveI : fact (prime 2) := \u27e8prime_two\u27e9,\n  exact order_of_eq_prime (int.units_mul_self _) dec_trivial,\nend\n\nend p_prime\n\nend monoid_add_monoid\n\nsection cancel_monoid\nvariables [left_cancel_monoid G] (x)\nvariables [add_left_cancel_monoid A] (a)\n\n@[to_additive nsmul_injective_aux]\nlemma pow_injective_aux (h : n \u2264 m)\n  (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\nby_contradiction $ assume ne : n \u2260 m,\n  have h\u2081 : m - n > 0, from nat.pos_of_ne_zero (by simp [tsub_eq_iff_eq_add_of_le h, ne.symm]),\n  have h\u2082 : m = n + (m - n) := (add_tsub_cancel_of_le h).symm,\n  have h\u2083 : x ^ (m - n) = 1,\n    by { rw [h\u2082, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (x ^ n) },\n  have le : order_of x \u2264 m - n, from order_of_le_of_pow_eq_one h\u2081 h\u2083,\n  have lt : m - n < order_of x,\n    from (tsub_lt_iff_left h).mpr $ nat.lt_add_left _ _ _ hm,\n  lt_irrefl _ (le.trans_lt lt)\n\n@[to_additive nsmul_injective_of_lt_add_order_of]\nlemma pow_injective_of_lt_order_of\n  (hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=\n(le_total n m).elim\n  (assume h, pow_injective_aux x h hm eq)\n  (assume h, (pow_injective_aux x h hn eq.symm).symm)\n\nend cancel_monoid\n\nsection group\nvariables [group G] [add_group A] {x a} {i : \u2124}\n\n@[to_additive add_order_of_dvd_iff_zsmul_eq_zero]\nlemma order_of_dvd_iff_zpow_eq_one : (order_of x : \u2124) \u2223 i \u2194 x ^ i = 1 :=\nbegin\n  rcases int.eq_coe_or_neg i with \u27e8i, rfl|rfl\u27e9,\n  { rw [int.coe_nat_dvd, order_of_dvd_iff_pow_eq_one, zpow_coe_nat] },\n  { rw [dvd_neg, int.coe_nat_dvd, zpow_neg, inv_eq_one, zpow_coe_nat,\n      order_of_dvd_iff_pow_eq_one] }\nend\n\n@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}\n  (y: H) : order_of (y : G) = order_of y :=\norder_of_injective H.subtype subtype.coe_injective y\n\n@[to_additive zsmul_eq_mod_add_order_of]\nlemma zpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=\ncalc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :\n    by rw [int.mod_add_div]\n       ... = x ^ (i % order_of x) :\n    by simp [zpow_add, zpow_mul, pow_order_of_eq_one]\n    set_option pp.all true\n\n@[to_additive nsmul_inj_iff_of_add_order_of_eq_zero]\nlemma pow_inj_iff_of_order_of_eq_zero (h : order_of x = 0) {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n = m :=\nbegin\n  rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one] at h,\n  push_neg at h,\n  induction n with n IH generalizing m,\n  { cases m,\n    { simp },\n    { simpa [eq_comm] using h m.succ m.zero_lt_succ } },\n  { cases m,\n    { simpa using h n.succ n.zero_lt_succ },\n    { simp [pow_succ, IH] } }\nend\n\n@[to_additive nsmul_inj_mod]\nlemma pow_inj_mod {n m : \u2115} :\n  x ^ n = x ^ m \u2194 n % order_of x = m % order_of x :=\nbegin\n  cases (order_of x).zero_le.eq_or_lt with hx hx,\n  { simp [pow_inj_iff_of_order_of_eq_zero, hx.symm] },\n  rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ m],\n  exact \u27e8pow_injective_of_lt_order_of _ (nat.mod_lt _ hx) (nat.mod_lt _ hx), \u03bb h, congr_arg _ h\u27e9\nend\n\n\nend group\n\nsection fintype\nvariables [fintype G] [fintype A]\n\nsection finite_monoid\nvariables [monoid G] [add_monoid A]\nopen_locale big_operators\n\n@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]\nlemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :\n  \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n  = (finset.univ.filter (\u03bb x : G, x ^ n = 1)).card :=\ncalc \u2211 m in (finset.range n.succ).filter (\u2223 n), (finset.univ.filter (\u03bb x : G, order_of x = m)).card\n    = _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm\n... = _ : congr_arg finset.card (finset.ext (begin\n  assume x,\n  suffices : order_of x \u2264 n \u2227 order_of x \u2223 n \u2194 x ^ n = 1,\n  { simpa [nat.lt_succ_iff], },\n  exact \u27e8\u03bb h, let \u27e8m, hm\u27e9 := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],\n    \u03bb h, \u27e8order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h\u27e9\u27e9\nend))\n\nend finite_monoid\n\nsection finite_cancel_monoid\n-- TODO: Of course everything also works for right_cancel_monoids.\nvariables [left_cancel_monoid G] [add_left_cancel_monoid A]\n\n-- TODO: Use this to show that a finite left cancellative monoid is a group.\n@[to_additive exists_nsmul_eq_zero]\nlemma exists_pow_eq_one (x : G) : is_of_fin_order x :=\nbegin\n  refine (is_of_fin_order_iff_pow_eq_one _).mpr _,\n  obtain \u27e8i, j, a_eq, ne\u27e9 : \u2203(i j : \u2115), x ^ i = x ^ j \u2227 i \u2260 j :=\n    by simpa only [not_forall, exists_prop, injective]\n      using (not_injective_infinite_fintype (\u03bbi:\u2115, x^i)),\n  wlog h'' : j \u2264 i,\n  refine \u27e8i - j, tsub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _\u27e9,\n  rw [mul_one, \u2190 pow_add, \u2190 a_eq, add_tsub_cancel_of_le h''],\nend\n\n@[to_additive add_order_of_le_card_univ]\nlemma order_of_le_card_univ : order_of x \u2264 fintype.card G :=\nfinset.le_card_of_inj_on_range ((^) x)\n  (assume n _, finset.mem_univ _)\n  (assume i hi j hj, pow_injective_of_lt_order_of x hi hj)\n\n/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative monoid.-/\n@[to_additive add_order_of_pos\n\"This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is\n  automatic in case of a finite cancellative additive monoid.\"]\nlemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)\n\nopen nat\n\n/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is\nautomatic in the case of a finite cancellative monoid.-/\n@[to_additive add_order_of_nsmul\n\"This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less\nwhich is automatic in the case of a finite cancellative additive monoid.\"]\nlemma order_of_pow (x : G) :\n  order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)\n\n@[to_additive mem_multiples_iff_mem_range_add_order_of]\nlemma mem_powers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 submonoid.powers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nfinset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)\n  (assume i, pow_eq_mod_order_of.symm)\n\n@[to_additive decidable_multiples]\nnoncomputable instance decidable_powers [decidable_eq G] :\n  decidable_pred (\u2208 submonoid.powers x) :=\nbegin\n  assume y,\n  apply decidable_of_iff'\n    (y \u2208 (finset.range (order_of x)).image ((^) x)),\n  exact mem_powers_iff_mem_range_order_of\nend\n\n/--The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`.\"-/\n@[to_additive fin_equiv_multiples \"The equivalence between `fin (add_order_of a)` and\n`add_submonoid.multiples a`, sending `i` to `i \u2022 a`.\"]\nnoncomputable def fin_equiv_powers (x : G) :\n  fin (order_of x) \u2243 (submonoid.powers x : set G) :=\nequiv.of_bijective (\u03bb n, \u27e8x ^ \u2191n, \u27e8n, rfl\u27e9\u27e9) \u27e8\u03bb \u27e8i, hi\u27e9 \u27e8j, hj\u27e9 ij,\n  subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),\n  \u03bb \u27e8_, i, rfl\u27e9, \u27e8\u27e8i % order_of x, mod_lt i (order_of_pos x)\u27e9, subtype.eq pow_eq_mod_order_of.symm\u27e9\u27e9\n\n@[simp, to_additive fin_equiv_multiples_apply]\nlemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :\n  fin_equiv_powers x n = \u27e8x ^ \u2191n, n, rfl\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_multiples_symm_apply]\nlemma fin_equiv_powers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2115), x ^ m = x ^ n} :\n  ((fin_equiv_powers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,\n  pow_eq_mod_order_of, fin.coe_mk]\n\n/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive multiples_equiv_multiples\n\"The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def powers_equiv_powers (h : order_of x = order_of y) :\n  (submonoid.powers x : set G) \u2243 (submonoid.powers y : set G) :=\n(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))\n\n@[simp, to_additive multiples_equiv_multiples_apply]\nlemma powers_equiv_powers_apply (h : order_of x = order_of y)\n  (n : \u2115) : powers_equiv_powers h \u27e8x ^ n, n, rfl\u27e9 = \u27e8y ^ n, n, rfl\u27e9 :=\nbegin\n  rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_powers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_powers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_of_eq_card_multiples]\nlemma order_eq_card_powers [decidable_eq G] :\n  order_of x = fintype.card (submonoid.powers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_powers x\u27e9)\n\nend finite_cancel_monoid\n\nsection finite_group\nvariables [group G] [add_group A]\n\n@[to_additive]\nlemma exists_zpow_eq_one (x : G) : \u2203 (i : \u2124) (H : i \u2260 0), x ^ (i : \u2124) = 1 :=\nbegin\n  rcases exists_pow_eq_one x with \u27e8w, hw1, hw2\u27e9,\n  refine \u27e8w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _\u27e9,\n  rw zpow_coe_nat,\n  exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,\nend\n\nopen subgroup\n\n@[to_additive mem_multiples_iff_mem_zmultiples]\nlemma mem_powers_iff_mem_zpowers : y \u2208 submonoid.powers x \u2194 y \u2208 zpowers x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, \u27e8n, by simp * at *\u27e9,\n\u03bb \u27e8i, hi\u27e9, \u27e8(i % order_of x).nat_abs,\n  by rwa [\u2190 zpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _\n    (int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),\n    \u2190 zpow_eq_mod_order_of]\u27e9\u27e9\n\n@[to_additive multiples_eq_zmultiples]\nlemma powers_eq_zpowers (x : G) : (submonoid.powers x : set G) = zpowers x :=\nset.ext $ \u03bb x, mem_powers_iff_mem_zpowers\n\n@[to_additive mem_zmultiples_iff_mem_range_add_order_of]\nlemma mem_zpowers_iff_mem_range_order_of [decidable_eq G] :\n  y \u2208 subgroup.zpowers x \u2194 y \u2208 (finset.range (order_of x)).image ((^) x : \u2115 \u2192 G) :=\nby rw [\u2190 mem_powers_iff_mem_zpowers, mem_powers_iff_mem_range_order_of]\n\n@[to_additive decidable_zmultiples]\nnoncomputable instance decidable_zpowers [decidable_eq G] :\n  decidable_pred (\u2208 subgroup.zpowers x) :=\nbegin\n  simp_rw \u2190set_like.mem_coe,\n  rw \u2190 powers_eq_zpowers,\n  exact decidable_powers,\nend\n\n/-- The equivalence between `fin (order_of x)` and `subgroup.zpowers x`, sending `i` to `x ^ i`. -/\n@[to_additive fin_equiv_zmultiples\n\"The equivalence between `fin (add_order_of a)` and `subgroup.zmultiples a`, sending `i`\nto `i \u2022 a`.\"]\nnoncomputable def fin_equiv_zpowers (x : G) :\n  fin (order_of x) \u2243 (subgroup.zpowers x : set G) :=\n(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_zpowers x))\n\n@[simp, to_additive fin_equiv_zmultiples_apply]\nlemma fin_equiv_zpowers_apply {n : fin (order_of x)} :\n  fin_equiv_zpowers x n = \u27e8x ^ (n : \u2115), n, zpow_coe_nat x n\u27e9 := rfl\n\n@[simp, to_additive fin_equiv_zmultiples_symm_apply]\nlemma fin_equiv_zpowers_symm_apply (x : G) (n : \u2115)\n  {hn : \u2203 (m : \u2124), x ^ m = x ^ n} :\n  ((fin_equiv_zpowers x).symm \u27e8x ^ n, hn\u27e9) = \u27e8n % order_of x, nat.mod_lt _ (order_of_pos x)\u27e9 :=\nby { rw [fin_equiv_zpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],\n  exact fin_equiv_powers_symm_apply x n }\n\n/-- The equivalence between `subgroup.zpowers` of two elements `x, y` of the same order, mapping\n  `x ^ i` to `y ^ i`. -/\n@[to_additive zmultiples_equiv_zmultiples\n\"The equivalence between `subgroup.zmultiples` of two elements `a, b` of the same additive order,\n  mapping `i \u2022 a` to `i \u2022 b`.\"]\nnoncomputable def zpowers_equiv_zpowers (h : order_of x = order_of y) :\n  (subgroup.zpowers x : set G) \u2243 (subgroup.zpowers y : set G) :=\n(fin_equiv_zpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_zpowers y))\n\n@[simp, to_additive zmultiples_equiv_zmultiples_apply]\nlemma zpowers_equiv_zpowers_apply (h : order_of x = order_of y)\n  (n : \u2115) : zpowers_equiv_zpowers h \u27e8x ^ n, n, zpow_coe_nat x n\u27e9 = \u27e8y ^ n, n, zpow_coe_nat y n\u27e9 :=\nbegin\n  rw [zpowers_equiv_zpowers, equiv.trans_apply, equiv.trans_apply,\n    fin_equiv_zpowers_symm_apply, \u2190 equiv.eq_symm_apply, fin_equiv_zpowers_symm_apply],\n  simp [h]\nend\n\n@[to_additive add_order_eq_card_zmultiples]\nlemma order_eq_card_zpowers [decidable_eq G] :\n  order_of x = fintype.card (subgroup.zpowers x : set G) :=\n(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 \u27e8fin_equiv_zpowers x\u27e9)\n\nopen quotient_group\n\n/- TODO: use cardinal theory, introduce `card : set G \u2192 \u2115`, or setup decidability for cosets -/\n@[to_additive add_order_of_dvd_card_univ]\nlemma order_of_dvd_card_univ : order_of x \u2223 fintype.card G :=\nbegin\n  classical,\n  have ft_prod : fintype ((G \u29f8 zpowers x) \u00d7 zpowers x),\n    from fintype.of_equiv G group_equiv_quotient_times_subgroup,\n  have ft_s : fintype (zpowers x),\n    from @fintype.prod_right _ _ _ ft_prod _,\n  have ft_cosets : fintype (G \u29f8 zpowers x),\n    from @fintype.prod_left _ _ _ ft_prod \u27e8\u27e81, (zpowers x).one_mem\u27e9\u27e9,\n  have eq\u2081 : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,\n    from calc fintype.card G = @fintype.card _ ft_prod :\n        @fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup\n      ... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :\n        congr_arg (@fintype.card _) $ subsingleton.elim _ _\n      ... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :\n        @fintype.card_prod _ _ ft_cosets ft_s,\n  have eq\u2082 : order_of x = @fintype.card _ ft_s,\n    from calc order_of x = _ : order_eq_card_zpowers\n      ... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,\n  exact dvd.intro (@fintype.card (G \u29f8 subgroup.zpowers x) ft_cosets)\n          (by rw [eq\u2081, eq\u2082, mul_comm])\nend\n\n@[simp, to_additive card_nsmul_eq_zero] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=\nlet \u27e8m, hm\u27e9 := @order_of_dvd_card_univ _ x _ _ in\nby simp [hm, pow_mul, pow_order_of_eq_one]\n\n@[to_additive nsmul_eq_mod_card] lemma pow_eq_mod_card (n : \u2115) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [pow_eq_mod_order_of, \u2190nat.mod_mod_of_dvd n order_of_dvd_card_univ,\n  \u2190 pow_eq_mod_order_of]\n\n@[to_additive] lemma zpow_eq_mod_card (n : \u2124) :\n  x ^ n = x ^ (n % fintype.card G) :=\nby rw [zpow_eq_mod_order_of, \u2190 int.mod_mod_of_dvd n (int.coe_nat_dvd.2 order_of_dvd_card_univ),\n  \u2190 zpow_eq_mod_order_of]\n\n/-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/\n@[simps] def pow_coprime (h : nat.coprime (fintype.card G) n) : G \u2243 G :=\n{ to_fun := \u03bb g, g ^ n,\n  inv_fun := \u03bb g, g ^ (nat.gcd_b (fintype.card G) n),\n  left_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul, zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key },\n  right_inv := \u03bb g, by\n  { have key : g ^ _ = g ^ _ := congr_arg (\u03bb n : \u2124, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),\n    rwa [zpow_add, zpow_mul, zpow_mul', zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,\n      h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key } }\n\n@[simp] lemma pow_coprime_one (h : nat.coprime (fintype.card G) n) : pow_coprime h 1 = 1 :=\none_pow n\n\n@[simp] lemma pow_coprime_inv (h : nat.coprime (fintype.card G) n) {g : G} :\n  pow_coprime h g\u207b\u00b9 = (pow_coprime h g)\u207b\u00b9 :=\ninv_pow g n\n\nlemma inf_eq_bot_of_coprime {G : Type*} [group G] {H K : subgroup G} [fintype H] [fintype K]\n  (h : nat.coprime (fintype.card H) (fintype.card K)) : H \u2293 K = \u22a5 :=\nbegin\n  refine (H \u2293 K).eq_bot_iff_forall.mpr (\u03bb x hx, _),\n  rw [\u2190order_of_eq_one_iff, \u2190nat.dvd_one, \u2190h.gcd_eq_one, nat.dvd_gcd_iff],\n  exact \u27e8(congr_arg (\u2223 fintype.card H) (order_of_subgroup \u27e8x, hx.1\u27e9)).mpr order_of_dvd_card_univ,\n    (congr_arg (\u2223 fintype.card K) (order_of_subgroup \u27e8x, hx.2\u27e9)).mpr order_of_dvd_card_univ\u27e9,\nend\n\nvariable (a)\n\nlemma image_range_add_order_of [decidable_eq A] :\n  finset.image (\u03bb i, i \u2022 a) (finset.range (add_order_of a)) =\n  (add_subgroup.zmultiples a : set A).to_finset :=\nby {ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_zmultiples_iff_mem_range_add_order_of] }\n\n/-- TODO: Generalise to `submonoid.powers`.-/\n@[to_additive image_range_add_order_of]\nlemma image_range_order_of [decidable_eq G] :\n  finset.image (\u03bb i, x ^ i) (finset.range (order_of x)) = (zpowers x : set G).to_finset :=\nby { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_zpowers_iff_mem_range_order_of] }\n\n/-- TODO: Generalise to `finite_cancel_monoid`. -/\n@[to_additive gcd_nsmul_card_eq_zero_iff]\nlemma pow_gcd_card_eq_one_iff : x ^ n = 1 \u2194 x ^ (gcd n (fintype.card G)) = 1 :=\n\u27e8\u03bb h, pow_gcd_eq_one _ h $ pow_card_eq_one,\n  \u03bb h, let \u27e8m, hm\u27e9 := gcd_dvd_left n (fintype.card G) in\n    by rw [hm, pow_mul, h, one_pow]\u27e9\n\nend finite_group\n\nend fintype\n\nsection pow_is_subgroup\n\n/-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/\ndef submonoid_of_idempotent {M : Type*} [left_cancel_monoid M] [fintype M] (S : set M)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : submonoid M :=\nhave pow_mem : \u2200 a : M, a \u2208 S \u2192 \u2200 n : \u2115, a ^ (n + 1) \u2208 S :=\n\u03bb a ha, nat.rec (by rwa [zero_add, pow_one])\n  (\u03bb n ih, (congr_arg2 (\u2208) (pow_succ a (n + 1)).symm hS2).mp (set.mul_mem_mul ha ih)),\n{ carrier := S,\n  one_mem' := by\n  { obtain \u27e8a, ha\u27e9 := hS1,\n    rw [\u2190pow_order_of_eq_one a, \u2190 tsub_add_cancel_of_le (succ_le_of_lt (order_of_pos a))],\n    exact pow_mem a ha (order_of a - 1) },\n  mul_mem' := \u03bb a b ha hb, (congr_arg2 (\u2208) rfl hS2).mp (set.mul_mem_mul ha hb) }\n\n/-- A nonempty idempotent subset of a finite group is a subgroup -/\ndef subgroup_of_idempotent {G : Type*} [group G] [fintype G] (S : set G)\n  (hS1 : S.nonempty) (hS2 : S * S = S) : subgroup G :=\n{ carrier := S,\n  inv_mem' := \u03bb a ha, by\n  { rw [\u2190one_mul a\u207b\u00b9, \u2190pow_one a, \u2190pow_order_of_eq_one a, \u2190pow_sub a (order_of_pos a)],\n    exact (submonoid_of_idempotent S hS1 hS2).pow_mem ha (order_of a - 1) },\n  .. submonoid_of_idempotent S hS1 hS2 }\n\n/-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/\ndef pow_card_subgroup {G : Type*} [group G] [fintype G] (S : set G) (hS : S.nonempty) :\n  subgroup G :=\nhave one_mem : (1 : G) \u2208 (S ^ fintype.card G) := by\n{ obtain \u27e8a, ha\u27e9 := hS,\n  rw \u2190 pow_card_eq_one,\n  exact set.pow_mem_pow ha (fintype.card G) },\nsubgroup_of_idempotent (S ^ (fintype.card G)) \u27e81, one_mem\u27e9 begin\n  classical,\n  refine (set.eq_of_subset_of_card_le\n    (\u03bb b hb, (congr_arg (\u2208 _) (one_mul b)).mp (set.mul_mem_mul one_mem hb)) (ge_of_eq _)).symm,\n  change _ = fintype.card (_ * _ : set G),\n  rw [\u2190pow_add, group.card_pow_eq_card_pow_card_univ S (fintype.card G) le_rfl,\n      group.card_pow_eq_card_pow_card_univ S (fintype.card G + fintype.card G) le_add_self],\nend\n\nend pow_is_subgroup\n\nsection linear_ordered_ring\n\nvariable [linear_ordered_ring G]\n\nlemma order_of_abs_ne_one (h : |x| \u2260 1) : order_of x = 0 :=\nbegin\n  rw order_of_eq_zero_iff',\n  intros n hn hx,\n  replace hx : |x| ^ n = 1 := by simpa only [abs_one, abs_pow] using congr_arg abs hx,\n  cases h.lt_or_lt with h h,\n  { exact ((pow_lt_one (abs_nonneg x) h hn.ne').ne hx).elim },\n  { exact ((one_lt_pow h hn.ne').ne' hx).elim }\nend\n\nlemma linear_ordered_ring.order_of_le_two : order_of x \u2264 2 :=\nbegin\n  cases ne_or_eq (|x|) 1 with h h,\n  { simp [order_of_abs_ne_one h] },\n  rcases eq_or_eq_neg_of_abs_eq h with rfl | rfl,\n  { simp },\n  apply order_of_le_of_pow_eq_one; norm_num\nend\n\nend linear_ordered_ring\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/group_theory/order_of_element.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.7003162632001333}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Johannes H\u00f6lzl, Scott Morrison, Jens Wagemaker\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.coeff\nimport Mathlib.data.nat.with_bot\nimport Mathlib.PostPort\n\nuniverses u v u_1 \n\nnamespace Mathlib\n\n/-!\n# Theory of univariate polynomials\n\nThe definitions include\n`degree`, `monic`, `leading_coeff`\n\nResults include\n- `degree_mul` : The degree of the product is the sum of degrees\n- `leading_coeff_add_of_degree_eq` and `leading_coeff_add_of_degree_lt` :\n    The leading_coefficient of a sum is determined by the leading coefficients and degrees\n-/\n\nnamespace polynomial\n\n\n/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.\n`degree p = some n` when `p \u2260 0` and `n` is the highest power of `X` that appears in `p`, otherwise\n`degree 0 = \u22a5`. -/\ndef degree {R : Type u} [semiring R] (p : polynomial R) : with_bot \u2115 :=\n  finset.sup (finsupp.support p) some\n\ntheorem degree_lt_wf {R : Type u} [semiring R] : well_founded fun (p q : polynomial R) => degree p < degree q :=\n  inv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)\n\nprotected instance has_well_founded {R : Type u} [semiring R] : has_well_founded (polynomial R) :=\n  has_well_founded.mk (fun (p q : polynomial R) => degree p < degree q) degree_lt_wf\n\n/-- `nat_degree p` forces `degree p` to \u2115, by defining nat_degree 0 = 0. -/\ndef nat_degree {R : Type u} [semiring R] (p : polynomial R) : \u2115 :=\n  option.get_or_else (degree p) 0\n\n/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/\ndef leading_coeff {R : Type u} [semiring R] (p : polynomial R) : R :=\n  coeff p (nat_degree p)\n\n/-- a polynomial is `monic` if its leading coefficient is 1 -/\ndef monic {R : Type u} [semiring R] (p : polynomial R) :=\n  leading_coeff p = 1\n\ntheorem monic_of_subsingleton {R : Type u} [semiring R] [subsingleton R] (p : polynomial R) : monic p :=\n  subsingleton.elim (leading_coeff p) 1\n\ntheorem monic.def {R : Type u} [semiring R] {p : polynomial R} : monic p \u2194 leading_coeff p = 1 :=\n  iff.rfl\n\nprotected instance monic.decidable {R : Type u} [semiring R] {p : polynomial R} [DecidableEq R] : Decidable (monic p) :=\n  eq.mpr sorry (_inst_2 (leading_coeff p) 1)\n\n@[simp] theorem monic.leading_coeff {R : Type u} [semiring R] {p : polynomial R} (hp : monic p) : leading_coeff p = 1 :=\n  hp\n\ntheorem monic.coeff_nat_degree {R : Type u} [semiring R] {p : polynomial R} (hp : monic p) : coeff p (nat_degree p) = 1 :=\n  hp\n\n@[simp] theorem degree_zero {R : Type u} [semiring R] : degree 0 = \u22a5 :=\n  rfl\n\n@[simp] theorem nat_degree_zero {R : Type u} [semiring R] : nat_degree 0 = 0 :=\n  rfl\n\n@[simp] theorem coeff_nat_degree {R : Type u} [semiring R] {p : polynomial R} : coeff p (nat_degree p) = leading_coeff p :=\n  rfl\n\ntheorem degree_eq_bot {R : Type u} [semiring R] {p : polynomial R} : degree p = \u22a5 \u2194 p = 0 := sorry\n\ntheorem degree_of_subsingleton {R : Type u} [semiring R] {p : polynomial R} [subsingleton R] : degree p = \u22a5 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (degree p = \u22a5)) (subsingleton.elim p 0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (degree 0 = \u22a5)) degree_zero)) (Eq.refl \u22a5))\n\ntheorem nat_degree_of_subsingleton {R : Type u} [semiring R] {p : polynomial R} [subsingleton R] : nat_degree p = 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_degree p = 0)) (subsingleton.elim p 0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_degree 0 = 0)) nat_degree_zero)) (Eq.refl 0))\n\ntheorem degree_eq_nat_degree {R : Type u} [semiring R] {p : polynomial R} (hp : p \u2260 0) : degree p = \u2191(nat_degree p) := sorry\n\ntheorem degree_eq_iff_nat_degree_eq {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} (hp : p \u2260 0) : degree p = \u2191n \u2194 nat_degree p = n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (degree p = \u2191n \u2194 nat_degree p = n)) (degree_eq_nat_degree hp)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (\u2191(nat_degree p) = \u2191n \u2194 nat_degree p = n)) (propext with_bot.coe_eq_coe)))\n      (iff.refl (nat_degree p = n)))\n\ntheorem degree_eq_iff_nat_degree_eq_of_pos {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} (hn : 0 < n) : degree p = \u2191n \u2194 nat_degree p = n := sorry\n\ntheorem nat_degree_eq_of_degree_eq_some {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} (h : degree p = \u2191n) : nat_degree p = n := sorry\n\n@[simp] theorem degree_le_nat_degree {R : Type u} [semiring R] {p : polynomial R} : degree p \u2264 \u2191(nat_degree p) :=\n  galois_connection.le_u_l (galois_insertion.gc with_bot.gi_get_or_else_bot) (degree p)\n\ntheorem nat_degree_eq_of_degree_eq {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] {q : polynomial S} (h : degree p = degree q) : nat_degree p = nat_degree q := sorry\n\ntheorem le_degree_of_ne_zero {R : Type u} {n : \u2115} [semiring R] {p : polynomial R} (h : coeff p n \u2260 0) : \u2191n \u2264 degree p :=\n  (fun (this : some n \u2264 finset.sup (finsupp.support p) some) => this) (finset.le_sup (iff.mpr finsupp.mem_support_iff h))\n\ntheorem le_nat_degree_of_ne_zero {R : Type u} {n : \u2115} [semiring R] {p : polynomial R} (h : coeff p n \u2260 0) : n \u2264 nat_degree p := sorry\n\ntheorem le_nat_degree_of_mem_supp {R : Type u} [semiring R] {p : polynomial R} (a : \u2115) : a \u2208 finsupp.support p \u2192 a \u2264 nat_degree p :=\n  le_nat_degree_of_ne_zero \u2218 iff.mp mem_support_iff_coeff_ne_zero\n\ntheorem supp_subset_range {R : Type u} {m : \u2115} [semiring R] {p : polynomial R} (h : nat_degree p < m) : finsupp.support p \u2286 finset.range m :=\n  fun (n : \u2115) (hn : n \u2208 finsupp.support p) =>\n    iff.mpr finset.mem_range (has_le.le.trans_lt (le_nat_degree_of_mem_supp n hn) h)\n\ntheorem supp_subset_range_nat_degree_succ {R : Type u} [semiring R] {p : polynomial R} : finsupp.support p \u2286 finset.range (nat_degree p + 1) :=\n  supp_subset_range (nat.lt_succ_self (nat_degree p))\n\ntheorem degree_le_degree {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : coeff q (nat_degree p) \u2260 0) : degree p \u2264 degree q :=\n  dite (p = 0) (fun (hp : p = 0) => eq.mpr (id (Eq._oldrec (Eq.refl (degree p \u2264 degree q)) hp)) bot_le)\n    fun (hp : \u00acp = 0) =>\n      eq.mpr (id (Eq._oldrec (Eq.refl (degree p \u2264 degree q)) (degree_eq_nat_degree hp))) (le_degree_of_ne_zero h)\n\ntheorem degree_ne_of_nat_degree_ne {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} : nat_degree p \u2260 n \u2192 degree p \u2260 \u2191n := sorry\n\ntheorem nat_degree_le_iff_degree_le {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} : nat_degree p \u2264 n \u2194 degree p \u2264 \u2191n :=\n  with_bot.get_or_else_bot_le_iff\n\ntheorem degree_le_of_nat_degree_le {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} : nat_degree p \u2264 n \u2192 degree p \u2264 \u2191n :=\n  iff.mp nat_degree_le_iff_degree_le\n\ntheorem nat_degree_le_nat_degree {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (hpq : degree p \u2264 degree q) : nat_degree p \u2264 nat_degree q :=\n  galois_connection.monotone_l (galois_insertion.gc with_bot.gi_get_or_else_bot) hpq\n\n@[simp] theorem degree_C {R : Type u} {a : R} [semiring R] (ha : a \u2260 0) : degree (coe_fn C a) = 0 :=\n  (fun (this : finset.sup (ite (a = 0) \u2205 (singleton 0)) some = 0) => this)\n    (eq.mpr (id (Eq._oldrec (Eq.refl (finset.sup (ite (a = 0) \u2205 (singleton 0)) some = 0)) (if_neg ha)))\n      (Eq.refl (finset.sup (singleton 0) some)))\n\ntheorem degree_C_le {R : Type u} {a : R} [semiring R] : degree (coe_fn C a) \u2264 0 := sorry\n\ntheorem degree_one_le {R : Type u} [semiring R] : degree 1 \u2264 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (degree 1 \u2264 0)) (Eq.symm C_1))) degree_C_le\n\n@[simp] theorem nat_degree_C {R : Type u} [semiring R] (a : R) : nat_degree (coe_fn C a) = 0 := sorry\n\n@[simp] theorem nat_degree_one {R : Type u} [semiring R] : nat_degree 1 = 0 :=\n  nat_degree_C 1\n\n@[simp] theorem nat_degree_nat_cast {R : Type u} [semiring R] (n : \u2115) : nat_degree \u2191n = 0 := sorry\n\n@[simp] theorem degree_monomial {R : Type u} {a : R} [semiring R] (n : \u2115) (ha : a \u2260 0) : degree (coe_fn (monomial n) a) = \u2191n := sorry\n\n@[simp] theorem degree_C_mul_X_pow {R : Type u} {a : R} [semiring R] (n : \u2115) (ha : a \u2260 0) : degree (coe_fn C a * X ^ n) = \u2191n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (degree (coe_fn C a * X ^ n) = \u2191n)) (Eq.symm single_eq_C_mul_X)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (degree (coe_fn (monomial n) a) = \u2191n)) (degree_monomial n ha))) (Eq.refl \u2191n))\n\ntheorem degree_monomial_le {R : Type u} [semiring R] (n : \u2115) (a : R) : degree (coe_fn (monomial n) a) \u2264 \u2191n := sorry\n\ntheorem degree_C_mul_X_pow_le {R : Type u} [semiring R] (n : \u2115) (a : R) : degree (coe_fn C a * X ^ n) \u2264 \u2191n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (degree (coe_fn C a * X ^ n) \u2264 \u2191n)) (C_mul_X_pow_eq_monomial a n)))\n    (degree_monomial_le n a)\n\n@[simp] theorem nat_degree_C_mul_X_pow {R : Type u} [semiring R] (n : \u2115) (a : R) (ha : a \u2260 0) : nat_degree (coe_fn C a * X ^ n) = n :=\n  nat_degree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)\n\n@[simp] theorem nat_degree_C_mul_X {R : Type u} [semiring R] (a : R) (ha : a \u2260 0) : nat_degree (coe_fn C a * X) = 1 := sorry\n\n@[simp] theorem nat_degree_monomial {R : Type u} [semiring R] (i : \u2115) (r : R) (hr : r \u2260 0) : nat_degree (coe_fn (monomial i) r) = i :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_degree (coe_fn (monomial i) r) = i)) (Eq.symm (C_mul_X_pow_eq_monomial r i))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_degree (coe_fn C r * X ^ i) = i)) (nat_degree_C_mul_X_pow i r hr))) (Eq.refl i))\n\ntheorem coeff_eq_zero_of_degree_lt {R : Type u} {n : \u2115} [semiring R] {p : polynomial R} (h : degree p < \u2191n) : coeff p n = 0 :=\n  iff.mp not_not (mt le_degree_of_ne_zero (not_le_of_gt h))\n\ntheorem coeff_eq_zero_of_nat_degree_lt {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} (h : nat_degree p < n) : coeff p n = 0 := sorry\n\n@[simp] theorem coeff_nat_degree_succ_eq_zero {R : Type u} [semiring R] {p : polynomial R} : coeff p (nat_degree p + 1) = 0 :=\n  coeff_eq_zero_of_nat_degree_lt (lt_add_one (nat_degree p))\n\n-- We need the explicit `decidable` argument here because an exotic one shows up in a moment!\n\ntheorem ite_le_nat_degree_coeff {R : Type u} [semiring R] (p : polynomial R) (n : \u2115) (I : Decidable (n < 1 + nat_degree p)) : ite (n < 1 + nat_degree p) (coeff p n) 0 = coeff p n := sorry\n\ntheorem as_sum_support {R : Type u} [semiring R] (p : polynomial R) : p = finset.sum (finsupp.support p) fun (i : \u2115) => coe_fn (monomial i) (coeff p i) :=\n  Eq.symm (finsupp.sum_single p)\n\ntheorem as_sum_support_C_mul_X_pow {R : Type u} [semiring R] (p : polynomial R) : p = finset.sum (finsupp.support p) fun (i : \u2115) => coe_fn C (coeff p i) * X ^ i := sorry\n\n/--\nWe can reexpress a sum over `p.support` as a sum over `range n`,\nfor any `n` satisfying `p.nat_degree < n`.\n-/\ntheorem sum_over_range' {R : Type u} {S : Type v} [semiring R] [add_comm_monoid S] (p : polynomial R) {f : \u2115 \u2192 R \u2192 S} (h : \u2200 (n : \u2115), f n 0 = 0) (n : \u2115) (w : nat_degree p < n) : finsupp.sum p f = finset.sum (finset.range n) fun (a : \u2115) => f a (coeff p a) :=\n  finsupp.sum_of_support_subset p (supp_subset_range w) f fun (n_1 : \u2115) (hn : n_1 \u2208 finset.range n) => h n_1\n\n/--\nWe can reexpress a sum over `p.support` as a sum over `range (p.nat_degree + 1)`.\n-/\ntheorem sum_over_range {R : Type u} {S : Type v} [semiring R] [add_comm_monoid S] (p : polynomial R) {f : \u2115 \u2192 R \u2192 S} (h : \u2200 (n : \u2115), f n 0 = 0) : finsupp.sum p f = finset.sum (finset.range (nat_degree p + 1)) fun (a : \u2115) => f a (coeff p a) :=\n  sum_over_range' p h (nat_degree p + 1) (lt_add_one (nat_degree p))\n\ntheorem as_sum_range' {R : Type u} [semiring R] (p : polynomial R) (n : \u2115) (w : nat_degree p < n) : p = finset.sum (finset.range n) fun (i : \u2115) => coe_fn (monomial i) (coeff p i) :=\n  Eq.trans (Eq.symm (finsupp.sum_single p)) (sum_over_range' p (fun (n : \u2115) => finsupp.single_zero) n w)\n\ntheorem as_sum_range {R : Type u} [semiring R] (p : polynomial R) : p = finset.sum (finset.range (nat_degree p + 1)) fun (i : \u2115) => coe_fn (monomial i) (coeff p i) :=\n  Eq.trans (Eq.symm (finsupp.sum_single p)) (sum_over_range p fun (n : \u2115) => finsupp.single_zero)\n\ntheorem as_sum_range_C_mul_X_pow {R : Type u} [semiring R] (p : polynomial R) : p = finset.sum (finset.range (nat_degree p + 1)) fun (i : \u2115) => coe_fn C (coeff p i) * X ^ i := sorry\n\ntheorem coeff_ne_zero_of_eq_degree {R : Type u} {n : \u2115} [semiring R] {p : polynomial R} (hn : degree p = \u2191n) : coeff p n \u2260 0 :=\n  fun (h : coeff p n = 0) => iff.mp finsupp.mem_support_iff (finset.mem_of_max hn) h\n\ntheorem eq_X_add_C_of_degree_le_one {R : Type u} [semiring R] {p : polynomial R} (h : degree p \u2264 1) : p = coe_fn C (coeff p 1) * X + coe_fn C (coeff p 0) := sorry\n\ntheorem eq_X_add_C_of_degree_eq_one {R : Type u} [semiring R] {p : polynomial R} (h : degree p = 1) : p = coe_fn C (leading_coeff p) * X + coe_fn C (coeff p 0) := sorry\n\ntheorem eq_X_add_C_of_nat_degree_le_one {R : Type u} [semiring R] {p : polynomial R} (h : nat_degree p \u2264 1) : p = coe_fn C (coeff p 1) * X + coe_fn C (coeff p 0) :=\n  eq_X_add_C_of_degree_le_one (degree_le_of_nat_degree_le h)\n\ntheorem exists_eq_X_add_C_of_nat_degree_le_one {R : Type u} [semiring R] {p : polynomial R} (h : nat_degree p \u2264 1) : \u2203 (a : R), \u2203 (b : R), p = coe_fn C a * X + coe_fn C b :=\n  Exists.intro (coeff p 1) (Exists.intro (coeff p 0) (eq_X_add_C_of_nat_degree_le_one h))\n\ntheorem degree_X_pow_le {R : Type u} [semiring R] (n : \u2115) : degree (X ^ n) \u2264 \u2191n := sorry\n\ntheorem degree_X_le {R : Type u} [semiring R] : degree X \u2264 1 :=\n  degree_monomial_le 1 1\n\ntheorem nat_degree_X_le {R : Type u} [semiring R] : nat_degree X \u2264 1 :=\n  nat_degree_le_of_degree_le degree_X_le\n\ntheorem support_C_mul_X_pow {R : Type u} [semiring R] (c : R) (n : \u2115) : finsupp.support (coe_fn C c * X ^ n) \u2286 singleton n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (finsupp.support (coe_fn C c * X ^ n) \u2286 singleton n)) (C_mul_X_pow_eq_monomial c n)))\n    finsupp.support_single_subset\n\ntheorem mem_support_C_mul_X_pow {R : Type u} [semiring R] {n : \u2115} {a : \u2115} {c : R} (h : a \u2208 finsupp.support (coe_fn C c * X ^ n)) : a = n :=\n  iff.mp finset.mem_singleton (support_C_mul_X_pow c n h)\n\ntheorem card_support_C_mul_X_pow_le_one {R : Type u} [semiring R] {c : R} {n : \u2115} : finset.card (finsupp.support (coe_fn C c * X ^ n)) \u2264 1 := sorry\n\ntheorem card_supp_le_succ_nat_degree {R : Type u} [semiring R] (p : polynomial R) : finset.card (finsupp.support p) \u2264 nat_degree p + 1 := sorry\n\ntheorem le_degree_of_mem_supp {R : Type u} [semiring R] {p : polynomial R} (a : \u2115) : a \u2208 finsupp.support p \u2192 \u2191a \u2264 degree p :=\n  le_degree_of_ne_zero \u2218 iff.mp mem_support_iff_coeff_ne_zero\n\ntheorem nonempty_support_iff {R : Type u} [semiring R] {p : polynomial R} : finset.nonempty (finsupp.support p) \u2194 p \u2260 0 := sorry\n\ntheorem support_C_mul_X_pow_nonzero {R : Type u} [semiring R] {c : R} {n : \u2115} (h : c \u2260 0) : finsupp.support (coe_fn C c * X ^ n) = singleton n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (finsupp.support (coe_fn C c * X ^ n) = singleton n)) (C_mul_X_pow_eq_monomial c n)))\n    (finsupp.support_single_ne_zero h)\n\n@[simp] theorem degree_one {R : Type u} [semiring R] [nontrivial R] : degree 1 = 0 :=\n  degree_C ((fun (this : 1 \u2260 0) => this) (ne.symm zero_ne_one))\n\n@[simp] theorem degree_X {R : Type u} [semiring R] [nontrivial R] : degree X = 1 :=\n  degree_monomial 1 one_ne_zero\n\n@[simp] theorem nat_degree_X {R : Type u} [semiring R] [nontrivial R] : nat_degree X = 1 :=\n  nat_degree_eq_of_degree_eq_some degree_X\n\ntheorem coeff_mul_X_sub_C {R : Type u} [ring R] {p : polynomial R} {r : R} {a : \u2115} : coeff (p * (X - coe_fn C r)) (a + 1) = coeff p a - coeff p (a + 1) * r := sorry\n\ntheorem C_eq_int_cast {R : Type u} [ring R] (n : \u2124) : coe_fn C \u2191n = \u2191n :=\n  ring_hom.map_int_cast C n\n\n@[simp] theorem degree_neg {R : Type u} [ring R] (p : polynomial R) : degree (-p) = degree p := sorry\n\n@[simp] theorem nat_degree_neg {R : Type u} [ring R] (p : polynomial R) : nat_degree (-p) = nat_degree p := sorry\n\n@[simp] theorem nat_degree_int_cast {R : Type u} [ring R] (n : \u2124) : nat_degree \u2191n = 0 := sorry\n\n/-- The second-highest coefficient, or 0 for constants -/\ndef next_coeff {R : Type u} [semiring R] (p : polynomial R) : R :=\n  ite (nat_degree p = 0) 0 (coeff p (nat_degree p - 1))\n\n@[simp] theorem next_coeff_C_eq_zero {R : Type u} [semiring R] (c : R) : next_coeff (coe_fn C c) = 0 := sorry\n\ntheorem next_coeff_of_pos_nat_degree {R : Type u} [semiring R] (p : polynomial R) (hp : 0 < nat_degree p) : next_coeff p = coeff p (nat_degree p - 1) := sorry\n\ntheorem coeff_nat_degree_eq_zero_of_degree_lt {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : degree p < degree q) : coeff p (nat_degree q) = 0 :=\n  coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)\n\ntheorem ne_zero_of_degree_gt {R : Type u} [semiring R] {p : polynomial R} {n : with_bot \u2115} (h : n < degree p) : p \u2260 0 :=\n  mt (iff.mpr degree_eq_bot) (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))\n\ntheorem eq_C_of_degree_le_zero {R : Type u} [semiring R] {p : polynomial R} (h : degree p \u2264 0) : p = coe_fn C (coeff p 0) := sorry\n\ntheorem eq_C_of_degree_eq_zero {R : Type u} [semiring R] {p : polynomial R} (h : degree p = 0) : p = coe_fn C (coeff p 0) :=\n  eq_C_of_degree_le_zero (h \u25b8 le_refl (degree p))\n\ntheorem degree_le_zero_iff {R : Type u} [semiring R] {p : polynomial R} : degree p \u2264 0 \u2194 p = coe_fn C (coeff p 0) :=\n  { mp := eq_C_of_degree_le_zero, mpr := fun (h : p = coe_fn C (coeff p 0)) => Eq.symm h \u25b8 degree_C_le }\n\ntheorem degree_add_le {R : Type u} [semiring R] (p : polynomial R) (q : polynomial R) : degree (p + q) \u2264 max (degree p) (degree q) := sorry\n\n@[simp] theorem leading_coeff_zero {R : Type u} [semiring R] : leading_coeff 0 = 0 :=\n  rfl\n\n@[simp] theorem leading_coeff_eq_zero {R : Type u} [semiring R] {p : polynomial R} : leading_coeff p = 0 \u2194 p = 0 := sorry\n\ntheorem leading_coeff_eq_zero_iff_deg_eq_bot {R : Type u} [semiring R] {p : polynomial R} : leading_coeff p = 0 \u2194 degree p = \u22a5 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (leading_coeff p = 0 \u2194 degree p = \u22a5)) (propext leading_coeff_eq_zero)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (p = 0 \u2194 degree p = \u22a5)) (propext degree_eq_bot))) (iff.refl (p = 0)))\n\ntheorem nat_degree_mem_support_of_nonzero {R : Type u} [semiring R] {p : polynomial R} (H : p \u2260 0) : nat_degree p \u2208 finsupp.support p :=\n  iff.mpr (finsupp.mem_support_to_fun p (nat_degree p)) (iff.mpr (not_congr leading_coeff_eq_zero) H)\n\ntheorem nat_degree_eq_support_max' {R : Type u} [semiring R] {p : polynomial R} (h : p \u2260 0) : nat_degree p = finset.max' (finsupp.support p) (iff.mpr nonempty_support_iff h) := sorry\n\ntheorem nat_degree_C_mul_X_pow_le {R : Type u} [semiring R] (a : R) (n : \u2115) : nat_degree (coe_fn C a * X ^ n) \u2264 n :=\n  iff.mpr nat_degree_le_iff_degree_le (degree_C_mul_X_pow_le n a)\n\ntheorem degree_add_eq_left_of_degree_lt {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : degree q < degree p) : degree (p + q) = degree p := sorry\n\ntheorem degree_add_eq_right_of_degree_lt {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : degree p < degree q) : degree (p + q) = degree q :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (degree (p + q) = degree q)) (add_comm p q)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (degree (q + p) = degree q)) (degree_add_eq_left_of_degree_lt h)))\n      (Eq.refl (degree q)))\n\ntheorem degree_add_C {R : Type u} {a : R} [semiring R] {p : polynomial R} (hp : 0 < degree p) : degree (p + coe_fn C a) = degree p :=\n  Eq.subst (add_comm (coe_fn C a) p) degree_add_eq_right_of_degree_lt (lt_of_le_of_lt degree_C_le hp)\n\ntheorem degree_add_eq_of_leading_coeff_add_ne_zero {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : leading_coeff p + leading_coeff q \u2260 0) : degree (p + q) = max (degree p) (degree q) := sorry\n\ntheorem degree_erase_le {R : Type u} [semiring R] (p : polynomial R) (n : \u2115) : degree (finsupp.erase n p) \u2264 degree p := sorry\n\ntheorem degree_erase_lt {R : Type u} [semiring R] {p : polynomial R} (hp : p \u2260 0) : degree (finsupp.erase (nat_degree p) p) < degree p := sorry\n\ntheorem degree_sum_le {R : Type u} [semiring R] {\u03b9 : Type u_1} (s : finset \u03b9) (f : \u03b9 \u2192 polynomial R) : degree (finset.sum s fun (i : \u03b9) => f i) \u2264 finset.sup s fun (b : \u03b9) => degree (f b) := sorry\n\ntheorem degree_mul_le {R : Type u} [semiring R] (p : polynomial R) (q : polynomial R) : degree (p * q) \u2264 degree p + degree q := sorry\n\ntheorem degree_pow_le {R : Type u} [semiring R] (p : polynomial R) (n : \u2115) : degree (p ^ n) \u2264 n \u2022\u2115 degree p := sorry\n\n@[simp] theorem leading_coeff_monomial {R : Type u} [semiring R] (a : R) (n : \u2115) : leading_coeff (coe_fn (monomial n) a) = a := sorry\n\ntheorem leading_coeff_C_mul_X_pow {R : Type u} [semiring R] (a : R) (n : \u2115) : leading_coeff (coe_fn C a * X ^ n) = a :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (leading_coeff (coe_fn C a * X ^ n) = a)) (C_mul_X_pow_eq_monomial a n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (leading_coeff (coe_fn (monomial n) a) = a)) (leading_coeff_monomial a n)))\n      (Eq.refl a))\n\n@[simp] theorem leading_coeff_C {R : Type u} [semiring R] (a : R) : leading_coeff (coe_fn C a) = a :=\n  leading_coeff_monomial a 0\n\n@[simp] theorem leading_coeff_X_pow {R : Type u} [semiring R] (n : \u2115) : leading_coeff (X ^ n) = 1 := sorry\n\n@[simp] theorem leading_coeff_X {R : Type u} [semiring R] : leading_coeff X = 1 := sorry\n\n@[simp] theorem monic_X_pow {R : Type u} [semiring R] (n : \u2115) : monic (X ^ n) :=\n  leading_coeff_X_pow n\n\n@[simp] theorem monic_X {R : Type u} [semiring R] : monic X :=\n  leading_coeff_X\n\n@[simp] theorem leading_coeff_one {R : Type u} [semiring R] : leading_coeff 1 = 1 :=\n  leading_coeff_C 1\n\n@[simp] theorem monic_one {R : Type u} [semiring R] : monic 1 :=\n  leading_coeff_C 1\n\ntheorem monic.ne_zero {R : Type u_1} [semiring R] [nontrivial R] {p : polynomial R} (hp : monic p) : p \u2260 0 := sorry\n\ntheorem monic.ne_zero_of_ne {R : Type u} [semiring R] (h : 0 \u2260 1) {p : polynomial R} (hp : monic p) : p \u2260 0 :=\n  monic.ne_zero hp\n\ntheorem monic.ne_zero_of_polynomial_ne {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} {r : polynomial R} (hp : monic p) (hne : q \u2260 r) : p \u2260 0 :=\n  monic.ne_zero hp\n\ntheorem leading_coeff_add_of_degree_lt {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : degree p < degree q) : leading_coeff (p + q) = leading_coeff q := sorry\n\ntheorem leading_coeff_add_of_degree_eq {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : degree p = degree q) (hlc : leading_coeff p + leading_coeff q \u2260 0) : leading_coeff (p + q) = leading_coeff p + leading_coeff q := sorry\n\n@[simp] theorem coeff_mul_degree_add_degree {R : Type u} [semiring R] (p : polynomial R) (q : polynomial R) : coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q := sorry\n\ntheorem degree_mul' {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : leading_coeff p * leading_coeff q \u2260 0) : degree (p * q) = degree p + degree q := sorry\n\ntheorem degree_mul_monic {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (hq : monic q) : degree (p * q) = degree p + degree q := sorry\n\ntheorem nat_degree_mul' {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : leading_coeff p * leading_coeff q \u2260 0) : nat_degree (p * q) = nat_degree p + nat_degree q := sorry\n\ntheorem leading_coeff_mul' {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : leading_coeff p * leading_coeff q \u2260 0) : leading_coeff (p * q) = leading_coeff p * leading_coeff q := sorry\n\ntheorem leading_coeff_pow' {R : Type u} {n : \u2115} [semiring R] {p : polynomial R} : leading_coeff p ^ n \u2260 0 \u2192 leading_coeff (p ^ n) = leading_coeff p ^ n := sorry\n\ntheorem degree_pow' {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} : leading_coeff p ^ n \u2260 0 \u2192 degree (p ^ n) = n \u2022\u2115 degree p := sorry\n\ntheorem nat_degree_pow' {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} (h : leading_coeff p ^ n \u2260 0) : nat_degree (p ^ n) = n * nat_degree p := sorry\n\ntheorem leading_coeff_mul_monic {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (hq : monic q) : leading_coeff (p * q) = leading_coeff p := sorry\n\n@[simp] theorem leading_coeff_mul_X_pow {R : Type u} [semiring R] {p : polynomial R} {n : \u2115} : leading_coeff (p * X ^ n) = leading_coeff p :=\n  leading_coeff_mul_monic (monic_X_pow n)\n\n@[simp] theorem leading_coeff_mul_X {R : Type u} [semiring R] {p : polynomial R} : leading_coeff (p * X) = leading_coeff p :=\n  leading_coeff_mul_monic monic_X\n\ntheorem nat_degree_mul_le {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} : nat_degree (p * q) \u2264 nat_degree p + nat_degree q := sorry\n\ntheorem subsingleton_of_monic_zero {R : Type u} [semiring R] (h : monic 0) : (\u2200 (p q : polynomial R), p = q) \u2227 \u2200 (a b : R), a = b := sorry\n\ntheorem zero_le_degree_iff {R : Type u} [semiring R] {p : polynomial R} : 0 \u2264 degree p \u2194 p \u2260 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 degree p \u2194 p \u2260 0)) (ne.def p 0)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (0 \u2264 degree p \u2194 \u00acp = 0)) (Eq.symm (propext degree_eq_bot))))\n      (option.cases_on (degree p) (of_as_true trivial) fun (val : \u2115) => of_as_true trivial))\n\ntheorem degree_nonneg_iff_ne_zero {R : Type u} [semiring R] {p : polynomial R} : 0 \u2264 degree p \u2194 p \u2260 0 := sorry\n\ntheorem nat_degree_eq_zero_iff_degree_le_zero {R : Type u} [semiring R] {p : polynomial R} : nat_degree p = 0 \u2194 degree p \u2264 0 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (nat_degree p = 0 \u2194 degree p \u2264 0)) (Eq.symm (propext nonpos_iff_eq_zero))))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (nat_degree p \u2264 0 \u2194 degree p \u2264 0)) (propext nat_degree_le_iff_degree_le)))\n      (eq.mpr (id (Eq._oldrec (Eq.refl (degree p \u2264 \u21910 \u2194 degree p \u2264 0)) with_bot.coe_zero)) (iff.refl (degree p \u2264 0))))\n\ntheorem degree_le_iff_coeff_zero {R : Type u} [semiring R] (f : polynomial R) (n : with_bot \u2115) : degree f \u2264 n \u2194 \u2200 (m : \u2115), n < \u2191m \u2192 coeff f m = 0 := sorry\n\ntheorem degree_lt_iff_coeff_zero {R : Type u} [semiring R] (f : polynomial R) (n : \u2115) : degree f < \u2191n \u2194 \u2200 (m : \u2115), n \u2264 m \u2192 coeff f m = 0 := sorry\n\ntheorem degree_lt_degree_mul_X {R : Type u} [semiring R] {p : polynomial R} (hp : p \u2260 0) : degree p < degree (p * X) := sorry\n\ntheorem nat_degree_pos_iff_degree_pos {R : Type u} [semiring R] {p : polynomial R} : 0 < nat_degree p \u2194 0 < degree p :=\n  lt_iff_lt_of_le_iff_le nat_degree_le_iff_degree_le\n\ntheorem eq_C_of_nat_degree_le_zero {R : Type u} [semiring R] {p : polynomial R} (h : nat_degree p \u2264 0) : p = coe_fn C (coeff p 0) :=\n  eq_C_of_degree_le_zero (degree_le_of_nat_degree_le h)\n\ntheorem eq_C_of_nat_degree_eq_zero {R : Type u} [semiring R] {p : polynomial R} (h : nat_degree p = 0) : p = coe_fn C (coeff p 0) :=\n  eq_C_of_nat_degree_le_zero (eq.le h)\n\n@[simp] theorem degree_X_pow {R : Type u} [semiring R] [nontrivial R] (n : \u2115) : degree (X ^ n) = \u2191n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (degree (X ^ n) = \u2191n)) (X_pow_eq_monomial n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (degree (coe_fn (monomial n) 1) = \u2191n)) (degree_monomial n one_ne_zero)))\n      (Eq.refl \u2191n))\n\n@[simp] theorem nat_degree_X_pow {R : Type u} [semiring R] [nontrivial R] (n : \u2115) : nat_degree (X ^ n) = n :=\n  nat_degree_eq_of_degree_eq_some (degree_X_pow n)\n\ntheorem not_is_unit_X {R : Type u} [semiring R] [nontrivial R] : \u00acis_unit X := sorry\n\n@[simp] theorem degree_mul_X {R : Type u} [semiring R] [nontrivial R] {p : polynomial R} : degree (p * X) = degree p + 1 := sorry\n\n@[simp] theorem degree_mul_X_pow {R : Type u} {n : \u2115} [semiring R] [nontrivial R] {p : polynomial R} : degree (p * X ^ n) = degree p + \u2191n := sorry\n\ntheorem degree_sub_le {R : Type u} [ring R] (p : polynomial R) (q : polynomial R) : degree (p - q) \u2264 max (degree p) (degree q) := sorry\n\ntheorem degree_sub_lt {R : Type u} [ring R] {p : polynomial R} {q : polynomial R} (hd : degree p = degree q) (hp0 : p \u2260 0) (hlc : leading_coeff p = leading_coeff q) : degree (p - q) < degree p := sorry\n\ntheorem nat_degree_X_sub_C_le {R : Type u} [ring R] {r : R} : nat_degree (X - coe_fn C r) \u2264 1 :=\n  iff.mpr nat_degree_le_iff_degree_le\n    (le_trans (degree_sub_le X (coe_fn C r))\n      (max_le degree_X_le (le_trans degree_C_le (iff.mpr with_bot.coe_le_coe zero_le_one))))\n\ntheorem degree_sum_fin_lt {R : Type u} [ring R] {n : \u2115} (f : fin n \u2192 R) : degree (finset.sum finset.univ fun (i : fin n) => coe_fn C (f i) * X ^ \u2191i) < \u2191n := sorry\n\ntheorem degree_sub_eq_left_of_degree_lt {R : Type u} [ring R] {p : polynomial R} {q : polynomial R} (h : degree q < degree p) : degree (p - q) = degree p := sorry\n\ntheorem degree_sub_eq_right_of_degree_lt {R : Type u} [ring R] {p : polynomial R} {q : polynomial R} (h : degree p < degree q) : degree (p - q) = degree q := sorry\n\n@[simp] theorem degree_X_sub_C {R : Type u} [nontrivial R] [ring R] (a : R) : degree (X - coe_fn C a) = 1 := sorry\n\n@[simp] theorem nat_degree_X_sub_C {R : Type u} [nontrivial R] [ring R] (x : R) : nat_degree (X - coe_fn C x) = 1 :=\n  nat_degree_eq_of_degree_eq_some (degree_X_sub_C x)\n\n@[simp] theorem next_coeff_X_sub_C {R : Type u} [nontrivial R] [ring R] (c : R) : next_coeff (X - coe_fn C c) = -c := sorry\n\ntheorem degree_X_pow_sub_C {R : Type u} [nontrivial R] [ring R] {n : \u2115} (hn : 0 < n) (a : R) : degree (X ^ n - coe_fn C a) = \u2191n := sorry\n\ntheorem X_pow_sub_C_ne_zero {R : Type u} [nontrivial R] [ring R] {n : \u2115} (hn : 0 < n) (a : R) : X ^ n - coe_fn C a \u2260 0 := sorry\n\ntheorem X_sub_C_ne_zero {R : Type u} [nontrivial R] [ring R] (r : R) : X - coe_fn C r \u2260 0 :=\n  pow_one X \u25b8 X_pow_sub_C_ne_zero zero_lt_one r\n\ntheorem nat_degree_X_pow_sub_C {R : Type u} [nontrivial R] [ring R] {n : \u2115} (hn : 0 < n) {r : R} : nat_degree (X ^ n - coe_fn C r) = n := sorry\n\n@[simp] theorem degree_mul {R : Type u} [comm_semiring R] [no_zero_divisors R] {p : polynomial R} {q : polynomial R} : degree (p * q) = degree p + degree q := sorry\n\n@[simp] theorem degree_pow {R : Type u} [comm_semiring R] [no_zero_divisors R] [nontrivial R] (p : polynomial R) (n : \u2115) : degree (p ^ n) = n \u2022\u2115 degree p := sorry\n\n@[simp] theorem leading_coeff_mul {R : Type u} [comm_semiring R] [no_zero_divisors R] (p : polynomial R) (q : polynomial R) : leading_coeff (p * q) = leading_coeff p * leading_coeff q := sorry\n\n@[simp] theorem leading_coeff_X_add_C {R : Type u} [comm_semiring R] [no_zero_divisors R] [nontrivial R] (a : R) (b : R) (ha : a \u2260 0) : leading_coeff (coe_fn C a * X + coe_fn C b) = a := sorry\n\n/-- `polynomial.leading_coeff` bundled as a `monoid_hom` when `R` has `no_zero_divisors`, and thus\n  `leading_coeff` is multiplicative -/\ndef leading_coeff_hom {R : Type u} [comm_semiring R] [no_zero_divisors R] : polynomial R \u2192* R :=\n  monoid_hom.mk leading_coeff sorry leading_coeff_mul\n\n@[simp] theorem leading_coeff_hom_apply {R : Type u} [comm_semiring R] [no_zero_divisors R] (p : polynomial R) : coe_fn leading_coeff_hom p = leading_coeff p :=\n  rfl\n\n@[simp] theorem leading_coeff_pow {R : Type u} [comm_semiring R] [no_zero_divisors R] (p : polynomial R) (n : \u2115) : leading_coeff (p ^ n) = leading_coeff p ^ n :=\n  monoid_hom.map_pow leading_coeff_hom p n\n\n", "meta": {"author": "AurelienSaue", "repo": "Mathlib4_auto", "sha": "590df64109b08190abe22358fabc3eae000943f2", "save_path": "github-repos/lean/AurelienSaue-Mathlib4_auto", "path": "github-repos/lean/AurelienSaue-Mathlib4_auto/Mathlib4_auto-590df64109b08190abe22358fabc3eae000943f2/Mathlib/data/polynomial/degree/definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7003162592944776}}
{"text": "/-\nCopyright (c) 2021 Oliver Nash. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Oliver Nash\n-/\nimport topology.compact_open\nimport topology.uniform_space.uniform_convergence\n\n/-!\n# Compact convergence (uniform convergence on compact sets)\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGiven a topological space `\u03b1` and a uniform space `\u03b2` (e.g., a metric space or a topological group),\nthe space of continuous maps `C(\u03b1, \u03b2)` carries a natural uniform space structure. We define this\nuniform space structure in this file and also prove the following properties of the topology it\ninduces on `C(\u03b1, \u03b2)`:\n\n 1. Given a sequence of continuous functions `F\u2099 : \u03b1 \u2192 \u03b2` together with some continuous `f : \u03b1 \u2192 \u03b2`,\n    then `F\u2099` converges to `f` as a sequence in `C(\u03b1, \u03b2)` iff `F\u2099` converges to `f` uniformly on\n    each compact subset `K` of `\u03b1`.\n 2. Given `F\u2099` and `f` as above and suppose `\u03b1` is locally compact, then `F\u2099` converges to `f` iff\n    `F\u2099` converges to `f` locally uniformly.\n 3. The topology coincides with the compact-open topology.\n\nProperty 1 is essentially true by definition, 2 follows from basic results about uniform\nconvergence, but 3 requires a little work and uses the Lebesgue number lemma.\n\n## The uniform space structure\n\nGiven subsets `K \u2286 \u03b1` and `V \u2286 \u03b2 \u00d7 \u03b2`, let `E(K, V) \u2286 C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)` be the set of pairs of\ncontinuous functions `\u03b1 \u2192 \u03b2` which are `V`-close on `K`:\n$$\n  E(K, V) = \\{ (f, g) | \u2200 (x \u2208 K), (f x, g x) \u2208 V \\}.\n$$\nFixing some `f \u2208 C(\u03b1, \u03b2)`, let `N(K, V, f) \u2286 C(\u03b1, \u03b2)` be the set of continuous functions `\u03b1 \u2192 \u03b2`\nwhich are `V`-close to `f` on `K`:\n$$\n  N(K, V, f) = \\{ g | \u2200 (x \u2208 K), (f x, g x) \u2208 V \\}.\n$$\nUsing this notation we can describe the uniform space structure and the topology it induces.\nSpecifically:\n *  A subset `X \u2286 C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)` is an entourage for the uniform space structure on `C(\u03b1, \u03b2)`\n    iff there exists a compact `K` and entourage `V` such that `E(K, V) \u2286 X`.\n *  A subset `Y \u2286 C(\u03b1, \u03b2)` is a neighbourhood of `f` iff there exists a compact `K` and entourage\n    `V` such that `N(K, V, f) \u2286 Y`.\n\nThe topology on `C(\u03b1, \u03b2)` thus has a natural subbasis (the compact-open subbasis) and a natural\nneighbourhood basis (the compact-convergence neighbourhood basis).\n\n## Main definitions / results\n\n * `compact_open_eq_compact_convergence`: the compact-open topology is equal to the\n   compact-convergence topology.\n * `compact_convergence_uniform_space`: the uniform space structure on `C(\u03b1, \u03b2)`.\n * `mem_compact_convergence_entourage_iff`: a characterisation of the entourages of `C(\u03b1, \u03b2)`.\n * `tendsto_iff_forall_compact_tendsto_uniformly_on`: a sequence of functions `F\u2099` in `C(\u03b1, \u03b2)`\n   converges to some `f` iff `F\u2099` converges to `f` uniformly on each compact subset `K` of `\u03b1`.\n * `tendsto_iff_tendsto_locally_uniformly`: on a locally compact space, a sequence of functions\n   `F\u2099` in `C(\u03b1, \u03b2)` converges to some `f` iff `F\u2099` converges to `f` locally uniformly.\n * `tendsto_iff_tendsto_uniformly`: on a compact space, a sequence of functions `F\u2099` in `C(\u03b1, \u03b2)`\n   converges to some `f` iff `F\u2099` converges to `f` uniformly.\n\n## Implementation details\n\nWe use the forgetful inheritance pattern (see Note [forgetful inheritance]) to make the topology\nof the uniform space structure on `C(\u03b1, \u03b2)` definitionally equal to the compact-open topology.\n\n## TODO\n\n * When `\u03b2` is a metric space, there is natural basis for the compact-convergence topology\n   parameterised by triples `(K, \u03b5, f)` for a real number `\u03b5 > 0`.\n * When `\u03b1` is compact and `\u03b2` is a metric space, the compact-convergence topology (and thus also\n   the compact-open topology) is metrisable.\n * Results about uniformly continuous functions `\u03b3 \u2192 C(\u03b1, \u03b2)` and uniform limits of sequences\n   `\u03b9 \u2192 \u03b3 \u2192 C(\u03b1, \u03b2)`.\n-/\n\nuniverses u\u2081 u\u2082 u\u2083\n\nopen_locale filter uniformity topology\nopen uniform_space set filter\n\nvariables {\u03b1 : Type u\u2081} {\u03b2 : Type u\u2082} [topological_space \u03b1] [uniform_space \u03b2]\nvariables (K : set \u03b1) (V : set (\u03b2 \u00d7 \u03b2)) (f : C(\u03b1, \u03b2))\n\nnamespace continuous_map\n\n/-- Given `K \u2286 \u03b1`, `V \u2286 \u03b2 \u00d7 \u03b2`, and `f : C(\u03b1, \u03b2)`, we define `compact_conv_nhd K V f` to be the set\nof `g : C(\u03b1, \u03b2)` that are `V`-close to `f` on `K`. -/\ndef compact_conv_nhd : set C(\u03b1, \u03b2) := { g | \u2200 (x \u2208 K), (f x, g x) \u2208 V }\n\nvariables {K V}\n\nlemma self_mem_compact_conv_nhd (hV : V \u2208 \ud835\udce4 \u03b2) : f \u2208 compact_conv_nhd K V f :=\n\u03bb x hx, refl_mem_uniformity hV\n\n@[mono] lemma compact_conv_nhd_mono {V' : set (\u03b2 \u00d7 \u03b2)} (hV' : V' \u2286 V) :\n  compact_conv_nhd K V' f \u2286 compact_conv_nhd K V f :=\n\u03bb x hx a ha, hV' (hx a ha)\n\nlemma compact_conv_nhd_mem_comp {g\u2081 g\u2082 : C(\u03b1, \u03b2)} {V' : set (\u03b2 \u00d7 \u03b2)}\n  (hg\u2081 : g\u2081 \u2208 compact_conv_nhd K V f) (hg\u2082 : g\u2082 \u2208 compact_conv_nhd K V' g\u2081) :\n  g\u2082 \u2208 compact_conv_nhd K (V \u25cb V') f :=\n\u03bb x hx, \u27e8g\u2081 x, hg\u2081 x hx, hg\u2082 x hx\u27e9\n\n/-- A key property of `compact_conv_nhd`. It allows us to apply\n`topological_space.nhds_mk_of_nhds_filter_basis` below. -/\nlemma compact_conv_nhd_nhd_basis (hV : V \u2208 \ud835\udce4 \u03b2) :\n  \u2203 (V' \u2208 \ud835\udce4 \u03b2), V' \u2286 V \u2227 \u2200 (g \u2208 compact_conv_nhd K V' f),\n    compact_conv_nhd K V' g \u2286 compact_conv_nhd K V f :=\nbegin\n  obtain \u27e8V', h\u2081, h\u2082\u27e9 := comp_mem_uniformity_sets hV,\n  exact \u27e8V', h\u2081, subset.trans (subset_comp_self_of_mem_uniformity h\u2081) h\u2082, \u03bb g hg g' hg',\n    compact_conv_nhd_mono f h\u2082 (compact_conv_nhd_mem_comp f hg hg')\u27e9,\nend\n\nlemma compact_conv_nhd_subset_inter (K\u2081 K\u2082 : set \u03b1) (V\u2081 V\u2082 : set (\u03b2 \u00d7 \u03b2)) :\n  compact_conv_nhd (K\u2081 \u222a K\u2082) (V\u2081 \u2229 V\u2082) f \u2286\n  compact_conv_nhd K\u2081 V\u2081 f \u2229 compact_conv_nhd K\u2082 V\u2082 f :=\n\u03bb g hg, \u27e8\u03bb x hx, mem_of_mem_inter_left (hg x (mem_union_left K\u2082 hx)),\n         \u03bb x hx, mem_of_mem_inter_right (hg x (mem_union_right K\u2081 hx))\u27e9\n\nlemma compact_conv_nhd_compact_entourage_nonempty :\n  { KV : set \u03b1 \u00d7 set (\u03b2 \u00d7 \u03b2) | is_compact KV.1 \u2227 KV.2 \u2208 \ud835\udce4 \u03b2 }.nonempty :=\n\u27e8\u27e8\u2205, univ\u27e9, is_compact_empty, filter.univ_mem\u27e9\n\nlemma compact_conv_nhd_filter_is_basis : filter.is_basis\n  (\u03bb (KV : set \u03b1 \u00d7 set (\u03b2 \u00d7 \u03b2)), is_compact KV.1 \u2227 KV.2 \u2208 \ud835\udce4 \u03b2)\n  (\u03bb KV, compact_conv_nhd KV.1 KV.2 f) :=\n{ nonempty := compact_conv_nhd_compact_entourage_nonempty,\n  inter    :=\n    begin\n      rintros \u27e8K\u2081, V\u2081\u27e9 \u27e8K\u2082, V\u2082\u27e9 \u27e8hK\u2081, hV\u2081\u27e9 \u27e8hK\u2082, hV\u2082\u27e9,\n      exact \u27e8\u27e8K\u2081 \u222a K\u2082, V\u2081 \u2229 V\u2082\u27e9, \u27e8hK\u2081.union hK\u2082, filter.inter_mem hV\u2081 hV\u2082\u27e9,\n        compact_conv_nhd_subset_inter f K\u2081 K\u2082 V\u2081 V\u2082\u27e9,\n    end, }\n\n/-- A filter basis for the neighbourhood filter of a point in the compact-convergence topology. -/\ndef compact_convergence_filter_basis (f : C(\u03b1, \u03b2)) : filter_basis C(\u03b1, \u03b2) :=\n(compact_conv_nhd_filter_is_basis f).filter_basis\n\nlemma mem_compact_convergence_nhd_filter (Y : set C(\u03b1, \u03b2)) :\n  Y \u2208 (compact_convergence_filter_basis f).filter \u2194\n  \u2203 (K : set \u03b1) (V : set (\u03b2 \u00d7 \u03b2)) (hK : is_compact K) (hV : V \u2208 \ud835\udce4 \u03b2), compact_conv_nhd K V f \u2286 Y :=\nbegin\n  split,\n  { rintros \u27e8X, \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9, hY\u27e9,\n    exact \u27e8K, V, hK, hV, hY\u27e9, },\n  { rintros \u27e8K, V, hK, hV, hY\u27e9,\n    exact \u27e8compact_conv_nhd K V f, \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9, hY\u27e9, },\nend\n\n/-- The compact-convergence topology. In fact, see `compact_open_eq_compact_convergence` this is\nthe same as the compact-open topology. This definition is thus an auxiliary convenience definition\nand is unlikely to be of direct use. -/\ndef compact_convergence_topology : topological_space C(\u03b1, \u03b2) :=\ntopological_space.mk_of_nhds $ \u03bb f, (compact_convergence_filter_basis f).filter\n\nlemma nhds_compact_convergence :\n  @nhds _ compact_convergence_topology f = (compact_convergence_filter_basis f).filter :=\nbegin\n  rw topological_space.nhds_mk_of_nhds_filter_basis;\n  rintros g - \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9,\n  { exact self_mem_compact_conv_nhd g hV, },\n  { obtain \u27e8V', hV', h\u2081, h\u2082\u27e9 := compact_conv_nhd_nhd_basis g hV,\n    exact \u27e8compact_conv_nhd K V' g, \u27e8\u27e8K, V'\u27e9, \u27e8hK, hV'\u27e9, rfl\u27e9, compact_conv_nhd_mono g h\u2081,\n      \u03bb g' hg', \u27e8compact_conv_nhd K V' g', \u27e8\u27e8K, V'\u27e9, \u27e8hK, hV'\u27e9, rfl\u27e9, h\u2082 g' hg'\u27e9\u27e9, },\nend\n\nlemma has_basis_nhds_compact_convergence :\n  has_basis (@nhds _ compact_convergence_topology f)\n  (\u03bb (p : set \u03b1 \u00d7 set (\u03b2 \u00d7 \u03b2)), is_compact p.1 \u2227 p.2 \u2208 \ud835\udce4 \u03b2) (\u03bb p, compact_conv_nhd p.1 p.2 f) :=\n(nhds_compact_convergence f).symm \u25b8 (compact_conv_nhd_filter_is_basis f).has_basis\n\n/-- This is an auxiliary lemma and is unlikely to be of direct use outside of this file. See\n`tendsto_iff_forall_compact_tendsto_uniformly_on` below for the useful version where the topology\nis picked up via typeclass inference. -/\nlemma tendsto_iff_forall_compact_tendsto_uniformly_on'\n  {\u03b9 : Type u\u2083} {p : filter \u03b9} {F : \u03b9 \u2192 C(\u03b1, \u03b2)} :\n  filter.tendsto F p (@nhds _ compact_convergence_topology f) \u2194\n  \u2200 K, is_compact K \u2192 tendsto_uniformly_on (\u03bb i a, F i a) f p K :=\nbegin\n  simp only [(has_basis_nhds_compact_convergence f).tendsto_right_iff, tendsto_uniformly_on,\n    and_imp, prod.forall],\n  refine forall_congr (\u03bb K, _),\n  rw forall_swap,\n  exact forall\u2083_congr (\u03bb hK V hV, iff.rfl),\nend\n\n/-- Any point of `compact_open.gen K U` is also an interior point wrt the topology of compact\nconvergence.\n\nThe topology of compact convergence is thus at least as fine as the compact-open topology. -/\nlemma compact_conv_nhd_subset_compact_open (hK : is_compact K) {U : set \u03b2} (hU : is_open U)\n  (hf : f \u2208 compact_open.gen K U) :\n  \u2203 (V \u2208 \ud835\udce4 \u03b2), is_open V \u2227 compact_conv_nhd K V f \u2286 compact_open.gen K U :=\nbegin\n  obtain \u27e8V, hV\u2081, hV\u2082, hV\u2083\u27e9 := lebesgue_number_of_compact_open (hK.image f.continuous) hU hf,\n  refine \u27e8V, hV\u2081, hV\u2082, _\u27e9,\n  rintros g hg _ \u27e8x, hx, rfl\u27e9,\n  exact hV\u2083 (f x) \u27e8x, hx, rfl\u27e9 (hg x hx),\nend\n\n/-- The point `f` in `compact_conv_nhd K V f` is also an interior point wrt the compact-open\ntopology.\n\nSince `compact_conv_nhd K V f` are a neighbourhood basis at `f` for each `f`, it follows that\nthe compact-open topology is at least as fine as the topology of compact convergence. -/\nlemma Inter_compact_open_gen_subset_compact_conv_nhd (hK : is_compact K) (hV : V \u2208 \ud835\udce4 \u03b2) :\n  \u2203 (\u03b9 : Sort (u\u2081 + 1)) [fintype \u03b9]\n  (C : \u03b9 \u2192 set \u03b1) (hC : \u2200 i, is_compact (C i))\n  (U : \u03b9 \u2192 set \u03b2) (hU : \u2200 i, is_open (U i)),\n  (f \u2208 \u22c2 i, compact_open.gen (C i) (U i)) \u2227\n  (\u22c2 i, compact_open.gen (C i) (U i)) \u2286 compact_conv_nhd K V f :=\nbegin\n  obtain \u27e8W, hW\u2081, hW\u2084, hW\u2082, hW\u2083\u27e9 := comp_open_symm_mem_uniformity_sets hV,\n  obtain \u27e8Z, hZ\u2081, hZ\u2084, hZ\u2082, hZ\u2083\u27e9 := comp_open_symm_mem_uniformity_sets hW\u2081,\n  let U : \u03b1 \u2192 set \u03b1 := \u03bb x, f\u207b\u00b9' (ball (f x) Z),\n  have hU : \u2200 x, is_open (U x) := \u03bb x, f.continuous.is_open_preimage _ (is_open_ball _ hZ\u2084),\n  have hUK : K \u2286 \u22c3 (x : K), U (x : K),\n  { intros x hx,\n    simp only [exists_prop, mem_Union, Union_coe_set, mem_preimage],\n    exact \u27e8(\u27e8x, hx\u27e9 : K), by simp [hx, mem_ball_self (f x) hZ\u2081]\u27e9, },\n  obtain \u27e8t, ht\u27e9 := hK.elim_finite_subcover _ (\u03bb (x : K), hU x.val) hUK,\n  let C : t \u2192 set \u03b1 := \u03bb i, K \u2229 closure (U ((i : K) : \u03b1)),\n  have hC : K \u2286 \u22c3 i, C i,\n  { rw [\u2190 K.inter_Union, subset_inter_iff],\n    refine \u27e8subset.rfl, ht.trans _\u27e9,\n    simp only [set_coe.forall, subtype.coe_mk, Union_subset_iff],\n    exact \u03bb x hx\u2081 hx\u2082, subset_Union_of_subset (\u27e8_, hx\u2082\u27e9 : t) (by simp [subset_closure]) },\n  have hfC : \u2200 (i : t), C i \u2286 f \u207b\u00b9' ball (f ((i : K) : \u03b1)) W,\n  { simp only [\u2190 image_subset_iff, \u2190 mem_preimage],\n    rintros \u27e8\u27e8x, hx\u2081\u27e9, hx\u2082\u27e9,\n    have hZW : closure (ball (f x) Z) \u2286 ball (f x) W,\n    { intros y hy,\n      obtain \u27e8z, hz\u2081, hz\u2082\u27e9 := uniform_space.mem_closure_iff_ball.mp hy hZ\u2081,\n      exact ball_mono hZ\u2083 _ (mem_ball_comp hz\u2082 ((mem_ball_symmetry hZ\u2082).mp hz\u2081)), },\n    calc f '' (K \u2229 closure (U x)) \u2286 f '' (closure (U x)) : image_subset _ (inter_subset_right _ _)\n                              ... \u2286 closure (f '' (U x)) : f.continuous.continuous_on.image_closure\n                              ... \u2286 closure (ball (f x) Z) : by { apply closure_mono, simp, }\n                              ... \u2286 ball (f x) W : hZW, },\n  refine \u27e8t, t.fintype_coe_sort, C,\n          \u03bb i, hK.inter_right is_closed_closure,\n          \u03bb i, ball (f ((i : K) : \u03b1)) W,\n          \u03bb i, is_open_ball _ hW\u2084,\n          by simp [compact_open.gen, hfC],\n          \u03bb g hg x hx, hW\u2083 (mem_comp_rel.mpr _)\u27e9,\n  simp only [mem_Inter, compact_open.gen, mem_set_of_eq, image_subset_iff] at hg,\n  obtain \u27e8y, hy\u27e9 := mem_Union.mp (hC hx),\n  exact \u27e8f y, (mem_ball_symmetry hW\u2082).mp (hfC y hy), mem_preimage.mp (hg y hy)\u27e9,\nend\n\n/-- The compact-open topology is equal to the compact-convergence topology. -/\nlemma compact_open_eq_compact_convergence :\n  continuous_map.compact_open = (compact_convergence_topology : topological_space C(\u03b1, \u03b2)) :=\nbegin\n  rw [compact_convergence_topology, continuous_map.compact_open],\n  refine le_antisymm _ _,\n  { refine \u03bb X hX, is_open_iff_forall_mem_open.mpr (\u03bb f hf, _),\n    have hXf : X \u2208 (compact_convergence_filter_basis f).filter,\n    { rw \u2190 nhds_compact_convergence,\n      exact @is_open.mem_nhds C(\u03b1, \u03b2) compact_convergence_topology _ _ hX hf, },\n    obtain \u27e8-, \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9, hXf\u27e9 := hXf,\n    obtain \u27e8\u03b9, h\u03b9, C, hC, U, hU, h\u2081, h\u2082\u27e9 := Inter_compact_open_gen_subset_compact_conv_nhd f hK hV,\n    haveI := h\u03b9,\n    exact \u27e8\u22c2 i, compact_open.gen (C i) (U i), h\u2082.trans hXf,\n      is_open_Inter (\u03bb i, continuous_map.is_open_gen (hC i) (hU i)), h\u2081\u27e9, },\n  { simp only [topological_space.le_generate_from_iff_subset_is_open, and_imp, exists_prop,\n      forall_exists_index, set_of_subset_set_of],\n    rintros - K hK U hU rfl f hf,\n    obtain \u27e8V, hV, hV', hVf\u27e9 := compact_conv_nhd_subset_compact_open f hK hU hf,\n    exact filter.mem_of_superset (filter_basis.mem_filter_of_mem _ \u27e8\u27e8K, V\u27e9, \u27e8hK, hV\u27e9, rfl\u27e9) hVf, },\nend\n\n/-- The filter on `C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)` which underlies the uniform space structure on `C(\u03b1, \u03b2)`. -/\ndef compact_convergence_uniformity : filter (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2)) :=\n\u2a05 KV \u2208 { KV : set \u03b1 \u00d7 set (\u03b2 \u00d7 \u03b2) | is_compact KV.1 \u2227 KV.2 \u2208 \ud835\udce4 \u03b2 },\n\ud835\udcdf { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 (x : \u03b1), x \u2208 KV.1 \u2192 (fg.1 x, fg.2 x) \u2208 KV.2 }\n\nlemma has_basis_compact_convergence_uniformity_aux :\n  has_basis (@compact_convergence_uniformity \u03b1 \u03b2 _ _)\n    (\u03bb p : set \u03b1 \u00d7 set (\u03b2 \u00d7 \u03b2), is_compact p.1 \u2227 p.2 \u2208 \ud835\udce4 \u03b2)\n    (\u03bb p, { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 p.1, (fg.1 x, fg.2 x) \u2208 p.2 }) :=\nbegin\n  refine filter.has_basis_binfi_principal _ compact_conv_nhd_compact_entourage_nonempty,\n  rintros \u27e8K\u2081, V\u2081\u27e9 \u27e8hK\u2081, hV\u2081\u27e9 \u27e8K\u2082, V\u2082\u27e9 \u27e8hK\u2082, hV\u2082\u27e9,\n  refine \u27e8\u27e8K\u2081 \u222a K\u2082, V\u2081 \u2229 V\u2082\u27e9, \u27e8hK\u2081.union hK\u2082, filter.inter_mem hV\u2081 hV\u2082\u27e9, _\u27e9,\n  simp only [le_eq_subset, prod.forall, set_of_subset_set_of, ge_iff_le, order.preimage,\n      \u2190 forall_and_distrib, mem_inter_iff, mem_union],\n  exact \u03bb f g, forall_imp (\u03bb x, by tauto!),\nend\n\n/-- An intermediate lemma. Usually `mem_compact_convergence_entourage_iff` is more useful. -/\nlemma mem_compact_convergence_uniformity (X : set (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2))) :\n  X \u2208 @compact_convergence_uniformity \u03b1 \u03b2 _ _ \u2194\n  \u2203 (K : set \u03b1) (V : set (\u03b2 \u00d7 \u03b2)) (hK : is_compact K) (hV : V \u2208 \ud835\udce4 \u03b2),\n    { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 K, (fg.1 x, fg.2 x) \u2208 V } \u2286 X :=\nby simp only [has_basis_compact_convergence_uniformity_aux.mem_iff, exists_prop, prod.exists,\n  and_assoc]\n\n/-- Note that we ensure the induced topology is definitionally the compact-open topology. -/\ninstance compact_convergence_uniform_space : uniform_space C(\u03b1, \u03b2) :=\n{ uniformity := compact_convergence_uniformity,\n  refl :=\n    begin\n      simp only [compact_convergence_uniformity, and_imp, filter.le_principal_iff, prod.forall,\n        filter.mem_principal, mem_set_of_eq, le_infi_iff, id_rel_subset],\n      exact \u03bb K V hK hV f x hx, refl_mem_uniformity hV,\n    end,\n  symm :=\n    begin\n      simp only [compact_convergence_uniformity, and_imp, prod.forall, mem_set_of_eq, prod.fst_swap,\n        filter.tendsto_principal, prod.snd_swap, filter.tendsto_infi],\n      intros K V hK hV,\n      obtain \u27e8V', hV', hsymm, hsub\u27e9 := symm_of_uniformity hV,\n      let X := { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 (x : \u03b1), x \u2208 K \u2192 (fg.1 x, fg.2 x) \u2208 V' },\n      have hX : X \u2208 compact_convergence_uniformity :=\n        (mem_compact_convergence_uniformity X).mpr \u27e8K, V', hK, hV', by simp\u27e9,\n      exact filter.eventually_of_mem hX (\u03bb fg hfg x hx, hsub (hsymm _ _ (hfg x hx))),\n    end,\n  comp := \u03bb X hX,\n    begin\n      obtain \u27e8K, V, hK, hV, hX\u27e9 := (mem_compact_convergence_uniformity X).mp hX,\n      obtain \u27e8V', hV', hcomp\u27e9 := comp_mem_uniformity_sets hV,\n      let h := \u03bb (s : set (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2))), s \u25cb s,\n      suffices : h {fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 (x \u2208 K), (fg.1 x, fg.2 x) \u2208 V'} \u2208\n                 compact_convergence_uniformity.lift' h,\n      { apply filter.mem_of_superset this,\n        rintros \u27e8f, g\u27e9 \u27e8z, hz\u2081, hz\u2082\u27e9,\n        refine hX (\u03bb x hx, hcomp _),\n        exact \u27e8z x, hz\u2081 x hx, hz\u2082 x hx\u27e9, },\n      apply filter.mem_lift',\n      exact (mem_compact_convergence_uniformity _).mpr \u27e8K, V', hK, hV', subset.refl _\u27e9,\n    end,\n  is_open_uniformity :=\n    begin\n      rw compact_open_eq_compact_convergence,\n      refine \u03bb Y, forall\u2082_congr (\u03bb f hf, _),\n      simp only [mem_compact_convergence_nhd_filter, mem_compact_convergence_uniformity,\n        prod.forall, set_of_subset_set_of, compact_conv_nhd],\n      refine exists\u2084_congr (\u03bb K V hK hV, \u27e8_, \u03bb hY g hg, hY f g hg rfl\u27e9),\n      rintros hY g\u2081 g\u2082 hg\u2081 rfl,\n      exact hY hg\u2081,\n    end }\n\nlemma mem_compact_convergence_entourage_iff (X : set (C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2))) :\n  X \u2208 \ud835\udce4 C(\u03b1, \u03b2) \u2194 \u2203 (K : set \u03b1) (V : set (\u03b2 \u00d7 \u03b2)) (hK : is_compact K) (hV : V \u2208 \ud835\udce4 \u03b2),\n    { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 K, (fg.1 x, fg.2 x) \u2208 V } \u2286 X :=\nmem_compact_convergence_uniformity X\n\nlemma has_basis_compact_convergence_uniformity :\n  has_basis (\ud835\udce4 C(\u03b1, \u03b2)) (\u03bb p : set \u03b1 \u00d7 set (\u03b2 \u00d7 \u03b2), is_compact p.1 \u2227 p.2 \u2208 \ud835\udce4 \u03b2)\n            (\u03bb p, { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 p.1, (fg.1 x, fg.2 x) \u2208 p.2 }) :=\nhas_basis_compact_convergence_uniformity_aux\n\nlemma _root_.filter.has_basis.compact_convergence_uniformity {\u03b9 : Type*} {pi : \u03b9 \u2192 Prop}\n  {s : \u03b9 \u2192 set (\u03b2 \u00d7 \u03b2)} (h : (\ud835\udce4 \u03b2).has_basis pi s) :\n  has_basis (\ud835\udce4 C(\u03b1, \u03b2)) (\u03bb p : set \u03b1 \u00d7 \u03b9, is_compact p.1 \u2227 pi p.2)\n    (\u03bb p, { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x \u2208 p.1, (fg.1 x, fg.2 x) \u2208 s p.2 }) :=\nbegin\n  refine has_basis_compact_convergence_uniformity.to_has_basis _ _,\n  { rintro \u27e8t\u2081, t\u2082\u27e9 \u27e8h\u2081, h\u2082\u27e9,\n    rcases h.mem_iff.1 h\u2082 with \u27e8i, hpi, hi\u27e9,\n    exact \u27e8(t\u2081, i), \u27e8h\u2081, hpi\u27e9, \u03bb fg hfg x hx, hi (hfg _ hx)\u27e9 },\n  { rintro \u27e8t, i\u27e9 \u27e8ht, hi\u27e9,\n    exact \u27e8(t, s i), \u27e8ht, h.mem_of_mem hi\u27e9, subset.rfl\u27e9 }\nend\n\nvariables {\u03b9 : Type u\u2083} {p : filter \u03b9} {F : \u03b9 \u2192 C(\u03b1, \u03b2)} {f}\n\nlemma tendsto_iff_forall_compact_tendsto_uniformly_on :\n  tendsto F p (\ud835\udcdd f) \u2194 \u2200 K, is_compact K \u2192 tendsto_uniformly_on (\u03bb i a, F i a) f p K :=\nby rw [compact_open_eq_compact_convergence, tendsto_iff_forall_compact_tendsto_uniformly_on']\n\n/-- Locally uniform convergence implies convergence in the compact-open topology. -/\nlemma tendsto_of_tendsto_locally_uniformly\n  (h : tendsto_locally_uniformly (\u03bb i a, F i a) f p) : tendsto F p (\ud835\udcdd f) :=\nbegin\n  rw tendsto_iff_forall_compact_tendsto_uniformly_on,\n  intros K hK,\n  rw \u2190 tendsto_locally_uniformly_on_iff_tendsto_uniformly_on_of_compact hK,\n  exact h.tendsto_locally_uniformly_on,\nend\n\n/-- If every point has a compact neighbourhood, then convergence in the compact-open topology\nimplies locally uniform convergence.\n\nSee also `tendsto_iff_tendsto_locally_uniformly`, especially for T2 spaces. -/\nlemma tendsto_locally_uniformly_of_tendsto\n  (h\u03b1 : \u2200 x : \u03b1, \u2203 n, is_compact n \u2227 n \u2208 \ud835\udcdd x) (h : tendsto F p (\ud835\udcdd f)) :\n  tendsto_locally_uniformly (\u03bb i a, F i a) f p :=\nbegin\n  rw tendsto_iff_forall_compact_tendsto_uniformly_on at h,\n  intros V hV x,\n  obtain \u27e8n, hn\u2081, hn\u2082\u27e9 := h\u03b1 x,\n  exact \u27e8n, hn\u2082, h n hn\u2081 V hV\u27e9,\nend\n\n/-- Convergence in the compact-open topology is the same as locally uniform convergence on a locally\ncompact space.\n\nFor non-T2 spaces, the assumption `locally_compact_space \u03b1` is stronger than we need and in fact\nthe `\u2190` direction is true unconditionally. See `tendsto_locally_uniformly_of_tendsto` and\n`tendsto_of_tendsto_locally_uniformly` for versions requiring weaker hypotheses. -/\nlemma tendsto_iff_tendsto_locally_uniformly [locally_compact_space \u03b1] :\n  tendsto F p (\ud835\udcdd f) \u2194 tendsto_locally_uniformly (\u03bb i a, F i a) f p :=\n\u27e8tendsto_locally_uniformly_of_tendsto exists_compact_mem_nhds, tendsto_of_tendsto_locally_uniformly\u27e9\n\nsection compact_domain\n\nvariables [compact_space \u03b1]\n\nlemma has_basis_compact_convergence_uniformity_of_compact :\n  has_basis (\ud835\udce4 C(\u03b1, \u03b2)) (\u03bb V : set (\u03b2 \u00d7 \u03b2), V \u2208 \ud835\udce4 \u03b2)\n            (\u03bb V, { fg : C(\u03b1, \u03b2) \u00d7 C(\u03b1, \u03b2) | \u2200 x, (fg.1 x, fg.2 x) \u2208 V }) :=\nhas_basis_compact_convergence_uniformity.to_has_basis\n  (\u03bb p hp, \u27e8p.2, hp.2, \u03bb fg hfg x hx, hfg x\u27e9)\n  (\u03bb V hV, \u27e8\u27e8univ, V\u27e9, \u27e8is_compact_univ, hV\u27e9, \u03bb fg hfg x, hfg x (mem_univ x)\u27e9)\n\n/-- Convergence in the compact-open topology is the same as uniform convergence for sequences of\ncontinuous functions on a compact space. -/\nlemma tendsto_iff_tendsto_uniformly :\n  tendsto F p (\ud835\udcdd f) \u2194 tendsto_uniformly (\u03bb i a, F i a) f p :=\nbegin\n  rw [tendsto_iff_forall_compact_tendsto_uniformly_on, \u2190 tendsto_uniformly_on_univ],\n  exact \u27e8\u03bb h, h univ is_compact_univ, \u03bb h K hK, h.mono (subset_univ K)\u27e9,\nend\n\nend compact_domain\n\nend continuous_map\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/topology/uniform_space/compact_convergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7003162428136369}}
{"text": "/-\nCopyright (c) 2022 Aaron Anderson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Aaron Anderson\n-/\nimport model_theory.semantics\n\n/-!\n# Ordered First-Ordered Structures\nThis file defines ordered first-order languages and structures, as well as their theories.\n\n## Main Definitions\n* `first_order.language.order` is the language consisting of a single relation representing `\u2264`.\n* `first_order.language.order_Structure` is the structure on an ordered type, assigning the symbol\nrepresenting `\u2264` to the actual relation `\u2264`.\n* `first_order.language.is_ordered` points out a specific symbol in a language as representing `\u2264`.\n* `first_order.language.is_ordered_structure` indicates that a structure over a\n* `first_order.language.Theory.linear_order` and similar define the theories of preorders,\npartial orders, and linear orders.\n* `first_order.language.Theory.DLO` defines the theory of dense linear orders without endpoints, a\nparticularly useful example in model theory.\n\n\n## Main Results\n* `partial_order`s model the theory of partial orders, `linear_order`s model the theory of\nlinear orders, and dense linear orders without endpoints model `Theory.DLO`.\n\n-/\n\nuniverses u v w w'\n\nnamespace first_order\nnamespace language\nopen_locale first_order\nopen Structure\n\nvariables {L : language.{u v}} {\u03b1 : Type w} {M : Type w'} {n : \u2115}\n\n/-- The language consisting of a single relation representing `\u2264`. -/\nprotected def order : language :=\nlanguage.mk\u2082 empty empty empty empty unit\n\nnamespace order\n\ninstance Structure [has_le M] : language.order.Structure M :=\nStructure.mk\u2082 empty.elim empty.elim empty.elim empty.elim (\u03bb _, (\u2264))\n\ninstance : is_relational (language.order) := language.is_relational_mk\u2082\n\ninstance : subsingleton (language.order.relations n) :=\nlanguage.subsingleton_mk\u2082_relations\n\nend order\n\n/-- A language is ordered if it has a symbol representing `\u2264`. -/\nclass is_ordered (L : language.{u v}) := (le_symb : L.relations 2)\n\nexport is_ordered (le_symb)\n\nsection is_ordered\n\nvariables [is_ordered L]\n\n/-- Joins two terms `t\u2081, t\u2082` in a formula representing `t\u2081 \u2264 t\u2082`. -/\ndef term.le (t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)) : L.bounded_formula \u03b1 n :=\nle_symb.bounded_formula\u2082 t\u2081 t\u2082\n\n/-- Joins two terms `t\u2081, t\u2082` in a formula representing `t\u2081 < t\u2082`. -/\ndef term.lt (t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)) : L.bounded_formula \u03b1 n :=\n(t\u2081.le t\u2082) \u2293 \u223c (t\u2082.le t\u2081)\n\nvariable (L)\n\n/-- The language homomorphism sending the unique symbol `\u2264` of `language.order` to `\u2264` in an ordered\n language. -/\ndef order_Lhom : language.order \u2192\u1d38 L :=\nLhom.mk\u2082 empty.elim empty.elim empty.elim empty.elim (\u03bb _, le_symb)\n\nend is_ordered\n\ninstance : is_ordered language.order := \u27e8unit.star\u27e9\n\n@[simp] lemma order_Lhom_le_symb [L.is_ordered] :\n  (order_Lhom L).on_relation le_symb = (le_symb : L.relations 2) := rfl\n\n@[simp]\nlemma order_Lhom_order : order_Lhom language.order = Lhom.id language.order :=\nLhom.funext (subsingleton.elim _ _) (subsingleton.elim _ _)\n\ninstance : is_ordered (L.sum language.order) := \u27e8sum.inr is_ordered.le_symb\u27e9\n\n/-- The theory of preorders. -/\nprotected def Theory.preorder : language.order.Theory :=\n{le_symb.reflexive, le_symb.transitive}\n\n/-- The theory of partial orders. -/\nprotected def Theory.partial_order : language.order.Theory :=\n{le_symb.reflexive, le_symb.antisymmetric, le_symb.transitive}\n\n/-- The theory of linear orders. -/\nprotected def Theory.linear_order : language.order.Theory :=\n{le_symb.reflexive, le_symb.antisymmetric, le_symb.transitive, le_symb.total}\n\n/-- A sentence indicating that an order has no top element:\n$\\forall x, \\exists y, \\neg y \\le x$.   -/\nprotected def sentence.no_top_order : language.order.sentence := \u2200' \u2203' \u223c ((&1).le &0)\n\n/-- A sentence indicating that an order has no bottom element:\n$\\forall x, \\exists y, \\neg x \\le y$. -/\nprotected def sentence.no_bot_order : language.order.sentence := \u2200' \u2203' \u223c ((&0).le &1)\n\n/-- A sentence indicating that an order is dense:\n$\\forall x, \\forall y, x < y \\to \\exists z, x < z \\wedge z < y$. -/\nprotected def sentence.densely_ordered : language.order.sentence :=\n\u2200' \u2200' (((&0).lt &1) \u27f9 (\u2203' (((&0).lt &2) \u2293 ((&2).lt &1))))\n\n/-- The theory of dense linear orders without endpoints. -/\nprotected def Theory.DLO : language.order.Theory :=\nTheory.linear_order \u222a {sentence.no_top_order, sentence.no_bot_order, sentence.densely_ordered}\n\nvariables (L M)\n\n/-- A structure is ordered if its language has a `\u2264` symbol whose interpretation is -/\nabbreviation is_ordered_structure [is_ordered L] [has_le M] [L.Structure M] : Prop :=\nLhom.is_expansion_on (order_Lhom L) M\n\nvariables {L M}\n\n@[simp] lemma is_ordered_structure_iff [is_ordered L] [has_le M] [L.Structure M] :\n  L.is_ordered_structure M \u2194 Lhom.is_expansion_on (order_Lhom L) M := iff.rfl\n\ninstance is_ordered_structure_has_le [has_le M] :\n  is_ordered_structure language.order M :=\nbegin\n  rw [is_ordered_structure_iff, order_Lhom_order],\n  exact Lhom.id_is_expansion_on M,\nend\n\ninstance model_preorder [preorder M] :\n  M \u22a8 Theory.preorder :=\nbegin\n  simp only [Theory.preorder, Theory.model_iff, set.mem_insert_iff, set.mem_singleton_iff,\n    forall_eq_or_imp, relations.realize_reflexive, rel_map_apply\u2082, forall_eq,\n    relations.realize_transitive],\n  exact \u27e8le_refl, \u03bb _ _ _, le_trans\u27e9\nend\n\ninstance model_partial_order [partial_order M] :\n  M \u22a8 Theory.partial_order :=\nbegin\n  simp only [Theory.partial_order, Theory.model_iff, set.mem_insert_iff, set.mem_singleton_iff,\n    forall_eq_or_imp, relations.realize_reflexive, rel_map_apply\u2082, relations.realize_antisymmetric,\n    forall_eq, relations.realize_transitive],\n  exact \u27e8le_refl, \u03bb _ _, le_antisymm, \u03bb _ _ _, le_trans\u27e9,\nend\n\ninstance model_linear_order [linear_order M] :\n  M \u22a8 Theory.linear_order :=\nbegin\n  simp only [Theory.linear_order, Theory.model_iff, set.mem_insert_iff, set.mem_singleton_iff,\n    forall_eq_or_imp, relations.realize_reflexive, rel_map_apply\u2082, relations.realize_antisymmetric,\n    relations.realize_transitive, forall_eq, relations.realize_total],\n  exact \u27e8le_refl, \u03bb _ _, le_antisymm, \u03bb _ _ _, le_trans, le_total\u27e9,\nend\n\nsection is_ordered_structure\nvariables [is_ordered L] [L.Structure M]\n\n@[simp] lemma rel_map_le_symb [has_le M] [L.is_ordered_structure M] {a b : M} :\n  rel_map (le_symb : L.relations 2) ![a, b] \u2194 a \u2264 b :=\nbegin\n  rw [\u2190 order_Lhom_le_symb, Lhom.is_expansion_on.map_on_relation],\n  refl,\nend\n\n@[simp] lemma term.realize_le [has_le M] [L.is_ordered_structure M]\n  {t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)} {v : \u03b1 \u2192 M} {xs : fin n \u2192 M} :\n  (t\u2081.le t\u2082).realize v xs \u2194 t\u2081.realize (sum.elim v xs) \u2264 t\u2082.realize (sum.elim v xs) :=\nby simp [term.le]\n\n@[simp] lemma term.realize_lt [preorder M] [L.is_ordered_structure M]\n  {t\u2081 t\u2082 : L.term (\u03b1 \u2295 fin n)} {v : \u03b1 \u2192 M} {xs : fin n \u2192 M} :\n  (t\u2081.lt t\u2082).realize v xs \u2194 t\u2081.realize (sum.elim v xs) < t\u2082.realize (sum.elim v xs) :=\nby simp [term.lt, lt_iff_le_not_le]\n\nend is_ordered_structure\n\nsection has_le\nvariables [has_le M]\n\ntheorem realize_no_top_order_iff : M \u22a8 sentence.no_top_order \u2194 no_top_order M :=\nbegin\n  simp only [sentence.no_top_order, sentence.realize, formula.realize, bounded_formula.realize_all,\n    bounded_formula.realize_ex, bounded_formula.realize_not, realize, term.realize_le,\n    sum.elim_inr],\n  refine \u27e8\u03bb h, \u27e8\u03bb a, h a\u27e9, _\u27e9,\n  introsI h a,\n  exact exists_not_le a,\nend\n\n@[simp] lemma realize_no_top_order [h : no_top_order M] : M \u22a8 sentence.no_top_order :=\nrealize_no_top_order_iff.2 h\n\ntheorem realize_no_bot_order_iff : M \u22a8 sentence.no_bot_order \u2194 no_bot_order M :=\nbegin\n  simp only [sentence.no_bot_order, sentence.realize, formula.realize, bounded_formula.realize_all,\n    bounded_formula.realize_ex, bounded_formula.realize_not, realize, term.realize_le,\n    sum.elim_inr],\n  refine \u27e8\u03bb h, \u27e8\u03bb a, h a\u27e9, _\u27e9,\n  introsI h a,\n  exact exists_not_ge a,\nend\n\n@[simp] lemma realize_no_bot_order [h : no_bot_order M] : M \u22a8 sentence.no_bot_order :=\nrealize_no_bot_order_iff.2 h\n\nend has_le\n\ntheorem realize_densely_ordered_iff [preorder M] :\n  M \u22a8 sentence.densely_ordered \u2194 densely_ordered M :=\nbegin\n  simp only [sentence.densely_ordered, sentence.realize, formula.realize,\n    bounded_formula.realize_imp, bounded_formula.realize_all, realize, term.realize_lt,\n    sum.elim_inr, bounded_formula.realize_ex, bounded_formula.realize_inf],\n  refine \u27e8\u03bb h, \u27e8\u03bb a b ab, h a b ab\u27e9, _\u27e9,\n  introsI h a b ab,\n  exact exists_between ab,\nend\n\n@[simp] lemma realize_densely_ordered [preorder M] [h : densely_ordered M] :\n  M \u22a8 sentence.densely_ordered :=\nrealize_densely_ordered_iff.2 h\n\ninstance model_DLO [linear_order M] [densely_ordered M] [no_top_order M] [no_bot_order M] :\n  M \u22a8 Theory.DLO :=\nbegin\n  simp only [Theory.DLO, set.union_insert, set.union_singleton, Theory.model_iff,\n    set.mem_insert_iff, forall_eq_or_imp, realize_no_top_order, realize_no_bot_order,\n    realize_densely_ordered, true_and],\n  rw \u2190 Theory.model_iff,\n  apply_instance,\nend\n\nend language\nend first_order\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/model_theory/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7003030463049438}}
{"text": "/-\nCopyright (c) 2021 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anne Baanen\n-/\n\nimport field_theory.primitive_element\nimport linear_algebra.determinant\nimport linear_algebra.finite_dimensional\nimport linear_algebra.matrix.charpoly.minpoly\nimport linear_algebra.matrix.to_linear_equiv\nimport field_theory.is_alg_closed.algebraic_closure\nimport field_theory.galois\n\n/-!\n# Norm for (finite) ring extensions\n\nSuppose we have an `R`-algebra `S` with a finite basis. For each `s : S`,\nthe determinant of the linear map given by multiplying by `s` gives information\nabout the roots of the minimal polynomial of `s` over `R`.\n\n## Implementation notes\n\nTypically, the norm is defined specifically for finite field extensions.\nThe current definition is as general as possible and the assumption that we have\nfields or that the extension is finite is added to the lemmas as needed.\n\nWe only define the norm for left multiplication (`algebra.left_mul_matrix`,\ni.e. `algebra.lmul_left`).\nFor now, the definitions assume `S` is commutative, so the choice doesn't\nmatter anyway.\n\nSee also `algebra.trace`, which is defined similarly as the trace of\n`algebra.left_mul_matrix`.\n\n## References\n\n * https://en.wikipedia.org/wiki/Field_norm\n\n-/\n\nuniverses u v w\n\nvariables {R S T : Type*} [comm_ring R] [comm_ring S]\nvariables [algebra R S]\nvariables {K L F : Type*} [field K] [field L] [field F]\nvariables [algebra K L] [algebra K F]\nvariables {\u03b9 : Type w} [fintype \u03b9]\n\nopen finite_dimensional\nopen linear_map\nopen matrix polynomial\n\nopen_locale big_operators\nopen_locale matrix\n\nnamespace algebra\n\nvariables (R)\n\n/-- The norm of an element `s` of an `R`-algebra is the determinant of `(*) s`. -/\nnoncomputable def norm : S \u2192* R :=\nlinear_map.det.comp (lmul R S).to_ring_hom.to_monoid_hom\n\nlemma norm_apply (x : S) : norm R x = linear_map.det (lmul R S x) := rfl\n\nlemma norm_eq_one_of_not_exists_basis\n  (h : \u00ac \u2203 (s : finset S), nonempty (basis s R S)) (x : S) : norm R x = 1 :=\nby { rw [norm_apply, linear_map.det], split_ifs with h, refl }\n\nvariables {R}\n\n-- Can't be a `simp` lemma because it depends on a choice of basis\nlemma norm_eq_matrix_det [decidable_eq \u03b9] (b : basis \u03b9 R S) (s : S) :\n  norm R s = matrix.det (algebra.left_mul_matrix b s) :=\nby rw [norm_apply, \u2190 linear_map.det_to_matrix b, to_matrix_lmul_eq]\n\n/-- If `x` is in the base field `K`, then the norm is `x ^ [L : K]`. -/\nlemma norm_algebra_map_of_basis (b : basis \u03b9 R S) (x : R) :\n  norm R (algebra_map R S x) = x ^ fintype.card \u03b9 :=\nbegin\n  haveI := classical.dec_eq \u03b9,\n  rw [norm_apply, \u2190 det_to_matrix b, lmul_algebra_map],\n  convert @det_diagonal _ _ _ _ _ (\u03bb (i : \u03b9), x),\n  { ext i j, rw [to_matrix_lsmul, matrix.diagonal] },\n  { rw [finset.prod_const, finset.card_univ] }\nend\n\n/-- If `x` is in the base field `K`, then the norm is `x ^ [L : K]`.\n\n(If `L` is not finite-dimensional over `K`, then `norm = 1 = x ^ 0 = x ^ (finrank L K)`.)\n-/\n@[simp]\nprotected lemma norm_algebra_map (x : K) : norm K (algebra_map K L x) = x ^ finrank K L :=\nbegin\n  by_cases H : \u2203 (s : finset L), nonempty (basis s K L),\n  { rw [norm_algebra_map_of_basis H.some_spec.some, finrank_eq_card_basis H.some_spec.some] },\n  { rw [norm_eq_one_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis, pow_zero],\n    rintros \u27e8s, \u27e8b\u27e9\u27e9,\n    exact H \u27e8s, \u27e8b\u27e9\u27e9 },\nend\n\nsection eq_prod_roots\n\n/-- Given `pb : power_basis K S`, then the norm of `pb.gen` is\n`(-1) ^ pb.dim * coeff (minpoly K pb.gen) 0`. -/\nlemma power_basis.norm_gen_eq_coeff_zero_minpoly [algebra K S] (pb : power_basis K S) :\n  norm K pb.gen = (-1) ^ pb.dim * coeff (minpoly K pb.gen) 0 :=\nbegin\n  rw [norm_eq_matrix_det pb.basis, det_eq_sign_charpoly_coeff, charpoly_left_mul_matrix,\n    fintype.card_fin]\nend\n\n/-- Given `pb : power_basis K S`, then the norm of `pb.gen` is\n`((minpoly K pb.gen).map (algebra_map K F)).roots.prod`. -/\nlemma power_basis.norm_gen_eq_prod_roots [algebra K S] (pb : power_basis K S)\n  (hf : (minpoly K pb.gen).splits (algebra_map K F)) :\n  algebra_map K F (norm K pb.gen) =\n    ((minpoly K pb.gen).map (algebra_map K F)).roots.prod :=\nbegin\n  rw [power_basis.norm_gen_eq_coeff_zero_minpoly, \u2190 pb.nat_degree_minpoly, ring_hom.map_mul,\n    \u2190 coeff_map, prod_roots_eq_coeff_zero_of_monic_of_split\n      ((minpoly.monic (power_basis.is_integral_gen _)).map _)\n      ((splits_id_iff_splits _).2 hf), nat_degree_map, map_pow, \u2190 mul_assoc, \u2190 mul_pow],\n  simp\nend\n\nend eq_prod_roots\n\nsection eq_zero_iff\n\nlemma norm_eq_zero_iff_of_basis [is_domain R] [is_domain S] (b : basis \u03b9 R S) {x : S} :\n  algebra.norm R x = 0 \u2194 x = 0 :=\nbegin\n  have h\u03b9 : nonempty \u03b9 := b.index_nonempty,\n  letI := classical.dec_eq \u03b9,\n  rw algebra.norm_eq_matrix_det b,\n  split,\n  { rw \u2190 matrix.exists_mul_vec_eq_zero_iff,\n    rintros \u27e8v, v_ne, hv\u27e9,\n    rw [\u2190 b.equiv_fun.apply_symm_apply v, b.equiv_fun_symm_apply, b.equiv_fun_apply,\n        algebra.left_mul_matrix_mul_vec_repr] at hv,\n    refine (mul_eq_zero.mp (b.ext_elem $ \u03bb i, _)).resolve_right (show \u2211 i, v i \u2022 b i \u2260 0, from _),\n    { simpa only [linear_equiv.map_zero, pi.zero_apply] using congr_fun hv i },\n    { contrapose! v_ne with sum_eq,\n      apply b.equiv_fun.symm.injective,\n      rw [b.equiv_fun_symm_apply, sum_eq, linear_equiv.map_zero] } },\n  { rintro rfl,\n    rw [alg_hom.map_zero, matrix.det_zero h\u03b9] },\nend\n\nlemma norm_ne_zero_iff_of_basis [is_domain R] [is_domain S] (b : basis \u03b9 R S) {x : S} :\n  algebra.norm R x \u2260 0 \u2194 x \u2260 0 :=\nnot_iff_not.mpr (algebra.norm_eq_zero_iff_of_basis b)\n\n/-- See also `algebra.norm_eq_zero_iff'` if you already have rewritten with `algebra.norm_apply`. -/\n@[simp]\nlemma norm_eq_zero_iff [finite_dimensional K L] {x : L} :\n  algebra.norm K x = 0 \u2194 x = 0 :=\nalgebra.norm_eq_zero_iff_of_basis (basis.of_vector_space K L)\n\n/-- This is `algebra.norm_eq_zero_iff` composed with `algebra.norm_apply`. -/\n@[simp]\nlemma norm_eq_zero_iff' [finite_dimensional K L] {x : L} :\n  linear_map.det (algebra.lmul K L x) = 0 \u2194 x = 0 :=\nalgebra.norm_eq_zero_iff_of_basis (basis.of_vector_space K L)\n\nend eq_zero_iff\n\nopen intermediate_field\n\nvariable (K)\n\nlemma norm_eq_norm_adjoin [finite_dimensional K L] [is_separable K L] (x : L) :\n  norm K x = norm K (adjoin_simple.gen K x) ^ finrank K\u27eex\u27ef L :=\nbegin\n  letI := is_separable_tower_top_of_is_separable K K\u27eex\u27ef L,\n  let pbL := field.power_basis_of_finite_of_separable K\u27eex\u27ef L,\n  let pbx := intermediate_field.adjoin.power_basis (is_separable.is_integral K x),\n  rw [\u2190 adjoin_simple.algebra_map_gen K x, norm_eq_matrix_det (pbx.basis.smul pbL.basis) _,\n    smul_left_mul_matrix_algebra_map, det_block_diagonal, norm_eq_matrix_det pbx.basis],\n  simp only [finset.card_fin, finset.prod_const],\n  congr,\n  rw [\u2190 power_basis.finrank, adjoin_simple.algebra_map_gen K x]\nend\n\nvariable {K}\n\nsection intermediate_field\n\nlemma _root_.intermediate_field.adjoin_simple.norm_gen_eq_one {x : L}\n  (hx : \u00ac_root_.is_integral K x) : norm K (adjoin_simple.gen K x) = 1 :=\nbegin\n  rw [norm_eq_one_of_not_exists_basis],\n  contrapose! hx,\n  obtain \u27e8s, \u27e8b\u27e9\u27e9 := hx,\n  refine is_integral_of_mem_of_fg (K\u27eex\u27ef).to_subalgebra _ x _,\n  { exact (submodule.fg_iff_finite_dimensional _).mpr (of_finset_basis b) },\n  { exact intermediate_field.subset_adjoin K _ (set.mem_singleton x) }\nend\n\nlemma _root_.intermediate_field.adjoin_simple.norm_gen_eq_prod_roots (x : L)\n  (hf : (minpoly K x).splits (algebra_map K F)) :\n  (algebra_map K F) (norm K (adjoin_simple.gen K x)) =\n    ((minpoly K x).map (algebra_map K F)).roots.prod :=\nbegin\n  have injKxL := (algebra_map K\u27eex\u27ef L).injective,\n  by_cases hx : _root_.is_integral K x, swap,\n  { simp [minpoly.eq_zero hx, intermediate_field.adjoin_simple.norm_gen_eq_one hx] },\n  have hx' : _root_.is_integral K (adjoin_simple.gen K x),\n  { rwa [\u2190 is_integral_algebra_map_iff injKxL, adjoin_simple.algebra_map_gen],\n    apply_instance },\n  rw [\u2190 adjoin.power_basis_gen hx, power_basis.norm_gen_eq_prod_roots];\n    rw [adjoin.power_basis_gen hx, minpoly.eq_of_algebra_map_eq injKxL hx'];\n    try { simp only [adjoin_simple.algebra_map_gen _ _] },\n  exact hf\nend\n\nend intermediate_field\n\nsection eq_prod_embeddings\n\nopen intermediate_field intermediate_field.adjoin_simple polynomial\n\nvariables (E : Type*) [field E] [algebra K E]\n\nlemma norm_eq_prod_embeddings_gen\n  (pb : power_basis K L)\n  (hE : (minpoly K pb.gen).splits (algebra_map K E)) (hfx : (minpoly K pb.gen).separable) :\n  algebra_map K E (norm K pb.gen) =\n    (@@finset.univ (power_basis.alg_hom.fintype pb)).prod (\u03bb \u03c3, \u03c3 pb.gen) :=\nbegin\n  letI := classical.dec_eq E,\n  rw [power_basis.norm_gen_eq_prod_roots pb hE, fintype.prod_equiv pb.lift_equiv',\n    finset.prod_mem_multiset, finset.prod_eq_multiset_prod, multiset.to_finset_val,\n    multiset.dedup_eq_self.mpr, multiset.map_id],\n  { exact nodup_roots ((separable_map _).mpr hfx) },\n  { intro x, refl },\n  { intro \u03c3, rw [power_basis.lift_equiv'_apply_coe, id.def] }\nend\n\nlemma norm_eq_prod_roots [is_separable K L] [finite_dimensional K L]\n  {x : L} (hF : (minpoly K x).splits (algebra_map K F)) :\n  algebra_map K F (norm K x) = ((minpoly K x).map (algebra_map K F)).roots.prod ^ finrank K\u27eex\u27ef L :=\nby rw [norm_eq_norm_adjoin K x, map_pow,\n  intermediate_field.adjoin_simple.norm_gen_eq_prod_roots _ hF]\n\nvariable (F)\n\nlemma prod_embeddings_eq_finrank_pow [algebra L F] [is_scalar_tower K L F][is_alg_closed E]\n  [is_separable K F] [finite_dimensional K F] (pb : power_basis K L) :\n  \u220f \u03c3 : F \u2192\u2090[K] E, \u03c3 (algebra_map L F pb.gen) =\n  ((@@finset.univ (power_basis.alg_hom.fintype pb)).prod\n    (\u03bb \u03c3 : L \u2192\u2090[K] E, \u03c3 pb.gen)) ^ finrank L F :=\nbegin\n  haveI : finite_dimensional L F := finite_dimensional.right K L F,\n  haveI : is_separable L F := is_separable_tower_top_of_is_separable K L F,\n  letI : fintype (L \u2192\u2090[K] E) := power_basis.alg_hom.fintype pb,\n  letI : \u2200 (f : L \u2192\u2090[K] E), fintype (@@alg_hom L F E _ _ _ _ f.to_ring_hom.to_algebra) := _,\n  rw [fintype.prod_equiv alg_hom_equiv_sigma (\u03bb (\u03c3 : F \u2192\u2090[K] E), _) (\u03bb \u03c3, \u03c3.1 pb.gen),\n     \u2190 finset.univ_sigma_univ, finset.prod_sigma, \u2190 finset.prod_pow],\n  refine finset.prod_congr rfl (\u03bb \u03c3 _, _),\n  { letI : algebra L E := \u03c3.to_ring_hom.to_algebra,\n    simp only [finset.prod_const, finset.card_univ],\n    congr,\n    rw alg_hom.card L F E },\n  { intros \u03c3,\n    simp only [alg_hom_equiv_sigma, equiv.coe_fn_mk, alg_hom.restrict_domain, alg_hom.comp_apply,\n         is_scalar_tower.coe_to_alg_hom'] }\nend\n\nvariable (K)\n\n/-- For `L/K` a finite separable extension of fields and `E` an algebraically closed extension\nof `K`, the norm (down to `K`) of an element `x` of `L` is equal to the product of the images\nof `x` over all the `K`-embeddings `\u03c3`  of `L` into `E`. -/\nlemma norm_eq_prod_embeddings [finite_dimensional K L] [is_separable K L] [is_alg_closed E]\n  {x : L} : algebra_map K E (norm K x) = \u220f \u03c3 : L \u2192\u2090[K] E, \u03c3 x :=\nbegin\n  have hx := is_separable.is_integral K x,\n  rw [norm_eq_norm_adjoin K x, ring_hom.map_pow, \u2190 adjoin.power_basis_gen hx,\n    norm_eq_prod_embeddings_gen E (adjoin.power_basis hx) (is_alg_closed.splits_codomain _)],\n  { exact (prod_embeddings_eq_finrank_pow L E (adjoin.power_basis hx)).symm },\n  { haveI := is_separable_tower_bot_of_is_separable K K\u27eex\u27ef L,\n    exact is_separable.separable K _ }\nend\n\nlemma norm_eq_prod_automorphisms [finite_dimensional K L] [is_galois K L] {x : L}:\n  algebra_map K L (norm K x) = \u220f (\u03c3 : L \u2243\u2090[K] L), \u03c3 x :=\nbegin\n  apply no_zero_smul_divisors.algebra_map_injective L (algebraic_closure L),\n  rw map_prod (algebra_map L (algebraic_closure L)),\n  rw \u2190 fintype.prod_equiv (normal.alg_hom_equiv_aut K (algebraic_closure L) L),\n  { rw \u2190 norm_eq_prod_embeddings,\n    simp only [algebra_map_eq_smul_one, smul_one_smul] },\n  { intro \u03c3,\n    simp only [normal.alg_hom_equiv_aut, alg_hom.restrict_normal', equiv.coe_fn_mk,\n               alg_equiv.coe_of_bijective, alg_hom.restrict_normal_commutes, id.map_eq_id,\n               ring_hom.id_apply] },\nend\n\nlemma is_integral_norm [algebra S L] [algebra S K] [is_scalar_tower S K L]\n  [is_separable K L] [finite_dimensional K L] {x : L} (hx : _root_.is_integral S x) :\n  _root_.is_integral S (norm K x) :=\nbegin\n  have hx' : _root_.is_integral K x := is_integral_of_is_scalar_tower _ hx,\n  rw [\u2190 is_integral_algebra_map_iff (algebra_map K (algebraic_closure L)).injective,\n      norm_eq_prod_roots],\n  { refine (is_integral.multiset_prod (\u03bb y hy, _)).pow _,\n    rw mem_roots_map (minpoly.ne_zero hx') at hy,\n    use [minpoly S x, minpoly.monic hx],\n    rw \u2190 aeval_def at \u22a2 hy,\n    exact minpoly.aeval_of_is_scalar_tower S x y hy },\n  { apply is_alg_closed.splits_codomain },\n  { apply_instance }\nend\n\nend eq_prod_embeddings\n\nend algebra\n", "meta": {"author": "nick-kuhn", "repo": "leantools", "sha": "567a98c031fffe3f270b7b8dea48389bc70d7abb", "save_path": "github-repos/lean/nick-kuhn-leantools", "path": "github-repos/lean/nick-kuhn-leantools/leantools-567a98c031fffe3f270b7b8dea48389bc70d7abb/src/ring_theory/norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417878, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7003030422873119}}
{"text": "import subgroup_world.subgroup_inv_bis -- hide\n\nvariables {G : Type} [group G] {H : set G} -- hide\n\n/-\n## Closed under product\n\nHere you prove finally that the product of elements in a subgroup stays in the subgroup.\n-/\n/- Lemma:\nIf $H\\leq G$, and $x, y \\in H$, then $x y \\in H$.\n-/\nlemma subgroup.mul_mem [h : subgroup H]\n{x y : G} (hx : x \u2208 H) (hy : y \u2208 H) :  x * y \u2208 H :=\nbegin\n  rw show x * y = x * y\u207b\u00b9\u207b\u00b9, by group,\n  apply h.2 _ _ hx (subgroup.inv_mem' hy),\n\n\n\n\n\n\nend\n", "meta": {"author": "mmasdeu", "repo": "fundamental", "sha": "ef60218d34c089beda66b39a85a4604b3604651f", "save_path": "github-repos/lean/mmasdeu-fundamental", "path": "github-repos/lean/mmasdeu-fundamental/fundamental-ef60218d34c089beda66b39a85a4604b3604651f/src/subgroup_world/subgroup_mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7003030376742583}}
{"text": "/-\nCopyright (c) 2019 Neil Strickland. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Neil Strickland\n\nIn this file we give an equivalence from lists in \u2115 with no \nduplicates to arbitrary lists in \u2115.  \n\n-/\n\nimport combinatorics.choose combinatorics.simplicial\n\nopen combinatorics\nopen simplicial.infinite\n\nnamespace natlist\n\n/- The map `spread` converts arbitrary lists to nonduplicating \n   lists, by moving the later entries upwards so that they \n   cannot conflict with the earlier ones.  It uses the map \n   `\u03b4` from the `simplicial.infinite` namespace. \n-/\ndef spread : list \u2115 \u2192 list \u2115 \n| [] := []\n| (i :: l) := i :: ((spread l).map (\u03b4 i))\n\n/- The map `squash` converts nonduplicating lists to arbitrary\n   lists by moving later entries downwards to eliminate the \n   gaps forced by the nonduplicating property.  It uses the \n   map `\u03c3` from the `simplicial.infinite` namespace. Although\n   `squash` is designed to be used on nonduplicating lists, it\n   is convenient to give the definition in a form that does not\n   rely on that property.\n-/\ndef squash : \u2200 (l : list \u2115 ), list \u2115 \n| [] := []\n| (i :: l) := i :: squash (l.map (simplicial.infinite.\u03c3 i.pred))\nusing_well_founded {\n  rel_tac := \u03bb _ _, `[exact \u27e8_, measure_wf list.length\u27e9],\n  dec_tac := well_founded_tactics.default_dec_tac }\n\n@[simp] lemma squash.nil : squash [] = [] := by simp[squash]\n\n@[simp] lemma squash.cons (i : \u2115) (l : list \u2115) : \n  squash (i :: l)  = i :: (squash (l.map (\u03c3 i.pred))) := by simp[squash]\n\nlemma spread.nodup (l : list \u2115) : (spread l).nodup := \nbegin\n  induction l with i l ih,\n  { exact list.nodup_nil },\n  { rw [spread, list.nodup_cons], split,\n    { intro h, rcases list.mem_map.mp h with \u27e8j,\u27e8hm,he\u27e9\u27e9, exact \u03b4_ne i j he },\n    { exact list.nodup.map (\u03b4_inj i) ih } }\nend\n\n@[simp] lemma spread.length (l : list \u2115) : (spread l).length = l.length :=\nbegin\n  induction l with i l ih,\n  { refl },\n  { rw [spread, list.length_cons, list.length_cons, list.length_map, ih] }\nend\n\n@[simp] lemma squash.length : \u2200 (l : list \u2115), (squash l).length = l.length\n| [] := by simp[squash]\n| (i :: l) := \nbegin\n  rw [squash.cons, list.length_cons, squash.length, list.length_map, list.length_cons]\nend\nusing_well_founded {\n  rel_tac := \u03bb _ _, `[exact \u27e8_, measure_wf list.length\u27e9],\n  dec_tac := well_founded_tactics.default_dec_tac }\n\nlemma squash_spread : \u2200 (l : list \u2115), squash (spread l) = l\n| [] := by simp[squash,spread]\n| (i :: l) :=\n  by { rw [spread, squash.cons, list.map_map, \u03c3\u03b4_pred, list.map_id, squash_spread] }\n\nlemma spread_squash : \u2200 {l : list \u2115} (hl : l.nodup), spread (squash l) = l\n| [] _ := by simp[squash,spread]\n| (i :: l) hl := begin\n  rw [list.nodup_cons] at hl,\n  let m := l.map (\u03c3 i.pred),\n  have hm : m.nodup := \u03c3_pred_nodup hl.right hl.left,\n  rw [squash.cons, spread, spread_squash hm],\n  congr' 1, dsimp[m], rw [list.map_map],\n  let p : \u2115 \u2192 \u2115 := (\u03b4 i) \u2218 (\u03c3 i.pred), change l.map p = l,\n  have hp : \u2200 (k : \u2115) (hk : k \u2260 i), p k = k := \n    \u03bb k hk, simplicial.infinite.\u03b4\u03c3_pred hk,\n  have : l.map p = l.map id := \n  begin\n    apply list.map_congr, intros k hk, \n    have : k \u2260 i := \u03bb h, hl.left (h \u25b8 hk),\n    exact \u03b4\u03c3_pred this\n  end,\n  rw [this, list.map_id],\nend\nusing_well_founded {\n  rel_tac := \u03bb _ _, `[exact \u27e8_, measure_wf (\u03bb x, list.length x.1)\u27e9],\n  dec_tac := well_founded_tactics.default_dec_tac }\n\ndef spread_equiv : list \u2115 \u2243 { l : list \u2115 // l.nodup } := {\n  to_fun := \u03bb l, \u27e8spread l, spread.nodup l\u27e9,\n  inv_fun := \u03bb l, squash l.val,\n  left_inv := \u03bb l, squash_spread l,\n  right_inv := \u03bb l, subtype.eq (spread_squash l.property) }\n\n/- We now prove upper bounds for the entries in the lists \n   `spread l` and `squash l`.  This will enable us to define\n   functions related to `spread` and `squash` using `fin n`\n   instead of `\u2115`.   Everything is formulated in terms of the\n   predicates `below_line n l` and `below_triangle n l` for\n   `l : list \u2115`.  The first of these says that all entries \n   of `l` are less than `n`, and the second says that the `i`th\n   entry is less than `n - i`. \n-/\n\ndef below_line : \u2200 (n : \u2115) (l : list \u2115), Prop \n| n [] := true\n| n (i :: l) := i < n \u2227 below_line n l\n\ndef below_triangle : \u2200 (n : \u2115) (l : list \u2115), Prop\n| 0 [] := true\n| 0 (i :: l) := false\n| (n + 1) [] := true\n| (n + 1) (i :: l) := i < n + 1 \u2227 below_triangle n l\n\nlemma below_line.iff {n : \u2115} {l : list \u2115} : \n  below_line n l \u2194 \u2200 j, j \u2208 l \u2192 j < n := \nbegin\n  split; induction l with i l ih,\n  { intros h j hj, exfalso, exact list.not_mem_nil j hj },\n  { intros h j hj, rw [below_line] at h, \n    rcases ((list.mem_cons_iff _ _ _).mp hj) with \u27e8\u27e8_\u27e9|hj'\u27e9,\n    { exact h.1 },\n    { exact ih h.2 j (by assumption) } },\n  { intro h, exact true.intro },\n  { intro h, dsimp [below_line], split,\n    { exact h i (l.mem_cons_self i) },\n    { apply ih, intros j hj, exact h j (list.mem_cons_of_mem i hj) } }\nend\n\nlemma below_line.\u03b4 (i : \u2115) {n : \u2115} {l : list \u2115} (h : below_line n l ) : \n  below_line (n + 1) (l.map (simplicial.infinite.\u03b4 i)) := \nbegin\n  rw [below_line.iff] at h \u22a2, \n  intros k hk,\n  rcases list.mem_map.mp hk with \u27e8j,\u27e8hm,he\u27e9\u27e9,\n  rw [\u2190 he], \n  exact lt_of_le_of_lt (simplicial.infinite.\u03b4_bound' i j).2\n                       (nat.succ_lt_succ (h j hm))\nend\n\nlemma below_line.\u03c3 {i n : \u2115} {l : list \u2115} \n  (hi : i < n) (hl : below_line (n + 1) l) : \n    (below_line n (l.map (simplicial.infinite.\u03c3 i))) := \nbegin\n  rw [below_line.iff] at hl \u22a2,\n  intros k hk,\n  rcases list.mem_map.mp hk with \u27e8j,\u27e8hm,he\u27e9\u27e9,\n  rw [\u2190 he],\n  exact simplicial.infinite.\u03c3_bound hi (hl j hm)\nend\n\nlemma below_line.of_fin {n : \u2115} (l : list (fin n)) : below_line n (l.map coe) := \nbelow_line.iff.mpr $ (\u03bb j hj, begin \n rcases list.mem_map.mp hj with \u27e8i,\u27e8hm,he\u27e9\u27e9, rw [\u2190 he], exact i.is_lt\nend)\n\nlemma below_triangle.nil (n : \u2115) : below_triangle n [] := \nby { cases n; trivial }\n\nlemma spread.below : \u2200 {n : \u2115} {l : list \u2115} (hb : below_triangle n l),\n  below_line n (spread l)\n| n [] h := by {  simp only [spread, below_line] }\n| 0 (i :: l) hb := false.elim hb\n| (n + 1) (i :: l) hb := \nbegin\n  dsimp[below_triangle] at hb,\n  split,\n  { exact hb.1 },\n  { exact below_line.\u03b4 i (spread.below hb.2) }\nend\n\nlemma squash.below : \u2200 {n : \u2115} {l : list \u2115}\n  (hb : below_line n l) (hn : l.nodup), \n  below_triangle n (squash l)\n| 0 [] hb hn := by { simp only [squash, below_triangle] }\n| (n + 1) [] hb hn := by { simp only [squash, below_triangle] }\n| 0 (i :: l) hb hn := false.elim (nat.not_lt_zero i hb.1)\n| (n + 1) (i :: l) hb hn := \nbegin\n  dsimp [below_line] at hb,\n  rw [squash.cons, below_triangle],\n  split, { exact hb.1 },\n  rw [list.nodup_cons] at hn,\n  apply squash.below _ (\u03c3_pred_nodup hn.right hn.left),\n  by_cases hb' : i < n,\n  { rw [below_line.iff] at hb \u22a2, \n      intros j hj,\n      rcases list.mem_map.mp hj with \u27e8j',hj'\u27e9,\n      have hj'' := hb.right j' hj'.left,\n      exact hj'.right \u25b8 (\u03c3_bound (lt_of_le_of_lt i.pred_le hb') hj'') },\n  { have : i = n := le_antisymm (nat.le_of_lt_succ hb.left) (le_of_not_gt hb'),\n    cases this,\n    rw [below_line.iff] at hb \u22a2, \n    intros j hj,\n    rcases list.mem_map.mp hj with \u27e8j',\u27e8hm',he'\u27e9\u27e9,\n    have hj' : j' \u2264 n := nat.le_of_lt_succ (hb.right j' hm'),\n    by_cases hjn : j' = n,\n    { exfalso, exact hn.left (hjn \u25b8 hm') },\n    { rw [\u2190 he'],\n      exact lt_of_le_of_lt (\u03c3_le n.pred j') (lt_of_le_of_ne hj' hjn) } }\nend\n\nend natlist\n\n/- `fin_falling` is an inductive type defined in the most obvious \n   way to ensure that `fin_falling n k` has size `falling n k` \n   (where `falling n k` is n (n - 1) (n - 2) ... (n - k + 1) ) \n-/\n@[derive decidable_eq]\ninductive fin_falling : \u2200 (n : \u2115), Type \n| nil (n : \u2115) : fin_falling n\n| cons {n : \u2115} (i : fin (n + 1)) (l : fin_falling n) : fin_falling (n + 1)\n\nnamespace fin_falling\n\ndef length : \u2200 {n : \u2115} (l : fin_falling n), \u2115 := \n @fin_falling.rec (\u03bb n l, \u2115) (\u03bb n, 0) (\u03bb n i l k, k + 1)\n\n@[simp] lemma length.nil (n : \u2115) : (fin_falling.nil n).length = 0 := rfl\n\n@[simp] lemma length.cons {n : \u2115} (i : fin (n + 1)) (l : fin_falling n) : \n  (fin_falling.cons i l).length = l.length + 1 := rfl\n\n/- We will define three different functions that convert an element \n   `l : fin_falling n k` to a list.  \n   * `to_list l` will be a nonduplicating list in `fin n`\n   * `to_spread_list l` will be a nonduplicating list in `\u2115`, and will\n     be the same as `(to_list l).map fin.val`\n   * `to_squash_list l` will be a list in `\u2115`, and will be the same as\n     `natlist.squash (to_spread_list l)`.\n-/\n\ndef to_squash_list : \u2200 { n : \u2115 } (l : fin_falling n), list \u2115 := \n @fin_falling.rec (\u03bb n l, list \u2115) (\u03bb n, list.nil)\n   (\u03bb n i l ih, i :: ih)\n\nlemma to_squash_list.nil (n : \u2115) : to_squash_list (fin_falling.nil n) = [] := rfl\n\nlemma to_squash_list.cons {n : \u2115} (i : fin (n + 1)) (l : fin_falling n) : \n  to_squash_list (fin_falling.cons i l) = i :: (to_squash_list l) := rfl\n\nlemma to_squash_list.length : \u2200 {n : \u2115} (l : fin_falling n), l.to_squash_list.length = l.length \n| _ (fin_falling.nil n) := \n  by { rw[to_squash_list.nil, list.length, length.nil] }\n| n (fin_falling.cons i l) := \n  by { rw[to_squash_list.cons, list.length, to_squash_list.length l, length.cons] }\n\nlemma to_squash_list.below : \u2200 {n : \u2115} (l : fin_falling n),\n  natlist.below_triangle n l.to_squash_list\n| _ (fin_falling.nil n) := natlist.below_triangle.nil n\n| n (fin_falling.cons i l) := and.intro i.is_lt (to_squash_list.below l)\n\ndef to_spread_list : \u2200 { n : \u2115 } (l : fin_falling n), list \u2115 := \n @fin_falling.rec (\u03bb n l, list \u2115) (\u03bb n, list.nil)\n   (\u03bb n i l ih, i :: (ih.map (simplicial.infinite.\u03b4 i)))\n\nlemma to_spread_list.nil (n : \u2115) : to_spread_list (fin_falling.nil n) = [] := rfl\n\nlemma to_spread_list.cons {n : \u2115} (i : fin (n + 1)) (l : fin_falling n) : \n  to_spread_list (fin_falling.cons i l) = \n    i :: ((to_spread_list l).map (simplicial.infinite.\u03b4 i)) := rfl\n\nlemma to_spread_list.length : \u2200 {n : \u2115} (l : fin_falling n),\n  (to_spread_list l).length = l.length \n| _ (fin_falling.nil n) := \n  by { rw[to_spread_list.nil, list.length, length.nil] }\n| n (fin_falling.cons i l) := \n  by { rw[to_spread_list.cons, list.length, list.length_map, \n          to_spread_list.length l, length.cons] }\n\nlemma to_spread_list.below : \u2200 {n : \u2115} (l : fin_falling n),\n  natlist.below_line n l.to_spread_list\n| _ (fin_falling.nil n) := true.intro\n| n (fin_falling.cons i l) := \nbegin\n  rw [to_spread_list.cons, natlist.below_line],\n  split, exact i.is_lt,\n  have h := to_spread_list.below l,\n  rw [natlist.below_line.iff] at h \u22a2, \n  intros j hj,\n  rcases list.mem_map.mp hj with \u27e8j\u2080,\u27e8hm,he\u27e9\u27e9,\n  exact he \u25b8 (lt_of_le_of_lt (\u03b4_bound' i j\u2080).right (nat.succ_lt_succ (h j\u2080 hm))), \nend\n\nlemma spread_squash : \u2200 {n : \u2115 } (l : fin_falling n),\n  natlist.spread l.to_squash_list = l.to_spread_list \n| _ (fin_falling.nil n) := rfl\n| n (fin_falling.cons i l) := \nby { rw [to_squash_list.cons, to_spread_list.cons, natlist.spread, spread_squash] }\n\nlemma to_spread_list.nodup {n : \u2115 } (l : fin_falling n) :\n  l.to_spread_list.nodup := \nby { rw[\u2190 l.spread_squash], exact natlist.spread.nodup _ }\n\nlemma squash_spread {n : \u2115} (l : fin_falling n) :\n  natlist.squash l.to_spread_list = l.to_squash_list := \nby { rw [\u2190 spread_squash l, natlist.squash_spread] }\n\ndef to_list : \u2200 { n : \u2115 } (l : fin_falling n), list (fin n) :=\n @fin_falling.rec (\u03bb n l, list (fin n)) (\u03bb n, list.nil)\n  (\u03bb n i l ih, i :: (ih.map (simplicial.\u03b4 i)))\n\nlemma to_list.nil (n : \u2115) : to_list (fin_falling.nil n) = [] := rfl\n\nlemma to_list.cons {n : \u2115} (i : fin (n + 1)) (l : fin_falling n) : \n  to_list (fin_falling.cons i l) = i :: (to_list l).map (simplicial.\u03b4 i) := rfl\n\nlemma to_list.length : \u2200 {n : \u2115} (l : fin_falling n), (to_list l).length = l.length\n| _ (fin_falling.nil n) := \n  by { rw[to_list.nil, list.length, length.nil] }\n| n (fin_falling.cons i l) := \n  by { rw[to_list.cons, list.length, list.length_map, to_list.length l, length.cons] }\n\nlemma to_list.nodup : \u2200 {n : \u2115} (l : fin_falling n), (to_list l).nodup\n| _ (fin_falling.nil n) := list.nodup_nil\n| n (fin_falling.cons i l) := \nbegin\n  rw [to_list.cons, list.nodup_cons], split,\n  { rw [list.mem_map],\n    rintro \u27e8k,\u27e8hm,he\u27e9\u27e9, exact simplicial.\u03b4_ne _ _ he, },\n  { exact list.nodup.map (simplicial.\u03b4_inj i) (to_list.nodup l) }\nend\n\nlemma to_list.val : \u2200 {n : \u2115} (l : fin_falling n), \n  (to_list l).map (coe : fin n \u2192 \u2115) = to_spread_list l \n| _ (fin_falling.nil n) := rfl\n| n (fin_falling.cons i l) := \nbegin\n  rw [to_list.cons, to_spread_list.cons, list.map_cons, list.map_map],\n  have : (coe : (fin _) \u2192 \u2115) \u2218 (simplicial.\u03b4 i) = (\u03b4 i) \u2218 coe := \n  begin ext j, simp only [function.comp_app, simplicial.\u03b4_infinite] end,\n  rw [this, \u2190 list.map_map, to_list.val]\nend\n\ndef of_squash_list : \u2200 {n : \u2115} (l : list \u2115)\n  (hb : natlist.below_triangle n l), fin_falling n\n| n [] hb := fin_falling.nil n\n| 0 (i :: l) hb := false.elim hb\n| (n + 1) (i :: l) hb := \n    fin_falling.cons \u27e8i,hb.left\u27e9 (of_squash_list l hb.right)\n\nlemma of_squash_list.nil (n : \u2115) (hb : natlist.below_triangle n []) : \n  of_squash_list [] hb = fin_falling.nil n := by { cases n; refl }\n\nlemma of_squash_list.length : \u2200 {n : \u2115} (l : list \u2115)\n  (hb : natlist.below_triangle n l), (of_squash_list l hb).length = l.length\n| n [] hb := by { cases n; refl }\n| 0 (i :: l) hb := false.elim hb\n| (n + 1) (i :: l) hb :=\n  by { rw [of_squash_list, length.cons, list.length_cons, of_squash_list.length] }\n\ndef of_spread_list {n : \u2115} (l : list \u2115) (hn : l.nodup) (hb : natlist.below_line n l) :\n fin_falling n := of_squash_list (natlist.squash l) (natlist.squash.below hb hn)\n\nlemma of_spread_list.length {n : \u2115} (l : list \u2115)\n  (hn : l.nodup) (hb : natlist.below_line n l) : \n  (of_spread_list l hn hb).length = l.length := \nby { rw [of_spread_list, of_squash_list.length, natlist.squash.length] }\n\ndef of_list {n : \u2115} (l : list (fin n)) (hn : l.nodup) : fin_falling n :=\n of_spread_list (l.map coe) \n  (list.nodup.map (\u03bb _ _ e, subtype.val_injective e) hn) (natlist.below_line.of_fin l)\n\nlemma of_list.length {n : \u2115} (l : list (fin n)) (hn : l.nodup) :\n  (of_list l hn).length = l.length := \nby { rw [of_list, of_spread_list.length, list.length_map] }\n\nlemma to_of_squash_list : \u2200 {n : \u2115} {l : list \u2115} (hb : natlist.below_triangle n l),\n to_squash_list (of_squash_list l hb) = l \n| n [] hb := by { cases n; refl }\n| 0 (i :: l) hb := false.elim hb\n| (n + 1) (i :: l) hb := \n  by { rw [of_squash_list, to_squash_list.cons, to_of_squash_list], refl }\n\nlemma of_to_squash_list_aux : \u2200 {n : \u2115} (l : fin_falling n) (h),\n of_squash_list (to_squash_list l) h = l := \nbegin\n  intros n l,\n  induction l with n\u2080 n\u2081 i l ih, \n  { rw [to_squash_list.nil], intro h, rw [of_squash_list.nil] },\n  { rw [to_squash_list.cons], intro h, rw [of_squash_list, ih], congr' 1,\n    exact fin.coe_inj rfl }\nend\n\nlemma of_to_squash_list {n : \u2115} (l : fin_falling n) :\n of_squash_list (to_squash_list l) (to_squash_list.below l) = l := \nof_to_squash_list_aux l _\n\nlemma to_of_spread_list {n : \u2115} {l : list \u2115} (hn : l.nodup) (hb : natlist.below_line n l) :\n to_spread_list (of_spread_list l hn hb) = l := \nby { rw [of_spread_list, \u2190 spread_squash, to_of_squash_list, natlist.spread_squash hn] }\n\nlemma of_to_spread_list_aux {n : \u2115} (l : fin_falling n) (hn) (hb):\n of_spread_list (to_spread_list l) hn hb = l := \nbegin\n  dsimp [of_spread_list], \n  have : \u2200 {l\u2080 l\u2081 : list \u2115} (e : l\u2080 = l\u2081) (h\u2081 : natlist.below_triangle n l\u2081), \n           (of_squash_list l\u2080 (by { rw[e], exact h\u2081})) = (of_squash_list l\u2081 h\u2081) := \n  by { intros, cases e, refl },\n  rw [this (squash_spread l) (to_squash_list.below l), of_to_squash_list_aux]\nend\n\nlemma to_of_list {n : \u2115} (l : list (fin n)) (hn : l.nodup): \n  to_list (of_list l hn) = l := \nbegin\n  apply list.map_injective_iff.mpr (@fin.coe_inj n),\n  rw [to_list.val, of_list, to_of_spread_list]\nend\n\nlemma of_to_list {n : \u2115} (l : fin_falling n) : \n  of_list (to_list l) (to_list.nodup l) = l := \nbegin\n  rw [of_list],\n  have : \u2200 {l\u2080 l\u2081 : list \u2115} (e : l\u2080 = l\u2081) \n           (hn : l\u2081.nodup) (hb : natlist.below_line n l\u2081), \n           (of_spread_list l\u2080 (by { rw[e], exact hn}) (by { rw[e], exact hb})) =\n             (of_spread_list l\u2081 hn hb) := \n  by { intros, cases e, refl },\n  rw [this (to_list.val l) (to_spread_list.nodup l) (to_spread_list.below l)],\n  apply of_to_spread_list_aux\nend\n\ndef ordered_subset_equiv (n k : \u2115) : \n  { l : fin_falling n // l.length = k } \u2243 ordered_subset (fin n) k := \n{ to_fun := \u03bb l, \u27e8fin_falling.to_list l,\n                  \u27e8(to_list.length l.val).trans l.property, to_list.nodup l.val\u27e9\u27e9,\n  inv_fun := \u03bb l, \u27e8fin_falling.of_list l.val l.property.2, \n                   (of_list.length l.val l.property.2).trans l.property.1\u27e9,\n  left_inv := \u03bb l, subtype.eq (of_to_list l),\n  right_inv := \u03bb l, subtype.eq (to_of_list l.val _) }\n\nend fin_falling\n\n", "meta": {"author": "NeilStrickland", "repo": "lean_lib", "sha": "6a9563de93748ace509d9db4302db6cd77d8f92c", "save_path": "github-repos/lean/NeilStrickland-lean_lib", "path": "github-repos/lean/NeilStrickland-lean_lib/lean_lib-6a9563de93748ace509d9db4302db6cd77d8f92c/src/combinatorics/choose_fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7003030357398035}}
{"text": "/-\nCopyright (c) 2021 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov\n-/\nimport topology.metric_space.basic\nimport topology.metric_space.emetric_paracompact\nimport topology.shrinking_lemma\n\n/-!\n# Shrinking lemma in a proper metric space\n\nIn this file we prove a few versions of the shrinking lemma for coverings by balls in a proper\n(pseudo) metric space.\n\n## Tags\n\nshrinking lemma, metric space\n-/\n\nuniverses u v\nopen set metric\nopen_locale topological_space\n\nvariables {\u03b1 : Type u} {\u03b9 : Type v} [metric_space \u03b1] [proper_space \u03b1] {c : \u03b9 \u2192 \u03b1}\nvariables {x : \u03b1} {r : \u211d} {s : set \u03b1}\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a closed subset of a proper metric space by open balls can be shrunk to a new cover by open balls\nso that each of the new balls has strictly smaller radius than the old one. This version assumes\nthat `\u03bb x, ball (c i) (r i)` is a locally finite covering and provides a covering indexed by the\nsame type. -/\nlemma exists_subset_Union_ball_radius_lt {r : \u03b9 \u2192 \u211d} (hs : is_closed s)\n  (uf : \u2200 x \u2208 s, finite {i | x \u2208 ball (c i) (r i)}) (us : s \u2286 \u22c3 i, ball (c i) (r i)) :\n  \u2203 r' : \u03b9 \u2192 \u211d, s \u2286 (\u22c3 i, ball (c i) (r' i)) \u2227 \u2200 i, r' i < r i :=\nbegin\n  rcases exists_subset_Union_closed_subset hs (\u03bb i, @is_open_ball _ _ (c i) (r i)) uf us\n    with \u27e8v, hsv, hvc, hcv\u27e9,\n  have := \u03bb i, exists_lt_subset_ball (hvc i) (hcv i),\n  choose r' hlt hsub,\n  exact \u27e8r', subset.trans hsv $ Union_subset_Union $ hsub, hlt\u27e9\nend\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a proper metric space by open balls can be shrunk to a new cover by open balls so that each of\nthe new balls has strictly smaller radius than the old one. -/\nlemma exists_Union_ball_eq_radius_lt {r : \u03b9 \u2192 \u211d} (uf : \u2200 x, finite {i | x \u2208 ball (c i) (r i)})\n  (uU : (\u22c3 i, ball (c i) (r i)) = univ) :\n  \u2203 r' : \u03b9 \u2192 \u211d, (\u22c3 i, ball (c i) (r' i)) = univ \u2227 \u2200 i, r' i < r i :=\nlet \u27e8r', hU, hv\u27e9 := exists_subset_Union_ball_radius_lt is_closed_univ (\u03bb x _, uf x) uU.ge\nin \u27e8r', univ_subset_iff.1 hU, hv\u27e9\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a closed subset of a proper metric space by nonempty open balls can be shrunk to a new cover by\nnonempty open balls so that each of the new balls has strictly smaller radius than the old one. -/\nlemma exists_subset_Union_ball_radius_pos_lt {r : \u03b9 \u2192 \u211d} (hr : \u2200 i, 0 < r i) (hs : is_closed s)\n  (uf : \u2200 x \u2208 s, finite {i | x \u2208 ball (c i) (r i)}) (us : s \u2286 \u22c3 i, ball (c i) (r i)) :\n  \u2203 r' : \u03b9 \u2192 \u211d, s \u2286 (\u22c3 i, ball (c i) (r' i)) \u2227 \u2200 i, r' i \u2208 Ioo 0 (r i) :=\nbegin\n  rcases exists_subset_Union_closed_subset hs (\u03bb i, @is_open_ball _ _ (c i) (r i)) uf us\n    with \u27e8v, hsv, hvc, hcv\u27e9,\n  have := \u03bb i, exists_pos_lt_subset_ball (hr i) (hvc i) (hcv i),\n  choose r' hlt hsub,\n  exact \u27e8r', subset.trans hsv $ Union_subset_Union hsub, hlt\u27e9\nend\n\n/-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover\nof a proper metric space by nonempty open balls can be shrunk to a new cover by nonempty open balls\nso that each of the new balls has strictly smaller radius than the old one. -/\nlemma exists_Union_ball_eq_radius_pos_lt {r : \u03b9 \u2192 \u211d} (hr : \u2200 i, 0 < r i)\n  (uf : \u2200 x, finite {i | x \u2208 ball (c i) (r i)}) (uU : (\u22c3 i, ball (c i) (r i)) = univ) :\n  \u2203 r' : \u03b9 \u2192 \u211d, (\u22c3 i, ball (c i) (r' i)) = univ \u2227 \u2200 i, r' i \u2208 Ioo 0 (r i) :=\nlet \u27e8r', hU, hv\u27e9 := exists_subset_Union_ball_radius_pos_lt hr is_closed_univ (\u03bb x _, uf x) uU.ge\nin \u27e8r', univ_subset_iff.1 hU, hv\u27e9\n\n/-- Let `R : \u03b1 \u2192 \u211d` be a (possibly discontinuous) function on a proper metric space.\nLet `s` be a closed set in `\u03b1` such that `R` is positive on `s`. Then there exists a collection of\npairs of balls `metric.ball (c i) (r i)`, `metric.ball (c i) (r' i)` such that\n\n* all centers belong to `s`;\n* for all `i` we have `0 < r i < r' i < R (c i)`;\n* the family of balls `metric.ball (c i) (r' i)` is locally finite;\n* the balls `metric.ball (c i) (r i)` cover `s`.\n\nThis is a simple corollary of `refinement_of_locally_compact_sigma_compact_of_nhds_basis_set`\nand `exists_subset_Union_ball_radius_pos_lt`. -/\nlemma exists_locally_finite_subset_Union_ball_radius_lt (hs : is_closed s)\n  {R : \u03b1 \u2192 \u211d} (hR : \u2200 x \u2208 s, 0 < R x) :\n  \u2203 (\u03b9 : Type u) (c : \u03b9 \u2192 \u03b1) (r r' : \u03b9 \u2192 \u211d),\n    (\u2200 i, c i \u2208 s \u2227 0 < r i \u2227 r i < r' i \u2227 r' i < R (c i)) \u2227\n    locally_finite (\u03bb i, ball (c i) (r' i)) \u2227 s \u2286 \u22c3 i, ball (c i) (r i) :=\nbegin\n  have : \u2200 x \u2208 s, (\ud835\udcdd x).has_basis (\u03bb r : \u211d, 0 < r \u2227 r < R x) (\u03bb r, ball x r),\n    from \u03bb x hx, nhds_basis_uniformity (uniformity_basis_dist_lt (hR x hx)),\n  rcases refinement_of_locally_compact_sigma_compact_of_nhds_basis_set hs this\n    with \u27e8\u03b9, c, r', hr', hsub', hfin\u27e9,\n  rcases exists_subset_Union_ball_radius_pos_lt (\u03bb i, (hr' i).2.1) hs\n    (\u03bb x hx, hfin.point_finite x) hsub' with \u27e8r, hsub, hlt\u27e9,\n  exact \u27e8\u03b9, c, r, r', \u03bb i, \u27e8(hr' i).1, (hlt i).1, (hlt i).2, (hr' i).2.2\u27e9, hfin, hsub\u27e9\nend\n\n/-- Let `R : \u03b1 \u2192 \u211d` be a (possibly discontinuous) positive function on a proper metric space. Then\nthere exists a collection of pairs of balls `metric.ball (c i) (r i)`, `metric.ball (c i) (r' i)`\nsuch that\n\n* for all `i` we have `0 < r i < r' i < R (c i)`;\n* the family of balls `metric.ball (c i) (r' i)` is locally finite;\n* the balls `metric.ball (c i) (r i)` cover the whole space.\n\nThis is a simple corollary of `refinement_of_locally_compact_sigma_compact_of_nhds_basis`\nand `exists_Union_ball_eq_radius_pos_lt` or `exists_locally_finite_subset_Union_ball_radius_lt`. -/\nlemma exists_locally_finite_Union_eq_ball_radius_lt {R : \u03b1 \u2192 \u211d} (hR : \u2200 x, 0 < R x) :\n  \u2203 (\u03b9 : Type u) (c : \u03b9 \u2192 \u03b1) (r r' : \u03b9 \u2192 \u211d), (\u2200 i, 0 < r i \u2227 r i < r' i \u2227 r' i < R (c i)) \u2227\n    locally_finite (\u03bb i, ball (c i) (r' i)) \u2227 (\u22c3 i, ball (c i) (r i)) = univ :=\nlet \u27e8\u03b9, c, r, r', hlt, hfin, hsub\u27e9 := exists_locally_finite_subset_Union_ball_radius_lt\n  is_closed_univ (\u03bb x _, hR x)\nin \u27e8\u03b9, c, r, r', \u03bb i, (hlt i).2, hfin, univ_subset_iff.1 hsub\u27e9\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/topology/metric_space/shrinking_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7002807790119798}}
{"text": "import data.finsupp\nimport algebra.ring\nimport .to_finset\nimport .to_multiset\nimport to_comm_semiring\n\nnoncomputable theory\n\nlocal infix ^ := monoid.pow\n\nopen classical multiset\nlocal attribute [instance] prop_decidable\nlocal notation a `~\u1d64` b : 50 := associated a b\nuniverse u\nvariable {\u03b1 : Type u}\nvariable [integral_domain \u03b1]\n\n--Should be placed elsewhere\nlemma prod_eq_zero_iff_zero_mem' {s : multiset \u03b1} : prod s = 0 \u2194 (0 : \u03b1) \u2208 s :=\nbegin\n  split,\n  {\n    apply multiset.induction_on s,\n    {\n      simp * at *,\n    },\n    {\n      intros a s h1 h2,\n      simp * at *,\n      by_cases ha : a = 0,\n      {\n        simp * at *,\n      },\n      {\n        have h3 : prod s = 0,\n        {\n          by_contradiction h4,\n          have : a * prod s \u2260 0,\n          from mul_ne_zero ha h4,\n          contradiction,\n        },\n        simp [h1 h3],\n      }\n    }\n  },\n  {\n    intro h,\n    rcases (exists_cons_of_mem h) with \u27e8t, ht\u27e9,\n    subst ht,\n    simp * at *,\n  }\nend\n\nlemma associated_of_dvd_dvd {a b : \u03b1}\n  (h1 : a \u2223 b) (h2 : b \u2223 a) : a ~\u1d64 b :=\nbegin\n  rcases h2 with \u27e8c, h3\u27e9,\n  rcases h1 with \u27e8d, h4\u27e9,\n  by_cases h6 : (a = 0),\n  {\n    have h7 : (b = 0),\n    {\n      simp [h6] at h4,\n      assumption,\n    },\n    simp * at *,\n  },\n  {\n    have h3b : a = a * (d * c),\n    { rwa [h4, mul_assoc] at h3},\n    have h5 : a * 1 = a * (d * c),\n    { simpa},\n    have h7 : 1 = (d * c),\n      from eq_of_mul_eq_mul_left h6 h5,\n    rw mul_comm _ _ at h7,\n    exact \u27e8unit_of_mul_eq_one (h7.symm), by rw [h4, unit_of_mul_eq_one, units.val_coe, \u2190mul_assoc, mul_comm c, mul_assoc, \u2190h7, mul_one]\u27e9,\n  }\nend\n\nlemma dvd_dvd_iff_associated {a b : \u03b1}\n   : (a ~\u1d64 b) \u2194 ( a \u2223 b) \u2227 ( b \u2223 a):=\n\u27e8dvd_dvd_of_associated, assume h1, associated_of_dvd_dvd h1.1 h1.2\u27e9\n\n--irreducible, prime and coprime\n\ndef prime (p : \u03b1) : Prop :=\np \u2260 0 \u2227 \u00ac is_unit p \u2227 \u2200 a b, p \u2223 (a * b) \u2192 (p \u2223 a \u2228 p \u2223 b)\n\ndef irreducible  (p : \u03b1) : Prop :=\np \u2260 0 \u2227 \u00ac is_unit p \u2227 \u2200d, d\u2223p \u2192 (is_unit d \u2228 (d ~\u1d64 p))\n\ndef irreducible'  (p : \u03b1) : Prop :=\np \u2260 0 \u2227 \u00ac is_unit p \u2227 \u2200 a b : \u03b1, p = a * b \u2192 (is_unit a \u2228 is_unit b)\n\nlemma irreducible'_of_irreducible {p : \u03b1} (h1 : irreducible p): irreducible' p :=\nbegin\n  have : \u2200 (a b : \u03b1), p = a * b \u2192 is_unit a \u2228 is_unit b,\n  {\n    intros a b h5,\n    have h7 : (is_unit a \u2228 (a ~\u1d64 p)),\n      from h1.2.2 a \u27e8b, h5\u27e9,\n    cases h7,\n    {\n      simp *\n    },\n    {\n      rcases h7 with \u27e8u, h8\u27e9,\n      have h9 : p * 1 = p * (\u2191u * b),\n      {\n        subst h8,\n        rw [mul_comm _ p, mul_assoc] at h5,\n        simpa *,\n      },\n      have h11 : is_unit b,\n      {\n        exact \u27e8u\u207b\u00b9, eq.symm \n            (calc \u2191(u\u207b\u00b9) = \u2191u\u207b\u00b9 * 1 : by simp\n            ... = \u2191u\u207b\u00b9 * (\u2191u * b) : by rw [eq_of_mul_eq_mul_left h1.1 h9]\n            ... = _ : by rw [\u2190mul_assoc, units.inv_mul, one_mul])\u27e9,\n      },\n      simp [h11]\n    }  \n  },\n  exact \u27e8h1.1, h1.2.1, this\u27e9, \nend\n\nlemma irreducible_of_irreducible' {p : \u03b1} (h1 : irreducible' p): irreducible p :=\nbegin\n  have : \u2200 (d : \u03b1), d \u2223 p \u2192 is_unit d \u2228 (d~\u1d64 p),\n  {\n    intros a h5,\n    rcases h5 with \u27e8b, h6\u27e9,\n    have h7 : is_unit a \u2228 is_unit b,\n      from h1.2.2 _ _ h6,\n    cases h7,\n    {\n      simp *,\n    },\n    {\n      have h8 : (a ~\u1d64 p),\n      {\n        rcases h7 with \u27e8u ,hu\u27e9,\n        apply exists.intro u\u207b\u00b9,\n        subst h6,\n        subst hu,\n        rw [mul_comm a, \u2190mul_assoc, units.inv_mul, one_mul],\n      },\n      simp [h8]\n    }\n  },\n  exact \u27e8h1.1, h1.2.1, this\u27e9,\nend\n\nlemma irreducible_iff_irreducible'  {p : \u03b1} : irreducible p \u2194 irreducible' p :=\niff.intro irreducible'_of_irreducible irreducible_of_irreducible'\n\n\nlemma not_is_unit_of_irreducible {a : \u03b1} (h : irreducible a) : \u00ac (is_unit a) := h.2.1\n\nlemma dvd_irreducible_of_dvd_mul_unit_irreducible {a b c: \u03b1} (h2 : is_unit b)(h3 : irreducible c)(h4 : a \u2223 (b * c)) : a \u2223 c :=\nlet \u27e8b\u1d64, hb\u27e9 := h2 in\nlet \u27e8d, h5\u27e9 := h4 in exists.intro ( d*b\u1d64.inv) \n    (calc c = 1 * c : by simp\n    ... = (\u2191b\u1d64\u207b\u00b9* \u2191b\u1d64) * c : by rw [\u2190units.inv_mul _]\n    ... = \u2191b\u1d64\u207b\u00b9 * (\u2191b\u1d64 * c) : by simp [mul_assoc]\n    ... = \u2191b\u1d64\u207b\u00b9 * (b * c): by rw [hb]\n    ... = \u2191b\u1d64\u207b\u00b9 * (a * d): by rw h5\n    ... = b\u1d64.inv * (a * d): by rw [units.inv_coe]\n    ... = (a * d) * b\u1d64.inv : by simp [mul_assoc, mul_comm]\n    ... = a * (d * b\u1d64.inv) : by simp [mul_assoc])\n\n\n--correct simp?\n@[simp] lemma not_irreducible_one : \u00ac irreducible (1 : \u03b1) :=\nbegin\n  by_contradiction h,\n  have : \u00acis_unit (1 : \u03b1),\n    from h.2.1,\n  have : is_unit (1 : \u03b1),\n    from is_unit_one,\n  contradiction,\nend\n\n@[simp] lemma not_irreducible_zero : \u00ac irreducible (0 : \u03b1) :=\nbegin\n  by_contradiction h1,\n  have : (0 : \u03b1) \u2260 0,\n    from h1.1,\n  contradiction,\nend\n\n--Problem with 'a' in the namespace\nlemma irreducible_of_associated {p b : \u03b1}(h1 : irreducible p)(h2 : p ~\u1d64 b) : irreducible b :=\nbegin   \n  rcases h2 with \u27e8u, hu\u27e9,   \n  have h7 : (b \u2260 0),\n  {\n    intro h6,\n    simp * at *,\n  },\n  have h8 : (\u00ac is_unit b),\n  {\n    intro h8,\n    have h9 : is_unit p,\n      from hu.symm \u25b8 (is_unit_mul_of_is_unit_of_is_unit (is_unit_unit u) h8),\n    exact h1.2.1 h9\n  },\n  have h9 : (\u2200c, (c\u2223b \u2192 (is_unit c \u2228 (c ~\u1d64 b)))),\n  {\n    intros c h9,\n    by_cases h10 : is_unit c,\n    { simp [h10]},\n    {\n      have h15 : (c~\u1d64 p),\n      {\n        have h14 : c \u2223 p,\n        {\n          rcases h9 with \u27e8d, h11\u27e9,             \n          exact \u27e8u * d, by {subst h11, subst hu, rw [\u2190mul_assoc, \u2190mul_assoc, mul_comm c]}\u27e9\n        },\n        have h16: is_unit c \u2228 (c~\u1d64 p),\n          from h1.2.2 c h14,\n        simp * at *,\n      },\n      have h16 : (c~\u1d64 b),\n        from h15.trans \u27e8u, hu\u27e9,\n      simp *,\n    }\n  },\n  exact \u27e8h7,h8,h9\u27e9,\nend\n\nlemma unit_mul_irreducible_is_irreducible'  {a b : \u03b1}: is_unit a \u2192 irreducible b \u2192 irreducible (a * b)\n| \u27e8a\u1d64, ha\u27e9 h2 := \n  have h3 : (b ~\u1d64 (a*b)),\n    from \u27e8a\u1d64\u207b\u00b9, by {rw [ha, \u2190mul_assoc, units.inv_mul, one_mul]}\u27e9,\n  irreducible_of_associated h2 h3\n\n\nlemma irreducible_of_prime  {p : \u03b1} (h1 : prime p) : irreducible p :=\nbegin\n  rw prime at h1,\n  --rw irreducible,\n  have h2 : (p \u2260 0),\n  {\n    from and.elim_left h1,\n  },\n  have h3 : (\u00ac is_unit p),\n  from and.elim_left (and.elim_right h1),\n  rw [irreducible_iff_irreducible', irreducible'],\n  have h4 : \u2200 (a b : \u03b1), p = a * b \u2192 is_unit a \u2228 is_unit b,\n  {\n    intros b c h4a,\n    by_cases h4b : (b = 0),\n    {\n      simp [h4b] at h4a,\n      contradiction,\n    },\n    {\n      by_cases h4c : (c = 0),\n      {\n        simp [h4c] at h4a,\n        contradiction,\n      }, --no indent here\n      have h4 : p \u2223 (b * c),\n      {\n        simp *,\n      },\n      have h5 : p \u2223 b \u2228 p \u2223 c,\n      from and.elim_right (and.elim_right h1) b c h4,\n      cases h5,\n      {\n        have h6 : b \u2223 b * c,\n        {simp},\n        have h7 : b \u2223 p,\n        {\n          apply dvd.trans h6,\n          simp *,\n        },\n        have h8 : (p ~\u1d64 b),\n        from associated_of_dvd_dvd h5 h7,\n        rw associated at h8,\n        let u := some h8,\n        have h9 : p = \u2191u * b,\n        from some_spec h8,\n        rw [h9, mul_comm b c] at h4a,\n        have h10 : \u2191u = c,\n        from eq_of_mul_eq_mul_right_of_ne_zero h4b h4a,\n        have h11 : is_unit c,\n        {\n          fapply exists.intro u,\n          exact eq.symm h10,\n        },\n        simp *,\n      },\n      {\n        have h6 : c \u2223 b * c,\n        {simp},\n        have h7 : c \u2223 p,\n        {\n          apply dvd.trans h6,\n          simp *,\n        },\n        have h8 : (p ~\u1d64 c),\n        from associated_of_dvd_dvd h5 h7,\n        rw associated at h8,\n        let u := some h8,\n        have h9 : p = \u2191u * c,\n        from some_spec h8,\n        rw [h9] at h4a,\n        have h10 : \u2191u = b,\n        from eq_of_mul_eq_mul_right_of_ne_zero h4c h4a,\n        have h11 : is_unit b,\n        {\n          fapply exists.intro u,\n          exact eq.symm h10,\n        },\n        simp *,\n      }\n    }\n  },\n  exact \u27e8h2, h3, h4 \u27e9\nend\n\n\nlemma irreducible_of_mul_is_unit {a b c : \u03b1} (h1 : irreducible a) (h2 : is_unit b) (h3 : a * b = c) : irreducible c :=\nbegin\n  apply irreducible_of_associated h1,\n  exact associated_of_mul_is_unit h2 h3,\nend\n\nprivate lemma succ_eq_succ_iff_eq {n m : \u2115} : nat.succ n = nat.succ m \u2194 n = m :=\nbegin\n  split,\n    exact nat.succ_inj,\n    intro h,\n    simp *,\nend\n\nprivate lemma eq_zero_or_exists_eq_succ_succ_of_ne_one {n : \u2115} (h : n \u2260 1) : n = 0 \u2228 \u2203 m, n = nat.succ (nat.succ m) :=\nbegin\n  by_cases h2 : n = 0,\n    {simp *},\n    {\n      rcases (nat.exists_eq_succ_of_ne_zero h2) with \u27e8m, hm\u27e9,\n      subst hm,\n      simp * at *,\n      rw succ_eq_succ_iff_eq at h,\n      rcases (nat.exists_eq_succ_of_ne_zero h) with \u27e8s, hs\u27e9,\n      subst hs,\n      exact \u27e8s, rfl\u27e9,\n    }\nend\n\nlemma irreducible_pow {a : \u03b1} {n : \u2115} (h : irreducible a) : irreducible (a^n) \u2194 n = 1 :=\nbegin\n  split,\n  {\n    intros h1,\n    by_contradiction h2,\n    have h3 : n = 0 \u2228 \u2203 m, n = nat.succ (nat.succ m),\n    from eq_zero_or_exists_eq_succ_succ_of_ne_one h2,\n    cases h3,\n    {\n      simp * at *,\n    },\n    {\n      rcases h3 with \u27e8m, hm\u27e9,\n      subst hm,\n      rw pow_succ at *,\n      rw irreducible_iff_irreducible' at h1,\n      unfold irreducible' at h1,\n      have h4: is_unit a \u2228 is_unit (a ^ nat.succ m),\n      from h1.2.2 _ _ rfl,\n      cases h4,\n      {\n        have : \u00acis_unit a,\n        from h.2.1,\n        contradiction,\n      },\n      {\n        rw pow_succ at h4,\n        rw is_unit_mul_iff_is_unit_and_is_unit at h4,\n        have : \u00acis_unit a,\n        from h.2.1,\n        exact this h4.1,\n      }\n    }\n\n  },\n  {\n    intro h,\n    simp * at *,\n  }\nend\n\n\nlemma not_is_unit_prod_of_ne_zero_of_forall_mem_irreducible {s : multiset \u03b1} (h1 : s \u2260 0) (h2 : \u2200x : \u03b1, x \u2208 s \u2192 irreducible x) : \u00acis_unit s.prod :=\nbegin\n  rcases (exists_mem_of_ne_zero h1) with \u27e8x, hx\u27e9,\n  have h2b : x \u2223 (s.prod),\n    from dvd_prod_of_mem _ hx,\n  have h3: irreducible x,\n    from h2 x hx,\n  have h4: \u00acis_unit x,\n    from not_is_unit_of_irreducible h3,\n  exact not_is_unit_of_not_is_unit_dvd h4 h2b,\nend\n\n--- GCDs\n\nsection gcd_id\nvariables [has_gcd \u03b1] {a b c : \u03b1}\n\nlemma gcd_zero_associated_left {f : \u03b1} : (gcd f (0 : \u03b1)) ~\u1d64 f :=\nbegin\n  apply associated_of_dvd_dvd,\n  exact gcd_left,\n  apply gcd_min,\n  simp,\n  simp\nend\n\nlemma gcd_zero_associated_right {\u03b1 : Type u} [integral_domain \u03b1][has_gcd \u03b1] {f : \u03b1} : (gcd (0 : \u03b1) f) ~\u1d64 f :=\nbegin\n  apply associated_of_dvd_dvd,\n  exact gcd_right,\n  apply gcd_min,\n  simp,\n  simp\nend\n\nlemma gcd_eq_zero_iff_eq_zero_and_eq_zero {\u03b1 : Type u} [integral_domain \u03b1][has_gcd \u03b1] {f g : \u03b1}  : gcd f g = 0 \u2194 f = 0 \u2227 g = 0:=\nbegin\n  constructor,\n  {\n     intro h1,\n     by_contradiction h2,\n     have h3 : \u00ac(g = 0 \u2227 f = 0),\n     {\n       rw and.comm at h2,\n       exact h2\n     },\n     simp at *,\n     by_cases h4 : (f = 0),\n     {\n       have h5 : g \u2260 0,\n       from h2 h4,\n       rw h4 at h1,\n       have h6 : ((gcd 0 g) ~\u1d64 g),\n       from gcd_zero_associated_right,\n       rw [h1] at h6,\n       have h7 : (g ~\u1d64 0),\n       from associated.symm h6,\n       rw [associated_zero_iff_eq_zero] at h7,\n       contradiction,\n     },\n     {\n       apply h4,\n       apply eq_zero_of_zero_dvd,\n       rw \u2190 h1,\n       exact gcd_left,\n     }\n\n  },\n  {\n    intro h1,\n    have h2 : f = 0,\n    from and.elim_left h1,\n    have h3 : g = 0,\n    from and.elim_right h1,\n    rw [h2, h3],\n    exact gcd_zero_zero_eq_zero\n  }\nend\n\n--Isn't it associated?\nlemma gcd_comm : (gcd a b ~\u1d64  gcd b a) :=\nbegin\n  apply associated_of_dvd_dvd,\n  {\n    have h1 : gcd a b \u2223 a,\n    from gcd_left,\n    have h2 : gcd a b \u2223 b,\n    from gcd_right,\n    exact gcd_min h2 h1,\n  },\n  {\n    have h1 : gcd b a \u2223 b,\n    from gcd_left,\n    have h2 : gcd b a \u2223 a,\n    from gcd_right,\n    exact gcd_min h2 h1,\n  }\nend\n\nend gcd_id", "meta": {"author": "johoelzl", "repo": "mason-stother", "sha": "573ecfaada288176462c03c87b80ad05bdab4644", "save_path": "github-repos/lean/johoelzl-mason-stother", "path": "github-repos/lean/johoelzl-mason-stother/mason-stother-573ecfaada288176462c03c87b80ad05bdab4644/to_integral_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389113, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.7002807744774394}}
{"text": "import linear_algebra.affine_space.basic\nimport linear_algebra.basis\n\nopen_locale affine\n\nuniverses u v w x\n\nvariables \n    (K : Type v) \n    (n : \u2115) \n    [inhabited K] \n    [field K]\n\nopen list\n--open vecl\n\n\n\n@[ext]\nstructure aff_vec_coord_tuple :=\n(vec : fin n \u2192 K)\n\n/-- type of affine points represented by coordinate tuples -/\n@[ext]\nstructure aff_pt_coord_tuple :=\n(pt : fin n \u2192 K)\n\n\ninstance vec_coe : has_coe (aff_vec_coord_tuple K n) (fin n \u2192 K) := \u27e8\u03bbv,v.1\u27e9\ninstance pt_coe : has_coe (aff_pt_coord_tuple K n) (fin n \u2192 K) := \u27e8\u03bbp,p.1\u27e9\n\n\nvariables (x y : aff_vec_coord_tuple K n) (a b : aff_pt_coord_tuple K n)\n    \n\ndef fin_add : (fin n \u2192 K) \u2192 (fin n \u2192 K) \u2192 (fin n \u2192 K) := \u03bb x y, (\u03bb m : fin n, x m + y m)\n\n/-! ### abelian group operations -/\ndef vec_add : aff_vec_coord_tuple K n \u2192 aff_vec_coord_tuple K n \u2192 aff_vec_coord_tuple K n :=\n    \u03bb x y, \u27e8\u03bb m : fin n, x.1 m + y.1 m\u27e9\ndef vec_zero : aff_vec_coord_tuple K n := \u27e8\u03bb m : fin n, 0\u27e9\ndef vec_neg : aff_vec_coord_tuple K n \u2192 aff_vec_coord_tuple K n\n| x := \u27e8\u03bb m : fin n, -(x.1 m)\u27e9\n\n/-! ### type class instances for the abelian group operations -/\ninstance : has_add (aff_vec_coord_tuple K n) := \u27e8vec_add K n\u27e9\ninstance : has_zero (aff_vec_coord_tuple K n) := \u27e8vec_zero K n\u27e9\ninstance : has_neg (aff_vec_coord_tuple K n) := \u27e8vec_neg K n\u27e9\n\n-- misc\ndef pt_zero : aff_pt_coord_tuple K n := \u27e8\u03bb m : fin n, 0\u27e9\n\nlemma vec_zero_id : (0 : aff_vec_coord_tuple K n) = vec_zero K n := rfl\n\nlemma vec_zero_is_zero (m : fin n) : (vec_zero K n).vec m = 0 := rfl\n\n-- properties necessary to show aff_vec_coord_tuple K n is an instance of add_comm_group\n#print add_comm_group\nlemma vec_add_assoc : \u2200 x y z : aff_vec_coord_tuple K n, x + y + z = x + (y + z) :=\nbegin\nintros,\ncases x,\ncases y,\ncases z,\next m,\nexact add_assoc (x m) (y m) (z m),\nend\n\nlemma vec_zero_add : \u2200 x : aff_vec_coord_tuple K n, 0 + x = x :=\nbegin\nintro x,\ncases x,\next m,\nexact zero_add (x m),\nend\n\nlemma vec_add_zero : \u2200 x : aff_vec_coord_tuple K n, x + 0 = x :=\nbegin\nintro x,\ncases x,\next m,\nexact add_zero (x m),\nend\n\nlemma vec_add_left_neg : \u2200 x : aff_vec_coord_tuple K n, -x + x = 0 :=\nbegin\nintro x,\ncases x,\next m,\nexact add_left_neg (x m),\nend\n\nlemma vec_add_comm : \u2200 x y : aff_vec_coord_tuple K n, x + y = y + x :=\nbegin\nintros x y,\ncases x,\ncases y,\next m,\nexact add_comm (x m) (y m),\nend\n\n/-! ### Type class instance for abelian group -/\ninstance aff_comm_group : add_comm_group (aff_vec_coord_tuple K n) :=\nbegin\nsplit,\nexact vec_add_left_neg K n,\nexact vec_add_comm K n,\nexact vec_add_assoc K n,\nexact vec_zero_add K n,\nexact vec_add_zero K n,\nend\n\n\n\n/-! ### Scalar action -/\n\n\n@[ext]\ndef vec_scalar : K \u2192 aff_vec_coord_tuple K n \u2192 aff_vec_coord_tuple K n :=\n    \u03bb a x, \u27e8\u03bb m : fin n, a * x.1 m\u27e9\n\ninstance : has_scalar K (aff_vec_coord_tuple K n) := \u27e8vec_scalar K n\u27e9\n\nlemma vec_one_smul : (1 : K) \u2022 x = x := \nbegin\ncases x,\next m,\nexact one_mul (x m),\nend\n\nlemma vec_mul_smul : \u2200 g h : K, \u2200 x : aff_vec_coord_tuple K n, (g * h) \u2022 x = g \u2022 h \u2022 x :=\nbegin\nintros,\ncases x,\next m,\nexact mul_assoc g h (x m),\nend\n\ninstance : mul_action K (aff_vec_coord_tuple K n) := \u27e8vec_one_smul K n, vec_mul_smul K n\u27e9\n\nlemma vec_smul_add : \u2200 g : K, \u2200 x y : aff_vec_coord_tuple K n, g \u2022 (x + y) = g\u2022x + g\u2022y :=\nbegin\nintros,\ncases x,\ncases y,\next m,\nexact left_distrib g (x m) (y m),\nend\n\nlemma vec_smul_zero : \u2200 g : K, g \u2022 (0 : aff_vec_coord_tuple K n) = 0 :=\nbegin\nintros,\ndsimp [vec_zero_id, vec_zero, has_scalar.smul, vec_scalar],\nrw mul_zero g,\nend\n\ninstance : distrib_mul_action K (aff_vec_coord_tuple K n) := \u27e8vec_smul_add K n, vec_smul_zero K n\u27e9\n\nlemma vec_add_smul : \u2200 g h : K, \u2200 x : aff_vec_coord_tuple K n, (g + h) \u2022 x = g\u2022x + h\u2022x :=\nbegin\nintros,\ncases x,\next m,\nexact right_distrib g h (x m),\nend\n\nlemma vec_zero_smul : \u2200 x : aff_vec_coord_tuple K n, (0 : K) \u2022 x = 0 :=\nbegin\nintros,\ncases x,\next m,\nexact zero_mul (x m),\nend\n\ninstance aff_semimod : semimodule K (aff_vec_coord_tuple K n) := \u27e8vec_add_smul K n, vec_zero_smul K n\u27e9\n\ninstance aff_module : module K (aff_vec_coord_tuple K n) := aff_semimod K n\n\n/-! ### group action of aff_vec_coord_tuple on aff_pt_coord_tuple -/\n\n\ndef aff_group_action : aff_vec_coord_tuple K n \u2192 aff_pt_coord_tuple K n \u2192 aff_pt_coord_tuple K n :=\n    \u03bb x y, \u27e8\u03bb m : fin n, x.1 m + y.1 m\u27e9\n\n\ndef aff_group_sub : aff_pt_coord_tuple K n \u2192 aff_pt_coord_tuple K n \u2192 aff_vec_coord_tuple K n :=\n    \u03bb x y, \u27e8\u03bb m : fin n, x.1 m - y.1 m\u27e9\n\n#check add_action\n\ninstance : has_vadd (aff_vec_coord_tuple K n) (aff_pt_coord_tuple K n) := \u27e8aff_group_action K n\u27e9\n\ninstance : has_vsub (aff_vec_coord_tuple K n) (aff_pt_coord_tuple K n) := \u27e8aff_group_sub K n\u27e9\n\nlemma aff_zero_sadd : \u2200 x : aff_pt_coord_tuple K n, (0 : aff_vec_coord_tuple K n) +\u1d65 x = x :=\nbegin\nintro x,\ncases x,\next m,\nexact zero_add (x m),\nend\n\nlemma aff_add_sadd : \u2200 x y : aff_vec_coord_tuple K n, \u2200 a : aff_pt_coord_tuple K n, x +\u1d65 (y +\u1d65 a) = x + y +\u1d65 a :=\nbegin\nintros,\ncases x,\ncases y,\ncases a,\next m,\nexact eq.symm (add_assoc (x m) (y m) (a m)),\nend\n\nlemma aff_vadd_vsub : \u2200 (x : aff_vec_coord_tuple K n) (a : aff_pt_coord_tuple K n), x +\u1d65 a -\u1d65 a = x := \nbegin\nintros,\next m,\nexact add_sub_cancel (x.vec m) (a.pt m),\nend\n\ninstance : add_action (aff_vec_coord_tuple K n) (aff_pt_coord_tuple K n) := \u27e8aff_group_action K n, aff_zero_sadd K n, aff_add_sadd K n\u27e9\n\nlemma aff_vsub_vadd : \u2200 a b : aff_pt_coord_tuple K n, (a -\u1d65 b) +\u1d65 b = a :=\nbegin\nintros,\next m, \nexact sub_add_cancel (a.pt m) (b.pt m),\nend\n\nlemma aff_add_trans : \u2200 a b : aff_pt_coord_tuple K n, \u2203 x : aff_vec_coord_tuple K n, x +\u1d65 a = b :=\nby {intros, apply exists.intro (b -\u1d65 a), exact aff_vsub_vadd K n b a}\n\nlemma aff_add_free : \u2200 a : aff_pt_coord_tuple K n, \u2200 g h : aff_vec_coord_tuple K n, g +\u1d65 a = h +\u1d65 a \u2192 g = h :=\nbegin\nintros a g h h\u2080,\nhave h\u2081 : g +\u1d65 a -\u1d65 a = h +\u1d65 a -\u1d65 a := by rw h\u2080,\nrw [aff_vadd_vsub K n g a, aff_vadd_vsub K n h a] at h\u2081,\nexact h\u2081,\nend\n\ninstance : nonempty (aff_pt_coord_tuple K n) := \u27e8pt_zero K n\u27e9\n\ninstance aff_torsor : add_torsor (aff_vec_coord_tuple K n) (aff_pt_coord_tuple K n) := \n\u27e8aff_group_action K n, \naff_zero_sadd K n,\naff_add_sadd K n,\naff_group_sub K n,\naff_vsub_vadd K n, \naff_vadd_vsub K n\u27e9\n\n\ninstance aff_coord_is : \n    affine_space \n        (aff_vec_coord_tuple K n) \n        (aff_pt_coord_tuple K n) := \n    aff_torsor K n\n\n\ndef pt_plus_vec\n    {X : Type u} \n    {K : Type v} \n    {V : Type w} \n    {n : \u2115}\n    {\u03b9 : Type*}\n    [inhabited K] \n    [field K] \n    [add_comm_group V] \n    [module K V] \n    [vector_space K V] \n    [affine_space V X] :\n    (aff_pt_coord_tuple K n) \u2192 \n    (aff_vec_coord_tuple K n) \u2192 \n    (aff_pt_coord_tuple K n) \n| p v := aff_group_action K n v p\n\nnotation\n pt +\u1d65 v := pt_plus_vec pt v\n\n \ndef vec_mul_scalar\n    {X : Type u} \n    {K : Type v} \n    {V : Type w} \n    {n : \u2115}\n    {\u03b9 : Type*}\n    [inhabited K] \n    [field K] \n    [add_comm_group V] \n    [module K V] \n    [vector_space K V] \n    [affine_space V X] :\n    (aff_vec_coord_tuple K n) \u2192 \n    K \u2192 \n    (aff_vec_coord_tuple K n) \n| v s := s \u2022 v\n\nnotation\n v \u2022 s := vec_mul_scalar v s\n \ndef pt_minus_vec\n    {X : Type u} \n    {K : Type v} \n    {V : Type w} \n    {n : \u2115}\n    {\u03b9 : Type*}\n    [inhabited K] \n    [field K] \n    [add_comm_group V] \n    [module K V] \n    [vector_space K V] \n    [affine_space V X]:\n    (aff_pt_coord_tuple K n) \u2192 \n    (aff_vec_coord_tuple K n) \u2192 \n    (aff_pt_coord_tuple K n) \n| p v := aff_group_action K n (-v) p\n\nnotation\n pt -\u1d65 v := pt_minus_vec pt v\n/-\nNEW FILE\n-/", "meta": {"author": "kevinsullivan", "repo": "affine_lib", "sha": "056fc95c31bdf473b0c1ecd07f5a061dd6b69234", "save_path": "github-repos/lean/kevinsullivan-affine_lib", "path": "github-repos/lean/kevinsullivan-affine_lib/affine_lib-056fc95c31bdf473b0c1ecd07f5a061dd6b69234/src/old/affine/affine_coordinate_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7002807743687735}}
{"text": "/-!\n# Polynomials\n\nIn this module we define univariate polynomials over a type `R`, together with basic functions\ndefining their evaluation, arithmetic, and divisibility.\n-/\n\n/-- \nThe type of a polynomial with coefficients in `R`. \n\nNOTE : We encode polynomials in such a way so that the `i`th entry of the array corresponds to the\ndegree `i-1` coefficient. For example `#[a,b,c]` <--> `a + b x + c x^2`\n-/\ndef Polynomial R := Array R\n\nnamespace Polynomial\n\ndef ofArray : Array R \u2192 Polynomial R := id\n\ndef toArray : Polynomial R \u2192 Array R := id\n\n/-- A useful coercion to write polynomial literals in terms of elements of type `R` -/\ninstance : Coe (Array R) (Polynomial R) where\n  coe := id\n\ninstance [Inhabited R] : Inhabited (Polynomial R) where\n  default := #[default]\n\ninstance : Append (Polynomial A) where\n  append := .append\n\nprivate def tail (ar : Polynomial A) : Polynomial A := ar.eraseIdx 0\n\nvariable {A : Type _ } [Add A] [Mul A] [HPow A Nat A] [OfNat A (nat_lit 1)] [OfNat A (nat_lit 0)] \n                       [BEq A] [Div A] [Neg A]\n\n/-- Returns a \"normalized\" form for a polynomial, dropping the leading zeroes -/\ndef norm (f : Polynomial A) : Polynomial A := \n  let ans := f.popWhile (\u00b7 == 0)\n  if ans.size == 0 then #[0] else ans\n\ninstance : BEq $ Polynomial A where\n  beq a b := a.norm.toArray == b.norm.toArray\n\n/-- Returns the degree of a polynomial -/\ndef degree (f : Polynomial A) : Nat :=\n  Array.size (norm f) - 1\n\n/-- Tests whether a polynomial is zero -/\ndef isZero (f : Polynomial A) : Bool := f.norm.size == 1 && f.getD 0 0 == 0\n\n/-- Returns the constant term of a polynomial -/\ndef constant (f : Polynomial A) : A := if f.isZero then 0 else f.getD 0 0\n\n/-- Returns the leading coefficient of a polynomial -/\ndef lead (f : Polynomial A) : A := f.getD f.degree 0\n\n/-- Tests whether a polynomial is monic-/\ndef isMonic (f : Polynomial A) : Bool := f.lead == 1\n\n/-- Scales a polynomial by an element of the base type -/\ndef mulByConst (a : A) (f : Polynomial A) : Polynomial A := f.map (\u00b7 * a)\n\ninstance : HMul A (Polynomial A) (Polynomial A) where\n  hMul := mulByConst\n\ndef makeMonic (f : Polynomial A) : Polynomial A := (1 / f.lead) * f\n\n/-- Evaluates a polynomial at a particular value `a : A` -/\ndef eval (f : Polynomial A) (a : A) : A :=\n  let f := f.norm\n  let action (i : Fin f.size) c := c * a ^ (i : Nat)\n  Array.foldr (. + .) 0 (f.mapIdx action)\n\nprivate def zeros (n : Nat) : Polynomial A := mkArray n 0\n\n/-- The zero polynomial -/\ndef zero : Polynomial A := #[0]\n\nprivate def padZeroes (f : Polynomial A) (n : Nat) : Polynomial A :=\n  f ++ zeros n \n\n/-- Returns the addition addition of two polynomials -/\ndef polyAdd (f : Polynomial A) (g : Polynomial A) : Polynomial A :=\n  let (f, g) := (f.norm, g.norm)\n  let action (f\u2081 : Polynomial A) (f\u2082 : Polynomial A) := f\u2081.zip f\u2082 |>.map (fun (x, y) => x + y)\n  if f.size < g.size\n  then\n    action (padZeroes f (g.size - f.size)) g\n  else\n    if f.size > g.size\n    then action f (padZeroes g (f.size - g.size))\n    else action f g\n\ninstance : Add (Polynomial A) where\n  add := polyAdd\n\ninstance : Neg (Polynomial A) where\n  neg := Array.map Neg.neg\n\n/-- Returns the subtraction of two polynomials -/\ndef polySub (f : Polynomial A) (g : Polynomial A) : Polynomial A := f + (-g)\n\ninstance : Sub (Polynomial A) where\n  sub := polySub\n\n/-- Returns the multiplication of two polynomials -/\ndef polyMul (f : Polynomial A) : Polynomial A \u2192 Polynomial A :=\n  Array.foldr (fun x (acc : Polynomial A) => (x * f) + (zero ++ acc)) (#[] : Polynomial A)\n\ninstance : Mul (Polynomial A) where\n  mul := polyMul\n\n/-- \nReturns `(q, r)` where `q` is the quotient of division of polynomial `f` by `g` and `r` is the\nremainder\n-/\ndef polyQuotRem (f : Polynomial A) (g : Polynomial A) : Polynomial A \u00d7 Polynomial A :=\n  let rec polyQRAux (f' g' : Polynomial A) (n : Nat) : Polynomial A \u00d7 Polynomial A :=\n    match n with\n    | 0     => (#[], #[])\n    | k + 1 => \n      if k + 1 < g'.size then (#[],f')\n      else\n        let x := f'.getD 0 0\n        let y := g'.getD 0 0\n        let z := x / y\n        let (q', r') := polyQRAux (tail $ f' - g' * (ofArray #[z])) g' k\n        (#[z] ++ q'.toArray, r')\n  if g == #[0] then (#[0], f) else\n  let (f, g) := (f.norm, g.norm)\n  let (q, r) := polyQRAux (f.reverse) (g.reverse) (f.size)\n  (q.reverse, r.reverse)\n\n/-- Returns the quotient of the division of the polynomial `f` by `g` -/\ndef polyDiv (f g : Polynomial A) : Polynomial A := polyQuotRem f g |>.fst\n\n/-- Returns the remainder of the division of the polynomial `f` by `g` -/\ndef polyMod (f g : Polynomial A) : Polynomial A := polyQuotRem f g |>.snd\n\n/-- \nReturns `(a, b, d)` where `d` is the greatest common divisor of `f` and `g` and `a`, `b` satisfy\n\n`a * f + b * g = d `\n\nTODO : Eliminate `partial` using `termination_by _ => g.degree` and a proof that `polyQuotRem`\nreduces degree.\n-/\npartial def polyEuc [Inhabited A] [Div A] (f g : Polynomial A) : Polynomial A \u00d7 Polynomial A \u00d7 Polynomial A \n  := if g.isZero then \n       (#[1 / f.lead], #[0], f.makeMonic) else\n       let (q, r) := polyQuotRem f g\n       let (s, t, d) := polyEuc g r\n       (t, s - q * t, d)\n\n/-- \nReturns the monic polynomial with the roots taken from the list `a`.\n-/\ndef rootsToPoly (as : List A) : Polynomial A :=\n  match as with\n  | [] => #[1]\n  | (root :: roots) => \n    let monom : Polynomial A := #[-root,1]\n    monom * (rootsToPoly roots)\n\ninstance : OfNat (Polynomial A) (nat_lit 1) where\n  ofNat := #[1]\n\ninstance : OfNat (Polynomial A) (nat_lit 0) where\n  ofNat := zero\n\nend Polynomial\n", "meta": {"author": "lurk-lab", "repo": "YatimaStdLib.lean", "sha": "f39dca7a0815ee65e71776d46337f0240037ff6d", "save_path": "github-repos/lean/lurk-lab-YatimaStdLib.lean", "path": "github-repos/lean/lurk-lab-YatimaStdLib.lean/YatimaStdLib.lean-f39dca7a0815ee65e71776d46337f0240037ff6d/YatimaStdLib/Polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7002807741514415}}
{"text": "import data.rat\n       galois.logic\n       galois.vector.lemmas\n\nuniverses u\n\nsection\nparameters {A : Type u} [comm_ring A]\n\ndef dot_product {n : \u2115} (x y : vector A n) : A\n  := list.foldr (+) 0 (vector.map\u2082 (*) x y).to_list\n\nlemma dot_product_cons {n : \u2115} (x y : A) (xs ys : vector A n)\n  : dot_product (x :: xs) (y :: ys)\n  = x * y + dot_product xs ys\n:= begin\ninduction xs, induction ys,\nreflexivity,\nend\n\nlemma dot_product_nil :  dot_product vector.nil vector.nil = 0\n  := rfl\n\nlemma dot_product_0_len (xs ys : vector A 0)\n  : dot_product xs ys = 0\n:= begin\nrw vector.eq_nil xs, rw vector.eq_nil ys, reflexivity,\nend\n\n\nlemma dot_product_0 {n : \u2115} (xs : vector A n)\n  : dot_product (vector.generate n (\u03bb _, (0 : A))) xs = 0\n:= begin\ninduction n,\nrw vector.eq_nil xs,\nrw dot_product_0_len,\ndsimp [vector.generate],\nhave Hxs := xs.invert_succ, induction Hxs with x xs' Hxs,\nsubst xs, rw dot_product_cons,\nrw ih_1, simp,\nend\n\n\nlemma dot_product_unit (n : \u2115) (i : fin n) (c : A) (v : vector A n)\n  : dot_product (vector.generate n (\u03bbj, if i.val = j then c else 0)) v\n  = c * v.nth i\n:= begin\ninduction n; dsimp [vector.generate],\nexfalso, apply fin.fin_0_empty, assumption,\nhave Hv := v.invert_succ,\ninduction Hv with x xs Hv, subst Hv,\nrw dot_product_cons,\napply (if H : i.val = 0 then _ else _),\n{ rw (if_pos H), rw (vector.nth_0 _ _ H),\n  dsimp [function.comp],\n  rw H,\n  have Hf : (\u03bb (x : \u2115), ite (0 = nat.succ x) c 0) = \u03bb _, 0,\n  apply funext; intros x,\n  rw if_neg, intros contra, cases contra,\n  rw Hf, clear Hf,\n  rw dot_product_0, simp,\n},\n{ rw (if_neg H), simp,\n  have H' : i \u2260 0,\n  intros contra, apply H, rw contra, reflexivity,\n  rw vector.nth_cons_nz _ H', dsimp [function.comp],\n  rw \u2190 ih_1, f_equal, f_equal,\n  apply funext, intros n,\n  f_equal, apply ite_iff,\n  apply fin.succ_pred_equiv, }\nend\n\nlemma dot_product_scale_l {n : \u2115} (c : A) (xs ys : vector A n)\n  : dot_product (vector.map (\u03bb x, c * x) xs) ys\n  = c * dot_product xs ys\n:= begin\ninduction n,\n{ rw (vector.eq_nil xs), rw (vector.eq_nil ys),\n  rw vector.map_nil,\n  rw dot_product_nil, simp, },\n{ have Hx := xs.invert_succ, induction Hx with x xs' Hx, subst xs,\n  have Hy := ys.invert_succ, induction Hy with y ys' Hy, subst ys,\n  rw vector.map_cons, repeat { rw dot_product_cons },\n  rw mul_add, rw ih_1, simp,\n}\nend\n\nlemma dot_product_comm {n : \u2115} (x y : vector A n)\n  : dot_product x y = dot_product y x\n:= begin\ndsimp [dot_product],\nrw vector.map\u2082_comm, intros, apply mul_comm,\nend\n\nlemma dot_product_sum_r {n : \u2115} (x y z : vector A n)\n  : dot_product x (vector.map\u2082 (+) y z)\n  = dot_product x y + dot_product x z\n:= begin\ninduction n,\n{ repeat {rw dot_product_0_len },\n  rw add_zero, },\n{ have Hx := x.invert_succ, induction Hx with x' xs Hx, subst x,\n  have Hy := y.invert_succ, induction Hy with y' ys Hy, subst y,\n  have Hz := z.invert_succ, induction Hz with z' zs Hz, subst z,\n  rw vector.map\u2082_cons, repeat { rw dot_product_cons },\n  rw ih_1, rw mul_add, simp,\n}\nend\n\nlemma dot_product_sum_l {n : \u2115} (x y z : vector A n)\n  : dot_product (vector.map\u2082 (+) x y) z\n  = dot_product x z + dot_product y z\n:= begin\nrw dot_product_comm, rw dot_product_sum_r,\nrw dot_product_comm z x, rw dot_product_comm z y,\nend\n\nend", "meta": {"author": "GaloisInc", "repo": "lean-protocol-support", "sha": "cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda", "save_path": "github-repos/lean/GaloisInc-lean-protocol-support", "path": "github-repos/lean/GaloisInc-lean-protocol-support/lean-protocol-support-cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda/galois/vector/dot_product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.7001959657520882}}
{"text": "inductive Expr : Type\n  | const (n : Nat)\n  | plus (e\u2081 e\u2082 : Expr)\n  | mul (e\u2081 e\u2082 : Expr)\n  deriving BEq, Inhabited, Repr, DecidableEq\n\ndef Expr.eval : Expr \u2192 Nat\n  | const n    => n\n  | plus e\u2081 e\u2082 => eval e\u2081 + eval e\u2082\n  | mul e\u2081 e\u2082  => eval e\u2081 * eval e\u2082\n\ndef Expr.times : Nat \u2192 Expr \u2192 Expr\n  | k, const n    => const (k*n)\n  | k, plus e\u2081 e\u2082 => plus (times k e\u2081) (times k e\u2082)\n  | k, mul e\u2081 e\u2082  => mul (times k e\u2081) e\u2082\n\ntheorem eval_times (k : Nat) (e : Expr) : (e.times k |>.eval) = k * e.eval := by\n  induction e with simp [Expr.times, Expr.eval]\n  | plus e\u2081 e\u2082 ih\u2081 ih\u2082 => simp [ih\u2081, ih\u2082, Nat.left_distrib]\n  | mul  _ _ ih\u2081 ih\u2082   => simp [ih\u2081, Nat.mul_assoc]\n\ndef Expr.reassoc : Expr \u2192 Expr\n  | const n    => const n\n  | plus e\u2081 e\u2082 =>\n    let e\u2081' := e\u2081.reassoc\n    let e\u2082' := e\u2082.reassoc\n    match e\u2082' with\n    | plus e\u2082\u2081 e\u2082\u2082 => plus (plus e\u2081' e\u2082\u2081) e\u2082\u2082\n    | _            => plus e\u2081' e\u2082'\n  | mul e\u2081 e\u2082 =>\n    let e\u2081' := e\u2081.reassoc\n    let e\u2082' := e\u2082.reassoc\n    match e\u2082' with\n    | mul e\u2082\u2081 e\u2082\u2082 => mul (mul e\u2081' e\u2082\u2081) e\u2082\u2082\n    | _           => mul e\u2081' e\u2082'\n\ntheorem eval_reassoc (e : Expr) : e.reassoc.eval = e.eval := by\n  induction e with simp [Expr.reassoc]\n  | plus e\u2081 e\u2082 ih\u2081 ih\u2082 =>\n    generalize h : (Expr.reassoc e\u2082) = e\u2082'\n    cases e\u2082' <;> rw [h] at ih\u2082 <;> simp [Expr.eval] at * <;> rw [\u2190 ih\u2082, ih\u2081]; rw [Nat.add_assoc]\n  | mul e\u2081 e\u2082 ih\u2081 ih\u2082 =>\n    generalize h : (Expr.reassoc e\u2082) = e\u2082'\n    cases e\u2082' <;> rw [h] at ih\u2082 <;> simp [Expr.eval] at * <;> rw [\u2190 ih\u2082, ih\u2081]; rw [Nat.mul_assoc]\n", "meta": {"author": "gebner", "repo": "lean4-old", "sha": "ee51cdfaf63ee313c914d83264f91f414a0e3b6e", "save_path": "github-repos/lean/gebner-lean4-old", "path": "github-repos/lean/gebner-lean4-old/lean4-old-ee51cdfaf63ee313c914d83264f91f414a0e3b6e/tests/lean/run/exp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703476, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7001959568914177}}
{"text": "/-\nCopyright (c) 2021 Johan Commelin. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johan Commelin\n-/\n\nimport data.polynomial.coeff\nimport data.nat.choose.basic\n\n/-!\n\n# Vandermonde's identity\n\nIn this file we prove Vandermonde's identity (`nat.add_choose_eq`):\n`(m + n).choose k = \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, m.choose ij.1 * n.choose ij.2`\n\nWe follow the algebraic proof from\nhttps://en.wikipedia.org/wiki/Vandermonde%27s_identity#Algebraic_proof .\n\n-/\n\nopen_locale big_operators\n\nopen polynomial finset.nat\n\n/-- Vandermonde's identity -/\nlemma nat.add_choose_eq (m n k : \u2115) :\n  (m + n).choose k = \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, m.choose ij.1 * n.choose ij.2 :=\nbegin\n  calc (m + n).choose k\n      = ((X + 1) ^ (m + n)).coeff k : _\n  ... = ((X + 1) ^ m * (X + 1) ^ n).coeff k : by rw pow_add\n  ... = \u2211 (ij : \u2115 \u00d7 \u2115) in antidiagonal k, m.choose ij.1 * n.choose ij.2 : _,\n  { rw [coeff_X_add_one_pow, nat.cast_id], },\n  { rw [coeff_mul, finset.sum_congr rfl],\n    simp only [coeff_X_add_one_pow, nat.cast_id, eq_self_iff_true, imp_true_iff], }\nend\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/data/nat/choose/vandermonde.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7001959541139563}}
{"text": "/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-/\n\nimport linear_algebra.charpoly.basic\nimport linear_algebra.matrix.basis\n\n/-!\n\n# Characteristic polynomial\n\n## Main result\n\n* `linear_map.charpoly_to_matrix f` : `charpoly f` is the characteristic polynomial of the matrix\nof `f` in any basis.\n\n-/\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} [comm_ring R] [nontrivial R]\nvariables [add_comm_group M] [module R M] [module.free R M] [module.finite R M] (f : M \u2192\u2097[R] M)\n\nopen_locale classical matrix\n\nnoncomputable theory\n\nopen module.free polynomial matrix\n\nnamespace linear_map\n\nsection basic\n\n/-- `charpoly f` is the characteristic polynomial of the matrix of `f` in any basis. -/\n@[simp] lemma charpoly_to_matrix {\u03b9 : Type w} [fintype \u03b9] (b : basis \u03b9 R M) :\n  (to_matrix b b f).charpoly = f.charpoly :=\nbegin\n  set A := to_matrix b b f,\n  set b' := choose_basis R M,\n  set \u03b9' := choose_basis_index R M,\n  set A' := to_matrix b' b' f,\n  set e := basis.index_equiv b b',\n  set \u03c6 := reindex_linear_equiv R R e e,\n  set \u03c6\u2081 := reindex_linear_equiv R R e (equiv.refl \u03b9'),\n  set \u03c6\u2082 := reindex_linear_equiv R R (equiv.refl \u03b9') (equiv.refl \u03b9'),\n  set \u03c6\u2083 := reindex_linear_equiv R R (equiv.refl \u03b9') e,\n  set P := b.to_matrix b',\n  set Q := b'.to_matrix b,\n\n  have hPQ : C.map_matrix (\u03c6\u2081 P) \u2b1d (C.map_matrix (\u03c6\u2083 Q)) = 1,\n  { rw [ring_hom.map_matrix_apply, ring_hom.map_matrix_apply, \u2190 matrix.map_mul, \u2190\n      @reindex_linear_equiv_mul _ \u03b9' _ _ _ _ R R, basis.to_matrix_mul_to_matrix_flip,\n      reindex_linear_equiv_one, \u2190 ring_hom.map_matrix_apply, ring_hom.map_one] },\n\n  calc A.charpoly = (reindex e e A).charpoly : (charpoly_reindex _ _).symm\n  ... = (scalar \u03b9' X - C.map_matrix (\u03c6 A)).det : rfl\n  ... = (scalar \u03b9' X - C.map_matrix (\u03c6 (P \u2b1d A' \u2b1d Q))).det :\n    by rw [basis_to_matrix_mul_linear_map_to_matrix_mul_basis_to_matrix]\n  ... = (scalar \u03b9' X - C.map_matrix (\u03c6\u2081 P \u2b1d \u03c6\u2082 A' \u2b1d \u03c6\u2083 Q)).det :\n    by rw [reindex_linear_equiv_mul R R _ _ e, reindex_linear_equiv_mul R R e _ _]\n  ... = (scalar \u03b9' X - (C.map_matrix (\u03c6\u2081 P) \u2b1d C.map_matrix A' \u2b1d C.map_matrix (\u03c6\u2083 Q))).det : by simp\n  ... = (scalar \u03b9' X \u2b1d C.map_matrix (\u03c6\u2081 P) \u2b1d (C.map_matrix (\u03c6\u2083 Q)) -\n    (C.map_matrix (\u03c6\u2081 P) \u2b1d C.map_matrix A' \u2b1d C.map_matrix (\u03c6\u2083 Q))).det :\n      by { rw [matrix.mul_assoc ((scalar \u03b9') X), hPQ, matrix.mul_one] }\n  ... = (C.map_matrix (\u03c6\u2081 P) \u2b1d scalar \u03b9' X \u2b1d (C.map_matrix (\u03c6\u2083 Q)) -\n    (C.map_matrix (\u03c6\u2081 P) \u2b1d C.map_matrix A' \u2b1d C.map_matrix (\u03c6\u2083 Q))).det : by simp\n  ... = (C.map_matrix (\u03c6\u2081 P) \u2b1d (scalar \u03b9' X - C.map_matrix A') \u2b1d C.map_matrix (\u03c6\u2083 Q)).det :\n    by rw [\u2190 matrix.sub_mul, \u2190 matrix.mul_sub]\n  ... = (C.map_matrix (\u03c6\u2081 P)).det * (scalar \u03b9' X - C.map_matrix A').det *\n    (C.map_matrix (\u03c6\u2083 Q)).det : by rw [det_mul, det_mul]\n  ... = (C.map_matrix (\u03c6\u2081 P)).det * (C.map_matrix (\u03c6\u2083 Q)).det *\n    (scalar \u03b9' X - C.map_matrix A').det : by ring\n  ... = (scalar \u03b9' X - C.map_matrix A').det : by rw [\u2190 det_mul, hPQ, det_one, one_mul]\n  ... = f.charpoly : rfl\nend\n\nend basic\n\nend linear_map\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/linear_algebra/charpoly/to_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703478, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7001959523004273}}
{"text": "import data.finset\n\n-- The Number of Subsets of a Set\n\nopen finset\n\ntheorem t052 {\u03b1} : \u03a0 (s : finset \u03b1), card (powerset s) = 2 ^ card s\n:= finset.card_powerset\n", "meta": {"author": "AtnNn", "repo": "lean-sandbox", "sha": "8c68afbdc09213173aef1be195da7a9a86060a97", "save_path": "github-repos/lean/AtnNn-lean-sandbox", "path": "github-repos/lean/AtnNn-lean-sandbox/lean-sandbox-8c68afbdc09213173aef1be195da7a9a86060a97/src/100_theorems/t052.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7001445202077617}}
{"text": "import data.real.basic\n\ndef fn_ub (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, f x \u2264 a\ndef fn_lb (f : \u211d \u2192 \u211d) (a : \u211d) : Prop := \u2200 x, a \u2264 f x\n\nvariables (f g : \u211d \u2192 \u211d) (a b : \u211d)\n\n#check add_le_add\n#check mul_nonneg\n#check mul_le_mul\n\n-- BEGIN\nexample (hfa : fn_lb f a) (hgb : fn_lb g b) :\n  fn_lb (\u03bb x, f x + g x) (a + b) :=\nbegin\n  intro x,\n  dsimp,\n  apply add_le_add,\n  apply hfa,\n  apply hgb,\nend\n\nexample (nnf : fn_lb f 0) (nng : fn_lb g 0) :\n  fn_lb (\u03bb x, f x * g x) 0 :=\nbegin\n  intro x,\n  dsimp,\n  sorry,\nend\n\n\nexample (hfa : fn_ub f a) (hfb : fn_ub g b)\n    (nng : fn_lb g 0) (nna : 0 \u2264 a) :\n  fn_ub (\u03bb x, f x * g x) (a * b) :=\nbegin\n  intro x,\n  dsimp,\n  sorry,\nend\n\n-- END", "meta": {"author": "xhkittyyan", "repo": "Lean-Seminars-Series-Fall-2022", "sha": "6951cdf2cb4e001666d2a56170601325f69d52b5", "save_path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022", "path": "github-repos/lean/xhkittyyan-Lean-Seminars-Series-Fall-2022/Lean-Seminars-Series-Fall-2022-6951cdf2cb4e001666d2a56170601325f69d52b5/src/3_apply_exact/3.1_apply/ex11_apply_fn_lb_operations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.7001445153312608}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Chris Hughes, Mario Carneiro\n-/\n\nimport algebra.algebra.basic\nimport ring_theory.ideal.operations\nimport ring_theory.jacobson_ideal\nimport logic.equiv.transfer_instance\n\n/-!\n\n# Local rings\n\nDefine local rings as commutative rings having a unique maximal ideal.\n\n## Main definitions\n\n* `local_ring`: A predicate on commutative semirings, stating that for any pair of elements that\n  adds up to `1`, one of them is a unit. This is shown to be equivalent to the condition that there\n  exists a unique maximal ideal.\n* `local_ring.maximal_ideal`: The unique maximal ideal for a local rings. Its carrier set is the\n  set of non units.\n* `is_local_ring_hom`: A predicate on semiring homomorphisms, requiring that it maps nonunits\n  to nonunits. For local rings, this means that the image of the unique maximal ideal is again\n  contained in the unique maximal ideal.\n* `local_ring.residue_field`: The quotient of a local ring by its maximal ideal.\n\n-/\n\nuniverses u v w u'\n\nvariables {R : Type u} {S : Type v} {T : Type w} {K : Type u'}\n\n/-- A semiring is local if it is nontrivial and `a` or `b` is a unit whenever `a + b = 1`.\nNote that `local_ring` is a predicate. -/\nclass local_ring (R : Type u) [semiring R] extends nontrivial R : Prop :=\nof_is_unit_or_is_unit_of_add_one ::\n(is_unit_or_is_unit_of_add_one {a b : R} (h : a + b = 1) : is_unit a \u2228 is_unit b)\n\nsection comm_semiring\nvariables [comm_semiring R]\n\nnamespace local_ring\n\nlemma of_is_unit_or_is_unit_of_is_unit_add [nontrivial R]\n  (h : \u2200 a b : R, is_unit (a + b) \u2192 is_unit a \u2228 is_unit b) :\n  local_ring R :=\n\u27e8\u03bb a b hab,  h a b $ hab.symm \u25b8 is_unit_one\u27e9\n\n/-- A semiring is local if it is nontrivial and the set of nonunits is closed under the addition. -/\nlemma of_nonunits_add [nontrivial R]\n  (h : \u2200 a b : R, a \u2208 nonunits R \u2192 b \u2208 nonunits R \u2192 a + b \u2208 nonunits R) :\n  local_ring R :=\n\u27e8\u03bb a b hab, or_iff_not_and_not.2 $ \u03bb H, h a b H.1 H.2 $ hab.symm \u25b8 is_unit_one\u27e9\n\n/-- A semiring is local if it has a unique maximal ideal. -/\nlemma of_unique_max_ideal (h : \u2203! I : ideal R, I.is_maximal) :\n  local_ring R :=\n@of_nonunits_add _ _ (nontrivial_of_ne (0 : R) 1 $\n  let \u27e8I, Imax, _\u27e9 := h in (\u03bb (H : 0 = 1), Imax.1.1 $ I.eq_top_iff_one.2 $ H \u25b8 I.zero_mem)) $\n  \u03bb x y hx hy H,\n    let \u27e8I, Imax, Iuniq\u27e9 := h in\n    let \u27e8Ix, Ixmax, Hx\u27e9 := exists_max_ideal_of_mem_nonunits hx in\n    let \u27e8Iy, Iymax, Hy\u27e9 := exists_max_ideal_of_mem_nonunits hy in\n    have xmemI : x \u2208 I, from Iuniq Ix Ixmax \u25b8 Hx,\n    have ymemI : y \u2208 I, from Iuniq Iy Iymax \u25b8 Hy,\n    Imax.1.1 $ I.eq_top_of_is_unit_mem (I.add_mem xmemI ymemI) H\n\nlemma of_unique_nonzero_prime (h : \u2203! P : ideal R, P \u2260 \u22a5 \u2227 ideal.is_prime P) :\n  local_ring R :=\nof_unique_max_ideal begin\n  rcases h with \u27e8P, \u27e8hPnonzero, hPnot_top, _\u27e9, hPunique\u27e9,\n  refine \u27e8P, \u27e8\u27e8hPnot_top, _\u27e9\u27e9, \u03bb M hM, hPunique _ \u27e8_, ideal.is_maximal.is_prime hM\u27e9\u27e9,\n  { refine ideal.maximal_of_no_maximal (\u03bb M hPM hM, ne_of_lt hPM _),\n    exact (hPunique _ \u27e8ne_bot_of_gt hPM, ideal.is_maximal.is_prime hM\u27e9).symm },\n  { rintro rfl,\n    exact hPnot_top (hM.1.2 P (bot_lt_iff_ne_bot.2 hPnonzero)) },\nend\n\nvariables [local_ring R]\n\nlemma is_unit_or_is_unit_of_is_unit_add {a b : R} (h : is_unit (a + b)) :\n  is_unit a \u2228 is_unit b :=\nbegin\n  rcases h with \u27e8u, hu\u27e9,\n  rw [\u2190units.inv_mul_eq_one, mul_add] at hu,\n  apply or.imp _ _ (is_unit_or_is_unit_of_add_one hu);\n    exact is_unit_of_mul_is_unit_right,\nend\n\nlemma nonunits_add {a b : R} (ha : a \u2208 nonunits R) (hb : b \u2208 nonunits R) : a + b \u2208 nonunits R:=\n\u03bb H, not_or ha hb (is_unit_or_is_unit_of_is_unit_add H)\n\nvariables (R)\n\n/-- The ideal of elements that are not units. -/\ndef maximal_ideal : ideal R :=\n{ carrier := nonunits R,\n  zero_mem' := zero_mem_nonunits.2 $ zero_ne_one,\n  add_mem' := \u03bb x y hx hy, nonunits_add hx hy,\n  smul_mem' := \u03bb a x, mul_mem_nonunits_right }\n\ninstance maximal_ideal.is_maximal : (maximal_ideal R).is_maximal :=\nbegin\n  rw ideal.is_maximal_iff,\n  split,\n  { intro h, apply h, exact is_unit_one },\n  { intros I x hI hx H,\n    erw not_not at hx,\n    rcases hx with \u27e8u,rfl\u27e9,\n    simpa using I.mul_mem_left \u2191u\u207b\u00b9 H }\nend\n\nlemma maximal_ideal_unique : \u2203! I : ideal R, I.is_maximal :=\n\u27e8maximal_ideal R, maximal_ideal.is_maximal R,\n  \u03bb I hI, hI.eq_of_le (maximal_ideal.is_maximal R).1.1 $\n  \u03bb x hx, hI.1.1 \u2218 I.eq_top_of_is_unit_mem hx\u27e9\n\nvariable {R}\n\nlemma eq_maximal_ideal {I : ideal R} (hI : I.is_maximal) : I = maximal_ideal R :=\nunique_of_exists_unique (maximal_ideal_unique R) hI $ maximal_ideal.is_maximal R\n\nlemma le_maximal_ideal {J : ideal R} (hJ : J \u2260 \u22a4) : J \u2264 maximal_ideal R :=\nbegin\n  rcases ideal.exists_le_maximal J hJ with \u27e8M, hM1, hM2\u27e9,\n  rwa \u2190eq_maximal_ideal hM1\nend\n\n@[simp] lemma mem_maximal_ideal (x) : x \u2208 maximal_ideal R \u2194 x \u2208 nonunits R := iff.rfl\n\nlemma is_field_iff_maximal_ideal_eq :\n  is_field R \u2194 maximal_ideal R = \u22a5 :=\nnot_iff_not.mp \u27e8ring.ne_bot_of_is_maximal_of_not_is_field infer_instance,\n  \u03bb h, ring.not_is_field_iff_exists_prime.mpr \u27e8_, h, ideal.is_maximal.is_prime' _\u27e9\u27e9\n\nend local_ring\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R]\n\nnamespace local_ring\n\nlemma of_is_unit_or_is_unit_one_sub_self [nontrivial R]\n  (h : \u2200 a : R, is_unit a \u2228 is_unit (1 - a)) : local_ring R :=\n\u27e8\u03bb a b hab, add_sub_cancel' a b \u25b8 hab.symm \u25b8 h a\u27e9\n\nvariables [local_ring R]\n\nlemma is_unit_or_is_unit_one_sub_self (a : R) : is_unit a \u2228 is_unit (1 - a) :=\nis_unit_or_is_unit_of_is_unit_add $ (add_sub_cancel'_right a 1).symm \u25b8 is_unit_one\n\nlemma is_unit_of_mem_nonunits_one_sub_self (a : R) (h : 1 - a \u2208 nonunits R) :\n  is_unit a :=\nor_iff_not_imp_right.1 (is_unit_or_is_unit_one_sub_self a) h\n\nlemma is_unit_one_sub_self_of_mem_nonunits (a : R) (h : a \u2208 nonunits R) :\n  is_unit (1 - a) :=\nor_iff_not_imp_left.1 (is_unit_or_is_unit_one_sub_self a) h\n\nlemma of_surjective' [comm_ring S] [nontrivial S] (f : R \u2192+* S) (hf : function.surjective f) :\n  local_ring S :=\nof_is_unit_or_is_unit_one_sub_self\nbegin\n  intros b,\n  obtain \u27e8a, rfl\u27e9 := hf b,\n  apply (is_unit_or_is_unit_one_sub_self a).imp f.is_unit_map _,\n  rw [\u2190 f.map_one, \u2190 f.map_sub],\n  apply f.is_unit_map,\nend\n\nlemma jacobson_eq_maximal_ideal (I : ideal R) (h : I \u2260 \u22a4) :\n  I.jacobson = local_ring.maximal_ideal R :=\nbegin\n  apply le_antisymm,\n  { exact Inf_le \u27e8local_ring.le_maximal_ideal h, local_ring.maximal_ideal.is_maximal R\u27e9 },\n  { exact le_Inf (\u03bb J (hJ : I \u2264 J \u2227 J.is_maximal),\n      le_of_eq (local_ring.eq_maximal_ideal hJ.2).symm) }\nend\n\nend local_ring\n\nend comm_ring\n\n/-- A local ring homomorphism is a homomorphism `f` between local rings such that `a` in the domain\n  is a unit if `f a` is a unit for any `a`. See `local_ring.local_hom_tfae` for other equivalent\n  definitions. -/\nclass is_local_ring_hom [semiring R] [semiring S] (f : R \u2192+* S) : Prop :=\n(map_nonunit : \u2200 a, is_unit (f a) \u2192 is_unit a)\n\nsection\nvariables [semiring R] [semiring S] [semiring T]\n\ninstance is_local_ring_hom_id (R : Type*) [semiring R] : is_local_ring_hom (ring_hom.id R) :=\n{ map_nonunit := \u03bb a, id }\n\n@[simp] lemma is_unit_map_iff (f : R \u2192+* S) [is_local_ring_hom f] (a) :\n  is_unit (f a) \u2194 is_unit a :=\n\u27e8is_local_ring_hom.map_nonunit a, f.is_unit_map\u27e9\n\n@[simp] lemma map_mem_nonunits_iff (f : R \u2192+* S) [is_local_ring_hom f] (a) :\n  f a \u2208 nonunits S \u2194 a \u2208 nonunits R :=\n\u27e8\u03bb h ha, h $ (is_unit_map_iff f a).mpr ha, \u03bb h ha, h $ (is_unit_map_iff f a).mp ha\u27e9\n\ninstance is_local_ring_hom_comp\n  (g : S \u2192+* T) (f : R \u2192+* S) [is_local_ring_hom g] [is_local_ring_hom f] :\n  is_local_ring_hom (g.comp f) :=\n{ map_nonunit := \u03bb a, is_local_ring_hom.map_nonunit a \u2218 is_local_ring_hom.map_nonunit (f a) }\n\ninstance is_local_ring_hom_equiv (f : R \u2243+* S) :\n  is_local_ring_hom (f : R \u2192+* S) :=\n{ map_nonunit := \u03bb a ha,\n  begin\n    convert (f.symm : S \u2192+* R).is_unit_map ha,\n    exact (ring_equiv.symm_apply_apply f a).symm,\n  end }\n\n@[simp] lemma is_unit_of_map_unit (f : R \u2192+* S) [is_local_ring_hom f]\n  (a) (h : is_unit (f a)) : is_unit a :=\nis_local_ring_hom.map_nonunit a h\n\ntheorem of_irreducible_map (f : R \u2192+* S) [h : is_local_ring_hom f] {x}\n  (hfx : irreducible (f x)) : irreducible x :=\n\u27e8\u03bb h, hfx.not_unit $ is_unit.map f h, \u03bb p q hx, let \u27e8H\u27e9 := h in\nor.imp (H p) (H q) $ hfx.is_unit_or_is_unit $ f.map_mul p q \u25b8 congr_arg f hx\u27e9\n\nlemma is_local_ring_hom_of_comp (f : R \u2192+* S) (g : S \u2192+* T) [is_local_ring_hom (g.comp f)] :\n  is_local_ring_hom f :=\n\u27e8\u03bb a ha, (is_unit_map_iff (g.comp f) _).mp (g.is_unit_map ha)\u27e9\n\n/-- If `f : R \u2192+* S` is a local ring hom, then `R` is a local ring if `S` is. -/\nlemma _root_.ring_hom.domain_local_ring {R S : Type*} [comm_semiring R] [comm_semiring S]\n  [H : _root_.local_ring S] (f : R \u2192+* S)\n  [is_local_ring_hom f] : _root_.local_ring R :=\nbegin\n  haveI : nontrivial R := pullback_nonzero f f.map_zero f.map_one,\n  apply local_ring.of_nonunits_add,\n  intros a b,\n  simp_rw [\u2190map_mem_nonunits_iff f, f.map_add],\n  exact local_ring.nonunits_add\nend\n\nend\n\nsection\nopen local_ring\nvariables [comm_semiring R] [local_ring R] [comm_semiring S] [local_ring S]\n\n/--\nThe image of the maximal ideal of the source is contained within the maximal ideal of the target.\n-/\nlemma map_nonunit (f : R \u2192+* S) [is_local_ring_hom f] (a : R) (h : a \u2208 maximal_ideal R) :\n  f a \u2208 maximal_ideal S :=\n\u03bb H, h $ is_unit_of_map_unit f a H\n\nend\n\nnamespace local_ring\n\nsection\nvariables [comm_semiring R] [local_ring R] [comm_semiring S] [local_ring S]\n\n/--\nA ring homomorphism between local rings is a local ring hom iff it reflects units,\ni.e. any preimage of a unit is still a unit. https://stacks.math.columbia.edu/tag/07BJ\n-/\ntheorem local_hom_tfae (f : R \u2192+* S) :\n  tfae [is_local_ring_hom f,\n        f '' (maximal_ideal R).1 \u2286 maximal_ideal S,\n        (maximal_ideal R).map f \u2264 maximal_ideal S,\n        maximal_ideal R \u2264 (maximal_ideal S).comap f,\n        (maximal_ideal S).comap f = maximal_ideal R] :=\nbegin\n  tfae_have : 1 \u2192 2, rintros _ _ \u27e8a,ha,rfl\u27e9,\n    resetI, exact map_nonunit f a ha,\n  tfae_have : 2 \u2192 4, exact set.image_subset_iff.1,\n  tfae_have : 3 \u2194 4, exact ideal.map_le_iff_le_comap,\n  tfae_have : 4 \u2192 1, intro h, fsplit, exact \u03bb x, not_imp_not.1 (@h x),\n  tfae_have : 1 \u2192 5, intro, resetI, ext,\n    exact not_iff_not.2 (is_unit_map_iff f x),\n  tfae_have : 5 \u2192 4, exact \u03bb h, le_of_eq h.symm,\n  tfae_finish,\nend\n\nend\n\nlemma of_surjective [comm_semiring R] [local_ring R] [comm_semiring S] [nontrivial S]\n  (f : R \u2192+* S) [is_local_ring_hom f] (hf : function.surjective f) :\n  local_ring S :=\nof_is_unit_or_is_unit_of_is_unit_add\nbegin\n  intros a b hab,\n  obtain \u27e8a, rfl\u27e9 := hf a,\n  obtain \u27e8b, rfl\u27e9 := hf b,\n  rw \u2190map_add at hab,\n  exact (is_unit_or_is_unit_of_is_unit_add $ is_local_ring_hom.map_nonunit _ hab).imp\n    f.is_unit_map f.is_unit_map\nend\n\n/-- If `f : R \u2192+* S` is a surjective local ring hom, then the induced units map is surjective. -/\nlemma surjective_units_map_of_local_ring_hom [comm_ring R] [comm_ring S]\n  (f : R \u2192+* S) (hf : function.surjective f) (h : is_local_ring_hom f) :\n  function.surjective (units.map $ f.to_monoid_hom) :=\nbegin\n  intro a,\n  obtain \u27e8b,hb\u27e9 := hf (a : S),\n  use (is_unit_of_map_unit f _ (by { rw hb, exact units.is_unit _})).unit, ext, exact hb,\nend\n\nsection\nvariables (R) [comm_ring R] [local_ring R] [comm_ring S] [local_ring S] [comm_ring T] [local_ring T]\n\n/-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/\n@[derive [ring, comm_ring, inhabited]]\ndef residue_field := R \u29f8 maximal_ideal R\n\nnoncomputable instance residue_field.field : field (residue_field R) :=\nideal.quotient.field (maximal_ideal R)\n\n/-- The quotient map from a local ring to its residue field. -/\ndef residue : R \u2192+* (residue_field R) :=\nideal.quotient.mk _\n\ninstance residue_field.algebra : algebra R (residue_field R) :=\nideal.quotient.algebra _\n\nlemma residue_field.algebra_map_eq : algebra_map R (residue_field R) = residue R := rfl\n\ninstance : is_local_ring_hom (local_ring.residue R) :=\n\u27e8\u03bb a ha, not_not.mp (ideal.quotient.eq_zero_iff_mem.not.mp (is_unit_iff_ne_zero.mp ha))\u27e9\n\nvariables {R}\n\nnamespace residue_field\n\n/-- A local ring homomorphism into a field can be descended onto the residue field. -/\ndef lift {R S : Type*} [comm_ring R] [local_ring R] [field S]\n  (f : R \u2192+* S) [is_local_ring_hom f] : local_ring.residue_field R \u2192+* S :=\nideal.quotient.lift _ f (\u03bb a ha,\n  classical.by_contradiction (\u03bb h, ha (is_unit_of_map_unit f a (is_unit_iff_ne_zero.mpr h))))\n\nlemma lift_comp_residue {R S : Type*} [comm_ring R] [local_ring R] [field S] (f : R \u2192+* S)\n  [is_local_ring_hom f] : (lift f).comp (residue R) = f :=\nring_hom.ext (\u03bb _, rfl)\n\n@[simp]\nlemma lift_residue_apply {R S : Type*} [comm_ring R] [local_ring R] [field S] (f : R \u2192+* S)\n  [is_local_ring_hom f] (x) : lift f (residue R x) = f x :=\nrfl\n\n/-- The map on residue fields induced by a local homomorphism between local rings -/\ndef map (f : R \u2192+* S) [is_local_ring_hom f] : residue_field R \u2192+* residue_field S :=\nideal.quotient.lift (maximal_ideal R) ((ideal.quotient.mk _).comp f) $\n\u03bb a ha,\nbegin\n  erw ideal.quotient.eq_zero_iff_mem,\n  exact map_nonunit f a ha\nend\n\n/-- Applying `residue_field.map` to the identity ring homomorphism gives the identity\nring homomorphism. -/\n@[simp] lemma map_id :\n  local_ring.residue_field.map (ring_hom.id R) = ring_hom.id (local_ring.residue_field R) :=\nideal.quotient.ring_hom_ext $ ring_hom.ext $ \u03bbx, rfl\n\n/-- The composite of two `residue_field.map`s is the `residue_field.map` of the composite. -/\nlemma map_comp (f : T \u2192+* R) (g : R \u2192+* S) [is_local_ring_hom f] [is_local_ring_hom g] :\n  local_ring.residue_field.map (g.comp f) =\n  (local_ring.residue_field.map g).comp (local_ring.residue_field.map f) :=\nideal.quotient.ring_hom_ext $ ring_hom.ext $ \u03bbx, rfl\n\nlemma map_comp_residue (f : R \u2192+* S) [is_local_ring_hom f] :\n  (residue_field.map f).comp (residue R) = (residue S).comp f := rfl\n\nlemma map_residue (f : R \u2192+* S) [is_local_ring_hom f] (r : R) :\n  residue_field.map f (residue R r) = residue S (f r) := rfl\n\nlemma map_id_apply (x : residue_field R) : map (ring_hom.id R) x = x :=\nfun_like.congr_fun map_id x\n\n@[simp] lemma map_map (f : R \u2192+* S) (g : S \u2192+* T) (x : residue_field R)\n  [is_local_ring_hom f] [is_local_ring_hom g] :\n  map g (map f x) = map (g.comp f) x :=\nfun_like.congr_fun (map_comp f g).symm x\n\n/-- A ring isomorphism defines an isomorphism of residue fields. -/\n@[simps apply]\ndef map_equiv (f : R \u2243+* S) : local_ring.residue_field R \u2243+* local_ring.residue_field S :=\n{ to_fun := map (f : R \u2192+* S),\n  inv_fun := map (f.symm : S \u2192+* R),\n  left_inv := \u03bb x, by simp only [map_map, ring_equiv.symm_comp, map_id, ring_hom.id_apply],\n  right_inv := \u03bb x, by simp only [map_map, ring_equiv.comp_symm, map_id, ring_hom.id_apply],\n  map_mul' := ring_hom.map_mul _,\n  map_add' := ring_hom.map_add _ }\n\n@[simp] lemma map_equiv.symm (f : R \u2243+* S) : (map_equiv f).symm = map_equiv f.symm := rfl\n\n@[simp] lemma map_equiv_trans (e\u2081 : R \u2243+* S) (e\u2082 : S \u2243+* T) :\n  map_equiv (e\u2081.trans e\u2082) = (map_equiv e\u2081).trans (map_equiv e\u2082) :=\nring_equiv.to_ring_hom_injective $ map_comp (e\u2081 : R \u2192+* S) (e\u2082 : S \u2192+* T)\n\n@[simp] lemma map_equiv_refl : map_equiv (ring_equiv.refl R) = ring_equiv.refl _ :=\nring_equiv.to_ring_hom_injective map_id\n\n/-- The group homomorphism from `ring_aut R` to `ring_aut k` where `k`\nis the residue field of `R`. -/\n@[simps] def map_aut : ring_aut R \u2192* ring_aut (local_ring.residue_field R) :=\n{ to_fun := map_equiv,\n  map_mul' := \u03bb e\u2081 e\u2082, map_equiv_trans e\u2082 e\u2081,\n  map_one' := map_equiv_refl }\n\nsection mul_semiring_action\nvariables (G : Type*) [group G] [mul_semiring_action G R]\n\n/-- If `G` acts on `R` as a `mul_semiring_action`, then it also acts on `residue_field R`. -/\ninstance : mul_semiring_action G (local_ring.residue_field R) :=\nmul_semiring_action.comp_hom _ $ map_aut.comp (mul_semiring_action.to_ring_aut G R)\n\n@[simp] lemma residue_smul (g : G) (r : R) : residue R (g \u2022 r) = g \u2022 residue R r := rfl\n\nend mul_semiring_action\n\nend residue_field\n\nlemma ker_eq_maximal_ideal [field K] (\u03c6 : R \u2192+* K) (h\u03c6 : function.surjective \u03c6) :\n  \u03c6.ker = maximal_ideal R :=\nlocal_ring.eq_maximal_ideal $ (ring_hom.ker_is_maximal_of_surjective \u03c6) h\u03c6\n\nlemma is_local_ring_hom_residue :\n  is_local_ring_hom (local_ring.residue R) :=\nbegin\n  constructor,\n  intros a ha,\n  by_contra,\n  erw ideal.quotient.eq_zero_iff_mem.mpr ((local_ring.mem_maximal_ideal _).mpr h) at ha,\n  exact ha.ne_zero rfl,\nend\n\nend\n\nend local_ring\n\nnamespace field\nvariables (K) [field K]\n\nopen_locale classical\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : local_ring K :=\nlocal_ring.of_is_unit_or_is_unit_one_sub_self $ \u03bb a,\n  if h : a = 0\n  then or.inr (by rw [h, sub_zero]; exact is_unit_one)\n  else or.inl $ is_unit.mk0 a h\n\nend field\n\nlemma local_ring.maximal_ideal_eq_bot {R : Type*} [field R] :\n  local_ring.maximal_ideal R = \u22a5 :=\nlocal_ring.is_field_iff_maximal_ideal_eq.mp (field.to_is_field R)\n\nnamespace ring_equiv\n\n@[reducible] protected \n\nend ring_equiv\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/ring_theory/ideal/local_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7001445135300409}}
{"text": "/-\nCopyright (c) 2019 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-/\nimport topology.fiber_bundle\nimport geometry.manifold.smooth_manifold_with_corners\n\n/-!\n# Basic smooth bundles\n\nIn general, a smooth bundle is a bundle over a smooth manifold, whose fiber is a manifold, and\nfor which the coordinate changes are smooth. In this definition, there are charts involved at\nseveral places: in the manifold structure of the base, in the manifold structure of the fibers, and\nin the local trivializations. This makes it a complicated object in general. There is however a\nspecific situation where things are much simpler: when the fiber is a vector space (no need for\ncharts for the fibers), and when the local trivializations of the bundle and the charts of the base\ncoincide. Then everything is expressed in terms of the charts of the base, making for a much\nsimpler overall structure, which is easier to manipulate formally.\n\nMost vector bundles that naturally occur in differential geometry are of this form:\nthe tangent bundle, the cotangent bundle, differential forms (used to define de Rham cohomology)\nand the bundle of Riemannian metrics. Therefore, it is worth defining a specific constructor for\nthis kind of bundle, that we call basic smooth bundles.\n\nA basic smooth bundle is thus a smooth bundle over a smooth manifold whose fiber is a vector space,\nand which is trivial in the coordinate charts of the base. (We recall that in our notion of manifold\nthere is a distinguished atlas, which does not need to be maximal: we require the triviality above\nthis specific atlas). It can be constructed from a basic smooth bundled core, defined below,\nspecifying the changes in the fiber when one goes from one coordinate chart to another one. We do\nnot require that this changes in fiber are linear, but only diffeomorphisms.\n\n## Main definitions\n\n* `basic_smooth_bundle_core I M F`: assuming that `M` is a smooth manifold over the model with\n  corners `I` on `(\ud835\udd5c, E, H)`, and `F` is a normed vector space over `\ud835\udd5c`, this structure registers,\n  for each pair of charts of `M`, a smooth change of coordinates on `F`. This is the core structure\n  from which one will build a smooth bundle with fiber `F` over `M`.\n\nLet `Z` be a basic smooth bundle core over `M` with fiber `F`. We define\n`Z.to_topological_fiber_bundle_core`, the (topological) fiber bundle core associated to `Z`. From\nit, we get a space `Z.to_topological_fiber_bundle_core.total_space` (which as a Type is just `\u03a3 (x :\nM), F`), with the fiber bundle topology. It inherits a manifold structure (where the charts are in\nbijection with the charts of the basis). We show that this manifold is smooth.\n\nThen we use this machinery to construct the tangent bundle of a smooth manifold.\n\n* `tangent_bundle_core I M`: the basic smooth bundle core associated to a smooth manifold `M` over a\n  model with corners `I`.\n* `tangent_bundle I M`     : the total space of `tangent_bundle_core I M`. It is itself a\n  smooth manifold over the model with corners `I.tangent`, the product of `I` and the trivial model\n  with corners on `E`.\n* `tangent_space I x`      : the tangent space to `M` at `x`\n* `tangent_bundle.proj I M`: the projection from the tangent bundle to the base manifold\n\n## Implementation notes\n\nIn the definition of a basic smooth bundle core, we do not require that the coordinate changes of\nthe fibers are linear map, only that they are diffeomorphisms. Therefore, the fibers of the\nresulting fiber bundle do not inherit a vector space structure (as an algebraic object) in general.\nAs the fiber, as a type, is just `F`, one can still always register the vector space structure, but\nit does not make sense to do so (i.e., it will not lead to any useful theorem) unless this structure\nis canonical, i.e., the coordinate changes are linear maps.\n\nFor instance, we register the vector space structure on the fibers of the tangent bundle. However,\nwe do not register the normed space structure coming from that of `F` (as it is not canonical, and\nwe also want to keep the possibility to add a Riemannian structure on the manifold later on without\nhaving two competing normed space instances on the tangent spaces).\n\nWe require `F` to be a normed space, and not just a topological vector space, as we want to talk\nabout smooth functions on `F`. The notion of derivative requires a norm to be defined.\n\n## TODO\nconstruct the cotangent bundle, and the bundles of differential forms. They should follow\nfunctorially from the description of the tangent bundle as a basic smooth bundle.\n\n## Tags\nSmooth fiber bundle, vector bundle, tangent space, tangent bundle\n-/\n\nnoncomputable theory\n\nuniverse u\n\nopen topological_space set\nopen_locale manifold topological_space\n\n/-- Core structure used to create a smooth bundle above `M` (a manifold over the model with\ncorner `I`) with fiber the normed vector space `F` over `\ud835\udd5c`, which is trivial in the chart domains\nof `M`. This structure registers the changes in the fibers when one changes coordinate charts in the\nbase. We do not require the change of coordinates of the fibers to be linear, only smooth.\nTherefore, the fibers of the resulting bundle will not inherit a canonical vector space structure\nin general. -/\nstructure basic_smooth_bundle_core {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n(F : Type*) [normed_group F] [normed_space \ud835\udd5c F] :=\n(coord_change      : atlas H M \u2192 atlas H M \u2192 H \u2192 F \u2192 F)\n(coord_change_self :\n  \u2200 i : atlas H M, \u2200 x \u2208 i.1.target, \u2200 v, coord_change i i x v = v)\n(coord_change_comp : \u2200 i j k : atlas H M,\n  \u2200 x \u2208 ((i.1.symm.trans j.1).trans (j.1.symm.trans k.1)).source, \u2200 v,\n  (coord_change j k ((i.1.symm.trans j.1) x)) (coord_change i j x v) = coord_change i k x v)\n(coord_change_smooth : \u2200 i j : atlas H M,\n  times_cont_diff_on \ud835\udd5c \u221e (\u03bbp : E \u00d7 F, coord_change i j (I.symm p.1) p.2)\n  ((I '' (i.1.symm.trans j.1).source).prod (univ : set F)))\n\n/-- The trivial basic smooth bundle core, in which all the changes of coordinates are the\nidentity. -/\ndef trivial_basic_smooth_bundle_core {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n(F : Type*) [normed_group F] [normed_space \ud835\udd5c F] : basic_smooth_bundle_core I M F :=\n{ coord_change := \u03bb i j x v, v,\n  coord_change_self := \u03bb i x hx v, rfl,\n  coord_change_comp := \u03bb i j k x hx v, rfl,\n  coord_change_smooth := \u03bb i j, times_cont_diff_snd.times_cont_diff_on }\n\nnamespace basic_smooth_bundle_core\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] {I : model_with_corners \ud835\udd5c E H}\n{M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n{F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\n(Z : basic_smooth_bundle_core I M F)\n\ninstance : inhabited (basic_smooth_bundle_core I M F) :=\n\u27e8trivial_basic_smooth_bundle_core I M F\u27e9\n\n/-- Fiber bundle core associated to a basic smooth bundle core -/\ndef to_topological_fiber_bundle_core : topological_fiber_bundle_core (atlas H M) M F :=\n{ base_set := \u03bbi, i.1.source,\n  is_open_base_set := \u03bbi, i.1.open_source,\n  index_at := \u03bbx, \u27e8chart_at H x, chart_mem_atlas H x\u27e9,\n  mem_base_set_at := \u03bbx, mem_chart_source H x,\n  coord_change := \u03bbi j x v, Z.coord_change i j (i.1 x) v,\n  coord_change_self := \u03bbi x hx v, Z.coord_change_self i (i.1 x) (i.1.map_source hx) v,\n  coord_change_comp := \u03bbi j k x \u27e8\u27e8hx1, hx2\u27e9, hx3\u27e9 v, begin\n    have := Z.coord_change_comp i j k (i.1 x) _ v,\n    convert this using 2,\n    { simp only [hx1] with mfld_simps },\n    { simp only [hx1, hx2, hx3] with mfld_simps }\n  end,\n  coord_change_continuous := \u03bbi j, begin\n    have A : continuous_on (\u03bbp : E \u00d7 F, Z.coord_change i j (I.symm p.1) p.2)\n      ((I '' (i.1.symm.trans j.1).source).prod (univ : set F)) :=\n      (Z.coord_change_smooth i j).continuous_on,\n    have B : continuous_on (\u03bbx : M, I (i.1 x)) i.1.source :=\n      I.continuous.comp_continuous_on i.1.continuous_on,\n    have C : continuous_on (\u03bbp : M \u00d7 F, (\u27e8I (i.1 p.1), p.2\u27e9 : E \u00d7 F))\n             (i.1.source.prod univ),\n    { apply continuous_on.prod _ continuous_snd.continuous_on,\n      exact B.comp continuous_fst.continuous_on (prod_subset_preimage_fst _ _) },\n    have C' : continuous_on (\u03bbp : M \u00d7 F, (\u27e8I (i.1 p.1), p.2\u27e9 : E \u00d7 F))\n              ((i.1.source \u2229 j.1.source).prod univ) :=\n      continuous_on.mono C (prod_mono (inter_subset_left _ _) (subset.refl _)),\n    have D : (i.1.source \u2229 j.1.source).prod univ \u2286 (\u03bb (p : M \u00d7 F),\n      (I (i.1 p.1), p.2)) \u207b\u00b9' ((I '' (i.1.symm.trans j.1).source).prod univ),\n    { rintros \u27e8x, v\u27e9 hx,\n      simp only with mfld_simps at hx,\n      simp only [hx] with mfld_simps },\n    convert continuous_on.comp A C' D,\n    ext p,\n    simp only with mfld_simps\n  end }\n\n@[simp, mfld_simps] lemma base_set (i : atlas H M) :\n  (Z.to_topological_fiber_bundle_core.local_triv i).base_set = i.1.source := rfl\n\n/-- Local chart for the total space of a basic smooth bundle -/\ndef chart {e : local_homeomorph M H} (he : e \u2208 atlas H M) :\n  local_homeomorph (Z.to_topological_fiber_bundle_core.total_space) (model_prod H F) :=\n(Z.to_topological_fiber_bundle_core.local_triv \u27e8e, he\u27e9).to_local_homeomorph.trans\n  (local_homeomorph.prod e (local_homeomorph.refl F))\n\n@[simp, mfld_simps] lemma chart_source (e : local_homeomorph M H) (he : e \u2208 atlas H M) :\n  (Z.chart he).source = Z.to_topological_fiber_bundle_core.proj \u207b\u00b9' e.source :=\nby { simp only [chart, mem_prod], mfld_set_tac }\n\n@[simp, mfld_simps] lemma chart_target (e : local_homeomorph M H) (he : e \u2208 atlas H M) :\n  (Z.chart he).target = e.target.prod univ :=\nby { simp only [chart], mfld_set_tac }\n\n/-- The total space of a basic smooth bundle is endowed with a charted space structure, where the\ncharts are in bijection with the charts of the basis. -/\ninstance to_charted_space :\n  charted_space (model_prod H F) Z.to_topological_fiber_bundle_core.total_space :=\n{ atlas := \u22c3(e : local_homeomorph M H) (he : e \u2208 atlas H M), {Z.chart he},\n  chart_at := \u03bbp, Z.chart (chart_mem_atlas H p.1),\n  mem_chart_source := \u03bbp, by simp [mem_chart_source],\n  chart_mem_atlas := \u03bbp, begin\n    simp only [mem_Union, mem_singleton_iff, chart_mem_atlas],\n    exact \u27e8chart_at H p.1, chart_mem_atlas H p.1, rfl\u27e9\n  end }\n\nlemma mem_atlas_iff\n  (f : local_homeomorph Z.to_topological_fiber_bundle_core.total_space (model_prod H F)) :\n  f \u2208 atlas (model_prod H F) Z.to_topological_fiber_bundle_core.total_space \u2194\n  \u2203(e : local_homeomorph M H) (he : e \u2208 atlas H M), f = Z.chart he :=\nby simp only [atlas, mem_Union, mem_singleton_iff]\n\n@[simp, mfld_simps] lemma mem_chart_source_iff\n  (p q : Z.to_topological_fiber_bundle_core.total_space) :\n  p \u2208 (chart_at (model_prod H F) q).source \u2194 p.1 \u2208 (chart_at H q.1).source :=\nby simp only [chart_at] with mfld_simps\n\n@[simp, mfld_simps] lemma mem_chart_target_iff\n  (p : H \u00d7 F) (q : Z.to_topological_fiber_bundle_core.total_space) :\n  p \u2208 (chart_at (model_prod H F) q).target \u2194 p.1 \u2208 (chart_at H q.1).target :=\nby simp only [chart_at] with mfld_simps\n\n@[simp, mfld_simps] lemma coe_chart_at_fst (p q : Z.to_topological_fiber_bundle_core.total_space) :\n  ((chart_at (model_prod H F) q) p).1 = chart_at H q.1 p.1 := rfl\n\n@[simp, mfld_simps] lemma coe_chart_at_symm_fst\n  (p : H \u00d7 F) (q : Z.to_topological_fiber_bundle_core.total_space) :\n  ((chart_at (model_prod H F) q).symm p).1 = ((chart_at H q.1).symm : H \u2192 M) p.1 := rfl\n\n/-- Smooth manifold structure on the total space of a basic smooth bundle -/\ninstance to_smooth_manifold :\n  smooth_manifold_with_corners (I.prod (\ud835\udcd8(\ud835\udd5c, F))) Z.to_topological_fiber_bundle_core.total_space :=\nbegin\n  /- We have to check that the charts belong to the smooth groupoid, i.e., they are smooth on their\n  source, and their inverses are smooth on the target. Since both objects are of the same kind, it\n  suffices to prove the first statement in A below, and then glue back the pieces at the end. -/\n  let J := model_with_corners.to_local_equiv (I.prod (\ud835\udcd8(\ud835\udd5c, F))),\n  have A : \u2200 (e e' : local_homeomorph M H) (he : e \u2208 atlas H M) (he' : e' \u2208 atlas H M),\n    times_cont_diff_on \ud835\udd5c \u221e\n    (J \u2218 ((Z.chart he).symm.trans (Z.chart he')) \u2218 J.symm)\n    (J.symm \u207b\u00b9' ((Z.chart he).symm.trans (Z.chart he')).source \u2229 range J),\n  { assume e e' he he',\n    have : J.symm \u207b\u00b9' ((chart Z he).symm.trans (chart Z he')).source \u2229 range J =\n      (I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I).prod univ,\n      by { simp only [J, chart, model_with_corners.prod], mfld_set_tac },\n    rw this,\n    -- check separately that the two components of the coordinate change are smooth\n    apply times_cont_diff_on.prod,\n    show times_cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F), (I \u2218 e' \u2218 e.symm \u2218 I.symm) p.1)\n         ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I).prod (univ : set F)),\n    { -- the coordinate change on the base is just a coordinate change for `M`, smooth since\n      -- `M` is smooth\n      have A : times_cont_diff_on \ud835\udd5c \u221e (I \u2218 (e.symm.trans e') \u2218 I.symm)\n        (I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I) :=\n      (has_groupoid.compatible (times_cont_diff_groupoid \u221e I) he he').1,\n      have B : times_cont_diff_on \ud835\udd5c \u221e (\u03bbp : E \u00d7 F, p.1)\n        ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I).prod univ) :=\n      times_cont_diff_fst.times_cont_diff_on,\n      exact times_cont_diff_on.comp A B (prod_subset_preimage_fst _ _) },\n    show times_cont_diff_on \ud835\udd5c \u221e (\u03bb (p : E \u00d7 F),\n      Z.coord_change \u27e8chart_at H (e.symm (I.symm p.1)), _\u27e9 \u27e8e', he'\u27e9\n         ((chart_at H (e.symm (I.symm p.1)) : M \u2192 H) (e.symm (I.symm p.1)))\n      (Z.coord_change \u27e8e, he\u27e9 \u27e8chart_at H (e.symm (I.symm p.1)), _\u27e9\n        (e (e.symm (I.symm p.1))) p.2))\n      ((I.symm \u207b\u00b9' (e.symm.trans e').source \u2229 range I).prod (univ : set F)),\n    { /- The coordinate change in the fiber is more complicated as its definition involves the\n      reference chart chosen at each point. However, it appears with its inverse, so using the\n      cocycle property one can get rid of it, and then conclude using the smoothness of the\n      cocycle as given in the definition of basic smooth bundles. -/\n      have := Z.coord_change_smooth \u27e8e, he\u27e9 \u27e8e', he'\u27e9,\n      rw I.image_eq at this,\n      apply times_cont_diff_on.congr this,\n      rintros \u27e8x, v\u27e9 hx,\n      simp only with mfld_simps at hx,\n      let f := chart_at H (e.symm (I.symm x)),\n      have A : I.symm x \u2208 ((e.symm.trans f).trans (f.symm.trans e')).source,\n        by simp only [hx.1.1, hx.1.2] with mfld_simps,\n      rw e.right_inv hx.1.1,\n      have := Z.coord_change_comp \u27e8e, he\u27e9 \u27e8f, chart_mem_atlas _ _\u27e9 \u27e8e', he'\u27e9 (I.symm x) A v,\n      simpa only [] using this } },\n  refine @smooth_manifold_with_corners.mk _ _ _ _ _ _ _ _ _ _ _ \u27e8_\u27e9,\n  assume e\u2080 e\u2080' he\u2080 he\u2080',\n  rcases (Z.mem_atlas_iff _).1 he\u2080 with \u27e8e, he, rfl\u27e9,\n  rcases (Z.mem_atlas_iff _).1 he\u2080' with \u27e8e', he', rfl\u27e9,\n  rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],\n  exact \u27e8A e e' he he', A e' e he' he\u27e9\nend\n\nend basic_smooth_bundle_core\n\nsection tangent_bundle\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\n{E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\n{H : Type*} [topological_space H] (I : model_with_corners \ud835\udd5c E H)\n(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]\n\n/-- Basic smooth bundle core version of the tangent bundle of a smooth manifold `M` modelled over a\nmodel with corners `I` on `(E, H)`. The fibers are equal to `E`, and the coordinate change in the\nfiber corresponds to the derivative of the coordinate change in `M`. -/\ndef tangent_bundle_core : basic_smooth_bundle_core I M E :=\n{ coord_change := \u03bbi j x v, (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n                            (range I) (I x) : E \u2192 E) v,\n  coord_change_smooth := \u03bbi j, begin\n    /- To check that the coordinate change of the bundle is smooth, one should just use the\n    smoothness of the charts, and thus the smoothness of their derivatives. -/\n    rw I.image_eq,\n    have A : times_cont_diff_on \ud835\udd5c \u221e\n      (I \u2218 (i.1.symm.trans j.1) \u2218 I.symm)\n      (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n      (has_groupoid.compatible (times_cont_diff_groupoid \u221e I) i.2 j.2).1,\n    have B : unique_diff_on \ud835\udd5c (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n      I.unique_diff_preimage_source,\n    have C : times_cont_diff_on \ud835\udd5c \u221e\n      (\u03bb (p : E \u00d7 E), (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) p.1 : E \u2192 E) p.2)\n      ((I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I).prod univ) :=\n      times_cont_diff_on_fderiv_within_apply A B le_top,\n    have D : \u2200 x \u2208 (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I),\n      fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (range I) x =\n      fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n            (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) x,\n    { assume x hx,\n      have N : I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2208 nhds x :=\n        I.continuous_symm.continuous_at.preimage_mem_nhds\n          (is_open.mem_nhds (local_homeomorph.open_source _) hx.1),\n      symmetry,\n      rw inter_comm,\n      exact fderiv_within_inter N (I.unique_diff _ hx.2) },\n    apply times_cont_diff_on.congr C,\n    rintros \u27e8x, v\u27e9 hx,\n    have E : x \u2208 I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I,\n      by simpa only [prod_mk_mem_set_prod_eq, and_true, mem_univ] using hx,\n    have : I (I.symm x) = x, by simp [E.2],\n    dsimp [-subtype.val_eq_coe],\n    rw [this, D x E],\n    refl\n  end,\n  coord_change_self := \u03bbi x hx v, begin\n    /- Locally, a self-change of coordinate is just the identity, thus its derivative is the\n    identity. One just needs to write this carefully, paying attention to the sets where the\n    functions are defined. -/\n    have A : I.symm \u207b\u00b9' (i.1.symm.trans i.1).source \u2229 range I \u2208\n      \ud835\udcdd[range I] (I x),\n    { rw inter_comm,\n      apply inter_mem_nhds_within,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simp only [hx, i.1.map_target] with mfld_simps },\n    have B : \u2200\u1da0 y in \ud835\udcdd[range I] (I x),\n      (I \u2218 i.1 \u2218 i.1.symm \u2218 I.symm) y = (id : E \u2192 E) y,\n    { filter_upwards [A],\n      assume y hy,\n      rw \u2190 I.image_eq at hy,\n      rcases hy with \u27e8z, hz\u27e9,\n      simp only with mfld_simps at hz,\n      simp only [hz.2.symm, hz.1] with mfld_simps },\n    have C : fderiv_within \ud835\udd5c (I \u2218 i.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x) =\n             fderiv_within \ud835\udd5c (id : E \u2192 E) (range I) (I x) :=\n      filter.eventually_eq.fderiv_within_eq I.unique_diff_at_image B\n      (by simp only [hx] with mfld_simps),\n    rw fderiv_within_id I.unique_diff_at_image at C,\n    rw C,\n    refl\n  end,\n  coord_change_comp := \u03bbi j u x hx, begin\n    /- The cocycle property is just the fact that the derivative of a composition is the product of\n    the derivatives. One needs however to check that all the functions one considers are smooth, and\n    to pay attention to the domains where these functions are defined, making this proof a little\n    bit cumbersome although there is nothing complicated here. -/\n    have M : I x \u2208\n      (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I) :=\n    \u27e8by simpa only [mem_preimage, model_with_corners.left_inv] using hx, mem_range_self _\u27e9,\n    have U : unique_diff_within_at \ud835\udd5c\n      (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I) (I x) :=\n      I.unique_diff_preimage_source _ M,\n    have A : fderiv_within \ud835\udd5c ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm))\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)\n      = (fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I)\n             ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x))).comp\n        (fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)),\n    { apply fderiv_within.comp _ _ _ _ U,\n      show differentiable_within_at \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n        (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n        (I x),\n      { have A : times_cont_diff_on \ud835\udd5c \u221e\n          (I \u2218 (i.1.symm.trans j.1) \u2218 I.symm)\n          (I.symm \u207b\u00b9' (i.1.symm.trans j.1).source \u2229 range I) :=\n        (has_groupoid.compatible (times_cont_diff_groupoid \u221e I) i.2 j.2).1,\n        have B : differentiable_on \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n          (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I),\n        { apply (A.differentiable_on le_top).mono,\n          have : ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2286\n            (i.1.symm.trans j.1).source := inter_subset_left _ _,\n          exact inter_subset_inter (preimage_mono this) (subset.refl (range I)) },\n        apply B,\n        simpa only [] with mfld_simps using hx },\n      show differentiable_within_at \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n        (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I)\n        ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)),\n      { have A : times_cont_diff_on \ud835\udd5c \u221e\n          (I \u2218 (j.1.symm.trans u.1) \u2218 I.symm)\n          (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I) :=\n        (has_groupoid.compatible (times_cont_diff_groupoid \u221e I) j.2 u.2).1,\n        apply A.differentiable_on le_top,\n        rw [local_homeomorph.trans_source] at hx,\n        simp only with mfld_simps,\n        exact hx.2 },\n      show (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n        \u2286 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) \u207b\u00b9' (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I),\n      { assume y hy,\n        simp only with mfld_simps at hy,\n        rw [local_homeomorph.left_inv] at hy,\n        { simp only [hy] with mfld_simps },\n        { exact hy.1.1.2 } } },\n    have B : fderiv_within \ud835\udd5c ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n                          \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm))\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x)\n             = fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x),\n    { have E :\n        \u2200 y \u2208 (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I),\n          ((I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) \u2218 (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)) y =\n            (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm) y,\n      { assume y hy,\n        simp only [function.comp_app, model_with_corners.left_inv],\n        rw [j.1.left_inv],\n        exact hy.1.1.2 },\n      exact fderiv_within_congr U E (E _ M) },\n    have C : fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n             (I x) =\n             fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 i.1.symm \u2218 I.symm)\n             (range I) (I x),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simpa only [model_with_corners.left_inv] using hx },\n    have D : fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm)\n      (I.symm \u207b\u00b9' (j.1.symm.trans u.1).source \u2229 range I) ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)) =\n      fderiv_within \ud835\udd5c (I \u2218 u.1 \u2218 j.1.symm \u2218 I.symm) (range I) ((I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (I x)),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      rw [local_homeomorph.trans_source] at hx,\n      simp only with mfld_simps,\n      exact hx.2 },\n    have E : fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm)\n               (I.symm \u207b\u00b9' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source \u2229 range I)\n               (I x) =\n             fderiv_within \ud835\udd5c (I \u2218 j.1 \u2218 i.1.symm \u2218 I.symm) (range I) (I x),\n    { rw inter_comm,\n      apply fderiv_within_inter _ I.unique_diff_at_image,\n      apply I.continuous_symm.continuous_at.preimage_mem_nhds\n        (is_open.mem_nhds (local_homeomorph.open_source _) _),\n      simpa only [model_with_corners.left_inv] using hx },\n    rw [B, C, D, E] at A,\n    simp only [A, continuous_linear_map.coe_comp'] with mfld_simps\n  end }\n\nvariable {M}\ninclude I\n\n/-- The tangent space at a point of the manifold `M`. It is just `E`. We could use instead\n`(tangent_bundle_core I M).to_topological_fiber_bundle_core.fiber x`, but we use `E` to help the\nkernel.\n-/\n@[nolint unused_arguments]\ndef tangent_space (x : M) : Type* := E\n\nomit I\nvariable (M)\n\n/-- The tangent bundle to a smooth manifold, as a plain type. We could use\n`(tangent_bundle_core I M).to_topological_fiber_bundle_core.total_space`, but instead we use the\n(definitionally equal) `\u03a3 (x : M), tangent_space I x`, to make sure that rcasing an element of the\ntangent bundle gives a second component in the tangent space. -/\n@[nolint has_inhabited_instance, reducible] -- is empty if the base manifold is empty\ndef tangent_bundle := \u03a3 (x : M), tangent_space I x\n\n/-- The projection from the tangent bundle of a smooth manifold to the manifold. As the tangent\nbundle is represented internally as a sigma type, the notation `p.1` also works for the projection\nof the point `p`. -/\ndef tangent_bundle.proj : tangent_bundle I M \u2192 M :=\n\u03bb p, p.1\n\nvariable {M}\n\n@[simp, mfld_simps] lemma tangent_bundle.proj_apply (x : M) (v : tangent_space I x) :\n  tangent_bundle.proj I M \u27e8x, v\u27e9 = x :=\nrfl\n\nsection tangent_bundle_instances\n\n/- In general, the definition of tangent_bundle and tangent_space are not reducible, so that type\nclass inference does not pick wrong instances. In this section, we record the right instances for\nthem, noting in particular that the tangent bundle is a smooth manifold. -/\nvariable (M)\n\ninstance : topological_space (tangent_bundle I M) :=\n(tangent_bundle_core I M).to_topological_fiber_bundle_core.to_topological_space (atlas H M)\n\ninstance : charted_space (model_prod H E) (tangent_bundle I M) :=\n(tangent_bundle_core I M).to_charted_space\n\ninstance : smooth_manifold_with_corners I.tangent (tangent_bundle I M) :=\n(tangent_bundle_core I M).to_smooth_manifold\n\nlocal attribute [reducible] tangent_space\nvariables {M} (x : M)\n\ninstance : has_continuous_smul \ud835\udd5c (tangent_space I x) := by apply_instance\ninstance : topological_space (tangent_space I x) := by apply_instance\ninstance : add_comm_group (tangent_space I x) := by apply_instance\ninstance : topological_add_group (tangent_space I x) := by apply_instance\ninstance : module \ud835\udd5c (tangent_space I x) := by apply_instance\ninstance : inhabited (tangent_space I x) := \u27e80\u27e9\n\nend tangent_bundle_instances\n\nvariable (M)\n\n/-- The tangent bundle projection on the basis is a continuous map. -/\nlemma tangent_bundle_proj_continuous : continuous (tangent_bundle.proj I M) :=\ntopological_fiber_bundle_core.continuous_proj _\n\n/-- The tangent bundle projection on the basis is an open map. -/\nlemma tangent_bundle_proj_open : is_open_map (tangent_bundle.proj I M) :=\ntopological_fiber_bundle_core.is_open_map_proj _\n\n/-- In the tangent bundle to the model space, the charts are just the canonical identification\nbetween a product type and a sigma type, a.k.a. `equiv.sigma_equiv_prod`. -/\n@[simp, mfld_simps] lemma tangent_bundle_model_space_chart_at (p : tangent_bundle I H) :\n  (chart_at (model_prod H E) p).to_local_equiv = (equiv.sigma_equiv_prod H E).to_local_equiv :=\nbegin\n  have A : \u2200 x_fst, fderiv_within \ud835\udd5c (I \u2218 I.symm) (range I) (I x_fst) = continuous_linear_map.id \ud835\udd5c E,\n  { assume x_fst,\n    have : fderiv_within \ud835\udd5c (I \u2218 I.symm) (range I) (I x_fst)\n         = fderiv_within \ud835\udd5c id (range I) (I x_fst),\n    { refine fderiv_within_congr I.unique_diff_at_image (\u03bby hy, _) (by simp),\n      exact model_with_corners.right_inv _ hy },\n    rwa fderiv_within_id I.unique_diff_at_image at this },\n  ext x : 1,\n  show (chart_at (model_prod H E) p : tangent_bundle I H \u2192 model_prod H E) x =\n    (equiv.sigma_equiv_prod H E) x,\n  { cases x,\n    simp only [chart_at, basic_smooth_bundle_core.chart, tangent_bundle_core,\n      basic_smooth_bundle_core.to_topological_fiber_bundle_core, A, prod.mk.inj_iff,\n      continuous_linear_map.coe_id'] with mfld_simps, },\n  show \u2200 x, ((chart_at (model_prod H E) p).to_local_equiv).symm x =\n    (equiv.sigma_equiv_prod H E).symm x,\n  { rintros \u27e8x_fst, x_snd\u27e9,\n    simp only [chart_at, basic_smooth_bundle_core.chart, tangent_bundle_core,\n      continuous_linear_map.coe_id', basic_smooth_bundle_core.to_topological_fiber_bundle_core, A]\n      with mfld_simps },\n  show ((chart_at (model_prod H E) p).to_local_equiv).source = univ,\n    by simp only [chart_at] with mfld_simps,\nend\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at (p : tangent_bundle I H) :\n  \u21d1(chart_at (model_prod H E) p) = equiv.sigma_equiv_prod H E :=\nby { unfold_coes, simp only with mfld_simps }\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at_symm (p : tangent_bundle I H) :\n  ((chart_at (model_prod H E) p).symm : model_prod H E \u2192 tangent_bundle I H) =\n  (equiv.sigma_equiv_prod H E).symm :=\nby { unfold_coes, simp only with mfld_simps }\n\nvariable (H)\n/-- The canonical identification between the tangent bundle to the model space and the product,\nas a homeomorphism -/\ndef tangent_bundle_model_space_homeomorph : tangent_bundle I H \u2243\u209c model_prod H E :=\n{ continuous_to_fun :=\n  begin\n    let p : tangent_bundle I H := \u27e8I.symm (0 : E), (0 : E)\u27e9,\n    have : continuous (chart_at (model_prod H E) p),\n    { rw continuous_iff_continuous_on_univ,\n      convert local_homeomorph.continuous_on _,\n      simp only with mfld_simps },\n    simpa only with mfld_simps using this,\n  end,\n  continuous_inv_fun :=\n  begin\n    let p : tangent_bundle I H := \u27e8I.symm (0 : E), (0 : E)\u27e9,\n    have : continuous (chart_at (model_prod H E) p).symm,\n    { rw continuous_iff_continuous_on_univ,\n      convert local_homeomorph.continuous_on _,\n      simp only with mfld_simps },\n    simpa only with mfld_simps using this,\n  end,\n  .. equiv.sigma_equiv_prod H E }\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe :\n  (tangent_bundle_model_space_homeomorph H I : tangent_bundle I H \u2192 model_prod H E)\n  = equiv.sigma_equiv_prod H E :=\nrfl\n\n@[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe_symm :\n  ((tangent_bundle_model_space_homeomorph H I).symm : model_prod H E \u2192 tangent_bundle I H)\n  = (equiv.sigma_equiv_prod H E).symm :=\nrfl\n\nend tangent_bundle\n", "meta": {"author": "jjaassoonn", "repo": "projective_space", "sha": "11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce", "save_path": "github-repos/lean/jjaassoonn-projective_space", "path": "github-repos/lean/jjaassoonn-projective_space/projective_space-11fe19fe9d7991a272e7a40be4b6ad9b0c10c7ce/src/geometry/manifold/basic_smooth_bundle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.70014450685232}}
{"text": "/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury G. Kudryashov, Johannes H\u00f6lzl\n\n! This file was ported from Lean 3 source module order.ord_continuous\n! leanprover-community/mathlib commit 207cfac9fcd06138865b5d04f7091e46d9320432\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.ConditionallyCompleteLattice.Basic\nimport Mathlib.Order.RelIso.Basic\n\n/-!\n# Order continuity\n\nWe say that a function is *left order continuous* if it sends all least upper bounds\nto least upper bounds. The order dual notion is called *right order continuity*.\n\nFor monotone functions `\u211d \u2192 \u211d` these notions correspond to the usual left and right continuity.\n\nWe prove some basic lemmas (`map_sup`, `map_sup\u209b` etc) and prove that a `RelIso` is both left\nand right order continuous.\n-/\n\n\nuniverse u v w x\n\nvariable {\u03b1 : Type u} {\u03b2 : Type v} {\u03b3 : Type w} {\u03b9 : Sort x}\n\nopen Function OrderDual Set\n\n/-!\n### Definitions\n-/\n\n\n/-- A function `f` between preorders is left order continuous if it preserves all suprema.  We\ndefine it using `is_lub` instead of `Sup` so that the proof works both for complete lattices and\nconditionally complete lattices. -/\ndef LeftOrdContinuous [Preorder \u03b1] [Preorder \u03b2] (f : \u03b1 \u2192 \u03b2) :=\n  \u2200 \u2983s : Set \u03b1\u2984 \u2983x\u2984, IsLUB s x \u2192 IsLUB (f '' s) (f x)\n#align left_ord_continuous LeftOrdContinuous\n\n/-- A function `f` between preorders is right order continuous if it preserves all infima.  We\ndefine it using `is_glb` instead of `Inf` so that the proof works both for complete lattices and\nconditionally complete lattices. -/\ndef RightOrdContinuous [Preorder \u03b1] [Preorder \u03b2] (f : \u03b1 \u2192 \u03b2) :=\n  \u2200 \u2983s : Set \u03b1\u2984 \u2983x\u2984, IsGLB s x \u2192 IsGLB (f '' s) (f x)\n#align right_ord_continuous RightOrdContinuous\n\nnamespace LeftOrdContinuous\n\nsection Preorder\n\nvariable (\u03b1) [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2}\n\nprotected theorem id : LeftOrdContinuous (id : \u03b1 \u2192 \u03b1) := fun s x h => by\n  simpa only [image_id] using h\n#align left_ord_continuous.id LeftOrdContinuous.id\n\nvariable {\u03b1}\n\n-- porting note: not sure what is the correct name for this\nprotected theorem order_dual : LeftOrdContinuous f \u2192 RightOrdContinuous (toDual \u2218 f \u2218 ofDual) :=\n  id\n#align left_ord_continuous.order_dual LeftOrdContinuous.order_dual\n\ntheorem map_isGreatest (hf : LeftOrdContinuous f) {s : Set \u03b1} {x : \u03b1} (h : IsGreatest s x) :\n    IsGreatest (f '' s) (f x) :=\n  \u27e8mem_image_of_mem f h.1, (hf h.isLUB).1\u27e9\n#align left_ord_continuous.map_is_greatest LeftOrdContinuous.map_isGreatest\n\ntheorem mono (hf : LeftOrdContinuous f) : Monotone f := fun a\u2081 a\u2082 h =>\n  have : IsGreatest {a\u2081, a\u2082} a\u2082 := \u27e8Or.inr rfl, by simp [*]\u27e9\n  (hf.map_isGreatest this).2 <| mem_image_of_mem _ (Or.inl rfl)\n#align left_ord_continuous.mono LeftOrdContinuous.mono\n\ntheorem comp (hg : LeftOrdContinuous g) (hf : LeftOrdContinuous f) : LeftOrdContinuous (g \u2218 f) :=\n  fun s x h => by simpa only [image_image] using hg (hf h)\n#align left_ord_continuous.comp LeftOrdContinuous.comp\n\n-- PORTING NOTE: how to do this in non-tactic mode?\nprotected theorem iterate {f : \u03b1 \u2192 \u03b1} (hf : LeftOrdContinuous f) (n : \u2115) :\n    LeftOrdContinuous (f^[n]) :=\nby induction n with\n| zero => exact LeftOrdContinuous.id \u03b1\n| succ n ihn => exact ihn.comp hf\n\n#align left_ord_continuous.iterate LeftOrdContinuous.iterate\n\nend Preorder\n\nsection SemilatticeSup\n\nvariable [SemilatticeSup \u03b1] [SemilatticeSup \u03b2] {f : \u03b1 \u2192 \u03b2}\n\ntheorem map_sup (hf : LeftOrdContinuous f) (x y : \u03b1) : f (x \u2294 y) = f x \u2294 f y :=\n  (hf isLUB_pair).unique <| by simp only [image_pair, isLUB_pair]\n#align left_ord_continuous.map_sup LeftOrdContinuous.map_sup\n\ntheorem le_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x \u2264 f y \u2194 x \u2264 y := by\n  simp only [\u2190 sup_eq_right, \u2190 hf.map_sup, h.eq_iff]\n#align left_ord_continuous.le_iff LeftOrdContinuous.le_iff\n\ntheorem lt_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x < f y \u2194 x < y := by\n  simp only [lt_iff_le_not_le, hf.le_iff h]\n#align left_ord_continuous.lt_iff LeftOrdContinuous.lt_iff\n\nvariable (f)\n\n/-- Convert an injective left order continuous function to an order embedding. -/\ndef toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) : \u03b1 \u21aao \u03b2 :=\n  \u27e8\u27e8f, h\u27e9, hf.le_iff h\u27e9\n#align left_ord_continuous.to_order_embedding LeftOrdContinuous.toOrderEmbedding\n\nvariable {f}\n\n@[simp]\ntheorem coe_toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) :\n    \u21d1(hf.toOrderEmbedding f h) = f :=\n  rfl\n#align left_ord_continuous.coe_to_order_embedding LeftOrdContinuous.coe_toOrderEmbedding\n\nend SemilatticeSup\n\nsection CompleteLattice\n\nvariable [CompleteLattice \u03b1] [CompleteLattice \u03b2] {f : \u03b1 \u2192 \u03b2}\n\ntheorem map_sup\u209b' (hf : LeftOrdContinuous f) (s : Set \u03b1) : f (sup\u209b s) = sup\u209b (f '' s) :=\n  (hf <| isLUB_sup\u209b s).sup\u209b_eq.symm\n#align left_ord_continuous.map_Sup' LeftOrdContinuous.map_sup\u209b'\n\ntheorem map_sup\u209b (hf : LeftOrdContinuous f) (s : Set \u03b1) : f (sup\u209b s) = \u2a06 x \u2208 s, f x := by\n  rw [hf.map_sup\u209b', sup\u209b_image]\n#align left_ord_continuous.map_Sup LeftOrdContinuous.map_sup\u209b\n\ntheorem map_sup\u1d62 (hf : LeftOrdContinuous f) (g : \u03b9 \u2192 \u03b1) : f (\u2a06 i, g i) = \u2a06 i, f (g i) := by\n  simp only [sup\u1d62, hf.map_sup\u209b', \u2190 range_comp]\n  rfl\n#align left_ord_continuous.map_supr LeftOrdContinuous.map_sup\u1d62\n\nend CompleteLattice\n\nsection ConditionallyCompleteLattice\n\nvariable [ConditionallyCompleteLattice \u03b1] [ConditionallyCompleteLattice \u03b2] [Nonempty \u03b9] {f : \u03b1 \u2192 \u03b2}\n\ntheorem map_csup\u209b (hf : LeftOrdContinuous f) {s : Set \u03b1} (sne : s.Nonempty) (sbdd : BddAbove s) :\n    f (sup\u209b s) = sup\u209b (f '' s) :=\n  ((hf <| isLUB_csup\u209b sne sbdd).csup\u209b_eq <| sne.image f).symm\n#align left_ord_continuous.map_cSup LeftOrdContinuous.map_csup\u209b\n\ntheorem map_csup\u1d62 (hf : LeftOrdContinuous f) {g : \u03b9 \u2192 \u03b1} (hg : BddAbove (range g)) :\n    f (\u2a06 i, g i) = \u2a06 i, f (g i) := by\n  simp only [sup\u1d62, hf.map_csup\u209b (range_nonempty _) hg, \u2190 range_comp]\n  rfl\n#align left_ord_continuous.map_csupr LeftOrdContinuous.map_csup\u1d62\n\nend ConditionallyCompleteLattice\n\nend LeftOrdContinuous\n\nnamespace RightOrdContinuous\n\nsection Preorder\n\nvariable (\u03b1) [Preorder \u03b1] [Preorder \u03b2] [Preorder \u03b3] {g : \u03b2 \u2192 \u03b3} {f : \u03b1 \u2192 \u03b2}\n\nprotected theorem id : RightOrdContinuous (id : \u03b1 \u2192 \u03b1) := fun s x h => by\n  simpa only [image_id] using h\n#align right_ord_continuous.id RightOrdContinuous.id\n\nvariable {\u03b1}\n\nprotected theorem orderDual : RightOrdContinuous f \u2192 LeftOrdContinuous (toDual \u2218 f \u2218 ofDual) :=\n  id\n#align right_ord_continuous.order_dual RightOrdContinuous.orderDual\n\ntheorem map_isLeast (hf : RightOrdContinuous f) {s : Set \u03b1} {x : \u03b1} (h : IsLeast s x) :\n    IsLeast (f '' s) (f x) :=\n  hf.orderDual.map_isGreatest h\n#align right_ord_continuous.map_is_least RightOrdContinuous.map_isLeast\n\ntheorem mono (hf : RightOrdContinuous f) : Monotone f :=\n  hf.orderDual.mono.dual\n#align right_ord_continuous.mono RightOrdContinuous.mono\n\ntheorem comp (hg : RightOrdContinuous g) (hf : RightOrdContinuous f) : RightOrdContinuous (g \u2218 f) :=\n  hg.orderDual.comp hf.orderDual\n#align right_ord_continuous.comp RightOrdContinuous.comp\n\nprotected theorem iterate {f : \u03b1 \u2192 \u03b1} (hf : RightOrdContinuous f) (n : \u2115) :\n    RightOrdContinuous (f^[n]) :=\n  hf.orderDual.iterate n\n#align right_ord_continuous.iterate RightOrdContinuous.iterate\n\nend Preorder\n\nsection SemilatticeInf\n\nvariable [SemilatticeInf \u03b1] [SemilatticeInf \u03b2] {f : \u03b1 \u2192 \u03b2}\n\ntheorem map_inf (hf : RightOrdContinuous f) (x y : \u03b1) : f (x \u2293 y) = f x \u2293 f y :=\n  hf.orderDual.map_sup x y\n#align right_ord_continuous.map_inf RightOrdContinuous.map_inf\n\ntheorem le_iff (hf : RightOrdContinuous f) (h : Injective f) {x y} : f x \u2264 f y \u2194 x \u2264 y :=\n  hf.orderDual.le_iff h\n#align right_ord_continuous.le_iff RightOrdContinuous.le_iff\n\ntheorem lt_iff (hf : RightOrdContinuous f) (h : Injective f) {x y} : f x < f y \u2194 x < y :=\n  hf.orderDual.lt_iff h\n#align right_ord_continuous.lt_iff RightOrdContinuous.lt_iff\n\nvariable (f)\n\n/-- Convert an injective left order continuous function to a `order_embedding`. -/\ndef toOrderEmbedding (hf : RightOrdContinuous f) (h : Injective f) : \u03b1 \u21aao \u03b2 :=\n  \u27e8\u27e8f, h\u27e9, hf.le_iff h\u27e9\n#align right_ord_continuous.to_order_embedding RightOrdContinuous.toOrderEmbedding\n\nvariable {f}\n\n@[simp]\ntheorem coe_toOrderEmbedding (hf : RightOrdContinuous f) (h : Injective f) :\n    \u21d1(hf.toOrderEmbedding f h) = f :=\n  rfl\n#align right_ord_continuous.coe_to_order_embedding RightOrdContinuous.coe_toOrderEmbedding\n\nend SemilatticeInf\n\nsection CompleteLattice\n\nvariable [CompleteLattice \u03b1] [CompleteLattice \u03b2] {f : \u03b1 \u2192 \u03b2}\n\ntheorem map_inf\u209b' (hf : RightOrdContinuous f) (s : Set \u03b1) : f (inf\u209b s) = inf\u209b (f '' s) :=\n  hf.orderDual.map_sup\u209b' s\n#align right_ord_continuous.map_Inf' RightOrdContinuous.map_inf\u209b'\n\ntheorem map_inf\u209b (hf : RightOrdContinuous f) (s : Set \u03b1) : f (inf\u209b s) = \u2a05 x \u2208 s, f x :=\n  hf.orderDual.map_sup\u209b s\n#align right_ord_continuous.map_Inf RightOrdContinuous.map_inf\u209b\n\ntheorem map_inf\u1d62 (hf : RightOrdContinuous f) (g : \u03b9 \u2192 \u03b1) : f (\u2a05 i, g i) = \u2a05 i, f (g i) :=\n  hf.orderDual.map_sup\u1d62 g\n#align right_ord_continuous.map_infi RightOrdContinuous.map_inf\u1d62\n\nend CompleteLattice\n\nsection ConditionallyCompleteLattice\n\nvariable [ConditionallyCompleteLattice \u03b1] [ConditionallyCompleteLattice \u03b2] [Nonempty \u03b9] {f : \u03b1 \u2192 \u03b2}\n\ntheorem map_cinf\u209b (hf : RightOrdContinuous f) {s : Set \u03b1} (sne : s.Nonempty) (sbdd : BddBelow s) :\n    f (inf\u209b s) = inf\u209b (f '' s) :=\n  hf.orderDual.map_csup\u209b sne sbdd\n#align right_ord_continuous.map_cInf RightOrdContinuous.map_cinf\u209b\n\ntheorem map_cinf\u1d62 (hf : RightOrdContinuous f) {g : \u03b9 \u2192 \u03b1} (hg : BddBelow (range g)) :\n    f (\u2a05 i, g i) = \u2a05 i, f (g i) :=\n  hf.orderDual.map_csup\u1d62 hg\n#align right_ord_continuous.map_cinfi RightOrdContinuous.map_cinf\u1d62\n\nend ConditionallyCompleteLattice\n\nend RightOrdContinuous\n\nnamespace OrderIso\n\nsection Preorder\n\nvariable [Preorder \u03b1] [Preorder \u03b2] (e : \u03b1 \u2243o \u03b2) {s : Set \u03b1} {x : \u03b1}\n\nprotected theorem leftOrdContinuous : LeftOrdContinuous e := fun _ _ hx =>\n  \u27e8Monotone.mem_upperBounds_image (fun _ _ => e.map_rel_iff.2) hx.1, fun _ hy =>\n    e.rel_symm_apply.1 <|\n      (isLUB_le_iff hx).2 fun _ hx' => e.rel_symm_apply.2 <| hy <| mem_image_of_mem _ hx'\u27e9\n#align order_iso.left_ord_continuous OrderIso.leftOrdContinuous\n\nprotected \n\nend Preorder\n\nend OrderIso\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/Order/OrdContinuous.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7001185423489388}}
{"text": "variables A B C D : Prop\n\nexample : A \u2227 (A \u2192 B) \u2192 B :=\nassume h,\nshow B, from h.right h.left\n\n\nexample : A \u2192 \u00ac (\u00ac A \u2227 B) :=\nassume h1 : A,\nassume h2: \u00ac A \u2227 B,\nshow false, from h2.left h1\n\nexample : \u00ac (A \u2227 B) \u2192 (A \u2192 \u00ac B) :=\n\u03bb h1 h2 h3, h1 (\u27e8 h2 , h3 \u27e9)\n\nexample (h\u2081 : A \u2228 B) (h\u2082 : A \u2192 C) (h\u2083 : B \u2192 D) : C \u2228 D :=\nor.elim h\u2081\n  (assume h\u2084 : A, show C \u2228 D, from or.inl (h\u2082 h\u2084))\n  (assume h\u2084 : B, show C \u2228 D, from or.inr (h\u2083 h\u2084))\n\nexample (h : \u00ac A \u2227 \u00ac B) : \u00ac (A \u2228 B) :=\nassume h1 : A \u2228 B,\nor.elim h1\n  (assume h2 : A, show false, from h.left h2)\n  (assume h3 : B, show false, from h.right h3)\n\nexample : \u00ac (A \u2194 \u00ac A) :=\nassume h,\nhave h1 : \u00ac A, from\n    assume a : A,\n    show false, from (h.mp a) a,\nshow false, from h1 (h.mpr h1)\n", "meta": {"author": "kaychaks", "repo": "logic_proof", "sha": "90f3bf0acbabf558ba2f82dee968255d8bfe2de1", "save_path": "github-repos/lean/kaychaks-logic_proof", "path": "github-repos/lean/kaychaks-logic_proof/logic_proof-90f3bf0acbabf558ba2f82dee968255d8bfe2de1/src/ch4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7001185377773124}}
{"text": "open classical\n\nvariable (r : Prop)\nvariable (\u03b1 : Type) \nvariables (p q : \u03b1 \u2192 Prop)\nvariable a : \u03b1\nvariable w : \u03b1\n\nexample (\u03b1 : Type) (p q : \u03b1 \u2192 Prop) : (\u2200 x : \u03b1, p x \u2227 q x) \u2194 (\u2200 x : \u03b1, p x) \u2227 (\u2200 x : \u03b1, q x) :=\n  iff.intro \n  (fun h : \u2200 x : \u03b1, p x \u2227 q x ,\n    and.intro \n      (fun z : \u03b1 , show p z ,from and.left (h z)) \n      (fun z : \u03b1 , show q z ,from and.right (h z))\n  )\n  (fun h : (\u2200 x : \u03b1, p x) \u2227 (\u2200 x : \u03b1, q x) ,\n    (fun z : \u03b1 , \n      and.intro ( and.left h z ) ( and.right h z)\n    )\n  )\n  \nexample : (\u2200 x: \u03b1, p x \u2192 q x) \u2192 (\u2200 x: \u03b1, p x) \u2192 (\u2200 x: \u03b1, q x) := \n  (fun h1 : \u2200 x: \u03b1, p x \u2192 q x , \n    (fun h2 : \u2200 x: \u03b1, p x ,\n      (fun z: \u03b1 ,  h1 z (h2 z) \n      ) \n    )\n  )\n\n\nexample : (\u2200 x : \u03b1, p x) \u2228 (\u2200 x : \u03b1, q x) \u2192 \u2200 x : \u03b1, p x \u2228 q x := \n  (fun h :(\u2200 x : \u03b1, p x) \u2228 (\u2200 x : \u03b1, q x) ,\n    or.elim\n      h\n      (fun h1 : (\u2200 x : \u03b1, p x) , (fun z : \u03b1 , or.intro_left (q z) (h1 z) ) ) \n      (fun h2 : (\u2200 x : \u03b1, q x) , (fun z : \u03b1 , or.intro_right (p z) (h2 z) ) )\n  )\n\nexample : \u03b1 \u2192 ( (\u2200 x : \u03b1, r) \u2194 r) :=\n  (fun a : \u03b1 ,\n    show (\u2200 x : \u03b1, r) \u2194 r, from\n    iff.intro\n        (fun h1 : (\u2200 x : \u03b1, r),\n            show r, from\n            h1 a\n        )\n        (fun h2 : r,\n            show (\u2200 x : \u03b1, r), from\n            (fun b : \u03b1, h2)\n        )\n  )\n\nexample : (\u2200 x, p x \u2228 r) \u2194 (\u2200 x, p x) \u2228 r :=\n  iff.intro\n    (fun h : (\u2200 x, p x \u2228 r),\n      or.elim \n        (em r)\n        (fun hr : r,\n          or.intro_right (\u2200 x, p x) hr\n        )\n        (fun hnr : \u00acr,\n          have h2 : (\u2200 z, p z) :=\n            (fun z : \u03b1, \n            have h1 : (p z \u2228 r) := (h z),\n            or.elim \n              h1\n              (fun hpz : (p z), hpz)\n              (fun hr : r, absurd hr hnr)\n            ),\n          or.intro_left r h2\n        )\n    )\n    (fun h : (\u2200 x, p x) \u2228 r,\n        (fun z : \u03b1,\n          or.elim \n            h\n            (fun hl : (\u2200 x, p x), or.intro_left r (hl z))\n            (fun hr : r, or.intro_right (p z) hr)\n        )\n    )\n\nexample : (\u2200 x, r \u2192 p x) \u2194 (r \u2192 \u2200 x, p x) :=\n  iff.intro\n      (fun h : (\u2200 x, r \u2192 p x),\n        (fun hr : r, \n          (fun z : \u03b1,\n            (h z) hr\n          )\n        )\n      )\n      (fun h : r \u2192 \u2200 x, p x,\n        (fun z : \u03b1,\n          (fun hr : r, \n            h hr z\n          )\n        )\n      )\n    \nexample : (\u2203 x : \u03b1, r) \u2192 r := \n  (fun h : (\u2203 x : \u03b1, r),\n    exists.elim \n      h\n      (fun w : \u03b1,\n        (fun hr : r,\n          hr \n        )\n      )\n  )\n  \n\nexample : r \u2192 (\u2203 x : \u03b1, r) := \n  (fun hr : r,\n    exists.intro a hr\n  )\n\nexample : (\u2203 x, p x \u2227 r) \u2194 (\u2203 x, p x) \u2227 r := \n  iff.intro\n    (fun h :(\u2203 x, p x \u2227 r),\n      exists.elim\n        h\n        (fun w, \n          (fun hw : (p w \u2227 r),\n            have hr : r :=  and.right hw,\n            have hl : (\u2203 x, p x) := exists.intro w (and.left hw),\n            and.intro hl hr\n          )\n        )\n    )\n    (fun h : ((\u2203 x, p x) \u2227 r),\n      exists.elim \n        (and.left h)\n        (fun w,\n          (fun hw: (p w),\n            exists.intro w (and.intro hw (and.right h))\n          )\n        )\n    )\n\nexample : (\u2203 x, p x \u2228 q x) \u2194 (\u2203 x, p x) \u2228 (\u2203 x, q x) := \n  iff.intro\n    (fun h : (\u2203 x, p x \u2228 q x),\n      exists.elim\n        h\n        (fun w,\n          (fun hw : (p w \u2228 q w),\n            or.elim\n              hw\n              (fun hpw : (p w),\n                have hepx : (\u2203 x, p x) := exists.intro w hpw,\n                or.intro_left (\u2203 x, q x) hepx \n              )\n              (fun hqw : (q w),\n                have heqx : (\u2203 x, q x) := exists.intro w hqw,\n                or.intro_right (\u2203 x, p x) heqx \n              )\n          ) \n        )\n    )\n    (fun h : (\u2203 x, p x) \u2228 (\u2203 x, q x),\n      or.elim\n        h \n        (fun hpx : (\u2203 x, p x),\n          exists.elim \n            hpx \n            (fun w,\n              (fun hw : p w,\n                have h_pw_or_qw : (p w) \u2228 (q w) := or.intro_left (q w) hw,\n                exists.intro \n                  w\n                  h_pw_or_qw\n              )\n            )\n        )    \n        (fun hqx : (\u2203 x, q x),\n          exists.elim \n            hqx \n            (fun w,\n              (fun hw : q w,\n                have h_pw_or_qw : (p w) \u2228 (q w) := or.intro_right (p w) hw,\n                exists.intro \n                  w\n                  h_pw_or_qw\n              )\n            )\n        )    \n    )\n\n\ntheorem forall_px_eq_not_exist_not_px  {\u03b1 : Type} {p : \u03b1 \u2192 Prop} : (\u2200 x, p x) \u2194 \u00ac (\u2203 x, \u00ac p x) := \n  iff.intro\n    (fun h : (\u2200 x, p x),\n      ( fun hx : (\u2203 x, \u00ac p x),\n        exists.elim\n          hx\n          (fun w,\n            have hpw : p w := h w,\n            (fun hw :  \u00ac (p w),\n              absurd hpw hw\n            )\n          )\n      )\n    )\n    (fun h : \u00ac (\u2203 x, \u00ac p x),\n      (fun z : \u03b1,\n        by_contradiction\n          (fun hnpz : \u00ac p z,\n            absurd \n              (exists.intro z hnpz)\n              h\n          )\n      )\n    )\n\ntheorem not_exists_p_x_imp_forall_not_p_x {\u03b1 : Type} {p : \u03b1 \u2192 Prop} :  \u00ac (\u2203 x, p x) -> (\u2200 x, \u00ac p x) := \n  (fun h : \u00ac (\u2203 x, p x),\n    (fun z,\n      (fun hpz : p z,\n        have h3 :  (\u2203 x, p x) := \n          exists.intro \n            z\n            hpz,\n        h h3 \n      )\n    )\n  )\n\ntheorem dne {p : Prop} (h : \u00ac\u00acp) : p :=\n  by_cases\n    (fun h1 : p , h1)\n    (fun h1 : \u00acp , absurd h1 h)\n\nexample : (\u2203 x, p x) \u2194 \u00ac (\u2200 x, \u00ac p x) := \n  iff.intro\n  (fun h: (\u2203 x, p x) ,\n      by_contradiction\n        (fun h2 : \u00ac\u00ac (\u2200 x, \u00ac p x),\n          have h1 : (\u2200 x, \u00ac p x) := dne h2,\n          exists.elim\n            h\n            (fun w,\n              (fun hw : (p w),\n                absurd hw (h1 w)\n              )\n            )\n        )\n  )\n  (fun h : \u00ac (\u2200 x, \u00ac p x),\n    by_contradiction\n      (fun h1:  \u00ac (\u2203 x, p x),\n        have h2 : (\u2200 x, \u00ac p x) := not_exists_p_x_imp_forall_not_p_x h1, \n        absurd h2 h\n      )\n  )\n\nexample : (\u00ac \u2203 x, p x) \u2194 (\u2200 x, \u00ac p x) :=\n  iff.intro\n    (fun h : \u00ac \u2203 x, p x,\n        not_exists_p_x_imp_forall_not_p_x h\n    )\n    (fun h : \u2200 x, \u00ac p x,\n        (fun h2 : \u2203 x, p x,\n          exists.elim\n            h2\n            (fun w,\n              (fun hw: p w,\n                absurd hw (h w)\n              )\n            )\n        )\n    )\n\ntheorem not_forall_iff_not_exists {\u03b1 : Type} {p : \u03b1 \u2192 Prop} : (\u00ac \u2200 x, p x) \u2194 (\u2203 x, \u00ac p x) :=\n  iff.intro\n    (fun h : \u00ac \u2200 x, p x,\n      by_contradiction\n        (fun h_tofalsify : \u00ac (\u2203 x, \u00ac p x),\n          have h2 : \u2200 x, p x := (iff.elim_right forall_px_eq_not_exist_not_px) h_tofalsify,\n          absurd h2 h\n        )\n      )\n    (fun h : \u2203 x, \u00ac p x,\n        exists.elim\n          h \n          (fun w ,\n            (fun hnw :  \u00ac p w,\n              (fun  hallp : \u2200 x, p x,\n                absurd (hallp w) hnw\n              )\n            )\n          )\n    )\n\n\nexample : (\u2200 x, p x \u2192 r) \u2194 (\u2203 x, p x) \u2192 r :=\n  iff.intro\n    (fun h : (\u2200 x, p x \u2192 r),\n      (fun h2 : \u2203 x, p x,\n        exists.elim \n          h2 \n          (fun w,\n            (fun hw: p w,\n              (h w) hw\n            )\n          )\n      )\n    )\n    (fun h : (\u2203 x, p x) \u2192 r,\n      (fun z : \u03b1,\n        (fun hpz : p z,\n          h(\n            exists.intro \n            z \n            hpz \n          )\n        )\n      )\n    )\n\nexample : (\u2203 x, p x \u2192 r) \u2194 (\u2200 x, p x) \u2192 r :=\n  iff.intro\n    (fun h : \u2203 x, p x \u2192 r,\n        exists.elim\n          h \n          (fun w ,\n            (fun hw : p w \u2192 r,\n              (fun h2 : \u2200 x, p x,\n                hw (h2 w)\n              ) \n            )\n          )\n    )\n    (fun h : (\u2200 x, p x) \u2192 r,\n      by_cases\n        (fun h1 : (\u2200 x, p x),\n          have hr : r := h h1,\n          exists.intro\n            a\n            (fun hp : p a,\n              hr\n            )\n        )\n        (fun hn1 : \u00ac (\u2200 x, p x),\n          have h3 : (\u2203 x, \u00ac p x) := (iff.elim_left not_forall_iff_not_exists) hn1,\n          exists.elim \n            h3 \n            (fun w ,\n              (fun hw : \u00ac p w,\n                exists.intro\n                  w \n                  (fun hpw : p w,\n                    absurd hpw hw\n                  )\n              )\n            )\n        )\n    )\n\n\nexample : (\u2203 x, r \u2192 p x) \u2194 (r \u2192 \u2203 x, p x) :=\n  iff.intro\n    (fun h : (\u2203 x, r \u2192 p x),\n        exists.elim\n          h \n          (fun w,\n            (fun hw : r -> p w ,\n              (fun hr : r,\n                exists.intro\n                  w\n                  (hw hr)\n              )\n            )\n          )\n    )\n    (fun h : (r \u2192 \u2203 x, p x),\n      by_cases\n        (fun hr : r,\n          have h2 : \u2203 x, p x := h hr,\n          exists.elim \n            h2\n            (fun w,\n              (fun hw : p w,\n                exists.intro\n                  w\n                  (fun hr : r, hw)\n              )\n            )\n        )\n        (fun hnr : \u00ac r,\n          exists.intro\n            a\n            (fun hr : r,\n              absurd hr hnr\n            )\n        )\n    )        ", "meta": {"author": "Lehnart", "repo": "lean-math-proof", "sha": "e691362ed040eacdbebaa50d43ab6a154e7be360", "save_path": "github-repos/lean/Lehnart-lean-math-proof", "path": "github-repos/lean/Lehnart-lean-math-proof/lean-math-proof-e691362ed040eacdbebaa50d43ab6a154e7be360/quantifier.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.7905303162021597, "lm_q1q2_score": 0.7001185314223939}}
{"text": "/-\nCopyright (c) 2022 Kyle Miller. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kyle Miller, Vincent Beffara\n-/\nimport combinatorics.simple_graph.connectivity\nimport data.nat.lattice\n\n/-!\n# Graph metric\n\nThis module defines the `simple_graph.dist` function, which takes\npairs of vertices to the length of the shortest walk between them.\n\n## Main definitions\n\n- `simple_graph.dist` is the graph metric.\n\n## Todo\n\n- Provide an additional computable version of `simple_graph.dist`\n  for when `G` is connected.\n\n- Evaluate `nat` vs `enat` for the codomain of `dist`, or potentially\n  having an additional `edist` when the objects under consideration are\n  disconnected graphs.\n\n- When directed graphs exist, a directed notion of distance,\n  likely `enat`-valued.\n\n## Tags\n\ngraph metric, distance\n\n-/\n\nnamespace simple_graph\nvariables {V : Type*} (G : simple_graph V)\n\n/-! ## Metric -/\n\n/-- The distance between two vertices is the length of the shortest walk between them.\nIf no such walk exists, this uses the junk value of `0`. -/\nnoncomputable\ndef dist (u v : V) : \u2115 := Inf (set.range (walk.length : G.walk u v \u2192 \u2115))\n\nvariables {G}\n\nprotected\nlemma reachable.exists_walk_of_dist {u v : V} (hr : G.reachable u v) :\n  \u2203 (p : G.walk u v), p.length = G.dist u v :=\nnat.Inf_mem (set.range_nonempty_iff_nonempty.mpr hr)\n\nprotected\nlemma connected.exists_walk_of_dist (hconn : G.connected) (u v : V) :\n  \u2203 (p : G.walk u v), p.length = G.dist u v :=\n(hconn u v).exists_walk_of_dist\n\nlemma dist_le {u v : V} (p : G.walk u v) : G.dist u v \u2264 p.length := nat.Inf_le \u27e8p, rfl\u27e9\n\n@[simp]\nlemma dist_eq_zero_iff_eq_or_not_reachable {u v : V} : G.dist u v = 0 \u2194 u = v \u2228 \u00ac G.reachable u v :=\nby simp [dist, nat.Inf_eq_zero, reachable]\n\nlemma dist_self {v : V} : dist G v v = 0 := by simp\n\nprotected\nlemma reachable.dist_eq_zero_iff {u v : V} (hr : G.reachable u v) :\n  G.dist u v = 0 \u2194 u = v := by simp [hr]\n\nprotected\nlemma reachable.pos_dist_of_ne {u v : V} (h : G.reachable u v) (hne : u \u2260 v) : 0 < G.dist u v :=\nnat.pos_of_ne_zero (by simp [h, hne])\n\nprotected\nlemma connected.dist_eq_zero_iff (hconn : G.connected) {u v : V} :\n  G.dist u v = 0 \u2194 u = v := by simp [hconn u v]\n\nprotected\nlemma connected.pos_dist_of_ne {u v : V} (hconn : G.connected) (hne : u \u2260 v) : 0 < G.dist u v :=\nnat.pos_of_ne_zero (by simp [hconn.dist_eq_zero_iff, hne])\n\nlemma dist_eq_zero_of_not_reachable {u v : V} (h : \u00ac G.reachable u v) : G.dist u v = 0 :=\nby simp [h]\n\nlemma nonempty_of_pos_dist {u v : V} (h : 0 < G.dist u v) :\n  (set.univ : set (G.walk u v)).nonempty :=\nby simpa [set.range_nonempty_iff_nonempty, set.nonempty_iff_univ_nonempty]\n     using nat.nonempty_of_pos_Inf h\n\nprotected\nlemma connected.dist_triangle (hconn : G.connected) {u v w : V} :\n  G.dist u w \u2264 G.dist u v + G.dist v w :=\nbegin\n  obtain \u27e8p, hp\u27e9 := hconn.exists_walk_of_dist u v,\n  obtain \u27e8q, hq\u27e9 := hconn.exists_walk_of_dist v w,\n  rw [\u2190 hp, \u2190 hq, \u2190 walk.length_append],\n  apply dist_le,\nend\n\nprivate\n\n\nlemma dist_comm {u v : V} : G.dist u v = G.dist v u :=\nbegin\n  by_cases h : G.reachable u v,\n  { apply le_antisymm (dist_comm_aux h) (dist_comm_aux h.symm), },\n  { have h' : \u00ac G.reachable v u := \u03bb h', absurd h'.symm h,\n    simp [h, h', dist_eq_zero_of_not_reachable], },\nend\n\nend simple_graph\n", "meta": {"author": "saisurbehera", "repo": "mathProof", "sha": "57c6bfe75652e9d3312d8904441a32aff7d6a75e", "save_path": "github-repos/lean/saisurbehera-mathProof", "path": "github-repos/lean/saisurbehera-mathProof/mathProof-57c6bfe75652e9d3312d8904441a32aff7d6a75e/src/tertiary_packages/mathlib/src/combinatorics/simple_graph/metric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7001185292370847}}
{"text": "/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen\n\n! This file was ported from Lean 3 source module ring_theory.localization.fraction_ring\n! leanprover-community/mathlib commit 831c494092374cfe9f50591ed0ac81a25efc5b86\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Algebra.Tower\nimport Mathlib.RingTheory.Localization.Basic\n\n/-!\n# Fraction ring / fraction field Frac(R) as localization\n\n## Main definitions\n\n * `IsFractionRing R K` expresses that `K` is a field of fractions of `R`, as an abbreviation of\n   `IsLocalization (NonZeroDivisors R) K`\n\n## Main results\n\n * `IsFractionRing.field`: a definition (not an instance) stating the localization of an integral\n   domain `R` at `R \\ {0}` is a field\n * `Rat.isFractionRing` is an instance stating `\u211a` is the field of fractions of `\u2124`\n\n## Implementation notes\n\nSee `RingTheory/Localization/Basic.lean` for a design overview.\n\n## Tags\nlocalization, ring localization, commutative ring localization, characteristic predicate,\ncommutative ring, field of fractions\n-/\n\n\nvariable (R : Type _) [CommRing R] {M : Submonoid R} (S : Type _) [CommRing S]\n\nvariable [Algebra R S] {P : Type _} [CommRing P]\n\nvariable {A : Type _} [CommRing A] [IsDomain A] (K : Type _)\n\n-- TODO: should this extend `Algebra` instead of assuming it?\n/-- `IsFractionRing R K` states `K` is the field of fractions of an integral domain `R`. -/\nabbrev IsFractionRing [CommRing K] [Algebra R K] :=\n  IsLocalization (nonZeroDivisors R) K\n#align is_fraction_ring IsFractionRing\n\n/-- The cast from `Int` to `Rat` as a `FractionRing`. -/\ninstance Rat.isFractionRing : IsFractionRing \u2124 \u211a where\n  map_units' := by\n    rintro \u27e8x, hx\u27e9\n    rw [mem_nonZeroDivisors_iff_ne_zero] at hx\n    simpa only [eq_intCast, isUnit_iff_ne_zero, Int.cast_eq_zero, Ne.def, Subtype.coe_mk] using hx\n  surj':= by\n    rintro \u27e8n, d, hd, h\u27e9\n    refine' \u27e8\u27e8n, \u27e8d, _\u27e9\u27e9, Rat.mul_den_eq_num\u27e9\n    rw [mem_nonZeroDivisors_iff_ne_zero, Int.coe_nat_ne_zero_iff_pos]\n    exact Nat.zero_lt_of_ne_zero hd\n  eq_iff_exists' := by\n    intro x y\n    rw [eq_intCast, eq_intCast, Int.cast_inj]\n    apply Iff.intro\n    \u00b7 rintro rfl\n      use 1\n    \u00b7 rintro \u27e8\u27e8c, hc\u27e9, h\u27e9\n      apply mul_left_cancel\u2080 _ h\n      rwa [mem_nonZeroDivisors_iff_ne_zero] at hc\n#align rat.is_fraction_ring Rat.isFractionRing\n\nnamespace IsFractionRing\n\nopen IsLocalization\n\nvariable {R K}\n\nsection CommRing\n\nvariable [CommRing K] [Algebra R K] [IsFractionRing R K] [Algebra A K] [IsFractionRing A K]\n\ntheorem to_map_eq_zero_iff {x : R} : algebraMap R K x = 0 \u2194 x = 0 :=\n  IsLocalization.to_map_eq_zero_iff _ le_rfl\n#align is_fraction_ring.to_map_eq_zero_iff IsFractionRing.to_map_eq_zero_iff\n\nvariable (R K)\n\nprotected theorem injective : Function.Injective (algebraMap R K) :=\n  IsLocalization.injective _ (le_of_eq rfl)\n#align is_fraction_ring.injective IsFractionRing.injective\n\nvariable {R K}\n\n@[norm_cast, simp]\n-- Porting note: using `\u2191` didn't work, so I needed to explicitly put in the cast myself\ntheorem coe_inj {a b : R} : (Algebra.cast a : K) = Algebra.cast b \u2194 a = b :=\n  (IsFractionRing.injective R K).eq_iff\n#align is_fraction_ring.coe_inj IsFractionRing.coe_inj\n\ninstance (priority := 100) [NoZeroDivisors K] : NoZeroSMulDivisors R K :=\n  NoZeroSMulDivisors.of_algebraMap_injective <| IsFractionRing.injective R K\n\nprotected theorem to_map_ne_zero_of_mem_nonZeroDivisors [Nontrivial R] {x : R}\n    (hx : x \u2208 nonZeroDivisors R) : algebraMap R K x \u2260 0 :=\n  IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors _ le_rfl hx\n#align is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors\n\nvariable (A)\n\n/-- A `CommRing` `K` which is the localization of an integral domain `R` at `R - {0}` is an\nintegral domain. -/\nprotected theorem isDomain : IsDomain K :=\n  isDomain_of_le_nonZeroDivisors _ (le_refl (nonZeroDivisors A))\n#align is_fraction_ring.is_domain IsFractionRing.isDomain\n\nattribute [local instance] Classical.decEq\n\n/-- The inverse of an element in the field of fractions of an integral domain. -/\n-- Porting note: Had to replace `irreducible_def` with the `@[irreducible]` attribute.\n@[irreducible] protected noncomputable def inv (z : K) : K :=\n  if h : z = 0 then 0\n  else\n    mk' K \u2191(sec (nonZeroDivisors A) z).2\n      \u27e8(sec _ z).1,\n        mem_nonZeroDivisors_iff_ne_zero.2 fun h0 =>\n          h <| eq_zero_of_fst_eq_zero (sec_spec (nonZeroDivisors A) z) h0\u27e9\n#align is_fraction_ring.inv IsFractionRing.inv\n\nprotected theorem mul_inv_cancel (x : K) (hx : x \u2260 0) : x * IsFractionRing.inv A x = 1 := by\n  rw [IsFractionRing.inv, dif_neg hx, \u2190\n    IsUnit.mul_left_inj\n      (map_units K\n        \u27e8(sec _ x).1,\n          mem_nonZeroDivisors_iff_ne_zero.2 fun h0 =>\n            hx <| eq_zero_of_fst_eq_zero (sec_spec (nonZeroDivisors A) x) h0\u27e9),\n    one_mul, mul_assoc]\n  rw [mk'_spec, \u2190 eq_mk'_iff_mul_eq]\n  exact (mk'_sec _ x).symm\n#align is_fraction_ring.mul_inv_cancel IsFractionRing.mul_inv_cancel\n\n/-- A `CommRing` `K` which is the localization of an integral domain `R` at `R - {0}` is a field.\nSee note [reducible non-instances]. -/\n@[reducible]\nnoncomputable def toField : Field K :=\n  { IsFractionRing.isDomain A, inferInstanceAs (CommRing K) with\n    inv := IsFractionRing.inv A\n    mul_inv_cancel := IsFractionRing.mul_inv_cancel A\n    inv_zero := by\n      change IsFractionRing.inv A (0 : K) = 0\n      rw [IsFractionRing.inv]\n      exact dif_pos rfl }\n#align is_fraction_ring.to_field IsFractionRing.toField\n\nend CommRing\n\nvariable {B : Type _} [CommRing B] [IsDomain B] [Field K] {L : Type _} [Field L] [Algebra A K]\n  [IsFractionRing A K] {g : A \u2192+* L}\n\ntheorem mk'_mk_eq_div {r s} (hs : s \u2208 nonZeroDivisors A) :\n    mk' K r \u27e8s, hs\u27e9 = algebraMap A K r / algebraMap A K s :=\n  mk'_eq_iff_eq_mul.2 <|\n    (div_mul_cancel (algebraMap A K r)\n        (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hs)).symm\n#align is_fraction_ring.mk'_mk_eq_div IsFractionRing.mk'_mk_eq_div\n\n@[simp]\ntheorem mk'_eq_div {r} (s : nonZeroDivisors A) : mk' K r s = algebraMap A K r / algebraMap A K s :=\n  mk'_mk_eq_div s.2\n#align is_fraction_ring.mk'_eq_div IsFractionRing.mk'_eq_div\n\ntheorem div_surjective (z : K) :\n    \u2203 (x y : A)(hy : y \u2208 nonZeroDivisors A), algebraMap _ _ x / algebraMap _ _ y = z :=\n  let \u27e8x, \u27e8y, hy\u27e9, h\u27e9 := mk'_surjective (nonZeroDivisors A) z\n  \u27e8x, y, hy, by rwa [mk'_eq_div] at h\u27e9\n#align is_fraction_ring.div_surjective IsFractionRing.div_surjective\n\ntheorem isUnit_map_of_injective (hg : Function.Injective g) (y : nonZeroDivisors A) :\n    IsUnit (g y) :=\n  IsUnit.mk0 (g y) <|\n    show g.toMonoidWithZeroHom y \u2260 0 from map_ne_zero_of_mem_nonZeroDivisors g hg y.2\n#align is_fraction_ring.is_unit_map_of_injective IsFractionRing.isUnit_map_of_injective\n\n@[simp]\ntheorem mk'_eq_zero_iff_eq_zero [Algebra R K] [IsFractionRing R K] {x : R} {y : nonZeroDivisors R} :\n    mk' K x y = 0 \u2194 x = 0 := by\n  refine' \u27e8fun hxy => _, fun h => by rw [h, mk'_zero]\u27e9\n  \u00b7 simp_rw [mk'_eq_zero_iff, mul_left_coe_nonZeroDivisors_eq_zero_iff] at hxy\n    exact (exists_const _).mp hxy\n#align is_fraction_ring.mk'_eq_zero_iff_eq_zero IsFractionRing.mk'_eq_zero_iff_eq_zero\n\ntheorem mk'_eq_one_iff_eq {x : A} {y : nonZeroDivisors A} : mk' K x y = 1 \u2194 x = y := by\n  refine' \u27e8_, fun hxy => by rw [hxy, mk'_self']\u27e9\n  \u00b7 intro hxy\n    have hy : (algebraMap A K) \u2191y \u2260 (0 : K) :=\n      IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors y.property\n    rw [IsFractionRing.mk'_eq_div, div_eq_one_iff_eq hy] at hxy\n    exact IsFractionRing.injective A K hxy\n#align is_fraction_ring.mk'_eq_one_iff_eq IsFractionRing.mk'_eq_one_iff_eq\n\nopen Function\n\n/-- Given an integral domain `A` with field of fractions `K`,\nand an injective ring hom `g : A \u2192+* L` where `L` is a field, we get a\nfield hom sending `z : K` to `g x * (g y)\u207b\u00b9`, where `(x, y) : A \u00d7 (NonZeroDivisors A)` are\nsuch that `z = f x * (f y)\u207b\u00b9`. -/\nnoncomputable def lift (hg : Injective g) : K \u2192+* L :=\n  IsLocalization.lift fun y : nonZeroDivisors A => isUnit_map_of_injective hg y\n#align is_fraction_ring.lift IsFractionRing.lift\n\n/-- Given an integral domain `A` with field of fractions `K`,\nand an injective ring hom `g : A \u2192+* L` where `L` is a field,\nthe field hom induced from `K` to `L` maps `x` to `g x` for all\n`x : A`. -/\n@[simp]\ntheorem lift_algebraMap (hg : Injective g) (x) : lift hg (algebraMap A K x) = g x :=\n  lift_eq _ _\n#align is_fraction_ring.lift_algebra_map IsFractionRing.lift_algebraMap\n\n/-- Given an integral domain `A` with field of fractions `K`,\nand an injective ring hom `g : A \u2192+* L` where `L` is a field,\nfield hom induced from `K` to `L` maps `f x / f y` to `g x / g y` for all\n`x : A, y \u2208 NonZeroDivisors A`. -/\ntheorem lift_mk' (hg : Injective g) (x) (y : nonZeroDivisors A) : lift hg (mk' K x y) = g x / g y :=\n  by simp only [mk'_eq_div, map_div\u2080, lift_algebraMap]\n#align is_fraction_ring.lift_mk' IsFractionRing.lift_mk'\n\n/-- Given integral domains `A, B` with fields of fractions `K`, `L`\nand an injective ring hom `j : A \u2192+* B`, we get a field hom\nsending `z : K` to `g (j x) * (g (j y))\u207b\u00b9`, where `(x, y) : A \u00d7 (NonZeroDivisors A)` are\nsuch that `z = f x * (f y)\u207b\u00b9`. -/\nnoncomputable def map {A B K L : Type _} [CommRing A] [CommRing B] [IsDomain B] [CommRing K]\n    [Algebra A K] [IsFractionRing A K] [CommRing L] [Algebra B L] [IsFractionRing B L] {j : A \u2192+* B}\n    (hj : Injective j) : K \u2192+* L :=\n  IsLocalization.map L j\n    (show nonZeroDivisors A \u2264 (nonZeroDivisors B).comap j from\n      nonZeroDivisors_le_comap_nonZeroDivisors_of_injective j hj)\n#align is_fraction_ring.map IsFractionRing.map\n\n/-- Given integral domains `A, B` and localization maps to their fields of fractions\n`f : A \u2192+* K, g : B \u2192+* L`, an isomorphism `j : A \u2243+* B` induces an isomorphism of\nfields of fractions `K \u2243+* L`. -/\nnoncomputable def fieldEquivOfRingEquiv [Algebra B L] [IsFractionRing B L] (h : A \u2243+* B) :\n    K \u2243+* L :=\n  ringEquivOfRingEquiv K L h\n    (by\n      ext b\n      show b \u2208 h.toEquiv '' _ \u2194 _\n      erw [h.toEquiv.image_eq_preimage, Set.preimage, Set.mem_setOf_eq,\n        mem_nonZeroDivisors_iff_ne_zero, mem_nonZeroDivisors_iff_ne_zero]\n      exact h.symm.map_ne_zero_iff)\n#align is_fraction_ring.field_equiv_of_ring_equiv IsFractionRing.fieldEquivOfRingEquiv\n\n\n\nprotected theorem nontrivial (R S : Type _) [CommRing R] [Nontrivial R] [CommRing S] [Algebra R S]\n    [IsFractionRing R S] : Nontrivial S := by\n  apply nontrivial_of_ne\n  intro h\n  apply @zero_ne_one R\n  exact\n    IsLocalization.injective S (le_of_eq rfl)\n      (((algebraMap R S).map_zero.trans h).trans (algebraMap R S).map_one.symm)\n#align is_fraction_ring.nontrivial IsFractionRing.nontrivial\n\nend IsFractionRing\n\nvariable (A)\n\n/-- The fraction ring of a commutative ring `R` as a quotient type.\n\nWe instantiate this definition as generally as possible, and assume that the\ncommutative ring `R` is an integral domain only when this is needed for proving.\n-/\n@[reducible]\ndef FractionRing :=\n  Localization (nonZeroDivisors R)\n#align fraction_ring FractionRing\n\nnamespace FractionRing\n\ninstance unique [Subsingleton R] : Unique (FractionRing R) :=\n  Localization.instUniqueLocalizationToCommMonoid\n#align fraction_ring.unique FractionRing.unique\n\ninstance [Nontrivial R] : Nontrivial (FractionRing R) :=\n  \u27e8\u27e8(algebraMap R _) 0, (algebraMap _ _) 1, fun H =>\n      zero_ne_one (IsLocalization.injective _ le_rfl H)\u27e9\u27e9\n\n/-- Porting note: if the fields of this instance are explicitly defined as they were\nin mathlib3, the last instance in this file suffers a TC timeout -/\nnoncomputable instance : Field (FractionRing A) := IsFractionRing.toField A\n\n@[simp]\ntheorem mk_eq_div {r s} :\n    (Localization.mk r s : FractionRing A) =\n      (algebraMap _ _ r / algebraMap A _ s : FractionRing A) :=\n  by rw [Localization.mk_eq_mk', IsFractionRing.mk'_eq_div]\n#align fraction_ring.mk_eq_div FractionRing.mk_eq_div\n\nnoncomputable instance [IsDomain R] [Field K] [Algebra R K] [NoZeroSMulDivisors R K] :\n    Algebra (FractionRing R) K :=\n  RingHom.toAlgebra (IsFractionRing.lift (NoZeroSMulDivisors.algebraMap_injective R _))\n\n-- Porting note: had to fill in the `_` by hand for this instance\ninstance [IsDomain R] [Field K] [Algebra R K] [NoZeroSMulDivisors R K] :\n    IsScalarTower R (FractionRing R) K :=\n  IsScalarTower.of_algebraMap_eq fun x =>\n    (IsFractionRing.lift_algebraMap (NoZeroSMulDivisors.algebraMap_injective R K ) x).symm\n\n/-- Given an integral domain `A` and a localization map to a field of fractions\n`f : A \u2192+* K`, we get an `A`-isomorphism between the field of fractions of `A` as a quotient\ntype and `K`. -/\nnoncomputable def algEquiv (K : Type _) [Field K] [Algebra A K] [IsFractionRing A K] :\n    FractionRing A \u2243\u2090[A] K :=\n  Localization.algEquiv (nonZeroDivisors A) K\n#align fraction_ring.alg_equiv FractionRing.algEquiv\n\ninstance [Algebra R A] [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R (FractionRing A) := by\n  apply NoZeroSMulDivisors.of_algebraMap_injective\n  rw [IsScalarTower.algebraMap_eq R A]\n  apply Function.Injective.comp (NoZeroSMulDivisors.algebraMap_injective A (FractionRing A))\n    (NoZeroSMulDivisors.algebraMap_injective R A)\n\nend FractionRing\n", "meta": {"author": "leanprover-community", "repo": "mathlib4", "sha": "b9a0a30342ca06e9817e22dbe46e75fc7f435500", "save_path": "github-repos/lean/leanprover-community-mathlib4", "path": "github-repos/lean/leanprover-community-mathlib4/mathlib4-b9a0a30342ca06e9817e22dbe46e75fc7f435500/Mathlib/RingTheory/Localization/FractionRing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7001185268507675}}
{"text": "/-\nCopyright (c) 2021 Praneeth Kolichala. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Praneeth Kolichala\n-/\nimport topology.homotopy.basic\nimport topology.constructions\nimport topology.homotopy.path\nimport category_theory.groupoid\nimport topology.homotopy.fundamental_groupoid\nimport topology.category.Top.limits\nimport category_theory.limits.preserves.shapes.products\n\n/-!\n# Product of homotopies\n\nIn this file, we introduce definitions for the product of\nhomotopies. We show that the products of relative homotopies\nare still relative homotopies. Finally, we specialize to the case\nof path homotopies, and provide the definition for the product of path classes.\nWe show various lemmas associated with these products, such as the fact that\npath products commute with path composition, and that projection is the inverse\nof products.\n\n## Definitions\n### General homotopies\n- `continuous_map.homotopy.pi homotopies`: Let f and g be a family of functions\n  indexed on I, such that for each i \u2208 I, f\u1d62 and g\u1d62 are maps from A to X\u1d62.\n  Let `homotopies` be a family of homotopies from f\u1d62 to g\u1d62 for each i.\n  Then `homotopy.pi homotopies` is the canonical homotopy\n  from \u220f f to \u220f g, where \u220f f is the product map from A to \u03a0i, X\u1d62,\n  and similarly for \u220f g.\n\n- `continuous_map.homotopy_rel.pi homotopies`: Same as `continuous_map.homotopy.pi`, but\n  all homotopies are done relative to some set S \u2286 A.\n\n- `continuous_map.homotopy.prod F G` is the product of homotopies F and G,\n   where F is a homotopy between f\u2080 and f\u2081, G is a homotopy between g\u2080 and g\u2081.\n   The result F \u00d7 G is a homotopy between (f\u2080 \u00d7 g\u2080) and (f\u2081 \u00d7 g\u2081).\n   Again, all homotopies are done relative to S.\n\n- `continuous_map.homotopy_rel.prod F G`: Same as `continuous_map.homotopy.prod`, but\n  all homotopies are done relative to some set S \u2286 A.\n\n### Path products\n- `path.homotopic.pi` The product of a family of path classes, where a path class is an equivalence\n  class of paths up to path homotopy.\n\n- `path.homotopic.prod` The product of two path classes.\n\n## Fundamental groupoid preserves products\n  - `fundamental_groupoid_functor.pi_iso` An isomorphism between \u03a0 i, (\u03c0 X\u1d62) and \u03c0 (\u03a0i, X\u1d62), whose\n    inverse is precisely the product of the maps \u03c0 (\u03a0 i, X\u1d62) \u2192 \u03c0 (X\u1d62), each induced by\n    the projection in `Top` \u03a0 i, X\u1d62 \u2192 X\u1d62.\n\n  - `fundamental_groupoid_functor.prod_iso` An isomorphism between \u03c0X \u00d7 \u03c0Y and \u03c0 (X \u00d7 Y), whose\n    inverse is precisely the product of the maps \u03c0 (X \u00d7 Y) \u2192 \u03c0X and \u03c0 (X \u00d7 Y) \u2192 Y, each induced by\n    the projections X \u00d7 Y \u2192 X and X \u00d7 Y \u2192 Y\n\n  - `fundamental_groupoid_functor.preserves_product` A proof that the fundamental groupoid functor\n    preserves all products.\n-/\n\nnoncomputable theory\n\nnamespace continuous_map\nopen continuous_map\n\nsection pi\n\nvariables {I : Type*} {X : I \u2192 Type*} [\u2200i, topological_space (X i)]\n  {A : Type*} [topological_space A]\n  {f g : \u03a0 i, C(A, X i)} {S : set A}\n\n/-- The product homotopy of `homotopies` between functions `f` and `g` -/\n@[simps]\ndef homotopy.pi (homotopies : \u03a0 i, homotopy (f i) (g i)) :\n        homotopy (pi f) (pi g) :=\n{ to_fun := \u03bb t i, homotopies i t,\n  to_fun_zero := by { intro t, ext i, simp only [pi_eval, homotopy.apply_zero], },\n  to_fun_one := by { intro t, ext i, simp only [pi_eval, homotopy.apply_one], } }\n\n/-- The relative product homotopy of `homotopies` between functions `f` and `g` -/\n@[simps]\ndef homotopy_rel.pi (homotopies : \u03a0 i : I, homotopy_rel (f i) (g i) S) :\n  homotopy_rel (pi f) (pi g) S :=\n{ prop' :=\n  begin\n    intros t x hx,\n    dsimp only [coe_mk, pi_eval, to_fun_eq_coe, homotopy_with.coe_to_continuous_map],\n    simp only [function.funext_iff, \u2190 forall_and_distrib],\n    intro i,\n    exact (homotopies i).prop' t x hx,\n  end,\n  ..(homotopy.pi (\u03bb i, (homotopies i).to_homotopy)), }\n\nend pi\n\nsection prod\n\nvariables {\u03b1 \u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n  {A : Type*} [topological_space A]\n  {f\u2080 f\u2081 : C(A, \u03b1)} {g\u2080 g\u2081 : C(A, \u03b2)} {S : set A}\n\n/-- The product of homotopies `F` and `G`,\n  where `F` takes `f\u2080` to `f\u2081`  and `G` takes `g\u2080` to `g\u2081` -/\n@[simps]\ndef homotopy.prod (F : homotopy f\u2080 f\u2081) (G : homotopy g\u2080 g\u2081) :\n  homotopy (prod_mk f\u2080 g\u2080) (prod_mk f\u2081 g\u2081) :=\n{ to_fun := \u03bb t, (F t, G t),\n  to_fun_zero := by { intro, simp only [prod_eval, homotopy.apply_zero], },\n  to_fun_one := by { intro, simp only [prod_eval, homotopy.apply_one], } }\n\n/-- The relative product of homotopies `F` and `G`,\n  where `F` takes `f\u2080` to `f\u2081`  and `G` takes `g\u2080` to `g\u2081` -/\n@[simps]\ndef homotopy_rel.prod (F : homotopy_rel f\u2080 f\u2081 S) (G : homotopy_rel g\u2080 g\u2081 S) :\n  homotopy_rel (prod_mk f\u2080 g\u2080) (prod_mk f\u2081 g\u2081) S :=\n{ prop' :=\n  begin\n    intros t x hx,\n    have hF := F.prop' t x hx,\n    have hG := G.prop' t x hx,\n    simp only [coe_mk, prod_eval, prod.mk.inj_iff, homotopy.prod] at hF hG \u22a2,\n    exact \u27e8\u27e8hF.1, hG.1\u27e9, \u27e8hF.2, hG.2\u27e9\u27e9,\n  end,\n  ..(homotopy.prod F.to_homotopy G.to_homotopy) }\n\nend prod\nend continuous_map\n\n\nnamespace path.homotopic\nlocal attribute [instance] path.homotopic.setoid\nlocal infix ` \u2b1d `:70 := quotient.comp\n\nsection pi\n\nvariables {\u03b9 : Type*} {X : \u03b9 \u2192 Type*} [\u2200 i, topological_space (X i)]\n  {as bs cs : \u03a0 i, X i}\n\n/-- The product of a family of path homotopies. This is just a specialization of `homotopy_rel` -/\ndef pi_homotopy (\u03b3\u2080 \u03b3\u2081 : \u03a0 i, path (as i) (bs i)) (H : \u2200 i, path.homotopy (\u03b3\u2080 i) (\u03b3\u2081 i)) :\n  path.homotopy (path.pi \u03b3\u2080) (path.pi \u03b3\u2081) := continuous_map.homotopy_rel.pi H\n\n/-- The product of a family of path homotopy classes -/\ndef pi (\u03b3 : \u03a0 i, path.homotopic.quotient (as i) (bs i)) : path.homotopic.quotient as bs :=\n(quotient.map path.pi\n  (\u03bb x y hxy, nonempty.map (pi_homotopy x y) (classical.nonempty_pi.mpr hxy)))\n  (quotient.choice \u03b3)\n\nlemma pi_lift (\u03b3 : \u03a0 i, path (as i) (bs i)) : path.homotopic.pi (\u03bb i, \u27e6\u03b3 i\u27e7) = \u27e6path.pi \u03b3\u27e7 :=\nby { unfold pi, simp, }\n\n/-- Composition and products commute.\n  This is `path.trans_pi_eq_pi_trans` descended to path homotopy classes -/\nlemma comp_pi_eq_pi_comp\n  (\u03b3\u2080 : \u03a0 i, path.homotopic.quotient (as i) (bs i))\n  (\u03b3\u2081 : \u03a0 i, path.homotopic.quotient (bs i) (cs i)) :\n  pi \u03b3\u2080 \u2b1d pi \u03b3\u2081 = pi (\u03bb i, \u03b3\u2080 i \u2b1d \u03b3\u2081 i) :=\nbegin\n  apply quotient.induction_on_pi \u03b3\u2081,\n  apply quotient.induction_on_pi \u03b3\u2080,\n  intros,\n  simp only [pi_lift],\n  rw [\u2190 path.homotopic.comp_lift,\n      path.trans_pi_eq_pi_trans,\n      \u2190 pi_lift],\n  refl,\nend\n\n/-- Abbreviation for projection onto the ith coordinate -/\n@[reducible]\ndef proj (i : \u03b9) (p : path.homotopic.quotient as bs) : path.homotopic.quotient (as i) (bs i) :=\np.map_fn \u27e8_, continuous_apply i\u27e9\n\n/-- Lemmas showing projection is the inverse of pi -/\n@[simp] lemma proj_pi (i : \u03b9) (paths : \u03a0 i, path.homotopic.quotient (as i) (bs i)) :\n  proj i (pi paths) = paths i :=\nbegin\n  apply quotient.induction_on_pi paths,\n  intro, unfold proj,\n  rw [pi_lift, \u2190 path.homotopic.map_lift],\n  congr, ext, refl,\nend\n\n@[simp] lemma pi_proj (p : path.homotopic.quotient as bs) : pi (\u03bb i, proj i p) = p :=\nbegin\n  apply quotient.induction_on p,\n  intro, unfold proj,\n  simp_rw \u2190 path.homotopic.map_lift,\n  rw pi_lift,\n  congr, ext, refl,\nend\n\nend pi\n\nsection prod\n\nvariables {\u03b1 \u03b2 : Type*} [topological_space \u03b1] [topological_space \u03b2]\n  {a\u2081 a\u2082 a\u2083 : \u03b1} {b\u2081 b\u2082 b\u2083 : \u03b2}\n  {p\u2081 p\u2081' : path a\u2081 a\u2082} {p\u2082 p\u2082' : path b\u2081 b\u2082}\n  (q\u2081 : path.homotopic.quotient a\u2081 a\u2082) (q\u2082 : path.homotopic.quotient b\u2081 b\u2082)\n\n/-- The product of homotopies h\u2081 and h\u2082.\n    This is `homotopy_rel.prod` specialized for path homotopies. -/\ndef prod_homotopy (h\u2081 : path.homotopy p\u2081 p\u2081') (h\u2082 : path.homotopy p\u2082 p\u2082') :\n  path.homotopy (p\u2081.prod p\u2082) (p\u2081'.prod p\u2082') := continuous_map.homotopy_rel.prod h\u2081 h\u2082\n\n/-- The product of path classes q\u2081 and q\u2082. This is `path.prod` descended to the quotient -/\ndef prod (q\u2081 : path.homotopic.quotient a\u2081 a\u2082) (q\u2082 : path.homotopic.quotient b\u2081 b\u2082) :\n  path.homotopic.quotient (a\u2081, b\u2081) (a\u2082, b\u2082) :=\nquotient.map\u2082 path.prod (\u03bb p\u2081 p\u2081' h\u2081 p\u2082 p\u2082' h\u2082, nonempty.map2 prod_homotopy h\u2081 h\u2082) q\u2081 q\u2082\n\nvariables (p\u2081 p\u2081' p\u2082 p\u2082')\nlemma prod_lift : prod \u27e6p\u2081\u27e7 \u27e6p\u2082\u27e7 = \u27e6p\u2081.prod p\u2082\u27e7 := rfl\n\nvariables (r\u2081 : path.homotopic.quotient a\u2082 a\u2083) (r\u2082 : path.homotopic.quotient b\u2082 b\u2083)\n/-- Products commute with path composition.\n    This is `trans_prod_eq_prod_trans` descended to the quotient.-/\nlemma comp_prod_eq_prod_comp : (prod q\u2081 q\u2082) \u2b1d (prod r\u2081 r\u2082) = prod (q\u2081 \u2b1d r\u2081) (q\u2082 \u2b1d r\u2082) :=\nbegin\n  apply quotient.induction_on\u2082 q\u2081 q\u2082,\n  apply quotient.induction_on\u2082 r\u2081 r\u2082,\n  intros,\n  simp only [prod_lift, \u2190 path.homotopic.comp_lift, path.trans_prod_eq_prod_trans],\nend\n\nvariables {c\u2081 c\u2082 : \u03b1 \u00d7 \u03b2}\n\n/-- Abbreviation for projection onto the left coordinate of a path class -/\n@[reducible]\ndef proj_left (p : path.homotopic.quotient c\u2081 c\u2082) : path.homotopic.quotient c\u2081.1 c\u2082.1 :=\np.map_fn \u27e8_, continuous_fst\u27e9\n\n/-- Abbreviation for projection onto the right coordinate of a path class -/\n@[reducible]\ndef proj_right (p : path.homotopic.quotient c\u2081 c\u2082) : path.homotopic.quotient c\u2081.2 c\u2082.2 :=\np.map_fn \u27e8_, continuous_snd\u27e9\n\n/-- Lemmas showing projection is the inverse of product -/\n@[simp] lemma proj_left_prod : proj_left (prod q\u2081 q\u2082) = q\u2081 :=\nbegin\n  apply quotient.induction_on\u2082 q\u2081 q\u2082,\n  intros p\u2081 p\u2082,\n  unfold proj_left,\n  rw [prod_lift, \u2190 path.homotopic.map_lift],\n  congr, ext, refl,\nend\n\n@[simp] lemma proj_right_prod : proj_right (prod q\u2081 q\u2082) = q\u2082 :=\nbegin\n  apply quotient.induction_on\u2082 q\u2081 q\u2082,\n  intros p\u2081 p\u2082,\n  unfold proj_right,\n  rw [prod_lift, \u2190 path.homotopic.map_lift],\n  congr, ext, refl,\nend\n\n@[simp] lemma prod_proj_left_proj_right (p : path.homotopic.quotient (a\u2081, b\u2081) (a\u2082, b\u2082))\n  : prod (proj_left p) (proj_right p) = p :=\nbegin\n  apply quotient.induction_on p,\n  intro p',\n  unfold proj_left, unfold proj_right,\n  simp only [\u2190 path.homotopic.map_lift, prod_lift],\n  congr, ext; refl,\nend\n\nend prod\n\nend path.homotopic\n\n\nnamespace fundamental_groupoid_functor\n\nopen_locale fundamental_groupoid\n\nuniverses u\n\nsection pi\n\nvariables {I : Type u} (X : I \u2192 Top.{u})\n\n/--\nThe projection map \u03a0 i, X i \u2192 X i induces a map \u03c0(\u03a0 i, X i) \u27f6 \u03c0(X i).\n-/\ndef proj (i : I) : (\u03c0\u2093 (Top.of (\u03a0 i, X i))).\u03b1 \u2964 (\u03c0\u2093 (X i)).\u03b1 := \u03c0\u2098 \u27e8_, continuous_apply i\u27e9\n\n/-- The projection map is precisely path.homotopic.proj interpreted as a functor -/\n@[simp] lemma proj_map (i : I) (x\u2080 x\u2081 : (\u03c0\u2093 (Top.of (\u03a0 i, X i))).\u03b1) (p : x\u2080 \u27f6 x\u2081) :\n  (proj X i).map p = (@path.homotopic.proj _ _ _ _ _ i p) := rfl\n\n/--\nThe map taking the pi product of a family of fundamental groupoids to the fundamental\ngroupoid of the pi product. This is actually an isomorphism (see `pi_iso`)\n-/\n@[simps]\ndef pi_to_pi_Top : (\u03a0 i, (\u03c0\u2093 (X i)).\u03b1) \u2964 (\u03c0\u2093 (Top.of (\u03a0 i, X i))).\u03b1 :=\n{ obj := \u03bb g, g,\n  map := \u03bb v\u2081 v\u2082 p, path.homotopic.pi p,\n  map_id' :=\n  begin\n    intro x,\n    change path.homotopic.pi (\u03bb i, \ud835\udfd9 (x i)) = _,\n    simp only [fundamental_groupoid.id_eq_path_refl, path.homotopic.pi_lift],\n    refl,\n  end,\n  map_comp' := \u03bb x y z f g, (path.homotopic.comp_pi_eq_pi_comp f g).symm, }\n\n/--\nShows `pi_to_pi_Top` is an isomorphism, whose inverse is precisely the pi product\nof the induced projections. This shows that `fundamental_groupoid_functor` preserves products.\n-/\n@[simps]\ndef pi_iso : category_theory.Groupoid.of (\u03a0 i : I, (\u03c0\u2093 (X i)).\u03b1) \u2245 (\u03c0\u2093 (Top.of (\u03a0 i, X i))) :=\n{ hom := pi_to_pi_Top X,\n  inv := category_theory.functor.pi' (proj X),\n  hom_inv_id' :=\n  begin\n    change pi_to_pi_Top X \u22d9 (category_theory.functor.pi' (proj X)) = \ud835\udfed _,\n    apply category_theory.functor.ext; intros,\n    { ext, simp, }, { refl, },\n  end,\n  inv_hom_id' :=\n  begin\n    change (category_theory.functor.pi' (proj X)) \u22d9 pi_to_pi_Top X = \ud835\udfed _,\n    apply category_theory.functor.ext; intros,\n    { suffices : path.homotopic.pi ((category_theory.functor.pi' (proj X)).map f) = f, { simpa, },\n      change (category_theory.functor.pi' (proj X)).map f\n        with \u03bb i, (category_theory.functor.pi' (proj X)).map f i,\n      simp, }, { refl, }\n  end }\n\nsection preserves\nopen category_theory\n\n/-- Equivalence between the categories of cones over the objects `\u03c0 X\u1d62` written in two ways -/\ndef cone_discrete_comp : limits.cone (discrete.functor X \u22d9 \u03c0) \u224c\n  limits.cone (discrete.functor (\u03bb i, \u03c0\u2093 (X i))) :=\nlimits.cones.postcompose_equivalence (discrete.comp_nat_iso_discrete X \u03c0)\n\nlemma cone_discrete_comp_obj_map_cone :\n  (cone_discrete_comp X).functor.obj ((\u03c0).map_cone (Top.pi_fan X))\n  = limits.fan.mk (\u03c0\u2093 (Top.of (\u03a0 i, X i))) (proj X) := rfl\n\n/-- This is `pi_iso.inv` as a cone morphism (in fact, isomorphism) -/\ndef pi_Top_to_pi_cone : (limits.fan.mk (\u03c0\u2093 (Top.of (\u03a0 i, X i))) (proj X)) \u27f6\n  Groupoid.pi_limit_fan (\u03bb i : I, (\u03c0\u2093 (X i))) := { hom := category_theory.functor.pi' (proj X) }\n\ninstance : is_iso (pi_Top_to_pi_cone X) :=\nbegin\n  haveI : is_iso (pi_Top_to_pi_cone X).hom := (infer_instance : is_iso (pi_iso X).inv),\n  exact limits.cones.cone_iso_of_hom_iso (pi_Top_to_pi_cone X),\nend\n\n/-- The fundamental groupoid functor preserves products -/\ndef preserves_product : limits.preserves_limit (discrete.functor X) \u03c0 :=\nbegin\n  apply limits.preserves_limit_of_preserves_limit_cone (Top.pi_fan_is_limit X),\n  apply (limits.is_limit.of_cone_equiv (cone_discrete_comp X)).to_fun,\n  simp only [cone_discrete_comp_obj_map_cone],\n  apply limits.is_limit.of_iso_limit _ (as_iso (pi_Top_to_pi_cone X)).symm,\n  exact (Groupoid.pi_limit_cone _).is_limit,\nend\n\nend preserves\n\nend pi\n\nsection prod\n\nvariables (A B : Top.{u})\n\n/-- The induced map of the left projection map X \u00d7 Y \u2192 X -/\ndef proj_left : (\u03c0\u2093 (Top.of (A \u00d7 B))).\u03b1 \u2964 (\u03c0\u2093 A).\u03b1 := \u03c0\u2098 \u27e8_, continuous_fst\u27e9\n\n/-- The induced map of the right projection map X \u00d7 Y \u2192 Y -/\ndef proj_right : (\u03c0\u2093 (Top.of (A \u00d7 B))).\u03b1 \u2964 (\u03c0\u2093 B).\u03b1 := \u03c0\u2098 \u27e8_, continuous_snd\u27e9\n\n@[simp] lemma proj_left_map (x\u2080 x\u2081 : (\u03c0\u2093 (Top.of (A \u00d7 B))).\u03b1) (p : x\u2080 \u27f6 x\u2081) :\n  (proj_left A B).map p = path.homotopic.proj_left p := rfl\n\n@[simp] lemma proj_right_map (x\u2080 x\u2081 : (\u03c0\u2093 (Top.of (A \u00d7 B))).\u03b1) (p : x\u2080 \u27f6 x\u2081) :\n  (proj_right A B).map p = path.homotopic.proj_right p := rfl\n\n\n/--\nThe map taking the product of two fundamental groupoids to the fundamental groupoid of the product\nof the two topological spaces. This is in fact an isomorphism (see `prod_iso`).\n-/\n@[simps]\ndef prod_to_prod_Top : (\u03c0\u2093 A).\u03b1 \u00d7 (\u03c0\u2093 B).\u03b1 \u2964 (\u03c0\u2093 (Top.of (A \u00d7 B))).\u03b1 :=\n{ obj := \u03bb g, g,\n  map := \u03bb x y p, match x, y, p with\n    | (x\u2080, x\u2081), (y\u2080, y\u2081), (p\u2080, p\u2081) := path.homotopic.prod p\u2080 p\u2081\n  end,\n  map_id' :=\n  begin\n    rintro \u27e8x\u2080, x\u2081\u27e9,\n    simp only [category_theory.prod_id, fundamental_groupoid.id_eq_path_refl],\n    unfold_aux, rw path.homotopic.prod_lift, refl,\n  end,\n  map_comp' := \u03bb x y z f g, match x, y, z, f, g with\n    | (x\u2080, x\u2081), (y\u2080, y\u2081), (z\u2080, z\u2081), (f\u2080, f\u2081), (g\u2080, g\u2081) :=\n    (path.homotopic.comp_prod_eq_prod_comp f\u2080 f\u2081 g\u2080 g\u2081).symm\n  end }\n\n/--\nShows `prod_to_prod_Top` is an isomorphism, whose inverse is precisely the product\nof the induced left and right projections.\n-/\n@[simps]\ndef prod_iso : category_theory.Groupoid.of ((\u03c0\u2093 A).\u03b1 \u00d7 (\u03c0\u2093 B).\u03b1) \u2245 (\u03c0\u2093 (Top.of (A \u00d7 B))) :=\n{ hom := prod_to_prod_Top A B,\n  inv := (proj_left A B).prod' (proj_right A B),\n  hom_inv_id' :=\n  begin\n    change prod_to_prod_Top A B \u22d9 ((proj_left A B).prod' (proj_right A B)) = \ud835\udfed _,\n    apply category_theory.functor.hext, { intros, ext; simp; refl, },\n    rintros \u27e8x\u2080, x\u2081\u27e9 \u27e8y\u2080, y\u2081\u27e9 \u27e8f\u2080, f\u2081\u27e9,\n    have := and.intro (path.homotopic.proj_left_prod f\u2080 f\u2081) (path.homotopic.proj_right_prod f\u2080 f\u2081),\n    simpa,\n  end,\n  inv_hom_id' :=\n  begin\n    change ((proj_left A B).prod' (proj_right A B)) \u22d9 prod_to_prod_Top A B = \ud835\udfed _,\n    apply category_theory.functor.hext, { intros, ext; simp; refl, },\n    rintros \u27e8x\u2080, x\u2081\u27e9 \u27e8y\u2080, y\u2081\u27e9 f,\n    have := path.homotopic.prod_proj_left_proj_right f,\n    simpa,\n  end }\n\nend prod\n\nend fundamental_groupoid_functor\n", "meta": {"author": "Mel-TunaRoll", "repo": "Lean-Mordell-Weil-Mel-Branch", "sha": "4db36f86423976aacd2c2968c4e45787fcd86b97", "save_path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch", "path": "github-repos/lean/Mel-TunaRoll-Lean-Mordell-Weil-Mel-Branch/Lean-Mordell-Weil-Mel-Branch-4db36f86423976aacd2c2968c4e45787fcd86b97/src/topology/homotopy/product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7001173835719148}}
{"text": "/-\nCopyright (c) 2020 Joseph Myers. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joseph Myers\n\n! This file was ported from Lean 3 source module linear_algebra.affine_space.affine_subspace\n! leanprover-community/mathlib commit cb3ceec8485239a61ed51d944cb9a95b68c6bafc\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.LinearAlgebra.AffineSpace.AffineEquiv\n\n/-!\n# Affine spaces\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file defines affine subspaces (over modules) and the affine span of a set of points.\n\n## Main definitions\n\n* `affine_subspace k P` is the type of affine subspaces.  Unlike\n  affine spaces, affine subspaces are allowed to be empty, and lemmas\n  that do not apply to empty affine subspaces have `nonempty`\n  hypotheses.  There is a `complete_lattice` structure on affine\n  subspaces.\n* `affine_subspace.direction` gives the `submodule` spanned by the\n  pairwise differences of points in an `affine_subspace`.  There are\n  various lemmas relating to the set of vectors in the `direction`,\n  and relating the lattice structure on affine subspaces to that on\n  their directions.\n* `affine_subspace.parallel`, notation `\u2225`, gives the property of two affine subspaces being\n  parallel (one being a translate of the other).\n* `affine_span` gives the affine subspace spanned by a set of points,\n  with `vector_span` giving its direction.  `affine_span` is defined\n  in terms of `span_points`, which gives an explicit description of\n  the points contained in the affine span; `span_points` itself should\n  generally only be used when that description is required, with\n  `affine_span` being the main definition for other purposes.  Two\n  other descriptions of the affine span are proved equivalent: it is\n  the `Inf` of affine subspaces containing the points, and (if\n  `[nontrivial k]`) it contains exactly those points that are affine\n  combinations of points in the given set.\n\n## Implementation notes\n\n`out_param` is used in the definiton of `add_torsor V P` to make `V` an implicit argument (deduced\nfrom `P`) in most cases; `include V` is needed in many cases for `V`, and type classes using it, to\nbe added as implicit arguments to individual lemmas.  As for modules, `k` is an explicit argument\nrather than implied by `P` or `V`.\n\nThis file only provides purely algebraic definitions and results.\nThose depending on analysis or topology are defined elsewhere; see\n`analysis.normed_space.add_torsor` and `topology.algebra.affine`.\n\n## References\n\n* https://en.wikipedia.org/wiki/Affine_space\n* https://en.wikipedia.org/wiki/Principal_homogeneous_space\n-/\n\n\nnoncomputable section\n\nopen BigOperators Affine\n\nopen Set\n\nsection\n\nvariable (k : Type _) {V : Type _} {P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n\nvariable [affine_space V P]\n\ninclude V\n\n#print vectorSpan /-\n/-- The submodule spanning the differences of a (possibly empty) set\nof points. -/\ndef vectorSpan (s : Set P) : Submodule k V :=\n  Submodule.span k (s -\u1d65 s)\n#align vector_span vectorSpan\n-/\n\n#print vectorSpan_def /-\n/-- The definition of `vector_span`, for rewriting. -/\ntheorem vectorSpan_def (s : Set P) : vectorSpan k s = Submodule.span k (s -\u1d65 s) :=\n  rfl\n#align vector_span_def vectorSpan_def\n-/\n\n/- warning: vector_span_mono -> vectorSpan_mono is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, (HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) s\u2081 s\u2082) -> (LE.le.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nbut is expected to have type\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, (HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) s\u2081 s\u2082) -> (LE.le.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (OmegaCompletePartialOrder.toPartialOrder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.instOmegaCompletePartialOrder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nCase conversion may be inaccurate. Consider using '#align vector_span_mono vectorSpan_mono\u2093'. -/\n/-- `vector_span` is monotone. -/\ntheorem vectorSpan_mono {s\u2081 s\u2082 : Set P} (h : s\u2081 \u2286 s\u2082) : vectorSpan k s\u2081 \u2264 vectorSpan k s\u2082 :=\n  Submodule.span_mono (vsub_self_mono h)\n#align vector_span_mono vectorSpan_mono\n\nvariable (P)\n\n/- warning: vector_span_empty -> vectorSpan_empty is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P))) (Bot.bot.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasBot.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} (P : Type.{u1}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)], Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (EmptyCollection.emptyCollection.{u1} (Set.{u1} P) (Set.instEmptyCollectionSet.{u1} P))) (Bot.bot.{u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (Submodule.instBotSubmodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))\nCase conversion may be inaccurate. Consider using '#align vector_span_empty vectorSpan_empty\u2093'. -/\n/-- The `vector_span` of the empty set is `\u22a5`. -/\n@[simp]\ntheorem vectorSpan_empty : vectorSpan k (\u2205 : Set P) = (\u22a5 : Submodule k V) := by\n  rw [vectorSpan_def, vsub_empty, Submodule.span_empty]\n#align vector_span_empty vectorSpan_empty\n\nvariable {P}\n\n/- warning: vector_span_singleton -> vectorSpan_singleton is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p)) (Bot.bot.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasBot.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] (p : P), Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p)) (Bot.bot.{u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (Submodule.instBotSubmodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))\nCase conversion may be inaccurate. Consider using '#align vector_span_singleton vectorSpan_singleton\u2093'. -/\n/-- The `vector_span` of a single point is `\u22a5`. -/\n@[simp]\ntheorem vectorSpan_singleton (p : P) : vectorSpan k ({p} : Set P) = \u22a5 := by simp [vectorSpan_def]\n#align vector_span_singleton vectorSpan_singleton\n\n#print vsub_set_subset_vectorSpan /-\n/-- The `s -\u1d65 s` lies within the `vector_span k s`. -/\ntheorem vsub_set_subset_vectorSpan (s : Set P) : s -\u1d65 s \u2286 \u2191(vectorSpan k s) :=\n  Submodule.subset_span\n#align vsub_set_subset_vector_span vsub_set_subset_vectorSpan\n-/\n\n#print vsub_mem_vectorSpan /-\n/-- Each pairwise difference is in the `vector_span`. -/\ntheorem vsub_mem_vectorSpan {s : Set P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n    p1 -\u1d65 p2 \u2208 vectorSpan k s :=\n  vsub_set_subset_vectorSpan k s (vsub_mem_vsub hp1 hp2)\n#align vsub_mem_vector_span vsub_mem_vectorSpan\n-/\n\n#print spanPoints /-\n/-- The points in the affine span of a (possibly empty) set of\npoints. Use `affine_span` instead to get an `affine_subspace k P`. -/\ndef spanPoints (s : Set P) : Set P :=\n  { p | \u2203 p1 \u2208 s, \u2203 v \u2208 vectorSpan k s, p = v +\u1d65 p1 }\n#align span_points spanPoints\n-/\n\n/- warning: mem_span_points -> mem_spanPoints is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (s : Set.{u3} P), (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p s) -> (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (p : P) (s : Set.{u3} P), (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p s) -> (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align mem_span_points mem_spanPoints\u2093'. -/\n/-- A point in a set is in its affine span. -/\ntheorem mem_spanPoints (p : P) (s : Set P) : p \u2208 s \u2192 p \u2208 spanPoints k s\n  | hp => \u27e8p, hp, 0, Submodule.zero_mem _, (zero_vadd V p).symm\u27e9\n#align mem_span_points mem_spanPoints\n\n/- warning: subset_span_points -> subset_spanPoints is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : Set.{u3} P), HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) s (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (s : Set.{u3} P), HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) s (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)\nCase conversion may be inaccurate. Consider using '#align subset_span_points subset_spanPoints\u2093'. -/\n/-- A set is contained in its `span_points`. -/\ntheorem subset_spanPoints (s : Set P) : s \u2286 spanPoints k s := fun p => mem_spanPoints k p s\n#align subset_span_points subset_spanPoints\n\n/- warning: span_points_nonempty -> spanPoints_nonempty is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : Set.{u3} P), Iff (Set.Nonempty.{u3} P (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.Nonempty.{u3} P s)\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (s : Set.{u3} P), Iff (Set.Nonempty.{u3} P (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.Nonempty.{u3} P s)\nCase conversion may be inaccurate. Consider using '#align span_points_nonempty spanPoints_nonempty\u2093'. -/\n/-- The `span_points` of a set is nonempty if and only if that set\nis. -/\n@[simp]\ntheorem spanPoints_nonempty (s : Set P) : (spanPoints k s).Nonempty \u2194 s.Nonempty :=\n  by\n  constructor\n  \u00b7 contrapose\n    rw [Set.not_nonempty_iff_eq_empty, Set.not_nonempty_iff_eq_empty]\n    intro h\n    simp [h, spanPoints]\n  \u00b7 exact fun h => h.mono (subset_spanPoints _ _)\n#align span_points_nonempty spanPoints_nonempty\n\n/- warning: vadd_mem_span_points_of_mem_span_points_of_mem_vector_span -> vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {p : P} {v : V}, (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p) (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P} {p : P} {v : V}, (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.mem.{u1, u1} V (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (SetLike.instMembership.{u1, u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)) v (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) (HVAdd.hVAdd.{u1, u3, u3} V P P (instHVAdd.{u1, u3} V P (AddAction.toVAdd.{u1, u3} V P (SubNegMonoid.toAddMonoid.{u1} V (AddGroup.toSubNegMonoid.{u1} V (AddCommGroup.toAddGroup.{u1} V _inst_2))) (AddTorsor.toAddAction.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4))) v p) (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align vadd_mem_span_points_of_mem_span_points_of_mem_vector_span vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan\u2093'. -/\n/-- Adding a point in the affine span and a vector in the spanning\nsubmodule produces a point in the affine span. -/\ntheorem vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan {s : Set P} {p : P} {v : V}\n    (hp : p \u2208 spanPoints k s) (hv : v \u2208 vectorSpan k s) : v +\u1d65 p \u2208 spanPoints k s :=\n  by\n  rcases hp with \u27e8p2, \u27e8hp2, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9\n  rw [hv2p, vadd_vadd]\n  use p2, hp2, v + v2, (vectorSpan k s).add_mem hv hv2, rfl\n#align vadd_mem_span_points_of_mem_span_points_of_mem_vector_span vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan\n\n/- warning: vsub_mem_vector_span_of_mem_span_points_of_mem_span_points -> vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {p1 : P} {p2 : P}, (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p1 (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p2 (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p1 p2) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P} {p1 : P} {p2 : P}, (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p1 (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p2 (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (Membership.mem.{u1, u1} V (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (SetLike.instMembership.{u1, u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)) (VSub.vsub.{u1, u3} V P (AddTorsor.toVSub.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4) p1 p2) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align vsub_mem_vector_span_of_mem_span_points_of_mem_span_points vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints\u2093'. -/\n/-- Subtracting two points in the affine span produces a vector in the\nspanning submodule. -/\ntheorem vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints {s : Set P} {p1 p2 : P}\n    (hp1 : p1 \u2208 spanPoints k s) (hp2 : p2 \u2208 spanPoints k s) : p1 -\u1d65 p2 \u2208 vectorSpan k s :=\n  by\n  rcases hp1 with \u27e8p1a, \u27e8hp1a, \u27e8v1, \u27e8hv1, hv1p\u27e9\u27e9\u27e9\u27e9\n  rcases hp2 with \u27e8p2a, \u27e8hp2a, \u27e8v2, \u27e8hv2, hv2p\u27e9\u27e9\u27e9\u27e9\n  rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +\u1d65 p1a), vadd_vsub_assoc, add_comm, add_sub_assoc]\n  have hv1v2 : v1 - v2 \u2208 vectorSpan k s :=\n    by\n    rw [sub_eq_add_neg]\n    apply (vectorSpan k s).add_mem hv1\n    rw [\u2190 neg_one_smul k v2]\n    exact (vectorSpan k s).smul_mem (-1 : k) hv2\n  refine' (vectorSpan k s).add_mem _ hv1v2\n  exact vsub_mem_vectorSpan k hp1a hp2a\n#align vsub_mem_vector_span_of_mem_span_points_of_mem_span_points vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints\n\nend\n\n#print AffineSubspace /-\n/-- An `affine_subspace k P` is a subset of an `affine_space V P`\nthat, if not empty, has an affine space structure induced by a\ncorresponding subspace of the `module k V`. -/\nstructure AffineSubspace (k : Type _) {V : Type _} (P : Type _) [Ring k] [AddCommGroup V]\n  [Module k V] [affine_space V P] where\n  carrier : Set P\n  smul_vsub_vadd_mem :\n    \u2200 (c : k) {p1 p2 p3 : P},\n      p1 \u2208 carrier \u2192 p2 \u2208 carrier \u2192 p3 \u2208 carrier \u2192 c \u2022 (p1 -\u1d65 p2 : V) +\u1d65 p3 \u2208 carrier\n#align affine_subspace AffineSubspace\n-/\n\nnamespace Submodule\n\nvariable {k V : Type _} [Ring k] [AddCommGroup V] [Module k V]\n\n#print Submodule.toAffineSubspace /-\n/-- Reinterpret `p : submodule k V` as an `affine_subspace k V`. -/\ndef toAffineSubspace (p : Submodule k V) : AffineSubspace k V\n    where\n  carrier := p\n  smul_vsub_vadd_mem c p\u2081 p\u2082 p\u2083 h\u2081 h\u2082 h\u2083 := p.add_mem (p.smul_mem _ (p.sub_mem h\u2081 h\u2082)) h\u2083\n#align submodule.to_affine_subspace Submodule.toAffineSubspace\n-/\n\nend Submodule\n\nnamespace AffineSubspace\n\nvariable (k : Type _) {V : Type _} (P : Type _) [Ring k] [AddCommGroup V] [Module k V]\n  [affine_space V P]\n\ninclude V\n\ninstance : SetLike (AffineSubspace k P) P\n    where\n  coe := carrier\n  coe_injective' p q _ := by cases p <;> cases q <;> congr\n\n/- warning: affine_subspace.mem_coe -> AffineSubspace.mem_coe is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4), Iff (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)) (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s)\nbut is expected to have type\n  forall (k : Type.{u3}) {V : Type.{u2}} (P : Type.{u1}) [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4), Iff (Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) p (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_coe AffineSubspace.mem_coe\u2093'. -/\n/-- A point is in an affine subspace coerced to a set if and only if\nit is in that affine subspace. -/\n@[simp]\ntheorem mem_coe (p : P) (s : AffineSubspace k P) : p \u2208 (s : Set P) \u2194 p \u2208 s :=\n  Iff.rfl\n#align affine_subspace.mem_coe AffineSubspace.mem_coe\n\nvariable {k P}\n\n#print AffineSubspace.direction /-\n/-- The direction of an affine subspace is the submodule spanned by\nthe pairwise differences of points.  (Except in the case of an empty\naffine subspace, where the direction is the zero submodule, every\nvector in the direction is the difference of two points in the affine\nsubspace.) -/\ndef direction (s : AffineSubspace k P) : Submodule k V :=\n  vectorSpan k (s : Set P)\n#align affine_subspace.direction AffineSubspace.direction\n-/\n\n/- warning: affine_subspace.direction_eq_vector_span -> AffineSubspace.direction_eq_vectorSpan is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (vectorSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_eq_vector_span AffineSubspace.direction_eq_vectorSpan\u2093'. -/\n/-- The direction equals the `vector_span`. -/\ntheorem direction_eq_vectorSpan (s : AffineSubspace k P) : s.direction = vectorSpan k (s : Set P) :=\n  rfl\n#align affine_subspace.direction_eq_vector_span AffineSubspace.direction_eq_vectorSpan\n\n#print AffineSubspace.directionOfNonempty /-\n/-- Alternative definition of the direction when the affine subspace\nis nonempty.  This is defined so that the order on submodules (as used\nin the definition of `submodule.span`) can be used in the proof of\n`coe_direction_eq_vsub_set`, and is not intended to be used beyond\nthat proof. -/\ndef directionOfNonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : Submodule k V\n    where\n  carrier := (s : Set P) -\u1d65 s\n  zero_mem' := by\n    cases' h with p hp\n    exact vsub_self p \u25b8 vsub_mem_vsub hp hp\n  add_mem' := by\n    intro a b ha hb\n    rcases ha with \u27e8p1, p2, hp1, hp2, rfl\u27e9\n    rcases hb with \u27e8p3, p4, hp3, hp4, rfl\u27e9\n    rw [\u2190 vadd_vsub_assoc]\n    refine' vsub_mem_vsub _ hp4\n    convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3\n    rw [one_smul]\n  smul_mem' := by\n    intro c v hv\n    rcases hv with \u27e8p1, p2, hp1, hp2, rfl\u27e9\n    rw [\u2190 vadd_vsub (c \u2022 (p1 -\u1d65 p2)) p2]\n    refine' vsub_mem_vsub _ hp2\n    exact s.smul_vsub_vadd_mem c hp1 hp2 hp2\n#align affine_subspace.direction_of_nonempty AffineSubspace.directionOfNonempty\n-/\n\n/- warning: affine_subspace.direction_of_nonempty_eq_direction -> AffineSubspace.directionOfNonempty_eq_direction is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} (h : Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.directionOfNonempty.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s h) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} (h : Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)), Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.directionOfNonempty.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s h) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_of_nonempty_eq_direction AffineSubspace.directionOfNonempty_eq_direction\u2093'. -/\n/-- `direction_of_nonempty` gives the same submodule as\n`direction`. -/\ntheorem directionOfNonempty_eq_direction {s : AffineSubspace k P} (h : (s : Set P).Nonempty) :\n    directionOfNonempty h = s.direction :=\n  le_antisymm (vsub_set_subset_vectorSpan k s) (Submodule.span_le.2 Set.Subset.rfl)\n#align affine_subspace.direction_of_nonempty_eq_direction AffineSubspace.directionOfNonempty_eq_direction\n\n/- warning: affine_subspace.coe_direction_eq_vsub_set -> AffineSubspace.coe_direction_eq_vsub_set is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)) -> (Eq.{succ u2} (Set.{u2} V) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (HasLiftT.mk.{succ u2, succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (CoeTC\u2093.coe.{succ u2, succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (SetLike.Set.hasCoeT.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (VSub.vsub.{u2, u3} (Set.{u2} V) (Set.{u3} P) (Set.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) -> (Eq.{succ u2} (Set.{u2} V) (SetLike.coe.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (VSub.vsub.{u2, u1} (Set.{u2} V) (Set.{u1} P) (Set.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_direction_eq_vsub_set AffineSubspace.coe_direction_eq_vsub_set\u2093'. -/\n/-- The set of vectors in the direction of a nonempty affine subspace\nis given by `vsub_set`. -/\ntheorem coe_direction_eq_vsub_set {s : AffineSubspace k P} (h : (s : Set P).Nonempty) :\n    (s.direction : Set V) = (s : Set P) -\u1d65 s :=\n  directionOfNonempty_eq_direction h \u25b8 rfl\n#align affine_subspace.coe_direction_eq_vsub_set AffineSubspace.coe_direction_eq_vsub_set\n\n/- warning: affine_subspace.mem_direction_iff_eq_vsub -> AffineSubspace.mem_direction_iff_eq_vsub is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)) -> (forall (v : V), Iff (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Exists.{succ u3} P (fun (p1 : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) (fun (H : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) => Exists.{succ u3} P (fun (p2 : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) (fun (H : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) => Eq.{succ u2} V v (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p1 p2)))))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) -> (forall (v : V), Iff (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Exists.{succ u1} P (fun (p1 : P) => And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) (Exists.{succ u1} P (fun (p2 : P) => And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) (Eq.{succ u2} V v (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p1 p2)))))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_direction_iff_eq_vsub AffineSubspace.mem_direction_iff_eq_vsub\u2093'. -/\n/-- A vector is in the direction of a nonempty affine subspace if and\nonly if it is the subtraction of two vectors in the subspace. -/\ntheorem mem_direction_iff_eq_vsub {s : AffineSubspace k P} (h : (s : Set P).Nonempty) (v : V) :\n    v \u2208 s.direction \u2194 \u2203 p1 \u2208 s, \u2203 p2 \u2208 s, v = p1 -\u1d65 p2 :=\n  by\n  rw [\u2190 SetLike.mem_coe, coe_direction_eq_vsub_set h]\n  exact\n    \u27e8fun \u27e8p1, p2, hp1, hp2, hv\u27e9 => \u27e8p1, hp1, p2, hp2, hv.symm\u27e9, fun \u27e8p1, hp1, p2, hp2, hv\u27e9 =>\n      \u27e8p1, p2, hp1, hp2, hv.symm\u27e9\u27e9\n#align affine_subspace.mem_direction_iff_eq_vsub AffineSubspace.mem_direction_iff_eq_vsub\n\n/- warning: affine_subspace.vadd_mem_of_mem_direction -> AffineSubspace.vadd_mem_of_mem_direction is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {v : V}, (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (forall {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p) s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {v : V}, (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (forall {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u2, u1, u1} V P P (instHVAdd.{u2, u1} V P (AddAction.toVAdd.{u2, u1} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4))) v p) s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vadd_mem_of_mem_direction AffineSubspace.vadd_mem_of_mem_direction\u2093'. -/\n/-- Adding a vector in the direction to a point in the subspace\nproduces a point in the subspace. -/\ntheorem vadd_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v \u2208 s.direction) {p : P}\n    (hp : p \u2208 s) : v +\u1d65 p \u2208 s :=\n  by\n  rw [mem_direction_iff_eq_vsub \u27e8p, hp\u27e9] at hv\n  rcases hv with \u27e8p1, hp1, p2, hp2, hv\u27e9\n  rw [hv]\n  convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp\n  rw [one_smul]\n#align affine_subspace.vadd_mem_of_mem_direction AffineSubspace.vadd_mem_of_mem_direction\n\n/- warning: affine_subspace.vsub_mem_direction -> AffineSubspace.vsub_mem_direction is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P} {p2 : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) -> (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p1 p2) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P} {p2 : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) -> (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p1 p2) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vsub_mem_direction AffineSubspace.vsub_mem_direction\u2093'. -/\n/-- Subtracting two points in the subspace produces a vector in the\ndirection. -/\ntheorem vsub_mem_direction {s : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) (hp2 : p2 \u2208 s) :\n    p1 -\u1d65 p2 \u2208 s.direction :=\n  vsub_mem_vectorSpan k hp1 hp2\n#align affine_subspace.vsub_mem_direction AffineSubspace.vsub_mem_direction\n\n/- warning: affine_subspace.vadd_mem_iff_mem_direction -> AffineSubspace.vadd_mem_iff_mem_direction is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} (v : V) {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p) s) (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} (v : V) {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Iff (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u2, u1, u1} V P P (instHVAdd.{u2, u1} V P (AddAction.toVAdd.{u2, u1} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4))) v p) s) (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vadd_mem_iff_mem_direction AffineSubspace.vadd_mem_iff_mem_direction\u2093'. -/\n/-- Adding a vector to a point in a subspace produces a point in the\nsubspace if and only if the vector is in the direction. -/\ntheorem vadd_mem_iff_mem_direction {s : AffineSubspace k P} (v : V) {p : P} (hp : p \u2208 s) :\n    v +\u1d65 p \u2208 s \u2194 v \u2208 s.direction :=\n  \u27e8fun h => by simpa using vsub_mem_direction h hp, fun h => vadd_mem_of_mem_direction h hp\u27e9\n#align affine_subspace.vadd_mem_iff_mem_direction AffineSubspace.vadd_mem_iff_mem_direction\n\n/- warning: affine_subspace.vadd_mem_iff_mem_of_mem_direction -> AffineSubspace.vadd_mem_iff_mem_of_mem_direction is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {v : V}, (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (forall {p : P}, Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p) s) (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {v : V}, (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (forall {p : P}, Iff (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u2, u1, u1} V P P (instHVAdd.{u2, u1} V P (AddAction.toVAdd.{u2, u1} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4))) v p) s) (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vadd_mem_iff_mem_of_mem_direction AffineSubspace.vadd_mem_iff_mem_of_mem_direction\u2093'. -/\n/-- Adding a vector in the direction to a point produces a point in the subspace if and only if\nthe original point is in the subspace. -/\ntheorem vadd_mem_iff_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v \u2208 s.direction)\n    {p : P} : v +\u1d65 p \u2208 s \u2194 p \u2208 s :=\n  by\n  refine' \u27e8fun h => _, fun h => vadd_mem_of_mem_direction hv h\u27e9\n  convert vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) h\n  simp\n#align affine_subspace.vadd_mem_iff_mem_of_mem_direction AffineSubspace.vadd_mem_iff_mem_of_mem_direction\n\n/- warning: affine_subspace.coe_direction_eq_vsub_set_right -> AffineSubspace.coe_direction_eq_vsub_set_right is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Eq.{succ u2} (Set.{u2} V) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (HasLiftT.mk.{succ u2, succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (CoeTC\u2093.coe.{succ u2, succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (SetLike.Set.hasCoeT.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.image.{u3, u2} P V (fun (_x : P) => VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) _x p) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Eq.{succ u2} (Set.{u2} V) (SetLike.coe.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.image.{u1, u2} P V (fun (_x : P) => VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) _x p) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_direction_eq_vsub_set_right AffineSubspace.coe_direction_eq_vsub_set_right\u2093'. -/\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nright. -/\ntheorem coe_direction_eq_vsub_set_right {s : AffineSubspace k P} {p : P} (hp : p \u2208 s) :\n    (s.direction : Set V) = (\u00b7 -\u1d65 p) '' s :=\n  by\n  rw [coe_direction_eq_vsub_set \u27e8p, hp\u27e9]\n  refine' le_antisymm _ _\n  \u00b7 rintro v \u27e8p1, p2, hp1, hp2, rfl\u27e9\n    exact \u27e8p1 -\u1d65 p2 +\u1d65 p, vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp, vadd_vsub _ _\u27e9\n  \u00b7 rintro v \u27e8p2, hp2, rfl\u27e9\n    exact \u27e8p2, p, hp2, hp, rfl\u27e9\n#align affine_subspace.coe_direction_eq_vsub_set_right AffineSubspace.coe_direction_eq_vsub_set_right\n\n/- warning: affine_subspace.coe_direction_eq_vsub_set_left -> AffineSubspace.coe_direction_eq_vsub_set_left is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Eq.{succ u2} (Set.{u2} V) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (HasLiftT.mk.{succ u2, succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (CoeTC\u2093.coe.{succ u2, succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Set.{u2} V) (SetLike.Set.hasCoeT.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.image.{u3, u2} P V (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Eq.{succ u2} (Set.{u2} V) (SetLike.coe.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.image.{u1, u2} P V ((fun (x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.2822 : P) (x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.2824 : P) => VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.2822 x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.2824) p) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_direction_eq_vsub_set_left AffineSubspace.coe_direction_eq_vsub_set_left\u2093'. -/\n/-- Given a point in an affine subspace, the set of vectors in its\ndirection equals the set of vectors subtracting that point on the\nleft. -/\ntheorem coe_direction_eq_vsub_set_left {s : AffineSubspace k P} {p : P} (hp : p \u2208 s) :\n    (s.direction : Set V) = (\u00b7 -\u1d65 \u00b7) p '' s := by\n  ext v\n  rw [SetLike.mem_coe, \u2190 Submodule.neg_mem_iff, \u2190 SetLike.mem_coe,\n    coe_direction_eq_vsub_set_right hp, Set.mem_image_iff_bex, Set.mem_image_iff_bex]\n  conv_lhs =>\n    congr\n    ext\n    rw [\u2190 neg_vsub_eq_vsub_rev, neg_inj]\n#align affine_subspace.coe_direction_eq_vsub_set_left AffineSubspace.coe_direction_eq_vsub_set_left\n\n/- warning: affine_subspace.mem_direction_iff_eq_vsub_right -> AffineSubspace.mem_direction_iff_eq_vsub_right is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (v : V), Iff (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Exists.{succ u3} P (fun (p2 : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) (fun (H : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) => Eq.{succ u2} V v (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p)))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (v : V), Iff (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Exists.{succ u1} P (fun (p2 : P) => And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) (Eq.{succ u2} V v (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p)))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_direction_iff_eq_vsub_right AffineSubspace.mem_direction_iff_eq_vsub_right\u2093'. -/\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the right. -/\ntheorem mem_direction_iff_eq_vsub_right {s : AffineSubspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n    v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p2 -\u1d65 p :=\n  by\n  rw [\u2190 SetLike.mem_coe, coe_direction_eq_vsub_set_right hp]\n  exact \u27e8fun \u27e8p2, hp2, hv\u27e9 => \u27e8p2, hp2, hv.symm\u27e9, fun \u27e8p2, hp2, hv\u27e9 => \u27e8p2, hp2, hv.symm\u27e9\u27e9\n#align affine_subspace.mem_direction_iff_eq_vsub_right AffineSubspace.mem_direction_iff_eq_vsub_right\n\n/- warning: affine_subspace.mem_direction_iff_eq_vsub_left -> AffineSubspace.mem_direction_iff_eq_vsub_left is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (v : V), Iff (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Exists.{succ u3} P (fun (p2 : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) (fun (H : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) => Eq.{succ u2} V v (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p p2)))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (v : V), Iff (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Exists.{succ u1} P (fun (p2 : P) => And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s) (Eq.{succ u2} V v (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p p2)))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_direction_iff_eq_vsub_left AffineSubspace.mem_direction_iff_eq_vsub_left\u2093'. -/\n/-- Given a point in an affine subspace, a vector is in its direction\nif and only if it results from subtracting that point on the left. -/\ntheorem mem_direction_iff_eq_vsub_left {s : AffineSubspace k P} {p : P} (hp : p \u2208 s) (v : V) :\n    v \u2208 s.direction \u2194 \u2203 p2 \u2208 s, v = p -\u1d65 p2 :=\n  by\n  rw [\u2190 SetLike.mem_coe, coe_direction_eq_vsub_set_left hp]\n  exact \u27e8fun \u27e8p2, hp2, hv\u27e9 => \u27e8p2, hp2, hv.symm\u27e9, fun \u27e8p2, hp2, hv\u27e9 => \u27e8p2, hp2, hv.symm\u27e9\u27e9\n#align affine_subspace.mem_direction_iff_eq_vsub_left AffineSubspace.mem_direction_iff_eq_vsub_left\n\n/- warning: affine_subspace.vsub_right_mem_direction_iff_mem -> AffineSubspace.vsub_right_mem_direction_iff_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (p2 : P), Iff (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (p2 : P), Iff (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vsub_right_mem_direction_iff_mem AffineSubspace.vsub_right_mem_direction_iff_mem\u2093'. -/\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the right is in the direction if and only if the other point\nis in the subspace. -/\ntheorem vsub_right_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n    p2 -\u1d65 p \u2208 s.direction \u2194 p2 \u2208 s :=\n  by\n  rw [mem_direction_iff_eq_vsub_right hp]\n  simp\n#align affine_subspace.vsub_right_mem_direction_iff_mem AffineSubspace.vsub_right_mem_direction_iff_mem\n\n/- warning: affine_subspace.vsub_left_mem_direction_iff_mem -> AffineSubspace.vsub_left_mem_direction_iff_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (p2 : P), Iff (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p p2) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (forall (p2 : P), Iff (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p p2) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vsub_left_mem_direction_iff_mem AffineSubspace.vsub_left_mem_direction_iff_mem\u2093'. -/\n/-- Given a point in an affine subspace, a result of subtracting that\npoint on the left is in the direction if and only if the other point\nis in the subspace. -/\ntheorem vsub_left_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p \u2208 s) (p2 : P) :\n    p -\u1d65 p2 \u2208 s.direction \u2194 p2 \u2208 s :=\n  by\n  rw [mem_direction_iff_eq_vsub_left hp]\n  simp\n#align affine_subspace.vsub_left_mem_direction_iff_mem AffineSubspace.vsub_left_mem_direction_iff_mem\n\n/- warning: affine_subspace.coe_injective -> AffineSubspace.coe_injective is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Function.Injective.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)], Function.Injective.{succ u3, succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_injective AffineSubspace.coe_injective\u2093'. -/\n/-- Two affine subspaces are equal if they have the same points. -/\ntheorem coe_injective : Function.Injective (coe : AffineSubspace k P \u2192 Set P) :=\n  SetLike.coe_injective\n#align affine_subspace.coe_injective AffineSubspace.coe_injective\n\n/- warning: affine_subspace.ext -> AffineSubspace.ext is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {q : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (forall (x : P), Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x p) (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x q)) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) p q)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {q : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (forall (x : P), Iff (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x p) (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x q)) -> (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) p q)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.ext AffineSubspace.ext\u2093'. -/\n@[ext]\ntheorem ext {p q : AffineSubspace k P} (h : \u2200 x, x \u2208 p \u2194 x \u2208 q) : p = q :=\n  SetLike.ext h\n#align affine_subspace.ext AffineSubspace.ext\n\n/- warning: affine_subspace.ext_iff -> AffineSubspace.ext_iff is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4), Iff (Eq.{succ u3} (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s\u2081) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s\u2082)) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2081 s\u2082)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4), Iff (Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2081) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2082)) (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2081 s\u2082)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.ext_iff AffineSubspace.ext_iff\u2093'. -/\n@[simp]\ntheorem ext_iff (s\u2081 s\u2082 : AffineSubspace k P) : (s\u2081 : Set P) = s\u2082 \u2194 s\u2081 = s\u2082 :=\n  SetLike.ext'_iff.symm\n#align affine_subspace.ext_iff AffineSubspace.ext_iff\n\n/- warning: affine_subspace.ext_of_direction_eq -> AffineSubspace.ext_of_direction_eq is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s2)) -> (Set.Nonempty.{u3} P (Inter.inter.{u3} (Set.{u3} P) (Set.hasInter.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s2))) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s1 s2)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s2)) -> (Set.Nonempty.{u1} P (Inter.inter.{u1} (Set.{u1} P) (Set.instInterSet.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s2))) -> (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s1 s2)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.ext_of_direction_eq AffineSubspace.ext_of_direction_eq\u2093'. -/\n/-- Two affine subspaces with the same direction and nonempty\nintersection are equal. -/\ntheorem ext_of_direction_eq {s1 s2 : AffineSubspace k P} (hd : s1.direction = s2.direction)\n    (hn : ((s1 : Set P) \u2229 s2).Nonempty) : s1 = s2 :=\n  by\n  ext p\n  have hq1 := Set.mem_of_mem_inter_left hn.some_mem\n  have hq2 := Set.mem_of_mem_inter_right hn.some_mem\n  constructor\n  \u00b7 intro hp\n    rw [\u2190 vsub_vadd p hn.some]\n    refine' vadd_mem_of_mem_direction _ hq2\n    rw [\u2190 hd]\n    exact vsub_mem_direction hp hq1\n  \u00b7 intro hp\n    rw [\u2190 vsub_vadd p hn.some]\n    refine' vadd_mem_of_mem_direction _ hq1\n    rw [hd]\n    exact vsub_mem_direction hp hq2\n#align affine_subspace.ext_of_direction_eq AffineSubspace.ext_of_direction_eq\n\n#print AffineSubspace.toAddTorsor /-\n-- See note [reducible non instances]\n/-- This is not an instance because it loops with `add_torsor.nonempty`. -/\n@[reducible]\ndef toAddTorsor (s : AffineSubspace k P) [Nonempty s] : AddTorsor s.direction s\n    where\n  vadd a b := \u27e8(a : V) +\u1d65 (b : P), vadd_mem_of_mem_direction a.2 b.2\u27e9\n  zero_vadd := by simp\n  add_vadd a b c := by\n    ext\n    apply add_vadd\n  vsub a b := \u27e8(a : P) -\u1d65 (b : P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2\u27e9\n  Nonempty := by infer_instance\n  vsub_vadd' a b := by\n    ext\n    apply AddTorsor.vsub_vadd'\n  vadd_vsub' a b := by\n    ext\n    apply AddTorsor.vadd_vsub'\n#align affine_subspace.to_add_torsor AffineSubspace.toAddTorsor\n-/\n\nattribute [local instance] to_add_torsor\n\n/- warning: affine_subspace.coe_vsub -> AffineSubspace.coe_vsub is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s)] (a : coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) (b : coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s), Eq.{succ u2} V ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (CoeTC\u2093.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (coeSubtype.{succ u2} V (fun (x : V) => Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))))) (VSub.vsub.{u2, u3} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) (AddTorsor.toHasVsub.{u2, u3} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) (AddCommGroup.toAddGroup.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)) a b)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeSubtype.{succ u3} P (fun (x : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))))) a) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeSubtype.{succ u3} P (fun (x : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))))) b))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u1} (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))] (a : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (b : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)), Eq.{succ u2} V (Subtype.val.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Set.{u2} V) (Set.instMembershipSet.{u2} V) x (SetLike.coe.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (VSub.vsub.{u2, u1} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (AddTorsor.toVSub.{u2, u1} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (AddCommGroup.toAddGroup.{u2} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)) a b)) (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) (Subtype.val.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) x (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) a) (Subtype.val.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) x (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) b))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_vsub AffineSubspace.coe_vsub\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_vsub (s : AffineSubspace k P) [Nonempty s] (a b : s) : \u2191(a -\u1d65 b) = (a : P) -\u1d65 (b : P) :=\n  rfl\n#align affine_subspace.coe_vsub AffineSubspace.coe_vsub\n\n/- warning: affine_subspace.coe_vadd -> AffineSubspace.coe_vadd is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s)] (a : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (b : coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s), Eq.{succ u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeSubtype.{succ u3} P (fun (x : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))))) (VAdd.vadd.{u2, u3} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) (AddAction.toHasVadd.{u2, u3} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) (SubNegMonoid.toAddMonoid.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AddGroup.toSubNegMonoid.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AddCommGroup.toAddGroup.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))))) (AddTorsor.toAddAction.{u2, u3} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) (AddCommGroup.toAddGroup.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5))) a b)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (CoeTC\u2093.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (coeSubtype.{succ u2} V (fun (x : V) => Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))))) a) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeSubtype.{succ u3} P (fun (x : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))))) b))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u1} (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))] (a : Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (b : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)), Eq.{succ u1} P (Subtype.val.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) x (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) (HVAdd.hVAdd.{u2, u1, u1} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (instHVAdd.{u2, u1} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (AddAction.toVAdd.{u2, u1} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (AddSubmonoid.toAddMonoid.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)) (Submodule.toAddSubmonoid.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (AddTorsor.toAddAction.{u2, u1} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (AddCommGroup.toAddGroup.{u2} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)))) a b)) (HVAdd.hVAdd.{u2, u1, u1} V P P (instHVAdd.{u2, u1} V P (AddAction.toVAdd.{u2, u1} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4))) (Subtype.val.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Set.{u2} V) (Set.instMembershipSet.{u2} V) x (SetLike.coe.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) a) (Subtype.val.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) x (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) b))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_vadd AffineSubspace.coe_vadd\u2093'. -/\n@[simp, norm_cast]\ntheorem coe_vadd (s : AffineSubspace k P) [Nonempty s] (a : s.direction) (b : s) :\n    \u2191(a +\u1d65 b) = (a : V) +\u1d65 (b : P) :=\n  rfl\n#align affine_subspace.coe_vadd AffineSubspace.coe_vadd\n\n#print AffineSubspace.subtype /-\n/-- Embedding of an affine subspace to the ambient space, as an affine map. -/\nprotected def subtype (s : AffineSubspace k P) [Nonempty s] : s \u2192\u1d43[k] P\n    where\n  toFun := coe\n  linear := s.direction.Subtype\n  map_vadd' p v := rfl\n#align affine_subspace.subtype AffineSubspace.subtype\n-/\n\n/- warning: affine_subspace.subtype_linear -> AffineSubspace.subtype_linear is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s)], Eq.{succ u2} (LinearMap.{u1, u1, u2, u2} k k (Ring.toSemiring.{u1} k _inst_1) (Ring.toSemiring.{u1} k _inst_1) (RingHom.id.{u1} k (Semiring.toNonAssocSemiring.{u1} k (Ring.toSemiring.{u1} k _inst_1))) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) V (AddCommGroup.toAddCommMonoid.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) _inst_3) (AffineMap.linear.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4 (AffineSubspace.subtype.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)) (Submodule.subtype.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u1} (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))], Eq.{succ u2} (LinearMap.{u3, u3, u2, u2} k k (Ring.toSemiring.{u3} k _inst_1) (Ring.toSemiring.{u3} k _inst_1) (RingHom.id.{u3} k (Semiring.toNonAssocSemiring.{u3} k (Ring.toSemiring.{u3} k _inst_1))) (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) V (AddCommGroup.toAddCommMonoid.{u2} (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) _inst_3) (AffineMap.linear.{u3, u2, u1, u2, u1} k (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) V P _inst_1 (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4 (AffineSubspace.subtype.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)) (Submodule.subtype.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.subtype_linear AffineSubspace.subtype_linear\u2093'. -/\n@[simp]\ntheorem subtype_linear (s : AffineSubspace k P) [Nonempty s] :\n    s.Subtype.linear = s.direction.Subtype :=\n  rfl\n#align affine_subspace.subtype_linear AffineSubspace.subtype_linear\n\n/- warning: affine_subspace.subtype_apply -> AffineSubspace.subtype_apply is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s)] (p : coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s), Eq.{succ u3} P (coeFn.{max (succ u2) (succ u3), succ u3} (AffineMap.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (fun (_x : AffineMap.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) => (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) -> P) (AffineMap.hasCoeToFun.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (AffineSubspace.subtype.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) p) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeSubtype.{succ u3} P (fun (x : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))))) p)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u1} (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))] (p : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)), Eq.{succ u1} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => P) p) (FunLike.coe.{max (succ u2) (succ u1), succ u1, succ u1} (AffineMap.{u3, u2, u1, u2, u1} k (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) V P _inst_1 (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (fun (_x : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => P) _x) (AffineMap.funLike.{u3, u2, u1, u2, u1} k (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) V P _inst_1 (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (AffineSubspace.subtype.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) p) (Subtype.val.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) x (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)) p)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.subtype_apply AffineSubspace.subtype_apply\u2093'. -/\ntheorem subtype_apply (s : AffineSubspace k P) [Nonempty s] (p : s) : s.Subtype p = p :=\n  rfl\n#align affine_subspace.subtype_apply AffineSubspace.subtype_apply\n\n/- warning: affine_subspace.coe_subtype -> AffineSubspace.coeSubtype is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s)], Eq.{succ u3} ((fun (_x : AffineMap.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) => (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) -> P) (AffineSubspace.subtype.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)) (coeFn.{max (succ u2) (succ u3), succ u3} (AffineMap.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (fun (_x : AffineMap.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) => (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) -> P) (AffineMap.hasCoeToFun.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (AffineSubspace.subtype.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeSubtype.{succ u3} P (fun (x : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u1} (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))], Eq.{succ u1} (forall (a : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)), (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => P) a) (FunLike.coe.{max (succ u2) (succ u1), succ u1, succ u1} (AffineMap.{u3, u2, u1, u2, u1} k (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) V P _inst_1 (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (fun (_x : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => P) _x) (AffineMap.funLike.{u3, u2, u1, u2, u1} k (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) V P _inst_1 (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (AffineSubspace.subtype.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5)) (Subtype.val.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (Set.{u1} P) (Set.instMembershipSet.{u1} P) x (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_subtype AffineSubspace.coeSubtype\u2093'. -/\n@[simp]\ntheorem coeSubtype (s : AffineSubspace k P) [Nonempty s] : (s.Subtype : s \u2192 P) = coe :=\n  rfl\n#align affine_subspace.coe_subtype AffineSubspace.coeSubtype\n\n/- warning: affine_subspace.injective_subtype -> AffineSubspace.injective_subtype is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s)], Function.Injective.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) P (coeFn.{max (succ u2) (succ u3), succ u3} (AffineMap.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (fun (_x : AffineMap.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) => (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) -> P) (AffineMap.hasCoeToFun.{u1, u2, u3, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) s) V P _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (AffineSubspace.subtype.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) [_inst_5 : Nonempty.{succ u1} (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s))], Function.Injective.{succ u1, succ u1} (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) P (FunLike.coe.{max (succ u2) (succ u1), succ u1, succ u1} (AffineMap.{u3, u2, u1, u2, u1} k (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) V P _inst_1 (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) (fun (_x : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) => P) _x) (AffineMap.funLike.{u3, u2, u1, u2, u1} k (Subtype.{succ u2} V (fun (x : V) => Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Subtype.{succ u1} P (fun (x : P) => Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x s)) V P _inst_1 (Submodule.addCommGroup.{u3, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Submodule.module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (AffineSubspace.toAddTorsor.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5) _inst_2 _inst_3 _inst_4) (AffineSubspace.subtype.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s _inst_5))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.injective_subtype AffineSubspace.injective_subtype\u2093'. -/\ntheorem injective_subtype (s : AffineSubspace k P) [Nonempty s] : Function.Injective s.Subtype :=\n  Subtype.coe_injective\n#align affine_subspace.injective_subtype AffineSubspace.injective_subtype\n\n/- warning: affine_subspace.eq_iff_direction_eq_of_mem -> AffineSubspace.eq_iff_direction_eq_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s\u2081) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s\u2082) -> (Iff (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2081 s\u2082) (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s\u2081) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s\u2082) -> (Iff (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2081 s\u2082) (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.eq_iff_direction_eq_of_mem AffineSubspace.eq_iff_direction_eq_of_mem\u2093'. -/\n/-- Two affine subspaces with nonempty intersection are equal if and\nonly if their directions are equal. -/\ntheorem eq_iff_direction_eq_of_mem {s\u2081 s\u2082 : AffineSubspace k P} {p : P} (h\u2081 : p \u2208 s\u2081)\n    (h\u2082 : p \u2208 s\u2082) : s\u2081 = s\u2082 \u2194 s\u2081.direction = s\u2082.direction :=\n  \u27e8fun h => h \u25b8 rfl, fun h => ext_of_direction_eq h \u27e8p, h\u2081, h\u2082\u27e9\u27e9\n#align affine_subspace.eq_iff_direction_eq_of_mem AffineSubspace.eq_iff_direction_eq_of_mem\n\n#print AffineSubspace.mk' /-\n/-- Construct an affine subspace from a point and a direction. -/\ndef mk' (p : P) (direction : Submodule k V) : AffineSubspace k P\n    where\n  carrier := { q | \u2203 v \u2208 direction, q = v +\u1d65 p }\n  smul_vsub_vadd_mem c p1 p2 p3 hp1 hp2 hp3 :=\n    by\n    rcases hp1 with \u27e8v1, hv1, hp1\u27e9\n    rcases hp2 with \u27e8v2, hv2, hp2\u27e9\n    rcases hp3 with \u27e8v3, hv3, hp3\u27e9\n    use c \u2022 (v1 - v2) + v3, direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3\n    simp [hp1, hp2, hp3, vadd_vadd]\n#align affine_subspace.mk' AffineSubspace.mk'\n-/\n\n/- warning: affine_subspace.self_mem_mk' -> AffineSubspace.self_mem_mk' is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (direction : Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (AffineSubspace.mk'.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (direction : Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3), Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (AffineSubspace.mk'.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.self_mem_mk' AffineSubspace.self_mem_mk'\u2093'. -/\n/-- An affine subspace constructed from a point and a direction contains\nthat point. -/\ntheorem self_mem_mk' (p : P) (direction : Submodule k V) : p \u2208 mk' p direction :=\n  \u27e80, \u27e8direction.zero_mem, (zero_vadd _ _).symm\u27e9\u27e9\n#align affine_subspace.self_mem_mk' AffineSubspace.self_mem_mk'\n\n/- warning: affine_subspace.vadd_mem_mk' -> AffineSubspace.vadd_mem_mk' is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {v : V} (p : P) {direction : Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3}, (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v direction) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p) (AffineSubspace.mk'.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {v : V} (p : P) {direction : Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3}, (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v direction) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u2, u1, u1} V P P (instHVAdd.{u2, u1} V P (AddAction.toVAdd.{u2, u1} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4))) v p) (AffineSubspace.mk'.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vadd_mem_mk' AffineSubspace.vadd_mem_mk'\u2093'. -/\n/-- An affine subspace constructed from a point and a direction contains\nthe result of adding a vector in that direction to that point. -/\ntheorem vadd_mem_mk' {v : V} (p : P) {direction : Submodule k V} (hv : v \u2208 direction) :\n    v +\u1d65 p \u2208 mk' p direction :=\n  \u27e8v, hv, rfl\u27e9\n#align affine_subspace.vadd_mem_mk' AffineSubspace.vadd_mem_mk'\n\n/- warning: affine_subspace.mk'_nonempty -> AffineSubspace.mk'_nonempty is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (direction : Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3), Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (AffineSubspace.mk'.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (direction : Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3), Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.mk'.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mk'_nonempty AffineSubspace.mk'_nonempty\u2093'. -/\n/-- An affine subspace constructed from a point and a direction is\nnonempty. -/\ntheorem mk'_nonempty (p : P) (direction : Submodule k V) : (mk' p direction : Set P).Nonempty :=\n  \u27e8p, self_mem_mk' p direction\u27e9\n#align affine_subspace.mk'_nonempty AffineSubspace.mk'_nonempty\n\n/- warning: affine_subspace.direction_mk' -> AffineSubspace.direction_mk' is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (direction : Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (AffineSubspace.mk'.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction)) direction\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (direction : Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3), Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (AffineSubspace.mk'.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 p direction)) direction\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_mk' AffineSubspace.direction_mk'\u2093'. -/\n/-- The direction of an affine subspace constructed from a point and a\ndirection. -/\n@[simp]\ntheorem direction_mk' (p : P) (direction : Submodule k V) :\n    (mk' p direction).direction = direction := by\n  ext v\n  rw [mem_direction_iff_eq_vsub (mk'_nonempty _ _)]\n  constructor\n  \u00b7 rintro \u27e8p1, \u27e8v1, hv1, hp1\u27e9, p2, \u27e8v2, hv2, hp2\u27e9, hv\u27e9\n    rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right]\n    exact direction.sub_mem hv1 hv2\n  \u00b7 exact fun hv => \u27e8v +\u1d65 p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm\u27e9\n#align affine_subspace.direction_mk' AffineSubspace.direction_mk'\n\n/- warning: affine_subspace.mem_mk'_iff_vsub_mem -> AffineSubspace.mem_mk'_iff_vsub_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {direction : Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3}, Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2082 (AffineSubspace.mk'.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2081 direction)) (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081) direction)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {direction : Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3}, Iff (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2082 (AffineSubspace.mk'.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2081 direction)) (Membership.mem.{u2, u2} V (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081) direction)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_mk'_iff_vsub_mem AffineSubspace.mem_mk'_iff_vsub_mem\u2093'. -/\n/-- A point lies in an affine subspace constructed from another point and a direction if and only\nif their difference is in that direction. -/\ntheorem mem_mk'_iff_vsub_mem {p\u2081 p\u2082 : P} {direction : Submodule k V} :\n    p\u2082 \u2208 mk' p\u2081 direction \u2194 p\u2082 -\u1d65 p\u2081 \u2208 direction :=\n  by\n  refine' \u27e8fun h => _, fun h => _\u27e9\n  \u00b7 rw [\u2190 direction_mk' p\u2081 direction]\n    exact vsub_mem_direction h (self_mem_mk' _ _)\n  \u00b7 rw [\u2190 vsub_vadd p\u2082 p\u2081]\n    exact vadd_mem_mk' p\u2081 h\n#align affine_subspace.mem_mk'_iff_vsub_mem AffineSubspace.mem_mk'_iff_vsub_mem\n\n/- warning: affine_subspace.mk'_eq -> AffineSubspace.mk'_eq is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.mk'.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) s)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p s) -> (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.mk'.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 p (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mk'_eq AffineSubspace.mk'_eq\u2093'. -/\n/-- Constructing an affine subspace from a point in a subspace and\nthat subspace's direction yields the original subspace. -/\n@[simp]\ntheorem mk'_eq {s : AffineSubspace k P} {p : P} (hp : p \u2208 s) : mk' p s.direction = s :=\n  ext_of_direction_eq (direction_mk' p s.direction) \u27e8p, Set.mem_inter (self_mem_mk' _ _) hp\u27e9\n#align affine_subspace.mk'_eq AffineSubspace.mk'_eq\n\n/- warning: affine_subspace.span_points_subset_coe_of_subset_coe -> AffineSubspace.spanPoints_subset_coe_of_subset_coe is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) s ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s1)) -> (HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s1))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P} {s1 : AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) s (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s1)) -> (HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s1))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.span_points_subset_coe_of_subset_coe AffineSubspace.spanPoints_subset_coe_of_subset_coe\u2093'. -/\n/-- If an affine subspace contains a set of points, it contains the\n`span_points` of that set. -/\ntheorem spanPoints_subset_coe_of_subset_coe {s : Set P} {s1 : AffineSubspace k P} (h : s \u2286 s1) :\n    spanPoints k s \u2286 s1 := by\n  rintro p \u27e8p1, hp1, v, hv, hp\u27e9\n  rw [hp]\n  have hp1s1 : p1 \u2208 (s1 : Set P) := Set.mem_of_mem_of_subset hp1 h\n  refine' vadd_mem_of_mem_direction _ hp1s1\n  have hs : vectorSpan k s \u2264 s1.direction := vectorSpan_mono k h\n  rw [SetLike.le_def] at hs\n  rw [\u2190 SetLike.mem_coe]\n  exact Set.mem_of_mem_of_subset hv hs\n#align affine_subspace.span_points_subset_coe_of_subset_coe AffineSubspace.spanPoints_subset_coe_of_subset_coe\n\nend AffineSubspace\n\n/- warning: affine_map.line_map_mem -> AffineMap.lineMap_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {Q : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p\u2080 : P} {p\u2081 : P} (c : k), (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2080 Q) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 Q) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (coeFn.{max (succ u1) (succ u2) (succ u3), max (succ u1) (succ u3)} (AffineMap.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) (fun (_x : AffineMap.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) => k -> P) (AffineMap.hasCoeToFun.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) (AffineMap.lineMap.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2080 p\u2081) c) Q)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {Q : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p\u2080 : P} {p\u2081 : P} (c : k), (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2080 Q) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 Q) -> (Membership.mem.{u1, u1} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : k) => P) c) (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (FunLike.coe.{max (max (succ u3) (succ u2)) (succ u1), succ u3, succ u1} (AffineMap.{u3, u3, u3, u2, u1} k k k V P _inst_1 (Ring.toAddCommGroup.{u3} k _inst_1) (AffineMap.instModuleToSemiringToAddCommMonoidToNonUnitalNonAssocSemiringToNonUnitalNonAssocRingToNonUnitalRing.{u3} k _inst_1) (addGroupIsAddTorsor.{u3} k (AddGroupWithOne.toAddGroup.{u3} k (Ring.toAddGroupWithOne.{u3} k _inst_1))) _inst_2 _inst_3 _inst_4) k (fun (_x : k) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : k) => P) _x) (AffineMap.funLike.{u3, u3, u3, u2, u1} k k k V P _inst_1 (Ring.toAddCommGroup.{u3} k _inst_1) (AffineMap.instModuleToSemiringToAddCommMonoidToNonUnitalNonAssocSemiringToNonUnitalNonAssocRingToNonUnitalRing.{u3} k _inst_1) (addGroupIsAddTorsor.{u3} k (AddGroupWithOne.toAddGroup.{u3} k (Ring.toAddGroupWithOne.{u3} k _inst_1))) _inst_2 _inst_3 _inst_4) (AffineMap.lineMap.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2080 p\u2081) c) Q)\nCase conversion may be inaccurate. Consider using '#align affine_map.line_map_mem AffineMap.lineMap_mem\u2093'. -/\ntheorem AffineMap.lineMap_mem {k V P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n    [AddTorsor V P] {Q : AffineSubspace k P} {p\u2080 p\u2081 : P} (c : k) (h\u2080 : p\u2080 \u2208 Q) (h\u2081 : p\u2081 \u2208 Q) :\n    AffineMap.lineMap p\u2080 p\u2081 c \u2208 Q :=\n  by\n  rw [AffineMap.lineMap_apply]\n  exact Q.smul_vsub_vadd_mem c h\u2081 h\u2080 h\u2080\n#align affine_map.line_map_mem AffineMap.lineMap_mem\n\nsection affineSpan\n\nvariable (k : Type _) {V : Type _} {P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n  [affine_space V P]\n\ninclude V\n\n#print affineSpan /-\n/-- The affine span of a set of points is the smallest affine subspace\ncontaining those points. (Actually defined here in terms of spans in\nmodules.) -/\ndef affineSpan (s : Set P) : AffineSubspace k P\n    where\n  carrier := spanPoints k s\n  smul_vsub_vadd_mem c p1 p2 p3 hp1 hp2 hp3 :=\n    vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp3\n      ((vectorSpan k s).smul_mem c\n        (vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp1 hp2))\n#align affine_span affineSpan\n-/\n\n/- warning: coe_affine_span -> coe_affineSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : Set.{u3} P), Eq.{succ u3} (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (spanPoints.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (s : Set.{u3} P), Eq.{succ u3} (Set.{u3} P) (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (spanPoints.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)\nCase conversion may be inaccurate. Consider using '#align coe_affine_span coe_affineSpan\u2093'. -/\n/-- The affine span, converted to a set, is `span_points`. -/\n@[simp]\ntheorem coe_affineSpan (s : Set P) : (affineSpan k s : Set P) = spanPoints k s :=\n  rfl\n#align coe_affine_span coe_affineSpan\n\n/- warning: subset_affine_span -> subset_affineSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : Set.{u3} P), HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) s ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (s : Set.{u3} P), HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) s (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align subset_affine_span subset_affineSpan\u2093'. -/\n/-- A set is contained in its affine span. -/\ntheorem subset_affineSpan (s : Set P) : s \u2286 affineSpan k s :=\n  subset_spanPoints k s\n#align subset_affine_span subset_affineSpan\n\n#print direction_affineSpan /-\n/-- The direction of the affine span is the `vector_span`. -/\ntheorem direction_affineSpan (s : Set P) : (affineSpan k s).direction = vectorSpan k s :=\n  by\n  apply le_antisymm\n  \u00b7 refine' Submodule.span_le.2 _\n    rintro v \u27e8p1, p3, \u27e8p2, hp2, v1, hv1, hp1\u27e9, \u27e8p4, hp4, v2, hv2, hp3\u27e9, rfl\u27e9\n    rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, SetLike.mem_coe]\n    exact\n      (vectorSpan k s).sub_mem ((vectorSpan k s).add_mem hv1 (vsub_mem_vectorSpan k hp2 hp4)) hv2\n  \u00b7 exact vectorSpan_mono k (subset_spanPoints k s)\n#align direction_affine_span direction_affineSpan\n-/\n\n/- warning: mem_affine_span -> mem_affineSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p : P} {s : Set.{u3} P}, (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p s) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p : P} {s : Set.{u3} P}, (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p s) -> (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align mem_affine_span mem_affineSpan\u2093'. -/\n/-- A point in a set is in its affine span. -/\ntheorem mem_affineSpan {p : P} {s : Set P} (hp : p \u2208 s) : p \u2208 affineSpan k s :=\n  mem_spanPoints k p s hp\n#align mem_affine_span mem_affineSpan\n\nend affineSpan\n\nnamespace AffineSubspace\n\nvariable {k : Type _} {V : Type _} {P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n  [S : affine_space V P]\n\ninclude S\n\ninstance : CompleteLattice (AffineSubspace k P) :=\n  {\n    PartialOrder.lift (coe : AffineSubspace k P \u2192 Set P)\n      coe_injective with\n    sup := fun s1 s2 => affineSpan k (s1 \u222a s2)\n    le_sup_left := fun s1 s2 =>\n      Set.Subset.trans (Set.subset_union_left s1 s2) (subset_spanPoints k _)\n    le_sup_right := fun s1 s2 =>\n      Set.Subset.trans (Set.subset_union_right s1 s2) (subset_spanPoints k _)\n    sup_le := fun s1 s2 s3 hs1 hs2 => spanPoints_subset_coe_of_subset_coe (Set.union_subset hs1 hs2)\n    inf := fun s1 s2 =>\n      mk (s1 \u2229 s2) fun c p1 p2 p3 hp1 hp2 hp3 =>\n        \u27e8s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1, s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2\u27e9\n    inf_le_left := fun _ _ => Set.inter_subset_left _ _\n    inf_le_right := fun _ _ => Set.inter_subset_right _ _\n    le_inf := fun _ _ _ => Set.subset_inter\n    top :=\n      { carrier := Set.univ\n        smul_vsub_vadd_mem := fun _ _ _ _ _ _ _ => Set.mem_univ _ }\n    le_top := fun _ _ _ => Set.mem_univ _\n    bot :=\n      { carrier := \u2205\n        smul_vsub_vadd_mem := fun _ _ _ _ => False.elim }\n    bot_le := fun _ _ => False.elim\n    sup\u209b := fun s => affineSpan k (\u22c3 s' \u2208 s, (s' : Set P))\n    inf\u209b := fun s =>\n      mk (\u22c2 s' \u2208 s, (s' : Set P)) fun c p1 p2 p3 hp1 hp2 hp3 =>\n        Set.mem_inter\u1d62\u2082.2 fun s2 hs2 => by\n          rw [Set.mem_inter\u1d62\u2082] at *\n          exact s2.smul_vsub_vadd_mem c (hp1 s2 hs2) (hp2 s2 hs2) (hp3 s2 hs2)\n    le_sup := fun _ _ h => Set.Subset.trans (Set.subset_bunion\u1d62_of_mem h) (subset_spanPoints k _)\n    sup_le := fun _ _ h => spanPoints_subset_coe_of_subset_coe (Set.union\u1d62\u2082_subset h)\n    inf_le := fun _ _ => Set.binter\u1d62_subset_of_mem\n    le_inf := fun _ _ => Set.subset_inter\u1d62\u2082 }\n\ninstance : Inhabited (AffineSubspace k P) :=\n  \u27e8\u22a4\u27e9\n\n/- warning: affine_subspace.le_def -> AffineSubspace.le_def is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) (HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (LE.le.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) (HasSubset.Subset.{u1} (Set.{u1} P) (Set.instHasSubsetSet.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.le_def AffineSubspace.le_def\u2093'. -/\n/-- The `\u2264` order on subspaces is the same as that on the corresponding\nsets. -/\ntheorem le_def (s1 s2 : AffineSubspace k P) : s1 \u2264 s2 \u2194 (s1 : Set P) \u2286 s2 :=\n  Iff.rfl\n#align affine_subspace.le_def AffineSubspace.le_def\n\n/- warning: affine_subspace.le_def' -> AffineSubspace.le_def' is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) (forall (p : P), (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s1) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (LE.le.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) (forall (p : P), (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s1) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.le_def' AffineSubspace.le_def'\u2093'. -/\n/-- One subspace is less than or equal to another if and only if all\nits points are in the second subspace. -/\ntheorem le_def' (s1 s2 : AffineSubspace k P) : s1 \u2264 s2 \u2194 \u2200 p \u2208 s1, p \u2208 s2 :=\n  Iff.rfl\n#align affine_subspace.le_def' AffineSubspace.le_def'\n\n/- warning: affine_subspace.lt_def -> AffineSubspace.lt_def is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (LT.lt.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) (HasSSubset.SSubset.{u3} (Set.{u3} P) (Set.hasSsubset.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (LT.lt.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) (HasSSubset.SSubset.{u1} (Set.{u1} P) (Set.instHasSSubsetSet.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.lt_def AffineSubspace.lt_def\u2093'. -/\n/-- The `<` order on subspaces is the same as that on the corresponding\nsets. -/\ntheorem lt_def (s1 s2 : AffineSubspace k P) : s1 < s2 \u2194 (s1 : Set P) \u2282 s2 :=\n  Iff.rfl\n#align affine_subspace.lt_def AffineSubspace.lt_def\n\n/- warning: affine_subspace.not_le_iff_exists -> AffineSubspace.not_le_iff_exists is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (Not (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2)) (Exists.{succ u3} P (fun (p : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s1) (fun (H : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s1) => Not (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s2))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (Not (LE.le.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2)) (Exists.{succ u1} P (fun (p : P) => And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s1) (Not (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s2))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.not_le_iff_exists AffineSubspace.not_le_iff_exists\u2093'. -/\n/-- One subspace is not less than or equal to another if and only if\nit has a point not in the second subspace. -/\ntheorem not_le_iff_exists (s1 s2 : AffineSubspace k P) : \u00acs1 \u2264 s2 \u2194 \u2203 p \u2208 s1, p \u2209 s2 :=\n  Set.not_subset\n#align affine_subspace.not_le_iff_exists AffineSubspace.not_le_iff_exists\n\n/- warning: affine_subspace.exists_of_lt -> AffineSubspace.exists_of_lt is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (LT.lt.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) -> (Exists.{succ u3} P (fun (p : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s2) (fun (H : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s2) => Not (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s1))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (LT.lt.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) -> (Exists.{succ u1} P (fun (p : P) => And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s2) (Not (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s1))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.exists_of_lt AffineSubspace.exists_of_lt\u2093'. -/\n/-- If a subspace is less than another, there is a point only in the\nsecond. -/\ntheorem exists_of_lt {s1 s2 : AffineSubspace k P} (h : s1 < s2) : \u2203 p \u2208 s2, p \u2209 s1 :=\n  Set.exists_of_ssubset h\n#align affine_subspace.exists_of_lt AffineSubspace.exists_of_lt\n\n/- warning: affine_subspace.lt_iff_le_and_exists -> AffineSubspace.lt_iff_le_and_exists is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (LT.lt.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) (And (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) (Exists.{succ u3} P (fun (p : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s2) (fun (H : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s2) => Not (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s1)))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (LT.lt.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) (And (LE.le.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) (Exists.{succ u1} P (fun (p : P) => And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s2) (Not (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s1)))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.lt_iff_le_and_exists AffineSubspace.lt_iff_le_and_exists\u2093'. -/\n/-- A subspace is less than another if and only if it is less than or\nequal to the second subspace and there is a point only in the\nsecond. -/\ntheorem lt_iff_le_and_exists (s1 s2 : AffineSubspace k P) : s1 < s2 \u2194 s1 \u2264 s2 \u2227 \u2203 p \u2208 s2, p \u2209 s1 :=\n  by rw [lt_iff_le_not_le, not_le_iff_exists]\n#align affine_subspace.lt_iff_le_and_exists AffineSubspace.lt_iff_le_and_exists\n\n/- warning: affine_subspace.eq_of_direction_eq_of_nonempty_of_le -> AffineSubspace.eq_of_direction_eq_of_nonempty_of_le is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s\u2081) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s\u2082)) -> (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s\u2081)) -> (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s\u2081 s\u2082) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) s\u2081 s\u2082)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s\u2081) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s\u2082)) -> (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s\u2081)) -> (LE.le.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s\u2081 s\u2082) -> (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s\u2081 s\u2082)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.eq_of_direction_eq_of_nonempty_of_le AffineSubspace.eq_of_direction_eq_of_nonempty_of_le\u2093'. -/\n/-- If an affine subspace is nonempty and contained in another with\nthe same direction, they are equal. -/\ntheorem eq_of_direction_eq_of_nonempty_of_le {s\u2081 s\u2082 : AffineSubspace k P}\n    (hd : s\u2081.direction = s\u2082.direction) (hn : (s\u2081 : Set P).Nonempty) (hle : s\u2081 \u2264 s\u2082) : s\u2081 = s\u2082 :=\n  let \u27e8p, hp\u27e9 := hn\n  ext_of_direction_eq hd \u27e8p, hp, hle hp\u27e9\n#align affine_subspace.eq_of_direction_eq_of_nonempty_of_le AffineSubspace.eq_of_direction_eq_of_nonempty_of_le\n\nvariable (k V)\n\n/- warning: affine_subspace.affine_span_eq_Inf -> AffineSubspace.affineSpan_eq_inf\u209b is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : Set.{u3} P), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (InfSet.inf\u209b.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))) (setOf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (fun (s' : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) => HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) s ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s'))))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (s : Set.{u3} P), Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (InfSet.inf\u209b.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toInfSet.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S))) (setOf.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (fun (s' : AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) => HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) s (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) s'))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.affine_span_eq_Inf AffineSubspace.affineSpan_eq_inf\u209b\u2093'. -/\n/-- The affine span is the `Inf` of subspaces containing the given\npoints. -/\ntheorem affineSpan_eq_inf\u209b (s : Set P) : affineSpan k s = inf\u209b { s' | s \u2286 s' } :=\n  le_antisymm (spanPoints_subset_coe_of_subset_coe <| Set.subset_inter\u1d62\u2082 fun _ => id)\n    (inf\u209b_le (subset_spanPoints k _))\n#align affine_subspace.affine_span_eq_Inf AffineSubspace.affineSpan_eq_inf\u209b\n\nvariable (P)\n\n/- warning: affine_subspace.gi -> AffineSubspace.gi is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], GaloisInsertion.{u3, u3} (Set.{u3} P) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (Set.{u3} P) (CompleteSemilatticeInf.toPartialOrder.{u3} (Set.{u3} P) (CompleteLattice.toCompleteSemilatticeInf.{u3} (Set.{u3} P) (Order.Coframe.toCompleteLattice.{u3} (Set.{u3} P) (CompleteDistribLattice.toCoframe.{u3} (Set.{u3} P) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u3} (Set.{u3} P) (Set.completeBooleanAlgebra.{u3} P))))))) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))))\nbut is expected to have type\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], GaloisInsertion.{u3, u3} (Set.{u3} P) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (Set.{u3} P) (OmegaCompletePartialOrder.toPartialOrder.{u3} (Set.{u3} P) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (Set.{u3} P) (Order.Coframe.toCompleteLattice.{u3} (Set.{u3} P) (CompleteDistribLattice.toCoframe.{u3} (Set.{u3} P) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u3} (Set.{u3} P) (Set.instCompleteBooleanAlgebraSet.{u3} P))))))) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.coe.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.gi AffineSubspace.gi\u2093'. -/\n/-- The Galois insertion formed by `affine_span` and coercion back to\na set. -/\nprotected def gi : GaloisInsertion (affineSpan k) (coe : AffineSubspace k P \u2192 Set P)\n    where\n  choice s _ := affineSpan k s\n  gc s1 s2 :=\n    \u27e8fun h => Set.Subset.trans (subset_spanPoints k s1) h, spanPoints_subset_coe_of_subset_coe\u27e9\n  le_l_u _ := subset_spanPoints k _\n  choice_eq _ _ := rfl\n#align affine_subspace.gi AffineSubspace.gi\n\n/- warning: affine_subspace.span_empty -> AffineSubspace.span_empty is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P))) (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)], Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.instEmptyCollectionSet.{u3} P))) (Bot.bot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.span_empty AffineSubspace.span_empty\u2093'. -/\n/-- The span of the empty set is `\u22a5`. -/\n@[simp]\ntheorem span_empty : affineSpan k (\u2205 : Set P) = \u22a5 :=\n  (AffineSubspace.gi k V P).gc.l_bot\n#align affine_subspace.span_empty AffineSubspace.span_empty\n\n/- warning: affine_subspace.span_univ -> AffineSubspace.span_univ is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Set.univ.{u3} P)) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)], Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Set.univ.{u3} P)) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.span_univ AffineSubspace.span_univ\u2093'. -/\n/-- The span of `univ` is `\u22a4`. -/\n@[simp]\ntheorem span_univ : affineSpan k (Set.univ : Set P) = \u22a4 :=\n  eq_top_iff.2 <| subset_spanPoints k _\n#align affine_subspace.span_univ AffineSubspace.span_univ\n\nvariable {k V P}\n\n/- warning: affine_span_le -> affineSpan_le is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {Q : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, Iff (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) Q) (HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) s ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) Q))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P} {Q : AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S}, Iff (LE.le.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S))))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) Q) (HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) s (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) Q))\nCase conversion may be inaccurate. Consider using '#align affine_span_le affineSpan_le\u2093'. -/\ntheorem affineSpan_le {s : Set P} {Q : AffineSubspace k P} : affineSpan k s \u2264 Q \u2194 s \u2286 (Q : Set P) :=\n  (AffineSubspace.gi k V P).gc _ _\n#align affine_span_le affineSpan_le\n\nvariable (k V) {P} {p\u2081 p\u2082 : P}\n\n/- warning: affine_subspace.coe_affine_span_singleton -> AffineSubspace.coe_affineSpan_singleton is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P), Eq.{succ u3} (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p))) (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p)\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (p : P), Eq.{succ u3} (Set.{u3} P) (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p))) (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_affine_span_singleton AffineSubspace.coe_affineSpan_singleton\u2093'. -/\n/-- The affine span of a single point, coerced to a set, contains just\nthat point. -/\n@[simp]\ntheorem coe_affineSpan_singleton (p : P) : (affineSpan k ({p} : Set P) : Set P) = {p} :=\n  by\n  ext x\n  rw [mem_coe, \u2190 vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_singleton p)) _,\n    direction_affineSpan]\n  simp\n#align affine_subspace.coe_affine_span_singleton AffineSubspace.coe_affineSpan_singleton\n\n/- warning: affine_subspace.mem_affine_span_singleton -> AffineSubspace.mem_affineSpan_singleton is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P}, Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p\u2081 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082))) (Eq.{succ u3} P p\u2081 p\u2082)\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p\u2081 : P} {p\u2082 : P}, Iff (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)) p\u2081 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082))) (Eq.{succ u3} P p\u2081 p\u2082)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_affine_span_singleton AffineSubspace.mem_affineSpan_singleton\u2093'. -/\n/-- A point is in the affine span of a single point if and only if\nthey are equal. -/\n@[simp]\ntheorem mem_affineSpan_singleton : p\u2081 \u2208 affineSpan k ({p\u2082} : Set P) \u2194 p\u2081 = p\u2082 := by simp [\u2190 mem_coe]\n#align affine_subspace.mem_affine_span_singleton AffineSubspace.mem_affineSpan_singleton\n\n/- warning: affine_subspace.preimage_coe_affine_span_singleton -> AffineSubspace.preimage_coe_affineSpan_singleton is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (x : P), Eq.{succ u3} (Set.{u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x)))) (Set.preimage.{u3, u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x))) P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x))) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x))) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x))) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x))) P (coeSubtype.{succ u3} P (fun (x_1 : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) x_1 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x)))))))) (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x)) (Set.univ.{u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) x))))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (x : P), Eq.{succ u3} (Set.{u3} (Subtype.{succ u3} P (fun (x_1 : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x_1 (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) x)))))) (Set.preimage.{u3, u3} (Subtype.{succ u3} P (fun (x_1 : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x_1 (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) x))))) P (Subtype.val.{succ u3} P (fun (x_1 : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x_1 (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) x))))) (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) x)) (Set.univ.{u3} (Subtype.{succ u3} P (fun (x_1 : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x_1 (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) x))))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.preimage_coe_affine_span_singleton AffineSubspace.preimage_coe_affineSpan_singleton\u2093'. -/\n@[simp]\ntheorem preimage_coe_affineSpan_singleton (x : P) :\n    (coe : affineSpan k ({x} : Set P) \u2192 P) \u207b\u00b9' {x} = univ :=\n  eq_univ_of_forall fun y => (AffineSubspace.mem_affineSpan_singleton _ _).1 y.2\n#align affine_subspace.preimage_coe_affine_span_singleton AffineSubspace.preimage_coe_affineSpan_singleton\n\n/- warning: affine_subspace.span_union -> AffineSubspace.span_union is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : Set.{u3} P) (t : Set.{u3} P), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Union.union.{u3} (Set.{u3} P) (Set.hasUnion.{u3} P) s t)) (Sup.sup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeSup.toHasSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S t))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (s : Set.{u3} P) (t : Set.{u3} P), Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Union.union.{u3} (Set.{u3} P) (Set.instUnionSet.{u3} P) s t)) (Sup.sup.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeSup.toSup.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeSup.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S))))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S t))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.span_union AffineSubspace.span_union\u2093'. -/\n/-- The span of a union of sets is the sup of their spans. -/\ntheorem span_union (s t : Set P) : affineSpan k (s \u222a t) = affineSpan k s \u2294 affineSpan k t :=\n  (AffineSubspace.gi k V P).gc.l_sup\n#align affine_subspace.span_union AffineSubspace.span_union\n\n/- warning: affine_subspace.span_Union -> AffineSubspace.span_union\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} (s : \u03b9 -> (Set.{u3} P)), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Set.union\u1d62.{u3, succ u4} P \u03b9 (fun (i : \u03b9) => s i))) (sup\u1d62.{u3, succ u4} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toHasSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))) \u03b9 (fun (i : \u03b9) => affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (s i)))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {\u03b9 : Type.{u4}} (s : \u03b9 -> (Set.{u3} P)), Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Set.union\u1d62.{u3, succ u4} P \u03b9 (fun (i : \u03b9) => s i))) (sup\u1d62.{u3, succ u4} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toSupSet.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S))) \u03b9 (fun (i : \u03b9) => affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (s i)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.span_Union AffineSubspace.span_union\u1d62\u2093'. -/\n/-- The span of a union of an indexed family of sets is the sup of\ntheir spans. -/\ntheorem span_union\u1d62 {\u03b9 : Type _} (s : \u03b9 \u2192 Set P) :\n    affineSpan k (\u22c3 i, s i) = \u2a06 i, affineSpan k (s i) :=\n  (AffineSubspace.gi k V P).gc.l_sup\u1d62\n#align affine_subspace.span_Union AffineSubspace.span_union\u1d62\n\nvariable (P)\n\n/- warning: affine_subspace.top_coe -> AffineSubspace.top_coe is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Eq.{succ u3} (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Set.univ.{u3} P)\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)], Eq.{succ u3} (Set.{u3} P) (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Set.univ.{u3} P)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.top_coe AffineSubspace.top_coe\u2093'. -/\n/-- `\u22a4`, coerced to a set, is the whole set of points. -/\n@[simp]\ntheorem top_coe : ((\u22a4 : AffineSubspace k P) : Set P) = Set.univ :=\n  rfl\n#align affine_subspace.top_coe AffineSubspace.top_coe\n\nvariable {P}\n\n/- warning: affine_subspace.mem_top -> AffineSubspace.mem_top is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (p : P), Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)) p (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_top AffineSubspace.mem_top\u2093'. -/\n/-- All points are in `\u22a4`. -/\ntheorem mem_top (p : P) : p \u2208 (\u22a4 : AffineSubspace k P) :=\n  Set.mem_univ p\n#align affine_subspace.mem_top AffineSubspace.mem_top\n\nvariable (P)\n\n/- warning: affine_subspace.direction_top -> AffineSubspace.direction_top is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Top.top.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasTop.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u3}) (P : Type.{u1}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [S : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)], Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (AffineSubspace.direction.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S (Top.top.{u1} (AffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u1} (AffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S)))) (Top.top.{u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (Submodule.instTopSubmodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_top AffineSubspace.direction_top\u2093'. -/\n/-- The direction of `\u22a4` is the whole module as a submodule. -/\n@[simp]\ntheorem direction_top : (\u22a4 : AffineSubspace k P).direction = \u22a4 :=\n  by\n  cases' S.nonempty with p\n  ext v\n  refine' \u27e8imp_intro Submodule.mem_top, fun hv => _\u27e9\n  have hpv : (v +\u1d65 p -\u1d65 p : V) \u2208 (\u22a4 : AffineSubspace k P).direction :=\n    vsub_mem_direction (mem_top k V _) (mem_top k V _)\n  rwa [vadd_vsub] at hpv\n#align affine_subspace.direction_top AffineSubspace.direction_top\n\n/- warning: affine_subspace.bot_coe -> AffineSubspace.bot_coe is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Eq.{succ u3} (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)], Eq.{succ u3} (Set.{u3} P) (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (Bot.bot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.instEmptyCollectionSet.{u3} P))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.bot_coe AffineSubspace.bot_coe\u2093'. -/\n/-- `\u22a5`, coerced to a set, is the empty set. -/\n@[simp]\ntheorem bot_coe : ((\u22a5 : AffineSubspace k P) : Set P) = \u2205 :=\n  rfl\n#align affine_subspace.bot_coe AffineSubspace.bot_coe\n\n/- warning: affine_subspace.bot_ne_top -> AffineSubspace.bot_ne_top is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Ne.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)], Ne.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (Bot.bot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S))) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.bot_ne_top AffineSubspace.bot_ne_top\u2093'. -/\ntheorem bot_ne_top : (\u22a5 : AffineSubspace k P) \u2260 \u22a4 :=\n  by\n  intro contra\n  rw [\u2190 ext_iff, bot_coe, top_coe] at contra\n  exact Set.empty_ne_univ contra\n#align affine_subspace.bot_ne_top AffineSubspace.bot_ne_top\n\ninstance : Nontrivial (AffineSubspace k P) :=\n  \u27e8\u27e8\u22a5, \u22a4, bot_ne_top k V P\u27e9\u27e9\n\n/- warning: affine_subspace.nonempty_of_affine_span_eq_top -> AffineSubspace.nonempty_of_affineSpan_eq_top is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Set.Nonempty.{u3} P s)\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Set.Nonempty.{u3} P s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.nonempty_of_affine_span_eq_top AffineSubspace.nonempty_of_affineSpan_eq_top\u2093'. -/\ntheorem nonempty_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = \u22a4) : s.Nonempty :=\n  by\n  rw [Set.nonempty_iff_ne_empty]\n  rintro rfl\n  rw [AffineSubspace.span_empty] at h\n  exact bot_ne_top k V P h\n#align affine_subspace.nonempty_of_affine_span_eq_top AffineSubspace.nonempty_of_affineSpan_eq_top\n\n/- warning: affine_subspace.vector_span_eq_top_of_affine_span_eq_top -> AffineSubspace.vectorSpan_eq_top_of_affineSpan_eq_top is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasTop.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Eq.{succ u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (Submodule.instTopSubmodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.vector_span_eq_top_of_affine_span_eq_top AffineSubspace.vectorSpan_eq_top_of_affineSpan_eq_top\u2093'. -/\n/-- If the affine span of a set is `\u22a4`, then the vector span of the same set is the `\u22a4`. -/\ntheorem vectorSpan_eq_top_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = \u22a4) :\n    vectorSpan k s = \u22a4 := by rw [\u2190 direction_affineSpan, h, direction_top]\n#align affine_subspace.vector_span_eq_top_of_affine_span_eq_top AffineSubspace.vectorSpan_eq_top_of_affineSpan_eq_top\n\n/- warning: affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nonempty -> AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, (Set.Nonempty.{u3} P s) -> (Iff (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasTop.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, (Set.Nonempty.{u3} P s) -> (Iff (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Eq.{succ u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (Submodule.instTopSubmodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nonempty AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty\u2093'. -/\n/-- For a nonempty set, the affine span is `\u22a4` iff its vector span is `\u22a4`. -/\ntheorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty {s : Set P} (hs : s.Nonempty) :\n    affineSpan k s = \u22a4 \u2194 vectorSpan k s = \u22a4 :=\n  by\n  refine' \u27e8vector_span_eq_top_of_affine_span_eq_top k V P, _\u27e9\n  intro h\n  suffices Nonempty (affineSpan k s)\n    by\n    obtain \u27e8p, hp : p \u2208 affineSpan k s\u27e9 := this\n    rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affineSpan, h, direction_top]\n  obtain \u27e8x, hx\u27e9 := hs\n  exact \u27e8\u27e8x, mem_affineSpan k hx\u27e9\u27e9\n#align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nonempty AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty\n\n/- warning: affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial -> AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} [_inst_4 : Nontrivial.{u3} P], Iff (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasTop.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P} [_inst_4 : Nontrivial.{u3} P], Iff (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Eq.{succ u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (Submodule.instTopSubmodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial\u2093'. -/\n/-- For a non-trivial space, the affine span of a set is `\u22a4` iff its vector span is `\u22a4`. -/\ntheorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial {s : Set P} [Nontrivial P] :\n    affineSpan k s = \u22a4 \u2194 vectorSpan k s = \u22a4 :=\n  by\n  cases' s.eq_empty_or_nonempty with hs hs\n  \u00b7 simp [hs, subsingleton_iff_bot_eq_top, AddTorsor.subsingleton_iff V P, not_subsingleton]\n  \u00b7 rw [affine_span_eq_top_iff_vector_span_eq_top_of_nonempty k V P hs]\n#align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial\n\n/- warning: affine_subspace.card_pos_of_affine_span_eq_top -> AffineSubspace.card_pos_of_affineSpan_eq_top is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} [_inst_4 : Fintype.{u4} \u03b9] {p : \u03b9 -> P}, (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Set.range.{u3, succ u4} P \u03b9 p)) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Fintype.card.{u4} \u03b9 _inst_4))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) (P : Type.{u3}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {\u03b9 : Type.{u4}} [_inst_4 : Fintype.{u4} \u03b9] {p : \u03b9 -> P}, (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S (Set.range.{u3, succ u4} P \u03b9 p)) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Fintype.card.{u4} \u03b9 _inst_4))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.card_pos_of_affine_span_eq_top AffineSubspace.card_pos_of_affineSpan_eq_top\u2093'. -/\ntheorem card_pos_of_affineSpan_eq_top {\u03b9 : Type _} [Fintype \u03b9] {p : \u03b9 \u2192 P}\n    (h : affineSpan k (range p) = \u22a4) : 0 < Fintype.card \u03b9 :=\n  by\n  obtain \u27e8-, \u27e8i, -\u27e9\u27e9 := nonempty_of_affine_span_eq_top k V P h\n  exact fintype.card_pos_iff.mpr \u27e8i\u27e9\n#align affine_subspace.card_pos_of_affine_span_eq_top AffineSubspace.card_pos_of_affineSpan_eq_top\n\nvariable {P}\n\n/- warning: affine_subspace.not_mem_bot -> AffineSubspace.not_mem_bot is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P), Not (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u1}) {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (p : P), Not (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)) p (Bot.bot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.not_mem_bot AffineSubspace.not_mem_bot\u2093'. -/\n/-- No points are in `\u22a5`. -/\ntheorem not_mem_bot (p : P) : p \u2209 (\u22a5 : AffineSubspace k P) :=\n  Set.not_mem_empty p\n#align affine_subspace.not_mem_bot AffineSubspace.not_mem_bot\n\nvariable (P)\n\n/- warning: affine_subspace.direction_bot -> AffineSubspace.direction_bot is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) (V : Type.{u2}) (P : Type.{u3}) [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)], Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Bot.bot.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasBot.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))\nbut is expected to have type\n  forall (k : Type.{u2}) (V : Type.{u3}) (P : Type.{u1}) [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [S : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)], Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (AffineSubspace.direction.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S (Bot.bot.{u1} (AffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u1} (AffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 S)))) (Bot.bot.{u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (Submodule.instBotSubmodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_bot AffineSubspace.direction_bot\u2093'. -/\n/-- The direction of `\u22a5` is the submodule `\u22a5`. -/\n@[simp]\ntheorem direction_bot : (\u22a5 : AffineSubspace k P).direction = \u22a5 := by\n  rw [direction_eq_vector_span, bot_coe, vectorSpan_def, vsub_empty, Submodule.span_empty]\n#align affine_subspace.direction_bot AffineSubspace.direction_bot\n\nvariable {k V P}\n\n/- warning: affine_subspace.coe_eq_bot_iff -> AffineSubspace.coe_eq_bot_iff is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (Eq.{succ u3} (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) Q) (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P))) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Q (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q) (EmptyCollection.emptyCollection.{u1} (Set.{u1} P) (Set.instEmptyCollectionSet.{u1} P))) (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_eq_bot_iff AffineSubspace.coe_eq_bot_iff\u2093'. -/\n@[simp]\ntheorem coe_eq_bot_iff (Q : AffineSubspace k P) : (Q : Set P) = \u2205 \u2194 Q = \u22a5 :=\n  coe_injective.eq_iff' (bot_coe _ _ _)\n#align affine_subspace.coe_eq_bot_iff AffineSubspace.coe_eq_bot_iff\n\n/- warning: affine_subspace.coe_eq_univ_iff -> AffineSubspace.coe_eq_univ_iff is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (Eq.{succ u3} (Set.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) Q) (Set.univ.{u3} P)) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Q (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (Eq.{succ u1} (Set.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q) (Set.univ.{u1} P)) (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q (Top.top.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_eq_univ_iff AffineSubspace.coe_eq_univ_iff\u2093'. -/\n@[simp]\ntheorem coe_eq_univ_iff (Q : AffineSubspace k P) : (Q : Set P) = univ \u2194 Q = \u22a4 :=\n  coe_injective.eq_iff' (top_coe _ _ _)\n#align affine_subspace.coe_eq_univ_iff AffineSubspace.coe_eq_univ_iff\n\n/- warning: affine_subspace.nonempty_iff_ne_bot -> AffineSubspace.nonempty_iff_ne_bot is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) Q)) (Ne.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Q (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q)) (Ne.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.nonempty_iff_ne_bot AffineSubspace.nonempty_iff_ne_bot\u2093'. -/\ntheorem nonempty_iff_ne_bot (Q : AffineSubspace k P) : (Q : Set P).Nonempty \u2194 Q \u2260 \u22a5 :=\n  by\n  rw [nonempty_iff_ne_empty]\n  exact not_congr Q.coe_eq_bot_iff\n#align affine_subspace.nonempty_iff_ne_bot AffineSubspace.nonempty_iff_ne_bot\n\n/- warning: affine_subspace.eq_bot_or_nonempty -> AffineSubspace.eq_bot_or_nonempty is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Or (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) Q (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) Q))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (Q : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Or (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)))) (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) Q))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.eq_bot_or_nonempty AffineSubspace.eq_bot_or_nonempty\u2093'. -/\ntheorem eq_bot_or_nonempty (Q : AffineSubspace k P) : Q = \u22a5 \u2228 (Q : Set P).Nonempty :=\n  by\n  rw [nonempty_iff_ne_bot]\n  apply eq_or_ne\n#align affine_subspace.eq_bot_or_nonempty AffineSubspace.eq_bot_or_nonempty\n\n/- warning: affine_subspace.subsingleton_of_subsingleton_span_eq_top -> AffineSubspace.subsingleton_of_subsingleton_span_eq_top is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, (Set.Subsingleton.{u3} P s) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Subsingleton.{succ u3} P)\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, (Set.Subsingleton.{u3} P s) -> (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Subsingleton.{succ u3} P)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.subsingleton_of_subsingleton_span_eq_top AffineSubspace.subsingleton_of_subsingleton_span_eq_top\u2093'. -/\ntheorem subsingleton_of_subsingleton_span_eq_top {s : Set P} (h\u2081 : s.Subsingleton)\n    (h\u2082 : affineSpan k s = \u22a4) : Subsingleton P :=\n  by\n  obtain \u27e8p, hp\u27e9 := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h\u2082\n  have : s = {p} := subset.antisymm (fun q hq => h\u2081 hq hp) (by simp [hp])\n  rw [this, \u2190 AffineSubspace.ext_iff, AffineSubspace.coe_affineSpan_singleton,\n    AffineSubspace.top_coe, eq_comm, \u2190 subsingleton_iff_singleton (mem_univ _)] at h\u2082\n  exact subsingleton_of_univ_subsingleton h\u2082\n#align affine_subspace.subsingleton_of_subsingleton_span_eq_top AffineSubspace.subsingleton_of_subsingleton_span_eq_top\n\n/- warning: affine_subspace.eq_univ_of_subsingleton_span_eq_top -> AffineSubspace.eq_univ_of_subsingleton_span_eq_top is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, (Set.Subsingleton.{u3} P s) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Eq.{succ u3} (Set.{u3} P) s (Set.univ.{u3} P))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [S : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, (Set.Subsingleton.{u3} P s) -> (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 S)))) -> (Eq.{succ u3} (Set.{u3} P) s (Set.univ.{u3} P))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.eq_univ_of_subsingleton_span_eq_top AffineSubspace.eq_univ_of_subsingleton_span_eq_top\u2093'. -/\ntheorem eq_univ_of_subsingleton_span_eq_top {s : Set P} (h\u2081 : s.Subsingleton)\n    (h\u2082 : affineSpan k s = \u22a4) : s = (univ : Set P) :=\n  by\n  obtain \u27e8p, hp\u27e9 := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h\u2082\n  have : s = {p} := subset.antisymm (fun q hq => h\u2081 hq hp) (by simp [hp])\n  rw [this, eq_comm, \u2190 subsingleton_iff_singleton (mem_univ p), subsingleton_univ_iff]\n  exact subsingleton_of_subsingleton_span_eq_top h\u2081 h\u2082\n#align affine_subspace.eq_univ_of_subsingleton_span_eq_top AffineSubspace.eq_univ_of_subsingleton_span_eq_top\n\n/- warning: affine_subspace.direction_eq_top_iff_of_nonempty -> AffineSubspace.direction_eq_top_iff_of_nonempty is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s)) -> (Iff (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasTop.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) s (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s)) -> (Iff (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s) (Top.top.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.instTopSubmodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))) (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s (Top.top.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toTop.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_eq_top_iff_of_nonempty AffineSubspace.direction_eq_top_iff_of_nonempty\u2093'. -/\n/-- A nonempty affine subspace is `\u22a4` if and only if its direction is\n`\u22a4`. -/\n@[simp]\ntheorem direction_eq_top_iff_of_nonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) :\n    s.direction = \u22a4 \u2194 s = \u22a4 := by\n  constructor\n  \u00b7 intro hd\n    rw [\u2190 direction_top k V P] at hd\n    refine' ext_of_direction_eq hd _\n    simp [h]\n  \u00b7 rintro rfl\n    simp\n#align affine_subspace.direction_eq_top_iff_of_nonempty AffineSubspace.direction_eq_top_iff_of_nonempty\n\n/- warning: affine_subspace.inf_coe -> AffineSubspace.inf_coe is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Eq.{succ u3} (Set.{u3} P) (Inf.inf.{u3} (Set.{u3} P) (SemilatticeInf.toHasInf.{u3} (Set.{u3} P) (Lattice.toSemilatticeInf.{u3} (Set.{u3} P) (ConditionallyCompleteLattice.toLattice.{u3} (Set.{u3} P) (CompleteLattice.toConditionallyCompleteLattice.{u3} (Set.{u3} P) (Order.Coframe.toCompleteLattice.{u3} (Set.{u3} P) (CompleteDistribLattice.toCoframe.{u3} (Set.{u3} P) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u3} (Set.{u3} P) (Set.completeBooleanAlgebra.{u3} P)))))))) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2)) (Inter.inter.{u3} (Set.{u3} P) (Set.hasInter.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Eq.{succ u1} (Set.{u1} P) (Inf.inf.{u1} (Set.{u1} P) (Lattice.toInf.{u1} (Set.{u1} P) (ConditionallyCompleteLattice.toLattice.{u1} (Set.{u1} P) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Set.{u1} P) (Order.Coframe.toCompleteLattice.{u1} (Set.{u1} P) (CompleteDistribLattice.toCoframe.{u1} (Set.{u1} P) (CompleteBooleanAlgebra.toCompleteDistribLattice.{u1} (Set.{u1} P) (Set.instCompleteBooleanAlgebraSet.{u1} P))))))) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2)) (Inter.inter.{u1} (Set.{u1} P) (Set.instInterSet.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.inf_coe AffineSubspace.inf_coe\u2093'. -/\n/-- The inf of two affine subspaces, coerced to a set, is the\nintersection of the two sets of points. -/\n@[simp]\ntheorem inf_coe (s1 s2 : AffineSubspace k P) : (s1 \u2293 s2 : Set P) = s1 \u2229 s2 :=\n  rfl\n#align affine_subspace.inf_coe AffineSubspace.inf_coe\n\n/- warning: affine_subspace.mem_inf_iff -> AffineSubspace.mem_inf_iff is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p (Inf.inf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeInf.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2)) (And (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s1) (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Iff (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p (Inf.inf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toInf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2)) (And (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s1) (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_inf_iff AffineSubspace.mem_inf_iff\u2093'. -/\n/-- A point is in the inf of two affine subspaces if and only if it is\nin both of them. -/\ntheorem mem_inf_iff (p : P) (s1 s2 : AffineSubspace k P) : p \u2208 s1 \u2293 s2 \u2194 p \u2208 s1 \u2227 p \u2208 s2 :=\n  Iff.rfl\n#align affine_subspace.mem_inf_iff AffineSubspace.mem_inf_iff\n\n/- warning: affine_subspace.direction_inf -> AffineSubspace.direction_inf is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), LE.le.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Inf.inf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeInf.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2)) (Inf.inf.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasInf.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), LE.le.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (OmegaCompletePartialOrder.toPartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.instOmegaCompletePartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S (Inf.inf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toInf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2)) (Inf.inf.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.instInfSubmodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_inf AffineSubspace.direction_inf\u2093'. -/\n/-- The direction of the inf of two affine subspaces is less than or\nequal to the inf of their directions. -/\ntheorem direction_inf (s1 s2 : AffineSubspace k P) :\n    (s1 \u2293 s2).direction \u2264 s1.direction \u2293 s2.direction :=\n  by\n  repeat' rw [direction_eq_vector_span, vectorSpan_def]\n  exact\n    le_inf (inf\u209b_le_inf\u209b fun p hp => trans (vsub_self_mono (inter_subset_left _ _)) hp)\n      (inf\u209b_le_inf\u209b fun p hp => trans (vsub_self_mono (inter_subset_right _ _)) hp)\n#align affine_subspace.direction_inf AffineSubspace.direction_inf\n\n/- warning: affine_subspace.direction_inf_of_mem -> AffineSubspace.direction_inf_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s\u2081) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p s\u2082) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Inf.inf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeInf.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) s\u2081 s\u2082)) (Inf.inf.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasInf.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s\u2081) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s\u2082)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s\u2081) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p s\u2082) -> (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S (Inf.inf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toInf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)))) s\u2081 s\u2082)) (Inf.inf.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.instInfSubmodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s\u2081) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s\u2082)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_inf_of_mem AffineSubspace.direction_inf_of_mem\u2093'. -/\n/-- If two affine subspaces have a point in common, the direction of\ntheir inf equals the inf of their directions. -/\ntheorem direction_inf_of_mem {s\u2081 s\u2082 : AffineSubspace k P} {p : P} (h\u2081 : p \u2208 s\u2081) (h\u2082 : p \u2208 s\u2082) :\n    (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\n  by\n  ext v\n  rw [Submodule.mem_inf, \u2190 vadd_mem_iff_mem_direction v h\u2081, \u2190 vadd_mem_iff_mem_direction v h\u2082, \u2190\n    vadd_mem_iff_mem_direction v ((mem_inf_iff p s\u2081 s\u2082).2 \u27e8h\u2081, h\u2082\u27e9), mem_inf_iff]\n#align affine_subspace.direction_inf_of_mem AffineSubspace.direction_inf_of_mem\n\n/- warning: affine_subspace.direction_inf_of_mem_inf -> AffineSubspace.direction_inf_of_mem_inf is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {p : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)) p (Inf.inf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeInf.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) s\u2081 s\u2082)) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Inf.inf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeInf.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeInf.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) s\u2081 s\u2082)) (Inf.inf.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasInf.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s\u2081) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s\u2082)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {p : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)) p (Inf.inf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toInf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)))) s\u2081 s\u2082)) -> (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S (Inf.inf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toInf.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S)))) s\u2081 s\u2082)) (Inf.inf.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.instInfSubmodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s\u2081) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s\u2082)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_inf_of_mem_inf AffineSubspace.direction_inf_of_mem_inf\u2093'. -/\n/-- If two affine subspaces have a point in their inf, the direction\nof their inf equals the inf of their directions. -/\ntheorem direction_inf_of_mem_inf {s\u2081 s\u2082 : AffineSubspace k P} {p : P} (h : p \u2208 s\u2081 \u2293 s\u2082) :\n    (s\u2081 \u2293 s\u2082).direction = s\u2081.direction \u2293 s\u2082.direction :=\n  direction_inf_of_mem ((mem_inf_iff p s\u2081 s\u2082).1 h).1 ((mem_inf_iff p s\u2081 s\u2082).1 h).2\n#align affine_subspace.direction_inf_of_mem_inf AffineSubspace.direction_inf_of_mem_inf\n\n/- warning: affine_subspace.direction_le -> AffineSubspace.direction_le is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) -> (LE.le.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (LE.le.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLE.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) -> (LE.le.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (OmegaCompletePartialOrder.toPartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.instOmegaCompletePartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_le AffineSubspace.direction_le\u2093'. -/\n/-- If one affine subspace is less than or equal to another, the same\napplies to their directions. -/\ntheorem direction_le {s1 s2 : AffineSubspace k P} (h : s1 \u2264 s2) : s1.direction \u2264 s2.direction :=\n  by\n  repeat' rw [direction_eq_vector_span, vectorSpan_def]\n  exact vectorSpan_mono k h\n#align affine_subspace.direction_le AffineSubspace.direction_le\n\n/- warning: affine_subspace.direction_lt_of_nonempty -> AffineSubspace.direction_lt_of_nonempty is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (LT.lt.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1 s2) -> (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1)) -> (LT.lt.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLT.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (LT.lt.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Preorder.toLT.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2) -> (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1)) -> (LT.lt.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLT.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (OmegaCompletePartialOrder.toPartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.instOmegaCompletePartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_lt_of_nonempty AffineSubspace.direction_lt_of_nonempty\u2093'. -/\n/-- If one nonempty affine subspace is less than another, the same\napplies to their directions -/\ntheorem direction_lt_of_nonempty {s1 s2 : AffineSubspace k P} (h : s1 < s2)\n    (hn : (s1 : Set P).Nonempty) : s1.direction < s2.direction :=\n  by\n  cases' hn with p hp\n  rw [lt_iff_le_and_exists] at h\n  rcases h with \u27e8hle, p2, hp2, hp2s1\u27e9\n  rw [SetLike.lt_iff_le_and_exists]\n  use direction_le hle, p2 -\u1d65 p, vsub_mem_direction hp2 (hle hp)\n  intro hm\n  rw [vsub_right_mem_direction_iff_mem hp p2] at hm\n  exact hp2s1 hm\n#align affine_subspace.direction_lt_of_nonempty AffineSubspace.direction_lt_of_nonempty\n\n/- warning: affine_subspace.sup_direction_le -> AffineSubspace.sup_direction_le is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), LE.le.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (Sup.sup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toHasSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s2)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Sup.sup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeSup.toHasSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), LE.le.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLE.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (OmegaCompletePartialOrder.toPartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.instOmegaCompletePartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (Sup.sup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s2)) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S (Sup.sup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeSup.toSup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeSup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.sup_direction_le AffineSubspace.sup_direction_le\u2093'. -/\n/-- The sup of the directions of two affine subspaces is less than or\nequal to the direction of their sup. -/\ntheorem sup_direction_le (s1 s2 : AffineSubspace k P) :\n    s1.direction \u2294 s2.direction \u2264 (s1 \u2294 s2).direction :=\n  by\n  repeat' rw [direction_eq_vector_span, vectorSpan_def]\n  exact\n    sup_le\n      (inf\u209b_le_inf\u209b fun p hp => Set.Subset.trans (vsub_self_mono (le_sup_left : s1 \u2264 s1 \u2294 s2)) hp)\n      (inf\u209b_le_inf\u209b fun p hp => Set.Subset.trans (vsub_self_mono (le_sup_right : s2 \u2264 s1 \u2294 s2)) hp)\n#align affine_subspace.sup_direction_le AffineSubspace.sup_direction_le\n\n/- warning: affine_subspace.sup_direction_lt_of_nonempty_of_inter_empty -> AffineSubspace.sup_direction_lt_of_nonempty_of_inter_empty is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1)) -> (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2)) -> (Eq.{succ u3} (Set.{u3} P) (Inter.inter.{u3} (Set.{u3} P) (Set.hasInter.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2)) (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P))) -> (LT.lt.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLT.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) (Sup.sup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toHasSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s2)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S (Sup.sup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeSup.toHasSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1)) -> (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2)) -> (Eq.{succ u1} (Set.{u1} P) (Inter.inter.{u1} (Set.{u1} P) (Set.instInterSet.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} P) (Set.instEmptyCollectionSet.{u1} P))) -> (LT.lt.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Preorder.toLT.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (OmegaCompletePartialOrder.toPartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.instOmegaCompletePartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (Sup.sup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s2)) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S (Sup.sup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (SemilatticeSup.toSup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (Lattice.toSemilatticeSup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S))))) s1 s2)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.sup_direction_lt_of_nonempty_of_inter_empty AffineSubspace.sup_direction_lt_of_nonempty_of_inter_empty\u2093'. -/\n/-- The sup of the directions of two nonempty affine subspaces with\nempty intersection is less than the direction of their sup. -/\ntheorem sup_direction_lt_of_nonempty_of_inter_empty {s1 s2 : AffineSubspace k P}\n    (h1 : (s1 : Set P).Nonempty) (h2 : (s2 : Set P).Nonempty) (he : (s1 \u2229 s2 : Set P) = \u2205) :\n    s1.direction \u2294 s2.direction < (s1 \u2294 s2).direction :=\n  by\n  cases' h1 with p1 hp1\n  cases' h2 with p2 hp2\n  rw [SetLike.lt_iff_le_and_exists]\n  use sup_direction_le s1 s2, p2 -\u1d65 p1,\n    vsub_mem_direction ((le_sup_right : s2 \u2264 s1 \u2294 s2) hp2) ((le_sup_left : s1 \u2264 s1 \u2294 s2) hp1)\n  intro h\n  rw [Submodule.mem_sup] at h\n  rcases h with \u27e8v1, hv1, v2, hv2, hv1v2\u27e9\n  rw [\u2190 sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc, \u2190\n    vadd_vsub_assoc, \u2190 neg_neg v2, add_comm, \u2190 sub_eq_add_neg, \u2190 vsub_vadd_eq_vsub_sub,\n    vsub_eq_zero_iff_eq] at hv1v2\n  refine' Set.Nonempty.ne_empty _ he\n  use v1 +\u1d65 p1, vadd_mem_of_mem_direction hv1 hp1\n  rw [hv1v2]\n  exact vadd_mem_of_mem_direction (Submodule.neg_mem _ hv2) hp2\n#align affine_subspace.sup_direction_lt_of_nonempty_of_inter_empty AffineSubspace.sup_direction_lt_of_nonempty_of_inter_empty\n\n/- warning: affine_subspace.inter_nonempty_of_nonempty_of_sup_direction_eq_top -> AffineSubspace.inter_nonempty_of_nonempty_of_sup_direction_eq_top is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1)) -> (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2)) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Sup.sup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toHasSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s2)) (Top.top.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasTop.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))) -> (Set.Nonempty.{u3} P (Inter.inter.{u3} (Set.{u3} P) (Set.hasInter.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1)) -> (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2)) -> (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Sup.sup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s2)) (Top.top.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.instTopSubmodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))) -> (Set.Nonempty.{u1} P (Inter.inter.{u1} (Set.{u1} P) (Set.instInterSet.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.inter_nonempty_of_nonempty_of_sup_direction_eq_top AffineSubspace.inter_nonempty_of_nonempty_of_sup_direction_eq_top\u2093'. -/\n/-- If the directions of two nonempty affine subspaces span the whole\nmodule, they have nonempty intersection. -/\ntheorem inter_nonempty_of_nonempty_of_sup_direction_eq_top {s1 s2 : AffineSubspace k P}\n    (h1 : (s1 : Set P).Nonempty) (h2 : (s2 : Set P).Nonempty)\n    (hd : s1.direction \u2294 s2.direction = \u22a4) : ((s1 : Set P) \u2229 s2).Nonempty :=\n  by\n  by_contra h\n  rw [Set.not_nonempty_iff_eq_empty] at h\n  have hlt := sup_direction_lt_of_nonempty_of_inter_empty h1 h2 h\n  rw [hd] at hlt\n  exact not_top_lt hlt\n#align affine_subspace.inter_nonempty_of_nonempty_of_sup_direction_eq_top AffineSubspace.inter_nonempty_of_nonempty_of_sup_direction_eq_top\n\n/- warning: affine_subspace.inter_eq_singleton_of_nonempty_of_is_compl -> AffineSubspace.inter_eq_singleton_of_nonempty_of_isCompl is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1)) -> (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2)) -> (IsCompl.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (CompleteLattice.toBoundedOrder.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S s2)) -> (Exists.{succ u3} P (fun (p : P) => Eq.{succ u3} (Set.{u3} P) (Inter.inter.{u3} (Set.{u3} P) (Set.hasInter.{u3} P) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s1) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s2)) (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S}, (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1)) -> (Set.Nonempty.{u1} P (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2)) -> (IsCompl.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (OmegaCompletePartialOrder.toPartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.instOmegaCompletePartialOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))) (CompleteLattice.toBoundedOrder.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S s2)) -> (Exists.{succ u1} P (fun (p : P) => Eq.{succ u1} (Set.{u1} P) (Inter.inter.{u1} (Set.{u1} P) (Set.instInterSet.{u1} P) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s1) (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s2)) (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.inter_eq_singleton_of_nonempty_of_is_compl AffineSubspace.inter_eq_singleton_of_nonempty_of_isCompl\u2093'. -/\n/-- If the directions of two nonempty affine subspaces are complements\nof each other, they intersect in exactly one point. -/\ntheorem inter_eq_singleton_of_nonempty_of_isCompl {s1 s2 : AffineSubspace k P}\n    (h1 : (s1 : Set P).Nonempty) (h2 : (s2 : Set P).Nonempty)\n    (hd : IsCompl s1.direction s2.direction) : \u2203 p, (s1 : Set P) \u2229 s2 = {p} :=\n  by\n  cases' inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top with p hp\n  use p\n  ext q\n  rw [Set.mem_singleton_iff]\n  constructor\n  \u00b7 rintro \u27e8hq1, hq2\u27e9\n    have hqp : q -\u1d65 p \u2208 s1.direction \u2293 s2.direction :=\n      \u27e8vsub_mem_direction hq1 hp.1, vsub_mem_direction hq2 hp.2\u27e9\n    rwa [hd.inf_eq_bot, Submodule.mem_bot, vsub_eq_zero_iff_eq] at hqp\n  \u00b7 exact fun h => h.symm \u25b8 hp\n#align affine_subspace.inter_eq_singleton_of_nonempty_of_is_compl AffineSubspace.inter_eq_singleton_of_nonempty_of_isCompl\n\n/- warning: affine_subspace.affine_span_coe -> AffineSubspace.affineSpan_coe is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 S)))) s)) s\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [S : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S), Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) (affineSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 S) s)) s\nCase conversion may be inaccurate. Consider using '#align affine_subspace.affine_span_coe AffineSubspace.affineSpan_coe\u2093'. -/\n/-- Coercing a subspace to a set then taking the affine span produces\nthe original subspace. -/\n@[simp]\ntheorem affineSpan_coe (s : AffineSubspace k P) : affineSpan k (s : Set P) = s :=\n  by\n  refine' le_antisymm _ (subset_spanPoints _ _)\n  rintro p \u27e8p1, hp1, v, hv, rfl\u27e9\n  exact vadd_mem_of_mem_direction hv hp1\n#align affine_subspace.affine_span_coe AffineSubspace.affineSpan_coe\n\nend AffineSubspace\n\nsection AffineSpace'\n\nvariable (k : Type _) {V : Type _} {P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n  [affine_space V P]\n\nvariable {\u03b9 : Type _}\n\ninclude V\n\nopen AffineSubspace Set\n\n#print vectorSpan_eq_span_vsub_set_left /-\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left. -/\ntheorem vectorSpan_eq_span_vsub_set_left {s : Set P} {p : P} (hp : p \u2208 s) :\n    vectorSpan k s = Submodule.span k ((\u00b7 -\u1d65 \u00b7) p '' s) :=\n  by\n  rw [vectorSpan_def]\n  refine' le_antisymm _ (Submodule.span_mono _)\n  \u00b7 rw [Submodule.span_le]\n    rintro v \u27e8p1, p2, hp1, hp2, hv\u27e9\n    rw [\u2190 vsub_sub_vsub_cancel_left p1 p2 p] at hv\n    rw [\u2190 hv, SetLike.mem_coe, Submodule.mem_span]\n    exact fun m hm => Submodule.sub_mem _ (hm \u27e8p2, hp2, rfl\u27e9) (hm \u27e8p1, hp1, rfl\u27e9)\n  \u00b7 rintro v \u27e8p2, hp2, hv\u27e9\n    exact \u27e8p, p2, hp, hp2, hv\u27e9\n#align vector_span_eq_span_vsub_set_left vectorSpan_eq_span_vsub_set_left\n-/\n\n#print vectorSpan_eq_span_vsub_set_right /-\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right. -/\ntheorem vectorSpan_eq_span_vsub_set_right {s : Set P} {p : P} (hp : p \u2208 s) :\n    vectorSpan k s = Submodule.span k ((\u00b7 -\u1d65 p) '' s) :=\n  by\n  rw [vectorSpan_def]\n  refine' le_antisymm _ (Submodule.span_mono _)\n  \u00b7 rw [Submodule.span_le]\n    rintro v \u27e8p1, p2, hp1, hp2, hv\u27e9\n    rw [\u2190 vsub_sub_vsub_cancel_right p1 p2 p] at hv\n    rw [\u2190 hv, SetLike.mem_coe, Submodule.mem_span]\n    exact fun m hm => Submodule.sub_mem _ (hm \u27e8p1, hp1, rfl\u27e9) (hm \u27e8p2, hp2, rfl\u27e9)\n  \u00b7 rintro v \u27e8p2, hp2, hv\u27e9\n    exact \u27e8p2, p, hp2, hp, hv\u27e9\n#align vector_span_eq_span_vsub_set_right vectorSpan_eq_span_vsub_set_right\n-/\n\n/- warning: vector_span_eq_span_vsub_set_left_ne -> vectorSpan_eq_span_vsub_set_left_ne is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {p : P}, (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p s) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.image.{u3, u2} P V (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p) (SDiff.sdiff.{u3} (Set.{u3} P) (BooleanAlgebra.toHasSdiff.{u3} (Set.{u3} P) (Set.booleanAlgebra.{u3} P)) s (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p)))))\nbut is expected to have type\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {p : P}, (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p s) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.image.{u3, u2} P V ((fun (x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11114 : P) (x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11116 : P) => VSub.vsub.{u2, u3} V P (AddTorsor.toVSub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11114 x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11116) p) (SDiff.sdiff.{u3} (Set.{u3} P) (Set.instSDiffSet.{u3} P) s (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p)))))\nCase conversion may be inaccurate. Consider using '#align vector_span_eq_span_vsub_set_left_ne vectorSpan_eq_span_vsub_set_left_ne\u2093'. -/\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the left, excluding the subtraction of that point from\nitself. -/\ntheorem vectorSpan_eq_span_vsub_set_left_ne {s : Set P} {p : P} (hp : p \u2208 s) :\n    vectorSpan k s = Submodule.span k ((\u00b7 -\u1d65 \u00b7) p '' (s \\ {p})) :=\n  by\n  conv_lhs =>\n    rw [vectorSpan_eq_span_vsub_set_left k hp, \u2190 Set.insert_eq_of_mem hp, \u2190\n      Set.insert_diff_singleton, Set.image_insert_eq]\n  simp [Submodule.span_insert_eq_span]\n#align vector_span_eq_span_vsub_set_left_ne vectorSpan_eq_span_vsub_set_left_ne\n\n/- warning: vector_span_eq_span_vsub_set_right_ne -> vectorSpan_eq_span_vsub_set_right_ne is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {p : P}, (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) p s) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.image.{u3, u2} P V (fun (_x : P) => VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) _x p) (SDiff.sdiff.{u3} (Set.{u3} P) (BooleanAlgebra.toHasSdiff.{u3} (Set.{u3} P) (Set.booleanAlgebra.{u3} P)) s (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p)))))\nbut is expected to have type\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {p : P}, (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) p s) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.image.{u3, u2} P V (fun (_x : P) => VSub.vsub.{u2, u3} V P (AddTorsor.toVSub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) _x p) (SDiff.sdiff.{u3} (Set.{u3} P) (Set.instSDiffSet.{u3} P) s (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p)))))\nCase conversion may be inaccurate. Consider using '#align vector_span_eq_span_vsub_set_right_ne vectorSpan_eq_span_vsub_set_right_ne\u2093'. -/\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right, excluding the subtraction of that point from\nitself. -/\ntheorem vectorSpan_eq_span_vsub_set_right_ne {s : Set P} {p : P} (hp : p \u2208 s) :\n    vectorSpan k s = Submodule.span k ((\u00b7 -\u1d65 p) '' (s \\ {p})) :=\n  by\n  conv_lhs =>\n    rw [vectorSpan_eq_span_vsub_set_right k hp, \u2190 Set.insert_eq_of_mem hp, \u2190\n      Set.insert_diff_singleton, Set.image_insert_eq]\n  simp [Submodule.span_insert_eq_span]\n#align vector_span_eq_span_vsub_set_right_ne vectorSpan_eq_span_vsub_set_right_ne\n\n#print vectorSpan_eq_span_vsub_finset_right_ne /-\n/-- The `vector_span` is the span of the pairwise subtractions with a\ngiven point on the right, excluding the subtraction of that point from\nitself. -/\ntheorem vectorSpan_eq_span_vsub_finset_right_ne [DecidableEq P] [DecidableEq V] {s : Finset P}\n    {p : P} (hp : p \u2208 s) :\n    vectorSpan k (s : Set P) = Submodule.span k ((s.erase\u2093 p).image (\u00b7 -\u1d65 p)) := by\n  simp [vectorSpan_eq_span_vsub_set_right_ne _ (finset.mem_coe.mpr hp)]\n#align vector_span_eq_span_vsub_finset_right_ne vectorSpan_eq_span_vsub_finset_right_ne\n-/\n\n/- warning: vector_span_image_eq_span_vsub_set_left_ne -> vectorSpan_image_eq_span_vsub_set_left_ne is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) {s : Set.{u4} \u03b9} {i : \u03b9}, (Membership.Mem.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.hasMem.{u4} \u03b9) i s) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.image.{u4, u3} \u03b9 P p s)) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.image.{u3, u2} P V (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) (p i)) (Set.image.{u4, u3} \u03b9 P p (SDiff.sdiff.{u4} (Set.{u4} \u03b9) (BooleanAlgebra.toHasSdiff.{u4} (Set.{u4} \u03b9) (Set.booleanAlgebra.{u4} \u03b9)) s (Singleton.singleton.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.hasSingleton.{u4} \u03b9) i))))))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) {s : Set.{u4} \u03b9} {i : \u03b9}, (Membership.mem.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.instMembershipSet.{u4} \u03b9) i s) -> (Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.image.{u4, u1} \u03b9 P p s)) (Submodule.span.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3 (Set.image.{u1, u3} P V ((fun (x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11422 : P) (x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11424 : P) => VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11422 x._@.Mathlib.LinearAlgebra.AffineSpace.AffineSubspace._hyg.11424) (p i)) (Set.image.{u4, u1} \u03b9 P p (SDiff.sdiff.{u4} (Set.{u4} \u03b9) (Set.instSDiffSet.{u4} \u03b9) s (Singleton.singleton.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.instSingletonSet.{u4} \u03b9) i))))))\nCase conversion may be inaccurate. Consider using '#align vector_span_image_eq_span_vsub_set_left_ne vectorSpan_image_eq_span_vsub_set_left_ne\u2093'. -/\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the left, excluding the\nsubtraction of that point from itself. -/\ntheorem vectorSpan_image_eq_span_vsub_set_left_ne (p : \u03b9 \u2192 P) {s : Set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n    vectorSpan k (p '' s) = Submodule.span k ((\u00b7 -\u1d65 \u00b7) (p i) '' (p '' (s \\ {i}))) :=\n  by\n  conv_lhs =>\n    rw [vectorSpan_eq_span_vsub_set_left k (Set.mem_image_of_mem p hi), \u2190 Set.insert_eq_of_mem hi, \u2190\n      Set.insert_diff_singleton, Set.image_insert_eq, Set.image_insert_eq]\n  simp [Submodule.span_insert_eq_span]\n#align vector_span_image_eq_span_vsub_set_left_ne vectorSpan_image_eq_span_vsub_set_left_ne\n\n/- warning: vector_span_image_eq_span_vsub_set_right_ne -> vectorSpan_image_eq_span_vsub_set_right_ne is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) {s : Set.{u4} \u03b9} {i : \u03b9}, (Membership.Mem.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.hasMem.{u4} \u03b9) i s) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.image.{u4, u3} \u03b9 P p s)) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.image.{u3, u2} P V (fun (_x : P) => VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) _x (p i)) (Set.image.{u4, u3} \u03b9 P p (SDiff.sdiff.{u4} (Set.{u4} \u03b9) (BooleanAlgebra.toHasSdiff.{u4} (Set.{u4} \u03b9) (Set.booleanAlgebra.{u4} \u03b9)) s (Singleton.singleton.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.hasSingleton.{u4} \u03b9) i))))))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) {s : Set.{u4} \u03b9} {i : \u03b9}, (Membership.mem.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.instMembershipSet.{u4} \u03b9) i s) -> (Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.image.{u4, u1} \u03b9 P p s)) (Submodule.span.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3 (Set.image.{u1, u3} P V (fun (_x : P) => VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) _x (p i)) (Set.image.{u4, u1} \u03b9 P p (SDiff.sdiff.{u4} (Set.{u4} \u03b9) (Set.instSDiffSet.{u4} \u03b9) s (Singleton.singleton.{u4, u4} \u03b9 (Set.{u4} \u03b9) (Set.instSingletonSet.{u4} \u03b9) i))))))\nCase conversion may be inaccurate. Consider using '#align vector_span_image_eq_span_vsub_set_right_ne vectorSpan_image_eq_span_vsub_set_right_ne\u2093'. -/\n/-- The `vector_span` of the image of a function is the span of the\npairwise subtractions with a given point on the right, excluding the\nsubtraction of that point from itself. -/\ntheorem vectorSpan_image_eq_span_vsub_set_right_ne (p : \u03b9 \u2192 P) {s : Set \u03b9} {i : \u03b9} (hi : i \u2208 s) :\n    vectorSpan k (p '' s) = Submodule.span k ((\u00b7 -\u1d65 p i) '' (p '' (s \\ {i}))) :=\n  by\n  conv_lhs =>\n    rw [vectorSpan_eq_span_vsub_set_right k (Set.mem_image_of_mem p hi), \u2190 Set.insert_eq_of_mem hi,\n      \u2190 Set.insert_diff_singleton, Set.image_insert_eq, Set.image_insert_eq]\n  simp [Submodule.span_insert_eq_span]\n#align vector_span_image_eq_span_vsub_set_right_ne vectorSpan_image_eq_span_vsub_set_right_ne\n\n/- warning: vector_span_range_eq_span_range_vsub_left -> vectorSpan_range_eq_span_range_vsub_left is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) (i0 : \u03b9), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u3, succ u4} P \u03b9 p)) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.range.{u2, succ u4} V \u03b9 (fun (i : \u03b9) => VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) (p i0) (p i))))\nbut is expected to have type\n  forall (k : Type.{u3}) {V : Type.{u4}} {P : Type.{u2}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u4} V] [_inst_3 : Module.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2)] [_inst_4 : AddTorsor.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2)] {\u03b9 : Type.{u1}} (p : \u03b9 -> P) (i0 : \u03b9), Eq.{succ u4} (Submodule.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3) (vectorSpan.{u3, u4, u2} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u2, succ u1} P \u03b9 p)) (Submodule.span.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3 (Set.range.{u4, succ u1} V \u03b9 (fun (i : \u03b9) => VSub.vsub.{u4, u2} V P (AddTorsor.toVSub.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2) _inst_4) (p i0) (p i))))\nCase conversion may be inaccurate. Consider using '#align vector_span_range_eq_span_range_vsub_left vectorSpan_range_eq_span_range_vsub_left\u2093'. -/\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left. -/\ntheorem vectorSpan_range_eq_span_range_vsub_left (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n    vectorSpan k (Set.range p) = Submodule.span k (Set.range fun i : \u03b9 => p i0 -\u1d65 p i) := by\n  rw [vectorSpan_eq_span_vsub_set_left k (Set.mem_range_self i0), \u2190 Set.range_comp]\n#align vector_span_range_eq_span_range_vsub_left vectorSpan_range_eq_span_range_vsub_left\n\n/- warning: vector_span_range_eq_span_range_vsub_right -> vectorSpan_range_eq_span_range_vsub_right is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) (i0 : \u03b9), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u3, succ u4} P \u03b9 p)) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.range.{u2, succ u4} V \u03b9 (fun (i : \u03b9) => VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) (p i) (p i0))))\nbut is expected to have type\n  forall (k : Type.{u3}) {V : Type.{u4}} {P : Type.{u2}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u4} V] [_inst_3 : Module.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2)] [_inst_4 : AddTorsor.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2)] {\u03b9 : Type.{u1}} (p : \u03b9 -> P) (i0 : \u03b9), Eq.{succ u4} (Submodule.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3) (vectorSpan.{u3, u4, u2} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u2, succ u1} P \u03b9 p)) (Submodule.span.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3 (Set.range.{u4, succ u1} V \u03b9 (fun (i : \u03b9) => VSub.vsub.{u4, u2} V P (AddTorsor.toVSub.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2) _inst_4) (p i) (p i0))))\nCase conversion may be inaccurate. Consider using '#align vector_span_range_eq_span_range_vsub_right vectorSpan_range_eq_span_range_vsub_right\u2093'. -/\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right. -/\ntheorem vectorSpan_range_eq_span_range_vsub_right (p : \u03b9 \u2192 P) (i0 : \u03b9) :\n    vectorSpan k (Set.range p) = Submodule.span k (Set.range fun i : \u03b9 => p i -\u1d65 p i0) := by\n  rw [vectorSpan_eq_span_vsub_set_right k (Set.mem_range_self i0), \u2190 Set.range_comp]\n#align vector_span_range_eq_span_range_vsub_right vectorSpan_range_eq_span_range_vsub_right\n\n/- warning: vector_span_range_eq_span_range_vsub_left_ne -> vectorSpan_range_eq_span_range_vsub_left_ne is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) (i\u2080 : \u03b9), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u3, succ u4} P \u03b9 p)) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.range.{u2, succ u4} V (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) (fun (i : Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) => VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) (p i\u2080) (p ((fun (a : Type.{u4}) (b : Type.{u4}) [self : HasLiftT.{succ u4, succ u4} a b] => self.0) (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (HasLiftT.mk.{succ u4, succ u4} (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (CoeTC\u2093.coe.{succ u4, succ u4} (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (coeBase.{succ u4, succ u4} (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (coeSubtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080))))) i)))))\nbut is expected to have type\n  forall (k : Type.{u3}) {V : Type.{u4}} {P : Type.{u2}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u4} V] [_inst_3 : Module.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2)] [_inst_4 : AddTorsor.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2)] {\u03b9 : Type.{u1}} (p : \u03b9 -> P) (i\u2080 : \u03b9), Eq.{succ u4} (Submodule.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3) (vectorSpan.{u3, u4, u2} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u2, succ u1} P \u03b9 p)) (Submodule.span.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3 (Set.range.{u4, succ u1} V (Subtype.{succ u1} \u03b9 (fun (x : \u03b9) => Ne.{succ u1} \u03b9 x i\u2080)) (fun (i : Subtype.{succ u1} \u03b9 (fun (x : \u03b9) => Ne.{succ u1} \u03b9 x i\u2080)) => VSub.vsub.{u4, u2} V P (AddTorsor.toVSub.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2) _inst_4) (p i\u2080) (p (Subtype.val.{succ u1} \u03b9 (fun (x : \u03b9) => Ne.{succ u1} \u03b9 x i\u2080) i)))))\nCase conversion may be inaccurate. Consider using '#align vector_span_range_eq_span_range_vsub_left_ne vectorSpan_range_eq_span_range_vsub_left_ne\u2093'. -/\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the left, excluding the subtraction\nof that point from itself. -/\ntheorem vectorSpan_range_eq_span_range_vsub_left_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n    vectorSpan k (Set.range p) =\n      Submodule.span k (Set.range fun i : { x // x \u2260 i\u2080 } => p i\u2080 -\u1d65 p i) :=\n  by\n  rw [\u2190 Set.image_univ, vectorSpan_image_eq_span_vsub_set_left_ne k _ (Set.mem_univ i\u2080)]\n  congr with v\n  simp only [Set.mem_range, Set.mem_image, Set.mem_diff, Set.mem_singleton_iff, Subtype.exists,\n    Subtype.coe_mk]\n  constructor\n  \u00b7 rintro \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9\n  \u00b7 exact fun \u27e8i\u2081, hi\u2081, hv\u27e9 => \u27e8p i\u2081, \u27e8i\u2081, \u27e8Set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9\n#align vector_span_range_eq_span_range_vsub_left_ne vectorSpan_range_eq_span_range_vsub_left_ne\n\n/- warning: vector_span_range_eq_span_range_vsub_right_ne -> vectorSpan_range_eq_span_range_vsub_right_ne is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {\u03b9 : Type.{u4}} (p : \u03b9 -> P) (i\u2080 : \u03b9), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u3, succ u4} P \u03b9 p)) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.range.{u2, succ u4} V (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) (fun (i : Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) => VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) (p ((fun (a : Type.{u4}) (b : Type.{u4}) [self : HasLiftT.{succ u4, succ u4} a b] => self.0) (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (HasLiftT.mk.{succ u4, succ u4} (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (CoeTC\u2093.coe.{succ u4, succ u4} (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (coeBase.{succ u4, succ u4} (Subtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080)) \u03b9 (coeSubtype.{succ u4} \u03b9 (fun (x : \u03b9) => Ne.{succ u4} \u03b9 x i\u2080))))) i)) (p i\u2080))))\nbut is expected to have type\n  forall (k : Type.{u3}) {V : Type.{u4}} {P : Type.{u2}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u4} V] [_inst_3 : Module.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2)] [_inst_4 : AddTorsor.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2)] {\u03b9 : Type.{u1}} (p : \u03b9 -> P) (i\u2080 : \u03b9), Eq.{succ u4} (Submodule.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3) (vectorSpan.{u3, u4, u2} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Set.range.{u2, succ u1} P \u03b9 p)) (Submodule.span.{u3, u4} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V _inst_2) _inst_3 (Set.range.{u4, succ u1} V (Subtype.{succ u1} \u03b9 (fun (x : \u03b9) => Ne.{succ u1} \u03b9 x i\u2080)) (fun (i : Subtype.{succ u1} \u03b9 (fun (x : \u03b9) => Ne.{succ u1} \u03b9 x i\u2080)) => VSub.vsub.{u4, u2} V P (AddTorsor.toVSub.{u4, u2} V P (AddCommGroup.toAddGroup.{u4} V _inst_2) _inst_4) (p (Subtype.val.{succ u1} \u03b9 (fun (x : \u03b9) => Ne.{succ u1} \u03b9 x i\u2080) i)) (p i\u2080))))\nCase conversion may be inaccurate. Consider using '#align vector_span_range_eq_span_range_vsub_right_ne vectorSpan_range_eq_span_range_vsub_right_ne\u2093'. -/\n/-- The `vector_span` of an indexed family is the span of the pairwise\nsubtractions with a given point on the right, excluding the subtraction\nof that point from itself. -/\ntheorem vectorSpan_range_eq_span_range_vsub_right_ne (p : \u03b9 \u2192 P) (i\u2080 : \u03b9) :\n    vectorSpan k (Set.range p) =\n      Submodule.span k (Set.range fun i : { x // x \u2260 i\u2080 } => p i -\u1d65 p i\u2080) :=\n  by\n  rw [\u2190 Set.image_univ, vectorSpan_image_eq_span_vsub_set_right_ne k _ (Set.mem_univ i\u2080)]\n  congr with v\n  simp only [Set.mem_range, Set.mem_image, Set.mem_diff, Set.mem_singleton_iff, Subtype.exists,\n    Subtype.coe_mk]\n  constructor\n  \u00b7 rintro \u27e8x, \u27e8i\u2081, \u27e8\u27e8hi\u2081u, hi\u2081\u27e9, rfl\u27e9\u27e9, hv\u27e9\n    exact \u27e8i\u2081, hi\u2081, hv\u27e9\n  \u00b7 exact fun \u27e8i\u2081, hi\u2081, hv\u27e9 => \u27e8p i\u2081, \u27e8i\u2081, \u27e8Set.mem_univ _, hi\u2081\u27e9, rfl\u27e9, hv\u27e9\n#align vector_span_range_eq_span_range_vsub_right_ne vectorSpan_range_eq_span_range_vsub_right_ne\n\nsection\n\nvariable {s : Set P}\n\n/- warning: affine_span_nonempty -> affineSpan_nonempty is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, Iff (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Set.Nonempty.{u3} P s)\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, Iff (Set.Nonempty.{u3} P (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s))) (Set.Nonempty.{u3} P s)\nCase conversion may be inaccurate. Consider using '#align affine_span_nonempty affineSpan_nonempty\u2093'. -/\n/-- The affine span of a set is nonempty if and only if that set is. -/\ntheorem affineSpan_nonempty : (affineSpan k s : Set P).Nonempty \u2194 s.Nonempty :=\n  spanPoints_nonempty k s\n#align affine_span_nonempty affineSpan_nonempty\n\n/- warning: set.nonempty.affine_span -> Set.Nonempty.affineSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, (Set.Nonempty.{u3} P s) -> (Set.Nonempty.{u3} P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, (Set.Nonempty.{u3} P s) -> (Set.Nonempty.{u3} P (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))\nCase conversion may be inaccurate. Consider using '#align set.nonempty.affine_span Set.Nonempty.affineSpan\u2093'. -/\nalias affineSpan_nonempty \u2194 _ _root_.set.nonempty.affine_span\n#align set.nonempty.affine_span Set.Nonempty.affineSpan\n\n/-- The affine span of a nonempty set is nonempty. -/\ninstance [Nonempty s] : Nonempty (affineSpan k s) :=\n  ((nonempty_coe_sort.1 \u2039_\u203a).affineSpan _).to_subtype\n\n/- warning: affine_span_eq_bot -> affineSpan_eq_bot is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, Iff (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u3} (Set.{u3} P) s (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, Iff (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) (Bot.bot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u3} (Set.{u3} P) s (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.instEmptyCollectionSet.{u3} P)))\nCase conversion may be inaccurate. Consider using '#align affine_span_eq_bot affineSpan_eq_bot\u2093'. -/\n/-- The affine span of a set is `\u22a5` if and only if that set is empty. -/\n@[simp]\ntheorem affineSpan_eq_bot : affineSpan k s = \u22a5 \u2194 s = \u2205 := by\n  rw [\u2190 not_iff_not, \u2190 Ne.def, \u2190 Ne.def, \u2190 nonempty_iff_ne_bot, affineSpan_nonempty,\n    nonempty_iff_ne_empty]\n#align affine_span_eq_bot affineSpan_eq_bot\n\n/- warning: bot_lt_affine_span -> bot_lt_affineSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P}, Iff (LT.lt.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLT.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.Nonempty.{u3} P s)\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P}, Iff (LT.lt.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLT.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))) (Bot.bot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (Set.Nonempty.{u3} P s)\nCase conversion may be inaccurate. Consider using '#align bot_lt_affine_span bot_lt_affineSpan\u2093'. -/\n@[simp]\ntheorem bot_lt_affineSpan : \u22a5 < affineSpan k s \u2194 s.Nonempty :=\n  by\n  rw [bot_lt_iff_ne_bot, nonempty_iff_ne_empty]\n  exact (affineSpan_eq_bot _).Not\n#align bot_lt_affine_span bot_lt_affineSpan\n\nend\n\nvariable {k}\n\n/- warning: affine_span_induction -> affineSpan_induction is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {x : P} {s : Set.{u3} P} {p : P -> Prop}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (forall (x : P), (Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) x s) -> (p x)) -> (forall (c : k) (u : P) (v : P) (w : P), (p u) -> (p v) -> (p w) -> (p (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) c (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) u v)) w))) -> (p x)\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {x : P} {s : Set.{u3} P} {p : P -> Prop}, (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> (forall (x : P), (Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x s) -> (p x)) -> (forall (c : k) (u : P) (v : P) (w : P), (p u) -> (p v) -> (p w) -> (p (HVAdd.hVAdd.{u1, u3, u3} V P P (instHVAdd.{u1, u3} V P (AddAction.toVAdd.{u1, u3} V P (SubNegMonoid.toAddMonoid.{u1} V (AddGroup.toSubNegMonoid.{u1} V (AddCommGroup.toAddGroup.{u1} V _inst_2))) (AddTorsor.toAddAction.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4))) (HSMul.hSMul.{u2, u1, u1} k V V (instHSMul.{u2, u1} k V (SMulZeroClass.toSMul.{u2, u1} k V (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u1} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u1} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (Module.toMulActionWithZero.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3))))) c (VSub.vsub.{u1, u3} V P (AddTorsor.toVSub.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4) u v)) w))) -> (p x)\nCase conversion may be inaccurate. Consider using '#align affine_span_induction affineSpan_induction\u2093'. -/\n/-- An induction principle for span membership. If `p` holds for all elements of `s` and is\npreserved under certain affine combinations, then `p` holds for all elements of the span of `s`.\n-/\ntheorem affineSpan_induction {x : P} {s : Set P} {p : P \u2192 Prop} (h : x \u2208 affineSpan k s)\n    (Hs : \u2200 x : P, x \u2208 s \u2192 p x)\n    (Hc : \u2200 (c : k) (u v w : P), p u \u2192 p v \u2192 p w \u2192 p (c \u2022 (u -\u1d65 v) +\u1d65 w)) : p x :=\n  (@affineSpan_le _ _ _ _ _ _ _ _ \u27e8p, Hc\u27e9).mpr Hs h\n#align affine_span_induction affineSpan_induction\n\n/- warning: affine_span_induction' -> affineSpan_induction' is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u3} P} {p : forall (x : P), (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> Prop}, (forall (y : P) (hys : Membership.Mem.{u3, u3} P (Set.{u3} P) (Set.hasMem.{u3} P) y s), p y (subset_affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s y hys)) -> (forall (c : k) (u : P) (hu : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) u (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (v : P) (hv : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) v (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (w : P) (hw : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) w (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)), (p u hu) -> (p v hv) -> (p w hw) -> (p (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) c (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) u v)) w) (AffineSubspace.smul_vsub_vadd_mem.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) c u v w hu hv hw))) -> (forall {x : P} (h : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)), p x h)\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s : Set.{u3} P} {p : forall (x : P), (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) -> Prop}, (forall (y : P) (hys : Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) y s), p y (subset_affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s y hys)) -> (forall (c : k) (u : P) (hu : Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) u (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (v : P) (hv : Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) v (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)) (w : P) (hw : Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) w (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)), (p u hu) -> (p v hv) -> (p w hw) -> (p (HVAdd.hVAdd.{u1, u3, u3} V P P (instHVAdd.{u1, u3} V P (AddAction.toVAdd.{u1, u3} V P (SubNegMonoid.toAddMonoid.{u1} V (AddGroup.toSubNegMonoid.{u1} V (AddCommGroup.toAddGroup.{u1} V _inst_2))) (AddTorsor.toAddAction.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4))) (HSMul.hSMul.{u2, u1, u1} k V V (instHSMul.{u2, u1} k V (SMulZeroClass.toSMul.{u2, u1} k V (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u1} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u1} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (Module.toMulActionWithZero.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3))))) c (VSub.vsub.{u1, u3} V P (AddTorsor.toVSub.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4) u v)) w) (AffineSubspace.smul_vsub_vadd_mem.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s) c u v w hu hv hw))) -> (forall {x : P} (h : Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)), p x h)\nCase conversion may be inaccurate. Consider using '#align affine_span_induction' affineSpan_induction'\u2093'. -/\n/-- A dependent version of `affine_span_induction`. -/\ntheorem affineSpan_induction' {s : Set P} {p : \u2200 x, x \u2208 affineSpan k s \u2192 Prop}\n    (Hs : \u2200 (y) (hys : y \u2208 s), p y (subset_affineSpan k _ hys))\n    (Hc :\n      \u2200 (c : k) (u hu v hv w hw),\n        p u hu \u2192\n          p v hv \u2192 p w hw \u2192 p (c \u2022 (u -\u1d65 v) +\u1d65 w) (AffineSubspace.smul_vsub_vadd_mem _ _ hu hv hw))\n    {x : P} (h : x \u2208 affineSpan k s) : p x h :=\n  by\n  refine' Exists.elim _ fun (hx : x \u2208 affineSpan k s) (hc : p x hx) => hc\n  refine' @affineSpan_induction k V P _ _ _ _ _ _ _ h _ _\n  \u00b7 exact fun y hy => \u27e8subset_affineSpan _ _ hy, Hs y hy\u27e9\n  \u00b7\n    exact fun c u v w hu hv hw =>\n      Exists.elim hu fun hu' hu =>\n        Exists.elim hv fun hv' hv =>\n          Exists.elim hw fun hw' hw =>\n            \u27e8AffineSubspace.smul_vsub_vadd_mem _ _ hu' hv' hw', Hc _ _ _ _ _ _ _ hu hv hw\u27e9\n#align affine_span_induction' affineSpan_induction'\n\nsection WithLocalInstance\n\nattribute [local instance] AffineSubspace.toAddTorsor\n\n/- warning: affine_span_coe_preimage_eq_top -> affineSpan_coe_preimage_eq_top is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (A : Set.{u3} P) [_inst_5 : Nonempty.{succ u3} (coeSort.{succ u3, succ (succ u3)} (Set.{u3} P) Type.{u3} (Set.hasCoeToSort.{u3} P) A)], Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (affineSpan.nonempty.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5))) (affineSpan.{u1, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (affineSpan.nonempty.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5)) (Set.preimage.{u3, u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) P ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) P (HasLiftT.mk.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) P (CoeTC\u2093.coe.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) P (coeBase.{succ u3, succ u3} (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) P (coeSubtype.{succ u3} P (fun (x : P) => Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) x (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))))))) A)) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (affineSpan.nonempty.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5))) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (affineSpan.nonempty.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5))) (AffineSubspace.completeLattice.{u1, u2, u3} k (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (coeSort.{succ u3, succ (succ u3)} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) Type.{u3} (SetLike.hasCoeToSort.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)) _inst_1 (Submodule.addCommGroup.{u1, u2} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (affineSpan.nonempty.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5)))))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (A : Set.{u3} P) [_inst_5 : Nonempty.{succ u3} (Set.Elem.{u3} P A)], Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k (Subtype.{succ u1} V (fun (x : V) => Membership.mem.{u1, u1} V (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (SetLike.instMembership.{u1, u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) (Subtype.{succ u3} P (fun (x : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) _inst_1 (Submodule.addCommGroup.{u2, u1} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (instNonemptySubtypeMemAffineSubspaceInstMembershipInstSetLikeAffineSubspaceAffineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5))) (affineSpan.{u2, u1, u3} k (Subtype.{succ u1} V (fun (x : V) => Membership.mem.{u1, u1} V (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (SetLike.instMembership.{u1, u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) (Subtype.{succ u3} P (fun (x : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) _inst_1 (Submodule.addCommGroup.{u2, u1} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (instNonemptySubtypeMemAffineSubspaceInstMembershipInstSetLikeAffineSubspaceAffineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5)) (Set.preimage.{u3, u3} (Subtype.{succ u3} P (fun (x : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) P (Subtype.val.{succ u3} P (fun (x : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) A)) (Top.top.{u3} (AffineSubspace.{u2, u1, u3} k (Subtype.{succ u1} V (fun (x : V) => Membership.mem.{u1, u1} V (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (SetLike.instMembership.{u1, u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) (Subtype.{succ u3} P (fun (x : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) _inst_1 (Submodule.addCommGroup.{u2, u1} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (instNonemptySubtypeMemAffineSubspaceInstMembershipInstSetLikeAffineSubspaceAffineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5))) (CompleteLattice.toTop.{u3} (AffineSubspace.{u2, u1, u3} k (Subtype.{succ u1} V (fun (x : V) => Membership.mem.{u1, u1} V (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (SetLike.instMembership.{u1, u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) (Subtype.{succ u3} P (fun (x : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) _inst_1 (Submodule.addCommGroup.{u2, u1} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (instNonemptySubtypeMemAffineSubspaceInstMembershipInstSetLikeAffineSubspaceAffineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5))) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k (Subtype.{succ u1} V (fun (x : V) => Membership.mem.{u1, u1} V (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (SetLike.instMembership.{u1, u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3)) x (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) (Subtype.{succ u3} P (fun (x : P) => Membership.mem.{u3, u3} P (Set.{u3} P) (Set.instMembershipSet.{u3} P) x (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A)))) _inst_1 (Submodule.addCommGroup.{u2, u1} k V _inst_1 _inst_2 _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (Submodule.module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3 (AffineSubspace.direction.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A))) (AffineSubspace.toAddTorsor.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A) (instNonemptySubtypeMemAffineSubspaceInstMembershipInstSetLikeAffineSubspaceAffineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 A _inst_5)))))\nCase conversion may be inaccurate. Consider using '#align affine_span_coe_preimage_eq_top affineSpan_coe_preimage_eq_top\u2093'. -/\n/-- A set, considered as a subset of its spanned affine subspace, spans the whole subspace. -/\n@[simp]\ntheorem affineSpan_coe_preimage_eq_top (A : Set P) [Nonempty A] :\n    affineSpan k ((coe : affineSpan k A \u2192 P) \u207b\u00b9' A) = \u22a4 :=\n  by\n  rw [eq_top_iff]\n  rintro \u27e8x, hx\u27e9 -\n  refine' affineSpan_induction' (fun y hy => _) (fun c u hu v hv w hw => _) hx\n  \u00b7 exact subset_affineSpan _ _ hy\n  \u00b7 exact AffineSubspace.smul_vsub_vadd_mem _ _\n#align affine_span_coe_preimage_eq_top affineSpan_coe_preimage_eq_top\n\nend WithLocalInstance\n\n/- warning: affine_span_singleton_union_vadd_eq_top_of_span_eq_top -> affineSpan_singleton_union_vadd_eq_top_of_span_eq_top is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : Set.{u2} V} (p : P), (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Set.range.{u2, succ u2} V (coeSort.{succ u2, succ (succ u2)} (Set.{u2} V) Type.{u2} (Set.hasCoeToSort.{u2} V) s) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Set.{u2} V) Type.{u2} (Set.hasCoeToSort.{u2} V) s) V (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} V) Type.{u2} (Set.hasCoeToSort.{u2} V) s) V (CoeTC\u2093.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} V) Type.{u2} (Set.hasCoeToSort.{u2} V) s) V (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} V) Type.{u2} (Set.hasCoeToSort.{u2} V) s) V (coeSubtype.{succ u2} V (fun (x : V) => Membership.Mem.{u2, u2} V (Set.{u2} V) (Set.hasMem.{u2} V) x s)))))))) (Top.top.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.hasTop.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Union.union.{u3} (Set.{u3} P) (Set.hasUnion.{u3} P) (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p) (Set.image.{u2, u3} V P (fun (v : V) => VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p) s))) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] {s : Set.{u3} V} (p : P), (Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (Submodule.span.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3 (Set.range.{u3, succ u3} V (Subtype.{succ u3} V (fun (x : V) => Membership.mem.{u3, u3} V (Set.{u3} V) (Set.instMembershipSet.{u3} V) x s)) (Subtype.val.{succ u3} V (fun (x : V) => Membership.mem.{u3, u3} V (Set.{u3} V) (Set.instMembershipSet.{u3} V) x s)))) (Top.top.{u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (Submodule.instTopSubmodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))) -> (Eq.{succ u1} (AffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Union.union.{u1} (Set.{u1} P) (Set.instUnionSet.{u1} P) (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p) (Set.image.{u3, u1} V P (fun (v : V) => HVAdd.hVAdd.{u3, u1, u1} V P P (instHVAdd.{u3, u1} V P (AddAction.toVAdd.{u3, u1} V P (SubNegMonoid.toAddMonoid.{u3} V (AddGroup.toSubNegMonoid.{u3} V (AddCommGroup.toAddGroup.{u3} V _inst_2))) (AddTorsor.toAddAction.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4))) v p) s))) (Top.top.{u1} (AffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toTop.{u1} (AffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4))))\nCase conversion may be inaccurate. Consider using '#align affine_span_singleton_union_vadd_eq_top_of_span_eq_top affineSpan_singleton_union_vadd_eq_top_of_span_eq_top\u2093'. -/\n/-- Suppose a set of vectors spans `V`.  Then a point `p`, together\nwith those vectors added to `p`, spans `P`. -/\ntheorem affineSpan_singleton_union_vadd_eq_top_of_span_eq_top {s : Set V} (p : P)\n    (h : Submodule.span k (Set.range (coe : s \u2192 V)) = \u22a4) :\n    affineSpan k ({p} \u222a (fun v => v +\u1d65 p) '' s) = \u22a4 :=\n  by\n  convert ext_of_direction_eq _\n      \u27e8p, mem_affineSpan k (Set.mem_union_left _ (Set.mem_singleton _)), mem_top k V p\u27e9\n  rw [direction_affineSpan, direction_top,\n    vectorSpan_eq_span_vsub_set_right k (Set.mem_union_left _ (Set.mem_singleton _) : p \u2208 _),\n    eq_top_iff, \u2190 h]\n  apply Submodule.span_mono\n  rintro v \u27e8v', rfl\u27e9\n  use (v' : V) +\u1d65 p\n  simp\n#align affine_span_singleton_union_vadd_eq_top_of_span_eq_top affineSpan_singleton_union_vadd_eq_top_of_span_eq_top\n\nvariable (k)\n\n/- warning: vector_span_pair -> vectorSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082))) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Singleton.singleton.{u2, u2} V (Set.{u2} V) (Set.hasSingleton.{u2} V) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2081 p\u2082)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082))) (Submodule.span.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3 (Singleton.singleton.{u3, u3} V (Set.{u3} V) (Set.instSingletonSet.{u3} V) (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2081 p\u2082)))\nCase conversion may be inaccurate. Consider using '#align vector_span_pair vectorSpan_pair\u2093'. -/\n/-- The `vector_span` of two points is the span of their difference. -/\ntheorem vectorSpan_pair (p\u2081 p\u2082 : P) : vectorSpan k ({p\u2081, p\u2082} : Set P) = k \u2219 p\u2081 -\u1d65 p\u2082 := by\n  rw [vectorSpan_eq_span_vsub_set_left k (mem_insert p\u2081 _), image_pair, vsub_self,\n    Submodule.span_insert_zero]\n#align vector_span_pair vectorSpan_pair\n\n/- warning: vector_span_pair_rev -> vectorSpan_pair_rev is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082))) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Singleton.singleton.{u2, u2} V (Set.{u2} V) (Set.hasSingleton.{u2} V) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Eq.{succ u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082))) (Submodule.span.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3 (Singleton.singleton.{u3, u3} V (Set.{u3} V) (Set.instSingletonSet.{u3} V) (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2082 p\u2081)))\nCase conversion may be inaccurate. Consider using '#align vector_span_pair_rev vectorSpan_pair_rev\u2093'. -/\n/-- The `vector_span` of two points is the span of their difference (reversed). -/\ntheorem vectorSpan_pair_rev (p\u2081 p\u2082 : P) : vectorSpan k ({p\u2081, p\u2082} : Set P) = k \u2219 p\u2082 -\u1d65 p\u2081 := by\n  rw [pair_comm, vectorSpan_pair]\n#align vector_span_pair_rev vectorSpan_pair_rev\n\n/- warning: vsub_mem_vector_span_pair -> vsub_mem_vectorSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2081 p\u2082) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} V (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3)) (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2081 p\u2082) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align vsub_mem_vector_span_pair vsub_mem_vectorSpan_pair\u2093'. -/\n/-- The difference between two points lies in their `vector_span`. -/\ntheorem vsub_mem_vectorSpan_pair (p\u2081 p\u2082 : P) : p\u2081 -\u1d65 p\u2082 \u2208 vectorSpan k ({p\u2081, p\u2082} : Set P) :=\n  vsub_mem_vectorSpan _ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_singleton _))\n#align vsub_mem_vector_span_pair vsub_mem_vectorSpan_pair\n\n/- warning: vsub_rev_mem_vector_span_pair -> vsub_rev_mem_vectorSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} V (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3)) (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2082 p\u2081) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align vsub_rev_mem_vector_span_pair vsub_rev_mem_vectorSpan_pair\u2093'. -/\n/-- The difference between two points (reversed) lies in their `vector_span`. -/\ntheorem vsub_rev_mem_vectorSpan_pair (p\u2081 p\u2082 : P) : p\u2082 -\u1d65 p\u2081 \u2208 vectorSpan k ({p\u2081, p\u2082} : Set P) :=\n  vsub_mem_vectorSpan _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)) (Set.mem_insert _ _)\n#align vsub_rev_mem_vector_span_pair vsub_rev_mem_vectorSpan_pair\n\nvariable {k}\n\n/- warning: smul_vsub_mem_vector_span_pair -> smul_vsub_mem_vectorSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2081 p\u2082)) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} V (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3)) (HSMul.hSMul.{u2, u3, u3} k V V (instHSMul.{u2, u3} k V (SMulZeroClass.toSMul.{u2, u3} k V (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u3} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u3} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (Module.toMulActionWithZero.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))))) r (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2081 p\u2082)) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align smul_vsub_mem_vector_span_pair smul_vsub_mem_vectorSpan_pair\u2093'. -/\n/-- A multiple of the difference between two points lies in their `vector_span`. -/\ntheorem smul_vsub_mem_vectorSpan_pair (r : k) (p\u2081 p\u2082 : P) :\n    r \u2022 (p\u2081 -\u1d65 p\u2082) \u2208 vectorSpan k ({p\u2081, p\u2082} : Set P) :=\n  Submodule.smul_mem _ _ (vsub_mem_vectorSpan_pair k p\u2081 p\u2082)\n#align smul_vsub_mem_vector_span_pair smul_vsub_mem_vectorSpan_pair\n\n/- warning: smul_vsub_rev_mem_vector_span_pair -> smul_vsub_rev_mem_vectorSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081)) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} V (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3)) (HSMul.hSMul.{u2, u3, u3} k V V (instHSMul.{u2, u3} k V (SMulZeroClass.toSMul.{u2, u3} k V (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u3} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u3} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (Module.toMulActionWithZero.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))))) r (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2082 p\u2081)) (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align smul_vsub_rev_mem_vector_span_pair smul_vsub_rev_mem_vectorSpan_pair\u2093'. -/\n/-- A multiple of the difference between two points (reversed) lies in their `vector_span`. -/\ntheorem smul_vsub_rev_mem_vectorSpan_pair (r : k) (p\u2081 p\u2082 : P) :\n    r \u2022 (p\u2082 -\u1d65 p\u2081) \u2208 vectorSpan k ({p\u2081, p\u2082} : Set P) :=\n  Submodule.smul_mem _ _ (vsub_rev_mem_vectorSpan_pair k p\u2081 p\u2082)\n#align smul_vsub_rev_mem_vector_span_pair smul_vsub_rev_mem_vectorSpan_pair\n\n/- warning: mem_vector_span_pair -> mem_vectorSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))) (Exists.{succ u1} k (fun (r : k) => Eq.{succ u2} V (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2081 p\u2082)) v))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.mem.{u3, u3} V (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3)) v (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082)))) (Exists.{succ u2} k (fun (r : k) => Eq.{succ u3} V (HSMul.hSMul.{u2, u3, u3} k V V (instHSMul.{u2, u3} k V (SMulZeroClass.toSMul.{u2, u3} k V (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u3} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u3} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (Module.toMulActionWithZero.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))))) r (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2081 p\u2082)) v))\nCase conversion may be inaccurate. Consider using '#align mem_vector_span_pair mem_vectorSpan_pair\u2093'. -/\n/-- A vector lies in the `vector_span` of two points if and only if it is a multiple of their\ndifference. -/\ntheorem mem_vectorSpan_pair {p\u2081 p\u2082 : P} {v : V} :\n    v \u2208 vectorSpan k ({p\u2081, p\u2082} : Set P) \u2194 \u2203 r : k, r \u2022 (p\u2081 -\u1d65 p\u2082) = v := by\n  rw [vectorSpan_pair, Submodule.mem_span_singleton]\n#align mem_vector_span_pair mem_vectorSpan_pair\n\n/- warning: mem_vector_span_pair_rev -> mem_vectorSpan_pair_rev is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.Mem.{u2, u2} V (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) V (Submodule.setLike.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)) v (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))) (Exists.{succ u1} k (fun (r : k) => Eq.{succ u2} V (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081)) v))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u3}} {P : Type.{u1}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u3} V] [_inst_3 : Module.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2)] [_inst_4 : AddTorsor.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.mem.{u3, u3} V (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3) V (Submodule.setLike.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3)) v (vectorSpan.{u2, u3, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082)))) (Exists.{succ u2} k (fun (r : k) => Eq.{succ u3} V (HSMul.hSMul.{u2, u3, u3} k V V (instHSMul.{u2, u3} k V (SMulZeroClass.toSMul.{u2, u3} k V (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u3} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u3} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u3} V (SubNegZeroMonoid.toNegZeroClass.{u3} V (SubtractionMonoid.toSubNegZeroMonoid.{u3} V (SubtractionCommMonoid.toSubtractionMonoid.{u3} V (AddCommGroup.toDivisionAddCommMonoid.{u3} V _inst_2))))) (Module.toMulActionWithZero.{u2, u3} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V _inst_2) _inst_3))))) r (VSub.vsub.{u3, u1} V P (AddTorsor.toVSub.{u3, u1} V P (AddCommGroup.toAddGroup.{u3} V _inst_2) _inst_4) p\u2082 p\u2081)) v))\nCase conversion may be inaccurate. Consider using '#align mem_vector_span_pair_rev mem_vectorSpan_pair_rev\u2093'. -/\n/-- A vector lies in the `vector_span` of two points if and only if it is a multiple of their\ndifference (reversed). -/\ntheorem mem_vectorSpan_pair_rev {p\u2081 p\u2082 : P} {v : V} :\n    v \u2208 vectorSpan k ({p\u2081, p\u2082} : Set P) \u2194 \u2203 r : k, r \u2022 (p\u2082 -\u1d65 p\u2081) = v := by\n  rw [vectorSpan_pair_rev, Submodule.mem_span_singleton]\n#align mem_vector_span_pair_rev mem_vectorSpan_pair_rev\n\nvariable (k)\n\n-- mathport name: \u00abexprline[ , , ]\u00bb\nnotation \"line[\" k \", \" p\u2081 \", \" p\u2082 \"]\" =>\n  affineSpan k (insert p\u2081 (@singleton _ _ Set.hasSingleton p\u2082))\n\n/- warning: left_mem_affine_span_pair -> left_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align left_mem_affine_span_pair left_mem_affineSpan_pair\u2093'. -/\n/-- The first of two points lies in their affine span. -/\ntheorem left_mem_affineSpan_pair (p\u2081 p\u2082 : P) : p\u2081 \u2208 line[k, p\u2081, p\u2082] :=\n  mem_affineSpan _ (Set.mem_insert _ _)\n#align left_mem_affine_span_pair left_mem_affineSpan_pair\n\n/- warning: right_mem_affine_span_pair -> right_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2082 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2082 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align right_mem_affine_span_pair right_mem_affineSpan_pair\u2093'. -/\n/-- The second of two points lies in their affine span. -/\ntheorem right_mem_affineSpan_pair (p\u2081 p\u2082 : P) : p\u2082 \u2208 line[k, p\u2081, p\u2082] :=\n  mem_affineSpan _ (Set.mem_insert_of_mem _ (Set.mem_singleton _))\n#align right_mem_affine_span_pair right_mem_affineSpan_pair\n\nvariable {k}\n\n/- warning: affine_map.line_map_mem_affine_span_pair -> AffineMap.lineMap_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (coeFn.{max (succ u1) (succ u2) (succ u3), max (succ u1) (succ u3)} (AffineMap.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) (fun (_x : AffineMap.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) => k -> P) (AffineMap.hasCoeToFun.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) (AffineMap.lineMap.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2081 p\u2082) r) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : k) => P) r) (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (FunLike.coe.{max (max (succ u2) (succ u1)) (succ u3), succ u2, succ u3} (AffineMap.{u2, u2, u2, u1, u3} k k k V P _inst_1 (Ring.toAddCommGroup.{u2} k _inst_1) (AffineMap.instModuleToSemiringToAddCommMonoidToNonUnitalNonAssocSemiringToNonUnitalNonAssocRingToNonUnitalRing.{u2} k _inst_1) (addGroupIsAddTorsor.{u2} k (AddGroupWithOne.toAddGroup.{u2} k (Ring.toAddGroupWithOne.{u2} k _inst_1))) _inst_2 _inst_3 _inst_4) k (fun (_x : k) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : k) => P) _x) (AffineMap.funLike.{u2, u2, u2, u1, u3} k k k V P _inst_1 (Ring.toAddCommGroup.{u2} k _inst_1) (AffineMap.instModuleToSemiringToAddCommMonoidToNonUnitalNonAssocSemiringToNonUnitalNonAssocRingToNonUnitalRing.{u2} k _inst_1) (addGroupIsAddTorsor.{u2} k (AddGroupWithOne.toAddGroup.{u2} k (Ring.toAddGroupWithOne.{u2} k _inst_1))) _inst_2 _inst_3 _inst_4) (AffineMap.lineMap.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2081 p\u2082) r) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align affine_map.line_map_mem_affine_span_pair AffineMap.lineMap_mem_affineSpan_pair\u2093'. -/\n/-- A combination of two points expressed with `line_map` lies in their affine span. -/\ntheorem AffineMap.lineMap_mem_affineSpan_pair (r : k) (p\u2081 p\u2082 : P) :\n    AffineMap.lineMap p\u2081 p\u2082 r \u2208 line[k, p\u2081, p\u2082] :=\n  AffineMap.lineMap_mem _ (left_mem_affineSpan_pair _ _ _) (right_mem_affineSpan_pair _ _ _)\n#align affine_map.line_map_mem_affine_span_pair AffineMap.lineMap_mem_affineSpan_pair\n\n/- warning: affine_map.line_map_rev_mem_affine_span_pair -> AffineMap.lineMap_rev_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (coeFn.{max (succ u1) (succ u2) (succ u3), max (succ u1) (succ u3)} (AffineMap.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) (fun (_x : AffineMap.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) => k -> P) (AffineMap.hasCoeToFun.{u1, u1, u1, u2, u3} k k k V P _inst_1 (NonUnitalNonAssocRing.toAddCommGroup.{u1} k (NonAssocRing.toNonUnitalNonAssocRing.{u1} k (Ring.toNonAssocRing.{u1} k _inst_1))) (Semiring.toModule.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (addGroupIsAddTorsor.{u1} k (AddGroupWithOne.toAddGroup.{u1} k (AddCommGroupWithOne.toAddGroupWithOne.{u1} k (Ring.toAddCommGroupWithOne.{u1} k _inst_1)))) _inst_2 _inst_3 _inst_4) (AffineMap.lineMap.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2082 p\u2081) r) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : k) => P) r) (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (FunLike.coe.{max (max (succ u2) (succ u1)) (succ u3), succ u2, succ u3} (AffineMap.{u2, u2, u2, u1, u3} k k k V P _inst_1 (Ring.toAddCommGroup.{u2} k _inst_1) (AffineMap.instModuleToSemiringToAddCommMonoidToNonUnitalNonAssocSemiringToNonUnitalNonAssocRingToNonUnitalRing.{u2} k _inst_1) (addGroupIsAddTorsor.{u2} k (AddGroupWithOne.toAddGroup.{u2} k (Ring.toAddGroupWithOne.{u2} k _inst_1))) _inst_2 _inst_3 _inst_4) k (fun (_x : k) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : k) => P) _x) (AffineMap.funLike.{u2, u2, u2, u1, u3} k k k V P _inst_1 (Ring.toAddCommGroup.{u2} k _inst_1) (AffineMap.instModuleToSemiringToAddCommMonoidToNonUnitalNonAssocSemiringToNonUnitalNonAssocRingToNonUnitalRing.{u2} k _inst_1) (addGroupIsAddTorsor.{u2} k (AddGroupWithOne.toAddGroup.{u2} k (Ring.toAddGroupWithOne.{u2} k _inst_1))) _inst_2 _inst_3 _inst_4) (AffineMap.lineMap.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 p\u2082 p\u2081) r) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align affine_map.line_map_rev_mem_affine_span_pair AffineMap.lineMap_rev_mem_affineSpan_pair\u2093'. -/\n/-- A combination of two points expressed with `line_map` (with the two points reversed) lies in\ntheir affine span. -/\ntheorem AffineMap.lineMap_rev_mem_affineSpan_pair (r : k) (p\u2081 p\u2082 : P) :\n    AffineMap.lineMap p\u2082 p\u2081 r \u2208 line[k, p\u2081, p\u2082] :=\n  AffineMap.lineMap_mem _ (right_mem_affineSpan_pair _ _ _) (left_mem_affineSpan_pair _ _ _)\n#align affine_map.line_map_rev_mem_affine_span_pair AffineMap.lineMap_rev_mem_affineSpan_pair\n\n/- warning: smul_vsub_vadd_mem_affine_span_pair -> smul_vsub_vadd_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081)) p\u2081) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u1, u3, u3} V P P (instHVAdd.{u1, u3} V P (AddAction.toVAdd.{u1, u3} V P (SubNegMonoid.toAddMonoid.{u1} V (AddGroup.toSubNegMonoid.{u1} V (AddCommGroup.toAddGroup.{u1} V _inst_2))) (AddTorsor.toAddAction.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4))) (HSMul.hSMul.{u2, u1, u1} k V V (instHSMul.{u2, u1} k V (SMulZeroClass.toSMul.{u2, u1} k V (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u1} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u1} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (Module.toMulActionWithZero.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3))))) r (VSub.vsub.{u1, u3} V P (AddTorsor.toVSub.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4) p\u2082 p\u2081)) p\u2081) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align smul_vsub_vadd_mem_affine_span_pair smul_vsub_vadd_mem_affineSpan_pair\u2093'. -/\n/-- A multiple of the difference of two points added to the first point lies in their affine\nspan. -/\ntheorem smul_vsub_vadd_mem_affineSpan_pair (r : k) (p\u2081 p\u2082 : P) :\n    r \u2022 (p\u2082 -\u1d65 p\u2081) +\u1d65 p\u2081 \u2208 line[k, p\u2081, p\u2082] :=\n  AffineMap.lineMap_mem_affineSpan_pair _ _ _\n#align smul_vsub_vadd_mem_affine_span_pair smul_vsub_vadd_mem_affineSpan_pair\n\n/- warning: smul_vsub_rev_vadd_mem_affine_span_pair -> smul_vsub_rev_vadd_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2081 p\u2082)) p\u2082) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (r : k) (p\u2081 : P) (p\u2082 : P), Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u1, u3, u3} V P P (instHVAdd.{u1, u3} V P (AddAction.toVAdd.{u1, u3} V P (SubNegMonoid.toAddMonoid.{u1} V (AddGroup.toSubNegMonoid.{u1} V (AddCommGroup.toAddGroup.{u1} V _inst_2))) (AddTorsor.toAddAction.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4))) (HSMul.hSMul.{u2, u1, u1} k V V (instHSMul.{u2, u1} k V (SMulZeroClass.toSMul.{u2, u1} k V (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u1} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u1} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (Module.toMulActionWithZero.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3))))) r (VSub.vsub.{u1, u3} V P (AddTorsor.toVSub.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4) p\u2081 p\u2082)) p\u2082) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))\nCase conversion may be inaccurate. Consider using '#align smul_vsub_rev_vadd_mem_affine_span_pair smul_vsub_rev_vadd_mem_affineSpan_pair\u2093'. -/\n/-- A multiple of the difference of two points added to the second point lies in their affine\nspan. -/\ntheorem smul_vsub_rev_vadd_mem_affineSpan_pair (r : k) (p\u2081 p\u2082 : P) :\n    r \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2082 \u2208 line[k, p\u2081, p\u2082] :=\n  AffineMap.lineMap_rev_mem_affineSpan_pair _ _ _\n#align smul_vsub_rev_vadd_mem_affine_span_pair smul_vsub_rev_vadd_mem_affineSpan_pair\n\n/- warning: vadd_left_mem_affine_span_pair -> vadd_left_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p\u2081) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))) (Exists.{succ u1} k (fun (r : k) => Eq.{succ u2} V (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2082 p\u2081)) v))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u1, u3, u3} V P P (instHVAdd.{u1, u3} V P (AddAction.toVAdd.{u1, u3} V P (SubNegMonoid.toAddMonoid.{u1} V (AddGroup.toSubNegMonoid.{u1} V (AddCommGroup.toAddGroup.{u1} V _inst_2))) (AddTorsor.toAddAction.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4))) v p\u2081) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))) (Exists.{succ u2} k (fun (r : k) => Eq.{succ u1} V (HSMul.hSMul.{u2, u1, u1} k V V (instHSMul.{u2, u1} k V (SMulZeroClass.toSMul.{u2, u1} k V (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u1} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u1} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (Module.toMulActionWithZero.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3))))) r (VSub.vsub.{u1, u3} V P (AddTorsor.toVSub.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4) p\u2082 p\u2081)) v))\nCase conversion may be inaccurate. Consider using '#align vadd_left_mem_affine_span_pair vadd_left_mem_affineSpan_pair\u2093'. -/\n/-- A vector added to the first point lies in the affine span of two points if and only if it is\na multiple of their difference. -/\ntheorem vadd_left_mem_affineSpan_pair {p\u2081 p\u2082 : P} {v : V} :\n    v +\u1d65 p\u2081 \u2208 line[k, p\u2081, p\u2082] \u2194 \u2203 r : k, r \u2022 (p\u2082 -\u1d65 p\u2081) = v := by\n  rw [vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _), direction_affineSpan,\n    mem_vectorSpan_pair_rev]\n#align vadd_left_mem_affine_span_pair vadd_left_mem_affineSpan_pair\n\n/- warning: vadd_right_mem_affine_span_pair -> vadd_right_mem_affineSpan_pair is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) v p\u2082) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082)))) (Exists.{succ u1} k (fun (r : k) => Eq.{succ u2} V (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p\u2081 p\u2082)) v))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {v : V}, Iff (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) (HVAdd.hVAdd.{u1, u3, u3} V P P (instHVAdd.{u1, u3} V P (AddAction.toVAdd.{u1, u3} V P (SubNegMonoid.toAddMonoid.{u1} V (AddGroup.toSubNegMonoid.{u1} V (AddCommGroup.toAddGroup.{u1} V _inst_2))) (AddTorsor.toAddAction.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4))) v p\u2082) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2082)))) (Exists.{succ u2} k (fun (r : k) => Eq.{succ u1} V (HSMul.hSMul.{u2, u1, u1} k V V (instHSMul.{u2, u1} k V (SMulZeroClass.toSMul.{u2, u1} k V (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u2, u1} k V (MonoidWithZero.toZero.{u2} k (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1))) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u2, u1} k V (Semiring.toMonoidWithZero.{u2} k (Ring.toSemiring.{u2} k _inst_1)) (NegZeroClass.toZero.{u1} V (SubNegZeroMonoid.toNegZeroClass.{u1} V (SubtractionMonoid.toSubNegZeroMonoid.{u1} V (SubtractionCommMonoid.toSubtractionMonoid.{u1} V (AddCommGroup.toDivisionAddCommMonoid.{u1} V _inst_2))))) (Module.toMulActionWithZero.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3))))) r (VSub.vsub.{u1, u3} V P (AddTorsor.toVSub.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2) _inst_4) p\u2081 p\u2082)) v))\nCase conversion may be inaccurate. Consider using '#align vadd_right_mem_affine_span_pair vadd_right_mem_affineSpan_pair\u2093'. -/\n/-- A vector added to the second point lies in the affine span of two points if and only if it is\na multiple of their difference. -/\ntheorem vadd_right_mem_affineSpan_pair {p\u2081 p\u2082 : P} {v : V} :\n    v +\u1d65 p\u2082 \u2208 line[k, p\u2081, p\u2082] \u2194 \u2203 r : k, r \u2022 (p\u2081 -\u1d65 p\u2082) = v := by\n  rw [vadd_mem_iff_mem_direction _ (right_mem_affineSpan_pair _ _ _), direction_affineSpan,\n    mem_vectorSpan_pair]\n#align vadd_right_mem_affine_span_pair vadd_right_mem_affineSpan_pair\n\n/- warning: affine_span_pair_le_of_mem_of_mem -> affineSpan_pair_le_of_mem_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 s) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2082 s) -> (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082))) s)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 s) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2082 s) -> (LE.le.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4))))) (affineSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082))) s)\nCase conversion may be inaccurate. Consider using '#align affine_span_pair_le_of_mem_of_mem affineSpan_pair_le_of_mem_of_mem\u2093'. -/\n/-- The span of two points that lie in an affine subspace is contained in that subspace. -/\ntheorem affineSpan_pair_le_of_mem_of_mem {p\u2081 p\u2082 : P} {s : AffineSubspace k P} (hp\u2081 : p\u2081 \u2208 s)\n    (hp\u2082 : p\u2082 \u2208 s) : line[k, p\u2081, p\u2082] \u2264 s :=\n  by\n  rw [affineSpan_le, Set.insert_subset, Set.singleton_subset_iff]\n  exact \u27e8hp\u2081, hp\u2082\u27e9\n#align affine_span_pair_le_of_mem_of_mem affineSpan_pair_le_of_mem_of_mem\n\n/- warning: affine_span_pair_le_of_left_mem -> affineSpan_pair_le_of_left_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {p\u2083 : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2083)))) -> (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2083))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2083))))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {p\u2083 : P}, (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2083)))) -> (LE.le.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2083))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2083))))\nCase conversion may be inaccurate. Consider using '#align affine_span_pair_le_of_left_mem affineSpan_pair_le_of_left_mem\u2093'. -/\n/-- One line is contained in another differing in the first point if the first point of the first\nline is contained in the second line. -/\ntheorem affineSpan_pair_le_of_left_mem {p\u2081 p\u2082 p\u2083 : P} (h : p\u2081 \u2208 line[k, p\u2082, p\u2083]) :\n    line[k, p\u2081, p\u2083] \u2264 line[k, p\u2082, p\u2083] :=\n  affineSpan_pair_le_of_mem_of_mem h (right_mem_affineSpan_pair _ _ _)\n#align affine_span_pair_le_of_left_mem affineSpan_pair_le_of_left_mem\n\n/- warning: affine_span_pair_le_of_right_mem -> affineSpan_pair_le_of_right_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {p\u2083 : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2083)))) -> (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2081))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2083))))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {p\u2083 : P}, (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p\u2081 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2083)))) -> (LE.le.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2081))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p\u2082 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.instSingletonSet.{u3} P) p\u2083))))\nCase conversion may be inaccurate. Consider using '#align affine_span_pair_le_of_right_mem affineSpan_pair_le_of_right_mem\u2093'. -/\n/-- One line is contained in another differing in the second point if the second point of the\nfirst line is contained in the second line. -/\ntheorem affineSpan_pair_le_of_right_mem {p\u2081 p\u2082 p\u2083 : P} (h : p\u2081 \u2208 line[k, p\u2082, p\u2083]) :\n    line[k, p\u2082, p\u2081] \u2264 line[k, p\u2082, p\u2083] :=\n  affineSpan_pair_le_of_mem_of_mem (left_mem_affineSpan_pair _ _ _) h\n#align affine_span_pair_le_of_right_mem affineSpan_pair_le_of_right_mem\n\nvariable (k)\n\n/- warning: affine_span_mono -> affineSpan_mono is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, (HasSubset.Subset.{u3} (Set.{u3} P) (Set.hasSubset.{u3} P) s\u2081 s\u2082) -> (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, (HasSubset.Subset.{u3} (Set.{u3} P) (Set.instHasSubsetSet.{u3} P) s\u2081 s\u2082) -> (LE.le.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nCase conversion may be inaccurate. Consider using '#align affine_span_mono affineSpan_mono\u2093'. -/\n/-- `affine_span` is monotone. -/\n@[mono]\ntheorem affineSpan_mono {s\u2081 s\u2082 : Set P} (h : s\u2081 \u2286 s\u2082) : affineSpan k s\u2081 \u2264 affineSpan k s\u2082 :=\n  spanPoints_subset_coe_of_subset_coe (Set.Subset.trans h (subset_affineSpan k _))\n#align affine_span_mono affineSpan_mono\n\n/- warning: affine_span_insert_affine_span -> affineSpan_insert_affineSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (p : P) (ps : Set.{u3} P), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps)))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p ps))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] (p : P) (ps : Set.{u3} P), Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p (SetLike.coe.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps)))) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p ps))\nCase conversion may be inaccurate. Consider using '#align affine_span_insert_affine_span affineSpan_insert_affineSpan\u2093'. -/\n/-- Taking the affine span of a set, adding a point and taking the\nspan again produces the same results as adding the point to the set\nand taking the span. -/\ntheorem affineSpan_insert_affineSpan (p : P) (ps : Set P) :\n    affineSpan k (insert p (affineSpan k ps : Set P)) = affineSpan k (insert p ps) := by\n  rw [Set.insert_eq, Set.insert_eq, span_union, span_union, affine_span_coe]\n#align affine_span_insert_affine_span affineSpan_insert_affineSpan\n\n/- warning: affine_span_insert_eq_affine_span -> affineSpan_insert_eq_affineSpan is a dubious translation:\nlean 3 declaration is\n  forall (k : Type.{u1}) {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p : P} {ps : Set.{u3} P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps)) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p ps)) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps))\nbut is expected to have type\n  forall (k : Type.{u2}) {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p : P} {ps : Set.{u3} P}, (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps)) -> (Eq.{succ u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p ps)) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps))\nCase conversion may be inaccurate. Consider using '#align affine_span_insert_eq_affine_span affineSpan_insert_eq_affineSpan\u2093'. -/\n/-- If a point is in the affine span of a set, adding it to that set\ndoes not change the affine span. -/\ntheorem affineSpan_insert_eq_affineSpan {p : P} {ps : Set P} (h : p \u2208 affineSpan k ps) :\n    affineSpan k (insert p ps) = affineSpan k ps :=\n  by\n  rw [\u2190 mem_coe] at h\n  rw [\u2190 affineSpan_insert_affineSpan, Set.insert_eq_of_mem h, affine_span_coe]\n#align affine_span_insert_eq_affine_span affineSpan_insert_eq_affineSpan\n\nvariable {k}\n\n/- warning: vector_span_insert_eq_vector_span -> vectorSpan_insert_eq_vectorSpan is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p : P} {ps : Set.{u3} P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps)) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p ps)) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {p : P} {ps : Set.{u3} P}, (Membership.mem.{u3, u3} P (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps)) -> (Eq.{succ u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.instInsertSet.{u3} P) p ps)) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 ps))\nCase conversion may be inaccurate. Consider using '#align vector_span_insert_eq_vector_span vectorSpan_insert_eq_vectorSpan\u2093'. -/\n/-- If a point is in the affine span of a set, adding it to that set\ndoes not change the vector span. -/\ntheorem vectorSpan_insert_eq_vectorSpan {p : P} {ps : Set P} (h : p \u2208 affineSpan k ps) :\n    vectorSpan k (insert p ps) = vectorSpan k ps := by\n  simp_rw [\u2190 direction_affineSpan, affineSpan_insert_eq_affineSpan _ h]\n#align vector_span_insert_eq_vector_span vectorSpan_insert_eq_vectorSpan\n\nend AffineSpace'\n\nnamespace AffineSubspace\n\nvariable {k : Type _} {V : Type _} {P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n  [affine_space V P]\n\ninclude V\n\n/- warning: affine_subspace.direction_sup -> AffineSubspace.direction_sup is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s2 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P} {p2 : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s1) -> (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s2) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Sup.sup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SemilatticeSup.toHasSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Lattice.toSemilatticeSup.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))) s1 s2)) (Sup.sup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toHasSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (Sup.sup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toHasSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s1) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s2)) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Singleton.singleton.{u2, u2} V (Set.{u2} V) (Set.hasSingleton.{u2} V) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p1)))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s1 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s2 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P} {p2 : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s1) -> (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p2 s2) -> (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Sup.sup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SemilatticeSup.toSup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Lattice.toSemilatticeSup.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4))))) s1 s2)) (Sup.sup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (Sup.sup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s1) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s2)) (Submodule.span.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Singleton.singleton.{u2, u2} V (Set.{u2} V) (Set.instSingletonSet.{u2} V) (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p1)))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_sup AffineSubspace.direction_sup\u2093'. -/\n/-- The direction of the sup of two nonempty affine subspaces is the\nsup of the two directions and of any one difference between points in\nthe two subspaces. -/\ntheorem direction_sup {s1 s2 : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s1) (hp2 : p2 \u2208 s2) :\n    (s1 \u2294 s2).direction = s1.direction \u2294 s2.direction \u2294 k \u2219 p2 -\u1d65 p1 :=\n  by\n  refine' le_antisymm _ _\n  \u00b7 change (affineSpan k ((s1 : Set P) \u222a s2)).direction \u2264 _\n    rw [\u2190 mem_coe] at hp1\n    rw [direction_affineSpan, vectorSpan_eq_span_vsub_set_right k (Set.mem_union_left _ hp1),\n      Submodule.span_le]\n    rintro v \u27e8p3, hp3, rfl\u27e9\n    cases hp3\n    \u00b7 rw [sup_assoc, sup_comm, SetLike.mem_coe, Submodule.mem_sup]\n      use 0, Submodule.zero_mem _, p3 -\u1d65 p1, vsub_mem_direction hp3 hp1\n      rw [zero_add]\n    \u00b7 rw [sup_assoc, SetLike.mem_coe, Submodule.mem_sup]\n      use 0, Submodule.zero_mem _, p3 -\u1d65 p1\n      rw [and_comm', zero_add]\n      use rfl\n      rw [\u2190 vsub_add_vsub_cancel p3 p2 p1, Submodule.mem_sup]\n      use p3 -\u1d65 p2, vsub_mem_direction hp3 hp2, p2 -\u1d65 p1, Submodule.mem_span_singleton_self _\n  \u00b7 refine' sup_le (sup_direction_le _ _) _\n    rw [direction_eq_vector_span, vectorSpan_def]\n    exact\n      inf\u209b_le_inf\u209b fun p hp =>\n        Set.Subset.trans\n          (Set.singleton_subset_iff.2\n            (vsub_mem_vsub (mem_spanPoints k p2 _ (Set.mem_union_right _ hp2))\n              (mem_spanPoints k p1 _ (Set.mem_union_left _ hp1))))\n          hp\n#align affine_subspace.direction_sup AffineSubspace.direction_sup\n\n/- warning: affine_subspace.direction_affine_span_insert -> AffineSubspace.direction_affineSpan_insert is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P} {p2 : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p2 ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)))) (Sup.sup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toHasSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (Submodule.span.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Singleton.singleton.{u2, u2} V (Set.{u2} V) (Set.hasSingleton.{u2} V) (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p1))) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P} {p2 : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) -> (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p2 (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)))) (Sup.sup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (SemilatticeSup.toSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Lattice.toSemilatticeSup.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (ConditionallyCompleteLattice.toLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (CompleteLattice.toConditionallyCompleteLattice.{u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (Submodule.completeLattice.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) (Submodule.span.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3 (Singleton.singleton.{u2, u2} V (Set.{u2} V) (Set.instSingletonSet.{u2} V) (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p1))) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.direction_affine_span_insert AffineSubspace.direction_affineSpan_insert\u2093'. -/\n/-- The direction of the span of the result of adding a point to a\nnonempty affine subspace is the sup of the direction of that subspace\nand of any one difference between that point and a point in the\nsubspace. -/\ntheorem direction_affineSpan_insert {s : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 \u2208 s) :\n    (affineSpan k (insert p2 (s : Set P))).direction = Submodule.span k {p2 -\u1d65 p1} \u2294 s.direction :=\n  by\n  rw [sup_comm, \u2190 Set.union_singleton, \u2190 coe_affine_span_singleton k V p2]\n  change (s \u2294 affineSpan k {p2}).direction = _\n  rw [direction_sup hp1 (mem_affineSpan k (Set.mem_singleton _)), direction_affineSpan]\n  simp\n#align affine_subspace.direction_affine_span_insert AffineSubspace.direction_affineSpan_insert\n\n/- warning: affine_subspace.mem_affine_span_insert_iff -> AffineSubspace.mem_affineSpan_insert_iff is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P}, (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) -> (forall (p2 : P) (p : P), Iff (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p2 ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) s)))) (Exists.{succ u1} k (fun (r : k) => Exists.{succ u3} P (fun (p0 : P) => Exists.{0} (Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p0 s) (fun (hp0 : Membership.Mem.{u3, u3} P (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.setLike.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p0 s) => Eq.{succ u3} P p (VAdd.vadd.{u2, u3} V P (AddAction.toHasVadd.{u2, u3} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4)) (SMul.smul.{u1, u2} k V (SMulZeroClass.toHasSmul.{u1, u2} k V (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (SMulWithZero.toSmulZeroClass.{u1, u2} k V (MulZeroClass.toHasZero.{u1} k (MulZeroOneClass.toMulZeroClass.{u1} k (MonoidWithZero.toMulZeroOneClass.{u1} k (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1))))) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (MulActionWithZero.toSMulWithZero.{u1, u2} k V (Semiring.toMonoidWithZero.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (AddZeroClass.toHasZero.{u2} V (AddMonoid.toAddZeroClass.{u2} V (AddCommMonoid.toAddMonoid.{u2} V (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)))) (Module.toMulActionWithZero.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3)))) r (VSub.vsub.{u2, u3} V P (AddTorsor.toHasVsub.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p1)) p0))))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {p1 : P}, (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p1 s) -> (forall (p2 : P) (p : P), Iff (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p (affineSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p2 (SetLike.coe.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s)))) (Exists.{succ u3} k (fun (r : k) => Exists.{succ u1} P (fun (p0 : P) => Exists.{0} (Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p0 s) (fun (hp0 : Membership.mem.{u1, u1} P (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) P (AffineSubspace.instSetLikeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)) p0 s) => Eq.{succ u1} P p (HVAdd.hVAdd.{u2, u1, u1} V P P (instHVAdd.{u2, u1} V P (AddAction.toVAdd.{u2, u1} V P (SubNegMonoid.toAddMonoid.{u2} V (AddGroup.toSubNegMonoid.{u2} V (AddCommGroup.toAddGroup.{u2} V _inst_2))) (AddTorsor.toAddAction.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4))) (HSMul.hSMul.{u3, u2, u2} k V V (instHSMul.{u3, u2} k V (SMulZeroClass.toSMul.{u3, u2} k V (NegZeroClass.toZero.{u2} V (SubNegZeroMonoid.toNegZeroClass.{u2} V (SubtractionMonoid.toSubNegZeroMonoid.{u2} V (SubtractionCommMonoid.toSubtractionMonoid.{u2} V (AddCommGroup.toDivisionAddCommMonoid.{u2} V _inst_2))))) (SMulWithZero.toSMulZeroClass.{u3, u2} k V (MonoidWithZero.toZero.{u3} k (Semiring.toMonoidWithZero.{u3} k (Ring.toSemiring.{u3} k _inst_1))) (NegZeroClass.toZero.{u2} V (SubNegZeroMonoid.toNegZeroClass.{u2} V (SubtractionMonoid.toSubNegZeroMonoid.{u2} V (SubtractionCommMonoid.toSubtractionMonoid.{u2} V (AddCommGroup.toDivisionAddCommMonoid.{u2} V _inst_2))))) (MulActionWithZero.toSMulWithZero.{u3, u2} k V (Semiring.toMonoidWithZero.{u3} k (Ring.toSemiring.{u3} k _inst_1)) (NegZeroClass.toZero.{u2} V (SubNegZeroMonoid.toNegZeroClass.{u2} V (SubtractionMonoid.toSubNegZeroMonoid.{u2} V (SubtractionCommMonoid.toSubtractionMonoid.{u2} V (AddCommGroup.toDivisionAddCommMonoid.{u2} V _inst_2))))) (Module.toMulActionWithZero.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3))))) r (VSub.vsub.{u2, u1} V P (AddTorsor.toVSub.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2) _inst_4) p2 p1)) p0))))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_affine_span_insert_iff AffineSubspace.mem_affineSpan_insert_iff\u2093'. -/\n/-- Given a point `p1` in an affine subspace `s`, and a point `p2`, a\npoint `p` is in the span of `s` with `p2` added if and only if it is a\nmultiple of `p2 -\u1d65 p1` added to a point in `s`. -/\ntheorem mem_affineSpan_insert_iff {s : AffineSubspace k P} {p1 : P} (hp1 : p1 \u2208 s) (p2 p : P) :\n    p \u2208 affineSpan k (insert p2 (s : Set P)) \u2194\n      \u2203 (r : k)(p0 : P)(hp0 : p0 \u2208 s), p = r \u2022 (p2 -\u1d65 p1 : V) +\u1d65 p0 :=\n  by\n  rw [\u2190 mem_coe] at hp1\n  rw [\u2190 vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_insert_of_mem _ hp1)),\n    direction_affine_span_insert hp1, Submodule.mem_sup]\n  constructor\n  \u00b7 rintro \u27e8v1, hv1, v2, hv2, hp\u27e9\n    rw [Submodule.mem_span_singleton] at hv1\n    rcases hv1 with \u27e8r, rfl\u27e9\n    use r, v2 +\u1d65 p1, vadd_mem_of_mem_direction hv2 hp1\n    symm at hp\n    rw [\u2190 sub_eq_zero, \u2190 vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hp\n    rw [hp, vadd_vadd]\n  \u00b7 rintro \u27e8r, p3, hp3, rfl\u27e9\n    use r \u2022 (p2 -\u1d65 p1), Submodule.mem_span_singleton.2 \u27e8r, rfl\u27e9, p3 -\u1d65 p1,\n      vsub_mem_direction hp3 hp1\n    rw [vadd_vsub_assoc, add_comm]\n#align affine_subspace.mem_affine_span_insert_iff AffineSubspace.mem_affineSpan_insert_iff\n\nend AffineSubspace\n\nsection MapComap\n\nvariable {k V\u2081 P\u2081 V\u2082 P\u2082 V\u2083 P\u2083 : Type _} [Ring k]\n\nvariable [AddCommGroup V\u2081] [Module k V\u2081] [AddTorsor V\u2081 P\u2081]\n\nvariable [AddCommGroup V\u2082] [Module k V\u2082] [AddTorsor V\u2082 P\u2082]\n\nvariable [AddCommGroup V\u2083] [Module k V\u2083] [AddTorsor V\u2083 P\u2083]\n\ninclude V\u2081 V\u2082\n\nsection\n\nvariable (f : P\u2081 \u2192\u1d43[k] P\u2082)\n\n/- warning: affine_map.vector_span_image_eq_submodule_map -> AffineMap.vectorSpan_image_eq_submodule_map is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {s : Set.{u3} P\u2081}, Eq.{succ u4} (Submodule.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_6) (Submodule.map.{u1, u1, u2, u4, max u2 u4} k k V\u2081 V\u2082 (Ring.toSemiring.{u1} k _inst_1) (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u1} k (Semiring.toNonAssocSemiring.{u1} k (Ring.toSemiring.{u1} k _inst_1))) (RingHomSurjective.ids.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (LinearMap.{u1, u1, u2, u4} k k (Ring.toSemiring.{u1} k _inst_1) (Ring.toSemiring.{u1} k _inst_1) (RingHom.id.{u1} k (Semiring.toNonAssocSemiring.{u1} k (Ring.toSemiring.{u1} k _inst_1))) V\u2081 V\u2082 (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6) (LinearMap.semilinearMapClass.{u1, u1, u2, u4} k k V\u2081 V\u2082 (Ring.toSemiring.{u1} k _inst_1) (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u1} k (Semiring.toNonAssocSemiring.{u1} k (Ring.toSemiring.{u1} k _inst_1)))) (AffineMap.linear.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f) (vectorSpan.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s)) (vectorSpan.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u3, u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u5}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u3, u2} k V\u2081 (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u5} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u3, u4} k V\u2082 (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u3, u2, u5, u4, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {s : Set.{u5} P\u2081}, Eq.{succ u4} (Submodule.{u3, u4} k V\u2082 (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_6) (Submodule.map.{u3, u3, u2, u4, max u2 u4} k k V\u2081 V\u2082 (Ring.toSemiring.{u3} k _inst_1) (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u3} k (Semiring.toNonAssocSemiring.{u3} k (Ring.toSemiring.{u3} k _inst_1))) (RingHomSurjective.ids.{u3} k (Ring.toSemiring.{u3} k _inst_1)) (LinearMap.{u3, u3, u2, u4} k k (Ring.toSemiring.{u3} k _inst_1) (Ring.toSemiring.{u3} k _inst_1) (RingHom.id.{u3} k (Semiring.toNonAssocSemiring.{u3} k (Ring.toSemiring.{u3} k _inst_1))) V\u2081 V\u2082 (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6) (LinearMap.instSemilinearMapClassLinearMap.{u3, u3, u2, u4} k k V\u2081 V\u2082 (Ring.toSemiring.{u3} k _inst_1) (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u3} k (Semiring.toNonAssocSemiring.{u3} k (Ring.toSemiring.{u3} k _inst_1)))) (AffineMap.linear.{u3, u2, u5, u4, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f) (vectorSpan.{u3, u2, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s)) (vectorSpan.{u3, u4, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u5, u1} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u2) (succ u5)) (succ u4)) (succ u1), succ u5, succ u1} (AffineMap.{u3, u2, u5, u4, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u3, u2, u5, u4, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) s))\nCase conversion may be inaccurate. Consider using '#align affine_map.vector_span_image_eq_submodule_map AffineMap.vectorSpan_image_eq_submodule_map\u2093'. -/\n@[simp]\ntheorem AffineMap.vectorSpan_image_eq_submodule_map {s : Set P\u2081} :\n    Submodule.map f.linear (vectorSpan k s) = vectorSpan k (f '' s) := by\n  simp [f.image_vsub_image, vectorSpan_def]\n#align affine_map.vector_span_image_eq_submodule_map AffineMap.vectorSpan_image_eq_submodule_map\n\nnamespace AffineSubspace\n\n#print AffineSubspace.map /-\n/-- The image of an affine subspace under an affine map as an affine subspace. -/\ndef map (s : AffineSubspace k P\u2081) : AffineSubspace k P\u2082\n    where\n  carrier := f '' s\n  smul_vsub_vadd_mem :=\n    by\n    rintro t - - - \u27e8p\u2081, h\u2081, rfl\u27e9 \u27e8p\u2082, h\u2082, rfl\u27e9 \u27e8p\u2083, h\u2083, rfl\u27e9\n    use t \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2083\n    suffices t \u2022 (p\u2081 -\u1d65 p\u2082) +\u1d65 p\u2083 \u2208 s by simp [this]\n    exact s.smul_vsub_vadd_mem t h\u2081 h\u2082 h\u2083\n#align affine_subspace.map AffineSubspace.map\n-/\n\n/- warning: affine_subspace.coe_map -> AffineSubspace.coe_map is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u5} (Set.{u5} P\u2082) ((fun (a : Type.{u5}) (b : Type.{u5}) [self : HasLiftT.{succ u5, succ u5} a b] => self.0) (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Set.{u5} P\u2082) (HasLiftT.mk.{succ u5, succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Set.{u5} P\u2082) (CoeTC\u2093.coe.{succ u5, succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Set.{u5} P\u2082) (SetLike.Set.hasCoeT.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Set.image.{u3, u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P\u2081) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P\u2081) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P\u2081) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) s))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u1}} {P\u2082 : Type.{u2}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u1} V\u2082] [_inst_6 : Module.{u5, u1} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u1, u2} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u1} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u2} (Set.{u2} P\u2082) (SetLike.coe.{u2, u2} (AffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.instSetLikeAffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Set.image.{u3, u2} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u1)) (succ u2), succ u3, succ u2} (AffineMap.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) (SetLike.coe.{u3, u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.instSetLikeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_map AffineSubspace.coe_map\u2093'. -/\n@[simp]\ntheorem coe_map (s : AffineSubspace k P\u2081) : (s.map f : Set P\u2082) = f '' s :=\n  rfl\n#align affine_subspace.coe_map AffineSubspace.coe_map\n\n/- warning: affine_subspace.mem_map -> AffineSubspace.mem_map is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {x : P\u2082} {s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, Iff (Membership.Mem.{u5, u5} P\u2082 (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.hasMem.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) x (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Exists.{succ u3} P\u2081 (fun (y : P\u2081) => Exists.{0} (Membership.Mem.{u3, u3} P\u2081 (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) y s) (fun (H : Membership.Mem.{u3, u3} P\u2081 (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) y s) => Eq.{succ u5} P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f y) x)))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {x : P\u2082} {s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, Iff (Membership.mem.{u1, u1} P\u2082 (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.instSetLikeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) x (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Exists.{succ u3} P\u2081 (fun (y : P\u2081) => And (Membership.mem.{u3, u3} P\u2081 (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.instSetLikeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) y s) (Eq.{succ u1} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) y) (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u3, succ u1} (AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (a : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) a) (AffineMap.funLike.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f y) x)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_map AffineSubspace.mem_map\u2093'. -/\n@[simp]\ntheorem mem_map {f : P\u2081 \u2192\u1d43[k] P\u2082} {x : P\u2082} {s : AffineSubspace k P\u2081} :\n    x \u2208 s.map f \u2194 \u2203 y \u2208 s, f y = x :=\n  mem_image_iff_bex\n#align affine_subspace.mem_map AffineSubspace.mem_map\n\n/- warning: affine_subspace.mem_map_of_mem -> AffineSubspace.mem_map_of_mem is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {x : P\u2081} {s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, (Membership.Mem.{u3, u3} P\u2081 (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) x s) -> (Membership.Mem.{u5, u5} P\u2082 (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.hasMem.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f x) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u1}} {P\u2082 : Type.{u2}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u1} V\u2082] [_inst_6 : Module.{u5, u1} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u1, u2} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u1} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {x : P\u2081} {s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, (Membership.mem.{u3, u3} P\u2081 (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.instSetLikeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) x s) -> (Membership.mem.{u2, u2} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) x) (AffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.instMembership.{u2, u2} (AffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.instSetLikeAffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u1)) (succ u2), succ u3, succ u2} (AffineMap.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f x) (AffineSubspace.map.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_map_of_mem AffineSubspace.mem_map_of_mem\u2093'. -/\ntheorem mem_map_of_mem {x : P\u2081} {s : AffineSubspace k P\u2081} (h : x \u2208 s) : f x \u2208 s.map f :=\n  Set.mem_image_of_mem _ h\n#align affine_subspace.mem_map_of_mem AffineSubspace.mem_map_of_mem\n\n/- warning: affine_subspace.mem_map_iff_mem_of_injective -> AffineSubspace.mem_map_iff_mem_of_injective is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {x : P\u2081} {s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, (Function.Injective.{succ u3, succ u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f)) -> (Iff (Membership.Mem.{u5, u5} P\u2082 (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.hasMem.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f x) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Membership.Mem.{u3, u3} P\u2081 (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) x s))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {x : P\u2081} {s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, (Function.Injective.{succ u3, succ u1} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u3, succ u1} (AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f)) -> (Iff (Membership.mem.{u1, u1} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) x) (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.instSetLikeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u3, succ u1} (AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f x) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Membership.mem.{u3, u3} P\u2081 (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.instSetLikeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) x s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_map_iff_mem_of_injective AffineSubspace.mem_map_iff_mem_of_injective\u2093'. -/\ntheorem mem_map_iff_mem_of_injective {f : P\u2081 \u2192\u1d43[k] P\u2082} {x : P\u2081} {s : AffineSubspace k P\u2081}\n    (hf : Function.Injective f) : f x \u2208 s.map f \u2194 x \u2208 s :=\n  hf.mem_set_image\n#align affine_subspace.mem_map_iff_mem_of_injective AffineSubspace.mem_map_iff_mem_of_injective\n\n/- warning: affine_subspace.map_bot -> AffineSubspace.map_bot is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (Bot.bot.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toHasBot.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))\nbut is expected to have type\n  forall {k : Type.{u4}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u1}} {V\u2082 : Type.{u3}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u4} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u4, u2} k V\u2081 (Ring.toSemiring.{u4} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u3} V\u2082] [_inst_6 : Module.{u4, u3} k V\u2082 (Ring.toSemiring.{u4} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u3, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u3} V\u2082 _inst_5)] (f : AffineMap.{u4, u2, u1, u3, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Eq.{succ u5} (AffineSubspace.{u4, u3, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u4, u2, u1, u3, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Bot.bot.{u1} (AffineSubspace.{u4, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u1} (AffineSubspace.{u4, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u4, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (Bot.bot.{u5} (AffineSubspace.{u4, u3, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toBot.{u5} (AffineSubspace.{u4, u3, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u4, u3, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_bot AffineSubspace.map_bot\u2093'. -/\n@[simp]\ntheorem map_bot : (\u22a5 : AffineSubspace k P\u2081).map f = \u22a5 :=\n  coe_injective <| image_empty f\n#align affine_subspace.map_bot AffineSubspace.map_bot\n\n/- warning: affine_subspace.map_eq_bot_iff -> AffineSubspace.map_eq_bot_iff is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, Iff (Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (Bot.bot.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toHasBot.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) s (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u1}} {P\u2082 : Type.{u2}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u1} V\u2082] [_inst_6 : Module.{u5, u1} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u1, u2} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u1} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4}, Iff (Eq.{succ u2} (AffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u5, u4, u3, u1, u2} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (Bot.bot.{u2} (AffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toBot.{u2} (AffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u1, u2} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (Eq.{succ u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) s (Bot.bot.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_eq_bot_iff AffineSubspace.map_eq_bot_iff\u2093'. -/\n@[simp]\ntheorem map_eq_bot_iff {s : AffineSubspace k P\u2081} : s.map f = \u22a5 \u2194 s = \u22a5 :=\n  by\n  refine' \u27e8fun h => _, fun h => _\u27e9\n  \u00b7 rwa [\u2190 coe_eq_bot_iff, coe_map, image_eq_empty, coe_eq_bot_iff] at h\n  \u00b7 rw [h, map_bot]\n#align affine_subspace.map_eq_bot_iff AffineSubspace.map_eq_bot_iff\n\nomit V\u2082\n\n/- warning: affine_subspace.map_id -> AffineSubspace.map_id is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.map.{u1, u2, u3, u2, u3} k V\u2081 P\u2081 V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 _inst_2 _inst_3 _inst_4 (AffineMap.id.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) s) s\nbut is expected to have type\n  forall {k : Type.{u3}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u3, u2} k V\u2081 (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.map.{u3, u2, u1, u2, u1} k V\u2081 P\u2081 V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 _inst_2 _inst_3 _inst_4 (AffineMap.id.{u3, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) s) s\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_id AffineSubspace.map_id\u2093'. -/\n@[simp]\ntheorem map_id (s : AffineSubspace k P\u2081) : s.map (AffineMap.id k P\u2081) = s :=\n  coe_injective <| image_id _\n#align affine_subspace.map_id AffineSubspace.map_id\n\ninclude V\u2082 V\u2083\n\n/- warning: affine_subspace.map_map -> AffineSubspace.map_map is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} {V\u2083 : Type.{u6}} {P\u2083 : Type.{u7}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] [_inst_8 : AddCommGroup.{u6} V\u2083] [_inst_9 : Module.{u1, u6} k V\u2083 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u6} V\u2083 _inst_8)] [_inst_10 : AddTorsor.{u6, u7} V\u2083 P\u2083 (AddCommGroup.toAddGroup.{u6} V\u2083 _inst_8)] (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (g : AffineMap.{u1, u4, u5, u6, u7} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10), Eq.{succ u7} (AffineSubspace.{u1, u6, u7} k V\u2083 P\u2083 _inst_1 _inst_8 _inst_9 _inst_10) (AffineSubspace.map.{u1, u4, u5, u6, u7} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (AffineSubspace.map.{u1, u2, u3, u6, u7} k V\u2081 P\u2081 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_8 _inst_9 _inst_10 (AffineMap.comp.{u1, u2, u3, u4, u5, u6, u7} k V\u2081 P\u2081 V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g f) s)\nbut is expected to have type\n  forall {k : Type.{u7}} {V\u2081 : Type.{u6}} {P\u2081 : Type.{u5}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u3}} {V\u2083 : Type.{u2}} {P\u2083 : Type.{u1}} [_inst_1 : Ring.{u7} k] [_inst_2 : AddCommGroup.{u6} V\u2081] [_inst_3 : Module.{u7, u6} k V\u2081 (Ring.toSemiring.{u7} k _inst_1) (AddCommGroup.toAddCommMonoid.{u6} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u6, u5} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u6} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u7, u4} k V\u2082 (Ring.toSemiring.{u7} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u3} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] [_inst_8 : AddCommGroup.{u2} V\u2083] [_inst_9 : Module.{u7, u2} k V\u2083 (Ring.toSemiring.{u7} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2083 _inst_8)] [_inst_10 : AddTorsor.{u2, u1} V\u2083 P\u2083 (AddCommGroup.toAddGroup.{u2} V\u2083 _inst_8)] (s : AffineSubspace.{u7, u6, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (f : AffineMap.{u7, u6, u5, u4, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (g : AffineMap.{u7, u4, u3, u2, u1} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10), Eq.{succ u1} (AffineSubspace.{u7, u2, u1} k V\u2083 P\u2083 _inst_1 _inst_8 _inst_9 _inst_10) (AffineSubspace.map.{u7, u4, u3, u2, u1} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g (AffineSubspace.map.{u7, u6, u5, u4, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (AffineSubspace.map.{u7, u6, u5, u2, u1} k V\u2081 P\u2081 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_8 _inst_9 _inst_10 (AffineMap.comp.{u7, u6, u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g f) s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_map AffineSubspace.map_map\u2093'. -/\ntheorem map_map (s : AffineSubspace k P\u2081) (f : P\u2081 \u2192\u1d43[k] P\u2082) (g : P\u2082 \u2192\u1d43[k] P\u2083) :\n    (s.map f).map g = s.map (g.comp f) :=\n  coe_injective <| image_image _ _ _\n#align affine_subspace.map_map AffineSubspace.map_map\n\nomit V\u2083\n\n/- warning: affine_subspace.map_direction -> AffineSubspace.map_direction is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u4} (Submodule.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_6) (AffineSubspace.direction.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Submodule.map.{u1, u1, u2, u4, max u2 u4} k k V\u2081 V\u2082 (Ring.toSemiring.{u1} k _inst_1) (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u1} k (Semiring.toNonAssocSemiring.{u1} k (Ring.toSemiring.{u1} k _inst_1))) (RingHomSurjective.ids.{u1} k (Ring.toSemiring.{u1} k _inst_1)) (LinearMap.{u1, u1, u2, u4} k k (Ring.toSemiring.{u1} k _inst_1) (Ring.toSemiring.{u1} k _inst_1) (RingHom.id.{u1} k (Semiring.toNonAssocSemiring.{u1} k (Ring.toSemiring.{u1} k _inst_1))) V\u2081 V\u2082 (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6) (LinearMap.semilinearMapClass.{u1, u1, u2, u4} k k V\u2081 V\u2082 (Ring.toSemiring.{u1} k _inst_1) (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u1} k (Semiring.toNonAssocSemiring.{u1} k (Ring.toSemiring.{u1} k _inst_1)))) (AffineMap.linear.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f) (AffineSubspace.direction.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u2} (Submodule.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5) _inst_6) (AffineSubspace.direction.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Submodule.map.{u5, u5, u4, u2, max u4 u2} k k V\u2081 V\u2082 (Ring.toSemiring.{u5} k _inst_1) (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u5} k (Semiring.toNonAssocSemiring.{u5} k (Ring.toSemiring.{u5} k _inst_1))) (RingHomSurjective.ids.{u5} k (Ring.toSemiring.{u5} k _inst_1)) (LinearMap.{u5, u5, u4, u2} k k (Ring.toSemiring.{u5} k _inst_1) (Ring.toSemiring.{u5} k _inst_1) (RingHom.id.{u5} k (Semiring.toNonAssocSemiring.{u5} k (Ring.toSemiring.{u5} k _inst_1))) V\u2081 V\u2082 (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5) _inst_3 _inst_6) (LinearMap.instSemilinearMapClassLinearMap.{u5, u5, u4, u2} k k V\u2081 V\u2082 (Ring.toSemiring.{u5} k _inst_1) (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5) _inst_3 _inst_6 (RingHom.id.{u5} k (Semiring.toNonAssocSemiring.{u5} k (Ring.toSemiring.{u5} k _inst_1)))) (AffineMap.linear.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f) (AffineSubspace.direction.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_direction AffineSubspace.map_direction\u2093'. -/\n@[simp]\ntheorem map_direction (s : AffineSubspace k P\u2081) : (s.map f).direction = s.direction.map f.linear :=\n  by simp [direction_eq_vector_span]\n#align affine_subspace.map_direction AffineSubspace.map_direction\n\n/- warning: affine_subspace.map_span -> AffineSubspace.map_span is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : Set.{u3} P\u2081), Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (affineSpan.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s)) (affineSpan.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u3, u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) s))\nbut is expected to have type\n  forall {k : Type.{u3}} {V\u2081 : Type.{u1}} {P\u2081 : Type.{u5}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u4}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u1} V\u2081] [_inst_3 : Module.{u3, u1} k V\u2081 (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u1, u5} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u1} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u3, u2} k V\u2082 (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u4} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u3, u1, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : Set.{u5} P\u2081), Eq.{succ u4} (AffineSubspace.{u3, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u3, u1, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (affineSpan.{u3, u1, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s)) (affineSpan.{u3, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u5, u4} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u1) (succ u5)) (succ u2)) (succ u4), succ u5, succ u4} (AffineMap.{u3, u1, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u3, u1, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_span AffineSubspace.map_span\u2093'. -/\ntheorem map_span (s : Set P\u2081) : (affineSpan k s).map f = affineSpan k (f '' s) :=\n  by\n  rcases s.eq_empty_or_nonempty with (rfl | \u27e8p, hp\u27e9); \u00b7 simp\n  apply ext_of_direction_eq\n  \u00b7 simp [direction_affineSpan]\n  \u00b7\n    exact\n      \u27e8f p, mem_image_of_mem f (subset_affineSpan k _ hp),\n        subset_affineSpan k _ (mem_image_of_mem f hp)\u27e9\n#align affine_subspace.map_span AffineSubspace.map_span\n\nend AffineSubspace\n\nnamespace AffineMap\n\n/- warning: affine_map.map_top_of_surjective -> AffineMap.map_top_of_surjective is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), (Function.Surjective.{succ u3, succ u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f)) -> (Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (Top.top.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toHasTop.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))\nbut is expected to have type\n  forall {k : Type.{u1}} {V\u2081 : Type.{u3}} {P\u2081 : Type.{u5}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u4}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u3} V\u2081] [_inst_3 : Module.{u1, u3} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u3, u5} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u3} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u1, u2} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u4} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), (Function.Surjective.{succ u5, succ u4} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u3) (succ u5)) (succ u2)) (succ u4), succ u5, succ u4} (AffineMap.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f)) -> (Eq.{succ u4} (AffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Top.top.{u5} (AffineSubspace.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toTop.{u5} (AffineSubspace.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (Top.top.{u4} (AffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toTop.{u4} (AffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))\nCase conversion may be inaccurate. Consider using '#align affine_map.map_top_of_surjective AffineMap.map_top_of_surjective\u2093'. -/\n@[simp]\ntheorem map_top_of_surjective (hf : Function.Surjective f) : AffineSubspace.map f \u22a4 = \u22a4 :=\n  by\n  rw [\u2190 AffineSubspace.ext_iff]\n  exact image_univ_of_surjective hf\n#align affine_map.map_top_of_surjective AffineMap.map_top_of_surjective\n\n/- warning: affine_map.span_eq_top_of_surjective -> AffineMap.span_eq_top_of_surjective is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {s : Set.{u3} P\u2081}, (Function.Surjective.{succ u3, succ u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f)) -> (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) -> (Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (affineSpan.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u3, u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) s)) (Top.top.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toHasTop.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))\nbut is expected to have type\n  forall {k : Type.{u1}} {V\u2081 : Type.{u3}} {P\u2081 : Type.{u5}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u4}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u3} V\u2081] [_inst_3 : Module.{u1, u3} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u3} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u3, u5} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u3} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u1, u2} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u4} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) {s : Set.{u5} P\u2081}, (Function.Surjective.{succ u5, succ u4} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u3) (succ u5)) (succ u2)) (succ u4), succ u5, succ u4} (AffineMap.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f)) -> (Eq.{succ u5} (AffineSubspace.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s) (Top.top.{u5} (AffineSubspace.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toTop.{u5} (AffineSubspace.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u1, u3, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) -> (Eq.{succ u4} (AffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (affineSpan.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u5, u4} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u3) (succ u5)) (succ u2)) (succ u4), succ u5, succ u4} (AffineMap.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u1, u3, u5, u2, u4} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) s)) (Top.top.{u4} (AffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toTop.{u4} (AffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u1, u2, u4} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))\nCase conversion may be inaccurate. Consider using '#align affine_map.span_eq_top_of_surjective AffineMap.span_eq_top_of_surjective\u2093'. -/\ntheorem span_eq_top_of_surjective {s : Set P\u2081} (hf : Function.Surjective f)\n    (h : affineSpan k s = \u22a4) : affineSpan k (f '' s) = \u22a4 := by\n  rw [\u2190 AffineSubspace.map_span, h, map_top_of_surjective f hf]\n#align affine_map.span_eq_top_of_surjective AffineMap.span_eq_top_of_surjective\n\nend AffineMap\n\nnamespace AffineEquiv\n\n/- warning: affine_equiv.span_eq_top_iff -> AffineEquiv.span_eq_top_iff is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {s : Set.{u3} P\u2081} (e : AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Iff (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (affineSpan.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u3, u5} P\u2081 P\u2082 (coeFn.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u3) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineEquiv.hasCoeToFun.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) e) s)) (Top.top.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toHasTop.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))\nbut is expected to have type\n  forall {k : Type.{u4}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u5}} {V\u2082 : Type.{u1}} {P\u2082 : Type.{u3}} [_inst_1 : Ring.{u4} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u4, u2} k V\u2081 (Ring.toSemiring.{u4} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u5} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u1} V\u2082] [_inst_6 : Module.{u4, u1} k V\u2082 (Ring.toSemiring.{u4} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u1, u3} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u1} V\u2082 _inst_5)] {s : Set.{u5} P\u2081} (e : AffineEquiv.{u4, u5, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Iff (Eq.{succ u5} (AffineSubspace.{u4, u2, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (affineSpan.{u4, u2, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 s) (Top.top.{u5} (AffineSubspace.{u4, u2, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toTop.{u5} (AffineSubspace.{u4, u2, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u4, u2, u5} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u3} (AffineSubspace.{u4, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (affineSpan.{u4, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 (Set.image.{u5, u3} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u5) (succ u3)) (succ u2)) (succ u1), succ u5, succ u3} (AffineEquiv.{u4, u5, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineEquiv._hyg.1471 : P\u2081) => P\u2082) _x) (EmbeddingLike.toFunLike.{max (max (max (succ u5) (succ u3)) (succ u2)) (succ u1), succ u5, succ u3} (AffineEquiv.{u4, u5, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 P\u2082 (EquivLike.toEmbeddingLike.{max (max (max (succ u5) (succ u3)) (succ u2)) (succ u1), succ u5, succ u3} (AffineEquiv.{u4, u5, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 P\u2082 (AffineEquiv.equivLike.{u4, u5, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7))) e) s)) (Top.top.{u3} (AffineSubspace.{u4, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toTop.{u3} (AffineSubspace.{u4, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u4, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))\nCase conversion may be inaccurate. Consider using '#align affine_equiv.span_eq_top_iff AffineEquiv.span_eq_top_iff\u2093'. -/\ntheorem span_eq_top_iff {s : Set P\u2081} (e : P\u2081 \u2243\u1d43[k] P\u2082) :\n    affineSpan k s = \u22a4 \u2194 affineSpan k (e '' s) = \u22a4 :=\n  by\n  refine' \u27e8(e : P\u2081 \u2192\u1d43[k] P\u2082).span_eq_top_of_surjective e.surjective, _\u27e9\n  intro h\n  have : s = e.symm '' (e '' s) := by simp [\u2190 image_comp]\n  rw [this]\n  exact (e.symm : P\u2082 \u2192\u1d43[k] P\u2081).span_eq_top_of_surjective e.symm.surjective h\n#align affine_equiv.span_eq_top_iff AffineEquiv.span_eq_top_iff\n\nend AffineEquiv\n\nend\n\nnamespace AffineSubspace\n\n#print AffineSubspace.comap /-\n/-- The preimage of an affine subspace under an affine map as an affine subspace. -/\ndef comap (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : AffineSubspace k P\u2082) : AffineSubspace k P\u2081\n    where\n  carrier := f \u207b\u00b9' s\n  smul_vsub_vadd_mem t p\u2081 p\u2082 p\u2083 (hp\u2081 : f p\u2081 \u2208 s) (hp\u2082 : f p\u2082 \u2208 s) (hp\u2083 : f p\u2083 \u2208 s) :=\n    show f _ \u2208 s by\n      rw [AffineMap.map_vadd, LinearMap.map_smul, AffineMap.linearMap_vsub]\n      apply s.smul_vsub_vadd_mem _ hp\u2081 hp\u2082 hp\u2083\n#align affine_subspace.comap AffineSubspace.comap\n-/\n\n/- warning: affine_subspace.coe_comap -> AffineSubspace.coe_comap is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7), Eq.{succ u3} (Set.{u3} P\u2081) ((fun (a : Type.{u3}) (b : Type.{u3}) [self : HasLiftT.{succ u3, succ u3} a b] => self.0) (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P\u2081) (HasLiftT.mk.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P\u2081) (CoeTC\u2093.coe.{succ u3, succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Set.{u3} P\u2081) (SetLike.Set.hasCoeT.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Set.preimage.{u3, u5} P\u2081 P\u2082 (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) ((fun (a : Type.{u5}) (b : Type.{u5}) [self : HasLiftT.{succ u5, succ u5} a b] => self.0) (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Set.{u5} P\u2082) (HasLiftT.mk.{succ u5, succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Set.{u5} P\u2082) (CoeTC\u2093.coe.{succ u5, succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Set.{u5} P\u2082) (SetLike.Set.hasCoeT.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) s))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7), Eq.{succ u3} (Set.{u3} P\u2081) (SetLike.coe.{u3, u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.instSetLikeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Set.preimage.{u3, u1} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u3, succ u1} (AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) (SetLike.coe.{u1, u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.instSetLikeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.coe_comap AffineSubspace.coe_comap\u2093'. -/\n@[simp]\ntheorem coe_comap (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : AffineSubspace k P\u2082) : (s.comap f : Set P\u2081) = f \u207b\u00b9' \u2191s :=\n  rfl\n#align affine_subspace.coe_comap AffineSubspace.coe_comap\n\n/- warning: affine_subspace.mem_comap -> AffineSubspace.mem_comap is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {x : P\u2081} {s : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7}, Iff (Membership.Mem.{u3, u3} P\u2081 (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) x (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Membership.Mem.{u5, u5} P\u2082 (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.hasMem.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) (coeFn.{max (succ u2) (succ u3) (succ u4) (succ u5), max (succ u3) (succ u5)} (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineMap.hasCoeToFun.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f x) s)\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {x : P\u2081} {s : AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7}, Iff (Membership.mem.{u3, u3} P\u2081 (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.instSetLikeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)) x (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) (Membership.mem.{u1, u1} ((fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) x) (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.instMembership.{u1, u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.instSetLikeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)) (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u3, succ u1} (AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineMap._hyg.1004 : P\u2081) => P\u2082) _x) (AffineMap.funLike.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f x) s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.mem_comap AffineSubspace.mem_comap\u2093'. -/\n@[simp]\ntheorem mem_comap {f : P\u2081 \u2192\u1d43[k] P\u2082} {x : P\u2081} {s : AffineSubspace k P\u2082} : x \u2208 s.comap f \u2194 f x \u2208 s :=\n  Iff.rfl\n#align affine_subspace.mem_comap AffineSubspace.mem_comap\n\n/- warning: affine_subspace.comap_mono -> AffineSubspace.comap_mono is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {s : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7} {t : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7}, (LE.le.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Preorder.toLE.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.partialOrder.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) s t) -> (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {s : AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7} {t : AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7}, (LE.le.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Preorder.toLE.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))) s t) -> (LE.le.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))) (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_mono AffineSubspace.comap_mono\u2093'. -/\ntheorem comap_mono {f : P\u2081 \u2192\u1d43[k] P\u2082} {s t : AffineSubspace k P\u2082} : s \u2264 t \u2192 s.comap f \u2264 t.comap f :=\n  preimage_mono\n#align affine_subspace.comap_mono AffineSubspace.comap_mono\n\n/- warning: affine_subspace.comap_top -> AffineSubspace.comap_top is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7}, Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Top.top.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toHasTop.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (Top.top.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasTop.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7}, Eq.{succ u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Top.top.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toTop.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (Top.top.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toTop.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_top AffineSubspace.comap_top\u2093'. -/\n@[simp]\ntheorem comap_top {f : P\u2081 \u2192\u1d43[k] P\u2082} : (\u22a4 : AffineSubspace k P\u2082).comap f = \u22a4 :=\n  by\n  rw [\u2190 ext_iff]\n  exact preimage_univ\n#align affine_subspace.comap_top AffineSubspace.comap_top\n\nomit V\u2082\n\n/- warning: affine_subspace.comap_id -> AffineSubspace.comap_id is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u1, u2, u3, u2, u3} k V\u2081 P\u2081 V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 _inst_2 _inst_3 _inst_4 (AffineMap.id.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) s) s\nbut is expected to have type\n  forall {k : Type.{u3}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u3, u2} k V\u2081 (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u3, u2, u1, u2, u1} k V\u2081 P\u2081 V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 _inst_2 _inst_3 _inst_4 (AffineMap.id.{u3, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) s) s\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_id AffineSubspace.comap_id\u2093'. -/\n@[simp]\ntheorem comap_id (s : AffineSubspace k P\u2081) : s.comap (AffineMap.id k P\u2081) = s :=\n  coe_injective rfl\n#align affine_subspace.comap_id AffineSubspace.comap_id\n\ninclude V\u2082 V\u2083\n\n/- warning: affine_subspace.comap_comap -> AffineSubspace.comap_comap is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} {V\u2083 : Type.{u6}} {P\u2083 : Type.{u7}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] [_inst_8 : AddCommGroup.{u6} V\u2083] [_inst_9 : Module.{u1, u6} k V\u2083 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u6} V\u2083 _inst_8)] [_inst_10 : AddTorsor.{u6, u7} V\u2083 P\u2083 (AddCommGroup.toAddGroup.{u6} V\u2083 _inst_8)] (s : AffineSubspace.{u1, u6, u7} k V\u2083 P\u2083 _inst_1 _inst_8 _inst_9 _inst_10) (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (g : AffineMap.{u1, u4, u5, u6, u7} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (AffineSubspace.comap.{u1, u4, u5, u6, u7} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g s)) (AffineSubspace.comap.{u1, u2, u3, u6, u7} k V\u2081 P\u2081 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_8 _inst_9 _inst_10 (AffineMap.comp.{u1, u2, u3, u4, u5, u6, u7} k V\u2081 P\u2081 V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g f) s)\nbut is expected to have type\n  forall {k : Type.{u7}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} {V\u2083 : Type.{u6}} {P\u2083 : Type.{u5}} [_inst_1 : Ring.{u7} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u7, u4} k V\u2081 (Ring.toSemiring.{u7} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u7, u2} k V\u2082 (Ring.toSemiring.{u7} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] [_inst_8 : AddCommGroup.{u6} V\u2083] [_inst_9 : Module.{u7, u6} k V\u2083 (Ring.toSemiring.{u7} k _inst_1) (AddCommGroup.toAddCommMonoid.{u6} V\u2083 _inst_8)] [_inst_10 : AddTorsor.{u6, u5} V\u2083 P\u2083 (AddCommGroup.toAddGroup.{u6} V\u2083 _inst_8)] (s : AffineSubspace.{u7, u6, u5} k V\u2083 P\u2083 _inst_1 _inst_8 _inst_9 _inst_10) (f : AffineMap.{u7, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (g : AffineMap.{u7, u2, u1, u6, u5} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10), Eq.{succ u3} (AffineSubspace.{u7, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u7, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (AffineSubspace.comap.{u7, u2, u1, u6, u5} k V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g s)) (AffineSubspace.comap.{u7, u4, u3, u6, u5} k V\u2081 P\u2081 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_8 _inst_9 _inst_10 (AffineMap.comp.{u7, u4, u3, u2, u1, u6, u5} k V\u2081 P\u2081 V\u2082 P\u2082 V\u2083 P\u2083 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 _inst_8 _inst_9 _inst_10 g f) s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_comap AffineSubspace.comap_comap\u2093'. -/\ntheorem comap_comap (s : AffineSubspace k P\u2083) (f : P\u2081 \u2192\u1d43[k] P\u2082) (g : P\u2082 \u2192\u1d43[k] P\u2083) :\n    (s.comap g).comap f = s.comap (g.comp f) :=\n  coe_injective rfl\n#align affine_subspace.comap_comap AffineSubspace.comap_comap\n\nomit V\u2083\n\n/- warning: affine_subspace.map_le_iff_le_comap -> AffineSubspace.map_le_iff_le_comap is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4} {t : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7}, Iff (LE.le.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Preorder.toLE.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.partialOrder.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) t) (LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) s (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7} {s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4} {t : AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7}, Iff (LE.le.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Preorder.toLE.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) t) (LE.le.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))) s (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_le_iff_le_comap AffineSubspace.map_le_iff_le_comap\u2093'. -/\n-- lemmas about map and comap derived from the galois connection\ntheorem map_le_iff_le_comap {f : P\u2081 \u2192\u1d43[k] P\u2082} {s : AffineSubspace k P\u2081} {t : AffineSubspace k P\u2082} :\n    s.map f \u2264 t \u2194 s \u2264 t.comap f :=\n  image_subset_iff\n#align affine_subspace.map_le_iff_le_comap AffineSubspace.map_le_iff_le_comap\n\n/- warning: affine_subspace.gc_map_comap -> AffineSubspace.gc_map_comap is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), GaloisConnection.{u3, u5} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))) (PartialOrder.toPreorder.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.partialOrder.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f)\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), GaloisConnection.{u3, u1} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f) (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.gc_map_comap AffineSubspace.gc_map_comap\u2093'. -/\ntheorem gc_map_comap (f : P\u2081 \u2192\u1d43[k] P\u2082) : GaloisConnection (map f) (comap f) := fun _ _ =>\n  map_le_iff_le_comap\n#align affine_subspace.gc_map_comap AffineSubspace.gc_map_comap\n\n/- warning: affine_subspace.map_comap_le -> AffineSubspace.map_comap_le is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7), LE.le.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Preorder.toLE.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SetLike.partialOrder.{u5, u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) P\u2082 (AffineSubspace.setLike.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) s\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7), LE.le.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Preorder.toLE.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (PartialOrder.toPreorder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (OmegaCompletePartialOrder.toPartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.instOmegaCompletePartialOrder.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s)) s\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_comap_le AffineSubspace.map_comap_le\u2093'. -/\ntheorem map_comap_le (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : AffineSubspace k P\u2082) : (s.comap f).map f \u2264 s :=\n  (gc_map_comap f).l_u_le _\n#align affine_subspace.map_comap_le AffineSubspace.map_comap_le\n\n/- warning: affine_subspace.le_comap_map -> AffineSubspace.le_comap_map is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), LE.le.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SetLike.partialOrder.{u3, u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) P\u2081 (AffineSubspace.setLike.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) s (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), LE.le.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Preorder.toLE.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (PartialOrder.toPreorder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (OmegaCompletePartialOrder.toPartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.instOmegaCompletePartialOrder.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))) s (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.le_comap_map AffineSubspace.le_comap_map\u2093'. -/\ntheorem le_comap_map (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : AffineSubspace k P\u2081) : s \u2264 (s.map f).comap f :=\n  (gc_map_comap f).le_u_l _\n#align affine_subspace.le_comap_map AffineSubspace.le_comap_map\n\n/- warning: affine_subspace.map_sup -> AffineSubspace.map_sup is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (t : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Sup.sup.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SemilatticeSup.toHasSup.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Lattice.toSemilatticeSup.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))) s t)) (Sup.sup.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SemilatticeSup.toHasSup.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Lattice.toSemilatticeSup.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toLattice.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] (s : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (t : AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Eq.{succ u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Sup.sup.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SemilatticeSup.toSup.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Lattice.toSemilatticeSup.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))) s t)) (Sup.sup.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SemilatticeSup.toSup.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Lattice.toSemilatticeSup.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_sup AffineSubspace.map_sup\u2093'. -/\ntheorem map_sup (s t : AffineSubspace k P\u2081) (f : P\u2081 \u2192\u1d43[k] P\u2082) : (s \u2294 t).map f = s.map f \u2294 t.map f :=\n  (gc_map_comap f).l_sup\n#align affine_subspace.map_sup AffineSubspace.map_sup\n\n/- warning: affine_subspace.map_supr -> AffineSubspace.map_sup\u1d62 is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {\u03b9 : Sort.{u6}} (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : \u03b9 -> (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)), Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (sup\u1d62.{u3, u6} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toHasSup.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))) \u03b9 s)) (sup\u1d62.{u5, u6} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toHasSup.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))) \u03b9 (fun (i : \u03b9) => AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (s i)))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {\u03b9 : Sort.{u6}} (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : \u03b9 -> (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)), Eq.{succ u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (sup\u1d62.{u3, u6} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toSupSet.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))) \u03b9 s)) (sup\u1d62.{u1, u6} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toSupSet.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))) \u03b9 (fun (i : \u03b9) => AffineSubspace.map.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (s i)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_supr AffineSubspace.map_sup\u1d62\u2093'. -/\ntheorem map_sup\u1d62 {\u03b9 : Sort _} (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : \u03b9 \u2192 AffineSubspace k P\u2081) :\n    (sup\u1d62 s).map f = \u2a06 i, (s i).map f :=\n  (gc_map_comap f).l_sup\u1d62\n#align affine_subspace.map_supr AffineSubspace.map_sup\u1d62\n\n/- warning: affine_subspace.comap_inf -> AffineSubspace.comap_inf is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (s : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (t : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Inf.inf.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (SemilatticeInf.toHasInf.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Lattice.toSemilatticeInf.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toLattice.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))))) s t)) (Inf.inf.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (SemilatticeInf.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Lattice.toSemilatticeInf.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))))) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u1}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u3}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u5, u2} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u5, u4} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u3} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (s : AffineSubspace.{u5, u4, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (t : AffineSubspace.{u5, u4, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (f : AffineMap.{u5, u2, u1, u4, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7), Eq.{succ u1} (AffineSubspace.{u5, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u5, u2, u1, u4, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (Inf.inf.{u3} (AffineSubspace.{u5, u4, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (Lattice.toInf.{u3} (AffineSubspace.{u5, u4, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toLattice.{u3} (AffineSubspace.{u5, u4, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u5, u4, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)))) s t)) (Inf.inf.{u1} (AffineSubspace.{u5, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (Lattice.toInf.{u1} (AffineSubspace.{u5, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toLattice.{u1} (AffineSubspace.{u5, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u5, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4)))) (AffineSubspace.comap.{u5, u2, u1, u4, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f s) (AffineSubspace.comap.{u5, u2, u1, u4, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f t))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_inf AffineSubspace.comap_inf\u2093'. -/\ntheorem comap_inf (s t : AffineSubspace k P\u2082) (f : P\u2081 \u2192\u1d43[k] P\u2082) :\n    (s \u2293 t).comap f = s.comap f \u2293 t.comap f :=\n  (gc_map_comap f).u_inf\n#align affine_subspace.comap_inf AffineSubspace.comap_inf\n\n/- warning: affine_subspace.comap_supr -> AffineSubspace.comap_supr is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] {\u03b9 : Sort.{u6}} (f : AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : \u03b9 -> (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (inf\u1d62.{u5, u6} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toHasInf.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.completeLattice.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))) \u03b9 s)) (inf\u1d62.{u3, u6} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toHasInf.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))) \u03b9 (fun (i : \u03b9) => AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (s i)))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u4}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u2}} {P\u2082 : Type.{u1}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u4} V\u2081] [_inst_3 : Module.{u5, u4} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u4, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u4} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u2} V\u2082] [_inst_6 : Module.{u5, u2} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u2, u1} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u2} V\u2082 _inst_5)] {\u03b9 : Sort.{u6}} (f : AffineMap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : \u03b9 -> (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7)), Eq.{succ u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (inf\u1d62.{u1, u6} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (ConditionallyCompleteLattice.toInfSet.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (CompleteLattice.toConditionallyCompleteLattice.{u1} (AffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u2, u1} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7))) \u03b9 s)) (inf\u1d62.{u3, u6} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (ConditionallyCompleteLattice.toInfSet.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toConditionallyCompleteLattice.{u3} (AffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u5, u4, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4))) \u03b9 (fun (i : \u03b9) => AffineSubspace.comap.{u5, u4, u3, u2, u1} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f (s i)))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_supr AffineSubspace.comap_supr\u2093'. -/\ntheorem comap_supr {\u03b9 : Sort _} (f : P\u2081 \u2192\u1d43[k] P\u2082) (s : \u03b9 \u2192 AffineSubspace k P\u2082) :\n    (inf\u1d62 s).comap f = \u2a05 i, (s i).comap f :=\n  (gc_map_comap f).u_inf\u1d62\n#align affine_subspace.comap_supr AffineSubspace.comap_supr\n\n/- warning: affine_subspace.comap_symm -> AffineSubspace.comap_symm is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (e : AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u5} (AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.comap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4 ((fun (a : Sort.{max (succ u5) (succ u3) (succ u4) (succ u2)}) (b : Sort.{max (succ u4) (succ u5) (succ u2) (succ u3)}) [self : HasLiftT.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} a b] => self.0) (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (HasLiftT.mk.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (CoeTC\u2093.coe.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (coeBase.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineEquiv.AffineMap.hasCoe.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4)))) (AffineEquiv.symm.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 e)) s) (AffineSubspace.map.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 ((fun (a : Sort.{max (succ u3) (succ u5) (succ u2) (succ u4)}) (b : Sort.{max (succ u2) (succ u3) (succ u4) (succ u5)}) [self : HasLiftT.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} a b] => self.0) (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (HasLiftT.mk.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (CoeTC\u2093.coe.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (coeBase.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineEquiv.AffineMap.hasCoe.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7)))) e) s)\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u4}} {V\u2082 : Type.{u1}} {P\u2082 : Type.{u3}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u5, u2} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u4} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u1} V\u2082] [_inst_6 : Module.{u5, u1} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u1, u3} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u1} V\u2082 _inst_5)] (e : AffineEquiv.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u5, u2, u4} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4), Eq.{succ u3} (AffineSubspace.{u5, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7) (AffineSubspace.comap.{u5, u1, u3, u2, u4} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4 (AffineEquiv.toAffineMap.{u5, u3, u4, u1, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4 (AffineEquiv.symm.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 e)) s) (AffineSubspace.map.{u5, u2, u4, u1, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 (AffineEquiv.toAffineMap.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 e) s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_symm AffineSubspace.comap_symm\u2093'. -/\n@[simp]\ntheorem comap_symm (e : P\u2081 \u2243\u1d43[k] P\u2082) (s : AffineSubspace k P\u2081) :\n    s.comap (e.symm : P\u2082 \u2192\u1d43[k] P\u2081) = s.map e :=\n  coe_injective <| e.preimage_symm _\n#align affine_subspace.comap_symm AffineSubspace.comap_symm\n\n/- warning: affine_subspace.map_symm -> AffineSubspace.map_symm is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (e : AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.map.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4 ((fun (a : Sort.{max (succ u5) (succ u3) (succ u4) (succ u2)}) (b : Sort.{max (succ u4) (succ u5) (succ u2) (succ u3)}) [self : HasLiftT.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} a b] => self.0) (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (HasLiftT.mk.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (CoeTC\u2093.coe.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (coeBase.{max (succ u5) (succ u3) (succ u4) (succ u2), max (succ u4) (succ u5) (succ u2) (succ u3)} (AffineEquiv.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineMap.{u1, u4, u5, u2, u3} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4) (AffineEquiv.AffineMap.hasCoe.{u1, u5, u3, u4, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4)))) (AffineEquiv.symm.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 e)) s) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 ((fun (a : Sort.{max (succ u3) (succ u5) (succ u2) (succ u4)}) (b : Sort.{max (succ u2) (succ u3) (succ u4) (succ u5)}) [self : HasLiftT.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} a b] => self.0) (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (HasLiftT.mk.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (CoeTC\u2093.coe.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (coeBase.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineEquiv.AffineMap.hasCoe.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7)))) e) s)\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u4}} {V\u2082 : Type.{u1}} {P\u2082 : Type.{u3}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u5, u2} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u4} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u1} V\u2082] [_inst_6 : Module.{u5, u1} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u1, u3} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u1} V\u2082 _inst_5)] (e : AffineEquiv.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : AffineSubspace.{u5, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7), Eq.{succ u4} (AffineSubspace.{u5, u2, u4} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.map.{u5, u1, u3, u2, u4} k V\u2082 P\u2082 V\u2081 P\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4 (AffineEquiv.toAffineMap.{u5, u3, u4, u1, u2} k P\u2082 P\u2081 V\u2082 V\u2081 _inst_1 _inst_5 _inst_6 _inst_7 _inst_2 _inst_3 _inst_4 (AffineEquiv.symm.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 e)) s) (AffineSubspace.comap.{u5, u2, u4, u1, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 (AffineEquiv.toAffineMap.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 e) s)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.map_symm AffineSubspace.map_symm\u2093'. -/\n@[simp]\ntheorem map_symm (e : P\u2081 \u2243\u1d43[k] P\u2082) (s : AffineSubspace k P\u2082) :\n    s.map (e.symm : P\u2082 \u2192\u1d43[k] P\u2081) = s.comap e :=\n  coe_injective <| e.image_symm _\n#align affine_subspace.map_symm AffineSubspace.map_symm\n\n/- warning: affine_subspace.comap_span -> AffineSubspace.comap_span is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u3}} {V\u2082 : Type.{u4}} {P\u2082 : Type.{u5}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u1, u2} k V\u2081 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u4} V\u2082] [_inst_6 : Module.{u1, u4} k V\u2082 (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u4} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u4, u5} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u4} V\u2082 _inst_5)] (f : AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : Set.{u5} P\u2082), Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 ((fun (a : Sort.{max (succ u3) (succ u5) (succ u2) (succ u4)}) (b : Sort.{max (succ u2) (succ u3) (succ u4) (succ u5)}) [self : HasLiftT.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} a b] => self.0) (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (HasLiftT.mk.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (CoeTC\u2093.coe.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (coeBase.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u2) (succ u3) (succ u4) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineMap.{u1, u2, u3, u4, u5} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (AffineEquiv.AffineMap.hasCoe.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7)))) f) (affineSpan.{u1, u4, u5} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 s)) (affineSpan.{u1, u2, u3} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 (Set.preimage.{u3, u5} P\u2081 P\u2082 (coeFn.{max (succ u3) (succ u5) (succ u2) (succ u4), max (succ u3) (succ u5)} (AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (fun (_x : AffineEquiv.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) => P\u2081 -> P\u2082) (AffineEquiv.hasCoeToFun.{u1, u3, u5, u2, u4} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) f) s))\nbut is expected to have type\n  forall {k : Type.{u5}} {V\u2081 : Type.{u2}} {P\u2081 : Type.{u4}} {V\u2082 : Type.{u1}} {P\u2082 : Type.{u3}} [_inst_1 : Ring.{u5} k] [_inst_2 : AddCommGroup.{u2} V\u2081] [_inst_3 : Module.{u5, u2} k V\u2081 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V\u2081 _inst_2)] [_inst_4 : AddTorsor.{u2, u4} V\u2081 P\u2081 (AddCommGroup.toAddGroup.{u2} V\u2081 _inst_2)] [_inst_5 : AddCommGroup.{u1} V\u2082] [_inst_6 : Module.{u5, u1} k V\u2082 (Ring.toSemiring.{u5} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V\u2082 _inst_5)] [_inst_7 : AddTorsor.{u1, u3} V\u2082 P\u2082 (AddCommGroup.toAddGroup.{u1} V\u2082 _inst_5)] (f : AffineEquiv.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) (s : Set.{u3} P\u2082), Eq.{succ u4} (AffineSubspace.{u5, u2, u4} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.comap.{u5, u2, u4, u1, u3} k V\u2081 P\u2081 V\u2082 P\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 (AffineEquiv.toAffineMap.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7 f) (affineSpan.{u5, u1, u3} k V\u2082 P\u2082 _inst_1 _inst_5 _inst_6 _inst_7 s)) (affineSpan.{u5, u2, u4} k V\u2081 P\u2081 _inst_1 _inst_2 _inst_3 _inst_4 (Set.preimage.{u4, u3} P\u2081 P\u2082 (FunLike.coe.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u4, succ u3} (AffineEquiv.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 (fun (_x : P\u2081) => (fun (a._@.Mathlib.LinearAlgebra.AffineSpace.AffineEquiv._hyg.1471 : P\u2081) => P\u2082) _x) (EmbeddingLike.toFunLike.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u4, succ u3} (AffineEquiv.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 P\u2082 (EquivLike.toEmbeddingLike.{max (max (max (succ u4) (succ u3)) (succ u2)) (succ u1), succ u4, succ u3} (AffineEquiv.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7) P\u2081 P\u2082 (AffineEquiv.equivLike.{u5, u4, u3, u2, u1} k P\u2081 P\u2082 V\u2081 V\u2082 _inst_1 _inst_2 _inst_3 _inst_4 _inst_5 _inst_6 _inst_7))) f) s))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.comap_span AffineSubspace.comap_span\u2093'. -/\ntheorem comap_span (f : P\u2081 \u2243\u1d43[k] P\u2082) (s : Set P\u2082) :\n    (affineSpan k s).comap (f : P\u2081 \u2192\u1d43[k] P\u2082) = affineSpan k (f \u207b\u00b9' s) := by\n  rw [\u2190 map_symm, map_span, AffineEquiv.coe_coe, f.image_symm]\n#align affine_subspace.comap_span AffineSubspace.comap_span\n\nend AffineSubspace\n\nend MapComap\n\nnamespace AffineSubspace\n\nopen AffineEquiv\n\nvariable {k : Type _} {V : Type _} {P : Type _} [Ring k] [AddCommGroup V] [Module k V]\n\nvariable [affine_space V P]\n\ninclude V\n\n#print AffineSubspace.Parallel /-\n/-- Two affine subspaces are parallel if one is related to the other by adding the same vector\nto all points. -/\ndef Parallel (s\u2081 s\u2082 : AffineSubspace k P) : Prop :=\n  \u2203 v : V, s\u2082 = s\u2081.map (constVAdd k P v)\n#align affine_subspace.parallel AffineSubspace.Parallel\n-/\n\n-- mathport name: affine_subspace.parallel\nscoped[Affine] infixl:50 \" \u2225 \" => AffineSubspace.Parallel\n\n/- warning: affine_subspace.parallel.symm -> AffineSubspace.Parallel.symm is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) -> (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082 s\u2081)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) -> (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082 s\u2081)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel.symm AffineSubspace.Parallel.symm\u2093'. -/\n@[symm]\ntheorem Parallel.symm {s\u2081 s\u2082 : AffineSubspace k P} (h : s\u2081 \u2225 s\u2082) : s\u2082 \u2225 s\u2081 :=\n  by\n  rcases h with \u27e8v, rfl\u27e9\n  refine' \u27e8-v, _\u27e9\n  rw [map_map, \u2190 coe_trans_to_affine_map, \u2190 const_vadd_add, neg_add_self, const_vadd_zero,\n    coe_refl_to_affine_map, map_id]\n#align affine_subspace.parallel.symm AffineSubspace.Parallel.symm\n\n/- warning: affine_subspace.parallel_comm -> AffineSubspace.parallel_comm is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082 s\u2081)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082 s\u2081)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel_comm AffineSubspace.parallel_comm\u2093'. -/\ntheorem parallel_comm {s\u2081 s\u2082 : AffineSubspace k P} : s\u2081 \u2225 s\u2082 \u2194 s\u2082 \u2225 s\u2081 :=\n  \u27e8Parallel.symm, Parallel.symm\u27e9\n#align affine_subspace.parallel_comm AffineSubspace.parallel_comm\n\n/- warning: affine_subspace.parallel.refl -> AffineSubspace.Parallel.refl is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4), AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s s\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] (s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4), AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s s\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel.refl AffineSubspace.Parallel.refl\u2093'. -/\n@[refl]\ntheorem Parallel.refl (s : AffineSubspace k P) : s \u2225 s :=\n  \u27e80, by simp\u27e9\n#align affine_subspace.parallel.refl AffineSubspace.Parallel.refl\n\n/- warning: affine_subspace.parallel.trans -> AffineSubspace.Parallel.trans is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2083 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) -> (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082 s\u2083) -> (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2083)\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2083 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) -> (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082 s\u2083) -> (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2083)\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel.trans AffineSubspace.Parallel.trans\u2093'. -/\n@[trans]\ntheorem Parallel.trans {s\u2081 s\u2082 s\u2083 : AffineSubspace k P} (h\u2081\u2082 : s\u2081 \u2225 s\u2082) (h\u2082\u2083 : s\u2082 \u2225 s\u2083) : s\u2081 \u2225 s\u2083 :=\n  by\n  rcases h\u2081\u2082 with \u27e8v\u2081\u2082, rfl\u27e9\n  rcases h\u2082\u2083 with \u27e8v\u2082\u2083, rfl\u27e9\n  refine' \u27e8v\u2082\u2083 + v\u2081\u2082, _\u27e9\n  rw [map_map, \u2190 coe_trans_to_affine_map, \u2190 const_vadd_add]\n#align affine_subspace.parallel.trans AffineSubspace.Parallel.trans\n\n/- warning: affine_subspace.parallel.direction_eq -> AffineSubspace.Parallel.direction_eq is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) -> (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel.direction_eq AffineSubspace.Parallel.direction_eq\u2093'. -/\ntheorem Parallel.direction_eq {s\u2081 s\u2082 : AffineSubspace k P} (h : s\u2081 \u2225 s\u2082) :\n    s\u2081.direction = s\u2082.direction := by\n  rcases h with \u27e8v, rfl\u27e9\n  simp\n#align affine_subspace.parallel.direction_eq AffineSubspace.Parallel.direction_eq\n\n/- warning: affine_subspace.parallel_bot_iff_eq_bot -> AffineSubspace.parallel_bot_iff_eq_bot is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel_bot_iff_eq_bot AffineSubspace.parallel_bot_iff_eq_bot\u2093'. -/\n@[simp]\ntheorem parallel_bot_iff_eq_bot {s : AffineSubspace k P} : s \u2225 \u22a5 \u2194 s = \u22a5 :=\n  by\n  refine' \u27e8fun h => _, fun h => h \u25b8 parallel.refl _\u27e9\n  rcases h with \u27e8v, h\u27e9\n  rwa [eq_comm, map_eq_bot_iff] at h\n#align affine_subspace.parallel_bot_iff_eq_bot AffineSubspace.parallel_bot_iff_eq_bot\n\n/- warning: affine_subspace.bot_parallel_iff_eq_bot -> AffineSubspace.bot_parallel_iff_eq_bot is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))) s) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4))) s) (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.bot_parallel_iff_eq_bot AffineSubspace.bot_parallel_iff_eq_bot\u2093'. -/\n@[simp]\ntheorem bot_parallel_iff_eq_bot {s : AffineSubspace k P} : \u22a5 \u2225 s \u2194 s = \u22a5 := by\n  rw [parallel_comm, parallel_bot_iff_eq_bot]\n#align affine_subspace.bot_parallel_iff_eq_bot AffineSubspace.bot_parallel_iff_eq_bot\n\n/- warning: affine_subspace.parallel_iff_direction_eq_and_eq_bot_iff_eq_bot -> AffineSubspace.parallel_iff_direction_eq_and_eq_bot_iff_eq_bot is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) (And (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (AffineSubspace.direction.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) (Iff (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2081 (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2082 (Bot.bot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toHasBot.{u3} (AffineSubspace.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.completeLattice.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4))))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4} {s\u2082 : AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4}, Iff (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081 s\u2082) (And (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (AffineSubspace.direction.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) (Iff (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2081 (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4)))) (Eq.{succ u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) s\u2082 (Bot.bot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (CompleteLattice.toBot.{u1} (AffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4) (AffineSubspace.instCompleteLatticeAffineSubspace.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4))))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel_iff_direction_eq_and_eq_bot_iff_eq_bot AffineSubspace.parallel_iff_direction_eq_and_eq_bot_iff_eq_bot\u2093'. -/\ntheorem parallel_iff_direction_eq_and_eq_bot_iff_eq_bot {s\u2081 s\u2082 : AffineSubspace k P} :\n    s\u2081 \u2225 s\u2082 \u2194 s\u2081.direction = s\u2082.direction \u2227 (s\u2081 = \u22a5 \u2194 s\u2082 = \u22a5) :=\n  by\n  refine' \u27e8fun h => \u27e8h.direction_eq, _, _\u27e9, fun h => _\u27e9\n  \u00b7 rintro rfl\n    exact bot_parallel_iff_eq_bot.1 h\n  \u00b7 rintro rfl\n    exact parallel_bot_iff_eq_bot.1 h\n  \u00b7 rcases h with \u27e8hd, hb\u27e9\n    by_cases hs\u2081 : s\u2081 = \u22a5\n    \u00b7 rw [hs\u2081, bot_parallel_iff_eq_bot]\n      exact hb.1 hs\u2081\n    \u00b7 have hs\u2082 : s\u2082 \u2260 \u22a5 := hb.not.1 hs\u2081\n      rcases(nonempty_iff_ne_bot s\u2081).2 hs\u2081 with \u27e8p\u2081, hp\u2081\u27e9\n      rcases(nonempty_iff_ne_bot s\u2082).2 hs\u2082 with \u27e8p\u2082, hp\u2082\u27e9\n      refine' \u27e8p\u2082 -\u1d65 p\u2081, (eq_iff_direction_eq_of_mem hp\u2082 _).2 _\u27e9\n      \u00b7 rw [mem_map]\n        refine' \u27e8p\u2081, hp\u2081, _\u27e9\n        simp\n      \u00b7 simpa using hd.symm\n#align affine_subspace.parallel_iff_direction_eq_and_eq_bot_iff_eq_bot AffineSubspace.parallel_iff_direction_eq_and_eq_bot_iff_eq_bot\n\n/- warning: affine_subspace.parallel.vector_span_eq -> AffineSubspace.Parallel.vectorSpan_eq is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) -> (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, (AffineSubspace.Parallel.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) -> (Eq.{succ u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.parallel.vector_span_eq AffineSubspace.Parallel.vectorSpan_eq\u2093'. -/\ntheorem Parallel.vectorSpan_eq {s\u2081 s\u2082 : Set P} (h : affineSpan k s\u2081 \u2225 affineSpan k s\u2082) :\n    vectorSpan k s\u2081 = vectorSpan k s\u2082 :=\n  by\n  simp_rw [\u2190 direction_affineSpan]\n  exact h.direction_eq\n#align affine_subspace.parallel.vector_span_eq AffineSubspace.Parallel.vectorSpan_eq\n\n/- warning: affine_subspace.affine_span_parallel_iff_vector_span_eq_and_eq_empty_iff_eq_empty -> AffineSubspace.affineSpan_parallel_iff_vectorSpan_eq_and_eq_empty_iff_eq_empty is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, Iff (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) (And (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) (Iff (Eq.{succ u3} (Set.{u3} P) s\u2081 (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P))) (Eq.{succ u3} (Set.{u3} P) s\u2082 (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.hasEmptyc.{u3} P)))))\nbut is expected to have type\n  forall {k : Type.{u2}} {V : Type.{u1}} {P : Type.{u3}} [_inst_1 : Ring.{u2} k] [_inst_2 : AddCommGroup.{u1} V] [_inst_3 : Module.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2)] [_inst_4 : AddTorsor.{u1, u3} V P (AddCommGroup.toAddGroup.{u1} V _inst_2)] {s\u2081 : Set.{u3} P} {s\u2082 : Set.{u3} P}, Iff (AffineSubspace.Parallel.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (affineSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) (And (Eq.{succ u1} (Submodule.{u2, u1} k V (Ring.toSemiring.{u2} k _inst_1) (AddCommGroup.toAddCommMonoid.{u1} V _inst_2) _inst_3) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2081) (vectorSpan.{u2, u1, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 s\u2082)) (Iff (Eq.{succ u3} (Set.{u3} P) s\u2081 (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.instEmptyCollectionSet.{u3} P))) (Eq.{succ u3} (Set.{u3} P) s\u2082 (EmptyCollection.emptyCollection.{u3} (Set.{u3} P) (Set.instEmptyCollectionSet.{u3} P)))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.affine_span_parallel_iff_vector_span_eq_and_eq_empty_iff_eq_empty AffineSubspace.affineSpan_parallel_iff_vectorSpan_eq_and_eq_empty_iff_eq_empty\u2093'. -/\ntheorem affineSpan_parallel_iff_vectorSpan_eq_and_eq_empty_iff_eq_empty {s\u2081 s\u2082 : Set P} :\n    affineSpan k s\u2081 \u2225 affineSpan k s\u2082 \u2194 vectorSpan k s\u2081 = vectorSpan k s\u2082 \u2227 (s\u2081 = \u2205 \u2194 s\u2082 = \u2205) :=\n  by\n  simp_rw [\u2190 direction_affineSpan, \u2190 affineSpan_eq_bot k]\n  exact parallel_iff_direction_eq_and_eq_bot_iff_eq_bot\n#align affine_subspace.affine_span_parallel_iff_vector_span_eq_and_eq_empty_iff_eq_empty AffineSubspace.affineSpan_parallel_iff_vectorSpan_eq_and_eq_empty_iff_eq_empty\n\n/- warning: affine_subspace.affine_span_pair_parallel_iff_vector_span_eq -> AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq is a dubious translation:\nlean 3 declaration is\n  forall {k : Type.{u1}} {V : Type.{u2}} {P : Type.{u3}} [_inst_1 : Ring.{u1} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u3} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {p\u2083 : P} {p\u2084 : P}, Iff (AffineSubspace.Parallel.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082))) (affineSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2083 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2084)))) (Eq.{succ u2} (Submodule.{u1, u2} k V (Ring.toSemiring.{u1} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2081 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2082))) (vectorSpan.{u1, u2, u3} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u3, u3} P (Set.{u3} P) (Set.hasInsert.{u3} P) p\u2083 (Singleton.singleton.{u3, u3} P (Set.{u3} P) (Set.hasSingleton.{u3} P) p\u2084))))\nbut is expected to have type\n  forall {k : Type.{u3}} {V : Type.{u2}} {P : Type.{u1}} [_inst_1 : Ring.{u3} k] [_inst_2 : AddCommGroup.{u2} V] [_inst_3 : Module.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2)] [_inst_4 : AddTorsor.{u2, u1} V P (AddCommGroup.toAddGroup.{u2} V _inst_2)] {p\u2081 : P} {p\u2082 : P} {p\u2083 : P} {p\u2084 : P}, Iff (AffineSubspace.Parallel.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (affineSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082))) (affineSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2083 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2084)))) (Eq.{succ u2} (Submodule.{u3, u2} k V (Ring.toSemiring.{u3} k _inst_1) (AddCommGroup.toAddCommMonoid.{u2} V _inst_2) _inst_3) (vectorSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2081 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2082))) (vectorSpan.{u3, u2, u1} k V P _inst_1 _inst_2 _inst_3 _inst_4 (Insert.insert.{u1, u1} P (Set.{u1} P) (Set.instInsertSet.{u1} P) p\u2083 (Singleton.singleton.{u1, u1} P (Set.{u1} P) (Set.instSingletonSet.{u1} P) p\u2084))))\nCase conversion may be inaccurate. Consider using '#align affine_subspace.affine_span_pair_parallel_iff_vector_span_eq AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq\u2093'. -/\ntheorem affineSpan_pair_parallel_iff_vectorSpan_eq {p\u2081 p\u2082 p\u2083 p\u2084 : P} :\n    line[k, p\u2081, p\u2082] \u2225 line[k, p\u2083, p\u2084] \u2194\n      vectorSpan k ({p\u2081, p\u2082} : Set P) = vectorSpan k ({p\u2083, p\u2084} : Set P) :=\n  by\n  simp [affine_span_parallel_iff_vector_span_eq_and_eq_empty_iff_eq_empty, \u2190\n    not_nonempty_iff_eq_empty]\n#align affine_subspace.affine_span_pair_parallel_iff_vector_span_eq AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq\n\nend AffineSubspace\n\n", "meta": {"author": "leanprover-community", "repo": "mathlib3port", "sha": "62505aa236c58c8559783b16d33e30df3daa54f4", "save_path": "github-repos/lean/leanprover-community-mathlib3port", "path": "github-repos/lean/leanprover-community-mathlib3port/mathlib3port-62505aa236c58c8559783b16d33e30df3daa54f4/Mathbin/LinearAlgebra/AffineSpace/AffineSubspace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985637, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7001173608153766}}
{"text": "import propositional_logic.semantics\nimport propositional_logic.syntactics\n\nopen formula\n\nsection soundness\n\nvariables {T : Theory} {\u03c6 : Formula}\n\ntheorem soundness (h : syntactics.consequence T \u03c6) : semantics.consequence T \u03c6 :=\nbegin\n  induction h with \u03c8 h\u03c8T \u03c8 h\u03c8ax \u03b1 \u03b2 h\u03b1S h\u03b1\u03b2S h\u03b1T h\u03b1\u03b2T,\n  { exact semantics.consequence_mem \u2039_\u203a },\n  { rcases h\u03c8ax with \u27e8\u03b1, \u03b2, h\u27e9,\n    { rw h,\n      exact semantics.consequence_P1 },\n    { rcases h\u03c8ax with \u27e8\u03b1, \u03b2, \u03b3, h\u27e9,\n      rw h,\n      exact semantics.consequence_P2 },\n    { rcases h\u03c8ax with \u27e8\u03b1, \u03b2, h\u27e9,\n      rw h,\n      exact semantics.consequence_P3 } },\n  { exact semantics.consequence_modus_ponens \u2039_\u203a \u2039_\u203a }\nend\n\nend soundness\n\nsection completeness\n\nlocal infix ` \u22a2 `:50 := syntactics.consequence\n\ndef model (T : Theory) : valuation :=\n\u03bb var, T \u22a2 Var var\n\nvariables {T : Theory} {\u03c6 : Formula}\n\nopen syntactics\n\n\n/- We are going to show that (syntactical) consistent and complete theories have a model. -/\nlemma model_models_iff_consequence (hcons : consistent T) (hcom : complete T) : \n  T \u22a2 \u03c6 \u2194 eval (model T) \u03c6 :=\nbegin\n  induction \u03c6 with v \u03c6 \u03c8 h\u03c6 h\u03c8 \u03c6 h\u03c6,\n  { refl },\n  { rw [semantics.eval_to, \u2190 h\u03c6, \u2190 h\u03c8],\n    exact consistent_complete.consequence_to_iff_consequence_of hcons hcom },\n  { rw semantics.eval_not,\n    rw consistent_complete.consequence_not_iff_not_consequence \u2039_\u203a \u2039_\u203a,\n    cc }\nend\n\ntheorem model_models (hcons : consistent T) (hcom : complete T) :\n  model T \u22a7 T :=\nbegin\n  intro \u03c6,\n  rw \u2190 model_models_iff_consequence \u2039_\u203a \u2039_\u203a,\n  exact consequence_mem,\nend\n\ntheorem completeness : semantics.consequence T \u03c6 \u2192 T \u22a2 \u03c6 :=\nbegin\n  contrapose!,\n  intro h,\n  have hTn\u03c6 := consistent_union_of_consistent_not_consequence h,\n  rcases hTn\u03c6.exists_consistent_complete_extension with \u27e8T', hs, hcons, hcom\u27e9,\n  apply (mt (semantics.consequence_trans ((by simp) : T \u2286 T \u222a {\u00ac\u1da0 \u03c6}))),\n  apply (mt (semantics.consequence_trans hs)),\n  apply semantics.not_consequence_of_models_union_not (_ : model T' \u22a7 T' \u222a {\u00ac\u1da0 \u03c6}),\n  refine (semantics.subset_models _ (model_models \u2039_\u203a \u2039_\u203a)),\n  apply set.union_subset (rfl.subset : T' \u2286 T'),\n  rw set.union_subset_iff at hs,\n  exact hs.2\nend\n\nend completeness\n\ntheorem semantics_iff_syntactics {T : Theory} {\u03c6 : Formula} : \n  semantics.consequence T \u03c6 \u2194 syntactics.consequence T \u03c6 :=\n\u27e8completeness, soundness\u27e9", "meta": {"author": "atarnoam", "repo": "logic-lean", "sha": "164e1afde76522cd5368914b562696506961ba29", "save_path": "github-repos/lean/atarnoam-logic-lean", "path": "github-repos/lean/atarnoam-logic-lean/logic-lean-164e1afde76522cd5368914b562696506961ba29/src/propositional_logic/completeness.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.7000804501546609}}
